onejs-core 0.3.5
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/.gitattributes +2 -0
- package/.github/workflows/jsr.yml +19 -0
- package/.prettierrc +5 -0
- package/3rdparty/preact/LICENSE +21 -0
- package/3rdparty/preact/clone-element.ts +45 -0
- package/3rdparty/preact/compat/Children.ts +21 -0
- package/3rdparty/preact/compat/forwardRef.ts +49 -0
- package/3rdparty/preact/compat/index.ts +3 -0
- package/3rdparty/preact/compat/memo.ts +34 -0
- package/3rdparty/preact/compat/util.ts +38 -0
- package/3rdparty/preact/component.ts +235 -0
- package/3rdparty/preact/constants.ts +3 -0
- package/3rdparty/preact/create-context.ts +71 -0
- package/3rdparty/preact/create-element.ts +98 -0
- package/3rdparty/preact/diff/catch-error.ts +40 -0
- package/3rdparty/preact/diff/children.ts +355 -0
- package/3rdparty/preact/diff/index.ts +563 -0
- package/3rdparty/preact/diff/props.ts +174 -0
- package/3rdparty/preact/hooks/index.ts +536 -0
- package/3rdparty/preact/hooks/internal.d.ts +85 -0
- package/3rdparty/preact/hooks.d.ts +145 -0
- package/3rdparty/preact/index.ts +13 -0
- package/3rdparty/preact/internal.d.ts +155 -0
- package/3rdparty/preact/jsx-runtime/index.ts +80 -0
- package/3rdparty/preact/jsx.d.ts +1008 -0
- package/3rdparty/preact/options.ts +16 -0
- package/3rdparty/preact/preact.d.ts +317 -0
- package/3rdparty/preact/render.ts +76 -0
- package/3rdparty/preact/signals/index.ts +443 -0
- package/3rdparty/preact/signals/internal.d.ts +36 -0
- package/3rdparty/preact/signals-core/index.ts +663 -0
- package/3rdparty/preact/style.d.ts +205 -0
- package/3rdparty/preact/util.ts +29 -0
- package/@DO_NOT_CHANGE.txt +3 -0
- package/README.md +33 -0
- package/definitions/app.d.ts +52048 -0
- package/definitions/augments.d.ts +16 -0
- package/definitions/globals.d.ts +34 -0
- package/definitions/index.d.ts +9 -0
- package/definitions/jsx.d.ts +517 -0
- package/definitions/modules.d.ts +29 -0
- package/definitions/onejs.d.ts +164 -0
- package/definitions/preact.jsx.d.ts +7 -0
- package/definitions/proto-overrides.d.ts +13 -0
- package/definitions/puerts.d.ts +31 -0
- package/definitions/unity-engine.d.ts +23 -0
- package/hooks/eventful.ts +56 -0
- package/import-transform.mjs +42 -0
- package/index.ts +44 -0
- package/jsr.json +10 -0
- package/onejs-tw-config.cjs +188 -0
- package/package.json +9 -0
- package/preloads/inject.ts +44 -0
- package/styling/index.tsx +80 -0
- package/styling/utils/generateAlphabeticName.ts +21 -0
- package/styling/utils/generateComponentId.ts +6 -0
- package/styling/utils/hash.ts +46 -0
- package/switch.cjs +185 -0
- package/uss-transform-plugin.cjs +83 -0
- package/utils/color-palettes.ts +3 -0
- package/utils/color-parser.ts +249 -0
- package/utils/float-parser.ts +31 -0
- package/utils/index.ts +12 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the closest error boundary to a thrown error and call it
|
|
3
|
+
* @param {object} error The thrown value
|
|
4
|
+
* @param {import('../internal').VNode} vnode The vnode that threw
|
|
5
|
+
* the error that was caught (except for unmounting when this parameter
|
|
6
|
+
* is the highest parent that was being unmounted)
|
|
7
|
+
* @param {import('../internal').VNode} [oldVNode]
|
|
8
|
+
* @param {import('../internal').ErrorInfo} [errorInfo]
|
|
9
|
+
*/
|
|
10
|
+
export function _catchError(error, vnode, oldVNode, errorInfo) {
|
|
11
|
+
/** @type {import('../internal').Component} */
|
|
12
|
+
let component, ctor, handled;
|
|
13
|
+
|
|
14
|
+
for (; (vnode = vnode._parent); ) {
|
|
15
|
+
if ((component = vnode._component) && !component._processingException) {
|
|
16
|
+
try {
|
|
17
|
+
ctor = component.constructor;
|
|
18
|
+
|
|
19
|
+
if (ctor && ctor.getDerivedStateFromError != null) {
|
|
20
|
+
component.setState(ctor.getDerivedStateFromError(error));
|
|
21
|
+
handled = component._dirty;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (component.componentDidCatch != null) {
|
|
25
|
+
component.componentDidCatch(error, errorInfo || {});
|
|
26
|
+
handled = component._dirty;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// This is an error boundary. Mark it as having bailed out, and whether it was mid-hydration.
|
|
30
|
+
if (handled) {
|
|
31
|
+
return (component._pendingError = component);
|
|
32
|
+
}
|
|
33
|
+
} catch (e) {
|
|
34
|
+
error = e;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { diff, unmount, applyRef } from './index';
|
|
2
|
+
import { createVNode, Fragment } from '../create-element';
|
|
3
|
+
import { EMPTY_OBJ, EMPTY_ARR } from '../constants';
|
|
4
|
+
import { getDomSibling } from '../component';
|
|
5
|
+
import { isArray } from '../util';
|
|
6
|
+
import { VNode } from '../internal';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Diff the children of a virtual node
|
|
10
|
+
* @param {import('../internal').PreactElement} parentDom The DOM element whose
|
|
11
|
+
* children are being diffed
|
|
12
|
+
* @param {import('../internal').ComponentChildren[]} renderResult
|
|
13
|
+
* @param {import('../internal').VNode} newParentVNode The new virtual
|
|
14
|
+
* node whose children should be diff'ed against oldParentVNode
|
|
15
|
+
* @param {import('../internal').VNode} oldParentVNode The old virtual
|
|
16
|
+
* node whose children should be diff'ed against newParentVNode
|
|
17
|
+
* @param {object} globalContext The current context object - modified by getChildContext
|
|
18
|
+
* @param {boolean} isSvg Whether or not this DOM node is an SVG node
|
|
19
|
+
* @param {Array<import('../internal').PreactElement>} excessDomChildren
|
|
20
|
+
* @param {Array<import('../internal').Component>} commitQueue List of components
|
|
21
|
+
* which have callbacks to invoke in commitRoot
|
|
22
|
+
* @param {import('../internal').PreactElement} oldDom The current attached DOM
|
|
23
|
+
* element any new dom elements should be placed around. Likely `null` on first
|
|
24
|
+
* render (except when hydrating). Can be a sibling DOM element when diffing
|
|
25
|
+
* Fragments that have siblings. In most cases, it starts out as `oldChildren[0]._dom`.
|
|
26
|
+
* @param {boolean} isHydrating Whether or not we are in hydration
|
|
27
|
+
*/
|
|
28
|
+
export function diffChildren(
|
|
29
|
+
parentDom,
|
|
30
|
+
renderResult,
|
|
31
|
+
newParentVNode,
|
|
32
|
+
oldParentVNode,
|
|
33
|
+
globalContext,
|
|
34
|
+
isSvg,
|
|
35
|
+
excessDomChildren,
|
|
36
|
+
commitQueue,
|
|
37
|
+
oldDom,
|
|
38
|
+
isHydrating
|
|
39
|
+
) {
|
|
40
|
+
let i, j, oldVNode, childVNode, newDom, firstChildDom, refs;
|
|
41
|
+
|
|
42
|
+
// This is a compression of oldParentVNode!=null && oldParentVNode != EMPTY_OBJ && oldParentVNode._children || EMPTY_ARR
|
|
43
|
+
// as EMPTY_OBJ._children should be `undefined`.
|
|
44
|
+
let oldChildren = (oldParentVNode && oldParentVNode._children) || EMPTY_ARR;
|
|
45
|
+
|
|
46
|
+
let oldChildrenLength = oldChildren.length;
|
|
47
|
+
|
|
48
|
+
newParentVNode._children = [];
|
|
49
|
+
for (i = 0; i < renderResult.length; i++) {
|
|
50
|
+
childVNode = renderResult[i];
|
|
51
|
+
|
|
52
|
+
if (childVNode === null || typeof childVNode === 'boolean' || typeof childVNode === 'function') { // MODDED
|
|
53
|
+
childVNode = newParentVNode._children[i] = null;
|
|
54
|
+
}
|
|
55
|
+
// If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
|
|
56
|
+
// or we are rendering a component (e.g. setState) copy the oldVNodes so it can have
|
|
57
|
+
// it's own DOM & etc. pointers
|
|
58
|
+
else if (
|
|
59
|
+
typeof childVNode === 'string' ||
|
|
60
|
+
typeof childVNode === 'number' ||
|
|
61
|
+
// eslint-disable-next-line valid-typeof
|
|
62
|
+
typeof childVNode === 'bigint'
|
|
63
|
+
) {
|
|
64
|
+
childVNode = newParentVNode._children[i] = createVNode(
|
|
65
|
+
null,
|
|
66
|
+
childVNode,
|
|
67
|
+
null,
|
|
68
|
+
null,
|
|
69
|
+
childVNode
|
|
70
|
+
);
|
|
71
|
+
} else if (Array.isArray(childVNode)) {
|
|
72
|
+
childVNode = newParentVNode._children[i] = createVNode(
|
|
73
|
+
Fragment,
|
|
74
|
+
{ children: childVNode },
|
|
75
|
+
null,
|
|
76
|
+
null,
|
|
77
|
+
null
|
|
78
|
+
);
|
|
79
|
+
// } else if (childVNode._depth > 0) {
|
|
80
|
+
} else if (typeof childVNode !== "undefined" && childVNode._depth > 0) { // MODDED
|
|
81
|
+
// VNode is already in use, clone it. This can happen in the following
|
|
82
|
+
// scenario:
|
|
83
|
+
// const reuse = <div />
|
|
84
|
+
// <div>{reuse}<span />{reuse}</div>
|
|
85
|
+
childVNode = newParentVNode._children[i] = createVNode(
|
|
86
|
+
childVNode.type,
|
|
87
|
+
childVNode.props,
|
|
88
|
+
childVNode.key,
|
|
89
|
+
childVNode.ref ? childVNode.ref : null,
|
|
90
|
+
childVNode._original
|
|
91
|
+
);
|
|
92
|
+
} else {
|
|
93
|
+
childVNode = newParentVNode._children[i] = childVNode;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Terser removes the `continue` here and wraps the loop body
|
|
97
|
+
// in a `if (childVNode) { ... } condition
|
|
98
|
+
if (childVNode === null || typeof childVNode === "undefined") { // MODDED
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
childVNode._parent = newParentVNode;
|
|
103
|
+
childVNode._depth = newParentVNode._depth + 1;
|
|
104
|
+
|
|
105
|
+
// Check if we find a corresponding element in oldChildren.
|
|
106
|
+
// If found, delete the array item by setting to `undefined`.
|
|
107
|
+
// We use `undefined`, as `null` is reserved for empty placeholders
|
|
108
|
+
// (holes).
|
|
109
|
+
oldVNode = oldChildren[i];
|
|
110
|
+
|
|
111
|
+
if (
|
|
112
|
+
oldVNode === null ||
|
|
113
|
+
(oldVNode &&
|
|
114
|
+
childVNode.key == oldVNode.key &&
|
|
115
|
+
childVNode.type === oldVNode.type)
|
|
116
|
+
) {
|
|
117
|
+
oldChildren[i] = undefined;
|
|
118
|
+
} else {
|
|
119
|
+
// Either oldVNode === undefined or oldChildrenLength > 0,
|
|
120
|
+
// so after this loop oldVNode == null or oldVNode is a valid value.
|
|
121
|
+
for (j = 0; j < oldChildrenLength; j++) {
|
|
122
|
+
oldVNode = oldChildren[j];
|
|
123
|
+
// If childVNode is unkeyed, we only match similarly unkeyed nodes, otherwise we match by key.
|
|
124
|
+
// We always match by type (in either case).
|
|
125
|
+
if (
|
|
126
|
+
oldVNode &&
|
|
127
|
+
childVNode.key == oldVNode.key &&
|
|
128
|
+
childVNode.type === oldVNode.type
|
|
129
|
+
) {
|
|
130
|
+
oldChildren[j] = undefined;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
oldVNode = null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
oldVNode = oldVNode || EMPTY_OBJ;
|
|
138
|
+
|
|
139
|
+
// Morph the old element into the new one, but don't append it to the dom yet
|
|
140
|
+
diff(
|
|
141
|
+
parentDom,
|
|
142
|
+
childVNode,
|
|
143
|
+
oldVNode,
|
|
144
|
+
globalContext,
|
|
145
|
+
isSvg,
|
|
146
|
+
excessDomChildren,
|
|
147
|
+
commitQueue,
|
|
148
|
+
oldDom,
|
|
149
|
+
isHydrating
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
newDom = childVNode._dom;
|
|
153
|
+
|
|
154
|
+
if ((j = childVNode.ref) && oldVNode.ref !== j) {
|
|
155
|
+
if (refs === null || typeof refs === "undefined") refs = []; // MODDED
|
|
156
|
+
if (oldVNode.ref) refs.push(oldVNode.ref, null, childVNode);
|
|
157
|
+
refs.push(j, childVNode._component || newDom, childVNode);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (newDom != null) {
|
|
161
|
+
if (firstChildDom == null) {
|
|
162
|
+
firstChildDom = newDom;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (
|
|
166
|
+
typeof childVNode.type == 'function' &&
|
|
167
|
+
childVNode._children === oldVNode._children
|
|
168
|
+
) {
|
|
169
|
+
childVNode._nextDom = oldDom = reorderChildren(
|
|
170
|
+
childVNode,
|
|
171
|
+
oldDom,
|
|
172
|
+
parentDom
|
|
173
|
+
);
|
|
174
|
+
} else {
|
|
175
|
+
oldDom = placeChild(
|
|
176
|
+
parentDom,
|
|
177
|
+
childVNode,
|
|
178
|
+
oldVNode,
|
|
179
|
+
oldChildren,
|
|
180
|
+
newDom,
|
|
181
|
+
oldDom
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (typeof newParentVNode.type == 'function') {
|
|
186
|
+
// Because the newParentVNode is Fragment-like, we need to set it's
|
|
187
|
+
// _nextDom property to the nextSibling of its last child DOM node.
|
|
188
|
+
//
|
|
189
|
+
// `oldDom` contains the correct value here because if the last child
|
|
190
|
+
// is a Fragment-like, then oldDom has already been set to that child's _nextDom.
|
|
191
|
+
// If the last child is a DOM VNode, then oldDom will be set to that DOM
|
|
192
|
+
// node's nextSibling.
|
|
193
|
+
newParentVNode._nextDom = oldDom;
|
|
194
|
+
}
|
|
195
|
+
} else if (
|
|
196
|
+
oldDom &&
|
|
197
|
+
oldVNode._dom == oldDom &&
|
|
198
|
+
oldDom.parentNode != parentDom
|
|
199
|
+
) {
|
|
200
|
+
// The above condition is to handle null placeholders. See test in placeholder.test.js:
|
|
201
|
+
// `efficiently replace null placeholders in parent rerenders`
|
|
202
|
+
oldDom = getDomSibling(oldVNode);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
newParentVNode._dom = firstChildDom;
|
|
207
|
+
|
|
208
|
+
// Remove remaining oldChildren if there are any.
|
|
209
|
+
for (i = oldChildrenLength; i--;) {
|
|
210
|
+
if (typeof oldChildren[i] !== "undefined" && oldChildren[i] !== null) { // MODDED
|
|
211
|
+
if (
|
|
212
|
+
typeof newParentVNode.type == 'function' &&
|
|
213
|
+
oldChildren[i]._dom != null &&
|
|
214
|
+
oldChildren[i]._dom == newParentVNode._nextDom
|
|
215
|
+
) {
|
|
216
|
+
// If the newParentVNode.__nextDom points to a dom node that is about to
|
|
217
|
+
// be unmounted, then get the next sibling of that vnode and set
|
|
218
|
+
// _nextDom to it
|
|
219
|
+
// newParentVNode._nextDom = getDomSibling(oldParentVNode, i + 1);
|
|
220
|
+
newParentVNode._nextDom = getLastDom(oldParentVNode).nextSibling;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
unmount(oldChildren[i], oldChildren[i]);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Set refs only after unmount
|
|
228
|
+
if (refs) {
|
|
229
|
+
for (i = 0; i < refs.length; i++) {
|
|
230
|
+
applyRef(refs[i], refs[++i], refs[++i]);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function reorderChildren(childVNode, oldDom, parentDom) {
|
|
236
|
+
// Note: VNodes in nested suspended trees may be missing _children.
|
|
237
|
+
let c = childVNode._children;
|
|
238
|
+
let tmp = 0;
|
|
239
|
+
for (; c && tmp < c.length; tmp++) {
|
|
240
|
+
let vnode = c[tmp];
|
|
241
|
+
if (vnode) {
|
|
242
|
+
// We typically enter this code path on sCU bailout, where we copy
|
|
243
|
+
// oldVNode._children to newVNode._children. If that is the case, we need
|
|
244
|
+
// to update the old children's _parent pointer to point to the newVNode
|
|
245
|
+
// (childVNode here).
|
|
246
|
+
vnode._parent = childVNode;
|
|
247
|
+
|
|
248
|
+
if (typeof vnode.type == 'function') {
|
|
249
|
+
oldDom = reorderChildren(vnode, oldDom, parentDom);
|
|
250
|
+
} else {
|
|
251
|
+
oldDom = placeChild(parentDom, vnode, vnode, c, vnode._dom, oldDom);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return oldDom;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Flatten and loop through the children of a virtual node
|
|
261
|
+
* @param {import('../index').ComponentChildren} children The unflattened
|
|
262
|
+
* children of a virtual node
|
|
263
|
+
* @returns {import('../internal').VNode[]}
|
|
264
|
+
*/
|
|
265
|
+
export function toChildArray(children, out) {
|
|
266
|
+
out = out || [];
|
|
267
|
+
if (children == null || typeof children == 'boolean') {
|
|
268
|
+
} else if (Array.isArray(children)) {
|
|
269
|
+
children.some(child => {
|
|
270
|
+
toChildArray(child, out);
|
|
271
|
+
});
|
|
272
|
+
} else {
|
|
273
|
+
out.push(children);
|
|
274
|
+
}
|
|
275
|
+
return out;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function placeChild(
|
|
279
|
+
parentDom,
|
|
280
|
+
childVNode,
|
|
281
|
+
oldVNode,
|
|
282
|
+
oldChildren,
|
|
283
|
+
newDom,
|
|
284
|
+
oldDom
|
|
285
|
+
) {
|
|
286
|
+
let nextDom;
|
|
287
|
+
if (childVNode._nextDom !== undefined) {
|
|
288
|
+
// Only Fragments or components that return Fragment like VNodes will
|
|
289
|
+
// have a non-undefined _nextDom. Continue the diff from the sibling
|
|
290
|
+
// of last DOM child of this child VNode
|
|
291
|
+
nextDom = childVNode._nextDom;
|
|
292
|
+
|
|
293
|
+
// Eagerly cleanup _nextDom. We don't need to persist the value because
|
|
294
|
+
// it is only used by `diffChildren` to determine where to resume the diff after
|
|
295
|
+
// diffing Components and Fragments. Once we store it the nextDOM local var, we
|
|
296
|
+
// can clean up the property
|
|
297
|
+
childVNode._nextDom = undefined;
|
|
298
|
+
} else if (
|
|
299
|
+
oldVNode === null ||
|
|
300
|
+
newDom != oldDom ||
|
|
301
|
+
newDom.parentNode == null
|
|
302
|
+
) {
|
|
303
|
+
outer: if (oldDom == null || oldDom.parentNode !== parentDom) {
|
|
304
|
+
parentDom.appendChild(newDom);
|
|
305
|
+
nextDom = null;
|
|
306
|
+
} else {
|
|
307
|
+
// `j<oldChildrenLength; j+=2` is an alternative to `j++<oldChildrenLength/2`
|
|
308
|
+
for (
|
|
309
|
+
let sibDom = oldDom, j = 0;
|
|
310
|
+
(sibDom = sibDom.nextSibling) && j < oldChildren.length;
|
|
311
|
+
j += 2
|
|
312
|
+
) {
|
|
313
|
+
if (sibDom == newDom) {
|
|
314
|
+
break outer;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
parentDom.insertBefore(newDom, oldDom);
|
|
318
|
+
nextDom = oldDom;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// If we have pre-calculated the nextDOM node, use it. Else calculate it now
|
|
323
|
+
// Strictly check for `undefined` here cuz `null` is a valid value of `nextDom`.
|
|
324
|
+
// See more detail in create-element.js:createVNode
|
|
325
|
+
if (nextDom !== undefined) {
|
|
326
|
+
oldDom = nextDom;
|
|
327
|
+
} else {
|
|
328
|
+
oldDom = newDom.nextSibling;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return oldDom;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @param {import('../internal').VNode} vnode
|
|
336
|
+
*/
|
|
337
|
+
function getLastDom(vnode) {
|
|
338
|
+
if (vnode.type == null || typeof vnode.type === 'string') {
|
|
339
|
+
return vnode._dom;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (vnode._children) {
|
|
343
|
+
for (let i = vnode._children.length - 1; i >= 0; i--) {
|
|
344
|
+
let child = vnode._children[i];
|
|
345
|
+
if (child) {
|
|
346
|
+
let lastDom = getLastDom(child);
|
|
347
|
+
if (lastDom) {
|
|
348
|
+
return lastDom;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return null;
|
|
355
|
+
}
|