@sigil-dev/runtime 0.9.3 → 0.9.5

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/async-boundary.ts CHANGED
@@ -1,30 +1,30 @@
1
- export function __asyncBoundary(
2
- factory: () => Promise<any>,
3
- Loading?: () => any,
4
- Err?: (props: { error: unknown }) => any,
5
- ): Node {
6
- const container = document.createElement("div");
7
- container.dataset.asyncBoundary = "1";
8
-
9
- if (Loading) {
10
- const node = Loading();
11
- if (node) container.appendChild(node);
12
- }
13
-
14
- factory()
15
- .then((node) => {
16
- if (node) container.replaceChildren(node);
17
- else container.replaceChildren();
18
- })
19
- .catch((err) => {
20
- if (Err) {
21
- const errNode = Err({ error: err });
22
- if (errNode) container.replaceChildren(errNode);
23
- } else {
24
- console.error("[sigil] async component error:", err);
25
- container.replaceChildren();
26
- }
27
- });
28
-
29
- return container;
30
- }
1
+ export function __asyncBoundary(
2
+ factory: () => Promise<any>,
3
+ Loading?: () => any,
4
+ Err?: (props: { error: unknown }) => any,
5
+ ): Node {
6
+ const container = document.createElement("div");
7
+ container.dataset.asyncBoundary = "1";
8
+
9
+ if (Loading) {
10
+ const node = Loading();
11
+ if (node) container.appendChild(node);
12
+ }
13
+
14
+ factory()
15
+ .then((node) => {
16
+ if (node) container.replaceChildren(node);
17
+ else container.replaceChildren();
18
+ })
19
+ .catch((err) => {
20
+ if (Err) {
21
+ const errNode = Err({ error: err });
22
+ if (errNode) container.replaceChildren(errNode);
23
+ } else {
24
+ console.error("[sigil] async component error:", err);
25
+ container.replaceChildren();
26
+ }
27
+ });
28
+
29
+ return container;
30
+ }
package/boundary.ts CHANGED
@@ -1,44 +1,44 @@
1
- /**
2
- * Error boundary for Sigil components.
3
- *
4
- * Wraps children so that errors during rendering are caught
5
- * and handled instead of crashing the app.
6
- *
7
- * Usage:
8
- * <Boundary
9
- * fallbackError={({ error, reset }) => <button onClick={reset}>Retry</button>}
10
- * onError={(e) => reportToSentry(e)}
11
- * >
12
- * <FlakyComponent />
13
- * </Boundary>
14
- */
15
-
16
- import { createSignal } from "./index.js";
17
-
18
- interface BoundaryProps {
19
- children: any;
20
- fallbackError?: (ctx: { error: Error; reset: () => void }) => any;
21
- onError?: (error: Error) => void;
22
- }
23
-
24
- export function Boundary(props: BoundaryProps): any {
25
- const error = createSignal<Error | null>(null);
26
-
27
- const reset = () => error.set(null);
28
-
29
- if (error()) {
30
- return props.fallbackError
31
- ? props.fallbackError({ error: error()!, reset })
32
- : null;
33
- }
34
-
35
- try {
36
- return props.children;
37
- } catch (e) {
38
- props.onError?.(e as Error);
39
- error.set(e as Error);
40
- return props.fallbackError
41
- ? props.fallbackError({ error: e as Error, reset })
42
- : null;
43
- }
44
- }
1
+ /**
2
+ * Error boundary for Sigil components.
3
+ *
4
+ * Wraps children so that errors during rendering are caught
5
+ * and handled instead of crashing the app.
6
+ *
7
+ * Usage:
8
+ * <Boundary
9
+ * fallbackError={({ error, reset }) => <button onClick={reset}>Retry</button>}
10
+ * onError={(e) => reportToSentry(e)}
11
+ * >
12
+ * <FlakyComponent />
13
+ * </Boundary>
14
+ */
15
+
16
+ import { createSignal } from "./index.js";
17
+
18
+ interface BoundaryProps {
19
+ children: any;
20
+ fallbackError?: (ctx: { error: Error; reset: () => void }) => any;
21
+ onError?: (error: Error) => void;
22
+ }
23
+
24
+ export function Boundary(props: BoundaryProps): any {
25
+ const error = createSignal<Error | null>(null);
26
+
27
+ const reset = () => error.set(null);
28
+
29
+ if (error()) {
30
+ return props.fallbackError
31
+ ? props.fallbackError({ error: error()!, reset })
32
+ : null;
33
+ }
34
+
35
+ try {
36
+ return props.children;
37
+ } catch (e) {
38
+ props.onError?.(e as Error);
39
+ error.set(e as Error);
40
+ return props.fallbackError
41
+ ? props.fallbackError({ error: e as Error, reset })
42
+ : null;
43
+ }
44
+ }
package/easing.ts CHANGED
@@ -1,66 +1,66 @@
1
- // A8: 15 standard easing functions (cubic bezier approximations)
2
- // All take t in [0, 1] and return eased value in [0, 1].
3
-
4
- export function linear(t: number): number {
5
- return t;
6
- }
7
-
8
- export function easeInQuad(t: number): number {
9
- return t * t;
10
- }
11
-
12
- export function easeOutQuad(t: number): number {
13
- return t * (2 - t);
14
- }
15
-
16
- export function easeInOutQuad(t: number): number {
17
- return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
18
- }
19
-
20
- export function easeInCubic(t: number): number {
21
- return t * t * t;
22
- }
23
-
24
- export function easeOutCubic(t: number): number {
25
- return --t * t * t + 1;
26
- }
27
-
28
- export function easeInOutCubic(t: number): number {
29
- return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
30
- }
31
-
32
- export function easeInQuart(t: number): number {
33
- return t * t * t * t;
34
- }
35
-
36
- export function easeOutQuart(t: number): number {
37
- return 1 - --t * t * t * t;
38
- }
39
-
40
- export function easeInOutQuart(t: number): number {
41
- return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
42
- }
43
-
44
- export function easeInQuint(t: number): number {
45
- return t * t * t * t * t;
46
- }
47
-
48
- export function easeOutQuint(t: number): number {
49
- return 1 + --t * t * t * t * t;
50
- }
51
-
52
- export function easeInOutQuint(t: number): number {
53
- return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
54
- }
55
-
56
- export function easeInSine(t: number): number {
57
- return 1 - Math.cos((t * Math.PI) / 2);
58
- }
59
-
60
- export function easeOutSine(t: number): number {
61
- return Math.sin((t * Math.PI) / 2);
62
- }
63
-
64
- export function easeInOutSine(t: number): number {
65
- return -(Math.cos(Math.PI * t) - 1) / 2;
66
- }
1
+ // A8: 15 standard easing functions (cubic bezier approximations)
2
+ // All take t in [0, 1] and return eased value in [0, 1].
3
+
4
+ export function linear(t: number): number {
5
+ return t;
6
+ }
7
+
8
+ export function easeInQuad(t: number): number {
9
+ return t * t;
10
+ }
11
+
12
+ export function easeOutQuad(t: number): number {
13
+ return t * (2 - t);
14
+ }
15
+
16
+ export function easeInOutQuad(t: number): number {
17
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
18
+ }
19
+
20
+ export function easeInCubic(t: number): number {
21
+ return t * t * t;
22
+ }
23
+
24
+ export function easeOutCubic(t: number): number {
25
+ return --t * t * t + 1;
26
+ }
27
+
28
+ export function easeInOutCubic(t: number): number {
29
+ return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
30
+ }
31
+
32
+ export function easeInQuart(t: number): number {
33
+ return t * t * t * t;
34
+ }
35
+
36
+ export function easeOutQuart(t: number): number {
37
+ return 1 - --t * t * t * t;
38
+ }
39
+
40
+ export function easeInOutQuart(t: number): number {
41
+ return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
42
+ }
43
+
44
+ export function easeInQuint(t: number): number {
45
+ return t * t * t * t * t;
46
+ }
47
+
48
+ export function easeOutQuint(t: number): number {
49
+ return 1 + --t * t * t * t * t;
50
+ }
51
+
52
+ export function easeInOutQuint(t: number): number {
53
+ return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
54
+ }
55
+
56
+ export function easeInSine(t: number): number {
57
+ return 1 - Math.cos((t * Math.PI) / 2);
58
+ }
59
+
60
+ export function easeOutSine(t: number): number {
61
+ return Math.sin((t * Math.PI) / 2);
62
+ }
63
+
64
+ export function easeInOutSine(t: number): number {
65
+ return -(Math.cos(Math.PI * t) - 1) / 2;
66
+ }