@lipsjs/lips 0.3.0 → 0.4.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.
- package/README.md +123 -9
- package/dist/lips.js +915 -669
- package/dist/lips.js.map +15 -12
- package/dist/lips.min.js +12 -12
- package/dist/lips.min.js.map +15 -12
- package/dist/lynx-background.min.js +3 -0
- package/dist/lynx-background.min.js.map +13 -0
- package/dist/lynx-main.min.js +3 -0
- package/dist/lynx-main.min.js.map +11 -0
- package/dist/lynx-plugin.mjs +1487 -0
- package/dist/lynx.min.js +51 -0
- package/dist/lynx.min.js.map +18 -0
- package/dist/mf2.min.js.map +1 -1
- package/dist/parts.min.js +19 -0
- package/dist/parts.min.js.map +11 -0
- package/dist/precompile.min.js +15 -15
- package/dist/precompile.min.js.map +8 -7
- package/dist/runtime.min.js +4 -4
- package/dist/runtime.min.js.map +11 -9
- package/dist/stylis.min.js.map +1 -1
- package/dist/types/component.d.ts +32 -0
- package/dist/types/ir/compiler.d.ts +2 -4
- package/dist/types/ir/facade.d.ts +63 -12
- package/dist/types/ir/host.d.ts +9 -1
- package/dist/types/ir/initial.d.ts +16 -0
- package/dist/types/ir/router.d.ts +2 -0
- package/dist/types/ir/tags.d.ts +16 -0
- package/dist/types/lips.d.ts +7 -7
- package/dist/types/lynx/a11y.d.ts +1 -0
- package/dist/types/lynx/background.d.ts +52 -3
- package/dist/types/lynx/main.d.ts +9 -5
- package/dist/types/lynx/plugin.d.ts +8 -0
- package/dist/types/lynx/protocol.d.ts +55 -4
- package/dist/types/lynx/style.d.ts +7 -0
- package/dist/types/lynx/template.d.ts +6 -0
- package/dist/types/lynx.d.ts +22 -0
- package/dist/types/parts/menu.d.ts +44 -0
- package/dist/types/parts/popover.d.ts +83 -0
- package/dist/types/parts.d.ts +16 -0
- package/dist/types/precompile.d.ts +8 -11
- package/dist/types/runtime.d.ts +1 -0
- package/dist/types/types.d.ts +181 -57
- package/dist/untrusted.min.js +4 -4
- package/dist/untrusted.min.js.map +7 -7
- package/package.json +29 -3
- package/dist/types/i18n/formatters.d.ts +0 -3
package/dist/lips.js
CHANGED
|
@@ -519,13 +519,13 @@ function gen(node) {
|
|
|
519
519
|
case "id":
|
|
520
520
|
return ID_RENAMES[node.name] ?? node.name;
|
|
521
521
|
case "member": {
|
|
522
|
-
const obj =
|
|
522
|
+
const obj = link(node.obj);
|
|
523
523
|
if (node.computed)
|
|
524
|
-
return
|
|
525
|
-
return
|
|
524
|
+
return `${obj}${node.optional ? "?." : ""}[${gen(node.prop)}]`;
|
|
525
|
+
return `${obj}${node.optional ? "?." : "."}${node.prop}`;
|
|
526
526
|
}
|
|
527
527
|
case "call":
|
|
528
|
-
return
|
|
528
|
+
return `${link(node.callee)}${node.optional ? "?." : ""}(${node.args.map(gen).join(",")})`;
|
|
529
529
|
case "unary":
|
|
530
530
|
return `(${node.op}(${gen(node.arg)}))`;
|
|
531
531
|
case "update":
|
|
@@ -548,6 +548,7 @@ function gen(node) {
|
|
|
548
548
|
return "undefined";
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
|
+
var link = (node) => node.t === "member" || node.t === "call" || node.t === "id" ? gen(node) : `(${gen(node)})`;
|
|
551
552
|
function genTarget(node) {
|
|
552
553
|
if (node.t === "id")
|
|
553
554
|
return ID_RENAMES[node.name] ?? node.name;
|
|
@@ -596,6 +597,7 @@ var GLOBALS = {
|
|
|
596
597
|
decodeURIComponent,
|
|
597
598
|
console
|
|
598
599
|
};
|
|
600
|
+
var ENDED = Symbol("lips.ended");
|
|
599
601
|
function interpretExpression(ast, env) {
|
|
600
602
|
const scope = env.scope || Object.create(null);
|
|
601
603
|
const resolveId = (name, locals) => {
|
|
@@ -637,28 +639,10 @@ function interpretExpression(ast, env) {
|
|
|
637
639
|
return node.v;
|
|
638
640
|
case "id":
|
|
639
641
|
return resolveId(node.name, locals);
|
|
640
|
-
case "member":
|
|
641
|
-
const obj = ev(node.obj, locals);
|
|
642
|
-
if (node.optional && obj == null)
|
|
643
|
-
return;
|
|
644
|
-
const prop = node.computed ? ev(node.prop, locals) : node.prop;
|
|
645
|
-
return obj?.[prop];
|
|
646
|
-
}
|
|
642
|
+
case "member":
|
|
647
643
|
case "call": {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
if ((node.callee.optional || node.optional) && obj == null)
|
|
651
|
-
return;
|
|
652
|
-
const prop = node.callee.computed ? ev(node.callee.prop, locals) : node.callee.prop;
|
|
653
|
-
const fn2 = obj?.[prop];
|
|
654
|
-
if (node.optional && fn2 == null)
|
|
655
|
-
return;
|
|
656
|
-
return fn2.apply(obj, node.args.map((a) => ev(a, locals)));
|
|
657
|
-
}
|
|
658
|
-
const fn = ev(node.callee, locals);
|
|
659
|
-
if (node.optional && fn == null)
|
|
660
|
-
return;
|
|
661
|
-
return fn(...node.args.map((a) => ev(a, locals)));
|
|
644
|
+
const v = chain(node, locals);
|
|
645
|
+
return v === ENDED ? undefined : v;
|
|
662
646
|
}
|
|
663
647
|
case "unary": {
|
|
664
648
|
const v = ev(node.arg, locals);
|
|
@@ -774,6 +758,23 @@ function interpretExpression(ast, env) {
|
|
|
774
758
|
return;
|
|
775
759
|
}
|
|
776
760
|
};
|
|
761
|
+
const chain = (node, locals) => {
|
|
762
|
+
if (node.t !== "member" && node.t !== "call")
|
|
763
|
+
return ev(node, locals);
|
|
764
|
+
const m = node.t === "member" ? node : node.callee.t === "member" ? node.callee : null;
|
|
765
|
+
let obj, fn;
|
|
766
|
+
if (m) {
|
|
767
|
+
obj = chain(m.obj, locals);
|
|
768
|
+
if (obj === ENDED || m.optional && obj == null)
|
|
769
|
+
return ENDED;
|
|
770
|
+
fn = obj[m.computed ? ev(m.prop, locals) : m.prop];
|
|
771
|
+
if (node === m)
|
|
772
|
+
return fn;
|
|
773
|
+
} else if ((fn = chain(node.callee, locals)) === ENDED)
|
|
774
|
+
return ENDED;
|
|
775
|
+
const call = node;
|
|
776
|
+
return call.optional && fn == null ? ENDED : Reflect.apply(fn, obj, call.args.map((a) => ev(a, locals)));
|
|
777
|
+
};
|
|
777
778
|
const setTarget = (target, value, locals) => {
|
|
778
779
|
if (target.t === "id")
|
|
779
780
|
return assignId(target.name, value, locals);
|
|
@@ -1034,6 +1035,7 @@ function reactive(obj, deep = false) {
|
|
|
1034
1035
|
if (obj[IS_REACTIVE])
|
|
1035
1036
|
return obj;
|
|
1036
1037
|
const sigs = new Map;
|
|
1038
|
+
const [keys, , touchKeys] = signal(0);
|
|
1037
1039
|
const sigFor = (key, initial) => {
|
|
1038
1040
|
let s = sigs.get(key);
|
|
1039
1041
|
if (!s) {
|
|
@@ -1053,10 +1055,11 @@ function reactive(obj, deep = false) {
|
|
|
1053
1055
|
return target[key];
|
|
1054
1056
|
},
|
|
1055
1057
|
set(target, key, value) {
|
|
1056
|
-
const prev = target[key];
|
|
1058
|
+
const had = key in target, prev = target[key];
|
|
1057
1059
|
target[key] = value;
|
|
1058
1060
|
if (typeof key !== "string")
|
|
1059
1061
|
return true;
|
|
1062
|
+
had || touchKeys();
|
|
1060
1063
|
const sig = sigFor(key, value);
|
|
1061
1064
|
Object.is(prev, value) && isCollection(value) ? sig[2]() : sig[1](value);
|
|
1062
1065
|
return true;
|
|
@@ -1064,9 +1067,15 @@ function reactive(obj, deep = false) {
|
|
|
1064
1067
|
has(target, key) {
|
|
1065
1068
|
return key in target;
|
|
1066
1069
|
},
|
|
1070
|
+
ownKeys(target) {
|
|
1071
|
+
keys();
|
|
1072
|
+
return Reflect.ownKeys(target);
|
|
1073
|
+
},
|
|
1067
1074
|
deleteProperty(target, key) {
|
|
1075
|
+
const had = key in target;
|
|
1068
1076
|
delete target[key];
|
|
1069
1077
|
typeof key === "string" && sigs.get(key)?.[1](undefined);
|
|
1078
|
+
had && touchKeys();
|
|
1070
1079
|
return true;
|
|
1071
1080
|
}
|
|
1072
1081
|
});
|
|
@@ -1074,6 +1083,8 @@ function reactive(obj, deep = false) {
|
|
|
1074
1083
|
|
|
1075
1084
|
// src/ir/host.ts
|
|
1076
1085
|
var SKELETONS = new WeakMap;
|
|
1086
|
+
var present = (v) => v !== null;
|
|
1087
|
+
var LIVE = { __proto__: null, value: (v) => v ?? "", checked: present, selected: present };
|
|
1077
1088
|
var domHost = {
|
|
1078
1089
|
clone(block) {
|
|
1079
1090
|
let tpl = SKELETONS.get(block);
|
|
@@ -1116,7 +1127,11 @@ var domHost = {
|
|
|
1116
1127
|
isElement: (node) => node.nodeType === 1,
|
|
1117
1128
|
connected: (node) => node.isConnected,
|
|
1118
1129
|
precedes: (a, b) => !!(a.compareDocumentPosition(b) & 4),
|
|
1119
|
-
attr
|
|
1130
|
+
attr(el, name, value) {
|
|
1131
|
+
value === null ? el.removeAttribute(name) : el.setAttribute(name, value);
|
|
1132
|
+
const live = LIVE[name];
|
|
1133
|
+
live && name in el && (el[name] = live(value));
|
|
1134
|
+
},
|
|
1120
1135
|
setText: (node, value) => {
|
|
1121
1136
|
node.data = value;
|
|
1122
1137
|
},
|
|
@@ -1131,8 +1146,9 @@ var domHost = {
|
|
|
1131
1146
|
el.hasAttribute("rel") || el.setAttribute("rel", nsp);
|
|
1132
1147
|
},
|
|
1133
1148
|
listen(el, name, fn) {
|
|
1134
|
-
el.
|
|
1135
|
-
|
|
1149
|
+
const type = name.split(".")[0], outside = name.includes(".outside"), at = outside ? document : el, capture = outside || name.includes(".capture"), stop = !outside && name.includes(".stop"), on = (e) => outside && el.contains(e.target) || (stop && e.stopPropagation(), fn(e));
|
|
1150
|
+
at.addEventListener(type, on, capture);
|
|
1151
|
+
return () => at.removeEventListener(type, on, capture);
|
|
1136
1152
|
},
|
|
1137
1153
|
keepFocus() {
|
|
1138
1154
|
const focused = document.activeElement;
|
|
@@ -1242,9 +1258,86 @@ var sameLets = (a, ax, b, bx) => {
|
|
|
1242
1258
|
return lets(a, ax) === lets(b, bx);
|
|
1243
1259
|
};
|
|
1244
1260
|
|
|
1261
|
+
// src/ir/initial.ts
|
|
1262
|
+
function initial(value, seen = new WeakMap) {
|
|
1263
|
+
if (value === null || typeof value !== "object")
|
|
1264
|
+
return value;
|
|
1265
|
+
const v = value;
|
|
1266
|
+
if (seen.has(v))
|
|
1267
|
+
return seen.get(v);
|
|
1268
|
+
if (Array.isArray(v)) {
|
|
1269
|
+
const out = [];
|
|
1270
|
+
seen.set(v, out);
|
|
1271
|
+
for (const each of v)
|
|
1272
|
+
out.push(initial(each, seen));
|
|
1273
|
+
return out;
|
|
1274
|
+
}
|
|
1275
|
+
if (v instanceof Map) {
|
|
1276
|
+
const out = new Map;
|
|
1277
|
+
seen.set(v, out);
|
|
1278
|
+
v.forEach((each, key) => out.set(initial(key, seen), initial(each, seen)));
|
|
1279
|
+
return out;
|
|
1280
|
+
}
|
|
1281
|
+
if (v instanceof Set) {
|
|
1282
|
+
const out = new Set;
|
|
1283
|
+
seen.set(v, out);
|
|
1284
|
+
v.forEach((each) => out.add(initial(each, seen)));
|
|
1285
|
+
return out;
|
|
1286
|
+
}
|
|
1287
|
+
if (v instanceof Date)
|
|
1288
|
+
return new Date(v.getTime());
|
|
1289
|
+
if (v instanceof RegExp)
|
|
1290
|
+
return new RegExp(v.source, v.flags);
|
|
1291
|
+
if (ArrayBuffer.isView(v))
|
|
1292
|
+
return new v.constructor(v);
|
|
1293
|
+
const proto = Object.getPrototypeOf(v);
|
|
1294
|
+
if (proto !== Object.prototype && proto !== null)
|
|
1295
|
+
return value;
|
|
1296
|
+
const out = Object.create(proto);
|
|
1297
|
+
seen.set(v, out);
|
|
1298
|
+
for (const key of Reflect.ownKeys(v)) {
|
|
1299
|
+
const d = Object.getOwnPropertyDescriptor(v, key);
|
|
1300
|
+
"value" in d && (d.value = initial(d.value, seen));
|
|
1301
|
+
Object.defineProperty(out, key, d);
|
|
1302
|
+
}
|
|
1303
|
+
return out;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1245
1306
|
// src/ir/runtime.ts
|
|
1246
1307
|
var SLOT = Symbol("lips.slot");
|
|
1247
1308
|
var isSlot = (v) => !!v && typeof v === "object" && v[SLOT] === true;
|
|
1309
|
+
function watchInput(self, input, hooks) {
|
|
1310
|
+
if (!input || typeof self.onInput !== "function")
|
|
1311
|
+
return () => {};
|
|
1312
|
+
let first = true, scheduled = false, live = true;
|
|
1313
|
+
const { dispose } = effect(() => {
|
|
1314
|
+
for (const k of Object.keys(input))
|
|
1315
|
+
input[k];
|
|
1316
|
+
if (first) {
|
|
1317
|
+
first = false;
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
if (scheduled)
|
|
1321
|
+
return;
|
|
1322
|
+
scheduled = true;
|
|
1323
|
+
Promise.resolve().then(() => {
|
|
1324
|
+
scheduled = false;
|
|
1325
|
+
if (!live)
|
|
1326
|
+
return;
|
|
1327
|
+
untrack(() => {
|
|
1328
|
+
try {
|
|
1329
|
+
self.onInput(input);
|
|
1330
|
+
} catch (error) {
|
|
1331
|
+
hooks.onError(error);
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
});
|
|
1335
|
+
});
|
|
1336
|
+
return () => {
|
|
1337
|
+
live = false;
|
|
1338
|
+
dispose();
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1248
1341
|
function makeHooks(self) {
|
|
1249
1342
|
let scheduled = false;
|
|
1250
1343
|
let isReady = false;
|
|
@@ -1316,6 +1409,7 @@ function release(h, rec) {
|
|
|
1316
1409
|
}
|
|
1317
1410
|
function place(h, ref, inst) {
|
|
1318
1411
|
h.insertAfter(ref, nodesOf(h, inst));
|
|
1412
|
+
PENDING_ATTACH.length && h.connected(ref) && flushAttach();
|
|
1319
1413
|
return inst;
|
|
1320
1414
|
}
|
|
1321
1415
|
var scopeRoots = (h, inst) => nodesOf(h, inst).filter((n) => h.isElement(n));
|
|
@@ -1345,7 +1439,22 @@ function destroy(h, inst) {
|
|
|
1345
1439
|
for (const n of nodesOf(h, inst))
|
|
1346
1440
|
h.remove(n, true);
|
|
1347
1441
|
}
|
|
1348
|
-
var
|
|
1442
|
+
var refTo = (benv, node, name, watch) => {
|
|
1443
|
+
const refs = benv.self.refs ||= {};
|
|
1444
|
+
let at = "";
|
|
1445
|
+
const drop = () => {
|
|
1446
|
+
refs[at] === node && delete refs[at];
|
|
1447
|
+
};
|
|
1448
|
+
const eff = watch(() => {
|
|
1449
|
+
drop();
|
|
1450
|
+
refs[at = String(name())] = node;
|
|
1451
|
+
});
|
|
1452
|
+
return () => {
|
|
1453
|
+
eff.dispose();
|
|
1454
|
+
drop();
|
|
1455
|
+
};
|
|
1456
|
+
};
|
|
1457
|
+
var applyAttr = (h, el, name, v) => h.attr(el, name, v == null || v === false && !name.startsWith("aria-") ? null : v === true && !name.startsWith("aria-") ? "" : String(v));
|
|
1349
1458
|
var defineGetter = (scope, name, get) => Object.defineProperty(scope, name, { get, enumerable: true, configurable: true });
|
|
1350
1459
|
var SELF = Symbol.for("lips.self");
|
|
1351
1460
|
var LAYER = Symbol("lips.ctx.layer");
|
|
@@ -1522,7 +1631,7 @@ class IRRenderer {
|
|
|
1522
1631
|
const [get, set] = signal(undefined);
|
|
1523
1632
|
defineGetter(scope, name, get);
|
|
1524
1633
|
const run = this.runner(input.e, block.scope);
|
|
1525
|
-
letDisposers.push(
|
|
1634
|
+
letDisposers.push(this.guarded(() => set(run(benv))).dispose);
|
|
1526
1635
|
}
|
|
1527
1636
|
}
|
|
1528
1637
|
inst.childHandles[i] = {
|
|
@@ -1532,7 +1641,8 @@ class IRRenderer {
|
|
|
1532
1641
|
dispose: () => letDisposers.forEach((d) => d())
|
|
1533
1642
|
};
|
|
1534
1643
|
});
|
|
1535
|
-
|
|
1644
|
+
const late = (b) => b.t === "attr" && b.name === "value";
|
|
1645
|
+
inst.bindHandles = block.binds.map((bind, i) => late(bind) ? null : this.bindOne(bind, bindNodes[i], benv, block.scope));
|
|
1536
1646
|
block.blocks.forEach((child, i) => {
|
|
1537
1647
|
if (child.t === "let")
|
|
1538
1648
|
return;
|
|
@@ -1543,6 +1653,10 @@ class IRRenderer {
|
|
|
1543
1653
|
dispose: this.execBlock(child, anchorNodes[i], benv, block.scope)
|
|
1544
1654
|
};
|
|
1545
1655
|
});
|
|
1656
|
+
block.binds.forEach((bind, i) => {
|
|
1657
|
+
if (late(bind))
|
|
1658
|
+
inst.bindHandles[i] = this.bindOne(bind, bindNodes[i], benv, block.scope);
|
|
1659
|
+
});
|
|
1546
1660
|
return inst;
|
|
1547
1661
|
}
|
|
1548
1662
|
bindOne(bind, node, benv, scopeNames, reuseText) {
|
|
@@ -1571,14 +1685,16 @@ class IRRenderer {
|
|
|
1571
1685
|
}
|
|
1572
1686
|
case "prop": {
|
|
1573
1687
|
const run = this.runner(bind.e, scopeNames);
|
|
1688
|
+
if (bind.name === "ref")
|
|
1689
|
+
return { bind, node, dispose: refTo(benv, node, () => run(benv), (fn) => this.guarded(fn)) };
|
|
1574
1690
|
if (bind.name === "format") {
|
|
1575
1691
|
const ref = bind.ref || "";
|
|
1576
|
-
const
|
|
1692
|
+
const eff = this.guarded(() => {
|
|
1577
1693
|
const params = run(benv);
|
|
1578
1694
|
const text = this.options.i18n?.format(ref, params, benv.lang?.());
|
|
1579
1695
|
h.content(node, text == null ? "" : String(text));
|
|
1580
1696
|
});
|
|
1581
|
-
return { bind, node, dispose:
|
|
1697
|
+
return { bind, node, dispose: eff.dispose };
|
|
1582
1698
|
}
|
|
1583
1699
|
const eff = this.guarded(() => {
|
|
1584
1700
|
const v = run(benv);
|
|
@@ -1667,7 +1783,7 @@ class IRRenderer {
|
|
|
1667
1783
|
const runs = child.branches.map((b) => b.when != null ? this.runner(b.when, scopeNames) : null);
|
|
1668
1784
|
let current = null;
|
|
1669
1785
|
let activeIdx = -2;
|
|
1670
|
-
const eff =
|
|
1786
|
+
const eff = this.guarded(() => {
|
|
1671
1787
|
let idx = -1;
|
|
1672
1788
|
for (let i = 0;i < child.branches.length; i++) {
|
|
1673
1789
|
const run = runs[i];
|
|
@@ -1698,7 +1814,7 @@ class IRRenderer {
|
|
|
1698
1814
|
const caseRuns = child.cases.map((c) => c.is && ("e" in c.is) ? this.runner(c.is.e, scopeNames) : null);
|
|
1699
1815
|
let current = null;
|
|
1700
1816
|
let activeIdx = -2;
|
|
1701
|
-
const eff =
|
|
1817
|
+
const eff = this.guarded(() => {
|
|
1702
1818
|
const value = onRun(benv);
|
|
1703
1819
|
let idx = -1, defaultIdx = -1;
|
|
1704
1820
|
for (let i = 0;i < child.cases.length; i++) {
|
|
@@ -1751,7 +1867,7 @@ class IRRenderer {
|
|
|
1751
1867
|
return { kind: "value", name: s.name, value: () => run(benv) };
|
|
1752
1868
|
});
|
|
1753
1869
|
let prevKeys = new Set;
|
|
1754
|
-
disposers.push(
|
|
1870
|
+
disposers.push(this.guarded(() => {
|
|
1755
1871
|
const next = {};
|
|
1756
1872
|
for (const r of runners) {
|
|
1757
1873
|
if (r.kind === "spread") {
|
|
@@ -1797,8 +1913,13 @@ class IRRenderer {
|
|
|
1797
1913
|
}
|
|
1798
1914
|
current = place(h, anchor, this.renderBlock(isArm ? arm.block : arm, { ...benv, scope: scope2 }));
|
|
1799
1915
|
};
|
|
1800
|
-
const eff =
|
|
1801
|
-
|
|
1916
|
+
const eff = this.guarded(() => {
|
|
1917
|
+
let p;
|
|
1918
|
+
try {
|
|
1919
|
+
p = awaitRun(benv);
|
|
1920
|
+
} catch (error) {
|
|
1921
|
+
p = Promise.reject(error);
|
|
1922
|
+
}
|
|
1802
1923
|
const my = ++token;
|
|
1803
1924
|
untrack(() => {
|
|
1804
1925
|
child.loading ? swapTo(child.loading) : swapTo(undefined);
|
|
@@ -1823,7 +1944,7 @@ class IRRenderer {
|
|
|
1823
1944
|
if ("lit" in input)
|
|
1824
1945
|
continue;
|
|
1825
1946
|
const run = this.runner(input.e, scopeNames);
|
|
1826
|
-
disposers.push(
|
|
1947
|
+
disposers.push(this.guarded(() => set(run(benv))).dispose);
|
|
1827
1948
|
}
|
|
1828
1949
|
let lang = benv.lang;
|
|
1829
1950
|
if (child.lang) {
|
|
@@ -1833,7 +1954,7 @@ class IRRenderer {
|
|
|
1833
1954
|
} else {
|
|
1834
1955
|
const [get, set] = signal(undefined);
|
|
1835
1956
|
const run = this.runner(child.lang.e, scopeNames);
|
|
1836
|
-
disposers.push(
|
|
1957
|
+
disposers.push(this.guarded(() => set(run(benv))).dispose);
|
|
1837
1958
|
lang = () => get() ?? benv.lang?.();
|
|
1838
1959
|
}
|
|
1839
1960
|
}
|
|
@@ -1843,7 +1964,7 @@ class IRRenderer {
|
|
|
1843
1964
|
}
|
|
1844
1965
|
case "log": {
|
|
1845
1966
|
const segs = splitTopLevel(this.ir.exprs[child.e]).map((s) => this.srcRunner(s, scopeNames));
|
|
1846
|
-
disposers.push(
|
|
1967
|
+
disposers.push(this.guarded(() => console.log(...segs.map((run) => run(benv)))).dispose);
|
|
1847
1968
|
break;
|
|
1848
1969
|
}
|
|
1849
1970
|
case "comp": {
|
|
@@ -1855,7 +1976,7 @@ class IRRenderer {
|
|
|
1855
1976
|
const tagRun = this.runner(child.tag, scopeNames);
|
|
1856
1977
|
let inner = [];
|
|
1857
1978
|
let activeVerb = Symbol("init");
|
|
1858
|
-
const eff =
|
|
1979
|
+
const eff = this.guarded(() => {
|
|
1859
1980
|
const verb = tagRun(benv);
|
|
1860
1981
|
if (verb === activeVerb)
|
|
1861
1982
|
return;
|
|
@@ -1867,10 +1988,12 @@ class IRRenderer {
|
|
|
1867
1988
|
if (verb == null)
|
|
1868
1989
|
return;
|
|
1869
1990
|
if (isSlot(verb)) {
|
|
1870
|
-
const
|
|
1871
|
-
for (const [name, ci] of Object.entries(child.inputs))
|
|
1872
|
-
|
|
1873
|
-
|
|
1991
|
+
const args = {};
|
|
1992
|
+
for (const [name, ci] of Object.entries(child.inputs)) {
|
|
1993
|
+
const run = "lit" in ci ? undefined : this.runner(ci.e, scopeNames);
|
|
1994
|
+
args[name] = run ? () => run(benv) : () => ci.lit;
|
|
1995
|
+
}
|
|
1996
|
+
const slotInst = place(h, anchor, verb.render(args, benv));
|
|
1874
1997
|
inner.push(() => destroy(h, slotInst));
|
|
1875
1998
|
return;
|
|
1876
1999
|
}
|
|
@@ -1926,7 +2049,7 @@ class IRRenderer {
|
|
|
1926
2049
|
return Object.entries(src).map(([k, v], i) => ({ key: k, values: [k, v, i] }));
|
|
1927
2050
|
return [];
|
|
1928
2051
|
};
|
|
1929
|
-
const eff =
|
|
2052
|
+
const eff = this.guarded(() => {
|
|
1930
2053
|
const next = tuples();
|
|
1931
2054
|
untrack(() => {
|
|
1932
2055
|
const seen = new Set;
|
|
@@ -1986,12 +2109,12 @@ class IRRenderer {
|
|
|
1986
2109
|
input[name] = ci.lit;
|
|
1987
2110
|
else {
|
|
1988
2111
|
const run = this.runner(ci.e, scopeNames);
|
|
1989
|
-
wiring.push(
|
|
2112
|
+
wiring.push(this.guarded(() => input[name] = run(benv)).dispose);
|
|
1990
2113
|
}
|
|
1991
2114
|
}
|
|
1992
2115
|
for (const e of child.spreads) {
|
|
1993
2116
|
const run = this.runner(e, scopeNames);
|
|
1994
|
-
wiring.push(
|
|
2117
|
+
wiring.push(this.guarded(() => {
|
|
1995
2118
|
const obj = run(benv) || {};
|
|
1996
2119
|
untrack(() => Object.entries(obj).forEach(([k, v]) => {
|
|
1997
2120
|
written?.add(k);
|
|
@@ -2012,13 +2135,12 @@ class IRRenderer {
|
|
|
2012
2135
|
return {
|
|
2013
2136
|
[SLOT]: true,
|
|
2014
2137
|
args: contents.args,
|
|
2015
|
-
render(
|
|
2138
|
+
render(args, at) {
|
|
2016
2139
|
const scope = Object.create(penv.scope ?? null);
|
|
2017
|
-
contents.args.forEach((name) => {
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
});
|
|
2021
|
-
return parent.renderBlock(contents.block, { ...penv, scope });
|
|
2140
|
+
contents.args.forEach((name) => defineGetter(scope, name, args?.[name] ?? (() => {
|
|
2141
|
+
return;
|
|
2142
|
+
})));
|
|
2143
|
+
return parent.renderBlock(contents.block, at ? { ...penv, scope, context: at.context, lang: at.lang } : { ...penv, scope });
|
|
2022
2144
|
}
|
|
2023
2145
|
};
|
|
2024
2146
|
}
|
|
@@ -2034,10 +2156,10 @@ class IRRenderer {
|
|
|
2034
2156
|
this.wireEvents(child.events, benv, scopeNames, rec.self, wiring);
|
|
2035
2157
|
rec.wiring = wiring;
|
|
2036
2158
|
rec.anchor = anchor;
|
|
2037
|
-
const
|
|
2159
|
+
const gen = rec.gen;
|
|
2038
2160
|
place(this.h, anchor, rec.inst);
|
|
2039
2161
|
disposers.push(() => {
|
|
2040
|
-
if (
|
|
2162
|
+
if (gen !== rec.gen)
|
|
2041
2163
|
return;
|
|
2042
2164
|
for (const d of rec.wiring)
|
|
2043
2165
|
d();
|
|
@@ -2053,7 +2175,7 @@ class IRRenderer {
|
|
|
2053
2175
|
this.wireInputs(child, benv, scopeNames, input, wiring);
|
|
2054
2176
|
if (child.contents)
|
|
2055
2177
|
input.renderer = this.slotRenderer(child.contents, benv);
|
|
2056
|
-
const state = reactive(
|
|
2178
|
+
const state = reactive(initial(def.state || {}), def.deep ?? false), statics = initial(def.statics ?? {});
|
|
2057
2179
|
let selfInst = null;
|
|
2058
2180
|
const irr = this;
|
|
2059
2181
|
const bus = selfBus(this.h, () => benv.lang?.() ?? irr.options.i18n?.lang() ?? "");
|
|
@@ -2061,7 +2183,7 @@ class IRRenderer {
|
|
|
2061
2183
|
...this.options.expose || {},
|
|
2062
2184
|
state,
|
|
2063
2185
|
input,
|
|
2064
|
-
static:
|
|
2186
|
+
static: statics,
|
|
2065
2187
|
context: benv.context,
|
|
2066
2188
|
setContext(arg, value) {
|
|
2067
2189
|
const write = (k, v) => writeContext(benv.context, k, v, irr.options.expose?.setContext);
|
|
@@ -2081,12 +2203,13 @@ class IRRenderer {
|
|
|
2081
2203
|
} catch (error) {
|
|
2082
2204
|
hooks.onError(error);
|
|
2083
2205
|
}
|
|
2206
|
+
const unwatchInput = watchInput(self, input, hooks);
|
|
2084
2207
|
const cenv = {
|
|
2085
2208
|
state,
|
|
2086
2209
|
input,
|
|
2087
2210
|
context: benv.context,
|
|
2088
2211
|
lang: benv.lang,
|
|
2089
|
-
static:
|
|
2212
|
+
static: statics,
|
|
2090
2213
|
self,
|
|
2091
2214
|
scope: undefined
|
|
2092
2215
|
};
|
|
@@ -2157,6 +2280,7 @@ class IRRenderer {
|
|
|
2157
2280
|
const i = this.live.indexOf(rec);
|
|
2158
2281
|
i > -1 && this.live.splice(i, 1);
|
|
2159
2282
|
unwatchContext?.();
|
|
2283
|
+
unwatchInput();
|
|
2160
2284
|
clearStyleBinds?.();
|
|
2161
2285
|
clearStyles?.();
|
|
2162
2286
|
destroy(this.h, inst);
|
|
@@ -2173,9 +2297,9 @@ class IRRenderer {
|
|
|
2173
2297
|
}
|
|
2174
2298
|
};
|
|
2175
2299
|
this.live.push(rec);
|
|
2176
|
-
const
|
|
2300
|
+
const gen = rec.gen;
|
|
2177
2301
|
disposers.push(() => {
|
|
2178
|
-
if (
|
|
2302
|
+
if (gen !== rec.gen)
|
|
2179
2303
|
return;
|
|
2180
2304
|
for (const d of rec.wiring)
|
|
2181
2305
|
d();
|
|
@@ -2186,11 +2310,16 @@ class IRRenderer {
|
|
|
2186
2310
|
execElement(child, anchor, benv, scopeNames, disposers) {
|
|
2187
2311
|
const h = this.h, el = h.element(child.name);
|
|
2188
2312
|
for (const [name, ci] of Object.entries(child.inputs)) {
|
|
2189
|
-
if ("
|
|
2313
|
+
if (name === "@ref") {
|
|
2314
|
+
const run = "lit" in ci ? () => ci.lit : this.runner(ci.e, scopeNames);
|
|
2315
|
+
disposers.push(refTo(benv, el, () => run(benv), (fn) => this.guarded(fn)));
|
|
2316
|
+
} else if (name[0] === "@")
|
|
2317
|
+
disposers.push(this.contentOf(el, name, ci, benv, scopeNames));
|
|
2318
|
+
else if ("lit" in ci)
|
|
2190
2319
|
applyAttr(h, el, name, ci.lit);
|
|
2191
2320
|
else {
|
|
2192
2321
|
const run = this.runner(ci.e, scopeNames);
|
|
2193
|
-
disposers.push(
|
|
2322
|
+
disposers.push(this.guarded(() => applyAttr(h, el, name, run(benv))).dispose);
|
|
2194
2323
|
}
|
|
2195
2324
|
}
|
|
2196
2325
|
for (const ev of child.events)
|
|
@@ -2204,38 +2333,58 @@ class IRRenderer {
|
|
|
2204
2333
|
h.insertAfter(anchor, [el]);
|
|
2205
2334
|
disposers.push(() => h.remove(el, true));
|
|
2206
2335
|
}
|
|
2336
|
+
contentOf(el, name, ci, benv, scopeNames) {
|
|
2337
|
+
const h = this.h;
|
|
2338
|
+
if (name === "@format") {
|
|
2339
|
+
const { ref, e } = "lit" in ci ? ci.lit : {};
|
|
2340
|
+
const run = e === undefined ? () => ({}) : this.runner(e, scopeNames);
|
|
2341
|
+
return this.guarded(() => {
|
|
2342
|
+
const text = this.options.i18n?.format(ref || "", run(benv), benv.lang?.());
|
|
2343
|
+
h.content(el, text == null ? "" : String(text));
|
|
2344
|
+
}).dispose;
|
|
2345
|
+
}
|
|
2346
|
+
const run = "lit" in ci ? () => ci.lit : this.runner(ci.e, scopeNames);
|
|
2347
|
+
return this.guarded(() => {
|
|
2348
|
+
const v = run(benv), s = v == null ? "" : String(v);
|
|
2349
|
+
name === "@html" && h.html ? h.html(el, s) : h.content(el, s);
|
|
2350
|
+
}).dispose;
|
|
2351
|
+
}
|
|
2207
2352
|
eventDispatcher(instruction, scopeNames, benv) {
|
|
2208
|
-
const segs = splitTopLevel(instruction);
|
|
2353
|
+
const segs = splitTopLevel(instruction), named = /^[A-Za-z_$][\w$]*$/.test(segs[0] || "") && !scopeNames.includes(segs[0]);
|
|
2209
2354
|
return (...params) => untrack(() => {
|
|
2210
2355
|
const resolveFn = (src) => {
|
|
2211
|
-
|
|
2356
|
+
if (named && benv.self && !this.options.guard?.self(src) && typeof benv.self[src] === "function")
|
|
2357
|
+
return benv.self[src];
|
|
2212
2358
|
try {
|
|
2213
|
-
|
|
2359
|
+
return this.srcRunner(src, scopeNames)(benv);
|
|
2214
2360
|
} catch (e) {
|
|
2215
|
-
|
|
2361
|
+
return;
|
|
2216
2362
|
}
|
|
2217
|
-
if (typeof v !== "function" && benv.self && !this.options.guard?.self(src) && typeof benv.self[src] === "function")
|
|
2218
|
-
v = benv.self[src];
|
|
2219
|
-
return v;
|
|
2220
2363
|
};
|
|
2221
2364
|
if (!segs.length)
|
|
2222
2365
|
return;
|
|
2223
2366
|
const fn = resolveFn(segs[0]);
|
|
2224
2367
|
if (typeof fn !== "function")
|
|
2225
2368
|
return;
|
|
2226
|
-
const
|
|
2227
|
-
|
|
2369
|
+
const failed = (error) => this.hooks ? this.hooks.onError(error) : console.error("[lips:ir]", error);
|
|
2370
|
+
try {
|
|
2371
|
+
const args = segs.slice(1).map((src) => this.srcRunner(src, scopeNames)(benv));
|
|
2372
|
+
const out = fn(...args, ...params);
|
|
2373
|
+
out && typeof out.then === "function" && out.then(undefined, failed);
|
|
2374
|
+
} catch (error) {
|
|
2375
|
+
failed(error);
|
|
2376
|
+
}
|
|
2228
2377
|
});
|
|
2229
2378
|
}
|
|
2230
2379
|
}
|
|
2231
2380
|
function renderIR(ir, setup = {}, options = {}) {
|
|
2232
|
-
const h = options.host || domHost, state = reactive(setup.state || {}, setup.deep ?? false), input = setup.input
|
|
2381
|
+
const h = options.host || domHost, state = reactive(setup.state || {}, setup.deep ?? false), input = reactive(setup.input || {}, setup.deep ?? false), statics = setup.static || {};
|
|
2233
2382
|
let rootInst = null;
|
|
2234
2383
|
const bus = selfBus(h, () => options.i18n?.lang() ?? "");
|
|
2235
2384
|
const self = bus.bind(Object.assign(Object.create(bus.proto), {
|
|
2236
2385
|
state,
|
|
2237
2386
|
input,
|
|
2238
|
-
static:
|
|
2387
|
+
static: statics,
|
|
2239
2388
|
...options.expose || {},
|
|
2240
2389
|
...setup.expose || {}
|
|
2241
2390
|
}), () => rootInst);
|
|
@@ -2244,7 +2393,7 @@ function renderIR(ir, setup = {}, options = {}) {
|
|
|
2244
2393
|
state,
|
|
2245
2394
|
input,
|
|
2246
2395
|
context: setup.context,
|
|
2247
|
-
static:
|
|
2396
|
+
static: statics,
|
|
2248
2397
|
self,
|
|
2249
2398
|
scope: undefined
|
|
2250
2399
|
};
|
|
@@ -2255,10 +2404,11 @@ function renderIR(ir, setup = {}, options = {}) {
|
|
|
2255
2404
|
hooks.onError(error);
|
|
2256
2405
|
}
|
|
2257
2406
|
try {
|
|
2258
|
-
|
|
2407
|
+
Object.keys(input).length && typeof self.onInput === "function" && self.onInput(input);
|
|
2259
2408
|
} catch (error) {
|
|
2260
2409
|
hooks.onError(error);
|
|
2261
2410
|
}
|
|
2411
|
+
const unwatchInput = watchInput(self, input, hooks);
|
|
2262
2412
|
let renderer = new IRRenderer(ir, options, hooks);
|
|
2263
2413
|
let current = renderer.renderBlock(ir.root, env);
|
|
2264
2414
|
rootInst = current;
|
|
@@ -2311,6 +2461,7 @@ function renderIR(ir, setup = {}, options = {}) {
|
|
|
2311
2461
|
return { changes, salvaged: renderer.salvaged };
|
|
2312
2462
|
},
|
|
2313
2463
|
dispose() {
|
|
2464
|
+
unwatchInput();
|
|
2314
2465
|
clearStyleBinds?.();
|
|
2315
2466
|
clearStyles?.();
|
|
2316
2467
|
destroy(h, current);
|
|
@@ -2545,7 +2696,11 @@ var BUILTINS = {};
|
|
|
2545
2696
|
function registerBuiltin(name, template) {
|
|
2546
2697
|
BUILTINS[name] = template;
|
|
2547
2698
|
}
|
|
2548
|
-
var
|
|
2699
|
+
var TAKEN = null;
|
|
2700
|
+
function setNameCheck(fn) {
|
|
2701
|
+
TAKEN = fn;
|
|
2702
|
+
}
|
|
2703
|
+
var RESERVED = [
|
|
2549
2704
|
"state",
|
|
2550
2705
|
"input",
|
|
2551
2706
|
"static",
|
|
@@ -2564,7 +2719,8 @@ var RESERVED_MEMBERS = new Set([
|
|
|
2564
2719
|
"replaceWith",
|
|
2565
2720
|
"render",
|
|
2566
2721
|
"swap"
|
|
2567
|
-
]
|
|
2722
|
+
];
|
|
2723
|
+
var RESERVED_MEMBERS = new Set(RESERVED);
|
|
2568
2724
|
function guardHandlers(handler) {
|
|
2569
2725
|
if (!handler)
|
|
2570
2726
|
return;
|
|
@@ -2586,14 +2742,14 @@ class IRFacadeComponent extends Events {
|
|
|
2586
2742
|
this.lips = lips;
|
|
2587
2743
|
this.template = template;
|
|
2588
2744
|
const handlers = guardHandlers(template.handler);
|
|
2589
|
-
this.state = reactive(
|
|
2590
|
-
const inputR =
|
|
2745
|
+
this.state = reactive(initial(template.state || {}), true);
|
|
2746
|
+
const inputR = reactive({ ...input }, true);
|
|
2591
2747
|
const emitExternal = (event, ...args) => super.emit(event, ...args);
|
|
2592
2748
|
this.instance = renderIR(ir, {
|
|
2593
2749
|
state: this.state,
|
|
2594
2750
|
input: inputR,
|
|
2595
2751
|
context: lips.getContext(),
|
|
2596
|
-
static: template.static ?? template._static,
|
|
2752
|
+
static: initial(template.static ?? template._static),
|
|
2597
2753
|
handlers,
|
|
2598
2754
|
deep: true,
|
|
2599
2755
|
stylesheet: lips.styleFor(name, template),
|
|
@@ -2606,7 +2762,7 @@ class IRFacadeComponent extends Events {
|
|
|
2606
2762
|
context: lips.getContext()
|
|
2607
2763
|
}
|
|
2608
2764
|
}, options);
|
|
2609
|
-
const watched = template.watchContext
|
|
2765
|
+
const watched = template.watchContext;
|
|
2610
2766
|
if (watched?.length && typeof handlers?.onContext === "function")
|
|
2611
2767
|
this.contextWatcher = lips.watchContext(watched, () => {
|
|
2612
2768
|
try {
|
|
@@ -2646,6 +2802,7 @@ class IRLips {
|
|
|
2646
2802
|
config;
|
|
2647
2803
|
debug;
|
|
2648
2804
|
store = new Map;
|
|
2805
|
+
plugins = new Map;
|
|
2649
2806
|
irCache = new WeakMap;
|
|
2650
2807
|
defCache = new WeakMap;
|
|
2651
2808
|
styleCache = new WeakMap;
|
|
@@ -2686,9 +2843,30 @@ class IRLips {
|
|
|
2686
2843
|
});
|
|
2687
2844
|
}
|
|
2688
2845
|
register(name, template) {
|
|
2846
|
+
const is = TAKEN?.(name);
|
|
2847
|
+
if (is)
|
|
2848
|
+
throw new Error(`[lips] <${name}> is ${is}: the compiler reads the tag as one, so a component of that name never renders. Register it under another name`);
|
|
2849
|
+
guardHandlers(template.handler);
|
|
2689
2850
|
this.store.set(name, template);
|
|
2690
2851
|
return this;
|
|
2691
2852
|
}
|
|
2853
|
+
use(plugin, options) {
|
|
2854
|
+
const had = this.plugins.get(plugin.name);
|
|
2855
|
+
if (had && had !== plugin)
|
|
2856
|
+
throw new Error(`[lips] two plugins named <${plugin.name}>: one is installed already`);
|
|
2857
|
+
if (had)
|
|
2858
|
+
return this;
|
|
2859
|
+
this.plugins.set(plugin.name, plugin);
|
|
2860
|
+
plugin.requires?.forEach((each) => this.use(each));
|
|
2861
|
+
for (const [name, template] of Object.entries(plugin.components || {})) {
|
|
2862
|
+
const held = this.store.get(name);
|
|
2863
|
+
if (held && held !== template)
|
|
2864
|
+
throw new Error(`[lips] <${name}> of plugin <${plugin.name}> is registered already, by something else`);
|
|
2865
|
+
this.register(name, template);
|
|
2866
|
+
}
|
|
2867
|
+
plugin.install?.(this, options);
|
|
2868
|
+
return this;
|
|
2869
|
+
}
|
|
2692
2870
|
unregister(name) {
|
|
2693
2871
|
this.store.delete(name);
|
|
2694
2872
|
return this;
|
|
@@ -2732,6 +2910,13 @@ class IRLips {
|
|
|
2732
2910
|
}
|
|
2733
2911
|
return style;
|
|
2734
2912
|
}
|
|
2913
|
+
unnamed(template) {
|
|
2914
|
+
let name = this.anonymous.get(template);
|
|
2915
|
+
!name && this.anonymous.set(template, name = `dynamic-${++this.anonymousCount}`);
|
|
2916
|
+
return name;
|
|
2917
|
+
}
|
|
2918
|
+
anonymous = new WeakMap;
|
|
2919
|
+
anonymousCount = 0;
|
|
2735
2920
|
defFor(name, template) {
|
|
2736
2921
|
let def = this.defCache.get(template);
|
|
2737
2922
|
if (!def) {
|
|
@@ -2739,7 +2924,7 @@ class IRLips {
|
|
|
2739
2924
|
ir: this.compile(template),
|
|
2740
2925
|
state: template.state,
|
|
2741
2926
|
statics: template.static ?? template._static,
|
|
2742
|
-
context: template.watchContext
|
|
2927
|
+
context: template.watchContext,
|
|
2743
2928
|
stylesheet: this.styleFor(name, template),
|
|
2744
2929
|
nsp: name,
|
|
2745
2930
|
handlers: guardHandlers(template.handler),
|
|
@@ -2753,7 +2938,7 @@ class IRLips {
|
|
|
2753
2938
|
const options = {
|
|
2754
2939
|
mode: this.config?.mode,
|
|
2755
2940
|
components: this.componentsProxy,
|
|
2756
|
-
resolveTemplate: (value) => value && (typeof value.default === "string" || value.ir) ? this.defFor(value.name ||
|
|
2941
|
+
resolveTemplate: (value) => value && (typeof value.default === "string" || value.ir) ? this.defFor(value.name || this.unnamed(value), value) : undefined,
|
|
2757
2942
|
expose: {
|
|
2758
2943
|
setContext: (arg, value) => this.setContext(arg, value),
|
|
2759
2944
|
setLanguage: (lang) => this.setLanguage(lang)
|
|
@@ -2779,9 +2964,10 @@ class IRLips {
|
|
|
2779
2964
|
return new IRFacadeComponent(this, name, template, input, this.compile(template), this.u ? this.u.runtime(options) : options);
|
|
2780
2965
|
}
|
|
2781
2966
|
root(template, selector) {
|
|
2782
|
-
|
|
2783
|
-
this.__root
|
|
2784
|
-
|
|
2967
|
+
const root = this.render("__ROOT__", template);
|
|
2968
|
+
this.__root = root;
|
|
2969
|
+
root.appendTo(selector);
|
|
2970
|
+
return root;
|
|
2785
2971
|
}
|
|
2786
2972
|
setLanguage(lang) {
|
|
2787
2973
|
this.i18n.lang = lang;
|
|
@@ -2829,6 +3015,162 @@ class IRLips {
|
|
|
2829
3015
|
}
|
|
2830
3016
|
}
|
|
2831
3017
|
|
|
3018
|
+
// src/ir/tags.ts
|
|
3019
|
+
var CONTROL_TAGS = new Set([
|
|
3020
|
+
"if",
|
|
3021
|
+
"else-if",
|
|
3022
|
+
"else",
|
|
3023
|
+
"for",
|
|
3024
|
+
"switch",
|
|
3025
|
+
"async",
|
|
3026
|
+
"let",
|
|
3027
|
+
"const",
|
|
3028
|
+
"log",
|
|
3029
|
+
"context",
|
|
3030
|
+
"i18n"
|
|
3031
|
+
]);
|
|
3032
|
+
var ARM_TAGS = new Set(["case", "default", "then", "catch", "loading"]);
|
|
3033
|
+
var HTML_TAGS = new Set([
|
|
3034
|
+
"a",
|
|
3035
|
+
"abbr",
|
|
3036
|
+
"address",
|
|
3037
|
+
"area",
|
|
3038
|
+
"article",
|
|
3039
|
+
"aside",
|
|
3040
|
+
"audio",
|
|
3041
|
+
"b",
|
|
3042
|
+
"base",
|
|
3043
|
+
"bdi",
|
|
3044
|
+
"bdo",
|
|
3045
|
+
"blockquote",
|
|
3046
|
+
"body",
|
|
3047
|
+
"br",
|
|
3048
|
+
"button",
|
|
3049
|
+
"canvas",
|
|
3050
|
+
"caption",
|
|
3051
|
+
"cite",
|
|
3052
|
+
"code",
|
|
3053
|
+
"col",
|
|
3054
|
+
"colgroup",
|
|
3055
|
+
"data",
|
|
3056
|
+
"datalist",
|
|
3057
|
+
"dd",
|
|
3058
|
+
"del",
|
|
3059
|
+
"details",
|
|
3060
|
+
"dfn",
|
|
3061
|
+
"dialog",
|
|
3062
|
+
"div",
|
|
3063
|
+
"dl",
|
|
3064
|
+
"dt",
|
|
3065
|
+
"em",
|
|
3066
|
+
"embed",
|
|
3067
|
+
"fieldset",
|
|
3068
|
+
"figcaption",
|
|
3069
|
+
"figure",
|
|
3070
|
+
"footer",
|
|
3071
|
+
"form",
|
|
3072
|
+
"h1",
|
|
3073
|
+
"h2",
|
|
3074
|
+
"h3",
|
|
3075
|
+
"h4",
|
|
3076
|
+
"h5",
|
|
3077
|
+
"h6",
|
|
3078
|
+
"head",
|
|
3079
|
+
"header",
|
|
3080
|
+
"hgroup",
|
|
3081
|
+
"hr",
|
|
3082
|
+
"html",
|
|
3083
|
+
"i",
|
|
3084
|
+
"iframe",
|
|
3085
|
+
"img",
|
|
3086
|
+
"input",
|
|
3087
|
+
"ins",
|
|
3088
|
+
"kbd",
|
|
3089
|
+
"label",
|
|
3090
|
+
"legend",
|
|
3091
|
+
"li",
|
|
3092
|
+
"link",
|
|
3093
|
+
"main",
|
|
3094
|
+
"map",
|
|
3095
|
+
"mark",
|
|
3096
|
+
"menu",
|
|
3097
|
+
"meta",
|
|
3098
|
+
"meter",
|
|
3099
|
+
"nav",
|
|
3100
|
+
"noscript",
|
|
3101
|
+
"object",
|
|
3102
|
+
"ol",
|
|
3103
|
+
"optgroup",
|
|
3104
|
+
"option",
|
|
3105
|
+
"output",
|
|
3106
|
+
"p",
|
|
3107
|
+
"picture",
|
|
3108
|
+
"pre",
|
|
3109
|
+
"progress",
|
|
3110
|
+
"q",
|
|
3111
|
+
"rp",
|
|
3112
|
+
"rt",
|
|
3113
|
+
"ruby",
|
|
3114
|
+
"s",
|
|
3115
|
+
"samp",
|
|
3116
|
+
"script",
|
|
3117
|
+
"section",
|
|
3118
|
+
"select",
|
|
3119
|
+
"slot",
|
|
3120
|
+
"small",
|
|
3121
|
+
"source",
|
|
3122
|
+
"span",
|
|
3123
|
+
"strong",
|
|
3124
|
+
"style",
|
|
3125
|
+
"sub",
|
|
3126
|
+
"summary",
|
|
3127
|
+
"sup",
|
|
3128
|
+
"table",
|
|
3129
|
+
"tbody",
|
|
3130
|
+
"td",
|
|
3131
|
+
"template",
|
|
3132
|
+
"textarea",
|
|
3133
|
+
"tfoot",
|
|
3134
|
+
"th",
|
|
3135
|
+
"thead",
|
|
3136
|
+
"time",
|
|
3137
|
+
"title",
|
|
3138
|
+
"tr",
|
|
3139
|
+
"track",
|
|
3140
|
+
"u",
|
|
3141
|
+
"ul",
|
|
3142
|
+
"var",
|
|
3143
|
+
"video",
|
|
3144
|
+
"wbr",
|
|
3145
|
+
"svg",
|
|
3146
|
+
"circle",
|
|
3147
|
+
"clippath",
|
|
3148
|
+
"defs",
|
|
3149
|
+
"ellipse",
|
|
3150
|
+
"foreignobject",
|
|
3151
|
+
"g",
|
|
3152
|
+
"image",
|
|
3153
|
+
"line",
|
|
3154
|
+
"lineargradient",
|
|
3155
|
+
"marker",
|
|
3156
|
+
"mask",
|
|
3157
|
+
"path",
|
|
3158
|
+
"pattern",
|
|
3159
|
+
"polygon",
|
|
3160
|
+
"polyline",
|
|
3161
|
+
"radialgradient",
|
|
3162
|
+
"rect",
|
|
3163
|
+
"stop",
|
|
3164
|
+
"symbol",
|
|
3165
|
+
"text",
|
|
3166
|
+
"tspan",
|
|
3167
|
+
"use"
|
|
3168
|
+
]);
|
|
3169
|
+
function taken(name) {
|
|
3170
|
+
const tag = name.toLowerCase();
|
|
3171
|
+
return HTML_TAGS.has(tag) ? "an HTML or SVG element" : CONTROL_TAGS.has(tag) || ARM_TAGS.has(tag) || tag === "macro" ? "a template syntax tag" : undefined;
|
|
3172
|
+
}
|
|
3173
|
+
|
|
2832
3174
|
// src/i18n/intl.ts
|
|
2833
3175
|
var g = globalThis;
|
|
2834
3176
|
var I = g.Intl ??= {};
|
|
@@ -2956,7 +3298,7 @@ var whitespaceChars = new Set(`
|
|
|
2956
3298
|
\r `);
|
|
2957
3299
|
var pos;
|
|
2958
3300
|
var source;
|
|
2959
|
-
var MissingSyntax = (
|
|
3301
|
+
var MissingSyntax = (pos, expected) => new MessageSyntaxError("missing-syntax", pos, pos + expected.length, expected);
|
|
2960
3302
|
var SyntaxError = (...args) => new MessageSyntaxError(...args);
|
|
2961
3303
|
function expect(searchString, consume) {
|
|
2962
3304
|
if (source.startsWith(searchString, pos)) {
|
|
@@ -3026,12 +3368,12 @@ function pattern(quoted) {
|
|
|
3026
3368
|
else
|
|
3027
3369
|
throw MissingSyntax(pos, "{{");
|
|
3028
3370
|
}
|
|
3029
|
-
const
|
|
3371
|
+
const pattern = [];
|
|
3030
3372
|
loop:
|
|
3031
3373
|
while (pos < source.length) {
|
|
3032
3374
|
switch (source[pos]) {
|
|
3033
3375
|
case "{": {
|
|
3034
|
-
|
|
3376
|
+
pattern.push(expression(true));
|
|
3035
3377
|
break;
|
|
3036
3378
|
}
|
|
3037
3379
|
case "}":
|
|
@@ -3039,7 +3381,7 @@ function pattern(quoted) {
|
|
|
3039
3381
|
throw SyntaxError("parse-error", pos);
|
|
3040
3382
|
break loop;
|
|
3041
3383
|
default: {
|
|
3042
|
-
|
|
3384
|
+
pattern.push(text());
|
|
3043
3385
|
}
|
|
3044
3386
|
}
|
|
3045
3387
|
}
|
|
@@ -3049,20 +3391,20 @@ function pattern(quoted) {
|
|
|
3049
3391
|
else
|
|
3050
3392
|
throw MissingSyntax(pos, "}}");
|
|
3051
3393
|
}
|
|
3052
|
-
return
|
|
3394
|
+
return pattern;
|
|
3053
3395
|
}
|
|
3054
3396
|
function declarations() {
|
|
3055
|
-
const
|
|
3397
|
+
const declarations = [];
|
|
3056
3398
|
ws();
|
|
3057
3399
|
loop:
|
|
3058
3400
|
while (source[pos] === ".") {
|
|
3059
3401
|
const keyword = source.substr(pos, 6);
|
|
3060
3402
|
switch (keyword) {
|
|
3061
3403
|
case ".input":
|
|
3062
|
-
|
|
3404
|
+
declarations.push(inputDeclaration());
|
|
3063
3405
|
break;
|
|
3064
3406
|
case ".local":
|
|
3065
|
-
|
|
3407
|
+
declarations.push(localDeclaration());
|
|
3066
3408
|
break;
|
|
3067
3409
|
case ".match":
|
|
3068
3410
|
break loop;
|
|
@@ -3071,7 +3413,7 @@ function declarations() {
|
|
|
3071
3413
|
}
|
|
3072
3414
|
ws();
|
|
3073
3415
|
}
|
|
3074
|
-
return
|
|
3416
|
+
return declarations;
|
|
3075
3417
|
}
|
|
3076
3418
|
function inputDeclaration() {
|
|
3077
3419
|
pos += 6;
|
|
@@ -3156,7 +3498,7 @@ function expression(allowMarkup) {
|
|
|
3156
3498
|
}
|
|
3157
3499
|
function options() {
|
|
3158
3500
|
ws("/}");
|
|
3159
|
-
const
|
|
3501
|
+
const options = {};
|
|
3160
3502
|
let isEmpty = true;
|
|
3161
3503
|
while (pos < source.length) {
|
|
3162
3504
|
const next = source[pos];
|
|
@@ -3164,40 +3506,40 @@ function options() {
|
|
|
3164
3506
|
break;
|
|
3165
3507
|
const start = pos;
|
|
3166
3508
|
const name_ = identifier();
|
|
3167
|
-
if (Object.hasOwn(
|
|
3509
|
+
if (Object.hasOwn(options, name_)) {
|
|
3168
3510
|
throw SyntaxError("duplicate-option-name", start, pos);
|
|
3169
3511
|
}
|
|
3170
3512
|
ws();
|
|
3171
3513
|
expect("=", true);
|
|
3172
3514
|
ws();
|
|
3173
|
-
|
|
3515
|
+
options[name_] = value(true);
|
|
3174
3516
|
isEmpty = false;
|
|
3175
3517
|
ws("/}");
|
|
3176
3518
|
}
|
|
3177
|
-
return isEmpty ? null :
|
|
3519
|
+
return isEmpty ? null : options;
|
|
3178
3520
|
}
|
|
3179
3521
|
function attributes() {
|
|
3180
|
-
const
|
|
3522
|
+
const attributes = {};
|
|
3181
3523
|
let isEmpty = true;
|
|
3182
3524
|
while (source[pos] === "@") {
|
|
3183
3525
|
const start = pos;
|
|
3184
3526
|
pos += 1;
|
|
3185
3527
|
const name_ = identifier();
|
|
3186
|
-
if (Object.hasOwn(
|
|
3528
|
+
if (Object.hasOwn(attributes, name_)) {
|
|
3187
3529
|
throw SyntaxError("duplicate-attribute", start, pos);
|
|
3188
3530
|
}
|
|
3189
3531
|
ws("=/}");
|
|
3190
3532
|
if (source[pos] === "=") {
|
|
3191
3533
|
pos += 1;
|
|
3192
3534
|
ws();
|
|
3193
|
-
|
|
3535
|
+
attributes[name_] = literal(true);
|
|
3194
3536
|
ws("/}");
|
|
3195
3537
|
} else {
|
|
3196
|
-
|
|
3538
|
+
attributes[name_] = true;
|
|
3197
3539
|
}
|
|
3198
3540
|
isEmpty = false;
|
|
3199
3541
|
}
|
|
3200
|
-
return isEmpty ? null :
|
|
3542
|
+
return isEmpty ? null : attributes;
|
|
3201
3543
|
}
|
|
3202
3544
|
function text() {
|
|
3203
3545
|
let value = "";
|
|
@@ -3233,34 +3575,34 @@ function variable() {
|
|
|
3233
3575
|
function literal(required) {
|
|
3234
3576
|
if (source[pos] === "|")
|
|
3235
3577
|
return quotedLiteral();
|
|
3236
|
-
const
|
|
3237
|
-
if (!
|
|
3578
|
+
const value = parseUnquotedLiteralValue(source, pos);
|
|
3579
|
+
if (!value) {
|
|
3238
3580
|
if (required)
|
|
3239
3581
|
throw SyntaxError("empty-token", pos);
|
|
3240
3582
|
else
|
|
3241
3583
|
return;
|
|
3242
3584
|
}
|
|
3243
|
-
pos +=
|
|
3244
|
-
return { type: "literal", value
|
|
3585
|
+
pos += value.length;
|
|
3586
|
+
return { type: "literal", value };
|
|
3245
3587
|
}
|
|
3246
3588
|
function quotedLiteral() {
|
|
3247
3589
|
pos += 1;
|
|
3248
|
-
let
|
|
3590
|
+
let value = "";
|
|
3249
3591
|
for (let i = pos;i < source.length; ++i) {
|
|
3250
3592
|
switch (source[i]) {
|
|
3251
3593
|
case "\\": {
|
|
3252
3594
|
const esc = source[i + 1];
|
|
3253
3595
|
if (!"\\{|}".includes(esc))
|
|
3254
3596
|
throw SyntaxError("bad-escape", i, i + 2);
|
|
3255
|
-
|
|
3597
|
+
value += source.substring(pos, i) + esc;
|
|
3256
3598
|
i += 1;
|
|
3257
3599
|
pos = i + 1;
|
|
3258
3600
|
break;
|
|
3259
3601
|
}
|
|
3260
3602
|
case "|":
|
|
3261
|
-
|
|
3603
|
+
value += source.substring(pos, i);
|
|
3262
3604
|
pos = i + 1;
|
|
3263
|
-
return { type: "literal", value
|
|
3605
|
+
return { type: "literal", value };
|
|
3264
3606
|
}
|
|
3265
3607
|
}
|
|
3266
3608
|
throw MissingSyntax(source.length, "|");
|
|
@@ -3274,11 +3616,11 @@ function identifier() {
|
|
|
3274
3616
|
return name_;
|
|
3275
3617
|
}
|
|
3276
3618
|
function name() {
|
|
3277
|
-
const
|
|
3278
|
-
if (!
|
|
3619
|
+
const name = parseNameValue(source, pos);
|
|
3620
|
+
if (!name)
|
|
3279
3621
|
throw SyntaxError("empty-token", pos);
|
|
3280
|
-
pos =
|
|
3281
|
-
return
|
|
3622
|
+
pos = name.end;
|
|
3623
|
+
return name.value;
|
|
3282
3624
|
}
|
|
3283
3625
|
function ws(req = false) {
|
|
3284
3626
|
let next = source[pos];
|
|
@@ -3299,14 +3641,14 @@ function ws(req = false) {
|
|
|
3299
3641
|
}
|
|
3300
3642
|
// node_modules/messageformat/lib/data-model/visit.js
|
|
3301
3643
|
function visit(msg, visitors) {
|
|
3302
|
-
const { node, pattern
|
|
3303
|
-
const { functionRef = node, attributes
|
|
3644
|
+
const { node, pattern } = visitors;
|
|
3645
|
+
const { functionRef = node, attributes = null, declaration = node, expression = node, key = node, markup = node, options = null, value = node, variant = node } = visitors;
|
|
3304
3646
|
const handleOptions = (options_, context) => {
|
|
3305
3647
|
if (options_) {
|
|
3306
|
-
const end =
|
|
3307
|
-
if (
|
|
3648
|
+
const end = options?.(options_, context);
|
|
3649
|
+
if (value) {
|
|
3308
3650
|
for (const value_ of Object.values(options_)) {
|
|
3309
|
-
|
|
3651
|
+
value(value_, context, "option");
|
|
3310
3652
|
}
|
|
3311
3653
|
}
|
|
3312
3654
|
end?.();
|
|
@@ -3314,11 +3656,11 @@ function visit(msg, visitors) {
|
|
|
3314
3656
|
};
|
|
3315
3657
|
const handleAttributes = (attributes_, context) => {
|
|
3316
3658
|
if (attributes_) {
|
|
3317
|
-
const end =
|
|
3318
|
-
if (
|
|
3659
|
+
const end = attributes?.(attributes_, context);
|
|
3660
|
+
if (value) {
|
|
3319
3661
|
for (const value_ of Object.values(attributes_)) {
|
|
3320
3662
|
if (value_ !== true)
|
|
3321
|
-
|
|
3663
|
+
value(value_, context, "attribute");
|
|
3322
3664
|
}
|
|
3323
3665
|
}
|
|
3324
3666
|
end?.();
|
|
@@ -3329,9 +3671,9 @@ function visit(msg, visitors) {
|
|
|
3329
3671
|
let end;
|
|
3330
3672
|
switch (exp.type) {
|
|
3331
3673
|
case "expression": {
|
|
3332
|
-
end =
|
|
3674
|
+
end = expression?.(exp, context);
|
|
3333
3675
|
if (exp.arg)
|
|
3334
|
-
|
|
3676
|
+
value?.(exp.arg, context, "arg");
|
|
3335
3677
|
if (exp.functionRef) {
|
|
3336
3678
|
const endA = functionRef?.(exp.functionRef, context, exp.arg);
|
|
3337
3679
|
handleOptions(exp.functionRef.options, context);
|
|
@@ -3351,7 +3693,7 @@ function visit(msg, visitors) {
|
|
|
3351
3693
|
}
|
|
3352
3694
|
};
|
|
3353
3695
|
const handlePattern = (pat) => {
|
|
3354
|
-
const end =
|
|
3696
|
+
const end = pattern?.(pat);
|
|
3355
3697
|
for (const el of pat)
|
|
3356
3698
|
handleElement(el, "placeholder");
|
|
3357
3699
|
end?.();
|
|
@@ -3365,11 +3707,11 @@ function visit(msg, visitors) {
|
|
|
3365
3707
|
if (msg.type === "message") {
|
|
3366
3708
|
handlePattern(msg.pattern);
|
|
3367
3709
|
} else {
|
|
3368
|
-
if (
|
|
3710
|
+
if (value)
|
|
3369
3711
|
for (const sel of msg.selectors)
|
|
3370
|
-
|
|
3712
|
+
value(sel, "selector", "arg");
|
|
3371
3713
|
for (const vari of msg.variants) {
|
|
3372
|
-
const end =
|
|
3714
|
+
const end = variant?.(vari);
|
|
3373
3715
|
if (key)
|
|
3374
3716
|
vari.keys.forEach(key);
|
|
3375
3717
|
handlePattern(vari.value);
|
|
@@ -3412,34 +3754,34 @@ function validate(msg, onError = (type, node) => {
|
|
|
3412
3754
|
if (functionRef)
|
|
3413
3755
|
functions.add(functionRef.name);
|
|
3414
3756
|
},
|
|
3415
|
-
value(
|
|
3416
|
-
if (
|
|
3757
|
+
value(value, context, position) {
|
|
3758
|
+
if (value.type !== "variable")
|
|
3417
3759
|
return;
|
|
3418
|
-
variables.add(
|
|
3760
|
+
variables.add(value.name);
|
|
3419
3761
|
switch (context) {
|
|
3420
3762
|
case "declaration":
|
|
3421
3763
|
if (position !== "arg" || setArgAsDeclared) {
|
|
3422
|
-
declared.add(
|
|
3764
|
+
declared.add(value.name);
|
|
3423
3765
|
}
|
|
3424
3766
|
break;
|
|
3425
3767
|
case "selector":
|
|
3426
3768
|
selectorCount += 1;
|
|
3427
|
-
missingFallback =
|
|
3428
|
-
if (!annotated.has(
|
|
3429
|
-
onError("missing-selector-annotation",
|
|
3769
|
+
missingFallback = value;
|
|
3770
|
+
if (!annotated.has(value.name)) {
|
|
3771
|
+
onError("missing-selector-annotation", value);
|
|
3430
3772
|
}
|
|
3431
3773
|
}
|
|
3432
3774
|
},
|
|
3433
|
-
variant(
|
|
3434
|
-
const { keys } =
|
|
3775
|
+
variant(variant) {
|
|
3776
|
+
const { keys } = variant;
|
|
3435
3777
|
if (keys.length !== selectorCount)
|
|
3436
|
-
onError("key-mismatch",
|
|
3778
|
+
onError("key-mismatch", variant);
|
|
3437
3779
|
const strKeys = JSON.stringify(keys.map((key) => key.type === "literal" ? key.value : 0));
|
|
3438
3780
|
if (variants.has(strKeys))
|
|
3439
|
-
onError("duplicate-variant",
|
|
3781
|
+
onError("duplicate-variant", variant);
|
|
3440
3782
|
else
|
|
3441
3783
|
variants.add(strKeys);
|
|
3442
|
-
missingFallback &&= keys.every((key) => key.type === "*") ? null :
|
|
3784
|
+
missingFallback &&= keys.every((key) => key.type === "*") ? null : variant;
|
|
3443
3785
|
}
|
|
3444
3786
|
});
|
|
3445
3787
|
if (missingFallback)
|
|
@@ -3470,66 +3812,66 @@ function getLocaleDir(locale) {
|
|
|
3470
3812
|
return "auto";
|
|
3471
3813
|
}
|
|
3472
3814
|
// node_modules/messageformat/lib/functions/utils.js
|
|
3473
|
-
function asBoolean(
|
|
3474
|
-
if (
|
|
3475
|
-
|
|
3476
|
-
if (typeof
|
|
3477
|
-
return
|
|
3478
|
-
if (
|
|
3479
|
-
|
|
3480
|
-
if (
|
|
3815
|
+
function asBoolean(value) {
|
|
3816
|
+
if (value && typeof value === "object")
|
|
3817
|
+
value = value.valueOf();
|
|
3818
|
+
if (typeof value === "boolean")
|
|
3819
|
+
return value;
|
|
3820
|
+
if (value && typeof value === "object")
|
|
3821
|
+
value = String(value);
|
|
3822
|
+
if (value === "true")
|
|
3481
3823
|
return true;
|
|
3482
|
-
if (
|
|
3824
|
+
if (value === "false")
|
|
3483
3825
|
return false;
|
|
3484
3826
|
throw new RangeError("Not a boolean");
|
|
3485
3827
|
}
|
|
3486
|
-
function asPositiveInteger(
|
|
3487
|
-
if (
|
|
3488
|
-
|
|
3489
|
-
if (
|
|
3490
|
-
|
|
3491
|
-
if (typeof
|
|
3492
|
-
|
|
3493
|
-
}
|
|
3494
|
-
if (typeof
|
|
3495
|
-
return
|
|
3828
|
+
function asPositiveInteger(value) {
|
|
3829
|
+
if (value && typeof value === "object")
|
|
3830
|
+
value = value.valueOf();
|
|
3831
|
+
if (value && typeof value === "object")
|
|
3832
|
+
value = String(value);
|
|
3833
|
+
if (typeof value === "string" && /^(0|[1-9][0-9]*)$/.test(value)) {
|
|
3834
|
+
value = Number(value);
|
|
3835
|
+
}
|
|
3836
|
+
if (typeof value === "number" && value >= 0 && Number.isInteger(value)) {
|
|
3837
|
+
return value;
|
|
3496
3838
|
}
|
|
3497
3839
|
throw new RangeError("Not a positive integer");
|
|
3498
3840
|
}
|
|
3499
|
-
function asString(
|
|
3500
|
-
if (
|
|
3501
|
-
|
|
3502
|
-
if (typeof
|
|
3503
|
-
return
|
|
3504
|
-
if (
|
|
3505
|
-
return String(
|
|
3841
|
+
function asString(value) {
|
|
3842
|
+
if (value && typeof value === "object")
|
|
3843
|
+
value = value.valueOf();
|
|
3844
|
+
if (typeof value === "string")
|
|
3845
|
+
return value;
|
|
3846
|
+
if (value && typeof value === "object")
|
|
3847
|
+
return String(value);
|
|
3506
3848
|
throw new RangeError("Not a string");
|
|
3507
3849
|
}
|
|
3508
3850
|
// node_modules/messageformat/lib/functions/number.js
|
|
3509
|
-
function readNumericOperand(
|
|
3510
|
-
let
|
|
3511
|
-
if (typeof
|
|
3512
|
-
const valueOf =
|
|
3851
|
+
function readNumericOperand(value) {
|
|
3852
|
+
let options = undefined;
|
|
3853
|
+
if (typeof value === "object") {
|
|
3854
|
+
const valueOf = value?.valueOf;
|
|
3513
3855
|
if (typeof valueOf === "function") {
|
|
3514
|
-
|
|
3515
|
-
|
|
3856
|
+
options = value.options;
|
|
3857
|
+
value = valueOf.call(value);
|
|
3516
3858
|
}
|
|
3517
3859
|
}
|
|
3518
|
-
if (typeof
|
|
3860
|
+
if (typeof value === "string") {
|
|
3519
3861
|
try {
|
|
3520
|
-
|
|
3862
|
+
value = JSON.parse(value);
|
|
3521
3863
|
} catch {}
|
|
3522
3864
|
}
|
|
3523
|
-
if (typeof
|
|
3865
|
+
if (typeof value !== "bigint" && typeof value !== "number") {
|
|
3524
3866
|
throw new MessageFunctionError("bad-operand", "Input is not numeric");
|
|
3525
3867
|
}
|
|
3526
|
-
return { value
|
|
3868
|
+
return { value, options };
|
|
3527
3869
|
}
|
|
3528
|
-
function getMessageNumber(ctx,
|
|
3870
|
+
function getMessageNumber(ctx, value, options, canSelect) {
|
|
3529
3871
|
let { dir, locales } = ctx;
|
|
3530
|
-
if (
|
|
3531
|
-
|
|
3532
|
-
if (canSelect && "select" in
|
|
3872
|
+
if (options.useGrouping === "never")
|
|
3873
|
+
options.useGrouping = false;
|
|
3874
|
+
if (canSelect && "select" in options && !ctx.literalOptionKeys.has("select")) {
|
|
3533
3875
|
ctx.onError("bad-option", "The option select may only be set by a literal value");
|
|
3534
3876
|
canSelect = false;
|
|
3535
3877
|
}
|
|
@@ -3541,65 +3883,65 @@ function getMessageNumber(ctx, value2, options2, canSelect) {
|
|
|
3541
3883
|
type: "number",
|
|
3542
3884
|
get dir() {
|
|
3543
3885
|
if (dir == null) {
|
|
3544
|
-
locale ??= Intl.NumberFormat.supportedLocalesOf(locales,
|
|
3886
|
+
locale ??= Intl.NumberFormat.supportedLocalesOf(locales, options)[0];
|
|
3545
3887
|
dir = getLocaleDir(locale);
|
|
3546
3888
|
}
|
|
3547
3889
|
return dir;
|
|
3548
3890
|
},
|
|
3549
3891
|
get options() {
|
|
3550
|
-
return { ...
|
|
3892
|
+
return { ...options };
|
|
3551
3893
|
},
|
|
3552
3894
|
selectKey: canSelect ? (keys) => {
|
|
3553
|
-
let numVal =
|
|
3554
|
-
if (
|
|
3895
|
+
let numVal = value;
|
|
3896
|
+
if (options.style === "percent") {
|
|
3555
3897
|
if (typeof numVal === "bigint")
|
|
3556
3898
|
numVal *= 100n;
|
|
3557
3899
|
else
|
|
3558
3900
|
numVal *= 100;
|
|
3559
3901
|
}
|
|
3560
|
-
const
|
|
3561
|
-
if (keys.has(
|
|
3562
|
-
return
|
|
3563
|
-
if (
|
|
3902
|
+
const str = String(numVal);
|
|
3903
|
+
if (keys.has(str))
|
|
3904
|
+
return str;
|
|
3905
|
+
if (options.select === "exact")
|
|
3564
3906
|
return null;
|
|
3565
|
-
const pluralOpt =
|
|
3907
|
+
const pluralOpt = options.select ? { ...options, select: undefined, type: options.select } : options;
|
|
3566
3908
|
cat ??= new Intl.PluralRules(locales, pluralOpt).select(Number(numVal));
|
|
3567
3909
|
return keys.has(cat) ? cat : null;
|
|
3568
3910
|
} : undefined,
|
|
3569
3911
|
toParts() {
|
|
3570
|
-
nf ??= new Intl.NumberFormat(locales,
|
|
3571
|
-
const parts = nf.formatToParts(
|
|
3912
|
+
nf ??= new Intl.NumberFormat(locales, options);
|
|
3913
|
+
const parts = nf.formatToParts(value);
|
|
3572
3914
|
locale ??= nf.resolvedOptions().locale;
|
|
3573
3915
|
dir ??= getLocaleDir(locale);
|
|
3574
3916
|
return dir === "ltr" || dir === "rtl" ? [{ type: "number", dir, locale, parts }] : [{ type: "number", locale, parts }];
|
|
3575
3917
|
},
|
|
3576
3918
|
toString() {
|
|
3577
|
-
nf ??= new Intl.NumberFormat(locales,
|
|
3578
|
-
str ??= nf.format(
|
|
3919
|
+
nf ??= new Intl.NumberFormat(locales, options);
|
|
3920
|
+
str ??= nf.format(value);
|
|
3579
3921
|
return str;
|
|
3580
3922
|
},
|
|
3581
|
-
valueOf: () =>
|
|
3923
|
+
valueOf: () => value
|
|
3582
3924
|
};
|
|
3583
3925
|
}
|
|
3584
3926
|
function number(ctx, exprOpt, operand) {
|
|
3585
3927
|
const input = readNumericOperand(operand);
|
|
3586
|
-
const
|
|
3587
|
-
const
|
|
3928
|
+
const value = input.value;
|
|
3929
|
+
const options = Object.assign({}, input.options, {
|
|
3588
3930
|
localeMatcher: ctx.localeMatcher,
|
|
3589
3931
|
style: "decimal"
|
|
3590
3932
|
});
|
|
3591
|
-
for (const [
|
|
3933
|
+
for (const [name, optval] of Object.entries(exprOpt)) {
|
|
3592
3934
|
if (optval === undefined)
|
|
3593
3935
|
continue;
|
|
3594
3936
|
try {
|
|
3595
|
-
switch (
|
|
3937
|
+
switch (name) {
|
|
3596
3938
|
case "minimumIntegerDigits":
|
|
3597
3939
|
case "minimumFractionDigits":
|
|
3598
3940
|
case "maximumFractionDigits":
|
|
3599
3941
|
case "minimumSignificantDigits":
|
|
3600
3942
|
case "maximumSignificantDigits":
|
|
3601
3943
|
case "roundingIncrement":
|
|
3602
|
-
|
|
3944
|
+
options[name] = asPositiveInteger(optval);
|
|
3603
3945
|
break;
|
|
3604
3946
|
case "roundingMode":
|
|
3605
3947
|
case "roundingPriority":
|
|
@@ -3607,100 +3949,100 @@ function number(ctx, exprOpt, operand) {
|
|
|
3607
3949
|
case "signDisplay":
|
|
3608
3950
|
case "trailingZeroDisplay":
|
|
3609
3951
|
case "useGrouping":
|
|
3610
|
-
|
|
3952
|
+
options[name] = asString(optval);
|
|
3611
3953
|
}
|
|
3612
3954
|
} catch {
|
|
3613
|
-
ctx.onError("bad-option", `Value ${optval} is not valid for :number option ${
|
|
3955
|
+
ctx.onError("bad-option", `Value ${optval} is not valid for :number option ${name}`);
|
|
3614
3956
|
}
|
|
3615
3957
|
}
|
|
3616
|
-
return getMessageNumber(ctx,
|
|
3958
|
+
return getMessageNumber(ctx, value, options, true);
|
|
3617
3959
|
}
|
|
3618
3960
|
function integer(ctx, exprOpt, operand) {
|
|
3619
3961
|
const input = readNumericOperand(operand);
|
|
3620
|
-
const
|
|
3621
|
-
const
|
|
3962
|
+
const value = Number.isFinite(input.value) ? Math.round(input.value) : input.value;
|
|
3963
|
+
const options = Object.assign({}, input.options, {
|
|
3622
3964
|
maximumFractionDigits: 0,
|
|
3623
3965
|
minimumFractionDigits: undefined,
|
|
3624
3966
|
minimumSignificantDigits: undefined,
|
|
3625
3967
|
style: "decimal"
|
|
3626
3968
|
});
|
|
3627
|
-
for (const [
|
|
3969
|
+
for (const [name, optval] of Object.entries(exprOpt)) {
|
|
3628
3970
|
if (optval === undefined)
|
|
3629
3971
|
continue;
|
|
3630
3972
|
try {
|
|
3631
|
-
switch (
|
|
3973
|
+
switch (name) {
|
|
3632
3974
|
case "minimumIntegerDigits":
|
|
3633
3975
|
case "maximumSignificantDigits":
|
|
3634
|
-
|
|
3976
|
+
options[name] = asPositiveInteger(optval);
|
|
3635
3977
|
break;
|
|
3636
3978
|
case "select":
|
|
3637
3979
|
case "signDisplay":
|
|
3638
3980
|
case "useGrouping":
|
|
3639
|
-
|
|
3981
|
+
options[name] = asString(optval);
|
|
3640
3982
|
}
|
|
3641
3983
|
} catch {
|
|
3642
|
-
ctx.onError("bad-option", `Value ${optval} is not valid for :integer option ${
|
|
3984
|
+
ctx.onError("bad-option", `Value ${optval} is not valid for :integer option ${name}`);
|
|
3643
3985
|
}
|
|
3644
3986
|
}
|
|
3645
|
-
return getMessageNumber(ctx,
|
|
3987
|
+
return getMessageNumber(ctx, value, options, true);
|
|
3646
3988
|
}
|
|
3647
3989
|
|
|
3648
3990
|
// node_modules/messageformat/lib/functions/currency.js
|
|
3649
3991
|
function currency(ctx, exprOpt, operand) {
|
|
3650
3992
|
const input = readNumericOperand(operand);
|
|
3651
|
-
const
|
|
3993
|
+
const options = Object.assign({}, input.options, {
|
|
3652
3994
|
localeMatcher: ctx.localeMatcher,
|
|
3653
3995
|
style: "currency"
|
|
3654
3996
|
});
|
|
3655
|
-
for (const [
|
|
3997
|
+
for (const [name, optval] of Object.entries(exprOpt)) {
|
|
3656
3998
|
if (optval === undefined)
|
|
3657
3999
|
continue;
|
|
3658
4000
|
try {
|
|
3659
|
-
switch (
|
|
4001
|
+
switch (name) {
|
|
3660
4002
|
case "currency":
|
|
3661
4003
|
case "currencySign":
|
|
3662
4004
|
case "roundingMode":
|
|
3663
4005
|
case "roundingPriority":
|
|
3664
4006
|
case "trailingZeroDisplay":
|
|
3665
4007
|
case "useGrouping":
|
|
3666
|
-
|
|
4008
|
+
options[name] = asString(optval);
|
|
3667
4009
|
break;
|
|
3668
4010
|
case "minimumIntegerDigits":
|
|
3669
4011
|
case "minimumSignificantDigits":
|
|
3670
4012
|
case "maximumSignificantDigits":
|
|
3671
4013
|
case "roundingIncrement":
|
|
3672
|
-
|
|
4014
|
+
options[name] = asPositiveInteger(optval);
|
|
3673
4015
|
break;
|
|
3674
4016
|
case "currencyDisplay": {
|
|
3675
4017
|
const strval = asString(optval);
|
|
3676
4018
|
if (strval === "never") {
|
|
3677
4019
|
ctx.onError("unsupported-operation", 'Currency display "never" is not yet supported');
|
|
3678
4020
|
} else {
|
|
3679
|
-
|
|
4021
|
+
options[name] = strval;
|
|
3680
4022
|
}
|
|
3681
4023
|
break;
|
|
3682
4024
|
}
|
|
3683
4025
|
case "fractionDigits": {
|
|
3684
4026
|
const strval = asString(optval);
|
|
3685
4027
|
if (strval === "auto") {
|
|
3686
|
-
|
|
3687
|
-
|
|
4028
|
+
options.minimumFractionDigits = undefined;
|
|
4029
|
+
options.maximumFractionDigits = undefined;
|
|
3688
4030
|
} else {
|
|
3689
4031
|
const numval = asPositiveInteger(strval);
|
|
3690
|
-
|
|
3691
|
-
|
|
4032
|
+
options.minimumFractionDigits = numval;
|
|
4033
|
+
options.maximumFractionDigits = numval;
|
|
3692
4034
|
}
|
|
3693
4035
|
break;
|
|
3694
4036
|
}
|
|
3695
4037
|
}
|
|
3696
4038
|
} catch {
|
|
3697
|
-
ctx.onError("bad-option", `Value ${optval} is not valid for :currency option ${
|
|
4039
|
+
ctx.onError("bad-option", `Value ${optval} is not valid for :currency option ${name}`);
|
|
3698
4040
|
}
|
|
3699
4041
|
}
|
|
3700
|
-
if (!
|
|
4042
|
+
if (!options.currency) {
|
|
3701
4043
|
throw new MessageFunctionError("bad-operand", "A currency code is required for :currency");
|
|
3702
4044
|
}
|
|
3703
|
-
return getMessageNumber(ctx, input.value,
|
|
4045
|
+
return getMessageNumber(ctx, input.value, options, false);
|
|
3704
4046
|
}
|
|
3705
4047
|
|
|
3706
4048
|
// node_modules/messageformat/lib/functions/datetime.js
|
|
@@ -3715,43 +4057,43 @@ var dateFieldsValues = new Set([
|
|
|
3715
4057
|
var dateLengthValues = new Set(["long", "medium", "short"]);
|
|
3716
4058
|
var timePrecisionValues = new Set(["hour", "minute", "second"]);
|
|
3717
4059
|
var timeZoneStyleValues = new Set(["long", "short"]);
|
|
3718
|
-
var datetime = (ctx,
|
|
3719
|
-
var date = (ctx,
|
|
3720
|
-
var time = (ctx,
|
|
4060
|
+
var datetime = (ctx, options, operand) => dateTimeImplementation("datetime", ctx, options, operand);
|
|
4061
|
+
var date = (ctx, options, operand) => dateTimeImplementation("date", ctx, options, operand);
|
|
4062
|
+
var time = (ctx, options, operand) => dateTimeImplementation("time", ctx, options, operand);
|
|
3721
4063
|
function dateTimeImplementation(functionName, ctx, exprOpt, operand) {
|
|
3722
|
-
const
|
|
4064
|
+
const options = {
|
|
3723
4065
|
localeMatcher: ctx.localeMatcher
|
|
3724
4066
|
};
|
|
3725
|
-
let
|
|
3726
|
-
if (typeof
|
|
3727
|
-
const opt =
|
|
4067
|
+
let value = operand;
|
|
4068
|
+
if (typeof value === "object" && value !== null) {
|
|
4069
|
+
const opt = value.options;
|
|
3728
4070
|
if (opt) {
|
|
3729
|
-
|
|
4071
|
+
options.calendar = opt.calendar;
|
|
3730
4072
|
if (functionName !== "date")
|
|
3731
|
-
|
|
3732
|
-
|
|
4073
|
+
options.hour12 = opt.hour12;
|
|
4074
|
+
options.timeZone = opt.timeZone;
|
|
3733
4075
|
}
|
|
3734
|
-
if (typeof
|
|
3735
|
-
|
|
4076
|
+
if (typeof value.valueOf === "function")
|
|
4077
|
+
value = value.valueOf();
|
|
3736
4078
|
}
|
|
3737
|
-
switch (typeof
|
|
4079
|
+
switch (typeof value) {
|
|
3738
4080
|
case "number":
|
|
3739
4081
|
case "string":
|
|
3740
|
-
|
|
4082
|
+
value = new Date(value);
|
|
3741
4083
|
}
|
|
3742
|
-
if (!(
|
|
4084
|
+
if (!(value instanceof Date) || isNaN(value.getTime())) {
|
|
3743
4085
|
throw new MessageFunctionError("bad-operand", "Input is not a valid date");
|
|
3744
4086
|
}
|
|
3745
4087
|
if (exprOpt.calendar !== undefined) {
|
|
3746
4088
|
try {
|
|
3747
|
-
|
|
4089
|
+
options.calendar = asString(exprOpt.calendar);
|
|
3748
4090
|
} catch {
|
|
3749
4091
|
ctx.onError("bad-option", `Invalid :${functionName} calendar option value`);
|
|
3750
4092
|
}
|
|
3751
4093
|
}
|
|
3752
4094
|
if (exprOpt.hour12 !== undefined && functionName !== "date") {
|
|
3753
4095
|
try {
|
|
3754
|
-
|
|
4096
|
+
options.hour12 = asBoolean(exprOpt.hour12);
|
|
3755
4097
|
} catch {
|
|
3756
4098
|
ctx.onError("bad-option", `Invalid :${functionName} hour12 option value`);
|
|
3757
4099
|
}
|
|
@@ -3764,14 +4106,14 @@ function dateTimeImplementation(functionName, ctx, exprOpt, operand) {
|
|
|
3764
4106
|
ctx.onError("bad-option", `Invalid :${functionName} timeZone option value`);
|
|
3765
4107
|
}
|
|
3766
4108
|
if (tz === "input") {
|
|
3767
|
-
if (
|
|
4109
|
+
if (options.timeZone === undefined) {
|
|
3768
4110
|
ctx.onError("bad-operand", `Missing input timeZone value for :${functionName}`);
|
|
3769
4111
|
}
|
|
3770
4112
|
} else if (tz !== undefined) {
|
|
3771
|
-
if (
|
|
4113
|
+
if (options.timeZone !== undefined && tz !== options.timeZone) {
|
|
3772
4114
|
throw new MessageFunctionError("bad-option", "Time zone conversion is not supported");
|
|
3773
4115
|
}
|
|
3774
|
-
|
|
4116
|
+
options.timeZone = tz;
|
|
3775
4117
|
}
|
|
3776
4118
|
}
|
|
3777
4119
|
if (functionName !== "time") {
|
|
@@ -3781,34 +4123,34 @@ function dateTimeImplementation(functionName, ctx, exprOpt, operand) {
|
|
|
3781
4123
|
const dateLength = readStringOption(ctx, exprOpt, dlName, dateLengthValues);
|
|
3782
4124
|
const dateFields = new Set(dateFieldsValue.split("-"));
|
|
3783
4125
|
if (dateFields.has("year"))
|
|
3784
|
-
|
|
4126
|
+
options.year = "numeric";
|
|
3785
4127
|
if (dateFields.has("month")) {
|
|
3786
|
-
|
|
4128
|
+
options.month = dateLength === "long" ? "long" : dateLength === "short" ? "numeric" : "short";
|
|
3787
4129
|
}
|
|
3788
4130
|
if (dateFields.has("day"))
|
|
3789
|
-
|
|
4131
|
+
options.day = "numeric";
|
|
3790
4132
|
if (dateFields.has("weekday")) {
|
|
3791
|
-
|
|
4133
|
+
options.weekday = dateLength === "long" ? "long" : "short";
|
|
3792
4134
|
}
|
|
3793
4135
|
}
|
|
3794
4136
|
if (functionName !== "date") {
|
|
3795
4137
|
const tpName = functionName === "time" ? "precision" : "timePrecision";
|
|
3796
4138
|
switch (readStringOption(ctx, exprOpt, tpName, timePrecisionValues)) {
|
|
3797
4139
|
case "hour":
|
|
3798
|
-
|
|
4140
|
+
options.hour = "numeric";
|
|
3799
4141
|
break;
|
|
3800
4142
|
case "second":
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
4143
|
+
options.hour = "numeric";
|
|
4144
|
+
options.minute = "numeric";
|
|
4145
|
+
options.second = "numeric";
|
|
3804
4146
|
break;
|
|
3805
4147
|
default:
|
|
3806
|
-
|
|
3807
|
-
|
|
4148
|
+
options.hour = "numeric";
|
|
4149
|
+
options.minute = "numeric";
|
|
3808
4150
|
}
|
|
3809
|
-
|
|
4151
|
+
options.timeZoneName = readStringOption(ctx, exprOpt, "timeZoneStyle", timeZoneStyleValues);
|
|
3810
4152
|
}
|
|
3811
|
-
const dtf = new Intl.DateTimeFormat(ctx.locales,
|
|
4153
|
+
const dtf = new Intl.DateTimeFormat(ctx.locales, options);
|
|
3812
4154
|
let dir = ctx.dir;
|
|
3813
4155
|
let locale;
|
|
3814
4156
|
let str;
|
|
@@ -3822,31 +4164,31 @@ function dateTimeImplementation(functionName, ctx, exprOpt, operand) {
|
|
|
3822
4164
|
return dir;
|
|
3823
4165
|
},
|
|
3824
4166
|
get options() {
|
|
3825
|
-
return { ...
|
|
4167
|
+
return { ...options };
|
|
3826
4168
|
},
|
|
3827
4169
|
toParts() {
|
|
3828
|
-
const parts = dtf.formatToParts(
|
|
4170
|
+
const parts = dtf.formatToParts(value);
|
|
3829
4171
|
locale ??= dtf.resolvedOptions().locale;
|
|
3830
4172
|
dir ??= getLocaleDir(locale);
|
|
3831
4173
|
return dir === "ltr" || dir === "rtl" ? [{ type: "datetime", dir, locale, parts }] : [{ type: "datetime", locale, parts }];
|
|
3832
4174
|
},
|
|
3833
4175
|
toString() {
|
|
3834
|
-
str ??= dtf.format(
|
|
4176
|
+
str ??= dtf.format(value);
|
|
3835
4177
|
return str;
|
|
3836
4178
|
},
|
|
3837
|
-
valueOf: () =>
|
|
4179
|
+
valueOf: () => value
|
|
3838
4180
|
};
|
|
3839
4181
|
}
|
|
3840
|
-
function readStringOption(ctx,
|
|
3841
|
-
const
|
|
3842
|
-
if (
|
|
4182
|
+
function readStringOption(ctx, options, name, allowed) {
|
|
4183
|
+
const value = options[name];
|
|
4184
|
+
if (value !== undefined) {
|
|
3843
4185
|
try {
|
|
3844
|
-
const str = asString(
|
|
4186
|
+
const str = asString(value);
|
|
3845
4187
|
if (allowed && !allowed.has(str))
|
|
3846
4188
|
throw Error();
|
|
3847
4189
|
return str;
|
|
3848
4190
|
} catch {
|
|
3849
|
-
ctx.onError("bad-option", `Invalid value for ${
|
|
4191
|
+
ctx.onError("bad-option", `Invalid value for ${name} option`);
|
|
3850
4192
|
}
|
|
3851
4193
|
}
|
|
3852
4194
|
return;
|
|
@@ -3854,7 +4196,7 @@ function readStringOption(ctx, options2, name2, allowed) {
|
|
|
3854
4196
|
|
|
3855
4197
|
// node_modules/messageformat/lib/functions/offset.js
|
|
3856
4198
|
function offset(ctx, exprOpt, operand) {
|
|
3857
|
-
let { value
|
|
4199
|
+
let { value, options } = readNumericOperand(operand);
|
|
3858
4200
|
let add;
|
|
3859
4201
|
try {
|
|
3860
4202
|
add = "add" in exprOpt ? asPositiveInteger(exprOpt.add) : -1;
|
|
@@ -3872,44 +4214,44 @@ function offset(ctx, exprOpt, operand) {
|
|
|
3872
4214
|
throw new MessageFunctionError("bad-option", msg);
|
|
3873
4215
|
}
|
|
3874
4216
|
const delta = add < 0 ? -sub : add;
|
|
3875
|
-
if (typeof
|
|
3876
|
-
|
|
4217
|
+
if (typeof value === "number")
|
|
4218
|
+
value += delta;
|
|
3877
4219
|
else
|
|
3878
|
-
|
|
3879
|
-
return number(ctx, {}, { valueOf: () =>
|
|
4220
|
+
value += BigInt(delta);
|
|
4221
|
+
return number(ctx, {}, { valueOf: () => value, options });
|
|
3880
4222
|
}
|
|
3881
4223
|
|
|
3882
4224
|
// node_modules/messageformat/lib/functions/percent.js
|
|
3883
4225
|
function percent(ctx, exprOpt, operand) {
|
|
3884
4226
|
const input = readNumericOperand(operand);
|
|
3885
|
-
const
|
|
4227
|
+
const options = Object.assign({}, input.options, {
|
|
3886
4228
|
localeMatcher: ctx.localeMatcher,
|
|
3887
4229
|
style: "percent"
|
|
3888
4230
|
});
|
|
3889
|
-
for (const [
|
|
4231
|
+
for (const [name, optval] of Object.entries(exprOpt)) {
|
|
3890
4232
|
if (optval === undefined)
|
|
3891
4233
|
continue;
|
|
3892
4234
|
try {
|
|
3893
|
-
switch (
|
|
4235
|
+
switch (name) {
|
|
3894
4236
|
case "roundingMode":
|
|
3895
4237
|
case "roundingPriority":
|
|
3896
4238
|
case "signDisplay":
|
|
3897
4239
|
case "trailingZeroDisplay":
|
|
3898
4240
|
case "useGrouping":
|
|
3899
|
-
|
|
4241
|
+
options[name] = asString(optval);
|
|
3900
4242
|
break;
|
|
3901
4243
|
case "minimumFractionDigits":
|
|
3902
4244
|
case "maximumFractionDigits":
|
|
3903
4245
|
case "minimumSignificantDigits":
|
|
3904
4246
|
case "maximumSignificantDigits":
|
|
3905
|
-
|
|
4247
|
+
options[name] = asPositiveInteger(optval);
|
|
3906
4248
|
break;
|
|
3907
4249
|
}
|
|
3908
4250
|
} catch {
|
|
3909
|
-
ctx.onError("bad-option", `Value ${optval} is not valid for :percent option ${
|
|
4251
|
+
ctx.onError("bad-option", `Value ${optval} is not valid for :percent option ${name}`);
|
|
3910
4252
|
}
|
|
3911
4253
|
}
|
|
3912
|
-
return getMessageNumber(ctx, input.value,
|
|
4254
|
+
return getMessageNumber(ctx, input.value, options, true);
|
|
3913
4255
|
}
|
|
3914
4256
|
|
|
3915
4257
|
// node_modules/messageformat/lib/functions/string.js
|
|
@@ -3933,15 +4275,15 @@ function string(ctx, _options, operand) {
|
|
|
3933
4275
|
// node_modules/messageformat/lib/functions/unit.js
|
|
3934
4276
|
function unit(ctx, exprOpt, operand) {
|
|
3935
4277
|
const input = readNumericOperand(operand);
|
|
3936
|
-
const
|
|
4278
|
+
const options = Object.assign({}, input.options, {
|
|
3937
4279
|
localeMatcher: ctx.localeMatcher,
|
|
3938
4280
|
style: "unit"
|
|
3939
4281
|
});
|
|
3940
|
-
for (const [
|
|
4282
|
+
for (const [name, optval] of Object.entries(exprOpt)) {
|
|
3941
4283
|
if (optval === undefined)
|
|
3942
4284
|
continue;
|
|
3943
4285
|
try {
|
|
3944
|
-
switch (
|
|
4286
|
+
switch (name) {
|
|
3945
4287
|
case "signDisplay":
|
|
3946
4288
|
case "roundingMode":
|
|
3947
4289
|
case "roundingPriority":
|
|
@@ -3949,7 +4291,7 @@ function unit(ctx, exprOpt, operand) {
|
|
|
3949
4291
|
case "unit":
|
|
3950
4292
|
case "unitDisplay":
|
|
3951
4293
|
case "useGrouping":
|
|
3952
|
-
|
|
4294
|
+
options[name] = asString(optval);
|
|
3953
4295
|
break;
|
|
3954
4296
|
case "minimumIntegerDigits":
|
|
3955
4297
|
case "minimumFractionDigits":
|
|
@@ -3957,21 +4299,21 @@ function unit(ctx, exprOpt, operand) {
|
|
|
3957
4299
|
case "minimumSignificantDigits":
|
|
3958
4300
|
case "maximumSignificantDigits":
|
|
3959
4301
|
case "roundingIncrement":
|
|
3960
|
-
|
|
4302
|
+
options[name] = asPositiveInteger(optval);
|
|
3961
4303
|
break;
|
|
3962
4304
|
}
|
|
3963
4305
|
} catch (error) {
|
|
3964
4306
|
if (error instanceof MessageError) {
|
|
3965
4307
|
ctx.onError(error);
|
|
3966
4308
|
} else {
|
|
3967
|
-
ctx.onError("bad-option", `Value ${optval} is not valid for :currency option ${
|
|
4309
|
+
ctx.onError("bad-option", `Value ${optval} is not valid for :currency option ${name}`);
|
|
3968
4310
|
}
|
|
3969
4311
|
}
|
|
3970
4312
|
}
|
|
3971
|
-
if (!
|
|
4313
|
+
if (!options.unit) {
|
|
3972
4314
|
throw new MessageFunctionError("bad-operand", "A unit identifier is required for :unit");
|
|
3973
4315
|
}
|
|
3974
|
-
return getMessageNumber(ctx, input.value,
|
|
4316
|
+
return getMessageNumber(ctx, input.value, options, false);
|
|
3975
4317
|
}
|
|
3976
4318
|
|
|
3977
4319
|
// node_modules/messageformat/lib/functions/index.js
|
|
@@ -3996,17 +4338,17 @@ DraftFunctions = Object.freeze(Object.assign(Object.create(null), DraftFunctions
|
|
|
3996
4338
|
var BIDI_ISOLATE = Symbol("bidi-isolate");
|
|
3997
4339
|
|
|
3998
4340
|
// node_modules/messageformat/lib/functions/fallback.js
|
|
3999
|
-
var fallback = (
|
|
4341
|
+
var fallback = (source = "�") => ({
|
|
4000
4342
|
type: "fallback",
|
|
4001
|
-
source
|
|
4002
|
-
toParts: () => [{ type: "fallback", source
|
|
4003
|
-
toString: () => `{${
|
|
4343
|
+
source,
|
|
4344
|
+
toParts: () => [{ type: "fallback", source }],
|
|
4345
|
+
toString: () => `{${source}}`
|
|
4004
4346
|
});
|
|
4005
4347
|
|
|
4006
4348
|
// node_modules/messageformat/lib/functions/unknown.js
|
|
4007
|
-
var unknown = (
|
|
4349
|
+
var unknown = (source, input) => ({
|
|
4008
4350
|
type: "unknown",
|
|
4009
|
-
source
|
|
4351
|
+
source,
|
|
4010
4352
|
dir: "auto",
|
|
4011
4353
|
toParts: () => [{ type: "unknown", value: input }],
|
|
4012
4354
|
toString: () => String(input),
|
|
@@ -4020,11 +4362,11 @@ class MessageFunctionContext {
|
|
|
4020
4362
|
#source;
|
|
4021
4363
|
dir;
|
|
4022
4364
|
id;
|
|
4023
|
-
constructor(ctx,
|
|
4365
|
+
constructor(ctx, source, options) {
|
|
4024
4366
|
this.#ctx = ctx;
|
|
4025
|
-
this.#source =
|
|
4367
|
+
this.#source = source;
|
|
4026
4368
|
this.dir = undefined;
|
|
4027
|
-
const dirOpt =
|
|
4369
|
+
const dirOpt = options && Object.hasOwn(options, "u:dir") ? options["u:dir"] : undefined;
|
|
4028
4370
|
if (dirOpt) {
|
|
4029
4371
|
const dir = String(resolveValue(ctx, dirOpt));
|
|
4030
4372
|
if (dir === "ltr" || dir === "rtl" || dir === "auto") {
|
|
@@ -4035,12 +4377,12 @@ class MessageFunctionContext {
|
|
|
4035
4377
|
ctx.onError(error);
|
|
4036
4378
|
}
|
|
4037
4379
|
}
|
|
4038
|
-
const idOpt =
|
|
4380
|
+
const idOpt = options && Object.hasOwn(options, "u:id") ? options["u:id"] : undefined;
|
|
4039
4381
|
this.id = idOpt ? String(resolveValue(ctx, idOpt)) : undefined;
|
|
4040
|
-
if (
|
|
4382
|
+
if (options) {
|
|
4041
4383
|
this.#litKeys = new Set;
|
|
4042
|
-
for (const [key,
|
|
4043
|
-
if (
|
|
4384
|
+
for (const [key, value] of Object.entries(options)) {
|
|
4385
|
+
if (value.type === "literal")
|
|
4044
4386
|
this.#litKeys.add(key);
|
|
4045
4387
|
}
|
|
4046
4388
|
}
|
|
@@ -4070,22 +4412,22 @@ class MessageFunctionContext {
|
|
|
4070
4412
|
}
|
|
4071
4413
|
|
|
4072
4414
|
// node_modules/messageformat/lib/resolve/resolve-function-ref.js
|
|
4073
|
-
function resolveFunctionRef(ctx, operand, { name
|
|
4074
|
-
const fnSource = `:${
|
|
4075
|
-
const
|
|
4415
|
+
function resolveFunctionRef(ctx, operand, { name, options }) {
|
|
4416
|
+
const fnSource = `:${name}`;
|
|
4417
|
+
const source = getValueSource(operand) ?? fnSource;
|
|
4076
4418
|
try {
|
|
4077
4419
|
const fnInput = operand ? [resolveValue(ctx, operand)] : [];
|
|
4078
|
-
const rf = ctx.functions[
|
|
4420
|
+
const rf = ctx.functions[name];
|
|
4079
4421
|
if (!rf) {
|
|
4080
|
-
throw new MessageResolutionError("unknown-function", `Unknown function ${fnSource}`,
|
|
4422
|
+
throw new MessageResolutionError("unknown-function", `Unknown function ${fnSource}`, source);
|
|
4081
4423
|
}
|
|
4082
|
-
const msgCtx = new MessageFunctionContext(ctx,
|
|
4083
|
-
const opt = resolveOptions(ctx,
|
|
4424
|
+
const msgCtx = new MessageFunctionContext(ctx, source, options);
|
|
4425
|
+
const opt = resolveOptions(ctx, options);
|
|
4084
4426
|
const res = rf(msgCtx, opt, ...fnInput);
|
|
4085
4427
|
if (res === null || typeof res !== "object" || typeof res.type !== "string") {
|
|
4086
|
-
throw new MessageResolutionError("bad-function-result", `Function ${fnSource} did not return a MessageValue`,
|
|
4428
|
+
throw new MessageResolutionError("bad-function-result", `Function ${fnSource} did not return a MessageValue`, source);
|
|
4087
4429
|
}
|
|
4088
|
-
const override = { source
|
|
4430
|
+
const override = { source };
|
|
4089
4431
|
if (msgCtx.dir) {
|
|
4090
4432
|
override.dir = msgCtx.dir;
|
|
4091
4433
|
override[BIDI_ISOLATE] = true;
|
|
@@ -4100,16 +4442,16 @@ function resolveFunctionRef(ctx, operand, { name: name2, options: options2 }) {
|
|
|
4100
4442
|
}
|
|
4101
4443
|
return { ...res, ...override };
|
|
4102
4444
|
} catch (error) {
|
|
4103
|
-
ctx.onError(error instanceof MessageError ? error : new MessageResolutionError("bad-function-result", String(error),
|
|
4104
|
-
return fallback(
|
|
4445
|
+
ctx.onError(error instanceof MessageError ? error : new MessageResolutionError("bad-function-result", String(error), source, error));
|
|
4446
|
+
return fallback(source);
|
|
4105
4447
|
}
|
|
4106
4448
|
}
|
|
4107
|
-
function resolveOptions(ctx,
|
|
4449
|
+
function resolveOptions(ctx, options) {
|
|
4108
4450
|
const opt = Object.create(null);
|
|
4109
|
-
if (
|
|
4110
|
-
for (const [
|
|
4111
|
-
if (!
|
|
4112
|
-
opt[
|
|
4451
|
+
if (options) {
|
|
4452
|
+
for (const [name, value] of Object.entries(options)) {
|
|
4453
|
+
if (!name.startsWith("u:"))
|
|
4454
|
+
opt[name] = resolveValue(ctx, value);
|
|
4113
4455
|
}
|
|
4114
4456
|
}
|
|
4115
4457
|
return opt;
|
|
@@ -4122,10 +4464,10 @@ function resolveExpression(ctx, { arg, functionRef }) {
|
|
|
4122
4464
|
}
|
|
4123
4465
|
switch (arg?.type) {
|
|
4124
4466
|
case "literal": {
|
|
4125
|
-
const
|
|
4126
|
-
const msgCtx = new MessageFunctionContext(ctx,
|
|
4467
|
+
const source = `|${arg.value}|`;
|
|
4468
|
+
const msgCtx = new MessageFunctionContext(ctx, source);
|
|
4127
4469
|
const msgStr = string(msgCtx, {}, arg.value);
|
|
4128
|
-
msgStr.source =
|
|
4470
|
+
msgStr.source = source;
|
|
4129
4471
|
return msgStr;
|
|
4130
4472
|
}
|
|
4131
4473
|
case "variable":
|
|
@@ -4139,17 +4481,17 @@ function resolveExpression(ctx, { arg, functionRef }) {
|
|
|
4139
4481
|
class UnresolvedExpression {
|
|
4140
4482
|
expression;
|
|
4141
4483
|
scope;
|
|
4142
|
-
constructor(
|
|
4143
|
-
this.expression =
|
|
4484
|
+
constructor(expression, scope) {
|
|
4485
|
+
this.expression = expression;
|
|
4144
4486
|
this.scope = scope;
|
|
4145
4487
|
}
|
|
4146
4488
|
}
|
|
4147
4489
|
var isScope = (scope) => scope !== null && (typeof scope === "object" || typeof scope === "function");
|
|
4148
|
-
function getValue(scope,
|
|
4490
|
+
function getValue(scope, name) {
|
|
4149
4491
|
if (isScope(scope)) {
|
|
4150
|
-
if (
|
|
4151
|
-
return scope[
|
|
4152
|
-
const parts =
|
|
4492
|
+
if (name in scope)
|
|
4493
|
+
return scope[name];
|
|
4494
|
+
const parts = name.split(".");
|
|
4153
4495
|
for (let i = parts.length - 1;i > 0; --i) {
|
|
4154
4496
|
const head = parts.slice(0, i).join(".");
|
|
4155
4497
|
if (head in scope) {
|
|
@@ -4157,44 +4499,44 @@ function getValue(scope, name2) {
|
|
|
4157
4499
|
return getValue(scope[head], tail);
|
|
4158
4500
|
}
|
|
4159
4501
|
}
|
|
4160
|
-
for (const [key,
|
|
4161
|
-
if (key.normalize() ===
|
|
4162
|
-
return
|
|
4502
|
+
for (const [key, value] of Object.entries(scope)) {
|
|
4503
|
+
if (key.normalize() === name)
|
|
4504
|
+
return value;
|
|
4163
4505
|
}
|
|
4164
4506
|
}
|
|
4165
4507
|
return;
|
|
4166
4508
|
}
|
|
4167
|
-
function lookupVariableRef(ctx, { name
|
|
4168
|
-
const
|
|
4169
|
-
if (
|
|
4170
|
-
const
|
|
4171
|
-
const msg = `Variable not available: ${
|
|
4172
|
-
ctx.onError(new MessageResolutionError("unresolved-variable", msg,
|
|
4173
|
-
} else if (
|
|
4174
|
-
const local = resolveExpression(
|
|
4175
|
-
ctx.scope[
|
|
4509
|
+
function lookupVariableRef(ctx, { name }) {
|
|
4510
|
+
const value = getValue(ctx.scope, name);
|
|
4511
|
+
if (value === undefined) {
|
|
4512
|
+
const source = "$" + name;
|
|
4513
|
+
const msg = `Variable not available: ${source}`;
|
|
4514
|
+
ctx.onError(new MessageResolutionError("unresolved-variable", msg, source));
|
|
4515
|
+
} else if (value instanceof UnresolvedExpression) {
|
|
4516
|
+
const local = resolveExpression(value.scope ? { ...ctx, scope: value.scope } : ctx, value.expression);
|
|
4517
|
+
ctx.scope[name] = local;
|
|
4176
4518
|
ctx.localVars.add(local);
|
|
4177
4519
|
return local;
|
|
4178
4520
|
}
|
|
4179
|
-
return
|
|
4521
|
+
return value;
|
|
4180
4522
|
}
|
|
4181
4523
|
function resolveVariableRef(ctx, ref) {
|
|
4182
|
-
const
|
|
4183
|
-
const
|
|
4184
|
-
if (
|
|
4185
|
-
return fallback(
|
|
4186
|
-
let type = typeof
|
|
4524
|
+
const source = "$" + ref.name;
|
|
4525
|
+
const value = lookupVariableRef(ctx, ref);
|
|
4526
|
+
if (value === undefined)
|
|
4527
|
+
return fallback(source);
|
|
4528
|
+
let type = typeof value;
|
|
4187
4529
|
if (type === "object") {
|
|
4188
|
-
const
|
|
4189
|
-
if (
|
|
4190
|
-
return fallback(
|
|
4191
|
-
if (ctx.localVars.has(
|
|
4192
|
-
|
|
4193
|
-
return
|
|
4194
|
-
}
|
|
4195
|
-
if (
|
|
4530
|
+
const mv = value;
|
|
4531
|
+
if (mv.type === "fallback")
|
|
4532
|
+
return fallback(source);
|
|
4533
|
+
if (ctx.localVars.has(mv)) {
|
|
4534
|
+
mv.source = source;
|
|
4535
|
+
return mv;
|
|
4536
|
+
}
|
|
4537
|
+
if (value instanceof Number)
|
|
4196
4538
|
type = "number";
|
|
4197
|
-
else if (
|
|
4539
|
+
else if (value instanceof String)
|
|
4198
4540
|
type = "string";
|
|
4199
4541
|
}
|
|
4200
4542
|
let msgFn;
|
|
@@ -4207,56 +4549,56 @@ function resolveVariableRef(ctx, ref) {
|
|
|
4207
4549
|
msgFn = ctx.functions.string;
|
|
4208
4550
|
break;
|
|
4209
4551
|
default:
|
|
4210
|
-
return unknown(
|
|
4552
|
+
return unknown(source, value);
|
|
4211
4553
|
}
|
|
4212
|
-
const msgCtx = new MessageFunctionContext(ctx,
|
|
4213
|
-
const mv = msgFn(msgCtx, {},
|
|
4214
|
-
mv.source =
|
|
4554
|
+
const msgCtx = new MessageFunctionContext(ctx, source);
|
|
4555
|
+
const mv = msgFn(msgCtx, {}, value);
|
|
4556
|
+
mv.source = source;
|
|
4215
4557
|
return mv;
|
|
4216
4558
|
}
|
|
4217
4559
|
|
|
4218
4560
|
// node_modules/messageformat/lib/resolve/resolve-value.js
|
|
4219
|
-
function resolveValue(ctx,
|
|
4220
|
-
switch (
|
|
4561
|
+
function resolveValue(ctx, value) {
|
|
4562
|
+
switch (value.type) {
|
|
4221
4563
|
case "literal":
|
|
4222
|
-
return
|
|
4564
|
+
return value.value;
|
|
4223
4565
|
case "variable":
|
|
4224
|
-
return lookupVariableRef(ctx,
|
|
4566
|
+
return lookupVariableRef(ctx, value);
|
|
4225
4567
|
default:
|
|
4226
|
-
throw new Error(`Unsupported value: ${
|
|
4568
|
+
throw new Error(`Unsupported value: ${value.type}`);
|
|
4227
4569
|
}
|
|
4228
4570
|
}
|
|
4229
|
-
function getValueSource(
|
|
4230
|
-
switch (
|
|
4571
|
+
function getValueSource(value) {
|
|
4572
|
+
switch (value?.type) {
|
|
4231
4573
|
case "literal":
|
|
4232
|
-
return "|" +
|
|
4574
|
+
return "|" + value.value.replaceAll("\\", "\\\\").replaceAll("|", "\\|") + "|";
|
|
4233
4575
|
case "variable":
|
|
4234
|
-
return "$" +
|
|
4576
|
+
return "$" + value.name;
|
|
4235
4577
|
default:
|
|
4236
4578
|
return;
|
|
4237
4579
|
}
|
|
4238
4580
|
}
|
|
4239
4581
|
|
|
4240
4582
|
// node_modules/messageformat/lib/resolve/format-markup.js
|
|
4241
|
-
function formatMarkup(ctx, { kind, name
|
|
4242
|
-
const part = { type: "markup", kind, name
|
|
4243
|
-
const entries =
|
|
4583
|
+
function formatMarkup(ctx, { kind, name, options }) {
|
|
4584
|
+
const part = { type: "markup", kind, name };
|
|
4585
|
+
const entries = options ? Object.entries(options) : null;
|
|
4244
4586
|
if (entries?.length) {
|
|
4245
4587
|
part.options = {};
|
|
4246
|
-
for (const [
|
|
4247
|
-
if (
|
|
4248
|
-
const error = new MessageFunctionError("bad-option", `The option ${
|
|
4249
|
-
error.source = getValueSource(
|
|
4588
|
+
for (const [name, value] of entries) {
|
|
4589
|
+
if (name === "u:dir") {
|
|
4590
|
+
const error = new MessageFunctionError("bad-option", `The option ${name} is not valid for markup`);
|
|
4591
|
+
error.source = getValueSource(value);
|
|
4250
4592
|
ctx.onError(error);
|
|
4251
4593
|
} else {
|
|
4252
|
-
let rv = resolveValue(ctx,
|
|
4594
|
+
let rv = resolveValue(ctx, value);
|
|
4253
4595
|
if (typeof rv === "object" && typeof rv?.valueOf === "function") {
|
|
4254
4596
|
rv = rv.valueOf();
|
|
4255
4597
|
}
|
|
4256
|
-
if (
|
|
4598
|
+
if (name === "u:id")
|
|
4257
4599
|
part.id = String(rv);
|
|
4258
4600
|
else
|
|
4259
|
-
part.options[
|
|
4601
|
+
part.options[name] = rv;
|
|
4260
4602
|
}
|
|
4261
4603
|
}
|
|
4262
4604
|
}
|
|
@@ -4343,14 +4685,14 @@ class MessageFormat {
|
|
|
4343
4685
|
#locales;
|
|
4344
4686
|
#message;
|
|
4345
4687
|
#functions;
|
|
4346
|
-
constructor(locales,
|
|
4347
|
-
this.#bidiIsolation =
|
|
4348
|
-
this.#localeMatcher =
|
|
4688
|
+
constructor(locales, source, options) {
|
|
4689
|
+
this.#bidiIsolation = options?.bidiIsolation !== "none";
|
|
4690
|
+
this.#localeMatcher = options?.localeMatcher ?? "best fit";
|
|
4349
4691
|
this.#locales = Array.isArray(locales) ? locales.map((lc) => new Intl.Locale(lc)) : locales ? [new Intl.Locale(locales)] : [];
|
|
4350
|
-
this.#dir =
|
|
4351
|
-
this.#message = typeof
|
|
4692
|
+
this.#dir = options?.dir ?? getLocaleDir(this.#locales[0]);
|
|
4693
|
+
this.#message = typeof source === "string" ? parseMessage(source) : source;
|
|
4352
4694
|
validate(this.#message);
|
|
4353
|
-
this.#functions =
|
|
4695
|
+
this.#functions = options?.functions ? Object.assign(Object.create(null), DefaultFunctions, options.functions) : DefaultFunctions;
|
|
4354
4696
|
}
|
|
4355
4697
|
format(msgParams, onError) {
|
|
4356
4698
|
const ctx = this.#createContext(msgParams, onError);
|
|
@@ -4485,16 +4827,16 @@ function skipLine(src, i) {
|
|
|
4485
4827
|
`, i + 2);
|
|
4486
4828
|
return end < 0 ? src.length : end;
|
|
4487
4829
|
}
|
|
4488
|
-
var quote = (
|
|
4489
|
-
function locOf(src,
|
|
4830
|
+
var quote = (value) => value.replace(/["\\]/g, "\\$&");
|
|
4831
|
+
function locOf(src, offset, length) {
|
|
4490
4832
|
let line = 1, last = -1;
|
|
4491
|
-
for (let i = 0;i <
|
|
4833
|
+
for (let i = 0;i < offset; i++)
|
|
4492
4834
|
if (src[i] === `
|
|
4493
4835
|
`) {
|
|
4494
4836
|
line++;
|
|
4495
4837
|
last = i;
|
|
4496
4838
|
}
|
|
4497
|
-
return { line, col:
|
|
4839
|
+
return { line, col: offset - last, offset, length };
|
|
4498
4840
|
}
|
|
4499
4841
|
function readInterpolation(src, open) {
|
|
4500
4842
|
let i = open + 1, nest = 0, question = false, colon = false;
|
|
@@ -4566,9 +4908,9 @@ function readValue(src, from, keepComments, onUnterminated) {
|
|
|
4566
4908
|
}
|
|
4567
4909
|
parts.push(src.slice(lit, i));
|
|
4568
4910
|
const m = UNIT.exec(src.slice(interp.end + 1));
|
|
4569
|
-
const
|
|
4570
|
-
parts.push({ expr: interp.expr, unit
|
|
4571
|
-
i = interp.end + 1 +
|
|
4911
|
+
const unit = m ? m[1] : "";
|
|
4912
|
+
parts.push({ expr: interp.expr, unit, at: i });
|
|
4913
|
+
i = interp.end + 1 + unit.length;
|
|
4572
4914
|
lit = i;
|
|
4573
4915
|
continue;
|
|
4574
4916
|
}
|
|
@@ -4590,7 +4932,7 @@ var QUOTED = /"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'/g;
|
|
|
4590
4932
|
var STRING_OR_SPACE = new RegExp(`(${QUOTED.source})|\\s+`, "g");
|
|
4591
4933
|
var COMMENTS = /\/\*[\s\S]*?\*\//g;
|
|
4592
4934
|
var LAYER2 = /^@layer\b/i;
|
|
4593
|
-
var squash = (
|
|
4935
|
+
var squash = (text) => text.replace(STRING_OR_SPACE, (_, str) => str || " ");
|
|
4594
4936
|
function nestSelector(prelude) {
|
|
4595
4937
|
const parts = [];
|
|
4596
4938
|
let from = 0, nest = 0;
|
|
@@ -4624,8 +4966,8 @@ function nestSelector(prelude) {
|
|
|
4624
4966
|
return s.includes("&") ? s.replace(LEAD_TOKEN, ":is($&)") : `& ${s}`;
|
|
4625
4967
|
}).join(",");
|
|
4626
4968
|
}
|
|
4627
|
-
function scan(src,
|
|
4628
|
-
const exprs = [], binds = [], props = [], prefix = `--${
|
|
4969
|
+
function scan(src, options, native, diagnostics) {
|
|
4970
|
+
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) }));
|
|
4629
4971
|
const slot = (expr) => {
|
|
4630
4972
|
let e = exprs.indexOf(expr);
|
|
4631
4973
|
if (e < 0)
|
|
@@ -4639,20 +4981,20 @@ function scan(src, options2, native, diagnostics) {
|
|
|
4639
4981
|
report("LIPS-S004", `Invalid expression: ${errors[0].message}`, s.at, length);
|
|
4640
4982
|
return;
|
|
4641
4983
|
}
|
|
4642
|
-
for (const
|
|
4643
|
-
if (!STYLE_SCOPE.has(
|
|
4644
|
-
report("LIPS-S003", `'${
|
|
4984
|
+
for (const name of freeRoots(ast))
|
|
4985
|
+
if (!STYLE_SCOPE.has(name) && !(name in globalThis))
|
|
4986
|
+
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.");
|
|
4645
4987
|
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.`);
|
|
4646
4988
|
};
|
|
4647
4989
|
let out = "", cur = "", tail = "", gap = false;
|
|
4648
|
-
const emit = (
|
|
4649
|
-
if (!
|
|
4990
|
+
const emit = (text) => {
|
|
4991
|
+
if (!text)
|
|
4650
4992
|
return;
|
|
4651
|
-
if (gap && tail && !BREAK.test(tail) && !BREAK.test(
|
|
4993
|
+
if (gap && tail && !BREAK.test(tail) && !BREAK.test(text[0]))
|
|
4652
4994
|
cur += " ";
|
|
4653
4995
|
gap = false;
|
|
4654
|
-
cur +=
|
|
4655
|
-
tail =
|
|
4996
|
+
cur += text;
|
|
4997
|
+
tail = text[text.length - 1];
|
|
4656
4998
|
};
|
|
4657
4999
|
const flush = (end) => {
|
|
4658
5000
|
out += cur + end;
|
|
@@ -4661,14 +5003,14 @@ function scan(src, options2, native, diagnostics) {
|
|
|
4661
5003
|
gap = false;
|
|
4662
5004
|
};
|
|
4663
5005
|
const drop = () => {
|
|
4664
|
-
const
|
|
5006
|
+
const text = cur;
|
|
4665
5007
|
cur = tail = "";
|
|
4666
5008
|
gap = false;
|
|
4667
|
-
return
|
|
5009
|
+
return text;
|
|
4668
5010
|
};
|
|
4669
|
-
const
|
|
5011
|
+
const value = (text) => ":" + (squash(text).trim() || " ");
|
|
4670
5012
|
let i = 0, paren = 0, stmt = 0, statements = "", hoisted = "", lastGroups = "", unterminated = false;
|
|
4671
|
-
const stack = [{ ctx:
|
|
5013
|
+
const stack = [{ ctx: options.meta ? "top" : "style" }];
|
|
4672
5014
|
const open = () => {
|
|
4673
5015
|
const parent = stack[stack.length - 1], prelude = cur;
|
|
4674
5016
|
let block;
|
|
@@ -4704,10 +5046,10 @@ function scan(src, options2, native, diagnostics) {
|
|
|
4704
5046
|
flush("}");
|
|
4705
5047
|
if (block.hoist === undefined)
|
|
4706
5048
|
return;
|
|
4707
|
-
const
|
|
5049
|
+
const text = out.slice(block.hoist), groups = stack.filter((b) => b.group), key = groups.map((b) => b.group).join("{"), shut = "}".repeat(groups.length);
|
|
4708
5050
|
out = out.slice(0, block.hoist);
|
|
4709
5051
|
tail = "";
|
|
4710
|
-
hoisted = key && key === lastGroups ? hoisted.slice(0, hoisted.length - shut.length) +
|
|
5052
|
+
hoisted = key && key === lastGroups ? hoisted.slice(0, hoisted.length - shut.length) + text + shut : hoisted + groups.map((b) => b.group + "{").join("") + text + shut;
|
|
4711
5053
|
lastGroups = key;
|
|
4712
5054
|
};
|
|
4713
5055
|
while (i < src.length) {
|
|
@@ -4745,8 +5087,8 @@ function scan(src, options2, native, diagnostics) {
|
|
|
4745
5087
|
else if (c === ")")
|
|
4746
5088
|
paren--;
|
|
4747
5089
|
if (c === ":" && paren === 0) {
|
|
4748
|
-
const
|
|
4749
|
-
if (PROP_NAME.test(
|
|
5090
|
+
const name = src.slice(stmt, i).replace(COMMENTS, "").trim();
|
|
5091
|
+
if (PROP_NAME.test(name)) {
|
|
4750
5092
|
const parsed = readValue(src, i + 1, !native, (at) => {
|
|
4751
5093
|
unterminated = true;
|
|
4752
5094
|
report("LIPS-S004", "Unterminated interpolation", at, src.length - at, "Close the expression with `}`.");
|
|
@@ -4756,18 +5098,18 @@ function scan(src, options2, native, diagnostics) {
|
|
|
4756
5098
|
for (const s of slots)
|
|
4757
5099
|
checkExpr(s);
|
|
4758
5100
|
gap = false;
|
|
4759
|
-
const bare =
|
|
5101
|
+
const bare = name.startsWith("--") && slots.length === 1 && !slots[0].unit && parsed.parts.every((p) => typeof p !== "string" || !p.trim());
|
|
4760
5102
|
if (bare) {
|
|
4761
|
-
binds.push({ prop:
|
|
5103
|
+
binds.push({ prop: name, e: slot(slots[0].expr) });
|
|
4762
5104
|
drop();
|
|
4763
5105
|
i = parsed.end + (src[parsed.end] === ";" ? 1 : 0);
|
|
4764
5106
|
stmt = i;
|
|
4765
5107
|
continue;
|
|
4766
5108
|
}
|
|
4767
|
-
let
|
|
5109
|
+
let text = "";
|
|
4768
5110
|
for (const part of parsed.parts) {
|
|
4769
5111
|
if (typeof part === "string") {
|
|
4770
|
-
|
|
5112
|
+
text += part;
|
|
4771
5113
|
continue;
|
|
4772
5114
|
}
|
|
4773
5115
|
const e = slot(part.expr), prop = `${prefix}-${e}`;
|
|
@@ -4781,10 +5123,10 @@ function scan(src, options2, native, diagnostics) {
|
|
|
4781
5123
|
initial: NUMBER_SYNTAX[1]
|
|
4782
5124
|
});
|
|
4783
5125
|
}
|
|
4784
|
-
|
|
5126
|
+
text += part.unit ? `calc(var(${prop}) * 1${part.unit})` : `var(${prop})`;
|
|
4785
5127
|
}
|
|
4786
|
-
lint(
|
|
4787
|
-
emit(
|
|
5128
|
+
lint(name, stmt, parsed.end, text);
|
|
5129
|
+
emit(value(text));
|
|
4788
5130
|
i = parsed.end;
|
|
4789
5131
|
continue;
|
|
4790
5132
|
}
|
|
@@ -4844,13 +5186,13 @@ function scan(src, options2, native, diagnostics) {
|
|
|
4844
5186
|
flush("");
|
|
4845
5187
|
return { css: out, statements, hoisted, exprs, binds, props };
|
|
4846
5188
|
}
|
|
4847
|
-
function compileStyle(src,
|
|
4848
|
-
const diagnostics = [], preprocess =
|
|
4849
|
-
const empty = { v: 1, nsp:
|
|
4850
|
-
const scoped =
|
|
5189
|
+
function compileStyle(src, options) {
|
|
5190
|
+
const diagnostics = [], preprocess = options.preprocess || PREPROCESSOR, { css, statements, hoisted, exprs, binds, props } = scan(src, options, !preprocess, diagnostics);
|
|
5191
|
+
const empty = { v: 1, nsp: options.nsp, css: "", exprs: [], binds: [] };
|
|
5192
|
+
const scoped = options.meta || !css ? css : `${options.scope || `[rel="${quote(options.nsp)}"]`}{${css}}`, body = hoisted + scoped, source = options.layer ? `@layer ${options.layer}{${body}}` : body;
|
|
4851
5193
|
let sheet;
|
|
4852
5194
|
try {
|
|
4853
|
-
sheet = preprocess ? preprocess(
|
|
5195
|
+
sheet = preprocess ? preprocess(source) : source;
|
|
4854
5196
|
} catch (error) {
|
|
4855
5197
|
diagnostics.push({
|
|
4856
5198
|
code: "LIPS-S006",
|
|
@@ -4861,7 +5203,7 @@ function compileStyle(src, options2) {
|
|
|
4861
5203
|
return { ir: empty, diagnostics };
|
|
4862
5204
|
}
|
|
4863
5205
|
const registrations = props.map((p) => `@property ${p.name}{syntax:"${p.syntax}";inherits:${p.inherits};initial-value:${p.initial}}`).join("");
|
|
4864
|
-
const ir = { v: 1, nsp:
|
|
5206
|
+
const ir = { v: 1, nsp: options.nsp, css: statements + registrations + sheet, exprs, binds };
|
|
4865
5207
|
if (props.length)
|
|
4866
5208
|
ir.props = props;
|
|
4867
5209
|
return { ir, diagnostics };
|
|
@@ -4887,15 +5229,26 @@ var VOID_ELEMENTS = new Set([
|
|
|
4887
5229
|
var RAW_WHITESPACE_TAGS = new Set(["pre", "textarea"]);
|
|
4888
5230
|
var HEAD_SUGAR_TAGS = new Set(["if", "else-if", "switch", "log"]);
|
|
4889
5231
|
var NAMED_ENTITIES = {
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
5232
|
+
__proto__: null,
|
|
5233
|
+
amp: "&",
|
|
5234
|
+
lt: "<",
|
|
5235
|
+
gt: ">",
|
|
5236
|
+
quot: '"',
|
|
5237
|
+
apos: "'",
|
|
5238
|
+
nbsp: " "
|
|
4896
5239
|
};
|
|
4897
|
-
|
|
4898
|
-
|
|
5240
|
+
var REFERENCE = /&(?:#(\d+)|#[xX]([0-9a-fA-F]+)|([A-Za-z][A-Za-z0-9]*));/g;
|
|
5241
|
+
function decodeEntities(text, unknown) {
|
|
5242
|
+
return text.replace(REFERENCE, (m, dec, hex, name, index) => {
|
|
5243
|
+
if (name === undefined) {
|
|
5244
|
+
const code = dec !== undefined ? parseInt(dec, 10) : parseInt(hex, 16);
|
|
5245
|
+
return code > 0 && code <= 1114111 ? String.fromCodePoint(code) : m;
|
|
5246
|
+
}
|
|
5247
|
+
if (name in NAMED_ENTITIES)
|
|
5248
|
+
return NAMED_ENTITIES[name];
|
|
5249
|
+
unknown?.(name, index);
|
|
5250
|
+
return m;
|
|
5251
|
+
});
|
|
4899
5252
|
}
|
|
4900
5253
|
|
|
4901
5254
|
class TemplateParser {
|
|
@@ -4906,7 +5259,7 @@ class TemplateParser {
|
|
|
4906
5259
|
constructor(src) {
|
|
4907
5260
|
this.src = src;
|
|
4908
5261
|
}
|
|
4909
|
-
locate(
|
|
5262
|
+
locate(offset) {
|
|
4910
5263
|
if (!this.lineStarts) {
|
|
4911
5264
|
this.lineStarts = [0];
|
|
4912
5265
|
for (let i = 0;i < this.src.length; i++)
|
|
@@ -4917,19 +5270,22 @@ class TemplateParser {
|
|
|
4917
5270
|
let lo = 0, hi = this.lineStarts.length - 1;
|
|
4918
5271
|
while (lo < hi) {
|
|
4919
5272
|
const mid = lo + hi + 1 >> 1;
|
|
4920
|
-
this.lineStarts[mid] <=
|
|
5273
|
+
this.lineStarts[mid] <= offset ? lo = mid : hi = mid - 1;
|
|
4921
5274
|
}
|
|
4922
|
-
return { line: lo + 1, col:
|
|
5275
|
+
return { line: lo + 1, col: offset - this.lineStarts[lo] + 1 };
|
|
5276
|
+
}
|
|
5277
|
+
report(code, severity, message, offset, length = 1, hint) {
|
|
5278
|
+
const { line, col } = this.locate(offset);
|
|
5279
|
+
this.diagnostics.push({ code, severity, message, hint, loc: { line, col, offset, length } });
|
|
4923
5280
|
}
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
this.diagnostics.push({ code, severity, message, hint, loc: { line, col, offset: offset2, length } });
|
|
5281
|
+
decode(text, at) {
|
|
5282
|
+
return decodeEntities(text, (name, index) => this.report("LIPS-P013", "warning", `&${name}; is not decoded`, at + index, name.length + 2, "Write the character, or its number: ©"));
|
|
4927
5283
|
}
|
|
4928
5284
|
eof() {
|
|
4929
5285
|
return this.pos >= this.src.length;
|
|
4930
5286
|
}
|
|
4931
|
-
peek(
|
|
4932
|
-
return this.src[this.pos +
|
|
5287
|
+
peek(offset = 0) {
|
|
5288
|
+
return this.src[this.pos + offset];
|
|
4933
5289
|
}
|
|
4934
5290
|
startsWith(str) {
|
|
4935
5291
|
return this.src.startsWith(str, this.pos);
|
|
@@ -5001,8 +5357,8 @@ class TemplateParser {
|
|
|
5001
5357
|
const node = this.parseTag(stack);
|
|
5002
5358
|
node && nodes.push(node);
|
|
5003
5359
|
} else {
|
|
5004
|
-
const
|
|
5005
|
-
|
|
5360
|
+
const text = this.parseText(stack);
|
|
5361
|
+
text && nodes.push(text);
|
|
5006
5362
|
}
|
|
5007
5363
|
if (this.pos === before)
|
|
5008
5364
|
this.pos++;
|
|
@@ -5032,14 +5388,14 @@ class TemplateParser {
|
|
|
5032
5388
|
if (parts.some((p) => typeof p !== "string"))
|
|
5033
5389
|
return {
|
|
5034
5390
|
t: "interp",
|
|
5035
|
-
parts: parts.map((p) => typeof p === "string" ?
|
|
5391
|
+
parts: parts.map((p) => typeof p === "string" ? this.decode(p, start) : p),
|
|
5036
5392
|
loc
|
|
5037
5393
|
};
|
|
5038
5394
|
const raw = parts.length ? parts[0] : "";
|
|
5039
5395
|
const inRaw = stack.some((tag) => RAW_WHITESPACE_TAGS.has(tag));
|
|
5040
5396
|
if (!raw || !inRaw && !raw.trim())
|
|
5041
5397
|
return null;
|
|
5042
|
-
return { t: "text", value:
|
|
5398
|
+
return { t: "text", value: this.decode(raw, start), loc };
|
|
5043
5399
|
}
|
|
5044
5400
|
parseTag(stack) {
|
|
5045
5401
|
const start = this.pos;
|
|
@@ -5050,9 +5406,9 @@ class TemplateParser {
|
|
|
5050
5406
|
this.pos = this.src.length;
|
|
5051
5407
|
return null;
|
|
5052
5408
|
}
|
|
5053
|
-
const
|
|
5409
|
+
const value = this.src.slice(this.pos + 4, end);
|
|
5054
5410
|
this.pos = end + 3;
|
|
5055
|
-
return { t: "comment", value
|
|
5411
|
+
return { t: "comment", value, loc: { offset: start, length: this.pos - start } };
|
|
5056
5412
|
}
|
|
5057
5413
|
if (this.startsWith("<>")) {
|
|
5058
5414
|
this.pos += 2;
|
|
@@ -5069,7 +5425,7 @@ class TemplateParser {
|
|
|
5069
5425
|
const region = this.scanBalanced("}", "LIPS-P008");
|
|
5070
5426
|
if (!region)
|
|
5071
5427
|
return null;
|
|
5072
|
-
const
|
|
5428
|
+
const el = {
|
|
5073
5429
|
t: "element",
|
|
5074
5430
|
tag: "#dynamic",
|
|
5075
5431
|
dynamicTag: { expr: region.content.trim(), loc: region.loc },
|
|
@@ -5078,8 +5434,8 @@ class TemplateParser {
|
|
|
5078
5434
|
selfClosed: false,
|
|
5079
5435
|
loc: { offset: start, length: 0 }
|
|
5080
5436
|
};
|
|
5081
|
-
this.finishTag(
|
|
5082
|
-
return
|
|
5437
|
+
this.finishTag(el, stack, start);
|
|
5438
|
+
return el;
|
|
5083
5439
|
}
|
|
5084
5440
|
this.pos++;
|
|
5085
5441
|
const nameStart = this.pos;
|
|
@@ -5175,8 +5531,8 @@ class TemplateParser {
|
|
|
5175
5531
|
const attrStart = this.pos;
|
|
5176
5532
|
if (this.startsWith("...")) {
|
|
5177
5533
|
this.pos += 3;
|
|
5178
|
-
const
|
|
5179
|
-
el.attrs.push({ k: "spread", source
|
|
5534
|
+
const source = this.readUnquotedValue();
|
|
5535
|
+
el.attrs.push({ k: "spread", source, loc: { offset: attrStart, length: this.pos - attrStart } });
|
|
5180
5536
|
continue;
|
|
5181
5537
|
}
|
|
5182
5538
|
if (this.peek() === "[") {
|
|
@@ -5196,8 +5552,8 @@ class TemplateParser {
|
|
|
5196
5552
|
const nameStart = this.pos;
|
|
5197
5553
|
while (!this.eof() && /[^\s=/>()]/.test(this.peek()))
|
|
5198
5554
|
this.pos++;
|
|
5199
|
-
const
|
|
5200
|
-
if (!
|
|
5555
|
+
const name = this.src.slice(nameStart, this.pos);
|
|
5556
|
+
if (!name) {
|
|
5201
5557
|
this.report("LIPS-P009", "error", `Invalid attribute syntax at '${this.peek()}'`, this.pos);
|
|
5202
5558
|
this.pos++;
|
|
5203
5559
|
continue;
|
|
@@ -5205,20 +5561,20 @@ class TemplateParser {
|
|
|
5205
5561
|
if (this.peek() === "(") {
|
|
5206
5562
|
this.pos++;
|
|
5207
5563
|
const region = this.scanBalanced(")", "LIPS-P010");
|
|
5208
|
-
const
|
|
5564
|
+
const source = region ? region.content.trim() : "";
|
|
5209
5565
|
const loc = { offset: attrStart, length: this.pos - attrStart };
|
|
5210
|
-
|
|
5566
|
+
name.startsWith("on-") ? el.attrs.push({ k: "event", name: name.slice(3), source, loc }) : el.attrs.push({ k: "fn", name, source, loc });
|
|
5211
5567
|
continue;
|
|
5212
5568
|
}
|
|
5213
5569
|
if (this.peek() === "=") {
|
|
5214
5570
|
this.pos++;
|
|
5215
|
-
this.parseAttrValue(el,
|
|
5571
|
+
this.parseAttrValue(el, name, attrStart);
|
|
5216
5572
|
continue;
|
|
5217
5573
|
}
|
|
5218
|
-
el.attrs.push({ k: "bool", name
|
|
5574
|
+
el.attrs.push({ k: "bool", name, value: !negated, loc: { offset: attrStart, length: this.pos - attrStart } });
|
|
5219
5575
|
}
|
|
5220
5576
|
}
|
|
5221
|
-
parseAttrValue(el,
|
|
5577
|
+
parseAttrValue(el, name, attrStart) {
|
|
5222
5578
|
const q = this.peek();
|
|
5223
5579
|
if (q === '"' || q === "'") {
|
|
5224
5580
|
this.pos++;
|
|
@@ -5240,9 +5596,9 @@ class TemplateParser {
|
|
|
5240
5596
|
this.pos++;
|
|
5241
5597
|
}
|
|
5242
5598
|
buffer && parts.push(buffer);
|
|
5243
|
-
this.eof() ? this.report("LIPS-P010", "error", `Unterminated value for '${
|
|
5599
|
+
this.eof() ? this.report("LIPS-P010", "error", `Unterminated value for '${name}'`, valueStart, this.pos - valueStart) : this.pos++;
|
|
5244
5600
|
const loc = { offset: attrStart, length: this.pos - attrStart };
|
|
5245
|
-
parts.some((p) => typeof p !== "string") ? el.attrs.push({ k: "interp", name
|
|
5601
|
+
parts.some((p) => typeof p !== "string") ? el.attrs.push({ k: "interp", name, parts: parts.map((p) => typeof p === "string" ? this.decode(p, valueStart) : p), loc }) : el.attrs.push({ k: "literal", name, value: this.decode(parts[0] ?? "", valueStart), loc });
|
|
5246
5602
|
return;
|
|
5247
5603
|
}
|
|
5248
5604
|
if (q === "{") {
|
|
@@ -5250,14 +5606,14 @@ class TemplateParser {
|
|
|
5250
5606
|
const region = this.scanBalanced("}", "LIPS-P007");
|
|
5251
5607
|
el.attrs.push({
|
|
5252
5608
|
k: "expr",
|
|
5253
|
-
name
|
|
5609
|
+
name,
|
|
5254
5610
|
source: region ? region.content.trim() : "",
|
|
5255
5611
|
loc: { offset: attrStart, length: this.pos - attrStart }
|
|
5256
5612
|
});
|
|
5257
5613
|
return;
|
|
5258
5614
|
}
|
|
5259
|
-
const
|
|
5260
|
-
|
|
5615
|
+
const source = this.readUnquotedValue();
|
|
5616
|
+
source ? el.attrs.push({ k: "expr", name, source, loc: { offset: attrStart, length: this.pos - attrStart } }) : this.report("LIPS-P010", "error", `Missing value for attribute '${name}'`, attrStart);
|
|
5261
5617
|
}
|
|
5262
5618
|
readUnquotedValue() {
|
|
5263
5619
|
const start = this.pos;
|
|
@@ -5311,9 +5667,9 @@ function findTemplateStart(src) {
|
|
|
5311
5667
|
for (let i = 0;i < src.length; i++) {
|
|
5312
5668
|
const c = src[i];
|
|
5313
5669
|
if (c === "'" || c === '"' || c === "`") {
|
|
5314
|
-
const
|
|
5670
|
+
const quote = c;
|
|
5315
5671
|
i++;
|
|
5316
|
-
while (i < src.length && src[i] !==
|
|
5672
|
+
while (i < src.length && src[i] !== quote) {
|
|
5317
5673
|
if (src[i] === "\\")
|
|
5318
5674
|
i++;
|
|
5319
5675
|
i++;
|
|
@@ -5352,156 +5708,7 @@ function findTemplateStart(src) {
|
|
|
5352
5708
|
|
|
5353
5709
|
// src/ir/compiler.ts
|
|
5354
5710
|
var ANCHOR = "<!--$-->";
|
|
5355
|
-
var
|
|
5356
|
-
"if",
|
|
5357
|
-
"else-if",
|
|
5358
|
-
"else",
|
|
5359
|
-
"for",
|
|
5360
|
-
"switch",
|
|
5361
|
-
"async",
|
|
5362
|
-
"let",
|
|
5363
|
-
"const",
|
|
5364
|
-
"log",
|
|
5365
|
-
"context",
|
|
5366
|
-
"i18n"
|
|
5367
|
-
]);
|
|
5368
|
-
var ARM_TAGS = new Set(["case", "default", "then", "catch", "loading"]);
|
|
5369
|
-
var HTML_TAGS = new Set([
|
|
5370
|
-
"a",
|
|
5371
|
-
"abbr",
|
|
5372
|
-
"address",
|
|
5373
|
-
"area",
|
|
5374
|
-
"article",
|
|
5375
|
-
"aside",
|
|
5376
|
-
"audio",
|
|
5377
|
-
"b",
|
|
5378
|
-
"base",
|
|
5379
|
-
"bdi",
|
|
5380
|
-
"bdo",
|
|
5381
|
-
"blockquote",
|
|
5382
|
-
"body",
|
|
5383
|
-
"br",
|
|
5384
|
-
"button",
|
|
5385
|
-
"canvas",
|
|
5386
|
-
"caption",
|
|
5387
|
-
"cite",
|
|
5388
|
-
"code",
|
|
5389
|
-
"col",
|
|
5390
|
-
"colgroup",
|
|
5391
|
-
"data",
|
|
5392
|
-
"datalist",
|
|
5393
|
-
"dd",
|
|
5394
|
-
"del",
|
|
5395
|
-
"details",
|
|
5396
|
-
"dfn",
|
|
5397
|
-
"dialog",
|
|
5398
|
-
"div",
|
|
5399
|
-
"dl",
|
|
5400
|
-
"dt",
|
|
5401
|
-
"em",
|
|
5402
|
-
"embed",
|
|
5403
|
-
"fieldset",
|
|
5404
|
-
"figcaption",
|
|
5405
|
-
"figure",
|
|
5406
|
-
"footer",
|
|
5407
|
-
"form",
|
|
5408
|
-
"h1",
|
|
5409
|
-
"h2",
|
|
5410
|
-
"h3",
|
|
5411
|
-
"h4",
|
|
5412
|
-
"h5",
|
|
5413
|
-
"h6",
|
|
5414
|
-
"head",
|
|
5415
|
-
"header",
|
|
5416
|
-
"hgroup",
|
|
5417
|
-
"hr",
|
|
5418
|
-
"html",
|
|
5419
|
-
"i",
|
|
5420
|
-
"iframe",
|
|
5421
|
-
"img",
|
|
5422
|
-
"input",
|
|
5423
|
-
"ins",
|
|
5424
|
-
"kbd",
|
|
5425
|
-
"label",
|
|
5426
|
-
"legend",
|
|
5427
|
-
"li",
|
|
5428
|
-
"link",
|
|
5429
|
-
"main",
|
|
5430
|
-
"map",
|
|
5431
|
-
"mark",
|
|
5432
|
-
"menu",
|
|
5433
|
-
"meta",
|
|
5434
|
-
"meter",
|
|
5435
|
-
"nav",
|
|
5436
|
-
"noscript",
|
|
5437
|
-
"object",
|
|
5438
|
-
"ol",
|
|
5439
|
-
"optgroup",
|
|
5440
|
-
"option",
|
|
5441
|
-
"output",
|
|
5442
|
-
"p",
|
|
5443
|
-
"picture",
|
|
5444
|
-
"pre",
|
|
5445
|
-
"progress",
|
|
5446
|
-
"q",
|
|
5447
|
-
"rp",
|
|
5448
|
-
"rt",
|
|
5449
|
-
"ruby",
|
|
5450
|
-
"s",
|
|
5451
|
-
"samp",
|
|
5452
|
-
"script",
|
|
5453
|
-
"section",
|
|
5454
|
-
"select",
|
|
5455
|
-
"slot",
|
|
5456
|
-
"small",
|
|
5457
|
-
"source",
|
|
5458
|
-
"span",
|
|
5459
|
-
"strong",
|
|
5460
|
-
"style",
|
|
5461
|
-
"sub",
|
|
5462
|
-
"summary",
|
|
5463
|
-
"sup",
|
|
5464
|
-
"table",
|
|
5465
|
-
"tbody",
|
|
5466
|
-
"td",
|
|
5467
|
-
"template",
|
|
5468
|
-
"textarea",
|
|
5469
|
-
"tfoot",
|
|
5470
|
-
"th",
|
|
5471
|
-
"thead",
|
|
5472
|
-
"time",
|
|
5473
|
-
"title",
|
|
5474
|
-
"tr",
|
|
5475
|
-
"track",
|
|
5476
|
-
"u",
|
|
5477
|
-
"ul",
|
|
5478
|
-
"var",
|
|
5479
|
-
"video",
|
|
5480
|
-
"wbr",
|
|
5481
|
-
"svg",
|
|
5482
|
-
"circle",
|
|
5483
|
-
"clippath",
|
|
5484
|
-
"defs",
|
|
5485
|
-
"ellipse",
|
|
5486
|
-
"foreignobject",
|
|
5487
|
-
"g",
|
|
5488
|
-
"image",
|
|
5489
|
-
"line",
|
|
5490
|
-
"lineargradient",
|
|
5491
|
-
"marker",
|
|
5492
|
-
"mask",
|
|
5493
|
-
"path",
|
|
5494
|
-
"pattern",
|
|
5495
|
-
"polygon",
|
|
5496
|
-
"polyline",
|
|
5497
|
-
"radialgradient",
|
|
5498
|
-
"rect",
|
|
5499
|
-
"stop",
|
|
5500
|
-
"symbol",
|
|
5501
|
-
"text",
|
|
5502
|
-
"tspan",
|
|
5503
|
-
"use"
|
|
5504
|
-
]);
|
|
5711
|
+
var EVENT_MODS = new Set(["stop", "capture", "outside"]);
|
|
5505
5712
|
var VOID_ELEMENTS2 = new Set([
|
|
5506
5713
|
"area",
|
|
5507
5714
|
"base",
|
|
@@ -5573,7 +5780,7 @@ class Compiler {
|
|
|
5573
5780
|
this.macros = macros;
|
|
5574
5781
|
this.tree = tree;
|
|
5575
5782
|
}
|
|
5576
|
-
locate(
|
|
5783
|
+
locate(offset) {
|
|
5577
5784
|
if (!this.lineStarts) {
|
|
5578
5785
|
this.lineStarts = [0];
|
|
5579
5786
|
for (let i = 0;i < this.src.length; i++)
|
|
@@ -5584,35 +5791,35 @@ class Compiler {
|
|
|
5584
5791
|
let lo = 0, hi = this.lineStarts.length - 1;
|
|
5585
5792
|
while (lo < hi) {
|
|
5586
5793
|
const mid = lo + hi + 1 >> 1;
|
|
5587
|
-
this.lineStarts[mid] <=
|
|
5794
|
+
this.lineStarts[mid] <= offset ? lo = mid : hi = mid - 1;
|
|
5588
5795
|
}
|
|
5589
|
-
return { line: lo + 1, col:
|
|
5796
|
+
return { line: lo + 1, col: offset - this.lineStarts[lo] + 1 };
|
|
5590
5797
|
}
|
|
5591
|
-
report(code, severity, message,
|
|
5592
|
-
const { line, col } = this.locate(
|
|
5593
|
-
this.diagnostics.push({ code, severity, message, hint, loc: { line, col, offset
|
|
5798
|
+
report(code, severity, message, offset, length = 1, hint) {
|
|
5799
|
+
const { line, col } = this.locate(offset);
|
|
5800
|
+
this.diagnostics.push({ code, severity, message, hint, loc: { line, col, offset, length } });
|
|
5594
5801
|
}
|
|
5595
|
-
expr(
|
|
5596
|
-
const cached = this.exprIndex.get(
|
|
5802
|
+
expr(source, at) {
|
|
5803
|
+
const cached = this.exprIndex.get(source);
|
|
5597
5804
|
if (cached !== undefined)
|
|
5598
5805
|
return cached;
|
|
5599
|
-
const { diagnostics } = parseExpression(
|
|
5806
|
+
const { diagnostics } = parseExpression(source);
|
|
5600
5807
|
for (const d of diagnostics) {
|
|
5601
|
-
const
|
|
5602
|
-
this.report(d.code, "error", d.message,
|
|
5808
|
+
const offset = (at?.offset ?? 0) + d.loc.offset;
|
|
5809
|
+
this.report(d.code, "error", d.message, offset, d.loc.length);
|
|
5603
5810
|
}
|
|
5604
5811
|
const idx = this.exprs.length;
|
|
5605
|
-
this.exprs.push(
|
|
5606
|
-
this.exprIndex.set(
|
|
5812
|
+
this.exprs.push(source);
|
|
5813
|
+
this.exprIndex.set(source, idx);
|
|
5607
5814
|
return idx;
|
|
5608
5815
|
}
|
|
5609
|
-
synth(
|
|
5610
|
-
const cached = this.exprIndex.get(
|
|
5816
|
+
synth(source) {
|
|
5817
|
+
const cached = this.exprIndex.get(source);
|
|
5611
5818
|
if (cached !== undefined)
|
|
5612
5819
|
return cached;
|
|
5613
5820
|
const idx = this.exprs.length;
|
|
5614
|
-
this.exprs.push(
|
|
5615
|
-
this.exprIndex.set(
|
|
5821
|
+
this.exprs.push(source);
|
|
5822
|
+
this.exprIndex.set(source, idx);
|
|
5616
5823
|
return idx;
|
|
5617
5824
|
}
|
|
5618
5825
|
concat(parts) {
|
|
@@ -5621,8 +5828,8 @@ class Compiler {
|
|
|
5621
5828
|
for (const d of diagnostics)
|
|
5622
5829
|
this.report(d.code, "error", d.message, p.loc.offset + d.loc.offset, d.loc.length);
|
|
5623
5830
|
});
|
|
5624
|
-
const
|
|
5625
|
-
return this.synth(
|
|
5831
|
+
const source = parts.map((p) => typeof p === "string" ? JSON.stringify(p) : `((${p.expr})??"")`).join("+");
|
|
5832
|
+
return this.synth(source);
|
|
5626
5833
|
}
|
|
5627
5834
|
compInput(attr) {
|
|
5628
5835
|
switch (attr.k) {
|
|
@@ -5671,8 +5878,8 @@ class Compiler {
|
|
|
5671
5878
|
case "comment": {
|
|
5672
5879
|
if (tree)
|
|
5673
5880
|
break;
|
|
5674
|
-
const
|
|
5675
|
-
html.push(`<!--${/^-?>/.test(
|
|
5881
|
+
const text = node.value.replace(/--/g, "- -");
|
|
5882
|
+
html.push(`<!--${/^-?>/.test(text) ? " " + text : text}-->`);
|
|
5676
5883
|
lastWasText = false;
|
|
5677
5884
|
index++;
|
|
5678
5885
|
break;
|
|
@@ -5740,19 +5947,19 @@ class Compiler {
|
|
|
5740
5947
|
emitElement(node, path, index, html, block, emitSiblings, kids) {
|
|
5741
5948
|
const p = [...path, index];
|
|
5742
5949
|
let open = `<${node.tag}`;
|
|
5743
|
-
const el = [node.tag], attrs = {}, put = (
|
|
5744
|
-
Object.prototype.hasOwnProperty.call(attrs,
|
|
5950
|
+
const el = [node.tag], attrs = {}, put = (name, value) => {
|
|
5951
|
+
Object.prototype.hasOwnProperty.call(attrs, name) || (attrs[name] = value);
|
|
5745
5952
|
};
|
|
5746
5953
|
this.tree && kids.push(el);
|
|
5747
5954
|
const named = node.attrs.filter((a) => ("name" in a));
|
|
5748
5955
|
const i18n = named.some((a) => a.name === "i18n" && (a.k === "bool" && a.value || a.k === "literal"));
|
|
5749
|
-
const translatableAttr = (
|
|
5750
|
-
const keyOf = (
|
|
5751
|
-
const a = named.find((x) => x.name ===
|
|
5956
|
+
const translatableAttr = (name) => i18n && (name === "title" || name === "placeholder");
|
|
5957
|
+
const keyOf = (name) => {
|
|
5958
|
+
const a = named.find((x) => x.name === name && x.k === "literal");
|
|
5752
5959
|
return a && "value" in a && a.value ? String(a.value) : undefined;
|
|
5753
5960
|
};
|
|
5754
5961
|
const textKey = keyOf("i18n");
|
|
5755
|
-
const attrKey = (
|
|
5962
|
+
const attrKey = (name) => keyOf(`i18n-${name}`);
|
|
5756
5963
|
!i18n && named.some((a) => a.name.startsWith("i18n-")) && this.report("LIPS-C014", "warning", `i18n-* key on <${node.tag}> without the 'i18n' marker — the attribute will not be translated`, node.loc.offset, node.loc.length);
|
|
5757
5964
|
for (const attr of node.attrs) {
|
|
5758
5965
|
if (this.tree && "name" in attr && attr.name === "@html") {
|
|
@@ -5760,8 +5967,8 @@ class Compiler {
|
|
|
5760
5967
|
continue;
|
|
5761
5968
|
}
|
|
5762
5969
|
if ("name" in attr && attr.name === "style") {
|
|
5763
|
-
const
|
|
5764
|
-
if (
|
|
5970
|
+
const source = objectishAttr(attr);
|
|
5971
|
+
if (source && isObjectLiteral(source)) {
|
|
5765
5972
|
this.report("LIPS-C019", "error", `style= on <${node.tag}> takes CSS text, not an object literal`, attr.loc.offset, attr.loc.length, 'Write the declarations as CSS — style="border: 2px solid gray; margin: 3rem" — ' + 'and interpolate values into it where they vary: style="margin: {state.gap}rem". ' + "Styles that need pseudo-classes, media queries or keyframes belong in the " + "component's stylesheet.");
|
|
5766
5973
|
continue;
|
|
5767
5974
|
}
|
|
@@ -5836,6 +6043,7 @@ class Compiler {
|
|
|
5836
6043
|
break;
|
|
5837
6044
|
}
|
|
5838
6045
|
case "event":
|
|
6046
|
+
this.modifiers(attr);
|
|
5839
6047
|
block.binds.push({ t: "event", p, name: attr.name, e: this.synth(attr.source) });
|
|
5840
6048
|
break;
|
|
5841
6049
|
case "spread":
|
|
@@ -5932,14 +6140,18 @@ class Compiler {
|
|
|
5932
6140
|
args,
|
|
5933
6141
|
block: this.block(node.children, [...scope, ...args])
|
|
5934
6142
|
};
|
|
5935
|
-
if (inAttr
|
|
5936
|
-
|
|
6143
|
+
if (inAttr) {
|
|
6144
|
+
const source = this.valueOf(inAttr);
|
|
6145
|
+
source === undefined ? this.report("LIPS-C004", "error", `<for in=…> takes an expression: in=state.items`, inAttr.loc.offset, inAttr.loc.length) : child.of = this.expr(source, inAttr.loc);
|
|
6146
|
+
}
|
|
5937
6147
|
if (fromAttr)
|
|
5938
6148
|
child.from = this.numInput(fromAttr);
|
|
5939
6149
|
if (toAttr)
|
|
5940
6150
|
child.to = this.numInput(toAttr);
|
|
5941
|
-
if (byAttr
|
|
5942
|
-
|
|
6151
|
+
if (byAttr) {
|
|
6152
|
+
const source = byAttr.k === "literal" ? undefined : this.valueOf(byAttr);
|
|
6153
|
+
byAttr.k === "literal" ? child.by = { lit: byAttr.value } : source === undefined ? this.report("LIPS-C004", "error", `<for by=…> takes a key path or an expression`, byAttr.loc.offset, byAttr.loc.length) : child.by = { e: this.expr(source, byAttr.loc) };
|
|
6154
|
+
}
|
|
5943
6155
|
block.blocks.push(child);
|
|
5944
6156
|
break;
|
|
5945
6157
|
}
|
|
@@ -6051,10 +6263,18 @@ class Compiler {
|
|
|
6051
6263
|
numInput(attr) {
|
|
6052
6264
|
if (attr.k === "literal")
|
|
6053
6265
|
return { lit: isNumeric(attr.value) ? Number(attr.value) : attr.value };
|
|
6054
|
-
|
|
6055
|
-
|
|
6266
|
+
const source = this.valueOf(attr);
|
|
6267
|
+
if (source !== undefined)
|
|
6268
|
+
return isNumeric(source) ? { lit: Number(source) } : { e: this.expr(source, attr.loc) };
|
|
6269
|
+
"name" in attr && this.report("LIPS-C004", "error", `<for ${attr.name}=…> takes a number or an expression`, attr.loc.offset, attr.loc.length);
|
|
6056
6270
|
return { lit: undefined };
|
|
6057
6271
|
}
|
|
6272
|
+
valueOf(attr) {
|
|
6273
|
+
if (attr.k === "expr")
|
|
6274
|
+
return attr.source;
|
|
6275
|
+
if (attr.k === "interp" && attr.parts.length === 1 && typeof attr.parts[0] !== "string")
|
|
6276
|
+
return attr.parts[0].expr;
|
|
6277
|
+
}
|
|
6058
6278
|
macroCall(node, p, scope) {
|
|
6059
6279
|
const macro = this.macros.get(node.tag);
|
|
6060
6280
|
if (this.macroStack.includes(macro.name)) {
|
|
@@ -6067,7 +6287,10 @@ class Compiler {
|
|
|
6067
6287
|
sets.push({ name: attr.name, ci: this.compInput(attr) });
|
|
6068
6288
|
else if (attr.k === "spread")
|
|
6069
6289
|
sets.push({ spread: this.expr(attr.source, attr.loc) });
|
|
6290
|
+
else if (attr.k === "event")
|
|
6291
|
+
this.report("LIPS-C023", "error", `on-${attr.name}( … ) on the macro <${node.tag}> wires no listener`, attr.loc.offset, attr.loc.length, "Pass the handler as an argument (fn=self.pick) and wire it in the body");
|
|
6070
6292
|
}
|
|
6293
|
+
node.children.length && this.report("LIPS-C024", "error", `<${node.tag}> is a macro: what it encloses is not rendered`, node.loc.offset, node.loc.length, "A component takes content: <{input.renderer}/>");
|
|
6071
6294
|
this.macroStack.push(macro.name);
|
|
6072
6295
|
const block = this.block(macro.children, [...scope, ...macro.argv]);
|
|
6073
6296
|
this.macroStack.pop();
|
|
@@ -6079,6 +6302,10 @@ class Compiler {
|
|
|
6079
6302
|
this.report("LIPS-C020", "error", `${attr.name}="…" on <${tag}> wires no listener`, attr.loc.offset, attr.loc.length, `Handlers use the instruction form: ${attr.name}( … ). ` + `Quoted, it is an ordinary attribute — the handler never runs and the source is emitted into the DOM.`);
|
|
6080
6303
|
return true;
|
|
6081
6304
|
}
|
|
6305
|
+
modifiers(attr, comp) {
|
|
6306
|
+
const mods = attr.name.split(".").slice(1), bad = mods.find((m) => !EVENT_MODS.has(m));
|
|
6307
|
+
(bad || comp && mods[0]) && this.report("LIPS-C022", bad ? "error" : "warning", bad ? `Unknown event modifier .${bad}: use .stop, .capture or .outside` : `.${mods[0]} does nothing on a component's event`, attr.loc.offset, attr.loc.length);
|
|
6308
|
+
}
|
|
6082
6309
|
compLike(node, p, scope, kind) {
|
|
6083
6310
|
const inputs = {}, spreads = [], events = [];
|
|
6084
6311
|
let args = [];
|
|
@@ -6090,9 +6317,15 @@ class Compiler {
|
|
|
6090
6317
|
case "bool":
|
|
6091
6318
|
case "expr":
|
|
6092
6319
|
case "interp":
|
|
6320
|
+
if (attr.name === "@format" && attr.k !== "bool") {
|
|
6321
|
+
const { ref, e } = this.formatBind(p, attr);
|
|
6322
|
+
inputs[attr.name] = { lit: { ref, e } };
|
|
6323
|
+
break;
|
|
6324
|
+
}
|
|
6093
6325
|
inputs[attr.name] = this.compInput(attr);
|
|
6094
6326
|
break;
|
|
6095
6327
|
case "event":
|
|
6328
|
+
this.modifiers(attr, kind === "comp");
|
|
6096
6329
|
events.push({ name: attr.name, e: this.synth(attr.source) });
|
|
6097
6330
|
break;
|
|
6098
6331
|
case "spread":
|
|
@@ -6129,15 +6362,15 @@ function parseMacros(src, diagnostics, check) {
|
|
|
6129
6362
|
});
|
|
6130
6363
|
continue;
|
|
6131
6364
|
}
|
|
6132
|
-
let
|
|
6365
|
+
let name = "";
|
|
6133
6366
|
const argv = [];
|
|
6134
6367
|
for (const attr of node.attrs) {
|
|
6135
6368
|
if (attr.k === "args")
|
|
6136
6369
|
argv.push(...attr.names);
|
|
6137
6370
|
else if (attr.k === "literal" && attr.name === "name")
|
|
6138
|
-
|
|
6371
|
+
name = attr.value;
|
|
6139
6372
|
}
|
|
6140
|
-
if (!
|
|
6373
|
+
if (!name) {
|
|
6141
6374
|
diagnostics.push({
|
|
6142
6375
|
code: "LIPS-C011",
|
|
6143
6376
|
severity: "error",
|
|
@@ -6146,27 +6379,27 @@ function parseMacros(src, diagnostics, check) {
|
|
|
6146
6379
|
});
|
|
6147
6380
|
continue;
|
|
6148
6381
|
}
|
|
6149
|
-
macros.set(
|
|
6382
|
+
macros.set(name.toLowerCase(), { name, argv, children: node.children });
|
|
6150
6383
|
}
|
|
6151
6384
|
return macros;
|
|
6152
6385
|
}
|
|
6153
|
-
function compileTemplate(src,
|
|
6386
|
+
function compileTemplate(src, options) {
|
|
6154
6387
|
const diagnostics = [];
|
|
6155
|
-
const macros = parseMacros(
|
|
6388
|
+
const macros = parseMacros(options?.macros || "", diagnostics, options?.check);
|
|
6156
6389
|
const parsed = parseTemplate(src);
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
const compiler = new Compiler(src, macros,
|
|
6390
|
+
options?.check?.(parsed.root.children, diagnostics, src);
|
|
6391
|
+
options?.transform?.(parsed.root.children, diagnostics);
|
|
6392
|
+
const compiler = new Compiler(src, macros, options?.target === "tree");
|
|
6160
6393
|
const ir = compiler.compile(parsed.root.children);
|
|
6161
6394
|
return { ir, diagnostics: [...diagnostics, ...parsed.diagnostics, ...compiler.diagnostics] };
|
|
6162
6395
|
}
|
|
6163
6396
|
|
|
6164
6397
|
// src/ir/router.ts
|
|
6165
|
-
function safeDecode(
|
|
6398
|
+
function safeDecode(value) {
|
|
6166
6399
|
try {
|
|
6167
|
-
return decodeURIComponent(
|
|
6400
|
+
return decodeURIComponent(value);
|
|
6168
6401
|
} catch (e) {
|
|
6169
|
-
return
|
|
6402
|
+
return value;
|
|
6170
6403
|
}
|
|
6171
6404
|
}
|
|
6172
6405
|
var parseQuery = (str) => Object.fromEntries(new URLSearchParams(str));
|
|
@@ -6186,32 +6419,39 @@ var routerTemplate = {
|
|
|
6186
6419
|
onInput() {
|
|
6187
6420
|
this.processor(this.input);
|
|
6188
6421
|
},
|
|
6189
|
-
processor(
|
|
6190
|
-
if (!
|
|
6422
|
+
processor(options) {
|
|
6423
|
+
if (!options?.routes)
|
|
6191
6424
|
return;
|
|
6192
|
-
if (
|
|
6425
|
+
if (options.global)
|
|
6193
6426
|
this.__global = true;
|
|
6194
|
-
this.__routes =
|
|
6427
|
+
this.__routes = options.routes.map(({ path, template, default: _default }) => {
|
|
6195
6428
|
if (_default)
|
|
6196
6429
|
this.__defaultPath = path;
|
|
6197
6430
|
const pathVars = path.match(/:[^\/]*(\/|$)/gi) || [], pathRegex = path.replaceAll("/", "\\/").replaceAll(/:[^\/]*(\/|$)/gi, "([^\\/]+)(?:\\/|$)");
|
|
6198
6431
|
return { path, template, default: _default, pathVars, pathRegex: new RegExp(`${pathRegex}$`, "i") };
|
|
6199
6432
|
});
|
|
6200
|
-
if (
|
|
6433
|
+
if (options.global) {
|
|
6201
6434
|
const cpathname = window.location.pathname;
|
|
6202
6435
|
this.__defaultPath = this.__defaultPath && cpathname === "/" && cpathname !== this.__defaultPath ? this.__defaultPath : cpathname ? cpathname + window.location.search : this.__routes[0]?.path;
|
|
6203
6436
|
}
|
|
6204
6437
|
},
|
|
6205
6438
|
onAttach() {
|
|
6206
6439
|
if (this.input?.global) {
|
|
6207
|
-
window.navigate = this.navigate.bind(this);
|
|
6208
|
-
|
|
6440
|
+
window.navigate = this.__navigate = this.navigate.bind(this);
|
|
6441
|
+
this.__popstate = (e) => e.state && this.navigate(e.state.path, true);
|
|
6442
|
+
window.addEventListener("popstate", this.__popstate);
|
|
6209
6443
|
}
|
|
6210
6444
|
typeof this.setContext === "function" && this.setContext("navigate", this.navigate.bind(this));
|
|
6445
|
+
this.__initial = true;
|
|
6211
6446
|
this.__defaultPath && this.navigate(this.__defaultPath);
|
|
6447
|
+
this.__initial = false;
|
|
6448
|
+
},
|
|
6449
|
+
onDestroy() {
|
|
6450
|
+
this.__popstate && window.removeEventListener("popstate", this.__popstate);
|
|
6451
|
+
this.__navigate && window.navigate === this.__navigate && delete window.navigate;
|
|
6212
6452
|
},
|
|
6213
6453
|
navigate(path, back) {
|
|
6214
|
-
!back && this.__global && history.pushState({ path }, "", path);
|
|
6454
|
+
!back && this.__global && history[this.__initial ? "replaceState" : "pushState"]({ path }, "", path);
|
|
6215
6455
|
const parts = String(path).split("?");
|
|
6216
6456
|
path = parts[0];
|
|
6217
6457
|
const query = parts[1] ? parseQuery(parts[1]) : {};
|
|
@@ -6251,16 +6491,22 @@ var routerTemplate = {
|
|
|
6251
6491
|
},
|
|
6252
6492
|
default: `<{state.page} params=state.params query=state.query/>`
|
|
6253
6493
|
};
|
|
6494
|
+
// src/component.ts
|
|
6495
|
+
function component(definition) {
|
|
6496
|
+
return definition ? definition : (named) => named;
|
|
6497
|
+
}
|
|
6254
6498
|
// src/lips.ts
|
|
6255
6499
|
setCompiler(compileTemplate);
|
|
6256
6500
|
setStyleCompiler(compileStyle);
|
|
6257
6501
|
setMessageFormat(messageFormat);
|
|
6502
|
+
setNameCheck(taken);
|
|
6258
6503
|
registerBuiltin("router", routerTemplate);
|
|
6259
6504
|
var lips_default = IRLips;
|
|
6260
6505
|
export {
|
|
6261
6506
|
batch,
|
|
6262
6507
|
compileStyle,
|
|
6263
6508
|
compileTemplate,
|
|
6509
|
+
component,
|
|
6264
6510
|
lips_default as default,
|
|
6265
6511
|
effect,
|
|
6266
6512
|
parseSFC,
|
|
@@ -6271,4 +6517,4 @@ export {
|
|
|
6271
6517
|
untrack
|
|
6272
6518
|
};
|
|
6273
6519
|
|
|
6274
|
-
//# debugId=
|
|
6520
|
+
//# debugId=92A7D93D1578738164756E2164756E21
|