@epoch32/visage 1.0.0 → 1.1.1

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 (137) hide show
  1. package/dist/api/client.d.ts +5 -0
  2. package/dist/api/file-router.d.ts +29 -0
  3. package/dist/api/handler.d.ts +15 -0
  4. package/dist/api/index.d.ts +12 -0
  5. package/dist/{src/api → api}/index.js +87 -2
  6. package/dist/api/middleware.d.ts +11 -0
  7. package/dist/api/pragma.d.ts +21 -0
  8. package/dist/api/procedure.d.ts +66 -0
  9. package/dist/api/types.d.ts +181 -0
  10. package/dist/charts/Area.d.ts +18 -0
  11. package/dist/charts/Axis.d.ts +21 -0
  12. package/dist/charts/Bar.d.ts +10 -0
  13. package/dist/charts/CartesianGrid.d.ts +10 -0
  14. package/dist/charts/Chart.d.ts +16 -0
  15. package/dist/charts/Cursor.d.ts +8 -0
  16. package/dist/charts/Legend.d.ts +9 -0
  17. package/dist/charts/Line.d.ts +18 -0
  18. package/dist/charts/Pie.d.ts +12 -0
  19. package/dist/charts/Tooltip.d.ts +12 -0
  20. package/dist/charts/context.d.ts +20 -0
  21. package/dist/charts/index.d.ts +14 -0
  22. package/dist/{src/charts → charts}/index.js +87 -2
  23. package/dist/charts/path.d.ts +27 -0
  24. package/dist/charts/scale.d.ts +23 -0
  25. package/dist/charts/types.d.ts +43 -0
  26. package/dist/devtools/DomTab.d.ts +6 -0
  27. package/dist/devtools/GraphInspector.d.ts +11 -0
  28. package/dist/devtools/GraphTab.d.ts +10 -0
  29. package/dist/devtools/QueryTab.d.ts +10 -0
  30. package/dist/devtools/RpcTab.d.ts +10 -0
  31. package/dist/devtools/SignalsTab.d.ts +10 -0
  32. package/dist/devtools/component.d.ts +2 -0
  33. package/dist/devtools/highlighter.d.ts +2 -0
  34. package/dist/devtools/hub.d.ts +41 -0
  35. package/dist/devtools/index.d.ts +9 -0
  36. package/dist/{src/devtools → devtools}/index.js +87 -2
  37. package/dist/devtools/styles.d.ts +1 -0
  38. package/dist/devtools/types.d.ts +44 -0
  39. package/dist/dom/async.d.ts +41 -0
  40. package/dist/dom/control-flow.d.ts +53 -0
  41. package/dist/dom/index.d.ts +3 -0
  42. package/dist/{src/dom → dom}/index.js +87 -2
  43. package/dist/dom/lazy.d.ts +30 -0
  44. package/dist/dom/render.d.ts +23 -0
  45. package/dist/dom/resource.d.ts +34 -0
  46. package/dist/form/form.d.ts +41 -0
  47. package/dist/form/index.d.ts +2 -0
  48. package/dist/{src/form → form}/index.js +87 -2
  49. package/dist/form/schema.d.ts +96 -0
  50. package/dist/index.d.ts +15 -0
  51. package/dist/{src/index.js → index.js} +87 -2
  52. package/dist/jsx-dev-runtime/index.d.ts +1 -0
  53. package/dist/jsx-runtime/index.d.ts +8 -0
  54. package/dist/{src/jsx-runtime → jsx-runtime}/index.js +87 -2
  55. package/dist/jsx-runtime/jsx.d.ts +278 -0
  56. package/dist/query/create-mutation.d.ts +3 -0
  57. package/dist/query/create-query.d.ts +4 -0
  58. package/dist/query/focus-manager.d.ts +14 -0
  59. package/dist/query/index.d.ts +9 -0
  60. package/dist/{src/query → query}/index.js +87 -2
  61. package/dist/query/mutation-cache.d.ts +24 -0
  62. package/dist/query/online-manager.d.ts +14 -0
  63. package/dist/query/query-cache.d.ts +69 -0
  64. package/dist/query/query-client.d.ts +46 -0
  65. package/dist/query/types.d.ts +131 -0
  66. package/dist/query/utils.d.ts +16 -0
  67. package/dist/router/index.d.ts +1 -0
  68. package/dist/{src/router → router}/index.js +87 -2
  69. package/dist/router/router.d.ts +91 -0
  70. package/dist/rpc/client.d.ts +2 -0
  71. package/dist/rpc/error.d.ts +16 -0
  72. package/dist/rpc/index.d.ts +7 -0
  73. package/dist/{src/rpc → rpc}/index.js +87 -2
  74. package/dist/rpc/procedure.d.ts +8 -0
  75. package/dist/rpc/router.d.ts +19 -0
  76. package/dist/rpc/server.d.ts +3 -0
  77. package/dist/rpc/types.d.ts +200 -0
  78. package/dist/server/hydrate.d.ts +5 -0
  79. package/dist/server/index.d.ts +3 -0
  80. package/dist/{src/server → server}/index.js +87 -2
  81. package/dist/server/render-to-stream.d.ts +9 -0
  82. package/dist/server/render-to-string.d.ts +6 -0
  83. package/dist/signals/computed.d.ts +61 -0
  84. package/dist/signals/context.d.ts +44 -0
  85. package/dist/signals/effect.d.ts +56 -0
  86. package/dist/signals/index.d.ts +8 -0
  87. package/dist/{src/signals → signals}/index.js +87 -2
  88. package/dist/signals/scope.d.ts +61 -0
  89. package/dist/signals/signal.d.ts +40 -0
  90. package/dist/signals/store.d.ts +45 -0
  91. package/dist/signals/system.d.ts +56 -0
  92. package/dist/signals/types.d.ts +58 -0
  93. package/dist/style/component.d.ts +49 -0
  94. package/dist/style/create-style.d.ts +63 -0
  95. package/dist/style/cx.d.ts +18 -0
  96. package/dist/style/hash.d.ts +8 -0
  97. package/dist/style/index.d.ts +8 -0
  98. package/dist/{src/style → style}/index.js +87 -2
  99. package/dist/style/layout.d.ts +129 -0
  100. package/dist/style/manager.d.ts +31 -0
  101. package/dist/style/parser.d.ts +12 -0
  102. package/dist/style/scale.d.ts +82 -0
  103. package/dist/template/index.d.ts +1 -0
  104. package/dist/{src/template → template}/index.js +87 -2
  105. package/dist/template/template.d.ts +8 -0
  106. package/dist/ui/accordion.d.ts +81 -0
  107. package/dist/ui/command-dialog.d.ts +10 -0
  108. package/dist/ui/command.d.ts +103 -0
  109. package/dist/ui/data-table.d.ts +38 -0
  110. package/dist/ui/dialog.d.ts +102 -0
  111. package/dist/ui/dropdown-menu.d.ts +92 -0
  112. package/dist/ui/icon.d.ts +18 -0
  113. package/dist/ui/index.d.ts +14 -0
  114. package/dist/{src/ui → ui}/index.js +87 -2
  115. package/dist/ui/layout.d.ts +1 -0
  116. package/dist/ui/popover.d.ts +68 -0
  117. package/dist/ui/switch.d.ts +31 -0
  118. package/dist/ui/tabs.d.ts +71 -0
  119. package/dist/ui/toast.d.ts +91 -0
  120. package/dist/ui/tooltip.d.ts +64 -0
  121. package/dist/ui/utils.d.ts +21 -0
  122. package/dist/virtual/index.d.ts +2 -0
  123. package/dist/{src/virtual → virtual}/index.js +87 -2
  124. package/dist/virtual/virtual-list.d.ts +21 -0
  125. package/dist/virtual/virtualizer.d.ts +31 -0
  126. package/dist/vite/hmr.d.ts +7 -0
  127. package/dist/vite/index.d.ts +3 -0
  128. package/dist/{src/vite → vite}/index.js +4 -0
  129. package/dist/vite/lucide.d.ts +27 -0
  130. package/dist/vite/plugin.d.ts +3 -0
  131. package/dist/vite/rpc-middleware.d.ts +5 -0
  132. package/dist/vite/types.d.ts +59 -0
  133. package/package.json +40 -40
  134. package/src/signals/index.ts +1 -0
  135. package/src/signals/signal.ts +110 -2
  136. package/src/signals/types.ts +9 -0
  137. package/src/vite/plugin.ts +4 -0
