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.
Files changed (63) hide show
  1. package/.gitattributes +2 -0
  2. package/.github/workflows/jsr.yml +19 -0
  3. package/.prettierrc +5 -0
  4. package/3rdparty/preact/LICENSE +21 -0
  5. package/3rdparty/preact/clone-element.ts +45 -0
  6. package/3rdparty/preact/compat/Children.ts +21 -0
  7. package/3rdparty/preact/compat/forwardRef.ts +49 -0
  8. package/3rdparty/preact/compat/index.ts +3 -0
  9. package/3rdparty/preact/compat/memo.ts +34 -0
  10. package/3rdparty/preact/compat/util.ts +38 -0
  11. package/3rdparty/preact/component.ts +235 -0
  12. package/3rdparty/preact/constants.ts +3 -0
  13. package/3rdparty/preact/create-context.ts +71 -0
  14. package/3rdparty/preact/create-element.ts +98 -0
  15. package/3rdparty/preact/diff/catch-error.ts +40 -0
  16. package/3rdparty/preact/diff/children.ts +355 -0
  17. package/3rdparty/preact/diff/index.ts +563 -0
  18. package/3rdparty/preact/diff/props.ts +174 -0
  19. package/3rdparty/preact/hooks/index.ts +536 -0
  20. package/3rdparty/preact/hooks/internal.d.ts +85 -0
  21. package/3rdparty/preact/hooks.d.ts +145 -0
  22. package/3rdparty/preact/index.ts +13 -0
  23. package/3rdparty/preact/internal.d.ts +155 -0
  24. package/3rdparty/preact/jsx-runtime/index.ts +80 -0
  25. package/3rdparty/preact/jsx.d.ts +1008 -0
  26. package/3rdparty/preact/options.ts +16 -0
  27. package/3rdparty/preact/preact.d.ts +317 -0
  28. package/3rdparty/preact/render.ts +76 -0
  29. package/3rdparty/preact/signals/index.ts +443 -0
  30. package/3rdparty/preact/signals/internal.d.ts +36 -0
  31. package/3rdparty/preact/signals-core/index.ts +663 -0
  32. package/3rdparty/preact/style.d.ts +205 -0
  33. package/3rdparty/preact/util.ts +29 -0
  34. package/@DO_NOT_CHANGE.txt +3 -0
  35. package/README.md +33 -0
  36. package/definitions/app.d.ts +52048 -0
  37. package/definitions/augments.d.ts +16 -0
  38. package/definitions/globals.d.ts +34 -0
  39. package/definitions/index.d.ts +9 -0
  40. package/definitions/jsx.d.ts +517 -0
  41. package/definitions/modules.d.ts +29 -0
  42. package/definitions/onejs.d.ts +164 -0
  43. package/definitions/preact.jsx.d.ts +7 -0
  44. package/definitions/proto-overrides.d.ts +13 -0
  45. package/definitions/puerts.d.ts +31 -0
  46. package/definitions/unity-engine.d.ts +23 -0
  47. package/hooks/eventful.ts +56 -0
  48. package/import-transform.mjs +42 -0
  49. package/index.ts +44 -0
  50. package/jsr.json +10 -0
  51. package/onejs-tw-config.cjs +188 -0
  52. package/package.json +9 -0
  53. package/preloads/inject.ts +44 -0
  54. package/styling/index.tsx +80 -0
  55. package/styling/utils/generateAlphabeticName.ts +21 -0
  56. package/styling/utils/generateComponentId.ts +6 -0
  57. package/styling/utils/hash.ts +46 -0
  58. package/switch.cjs +185 -0
  59. package/uss-transform-plugin.cjs +83 -0
  60. package/utils/color-palettes.ts +3 -0
  61. package/utils/color-parser.ts +249 -0
  62. package/utils/float-parser.ts +31 -0
  63. package/utils/index.ts +12 -0
