@camerontaylor/paseo-highlight 0.8.0-fork.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/astro/parser.d.ts +11 -0
  2. package/dist/astro/parser.js +228 -0
  3. package/dist/colors.d.ts +4 -0
  4. package/dist/colors.js +45 -0
  5. package/dist/csharp/highlight.d.ts +2 -0
  6. package/dist/csharp/highlight.js +22 -0
  7. package/dist/csharp/language.d.ts +3 -0
  8. package/dist/csharp/language.js +21 -0
  9. package/dist/csharp/parser.d.ts +3 -0
  10. package/dist/csharp/parser.js +150 -0
  11. package/dist/csharp/terms.d.ts +7 -0
  12. package/dist/csharp/terms.js +12 -0
  13. package/dist/csharp/tokens.d.ts +4 -0
  14. package/dist/csharp/tokens.js +73 -0
  15. package/dist/highlighter.d.ts +4 -0
  16. package/dist/highlighter.js +55 -0
  17. package/dist/index.d.ts +8 -0
  18. package/dist/index.js +6 -0
  19. package/dist/nix/highlight.d.ts +2 -0
  20. package/dist/nix/highlight.js +21 -0
  21. package/dist/nix/language.d.ts +3 -0
  22. package/dist/nix/language.js +32 -0
  23. package/dist/nix/parser.d.ts +3 -0
  24. package/dist/nix/parser.js +45 -0
  25. package/dist/nix/terms.d.ts +9 -0
  26. package/dist/nix/terms.js +14 -0
  27. package/dist/nix/tokens.d.ts +4 -0
  28. package/dist/nix/tokens.js +70 -0
  29. package/dist/parsers.d.ts +7 -0
  30. package/dist/parsers.js +101 -0
  31. package/dist/svelte/highlight.d.ts +2 -0
  32. package/dist/svelte/highlight.js +54 -0
  33. package/dist/svelte/nesting.d.ts +9 -0
  34. package/dist/svelte/nesting.js +97 -0
  35. package/dist/svelte/parser.d.ts +3 -0
  36. package/dist/svelte/parser.js +204 -0
  37. package/dist/svelte/terms.d.ts +24 -0
  38. package/dist/svelte/terms.js +24 -0
  39. package/dist/svelte/tokens.d.ts +16 -0
  40. package/dist/svelte/tokens.js +509 -0
  41. package/dist/syntax-roles.d.ts +10 -0
  42. package/dist/syntax-roles.js +50 -0
  43. package/dist/themes.d.ts +12 -0
  44. package/dist/themes.js +235 -0
  45. package/dist/types.d.ts +6 -0
  46. package/dist/types.js +2 -0
  47. package/package.json +55 -0
  48. package/src/astro/LICENSE +21 -0
