@lipsjs/lips 0.3.1 → 0.5.0

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 (55) hide show
  1. package/README.md +122 -9
  2. package/dist/lips.js +917 -669
  3. package/dist/lips.js.map +15 -12
  4. package/dist/lips.min.js +12 -12
  5. package/dist/lips.min.js.map +15 -12
  6. package/dist/lynx-background.min.js +3 -0
  7. package/dist/lynx-background.min.js.map +13 -0
  8. package/dist/lynx-main.min.js +3 -0
  9. package/dist/lynx-main.min.js.map +11 -0
  10. package/dist/lynx-plugin.mjs +1487 -0
  11. package/dist/lynx.min.js +8 -8
  12. package/dist/lynx.min.js.map +12 -10
  13. package/dist/mf2.min.js.map +1 -1
  14. package/dist/parts.min.js +100 -0
  15. package/dist/parts.min.js.map +19 -0
  16. package/dist/precompile.min.js +15 -15
  17. package/dist/precompile.min.js.map +8 -7
  18. package/dist/runtime.min.js +4 -4
  19. package/dist/runtime.min.js.map +11 -9
  20. package/dist/stylis.min.js.map +1 -1
  21. package/dist/types/component.d.ts +32 -0
  22. package/dist/types/ir/compiler.d.ts +2 -4
  23. package/dist/types/ir/facade.d.ts +63 -12
  24. package/dist/types/ir/host.d.ts +9 -1
  25. package/dist/types/ir/initial.d.ts +16 -0
  26. package/dist/types/ir/router.d.ts +2 -0
  27. package/dist/types/ir/tags.d.ts +16 -0
  28. package/dist/types/lips.d.ts +7 -7
  29. package/dist/types/lynx/a11y.d.ts +1 -0
  30. package/dist/types/lynx/background.d.ts +52 -3
  31. package/dist/types/lynx/components.d.ts +28 -0
  32. package/dist/types/lynx/main.d.ts +9 -5
  33. package/dist/types/lynx/plugin.d.ts +8 -0
  34. package/dist/types/lynx/protocol.d.ts +55 -4
  35. package/dist/types/lynx/style.d.ts +7 -0
  36. package/dist/types/lynx/template.d.ts +6 -0
  37. package/dist/types/lynx.d.ts +1 -0
  38. package/dist/types/parts/combobox.d.ts +40 -0
  39. package/dist/types/parts/date.d.ts +75 -0
  40. package/dist/types/parts/dialog.d.ts +42 -0
  41. package/dist/types/parts/icon.d.ts +31 -0
  42. package/dist/types/parts/layer.d.ts +28 -0
  43. package/dist/types/parts/list.d.ts +45 -0
  44. package/dist/types/parts/menu.d.ts +44 -0
  45. package/dist/types/parts/popover.d.ts +81 -0
  46. package/dist/types/parts/reveal.d.ts +24 -0
  47. package/dist/types/parts/toast.d.ts +36 -0
  48. package/dist/types/parts.d.ts +24 -0
  49. package/dist/types/precompile.d.ts +8 -11
  50. package/dist/types/runtime.d.ts +1 -0
  51. package/dist/types/types.d.ts +188 -57
  52. package/dist/untrusted.min.js +4 -4
  53. package/dist/untrusted.min.js.map +7 -7
  54. package/package.json +24 -3
  55. package/dist/types/i18n/formatters.d.ts +0 -3
