frosty 0.0.113 → 0.0.115
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/_native.d.mts +1 -1
- package/dist/_native.d.ts +1 -1
- package/dist/_native.js +1 -1
- package/dist/_native.mjs +1 -1
- package/dist/dom.d.mts +2 -2
- package/dist/dom.d.ts +2 -2
- package/dist/dom.js +2 -2
- package/dist/dom.mjs +2 -2
- package/dist/internals/{renderer-DowEJaeR.mjs → renderer-B2hPQcF0.mjs} +25 -32
- package/dist/internals/{renderer-DowEJaeR.mjs.map → renderer-B2hPQcF0.mjs.map} +1 -1
- package/dist/internals/{renderer-Bv5pi6kG.d.ts → renderer-Bnsr3mNZ.d.ts} +3 -4
- package/dist/internals/renderer-Bnsr3mNZ.d.ts.map +1 -0
- package/dist/internals/{renderer-BQawOCgo.d.mts → renderer-CJV68U2U.d.mts} +3 -4
- package/dist/internals/renderer-CJV68U2U.d.mts.map +1 -0
- package/dist/internals/{renderer--F4YB5QP.d.ts → renderer-CtvkpyUB.d.ts} +2 -3
- package/dist/internals/{renderer--F4YB5QP.d.ts.map → renderer-CtvkpyUB.d.ts.map} +1 -1
- package/dist/internals/{renderer-I-1wuWMB.js → renderer-DINmR7Fc.js} +25 -32
- package/dist/internals/{renderer-I-1wuWMB.js.map → renderer-DINmR7Fc.js.map} +1 -1
- package/dist/internals/{renderer-CA9aKFMW.mjs → renderer-DNuaMgXi.mjs} +13 -21
- package/dist/internals/renderer-DNuaMgXi.mjs.map +1 -0
- package/dist/internals/{renderer-CNz1Y3a_.js → renderer-Dv-IAwBn.js} +13 -21
- package/dist/internals/renderer-Dv-IAwBn.js.map +1 -0
- package/dist/internals/{renderer-BelBgEvy.d.mts → renderer-JDjL_fNZ.d.mts} +2 -3
- package/dist/internals/{renderer-BelBgEvy.d.mts.map → renderer-JDjL_fNZ.d.mts.map} +1 -1
- package/dist/server-dom.d.mts +2 -2
- package/dist/server-dom.d.ts +2 -2
- package/dist/server-dom.js +2 -2
- package/dist/server-dom.mjs +2 -2
- package/dist/web.d.mts +2 -2
- package/dist/web.d.ts +2 -2
- package/dist/web.js +2 -2
- package/dist/web.mjs +3 -3
- package/package.json +5 -5
- package/dist/internals/renderer-BQawOCgo.d.mts.map +0 -1
- package/dist/internals/renderer-Bv5pi6kG.d.ts.map +0 -1
- package/dist/internals/renderer-CA9aKFMW.mjs.map +0 -1
- package/dist/internals/renderer-CNz1Y3a_.js.map +0 -1
|
@@ -50,7 +50,7 @@ class _Renderer {
|
|
|
50
50
|
});
|
|
51
51
|
return children(node);
|
|
52
52
|
};
|
|
53
|
-
const commit = (elements, force) => {
|
|
53
|
+
const commit = (elements, updated, force) => {
|
|
54
54
|
const _mount = (node, stack) => {
|
|
55
55
|
for (const item of node.children) {
|
|
56
56
|
if (item instanceof VNode)
|
|
@@ -59,9 +59,9 @@ class _Renderer {
|
|
|
59
59
|
const element = elements.get(node)?.native;
|
|
60
60
|
if (element instanceof _ParentComponent)
|
|
61
61
|
return;
|
|
62
|
-
if (element) {
|
|
62
|
+
if (element && updated.has(node)) {
|
|
63
63
|
try {
|
|
64
|
-
this.
|
|
64
|
+
this._updateElement(node, element, resolveChildren(node, elements), stack, force);
|
|
65
65
|
}
|
|
66
66
|
catch (e) {
|
|
67
67
|
console.error(e);
|
|
@@ -110,8 +110,8 @@ class _Renderer {
|
|
|
110
110
|
mountState.delete(node);
|
|
111
111
|
}
|
|
112
112
|
if (root)
|
|
113
|
-
this.
|
|
114
|
-
_mount(runtime.node, []);
|
|
113
|
+
this._updateElement(runtime.node, root, _.castArray(elements.get(runtime.node)?.native ?? resolveChildren(runtime.node, elements)), [], force);
|
|
114
|
+
_mount(runtime.node, [runtime.node]);
|
|
115
115
|
};
|
|
116
116
|
const update = async (elements, force) => {
|
|
117
117
|
try {
|
|
@@ -121,6 +121,7 @@ class _Renderer {
|
|
|
121
121
|
console.error(e);
|
|
122
122
|
}
|
|
123
123
|
const map = new Map();
|
|
124
|
+
const updatedNodes = new Set();
|
|
124
125
|
for await (const { node, stack, updated } of runtime.excute()) {
|
|
125
126
|
if (node.error)
|
|
126
127
|
continue;
|
|
@@ -136,27 +137,18 @@ class _Renderer {
|
|
|
136
137
|
map.set(node, { native: elem });
|
|
137
138
|
}
|
|
138
139
|
else {
|
|
140
|
+
const elem = elements?.get(node)?.native;
|
|
141
|
+
if (!elem || updated)
|
|
142
|
+
updatedNodes.add(node);
|
|
139
143
|
try {
|
|
140
|
-
|
|
141
|
-
let elem = elements?.get(node)?.native;
|
|
142
|
-
if (elem) {
|
|
143
|
-
this._updateElement(node, elem, stack);
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
elem = this._createElement(node, stack);
|
|
147
|
-
}
|
|
148
|
-
map.set(node, { native: elem });
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
map.set(node, { native: elements?.get(node)?.native ?? this._createElement(node, stack) });
|
|
152
|
-
}
|
|
144
|
+
map.set(node, { native: elem ?? this._createElement(node, stack) });
|
|
153
145
|
}
|
|
154
146
|
catch (e) {
|
|
155
147
|
console.error(e);
|
|
156
148
|
}
|
|
157
149
|
}
|
|
158
150
|
}
|
|
159
|
-
commit(map, force);
|
|
151
|
+
commit(map, updatedNodes, force);
|
|
160
152
|
if (elements) {
|
|
161
153
|
for (const [node, element] of elements) {
|
|
162
154
|
if (map.has(node) || !element.native)
|
|
@@ -204,7 +196,7 @@ class _Renderer {
|
|
|
204
196
|
},
|
|
205
197
|
destroy: () => {
|
|
206
198
|
if (root)
|
|
207
|
-
this.
|
|
199
|
+
this._updateElement(runtime.node, root, [], [], true);
|
|
208
200
|
destroyed = true;
|
|
209
201
|
listener.remove();
|
|
210
202
|
for (const state of mountState.values()) {
|
|
@@ -232,4 +224,4 @@ class _Renderer {
|
|
|
232
224
|
}
|
|
233
225
|
|
|
234
226
|
export { _Renderer as _ };
|
|
235
|
-
//# sourceMappingURL=renderer-
|
|
227
|
+
//# sourceMappingURL=renderer-DNuaMgXi.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer-DNuaMgXi.mjs","sources":["../../../src/core/renderer.ts"],"sourcesContent":["//\n// renderer.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { VNode } from './reconciler/vnode';\nimport { ComponentNode, NativeElementType } from './types/component';\nimport { reconciler } from './reconciler/state';\nimport nextick from 'nextick';\nimport { equalDeps } from './reconciler/utils';\nimport { _ParentComponent } from './components/pairs';\n\nexport abstract class _Renderer<T> {\n\n protected abstract _beforeUpdate(): void;\n\n protected abstract _afterUpdate(): void;\n\n protected abstract _createElement(node: VNode, stack: VNode[]): T;\n\n protected abstract _updateElement(node: VNode, element: T, children: (T | string)[], stack: VNode[], force?: boolean): void;\n\n protected abstract _destroyElement(node: VNode, element: T): void;\n\n abstract get _server(): boolean;\n\n private async _createRoot(\n root: T | null,\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) {\n\n const runtime = reconciler.buildVNodes(component, this);\n\n type _State = {\n hook: string;\n deps: any;\n unmount?: () => void;\n };\n\n const mountState = new Map<VNode, _State[]>();\n\n const resolveChildren = (node: VNode, elements: Map<VNode, { native?: T }>) => {\n const childrenOfParent = (node: VNode, allowedChild: (node: string | VNode) => boolean): (string | T)[] => _.flatMap(node.children, x => {\n if (_.isString(x)) return allowedChild(x) ? x : [];\n const _node = elements.get(x)?.native;\n if (allowedChild(x)) return _node ?? children(x);\n return _node ? [] : childrenOfParent(x, allowedChild);\n });\n const children = (node: VNode): (string | T)[] => _.flatMap(node.children, x => {\n if (_.isString(x)) return x;\n const _node = elements.get(x)?.native;\n if (_node instanceof _ParentComponent) return childrenOfParent(x, c => _node.isChildNode(c));\n return _node ?? children(x);\n });\n return children(node);\n };\n\n const commit = (elements: Map<VNode, { native?: T }>, updated: Set<VNode>, force?: boolean) => {\n\n const _mount = (node: VNode, stack: VNode[]) => {\n for (const item of node.children) {\n if (item instanceof VNode) _mount(item, [...stack, node]);\n }\n const element = elements.get(node)?.native;\n if (element instanceof _ParentComponent) return;\n if (element && updated.has(node)) {\n try {\n this._updateElement(node, element, resolveChildren(node, elements), stack, force);\n } catch (e) {\n console.error(e);\n }\n }\n const state: _State[] = [];\n const prevState = mountState.get(node) ?? [];\n const curState = node.state;\n for (const i of _.range(Math.max(prevState.length, curState.length))) {\n const unmount = prevState[i]?.unmount;\n const changed = prevState[i]?.hook !== curState[i]?.hook || !equalDeps(prevState[i].deps, curState[i]?.deps);\n if (unmount && changed) {\n try {\n unmount();\n } catch (e) {\n console.error(e);\n }\n }\n state.push({\n hook: curState[i].hook,\n deps: curState[i].deps,\n unmount: options?.skipMount || !changed ? prevState[i]?.unmount : (() => {\n try {\n return curState[i].mount?.();\n } catch (e) {\n console.error(e);\n }\n })(),\n });\n }\n mountState.set(node, state);\n };\n\n for (const [node, state] of mountState) {\n if (elements.has(node)) continue;\n for (const { unmount } of state) {\n try {\n unmount?.();\n } catch (e) {\n console.error(e);\n }\n }\n mountState.delete(node);\n }\n if (root) this._updateElement(\n runtime.node, root,\n _.castArray(elements.get(runtime.node)?.native ?? resolveChildren(runtime.node, elements)),\n [],\n force,\n );\n _mount(runtime.node, [runtime.node]);\n };\n\n const update = async (elements?: Map<VNode, { native?: T }>, force?: boolean) => {\n try {\n this._beforeUpdate();\n } catch (e) {\n console.error(e);\n }\n const map = new Map<VNode, { native?: T }>();\n const updatedNodes = new Set<VNode>();\n for await (const { node, stack, updated } of runtime.excute()) {\n if (node.error) continue;\n if (_.isFunction(node.type) && !(node.type.prototype instanceof NativeElementType)) {\n map.set(node, {});\n } else if (_.isFunction(node.type) && node.type.prototype instanceof _ParentComponent) {\n let elem = elements?.get(node)?.native;\n if (!elem) {\n const Component = node.type as any;\n elem = new Component();\n }\n map.set(node, { native: elem });\n } else {\n const elem = elements?.get(node)?.native;\n if (!elem || updated) updatedNodes.add(node);\n try {\n map.set(node, { native: elem ?? this._createElement(node, stack) });\n } catch (e) {\n console.error(e);\n }\n }\n }\n commit(map, updatedNodes, force);\n if (elements) {\n for (const [node, element] of elements) {\n if (map.has(node) || !element.native) continue;\n try {\n this._destroyElement(node, element.native);\n } catch (e) {\n console.error(e);\n }\n }\n }\n try {\n this._afterUpdate();\n } catch (e) {\n console.error(e);\n }\n return map;\n };\n\n let update_count = 0;\n let render_count = 0;\n let destroyed = false;\n let elements = await update(undefined, true);\n\n const listener = runtime.event.register('onchange', () => {\n if (render_count !== update_count++) return;\n nextick(async () => {\n while (render_count !== update_count) {\n if (destroyed) return;\n const current = update_count;\n elements = await update(elements, false);\n render_count = current;\n }\n });\n });\n\n return {\n get root() {\n if (root) return root;\n const elems = _.castArray(elements.get(runtime.node)?.native ?? resolveChildren(runtime.node, elements));\n const nodes = _.filter(elems, x => !_.isString(x)) as T[];\n return nodes.length === 1 ? nodes[0] : nodes;\n },\n destroy: () => {\n if (root) this._updateElement(runtime.node, root, [], [], true);\n destroyed = true;\n listener.remove();\n for (const state of mountState.values()) {\n for (const { unmount } of state) unmount?.();\n }\n },\n };\n }\n\n createRoot(root?: T) {\n let state: Awaited<ReturnType<typeof this._createRoot>> | undefined;\n return {\n get root() {\n return state?.root;\n },\n mount: async (\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) => {\n state = await this._createRoot(root ?? null, component, options);\n },\n unmount: () => {\n state?.destroy();\n state = undefined;\n },\n };\n }\n}"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MAUsB,SAAS,CAAA;AAcrB,IAAA,MAAM,WAAW,CACvB,IAAc,EACd,SAAwB,EACxB,OAEC,EAAA;QAGD,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC;AAQvD,QAAA,MAAM,UAAU,GAAG,IAAI,GAAG,EAAmB;AAE7C,QAAA,MAAM,eAAe,GAAG,CAAC,IAAW,EAAE,QAAoC,KAAI;AAC5E,YAAA,MAAM,gBAAgB,GAAG,CAAC,IAAW,EAAE,YAA+C,KAAqB,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAG;AACtI,gBAAA,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AAAE,oBAAA,OAAO,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE;gBAClD,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM;gBACrC,IAAI,YAAY,CAAC,CAAC,CAAC;AAAE,oBAAA,OAAO,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC;AAChD,gBAAA,OAAO,KAAK,GAAG,EAAE,GAAG,gBAAgB,CAAC,CAAC,EAAE,YAAY,CAAC;AACvD,YAAA,CAAC,CAAC;AAC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e,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACxG,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAQ;AACzD,gBAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK;YAC9C,CAAC;YACD,OAAO,EAAE,MAAK;AACZ,gBAAA,IAAI,IAAI;AAAE,oBAAA,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC;gBAC/D,SAAS,GAAG,IAAI;gBAChB,QAAQ,CAAC,MAAM,EAAE;gBACjB,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE;AACvC,oBAAA,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,KAAK;wBAAE,OAAO,IAAI;gBAC9C;YACF,CAAC;SACF;IACH;AAEA,IAAA,UAAU,CAAC,IAAQ,EAAA;AACjB,QAAA,IAAI,KAA+D;QACnE,OAAO;AACL,YAAA,IAAI,IAAI,GAAA;gBACN,OAAO,KAAK,EAAE,IAAI;YACpB,CAAC;AACD,YAAA,KAAK,EAAE,OACL,SAAwB,EACxB,OAEC,KACC;AACF,gBAAA,KAAK,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC;YAClE,CAAC;YACD,OAAO,EAAE,MAAK;gBACZ,KAAK,EAAE,OAAO,EAAE;gBAChB,KAAK,GAAG,SAAS;YACnB,CAAC;SACF;IACH;AACD;;;;"}
|
|
@@ -52,7 +52,7 @@ class _Renderer {
|
|
|
52
52
|
});
|
|
53
53
|
return children(node);
|
|
54
54
|
};
|
|
55
|
-
const commit = (elements, force) => {
|
|
55
|
+
const commit = (elements, updated, force) => {
|
|
56
56
|
const _mount = (node, stack) => {
|
|
57
57
|
for (const item of node.children) {
|
|
58
58
|
if (item instanceof state.VNode)
|
|
@@ -61,9 +61,9 @@ class _Renderer {
|
|
|
61
61
|
const element = elements.get(node)?.native;
|
|
62
62
|
if (element instanceof state._ParentComponent)
|
|
63
63
|
return;
|
|
64
|
-
if (element) {
|
|
64
|
+
if (element && updated.has(node)) {
|
|
65
65
|
try {
|
|
66
|
-
this.
|
|
66
|
+
this._updateElement(node, element, resolveChildren(node, elements), stack, force);
|
|
67
67
|
}
|
|
68
68
|
catch (e) {
|
|
69
69
|
console.error(e);
|
|
@@ -112,8 +112,8 @@ class _Renderer {
|
|
|
112
112
|
mountState.delete(node);
|
|
113
113
|
}
|
|
114
114
|
if (root)
|
|
115
|
-
this.
|
|
116
|
-
_mount(runtime$1.node, []);
|
|
115
|
+
this._updateElement(runtime$1.node, root, _.castArray(elements.get(runtime$1.node)?.native ?? resolveChildren(runtime$1.node, elements)), [], force);
|
|
116
|
+
_mount(runtime$1.node, [runtime$1.node]);
|
|
117
117
|
};
|
|
118
118
|
const update = async (elements, force) => {
|
|
119
119
|
try {
|
|
@@ -123,6 +123,7 @@ class _Renderer {
|
|
|
123
123
|
console.error(e);
|
|
124
124
|
}
|
|
125
125
|
const map = new Map();
|
|
126
|
+
const updatedNodes = new Set();
|
|
126
127
|
for await (const { node, stack, updated } of runtime$1.excute()) {
|
|
127
128
|
if (node.error)
|
|
128
129
|
continue;
|
|
@@ -138,27 +139,18 @@ class _Renderer {
|
|
|
138
139
|
map.set(node, { native: elem });
|
|
139
140
|
}
|
|
140
141
|
else {
|
|
142
|
+
const elem = elements?.get(node)?.native;
|
|
143
|
+
if (!elem || updated)
|
|
144
|
+
updatedNodes.add(node);
|
|
141
145
|
try {
|
|
142
|
-
|
|
143
|
-
let elem = elements?.get(node)?.native;
|
|
144
|
-
if (elem) {
|
|
145
|
-
this._updateElement(node, elem, stack);
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
elem = this._createElement(node, stack);
|
|
149
|
-
}
|
|
150
|
-
map.set(node, { native: elem });
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
map.set(node, { native: elements?.get(node)?.native ?? this._createElement(node, stack) });
|
|
154
|
-
}
|
|
146
|
+
map.set(node, { native: elem ?? this._createElement(node, stack) });
|
|
155
147
|
}
|
|
156
148
|
catch (e) {
|
|
157
149
|
console.error(e);
|
|
158
150
|
}
|
|
159
151
|
}
|
|
160
152
|
}
|
|
161
|
-
commit(map, force);
|
|
153
|
+
commit(map, updatedNodes, force);
|
|
162
154
|
if (elements) {
|
|
163
155
|
for (const [node, element] of elements) {
|
|
164
156
|
if (map.has(node) || !element.native)
|
|
@@ -206,7 +198,7 @@ class _Renderer {
|
|
|
206
198
|
},
|
|
207
199
|
destroy: () => {
|
|
208
200
|
if (root)
|
|
209
|
-
this.
|
|
201
|
+
this._updateElement(runtime$1.node, root, [], [], true);
|
|
210
202
|
destroyed = true;
|
|
211
203
|
listener.remove();
|
|
212
204
|
for (const state of mountState.values()) {
|
|
@@ -234,4 +226,4 @@ class _Renderer {
|
|
|
234
226
|
}
|
|
235
227
|
|
|
236
228
|
exports._Renderer = _Renderer;
|
|
237
|
-
//# sourceMappingURL=renderer-
|
|
229
|
+
//# sourceMappingURL=renderer-Dv-IAwBn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer-Dv-IAwBn.js","sources":["../../../src/core/renderer.ts"],"sourcesContent":["//\n// renderer.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { VNode } from './reconciler/vnode';\nimport { ComponentNode, NativeElementType } from './types/component';\nimport { reconciler } from './reconciler/state';\nimport nextick from 'nextick';\nimport { equalDeps } from './reconciler/utils';\nimport { _ParentComponent } from './components/pairs';\n\nexport abstract class _Renderer<T> {\n\n protected abstract _beforeUpdate(): void;\n\n protected abstract _afterUpdate(): void;\n\n protected abstract _createElement(node: VNode, stack: VNode[]): T;\n\n protected abstract _updateElement(node: VNode, element: T, children: (T | string)[], stack: VNode[], force?: boolean): void;\n\n protected abstract _destroyElement(node: VNode, element: T): void;\n\n abstract get _server(): boolean;\n\n private async _createRoot(\n root: T | null,\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) {\n\n const runtime = reconciler.buildVNodes(component, this);\n\n type _State = {\n hook: string;\n deps: any;\n unmount?: () => void;\n };\n\n const mountState = new Map<VNode, _State[]>();\n\n const resolveChildren = (node: VNode, elements: Map<VNode, { native?: T }>) => {\n const childrenOfParent = (node: VNode, allowedChild: (node: string | VNode) => boolean): (string | T)[] => _.flatMap(node.children, x => {\n if (_.isString(x)) return allowedChild(x) ? x : [];\n const _node = elements.get(x)?.native;\n if (allowedChild(x)) return _node ?? children(x);\n return _node ? [] : childrenOfParent(x, allowedChild);\n });\n const children = (node: VNode): (string | T)[] => _.flatMap(node.children, x => {\n if (_.isString(x)) return x;\n const _node = elements.get(x)?.native;\n if (_node instanceof _ParentComponent) return childrenOfParent(x, c => _node.isChildNode(c));\n return _node ?? children(x);\n });\n return children(node);\n };\n\n const commit = (elements: Map<VNode, { native?: T }>, updated: Set<VNode>, force?: boolean) => {\n\n const _mount = (node: VNode, stack: VNode[]) => {\n for (const item of node.children) {\n if (item instanceof VNode) _mount(item, [...stack, node]);\n }\n const element = elements.get(node)?.native;\n if (element instanceof _ParentComponent) return;\n if (element && updated.has(node)) {\n try {\n this._updateElement(node, element, resolveChildren(node, elements), stack, force);\n } catch (e) {\n console.error(e);\n }\n }\n const state: _State[] = [];\n const prevState = mountState.get(node) ?? [];\n const curState = node.state;\n for (const i of _.range(Math.max(prevState.length, curState.length))) {\n const unmount = prevState[i]?.unmount;\n const changed = prevState[i]?.hook !== curState[i]?.hook || !equalDeps(prevState[i].deps, curState[i]?.deps);\n if (unmount && changed) {\n try {\n unmount();\n } catch (e) {\n console.error(e);\n }\n }\n state.push({\n hook: curState[i].hook,\n deps: curState[i].deps,\n unmount: options?.skipMount || !changed ? prevState[i]?.unmount : (() => {\n try {\n return curState[i].mount?.();\n } catch (e) {\n console.error(e);\n }\n })(),\n });\n }\n mountState.set(node, state);\n };\n\n for (const [node, state] of mountState) {\n if (elements.has(node)) continue;\n for (const { unmount } of state) {\n try {\n unmount?.();\n } catch (e) {\n console.error(e);\n }\n }\n mountState.delete(node);\n }\n if (root) this._updateElement(\n runtime.node, root,\n _.castArray(elements.get(runtime.node)?.native ?? resolveChildren(runtime.node, elements)),\n [],\n force,\n );\n _mount(runtime.node, [runtime.node]);\n };\n\n const update = async (elements?: Map<VNode, { native?: T }>, force?: boolean) => {\n try {\n this._beforeUpdate();\n } catch (e) {\n console.error(e);\n }\n const map = new Map<VNode, { native?: T }>();\n const updatedNodes = new Set<VNode>();\n for await (const { node, stack, updated } of runtime.excute()) {\n if (node.error) continue;\n if (_.isFunction(node.type) && !(node.type.prototype instanceof NativeElementType)) {\n map.set(node, {});\n } else if (_.isFunction(node.type) && node.type.prototype instanceof _ParentComponent) {\n let elem = elements?.get(node)?.native;\n if (!elem) {\n const Component = node.type as any;\n elem = new Component();\n }\n map.set(node, { native: elem });\n } else {\n const elem = elements?.get(node)?.native;\n if (!elem || updated) updatedNodes.add(node);\n try {\n map.set(node, { native: elem ?? this._createElement(node, stack) });\n } catch (e) {\n console.error(e);\n }\n }\n }\n commit(map, updatedNodes, force);\n if (elements) {\n for (const [node, element] of elements) {\n if (map.has(node) || !element.native) continue;\n try {\n this._destroyElement(node, element.native);\n } catch (e) {\n console.error(e);\n }\n }\n }\n try {\n this._afterUpdate();\n } catch (e) {\n console.error(e);\n }\n return map;\n };\n\n let update_count = 0;\n let render_count = 0;\n let destroyed = false;\n let elements = await update(undefined, true);\n\n const listener = runtime.event.register('onchange', () => {\n if (render_count !== update_count++) return;\n nextick(async () => {\n while (render_count !== update_count) {\n if (destroyed) return;\n const current = update_count;\n elements = await update(elements, false);\n render_count = current;\n }\n });\n });\n\n return {\n get root() {\n if (root) return root;\n const elems = _.castArray(elements.get(runtime.node)?.native ?? resolveChildren(runtime.node, elements));\n const nodes = _.filter(elems, x => !_.isString(x)) as T[];\n return nodes.length === 1 ? nodes[0] : nodes;\n },\n destroy: () => {\n if (root) this._updateElement(runtime.node, root, [], [], true);\n destroyed = true;\n listener.remove();\n for (const state of mountState.values()) {\n for (const { unmount } of state) unmount?.();\n }\n },\n };\n }\n\n createRoot(root?: T) {\n let state: Awaited<ReturnType<typeof this._createRoot>> | undefined;\n return {\n get root() {\n return state?.root;\n },\n mount: async (\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) => {\n state = await this._createRoot(root ?? null, component, options);\n },\n unmount: () => {\n state?.destroy();\n state = undefined;\n },\n };\n }\n}"],"names":["runtime","reconciler","_ParentComponent","VNode","state","equalDeps","NativeElementType"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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AAc,CAACA,SAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC;gBAC/D,SAAS,GAAG,IAAI;gBAChB,QAAQ,CAAC,MAAM,EAAE;gBACjB,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE;AACvC,oBAAA,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,KAAK;wBAAE,OAAO,IAAI;gBAC9C;YACF,CAAC;SACF;IACH;AAEA,IAAA,UAAU,CAAC,IAAQ,EAAA;AACjB,QAAA,IAAI,KAA+D;QACnE,OAAO;AACL,YAAA,IAAI,IAAI,GAAA;gBACN,OAAO,KAAK,EAAE,IAAI;YACpB,CAAC;AACD,YAAA,KAAK,EAAE,OACL,SAAwB,EACxB,OAEC,KACC;AACF,gBAAA,KAAK,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC;YAClE,CAAC;YACD,OAAO,EAAE,MAAK;gBACZ,KAAK,EAAE,OAAO,EAAE;gBAChB,KAAK,GAAG,SAAS;YACnB,CAAC;SACF;IACH;AACD;;;;"}
|
|
@@ -29,9 +29,8 @@ declare abstract class _Renderer<T> {
|
|
|
29
29
|
protected abstract _beforeUpdate(): void;
|
|
30
30
|
protected abstract _afterUpdate(): void;
|
|
31
31
|
protected abstract _createElement(node: VNode, stack: VNode[]): T;
|
|
32
|
-
protected abstract _updateElement(node: VNode, element: T, stack: VNode[]): void;
|
|
32
|
+
protected abstract _updateElement(node: VNode, element: T, children: (T | string)[], stack: VNode[], force?: boolean): void;
|
|
33
33
|
protected abstract _destroyElement(node: VNode, element: T): void;
|
|
34
|
-
protected abstract _replaceChildren(node: VNode, element: T, children: (T | string)[], stack: VNode[], force?: boolean): void;
|
|
35
34
|
abstract get _server(): boolean;
|
|
36
35
|
private _createRoot;
|
|
37
36
|
createRoot(root?: T): {
|
|
@@ -44,4 +43,4 @@ declare abstract class _Renderer<T> {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
export { VNode as V, _Renderer as _ };
|
|
47
|
-
//# sourceMappingURL=renderer-
|
|
46
|
+
//# sourceMappingURL=renderer-JDjL_fNZ.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer-BelBgEvy.d.mts","sources":["../../src/core/reconciler/vnode.ts","../../src/core/renderer.ts"],"sourcesContent":["//\n// vnode.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { ComponentNode, NativeElementType } from '../types/component';\nimport { Context, isContext } from '../hooks/context';\nimport { reconciler } from './state';\nimport { myersSync } from 'myers.js';\nimport { EventEmitter } from './events';\nimport { equalDeps, equalProps } from './utils';\nimport { _Renderer } from '../renderer';\nimport { PropsType } from '../types/runtime';\nimport { uniqueId } from '../utils';\n\nexport type VNodeState = {\n hook: string;\n deps: any;\n data?: any;\n mount?: () => () => void;\n};\n\nexport type _ContextState = {\n value: any;\n state: string;\n node: VNode;\n};\n\nexport class VNode {\n\n /** @internal */\n _component: ComponentNode;\n\n private _id = uniqueId();\n\n private _event: EventEmitter;\n private _props: PropsType = {};\n private _error?: any;\n private _children: (VNode | string)[] = [];\n private _state?: VNodeState[];\n private _dirty = true;\n private _listens = new Map<Context<any>, Omit<_ContextState, 'value'>>();\n\n /** @internal */\n _content_state = uniqueId();\n private _content_value?: any;\n\n /** @internal */\n constructor(component: ComponentNode, event: EventEmitter) {\n this._component = component;\n this._event = event;\n }\n\n /** @internal */\n _resolve_children(child: any): (VNode | string)[] {\n if (_.isBoolean(child) || _.isNil(child)) return [];\n if (_.isString(child)) return [child];\n if (_.isNumber(child)) return [`${child}`];\n if (child instanceof ComponentNode) return [new VNode(child, this._event)];\n if (_.isArrayLikeObject(child)) return _.flatMap(child, x => this._resolve_children(x));\n if (typeof child[Symbol.iterator] === 'function') return _.flatMap([...child], x => this._resolve_children(x));\n throw Error(`${child} are not valid as a child.`);\n }\n\n get id() {\n return this._id;\n }\n\n get type() {\n return this._component.type;\n }\n\n get props() {\n return this._props;\n }\n\n get key() {\n return this._component.key;\n }\n\n get state() {\n return this._state ?? [];\n }\n\n get children() {\n return this._children;\n }\n\n get error() {\n return this._error;\n }\n\n /** @internal */\n _setDirty() {\n this._dirty = true;\n this._event.emit('onchange');\n }\n\n /** @internal */\n private _check_context(values: Map<Context<any>, Omit<_ContextState, 'value'>>) {\n return this._listens.entries().every(([k, v]) => {\n const { state, node } = values.get(k) ?? {};\n return state === v.state && node === v.node;\n });\n }\n\n /** @internal */\n async _updateIfNeed(options: {\n renderer: _Renderer<any>;\n stack: VNode[];\n propsProvider: VNode[];\n errorBoundary?: VNode;\n contextValue: Map<Context<any>, _ContextState>;\n }) {\n if (!this._dirty && this._check_context(options.contextValue)) return false;\n try {\n const self = this;\n const { type, props: _props } = this._component;\n const props = _.mapValues(\n options.propsProvider.reduceRight((p, node) => node.props.callback({ type, props: p }), _props),\n (v, k) => _.isFunction(v) ? function (this: any, ...args: any[]) {\n const current = self._component.props[k];\n return _.isFunction(current) ? current.call(this, ...args) : v.call(this, ...args);\n } : v,\n );\n let children: (VNode | string)[];\n if (_.isString(type) || type?.prototype instanceof NativeElementType) {\n children = this._resolve_children(props.children);\n } else if (isContext(type)) {\n const { value } = props;\n if (!equalDeps(this._content_value, value)) this._content_state = uniqueId();\n this._content_value = value;\n children = this._resolve_children(type(props as any));\n } else if (_.isFunction(type)) {\n let resolved;\n while (true) {\n const {\n resolved: rendered,\n error,\n state,\n } = reconciler.withHookState({\n renderer: options.renderer,\n node: this,\n state: this._state,\n stack: options.stack,\n contextValue: options.contextValue,\n }, () => type(props));\n this._state = state.state;\n if (_.isEmpty(state.tasks)) {\n if (error) throw error;\n resolved = { rendered, state };\n break;\n }\n await Promise.all(state.tasks);\n }\n this._listens = new Map(options.contextValue.entries().filter(([k]) => resolved.state.listens.has(k)));\n children = this._resolve_children(resolved.rendered);\n } else {\n throw Error(`Invalid node type ${type}`);\n }\n const diff = myersSync(this._children, children, {\n compare: (lhs, rhs) => {\n if (_.isString(lhs) && _.isString(rhs)) return lhs === rhs;\n if (lhs instanceof VNode && rhs instanceof VNode) return lhs._component._equal(rhs._component);\n return false;\n },\n });\n this._props = _.omit(props, 'children');\n this._children = _.flatMap(diff, x => x.equivalent ?? x.insert ?? []);\n this._error = undefined;\n for (const [i, item] of this._children.entries()) {\n if (!(item instanceof VNode)) continue;\n if (!(children[i] instanceof VNode)) continue;\n if (!equalProps(item._component.props, children[i]._component.props)) item._dirty = true;\n item._component = children[i]._component;\n }\n } catch (error) {\n this._props = {};\n this._children = [];\n this._error = error;\n (async () => {\n try {\n const { onError, silent } = options.errorBoundary?.props ?? {};\n if (!silent) console.error(error);\n if (_.isFunction(onError)) await onError(error, this._component, _.map(options.stack, x => x._component));\n } catch (e) {\n console.error(e);\n }\n })();\n } finally {\n this._dirty = false;\n }\n return true;\n }\n}\n","//\n// renderer.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { VNode } from './reconciler/vnode';\nimport { ComponentNode, NativeElementType } from './types/component';\nimport { reconciler } from './reconciler/state';\nimport nextick from 'nextick';\nimport { equalDeps } from './reconciler/utils';\nimport { _ParentComponent } from './components/pairs';\n\nexport abstract class _Renderer<T> {\n\n protected abstract _beforeUpdate(): void;\n\n protected abstract _afterUpdate(): void;\n\n protected abstract _createElement(node: VNode, stack: VNode[]): T;\n\n protected abstract _updateElement(node: VNode, element: T, stack: VNode[]): void;\n\n protected abstract _destroyElement(node: VNode, element: T): void;\n\n protected abstract _replaceChildren(node: VNode, element: T, children: (T | string)[], stack: VNode[], force?: boolean): void;\n\n abstract get _server(): boolean;\n\n private async _createRoot(\n root: T | null,\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) {\n\n const runtime = reconciler.buildVNodes(component, this);\n\n type _State = {\n hook: string;\n deps: any;\n unmount?: () => void;\n };\n\n const mountState = new Map<VNode, _State[]>();\n\n const resolveChildren = (node: VNode, elements: Map<VNode, { native?: T }>) => {\n const childrenOfParent = (node: VNode, allowedChild: (node: string | VNode) => boolean): (string | T)[] => _.flatMap(node.children, x => {\n if (_.isString(x)) return allowedChild(x) ? x : [];\n const _node = elements.get(x)?.native;\n if (allowedChild(x)) return _node ?? children(x);\n return _node ? [] : childrenOfParent(x, allowedChild);\n });\n const children = (node: VNode): (string | T)[] => _.flatMap(node.children, x => {\n if (_.isString(x)) return x;\n const _node = elements.get(x)?.native;\n if (_node instanceof _ParentComponent) return childrenOfParent(x, c => _node.isChildNode(c));\n return _node ?? children(x);\n });\n return children(node);\n };\n\n const commit = (elements: Map<VNode, { native?: T }>, force?: boolean) => {\n\n const _mount = (node: VNode, stack: VNode[]) => {\n for (const item of node.children) {\n if (item instanceof VNode) _mount(item, [...stack, node]);\n }\n const element = elements.get(node)?.native;\n if (element instanceof _ParentComponent) return;\n if (element) {\n try {\n this._replaceChildren(node, element, resolveChildren(node, elements), stack, force);\n } catch (e) {\n console.error(e);\n }\n }\n const state: _State[] = [];\n const prevState = mountState.get(node) ?? [];\n const curState = node.state;\n for (const i of _.range(Math.max(prevState.length, curState.length))) {\n const unmount = prevState[i]?.unmount;\n const changed = prevState[i]?.hook !== curState[i]?.hook || !equalDeps(prevState[i].deps, curState[i]?.deps);\n if (unmount && changed) {\n try {\n unmount();\n } catch (e) {\n console.error(e);\n }\n }\n state.push({\n hook: curState[i].hook,\n deps: curState[i].deps,\n unmount: options?.skipMount || !changed ? prevState[i]?.unmount : (() => {\n try {\n return curState[i].mount?.();\n } catch (e) {\n console.error(e);\n }\n })(),\n });\n }\n mountState.set(node, state);\n };\n\n for (const [node, state] of mountState) {\n if (elements.has(node)) continue;\n for (const { unmount } of state) {\n try {\n unmount?.();\n } catch (e) {\n console.error(e);\n }\n }\n mountState.delete(node);\n }\n if (root) this._replaceChildren(\n runtime.node, root,\n _.castArray(elements.get(runtime.node)?.native ?? resolveChildren(runtime.node, elements)),\n [],\n force,\n );\n _mount(runtime.node, []);\n };\n\n const update = async (elements?: Map<VNode, { native?: T }>, force?: boolean) => {\n try {\n this._beforeUpdate();\n } catch (e) {\n console.error(e);\n }\n const map = new Map<VNode, { native?: T }>();\n for await (const { node, stack, updated } of runtime.excute()) {\n if (node.error) continue;\n if (_.isFunction(node.type) && !(node.type.prototype instanceof NativeElementType)) {\n map.set(node, {});\n } else if (_.isFunction(node.type) && node.type.prototype instanceof _ParentComponent) {\n let elem = elements?.get(node)?.native;\n if (!elem) {\n const Component = node.type as any;\n elem = new Component();\n }\n map.set(node, { native: elem });\n } else {\n try {\n if (updated) {\n let elem = elements?.get(node)?.native;\n if (elem) {\n this._updateElement(node, elem, stack);\n } else {\n elem = this._createElement(node, stack);\n }\n map.set(node, { native: elem });\n } else {\n map.set(node, { native: elements?.get(node)?.native ?? this._createElement(node, stack) });\n }\n } catch (e) {\n console.error(e);\n }\n }\n }\n commit(map, force);\n if (elements) {\n for (const [node, element] of elements) {\n if (map.has(node) || !element.native) continue;\n try {\n this._destroyElement(node, element.native);\n } catch (e) {\n console.error(e);\n }\n }\n }\n try {\n this._afterUpdate();\n } catch (e) {\n console.error(e);\n }\n return map;\n };\n\n let update_count = 0;\n let render_count = 0;\n let destroyed = false;\n let elements = await update(undefined, true);\n\n const listener = runtime.event.register('onchange', () => {\n if (render_count !== update_count++) return;\n nextick(async () => {\n while (render_count !== update_count) {\n if (destroyed) return;\n const current = update_count;\n elements = await update(elements, false);\n render_count = current;\n }\n });\n });\n\n return {\n get root() {\n if (root) return root;\n const elems = _.castArray(elements.get(runtime.node)?.native ?? resolveChildren(runtime.node, elements));\n const nodes = _.filter(elems, x => !_.isString(x)) as T[];\n return nodes.length === 1 ? nodes[0] : nodes;\n },\n destroy: () => {\n if (root) this._replaceChildren(runtime.node, root, [], [], true);\n destroyed = true;\n listener.remove();\n for (const state of mountState.values()) {\n for (const { unmount } of state) unmount?.();\n }\n },\n };\n }\n\n createRoot(root?: T) {\n let state: Awaited<ReturnType<typeof this._createRoot>> | undefined;\n return {\n get root() {\n return state?.root;\n },\n mount: async (\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) => {\n state = await this._createRoot(root ?? null, component, options);\n },\n unmount: () => {\n state?.destroy();\n state = undefined;\n },\n };\n }\n}"],"names":[],"mappings":";;AAEO;AACP;AACA;AACA;AACA;AACA;AAMO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5BO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;"}
|
|
1
|
+
{"version":3,"file":"renderer-JDjL_fNZ.d.mts","sources":["../../src/core/reconciler/vnode.ts","../../src/core/renderer.ts"],"sourcesContent":["//\n// vnode.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { ComponentNode, NativeElementType } from '../types/component';\nimport { Context, isContext } from '../hooks/context';\nimport { reconciler } from './state';\nimport { myersSync } from 'myers.js';\nimport { EventEmitter } from './events';\nimport { equalDeps, equalProps } from './utils';\nimport { _Renderer } from '../renderer';\nimport { PropsType } from '../types/runtime';\nimport { uniqueId } from '../utils';\n\nexport type VNodeState = {\n hook: string;\n deps: any;\n data?: any;\n mount?: () => () => void;\n};\n\nexport type _ContextState = {\n value: any;\n state: string;\n node: VNode;\n};\n\nexport class VNode {\n\n /** @internal */\n _component: ComponentNode;\n\n private _id = uniqueId();\n\n private _event: EventEmitter;\n private _props: PropsType = {};\n private _error?: any;\n private _children: (VNode | string)[] = [];\n private _state?: VNodeState[];\n private _dirty = true;\n private _listens = new Map<Context<any>, Omit<_ContextState, 'value'>>();\n\n /** @internal */\n _content_state = uniqueId();\n private _content_value?: any;\n\n /** @internal */\n constructor(component: ComponentNode, event: EventEmitter) {\n this._component = component;\n this._event = event;\n }\n\n /** @internal */\n _resolve_children(child: any): (VNode | string)[] {\n if (_.isBoolean(child) || _.isNil(child)) return [];\n if (_.isString(child)) return [child];\n if (_.isNumber(child)) return [`${child}`];\n if (child instanceof ComponentNode) return [new VNode(child, this._event)];\n if (_.isArrayLikeObject(child)) return _.flatMap(child, x => this._resolve_children(x));\n if (typeof child[Symbol.iterator] === 'function') return _.flatMap([...child], x => this._resolve_children(x));\n throw Error(`${child} are not valid as a child.`);\n }\n\n get id() {\n return this._id;\n }\n\n get type() {\n return this._component.type;\n }\n\n get props() {\n return this._props;\n }\n\n get key() {\n return this._component.key;\n }\n\n get state() {\n return this._state ?? [];\n }\n\n get children() {\n return this._children;\n }\n\n get error() {\n return this._error;\n }\n\n /** @internal */\n _setDirty() {\n this._dirty = true;\n this._event.emit('onchange');\n }\n\n /** @internal */\n private _check_context(values: Map<Context<any>, Omit<_ContextState, 'value'>>) {\n return this._listens.entries().every(([k, v]) => {\n const { state, node } = values.get(k) ?? {};\n return state === v.state && node === v.node;\n });\n }\n\n /** @internal */\n async _updateIfNeed(options: {\n renderer: _Renderer<any>;\n stack: VNode[];\n propsProvider: VNode[];\n errorBoundary?: VNode;\n contextValue: Map<Context<any>, _ContextState>;\n }) {\n if (!this._dirty && this._check_context(options.contextValue)) return false;\n try {\n const self = this;\n const { type, props: _props } = this._component;\n const props = _.mapValues(\n options.propsProvider.reduceRight((p, node) => node.props.callback({ type, props: p }), _props),\n (v, k) => _.isFunction(v) ? function (this: any, ...args: any[]) {\n const current = self._component.props[k];\n return _.isFunction(current) ? current.call(this, ...args) : v.call(this, ...args);\n } : v,\n );\n let children: (VNode | string)[];\n if (_.isString(type) || type?.prototype instanceof NativeElementType) {\n children = this._resolve_children(props.children);\n } else if (isContext(type)) {\n const { value } = props;\n if (!equalDeps(this._content_value, value)) this._content_state = uniqueId();\n this._content_value = value;\n children = this._resolve_children(type(props as any));\n } else if (_.isFunction(type)) {\n let resolved;\n while (true) {\n const {\n resolved: rendered,\n error,\n state,\n } = reconciler.withHookState({\n renderer: options.renderer,\n node: this,\n state: this._state,\n stack: options.stack,\n contextValue: options.contextValue,\n }, () => type(props));\n this._state = state.state;\n if (_.isEmpty(state.tasks)) {\n if (error) throw error;\n resolved = { rendered, state };\n break;\n }\n await Promise.all(state.tasks);\n }\n this._listens = new Map(options.contextValue.entries().filter(([k]) => resolved.state.listens.has(k)));\n children = this._resolve_children(resolved.rendered);\n } else {\n throw Error(`Invalid node type ${type}`);\n }\n const diff = myersSync(this._children, children, {\n compare: (lhs, rhs) => {\n if (_.isString(lhs) && _.isString(rhs)) return lhs === rhs;\n if (lhs instanceof VNode && rhs instanceof VNode) return lhs._component._equal(rhs._component);\n return false;\n },\n });\n this._props = _.omit(props, 'children');\n this._children = _.flatMap(diff, x => x.equivalent ?? x.insert ?? []);\n this._error = undefined;\n for (const [i, item] of this._children.entries()) {\n if (!(item instanceof VNode)) continue;\n if (!(children[i] instanceof VNode)) continue;\n if (!equalProps(item._component.props, children[i]._component.props)) item._dirty = true;\n item._component = children[i]._component;\n }\n } catch (error) {\n this._props = {};\n this._children = [];\n this._error = error;\n (async () => {\n try {\n const { onError, silent } = options.errorBoundary?.props ?? {};\n if (!silent) console.error(error);\n if (_.isFunction(onError)) await onError(error, this._component, _.map(options.stack, x => x._component));\n } catch (e) {\n console.error(e);\n }\n })();\n } finally {\n this._dirty = false;\n }\n return true;\n }\n}\n","//\n// renderer.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { VNode } from './reconciler/vnode';\nimport { ComponentNode, NativeElementType } from './types/component';\nimport { reconciler } from './reconciler/state';\nimport nextick from 'nextick';\nimport { equalDeps } from './reconciler/utils';\nimport { _ParentComponent } from './components/pairs';\n\nexport abstract class _Renderer<T> {\n\n protected abstract _beforeUpdate(): void;\n\n protected abstract _afterUpdate(): void;\n\n protected abstract _createElement(node: VNode, stack: VNode[]): T;\n\n protected abstract _updateElement(node: VNode, element: T, children: (T | string)[], stack: VNode[], force?: boolean): void;\n\n protected abstract _destroyElement(node: VNode, element: T): void;\n\n abstract get _server(): boolean;\n\n private async _createRoot(\n root: T | null,\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) {\n\n const runtime = reconciler.buildVNodes(component, this);\n\n type _State = {\n hook: string;\n deps: any;\n unmount?: () => void;\n };\n\n const mountState = new Map<VNode, _State[]>();\n\n const resolveChildren = (node: VNode, elements: Map<VNode, { native?: T }>) => {\n const childrenOfParent = (node: VNode, allowedChild: (node: string | VNode) => boolean): (string | T)[] => _.flatMap(node.children, x => {\n if (_.isString(x)) return allowedChild(x) ? x : [];\n const _node = elements.get(x)?.native;\n if (allowedChild(x)) return _node ?? children(x);\n return _node ? [] : childrenOfParent(x, allowedChild);\n });\n const children = (node: VNode): (string | T)[] => _.flatMap(node.children, x => {\n if (_.isString(x)) return x;\n const _node = elements.get(x)?.native;\n if (_node instanceof _ParentComponent) return childrenOfParent(x, c => _node.isChildNode(c));\n return _node ?? children(x);\n });\n return children(node);\n };\n\n const commit = (elements: Map<VNode, { native?: T }>, updated: Set<VNode>, force?: boolean) => {\n\n const _mount = (node: VNode, stack: VNode[]) => {\n for (const item of node.children) {\n if (item instanceof VNode) _mount(item, [...stack, node]);\n }\n const element = elements.get(node)?.native;\n if (element instanceof _ParentComponent) return;\n if (element && updated.has(node)) {\n try {\n this._updateElement(node, element, resolveChildren(node, elements), stack, force);\n } catch (e) {\n console.error(e);\n }\n }\n const state: _State[] = [];\n const prevState = mountState.get(node) ?? [];\n const curState = node.state;\n for (const i of _.range(Math.max(prevState.length, curState.length))) {\n const unmount = prevState[i]?.unmount;\n const changed = prevState[i]?.hook !== curState[i]?.hook || !equalDeps(prevState[i].deps, curState[i]?.deps);\n if (unmount && changed) {\n try {\n unmount();\n } catch (e) {\n console.error(e);\n }\n }\n state.push({\n hook: curState[i].hook,\n deps: curState[i].deps,\n unmount: options?.skipMount || !changed ? prevState[i]?.unmount : (() => {\n try {\n return curState[i].mount?.();\n } catch (e) {\n console.error(e);\n }\n })(),\n });\n }\n mountState.set(node, state);\n };\n\n for (const [node, state] of mountState) {\n if (elements.has(node)) continue;\n for (const { unmount } of state) {\n try {\n unmount?.();\n } catch (e) {\n console.error(e);\n }\n }\n mountState.delete(node);\n }\n if (root) this._updateElement(\n runtime.node, root,\n _.castArray(elements.get(runtime.node)?.native ?? resolveChildren(runtime.node, elements)),\n [],\n force,\n );\n _mount(runtime.node, [runtime.node]);\n };\n\n const update = async (elements?: Map<VNode, { native?: T }>, force?: boolean) => {\n try {\n this._beforeUpdate();\n } catch (e) {\n console.error(e);\n }\n const map = new Map<VNode, { native?: T }>();\n const updatedNodes = new Set<VNode>();\n for await (const { node, stack, updated } of runtime.excute()) {\n if (node.error) continue;\n if (_.isFunction(node.type) && !(node.type.prototype instanceof NativeElementType)) {\n map.set(node, {});\n } else if (_.isFunction(node.type) && node.type.prototype instanceof _ParentComponent) {\n let elem = elements?.get(node)?.native;\n if (!elem) {\n const Component = node.type as any;\n elem = new Component();\n }\n map.set(node, { native: elem });\n } else {\n const elem = elements?.get(node)?.native;\n if (!elem || updated) updatedNodes.add(node);\n try {\n map.set(node, { native: elem ?? this._createElement(node, stack) });\n } catch (e) {\n console.error(e);\n }\n }\n }\n commit(map, updatedNodes, force);\n if (elements) {\n for (const [node, element] of elements) {\n if (map.has(node) || !element.native) continue;\n try {\n this._destroyElement(node, element.native);\n } catch (e) {\n console.error(e);\n }\n }\n }\n try {\n this._afterUpdate();\n } catch (e) {\n console.error(e);\n }\n return map;\n };\n\n let update_count = 0;\n let render_count = 0;\n let destroyed = false;\n let elements = await update(undefined, true);\n\n const listener = runtime.event.register('onchange', () => {\n if (render_count !== update_count++) return;\n nextick(async () => {\n while (render_count !== update_count) {\n if (destroyed) return;\n const current = update_count;\n elements = await update(elements, false);\n render_count = current;\n }\n });\n });\n\n return {\n get root() {\n if (root) return root;\n const elems = _.castArray(elements.get(runtime.node)?.native ?? resolveChildren(runtime.node, elements));\n const nodes = _.filter(elems, x => !_.isString(x)) as T[];\n return nodes.length === 1 ? nodes[0] : nodes;\n },\n destroy: () => {\n if (root) this._updateElement(runtime.node, root, [], [], true);\n destroyed = true;\n listener.remove();\n for (const state of mountState.values()) {\n for (const { unmount } of state) unmount?.();\n }\n },\n };\n }\n\n createRoot(root?: T) {\n let state: Awaited<ReturnType<typeof this._createRoot>> | undefined;\n return {\n get root() {\n return state?.root;\n },\n mount: async (\n component: ComponentNode,\n options?: {\n skipMount?: boolean;\n },\n ) => {\n state = await this._createRoot(root ?? null, component, options);\n },\n unmount: () => {\n state?.destroy();\n state = undefined;\n },\n };\n }\n}"],"names":[],"mappings":";;AAEO;AACP;AACA;AACA;AACA;AACA;AAMO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5BO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;"}
|
package/dist/server-dom.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { JSDOM } from 'jsdom';
|
|
2
2
|
export * from 'jsdom';
|
|
3
|
-
import { _ as _DOMRenderer } from './internals/renderer-
|
|
3
|
+
import { _ as _DOMRenderer } from './internals/renderer-CJV68U2U.mjs';
|
|
4
4
|
import './internals/common-CpEB3ieX.mjs';
|
|
5
5
|
import '@o2ter/utils-js';
|
|
6
6
|
import 'lodash';
|
|
7
7
|
import 'csstype';
|
|
8
|
-
import './internals/renderer-
|
|
8
|
+
import './internals/renderer-JDjL_fNZ.mjs';
|
|
9
9
|
|
|
10
10
|
declare class ServerDOMRenderer extends _DOMRenderer {
|
|
11
11
|
constructor(dom?: JSDOM);
|
package/dist/server-dom.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { JSDOM } from 'jsdom';
|
|
2
2
|
export * from 'jsdom';
|
|
3
|
-
import { _ as _DOMRenderer } from './internals/renderer-
|
|
3
|
+
import { _ as _DOMRenderer } from './internals/renderer-Bnsr3mNZ.js';
|
|
4
4
|
import './internals/common-CpEB3ieX.js';
|
|
5
5
|
import '@o2ter/utils-js';
|
|
6
6
|
import 'lodash';
|
|
7
7
|
import 'csstype';
|
|
8
|
-
import './internals/renderer
|
|
8
|
+
import './internals/renderer-CtvkpyUB.js';
|
|
9
9
|
|
|
10
10
|
declare class ServerDOMRenderer extends _DOMRenderer {
|
|
11
11
|
constructor(dom?: JSDOM);
|
package/dist/server-dom.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsdom = require('jsdom');
|
|
4
|
-
var renderer = require('./internals/renderer-
|
|
4
|
+
var renderer = require('./internals/renderer-DINmR7Fc.js');
|
|
5
5
|
require('lodash');
|
|
6
6
|
require('myers.js');
|
|
7
|
-
require('./internals/renderer-
|
|
7
|
+
require('./internals/renderer-Dv-IAwBn.js');
|
|
8
8
|
require('./internals/state-C9_fGuhZ.js');
|
|
9
9
|
require('./internals/runtime-57ivQprw.js');
|
|
10
10
|
require('nextick');
|
package/dist/server-dom.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { JSDOM } from 'jsdom';
|
|
2
2
|
export * from 'jsdom';
|
|
3
|
-
import { _ as _DOMRenderer } from './internals/renderer-
|
|
3
|
+
import { _ as _DOMRenderer } from './internals/renderer-B2hPQcF0.mjs';
|
|
4
4
|
import 'lodash';
|
|
5
5
|
import 'myers.js';
|
|
6
|
-
import './internals/renderer-
|
|
6
|
+
import './internals/renderer-DNuaMgXi.mjs';
|
|
7
7
|
import './internals/state-DgSrjGGU.mjs';
|
|
8
8
|
import './internals/runtime-Dp4_akLf.mjs';
|
|
9
9
|
import 'nextick';
|
package/dist/web.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { S as SetStateAction, R as RefObject } from './internals/common-CpEB3ieX.mjs';
|
|
2
2
|
import * as jsdom from 'jsdom';
|
|
3
|
-
export { D as DOMNativeNode, _ as _DOMRenderer } from './internals/renderer-
|
|
3
|
+
export { D as DOMNativeNode, _ as _DOMRenderer } from './internals/renderer-CJV68U2U.mjs';
|
|
4
4
|
import '@o2ter/utils-js';
|
|
5
5
|
import 'lodash';
|
|
6
6
|
import 'csstype';
|
|
7
|
-
import './internals/renderer-
|
|
7
|
+
import './internals/renderer-JDjL_fNZ.mjs';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Hook to access the current document object in a web renderer.
|
package/dist/web.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { S as SetStateAction, R as RefObject } from './internals/common-CpEB3ieX.js';
|
|
2
2
|
import * as jsdom from 'jsdom';
|
|
3
|
-
export { D as DOMNativeNode, _ as _DOMRenderer } from './internals/renderer-
|
|
3
|
+
export { D as DOMNativeNode, _ as _DOMRenderer } from './internals/renderer-Bnsr3mNZ.js';
|
|
4
4
|
import '@o2ter/utils-js';
|
|
5
5
|
import 'lodash';
|
|
6
6
|
import 'csstype';
|
|
7
|
-
import './internals/renderer
|
|
7
|
+
import './internals/renderer-CtvkpyUB.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Hook to access the current document object in a web renderer.
|
package/dist/web.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var state = require('./internals/state-C9_fGuhZ.js');
|
|
4
|
-
var renderer = require('./internals/renderer-
|
|
4
|
+
var renderer = require('./internals/renderer-DINmR7Fc.js');
|
|
5
5
|
var _ = require('lodash');
|
|
6
6
|
require('myers.js');
|
|
7
7
|
var sync = require('./internals/sync-B7gLfyQK.js');
|
|
@@ -10,7 +10,7 @@ require('postcss');
|
|
|
10
10
|
require('postcss-js');
|
|
11
11
|
require('postcss-nested');
|
|
12
12
|
require('./internals/runtime-57ivQprw.js');
|
|
13
|
-
require('./internals/renderer-
|
|
13
|
+
require('./internals/renderer-Dv-IAwBn.js');
|
|
14
14
|
|
|
15
15
|
//
|
|
16
16
|
// document.ts
|
package/dist/web.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as reconciler, a as uniqueId, d as EventEmitter } from './internals/state-DgSrjGGU.mjs';
|
|
2
|
-
import { _ as _DOMRenderer } from './internals/renderer-
|
|
3
|
-
export { D as DOMNativeNode } from './internals/renderer-
|
|
2
|
+
import { _ as _DOMRenderer } from './internals/renderer-B2hPQcF0.mjs';
|
|
3
|
+
export { D as DOMNativeNode } from './internals/renderer-B2hPQcF0.mjs';
|
|
4
4
|
import _ from 'lodash';
|
|
5
5
|
import 'myers.js';
|
|
6
6
|
import { c as useSyncExternalStore, u as useMemo, b as useCallback, a as useEffect } from './internals/sync-CeJllG9M.mjs';
|
|
@@ -9,7 +9,7 @@ import 'postcss';
|
|
|
9
9
|
import 'postcss-js';
|
|
10
10
|
import 'postcss-nested';
|
|
11
11
|
import './internals/runtime-Dp4_akLf.mjs';
|
|
12
|
-
import './internals/renderer-
|
|
12
|
+
import './internals/renderer-DNuaMgXi.mjs';
|
|
13
13
|
|
|
14
14
|
//
|
|
15
15
|
// document.ts
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frosty",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.115",
|
|
4
4
|
"main": "dist/index",
|
|
5
5
|
"module": "dist/index",
|
|
6
6
|
"types": "dist/index",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"types": "./dist/index.mjs",
|
|
10
|
+
"default": "./dist/index"
|
|
11
11
|
},
|
|
12
12
|
"./*": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
13
|
+
"types": "./dist/*.mjs",
|
|
14
|
+
"default": "./dist/*"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renderer-BQawOCgo.d.mts","sources":["../../src/renderer/common/node.ts","../../src/renderer/common/renderer.ts"],"sourcesContent":["//\n// common.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport type { _DOMRenderer } from './renderer';\nimport { myersSync } from 'myers.js';\nimport { globalEvents } from '../../core/web/event';\nimport { NativeElementType } from '../../core/types/component';\nimport { svgProps, htmlProps } from '../../../generated/elements';\nimport { _propValue } from '../../core/web/props';\nimport { _Renderer } from '../../core/renderer';\n\nconst findPrototypeProperty = (object: any, propertyName: string) => {\n while (object && object.constructor && object.constructor.name !== 'Object') {\n let desc = Object.getOwnPropertyDescriptor(object, propertyName);\n if (desc) return desc;\n object = Object.getPrototypeOf(object);\n }\n return null;\n};\n\nconst isWriteable = (object: any, propertyName: string) => {\n let desc = findPrototypeProperty(object, propertyName);\n if (!desc) {\n return false;\n }\n if (desc.writable && typeof desc.value !== 'function') {\n return true;\n }\n return !!desc.set;\n};\n\nconst tracked_props = new WeakMap<Element, string[]>();\nconst tracked_listeners = new WeakMap<Element, Record<string, EventListener | undefined>>();\nconst _updateEventListener = (\n element: Element,\n key: string,\n listener: EventListener | undefined,\n) => {\n const event = key.endsWith('Capture') ? key.slice(2, -7).toLowerCase() : key.slice(2).toLowerCase();\n const listeners = tracked_listeners.get(element) ?? {};\n if (!tracked_listeners.has(element)) tracked_listeners.set(element, listeners);\n if (listeners[key] !== listener) {\n const options = { capture: key.endsWith('Capture') };\n if (_.isFunction(listeners[key])) element.removeEventListener(event, listeners[key], options);\n if (_.isFunction(listener)) element.addEventListener(event, listener, options);\n }\n listeners[key] = listener;\n}\n\nconst DOMUtils = new class {\n\n update(\n element: Element,\n { className, style, ...props }: Record<string, any> & {\n className?: string;\n style?: string;\n },\n ) {\n if (className) {\n if (element.className !== className)\n element.className = className;\n } else if (!_.isNil(element.getAttribute('class'))) {\n element.removeAttribute('class');\n }\n if (style) {\n const oldValue = element.getAttribute('style');\n if (oldValue !== style)\n element.setAttribute('style', style);\n } else if (!_.isNil(element.getAttribute('style'))) {\n element.removeAttribute('style');\n }\n for (const [key, value] of _.entries(props)) {\n if (_.includes(globalEvents, key)) {\n _updateEventListener(element, key, value);\n } else if (key.endsWith('Capture') && _.includes(globalEvents, key.slice(0, -7))) {\n _updateEventListener(element, key, value);\n } else if (key.startsWith('data-')) {\n const oldValue = element.getAttribute(key);\n if (value === false || _.isNil(value)) {\n if (!_.isNil(oldValue))\n element.removeAttribute(key);\n } else {\n const newValue = value === true ? '' : `${value}`;\n if (oldValue !== newValue)\n element.setAttribute(key, newValue);\n }\n } else {\n const tagName = _.toLower(element.tagName);\n const { type: _type, attr } = (htmlProps as any)['*'][key]\n ?? (htmlProps as any)[tagName]?.[key]\n ?? (svgProps as any)['*'][key]\n ?? (svgProps as any)[tagName]?.[key]\n ?? {};\n const tracked = tracked_props.get(element) ?? [];\n const writeable = isWriteable(element, key);\n if (!tracked_props.has(element)) tracked_props.set(element, tracked);\n const assigned = _.includes(tracked, key);\n if (writeable && !_.isNil(value)) {\n if (!assigned || (element as any)[key] !== value) (element as any)[key] = value;\n if (!assigned) tracked.push(key);\n } else if (_type && attr && (_propValue as any)[_type]) {\n const oldValue = element.getAttribute(attr);\n if (value === false || _.isNil(value)) {\n if (!_.isNil(oldValue))\n element.removeAttribute(attr);\n } else {\n const newValue = value === true ? '' : `${value}`;\n if (oldValue !== newValue)\n element.setAttribute(attr, newValue);\n }\n } else if (writeable) {\n if (!assigned || (element as any)[key] !== value) (element as any)[key] = value;\n if (!assigned) tracked.push(key);\n }\n }\n }\n }\n\n replaceChildren(\n element: Element,\n children: (string | Element | DOMNativeNode)[],\n shouldRemove: (child: ChildNode) => boolean = () => true,\n ) {\n const document = element.ownerDocument;\n const diff = myersSync(\n _.map(element.childNodes, x => x.nodeType === document.TEXT_NODE ? x.textContent ?? '' : x),\n _.flatMap(children, x => x instanceof DOMNativeNode ? x.target : x),\n { compare: (a, b) => a === b },\n );\n let i = 0;\n for (const { remove, insert, equivalent } of diff) {\n if (equivalent) {\n i += equivalent.length;\n } else if (remove) {\n for (const child of remove) {\n if (_.isString(child) || shouldRemove(child)) {\n element.removeChild(element.childNodes[i]);\n } else {\n i++;\n }\n }\n }\n if (insert) {\n for (const child of insert) {\n const node = _.isString(child) ? document.createTextNode(child) : child;\n element.insertBefore(node, element.childNodes[i++]);\n }\n }\n }\n }\n\n destroy(element: Element) {\n const listeners = tracked_listeners.get(element);\n for (const [key, listener] of _.entries(listeners)) {\n const event = key.endsWith('Capture') ? key.slice(2, -7).toLowerCase() : key.slice(2).toLowerCase();\n if (_.isFunction(listener)) {\n element.removeEventListener(event, listener, { capture: key.endsWith('Capture') });\n }\n }\n tracked_listeners.delete(element);\n }\n}\n\nexport abstract class DOMNativeNode extends NativeElementType {\n\n static get Utils() { return DOMUtils; }\n\n static createElement: (doc: Document, renderer: _DOMRenderer) => DOMNativeNode;\n\n abstract get target(): Element | Element[];\n\n abstract update(props: Record<string, any> & {\n className?: string;\n style?: string;\n }): void;\n\n abstract replaceChildren(children: (string | Element | DOMNativeNode)[]): void;\n\n abstract destroy(): void;\n}\n","//\n// renderer.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { VNode } from '../../core/reconciler/vnode';\nimport { ComponentNode } from '../../core/types/component';\nimport { tags } from '../../../generated/elements';\nimport { _propValue } from '../../core/web/props';\nimport { ClassName, StyleProp } from '../../core/types/style';\nimport { ExtendedCSSProperties } from '../../core/web/styles/css';\nimport { _Renderer } from '../../core/renderer';\nimport { processCss } from '../../core/web/styles/process';\nimport { StyleBuilder } from '../style';\nimport { mergeRefs } from '../../core/utils';\nimport type { DOMWindow } from 'jsdom';\nimport { compress } from '../minify/compress';\nimport { DOMNativeNode } from './node';\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\nconst HTML_NS = 'http://www.w3.org/1999/xhtml';\nconst MATHML_NS = 'http://www.w3.org/1998/Math/MathML';\n\nexport abstract class _DOMRenderer extends _Renderer<Element | DOMNativeNode> {\n\n private _window: Window | DOMWindow;\n private _namespace_map = new WeakMap<VNode, string | undefined>();\n\n private _tracked_head_children: (string | Element | DOMNativeNode)[] = [];\n private _tracked_style = new StyleBuilder();\n /** @internal */\n _tracked_server_resource = new Map<string, string>();\n private _tracked_elements = new Map<Element | DOMNativeNode, { props: string[]; className: string[]; }>();\n\n constructor(window: Window | DOMWindow) {\n super();\n this._window = window;\n }\n\n get document() {\n return this.window.document;\n }\n\n get window() {\n return this._window;\n }\n\n /** @internal */\n _beforeUpdate() {\n if (this._server) {\n this._tracked_head_children = [];\n this._tracked_server_resource = new Map<string, string>();\n }\n }\n\n /** @internal */\n _afterUpdate() {\n this._tracked_style.select([...this._tracked_elements.values().flatMap(({ className }) => className)]);\n const head = this.document.head ?? this.document.createElementNS(HTML_NS, 'head');\n const styleElem = this.document.querySelector('style[data-frosty-style]') ?? this.document.createElementNS(HTML_NS, 'style');\n styleElem.setAttribute('data-frosty-style', '');\n if (styleElem.textContent !== this._tracked_style.css)\n styleElem.textContent = this._tracked_style.css;\n if (this._server) {\n const ssrData = this._tracked_server_resource.size ? this.document.createElementNS(HTML_NS, 'script') : undefined;\n if (ssrData) {\n ssrData.setAttribute('data-frosty-ssr-data', '');\n ssrData.setAttribute('type', 'text/plain');\n ssrData.innerHTML = compress(JSON.stringify(Object.fromEntries(this._tracked_server_resource)));\n }\n DOMNativeNode.Utils.replaceChildren(head, _.compact([\n ...this._tracked_head_children,\n styleElem.textContent && styleElem,\n ssrData,\n ]), (x) => this._tracked_elements.has(x as any));\n } else if (styleElem.parentNode !== head && styleElem.textContent) {\n head.appendChild(styleElem);\n }\n if (!this.document.head) {\n this.document.documentElement.insertBefore(head, this.document.body);\n }\n }\n\n /** @internal */\n _createElement(node: VNode, stack: VNode[]) {\n const { type } = node;\n if (!_.isString(type) && type.prototype instanceof DOMNativeNode) {\n const ElementType = type as typeof DOMNativeNode;\n const elem = ElementType.createElement(this.document, this);\n this._tracked_elements.set(elem, {\n props: [],\n className: [],\n });\n this._updateElement(node, elem, stack);\n return elem;\n }\n if (!_.isString(type)) throw Error('Invalid type');\n switch (type) {\n case 'html': return this.document.documentElement;\n case 'head': return this.document.head ?? this.document.createElementNS(HTML_NS, 'head');\n case 'body': return this.document.body ?? this.document.createElementNS(HTML_NS, 'body');\n default: break;\n }\n const _ns_list = _.compact([\n _.includes(tags.svg, type) && SVG_NS,\n _.includes(tags.html, type) && HTML_NS,\n _.includes(tags.mathml, type) && MATHML_NS,\n ]);\n const parent = _.last(stack);\n const ns = _ns_list.length > 1 ? parent && _.first(_.intersection([this._namespace_map.get(parent)], _ns_list)) : _.first(_ns_list);\n const elem = ns ? this.document.createElementNS(ns, type) : this.document.createElement(type);\n this._namespace_map.set(node, ns);\n this._tracked_elements.set(elem, {\n props: [],\n className: [],\n });\n this._updateElement(node, elem, stack);\n return elem;\n }\n\n private __createBuiltClassName(\n element: Element | DOMNativeNode,\n className: ClassName,\n style: StyleProp<ExtendedCSSProperties>,\n ) {\n const _className = _.compact(_.flattenDeep([className]));\n const built = this._tracked_style.buildStyle(_.compact(_.flattenDeep([style])));\n const tracked = this._tracked_elements.get(element);\n if (tracked) tracked.className = built;\n return [..._className, ...built].join(' ');\n }\n\n /** @internal */\n _updateElement(node: VNode, element: Element | DOMNativeNode, stack: VNode[]) {\n\n if (element instanceof DOMNativeNode) {\n const {\n props: { ref, className, style, inlineStyle, ..._props }\n } = node;\n if (ref) mergeRefs(ref)(element.target);\n const builtClassName = this.__createBuiltClassName(element, className, style);\n const { css } = processCss(inlineStyle);\n element.update({\n className: builtClassName ? builtClassName : undefined,\n style: css ? css : undefined,\n ..._props\n });\n return;\n }\n\n const {\n type,\n props: { ref, className, style, inlineStyle, innerHTML, ..._props }\n } = node;\n\n if (!_.isString(type)) throw Error('Invalid type');\n switch (type) {\n case 'html': return;\n case 'head': return;\n case 'body': return;\n default: break;\n }\n\n if (ref) mergeRefs(ref)(element);\n\n const tracked = this._tracked_elements.get(element);\n if (!tracked) return;\n const removed = _.difference(tracked.props, _.keys(_props));\n tracked.props = _.keys(_props);\n\n const builtClassName = this.__createBuiltClassName(element, className, style);\n if (!_.isEmpty(innerHTML) && element.innerHTML !== innerHTML) element.innerHTML = innerHTML;\n\n DOMNativeNode.Utils.update(element, {\n className: builtClassName,\n style: inlineStyle ? processCss(inlineStyle).css : undefined,\n ..._props,\n ..._.fromPairs(_.map(removed, x => [x, undefined])),\n });\n }\n\n /** @internal */\n _replaceChildren(node: VNode, element: Element | DOMNativeNode, children: (string | Element | DOMNativeNode)[], stack: VNode[], force?: boolean) {\n if (element instanceof DOMNativeNode) {\n element.replaceChildren(children);\n } else {\n const {\n type,\n props: { innerHTML }\n } = node;\n if (type === 'head') {\n this._tracked_head_children.push(...children);\n } else if (_.isEmpty(innerHTML)) {\n DOMNativeNode.Utils.replaceChildren(element, children, (x) => !!force || this._tracked_elements.has(x as any));\n }\n }\n }\n\n /** @internal */\n _destroyElement(node: VNode, element: Element | DOMNativeNode) {\n if (element instanceof DOMNativeNode) {\n element.destroy();\n } else {\n DOMNativeNode.Utils.destroy(element);\n }\n }\n\n async renderToString(component: ComponentNode) {\n const root = this.createRoot();\n try {\n await root.mount(component, { skipMount: true });\n const elements = _.flatMap(_.castArray(root.root ?? []), x => x instanceof DOMNativeNode ? x.target : x);\n const str = _.map(elements, x => x.outerHTML).join('');\n return str.startsWith('<html>') ? `<!DOCTYPE html>${str}` : str;\n } finally {\n root.unmount();\n }\n }\n}\n"],"names":[],"mappings":";;;;AAEO,uBAAA,aAAA,SAAA,iBAAA;AACP;AACA,wBAAA,OAAA,kCAAA,MAAA;AACA;AACA;AACA;AACA,iCAAA,OAAA,sBAAA,OAAA,GAAA,aAAA,4BAAA,SAAA;AACA,yBAAA,OAAA;AACA;AACA,gCAAA,QAAA,YAAA,YAAA,KAAA,aAAA;AACA,2BAAA,OAAA,GAAA,OAAA;AACA,2BAAA,MAAA;AACA;AACA;AACA;AACA,iDAAA,OAAA,GAAA,aAAA;AACA;AACA;;ACfO,uBAAA,YAAA,SAAA,SAAA,CAAA,OAAA,GAAA,aAAA;AACP;AACA;AACA;AACA;AACA;AACA,wBAAA,MAAA,GAAA,SAAA;AACA,oBAAA,QAAA;AACA,kBAAA,MAAA,GAAA,SAAA;AACA;AACA,8BAAA,aAAA,GAAA,OAAA;AACA;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renderer-Bv5pi6kG.d.ts","sources":["../../src/renderer/common/node.ts","../../src/renderer/common/renderer.ts"],"sourcesContent":["//\n// common.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport type { _DOMRenderer } from './renderer';\nimport { myersSync } from 'myers.js';\nimport { globalEvents } from '../../core/web/event';\nimport { NativeElementType } from '../../core/types/component';\nimport { svgProps, htmlProps } from '../../../generated/elements';\nimport { _propValue } from '../../core/web/props';\nimport { _Renderer } from '../../core/renderer';\n\nconst findPrototypeProperty = (object: any, propertyName: string) => {\n while (object && object.constructor && object.constructor.name !== 'Object') {\n let desc = Object.getOwnPropertyDescriptor(object, propertyName);\n if (desc) return desc;\n object = Object.getPrototypeOf(object);\n }\n return null;\n};\n\nconst isWriteable = (object: any, propertyName: string) => {\n let desc = findPrototypeProperty(object, propertyName);\n if (!desc) {\n return false;\n }\n if (desc.writable && typeof desc.value !== 'function') {\n return true;\n }\n return !!desc.set;\n};\n\nconst tracked_props = new WeakMap<Element, string[]>();\nconst tracked_listeners = new WeakMap<Element, Record<string, EventListener | undefined>>();\nconst _updateEventListener = (\n element: Element,\n key: string,\n listener: EventListener | undefined,\n) => {\n const event = key.endsWith('Capture') ? key.slice(2, -7).toLowerCase() : key.slice(2).toLowerCase();\n const listeners = tracked_listeners.get(element) ?? {};\n if (!tracked_listeners.has(element)) tracked_listeners.set(element, listeners);\n if (listeners[key] !== listener) {\n const options = { capture: key.endsWith('Capture') };\n if (_.isFunction(listeners[key])) element.removeEventListener(event, listeners[key], options);\n if (_.isFunction(listener)) element.addEventListener(event, listener, options);\n }\n listeners[key] = listener;\n}\n\nconst DOMUtils = new class {\n\n update(\n element: Element,\n { className, style, ...props }: Record<string, any> & {\n className?: string;\n style?: string;\n },\n ) {\n if (className) {\n if (element.className !== className)\n element.className = className;\n } else if (!_.isNil(element.getAttribute('class'))) {\n element.removeAttribute('class');\n }\n if (style) {\n const oldValue = element.getAttribute('style');\n if (oldValue !== style)\n element.setAttribute('style', style);\n } else if (!_.isNil(element.getAttribute('style'))) {\n element.removeAttribute('style');\n }\n for (const [key, value] of _.entries(props)) {\n if (_.includes(globalEvents, key)) {\n _updateEventListener(element, key, value);\n } else if (key.endsWith('Capture') && _.includes(globalEvents, key.slice(0, -7))) {\n _updateEventListener(element, key, value);\n } else if (key.startsWith('data-')) {\n const oldValue = element.getAttribute(key);\n if (value === false || _.isNil(value)) {\n if (!_.isNil(oldValue))\n element.removeAttribute(key);\n } else {\n const newValue = value === true ? '' : `${value}`;\n if (oldValue !== newValue)\n element.setAttribute(key, newValue);\n }\n } else {\n const tagName = _.toLower(element.tagName);\n const { type: _type, attr } = (htmlProps as any)['*'][key]\n ?? (htmlProps as any)[tagName]?.[key]\n ?? (svgProps as any)['*'][key]\n ?? (svgProps as any)[tagName]?.[key]\n ?? {};\n const tracked = tracked_props.get(element) ?? [];\n const writeable = isWriteable(element, key);\n if (!tracked_props.has(element)) tracked_props.set(element, tracked);\n const assigned = _.includes(tracked, key);\n if (writeable && !_.isNil(value)) {\n if (!assigned || (element as any)[key] !== value) (element as any)[key] = value;\n if (!assigned) tracked.push(key);\n } else if (_type && attr && (_propValue as any)[_type]) {\n const oldValue = element.getAttribute(attr);\n if (value === false || _.isNil(value)) {\n if (!_.isNil(oldValue))\n element.removeAttribute(attr);\n } else {\n const newValue = value === true ? '' : `${value}`;\n if (oldValue !== newValue)\n element.setAttribute(attr, newValue);\n }\n } else if (writeable) {\n if (!assigned || (element as any)[key] !== value) (element as any)[key] = value;\n if (!assigned) tracked.push(key);\n }\n }\n }\n }\n\n replaceChildren(\n element: Element,\n children: (string | Element | DOMNativeNode)[],\n shouldRemove: (child: ChildNode) => boolean = () => true,\n ) {\n const document = element.ownerDocument;\n const diff = myersSync(\n _.map(element.childNodes, x => x.nodeType === document.TEXT_NODE ? x.textContent ?? '' : x),\n _.flatMap(children, x => x instanceof DOMNativeNode ? x.target : x),\n { compare: (a, b) => a === b },\n );\n let i = 0;\n for (const { remove, insert, equivalent } of diff) {\n if (equivalent) {\n i += equivalent.length;\n } else if (remove) {\n for (const child of remove) {\n if (_.isString(child) || shouldRemove(child)) {\n element.removeChild(element.childNodes[i]);\n } else {\n i++;\n }\n }\n }\n if (insert) {\n for (const child of insert) {\n const node = _.isString(child) ? document.createTextNode(child) : child;\n element.insertBefore(node, element.childNodes[i++]);\n }\n }\n }\n }\n\n destroy(element: Element) {\n const listeners = tracked_listeners.get(element);\n for (const [key, listener] of _.entries(listeners)) {\n const event = key.endsWith('Capture') ? key.slice(2, -7).toLowerCase() : key.slice(2).toLowerCase();\n if (_.isFunction(listener)) {\n element.removeEventListener(event, listener, { capture: key.endsWith('Capture') });\n }\n }\n tracked_listeners.delete(element);\n }\n}\n\nexport abstract class DOMNativeNode extends NativeElementType {\n\n static get Utils() { return DOMUtils; }\n\n static createElement: (doc: Document, renderer: _DOMRenderer) => DOMNativeNode;\n\n abstract get target(): Element | Element[];\n\n abstract update(props: Record<string, any> & {\n className?: string;\n style?: string;\n }): void;\n\n abstract replaceChildren(children: (string | Element | DOMNativeNode)[]): void;\n\n abstract destroy(): void;\n}\n","//\n// renderer.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { VNode } from '../../core/reconciler/vnode';\nimport { ComponentNode } from '../../core/types/component';\nimport { tags } from '../../../generated/elements';\nimport { _propValue } from '../../core/web/props';\nimport { ClassName, StyleProp } from '../../core/types/style';\nimport { ExtendedCSSProperties } from '../../core/web/styles/css';\nimport { _Renderer } from '../../core/renderer';\nimport { processCss } from '../../core/web/styles/process';\nimport { StyleBuilder } from '../style';\nimport { mergeRefs } from '../../core/utils';\nimport type { DOMWindow } from 'jsdom';\nimport { compress } from '../minify/compress';\nimport { DOMNativeNode } from './node';\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\nconst HTML_NS = 'http://www.w3.org/1999/xhtml';\nconst MATHML_NS = 'http://www.w3.org/1998/Math/MathML';\n\nexport abstract class _DOMRenderer extends _Renderer<Element | DOMNativeNode> {\n\n private _window: Window | DOMWindow;\n private _namespace_map = new WeakMap<VNode, string | undefined>();\n\n private _tracked_head_children: (string | Element | DOMNativeNode)[] = [];\n private _tracked_style = new StyleBuilder();\n /** @internal */\n _tracked_server_resource = new Map<string, string>();\n private _tracked_elements = new Map<Element | DOMNativeNode, { props: string[]; className: string[]; }>();\n\n constructor(window: Window | DOMWindow) {\n super();\n this._window = window;\n }\n\n get document() {\n return this.window.document;\n }\n\n get window() {\n return this._window;\n }\n\n /** @internal */\n _beforeUpdate() {\n if (this._server) {\n this._tracked_head_children = [];\n this._tracked_server_resource = new Map<string, string>();\n }\n }\n\n /** @internal */\n _afterUpdate() {\n this._tracked_style.select([...this._tracked_elements.values().flatMap(({ className }) => className)]);\n const head = this.document.head ?? this.document.createElementNS(HTML_NS, 'head');\n const styleElem = this.document.querySelector('style[data-frosty-style]') ?? this.document.createElementNS(HTML_NS, 'style');\n styleElem.setAttribute('data-frosty-style', '');\n if (styleElem.textContent !== this._tracked_style.css)\n styleElem.textContent = this._tracked_style.css;\n if (this._server) {\n const ssrData = this._tracked_server_resource.size ? this.document.createElementNS(HTML_NS, 'script') : undefined;\n if (ssrData) {\n ssrData.setAttribute('data-frosty-ssr-data', '');\n ssrData.setAttribute('type', 'text/plain');\n ssrData.innerHTML = compress(JSON.stringify(Object.fromEntries(this._tracked_server_resource)));\n }\n DOMNativeNode.Utils.replaceChildren(head, _.compact([\n ...this._tracked_head_children,\n styleElem.textContent && styleElem,\n ssrData,\n ]), (x) => this._tracked_elements.has(x as any));\n } else if (styleElem.parentNode !== head && styleElem.textContent) {\n head.appendChild(styleElem);\n }\n if (!this.document.head) {\n this.document.documentElement.insertBefore(head, this.document.body);\n }\n }\n\n /** @internal */\n _createElement(node: VNode, stack: VNode[]) {\n const { type } = node;\n if (!_.isString(type) && type.prototype instanceof DOMNativeNode) {\n const ElementType = type as typeof DOMNativeNode;\n const elem = ElementType.createElement(this.document, this);\n this._tracked_elements.set(elem, {\n props: [],\n className: [],\n });\n this._updateElement(node, elem, stack);\n return elem;\n }\n if (!_.isString(type)) throw Error('Invalid type');\n switch (type) {\n case 'html': return this.document.documentElement;\n case 'head': return this.document.head ?? this.document.createElementNS(HTML_NS, 'head');\n case 'body': return this.document.body ?? this.document.createElementNS(HTML_NS, 'body');\n default: break;\n }\n const _ns_list = _.compact([\n _.includes(tags.svg, type) && SVG_NS,\n _.includes(tags.html, type) && HTML_NS,\n _.includes(tags.mathml, type) && MATHML_NS,\n ]);\n const parent = _.last(stack);\n const ns = _ns_list.length > 1 ? parent && _.first(_.intersection([this._namespace_map.get(parent)], _ns_list)) : _.first(_ns_list);\n const elem = ns ? this.document.createElementNS(ns, type) : this.document.createElement(type);\n this._namespace_map.set(node, ns);\n this._tracked_elements.set(elem, {\n props: [],\n className: [],\n });\n this._updateElement(node, elem, stack);\n return elem;\n }\n\n private __createBuiltClassName(\n element: Element | DOMNativeNode,\n className: ClassName,\n style: StyleProp<ExtendedCSSProperties>,\n ) {\n const _className = _.compact(_.flattenDeep([className]));\n const built = this._tracked_style.buildStyle(_.compact(_.flattenDeep([style])));\n const tracked = this._tracked_elements.get(element);\n if (tracked) tracked.className = built;\n return [..._className, ...built].join(' ');\n }\n\n /** @internal */\n _updateElement(node: VNode, element: Element | DOMNativeNode, stack: VNode[]) {\n\n if (element instanceof DOMNativeNode) {\n const {\n props: { ref, className, style, inlineStyle, ..._props }\n } = node;\n if (ref) mergeRefs(ref)(element.target);\n const builtClassName = this.__createBuiltClassName(element, className, style);\n const { css } = processCss(inlineStyle);\n element.update({\n className: builtClassName ? builtClassName : undefined,\n style: css ? css : undefined,\n ..._props\n });\n return;\n }\n\n const {\n type,\n props: { ref, className, style, inlineStyle, innerHTML, ..._props }\n } = node;\n\n if (!_.isString(type)) throw Error('Invalid type');\n switch (type) {\n case 'html': return;\n case 'head': return;\n case 'body': return;\n default: break;\n }\n\n if (ref) mergeRefs(ref)(element);\n\n const tracked = this._tracked_elements.get(element);\n if (!tracked) return;\n const removed = _.difference(tracked.props, _.keys(_props));\n tracked.props = _.keys(_props);\n\n const builtClassName = this.__createBuiltClassName(element, className, style);\n if (!_.isEmpty(innerHTML) && element.innerHTML !== innerHTML) element.innerHTML = innerHTML;\n\n DOMNativeNode.Utils.update(element, {\n className: builtClassName,\n style: inlineStyle ? processCss(inlineStyle).css : undefined,\n ..._props,\n ..._.fromPairs(_.map(removed, x => [x, undefined])),\n });\n }\n\n /** @internal */\n _replaceChildren(node: VNode, element: Element | DOMNativeNode, children: (string | Element | DOMNativeNode)[], stack: VNode[], force?: boolean) {\n if (element instanceof DOMNativeNode) {\n element.replaceChildren(children);\n } else {\n const {\n type,\n props: { innerHTML }\n } = node;\n if (type === 'head') {\n this._tracked_head_children.push(...children);\n } else if (_.isEmpty(innerHTML)) {\n DOMNativeNode.Utils.replaceChildren(element, children, (x) => !!force || this._tracked_elements.has(x as any));\n }\n }\n }\n\n /** @internal */\n _destroyElement(node: VNode, element: Element | DOMNativeNode) {\n if (element instanceof DOMNativeNode) {\n element.destroy();\n } else {\n DOMNativeNode.Utils.destroy(element);\n }\n }\n\n async renderToString(component: ComponentNode) {\n const root = this.createRoot();\n try {\n await root.mount(component, { skipMount: true });\n const elements = _.flatMap(_.castArray(root.root ?? []), x => x instanceof DOMNativeNode ? x.target : x);\n const str = _.map(elements, x => x.outerHTML).join('');\n return str.startsWith('<html>') ? `<!DOCTYPE html>${str}` : str;\n } finally {\n root.unmount();\n }\n }\n}\n"],"names":[],"mappings":";;;;AAEO,uBAAA,aAAA,SAAA,iBAAA;AACP;AACA,wBAAA,OAAA,kCAAA,MAAA;AACA;AACA;AACA;AACA,iCAAA,OAAA,sBAAA,OAAA,GAAA,aAAA,4BAAA,SAAA;AACA,yBAAA,OAAA;AACA;AACA,gCAAA,QAAA,YAAA,YAAA,KAAA,aAAA;AACA,2BAAA,OAAA,GAAA,OAAA;AACA,2BAAA,MAAA;AACA;AACA;AACA;AACA,iDAAA,OAAA,GAAA,aAAA;AACA;AACA;;ACfO,uBAAA,YAAA,SAAA,SAAA,CAAA,OAAA,GAAA,aAAA;AACP;AACA;AACA;AACA;AACA;AACA,wBAAA,MAAA,GAAA,SAAA;AACA,oBAAA,QAAA;AACA,kBAAA,MAAA,GAAA,SAAA;AACA;AACA,8BAAA,aAAA,GAAA,OAAA;AACA;;;;"}
|