@petit-kit/scoped 0.0.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.
- package/README.md +534 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +627 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/content/index.d.ts +1 -0
- package/dist/plugins/content/index.d.ts.map +1 -0
- package/dist/plugins/device/index.d.ts +8 -0
- package/dist/plugins/device/index.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +8 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/inview/index.d.ts +63 -0
- package/dist/plugins/inview/index.d.ts.map +1 -0
- package/dist/plugins/lenis/index.d.ts +37 -0
- package/dist/plugins/lenis/index.d.ts.map +1 -0
- package/dist/plugins/lerp/index.d.ts +1 -0
- package/dist/plugins/lerp/index.d.ts.map +1 -0
- package/dist/plugins/morph/index.d.ts +92 -0
- package/dist/plugins/morph/index.d.ts.map +1 -0
- package/dist/plugins/mouse/index.d.ts +91 -0
- package/dist/plugins/mouse/index.d.ts.map +1 -0
- package/dist/plugins/spring/index.d.ts +1 -0
- package/dist/plugins/spring/index.d.ts.map +1 -0
- package/dist/plugins/timer/index.d.ts +82 -0
- package/dist/plugins/timer/index.d.ts.map +1 -0
- package/dist/plugins/window/index.d.ts +11 -0
- package/dist/plugins/window/index.d.ts.map +1 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
export * from './plugins';
|
|
2
|
+
/**
|
|
3
|
+
* Scope - A lightweight, framework-agnostic library for building web components
|
|
4
|
+
*
|
|
5
|
+
* @module scope
|
|
6
|
+
* @version 0.0.1
|
|
7
|
+
* @since 0.0.1
|
|
8
|
+
* @description Provides a minimal abstraction over Custom Elements API, making it easy
|
|
9
|
+
* to create reusable, encapsulated components with reactive state, lifecycle hooks,
|
|
10
|
+
* and a simple template-based rendering system.
|
|
11
|
+
*
|
|
12
|
+
* @example Basic component
|
|
13
|
+
* ```javascript
|
|
14
|
+
* import { define } from './scope.js';
|
|
15
|
+
*
|
|
16
|
+
* define("c-slider", {
|
|
17
|
+
* props: { value: { type: Number, default: 0 } }
|
|
18
|
+
* }, ({ link, emit, actions, host }) => {
|
|
19
|
+
* link("value", "value")
|
|
20
|
+
*
|
|
21
|
+
* actions.handleChange = event => {
|
|
22
|
+
* host.updateState({ value: event.target.valueAsNumber })
|
|
23
|
+
* emit("on-change", { value: event.target.valueAsNumber })
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* return () => `
|
|
27
|
+
* <div>
|
|
28
|
+
* <input
|
|
29
|
+
* type="range"
|
|
30
|
+
* min="0" max="100" step="1"
|
|
31
|
+
* bind:value="value"
|
|
32
|
+
* on:input="handleChange"
|
|
33
|
+
* />
|
|
34
|
+
* <c-number ref="number" bind:value="value"></c-number>
|
|
35
|
+
* </div>
|
|
36
|
+
* `
|
|
37
|
+
* })
|
|
38
|
+
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example Component with shadow DOM
|
|
42
|
+
* ```javascript
|
|
43
|
+
* define('styled-button', {
|
|
44
|
+
* shadow: true,
|
|
45
|
+
* styles: 'button { background: blue; color: white; }'
|
|
46
|
+
* }, () => {
|
|
47
|
+
* return () => '<button>Click me</button>';
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @see {@link ComponentContext} for available context properties
|
|
52
|
+
* @see {@link ComponentOptions} for configuration options
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Library version.
|
|
56
|
+
*
|
|
57
|
+
* @constant {string}
|
|
58
|
+
* @since 0.1.0
|
|
59
|
+
*/
|
|
60
|
+
declare const SCOPE_VERSION = "0.0.1";
|
|
61
|
+
/**
|
|
62
|
+
* Supported prop types for type checking and parsing
|
|
63
|
+
*
|
|
64
|
+
* @typedef {StringConstructor|NumberConstructor|BooleanConstructor|ObjectConstructor|ArrayConstructor} PropType
|
|
65
|
+
* @since 0.1.0
|
|
66
|
+
*/
|
|
67
|
+
export type PropType = StringConstructor | NumberConstructor | BooleanConstructor | ObjectConstructor | ArrayConstructor;
|
|
68
|
+
/**
|
|
69
|
+
* Definition for a single prop, including type, default value, and reflection behavior
|
|
70
|
+
*
|
|
71
|
+
* @template T - The type of the prop value
|
|
72
|
+
* @interface PropDefinition
|
|
73
|
+
* @since 0.1.0
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const propDef: PropDefinition<number> = {
|
|
78
|
+
* type: Number,
|
|
79
|
+
* default: 0,
|
|
80
|
+
* reflect: true
|
|
81
|
+
* };
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export interface PropDefinition<T = any> {
|
|
85
|
+
/**
|
|
86
|
+
* Type constructor for parsing the prop value from attributes
|
|
87
|
+
* @type {PropType}
|
|
88
|
+
*/
|
|
89
|
+
type?: PropType;
|
|
90
|
+
/**
|
|
91
|
+
* Default value if prop is not provided
|
|
92
|
+
* @type {T}
|
|
93
|
+
*/
|
|
94
|
+
default?: T;
|
|
95
|
+
/**
|
|
96
|
+
* Whether to reflect prop changes back to HTML attributes
|
|
97
|
+
* @type {boolean}
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
reflect?: boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Props definition object mapping prop names to their definitions or default values
|
|
104
|
+
*
|
|
105
|
+
* @typedef {Record<string, PropDefinition | any>} PropsDefinition
|
|
106
|
+
* @since 0.1.0
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const props: PropsDefinition = {
|
|
111
|
+
* count: { type: Number, default: 0 },
|
|
112
|
+
* name: { type: String, default: 'World' },
|
|
113
|
+
* active: { type: Boolean, default: false }
|
|
114
|
+
* };
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export type PropsDefinition = Record<string, PropDefinition | any>;
|
|
118
|
+
/**
|
|
119
|
+
* Plugin for extending the component context.
|
|
120
|
+
*/
|
|
121
|
+
export type ComponentPlugin<Ext extends Record<string, any> = {}> = {
|
|
122
|
+
/** Optional plugin name for debugging */
|
|
123
|
+
name?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Extend the component context with new capabilities.
|
|
126
|
+
*/
|
|
127
|
+
extend: (context: ComponentContextBase<any, any, any, any>, host: ComponentHost) => Ext;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Options for component definition
|
|
131
|
+
*
|
|
132
|
+
* @interface ComponentOptions
|
|
133
|
+
* @since 0.1.0
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const options: ComponentOptions = {
|
|
138
|
+
* props: { count: { type: Number, default: 0 } },
|
|
139
|
+
* shadow: true,
|
|
140
|
+
* styles: 'div { color: red; }'
|
|
141
|
+
* };
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export interface ComponentOptions<Plugins extends readonly ComponentPlugin<any>[] = ComponentPlugin<any>[]> {
|
|
145
|
+
/**
|
|
146
|
+
* Prop definitions for the component
|
|
147
|
+
* @type {PropsDefinition}
|
|
148
|
+
*/
|
|
149
|
+
props?: PropsDefinition;
|
|
150
|
+
/**
|
|
151
|
+
* Whether to use Shadow DOM (default: false, uses light DOM)
|
|
152
|
+
* @type {boolean}
|
|
153
|
+
* @default false
|
|
154
|
+
*/
|
|
155
|
+
shadow?: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* CSS styles to inject into document head (for shadow DOM components)
|
|
158
|
+
* @type {string}
|
|
159
|
+
*/
|
|
160
|
+
styles?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Plugins that extend the component context.
|
|
163
|
+
* @type {Plugins}
|
|
164
|
+
*/
|
|
165
|
+
plugins?: Plugins;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Methods available on the component host element
|
|
169
|
+
*
|
|
170
|
+
* @interface ComponentHost
|
|
171
|
+
* @since 0.1.0
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* define('my-component', {}, ({ host }) => {
|
|
176
|
+
* host.setState({ count: 5 });
|
|
177
|
+
* host.updateState({ scrollY: 100 });
|
|
178
|
+
* host.setProps({ title: 'New Title' });
|
|
179
|
+
* });
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export interface ComponentHost {
|
|
183
|
+
/**
|
|
184
|
+
* Update state and trigger full re-render
|
|
185
|
+
* @method setState
|
|
186
|
+
* @param {Partial<State>} partial - Partial state object to merge
|
|
187
|
+
* @template State
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* host.setState({ count: 5, name: 'Updated' });
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
setState: <State>(partial: Partial<State>) => void;
|
|
195
|
+
/**
|
|
196
|
+
* Update state without re-render (triggers effects only)
|
|
197
|
+
* @method updateState
|
|
198
|
+
* @param {Partial<State>} partial - Partial state object to merge
|
|
199
|
+
* @template State
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* // Update scroll position without re-rendering
|
|
204
|
+
* host.updateState({ scrollY: window.scrollY });
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
updateState: <State>(partial: Partial<State>) => void;
|
|
208
|
+
/**
|
|
209
|
+
* Update props programmatically
|
|
210
|
+
* @method setProps
|
|
211
|
+
* @param {Partial<Props>} partial - Partial props object to merge
|
|
212
|
+
* @template Props
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* // Pass large data (recommended for objects/arrays)
|
|
217
|
+
* element.setProps({ data: largeArray, config: complexObject });
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
setProps: <Props>(partial: Partial<Props>) => void;
|
|
221
|
+
/**
|
|
222
|
+
* Schedule a partial update (effects only)
|
|
223
|
+
* @method scheduleUpdate
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* host.scheduleUpdate(); // Runs effects on next animation frame
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
scheduleUpdate: () => void;
|
|
231
|
+
/**
|
|
232
|
+
* Force an update (full or partial render)
|
|
233
|
+
* @method update
|
|
234
|
+
* @param {boolean} fullRender - Whether to perform full render or effects only
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* host.update(true); // Full render
|
|
239
|
+
* host.update(false); // Effects only
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
update: (fullRender: boolean) => void;
|
|
243
|
+
/**
|
|
244
|
+
* Force a full re-render even if template is unchanged
|
|
245
|
+
* @method forceRender
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* host.forceRender(); // Forces DOM update even if template string matches
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
forceRender: () => void;
|
|
253
|
+
/**
|
|
254
|
+
* Clean up component and run destroy callbacks
|
|
255
|
+
* @method destroy
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* host.destroy(); // Cleans up effects, events, and runs onDestroy hooks
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
destroy: () => void;
|
|
263
|
+
/**
|
|
264
|
+
* Remove the component from the DOM
|
|
265
|
+
* @method remove
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* host.remove(); // Removes element and triggers cleanup via disconnectedCallback
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
remove: () => void;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Context object passed to the setup function, providing access to component APIs
|
|
276
|
+
*
|
|
277
|
+
* @template Props - Type of component props
|
|
278
|
+
* @template State - Type of component state
|
|
279
|
+
* @template Actions - Type of action methods
|
|
280
|
+
* @template Refs - Type of DOM refs
|
|
281
|
+
* @interface ComponentContext
|
|
282
|
+
* @since 0.1.0
|
|
283
|
+
*
|
|
284
|
+
* @example Basic usage
|
|
285
|
+
* ```typescript
|
|
286
|
+
* define('counter', {}, ({ props, state, actions, host }) => {
|
|
287
|
+
* state.count = 0;
|
|
288
|
+
* actions.increment = () => host.setState({ count: state.count + 1 });
|
|
289
|
+
* return () => `<div>${state.count}</div>`;
|
|
290
|
+
* });
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
* @example With lifecycle hooks
|
|
294
|
+
* ```typescript
|
|
295
|
+
* define('component', {}, ({ onMount, onDestroy, effect }) => {
|
|
296
|
+
* onMount(() => console.log('Mounted'));
|
|
297
|
+
* onDestroy(() => console.log('Destroyed'));
|
|
298
|
+
* effect((deps) => {
|
|
299
|
+
* const timer = setInterval(() => {}, 1000);
|
|
300
|
+
* return () => clearInterval(timer);
|
|
301
|
+
* }, []);
|
|
302
|
+
* return () => '<div>Hello</div>';
|
|
303
|
+
* });
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* @see {@link ComponentHost} for host methods
|
|
307
|
+
* @see {@link ComponentOptions} for component configuration
|
|
308
|
+
*/
|
|
309
|
+
export interface ComponentContextBase<Props = Record<string, any>, State = Record<string, any>, Actions = Record<string, Function>, Refs = Record<string, HTMLElement | HTMLElement[]>> {
|
|
310
|
+
/**
|
|
311
|
+
* Component props (read-only, updated via attributes or setProps)
|
|
312
|
+
* @type {Props}
|
|
313
|
+
* @readonly
|
|
314
|
+
*/
|
|
315
|
+
props: Props;
|
|
316
|
+
/**
|
|
317
|
+
* Component state (mutable, updated via setState/updateState)
|
|
318
|
+
* @type {State}
|
|
319
|
+
*/
|
|
320
|
+
state: State;
|
|
321
|
+
/**
|
|
322
|
+
* Action methods that can be called from event handlers
|
|
323
|
+
* @type {Actions}
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```typescript
|
|
327
|
+
* actions.handleClick = () => { /* ... *\/ };
|
|
328
|
+
* // Use in template: <button on:click="handleClick">
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
actions: Actions;
|
|
332
|
+
/**
|
|
333
|
+
* DOM element references (populated after render)
|
|
334
|
+
* @type {Refs}
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```typescript
|
|
338
|
+
* // In template: <div ref="myDiv"></div>
|
|
339
|
+
* // Access: refs.myDiv
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
refs: Refs;
|
|
343
|
+
/**
|
|
344
|
+
* Emit custom events that bubble up the DOM tree
|
|
345
|
+
* @method emit
|
|
346
|
+
* @param {string} name - Event name
|
|
347
|
+
* @param {any} [detail] - Optional event detail data
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* emit('item-clicked', { id: 123, name: 'Item' });
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
emit: (name: string, detail?: any) => void;
|
|
355
|
+
/**
|
|
356
|
+
* Listen to a custom event from a given target
|
|
357
|
+
* @method listen
|
|
358
|
+
* @param {EventTarget} target - Target to attach the listener to
|
|
359
|
+
* @param {string} name - Custom event name to listen for
|
|
360
|
+
* @param {function(CustomEvent): void} handler - Event handler
|
|
361
|
+
* @param {AddEventListenerOptions} [options] - Listener options
|
|
362
|
+
* @returns {() => void} Cleanup function to remove the listener
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* const cleanup = listen(window, 'theme-change', (e) => {
|
|
367
|
+
* console.log(e.detail);
|
|
368
|
+
* });
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
listen: (target: EventTarget, name: string, handler: (event: CustomEvent<any>) => void, options?: AddEventListenerOptions) => () => void;
|
|
372
|
+
/**
|
|
373
|
+
* Update state without triggering a re-render (triggers effects only)
|
|
374
|
+
* @method updateState
|
|
375
|
+
* @param {Partial<State>} partial - Partial state object to merge
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* ```typescript
|
|
379
|
+
* updateState({ count: 5 }); // Updates state, runs effects, but doesn't re-render
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
updateState: (partial: Partial<State>) => void;
|
|
383
|
+
/**
|
|
384
|
+
* The component host element with all host methods
|
|
385
|
+
* @type {HTMLElement & ComponentHost}
|
|
386
|
+
*
|
|
387
|
+
* @see {@link ComponentHost}
|
|
388
|
+
*/
|
|
389
|
+
host: HTMLElement & ComponentHost;
|
|
390
|
+
/**
|
|
391
|
+
* Register callback to run after component is mounted
|
|
392
|
+
* @method onMount
|
|
393
|
+
* @param {function(): void} callback - Callback function
|
|
394
|
+
* @since 0.1.0
|
|
395
|
+
*/
|
|
396
|
+
onMount: (callback: () => void) => void;
|
|
397
|
+
/**
|
|
398
|
+
* Register callback to run when component is destroyed
|
|
399
|
+
* @method onDestroy
|
|
400
|
+
* @param {function(): void} callback - Callback function
|
|
401
|
+
* @since 0.1.0
|
|
402
|
+
*/
|
|
403
|
+
onDestroy: (callback: () => void) => void;
|
|
404
|
+
/**
|
|
405
|
+
* Register callback to run after each update/re-render
|
|
406
|
+
* @method onUpdate
|
|
407
|
+
* @param {function(): void} callback - Callback function
|
|
408
|
+
* @since 0.3.0
|
|
409
|
+
*/
|
|
410
|
+
onUpdate: (callback: () => void) => void;
|
|
411
|
+
/**
|
|
412
|
+
* Register callback to run before each update/re-render
|
|
413
|
+
* @method onBeforeUpdate
|
|
414
|
+
* @param {function(): void} callback - Callback function
|
|
415
|
+
* @since 0.3.0
|
|
416
|
+
*/
|
|
417
|
+
onBeforeUpdate: (callback: () => void) => void;
|
|
418
|
+
/**
|
|
419
|
+
* Register callback to run only on the first update (after mount)
|
|
420
|
+
* @method onFirstUpdate
|
|
421
|
+
* @param {function(): void} callback - Callback function
|
|
422
|
+
* @since 0.3.0
|
|
423
|
+
*/
|
|
424
|
+
onFirstUpdate: (callback: () => void) => void;
|
|
425
|
+
/**
|
|
426
|
+
* Register callback to run when props change
|
|
427
|
+
* @method onPropsChanged
|
|
428
|
+
* @param {function(string, any, any): void} callback - Callback function
|
|
429
|
+
* @since 0.3.0
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```typescript
|
|
433
|
+
* onPropsChanged((propName, oldValue, newValue) => {
|
|
434
|
+
* console.log(`${propName} changed from ${oldValue} to ${newValue}`);
|
|
435
|
+
* });
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
onPropsChanged: (callback: (propName: string, oldValue: any, newValue: any) => void) => void;
|
|
439
|
+
/**
|
|
440
|
+
* Link a prop and a state key (two-way, no extra render)
|
|
441
|
+
*
|
|
442
|
+
* Updates state when the prop changes, and updates the prop/attribute
|
|
443
|
+
* when the state changes without triggering a render. Attribute
|
|
444
|
+
* reflection is forced even if the prop is not marked reflect: true.
|
|
445
|
+
*
|
|
446
|
+
* @method link
|
|
447
|
+
* @param {string} propName - Prop name to link
|
|
448
|
+
* @param {string} [stateKey] - State key to link (defaults to propName)
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```typescript
|
|
452
|
+
* link('value'); // state.value <-> props.value
|
|
453
|
+
* link('title', 'text'); // state.text <-> props.title
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
link: (propName: string, stateKey?: string) => void;
|
|
457
|
+
/**
|
|
458
|
+
* Register effect function that runs after renders (with optional cleanup)
|
|
459
|
+
* @method effect
|
|
460
|
+
* @param {function(any[]): (void|function())} fn - Effect function that can return cleanup
|
|
461
|
+
* @param {any[] | (() => any[])} [deps] - Optional dependency array or deps getter
|
|
462
|
+
* @returns {() => void} Cleanup function to remove the effect
|
|
463
|
+
* @since 0.2.0
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* const cleanup = effect((deps) => {
|
|
468
|
+
* const timer = setInterval(() => {}, 1000);
|
|
469
|
+
* return () => clearInterval(timer); // Cleanup function
|
|
470
|
+
* }, []);
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
effect: (fn: EffectFn, deps?: any[] | (() => any[])) => () => void;
|
|
474
|
+
/**
|
|
475
|
+
* Register a computed value that updates before renders.
|
|
476
|
+
*
|
|
477
|
+
* @method computed
|
|
478
|
+
* @param {function(any[]): *} getter - Function that returns the computed value
|
|
479
|
+
* @param {any[] | (() => any[])} [deps] - Optional dependency array or deps getter
|
|
480
|
+
* @returns {() => T} Getter for the current computed value
|
|
481
|
+
* @since 0.0.1
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* ```typescript
|
|
485
|
+
* const fullName = computed((deps) => `${props.first} ${state.last}`, () => [props.first, state.last]);
|
|
486
|
+
* return () => `<div>${fullName()}</div>`;
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
computed: <T>(getter: ComputedGetter<T>, deps?: ComputedDeps) => () => T;
|
|
490
|
+
/**
|
|
491
|
+
* Set up event delegation for dynamic content
|
|
492
|
+
* @method delegate
|
|
493
|
+
* @param {string} eventType - The event type (e.g., 'click', 'input')
|
|
494
|
+
* @param {string} selector - CSS selector to match target elements
|
|
495
|
+
* @param {function(Event, Element): void} handler - Handler function
|
|
496
|
+
* @returns {() => void} Cleanup function to remove the delegation
|
|
497
|
+
* @since 0.2.0
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
* ```typescript
|
|
501
|
+
* const cleanup = delegate('click', '.item', (e, target) => {
|
|
502
|
+
* console.log('Item clicked:', target);
|
|
503
|
+
* });
|
|
504
|
+
* ```
|
|
505
|
+
*/
|
|
506
|
+
delegate: (eventType: string, selector: string, handler: (event: Event, target: Element) => void) => () => void;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Component context including plugin-provided extensions.
|
|
510
|
+
*/
|
|
511
|
+
export type ComponentContext<Props = Record<string, any>, State = Record<string, any>, Actions = Record<string, Function>, Refs = Record<string, HTMLElement | HTMLElement[]>, Ext = {}> = ComponentContextBase<Props, State, Actions, Refs> & Ext;
|
|
512
|
+
type UnionToIntersection<U> = (U extends any ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
|
|
513
|
+
type PluginExtensions<Plugins extends readonly ComponentPlugin<any>[]> = UnionToIntersection<Plugins[number] extends ComponentPlugin<infer Ext> ? Ext : {}>;
|
|
514
|
+
/**
|
|
515
|
+
* Setup function that receives component context and returns a render function
|
|
516
|
+
*
|
|
517
|
+
* @template Props - Type of component props
|
|
518
|
+
* @template State - Type of component state
|
|
519
|
+
* @template Actions - Type of action methods
|
|
520
|
+
* @template Refs - Type of DOM refs
|
|
521
|
+
* @typedef {function} SetupFunction
|
|
522
|
+
* @param {ComponentContext<Props, State, Actions, Refs, Ext>} context - Component context
|
|
523
|
+
* @returns {() => string} Render function that returns HTML template string
|
|
524
|
+
* @since 0.1.0
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```typescript
|
|
528
|
+
* const setup: SetupFunction = ({ props, state, actions }) => {
|
|
529
|
+
* state.count = 0;
|
|
530
|
+
* actions.increment = () => state.count++;
|
|
531
|
+
* return () => `<div>Count: ${state.count}</div>`;
|
|
532
|
+
* };
|
|
533
|
+
* ```
|
|
534
|
+
*
|
|
535
|
+
* @see {@link ComponentContext}
|
|
536
|
+
*/
|
|
537
|
+
export type SetupFunction<Props = Record<string, any>, State = Record<string, any>, Actions = Record<string, Function>, Refs = Record<string, HTMLElement | HTMLElement[]>, Ext = {}> = (context: ComponentContext<Props, State, Actions, Refs, Ext>) => () => string;
|
|
538
|
+
/**
|
|
539
|
+
* Information about a delegated event handler
|
|
540
|
+
*/
|
|
541
|
+
export type DelegatedEventInfo = {
|
|
542
|
+
/** The event type (e.g., 'click', 'input') */
|
|
543
|
+
eventType: string;
|
|
544
|
+
/** CSS selector to match elements */
|
|
545
|
+
selector: string;
|
|
546
|
+
/** The actual event listener attached to the root */
|
|
547
|
+
listener: (e: Event) => void;
|
|
548
|
+
/** Set of handler functions registered for this delegation */
|
|
549
|
+
handlers: Set<(e: Event, target: Element) => void>;
|
|
550
|
+
};
|
|
551
|
+
export type EffectDeps = any[] | (() => any[]);
|
|
552
|
+
export type ComputedDeps = any[] | (() => any[]);
|
|
553
|
+
export type EffectFn = (deps?: any[]) => void | (() => void);
|
|
554
|
+
export type ComputedGetter<T = any> = (deps?: any[]) => T;
|
|
555
|
+
export type EffectRecord = {
|
|
556
|
+
fn: EffectFn;
|
|
557
|
+
deps?: EffectDeps;
|
|
558
|
+
prevDeps?: any[];
|
|
559
|
+
cleanup?: () => void;
|
|
560
|
+
};
|
|
561
|
+
export type ComputedRecord<T = any> = {
|
|
562
|
+
getter: ComputedGetter<T>;
|
|
563
|
+
deps?: ComputedDeps;
|
|
564
|
+
prevDeps?: any[];
|
|
565
|
+
value: T;
|
|
566
|
+
};
|
|
567
|
+
/**
|
|
568
|
+
* Defines a new custom element component
|
|
569
|
+
*
|
|
570
|
+
* @function define
|
|
571
|
+
* @template Props - Type of component props
|
|
572
|
+
* @template State - Type of component state
|
|
573
|
+
* @template Actions - Type of action methods
|
|
574
|
+
* @template Refs - Type of DOM refs
|
|
575
|
+
*
|
|
576
|
+
* @param {string} tagName - The custom element tag name (must contain a hyphen, e.g., 'my-component')
|
|
577
|
+
* @param {ComponentOptions} [options={}] - Component configuration options
|
|
578
|
+
* @param {SetupFunction<Props, State, Actions, Refs, PluginExtensions<Plugins>>} [setup] - Optional setup function that receives context and returns render function
|
|
579
|
+
* @returns {Function} The custom element class constructor
|
|
580
|
+
*
|
|
581
|
+
* @throws {Error} If tagName doesn't contain a hyphen (required by Custom Elements spec)
|
|
582
|
+
* @throws {Error} If component is already defined (logs warning instead of throwing)
|
|
583
|
+
*
|
|
584
|
+
* @example Basic component
|
|
585
|
+
* ```javascript
|
|
586
|
+
* define('my-counter', {
|
|
587
|
+
* props: { initialValue: { type: Number, default: 0 } }
|
|
588
|
+
* }, ({ props, state, actions, host }) => {
|
|
589
|
+
* state.count = props.initialValue;
|
|
590
|
+
* actions.increment = () => host.setState({ count: state.count + 1 });
|
|
591
|
+
* return () => `<div>Count: ${state.count}</div>`;
|
|
592
|
+
* });
|
|
593
|
+
* ```
|
|
594
|
+
*
|
|
595
|
+
* @example Component with shadow DOM
|
|
596
|
+
* ```javascript
|
|
597
|
+
* define('styled-button', {
|
|
598
|
+
* shadow: true,
|
|
599
|
+
* styles: 'button { background: blue; color: white; }'
|
|
600
|
+
* }, () => {
|
|
601
|
+
* return () => '<button>Click me</button>';
|
|
602
|
+
* });
|
|
603
|
+
* ```
|
|
604
|
+
*
|
|
605
|
+
* @example Component with TypeScript types
|
|
606
|
+
* ```typescript
|
|
607
|
+
* interface MyProps { count: number }
|
|
608
|
+
* interface MyState { value: string }
|
|
609
|
+
* interface MyActions { handleClick: () => void }
|
|
610
|
+
*
|
|
611
|
+
* define<MyProps, MyState, MyActions>('typed-component', {
|
|
612
|
+
* props: { count: { type: Number, default: 0 } }
|
|
613
|
+
* }, ({ props, state, actions }) => {
|
|
614
|
+
* state.value = `Count: ${props.count}`;
|
|
615
|
+
* actions.handleClick = () => console.log('clicked');
|
|
616
|
+
* return () => `<div>${state.value}</div>`;
|
|
617
|
+
* });
|
|
618
|
+
* ```
|
|
619
|
+
*
|
|
620
|
+
* @see {@link ComponentContext} for available context properties
|
|
621
|
+
* @see {@link ComponentOptions} for configuration options
|
|
622
|
+
* @see {@link SetupFunction} for setup function signature
|
|
623
|
+
* @since 0.1.0
|
|
624
|
+
*/
|
|
625
|
+
declare function define<Props = Record<string, any>, State = Record<string, any>, Actions = Record<string, Function>, Refs = Record<string, HTMLElement | HTMLElement[]>, Plugins extends readonly ComponentPlugin<any>[] = []>(tagName: string, options?: ComponentOptions<Plugins>, setup?: SetupFunction<Props, State, Actions, Refs, PluginExtensions<Plugins>>): typeof HTMLElement;
|
|
626
|
+
export { define, SCOPE_VERSION };
|
|
627
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH;;;;;GAKG;AACH,QAAA,MAAM,aAAa,UAAU,CAAC;AAuC9B;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAChB,iBAAiB,GACjB,iBAAiB,GACjB,kBAAkB,GAClB,iBAAiB,GACjB,gBAAgB,CAAC;AAErB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,GAAG;IACrC;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC;IACZ;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,GAAG,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI;IAClE,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,MAAM,EAAE,CACN,OAAO,EAAE,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EACjD,IAAI,EAAE,aAAa,KAChB,GAAG,CAAC;CACV,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,gB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IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAC5E,OAAO,WAAW,CA0xDpB;AAED,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function t(t,i){if(!i||"object"!=typeof i||null==i.type)return null!=t?t:i;const{type:e,default:s}=i;if(null==t)return s;try{switch(e){case String:return String(t);case Number:{const i=Number(t);return Number.isNaN(i)?s:i}case Boolean:return""===t||"true"===t||"false"!==t&&"0"!==t&&null!=t;case Object:try{return"string"==typeof t?JSON.parse(t):t}catch{return s}case Array:try{return"string"==typeof t?JSON.parse(t):t}catch{return Array.isArray(s)?s:[]}default:return t}}catch{return s}}function i(t,i,e,s){if(!s||"object"!=typeof s||!s.reflect)return;let n=null;const o=s.type;if(o===Boolean)return e?void t.setAttribute(i,""):void t.removeAttribute(i);if(o===Object||o===Array)try{n=null==e?null:JSON.stringify(e)}catch{n=null}else n=null==e?null:String(e);null==n?t.removeAttribute(i):t.setAttribute(i,n)}function e(e,s={},n){const{props:o={},shadow:r=!1,styles:h,plugins:c}=s,f=c??[],d=()=>{};class y extends HTMLElement{constructor(){super(),this.version=u,this.t={};for(const t of Object.keys(o)){const i=o[t];this.t[t]=i&&"object"==typeof i&&("type"in i||"default"in i)?i:{type:void 0,default:i,reflect:!1}}this.props={},this.state={},this.actions={},this.refs={},this.emit=this.emit.bind(this),this.listen=this.listen.bind(this),this.setState=this.setState.bind(this),this.updateState=this.updateState.bind(this),this.setProps=this.setProps.bind(this),this.scheduleUpdate=this.scheduleUpdate.bind(this),this.update=this.update.bind(this),this.forceRender=this.forceRender.bind(this),this.destroy=this.destroy.bind(this),this.i=null,this.o=null,this.h=!1,this.u=!1,this.l=r,this.p=r?this.attachShadow({mode:"open"}):this,this.m=null,this.S=[],this.v=[],this._=[],this.O=[],this.j=[],this.M=[],this.A=[],this.$=[],this.k=new Map,this.F=!1,this.T=!1,this.C={},this.H=!1,this.I=e,this.R=!1,this.U=new Set,this.q=!1,this.B=new Map,this.L=0,this.N=!1}V(t){const i=this.l?this.p.host:this;let e=t.parentElement;for(;e;){if(e===i)return!1;if(e.tagName.includes("-"))return!0;e=e.parentElement}return!1}static get observedAttributes(){return Object.keys(o)}attributeChangedCallback(i,e,s){if(e===s)return;const n=this.t[i],o=this.C[i],r=t(s,n);if(this.props[i]=r,this.F&&o!==r)for(const t of this.$)try{t(i,o,r)}catch(t){d(String(t?.message||t))}this.C[i]=r,this.U.has(i)?this.U.delete(i):this.i&&this.isConnected?this.q?this.R=!0:this.update(!0):this.R=!0}connectedCallback(){for(const i in this.t){if(!this.t.hasOwnProperty(i))continue;const e=t(this.getAttribute(i),this.t[i]);this.props[i]=e,this.C[i]=e}r||this.m||(this.m=this.J());let e=null;try{if(n){const t={props:this.props,state:this.state,actions:this.actions,refs:this.refs,emit:this.emit,listen:this.listen,updateState:this.updateState.bind(this),host:this,onMount:t=>this._.push(t),onDestroy:t=>this.O.push(t),onUpdate:t=>this.j.push(t),onBeforeUpdate:t=>this.M.push(t),onFirstUpdate:t=>this.A.push(t),onPropsChanged:t=>this.$.push(t),link:(t,e)=>{const s=e||t;this.state[s]=this.props[t],this.$.push((i,e,n)=>{i===t&&(Object.is(this.state[s],n)||(this.state[s]=n))});const n={fn:()=>{const e=this.state[s];if(Object.is(this.props[t],e))return;this.props[t]=e,this.C[t]=e;const n=this.t[t],o=n?{...n,reflect:!0}:n,r=this.getAttribute(t);this.U.add(t),i(this,t,e,o),r===this.getAttribute(t)&&this.U.delete(t)},deps:()=>[this.state[s]]};this.S.push(n)},computed:(t,i)=>{let e;if(void 0!==i)try{const t="function"==typeof i?i():i;Array.isArray(t)&&(e=t)}catch(t){String(t?.message||t)}const s={getter:t,deps:i,value:void 0!==i?t(e):t()};this.v.push(s);const n=()=>s.value;return n.P=s,this.W(n),n},effect:(t,i)=>{const e={fn:t,deps:i};return this.S.push(e),()=>this.D(e)},delegate:(t,i,e)=>(this.Z(t,i,e),()=>this.G(t,i,e))};for(const i of f)if(i)try{const e=i.extend(t,this);e&&"object"==typeof e&&Object.assign(t,e)}catch(t){d(String(t?.message||t))}e=n(t)}}catch(t){String(t?.message||t)}if(this.i="function"!=typeof e?()=>"":e,this.q=!0,this.update(!0),this.q=!1,this.R&&(this.R=!1,this.update(!0)),!this.F){this.F=!0;for(const t of this._)try{t()}catch(t){d(String(t?.message||t))}}}disconnectedCallback(){this.destroy()}remove(){super.remove()}destroy(){for(const t of this.O)try{t()}catch(t){d(String(t?.message||t))}for(const t of this.S)if(t.cleanup){try{t.cleanup()}catch(t){d(String(t?.message||t))}t.cleanup=void 0}for(const[,t]of this.k)try{this.p.removeEventListener(t.eventType,t.listener)}catch{}this.k.clear(),this.F=!1}emit(t,i){this.dispatchEvent(new CustomEvent(t,{detail:i,bubbles:!0,composed:!0}))}listen(t,i,e,s){const n=e;t.addEventListener(i,n,s);const o=()=>{try{t.removeEventListener(i,n,s)}catch{}};return this.O.push(o),o}setState(t){let i=!1;const e=t,s=this.state;for(const t in e){if(!Object.prototype.hasOwnProperty.call(e,t))continue;const n=e[t];Object.is(s[t],n)||(s[t]=n,i=!0)}if(i)if(this.q||!this.F)this.update(!0);else{if(!this.i||!this.isConnected)return;if(this.h)return;this.h=!0,requestAnimationFrame(()=>{this.h=!1,this.i&&this.isConnected&&this.update(!0)})}}updateState(t){Object.assign(this.state,t),this.i&&this.isConnected&&this.K()}setProps(t){const e=Object.keys(t);if(0===e.length)return;const s=[];for(const n of e){const e=t[n],o=this.C[n];this.props[n]=e,this.F&&o!==e&&s.push(n);const r=this.t[n];r&&r.reflect&&i(this,n,e,r),this.F&&o===e||(this.C[n]=e)}if(this.F&&s.length>0)for(const i of s){const e=this.C[i],s=t[i];for(const t of this.$)try{t(i,e,s)}catch(t){d(String(t?.message||t))}}this.i&&this.isConnected?this.update(!0):this.R=!0}scheduleUpdate(){this.i&&this.isConnected&&this.K()}K(){this.u||this.h||(this.u=!0,("function"==typeof queueMicrotask?queueMicrotask:t=>Promise.resolve().then(t))(()=>{this.u=!1,this.i&&this.isConnected&&(this.h||this.update(!1))}))}update(t){if(this.i){if(t&&this.F)for(const t of this.M)try{t()}catch(t){d(String(t?.message||t))}if(t){this.X();let t="";try{t=this.i()}catch(i){String(i?.message||i),t=""}if("string"!=typeof t&&(t=null==t?"":String(t)),t=((t,i)=>{const e={...this.props,...i};return t.replace(l,(t,i)=>{const s=e[i];return null==s?"":String(s)})})(t,this.state),!this.l){const i=`data-scope-owner="${this.I}"`;t=t.replace(/<slot(?![^>]*data-scope-owner)(\s|>)/g,`<slot ${i}$1`)}this.N=!1;const i=null!==this.o&&Object.is(this.o,t);let e=!1;i&&this.F||(this.l,this.p.innerHTML=t,this.o=t,e=!0),this.q?(this.Y(),("function"==typeof requestAnimationFrame?requestAnimationFrame:t=>setTimeout(t,0))(()=>{this.i&&this.isConnected&&(e&&!r&&this.projectSlots(),e&&this.tt(),this.it(),this.et())})):(e&&!r&&this.projectSlots(),e&&this.st(),this.it(),this.et())}else this.N&&this.X(),this.it(),this.F&&this.et()}}forceRender(){this.o=null,this.i&&this.isConnected?this.q?this.R=!0:this.update(!0):this.R=!0}et(){if(!this.T){this.T=!0;for(const t of this.A)try{t()}catch(t){d(String(t?.message||t))}}for(const t of this.j)try{t()}catch(t){d(String(t?.message||t))}this.nt()}nt(){const t=(this.l?this.p:this).querySelectorAll("*"),i=Object.prototype.hasOwnProperty,e=this.state,s=this.props;this.actions;for(let n=0;n<t.length;n++){const o=t[n];if(this.V(o))continue;if(0===o.attributes.length)continue;const r=o.attributes;for(let t=r.length-1;t>=0;t--){const n=r[t];if(!n.name.startsWith(a))continue;const h=n.name.slice(5),c=n.value,f=c?c.trim():"";let u,l=!1;if(f){const t=this.B.get(f);if(t){t.P&&(this.N=!0);try{u=t()}catch{}l=!0}}if(!l){const t=f||h,n=i.call(e,t),o=!n&&i.call(s,t);n?u=e[t]:o&&(u=s[t])}if("text"===h){const t=null==u?"":String(u);o.textContent!==t&&(o.textContent=t)}else if("html"===h){const t=null==u?"":String(u);o.innerHTML!==t&&(o.innerHTML=t)}else if(h in o){if(!Object.is(o[h],u))try{o[h]=u}catch{}if("value"===h)try{null==u?o.removeAttribute("value"):o.setAttribute("value",String(u))}catch{}}else if(null!=u)try{o.setAttribute(h,String(u))}catch{}const d=`__scopeBind_${h}`,y=o[d];if(y){const t=y.ot;t&&o.removeEventListener(t,y),delete o[d]}}}}X(){for(const t of this.v){let i,e=!0;if(void 0!==t.deps)try{const s="function"==typeof t.deps?t.deps():t.deps;if(Array.isArray(s)&&(i=s,t.prevDeps&&t.prevDeps.length===i.length)){e=!1;for(let s=0;s<i.length;s++)if(!Object.is(t.prevDeps[s],i[s])){e=!0;break}}}catch(t){d(String(t?.message||t)),e=!0,i=void 0}if(e){try{t.value=void 0!==t.deps?t.getter(i):t.getter()}catch(t){d(String(t?.message||t))}i&&(t.prevDeps=i.slice())}}}it(){for(const t of this.S){let i,e=!0;if(void 0!==t.deps)try{const s="function"==typeof t.deps?t.deps():t.deps;if(Array.isArray(s)&&(i=s,t.prevDeps&&t.prevDeps.length===i.length)){e=!1;for(let s=0;s<i.length;s++)if(!Object.is(t.prevDeps[s],i[s])){e=!0;break}}}catch(t){d(String(t?.message||t)),e=!0,i=void 0}if(e){if(t.cleanup){try{t.cleanup()}catch{}t.cleanup=void 0}try{const e=void 0!==t.deps?t.fn(i):t.fn();"function"==typeof e&&(t.cleanup=e)}catch{}i&&(t.prevDeps=i.slice())}}}D(t){const i=this.S.indexOf(t);if(-1!==i){if(t.cleanup)try{t.cleanup()}catch{}this.S.splice(i,1)}}W(t){const i=t.rt;if(i&&"string"==typeof i)return this.B.set(i,t),i;const e=`__scope_bind_${++this.L}__`;this.B.set(e,t);try{t.rt=e,t.toString=()=>e}catch{}return e}Y(){const t=(this.l?this.p:this).querySelectorAll("[ref]"),i=this.refs;for(const t in i)i.hasOwnProperty(t)&&delete i[t];if(0!==t.length)for(let e=0;e<t.length;e++){const s=t[e];if(this.V(s))continue;const n=s.getAttribute("ref");n&&(i[n]?Array.isArray(i[n])?i[n].push(s):i[n]=[i[n],s]:i[n]=s)}}tt(){const t=(this.l?this.p:this).querySelectorAll("*");for(let i=0;i<t.length;i++){const e=t[i];if(this.V(e))continue;if(0===e.attributes.length)continue;const s=e.attributes;for(let t=s.length-1;t>=0;t--){const i=s[t];if(!i.name.startsWith("on:"))continue;const n=i.name.slice(3),o=i.value,r=`__tinyHandler_${n}`,h=e[r];h&&e.removeEventListener(n,h),e.removeAttribute(i.name);const c=this.actions[o];if(c&&"function"==typeof c){const t=t=>{c.call(this.actions,t)};e[r]=t,e.addEventListener(n,t)}}}}st(){const t=(this.l?this.p:this).querySelectorAll("*"),i=this.refs;for(const t in i)i.hasOwnProperty(t)&&delete i[t];for(let e=0;e<t.length;e++){const s=t[e];if(this.V(s))continue;const n=s.getAttribute("ref");if(n&&(i[n]?Array.isArray(i[n])?i[n].push(s):i[n]=[i[n],s]:i[n]=s),s.attributes.length>0){const t=s.attributes;for(let i=t.length-1;i>=0;i--){const e=t[i];if(!e.name.startsWith("on:"))continue;const n=e.name.slice(3),o=e.value,r=`__tinyHandler_${n}`,h=s[r];h&&s.removeEventListener(n,h),s.removeAttribute(e.name);const c=this.actions[o];if(c&&"function"==typeof c){const t=t=>{c.call(this.actions,t)};s[r]=t,s.addEventListener(n,t)}}}}}J(){const t=new Map,i=this.childNodes,e=[];for(let t=0;t<i.length;t++)e.push(i[t]);for(let i=0;i<e.length;i++){const s=e[i];let n="";1===s.nodeType&&s.getAttribute&&(n=s.getAttribute("slot")||""),t.has(n)||t.set(n,[]),t.get(n).push(s)}for(let t=0;t<e.length;t++){const i=e[t];i.parentNode&&i.parentNode.removeChild(i)}return t}projectSlots(){const t=this.m||new Map,i=(this.l?this.p:this).querySelectorAll(`slot[data-scope-owner="${this.I}"]`);if(0!==i.length)for(let e=0;e<i.length;e++){const s=i[e],n=s.getAttribute("name")||"",o=t.get(n)||[];if(o.length){const t=document.createDocumentFragment();for(let i=0;i<o.length;i++){const e=o[i];let s;if(1===e.nodeType&&e.tagName.includes("-")&&e.m instanceof Map){const t=e,i=document.createElement(t.tagName.toLowerCase());for(let e=0;e<t.attributes.length;e++){const s=t.attributes[e];i.setAttribute(s.name,s.value)}for(const e of t.m.values())for(let t=0;t<e.length;t++)i.appendChild(e[t].cloneNode(!0));s=i}else s=e.cloneNode(!0);t.appendChild(s)}s.replaceWith(t)}else{const t=s.childNodes,i=[];for(let e=0;e<t.length;e++)i.push(t[e]);if(i.length>0){const t=document.createDocumentFragment();for(let e=0;e<i.length;e++)t.appendChild(i[e]);s.replaceWith(t)}}}}Z(t,i,e){const s=`${t}::${i}`;let n=this.k.get(s);if(!n){const e=t=>{const e=t.target&&t.target.closest?t.target.closest(i):null;if(e)for(const i of n.handlers)try{i(t,e)}catch{}};n={eventType:t,selector:i,listener:e,handlers:new Set},this.k.set(s,n),this.p.addEventListener(t,e)}n.handlers.add(e)}G(t,i,e){const s=`${t}::${i}`,n=this.k.get(s);if(n&&(n.handlers.delete(e),0===n.handlers.size)){try{this.p.removeEventListener(t,n.listener)}catch{}this.k.delete(s)}}}if(!customElements.get(e)){if(h&&"undefined"!=typeof document){const t=`scope-${e}-styles`;if(!document.getElementById(t)){const i=document.createElement("style");i.id=t,i.textContent=h,document.head.appendChild(i)}}try{customElements.define(e,y)}catch(t){String(t?.message||t)}}return y}const s=()=>({name:"device",extend:t=>{const i=new Map;return t.onDestroy(()=>{for(const[t,e]of i)t.removeEventListener("change",e);i.clear()}),{onMediaQuery:(t,e,s={})=>{if("undefined"==typeof window||"undefined"==typeof matchMedia)return()=>{};const{immediate:n=!0}=s,o=matchMedia(t),r=t=>{e(t.matches,t)};return o.addEventListener("change",r),i.set(o,r),n&&e(o.matches,null),()=>{o.removeEventListener("change",r),i.delete(o)}}}}}),n=(t,i={})=>({name:"morph",extend:(e,s)=>{const{ignoreActiveValue:n=!0,callbacks:o}=i,r=t(),h=s,c=h.p,f=h.l?ShadowRoot.prototype:HTMLElement.prototype,u=Object.getOwnPropertyDescriptor(f,"innerHTML"),l=t=>{r.morph(c,t,{morphStyle:"innerHTML",ignoreActiveValue:n,callbacks:o})};let a=!0;return Object.defineProperty(c,"innerHTML",{set(t){a?(u.set.call(this,t),a=!1):l(t)},get(){return u.get.call(this)},configurable:!0}),e.onDestroy(()=>{delete c.innerHTML}),{morph:l}}}),o=()=>({name:"window",extend:t=>{const i=new Set,e=new Set,s=(t,e={})=>{if("undefined"==typeof window)return()=>{};const{immediate:s=!0}=e,n=i=>{t(window.innerWidth,window.innerHeight,i)};return window.addEventListener("resize",n),i.add(n),s&&n(new UIEvent("resize")),()=>{window.removeEventListener("resize",n),i.delete(n)}};return t.onDestroy(()=>{if("undefined"!=typeof window){for(const t of i)window.removeEventListener("resize",t);i.clear();for(const t of e)t.disconnect();e.clear()}}),{onViewportResize:s,onWindowResize:(t,i={})=>{if("undefined"==typeof window)return()=>{};if("undefined"==typeof ResizeObserver)return s((i,e,s)=>t(i,e,s),i);const{immediate:n=!0}=i,o=document.documentElement,r=new ResizeObserver(i=>{const e=i[0];if(!e)return;const{width:s,height:n}=e.contentRect;t(s,n,e)});if(r.observe(o),e.add(r),n){const i=o.getBoundingClientRect();t(i.width,i.height,new UIEvent("resize"))}return()=>{r.disconnect(),e.delete(r)}}}}}),r=()=>({name:"inview",extend:(t,i)=>{const e=new Set,s=(t,i,s={})=>{if("undefined"==typeof window||"undefined"==typeof IntersectionObserver)return()=>{};const{immediate:n=!0,...o}=s;let r=!n;const h=new IntersectionObserver(e=>{for(const s of e)s.target===t&&(r?r=!1:i(s.isIntersecting,s))},o);return h.observe(t),e.add(h),()=>{h.unobserve(t),h.disconnect(),e.delete(h)}};return t.onDestroy(()=>{for(const t of e)t.disconnect();e.clear()}),{onInView:(t,e)=>s(i,t,e),observeInView:(t,i,e)=>s(t,i,e)}}}),h=t=>({name:"lenis",extend:i=>{const e=new Set;return i.onDestroy(()=>{for(const{lenis:t,handler:i}of e)"function"==typeof t.off&&t.off("scroll",i);e.clear()}),{onLenisScroll:i=>{const s=t();if(!s)return()=>{};const n=t=>{i(t)};s.on("scroll",n);const o={lenis:s,handler:n};return e.add(o),()=>{e.has(o)&&(e.delete(o),"function"==typeof s.off&&s.off("scroll",n))}}}}}),c=()=>({name:"timer",extend:t=>{const i=new Set,e=new Set,s=new Set,n={setTimeout:(t,e,...s)=>{let n;return n=setTimeout((...e)=>{i.delete(n),t(...e)},e,...s),i.add(n),n},setInterval:(t,i,...s)=>{const n=setInterval(t,i,...s);return e.add(n),n},raf:(t,i)=>{let e=0,n=!0,o=0;const r="number"==typeof i&&i>0?1e3/i:0,h=i=>{if(s.delete(e),n){if(r){if(i-o>=r){const e=o?i-o:r;o=i,t(i,e)}}else{const e=o?i-o:0;o=i,t(i,e)}e=requestAnimationFrame(h),s.add(e)}};return e=requestAnimationFrame(h),s.add(e),()=>{n&&(n=!1,s.delete(e),cancelAnimationFrame(e))}}};return t.onDestroy(()=>{for(const t of i)clearTimeout(t);i.clear();for(const t of e)clearInterval(t);e.clear();for(const t of s)cancelAnimationFrame(t);s.clear()}),{timer:n}}}),f=()=>({name:"mouse",extend:t=>{const i=new Map,e=(t,e)=>{if("undefined"==typeof window)return()=>{};const s=t=>{const i=t;e(i.clientX,i.clientY,i)};window.addEventListener(t,s);let n=i.get(t);return n||(n=new Set,i.set(t,n)),n.add(s),()=>{window.removeEventListener(t,s),n?.delete(s)}};return t.onDestroy(()=>{if("undefined"!=typeof window){for(const[t,e]of i){for(const i of e)window.removeEventListener(t,i);e.clear()}i.clear()}}),{onMouseMove:t=>e("mousemove",t),onMouseDown:t=>e("mousedown",t),onMouseUp:t=>e("mouseup",t),onMouseWheel:t=>(t=>{if("undefined"==typeof window)return()=>{};const e=i=>{const e=i;t(e.clientX,e.clientY,e.deltaY,e)};window.addEventListener("wheel",e);let s=i.get("wheel");return s||(s=new Set,i.set("wheel",s)),s.add(e),()=>{window.removeEventListener("wheel",e),s?.delete(e)}})(t)}}}),u="0.0.1",l=/\{([A-Za-z_$][\w$]*)\}/g,a="bind:";export{u as SCOPE_VERSION,e as define,s as devicePlugin,r as inViewPlugin,h as lenisPlugin,n as morphPlugin,f as mousePlugin,c as timerPlugin,o as windowPlugin};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.d.ts.map
|