@ssgoi/react 4.0.0 → 4.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 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;
@@ -3,6 +3,13 @@ import { SsgoiConfig } from './types';
3
3
  interface SsgoiProps {
4
4
  config: SsgoiConfig;
5
5
  children: ReactNode;
6
+ /**
7
+ * Hook to get current pathname (e.g., Next.js usePathname)
8
+ * @example
9
+ * import { usePathname } from 'next/navigation';
10
+ * <Ssgoi config={config} usePathname={usePathname}>
11
+ */
12
+ usePathname?: () => string;
6
13
  }
7
14
  export declare const Ssgoi: React.FC<SsgoiProps>;
8
15
  export {};
@@ -1 +1,23 @@
1
+ import { CSSProperties } from 'react';
2
+ import { SsgoiContext } from '@ssgoi/core/types';
1
3
  export * from '@ssgoi/core/types';
4
+ /**
5
+ * Navigation info containing from/to paths
6
+ */
7
+ export type NavigationInfo = {
8
+ from: string | null;
9
+ to: string;
10
+ };
11
+ /**
12
+ * React-specific context type with style control
13
+ */
14
+ export type ReactSsgoiContext = {
15
+ /** Get transition config for a path */
16
+ getTransition: SsgoiContext;
17
+ /**
18
+ * Get initial style for an element
19
+ * Returns { visibility: "hidden" } on first call if transition is configured, {} otherwise
20
+ * Subsequent calls always return {} to prevent re-hiding on rerender
21
+ */
22
+ getInitialStyle: () => CSSProperties;
23
+ };
@@ -0,0 +1,10 @@
1
+ import { CSSProperties } from 'react';
2
+ /**
3
+ * Combines multiple ref callbacks into one
4
+ */
5
+ export declare function combineRefs<T>(...refs: Array<((el: T | null) => void) | null | undefined>): (el: T | null) => void;
6
+ /**
7
+ * Forks style from element.style based on initialStyle keys
8
+ * Returns the current DOM style values for keys that were in initialStyle
9
+ */
10
+ export declare function forkStyleFromElement(element: HTMLElement, initialStyle: CSSProperties): CSSProperties;
@@ -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 d=require("react/jsx-runtime"),r=require("react"),q=require("./transition.cjs"),b=require("./context.cjs"),o=require("./utils.cjs"),T=({children:c,id:i,as:u,className:l,...f})=>{const{getTransition:a,getInitialStyle:R}=b.useSsgoi(),S=u||"div",t=r.useRef(null),s=r.useRef(!0),e=r.useRef(null);e.current===null&&(e.current=R());let n;s.current?n=e.current:t.current&&e.current&&(n=o.forkStyleFromElement(t.current,e.current));const g=q.transition(a(i)),m=o.combineRefs(y=>{t.current=y,s.current=!1},g);return d.jsx(S,{ref:m,"data-ssgoi-transition":i,className:l,style:n,...f,children:c})};exports.SsgoiTransition=T;
@@ -1,26 +1,38 @@
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";
5
- const u = ({
6
- children: t,
2
+ import { jsx as g } from "react/jsx-runtime";
3
+ import { useRef as n } from "react";
4
+ import { transition as y } from "./transition.js";
5
+ import { useSsgoi as d } from "./context.js";
6
+ import { forkStyleFromElement as b, combineRefs as x } from "./utils.js";
7
+ const C = ({
8
+ children: s,
7
9
  id: o,
8
- as: n,
9
- className: i,
10
- ...r
10
+ as: c,
11
+ className: f,
12
+ ...l
11
13
  }) => {
12
- const s = a();
13
- return /* @__PURE__ */ m(
14
- n || "div",
14
+ const { getTransition: u, getInitialStyle: m } = d(), a = c || "div", r = n(null), i = n(!0), t = n(null);
15
+ t.current === null && (t.current = m());
16
+ let e;
17
+ i.current ? e = t.current : r.current && t.current && (e = b(
18
+ r.current,
19
+ t.current
20
+ ));
21
+ const R = y(u(o)), p = x((S) => {
22
+ r.current = S, i.current = !1;
23
+ }, R);
24
+ return /* @__PURE__ */ g(
25
+ a,
15
26
  {
16
- ref: e(s(o)),
27
+ ref: p,
17
28
  "data-ssgoi-transition": o,
18
- className: i,
19
- ...r,
20
- children: t
29
+ className: f,
30
+ style: e,
31
+ ...l,
32
+ children: s
21
33
  }
22
34
  );
23
35
  };
24
36
  export {
25
- u as SsgoiTransition
37
+ C as SsgoiTransition
26
38
  };
@@ -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 a=require("react/jsx-runtime"),o=require("react"),v=require("./context.cjs"),s=require("@ssgoi/core");function R(t){const n=o.useRef(null),e=o.useRef(null);t!==null&&n.current!==t&&(e.current=n.current,n.current=t);const r=o.useRef({from:null,to:""});return t!==null&&(r.current={from:e.current,to:t}),o.useCallback(()=>r.current,[])}function S(t){return{trigger(){},get(n){const{from:e,to:r}=t();return!e||!r||e===r?Promise.resolve(null):Promise.resolve({from:e,to:r})}}}const y=o.memo(({config:t,children:n,usePathname:e})=>{const r=e?.()??null,i=R(r),l=o.useMemo(()=>{const{getTransition:g,hasMatchingTransition:f}=s.createSggoiTransitionContext(t,{createNavigationDetector:e?()=>S(i):s.createAnyOrderDetector});return{getTransition:g,getInitialStyle:()=>{if(!e)return{};const{from:u,to:c}=i();return!u||u===c?{}:f(u,c)?{visibility:"hidden"}:{}}}},[t,e,i]);return a.jsx(v.SsgoiProvider,{value:l,children:n})});exports.Ssgoi=y;
@@ -1,19 +1,43 @@
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 g } from "react/jsx-runtime";
3
+ import a, { useMemo as m, useRef as c, useCallback as v } from "react";
4
+ import { SsgoiProvider as y } from "./context.js";
5
+ import { createSggoiTransitionContext as R, createAnyOrderDetector as S } from "@ssgoi/core";
6
+ function d(t) {
7
+ const n = c(null), r = c(null);
8
+ t !== null && n.current !== t && (r.current = n.current, n.current = t);
9
+ const e = c({ from: null, to: "" });
10
+ return t !== null && (e.current = { from: r.current, to: t }), v(() => e.current, []);
11
+ }
12
+ function p(t) {
13
+ return {
14
+ trigger() {
15
+ },
16
+ get(n) {
17
+ const { from: r, to: e } = t();
18
+ return !r || !e || r === e ? Promise.resolve(null) : Promise.resolve({ from: r, to: e });
19
+ }
20
+ };
21
+ }
22
+ const C = a.memo(
23
+ ({ config: t, children: n, usePathname: r }) => {
24
+ const e = r?.() ?? null, o = d(e), l = m(() => {
25
+ const { getTransition: s, hasMatchingTransition: f } = R(t, {
26
+ createNavigationDetector: r ? () => p(o) : S
27
+ });
28
+ return {
29
+ getTransition: s,
30
+ getInitialStyle: () => {
31
+ if (!r)
32
+ return {};
33
+ const { from: i, to: u } = o();
34
+ return !i || i === u ? {} : f(i, u) ? { visibility: "hidden" } : {};
35
+ }
36
+ };
37
+ }, [t, r, o]);
38
+ return /* @__PURE__ */ g(y, { value: l, children: n });
39
+ }
40
+ );
17
41
  export {
18
- f as Ssgoi
42
+ C as Ssgoi
19
43
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function f(...t){return o=>{t.forEach(e=>e?.(o))}}function c(t,o){const e={};for(const n of Object.keys(o)){const r=t.style[n];r&&(e[n]=r)}return e}exports.combineRefs=f;exports.forkStyleFromElement=c;
@@ -0,0 +1,17 @@
1
+ function f(...o) {
2
+ return (t) => {
3
+ o.forEach((e) => e?.(t));
4
+ };
5
+ }
6
+ function c(o, t) {
7
+ const e = {};
8
+ for (const n of Object.keys(t)) {
9
+ const r = o.style[n];
10
+ r && (e[n] = r);
11
+ }
12
+ return e;
13
+ }
14
+ export {
15
+ f as combineRefs,
16
+ c as forkStyleFromElement
17
+ };
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.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",
@@ -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",