@mks2508/mks-ui 0.6.5 → 0.6.6

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,3 +1,4 @@
1
+ import './useViewTransitions.module.css';
1
2
  import type { IViewTransitionsOptions, IViewTransitionsAPI } from '../Morph.types';
2
3
  /**
3
4
  * Hook for the View Transitions API.
@@ -10,18 +11,25 @@ import type { IViewTransitionsOptions, IViewTransitionsAPI } from '../Morph.type
10
11
  * - Firefox 144+
11
12
  * - Safari latest
12
13
  *
13
- * @param options - Optional view transition name and types
14
+ * View transition styles are applied via CSS module, eliminating
15
+ * the need for runtime style injection. Elements should have
16
+ * `view-transition-name` applied via inline style or CSS class.
17
+ *
18
+ * @param options - Optional view transition name (deprecated, use inline style)
14
19
  * @returns View Transitions API with support detection and transition trigger
15
20
  *
16
21
  * @example
17
22
  * ```tsx
18
- * const { isSupported, startTransition } = useViewTransitions({ name: 'hero' });
23
+ * const { isSupported, startTransition } = useViewTransitions();
19
24
  *
20
25
  * const handleTransition = async () => {
21
26
  * await startTransition(() => {
22
27
  * setActiveImage(nextImage);
23
28
  * });
24
29
  * };
30
+ *
31
+ * // Apply view-transition-name to elements
32
+ * <div style={{ viewTransitionName: 'hero' }}>...</div>
25
33
  * ```
26
34
  */
27
35
  export declare function useViewTransitions(options?: IViewTransitionsOptions): IViewTransitionsAPI;
