@petit-kit/scoped 0.0.6 → 0.0.7
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 +26 -11
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +656 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- 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 +12 -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 +42 -0
- package/dist/plugins/lerp/index.d.ts.map +1 -0
- package/dist/plugins/localstorage/index.d.ts +57 -0
- package/dist/plugins/localstorage/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/pointer/index.d.ts +59 -0
- package/dist/plugins/pointer/index.d.ts.map +1 -0
- package/dist/plugins/spring/index.d.ts +42 -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 +14 -0
- package/dist/plugins/window/index.d.ts.map +1 -0
- package/package.json +13 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/pointer/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AACzE,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAW3D,+CAA+C;AAC/C,MAAM,MAAM,eAAe,GAAG;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,mFAAmF;AACnF,MAAM,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,CAAC;AAEhE;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;;;;;;;;OAaG;IACH,aAAa,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACrD,0EAA0E;IAC1E,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;CAC3C,CAAC;AAoCF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,QAAO,eAAe,CAAC,eAAe,CAsD9D,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ComponentPlugin } from '../../index';
|
|
2
|
+
import { spring } from '@petit-kit/animate';
|
|
3
|
+
type SpringValue = number | number[] | Record<string, number>;
|
|
4
|
+
type SpringOptions<T extends SpringValue = number> = Parameters<typeof spring<T>>[0];
|
|
5
|
+
type SpringController<T extends SpringValue = number> = ReturnType<typeof spring<T>>;
|
|
6
|
+
export type SpringControls = {
|
|
7
|
+
/**
|
|
8
|
+
* Create an independent spring controller.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const springX = createSpring({ from: 0, to: 1, stiffness: 200 });
|
|
12
|
+
* springX.setTarget(1);
|
|
13
|
+
*/
|
|
14
|
+
createSpring: <T extends SpringValue>(options?: SpringOptions<T>) => SpringController<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Drive a spring controller on the scoped timer RAF.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const scale = createSpring({ from: 0, to: 1 });
|
|
20
|
+
* const stop = runSpring(scale, (value) => {
|
|
21
|
+
* host.updateState({ scale: value });
|
|
22
|
+
* });
|
|
23
|
+
*/
|
|
24
|
+
runSpring: <T extends SpringValue>(controller: SpringController<T>, onUpdate: (value: T, controller: SpringController<T>) => void, options?: {
|
|
25
|
+
fps?: number;
|
|
26
|
+
immediate?: boolean;
|
|
27
|
+
stopWhenDone?: boolean;
|
|
28
|
+
}) => () => void;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Scoped spring plugin built on top of the timer plugin.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* define("my-component", { plugins: [springPlugin()] }, ({ createSpring, runSpring, host }) => {
|
|
35
|
+
* const scale = createSpring({ from: 0.8, to: 1 });
|
|
36
|
+
* runSpring(scale, (value) => host.updateState({ scale: value }));
|
|
37
|
+
* return () => `<div bind:style="transform: scale({scale})"></div>`;
|
|
38
|
+
* });
|
|
39
|
+
*/
|
|
40
|
+
export declare const springPlugin: () => ComponentPlugin<SpringControls>;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/spring/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC9D,KAAK,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,MAAM,IAAI,UAAU,CAC7D,OAAO,MAAM,CAAC,CAAC,CAAC,CACjB,CAAC,CAAC,CAAC,CAAC;AACL,KAAK,gBAAgB,CAAC,CAAC,SAAS,WAAW,GAAG,MAAM,IAAI,UAAU,CAChE,OAAO,MAAM,CAAC,CAAC,CAAC,CACjB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B;;;;;;OAMG;IACH,YAAY,EAAE,CAAC,CAAC,SAAS,WAAW,EAClC,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,KACvB,gBAAgB,CAAC,CAAC,CAAC,CAAC;IACzB;;;;;;;;OAQG;IACH,SAAS,EAAE,CAAC,CAAC,SAAS,WAAW,EAC/B,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC/B,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,IAAI,EAC7D,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,KACpE,MAAM,IAAI,CAAC;CACjB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,QAAO,eAAe,CAAC,cAAc,CAyE5D,CAAC"}
|
|
@@ -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,14 @@
|
|
|
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
|
+
onWindowScroll: (handler: (scrollX: number, scrollY: number, event: Event) => void, options?: {
|
|
10
|
+
immediate?: boolean;
|
|
11
|
+
}) => () => void;
|
|
12
|
+
};
|
|
13
|
+
export declare const windowPlugin: () => ComponentPlugin<WindowControls>;
|
|
14
|
+
//# 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;IAQhB,cAAc,EAAE,CACd,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,EACjE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,KAC9B,MAAM,IAAI,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,eAAe,CAAC,cAAc,CAuG5D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@petit-kit/scoped",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "A lightweight, reactive web component framework with built-in plugins for modern web development.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components",
|
|
@@ -32,6 +32,17 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"sideEffects": false,
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "pnpm run version:patch && pnpm run build:doc && pnpm run clean && pnpm run format && rollup -c && pnpm run build:types",
|
|
37
|
+
"version:patch": "node version/patch.js",
|
|
38
|
+
"build:types": "tsc -p tsconfig.declarations.json",
|
|
39
|
+
"build:doc": "node doc/index.js",
|
|
40
|
+
"dev": "rollup -c -w",
|
|
41
|
+
"clean": "rm -rf dist",
|
|
42
|
+
"format": "prettier --write .",
|
|
43
|
+
"format:check": "prettier --check .",
|
|
44
|
+
"publish": "pnpm build && pnpm publish --access public"
|
|
45
|
+
},
|
|
35
46
|
"author": "",
|
|
36
47
|
"license": "MIT",
|
|
37
48
|
"devDependencies": {
|
|
@@ -46,14 +57,5 @@
|
|
|
46
57
|
},
|
|
47
58
|
"dependencies": {
|
|
48
59
|
"@petit-kit/animate": "^0.0.1"
|
|
49
|
-
},
|
|
50
|
-
"scripts": {
|
|
51
|
-
"build": "pnpm run build:doc && pnpm run clean && pnpm run format && rollup -c && pnpm run build:types",
|
|
52
|
-
"build:types": "tsc -p tsconfig.declarations.json",
|
|
53
|
-
"build:doc": "node doc/index.js",
|
|
54
|
-
"dev": "rollup -c -w",
|
|
55
|
-
"clean": "rm -rf dist",
|
|
56
|
-
"format": "prettier --write .",
|
|
57
|
-
"format:check": "prettier --check ."
|
|
58
60
|
}
|
|
59
|
-
}
|
|
61
|
+
}
|