@ssgoi/react 4.0.0 → 4.1.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 h(e){return("tick"in e||"css"in e)&&!("springs"in e)}function r(e){return"springs"in e}function o(e){return"css"in e&&typeof e.css=="function"}function c(e){return"tick"in e&&typeof e.tick=="function"}function a(e){if(o(e)&&c(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 t=await e;return r(t)?(t.springs.forEach(l),t):(a(t),{prepare:t.prepare,wait:t.wait,onStart:t.onStart,onEnd:t.onEnd,springs:[{physics:t.physics,tick:t.tick,css:t.css}],schedule:"parallel"})}function S(e,t){const u=e.schedule??"parallel",f=e.springs.map(s=>{let n;switch(u){case"parallel":n=0;break;case"sequential":n=1;break;case"stagger":n=Math.max(0,Math.min(1,s.offset??0));break;default:n=0}const{css:i,offset:y,...d}=s,g=i?typeof i=="function"?t?{element:t,style:i}:void 0:{element:i.element,style:i.style}:void 0;return{...d,css:g,normalizedOffset:n}}),{schedule:k,...p}=e;return{...p,springs:f}}exports.isCssAnimation=o;exports.isMultiSpring=r;exports.isSingleSpring=h;exports.isTickAnimation=c;exports.normalizeMultiSpringSchedule=S;exports.normalizeToMultiSpring=m;exports.validateAnimationMode=a;exports.validateSpringItem=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function m(e){return("tick"in e||"css"in e)&&!("items"in e)}function a(e){return"items"in e}function f(e){return"css"in e&&typeof e.css=="function"}function p(e){return"tick"in e&&typeof e.tick=="function"}async function d(e){const t=await e;return a(t)?{prepare:t.prepare,wait:t.wait,onStart:t.onStart,onEnd:t.onEnd,items:t.items,schedule:t.schedule}:{prepare:t.prepare,wait:t.wait,onStart:t.onStart,onEnd:t.onEnd,items:[{physics:t.physics,tick:t.tick,css:t.css}],schedule:"parallel"}}function h(e,t){const c=e.schedule??"parallel",o=e.items.map(s=>{let n;switch(c){case"parallel":n=0;break;case"sequential":n=1;break;case"stagger":n=Math.max(0,Math.min(1,s.offset??0));break;default:n=0}const{css:i,offset:k,...l}=s,u=i?typeof i=="function"?t?{element:t,style:i}:void 0:{element:i.element,style:i.style}:void 0;return{...l,css:u,normalizedOffset:n}}),{schedule:y,...r}=e;return{...r,items:o}}exports.isCssAnimation=f;exports.isMultiAnimation=a;exports.isSingleAnimation=m;exports.isTickAnimation=p;exports.normalizeSchedule=h;exports.normalizeToMultiAnimation=d;
@@ -1,49 +1,44 @@
1
- function k(n) {
2
- return ("tick" in n || "css" in n) && !("springs" in n);
1
+ function p(e) {
2
+ return ("tick" in e || "css" in e) && !("items" in e);
3
3
  }
4
- function f(n) {
5
- return "springs" in n;
4
+ function u(e) {
5
+ return "items" in e;
6
6
  }
7
- function p(n) {
8
- return "css" in n && typeof n.css == "function";
7
+ function d(e) {
8
+ return "css" in e && typeof e.css == "function";
9
9
  }
10
- function u(n) {
11
- return "tick" in n && typeof n.tick == "function";
10
+ function h(e) {
11
+ return "tick" in e && typeof e.tick == "function";
12
12
  }
13
- function h(n) {
14
- if (p(n) && u(n))
15
- throw new Error(
16
- "SingleSpringConfig cannot have both 'tick' and 'css' defined. Use one or the other."
17
- );
18
- }
19
- function d(n) {
20
- if (n.tick && n.css)
21
- throw new Error(
22
- "SpringItem cannot have both 'tick' and 'css' defined. Use one or the other."
23
- );
24
- }
25
- async function S(n) {
26
- const e = await n;
27
- return f(e) ? (e.springs.forEach(d), e) : (h(e), {
28
- prepare: e.prepare,
29
- wait: e.wait,
30
- onStart: e.onStart,
31
- onEnd: e.onEnd,
32
- springs: [
13
+ async function k(e) {
14
+ const n = await e;
15
+ return u(n) ? {
16
+ prepare: n.prepare,
17
+ wait: n.wait,
18
+ onStart: n.onStart,
19
+ onEnd: n.onEnd,
20
+ items: n.items,
21
+ schedule: n.schedule
22
+ } : {
23
+ prepare: n.prepare,
24
+ wait: n.wait,
25
+ onStart: n.onStart,
26
+ onEnd: n.onEnd,
27
+ items: [
33
28
  {
34
- physics: e.physics,
35
- tick: e.tick,
36
- css: e.css
29
+ physics: n.physics,
30
+ tick: n.tick,
31
+ css: n.css
37
32
  }
38
33
  ],
39
34
  schedule: "parallel"
40
- });
35
+ };
41
36
  }
42
- function y(n, e) {
43
- const r = n.schedule ?? "parallel", a = n.springs.map(
37
+ function y(e, n) {
38
+ const a = e.schedule ?? "parallel", c = e.items.map(
44
39
  (s) => {
45
40
  let t;
46
- switch (r) {
41
+ switch (a) {
47
42
  case "parallel":
48
43
  t = 0;
49
44
  break;
@@ -56,22 +51,20 @@ function y(n, e) {
56
51
  default:
57
52
  t = 0;
58
53
  }
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 };
54
+ const { css: i, offset: f, ...r } = s, l = i ? typeof i == "function" ? n ? { element: n, style: i } : void 0 : { element: i.element, style: i.style } : void 0;
55
+ return { ...r, css: l, normalizedOffset: t };
61
56
  }
62
- ), { schedule: g, ...o } = n;
57
+ ), { schedule: m, ...o } = e;
63
58
  return {
64
59
  ...o,
65
- springs: a
60
+ items: c
66
61
  };
67
62
  }
68
63
  export {
69
- p as isCssAnimation,
70
- f as isMultiSpring,
71
- k as isSingleSpring,
72
- u as isTickAnimation,
73
- y as normalizeMultiSpringSchedule,
74
- S as normalizeToMultiSpring,
75
- h as validateAnimationMode,
76
- d as validateSpringItem
64
+ d as isCssAnimation,
65
+ u as isMultiAnimation,
66
+ p as isSingleAnimation,
67
+ h as isTickAnimation,
68
+ y as normalizeSchedule,
69
+ k as normalizeToMultiAnimation
77
70
  };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./react/src/lib/transition.cjs"),i=require("./core/dist/types.cjs"),o=require("./react/src/lib/ssgoi.cjs"),t=require("./react/src/lib/ssgoi-transition.cjs"),s=require("./react/src/lib/transition-scope.cjs");exports.transition=n.transition;exports.isCssAnimation=i.isCssAnimation;exports.isMultiAnimation=i.isMultiAnimation;exports.isSingleAnimation=i.isSingleAnimation;exports.isTickAnimation=i.isTickAnimation;exports.normalizeSchedule=i.normalizeSchedule;exports.normalizeToMultiAnimation=i.normalizeToMultiAnimation;exports.Ssgoi=o.Ssgoi;exports.SsgoiTransition=t.SsgoiTransition;exports.TransitionScope=s.TransitionScope;
package/dist/index.js CHANGED
@@ -1,19 +1,17 @@
1
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";
2
+ import { isCssAnimation as r, isMultiAnimation as m, isSingleAnimation as e, isTickAnimation as s, normalizeSchedule as a, normalizeToMultiAnimation as l } from "./core/dist/types.js";
3
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";
4
+ import { SsgoiTransition as A } from "./react/src/lib/ssgoi-transition.js";
5
+ import { TransitionScope as T } from "./react/src/lib/transition-scope.js";
6
6
  export {
7
7
  f as Ssgoi,
8
- d as SsgoiTransition,
9
- M as TransitionScope,
10
- t as isCssAnimation,
11
- e as isMultiSpring,
12
- a as isSingleSpring,
13
- m as isTickAnimation,
14
- p as normalizeMultiSpringSchedule,
15
- s as normalizeToMultiSpring,
16
- n as transition,
17
- S as validateAnimationMode,
18
- l as validateSpringItem
8
+ A as SsgoiTransition,
9
+ T as TransitionScope,
10
+ r as isCssAnimation,
11
+ m as isMultiAnimation,
12
+ e as isSingleAnimation,
13
+ s as isTickAnimation,
14
+ a as normalizeSchedule,
15
+ l as normalizeToMultiAnimation,
16
+ n as transition
19
17
  };
@@ -1,3 +1,3 @@
1
- import { SsgoiContext } from './types';
2
- export declare const SsgoiProvider: import('react').Provider<SsgoiContext | null>;
3
- export declare const useSsgoi: () => SsgoiContext;
1
+ import { ReactSsgoiContext } from './types';
2
+ export declare const SsgoiProvider: import('react').Provider<ReactSsgoiContext | null>;
3
+ export declare const useSsgoi: () => ReactSsgoiContext;
@@ -0,0 +1,6 @@
1
+ import { NavigationDetector } from '@ssgoi/core';
2
+ /**
3
+ * Creates a NavigationDetector based on pathname changes
4
+ * Uses getPathname() to detect navigation without relying on IN/OUT callbacks
5
+ */
6
+ export declare function createPathnameDetector(getPathname: () => string): NavigationDetector;
@@ -1,9 +1,10 @@
1
- import { ReactNode, ElementType } from 'react';
1
+ import { ReactNode, ElementType, CSSProperties } from 'react';
2
2
  type SsgoiTransitionProps<T extends ElementType = "div"> = {
3
3
  children: ReactNode;
4
4
  id: string;
5
5
  as?: T;
6
6
  className?: string;
7
+ style?: CSSProperties;
7
8
  };
8
- export declare const SsgoiTransition: <T extends ElementType = "div">({ children, id, as, className, ...rest }: SsgoiTransitionProps<T>) => import("react/jsx-runtime").JSX.Element;
9
+ export declare const SsgoiTransition: <T extends ElementType = "div">({ children, id, as, className, style, ...rest }: SsgoiTransitionProps<T>) => import("react/jsx-runtime").JSX.Element;
9
10
  export {};
@@ -3,6 +3,12 @@ import { SsgoiConfig } from './types';
3
3
  interface SsgoiProps {
4
4
  config: SsgoiConfig;
5
5
  children: ReactNode;
6
+ /**
7
+ * Function to get current pathname
8
+ * Used to determine initial style and navigation detection
9
+ * @example Next.js: () => usePathname()
10
+ */
11
+ getPathname?: () => string;
6
12
  }
7
13
  export declare const Ssgoi: React.FC<SsgoiProps>;
8
14
  export {};
@@ -1 +1,15 @@
1
+ import { CSSProperties } from 'react';
2
+ import { SsgoiContext } from '@ssgoi/core/types';
1
3
  export * from '@ssgoi/core/types';
4
+ /**
5
+ * React-specific context type with style control
6
+ */
7
+ export type ReactSsgoiContext = {
8
+ /** Get transition config for a path */
9
+ getTransition: SsgoiContext;
10
+ /**
11
+ * Get initial style for an element
12
+ * Returns { visibility: "hidden" } if transition is configured, {} otherwise
13
+ */
14
+ getInitialStyle: (path: string) => CSSProperties;
15
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function s(o){let e=null,t=null,r=!1,l=!1;return{trigger(){},get(u){const n=o();if(!t||r&&l){if(!e||e===n)return e=n,Promise.resolve(null);t={from:e,to:n},r=!1,l=!1}u==="out"?r=!0:l=!0;const a=t;return r&&l&&(e=n,t=null),Promise.resolve(a)}}}exports.createPathnameDetector=s;
@@ -0,0 +1,24 @@
1
+ function s(u) {
2
+ let e = null, t = null, r = !1, l = !1;
3
+ return {
4
+ trigger() {
5
+ },
6
+ get(o) {
7
+ const n = u();
8
+ if (!t || r && l) {
9
+ if (!e || e === n)
10
+ return e = n, Promise.resolve(null);
11
+ t = {
12
+ from: e,
13
+ to: n
14
+ }, r = !1, l = !1;
15
+ }
16
+ o === "out" ? r = !0 : l = !0;
17
+ const a = t;
18
+ return r && l && (e = n, t = null), Promise.resolve(a);
19
+ }
20
+ };
21
+ }
22
+ export {
23
+ s as createPathnameDetector
24
+ };
@@ -1,2 +1,2 @@
1
1
  "use client";
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;
2
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),l=require("./transition.cjs"),S=require("./context.cjs"),y=({children:n,id:t,as:i,className:e,style:o,...s})=>{const{getTransition:r,getInitialStyle:a}=S.useSsgoi(),c=i||"div",u=a(t);return g.jsx(c,{ref:l.transition(r(t)),"data-ssgoi-transition":t,className:e,style:{...o,...u},...s,children:n})};exports.SsgoiTransition=y;
@@ -1,23 +1,25 @@
1
1
  "use client";
2
- import { jsx as m } from "react/jsx-runtime";
3
- import { transition as e } from "./transition.js";
4
- import { useSsgoi as a } from "./context.js";
2
+ import { jsx as l } from "react/jsx-runtime";
3
+ import { transition as p } from "./transition.js";
4
+ import { useSsgoi as c } from "./context.js";
5
5
  const u = ({
6
- children: t,
7
- id: o,
8
- as: n,
9
- className: i,
6
+ children: o,
7
+ id: t,
8
+ as: i,
9
+ className: n,
10
+ style: s,
10
11
  ...r
11
12
  }) => {
12
- const s = a();
13
- return /* @__PURE__ */ m(
14
- n || "div",
13
+ const { getTransition: e, getInitialStyle: a } = c(), m = i || "div", g = a(t);
14
+ return /* @__PURE__ */ l(
15
+ m,
15
16
  {
16
- ref: e(s(o)),
17
- "data-ssgoi-transition": o,
18
- className: i,
17
+ ref: p(e(t)),
18
+ "data-ssgoi-transition": t,
19
+ className: n,
20
+ style: { ...s, ...g },
19
21
  ...r,
20
- children: t
22
+ children: o
21
23
  }
22
24
  );
23
25
  };
@@ -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"),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;
2
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),n=require("react"),g=require("./context.cjs"),i=require("@ssgoi/core"),d=require("./create-pathname-detector.cjs"),m=n.memo(({config:o,children:c,getPathname:e})=>{const t=n.useRef(null),s=n.useMemo(()=>{const{getTransition:u,hasMatchingTransition:a}=i.createSggoiTransitionContext(o,{outFirst:!1,createNavigationDetector:e?()=>d.createPathnameDetector(e):i.createAnyOrderDetector});return{getTransition:u,getInitialStyle:l=>{if(!e)return{};const r=e();if(!t.current||t.current===r)return t.current=r,{};const S=t.current;return t.current=r,a(S,l)?{visibility:"hidden"}:{}}}},[o,e]);return f.jsx(g.SsgoiProvider,{value:s,children:c})});exports.Ssgoi=m;
@@ -1,19 +1,36 @@
1
1
  "use client";
2
- import { jsx as e } from "react/jsx-runtime";
3
- import { useMemo as i } from "react";
4
- import { SsgoiProvider as m } from "./context.js";
5
- import { createSggoiTransitionContext as s } from "@ssgoi/core";
6
- const f = ({ config: o, children: r }) => {
7
- const t = i(
8
- () => s(o, {
9
- // React uses MutationObserver for unmount detection,
10
- // so OUT and IN can arrive in any order
11
- outFirst: !1
12
- }),
13
- [o]
14
- );
15
- return /* @__PURE__ */ e(m, { value: t, children: r });
16
- };
2
+ import { jsx as m } from "react/jsx-runtime";
3
+ import f, { useRef as l, useMemo as p } from "react";
4
+ import { SsgoiProvider as v } from "./context.js";
5
+ import { createSggoiTransitionContext as S, createAnyOrderDetector as d } from "@ssgoi/core";
6
+ import { createPathnameDetector as g } from "./create-pathname-detector.js";
7
+ const I = f.memo(
8
+ ({ config: o, children: n, getPathname: r }) => {
9
+ const t = l(null), i = p(() => {
10
+ const { getTransition: c, hasMatchingTransition: s } = S(o, {
11
+ // React uses MutationObserver for unmount detection,
12
+ // so OUT and IN can arrive in any order
13
+ outFirst: !1,
14
+ // Use pathname-based detector when getPathname is provided,
15
+ // otherwise use default any-order detector for React
16
+ createNavigationDetector: r ? () => g(r) : d
17
+ });
18
+ return {
19
+ getTransition: c,
20
+ getInitialStyle: (u) => {
21
+ if (!r)
22
+ return {};
23
+ const e = r();
24
+ if (!t.current || t.current === e)
25
+ return t.current = e, {};
26
+ const a = t.current;
27
+ return t.current = e, s(a, u) ? { visibility: "hidden" } : {};
28
+ }
29
+ };
30
+ }, [o, r]);
31
+ return /* @__PURE__ */ m(v, { value: i, children: n });
32
+ }
33
+ );
17
34
  export {
18
- f as Ssgoi
35
+ I as Ssgoi
19
36
  };
package/dist/types.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./core/dist/types.cjs");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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./core/dist/types.cjs");exports.isCssAnimation=i.isCssAnimation;exports.isMultiAnimation=i.isMultiAnimation;exports.isSingleAnimation=i.isSingleAnimation;exports.isTickAnimation=i.isTickAnimation;exports.normalizeSchedule=i.normalizeSchedule;exports.normalizeToMultiAnimation=i.normalizeToMultiAnimation;
package/dist/types.js CHANGED
@@ -1,11 +1,9 @@
1
- import { isCssAnimation as e, isMultiSpring as t, isSingleSpring as a, isTickAnimation as l, normalizeMultiSpringSchedule as o, normalizeToMultiSpring as r, validateAnimationMode as m, validateSpringItem as S } from "./core/dist/types.js";
1
+ import { isCssAnimation as o, isMultiAnimation as m, isSingleAnimation as t, isTickAnimation as a, normalizeSchedule as e, normalizeToMultiAnimation as l } from "./core/dist/types.js";
2
2
  export {
3
- e as isCssAnimation,
4
- t as isMultiSpring,
5
- a as isSingleSpring,
6
- l as isTickAnimation,
7
- o as normalizeMultiSpringSchedule,
8
- r as normalizeToMultiSpring,
9
- m as validateAnimationMode,
10
- S as validateSpringItem
3
+ o as isCssAnimation,
4
+ m as isMultiAnimation,
5
+ t as isSingleAnimation,
6
+ a as isTickAnimation,
7
+ e as normalizeSchedule,
8
+ l as normalizeToMultiAnimation
11
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssgoi/react",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "React bindings for SSGOI - Native app-like page transitions for React applications",
5
5
  "private": false,
6
6
  "type": "module",
@@ -78,7 +78,7 @@
78
78
  "dependencies": {
79
79
  "unplugin": "^2.3.2",
80
80
  "@babel/core": "^7.26.10",
81
- "@ssgoi/core": "^4.0.0"
81
+ "@ssgoi/core": "^4.2.0"
82
82
  },
83
83
  "devDependencies": {
84
84
  "@types/babel__core": "^7.20.5",