marko 6.0.0-next.3.58 → 6.0.0-next.3.59
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/dist/debug/dom.js +181 -188
- package/dist/debug/dom.mjs +181 -188
- package/dist/debug/html.js +0 -3
- package/dist/debug/html.mjs +0 -3
- package/dist/dom/resume.d.ts +1 -1
- package/dist/dom.js +153 -150
- package/dist/dom.mjs +153 -150
- package/dist/html.js +1 -1
- package/dist/html.mjs +1 -1
- package/package.json +1 -1
package/dist/debug/dom.js
CHANGED
@@ -243,168 +243,197 @@ var DEFAULT_RENDER_ID = "_";
|
|
243
243
|
|
244
244
|
// src/dom/resume.ts
|
245
245
|
var registeredValues = {};
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
constructor(renders, runtimeId, renderId) {
|
253
|
-
Object.assign(this, renders[renderId]);
|
254
|
-
this.___renders = renders;
|
255
|
-
this.___runtimeId = runtimeId;
|
256
|
-
this.___renderId = renderId;
|
257
|
-
this.___walk = this.w;
|
258
|
-
this.___resume();
|
259
|
-
this.w = () => {
|
260
|
-
this.___walk();
|
261
|
-
this.___resume();
|
262
|
-
};
|
263
|
-
}
|
264
|
-
___resume() {
|
265
|
-
const serializeContext = this.___serializeContext;
|
266
|
-
const scopeLookup = this.___scopeLookup;
|
267
|
-
const visits = this.v;
|
268
|
-
const branchIds = /* @__PURE__ */ new Set();
|
269
|
-
const parentBranchIds = /* @__PURE__ */ new Map();
|
270
|
-
if (visits.length) {
|
271
|
-
const commentPrefix = this.i;
|
272
|
-
const commentPrefixLen = commentPrefix.length;
|
273
|
-
const closestBranchMarkers = /* @__PURE__ */ new Map();
|
274
|
-
const visitNodes = new Set(visits);
|
275
|
-
let lastEndNode;
|
276
|
-
this.v = [];
|
277
|
-
const branchEnd = (branchId, visit, reference) => {
|
278
|
-
const branch = scopeLookup[branchId] ||= {};
|
279
|
-
let endNode = reference;
|
280
|
-
while (visitNodes.has(endNode = endNode.previousSibling)) ;
|
281
|
-
if (endNode === lastEndNode) {
|
282
|
-
endNode = reference.parentNode.insertBefore(new Text(), reference);
|
283
|
-
}
|
284
|
-
branch.___endNode = lastEndNode = endNode;
|
285
|
-
branch.___startNode ||= endNode;
|
286
|
-
for (const [markerScopeId, markerNode] of closestBranchMarkers) {
|
287
|
-
if (branch.___startNode.compareDocumentPosition(markerNode) & 4 && reference.compareDocumentPosition(markerNode) & 2) {
|
288
|
-
parentBranchIds.set(markerScopeId, branchId);
|
289
|
-
closestBranchMarkers.delete(markerScopeId);
|
290
|
-
}
|
291
|
-
}
|
292
|
-
branchIds.add(branchId);
|
293
|
-
closestBranchMarkers.set(branchId, visit);
|
294
|
-
return branch;
|
295
|
-
};
|
296
|
-
for (const visit of visits) {
|
297
|
-
const commentText = visit.data;
|
298
|
-
const dataIndex = commentText.indexOf(" ") + 1;
|
299
|
-
const scopeId = commentText.slice(
|
300
|
-
commentPrefixLen + 1,
|
301
|
-
dataIndex ? dataIndex - 1 : commentText.length
|
302
|
-
);
|
303
|
-
const scope = scopeLookup[scopeId] ||= { ___id: +scopeId };
|
304
|
-
const data2 = dataIndex ? commentText.slice(dataIndex) : "";
|
305
|
-
const token = commentText[commentPrefixLen];
|
306
|
-
if (token === "*" /* Node */) {
|
307
|
-
const node = scope[data2] = visit.previousSibling;
|
308
|
-
scope[data2 + ">" /* Getter */] = () => node;
|
309
|
-
} else if (token === "$" /* ClosestBranch */) {
|
310
|
-
closestBranchMarkers.set(scopeId, visit);
|
311
|
-
} else if (token === "[" /* BranchStart */) {
|
312
|
-
if (this.___currentScopeId) {
|
313
|
-
if (dataIndex) {
|
314
|
-
branchEnd(this.___currentScopeId, visit, visit);
|
315
|
-
}
|
316
|
-
this.___scopeStack.push(this.___currentScopeId);
|
317
|
-
}
|
318
|
-
this.___currentScopeId = scopeId;
|
319
|
-
scope.___startNode = visit;
|
320
|
-
} else if (token === "]" /* BranchEnd */) {
|
321
|
-
scope[data2] = visit;
|
322
|
-
const curParent = visit.parentNode;
|
323
|
-
const startNode = branchEnd(
|
324
|
-
this.___currentScopeId,
|
325
|
-
visit,
|
326
|
-
visit
|
327
|
-
).___startNode;
|
328
|
-
if (curParent !== startNode.parentNode) {
|
329
|
-
curParent.prepend(startNode);
|
330
|
-
}
|
331
|
-
this.___currentScopeId = this.___scopeStack.pop();
|
332
|
-
} else if (token === "|" /* BranchSingleNode */ || token === "=" /* BranchSingleNodeOnlyChildInParent */) {
|
333
|
-
let next = data2.indexOf(" ");
|
334
|
-
let curNode = visit;
|
335
|
-
scope[~next ? data2.slice(0, next) : data2] = token === "=" /* BranchSingleNodeOnlyChildInParent */ ? visit.parentNode : visit;
|
336
|
-
while (~next) {
|
337
|
-
const start = next + 1;
|
338
|
-
next = data2.indexOf(" ", start);
|
339
|
-
const childScopeId = data2.slice(start, ~next ? next : data2.length);
|
340
|
-
curNode = branchEnd(childScopeId, visit, curNode).___endNode;
|
341
|
-
}
|
342
|
-
}
|
343
|
-
}
|
246
|
+
function init(runtimeId = DEFAULT_RUNTIME_ID) {
|
247
|
+
if (true) {
|
248
|
+
if (!runtimeId.match(/^[_$a-z][_$a-z0-9]*$/i)) {
|
249
|
+
throw new Error(
|
250
|
+
`Invalid runtimeId: "${runtimeId}". The runtimeId must be a valid JavaScript identifier.`
|
251
|
+
);
|
344
252
|
}
|
345
|
-
const
|
346
|
-
if (
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
253
|
+
const descriptor = Object.getOwnPropertyDescriptor(window, runtimeId);
|
254
|
+
if (descriptor && (descriptor.set || descriptor.configurable === false)) {
|
255
|
+
throw new Error(
|
256
|
+
`Marko initialized multiple times with the same $global.runtimeId of ${JSON.stringify(runtimeId)}. It could be that there are multiple copies of Marko running on the page.`
|
257
|
+
);
|
258
|
+
}
|
259
|
+
}
|
260
|
+
const renders = window[runtimeId];
|
261
|
+
const defineRuntime = (desc) => Object.defineProperty(window, runtimeId, desc);
|
262
|
+
let resumeRender;
|
263
|
+
const initRuntime = (renders2) => {
|
264
|
+
defineRuntime({
|
265
|
+
value: resumeRender = (renderId) => {
|
266
|
+
const render = resumeRender[renderId] = renders2[renderId] || renders2(renderId);
|
267
|
+
const walk2 = render.w;
|
268
|
+
const commentPrefixLen = render.i.length;
|
269
|
+
const scopeStack = [];
|
270
|
+
const scopeLookup = render.s = {};
|
271
|
+
const serializeContext = {
|
272
|
+
_: registeredValues
|
273
|
+
};
|
274
|
+
const branchIds = /* @__PURE__ */ new Set();
|
275
|
+
const parentBranchIds = /* @__PURE__ */ new Map();
|
276
|
+
const closestBranchMarkers = /* @__PURE__ */ new Map();
|
277
|
+
let currentScopeId;
|
278
|
+
render.w = () => {
|
279
|
+
walk2.call(render);
|
280
|
+
const visits = render.v;
|
281
|
+
const resumes = render.r;
|
282
|
+
if (visits.length) {
|
283
|
+
const visitNodes = new Set(visits);
|
284
|
+
let lastEndNode;
|
285
|
+
render.v = [];
|
286
|
+
const branchEnd = (branchId, visit, reference) => {
|
287
|
+
const branch = scopeLookup[branchId] ||= {};
|
288
|
+
let endNode = reference;
|
289
|
+
while (visitNodes.has(endNode = endNode.previousSibling)) ;
|
290
|
+
if (endNode === lastEndNode) {
|
291
|
+
endNode = reference.parentNode.insertBefore(
|
292
|
+
new Text(),
|
293
|
+
reference
|
294
|
+
);
|
295
|
+
}
|
296
|
+
branch.___endNode = lastEndNode = endNode;
|
297
|
+
branch.___startNode ||= endNode;
|
298
|
+
for (const [markerScopeId, markerNode] of closestBranchMarkers) {
|
299
|
+
if (branch.___startNode.compareDocumentPosition(markerNode) & 4 && reference.compareDocumentPosition(markerNode) & 2) {
|
300
|
+
parentBranchIds.set(markerScopeId, branchId);
|
301
|
+
closestBranchMarkers.delete(markerScopeId);
|
378
302
|
}
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
303
|
+
}
|
304
|
+
branchIds.add(branchId);
|
305
|
+
closestBranchMarkers.set(branchId, visit);
|
306
|
+
return branch;
|
307
|
+
};
|
308
|
+
for (const visit of visits) {
|
309
|
+
const commentText = visit.data;
|
310
|
+
const dataIndex = commentText.indexOf(" ") + 1;
|
311
|
+
const scopeId = commentText.slice(
|
312
|
+
commentPrefixLen + 1,
|
313
|
+
dataIndex ? dataIndex - 1 : commentText.length
|
314
|
+
);
|
315
|
+
const scope = scopeLookup[scopeId] ||= {
|
316
|
+
___id: +scopeId
|
317
|
+
};
|
318
|
+
const data2 = dataIndex ? commentText.slice(dataIndex) : "";
|
319
|
+
const token = commentText[commentPrefixLen];
|
320
|
+
if (token === "*" /* Node */) {
|
321
|
+
const node = scope[data2] = visit.previousSibling;
|
322
|
+
scope[data2 + ">" /* Getter */] = () => node;
|
323
|
+
} else if (token === "$" /* ClosestBranch */) {
|
324
|
+
closestBranchMarkers.set(scopeId, visit);
|
325
|
+
} else if (token === "[" /* BranchStart */) {
|
326
|
+
if (currentScopeId) {
|
327
|
+
if (dataIndex) {
|
328
|
+
branchEnd(currentScopeId, visit, visit);
|
386
329
|
}
|
330
|
+
scopeStack.push(currentScopeId);
|
387
331
|
}
|
388
|
-
|
389
|
-
|
332
|
+
currentScopeId = scopeId;
|
333
|
+
scope.___startNode = visit;
|
334
|
+
} else if (token === "]" /* BranchEnd */) {
|
335
|
+
scope[data2] = visit;
|
336
|
+
const curParent = visit.parentNode;
|
337
|
+
const startNode = branchEnd(
|
338
|
+
currentScopeId,
|
339
|
+
visit,
|
340
|
+
visit
|
341
|
+
).___startNode;
|
342
|
+
if (curParent !== startNode.parentNode) {
|
343
|
+
curParent.prepend(startNode);
|
344
|
+
}
|
345
|
+
currentScopeId = scopeStack.pop();
|
346
|
+
} else if (token === "|" /* BranchSingleNode */ || token === "=" /* BranchSingleNodeOnlyChildInParent */) {
|
347
|
+
let next = data2.indexOf(" ");
|
348
|
+
let curNode = visit;
|
349
|
+
scope[~next ? data2.slice(0, next) : data2] = token === "=" /* BranchSingleNodeOnlyChildInParent */ ? visit.parentNode : visit;
|
350
|
+
while (~next) {
|
351
|
+
const start = next + 1;
|
352
|
+
next = data2.indexOf(" ", start);
|
353
|
+
const childScopeId = data2.slice(
|
354
|
+
start,
|
355
|
+
~next ? next : data2.length
|
356
|
+
);
|
357
|
+
curNode = branchEnd(childScopeId, visit, curNode).___endNode;
|
390
358
|
}
|
391
359
|
}
|
392
360
|
}
|
393
|
-
} else if (i === len || typeof resumes[i] !== "string") {
|
394
|
-
delete this.___renders[this.___renderId];
|
395
|
-
} else {
|
396
|
-
registeredValues[resumes[i++]](
|
397
|
-
scopeLookup[resumeData],
|
398
|
-
scopeLookup[resumeData]
|
399
|
-
);
|
400
361
|
}
|
401
|
-
|
402
|
-
|
403
|
-
|
362
|
+
if (resumes) {
|
363
|
+
try {
|
364
|
+
render.r = [];
|
365
|
+
isResuming = true;
|
366
|
+
for (let i = 0; i < resumes.length; i++) {
|
367
|
+
const serialized = resumes[i];
|
368
|
+
if (typeof serialized === "function") {
|
369
|
+
const scopes = serialized(serializeContext);
|
370
|
+
let { $global } = scopeLookup;
|
371
|
+
if (!$global) {
|
372
|
+
scopeLookup.$global = $global = scopes.$ || {};
|
373
|
+
$global.runtimeId = runtimeId;
|
374
|
+
$global.renderId = renderId;
|
375
|
+
$global.___nextScopeId = 1e6;
|
376
|
+
}
|
377
|
+
for (const scopeId in scopes) {
|
378
|
+
if (scopeId !== "$") {
|
379
|
+
const scope = scopes[scopeId];
|
380
|
+
const prevScope = scopeLookup[scopeId];
|
381
|
+
scope.$global = $global;
|
382
|
+
scope.___id = +scopeId;
|
383
|
+
if (prevScope !== scope) {
|
384
|
+
scopeLookup[scopeId] = Object.assign(
|
385
|
+
scope,
|
386
|
+
prevScope
|
387
|
+
);
|
388
|
+
}
|
389
|
+
const parentBranchId = parentBranchIds.get(scopeId);
|
390
|
+
if (parentBranchId) {
|
391
|
+
scope.___closestBranch = scopes[parentBranchId];
|
392
|
+
}
|
393
|
+
if (branchIds.has(scopeId)) {
|
394
|
+
const branch = scope;
|
395
|
+
const parentBranch = branch.___closestBranch;
|
396
|
+
scope.___closestBranch = branch;
|
397
|
+
if (parentBranch) {
|
398
|
+
branch.___parentBranch = parentBranch;
|
399
|
+
(parentBranch.___branchScopes ||= /* @__PURE__ */ new Set()).add(
|
400
|
+
branch
|
401
|
+
);
|
402
|
+
}
|
403
|
+
}
|
404
|
+
if (true) {
|
405
|
+
scope.___debugId = "server-" + scopeId;
|
406
|
+
}
|
407
|
+
}
|
408
|
+
}
|
409
|
+
} else {
|
410
|
+
registeredValues[resumes[++i]](
|
411
|
+
scopeLookup[serialized],
|
412
|
+
scopeLookup[serialized]
|
413
|
+
);
|
414
|
+
}
|
415
|
+
}
|
416
|
+
} finally {
|
417
|
+
isResuming = false;
|
418
|
+
}
|
419
|
+
}
|
420
|
+
};
|
421
|
+
return render;
|
404
422
|
}
|
423
|
+
});
|
424
|
+
};
|
425
|
+
if (renders) {
|
426
|
+
initRuntime(renders);
|
427
|
+
for (const renderId in renders) {
|
428
|
+
resumeRender(renderId).w();
|
405
429
|
}
|
430
|
+
} else {
|
431
|
+
defineRuntime({
|
432
|
+
configurable: true,
|
433
|
+
set: initRuntime
|
434
|
+
});
|
406
435
|
}
|
407
|
-
}
|
436
|
+
}
|
408
437
|
var isResuming = false;
|
409
438
|
function register(id, obj) {
|
410
439
|
registeredValues[id] = obj;
|
@@ -418,42 +447,6 @@ function getRegisteredWithScope(id, scope) {
|
|
418
447
|
const val = registeredValues[id];
|
419
448
|
return scope ? val(scope) : val;
|
420
449
|
}
|
421
|
-
function init(runtimeId = DEFAULT_RUNTIME_ID) {
|
422
|
-
if (true) {
|
423
|
-
if (!runtimeId.match(/^[_$a-z][_$a-z0-9]*$/i)) {
|
424
|
-
throw new Error(
|
425
|
-
`Invalid runtimeId: "${runtimeId}". The runtimeId must be a valid JavaScript identifier.`
|
426
|
-
);
|
427
|
-
}
|
428
|
-
}
|
429
|
-
const resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId);
|
430
|
-
let renders;
|
431
|
-
if (window[runtimeId]) {
|
432
|
-
setRenders(window[runtimeId]);
|
433
|
-
} else {
|
434
|
-
Object.defineProperty(window, runtimeId, {
|
435
|
-
configurable: true,
|
436
|
-
set: setRenders
|
437
|
-
});
|
438
|
-
}
|
439
|
-
function setRenders(v) {
|
440
|
-
if (true) {
|
441
|
-
if (renders) {
|
442
|
-
throw new Error(
|
443
|
-
"Marko tried to initialize multiple times. It could be that there are multiple instances of Marko running on the page."
|
444
|
-
);
|
445
|
-
}
|
446
|
-
}
|
447
|
-
renders = v;
|
448
|
-
for (const renderId in v) {
|
449
|
-
resumeRender(renderId);
|
450
|
-
}
|
451
|
-
Object.defineProperty(window, runtimeId, {
|
452
|
-
configurable: true,
|
453
|
-
value: resumeRender
|
454
|
-
});
|
455
|
-
}
|
456
|
-
}
|
457
450
|
function nodeRef(id, key) {
|
458
451
|
return register(id, (scope) => () => scope[key]());
|
459
452
|
}
|
@@ -1973,7 +1966,7 @@ var compat = {
|
|
1973
1966
|
if (Array.isArray(value2) && typeof value2[0] === "string") {
|
1974
1967
|
return getRegisteredWithScope(
|
1975
1968
|
value2[0],
|
1976
|
-
value2.length === 2 && window[runtimeId]?.[componentIdPrefix === "s" ? "_" : componentIdPrefix]?.
|
1969
|
+
value2.length === 2 && window[runtimeId]?.[componentIdPrefix === "s" ? "_" : componentIdPrefix]?.s[value2[1]]
|
1977
1970
|
);
|
1978
1971
|
}
|
1979
1972
|
return value2;
|