@epoch32/visage 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.js +55 -4085
- package/dist/charts/index.js +48 -2806
- package/dist/devtools/index.js +18 -4771
- package/dist/dom/index.js +32 -1639
- package/dist/form/index.js +13 -1498
- package/dist/index-061jf06a.js +848 -0
- package/dist/index-0madxn60.js +442 -0
- package/dist/index-1xtrtz1t.js +256 -0
- package/dist/index-2zz0g2n2.js +212 -0
- package/dist/index-5s255b3w.js +303 -0
- package/dist/index-6kfe1nr4.js +1179 -0
- package/dist/index-8czhpea8.js +338 -0
- package/dist/index-8x8xz80v.js +727 -0
- package/dist/index-921pn75b.js +0 -0
- package/dist/index-965ryh36.js +537 -0
- package/dist/index-9fvarkrx.js +98 -0
- package/dist/index-a4xns6cc.js +219 -0
- package/dist/index-b5wc752a.js +1696 -0
- package/dist/index-df5e614s.js +334 -0
- package/dist/index-dyvgtp43.js +1094 -0
- package/dist/index-grhdtcb5.js +234 -0
- package/dist/index-h6tjqk6e.js +158 -0
- package/dist/index-js199er4.js +101 -0
- package/dist/index-x2rs3vab.js +124 -0
- package/dist/index-y9bq7h9g.js +1162 -0
- package/dist/index-zr6cvset.js +2092 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +458 -11920
- package/dist/jsx-runtime/index.js +13 -1719
- package/dist/query/index.js +47 -2505
- package/dist/router/index.js +25 -1945
- package/dist/rpc/index.js +39 -3567
- package/dist/server/index.js +11 -1256
- package/dist/signals/index.js +52 -1160
- package/dist/style/index.js +77 -2429
- package/dist/template/index.js +7 -1232
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +150 -4249
- package/dist/ui/tabs.d.ts +23 -1
- package/dist/virtual/index.js +12 -2044
- package/dist/vite/index.js +27 -746
- package/package.json +2 -2
- package/src/dom/render.ts +20 -7
- package/src/index.ts +2 -0
- package/src/signals/computed.ts +19 -12
- package/src/signals/effect.ts +7 -7
- package/src/signals/signal.ts +16 -12
- package/src/signals/system.ts +50 -21
- package/src/ui/index.ts +2 -0
- package/src/ui/tabs.tsx +211 -10
- package/src/ui/utils.ts +1 -3
- package/src/vite/lucide.ts +22 -2
|
@@ -0,0 +1,1179 @@
|
|
|
1
|
+
// src/signals/types.ts
|
|
2
|
+
var SubscriberState2;
|
|
3
|
+
((SubscriberState) => {
|
|
4
|
+
SubscriberState[SubscriberState["CLEAN"] = 0] = "CLEAN";
|
|
5
|
+
SubscriberState[SubscriberState["CHECK_DIRTY"] = 1] = "CHECK_DIRTY";
|
|
6
|
+
SubscriberState[SubscriberState["DIRTY"] = 2] = "DIRTY";
|
|
7
|
+
SubscriberState[SubscriberState["DISPOSED"] = 3] = "DISPOSED";
|
|
8
|
+
})(SubscriberState2 ||= {});
|
|
9
|
+
var SIGNAL_BRAND2 = Symbol("visage.signal");
|
|
10
|
+
var COMPUTED_BRAND2 = Symbol("visage.computed");
|
|
11
|
+
function isSignal2(value) {
|
|
12
|
+
return typeof value === "function" && ((SIGNAL_BRAND2 in value) || (COMPUTED_BRAND2 in value));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/signals/system.ts
|
|
16
|
+
var REACTIVITY_KEY = Symbol.for("visage.reactivity.context");
|
|
17
|
+
var g = globalThis;
|
|
18
|
+
if (!g[REACTIVITY_KEY]) {
|
|
19
|
+
g[REACTIVITY_KEY] = {
|
|
20
|
+
currentSubscriber: null,
|
|
21
|
+
currentScope: null,
|
|
22
|
+
batchDepth: 0,
|
|
23
|
+
pendingEffects: new Set,
|
|
24
|
+
warnedCyclicSubscribers: new WeakSet,
|
|
25
|
+
isFlushing: false
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var ctx = g[REACTIVITY_KEY];
|
|
29
|
+
var currentSubscriber = ctx.currentSubscriber;
|
|
30
|
+
var currentScope = ctx.currentScope;
|
|
31
|
+
var batchDepth = ctx.batchDepth;
|
|
32
|
+
var pendingEffects = ctx.pendingEffects;
|
|
33
|
+
var warnedCyclicSubscribers = ctx.warnedCyclicSubscribers;
|
|
34
|
+
var isFlushing = ctx.isFlushing;
|
|
35
|
+
function setCurrentSubscriber(sub) {
|
|
36
|
+
ctx.currentSubscriber = sub;
|
|
37
|
+
currentSubscriber = sub;
|
|
38
|
+
}
|
|
39
|
+
function getCurrentSubscriber() {
|
|
40
|
+
return ctx.currentSubscriber;
|
|
41
|
+
}
|
|
42
|
+
function setCurrentScope(scope) {
|
|
43
|
+
ctx.currentScope = scope;
|
|
44
|
+
currentScope = scope;
|
|
45
|
+
}
|
|
46
|
+
function getCurrentScope() {
|
|
47
|
+
return ctx.currentScope;
|
|
48
|
+
}
|
|
49
|
+
function addPendingEffect(eff) {
|
|
50
|
+
ctx.pendingEffects.add(eff);
|
|
51
|
+
}
|
|
52
|
+
function removePendingEffect(eff) {
|
|
53
|
+
ctx.pendingEffects.delete(eff);
|
|
54
|
+
}
|
|
55
|
+
var MAX_FLUSH_COUNT = 100;
|
|
56
|
+
function flushEffects() {
|
|
57
|
+
if (ctx.isFlushing || ctx.batchDepth > 0)
|
|
58
|
+
return;
|
|
59
|
+
ctx.isFlushing = true;
|
|
60
|
+
isFlushing = true;
|
|
61
|
+
let iterations = 0;
|
|
62
|
+
try {
|
|
63
|
+
while (ctx.pendingEffects.size > 0) {
|
|
64
|
+
if (++iterations > MAX_FLUSH_COUNT) {
|
|
65
|
+
ctx.pendingEffects.clear();
|
|
66
|
+
throw new Error(`[Visage Reactivity] Maximum update depth exceeded (${MAX_FLUSH_COUNT} cycles). ` + `An effect continuously triggered state mutations (infinite loop detected). ` + `Ensure effects that modify signals do not unconditionally depend on them, or use untrack() to read state.`);
|
|
67
|
+
}
|
|
68
|
+
const effectsToRun = Array.from(ctx.pendingEffects);
|
|
69
|
+
ctx.pendingEffects.clear();
|
|
70
|
+
for (const eff of effectsToRun) {
|
|
71
|
+
if (eff.state === 2 /* DIRTY */ || eff.state === 1 /* CHECK_DIRTY */) {
|
|
72
|
+
eff.run();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} finally {
|
|
77
|
+
ctx.isFlushing = false;
|
|
78
|
+
isFlushing = false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function batch2(fn) {
|
|
82
|
+
ctx.batchDepth++;
|
|
83
|
+
batchDepth = ctx.batchDepth;
|
|
84
|
+
try {
|
|
85
|
+
return fn();
|
|
86
|
+
} finally {
|
|
87
|
+
ctx.batchDepth--;
|
|
88
|
+
batchDepth = ctx.batchDepth;
|
|
89
|
+
if (ctx.batchDepth === 0) {
|
|
90
|
+
flushEffects();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function untrack2(fn) {
|
|
95
|
+
const prev = ctx.currentSubscriber;
|
|
96
|
+
setCurrentSubscriber(null);
|
|
97
|
+
try {
|
|
98
|
+
return fn();
|
|
99
|
+
} finally {
|
|
100
|
+
setCurrentSubscriber(prev);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/signals/computed.ts
|
|
105
|
+
class Computed2 {
|
|
106
|
+
[COMPUTED_BRAND2] = true;
|
|
107
|
+
_fn;
|
|
108
|
+
_value;
|
|
109
|
+
_subscribers = new Set;
|
|
110
|
+
sources = new Set;
|
|
111
|
+
sourceVersions = new Map;
|
|
112
|
+
state = 2 /* DIRTY */;
|
|
113
|
+
scope;
|
|
114
|
+
version = 0;
|
|
115
|
+
constructor(fn) {
|
|
116
|
+
this._fn = fn;
|
|
117
|
+
this.scope = getCurrentScope();
|
|
118
|
+
if (this.scope) {
|
|
119
|
+
this.scope.addSubscriber(this);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
get() {
|
|
123
|
+
if (this.state === 3 /* DISPOSED */) {
|
|
124
|
+
return this._fn();
|
|
125
|
+
}
|
|
126
|
+
const curSub = getCurrentSubscriber();
|
|
127
|
+
if (curSub !== null && curSub.state !== 3 /* DISPOSED */) {
|
|
128
|
+
this._subscribers.add(curSub);
|
|
129
|
+
curSub.sources.add(this);
|
|
130
|
+
curSub.sourceVersions.set(this, this.version);
|
|
131
|
+
}
|
|
132
|
+
if (this.state === 2 /* DIRTY */ || this.state === 1 /* CHECK_DIRTY */) {
|
|
133
|
+
this.updateIfNecessary();
|
|
134
|
+
}
|
|
135
|
+
return this._value;
|
|
136
|
+
}
|
|
137
|
+
get value() {
|
|
138
|
+
return this.get();
|
|
139
|
+
}
|
|
140
|
+
removeSubscriber(sub) {
|
|
141
|
+
this._subscribers.delete(sub);
|
|
142
|
+
}
|
|
143
|
+
markDirty(targetState = 1 /* CHECK_DIRTY */) {
|
|
144
|
+
if (this.state >= targetState || this.state === 3 /* DISPOSED */) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
this.state = targetState;
|
|
148
|
+
for (const sub of this._subscribers) {
|
|
149
|
+
sub.markDirty(1 /* CHECK_DIRTY */);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
updateIfNecessary() {
|
|
153
|
+
if (this.state === 2 /* DIRTY */) {
|
|
154
|
+
const prev = this._value;
|
|
155
|
+
this.recompute();
|
|
156
|
+
return !Object.is(prev, this._value);
|
|
157
|
+
}
|
|
158
|
+
if (this.state === 1 /* CHECK_DIRTY */) {
|
|
159
|
+
let anyChanged = false;
|
|
160
|
+
for (const source of this.sources) {
|
|
161
|
+
if (source instanceof Computed2) {
|
|
162
|
+
source.updateIfNecessary();
|
|
163
|
+
}
|
|
164
|
+
const lastVersion = this.sourceVersions.get(source);
|
|
165
|
+
if (lastVersion !== undefined && lastVersion !== source.version) {
|
|
166
|
+
anyChanged = true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (anyChanged) {
|
|
170
|
+
const prev = this._value;
|
|
171
|
+
this.recompute();
|
|
172
|
+
return !Object.is(prev, this._value);
|
|
173
|
+
}
|
|
174
|
+
this.state = 0 /* CLEAN */;
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
recompute() {
|
|
180
|
+
this.cleanupSources();
|
|
181
|
+
const prevSubscriber = getCurrentSubscriber();
|
|
182
|
+
setCurrentSubscriber(this);
|
|
183
|
+
const prevScope = getCurrentScope();
|
|
184
|
+
setCurrentScope(this.scope);
|
|
185
|
+
try {
|
|
186
|
+
const next = this._fn();
|
|
187
|
+
if (!Object.is(this._value, next)) {
|
|
188
|
+
this._value = next;
|
|
189
|
+
this.version++;
|
|
190
|
+
}
|
|
191
|
+
this.state = 0 /* CLEAN */;
|
|
192
|
+
} finally {
|
|
193
|
+
setCurrentSubscriber(prevSubscriber);
|
|
194
|
+
setCurrentScope(prevScope);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
cleanupSources() {
|
|
198
|
+
for (const source of this.sources) {
|
|
199
|
+
source.removeSubscriber(this);
|
|
200
|
+
}
|
|
201
|
+
this.sources.clear();
|
|
202
|
+
this.sourceVersions.clear();
|
|
203
|
+
}
|
|
204
|
+
dispose() {
|
|
205
|
+
if (this.state === 3 /* DISPOSED */)
|
|
206
|
+
return;
|
|
207
|
+
this.state = 3 /* DISPOSED */;
|
|
208
|
+
this.cleanupSources();
|
|
209
|
+
this._subscribers.clear();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function computed2(fn, options) {
|
|
213
|
+
const isInternal = options?.internal ?? false;
|
|
214
|
+
const customName = options?.name;
|
|
215
|
+
const c = new Computed2(fn);
|
|
216
|
+
const accessor = () => c.get();
|
|
217
|
+
Object.defineProperties(accessor, {
|
|
218
|
+
[COMPUTED_BRAND2]: { value: true },
|
|
219
|
+
get: { value: () => c.get() },
|
|
220
|
+
value: { get: () => c.get() }
|
|
221
|
+
});
|
|
222
|
+
if (!isInternal && typeof window !== "undefined" && window.__VISAGE_DEVTOOLS__) {
|
|
223
|
+
const devtools = window.__VISAGE_DEVTOOLS__;
|
|
224
|
+
const sigId = devtools.registerSignal({
|
|
225
|
+
name: customName,
|
|
226
|
+
type: "computed",
|
|
227
|
+
getValue: () => c.get(),
|
|
228
|
+
version: () => c.version,
|
|
229
|
+
subscribersCount: () => c._subscribers?.size ?? 0,
|
|
230
|
+
dependencies: () => Array.from(c.sources ?? []).map((src) => src._devId).filter(Boolean),
|
|
231
|
+
dependents: () => Array.from(c._subscribers ?? []).map((sub) => sub._devId).filter(Boolean)
|
|
232
|
+
});
|
|
233
|
+
c._devId = sigId;
|
|
234
|
+
const curScope = getCurrentScope();
|
|
235
|
+
if (curScope) {
|
|
236
|
+
curScope.addCleanup(() => {
|
|
237
|
+
devtools.unregisterSignal(sigId);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return accessor;
|
|
242
|
+
}
|
|
243
|
+
var createMemo2 = computed2;
|
|
244
|
+
// src/style/cx.ts
|
|
245
|
+
function hasReactiveClass2(val) {
|
|
246
|
+
if (typeof val === "function")
|
|
247
|
+
return true;
|
|
248
|
+
if (Array.isArray(val)) {
|
|
249
|
+
for (let i = 0;i < val.length; i++) {
|
|
250
|
+
if (hasReactiveClass2(val[i]))
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
if (typeof val === "object" && val !== null) {
|
|
256
|
+
for (const k in val) {
|
|
257
|
+
if (typeof val[k] === "function")
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
function normalizeClass2(val) {
|
|
264
|
+
if (!val)
|
|
265
|
+
return "";
|
|
266
|
+
if (typeof val === "function")
|
|
267
|
+
return normalizeClass2(val());
|
|
268
|
+
if (typeof val === "string")
|
|
269
|
+
return val.trim();
|
|
270
|
+
if (typeof val === "number")
|
|
271
|
+
return String(val);
|
|
272
|
+
if (Array.isArray(val)) {
|
|
273
|
+
let res = "";
|
|
274
|
+
for (let i = 0;i < val.length; i++) {
|
|
275
|
+
const item = typeof val[i] === "function" ? val[i]() : val[i];
|
|
276
|
+
const itemStr = normalizeClass2(item);
|
|
277
|
+
if (itemStr) {
|
|
278
|
+
res = res ? `${res} ${itemStr}` : itemStr;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return res;
|
|
282
|
+
}
|
|
283
|
+
if (typeof val === "object") {
|
|
284
|
+
let res = "";
|
|
285
|
+
for (const key in val) {
|
|
286
|
+
const condition = typeof val[key] === "function" ? val[key]() : val[key];
|
|
287
|
+
if (condition) {
|
|
288
|
+
res = res ? `${res} ${key}` : key;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return res;
|
|
292
|
+
}
|
|
293
|
+
return "";
|
|
294
|
+
}
|
|
295
|
+
function cx2(...args) {
|
|
296
|
+
return normalizeClass2(args);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/style/scale.ts
|
|
300
|
+
var UNITLESS_PROPERTIES2 = new Set([
|
|
301
|
+
"animationIterationCount",
|
|
302
|
+
"aspectRatio",
|
|
303
|
+
"borderImageSlice",
|
|
304
|
+
"columnCount",
|
|
305
|
+
"columns",
|
|
306
|
+
"flex",
|
|
307
|
+
"flexGrow",
|
|
308
|
+
"flexShrink",
|
|
309
|
+
"flexOrder",
|
|
310
|
+
"fontWeight",
|
|
311
|
+
"lineHeight",
|
|
312
|
+
"opacity",
|
|
313
|
+
"order",
|
|
314
|
+
"orphans",
|
|
315
|
+
"scale",
|
|
316
|
+
"tabSize",
|
|
317
|
+
"widows",
|
|
318
|
+
"zIndex",
|
|
319
|
+
"zoom",
|
|
320
|
+
"fillOpacity",
|
|
321
|
+
"strokeOpacity"
|
|
322
|
+
]);
|
|
323
|
+
var DIMENSION_KEYWORDS2 = {
|
|
324
|
+
screen: "100dvh",
|
|
325
|
+
"screen-h": "100dvh",
|
|
326
|
+
"screen-w": "100dvw",
|
|
327
|
+
full: "100%",
|
|
328
|
+
half: "50%",
|
|
329
|
+
third: "33.333333%",
|
|
330
|
+
"two-thirds": "66.666667%",
|
|
331
|
+
quarter: "25%",
|
|
332
|
+
"three-quarters": "75%",
|
|
333
|
+
auto: "auto",
|
|
334
|
+
min: "min-content",
|
|
335
|
+
max: "max-content",
|
|
336
|
+
fit: "fit-content"
|
|
337
|
+
};
|
|
338
|
+
function space2(val) {
|
|
339
|
+
if (val === undefined || val === null || val === "")
|
|
340
|
+
return "";
|
|
341
|
+
if (typeof val === "number") {
|
|
342
|
+
if (val === 0)
|
|
343
|
+
return "0px";
|
|
344
|
+
return `${val * 4}px`;
|
|
345
|
+
}
|
|
346
|
+
const str = String(val).trim();
|
|
347
|
+
if (str in DIMENSION_KEYWORDS2) {
|
|
348
|
+
return DIMENSION_KEYWORDS2[str];
|
|
349
|
+
}
|
|
350
|
+
return str;
|
|
351
|
+
}
|
|
352
|
+
function resolveDimension2(val) {
|
|
353
|
+
if (val === undefined || val === null || val === "")
|
|
354
|
+
return "";
|
|
355
|
+
if (typeof val === "number") {
|
|
356
|
+
if (val === 0)
|
|
357
|
+
return "0px";
|
|
358
|
+
if (val > 48)
|
|
359
|
+
return `${val}px`;
|
|
360
|
+
return `${val * 4}px`;
|
|
361
|
+
}
|
|
362
|
+
const str = String(val).trim();
|
|
363
|
+
if (str in DIMENSION_KEYWORDS2) {
|
|
364
|
+
return DIMENSION_KEYWORDS2[str];
|
|
365
|
+
}
|
|
366
|
+
return str;
|
|
367
|
+
}
|
|
368
|
+
function px2(val) {
|
|
369
|
+
return `${val}px`;
|
|
370
|
+
}
|
|
371
|
+
function rem2(val) {
|
|
372
|
+
return `${val}rem`;
|
|
373
|
+
}
|
|
374
|
+
function em2(val) {
|
|
375
|
+
return `${val}em`;
|
|
376
|
+
}
|
|
377
|
+
function fluid2(minPx, maxPx, options) {
|
|
378
|
+
const minVw = options?.minVw ?? 375;
|
|
379
|
+
const maxVw = options?.maxVw ?? 1280;
|
|
380
|
+
const slope = (maxPx - minPx) / (maxVw - minVw);
|
|
381
|
+
const yIntercept = -minVw * slope + minPx;
|
|
382
|
+
const slopeVw = slope * 100;
|
|
383
|
+
const preferred = `${yIntercept.toFixed(2)}px + ${slopeVw.toFixed(2)}vw`;
|
|
384
|
+
const min = Math.min(minPx, maxPx);
|
|
385
|
+
const max = Math.max(minPx, maxPx);
|
|
386
|
+
return `clamp(${min}px, ${preferred}, ${max}px)`;
|
|
387
|
+
}
|
|
388
|
+
var SHADOW_PRESETS2 = {
|
|
389
|
+
none: "none",
|
|
390
|
+
sm: "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
|
|
391
|
+
md: "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",
|
|
392
|
+
lg: "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)",
|
|
393
|
+
xl: "0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1)",
|
|
394
|
+
soft: "0 8px 30px rgba(0, 0, 0, 0.06)",
|
|
395
|
+
glow: "0 0 24px rgba(168, 85, 247, 0.35)",
|
|
396
|
+
inner: "inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)"
|
|
397
|
+
};
|
|
398
|
+
function shadow2(variant) {
|
|
399
|
+
if (variant in SHADOW_PRESETS2) {
|
|
400
|
+
return SHADOW_PRESETS2[variant];
|
|
401
|
+
}
|
|
402
|
+
return variant;
|
|
403
|
+
}
|
|
404
|
+
var RADIUS_PRESETS2 = {
|
|
405
|
+
none: "0px",
|
|
406
|
+
sm: "4px",
|
|
407
|
+
md: "8px",
|
|
408
|
+
lg: "12px",
|
|
409
|
+
xl: "16px",
|
|
410
|
+
"2xl": "20px",
|
|
411
|
+
"3xl": "24px",
|
|
412
|
+
full: "9999px"
|
|
413
|
+
};
|
|
414
|
+
function radius2(variant) {
|
|
415
|
+
if (typeof variant === "number") {
|
|
416
|
+
return `${variant}px`;
|
|
417
|
+
}
|
|
418
|
+
if (variant in RADIUS_PRESETS2) {
|
|
419
|
+
return RADIUS_PRESETS2[variant];
|
|
420
|
+
}
|
|
421
|
+
return String(variant);
|
|
422
|
+
}
|
|
423
|
+
function glass2(options = {}) {
|
|
424
|
+
const blurVal = typeof options.blur === "number" ? `${options.blur}px` : options.blur ?? "20px";
|
|
425
|
+
const tintVal = options.tint ?? "rgba(255, 255, 255, 0.65)";
|
|
426
|
+
const borderVal = options.border ?? "1px solid rgba(255, 255, 255, 0.75)";
|
|
427
|
+
return {
|
|
428
|
+
backdropFilter: `blur(${blurVal})`,
|
|
429
|
+
WebkitBackdropFilter: `blur(${blurVal})`,
|
|
430
|
+
backgroundColor: tintVal,
|
|
431
|
+
border: borderVal
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
function formatStyleProp2(prop, val) {
|
|
435
|
+
if (val === null || val === undefined || val === "")
|
|
436
|
+
return "";
|
|
437
|
+
if (typeof val === "number") {
|
|
438
|
+
if (val === 0 || UNITLESS_PROPERTIES2.has(prop)) {
|
|
439
|
+
return String(val);
|
|
440
|
+
}
|
|
441
|
+
return `${val}px`;
|
|
442
|
+
}
|
|
443
|
+
const str = String(val).trim();
|
|
444
|
+
if (str in DIMENSION_KEYWORDS2) {
|
|
445
|
+
const lowerProp = prop.toLowerCase();
|
|
446
|
+
if (str === "screen") {
|
|
447
|
+
if (lowerProp.includes("width"))
|
|
448
|
+
return "100dvw";
|
|
449
|
+
return "100dvh";
|
|
450
|
+
}
|
|
451
|
+
return DIMENSION_KEYWORDS2[str];
|
|
452
|
+
}
|
|
453
|
+
return str;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// src/dom/render.ts
|
|
457
|
+
function isReactive2(value) {
|
|
458
|
+
return isSignal2(value) || typeof value === "function";
|
|
459
|
+
}
|
|
460
|
+
function resolveValue2(val) {
|
|
461
|
+
if (typeof val === "function") {
|
|
462
|
+
return val();
|
|
463
|
+
}
|
|
464
|
+
return val;
|
|
465
|
+
}
|
|
466
|
+
function render2(fn, container) {
|
|
467
|
+
return createRoot2((dispose) => {
|
|
468
|
+
container.textContent = "";
|
|
469
|
+
const node = insertChild2(container, fn());
|
|
470
|
+
onCleanup2(() => {
|
|
471
|
+
if (node && node instanceof Node && node.parentNode === container) {
|
|
472
|
+
container.removeChild(node);
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
return dispose;
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
function setAttribute2(el, key, value) {
|
|
479
|
+
if (key.startsWith("on") && typeof value === "function") {
|
|
480
|
+
const eventName = key.startsWith("onCapture") ? key.slice(9).toLowerCase() : key.slice(2).toLowerCase();
|
|
481
|
+
const useCapture = key.startsWith("onCapture");
|
|
482
|
+
el.addEventListener(eventName, value, useCapture);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (key === "ref" && typeof value === "function") {
|
|
486
|
+
value(el);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (key === "class" || key === "className") {
|
|
490
|
+
const isSvg = typeof SVGElement !== "undefined" && el instanceof SVGElement;
|
|
491
|
+
if (hasReactiveClass2(value)) {
|
|
492
|
+
effect2(() => {
|
|
493
|
+
const cls = normalizeClass2(value);
|
|
494
|
+
if (cls) {
|
|
495
|
+
el.setAttribute("class", cls);
|
|
496
|
+
if (!isSvg)
|
|
497
|
+
el.className = cls;
|
|
498
|
+
} else {
|
|
499
|
+
el.removeAttribute("class");
|
|
500
|
+
if (!isSvg)
|
|
501
|
+
el.className = "";
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
} else {
|
|
505
|
+
const cls = normalizeClass2(value);
|
|
506
|
+
if (cls) {
|
|
507
|
+
el.setAttribute("class", cls);
|
|
508
|
+
if (!isSvg)
|
|
509
|
+
el.className = cls;
|
|
510
|
+
} else {
|
|
511
|
+
el.removeAttribute("class");
|
|
512
|
+
if (!isSvg)
|
|
513
|
+
el.className = "";
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
if (isReactive2(value)) {
|
|
519
|
+
effect2(() => {
|
|
520
|
+
const resolved = resolveValue2(value);
|
|
521
|
+
applyProp(el, key, resolved);
|
|
522
|
+
});
|
|
523
|
+
} else {
|
|
524
|
+
applyProp(el, key, value);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
function setStyleProperty(el, prop, val) {
|
|
528
|
+
const formatted = formatStyleProp2(prop, val);
|
|
529
|
+
if (prop.startsWith("--") || prop.includes("-")) {
|
|
530
|
+
if (formatted === "") {
|
|
531
|
+
el.style.removeProperty(prop);
|
|
532
|
+
} else {
|
|
533
|
+
el.style.setProperty(prop, formatted);
|
|
534
|
+
}
|
|
535
|
+
} else {
|
|
536
|
+
el.style[prop] = formatted;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
function applyProp(el, key, value) {
|
|
540
|
+
if (value === null || value === undefined || value === false && !key.startsWith("aria-") && !key.startsWith("data-")) {
|
|
541
|
+
if (key === "className" || key === "class") {
|
|
542
|
+
el.removeAttribute("class");
|
|
543
|
+
} else if (key === "style" && typeof value === "string") {
|
|
544
|
+
el.removeAttribute("style");
|
|
545
|
+
} else if (key in el && !(el instanceof SVGElement)) {
|
|
546
|
+
try {
|
|
547
|
+
el[key] = typeof el[key] === "boolean" ? false : "";
|
|
548
|
+
} catch {
|
|
549
|
+
el.removeAttribute(key);
|
|
550
|
+
}
|
|
551
|
+
} else {
|
|
552
|
+
el.removeAttribute(key);
|
|
553
|
+
}
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
if (key === "className" || key === "class") {
|
|
557
|
+
const cls = normalizeClass2(value);
|
|
558
|
+
const isSvg = typeof SVGElement !== "undefined" && el instanceof SVGElement;
|
|
559
|
+
if (cls) {
|
|
560
|
+
el.setAttribute("class", cls);
|
|
561
|
+
if (!isSvg)
|
|
562
|
+
el.className = cls;
|
|
563
|
+
} else {
|
|
564
|
+
el.removeAttribute("class");
|
|
565
|
+
if (!isSvg)
|
|
566
|
+
el.className = "";
|
|
567
|
+
}
|
|
568
|
+
} else if (key === "style") {
|
|
569
|
+
if (typeof value === "string") {
|
|
570
|
+
el.setAttribute("style", value);
|
|
571
|
+
} else if (typeof value === "object" && value !== null) {
|
|
572
|
+
for (const styleKey in value) {
|
|
573
|
+
const styleVal = value[styleKey];
|
|
574
|
+
if (isReactive2(styleVal)) {
|
|
575
|
+
effect2(() => {
|
|
576
|
+
setStyleProperty(el, styleKey, resolveValue2(styleVal));
|
|
577
|
+
});
|
|
578
|
+
} else {
|
|
579
|
+
setStyleProperty(el, styleKey, styleVal);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
} else if (key === "dangerouslySetInnerHTML" && value && typeof value.__html === "string") {
|
|
584
|
+
el.innerHTML = value.__html;
|
|
585
|
+
} else if (key in el && !(el instanceof SVGElement) && key !== "list" && key !== "form") {
|
|
586
|
+
try {
|
|
587
|
+
el[key] = value;
|
|
588
|
+
} catch {
|
|
589
|
+
el.setAttribute(key, String(value));
|
|
590
|
+
}
|
|
591
|
+
} else {
|
|
592
|
+
if (key.startsWith("aria-") || key.startsWith("data-")) {
|
|
593
|
+
el.setAttribute(key, String(value));
|
|
594
|
+
} else if (value === true) {
|
|
595
|
+
el.setAttribute(key, "");
|
|
596
|
+
} else if (value === false) {
|
|
597
|
+
el.removeAttribute(key);
|
|
598
|
+
} else {
|
|
599
|
+
el.setAttribute(key, String(value));
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
function insertChild2(parent, child, before = null) {
|
|
604
|
+
if (child === null || child === undefined || child === false || child === true) {
|
|
605
|
+
return null;
|
|
606
|
+
}
|
|
607
|
+
if (child instanceof Node) {
|
|
608
|
+
parent.insertBefore(child, before);
|
|
609
|
+
return child;
|
|
610
|
+
}
|
|
611
|
+
if (Array.isArray(child)) {
|
|
612
|
+
const fragment = document.createDocumentFragment();
|
|
613
|
+
for (const item of child) {
|
|
614
|
+
insertChild2(fragment, item);
|
|
615
|
+
}
|
|
616
|
+
parent.insertBefore(fragment, before);
|
|
617
|
+
return fragment;
|
|
618
|
+
}
|
|
619
|
+
if (isReactive2(child)) {
|
|
620
|
+
const marker = document.createTextNode("");
|
|
621
|
+
parent.insertBefore(marker, before);
|
|
622
|
+
let childScope = null;
|
|
623
|
+
let currentNodes = [];
|
|
624
|
+
effect2(() => {
|
|
625
|
+
const resolved = resolveValue2(child);
|
|
626
|
+
if ((typeof resolved === "string" || typeof resolved === "number") && currentNodes.length === 1 && currentNodes[0].nodeType === Node.TEXT_NODE) {
|
|
627
|
+
currentNodes[0].data = String(resolved);
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
if (childScope) {
|
|
631
|
+
childScope.dispose();
|
|
632
|
+
}
|
|
633
|
+
childScope = new Scope2(getActiveScope2());
|
|
634
|
+
runInScope2(childScope, () => {
|
|
635
|
+
for (const node of currentNodes) {
|
|
636
|
+
if (node.parentNode) {
|
|
637
|
+
node.parentNode.removeChild(node);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
currentNodes = [];
|
|
641
|
+
if (resolved === null || resolved === undefined || resolved === false) {
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
const frag = document.createDocumentFragment();
|
|
645
|
+
if (typeof resolved === "string" || typeof resolved === "number" || typeof resolved === "boolean") {
|
|
646
|
+
frag.appendChild(document.createTextNode(String(resolved)));
|
|
647
|
+
} else {
|
|
648
|
+
insertChild2(frag, resolved);
|
|
649
|
+
}
|
|
650
|
+
currentNodes = Array.from(frag.childNodes);
|
|
651
|
+
if (marker.parentNode) {
|
|
652
|
+
marker.parentNode.insertBefore(frag, marker);
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
});
|
|
656
|
+
onCleanup2(() => {
|
|
657
|
+
if (childScope) {
|
|
658
|
+
childScope.dispose();
|
|
659
|
+
}
|
|
660
|
+
for (const node of currentNodes) {
|
|
661
|
+
if (node.parentNode) {
|
|
662
|
+
node.parentNode.removeChild(node);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
if (marker.parentNode) {
|
|
666
|
+
marker.parentNode.removeChild(marker);
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
return marker;
|
|
670
|
+
}
|
|
671
|
+
const textNode = document.createTextNode(String(child));
|
|
672
|
+
parent.insertBefore(textNode, before);
|
|
673
|
+
return textNode;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// src/signals/scope.ts
|
|
677
|
+
class Scope2 {
|
|
678
|
+
subscribers = new Set;
|
|
679
|
+
cleanups = [];
|
|
680
|
+
parent = null;
|
|
681
|
+
isDisposed = false;
|
|
682
|
+
context;
|
|
683
|
+
constructor(parent = currentScope) {
|
|
684
|
+
this.parent = parent;
|
|
685
|
+
if (parent && !parent.isDisposed) {
|
|
686
|
+
parent.cleanups.push(() => this.dispose());
|
|
687
|
+
if (parent.context) {
|
|
688
|
+
this.context = new Map(parent.context);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
addSubscriber(sub) {
|
|
693
|
+
if (this.isDisposed)
|
|
694
|
+
return;
|
|
695
|
+
this.subscribers.add(sub);
|
|
696
|
+
}
|
|
697
|
+
addCleanup(fn) {
|
|
698
|
+
if (this.isDisposed) {
|
|
699
|
+
fn();
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
this.cleanups.push(fn);
|
|
703
|
+
}
|
|
704
|
+
dispose() {
|
|
705
|
+
if (this.isDisposed)
|
|
706
|
+
return;
|
|
707
|
+
this.isDisposed = true;
|
|
708
|
+
for (const sub of this.subscribers) {
|
|
709
|
+
sub.dispose();
|
|
710
|
+
}
|
|
711
|
+
this.subscribers.clear();
|
|
712
|
+
for (let i = this.cleanups.length - 1;i >= 0; i--) {
|
|
713
|
+
try {
|
|
714
|
+
this.cleanups[i]();
|
|
715
|
+
} catch (err) {
|
|
716
|
+
console.error("Error during cleanup:", err);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
this.cleanups = [];
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
function onCleanup2(fn) {
|
|
723
|
+
if (currentSubscriber && "addCleanup" in currentSubscriber) {
|
|
724
|
+
currentSubscriber.addCleanup(fn);
|
|
725
|
+
} else if (currentScope) {
|
|
726
|
+
currentScope.addCleanup(fn);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
function createRoot2(fn) {
|
|
730
|
+
const prevScope = currentScope;
|
|
731
|
+
const scope = new Scope2(null);
|
|
732
|
+
setCurrentScope(scope);
|
|
733
|
+
try {
|
|
734
|
+
return fn(() => scope.dispose());
|
|
735
|
+
} finally {
|
|
736
|
+
setCurrentScope(prevScope);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
function runInScope2(scope, fn) {
|
|
740
|
+
const prevScope = currentScope;
|
|
741
|
+
setCurrentScope(scope);
|
|
742
|
+
try {
|
|
743
|
+
return fn();
|
|
744
|
+
} finally {
|
|
745
|
+
setCurrentScope(prevScope);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
function getActiveScope2() {
|
|
749
|
+
return getCurrentScope();
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// src/signals/context.ts
|
|
753
|
+
function createContext2(defaultValue) {
|
|
754
|
+
const id = Symbol("visage.context");
|
|
755
|
+
const context = {
|
|
756
|
+
id,
|
|
757
|
+
defaultValue,
|
|
758
|
+
Provider: (props) => {
|
|
759
|
+
const parentScope = getActiveScope2();
|
|
760
|
+
const scope = new Scope2(parentScope);
|
|
761
|
+
if (!scope.context) {
|
|
762
|
+
scope.context = new Map(parentScope?.context);
|
|
763
|
+
}
|
|
764
|
+
scope.context.set(id, props.value);
|
|
765
|
+
return runInScope2(scope, () => {
|
|
766
|
+
const content = typeof props.children === "function" ? props.children() : props.children;
|
|
767
|
+
if (typeof document !== "undefined") {
|
|
768
|
+
const frag = document.createDocumentFragment();
|
|
769
|
+
insertChild2(frag, content);
|
|
770
|
+
return frag;
|
|
771
|
+
}
|
|
772
|
+
return content;
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
return context;
|
|
777
|
+
}
|
|
778
|
+
function useContext2(context) {
|
|
779
|
+
let scope = getActiveScope2();
|
|
780
|
+
while (scope) {
|
|
781
|
+
if (scope.context?.has(context.id)) {
|
|
782
|
+
return scope.context.get(context.id);
|
|
783
|
+
}
|
|
784
|
+
scope = scope.parent;
|
|
785
|
+
}
|
|
786
|
+
return context.defaultValue;
|
|
787
|
+
}
|
|
788
|
+
// src/signals/effect.ts
|
|
789
|
+
class Effect2 {
|
|
790
|
+
_fn;
|
|
791
|
+
sources = new Set;
|
|
792
|
+
sourceVersions = new Map;
|
|
793
|
+
cleanups = [];
|
|
794
|
+
state = 2 /* DIRTY */;
|
|
795
|
+
scope;
|
|
796
|
+
constructor(fn) {
|
|
797
|
+
this._fn = fn;
|
|
798
|
+
this.scope = getCurrentScope();
|
|
799
|
+
if (this.scope) {
|
|
800
|
+
this.scope.addSubscriber(this);
|
|
801
|
+
}
|
|
802
|
+
this.run();
|
|
803
|
+
}
|
|
804
|
+
addCleanup(fn) {
|
|
805
|
+
this.cleanups.push(fn);
|
|
806
|
+
}
|
|
807
|
+
runCleanups() {
|
|
808
|
+
for (let i = this.cleanups.length - 1;i >= 0; i--) {
|
|
809
|
+
try {
|
|
810
|
+
this.cleanups[i]();
|
|
811
|
+
} catch (e) {
|
|
812
|
+
console.error("Error in effect cleanup:", e);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
this.cleanups = [];
|
|
816
|
+
}
|
|
817
|
+
markDirty(targetState = 2 /* DIRTY */) {
|
|
818
|
+
if (this.state >= targetState || this.state === 3 /* DISPOSED */) {
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
this.state = targetState;
|
|
822
|
+
addPendingEffect(this);
|
|
823
|
+
if (batchDepth === 0) {
|
|
824
|
+
flushEffects();
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
run() {
|
|
828
|
+
if (this.state === 3 /* DISPOSED */)
|
|
829
|
+
return;
|
|
830
|
+
if (this.state === 1 /* CHECK_DIRTY */) {
|
|
831
|
+
let isDirty = false;
|
|
832
|
+
for (const source of this.sources) {
|
|
833
|
+
if (source instanceof Computed2) {
|
|
834
|
+
source.updateIfNecessary();
|
|
835
|
+
}
|
|
836
|
+
const lastVersion = this.sourceVersions.get(source);
|
|
837
|
+
if (lastVersion !== undefined && lastVersion !== source.version) {
|
|
838
|
+
isDirty = true;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
if (!isDirty) {
|
|
842
|
+
this.state = 0 /* CLEAN */;
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
this.runCleanups();
|
|
847
|
+
this.cleanupSources();
|
|
848
|
+
const prevSubscriber = getCurrentSubscriber();
|
|
849
|
+
setCurrentSubscriber(this);
|
|
850
|
+
const prevScope = getCurrentScope();
|
|
851
|
+
setCurrentScope(this.scope);
|
|
852
|
+
try {
|
|
853
|
+
this.state = 0 /* CLEAN */;
|
|
854
|
+
const res = this._fn();
|
|
855
|
+
if (typeof res === "function") {
|
|
856
|
+
this.cleanups.push(res);
|
|
857
|
+
}
|
|
858
|
+
} finally {
|
|
859
|
+
setCurrentSubscriber(prevSubscriber);
|
|
860
|
+
setCurrentScope(prevScope);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
cleanupSources() {
|
|
864
|
+
for (const source of this.sources) {
|
|
865
|
+
source.removeSubscriber(this);
|
|
866
|
+
}
|
|
867
|
+
this.sources.clear();
|
|
868
|
+
this.sourceVersions.clear();
|
|
869
|
+
}
|
|
870
|
+
dispose() {
|
|
871
|
+
if (this.state === 3 /* DISPOSED */)
|
|
872
|
+
return;
|
|
873
|
+
this.state = 3 /* DISPOSED */;
|
|
874
|
+
this.runCleanups();
|
|
875
|
+
this.cleanupSources();
|
|
876
|
+
removePendingEffect(this);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
function effect2(fn) {
|
|
880
|
+
const eff = new Effect2(fn);
|
|
881
|
+
return () => eff.dispose();
|
|
882
|
+
}
|
|
883
|
+
var createEffect2 = effect2;
|
|
884
|
+
// src/signals/signal.ts
|
|
885
|
+
class Signal2 {
|
|
886
|
+
[SIGNAL_BRAND2] = true;
|
|
887
|
+
_value;
|
|
888
|
+
_subscribers = new Set;
|
|
889
|
+
_equals;
|
|
890
|
+
_onSet;
|
|
891
|
+
version = 0;
|
|
892
|
+
constructor(initialValue, equals, onSet) {
|
|
893
|
+
this._value = initialValue;
|
|
894
|
+
this._equals = equals ?? Object.is;
|
|
895
|
+
this._onSet = onSet;
|
|
896
|
+
}
|
|
897
|
+
get() {
|
|
898
|
+
const curSub = getCurrentSubscriber();
|
|
899
|
+
if (curSub !== null && curSub.state !== 3 /* DISPOSED */) {
|
|
900
|
+
this._subscribers.add(curSub);
|
|
901
|
+
curSub.sources.add(this);
|
|
902
|
+
curSub.sourceVersions.set(this, this.version);
|
|
903
|
+
}
|
|
904
|
+
return this._value;
|
|
905
|
+
}
|
|
906
|
+
set(newValue) {
|
|
907
|
+
if (this._equals(this._value, newValue)) {
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
const curSub = getCurrentSubscriber();
|
|
911
|
+
if (curSub !== null && this._subscribers.has(curSub)) {
|
|
912
|
+
if (!warnedCyclicSubscribers.has(curSub)) {
|
|
913
|
+
warnedCyclicSubscribers.add(curSub);
|
|
914
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
915
|
+
console.warn(`[Visage Reactivity] Cyclic update detected: An active subscriber modified a signal that it depends on. ` + `To read a signal inside an effect/computed without creating a circular dependency, wrap the read in untrack():
|
|
916
|
+
` + ` untrack(() => signal())`);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
this._value = newValue;
|
|
921
|
+
this.version++;
|
|
922
|
+
if (this._onSet) {
|
|
923
|
+
this._onSet(newValue);
|
|
924
|
+
}
|
|
925
|
+
batch2(() => {
|
|
926
|
+
this.notify();
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
update(fn) {
|
|
930
|
+
this.set(fn(this._value));
|
|
931
|
+
}
|
|
932
|
+
get value() {
|
|
933
|
+
return this.get();
|
|
934
|
+
}
|
|
935
|
+
set value(val) {
|
|
936
|
+
this.set(val);
|
|
937
|
+
}
|
|
938
|
+
removeSubscriber(sub) {
|
|
939
|
+
this._subscribers.delete(sub);
|
|
940
|
+
}
|
|
941
|
+
notify() {
|
|
942
|
+
if (this._subscribers.size === 0)
|
|
943
|
+
return;
|
|
944
|
+
const subs = Array.from(this._subscribers);
|
|
945
|
+
for (const sub of subs) {
|
|
946
|
+
sub.markDirty(2 /* DIRTY */);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
function resolveStorage(storageOption) {
|
|
951
|
+
if (storageOption && typeof storageOption === "object") {
|
|
952
|
+
return storageOption;
|
|
953
|
+
}
|
|
954
|
+
if (storageOption === "session") {
|
|
955
|
+
try {
|
|
956
|
+
if (typeof sessionStorage !== "undefined")
|
|
957
|
+
return sessionStorage;
|
|
958
|
+
} catch {}
|
|
959
|
+
try {
|
|
960
|
+
if (typeof window !== "undefined" && window.sessionStorage) {
|
|
961
|
+
return window.sessionStorage;
|
|
962
|
+
}
|
|
963
|
+
} catch {}
|
|
964
|
+
try {
|
|
965
|
+
if (typeof globalThis !== "undefined" && globalThis.sessionStorage) {
|
|
966
|
+
return globalThis.sessionStorage;
|
|
967
|
+
}
|
|
968
|
+
} catch {}
|
|
969
|
+
return null;
|
|
970
|
+
}
|
|
971
|
+
try {
|
|
972
|
+
if (typeof localStorage !== "undefined")
|
|
973
|
+
return localStorage;
|
|
974
|
+
} catch {}
|
|
975
|
+
try {
|
|
976
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
977
|
+
return window.localStorage;
|
|
978
|
+
}
|
|
979
|
+
} catch {}
|
|
980
|
+
try {
|
|
981
|
+
if (typeof globalThis !== "undefined" && globalThis.localStorage) {
|
|
982
|
+
return globalThis.localStorage;
|
|
983
|
+
}
|
|
984
|
+
} catch {}
|
|
985
|
+
return null;
|
|
986
|
+
}
|
|
987
|
+
function signal2(initialValue, optionsOrEquals) {
|
|
988
|
+
const equals = typeof optionsOrEquals === "function" ? optionsOrEquals : optionsOrEquals?.equals;
|
|
989
|
+
const isInternal = typeof optionsOrEquals === "object" ? optionsOrEquals?.internal : false;
|
|
990
|
+
const customName = typeof optionsOrEquals === "object" ? optionsOrEquals?.name : undefined;
|
|
991
|
+
const persistOption = typeof optionsOrEquals === "object" ? optionsOrEquals?.persist : undefined;
|
|
992
|
+
const persistConfig = persistOption ? typeof persistOption === "string" ? { key: persistOption } : persistOption : undefined;
|
|
993
|
+
let effectiveInitial = initialValue;
|
|
994
|
+
const storage = persistConfig ? resolveStorage(persistConfig.storage) : null;
|
|
995
|
+
const serialize = persistConfig?.serialize ?? JSON.stringify;
|
|
996
|
+
const deserialize = persistConfig?.deserialize ?? JSON.parse;
|
|
997
|
+
if (persistConfig && storage) {
|
|
998
|
+
try {
|
|
999
|
+
const stored = storage.getItem(persistConfig.key);
|
|
1000
|
+
if (stored !== null) {
|
|
1001
|
+
effectiveInitial = deserialize(stored);
|
|
1002
|
+
}
|
|
1003
|
+
} catch {}
|
|
1004
|
+
}
|
|
1005
|
+
let isSyncing = false;
|
|
1006
|
+
const onSet = persistConfig && storage ? (val) => {
|
|
1007
|
+
if (isSyncing)
|
|
1008
|
+
return;
|
|
1009
|
+
try {
|
|
1010
|
+
storage.setItem(persistConfig.key, serialize(val));
|
|
1011
|
+
} catch {}
|
|
1012
|
+
} : undefined;
|
|
1013
|
+
const s = new Signal2(effectiveInitial, equals, onSet);
|
|
1014
|
+
if (persistConfig && storage && (persistConfig.syncTabs ?? true) && typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
1015
|
+
const onStorage = (e) => {
|
|
1016
|
+
if (e.key === persistConfig.key) {
|
|
1017
|
+
try {
|
|
1018
|
+
const nextVal = e.newValue !== null ? deserialize(e.newValue) : initialValue;
|
|
1019
|
+
isSyncing = true;
|
|
1020
|
+
try {
|
|
1021
|
+
s.set(nextVal);
|
|
1022
|
+
} finally {
|
|
1023
|
+
isSyncing = false;
|
|
1024
|
+
}
|
|
1025
|
+
} catch {}
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
window.addEventListener("storage", onStorage);
|
|
1029
|
+
const curScope = getCurrentScope();
|
|
1030
|
+
if (curScope) {
|
|
1031
|
+
curScope.addCleanup(() => {
|
|
1032
|
+
window.removeEventListener("storage", onStorage);
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
const accessor = (...args) => {
|
|
1037
|
+
if (args.length === 0) {
|
|
1038
|
+
return s.get();
|
|
1039
|
+
}
|
|
1040
|
+
s.set(args[0]);
|
|
1041
|
+
return args[0];
|
|
1042
|
+
};
|
|
1043
|
+
Object.defineProperties(accessor, {
|
|
1044
|
+
[SIGNAL_BRAND2]: { value: true },
|
|
1045
|
+
get: { value: () => s.get() },
|
|
1046
|
+
set: { value: (v) => s.set(v) },
|
|
1047
|
+
update: { value: (fn) => s.update(fn) },
|
|
1048
|
+
value: {
|
|
1049
|
+
get: () => s.get(),
|
|
1050
|
+
set: (v) => s.set(v)
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
if (!isInternal && typeof window !== "undefined" && window.__VISAGE_DEVTOOLS__) {
|
|
1054
|
+
const devtools = window.__VISAGE_DEVTOOLS__;
|
|
1055
|
+
const sigId = devtools.registerSignal({
|
|
1056
|
+
name: customName,
|
|
1057
|
+
type: "signal",
|
|
1058
|
+
getValue: () => s.get(),
|
|
1059
|
+
version: () => s.version,
|
|
1060
|
+
subscribersCount: () => s._subscribers?.size ?? 0,
|
|
1061
|
+
dependents: () => Array.from(s._subscribers ?? []).map((sub) => sub._devId).filter(Boolean)
|
|
1062
|
+
});
|
|
1063
|
+
s._devId = sigId;
|
|
1064
|
+
const curScope = getCurrentScope();
|
|
1065
|
+
if (curScope) {
|
|
1066
|
+
curScope.addCleanup(() => {
|
|
1067
|
+
devtools.unregisterSignal(sigId);
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
return accessor;
|
|
1072
|
+
}
|
|
1073
|
+
function createSignal2(initialValue, optionsOrEquals) {
|
|
1074
|
+
const s = signal2(initialValue, optionsOrEquals);
|
|
1075
|
+
const setter = (value) => {
|
|
1076
|
+
if (typeof value === "function") {
|
|
1077
|
+
s.update(value);
|
|
1078
|
+
} else {
|
|
1079
|
+
s.set(value);
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
return [s, setter];
|
|
1083
|
+
}
|
|
1084
|
+
// src/signals/store.ts
|
|
1085
|
+
var STORE_RAW = Symbol("visage.store.raw");
|
|
1086
|
+
var STORE_SIGNALS = Symbol("visage.store.signals");
|
|
1087
|
+
var STORE_PROXY = Symbol("visage.store.proxy");
|
|
1088
|
+
function isObject(val) {
|
|
1089
|
+
return typeof val === "object" && val !== null && (typeof Node === "undefined" || !(val instanceof Node)) && !isSignal2(val);
|
|
1090
|
+
}
|
|
1091
|
+
function getOrCreatePropertySignal(target, prop) {
|
|
1092
|
+
let signalsMap = target[STORE_SIGNALS];
|
|
1093
|
+
if (!signalsMap) {
|
|
1094
|
+
signalsMap = new Map;
|
|
1095
|
+
Object.defineProperty(target, STORE_SIGNALS, {
|
|
1096
|
+
value: signalsMap,
|
|
1097
|
+
enumerable: false,
|
|
1098
|
+
writable: true
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
let sig = signalsMap.get(prop);
|
|
1102
|
+
if (!sig) {
|
|
1103
|
+
sig = new Signal2(target[prop]);
|
|
1104
|
+
signalsMap.set(prop, sig);
|
|
1105
|
+
}
|
|
1106
|
+
return sig;
|
|
1107
|
+
}
|
|
1108
|
+
function createStoreProxy(target) {
|
|
1109
|
+
if (!isObject(target))
|
|
1110
|
+
return target;
|
|
1111
|
+
if (target[STORE_PROXY])
|
|
1112
|
+
return target[STORE_PROXY];
|
|
1113
|
+
const proxy = new Proxy(target, {
|
|
1114
|
+
get(target, prop, receiver) {
|
|
1115
|
+
if (prop === STORE_RAW)
|
|
1116
|
+
return target;
|
|
1117
|
+
if (prop === STORE_PROXY)
|
|
1118
|
+
return proxy;
|
|
1119
|
+
if (typeof prop === "string" || typeof prop === "symbol") {
|
|
1120
|
+
const sig = getOrCreatePropertySignal(target, prop);
|
|
1121
|
+
sig.get();
|
|
1122
|
+
}
|
|
1123
|
+
const value = Reflect.get(target, prop, receiver);
|
|
1124
|
+
if (isObject(value)) {
|
|
1125
|
+
return createStoreProxy(value);
|
|
1126
|
+
}
|
|
1127
|
+
return value;
|
|
1128
|
+
},
|
|
1129
|
+
set(target, prop, value, receiver) {
|
|
1130
|
+
const prevValue = Reflect.get(target, prop, receiver);
|
|
1131
|
+
if (Object.is(prevValue, value)) {
|
|
1132
|
+
return true;
|
|
1133
|
+
}
|
|
1134
|
+
const success = Reflect.set(target, prop, value, receiver);
|
|
1135
|
+
if (success) {
|
|
1136
|
+
const sig = getOrCreatePropertySignal(target, prop);
|
|
1137
|
+
sig.set(value);
|
|
1138
|
+
if (Array.isArray(target) && prop !== "length") {
|
|
1139
|
+
const lenSig = getOrCreatePropertySignal(target, "length");
|
|
1140
|
+
lenSig.set(target.length);
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return success;
|
|
1144
|
+
},
|
|
1145
|
+
deleteProperty(target, prop) {
|
|
1146
|
+
const hadProp = Reflect.has(target, prop);
|
|
1147
|
+
const success = Reflect.deleteProperty(target, prop);
|
|
1148
|
+
if (hadProp && success) {
|
|
1149
|
+
const sig = getOrCreatePropertySignal(target, prop);
|
|
1150
|
+
sig.set(undefined);
|
|
1151
|
+
}
|
|
1152
|
+
return success;
|
|
1153
|
+
}
|
|
1154
|
+
});
|
|
1155
|
+
Object.defineProperty(target, STORE_PROXY, {
|
|
1156
|
+
value: proxy,
|
|
1157
|
+
enumerable: false,
|
|
1158
|
+
writable: true
|
|
1159
|
+
});
|
|
1160
|
+
return proxy;
|
|
1161
|
+
}
|
|
1162
|
+
function createStore2(initialState) {
|
|
1163
|
+
if (!isObject(initialState)) {
|
|
1164
|
+
throw new Error("createStore requires an object or array as initial state");
|
|
1165
|
+
}
|
|
1166
|
+
return createStoreProxy(initialState);
|
|
1167
|
+
}
|
|
1168
|
+
function mutateStore2(store, mutator) {
|
|
1169
|
+
batch2(() => {
|
|
1170
|
+
mutator(store);
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
function unwrapStore2(store) {
|
|
1174
|
+
if (isObject(store) && store[STORE_RAW]) {
|
|
1175
|
+
return store[STORE_RAW];
|
|
1176
|
+
}
|
|
1177
|
+
return store;
|
|
1178
|
+
}
|
|
1179
|
+
export { SubscriberState2, SIGNAL_BRAND2, COMPUTED_BRAND2, isSignal2, batch2, untrack2, Computed2, computed2, createMemo2, hasReactiveClass2, normalizeClass2, cx2, UNITLESS_PROPERTIES2, DIMENSION_KEYWORDS2, space2, resolveDimension2, px2, rem2, em2, fluid2, SHADOW_PRESETS2, shadow2, RADIUS_PRESETS2, radius2, glass2, formatStyleProp2, isReactive2, resolveValue2, render2, setAttribute2, insertChild2, Scope2, onCleanup2, createRoot2, runInScope2, getActiveScope2, createContext2, useContext2, Effect2, effect2, createEffect2, Signal2, signal2, createSignal2, createStore2, mutateStore2, unwrapStore2 };
|