@ssgoi/react 3.1.0 → 3.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.
@@ -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 a(n){return"tick"in n&&typeof n.tick=="function"}function o(n){if(s(n)&&a(n))throw new Error("SingleSpringConfig cannot have both 'tick' and 'css' defined. Use one or the other.")}function c(n){if(n.tick&&n.css)throw new Error("SpringItem cannot have both 'tick' and 'css' defined. Use one or the other.")}async function f(n){const i=await n;return r(i)?(i.springs.forEach(c),i):(o(i),{prepare:i.prepare,wait:i.wait,onStart:i.onStart,onEnd:i.onEnd,springs:[{spring:i.spring,tick:i.tick,css:i.css}],schedule:"parallel"})}function g(n){const i=n.schedule??"parallel",l=n.springs.map(t=>{let e;switch(i){case"parallel":e=0;break;case"sequential":e=1;break;case"stagger":e=Math.max(0,Math.min(1,t.offset??0));break;default:e=0}return{...t,normalizedOffset:e}}),{schedule:d,...u}=n;return{...u,springs:l}}exports.isCssAnimation=s;exports.isMultiSpring=r;exports.isSingleSpring=p;exports.isTickAnimation=a;exports.normalizeMultiSpringSchedule=g;exports.normalizeToMultiSpring=f;exports.validateAnimationMode=o;exports.validateSpringItem=c;
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,74 +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 a(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
- async function g(n) {
26
- const i = await n;
27
- return a(i) ? (i.springs.forEach(p), i) : (l(i), {
28
- prepare: i.prepare,
29
- wait: i.wait,
30
- onStart: i.onStart,
31
- onEnd: i.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,
32
32
  springs: [
33
33
  {
34
- spring: i.spring,
35
- tick: i.tick,
36
- css: i.css
34
+ spring: e.spring,
35
+ tick: e.tick,
36
+ css: e.css
37
37
  }
38
38
  ],
39
39
  schedule: "parallel"
40
40
  });
41
41
  }
42
- function h(n) {
43
- const i = n.schedule ?? "parallel", s = n.springs.map((e) => {
44
- let t;
45
- switch (i) {
46
- case "parallel":
47
- t = 0;
48
- break;
49
- case "sequential":
50
- t = 1;
51
- break;
52
- case "stagger":
53
- t = Math.max(0, Math.min(1, e.offset ?? 0));
54
- break;
55
- default:
56
- t = 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 };
57
61
  }
58
- return { ...e, normalizedOffset: t };
59
- }), { schedule: u, ...r } = n;
62
+ ), { schedule: h, ...o } = n;
60
63
  return {
61
- ...r,
62
- springs: s
64
+ ...o,
65
+ springs: a
63
66
  };
64
67
  }
65
68
  export {
66
- o as isCssAnimation,
67
- a as isMultiSpring,
68
- f as isSingleSpring,
69
- c as isTickAnimation,
70
- h as normalizeMultiSpringSchedule,
71
- g as normalizeToMultiSpring,
72
- l as validateAnimationMode,
73
- 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
74
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"),o=require("./react/src/lib/transition-scope.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;exports.TransitionScope=o.TransitionScope;
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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { transition as n } from "@ssgoi/core";
1
+ import { transition as n } from "./react/src/lib/transition.js";
2
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
3
  import { Ssgoi as f } from "./react/src/lib/ssgoi.js";
4
4
  import { SsgoiTransition as d } from "./react/src/lib/ssgoi-transition.js";
@@ -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 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
+ };
@@ -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.1.0",
3
+ "version": "3.2.1",
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,7 @@
45
45
  }
46
46
  },
47
47
  "dependencies": {
48
- "@ssgoi/core": "^3.1.0"
49
- },
50
- "peerDependencies": {
51
- "react": "^19.0.0",
52
- "react-dom": "^19.0.0"
48
+ "@ssgoi/core": "^3.2.0"
53
49
  },
54
50
  "devDependencies": {
55
51
  "@eslint/js": "^9.30.1",