@animus-ui/layergate 0.0.0-stage → 0.1.35

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 (46) hide show
  1. package/README.md +239 -2
  2. package/dist/compile-C4GyCiuY.cjs +323 -0
  3. package/dist/compile-Cu_GFS3l.mjs +295 -0
  4. package/dist/compile-DZwVBjTM.d.cts +126 -0
  5. package/dist/compile-DZwVBjTM.d.cts.map +1 -0
  6. package/dist/compile-DZwVBjTM.d.mts +126 -0
  7. package/dist/compile-DZwVBjTM.d.mts.map +1 -0
  8. package/dist/host-BGcb1rMJ.mjs +169 -0
  9. package/dist/host-C4ZaMdkx.cjs +210 -0
  10. package/dist/index.cjs +6 -0
  11. package/dist/index.d.cts +3 -0
  12. package/dist/index.d.mts +3 -0
  13. package/dist/index.mjs +3 -0
  14. package/dist/plan-Bsn_yxS9.mjs +29 -0
  15. package/dist/plan-hvk04qzh.cjs +40 -0
  16. package/dist/plan-w-y0limy.d.cts +35 -0
  17. package/dist/plan-w-y0limy.d.cts.map +1 -0
  18. package/dist/plan-w-y0limy.d.mts +35 -0
  19. package/dist/plan-w-y0limy.d.mts.map +1 -0
  20. package/dist/sheet-BUnyt5Jt.cjs +576 -0
  21. package/dist/sheet-DJGhbeYI.mjs +571 -0
  22. package/dist/vite.cjs +295 -0
  23. package/dist/vite.d.cts +59 -0
  24. package/dist/vite.d.cts.map +1 -0
  25. package/dist/vite.d.mts +59 -0
  26. package/dist/vite.d.mts.map +1 -0
  27. package/dist/vite.mjs +290 -0
  28. package/dist/webpack-loader.cjs +104 -0
  29. package/dist/webpack-loader.d.cts +35 -0
  30. package/dist/webpack-loader.d.cts.map +1 -0
  31. package/dist/webpack-loader.d.mts +36 -0
  32. package/dist/webpack-loader.d.mts.map +1 -0
  33. package/dist/webpack-loader.mjs +104 -0
  34. package/dist/webpack-state-BpF2PPjA.d.cts +15 -0
  35. package/dist/webpack-state-BpF2PPjA.d.cts.map +1 -0
  36. package/dist/webpack-state-BtmtzsWZ.cjs +61 -0
  37. package/dist/webpack-state-CXoQQ7XR.d.mts +15 -0
  38. package/dist/webpack-state-CXoQQ7XR.d.mts.map +1 -0
  39. package/dist/webpack-state-DwltSkQq.mjs +44 -0
  40. package/dist/webpack.cjs +161 -0
  41. package/dist/webpack.d.cts +98 -0
  42. package/dist/webpack.d.cts.map +1 -0
  43. package/dist/webpack.d.mts +98 -0
  44. package/dist/webpack.d.mts.map +1 -0
  45. package/dist/webpack.mjs +155 -0
  46. package/package.json +90 -4
