marko 6.0.15 → 6.0.17

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.
@@ -1130,183 +1130,6 @@ function longestIncreasingSubsequence(a) {
1130
1130
  return result;
1131
1131
  }
1132
1132
 
1133
- // src/dom/walker.ts
1134
- var walker = /* @__PURE__ */ document.createTreeWalker(document);
1135
- function walk(startNode, walkCodes, branch) {
1136
- walker.currentNode = startNode;
1137
- walkInternal(0, walkCodes, branch);
1138
- }
1139
- function walkInternal(currentWalkIndex, walkCodes, scope) {
1140
- let value2;
1141
- let storedMultiplier = 0;
1142
- let currentMultiplier = 0;
1143
- let currentScopeIndex = 0;
1144
- for (; currentWalkIndex < walkCodes.length; ) {
1145
- value2 = walkCodes.charCodeAt(currentWalkIndex++);
1146
- currentMultiplier = storedMultiplier;
1147
- storedMultiplier = 0;
1148
- if (value2 === 32 /* Get */) {
1149
- const node = walker.currentNode;
1150
- scope[true ? getDebugKey(currentScopeIndex, walker.currentNode) : currentScopeIndex] = node;
1151
- scope["Getter:" /* Getter */ + (true ? getDebugKey(currentScopeIndex++, walker.currentNode) : currentScopeIndex++)] = () => node;
1152
- } else if (value2 === 37 /* Replace */ || value2 === 49 /* DynamicTagWithVar */) {
1153
- walker.currentNode.replaceWith(
1154
- walker.currentNode = scope[true ? getDebugKey(currentScopeIndex++, "#text") : currentScopeIndex++] = new Text()
1155
- );
1156
- if (value2 === 49 /* DynamicTagWithVar */) {
1157
- scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : currentScopeIndex++] = skipScope(scope);
1158
- }
1159
- } else if (value2 === 38 /* EndChild */) {
1160
- return currentWalkIndex;
1161
- } else if (value2 === 47 /* BeginChild */ || value2 === 48 /* BeginChildWithVar */) {
1162
- currentWalkIndex = walkInternal(
1163
- currentWalkIndex,
1164
- walkCodes,
1165
- scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global, scope.___closestBranch)
1166
- );
1167
- if (value2 === 48 /* BeginChildWithVar */) {
1168
- scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : currentScopeIndex++] = skipScope(scope);
1169
- }
1170
- } else if (value2 < 91 /* NextEnd */ + 1) {
1171
- value2 = 20 /* Next */ * currentMultiplier + value2 - 67 /* Next */;
1172
- while (value2--) {
1173
- walker.nextNode();
1174
- }
1175
- } else if (value2 < 106 /* OverEnd */ + 1) {
1176
- value2 = 10 /* Over */ * currentMultiplier + value2 - 97 /* Over */;
1177
- while (value2--) {
1178
- walker.nextSibling();
1179
- }
1180
- } else if (value2 < 116 /* OutEnd */ + 1) {
1181
- value2 = 10 /* Out */ * currentMultiplier + value2 - 107 /* Out */;
1182
- while (value2--) {
1183
- walker.parentNode();
1184
- }
1185
- walker.nextSibling();
1186
- } else {
1187
- if (value2 < 117 /* Multiplier */ || value2 > 126 /* MultiplierEnd */) {
1188
- throw new Error(`Unknown walk code: ${value2}`);
1189
- }
1190
- storedMultiplier = currentMultiplier * 10 /* Multiplier */ + value2 - 117 /* Multiplier */;
1191
- }
1192
- }
1193
- }
1194
- function getDebugKey(index, node) {
1195
- if (typeof node === "string") {
1196
- return `${node}/${index}`;
1197
- } else if (node.nodeType === 3 /* Text */) {
1198
- return `#text/${index}`;
1199
- } else if (node.nodeType === 8 /* Comment */) {
1200
- return `#comment/${index}`;
1201
- } else if (node.nodeType === 1 /* Element */) {
1202
- return `#${node.tagName.toLowerCase()}/${index}`;
1203
- }
1204
- return index;
1205
- }
1206
-
1207
- // src/dom/renderer.ts
1208
- function createBranch($global, renderer, parentScope, parentNode) {
1209
- const branch = createScope($global);
1210
- const parentBranch = parentScope?.___closestBranch;
1211
- branch["_" /* Owner */] = renderer.___owner || parentScope;
1212
- branch.___closestBranch = branch;
1213
- if (parentBranch) {
1214
- branch.___parentBranch = parentBranch;
1215
- (parentBranch.___branchScopes ||= /* @__PURE__ */ new Set()).add(branch);
1216
- }
1217
- if (true) {
1218
- branch.___renderer = renderer;
1219
- }
1220
- renderer.___clone?.(
1221
- branch,
1222
- parentNode.namespaceURI
1223
- );
1224
- return branch;
1225
- }
1226
- function createAndSetupBranch($global, renderer, parentScope, parentNode) {
1227
- return setupBranch(
1228
- renderer,
1229
- createBranch($global, renderer, parentScope, parentNode)
1230
- );
1231
- }
1232
- function setupBranch(renderer, branch) {
1233
- if (renderer.___setup || renderer.___closures) {
1234
- queueRender(
1235
- branch,
1236
- (branch2) => {
1237
- renderer.___setup?.(branch2);
1238
- renderer.___closures?.(branch2);
1239
- },
1240
- -1
1241
- );
1242
- }
1243
- return branch;
1244
- }
1245
- function createContent(id, template, walks, setup, params, closures, dynamicScopesAccessor) {
1246
- walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
1247
- setup ||= void 0;
1248
- params ||= void 0;
1249
- closures = closures ? closures._ || closures : void 0;
1250
- const clone = template ? (branch, ns) => {
1251
- ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
1252
- template,
1253
- ns
1254
- ))(branch, walks);
1255
- } : (branch) => {
1256
- walk(
1257
- branch.___startNode = branch.___endNode = new Text(),
1258
- walks,
1259
- branch
1260
- );
1261
- };
1262
- return (owner) => {
1263
- return {
1264
- ___id: id,
1265
- ___clone: clone,
1266
- ___owner: owner,
1267
- ___setup: setup,
1268
- ___params: params,
1269
- ___closures: closures,
1270
- ___accessor: dynamicScopesAccessor
1271
- };
1272
- };
1273
- }
1274
- function registerContent(id, template, walks, setup, params, closures, dynamicScopesAccessor) {
1275
- return register(
1276
- id,
1277
- createContent(
1278
- id,
1279
- template,
1280
- walks,
1281
- setup,
1282
- params,
1283
- closures,
1284
- dynamicScopesAccessor
1285
- )
1286
- );
1287
- }
1288
- function createRenderer(template, walks, setup, params, closures) {
1289
- return createContent("", template, walks, setup, params, closures)();
1290
- }
1291
- var cloneCache = {};
1292
- function createCloneableHTML(html2, ns) {
1293
- const { firstChild, lastChild } = parseHTML(html2, ns);
1294
- const parent = document.createElementNS(ns, "t");
1295
- insertChildNodes(parent, null, firstChild, lastChild);
1296
- return firstChild === lastChild && firstChild.nodeType < 8 /* Comment */ ? (branch, walks) => {
1297
- walk(
1298
- branch.___startNode = branch.___endNode = firstChild.cloneNode(true),
1299
- walks,
1300
- branch
1301
- );
1302
- } : (branch, walks) => {
1303
- const clone = parent.cloneNode(true);
1304
- walk(clone.firstChild, walks, branch);
1305
- branch.___startNode = clone.firstChild;
1306
- branch.___endNode = clone.lastChild;
1307
- };
1308
- }
1309
-
1310
1133
  // src/dom/schedule.ts
