@epoch32/visage 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/api/index.js +55 -4085
  2. package/dist/charts/index.js +48 -2806
  3. package/dist/devtools/index.js +18 -4771
  4. package/dist/dom/index.js +32 -1639
  5. package/dist/form/index.js +13 -1498
  6. package/dist/index-061jf06a.js +848 -0
  7. package/dist/index-0madxn60.js +442 -0
  8. package/dist/index-1xtrtz1t.js +256 -0
  9. package/dist/index-2zz0g2n2.js +212 -0
  10. package/dist/index-5s255b3w.js +303 -0
  11. package/dist/index-6kfe1nr4.js +1179 -0
  12. package/dist/index-8czhpea8.js +338 -0
  13. package/dist/index-8x8xz80v.js +727 -0
  14. package/dist/index-921pn75b.js +0 -0
  15. package/dist/index-965ryh36.js +537 -0
  16. package/dist/index-9fvarkrx.js +98 -0
  17. package/dist/index-a4xns6cc.js +219 -0
  18. package/dist/index-b5wc752a.js +1696 -0
  19. package/dist/index-df5e614s.js +334 -0
  20. package/dist/index-dyvgtp43.js +1094 -0
  21. package/dist/index-grhdtcb5.js +234 -0
  22. package/dist/index-h6tjqk6e.js +158 -0
  23. package/dist/index-js199er4.js +101 -0
  24. package/dist/index-x2rs3vab.js +124 -0
  25. package/dist/index-y9bq7h9g.js +1162 -0
  26. package/dist/index-zr6cvset.js +2092 -0
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +458 -11920
  29. package/dist/jsx-runtime/index.js +13 -1719
  30. package/dist/query/index.js +47 -2505
  31. package/dist/router/index.js +25 -1945
  32. package/dist/rpc/index.js +39 -3567
  33. package/dist/server/index.js +11 -1256
  34. package/dist/signals/index.js +52 -1160
  35. package/dist/style/index.js +77 -2429
  36. package/dist/template/index.js +7 -1232
  37. package/dist/ui/index.d.ts +1 -1
  38. package/dist/ui/index.js +150 -4249
  39. package/dist/ui/tabs.d.ts +23 -1
  40. package/dist/virtual/index.js +12 -2044
  41. package/dist/vite/index.js +5 -744
  42. package/package.json +2 -2
  43. package/src/dom/render.ts +20 -7
  44. package/src/index.ts +2 -0
  45. package/src/signals/computed.ts +19 -12
  46. package/src/signals/effect.ts +7 -7
  47. package/src/signals/signal.ts +16 -12
  48. package/src/signals/system.ts +50 -21
  49. package/src/ui/index.ts +2 -0
  50. package/src/ui/tabs.tsx +211 -10
  51. package/src/ui/utils.ts +1 -3
