elit 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -125,6 +125,96 @@ declare const cleanupUnused: (root: HTMLElement) => number;
125
125
  declare const throttle: <T extends any[]>(fn: (...args: T) => void, delay: number) => (...args: T) => void;
126
126
  declare const debounce: <T extends any[]>(fn: (...args: T) => void, delay: number) => (...args: T) => void;
127
127
 
128
+ /**
129
+ * Shared State for Elit
130
+ * Integrates with @elit/server for real-time state synchronization
131
+ */
132
+
133
+ type StateChangeCallback<T = any> = (value: T, oldValue: T) => void;
134
+ /**
135
+ * Shared State - syncs with @elit/server
136
+ */
137
+ declare class SharedState<T = any> {
138
+ readonly key: string;
139
+ private wsUrl?;
140
+ private localState;
141
+ private ws;
142
+ private pendingUpdates;
143
+ private previousValue;
144
+ constructor(key: string, defaultValue: T, wsUrl?: string | undefined);
145
+ /**
146
+ * Get current value
147
+ */
148
+ get value(): T;
149
+ /**
150
+ * Set new value and sync to server
151
+ */
152
+ set value(newValue: T);
153
+ /**
154
+ * Get the underlying Elit State (for reactive binding)
155
+ */
156
+ get state(): State<T>;
157
+ /**
158
+ * Subscribe to changes (returns Elit State for reactive)
159
+ */
160
+ onChange(callback: StateChangeCallback<T>): () => void;
161
+ /**
162
+ * Update value using a function
163
+ */
164
+ update(updater: (current: T) => T): void;
165
+ /**
166
+ * Connect to WebSocket
167
+ */
168
+ private connect;
169
+ /**
170
+ * Subscribe to server state
171
+ */
172
+ private subscribe;
173
+ /**
174
+ * Handle message from server
175
+ */
176
+ private handleMessage;
177
+ /**
178
+ * Send value to server
179
+ */
180
+ private sendToServer;
181
+ /**
182
+ * Disconnect
183
+ */
184
+ disconnect(): void;
185
+ /**
186
+ * Destroy state and cleanup
187
+ */
188
+ destroy(): void;
189
+ }
190
+ /**
191
+ * Create a shared state that syncs with @elit/server
192
+ */
193
+ declare function createSharedState<T>(key: string, defaultValue: T, wsUrl?: string): SharedState<T>;
194
+ /**
195
+ * Shared State Manager for managing multiple shared states
196
+ */
197
+ declare class SharedStateManager {
198
+ private states;
199
+ /**
200
+ * Create or get a shared state
201
+ */
202
+ create<T>(key: string, defaultValue: T, wsUrl?: string): SharedState<T>;
203
+ /**
204
+ * Get existing state
205
+ */
206
+ get<T>(key: string): SharedState<T> | undefined;
207
+ /**
208
+ * Delete a state
209
+ */
210
+ delete(key: string): boolean;
211
+ /**
212
+ * Clear all states
213
+ */
214
+ clear(): void;
215
+ }
216
+ declare const sharedStateManager: SharedStateManager;
217
+
128
218
  /**
129
219
  * Elit - Reactive Rendering Helpers
130
220
  */
@@ -472,6 +562,45 @@ declare const mathMsub: ElementFactory;
472
562
  declare const mathMsup: ElementFactory;
473
563
  declare const varElement: ElementFactory;
474
564
 
