sibujs 1.2.0 → 1.4.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 +29 -25
- package/dist/browser.cjs +804 -2
- package/dist/browser.d.cts +591 -1
- package/dist/browser.d.ts +591 -1
- package/dist/browser.js +50 -8
- package/dist/build.cjs +655 -237
- package/dist/build.js +15 -93
- package/dist/cdn.global.js +188 -7
- package/dist/chunk-2BYQDGN3.js +742 -0
- package/dist/chunk-32DY64NT.js +282 -0
- package/dist/chunk-3AIRKM3B.js +1263 -0
- package/dist/chunk-3X2YG6YM.js +505 -0
- package/dist/chunk-5X6PP2UK.js +28 -0
- package/dist/chunk-77L6NL3X.js +1097 -0
- package/dist/chunk-BGN5ZMP4.js +26 -0
- package/dist/chunk-BTU3TJDS.js +365 -0
- package/dist/chunk-CHF5OHIA.js +61 -0
- package/dist/chunk-CMBFNA7L.js +27 -0
- package/dist/chunk-CNZ35WI2.js +178 -0
- package/dist/chunk-DAHRH4ON.js +331 -0
- package/dist/chunk-EBGIRKQY.js +616 -0
- package/dist/chunk-EUZND3CB.js +27 -0
- package/dist/chunk-F3FA4F32.js +292 -0
- package/dist/chunk-JAKHTMQU.js +1000 -0
- package/dist/chunk-JCI5M6U6.js +956 -0
- package/dist/chunk-KQPDEVVS.js +398 -0
- package/dist/chunk-M4NLBH4I.js +725 -0
- package/dist/chunk-NEKUBFPT.js +60 -0
- package/dist/chunk-NYVAC6P5.js +37 -0
- package/dist/chunk-PTQJDMRT.js +146 -0
- package/dist/chunk-QWZG56ET.js +2744 -0
- package/dist/chunk-TSOKIX5Z.js +654 -0
- package/dist/chunk-UHNL42EF.js +2730 -0
- package/dist/chunk-VRW3FULF.js +725 -0
- package/dist/chunk-WZSPOOER.js +84 -0
- package/dist/chunk-YT6HQ6AM.js +14 -0
- package/dist/chunk-ZD6OAMTH.js +277 -0
- package/dist/chunk-ZWKZCBO6.js +317 -0
- package/dist/contracts-DDrwxvJ-.d.cts +245 -0
- package/dist/contracts-DDrwxvJ-.d.ts +245 -0
- package/dist/contracts-xo5ckdRP.d.cts +240 -0
- package/dist/contracts-xo5ckdRP.d.ts +240 -0
- package/dist/data.cjs +35 -2
- package/dist/data.d.cts +7 -0
- package/dist/data.d.ts +7 -0
- package/dist/data.js +9 -8
- package/dist/devtools.cjs +122 -0
- package/dist/devtools.d.cts +69 -461
- package/dist/devtools.d.ts +69 -461
- package/dist/devtools.js +127 -6
- package/dist/ecosystem.cjs +23 -6
- package/dist/ecosystem.d.cts +1 -1
- package/dist/ecosystem.d.ts +1 -1
- package/dist/ecosystem.js +10 -9
- package/dist/extras.cjs +1208 -88
- package/dist/extras.d.cts +6 -6
- package/dist/extras.d.ts +6 -6
- package/dist/extras.js +70 -33
- package/dist/index.cjs +663 -158
- package/dist/index.d.cts +398 -40
- package/dist/index.d.ts +398 -40
- package/dist/index.js +39 -21
- package/dist/introspect-BumjnBKr.d.cts +477 -0
- package/dist/introspect-CZrlcaYy.d.ts +477 -0
- package/dist/introspect-Cb0zgpi2.d.cts +477 -0
- package/dist/introspect-Y2xNXGSf.d.ts +477 -0
- package/dist/motion.js +4 -4
- package/dist/patterns.cjs +51 -24
- package/dist/patterns.d.cts +19 -57
- package/dist/patterns.d.ts +19 -57
- package/dist/patterns.js +8 -16
- package/dist/performance.js +4 -4
- package/dist/plugins.cjs +429 -82
- package/dist/plugins.d.cts +27 -4
- package/dist/plugins.d.ts +27 -4
- package/dist/plugins.js +156 -37
- package/dist/ssr-4PBXAOO3.js +40 -0
- package/dist/ssr-Do_SiVoL.d.cts +201 -0
- package/dist/ssr-Do_SiVoL.d.ts +201 -0
- package/dist/ssr.cjs +312 -60
- package/dist/ssr.d.cts +10 -1
- package/dist/ssr.d.ts +10 -1
- package/dist/ssr.js +13 -10
- package/dist/tagFactory-DaJ0YWX6.d.cts +47 -0
- package/dist/tagFactory-DaJ0YWX6.d.ts +47 -0
- package/dist/testing.cjs +233 -2
- package/dist/testing.d.cts +42 -1
- package/dist/testing.d.ts +42 -1
- package/dist/testing.js +129 -2
- package/dist/ui.cjs +374 -8
- package/dist/ui.d.cts +252 -2
- package/dist/ui.d.ts +252 -2
- package/dist/ui.js +329 -11
- package/dist/widgets.js +7 -7
- package/package.json +1 -1
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import {
|
|
2
|
+
derived
|
|
3
|
+
} from "./chunk-NEKUBFPT.js";
|
|
4
|
+
import {
|
|
5
|
+
effect
|
|
6
|
+
} from "./chunk-CHF5OHIA.js";
|
|
7
|
+
import {
|
|
8
|
+
signal
|
|
9
|
+
} from "./chunk-WZSPOOER.js";
|
|
10
|
+
|
|
11
|
+
// src/patterns/machine.ts
|
|
12
|
+
function machine(config) {
|
|
13
|
+
const [state, setState] = signal(config.initial);
|
|
14
|
+
const [context, setContext] = signal(config.context || {});
|
|
15
|
+
const initialDef = config.states[config.initial];
|
|
16
|
+
if (initialDef?.entry) {
|
|
17
|
+
initialDef.entry(context());
|
|
18
|
+
}
|
|
19
|
+
function send(event) {
|
|
20
|
+
const currentState = state();
|
|
21
|
+
const stateDef = config.states[currentState];
|
|
22
|
+
if (!stateDef?.on) return;
|
|
23
|
+
const transition = stateDef.on[event];
|
|
24
|
+
if (!transition) return;
|
|
25
|
+
let target;
|
|
26
|
+
let guard;
|
|
27
|
+
let action;
|
|
28
|
+
if (typeof transition === "string") {
|
|
29
|
+
target = transition;
|
|
30
|
+
} else {
|
|
31
|
+
target = transition.target;
|
|
32
|
+
guard = transition.guard;
|
|
33
|
+
action = transition.action;
|
|
34
|
+
}
|
|
35
|
+
const ctx = context();
|
|
36
|
+
if (guard && !guard(ctx)) return;
|
|
37
|
+
if (stateDef.exit) {
|
|
38
|
+
stateDef.exit(ctx);
|
|
39
|
+
}
|
|
40
|
+
if (action) {
|
|
41
|
+
const rawPatch = action(ctx);
|
|
42
|
+
const next = { ...ctx };
|
|
43
|
+
for (const key of Object.keys(rawPatch)) {
|
|
44
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
|
|
45
|
+
next[key] = rawPatch[key];
|
|
46
|
+
}
|
|
47
|
+
setContext(next);
|
|
48
|
+
}
|
|
49
|
+
setState(target);
|
|
50
|
+
const targetDef = config.states[target];
|
|
51
|
+
if (targetDef?.entry) {
|
|
52
|
+
targetDef.entry(context());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function matches(s) {
|
|
56
|
+
return state() === s;
|
|
57
|
+
}
|
|
58
|
+
function can(event) {
|
|
59
|
+
const currentState = state();
|
|
60
|
+
const stateDef = config.states[currentState];
|
|
61
|
+
if (!stateDef?.on) return false;
|
|
62
|
+
const transition = stateDef.on[event];
|
|
63
|
+
if (!transition) return false;
|
|
64
|
+
if (typeof transition === "string") return true;
|
|
65
|
+
if (transition.guard) {
|
|
66
|
+
return transition.guard(context());
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return { state, context, send, matches, can };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/patterns/persist.ts
|
|
74
|
+
function persisted(key, initial, options = {}) {
|
|
75
|
+
const storage = options.session ? sessionStorage : localStorage;
|
|
76
|
+
const serialize = options.serialize || JSON.stringify;
|
|
77
|
+
const deserialize = options.deserialize || JSON.parse;
|
|
78
|
+
const encrypt = options.encrypt;
|
|
79
|
+
const decrypt = options.decrypt;
|
|
80
|
+
const syncTabs = options.session ? false : options.syncTabs ?? true;
|
|
81
|
+
let restored = initial;
|
|
82
|
+
try {
|
|
83
|
+
let raw = storage.getItem(key);
|
|
84
|
+
if (raw !== null) {
|
|
85
|
+
if (decrypt) raw = decrypt(raw);
|
|
86
|
+
const parsed = deserialize(raw);
|
|
87
|
+
restored = options.validate && !options.validate(parsed) ? initial : parsed;
|
|
88
|
+
}
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
const [value, setValue] = signal(restored);
|
|
92
|
+
let applyingFromStorage = false;
|
|
93
|
+
effect(() => {
|
|
94
|
+
const current = value();
|
|
95
|
+
if (applyingFromStorage) return;
|
|
96
|
+
try {
|
|
97
|
+
let serialized = serialize(current);
|
|
98
|
+
if (encrypt) serialized = encrypt(serialized);
|
|
99
|
+
storage.setItem(key, serialized);
|
|
100
|
+
} catch {
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
let storageListener = null;
|
|
104
|
+
if (syncTabs && typeof window !== "undefined") {
|
|
105
|
+
storageListener = (e) => {
|
|
106
|
+
if (e.storageArea !== storage || e.key !== key) return;
|
|
107
|
+
if (e.newValue === null) {
|
|
108
|
+
applyingFromStorage = true;
|
|
109
|
+
try {
|
|
110
|
+
setValue(initial);
|
|
111
|
+
} finally {
|
|
112
|
+
applyingFromStorage = false;
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
let raw = e.newValue;
|
|
118
|
+
if (decrypt) raw = decrypt(raw);
|
|
119
|
+
const parsed = deserialize(raw);
|
|
120
|
+
if (options.validate && !options.validate(parsed)) return;
|
|
121
|
+
applyingFromStorage = true;
|
|
122
|
+
try {
|
|
123
|
+
setValue(parsed);
|
|
124
|
+
} finally {
|
|
125
|
+
applyingFromStorage = false;
|
|
126
|
+
}
|
|
127
|
+
} catch {
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
window.addEventListener("storage", storageListener);
|
|
131
|
+
}
|
|
132
|
+
const dispose = () => {
|
|
133
|
+
if (storageListener && typeof window !== "undefined") {
|
|
134
|
+
window.removeEventListener("storage", storageListener);
|
|
135
|
+
storageListener = null;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
Object.defineProperty(setValue, "dispose", {
|
|
139
|
+
value: dispose,
|
|
140
|
+
enumerable: false,
|
|
141
|
+
writable: false,
|
|
142
|
+
configurable: false
|
|
143
|
+
});
|
|
144
|
+
return [value, setValue];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/patterns/optimistic.ts
|
|
148
|
+
function optimistic(initialValue) {
|
|
149
|
+
const [value, setValue] = signal(initialValue);
|
|
150
|
+
const [_pending, setPending] = signal(false);
|
|
151
|
+
async function addOptimistic(optimisticValue, asyncAction) {
|
|
152
|
+
const previousValue = value();
|
|
153
|
+
setValue(optimisticValue);
|
|
154
|
+
setPending(true);
|
|
155
|
+
try {
|
|
156
|
+
const result = await asyncAction();
|
|
157
|
+
setValue(result);
|
|
158
|
+
} catch {
|
|
159
|
+
setValue(previousValue);
|
|
160
|
+
} finally {
|
|
161
|
+
setPending(false);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return [value, addOptimistic];
|
|
165
|
+
}
|
|
166
|
+
function optimisticList(initialValue) {
|
|
167
|
+
const [items, setItems] = signal([...initialValue]);
|
|
168
|
+
async function addOptimistic(item, asyncAction) {
|
|
169
|
+
const prev = items();
|
|
170
|
+
setItems([...prev, item]);
|
|
171
|
+
try {
|
|
172
|
+
const result = await asyncAction();
|
|
173
|
+
setItems((current) => {
|
|
174
|
+
const idx = current.lastIndexOf(item);
|
|
175
|
+
if (idx >= 0) {
|
|
176
|
+
const next = [...current];
|
|
177
|
+
next[idx] = result;
|
|
178
|
+
return next;
|
|
179
|
+
}
|
|
180
|
+
return [...current.filter((i) => i !== item), result];
|
|
181
|
+
});
|
|
182
|
+
} catch {
|
|
183
|
+
setItems(prev);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async function removeOptimistic(predicate, asyncAction) {
|
|
187
|
+
const prev = items();
|
|
188
|
+
setItems(prev.filter((item) => !predicate(item)));
|
|
189
|
+
try {
|
|
190
|
+
await asyncAction();
|
|
191
|
+
} catch {
|
|
192
|
+
setItems(prev);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function updateOptimistic(predicate, update, asyncAction) {
|
|
196
|
+
const prev = items();
|
|
197
|
+
setItems(prev.map((item) => predicate(item) ? { ...item, ...update } : item));
|
|
198
|
+
try {
|
|
199
|
+
const result = await asyncAction();
|
|
200
|
+
setItems((current) => current.map((item) => predicate(item) ? result : item));
|
|
201
|
+
} catch {
|
|
202
|
+
setItems(prev);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return { items, addOptimistic, removeOptimistic, updateOptimistic };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/patterns/timeTravel.ts
|
|
209
|
+
function timeline(initial, maxHistory = 100) {
|
|
210
|
+
const [history, setHistory] = signal([initial]);
|
|
211
|
+
const [index, setIndex] = signal(0);
|
|
212
|
+
const value = derived(() => history()[index()]);
|
|
213
|
+
const canUndo = derived(() => index() > 0);
|
|
214
|
+
const canRedo = derived(() => index() < history().length - 1);
|
|
215
|
+
function set(next) {
|
|
216
|
+
const current = value();
|
|
217
|
+
const newValue = typeof next === "function" ? next(current) : next;
|
|
218
|
+
if (Object.is(newValue, current)) return;
|
|
219
|
+
const hist = history();
|
|
220
|
+
const idx = index();
|
|
221
|
+
const newHistory = hist.slice(0, idx + 1);
|
|
222
|
+
newHistory.push(newValue);
|
|
223
|
+
if (newHistory.length > maxHistory) {
|
|
224
|
+
newHistory.shift();
|
|
225
|
+
setHistory(newHistory);
|
|
226
|
+
setIndex(newHistory.length - 1);
|
|
227
|
+
} else {
|
|
228
|
+
setHistory(newHistory);
|
|
229
|
+
setIndex(idx + 1);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function undo() {
|
|
233
|
+
if (canUndo()) {
|
|
234
|
+
setIndex(index() - 1);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function redo() {
|
|
238
|
+
if (canRedo()) {
|
|
239
|
+
setIndex(index() + 1);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function reset() {
|
|
243
|
+
setHistory([initial]);
|
|
244
|
+
setIndex(0);
|
|
245
|
+
}
|
|
246
|
+
function jumpTo(targetIndex) {
|
|
247
|
+
const hist = history();
|
|
248
|
+
if (targetIndex >= 0 && targetIndex < hist.length) {
|
|
249
|
+
setIndex(targetIndex);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return { value, set, undo, redo, canUndo, canRedo, history, index, reset, jumpTo };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/patterns/globalStore.ts
|
|
256
|
+
function globalStore(config) {
|
|
257
|
+
const initialState = { ...config.state };
|
|
258
|
+
const [getState, setState] = signal({ ...initialState });
|
|
259
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
260
|
+
const middlewares = config.middleware || [];
|
|
261
|
+
function dispatch(action, payload) {
|
|
262
|
+
const actionFn = config.actions[action];
|
|
263
|
+
if (!actionFn) throw new Error(`Unknown action: ${String(action)}`);
|
|
264
|
+
const execute = () => {
|
|
265
|
+
const current = getState();
|
|
266
|
+
const rawPatch = actionFn(current, payload);
|
|
267
|
+
const patch = {};
|
|
268
|
+
for (const key of Object.keys(rawPatch)) {
|
|
269
|
+
if (key !== "__proto__" && key !== "constructor" && key !== "prototype") {
|
|
270
|
+
patch[key] = rawPatch[key];
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
setState({ ...current, ...patch });
|
|
274
|
+
const newState = getState();
|
|
275
|
+
for (const listener of listeners) {
|
|
276
|
+
listener(newState);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
if (middlewares.length === 0) {
|
|
280
|
+
execute();
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
let index = 0;
|
|
284
|
+
const next = () => {
|
|
285
|
+
if (index < middlewares.length) {
|
|
286
|
+
const mw = middlewares[index++];
|
|
287
|
+
mw(getState(), String(action), payload, next);
|
|
288
|
+
} else {
|
|
289
|
+
execute();
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
next();
|
|
293
|
+
}
|
|
294
|
+
function select(selector) {
|
|
295
|
+
return derived(() => selector(getState()));
|
|
296
|
+
}
|
|
297
|
+
function subscribe(callback) {
|
|
298
|
+
listeners.add(callback);
|
|
299
|
+
return () => listeners.delete(callback);
|
|
300
|
+
}
|
|
301
|
+
function reset() {
|
|
302
|
+
setState({ ...initialState });
|
|
303
|
+
for (const listener of listeners) {
|
|
304
|
+
listener(getState());
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return { getState, select, dispatch, subscribe, reset };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/patterns/primitives.ts
|
|
311
|
+
function createSignal(value) {
|
|
312
|
+
return signal(value);
|
|
313
|
+
}
|
|
314
|
+
function createMemo(fn) {
|
|
315
|
+
return derived(fn);
|
|
316
|
+
}
|
|
317
|
+
function createEffect(fn) {
|
|
318
|
+
return effect(fn);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export {
|
|
322
|
+
machine,
|
|
323
|
+
persisted,
|
|
324
|
+
optimistic,
|
|
325
|
+
optimisticList,
|
|
326
|
+
timeline,
|
|
327
|
+
globalStore,
|
|
328
|
+
createSignal,
|
|
329
|
+
createMemo,
|
|
330
|
+
createEffect
|
|
331
|
+
};
|