@@ -1,2431 +1,79 @@
1
- // src/signals/types.ts
2
- var SubscriberState;
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
- })(SubscriberState ||= {});
9
- var SIGNAL_BRAND = Symbol("visage.signal");
10
- var COMPUTED_BRAND = Symbol("visage.computed");
11
- function isSignal(value) {
12
- return typeof value === "function" && ((SIGNAL_BRAND in value) || (COMPUTED_BRAND in value));
13
- }
14
-
15
- // src/signals/system.ts
16
- var currentSubscriber = null;
17
- var currentScope = null;
18
- var batchDepth = 0;
19
- var pendingEffects = new Set;
20
- var warnedCyclicSubscribers = new WeakSet;
21
- var isFlushing = false;
22
- function setCurrentSubscriber(sub) {
23
- currentSubscriber = sub;
24
- }
25
- function setCurrentScope(scope) {
26
- currentScope = scope;
27
- }
28
- function getCurrentScope() {
29
- return currentScope;
30
- }
31
- function addPendingEffect(eff) {
32
- pendingEffects.add(eff);
33
- }
34
- function removePendingEffect(eff) {
35
- pendingEffects.delete(eff);
36
- }
37
- var MAX_FLUSH_COUNT = 100;
38
- function flushEffects() {
39
- if (isFlushing || batchDepth > 0)
40
- return;
41
- isFlushing = true;
42
- let iterations = 0;
43
- try {
44
- while (pendingEffects.size > 0) {
45
- if (++iterations > MAX_FLUSH_COUNT) {
46
- pendingEffects.clear();
47
- 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.`);
48
- }
49
- const effectsToRun = Array.from(pendingEffects);
50
- pendingEffects.clear();
51
- for (const eff of effectsToRun) {
52
- if (eff.state === 2 /* DIRTY */ || eff.state === 1 /* CHECK_DIRTY */) {
53
- eff.run();
54
- }
55
- }
56
- }
57
- } finally {
58
- isFlushing = false;
59
- }
60
- }
61
- function batch(fn) {
62
- batchDepth++;
63
- try {
64
- return fn();
65
- } finally {
66
- batchDepth--;
67
- if (batchDepth === 0) {
68
- flushEffects();
69
- }
70
- }
71
- }
72
- function untrack(fn) {
73
- const prev = currentSubscriber;
74
- currentSubscriber = null;
75
- try {
76
- return fn();
77
- } finally {
78
- currentSubscriber = prev;
79
- }
80
- }
81
-
82
- // src/signals/computed.ts
83
- class Computed {
84
- [COMPUTED_BRAND] = true;
85
- _fn;
86
- _value;
87
- _subscribers = new Set;
88
- sources = new Set;
89
- sourceVersions = new Map;
90
- state = 2 /* DIRTY */;
91
- scope;
92
- version = 0;
93
- constructor(fn) {
94
- this._fn = fn;
95
- this.scope = currentScope;
96
- if (currentScope) {
97
- currentScope.addSubscriber(this);
98
- }
99
- }
100
- get() {
101
- if (this.state === 3 /* DISPOSED */) {
102
- return this._fn();
103
- }
104
- if (currentSubscriber !== null && currentSubscriber.state !== 3 /* DISPOSED */) {
105
- this._subscribers.add(currentSubscriber);
106
- currentSubscriber.sources.add(this);
107
- currentSubscriber.sourceVersions.set(this, this.version);
108
- }
109
- if (this.state === 2 /* DIRTY */ || this.state === 1 /* CHECK_DIRTY */) {
110
- this.updateIfNecessary();
111
- }
112
- return this._value;
113
- }
114
- get value() {
115
- return this.get();
116
- }
117
- removeSubscriber(sub) {
118
- this._subscribers.delete(sub);
119
- }
120
- markDirty(targetState = 1 /* CHECK_DIRTY */) {
121
- if (this.state >= targetState || this.state === 3 /* DISPOSED */) {
122
- return;
123
- }
124
- this.state = targetState;
125
- for (const sub of this._subscribers) {
126
- sub.markDirty(1 /* CHECK_DIRTY */);
127
- }
128
- }
129
- updateIfNecessary() {
130
- if (this.state === 2 /* DIRTY */) {
131
- const prev = this._value;
132
- this.recompute();
133
- return !Object.is(prev, this._value);
134
- }
135
- if (this.state === 1 /* CHECK_DIRTY */) {
136
- let anyChanged = false;
137
- for (const source of this.sources) {
138
- if (source instanceof Computed) {
139
- source.updateIfNecessary();
140
- }
141
- const lastVersion = this.sourceVersions.get(source);
142
- if (lastVersion !== undefined && lastVersion !== source.version) {
143
- anyChanged = true;
144
- }
145
- }
146
- if (anyChanged) {
147
- const prev = this._value;
148
- this.recompute();
149
- return !Object.is(prev, this._value);
150
- }
151
- this.state = 0 /* CLEAN */;
152
- return false;
153
- }
154
- return false;
155
- }
156
- recompute() {
157
- this.cleanupSources();
158
- const prevSubscriber = currentSubscriber;
159
- setCurrentSubscriber(this);
160
- const prevScope = currentScope;
161
- setCurrentScope(this.scope);
162
- try {
163
- const next = this._fn();
164
- if (!Object.is(this._value, next)) {
165
- this._value = next;
166
- this.version++;
167
- }
168
- this.state = 0 /* CLEAN */;
169
- } finally {
170
- setCurrentSubscriber(prevSubscriber);
171
- setCurrentScope(prevScope);
172
- }
173
- }
174
- cleanupSources() {
175
- for (const source of this.sources) {
176
- source.removeSubscriber(this);
177
- }
178
- this.sources.clear();
179
- this.sourceVersions.clear();
180
- }
181
- dispose() {
182
- if (this.state === 3 /* DISPOSED */)
183
- return;
184
- this.state = 3 /* DISPOSED */;
185
- this.cleanupSources();
186
- this._subscribers.clear();
187
- }
188
- }
189
- function computed(fn, options) {
190
- const isInternal = options?.internal ?? false;
191
- const customName = options?.name;
192
- const c = new Computed(fn);
193
- const accessor = () => c.get();
194
- Object.defineProperties(accessor, {
195
- [COMPUTED_BRAND]: { value: true },
196
- get: { value: () => c.get() },
197
- value: { get: () => c.get() }
198
- });
199
- if (!isInternal && typeof window !== "undefined" && window.__VISAGE_DEVTOOLS__) {
200
- const devtools = window.__VISAGE_DEVTOOLS__;
201
- const sigId = devtools.registerSignal({
202
- name: customName,
203
- type: "computed",
204
- getValue: () => c.get(),
205
- version: () => c.version,
206
- subscribersCount: () => c._subscribers?.size ?? 0,
207
- dependencies: () => Array.from(c.sources ?? []).map((src) => src._devId).filter(Boolean),
208
- dependents: () => Array.from(c._subscribers ?? []).map((sub) => sub._devId).filter(Boolean)
209
- });
210
- c._devId = sigId;
211
- if (currentScope) {
212
- currentScope.addCleanup(() => {
213
- devtools.unregisterSignal(sigId);
214
- });
215
- }
216
- }
217
- return accessor;
218
- }
219
- var createMemo = computed;
220
- // src/style/cx.ts
221
- function hasReactiveClass(val) {
222
- if (typeof val === "function")
223
- return true;
224
- if (Array.isArray(val)) {
225
- for (let i = 0;i < val.length; i++) {
226
- if (hasReactiveClass(val[i]))
227
- return true;
228
- }
229
- return false;
230
- }
231
- if (typeof val === "object" && val !== null) {
232
- for (const k in val) {
233
- if (typeof val[k] === "function")
234
- return true;
235
- }
236
- }
237
- return false;
238
- }
239
- function normalizeClass(val) {
240
- if (!val)
241
- return "";
242
- if (typeof val === "function")
243
- return normalizeClass(val());
244
- if (typeof val === "string")
245
- return val.trim();
246
- if (typeof val === "number")
247
- return String(val);
248
- if (Array.isArray(val)) {
249
- let res = "";
250
- for (let i = 0;i < val.length; i++) {
251
- const item = typeof val[i] === "function" ? val[i]() : val[i];
252
- const itemStr = normalizeClass(item);
253
- if (itemStr) {
254
- res = res ? `${res} ${itemStr}` : itemStr;
255
- }
256
- }
257
- return res;
258
- }
259
- if (typeof val === "object") {
260
- let res = "";
261
- for (const key in val) {
262
- const condition = typeof val[key] === "function" ? val[key]() : val[key];
263
- if (condition) {
264
- res = res ? `${res} ${key}` : key;
265
- }
266
- }
267
- return res;
268
- }
269
- return "";
270
- }
271
- function cx(...args) {
272
- return normalizeClass(args);
273
- }
274
-
275
- // src/style/scale.ts
276
- var UNITLESS_PROPERTIES = new Set([
277
- "animationIterationCount",
278
- "aspectRatio",
279
- "borderImageSlice",
280
- "columnCount",
281
- "columns",
282
- "flex",
283
- "flexGrow",
284
- "flexShrink",
285
- "flexOrder",
286
- "fontWeight",
287
- "lineHeight",
288
- "opacity",
289
- "order",
290
- "orphans",
291
- "scale",
292
- "tabSize",
293
- "widows",
294
- "zIndex",
295
- "zoom",
296
- "fillOpacity",
297
- "strokeOpacity"
298
- ]);
299
- var DIMENSION_KEYWORDS = {
300
- screen: "100dvh",
301
- "screen-h": "100dvh",
302
- "screen-w": "100dvw",
303
- full: "100%",
304
- half: "50%",
305
- third: "33.333333%",
306
- "two-thirds": "66.666667%",
307
- quarter: "25%",
308
- "three-quarters": "75%",
309
- auto: "auto",
310
- min: "min-content",
311
- max: "max-content",
312
- fit: "fit-content"
313
- };
314
- function space(val) {
315
- if (val === undefined || val === null || val === "")
316
- return "";
317
- if (typeof val === "number") {
318
- if (val === 0)
319
- return "0px";
320
- return `${val * 4}px`;
321
- }
322
- const str = String(val).trim();
323
- if (str in DIMENSION_KEYWORDS) {
324
- return DIMENSION_KEYWORDS[str];
325
- }
326
- return str;
327
- }
328
- function resolveDimension(val) {
329
- if (val === undefined || val === null || val === "")
330
- return "";
331
- if (typeof val === "number") {
332
- if (val === 0)
333
- return "0px";
334
- if (val > 48)
335
- return `${val}px`;
336
- return `${val * 4}px`;
337
- }
338
- const str = String(val).trim();
339
- if (str in DIMENSION_KEYWORDS) {
340
- return DIMENSION_KEYWORDS[str];
341
- }
342
- return str;
343
- }
344
- function px(val) {
345
- return `${val}px`;
346
- }
347
- function rem(val) {
348
- return `${val}rem`;
349
- }
350
- function em(val) {
351
- return `${val}em`;
352
- }
353
- function fluid(minPx, maxPx, options) {
354
- const minVw = options?.minVw ?? 375;
355
- const maxVw = options?.maxVw ?? 1280;
356
- const slope = (maxPx - minPx) / (maxVw - minVw);
357
- const yIntercept = -minVw * slope + minPx;
358
- const slopeVw = slope * 100;
359
- const preferred = `${yIntercept.toFixed(2)}px + ${slopeVw.toFixed(2)}vw`;
360
- const min = Math.min(minPx, maxPx);
361
- const max = Math.max(minPx, maxPx);
362
- return `clamp(${min}px, ${preferred}, ${max}px)`;
363
- }
364
- var SHADOW_PRESETS = {
365
- none: "none",
366
- sm: "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
367
- md: "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",
368
- lg: "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)",
369
- xl: "0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1)",
370
- soft: "0 8px 30px rgba(0, 0, 0, 0.06)",
371
- glow: "0 0 24px rgba(168, 85, 247, 0.35)",
372
- inner: "inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)"
373
- };
374
- function shadow(variant) {
375
- if (variant in SHADOW_PRESETS) {
376
- return SHADOW_PRESETS[variant];
377
- }
378
- return variant;
379
- }
380
- var RADIUS_PRESETS = {
381
- none: "0px",
382
- sm: "4px",
383
- md: "8px",
384
- lg: "12px",
385
- xl: "16px",
386
- "2xl": "20px",
387
- "3xl": "24px",
388
- full: "9999px"
389
- };
390
- function radius(variant) {
391
- if (typeof variant === "number") {
392
- return `${variant}px`;
393
- }
394
- if (variant in RADIUS_PRESETS) {
395
- return RADIUS_PRESETS[variant];
396
- }
397
- return String(variant);
398
- }
399
- function glass(options = {}) {
400
- const blurVal = typeof options.blur === "number" ? `${options.blur}px` : options.blur ?? "20px";
401
- const tintVal = options.tint ?? "rgba(255, 255, 255, 0.65)";
402
- const borderVal = options.border ?? "1px solid rgba(255, 255, 255, 0.75)";
403
- return {
404
- backdropFilter: `blur(${blurVal})`,
405
- WebkitBackdropFilter: `blur(${blurVal})`,
406
- backgroundColor: tintVal,
407
- border: borderVal
408
- };
409
- }
410
- function formatStyleProp(prop, val) {
411
- if (val === null || val === undefined || val === "")
412
- return "";
413
- if (typeof val === "number") {
414
- if (val === 0 || UNITLESS_PROPERTIES.has(prop)) {
415
- return String(val);
416
- }
417
- return `${val}px`;
418
- }
419
- const str = String(val).trim();
420
- if (str in DIMENSION_KEYWORDS) {
421
- const lowerProp = prop.toLowerCase();
422
- if (str === "screen") {
423
- if (lowerProp.includes("width"))
424
- return "100dvw";
425
- return "100dvh";
426
- }
427
- return DIMENSION_KEYWORDS[str];
428
- }
429
- return str;
430
- }
431
-
432
- // src/dom/render.ts
433
- function isReactive(value) {
434
- return isSignal(value) || typeof value === "function";
435
- }
436
- function resolveValue(val) {
437
- if (typeof val === "function") {
438
- return val();
439
- }
440
- return val;
441
- }
442
- function render(fn, container) {
443
- return createRoot((dispose) => {
444
- container.textContent = "";
445
- const node = insertChild(container, fn());
446
- onCleanup(() => {
447
- if (node && node instanceof Node && node.parentNode === container) {
448
- container.removeChild(node);
449
- }
450
- });
451
- return dispose;
452
- });
453
- }
454
- function setAttribute(el, key, value) {
455
- if (key.startsWith("on") && typeof value === "function") {
456
- const eventName = key.startsWith("onCapture") ? key.slice(9).toLowerCase() : key.slice(2).toLowerCase();
457
- const useCapture = key.startsWith("onCapture");
458
- el.addEventListener(eventName, value, useCapture);
459
- onCleanup(() => {
460
- el.removeEventListener(eventName, value, useCapture);
461
- });
462
- return;
463
- }
464
- if (key === "ref" && typeof value === "function") {
465
- value(el);
466
- return;
467
- }
468
- if (key === "class" || key === "className") {
469
- if (hasReactiveClass(value)) {
470
- effect(() => {
471
- const cls = normalizeClass(value);
472
- if (cls)
473
- el.setAttribute("class", cls);
474
- else
475
- el.removeAttribute("class");
476
- });
477
- } else {
478
- const cls = normalizeClass(value);
479
- if (cls)
480
- el.setAttribute("class", cls);
481
- else
482
- el.removeAttribute("class");
483
- }
484
- return;
485
- }
486
- if (isReactive(value)) {
487
- effect(() => {
488
- const resolved = resolveValue(value);
489
- applyProp(el, key, resolved);
490
- });
491
- } else {
492
- applyProp(el, key, value);
493
- }
494
- }
495
- function setStyleProperty(el, prop, val) {
496
- const formatted = formatStyleProp(prop, val);
497
- if (prop.startsWith("--") || prop.includes("-")) {
498
- if (formatted === "") {
499
- el.style.removeProperty(prop);
500
- } else {
501
- el.style.setProperty(prop, formatted);
502
- }
503
- } else {
504
- el.style[prop] = formatted;
505
- }
506
- }
507
- function applyProp(el, key, value) {
508
- if (value === null || value === undefined || value === false && !key.startsWith("aria-") && !key.startsWith("data-")) {
509
- if (key === "className" || key === "class") {
510
- el.removeAttribute("class");
511
- } else if (key === "style" && typeof value === "string") {
512
- el.removeAttribute("style");
513
- } else if (key in el && !(el instanceof SVGElement)) {
514
- try {
515
- el[key] = typeof el[key] === "boolean" ? false : "";
516
- } catch {
517
- el.removeAttribute(key);
518
- }
519
- } else {
520
- el.removeAttribute(key);
521
- }
522
- return;
523
- }
524
- if (key === "className" || key === "class") {
525
- const cls = normalizeClass(value);
526
- if (cls) {
527
- el.setAttribute("class", cls);
528
- } else {
529
- el.removeAttribute("class");
530
- }
531
- } else if (key === "style") {
532
- if (typeof value === "string") {
533
- el.setAttribute("style", value);
534
- } else if (typeof value === "object" && value !== null) {
535
- for (const styleKey in value) {
536
- const styleVal = value[styleKey];
537
- if (isReactive(styleVal)) {
538
- effect(() => {
539
- setStyleProperty(el, styleKey, resolveValue(styleVal));
540
- });
541
- } else {
542
- setStyleProperty(el, styleKey, styleVal);
543
- }
544
- }
545
- }
546
- } else if (key === "dangerouslySetInnerHTML" && value && typeof value.__html === "string") {
547
- el.innerHTML = value.__html;
548
- } else if (key in el && !(el instanceof SVGElement) && key !== "list" && key !== "form") {
549
- try {
550
- el[key] = value;
551
- } catch {
552
- el.setAttribute(key, String(value));
553
- }
554
- } else {
555
- if (key.startsWith("aria-") || key.startsWith("data-")) {
556
- el.setAttribute(key, String(value));
557
- } else if (value === true) {
558
- el.setAttribute(key, "");
559
- } else {
560
- el.setAttribute(key, String(value));
561
- }
562
- }
563
- }
564
- function insertChild(parent, child, before = null) {
565
- if (child === null || child === undefined || child === false || child === true) {
566
- return null;
567
- }
568
- if (child instanceof Node) {
569
- parent.insertBefore(child, before);
570
- return child;
571
- }
572
- if (Array.isArray(child)) {
573
- const fragment = document.createDocumentFragment();
574
- for (const item of child) {
575
- insertChild(fragment, item);
576
- }
577
- parent.insertBefore(fragment, before);
578
- return fragment;
579
- }
580
- if (isReactive(child)) {
581
- const marker = document.createTextNode("");
582
- parent.insertBefore(marker, before);
583
- let childScope = null;
584
- let currentNodes = [];
585
- effect(() => {
586
- const resolved = resolveValue(child);
587
- if ((typeof resolved === "string" || typeof resolved === "number") && currentNodes.length === 1 && currentNodes[0].nodeType === Node.TEXT_NODE) {
588
- currentNodes[0].data = String(resolved);
589
- return;
590
- }
591
- if (childScope) {
592
- childScope.dispose();
593
- }
594
- childScope = new Scope(getActiveScope());
595
- runInScope(childScope, () => {
596
- for (const node of currentNodes) {
597
- if (node.parentNode) {
598
- node.parentNode.removeChild(node);
599
- }
600
- }
601
- currentNodes = [];
602
- if (resolved === null || resolved === undefined || resolved === false) {
603
- return;
604
- }
605
- const frag = document.createDocumentFragment();
606
- if (typeof resolved === "string" || typeof resolved === "number" || typeof resolved === "boolean") {
607
- frag.appendChild(document.createTextNode(String(resolved)));
608
- } else {
609
- insertChild(frag, resolved);
610
- }
611
- currentNodes = Array.from(frag.childNodes);
612
- if (marker.parentNode) {
613
- marker.parentNode.insertBefore(frag, marker);
614
- }
615
- });
616
- });
617
- onCleanup(() => {
618
- if (childScope) {
619
- childScope.dispose();
620
- }
621
- for (const node of currentNodes) {
622
- if (node.parentNode) {
623
- node.parentNode.removeChild(node);
624
- }
625
- }
626
- if (marker.parentNode) {
627
- marker.parentNode.removeChild(marker);
628
- }
629
- });
630
- return marker;
631
- }
632
- const textNode = document.createTextNode(String(child));
633
- parent.insertBefore(textNode, before);
634
- return textNode;
635
- }
636
-
637
- // src/signals/scope.ts
638
- class Scope {
639
- subscribers = new Set;
640
- cleanups = [];
641
- parent = null;
642
- isDisposed = false;
643
- context;
644
- constructor(parent = currentScope) {
645
- this.parent = parent;
646
- if (parent && !parent.isDisposed) {
647
- parent.cleanups.push(() => this.dispose());
648
- if (parent.context) {
649
- this.context = new Map(parent.context);
650
- }
651
- }
652
- }
653
- addSubscriber(sub) {
654
- if (this.isDisposed)
655
- return;
656
- this.subscribers.add(sub);
657
- }
658
- addCleanup(fn) {
659
- if (this.isDisposed) {
660
- fn();
661
- return;
662
- }
663
- this.cleanups.push(fn);
664
- }
665
- dispose() {
666
- if (this.isDisposed)
667
- return;
668
- this.isDisposed = true;
669
- for (const sub of this.subscribers) {
670
- sub.dispose();
671
- }
672
- this.subscribers.clear();
673
- for (let i = this.cleanups.length - 1;i >= 0; i--) {
674
- try {
675
- this.cleanups[i]();
676
- } catch (err) {
677
- console.error("Error during cleanup:", err);
678
- }
679
- }
680
- this.cleanups = [];
681
- }
682
- }
683
- function onCleanup(fn) {
684
- if (currentSubscriber && "addCleanup" in currentSubscriber) {
685
- currentSubscriber.addCleanup(fn);
686
- } else if (currentScope) {
687
- currentScope.addCleanup(fn);
688
- }
689
- }
690
- function createRoot(fn) {
691
- const prevScope = currentScope;
692
- const scope = new Scope(null);
693
- setCurrentScope(scope);
694
- try {
695
- return fn(() => scope.dispose());
696
- } finally {
697
- setCurrentScope(prevScope);
698
- }
699
- }
700
- function runInScope(scope, fn) {
701
- const prevScope = currentScope;
702
- setCurrentScope(scope);
703
- try {
704
- return fn();
705
- } finally {
706
- setCurrentScope(prevScope);
707
- }
708
- }
709
- function getActiveScope() {
710
- return getCurrentScope();
711
- }
712
-
713
- // src/signals/context.ts
714
- function createContext(defaultValue) {
715
- const id = Symbol("visage.context");
716
- const context = {
717
- id,
718
- defaultValue,
719
- Provider: (props) => {
720
- const parentScope = getActiveScope();
721
- const scope = new Scope(parentScope);
722
- if (!scope.context) {
723
- scope.context = new Map(parentScope?.context);
724
- }
725
- scope.context.set(id, props.value);
726
- return runInScope(scope, () => {
727
- const content = typeof props.children === "function" ? props.children() : props.children;
728
- if (typeof document !== "undefined") {
729
- const frag = document.createDocumentFragment();
730
- insertChild(frag, content);
731
- return frag;
732
- }
733
- return content;
734
- });
735
- }
736
- };
737
- return context;
738
- }
739
- function useContext(context) {
740
- let scope = getActiveScope();
741
- while (scope) {
742
- if (scope.context?.has(context.id)) {
743
- return scope.context.get(context.id);
744
- }
745
- scope = scope.parent;
746
- }
747
- return context.defaultValue;
748
- }
749
- // src/signals/effect.ts
750
- class Effect {
751
- _fn;
752
- sources = new Set;
753
- sourceVersions = new Map;
754
- cleanups = [];
755
- state = 2 /* DIRTY */;
756
- scope;
757
- constructor(fn) {
758
- this._fn = fn;
759
- this.scope = currentScope;
760
- if (currentScope) {
761
- currentScope.addSubscriber(this);
762
- }
763
- this.run();
764
- }
765
- addCleanup(fn) {
766
- this.cleanups.push(fn);
767
- }
768
- runCleanups() {
769
- for (let i = this.cleanups.length - 1;i >= 0; i--) {
770
- try {
771
- this.cleanups[i]();
772
- } catch (e) {
773
- console.error("Error in effect cleanup:", e);
774
- }
775
- }
776
- this.cleanups = [];
777
- }
778
- markDirty(targetState = 2 /* DIRTY */) {
779
- if (this.state >= targetState || this.state === 3 /* DISPOSED */) {
780
- return;
781
- }
782
- this.state = targetState;
783
- addPendingEffect(this);
784
- if (batchDepth === 0) {
785
- flushEffects();
786
- }
787
- }
788
- run() {
789
- if (this.state === 3 /* DISPOSED */)
790
- return;
791
- if (this.state === 1 /* CHECK_DIRTY */) {
792
- let isDirty = false;
793
- for (const source of this.sources) {
794
- if (source instanceof Computed) {
795
- source.updateIfNecessary();
796
- }
797
- const lastVersion = this.sourceVersions.get(source);
798
- if (lastVersion !== undefined && lastVersion !== source.version) {
799
- isDirty = true;
800
- }
801
- }
802
- if (!isDirty) {
803
- this.state = 0 /* CLEAN */;
804
- return;
805
- }
806
- }
807
- this.runCleanups();
808
- this.cleanupSources();
809
- const prevSubscriber = currentSubscriber;
810
- setCurrentSubscriber(this);
811
- const prevScope = currentScope;
812
- setCurrentScope(this.scope);
813
- try {
814
- this.state = 0 /* CLEAN */;
815
- const res = this._fn();
816
- if (typeof res === "function") {
817
- this.cleanups.push(res);
818
- }
819
- } finally {
820
- setCurrentSubscriber(prevSubscriber);
821
- setCurrentScope(prevScope);
822
- }
823
- }
824
- cleanupSources() {
825
- for (const source of this.sources) {
826
- source.removeSubscriber(this);
827
- }
828
- this.sources.clear();
829
- this.sourceVersions.clear();
830
- }
831
- dispose() {
832
- if (this.state === 3 /* DISPOSED */)
833
- return;
834
- this.state = 3 /* DISPOSED */;
835
- this.runCleanups();
836
- this.cleanupSources();
837
- removePendingEffect(this);
838
- }
839
- }
840
- function effect(fn) {
841
- const eff = new Effect(fn);
842
- return () => eff.dispose();
843
- }
844
- var createEffect = effect;
845
- // src/signals/signal.ts
846
- class Signal {
847
- [SIGNAL_BRAND] = true;
848
- _value;
849
- _subscribers = new Set;
850
- _equals;
851
- _onSet;
852
- version = 0;
853
- constructor(initialValue, equals, onSet) {
854
- this._value = initialValue;
855
- this._equals = equals ?? Object.is;
856
- this._onSet = onSet;
857
- }
858
- get() {
859
- if (currentSubscriber !== null && currentSubscriber.state !== 3 /* DISPOSED */) {
860
- this._subscribers.add(currentSubscriber);
861
- currentSubscriber.sources.add(this);
862
- currentSubscriber.sourceVersions.set(this, this.version);
863
- }
864
- return this._value;
865
- }
866
- set(newValue) {
867
- if (this._equals(this._value, newValue)) {
868
- return;
869
- }
870
- if (currentSubscriber !== null && this._subscribers.has(currentSubscriber)) {
871
- if (!warnedCyclicSubscribers.has(currentSubscriber)) {
872
- warnedCyclicSubscribers.add(currentSubscriber);
873
- if (typeof console !== "undefined" && typeof console.warn === "function") {
874
- 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():
875
- ` + ` untrack(() => signal())`);
876
- }
877
- }
878
- }
879
- this._value = newValue;
880
- this.version++;
881
- if (this._onSet) {
882
- this._onSet(newValue);
883
- }
884
- batch(() => {
885
- this.notify();
886
- });
887
- }
888
- update(fn) {
889
- this.set(fn(this._value));
890
- }
891
- get value() {
892
- return this.get();
893
- }
894
- set value(val) {
895
- this.set(val);
896
- }
897
- removeSubscriber(sub) {
898
- this._subscribers.delete(sub);
899
- }
900
- notify() {
901
- if (this._subscribers.size === 0)
902
- return;
903
- const subs = Array.from(this._subscribers);
904
- for (const sub of subs) {
905
- sub.markDirty(2 /* DIRTY */);
906
- }
907
- }
908
- }
909
- function resolveStorage(storageOption) {
910
- if (storageOption && typeof storageOption === "object") {
911
- return storageOption;
912
- }
913
- if (storageOption === "session") {
914
- try {
915
- if (typeof sessionStorage !== "undefined")
916
- return sessionStorage;
917
- } catch {}
918
- try {
919
- if (typeof window !== "undefined" && window.sessionStorage) {
920
- return window.sessionStorage;
921
- }
922
- } catch {}
923
- try {
924
- if (typeof globalThis !== "undefined" && globalThis.sessionStorage) {
925
- return globalThis.sessionStorage;
926
- }
927
- } catch {}
928
- return null;
929
- }
930
- try {
931
- if (typeof localStorage !== "undefined")
932
- return localStorage;
933
- } catch {}
934
- try {
935
- if (typeof window !== "undefined" && window.localStorage) {
936
- return window.localStorage;
937
- }
938
- } catch {}
939
- try {
940
- if (typeof globalThis !== "undefined" && globalThis.localStorage) {
941
- return globalThis.localStorage;
942
- }
943
- } catch {}
944
- return null;
945
- }
946
- function signal(initialValue, optionsOrEquals) {
947
- const equals = typeof optionsOrEquals === "function" ? optionsOrEquals : optionsOrEquals?.equals;
948
- const isInternal = typeof optionsOrEquals === "object" ? optionsOrEquals?.internal : false;
949
- const customName = typeof optionsOrEquals === "object" ? optionsOrEquals?.name : undefined;
950
- const persistOption = typeof optionsOrEquals === "object" ? optionsOrEquals?.persist : undefined;
951
- const persistConfig = persistOption ? typeof persistOption === "string" ? { key: persistOption } : persistOption : undefined;
952
- let effectiveInitial = initialValue;
953
- const storage = persistConfig ? resolveStorage(persistConfig.storage) : null;
954
- const serialize = persistConfig?.serialize ?? JSON.stringify;
955
- const deserialize = persistConfig?.deserialize ?? JSON.parse;
956
- if (persistConfig && storage) {
957
- try {
958
- const stored = storage.getItem(persistConfig.key);
959
- if (stored !== null) {
960
- effectiveInitial = deserialize(stored);
961
- }
962
- } catch {}
963
- }
964
- let isSyncing = false;
965
- const onSet = persistConfig && storage ? (val) => {
966
- if (isSyncing)
967
- return;
968
- try {
969
- storage.setItem(persistConfig.key, serialize(val));
970
- } catch {}
971
- } : undefined;
972
- const s = new Signal(effectiveInitial, equals, onSet);
973
- if (persistConfig && storage && (persistConfig.syncTabs ?? true) && typeof window !== "undefined" && typeof window.addEventListener === "function") {
974
- const onStorage = (e) => {
975
- if (e.key === persistConfig.key) {
976
- try {
977
- const nextVal = e.newValue !== null ? deserialize(e.newValue) : initialValue;
978
- isSyncing = true;
979
- try {
980
- s.set(nextVal);
981
- } finally {
982
- isSyncing = false;
983
- }
984
- } catch {}
985
- }
986
- };
987
- window.addEventListener("storage", onStorage);
988
- if (currentScope) {
989
- currentScope.addCleanup(() => {
990
- window.removeEventListener("storage", onStorage);
991
- });
992
- }
993
- }
994
- const accessor = (...args) => {
995
- if (args.length === 0) {
996
- return s.get();
997
- }
998
- s.set(args[0]);
999
- return args[0];
1000
- };
1001
- Object.defineProperties(accessor, {
1002
- [SIGNAL_BRAND]: { value: true },
1003
- get: { value: () => s.get() },
1004
- set: { value: (v) => s.set(v) },
1005
- update: { value: (fn) => s.update(fn) },
1006
- value: {
1007
- get: () => s.get(),
1008
- set: (v) => s.set(v)
1009
- }
1010
- });
1011
- if (!isInternal && typeof window !== "undefined" && window.__VISAGE_DEVTOOLS__) {
1012
- const devtools = window.__VISAGE_DEVTOOLS__;
1013
- const sigId = devtools.registerSignal({
1014
- name: customName,
1015
- type: "signal",
1016
- getValue: () => s.get(),
1017
- version: () => s.version,
1018
- subscribersCount: () => s._subscribers?.size ?? 0,
1019
- dependents: () => Array.from(s._subscribers ?? []).map((sub) => sub._devId).filter(Boolean)
1020
- });
1021
- s._devId = sigId;
1022
- if (currentScope) {
1023
- currentScope.addCleanup(() => {
1024
- devtools.unregisterSignal(sigId);
1025
- });
1026
- }
1027
- }
1028
- return accessor;
1029
- }
1030
- function createSignal(initialValue, optionsOrEquals) {
1031
- const s = signal(initialValue, optionsOrEquals);
1032
- const setter = (value) => {
1033
- if (typeof value === "function") {
1034
- s.update(value);
1035
- } else {
1036
- s.set(value);
1037
- }
1038
- };
1039
- return [s, setter];
1040
- }
1041
- // src/signals/store.ts
1042
- var STORE_RAW = Symbol("visage.store.raw");
1043
- var STORE_SIGNALS = Symbol("visage.store.signals");
1044
- var STORE_PROXY = Symbol("visage.store.proxy");
1045
- function isObject(val) {
1046
- return typeof val === "object" && val !== null && (typeof Node === "undefined" || !(val instanceof Node)) && !isSignal(val);
1047
- }
1048
- function getOrCreatePropertySignal(target, prop) {
1049
- let signalsMap = target[STORE_SIGNALS];
1050
- if (!signalsMap) {
1051
- signalsMap = new Map;
1052
- Object.defineProperty(target, STORE_SIGNALS, {
1053
- value: signalsMap,
1054
- enumerable: false,
1055
- writable: true
1056
- });
1057
- }
1058
- let sig = signalsMap.get(prop);
1059
- if (!sig) {
1060
- sig = new Signal(target[prop]);
1061
- signalsMap.set(prop, sig);
1062
- }
1063
- return sig;
1064
- }
1065
- function createStoreProxy(target) {
1066
- if (!isObject(target))
1067
- return target;
1068
- if (target[STORE_PROXY])
1069
- return target[STORE_PROXY];
1070
- const proxy = new Proxy(target, {
1071
- get(target, prop, receiver) {
1072
- if (prop === STORE_RAW)
1073
- return target;
1074
- if (prop === STORE_PROXY)
1075
- return proxy;
1076
- if (typeof prop === "string" || typeof prop === "symbol") {
1077
- const sig = getOrCreatePropertySignal(target, prop);
1078
- sig.get();
1079
- }
1080
- const value = Reflect.get(target, prop, receiver);
1081
- if (isObject(value)) {
1082
- return createStoreProxy(value);
1083
- }
1084
- return value;
1085
- },
1086
- set(target, prop, value, receiver) {
1087
- const prevValue = Reflect.get(target, prop, receiver);
1088
- if (Object.is(prevValue, value)) {
1089
- return true;
1090
- }
1091
- const success = Reflect.set(target, prop, value, receiver);
1092
- if (success) {
1093
- const sig = getOrCreatePropertySignal(target, prop);
1094
- sig.set(value);
1095
- if (Array.isArray(target) && prop !== "length") {
1096
- const lenSig = getOrCreatePropertySignal(target, "length");
1097
- lenSig.set(target.length);
1098
- }
1099
- }
1100
- return success;
1101
- },
1102
- deleteProperty(target, prop) {
1103
- const hadProp = Reflect.has(target, prop);
1104
- const success = Reflect.deleteProperty(target, prop);
1105
- if (hadProp && success) {
1106
- const sig = getOrCreatePropertySignal(target, prop);
1107
- sig.set(undefined);
1108
- }
1109
- return success;
1110
- }
1111
- });
1112
- Object.defineProperty(target, STORE_PROXY, {
1113
- value: proxy,
1114
- enumerable: false,
1115
- writable: true
1116
- });
1117
- return proxy;
1118
- }
1119
- function createStore(initialState) {
1120
- if (!isObject(initialState)) {
1121
- throw new Error("createStore requires an object or array as initial state");
1122
- }
1123
- return createStoreProxy(initialState);
1124
- }
1125
- function mutateStore(store, mutator) {
1126
- batch(() => {
1127
- mutator(store);
1128
- });
1129
- }
1130
- function unwrapStore(store) {
1131
- if (isObject(store) && store[STORE_RAW]) {
1132
- return store[STORE_RAW];
1133
- }
1134
- return store;
1135
- }
1136
- // src/style/hash.ts
1137
- function hashString(str) {
1138
- let hash = 2166136261;
1139
- for (let i = 0;i < str.length; i++) {
1140
- hash ^= str.charCodeAt(i);
1141
- hash = Math.imul(hash, 16777619);
1142
- }
1143
- return (hash >>> 0).toString(36);
1144
- }
1145
- function getScopeId(css, prefix = "v") {
1146
- const hash = hashString(css.trim());
1147
- return `${prefix}-${hash}`;
1148
- }
1149
-
1150
- // src/style/manager.ts
1151
- class StyleManager {
1152
- _styles = new Map;
1153
- _ssrStyles = new Set;
1154
- inject(id, css) {
1155
- let entry = this._styles.get(id);
1156
- if (!entry) {
1157
- entry = { id, css, count: 0 };
1158
- this._styles.set(id, entry);
1159
- if (typeof document !== "undefined") {
1160
- const target = document.head || document.documentElement || document.body;
1161
- if (target) {
1162
- const styleEl = document.createElement("style");
1163
- styleEl.id = `visage-style-${id}`;
1164
- styleEl.setAttribute("data-visage-scope", id);
1165
- styleEl.textContent = css;
1166
- target.appendChild(styleEl);
1167
- entry.element = styleEl;
1168
- }
1169
- }
1170
- this._ssrStyles.add(css);
1171
- }
1172
- entry.count++;
1173
- return () => {
1174
- if (!entry)
1175
- return;
1176
- entry.count--;
1177
- if (entry.count <= 0) {
1178
- if (entry.element?.parentNode) {
1179
- entry.element.parentNode.removeChild(entry.element);
1180
- }
1181
- this._styles.delete(id);
1182
- }
1183
- };
1184
- }
1185
- has(id) {
1186
- return this._styles.has(id);
1187
- }
1188
- extractSSRStyles() {
1189
- return Array.from(this._ssrStyles).join(`
1190
- `);
1191
- }
1192
- clear() {
1193
- for (const entry of this._styles.values()) {
1194
- if (entry.element?.parentNode) {
1195
- entry.element.parentNode.removeChild(entry.element);
1196
- }
1197
- }
1198
- this._styles.clear();
1199
- this._ssrStyles.clear();
1200
- }
1201
- }
1202
- var styleManager = new StyleManager;
1203
- function extractStyleTags() {
1204
- const css = styleManager.extractSSRStyles();
1205
- return css ? `<style data-visage-ssr="true">${css}</style>` : "";
1206
- }
1207
-
1208
- // src/style/parser.ts
1209
- function scopeSelector(selector, options) {
1210
- const { scopeId, passToChildren = false } = options;
1211
- const scopeAttr = `[data-${scopeId}]`;
1212
- const parts = splitSelectorList(selector);
1213
- return parts.map((part) => {
1214
- const trimmed = part.trim();
1215
- if (!trimmed)
1216
- return "";
1217
- if (trimmed.includes(":global(") || trimmed.includes("::v-global(")) {
1218
- return trimmed.replace(/(.*?)(?:::v-global|:global)\(([^)]+)\)(.*)/g, (_match, before, globalTarget, after) => {
1219
- const prefix = before.trim();
1220
- const scopedPrefix = prefix ? scopeCompoundSelector(prefix, scopeAttr) : "";
1221
- if (scopedPrefix) {
1222
- return `${scopedPrefix} ${globalTarget.trim()}${after}`;
1223
- }
1224
- return `${globalTarget.trim()}${after}`;
1225
- }).trim();
1226
- }
1227
- if (trimmed.includes(":deep(") || trimmed.includes("::v-deep(")) {
1228
- return trimmed.replace(/(.*?)(?:::v-deep|:deep)\(([^)]+)\)(.*)/g, (_match, before, deepTarget, after) => {
1229
- const prefix = before.trim();
1230
- const scopedPrefix = prefix ? scopeCompoundSelector(prefix, scopeAttr) : scopeAttr;
1231
- return `${scopedPrefix} ${deepTarget.trim()}${after}`;
1232
- }).trim();
1233
- }
1234
- if (passToChildren) {
1235
- const compound = scopeCompoundSelector(trimmed, scopeAttr);
1236
- return `${scopeAttr} ${trimmed}, ${compound}`;
1237
- }
1238
- return scopeCompoundSelector(trimmed, scopeAttr);
1239
- }).filter(Boolean).join(", ");
1240
- }
1241
- function scopeCompoundSelector(selector, scopeAttr) {
1242
- const combinatorRegex = /([ >+~]+)/;
1243
- const tokens = selector.split(combinatorRegex);
1244
- const scopedTokens = tokens.map((token, index) => {
1245
- if (index % 2 === 1)
1246
- return token;
1247
- const piece = token.trim();
1248
- if (!piece || piece === "*")
1249
- return piece ? `${piece}${scopeAttr}` : "";
1250
- const pseudoElemIdx = piece.indexOf("::");
1251
- if (pseudoElemIdx !== -1) {
1252
- const base = piece.slice(0, pseudoElemIdx);
1253
- const pseudo = piece.slice(pseudoElemIdx);
1254
- return `${base}${scopeAttr}${pseudo}`;
1255
- }
1256
- const pseudoClassIdx = piece.indexOf(":");
1257
- if (pseudoClassIdx !== -1) {
1258
- const base = piece.slice(0, pseudoClassIdx);
1259
- const pseudo = piece.slice(pseudoClassIdx);
1260
- return `${base}${scopeAttr}${pseudo}`;
1261
- }
1262
- return `${piece}${scopeAttr}`;
1263
- });
1264
- return scopedTokens.join("");
1265
- }
1266
- function splitSelectorList(selectorList) {
1267
- const result = [];
1268
- let depth = 0;
1269
- let current = "";
1270
- for (let i = 0;i < selectorList.length; i++) {
1271
- const char = selectorList[i];
1272
- if (char === "(") {
1273
- depth++;
1274
- current += char;
1275
- } else if (char === ")") {
1276
- depth = Math.max(0, depth - 1);
1277
- current += char;
1278
- } else if (char === "," && depth === 0) {
1279
- if (current.trim())
1280
- result.push(current.trim());
1281
- current = "";
1282
- } else {
1283
- current += char;
1284
- }
1285
- }
1286
- if (current.trim())
1287
- result.push(current.trim());
1288
- return result;
1289
- }
1290
- function scopeCSS(css, options) {
1291
- const { scopeId } = options;
1292
- const keyframeNames = new Set;
1293
- const keyframeRegex = /@(?:-webkit-)?keyframes\s+([a-zA-Z0-9_-]+)/g;
1294
- let kMatch = keyframeRegex.exec(css);
1295
- while (kMatch !== null) {
1296
- if (kMatch[1]) {
1297
- keyframeNames.add(kMatch[1]);
1298
- }
1299
- kMatch = keyframeRegex.exec(css);
1300
- }
1301
- let processed = css;
1302
- for (const name of keyframeNames) {
1303
- const scopedName = `${scopeId}-${name}`;
1304
- const defRegex = new RegExp(`(@(?:-webkit-)?keyframes\\s+)${name}\\b`, "g");
1305
- processed = processed.replace(defRegex, `$1${scopedName}`);
1306
- }
1307
- if (keyframeNames.size > 0) {
1308
- for (const name of keyframeNames) {
1309
- const scopedName = `${scopeId}-${name}`;
1310
- const animRegex = new RegExp(`(animation(?:-name)?\\s*:[^;}]*?)\\b${name}\\b([^;}]*)`, "g");
1311
- processed = processed.replace(animRegex, `$1${scopedName}$2`);
1312
- }
1313
- }
1314
- return transformRules(processed, options);
1315
- }
1316
- function transformRules(css, options) {
1317
- let output = "";
1318
- let i = 0;
1319
- const len = css.length;
1320
- while (i < len) {
1321
- while (i < len && /\s/.test(css[i])) {
1322
- output += css[i];
1323
- i++;
1324
- }
1325
- if (i >= len)
1326
- break;
1327
- if (css[i] === "/" && css[i + 1] === "*") {
1328
- const endComment = css.indexOf("*/", i + 2);
1329
- if (endComment === -1) {
1330
- output += css.slice(i);
1331
- break;
1332
- }
1333
- output += css.slice(i, endComment + 2);
1334
- i = endComment + 2;
1335
- continue;
1336
- }
1337
- const openBrace = css.indexOf("{", i);
1338
- if (openBrace === -1) {
1339
- output += css.slice(i);
1340
- break;
1341
- }
1342
- const header = css.slice(i, openBrace).trim();
1343
- if (header.startsWith("@")) {
1344
- if (header.startsWith("@media") || header.startsWith("@supports") || header.startsWith("@container")) {
1345
- const closeBrace = findMatchingBrace(css, openBrace);
1346
- const innerContent = css.slice(openBrace + 1, closeBrace);
1347
- const transformedInner = transformRules(innerContent, options);
1348
- output += `${header} {
1349
- ${transformedInner}
1350
- }`;
1351
- i = closeBrace + 1;
1352
- continue;
1353
- }
1354
- if (header.includes("keyframes") || header.startsWith("@font-face")) {
1355
- const closeBrace = findMatchingBrace(css, openBrace);
1356
- output += css.slice(i, closeBrace + 1);
1357
- i = closeBrace + 1;
1358
- continue;
1359
- }
1360
- }
1361
- const closeBrace = css.indexOf("}", openBrace);
1362
- if (closeBrace === -1) {
1363
- output += css.slice(i);
1364
- break;
1365
- }
1366
- const body = css.slice(openBrace + 1, closeBrace);
1367
- const scopedSelector = scopeSelector(header, options);
1368
- output += `${scopedSelector} {${body}}`;
1369
- i = closeBrace + 1;
1370
- }
1371
- return output;
1372
- }
1373
- function findMatchingBrace(str, openIndex) {
1374
- let depth = 0;
1375
- for (let i = openIndex;i < str.length; i++) {
1376
- if (str[i] === "{")
1377
- depth++;
1378
- else if (str[i] === "}") {
1379
- depth--;
1380
- if (depth === 0)
1381
- return i;
1382
- }
1383
- }
1384
- return str.length - 1;
1385
- }
1386
-
1387
- // src/style/create-style.ts
1388
- function formatCSSValue(prop, val) {
1389
- return formatStyleProp(prop, val);
1390
- }
1391
- function objectToCSS(classes) {
1392
- let css = "";
1393
- for (const [selector, rules] of Object.entries(classes)) {
1394
- if (typeof rules !== "object" || rules === null)
1395
- continue;
1396
- const sel = selector.startsWith(".") || selector.startsWith("@") || selector.startsWith(":") || selector.includes(" ") || selector === "*" ? selector : `.${selector}`;
1397
- let mainRules = "";
1398
- let nestedRules = "";
1399
- for (const [prop, val] of Object.entries(rules)) {
1400
- if (typeof val === "object" && val !== null) {
1401
- const nestedSel = prop.startsWith("&") ? prop.replace(/&/g, sel) : prop.startsWith(":") ? `${sel}${prop}` : `${sel} ${prop}`;
1402
- nestedRules += `${nestedSel} {
1403
- `;
1404
- for (const [np, nv] of Object.entries(val)) {
1405
- if (nv !== undefined && nv !== null) {
1406
- const kebab = np.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
1407
- nestedRules += ` ${kebab}: ${formatCSSValue(np, nv)};
1408
- `;
1409
- }
1410
- }
1411
- nestedRules += `}
1412
- `;
1413
- } else if (val !== undefined && val !== null) {
1414
- const kebab = prop.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
1415
- mainRules += ` ${kebab}: ${formatCSSValue(prop, val)};
1416
- `;
1417
- }
1418
- }
1419
- if (mainRules) {
1420
- css += `${sel} {
1421
- ${mainRules}}
1422
- `;
1423
- }
1424
- if (nestedRules) {
1425
- css += nestedRules;
1426
- }
1427
- }
1428
- return css;
1429
- }
1430
- function createStyle(templateOrObject, ...valuesOrOptions) {
1431
- let cssInput = "";
1432
- let options;
1433
- if (typeof templateOrObject === "object" && !Array.isArray(templateOrObject)) {
1434
- cssInput = objectToCSS(templateOrObject);
1435
- options = valuesOrOptions[0];
1436
- } else if (typeof templateOrObject === "string") {
1437
- cssInput = templateOrObject;
1438
- options = valuesOrOptions[0];
1439
- } else {
1440
- const template = templateOrObject;
1441
- for (let i = 0;i < template.length; i++) {
1442
- cssInput += template[i];
1443
- if (i < valuesOrOptions.length) {
1444
- cssInput += String(valuesOrOptions[i]);
1445
- }
1446
- }
1447
- }
1448
- const scopeId = options?.id ?? getScopeId(cssInput);
1449
- const scopeAttr = `data-${scopeId}`;
1450
- const classMap = {};
1451
- const classRegex = /\.([a-zA-Z0-9_-]+)/g;
1452
- let match = classRegex.exec(cssInput);
1453
- while (match !== null) {
1454
- const className = match[1];
1455
- if (className && !classMap[className]) {
1456
- classMap[className] = `${className}_${scopeId}`;
1457
- }
1458
- match = classRegex.exec(cssInput);
1459
- }
1460
- let transformedCSS = cssInput;
1461
- for (const [orig, scoped] of Object.entries(classMap)) {
1462
- const replaceRegex = new RegExp(`\\.${orig}\\b`, "g");
1463
- transformedCSS = transformedCSS.replace(replaceRegex, `.${scoped}`);
1464
- }
1465
- const finalScopedCSS = scopeCSS(transformedCSS, {
1466
- scopeId,
1467
- passToChildren: options?.passToChildren ?? false
1468
- });
1469
- styleManager.inject(scopeId, finalScopedCSS);
1470
- const result = {
1471
- ...classMap,
1472
- scope: scopeId,
1473
- scopeAttr,
1474
- css: finalScopedCSS,
1475
- cx: (...args) => cx(...args)
1476
- };
1477
- return result;
1478
- }
1479
- function css(strings, ...values) {
1480
- let rawCSS = "";
1481
- for (let i = 0;i < strings.length; i++) {
1482
- rawCSS += strings[i];
1483
- if (i < values.length) {
1484
- rawCSS += String(values[i]);
1485
- }
1486
- }
1487
- const scopeId = getScopeId(rawCSS, "cls");
1488
- const className = `visage_${scopeId}`;
1489
- const fullCSS = rawCSS.includes("&") ? rawCSS.replace(/&/g, `.${className}`) : `.${className} { ${rawCSS} }`;
1490
- const scoped = scopeCSS(fullCSS, { scopeId });
1491
- styleManager.inject(scopeId, scoped);
1492
- return className;
1493
- }
1494
- function useStyle(cssInput, options) {
1495
- const getRaw = () => {
1496
- const val = typeof cssInput === "function" ? cssInput() : cssInput;
1497
- return typeof val === "object" ? objectToCSS(val) : val;
1498
- };
1499
- const raw = getRaw();
1500
- const scopeId = options?.id ?? getScopeId(raw);
1501
- const scopedCSS = scopeCSS(raw, {
1502
- scopeId,
1503
- passToChildren: options?.passToChildren ?? false
1504
- });
1505
- const cleanup = styleManager.inject(scopeId, scopedCSS);
1506
- onCleanup(() => {
1507
- cleanup();
1508
- });
1509
- return scopeId;
1510
- }
1511
-
1512
- // src/style/component.tsx
1513
- function Style(props) {
1514
- const getRawCSS = () => {
1515
- if (props.classes) {
1516
- const cls = typeof props.classes === "function" ? props.classes() : props.classes;
1517
- return objectToCSS(cls);
1518
- }
1519
- if (props.children) {
1520
- const ch = typeof props.children === "function" ? props.children() : props.children;
1521
- return typeof ch === "object" ? objectToCSS(ch) : ch;
1522
- }
1523
- return "";
1524
- };
1525
- const rawCSS = getRawCSS();
1526
- const scopeId = props.id ?? getScopeId(rawCSS);
1527
- const scopeAttr = `data-${scopeId}`;
1528
- if (typeof document !== "undefined") {
1529
- const marker = document.createTextNode("");
1530
- let unsubscribe = null;
1531
- effect(() => {
1532
- const currentCSS = getRawCSS();
1533
- const currentScopeId = props.id ?? getScopeId(currentCSS);
1534
- const scoped = scopeCSS(currentCSS, {
1535
- scopeId: currentScopeId,
1536
- passToChildren: props.passToChildren ?? true
1537
- });
1538
- if (unsubscribe) {
1539
- unsubscribe();
1540
- }
1541
- unsubscribe = styleManager.inject(currentScopeId, scoped);
1542
- const attachScope = () => {
1543
- const parent = marker.parentElement || marker.parentNode;
1544
- if (parent && typeof parent.setAttribute === "function") {
1545
- parent.setAttribute(`data-${currentScopeId}`, "");
1546
- }
1547
- };
1548
- attachScope();
1549
- queueMicrotask(attachScope);
1550
- });
1551
- onCleanup(() => {
1552
- if (unsubscribe) {
1553
- unsubscribe();
1554
- }
1555
- const parent = marker.parentElement || marker.parentNode;
1556
- if (parent && typeof parent.removeAttribute === "function") {
1557
- parent.removeAttribute(scopeAttr);
1558
- }
1559
- });
1560
- return marker;
1561
- }
1562
- const scoped = scopeCSS(rawCSS, {
1563
- scopeId,
1564
- passToChildren: props.passToChildren ?? true
1565
- });
1566
- styleManager.inject(scopeId, scoped);
1567
- return null;
1568
- }
1569
- // src/dom/resource.ts
1570
- var SuspenseContext = createContext(null);
1571
- function createResource(sourceOrFetcher, maybeFetcher) {
1572
- const isDirect = typeof maybeFetcher !== "function";
1573
- const fetcher = isDirect ? sourceOrFetcher : maybeFetcher;
1574
- const source = isDirect ? null : sourceOrFetcher;
1575
- const data = signal(undefined);
1576
- const loading = signal(true);
1577
- const error = signal(null);
1578
- let currentPromise = null;
1579
- let requestId = 0;
1580
- const load = async (arg) => {
1581
- const currentReq = ++requestId;
1582
- loading.set(true);
1583
- error.set(null);
1584
- const promise = isDirect ? fetcher() : fetcher(arg);
1585
- currentPromise = promise;
1586
- const suspense = useContext(SuspenseContext);
1587
- if (suspense) {
1588
- suspense.registerPromise(promise);
1589
- }
1590
- try {
1591
- const res = await promise;
1592
- if (currentReq === requestId) {
1593
- data.set(res);
1594
- loading.set(false);
1595
- currentPromise = null;
1596
- }
1597
- return res;
1598
- } catch (err) {
1599
- if (currentReq === requestId) {
1600
- error.set(err);
1601
- loading.set(false);
1602
- currentPromise = null;
1603
- }
1604
- throw err;
1605
- }
1606
- };
1607
- if (source) {
1608
- effect(() => {
1609
- const sourceVal = resolveValue(source);
1610
- if (sourceVal !== false && sourceVal !== null && sourceVal !== undefined) {
1611
- load(sourceVal).catch(() => {});
1612
- }
1613
- });
1614
- } else {
1615
- load().catch(() => {});
1616
- }
1617
- const accessor = () => {
1618
- if (loading() && currentPromise) {
1619
- const suspense = useContext(SuspenseContext);
1620
- if (suspense) {
1621
- suspense.registerPromise(currentPromise);
1622
- }
1623
- }
1624
- return data();
1625
- };
1626
- Object.defineProperties(accessor, {
1627
- loading: { get: () => loading },
1628
- error: { get: () => error },
1629
- mutate: { value: (val) => data.set(val) },
1630
- refetch: { value: () => source ? load(resolveValue(source)) : load() }
1631
- });
1632
- return accessor;
1633
- }
1634
-
1635
- // src/dom/lazy.ts
1636
- function lazy(importer) {
1637
- let loadedComponent = null;
1638
- let loadingPromise = null;
1639
- const preload = () => {
1640
- if (loadedComponent) {
1641
- return Promise.resolve(loadedComponent);
1642
- }
1643
- if (!loadingPromise) {
1644
- loadingPromise = importer().then((mod) => {
1645
- const comp = mod && typeof mod === "object" && "default" in mod ? mod.default : mod;
1646
- loadedComponent = comp;
1647
- return comp;
1648
- }).catch((err) => {
1649
- loadingPromise = null;
1650
- throw err;
1651
- });
1652
- }
1653
- return loadingPromise;
1654
- };
1655
- const LazyWrapper = (props) => {
1656
- if (loadedComponent) {
1657
- return loadedComponent(props);
1658
- }
1659
- const promise = preload();
1660
- const suspense = useContext(SuspenseContext);
1661
- if (suspense) {
1662
- suspense.registerPromise(promise);
1663
- }
1664
- const res = createResource(() => promise);
1665
- return () => {
1666
- const Comp = res();
1667
- return Comp ? Comp(props) : null;
1668
- };
1669
- };
1670
- LazyWrapper.preload = preload;
1671
- return LazyWrapper;
1672
- }
1673
- // src/dom/async.ts
1674
- function Suspense(props) {
1675
- if (typeof document === "undefined") {
1676
- return typeof props.children === "function" ? props.children() : props.children;
1677
- }
1678
- const marker = document.createTextNode("");
1679
- const initialFrag = document.createDocumentFragment();
1680
- const pendingCount = signal(0);
1681
- let currentScope = null;
1682
- let currentNodes = [];
1683
- let isMounted = false;
1684
- const suspenseValue = {
1685
- registerPromise(p) {
1686
- pendingCount.update((c) => c + 1);
1687
- p.finally(() => {
1688
- pendingCount.update((c) => Math.max(0, c - 1));
1689
- });
1690
- }
1691
- };
1692
- const renderContent = (content) => {
1693
- const parent = marker.parentNode ?? (!isMounted ? initialFrag : null);
1694
- if (!parent)
1695
- return;
1696
- for (const n of currentNodes) {
1697
- if (n.parentNode)
1698
- n.parentNode.removeChild(n);
1699
- }
1700
- currentNodes = [];
1701
- const frag = document.createDocumentFragment();
1702
- insertChild(frag, content);
1703
- currentNodes = Array.from(frag.childNodes);
1704
- if (marker.parentNode) {
1705
- marker.parentNode.insertBefore(frag, marker);
1706
- } else if (!isMounted) {
1707
- initialFrag.appendChild(frag);
1708
- }
1709
- };
1710
- effect(() => {
1711
- if (currentScope) {
1712
- currentScope.dispose();
1713
- currentScope = null;
1714
- }
1715
- currentScope = new Scope(getActiveScope());
1716
- runInScope(currentScope, () => {
1717
- let threwPromise = null;
1718
- let rendered = null;
1719
- try {
1720
- const SuspenseProvider = SuspenseContext.Provider;
1721
- rendered = SuspenseProvider({
1722
- value: suspenseValue,
1723
- children: props.children
1724
- });
1725
- } catch (err) {
1726
- if (err && typeof err.then === "function") {
1727
- threwPromise = err;
1728
- suspenseValue.registerPromise(err);
1729
- } else {
1730
- throw err;
1731
- }
1732
- }
1733
- if (pendingCount() > 0 || threwPromise) {
1734
- renderContent(props.fallback);
1735
- } else {
1736
- renderContent(rendered);
1737
- }
1738
- });
1739
- });
1740
- isMounted = true;
1741
- initialFrag.appendChild(marker);
1742
- onCleanup(() => {
1743
- if (currentScope)
1744
- currentScope.dispose();
1745
- });
1746
- return initialFrag;
1747
- }
1748
- function ErrorBoundary(props) {
1749
- if (typeof document === "undefined") {
1750
- try {
1751
- return typeof props.children === "function" ? props.children() : props.children;
1752
- } catch (err) {
1753
- return typeof props.fallback === "function" ? props.fallback(err, () => {}) : props.fallback;
1754
- }
1755
- }
1756
- const marker = document.createTextNode("");
1757
- const initialFrag = document.createDocumentFragment();
1758
- const currentError = signal(null);
1759
- let currentScope = null;
1760
- let currentNodes = [];
1761
- let isMounted = false;
1762
- const reset = () => {
1763
- currentError.set(null);
1764
- };
1765
- const renderNodes = (child) => {
1766
- const parent = marker.parentNode ?? (!isMounted ? initialFrag : null);
1767
- if (!parent)
1768
- return;
1769
- for (const n of currentNodes) {
1770
- if (n.parentNode)
1771
- n.parentNode.removeChild(n);
1772
- }
1773
- currentNodes = [];
1774
- const frag = document.createDocumentFragment();
1775
- insertChild(frag, child);
1776
- currentNodes = Array.from(frag.childNodes);
1777
- if (marker.parentNode) {
1778
- marker.parentNode.insertBefore(frag, marker);
1779
- } else if (!isMounted) {
1780
- initialFrag.appendChild(frag);
1781
- }
1782
- };
1783
- effect(() => {
1784
- const err = currentError();
1785
- if (currentScope) {
1786
- currentScope.dispose();
1787
- currentScope = null;
1788
- }
1789
- currentScope = new Scope(getActiveScope());
1790
- runInScope(currentScope, () => {
1791
- if (err !== null) {
1792
- const fallbackNode = typeof props.fallback === "function" ? props.fallback(err, reset) : props.fallback;
1793
- renderNodes(fallbackNode);
1794
- } else {
1795
- try {
1796
- const content = typeof props.children === "function" ? props.children() : props.children;
1797
- renderNodes(content);
1798
- } catch (catchedErr) {
1799
- currentError.set(catchedErr);
1800
- }
1801
- }
1802
- });
1803
- });
1804
- isMounted = true;
1805
- initialFrag.appendChild(marker);
1806
- onCleanup(() => {
1807
- if (currentScope)
1808
- currentScope.dispose();
1809
- });
1810
- return initialFrag;
1811
- }
1812
- // src/dom/control-flow.ts
1813
- function Show(props) {
1814
- if (typeof document === "undefined") {
1815
- const condition = resolveValue(props.when);
1816
- if (condition) {
1817
- return typeof props.children === "function" && props.children.length > 0 ? props.children(() => resolveValue(props.when)) : typeof props.children === "function" ? props.children() : props.children;
1818
- }
1819
- return props.fallback ?? null;
1820
- }
1821
- const marker = document.createComment("visage-show");
1822
- const initialFrag = document.createDocumentFragment();
1823
- initialFrag.appendChild(marker);
1824
- let currentScope = null;
1825
- let currentContent = [];
1826
- effect(() => {
1827
- const condition = resolveValue(props.when);
1828
- if (currentScope) {
1829
- currentScope.dispose();
1830
- currentScope = null;
1831
- }
1832
- for (const node of currentContent) {
1833
- if (node.parentNode) {
1834
- node.parentNode.removeChild(node);
1835
- }
1836
- }
1837
- currentContent = [];
1838
- const frag = document.createDocumentFragment();
1839
- if (condition) {
1840
- currentScope = new Scope(getActiveScope());
1841
- untrack(() => {
1842
- runInScope(currentScope, () => {
1843
- const childRes = typeof props.children === "function" && props.children.length > 0 ? props.children(() => resolveValue(props.when)) : typeof props.children === "function" ? props.children() : props.children;
1844
- insertChild(frag, childRes);
1845
- });
1846
- });
1847
- } else if (props.fallback !== undefined) {
1848
- currentScope = new Scope(getActiveScope());
1849
- untrack(() => {
1850
- runInScope(currentScope, () => {
1851
- const fallbackRes = typeof props.fallback === "function" ? props.fallback() : props.fallback;
1852
- insertChild(frag, fallbackRes);
1853
- });
1854
- });
1855
- }
1856
- currentContent = Array.from(frag.childNodes);
1857
- const parent = marker.parentNode;
1858
- if (parent) {
1859
- parent.insertBefore(frag, marker);
1860
- }
1861
- });
1862
- onCleanup(() => {
1863
- if (currentScope) {
1864
- currentScope.dispose();
1865
- }
1866
- for (const node of currentContent) {
1867
- if (node.parentNode) {
1868
- node.parentNode.removeChild(node);
1869
- }
1870
- }
1871
- if (marker.parentNode) {
1872
- marker.parentNode.removeChild(marker);
1873
- }
1874
- });
1875
- return initialFrag;
1876
- }
1877
- function For(props) {
1878
- if (typeof document === "undefined") {
1879
- const list = resolveValue(props.each) ?? [];
1880
- if (list.length === 0) {
1881
- return props.fallback ?? null;
1882
- }
1883
- return list.map((item, idx) => props.children(item, () => idx));
1884
- }
1885
- const marker = document.createTextNode("");
1886
- const initialFrag = document.createDocumentFragment();
1887
- let items = [];
1888
- let fallbackScope = null;
1889
- let fallbackNodes = [];
1890
- let isMounted = false;
1891
- effect(() => {
1892
- const list = resolveValue(props.each) ?? [];
1893
- const parent = marker.parentNode ?? (!isMounted ? initialFrag : null);
1894
- if (list.length === 0) {
1895
- for (const rec of items) {
1896
- rec.scope.dispose();
1897
- for (const node of rec.nodes) {
1898
- if (node.parentNode)
1899
- node.parentNode.removeChild(node);
1900
- }
1901
- }
1902
- items = [];
1903
- if (props.fallback !== undefined && fallbackNodes.length === 0 && parent) {
1904
- fallbackScope = new Scope(getActiveScope());
1905
- untrack(() => {
1906
- runInScope(fallbackScope, () => {
1907
- const frag = document.createDocumentFragment();
1908
- insertChild(frag, props.fallback);
1909
- fallbackNodes = Array.from(frag.childNodes);
1910
- if (marker.parentNode) {
1911
- marker.parentNode.insertBefore(frag, marker);
1912
- } else if (!isMounted) {
1913
- initialFrag.appendChild(frag);
1914
- }
1915
- });
1916
- });
1917
- }
1918
- return;
1919
- }
1920
- if (fallbackNodes.length > 0) {
1921
- if (fallbackScope) {
1922
- fallbackScope.dispose();
1923
- fallbackScope = null;
1924
- }
1925
- for (const node of fallbackNodes) {
1926
- if (node.parentNode)
1927
- node.parentNode.removeChild(node);
1928
- }
1929
- fallbackNodes = [];
1930
- }
1931
- if (!parent)
1932
- return;
1933
- const newItems = [];
1934
- const prevMap = new Map;
1935
- for (const rec of items) {
1936
- prevMap.set(rec.item, rec);
1937
- }
1938
- for (let i = 0;i < list.length; i++) {
1939
- const item = list[i];
1940
- const existing = prevMap.get(item);
1941
- if (existing) {
1942
- existing.indexSignal(i);
1943
- newItems.push(existing);
1944
- prevMap.delete(item);
1945
- } else {
1946
- let indexVal = i;
1947
- const indexSubscribers = new Set;
1948
- const indexSignal = (...args) => {
1949
- if (args.length > 0 && args[0] !== undefined && args[0] !== indexVal) {
1950
- indexVal = args[0];
1951
- for (const sub of Array.from(indexSubscribers))
1952
- sub();
1953
- }
1954
- return indexVal;
1955
- };
1956
- const itemScope = new Scope(getActiveScope());
1957
- let itemNodes = [];
1958
- untrack(() => {
1959
- runInScope(itemScope, () => {
1960
- const frag = document.createDocumentFragment();
1961
- const child = props.children(item, indexSignal);
1962
- insertChild(frag, child);
1963
- itemNodes = Array.from(frag.childNodes);
1964
- });
1965
- });
1966
- newItems.push({
1967
- item,
1968
- scope: itemScope,
1969
- nodes: itemNodes,
1970
- indexSignal
1971
- });
1972
- }
1973
- }
1974
- for (const [, removed] of prevMap) {
1975
- removed.scope.dispose();
1976
- for (const node of removed.nodes) {
1977
- if (node.parentNode)
1978
- node.parentNode.removeChild(node);
1979
- }
1980
- }
1981
- if (marker.parentNode) {
1982
- let currentMarker = marker;
1983
- for (let i = newItems.length - 1;i >= 0; i--) {
1984
- const rec = newItems[i];
1985
- for (let j = rec.nodes.length - 1;j >= 0; j--) {
1986
- const node = rec.nodes[j];
1987
- if (node.nextSibling !== currentMarker) {
1988
- marker.parentNode.insertBefore(node, currentMarker);
1989
- }
1990
- currentMarker = node;
1991
- }
1992
- }
1993
- } else if (!isMounted) {
1994
- for (const rec of newItems) {
1995
- for (const node of rec.nodes) {
1996
- initialFrag.appendChild(node);
1997
- }
1998
- }
1999
- }
2000
- items = newItems;
2001
- });
2002
- isMounted = true;
2003
- initialFrag.appendChild(marker);
2004
- onCleanup(() => {
2005
- for (const rec of items) {
2006
- rec.scope.dispose();
2007
- }
2008
- if (fallbackScope) {
2009
- fallbackScope.dispose();
2010
- }
2011
- });
2012
- return initialFrag;
2013
- }
2014
- function Portal(props) {
2015
- if (typeof document === "undefined") {
2016
- return null;
2017
- }
2018
- const marker = document.createTextNode("");
2019
- let currentScope = null;
2020
- let nodes = [];
2021
- effect(() => {
2022
- const target = props.mount ?? (typeof document !== "undefined" ? document.body : null);
2023
- if (!target)
2024
- return;
2025
- if (currentScope) {
2026
- currentScope.dispose();
2027
- currentScope = null;
2028
- }
2029
- for (const node of nodes) {
2030
- if (node.parentNode) {
2031
- node.parentNode.removeChild(node);
2032
- }
2033
- }
2034
- nodes = [];
2035
- currentScope = new Scope(getActiveScope());
2036
- untrack(() => {
2037
- runInScope(currentScope, () => {
2038
- const childRes = typeof props.children === "function" ? props.children() : props.children;
2039
- const frag = document.createDocumentFragment();
2040
- insertChild(frag, childRes);
2041
- nodes = Array.from(frag.childNodes);
2042
- target.appendChild(frag);
2043
- });
2044
- });
2045
- });
2046
- onCleanup(() => {
2047
- if (currentScope) {
2048
- currentScope.dispose();
2049
- currentScope = null;
2050
- }
2051
- for (const node of nodes) {
2052
- if (node.parentNode) {
2053
- node.parentNode.removeChild(node);
2054
- }
2055
- }
2056
- nodes = [];
2057
- });
2058
- return marker;
2059
- }
2060
- // src/jsx-runtime/index.ts
2061
- var SVG_NS = "http://www.w3.org/2000/svg";
2062
- var SVG_TAGS = new Set([
2063
- "svg",
2064
- "path",
2065
- "circle",
2066
- "rect",
2067
- "g",
2068
- "line",
2069
- "polyline",
2070
- "polygon",
2071
- "text",
2072
- "defs",
2073
- "clipPath",
2074
- "linearGradient",
2075
- "radialGradient",
2076
- "stop"
2077
- ]);
2078
- function Fragment(props) {
2079
- if (typeof document === "undefined") {
2080
- return props.children !== undefined ? props.children : [];
2081
- }
2082
- const fragment = document.createDocumentFragment();
2083
- if (props.children !== undefined) {
2084
- insertChild(fragment, props.children);
2085
- }
2086
- return fragment;
2087
- }
2088
- function jsx(type, props = {}, key) {
2089
- if (typeof type === "function") {
2090
- return type(props, key);
2091
- }
2092
- if (typeof type === "string") {
2093
- const { children, ...restProps } = props;
2094
- if (typeof document === "undefined") {
2095
- const attributes = new Map;
2096
- for (const propName in restProps) {
2097
- const val = restProps[propName];
2098
- if (propName === "className" || propName === "class") {
2099
- const resolved = typeof val === "function" ? val() : val;
2100
- if (resolved)
2101
- attributes.set("class", resolved);
2102
- } else if (propName === "style") {
2103
- const val = restProps[propName];
2104
- const resolved = resolveValue(val);
2105
- if (typeof resolved === "string") {
2106
- attributes.set("style", resolved);
2107
- } else if (typeof resolved === "object" && resolved !== null) {
2108
- const styleStr = Object.entries(resolved).map(([k, v]) => {
2109
- const finalVal = resolveValue(v);
2110
- const formatted = formatStyleProp(k, finalVal);
2111
- if (!formatted)
2112
- return "";
2113
- const kebab = k.startsWith("--") ? k : k.replace(/([A-Z])/g, "-$1").toLowerCase();
2114
- return `${kebab}: ${formatted}`;
2115
- }).filter(Boolean).join("; ");
2116
- if (styleStr)
2117
- attributes.set("style", styleStr);
2118
- }
2119
- } else if (!propName.startsWith("on")) {
2120
- const resolved = typeof val === "function" ? val() : val;
2121
- if (resolved === true) {
2122
- attributes.set(propName, propName);
2123
- } else if (resolved !== false && resolved !== null && resolved !== undefined) {
2124
- attributes.set(propName, resolved);
2125
- }
2126
- }
2127
- }
2128
- const childNodes = children !== undefined ? Array.isArray(children) ? children : [children] : [];
2129
- return {
2130
- tagName: type,
2131
- attributes,
2132
- childNodes
2133
- };
2134
- }
2135
- const isSvg = SVG_TAGS.has(type);
2136
- const element = isSvg ? document.createElementNS(SVG_NS, type) : document.createElement(type);
2137
- for (const propName in restProps) {
2138
- setAttribute(element, propName, restProps[propName]);
2139
- }
2140
- if (children !== undefined) {
2141
- insertChild(element, children);
2142
- }
2143
- return element;
2144
- }
2145
- return type;
2146
- }
2147
- var jsxs = jsx;
2148
- var jsxDEV = jsx;
2149
-
2150
- // src/style/layout.tsx
2151
- var ALIGN_MAP = {
2152
- start: "flex-start",
2153
- center: "center",
2154
- end: "flex-end",
2155
- stretch: "stretch",
2156
- baseline: "baseline"
2157
- };
2158
- var JUSTIFY_MAP = {
2159
- start: "flex-start",
2160
- center: "center",
2161
- end: "flex-end",
2162
- between: "space-between",
2163
- around: "space-around",
2164
- evenly: "space-evenly",
2165
- stretch: "stretch"
2166
- };
2167
- function resolveBaseStyles(props) {
2168
- const s = {
2169
- boxSizing: "border-box"
2170
- };
2171
- if (props.gap !== undefined)
2172
- s.gap = space(props.gap);
2173
- if (props.p !== undefined)
2174
- s.padding = space(props.p);
2175
- if (props.px !== undefined) {
2176
- s.paddingLeft = space(props.px);
2177
- s.paddingRight = space(props.px);
2178
- }
2179
- if (props.py !== undefined) {
2180
- s.paddingTop = space(props.py);
2181
- s.paddingBottom = space(props.py);
2182
- }
2183
- if (props.pt !== undefined)
2184
- s.paddingTop = space(props.pt);
2185
- if (props.pb !== undefined)
2186
- s.paddingBottom = space(props.pb);
2187
- if (props.pl !== undefined)
2188
- s.paddingLeft = space(props.pl);
2189
- if (props.pr !== undefined)
2190
- s.paddingRight = space(props.pr);
2191
- if (props.m !== undefined)
2192
- s.margin = space(props.m);
2193
- if (props.mx !== undefined) {
2194
- s.marginLeft = space(props.mx);
2195
- s.marginRight = space(props.mx);
2196
- }
2197
- if (props.my !== undefined) {
2198
- s.marginTop = space(props.my);
2199
- s.marginBottom = space(props.my);
2200
- }
2201
- if (props.mt !== undefined)
2202
- s.marginTop = space(props.mt);
2203
- if (props.mb !== undefined)
2204
- s.marginBottom = space(props.mb);
2205
- if (props.ml !== undefined)
2206
- s.marginLeft = space(props.ml);
2207
- if (props.mr !== undefined)
2208
- s.marginRight = space(props.mr);
2209
- if (props.w !== undefined)
2210
- s.width = resolveDimension(props.w);
2211
- if (props.h !== undefined)
2212
- s.height = resolveDimension(props.h);
2213
- if (props.minW !== undefined)
2214
- s.minWidth = resolveDimension(props.minW);
2215
- if (props.maxW !== undefined)
2216
- s.maxWidth = resolveDimension(props.maxW);
2217
- if (props.minH !== undefined)
2218
- s.minHeight = resolveDimension(props.minH);
2219
- if (props.maxH !== undefined)
2220
- s.maxHeight = resolveDimension(props.maxH);
2221
- return s;
2222
- }
2223
- function mergeStyles(base, userStyle) {
2224
- if (!userStyle)
2225
- return base;
2226
- if (typeof userStyle === "string") {
2227
- const baseStr = Object.entries(base).map(([k, v]) => `${k.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${v}`).join("; ");
2228
- return `${baseStr}; ${userStyle}`;
2229
- }
2230
- if (typeof userStyle === "object") {
2231
- return { ...base, ...userStyle };
2232
- }
2233
- return base;
2234
- }
2235
- function cleanProps(props, excludeKeys) {
2236
- const result = {};
2237
- for (const k in props) {
2238
- if (!excludeKeys.has(k)) {
2239
- result[k] = props[k];
2240
- }
2241
- }
2242
- return result;
2243
- }
2244
- var COMMON_EXCLUDE = new Set([
2245
- "as",
2246
- "gap",
2247
- "p",
2248
- "px",
2249
- "py",
2250
- "pt",
2251
- "pb",
2252
- "pl",
2253
- "pr",
2254
- "m",
2255
- "mx",
2256
- "my",
2257
- "mt",
2258
- "mb",
2259
- "ml",
2260
- "mr",
2261
- "w",
2262
- "h",
2263
- "minW",
2264
- "maxW",
2265
- "minH",
2266
- "maxH"
2267
- ]);
2268
- var STACK_EXCLUDE = new Set([
2269
- ...COMMON_EXCLUDE,
2270
- "align",
2271
- "justify",
2272
- "direction",
2273
- "reversed",
2274
- "wrap",
2275
- "inline"
2276
- ]);
2277
- function Stack(props) {
2278
- const { as = "div", children, ...rest } = props;
2279
- const layoutStyles = resolveBaseStyles(props);
2280
- layoutStyles.display = props.inline ? "inline-flex" : "flex";
2281
- layoutStyles.flexDirection = props.direction === "horizontal" ? props.reversed ? "row-reverse" : "row" : props.reversed ? "column-reverse" : "column";
2282
- if (props.align && ALIGN_MAP[props.align]) {
2283
- layoutStyles.alignItems = ALIGN_MAP[props.align];
2284
- }
2285
- if (props.justify && JUSTIFY_MAP[props.justify]) {
2286
- layoutStyles.justifyContent = JUSTIFY_MAP[props.justify];
2287
- }
2288
- if (props.wrap) {
2289
- layoutStyles.flexWrap = props.wrap === true ? "wrap" : props.wrap;
2290
- }
2291
- const domProps = cleanProps(rest, STACK_EXCLUDE);
2292
- domProps.style = mergeStyles(layoutStyles, props.style);
2293
- domProps.children = children;
2294
- return jsx(as, domProps);
2295
- }
2296
- var ROW_EXCLUDE = new Set([...COMMON_EXCLUDE, "align", "justify", "reversed", "wrap", "inline"]);
2297
- function Row(props) {
2298
- const { as = "div", children, ...rest } = props;
2299
- const layoutStyles = resolveBaseStyles(props);
2300
- layoutStyles.display = props.inline ? "inline-flex" : "flex";
2301
- layoutStyles.flexDirection = props.reversed ? "row-reverse" : "row";
2302
- layoutStyles.alignItems = props.align ? ALIGN_MAP[props.align] ?? props.align : "center";
2303
- if (props.justify && JUSTIFY_MAP[props.justify]) {
2304
- layoutStyles.justifyContent = JUSTIFY_MAP[props.justify];
2305
- }
2306
- if (props.wrap) {
2307
- layoutStyles.flexWrap = props.wrap === true ? "wrap" : props.wrap;
2308
- }
2309
- const domProps = cleanProps(rest, ROW_EXCLUDE);
2310
- domProps.style = mergeStyles(layoutStyles, props.style);
2311
- domProps.children = children;
2312
- return jsx(as, domProps);
2313
- }
2314
- var CENTER_EXCLUDE = new Set([...COMMON_EXCLUDE, "inline"]);
2315
- function Center(props) {
2316
- const { as = "div", children, ...rest } = props;
2317
- const layoutStyles = resolveBaseStyles(props);
2318
- layoutStyles.display = props.inline ? "inline-flex" : "flex";
2319
- layoutStyles.alignItems = "center";
2320
- layoutStyles.justifyContent = "center";
2321
- const domProps = cleanProps(rest, CENTER_EXCLUDE);
2322
- domProps.style = mergeStyles(layoutStyles, props.style);
2323
- domProps.children = children;
2324
- return jsx(as, domProps);
2325
- }
2326
- var GRID_EXCLUDE = new Set([
2327
- ...COMMON_EXCLUDE,
2328
- "columns",
2329
- "minChildWidth",
2330
- "rows",
2331
- "rowGap",
2332
- "colGap",
2333
- "align",
2334
- "justify",
2335
- "inline"
2336
- ]);
2337
- function Grid(props) {
2338
- const { as = "div", children, ...rest } = props;
2339
- const layoutStyles = resolveBaseStyles(props);
2340
- layoutStyles.display = props.inline ? "inline-grid" : "grid";
2341
- if (props.minChildWidth !== undefined) {
2342
- const minW = resolveDimension(props.minChildWidth);
2343
- layoutStyles.gridTemplateColumns = `repeat(auto-fit, minmax(min(100%, ${minW}), 1fr))`;
2344
- } else if (props.columns !== undefined) {
2345
- if (typeof props.columns === "number") {
2346
- layoutStyles.gridTemplateColumns = `repeat(${props.columns}, minmax(0, 1fr))`;
2347
- } else {
2348
- layoutStyles.gridTemplateColumns = String(props.columns);
2349
- }
2350
- }
2351
- if (props.rows !== undefined) {
2352
- if (typeof props.rows === "number") {
2353
- layoutStyles.gridTemplateRows = `repeat(${props.rows}, minmax(0, 1fr))`;
2354
- } else {
2355
- layoutStyles.gridTemplateRows = String(props.rows);
2356
- }
2357
- }
2358
- if (props.rowGap !== undefined)
2359
- layoutStyles.rowGap = space(props.rowGap);
2360
- if (props.colGap !== undefined)
2361
- layoutStyles.columnGap = space(props.colGap);
2362
- if (props.align) {
2363
- layoutStyles.alignItems = ALIGN_MAP[props.align] ?? props.align;
2364
- }
2365
- if (props.justify) {
2366
- layoutStyles.justifyItems = props.justify;
2367
- }
2368
- const domProps = cleanProps(rest, GRID_EXCLUDE);
2369
- domProps.style = mergeStyles(layoutStyles, props.style);
2370
- domProps.children = children;
2371
- return jsx(as, domProps);
2372
- }
2373
- var SPACER_EXCLUDE = new Set([...COMMON_EXCLUDE, "size", "x", "y", "flex"]);
2374
- function Spacer(props) {
2375
- const { as = "div", ...rest } = props;
2376
- const layoutStyles = resolveBaseStyles(props);
2377
- if (props.size !== undefined) {
2378
- const s = space(props.size);
2379
- layoutStyles.width = s;
2380
- layoutStyles.height = s;
2381
- layoutStyles.flexShrink = "0";
2382
- } else if (props.x !== undefined || props.y !== undefined) {
2383
- if (props.x !== undefined)
2384
- layoutStyles.width = space(props.x);
2385
- if (props.y !== undefined)
2386
- layoutStyles.height = space(props.y);
2387
- layoutStyles.flexShrink = "0";
2388
- } else {
2389
- layoutStyles.flex = typeof props.flex === "number" ? String(props.flex) : "1 1 0%";
2390
- layoutStyles.alignSelf = "stretch";
2391
- }
2392
- const domProps = cleanProps(rest, SPACER_EXCLUDE);
2393
- domProps.style = mergeStyles(layoutStyles, props.style);
2394
- return jsx(as, domProps);
2395
- }
1
+ import {
2
+ hasReactiveClass2,
3
+ normalizeClass2,
4
+ cx2,
5
+ UNITLESS_PROPERTIES2,
6
+ DIMENSION_KEYWORDS2,
7
+ space2,
8
+ resolveDimension2,
9
+ px2,
10
+ rem2,
11
+ em2,
12
+ fluid2,
13
+ SHADOW_PRESETS2,
14
+ shadow2,
15
+ RADIUS_PRESETS2,
16
+ radius2,
17
+ glass2,
18
+ formatStyleProp2
19
+ } from "../index-6kfe1nr4.js";
20
+ import"../index-5s255b3w.js";
21
+ import"../index-9fvarkrx.js";
22
+ import {
23
+ hashString2,
24
+ getScopeId2,
25
+ StyleManager2,
26
+ styleManager2,
27
+ extractStyleTags2,
28
+ scopeSelector2,
29
+ scopeCSS2,
30
+ objectToCSS2,
31
+ createStyle2,
32
+ css2,
33
+ useStyle2,
34
+ Style2
35
+ } from "../index-0madxn60.js";
36
+ import {
37
+ Stack2,
38
+ Row2,
39
+ Center2,
40
+ Grid2,
41
+ Spacer2
42
+ } from "../index-1xtrtz1t.js";
43
+ import"../index-a4xns6cc.js";
2396
44
  export {
2397
- Center,
2398
- DIMENSION_KEYWORDS,
2399
- Grid,
2400
- RADIUS_PRESETS,
2401
- Row,
2402
- SHADOW_PRESETS,
2403
- Spacer,
2404
- Stack,
2405
- Style,
2406
- StyleManager,
2407
- UNITLESS_PROPERTIES,
2408
- createStyle,
2409
- css,
2410
- cx,
2411
- em,
2412
- extractStyleTags,
2413
- fluid,
2414
- formatStyleProp,
2415
- getScopeId,
2416
- glass,
2417
- hasReactiveClass,
2418
- hashString,
2419
- normalizeClass,
2420
- objectToCSS,
2421
- px,
2422
- radius,
2423
- rem,
2424
- resolveDimension,
2425
- scopeCSS,
2426
- scopeSelector,
2427
- shadow,
2428
- space,
2429
- styleManager,
2430
- useStyle
45
+ Center2 as Center,
46
+ DIMENSION_KEYWORDS2 as DIMENSION_KEYWORDS,
47
+ Grid2 as Grid,
48
+ RADIUS_PRESETS2 as RADIUS_PRESETS,
49
+ Row2 as Row,
50
+ SHADOW_PRESETS2 as SHADOW_PRESETS,
51
+ Spacer2 as Spacer,
52
+ Stack2 as Stack,
53
+ Style2 as Style,
54
+ StyleManager2 as StyleManager,
55
+ UNITLESS_PROPERTIES2 as UNITLESS_PROPERTIES,
56
+ createStyle2 as createStyle,
57
+ css2 as css,
58
+ cx2 as cx,
59
+ em2 as em,
60
+ extractStyleTags2 as extractStyleTags,
61
+ fluid2 as fluid,
62
+ formatStyleProp2 as formatStyleProp,
63
+ getScopeId2 as getScopeId,
64
+ glass2 as glass,
65
+ hasReactiveClass2 as hasReactiveClass,
66
+ hashString2 as hashString,
67
+ normalizeClass2 as normalizeClass,
68
+ objectToCSS2 as objectToCSS,
69
+ px2 as px,
70
+ radius2 as radius,
71
+ rem2 as rem,
72
+ resolveDimension2 as resolveDimension,
73
+ scopeCSS2 as scopeCSS,
74
+ scopeSelector2 as scopeSelector,
75
+ shadow2 as shadow,
76
+ space2 as space,
77
+ styleManager2 as styleManager,
78
+ useStyle2 as useStyle
2431
79
  };