quickwin 2026.5.2-3.145209
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 +6 -0
- package/examples/pdf_preview.js +440 -0
- package/examples/pdf_preview.ts +470 -0
- package/examples/preact_demo.js +35 -0
- package/examples/preact_demo.tsx +49 -0
- package/examples/tray_demo.js +75 -0
- package/examples/tray_demo.tsx +79 -0
- package/lib/fetch.js +746 -0
- package/lib/fetch.ts +811 -0
- package/lib/polyfill.js +500 -0
- package/lib/polyfill.ts +454 -0
- package/lib/preact/hooks.js +287 -0
- package/lib/preact/hooks.ts +330 -0
- package/lib/preact/jsx-runtime.js +1 -0
- package/lib/preact/jsx-runtime.ts +2 -0
- package/lib/preact/jsx.d.ts +36 -0
- package/lib/preact/layout.js +153 -0
- package/lib/preact/layout.ts +183 -0
- package/lib/preact/preact.js +54 -0
- package/lib/preact/preact.ts +133 -0
- package/lib/preact/props.js +99 -0
- package/lib/preact/props.ts +119 -0
- package/lib/preact/render.js +320 -0
- package/lib/preact/render.ts +353 -0
- package/lib/websocket.js +540 -0
- package/lib/websocket.ts +574 -0
- package/package.json +32 -0
- package/quickwin.d.ts +657 -0
- package/test/add.wasm +0 -0
- package/test/complex.wasm +0 -0
- package/test/complex_imports.wasm +0 -0
- package/test/global_imports.wasm +0 -0
- package/test/import_func.wasm +0 -0
- package/test/imports.wasm +0 -0
- package/test/run.js +86 -0
- package/test/run.ts +90 -0
- package/test/sjlj.wasm +0 -0
- package/test/test_basic.js +7 -0
- package/test/test_basic.ts +9 -0
- package/test/test_brotli.js +48 -0
- package/test/test_brotli.ts +52 -0
- package/test/test_fetch_cache.js +131 -0
- package/test/test_fetch_cache.ts +141 -0
- package/test/test_ffi.js +157 -0
- package/test/test_ffi.ts +174 -0
- package/test/test_frame_encoding.js +128 -0
- package/test/test_frame_encoding.ts +132 -0
- package/test/test_helper.js +84 -0
- package/test/test_helper.ts +80 -0
- package/test/test_http_import.js +78 -0
- package/test/test_http_import.ts +74 -0
- package/test/test_mupdf_render.js +69 -0
- package/test/test_mupdf_render.ts +74 -0
- package/test/test_mupdf_twice.js +77 -0
- package/test/test_mupdf_twice.ts +81 -0
- package/test/test_mupdf_wasm.js +33 -0
- package/test/test_mupdf_wasm.ts +30 -0
- package/test/test_net_event.js +63 -0
- package/test/test_net_event.ts +59 -0
- package/test/test_net_fetch.js +153 -0
- package/test/test_net_fetch.ts +131 -0
- package/test/test_net_websocket.js +158 -0
- package/test/test_net_websocket.ts +144 -0
- package/test/test_polyfill.js +58 -0
- package/test/test_polyfill.ts +60 -0
- package/test/test_url.js +173 -0
- package/test/test_url.ts +183 -0
- package/test/test_wasm_basic.js +82 -0
- package/test/test_wasm_basic.ts +70 -0
- package/test/test_wasm_import_global.js +41 -0
- package/test/test_wasm_import_global.ts +39 -0
- package/test/test_wasm_sjlj.js +153 -0
- package/test/test_wasm_sjlj.ts +134 -0
- package/test/test_wasm_types.js +96 -0
- package/test/test_wasm_types.ts +108 -0
- package/test/types.wasm +0 -0
- package/tsconfig.json +18 -0
- package/vendor/mupdf-wasm/mupdf-wasm.d.ts +571 -0
- package/vendor/mupdf-wasm/mupdf-wasm.js +2749 -0
- package/vendor/mupdf-wasm/mupdf-wasm.wasm +0 -0
- package/vendor/mupdf-wasm/mupdf.d.ts +939 -0
- package/vendor/mupdf-wasm/mupdf.js +3317 -0
- package/win-mingw64.exe +0 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// Minimal Preact Hooks
|
|
2
|
+
// Based on https://github.com/preactjs/preact (hooks/src/index.js)
|
|
3
|
+
// DOM dependencies removed - for custom renderers only
|
|
4
|
+
import { options } from './preact.js';
|
|
5
|
+
const ObjectIs = Object.is;
|
|
6
|
+
let currentIndex;
|
|
7
|
+
let currentComponent = null;
|
|
8
|
+
let previousComponent = null;
|
|
9
|
+
let currentHook = 0 /* HookType.None */;
|
|
10
|
+
let afterPaintEffects = [];
|
|
11
|
+
let oldBeforeDiff = options._diff;
|
|
12
|
+
let oldBeforeRender = options._render;
|
|
13
|
+
let oldAfterDiff = options.diffed;
|
|
14
|
+
let oldCommit = options._commit;
|
|
15
|
+
let oldBeforeUnmount = options.unmount;
|
|
16
|
+
let oldRoot = options._root;
|
|
17
|
+
const RAF_TIMEOUT = 35;
|
|
18
|
+
let prevRaf;
|
|
19
|
+
options._diff = (vnode) => {
|
|
20
|
+
currentComponent = null;
|
|
21
|
+
if (oldBeforeDiff)
|
|
22
|
+
oldBeforeDiff(vnode);
|
|
23
|
+
};
|
|
24
|
+
options._root = (vnode, parentDom) => {
|
|
25
|
+
if (vnode && parentDom._children && parentDom._children._mask) {
|
|
26
|
+
vnode._mask = parentDom._children._mask;
|
|
27
|
+
}
|
|
28
|
+
if (oldRoot)
|
|
29
|
+
oldRoot(vnode, parentDom);
|
|
30
|
+
};
|
|
31
|
+
options._render = (vnode) => {
|
|
32
|
+
if (oldBeforeRender)
|
|
33
|
+
oldBeforeRender(vnode);
|
|
34
|
+
currentComponent = vnode._component;
|
|
35
|
+
currentIndex = 0;
|
|
36
|
+
const hooks = currentComponent.__hooks;
|
|
37
|
+
if (hooks) {
|
|
38
|
+
hooks._list.some((hookItem) => {
|
|
39
|
+
if (hookItem._nextValue) {
|
|
40
|
+
hookItem._value = hookItem._nextValue;
|
|
41
|
+
hookItem._nextValue = undefined;
|
|
42
|
+
}
|
|
43
|
+
hookItem._pendingArgs = undefined;
|
|
44
|
+
});
|
|
45
|
+
hooks._pendingEffects.some(invokeCleanup);
|
|
46
|
+
hooks._pendingEffects.some(invokeEffect);
|
|
47
|
+
hooks._pendingEffects = [];
|
|
48
|
+
currentIndex = 0;
|
|
49
|
+
}
|
|
50
|
+
previousComponent = currentComponent;
|
|
51
|
+
};
|
|
52
|
+
options.diffed = (vnode) => {
|
|
53
|
+
if (oldAfterDiff)
|
|
54
|
+
oldAfterDiff(vnode);
|
|
55
|
+
const c = vnode._component;
|
|
56
|
+
if (c && c.__hooks) {
|
|
57
|
+
if (c.__hooks._pendingEffects.length)
|
|
58
|
+
afterPaint(afterPaintEffects.push(c));
|
|
59
|
+
c.__hooks._list.some((hookItem) => {
|
|
60
|
+
if (hookItem._pendingArgs) {
|
|
61
|
+
hookItem._args = hookItem._pendingArgs;
|
|
62
|
+
}
|
|
63
|
+
hookItem._pendingArgs = undefined;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
previousComponent = currentComponent = null;
|
|
67
|
+
};
|
|
68
|
+
options._commit = (vnode, commitQueue) => {
|
|
69
|
+
commitQueue.some((component) => {
|
|
70
|
+
try {
|
|
71
|
+
component._renderCallbacks.some(invokeCleanup);
|
|
72
|
+
component._renderCallbacks = component._renderCallbacks.filter((cb) => cb._value ? invokeEffect(cb) : true);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
commitQueue.some((c) => {
|
|
76
|
+
if (c._renderCallbacks)
|
|
77
|
+
c._renderCallbacks = [];
|
|
78
|
+
});
|
|
79
|
+
commitQueue = [];
|
|
80
|
+
if (options._catchError)
|
|
81
|
+
options._catchError(e, component._vnode);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
if (oldCommit)
|
|
85
|
+
oldCommit(vnode, commitQueue);
|
|
86
|
+
};
|
|
87
|
+
options.unmount = (vnode) => {
|
|
88
|
+
if (oldBeforeUnmount)
|
|
89
|
+
oldBeforeUnmount(vnode);
|
|
90
|
+
const c = vnode._component;
|
|
91
|
+
if (c && c.__hooks) {
|
|
92
|
+
let hasErrored;
|
|
93
|
+
c.__hooks._list.some((s) => {
|
|
94
|
+
try {
|
|
95
|
+
invokeCleanup(s);
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
hasErrored = e;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
c.__hooks = null;
|
|
102
|
+
if (hasErrored && options._catchError)
|
|
103
|
+
options._catchError(hasErrored, c._vnode);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
function getHookState(index, type) {
|
|
107
|
+
if (options._hook) {
|
|
108
|
+
options._hook(currentComponent, index, currentHook || type);
|
|
109
|
+
}
|
|
110
|
+
currentHook = 0 /* HookType.None */;
|
|
111
|
+
const comp = currentComponent;
|
|
112
|
+
const hooks = comp.__hooks ||
|
|
113
|
+
(comp.__hooks = {
|
|
114
|
+
_list: [],
|
|
115
|
+
_pendingEffects: []
|
|
116
|
+
});
|
|
117
|
+
if (index >= hooks._list.length) {
|
|
118
|
+
hooks._list.push({});
|
|
119
|
+
}
|
|
120
|
+
return hooks._list[index];
|
|
121
|
+
}
|
|
122
|
+
export function useState(initialState) {
|
|
123
|
+
currentHook = 1 /* HookType.useState */;
|
|
124
|
+
return useReducer(invokeOrReturn, initialState);
|
|
125
|
+
}
|
|
126
|
+
export function useReducer(reducer, initialState, init) {
|
|
127
|
+
const hookState = getHookState(currentIndex++, 2 /* HookType.useReducer */);
|
|
128
|
+
hookState._reducer = reducer;
|
|
129
|
+
if (!hookState._component) {
|
|
130
|
+
hookState._value = [
|
|
131
|
+
!init ? invokeOrReturn(undefined, initialState) : init(initialState),
|
|
132
|
+
(action) => {
|
|
133
|
+
const currentValue = hookState._nextValue
|
|
134
|
+
? hookState._nextValue[0]
|
|
135
|
+
: hookState._value[0];
|
|
136
|
+
const nextValue = hookState._reducer(currentValue, action);
|
|
137
|
+
if (!ObjectIs(currentValue, nextValue)) {
|
|
138
|
+
hookState._nextValue = [nextValue, hookState._value[1]];
|
|
139
|
+
hookState._component._forceUpdate();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
];
|
|
143
|
+
hookState._component = currentComponent;
|
|
144
|
+
}
|
|
145
|
+
return hookState._value;
|
|
146
|
+
}
|
|
147
|
+
export function useEffect(callback, args) {
|
|
148
|
+
const state = getHookState(currentIndex++, 3 /* HookType.useEffect */);
|
|
149
|
+
if (!options._skipEffects && argsChanged(state._args, args)) {
|
|
150
|
+
state._value = callback;
|
|
151
|
+
state._pendingArgs = args;
|
|
152
|
+
currentComponent.__hooks._pendingEffects.push(state);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export function useLayoutEffect(callback, args) {
|
|
156
|
+
const state = getHookState(currentIndex++, 4 /* HookType.useLayoutEffect */);
|
|
157
|
+
if (!options._skipEffects && argsChanged(state._args, args)) {
|
|
158
|
+
state._value = callback;
|
|
159
|
+
state._pendingArgs = args;
|
|
160
|
+
currentComponent._renderCallbacks.push(state);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export function useRef(initialValue) {
|
|
164
|
+
currentHook = 5 /* HookType.useRef */;
|
|
165
|
+
return useMemo(() => ({ current: initialValue }), []);
|
|
166
|
+
}
|
|
167
|
+
export function useImperativeHandle(ref, createHandle, args) {
|
|
168
|
+
currentHook = 6 /* HookType.useImperativeHandle */;
|
|
169
|
+
useLayoutEffect(() => {
|
|
170
|
+
if (typeof ref === 'function') {
|
|
171
|
+
const result = ref(createHandle());
|
|
172
|
+
return () => {
|
|
173
|
+
ref(null);
|
|
174
|
+
if (result && typeof result === 'function')
|
|
175
|
+
result();
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
else if (ref) {
|
|
179
|
+
ref.current = createHandle();
|
|
180
|
+
return () => { ref.current = null; };
|
|
181
|
+
}
|
|
182
|
+
}, args == null ? args : args.concat(ref));
|
|
183
|
+
}
|
|
184
|
+
export function useMemo(factory, args) {
|
|
185
|
+
const state = getHookState(currentIndex++, 7 /* HookType.useMemo */);
|
|
186
|
+
if (argsChanged(state._args, args)) {
|
|
187
|
+
state._value = factory();
|
|
188
|
+
state._args = args;
|
|
189
|
+
state._factory = factory;
|
|
190
|
+
}
|
|
191
|
+
return state._value;
|
|
192
|
+
}
|
|
193
|
+
export function useCallback(callback, args) {
|
|
194
|
+
currentHook = 8 /* HookType.useCallback */;
|
|
195
|
+
return useMemo(() => callback, args);
|
|
196
|
+
}
|
|
197
|
+
export function useContext(context) {
|
|
198
|
+
const provider = currentComponent.context[context._id];
|
|
199
|
+
const state = getHookState(currentIndex++, 9 /* HookType.useContext */);
|
|
200
|
+
state._context = context;
|
|
201
|
+
if (!provider)
|
|
202
|
+
return context._defaultValue;
|
|
203
|
+
if (state._value == null) {
|
|
204
|
+
state._value = true;
|
|
205
|
+
provider.sub(currentComponent);
|
|
206
|
+
}
|
|
207
|
+
return provider.props.value;
|
|
208
|
+
}
|
|
209
|
+
export function useDebugValue(value, formatter) {
|
|
210
|
+
if (options.useDebugValue) {
|
|
211
|
+
options.useDebugValue(formatter ? formatter(value) : value);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
export function useErrorBoundary(cb) {
|
|
215
|
+
const state = getHookState(currentIndex++, 10 /* HookType.useErrorBoundary */);
|
|
216
|
+
const errState = useState();
|
|
217
|
+
state._value = cb;
|
|
218
|
+
if (!currentComponent._errorHandler) {
|
|
219
|
+
currentComponent._errorHandler = (err) => {
|
|
220
|
+
if (state._value)
|
|
221
|
+
state._value(err);
|
|
222
|
+
errState[1](err);
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return [errState[0], () => { errState[1](undefined); }];
|
|
226
|
+
}
|
|
227
|
+
export function useId() {
|
|
228
|
+
const state = getHookState(currentIndex++, 11 /* HookType.useId */);
|
|
229
|
+
if (!state._value) {
|
|
230
|
+
let root = currentComponent._vnode;
|
|
231
|
+
while (root !== null && !root._mask && root._parent !== null) {
|
|
232
|
+
root = root._parent;
|
|
233
|
+
}
|
|
234
|
+
let mask = root._mask || (root._mask = [0, 0]);
|
|
235
|
+
state._value = 'P' + mask[0] + '-' + mask[1]++;
|
|
236
|
+
}
|
|
237
|
+
return state._value;
|
|
238
|
+
}
|
|
239
|
+
function flushAfterPaintEffects() {
|
|
240
|
+
let component;
|
|
241
|
+
while ((component = afterPaintEffects.shift())) {
|
|
242
|
+
const hooks = component.__hooks;
|
|
243
|
+
if (!component._parentDom || !hooks)
|
|
244
|
+
continue;
|
|
245
|
+
try {
|
|
246
|
+
hooks._pendingEffects.some(invokeCleanup);
|
|
247
|
+
hooks._pendingEffects.some(invokeEffect);
|
|
248
|
+
hooks._pendingEffects = [];
|
|
249
|
+
}
|
|
250
|
+
catch (e) {
|
|
251
|
+
hooks._pendingEffects = [];
|
|
252
|
+
if (options._catchError)
|
|
253
|
+
options._catchError(e, component._vnode);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function afterNextFrame(callback) {
|
|
258
|
+
setTimeout(callback, RAF_TIMEOUT);
|
|
259
|
+
}
|
|
260
|
+
function afterPaint(newQueueLength) {
|
|
261
|
+
if (newQueueLength === 1 || prevRaf !== options.requestAnimationFrame) {
|
|
262
|
+
prevRaf = options.requestAnimationFrame;
|
|
263
|
+
(prevRaf || afterNextFrame)(flushAfterPaintEffects);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function invokeCleanup(hook) {
|
|
267
|
+
const comp = currentComponent;
|
|
268
|
+
let cleanup = hook._cleanup;
|
|
269
|
+
if (typeof cleanup === 'function') {
|
|
270
|
+
hook._cleanup = undefined;
|
|
271
|
+
cleanup();
|
|
272
|
+
}
|
|
273
|
+
currentComponent = comp;
|
|
274
|
+
}
|
|
275
|
+
function invokeEffect(hook) {
|
|
276
|
+
const comp = currentComponent;
|
|
277
|
+
hook._cleanup = hook._value();
|
|
278
|
+
currentComponent = comp;
|
|
279
|
+
}
|
|
280
|
+
function argsChanged(oldArgs, newArgs) {
|
|
281
|
+
return (!oldArgs ||
|
|
282
|
+
oldArgs.length !== newArgs.length ||
|
|
283
|
+
newArgs.some((arg, index) => !ObjectIs(arg, oldArgs[index])));
|
|
284
|
+
}
|
|
285
|
+
function invokeOrReturn(arg, f) {
|
|
286
|
+
return typeof f === 'function' ? f(arg) : f;
|
|
287
|
+
}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
// Minimal Preact Hooks
|
|
2
|
+
// Based on https://github.com/preactjs/preact (hooks/src/index.js)
|
|
3
|
+
// DOM dependencies removed - for custom renderers only
|
|
4
|
+
|
|
5
|
+
import { options, type VNode, type Component } from './preact.js'
|
|
6
|
+
|
|
7
|
+
const enum HookType {
|
|
8
|
+
None = 0,
|
|
9
|
+
useState = 1,
|
|
10
|
+
useReducer = 2,
|
|
11
|
+
useEffect = 3,
|
|
12
|
+
useLayoutEffect = 4,
|
|
13
|
+
useRef = 5,
|
|
14
|
+
useImperativeHandle = 6,
|
|
15
|
+
useMemo = 7,
|
|
16
|
+
useCallback = 8,
|
|
17
|
+
useContext = 9,
|
|
18
|
+
useErrorBoundary = 10,
|
|
19
|
+
useId = 11,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const ObjectIs = Object.is
|
|
23
|
+
|
|
24
|
+
let currentIndex: number
|
|
25
|
+
let currentComponent: Component | null = null
|
|
26
|
+
let previousComponent: Component | null = null
|
|
27
|
+
let currentHook = HookType.None
|
|
28
|
+
let afterPaintEffects: Component[] = []
|
|
29
|
+
|
|
30
|
+
let oldBeforeDiff = options._diff
|
|
31
|
+
let oldBeforeRender = options._render
|
|
32
|
+
let oldAfterDiff = options.diffed
|
|
33
|
+
let oldCommit = options._commit
|
|
34
|
+
let oldBeforeUnmount = options.unmount
|
|
35
|
+
let oldRoot = options._root
|
|
36
|
+
|
|
37
|
+
const RAF_TIMEOUT = 35
|
|
38
|
+
let prevRaf: any
|
|
39
|
+
|
|
40
|
+
options._diff = (vnode: VNode) => {
|
|
41
|
+
currentComponent = null
|
|
42
|
+
if (oldBeforeDiff) oldBeforeDiff(vnode)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
options._root = (vnode: VNode, parentDom: any) => {
|
|
46
|
+
if (vnode && parentDom._children && parentDom._children._mask) {
|
|
47
|
+
vnode._mask = parentDom._children._mask
|
|
48
|
+
}
|
|
49
|
+
if (oldRoot) oldRoot(vnode, parentDom)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
options._render = (vnode: VNode) => {
|
|
53
|
+
if (oldBeforeRender) oldBeforeRender(vnode)
|
|
54
|
+
currentComponent = vnode._component
|
|
55
|
+
currentIndex = 0
|
|
56
|
+
const hooks = currentComponent!.__hooks
|
|
57
|
+
if (hooks) {
|
|
58
|
+
hooks._list.some((hookItem: any) => {
|
|
59
|
+
if (hookItem._nextValue) {
|
|
60
|
+
hookItem._value = hookItem._nextValue
|
|
61
|
+
hookItem._nextValue = undefined
|
|
62
|
+
}
|
|
63
|
+
hookItem._pendingArgs = undefined
|
|
64
|
+
})
|
|
65
|
+
hooks._pendingEffects.some(invokeCleanup)
|
|
66
|
+
hooks._pendingEffects.some(invokeEffect)
|
|
67
|
+
hooks._pendingEffects = []
|
|
68
|
+
currentIndex = 0
|
|
69
|
+
}
|
|
70
|
+
previousComponent = currentComponent
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
options.diffed = (vnode: VNode) => {
|
|
74
|
+
if (oldAfterDiff) oldAfterDiff(vnode)
|
|
75
|
+
const c = vnode._component
|
|
76
|
+
if (c && c.__hooks) {
|
|
77
|
+
if (c.__hooks._pendingEffects.length) afterPaint(afterPaintEffects.push(c))
|
|
78
|
+
c.__hooks._list.some((hookItem: any) => {
|
|
79
|
+
if (hookItem._pendingArgs) {
|
|
80
|
+
hookItem._args = hookItem._pendingArgs
|
|
81
|
+
}
|
|
82
|
+
hookItem._pendingArgs = undefined
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
previousComponent = currentComponent = null
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
options._commit = (vnode: VNode, commitQueue: any[]) => {
|
|
89
|
+
commitQueue.some((component: any) => {
|
|
90
|
+
try {
|
|
91
|
+
component._renderCallbacks.some(invokeCleanup)
|
|
92
|
+
component._renderCallbacks = component._renderCallbacks.filter((cb: any) =>
|
|
93
|
+
cb._value ? invokeEffect(cb) : true
|
|
94
|
+
)
|
|
95
|
+
} catch (e) {
|
|
96
|
+
commitQueue.some((c: any) => {
|
|
97
|
+
if (c._renderCallbacks) c._renderCallbacks = []
|
|
98
|
+
})
|
|
99
|
+
commitQueue = []
|
|
100
|
+
if (options._catchError) options._catchError(e, component._vnode!)
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
if (oldCommit) oldCommit(vnode, commitQueue)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
options.unmount = (vnode: VNode) => {
|
|
107
|
+
if (oldBeforeUnmount) oldBeforeUnmount(vnode)
|
|
108
|
+
const c = vnode._component
|
|
109
|
+
if (c && c.__hooks) {
|
|
110
|
+
let hasErrored: any
|
|
111
|
+
c.__hooks._list.some((s: any) => {
|
|
112
|
+
try {
|
|
113
|
+
invokeCleanup(s)
|
|
114
|
+
} catch (e) {
|
|
115
|
+
hasErrored = e
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
c.__hooks = null as any
|
|
119
|
+
if (hasErrored && options._catchError) options._catchError(hasErrored, c._vnode!)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function getHookState(index: number, type: number): any {
|
|
124
|
+
if (options._hook) {
|
|
125
|
+
options._hook(currentComponent!, index, currentHook || type)
|
|
126
|
+
}
|
|
127
|
+
currentHook = HookType.None
|
|
128
|
+
const comp = currentComponent!
|
|
129
|
+
const hooks =
|
|
130
|
+
comp.__hooks ||
|
|
131
|
+
(comp.__hooks = {
|
|
132
|
+
_list: [],
|
|
133
|
+
_pendingEffects: []
|
|
134
|
+
})
|
|
135
|
+
if (index >= hooks._list.length) {
|
|
136
|
+
hooks._list.push({})
|
|
137
|
+
}
|
|
138
|
+
return hooks._list[index]
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function useState<S>(initialState?: S | (() => S)): [S, (state: S | ((prevState: S) => S)) => void] {
|
|
142
|
+
currentHook = HookType.useState
|
|
143
|
+
return useReducer(invokeOrReturn, initialState as S)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function useReducer<S, A>(
|
|
147
|
+
reducer: (state: S, action: A) => S,
|
|
148
|
+
initialState: S | (() => S),
|
|
149
|
+
init?: (initialState: any) => S
|
|
150
|
+
): [S, (action: A) => void] {
|
|
151
|
+
const hookState = getHookState(currentIndex++, HookType.useReducer)
|
|
152
|
+
hookState._reducer = reducer
|
|
153
|
+
if (!hookState._component) {
|
|
154
|
+
hookState._value = [
|
|
155
|
+
!init ? invokeOrReturn(undefined, initialState) : init(initialState),
|
|
156
|
+
(action: A) => {
|
|
157
|
+
const currentValue = hookState._nextValue
|
|
158
|
+
? hookState._nextValue[0]
|
|
159
|
+
: hookState._value[0]
|
|
160
|
+
const nextValue = hookState._reducer(currentValue, action)
|
|
161
|
+
if (!ObjectIs(currentValue, nextValue)) {
|
|
162
|
+
hookState._nextValue = [nextValue, hookState._value[1]]
|
|
163
|
+
hookState._component._forceUpdate()
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
hookState._component = currentComponent
|
|
168
|
+
}
|
|
169
|
+
return hookState._value
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function useEffect(callback: () => void | (() => void), args?: any[]): void {
|
|
173
|
+
const state = getHookState(currentIndex++, HookType.useEffect)
|
|
174
|
+
if (!options._skipEffects && argsChanged(state._args, args)) {
|
|
175
|
+
state._value = callback
|
|
176
|
+
state._pendingArgs = args
|
|
177
|
+
currentComponent!.__hooks!._pendingEffects.push(state)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function useLayoutEffect(callback: () => void | (() => void), args?: any[]): void {
|
|
182
|
+
const state = getHookState(currentIndex++, HookType.useLayoutEffect)
|
|
183
|
+
if (!options._skipEffects && argsChanged(state._args, args)) {
|
|
184
|
+
state._value = callback
|
|
185
|
+
state._pendingArgs = args
|
|
186
|
+
currentComponent!._renderCallbacks.push(state)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function useRef<T>(initialValue: T): { current: T } {
|
|
191
|
+
currentHook = HookType.useRef
|
|
192
|
+
return useMemo(() => ({ current: initialValue }), [])
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function useImperativeHandle<T>(
|
|
196
|
+
ref: any,
|
|
197
|
+
createHandle: () => T,
|
|
198
|
+
args?: any[]
|
|
199
|
+
): void {
|
|
200
|
+
currentHook = HookType.useImperativeHandle
|
|
201
|
+
useLayoutEffect(
|
|
202
|
+
() => {
|
|
203
|
+
if (typeof ref === 'function') {
|
|
204
|
+
const result = ref(createHandle())
|
|
205
|
+
return () => {
|
|
206
|
+
ref(null)
|
|
207
|
+
if (result && typeof result === 'function') result()
|
|
208
|
+
}
|
|
209
|
+
} else if (ref) {
|
|
210
|
+
ref.current = createHandle()
|
|
211
|
+
return () => { ref.current = null }
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
args == null ? args : args.concat(ref)
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function useMemo<T>(factory: () => T, args: any[]): T {
|
|
219
|
+
const state = getHookState(currentIndex++, HookType.useMemo)
|
|
220
|
+
if (argsChanged(state._args, args)) {
|
|
221
|
+
state._value = factory()
|
|
222
|
+
state._args = args
|
|
223
|
+
state._factory = factory
|
|
224
|
+
}
|
|
225
|
+
return state._value
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function useCallback<T extends (...args: any[]) => any>(callback: T, args: any[]): T {
|
|
229
|
+
currentHook = HookType.useCallback
|
|
230
|
+
return useMemo(() => callback, args)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function useContext<T>(context: any): T {
|
|
234
|
+
const provider: any = currentComponent!.context[context._id]
|
|
235
|
+
const state = getHookState(currentIndex++, HookType.useContext)
|
|
236
|
+
state._context = context
|
|
237
|
+
if (!provider) return context._defaultValue
|
|
238
|
+
if (state._value == null) {
|
|
239
|
+
state._value = true
|
|
240
|
+
provider.sub(currentComponent!)
|
|
241
|
+
}
|
|
242
|
+
return provider.props.value
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function useDebugValue<T>(value: T, formatter?: (value: T) => any): void {
|
|
246
|
+
if (options.useDebugValue) {
|
|
247
|
+
options.useDebugValue(formatter ? formatter(value) : value)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function useErrorBoundary(cb?: (error: any) => void): [any, () => void] {
|
|
252
|
+
const state = getHookState(currentIndex++, HookType.useErrorBoundary)
|
|
253
|
+
const errState = useState<any>()
|
|
254
|
+
state._value = cb
|
|
255
|
+
if (!(currentComponent! as any)._errorHandler) {
|
|
256
|
+
(currentComponent! as any)._errorHandler = (err: any) => {
|
|
257
|
+
if (state._value) state._value(err)
|
|
258
|
+
errState[1](err)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return [errState[0], () => { errState[1](undefined) }]
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function useId(): string {
|
|
265
|
+
const state = getHookState(currentIndex++, HookType.useId)
|
|
266
|
+
if (!state._value) {
|
|
267
|
+
let root: any = currentComponent!._vnode
|
|
268
|
+
while (root !== null && !root._mask && root._parent !== null) {
|
|
269
|
+
root = root._parent
|
|
270
|
+
}
|
|
271
|
+
let mask = root._mask || (root._mask = [0, 0])
|
|
272
|
+
state._value = 'P' + mask[0] + '-' + mask[1]++
|
|
273
|
+
}
|
|
274
|
+
return state._value
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function flushAfterPaintEffects() {
|
|
278
|
+
let component: Component | undefined
|
|
279
|
+
while ((component = afterPaintEffects.shift())) {
|
|
280
|
+
const hooks = component.__hooks
|
|
281
|
+
if (!component._parentDom || !hooks) continue
|
|
282
|
+
try {
|
|
283
|
+
hooks._pendingEffects.some(invokeCleanup)
|
|
284
|
+
hooks._pendingEffects.some(invokeEffect)
|
|
285
|
+
hooks._pendingEffects = []
|
|
286
|
+
} catch (e) {
|
|
287
|
+
hooks._pendingEffects = []
|
|
288
|
+
if (options._catchError) options._catchError(e, component._vnode!)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function afterNextFrame(callback: () => void) {
|
|
294
|
+
setTimeout(callback, RAF_TIMEOUT)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function afterPaint(newQueueLength: number) {
|
|
298
|
+
if (newQueueLength === 1 || prevRaf !== options.requestAnimationFrame) {
|
|
299
|
+
prevRaf = options.requestAnimationFrame
|
|
300
|
+
;(prevRaf || afterNextFrame)(flushAfterPaintEffects)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function invokeCleanup(hook: any) {
|
|
305
|
+
const comp = currentComponent
|
|
306
|
+
let cleanup = hook._cleanup
|
|
307
|
+
if (typeof cleanup === 'function') {
|
|
308
|
+
hook._cleanup = undefined
|
|
309
|
+
cleanup()
|
|
310
|
+
}
|
|
311
|
+
currentComponent = comp
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function invokeEffect(hook: any) {
|
|
315
|
+
const comp = currentComponent
|
|
316
|
+
hook._cleanup = hook._value()
|
|
317
|
+
currentComponent = comp
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function argsChanged(oldArgs: any[] | undefined, newArgs: any[] | undefined): boolean {
|
|
321
|
+
return (
|
|
322
|
+
!oldArgs ||
|
|
323
|
+
oldArgs.length !== newArgs!.length ||
|
|
324
|
+
newArgs!.some((arg, index) => !ObjectIs(arg, oldArgs[index]))
|
|
325
|
+
)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function invokeOrReturn<S>(arg: S, f: S | ((arg: S) => S)): S {
|
|
329
|
+
return typeof f === 'function' ? (f as (arg: S) => S)(arg) : f
|
|
330
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createElement as jsx, createElement as jsxs, Fragment, options } from './preact.js';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { VNode, ComponentChildren } from './preact.js'
|
|
2
|
+
import type { LayoutStyle } from './layout.js'
|
|
3
|
+
|
|
4
|
+
interface WEvent {
|
|
5
|
+
hwnd: number
|
|
6
|
+
msg: number
|
|
7
|
+
wParam: number
|
|
8
|
+
lParam: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface WIntrinsicProps {
|
|
12
|
+
type?: 'button' | 'edit' | 'static' | 'checkbox' | 'groupbox' | 'combobox' | 'listbox' | 'progressbar'
|
|
13
|
+
text?: string
|
|
14
|
+
value?: string
|
|
15
|
+
disabled?: boolean
|
|
16
|
+
visible?: boolean
|
|
17
|
+
style?: LayoutStyle
|
|
18
|
+
onEvent?: (e: WEvent) => void
|
|
19
|
+
placeholder?: string
|
|
20
|
+
password?: boolean
|
|
21
|
+
checked?: boolean
|
|
22
|
+
items?: string[]
|
|
23
|
+
max?: number
|
|
24
|
+
children?: ComponentChildren
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare global {
|
|
28
|
+
namespace JSX {
|
|
29
|
+
interface IntrinsicElements {
|
|
30
|
+
w: WIntrinsicProps
|
|
31
|
+
}
|
|
32
|
+
interface Element extends VNode {}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {}
|