@akashjs/runtime 0.1.43 → 0.2.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/dist/animate.d.cts +145 -0
- package/dist/animate.d.ts +145 -0
- package/dist/chunk-3AL2DVPZ.cjs +13 -0
- package/dist/chunk-3AL2DVPZ.cjs.map +1 -0
- package/dist/{chunk-TBCX5WQQ.cjs → chunk-6NX6JRSV.cjs} +3 -3
- package/dist/{chunk-TBCX5WQQ.cjs.map → chunk-6NX6JRSV.cjs.map} +1 -1
- package/dist/chunk-772SU4MG.js +2 -0
- package/dist/chunk-772SU4MG.js.map +1 -0
- package/dist/chunk-7LQZF3XA.cjs +2 -0
- package/dist/chunk-7LQZF3XA.cjs.map +1 -0
- package/dist/chunk-BT6HNBE7.js +5 -0
- package/dist/chunk-BT6HNBE7.js.map +1 -0
- package/dist/{chunk-NC5RE4IQ.js → chunk-D6QQYZIC.js} +2 -2
- package/dist/{chunk-NC5RE4IQ.js.map → chunk-D6QQYZIC.js.map} +1 -1
- package/dist/{chunk-CO4D6JTQ.cjs → chunk-H4SAK7A5.cjs} +2 -2
- package/dist/{chunk-CO4D6JTQ.cjs.map → chunk-H4SAK7A5.cjs.map} +1 -1
- package/dist/{chunk-WG5GKD3B.js → chunk-IM2VW4TK.js} +3 -3
- package/dist/{chunk-WG5GKD3B.js.map → chunk-IM2VW4TK.js.map} +1 -1
- package/dist/chunk-NQVWTQ2I.cjs +5 -0
- package/dist/chunk-NQVWTQ2I.cjs.map +1 -0
- package/dist/{chunk-YSVREYEH.cjs → chunk-NVZLEJXB.cjs} +2 -2
- package/dist/{chunk-YSVREYEH.cjs.map → chunk-NVZLEJXB.cjs.map} +1 -1
- package/dist/{chunk-CEJF44LZ.js → chunk-ODDXU5DO.js} +2 -2
- package/dist/chunk-ODDXU5DO.js.map +1 -0
- package/dist/chunk-POLTPHUA.js +13 -0
- package/dist/chunk-POLTPHUA.js.map +1 -0
- package/dist/{chunk-YN2TQLVA.cjs → chunk-YIB4EKVI.cjs} +2 -2
- package/dist/chunk-YIB4EKVI.cjs.map +1 -0
- package/dist/{chunk-42ZHET2G.js → chunk-Z5LQV5ND.js} +2 -2
- package/dist/{chunk-42ZHET2G.js.map → chunk-Z5LQV5ND.js.map} +1 -1
- package/dist/component-C1WnFcRp.d.cts +59 -0
- package/dist/component-C1WnFcRp.d.ts +59 -0
- package/dist/context-2uQ6fuxu.d.cts +57 -0
- package/dist/context-2uQ6fuxu.d.ts +57 -0
- package/dist/core.cjs +1 -1
- package/dist/core.d.cts +65 -0
- package/dist/core.d.ts +65 -0
- package/dist/core.js +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3218 -0
- package/dist/index.d.ts +3218 -0
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/machine.cjs +1 -1
- package/dist/machine.d.cts +87 -0
- package/dist/machine.d.ts +87 -0
- package/dist/machine.js +1 -1
- package/dist/offline.cjs +1 -1
- package/dist/offline.d.cts +73 -0
- package/dist/offline.d.ts +73 -0
- package/dist/offline.js +1 -1
- package/dist/pwa.cjs +1 -1
- package/dist/pwa.d.cts +80 -0
- package/dist/pwa.d.ts +80 -0
- package/dist/pwa.js +1 -1
- package/dist/signals-C7XfOHHR.d.cts +55 -0
- package/dist/signals-C7XfOHHR.d.ts +55 -0
- package/dist/ssr.cjs +1 -1
- package/dist/ssr.d.cts +78 -0
- package/dist/ssr.d.ts +78 -0
- package/dist/ssr.js +1 -1
- package/dist/store.cjs +1 -1
- package/dist/store.d.cts +88 -0
- package/dist/store.d.ts +88 -0
- package/dist/store.js +1 -1
- package/dist/sync.cjs +1 -1
- package/dist/sync.d.cts +128 -0
- package/dist/sync.d.ts +128 -0
- package/dist/sync.js +1 -1
- package/dist/test.cjs +2 -2
- package/dist/test.d.cts +109 -0
- package/dist/test.d.ts +109 -0
- package/dist/test.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-367DJVST.js +0 -5
- package/dist/chunk-367DJVST.js.map +0 -1
- package/dist/chunk-3KIPMVCN.js +0 -2
- package/dist/chunk-3KIPMVCN.js.map +0 -1
- package/dist/chunk-CEJF44LZ.js.map +0 -1
- package/dist/chunk-M7HHZMIO.cjs +0 -2
- package/dist/chunk-M7HHZMIO.cjs.map +0 -1
- package/dist/chunk-RTJ6UDGV.cjs +0 -13
- package/dist/chunk-RTJ6UDGV.cjs.map +0 -1
- package/dist/chunk-TWA4T6PX.js +0 -13
- package/dist/chunk-TWA4T6PX.js.map +0 -1
- package/dist/chunk-YIVBLM2A.cjs +0 -5
- package/dist/chunk-YIVBLM2A.cjs.map +0 -1
- package/dist/chunk-YN2TQLVA.cjs.map +0 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animation module.
|
|
3
|
+
*
|
|
4
|
+
* State-based animations, stagger, group, sequence, keyframes,
|
|
5
|
+
* and spring physics. Goes far beyond CSS transitions.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const fadeIn = animate(el, { opacity: [0, 1] }, { duration: 300 });
|
|
9
|
+
* const staggered = animateStagger('.item', { opacity: [0, 1], y: [20, 0] }, { stagger: 50 });
|
|
10
|
+
* const spring = animateSpring(el, { scale: 1.2 }, { stiffness: 300, damping: 20 });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
interface AnimationOptions {
|
|
14
|
+
/** Duration in ms (default: 300) */
|
|
15
|
+
duration?: number;
|
|
16
|
+
/** Easing function or CSS easing string (default: 'ease') */
|
|
17
|
+
easing?: string;
|
|
18
|
+
/** Delay before animation starts in ms */
|
|
19
|
+
delay?: number;
|
|
20
|
+
/** Number of iterations (Infinity for loop) */
|
|
21
|
+
iterations?: number;
|
|
22
|
+
/** Direction: normal, reverse, alternate */
|
|
23
|
+
direction?: PlaybackDirection;
|
|
24
|
+
/** Fill mode */
|
|
25
|
+
fill?: FillMode;
|
|
26
|
+
/** Callback when animation completes */
|
|
27
|
+
onComplete?: () => void;
|
|
28
|
+
}
|
|
29
|
+
interface StaggerOptions extends AnimationOptions {
|
|
30
|
+
/** Delay between each element in ms */
|
|
31
|
+
stagger?: number;
|
|
32
|
+
/** Stagger from: 'start', 'center', 'end' */
|
|
33
|
+
from?: 'start' | 'center' | 'end';
|
|
34
|
+
}
|
|
35
|
+
interface SpringOptions {
|
|
36
|
+
/** Spring stiffness (default: 100) */
|
|
37
|
+
stiffness?: number;
|
|
38
|
+
/** Damping ratio (default: 10) */
|
|
39
|
+
damping?: number;
|
|
40
|
+
/** Mass (default: 1) */
|
|
41
|
+
mass?: number;
|
|
42
|
+
/** Velocity threshold to stop (default: 0.01) */
|
|
43
|
+
threshold?: number;
|
|
44
|
+
/** Callback when animation completes */
|
|
45
|
+
onComplete?: () => void;
|
|
46
|
+
}
|
|
47
|
+
interface AnimationControl {
|
|
48
|
+
/** Play the animation */
|
|
49
|
+
play(): void;
|
|
50
|
+
/** Pause the animation */
|
|
51
|
+
pause(): void;
|
|
52
|
+
/** Cancel the animation */
|
|
53
|
+
cancel(): void;
|
|
54
|
+
/** Reverse the animation */
|
|
55
|
+
reverse(): void;
|
|
56
|
+
/** Promise that resolves when animation completes */
|
|
57
|
+
finished: Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
type PropertyValue = number | string | [number | string, number | string];
|
|
60
|
+
/**
|
|
61
|
+
* Animate an element using the Web Animations API.
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const ctrl = animate(el, {
|
|
65
|
+
* opacity: [0, 1],
|
|
66
|
+
* transform: ['translateY(20px)', 'translateY(0)'],
|
|
67
|
+
* }, { duration: 300, easing: 'ease-out' });
|
|
68
|
+
*
|
|
69
|
+
* await ctrl.finished;
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function animate(el: HTMLElement, properties: Record<string, PropertyValue>, options?: AnimationOptions): AnimationControl;
|
|
73
|
+
/**
|
|
74
|
+
* Animate multiple elements with staggered timing.
|
|
75
|
+
*
|
|
76
|
+
* ```ts
|
|
77
|
+
* animateStagger('.list-item', {
|
|
78
|
+
* opacity: [0, 1],
|
|
79
|
+
* y: [20, 0],
|
|
80
|
+
* }, { stagger: 50, duration: 300 });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare function animateStagger(selector: string | HTMLElement[], properties: Record<string, PropertyValue>, options?: StaggerOptions): AnimationControl[];
|
|
84
|
+
/**
|
|
85
|
+
* Run animations in sequence, one after another.
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* await animateSequence([
|
|
89
|
+
* [el1, { opacity: [0, 1] }, { duration: 200 }],
|
|
90
|
+
* [el2, { opacity: [0, 1] }, { duration: 200 }],
|
|
91
|
+
* ]);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare function animateSequence(steps: Array<[HTMLElement, Record<string, PropertyValue>, AnimationOptions?]>): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Run multiple animations in parallel, wait for all to complete.
|
|
97
|
+
*/
|
|
98
|
+
declare function animateGroup(steps: Array<[HTMLElement, Record<string, PropertyValue>, AnimationOptions?]>): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Animate with spring physics (no CSS easing — uses requestAnimationFrame).
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* animateSpring(el, { scale: 1.2, rotate: 10 }, {
|
|
104
|
+
* stiffness: 300,
|
|
105
|
+
* damping: 20,
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
declare function animateSpring(el: HTMLElement, target: Record<string, number>, options?: SpringOptions): AnimationControl;
|
|
110
|
+
/**
|
|
111
|
+
* Define keyframes for multi-step animations.
|
|
112
|
+
*
|
|
113
|
+
* ```ts
|
|
114
|
+
* const bounce = keyframes([
|
|
115
|
+
* { offset: 0, transform: 'translateY(0)' },
|
|
116
|
+
* { offset: 0.5, transform: 'translateY(-30px)' },
|
|
117
|
+
* { offset: 1, transform: 'translateY(0)' },
|
|
118
|
+
* ]);
|
|
119
|
+
*
|
|
120
|
+
* el.animate(bounce, { duration: 600 });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
declare function keyframes(frames: Keyframe[]): Keyframe[];
|
|
124
|
+
interface AnimationState {
|
|
125
|
+
[property: string]: string | number;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Define state-based animations.
|
|
129
|
+
*
|
|
130
|
+
* ```ts
|
|
131
|
+
* const toggle = defineStates({
|
|
132
|
+
* open: { height: 'auto', opacity: 1 },
|
|
133
|
+
* closed: { height: 0, opacity: 0 },
|
|
134
|
+
* }, { duration: 300 });
|
|
135
|
+
*
|
|
136
|
+
* toggle.transitionTo(el, 'open');
|
|
137
|
+
* toggle.transitionTo(el, 'closed');
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
declare function defineStates(states: Record<string, AnimationState>, defaultOptions?: AnimationOptions): {
|
|
141
|
+
states: Record<string, AnimationState>;
|
|
142
|
+
transitionTo(el: HTMLElement, stateName: string, options?: AnimationOptions): AnimationControl;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export { type AnimationControl, type AnimationOptions, type AnimationState, type SpringOptions, type StaggerOptions, animate, animateGroup, animateSequence, animateSpring, animateStagger, defineStates, keyframes };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animation module.
|
|
3
|
+
*
|
|
4
|
+
* State-based animations, stagger, group, sequence, keyframes,
|
|
5
|
+
* and spring physics. Goes far beyond CSS transitions.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const fadeIn = animate(el, { opacity: [0, 1] }, { duration: 300 });
|
|
9
|
+
* const staggered = animateStagger('.item', { opacity: [0, 1], y: [20, 0] }, { stagger: 50 });
|
|
10
|
+
* const spring = animateSpring(el, { scale: 1.2 }, { stiffness: 300, damping: 20 });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
interface AnimationOptions {
|
|
14
|
+
/** Duration in ms (default: 300) */
|
|
15
|
+
duration?: number;
|
|
16
|
+
/** Easing function or CSS easing string (default: 'ease') */
|
|
17
|
+
easing?: string;
|
|
18
|
+
/** Delay before animation starts in ms */
|
|
19
|
+
delay?: number;
|
|
20
|
+
/** Number of iterations (Infinity for loop) */
|
|
21
|
+
iterations?: number;
|
|
22
|
+
/** Direction: normal, reverse, alternate */
|
|
23
|
+
direction?: PlaybackDirection;
|
|
24
|
+
/** Fill mode */
|
|
25
|
+
fill?: FillMode;
|
|
26
|
+
/** Callback when animation completes */
|
|
27
|
+
onComplete?: () => void;
|
|
28
|
+
}
|
|
29
|
+
interface StaggerOptions extends AnimationOptions {
|
|
30
|
+
/** Delay between each element in ms */
|
|
31
|
+
stagger?: number;
|
|
32
|
+
/** Stagger from: 'start', 'center', 'end' */
|
|
33
|
+
from?: 'start' | 'center' | 'end';
|
|
34
|
+
}
|
|
35
|
+
interface SpringOptions {
|
|
36
|
+
/** Spring stiffness (default: 100) */
|
|
37
|
+
stiffness?: number;
|
|
38
|
+
/** Damping ratio (default: 10) */
|
|
39
|
+
damping?: number;
|
|
40
|
+
/** Mass (default: 1) */
|
|
41
|
+
mass?: number;
|
|
42
|
+
/** Velocity threshold to stop (default: 0.01) */
|
|
43
|
+
threshold?: number;
|
|
44
|
+
/** Callback when animation completes */
|
|
45
|
+
onComplete?: () => void;
|
|
46
|
+
}
|
|
47
|
+
interface AnimationControl {
|
|
48
|
+
/** Play the animation */
|
|
49
|
+
play(): void;
|
|
50
|
+
/** Pause the animation */
|
|
51
|
+
pause(): void;
|
|
52
|
+
/** Cancel the animation */
|
|
53
|
+
cancel(): void;
|
|
54
|
+
/** Reverse the animation */
|
|
55
|
+
reverse(): void;
|
|
56
|
+
/** Promise that resolves when animation completes */
|
|
57
|
+
finished: Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
type PropertyValue = number | string | [number | string, number | string];
|
|
60
|
+
/**
|
|
61
|
+
* Animate an element using the Web Animations API.
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const ctrl = animate(el, {
|
|
65
|
+
* opacity: [0, 1],
|
|
66
|
+
* transform: ['translateY(20px)', 'translateY(0)'],
|
|
67
|
+
* }, { duration: 300, easing: 'ease-out' });
|
|
68
|
+
*
|
|
69
|
+
* await ctrl.finished;
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function animate(el: HTMLElement, properties: Record<string, PropertyValue>, options?: AnimationOptions): AnimationControl;
|
|
73
|
+
/**
|
|
74
|
+
* Animate multiple elements with staggered timing.
|
|
75
|
+
*
|
|
76
|
+
* ```ts
|
|
77
|
+
* animateStagger('.list-item', {
|
|
78
|
+
* opacity: [0, 1],
|
|
79
|
+
* y: [20, 0],
|
|
80
|
+
* }, { stagger: 50, duration: 300 });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare function animateStagger(selector: string | HTMLElement[], properties: Record<string, PropertyValue>, options?: StaggerOptions): AnimationControl[];
|
|
84
|
+
/**
|
|
85
|
+
* Run animations in sequence, one after another.
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* await animateSequence([
|
|
89
|
+
* [el1, { opacity: [0, 1] }, { duration: 200 }],
|
|
90
|
+
* [el2, { opacity: [0, 1] }, { duration: 200 }],
|
|
91
|
+
* ]);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare function animateSequence(steps: Array<[HTMLElement, Record<string, PropertyValue>, AnimationOptions?]>): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Run multiple animations in parallel, wait for all to complete.
|
|
97
|
+
*/
|
|
98
|
+
declare function animateGroup(steps: Array<[HTMLElement, Record<string, PropertyValue>, AnimationOptions?]>): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Animate with spring physics (no CSS easing — uses requestAnimationFrame).
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* animateSpring(el, { scale: 1.2, rotate: 10 }, {
|
|
104
|
+
* stiffness: 300,
|
|
105
|
+
* damping: 20,
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
declare function animateSpring(el: HTMLElement, target: Record<string, number>, options?: SpringOptions): AnimationControl;
|
|
110
|
+
/**
|
|
111
|
+
* Define keyframes for multi-step animations.
|
|
112
|
+
*
|
|
113
|
+
* ```ts
|
|
114
|
+
* const bounce = keyframes([
|
|
115
|
+
* { offset: 0, transform: 'translateY(0)' },
|
|
116
|
+
* { offset: 0.5, transform: 'translateY(-30px)' },
|
|
117
|
+
* { offset: 1, transform: 'translateY(0)' },
|
|
118
|
+
* ]);
|
|
119
|
+
*
|
|
120
|
+
* el.animate(bounce, { duration: 600 });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
declare function keyframes(frames: Keyframe[]): Keyframe[];
|
|
124
|
+
interface AnimationState {
|
|
125
|
+
[property: string]: string | number;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Define state-based animations.
|
|
129
|
+
*
|
|
130
|
+
* ```ts
|
|
131
|
+
* const toggle = defineStates({
|
|
132
|
+
* open: { height: 'auto', opacity: 1 },
|
|
133
|
+
* closed: { height: 0, opacity: 0 },
|
|
134
|
+
* }, { duration: 300 });
|
|
135
|
+
*
|
|
136
|
+
* toggle.transitionTo(el, 'open');
|
|
137
|
+
* toggle.transitionTo(el, 'closed');
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
declare function defineStates(states: Record<string, AnimationState>, defaultOptions?: AnimationOptions): {
|
|
141
|
+
states: Record<string, AnimationState>;
|
|
142
|
+
transitionTo(el: HTMLElement, stateName: string, options?: AnimationOptions): AnimationControl;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export { type AnimationControl, type AnimationOptions, type AnimationState, type SpringOptions, type StaggerOptions, animate, animateGroup, animateSequence, animateSpring, animateStagger, defineStates, keyframes };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';var f=new Set,l=new Set,b=false,d=0,g=false,x=3,P=100;function v(){if(b)return;b=true;let e=new Map,n=false,t=0;for(;(f.size>0||l.size>0)&&t<P;){if(t++,f.size>0){let s=[...f].sort(C);f.clear();for(let r of s){let o=(e.get(r)??0)+1;if(e.set(r,o),o>x){n=true;continue}r.run();}}if(l.size>0){let s=[...l].sort(C);l.clear();for(let r of s){let o=(e.get(r)??0)+1;if(e.set(r,o),o>x){n=true;continue}r.run();}}if(n&&f.size===0&&l.size===0)break}(n||t>=P)&&(f.clear(),l.clear(),console.error("[AkashJS] Circular dependency detected between effects. Two or more effects are writing to each other's dependencies. The cycle has been broken after "+t+" iterations.")),b=false,g&&(g=false,(f.size>0||l.size>0)&&v());}function N(e){e.isRender?f.add(e):l.add(e),d===0&&!b?v():b&&(g=true);}function _(e){d++;try{e();}finally{d--,d===0&&v();}}function R(){d++;}function k(){d--,d===0&&v();}function C(e,n){return (e.depth??0)-(n.depth??0)}function M(){v();}var y=false,h=[],S=0;function B(){y=true,h=[],S=performance.now();}function K(){y=false;let e=performance.now();return {entries:[...h],totalDuration:e-S,startTime:S,endTime:e}}function T(){return y}function p(e,n,t){y&&h.push({type:e,name:n,duration:t,timestamp:performance.now()});}function z(e){let n=e.entries.filter(i=>i.type==="render"),t=e.entries.filter(i=>i.type==="effect"),s=e.entries.filter(i=>i.type==="signal-update"),r=e.entries.filter(i=>i.type==="computed"),o=i=>i.length>0?i.reduce((u,m)=>u+m.duration,0)/i.length:0,c=i=>i.length>0?i.reduce((u,m)=>m.duration>u.duration?m:u):null;return {totalRenders:n.length,totalEffects:t.length,totalSignalUpdates:s.length,totalComputedEvals:r.length,avgRenderTime:o(n),avgEffectTime:o(t),slowestRender:c(n),slowestEffect:c(t)}}function O(e,n){let t=performance.now(),s=n(),r=performance.now()-t;return p("render",e,r),{result:s,duration:r}}async function j(e,n){let t=performance.now(),s=await n(),r=performance.now()-t;return p("render",e,r),{result:s,duration:r}}function I(e){let n=0,t=0;return {start(){n=performance.now();},stop(){t=performance.now()-n,p("render",e,t);},get duration(){return t}}}function X(e){let n=z(e),t=`
|
|
2
|
+
Performance Profile
|
|
3
|
+
`;return t+=" "+"\u2500".repeat(50)+`
|
|
4
|
+
`,t+=` Duration: ${e.totalDuration.toFixed(1)} ms
|
|
5
|
+
`,t+=` Renders: ${n.totalRenders} (avg ${n.avgRenderTime.toFixed(2)} ms)
|
|
6
|
+
`,t+=` Effects: ${n.totalEffects} (avg ${n.avgEffectTime.toFixed(2)} ms)
|
|
7
|
+
`,t+=` Signal updates: ${n.totalSignalUpdates}
|
|
8
|
+
`,t+=` Computed evals: ${n.totalComputedEvals}
|
|
9
|
+
`,n.slowestRender&&(t+=` Slowest render: ${n.slowestRender.name} (${n.slowestRender.duration.toFixed(2)} ms)
|
|
10
|
+
`),n.slowestEffect&&(t+=` Slowest effect: ${n.slowestEffect.name} (${n.slowestEffect.duration.toFixed(2)} ms)
|
|
11
|
+
`),t+=" "+"\u2500".repeat(50)+`
|
|
12
|
+
`,t}var F=typeof process>"u"||process.env?.NODE_ENV!=="production";var a=null;function G(e,n){let t={value:e,subscribers:new Set,equals:n?.equals??Object.is},s=()=>(J(t),t.value);return s.set=r=>{F&&a&&a._tag==="computed"&&console.warn("[AkashJS] Writing to a signal inside computed() is not allowed. The write will be lost on the next evaluation."),!t.equals(t.value,r)&&(t.value=r,T()&&p("signal-update","signal.set",0),_(()=>{E(t);}));},s.update=r=>{s.set(r(t.value));},s.peek=()=>t.value,s}function Q(e,n){let t={_tag:"computed",fn:e,value:void 0,state:1,subscribers:new Set,sources:new Set,equals:n?.equals??Object.is};return ()=>(a&&(t.subscribers.add(a),"sources"in a&&a.sources.add(t)),t.state!==0&&q(t),t.value)}var w=new Set;function q(e,n=false){if(w.has(e))throw new Error("[AkashJS] Circular dependency detected between computed values.");w.add(e),R();for(let r of e.sources)r.subscribers.delete(e);e.sources.clear();let t=a;a=e;let s=T()?performance.now():0;try{let r=e.fn(),o=e.value===void 0,c=o||!e.equals(e.value,r);if(e.value=r,e.state=0,c&&!o)if(n){for(let i of [...e.subscribers])if(i._tag==="computed"){i.state=1;for(let u of [...i.subscribers])u._tag==="computed"&&(u.state=1);}}else E(e);}finally{s&&p("computed","computed",performance.now()-s),w.delete(e),a=t,k();}}function Y(e,n){let t={_tag:"effect",fn:e,cleanup:null,sources:new Set,disposed:false,isRender:n?.render??false,run(){D(t);}};return D(t),()=>{t.disposed=true,A(t);for(let s of t.sources)s.subscribers.delete(t);t.sources.clear();}}function D(e){if(e.disposed)return;if(e.sources.size>0){let r=false;for(let o of e.sources)if("_tag"in o&&o._tag==="computed"){o.state===1&&q(o,true);let c=e._lastSeen;if(c?.has(o)){let i=c.get(o);o.equals(i,o.value)||(r=true);}else r=true;}else r=true;if(!r)return}A(e);let n=new Set(e.sources);for(let r of e.sources)r.subscribers.delete(e);e.sources.clear();let t=a;a=e;let s=T()?performance.now():0;try{let r=e.fn();typeof r=="function"&&(e.cleanup=r);}catch(r){for(let o of n)o.subscribers.add(e),e.sources.add(o);console.error("[AkashJS] Error in effect (will retry on next signal change):",r);}finally{s&&p("effect","effect",performance.now()-s),a=t;let r=new Map;for(let o of e.sources)"_tag"in o&&o._tag==="computed"&&r.set(o,o.value);r.size>0&&(e._lastSeen=r);}}function A(e){if(e.cleanup){try{e.cleanup();}catch(n){console.error("[AkashJS] Error in effect cleanup (ignored):",n);}e.cleanup=null;}}function U(e){let n=a;a=null;try{return e()}finally{a=n;}}function Z(e,n,t){let s=Array.isArray(e),r=s?e:[e],o,c=true;return ()=>{let i=r.map(m=>m());if(c&&(c=false,o=i.slice(),t?.defer!==false))return;let u=o;return o=i.slice(),U(()=>n(s?i:i[0],u?s?u:u[0]:void 0))}}function J(e){a&&(e.subscribers.add(a),"sources"in a&&a.sources.add(e));}function E(e){let n=[...e.subscribers];for(let t of n)t._tag==="computed"?(t.state=1,E(t)):t._tag==="effect"&&N(t);}exports.a=_;exports.b=M;exports.c=B;exports.d=K;exports.e=T;exports.f=p;exports.g=z;exports.h=O;exports.i=j;exports.j=I;exports.k=X;exports.l=G;exports.m=Q;exports.n=Y;exports.o=U;exports.p=Z;//# sourceMappingURL=chunk-3AL2DVPZ.cjs.map
|
|
13
|
+
//# sourceMappingURL=chunk-3AL2DVPZ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/scheduler.ts","../src/perf.ts","../src/signals.ts"],"names":["pendingRender","pendingUser","flushing","batchDepth","reflushNeeded","MAX_EFFECT_RUNS","MAX_FLUSH_ITERATIONS","flush","runCounts","circularDetected","iterations","queue","byDepth","fx","count","scheduleEffect","batch","fn","enterBatch","exitBatch","a","b","flushSync","profiling","entries","profileStart","startProfiling","stopProfiling","endTime","isProfiling","recordPerfEntry","type","name","duration","getProfileSummary","profile","renders","e","effects","signalUpdates","computeds","avg","arr","s","slowest","measureSync","start","result","measureAsync","createTimer","startTime","dur","formatProfile","summary","out","__DEV__","currentSubscriber","signal","initialValue","options","node","read","trackSubscriber","value","notifySubscribers","computed","recompute","computingSet","skipEffectNotify","source","prevSubscriber","_t0","newValue","isFirst","changed","sub","sub2","effect","runEffect","cleanupEffect","anyChanged","cachedValues","lastSeen","prevSources","err","untrack","prev","on","deps","isArray","depArray","prevValues","values","d","subs"],"mappings":"aAcA,IAAMA,CAAAA,CAAgB,IAAI,GAAA,CACpBC,CAAAA,CAAc,IAAI,GAAA,CACpBC,CAAAA,CAAW,KAAA,CACXC,CAAAA,CAAa,CAAA,CAEbC,EAAgB,KAAA,CAEdC,CAAAA,CAAkB,CAAA,CAClBC,CAAAA,CAAuB,IAE7B,SAASC,CAAAA,EAAc,CACrB,GAAIL,CAAAA,CAAU,OACdA,CAAAA,CAAW,IACM,CAGjB,IAAMM,EAAY,IAAI,GAAA,CAClBC,CAAAA,CAAmB,KAAA,CAInBC,CAAAA,CAAa,CAAA,CACjB,KAAA,CAAQV,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.\n *\n * Render effects (DOM bindings) run before user effects to ensure\n * DOM is consistent before user-side effects execute.\n */\n\nexport interface ScheduledEffect {\n run(): void;\n isRender: boolean;\n /** Depth in the dependency graph (0 = root). Lower depth runs first. */\n depth?: number;\n}\n\nconst pendingRender = new Set<ScheduledEffect>();\nconst pendingUser = new Set<ScheduledEffect>();\nlet flushing = false;\nlet batchDepth = 0;\nlet flushScheduled = false;\nlet reflushNeeded = false;\n\nconst MAX_EFFECT_RUNS = 3;\nconst MAX_FLUSH_ITERATIONS = 100;\n\nfunction flush(): void {\n if (flushing) return;\n flushing = true;\n flushScheduled = false;\n\n // Fresh per-effect run counter for THIS flush — reset every time\n const runCounts = new Map<ScheduledEffect, number>();\n let circularDetected = false;\n\n // Process render effects first, then user effects.\n // Effects may enqueue more effects during flush, so loop until empty.\n let iterations = 0;\n while ((pendingRender.size > 0 || pendingUser.size > 0) && iterations < MAX_FLUSH_ITERATIONS) {\n iterations++;\n\n // Drain render effects (sorted by depth — parents before children)\n if (pendingRender.size > 0) {\n const queue = [...pendingRender].sort(byDepth);\n pendingRender.clear();\n for (const fx of queue) {\n const count = (runCounts.get(fx) ?? 0) + 1;\n runCounts.set(fx, count);\n if (count > MAX_EFFECT_RUNS) {\n circularDetected = true;\n continue; // skip this effect — it's in a cycle\n }\n fx.run();\n }\n }\n\n // Drain user effects (sorted by depth)\n if (pendingUser.size > 0) {\n const queue = [...pendingUser].sort(byDepth);\n pendingUser.clear();\n for (const fx of queue) {\n const count = (runCounts.get(fx) ?? 0) + 1;\n runCounts.set(fx, count);\n if (count > MAX_EFFECT_RUNS) {\n circularDetected = true;\n continue; // skip this effect — it's in a cycle\n }\n fx.run();\n }\n }\n\n // If all remaining effects were skipped due to cycle detection, break\n if (circularDetected && pendingRender.size === 0 && pendingUser.size === 0) {\n break;\n }\n }\n\n if (circularDetected || iterations >= MAX_FLUSH_ITERATIONS) {\n pendingRender.clear();\n pendingUser.clear();\n console.error(\n '[AkashJS] Circular dependency detected between effects. ' +\n 'Two or more effects are writing to each other\\'s dependencies. ' +\n 'The cycle has been broken after ' + iterations + ' iterations.'\n );\n }\n\n flushing = false;\n\n // If effects were scheduled during the tail end of this flush (after the\n // while loop's condition was last checked), re-flush them now.\n if (reflushNeeded) {\n reflushNeeded = false;\n if (pendingRender.size > 0 || pendingUser.size > 0) {\n flush();\n }\n }\n}\n\nexport function scheduleEffect(fx: ScheduledEffect): void {\n if (fx.isRender) {\n pendingRender.add(fx);\n } else {\n pendingUser.add(fx);\n }\n\n if (batchDepth === 0 && !flushing) {\n flush();\n } else if (flushing) {\n // Effects were added during a flush. The while loop may still pick them\n // up, but if it has already checked the queues and found them empty,\n // we need a re-flush after the current one completes.\n reflushNeeded = true;\n }\n}\n\n/**\n * Batch multiple signal writes — subscribers are notified only once\n * at the end of the batch.\n */\nexport function batch(fn: () => void): void {\n batchDepth++;\n try {\n fn();\n } finally {\n batchDepth--;\n if (batchDepth === 0) {\n flush();\n }\n }\n}\n\n/** Enter/exit batch depth — used by computed recompute to prevent mid-evaluation flush */\nexport function enterBatch(): void { batchDepth++; }\nexport function exitBatch(): void {\n batchDepth--;\n if (batchDepth === 0) flush();\n}\n\n/** Sort effects by depth (lower depth first = parents before children) */\nfunction byDepth(a: ScheduledEffect, b: ScheduledEffect): number {\n return (a.depth ?? 0) - (b.depth ?? 0);\n}\n\n/** Synchronously flush all pending effects. Useful for testing. */\nexport function flushSync(): void {\n flush();\n}\n","/**\n * Performance profiling utilities.\n *\n * Measure component render times, signal propagation, and\n * effect execution for performance debugging.\n *\n * ```ts\n * import { startProfiling, stopProfiling, getProfile } from '@akashjs/runtime';\n *\n * startProfiling();\n * // ... do stuff ...\n * stopProfiling();\n * console.table(getProfile().entries);\n * ```\n */\n\n// --- Types ---\n\nexport interface PerfEntry {\n type: 'render' | 'effect' | 'signal-update' | 'computed';\n name: string;\n duration: number;\n timestamp: number;\n}\n\nexport interface PerfProfile {\n entries: PerfEntry[];\n totalDuration: number;\n startTime: number;\n endTime: number;\n}\n\nexport interface PerfSummary {\n totalRenders: number;\n totalEffects: number;\n totalSignalUpdates: number;\n totalComputedEvals: number;\n avgRenderTime: number;\n avgEffectTime: number;\n slowestRender: PerfEntry | null;\n slowestEffect: PerfEntry | null;\n}\n\n// --- Profiling state ---\n\nlet profiling = false;\nlet entries: PerfEntry[] = [];\nlet profileStart = 0;\n\n// --- Public API ---\n\n/**\n * Start profiling. Clears previous data.\n */\nexport function startProfiling(): void {\n profiling = true;\n entries = [];\n profileStart = performance.now();\n}\n\n/**\n * Stop profiling.\n */\nexport function stopProfiling(): PerfProfile {\n profiling = false;\n const endTime = performance.now();\n\n return {\n entries: [...entries],\n totalDuration: endTime - profileStart,\n startTime: profileStart,\n endTime,\n };\n}\n\n/**\n * Check if profiling is active.\n */\nexport function isProfiling(): boolean {\n return profiling;\n}\n\n/**\n * Record a performance entry (called internally by the framework).\n */\nexport function recordPerfEntry(\n type: PerfEntry['type'],\n name: string,\n duration: number,\n): void {\n if (!profiling) return;\n entries.push({\n type,\n name,\n duration,\n timestamp: performance.now(),\n });\n}\n\n/**\n * Get a summary of the profiling data.\n */\nexport function getProfileSummary(profile: PerfProfile): PerfSummary {\n const renders = profile.entries.filter((e) => e.type === 'render');\n const effects = profile.entries.filter((e) => e.type === 'effect');\n const signalUpdates = profile.entries.filter((e) => e.type === 'signal-update');\n const computeds = profile.entries.filter((e) => e.type === 'computed');\n\n const avg = (arr: PerfEntry[]) =>\n arr.length > 0 ? arr.reduce((s, e) => s + e.duration, 0) / arr.length : 0;\n\n const slowest = (arr: PerfEntry[]) =>\n arr.length > 0 ? arr.reduce((s, e) => (e.duration > s.duration ? e : s)) : null;\n\n return {\n totalRenders: renders.length,\n totalEffects: effects.length,\n totalSignalUpdates: signalUpdates.length,\n totalComputedEvals: computeds.length,\n avgRenderTime: avg(renders),\n avgEffectTime: avg(effects),\n slowestRender: slowest(renders),\n slowestEffect: slowest(effects),\n };\n}\n\n// --- Measurement helpers ---\n\n/**\n * Measure the time to execute a function.\n *\n * ```ts\n * const { result, duration } = measureSync('my-operation', () => expensiveWork());\n * ```\n */\nexport function measureSync<T>(name: string, fn: () => T): { result: T; duration: number } {\n const start = performance.now();\n const result = fn();\n const duration = performance.now() - start;\n recordPerfEntry('render', name, duration);\n return { result, duration };\n}\n\n/**\n * Measure the time to execute an async function.\n */\nexport async function measureAsync<T>(\n name: string,\n fn: () => Promise<T>,\n): Promise<{ result: T; duration: number }> {\n const start = performance.now();\n const result = await fn();\n const duration = performance.now() - start;\n recordPerfEntry('render', name, duration);\n return { result, duration };\n}\n\n/**\n * Create a named timer for manual start/stop measurement.\n *\n * ```ts\n * const timer = createTimer('data-fetch');\n * timer.start();\n * await fetch(...);\n * timer.stop(); // records the entry\n * timer.duration; // ms\n * ```\n */\nexport function createTimer(name: string) {\n let startTime = 0;\n let dur = 0;\n\n return {\n start() { startTime = performance.now(); },\n stop() {\n dur = performance.now() - startTime;\n recordPerfEntry('render', name, dur);\n },\n get duration() { return dur; },\n };\n}\n\n/**\n * Format a profile for console output.\n */\nexport function formatProfile(profile: PerfProfile): string {\n const summary = getProfileSummary(profile);\n let out = '\\n Performance Profile\\n';\n out += ' ' + '─'.repeat(50) + '\\n';\n out += ` Duration: ${profile.totalDuration.toFixed(1)} ms\\n`;\n out += ` Renders: ${summary.totalRenders} (avg ${summary.avgRenderTime.toFixed(2)} ms)\\n`;\n out += ` Effects: ${summary.totalEffects} (avg ${summary.avgEffectTime.toFixed(2)} ms)\\n`;\n out += ` Signal updates: ${summary.totalSignalUpdates}\\n`;\n out += ` Computed evals: ${summary.totalComputedEvals}\\n`;\n\n if (summary.slowestRender) {\n out += ` Slowest render: ${summary.slowestRender.name} (${summary.slowestRender.duration.toFixed(2)} ms)\\n`;\n }\n if (summary.slowestEffect) {\n out += ` Slowest effect: ${summary.slowestEffect.name} (${summary.slowestEffect.duration.toFixed(2)} ms)\\n`;\n }\n\n out += ' ' + '─'.repeat(50) + '\\n';\n return out;\n}\n","/**\n * Fine-grained reactivity system.\n *\n * Inspired by SolidJS/Preact Signals. Provides signal(), computed(),\n * effect(), and untrack() primitives with automatic dependency tracking\n * and glitch-free diamond dependency resolution.\n */\n\nimport { scheduleEffect, batch, enterBatch, exitBatch, type ScheduledEffect } from './scheduler.js';\nimport { recordPerfEntry, isProfiling } from './perf.js';\n\nconst __DEV__ = typeof process === 'undefined' || process.env?.NODE_ENV !== 'production';\n\n/** Depth counter to defer effect scheduling until all notifications complete (glitch-free) */\nlet notifyDepth = 0;\n\n// --- Tracking scope ---\n\ntype Subscriber = EffectNode | ComputedNode<any>;\n\nlet currentSubscriber: Subscriber | null = null;\n\n// --- Signal ---\n\nexport interface Signal<T> {\n /** Read the current value (tracks dependency if inside a reactive scope) */\n (): T;\n /** Set a new value */\n set(value: T): void;\n /** Update the value using the previous value */\n update(fn: (prev: T) => T): void;\n /** Read without tracking (no dependency registered) */\n peek(): T;\n}\n\nexport type ReadonlySignal<T> = () => T;\n\ninterface SignalNode<T> {\n value: T;\n subscribers: Set<Subscriber>;\n equals: (a: T, b: T) => boolean;\n}\n\nexport function signal<T>(\n initialValue: T,\n options?: { equals?: (a: T, b: T) => boolean },\n): Signal<T> {\n const node: SignalNode<T> = {\n value: initialValue,\n subscribers: new Set(),\n equals: options?.equals ?? Object.is,\n };\n\n const read = (): T => {\n trackSubscriber(node);\n return node.value;\n };\n\n read.set = (value: T): void => {\n if (__DEV__ && currentSubscriber && currentSubscriber._tag === 'computed') {\n console.warn('[AkashJS] Writing to a signal inside computed() is not allowed. The write will be lost on the next evaluation.');\n }\n if (node.equals(node.value, value)) return;\n node.value = value;\n if (isProfiling()) recordPerfEntry('signal-update', 'signal.set', 0);\n batch(() => { notifySubscribers(node); });\n };\n\n read.update = (fn: (prev: T) => T): void => {\n read.set(fn(node.value));\n };\n\n read.peek = (): T => node.value;\n\n return read;\n}\n\n// --- Computed ---\n\nconst enum ComputedState {\n Clean = 0,\n Dirty = 1,\n}\n\ninterface ComputedNode<T> {\n _tag: 'computed';\n fn: () => T;\n value: T | undefined;\n state: ComputedState;\n subscribers: Set<Subscriber>;\n sources: Set<SignalNode<any> | ComputedNode<any>>;\n equals: (a: T, b: T) => boolean;\n}\n\nexport function computed<T>(\n fn: () => T,\n options?: { equals?: (a: T, b: T) => boolean },\n): ReadonlySignal<T> {\n const node: ComputedNode<T> = {\n _tag: 'computed',\n fn,\n value: undefined,\n state: ComputedState.Dirty,\n subscribers: new Set(),\n sources: new Set(),\n equals: options?.equals ?? Object.is,\n };\n\n const read = (): T => {\n // Track this computed as a dependency of the current subscriber\n if (currentSubscriber) {\n node.subscribers.add(currentSubscriber);\n if ('sources' in currentSubscriber) {\n currentSubscriber.sources.add(node);\n }\n }\n\n if (node.state !== ComputedState.Clean) {\n recompute(node);\n }\n\n return node.value as T;\n };\n\n return read;\n}\n\nconst computingSet = new Set<ComputedNode<unknown>>();\n\n/**\n * @param skipEffectNotify - When true, don't schedule effects in notifySubscribers.\n * Used when recompute is called from runEffect's dirty check — the effect is\n * already being processed, re-scheduling it would trigger the circular run limit.\n */\nfunction recompute<T>(node: ComputedNode<T>, skipEffectNotify = false): void {\n // Detect circular computed dependencies — only if THIS node is already being computed\n if (computingSet.has(node as ComputedNode<unknown>)) {\n throw new Error('[AkashJS] Circular dependency detected between computed values.');\n }\n computingSet.add(node as ComputedNode<unknown>);\n\n // Prevent effects from flushing while computed is evaluating.\n // Without this, a computed that reads other dirty computeds can trigger\n // notifySubscribers → scheduleEffect → flush → re-enter recompute on\n // a node still in computingSet (false circular detection).\n enterBatch();\n\n // Clean up old source subscriptions\n for (const source of node.sources) {\n source.subscribers.delete(node);\n }\n node.sources.clear();\n\n const prevSubscriber = currentSubscriber;\n currentSubscriber = node;\n\n const _t0 = isProfiling() ? performance.now() : 0;\n try {\n const newValue = node.fn();\n const isFirst = node.value === undefined;\n const changed = isFirst || !node.equals(node.value as T, newValue);\n node.value = newValue;\n node.state = ComputedState.Clean;\n\n // Only propagate if value actually changed (skip first computation —\n // the effect that triggered the read is already running).\n if (changed && !isFirst) {\n if (skipEffectNotify) {\n // Only mark downstream computeds as dirty — don't schedule effects.\n // Effects are already handled by the runEffect that triggered this recompute.\n for (const sub of [...node.subscribers]) {\n if (sub._tag === 'computed') {\n sub.state = ComputedState.Dirty;\n // Recursively propagate to further computeds\n for (const sub2 of [...sub.subscribers]) {\n if (sub2._tag === 'computed') sub2.state = ComputedState.Dirty;\n }\n }\n }\n } else {\n notifySubscribers(node);\n }\n }\n } finally {\n if (_t0) recordPerfEntry('computed', 'computed', performance.now() - _t0);\n computingSet.delete(node as ComputedNode<unknown>);\n currentSubscriber = prevSubscriber;\n exitBatch();\n }\n}\n\n// --- Effect ---\n\ninterface EffectNode extends ScheduledEffect {\n _tag: 'effect';\n fn: () => void | (() => void);\n cleanup: (() => void) | null;\n sources: Set<SignalNode<any> | ComputedNode<any>>;\n disposed: boolean;\n isRender: boolean;\n}\n\nexport function effect(\n fn: () => void | (() => void),\n options?: { render?: boolean },\n): () => void {\n const node: EffectNode = {\n _tag: 'effect',\n fn,\n cleanup: null,\n sources: new Set(),\n disposed: false,\n isRender: options?.render ?? false,\n run() {\n runEffect(node);\n },\n };\n\n // Run immediately to establish dependencies\n runEffect(node);\n\n // Return dispose function\n return () => {\n node.disposed = true;\n cleanupEffect(node);\n for (const source of node.sources) {\n source.subscribers.delete(node);\n }\n node.sources.clear();\n };\n}\n\nfunction runEffect(node: EffectNode): void {\n if (node.disposed) return;\n\n // Before re-running, check if any dirty computed source actually changed.\n // Compare against per-effect cached values (not the shared source.value which\n // may have been updated by another effect's recompute already).\n if (node.sources.size > 0) {\n let anyChanged = false;\n for (const source of node.sources) {\n if ('_tag' in source && source._tag === 'computed') {\n if (source.state === ComputedState.Dirty) {\n recompute(source, true);\n }\n // Compare against this effect's last-seen value (not the shared source.value\n // which another effect's recompute may have already updated)\n const cachedValues = (node as any)._lastSeen as Map<unknown, unknown> | undefined;\n if (cachedValues?.has(source)) {\n const lastSeen = cachedValues.get(source);\n if (!source.equals(lastSeen as never, source.value as never)) {\n anyChanged = true;\n }\n } else {\n // No cached value — first dirty check after creation. Always run.\n anyChanged = true;\n }\n } else {\n // Plain signal source — if we got scheduled, something changed\n anyChanged = true;\n }\n }\n if (!anyChanged) return;\n }\n\n // Clean up previous run\n cleanupEffect(node);\n\n // Save old sources in case the effect throws — we need to re-subscribe\n const prevSources = new Set(node.sources);\n\n // Clean up old source subscriptions\n for (const source of node.sources) {\n source.subscribers.delete(node);\n }\n node.sources.clear();\n\n const prevSubscriber = currentSubscriber;\n currentSubscriber = node;\n const _t0 = isProfiling() ? performance.now() : 0;\n\n try {\n const result = node.fn();\n if (typeof result === 'function') {\n node.cleanup = result;\n }\n } catch (err) {\n // Re-subscribe to previous sources so the effect can recover on next change\n for (const source of prevSources) {\n source.subscribers.add(node);\n node.sources.add(source);\n }\n console.error('[AkashJS] Error in effect (will retry on next signal change):', err);\n } finally {\n if (_t0) recordPerfEntry('effect', 'effect', performance.now() - _t0);\n currentSubscriber = prevSubscriber;\n\n // Cache computed values so the next dirty check compares against THIS effect's\n // last-seen values, not the shared source.value (which another effect may update)\n const lastSeen = new Map();\n for (const source of node.sources) {\n if ('_tag' in source && source._tag === 'computed') {\n lastSeen.set(source, source.value);\n }\n }\n if (lastSeen.size > 0) (node as any)._lastSeen = lastSeen;\n }\n}\n\nfunction cleanupEffect(node: EffectNode): void {\n if (node.cleanup) {\n try {\n node.cleanup();\n } catch (err) {\n console.error('[AkashJS] Error in effect cleanup (ignored):', err);\n }\n node.cleanup = null;\n }\n}\n\n// --- Untrack ---\n\n/** Execute a function without tracking any signal reads */\nexport function untrack<T>(fn: () => T): T {\n const prev = currentSubscriber;\n currentSubscriber = null;\n try {\n return fn();\n } finally {\n currentSubscriber = prev;\n }\n}\n\n// --- on() helper ---\n\n/**\n * Create an effect callback that only tracks specific signals.\n * All other signal reads inside the callback are untracked.\n *\n * ```ts\n * effect(on(url, (currentUrl, prevUrl) => {\n * fetch(currentUrl, options()); // options() not tracked\n * }));\n *\n * effect(on([url, page], ([u, p], prev) => {\n * fetch(`${u}?page=${p}`);\n * }));\n * ```\n */\nexport function on<T>(\n dep: () => T,\n fn: (value: T, prev: T | undefined) => void | (() => void),\n options?: { defer?: boolean },\n): () => void | (() => void);\nexport function on<T extends readonly (() => unknown)[]>(\n deps: [...T],\n fn: (values: { [K in keyof T]: ReturnType<T[K]> }, prev: { [K in keyof T]: ReturnType<T[K]> } | undefined) => void | (() => void),\n options?: { defer?: boolean },\n): () => void | (() => void);\nexport function on(\n deps: (() => any) | (() => any)[],\n fn: (values: any, prev: any) => void | (() => void),\n options?: { defer?: boolean },\n): () => void | (() => void) {\n const isArray = Array.isArray(deps);\n const depArray = isArray ? deps : [deps];\n let prevValues: unknown[] | undefined;\n let isFirst = true;\n\n return () => {\n // Track only the specified deps\n const values = depArray.map(d => d());\n\n // Skip the initial effect run — only fire on actual changes\n // (pass { defer: false } to opt out and run immediately)\n if (isFirst) {\n isFirst = false;\n prevValues = values.slice();\n if (options?.defer !== false) return;\n }\n\n const prev = prevValues;\n prevValues = values.slice();\n\n // Run fn without tracking so reads inside don't create subscriptions\n return untrack(() => fn(\n isArray ? values : values[0],\n prev ? (isArray ? prev : prev[0]) : undefined,\n ));\n };\n}\n\n// --- Internal helpers ---\n\nfunction trackSubscriber(\n node: SignalNode<any> | ComputedNode<any>,\n): void {\n if (currentSubscriber) {\n node.subscribers.add(currentSubscriber);\n\n if ('sources' in currentSubscriber) {\n currentSubscriber.sources.add(node);\n }\n }\n}\n\nfunction notifySubscribers(\n node: SignalNode<any> | ComputedNode<any>,\n): void {\n // Snapshot subscribers before iterating. Effects that run synchronously\n // during flush() will delete and re-add themselves to the Set, and JS\n // Set iterators visit newly added entries — causing an infinite loop\n // without the snapshot.\n const subs = [...node.subscribers];\n for (const sub of subs) {\n if (sub._tag === 'computed') {\n // Mark dirty. The computed will re-evaluate lazily when read.\n sub.state = ComputedState.Dirty;\n // Propagate through the computed chain to reach effects.\n // The effects will re-read the computed, triggering recompute,\n // and only update DOM if the value actually changed.\n notifySubscribers(sub);\n } else if (sub._tag === 'effect') {\n scheduleEffect(sub);\n }\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk3AL2DVPZ_cjs=require('./chunk-3AL2DVPZ.cjs');function f(r,e={}){let t=chunk3AL2DVPZ_cjs.l(false),a=chunk3AL2DVPZ_cjs.l(false),s=chunk3AL2DVPZ_cjs.l(!navigator.onLine),i=null;window.addEventListener("online",()=>s.set(false)),window.addEventListener("offline",()=>s.set(true));let u=new Promise((h,l)=>{if(!("serviceWorker"in navigator)){l(new Error("Service workers not supported"));return}navigator.serviceWorker.register(r,{scope:e.scope}).then(n=>{i=n,t.set(true),e.onReady?.(n),h(n),n.addEventListener("updatefound",()=>{let o=n.installing;o&&o.addEventListener("statechange",()=>{o.state==="installed"&&navigator.serviceWorker.controller&&(a.set(true),e.onUpdate?.(n),e.autoReload&&(o.postMessage({type:"SKIP_WAITING"}),window.location.reload()));});});}).catch(n=>{e.onError?.(n),l(n);});});return {registered:()=>t(),updateAvailable:()=>a(),offline:()=>s(),ready:u,async update(){i&&await i.update();},skipWaiting(){i?.waiting&&(i.waiting.postMessage({type:"SKIP_WAITING"}),window.location.reload());},async unregister(){return i?i.unregister():false}}}function v(r){let e=`// Auto-generated service worker by AkashJS
|
|
2
2
|
const CACHE_VERSION = 'v1';
|
|
3
3
|
|
|
4
4
|
self.addEventListener('install', (event) => {
|
|
@@ -28,5 +28,5 @@ self.addEventListener('fetch', (event) => {
|
|
|
28
28
|
fetch(event.request).catch(() => caches.match(event.request))
|
|
29
29
|
);
|
|
30
30
|
});
|
|
31
|
-
`,e}function p(r,e){switch(r){case "cache-first":return `caches.match(event.request).then(cached => cached || fetch(event.request).then(response => { const clone = response.clone(); caches.open('${e}').then(cache => cache.put(event.request, clone)); return response; }))`;case "network-first":return `fetch(event.request).then(response => { const clone = response.clone(); caches.open('${e}').then(cache => cache.put(event.request, clone)); return response; }).catch(() => caches.match(event.request))`;case "stale-while-revalidate":return `caches.match(event.request).then(cached => { const fetchPromise = fetch(event.request).then(response => { caches.open('${e}').then(cache => cache.put(event.request, response.clone())); return response; }); return cached || fetchPromise; })`;case "network-only":return "fetch(event.request)";case "cache-only":return "caches.match(event.request)"}}async function y(r,e){return await Notification.requestPermission()!=="granted"?null:await r.pushManager.subscribe({userVisibleOnly:true,applicationServerKey:d(e)})}function d(r){let e="=".repeat((4-r.length%4)%4),t=(r+e).replace(/-/g,"+").replace(/_/g,"/"),a=atob(t);return Uint8Array.from(a,s=>s.charCodeAt(0))}exports.a=f;exports.b=v;exports.c=y;//# sourceMappingURL=chunk-
|
|
32
|
-
//# sourceMappingURL=chunk-
|
|
31
|
+
`,e}function p(r,e){switch(r){case "cache-first":return `caches.match(event.request).then(cached => cached || fetch(event.request).then(response => { const clone = response.clone(); caches.open('${e}').then(cache => cache.put(event.request, clone)); return response; }))`;case "network-first":return `fetch(event.request).then(response => { const clone = response.clone(); caches.open('${e}').then(cache => cache.put(event.request, clone)); return response; }).catch(() => caches.match(event.request))`;case "stale-while-revalidate":return `caches.match(event.request).then(cached => { const fetchPromise = fetch(event.request).then(response => { caches.open('${e}').then(cache => cache.put(event.request, response.clone())); return response; }); return cached || fetchPromise; })`;case "network-only":return "fetch(event.request)";case "cache-only":return "caches.match(event.request)"}}async function y(r,e){return await Notification.requestPermission()!=="granted"?null:await r.pushManager.subscribe({userVisibleOnly:true,applicationServerKey:d(e)})}function d(r){let e="=".repeat((4-r.length%4)%4),t=(r+e).replace(/-/g,"+").replace(/_/g,"/"),a=atob(t);return Uint8Array.from(a,s=>s.charCodeAt(0))}exports.a=f;exports.b=v;exports.c=y;//# sourceMappingURL=chunk-6NX6JRSV.cjs.map
|
|
32
|
+
//# sourceMappingURL=chunk-6NX6JRSV.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pwa.ts"],"names":["registerServiceWorker","swUrl","options","registered","signal","updateAvailable","offline","registration","ready","resolve","reject","reg","newWorker","err","generateSWScript","routes","script","route","pattern","cacheName","generateStrategyCode","strategy","subscribePush","vapidPublicKey","urlBase64ToUint8Array","base64String","padding","base64","rawData","char"],"mappings":"mEA2DO,SAASA,CAAAA,CACdC,EACAC,CAAAA,CAAqB,GACL,CAChB,IAAMC,CAAAA,CAAaC,mBAAAA,CAAO,KAAK,CAAA,CACzBC,EAAkBD,mBAAAA,CAAO,KAAK,EAC9BE,CAAAA,CAAUF,mBAAAA,CAAO,CAAC,SAAA,CAAU,MAAM,CAAA,CAEpCG,CAAAA,CAAiD,IAAA,CAGrD,MAAA,CAAO,iBAAiB,QAAA,CAAU,IAAMD,EAAQ,GAAA,CAAI,KAAK,CAAC,CAAA,CAC1D,MAAA,CAAO,gBAAA,CAAiB,SAAA,CAAW,IAAMA,CAAAA,CAAQ,IAAI,IAAI,CAAC,CAAA,CAE1D,IAAME,CAAAA,CAAQ,IAAI,QAAmC,CAACC,CAAAA,CAASC,CAAAA,GAAW,CACxE,GAAI,EAAE,kBAAmB,SAAA,CAAA,CAAY,CACnCA,EAAO,IAAI,KAAA,CAAM,+BAA+B,CAAC,CAAA,CACjD,MACF,CAEA,SAAA,CAAU,aAAA,CACP,SAAST,CAAAA,CAAO,CAAE,MAAOC,CAAAA,CAAQ,KAAM,CAAC,CAAA,CACxC,IAAA,CAAMS,CAAAA,EAAQ,CACbJ,CAAAA,CAAeI,CAAAA,CACfR,EAAW,GAAA,CAAI,IAAI,EACnBD,CAAAA,CAAQ,OAAA,GAAUS,CAAG,CAAA,CACrBF,CAAAA,CAAQE,CAAG,CAAA,CAGXA,CAAAA,CAAI,gBAAA,CAAiB,cAAe,IAAM,CACxC,IAAMC,CAAAA,CAAYD,CAAAA,CAAI,UAAA,CACjBC,GAELA,CAAAA,CAAU,gBAAA,CAAiB,aAAA,CAAe,IAAM,CAC1CA,CAAAA,CAAU,QAAU,WAAA,EAAe,SAAA,CAAU,cAAc,UAAA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A,CAAQ,IAAA,CAAM,GAAG,CAAA,CACtEE,CAAAA,CAAU,KAAKD,CAAM,CAAA,CAC3B,OAAO,UAAA,CAAW,IAAA,CAAKC,CAAAA,CAAUC,GAASA,CAAAA,CAAK,UAAA,CAAW,CAAC,CAAC,CAC9D","file":"chunk-TBCX5WQQ.cjs","sourcesContent":["/**\n * PWA / Service Worker support.\n *\n * Register service workers, configure caching strategies,\n * handle updates, and manage push notifications.\n *\n * ```ts\n * const sw = registerServiceWorker('/sw.js', {\n * onUpdate: () => toast.info('New version available!'),\n * });\n * sw.ready; // Promise<ServiceWorkerRegistration>\n * sw.update(); // check for updates\n * ```\n */\n\nimport { signal } from './signals.js';\nimport type { ReadonlySignal } from './signals.js';\n\n// =========================================================================\n// Types\n// =========================================================================\n\nexport interface SWOptions {\n /** Callback when a new version is available */\n onUpdate?: (registration: ServiceWorkerRegistration) => void;\n /** Callback when the SW is ready */\n onReady?: (registration: ServiceWorkerRegistration) => void;\n /** Callback on registration error */\n onError?: (error: Error) => void;\n /** Auto-reload on update (default: false) */\n autoReload?: boolean;\n /** Scope of the service worker */\n scope?: string;\n}\n\nexport interface SWRegistration {\n /** Whether the SW is registered */\n registered: ReadonlySignal<boolean>;\n /** Whether an update is available */\n updateAvailable: ReadonlySignal<boolean>;\n /** Whether the app is running offline */\n offline: ReadonlySignal<boolean>;\n /** The raw SW registration (available after ready) */\n ready: Promise<ServiceWorkerRegistration>;\n /** Check for updates */\n update(): Promise<void>;\n /** Skip waiting and activate new SW */\n skipWaiting(): void;\n /** Unregister the service worker */\n unregister(): Promise<boolean>;\n}\n\n// =========================================================================\n// Service Worker registration\n// =========================================================================\n\n/**\n * Register a service worker with update detection.\n */\nexport function registerServiceWorker(\n swUrl: string,\n options: SWOptions = {},\n): SWRegistration {\n const registered = signal(false);\n const updateAvailable = signal(false);\n const offline = signal(!navigator.onLine);\n\n let registration: ServiceWorkerRegistration | null = null;\n\n // Track online/offline\n window.addEventListener('online', () => offline.set(false));\n window.addEventListener('offline', () => offline.set(true));\n\n const ready = new Promise<ServiceWorkerRegistration>((resolve, reject) => {\n if (!('serviceWorker' in navigator)) {\n reject(new Error('Service workers not supported'));\n return;\n }\n\n navigator.serviceWorker\n .register(swUrl, { scope: options.scope })\n .then((reg) => {\n registration = reg;\n registered.set(true);\n options.onReady?.(reg);\n resolve(reg);\n\n // Listen for updates\n reg.addEventListener('updatefound', () => {\n const newWorker = reg.installing;\n if (!newWorker) return;\n\n newWorker.addEventListener('statechange', () => {\n if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {\n updateAvailable.set(true);\n options.onUpdate?.(reg);\n\n if (options.autoReload) {\n newWorker.postMessage({ type: 'SKIP_WAITING' });\n window.location.reload();\n }\n }\n });\n });\n })\n .catch((err) => {\n options.onError?.(err);\n reject(err);\n });\n });\n\n return {\n registered: () => registered(),\n updateAvailable: () => updateAvailable(),\n offline: () => offline(),\n ready,\n async update() {\n if (registration) {\n await registration.update();\n }\n },\n skipWaiting() {\n if (registration?.waiting) {\n registration.waiting.postMessage({ type: 'SKIP_WAITING' });\n window.location.reload();\n }\n },\n async unregister() {\n if (registration) {\n return registration.unregister();\n }\n return false;\n },\n };\n}\n\n// =========================================================================\n// Caching strategies (for SW scripts)\n// =========================================================================\n\nexport type CacheStrategy = 'cache-first' | 'network-first' | 'stale-while-revalidate' | 'network-only' | 'cache-only';\n\nexport interface CacheRoute {\n /** URL pattern to match (string or regex) */\n match: string | RegExp;\n /** Caching strategy */\n strategy: CacheStrategy;\n /** Cache name */\n cacheName?: string;\n /** Max entries in cache */\n maxEntries?: number;\n /** Max age in seconds */\n maxAgeSeconds?: number;\n}\n\n/**\n * Generate a service worker script from cache route configs.\n *\n * ```ts\n * const swScript = generateSWScript([\n * { match: /\\.(?:js|css)$/, strategy: 'cache-first', cacheName: 'assets' },\n * { match: '/api/', strategy: 'network-first', maxAgeSeconds: 300 },\n * { match: /\\.(?:png|jpg|svg)$/, strategy: 'cache-first', cacheName: 'images' },\n * ]);\n * ```\n */\nexport function generateSWScript(routes: CacheRoute[]): string {\n let script = `// Auto-generated service worker by AkashJS\nconst CACHE_VERSION = 'v1';\n\nself.addEventListener('install', (event) => {\n self.skipWaiting();\n});\n\nself.addEventListener('activate', (event) => {\n event.waitUntil(clients.claim());\n});\n\nself.addEventListener('message', (event) => {\n if (event.data?.type === 'SKIP_WAITING') {\n self.skipWaiting();\n }\n});\n\nself.addEventListener('fetch', (event) => {\n const url = new URL(event.request.url);\n`;\n\n for (const route of routes) {\n const pattern = route.match instanceof RegExp\n ? route.match.toString()\n : `new RegExp(${JSON.stringify(route.match.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'))})`;\n\n const cacheName = route.cacheName ?? 'akash-cache';\n\n script += `\n if (${pattern}.test(url.pathname)) {\n event.respondWith(${generateStrategyCode(route.strategy, cacheName)});\n return;\n }\n`;\n }\n\n script += `\n // Default: network-first\n event.respondWith(\n fetch(event.request).catch(() => caches.match(event.request))\n );\n});\n`;\n\n return script;\n}\n\nfunction generateStrategyCode(strategy: CacheStrategy, cacheName: string): string {\n switch (strategy) {\n case 'cache-first':\n return `caches.match(event.request).then(cached => cached || fetch(event.request).then(response => { const clone = response.clone(); caches.open('${cacheName}').then(cache => cache.put(event.request, clone)); return response; }))`;\n case 'network-first':\n return `fetch(event.request).then(response => { const clone = response.clone(); caches.open('${cacheName}').then(cache => cache.put(event.request, clone)); return response; }).catch(() => caches.match(event.request))`;\n case 'stale-while-revalidate':\n return `caches.match(event.request).then(cached => { const fetchPromise = fetch(event.request).then(response => { caches.open('${cacheName}').then(cache => cache.put(event.request, response.clone())); return response; }); return cached || fetchPromise; })`;\n case 'network-only':\n return `fetch(event.request)`;\n case 'cache-only':\n return `caches.match(event.request)`;\n }\n}\n\n// =========================================================================\n// Push notifications\n// =========================================================================\n\n/**\n * Request push notification permission and subscribe.\n */\nexport async function subscribePush(\n registration: ServiceWorkerRegistration,\n vapidPublicKey: string,\n): Promise<PushSubscription | null> {\n const permission = await Notification.requestPermission();\n if (permission !== 'granted') return null;\n\n const subscription = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: urlBase64ToUint8Array(vapidPublicKey),\n });\n\n return subscription;\n}\n\nfunction urlBase64ToUint8Array(base64String: string): Uint8Array {\n const padding = '='.repeat((4 - (base64String.length % 4)) % 4);\n const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');\n const rawData = atob(base64);\n return Uint8Array.from(rawData, (char) => char.charCodeAt(0));\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/pwa.ts"],"names":["registerServiceWorker","swUrl","options","registered","signal","updateAvailable","offline","registration","ready","resolve","reject","reg","newWorker","err","generateSWScript","routes","script","route","pattern","cacheName","generateStrategyCode","strategy","subscribePush","vapidPublicKey","urlBase64ToUint8Array","base64String","padding","base64","rawData","char"],"mappings":"mEA2DO,SAASA,CAAAA,CACdC,EACAC,CAAAA,CAAqB,GACL,CAChB,IAAMC,CAAAA,CAAaC,mBAAAA,CAAO,KAAK,CAAA,CACzBC,EAAkBD,mBAAAA,CAAO,KAAK,EAC9BE,CAAAA,CAAUF,mBAAAA,CAAO,CAAC,SAAA,CAAU,MAAM,CAAA,CAEpCG,CAAAA,CAAiD,IAAA,CAGrD,MAAA,CAAO,iBAAiB,QAAA,CAAU,IAAMD,EAAQ,GAAA,CAAI,KAAK,CAAC,CAAA,CAC1D,MAAA,CAAO,gBAAA,CAAiB,SAAA,CAAW,IAAMA,CAAAA,CAAQ,IAAI,IAAI,CAAC,CAAA,CAE1D,IAAME,CAAAA,CAAQ,IAAI,QAAmC,CAACC,CAAAA,CAASC,CAAAA,GAAW,CACxE,GAAI,EAAE,kBAAmB,SAAA,CAAA,CAAY,CACnCA,EAAO,IAAI,KAAA,CAAM,+BAA+B,CAAC,CAAA,CACjD,MACF,CAEA,SAAA,CAAU,aAAA,CACP,SAAST,CAAAA,CAAO,CAAE,MAAOC,CAAAA,CAAQ,KAAM,CAAC,CAAA,CACxC,IAAA,CAA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B,MAAMhB,EAAa,WAAA,CAAY,SAAA,CAAU,CAC5D,eAAA,CAAiB,IAAA,CAEjB,qBAAsBiB,CAAAA,CAAsBD,CAAc,CAC5D,CAAC,CAGH,CAEA,SAASC,CAAAA,CAAsBC,CAAAA,CAAkC,CAC/D,IAAMC,CAAAA,CAAU,IAAI,MAAA,CAAA,CAAQ,CAAA,CAAKD,CAAAA,CAAa,MAAA,CAAS,CAAA,EAAM,CAAC,EACxDE,CAAAA,CAAAA,CAAUF,CAAAA,CAAeC,GAAS,OAAA,CAAQ,IAAA,CAAM,GAAG,CAAA,CAAE,OAAA,CAAQ,IAAA,CAAM,GAAG,CAAA,CACtEE,CAAAA,CAAU,KAAKD,CAAM,CAAA,CAC3B,OAAO,UAAA,CAAW,IAAA,CAAKC,CAAAA,CAAUC,GAASA,CAAAA,CAAK,UAAA,CAAW,CAAC,CAAC,CAC9D","file":"chunk-6NX6JRSV.cjs","sourcesContent":["/**\n * PWA / Service Worker support.\n *\n * Register service workers, configure caching strategies,\n * handle updates, and manage push notifications.\n *\n * ```ts\n * const sw = registerServiceWorker('/sw.js', {\n * onUpdate: () => toast.info('New version available!'),\n * });\n * sw.ready; // Promise<ServiceWorkerRegistration>\n * sw.update(); // check for updates\n * ```\n */\n\nimport { signal } from './signals.js';\nimport type { ReadonlySignal } from './signals.js';\n\n// =========================================================================\n// Types\n// =========================================================================\n\nexport interface SWOptions {\n /** Callback when a new version is available */\n onUpdate?: (registration: ServiceWorkerRegistration) => void;\n /** Callback when the SW is ready */\n onReady?: (registration: ServiceWorkerRegistration) => void;\n /** Callback on registration error */\n onError?: (error: Error) => void;\n /** Auto-reload on update (default: false) */\n autoReload?: boolean;\n /** Scope of the service worker */\n scope?: string;\n}\n\nexport interface SWRegistration {\n /** Whether the SW is registered */\n registered: ReadonlySignal<boolean>;\n /** Whether an update is available */\n updateAvailable: ReadonlySignal<boolean>;\n /** Whether the app is running offline */\n offline: ReadonlySignal<boolean>;\n /** The raw SW registration (available after ready) */\n ready: Promise<ServiceWorkerRegistration>;\n /** Check for updates */\n update(): Promise<void>;\n /** Skip waiting and activate new SW */\n skipWaiting(): void;\n /** Unregister the service worker */\n unregister(): Promise<boolean>;\n}\n\n// =========================================================================\n// Service Worker registration\n// =========================================================================\n\n/**\n * Register a service worker with update detection.\n */\nexport function registerServiceWorker(\n swUrl: string,\n options: SWOptions = {},\n): SWRegistration {\n const registered = signal(false);\n const updateAvailable = signal(false);\n const offline = signal(!navigator.onLine);\n\n let registration: ServiceWorkerRegistration | null = null;\n\n // Track online/offline\n window.addEventListener('online', () => offline.set(false));\n window.addEventListener('offline', () => offline.set(true));\n\n const ready = new Promise<ServiceWorkerRegistration>((resolve, reject) => {\n if (!('serviceWorker' in navigator)) {\n reject(new Error('Service workers not supported'));\n return;\n }\n\n navigator.serviceWorker\n .register(swUrl, { scope: options.scope })\n .then((reg) => {\n registration = reg;\n registered.set(true);\n options.onReady?.(reg);\n resolve(reg);\n\n // Listen for updates\n reg.addEventListener('updatefound', () => {\n const newWorker = reg.installing;\n if (!newWorker) return;\n\n newWorker.addEventListener('statechange', () => {\n if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {\n updateAvailable.set(true);\n options.onUpdate?.(reg);\n\n if (options.autoReload) {\n newWorker.postMessage({ type: 'SKIP_WAITING' });\n window.location.reload();\n }\n }\n });\n });\n })\n .catch((err) => {\n options.onError?.(err);\n reject(err);\n });\n });\n\n return {\n registered: () => registered(),\n updateAvailable: () => updateAvailable(),\n offline: () => offline(),\n ready,\n async update() {\n if (registration) {\n await registration.update();\n }\n },\n skipWaiting() {\n if (registration?.waiting) {\n registration.waiting.postMessage({ type: 'SKIP_WAITING' });\n window.location.reload();\n }\n },\n async unregister() {\n if (registration) {\n return registration.unregister();\n }\n return false;\n },\n };\n}\n\n// =========================================================================\n// Caching strategies (for SW scripts)\n// =========================================================================\n\nexport type CacheStrategy = 'cache-first' | 'network-first' | 'stale-while-revalidate' | 'network-only' | 'cache-only';\n\nexport interface CacheRoute {\n /** URL pattern to match (string or regex) */\n match: string | RegExp;\n /** Caching strategy */\n strategy: CacheStrategy;\n /** Cache name */\n cacheName?: string;\n /** Max entries in cache */\n maxEntries?: number;\n /** Max age in seconds */\n maxAgeSeconds?: number;\n}\n\n/**\n * Generate a service worker script from cache route configs.\n *\n * ```ts\n * const swScript = generateSWScript([\n * { match: /\\.(?:js|css)$/, strategy: 'cache-first', cacheName: 'assets' },\n * { match: '/api/', strategy: 'network-first', maxAgeSeconds: 300 },\n * { match: /\\.(?:png|jpg|svg)$/, strategy: 'cache-first', cacheName: 'images' },\n * ]);\n * ```\n */\nexport function generateSWScript(routes: CacheRoute[]): string {\n let script = `// Auto-generated service worker by AkashJS\nconst CACHE_VERSION = 'v1';\n\nself.addEventListener('install', (event) => {\n self.skipWaiting();\n});\n\nself.addEventListener('activate', (event) => {\n event.waitUntil(clients.claim());\n});\n\nself.addEventListener('message', (event) => {\n if (event.data?.type === 'SKIP_WAITING') {\n self.skipWaiting();\n }\n});\n\nself.addEventListener('fetch', (event) => {\n const url = new URL(event.request.url);\n`;\n\n for (const route of routes) {\n const pattern = route.match instanceof RegExp\n ? route.match.toString()\n : `new RegExp(${JSON.stringify(route.match.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'))})`;\n\n const cacheName = route.cacheName ?? 'akash-cache';\n\n script += `\n if (${pattern}.test(url.pathname)) {\n event.respondWith(${generateStrategyCode(route.strategy, cacheName)});\n return;\n }\n`;\n }\n\n script += `\n // Default: network-first\n event.respondWith(\n fetch(event.request).catch(() => caches.match(event.request))\n );\n});\n`;\n\n return script;\n}\n\nfunction generateStrategyCode(strategy: CacheStrategy, cacheName: string): string {\n switch (strategy) {\n case 'cache-first':\n return `caches.match(event.request).then(cached => cached || fetch(event.request).then(response => { const clone = response.clone(); caches.open('${cacheName}').then(cache => cache.put(event.request, clone)); return response; }))`;\n case 'network-first':\n return `fetch(event.request).then(response => { const clone = response.clone(); caches.open('${cacheName}').then(cache => cache.put(event.request, clone)); return response; }).catch(() => caches.match(event.request))`;\n case 'stale-while-revalidate':\n return `caches.match(event.request).then(cached => { const fetchPromise = fetch(event.request).then(response => { caches.open('${cacheName}').then(cache => cache.put(event.request, response.clone())); return response; }); return cached || fetchPromise; })`;\n case 'network-only':\n return `fetch(event.request)`;\n case 'cache-only':\n return `caches.match(event.request)`;\n }\n}\n\n// =========================================================================\n// Push notifications\n// =========================================================================\n\n/**\n * Request push notification permission and subscribe.\n */\nexport async function subscribePush(\n registration: ServiceWorkerRegistration,\n vapidPublicKey: string,\n): Promise<PushSubscription | null> {\n const permission = await Notification.requestPermission();\n if (permission !== 'granted') return null;\n\n const subscription = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n applicationServerKey: urlBase64ToUint8Array(vapidPublicKey) as any,\n });\n\n return subscription;\n}\n\nfunction urlBase64ToUint8Array(base64String: string): Uint8Array {\n const padding = '='.repeat((4 - (base64String.length % 4)) % 4);\n const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');\n const rawData = atob(base64);\n return Uint8Array.from(rawData, (char) => char.charCodeAt(0));\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {l,m,n}from'./chunk-POLTPHUA.js';var k=[];function v(s){k.push(...s.plugins);}var g=new Map;function R(s,a){return ()=>{if(g.has(s))return g.get(s);let r=a.state(),o=A(s,r,a);return g.set(s,o),o}}function A(s,a,r){let o={},c=Object.keys(a);for(let t of c)o[t]=l(a[t]);let n$1={$id:s};for(let t of c)n$1[t]=o[t];if(r.getters)for(let[t,e]of Object.entries(r.getters))n$1[t]=m(()=>e.call(n$1,o));let y=[...k,...r.plugins??[]];if(r.actions)for(let[t,e]of Object.entries(r.actions))n$1[t]=(...i)=>{for(let f of y)f.onAction?.(n$1,t,i);return e.apply(n$1,i)};n$1.$reset=()=>{let t=r.state();for(let e of c)o[e].set(t[e]);},n$1.$patch=t=>{if(typeof t=="function")t(o);else for(let[e,i]of Object.entries(t))e in o&&o[e].set(i);},n$1.$snapshot=()=>{let t={};for(let e of c)t[e]=o[e]();return t};let l$1=new Set,S=null;n$1.$subscribe=t=>{if(l$1.add(t),!S){let e=true;S=n(()=>{for(let f of c)o[f]();if(e){e=false;return}let i=n$1.$snapshot();for(let f of l$1)f(i);});}return ()=>{l$1.delete(t),l$1.size===0&&S&&(S(),S=null);}};for(let t of y)t.init?.(n$1);return n$1}function x(){g.clear();}function b(){return Object.fromEntries(g)}export{v as a,R as b,x as c,b as d};//# sourceMappingURL=chunk-772SU4MG.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-772SU4MG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/store.ts"],"names":["globalPlugins","configureStores","options","storeInstances","defineStore","id","definition","initialState","store","createStoreInstance","stateSignals","stateKeys","key","signal","getterFn","computed","plugins","actionFn","args","plugin","fresh","partialOrFn","value","snapshot","subscribers","subscribeEffect","callback","isInitial","effect","cb","clearStores","__getStoreInstances"],"mappings":"wCA2FA,IAAMA,EAA+B,EAAC,CAG/B,SAASC,CAAAA,CAAgBC,EAA2C,CACzEF,CAAAA,CAAc,IAAA,CAAK,GAAGE,EAAQ,OAAO,EACvC,CAIA,IAAMC,CAAAA,CAAiB,IAAI,GAAA,CAQpB,SAASC,CAAAA,CAKdC,CAAAA,CACAC,EACsB,CACtB,OAAO,IAAM,CAEX,GAAIH,CAAAA,CAAe,GAAA,CAAIE,CAAE,CAAA,CACvB,OAAOF,CAAAA,CAAe,GAAA,CAAIE,CAAE,CAAA,CAG9B,IAAME,EAAeD,CAAAA,CAAW,KAAA,EAAM,CAChCE,CAAAA,CAAQC,EAAoBJ,CAAAA,CAAIE,CAAAA,CAAcD,CAAU,CAAA,CAC9D,OAAAH,CAAAA,CAAe,GAAA,CAAIE,CAAAA,CAAIG,CAAK,EACrBA,CACT,CACF,CAEA,SAASC,CAAAA,CAKPJ,EACAE,CAAAA,CACAD,CAAA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AEjD,OAAOA,GACT,CAKO,SAASsB,CAAAA,EAAoB,CAClC3B,CAAAA,CAAe,KAAA,GACjB,CAGO,SAAS4B,CAAAA,EAA4D,CAC1E,OAAO,MAAA,CAAO,WAAA,CAAY5B,CAAc,CAC1C","file":"chunk-772SU4MG.js","sourcesContent":["/**\n * Global state management via defineStore().\n *\n * Stores are singleton signal containers that persist across\n * components. They provide shared state, computed getters,\n * and actions — no external library needed.\n *\n * ```ts\n * const useCounterStore = defineStore('counter', {\n * state: () => ({ count: 0, name: 'Counter' }),\n * getters: {\n * doubled: (state) => state.count() * 2,\n * },\n * actions: {\n * increment() { this.count.update(c => c + 1); },\n * reset() { this.count.set(0); },\n * },\n * });\n *\n * // In any component:\n * const store = useCounterStore();\n * store.count(); // 0\n * store.doubled(); // 0\n * store.increment();\n * store.count(); // 1\n * ```\n */\n\nimport { signal, computed, effect } from './signals.js';\nimport type { Signal, ReadonlySignal } from './signals.js';\n\n// --- Types ---\n\ntype StateFactory<S> = () => S;\n\ntype Getters<S, G> = {\n [K in keyof G]: (state: SignalifiedState<S>) => G[K];\n};\n\ntype Actions<A> = {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (...args: P) => R\n : never;\n};\n\n/** Maps plain state values to signals */\ntype SignalifiedState<S> = {\n [K in keyof S]: Signal<S[K]>;\n};\n\n/** The store instance returned to consumers */\nexport type Store<S, G, A> = SignalifiedState<S> & {\n [K in keyof G]: ReadonlySignal<G[K]>;\n} & {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (...args: P) => R\n : never;\n} & {\n /** Reset all state to initial values */\n $reset(): void;\n /** Merge partial state into the store, or apply changes via callback */\n $patch(partialOrFn: Partial<S> | ((state: SignalifiedState<S>) => void)): void;\n /** Subscribe to all state changes */\n $subscribe(callback: (state: S) => void): () => void;\n /** Get a plain snapshot of current state */\n $snapshot(): S;\n /** Store ID */\n $id: string;\n};\n\n/** Actions with `this` typed to include state signals, getters, and other actions */\ntype StoreActions<S, G, A> = {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (this: SignalifiedState<S> & { [GK in keyof G]: ReadonlySignal<G[GK]> } & A, ...args: P) => R\n : never;\n};\n\nexport interface StoreDefinition<S, G, A> {\n state: StateFactory<S>;\n getters?: Getters<S, G>;\n actions?: StoreActions<S, G, A>;\n plugins?: StorePlugin[];\n}\n\n// --- Plugin system ---\n\nexport interface StorePlugin {\n init?(store: Store<any, any, any>): void;\n onAction?(store: Store<any, any, any>, actionName: string, args: unknown[]): void;\n}\n\nconst globalPlugins: StorePlugin[] = [];\n\n/** Register global plugins that apply to all stores */\nexport function configureStores(options: { plugins: StorePlugin[] }): void {\n globalPlugins.push(...options.plugins);\n}\n\n// --- Store registry (singleton) ---\n\nconst storeInstances = new Map<string, Store<any, any, any>>();\n\n// --- defineStore ---\n\n/**\n * Define a global store. Returns a composable function that\n * always returns the same store instance (singleton).\n */\nexport function defineStore<\n S extends Record<string, unknown>,\n G extends Record<string, unknown> = {},\n A extends Record<string, (...args: any[]) => any> = {},\n>(\n id: string,\n definition: StoreDefinition<S, G, A>,\n): () => Store<S, G, A> {\n return () => {\n // Return existing instance if already created\n if (storeInstances.has(id)) {\n return storeInstances.get(id) as Store<S, G, A>;\n }\n\n const initialState = definition.state();\n const store = createStoreInstance(id, initialState, definition);\n storeInstances.set(id, store);\n return store;\n };\n}\n\nfunction createStoreInstance<\n S extends Record<string, unknown>,\n G extends Record<string, unknown>,\n A extends Record<string, (...args: any[]) => any>,\n>(\n id: string,\n initialState: S,\n definition: StoreDefinition<S, G, A>,\n): Store<S, G, A> {\n // Create signals for each state property\n const stateSignals: Record<string, Signal<unknown>> = {};\n const stateKeys = Object.keys(initialState);\n\n for (const key of stateKeys) {\n stateSignals[key] = signal(initialState[key]);\n }\n\n // Build the store object first so getters can reference other getters via `this`\n const store: any = { $id: id };\n\n // Add state signals\n for (const key of stateKeys) {\n store[key] = stateSignals[key];\n }\n\n // Create computed getters — bound to store so `this.otherGetter()` works\n if (definition.getters) {\n for (const [key, getterFn] of Object.entries(definition.getters)) {\n store[key] = computed(() =>\n (getterFn as Function).call(store, stateSignals),\n );\n }\n }\n\n // Collect all plugins (global + per-store)\n const plugins = [...globalPlugins, ...(definition.plugins ?? [])];\n\n // Bind actions with `this` pointing to the full store (state + getters + actions)\n if (definition.actions) {\n for (const [key, actionFn] of Object.entries(definition.actions)) {\n store[key] = (...args: unknown[]) => {\n for (const plugin of plugins) plugin.onAction?.(store, key, args);\n return (actionFn as Function).apply(store, args);\n };\n }\n }\n\n // $reset\n store.$reset = () => {\n const fresh = definition.state();\n for (const key of stateKeys) {\n stateSignals[key].set(fresh[key as keyof S]);\n }\n };\n\n // $patch — merge partial state or apply via callback\n store.$patch = (partialOrFn: Partial<S> | ((state: any) => void)) => {\n if (typeof partialOrFn === 'function') {\n partialOrFn(stateSignals);\n } else {\n for (const [key, value] of Object.entries(partialOrFn)) {\n if (key in stateSignals) {\n stateSignals[key].set(value);\n }\n }\n }\n };\n\n // $snapshot\n store.$snapshot = (): S => {\n const snapshot: Record<string, unknown> = {};\n for (const key of stateKeys) {\n snapshot[key] = stateSignals[key]();\n }\n return snapshot as S;\n };\n\n // $subscribe — watch all state signals and notify on change\n const subscribers = new Set<(state: S) => void>();\n let subscribeEffect: (() => void) | null = null;\n store.$subscribe = (callback: (state: S) => void): (() => void) => {\n subscribers.add(callback);\n // Start watching if this is the first subscriber\n if (!subscribeEffect) {\n let isInitial = true;\n subscribeEffect = effect(() => {\n // Read all state signals to track them\n for (const key of stateKeys) {\n stateSignals[key]();\n }\n // Skip initial run — only notify on actual changes\n if (isInitial) {\n isInitial = false;\n return;\n }\n const snapshot = store.$snapshot();\n for (const cb of subscribers) {\n cb(snapshot);\n }\n });\n }\n return () => {\n subscribers.delete(callback);\n // Dispose effect when no subscribers remain\n if (subscribers.size === 0 && subscribeEffect) {\n subscribeEffect();\n subscribeEffect = null;\n }\n };\n };\n\n // Initialize plugins\n for (const plugin of plugins) plugin.init?.(store);\n\n return store as Store<S, G, A>;\n}\n\n/**\n * Clear all store instances (useful for testing).\n */\nexport function clearStores(): void {\n storeInstances.clear();\n}\n\n/** @internal — exposes store registry for devtools */\nexport function __getStoreInstances(): Record<string, Store<any, any, any>> {\n return Object.fromEntries(storeInstances);\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var chunk3AL2DVPZ_cjs=require('./chunk-3AL2DVPZ.cjs');var k=[];function v(s){k.push(...s.plugins);}var g=new Map;function R(s,a){return ()=>{if(g.has(s))return g.get(s);let r=a.state(),o=A(s,r,a);return g.set(s,o),o}}function A(s,a,r){let o={},c=Object.keys(a);for(let t of c)o[t]=chunk3AL2DVPZ_cjs.l(a[t]);let n={$id:s};for(let t of c)n[t]=o[t];if(r.getters)for(let[t,e]of Object.entries(r.getters))n[t]=chunk3AL2DVPZ_cjs.m(()=>e.call(n,o));let y=[...k,...r.plugins??[]];if(r.actions)for(let[t,e]of Object.entries(r.actions))n[t]=(...i)=>{for(let f of y)f.onAction?.(n,t,i);return e.apply(n,i)};n.$reset=()=>{let t=r.state();for(let e of c)o[e].set(t[e]);},n.$patch=t=>{if(typeof t=="function")t(o);else for(let[e,i]of Object.entries(t))e in o&&o[e].set(i);},n.$snapshot=()=>{let t={};for(let e of c)t[e]=o[e]();return t};let l=new Set,S=null;n.$subscribe=t=>{if(l.add(t),!S){let e=true;S=chunk3AL2DVPZ_cjs.n(()=>{for(let f of c)o[f]();if(e){e=false;return}let i=n.$snapshot();for(let f of l)f(i);});}return ()=>{l.delete(t),l.size===0&&S&&(S(),S=null);}};for(let t of y)t.init?.(n);return n}function x(){g.clear();}function b(){return Object.fromEntries(g)}exports.a=v;exports.b=R;exports.c=x;exports.d=b;//# sourceMappingURL=chunk-7LQZF3XA.cjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-7LQZF3XA.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/store.ts"],"names":["globalPlugins","configureStores","options","storeInstances","defineStore","id","definition","initialState","store","createStoreInstance","stateSignals","stateKeys","key","signal","getterFn","computed","plugins","actionFn","args","plugin","fresh","partialOrFn","value","snapshot","subscribers","subscribeEffect","callback","isInitial","effect","cb","clearStores","__getStoreInstances"],"mappings":"mEA2FA,IAAMA,EAA+B,EAAC,CAG/B,SAASC,CAAAA,CAAgBC,EAA2C,CACzEF,CAAAA,CAAc,IAAA,CAAK,GAAGE,EAAQ,OAAO,EACvC,CAIA,IAAMC,CAAAA,CAAiB,IAAI,GAAA,CAQpB,SAASC,CAAAA,CAKdC,CAAAA,CACAC,EACsB,CACtB,OAAO,IAAM,CAEX,GAAIH,CAAAA,CAAe,GAAA,CAAIE,CAAE,CAAA,CACvB,OAAOF,CAAAA,CAAe,GAAA,CAAIE,CAAE,CAAA,CAG9B,IAAME,EAAeD,CAAAA,CAAW,KAAA,EAAM,CAChCE,CAAAA,CAAQC,EAAoBJ,CAAAA,CAAIE,CAAAA,CAAcD,CAAU,CAAA,CAC9D,OAAAH,CAAAA,CAAe,GAAA,CAAIE,CAAAA,CAAIG,CAAK,EACrBA,CACT,CACF,CAEA,SAASC,CAAAA,CAKPJ,EACAE,CAAAA,CACAD,CAAAA,CACgB,CAEhB,IAAMI,EAAgD,EAAC,CACjDC,CAAAA,CAAY,MAAA,CAAO,KAAKJ,CAAY,CAAA,CAE1C,IAAA,IAAWK,CAAAA,IAAOD,EAChBD,CAAAA,CAAaE,CAAG,EAAIC,mBAAAA,CAAON,CAAAA,CAAaK,CAAG,CAAC,CAAA,CAI9C,IAAMJ,CAAAA,CAAa,CAAE,GAAA,CAAKH,CAAG,CAAA,CAG7B,IAAA,IAAWO,KAAOD,CAAAA,CAChBH,CAAAA,CAAMI,CAAG,CAAA,CAAIF,EAAaE,CAAG,CAAA,CAI/B,GAAIN,CAAAA,CAAW,OAAA,CACb,OAAW,CAACM,CAAAA,CAAKE,CAAQ,CAAA,GAAK,OAAO,OAAA,CAAQR,CAAAA,CAAW,OAAO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AAOW,CACT,CAAA,CAGA,IAAMC,CAAAA,CAAc,IAAI,IACpBC,CAAAA,CAAuC,IAAA,CAC3CjB,EAAM,UAAA,CAAckB,CAAAA,EAA+C,CAGjE,GAFAF,CAAAA,CAAY,GAAA,CAAIE,CAAQ,EAEpB,CAACD,CAAAA,CAAiB,CACpB,IAAIE,EAAY,IAAA,CAChBF,CAAAA,CAAkBG,mBAAAA,CAAO,IAAM,CAE7B,IAAA,IAAWhB,CAAAA,IAAOD,EAChBD,CAAAA,CAAaE,CAAG,GAAE,CAGpB,GAAIe,CAAAA,CAAW,CACbA,EAAY,KAAA,CACZ,MACF,CACA,IAAMJ,EAAWf,CAAAA,CAAM,SAAA,EAAU,CACjC,IAAA,IAAWqB,KAAML,CAAAA,CACfK,CAAAA,CAAGN,CAAQ,EAEf,CAAC,EACH,CACA,OAAO,IAAM,CACXC,EAAY,MAAA,CAAOE,CAAQ,CAAA,CAEvBF,CAAAA,CAAY,OAAS,CAAA,EAAKC,CAAAA,GAC5BA,CAAAA,EAAgB,CAChBA,EAAkB,IAAA,EAEtB,CACF,EAGA,IAAA,IAAWN,CAAAA,IAAUH,EAASG,CAAAA,CAAO,IAAA,GAAOX,CAAK,CAAA,CAEjD,OAAOA,CACT,CAKO,SAASsB,CAAAA,EAAoB,CAClC3B,CAAAA,CAAe,KAAA,GACjB,CAGO,SAAS4B,CAAAA,EAA4D,CAC1E,OAAO,MAAA,CAAO,WAAA,CAAY5B,CAAc,CAC1C","file":"chunk-7LQZF3XA.cjs","sourcesContent":["/**\n * Global state management via defineStore().\n *\n * Stores are singleton signal containers that persist across\n * components. They provide shared state, computed getters,\n * and actions — no external library needed.\n *\n * ```ts\n * const useCounterStore = defineStore('counter', {\n * state: () => ({ count: 0, name: 'Counter' }),\n * getters: {\n * doubled: (state) => state.count() * 2,\n * },\n * actions: {\n * increment() { this.count.update(c => c + 1); },\n * reset() { this.count.set(0); },\n * },\n * });\n *\n * // In any component:\n * const store = useCounterStore();\n * store.count(); // 0\n * store.doubled(); // 0\n * store.increment();\n * store.count(); // 1\n * ```\n */\n\nimport { signal, computed, effect } from './signals.js';\nimport type { Signal, ReadonlySignal } from './signals.js';\n\n// --- Types ---\n\ntype StateFactory<S> = () => S;\n\ntype Getters<S, G> = {\n [K in keyof G]: (state: SignalifiedState<S>) => G[K];\n};\n\ntype Actions<A> = {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (...args: P) => R\n : never;\n};\n\n/** Maps plain state values to signals */\ntype SignalifiedState<S> = {\n [K in keyof S]: Signal<S[K]>;\n};\n\n/** The store instance returned to consumers */\nexport type Store<S, G, A> = SignalifiedState<S> & {\n [K in keyof G]: ReadonlySignal<G[K]>;\n} & {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (...args: P) => R\n : never;\n} & {\n /** Reset all state to initial values */\n $reset(): void;\n /** Merge partial state into the store, or apply changes via callback */\n $patch(partialOrFn: Partial<S> | ((state: SignalifiedState<S>) => void)): void;\n /** Subscribe to all state changes */\n $subscribe(callback: (state: S) => void): () => void;\n /** Get a plain snapshot of current state */\n $snapshot(): S;\n /** Store ID */\n $id: string;\n};\n\n/** Actions with `this` typed to include state signals, getters, and other actions */\ntype StoreActions<S, G, A> = {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (this: SignalifiedState<S> & { [GK in keyof G]: ReadonlySignal<G[GK]> } & A, ...args: P) => R\n : never;\n};\n\nexport interface StoreDefinition<S, G, A> {\n state: StateFactory<S>;\n getters?: Getters<S, G>;\n actions?: StoreActions<S, G, A>;\n plugins?: StorePlugin[];\n}\n\n// --- Plugin system ---\n\nexport interface StorePlugin {\n init?(store: Store<any, any, any>): void;\n onAction?(store: Store<any, any, any>, actionName: string, args: unknown[]): void;\n}\n\nconst globalPlugins: StorePlugin[] = [];\n\n/** Register global plugins that apply to all stores */\nexport function configureStores(options: { plugins: StorePlugin[] }): void {\n globalPlugins.push(...options.plugins);\n}\n\n// --- Store registry (singleton) ---\n\nconst storeInstances = new Map<string, Store<any, any, any>>();\n\n// --- defineStore ---\n\n/**\n * Define a global store. Returns a composable function that\n * always returns the same store instance (singleton).\n */\nexport function defineStore<\n S extends Record<string, unknown>,\n G extends Record<string, unknown> = {},\n A extends Record<string, (...args: any[]) => any> = {},\n>(\n id: string,\n definition: StoreDefinition<S, G, A>,\n): () => Store<S, G, A> {\n return () => {\n // Return existing instance if already created\n if (storeInstances.has(id)) {\n return storeInstances.get(id) as Store<S, G, A>;\n }\n\n const initialState = definition.state();\n const store = createStoreInstance(id, initialState, definition);\n storeInstances.set(id, store);\n return store;\n };\n}\n\nfunction createStoreInstance<\n S extends Record<string, unknown>,\n G extends Record<string, unknown>,\n A extends Record<string, (...args: any[]) => any>,\n>(\n id: string,\n initialState: S,\n definition: StoreDefinition<S, G, A>,\n): Store<S, G, A> {\n // Create signals for each state property\n const stateSignals: Record<string, Signal<unknown>> = {};\n const stateKeys = Object.keys(initialState);\n\n for (const key of stateKeys) {\n stateSignals[key] = signal(initialState[key]);\n }\n\n // Build the store object first so getters can reference other getters via `this`\n const store: any = { $id: id };\n\n // Add state signals\n for (const key of stateKeys) {\n store[key] = stateSignals[key];\n }\n\n // Create computed getters — bound to store so `this.otherGetter()` works\n if (definition.getters) {\n for (const [key, getterFn] of Object.entries(definition.getters)) {\n store[key] = computed(() =>\n (getterFn as Function).call(store, stateSignals),\n );\n }\n }\n\n // Collect all plugins (global + per-store)\n const plugins = [...globalPlugins, ...(definition.plugins ?? [])];\n\n // Bind actions with `this` pointing to the full store (state + getters + actions)\n if (definition.actions) {\n for (const [key, actionFn] of Object.entries(definition.actions)) {\n store[key] = (...args: unknown[]) => {\n for (const plugin of plugins) plugin.onAction?.(store, key, args);\n return (actionFn as Function).apply(store, args);\n };\n }\n }\n\n // $reset\n store.$reset = () => {\n const fresh = definition.state();\n for (const key of stateKeys) {\n stateSignals[key].set(fresh[key as keyof S]);\n }\n };\n\n // $patch — merge partial state or apply via callback\n store.$patch = (partialOrFn: Partial<S> | ((state: any) => void)) => {\n if (typeof partialOrFn === 'function') {\n partialOrFn(stateSignals);\n } else {\n for (const [key, value] of Object.entries(partialOrFn)) {\n if (key in stateSignals) {\n stateSignals[key].set(value);\n }\n }\n }\n };\n\n // $snapshot\n store.$snapshot = (): S => {\n const snapshot: Record<string, unknown> = {};\n for (const key of stateKeys) {\n snapshot[key] = stateSignals[key]();\n }\n return snapshot as S;\n };\n\n // $subscribe — watch all state signals and notify on change\n const subscribers = new Set<(state: S) => void>();\n let subscribeEffect: (() => void) | null = null;\n store.$subscribe = (callback: (state: S) => void): (() => void) => {\n subscribers.add(callback);\n // Start watching if this is the first subscriber\n if (!subscribeEffect) {\n let isInitial = true;\n subscribeEffect = effect(() => {\n // Read all state signals to track them\n for (const key of stateKeys) {\n stateSignals[key]();\n }\n // Skip initial run — only notify on actual changes\n if (isInitial) {\n isInitial = false;\n return;\n }\n const snapshot = store.$snapshot();\n for (const cb of subscribers) {\n cb(snapshot);\n }\n });\n }\n return () => {\n subscribers.delete(callback);\n // Dispose effect when no subscribers remain\n if (subscribers.size === 0 && subscribeEffect) {\n subscribeEffect();\n subscribeEffect = null;\n }\n };\n };\n\n // Initialize plugins\n for (const plugin of plugins) plugin.init?.(store);\n\n return store as Store<S, G, A>;\n}\n\n/**\n * Clear all store instances (useful for testing).\n */\nexport function clearStores(): void {\n storeInstances.clear();\n}\n\n/** @internal — exposes store registry for devtools */\nexport function __getStoreInstances(): Record<string, Store<any, any, any>> {\n return Object.fromEntries(storeInstances);\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import {n,o}from'./chunk-POLTPHUA.js';var w={AK0010:{code:"AK0010",message:"provide() called outside of component setup.",hint:"provide() must be called inside defineComponent()."},AK0012:{code:"AK0012",message:"inject() called outside of component setup.",hint:"inject() must be called inside defineComponent()."},AK0013:{code:"AK0013",message:"No provider found for injected context.",hint:"Make sure an ancestor component calls provide() with this key."},AK0020:{code:"AK0020",message:"onMount() called outside of component setup.",hint:"onMount() must be called inside defineComponent()."},AK0021:{code:"AK0021",message:"onUnmount() called outside of component setup.",hint:"onUnmount() must be called inside defineComponent()."},AK0022:{code:"AK0022",message:"onError() called outside of component setup.",hint:"onError() must be called inside defineComponent()."},AK0030:{code:"AK0030",message:"Circular dependency detected in computed signal.",hint:"A computed signal is reading itself, directly or via other computeds."},AK0031:{code:"AK0031",message:"Signal set() called during computation.",hint:"Do not set signals inside computed() or during effect execution. Use batch() or set signals in event handlers."},AK0040:{code:"AK0040",message:"Component setup must return a render function.",hint:"The function passed to defineComponent() must return () => AkashNode."},AK0041:{code:"AK0041",message:"Required prop is missing.",hint:"Check that the parent component is passing all required props."},AK0050:{code:"AK0050",message:"useRoute() called outside of router context.",hint:"Make sure your component is rendered inside a router provider."},AK0051:{code:"AK0051",message:"No route matched the current URL.",hint:"Add a catch-all route ([...rest]) to handle unmatched paths."},AK0052:{code:"AK0052",message:"Route guard threw an error.",hint:"Check the guard function for unhandled exceptions."},AK0060:{code:"AK0060",message:"Form submitted while invalid.",hint:"The submit handler was not called because validation failed. Check form.errors()."},AK0061:{code:"AK0061",message:"Async validator timed out.",hint:"The async validator did not resolve within the expected time. Check your async validation logic."},AK0070:{code:"AK0070",message:"HTTP request failed.",hint:"Check the server response status and network connectivity."},AK0071:{code:"AK0071",message:"createResource() fetcher threw an error.",hint:"Check the fetcher function passed to createResource()."}},P="https://akashjs.dev/errors";function R(e,n){let o=w[e];if(!o)return `[AkashJS ${e}] Unknown error code.`;let s=`[AkashJS ${e}] ${o.message}`;return n&&(s+=`
|
|
2
|
+
${n}`),s+=`
|
|
3
|
+
${o.hint}`,s+=`
|
|
4
|
+
See: ${P}/${e}`,s}function T(e,n){return new Error(R(e,n))}function F(e){return w[e]}function _(){return Object.keys(w)}var D=Symbol("akash.context"),m=null;function S(e=m){let n={values:new Map,parent:e};return m=n,n}function K(e){m=e.parent;}function C(){return m}function v(e,n){let o=m;m=e;try{return n()}finally{m=o;}}function O(e){return {[D]:true,_type:void 0,defaultValue:e,id:Symbol("context")}}function $(e,n){if(!m)throw T("AK0010");m.values.set(e.id,n);}function U(e,n){if(!m)throw T("AK0012");let o=m;for(;o;){if(o.values.has(e.id))return o.values.get(e.id);o=o.parent;}if(n!==void 0)return n;if(e.defaultValue!==void 0)return e.defaultValue;throw T("AK0013")}function W(e,n){let o=document.createElement(e);if(n)for(let[s,a]of Object.entries(n))b(o,s,a);return o}function X(e){return document.createTextNode(e)}function G(e){let n=document.createElement("template");return n.innerHTML=e,n.content.cloneNode(true)}function b(e,n,o){if(n==="class"||n==="className")e.className=o;else if(n==="style"&&typeof o=="object"&&o!==null)Object.assign(e.style,o);else if(n==="innerHTML")e.innerHTML=o;else if(n!=="ref")if(n.startsWith("on")){let s=n.slice(2).toLowerCase();e.addEventListener(s,o);}else n in e?e[n]=o:o===false||o==null?e.removeAttribute(n):e.setAttribute(n,o===true?"":String(o));}function Y(e,n$1){return n(()=>{e.textContent=String(n$1());},{render:true})}function z(e,n$1,o){return n(()=>{b(e,n$1,o());},{render:true})}function Q(e,n$1){return n(()=>{e.style.display=n$1()?"":"none";},{render:true})}function L(e=""){return document.createComment(e)}function j(e,n$1,o,s,a){let i=null,g=C(),y=n(()=>{let c=o();if(i){for(let f of i.nodes)try{f.parentNode?.removeChild(f);}catch{}i.dispose?.(),i=null;}let d=c?s:a,p=n$1.parentNode;if(!p&&i?.nodes[0]?.parentNode&&(p=i.nodes[0].parentNode),d&&p){let f=g?v(g,d):d(),t=f instanceof DocumentFragment?Array.from(f.childNodes):[f];for(let r of t)p.insertBefore(r,n$1);i={nodes:t,dispose:null};}},{render:true});return ()=>{if(y(),i){for(let c of i.nodes)try{c.parentNode?.removeChild(c);}catch{}i.dispose?.();}}}function H(e,n$1,o,s,a){let i=[],g=C(),y=n(()=>{let c=o(),d=[],p=new Map;for(let t of i)p.set(t.key,t);for(let t=0;t<c.length;t++){let r=c[t],u=s(r,t),l=p.get(u);if(l){p.delete(u);let A=l.nodes[0];if(A&&!A.parentNode){let k=g?v(g,()=>a(r,t)):a(r,t),M=k instanceof DocumentFragment?Array.from(k.childNodes):[k];d.push({key:u,value:r,nodes:M,dispose:null});}else l.value=r,d.push(l);}else {let A=g?v(g,()=>a(r,t)):a(r,t),k=A instanceof DocumentFragment?Array.from(A.childNodes):[A];d.push({key:u,value:r,nodes:k,dispose:null});}}for(let t of p.values()){for(let r of t.nodes)r.parentNode&&r.parentNode.removeChild(r);t.dispose?.();}let f=n$1.parentNode;if(f)for(let t of d)for(let r of t.nodes)f.insertBefore(r,n$1);else {let t=null;for(let r of i)if(r.nodes[0]?.parentNode){t=r.nodes[0].parentNode;break}if(t)for(let r of d)for(let u of r.nodes)t.appendChild(u);}i=d;},{render:true});return ()=>{y();for(let c of i){for(let d of c.nodes)d.parentNode&&d.parentNode.removeChild(d);c.dispose?.();}i=[];}}function Z(e){let n=L("show"),o=document.createDocumentFragment();o.appendChild(n);let s=typeof e.when=="function"?e.when:()=>e.when,a;return j(o,n,()=>(a=s(),!!a),()=>x(e.children(a)),e.fallback?()=>x(e.fallback()):void 0),o}function ee(e){let n=L("for"),o=document.createDocumentFragment();o.appendChild(n);let s=typeof e.each=="function"?e.each:()=>e.each;return H(o,n,s,e.key,(a,i)=>x(e.children(a,i))),o}function x(e){if(e==null||typeof e=="boolean")return document.createTextNode("");if(typeof e=="string"||typeof e=="number")return document.createTextNode(String(e));if(e instanceof Node)return e;if(Array.isArray(e)){let n=document.createDocumentFragment();for(let o of e)n.appendChild(x(o));return n}return document.createTextNode(String(e))}function ne(e,n,o){let s=x(n);o?e.insertBefore(s,o):e.appendChild(s);}function de(e){return e.__reactive=true,e}var h=null;function ae(e){if(!h)throw T("AK0020");h.mount.push(e);}function ue(e){if(!h)throw T("AK0021");h.unmount.push(e);}function le(e){if(!h)throw T("AK0022");h.error.push(e);}function fe(e){return {current:e}}function pe(e){let n=o$1=>{let{children:s,...a}=o$1??{},y={props:a,children:typeof s=="function"?s:()=>s??null},c={mount:[],unmount:[],error:[]},d=h;h=c;let p=C(),f=S(p),t,r;try{r=o(()=>{if(t=e(y),typeof t!="function")throw T("AK0040");let u=t();return x(u)});}catch(u){if(K(f),h=d,c.error.length>0){for(let l of c.error)l(u instanceof Error?u:new Error(String(u)));return document.createComment("error")}throw u}return K(f),h=d,c.mount.length>0&&queueMicrotask(()=>{for(let u of c.mount)try{let l=u();typeof l=="function"&&c.unmount.push(l);}catch(l){for(let A of c.error)A(l instanceof Error?l:new Error(String(l)));}}),r};return n._akash=true,n}export{fe as A,pe as B,R as a,T as b,F as c,_ as d,C as e,v as f,O as g,$ as h,U as i,W as j,X as k,G as l,b as m,Y as n,z as o,Q as p,j as q,H as r,Z as s,ee as t,x as u,ne as v,de as w,ae as x,ue as y,le as z};//# sourceMappingURL=chunk-BT6HNBE7.js.map
|
|
5
|
+
//# sourceMappingURL=chunk-BT6HNBE7.js.map
|