Comparing version 6.0.0-next.3.22 to 6.0.0-next.3.23
@@ -1,5 +0,4 @@ | ||
type Falsy = undefined | null | false | 0 | ""; | ||
export declare function forIn<V extends {}>(obj: Falsy | V, cb: <K extends keyof V>(key: K, value: V[K]) => void): void; | ||
export declare function forOf<T, V extends Iterable<T>>(list: Falsy | V, cb: (item: T, index: number) => void): void; | ||
import type { Falsy } from "./types"; | ||
export declare function forIn(obj: Falsy | {}, cb: (key: string, value: unknown) => void): void; | ||
export declare function forOf(list: Falsy | Iterable<unknown>, cb: (item: unknown, index: number) => void): void; | ||
export declare function forTo(to: number, from: number | Falsy, step: number | Falsy, cb: (index: number) => void): void; | ||
export {}; |
import type { Renderer as ClientRenderer } from "../dom/renderer"; | ||
export type Falsy = undefined | null | false | 0 | ""; | ||
export type CommentWalker = TreeWalker & Record<string, Comment>; | ||
export type Scope<T extends { | ||
[x: string | number]: unknown; | ||
} = { | ||
[x: string | number]: unknown; | ||
}> = [...unknown[]] & { | ||
export interface BranchScope extends Scope { | ||
___parentBranch: BranchScope | undefined; | ||
___destroyed: 1 | undefined; | ||
___abortScopes: Set<Scope> | undefined; | ||
___branchScopes: Set<BranchScope> | undefined; | ||
} | ||
export interface Scope { | ||
$global: Record<string, unknown>; | ||
_: Scope | undefined; | ||
___args: unknown; | ||
___startNode: Node & ChildNode; | ||
___endNode: Node & ChildNode; | ||
___cleanup: Set<Scope> | undefined; | ||
___client: 1 | undefined; | ||
___bound: Map<unknown, unknown> | undefined; | ||
___pending: 1 | 0 | undefined; | ||
___renderer: ClientRenderer | undefined; | ||
___abortControllers: Map<string | number, AbortController> | undefined; | ||
___cleanupOwner: Scope | undefined; | ||
$global: Record<string, unknown>; | ||
_: Scope | undefined; | ||
___abortControllers: Record<string | number, AbortController | void> | undefined; | ||
___closestBranch: BranchScope | undefined; | ||
[x: string | number]: any; | ||
} & T; | ||
} | ||
export declare enum ResumeSymbol { | ||
SectionStart = "[", | ||
SectionEnd = "]", | ||
SectionSingleNodesEnd = "|", | ||
Node = "*", | ||
Cleanup = "$" | ||
BranchStart = "[", | ||
BranchEnd = "]", | ||
BranchSingleNode = "|", | ||
ClosestBranch = "$" | ||
} | ||
@@ -28,0 +29,0 @@ export declare enum AccessorChar { |
@@ -6,3 +6,3 @@ export { attrTag, attrTags } from "./common/attr-tag"; | ||
export { compat } from "./dom/compat"; | ||
export { conditional, conditionalOnlyChild, inConditionalScope, inLoopScope, loopIn, loopOf, loopTo, } from "./dom/control-flow"; | ||
export { conditional, conditionalOnlyChild, loopIn, loopOf, loopTo, } from "./dom/control-flow"; | ||
export { controllable_detailsOrDialog_open, controllable_detailsOrDialog_open_effect, controllable_input_checked, controllable_input_checked_effect, controllable_input_checkedValue, controllable_input_checkedValue_effect, controllable_input_value, controllable_input_value_effect, controllable_select_value, controllable_select_value_effect, controllable_textarea_value, controllable_textarea_value_effect, } from "./dom/controllable"; | ||
@@ -15,3 +15,3 @@ export { attr, attrs, attrsEvents, classAttr, data, html, lifecycle, partialAttrs, props, styleAttr, textContent, } from "./dom/dom"; | ||
export { createScope } from "./dom/scope"; | ||
export { childClosures, closure, dynamicClosure, dynamicSubscribers, effect, inChild, intersection, intersections, nextTagId, setTagVar, setTagVarChange, state, tagVarSignal, tagVarSignalChange, value, } from "./dom/signals"; | ||
export { conditionalClosure, dynamicClosure, effect, inChild, intersection, intersections, loopClosure, nextTagId, setTagVar, setTagVarChange, state, tagVarSignal, tagVarSignalChange, value, } from "./dom/signals"; | ||
export { createTemplate } from "./dom/template"; |
917
dist/dom.js
@@ -25,7 +25,6 @@ "use strict"; | ||
attrsEvents: () => attrsEvents, | ||
childClosures: () => childClosures, | ||
classAttr: () => classAttr, | ||
closure: () => closure, | ||
compat: () => compat, | ||
conditional: () => conditional, | ||
conditionalClosure: () => conditionalClosure, | ||
conditionalOnlyChild: () => conditionalOnlyChild, | ||
@@ -50,3 +49,2 @@ controllable_detailsOrDialog_open: () => controllable_detailsOrDialog_open, | ||
dynamicClosure: () => dynamicClosure, | ||
dynamicSubscribers: () => dynamicSubscribers, | ||
dynamicTagAttrs: () => dynamicTagAttrs, | ||
@@ -60,4 +58,2 @@ effect: () => effect, | ||
inChild: () => inChild, | ||
inConditionalScope: () => inConditionalScope, | ||
inLoopScope: () => inLoopScope, | ||
init: () => init, | ||
@@ -67,2 +63,3 @@ intersection: () => intersection, | ||
lifecycle: () => lifecycle, | ||
loopClosure: () => loopClosure, | ||
loopIn: () => loopIn, | ||
@@ -139,39 +136,29 @@ loopOf: () => loopOf, | ||
// src/common/meta.ts | ||
var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_"; | ||
// src/dom/scope.ts | ||
var pendingScopes = []; | ||
function createScope($global) { | ||
return { | ||
u: 1, | ||
let scope = { | ||
g: 1, | ||
$global | ||
}; | ||
return pendingScopes.push(scope), scope; | ||
} | ||
function finishPendingScopes() { | ||
for (let scope of pendingScopes) | ||
scope.g = 0; | ||
pendingScopes = []; | ||
} | ||
var emptyScope = createScope({}); | ||
function getEmptyScope(marker) { | ||
return emptyScope.a = emptyScope.b = marker, emptyScope; | ||
return emptyScope.a = emptyScope.c = marker, emptyScope; | ||
} | ||
function destroyScope(scope) { | ||
_destroyScope(scope), scope.d?.h?.delete(scope); | ||
let closureSignals = scope.x?.c; | ||
if (closureSignals) | ||
for (let signal of closureSignals) | ||
signal.j?.(scope); | ||
return scope; | ||
function destroyBranch(branch) { | ||
if (branch.y = 1, branch.m?.forEach(destroyBranch), branch.n) | ||
for (let scope of branch.n) | ||
for (let id in scope.h) | ||
scope.h[id]?.abort(); | ||
} | ||
function _destroyScope(scope) { | ||
scope.h?.forEach(_destroyScope); | ||
let controllers = scope.l; | ||
if (controllers) | ||
for (let ctrl of controllers.values()) | ||
ctrl.abort(); | ||
} | ||
function onDestroy(scope) { | ||
let parentScope = scope.d; | ||
for (; parentScope && !parentScope.h?.has(scope); ) | ||
(parentScope.h ||= /* @__PURE__ */ new Set()).add(scope), scope = parentScope, parentScope = scope.d; | ||
} | ||
function removeAndDestroyScope(scope) { | ||
destroyScope(scope); | ||
let current = scope.a, stop = scope.b.nextSibling; | ||
function removeAndDestroyBranch(branch) { | ||
destroyBranch(branch); | ||
let current = branch.a, stop = branch.c.nextSibling; | ||
for (; current !== stop; ) { | ||
@@ -183,3 +170,3 @@ let next = current.nextSibling; | ||
function insertBefore(scope, parent, nextSibling) { | ||
let current = scope.a, stop = scope.b.nextSibling; | ||
let current = scope.a, stop = scope.c.nextSibling; | ||
for (; current !== stop; ) { | ||
@@ -191,292 +178,2 @@ let next = current.nextSibling; | ||
// src/dom/resume.ts | ||
var registeredValues = {}, Render = class { | ||
m = []; | ||
n = {}; | ||
y = { | ||
_: registeredValues | ||
}; | ||
constructor(renders, runtimeId, renderId) { | ||
this.z = renders, this.A = runtimeId, this.o = renderId, this.p = renders[renderId], this.q(); | ||
} | ||
w() { | ||
this.p.w(), this.q(); | ||
} | ||
q() { | ||
let data2 = this.p, serializeContext = this.y, scopeLookup = this.n, visits = data2.v, cleanupOwners = /* @__PURE__ */ new Map(); | ||
if (visits.length) { | ||
let commentPrefixLen = data2.i.length, cleanupMarkers = /* @__PURE__ */ new Map(); | ||
data2.v = []; | ||
let sectionEnd = (visit, scopeId = this.f, curNode = visit) => { | ||
let scope = scopeLookup[scopeId] ||= {}, endNode = curNode; | ||
for (; (endNode = endNode.previousSibling).nodeType === 8; ) ; | ||
scope.b = endNode; | ||
let startNode = scope.a ||= endNode, len = cleanupMarkers.size; | ||
for (let [markerScopeId, markerNode] of cleanupMarkers) { | ||
if (!len--) break; | ||
markerScopeId !== scopeId && startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2 && (cleanupOwners.set("" + markerScopeId, scopeId), cleanupMarkers.delete(markerScopeId)); | ||
} | ||
return cleanupMarkers.set(scopeId, visit), scope; | ||
}; | ||
for (let visit of visits) { | ||
let commentText = visit.data, token = commentText[commentPrefixLen], scopeId = parseInt(commentText.slice(commentPrefixLen + 1)), scope = scopeLookup[scopeId] ||= {}, dataIndex = commentText.indexOf(" ") + 1, data3 = dataIndex ? commentText.slice(dataIndex) : ""; | ||
if (token === "*" /* Node */) | ||
scope[data3] = visit.previousSibling; | ||
else if (token === "$" /* Cleanup */) | ||
cleanupMarkers.set(scopeId, visit); | ||
else if (token === "[" /* SectionStart */) | ||
this.f && (data3 && sectionEnd(visit), this.m.push(this.f)), this.f = scopeId, scope.a = visit; | ||
else if (token === "]" /* SectionEnd */) { | ||
if (scope[data3] = visit, scopeId < this.f) { | ||
let currParent = visit.parentNode, startNode = sectionEnd(visit).a; | ||
currParent && currParent !== startNode.parentNode && currParent.prepend(startNode), this.f = this.m.pop(); | ||
} | ||
} else if (token === "|" /* SectionSingleNodesEnd */) { | ||
scope[parseInt(data3)] = visit; | ||
let childScopeIds = JSON.parse( | ||
"[" + data3.slice(data3.indexOf(" ") + 1) + "]" | ||
), curNode = visit; | ||
for (let i = childScopeIds.length - 1; i >= 0; i--) | ||
curNode = sectionEnd(visit, childScopeIds[i], curNode).b; | ||
} | ||
} | ||
} | ||
let resumes = data2.r; | ||
if (resumes) { | ||
data2.r = []; | ||
let len = resumes.length, i = 0; | ||
try { | ||
for (isResuming = !0; i < len; ) { | ||
let resumeData = resumes[i++]; | ||
if (typeof resumeData == "function") { | ||
let scopes = resumeData(serializeContext), { $global } = scopeLookup; | ||
$global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = this.A, $global.renderId = this.o); | ||
for (let scopeId in scopes) | ||
if (scopeId !== "$") { | ||
let scope = scopes[scopeId], prevScope = scopeLookup[scopeId]; | ||
scope.$global = $global, prevScope !== scope && (scopeLookup[scopeId] = Object.assign( | ||
scope, | ||
prevScope | ||
)); | ||
let cleanupOwnerId = cleanupOwners.get(scopeId); | ||
cleanupOwnerId && (scope.d = scopes[cleanupOwnerId], onDestroy(scope)); | ||
} | ||
} else i === len || typeof resumes[i] != "string" ? delete this.z[this.o] : registeredValues[resumes[i++]]( | ||
scopeLookup[resumeData], | ||
scopeLookup[resumeData] | ||
); | ||
} | ||
} finally { | ||
isResuming = !1; | ||
} | ||
} | ||
} | ||
}, isResuming = !1; | ||
function register(id, obj) { | ||
return registeredValues[id] = obj, obj; | ||
} | ||
function registerBoundSignal(id, signal) { | ||
return registeredValues[id] = (scope) => (valueOrOp) => signal(scope, valueOrOp), signal; | ||
} | ||
function getRegisteredWithScope(id, scope) { | ||
let val = registeredValues[id]; | ||
return scope ? val(scope) : val; | ||
} | ||
function init(runtimeId = DEFAULT_RUNTIME_ID) { | ||
let resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId), renders; | ||
window[runtimeId] ? setRenders(window[runtimeId]) : Object.defineProperty(window, runtimeId, { | ||
configurable: !0, | ||
set: setRenders | ||
}); | ||
function setRenders(v) { | ||
renders = v; | ||
for (let renderId in v) | ||
resumeRender(renderId); | ||
Object.defineProperty(window, runtimeId, { | ||
configurable: !0, | ||
value: resumeRender | ||
}); | ||
} | ||
} | ||
function registerSubscriber(id, signal) { | ||
return register(id, signal.g), signal; | ||
} | ||
function nodeRef(id, key) { | ||
return register(id, (scope) => () => scope[key]); | ||
} | ||
// src/dom/signals.ts | ||
var MARK = {}, CLEAN = {}, DIRTY = {}; | ||
function state(valueAccessor, fn, getIntersection) { | ||
let valueSignal = value(valueAccessor, fn, getIntersection), markAccessor = valueAccessor + "#" /* Mark */, valueChangeAccessor = valueAccessor + "@" /* TagVariableChange */; | ||
return (scope, valueOrOp, valueChange) => (rendering ? valueSignal( | ||
scope, | ||
valueOrOp === MARK || valueOrOp === CLEAN || valueOrOp === DIRTY || (scope[valueChangeAccessor] = valueChange) || scope[markAccessor] === void 0 ? valueOrOp : CLEAN | ||
) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](valueOrOp) : queueSource(scope, valueSignal, valueOrOp), valueOrOp); | ||
} | ||
function value(valueAccessor, fn, getIntersection) { | ||
let markAccessor = valueAccessor + "#" /* Mark */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op)); | ||
return (scope, valueOrOp) => { | ||
if (valueOrOp === MARK) | ||
(scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK); | ||
else if (valueOrOp !== DIRTY) { | ||
let existing = scope[markAccessor] !== void 0; | ||
(scope[markAccessor] ||= 1) === 1 && (valueOrOp === CLEAN || existing && scope[valueAccessor] === valueOrOp ? intersection2?.(scope, CLEAN) : (scope[valueAccessor] = valueOrOp, fn && fn(scope, valueOrOp), intersection2?.(scope, DIRTY))), scope[markAccessor]--; | ||
} | ||
}; | ||
} | ||
var accessorId = 0; | ||
function intersection(count, fn, getIntersection) { | ||
let dirtyAccessor = "?" /* Dynamic */ + accessorId++, markAccessor = dirtyAccessor + "#" /* Mark */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op)); | ||
return (scope, op) => { | ||
op === MARK ? (scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK) : scope[markAccessor] === void 0 ? (scope[markAccessor] = count - 1, scope[dirtyAccessor] = !0) : --scope[markAccessor] === 0 ? op === DIRTY || scope[dirtyAccessor] ? (scope[dirtyAccessor] = !1, fn(scope, 0), intersection2?.(scope, DIRTY)) : intersection2?.(scope, CLEAN) : scope[dirtyAccessor] ||= op === DIRTY; | ||
}; | ||
} | ||
var defaultGetOwnerScope = (scope) => scope._; | ||
function closure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) { | ||
let dirtyAccessor = "?" /* Dynamic */ + accessorId++, markAccessor = dirtyAccessor + 1, getOwnerValueAccessor = typeof ownerValueAccessor == "function" ? ownerValueAccessor : () => ownerValueAccessor, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op)); | ||
return (scope, op) => { | ||
if (op === MARK) | ||
(scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK); | ||
else { | ||
let ownerScope, ownerValueAccessor2; | ||
if (scope[markAccessor] === void 0) { | ||
ownerScope = getOwnerScope(scope), ownerValueAccessor2 = getOwnerValueAccessor(scope); | ||
let ownerMark = ownerScope[ownerValueAccessor2 + "#" /* Mark */], ownerHasRun = ownerMark === void 0 ? !ownerScope.u : ownerMark === 0; | ||
scope[markAccessor] = ownerHasRun ? 1 : 2, op = DIRTY; | ||
} | ||
--scope[markAccessor] === 0 ? op === DIRTY || scope[dirtyAccessor] ? (scope[dirtyAccessor] = !1, ownerScope ||= getOwnerScope(scope), ownerValueAccessor2 ||= getOwnerValueAccessor(scope), fn && fn(scope, ownerScope[ownerValueAccessor2]), intersection2?.(scope, DIRTY)) : intersection2?.(scope, CLEAN) : scope[dirtyAccessor] ||= op === DIRTY; | ||
} | ||
}; | ||
} | ||
function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) { | ||
let getOwnerValueAccessor = typeof ownerValueAccessor == "function" ? ownerValueAccessor : () => ownerValueAccessor, signalFn = closure( | ||
getOwnerValueAccessor, | ||
fn, | ||
getOwnerScope, | ||
getIntersection | ||
), subscribeFns = /* @__PURE__ */ new WeakMap(); | ||
return signalFn.g = (scope) => { | ||
let subscribeFn = (value2) => signalFn(scope, value2), ownerScope = getOwnerScope(scope), providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */; | ||
subscribeFns.set(scope, subscribeFn), (ownerScope[providerSubscriptionsAccessor] ||= /* @__PURE__ */ new Set()).add(subscribeFn); | ||
}, signalFn.j = (scope) => { | ||
let ownerScope = getOwnerScope(scope), providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */; | ||
ownerScope[providerSubscriptionsAccessor]?.delete(subscribeFns.get(scope)), subscribeFns.delete(scope); | ||
}, signalFn; | ||
} | ||
function childClosures(closureSignals, childAccessor) { | ||
let signal = (scope, op) => { | ||
let childScope = scope[childAccessor]; | ||
for (let closureSignal of closureSignals) | ||
closureSignal(childScope, op); | ||
}; | ||
return signal.g = (scope) => { | ||
let childScope = scope[childAccessor]; | ||
for (let closureSignal of closureSignals) | ||
closureSignal.g?.(childScope); | ||
}, signal.j = (scope) => { | ||
let childScope = scope[childAccessor]; | ||
for (let closureSignal of closureSignals) | ||
closureSignal.j?.(childScope); | ||
}, signal; | ||
} | ||
function dynamicSubscribers(valueAccessor) { | ||
let subscribersAccessor = valueAccessor + "*" /* Subscribers */; | ||
return (scope, op) => { | ||
let subscribers = scope[subscribersAccessor]; | ||
if (subscribers) | ||
for (let subscriber of subscribers) | ||
subscriber(op); | ||
}; | ||
} | ||
function setTagVar(scope, childAccessor, tagVarSignal2) { | ||
scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp); | ||
} | ||
var tagVarSignal = (scope, valueOrOp) => scope["/" /* TagVariable */]?.(valueOrOp); | ||
function setTagVarChange(scope, changeHandler) { | ||
scope["@" /* TagVariableChange */] = changeHandler; | ||
} | ||
var tagVarSignalChange = (scope, value2) => scope["@" /* TagVariableChange */]?.(value2), contentClosures = (content, childScope, op) => { | ||
let signals = content?.c; | ||
if (signals) | ||
for (let signal of signals) | ||
signal(childScope, op); | ||
}; | ||
var tagIdsByGlobal = /* @__PURE__ */ new WeakMap(); | ||
function nextTagId({ $global }) { | ||
let id = tagIdsByGlobal.get($global) || 0; | ||
return tagIdsByGlobal.set($global, id + 1), "c" + $global.runtimeId + $global.renderId + id.toString(36); | ||
} | ||
function inChild(childAccessor, signal) { | ||
return (scope, valueOrOp) => { | ||
signal(scope[childAccessor], valueOrOp); | ||
}; | ||
} | ||
function intersections(signals) { | ||
return (scope, op) => { | ||
for (let signal of signals) | ||
signal(scope, op); | ||
}; | ||
} | ||
function effect(id, fn) { | ||
return register(id, fn), (scope) => { | ||
queueEffect(scope, fn); | ||
}; | ||
} | ||
// src/dom/queue.ts | ||
var pendingSignals = [], pendingEffects = [], rendering = !1; | ||
function queueSource(scope, signal, value2) { | ||
return schedule(), rendering = !0, signal(scope, MARK), rendering = !1, pendingSignals.push(scope, signal, value2), value2; | ||
} | ||
function queueEffect(scope, fn) { | ||
pendingEffects.push(scope, fn); | ||
} | ||
function run() { | ||
let signals = pendingSignals, effects = pendingEffects; | ||
try { | ||
rendering = !0, pendingSignals = [], runSignals(signals); | ||
} finally { | ||
rendering = !1; | ||
} | ||
pendingEffects = [], runEffects(effects); | ||
} | ||
function prepareEffects(fn) { | ||
let prevSignals = pendingSignals, prevEffects = pendingEffects, preparedEffects = pendingEffects = [], preparedSignals = pendingSignals = []; | ||
try { | ||
rendering = !0, fn(), pendingSignals = prevSignals, runSignals(preparedSignals); | ||
} finally { | ||
rendering = !1, pendingSignals = prevSignals, pendingEffects = prevEffects; | ||
} | ||
return preparedEffects; | ||
} | ||
function runEffects(effects = pendingEffects) { | ||
for (let i = 0; i < effects.length; i += 2 /* Total */) { | ||
let scope = effects[i], fn = effects[i + 1]; | ||
fn(scope, scope); | ||
} | ||
} | ||
function runSignals(signals) { | ||
for (let i = 0; i < signals.length; i += 3 /* Total */) { | ||
let scope = signals[i + 0 /* Scope */], signal = signals[i + 1 /* Signal */], value2 = signals[i + 2 /* Value */]; | ||
signal(scope, value2); | ||
} | ||
} | ||
// src/dom/abort-signal.ts | ||
function resetAbortSignal(scope, id) { | ||
let controllers = scope.l; | ||
if (controllers) { | ||
let ctrl = controllers.get(id); | ||
ctrl && (queueEffect(null, () => ctrl.abort()), controllers.delete(id)); | ||
} | ||
} | ||
function getAbortSignal(scope, id) { | ||
let controllers = scope.l ||= /* @__PURE__ */ new Map(), controller = controllers.get(id); | ||
return controller || (onDestroy(scope), controllers.set(id, controller = new AbortController())), controller.signal; | ||
} | ||
// src/common/compat-meta.ts | ||
var prefix = "$C_", RENDERER_REGISTER_ID = prefix + "r", SET_SCOPE_REGISTER_ID = prefix + "s"; | ||
// src/common/helpers.ts | ||
@@ -530,14 +227,14 @@ function classValue(value2) { | ||
var WRONG_POS = 2147483647; | ||
function reconcile(parent, oldScopes, newScopes, afterReference) { | ||
let oldStart = 0, newStart = 0, oldEnd = oldScopes.length - 1, newEnd = newScopes.length - 1, oldStartScope = oldScopes[oldStart], newStartScope = newScopes[newStart], oldEndScope = oldScopes[oldEnd], newEndScope = newScopes[newEnd], i, j, k, nextSibling, oldScope, newScope; | ||
function reconcile(parent, oldBranches, newBranches, afterReference) { | ||
let oldStart = 0, newStart = 0, oldEnd = oldBranches.length - 1, newEnd = newBranches.length - 1, oldStartBranch = oldBranches[oldStart], newStartBranch = newBranches[newStart], oldEndBranch = oldBranches[oldEnd], newEndBranch = newBranches[newEnd], i, j, k, nextSibling, oldBranch, newBranch; | ||
outer: { | ||
for (; oldStartScope === newStartScope; ) { | ||
for (; oldStartBranch === newStartBranch; ) { | ||
if (++oldStart, ++newStart, oldStart > oldEnd || newStart > newEnd) | ||
break outer; | ||
oldStartScope = oldScopes[oldStart], newStartScope = newScopes[newStart]; | ||
oldStartBranch = oldBranches[oldStart], newStartBranch = newBranches[newStart]; | ||
} | ||
for (; oldEndScope === newEndScope; ) { | ||
for (; oldEndBranch === newEndBranch; ) { | ||
if (--oldEnd, --newEnd, oldStart > oldEnd || newStart > newEnd) | ||
break outer; | ||
oldEndScope = oldScopes[oldEnd], newEndScope = newScopes[newEnd]; | ||
oldEndBranch = oldBranches[oldEnd], newEndBranch = newBranches[newEnd]; | ||
} | ||
@@ -547,5 +244,5 @@ } | ||
if (newStart <= newEnd) { | ||
k = newEnd + 1, nextSibling = k < newScopes.length ? newScopes[k].a : afterReference; | ||
k = newEnd + 1, nextSibling = k < newBranches.length ? newBranches[k].a : afterReference; | ||
do | ||
insertBefore(newScopes[newStart++], parent, nextSibling); | ||
insertBefore(newBranches[newStart++], parent, nextSibling); | ||
while (newStart <= newEnd); | ||
@@ -555,6 +252,6 @@ } | ||
do | ||
removeAndDestroyScope(oldScopes[oldStart++]); | ||
removeAndDestroyBranch(oldBranches[oldStart++]); | ||
while (oldStart <= oldEnd); | ||
else { | ||
let oldLength = oldEnd - oldStart + 1, newLength = newEnd - newStart + 1, aNullable = oldScopes, sources = new Array(newLength); | ||
let oldLength = oldEnd - oldStart + 1, newLength = newEnd - newStart + 1, aNullable = oldBranches, sources = new Array(newLength); | ||
for (i = 0; i < newLength; ++i) | ||
@@ -564,20 +261,20 @@ sources[i] = -1; | ||
for (j = newStart; j <= newEnd; ++j) | ||
keyIndex.set(newScopes[j], j); | ||
keyIndex.set(newBranches[j], j); | ||
for (i = oldStart; i <= oldEnd && synced < newLength; ++i) | ||
oldScope = oldScopes[i], j = keyIndex.get(oldScope), j !== void 0 && (pos = pos > j ? WRONG_POS : j, ++synced, newScope = newScopes[j], sources[j - newStart] = i, aNullable[i] = null); | ||
if (oldLength === oldScopes.length && synced === 0) { | ||
oldBranch = oldBranches[i], j = keyIndex.get(oldBranch), j !== void 0 && (pos = pos > j ? WRONG_POS : j, ++synced, newBranch = newBranches[j], sources[j - newStart] = i, aNullable[i] = null); | ||
if (oldLength === oldBranches.length && synced === 0) { | ||
for (; newStart < newLength; ++newStart) | ||
insertBefore(newScopes[newStart], parent, afterReference); | ||
insertBefore(newBranches[newStart], parent, afterReference); | ||
for (; oldStart < oldLength; ++oldStart) | ||
removeAndDestroyScope(oldScopes[oldStart]); | ||
removeAndDestroyBranch(oldBranches[oldStart]); | ||
} else { | ||
for (i = oldLength - synced; i > 0; ) | ||
oldScope = aNullable[oldStart++], oldScope !== null && (removeAndDestroyScope(oldScope), i--); | ||
oldBranch = aNullable[oldStart++], oldBranch !== null && (removeAndDestroyBranch(oldBranch), i--); | ||
if (pos === WRONG_POS) { | ||
let seq = longestIncreasingSubsequence(sources); | ||
for (j = seq.length - 1, k = newScopes.length, i = newLength - 1; i >= 0; --i) | ||
sources[i] === -1 ? (pos = i + newStart, newScope = newScopes[pos++], nextSibling = pos < k ? newScopes[pos].a : afterReference, insertBefore(newScope, parent, nextSibling)) : j < 0 || i !== seq[j] ? (pos = i + newStart, newScope = newScopes[pos++], nextSibling = pos < k ? newScopes[pos].a : afterReference, insertBefore(newScope, parent, nextSibling)) : --j; | ||
for (j = seq.length - 1, k = newBranches.length, i = newLength - 1; i >= 0; --i) | ||
sources[i] === -1 ? (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].a : afterReference, insertBefore(newBranch, parent, nextSibling)) : j < 0 || i !== seq[j] ? (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].a : afterReference, insertBefore(newBranch, parent, nextSibling)) : --j; | ||
} else if (synced !== newLength) | ||
for (k = newScopes.length, i = newLength - 1; i >= 0; --i) | ||
sources[i] === -1 && (pos = i + newStart, newScope = newScopes[pos++], nextSibling = pos < k ? newScopes[pos].a : afterReference, insertBefore(newScope, parent, nextSibling)); | ||
for (k = newBranches.length, i = newLength - 1; i >= 0; --i) | ||
sources[i] === -1 && (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].a : afterReference, insertBefore(newBranch, parent, nextSibling)); | ||
} | ||
@@ -654,2 +351,128 @@ } | ||
// src/common/meta.ts | ||
var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_"; | ||
// src/dom/resume.ts | ||
var registeredValues = {}, Render = class { | ||
o = []; | ||
p = {}; | ||
z = { | ||
_: registeredValues | ||
}; | ||
constructor(renders, runtimeId, renderId) { | ||
this.A = renders, this.B = runtimeId, this.q = renderId, this.s = renders[renderId], this.t(); | ||
} | ||
w() { | ||
this.s.w(), this.t(); | ||
} | ||
t() { | ||
let data2 = this.s, serializeContext = this.z, scopeLookup = this.p, visits = data2.v, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map(); | ||
if (visits.length) { | ||
let commentPrefixLen = data2.i.length, closestBranchMarkers = /* @__PURE__ */ new Map(); | ||
data2.v = []; | ||
let branchEnd = (branchId, visit, curNode) => { | ||
let branch = scopeLookup[branchId] ||= {}, endNode = curNode; | ||
for (; (endNode = endNode.previousSibling).nodeType === 8; ) ; | ||
branch.c = endNode, branch.a ||= endNode; | ||
for (let [markerScopeId, markerNode] of closestBranchMarkers) | ||
branch.a.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2 && (parentBranchIds.set(markerScopeId, branchId), closestBranchMarkers.delete(markerScopeId)); | ||
return branchIds.add(branchId), closestBranchMarkers.set(branchId, visit), branch; | ||
}; | ||
for (let visit of visits) { | ||
let commentText = visit.data, dataIndex = commentText.indexOf(" ") + 1, scopeId = commentText.slice( | ||
commentPrefixLen + 1, | ||
dataIndex ? dataIndex - 1 : commentText.length | ||
), scope = scopeLookup[scopeId] ||= {}, data3 = dataIndex ? commentText.slice(dataIndex) : "", token = commentText[commentPrefixLen]; | ||
if (token === "*" /* Node */) | ||
scope[data3] = visit.previousSibling; | ||
else if (token === "$" /* ClosestBranch */) | ||
closestBranchMarkers.set(scopeId, visit); | ||
else if (token === "[" /* BranchStart */) | ||
this.f && (dataIndex && branchEnd(this.f, visit, visit), this.o.push(this.f)), this.f = scopeId, scope.a = visit; | ||
else if (token === "]" /* BranchEnd */) { | ||
scope[data3] = visit; | ||
let curParent = visit.parentNode, startNode = branchEnd( | ||
this.f, | ||
visit, | ||
visit | ||
).a; | ||
curParent !== startNode.parentNode && curParent.prepend(startNode), this.f = this.o.pop(); | ||
} else if (token === "|" /* BranchSingleNode */) { | ||
let next = data3.indexOf(" "), curNode = scope[~next ? data3.slice(0, next) : data3] = visit; | ||
for (; ~next; ) { | ||
let start = next + 1; | ||
next = data3.indexOf(" ", start); | ||
let childScopeId = data3.slice(start, ~next ? next : data3.length); | ||
curNode = branchEnd(childScopeId, visit, curNode).c; | ||
} | ||
} | ||
} | ||
} | ||
let resumes = data2.r; | ||
if (resumes) { | ||
data2.r = []; | ||
let len = resumes.length, i = 0; | ||
try { | ||
for (isResuming = !0; i < len; ) { | ||
let resumeData = resumes[i++]; | ||
if (typeof resumeData == "function") { | ||
let scopes = resumeData(serializeContext), { $global } = scopeLookup; | ||
$global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = this.B, $global.renderId = this.q); | ||
for (let scopeId in scopes) | ||
if (scopeId !== "$") { | ||
let scope = scopes[scopeId], prevScope = scopeLookup[scopeId]; | ||
scope.$global = $global, prevScope !== scope && (scopeLookup[scopeId] = Object.assign( | ||
scope, | ||
prevScope | ||
)); | ||
let parentBranchId = parentBranchIds.get(scopeId); | ||
if (parentBranchId && (scope.b = scopes[parentBranchId]), branchIds.has(scopeId)) { | ||
let branch = scope, parentBranch = branch.b; | ||
scope.b = branch, parentBranch && (branch.C = parentBranch, (parentBranch.m ||= /* @__PURE__ */ new Set()).add(branch)); | ||
} | ||
} | ||
} else i === len || typeof resumes[i] != "string" ? delete this.A[this.q] : registeredValues[resumes[i++]]( | ||
scopeLookup[resumeData], | ||
scopeLookup[resumeData] | ||
); | ||
} | ||
} finally { | ||
isResuming = !1; | ||
} | ||
} | ||
} | ||
}, isResuming = !1; | ||
function register(id, obj) { | ||
return registeredValues[id] = obj, obj; | ||
} | ||
function registerBoundSignal(id, signal) { | ||
return registeredValues[id] = (scope) => (valueOrOp) => signal(scope, valueOrOp), signal; | ||
} | ||
function getRegisteredWithScope(id, scope) { | ||
let val = registeredValues[id]; | ||
return scope ? val(scope) : val; | ||
} | ||
function init(runtimeId = DEFAULT_RUNTIME_ID) { | ||
let resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId), renders; | ||
window[runtimeId] ? setRenders(window[runtimeId]) : Object.defineProperty(window, runtimeId, { | ||
configurable: !0, | ||
set: setRenders | ||
}); | ||
function setRenders(v) { | ||
renders = v; | ||
for (let renderId in v) | ||
resumeRender(renderId); | ||
Object.defineProperty(window, runtimeId, { | ||
configurable: !0, | ||
value: resumeRender | ||
}); | ||
} | ||
} | ||
function registerSubscriber(id, signal) { | ||
return register(id, signal.D), signal; | ||
} | ||
function nodeRef(id, key) { | ||
return register(id, (scope) => () => scope[key]); | ||
} | ||
// src/dom/controllable.ts | ||
@@ -708,6 +531,9 @@ function controllable_input_checked(scope, nodeAccessor, checked, checkedChange) { | ||
function controllable_select_value(scope, nodeAccessor, value2, valueChange) { | ||
scope[nodeAccessor + ";" /* ControlledHandler */] = valueChange, valueChange ? (scope[nodeAccessor + "=" /* ControlledType */] = 3 /* SelectValue */, scope[nodeAccessor + ":" /* ControlledValue */] = value2) : scope[nodeAccessor + "=" /* ControlledType */] = 5 /* None */, setSelectOptions( | ||
scope[nodeAccessor], | ||
value2, | ||
valueChange | ||
scope[nodeAccessor + ";" /* ControlledHandler */] = valueChange, valueChange ? (scope[nodeAccessor + "=" /* ControlledType */] = 3 /* SelectValue */, scope[nodeAccessor + ":" /* ControlledValue */] = value2) : scope[nodeAccessor + "=" /* ControlledType */] = 5 /* None */, pendingEffects.unshift( | ||
scope, | ||
() => setSelectOptions( | ||
scope[nodeAccessor], | ||
value2, | ||
valueChange | ||
) | ||
); | ||
@@ -861,4 +687,6 @@ } | ||
let el = scope[nodeAccessor]; | ||
for (let { name } of el.attributes) | ||
for (let i = el.attributes.length; i--; ) { | ||
let { name } = el.attributes.item(i); | ||
nextAttrs && (name in nextAttrs || hasAttrAlias(el, name, nextAttrs)) || el.removeAttribute(name); | ||
} | ||
attrsInternal(scope, nodeAccessor, nextAttrs); | ||
@@ -871,4 +699,6 @@ } | ||
let el = scope[nodeAccessor], partial = {}; | ||
for (let { name } of el.attributes) | ||
for (let i = el.attributes.length; i--; ) { | ||
let { name } = el.attributes.item(i); | ||
!skip[name] && !(nextAttrs && name in nextAttrs) && el.removeAttribute(name); | ||
} | ||
for (let key in nextAttrs) | ||
@@ -1013,7 +843,7 @@ skip[key] || (partial[key] = nextAttrs[key]); | ||
function walk(startNode, walkCodes, scope) { | ||
walker.currentNode = startNode, walkInternal(walkCodes, scope, scope, 0), walker.currentNode = document.documentElement; | ||
walker.currentNode = startNode, walkInternal(walkCodes, scope, 0), walker.currentNode = document; | ||
} | ||
function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) { | ||
function walkInternal(walkCodes, scope, currentWalkIndex) { | ||
let value2, storedMultiplier = 0, currentMultiplier = 0, currentScopeIndex = 0; | ||
for (cleanupOwnerScope !== scope && (scope.d = cleanupOwnerScope); value2 = walkCodes.charCodeAt(currentWalkIndex++); ) | ||
for (; value2 = walkCodes.charCodeAt(currentWalkIndex++); ) | ||
if (currentMultiplier = storedMultiplier, storedMultiplier = 0, value2 >= 117 /* Multiplier */) | ||
@@ -1031,10 +861,6 @@ storedMultiplier = currentMultiplier * 10 /* Multiplier */ + value2 - 117 /* Multiplier */; | ||
walker.nextNode(); | ||
else if (value2 === 47 /* BeginChild */) | ||
currentWalkIndex = walkInternal( | ||
walkCodes, | ||
scope[currentScopeIndex++] = createScope(scope.$global), | ||
cleanupOwnerScope, | ||
currentWalkIndex | ||
); | ||
else { | ||
else if (value2 === 47 /* BeginChild */) { | ||
let childScope = scope[currentScopeIndex++] = createScope(scope.$global); | ||
childScope.a = walker.currentNode, childScope.b = scope.b, currentWalkIndex = walkInternal(walkCodes, childScope, currentWalkIndex); | ||
} else { | ||
if (value2 === 38 /* EndChild */) | ||
@@ -1053,22 +879,31 @@ return currentWalkIndex; | ||
// src/dom/renderer.ts | ||
function createScopeWithRenderer(renderer, $global, ownerScope) { | ||
let newScope = createScope($global); | ||
if (newScope._ = newScope.d = renderer.B || ownerScope, newScope.x = renderer, initRenderer(renderer, newScope), renderer.c) | ||
for (let signal of renderer.c) | ||
signal.g?.(newScope); | ||
return newScope; | ||
function createBranchScopeWithRenderer(renderer, $global, parentScope) { | ||
let branch = createBranch( | ||
$global, | ||
renderer.u || parentScope, | ||
parentScope | ||
); | ||
return initRenderer(renderer, branch), branch; | ||
} | ||
function createScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, ownerScope) { | ||
function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, parentScope) { | ||
if (typeof tagNameOrRenderer != "string") | ||
return createScopeWithRenderer(tagNameOrRenderer, $global, ownerScope); | ||
let newScope = createScope($global); | ||
return newScope._ = newScope.d = ownerScope, newScope[0] = newScope.a = newScope.b = document.createElement(tagNameOrRenderer), newScope; | ||
return createBranchScopeWithRenderer( | ||
tagNameOrRenderer, | ||
$global, | ||
parentScope | ||
); | ||
let branch = createBranch($global, parentScope, parentScope); | ||
return branch[0] = branch.a = branch.c = document.createElement(tagNameOrRenderer), branch; | ||
} | ||
function createBranch($global, ownerScope, parentScope) { | ||
let branch = createScope($global), parentBranch = parentScope.b; | ||
return branch._ = ownerScope, branch.b = branch, parentBranch && (branch.C = parentBranch, (parentBranch.m ||= /* @__PURE__ */ new Set()).add(branch)), branch; | ||
} | ||
function initRenderer(renderer, scope) { | ||
let dom = renderer.k(); | ||
let dom = renderer.l(); | ||
return walk( | ||
dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom, | ||
renderer.C, | ||
renderer.E, | ||
scope | ||
), scope.a = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom, scope.b = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom, renderer.s && renderer.s(scope), dom; | ||
), scope.a = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom, scope.c = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom, renderer.x && queueRender(scope, renderer.x), dom; | ||
} | ||
@@ -1100,32 +935,23 @@ function dynamicTagAttrs(nodeAccessor, getContent, inputIsArgs) { | ||
} | ||
function createRendererWithOwner(template, rawWalks, setup, getClosureSignals, getArgs) { | ||
let args, closureSignals, id = {}, walks = rawWalks ? /* @__PURE__ */ trimWalkString(rawWalks) : " "; | ||
function createRendererWithOwner(template, rawWalks, setup, getArgs) { | ||
let args, id = {}, walks = rawWalks ? /* @__PURE__ */ trimWalkString(rawWalks) : " "; | ||
return (owner) => ({ | ||
t: id, | ||
D: template, | ||
C: walks, | ||
s: setup, | ||
k: _clone, | ||
B: owner, | ||
E: void 0, | ||
j: id, | ||
F: template, | ||
E: walks, | ||
x: setup, | ||
l: _clone, | ||
u: owner, | ||
G: void 0, | ||
get e() { | ||
return args ||= getArgs?.(); | ||
}, | ||
get c() { | ||
return closureSignals ||= new Set(getClosureSignals?.()); | ||
} | ||
}); | ||
} | ||
function createRenderer(template, walks, setup, getClosureSignals, getArgs) { | ||
return createRendererWithOwner( | ||
template, | ||
walks, | ||
setup, | ||
getClosureSignals, | ||
getArgs | ||
)(); | ||
function createRenderer(template, walks, setup, getArgs) { | ||
return createRendererWithOwner(template, walks, setup, getArgs)(); | ||
} | ||
function _clone() { | ||
return (this.E ||= parseHTMLOrSingleNode( | ||
this.D | ||
return (this.G ||= parseHTMLOrSingleNode( | ||
this.F | ||
)).cloneNode(!0); | ||
@@ -1139,3 +965,3 @@ } | ||
var conditional = function(nodeAccessor, fn, getIntersection) { | ||
let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op)); | ||
let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op)); | ||
return (scope, newRendererOrOp) => { | ||
@@ -1146,31 +972,17 @@ if (newRendererOrOp === DIRTY) return; | ||
let normalizedRenderer = normalizeDynamicRenderer(newRendererOrOp); | ||
isDifferentRenderer(normalizedRenderer, currentRenderer) ? (currentRenderer = scope[rendererAccessor] = normalizedRenderer, setConditionalRenderer(scope, nodeAccessor, normalizedRenderer), fn && fn(scope), op = DIRTY) : op = CLEAN; | ||
isDifferentRenderer(normalizedRenderer, currentRenderer) ? (setConditionalRenderer(scope, nodeAccessor, normalizedRenderer), fn && fn(scope), op = DIRTY) : op = CLEAN; | ||
} | ||
intersection2?.(scope, op), contentClosures(currentRenderer, scope[childScopeAccessor], op); | ||
intersection2?.(scope, op); | ||
}; | ||
}; | ||
function inConditionalScope(signal, nodeAccessor) { | ||
let scopeAccessor = nodeAccessor + "!" /* ConditionalScope */, rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */; | ||
return (scope, op) => { | ||
let conditionalScope = scope[scopeAccessor]; | ||
if (conditionalScope) { | ||
let conditionalRenderer = scope[rendererAccessor]; | ||
(!conditionalRenderer?.c || conditionalRenderer.c.has(signal)) && signal(conditionalScope, op); | ||
} | ||
}; | ||
} | ||
function setConditionalRenderer(scope, nodeAccessor, newRenderer) { | ||
let newScope, prevScope = scope[nodeAccessor + "!" /* ConditionalScope */]; | ||
newRenderer ? (newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithTagNameOrRenderer( | ||
newRenderer, | ||
scope.$global, | ||
scope | ||
), prevScope = prevScope || getEmptyScope(scope[nodeAccessor])) : (newScope = getEmptyScope(scope[nodeAccessor]), scope[nodeAccessor + "!" /* ConditionalScope */] = void 0), insertBefore( | ||
newScope, | ||
prevScope.a.parentNode, | ||
prevScope.a | ||
), removeAndDestroyScope(prevScope); | ||
let newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0, prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyScope(scope[nodeAccessor]); | ||
insertBefore( | ||
newBranch || getEmptyScope(scope[nodeAccessor]), | ||
prevBranch.a.parentNode, | ||
prevBranch.a | ||
), removeAndDestroyBranch(prevBranch), scope[nodeAccessor + "(" /* ConditionalRenderer */] = newRenderer, scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch; | ||
} | ||
var conditionalOnlyChild = function(nodeAccessor, fn, getIntersection) { | ||
let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op)); | ||
let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op)); | ||
return (scope, newRendererOrOp) => { | ||
@@ -1187,14 +999,12 @@ if (newRendererOrOp === DIRTY) return; | ||
} | ||
intersection2?.(scope, op), contentClosures(currentRenderer, scope[childScopeAccessor], op); | ||
intersection2?.(scope, op); | ||
}; | ||
}; | ||
function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) { | ||
let prevScope = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor]; | ||
if (referenceNode.textContent = "", newRenderer) { | ||
let newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope); | ||
insertBefore(newScope, referenceNode, null); | ||
} | ||
prevScope && destroyScope(prevScope); | ||
let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor], newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0; | ||
referenceNode.textContent = "", newBranch && insertBefore(newBranch, referenceNode, null), prevBranch && destroyBranch(prevBranch), scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch; | ||
} | ||
var emptyMarkerMap = /* @__PURE__ */ new Map([[Symbol(), getEmptyScope(void 0)]]), emptyMarkerArray = [ | ||
var emptyMarkerMap = /* @__PURE__ */ new Map([ | ||
[Symbol(), getEmptyScope(void 0)] | ||
]), emptyMarkerArray = [ | ||
/* @__PURE__ */ getEmptyScope(void 0) | ||
@@ -1229,13 +1039,10 @@ ], emptyMap = /* @__PURE__ */ new Map(), emptyArray = []; | ||
function loop(nodeAccessor, renderer, forEach) { | ||
let loopScopeAccessor = nodeAccessor + "!" /* LoopScopeArray */, closureSignals = renderer.c, params = renderer.e; | ||
let loopScopeAccessor = nodeAccessor + "!" /* LoopScopeArray */, params = renderer.e; | ||
return (scope, valueOrOp) => { | ||
if (valueOrOp === DIRTY) return; | ||
if (valueOrOp === MARK || valueOrOp === CLEAN) { | ||
let loopScopes = scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */]?.values() ?? []; | ||
if (loopScopes !== emptyMarkerArray) | ||
for (let childScope of loopScopes) { | ||
params?.(childScope, valueOrOp); | ||
for (let signal of closureSignals) | ||
signal(childScope, valueOrOp); | ||
} | ||
let loopBranches = scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */]?.values() ?? []; | ||
if (loopBranches !== emptyMarkerArray) | ||
for (let branch of loopBranches) | ||
params?.(branch, valueOrOp); | ||
return; | ||
@@ -1245,12 +1052,9 @@ } | ||
if (forEach(valueOrOp, (key, args) => { | ||
let childScope = oldMap.get(key), closureOp = CLEAN; | ||
if (childScope || (childScope = createScopeWithRenderer(renderer, scope.$global, scope), closureOp = DIRTY), params && params(childScope, args), closureSignals) | ||
for (let signal of closureSignals) | ||
signal(childScope, closureOp); | ||
newMap ? (newMap.set(key, childScope), newArray.push(childScope)) : (newMap = /* @__PURE__ */ new Map([[key, childScope]]), newArray = [childScope]); | ||
}), newMap || (referenceIsMarker ? (newMap = emptyMarkerMap, newArray = emptyMarkerArray, getEmptyScope(referenceNode)) : (oldArray.forEach(destroyScope), referenceNode.textContent = "", newMap = emptyMap, newArray = emptyArray, needsReconciliation = !1)), needsReconciliation) { | ||
let branch = oldMap.get(key); | ||
branch || (branch = createBranchScopeWithRenderer(renderer, scope.$global, scope)), params && params(branch, args), newMap ? (newMap.set(key, branch), newArray.push(branch)) : (newMap = /* @__PURE__ */ new Map([[key, branch]]), newArray = [branch]); | ||
}), newMap || (referenceIsMarker ? (newMap = emptyMarkerMap, newArray = emptyMarkerArray, getEmptyScope(referenceNode)) : (oldArray.forEach(destroyBranch), referenceNode.textContent = "", newMap = emptyMap, newArray = emptyArray, needsReconciliation = !1)), needsReconciliation) { | ||
if (referenceIsMarker) { | ||
oldMap === emptyMarkerMap && getEmptyScope(referenceNode); | ||
let oldLastChild = oldArray[oldArray.length - 1]; | ||
afterReference = oldLastChild.b.nextSibling, parentNode = oldLastChild.a.parentNode; | ||
afterReference = oldLastChild.c.nextSibling, parentNode = oldLastChild.a.parentNode; | ||
} else | ||
@@ -1263,11 +1067,2 @@ afterReference = null, parentNode = referenceNode; | ||
} | ||
function inLoopScope(signal, loopNodeAccessor) { | ||
let loopScopeAccessor = loopNodeAccessor + "!" /* LoopScopeArray */; | ||
return (scope, op) => { | ||
let loopScopes = scope[loopScopeAccessor] ?? scope[loopNodeAccessor + "(" /* LoopScopeMap */]?.values() ?? []; | ||
if (loopScopes !== emptyMarkerArray) | ||
for (let scope2 of loopScopes) | ||
signal(scope2, op); | ||
}; | ||
} | ||
function bySecondArg(_item, index) { | ||
@@ -1280,5 +1075,181 @@ return index; | ||
function isDifferentRenderer(a, b) { | ||
return a !== b && (a?.t || 0) !== b?.t; | ||
return a !== b && (a?.j || 0) !== b?.j; | ||
} | ||
// src/dom/signals.ts | ||
var MARK = {}, CLEAN = {}, DIRTY = {}; | ||
function state(valueAccessor, fn, getIntersection) { | ||
let valueSignal = value(valueAccessor, fn, getIntersection), markAccessor = valueAccessor + "#" /* Mark */, valueChangeAccessor = valueAccessor + "@" /* TagVariableChange */; | ||
return (scope, valueOrOp, valueChange) => (rendering ? valueSignal( | ||
scope, | ||
valueOrOp === MARK || valueOrOp === CLEAN || valueOrOp === DIRTY || (scope[valueChangeAccessor] = valueChange) || scope[markAccessor] === void 0 ? valueOrOp : CLEAN | ||
) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](valueOrOp) : queueSource(scope, valueSignal, valueOrOp), valueOrOp); | ||
} | ||
function value(valueAccessor, fn, getIntersection) { | ||
let markAccessor = valueAccessor + "#" /* Mark */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op)); | ||
return (scope, valueOrOp) => { | ||
if (valueOrOp === MARK) | ||
(scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK); | ||
else if (valueOrOp !== DIRTY) { | ||
let existing = scope[markAccessor] !== void 0; | ||
(scope[markAccessor] ||= 1) === 1 && (valueOrOp === CLEAN || existing && scope[valueAccessor] === valueOrOp ? intersection2?.(scope, CLEAN) : (scope[valueAccessor] = valueOrOp, fn && fn(scope, valueOrOp), intersection2?.(scope, DIRTY))), scope[markAccessor]--; | ||
} | ||
}; | ||
} | ||
var accessorId = 0; | ||
function intersection(count, fn, getIntersection) { | ||
let dirtyAccessor = "?" /* Dynamic */ + accessorId++, markAccessor = dirtyAccessor + "#" /* Mark */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op)); | ||
return (scope, op) => { | ||
op === MARK ? (scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK) : scope[markAccessor] === void 0 ? (scope[markAccessor] = count - 1, scope[dirtyAccessor] = !0) : --scope[markAccessor] === 0 ? op === DIRTY || scope[dirtyAccessor] ? (scope[dirtyAccessor] = !1, fn(scope, 0), intersection2?.(scope, DIRTY)) : intersection2?.(scope, CLEAN) : scope[dirtyAccessor] ||= op === DIRTY; | ||
}; | ||
} | ||
function closure(fn, getIntersection) { | ||
let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op)); | ||
return (scope, valueOrOp) => { | ||
valueOrOp === MARK ? intersection2?.(scope, MARK) : (fn && fn(scope, valueOrOp), intersection2?.(scope, DIRTY)); | ||
}; | ||
} | ||
function loopClosure(ownerLoopNodeAccessor, fn, getIntersection) { | ||
let signal = closure(fn, getIntersection), loopScopeAccessor = ownerLoopNodeAccessor + "!" /* LoopScopeArray */, loopScopeMapAccessor = ownerLoopNodeAccessor + "(" /* LoopScopeMap */, helperSignal = (ownerScope, value2) => { | ||
let loopScopes = ownerScope[loopScopeAccessor] ?? ownerScope[loopScopeMapAccessor]?.values() ?? []; | ||
if (loopScopes !== emptyMarkerArray) | ||
for (let scope of loopScopes) | ||
scope.g || queueSource(scope, signal, value2); | ||
}; | ||
return helperSignal._ = signal, helperSignal; | ||
} | ||
function conditionalClosure(ownerConditionalNodeAccessor, getRenderer, fn, getIntersection) { | ||
let signal = closure(fn, getIntersection), scopeAccessor = ownerConditionalNodeAccessor + "!" /* ConditionalScope */, rendererAccessor = ownerConditionalNodeAccessor + "(" /* ConditionalRenderer */, helperSignal = (scope, value2) => { | ||
let conditionalScope = scope[scopeAccessor]; | ||
conditionalScope && !conditionalScope.g && scope[rendererAccessor]?.j === getRenderer().j && queueSource(conditionalScope, signal, value2); | ||
}; | ||
return helperSignal._ = signal, helperSignal; | ||
} | ||
var defaultGetOwnerScope = (scope) => scope._; | ||
function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) { | ||
let ownerSubscribersAccessor = ownerValueAccessor + "*" /* Subscribers */, _signal = closure(fn, getIntersection), helperSignal = (ownerScope, value2) => { | ||
let subscribers = ownerScope[ownerSubscribersAccessor]; | ||
if (subscribers) | ||
for (let subscriber of subscribers) | ||
subscriber.g || queueSource(subscriber, _signal, value2); | ||
}, setupSignal = (scope, value2) => { | ||
_signal(scope, value2), subscribe(scope); | ||
}, subscribe = (scope) => { | ||
(getOwnerScope(scope)[ownerSubscribersAccessor] ||= /* @__PURE__ */ new Set()).add(scope), getAbortSignal(scope, -1).addEventListener("abort", () => { | ||
getOwnerScope(scope)[ownerSubscribersAccessor].delete(scope); | ||
}); | ||
}; | ||
return helperSignal._ = setupSignal, helperSignal.D = subscribe, helperSignal; | ||
} | ||
function setTagVar(scope, childAccessor, tagVarSignal2) { | ||
scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp); | ||
} | ||
var tagVarSignal = (scope, valueOrOp) => scope["/" /* TagVariable */]?.(valueOrOp); | ||
function setTagVarChange(scope, changeHandler) { | ||
scope["@" /* TagVariableChange */] = changeHandler; | ||
} | ||
var tagVarSignalChange = (scope, value2) => scope["@" /* TagVariableChange */]?.(value2); | ||
var tagIdsByGlobal = /* @__PURE__ */ new WeakMap(); | ||
function nextTagId({ $global }) { | ||
let id = tagIdsByGlobal.get($global) || 0; | ||
return tagIdsByGlobal.set($global, id + 1), "c" + $global.runtimeId + $global.renderId + id.toString(36); | ||
} | ||
function inChild(childAccessor, signal) { | ||
return (scope, valueOrOp) => { | ||
signal(scope[childAccessor], valueOrOp); | ||
}; | ||
} | ||
function intersections(signals) { | ||
return (scope, op) => { | ||
for (let signal of signals) | ||
signal(scope, op); | ||
}; | ||
} | ||
function effect(id, fn) { | ||
return register(id, fn), (scope) => { | ||
queueEffect(scope, fn); | ||
}; | ||
} | ||
// src/dom/queue.ts | ||
var pendingRender, pendingEffects = [], rendering = !1; | ||
function queueSource(scope, signal, value2) { | ||
schedule(); | ||
let prevRendering = rendering; | ||
return rendering = !0, signal(scope, MARK), rendering = prevRendering, queueRender(scope, signal, value2), value2; | ||
} | ||
function queueRender(scope, signal, value2) { | ||
let nextRender = { | ||
k: scope, | ||
H: signal, | ||
I: value2, | ||
d: void 0 | ||
}; | ||
if (!pendingRender) | ||
pendingRender = nextRender; | ||
else if (comparePendingRenders(pendingRender, nextRender) < 0) | ||
nextRender.d = pendingRender, pendingRender = nextRender; | ||
else { | ||
let curRender = pendingRender; | ||
for (; curRender.d && comparePendingRenders(curRender.d, nextRender) >= 0; ) | ||
curRender = curRender.d; | ||
nextRender.d = curRender.d, curRender.d = nextRender; | ||
} | ||
} | ||
function queueEffect(scope, fn) { | ||
pendingEffects.push(scope, fn); | ||
} | ||
function run() { | ||
let effects = pendingEffects; | ||
try { | ||
rendering = !0, runRenders(); | ||
} finally { | ||
pendingRender = void 0, rendering = !1; | ||
} | ||
pendingEffects = [], runEffects(effects); | ||
} | ||
function prepareEffects(fn) { | ||
let prevRender = pendingRender, prevEffects = pendingEffects, preparedEffects = pendingEffects = []; | ||
pendingRender = void 0; | ||
try { | ||
rendering = !0, fn(), runRenders(); | ||
} finally { | ||
rendering = !1, pendingRender = prevRender, pendingEffects = prevEffects; | ||
} | ||
return preparedEffects; | ||
} | ||
function runEffects(effects = pendingEffects) { | ||
for (let i = 0; i < effects.length; i += 2 /* Total */) { | ||
let scope = effects[i], fn = effects[i + 1]; | ||
fn(scope, scope); | ||
} | ||
} | ||
function runRenders() { | ||
for (; pendingRender; ) | ||
pendingRender.k.b?.y || pendingRender.H(pendingRender.k, pendingRender.I), pendingRender = pendingRender.d; | ||
finishPendingScopes(); | ||
} | ||
function comparePendingRenders(a, b) { | ||
let aStart = ownerStartNode(a.k), bStart = ownerStartNode(b.k); | ||
return aStart === bStart ? 0 : aStart ? bStart ? aStart.compareDocumentPosition(bStart) & 2 ? -1 : 1 : -1 : 1; | ||
} | ||
function ownerStartNode(scope) { | ||
return (scope.b || scope).a; | ||
} | ||
// src/dom/abort-signal.ts | ||
function resetAbortSignal(scope, id) { | ||
let ctrl = scope.h?.[id]; | ||
ctrl && (queueEffect(ctrl, abort), scope.h[id] = void 0); | ||
} | ||
function getAbortSignal(scope, id) { | ||
return scope.b && (scope.b.n ||= /* @__PURE__ */ new Set()).add(scope), ((scope.h ||= {})[id] ||= new AbortController()).signal; | ||
} | ||
function abort(ctrl) { | ||
ctrl.abort(); | ||
} | ||
// src/common/compat-meta.ts | ||
var prefix = "$C_", RENDERER_REGISTER_ID = prefix + "r", SET_SCOPE_REGISTER_ID = prefix + "s"; | ||
// src/dom/compat.ts | ||
@@ -1300,3 +1271,3 @@ var classIdToScope = /* @__PURE__ */ new Map(), compat = { | ||
isRenderer(renderer) { | ||
return renderer.k !== void 0; | ||
return renderer.l !== void 0; | ||
}, | ||
@@ -1307,3 +1278,3 @@ getStartNode(scope) { | ||
setScopeNodes(scope, startNode, endNode) { | ||
scope.a = startNode, scope.b = endNode; | ||
scope.a = startNode, scope.c = endNode; | ||
}, | ||
@@ -1313,2 +1284,5 @@ runComponentEffects() { | ||
}, | ||
runComponentDestroy() { | ||
this.scope && destroyBranch(this.scope); | ||
}, | ||
resolveRegistered(value2, { | ||
@@ -1320,14 +1294,8 @@ runtimeId, | ||
value2[0], | ||
value2.length === 2 && window[runtimeId]?.[componentIdPrefix === "s" ? "_" : componentIdPrefix]?.n[value2[1]] | ||
value2.length === 2 && window[runtimeId]?.[componentIdPrefix === "s" ? "_" : componentIdPrefix]?.p[value2[1]] | ||
) : value2; | ||
}, | ||
createRenderer(setup, clone, args) { | ||
let renderer = createRenderer( | ||
"", | ||
void 0, | ||
setup, | ||
void 0, | ||
args && (() => args) | ||
); | ||
return renderer.k = clone, renderer; | ||
let renderer = createRenderer("", void 0, setup, args && (() => args)); | ||
return renderer.l = clone, renderer; | ||
}, | ||
@@ -1344,14 +1312,5 @@ render(out, component, renderer, args) { | ||
if (component.effects = prepareEffects(() => { | ||
if (scope) | ||
applyArgs(scope, MARK), existing = !0; | ||
else { | ||
scope = component.scope = createScopeWithRenderer(renderer, out.global); | ||
let closures = renderer.c; | ||
if (closures) | ||
for (let signal of closures) | ||
signal(component.scope, CLEAN); | ||
} | ||
applyArgs(scope, args); | ||
scope ? (applyArgs(scope, MARK), existing = !0) : (scope = component.scope = createScope(out.global), scope._ = renderer.u, initRenderer(renderer, scope)), applyArgs(scope, args); | ||
}), !existing) | ||
return scope.a === scope.b ? scope.a : scope.a.parentNode; | ||
return scope.a === scope.c ? scope.a : scope.a.parentNode; | ||
} | ||
@@ -1368,3 +1327,3 @@ }; | ||
function mount(input = {}, reference, position) { | ||
let scope, dom, { $global } = input; | ||
let branch, dom, { $global } = input; | ||
$global ? ({ $global, ...input } = input, $global = { | ||
@@ -1379,3 +1338,3 @@ runtimeId: DEFAULT_RUNTIME_ID, | ||
let args = this.e, effects = prepareEffects(() => { | ||
scope = createScope($global), dom = initRenderer(this, scope), args && args(scope, [input]); | ||
branch = createScope($global), dom = initRenderer(this, branch), args && args(branch, [input]); | ||
}); | ||
@@ -1400,3 +1359,3 @@ switch (position) { | ||
prepareEffects(() => { | ||
args(scope, MARK), args(scope, [newInput]); | ||
args(branch, MARK), args(branch, [newInput]); | ||
}) | ||
@@ -1406,5 +1365,5 @@ ); | ||
destroy: () => { | ||
removeAndDestroyScope(scope); | ||
removeAndDestroyBranch(branch); | ||
} | ||
}; | ||
} |
import type { Scope } from "../common/types"; | ||
export declare function resetAbortSignal(scope: Scope, id: string | number): void; | ||
export declare function getAbortSignal(scope: Scope, id: string | number): any; | ||
export declare function getAbortSignal(scope: Scope, id: string | number): AbortSignal; |
@@ -14,2 +14,3 @@ import { patchConditionals } from "./control-flow"; | ||
runComponentEffects(this: any): void; | ||
runComponentDestroy(this: any): void; | ||
resolveRegistered(value: any, { runtimeId, componentIdPrefix, }: { | ||
@@ -16,0 +17,0 @@ runtimeId: string; |
@@ -1,14 +0,12 @@ | ||
import { type Accessor, type Scope } from "../common/types"; | ||
import { type Accessor, type BranchScope, type Scope } from "../common/types"; | ||
import { type Renderer } from "./renderer"; | ||
import { type IntersectionSignal, type SignalOp, type ValueSignal } from "./signals"; | ||
import { type Signal, type SignalOp } from "./signals"; | ||
export declare function patchConditionals(fn: <T extends typeof conditional | typeof conditionalOnlyChild>(cond: T) => T): void; | ||
export declare let conditional: (nodeAccessor: Accessor, fn?: ((scope: Scope) => void) | 0, getIntersection?: () => IntersectionSignal) => ValueSignal<Renderer | string | undefined>; | ||
export declare function inConditionalScope<S extends Scope>(signal: IntersectionSignal, nodeAccessor: Accessor): IntersectionSignal; | ||
export declare function setConditionalRenderer<ChildScope extends Scope>(scope: Scope, nodeAccessor: Accessor, newRenderer: Renderer | string | undefined): void; | ||
export declare let conditionalOnlyChild: (nodeAccessor: Accessor, fn?: ((scope: Scope) => void) | 0, getIntersection?: () => IntersectionSignal) => ValueSignal<Renderer | string | undefined>; | ||
export declare let conditional: (nodeAccessor: Accessor, fn?: ((scope: Scope) => void) | 0, getIntersection?: () => Signal<never>) => Signal<Renderer | string | undefined>; | ||
export declare function setConditionalRenderer(scope: Scope, nodeAccessor: Accessor, newRenderer: Renderer | string | undefined): void; | ||
export declare let conditionalOnlyChild: (nodeAccessor: Accessor, fn?: ((scope: Scope) => void) | 0, getIntersection?: () => Signal<never>) => Signal<Renderer | string | undefined>; | ||
export declare function setConditionalRendererOnlyChild(scope: Scope, nodeAccessor: Accessor, newRenderer: Renderer | string | undefined): void; | ||
export declare const emptyMarkerArray: Scope[]; | ||
export declare const emptyMarkerArray: BranchScope[]; | ||
export declare function loopOf(nodeAccessor: Accessor, renderer: Renderer): (scope: Scope, valueOrOp: SignalOp | [all: unknown[], by?: ((item: unknown, index: number) => unknown) | undefined]) => void; | ||
export declare function loopIn(nodeAccessor: Accessor, renderer: Renderer): (scope: Scope, valueOrOp: SignalOp | [obj: {}, by?: ((key: string, v: unknown) => unknown) | undefined]) => void; | ||
export declare function loopTo(nodeAccessor: Accessor, renderer: Renderer): (scope: Scope, valueOrOp: SignalOp | [to: number, from: number, step: number, by?: ((v: number) => unknown) | undefined]) => void; | ||
export declare function inLoopScope(signal: IntersectionSignal, loopNodeAccessor: Accessor): (scope: Scope, op: SignalOp) => void; |
import type { Scope } from "../common/types"; | ||
import { type ValueSignal } from "./signals"; | ||
import { type Signal } from "./signals"; | ||
type ExecFn<S extends Scope = Scope> = (scope: S, arg?: any) => void; | ||
export declare let pendingEffects: unknown[]; | ||
export declare let rendering: boolean; | ||
export declare function queueSource<T>(scope: Scope, signal: ValueSignal, value: T): T; | ||
export declare function queueSource<T>(scope: Scope, signal: Signal<T>, value: T): T; | ||
export declare function queueRender(scope: Scope, signal: Signal<any>, value?: unknown): void; | ||
export declare function queueEffect<S extends Scope, T extends ExecFn<S>>(scope: S, fn: T): void; | ||
@@ -7,0 +9,0 @@ export declare function run(): void; |
@@ -1,2 +0,2 @@ | ||
import type { Scope } from "../common/types"; | ||
export declare function reconcile(parent: Node & ParentNode, oldScopes: Scope[], newScopes: Scope[], afterReference: Node | null): void; | ||
import type { BranchScope } from "../common/types"; | ||
export declare function reconcile(parent: Node & ParentNode, oldBranches: BranchScope[], newBranches: BranchScope[], afterReference: Node | null): void; |
@@ -1,3 +0,3 @@ | ||
import { type Accessor, type Scope } from "../common/types"; | ||
import { type IntersectionSignal, type SignalOp, type ValueSignal } from "./signals"; | ||
import { type Accessor, type BranchScope, type Scope } from "../common/types"; | ||
import { type Signal, type SignalOp } from "./signals"; | ||
export type Renderer = { | ||
@@ -8,15 +8,14 @@ ___id: symbol; | ||
___setup: SetupFn | undefined; | ||
___closureSignals: Set<IntersectionSignal>; | ||
___clone: () => Node; | ||
___sourceNode: Node | undefined; | ||
___args: ValueSignal | undefined; | ||
___args: Signal<unknown> | undefined; | ||
___owner: Scope | undefined; | ||
}; | ||
type SetupFn = (scope: Scope) => void; | ||
export declare function createScopeWithRenderer(renderer: Renderer, $global: Scope["___global"], ownerScope?: Scope): Scope; | ||
export declare function createScopeWithTagNameOrRenderer(tagNameOrRenderer: Renderer | string, $global: Scope["___global"], ownerScope?: Scope): Scope; | ||
export declare function createBranchScopeWithRenderer(renderer: Renderer, $global: Scope["$global"], parentScope: Scope): BranchScope; | ||
export declare function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer: Renderer | string, $global: Scope["$global"], parentScope: Scope): BranchScope; | ||
export declare function initRenderer(renderer: Renderer, scope: Scope): Node; | ||
export declare function dynamicTagAttrs(nodeAccessor: Accessor, getContent?: (scope: Scope) => Renderer, inputIsArgs?: boolean): (scope: Scope, attrsOrOp: (() => Record<string, unknown>) | SignalOp) => void; | ||
export declare function createRendererWithOwner(template: string, rawWalks?: string, setup?: SetupFn, getClosureSignals?: () => IntersectionSignal[], getArgs?: () => ValueSignal): (owner?: Scope) => Renderer; | ||
export declare function createRenderer(template: string, walks?: string, setup?: SetupFn, getClosureSignals?: () => IntersectionSignal[], getArgs?: () => ValueSignal): Renderer; | ||
export declare function createRendererWithOwner(template: string, rawWalks?: string, setup?: SetupFn, getArgs?: () => Signal<unknown>): (owner?: Scope) => Renderer; | ||
export declare function createRenderer(template: string, walks?: string, setup?: SetupFn, getArgs?: () => Signal<unknown>): Renderer; | ||
export {}; |
import { type Scope } from "../common/types"; | ||
import type { IntersectionSignal, ValueSignal } from "./signals"; | ||
import type { Signal } from "./signals"; | ||
export declare let isResuming: boolean; | ||
export declare function register<T>(id: string, obj: T): T; | ||
export declare function registerBoundSignal<T extends ValueSignal>(id: string, signal: T): T; | ||
export declare function registerBoundSignal<T extends Signal<unknown>>(id: string, signal: T): T; | ||
export declare function getRegisteredWithScope(id: string, scope?: Scope): unknown; | ||
export declare function init(runtimeId?: string): void; | ||
export declare function registerSubscriber(id: string, signal: IntersectionSignal): IntersectionSignal; | ||
export declare function registerSubscriber(id: string, signal: Signal<never>): Signal<never>; | ||
export declare function nodeRef(id: string, key: string): (scope: Scope) => () => any; |
@@ -1,7 +0,7 @@ | ||
import type { Scope } from "../common/types"; | ||
import type { BranchScope, Scope } from "../common/types"; | ||
export declare function createScope($global: Scope["$global"]): Scope; | ||
export declare function finishPendingScopes(): void; | ||
export declare function getEmptyScope(marker: Comment): Scope; | ||
export declare function destroyScope(scope: Scope): Scope; | ||
export declare function onDestroy(scope: Scope): void; | ||
export declare function removeAndDestroyScope(scope: Scope): void; | ||
export declare function destroyBranch(branch: BranchScope): void; | ||
export declare function removeAndDestroyBranch(branch: BranchScope): void; | ||
export declare function insertBefore(scope: Scope, parent: Node & ParentNode, nextSibling: Node | null): void; |
import { type Accessor, type Scope } from "../common/types"; | ||
import type { Renderer } from "./renderer"; | ||
export type Signal = ValueSignal | IntersectionSignal; | ||
export declare const MARK: unique symbol; | ||
@@ -8,33 +7,21 @@ export declare const CLEAN: unique symbol; | ||
export type SignalOp = typeof MARK | typeof CLEAN | typeof DIRTY; | ||
export type SignalFn<T = unknown> = (scope: Scope, value: T) => void; | ||
export type ValueSignal<T = unknown> = SignalFn<T | SignalOp>; | ||
export type BoundValueSignal<T = unknown> = (valueOrOp: T | SignalOp) => void; | ||
export type IntersectionSignal = SignalFn<SignalOp> & { | ||
export type SignalFn<T> = (scope: Scope, value: T) => void; | ||
export type Signal<T> = ((scope: Scope, value: T | SignalOp) => void) & { | ||
___subscribe?(scope: Scope): void; | ||
___unsubscribe?(scope: Scope): void; | ||
}; | ||
export type BoundIntersectionSignal = ((op?: SignalOp) => void) & { | ||
___subscribe?(scope: Scope): void; | ||
___unsubscribe?(scope: Scope): void; | ||
}; | ||
export declare function state<T>(valueAccessor: Accessor, fn: ValueSignal<T>, getIntersection?: () => IntersectionSignal): (scope: Scope, valueOrOp: T | SignalOp, valueChange?: (v: T) => void) => SignalOp | T; | ||
export declare function value<T>(valueAccessor: Accessor, fn: SignalFn<T> | 0, getIntersection?: () => IntersectionSignal): ValueSignal<T>; | ||
export declare function intersection(count: number, fn: SignalFn<never>, getIntersection?: () => IntersectionSignal): IntersectionSignal; | ||
export declare function closure<T>(ownerValueAccessor: Accessor | ((scope: Scope) => Accessor), fn: SignalFn<T> | 0, getOwnerScope?: (scope: Scope) => Scope, getIntersection?: () => IntersectionSignal): IntersectionSignal; | ||
export declare function dynamicClosure<T>(ownerValueAccessor: Accessor | ((scope: Scope) => Accessor), fn: ValueSignal<T> | 0, getOwnerScope?: (scope: Scope) => Scope, getIntersection?: () => IntersectionSignal): IntersectionSignal; | ||
export declare function childClosures(closureSignals: IntersectionSignal[], childAccessor: Accessor): { | ||
(scope: Scope, op: SignalOp): void; | ||
___subscribe(scope: Scope): void; | ||
___unsubscribe(scope: Scope): void; | ||
}; | ||
export declare function dynamicSubscribers(valueAccessor: Accessor): (scope: Scope, op: SignalOp) => void; | ||
export declare function setTagVar(scope: Scope, childAccessor: Accessor, tagVarSignal: ValueSignal): void; | ||
export declare function state<T>(valueAccessor: Accessor, fn: Signal<T>, getIntersection?: () => Signal<never>): (scope: Scope, valueOrOp: T | SignalOp, valueChange?: (v: T) => void) => SignalOp | T; | ||
export declare function value<T>(valueAccessor: Accessor, fn: SignalFn<T> | 0, getIntersection?: () => Signal<never>): Signal<T>; | ||
export declare function intersection(count: number, fn: SignalFn<never>, getIntersection?: () => Signal<never>): Signal<never>; | ||
export declare function closure<T>(fn: SignalFn<T> | 0, getIntersection?: () => Signal<never>): Signal<T>; | ||
export declare function loopClosure<T>(ownerLoopNodeAccessor: Accessor, fn: SignalFn<T> | 0, getIntersection?: () => Signal<never>): SignalFn<T>; | ||
export declare function conditionalClosure<T>(ownerConditionalNodeAccessor: Accessor, getRenderer: () => Renderer, fn: SignalFn<T> | 0, getIntersection?: () => Signal<never>): SignalFn<T>; | ||
export declare function dynamicClosure<T>(ownerValueAccessor: Accessor, fn: Signal<T> | 0, getOwnerScope?: (scope: Scope) => Scope, getIntersection?: () => Signal<never>): SignalFn<T>; | ||
export declare function setTagVar(scope: Scope, childAccessor: Accessor, tagVarSignal: Signal<unknown>): void; | ||
export declare const tagVarSignal: (scope: Scope, valueOrOp: unknown | SignalOp) => any; | ||
export declare function setTagVarChange(scope: Scope, changeHandler: (value: unknown) => void): void; | ||
export declare const tagVarSignalChange: (scope: Scope, value: unknown) => any; | ||
export declare const contentClosures: (content: Renderer | string | undefined, childScope: Scope, op: SignalOp) => void; | ||
export declare const inMany: (scopes: Scope[], op: SignalOp, signal: IntersectionSignal) => void; | ||
export declare const inMany: (scopes: Scope[], op: SignalOp, signal: Signal<never>) => void; | ||
export declare function nextTagId({ $global }: Scope): string; | ||
export declare function inChild(childAccessor: Accessor, signal: ValueSignal): (scope: Scope, valueOrOp: unknown | SignalOp) => void; | ||
export declare function intersections(signals: IntersectionSignal[]): IntersectionSignal; | ||
export declare function inChild(childAccessor: Accessor, signal: Signal<unknown>): (scope: Scope, valueOrOp: unknown | SignalOp) => void; | ||
export declare function intersections(signals: Signal<never>[]): Signal<never>; | ||
export declare function effect(id: string, fn: (scope: Scope) => void): (scope: Scope) => void; |
@@ -1,3 +0,3 @@ | ||
import type { Scope, Template } from "../common/types"; | ||
import type { Template } from "../common/types"; | ||
import { createRenderer } from "./renderer"; | ||
export declare const createTemplate: (templateId: string, template: string, walks?: string | undefined, setup?: ((scope: Scope) => void) | undefined, getClosureSignals?: (() => import("./signals").IntersectionSignal[]) | undefined, getArgs?: (() => import("./signals").ValueSignal) | undefined) => Template; | ||
export declare const createTemplate: (templateId: string, template: string, walks?: string | undefined, setup?: ((scope: import("../dom").Scope) => void) | undefined, getArgs?: (() => import("./signals").Signal<unknown>) | undefined) => Template; |
@@ -9,2 +9,2 @@ export { attrTag, attrTags } from "./common/attr-tag"; | ||
export { createTemplate } from "./html/template"; | ||
export { $global, ensureScopeWithId, fork, getScopeById, markResumeCleanup, markResumeControlEnd, markResumeControlSingleNodeEnd, markResumeNode, markResumeScopeStart, nextScopeId, nextTagId, nodeRef, peekNextScope, register, tryContent, write, writeEffect, writeExistingScope, writeScope, writeTrailers, } from "./html/writer"; | ||
export { $global, ensureScopeWithId, fork, getScopeById, markResumeNode, nextScopeId, nextTagId, nodeRef, peekNextScope, register, resumeClosestBranch, resumeConditional, resumeForIn, resumeForOf, resumeForTo, resumeSingleNodeConditional, resumeSingleNodeForIn, resumeSingleNodeForOf, resumeSingleNodeForTo, tryContent, write, writeEffect, writeExistingScope, writeScope, writeTrailers, } from "./html/writer"; |
@@ -0,3 +1,3 @@ | ||
import type { Accessor } from "../common/types"; | ||
import type { ServerRenderer } from "./template"; | ||
import { type PartialScope } from "./writer"; | ||
interface BodyContentObject { | ||
@@ -7,4 +7,4 @@ [x: PropertyKey]: unknown; | ||
} | ||
export declare function dynamicTagInput(scope: PartialScope, tag: unknown | string | ServerRenderer | BodyContentObject, input: Record<string, unknown>, content?: () => void, tagVar?: unknown): unknown; | ||
export declare function dynamicTagArgs(scope: PartialScope, tag: unknown | string | ServerRenderer | BodyContentObject, args: unknown[]): unknown; | ||
export declare function dynamicTagInput(scopeId: number, accessor: Accessor, tag: unknown | string | ServerRenderer | BodyContentObject, input: Record<string, unknown>, content?: () => void, tagVar?: unknown): undefined; | ||
export declare function dynamicTagArgs(scopeId: number, accessor: Accessor, tag: unknown | string | ServerRenderer | BodyContentObject, args: unknown[]): undefined; | ||
declare let getDynamicRenderer: (value: any) => string | ServerRenderer | undefined; | ||
@@ -11,0 +11,0 @@ export declare let createRenderer: (fn: ServerRenderer) => ServerRenderer; |
@@ -1,2 +0,2 @@ | ||
import type { $Global, Accessor } from "../common/types"; | ||
import { type $Global, type Accessor, type Falsy, ResumeSymbol } from "../common/types"; | ||
import { Serializer } from "./serializer"; | ||
@@ -11,8 +11,3 @@ export type PartialScope = Record<Accessor, unknown>; | ||
PlaceholderEnd = "!", | ||
ReorderMarker = "#", | ||
SectionStart = "[", | ||
SectionEnd = "]", | ||
SectionSingleNodesEnd = "|", | ||
Node = "*", | ||
Cleanup = "$" | ||
ReorderMarker = "#" | ||
} | ||
@@ -33,6 +28,11 @@ export declare function getChunk(): Chunk | undefined; | ||
export declare function nodeRef(scopeId: number, id?: string): () => void; | ||
export declare function markResumeScopeStart(scopeId: number, index?: number): string; | ||
export declare function markResumeControlEnd(scopeId: number, accessor: Accessor): string; | ||
export declare function markResumeControlSingleNodeEnd(scopeId: number, accessor: Accessor, childScopeIds?: number | number[]): string; | ||
export declare function markResumeCleanup(scopeId: number): string; | ||
export declare function resumeClosestBranch(scopeId: number): void; | ||
export declare function resumeForOf(list: Falsy | Iterable<unknown>, cb: (item: unknown, index: number) => void, scopeId: number, accessor: Accessor): void; | ||
export declare function resumeSingleNodeForOf(list: Falsy | Iterable<unknown>, cb: (item: unknown, index: number) => void, scopeId: number, accessor: Accessor): void; | ||
export declare function resumeForIn(obj: Falsy | {}, cb: (key: string, value: unknown) => void, scopeId: number, accessor: Accessor): void; | ||
export declare function resumeSingleNodeForIn(obj: Falsy | {}, cb: (key: string, value: unknown) => void, scopeId: number, accessor: Accessor): void; | ||
export declare function resumeForTo(to: number, from: number | Falsy, step: number | Falsy, cb: (index: number) => void, scopeId: number, accessor: Accessor): void; | ||
export declare function resumeSingleNodeForTo(to: number, from: number | Falsy, step: number | Falsy, cb: (index: number) => void, scopeId: number, accessor: Accessor): void; | ||
export declare function resumeConditional(cb: () => void | number, scopeId: number, accessor: Accessor): void; | ||
export declare function resumeSingleNodeConditional(cb: () => void | number, scopeId: number, accessor: Accessor): void; | ||
export declare function writeScope(scopeId: number, partialScope: PartialScope): ScopeInternals; | ||
@@ -84,3 +84,3 @@ export declare function writeExistingScope(scope: ScopeInternals): ScopeInternals; | ||
nextReorderId(): string; | ||
mark(code: Mark, str: string): string; | ||
mark(code: ResumeSymbol | Mark, str: string): string; | ||
} | ||
@@ -87,0 +87,0 @@ export declare class Boundary extends AbortController { |
@@ -5,3 +5,2 @@ import { types as t } from "@marko/compiler"; | ||
declare const kForMarkerBinding: unique symbol; | ||
declare const kForScopeStartIndex: unique symbol; | ||
declare const kOnlyChildInParent: unique symbol; | ||
@@ -11,3 +10,2 @@ declare module "@marko/compiler/dist/types" { | ||
[kForMarkerBinding]?: Binding; | ||
[kForScopeStartIndex]?: t.Identifier; | ||
[kOnlyChildInParent]?: boolean; | ||
@@ -14,0 +12,0 @@ } |
import { types as t } from "@marko/compiler"; | ||
import type { Falsy } from "../../common/types"; | ||
import { attr, classAttr, escapeScript, escapeStyle, escapeXML, styleAttr, toString } from "../../html"; | ||
type Falsy = false | 0 | "" | null | undefined; | ||
export declare function importRuntime(name: keyof typeof import("../../dom") | keyof typeof import("../../html")): t.MemberExpression; | ||
@@ -16,2 +16,1 @@ export declare function callRuntime(name: keyof typeof import("../../dom") | keyof typeof import("../../html"), ...args: Array<Parameters<typeof t.callExpression>[1][number] | Falsy>): t.CallExpression; | ||
export declare function getCompatRuntimeFile(): string; | ||
export {}; |
@@ -19,3 +19,4 @@ import { types as t } from "@marko/compiler"; | ||
upstreamExpression: t.NodeExtra | undefined; | ||
hasCleanup: boolean; | ||
hasAbortSignal: boolean; | ||
isBranch: boolean; | ||
content: null | { | ||
@@ -22,0 +23,0 @@ startType: ContentType; |
@@ -5,3 +5,3 @@ import { types as t } from "@marko/compiler"; | ||
import { type Section } from "./sections"; | ||
export type subscribeBuilder = (subscriber: t.Expression) => t.Expression; | ||
export type closureSignalBuilder = (signal: Signal, render: t.Expression, intersection?: t.Expression) => t.Expression; | ||
export type registerScopeBuilder = (scope: t.Expression) => t.Expression; | ||
@@ -39,3 +39,3 @@ export type Signal = { | ||
}; | ||
export declare function setSubscriberBuilder(tag: t.NodePath<t.MarkoTag>, builder: subscribeBuilder): void; | ||
export declare function setClosureSignalBuilder(tag: t.NodePath<t.MarkoTag>, builder: closureSignalBuilder): void; | ||
export declare function setForceResumeScope(section: Section): void; | ||
@@ -42,0 +42,0 @@ export declare const getSerializedScopeProperties: (section: Section) => Map<t.StringLiteral | t.NumericLiteral, t.Expression>; |
{ | ||
"name": "marko", | ||
"version": "6.0.0-next.3.22", | ||
"version": "6.0.0-next.3.23", | ||
"description": "Optimized runtime for Marko templates.", | ||
@@ -51,3 +51,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@marko/compiler": "^5.39.9", | ||
"@marko/compiler": "^5.39.11", | ||
"csstype": "^3.1.3", | ||
@@ -54,0 +54,0 @@ "magic-string": "^0.30.17" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1091883
31046
Updated@marko/compiler@^5.39.11