@master/css-binding 0.0.0-site.1793659883.g69c9aebcf628

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 (66) hide show
  1. package/artifacts/mastercss.node +0 -0
  2. package/artifacts/mcss +0 -0
  3. package/dist/binding-options.d.ts +14 -0
  4. package/dist/binding-options.js +15 -0
  5. package/dist/binding.d.ts +12 -0
  6. package/dist/binding.js +23 -0
  7. package/dist/browser.d.ts +3 -0
  8. package/dist/browser.js +3 -0
  9. package/dist/compiler-binding-adapter.js +55 -0
  10. package/dist/compiler-binding-browser.d.ts +6 -0
  11. package/dist/compiler-binding-browser.js +24 -0
  12. package/dist/compiler-binding-contract.d.ts +45 -0
  13. package/dist/compiler-binding-node.d.ts +5 -0
  14. package/dist/compiler-binding-node.js +20 -0
  15. package/dist/compiler-binding-wasm.js +58 -0
  16. package/dist/compiler-binding.d.ts +6 -0
  17. package/dist/compiler-binding.js +42 -0
  18. package/dist/compiler.js +52 -0
  19. package/dist/engine-binding-adapter.js +61 -0
  20. package/dist/engine-binding-browser.d.ts +8 -0
  21. package/dist/engine-binding-browser.js +35 -0
  22. package/dist/engine-binding-js.js +81 -0
  23. package/dist/engine-binding-node.d.ts +9 -0
  24. package/dist/engine-binding-node.js +38 -0
  25. package/dist/engine-binding-wasm.js +64 -0
  26. package/dist/engine-binding.d.ts +40 -0
  27. package/dist/engine-binding.js +57 -0
  28. package/dist/engine-contract.d.ts +14 -0
  29. package/dist/engine-js/src/animation.js +154 -0
  30. package/dist/engine-js/src/apply.js +207 -0
  31. package/dist/engine-js/src/class-syntax.js +333 -0
  32. package/dist/engine-js/src/condition.js +440 -0
  33. package/dist/engine-js/src/css-syntax.js +247 -0
  34. package/dist/engine-js/src/generate.js +288 -0
  35. package/dist/engine-js/src/mixin.js +328 -0
  36. package/dist/engine-js/src/native-properties.js +5 -0
  37. package/dist/engine-js/src/order.js +97 -0
  38. package/dist/engine-js/src/program-model.js +19 -0
  39. package/dist/engine-js/src/program.js +434 -0
  40. package/dist/engine-js/src/selector.js +195 -0
  41. package/dist/engine-js/src/session.js +540 -0
  42. package/dist/engine-js/src/state.js +62 -0
  43. package/dist/engine-js/src/text.js +51 -0
  44. package/dist/engine-js/src/utility.js +236 -0
  45. package/dist/engine-js/src/value.js +254 -0
  46. package/dist/engine.js +86 -0
  47. package/dist/errors.js +10 -0
  48. package/dist/index.d.ts +4 -0
  49. package/dist/index.js +3 -0
  50. package/dist/native-loader.js +134 -0
  51. package/dist/normalize-error.js +63 -0
  52. package/dist/protocol.d.ts +1119 -0
  53. package/dist/protocol.js +14 -0
  54. package/dist/tooling-binding-adapter.js +23 -0
  55. package/dist/tooling-binding-browser.d.ts +5 -0
  56. package/dist/tooling-binding-browser.js +15 -0
  57. package/dist/tooling-binding-contract.d.ts +92 -0
  58. package/dist/tooling-binding-native.js +46 -0
  59. package/dist/tooling-binding-node.d.ts +4 -0
  60. package/dist/tooling-binding-node.js +11 -0
  61. package/dist/tooling-binding-wasm.js +127 -0
  62. package/dist/tooling-binding.d.ts +5 -0
  63. package/dist/tooling-binding.js +21 -0
  64. package/dist/tooling.js +144 -0
  65. package/dist/version.js +3 -0
  66. package/package.json +78 -0
