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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { N as NativeElementType, C as ComponentNode } from './common-CpEB3ieX.js';
|
|
2
|
-
import { _ as _Renderer } from './renderer
|
|
2
|
+
import { _ as _Renderer } from './renderer-CtvkpyUB.js';
|
|
3
3
|
import { DOMWindow } from 'jsdom';
|
|
4
4
|
|
|
5
5
|
declare abstract class DOMNativeNode extends NativeElementType {
|
|
@@ -16,8 +16,7 @@ declare abstract class DOMNativeNode extends NativeElementType {
|
|
|
16
16
|
abstract update(props: Record<string, any> & {
|
|
17
17
|
className?: string;
|
|
18
18
|
style?: string;
|
|
19
|
-
}): void;
|
|
20
|
-
abstract replaceChildren(children: (string | Element | DOMNativeNode)[]): void;
|
|
19
|
+
}, children: (string | Element | DOMNativeNode)[]): void;
|
|
21
20
|
abstract destroy(): void;
|
|
22
21
|
}
|
|
23
22
|
|
|
@@ -35,4 +34,4 @@ declare abstract class _DOMRenderer extends _Renderer<Element | DOMNativeNode> {
|
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
export { DOMNativeNode as D, _DOMRenderer as _ };
|
|
38
|
-
//# sourceMappingURL=renderer-
|
|
37
|
+
//# sourceMappingURL=renderer-Bnsr3mNZ.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer-Bnsr3mNZ.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(\n props: Record<string, any> & {\n className?: string;\n style?: string;\n },\n children: (string | Element | DOMNativeNode)[]\n ): 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 return elem;\n }\n if (!_.isString(type)) throw Error(`Invalid type ${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 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(\n node: VNode,\n element: Element | DOMNativeNode,\n children: (string | Element | DOMNativeNode)[],\n stack: VNode[],\n force?: boolean\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 }, children);\n return;\n }\n\n if (_.isEmpty(stack)) {\n DOMNativeNode.Utils.replaceChildren(element, children, (x) => !!force || this._tracked_elements.has(x as any));\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 ${type}`);\n switch (type) {\n case 'head': {\n this._tracked_head_children.push(...children);\n return;\n }\n default: break;\n }\n\n if (ref) mergeRefs(ref)(element);\n\n const tracked = this._tracked_elements.get(element);\n const removed = tracked ? _.difference(tracked.props, _.keys(_props)) : [];\n if (tracked) tracked.props = _.keys(_props);\n\n const builtClassName = this.__createBuiltClassName(element, className, style);\n if (_.isNil(innerHTML)) {\n DOMNativeNode.Utils.replaceChildren(element, children, (x) => !!force || this._tracked_elements.has(x as any));\n } else if (element.innerHTML !== innerHTML) {\n element.innerHTML = innerHTML;\n }\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 _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 if (elements.length !== 1) return str;\n return elements[0].tagName.toLowerCase() === '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,2BAAA,OAAA,GAAA,aAAA;AACA;AACA;;ACdO,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,5 +1,5 @@
|
|
|
1
1
|
import { N as NativeElementType, C as ComponentNode } from './common-CpEB3ieX.mjs';
|
|
2
|
-
import { _ as _Renderer } from './renderer-
|
|
2
|
+
import { _ as _Renderer } from './renderer-JDjL_fNZ.mjs';
|
|
3
3
|
import { DOMWindow } from 'jsdom';
|
|
4
4
|
|
|
5
5
|
declare abstract class DOMNativeNode extends NativeElementType {
|
|
@@ -16,8 +16,7 @@ declare abstract class DOMNativeNode extends NativeElementType {
|
|
|
16
16
|
abstract update(props: Record<string, any> & {
|
|
17
17
|
className?: string;
|
|
18
18
|
style?: string;
|
|
19
|
-
}): void;
|
|
20
|
-
abstract replaceChildren(children: (string | Element | DOMNativeNode)[]): void;
|
|
19
|
+
}, children: (string | Element | DOMNativeNode)[]): void;
|
|
21
20
|
abstract destroy(): void;
|
|
22
21
|
}
|
|
23
22
|
|
|
@@ -35,4 +34,4 @@ declare abstract class _DOMRenderer extends _Renderer<Element | DOMNativeNode> {
|
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
export { DOMNativeNode as D, _DOMRenderer as _ };
|
|
38
|
-
//# sourceMappingURL=renderer-
|
|
37
|
+
//# sourceMappingURL=renderer-CJV68U2U.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer-CJV68U2U.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(\n props: Record<string, any> & {\n className?: string;\n style?: string;\n },\n children: (string | Element | DOMNativeNode)[]\n ): 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 return elem;\n }\n if (!_.isString(type)) throw Error(`Invalid type ${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 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(\n node: VNode,\n element: Element | DOMNativeNode,\n children: (string | Element | DOMNativeNode)[],\n stack: VNode[],\n force?: boolean\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 }, children);\n return;\n }\n\n if (_.isEmpty(stack)) {\n DOMNativeNode.Utils.replaceChildren(element, children, (x) => !!force || this._tracked_elements.has(x as any));\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 ${type}`);\n switch (type) {\n case 'head': {\n this._tracked_head_children.push(...children);\n return;\n }\n default: break;\n }\n\n if (ref) mergeRefs(ref)(element);\n\n const tracked = this._tracked_elements.get(element);\n const removed = tracked ? _.difference(tracked.props, _.keys(_props)) : [];\n if (tracked) tracked.props = _.keys(_props);\n\n const builtClassName = this.__createBuiltClassName(element, className, style);\n if (_.isNil(innerHTML)) {\n DOMNativeNode.Utils.replaceChildren(element, children, (x) => !!force || this._tracked_elements.has(x as any));\n } else if (element.innerHTML !== innerHTML) {\n element.innerHTML = innerHTML;\n }\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 _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 if (elements.length !== 1) return str;\n return elements[0].tagName.toLowerCase() === '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,2BAAA,OAAA,GAAA,aAAA;AACA;AACA;;ACdO,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;;;;"}
|
|
@@ -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-CtvkpyUB.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer--F4YB5QP.d.ts","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-CtvkpyUB.d.ts","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;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
|
-
var renderer = require('./renderer-
|
|
4
|
+
var renderer = require('./renderer-Dv-IAwBn.js');
|
|
5
5
|
var postcss = require('postcss');
|
|
6
6
|
var postcssJs = require('postcss-js');
|
|
7
7
|
var nested = require('postcss-nested');
|
|
@@ -4283,11 +4283,10 @@ class _DOMRenderer extends renderer._Renderer {
|
|
|
4283
4283
|
props: [],
|
|
4284
4284
|
className: [],
|
|
4285
4285
|
});
|
|
4286
|
-
this._updateElement(node, elem, stack);
|
|
4287
4286
|
return elem;
|
|
4288
4287
|
}
|
|
4289
4288
|
if (!_.isString(type))
|
|
4290
|
-
throw Error(
|
|
4289
|
+
throw Error(`Invalid type ${type}`);
|
|
4291
4290
|
switch (type) {
|
|
4292
4291
|
case 'html': return this.document.documentElement;
|
|
4293
4292
|
case 'head': return this.document.head ?? this.document.createElementNS(HTML_NS, 'head');
|
|
@@ -4306,7 +4305,6 @@ class _DOMRenderer extends renderer._Renderer {
|
|
|
4306
4305
|
props: [],
|
|
4307
4306
|
className: [],
|
|
4308
4307
|
});
|
|
4309
|
-
this._updateElement(node, elem, stack);
|
|
4310
4308
|
return elem;
|
|
4311
4309
|
}
|
|
4312
4310
|
__createBuiltClassName(element, className, style) {
|
|
@@ -4318,7 +4316,7 @@ class _DOMRenderer extends renderer._Renderer {
|
|
|
4318
4316
|
return [..._className, ...built].join(' ');
|
|
4319
4317
|
}
|
|
4320
4318
|
/** @internal */
|
|
4321
|
-
_updateElement(node, element, stack) {
|
|
4319
|
+
_updateElement(node, element, children, stack, force) {
|
|
4322
4320
|
if (element instanceof DOMNativeNode) {
|
|
4323
4321
|
const { props: { ref, className, style, inlineStyle, ..._props } } = node;
|
|
4324
4322
|
if (ref)
|
|
@@ -4329,27 +4327,35 @@ class _DOMRenderer extends renderer._Renderer {
|
|
|
4329
4327
|
className: builtClassName ? builtClassName : undefined,
|
|
4330
4328
|
style: css ? css : undefined,
|
|
4331
4329
|
..._props
|
|
4332
|
-
});
|
|
4330
|
+
}, children);
|
|
4331
|
+
return;
|
|
4332
|
+
}
|
|
4333
|
+
if (_.isEmpty(stack)) {
|
|
4334
|
+
DOMNativeNode.Utils.replaceChildren(element, children, (x) => !!force || this._tracked_elements.has(x));
|
|
4333
4335
|
return;
|
|
4334
4336
|
}
|
|
4335
4337
|
const { type, props: { ref, className, style, inlineStyle, innerHTML, ..._props } } = node;
|
|
4336
4338
|
if (!_.isString(type))
|
|
4337
|
-
throw Error(
|
|
4339
|
+
throw Error(`Invalid type ${type}`);
|
|
4338
4340
|
switch (type) {
|
|
4339
|
-
case '
|
|
4340
|
-
|
|
4341
|
-
|
|
4341
|
+
case 'head': {
|
|
4342
|
+
this._tracked_head_children.push(...children);
|
|
4343
|
+
return;
|
|
4344
|
+
}
|
|
4342
4345
|
}
|
|
4343
4346
|
if (ref)
|
|
4344
4347
|
state.mergeRefs(ref)(element);
|
|
4345
4348
|
const tracked = this._tracked_elements.get(element);
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
tracked.props = _.keys(_props);
|
|
4349
|
+
const removed = tracked ? _.difference(tracked.props, _.keys(_props)) : [];
|
|
4350
|
+
if (tracked)
|
|
4351
|
+
tracked.props = _.keys(_props);
|
|
4350
4352
|
const builtClassName = this.__createBuiltClassName(element, className, style);
|
|
4351
|
-
if (
|
|
4353
|
+
if (_.isNil(innerHTML)) {
|
|
4354
|
+
DOMNativeNode.Utils.replaceChildren(element, children, (x) => !!force || this._tracked_elements.has(x));
|
|
4355
|
+
}
|
|
4356
|
+
else if (element.innerHTML !== innerHTML) {
|
|
4352
4357
|
element.innerHTML = innerHTML;
|
|
4358
|
+
}
|
|
4353
4359
|
DOMNativeNode.Utils.update(element, {
|
|
4354
4360
|
className: builtClassName,
|
|
4355
4361
|
style: inlineStyle ? processCss(inlineStyle).css : undefined,
|
|
@@ -4358,21 +4364,6 @@ class _DOMRenderer extends renderer._Renderer {
|
|
|
4358
4364
|
});
|
|
4359
4365
|
}
|
|
4360
4366
|
/** @internal */
|
|
4361
|
-
_replaceChildren(node, element, children, stack, force) {
|
|
4362
|
-
if (element instanceof DOMNativeNode) {
|
|
4363
|
-
element.replaceChildren(children);
|
|
4364
|
-
}
|
|
4365
|
-
else {
|
|
4366
|
-
const { type, props: { innerHTML } } = node;
|
|
4367
|
-
if (type === 'head') {
|
|
4368
|
-
this._tracked_head_children.push(...children);
|
|
4369
|
-
}
|
|
4370
|
-
else if (_.isEmpty(innerHTML)) {
|
|
4371
|
-
DOMNativeNode.Utils.replaceChildren(element, children, (x) => !!force || this._tracked_elements.has(x));
|
|
4372
|
-
}
|
|
4373
|
-
}
|
|
4374
|
-
}
|
|
4375
|
-
/** @internal */
|
|
4376
4367
|
_destroyElement(node, element) {
|
|
4377
4368
|
if (element instanceof DOMNativeNode) {
|
|
4378
4369
|
element.destroy();
|
|
@@ -4387,7 +4378,9 @@ class _DOMRenderer extends renderer._Renderer {
|
|
|
4387
4378
|
await root.mount(component, { skipMount: true });
|
|
4388
4379
|
const elements = _.flatMap(_.castArray(root.root ?? []), x => x instanceof DOMNativeNode ? x.target : x);
|
|
4389
4380
|
const str = _.map(elements, x => x.outerHTML).join('');
|
|
4390
|
-
|
|
4381
|
+
if (elements.length !== 1)
|
|
4382
|
+
return str;
|
|
4383
|
+
return elements[0].tagName.toLowerCase() === 'html' ? `<!DOCTYPE html>${str}` : str;
|
|
4391
4384
|
}
|
|
4392
4385
|
finally {
|
|
4393
4386
|
root.unmount();
|
|
@@ -4397,4 +4390,4 @@ class _DOMRenderer extends renderer._Renderer {
|
|
|
4397
4390
|
|
|
4398
4391
|
exports.DOMNativeNode = DOMNativeNode;
|
|
4399
4392
|
exports._DOMRenderer = _DOMRenderer;
|
|
4400
|
-
//# sourceMappingURL=renderer-
|
|
4393
|
+
//# sourceMappingURL=renderer-DINmR7Fc.js.map
|