frosty 0.0.67 → 0.0.68
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/README.md +50 -0
- package/dist/_native.d.ts +3 -3
- package/dist/_native.mjs +2 -2
- package/dist/dom.d.ts +3 -3
- package/dist/dom.mjs +3 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/internals/{common-jmXMOod4.d.ts → common-B0Nya-9e.d.ts} +3 -3
- package/dist/internals/{common-jmXMOod4.d.ts.map → common-B0Nya-9e.d.ts.map} +1 -1
- package/dist/internals/{common-uTufm_t7.mjs → common-Ca5Ux3vo.mjs} +3 -3
- package/dist/internals/{common-uTufm_t7.mjs.map → common-Ca5Ux3vo.mjs.map} +1 -1
- package/dist/internals/{common-C5xm7xDw.d.ts → common-lfYTb1eV.d.ts} +3 -3
- package/dist/internals/{common-C5xm7xDw.d.ts.map → common-lfYTb1eV.d.ts.map} +1 -1
- package/dist/internals/{fragment-BQXp1_iv.d.ts → fragment-CApRh6Hp.d.ts} +2 -2
- package/dist/internals/{fragment-BQXp1_iv.d.ts.map → fragment-CApRh6Hp.d.ts.map} +1 -1
- package/dist/internals/{renderer-DgKjFDB-.mjs → renderer-CEj3F2CM.mjs} +2 -2
- package/dist/internals/{renderer-DgKjFDB-.mjs.map → renderer-CEj3F2CM.mjs.map} +1 -1
- package/dist/internals/{renderer-D4aiCZGU.d.ts → renderer-DBPR_8BN.d.ts} +2 -2
- package/dist/internals/{renderer-D4aiCZGU.d.ts.map → renderer-DBPR_8BN.d.ts.map} +1 -1
- package/dist/internals/{state-j1YggBhW.mjs → state-C4Wldkq7.mjs} +2 -2
- package/dist/internals/{state-j1YggBhW.mjs.map → state-C4Wldkq7.mjs.map} +1 -1
- package/dist/internals/{sync-D_pTd9lu.mjs → sync-Ciycjqeo.mjs} +3 -3
- package/dist/internals/{sync-D_pTd9lu.mjs.map → sync-Ciycjqeo.mjs.map} +1 -1
- package/dist/internals/{utils-B_4b5vas.d.ts → utils-CyrF9IfR.d.ts} +2 -2
- package/dist/internals/{utils-B_4b5vas.d.ts.map → utils-CyrF9IfR.d.ts.map} +1 -1
- package/dist/jsx-dev-runtime.d.ts +7 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +14 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-dev-runtime.mjs +4 -0
- package/dist/jsx-dev-runtime.mjs.map +1 -0
- package/dist/jsx-runtime.d.ts +2 -2
- package/dist/jsx-runtime.d.ts.map +1 -1
- package/dist/jsx-runtime.js +1 -1
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/jsx-runtime.mjs +1 -1
- package/dist/jsx-runtime.mjs.map +1 -1
- package/dist/server-dom.d.ts +3 -3
- package/dist/server-dom.mjs +3 -3
- package/dist/web.d.ts +3 -3
- package/dist/web.mjs +5 -5
- package/package.json +3 -2
- package/packages/frosty-cli/package.json +0 -1
- package/packages/frosty-cli/scripts/bin/run.sh +81 -42
- package/packages/frosty-cli/src/server/env.js +26 -0
- package/packages/frosty-cli/src/server/index.js +7 -11
- package/packages/frosty-cli/src/server/render.js +9 -10
- package/packages/frosty-cli/src/server/route.ts +1 -7
- package/packages/frosty-cli/{webpack.js → webpack.mjs} +90 -48
package/README.md
CHANGED
|
@@ -38,6 +38,56 @@ function App() {
|
|
|
38
38
|
|
|
39
39
|
See the [API documentation](./docs) for more details and advanced usage.
|
|
40
40
|
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
To run your app with Frosty CLI using `npx`:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npx frosty run app.js
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Common Options
|
|
50
|
+
|
|
51
|
+
- `-w, --watch` Enable watch mode (rebuild on file changes)
|
|
52
|
+
- `-d, --debug` Enable debug mode (development build)
|
|
53
|
+
- `-p, --port <port>` Specify server port (default: 8080)
|
|
54
|
+
- `-c, --configuration <file>` Use a custom config file (default: server.config.js)
|
|
55
|
+
- `-s, --src <dir>` Specify source directory
|
|
56
|
+
- `-o, --output <dir>` Specify output directory
|
|
57
|
+
|
|
58
|
+
### Example Commands
|
|
59
|
+
|
|
60
|
+
Start your app in development mode with watch:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
npx frosty run --watch --debug app.js
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Run with a custom port and config:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
npx frosty run --port 3000 --configuration my.config.js app.js
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
See `npx frosty run --help` for the full list of options.
|
|
73
|
+
|
|
74
|
+
### Configuration File
|
|
75
|
+
|
|
76
|
+
You can customize the build and server behavior by providing a `server.config.js` file in your project root. This file can export an object or a function that returns configuration options for Frosty’s CLI and build process. Common settings include specifying source/output directories, custom plugins, module rules, and server options.
|
|
77
|
+
|
|
78
|
+
Example `server.config.js`:
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
module.exports = {
|
|
82
|
+
src: 'src',
|
|
83
|
+
output: 'dist',
|
|
84
|
+
serverEntry: 'server.js',
|
|
85
|
+
options: {
|
|
86
|
+
// custom webpack or build options
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
```
|
|
90
|
+
|
|
41
91
|
## TypeScript Setup
|
|
42
92
|
|
|
43
93
|
To enable JSX support with Frosty in TypeScript, update your `tsconfig.json`:
|
package/dist/_native.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { N as NativeElementType,
|
|
2
|
-
export { V as VNode, _ as _Renderer } from './internals/renderer-
|
|
3
|
-
export { u as uniqueId } from './internals/utils-
|
|
1
|
+
import { N as NativeElementType, b as PropsType, a as ComponentNode } from './internals/common-lfYTb1eV.js';
|
|
2
|
+
export { V as VNode, _ as _Renderer } from './internals/renderer-DBPR_8BN.js';
|
|
3
|
+
export { u as uniqueId } from './internals/utils-CyrF9IfR.js';
|
|
4
4
|
import '@o2ter/utils-js';
|
|
5
5
|
import 'lodash';
|
|
6
6
|
import 'csstype';
|
package/dist/_native.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as _createElement } from './internals/runtime-DK28Kyy2.mjs';
|
|
2
|
-
export { _ as _Renderer } from './internals/renderer-
|
|
3
|
-
export {
|
|
2
|
+
export { _ as _Renderer } from './internals/renderer-CEj3F2CM.mjs';
|
|
3
|
+
export { E as EventEmitter, V as VNode, u as uniqueId } from './internals/state-C4Wldkq7.mjs';
|
|
4
4
|
export { N as NativeElementType } from './internals/component-BzurKp_J.mjs';
|
|
5
5
|
import 'lodash';
|
|
6
6
|
import 'nextick';
|
package/dist/dom.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { _ as _DOMRenderer } from './internals/common-
|
|
2
|
-
import './internals/common-
|
|
1
|
+
import { _ as _DOMRenderer } from './internals/common-B0Nya-9e.js';
|
|
2
|
+
import './internals/common-lfYTb1eV.js';
|
|
3
3
|
import '@o2ter/utils-js';
|
|
4
4
|
import 'lodash';
|
|
5
5
|
import 'csstype';
|
|
6
|
-
import './internals/renderer-
|
|
6
|
+
import './internals/renderer-DBPR_8BN.js';
|
|
7
7
|
import 'jsdom';
|
|
8
8
|
|
|
9
9
|
declare class DOMRenderer extends _DOMRenderer {
|
package/dist/dom.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { _ as _DOMRenderer } from './internals/common-
|
|
1
|
+
import { _ as _DOMRenderer } from './internals/common-Ca5Ux3vo.mjs';
|
|
2
2
|
import 'lodash';
|
|
3
3
|
import 'myers.js';
|
|
4
4
|
import './internals/component-BzurKp_J.mjs';
|
|
5
|
-
import './internals/renderer-
|
|
6
|
-
import './internals/state-
|
|
5
|
+
import './internals/renderer-CEj3F2CM.mjs';
|
|
6
|
+
import './internals/state-C4Wldkq7.mjs';
|
|
7
7
|
import 'nextick';
|
|
8
8
|
import 'postcss';
|
|
9
9
|
import 'postcss-js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { S as SetStateAction, C as ComponentType, P as PropsWithChildren, E as ElementNode,
|
|
2
|
-
export { h as CSSProperties, e as ClassName, j as ComponentProps, k as ComponentPropsWithoutRef, m as ComponentRef, g as ExtendedCSSProperties, i as RefAttribute, l as RefCallback, f as StyleProp, d as createElement } from './internals/common-
|
|
1
|
+
import { S as SetStateAction, C as ComponentType, P as PropsWithChildren, E as ElementNode, c as RefObject, R as Ref, a as ComponentNode, _ as _ElementType, N as NativeElementType, b as PropsType } from './internals/common-lfYTb1eV.js';
|
|
2
|
+
export { h as CSSProperties, e as ClassName, j as ComponentProps, k as ComponentPropsWithoutRef, m as ComponentRef, g as ExtendedCSSProperties, i as RefAttribute, l as RefCallback, f as StyleProp, d as createElement } from './internals/common-lfYTb1eV.js';
|
|
3
3
|
import _ from 'lodash';
|
|
4
4
|
import { Awaitable } from '@o2ter/utils-js';
|
|
5
|
-
export { F as Fragment } from './internals/fragment-
|
|
6
|
-
export { m as mergeRefs } from './internals/utils-
|
|
5
|
+
export { F as Fragment } from './internals/fragment-CApRh6Hp.js';
|
|
6
|
+
export { m as mergeRefs } from './internals/utils-CyrF9IfR.js';
|
|
7
7
|
import 'csstype';
|
|
8
8
|
|
|
9
9
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import { _ as _useEffect,
|
|
2
|
+
import { _ as _useEffect, d as _useMemo, b as useCallback, a as useMemo, c as useEffect, u as useSyncExternalStore } from './internals/sync-Ciycjqeo.mjs';
|
|
3
3
|
import { jsx } from './jsx-runtime.mjs';
|
|
4
4
|
export { Fragment } from './jsx-runtime.mjs';
|
|
5
|
-
import { r as reconciler, c as createContext,
|
|
6
|
-
export {
|
|
5
|
+
import { r as reconciler, c as createContext, a as useContext, u as uniqueId } from './internals/state-C4Wldkq7.mjs';
|
|
6
|
+
export { b as ErrorBoundary, P as PropsProvider, m as mergeRefs } from './internals/state-C4Wldkq7.mjs';
|
|
7
7
|
export { C as ComponentNode } from './internals/component-BzurKp_J.mjs';
|
|
8
8
|
export { c as createElement } from './internals/runtime-DK28Kyy2.mjs';
|
|
9
9
|
import 'myers.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as NativeElementType,
|
|
2
|
-
import { _ as _Renderer } from './renderer-
|
|
1
|
+
import { N as NativeElementType, a as ComponentNode } from './common-lfYTb1eV.js';
|
|
2
|
+
import { _ as _Renderer } from './renderer-DBPR_8BN.js';
|
|
3
3
|
import { DOMWindow } from 'jsdom';
|
|
4
4
|
|
|
5
5
|
declare abstract class DOMNativeNode extends NativeElementType {
|
|
@@ -28,4 +28,4 @@ declare abstract class _DOMRenderer extends _Renderer<Element | DOMNativeNode> {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export { DOMNativeNode as D, _DOMRenderer as _ };
|
|
31
|
-
//# sourceMappingURL=common-
|
|
31
|
+
//# sourceMappingURL=common-B0Nya-9e.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-jmXMOod4.d.ts","sources":["../../src/renderer/common.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 { VNode } from '../core/reconciler/vnode';\nimport { myersSync } from 'myers.js';\nimport { globalEvents } from '../core/web/event';\nimport { ComponentNode, NativeElementType } from '../core/types/component';\nimport { svgProps, htmlProps, 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';\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\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\nexport abstract class DOMNativeNode extends NativeElementType {\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\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 private _tracked_elements = new Map<Element | DOMNativeNode, { props: string[]; className: string[]; listener: Record<string, EventListener | undefined>; }>();\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 }\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 if (this._tracked_style.isEmpty) {\n if (this._server) {\n this.__replaceChildren(head, this._tracked_head_children);\n }\n } else {\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 this.__replaceChildren(head, [...this._tracked_head_children, styleElem]);\n } else if (styleElem.parentNode !== head) {\n head.appendChild(styleElem);\n }\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 listener: {},\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 listener: {},\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 private __updateEventListener(\n element: Element,\n key: string,\n listener: EventListener | undefined,\n options?: AddEventListenerOptions,\n ) {\n const event = key.endsWith('Capture') ? key.slice(2, -7).toLowerCase() : key.slice(2).toLowerCase();\n const tracked_listener = this._tracked_elements.get(element)?.listener;\n if (!tracked_listener) return;\n if (tracked_listener[key] !== listener) {\n if (_.isFunction(tracked_listener[key])) element.removeEventListener(event, tracked_listener[key], options);\n if (_.isFunction(listener)) element.addEventListener(event, listener, options);\n }\n tracked_listener[key] = listener;\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 builtClassName = this.__createBuiltClassName(element, className, style);\n if (_.isEmpty(builtClassName)) {\n if (!_.isNil(element.getAttribute('class')))\n element.removeAttribute('class');\n } else if (element.className !== builtClassName) {\n element.className = builtClassName;\n }\n if (!_.isEmpty(innerHTML) && element.innerHTML !== innerHTML) element.innerHTML = innerHTML;\n\n if (inlineStyle) {\n const { css } = processCss(inlineStyle);\n const oldValue = element.getAttribute('style');\n const newValue = css.split('\\n').join('');\n if (oldValue !== newValue)\n element.setAttribute('style', newValue);\n } else if (!_.isNil(element.getAttribute('style'))) {\n element.removeAttribute('style');\n }\n\n const tracked = this._tracked_elements.get(element);\n if (!tracked) return;\n const removed = _.difference(tracked.props, _.keys(_props));\n const props = {\n ..._props,\n ..._.fromPairs(_.map(removed, x => [x, undefined])),\n };\n tracked.props = _.keys(_props);\n\n for (const [key, value] of _.entries(props)) {\n if (_.includes(globalEvents, key)) {\n this.__updateEventListener(element, key, value, { capture: false });\n } else if (key.endsWith('Capture') && _.includes(globalEvents, key.slice(0, -7))) {\n this.__updateEventListener(element, key, value, { capture: true });\n } else if (isWriteable(element, key)) {\n if ((element as any)[key] !== value)\n (element as any)[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 { type: _type, attr } = (htmlProps as any)['*'][key]\n ?? (htmlProps as any)[type]?.[key]\n ?? (svgProps as any)['*'][key]\n ?? (svgProps as any)[type]?.[key]\n ?? {};\n if (_type && attr && (_propValue as any)[_type]) {\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 }\n }\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 this.__replaceChildren(element, children, force);\n }\n }\n }\n\n /** @internal */\n _destroyElement(node: VNode, element: Element | DOMNativeNode) {\n if (element instanceof DOMNativeNode) {\n element.destroy();\n } else {\n const tracked_listener = this._tracked_elements.get(element)?.listener;\n for (const [key, listener] of _.entries(tracked_listener)) {\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 }\n this._tracked_elements.delete(element);\n }\n\n __replaceChildren(element: Element, children: (string | Element | DOMNativeNode)[], force?: boolean) {\n const diff = myersSync(\n _.map(element.childNodes, x => x.nodeType === this.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 (force || _.isString(child) || this._tracked_elements.has(child as any)) {\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) ? this.document.createTextNode(child) : child;\n element.insertBefore(node, element.childNodes[i++]);\n }\n }\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":";;;;AAGO,uBAAA,aAAA,SAAA,iBAAA;AACP,gCAAA,QAAA,YAAA,YAAA,KAAA,aAAA;AACA,2BAAA,OAAA,GAAA,OAAA;AACA,2BAAA,MAAA;AACA;AACA;AACA;AACA,iDAAA,OAAA,GAAA,aAAA;AACA;AACA;AACO,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;AACA,+BAAA,OAAA,sBAAA,OAAA,GAAA,aAAA;AACA,8BAAA,aAAA,GAAA,OAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"common-B0Nya-9e.d.ts","sources":["../../src/renderer/common.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 { VNode } from '../core/reconciler/vnode';\nimport { myersSync } from 'myers.js';\nimport { globalEvents } from '../core/web/event';\nimport { ComponentNode, NativeElementType } from '../core/types/component';\nimport { svgProps, htmlProps, 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';\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\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\nexport abstract class DOMNativeNode extends NativeElementType {\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\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 private _tracked_elements = new Map<Element | DOMNativeNode, { props: string[]; className: string[]; listener: Record<string, EventListener | undefined>; }>();\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 }\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 if (this._tracked_style.isEmpty) {\n if (this._server) {\n this.__replaceChildren(head, this._tracked_head_children);\n }\n } else {\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 this.__replaceChildren(head, [...this._tracked_head_children, styleElem]);\n } else if (styleElem.parentNode !== head) {\n head.appendChild(styleElem);\n }\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 listener: {},\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 listener: {},\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 private __updateEventListener(\n element: Element,\n key: string,\n listener: EventListener | undefined,\n options?: AddEventListenerOptions,\n ) {\n const event = key.endsWith('Capture') ? key.slice(2, -7).toLowerCase() : key.slice(2).toLowerCase();\n const tracked_listener = this._tracked_elements.get(element)?.listener;\n if (!tracked_listener) return;\n if (tracked_listener[key] !== listener) {\n if (_.isFunction(tracked_listener[key])) element.removeEventListener(event, tracked_listener[key], options);\n if (_.isFunction(listener)) element.addEventListener(event, listener, options);\n }\n tracked_listener[key] = listener;\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 builtClassName = this.__createBuiltClassName(element, className, style);\n if (_.isEmpty(builtClassName)) {\n if (!_.isNil(element.getAttribute('class')))\n element.removeAttribute('class');\n } else if (element.className !== builtClassName) {\n element.className = builtClassName;\n }\n if (!_.isEmpty(innerHTML) && element.innerHTML !== innerHTML) element.innerHTML = innerHTML;\n\n if (inlineStyle) {\n const { css } = processCss(inlineStyle);\n const oldValue = element.getAttribute('style');\n const newValue = css.split('\\n').join('');\n if (oldValue !== newValue)\n element.setAttribute('style', newValue);\n } else if (!_.isNil(element.getAttribute('style'))) {\n element.removeAttribute('style');\n }\n\n const tracked = this._tracked_elements.get(element);\n if (!tracked) return;\n const removed = _.difference(tracked.props, _.keys(_props));\n const props = {\n ..._props,\n ..._.fromPairs(_.map(removed, x => [x, undefined])),\n };\n tracked.props = _.keys(_props);\n\n for (const [key, value] of _.entries(props)) {\n if (_.includes(globalEvents, key)) {\n this.__updateEventListener(element, key, value, { capture: false });\n } else if (key.endsWith('Capture') && _.includes(globalEvents, key.slice(0, -7))) {\n this.__updateEventListener(element, key, value, { capture: true });\n } else if (isWriteable(element, key)) {\n if ((element as any)[key] !== value)\n (element as any)[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 { type: _type, attr } = (htmlProps as any)['*'][key]\n ?? (htmlProps as any)[type]?.[key]\n ?? (svgProps as any)['*'][key]\n ?? (svgProps as any)[type]?.[key]\n ?? {};\n if (_type && attr && (_propValue as any)[_type]) {\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 }\n }\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 this.__replaceChildren(element, children, force);\n }\n }\n }\n\n /** @internal */\n _destroyElement(node: VNode, element: Element | DOMNativeNode) {\n if (element instanceof DOMNativeNode) {\n element.destroy();\n } else {\n const tracked_listener = this._tracked_elements.get(element)?.listener;\n for (const [key, listener] of _.entries(tracked_listener)) {\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 }\n this._tracked_elements.delete(element);\n }\n\n __replaceChildren(element: Element, children: (string | Element | DOMNativeNode)[], force?: boolean) {\n const diff = myersSync(\n _.map(element.childNodes, x => x.nodeType === this.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 (force || _.isString(child) || this._tracked_elements.has(child as any)) {\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) ? this.document.createTextNode(child) : child;\n element.insertBefore(node, element.childNodes[i++]);\n }\n }\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":";;;;AAGO,uBAAA,aAAA,SAAA,iBAAA;AACP,gCAAA,QAAA,YAAA,YAAA,KAAA,aAAA;AACA,2BAAA,OAAA,GAAA,OAAA;AACA,2BAAA,MAAA;AACA;AACA;AACA;AACA,iDAAA,OAAA,GAAA,aAAA;AACA;AACA;AACO,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;AACA,+BAAA,OAAA,sBAAA,OAAA,GAAA,aAAA;AACA,8BAAA,aAAA,GAAA,OAAA;AACA;;;;"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { myersSync } from 'myers.js';
|
|
3
3
|
import { N as NativeElementType } from './component-BzurKp_J.mjs';
|
|
4
|
-
import { _ as _Renderer } from './renderer-
|
|
4
|
+
import { _ as _Renderer } from './renderer-CEj3F2CM.mjs';
|
|
5
5
|
import postcss from 'postcss';
|
|
6
6
|
import { parse } from 'postcss-js';
|
|
7
7
|
import nested from 'postcss-nested';
|
|
8
8
|
import autoprefixer from 'autoprefixer';
|
|
9
|
-
import {
|
|
9
|
+
import { u as uniqueId, m as mergeRefs } from './state-C4Wldkq7.mjs';
|
|
10
10
|
|
|
11
11
|
//
|
|
12
12
|
// event.ts
|
|
@@ -4165,4 +4165,4 @@ class _DOMRenderer extends _Renderer {
|
|
|
4165
4165
|
}
|
|
4166
4166
|
|
|
4167
4167
|
export { DOMNativeNode as D, _DOMRenderer as _ };
|
|
4168
|
-
//# sourceMappingURL=common-
|
|
4168
|
+
//# sourceMappingURL=common-Ca5Ux3vo.mjs.map
|