pax_global_header00006660000000000000000000000064144632520010014507gustar00rootroot0000000000000052 comment=c1cfd8e8d8f716bdf6d35e9f2e200b5c736a9956 lang-css-6.2.1/000077500000000000000000000000001446325200100132245ustar00rootroot00000000000000lang-css-6.2.1/.github/000077500000000000000000000000001446325200100145645ustar00rootroot00000000000000lang-css-6.2.1/.github/workflows/000077500000000000000000000000001446325200100166215ustar00rootroot00000000000000lang-css-6.2.1/.github/workflows/dispatch.yml000066400000000000000000000006371446325200100211510ustar00rootroot00000000000000name: Trigger CI on: push jobs: build: name: Dispatch to main repo runs-on: ubuntu-latest steps: - name: Emit repository_dispatch uses: mvasigh/dispatch-action@main with: # You should create a personal access token and store it in your repository token: ${{ secrets.DISPATCH_AUTH }} repo: dev owner: codemirror event_type: push lang-css-6.2.1/.gitignore000066400000000000000000000001271446325200100152140ustar00rootroot00000000000000/node_modules package-lock.json /dist /test/*.js /test/*.d.ts /test/*.d.ts.map .tern-* lang-css-6.2.1/.npmignore000066400000000000000000000001001446325200100152120ustar00rootroot00000000000000/src /test /node_modules .tern-* rollup.config.js tsconfig.json lang-css-6.2.1/CHANGELOG.md000066400000000000000000000031131446325200100150330ustar00rootroot00000000000000## 6.2.1 (2023-08-04) ### Bug fixes Allow keyframe blocks to be code-folded. ## 6.2.0 (2023-04-26) ### Bug fixes Explicitly list @lezer/common as a package dependency. ### New features Export `defineCSSCompletionSource`, which allows one to define a CSS-style completion source for dialects with their own variable syntax. ## 6.1.1 (2023-03-08) ### Bug fixes Provide better completions when completing directly in a `Styles` top node. ## 6.1.0 (2023-03-06) ### New features CSS completion can now complete variable names. ## 6.0.2 (2023-01-28) ### Bug fixes Fetch the available CSS property names in a way that works on Chrome. ## 6.0.1 (2022-10-24) ### Bug fixes CSS completion now supports a number of additional recent and semi-standardized pseudo-class names. ## 6.0.0 (2022-06-08) ### Breaking changes Update dependencies to 6.0.0 ## 0.20.0 (2022-04-20) ### Breaking changes Update dependencies to 0.20.0 ## 0.19.3 (2021-09-24) ### Bug fixes Use more appropriate highlighting tags for attribute names, tag names, and CSS variables. ## 0.19.2 (2021-09-22) ### New features The package now exports a completion source function, rather than a prebuilt completion extension. ## 0.19.1 (2021-08-11) ### Bug fixes Fix incorrect versions for @lezer dependencies. ## 0.19.0 (2021-08-11) ### Breaking changes Update dependencies to 0.19.0 ## 0.18.0 (2021-03-03) ### Breaking changes Update dependencies to 0.18. ## 0.17.1 (2021-01-06) ### New features The package now also exports a CommonJS module. ## 0.17.0 (2020-12-29) ### Breaking changes First numbered release. lang-css-6.2.1/LICENSE000066400000000000000000000021361446325200100142330ustar00rootroot00000000000000MIT License Copyright (C) 2018-2021 by Marijn Haverbeke and others Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. lang-css-6.2.1/README.md000066400000000000000000000056571446325200100145200ustar00rootroot00000000000000 # @codemirror/lang-css [![NPM version](https://img.shields.io/npm/v/@codemirror/lang-css.svg)](https://www.npmjs.org/package/@codemirror/lang-css) [ [**WEBSITE**](https://codemirror.net/) | [**ISSUES**](https://github.com/codemirror/dev/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/lang-css/blob/main/CHANGELOG.md) ] This package implements CSS language support for the [CodeMirror](https://codemirror.net/) code editor. The [project page](https://codemirror.net/) has more information, a number of [examples](https://codemirror.net/examples/) and the [documentation](https://codemirror.net/docs/). This code is released under an [MIT license](https://github.com/codemirror/lang-css/tree/main/LICENSE). We aim to be an inclusive, welcoming community. To make that explicit, we have a [code of conduct](http://contributor-covenant.org/version/1/1/0/) that applies to communication around the project. ## API Reference
css() → LanguageSupport