1311
1134
  var runTask;
1312
1135
  var isScheduled;
@@ -1542,6 +1365,178 @@ function hoist(...path) {
1542
1365
  };
1543
1366
  }
1544
1367
 
1368
+ // src/dom/walker.ts
1369
+ var walker = /* @__PURE__ */ document.createTreeWalker(document);
1370
+ function walk(startNode, walkCodes, branch) {
1371
+ walker.currentNode = startNode;
1372
+ walkInternal(0, walkCodes, branch);
1373
+ }
1374
+ function walkInternal(currentWalkIndex, walkCodes, scope) {
1375
+ let value2;
1376
+ let storedMultiplier = 0;
1377
+ let currentMultiplier = 0;
1378
+ let currentScopeIndex = 0;
1379
+ for (; currentWalkIndex < walkCodes.length; ) {
1380
+ value2 = walkCodes.charCodeAt(currentWalkIndex++);
1381
+ currentMultiplier = storedMultiplier;
1382
+ storedMultiplier = 0;
1383
+ if (value2 === 32 /* Get */) {
1384
+ const node = walker.currentNode;
1385
+ scope[true ? getDebugKey(currentScopeIndex, walker.currentNode) : currentScopeIndex] = node;
1386
+ scope["Getter:" /* Getter */ + (true ? getDebugKey(currentScopeIndex++, walker.currentNode) : currentScopeIndex++)] = () => node;
1387
+ } else if (value2 === 37 /* Replace */ || value2 === 49 /* DynamicTagWithVar */) {
1388
+ walker.currentNode.replaceWith(
1389
+ walker.currentNode = scope[true ? getDebugKey(currentScopeIndex++, "#text") : currentScopeIndex++] = new Text()
1390
+ );
1391
+ if (value2 === 49 /* DynamicTagWithVar */) {
1392
+ scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : currentScopeIndex++] = skipScope(scope);
1393
+ }
1394
+ } else if (value2 === 38 /* EndChild */) {
1395
+ return currentWalkIndex;
1396
+ } else if (value2 === 47 /* BeginChild */ || value2 === 48 /* BeginChildWithVar */) {
1397
+ currentWalkIndex = walkInternal(
1398
+ currentWalkIndex,
1399
+ walkCodes,
1400
+ scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global, scope.___closestBranch)
1401
+ );
1402
+ if (value2 === 48 /* BeginChildWithVar */) {
1403
+ scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : currentScopeIndex++] = skipScope(scope);
1404
+ }
1405
+ } else if (value2 < 91 /* NextEnd */ + 1) {
1406
+ value2 = 20 /* Next */ * currentMultiplier + value2 - 67 /* Next */;
1407
+ while (value2--) {
1408
+ walker.nextNode();
1409
+ }
1410
+ } else if (value2 < 106 /* OverEnd */ + 1) {
1411
+ value2 = 10 /* Over */ * currentMultiplier + value2 - 97 /* Over */;
1412
+ while (value2--) {
1413
+ walker.nextSibling();
1414
+ }
1415
+ } else if (value2 < 116 /* OutEnd */ + 1) {
1416
+ value2 = 10 /* Out */ * currentMultiplier + value2 - 107 /* Out */;
1417
+ while (value2--) {
1418
+ walker.parentNode();
1419
+ }
1420
+ walker.nextSibling();
1421
+ } else {
1422
+ if (value2 < 117 /* Multiplier */ || value2 > 126 /* MultiplierEnd */) {
1423
+ throw new Error(`Unknown walk code: ${value2}`);
1424
+ }
1425
+ storedMultiplier = currentMultiplier * 10 /* Multiplier */ + value2 - 117 /* Multiplier */;
1426
+ }
1427
+ }
1428
+ }
1429
+ function getDebugKey(index, node) {
1430
+ if (typeof node === "string") {
1431
+ return `${node}/${index}`;
1432
+ } else if (node.nodeType === 3 /* Text */) {
1433
+ return `#text/${index}`;
1434
+ } else if (node.nodeType === 8 /* Comment */) {
1435
+ return `#comment/${index}`;
1436
+ } else if (node.nodeType === 1 /* Element */) {
1437
+ return `#${node.tagName.toLowerCase()}/${index}`;
1438
+ }
1439
+ return index;
1440
+ }
1441
+
1442
+ // src/dom/renderer.ts
1443
+ function createBranch($global, renderer, parentScope, parentNode) {
1444
+ const branch = createScope($global);
1445
+ const parentBranch = parentScope?.___closestBranch;
1446
+ branch["_" /* Owner */] = renderer.___owner || parentScope;
1447
+ branch.___closestBranch = branch;
1448
+ if (parentBranch) {
1449
+ branch.___parentBranch = parentBranch;
1450
+ (parentBranch.___branchScopes ||= /* @__PURE__ */ new Set()).add(branch);
1451
+ }
1452
+ if (true) {
1453
+ branch.___renderer = renderer;
1454
+ }
1455
+ renderer.___clone?.(
1456
+ branch,
1457
+ parentNode.namespaceURI
1458
+ );
1459
+ return branch;
1460
+ }
1461
+ function createAndSetupBranch($global, renderer, parentScope, parentNode) {
1462
+ return setupBranch(
1463
+ renderer,
1464
+ createBranch($global, renderer, parentScope, parentNode)
1465
+ );
1466
+ }
1467
+ function setupBranch(renderer, branch) {
1468
+ if (renderer.___setup) {
1469
+ queueRender(branch, renderer.___setup, -1);
1470
+ }
1471
+ return branch;
1472
+ }
1473
+ function createContent(id, template, walks, setup, params, dynamicScopesAccessor) {
1474
+ walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
1475
+ setup = setup ? setup._ || setup : void 0;
1476
+ params ||= void 0;
1477
+ const clone = template ? (branch, ns) => {
1478
+ ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
1479
+ template,
1480
+ ns
1481
+ ))(branch, walks);
1482
+ } : (branch) => {
1483
+ walk(
1484
+ branch.___startNode = branch.___endNode = new Text(),
1485
+ walks,
1486
+ branch
1487
+ );
1488
+ };
1489
+ return (owner) => {
1490
+ return {
1491
+ ___id: id,
1492
+ ___clone: clone,
1493
+ ___owner: owner,
1494
+ ___setup: setup,
1495
+ ___params: params,
1496
+ ___accessor: dynamicScopesAccessor
1497
+ };
1498
+ };
1499
+ }
1500
+ function registerContent(id, template, walks, setup, params, dynamicScopesAccessor) {
1501
+ return register(
1502
+ id,
1503
+ createContent(id, template, walks, setup, params, dynamicScopesAccessor)
1504
+ );
1505
+ }
1506
+ function localClosures(renderer, closureFns) {
1507
+ const closureSignals = {};
1508
+ for (const key in closureFns) {
1509
+ closureSignals[key] = value(key, closureFns[key]);
1510
+ }
1511
+ return (owner, closureValues) => {
1512
+ const instance = renderer(owner);
1513
+ instance.___localClosures = closureSignals;
1514
+ instance.___localClosureValues = closureValues;
1515
+ return instance;
1516
+ };
1517
+ }
1518
+ function createRenderer(template, walks, setup, params) {
1519
+ return createContent("", template, walks, setup, params)();
1520
+ }
1521
+ var cloneCache = {};
1522
+ function createCloneableHTML(html2, ns) {
1523
+ const { firstChild, lastChild } = parseHTML(html2, ns);
1524
+ const parent = document.createElementNS(ns, "t");
1525
+ insertChildNodes(parent, null, firstChild, lastChild);
1526
+ return firstChild === lastChild && firstChild.nodeType < 8 /* Comment */ ? (branch, walks) => {
1527
+ walk(
1528
+ branch.___startNode = branch.___endNode = firstChild.cloneNode(true),
1529
+ walks,
1530
+ branch
1531
+ );
1532
+ } : (branch, walks) => {
1533
+ const clone = parent.cloneNode(true);
1534
+ walk(clone.firstChild, walks, branch);
1535
+ branch.___startNode = clone.firstChild;
1536
+ branch.___endNode = clone.lastChild;
1537
+ };
1538
+ }
1539
+
1545
1540
  // src/dom/control-flow.ts
