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,16 @@
|
|
|
1
|
+
import { _catchError } from './diff/catch-error';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `option` object can potentially contain callback functions
|
|
5
|
+
* that are called during various stages of our renderer. This is the
|
|
6
|
+
* foundation on which all our addons like `preact/debug`, `preact/compat`,
|
|
7
|
+
* and `preact/hooks` are based on. See the `Options` type in `internal.d.ts`
|
|
8
|
+
* for a full list of available option hooks (most editors/IDEs allow you to
|
|
9
|
+
* ctrl+click or cmd+click on mac the type definition below).
|
|
10
|
+
* @type {import('./internal').Options}
|
|
11
|
+
*/
|
|
12
|
+
const options: any = {
|
|
13
|
+
_catchError
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default options;
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
declare module "preact" {
|
|
5
|
+
import { JSXInternal } from "preact/jsx"
|
|
6
|
+
// export as namespace preact;
|
|
7
|
+
|
|
8
|
+
// import { JSXInternal } from './jsx';
|
|
9
|
+
|
|
10
|
+
export import JSX = JSXInternal;
|
|
11
|
+
|
|
12
|
+
//
|
|
13
|
+
// Preact Virtual DOM
|
|
14
|
+
// -----------------------------------
|
|
15
|
+
|
|
16
|
+
export interface VNode<P = {}> {
|
|
17
|
+
type: ComponentType<P> | string;
|
|
18
|
+
props: P & { children: ComponentChildren };
|
|
19
|
+
key: Key;
|
|
20
|
+
/**
|
|
21
|
+
* ref is not guaranteed by React.ReactElement, for compatibility reasons
|
|
22
|
+
* with popular react libs we define it as optional too
|
|
23
|
+
*/
|
|
24
|
+
ref?: Ref<any> | null;
|
|
25
|
+
/**
|
|
26
|
+
* The time this `vnode` started rendering. Will only be set when
|
|
27
|
+
* the devtools are attached.
|
|
28
|
+
* Default value: `0`
|
|
29
|
+
*/
|
|
30
|
+
startTime?: number;
|
|
31
|
+
/**
|
|
32
|
+
* The time that the rendering of this `vnode` was completed. Will only be
|
|
33
|
+
* set when the devtools are attached.
|
|
34
|
+
* Default value: `-1`
|
|
35
|
+
*/
|
|
36
|
+
endTime?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//
|
|
40
|
+
// Preact Component interface
|
|
41
|
+
// -----------------------------------
|
|
42
|
+
|
|
43
|
+
export type Key = string | number | any;
|
|
44
|
+
|
|
45
|
+
export type RefObject<T> = { current: T | null };
|
|
46
|
+
export type RefCallback<T> = (instance: T | null) => void;
|
|
47
|
+
export type Ref<T> = RefObject<T> | RefCallback<T>;
|
|
48
|
+
|
|
49
|
+
export type ComponentChild =
|
|
50
|
+
| VNode<any>
|
|
51
|
+
| object
|
|
52
|
+
| string
|
|
53
|
+
| number
|
|
54
|
+
| bigint
|
|
55
|
+
| boolean
|
|
56
|
+
| null
|
|
57
|
+
| undefined;
|
|
58
|
+
export type ComponentChildren = ComponentChild[] | ComponentChild;
|
|
59
|
+
|
|
60
|
+
export interface Attributes {
|
|
61
|
+
key?: Key;
|
|
62
|
+
jsx?: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface ClassAttributes<T> extends Attributes {
|
|
66
|
+
ref?: Ref<T>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface PreactDOMAttributes {
|
|
70
|
+
children?: ComponentChildren;
|
|
71
|
+
dangerouslySetInnerHTML?: {
|
|
72
|
+
__html: string;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type RenderableProps<P, RefType = any> = P &
|
|
77
|
+
Readonly<Attributes & { children?: ComponentChildren; ref?: Ref<RefType> }>;
|
|
78
|
+
|
|
79
|
+
export type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
|
|
80
|
+
export type ComponentFactory<P = {}> = ComponentType<P>;
|
|
81
|
+
|
|
82
|
+
export type ComponentProps<
|
|
83
|
+
C extends ComponentType<any> | keyof JSXInternal.IntrinsicElements
|
|
84
|
+
> = C extends ComponentType<infer P>
|
|
85
|
+
? P
|
|
86
|
+
: C extends keyof JSXInternal.IntrinsicElements
|
|
87
|
+
? JSXInternal.IntrinsicElements[C]
|
|
88
|
+
: never;
|
|
89
|
+
|
|
90
|
+
export interface FunctionComponent<P = {}> {
|
|
91
|
+
(props: RenderableProps<P>, context?: any): VNode<any> | null;
|
|
92
|
+
displayName?: string;
|
|
93
|
+
defaultProps?: Partial<P>;
|
|
94
|
+
}
|
|
95
|
+
export interface FunctionalComponent<P = {}> extends FunctionComponent<P> { }
|
|
96
|
+
|
|
97
|
+
export interface ComponentClass<P = {}, S = {}> {
|
|
98
|
+
new(props: P, context?: any): Component<P, S>;
|
|
99
|
+
displayName?: string;
|
|
100
|
+
defaultProps?: Partial<P>;
|
|
101
|
+
contextType?: Context<any>;
|
|
102
|
+
getDerivedStateFromProps?(
|
|
103
|
+
props: Readonly<P>,
|
|
104
|
+
state: Readonly<S>
|
|
105
|
+
): Partial<S> | null;
|
|
106
|
+
getDerivedStateFromError?(error: any): Partial<S> | null;
|
|
107
|
+
}
|
|
108
|
+
export interface ComponentConstructor<P = {}, S = {}>
|
|
109
|
+
extends ComponentClass<P, S> { }
|
|
110
|
+
|
|
111
|
+
// Type alias for a component instance considered generally, whether stateless or stateful.
|
|
112
|
+
export type AnyComponent<P = {}, S = {}> =
|
|
113
|
+
| FunctionComponent<P>
|
|
114
|
+
| Component<P, S>;
|
|
115
|
+
|
|
116
|
+
export interface Component<P = {}, S = {}> {
|
|
117
|
+
componentWillMount?(): void;
|
|
118
|
+
componentDidMount?(): void;
|
|
119
|
+
componentWillUnmount?(): void;
|
|
120
|
+
getChildContext?(): object;
|
|
121
|
+
componentWillReceiveProps?(nextProps: Readonly<P>, nextContext: any): void;
|
|
122
|
+
shouldComponentUpdate?(
|
|
123
|
+
nextProps: Readonly<P>,
|
|
124
|
+
nextState: Readonly<S>,
|
|
125
|
+
nextContext: any
|
|
126
|
+
): boolean;
|
|
127
|
+
componentWillUpdate?(
|
|
128
|
+
nextProps: Readonly<P>,
|
|
129
|
+
nextState: Readonly<S>,
|
|
130
|
+
nextContext: any
|
|
131
|
+
): void;
|
|
132
|
+
getSnapshotBeforeUpdate?(oldProps: Readonly<P>, oldState: Readonly<S>): any;
|
|
133
|
+
componentDidUpdate?(
|
|
134
|
+
previousProps: Readonly<P>,
|
|
135
|
+
previousState: Readonly<S>,
|
|
136
|
+
snapshot: any
|
|
137
|
+
): void;
|
|
138
|
+
componentDidCatch?(error: any, errorInfo: any): void;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export abstract class Component<P, S> {
|
|
142
|
+
constructor(props?: P, context?: any);
|
|
143
|
+
|
|
144
|
+
static displayName?: string;
|
|
145
|
+
static defaultProps?: any;
|
|
146
|
+
static contextType?: Context<any>;
|
|
147
|
+
|
|
148
|
+
// Static members cannot reference class type parameters. This is not
|
|
149
|
+
// supported in TypeScript. Reusing the same type arguments from `Component`
|
|
150
|
+
// will lead to an impossible state where one cannot satisfy the type
|
|
151
|
+
// constraint under no circumstances, see #1356.In general type arguments
|
|
152
|
+
// seem to be a bit buggy and not supported well at the time of this
|
|
153
|
+
// writing with TS 3.3.3333.
|
|
154
|
+
static getDerivedStateFromProps?(
|
|
155
|
+
props: Readonly<object>,
|
|
156
|
+
state: Readonly<object>
|
|
157
|
+
): object | null;
|
|
158
|
+
static getDerivedStateFromError?(error: any): object | null;
|
|
159
|
+
|
|
160
|
+
state: Readonly<S>;
|
|
161
|
+
props: RenderableProps<P>;
|
|
162
|
+
context: any;
|
|
163
|
+
base?: Element | Text;
|
|
164
|
+
|
|
165
|
+
// From https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e836acc75a78cf0655b5dfdbe81d69fdd4d8a252/types/react/index.d.ts#L402
|
|
166
|
+
// // We MUST keep setState() as a unified signature because it allows proper checking of the method return type.
|
|
167
|
+
// // See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365#issuecomment-351013257
|
|
168
|
+
setState<K extends keyof S>(
|
|
169
|
+
state:
|
|
170
|
+
| ((
|
|
171
|
+
prevState: Readonly<S>,
|
|
172
|
+
props: Readonly<P>
|
|
173
|
+
) => Pick<S, K> | Partial<S> | null)
|
|
174
|
+
| (Pick<S, K> | Partial<S> | null),
|
|
175
|
+
callback?: () => void
|
|
176
|
+
): void;
|
|
177
|
+
|
|
178
|
+
forceUpdate(callback?: () => void): void;
|
|
179
|
+
|
|
180
|
+
abstract render(
|
|
181
|
+
props?: RenderableProps<P>,
|
|
182
|
+
state?: Readonly<S>,
|
|
183
|
+
context?: any
|
|
184
|
+
): ComponentChild;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//
|
|
188
|
+
// Preact createElement
|
|
189
|
+
// -----------------------------------
|
|
190
|
+
|
|
191
|
+
export function createElement(
|
|
192
|
+
type: string,
|
|
193
|
+
props:
|
|
194
|
+
| (JSXInternal.HTMLAttributes &
|
|
195
|
+
JSXInternal.SVGAttributes &
|
|
196
|
+
Record<string, any>)
|
|
197
|
+
| null,
|
|
198
|
+
...children: ComponentChildren[]
|
|
199
|
+
): VNode<any>;
|
|
200
|
+
export function createElement<P>(
|
|
201
|
+
type: ComponentType<P>,
|
|
202
|
+
props: (Attributes & P) | null,
|
|
203
|
+
...children: ComponentChildren[]
|
|
204
|
+
): VNode<any>;
|
|
205
|
+
export namespace createElement {
|
|
206
|
+
export import JSX = JSXInternal;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function h(
|
|
210
|
+
type: string,
|
|
211
|
+
props:
|
|
212
|
+
| (JSXInternal.HTMLAttributes &
|
|
213
|
+
JSXInternal.SVGAttributes &
|
|
214
|
+
Record<string, any>)
|
|
215
|
+
| null,
|
|
216
|
+
...children: ComponentChildren[]
|
|
217
|
+
): VNode<any>;
|
|
218
|
+
export function h<P>(
|
|
219
|
+
type: ComponentType<P>,
|
|
220
|
+
props: (Attributes & P) | null,
|
|
221
|
+
...children: ComponentChildren[]
|
|
222
|
+
): VNode<any>;
|
|
223
|
+
export namespace h {
|
|
224
|
+
export import JSX = JSXInternal;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
//
|
|
228
|
+
// Preact render
|
|
229
|
+
// -----------------------------------
|
|
230
|
+
|
|
231
|
+
export function render(
|
|
232
|
+
vnode: ComponentChild,
|
|
233
|
+
parent: Element | Document | ShadowRoot | DocumentFragment,
|
|
234
|
+
replaceNode?: Element | Text
|
|
235
|
+
): void;
|
|
236
|
+
export function hydrate(
|
|
237
|
+
vnode: ComponentChild,
|
|
238
|
+
parent: Element | Document | ShadowRoot | DocumentFragment
|
|
239
|
+
): void;
|
|
240
|
+
export function cloneElement(
|
|
241
|
+
vnode: VNode<any>,
|
|
242
|
+
props?: any,
|
|
243
|
+
...children: ComponentChildren[]
|
|
244
|
+
): VNode<any>;
|
|
245
|
+
export function cloneElement<P>(
|
|
246
|
+
vnode: VNode<P>,
|
|
247
|
+
props?: any,
|
|
248
|
+
...children: ComponentChildren[]
|
|
249
|
+
): VNode<P>;
|
|
250
|
+
|
|
251
|
+
//
|
|
252
|
+
// Preact Built-in Components
|
|
253
|
+
// -----------------------------------
|
|
254
|
+
|
|
255
|
+
// TODO: Revisit what the public type of this is...
|
|
256
|
+
export const Fragment: ComponentClass<{}, {}>;
|
|
257
|
+
|
|
258
|
+
//
|
|
259
|
+
// Preact options
|
|
260
|
+
// -----------------------------------
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Global options for preact
|
|
264
|
+
*/
|
|
265
|
+
export interface Options {
|
|
266
|
+
/** Attach a hook that is invoked whenever a VNode is created. */
|
|
267
|
+
vnode?(vnode: VNode): void;
|
|
268
|
+
/** Attach a hook that is invoked immediately before a vnode is unmounted. */
|
|
269
|
+
unmount?(vnode: VNode): void;
|
|
270
|
+
/** Attach a hook that is invoked after a vnode has rendered. */
|
|
271
|
+
diffed?(vnode: VNode): void;
|
|
272
|
+
event?(e: Event): any;
|
|
273
|
+
requestAnimationFrame?(callback: () => void): void;
|
|
274
|
+
debounceRendering?(cb: () => void): void;
|
|
275
|
+
useDebugValue?(value: string | number): void;
|
|
276
|
+
_addHookName?(name: string | number): void;
|
|
277
|
+
__suspenseDidResolve?(vnode: VNode, cb: () => void): void;
|
|
278
|
+
// __canSuspenseResolve?(vnode: VNode, cb: () => void): void;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export const options: Options;
|
|
282
|
+
|
|
283
|
+
//
|
|
284
|
+
// Preact helpers
|
|
285
|
+
// -----------------------------------
|
|
286
|
+
export function createRef<T = any>(): RefObject<T>;
|
|
287
|
+
export function toChildArray(
|
|
288
|
+
children: ComponentChildren
|
|
289
|
+
): Array<VNode | string | number>;
|
|
290
|
+
export function isValidElement(vnode: any): vnode is VNode;
|
|
291
|
+
|
|
292
|
+
//
|
|
293
|
+
// Context
|
|
294
|
+
// -----------------------------------
|
|
295
|
+
export interface Consumer<T>
|
|
296
|
+
extends FunctionComponent<{
|
|
297
|
+
children: (value: T) => ComponentChildren;
|
|
298
|
+
}> { }
|
|
299
|
+
export interface PreactConsumer<T> extends Consumer<T> { }
|
|
300
|
+
|
|
301
|
+
export interface Provider<T>
|
|
302
|
+
extends FunctionComponent<{
|
|
303
|
+
value: T;
|
|
304
|
+
children: ComponentChildren;
|
|
305
|
+
}> { }
|
|
306
|
+
export interface PreactProvider<T> extends Provider<T> { }
|
|
307
|
+
|
|
308
|
+
export interface Context<T> {
|
|
309
|
+
Consumer: Consumer<T>;
|
|
310
|
+
Provider: Provider<T>;
|
|
311
|
+
displayName?: string;
|
|
312
|
+
}
|
|
313
|
+
export interface PreactContext<T> extends Context<T> { }
|
|
314
|
+
|
|
315
|
+
export function createContext<T>(defaultValue: T): Context<T>;
|
|
316
|
+
|
|
317
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { EMPTY_OBJ } from './constants';
|
|
2
|
+
import { commitRoot, diff } from './diff/index';
|
|
3
|
+
import { createElement, Fragment } from './create-element';
|
|
4
|
+
import options from './options';
|
|
5
|
+
import { slice } from './util';
|
|
6
|
+
import { PreactElement } from './internal';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Render a Preact virtual node into a DOM element
|
|
10
|
+
* @param {import('./internal').ComponentChild} vnode The virtual node to render
|
|
11
|
+
* @param {import('./internal').PreactElement} parentDom The DOM element to
|
|
12
|
+
* render into
|
|
13
|
+
* @param {import('./internal').PreactElement | object} [replaceNode] Optional: Attempt to re-use an
|
|
14
|
+
* existing DOM tree rooted at `replaceNode`
|
|
15
|
+
*/
|
|
16
|
+
export function render(vnode, parentDom: PreactElement, replaceNode) {
|
|
17
|
+
if (options._root) options._root(vnode, parentDom);
|
|
18
|
+
|
|
19
|
+
// We abuse the `replaceNode` parameter in `hydrate()` to signal if we are in
|
|
20
|
+
// hydration mode or not by passing the `hydrate` function instead of a DOM
|
|
21
|
+
// element..
|
|
22
|
+
let isHydrating = typeof replaceNode === 'function';
|
|
23
|
+
|
|
24
|
+
// To be able to support calling `render()` multiple times on the same
|
|
25
|
+
// DOM node, we need to obtain a reference to the previous tree. We do
|
|
26
|
+
// this by assigning a new `_children` property to DOM nodes which points
|
|
27
|
+
// to the last rendered tree. By default this property is not present, which
|
|
28
|
+
// means that we are mounting a new tree for the first time.
|
|
29
|
+
let oldVNode = isHydrating
|
|
30
|
+
? null
|
|
31
|
+
: (replaceNode && replaceNode._children) || parentDom._children;
|
|
32
|
+
|
|
33
|
+
vnode = (
|
|
34
|
+
(!isHydrating && replaceNode) ||
|
|
35
|
+
parentDom
|
|
36
|
+
)._children = createElement(Fragment, null, [vnode]);
|
|
37
|
+
|
|
38
|
+
// List of effects that need to be called after diffing.
|
|
39
|
+
let commitQueue = [];
|
|
40
|
+
diff(
|
|
41
|
+
parentDom,
|
|
42
|
+
// Determine the new vnode tree and store it on the DOM element on
|
|
43
|
+
// our custom `_children` property.
|
|
44
|
+
vnode,
|
|
45
|
+
oldVNode || EMPTY_OBJ,
|
|
46
|
+
EMPTY_OBJ,
|
|
47
|
+
parentDom.ownerSVGElement !== undefined,
|
|
48
|
+
!isHydrating && replaceNode
|
|
49
|
+
? [replaceNode]
|
|
50
|
+
: oldVNode
|
|
51
|
+
? null
|
|
52
|
+
: parentDom.firstChild
|
|
53
|
+
? slice.call(parentDom.childNodes)
|
|
54
|
+
: null,
|
|
55
|
+
commitQueue,
|
|
56
|
+
!isHydrating && replaceNode
|
|
57
|
+
? replaceNode
|
|
58
|
+
: oldVNode
|
|
59
|
+
? oldVNode._dom
|
|
60
|
+
: parentDom.firstChild,
|
|
61
|
+
isHydrating
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// Flush all queued effects
|
|
65
|
+
commitRoot(commitQueue, vnode);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Update an existing DOM element with data from a Preact virtual node
|
|
70
|
+
* @param {import('./internal').ComponentChild} vnode The virtual node to render
|
|
71
|
+
* @param {import('./internal').PreactElement} parentDom The DOM element to
|
|
72
|
+
* update
|
|
73
|
+
*/
|
|
74
|
+
export function hydrate(vnode, parentDom) {
|
|
75
|
+
render(vnode, parentDom, hydrate);
|
|
76
|
+
}
|