marko 6.1.2 → 6.1.4
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/common/accessor.d.ts +5 -0
- package/dist/common/accessor.debug.d.ts +5 -0
- package/dist/common/compat-meta.d.ts +0 -1
- package/dist/common/opt.d.ts +3 -1
- package/dist/common/types.d.ts +1 -1
- package/dist/debug/dom.js +315 -122
- package/dist/debug/dom.mjs +306 -123
- package/dist/debug/html.js +922 -712
- package/dist/debug/html.mjs +920 -713
- package/dist/dom/compat.d.ts +3 -2
- package/dist/dom/control-flow.d.ts +2 -1
- package/dist/dom/load.d.ts +23 -0
- package/dist/dom/queue.d.ts +4 -2
- package/dist/dom/resume.d.ts +10 -8
- package/dist/dom/signals.d.ts +4 -3
- package/dist/dom.d.ts +3 -2
- package/dist/dom.js +195 -66
- package/dist/dom.mjs +195 -66
- package/dist/html/assets.d.ts +47 -0
- package/dist/html/compat.d.ts +3 -2
- package/dist/html/inlined-runtimes.d.ts +1 -1
- package/dist/html/inlined-runtimes.debug.d.ts +1 -1
- package/dist/html/serializer.d.ts +14 -9
- package/dist/html/writer.d.ts +34 -15
- package/dist/html.d.ts +1 -0
- package/dist/html.js +502 -345
- package/dist/html.mjs +502 -345
- package/dist/translator/index.d.ts +1 -0
- package/dist/translator/index.js +342 -76
- package/dist/translator/interop/index.d.ts +1 -0
- package/dist/translator/util/marko-config.d.ts +2 -0
- package/dist/translator/util/references.d.ts +1 -5
- package/dist/translator/util/runtime.d.ts +1 -0
- package/dist/translator/util/tag-name-type.d.ts +2 -0
- package/dist/translator/util/walks.d.ts +1 -1
- package/dist/translator/visitors/import-declaration.d.ts +10 -1
- package/dist/translator/visitors/tag/custom-tag.d.ts +7 -0
- package/package.json +2 -2
package/dist/dom.mjs
CHANGED
|
@@ -20,10 +20,7 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
|
|
|
20
20
|
for (value = 10 * currentMultiplier + value - 107; value--;) walker.parentNode();
|
|
21
21
|
walker.nextSibling();
|
|
22
22
|
} else storedMultiplier = currentMultiplier * 10 + value - 117;
|
|
23
|
-
}, cloneCache = {}, registeredValues = {},
|
|
24
|
-
let cb = readyLookup[id];
|
|
25
|
-
readyLookup[id] = 1, cb?.();
|
|
26
|
-
})(readyLookup = {}), isResuming, inputType = "", controllableDelegate = /* @__PURE__ */ createDelegator(), _dynamic_tag = function(nodeAccessor, getContent, getTagVar, inputIsArgs) {
|
|
23
|
+
}, cloneCache = {}, registeredValues = {}, curRenders, branchesEnabled, embedRenders, readyIds, isResuming, inputType = "", controllableDelegate = /* @__PURE__ */ createDelegator(), _dynamic_tag = function(nodeAccessor, getContent, getTagVar, inputIsArgs) {
|
|
27
24
|
nodeAccessor = decodeAccessor(nodeAccessor);
|
|
28
25
|
let childScopeAccessor = "A" + nodeAccessor, rendererAccessor = "D" + nodeAccessor;
|
|
29
26
|
return enableBranches(), (scope, newRenderer, getInput) => {
|
|
@@ -54,16 +51,22 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
|
|
|
54
51
|
typeof by == "string" ? forOf(all, (item, i) => cb(item[by], [item, i])) : forOf(all, (item, i) => cb(by(item, i), [item, i]));
|
|
55
52
|
}), _for_in = /* @__PURE__ */ loop(([obj, by = byFirstArg], cb) => forIn(obj, (key, value) => cb(by(key, value), [key, value]))), _for_to = /* @__PURE__ */ loop(([to, from, step, by = byFirstArg], cb) => forTo(to, from, step, (v) => cb(by(v), [v]))), _for_until = /* @__PURE__ */ loop(([until, from, step, by = byFirstArg], cb) => forUntil(until, from, step, (v) => cb(by(v), [v]))), pendingRenders = [], pendingRendersLookup = {}, asyncRendersLookup, caughtError = /* @__PURE__ */ new WeakSet(), placeholderShown = /* @__PURE__ */ new WeakSet(), pendingEffects = [], pendingScopes = [], rendering, runEffects = ((effects) => {
|
|
56
53
|
for (let i = 0; i < effects.length;) effects[i++](effects[i++]);
|
|
57
|
-
}), runRender = (render) => render.c(render.b, render.d), catchEnabled, classIdToBranch = /* @__PURE__ */ new Map(),
|
|
54
|
+
}), runRender = (render) => render.c(render.b, render.d), catchEnabled, classIdToBranch = /* @__PURE__ */ new Map(), scopesByRender = /* @__PURE__ */ new WeakMap(), getRenderScopes = ($global) => {
|
|
55
|
+
let render = self[$global.runtimeId]?.[$global.renderId], scopes = render && scopesByRender.get(render);
|
|
56
|
+
return render && !scopes && scopesByRender.set(render, scopes = {}), scopes;
|
|
57
|
+
}, compat = {
|
|
58
58
|
patchDynamicTag,
|
|
59
59
|
queueEffect,
|
|
60
60
|
init(warp10Noop) {
|
|
61
|
-
_resume("$C_s", (
|
|
62
|
-
classIdToBranch.set(
|
|
61
|
+
_resume("$C_s", (scope) => {
|
|
62
|
+
getRenderScopes(scope.$)[scope.L] = scope, scope.m5c && classIdToBranch.set(scope.m5c, scope);
|
|
63
63
|
}), _resume("$C_b", warp10Noop);
|
|
64
64
|
},
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
getScope($global, scopeId) {
|
|
66
|
+
return getRenderScopes($global)?.[scopeId];
|
|
67
|
+
},
|
|
68
|
+
setRendererId(renderer, id) {
|
|
69
|
+
renderer.a = id;
|
|
67
70
|
},
|
|
68
71
|
isRenderer(renderer) {
|
|
69
72
|
return renderer.b;
|
|
@@ -81,7 +84,7 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
|
|
|
81
84
|
this.scope && destroyBranch(this.scope);
|
|
82
85
|
},
|
|
83
86
|
resolveRegistered(value, $global) {
|
|
84
|
-
return Array.isArray(value) && typeof value[0] == "string" ? getRegisteredWithScope(value[0],
|
|
87
|
+
return Array.isArray(value) && typeof value[0] == "string" ? getRegisteredWithScope(value[0], getRenderScopes($global)?.[value[1]]) : value;
|
|
85
88
|
},
|
|
86
89
|
createRenderer(params, clone) {
|
|
87
90
|
let renderer = _content("", 0, 0, 0, params)();
|
|
@@ -248,7 +251,7 @@ function schedule() {
|
|
|
248
251
|
isScheduled || (isScheduled = 1, queueMicrotask(flushAndWaitFrame));
|
|
249
252
|
}
|
|
250
253
|
function flushAndWaitFrame() {
|
|
251
|
-
|
|
254
|
+
requestAnimationFrame(triggerMacroTask), run();
|
|
252
255
|
}
|
|
253
256
|
function triggerMacroTask() {
|
|
254
257
|
channel || (channel = new MessageChannel(), channel.port1.onmessage = () => {
|
|
@@ -258,13 +261,17 @@ function triggerMacroTask() {
|
|
|
258
261
|
//#endregion
|
|
259
262
|
//#region src/dom/signals.ts
|
|
260
263
|
function _let(id, fn) {
|
|
261
|
-
let valueAccessor = decodeAccessor(id)
|
|
262
|
-
return (scope, value
|
|
264
|
+
let valueAccessor = decodeAccessor(id);
|
|
265
|
+
return (scope, value) => (rendering ? scope.H && (scope[valueAccessor] = value, fn?.(scope)) : (scope[valueAccessor] !== value || !(valueAccessor in scope)) && (scope[valueAccessor] = value, fn) && (schedule(), queueRender(scope, fn, id)), value);
|
|
266
|
+
}
|
|
267
|
+
function _let_change(id, fn) {
|
|
268
|
+
let valueAccessor = decodeAccessor(id), valueChangeAccessor = "M" + valueAccessor, base = _let(id, fn);
|
|
269
|
+
return (scope, value, valueChange) => (rendering ? (scope[valueChangeAccessor] = valueChange) && (scope[valueAccessor] !== value || !(valueAccessor in scope)) ? (scope[valueAccessor] = value, fn?.(scope)) : base(scope, value) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](value) : base(scope, value), value);
|
|
263
270
|
}
|
|
264
271
|
function _const(valueAccessor, fn) {
|
|
265
|
-
return valueAccessor = decodeAccessor(valueAccessor), (scope, value) => {
|
|
266
|
-
(scope
|
|
267
|
-
};
|
|
272
|
+
return valueAccessor = decodeAccessor(valueAccessor), ((scope, value) => {
|
|
273
|
+
(scope[valueAccessor] !== value || !(valueAccessor in scope)) && (scope[valueAccessor] = value, fn?.(scope));
|
|
274
|
+
});
|
|
268
275
|
}
|
|
269
276
|
function _or(id, fn, defaultPending = 1, scopeIdAccessor = "L") {
|
|
270
277
|
return scopeIdAccessor !== "L" && (scopeIdAccessor = decodeAccessor(scopeIdAccessor)), (scope) => {
|
|
@@ -405,29 +412,37 @@ function createCloneableHTML(html, ns) {
|
|
|
405
412
|
//#endregion
|
|
406
413
|
//#region src/dom/resume.ts
|
|
407
414
|
function enableBranches() {
|
|
408
|
-
branchesEnabled = 1;
|
|
415
|
+
branchesEnabled || (branchesEnabled = 1, skipDestroyedRenders());
|
|
416
|
+
}
|
|
417
|
+
function ready(readyId, runtimeId) {
|
|
418
|
+
(readyIds ||= /* @__PURE__ */ new Set()).add(readyId), init(runtimeId);
|
|
419
|
+
for (let renderId in curRenders) runResumeEffects(curRenders[renderId]);
|
|
409
420
|
}
|
|
410
421
|
function initEmbedded(readyId, runtimeId) {
|
|
411
|
-
|
|
412
|
-
let
|
|
413
|
-
|
|
414
|
-
let
|
|
415
|
-
if (n && !n.isConnected) {
|
|
416
|
-
delete renders[renderId];
|
|
417
|
-
for (let id in s) destroyScope(s[id]);
|
|
418
|
-
}
|
|
422
|
+
embedRenders || (embedRenders = /* @__PURE__ */ new Map(), new MutationObserver(() => {
|
|
423
|
+
for (let [anchor, [renderId, scopes]] of embedRenders) if (!anchor.isConnected) {
|
|
424
|
+
embedRenders.delete(anchor), delete curRenders[renderId];
|
|
425
|
+
for (let id in scopes) destroyScope(scopes[id]);
|
|
419
426
|
}
|
|
420
|
-
}).observe(document
|
|
427
|
+
}).observe(document, {
|
|
421
428
|
childList: !0,
|
|
422
429
|
subtree: !0
|
|
423
|
-
});
|
|
430
|
+
})), ready(readyId, runtimeId);
|
|
424
431
|
}
|
|
425
432
|
function init(runtimeId = "M") {
|
|
426
|
-
if (
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
433
|
+
if (curRenders) return;
|
|
434
|
+
let renders = self[runtimeId], defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc), initRuntime = (renders) => {
|
|
435
|
+
defineRuntime({ value: curRenders = ((renderId) => {
|
|
436
|
+
let render = curRenders[renderId] = renders[renderId] || renders(renderId), walk = render.w, scopeLookup = {}, getScope = (id) => scopeLookup[id] || initScope(scopeLookup[id] = { L: +id }), initGlobal = () => $global ||= {
|
|
437
|
+
runtimeId,
|
|
438
|
+
renderId
|
|
439
|
+
}, initScope = (scope) => (scope.$ = initGlobal(), branchesEnabled && scope.G && (scope.F = getScope(scope.G)), scope), applyScopes = (partials) => {
|
|
440
|
+
let scopeId = partials[0];
|
|
441
|
+
for (let i = 1; i < partials.length; i++) {
|
|
442
|
+
let partial = partials[i];
|
|
443
|
+
typeof partial == "number" ? scopeId += partial : (scopeId ? initScope(Object.assign(scopeLookup[scopeId] ||= (partial.L = scopeId, partial), partial)) : Object.assign(initGlobal(), partial), scopeId++);
|
|
444
|
+
}
|
|
445
|
+
}, serializeContext = ((data, registryId) => typeof data == "number" ? registryId ? registeredValues[registryId](getScope(data)) : getScope(data) : applyScopes(data)), createVisitBranches = (branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
|
|
431
446
|
for (visitType !== "[" && (visitScope[nextToken()] = visitType === ")" || visitType === "}" ? parent : visit, accessor = "A" + lastToken, singleNode = visitType !== "]" && visitType !== ")", nextToken()); branchId = +lastToken;) {
|
|
432
447
|
if ((endedBranches ||= []).push(branch = getScope(branchId)), setParentBranch(branch, branch.F), (branch.O = render.p?.[branchId]) && (branch.O.m = render.m), singleNode) {
|
|
433
448
|
for (; startVisit.previousSibling && ~visits.indexOf(startVisit = startVisit.previousSibling););
|
|
@@ -436,22 +451,40 @@ function init(runtimeId = "M") {
|
|
|
436
451
|
for (; i && orphanBranches[--i].L > branchId;) setParentBranch(orphanBranches.pop(), branch);
|
|
437
452
|
nextToken();
|
|
438
453
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
454
|
+
if (endedBranches) {
|
|
455
|
+
for (let ended of endedBranches) orphanBranches.push(ended);
|
|
456
|
+
singleNode && (visitScope[accessor] = endedBranches.length > 1 ? endedBranches.reverse() : endedBranches[0]);
|
|
457
|
+
}
|
|
458
|
+
visitType === "[" && (endedBranches || (branchScopesStack.push(curBranchScopes), curBranchScopes = void 0), branchStarts.push(visit));
|
|
459
|
+
}, nextToken = () => lastToken = visitText.slice(lastTokenIndex, (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1), processResumes = (resumes = [], effects) => {
|
|
460
|
+
let i = 0;
|
|
461
|
+
for (; i < resumes.length; i++) {
|
|
462
|
+
let serialized = resumes[i];
|
|
463
|
+
if (typeof serialized == "string") for (lastTokenIndex = 0, visitText = serialized; nextToken();) /\D/.test(lastToken) ? lastEffect = registeredValues[lastToken] : effects.push(lastEffect, getScope(lastToken));
|
|
464
|
+
else if (Array.isArray(serialized)) {
|
|
465
|
+
if (!(readyIds && serialized.every((dep) => readyIds.has(dep) && !render.b[dep].length))) break;
|
|
466
|
+
} else if (readyIds && typeof serialized == "number") break;
|
|
467
|
+
else {
|
|
468
|
+
let scopes = serialized(serializeContext);
|
|
469
|
+
Array.isArray(scopes) && applyScopes(scopes);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return resumes.splice(0, i), i;
|
|
473
|
+
}, $global, lastEffect, visits, visit, visitText, visitType, visitScope, lastToken, lastTokenIndex, visitBranches, embedAnchor;
|
|
474
|
+
return serializeContext._ = registeredValues, render.m = (effects) => {
|
|
475
|
+
if (processResumes(render.r, effects), readyIds && render.b) for (let progress = 1; progress;) {
|
|
476
|
+
progress = 0;
|
|
477
|
+
for (let readyId of readyIds) {
|
|
478
|
+
let resumes = render.b[readyId];
|
|
479
|
+
resumes && processResumes(resumes, effects) && (progress = 1);
|
|
480
|
+
}
|
|
447
481
|
}
|
|
448
|
-
|
|
449
|
-
else for (let scope of serialized(serializeContext)) $global ? typeof scope == "number" ? lastScopeId += scope : (scopeLookup[scope.L = ++lastScopeId] = scope, scope.$ = $global, branchesEnabled && (scope.F = getScope(scope.G))) : ($global = scope || {}, $global.runtimeId = runtimeId, $global.renderId = renderId);
|
|
482
|
+
let retained = 0;
|
|
450
483
|
for (visit of visits = render.v) if (lastTokenIndex = render.i.length, visitText = visit.data, visitType = visitText[lastTokenIndex++], visitScope = getScope(nextToken()), visitType === "*") {
|
|
451
484
|
let prev = visit.previousSibling;
|
|
452
485
|
visitScope[nextToken()] = prev && (prev.nodeType < 8 || prev.data) ? prev : visit.parentNode.insertBefore(new Text(), visit);
|
|
453
|
-
} else branchesEnabled
|
|
454
|
-
return
|
|
486
|
+
} else branchesEnabled ? (visitBranches ||= createVisitBranches())() : render.b && (visits[retained++] = visit);
|
|
487
|
+
return embedRenders && !embedAnchor && visit && embedRenders.set(embedAnchor = visit.parentNode.insertBefore(new Text(), visit.nextSibling), [renderId, scopeLookup]), visits.length = retained, effects;
|
|
455
488
|
}, render.w = () => {
|
|
456
489
|
walk(), runResumeEffects(render);
|
|
457
490
|
}, render;
|
|
@@ -459,7 +492,7 @@ function init(runtimeId = "M") {
|
|
|
459
492
|
};
|
|
460
493
|
if (renders) {
|
|
461
494
|
initRuntime(renders);
|
|
462
|
-
for (let renderId in renders) runResumeEffects(
|
|
495
|
+
for (let renderId in renders) runResumeEffects(curRenders(renderId));
|
|
463
496
|
} else defineRuntime({
|
|
464
497
|
configurable: !0,
|
|
465
498
|
set: initRuntime
|
|
@@ -467,7 +500,7 @@ function init(runtimeId = "M") {
|
|
|
467
500
|
}
|
|
468
501
|
function runResumeEffects(render) {
|
|
469
502
|
try {
|
|
470
|
-
isResuming = 1, runEffects(render.m(), 1);
|
|
503
|
+
isResuming = 1, runEffects(render.m([]), 1);
|
|
471
504
|
} finally {
|
|
472
505
|
isResuming = 0;
|
|
473
506
|
}
|
|
@@ -825,32 +858,24 @@ function _await_promise(nodeAccessor, params) {
|
|
|
825
858
|
nodeAccessor = decodeAccessor(nodeAccessor);
|
|
826
859
|
let promiseAccessor = "L" + nodeAccessor, branchAccessor = "A" + nodeAccessor;
|
|
827
860
|
return _enable_catch(), (scope, promise) => {
|
|
828
|
-
let awaitBranch = scope[branchAccessor],
|
|
829
|
-
awaitCounter?.i || (awaitCounter = tryBranch.O = {
|
|
861
|
+
let awaitBranch = scope[branchAccessor], tryPlaceholder = findBranchWithKey(scope, "Q"), tryBranch = tryPlaceholder || awaitBranch, awaitCounter = tryBranch.O;
|
|
862
|
+
placeholderShown.add(pendingEffects), tryPlaceholder ? scope[promiseAccessor] || (awaitBranch && (awaitBranch.W ||= []), awaitCounter = addAwaitCounter(scope, tryPlaceholder)) : (awaitCounter?.i || (awaitCounter = tryBranch.O = {
|
|
830
863
|
i: 0,
|
|
831
864
|
c() {
|
|
832
865
|
if (--awaitCounter.i) return 1;
|
|
833
|
-
|
|
834
|
-
else {
|
|
835
|
-
let placeholderBranch = tryBranch.P;
|
|
836
|
-
placeholderBranch && (tryBranch.P = 0, placeholderBranch.S.parentNode.insertBefore(tryBranch.S.parentNode, placeholderBranch.S), removeAndDestroyBranch(placeholderBranch));
|
|
837
|
-
}
|
|
838
|
-
queueEffect(tryBranch, (scope) => {
|
|
839
|
-
let pendingEffects = scope.J;
|
|
840
|
-
pendingEffects && (scope.J = [], runEffects(pendingEffects, 1));
|
|
841
|
-
});
|
|
866
|
+
tryBranch === scope[branchAccessor] ? scope[nodeAccessor].parentNode && scope[nodeAccessor].replaceWith(scope[branchAccessor].S.parentNode) : dismissPlaceholder(tryBranch), queueEffect(tryBranch, runPendingEffects);
|
|
842
867
|
}
|
|
843
|
-
}),
|
|
844
|
-
|
|
845
|
-
}, -1)))));
|
|
868
|
+
}), scope[promiseAccessor] || (awaitBranch && (awaitBranch.W ||= []), awaitCounter.i++ || requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(scope, () => {
|
|
869
|
+
awaitBranch.V || (awaitBranch.S.parentNode.insertBefore(scope[nodeAccessor], awaitBranch.S), tempDetachBranch(tryBranch));
|
|
870
|
+
}, -1))))));
|
|
846
871
|
let thisPromise = scope[promiseAccessor] = promise.then((data) => {
|
|
847
872
|
if (thisPromise === scope[promiseAccessor]) {
|
|
848
873
|
let referenceNode = scope[nodeAccessor];
|
|
849
|
-
scope[promiseAccessor] = 0,
|
|
874
|
+
scope[promiseAccessor] = 0, queueAsyncRender(scope, () => {
|
|
850
875
|
(awaitBranch = scope[branchAccessor]).V && (pendingScopes.push(awaitBranch), setupBranch(awaitBranch.V, awaitBranch), awaitBranch.V = 0, insertBranchBefore(awaitBranch, scope[nodeAccessor].parentNode, scope[nodeAccessor]), referenceNode.remove()), params?.(awaitBranch, [data]);
|
|
851
876
|
let pendingRenders = awaitBranch.W;
|
|
852
877
|
if (awaitBranch.W = 0, pendingRenders?.forEach(queuePendingRender), placeholderShown.add(pendingEffects), awaitCounter.c(), awaitCounter.m) {
|
|
853
|
-
let fnScopes = /* @__PURE__ */ new Map(), effects = awaitCounter.m();
|
|
878
|
+
let fnScopes = /* @__PURE__ */ new Map(), effects = awaitCounter.m([]);
|
|
854
879
|
for (let i = 0; i < pendingEffects.length;) {
|
|
855
880
|
let fn = pendingEffects[i++], scopes = fnScopes.get(fn);
|
|
856
881
|
scopes || fnScopes.set(fn, scopes = /* @__PURE__ */ new Set()), scopes.add(pendingEffects[i++]);
|
|
@@ -860,10 +885,10 @@ function _await_promise(nodeAccessor, params) {
|
|
|
860
885
|
fnScopes.get(fn)?.has(scope) || queueEffect(scope, fn);
|
|
861
886
|
}
|
|
862
887
|
}
|
|
863
|
-
}
|
|
888
|
+
});
|
|
864
889
|
}
|
|
865
890
|
}, (error) => {
|
|
866
|
-
thisPromise === scope[promiseAccessor] && (awaitCounter.i = scope[promiseAccessor] = 0,
|
|
891
|
+
thisPromise === scope[promiseAccessor] && (awaitCounter.i = scope[promiseAccessor] = 0, queueAsyncRender(scope, renderCatch, error));
|
|
867
892
|
});
|
|
868
893
|
};
|
|
869
894
|
}
|
|
@@ -874,6 +899,27 @@ function _await_content(nodeAccessor, template, walks, setup) {
|
|
|
874
899
|
(scope[branchAccessor] = createBranch(scope.$, renderer, scope, scope[nodeAccessor].parentNode)).V = renderer, pendingScopes.pop();
|
|
875
900
|
};
|
|
876
901
|
}
|
|
902
|
+
function addAwaitCounter(scope, tryBranch = findBranchWithKey(scope, "Q")) {
|
|
903
|
+
if (!tryBranch) return;
|
|
904
|
+
let awaitCounter = tryBranch.O;
|
|
905
|
+
return awaitCounter?.i || (awaitCounter = tryBranch.O = {
|
|
906
|
+
i: 0,
|
|
907
|
+
c() {
|
|
908
|
+
if (--awaitCounter.i) return 1;
|
|
909
|
+
dismissPlaceholder(tryBranch), queueEffect(tryBranch, runPendingEffects);
|
|
910
|
+
}
|
|
911
|
+
}), placeholderShown.add(pendingEffects), awaitCounter.i++ || requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(tryBranch, () => {
|
|
912
|
+
insertBranchBefore(tryBranch.P = createAndSetupBranch(tryBranch.$, tryBranch.Q, tryBranch._, tryBranch.S.parentNode), tryBranch.S.parentNode, tryBranch.S), tempDetachBranch(tryBranch);
|
|
913
|
+
}, -1)))), awaitCounter;
|
|
914
|
+
}
|
|
915
|
+
function runPendingEffects(scope) {
|
|
916
|
+
let effects = scope.J;
|
|
917
|
+
effects && (scope.J = [], runEffects(effects, 1));
|
|
918
|
+
}
|
|
919
|
+
function dismissPlaceholder(tryBranch) {
|
|
920
|
+
let placeholderBranch = tryBranch.P;
|
|
921
|
+
placeholderBranch && (tryBranch.P = 0, placeholderBranch.S.parentNode.insertBefore(tryBranch.S.parentNode, placeholderBranch.S), removeAndDestroyBranch(placeholderBranch));
|
|
922
|
+
}
|
|
877
923
|
function _try(nodeAccessor, template, walks, setup) {
|
|
878
924
|
nodeAccessor = decodeAccessor(nodeAccessor);
|
|
879
925
|
let branchAccessor = "A" + nodeAccessor, renderer = _content("", template, walks, setup)();
|
|
@@ -991,6 +1037,9 @@ function run() {
|
|
|
991
1037
|
}
|
|
992
1038
|
runEffects(effects);
|
|
993
1039
|
}
|
|
1040
|
+
function queueAsyncRender(scope, signal, value) {
|
|
1041
|
+
queueRender(scope, signal, -1, value), queueMicrotask(run);
|
|
1042
|
+
}
|
|
994
1043
|
function prepareEffects(fn) {
|
|
995
1044
|
let prevRenders = pendingRenders, prevEffects = pendingEffects, prevLookup = asyncRendersLookup, preparedEffects = pendingEffects = [];
|
|
996
1045
|
pendingRenders = [], asyncRendersLookup = pendingRendersLookup, pendingRendersLookup = {};
|
|
@@ -1013,11 +1062,16 @@ function runRenders() {
|
|
|
1013
1062
|
}
|
|
1014
1063
|
pendingRenders[i] = item;
|
|
1015
1064
|
}
|
|
1016
|
-
|
|
1065
|
+
runRender(render);
|
|
1017
1066
|
}
|
|
1018
1067
|
for (let scope of pendingScopes) scope.H = 0;
|
|
1019
1068
|
pendingScopes = [];
|
|
1020
1069
|
}
|
|
1070
|
+
function skipDestroyedRenders() {
|
|
1071
|
+
runRender = ((runRender) => (render) => {
|
|
1072
|
+
render.b.F?.I || runRender(render);
|
|
1073
|
+
})(runRender);
|
|
1074
|
+
}
|
|
1021
1075
|
function _enable_catch() {
|
|
1022
1076
|
if (!catchEnabled) {
|
|
1023
1077
|
catchEnabled = 1, enableBranches();
|
|
@@ -1107,4 +1161,79 @@ function mount(input = {}, reference, position) {
|
|
|
1107
1161
|
};
|
|
1108
1162
|
}
|
|
1109
1163
|
//#endregion
|
|
1110
|
-
|
|
1164
|
+
//#region src/dom/load.ts
|
|
1165
|
+
function _load_template(id, load) {
|
|
1166
|
+
_enable_catch();
|
|
1167
|
+
let pending, lazyTemplate = _template(id, 0, 0, (branch) => {
|
|
1168
|
+
let awaitCounter = addAwaitCounter(branch);
|
|
1169
|
+
branch.X ||= /* @__PURE__ */ new Map(), (pending ||= load()).then((renderer) => {
|
|
1170
|
+
Object.assign(lazyTemplate, renderer), queueAsyncRender(branch, (branch) => insertLoaded(renderer, branch, branch.S, awaitCounter));
|
|
1171
|
+
}, loadFailed(branch, awaitCounter));
|
|
1172
|
+
}, _load_signal(() => (pending ||= load()).then((r) => ({ _: r.d }))));
|
|
1173
|
+
return lazyTemplate;
|
|
1174
|
+
}
|
|
1175
|
+
function _load_setup(nodeAccessor, childScopeAccessor, load) {
|
|
1176
|
+
nodeAccessor = decodeAccessor(nodeAccessor), childScopeAccessor = decodeAccessor(childScopeAccessor);
|
|
1177
|
+
let pending, renderer;
|
|
1178
|
+
return _enable_catch(), (owner) => {
|
|
1179
|
+
let child = owner[childScopeAccessor];
|
|
1180
|
+
if (renderer) insertLoaded(renderer, child, owner[nodeAccessor]);
|
|
1181
|
+
else {
|
|
1182
|
+
let awaitCounter = addAwaitCounter(owner);
|
|
1183
|
+
child.X ||= /* @__PURE__ */ new Map(), (pending ||= load()).then((mod) => {
|
|
1184
|
+
renderer = _content("", ...mod._)(), queueAsyncRender(child, (child) => insertLoaded(renderer, child, owner[nodeAccessor], awaitCounter));
|
|
1185
|
+
}, loadFailed(child, awaitCounter));
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
function insertLoaded(renderer, branch, marker, awaitCounter) {
|
|
1190
|
+
let parent = marker.parentNode;
|
|
1191
|
+
branch.H = 1, renderer.b(branch, parent.namespaceURI), setupBranch(renderer, branch), applyLoad(branch, () => {
|
|
1192
|
+
insertBranchBefore(branch, parent, marker), marker.remove(), pendingScopes.push(branch), awaitCounter?.c();
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
function loadFailed(scope, awaitCounter) {
|
|
1196
|
+
return (error) => {
|
|
1197
|
+
awaitCounter && (awaitCounter.i = 0), queueAsyncRender(scope, renderCatch, error);
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
function applyLoad(scope, insert) {
|
|
1201
|
+
let values = scope.X, remaining;
|
|
1202
|
+
if (scope.X = 0, remaining = values?.size) for (let [promise, entry] of values) promise.then((signal) => {
|
|
1203
|
+
entry.b = signal, --remaining || (scope.H = 1, pendingScopes.push(scope), queueAsyncRender(scope, (scope) => {
|
|
1204
|
+
values.forEach((e) => e.b._(scope, e.a)), insert();
|
|
1205
|
+
}));
|
|
1206
|
+
}, () => 0);
|
|
1207
|
+
else insert();
|
|
1208
|
+
}
|
|
1209
|
+
function _load_signal(load) {
|
|
1210
|
+
let pending, signal;
|
|
1211
|
+
return (scope, value) => {
|
|
1212
|
+
pending ||= load(), scope.X || !("X" in scope) && scope.H ? (scope.X ||= /* @__PURE__ */ new Map()).set(pending, { a: value }) : signal ? signal(scope, value) : pending.then((mod) => queueAsyncRender(scope, signal = mod._, value), () => 0);
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
function _load_visible_trigger(selector, options) {
|
|
1216
|
+
let pending, el;
|
|
1217
|
+
return (load) => () => (pending ||= new Promise((resolve) => (el = getSelectorOrResolve(selector, resolve)) && new IntersectionObserver((entries, io) => entries.some((entry) => entry.isIntersecting) && resolve(io.disconnect()), options).observe(el))).then(load);
|
|
1218
|
+
}
|
|
1219
|
+
function _load_idle_trigger(options) {
|
|
1220
|
+
let pending;
|
|
1221
|
+
return (load) => () => (pending ||= new Promise((resolve) => (self.requestIdleCallback || resolve)(resolve, options))).then(load);
|
|
1222
|
+
}
|
|
1223
|
+
function _load_event_trigger(event, selector) {
|
|
1224
|
+
let pending;
|
|
1225
|
+
return (load) => () => (pending ||= new Promise((resolve) => getSelectorOrResolve(selector, resolve)?.addEventListener(event, resolve, { once: !0 }))).then(load);
|
|
1226
|
+
}
|
|
1227
|
+
function _load_media_trigger(query) {
|
|
1228
|
+
let pending, mql;
|
|
1229
|
+
return (load) => () => (pending ||= new Promise((resolve) => (mql = matchMedia(query)).matches ? resolve() : mql.addEventListener("change", resolve, { once: !0 }))).then(load);
|
|
1230
|
+
}
|
|
1231
|
+
function _load_race_trigger(...triggers) {
|
|
1232
|
+
let noop = () => Promise.resolve(), pending;
|
|
1233
|
+
return (load) => () => (pending ||= Promise.race(triggers.map((t) => t(noop)()))).then(load);
|
|
1234
|
+
}
|
|
1235
|
+
function getSelectorOrResolve(selector, resolve) {
|
|
1236
|
+
return document.querySelector(selector) || resolve();
|
|
1237
|
+
}
|
|
1238
|
+
//#endregion
|
|
1239
|
+
export { $signal, $signalReset, _assert_hoist, _assert_init, _attr, _attr_class, _attr_class_item, _attr_class_items, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_details_or_dialog_open_default as _attr_details_open_default, _attr_details_or_dialog_open_default as _attr_dialog_open_default, _attr_details_or_dialog_open_script as _attr_details_open_script, _attr_details_or_dialog_open_script as _attr_dialog_open_script, _attr_input_checked, _attr_input_checkedValue, _attr_input_checkedValue_default, _attr_input_checkedValue_script, _attr_input_checked_default, _attr_input_checked_script, _attr_input_value, _attr_input_value as _attr_textarea_value, _attr_input_value_default, _attr_input_value_default as _attr_textarea_value_default, _attr_input_value_script, _attr_input_value_script as _attr_textarea_value_script, _attr_nonce, _attr_select_value, _attr_select_value_default, _attr_select_value_script, _attr_style, _attr_style_item, _attr_style_items, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_script, _await_content, _await_promise, _call, _child_setup, _closure, _closure_get, _const, _content, _content_closures, _content_resume, _dynamic_tag, _el, _el_read, _enable_catch, _for_closure, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_resume, _html, _id, _if, _if_closure, _let, _let_change, _lifecycle, _load_event_trigger, _load_idle_trigger, _load_media_trigger, _load_race_trigger, _load_setup, _load_signal, _load_template, _load_visible_trigger, _on, _or, _resume, _resume_dynamic_tag, _return, _return_change, _script, _template, _text, _text_content, _to_text, _try, _var, _var_change, _var_resume, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, init, initEmbedded, ready, run };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { $Global, Template } from "../common/types";
|
|
2
|
+
import { type ServerRenderer } from "./template";
|
|
3
|
+
declare const kAssets: unique symbol;
|
|
4
|
+
declare const kBlockIndex: unique symbol;
|
|
5
|
+
declare const kDeferIndex: unique symbol;
|
|
6
|
+
export interface VisibleTrigger {
|
|
7
|
+
type: "visible";
|
|
8
|
+
selector: string;
|
|
9
|
+
options?: {
|
|
10
|
+
rootMargin?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface IdleTrigger {
|
|
14
|
+
type: "idle";
|
|
15
|
+
selector?: never;
|
|
16
|
+
options?: {
|
|
17
|
+
timeout?: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface MediaTrigger {
|
|
21
|
+
type: "media";
|
|
22
|
+
selector: string;
|
|
23
|
+
options?: never;
|
|
24
|
+
}
|
|
25
|
+
export interface EventTrigger {
|
|
26
|
+
type: `on-${string}`;
|
|
27
|
+
selector: string;
|
|
28
|
+
options?: never;
|
|
29
|
+
}
|
|
30
|
+
export type LoadTrigger = VisibleTrigger | IdleTrigger | MediaTrigger | EventTrigger;
|
|
31
|
+
type Trigger = LoadTrigger;
|
|
32
|
+
interface Asset {
|
|
33
|
+
id: string;
|
|
34
|
+
triggers?: Trigger[];
|
|
35
|
+
}
|
|
36
|
+
declare module "../common/types" {
|
|
37
|
+
interface $Global {
|
|
38
|
+
[kAssets]?: Asset[];
|
|
39
|
+
[kBlockIndex]?: number;
|
|
40
|
+
[kDeferIndex]?: number;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
type AssetFlush = (g: $Global, type: "block" | "defer", asset: string) => string;
|
|
44
|
+
export declare function withLoadAssets(renderer: ServerRenderer, assetId: string, triggers?: Trigger[]): ServerRenderer;
|
|
45
|
+
export declare function withPageAssets(template: ServerRenderer & Template, runtime: AssetFlush, assetId: string, runtimeId?: string): Template;
|
|
46
|
+
export declare function _flush_head(): string;
|
|
47
|
+
export {};
|
package/dist/html/compat.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { register } from "./serializer";
|
|
1
2
|
import type { ServerRenderer } from "./template";
|
|
2
3
|
import { _await, _html, _peek_scope_id, _scope_id, $global, Chunk, isInResumedBranch, State, writeScript } from "./writer";
|
|
3
4
|
export declare const compat: {
|
|
@@ -13,9 +14,9 @@ export declare const compat: {
|
|
|
13
14
|
onFlush(fn: (chunk: Chunk) => void): void;
|
|
14
15
|
patchDynamicTag: (patch: (tag: unknown, scopeId: number, accessor: import("../common/types").Accessor) => unknown) => void;
|
|
15
16
|
writeSetScopeForComponent(branchId: number, m5c: string, m5i: unknown): void;
|
|
16
|
-
toJSON(
|
|
17
|
+
toJSON(): (this: WeakKey) => [registryId: string, scopeId: unknown] | undefined;
|
|
17
18
|
flushScript($global: any): string;
|
|
18
19
|
render(renderer: ServerRenderer, willRerender: boolean, classAPIOut: any, component: any, input: any, completeChunks: Chunk[]): void;
|
|
19
|
-
|
|
20
|
+
register: typeof register;
|
|
20
21
|
registerRenderBody(fn: any): void;
|
|
21
22
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const WALKER_RUNTIME_CODE = "(e=>(self[e]
|
|
1
|
+
export declare const WALKER_RUNTIME_CODE = "(e=>(self[e]||=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(a[r=l.slice(s+1)]=e,l[s]),r,e),l>\"#\"&&d.push(e)}},self[e]))";
|
|
2
2
|
export declare const REORDER_RUNTIME_CODE = "(e=>{if(e.j)return;let i,l,r,t=e.p={},c=(i,l)=>e.l[i].replaceWith(...l.childNodes);e.d.head.append(e.d.querySelector(\"style[\"+e.i+\"]\")||\"\"),e.j={},e.x=(n,a,d,o,g)=>{d==r&&i(),\"#\"==n?(t[a]=l).i++:\"!\"==n?e.l[a]&&t[a]&&(r=d.nextSibling,i=()=>t[a].c()):\"T\"==d.tagName&&(a=d.getAttribute(e.i))&&(r=d.nextSibling,i=()=>{d.remove(),o||c(a,d),l.c()},l=t[a]||(o=t[a]={i:e.l[a]?1:2,c(i=e.l[\"^\"+a]){if(--o.i)return 1;for(;(r=e.l[a].previousSibling||i).remove(),i!=r;);c(a,d)}}),(n=e.j[a])&&(g=l.c,l.c=()=>g()||n(e.r)))}})";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const WALKER_RUNTIME_CODE = "((runtimeId) => (self[runtimeId]
|
|
1
|
+
export declare const WALKER_RUNTIME_CODE = "((runtimeId) => (self[runtimeId] ||= (\n renderId,\n prefix = runtimeId + renderId,\n prefixLen = prefix.length,\n lookup = {},\n visits = [],\n doc = document,\n walker = doc.createTreeWalker(\n doc,\n 129 /* NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_ELEMENT */,\n ),\n) =>\n doc = (self[runtimeId][renderId] = {\n i: prefix,\n d: doc,\n l: lookup,\n v: visits,\n x() {},\n w(node, op, id) {\n while ((node = walker.nextNode())) {\n doc.x(\n (op =\n (op = node.data) &&\n !op.indexOf(prefix) &&\n ((lookup[(id = op.slice(prefixLen + 1))] = node), op[prefixLen])),\n id,\n node,\n );\n\n if (op > \"#\") {\n visits.push(node);\n }\n }\n },\n })\n, self[runtimeId]))";
|
|
2
2
|
export declare const REORDER_RUNTIME_CODE = "((runtime) => {\n if (runtime.j) return;\n let onNextSibling,\n placeholder,\n nextSibling,\n placeholders = runtime.p = {},\n replace = (id, container) => runtime.l[id].replaceWith(...container.childNodes);\n runtime.d.head.append(\n runtime.d.querySelector(\"style[\" + runtime.i + \"]\") || \"\"\n );\n runtime.j = {};\n runtime.x = (op, id, node, placeholderRoot, placeholderCb) => {\n if (node == nextSibling) {\n onNextSibling();\n }\n\n if (op == \"#\") {\n (placeholders[id] = placeholder).i++;\n } else if (op == \"!\") {\n if (runtime.l[id] && placeholders[id]) {\n nextSibling = node.nextSibling;\n onNextSibling = () => placeholders[id].c();\n }\n } else if (node.tagName == \"T\" && (id = node.getAttribute(runtime.i))) {\n nextSibling = node.nextSibling;\n onNextSibling = () => {\n node.remove();\n placeholderRoot || replace(id, node);\n placeholder.c();\n };\n placeholder =\n placeholders[id] ||\n (placeholderRoot = placeholders[id] =\n {\n i: runtime.l[id] ? 1 : 2,\n c(start = runtime.l[\"^\" + id]) {\n if (--placeholderRoot.i) return 1;\n for (\n ;\n (nextSibling =\n runtime.l[id].previousSibling || start).remove(),\n start != nextSibling;\n\n );\n replace(id, node);\n },\n });\n // repurpose \"op\" for callbacks ...carefully\n if ((op = runtime.j[id])) {\n placeholderCb = placeholder.c;\n placeholder.c = () => placeholderCb() || op(runtime.r);\n }\n }\n };\n})";
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import type { Boundary } from "./writer";
|
|
2
|
+
export declare const K_SCOPE_ID: unique symbol;
|
|
3
|
+
export type ScopeFlush = [scopeId: number, scope: object, props: object];
|
|
4
|
+
export interface SerializeChannel {
|
|
5
|
+
readyId?: string;
|
|
6
|
+
parent?: SerializeChannel;
|
|
7
|
+
}
|
|
2
8
|
export declare function setDebugInfo(obj: WeakKey, file: string, loc: string | 0, vars?: Record<string, string>): void;
|
|
3
9
|
export declare class Serializer {
|
|
4
10
|
#private;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
register<T extends WeakKey>(id: string, val: T, scope?: unknown): T;
|
|
11
|
+
pending(channel?: SerializeChannel): boolean;
|
|
12
|
+
pendingReadyChannel(): SerializeChannel | undefined;
|
|
13
|
+
stringifyScopes(flushes: ScopeFlush[], globals: object | 0, boundary: Boundary, channel?: SerializeChannel): string;
|
|
14
|
+
written(val: WeakKey): boolean;
|
|
15
|
+
takeChannelDeps(): Set<string> | null;
|
|
16
|
+
writeCall(value: unknown, object: unknown, property: string, channel?: SerializeChannel): void;
|
|
12
17
|
}
|
|
13
|
-
export declare function register<T extends WeakKey>(id: string, val: T, scope?: unknown
|
|
18
|
+
export declare function register<T extends WeakKey>(id: string, val: T, scope?: unknown): T;
|
|
14
19
|
export declare function getRegistered(val: WeakKey): {
|
|
15
20
|
id: string;
|
|
16
21
|
scope: unknown;
|
|
17
22
|
} | undefined;
|
|
18
|
-
export declare function stringify(val: unknown): string;
|
|
19
23
|
export declare function toObjectKey(name: string): string;
|
|
20
24
|
export declare function toAccess(accessor: string): string;
|
|
25
|
+
export declare function quote(str: string, startPos: number): string;
|