1546
1541
  function awaitTag(nodeAccessor, renderer) {
1547
1542
  const promiseAccessor = "Promise:" /* Promise */ + nodeAccessor;
@@ -1753,26 +1748,35 @@ var dynamicTag = function dynamicTag2(nodeAccessor, getContent, getTagVar, input
1753
1748
  }
1754
1749
  }
1755
1750
  if (normalizedRenderer) {
1751
+ const childScope = scope[childScopeAccessor];
1756
1752
  const args = getInput?.();
1757
1753
  if (typeof normalizedRenderer === "string") {
1758
1754
  attrs(
1759
- scope[childScopeAccessor],
1755
+ childScope,
1760
1756
  true ? `#${normalizedRenderer}/0` : 0,
1761
1757
  (inputIsArgs ? args[0] : args) || {}
1762
1758
  );
1763
- } else if (normalizedRenderer.___params) {
1764
- if (inputIsArgs) {
1765
- normalizedRenderer.___params(
1766
- scope[childScopeAccessor],
1767
- normalizedRenderer._ ? args[0] : args
1768
- );
1769
- } else {
1770
- const inputWithContent = getContent ? { ...args, content: getContent(scope) } : args || {};
1771
- normalizedRenderer.___params(
1772
- scope[childScopeAccessor],
1773
- normalizedRenderer._ ? inputWithContent : [inputWithContent]
1759
+ } else {
1760
+ for (const accessor in normalizedRenderer.___localClosures) {
1761
+ normalizedRenderer.___localClosures[accessor](
1762
+ childScope,
1763
+ normalizedRenderer.___localClosureValues[accessor]
1774
1764
  );
1775
1765
  }
1766
+ if (normalizedRenderer.___params) {
1767
+ if (inputIsArgs) {
1768
+ normalizedRenderer.___params(
1769
+ childScope,
1770
+ normalizedRenderer._ ? args[0] : args
1771
+ );
1772
+ } else {
1773
+ const inputWithContent = getContent ? { ...args, content: getContent(scope) } : args || {};
1774
+ normalizedRenderer.___params(
1775
+ childScope,
1776
+ normalizedRenderer._ ? inputWithContent : [inputWithContent]
1777
+ );
1778
+ }
1779
+ }
1776
1780
  }
1777
1781
  }
1778
1782
  };
@@ -2281,6 +2285,7 @@ export {
2281
2285
  init,
2282
2286
  intersection,
2283
2287
  lifecycle,
2288
+ localClosures,
2284
2289
  loopClosure,
2285
2290
  loopIn,
2286
2291
  loopOf,
@@ -1,25 +1,23 @@
1
1
  import { type Accessor, type BranchScope, type Scope } from "../common/types";
2
- import type { Signal } from "./signals";
2
+ import { type Signal, type SignalFn } from "./signals";
3
3
  export type Renderer = {
4
4
  ___id: string;
5
- ___setup: undefined | ((branch: BranchScope) => void);
5
+ ___setup: undefined | SetupFn;
6
6
  ___clone: (branch: BranchScope, ns: string) => void;
7
7
  ___params: Signal<unknown> | undefined;
8
- ___closures: SetupFn | undefined;
9
8
  ___owner: Scope | undefined;
10
9
  ___accessor: Accessor | undefined;
10
+ ___localClosures?: Record<Accessor, Signal<unknown>>;
11
+ ___localClosureValues?: Record<Accessor, unknown>;
11
12
  };
12
13
  type SetupFn = (scope: Scope) => void;
13
14
  export declare function createBranch($global: Scope["$global"], renderer: Renderer | string, parentScope: Scope | undefined, parentNode: ParentNode): BranchScope;
14
15
  export declare function createAndSetupBranch($global: Scope["$global"], renderer: Renderer, parentScope: Scope | undefined, parentNode: ParentNode): BranchScope;
15
16
  export declare function setupBranch(renderer: Renderer, branch: BranchScope): BranchScope;
16
- export declare function createContent(id: string, template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0, closures?: {
17
+ export declare function createContent(id: string, template: string | 0, walks?: string | 0, setup?: {
17
18
  _: Signal<unknown>;
18
- } | Signal<unknown> | 0, dynamicScopesAccessor?: Accessor): (owner?: Scope) => Renderer;
19
- export declare function registerContent(id: string, template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0, closures?: {
20
- _: Signal<unknown>;
21
- } | Signal<unknown> | 0, dynamicScopesAccessor?: Accessor): (owner?: Scope) => Renderer;
22
- export declare function createRenderer(template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0, closures?: {
23
- _: Signal<unknown>;
24
- } | Signal<unknown> | 0): Renderer;
19
+ } | SetupFn | 0, params?: Signal<unknown> | 0, dynamicScopesAccessor?: Accessor): (owner?: Scope) => Renderer;
20
+ export declare function registerContent(id: string, template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0, dynamicScopesAccessor?: Accessor): (owner?: Scope) => Renderer;
21
+ export declare function localClosures(renderer: ReturnType<typeof createContent>, closureFns: Record<Accessor, SignalFn<unknown>>): (owner: Scope, closureValues: Record<Accessor, unknown>) => Renderer;
22
+ export declare function createRenderer(template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0): Renderer;
25
23
  export {};
package/dist/dom.d.ts CHANGED
@@ -7,7 +7,7 @@ export { controllable_detailsOrDialog_open, controllable_detailsOrDialog_open_ef
7
7
  export { attr, attrs, attrsEvents, classAttr, classItem, classItems, data, html, lifecycle, partialAttrs, props, styleAttr, styleItem, styleItems, textContent, } from "./dom/dom";
8
8
  export { on } from "./dom/event";
9
9
  export { enableCatch, run } from "./dom/queue";
10
- export { createContent, createRenderer, registerContent } from "./dom/renderer";
10
+ export { createContent, createRenderer, localClosures, registerContent, } from "./dom/renderer";
11
11
  export { init, nodeRef, register, registerBoundSignal } from "./dom/resume";
12
12
  export { conditionalClosure, dynamicClosure, dynamicClosureRead, effect, hoist, intersection, loopClosure, nextTagId, setTagVar, setTagVarChange, state, tagVarSignal, tagVarSignalChange, value, } from "./dom/signals";
13
13
  export { createTemplate } from "./dom/template";