@ssgoi/react 3.0.0 → 3.2.0

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function p(n){return("tick"in n||"css"in n)&&!("springs"in n)}function r(n){return"springs"in n}function s(n){return"css"in n&&typeof n.css=="function"}function e(n){return"tick"in n&&typeof n.tick=="function"}function o(n){if(s(n)&&e(n))throw new Error("SingleSpringConfig cannot have both 'tick' and 'css' defined. Use one or the other.")}function a(n){if(n.tick&&n.css)throw new Error("SpringItem cannot have both 'tick' and 'css' defined. Use one or the other.")}function f(n){return r(n)?(n.springs.forEach(a),n):(o(n),{prepare:n.prepare,wait:n.wait,onStart:n.onStart,onEnd:n.onEnd,springs:[{spring:n.spring,tick:n.tick,css:n.css}],schedule:"parallel"})}function g(n){const c=n.schedule??"parallel",l=n.springs.map(t=>{let i;switch(c){case"parallel":i=0;break;case"sequential":i=1;break;case"stagger":i=Math.max(0,Math.min(1,t.offset??0));break;default:i=0}return{...t,normalizedOffset:i}}),{schedule:d,...u}=n;return{...u,springs:l}}exports.isCssAnimation=s;exports.isMultiSpring=r;exports.isSingleSpring=p;exports.isTickAnimation=e;exports.normalizeMultiSpringSchedule=g;exports.normalizeToMultiSpring=f;exports.validateAnimationMode=o;exports.validateSpringItem=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function h(e){return("tick"in e||"css"in e)&&!("springs"in e)}function s(e){return"springs"in e}function o(e){return"css"in e&&typeof e.css=="function"}function a(e){return"tick"in e&&typeof e.tick=="function"}function c(e){if(o(e)&&a(e))throw new Error("SingleSpringConfig cannot have both 'tick' and 'css' defined. Use one or the other.")}function l(e){if(e.tick&&e.css)throw new Error("SpringItem cannot have both 'tick' and 'css' defined. Use one or the other.")}async function m(e){const n=await e;return s(n)?(n.springs.forEach(l),n):(c(n),{prepare:n.prepare,wait:n.wait,onStart:n.onStart,onEnd:n.onEnd,springs:[{spring:n.spring,tick:n.tick,css:n.css}],schedule:"parallel"})}function S(e,n){const u=e.schedule??"parallel",f=e.springs.map(r=>{let t;switch(u){case"parallel":t=0;break;case"sequential":t=1;break;case"stagger":t=Math.max(0,Math.min(1,r.offset??0));break;default:t=0}const{css:i,offset:w,...g}=r,d=i?typeof i=="function"?n?{element:n,style:i}:void 0:{element:i.element,style:i.style}:void 0;return{...g,css:d,normalizedOffset:t}}),{schedule:k,...p}=e;return{...p,springs:f}}exports.isCssAnimation=o;exports.isMultiSpring=s;exports.isSingleSpring=h;exports.isTickAnimation=a;exports.normalizeMultiSpringSchedule=S;exports.normalizeToMultiSpring=m;exports.validateAnimationMode=c;exports.validateSpringItem=l;
@@ -1,73 +1,77 @@
1
- function f(n) {
1
+ function k(n) {
2
2
  return ("tick" in n || "css" in n) && !("springs" in n);
3
3
  }
4
- function e(n) {
4
+ function f(n) {
5
5
  return "springs" in n;
6
6
  }
7
- function o(n) {
7
+ function p(n) {
8
8
  return "css" in n && typeof n.css == "function";
9
9
  }
10
- function c(n) {
10
+ function u(n) {
11
11
  return "tick" in n && typeof n.tick == "function";
12
12
  }
13
- function l(n) {
14
- if (o(n) && c(n))
13
+ function g(n) {
14
+ if (p(n) && u(n))
15
15
  throw new Error(
16
16
  "SingleSpringConfig cannot have both 'tick' and 'css' defined. Use one or the other."
17
17
  );
18
18
  }
19
- function p(n) {
19
+ function d(n) {
20
20
  if (n.tick && n.css)
21
21
  throw new Error(
22
22
  "SpringItem cannot have both 'tick' and 'css' defined. Use one or the other."
23
23
  );
24
24
  }
25
- function g(n) {
26
- return e(n) ? (n.springs.forEach(p), n) : (l(n), {
27
- prepare: n.prepare,
28
- wait: n.wait,
29
- onStart: n.onStart,
30
- onEnd: n.onEnd,
25
+ async function S(n) {
26
+ const e = await n;
27
+ return f(e) ? (e.springs.forEach(d), e) : (g(e), {
28
+ prepare: e.prepare,
29
+ wait: e.wait,
30
+ onStart: e.onStart,
31
+ onEnd: e.onEnd,
31
32
  springs: [
32
33
  {
33
- spring: n.spring,
34
- tick: n.tick,
35
- css: n.css
34
+ spring: e.spring,
35
+ tick: e.tick,
36
+ css: e.css
36
37
  }
37
38
  ],
38
39
  schedule: "parallel"
39
40
  });
40
41
  }
41
- function h(n) {
42
- const r = n.schedule ?? "parallel", s = n.springs.map((t) => {
43
- let i;
44
- switch (r) {
45
- case "parallel":
46
- i = 0;
47
- break;
48
- case "sequential":
49
- i = 1;
50
- break;
51
- case "stagger":
52
- i = Math.max(0, Math.min(1, t.offset ?? 0));
53
- break;
54
- default:
55
- i = 0;
42
+ function w(n, e) {
43
+ const r = n.schedule ?? "parallel", a = n.springs.map(
44
+ (s) => {
45
+ let t;
46
+ switch (r) {
47
+ case "parallel":
48
+ t = 0;
49
+ break;
50
+ case "sequential":
51
+ t = 1;
52
+ break;
53
+ case "stagger":
54
+ t = Math.max(0, Math.min(1, s.offset ?? 0));
55
+ break;
56
+ default:
57
+ t = 0;
58
+ }
59
+ const { css: i, offset: m, ...c } = s, l = i ? typeof i == "function" ? e ? { element: e, style: i } : void 0 : { element: i.element, style: i.style } : void 0;
60
+ return { ...c, css: l, normalizedOffset: t };
56
61
  }
57
- return { ...t, normalizedOffset: i };
58
- }), { schedule: u, ...a } = n;
62
+ ), { schedule: h, ...o } = n;
59
63
  return {
60
- ...a,
61
- springs: s
64
+ ...o,
65
+ springs: a
62
66
  };
63
67
  }
64
68
  export {
65
- o as isCssAnimation,
66
- e as isMultiSpring,
67
- f as isSingleSpring,
68
- c as isTickAnimation,
69
- h as normalizeMultiSpringSchedule,
70
- g as normalizeToMultiSpring,
71
- l as validateAnimationMode,
72
- p as validateSpringItem
69
+ p as isCssAnimation,
70
+ f as isMultiSpring,
71
+ k as isSingleSpring,
72
+ u as isTickAnimation,
73
+ w as normalizeMultiSpringSchedule,
74
+ S as normalizeToMultiSpring,
75
+ g as validateAnimationMode,
76
+ d as validateSpringItem
73
77
  };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@ssgoi/core"),i=require("./core/dist/types.cjs"),e=require("./react/src/lib/ssgoi.cjs"),t=require("./react/src/lib/ssgoi-transition.cjs");Object.defineProperty(exports,"transition",{enumerable:!0,get:()=>n.transition});exports.isCssAnimation=i.isCssAnimation;exports.isMultiSpring=i.isMultiSpring;exports.isSingleSpring=i.isSingleSpring;exports.isTickAnimation=i.isTickAnimation;exports.normalizeMultiSpringSchedule=i.normalizeMultiSpringSchedule;exports.normalizeToMultiSpring=i.normalizeToMultiSpring;exports.validateAnimationMode=i.validateAnimationMode;exports.validateSpringItem=i.validateSpringItem;exports.Ssgoi=e.Ssgoi;exports.SsgoiTransition=t.SsgoiTransition;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./react/src/lib/transition.cjs"),i=require("./core/dist/types.cjs"),t=require("./react/src/lib/ssgoi.cjs"),o=require("./react/src/lib/ssgoi-transition.cjs"),e=require("./react/src/lib/transition-scope.cjs");exports.transition=n.transition;exports.isCssAnimation=i.isCssAnimation;exports.isMultiSpring=i.isMultiSpring;exports.isSingleSpring=i.isSingleSpring;exports.isTickAnimation=i.isTickAnimation;exports.normalizeMultiSpringSchedule=i.normalizeMultiSpringSchedule;exports.normalizeToMultiSpring=i.normalizeToMultiSpring;exports.validateAnimationMode=i.validateAnimationMode;exports.validateSpringItem=i.validateSpringItem;exports.Ssgoi=t.Ssgoi;exports.SsgoiTransition=o.SsgoiTransition;exports.TransitionScope=e.TransitionScope;
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export { transition } from './transition';
2
2
  export * from './types';
3
3
  export { Ssgoi } from './ssgoi';
4
4
  export { SsgoiTransition } from './ssgoi-transition';
5
+ export { TransitionScope } from './transition-scope';
package/dist/index.js CHANGED
@@ -1,17 +1,19 @@
1
- import { transition as n } from "@ssgoi/core";
2
- import { isCssAnimation as t, isMultiSpring as e, isSingleSpring as a, isTickAnimation as m, normalizeMultiSpringSchedule as s, normalizeToMultiSpring as l, validateAnimationMode as p, validateSpringItem as S } from "./core/dist/types.js";
3
- import { Ssgoi as d } from "./react/src/lib/ssgoi.js";
4
- import { SsgoiTransition as u } from "./react/src/lib/ssgoi-transition.js";
1
+ import { transition as n } from "./react/src/lib/transition.js";
2
+ import { isCssAnimation as t, isMultiSpring as e, isSingleSpring as a, isTickAnimation as m, normalizeMultiSpringSchedule as p, normalizeToMultiSpring as s, validateAnimationMode as S, validateSpringItem as l } from "./core/dist/types.js";
3
+ import { Ssgoi as f } from "./react/src/lib/ssgoi.js";
4
+ import { SsgoiTransition as d } from "./react/src/lib/ssgoi-transition.js";
5
+ import { TransitionScope as M } from "./react/src/lib/transition-scope.js";
5
6
  export {
6
- d as Ssgoi,
7
- u as SsgoiTransition,
7
+ f as Ssgoi,
8
+ d as SsgoiTransition,
9
+ M as TransitionScope,
8
10
  t as isCssAnimation,
9
11
  e as isMultiSpring,
10
12
  a as isSingleSpring,
11
13
  m as isTickAnimation,
12
- s as normalizeMultiSpringSchedule,
13
- l as normalizeToMultiSpring,
14
+ p as normalizeMultiSpringSchedule,
15
+ s as normalizeToMultiSpring,
14
16
  n as transition,
15
- p as validateAnimationMode,
16
- S as validateSpringItem
17
+ S as validateAnimationMode,
18
+ l as validateSpringItem
17
19
  };
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),a=require("@ssgoi/core"),u=require("./context.cjs"),g=({children:n,id:t,as:o,className:e,...i})=>{const s=u.useSsgoi(),r=o||"div";return c.jsx(r,{ref:a.transition(s(t)),"data-ssgoi-transition":t,className:e,...i,children:n})};exports.SsgoiTransition=g;
2
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),c=require("./transition.cjs"),u=require("./context.cjs"),g=({children:n,id:t,as:i,className:o,...s})=>{const e=u.useSsgoi(),r=i||"div";return a.jsx(r,{ref:c.transition(e(t)),"data-ssgoi-transition":t,className:o,...s,children:n})};exports.SsgoiTransition=g;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as m } from "react/jsx-runtime";
3
- import { transition as e } from "@ssgoi/core";
3
+ import { transition as e } from "./transition.js";
4
4
  import { useSsgoi as a } from "./context.js";
5
5
  const u = ({
6
6
  children: t,
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),s=require("react"),i=require("./context.cjs"),n=require("@ssgoi/core"),c=({config:e,children:t})=>{const o=s.useMemo(()=>n.createSggoiTransitionContext(e),[e]);return r.jsx(i.SsgoiProvider,{value:o,children:t})};exports.Ssgoi=c;
2
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),s=require("react"),i=require("./context.cjs"),n=require("@ssgoi/core"),u=({config:e,children:t})=>{const o=s.useMemo(()=>n.createSggoiTransitionContext(e,{outFirst:!1}),[e]);return r.jsx(i.SsgoiProvider,{value:o,children:t})};exports.Ssgoi=u;
@@ -3,13 +3,17 @@ import { jsx as e } from "react/jsx-runtime";
3
3
  import { useMemo as i } from "react";
4
4
  import { SsgoiProvider as m } from "./context.js";
5
5
  import { createSggoiTransitionContext as s } from "@ssgoi/core";
6
- const x = ({ config: o, children: r }) => {
6
+ const f = ({ config: o, children: r }) => {
7
7
  const t = i(
8
- () => s(o),
8
+ () => s(o, {
9
+ // React uses MutationObserver for unmount detection,
10
+ // so OUT and IN can arrive in any order
11
+ outFirst: !1
12
+ }),
9
13
  [o]
10
14
  );
11
15
  return /* @__PURE__ */ e(m, { value: t, children: r });
12
16
  };
13
17
  export {
14
- x as Ssgoi
18
+ f as Ssgoi
15
19
  };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),n=require("@ssgoi/core");function r({children:e}){return t.jsx("div",{ref:n.createTransitionScope(),style:{display:"contents"},children:e})}exports.TransitionScope=r;
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import { jsx as r } from "react/jsx-runtime";
3
+ import { createTransitionScope as t } from "@ssgoi/core";
4
+ function n({ children: o }) {
5
+ return /* @__PURE__ */ r("div", { ref: t(), style: { display: "contents" }, children: o });
6
+ }
7
+ export {
8
+ n as TransitionScope
9
+ };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@ssgoi/core"),c=i=>{const r=o.transition(i);return t=>{if(t){const n=r(t);n&&o.watchUnmount(t,n)}}};exports.transition=c;
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import { transition as a, watchUnmount as r } from "@ssgoi/core";
3
+ const s = (o) => {
4
+ const i = a(o);
5
+ return (t) => {
6
+ if (t) {
7
+ const n = i(t);
8
+ n && r(t, n);
9
+ }
10
+ };
11
+ };
12
+ export {
13
+ s as transition
14
+ };
@@ -0,0 +1,28 @@
1
+ import { ReactNode } from 'react';
2
+ type TransitionScopeProps = {
3
+ children: ReactNode;
4
+ };
5
+ /**
6
+ * TransitionScope creates a boundary for local-scoped transitions.
7
+ *
8
+ * Child elements with `scope: 'local'` will:
9
+ * - Skip IN animation when mounted simultaneously with the scope
10
+ * - Skip OUT animation when unmounted simultaneously with the scope
11
+ *
12
+ * This is useful for:
13
+ * - Page transitions where child elements shouldn't animate individually
14
+ * - Modal/dialog content that appears/disappears with the container
15
+ * - List items that shouldn't animate when the entire list mounts/unmounts
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * <TransitionScope>
20
+ * <div ref={transition(fadeIn(), { scope: 'local' })}>
21
+ * This will only animate when added/removed independently,
22
+ * not when the entire scope mounts/unmounts.
23
+ * </div>
24
+ * </TransitionScope>
25
+ * ```
26
+ */
27
+ export declare function TransitionScope({ children }: TransitionScopeProps): import("react/jsx-runtime").JSX.Element;
28
+ export {};
@@ -1 +1,23 @@
1
- export { transition } from '@ssgoi/core';
1
+ import { Transition, TransitionKey, TransitionScope } from '@ssgoi/core';
2
+ type TransitionOptions = Transition<undefined> & {
3
+ key?: TransitionKey;
4
+ scope?: TransitionScope;
5
+ ref?: object;
6
+ };
7
+ /**
8
+ * React ref callback for element transitions
9
+ *
10
+ * OUT transition is automatically triggered by MutationObserver
11
+ * when the element is removed from the DOM - works with React 18+
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * <div ref={transition({
16
+ * key: 'fade',
17
+ * in: (el) => ({ tick: (p) => el.style.opacity = String(p) }),
18
+ * out: (el) => ({ tick: (p) => el.style.opacity = String(p) }),
19
+ * })} />
20
+ * ```
21
+ */
22
+ export declare const transition: (options: TransitionOptions) => (element: HTMLElement | null) => void;
23
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssgoi/react",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "React bindings for SSGOI - Native app-like page transitions for React applications",
5
5
  "private": false,
6
6
  "type": "module",
@@ -45,11 +45,11 @@
45
45
  }
46
46
  },
47
47
  "dependencies": {
48
- "@ssgoi/core": "^3.0.0"
48
+ "@ssgoi/core": "^3.2.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "react": "^19.0.0",
52
- "react-dom": "^19.0.0"
51
+ "react": "^18.0.0",
52
+ "react-dom": "^18.0.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@eslint/js": "^9.30.1",