@@ -1 +1 @@
1
- {"version":3,"file":"useViewTransitions.d.ts","sourceRoot":"","sources":["../../../../../../src/react-ui/primitives/waapi/Morph/techniques/useViewTransitions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEnF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,mBAAmB,CAyDzF"}
1
+ {"version":3,"file":"useViewTransitions.d.ts","sourceRoot":"","sources":["../../../../../../src/react-ui/primitives/waapi/Morph/techniques/useViewTransitions.ts"],"names":[],"mappings":"AAGA,OAAO,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,mBAAmB,CAoCzF"}
@@ -1,5 +1,6 @@
1
1
  'use client';
2
2
 
3
+ import "./useViewTransitions.module.js";
3
4
  import { useCallback, useMemo, useRef } from "react";
4
5
 
5
6
  //#region src/react-ui/primitives/waapi/Morph/techniques/useViewTransitions.ts
@@ -14,22 +15,29 @@ import { useCallback, useMemo, useRef } from "react";
14
15
  * - Firefox 144+
15
16
  * - Safari latest
16
17
  *
17
- * @param options - Optional view transition name and types
18
+ * View transition styles are applied via CSS module, eliminating
19
+ * the need for runtime style injection. Elements should have
20
+ * `view-transition-name` applied via inline style or CSS class.
21
+ *
22
+ * @param options - Optional view transition name (deprecated, use inline style)
18
23
  * @returns View Transitions API with support detection and transition trigger
19
24
  *
20
25
  * @example
21
26
  * ```tsx
22
- * const { isSupported, startTransition } = useViewTransitions({ name: 'hero' });
27
+ * const { isSupported, startTransition } = useViewTransitions();
23
28
  *
24
29
  * const handleTransition = async () => {
25
30
  * await startTransition(() => {
26
31
  * setActiveImage(nextImage);
27
32
  * });
28
33
  * };
34
+ *
35
+ * // Apply view-transition-name to elements
36
+ * <div style={{ viewTransitionName: 'hero' }}>...</div>
29
37
  * ```
30
38
  */
31
39
  function useViewTransitions(options) {
32
- const optionsRef = useRef(options);
40
+ useRef(options);
33
41
  const typesRef = useRef(options?.types || []);
34
42
  const isSupported = useMemo(() => {
35
43
  if (typeof document === "undefined") return false;
@@ -45,30 +53,10 @@ function useViewTransitions(options) {
45
53
  await callback();
46
54
  return;
47
55
  }
48
- const viewTransitionName = optionsRef.current?.name;
49
- const setupStyles = () => {
50
- if (viewTransitionName) {
51
- const styleEl = document.createElement("style");
52
- styleEl.id = `view-transition-${viewTransitionName}`;
53
- styleEl.textContent = `
54
- ::view-transition-old(${viewTransitionName}),
55
- ::view-transition-new(${viewTransitionName}) {
56
- animation-duration: 300ms;
57
- animation-timing-function: ease-out;
58
- }
59
- `;
60
- document.head.appendChild(styleEl);
61
- return () => {
62
- styleEl.remove();
63
- };
64
- }
65
- return () => {};
66
- };
67
- const cleanup = setupStyles();
68
56
  try {
69
57
  await document.startViewTransition(callback).finished;
70
- } finally {
71
- cleanup();
58
+ } catch (error) {
59
+ await callback();
72
60
  }
73
61
  }, []),
74
62
  setTypes
@@ -0,0 +1,20 @@
1
+ /**
2
+ * View Transitions API - Default transition styles.
3
+ *
4
+ * These styles apply to all view-transition pseudo-elements by default,
5
+ * eliminating the need for dynamic style injection based on transition names.
6
+ *
7
+ * Usage: Apply `view-transition-name` via inline style or CSS variable:
8
+ * <div style={{ viewTransitionName: 'hero' }}>...</div>
9
+ *
10
+ * Or via CSS:
11
+ * .my-element { view-transition-name: hero; }
12
+ */
13
+
14
+ /* Default animation for all view transitions */
15
+ ::view-transition-old(*),
16
+ ::view-transition-new(*) {
17
+ animation-duration: 300ms;
18
+ animation-timing-function: ease-out;
19
+ }
20
+
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Tabs CSS Anchor Positioning.
3
+ *
4
+ * Zero-JS position tracking for the sliding indicator using CSS Anchor API.
5
+ * The indicator automatically follows the active tab via anchor positioning.
6
+ */
7
+
8
+ /* Scope anchors per Tabs instance */
9
+ [data-slot="tabs-list"] {
10
+ anchor-scope: --tabs-active;
11
+ }
12
+
13
+ /* Active tab becomes the anchor */
14
+ [data-slot="tabs-tab"][data-active] {
15
+ anchor-name: --tabs-active;
16
+ }
17
+
18
+ /* Indicator follows the active anchor */
19
+ [data-slot="tabs-indicator"] {
20
+ position-anchor: --tabs-active;
21
+ left: anchor(left);
22
+ right: anchor(right);
23
+ transition:
24
+ top 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
25
+ left 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
26
+ right 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
27
+ bottom 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
28
+ width 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
29
+ height 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
30
+ }
31
+
32
+ /* Respect reduced motion preference */
33
+ @media (prefers-reduced-motion: reduce) {
34
+ [data-slot="tabs-indicator"] {
35
+ transition-duration: 0ms;
36
+ }
37
+ }
38
+
File without changes
@@ -1,4 +1,5 @@
1
1
  import { tabsListVariants, tabsTabVariants, tabsIndicatorVariants } from './Tabs.styles';
2
+ import './Tabs.module.css';
2
3
  import type { ITabsProps, ITabsHighlightProps, ITabsHighlightItemProps, ITabsListProps, ITabsTabProps, ITabsPanelProps, ITabsPanelsProps } from './Tabs.types';
3
4
  /**
4
5
  * Root Tabs component -- provides active tab value context and
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/react-ui/ui/Tabs/index.tsx"],"names":[],"mappings":"AAoEA,OAAO,EAEL,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACtB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAEV,UAAU,EACV,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,aAAa,EACb,eAAe,EACf,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AAgDtB;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,UAAU,2CAiB/D;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,aAAa,CAAC,EACrB,UAA4D,EAC5D,KAAK,EACL,SAAS,EACT,GAAG,KAAK,EACT,EAAE,mBAAmB,2CAcrB;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,QAAQ,CAAC,EAChB,OAAO,EACP,IAAI,EACJ,SAAS,EACT,KAAK,EACL,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,cAAc,2CA+BhB;AAMD;;;;;;;;;;;;;;GAcG;AACH,iBAAS,iBAAiB,CAAC,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,uBAAuB,2CAEtE;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,aAAa,2CAgB5E;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,SAAS,CAAC,EACjB,KAAK,EACL,WAAW,EACX,UAAiD,EACjD,KAAK,EACL,SAAS,EACT,GAAG,KAAK,EACT,EAAE,eAAe,2CAsBjB;AAuBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,iBAAS,UAAU,CAAC,KAAK,EAAE,gBAAgB,2CAiD1C;AAMD,OAAO,EACL,IAAI,EACJ,aAAa,EACb,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACP,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,qBAAqB,GACtB,CAAC;AAGF,YAAY,EACV,UAAU,EACV,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,WAAW,EACX,eAAe,GAChB,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/react-ui/ui/Tabs/index.tsx"],"names":[],"mappings":"AAoEA,OAAO,EAEL,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACtB,MAAM,eAAe,CAAC;AACvB,OAAO,mBAAm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,EACf,qBAAqB,GACtB,CAAC;AAGF,YAAY,EACV,UAAU,EACV,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,WAAW,EACX,eAAe,GAChB,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
@@ -6,6 +6,7 @@ import { AutoHeight } from "../../primitives/AutoHeight/index.js";
6
6
  import { getStrictContext } from "../../lib/get-strict-context.js";
7
7
  import { useControlledState } from "../../hooks/State/UseControlledState.js";
8
8
  import { tabsIndicatorVariants, tabsListVariants, tabsStyles, tabsTabVariants } from "./Tabs.styles.js";
9
+ import "./Tabs.module.js";
9
10
  import * as React$1 from "react";
10
11
  import { AnimatePresence, motion } from "motion/react";
11
12
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -61,27 +62,6 @@ import { Tabs } from "@base-ui/react/tabs";
61
62
  * </Tabs>
62
63
  * ```
63
64
  */
64
- const TABS_CSS_ID = "mks-tabs-anchor-css";
65
- const TABS_ANCHOR_CSS = `
66
- [data-slot="tabs-list"]{anchor-scope:--tabs-active}
67
- [data-slot="tabs-tab"][data-active]{anchor-name:--tabs-active}
68
- [data-slot="tabs-indicator"]{position-anchor:--tabs-active;left:anchor(left);right:anchor(right);transition:top 200ms cubic-bezier(.25,.46,.45,.94),left 200ms cubic-bezier(.25,.46,.45,.94),right 200ms cubic-bezier(.25,.46,.45,.94),bottom 200ms cubic-bezier(.25,.46,.45,.94),width 200ms cubic-bezier(.25,.46,.45,.94),height 200ms cubic-bezier(.25,.46,.45,.94)}
69
- @media(prefers-reduced-motion:reduce){[data-slot="tabs-indicator"]{transition-duration:0ms}}
70
- `;
71
- /**
72
- * Injects the CSS Anchor Positioning rules into the document head once.
73
- * Safe for SSR -- no-ops on the server.
74
- */
75
- function useTabsAnchorCSS() {
76
- React$1.useEffect(() => {
77
- if (typeof document === "undefined") return;
78
- if (document.getElementById(TABS_CSS_ID)) return;
79
- const style = document.createElement("style");
80
- style.id = TABS_CSS_ID;
81
- style.textContent = TABS_ANCHOR_CSS;
82
- document.head.appendChild(style);
83
- }, []);
84
- }
85
65
  const [TabsProvider, useTabs] = getStrictContext("TabsContext");
86
66
  const TabsVariantCtx = React$1.createContext({});
87
67
  /**
@@ -175,7 +155,6 @@ function TabsHighlight({ transition = {
175
155
  * ```
176
156
  */
177
157
  function TabsList({ variant, size, indicator, slots, className, children, ...props }) {
178
- useTabsAnchorCSS();
179
158
  const resolvedVariant = variant ?? "default";
180
159
  const showIndicator = indicator ?? !["ghost", "underline"].includes(resolvedVariant);
181
160
  return /* @__PURE__ */ jsx(TabsVariantCtx.Provider, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mks2508/mks-ui",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "description": "UI component library - Shadcn/Animate UI based with DevEnv components",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",