@getforma/core 0.9.0 → 1.0.0
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 +20 -1
- package/dist/chunk-DCTOXHPF.cjs +399 -0
- package/dist/chunk-DCTOXHPF.cjs.map +1 -0
- package/dist/chunk-OUVOAYIO.js +359 -0
- package/dist/chunk-OUVOAYIO.js.map +1 -0
- package/dist/{chunk-YMIMKO4W.cjs → chunk-V732ZBCU.cjs} +119 -511
- package/dist/chunk-V732ZBCU.cjs.map +1 -0
- package/dist/{chunk-N522P3G6.js → chunk-VTPFK5TJ.js} +89 -442
- package/dist/chunk-VTPFK5TJ.js.map +1 -0
- package/dist/forma-runtime-csp.js +1 -1
- package/dist/forma-runtime.js +1 -1
- package/dist/formajs-runtime-hardened.global.js +1 -1
- package/dist/formajs-runtime-hardened.global.js.map +1 -1
- package/dist/formajs-runtime.global.js +1 -1
- package/dist/formajs-runtime.global.js.map +1 -1
- package/dist/formajs.global.js +1 -1
- package/dist/formajs.global.js.map +1 -1
- package/dist/http.cjs +225 -0
- package/dist/http.cjs.map +1 -0
- package/dist/http.d.cts +108 -0
- package/dist/http.d.ts +108 -0
- package/dist/http.js +220 -0
- package/dist/http.js.map +1 -0
- package/dist/index.cjs +71 -607
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -458
- package/dist/index.d.ts +4 -458
- package/dist/index.js +7 -523
- package/dist/index.js.map +1 -1
- package/dist/resource-Cd0cGOxS.d.ts +62 -0
- package/dist/resource-DK98lW5e.d.cts +62 -0
- package/dist/runtime-hardened.cjs +3 -111
- package/dist/runtime-hardened.cjs.map +1 -1
- package/dist/runtime-hardened.js +4 -112
- package/dist/runtime-hardened.js.map +1 -1
- package/dist/runtime.cjs +23 -22
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.js +2 -1
- package/dist/runtime.js.map +1 -1
- package/dist/server.cjs +179 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +217 -0
- package/dist/server.d.ts +217 -0
- package/dist/server.js +166 -0
- package/dist/server.js.map +1 -0
- package/dist/{signal-B4_wQJHs.d.cts → signal-YlS1kgfh.d.cts} +1 -1
- package/dist/{signal-B4_wQJHs.d.ts → signal-YlS1kgfh.d.ts} +1 -1
- package/dist/storage.cjs +151 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +77 -0
- package/dist/storage.d.ts +77 -0
- package/dist/storage.js +147 -0
- package/dist/storage.js.map +1 -0
- package/dist/tc39-compat.d.cts +1 -1
- package/dist/tc39-compat.d.ts +1 -1
- package/package.json +31 -1
- package/dist/chunk-N522P3G6.js.map +0 -1
- package/dist/chunk-YMIMKO4W.cjs.map +0 -1
|
@@ -1,358 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export { getBatchDepth, isComputed, isEffect, isEffectScope, isSignal, trigger } from 'alien-signals';
|
|
4
|
-
|
|
5
|
-
var currentRoot = null;
|
|
6
|
-
var rootStack = [];
|
|
7
|
-
function createRoot(fn) {
|
|
8
|
-
const scope = { disposers: [], scopeDispose: null };
|
|
9
|
-
rootStack.push(currentRoot);
|
|
10
|
-
currentRoot = scope;
|
|
11
|
-
const dispose = () => {
|
|
12
|
-
if (scope.scopeDispose) {
|
|
13
|
-
try {
|
|
14
|
-
scope.scopeDispose();
|
|
15
|
-
} catch {
|
|
16
|
-
}
|
|
17
|
-
scope.scopeDispose = null;
|
|
18
|
-
}
|
|
19
|
-
for (const d of scope.disposers) {
|
|
20
|
-
try {
|
|
21
|
-
d();
|
|
22
|
-
} catch {
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
scope.disposers.length = 0;
|
|
26
|
-
};
|
|
27
|
-
let result;
|
|
28
|
-
try {
|
|
29
|
-
scope.scopeDispose = effectScope(() => {
|
|
30
|
-
result = fn(dispose);
|
|
31
|
-
});
|
|
32
|
-
} finally {
|
|
33
|
-
currentRoot = rootStack.pop() ?? null;
|
|
34
|
-
}
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
function registerDisposer(dispose) {
|
|
38
|
-
if (currentRoot) {
|
|
39
|
-
currentRoot.disposers.push(dispose);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function hasActiveRoot() {
|
|
43
|
-
return currentRoot !== null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/reactive/cleanup.ts
|
|
47
|
-
var currentCleanupCollector = null;
|
|
48
|
-
function onCleanup(fn) {
|
|
49
|
-
currentCleanupCollector?.(fn);
|
|
50
|
-
}
|
|
51
|
-
function setCleanupCollector(collector) {
|
|
52
|
-
const prev = currentCleanupCollector;
|
|
53
|
-
currentCleanupCollector = collector;
|
|
54
|
-
return prev;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/reactive/dev.ts
|
|
58
|
-
var __DEV__ = typeof process !== "undefined" ? process.env?.NODE_ENV !== "production" : true;
|
|
59
|
-
var _errorHandler = null;
|
|
60
|
-
function onError(handler) {
|
|
61
|
-
_errorHandler = handler;
|
|
62
|
-
}
|
|
63
|
-
function reportError(error, source) {
|
|
64
|
-
if (_errorHandler) {
|
|
65
|
-
try {
|
|
66
|
-
_errorHandler(error, source ? { source } : {});
|
|
67
|
-
} catch {
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (__DEV__) {
|
|
71
|
-
console.error(`[forma] ${source ?? "Unknown"} error:`, error);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
var POOL_SIZE = 32;
|
|
75
|
-
var MAX_REENTRANT_RUNS = 100;
|
|
76
|
-
var pool = [];
|
|
77
|
-
for (let i = 0; i < POOL_SIZE; i++) pool.push([]);
|
|
78
|
-
var poolIdx = POOL_SIZE;
|
|
79
|
-
function acquireArray() {
|
|
80
|
-
if (poolIdx > 0) {
|
|
81
|
-
const arr = pool[--poolIdx];
|
|
82
|
-
arr.length = 0;
|
|
83
|
-
return arr;
|
|
84
|
-
}
|
|
85
|
-
return [];
|
|
86
|
-
}
|
|
87
|
-
function releaseArray(arr) {
|
|
88
|
-
arr.length = 0;
|
|
89
|
-
if (poolIdx < POOL_SIZE) {
|
|
90
|
-
pool[poolIdx++] = arr;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function runCleanup(fn) {
|
|
94
|
-
if (fn === void 0) return;
|
|
95
|
-
try {
|
|
96
|
-
fn();
|
|
97
|
-
} catch (e) {
|
|
98
|
-
reportError(e, "effect cleanup");
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
function runCleanups(bag) {
|
|
102
|
-
if (bag === void 0) return;
|
|
103
|
-
for (let i = 0; i < bag.length; i++) {
|
|
104
|
-
try {
|
|
105
|
-
bag[i]();
|
|
106
|
-
} catch (e) {
|
|
107
|
-
reportError(e, "effect cleanup");
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function internalEffect(fn) {
|
|
112
|
-
const dispose = effect(fn);
|
|
113
|
-
if (hasActiveRoot()) {
|
|
114
|
-
registerDisposer(dispose);
|
|
115
|
-
}
|
|
116
|
-
return dispose;
|
|
117
|
-
}
|
|
118
|
-
function createEffect(fn) {
|
|
119
|
-
const shouldRegister = hasActiveRoot();
|
|
120
|
-
let cleanup2;
|
|
121
|
-
let cleanupBag;
|
|
122
|
-
let nextCleanup;
|
|
123
|
-
let nextCleanupBag;
|
|
124
|
-
const addCleanup = (cb) => {
|
|
125
|
-
if (nextCleanupBag !== void 0) {
|
|
126
|
-
nextCleanupBag.push(cb);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
if (nextCleanup !== void 0) {
|
|
130
|
-
const bag = acquireArray();
|
|
131
|
-
bag.push(nextCleanup, cb);
|
|
132
|
-
nextCleanup = void 0;
|
|
133
|
-
nextCleanupBag = bag;
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
nextCleanup = cb;
|
|
137
|
-
};
|
|
138
|
-
let skipCleanupInfra = false;
|
|
139
|
-
let firstRun = true;
|
|
140
|
-
let running = false;
|
|
141
|
-
let rerunRequested = false;
|
|
142
|
-
const runOnce = () => {
|
|
143
|
-
if (cleanup2 !== void 0) {
|
|
144
|
-
runCleanup(cleanup2);
|
|
145
|
-
cleanup2 = void 0;
|
|
146
|
-
}
|
|
147
|
-
if (cleanupBag !== void 0) {
|
|
148
|
-
runCleanups(cleanupBag);
|
|
149
|
-
releaseArray(cleanupBag);
|
|
150
|
-
cleanupBag = void 0;
|
|
151
|
-
}
|
|
152
|
-
if (skipCleanupInfra) {
|
|
153
|
-
try {
|
|
154
|
-
fn();
|
|
155
|
-
} catch (e) {
|
|
156
|
-
reportError(e, "effect");
|
|
157
|
-
}
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
nextCleanup = void 0;
|
|
161
|
-
nextCleanupBag = void 0;
|
|
162
|
-
const prevCollector = setCleanupCollector(addCleanup);
|
|
163
|
-
try {
|
|
164
|
-
const result = fn();
|
|
165
|
-
if (typeof result === "function") {
|
|
166
|
-
addCleanup(result);
|
|
167
|
-
}
|
|
168
|
-
if (nextCleanup === void 0 && nextCleanupBag === void 0) {
|
|
169
|
-
if (firstRun) skipCleanupInfra = true;
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
if (nextCleanupBag !== void 0) {
|
|
173
|
-
cleanupBag = nextCleanupBag;
|
|
174
|
-
} else {
|
|
175
|
-
cleanup2 = nextCleanup;
|
|
176
|
-
}
|
|
177
|
-
} catch (e) {
|
|
178
|
-
reportError(e, "effect");
|
|
179
|
-
if (nextCleanupBag !== void 0) {
|
|
180
|
-
cleanupBag = nextCleanupBag;
|
|
181
|
-
} else {
|
|
182
|
-
cleanup2 = nextCleanup;
|
|
183
|
-
}
|
|
184
|
-
} finally {
|
|
185
|
-
setCleanupCollector(prevCollector);
|
|
186
|
-
firstRun = false;
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
const safeFn = () => {
|
|
190
|
-
if (running) {
|
|
191
|
-
rerunRequested = true;
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
running = true;
|
|
195
|
-
try {
|
|
196
|
-
let reentrantRuns = 0;
|
|
197
|
-
do {
|
|
198
|
-
rerunRequested = false;
|
|
199
|
-
runOnce();
|
|
200
|
-
if (rerunRequested) {
|
|
201
|
-
reentrantRuns++;
|
|
202
|
-
if (reentrantRuns >= MAX_REENTRANT_RUNS) {
|
|
203
|
-
reportError(
|
|
204
|
-
new Error(`createEffect exceeded ${MAX_REENTRANT_RUNS} re-entrant runs`),
|
|
205
|
-
"effect"
|
|
206
|
-
);
|
|
207
|
-
rerunRequested = false;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
} while (rerunRequested);
|
|
211
|
-
} finally {
|
|
212
|
-
running = false;
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
const dispose = effect(safeFn);
|
|
216
|
-
let disposed = false;
|
|
217
|
-
const wrappedDispose = () => {
|
|
218
|
-
if (disposed) return;
|
|
219
|
-
disposed = true;
|
|
220
|
-
dispose();
|
|
221
|
-
if (cleanup2 !== void 0) {
|
|
222
|
-
runCleanup(cleanup2);
|
|
223
|
-
cleanup2 = void 0;
|
|
224
|
-
}
|
|
225
|
-
if (cleanupBag !== void 0) {
|
|
226
|
-
runCleanups(cleanupBag);
|
|
227
|
-
releaseArray(cleanupBag);
|
|
228
|
-
cleanupBag = void 0;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
if (shouldRegister) {
|
|
232
|
-
registerDisposer(wrappedDispose);
|
|
233
|
-
}
|
|
234
|
-
return wrappedDispose;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// src/reactive/memo.ts
|
|
238
|
-
var createMemo = createComputed;
|
|
239
|
-
function batch(fn) {
|
|
240
|
-
startBatch();
|
|
241
|
-
try {
|
|
242
|
-
fn();
|
|
243
|
-
} finally {
|
|
244
|
-
endBatch();
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
function untrack(fn) {
|
|
248
|
-
const prev = setActiveSub(void 0);
|
|
249
|
-
try {
|
|
250
|
-
return fn();
|
|
251
|
-
} finally {
|
|
252
|
-
setActiveSub(prev);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// src/reactive/on.ts
|
|
257
|
-
function on(deps, fn, options) {
|
|
258
|
-
let prev;
|
|
259
|
-
let isFirst = true;
|
|
260
|
-
return () => {
|
|
261
|
-
const value2 = deps();
|
|
262
|
-
if (options?.defer && isFirst) {
|
|
263
|
-
isFirst = false;
|
|
264
|
-
prev = value2;
|
|
265
|
-
return void 0;
|
|
266
|
-
}
|
|
267
|
-
const result = untrack(() => fn(value2, prev));
|
|
268
|
-
prev = value2;
|
|
269
|
-
return result;
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// src/reactive/ref.ts
|
|
274
|
-
function createRef(initialValue) {
|
|
275
|
-
return { current: initialValue };
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// src/reactive/reducer.ts
|
|
279
|
-
function createReducer(reducer, initialState) {
|
|
280
|
-
const [state, setState] = createSignal(initialState);
|
|
281
|
-
const dispatch = (action) => {
|
|
282
|
-
setState((prev) => reducer(prev, action));
|
|
283
|
-
};
|
|
284
|
-
return [state, dispatch];
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// src/reactive/suspense-context.ts
|
|
288
|
-
var currentSuspenseContext = null;
|
|
289
|
-
var suspenseStack = [];
|
|
290
|
-
function pushSuspenseContext(ctx) {
|
|
291
|
-
suspenseStack.push(currentSuspenseContext);
|
|
292
|
-
currentSuspenseContext = ctx;
|
|
293
|
-
}
|
|
294
|
-
function popSuspenseContext() {
|
|
295
|
-
currentSuspenseContext = suspenseStack.pop() ?? null;
|
|
296
|
-
}
|
|
297
|
-
function getSuspenseContext() {
|
|
298
|
-
return currentSuspenseContext;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// src/reactive/resource.ts
|
|
302
|
-
function createResource(source, fetcher, options) {
|
|
303
|
-
const [data, setData] = createSignal(options?.initialValue);
|
|
304
|
-
const [loading, setLoading] = createSignal(false);
|
|
305
|
-
const [error, setError] = createSignal(void 0);
|
|
306
|
-
const suspenseCtx = getSuspenseContext();
|
|
307
|
-
let abortController = null;
|
|
308
|
-
let fetchVersion = 0;
|
|
309
|
-
const doFetch = () => {
|
|
310
|
-
const sourceValue = untrack(source);
|
|
311
|
-
if (abortController) {
|
|
312
|
-
abortController.abort();
|
|
313
|
-
}
|
|
314
|
-
const controller = new AbortController();
|
|
315
|
-
abortController = controller;
|
|
316
|
-
const version = ++fetchVersion;
|
|
317
|
-
const isLatest = () => version === fetchVersion;
|
|
318
|
-
let suspensePending = false;
|
|
319
|
-
if (suspenseCtx) {
|
|
320
|
-
suspenseCtx.increment();
|
|
321
|
-
suspensePending = true;
|
|
322
|
-
}
|
|
323
|
-
setLoading(true);
|
|
324
|
-
setError(void 0);
|
|
325
|
-
Promise.resolve(fetcher(sourceValue)).then((result) => {
|
|
326
|
-
if (isLatest() && !controller.signal.aborted) {
|
|
327
|
-
setData(() => result);
|
|
328
|
-
}
|
|
329
|
-
}).catch((err) => {
|
|
330
|
-
if (isLatest() && !controller.signal.aborted) {
|
|
331
|
-
if (err?.name !== "AbortError") {
|
|
332
|
-
setError(err);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}).finally(() => {
|
|
336
|
-
if (suspensePending) suspenseCtx?.decrement();
|
|
337
|
-
if (isLatest()) {
|
|
338
|
-
setLoading(false);
|
|
339
|
-
if (abortController === controller) {
|
|
340
|
-
abortController = null;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
};
|
|
345
|
-
internalEffect(() => {
|
|
346
|
-
source();
|
|
347
|
-
doFetch();
|
|
348
|
-
});
|
|
349
|
-
const resource = (() => data());
|
|
350
|
-
resource.loading = loading;
|
|
351
|
-
resource.error = error;
|
|
352
|
-
resource.refetch = doFetch;
|
|
353
|
-
resource.mutate = (value2) => setData(() => value2);
|
|
354
|
-
return resource;
|
|
355
|
-
}
|
|
1
|
+
import { internalEffect, createRoot, untrack, __DEV__ } from './chunk-OUVOAYIO.js';
|
|
2
|
+
import { createSignal } from './chunk-OZCHIVAZ.js';
|
|
356
3
|
|
|
357
4
|
// src/dom/element.ts
|
|
358
5
|
var Fragment = /* @__PURE__ */ Symbol.for("forma.fragment");
|
|
@@ -505,10 +152,10 @@ var DYNAMIC_CHILD_SYM = /* @__PURE__ */ Symbol.for("forma-dynamic-child");
|
|
|
505
152
|
function getCache(el) {
|
|
506
153
|
return el[CACHE_SYM] ?? (el[CACHE_SYM] = /* @__PURE__ */ Object.create(null));
|
|
507
154
|
}
|
|
508
|
-
function handleClass(el, _key,
|
|
509
|
-
if (typeof
|
|
155
|
+
function handleClass(el, _key, value) {
|
|
156
|
+
if (typeof value === "function") {
|
|
510
157
|
internalEffect(() => {
|
|
511
|
-
const v =
|
|
158
|
+
const v = value();
|
|
512
159
|
const cache = getCache(el);
|
|
513
160
|
if (cache["class"] === v) return;
|
|
514
161
|
cache["class"] = v;
|
|
@@ -520,20 +167,20 @@ function handleClass(el, _key, value2) {
|
|
|
520
167
|
});
|
|
521
168
|
} else {
|
|
522
169
|
const cache = getCache(el);
|
|
523
|
-
if (cache["class"] ===
|
|
524
|
-
cache["class"] =
|
|
170
|
+
if (cache["class"] === value) return;
|
|
171
|
+
cache["class"] = value;
|
|
525
172
|
if (el instanceof HTMLElement) {
|
|
526
|
-
el.className =
|
|
173
|
+
el.className = value;
|
|
527
174
|
} else {
|
|
528
|
-
el.setAttribute("class",
|
|
175
|
+
el.setAttribute("class", value);
|
|
529
176
|
}
|
|
530
177
|
}
|
|
531
178
|
}
|
|
532
|
-
function handleStyle(el, _key,
|
|
533
|
-
if (typeof
|
|
179
|
+
function handleStyle(el, _key, value) {
|
|
180
|
+
if (typeof value === "function") {
|
|
534
181
|
let prevKeys = [];
|
|
535
182
|
internalEffect(() => {
|
|
536
|
-
const v =
|
|
183
|
+
const v = value();
|
|
537
184
|
if (typeof v === "string") {
|
|
538
185
|
const cache = getCache(el);
|
|
539
186
|
if (cache["style"] === v) return;
|
|
@@ -552,27 +199,27 @@ function handleStyle(el, _key, value2) {
|
|
|
552
199
|
prevKeys = nextKeys;
|
|
553
200
|
}
|
|
554
201
|
});
|
|
555
|
-
} else if (typeof
|
|
202
|
+
} else if (typeof value === "string") {
|
|
556
203
|
const cache = getCache(el);
|
|
557
|
-
if (cache["style"] ===
|
|
558
|
-
cache["style"] =
|
|
559
|
-
el.style.cssText =
|
|
560
|
-
} else if (
|
|
561
|
-
Object.assign(el.style,
|
|
204
|
+
if (cache["style"] === value) return;
|
|
205
|
+
cache["style"] = value;
|
|
206
|
+
el.style.cssText = value;
|
|
207
|
+
} else if (value && typeof value === "object") {
|
|
208
|
+
Object.assign(el.style, value);
|
|
562
209
|
}
|
|
563
210
|
}
|
|
564
|
-
function handleEvent(el, key,
|
|
211
|
+
function handleEvent(el, key, value) {
|
|
565
212
|
const controller = getAbortController(el);
|
|
566
213
|
el.addEventListener(
|
|
567
214
|
eventName(key),
|
|
568
|
-
|
|
215
|
+
value,
|
|
569
216
|
{ signal: controller.signal }
|
|
570
217
|
);
|
|
571
218
|
}
|
|
572
|
-
function handleInnerHTML(el, _key,
|
|
573
|
-
if (typeof
|
|
219
|
+
function handleInnerHTML(el, _key, value) {
|
|
220
|
+
if (typeof value === "function") {
|
|
574
221
|
internalEffect(() => {
|
|
575
|
-
const resolved =
|
|
222
|
+
const resolved = value();
|
|
576
223
|
if (resolved == null) {
|
|
577
224
|
el.innerHTML = "";
|
|
578
225
|
return;
|
|
@@ -594,16 +241,16 @@ function handleInnerHTML(el, _key, value2) {
|
|
|
594
241
|
el.innerHTML = html;
|
|
595
242
|
});
|
|
596
243
|
} else {
|
|
597
|
-
if (
|
|
244
|
+
if (value == null) {
|
|
598
245
|
el.innerHTML = "";
|
|
599
246
|
return;
|
|
600
247
|
}
|
|
601
|
-
if (typeof
|
|
248
|
+
if (typeof value !== "object" || !("__html" in value)) {
|
|
602
249
|
throw new TypeError(
|
|
603
|
-
"dangerouslySetInnerHTML: expected { __html: string }, got " + typeof
|
|
250
|
+
"dangerouslySetInnerHTML: expected { __html: string }, got " + typeof value
|
|
604
251
|
);
|
|
605
252
|
}
|
|
606
|
-
const html =
|
|
253
|
+
const html = value.__html;
|
|
607
254
|
if (typeof html !== "string") {
|
|
608
255
|
throw new TypeError(
|
|
609
256
|
"dangerouslySetInnerHTML: __html must be a string, got " + typeof html
|
|
@@ -612,11 +259,11 @@ function handleInnerHTML(el, _key, value2) {
|
|
|
612
259
|
el.innerHTML = html;
|
|
613
260
|
}
|
|
614
261
|
}
|
|
615
|
-
function handleXLink(el, key,
|
|
262
|
+
function handleXLink(el, key, value) {
|
|
616
263
|
const localName = key.slice(6);
|
|
617
|
-
if (typeof
|
|
264
|
+
if (typeof value === "function") {
|
|
618
265
|
internalEffect(() => {
|
|
619
|
-
const v =
|
|
266
|
+
const v = value();
|
|
620
267
|
if (v == null || v === false) {
|
|
621
268
|
el.removeAttributeNS(XLINK_NS, localName);
|
|
622
269
|
} else {
|
|
@@ -624,17 +271,17 @@ function handleXLink(el, key, value2) {
|
|
|
624
271
|
}
|
|
625
272
|
});
|
|
626
273
|
} else {
|
|
627
|
-
if (
|
|
274
|
+
if (value == null || value === false) {
|
|
628
275
|
el.removeAttributeNS(XLINK_NS, localName);
|
|
629
276
|
} else {
|
|
630
|
-
el.setAttributeNS(XLINK_NS, key, String(
|
|
277
|
+
el.setAttributeNS(XLINK_NS, key, String(value));
|
|
631
278
|
}
|
|
632
279
|
}
|
|
633
280
|
}
|
|
634
|
-
function handleBooleanAttr(el, key,
|
|
635
|
-
if (typeof
|
|
281
|
+
function handleBooleanAttr(el, key, value) {
|
|
282
|
+
if (typeof value === "function") {
|
|
636
283
|
internalEffect(() => {
|
|
637
|
-
const v =
|
|
284
|
+
const v = value();
|
|
638
285
|
const cache = getCache(el);
|
|
639
286
|
if (cache[key] === v) return;
|
|
640
287
|
cache[key] = v;
|
|
@@ -646,19 +293,19 @@ function handleBooleanAttr(el, key, value2) {
|
|
|
646
293
|
});
|
|
647
294
|
} else {
|
|
648
295
|
const cache = getCache(el);
|
|
649
|
-
if (cache[key] ===
|
|
650
|
-
cache[key] =
|
|
651
|
-
if (
|
|
296
|
+
if (cache[key] === value) return;
|
|
297
|
+
cache[key] = value;
|
|
298
|
+
if (value) {
|
|
652
299
|
el.setAttribute(key, "");
|
|
653
300
|
} else {
|
|
654
301
|
el.removeAttribute(key);
|
|
655
302
|
}
|
|
656
303
|
}
|
|
657
304
|
}
|
|
658
|
-
function handleGenericAttr(el, key,
|
|
659
|
-
if (typeof
|
|
305
|
+
function handleGenericAttr(el, key, value) {
|
|
306
|
+
if (typeof value === "function") {
|
|
660
307
|
internalEffect(() => {
|
|
661
|
-
const v =
|
|
308
|
+
const v = value();
|
|
662
309
|
if (v == null || v === false) {
|
|
663
310
|
const cache = getCache(el);
|
|
664
311
|
if (cache[key] === null) return;
|
|
@@ -673,13 +320,13 @@ function handleGenericAttr(el, key, value2) {
|
|
|
673
320
|
}
|
|
674
321
|
});
|
|
675
322
|
} else {
|
|
676
|
-
if (
|
|
323
|
+
if (value == null || value === false) {
|
|
677
324
|
const cache = getCache(el);
|
|
678
325
|
if (cache[key] === null) return;
|
|
679
326
|
cache[key] = null;
|
|
680
327
|
el.removeAttribute(key);
|
|
681
328
|
} else {
|
|
682
|
-
const strVal = String(
|
|
329
|
+
const strVal = String(value);
|
|
683
330
|
const cache = getCache(el);
|
|
684
331
|
if (cache[key] === strVal) return;
|
|
685
332
|
cache[key] = strVal;
|
|
@@ -697,47 +344,47 @@ PROP_HANDLERS.set("dangerouslySetInnerHTML", handleInnerHTML);
|
|
|
697
344
|
for (const attr of BOOLEAN_ATTRS) {
|
|
698
345
|
PROP_HANDLERS.set(attr, handleBooleanAttr);
|
|
699
346
|
}
|
|
700
|
-
function applyProp(el, key,
|
|
347
|
+
function applyProp(el, key, value) {
|
|
701
348
|
if (key === "class") {
|
|
702
|
-
handleClass(el, key,
|
|
349
|
+
handleClass(el, key, value);
|
|
703
350
|
return;
|
|
704
351
|
}
|
|
705
352
|
if (key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key.length > 2) {
|
|
706
|
-
handleEvent(el, key,
|
|
353
|
+
handleEvent(el, key, value);
|
|
707
354
|
return;
|
|
708
355
|
}
|
|
709
356
|
const handler = PROP_HANDLERS.get(key);
|
|
710
357
|
if (handler) {
|
|
711
|
-
handler(el, key,
|
|
358
|
+
handler(el, key, value);
|
|
712
359
|
return;
|
|
713
360
|
}
|
|
714
361
|
if (key.charCodeAt(0) === 120 && key.startsWith("xlink:")) {
|
|
715
|
-
handleXLink(el, key,
|
|
362
|
+
handleXLink(el, key, value);
|
|
716
363
|
return;
|
|
717
364
|
}
|
|
718
|
-
handleGenericAttr(el, key,
|
|
365
|
+
handleGenericAttr(el, key, value);
|
|
719
366
|
}
|
|
720
|
-
function applyStaticProp(el, key,
|
|
721
|
-
if (
|
|
367
|
+
function applyStaticProp(el, key, value) {
|
|
368
|
+
if (value == null || value === false) return;
|
|
722
369
|
if (key === "class" || key === "className") {
|
|
723
|
-
el.className =
|
|
370
|
+
el.className = value;
|
|
724
371
|
return;
|
|
725
372
|
}
|
|
726
373
|
if (key === "style") {
|
|
727
|
-
if (typeof
|
|
728
|
-
el.style.cssText =
|
|
729
|
-
} else if (
|
|
730
|
-
Object.assign(el.style,
|
|
374
|
+
if (typeof value === "string") {
|
|
375
|
+
el.style.cssText = value;
|
|
376
|
+
} else if (value && typeof value === "object") {
|
|
377
|
+
Object.assign(el.style, value);
|
|
731
378
|
}
|
|
732
379
|
return;
|
|
733
380
|
}
|
|
734
381
|
if (key === "dangerouslySetInnerHTML") {
|
|
735
|
-
if (typeof
|
|
382
|
+
if (typeof value !== "object" || !("__html" in value)) {
|
|
736
383
|
throw new TypeError(
|
|
737
|
-
"dangerouslySetInnerHTML: expected { __html: string }, got " + typeof
|
|
384
|
+
"dangerouslySetInnerHTML: expected { __html: string }, got " + typeof value
|
|
738
385
|
);
|
|
739
386
|
}
|
|
740
|
-
const html =
|
|
387
|
+
const html = value.__html;
|
|
741
388
|
if (typeof html !== "string") {
|
|
742
389
|
throw new TypeError(
|
|
743
390
|
"dangerouslySetInnerHTML: __html must be a string, got " + typeof html
|
|
@@ -747,17 +394,17 @@ function applyStaticProp(el, key, value2) {
|
|
|
747
394
|
return;
|
|
748
395
|
}
|
|
749
396
|
if (key.charCodeAt(0) === 120 && key.startsWith("xlink:")) {
|
|
750
|
-
el.setAttributeNS(XLINK_NS, key, String(
|
|
397
|
+
el.setAttributeNS(XLINK_NS, key, String(value));
|
|
751
398
|
return;
|
|
752
399
|
}
|
|
753
400
|
if (BOOLEAN_ATTRS.has(key)) {
|
|
754
|
-
if (
|
|
401
|
+
if (value) el.setAttribute(key, "");
|
|
755
402
|
return;
|
|
756
403
|
}
|
|
757
|
-
if (
|
|
404
|
+
if (value === true) {
|
|
758
405
|
el.setAttribute(key, "");
|
|
759
406
|
} else {
|
|
760
|
-
el.setAttribute(key, String(
|
|
407
|
+
el.setAttribute(key, String(value));
|
|
761
408
|
}
|
|
762
409
|
}
|
|
763
410
|
function appendChild(parent, child) {
|
|
@@ -841,20 +488,20 @@ function h(tag, props, ...children) {
|
|
|
841
488
|
let hasDynamic = false;
|
|
842
489
|
for (const key in props) {
|
|
843
490
|
if (key === "ref") continue;
|
|
844
|
-
const
|
|
491
|
+
const value = props[key];
|
|
845
492
|
if (key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key.length > 2) {
|
|
846
|
-
handleEvent(el, key,
|
|
493
|
+
handleEvent(el, key, value);
|
|
847
494
|
continue;
|
|
848
495
|
}
|
|
849
|
-
if (typeof
|
|
496
|
+
if (typeof value === "function") {
|
|
850
497
|
if (!hasDynamic) {
|
|
851
498
|
el[CACHE_SYM] = /* @__PURE__ */ Object.create(null);
|
|
852
499
|
hasDynamic = true;
|
|
853
500
|
}
|
|
854
|
-
applyProp(el, key,
|
|
501
|
+
applyProp(el, key, value);
|
|
855
502
|
continue;
|
|
856
503
|
}
|
|
857
|
-
applyStaticProp(el, key,
|
|
504
|
+
applyStaticProp(el, key, value);
|
|
858
505
|
}
|
|
859
506
|
}
|
|
860
507
|
const childLen = children.length;
|
|
@@ -962,8 +609,8 @@ function createShow(when, thenFn, elseFn) {
|
|
|
962
609
|
// src/dom/hydrate.ts
|
|
963
610
|
var ABORT_SYM2 = /* @__PURE__ */ Symbol.for("forma-abort");
|
|
964
611
|
var hydrating = false;
|
|
965
|
-
function setHydrating(
|
|
966
|
-
hydrating =
|
|
612
|
+
function setHydrating(value) {
|
|
613
|
+
hydrating = value;
|
|
967
614
|
}
|
|
968
615
|
function isDescriptor(v) {
|
|
969
616
|
return v != null && typeof v === "object" && "type" in v && v.type === "element";
|
|
@@ -977,18 +624,18 @@ function isListDescriptor(v) {
|
|
|
977
624
|
function applyDynamicProps(el, props) {
|
|
978
625
|
if (!props) return;
|
|
979
626
|
for (const key in props) {
|
|
980
|
-
const
|
|
981
|
-
if (typeof
|
|
627
|
+
const value = props[key];
|
|
628
|
+
if (typeof value !== "function") continue;
|
|
982
629
|
if (key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key.length > 2) {
|
|
983
630
|
let ac = el[ABORT_SYM2];
|
|
984
631
|
if (!ac) {
|
|
985
632
|
ac = new AbortController();
|
|
986
633
|
el[ABORT_SYM2] = ac;
|
|
987
634
|
}
|
|
988
|
-
el.addEventListener(key.slice(2).toLowerCase(),
|
|
635
|
+
el.addEventListener(key.slice(2).toLowerCase(), value, { signal: ac.signal });
|
|
989
636
|
continue;
|
|
990
637
|
}
|
|
991
|
-
const fn =
|
|
638
|
+
const fn = value;
|
|
992
639
|
const attrKey = key;
|
|
993
640
|
internalEffect(() => {
|
|
994
641
|
const v = fn();
|
|
@@ -1002,30 +649,30 @@ function applyDynamicProps(el, props) {
|
|
|
1002
649
|
});
|
|
1003
650
|
}
|
|
1004
651
|
}
|
|
1005
|
-
function ensureNode(
|
|
1006
|
-
if (
|
|
1007
|
-
if (
|
|
1008
|
-
if (typeof
|
|
1009
|
-
if (typeof
|
|
1010
|
-
if (isDescriptor(
|
|
1011
|
-
if (isShowDescriptor(
|
|
652
|
+
function ensureNode(value) {
|
|
653
|
+
if (value instanceof Node) return value;
|
|
654
|
+
if (value == null || value === false || value === true) return null;
|
|
655
|
+
if (typeof value === "string") return new Text(value);
|
|
656
|
+
if (typeof value === "number") return new Text(String(value));
|
|
657
|
+
if (isDescriptor(value)) return descriptorToElement(value);
|
|
658
|
+
if (isShowDescriptor(value)) {
|
|
1012
659
|
const prevH = hydrating;
|
|
1013
660
|
hydrating = false;
|
|
1014
661
|
try {
|
|
1015
662
|
return createShow(
|
|
1016
|
-
|
|
1017
|
-
() => ensureNode(
|
|
1018
|
-
|
|
663
|
+
value.condition,
|
|
664
|
+
() => ensureNode(value.whenTrue()) ?? document.createComment("empty"),
|
|
665
|
+
value.whenFalse ? () => ensureNode(value.whenFalse()) ?? document.createComment("empty") : void 0
|
|
1019
666
|
);
|
|
1020
667
|
} finally {
|
|
1021
668
|
hydrating = prevH;
|
|
1022
669
|
}
|
|
1023
670
|
}
|
|
1024
|
-
if (isListDescriptor(
|
|
671
|
+
if (isListDescriptor(value)) {
|
|
1025
672
|
const prevH = hydrating;
|
|
1026
673
|
hydrating = false;
|
|
1027
674
|
try {
|
|
1028
|
-
return createList(
|
|
675
|
+
return createList(value.items, value.keyFn, value.renderFn, value.options);
|
|
1029
676
|
} finally {
|
|
1030
677
|
hydrating = prevH;
|
|
1031
678
|
}
|
|
@@ -1822,6 +1469,6 @@ function createList(items, keyFn, renderFn, options) {
|
|
|
1822
1469
|
return fragment2;
|
|
1823
1470
|
}
|
|
1824
1471
|
|
|
1825
|
-
export { Fragment,
|
|
1826
|
-
//# sourceMappingURL=chunk-
|
|
1827
|
-
//# sourceMappingURL=chunk-
|
|
1472
|
+
export { Fragment, cleanup, createList, createShow, fragment, h, hydrateIsland, reconcileList };
|
|
1473
|
+
//# sourceMappingURL=chunk-VTPFK5TJ.js.map
|
|
1474
|
+
//# sourceMappingURL=chunk-VTPFK5TJ.js.map
|