@@ -0,0 +1,1487 @@
1
+ // node_modules/stylis/src/Enum.js
2
+ var COMMENT = "comm";
3
+ var RULESET = "rule";
4
+ var DECLARATION = "decl";
5
+ var IMPORT = "@import";
6
+ var NAMESPACE = "@namespace";
7
+ var KEYFRAMES = "@keyframes";
8
+ var LAYER = "@layer";
9
+
10
+ // node_modules/stylis/src/Utility.js
11
+ var abs = Math.abs;
12
+ var from = String.fromCharCode;
13
+ function trim(value) {
14
+ return value.trim();
15
+ }
16
+ function replace(value, pattern, replacement) {
17
+ return value.replace(pattern, replacement);
18
+ }
19
+ function indexof(value, search, position) {
20
+ return value.indexOf(search, position);
21
+ }
22
+ function charat(value, index) {
23
+ return value.charCodeAt(index) | 0;
24
+ }
25
+ function substr(value, begin, end) {
26
+ return value.slice(begin, end);
27
+ }
28
+ function strlen(value) {
29
+ return value.length;
30
+ }
31
+ function sizeof(value) {
32
+ return value.length;
33
+ }
34
+ function append(value, array) {
35
+ return array.push(value), value;
36
+ }
37
+
38
+ // node_modules/stylis/src/Tokenizer.js
39
+ var line = 1;
40
+ var column = 1;
41
+ var length = 0;
42
+ var position = 0;
43
+ var character = 0;
44
+ var characters = "";
45
+ function node(value, root, parent, type, props, children, length, siblings) {
46
+ return { value, root, parent, type, props, children, line, column, length, return: "", siblings };
47
+ }
48
+ function char() {
49
+ return character;
50
+ }
51
+ function prev() {
52
+ character = position > 0 ? charat(characters, --position) : 0;
53
+ if (column--, character === 10)
54
+ column = 1, line--;
55
+ return character;
56
+ }
57
+ function next() {
58
+ character = position < length ? charat(characters, position++) : 0;
59
+ if (column++, character === 10)
60
+ column = 1, line++;
61
+ return character;
62
+ }
63
+ function peek() {
64
+ return charat(characters, position);
65
+ }
66
+ function caret() {
67
+ return position;
68
+ }
69
+ function slice(begin, end) {
70
+ return substr(characters, begin, end);
71
+ }
72
+ function token(type) {
73
+ switch (type) {
74
+ case 0:
75
+ case 9:
76
+ case 10:
77
+ case 13:
78
+ case 32:
79
+ return 5;
80
+ case 33:
81
+ case 43:
82
+ case 44:
83
+ case 47:
84
+ case 62:
85
+ case 64:
86
+ case 126:
87
+ case 59:
88
+ case 123:
89
+ case 125:
90
+ return 4;
91
+ case 58:
92
+ return 3;
93
+ case 34:
94
+ case 39:
95
+ case 40:
96
+ case 91:
97
+ return 2;
98
+ case 41:
99
+ case 93:
100
+ return 1;
101
+ }
102
+ return 0;
103
+ }
104
+ function alloc(value) {
105
+ return line = column = 1, length = strlen(characters = value), position = 0, [];
106
+ }
107
+ function dealloc(value) {
108
+ return characters = "", value;
109
+ }
110
+ function delimit(type) {
111
+ return trim(slice(position - 1, delimiter(type === 91 ? type + 2 : type === 40 ? type + 1 : type)));
112
+ }
113
+ function whitespace(type) {
114
+ while (character = peek())
115
+ if (character < 33)
116
+ next();
117
+ else
118
+ break;
119
+ return token(type) > 2 || token(character) > 3 ? "" : " ";
120
+ }
121
+ function escaping(index, count) {
122
+ while (--count && next())
123
+ if (character < 48 || character > 102 || character > 57 && character < 65 || character > 70 && character < 97)
124
+ break;
125
+ return slice(index, caret() + (count < 6 && peek() == 32 && next() == 32));
126
+ }
127
+ function delimiter(type) {
128
+ while (next())
129
+ switch (character) {
130
+ case type:
131
+ return position;
132
+ case 34:
133
+ case 39:
134
+ if (type !== 34 && type !== 39)
135
+ delimiter(character);
136
+ break;
137
+ case 40:
138
+ if (type === 41)
139
+ delimiter(type);
140
+ break;
141
+ case 92:
142
+ next();
143
+ break;
144
+ }
145
+ return position;
146
+ }
147
+ function commenter(type, index) {
148
+ while (next())
149
+ if (type + character === 47 + 10)
150
+ break;
151
+ else if (type + character === 42 + 42 && peek() === 47)
152
+ break;
153
+ return "/*" + slice(index, position - 1) + "*" + from(type === 47 ? type : next());
154
+ }
155
+ function identifier(index) {
156
+ while (!token(peek()))
157
+ next();
158
+ return slice(index, position);
159
+ }
160
+
161
+ // node_modules/stylis/src/Parser.js
162
+ function compile(value) {
163
+ return dealloc(parse("", null, null, null, [""], value = alloc(value), 0, [0], value));
164
+ }
165
+ function parse(value, root, parent, rule, rules, rulesets, pseudo, points, declarations) {
166
+ var index = 0;
167
+ var offset = 0;
168
+ var length = pseudo;
169
+ var atrule = 0;
170
+ var property = 0;
171
+ var previous = 0;
172
+ var variable = 1;
173
+ var scanning = 1;
174
+ var ampersand = 1;
175
+ var character = 0;
176
+ var type = "";
177
+ var props = rules;
178
+ var children = rulesets;
179
+ var reference = rule;
180
+ var characters = type;
181
+ while (scanning)
182
+ switch (previous = character, character = next()) {
183
+ case 40:
184
+ if (previous != 108 && charat(characters, length - 1) == 58) {
185
+ if (indexof(characters += replace(delimit(character), "&", "&\f"), "&\f", abs(index ? points[index - 1] : 0)) != -1)
186
+ ampersand = -1;
187
+ break;
188
+ }
189
+ case 34:
190
+ case 39:
191
+ case 91:
192
+ characters += delimit(character);
193
+ break;
194
+ case 9:
195
+ case 10:
196
+ case 13:
197
+ case 32:
198
+ characters += whitespace(previous);
199
+ break;
200
+ case 92:
201
+ characters += escaping(caret() - 1, 7);
202
+ continue;
203
+ case 47:
204
+ switch (peek()) {
205
+ case 42:
206
+ case 47:
207
+ append(comment(commenter(next(), caret()), root, parent, declarations), declarations);
208
+ if ((token(previous || 1) == 5 || token(peek() || 1) == 5) && strlen(characters) && substr(characters, -1, undefined) !== " ")
209
+ characters += " ";
210
+ break;
211
+ default:
212
+ characters += "/";
213
+ }
214
+ break;
215
+ case 123 * variable:
216
+ points[index++] = strlen(characters) * ampersand;
217
+ case 125 * variable:
218
+ case 59:
219
+ case 0:
220
+ switch (character) {
221
+ case 0:
222
+ case 125:
223
+ scanning = 0;
224
+ case 59 + offset:
225
+ if (ampersand == -1)
226
+ characters = replace(characters, /\f/g, "");
227
+ if (property > 0 && (strlen(characters) - length || variable === 0 && previous === 47))
228
+ append(property > 32 ? declaration(characters + ";", rule, parent, length - 1, declarations) : declaration(replace(characters, " ", "") + ";", rule, parent, length - 2, declarations), declarations);
229
+ break;
230
+ case 59:
231
+ characters += ";";
232
+ default:
233
+ append(reference = ruleset(characters, root, parent, index, offset, rules, points, type, props = [], children = [], length, rulesets), rulesets);
234
+ if (character === 123)
235
+ if (offset === 0)
236
+ parse(characters, root, reference, reference, props, rulesets, length, points, children);
237
+ else {
238
+ switch (atrule) {
239
+ case 99:
240
+ if (charat(characters, 3) === 110)
241
+ break;
242
+ case 108:
243
+ if (charat(characters, 2) === 97)
244
+ break;
245
+ default:
246
+ offset = 0;
247
+ case 100:
248
+ case 109:
249
+ case 115:
250
+ }
251
+ if (offset)
252
+ parse(value, reference, reference, rule && append(ruleset(value, reference, reference, 0, 0, rules, points, type, rules, props = [], length, children), children), rules, children, length, points, rule ? props : children);
253
+ else
254
+ parse(characters, reference, reference, reference, [""], children, 0, points, children);
255
+ }
256
+ }
257
+ index = offset = property = 0, variable = ampersand = 1, type = characters = "", length = pseudo;
258
+ break;
259
+ case 58:
260
+ length = 1 + strlen(characters), property = previous;
261
+ default:
262
+ if (variable < 1) {
263
+ if (character == 123)
264
+ --variable;
265
+ else if (character == 125 && variable++ == 0 && prev() == 125)
266
+ continue;
267
+ }
268
+ switch (characters += from(character), character * variable) {
269
+ case 38:
270
+ ampersand = offset > 0 ? 1 : (characters += "\f", -1);
271
+ break;
272
+ case 44:
273
+ points[index++] = (strlen(characters) - 1) * ampersand, ampersand = 1;
274
+ break;
275
+ case 64:
276
+ if (peek() === 45)
277
+ characters += delimit(next());
278
+ atrule = peek(), offset = length = strlen(type = characters += identifier(caret())), character++;
279
+ break;
280
+ case 45:
281
+ if (previous === 45 && strlen(characters) == 2)
282
+ variable = 0;
283
+ }
284
+ }
285
+ return rulesets;
286
+ }
287
+ function ruleset(value, root, parent, index, offset, rules, points, type, props, children, length, siblings) {
288
+ var post = offset - 1;
289
+ var rule = offset === 0 ? rules : [""];
290
+ var size = sizeof(rule);
291
+ for (var i = 0, j = 0, k = 0;i < index; ++i)
292
+ for (var x = 0, y = substr(value, post + 1, post = abs(j = points[i])), z = value;x < size; ++x)
293
+ if (z = trim(j > 0 ? rule[x] + " " + y : replace(y, /&\f/g, rule[x])))
294
+ props[k++] = z;
295
+ return node(value, root, parent, offset === 0 ? RULESET : type, props, children, length, siblings);
296
+ }
297
+ function comment(value, root, parent, siblings) {
298
+ return node(value, root, parent, COMMENT, from(char()), substr(value, 2, -2), 0, siblings);
299
+ }
300
+ function declaration(value, root, parent, length, siblings) {
301
+ return node(value, root, parent, DECLARATION, substr(value, 0, length), substr(value, length + 1, -1), length, siblings);
302
+ }
303
+
304
+ // node_modules/stylis/src/Serializer.js
305
+ function serialize(children, callback) {
306
+ var output = "";
307
+ for (var i = 0;i < children.length; i++)
308
+ output += callback(children[i], i, children, callback) || "";
309
+ return output;
310
+ }
311
+ function stringify(element, index, children, callback) {
312
+ switch (element.type) {
313
+ case LAYER:
314
+ if (element.children.length)
315
+ break;
316
+ case IMPORT:
317
+ case NAMESPACE:
318
+ case DECLARATION:
319
+ return element.return = element.return || element.value;
320
+ case COMMENT:
321
+ return "";
322
+ case KEYFRAMES:
323
+ return element.return = element.value + "{" + serialize(element.children, callback) + "}";
324
+ case RULESET:
325
+ if (!strlen(element.value = element.props.join(",")))
326
+ return "";
327
+ }
328
+ return strlen(children = serialize(element.children, callback)) ? element.return = element.value + "{" + children + "}" : "";
329
+ }
330
+
331
+ // node_modules/stylis/src/Middleware.js
332
+ function middleware(collection) {
333
+ var length = sizeof(collection);
334
+ return function(element, index, children, callback) {
335
+ var output = "";
336
+ for (var i = 0;i < length; i++)
337
+ output += collection[i](element, index, children, callback) || "";
338
+ return output;
339
+ };
340
+ }
341
+
342
+ // src/ir/expression.ts
343
+ var PUNCTS = [
344
+ "===",
345
+ "!==",
346
+ "...",
347
+ "=>",
348
+ "==",
349
+ "!=",
350
+ "<=",
351
+ ">=",
352
+ "&&",
353
+ "||",
354
+ "??",
355
+ "?.",
356
+ "++",
357
+ "--",
358
+ "+=",
359
+ "-=",
360
+ "*=",
361
+ "/=",
362
+ "%=",
363
+ "+",
364
+ "-",
365
+ "*",
366
+ "/",
367
+ "%",
368
+ "<",
369
+ ">",
370
+ "!",
371
+ "?",
372
+ ":",
373
+ ".",
374
+ ",",
375
+ "(",
376
+ ")",
377
+ "[",
378
+ "]",
379
+ "{",
380
+ "}",
381
+ "="
382
+ ];
383
+ function tokenize(src, diagnostics) {
384
+ const tokens = [];
385
+ let i = 0;
386
+ const isIdStart = (c) => /[A-Za-z_$]/.test(c);
387
+ const isIdChar = (c) => /[A-Za-z0-9_$]/.test(c);
388
+ while (i < src.length) {
389
+ const c = src[i];
390
+ if (/\s/.test(c)) {
391
+ i++;
392
+ continue;
393
+ }
394
+ if (/[0-9]/.test(c) || c === "." && /[0-9]/.test(src[i + 1])) {
395
+ const start = i;
396
+ while (i < src.length && /[0-9]/.test(src[i]))
397
+ i++;
398
+ if (src[i] === ".") {
399
+ i++;
400
+ while (i < src.length && /[0-9]/.test(src[i]))
401
+ i++;
402
+ }
403
+ if (src[i] === "e" || src[i] === "E") {
404
+ i++;
405
+ if (src[i] === "+" || src[i] === "-")
406
+ i++;
407
+ while (i < src.length && /[0-9]/.test(src[i]))
408
+ i++;
409
+ }
410
+ tokens.push({ t: "num", value: src.slice(start, i), start, end: i });
411
+ continue;
412
+ }
413
+ if (c === "'" || c === '"') {
414
+ const start = i;
415
+ i++;
416
+ let value = "";
417
+ let closed = false;
418
+ while (i < src.length) {
419
+ const ch = src[i];
420
+ if (ch === "\\") {
421
+ const next = src[i + 1];
422
+ const escapes = { n: `
423
+ `, t: "\t", r: "\r", b: "\b", f: "\f", v: "\v", "0": "\x00" };
424
+ if (next === "u") {
425
+ const hex = src.slice(i + 2, i + 6);
426
+ value += String.fromCharCode(parseInt(hex, 16) || 0);
427
+ i += 6;
428
+ } else {
429
+ value += escapes[next] ?? next;
430
+ i += 2;
431
+ }
432
+ continue;
433
+ }
434
+ if (ch === c) {
435
+ closed = true;
436
+ i++;
437
+ break;
438
+ }
439
+ value += ch;
440
+ i++;
441
+ }
442
+ if (!closed)
443
+ diagnostics.push({ code: "LIPS-E001", message: "Unterminated string literal", loc: { offset: start, length: i - start } });
444
+ tokens.push({ t: "str", value, start, end: i });
445
+ continue;
446
+ }
447
+ if (isIdStart(c)) {
448
+ const start = i;
449
+ while (i < src.length && isIdChar(src[i]))
450
+ i++;
451
+ tokens.push({ t: "id", value: src.slice(start, i), start, end: i });
452
+ continue;
453
+ }
454
+ let punct = PUNCTS.find((p) => src.startsWith(p, i));
455
+ if (punct === "?." && /[0-9]/.test(src[i + 2] ?? ""))
456
+ punct = "?";
457
+ if (punct) {
458
+ tokens.push({ t: "punct", value: punct, start: i, end: i + punct.length });
459
+ i += punct.length;
460
+ continue;
461
+ }
462
+ diagnostics.push({ code: "LIPS-E002", message: `Unexpected character '${c}'`, loc: { offset: i, length: 1 } });
463
+ i++;
464
+ }
465
+ tokens.push({ t: "eof", value: "", start: src.length, end: src.length });
466
+ return tokens;
467
+ }
468
+
469
+ class Parser {
470
+ tokens;
471
+ diagnostics;
472
+ pos = 0;
473
+ constructor(tokens, diagnostics) {
474
+ this.tokens = tokens;
475
+ this.diagnostics = diagnostics;
476
+ }
477
+ peek(offset = 0) {
478
+ return this.tokens[Math.min(this.pos + offset, this.tokens.length - 1)];
479
+ }
480
+ next() {
481
+ return this.tokens[this.pos++] ?? this.tokens[this.tokens.length - 1];
482
+ }
483
+ at(value) {
484
+ const t = this.peek();
485
+ return t.t === "punct" && t.value === value;
486
+ }
487
+ eat(value) {
488
+ if (this.at(value)) {
489
+ this.pos++;
490
+ return true;
491
+ }
492
+ return false;
493
+ }
494
+ error(code, message, token = this.peek()) {
495
+ this.diagnostics.push({ code, message, loc: { offset: token.start, length: Math.max(1, token.end - token.start) } });
496
+ return { t: "error" };
497
+ }
498
+ expect(value, code) {
499
+ if (!this.eat(value))
500
+ this.error(code, `Expected '${value}'`);
501
+ }
502
+ parse() {
503
+ const expr = this.assign();
504
+ if (this.peek().t !== "eof")
505
+ this.error("LIPS-E003", `Unexpected token '${this.peek().value}' after expression`);
506
+ return expr;
507
+ }
508
+ isArrowAhead() {
509
+ const t = this.peek();
510
+ if (t.t === "id") {
511
+ const n = this.peek(1);
512
+ return n.t === "punct" && n.value === "=>";
513
+ }
514
+ if (t.t === "punct" && t.value === "(") {
515
+ let depth = 0, k = 0;
516
+ while (true) {
517
+ const tok = this.peek(k);
518
+ if (tok.t === "eof")
519
+ return false;
520
+ if (tok.t === "punct" && tok.value === "(")
521
+ depth++;
522
+ if (tok.t === "punct" && tok.value === ")") {
523
+ depth--;
524
+ if (depth === 0) {
525
+ const after = this.peek(k + 1);
526
+ return after.t === "punct" && after.value === "=>";
527
+ }
528
+ }
529
+ k++;
530
+ }
531
+ }
532
+ return false;
533
+ }
534
+ assign() {
535
+ if (this.isArrowAhead()) {
536
+ const params = [];
537
+ if (this.peek().t === "id")
538
+ params.push(this.next().value);
539
+ else {
540
+ this.expect("(", "LIPS-E004");
541
+ while (!this.at(")") && this.peek().t !== "eof") {
542
+ const p = this.next();
543
+ if (p.t !== "id")
544
+ return this.error("LIPS-E005", "Invalid arrow parameter", p);
545
+ params.push(p.value);
546
+ if (!this.eat(","))
547
+ break;
548
+ }
549
+ this.expect(")", "LIPS-E004");
550
+ }
551
+ this.expect("=>", "LIPS-E004");
552
+ return { t: "arrow", params, body: this.assign() };
553
+ }
554
+ const target = this.conditional();
555
+ const op = this.peek();
556
+ if (op.t === "punct" && ["=", "+=", "-=", "*=", "/=", "%="].includes(op.value)) {
557
+ if (target.t !== "id" && target.t !== "member")
558
+ return this.error("LIPS-E006", "Invalid assignment target", op);
559
+ this.next();
560
+ return { t: "assign", op: op.value, target, value: this.assign() };
561
+ }
562
+ return target;
563
+ }
564
+ conditional() {
565
+ const test = this.nullish();
566
+ if (this.eat("?")) {
567
+ const cons = this.assign();
568
+ this.expect(":", "LIPS-E007");
569
+ return { t: "cond", test, cons, alt: this.assign() };
570
+ }
571
+ return test;
572
+ }
573
+ nullish() {
574
+ let l = this.or();
575
+ while (this.at("??")) {
576
+ this.next();
577
+ l = { t: "logic", op: "??", l, r: this.or() };
578
+ }
579
+ return l;
580
+ }
581
+ or() {
582
+ let l = this.and();
583
+ while (this.at("||")) {
584
+ this.next();
585
+ l = { t: "logic", op: "||", l, r: this.and() };
586
+ }
587
+ return l;
588
+ }
589
+ and() {
590
+ let l = this.equality();
591
+ while (this.at("&&")) {
592
+ this.next();
593
+ l = { t: "logic", op: "&&", l, r: this.equality() };
594
+ }
595
+ return l;
596
+ }
597
+ equality() {
598
+ let l = this.relational();
599
+ while (["===", "!==", "==", "!="].some((op) => this.at(op))) {
600
+ const op = this.next().value;
601
+ l = { t: "bin", op, l, r: this.relational() };
602
+ }
603
+ return l;
604
+ }
605
+ relational() {
606
+ let l = this.additive();
607
+ while (["<=", ">=", "<", ">"].some((op) => this.at(op))) {
608
+ const op = this.next().value;
609
+ l = { t: "bin", op, l, r: this.additive() };
610
+ }
611
+ return l;
612
+ }
613
+ additive() {
614
+ let l = this.multiplicative();
615
+ while (this.at("+") || this.at("-")) {
616
+ const op = this.next().value;
617
+ l = { t: "bin", op, l, r: this.multiplicative() };
618
+ }
619
+ return l;
620
+ }
621
+ multiplicative() {
622
+ let l = this.unary();
623
+ while (this.at("*") || this.at("/") || this.at("%")) {
624
+ const op = this.next().value;
625
+ l = { t: "bin", op, l, r: this.unary() };
626
+ }
627
+ return l;
628
+ }
629
+ unary() {
630
+ if (this.at("!") || this.at("-") || this.at("+")) {
631
+ const op = this.next().value;
632
+ return { t: "unary", op, arg: this.unary() };
633
+ }
634
+ if (this.at("++") || this.at("--")) {
635
+ const op = this.next().value;
636
+ const arg = this.unary();
637
+ if (arg.t !== "id" && arg.t !== "member")
638
+ return this.error("LIPS-E006", "Invalid update target");
639
+ return { t: "update", op, arg, prefix: true };
640
+ }
641
+ return this.postfix();
642
+ }
643
+ postfix() {
644
+ let expr = this.callMember();
645
+ if (this.at("++") || this.at("--")) {
646
+ const op = this.next().value;
647
+ if (expr.t !== "id" && expr.t !== "member")
648
+ return this.error("LIPS-E006", "Invalid update target");
649
+ expr = { t: "update", op, arg: expr, prefix: false };
650
+ }
651
+ return expr;
652
+ }
653
+ callMember() {
654
+ let expr = this.primary();
655
+ while (true) {
656
+ if (this.eat(".")) {
657
+ const prop = this.next();
658
+ if (prop.t !== "id")
659
+ return this.error("LIPS-E008", "Expected property name", prop);
660
+ expr = { t: "member", obj: expr, prop: prop.value, computed: false, optional: false, at: prop.start };
661
+ } else if (this.eat("?.")) {
662
+ if (this.at("(")) {
663
+ expr = { t: "call", callee: expr, args: this.argList(), optional: true };
664
+ } else if (this.eat("[")) {
665
+ const at = this.peek().start;
666
+ const idx = this.assign();
667
+ this.expect("]", "LIPS-E009");
668
+ expr = { t: "member", obj: expr, prop: idx, computed: true, optional: true, at };
669
+ } else {
670
+ const prop = this.next();
671
+ if (prop.t !== "id")
672
+ return this.error("LIPS-E008", "Expected property name", prop);
673
+ expr = { t: "member", obj: expr, prop: prop.value, computed: false, optional: true, at: prop.start };
674
+ }
675
+ } else if (this.eat("[")) {
676
+ const at = this.peek().start;
677
+ const idx = this.assign();
678
+ this.expect("]", "LIPS-E009");
679
+ expr = { t: "member", obj: expr, prop: idx, computed: true, optional: false, at };
680
+ } else if (this.at("(")) {
681
+ expr = { t: "call", callee: expr, args: this.argList(), optional: false };
682
+ } else
683
+ break;
684
+ }
685
+ return expr;
686
+ }
687
+ argList() {
688
+ this.expect("(", "LIPS-E010");
689
+ const args = [];
690
+ while (!this.at(")") && this.peek().t !== "eof") {
691
+ args.push(this.assign());
692
+ if (!this.eat(","))
693
+ break;
694
+ }
695
+ this.expect(")", "LIPS-E010");
696
+ return args;
697
+ }
698
+ primary() {
699
+ const t = this.peek();
700
+ if (t.t === "num") {
701
+ this.next();
702
+ return { t: "lit", v: parseFloat(t.value) };
703
+ }
704
+ if (t.t === "str") {
705
+ this.next();
706
+ return { t: "lit", v: t.value };
707
+ }
708
+ if (t.t === "id") {
709
+ this.next();
710
+ switch (t.value) {
711
+ case "true":
712
+ return { t: "lit", v: true };
713
+ case "false":
714
+ return { t: "lit", v: false };
715
+ case "null":
716
+ return { t: "lit", v: null };
717
+ case "undefined":
718
+ return { t: "lit", v: undefined };
719
+ case "NaN":
720
+ return { t: "lit", v: NaN };
721
+ case "Infinity":
722
+ return { t: "lit", v: Infinity };
723
+ default:
724
+ return { t: "id", name: t.value, at: t.start };
725
+ }
726
+ }
727
+ if (this.eat("(")) {
728
+ const expr = this.assign();
729
+ this.expect(")", "LIPS-E010");
730
+ return expr;
731
+ }
732
+ if (this.eat("[")) {
733
+ const items = [];
734
+ while (!this.at("]") && this.peek().t !== "eof") {
735
+ const spread = this.eat("...");
736
+ items.push({ spread: spread || undefined, value: this.assign() });
737
+ if (!this.eat(","))
738
+ break;
739
+ }
740
+ this.expect("]", "LIPS-E009");
741
+ return { t: "arr", items };
742
+ }
743
+ if (this.eat("{")) {
744
+ const props = [];
745
+ while (!this.at("}") && this.peek().t !== "eof") {
746
+ if (this.eat("...")) {
747
+ props.push({ spread: true, value: this.assign() });
748
+ } else {
749
+ const key = this.next();
750
+ if (key.t !== "id" && key.t !== "str" && key.t !== "num")
751
+ return this.error("LIPS-E011", "Invalid object key", key);
752
+ if (this.eat(":"))
753
+ props.push({ key: String(key.value), value: this.assign(), at: key.start });
754
+ else if (key.t === "id")
755
+ props.push({ key: key.value, value: { t: "id", name: key.value, at: key.start }, at: key.start });
756
+ else
757
+ return this.error("LIPS-E011", "Invalid shorthand property", key);
758
+ }
759
+ if (!this.eat(","))
760
+ break;
761
+ }
762
+ this.expect("}", "LIPS-E011");
763
+ return { t: "obj", props };
764
+ }
765
+ this.next();
766
+ return this.error("LIPS-E012", t.t === "eof" ? "Unexpected end of expression" : `Unexpected token '${t.value}'`, t);
767
+ }
768
+ }
769
+ function parseExpression(src) {
770
+ const diagnostics = [];
771
+ const tokens = tokenize(src, diagnostics);
772
+ const ast = new Parser(tokens, diagnostics).parse();
773
+ return { ast, diagnostics };
774
+ }
775
+ var METAVAR_ROOTS = new Set(["state", "input", "context", "self", "arguments"]);
776
+ function freeRoots(ast) {
777
+ const roots = new Set;
778
+ const walk = (node, shadow) => {
779
+ switch (node.t) {
780
+ case "id":
781
+ !shadow.has(node.name) && roots.add(node.name);
782
+ return;
783
+ case "member":
784
+ walk(node.obj, shadow);
785
+ typeof node.prop !== "string" && walk(node.prop, shadow);
786
+ return;
787
+ case "call":
788
+ walk(node.callee, shadow);
789
+ node.args.forEach((a) => walk(a, shadow));
790
+ return;
791
+ case "unary":
792
+ case "update":
793
+ walk(node.arg, shadow);
794
+ return;
795
+ case "bin":
796
+ case "logic":
797
+ walk(node.l, shadow);
798
+ walk(node.r, shadow);
799
+ return;
800
+ case "cond":
801
+ walk(node.test, shadow);
802
+ walk(node.cons, shadow);
803
+ walk(node.alt, shadow);
804
+ return;
805
+ case "assign":
806
+ walk(node.target, shadow);
807
+ walk(node.value, shadow);
808
+ return;
809
+ case "arrow":
810
+ walk(node.body, new Set([...shadow, ...node.params]));
811
+ return;
812
+ case "arr":
813
+ node.items.forEach((i) => walk(i.value, shadow));
814
+ return;
815
+ case "obj":
816
+ node.props.forEach((p) => walk(p.value, shadow));
817
+ return;
818
+ }
819
+ };
820
+ walk(ast, new Set);
821
+ return [...roots];
822
+ }
823
+ var COMPILE_CACHE = new Map;
824
+ var ENDED = Symbol("lips.ended");
825
+
826
+ // src/ir/style.ts
827
+ var PREPROCESSOR = null;
828
+ var PROP_NAME = /^[-\w]+$/;
829
+ var UNIT = /^(%|[a-zA-Z]+)/;
830
+ var NUMBER_SYNTAX = ["<number>", "0"];
831
+ function skipString(src, i) {
832
+ const q = src[i];
833
+ i++;
834
+ while (i < src.length) {
835
+ if (src[i] === "\\") {
836
+ i += 2;
837
+ continue;
838
+ }
839
+ if (src[i] === q)
840
+ return i + 1;
841
+ i++;
842
+ }
843
+ return i;
844
+ }
845
+ function skipComment(src, i) {
846
+ const end = src.indexOf("*/", i + 2);
847
+ return end < 0 ? src.length : end + 2;
848
+ }
849
+ function skipLine(src, i) {
850
+ const end = src.indexOf(`
851
+ `, i + 2);
852
+ return end < 0 ? src.length : end;
853
+ }
854
+ var quote = (value) => value.replace(/["\\]/g, "\\$&");
855
+ function locOf(src, offset, length) {
856
+ let line = 1, last = -1;
857
+ for (let i = 0;i < offset; i++)
858
+ if (src[i] === `
859
+ `) {
860
+ line++;
861
+ last = i;
862
+ }
863
+ return { line, col: offset - last, offset, length };
864
+ }
865
+ function readInterpolation(src, open) {
866
+ let i = open + 1, nest = 0, question = false, colon = false;
867
+ while (i < src.length) {
868
+ const c = src[i];
869
+ if (c === '"' || c === "'") {
870
+ i = skipString(src, i);
871
+ continue;
872
+ }
873
+ if (c === "{" || c === ";")
874
+ return null;
875
+ if (c === "}")
876
+ break;
877
+ if (c === "(" || c === "[")
878
+ nest++;
879
+ else if (c === ")" || c === "]")
880
+ nest--;
881
+ else if (nest === 0) {
882
+ if (c === "?")
883
+ question = true;
884
+ else if (c === ":" && !question)
885
+ colon = true;
886
+ }
887
+ i++;
888
+ }
889
+ if (i >= src.length || colon)
890
+ return null;
891
+ const expr = src.slice(open + 1, i).trim();
892
+ return expr ? { end: i, expr } : null;
893
+ }
894
+ var STYLE_SCOPE = new Set(["state", "input", "static", "context", "self"]);
895
+ function readValue(src, from, keepComments, onUnterminated) {
896
+ const parts = [];
897
+ let i = from, lit = from, paren = 0;
898
+ while (i < src.length) {
899
+ const c = src[i];
900
+ if (c === '"' || c === "'") {
901
+ i = skipString(src, i);
902
+ continue;
903
+ }
904
+ if (c === "/" && src[i + 1] === "*") {
905
+ const end = skipComment(src, i);
906
+ if (!keepComments) {
907
+ parts.push(src.slice(lit, i), " ");
908
+ lit = end;
909
+ }
910
+ i = end;
911
+ continue;
912
+ }
913
+ if (c === "(") {
914
+ paren++;
915
+ i++;
916
+ continue;
917
+ }
918
+ if (c === ")") {
919
+ paren--;
920
+ i++;
921
+ continue;
922
+ }
923
+ if (paren === 0 && (c === ";" || c === "}")) {
924
+ parts.push(src.slice(lit, i));
925
+ return { end: i, parts };
926
+ }
927
+ if (c === "{") {
928
+ const interp = readInterpolation(src, i);
929
+ if (!interp) {
930
+ src.indexOf("}", i + 1) < 0 && onUnterminated?.(i);
931
+ return null;
932
+ }
933
+ parts.push(src.slice(lit, i));
934
+ const m = UNIT.exec(src.slice(interp.end + 1));
935
+ const unit = m ? m[1] : "";
936
+ parts.push({ expr: interp.expr, unit, at: i });
937
+ i = interp.end + 1 + unit.length;
938
+ lit = i;
939
+ continue;
940
+ }
941
+ i++;
942
+ }
943
+ parts.some((p) => typeof p !== "string") && onUnterminated?.(from);
944
+ return null;
945
+ }
946
+ var HOISTED_BLOCK = /^@(-\w+-)?(keyframes|font-face|property|counter-style|font-feature-values|font-palette-values|page|view-transition|position-try|color-profile|function)\b/i;
947
+ var HOISTED_STATEMENT = /^@(import|charset|namespace)\b/i;
948
+ var GROUP_AT = /^@(media|supports|container|layer|scope|starting-style|document)\b/i;
949
+ var TYPE_LEAD = /^([a-zA-Z_*\\]|[^\x00-\x7f])/;
950
+ var LEAD_TOKEN = /^(?:[-\w*|]|[^\x00-\x7f]|\\[\s\S])+/;
951
+ var CONCAT = /&[-_]/;
952
+ var WS = /\s/;
953
+ var BREAK = /[{};]/;
954
+ var IDENT_CHAR = /[-\w]/;
955
+ var QUOTED = /"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'/g;
956
+ var STRING_OR_SPACE = new RegExp(`(${QUOTED.source})|\\s+`, "g");
957
+ var COMMENTS = /\/\*[\s\S]*?\*\//g;
958
+ var LAYER2 = /^@layer\b/i;
959
+ var squash = (text) => text.replace(STRING_OR_SPACE, (_, str) => str || " ");
960
+ function nestSelector(prelude) {
961
+ const parts = [];
962
+ let from = 0, nest = 0;
963
+ for (let i = 0;i < prelude.length; i++) {
964
+ const c = prelude[i];
965
+ if (c === "\\") {
966
+ i++;
967
+ continue;
968
+ }
969
+ if (c === '"' || c === "'") {
970
+ i = skipString(prelude, i) - 1;
971
+ continue;
972
+ }
973
+ if (c === "(" || c === "[")
974
+ nest++;
975
+ else if (c === ")" || c === "]")
976
+ nest--;
977
+ else if (c === "," && !nest) {
978
+ parts.push(prelude.slice(from, i));
979
+ from = i + 1;
980
+ }
981
+ }
982
+ parts.push(prelude.slice(from));
983
+ return parts.map((p) => {
984
+ let s = p.trimStart(), e = s.length;
985
+ while (e && WS.test(s[e - 1]) && s[e - 2] !== "\\")
986
+ e--;
987
+ s = s.slice(0, e);
988
+ if (!TYPE_LEAD.test(s))
989
+ return s;
990
+ return s.includes("&") ? s.replace(LEAD_TOKEN, ":is($&)") : `& ${s}`;
991
+ }).join(",");
992
+ }
993
+ function scan(src, options, native, diagnostics) {
994
+ const exprs = [], binds = [], props = [], prefix = `--${options.nsp.replace(/[^a-zA-Z0-9_-]/g, "-")}`, report = (code, message, offset, length, hint) => diagnostics.push({ code, severity: "error", message, hint, loc: locOf(src, offset, length) }), warn = (code, message, offset, length, hint) => diagnostics.push({ code, severity: "warning", message, hint, loc: locOf(src, offset, length) }), lint = (text, from, to, value) => options.lint?.(text, value)?.forEach((d) => diagnostics.push({ ...d, loc: locOf(src, from, to - from) }));
995
+ const slot = (expr) => {
996
+ let e = exprs.indexOf(expr);
997
+ if (e < 0)
998
+ e = exprs.push(expr) - 1;
999
+ return e;
1000
+ };
1001
+ const checkExpr = (s) => {
1002
+ const { ast, diagnostics: errors } = parseExpression(s.expr);
1003
+ const length = s.expr.length + 2;
1004
+ if (errors.length) {
1005
+ report("LIPS-S004", `Invalid expression: ${errors[0].message}`, s.at, length);
1006
+ return;
1007
+ }
1008
+ for (const name of freeRoots(ast))
1009
+ if (!STYLE_SCOPE.has(name) && !(name in globalThis))
1010
+ report("LIPS-S003", `'${name}' is not readable from a stylesheet`, s.at, length, "Stylesheets see state, input, static, context and self — not <for> iterators or <let> names, " + "which are local to a template position.");
1011
+ s.unit && ast.t === "lit" && typeof ast.v === "string" && warn("LIPS-S005", `Unit '${s.unit}' after a string value`, s.at, length, `A unit suffix multiplies a number: drop the unit, or return ${s.unit === "%" ? "50" : "8"} instead of a string.`);
1012
+ };
1013
+ let out = "", cur = "", tail = "", gap = false;
1014
+ const emit = (text) => {
1015
+ if (!text)
1016
+ return;
1017
+ if (gap && tail && !BREAK.test(tail) && !BREAK.test(text[0]))
1018
+ cur += " ";
1019
+ gap = false;
1020
+ cur += text;
1021
+ tail = text[text.length - 1];
1022
+ };
1023
+ const flush = (end) => {
1024
+ out += cur + end;
1025
+ cur = "";
1026
+ tail = end;
1027
+ gap = false;
1028
+ };
1029
+ const drop = () => {
1030
+ const text = cur;
1031
+ cur = tail = "";
1032
+ gap = false;
1033
+ return text;
1034
+ };
1035
+ const value = (text) => ":" + (squash(text).trim() || " ");
1036
+ let i = 0, paren = 0, stmt = 0, statements = "", hoisted = "", lastGroups = "", unterminated = false;
1037
+ const stack = [{ ctx: options.meta ? "top" : "style" }];
1038
+ const open = () => {
1039
+ const parent = stack[stack.length - 1], prelude = cur;
1040
+ let block;
1041
+ parent.ctx === "opaque" || lint(prelude, stmt, i);
1042
+ if (prelude[0] === "@") {
1043
+ if (parent.ctx !== "opaque" && HOISTED_BLOCK.test(prelude))
1044
+ block = { ctx: "opaque", hoist: out.length };
1045
+ else if (GROUP_AT.test(prelude))
1046
+ block = { ctx: parent.ctx, group: prelude, at: out.length };
1047
+ else
1048
+ block = { ctx: "opaque" };
1049
+ } else {
1050
+ if (parent.ctx === "style") {
1051
+ if (native) {
1052
+ CONCAT.test(prelude.replace(QUOTED, "")) && warn("LIPS-S008", `'${prelude}' joins '&' to a name`, stmt, i - stmt, "Native nesting cannot: write the full selector, or use stylisPreprocessor.");
1053
+ cur = nestSelector(prelude);
1054
+ }
1055
+ }
1056
+ block = { ctx: parent.ctx === "opaque" ? "opaque" : "style" };
1057
+ }
1058
+ stack.push(block);
1059
+ flush("{");
1060
+ block.group && (block.body = out.length);
1061
+ };
1062
+ const close = () => {
1063
+ const block = stack.pop();
1064
+ if (block.group && !cur && out.length === block.body && !LAYER2.test(block.group)) {
1065
+ out = out.slice(0, block.at);
1066
+ tail = "";
1067
+ gap = false;
1068
+ return;
1069
+ }
1070
+ flush("}");
1071
+ if (block.hoist === undefined)
1072
+ return;
1073
+ const text = out.slice(block.hoist), groups = stack.filter((b) => b.group), key = groups.map((b) => b.group).join("{"), shut = "}".repeat(groups.length);
1074
+ out = out.slice(0, block.hoist);
1075
+ tail = "";
1076
+ hoisted = key && key === lastGroups ? hoisted.slice(0, hoisted.length - shut.length) + text + shut : hoisted + groups.map((b) => b.group + "{").join("") + text + shut;
1077
+ lastGroups = key;
1078
+ };
1079
+ while (i < src.length) {
1080
+ const c = src[i];
1081
+ if (c === "\\") {
1082
+ emit(src.slice(i, i + 2));
1083
+ i += 2;
1084
+ continue;
1085
+ }
1086
+ const leading = c === "/" && !src.slice(stmt, i).trim();
1087
+ if (c === "/" && (src[i + 1] === "*" || src[i + 1] === "/" && leading)) {
1088
+ const line = src[i + 1] === "/", end = line ? skipLine(src, i) : skipComment(src, i);
1089
+ if (!line && !native) {
1090
+ cur ? emit(src.slice(i, end)) : out += src.slice(i, end);
1091
+ } else
1092
+ IDENT_CHAR.test(tail) && IDENT_CHAR.test(src[end] || "") && (gap = true);
1093
+ leading && (stmt = end);
1094
+ i = end;
1095
+ continue;
1096
+ }
1097
+ if (c === '"' || c === "'") {
1098
+ const end = skipString(src, i);
1099
+ emit(src.slice(i, end));
1100
+ i = end;
1101
+ continue;
1102
+ }
1103
+ if (WS.test(c)) {
1104
+ stmt === i && stmt++;
1105
+ gap = true;
1106
+ i++;
1107
+ continue;
1108
+ }
1109
+ if (c === "(")
1110
+ paren++;
1111
+ else if (c === ")")
1112
+ paren--;
1113
+ if (c === ":" && paren === 0) {
1114
+ const name = src.slice(stmt, i).replace(COMMENTS, "").trim();
1115
+ if (PROP_NAME.test(name)) {
1116
+ const parsed = readValue(src, i + 1, !native, (at) => {
1117
+ unterminated = true;
1118
+ report("LIPS-S004", "Unterminated interpolation", at, src.length - at, "Close the expression with `}`.");
1119
+ });
1120
+ if (parsed) {
1121
+ const slots = parsed.parts.filter((p) => typeof p !== "string");
1122
+ for (const s of slots)
1123
+ checkExpr(s);
1124
+ gap = false;
1125
+ const bare = name.startsWith("--") && slots.length === 1 && !slots[0].unit && parsed.parts.every((p) => typeof p !== "string" || !p.trim());
1126
+ if (bare) {
1127
+ binds.push({ prop: name, e: slot(slots[0].expr) });
1128
+ drop();
1129
+ i = parsed.end + (src[parsed.end] === ";" ? 1 : 0);
1130
+ stmt = i;
1131
+ continue;
1132
+ }
1133
+ let text = "";
1134
+ for (const part of parsed.parts) {
1135
+ if (typeof part === "string") {
1136
+ text += part;
1137
+ continue;
1138
+ }
1139
+ const e = slot(part.expr), prop = `${prefix}-${e}`;
1140
+ if (!binds.some((b) => b.prop === prop)) {
1141
+ binds.push({ prop, e });
1142
+ if (part.unit && !props.some((p) => p.name === prop))
1143
+ props.push({
1144
+ name: prop,
1145
+ syntax: NUMBER_SYNTAX[0],
1146
+ inherits: true,
1147
+ initial: NUMBER_SYNTAX[1]
1148
+ });
1149
+ }
1150
+ text += part.unit ? `calc(var(${prop}) * 1${part.unit})` : `var(${prop})`;
1151
+ }
1152
+ lint(name, stmt, parsed.end, text);
1153
+ emit(value(text));
1154
+ i = parsed.end;
1155
+ continue;
1156
+ }
1157
+ }
1158
+ }
1159
+ if (c === "{") {
1160
+ if (paren > 0) {
1161
+ const interp = readInterpolation(src, i);
1162
+ if (interp) {
1163
+ report("LIPS-S002", "Interpolation in an at-rule condition", i, interp.end - i + 1, "Media and container conditions cannot read custom properties. Keep the condition static.");
1164
+ const m = UNIT.exec(src.slice(interp.end + 1));
1165
+ i = interp.end + 1 + (m ? m[1].length : 0);
1166
+ continue;
1167
+ }
1168
+ }
1169
+ if (!src.slice(stmt, i).trim()) {
1170
+ const interp = readInterpolation(src, i);
1171
+ if (interp) {
1172
+ report("LIPS-S001", "Interpolation in a selector", i, interp.end - i + 1, "Selectors are static in Layer 1. Bind a value inside the rule instead.");
1173
+ i = interp.end + 1;
1174
+ stmt = i;
1175
+ continue;
1176
+ }
1177
+ }
1178
+ open();
1179
+ stmt = ++i;
1180
+ continue;
1181
+ }
1182
+ if (c === "}") {
1183
+ if (stack.length > 1)
1184
+ close();
1185
+ else {
1186
+ warn("LIPS-S007", "Unmatched `}` dropped", i, 1);
1187
+ cur && flush(";");
1188
+ }
1189
+ stmt = ++i;
1190
+ continue;
1191
+ }
1192
+ if (c === ";") {
1193
+ cur[0] === "@" && lint(cur, stmt, i);
1194
+ if (stack.length === 1 && HOISTED_STATEMENT.test(cur))
1195
+ statements += drop() + ";";
1196
+ else
1197
+ flush(";");
1198
+ stmt = ++i;
1199
+ continue;
1200
+ }
1201
+ emit(c);
1202
+ i++;
1203
+ }
1204
+ if (stack.length > 1) {
1205
+ unterminated || warn("LIPS-S007", "Unclosed `{` closed at the end", src.length, 0);
1206
+ while (stack.length > 1)
1207
+ close();
1208
+ }
1209
+ HOISTED_STATEMENT.test(cur) && (statements += drop() + ";");
1210
+ flush("");
1211
+ return { css: out, statements, hoisted, exprs, binds, props };
1212
+ }
1213
+ function compileStyle(src, options) {
1214
+ const diagnostics = [], preprocess = options.preprocess || PREPROCESSOR, { css, statements, hoisted, exprs, binds, props } = scan(src, options, !preprocess, diagnostics);
1215
+ const empty = { v: 1, nsp: options.nsp, css: "", exprs: [], binds: [] };
1216
+ const scoped = options.meta || !css ? css : `${options.scope || `[rel="${quote(options.nsp)}"]`}{${css}}`, body = hoisted + scoped, source = options.layer ? `@layer ${options.layer}{${body}}` : body;
1217
+ let sheet;
1218
+ try {
1219
+ sheet = preprocess ? preprocess(source) : source;
1220
+ } catch (error) {
1221
+ diagnostics.push({
1222
+ code: "LIPS-S006",
1223
+ severity: "error",
1224
+ message: `Style compilation failed: ${error.message}`,
1225
+ loc: locOf(src, 0, src.length)
1226
+ });
1227
+ return { ir: empty, diagnostics };
1228
+ }
1229
+ const registrations = props.map((p) => `@property ${p.name}{syntax:"${p.syntax}";inherits:${p.inherits};initial-value:${p.initial}}`).join("");
1230
+ const ir = { v: 1, nsp: options.nsp, css: statements + registrations + sheet, exprs, binds };
1231
+ if (props.length)
1232
+ ir.props = props;
1233
+ return { ir, diagnostics };
1234
+ }
1235
+
1236
+ // src/lynx/protocol.ts
1237
+ var VIEW = [
1238
+ "div",
1239
+ "section",
1240
+ "article",
1241
+ "nav",
1242
+ "header",
1243
+ "footer",
1244
+ "main",
1245
+ "aside",
1246
+ "ul",
1247
+ "ol",
1248
+ "li",
1249
+ "button",
1250
+ "form",
1251
+ "figure",
1252
+ "dialog",
1253
+ "details",
1254
+ "summary",
1255
+ "address",
1256
+ "blockquote",
1257
+ "hgroup",
1258
+ "fieldset",
1259
+ "legend",
1260
+ "menu",
1261
+ "dl",
1262
+ "dt",
1263
+ "dd",
1264
+ "figcaption"
1265
+ ];
1266
+ var TEXT_LIKE = [
1267
+ "span",
1268
+ "p",
1269
+ "h1",
1270
+ "h2",
1271
+ "h3",
1272
+ "h4",
1273
+ "h5",
1274
+ "h6",
1275
+ "label",
1276
+ "b",
1277
+ "strong",
1278
+ "i",
1279
+ "em",
1280
+ "small",
1281
+ "a",
1282
+ "code",
1283
+ "mark",
1284
+ "s",
1285
+ "u",
1286
+ "sub",
1287
+ "sup",
1288
+ "time",
1289
+ "abbr",
1290
+ "cite",
1291
+ "kbd",
1292
+ "q",
1293
+ "var",
1294
+ "samp",
1295
+ "dfn",
1296
+ "del",
1297
+ "ins",
1298
+ "data",
1299
+ "bdi",
1300
+ "bdo"
1301
+ ];
1302
+ var LYNX_TAG = Object.fromEntries([
1303
+ ...VIEW.map((t) => [t, "view"]),
1304
+ ...TEXT_LIKE.map((t) => [t, "text"]),
1305
+ ["img", "image"]
1306
+ ]);
1307
+ var scopeClass = (nsp) => `lips-${nsp.replace(/[^\w-]/g, "-")}`;
1308
+
1309
+ // src/lynx/style.ts
1310
+ var LYNX_PAGE_CONFIG = {
1311
+ enableCSSInlineVariables: true,
1312
+ enableCSSRule: true,
1313
+ enableCSSInheritance: true,
1314
+ enableA11y: true
1315
+ };
1316
+ function compileLynxStyle(source, options) {
1317
+ const { ir, diagnostics } = compileStyle(source, {
1318
+ nsp: options.nsp,
1319
+ meta: options.meta,
1320
+ preprocess: options.preprocess,
1321
+ scope: `.${scopeClass(options.nsp)}`,
1322
+ lint: lintLynx
1323
+ });
1324
+ return { ir: fullValues(ir), diagnostics };
1325
+ }
1326
+ var GENERATED_CALC = /calc\(var\((--[\w-]+?-(\d+))\)\s*\*\s*1(%|[a-zA-Z]+)\)/g;
1327
+ var REGISTRATION = /@property\s[^{]+\{[^}]*\}/g;
1328
+ function fullValues(ir) {
1329
+ const prefix = `--${ir.nsp.replace(/[^a-zA-Z0-9_-]/g, "-")}-`, binds = [...ir.binds], css = ir.css.replace(REGISTRATION, "").replace(GENERATED_CALC, (whole, prop, e, unit) => {
1330
+ if (!prop.startsWith(prefix) || prop.length !== prefix.length + e.length)
1331
+ return whole;
1332
+ const name = `${prop}-${unit === "%" ? "pct" : unit}`;
1333
+ binds.some((b) => b.prop === name) || binds.push({ prop: name, e: +e, u: unit });
1334
+ return `var(${name})`;
1335
+ });
1336
+ const out = {
1337
+ ...ir,
1338
+ css,
1339
+ binds: binds.filter((b) => b.u || !b.prop.startsWith(prefix) || css.includes(`var(${b.prop})`))
1340
+ };
1341
+ delete out.props;
1342
+ return out;
1343
+ }
1344
+ var error = (code, message, hint) => ({ code, severity: "error", message, hint });
1345
+ var warning = (code, message, hint) => ({ code, severity: "warning", message, hint });
1346
+ var PROPERTIES = new Set(`
1347
+ -x-animation-color-interpolation -x-app-region -x-auto-font-size -x-auto-font-size-line-ranges
1348
+ -x-auto-font-size-preset-sizes -x-caret-gradient -x-caret-height -x-caret-radius -x-caret-width
1349
+ -x-handle-color -x-handle-size adapt-font-size align-content align-items align-self animation
1350
+ animation-delay animation-direction animation-duration animation-fill-mode
1351
+ animation-iteration-count animation-name animation-play-state animation-timing-function
1352
+ aspect-ratio background background-clip background-color background-image background-origin
1353
+ background-position background-repeat background-size border border-bottom border-bottom-color
1354
+ border-bottom-left-radius border-bottom-right-radius border-bottom-style border-bottom-width
1355
+ border-color border-end-end-radius border-end-start-radius border-inline-end-color
1356
+ border-inline-end-style border-inline-end-width border-inline-start-color
1357
+ border-inline-start-style border-inline-start-width border-left border-left-color
1358
+ border-left-style border-left-width border-radius border-right border-right-color
1359
+ border-right-style border-right-width border-start-end-radius border-start-start-radius
1360
+ border-style border-top border-top-color border-top-left-radius border-top-right-radius
1361
+ border-top-style border-top-width border-width bottom box-shadow box-sizing caret-color
1362
+ clip-path color column-gap content cursor direction display enter-transition-name
1363
+ exit-transition-name filter flex flex-basis flex-direction flex-flow flex-grow flex-shrink
1364
+ flex-wrap font-family font-feature-settings font-optical-sizing font-size font-style
1365
+ font-variation-settings font-weight gap grid-auto-columns grid-auto-flow grid-auto-rows
1366
+ grid-column-end grid-column-gap grid-column-span grid-column-start grid-row-end grid-row-gap
1367
+ grid-row-span grid-row-start grid-template-columns grid-template-rows height hyphens
1368
+ image-rendering implicit-animation inset-inline-end inset-inline-start justify-content
1369
+ justify-items justify-self layout-animation-create-delay layout-animation-create-duration
1370
+ layout-animation-create-property layout-animation-create-timing-function
1371
+ layout-animation-delete-delay layout-animation-delete-duration layout-animation-delete-property
1372
+ layout-animation-delete-timing-function layout-animation-update-delay
1373
+ layout-animation-update-duration layout-animation-update-timing-function left letter-spacing
1374
+ line-height line-spacing linear-cross-gravity linear-direction linear-gravity
1375
+ linear-layout-gravity linear-orientation linear-weight linear-weight-sum list-cross-axis-gap
1376
+ list-main-axis-gap margin margin-bottom margin-inline-end margin-inline-start margin-left
1377
+ margin-right margin-top mask mask-clip mask-image mask-origin mask-position mask-repeat
1378
+ mask-size max-height max-width min-height min-width offset-distance offset-path offset-rotate
1379
+ opacity order outline outline-color outline-style outline-width overflow overflow-x overflow-y
1380
+ padding padding-bottom padding-inline-end padding-inline-start padding-left padding-right
1381
+ padding-top pause-transition-name perspective pointer-events position relative-align-bottom
1382
+ relative-align-inline-end relative-align-inline-start relative-align-left relative-align-right
1383
+ relative-align-top relative-bottom-of relative-center relative-id relative-inline-end-of
1384
+ relative-inline-start-of relative-layout-once relative-left-of relative-right-of relative-top-of
1385
+ resume-transition-name right row-gap text-align text-decoration text-decoration-color
1386
+ text-indent text-overflow text-shadow text-stroke text-stroke-color text-stroke-width top
1387
+ transform transform-origin transition transition-delay transition-duration transition-property
1388
+ transition-timing-function vertical-align visibility white-space width word-break z-index
1389
+ `.trim().split(/\s+/));
1390
+ var LINE_CLAMP = /^(-webkit-)?line-clamp$/;
1391
+ var DESCRIPTORS = new Set(["src", "font-display", "unicode-range"]);
1392
+ var CALC_OK = /^(width|height|(min|max)-(width|height)|(margin|padding)(-(top|right|bottom|left|inline-start|inline-end))?|top|right|bottom|left|inset-inline-(start|end)|gap|row-gap|column-gap|grid-(row|column)-gap|font-size|line-height|letter-spacing|flex-basis|text-indent|border(-(top|right|bottom|left|inline-start|inline-end))?-width|outline-width)$/;
1393
+ var PSEUDO_OK = new Set(["not", "active", "focus", "root"]);
1394
+ var LEGACY_ELEMENT = new Set(["before", "after", "first-line", "first-letter"]);
1395
+ var AT_OK = new Set(["media", "keyframes", "font-face", "import"]);
1396
+ var AT_UNVERIFIED = new Set(["supports", "layer"]);
1397
+ var QUOTED2 = /"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'/g;
1398
+ var lintLynx = (text, value) => text[0] === "@" ? atRule(text) : value === undefined ? selector(text) : declaration2(text, value);
1399
+ function selector(prelude) {
1400
+ const found = [], s = prelude.replace(QUOTED2, '""');
1401
+ if (s.includes("["))
1402
+ found.push(error("LIPS-L001", "Attribute selectors never match on Lynx", "Select by class instead."));
1403
+ for (const [, colons, name] of s.matchAll(/(::?)([-\w]+)/g)) {
1404
+ const pseudo = name.toLowerCase();
1405
+ if (colons === "::" || LEGACY_ELEMENT.has(pseudo))
1406
+ found.push(error("LIPS-L002", `Pseudo-elements are not supported on Lynx: '${colons}${name}'`, "Render it as an element."));
1407
+ else if (pseudo === "hover")
1408
+ found.push(warning("LIPS-L004", "':hover' matches only on desktop Lynx", "Mobile has no pointer to hover with."));
1409
+ else if (!PSEUDO_OK.has(pseudo))
1410
+ found.push(error("LIPS-L003", `':${name}' never matches on Lynx`, "Lynx matches :not(), :active, :focus and :root. Use a class."));
1411
+ }
1412
+ for (const [, , tag] of s.replace(/\[[^\]]*\]/g, "").matchAll(/(^|[\s>+~,(])([a-zA-Z][-\w]*)/g)) {
1413
+ const lynx = LYNX_TAG[tag.toLowerCase()];
1414
+ lynx && found.push(error("LIPS-L005", `'${tag}' renders as '${lynx}' on Lynx, so this selector never matches`, `Use a class. A '${lynx}' selector would match every ${lynx}, not just the ${tag}s.`));
1415
+ }
1416
+ return found;
1417
+ }
1418
+ function atRule(prelude) {
1419
+ const name = /^@(?:-\w+-)?([-\w]+)/.exec(prelude)?.[1].toLowerCase();
1420
+ if (!name || AT_OK.has(name))
1421
+ return;
1422
+ return [AT_UNVERIFIED.has(name) ? warning("LIPS-L007", `'@${name}' is untested on Lynx`, "The engine evaluates it, but its docs say it is unsupported.") : error("LIPS-L006", `'@${name}' is not supported on Lynx`)];
1423
+ }
1424
+ function declaration2(name, value) {
1425
+ const found = [];
1426
+ if (name.startsWith("--"))
1427
+ return found;
1428
+ const property = name.toLowerCase();
1429
+ if (LINE_CLAMP.test(property))
1430
+ found.push(error("LIPS-L012", `'${name}' does not cut text on Lynx`, `Set the text-maxline attribute on the text element instead (text-maxline="${/^\d+$/.test(value.trim()) ? value.trim() : "N"}"), with text-overflow: ellipsis.`));
1431
+ else
1432
+ PROPERTIES.has(property) || DESCRIPTORS.has(property) || found.push(warning("LIPS-L008", `'${name}' is not a Lynx CSS property`, "Lynx ignores it."));
1433
+ const authored = value.replace(QUOTED2, '""').replace(GENERATED_CALC, "var()");
1434
+ const fn = /(?:^|[^-\w])(min|max|clamp)\(/i.exec(authored);
1435
+ fn && found.push(error("LIPS-L009", `'${fn[1]}()' is not supported on Lynx`, "Compute the value in the expression instead."));
1436
+ /(?:^|[^-\w])calc\(/i.test(authored) && !CALC_OK.test(property) && found.push(error("LIPS-L010", `'calc()' works on length properties only on Lynx, not '${name}'`, "Bind the computed value instead: `{expr}` writes it whole."));
1437
+ /!\s*important/i.test(authored) && found.push(warning("LIPS-L011", "'!important' is ignored on Lynx unless the page enables it"));
1438
+ return found;
1439
+ }
1440
+
1441
+ // src/lynx/plugin.ts
1442
+ var SHEET = /\.lips\.css$/;
1443
+ var LIPS = /[\\/]@lipsjs[\\/]lips[\\/]dist[\\/]/;
1444
+ var flatten = (css) => serialize(compile(css), middleware([stringify]));
1445
+ var scopeOf = (path) => path.replace(/^.*[\\/]/, "").replace(SHEET, "");
1446
+ function buildSheet(source, path) {
1447
+ const { ir, diagnostics } = compileLynxStyle(source, { nsp: scopeOf(path), preprocess: flatten });
1448
+ const lines = diagnostics.map((d) => `${path}:${d.loc.line}:${d.loc.col} ${d.severity} ${d.code} ${d.message}${d.hint ? `
1449
+ ${d.hint}` : ""}`);
1450
+ if (diagnostics.some((d) => d.severity === "error"))
1451
+ throw new Error(`Lips stylesheet:
1452
+ ${lines.join(`
1453
+ `)}`);
1454
+ lines.length && console.warn(lines.join(`
1455
+ `));
1456
+ return ir;
1457
+ }
1458
+
1459
+ class PageConfig {
1460
+ apply(compiler) {
1461
+ const Template = compiler.options.plugins.find((p) => p?.constructor?.getLynxTemplatePluginHooks)?.constructor;
1462
+ if (!Template)
1463
+ throw new Error("[lips] pluginLips needs a Lynx build plugin before it (pluginVanillaLynx or pluginReactLynx): no Lynx template plugin is registered");
1464
+ compiler.hooks.thisCompilation.tap("lips:page-config", (compilation) => {
1465
+ Template.getLynxTemplatePluginHooks(compilation).beforeEncode.tap("lips:page-config", (args) => {
1466
+ const config = args.encodeData.sourceContent.config;
1467
+ Object.assign(config, LYNX_PAGE_CONFIG, "enableA11y" in config && { enableA11y: config.enableA11y });
1468
+ return args;
1469
+ });
1470
+ });
1471
+ }
1472
+ }
1473
+ var pluginLips = () => ({
1474
+ name: "lips:lynx",
1475
+ setup(api) {
1476
+ api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => mergeRsbuildConfig(config, { source: { include: [LIPS] } }));
1477
+ api.transform({ test: SHEET, resourceQuery: { not: /raw/ }, order: "pre" }, ({ code, resourcePath }) => buildSheet(code, resourcePath).css);
1478
+ api.transform({ test: SHEET, resourceQuery: /raw/, order: "pre" }, ({ code, resourcePath }) => JSON.stringify({ ...buildSheet(code, resourcePath), css: "" }));
1479
+ api.modifyBundlerChain((chain) => {
1480
+ chain.plugin("lips:page-config").use(PageConfig);
1481
+ });
1482
+ }
1483
+ });
1484
+ export {
1485
+ buildSheet,
1486
+ pluginLips
1487
+ };