@@ -848,10 +848,12 @@ class Signal {
848
848
  _value;
849
849
  _subscribers = new Set;
850
850
  _equals;
851
+ _onSet;
851
852
  version = 0;
852
- constructor(initialValue, equals) {
853
+ constructor(initialValue, equals, onSet) {
853
854
  this._value = initialValue;
854
855
  this._equals = equals ?? Object.is;
856
+ this._onSet = onSet;
855
857
  }
856
858
  get() {
857
859
  if (currentSubscriber !== null && currentSubscriber.state !== 3 /* DISPOSED */) {
@@ -876,6 +878,9 @@ class Signal {
876
878
  }
877
879
  this._value = newValue;
878
880
  this.version++;
881
+ if (this._onSet) {
882
+ this._onSet(newValue);
883
+ }
879
884
  batch(() => {
880
885
  this.notify();
881
886
  });
@@ -901,11 +906,91 @@ class Signal {
901
906
  }
902
907
  }
903
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
+ }
904
946
  function signal(initialValue, optionsOrEquals) {
905
947
  const equals = typeof optionsOrEquals === "function" ? optionsOrEquals : optionsOrEquals?.equals;
906
948
  const isInternal = typeof optionsOrEquals === "object" ? optionsOrEquals?.internal : false;
907
949
  const customName = typeof optionsOrEquals === "object" ? optionsOrEquals?.name : undefined;
908
- const s = new Signal(initialValue, equals);
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
+ }
909
994
  const accessor = (...args) => {
910
995
  if (args.length === 0) {
911
996
  return s.get();
@@ -0,0 +1,278 @@
1
+ import type { Child } from "../dom";
2
+ import type { ReadonlySignal } from "../signals";
3
+
4
+ /**
5
+ * Fine-grained reactive property value.
6
+ *
7
+ * Can be a static value `T`, a reactive `ReadonlySignal<T>`, or a dynamic getter function `() => T`.
8
+ * Visage binds reactive props directly to the DOM attribute or property via fine-grained effects,
9
+ * updating only the exact target attribute when the signal changes without re-rendering the component.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const count = signal(5);
14
+ *
15
+ * // Direct signal
16
+ * <input disabled={count} />
17
+ *
18
+ * // Getter function
19
+ * <div title={() => `Item count: ${count()}`} />
20
+ * ```
21
+ */
22
+ export type ReactiveProp<T> = T | ReadonlySignal<T> | (() => T);
23
+
24
+ /**
25
+ * Flexible reactive class value supporting strings, conditional objects, arrays, and getters.
26
+ */
27
+ export type ClassValue =
28
+ | string
29
+ | number
30
+ | boolean
31
+ | null
32
+ | undefined
33
+ | (() => any)
34
+ | ClassValue[]
35
+ | Record<string, any>;
36
+
37
+ /**
38
+ * Reactive class / className property.
39
+ *
40
+ * @example
41
+ * ```tsx
42
+ * // Object conditional syntax
43
+ * <div class={{ active: isActive(), hidden: isHidden() }} />
44
+ *
45
+ * // Array syntax
46
+ * <div class={["btn", isPrimary() ? "btn-primary" : "btn-secondary"]} />
47
+ *
48
+ * // Signal / Getter syntax
49
+ * <div class={() => `theme-${theme()}`} />
50
+ * ```
51
+ */
52
+ export type ClassProp = ReactiveProp<
53
+ string | number | boolean | undefined | null | ClassValue[] | Record<string, any>
54
+ >;
55
+
56
+ /**
57
+ * Standard HTML Element attributes with fine-grained reactive property bindings.
58
+ */
59
+ export type HTMLAttributes<T extends HTMLElement = HTMLElement> = {
60
+ [K in keyof HTMLElementTagNameMap[keyof HTMLElementTagNameMap]]?: any;
61
+ } & {
62
+ class?: ClassProp;
63
+ className?: ClassProp;
64
+ id?: ReactiveProp<string | undefined | null>;
65
+ title?: ReactiveProp<string | undefined | null>;
66
+ tabIndex?: ReactiveProp<number | undefined | null>;
67
+ role?: ReactiveProp<string | undefined | null>;
68
+ hidden?: ReactiveProp<boolean | undefined | null>;
69
+ disabled?: ReactiveProp<boolean | undefined | null>;
70
+ style?: ReactiveProp<
71
+ string | Record<string, ReactiveProp<string | number | undefined | null>> | undefined | null
72
+ >;
73
+ ref?: (el: T) => void;
74
+ dangerouslySetInnerHTML?: { __html: string };
75
+
76
+ // Events
77
+ onClick?: (e: MouseEvent) => void;
78
+ onDblClick?: (e: MouseEvent) => void;
79
+ onMouseDown?: (e: MouseEvent) => void;
80
+ onMouseUp?: (e: MouseEvent) => void;
81
+ onMouseMove?: (e: MouseEvent) => void;
82
+ onMouseEnter?: (e: MouseEvent) => void;
83
+ onMouseLeave?: (e: MouseEvent) => void;
84
+ onKeyDown?: (e: KeyboardEvent) => void;
85
+ onKeyUp?: (e: KeyboardEvent) => void;
86
+ onKeyPress?: (e: KeyboardEvent) => void;
87
+ onInput?: (e: InputEvent & { target: T }) => void;
88
+ onChange?: (e: Event & { target: T }) => void;
89
+ onSubmit?: (e: SubmitEvent) => void;
90
+ onFocus?: (e: FocusEvent) => void;
91
+ onBlur?: (e: FocusEvent) => void;
92
+ onScroll?: (e: Event) => void;
93
+
94
+ children?: Child;
95
+ [attr: string]: any;
96
+ };
97
+
98
+ export type InputAttributes = HTMLAttributes<HTMLInputElement> & {
99
+ type?: ReactiveProp<string>;
100
+ value?: ReactiveProp<string | number | readonly string[] | undefined | null>;
101
+ checked?: ReactiveProp<boolean | undefined | null>;
102
+ placeholder?: ReactiveProp<string | undefined | null>;
103
+ name?: ReactiveProp<string | undefined | null>;
104
+ disabled?: ReactiveProp<boolean | undefined | null>;
105
+ readOnly?: ReactiveProp<boolean | undefined | null>;
106
+ required?: ReactiveProp<boolean | undefined | null>;
107
+ min?: ReactiveProp<string | number | undefined | null>;
108
+ max?: ReactiveProp<string | number | undefined | null>;
109
+ step?: ReactiveProp<string | number | undefined | null>;
110
+ pattern?: ReactiveProp<string | undefined | null>;
111
+ autoFocus?: ReactiveProp<boolean | undefined | null>;
112
+ autoComplete?: ReactiveProp<string | undefined | null>;
113
+ };
114
+
115
+ export type ButtonAttributes = HTMLAttributes<HTMLButtonElement> & {
116
+ type?: ReactiveProp<"button" | "submit" | "reset" | undefined>;
117
+ disabled?: ReactiveProp<boolean | undefined | null>;
118
+ name?: ReactiveProp<string | undefined | null>;
119
+ value?: ReactiveProp<string | number | undefined | null>;
120
+ };
121
+
122
+ export type AnchorAttributes = HTMLAttributes<HTMLAnchorElement> & {
123
+ href?: ReactiveProp<string | undefined | null>;
124
+ target?: ReactiveProp<"_blank" | "_self" | "_parent" | "_top" | string | undefined | null>;
125
+ rel?: ReactiveProp<string | undefined | null>;
126
+ download?: ReactiveProp<any>;
127
+ };
128
+
129
+ export interface VisageIntrinsicElements {
130
+ // HTML tags
131
+ div: HTMLAttributes<HTMLDivElement>;
132
+ span: HTMLAttributes<HTMLSpanElement>;
133
+ p: HTMLAttributes<HTMLParagraphElement>;
134
+ a: AnchorAttributes;
135
+ button: ButtonAttributes;
136
+ input: InputAttributes;
137
+ textarea: HTMLAttributes<HTMLTextAreaElement> & {
138
+ value?: ReactiveProp<string | number | undefined | null>;
139
+ placeholder?: ReactiveProp<string | undefined | null>;
140
+ rows?: ReactiveProp<number | undefined | null>;
141
+ cols?: ReactiveProp<number | undefined | null>;
142
+ };
143
+ select: HTMLAttributes<HTMLSelectElement> & {
144
+ value?: ReactiveProp<any>;
145
+ multiple?: ReactiveProp<boolean | undefined | null>;
146
+ };
147
+ option: HTMLAttributes<HTMLOptionElement> & {
148
+ value?: ReactiveProp<any>;
149
+ selected?: ReactiveProp<boolean | undefined | null>;
150
+ };
151
+ form: HTMLAttributes<HTMLFormElement> & {
152
+ action?: ReactiveProp<string | undefined | null>;
153
+ method?: ReactiveProp<string | undefined | null>;
154
+ };
155
+ label: HTMLAttributes<HTMLLabelElement> & {
156
+ htmlFor?: ReactiveProp<string | undefined | null>;
157
+ for?: ReactiveProp<string | undefined | null>;
158
+ };
159
+ h1: HTMLAttributes<HTMLHeadingElement>;
160
+ h2: HTMLAttributes<HTMLHeadingElement>;
161
+ h3: HTMLAttributes<HTMLHeadingElement>;
162
+ h4: HTMLAttributes<HTMLHeadingElement>;
163
+ h5: HTMLAttributes<HTMLHeadingElement>;
164
+ h6: HTMLAttributes<HTMLHeadingElement>;
165
+ header: HTMLAttributes<HTMLElement>;
166
+ footer: HTMLAttributes<HTMLElement>;
167
+ main: HTMLAttributes<HTMLElement>;
168
+ nav: HTMLAttributes<HTMLElement>;
169
+ section: HTMLAttributes<HTMLElement>;
170
+ article: HTMLAttributes<HTMLElement>;
171
+ aside: HTMLAttributes<HTMLElement>;
172
+ ul: HTMLAttributes<HTMLUListElement>;
173
+ ol: HTMLAttributes<HTMLOListElement>;
174
+ li: HTMLAttributes<HTMLLIElement>;
175
+ table: HTMLAttributes<HTMLTableElement>;
176
+ thead: HTMLAttributes<HTMLTableSectionElement>;
177
+ tbody: HTMLAttributes<HTMLTableSectionElement>;
178
+ tfoot: HTMLAttributes<HTMLTableSectionElement>;
179
+ tr: HTMLAttributes<HTMLTableRowElement>;
180
+ td: HTMLAttributes<HTMLTableCellElement>;
181
+ th: HTMLAttributes<HTMLTableCellElement>;
182
+ img: HTMLAttributes<HTMLImageElement> & {
183
+ src?: ReactiveProp<string | undefined | null>;
184
+ alt?: ReactiveProp<string | undefined | null>;
185
+ width?: ReactiveProp<number | string | undefined | null>;
186
+ height?: ReactiveProp<number | string | undefined | null>;
187
+ loading?: ReactiveProp<"lazy" | "eager" | undefined | null>;
188
+ };
189
+ iframe: HTMLAttributes<HTMLIFrameElement> & {
190
+ src?: ReactiveProp<string | undefined | null>;
191
+ title?: ReactiveProp<string | undefined | null>;
192
+ };
193
+ canvas: HTMLAttributes<HTMLCanvasElement> & {
194
+ width?: ReactiveProp<number | undefined | null>;
195
+ height?: ReactiveProp<number | undefined | null>;
196
+ };
197
+ code: HTMLAttributes<HTMLElement>;
198
+ pre: HTMLAttributes<HTMLPreElement>;
199
+ blockquote: HTMLAttributes<HTMLQuoteElement>;
200
+ strong: HTMLAttributes<HTMLElement>;
201
+ em: HTMLAttributes<HTMLElement>;
202
+ small: HTMLAttributes<HTMLElement>;
203
+ hr: HTMLAttributes<HTMLHRElement>;
204
+ br: HTMLAttributes<HTMLBRElement>;
205
+
206
+ // SVG Tags
207
+ svg: HTMLAttributes<SVGElement> & {
208
+ viewBox?: ReactiveProp<string>;
209
+ xmlns?: ReactiveProp<string>;
210
+ width?: ReactiveProp<number | string>;
211
+ height?: ReactiveProp<number | string>;
212
+ fill?: ReactiveProp<string>;
213
+ stroke?: ReactiveProp<string>;
214
+ };
215
+ path: HTMLAttributes<SVGElement> & {
216
+ d?: ReactiveProp<string>;
217
+ fill?: ReactiveProp<string>;
218
+ stroke?: ReactiveProp<string>;
219
+ strokeWidth?: ReactiveProp<number | string>;
220
+ };
221
+ circle: HTMLAttributes<SVGElement> & {
222
+ cx?: ReactiveProp<number | string>;
223
+ cy?: ReactiveProp<number | string>;
224
+ r?: ReactiveProp<number | string>;
225
+ fill?: ReactiveProp<string>;
226
+ };
227
+ rect: HTMLAttributes<SVGElement> & {
228
+ x?: ReactiveProp<number | string>;
229
+ y?: ReactiveProp<number | string>;
230
+ width?: ReactiveProp<number | string>;
231
+ height?: ReactiveProp<number | string>;
232
+ fill?: ReactiveProp<string>;
233
+ };
234
+
235
+ // Catch-all for other tags
236
+ [elemName: string]: HTMLAttributes<HTMLElement>;
237
+ }
238
+
239
+ /**
240
+ * Visage JSX Namespace Definitions
241
+ */
242
+ export namespace JSX {
243
+ /**
244
+ * Represents any valid JSX element in Visage (DOM Node, Signal, Function Getter, VNode, string, number, null, undefined).
245
+ */
246
+ export type Element = Node | Child;
247
+
248
+ export interface ElementChildrenAttribute {
249
+ children: unknown;
250
+ }
251
+
252
+ export interface IntrinsicAttributes {
253
+ key?: any;
254
+ [key: string]: any;
255
+ }
256
+
257
+ export interface IntrinsicElements extends VisageIntrinsicElements {}
258
+ }
259
+
260
+ declare global {
261
+ namespace JSX {
262
+ /**
263
+ * Represents any valid JSX element in Visage (DOM Node, Signal, Function Getter, VNode, string, number, null, undefined).
264
+ */
265
+ type Element = Node | Child;
266
+
267
+ interface ElementChildrenAttribute {
268
+ children: unknown;
269
+ }
270
+
271
+ interface IntrinsicAttributes {
272
+ key?: any;
273
+ [key: string]: any;
274
+ }
275
+
276
+ interface IntrinsicElements extends VisageIntrinsicElements {}
277
+ }
278
+ }
@@ -0,0 +1,3 @@
1
+ import { type QueryClient } from "./query-client";
2
+ import type { MutationOptions, MutationResult } from "./types";
3
+ export declare function createMutation<TData = unknown, TError = any, TVariables = void, TContext = unknown>(options: MutationOptions<TData, TError, TVariables, TContext> | (() => MutationOptions<TData, TError, TVariables, TContext>), client?: QueryClient): MutationResult<TData, TError, TVariables, TContext>;
@@ -0,0 +1,4 @@
1
+ import { type QueryClient } from "./query-client";
2
+ import type { CreateQueryOptions, InfiniteData, InfiniteQueryOptions, InfiniteQueryResult, QueryKey, QueryResult } from "./types";
3
+ export declare function createQuery<TData = unknown, TError = any, TSelected = TData, TQueryKey extends QueryKey = QueryKey>(options: CreateQueryOptions<TData, TError, TSelected, TQueryKey> | (() => CreateQueryOptions<TData, TError, TSelected, TQueryKey>), client?: QueryClient): QueryResult<TSelected, TError>;
4
+ export declare function createInfiniteQuery<TData = unknown, TError = any, TPageParam = unknown, TSelected = InfiniteData<TData, TPageParam>, TQueryKey extends QueryKey = QueryKey>(options: InfiniteQueryOptions<TData, TError, TPageParam, TSelected, TQueryKey> | (() => InfiniteQueryOptions<TData, TError, TPageParam, TSelected, TQueryKey>), client?: QueryClient): InfiniteQueryResult<TData, TError, TPageParam>;
@@ -0,0 +1,14 @@
1
+ export type FocusListener = (focused: boolean) => void;
2
+ export declare class FocusManager {
3
+ private _focused?;
4
+ private _listeners;
5
+ private _cleanup?;
6
+ constructor();
7
+ private setupEventListener;
8
+ setFocused(focused?: boolean): void;
9
+ isFocused(): boolean;
10
+ subscribe(listener: FocusListener): () => void;
11
+ private notify;
12
+ cleanup(): void;
13
+ }
14
+ export declare const focusManager: FocusManager;
@@ -0,0 +1,9 @@
1
+ export { createMutation } from "./create-mutation";
2
+ export { createInfiniteQuery, createQuery } from "./create-query";
3
+ export { type FocusListener, FocusManager, focusManager } from "./focus-manager";
4
+ export { Mutation, MutationCache } from "./mutation-cache";
5
+ export { type OnlineListener, OnlineManager, onlineManager } from "./online-manager";
6
+ export { Query, QueryCache, type QueryObserver } from "./query-cache";
7
+ export { QueryClient, type QueryClientConfig, QueryClientContext, QueryClientProvider, useQueryClient } from "./query-client";
8
+ export type { CreateQueryOptions, DefaultOptions, FetchStatus, InfiniteData, InfiniteQueryOptions, InfiniteQueryResult, MutateOptions, MutationFunction, MutationOptions, MutationResult, MutationStatus, QueryFilters, QueryFunction, QueryFunctionContext, QueryKey, QueryOptions, QueryResult, QueryState, QueryStatus, RefetchOptions, RetryDelayValue, RetryValue } from "./types";
9
+ export { deepEqual, hashKey, isPlainObject, matchQuery, partialDeepEqual, sleep } from "./utils";
@@ -848,10 +848,12 @@ class Signal {
848
848
  _value;
849
849
  _subscribers = new Set;
850
850
  _equals;
851
+ _onSet;
851
852
  version = 0;
852
- constructor(initialValue, equals) {
853
+ constructor(initialValue, equals, onSet) {
853
854
  this._value = initialValue;
854
855
  this._equals = equals ?? Object.is;
856
+ this._onSet = onSet;
855
857
  }
856
858
  get() {
857
859
  if (currentSubscriber !== null && currentSubscriber.state !== 3 /* DISPOSED */) {
@@ -876,6 +878,9 @@ class Signal {
876
878
  }
877
879
  this._value = newValue;
878
880
  this.version++;
881
+ if (this._onSet) {
882
+ this._onSet(newValue);
883
+ }
879
884
  batch(() => {
880
885
  this.notify();
881
886
  });
@@ -901,11 +906,91 @@ class Signal {
901
906
  }
902
907
  }
903
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
+ }
904
946
  function signal(initialValue, optionsOrEquals) {
905
947
  const equals = typeof optionsOrEquals === "function" ? optionsOrEquals : optionsOrEquals?.equals;
906
948
  const isInternal = typeof optionsOrEquals === "object" ? optionsOrEquals?.internal : false;
907
949
  const customName = typeof optionsOrEquals === "object" ? optionsOrEquals?.name : undefined;
908
- const s = new Signal(initialValue, equals);
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
+ }
909
994
  const accessor = (...args) => {
910
995
  if (args.length === 0) {
911
996
  return s.get();
@@ -0,0 +1,24 @@
1
+ import { type ReadonlySignal, type WritableSignal } from "../signals";
2
+ import type { MutateOptions, MutationOptions, MutationStatus } from "./types";
3
+ export declare class Mutation<TData = unknown, TError = any, TVariables = void, TContext = unknown> {
4
+ readonly options: MutationOptions<TData, TError, TVariables, TContext>;
5
+ readonly data: WritableSignal<TData | undefined>;
6
+ readonly error: WritableSignal<TError | null>;
7
+ readonly status: WritableSignal<MutationStatus>;
8
+ readonly submittedAt: WritableSignal<number>;
9
+ readonly variables: WritableSignal<TVariables | undefined>;
10
+ readonly isIdle: ReadonlySignal<boolean>;
11
+ readonly isPending: ReadonlySignal<boolean>;
12
+ readonly isLoading: ReadonlySignal<boolean>;
13
+ readonly isSuccess: ReadonlySignal<boolean>;
14
+ readonly isError: ReadonlySignal<boolean>;
15
+ constructor(options: MutationOptions<TData, TError, TVariables, TContext>);
16
+ execute(variables: TVariables, mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>): Promise<TData>;
17
+ reset(): void;
18
+ }
19
+ export declare class MutationCache {
20
+ mutations: Set<Mutation<any, any, any, any>>;
21
+ build<TData, TError, TVariables, TContext>(options: MutationOptions<TData, TError, TVariables, TContext>): Mutation<TData, TError, TVariables, TContext>;
22
+ remove(mutation: Mutation<any, any, any, any>): void;
23
+ clear(): void;
24
+ }
@@ -0,0 +1,14 @@
1
+ export type OnlineListener = (online: boolean) => void;
2
+ export declare class OnlineManager {
3
+ private _online?;
4
+ private _listeners;
5
+ private _cleanup?;
6
+ constructor();
7
+ private setupEventListener;
8
+ setOnline(online?: boolean): void;
9
+ isOnline(): boolean;
10
+ subscribe(listener: OnlineListener): () => void;
11
+ private notify;
12
+ cleanup(): void;
13
+ }
14
+ export declare const onlineManager: OnlineManager;
@@ -0,0 +1,69 @@
1
+ import { type WritableSignal } from "../signals";
2
+ import type { QueryClient } from "./query-client";
3
+ import type { FetchStatus, QueryFilters, QueryKey, QueryOptions, QueryState, QueryStatus } from "./types";
4
+ export interface QueryObserver<TData = any, TError = any> {
5
+ onQueryUpdate(): void;
6
+ options: QueryOptions<TData, TError, any>;
7
+ }
8
+ export declare class Query<TData = unknown, TError = any> {
9
+ readonly queryKey: QueryKey;
10
+ readonly queryHash: string;
11
+ cache: QueryCache;
12
+ readonly data: WritableSignal<TData | undefined>;
13
+ readonly error: WritableSignal<TError | null>;
14
+ readonly status: WritableSignal<QueryStatus>;
15
+ readonly fetchStatus: WritableSignal<FetchStatus>;
16
+ readonly dataUpdatedAt: WritableSignal<number>;
17
+ readonly errorUpdatedAt: WritableSignal<number>;
18
+ readonly failureCount: WritableSignal<number>;
19
+ readonly isInvalidated: WritableSignal<boolean>;
20
+ observers: Set<QueryObserver<TData, TError>>;
21
+ private _gcTimeout;
22
+ private _abortController;
23
+ promise: Promise<TData> | null;
24
+ defaultGcTime: number;
25
+ constructor(options: {
26
+ queryKey: QueryKey;
27
+ queryHash: string;
28
+ cache: QueryCache;
29
+ initialData?: TData | (() => TData);
30
+ initialDataUpdatedAt?: number | (() => number);
31
+ });
32
+ get state(): QueryState<TData, TError>;
33
+ isStale(staleTime?: number): boolean;
34
+ addObserver(observer: QueryObserver<TData, TError>): void;
35
+ removeObserver(observer: QueryObserver<TData, TError>): void;
36
+ scheduleGc(gcTime?: number): void;
37
+ clearGcTimeout(): void;
38
+ setData(updater: TData | ((prev: TData | undefined) => TData), options?: {
39
+ updatedAt?: number;
40
+ }): TData;
41
+ invalidate(): void;
42
+ cancel(): void;
43
+ reset(): void;
44
+ fetch(options?: Partial<QueryOptions<TData, TError, any>>, fetchOptions?: {
45
+ cancelRefetch?: boolean;
46
+ }): Promise<TData>;
47
+ private notifyObservers;
48
+ destroy(): void;
49
+ }
50
+ export declare class QueryCache {
51
+ queries: Map<string, Query<any, any>>;
52
+ private _subscribers;
53
+ subscribe(listener: (event: {
54
+ type: string;
55
+ query?: Query<any, any>;
56
+ }) => void): () => void;
57
+ notify(event: {
58
+ type: string;
59
+ query?: Query<any, any>;
60
+ }): void;
61
+ getAll(): Query<any, any>[];
62
+ build<TData, TError>(_client: QueryClient, options: QueryOptions<TData, TError, any>): Query<TData, TError>;
63
+ get<TData = unknown, TError = any>(queryHash: string): Query<TData, TError> | undefined;
64
+ add(query: Query<any, any>): void;
65
+ remove(query: Query<any, any>): void;
66
+ find<TData = unknown, TError = any>(filters: QueryFilters): Query<TData, TError> | undefined;
67
+ findAll<TData = unknown, TError = any>(filters?: QueryFilters): Query<TData, TError>[];
68
+ clear(): void;
69
+ }