565
+ /**
566
+ * DOM utility functions - Shorthand helpers for common document operations
567
+ */
568
+ declare const doc: Document;
569
+ declare const el: {
570
+ <K extends keyof HTMLElementTagNameMap>(selectors: K): HTMLElementTagNameMap[K] | null;
571
+ <K extends keyof SVGElementTagNameMap>(selectors: K): SVGElementTagNameMap[K] | null;
572
+ <K extends keyof MathMLElementTagNameMap>(selectors: K): MathMLElementTagNameMap[K] | null;
573
+ <K extends keyof HTMLElementDeprecatedTagNameMap>(selectors: K): HTMLElementDeprecatedTagNameMap[K] | null;
574
+ <E extends Element = Element>(selectors: string): E | null;
575
+ };
576
+ declare const els: {
577
+ <K extends keyof HTMLElementTagNameMap>(selectors: K): NodeListOf<HTMLElementTagNameMap[K]>;
578
+ <K extends keyof SVGElementTagNameMap>(selectors: K): NodeListOf<SVGElementTagNameMap[K]>;
579
+ <K extends keyof MathMLElementTagNameMap>(selectors: K): NodeListOf<MathMLElementTagNameMap[K]>;
580
+ <K extends keyof HTMLElementDeprecatedTagNameMap>(selectors: K): NodeListOf<HTMLElementDeprecatedTagNameMap[K]>;
581
+ <E extends Element = Element>(selectors: string): NodeListOf<E>;
582
+ };
583
+ declare const createEl: {
584
+ <K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K];
585
+ <K extends keyof HTMLElementDeprecatedTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementDeprecatedTagNameMap[K];
586
+ (tagName: string, options?: ElementCreationOptions): HTMLElement;
587
+ };
588
+ declare const createSvgEl: (qualifiedName: string, options?: string | ElementCreationOptions | undefined) => Element;
589
+ declare const createMathEl: (qualifiedName: string, options?: string | ElementCreationOptions | undefined) => Element;
590
+ declare const fragment: () => DocumentFragment;
591
+ declare const textNode: (data: string) => Text;
592
+ declare const commentNode: (data: string) => Comment;
593
+ declare const elId: (elementId: string) => HTMLElement | null;
594
+ declare const elClass: (classNames: string) => HTMLCollectionOf<Element>;
595
+ declare const elTag: {
596
+ <K extends keyof HTMLElementTagNameMap>(qualifiedName: K): HTMLCollectionOf<HTMLElementTagNameMap[K]>;
597
+ <K extends keyof SVGElementTagNameMap>(qualifiedName: K): HTMLCollectionOf<SVGElementTagNameMap[K]>;
598
+ <K extends keyof MathMLElementTagNameMap>(qualifiedName: K): HTMLCollectionOf<MathMLElementTagNameMap[K]>;
599
+ <K extends keyof HTMLElementDeprecatedTagNameMap>(qualifiedName: K): HTMLCollectionOf<HTMLElementDeprecatedTagNameMap[K]>;
600
+ (qualifiedName: string): HTMLCollectionOf<Element>;
601
+ };
602
+ declare const elName: (elementName: string) => NodeListOf<HTMLElement>;
603
+
475
604
  /**
476
605
  * Elit - Optimized lightweight library for creating DOM elements with reactive state
477
606
  */
@@ -498,4 +627,4 @@ declare const renderVNodeToString: (json: VNodeJson, options?: {
498
627
  indent?: number;
499
628
  }) => string;
500
629
 