Language support for CSS.

cssLanguage: LRLanguage

A language provider based on the Lezer CSS parser, extended with highlighting and indentation information.

cssCompletionSource: CompletionSource

CSS property, variable, and value keyword completion source.

defineCSSCompletionSource(isVariable: fn(nodeSyntaxNodeRef) → boolean) → CompletionSource

Create a completion source for a CSS dialect, providing a predicate for determining what kind of syntax node can act as a completable variable. This is used by language modes like Sass and Less to reuse this package's completion logic.

lang-css-6.2.1/package.json000066400000000000000000000017471446325200100155230ustar00rootroot00000000000000{ "name": "@codemirror/lang-css", "version": "6.2.1", "description": "CSS language support for the CodeMirror code editor", "scripts": { "test": "cm-runtests", "prepare": "cm-buildhelper src/css.ts" }, "keywords": [ "editor", "code" ], "author": { "name": "Marijn Haverbeke", "email": "marijn@haverbeke.berlin", "url": "http://marijnhaverbeke.nl" }, "type": "module", "main": "dist/index.cjs", "exports": { "import": "./dist/index.js", "require": "./dist/index.cjs" }, "types": "dist/index.d.ts", "module": "dist/index.js", "sideEffects": false, "license": "MIT", "dependencies": { "@codemirror/autocomplete": "^6.0.0", "@codemirror/language": "^6.0.0", "@codemirror/state": "^6.0.0", "@lezer/common": "^1.0.2", "@lezer/css": "^1.0.0" }, "devDependencies": { "@codemirror/buildhelper": "^1.0.0" }, "repository": { "type": "git", "url": "https://github.com/codemirror/lang-css.git" } } lang-css-6.2.1/src/000077500000000000000000000000001446325200100140135ustar00rootroot00000000000000lang-css-6.2.1/src/README.md000066400000000000000000000021341446325200100152720ustar00rootroot00000000000000 # @codemirror/lang-css [![NPM version](https://img.shields.io/npm/v/@codemirror/lang-css.svg)](https://www.npmjs.org/package/@codemirror/lang-css) [ [**WEBSITE**](https://codemirror.net/) | [**ISSUES**](https://github.com/codemirror/dev/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/lang-css/blob/main/CHANGELOG.md) ] This package implements CSS language support for the [CodeMirror](https://codemirror.net/) code editor. The [project page](https://codemirror.net/) has more information, a number of [examples](https://codemirror.net/examples/) and the [documentation](https://codemirror.net/docs/). This code is released under an [MIT license](https://github.com/codemirror/lang-css/tree/main/LICENSE). We aim to be an inclusive, welcoming community. To make that explicit, we have a [code of conduct](http://contributor-covenant.org/version/1/1/0/) that applies to communication around the project. ## API Reference @css @cssLanguage @cssCompletionSource @defineCSSCompletionSource lang-css-6.2.1/src/complete.ts000066400000000000000000000327551446325200100162070ustar00rootroot00000000000000import {CompletionSource, Completion} from "@codemirror/autocomplete" import {syntaxTree} from "@codemirror/language" import {SyntaxNode, SyntaxNodeRef, NodeWeakMap, IterMode} from "@lezer/common" import {Text} from "@codemirror/state" let _properties: readonly Completion[] | null = null function properties() { if (!_properties && typeof document == "object" && document.body) { let {style} = document.body, names = [], seen = new Set for (let prop in style) if (prop != "cssText" && prop != "cssFloat") { if (typeof style[prop] == "string") { if (/[A-Z]/.test(prop)) prop = prop.replace(/[A-Z]/g, ch => "-" + ch.toLowerCase()) if (!seen.has(prop)) { names.push(prop) seen.add(prop) } } } _properties = names.sort().map(name => ({type: "property", label: name})) } return _properties || [] } const pseudoClasses = [ "active", "after", "any-link", "autofill", "backdrop", "before", "checked", "cue", "default", "defined", "disabled", "empty", "enabled", "file-selector-button", "first", "first-child", "first-letter", "first-line", "first-of-type", "focus", "focus-visible", "focus-within", "fullscreen", "has", "host", "host-context", "hover", "in-range", "indeterminate", "invalid", "is", "lang", "last-child", "last-of-type", "left", "link", "marker", "modal", "not", "nth-child", "nth-last-child", "nth-last-of-type", "nth-of-type", "only-child", "only-of-type", "optional", "out-of-range", "part", "placeholder", "placeholder-shown", "read-only", "read-write", "required", "right", "root", "scope", "selection", "slotted", "target", "target-text", "valid", "visited", "where" ].map(name => ({type: "class", label: name})) const values = [ "above", "absolute", "activeborder", "additive", "activecaption", "after-white-space", "ahead", "alias", "all", "all-scroll", "alphabetic", "alternate", "always", "antialiased", "appworkspace", "asterisks", "attr", "auto", "auto-flow", "avoid", "avoid-column", "avoid-page", "avoid-region", "axis-pan", "background", "backwards", "baseline", "below", "bidi-override", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box", "both", "bottom", "break", "break-all", "break-word", "bullets", "button", "button-bevel", "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "calc", "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret", "cell", "center", "checkbox", "circle", "cjk-decimal", "clear", "clip", "close-quote", "col-resize", "collapse", "color", "color-burn", "color-dodge", "column", "column-reverse", "compact", "condensed", "contain", "content", "contents", "content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop", "cross", "crosshair", "currentcolor", "cursive", "cyclic", "darken", "dashed", "decimal", "decimal-leading-zero", "default", "default-button", "dense", "destination-atop", "destination-in", "destination-out", "destination-over", "difference", "disc", "discard", "disclosure-closed", "disclosure-open", "document", "dot-dash", "dot-dot-dash", "dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out", "element", "ellipse", "ellipsis", "embed", "end", "ethiopic-abegede-gez", "ethiopic-halehame-aa-er", "ethiopic-halehame-gez", "ew-resize", "exclusion", "expanded", "extends", "extra-condensed", "extra-expanded", "fantasy", "fast", "fill", "fill-box", "fixed", "flat", "flex", "flex-end", "flex-start", "footnotes", "forwards", "from", "geometricPrecision", "graytext", "grid", "groove", "hand", "hard-light", "help", "hidden", "hide", "higher", "highlight", "highlighttext", "horizontal", "hsl", "hsla", "hue", "icon", "ignore", "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite", "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis", "inline-block", "inline-flex", "inline-grid", "inline-table", "inset", "inside", "intrinsic", "invert", "italic", "justify", "keep-all", "landscape", "large", "larger", "left", "level", "lighter", "lighten", "line-through", "linear", "linear-gradient", "lines", "list-item", "listbox", "listitem", "local", "logical", "loud", "lower", "lower-hexadecimal", "lower-latin", "lower-norwegian", "lowercase", "ltr", "luminosity", "manipulation", "match", "matrix", "matrix3d", "medium", "menu", "menutext", "message-box", "middle", "min-intrinsic", "mix", "monospace", "move", "multiple", "multiple_mask_images", "multiply", "n-resize", "narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop", "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap", "ns-resize", "numbers", "numeric", "nw-resize", "nwse-resize", "oblique", "opacity", "open-quote", "optimizeLegibility", "optimizeSpeed", "outset", "outside", "outside-shape", "overlay", "overline", "padding", "padding-box", "painted", "page", "paused", "perspective", "pinch-zoom", "plus-darker", "plus-lighter", "pointer", "polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "push-button", "radial-gradient", "radio", "read-only", "read-write", "read-write-plaintext-only", "rectangle", "region", "relative", "repeat", "repeating-linear-gradient", "repeating-radial-gradient", "repeat-x", "repeat-y", "reset", "reverse", "rgb", "rgba", "ridge", "right", "rotate", "rotate3d", "rotateX", "rotateY", "rotateZ", "round", "row", "row-resize", "row-reverse", "rtl", "run-in", "running", "s-resize", "sans-serif", "saturation", "scale", "scale3d", "scaleX", "scaleY", "scaleZ", "screen", "scroll", "scrollbar", "scroll-position", "se-resize", "self-start", "self-end", "semi-condensed", "semi-expanded", "separate", "serif", "show", "single", "skew", "skewX", "skewY", "skip-white-space", "slide", "slider-horizontal", "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow", "small", "small-caps", "small-caption", "smaller", "soft-light", "solid", "source-atop", "source-in", "source-out", "source-over", "space", "space-around", "space-between", "space-evenly", "spell-out", "square", "start", "static", "status-bar", "stretch", "stroke", "stroke-box", "sub", "subpixel-antialiased", "svg_masks", "super", "sw-resize", "symbolic", "symbols", "system-ui", "table", "table-caption", "table-cell", "table-column", "table-column-group", "table-footer-group", "table-header-group", "table-row", "table-row-group", "text", "text-bottom", "text-top", "textarea", "textfield", "thick", "thin", "threeddarkshadow", "threedface", "threedhighlight", "threedlightshadow", "threedshadow", "to", "top", "transform", "translate", "translate3d", "translateX", "translateY", "translateZ", "transparent", "ultra-condensed", "ultra-expanded", "underline", "unidirectional-pan", "unset", "up", "upper-latin", "uppercase", "url", "var", "vertical", "vertical-text", "view-box", "visible", "visibleFill", "visiblePainted", "visibleStroke", "visual", "w-resize", "wait", "wave", "wider", "window", "windowframe", "windowtext", "words", "wrap", "wrap-reverse", "x-large", "x-small", "xor", "xx-large", "xx-small" ].map(name => ({type: "keyword", label: name})).concat([ "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", "darkslateblue", "darkslategray", "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick", "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew", "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral", "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink", "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", "maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", "navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered", "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", "purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", "snow", "springgreen", "steelblue", "tan", "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen" ].map(name => ({type: "constant", label: name}))) const tags = [ "a", "abbr", "address", "article", "aside", "b", "bdi", "bdo", "blockquote", "body", "br", "button", "canvas", "caption", "cite", "code", "col", "colgroup", "dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "figcaption", "figure", "footer", "form", "header", "hgroup", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "html", "i", "iframe", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "meter", "nav", "ol", "output", "p", "pre", "ruby", "section", "select", "small", "source", "span", "strong", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "tr", "u", "ul" ].map(name => ({type: "type", label: name})) const identifier = /^(\w[\w-]*|-\w[\w-]*|)$/, variable = /^-(-[\w-]*)?$/ function isVarArg(node: SyntaxNode, doc: Text) { if (node.name == "(" || node.type.isError) node = node.parent || node if (node.name != "ArgList") return false let callee = node.parent?.firstChild if (callee?.name != "Callee") return false return doc.sliceString(callee.from, callee.to) == "var" } const VariablesByNode = new NodeWeakMap() const declSelector = ["Declaration"] function astTop(node: SyntaxNode) { for (let cur: SyntaxNode | null = node;;) { if (cur.type.isTop) return cur if (!(cur = cur.parent)) return node } } function variableNames(doc: Text, node: SyntaxNode, isVariable: (node: SyntaxNodeRef) => boolean): readonly Completion[] { if (node.to - node.from > 4096) { let known = VariablesByNode.get(node) if (known) return known let result = [], seen = new Set, cursor = node.cursor(IterMode.IncludeAnonymous) if (cursor.firstChild()) do { for (let option of variableNames(doc, cursor.node, isVariable)) if (!seen.has(option.label)) { seen.add(option.label) result.push(option) } } while (cursor.nextSibling()) VariablesByNode.set(node, result) return result } else { let result: Completion[] = [], seen = new Set node.cursor().iterate(node => { if (isVariable(node) && node.matchContext(declSelector) && node.node.nextSibling?.name == ":") { let name = doc.sliceString(node.from, node.to) if (!seen.has(name)) { seen.add(name) result.push({label: name, type: "variable"}) } } }) return result } } /// Create a completion source for a CSS dialect, providing a /// predicate for determining what kind of syntax node can act as a /// completable variable. This is used by language modes like Sass and /// Less to reuse this package's completion logic. export const defineCSSCompletionSource = (isVariable: (node: SyntaxNodeRef) => boolean): CompletionSource => context => { let {state, pos} = context, node = syntaxTree(state).resolveInner(pos, -1) let isDash = node.type.isError && node.from == node.to - 1 && state.doc.sliceString(node.from, node.to) == "-" if (node.name == "PropertyName" || (isDash || node.name == "TagName") && /^(Block|Styles)$/.test(node.resolve(node.to).name)) return {from: node.from, options: properties(), validFor: identifier} if (node.name == "ValueName") return {from: node.from, options: values, validFor: identifier} if (node.name == "PseudoClassName") return {from: node.from, options: pseudoClasses, validFor: identifier} if (isVariable(node) || (context.explicit || isDash) && isVarArg(node, state.doc)) return {from: isVariable(node) || isDash ? node.from : pos, options: variableNames(state.doc, astTop(node), isVariable), validFor: variable} if (node.name == "TagName") { for (let {parent} = node; parent; parent = parent.parent) if (parent.name == "Block") return {from: node.from, options: properties(), validFor: identifier} return {from: node.from, options: tags, validFor: identifier} } if (!context.explicit) return null let above = node.resolve(pos), before = above.childBefore(pos) if (before && before.name == ":" && above.name == "PseudoClassSelector") return {from: pos, options: pseudoClasses, validFor: identifier} if (before && before.name == ":" && above.name == "Declaration" || above.name == "ArgList") return {from: pos, options: values, validFor: identifier} if (above.name == "Block" || above.name == "Styles") return {from: pos, options: properties(), validFor: identifier} return null } /// CSS property, variable, and value keyword completion source. export const cssCompletionSource: CompletionSource = defineCSSCompletionSource(n => n.name == "VariableName" ) lang-css-6.2.1/src/css.ts000066400000000000000000000017371446325200100151630ustar00rootroot00000000000000import {parser} from "@lezer/css" import {LRLanguage, continuedIndent, indentNodeProp, foldNodeProp, foldInside, LanguageSupport} from "@codemirror/language" import {cssCompletionSource} from "./complete" export {cssCompletionSource, defineCSSCompletionSource} from "./complete" /// A language provider based on the [Lezer CSS /// parser](https://github.com/lezer-parser/css), extended with /// highlighting and indentation information. export const cssLanguage = LRLanguage.define({ name: "css", parser: parser.configure({ props: [ indentNodeProp.add({ Declaration: continuedIndent() }), foldNodeProp.add({ "Block KeyframeList": foldInside }) ] }), languageData: { commentTokens: {block: {open: "/*", close: "*/"}}, indentOnInput: /^\s*\}$/, wordChars: "-" } }) /// Language support for CSS. export function css() { return new LanguageSupport(cssLanguage, cssLanguage.data.of({autocomplete: cssCompletionSource})) }