@@ -0,0 +1,333 @@
1
+ import { isAsciiCase, isAsciiDigit, isAsciiWhitespace, trim } from "./text.js";
2
+ import { readName, startsIdentifier, tokenize } from "./css-syntax.js";
3
+ // ../engine-js/src/class-syntax.ts
4
+ const isOpen = (unit) => unit === 40 || unit === 91 || unit === 123;
5
+ const isClose = (unit) => unit === 41 || unit === 93 || unit === 125;
6
+ const isQuote = (unit) => unit === 34 || unit === 39;
7
+ /**
8
+ * Balanced native content outside strings, escapes and comments, or undefined. With
9
+ * `decode`, Master's `|` separators become spaces.
10
+ */
11
+ function content(source, decode) {
12
+ let result = "";
13
+ let copied = 0;
14
+ const stack = [];
15
+ let quote = 0;
16
+ let escaped = false;
17
+ let comment = false;
18
+ for (let index = 0; index < source.length; index++) {
19
+ const unit = source.charCodeAt(index);
20
+ if (comment) {
21
+ if (unit === 42 && source.charCodeAt(index + 1) === 47) {
22
+ index++;
23
+ comment = false;
24
+ }
25
+ } else if (escaped) escaped = false;
26
+ else if (unit === 92) escaped = true;
27
+ else if (quote) {
28
+ if (unit === quote) quote = 0;
29
+ } else if (unit === 47 && source.charCodeAt(index + 1) === 42) {
30
+ index++;
31
+ comment = true;
32
+ } else if (isQuote(unit)) quote = unit;
33
+ else if (unit === 40 || unit === 91) stack.push(unit);
34
+ else if (unit === 41) {
35
+ if (stack.pop() !== 40) return;
36
+ } else if (unit === 93) {
37
+ if (stack.pop() !== 91) return;
38
+ } else if ((unit === 123 || unit === 125 || unit === 59) && !stack.length) return;
39
+ else if (decode && unit === 124) {
40
+ result += `${source.slice(copied, index)} `;
41
+ copied = index + 1;
42
+ }
43
+ }
44
+ return !stack.length && !quote && !escaped && !comment ? result + source.slice(copied) : void 0;
45
+ }
46
+ const nativeContent = (source) => content(source, false);
47
+ const decodeNativeContent = (source) => content(source, true);
48
+ /** The characters that may begin a class suffix after a complete head. */
49
+ const isClassSuffixStart = (character) => "!*>+~:[@_.#".includes(character);
50
+ /** Whether a matched name may end here: the rest is empty or starts a state. */
51
+ function isMatchStateBoundary(rest) {
52
+ return !rest.length || isClassSuffixStart(rest[0]);
53
+ }
54
+ /** The property range of a `(property:` prefix, the value start once its colon exists and whether the decoded property is custom. */
55
+ function nativeDeclarationPrefix(source) {
56
+ if (source.charCodeAt(0) !== 40 || !startsIdentifier(source, 1)) return;
57
+ const [end, property] = readName(source, 1);
58
+ if (property === "--") return;
59
+ return [
60
+ [1, end],
61
+ source.charCodeAt(end) === 58 ? end + 1 : void 0,
62
+ property.startsWith("--")
63
+ ];
64
+ }
65
+ /** The end of the string whose quote is at `start`, or undefined when it is unclosed or broken by a newline. */
66
+ function skipString(source, start) {
67
+ const quote = source.charCodeAt(start);
68
+ for (let cursor = start + 1; cursor < source.length; cursor++) {
69
+ const unit = source.charCodeAt(cursor);
70
+ if (unit === 92) {
71
+ cursor++;
72
+ if (cursor >= source.length) return;
73
+ } else if (unit === 10 || unit === 13 || unit === 12) return;
74
+ else if (unit === quote) return cursor + 1;
75
+ }
76
+ }
77
+ /**
78
+ * The end of an unquoted `url(` token whose contents start at `start`; brackets, braces
79
+ * and pipes are URL text. Only CSS whitespace before `)` and non-printable code points
80
+ * end it badly; other Unicode, including U+00A0 and U+0085, is URL text.
81
+ */
82
+ function skipUrl(source, start) {
83
+ for (let cursor = start; cursor < source.length; cursor++) {
84
+ const unit = source.charCodeAt(cursor);
85
+ if (unit === 41) return cursor + 1;
86
+ if (unit === 92 && startsIdentifier(source, cursor)) cursor++;
87
+ else if (isAsciiWhitespace(unit)) {
88
+ while (cursor < source.length && isAsciiWhitespace(source.charCodeAt(cursor))) cursor++;
89
+ return source.charCodeAt(cursor) === 41 ? cursor + 1 : void 0;
90
+ } else if (isQuote(unit) || unit === 40 || unit === 92 || unit < 32 || unit === 127) return;
91
+ }
92
+ }
93
+ const OTHER_ITEM = -1;
94
+ const IMPORTANT_ITEM = -2;
95
+ /**
96
+ * The closing parenthesis and top-level items of a declaration value. A bang is the end
97
+ * of the last component before it, so a trailing `!important` never trims into an escape.
98
+ */
99
+ function scanValue(source, start, custom) {
100
+ const stack = [];
101
+ const items = [];
102
+ let componentEnd = start;
103
+ let cursor = start;
104
+ while (cursor < source.length) {
105
+ const unit = source.charCodeAt(cursor);
106
+ const top = !stack.length;
107
+ if (isQuote(unit)) {
108
+ const end = skipString(source, cursor);
109
+ if (end === void 0) return;
110
+ cursor = componentEnd = end;
111
+ if (top) items.push(OTHER_ITEM);
112
+ continue;
113
+ }
114
+ if (unit === 47 && source.charCodeAt(cursor + 1) === 42) {
115
+ const end = source.indexOf("*/", cursor + 2);
116
+ if (end < 0) return;
117
+ cursor = componentEnd = end + 2;
118
+ continue;
119
+ }
120
+ if (startsIdentifier(source, cursor)) {
121
+ const [end, ident] = readName(source, cursor);
122
+ cursor = end;
123
+ if (source.charCodeAt(cursor) === 40) {
124
+ cursor++;
125
+ if (isAsciiCase(ident, "url") && !isQuote(source.charCodeAt(cursor))) {
126
+ const url = skipUrl(source, cursor);
127
+ if (url === void 0) return;
128
+ cursor = url;
129
+ } else stack.push(41);
130
+ if (top) items.push(OTHER_ITEM);
131
+ } else if (top) items.push(isAsciiCase(ident, "important") ? IMPORTANT_ITEM : OTHER_ITEM);
132
+ componentEnd = cursor;
133
+ continue;
134
+ }
135
+ if (unit === 124 || isAsciiWhitespace(unit)) {
136
+ cursor++;
137
+ continue;
138
+ }
139
+ if (unit === 92) return;
140
+ if (isOpen(unit)) {
141
+ if (unit === 123 && top && !custom) return;
142
+ stack.push(unit === 40 ? 41 : unit === 91 ? 93 : 125);
143
+ if (top) items.push(OTHER_ITEM);
144
+ } else if (unit === 41 && top) return [cursor, items];
145
+ else if (isClose(unit)) {
146
+ if (stack.pop() !== unit) return;
147
+ } else if (unit === 59 && top) return;
148
+ else if (unit === 33 && top) items.push(componentEnd);
149
+ else if (top) items.push(OTHER_ITEM);
150
+ cursor++;
151
+ componentEnd = cursor;
152
+ }
153
+ }
154
+ /**
155
+ * Parses a class that starts with `(` as exactly one native declaration: undefined for
156
+ * other classes, null for a malformed declaration, which never becomes another head.
157
+ */
158
+ function parseNativeDeclaration(source) {
159
+ if (source.charCodeAt(0) !== 40) return;
160
+ const prefix = nativeDeclarationPrefix(source);
161
+ if (!prefix || prefix[1] === void 0) return null;
162
+ const [property, start, custom] = prefix;
163
+ const scan = scanValue(source, start, custom);
164
+ if (!scan) return null;
165
+ const [close, items] = scan;
166
+ const bang = items.length >= 2 && items[items.length - 1] === IMPORTANT_ITEM ? items[items.length - 2] : -1;
167
+ const important = bang >= 0;
168
+ const valueEnd = important ? Math.max(bang, start) : close;
169
+ if (!custom && items.length === (important ? 2 : 0)) return null;
170
+ const suffixStart = close + 1;
171
+ if (suffixStart < source.length && !isClassSuffixStart(source[suffixStart])) return null;
172
+ return {
173
+ property,
174
+ value: [start, valueEnd],
175
+ important,
176
+ suffixStart
177
+ };
178
+ }
179
+ /** Decodes Master's `|` value spaces outside strings, comments, escapes and URL tokens. */
180
+ function decodeNativeValue(value) {
181
+ let output = "";
182
+ let cursor = 0;
183
+ while (cursor < value.length) {
184
+ const start = cursor;
185
+ const unit = value.charCodeAt(cursor);
186
+ if (isQuote(unit)) cursor = skipString(value, cursor) ?? value.length;
187
+ else if (unit === 47 && value.charCodeAt(cursor + 1) === 42) {
188
+ const end = value.indexOf("*/", cursor + 2);
189
+ cursor = end < 0 ? value.length : end + 2;
190
+ } else if (startsIdentifier(value, cursor)) {
191
+ const [end, ident] = readName(value, cursor);
192
+ cursor = end;
193
+ if (isAsciiCase(ident, "url") && value.charCodeAt(cursor) === 40 && !isQuote(value.charCodeAt(cursor + 1))) cursor = skipUrl(value, cursor + 1) ?? value.length;
194
+ } else if (unit === 124) {
195
+ output += " ";
196
+ cursor++;
197
+ continue;
198
+ } else cursor++;
199
+ output += value.slice(start, cursor);
200
+ }
201
+ return output;
202
+ }
203
+ /** Whether a class has a complete head and a structurally balanced suffix. */
204
+ function validClassStructure(className) {
205
+ const source = className.endsWith("!") ? className.slice(0, -1) : className;
206
+ const head = parseNativeDeclaration(source);
207
+ if (head === null) return false;
208
+ return decodeNativeContent(head ? source.slice(head.suffixStart) : className) !== void 0;
209
+ }
210
+ /** Splits a dynamic value from the state that follows it at the first top-level state character. */
211
+ function splitDynamicValueState(value) {
212
+ let quote = 0;
213
+ let escaped = false;
214
+ let depth = 0;
215
+ for (let index = 0; index < value.length; index++) {
216
+ const unit = value.charCodeAt(index);
217
+ if (escaped) {
218
+ escaped = false;
219
+ continue;
220
+ }
221
+ if (unit === 92) {
222
+ escaped = true;
223
+ continue;
224
+ }
225
+ if (quote) {
226
+ if (unit === quote) quote = 0;
227
+ continue;
228
+ }
229
+ if (isQuote(unit)) {
230
+ quote = unit;
231
+ continue;
232
+ }
233
+ if (unit === 91 && !depth) return [value.slice(0, index), value.slice(index)];
234
+ if (isOpen(unit)) {
235
+ depth++;
236
+ continue;
237
+ }
238
+ if (isClose(unit)) {
239
+ if (depth) depth--;
240
+ continue;
241
+ }
242
+ if (depth) continue;
243
+ let startsState;
244
+ if (unit === 46) startsState = !isAsciiDigit(value.charCodeAt(index + 1));
245
+ else if (unit === 35) {
246
+ const previous = value.charCodeAt(index - 1);
247
+ startsState = index > 0 && previous !== 124 && previous !== 32;
248
+ } else startsState = "!*>+~:@_".includes(value[index]);
249
+ if (startsState) return [value.slice(0, index), value.slice(index)];
250
+ }
251
+ return [value, ""];
252
+ }
253
+ function hasTopLevelValueSeparator(value) {
254
+ let quote = 0;
255
+ let escaped = false;
256
+ let depth = 0;
257
+ for (let index = 0; index < value.length; index++) {
258
+ const unit = value.charCodeAt(index);
259
+ if (escaped) escaped = false;
260
+ else if (unit === 92) escaped = true;
261
+ else if (quote) {
262
+ if (unit === quote) quote = 0;
263
+ } else if (isQuote(unit)) quote = unit;
264
+ else if (isOpen(unit)) depth++;
265
+ else if (isClose(unit)) {
266
+ if (depth) depth--;
267
+ } else if (unit === 124 && !depth) return true;
268
+ }
269
+ return false;
270
+ }
271
+ /** Splits `source` at each top-level `delimiter`. */
272
+ function splitTopLevel(source, delimiter) {
273
+ const result = [];
274
+ const separator = delimiter.charCodeAt(0);
275
+ let start = 0;
276
+ let depth = 0;
277
+ let quote = 0;
278
+ let escaped = false;
279
+ for (let index = 0; index < source.length; index++) {
280
+ const unit = source.charCodeAt(index);
281
+ if (escaped) escaped = false;
282
+ else if (unit === 92) escaped = true;
283
+ else if (quote) {
284
+ if (unit === quote) quote = 0;
285
+ } else if (isQuote(unit)) quote = unit;
286
+ else if (isOpen(unit)) depth++;
287
+ else if (isClose(unit)) {
288
+ if (depth) depth--;
289
+ } else if (unit === separator && !depth) {
290
+ result.push(source.slice(start, index));
291
+ start = index + 1;
292
+ }
293
+ }
294
+ result.push(source.slice(start));
295
+ return result;
296
+ }
297
+ /** Splits a state token into its selector and the conditions after each top-level `@`. */
298
+ function splitStateToken(stateToken) {
299
+ const parts = splitTopLevel(stateToken, "@");
300
+ return [parts[0], parts.slice(1).filter((condition, index) => condition || index < parts.length - 2)];
301
+ }
302
+ /** A functional class head, `name(arguments)` before its suffix; undefined when the class does not start with a function. */
303
+ function parseFunctionalClass(source) {
304
+ const tokens = tokenize(source);
305
+ const first = tokens[0];
306
+ if (first?.kind !== 3) return;
307
+ if (first.close < 0) return "Unclosed mixin argument list";
308
+ const close = first.close;
309
+ const suffixStart = tokens[close].end;
310
+ const suffix = source.slice(suffixStart);
311
+ if (suffix && !isClassSuffixStart(suffix[0])) return "Invalid suffix after mixin arguments";
312
+ const argumentsStart = first.end;
313
+ const argumentsEnd = tokens[close].start;
314
+ const ranges = [];
315
+ if (trim(source.slice(argumentsStart, argumentsEnd))) {
316
+ let start = argumentsStart;
317
+ for (let index = 1; index < close; index++) {
318
+ const token = tokens[index];
319
+ if (token.kind === 8 && token.value === ",") {
320
+ ranges.push([start, token.start]);
321
+ start = token.end;
322
+ } else if (token.close >= 0) index = token.close;
323
+ }
324
+ ranges.push([start, argumentsEnd]);
325
+ if (ranges.some(([start, end]) => !trim(source.slice(start, end)))) return "Empty mixin argument";
326
+ }
327
+ return {
328
+ name: first.value,
329
+ arguments: ranges.map(([start, end]) => source.slice(start, end)),
330
+ suffix
331
+ };
332
+ }
333
+ export { decodeNativeContent, decodeNativeValue, hasTopLevelValueSeparator, isClassSuffixStart, isMatchStateBoundary, isQuote, nativeContent, parseFunctionalClass, parseNativeDeclaration, splitDynamicValueState, splitStateToken, splitTopLevel, validClassStructure };