@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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/content/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import type { ComponentPlugin } from '../../index';
2
+ export type DeviceControls = {
3
+ onMediaQuery: (query: string, handler: (matches: boolean, event: MediaQueryListEvent | null) => void, options?: {
4
+ immediate?: boolean;
5
+ }) => () => void;
6
+ };
7
+ export declare const devicePlugin: () => ComponentPlugin<DeviceControls>;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/device/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAEzE,MAAM,MAAM,cAAc,GAAG;IAS3B,YAAY,EAAE,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,mBAAmB,GAAG,IAAI,KAAK,IAAI,EACtE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,KAC9B,MAAM,IAAI,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,eAAe,CAAC,cAAc,CA6C5D,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { devicePlugin, type DeviceControls } from './device';
2
+ export { morphPlugin, type IdiomorphAPI, type IdiomorphGetter, type MorphControls, type MorphOptions, } from './morph';
3
+ export { windowPlugin, type WindowControls } from './window';
4
+ export { inViewPlugin, type InViewControls, type InViewHandler, type InViewOptions, } from './inview';
5
+ export { lenisPlugin, type LenisControls, type LenisGetter, type LenisInstance, type LenisScrollEvent, type LenisScrollHandler, } from './lenis';
6
+ export { timerPlugin, type TimerControls, type TimerIntervalHandle, type TimerRafCallback, type TimerRafUnsubscribe, type TimerTimeoutHandle, } from './timer';
7
+ export { mousePlugin, type MouseControls, type MouseEventHandler, type MouseUnsubscribe, type MouseWheelHandler, } from './mouse';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EACL,WAAW,EACX,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EACL,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,aAAa,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACxB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,GACxB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACvB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,63 @@
1
+ import type { ComponentPlugin } from '../../index';
2
+ /**
3
+ * In-view handler signature.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const handler: InViewHandler = (isInView, entry) => {
8
+ * if (isInView) entry.target.classList.add("is-in");
9
+ * };
10
+ * ```
11
+ */
12
+ export type InViewHandler = (isInView: boolean, entry: IntersectionObserverEntry) => void;
13
+ /**
14
+ * Options for IntersectionObserver plus an immediate callback toggle.
15
+ *
16
+ * `immediate` controls whether the first observer callback is skipped.
17
+ */
18
+ export type InViewOptions = IntersectionObserverInit & {
19
+ immediate?: boolean;
20
+ };
21
+ /**
22
+ * In-view plugin controls.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { inViewPlugin } from "@/lib/plugins/inview";
27
+ *
28
+ * define(
29
+ * "c-example",
30
+ * { plugins: [inViewPlugin()] },
31
+ * ({ onInView }) => {
32
+ * onInView((isInView) => {
33
+ * console.log("host in view:", isInView);
34
+ * });
35
+ * return () => "<div>...</div>";
36
+ * }
37
+ * );
38
+ * ```
39
+ */
40
+ export type InViewControls = {
41
+ /**
42
+ * Observe the component host element.
43
+ */
44
+ onInView: (handler: InViewHandler, options?: InViewOptions) => () => void;
45
+ /**
46
+ * Observe a specific element (ref or any Element).
47
+ */
48
+ observeInView: (element: Element, handler: InViewHandler, options?: InViewOptions) => () => void;
49
+ };
50
+ /**
51
+ * In-view plugin based on IntersectionObserver.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const { observeInView } = inViewPlugin().extend(ctx, host);
56
+ * observeInView(el, (isInView) => {
57
+ * el.toggleAttribute("data-inview", isInView);
58
+ * }, { rootMargin: "0px 0px -20% 0px" });
59
+ * ```
60
+ */
61
+ declare const inViewPlugin: () => ComponentPlugin<InViewControls>;
62
+ export { inViewPlugin, type InViewControls as InViewPluginControls, type InViewHandler as InViewPluginHandler, type InViewOptions as InViewPluginOptions, };
63
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/inview/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAEzE;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,CAC1B,QAAQ,EAAE,OAAO,EACjB,KAAK,EAAE,yBAAyB,KAC7B,IAAI,CAAC;AAEV;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,wBAAwB,GAAG;IACrD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,QAAQ,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,MAAM,IAAI,CAAC;IAC1E;;OAEG;IACH,aAAa,EAAE,CACb,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,aAAa,KACpB,MAAM,IAAI,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,QAAA,MAAM,YAAY,QAAO,eAAe,CAAC,cAAc,CA4DrD,CAAC;AAEH,OAAO,EACL,YAAY,EACZ,KAAK,cAAc,IAAI,oBAAoB,EAC3C,KAAK,aAAa,IAAI,mBAAmB,EACzC,KAAK,aAAa,IAAI,mBAAmB,GAC1C,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { ComponentPlugin } from '../../index';
2
+ /**
3
+ * Minimal Lenis instance interface used by this plugin.
4
+ * Compatible with the Lenis smooth scroll library (lenis package).
5
+ */
6
+ export interface LenisInstance {
7
+ on(event: 'scroll', handler: (event: LenisScrollEvent) => void): void;
8
+ off?(event: 'scroll', handler: (event: LenisScrollEvent) => void): void;
9
+ }
10
+ /**
11
+ * Lenis scroll event payload.
12
+ * Emitted on each scroll update with current scroll state.
13
+ */
14
+ export interface LenisScrollEvent {
15
+ scroll: number;
16
+ limit: number;
17
+ velocity: number;
18
+ direction: number;
19
+ progress: number;
20
+ }
21
+ /** Handler called on each Lenis scroll event. */
22
+ export type LenisScrollHandler = (event: LenisScrollEvent) => void;
23
+ /** Controls exposed to components when the lenis plugin is used. */
24
+ export type LenisControls = {
25
+ /** Subscribe to Lenis scroll events. Returns an unsubscribe function. */
26
+ onLenisScroll: (handler: LenisScrollHandler) => () => void;
27
+ };
28
+ /** Factory that returns the current Lenis instance (may be null before init). */
29
+ export type LenisGetter = () => LenisInstance | null | undefined;
30
+ /**
31
+ * Plugin that wires components to Lenis smooth scroll events.
32
+ *
33
+ * @param getLenis - Function that returns the current Lenis instance
34
+ * @returns A component plugin providing onLenisScroll
35
+ */
36
+ export declare const lenisPlugin: (getLenis: LenisGetter) => ComponentPlugin<LenisControls>;
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/lenis/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAEzE;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI,CAAC;IACtE,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI,CAAC;CACzE;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,iDAAiD;AACjD,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;AAEnE,oEAAoE;AACpE,MAAM,MAAM,aAAa,GAAG;IAC1B,yEAAyE;IACzE,aAAa,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,MAAM,IAAI,CAAC;CAC5D,CAAC;AAEF,iFAAiF;AACjF,MAAM,MAAM,WAAW,GAAG,MAAM,aAAa,GAAG,IAAI,GAAG,SAAS,CAAC;AAEjE;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GACtB,UAAU,WAAW,KACpB,eAAe,CAAC,aAAa,CAyC9B,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/lerp/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,92 @@
1
+ import type { ComponentPlugin } from '../../index';
2
+ /**
3
+ * Minimal Idiomorph API used by this plugin.
4
+ * Compatible with the idiomorph package.
5
+ */
6
+ export interface IdiomorphAPI {
7
+ morph(target: Element, html: string, options?: Record<string, unknown>): void;
8
+ }
9
+ /** Factory that returns the Idiomorph instance to use for morphing. */
10
+ export type IdiomorphGetter = () => IdiomorphAPI;
11
+ /**
12
+ * Options for the morph plugin.
13
+ */
14
+ export type MorphOptions = {
15
+ /**
16
+ * Preserve the value of the focused input element during morph.
17
+ * @default true
18
+ */
19
+ ignoreActiveValue?: boolean;
20
+ /**
21
+ * Additional callbacks forwarded to Idiomorph.
22
+ *
23
+ * @see https://github.com/bigskysoftware/idiomorph#callbacks
24
+ */
25
+ callbacks?: Record<string, (...args: any[]) => any>;
26
+ };
27
+ /**
28
+ * Morph plugin controls.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { Idiomorph } from 'idiomorph';
33
+ * import { morphPlugin } from "@/lib/plugins/morph";
34
+ *
35
+ * define(
36
+ * "c-search",
37
+ * { plugins: [morphPlugin(() => Idiomorph)] },
38
+ * ({ morph, state, actions, host }) => {
39
+ * state.query = "";
40
+ * actions.onInput = (e: Event) => {
41
+ * host.setState({ query: (e.target as HTMLInputElement).value });
42
+ * };
43
+ * return () => `
44
+ * <input type="text" on:input="onInput" />
45
+ * <p>Results for: {query}</p>
46
+ * `;
47
+ * }
48
+ * );
49
+ * ```
50
+ */
51
+ export type MorphControls = {
52
+ /**
53
+ * Morph the component root with the given HTML string.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * morph('<div class="updated">New content</div>');
58
+ * ```
59
+ */
60
+ morph: (html: string) => void;
61
+ };
62
+ /**
63
+ * DOM morphing plugin powered by Idiomorph.
64
+ *
65
+ * Intercepts `innerHTML` writes on the component root so that every
66
+ * re-render after the initial mount patches the existing DOM in place
67
+ * instead of replacing it. This preserves focus, selection, scroll
68
+ * position and running CSS animations across re-renders.
69
+ *
70
+ * The first render always uses native `innerHTML` for speed since
71
+ * there is no existing DOM state to preserve.
72
+ *
73
+ * @example Basic usage
74
+ * ```ts
75
+ * import { Idiomorph } from 'idiomorph';
76
+ *
77
+ * define("c-counter", { plugins: [morphPlugin(() => Idiomorph)] }, ({ state, actions, host }) => {
78
+ * state.count = 0;
79
+ * actions.increment = () => host.setState({ count: state.count + 1 });
80
+ * return () => `<button on:click="increment">Count: {count}</button>`;
81
+ * });
82
+ * ```
83
+ *
84
+ * @example With options
85
+ * ```ts
86
+ * define("c-editor", { plugins: [morphPlugin(() => Idiomorph, { ignoreActiveValue: false })] }, ({ host }) => {
87
+ * return () => `<textarea></textarea>`;
88
+ * });
89
+ * ```
90
+ */
91
+ export declare const morphPlugin: (getIdiomorph: IdiomorphGetter, options?: MorphOptions) => ComponentPlugin<MorphControls>;
92
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/morph/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAEzE;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC/E;AAED,uEAAuE;AACvE,MAAM,MAAM,eAAe,GAAG,MAAM,YAAY,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;;;OAOG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,WAAW,GACtB,cAAc,eAAe,EAC7B,UAAS,YAAiB,KACzB,eAAe,CAAC,aAAa,CAkD9B,CAAC"}
@@ -0,0 +1,91 @@
1
+ import type { ComponentPlugin } from '../../index';
2
+ /** Handler for mouse move, down, and up events. Receives client coordinates and the native event. */
3
+ export type MouseEventHandler = (x: number, y: number, event: MouseEvent) => void;
4
+ /** Handler for wheel events. Receives client coordinates, scroll delta, and the native event. */
5
+ export type MouseWheelHandler = (x: number, y: number, deltaY: number, event: WheelEvent) => void;
6
+ /** Unsubscribe function returned by each mouse listener. Call to remove the listener. */
7
+ export type MouseUnsubscribe = () => void;
8
+ /**
9
+ * Mouse plugin controls. All listeners are bound to `window` and cleaned up on component destroy.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * define("cursor-follower", { plugins: [mousePlugin()] }, ({ onMouseMove, host }) => {
14
+ * const stop = onMouseMove((x, y) => {
15
+ * host.updateState({ cursorX: x, cursorY: y });
16
+ * });
17
+ * return () => `<div style="left: {cursorX}px; top: {cursorY}px">...</div>`;
18
+ * });
19
+ * ```
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * // Parallax on scroll
24
+ * onMouseWheel((x, y, deltaY) => {
25
+ * parallaxOffset += deltaY * 0.1;
26
+ * });
27
+ * ```
28
+ */
29
+ export type MouseControls = {
30
+ /**
31
+ * Subscribe to global mouse move. Returns an unsubscribe function.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const stop = onMouseMove((x, y) => {
36
+ * console.log(`cursor at ${x}, ${y}`);
37
+ * });
38
+ * // later: stop();
39
+ * ```
40
+ */
41
+ onMouseMove: (handler: MouseEventHandler) => MouseUnsubscribe;
42
+ /**
43
+ * Subscribe to global mouse down. Returns an unsubscribe function.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * onMouseDown((x, y, e) => {
48
+ * if (e.button === 0) startDrag(x, y);
49
+ * });
50
+ * ```
51
+ */
52
+ onMouseDown: (handler: MouseEventHandler) => MouseUnsubscribe;
53
+ /**
54
+ * Subscribe to global mouse up. Returns an unsubscribe function.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * onMouseUp(() => endDrag());
59
+ * ```
60
+ */
61
+ onMouseUp: (handler: MouseEventHandler) => MouseUnsubscribe;
62
+ /**
63
+ * Subscribe to global wheel events. Returns an unsubscribe function.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * onMouseWheel((x, y, deltaY) => {
68
+ * zoomLevel += deltaY > 0 ? -0.1 : 0.1;
69
+ * });
70
+ * ```
71
+ */
72
+ onMouseWheel: (handler: MouseWheelHandler) => MouseUnsubscribe;
73
+ };
74
+ /**
75
+ * Mouse plugin – global mouse and wheel listeners with automatic cleanup.
76
+ *
77
+ * Listeners are attached to `window`. All subscriptions are removed when the
78
+ * component is destroyed. Safe to use in SSR (no-op when `window` is undefined).
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * define("my-component", { plugins: [mousePlugin()] }, ({ onMouseMove, onMouseDown, onMouseUp }) => {
83
+ * onMouseMove((x, y) => updateCursor(x, y));
84
+ * onMouseDown((x, y, e) => e.button === 0 && startDrag(x, y));
85
+ * onMouseUp(() => endDrag());
86
+ * return () => `<div>...</div>`;
87
+ * });
88
+ * ```
89
+ */
90
+ export declare const mousePlugin: () => ComponentPlugin<MouseControls>;
91
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/mouse/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAEzE,qGAAqG;AACrG,MAAM,MAAM,iBAAiB,GAAG,CAC9B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,UAAU,KACd,IAAI,CAAC;AAEV,iGAAiG;AACjG,MAAM,MAAM,iBAAiB,GAAG,CAC9B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,KACd,IAAI,CAAC;AAEV,yFAAyF;AACzF,MAAM,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;;;;;;OAUG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,gBAAgB,CAAC;IAC9D;;;;;;;;;OASG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,gBAAgB,CAAC;IAC9D;;;;;;;OAOG;IACH,SAAS,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,gBAAgB,CAAC;IAC5D;;;;;;;;;OASG;IACH,YAAY,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,gBAAgB,CAAC;CAChE,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,WAAW,QAAO,eAAe,CAAC,aAAa,CAyE1D,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/spring/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,82 @@
1
+ import type { ComponentPlugin } from '../../index';
2
+ /** Handle returned by `timer.setTimeout`. Use with `clearTimeout` if needed before destroy. */
3
+ export type TimerTimeoutHandle = ReturnType<typeof setTimeout>;
4
+ /** Handle returned by `timer.setInterval`. Use with `clearInterval` if needed before destroy. */
5
+ export type TimerIntervalHandle = ReturnType<typeof setInterval>;
6
+ /** Callback for `timer.raf`. Receives high-res timestamp and time since last frame (ms). */
7
+ export type TimerRafCallback = (time: number, deltaTime: number) => void;
8
+ /** Unsubscribe function returned by `timer.raf`. Call to stop the animation loop. */
9
+ export type TimerRafUnsubscribe = () => void;
10
+ /**
11
+ * Timer plugin controls. All timeouts, intervals, and RAF loops are cleared on component destroy.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * define("delayed-tooltip", { plugins: [timerPlugin()] }, ({ timer }) => {
16
+ * timer.setTimeout(() => showTooltip(), 500);
17
+ * timer.raf((time, dt) => updateAnimation(dt));
18
+ * return () => `<div>...</div>`;
19
+ * });
20
+ * ```
21
+ */
22
+ export type TimerControls = {
23
+ /**
24
+ * Scoped `setTimeout`. Cleared automatically on component destroy.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const id = timer.setTimeout(() => doSomething(), 1000);
29
+ * // or with args: timer.setTimeout((a, b) => log(a, b), 500, "hello", 42);
30
+ * ```
31
+ */
32
+ setTimeout: (cb: (...args: unknown[]) => void, delay?: number, ...args: unknown[]) => TimerTimeoutHandle;
33
+ /**
34
+ * Scoped `setInterval`. Cleared automatically on component destroy.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * timer.setInterval(() => tick(), 1000);
39
+ * ```
40
+ */
41
+ setInterval: (cb: (...args: unknown[]) => void, delay?: number, ...args: unknown[]) => TimerIntervalHandle;
42
+ /**
43
+ * RequestAnimationFrame loop. Optionally throttle to a target FPS.
44
+ * Returns an unsubscribe function to stop the loop early.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const stop = timer.raf((time, deltaTime) => {
49
+ * position += velocity * (deltaTime / 1000);
50
+ * });
51
+ * // later: stop();
52
+ * ```
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * // Throttle to 30 FPS
57
+ * timer.raf((time, dt) => update(dt), 30);
58
+ * ```
59
+ */
60
+ raf: (cb: TimerRafCallback, fps?: number) => TimerRafUnsubscribe;
61
+ };
62
+ /**
63
+ * Timer plugin – scoped setTimeout, setInterval, and RAF with automatic cleanup.
64
+ *
65
+ * All timers are cleared when the component is destroyed. The RAF loop supports
66
+ * optional FPS throttling for performance-sensitive animations.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * define("my-component", { plugins: [timerPlugin()] }, ({ timer }) => {
71
+ * timer.setTimeout(() => host.updateState({ ready: true }), 2000);
72
+ * const stop = timer.raf((time, dt) => {
73
+ * host.updateState({ elapsed: time });
74
+ * });
75
+ * return () => `<div>{elapsed}</div>`;
76
+ * });
77
+ * ```
78
+ */
79
+ export declare const timerPlugin: () => ComponentPlugin<{
80
+ timer: TimerControls;
81
+ }>;
82
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/timer/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAEzE,+FAA+F;AAC/F,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AAE/D,iGAAiG;AACjG,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAEjE,4FAA4F;AAC5F,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;AAEzE,qFAAqF;AACrF,MAAM,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC;AAE7C;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;;;;OAQG;IACH,UAAU,EAAE,CACV,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EAChC,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,IAAI,EAAE,OAAO,EAAE,KACf,kBAAkB,CAAC;IACxB;;;;;;;OAOG;IACH,WAAW,EAAE,CACX,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EAChC,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,IAAI,EAAE,OAAO,EAAE,KACf,mBAAmB,CAAC;IACzB;;;;;;;;;;;;;;;;;OAiBG;IACH,GAAG,EAAE,CAAC,EAAE,EAAE,gBAAgB,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,mBAAmB,CAAC;CAClE,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,WAAW,QAAO,eAAe,CAAC;IAAE,KAAK,EAAE,aAAa,CAAA;CAAE,CAyErE,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { ComponentPlugin } from '../../index';
2
+ export type WindowControls = {
3
+ onViewportResize: (handler: (width: number, height: number, event: UIEvent) => void, options?: {
4
+ immediate?: boolean;
5
+ }) => () => void;
6
+ onWindowResize: (handler: (width: number, height: number, event: UIEvent | ResizeObserverEntry) => void, options?: {
7
+ immediate?: boolean;
8
+ }) => () => void;
9
+ };
10
+ export declare const windowPlugin: () => ComponentPlugin<WindowControls>;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/window/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAEzE,MAAM,MAAM,cAAc,GAAG;IAO3B,gBAAgB,EAAE,CAChB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,EAChE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,KAC9B,MAAM,IAAI,CAAC;IAShB,cAAc,EAAE,CACd,OAAO,EAAE,CACP,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,GAAG,mBAAmB,KACjC,IAAI,EACT,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,KAC9B,MAAM,IAAI,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,eAAe,CAAC,cAAc,CA8E5D,CAAC"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@petit-kit/scoped",
3
+ "version": "0.0.1",
4
+ "description": "A lightweight, reactive web component framework with built-in plugins for modern web development.",
5
+ "keywords": [
6
+ "web-components",
7
+ "custom-elements",
8
+ "reactive",
9
+ "framework-agnostic",
10
+ "typescript"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/petit-kit/scoped"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/petit-kit/scoped/issues"
18
+ },
19
+ "homepage": "https://github.com/petit-kit/scoped",
20
+ "type": "module",
21
+ "main": "./dist/index.cjs",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.cjs"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "sideEffects": false,
35
+ "author": "",
36
+ "license": "MIT",
37
+ "devDependencies": {
38
+ "@rollup/plugin-node-resolve": "^16.0.0",
39
+ "@rollup/plugin-replace": "^6.0.3",
40
+ "@rollup/plugin-terser": "^0.4.4",
41
+ "@rollup/plugin-typescript": "^12.0.0",
42
+ "prettier": "^3.8.1",
43
+ "rollup": "^4.28.1",
44
+ "tslib": "^2.8.1",
45
+ "typescript": "^5.7.2"
46
+ },
47
+ "scripts": {
48
+ "build": "npm run clean && npm run format && rollup -c && npm run build:types",
49
+ "build:types": "tsc -p tsconfig.declarations.json",
50
+ "dev": "rollup -c -w",
51
+ "clean": "rm -rf dist",
52
+ "format": "prettier --write .",
53
+ "format:check": "prettier --check ."
54
+ }
55
+ }