@@ -0,0 +1,571 @@
1
+ //#region src/tokenize.ts
2
+ const isNewline = (c) => c === "\n" || c === "\r" || c === "\f";
3
+ const isWhitespace = (c) => c === " " || c === " " || isNewline(c);
4
+ const isDigit = (c) => c !== void 0 && c >= "0" && c <= "9";
5
+ const isHex = (c) => c !== void 0 && (c >= "0" && c <= "9" || c >= "a" && c <= "f" || c >= "A" && c <= "F");
6
+ const isNameStart = (c) => c !== void 0 && (c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c === "_" || c.charCodeAt(0) >= 128);
7
+ const isName = (c) => isNameStart(c) || isDigit(c) || c === "-";
8
+ const isNonPrintable = (c) => {
9
+ if (c === void 0) return false;
10
+ const code = c.charCodeAt(0);
11
+ return code <= 8 || code === 11 || code >= 14 && code <= 31 || code === 127;
12
+ };
13
+ /** Whether the two code points at `at` start a valid escape. */
14
+ function validEscape(css, at) {
15
+ return css[at] === "\\" && !isNewline(css[at + 1]) && at + 1 < css.length;
16
+ }
17
+ /** Whether the three code points at `at` would start an identifier. */
18
+ function startsIdent(css, at) {
19
+ const c = css[at];
20
+ if (c === "-") return isNameStart(css[at + 1]) || css[at + 1] === "-" || validEscape(css, at + 1);
21
+ if (isNameStart(c)) return true;
22
+ return validEscape(css, at);
23
+ }
24
+ /** Whether the three code points at `at` would start a number. */
25
+ function startsNumber(css, at) {
26
+ const c = css[at];
27
+ if (c === "+" || c === "-") return isDigit(css[at + 1]) || css[at + 1] === "." && isDigit(css[at + 2]);
28
+ if (c === ".") return isDigit(css[at + 1]);
29
+ return isDigit(c);
30
+ }
31
+ function tokenize(css) {
32
+ const tokens = [];
33
+ let at = 0;
34
+ /** Consumes an escape after its `\`, returning the code point. */
35
+ const escape = () => {
36
+ let hex = "";
37
+ while (hex.length < 6 && isHex(css[at])) hex += css[at++];
38
+ if (hex) {
39
+ if (css[at] === "\r" && css[at + 1] === "\n") at += 2;
40
+ else if (isWhitespace(css[at])) at += 1;
41
+ const code = Number.parseInt(hex, 16);
42
+ return code === 0 || code >= 55296 && code <= 57343 || code > 1114111 ? "�" : String.fromCodePoint(code);
43
+ }
44
+ if (at >= css.length) return "�";
45
+ const char = String.fromCodePoint(css.codePointAt(at));
46
+ at += char.length;
47
+ return char;
48
+ };
49
+ const name = () => {
50
+ let result = "";
51
+ for (;;) if (isName(css[at])) result += css[at++];
52
+ else if (validEscape(css, at)) {
53
+ at += 1;
54
+ result += escape();
55
+ } else return result;
56
+ };
57
+ const numeric = (start) => {
58
+ if (css[at] === "+" || css[at] === "-") at += 1;
59
+ while (isDigit(css[at])) at += 1;
60
+ if (css[at] === "." && isDigit(css[at + 1])) {
61
+ at += 1;
62
+ while (isDigit(css[at])) at += 1;
63
+ }
64
+ if ((css[at] === "e" || css[at] === "E") && (isDigit(css[at + 1]) || (css[at + 1] === "+" || css[at + 1] === "-") && isDigit(css[at + 2]))) {
65
+ at += 2;
66
+ while (isDigit(css[at])) at += 1;
67
+ }
68
+ const number = css.slice(start, at);
69
+ if (startsIdent(css, at)) {
70
+ const unit = name();
71
+ tokens.push({
72
+ type: "dimension",
73
+ start,
74
+ end: at,
75
+ value: number + unit
76
+ });
77
+ } else if (css[at] === "%") {
78
+ at += 1;
79
+ tokens.push({
80
+ type: "percentage",
81
+ start,
82
+ end: at,
83
+ value: number
84
+ });
85
+ } else tokens.push({
86
+ type: "number",
87
+ start,
88
+ end: at,
89
+ value: number
90
+ });
91
+ };
92
+ const string = (start, quote) => {
93
+ let value = "";
94
+ for (;;) {
95
+ const c = css[at];
96
+ if (c === void 0) break;
97
+ if (c === quote) {
98
+ at += 1;
99
+ break;
100
+ }
101
+ if (isNewline(c)) {
102
+ tokens.push({
103
+ type: "bad-string",
104
+ start,
105
+ end: at,
106
+ value
107
+ });
108
+ return;
109
+ }
110
+ if (c === "\\") {
111
+ if (at + 1 >= css.length) {
112
+ at += 1;
113
+ continue;
114
+ }
115
+ if (isNewline(css[at + 1])) {
116
+ at += css[at + 1] === "\r" && css[at + 2] === "\n" ? 3 : 2;
117
+ continue;
118
+ }
119
+ at += 1;
120
+ value += escape();
121
+ continue;
122
+ }
123
+ value += c;
124
+ at += 1;
125
+ }
126
+ tokens.push({
127
+ type: "string",
128
+ start,
129
+ end: at,
130
+ value
131
+ });
132
+ };
133
+ const badUrlRemnant = () => {
134
+ while (at < css.length) {
135
+ if (css[at] === ")") {
136
+ at += 1;
137
+ return;
138
+ }
139
+ if (validEscape(css, at)) {
140
+ at += 1;
141
+ escape();
142
+ } else at += 1;
143
+ }
144
+ };
145
+ const url = (start) => {
146
+ while (isWhitespace(css[at])) at += 1;
147
+ let value = "";
148
+ for (;;) {
149
+ const c = css[at];
150
+ if (c === void 0) break;
151
+ if (c === ")") {
152
+ at += 1;
153
+ break;
154
+ }
155
+ if (isWhitespace(c)) {
156
+ while (isWhitespace(css[at])) at += 1;
157
+ if (css[at] === ")" || css[at] === void 0) {
158
+ if (css[at] === ")") at += 1;
159
+ break;
160
+ }
161
+ badUrlRemnant();
162
+ tokens.push({
163
+ type: "bad-url",
164
+ start,
165
+ end: at,
166
+ value
167
+ });
168
+ return;
169
+ }
170
+ if (c === "\"" || c === "'" || c === "(" || isNonPrintable(c)) {
171
+ badUrlRemnant();
172
+ tokens.push({
173
+ type: "bad-url",
174
+ start,
175
+ end: at,
176
+ value
177
+ });
178
+ return;
179
+ }
180
+ if (c === "\\") {
181
+ if (validEscape(css, at)) {
182
+ at += 1;
183
+ value += escape();
184
+ continue;
185
+ }
186
+ badUrlRemnant();
187
+ tokens.push({
188
+ type: "bad-url",
189
+ start,
190
+ end: at,
191
+ value
192
+ });
193
+ return;
194
+ }
195
+ value += c;
196
+ at += 1;
197
+ }
198
+ tokens.push({
199
+ type: "url",
200
+ start,
201
+ end: at,
202
+ value
203
+ });
204
+ };
205
+ const identLike = (start) => {
206
+ const value = name();
207
+ if (value.toLowerCase() === "url" && css[at] === "(") {
208
+ at += 1;
209
+ let peek = at;
210
+ while (isWhitespace(css[peek]) && isWhitespace(css[peek + 1])) peek += 1;
211
+ const next = isWhitespace(css[peek]) ? css[peek + 1] : css[peek];
212
+ if (next === "\"" || next === "'") {
213
+ tokens.push({
214
+ type: "function",
215
+ start,
216
+ end: at,
217
+ value
218
+ });
219
+ return;
220
+ }
221
+ url(start);
222
+ return;
223
+ }
224
+ if (css[at] === "(") {
225
+ at += 1;
226
+ tokens.push({
227
+ type: "function",
228
+ start,
229
+ end: at,
230
+ value
231
+ });
232
+ return;
233
+ }
234
+ tokens.push({
235
+ type: "ident",
236
+ start,
237
+ end: at,
238
+ value
239
+ });
240
+ };
241
+ if (css.charCodeAt(0) === 65279) {
242
+ at = 1;
243
+ tokens.push({
244
+ type: "whitespace",
245
+ start: 0,
246
+ end: 1,
247
+ value: ""
248
+ });
249
+ }
250
+ while (at < css.length) {
251
+ const start = at;
252
+ const c = css[at];
253
+ if (c === "/" && css[at + 1] === "*") {
254
+ const close = css.indexOf("*/", at + 2);
255
+ at = close === -1 ? css.length : close + 2;
256
+ tokens.push({
257
+ type: "comment",
258
+ start,
259
+ end: at,
260
+ value: ""
261
+ });
262
+ } else if (isWhitespace(c)) {
263
+ while (isWhitespace(css[at])) at += 1;
264
+ tokens.push({
265
+ type: "whitespace",
266
+ start,
267
+ end: at,
268
+ value: ""
269
+ });
270
+ } else if (c === "\"" || c === "'") {
271
+ at += 1;
272
+ string(start, c);
273
+ } else if (c === "#") {
274
+ if (isName(css[at + 1]) || validEscape(css, at + 1)) {
275
+ at += 1;
276
+ const value = name();
277
+ tokens.push({
278
+ type: "hash",
279
+ start,
280
+ end: at,
281
+ value
282
+ });
283
+ } else {
284
+ at += 1;
285
+ tokens.push({
286
+ type: "delim",
287
+ start,
288
+ end: at,
289
+ value: c
290
+ });
291
+ }
292
+ } else if (c === "(" || c === ")" || c === "[" || c === "]" || c === "{" || c === "}" || c === "," || c === ":" || c === ";") {
293
+ at += 1;
294
+ tokens.push({
295
+ type: c,
296
+ start,
297
+ end: at,
298
+ value: ""
299
+ });
300
+ } else if (c === "+" || c === ".") {
301
+ if (startsNumber(css, at)) numeric(start);
302
+ else {
303
+ at += 1;
304
+ tokens.push({
305
+ type: "delim",
306
+ start,
307
+ end: at,
308
+ value: c
309
+ });
310
+ }
311
+ } else if (c === "-") {
312
+ if (startsNumber(css, at)) numeric(start);
313
+ else if (css[at + 1] === "-" && css[at + 2] === ">") {
314
+ at += 3;
315
+ tokens.push({
316
+ type: "cdc",
317
+ start,
318
+ end: at,
319
+ value: ""
320
+ });
321
+ } else if (startsIdent(css, at)) identLike(start);
322
+ else {
323
+ at += 1;
324
+ tokens.push({
325
+ type: "delim",
326
+ start,
327
+ end: at,
328
+ value: c
329
+ });
330
+ }
331
+ } else if (c === "<" && css.startsWith("!--", at + 1)) {
332
+ at += 4;
333
+ tokens.push({
334
+ type: "cdo",
335
+ start,
336
+ end: at,
337
+ value: ""
338
+ });
339
+ } else if (c === "@") {
340
+ at += 1;
341
+ if (startsIdent(css, at)) {
342
+ const value = name();
343
+ tokens.push({
344
+ type: "at-keyword",
345
+ start,
346
+ end: at,
347
+ value
348
+ });
349
+ } else tokens.push({
350
+ type: "delim",
351
+ start,
352
+ end: at,
353
+ value: c
354
+ });
355
+ } else if (c === "\\") {
356
+ if (validEscape(css, at)) identLike(start);
357
+ else {
358
+ at += 1;
359
+ tokens.push({
360
+ type: "delim",
361
+ start,
362
+ end: at,
363
+ value: c
364
+ });
365
+ }
366
+ } else if (isDigit(c)) numeric(start);
367
+ else if (isNameStart(c)) identLike(start);
368
+ else {
369
+ const char = String.fromCodePoint(css.codePointAt(at));
370
+ at += char.length;
371
+ tokens.push({
372
+ type: "delim",
373
+ start,
374
+ end: at,
375
+ value: char
376
+ });
377
+ }
378
+ }
379
+ return tokens;
380
+ }
381
+ //#endregion
382
+ //#region src/sheet.ts
383
+ /**
384
+ * One stylesheet's structure, read from its tokens: the leading statements
385
+ * (`@charset`, `@import`, `@namespace`, `@layer` statements), the URLs it
386
+ * references and the effects a layer cannot hold back.
387
+ */
388
+ const skippable = (token) => token.type === "whitespace" || token.type === "comment" || token.type === "cdo" || token.type === "cdc";
389
+ /** The index of the first significant token at or after `at`, before `to`. */
390
+ function significant(tokens, at, to = tokens.length) {
391
+ while (at < to && skippable(tokens[at])) at += 1;
392
+ return at;
393
+ }
394
+ function statementEnd(tokens, index) {
395
+ let depth = 0;
396
+ for (let at = index; at < tokens.length; at++) {
397
+ const type = tokens[at].type;
398
+ if (type === "(" || type === "[" || type === "function") depth += 1;
399
+ else if ((type === ")" || type === "]") && depth > 0) depth -= 1;
400
+ else if (depth === 0 && type === ";") return {
401
+ end: at + 1,
402
+ block: false
403
+ };
404
+ else if (depth === 0 && type === "{") return {
405
+ end: tokens.length,
406
+ block: true
407
+ };
408
+ }
409
+ return {
410
+ end: tokens.length,
411
+ block: false
412
+ };
413
+ }
414
+ /** The index of the token closing the function or `(` at `index`. */
415
+ function closing(tokens, index) {
416
+ let depth = 0;
417
+ for (let at = index; at < tokens.length; at++) {
418
+ const type = tokens[at].type;
419
+ if (type === "(" || type === "function") depth += 1;
420
+ else if (type === ")" && --depth === 0) return at;
421
+ }
422
+ return tokens.length - 1;
423
+ }
424
+ /** An `@import`'s URL, layer, supports and media, from the tokens after
425
+ * its at-keyword (`from`) through its `;` (`to`, exclusive). */
426
+ function readImport(css, tokens, from, to) {
427
+ const start = tokens[from - 1].start;
428
+ const last = tokens[to - 1];
429
+ const end = last.end;
430
+ let at = significant(tokens, from, to);
431
+ const target = tokens[at];
432
+ if (!target || at >= to) return null;
433
+ let url;
434
+ if (target.type === "string" || target.type === "url") {
435
+ url = target.value;
436
+ at += 1;
437
+ } else if (target.type === "function" && target.value.toLowerCase() === "url") {
438
+ const close = closing(tokens, at);
439
+ const inner = tokens[significant(tokens, at + 1, close)];
440
+ if (inner?.type !== "string") return null;
441
+ url = inner.value;
442
+ at = close + 1;
443
+ } else return null;
444
+ let layer = { kind: "none" };
445
+ at = significant(tokens, at, to);
446
+ let token = tokens[at];
447
+ if (token?.type === "ident" && token.value.toLowerCase() === "layer") {
448
+ layer = { kind: "anonymous" };
449
+ at += 1;
450
+ } else if (token?.type === "function" && token.value.toLowerCase() === "layer") {
451
+ const close = closing(tokens, at);
452
+ layer = {
453
+ kind: "named",
454
+ name: css.slice(token.end, tokens[close].start).trim()
455
+ };
456
+ at = close + 1;
457
+ }
458
+ let supports = null;
459
+ at = significant(tokens, at, to);
460
+ token = tokens[at];
461
+ if (token?.type === "function" && token.value.toLowerCase() === "supports") {
462
+ const close = closing(tokens, at);
463
+ supports = css.slice(token.end, tokens[close].start).trim();
464
+ at = close + 1;
465
+ }
466
+ at = significant(tokens, at, to);
467
+ token = tokens[at];
468
+ const mediaEnd = last.type === ";" ? last.start : end;
469
+ const media = token && at < to && token.type !== ";" ? css.slice(token.start, mediaEnd).trim() : "";
470
+ return {
471
+ start,
472
+ end,
473
+ url,
474
+ layer,
475
+ supports,
476
+ media
477
+ };
478
+ }
479
+ function readSheet(css) {
480
+ const tokens = tokenize(css);
481
+ const sheet = {
482
+ imports: [],
483
+ removed: [],
484
+ namespaces: [],
485
+ urls: [],
486
+ important: [],
487
+ keyframes: [],
488
+ animations: [],
489
+ ignoredImports: [],
490
+ layers: []
491
+ };
492
+ if (css.charCodeAt(0) === 65279) sheet.removed.push([0, 1]);
493
+ let index = significant(tokens, 0);
494
+ let leading = 0;
495
+ while (index < tokens.length) {
496
+ const token = tokens[index];
497
+ const name = token.type === "at-keyword" ? token.value.toLowerCase() : "";
498
+ if (name !== "charset" && name !== "import" && name !== "namespace" && name !== "layer") break;
499
+ const { end, block } = statementEnd(tokens, index);
500
+ if (block) break;
501
+ const span = [token.start, tokens[end - 1].end];
502
+ if (name === "charset") sheet.removed.push(span);
503
+ else if (name === "import") {
504
+ const statement = readImport(css, tokens, index + 1, end);
505
+ if (statement) sheet.imports.push(statement);
506
+ sheet.removed.push(span);
507
+ } else if (name === "namespace") sheet.namespaces.push(token.start);
508
+ index = significant(tokens, end);
509
+ leading = index;
510
+ }
511
+ let previous;
512
+ let depth = 0;
513
+ for (let at = 0; at < tokens.length; at++) {
514
+ const token = tokens[at];
515
+ if (token.type === "{") depth += 1;
516
+ else if (token.type === "}" && depth > 0) depth -= 1;
517
+ else if (depth === 0 && token.type === "at-keyword") {
518
+ const name = token.value.toLowerCase();
519
+ if (name === "layer") {
520
+ let to = at + 1;
521
+ while (to < tokens.length && tokens[to].type !== "{" && tokens[to].type !== ";") to += 1;
522
+ const names = css.slice(token.end, tokens[to]?.start ?? css.length).split(",").map((part) => part.trim()).filter(Boolean);
523
+ sheet.layers.push({
524
+ at: token.start,
525
+ names
526
+ });
527
+ } else if (name === "import" && at >= leading) sheet.ignoredImports.push(token.start);
528
+ }
529
+ if (at < leading && sheet.removed.some(([from, to]) => token.start >= from && token.start < to)) continue;
530
+ if (token.type === "url") sheet.urls.push({
531
+ start: token.start,
532
+ end: token.end,
533
+ url: token.value,
534
+ kind: "token"
535
+ });
536
+ else if (token.type === "function") {
537
+ const fn = token.value.toLowerCase();
538
+ if (fn === "url" || fn === "src") {
539
+ const inner = tokens[significant(tokens, at + 1, closing(tokens, at))];
540
+ if (inner?.type === "string") sheet.urls.push({
541
+ start: inner.start,
542
+ end: inner.end,
543
+ url: inner.value,
544
+ kind: "string"
545
+ });
546
+ } else if (fn === "image-set" || fn === "-webkit-image-set") {
547
+ const close = closing(tokens, at);
548
+ let nesting = 0;
549
+ for (let inner = at + 1; inner < close; inner++) {
550
+ const candidate = tokens[inner];
551
+ if (candidate.type === "(" || candidate.type === "function") nesting += 1;
552
+ else if (candidate.type === ")") nesting -= 1;
553
+ else if (nesting === 0 && candidate.type === "string") sheet.urls.push({
554
+ start: candidate.start,
555
+ end: candidate.end,
556
+ url: candidate.value,
557
+ kind: "string"
558
+ });
559
+ }
560
+ }
561
+ } else if (token.type === "delim" && token.value === "!") {
562
+ const next = tokens[significant(tokens, at + 1)];
563
+ if (next?.type === "ident" && next.value.toLowerCase() === "important") sheet.important.push(token.start);
564
+ } else if (token.type === "at-keyword" && /^(-[a-z]+-)?keyframes$/i.test(token.value)) sheet.keyframes.push(token.start);
565
+ else if (token.type === "ident" && /^(-[a-z]+-)?animation(-name)?$/i.test(token.value) && (previous?.type === "{" || previous?.type === ";") && tokens[significant(tokens, at + 1)]?.type === ":") sheet.animations.push(token.start);
566
+ if (!skippable(token)) previous = token;
567
+ }
568
+ return sheet;
569
+ }
570
+ //#endregion
571
+ export { readSheet as t };