@@ -0,0 +1,85 @@
1
+ import {
2
+ Component as PreactComponent,
3
+ PreactContext,
4
+ ErrorInfo,
5
+ VNode as PreactVNode
6
+ } from '../internal';
7
+ import { Reducer } from 'preact/hooks';
8
+
9
+ export { PreactContext };
10
+
11
+ /**
12
+ * The type of arguments passed to a Hook function. While this type is not
13
+ * strictly necessary, they are given a type name to make it easier to read
14
+ * the following types and trace the flow of data.
15
+ */
16
+ export type HookArgs = any;
17
+
18
+ /**
19
+ * The return type of a Hook function. While this type is not
20
+ * strictly necessary, they are given a type name to make it easier to read
21
+ * the following types and trace the flow of data.
22
+ */
23
+ export type HookReturnValue = any;
24
+
25
+ /** The public function a user invokes to use a Hook */
26
+ export type Hook = (...args: HookArgs[]) => HookReturnValue;
27
+
28
+ // Hook tracking
29
+
30
+ export interface ComponentHooks {
31
+ /** The list of hooks a component uses */
32
+ _list: HookState[];
33
+ /** List of Effects to be invoked after the next frame is rendered */
34
+ _pendingEffects: EffectHookState[];
35
+ }
36
+
37
+ export interface Component extends PreactComponent<any, any> {
38
+ __hooks?: ComponentHooks;
39
+ }
40
+
41
+ export interface VNode extends PreactVNode {
42
+ _mask?: string;
43
+ }
44
+
45
+ export type HookState =
46
+ | EffectHookState
47
+ | MemoHookState
48
+ | ReducerHookState
49
+ | ContextHookState
50
+ | ErrorBoundaryHookState;
51
+
52
+ export type Effect = () => void | Cleanup;
53
+ export type Cleanup = () => void;
54
+
55
+ export interface EffectHookState {
56
+ _value?: Effect;
57
+ _args?: any[];
58
+ _pendingArgs?: any[];
59
+ _cleanup?: Cleanup | void;
60
+ }
61
+
62
+ export interface MemoHookState {
63
+ _value?: any;
64
+ _pendingValue?: any;
65
+ _args?: any[];
66
+ _pendingArgs?: any[];
67
+ _factory?: () => any;
68
+ }
69
+
70
+ export interface ReducerHookState {
71
+ _nextValue?: any;
72
+ _value?: any;
73
+ _component?: Component;
74
+ _reducer?: Reducer<any, any>;
75
+ }
76
+
77
+ export interface ContextHookState {
78
+ /** Whether this hooks as subscribed to updates yet */
79
+ _value?: boolean;
80
+ _context?: PreactContext;
81
+ }
82
+
83
+ export interface ErrorBoundaryHookState {
84
+ _value?: (error: any, errorInfo: ErrorInfo) => void;
85
+ }
@@ -0,0 +1,145 @@
1
+
2
+ declare module "preact/hooks" {
3
+
4
+ import { PreactContext, Ref as PreactRef } from 'preact'
5
+
6
+ type Inputs = ReadonlyArray<unknown>;
7
+
8
+ export type StateUpdater<S> = (value: S | ((prevState: S) => S)) => void;
9
+ /**
10
+ * Returns a stateful value, and a function to update it.
11
+ * @param initialState The initial value (or a function that returns the initial value)
12
+ */
13
+ export function useState<S>(initialState: S | (() => S)): [S, StateUpdater<S>];
14
+
15
+ export function useState<S = undefined>(): [
16
+ S | undefined,
17
+ StateUpdater<S | undefined>
18
+ ];
19
+
20
+ export type Reducer<S, A> = (prevState: S, action: A) => S;
21
+ /**
22
+ * An alternative to `useState`.
23
+ *
24
+ * `useReducer` is usually preferable to `useState` when you have complex state logic that involves
25
+ * multiple sub-values. It also lets you optimize performance for components that trigger deep
26
+ * updates because you can pass `dispatch` down instead of callbacks.
27
+ * @param reducer Given the current state and an action, returns the new state
28
+ * @param initialState The initial value to store as state
29
+ */
30
+ export function useReducer<S, A>(
31
+ reducer: Reducer<S, A>,
32
+ initialState: S
33
+ ): [S, (action: A) => void];
34
+
35
+ /**
36
+ * An alternative to `useState`.
37
+ *
38
+ * `useReducer` is usually preferable to `useState` when you have complex state logic that involves
39
+ * multiple sub-values. It also lets you optimize performance for components that trigger deep
40
+ * updates because you can pass `dispatch` down instead of callbacks.
41
+ * @param reducer Given the current state and an action, returns the new state
42
+ * @param initialArg The initial argument to pass to the `init` function
43
+ * @param init A function that, given the `initialArg`, returns the initial value to store as state
44
+ */
45
+ export function useReducer<S, A, I>(
46
+ reducer: Reducer<S, A>,
47
+ initialArg: I,
48
+ init: (arg: I) => S
49
+ ): [S, (action: A) => void];
50
+
51
+ /** @deprecated Use the `Ref` type instead. */
52
+ type PropRef<T> = MutableRef<T>;
53
+ interface Ref<T> {
54
+ readonly current: T | null;
55
+ }
56
+
57
+ interface MutableRef<T> {
58
+ current: T;
59
+ }
60
+
61
+ /**
62
+ * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
63
+ * (`initialValue`). The returned object will persist for the full lifetime of the component.
64
+ *
65
+ * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
66
+ * value around similar to how you’d use instance fields in classes.
67
+ *
68
+ * @param initialValue the initial value to store in the ref object
69
+ */
70
+ export function useRef<T>(initialValue: T): MutableRef<T>;
71
+ export function useRef<T>(initialValue: T | null): Ref<T>;
72
+ export function useRef<T>(): MutableRef<T>;
73
+
74
+ type EffectCallback = () => void | (() => void);
75
+ /**
76
+ * Accepts a function that contains imperative, possibly effectful code.
77
+ * The effects run after browser paint, without blocking it.
78
+ *
79
+ * @param effect Imperative function that can return a cleanup function
80
+ * @param inputs If present, effect will only activate if the values in the list change (using ===).
81
+ */
82
+ export function useEffect(effect: EffectCallback, inputs?: Inputs): void;
83
+
84
+ type CreateHandle = () => object;
85
+
86
+ /**
87
+ * @param ref The ref that will be mutated
88
+ * @param create The function that will be executed to get the value that will be attached to
89
+ * ref.current
90
+ * @param inputs If present, effect will only activate if the values in the list change (using ===).
91
+ */
92
+ export function useImperativeHandle<T, R extends T>(
93
+ ref: PreactRef<T>,
94
+ create: () => R,
95
+ inputs?: Inputs
96
+ ): void;
97
+
98
+ /**
99
+ * Accepts a function that contains imperative, possibly effectful code.
100
+ * Use this to read layout from the DOM and synchronously re-render.
101
+ * Updates scheduled inside `useLayoutEffect` will be flushed synchronously, after all DOM mutations but before the browser has a chance to paint.
102
+ * Prefer the standard `useEffect` hook when possible to avoid blocking visual updates.
103
+ *
104
+ * @param effect Imperative function that can return a cleanup function
105
+ * @param inputs If present, effect will only activate if the values in the list change (using ===).
106
+ */
107
+ export function useLayoutEffect(effect: EffectCallback, inputs?: Inputs): void;
108
+
109
+ /**
110
+ * Returns a memoized version of the callback that only changes if one of the `inputs`
111
+ * has changed (using ===).
112
+ */
113
+ export function useCallback<T extends Function>(callback: T, inputs: Inputs): T;
114
+
115
+ /**
116
+ * Pass a factory function and an array of inputs.
117
+ * useMemo will only recompute the memoized value when one of the inputs has changed.
118
+ * This optimization helps to avoid expensive calculations on every render.
119
+ * If no array is provided, a new value will be computed whenever a new function instance is passed as the first argument.
120
+ */
121
+ // for `inputs`, allow undefined, but don't make it optional as that is very likely a mistake
122
+ export function useMemo<T>(factory: () => T, inputs: Inputs | undefined): T;
123
+
124
+ /**
125
+ * Returns the current context value, as given by the nearest context provider for the given context.
126
+ * When the provider updates, this Hook will trigger a rerender with the latest context value.
127
+ *
128
+ * @param context The context you want to use
129
+ */
130
+ export function useContext<T>(context: PreactContext<T>): T;
131
+
132
+ /**
133
+ * Customize the displayed value in the devtools panel.
134
+ *
135
+ * @param value Custom hook name or object that is passed to formatter
136
+ * @param formatter Formatter to modify value before sending it to the devtools
137
+ */
138
+ export function useDebugValue<T>(value: T, formatter?: (value: T) => any): void;
139
+
140
+ export function useErrorBoundary(
141
+ callback?: (error: any, errorInfo: any) => Promise<void> | void
142
+ ): [any, () => void];
143
+
144
+ export function useId(): string;
145
+ }
@@ -0,0 +1,13 @@
1
+ export { render, hydrate } from './render';
2
+ export {
3
+ createElement,
4
+ createElement as h,
5
+ Fragment,
6
+ createRef,
7
+ isValidElement
8
+ } from './create-element';
9
+ export { Component } from './component';
10
+ export { cloneElement } from './clone-element';
11
+ export { createContext } from './create-context';
12
+ export { toChildArray } from './diff/children';
13
+ export { default as options } from './options';
@@ -0,0 +1,155 @@
1
+ import * as preact from 'preact';
2
+
3
+ export enum HookType {
4
+ useState = 1,
5
+ useReducer = 2,
6
+ useEffect = 3,
7
+ useLayoutEffect = 4,
8
+ useRef = 5,
9
+ useImperativeHandle = 6,
10
+ useMemo = 7,
11
+ useCallback = 8,
12
+ useContext = 9,
13
+ useErrorBoundary = 10,
14
+ // Not a real hook, but the devtools treat is as such
15
+ useDebugvalue = 11
16
+ }
17
+
18
+ export interface DevSource {
19
+ fileName: string;
20
+ lineNumber: number;
21
+ }
22
+
23
+ export interface ErrorInfo {
24
+ componentStack?: string;
25
+ }
26
+
27
+ export interface Options extends preact.Options {
28
+ /** Attach a hook that is invoked before render, mainly to check the arguments. */
29
+ _root?(
30
+ vnode: ComponentChild,
31
+ parent: Element | Document | ShadowRoot | DocumentFragment
32
+ ): void;
33
+ /** Attach a hook that is invoked before a vnode is diffed. */
34
+ _diff?(vnode: VNode): void;
35
+ /** Attach a hook that is invoked after a tree was mounted or was updated. */
36
+ _commit?(vnode: VNode, commitQueue: Component[]): void;
37
+ /** Attach a hook that is invoked before a vnode has rendered. */
38
+ _render?(vnode: VNode): void;
39
+ /** Attach a hook that is invoked before a hook's state is queried. */
40
+ _hook?(component: Component, index: number, type: HookType): void;
41
+ /** Bypass effect execution. Currenty only used in devtools for hooks inspection */
42
+ _skipEffects?: boolean;
43
+ /** Attach a hook that is invoked after an error is caught in a component but before calling lifecycle hooks */
44
+ _catchError(
45
+ error: any,
46
+ vnode: VNode,
47
+ oldVNode: VNode | undefined,
48
+ errorInfo: ErrorInfo | undefined
49
+ ): void;
50
+ }
51
+
52
+ export type ComponentChild =
53
+ | VNode<any>
54
+ | string
55
+ | number
56
+ | boolean
57
+ | null
58
+ | undefined;
59
+ export type ComponentChildren = ComponentChild[] | ComponentChild;
60
+
61
+ export interface FunctionComponent<P = {}> extends preact.FunctionComponent<P> {
62
+ // Internally, createContext uses `contextType` on a Function component to
63
+ // implement the Consumer component
64
+ contextType?: PreactContext;
65
+
66
+ // Internally, createContext stores a ref to the context object on the Provider
67
+ // Function component to help devtools
68
+ _contextRef?: PreactContext;
69
+
70
+ // Define these properties as undefined on FunctionComponent to get rid of
71
+ // some errors in `diff()`
72
+ getDerivedStateFromProps?: undefined;
73
+ getDerivedStateFromError?: undefined;
74
+ }
75
+
76
+ export interface ComponentClass<P = {}> extends preact.ComponentClass<P> {
77
+ _contextRef?: any;
78
+
79
+ // Override public contextType with internal PreactContext type
80
+ contextType?: PreactContext;
81
+ }
82
+
83
+ // Redefine ComponentType using our new internal FunctionComponent interface above
84
+ export type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
85
+
86
+ export interface PreactElement extends HTMLElement {
87
+ _children?: VNode<any> | null;
88
+ /** Event listeners to support event delegation */
89
+ _listeners?: Record<string, (e: Event) => void>;
90
+
91
+ // Preact uses this attribute to detect SVG nodes
92
+ ownerSVGElement?: SVGElement | null;
93
+
94
+ // style: HTMLElement["style"]; // From HTMLElement
95
+
96
+ data?: string | number; // From Text node
97
+ }
98
+
99
+ // We use the `current` property to differentiate between the two kinds of Refs so
100
+ // internally we'll define `current` on both to make TypeScript happy
101
+ type RefObject<T> = { current: T | null };
102
+ type RefCallback<T> = { (instance: T | null): void; current: undefined };
103
+ type Ref<T> = RefObject<T> | RefCallback<T>;
104
+
105
+ export interface VNode<P = {}> extends preact.VNode<P> {
106
+ // Redefine type here using our internal ComponentType type
107
+ type: string | ComponentType<P>;
108
+ props: P & { children: ComponentChildren };
109
+ ref?: Ref<any> | null;
110
+ _children: Array<VNode<any>> | null;
111
+ _parent: VNode | null;
112
+ _depth: number | null;
113
+ /**
114
+ * The [first (for Fragments)] DOM child of a VNode
115
+ */
116
+ _dom: PreactElement | null;
117
+ /**
118
+ * The last dom child of a Fragment, or components that return a Fragment
119
+ */
120
+ _nextDom: PreactElement | null;
121
+ _component: Component | null;
122
+ _hydrating: boolean | null;
123
+ constructor: undefined;
124
+ _original: number;
125
+ }
126
+
127
+ export interface Component<P = {}, S = {}> extends preact.Component<P, S> {
128
+ // When component is functional component, this is reset to functional component
129
+ constructor: ComponentType<P>;
130
+ state: S; // Override Component["state"] to not be readonly for internal use, specifically Hooks
131
+ base?: PreactElement;
132
+
133
+ _dirty: boolean;
134
+ _force?: boolean;
135
+ _renderCallbacks: Array<() => void>; // Only class components
136
+ _globalContext?: any;
137
+ _vnode?: VNode<P> | null;
138
+ _nextState?: S | null; // Only class components
139
+ /** Only used in the devtools to later dirty check if state has changed */
140
+ _prevState?: S | null;
141
+ /**
142
+ * Pointer to the parent dom node. This is only needed for top-level Fragment
143
+ * components or array returns.
144
+ */
145
+ _parentDom?: PreactElement | null;
146
+ // Always read, set only when handling error
147
+ _processingException?: Component<any, any> | null;
148
+ // Always read, set only when handling error. This is used to indicate at diffTime to set _processingException
149
+ _pendingError?: Component<any, any> | null;
150
+ }
151
+
152
+ export interface PreactContext extends preact.Context<any> {
153
+ _id: string;
154
+ _defaultValue: any;
155
+ }
@@ -0,0 +1,80 @@
1
+ import { options, Fragment } from 'preact';
2
+
3
+ /** @typedef {import('preact').VNode} VNode */
4
+
5
+ let vnodeId = 0;
6
+
7
+ /**
8
+ * @fileoverview
9
+ * This file exports various methods that implement Babel's "automatic" JSX runtime API:
10
+ * - jsx(type, props, key)
11
+ * - jsxs(type, props, key)
12
+ * - jsxDEV(type, props, key, __source, __self)
13
+ *
14
+ * The implementation of createVNode here is optimized for performance.
15
+ * Benchmarks: https://esbench.com/bench/5f6b54a0b4632100a7dcd2b3
16
+ */
17
+
18
+ /**
19
+ * JSX.Element factory used by Babel's {runtime:"automatic"} JSX transform
20
+ * @param {VNode['type']} type
21
+ * @param {VNode['props']} props
22
+ * @param {VNode['key']} [key]
23
+ * @param {unknown} [isStaticChildren]
24
+ * @param {unknown} [__source]
25
+ * @param {unknown} [__self]
26
+ */
27
+ function createVNode(type, props, key, isStaticChildren, __source, __self) {
28
+ // We'll want to preserve `ref` in props to get rid of the need for
29
+ // forwardRef components in the future, but that should happen via
30
+ // a separate PR.
31
+ let normalizedProps = {},
32
+ ref,
33
+ i;
34
+ for (i in props) {
35
+ if (i == 'ref') {
36
+ ref = props[i];
37
+ } else {
38
+ normalizedProps[i] = props[i];
39
+ }
40
+ }
41
+
42
+ const vnode = {
43
+ type,
44
+ props: normalizedProps,
45
+ key,
46
+ ref,
47
+ _children: null,
48
+ _parent: null,
49
+ _depth: 0,
50
+ _dom: null,
51
+ _nextDom: undefined,
52
+ _component: null,
53
+ _hydrating: null,
54
+ constructor: undefined,
55
+ _original: --vnodeId,
56
+ __source,
57
+ __self
58
+ };
59
+
60
+ // If a Component VNode, check for and apply defaultProps.
61
+ // Note: `type` is often a String, and can be `undefined` in development.
62
+ if (typeof type === 'function' && (ref = type.defaultProps)) {
63
+ for (i in ref)
64
+ if (typeof normalizedProps[i] === 'undefined') {
65
+ normalizedProps[i] = ref[i];
66
+ }
67
+ }
68
+
69
+ if (options.vnode) options.vnode(vnode as any);
70
+ return vnode;
71
+ }
72
+
73
+ export {
74
+ createVNode as jsx,
75
+ createVNode as jsxs,
76
+ createVNode as jsxDEV,
77
+ Fragment
78
+ };
79
+
80
+ export { type JSXInternal as JSX } from 'preact/jsx'