501
- export { type CSSRule, type CSSVariable, type Child, type Children, type ContainerRule, CreateStyle, DomNode, type ElementFactory, type FontFace, type JsonNode, type KeyframeStep, type Keyframes, type LayerRule, type MediaRule, type Props, type RefCallback, type RefObject, type Route, type RouteLocation, type RouteParams, type Router, type RouterOptions, type State, type StateOptions, type SupportsRule, type VNode, type VNodeJson, type VirtualListController, a, abbr, addLink, addMeta, addStyle, address, area, article, aside, audio, b, base, batchRender, bdi, bdo, bindChecked, bindValue, blockquote, body, br, button, canvas, caption, cite, cleanupUnused, code, col, colgroup, computed, createElementFactory, createRouter, createRouterView, createState, createVirtualList, data, datalist, dd, debounce, del, details, dfn, dialog, div, dl, domNode, dt, effect, elements, em, embed, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, head, header, hr, html, i, iframe, img, input, ins, jsonToVNode, kbd, label, lazy, legend, li, link, main, map, mark, mathMath, mathMfrac, mathMi, mathMn, mathMo, mathMroot, mathMrow, mathMs, mathMsqrt, mathMsub, mathMsup, mathMtext, menu, meta, meter, nav, noscript, object, ol, optgroup, option, output, p, param, picture, portal, pre, progress, q, reactive, reactiveAs, renderChunked, renderJson, renderJsonToString, renderToHead, renderToString, renderVNode, renderVNodeToString, routerLink, rp, rt, ruby, s, samp, script, section, select, setTitle, slot, small, source, span, strong, style, sub, summary, sup, svgAnimate, svgAnimateMotion, svgAnimateTransform, svgCircle, svgClipPath, svgDefs, svgEllipse, svgFeBlend, svgFeColorMatrix, svgFeComponentTransfer, svgFeComposite, svgFeConvolveMatrix, svgFeDiffuseLighting, svgFeDisplacementMap, svgFeFlood, svgFeGaussianBlur, svgFeMorphology, svgFeOffset, svgFeSpecularLighting, svgFeTile, svgFeTurbulence, svgFilter, svgForeignObject, svgG, svgImage, svgLine, svgLinearGradient, svgMarker, svgMask, svgPath, svgPattern, svgPolygon, svgPolyline, svgRadialGradient, svgRect, svgSet, svgStop, svgSvg, svgSymbol, svgText, svgTspan, svgUse, table, tbody, td, template, text, textarea, tfoot, th, thead, throttle, time, title, tr, track, u, ul, vNodeJsonToVNode, varElement, video, wbr };
630
+ export { type CSSRule, type CSSVariable, type Child, type Children, type ContainerRule, CreateStyle, DomNode, type ElementFactory, type FontFace, type JsonNode, type KeyframeStep, type Keyframes, type LayerRule, type MediaRule, type Props, type RefCallback, type RefObject, type Route, type RouteLocation, type RouteParams, type Router, type RouterOptions, SharedState, type State, type StateOptions, type SupportsRule, type VNode, type VNodeJson, type VirtualListController, a, abbr, addLink, addMeta, addStyle, address, area, article, aside, audio, b, base, batchRender, bdi, bdo, bindChecked, bindValue, blockquote, body, br, button, canvas, caption, cite, cleanupUnused, code, col, colgroup, commentNode, computed, createEl, createElementFactory, createMathEl, createRouter, createRouterView, createSharedState, createState, createSvgEl, createVirtualList, data, datalist, dd, debounce, del, details, dfn, dialog, div, dl, doc, domNode, dt, effect, el, elClass, elId, elName, elTag, elements, els, em, embed, fieldset, figcaption, figure, footer, form, fragment, h1, h2, h3, h4, h5, h6, head, header, hr, html, i, iframe, img, input, ins, jsonToVNode, kbd, label, lazy, legend, li, link, main, map, mark, mathMath, mathMfrac, mathMi, mathMn, mathMo, mathMroot, mathMrow, mathMs, mathMsqrt, mathMsub, mathMsup, mathMtext, menu, meta, meter, nav, noscript, object, ol, optgroup, option, output, p, param, picture, portal, pre, progress, q, reactive, reactiveAs, renderChunked, renderJson, renderJsonToString, renderToHead, renderToString, renderVNode, renderVNodeToString, routerLink, rp, rt, ruby, s, samp, script, section, select, setTitle, sharedStateManager, slot, small, source, span, strong, style, sub, summary, sup, svgAnimate, svgAnimateMotion, svgAnimateTransform, svgCircle, svgClipPath, svgDefs, svgEllipse, svgFeBlend, svgFeColorMatrix, svgFeComponentTransfer, svgFeComposite, svgFeConvolveMatrix, svgFeDiffuseLighting, svgFeDisplacementMap, svgFeFlood, svgFeGaussianBlur, svgFeMorphology, svgFeOffset, svgFeSpecularLighting, svgFeTile, svgFeTurbulence, svgFilter, svgForeignObject, svgG, svgImage, svgLine, svgLinearGradient, svgMarker, svgMask, svgPath, svgPattern, svgPolygon, svgPolyline, svgRadialGradient, svgRect, svgSet, svgStop, svgSvg, svgSymbol, svgText, svgTspan, svgUse, table, tbody, td, template, text, textNode, textarea, tfoot, th, thead, throttle, time, title, tr, track, u, ul, vNodeJsonToVNode, varElement, video, wbr };