@@ -0,0 +1,11 @@
1
+ import { type Input, type PartialParse, Parser, type TreeFragment } from "@lezer/common";
2
+ interface Range {
3
+ from: number;
4
+ to: number;
5
+ }
6
+ declare class AstroParser extends Parser {
7
+ createParse(input: Input, fragments: readonly TreeFragment[], ranges: readonly Range[]): PartialParse;
8
+ }
9
+ export declare const astroParser: AstroParser;
10
+ export {};
11
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1,228 @@
1
+ // Adapted from @fazelstudio/codemirror-lang-astro@0.2.0 (MIT).
2
+ // The parser is kept pure so server-side diff highlighting does not load editor-only modules.
3
+ import { Parser, parseMixed, } from "@lezer/common";
4
+ import { parser as cssParser } from "@lezer/css";
5
+ import { parser as htmlParser } from "@lezer/html";
6
+ import { parser as jsParser } from "@lezer/javascript";
7
+ const jsxParser = jsParser.configure({ dialect: "ts jsx" });
8
+ const typescriptParser = jsParser.configure({ dialect: "ts" });
9
+ function isSpace(code) {
10
+ return code === 32 || code === 9 || code === 10 || code === 13;
11
+ }
12
+ function isRegexStart(text, position) {
13
+ let previous = position - 1;
14
+ while (previous >= 0 && isSpace(text.charCodeAt(previous)))
15
+ previous--;
16
+ if (previous < 0)
17
+ return true;
18
+ const character = text[previous];
19
+ if (/[)\]}<"'`\d]/.test(character))
20
+ return false;
21
+ const code = text.charCodeAt(previous);
22
+ if (code === 62)
23
+ return previous > 0 && text.charCodeAt(previous - 1) === 61;
24
+ if (!/[A-Za-z_$]/.test(character))
25
+ return true;
26
+ let start = previous;
27
+ while (start >= 0 && /[A-Za-z0-9_$]/.test(text[start]))
28
+ start--;
29
+ const keyword = text.slice(start + 1, previous + 1);
30
+ return /^(return|typeof|instanceof|in|of|new|void|delete|yield|await|case|do|else|throw|extends|assert|with)$/.test(keyword);
31
+ }
32
+ function skipQuotedText(text, opening) {
33
+ const quote = text.charCodeAt(opening);
34
+ for (let position = opening + 1; position < text.length; position++) {
35
+ const code = text.charCodeAt(position);
36
+ if (code === 92)
37
+ position++;
38
+ else if (code === quote)
39
+ return position;
40
+ }
41
+ return text.length - 1;
42
+ }
43
+ function skipLineComment(text, opening) {
44
+ const newline = text.indexOf("\n", opening + 2);
45
+ return newline >= 0 ? newline : text.length - 1;
46
+ }
47
+ function skipBlockComment(text, opening) {
48
+ const closing = text.indexOf("*/", opening + 2);
49
+ return closing >= 0 ? closing + 1 : text.length - 1;
50
+ }
51
+ function skipRegex(text, opening) {
52
+ let isInCharacterClass = false;
53
+ for (let position = opening + 1; position < text.length; position++) {
54
+ const code = text.charCodeAt(position);
55
+ if (code === 10 || code === 13)
56
+ return position;
57
+ if (code === 92)
58
+ position++;
59
+ else if (isInCharacterClass && code === 93)
60
+ isInCharacterClass = false;
61
+ else if (!isInCharacterClass && code === 91)
62
+ isInCharacterClass = true;
63
+ else if (!isInCharacterClass && code === 47)
64
+ return position;
65
+ }
66
+ return text.length - 1;
67
+ }
68
+ function findClosingBrace(text, opening) {
69
+ let depth = 0;
70
+ for (let position = opening; position < text.length; position++) {
71
+ const code = text.charCodeAt(position);
72
+ if (code === 47 && text.charCodeAt(position + 1) === 47) {
73
+ position = skipLineComment(text, position);
74
+ }
75
+ else if (code === 47 && text.charCodeAt(position + 1) === 42) {
76
+ position = skipBlockComment(text, position);
77
+ }
78
+ else if (code === 47 && isRegexStart(text, position)) {
79
+ position = skipRegex(text, position);
80
+ }
81
+ else if (code === 34 || code === 39 || code === 96) {
82
+ position = skipQuotedText(text, position);
83
+ }
84
+ else if (code === 123) {
85
+ depth++;
86
+ }
87
+ else if (code === 125 && --depth === 0) {
88
+ return position;
89
+ }
90
+ }
91
+ return -1;
92
+ }
93
+ function findExpressions(text) {
94
+ const ranges = [];
95
+ for (let position = 0; position < text.length; position++) {
96
+ if (text.charCodeAt(position) !== 123)
97
+ continue;
98
+ const closing = findClosingBrace(text, position);
99
+ if (closing < 0)
100
+ break;
101
+ ranges.push({ from: position, to: closing });
102
+ position = closing;
103
+ }
104
+ return ranges;
105
+ }
106
+ function maskExpressions(text) {
107
+ const characters = text.split("");
108
+ for (const { from, to } of findExpressions(text)) {
109
+ for (let position = from + 1; position < to; position++)
110
+ characters[position] = "a";
111
+ }
112
+ return characters.join("");
113
+ }
114
+ function expressionOverlays(node, input) {
115
+ const overlays = findExpressions(input.read(node.from, node.to)).map(({ from, to }) => ({
116
+ from: node.from + from + 1,
117
+ to: node.from + to,
118
+ }));
119
+ return overlays.length > 0 ? overlays : null;
120
+ }
121
+ function isFenceEnd(text, position) {
122
+ if (position >= text.length)
123
+ return true;
124
+ const code = text.charCodeAt(position);
125
+ return code === 10 || code === 13 || code === 32 || code === 9;
126
+ }
127
+ function findFrontmatter(text) {
128
+ const from = text.charCodeAt(0) === 0xfeff ? 1 : 0;
129
+ if (!text.startsWith("---", from) || !isFenceEnd(text, from + 3))
130
+ return null;
131
+ let newline = text.indexOf("\n", from + 3);
132
+ while (newline >= 0) {
133
+ const closing = newline + 1;
134
+ if (text.startsWith("---", closing) && isFenceEnd(text, closing + 3)) {
135
+ return { from, to: closing + 3 };
136
+ }
137
+ newline = text.indexOf("\n", closing);
138
+ }
139
+ return null;
140
+ }
141
+ function maskDocument(text, frontmatter) {
142
+ if (!frontmatter)
143
+ return maskExpressions(text);
144
+ return (text.slice(0, frontmatter.from) +
145
+ "<!--" +
146
+ text.slice(frontmatter.from + 4, frontmatter.to - 3) +
147
+ "-->" +
148
+ maskExpressions(text.slice(frontmatter.to)));
149
+ }
150
+ function getOpenTagAttributes(node, input) {
151
+ const attributes = Object.create(null);
152
+ const openTag = node.getChild("OpenTag");
153
+ if (!openTag)
154
+ return attributes;
155
+ for (const attribute of openTag.getChildren("Attribute")) {
156
+ const name = attribute.getChild("AttributeName");
157
+ if (!name)
158
+ continue;
159
+ const value = attribute.getChild("AttributeValue") || attribute.getChild("UnquotedAttributeValue");
160
+ const key = input.read(name.from, name.to).toLowerCase();
161
+ attributes[key] = value ? input.read(value.from, value.to).replace(/^["']|["']$/g, "") : "";
162
+ }
163
+ return attributes;
164
+ }
165
+ function nestedLanguage(node, input) {
166
+ if (node.name === "Comment") {
167
+ const isFrontmatter = input.read(node.from, node.from + 3) === "---" && input.read(node.to - 3, node.to) === "---";
168
+ const from = node.from + 4;
169
+ const to = node.to - 3;
170
+ return isFrontmatter && to > from
171
+ ? { parser: typescriptParser, overlay: [{ from, to }] }
172
+ : null;
173
+ }
174
+ const canContainExpression = node.name === "Text" ||
175
+ node.name === "UnquotedAttributeValue" ||
176
+ node.name === "AttributeValue";
177
+ if (canContainExpression) {
178
+ const overlay = expressionOverlays(node, input);
179
+ return overlay ? { parser: jsxParser, overlay } : null;
180
+ }
181
+ if (node.name === "StyleText")
182
+ return { parser: cssParser };
183
+ if (node.name !== "ScriptText" || !node.node.parent)
184
+ return null;
185
+ const attributes = getOpenTagAttributes(node.node.parent, input);
186
+ if (attributes.src)
187
+ return null;
188
+ const language = (attributes.lang || attributes.type || "").toLowerCase();
189
+ let dialect = "";
190
+ if (language.includes("tsx"))
191
+ dialect = "ts jsx";
192
+ else if (language.includes("typescript") || language === "ts")
193
+ dialect = "ts";
194
+ else if (language.includes("jsx"))
195
+ dialect = "jsx";
196
+ return { parser: dialect ? jsParser.configure({ dialect }) : jsParser };
197
+ }
198
+ class CompletedParse {
199
+ constructor(tree) {
200
+ this.tree = tree;
201
+ this.isDone = false;
202
+ }
203
+ advance() {
204
+ if (this.isDone)
205
+ return null;
206
+ this.isDone = true;
207
+ return this.tree;
208
+ }
209
+ get parsedPos() {
210
+ return this.tree.length;
211
+ }
212
+ stopAt() { }
213
+ get stoppedAt() {
214
+ return null;
215
+ }
216
+ }
217
+ const mountNestedLanguages = parseMixed(nestedLanguage);
218
+ class AstroParser extends Parser {
219
+ createParse(input, fragments, ranges) {
220
+ const from = ranges[0]?.from ?? 0;
221
+ const to = ranges[0]?.to ?? input.length;
222
+ const text = input.read(from, to);
223
+ const tree = htmlParser.parse(maskDocument(text, findFrontmatter(text)));
224
+ return mountNestedLanguages(new CompletedParse(tree), input, fragments, ranges);
225
+ }
226
+ }
227
+ export const astroParser = new AstroParser();
228
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1,4 @@
1
+ import type { HighlightStyle } from "./types.js";
2
+ export declare const darkHighlightColors: Record<HighlightStyle, string>;
3
+ export declare const lightHighlightColors: Record<HighlightStyle, string>;
4
+ //# sourceMappingURL=colors.d.ts.map
package/dist/colors.js ADDED
@@ -0,0 +1,45 @@
1
+ export const darkHighlightColors = {
2
+ keyword: "#ff7b72",
3
+ comment: "#8b949e",
4
+ string: "#a5d6ff",
5
+ number: "#79c0ff",
6
+ literal: "#79c0ff",
7
+ function: "#d2a8ff",
8
+ definition: "#d2a8ff",
9
+ class: "#ffa657",
10
+ type: "#ff7b72",
11
+ tag: "#7ee787",
12
+ attribute: "#79c0ff",
13
+ property: "#79c0ff",
14
+ variable: "#c9d1d9",
15
+ operator: "#79c0ff",
16
+ punctuation: "#c9d1d9",
17
+ regexp: "#a5d6ff",
18
+ escape: "#79c0ff",
19
+ meta: "#8b949e",
20
+ heading: "#79c0ff",
21
+ link: "#a5d6ff",
22
+ };
23
+ export const lightHighlightColors = {
24
+ keyword: "#cf222e",
25
+ comment: "#6e7781",
26
+ string: "#0a3069",
27
+ number: "#0550ae",
28
+ literal: "#0550ae",
29
+ function: "#8250df",
30
+ definition: "#8250df",
31
+ class: "#953800",
32
+ type: "#cf222e",
33
+ tag: "#116329",
34
+ attribute: "#0550ae",
35
+ property: "#0550ae",
36
+ variable: "#24292f",
37
+ operator: "#0550ae",
38
+ punctuation: "#24292f",
39
+ regexp: "#0a3069",
40
+ escape: "#0550ae",
41
+ meta: "#6e7781",
42
+ heading: "#0550ae",
43
+ link: "#0a3069",
44
+ };
45
+ //# sourceMappingURL=colors.js.map
@@ -0,0 +1,2 @@
1
+ export declare const csharpHighlighting: import("@lezer/common").NodePropSource;
2
+ //# sourceMappingURL=highlight.d.ts.map
@@ -0,0 +1,22 @@
1
+ import { styleTags, tags as t } from "@lezer/highlight";
2
+ export const csharpHighlighting = styleTags({
3
+ "Keyword ContextualKeyword SimpleType": t.keyword,
4
+ "NullLiteral BooleanLiteral": t.bool,
5
+ IntegerLiteral: t.integer,
6
+ RealLiteral: t.float,
7
+ 'StringLiteral CharacterLiteral InterpolatedRegularString InterpolatedVerbatimString $" @$" $@"': t.string,
8
+ "LineComment BlockComment": t.comment,
9
+ ". .. : Astrisk Slash % + - ++ -- Not ~ << & | ^ && || < > <= >= == NotEq = += -= *= SlashEq %= &= |= ^= ? ?? ??= =>": t.operator,
10
+ PP_Directive: t.keyword,
11
+ TypeIdentifier: t.typeName,
12
+ "ArgumentName AttrsNamedArg": t.variableName,
13
+ ConstName: t.constant(t.variableName),
14
+ MethodName: t.function(t.variableName),
15
+ ParamName: [t.emphasis, t.variableName],
16
+ VarName: t.variableName,
17
+ "FieldName PropertyName": t.propertyName,
18
+ "( )": t.paren,
19
+ "{ }": t.brace,
20
+ "[ ]": t.squareBracket,
21
+ });
22
+ //# sourceMappingURL=highlight.js.map
@@ -0,0 +1,3 @@
1
+ import { LRLanguage } from "@codemirror/language";
2
+ export declare const csharpLanguage: LRLanguage;
3
+ //# sourceMappingURL=language.d.ts.map
@@ -0,0 +1,21 @@
1
+ import { continuedIndent, foldInside, foldNodeProp, indentNodeProp, LRLanguage, } from "@codemirror/language";
2
+ import { parser } from "./parser.js";
3
+ export const csharpLanguage = LRLanguage.define({
4
+ name: "C#",
5
+ parser: parser.configure({
6
+ props: [
7
+ indentNodeProp.add({
8
+ Delim: continuedIndent({ except: /^\s*(?:case\b|default:)/ }),
9
+ }),
10
+ foldNodeProp.add({
11
+ Delim: foldInside,
12
+ }),
13
+ ],
14
+ }),
15
+ languageData: {
16
+ commentTokens: { line: "//", block: { open: "/*", close: "*/" } },
17
+ closeBrackets: { brackets: ["(", "[", "{", '"', "'"] },
18
+ indentOnInput: /^\s*((\)|\]|\})$|(else|else\s+if|catch|finally|case)\b|default:)/,
19
+ },
20
+ });
21
+ //# sourceMappingURL=language.js.map
@@ -0,0 +1,3 @@
1
+ import { LRParser } from "@lezer/lr";
2
+ export declare const parser: LRParser;
3
+ //# sourceMappingURL=parser.d.ts.map