@lobehub/ui 6.10.0 → 6.10.2
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.
- package/es/Accordion/style.d.mts +1 -1
- package/es/Button/Button.mjs +22 -2
- package/es/Button/Button.mjs.map +1 -1
- package/es/Button/style.d.mts +22 -4
- package/es/Button/style.mjs +24 -4
- package/es/Button/style.mjs.map +1 -1
- package/es/Image/viewer/ImageViewer.mjs +1 -0
- package/es/Image/viewer/ImageViewer.mjs.map +1 -1
- package/es/Image/viewer/geometry.mjs +2 -2
- package/es/Image/viewer/geometry.mjs.map +1 -1
- package/es/Image/viewer/registry.mjs.map +1 -1
- package/es/Image/viewer/useZoomPan.mjs +5 -2
- package/es/Image/viewer/useZoomPan.mjs.map +1 -1
- package/es/Mermaid/SyntaxMermaid/MermaidSvg.mjs +2 -1
- package/es/Mermaid/SyntaxMermaid/MermaidSvg.mjs.map +1 -1
- package/es/Tabs/style.d.mts +1 -1
- package/es/style.css +14 -2
- package/package.json +1 -1
package/es/Accordion/style.d.mts
CHANGED
package/es/Button/Button.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import Icon from "../Icon/Icon.mjs";
|
|
|
7
7
|
import { buttonClasses } from "./stable.mjs";
|
|
8
8
|
import { styles } from "./style.mjs";
|
|
9
9
|
import clsx$1 from "clsx";
|
|
10
|
-
import { isValidElement } from "react";
|
|
10
|
+
import { isValidElement, useLayoutEffect, useRef, useState } from "react";
|
|
11
11
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
import * as stylex from "@stylexjs/stylex";
|
|
13
13
|
// src/Button/Button.tsx
|
|
@@ -53,6 +53,21 @@ const motionTransition = {
|
|
|
53
53
|
};
|
|
54
54
|
const ButtonImpl = ({ block, children, className, classNames, danger = false, disabled, outdent, ghost = false, href, htmlType = "button", icon, iconPosition = "start", loading, onClick, ref, shape = "default", size = "middle", stableData, styles: userStyles, target, type = "default", xstyle, ...rest }) => {
|
|
55
55
|
const Motion = useMotionComponent();
|
|
56
|
+
const spinnerRef = useRef(null);
|
|
57
|
+
const spinnerVisualRef = useRef(null);
|
|
58
|
+
const [spinnerPresent, setSpinnerPresent] = useState(!!loading);
|
|
59
|
+
if (loading && !spinnerPresent) setSpinnerPresent(true);
|
|
60
|
+
useLayoutEffect(() => {
|
|
61
|
+
if (loading || !spinnerPresent) return;
|
|
62
|
+
const exits = [...spinnerRef.current?.getAnimations?.() ?? [], ...spinnerVisualRef.current?.getAnimations?.() ?? []].filter((animation) => "transitionProperty" in animation);
|
|
63
|
+
let canceled = false;
|
|
64
|
+
Promise.allSettled(exits.map((animation) => animation.finished)).then(() => {
|
|
65
|
+
if (!canceled) setSpinnerPresent(false);
|
|
66
|
+
});
|
|
67
|
+
return () => {
|
|
68
|
+
canceled = true;
|
|
69
|
+
};
|
|
70
|
+
}, [loading, spinnerPresent]);
|
|
56
71
|
const isInteractionDisabled = disabled || loading;
|
|
57
72
|
const sizeCls = resolveSizeCls(size);
|
|
58
73
|
const variantCls = resolveVariantCls({
|
|
@@ -86,13 +101,18 @@ const ButtonImpl = ({ block, children, className, classNames, danger = false, di
|
|
|
86
101
|
});
|
|
87
102
|
const spinnerNode = /* @__PURE__ */ jsx("span", {
|
|
88
103
|
"aria-hidden": !loading,
|
|
104
|
+
ref: spinnerRef,
|
|
89
105
|
...styleProps([
|
|
90
106
|
styles.iconBox,
|
|
91
107
|
styles.spinnerSlot,
|
|
92
108
|
iconPosition === "end" && styles.spinnerSlotEnd,
|
|
93
109
|
loading && styles.spinnerSlotShow
|
|
94
110
|
], clsx$1(buttonClasses("spinner"), classNames?.icon), userStyles?.icon),
|
|
95
|
-
children: /* @__PURE__ */ jsx("span", {
|
|
111
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
112
|
+
ref: spinnerVisualRef,
|
|
113
|
+
...stylex.props(styles.spinnerVisual, loading && styles.spinnerVisualShow),
|
|
114
|
+
children: (loading || spinnerPresent) && /* @__PURE__ */ jsx("span", { ...stylex.props(styles.spinner) })
|
|
115
|
+
})
|
|
96
116
|
});
|
|
97
117
|
const iconNode = icon && !loading ? /* @__PURE__ */ jsx("span", {
|
|
98
118
|
...styleProps(styles.iconBox, clsx$1(buttonClasses("icon"), classNames?.icon), userStyles?.icon),
|
package/es/Button/Button.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.mjs","names":["clsx"],"sources":["../../src/Button/Button.tsx"],"sourcesContent":["'use client';\n\nimport * as stylex from '@stylexjs/stylex';\nimport clsx from 'clsx';\nimport {\n isValidElement,\n type MouseEvent,\n type ReactElement,\n type ReactNode,\n type Ref,\n} from 'react';\n\nimport Icon, { type IconProps } from '@/Icon';\nimport { useMotionComponent } from '@/MotionProvider';\nimport { focusRing } from '@/styles/stylex/focusRing';\nimport { styleProps } from '@/styles/stylex/props';\nimport { toDataAttributes } from '@/utils/bem';\n\nimport { buttonClasses } from './stable';\nimport { styles } from './style';\nimport type { ButtonOutdent, ButtonProps, ButtonType } from './type';\n\nconst resolveIconNode = (node: ReactNode | IconProps['icon'] | undefined | null) => {\n if (node === undefined || node === null) return null;\n if (isValidElement(node) || typeof node === 'string' || typeof node === 'number') {\n return node;\n }\n return <Icon icon={node as any} size={'small'} />;\n};\n\nconst resolveSizeCls = (size: ButtonProps['size']) => {\n if (size === 'small') return styles.sizeSmall;\n if (size === 'large') return styles.sizeLarge;\n return styles.sizeMiddle;\n};\n\nconst resolveIconOnlySizeCls = (size: ButtonProps['size']) => {\n if (size === 'small') return styles.iconOnlySmall;\n if (size === 'large') return styles.iconOnlyLarge;\n return styles.iconOnlyMiddle;\n};\n\nconst resolveVariantCls = ({\n danger,\n ghost,\n type,\n}: {\n danger: boolean;\n ghost: boolean;\n type: NonNullable<ButtonProps['type']>;\n}) => {\n // `text` and `link` already drop the surface, so `ghost` there would only cost them\n // their own traits (link's zero inline padding).\n if (ghost && type !== 'text' && type !== 'link') {\n if (danger) return styles.ghostDanger;\n if (type === 'primary') return styles.ghostPrimary;\n return styles.ghostDefault;\n }\n\n switch (type) {\n case 'primary': {\n return danger ? styles.dangerSolid : styles.variantPrimary;\n }\n case 'dashed': {\n return danger ? [styles.variantDashed, styles.dangerOutlined] : styles.variantDashed;\n }\n case 'fill': {\n return danger ? styles.dangerFill : styles.variantFill;\n }\n case 'text': {\n return danger ? [styles.variantText, styles.dangerText] : styles.variantText;\n }\n case 'link': {\n return danger ? [styles.variantLink, styles.dangerInline] : styles.variantLink;\n }\n default: {\n return danger ? [styles.variantDefault, styles.dangerOutlined] : styles.variantDefault;\n }\n }\n};\n\nconst tapAnim = { scale: 0.98 };\nconst motionTransition = {\n damping: 26,\n mass: 0.6,\n stiffness: 600,\n type: 'spring' as const,\n};\n\ntype ButtonImplProps = Omit<ButtonProps, 'outdent' | 'type'> & {\n outdent?: ButtonOutdent;\n stableData?: Record<`data-${string}`, string>;\n type?: ButtonType;\n xstyle?: Parameters<typeof styleProps>[0];\n};\n\nconst ButtonImpl = ({\n block,\n children,\n className,\n classNames,\n danger = false,\n disabled,\n outdent,\n ghost = false,\n href,\n htmlType = 'button',\n icon,\n iconPosition = 'start',\n loading,\n onClick,\n ref,\n shape = 'default',\n size = 'middle',\n stableData,\n styles: userStyles,\n target,\n type = 'default',\n xstyle,\n ...rest\n}: ButtonImplProps) => {\n const Motion = useMotionComponent();\n const isInteractionDisabled = disabled || loading;\n const sizeCls = resolveSizeCls(size);\n const variantCls = resolveVariantCls({ danger, ghost, type });\n const shapeCls =\n shape === 'circle' ? styles.shapeCircle : shape === 'round' ? styles.shapeRound : undefined;\n\n const hasChildren =\n children !== undefined && children !== null && children !== false && children !== '';\n const renderIcon = loading || icon;\n const iconOnly = !hasChildren && !!renderIcon;\n const iconOnlySizeCls = iconOnly ? resolveIconOnlySizeCls(size) : undefined;\n\n const outdentCls =\n type === 'text' && outdent\n ? outdent === 'end'\n ? styles.outdentEnd\n : styles.outdentStart\n : undefined;\n\n const composedClassName = styleProps(\n [\n styles.base,\n focusRing.info,\n sizeCls,\n variantCls,\n shapeCls,\n block && styles.block,\n iconPosition === 'end' && styles.iconEnd,\n iconOnlySizeCls,\n outdentCls,\n xstyle,\n ],\n clsx(buttonClasses(), className),\n ).className;\n\n const dataAttributes =\n stableData ?? toDataAttributes({ block, danger, ghost, loading, shape, size, type });\n\n const spinnerNode = (\n <span\n aria-hidden={!loading}\n {...styleProps(\n [\n styles.iconBox,\n styles.spinnerSlot,\n iconPosition === 'end' && styles.spinnerSlotEnd,\n loading && styles.spinnerSlotShow,\n ],\n clsx(buttonClasses('spinner'), classNames?.icon),\n userStyles?.icon,\n )}\n >\n <span {...stylex.props(styles.spinner)} />\n </span>\n );\n\n const iconNode =\n icon && !loading ? (\n <span\n {...styleProps(\n styles.iconBox,\n clsx(buttonClasses('icon'), classNames?.icon),\n userStyles?.icon,\n )}\n >\n {resolveIconNode(icon)}\n </span>\n ) : null;\n\n const inner = (\n <>\n {spinnerNode}\n {iconNode}\n {children}\n </>\n );\n\n const motionGestures = isInteractionDisabled\n ? {}\n : { transition: motionTransition, whileTap: tapAnim };\n\n if (href !== undefined) {\n const handleAnchorClick = (e: MouseEvent<HTMLAnchorElement>) => {\n if (isInteractionDisabled) {\n e.preventDefault();\n return;\n }\n onClick?.(e as unknown as MouseEvent<HTMLButtonElement>);\n };\n\n return (\n <Motion.a\n aria-busy={loading || undefined}\n aria-disabled={isInteractionDisabled || undefined}\n href={disabled ? undefined : href}\n target={target}\n {...dataAttributes}\n {...(rest as any)}\n className={composedClassName}\n ref={ref as Ref<HTMLAnchorElement>}\n onClick={handleAnchorClick}\n {...motionGestures}\n >\n {inner}\n </Motion.a>\n );\n }\n\n const handleButtonClick = (e: MouseEvent<HTMLButtonElement>) => {\n if (isInteractionDisabled) {\n e.preventDefault();\n return;\n }\n onClick?.(e);\n };\n\n return (\n <Motion.button\n type={htmlType}\n {...dataAttributes}\n {...(rest as any)}\n aria-busy={loading || undefined}\n aria-disabled={isInteractionDisabled || undefined}\n className={composedClassName}\n disabled={disabled}\n ref={ref as Ref<HTMLButtonElement>}\n onClick={handleButtonClick}\n {...motionGestures}\n >\n {inner}\n </Motion.button>\n );\n};\n\nButtonImpl.displayName = 'BaseButton';\n\nexport { ButtonImpl };\n\nconst Button = ButtonImpl as <T extends ButtonType = 'default'>(\n props: ButtonProps<T>,\n) => ReactElement;\n\nexport default Button;\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,mBAAmB,SAA2D;CAClF,IAAI,SAAS,KAAA,KAAa,SAAS,MAAM,OAAO;CAChD,IAAI,eAAe,IAAI,KAAK,OAAO,SAAS,YAAY,OAAO,SAAS,UACtE,OAAO;CAET,OAAO,oBAAC,MAAD;EAAM,MAAM;EAAa,MAAM;CAAU,CAAA;AAClD;AACA,MAAM,kBAAkB,SAA8B;CACpD,IAAI,SAAS,SAAS,OAAO,OAAO;CACpC,IAAI,SAAS,SAAS,OAAO,OAAO;CACpC,OAAO,OAAO;AAChB;AACA,MAAM,0BAA0B,SAA8B;CAC5D,IAAI,SAAS,SAAS,OAAO,OAAO;CACpC,IAAI,SAAS,SAAS,OAAO,OAAO;CACpC,OAAO,OAAO;AAChB;AACA,MAAM,qBAAqB,EACzB,QACA,OACA,WAKI;CAGJ,IAAI,SAAS,SAAS,UAAU,SAAS,QAAQ;EAC/C,IAAI,QAAQ,OAAO,OAAO;EAC1B,IAAI,SAAS,WAAW,OAAO,OAAO;EACtC,OAAO,OAAO;CAChB;CACA,QAAQ,MAAR;EACE,KAAK,WAED,OAAO,SAAS,OAAO,cAAc,OAAO;EAEhD,KAAK,UAED,OAAO,SAAS,CAAC,OAAO,eAAe,OAAO,cAAc,IAAI,OAAO;EAE3E,KAAK,QAED,OAAO,SAAS,OAAO,aAAa,OAAO;EAE/C,KAAK,QAED,OAAO,SAAS,CAAC,OAAO,aAAa,OAAO,UAAU,IAAI,OAAO;EAErE,KAAK,QAED,OAAO,SAAS,CAAC,OAAO,aAAa,OAAO,YAAY,IAAI,OAAO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GAAG,YAAY,IAAI,GAAG,YAAY,IAAI;EACxP,UAAA,oBAAC,QAAD,EAAM,GAAI,OAAO,MAAM,OAAO,OAAO,EAAI,CAAA;CACrC,CAAA;CACR,MAAM,WAAW,QAAQ,CAAC,UAAU,oBAAC,QAAD;EAAM,GAAI,WAAW,OAAO,SAASA,OAAK,cAAc,MAAM,GAAG,YAAY,IAAI,GAAG,YAAY,IAAI;EACjI,UAAA,gBAAgB,IAAI;CACjB,CAAA,IAAI;CACd,MAAM,QAAQ,qBAAA,YAAA,EAAA,UAAA;EACT;EACA;EACA;CACD,EAAA,CAAA;CACJ,MAAM,iBAAiB,wBAAwB,CAAC,IAAI;EAClD,YAAY;EACZ,UAAU;CACZ;CACA,IAAI,SAAS,KAAA,GAAW;EACtB,MAAM,qBAAqB,MAAqC;GAC9D,IAAI,uBAAuB;IACzB,EAAE,eAAe;IACjB;GACF;GACA,UAAU,CAA6C;EACzD;EACA,OAAO,oBAAC,OAAO,GAAR;GAAU,aAAW,WAAW,KAAA;GAAW,iBAAe,yBAAyB,KAAA;GAAW,MAAM,WAAW,KAAA,IAAY;GAAc;GAAQ,GAAI;GAAgB,GAAI;GAAa,WAAW;GAAwB;GAA+B,SAAS;GAAmB,GAAI;GAC1R,UAAA;EACO,CAAA;CACd;CACA,MAAM,qBAAqB,MAAqC;EAC9D,IAAI,uBAAuB;GACzB,EAAE,eAAe;GACjB;EACF;EACA,UAAU,CAAC;CACb;CACA,OAAO,oBAAC,OAAO,QAAR;EAAe,MAAM;EAAU,GAAI;EAAgB,GAAI;EAAa,aAAW,WAAW,KAAA;EAAW,iBAAe,yBAAyB,KAAA;EAAW,WAAW;EAA6B;EAAe;EAA+B,SAAS;EAAmB,GAAI;EAChR,UAAA;CACY,CAAA;AACnB;AACA,WAAW,cAAc;AAEzB,MAAM,SAAS"}
|
|
1
|
+
{"version":3,"file":"Button.mjs","names":["clsx"],"sources":["../../src/Button/Button.tsx"],"sourcesContent":["'use client';\n\nimport * as stylex from '@stylexjs/stylex';\nimport clsx from 'clsx';\nimport {\n isValidElement,\n type MouseEvent,\n type ReactElement,\n type ReactNode,\n type Ref,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport Icon, { type IconProps } from '@/Icon';\nimport { useMotionComponent } from '@/MotionProvider';\nimport { focusRing } from '@/styles/stylex/focusRing';\nimport { styleProps } from '@/styles/stylex/props';\nimport { toDataAttributes } from '@/utils/bem';\n\nimport { buttonClasses } from './stable';\nimport { styles } from './style';\nimport type { ButtonOutdent, ButtonProps, ButtonType } from './type';\n\nconst resolveIconNode = (node: ReactNode | IconProps['icon'] | undefined | null) => {\n if (node === undefined || node === null) return null;\n if (isValidElement(node) || typeof node === 'string' || typeof node === 'number') {\n return node;\n }\n return <Icon icon={node as any} size={'small'} />;\n};\n\nconst resolveSizeCls = (size: ButtonProps['size']) => {\n if (size === 'small') return styles.sizeSmall;\n if (size === 'large') return styles.sizeLarge;\n return styles.sizeMiddle;\n};\n\nconst resolveIconOnlySizeCls = (size: ButtonProps['size']) => {\n if (size === 'small') return styles.iconOnlySmall;\n if (size === 'large') return styles.iconOnlyLarge;\n return styles.iconOnlyMiddle;\n};\n\nconst resolveVariantCls = ({\n danger,\n ghost,\n type,\n}: {\n danger: boolean;\n ghost: boolean;\n type: NonNullable<ButtonProps['type']>;\n}) => {\n // `text` and `link` already drop the surface, so `ghost` there would only cost them\n // their own traits (link's zero inline padding).\n if (ghost && type !== 'text' && type !== 'link') {\n if (danger) return styles.ghostDanger;\n if (type === 'primary') return styles.ghostPrimary;\n return styles.ghostDefault;\n }\n\n switch (type) {\n case 'primary': {\n return danger ? styles.dangerSolid : styles.variantPrimary;\n }\n case 'dashed': {\n return danger ? [styles.variantDashed, styles.dangerOutlined] : styles.variantDashed;\n }\n case 'fill': {\n return danger ? styles.dangerFill : styles.variantFill;\n }\n case 'text': {\n return danger ? [styles.variantText, styles.dangerText] : styles.variantText;\n }\n case 'link': {\n return danger ? [styles.variantLink, styles.dangerInline] : styles.variantLink;\n }\n default: {\n return danger ? [styles.variantDefault, styles.dangerOutlined] : styles.variantDefault;\n }\n }\n};\n\nconst tapAnim = { scale: 0.98 };\nconst motionTransition = {\n damping: 26,\n mass: 0.6,\n stiffness: 600,\n type: 'spring' as const,\n};\n\ntype ButtonImplProps = Omit<ButtonProps, 'outdent' | 'type'> & {\n outdent?: ButtonOutdent;\n stableData?: Record<`data-${string}`, string>;\n type?: ButtonType;\n xstyle?: Parameters<typeof styleProps>[0];\n};\n\nconst ButtonImpl = ({\n block,\n children,\n className,\n classNames,\n danger = false,\n disabled,\n outdent,\n ghost = false,\n href,\n htmlType = 'button',\n icon,\n iconPosition = 'start',\n loading,\n onClick,\n ref,\n shape = 'default',\n size = 'middle',\n stableData,\n styles: userStyles,\n target,\n type = 'default',\n xstyle,\n ...rest\n}: ButtonImplProps) => {\n const Motion = useMotionComponent();\n const spinnerRef = useRef<HTMLSpanElement>(null);\n const spinnerVisualRef = useRef<HTMLSpanElement>(null);\n const [spinnerPresent, setSpinnerPresent] = useState(!!loading);\n\n if (loading && !spinnerPresent) setSpinnerPresent(true);\n\n useLayoutEffect(() => {\n if (loading || !spinnerPresent) return;\n\n // Wait for both exit layers, never the child's infinite rotation.\n const exits = [\n ...(spinnerRef.current?.getAnimations?.() ?? []),\n ...(spinnerVisualRef.current?.getAnimations?.() ?? []),\n ].filter((animation) => 'transitionProperty' in animation);\n let canceled = false;\n Promise.allSettled(exits.map((animation) => animation.finished)).then(() => {\n if (!canceled) setSpinnerPresent(false);\n });\n return () => {\n canceled = true;\n };\n }, [loading, spinnerPresent]);\n\n const isInteractionDisabled = disabled || loading;\n const sizeCls = resolveSizeCls(size);\n const variantCls = resolveVariantCls({ danger, ghost, type });\n const shapeCls =\n shape === 'circle' ? styles.shapeCircle : shape === 'round' ? styles.shapeRound : undefined;\n\n const hasChildren =\n children !== undefined && children !== null && children !== false && children !== '';\n const renderIcon = loading || icon;\n const iconOnly = !hasChildren && !!renderIcon;\n const iconOnlySizeCls = iconOnly ? resolveIconOnlySizeCls(size) : undefined;\n\n const outdentCls =\n type === 'text' && outdent\n ? outdent === 'end'\n ? styles.outdentEnd\n : styles.outdentStart\n : undefined;\n\n const composedClassName = styleProps(\n [\n styles.base,\n focusRing.info,\n sizeCls,\n variantCls,\n shapeCls,\n block && styles.block,\n iconPosition === 'end' && styles.iconEnd,\n iconOnlySizeCls,\n outdentCls,\n xstyle,\n ],\n clsx(buttonClasses(), className),\n ).className;\n\n const dataAttributes =\n stableData ?? toDataAttributes({ block, danger, ghost, loading, shape, size, type });\n\n const spinnerNode = (\n <span\n aria-hidden={!loading}\n ref={spinnerRef}\n {...styleProps(\n [\n styles.iconBox,\n styles.spinnerSlot,\n iconPosition === 'end' && styles.spinnerSlotEnd,\n loading && styles.spinnerSlotShow,\n ],\n clsx(buttonClasses('spinner'), classNames?.icon),\n userStyles?.icon,\n )}\n >\n <span\n ref={spinnerVisualRef}\n {...stylex.props(styles.spinnerVisual, loading && styles.spinnerVisualShow)}\n >\n {(loading || spinnerPresent) && <span {...stylex.props(styles.spinner)} />}\n </span>\n </span>\n );\n\n const iconNode =\n icon && !loading ? (\n <span\n {...styleProps(\n styles.iconBox,\n clsx(buttonClasses('icon'), classNames?.icon),\n userStyles?.icon,\n )}\n >\n {resolveIconNode(icon)}\n </span>\n ) : null;\n\n const inner = (\n <>\n {spinnerNode}\n {iconNode}\n {children}\n </>\n );\n\n const motionGestures = isInteractionDisabled\n ? {}\n : { transition: motionTransition, whileTap: tapAnim };\n\n if (href !== undefined) {\n const handleAnchorClick = (e: MouseEvent<HTMLAnchorElement>) => {\n if (isInteractionDisabled) {\n e.preventDefault();\n return;\n }\n onClick?.(e as unknown as MouseEvent<HTMLButtonElement>);\n };\n\n return (\n <Motion.a\n aria-busy={loading || undefined}\n aria-disabled={isInteractionDisabled || undefined}\n href={disabled ? undefined : href}\n target={target}\n {...dataAttributes}\n {...(rest as any)}\n className={composedClassName}\n ref={ref as Ref<HTMLAnchorElement>}\n onClick={handleAnchorClick}\n {...motionGestures}\n >\n {inner}\n </Motion.a>\n );\n }\n\n const handleButtonClick = (e: MouseEvent<HTMLButtonElement>) => {\n if (isInteractionDisabled) {\n e.preventDefault();\n return;\n }\n onClick?.(e);\n };\n\n return (\n <Motion.button\n type={htmlType}\n {...dataAttributes}\n {...(rest as any)}\n aria-busy={loading || undefined}\n aria-disabled={isInteractionDisabled || undefined}\n className={composedClassName}\n disabled={disabled}\n ref={ref as Ref<HTMLButtonElement>}\n onClick={handleButtonClick}\n {...motionGestures}\n >\n {inner}\n </Motion.button>\n );\n};\n\nButtonImpl.displayName = 'BaseButton';\n\nexport { ButtonImpl };\n\nconst Button = ButtonImpl as <T extends ButtonType = 'default'>(\n props: ButtonProps<T>,\n) => ReactElement;\n\nexport default Button;\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,mBAAmB,SAA2D;CAClF,IAAI,SAAS,KAAA,KAAa,SAAS,MAAM,OAAO;CAChD,IAAI,eAAe,IAAI,KAAK,OAAO,SAAS,YAAY,OAAO,SAAS,UACtE,OAAO;CAET,OAAO,oBAAC,MAAD;EAAM,MAAM;EAAa,MAAM;CAAU,CAAA;AAClD;AACA,MAAM,kBAAkB,SAA8B;CACpD,IAAI,SAAS,SAAS,OAAO,OAAO;CACpC,IAAI,SAAS,SAAS,OAAO,OAAO;CACpC,OAAO,OAAO;AAChB;AACA,MAAM,0BAA0B,SAA8B;CAC5D,IAAI,SAAS,SAAS,OAAO,OAAO;CACpC,IAAI,SAAS,SAAS,OAAO,OAAO;CACpC,OAAO,OAAO;AAChB;AACA,MAAM,qBAAqB,EACzB,QACA,OACA,WAKI;CAGJ,IAAI,SAAS,SAAS,UAAU,SAAS,QAAQ;EAC/C,IAAI,QAAQ,OAAO,OAAO;EAC1B,IAAI,SAAS,WAAW,OAAO,OAAO;EACtC,OAAO,OAAO;CAChB;CACA,QAAQ,MAAR;EACE,KAAK,WAED,OAAO,SAAS,OAAO,cAAc,OAAO;EAEhD,KAAK,U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BAAgB,IAAI;CACjB,CAAA,IAAI;CACd,MAAM,QAAQ,qBAAA,YAAA,EAAA,UAAA;EACT;EACA;EACA;CACD,EAAA,CAAA;CACJ,MAAM,iBAAiB,wBAAwB,CAAC,IAAI;EAClD,YAAY;EACZ,UAAU;CACZ;CACA,IAAI,SAAS,KAAA,GAAW;EACtB,MAAM,qBAAqB,MAAqC;GAC9D,IAAI,uBAAuB;IACzB,EAAE,eAAe;IACjB;GACF;GACA,UAAU,CAA6C;EACzD;EACA,OAAO,oBAAC,OAAO,GAAR;GAAU,aAAW,WAAW,KAAA;GAAW,iBAAe,yBAAyB,KAAA;GAAW,MAAM,WAAW,KAAA,IAAY;GAAc;GAAQ,GAAI;GAAgB,GAAI;GAAa,WAAW;GAAwB;GAA+B,SAAS;GAAmB,GAAI;GAC1R,UAAA;EACO,CAAA;CACd;CACA,MAAM,qBAAqB,MAAqC;EAC9D,IAAI,uBAAuB;GACzB,EAAE,eAAe;GACjB;EACF;EACA,UAAU,CAAC;CACb;CACA,OAAO,oBAAC,OAAO,QAAR;EAAe,MAAM;EAAU,GAAI;EAAgB,GAAI;EAAa,aAAW,WAAW,KAAA;EAAW,iBAAe,yBAAyB,KAAA;EAAW,WAAW;EAA6B;EAAe;EAA+B,SAAS;EAAmB,GAAI;EAChR,UAAA;CACY,CAAA;AACnB;AACA,WAAW,cAAc;AAEzB,MAAM,SAAS"}
|
package/es/Button/style.d.mts
CHANGED
|
@@ -85,10 +85,12 @@ export declare const styles: Readonly<{
|
|
|
85
85
|
readonly justifyContent: stylex.StyleXClassNameFor<"justifyContent", "center">;
|
|
86
86
|
}>;
|
|
87
87
|
readonly spinnerSlot: Readonly<{
|
|
88
|
-
readonly overflow: stylex.StyleXClassNameFor<"overflow", "
|
|
89
|
-
readonly transition: stylex.StyleXClassNameFor<"transition", "width
|
|
88
|
+
readonly overflow: stylex.StyleXClassNameFor<"overflow", "visible">;
|
|
89
|
+
readonly transition: stylex.StyleXClassNameFor<"transition", "width 300ms cubic-bezier(0.22, 1, 0.36, 1), margin 300ms cubic-bezier(0.22, 1, 0.36, 1)">;
|
|
90
|
+
readonly flexShrink: stylex.StyleXClassNameFor<"flexShrink", 0>;
|
|
90
91
|
readonly marginInlineEnd: stylex.StyleXClassNameFor<"marginInlineEnd", -6>;
|
|
91
|
-
readonly
|
|
92
|
+
readonly position: stylex.StyleXClassNameFor<"position", "relative">;
|
|
93
|
+
readonly height: stylex.StyleXClassNameFor<"height", 12>;
|
|
92
94
|
readonly width: stylex.StyleXClassNameFor<"width", 0>;
|
|
93
95
|
}>;
|
|
94
96
|
readonly spinnerSlotEnd: Readonly<{
|
|
@@ -98,9 +100,23 @@ export declare const styles: Readonly<{
|
|
|
98
100
|
readonly spinnerSlotShow: Readonly<{
|
|
99
101
|
readonly marginInlineEnd: stylex.StyleXClassNameFor<"marginInlineEnd", 0>;
|
|
100
102
|
readonly marginInlineStart: stylex.StyleXClassNameFor<"marginInlineStart", 0>;
|
|
101
|
-
readonly opacity: stylex.StyleXClassNameFor<"opacity", 1>;
|
|
102
103
|
readonly width: stylex.StyleXClassNameFor<"width", 12>;
|
|
103
104
|
}>;
|
|
105
|
+
readonly spinnerVisual: Readonly<{
|
|
106
|
+
readonly transition: stylex.StyleXClassNameFor<"transition", "transform 180ms cubic-bezier(0.22, 1, 0.36, 1), opacity 180ms ease-out">;
|
|
107
|
+
readonly insetBlockStart: stylex.StyleXClassNameFor<"insetBlockStart", 0>;
|
|
108
|
+
readonly insetInlineStart: stylex.StyleXClassNameFor<"insetInlineStart", 0>;
|
|
109
|
+
readonly opacity: stylex.StyleXClassNameFor<"opacity", 0>;
|
|
110
|
+
readonly position: stylex.StyleXClassNameFor<"position", "absolute">;
|
|
111
|
+
readonly transform: stylex.StyleXClassNameFor<"transform", "scale(0.5)">;
|
|
112
|
+
readonly transformOrigin: stylex.StyleXClassNameFor<"transformOrigin", "center">;
|
|
113
|
+
readonly height: stylex.StyleXClassNameFor<"height", 12>;
|
|
114
|
+
readonly width: stylex.StyleXClassNameFor<"width", 12>;
|
|
115
|
+
}>;
|
|
116
|
+
readonly spinnerVisualShow: Readonly<{
|
|
117
|
+
readonly opacity: stylex.StyleXClassNameFor<"opacity", 1>;
|
|
118
|
+
readonly transform: stylex.StyleXClassNameFor<"transform", "scale(1)">;
|
|
119
|
+
}>;
|
|
104
120
|
readonly variantDefault: Readonly<{
|
|
105
121
|
readonly borderColor: stylex.StyleXClassNameFor<"borderColor", string>;
|
|
106
122
|
readonly backgroundColor: stylex.StyleXClassNameFor<"backgroundColor", string>;
|
|
@@ -183,7 +199,9 @@ export declare const styles: Readonly<{
|
|
|
183
199
|
readonly animationName: stylex.StyleXClassNameFor<"animationName", string>;
|
|
184
200
|
readonly animationTimingFunction: stylex.StyleXClassNameFor<"animationTimingFunction", "linear">;
|
|
185
201
|
readonly borderBlockStartColor: stylex.StyleXClassNameFor<"borderBlockStartColor", "transparent">;
|
|
202
|
+
readonly boxSizing: stylex.StyleXClassNameFor<"boxSizing", "border-box">;
|
|
186
203
|
readonly display: stylex.StyleXClassNameFor<"display", "inline-block">;
|
|
204
|
+
readonly flexShrink: stylex.StyleXClassNameFor<"flexShrink", 0>;
|
|
187
205
|
readonly height: stylex.StyleXClassNameFor<"height", 12>;
|
|
188
206
|
readonly width: stylex.StyleXClassNameFor<"width", 12>;
|
|
189
207
|
}>;
|
package/es/Button/style.mjs
CHANGED
|
@@ -115,10 +115,12 @@ const styles = {
|
|
|
115
115
|
$$css: true
|
|
116
116
|
},
|
|
117
117
|
spinnerSlot: {
|
|
118
|
-
kVQacm: "
|
|
119
|
-
kmkexE: "
|
|
118
|
+
kVQacm: "lb1rea2x4",
|
|
119
|
+
kmkexE: "lbp7890b",
|
|
120
|
+
kmuXW: "lb2lah0s",
|
|
120
121
|
k71WvV: "lb1ws5yxj",
|
|
121
|
-
|
|
122
|
+
kVAEAm: "lb1n2onr6",
|
|
123
|
+
kZKoxP: "lb1kpxq89",
|
|
122
124
|
kzqmXN: "lbnalus7",
|
|
123
125
|
$$css: true
|
|
124
126
|
},
|
|
@@ -130,10 +132,26 @@ const styles = {
|
|
|
130
132
|
spinnerSlotShow: {
|
|
131
133
|
k71WvV: "lb14z9mp",
|
|
132
134
|
keTefX: "lb1lziwak",
|
|
133
|
-
kSiTet: "lb1hc1fzr",
|
|
134
135
|
kzqmXN: "lbsmyaan",
|
|
135
136
|
$$css: true
|
|
136
137
|
},
|
|
138
|
+
spinnerVisual: {
|
|
139
|
+
kmkexE: "lb1ja9v0h",
|
|
140
|
+
k87sOh: "lb13vifvy",
|
|
141
|
+
kLqNvP: "lb1o0tod",
|
|
142
|
+
kSiTet: "lbg01cxk",
|
|
143
|
+
kVAEAm: "lb10l6tqk",
|
|
144
|
+
k3aq6I: "lb1a33avv",
|
|
145
|
+
k3nNDw: "lb1g0ag68",
|
|
146
|
+
kZKoxP: "lb1kpxq89",
|
|
147
|
+
kzqmXN: "lbsmyaan",
|
|
148
|
+
$$css: true
|
|
149
|
+
},
|
|
150
|
+
spinnerVisualShow: {
|
|
151
|
+
kSiTet: "lb1hc1fzr",
|
|
152
|
+
k3aq6I: "lb3oybdh",
|
|
153
|
+
$$css: true
|
|
154
|
+
},
|
|
137
155
|
variantDefault: {
|
|
138
156
|
kVAM5u: "lbqnr5ac lbv4eugq",
|
|
139
157
|
kWkggS: "lb6yijhg",
|
|
@@ -230,7 +248,9 @@ const styles = {
|
|
|
230
248
|
kKVMdj: "lb1v0ides",
|
|
231
249
|
kyAemX: "lb1esw782",
|
|
232
250
|
kLZC3w: "lb1v8p93f",
|
|
251
|
+
kB7OPa: "lb9f619",
|
|
233
252
|
k1xSpc: "lb1rg5ohu",
|
|
253
|
+
kmuXW: "lb2lah0s",
|
|
234
254
|
kZKoxP: "lb1kpxq89",
|
|
235
255
|
kzqmXN: "lbsmyaan",
|
|
236
256
|
$$css: true
|
package/es/Button/style.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.mjs","names":[],"sources":["../../src/Button/style.ts"],"sourcesContent":["import * as stylex from '@stylexjs/stylex';\n\nimport { cssVar } from '@/styles/stylex/cssVar.stylex';\n\nexport const buttonPaddingInline = {\n large: 16,\n middle: 14,\n small: 8,\n} as const;\n\nconst disabled = ':is(:disabled, [aria-disabled=\"true\"])';\nconst hover = ':hover:not(:disabled, [aria-disabled=\"true\"])';\nconst active = ':active:not(:disabled, [aria-disabled=\"true\"])';\nconst hoverIdle = ':hover:not(:active, :disabled, [aria-disabled=\"true\"])';\nconst hoverIdleClosed = ':hover:not(:active, :disabled, [aria-disabled=\"true\"], [data-popup-open])';\nconst popupOpen = ':is([data-popup-open])';\n\nconst spin = stylex.keyframes({\n to: { transform: 'rotate(360deg)' },\n});\n\nconst ease = 'cubic-bezier(0.32, 0.72, 0, 1)';\n\nconst errorHover = `color-mix(in srgb, ${cssVar.colorError} 88%, white)`;\nconst errorActive = `color-mix(in srgb, ${cssVar.colorError} 88%, black)`;\nconst borderHover = `color-mix(in srgb, ${cssVar.colorText} 8%, ${cssVar.colorBorder})`;\nconst neutralWash = `linear-gradient(${cssVar.colorFillTertiary}, ${cssVar.colorFillTertiary})`;\nconst neutralWashActive = `linear-gradient(${cssVar.colorFillSecondary}, ${cssVar.colorFillSecondary})`;\nconst error10 = `color-mix(in srgb, ${cssVar.colorError} 10%, transparent)`;\nconst error12 = `color-mix(in srgb, ${cssVar.colorError} 12%, transparent)`;\nconst error16 = `color-mix(in srgb, ${cssVar.colorError} 16%, transparent)`;\nconst error18 = `color-mix(in srgb, ${cssVar.colorError} 18%, transparent)`;\nconst error22 = `color-mix(in srgb, ${cssVar.colorError} 22%, transparent)`;\nconst error40 = `color-mix(in srgb, ${cssVar.colorError} 40%, transparent)`;\nconst error65 = `color-mix(in srgb, ${cssVar.colorError} 65%, transparent)`;\nconst errorOnContainer8 = `color-mix(in srgb, ${cssVar.colorError} 8%, ${cssVar.colorBgContainer})`;\nconst errorOnContainer14 = `color-mix(in srgb, ${cssVar.colorError} 14%, ${cssVar.colorBgContainer})`;\nconst slotEase = 'cubic-bezier(0.22, 1, 0.36, 1)';\n\nexport const styles = stylex.create({\n base: {\n borderColor: cssVar.colorBorder,\n borderStyle: 'solid',\n borderWidth: 1,\n gap: 6,\n textDecoration: 'none',\n transition: `color 160ms ${ease}, background-color 160ms ${ease}, background-image 160ms ${ease}, border-color 160ms ${ease}, box-shadow 160ms ${ease}`,\n alignItems: 'center',\n boxSizing: 'border-box',\n cursor: { default: 'pointer', [disabled]: 'not-allowed' },\n display: 'inline-flex',\n fontWeight: 500,\n justifyContent: 'center',\n lineHeight: 1,\n opacity: { default: null, [disabled]: 0.5 },\n pointerEvents: { default: null, [disabled]: 'none' },\n position: 'relative',\n whiteSpace: 'nowrap',\n },\n\n sizeSmall: {\n '--button-padding-inline': `${buttonPaddingInline.small}px`,\n 'borderRadius': cssVar.borderRadiusSM,\n 'paddingInline': 'var(--button-padding-inline)',\n 'fontSize': 12,\n 'height': 24,\n },\n\n sizeMiddle: {\n '--button-padding-inline': `${buttonPaddingInline.middle}px`,\n 'borderRadius': cssVar.borderRadiusSM,\n 'paddingInline': 'var(--button-padding-inline)',\n 'fontSize': 13,\n 'height': 32,\n },\n\n sizeLarge: {\n '--button-padding-inline': `${buttonPaddingInline.large}px`,\n 'borderRadius': cssVar.borderRadius,\n 'paddingInline': 'var(--button-padding-inline)',\n 'fontSize': 14,\n 'height': 40,\n },\n\n outdentStart: {\n marginInlineStart: 'calc(var(--button-padding-inline) * -1)',\n },\n\n outdentEnd: {\n marginInlineEnd: 'calc(var(--button-padding-inline) * -1)',\n },\n\n shapeCircle: {\n borderRadius: '50%',\n paddingInline: 0,\n },\n\n shapeRound: {\n borderRadius: 999,\n },\n\n block: {\n width: '100%',\n },\n\n iconEnd: {\n flexDirection: 'row-reverse',\n },\n\n iconOnlySmall: {\n '--button-padding-inline': '0px',\n 'paddingInline': 0,\n 'width': 24,\n },\n\n iconOnlyMiddle: {\n '--button-padding-inline': '0px',\n 'paddingInline': 0,\n 'width': 32,\n },\n\n iconOnlyLarge: {\n '--button-padding-inline': '0px',\n 'paddingInline': 0,\n 'width': 40,\n },\n\n iconBox: {\n alignItems: 'center',\n display: 'inline-flex',\n justifyContent: 'center',\n },\n\n spinnerSlot: {\n overflow: 'hidden',\n transition: `width 380ms ${slotEase}, margin 380ms ${slotEase}, opacity 260ms ${slotEase}`,\n marginInlineEnd: -6,\n opacity: 0,\n width: 0,\n },\n\n spinnerSlotEnd: {\n marginInlineEnd: 0,\n marginInlineStart: -6,\n },\n\n spinnerSlotShow: {\n marginInlineEnd: 0,\n marginInlineStart: 0,\n opacity: 1,\n width: 12,\n },\n\n variantDefault: {\n borderColor: { default: cssVar.colorBorder, [hover]: borderHover },\n backgroundColor: cssVar.colorBgContainer,\n backgroundImage: {\n [active]: neutralWashActive,\n default: null,\n [hoverIdle]: neutralWash,\n },\n color: cssVar.colorText,\n },\n\n variantPrimary: {\n borderColor: {\n [active]: cssVar.colorPrimaryActive,\n default: cssVar.colorPrimary,\n [hoverIdleClosed]: cssVar.colorPrimaryHover,\n [popupOpen]: cssVar.colorPrimaryActive,\n },\n backgroundColor: {\n [active]: cssVar.colorPrimaryActive,\n default: cssVar.colorPrimary,\n [hoverIdleClosed]: cssVar.colorPrimaryHover,\n [popupOpen]: cssVar.colorPrimaryActive,\n },\n color: cssVar.colorBgLayout,\n },\n\n variantDashed: {\n borderColor: { default: cssVar.colorBorder, [hover]: borderHover },\n borderStyle: 'dashed',\n backgroundColor: cssVar.colorBgContainer,\n backgroundImage: {\n [active]: neutralWashActive,\n default: null,\n [hoverIdle]: neutralWash,\n },\n color: cssVar.colorText,\n },\n\n variantFill: {\n borderColor: 'transparent',\n backgroundColor: {\n [active]: cssVar.colorFill,\n default: cssVar.colorFillTertiary,\n [hoverIdle]: cssVar.colorFillSecondary,\n },\n color: cssVar.colorText,\n },\n\n variantText: {\n borderColor: 'transparent',\n backgroundColor: { default: 'transparent', [hover]: cssVar.colorFillSecondary },\n color: cssVar.colorText,\n },\n\n variantLink: {\n borderColor: 'transparent',\n paddingInline: 0,\n backgroundColor: 'transparent',\n color: { default: cssVar.colorPrimary, [hover]: cssVar.colorPrimaryHover },\n },\n\n dangerOutlined: {\n borderColor: { default: error40, [hover]: error65 },\n backgroundColor: {\n [active]: errorOnContainer14,\n default: cssVar.colorBgContainer,\n [hoverIdle]: errorOnContainer8,\n },\n backgroundImage: null,\n color: cssVar.colorError,\n },\n\n dangerSolid: {\n borderColor: {\n [active]: errorActive,\n default: cssVar.colorError,\n [hoverIdleClosed]: errorHover,\n [popupOpen]: errorActive,\n },\n backgroundColor: {\n [active]: errorActive,\n default: cssVar.colorError,\n [hoverIdleClosed]: errorHover,\n [popupOpen]: errorActive,\n },\n color: cssVar.colorBgLayout,\n },\n\n dangerFill: {\n borderColor: 'transparent',\n backgroundColor: {\n [active]: error22,\n default: error12,\n [hoverIdle]: error18,\n },\n color: cssVar.colorError,\n },\n\n dangerText: {\n backgroundColor: {\n [active]: error16,\n default: 'transparent',\n [hoverIdle]: error10,\n },\n color: cssVar.colorError,\n },\n\n dangerInline: {\n color: { default: cssVar.colorError, [hover]: errorHover },\n },\n\n ghostDefault: {\n borderColor: 'transparent',\n backgroundColor: {\n [active]: cssVar.colorFill,\n default: 'transparent',\n [hoverIdle]: cssVar.colorFillSecondary,\n },\n color: cssVar.colorText,\n },\n\n ghostPrimary: {\n borderColor: 'transparent',\n backgroundColor: {\n [active]: cssVar.colorFill,\n default: 'transparent',\n [hoverIdle]: cssVar.colorFillSecondary,\n },\n color: {\n [active]: cssVar.colorPrimaryActive,\n default: cssVar.colorPrimary,\n [hoverIdle]: cssVar.colorPrimaryHover,\n },\n },\n\n ghostDanger: {\n borderColor: 'transparent',\n backgroundColor: {\n [active]: error16,\n default: 'transparent',\n [hoverIdle]: error10,\n },\n color: cssVar.colorError,\n },\n\n spinner: {\n borderColor: 'currentcolor',\n borderRadius: '50%',\n borderStyle: 'solid',\n borderWidth: 1.5,\n animationDuration: '0.6s',\n animationIterationCount: 'infinite',\n animationName: spin,\n animationTimingFunction: 'linear',\n borderBlockStartColor: 'transparent',\n display: 'inline-block',\n height: 12,\n width: 12,\n },\n});\n\nconst hasHover = ':has(> :where(button, a):hover:not(:disabled, [aria-disabled=\"true\"]))';\nconst hasActive = ':has(> :where(button, a):active:not(:disabled, [aria-disabled=\"true\"]))';\nconst hasHoverOnly = `${hasHover}:not(${hasActive})`;\nconst first = ':first-of-type';\nconst last = ':last-of-type';\n\nexport const splitStyles = stylex.create({\n root: {\n display: 'inline-flex',\n flexDirection: 'row',\n },\n interactionDisabled: {\n opacity: 0.5,\n },\n solidPrimary: {\n '--lobe-split-button-fill': {\n default: null,\n [hasActive]: cssVar.colorPrimaryActive,\n [hasHoverOnly]: cssVar.colorPrimaryHover,\n },\n },\n solidDanger: {\n '--lobe-split-button-fill': {\n default: null,\n [hasActive]: errorActive,\n [hasHoverOnly]: errorHover,\n },\n },\n item: {\n borderEndEndRadius: { default: null, [first]: 0 },\n borderEndStartRadius: { default: null, [last]: 0 },\n borderStartEndRadius: { default: null, [first]: 0 },\n borderStartStartRadius: { default: null, [last]: 0 },\n marginInlineStart: { default: null, [last]: -1 },\n },\n itemInteractionDisabled: {\n opacity: { default: null, [disabled]: 1 },\n },\n itemSolid: {\n // solid halves share one color, so the outline-merging overlap only adds a dark seam once each half is translucent (disabled)\n 'marginInlineStart': { default: null, [last]: 0 },\n '::before': {\n insetBlock: { default: null, [last]: 0 },\n backgroundColor: { default: null, [last]: 'currentcolor' },\n content: { default: null, [last]: \"''\" },\n insetInlineStart: { default: null, [last]: 0 },\n opacity: { default: null, [last]: 0.2 },\n pointerEvents: { default: null, [last]: 'none' },\n position: { default: null, [last]: 'absolute' },\n width: { default: null, [last]: 1 },\n },\n },\n itemFillDanger: {\n borderColor: {\n default: `var(--lobe-split-button-fill, ${cssVar.colorError})`,\n [popupOpen]: errorActive,\n },\n backgroundColor: {\n default: `var(--lobe-split-button-fill, ${cssVar.colorError})`,\n [popupOpen]: errorActive,\n },\n },\n itemFillGhost: {\n borderColor: 'var(--lobe-split-button-fill, transparent)',\n backgroundColor: 'var(--lobe-split-button-fill, transparent)',\n },\n itemFillPrimary: {\n borderColor: {\n default: `var(--lobe-split-button-fill, ${cssVar.colorPrimary})`,\n [popupOpen]: cssVar.colorPrimaryActive,\n },\n backgroundColor: {\n default: `var(--lobe-split-button-fill, ${cssVar.colorPrimary})`,\n [popupOpen]: cssVar.colorPrimaryActive,\n },\n },\n});\n\nexport const buttonStyles = Object.fromEntries(\n Object.entries(styles).map(([key, value]) => [key, stylex.props(value).className ?? '']),\n) as Record<keyof typeof styles, string>;\n"],"mappings":";;;AAGA,MAAa,sBAAsB;CACjC,OAAO;CACP,QAAQ;CACR,OAAO;AACT;AASmB,GAAsB,OAAO;AAC5B,GAAsB,OAAO;AAC7B,GAAsB,OAAO,YAAiB,OAAO;AACrD,GAAmB,OAAO,oBAAsB,OAAO;AACjD,GAAmB,OAAO,qBAAuB,OAAO;AAClE,GAAsB,OAAO;AAC7B,GAAsB,OAAO;AAC7B,GAAsB,OAAO;AAC7B,GAAsB,OAAO;AAC7B,GAAsB,OAAO;AAC7B,GAAsB,OAAO;AAC7B,GAAsB,OAAO;AACnB,GAAsB,OAAO,aAAkB,OAAO;AACrD,GAAsB,OAAO,aAAmB,OAAO;AAElF,MAAa,SAAS;CACpB,MAAM;EACJ,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;CACA,WAAW;EACT,2BAA2B;EAC3B,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;CACA,YAAY;EACV,2BAA2B;EAC3B,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,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ACR,OAAO;CACT;CACA,iBAAiB;EACf,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;AACF;AACA,MAAa,eAAe,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,OAAO,MAAM,KAAK,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"style.mjs","names":[],"sources":["../../src/Button/style.ts"],"sourcesContent":["import * as stylex from '@stylexjs/stylex';\n\nimport { cssVar } from '@/styles/stylex/cssVar.stylex';\n\nexport const buttonPaddingInline = {\n large: 16,\n middle: 14,\n small: 8,\n} as const;\n\nconst disabled = ':is(:disabled, [aria-disabled=\"true\"])';\nconst hover = ':hover:not(:disabled, [aria-disabled=\"true\"])';\nconst active = ':active:not(:disabled, [aria-disabled=\"true\"])';\nconst hoverIdle = ':hover:not(:active, :disabled, [aria-disabled=\"true\"])';\nconst hoverIdleClosed = ':hover:not(:active, :disabled, [aria-disabled=\"true\"], [data-popup-open])';\nconst popupOpen = ':is([data-popup-open])';\n\nconst spin = stylex.keyframes({\n to: { transform: 'rotate(360deg)' },\n});\n\nconst ease = 'cubic-bezier(0.32, 0.72, 0, 1)';\n\nconst errorHover = `color-mix(in srgb, ${cssVar.colorError} 88%, white)`;\nconst errorActive = `color-mix(in srgb, ${cssVar.colorError} 88%, black)`;\nconst borderHover = `color-mix(in srgb, ${cssVar.colorText} 8%, ${cssVar.colorBorder})`;\nconst neutralWash = `linear-gradient(${cssVar.colorFillTertiary}, ${cssVar.colorFillTertiary})`;\nconst neutralWashActive = `linear-gradient(${cssVar.colorFillSecondary}, ${cssVar.colorFillSecondary})`;\nconst error10 = `color-mix(in srgb, ${cssVar.colorError} 10%, transparent)`;\nconst error12 = `color-mix(in srgb, ${cssVar.colorError} 12%, transparent)`;\nconst error16 = `color-mix(in srgb, ${cssVar.colorError} 16%, transparent)`;\nconst error18 = `color-mix(in srgb, ${cssVar.colorError} 18%, transparent)`;\nconst error22 = `color-mix(in srgb, ${cssVar.colorError} 22%, transparent)`;\nconst error40 = `color-mix(in srgb, ${cssVar.colorError} 40%, transparent)`;\nconst error65 = `color-mix(in srgb, ${cssVar.colorError} 65%, transparent)`;\nconst errorOnContainer8 = `color-mix(in srgb, ${cssVar.colorError} 8%, ${cssVar.colorBgContainer})`;\nconst errorOnContainer14 = `color-mix(in srgb, ${cssVar.colorError} 14%, ${cssVar.colorBgContainer})`;\nconst slotEase = 'cubic-bezier(0.22, 1, 0.36, 1)';\n\nexport const styles = stylex.create({\n base: {\n borderColor: cssVar.colorBorder,\n borderStyle: 'solid',\n borderWidth: 1,\n gap: 6,\n textDecoration: 'none',\n transition: `color 160ms ${ease}, background-color 160ms ${ease}, background-image 160ms ${ease}, border-color 160ms ${ease}, box-shadow 160ms ${ease}`,\n alignItems: 'center',\n boxSizing: 'border-box',\n cursor: { default: 'pointer', [disabled]: 'not-allowed' },\n display: 'inline-flex',\n fontWeight: 500,\n justifyContent: 'center',\n lineHeight: 1,\n opacity: { default: null, [disabled]: 0.5 },\n pointerEvents: { default: null, [disabled]: 'none' },\n position: 'relative',\n whiteSpace: 'nowrap',\n },\n\n sizeSmall: {\n '--button-padding-inline': `${buttonPaddingInline.small}px`,\n 'borderRadius': cssVar.borderRadiusSM,\n 'paddingInline': 'var(--button-padding-inline)',\n 'fontSize': 12,\n 'height': 24,\n },\n\n sizeMiddle: {\n '--button-padding-inline': `${buttonPaddingInline.middle}px`,\n 'borderRadius': cssVar.borderRadiusSM,\n 'paddingInline': 'var(--button-padding-inline)',\n 'fontSize': 13,\n 'height': 32,\n },\n\n sizeLarge: {\n '--button-padding-inline': `${buttonPaddingInline.large}px`,\n 'borderRadius': cssVar.borderRadius,\n 'paddingInline': 'var(--button-padding-inline)',\n 'fontSize': 14,\n 'height': 40,\n },\n\n outdentStart: {\n marginInlineStart: 'calc(var(--button-padding-inline) * -1)',\n },\n\n outdentEnd: {\n marginInlineEnd: 'calc(var(--button-padding-inline) * -1)',\n },\n\n shapeCircle: {\n borderRadius: '50%',\n paddingInline: 0,\n },\n\n shapeRound: {\n borderRadius: 999,\n },\n\n block: {\n width: '100%',\n },\n\n iconEnd: {\n flexDirection: 'row-reverse',\n },\n\n iconOnlySmall: {\n '--button-padding-inline': '0px',\n 'paddingInline': 0,\n 'width': 24,\n },\n\n iconOnlyMiddle: {\n '--button-padding-inline': '0px',\n 'paddingInline': 0,\n 'width': 32,\n },\n\n iconOnlyLarge: {\n '--button-padding-inline': '0px',\n 'paddingInline': 0,\n 'width': 40,\n },\n\n iconBox: {\n alignItems: 'center',\n display: 'inline-flex',\n justifyContent: 'center',\n },\n\n spinnerSlot: {\n overflow: 'visible',\n transition: `width 300ms ${slotEase}, margin 300ms ${slotEase}`,\n flexShrink: 0,\n marginInlineEnd: -6,\n position: 'relative',\n height: 12,\n width: 0,\n },\n\n spinnerSlotEnd: {\n marginInlineEnd: 0,\n marginInlineStart: -6,\n },\n\n spinnerSlotShow: {\n marginInlineEnd: 0,\n marginInlineStart: 0,\n width: 12,\n },\n\n spinnerVisual: {\n transition: `transform 180ms ${slotEase}, opacity 180ms ease-out`,\n insetBlockStart: 0,\n insetInlineStart: 0,\n opacity: 0,\n position: 'absolute',\n transform: 'scale(0.5)',\n transformOrigin: 'center',\n height: 12,\n width: 12,\n },\n\n spinnerVisualShow: {\n opacity: 1,\n transform: 'scale(1)',\n },\n\n variantDefault: {\n borderColor: { default: cssVar.colorBorder, [hover]: borderHover },\n backgroundColor: cssVar.colorBgContainer,\n backgroundImage: {\n [active]: neutralWashActive,\n default: null,\n [hoverIdle]: neutralWash,\n },\n color: cssVar.colorText,\n },\n\n variantPrimary: {\n borderColor: {\n [active]: cssVar.colorPrimaryActive,\n default: cssVar.colorPrimary,\n [hoverIdleClosed]: cssVar.colorPrimaryHover,\n [popupOpen]: cssVar.colorPrimaryActive,\n },\n backgroundColor: {\n [active]: cssVar.colorPrimaryActive,\n default: cssVar.colorPrimary,\n [hoverIdleClosed]: cssVar.colorPrimaryHover,\n [popupOpen]: cssVar.colorPrimaryActive,\n },\n color: cssVar.colorBgLayout,\n },\n\n variantDashed: {\n borderColor: { default: cssVar.colorBorder, [hover]: borderHover },\n borderStyle: 'dashed',\n backgroundColor: cssVar.colorBgContainer,\n backgroundImage: {\n [active]: neutralWashActive,\n default: null,\n [hoverIdle]: neutralWash,\n },\n color: cssVar.colorText,\n },\n\n variantFill: {\n borderColor: 'transparent',\n backgroundColor: {\n [active]: cssVar.colorFill,\n default: cssVar.colorFillTertiary,\n [hoverIdle]: cssVar.colorFillSecondary,\n },\n color: cssVar.colorText,\n },\n\n variantText: {\n borderColor: 'transparent',\n backgroundColor: { default: 'transparent', [hover]: cssVar.colorFillSecondary },\n color: cssVar.colorText,\n },\n\n variantLink: {\n borderColor: 'transparent',\n paddingInline: 0,\n backgroundColor: 'transparent',\n color: { default: cssVar.colorPrimary, [hover]: cssVar.colorPrimaryHover },\n },\n\n dangerOutlined: {\n borderColor: { default: error40, [hover]: error65 },\n backgroundColor: {\n [active]: errorOnContainer14,\n default: cssVar.colorBgContainer,\n [hoverIdle]: errorOnContainer8,\n },\n backgroundImage: null,\n color: cssVar.colorError,\n },\n\n dangerSolid: {\n borderColor: {\n [active]: errorActive,\n default: cssVar.colorError,\n [hoverIdleClosed]: errorHover,\n [popupOpen]: errorActive,\n },\n backgroundColor: {\n [active]: errorActive,\n default: cssVar.colorError,\n [hoverIdleClosed]: errorHover,\n [popupOpen]: errorActive,\n },\n color: cssVar.colorBgLayout,\n },\n\n dangerFill: {\n borderColor: 'transparent',\n backgroundColor: {\n [active]: error22,\n default: error12,\n [hoverIdle]: error18,\n },\n color: cssVar.colorError,\n },\n\n dangerText: {\n backgroundColor: {\n [active]: error16,\n default: 'transparent',\n [hoverIdle]: error10,\n },\n color: cssVar.colorError,\n },\n\n dangerInline: {\n color: { default: cssVar.colorError, [hover]: errorHover },\n },\n\n ghostDefault: {\n borderColor: 'transparent',\n backgroundColor: {\n [active]: cssVar.colorFill,\n default: 'transparent',\n [hoverIdle]: cssVar.colorFillSecondary,\n },\n color: cssVar.colorText,\n },\n\n ghostPrimary: {\n borderColor: 'transparent',\n backgroundColor: {\n [active]: cssVar.colorFill,\n default: 'transparent',\n [hoverIdle]: cssVar.colorFillSecondary,\n },\n color: {\n [active]: cssVar.colorPrimaryActive,\n default: cssVar.colorPrimary,\n [hoverIdle]: cssVar.colorPrimaryHover,\n },\n },\n\n ghostDanger: {\n borderColor: 'transparent',\n backgroundColor: {\n [active]: error16,\n default: 'transparent',\n [hoverIdle]: error10,\n },\n color: cssVar.colorError,\n },\n\n spinner: {\n borderColor: 'currentcolor',\n borderRadius: '50%',\n borderStyle: 'solid',\n borderWidth: 1.5,\n animationDuration: '0.6s',\n animationIterationCount: 'infinite',\n animationName: spin,\n animationTimingFunction: 'linear',\n borderBlockStartColor: 'transparent',\n boxSizing: 'border-box',\n display: 'inline-block',\n flexShrink: 0,\n height: 12,\n width: 12,\n },\n});\n\nconst hasHover = ':has(> :where(button, a):hover:not(:disabled, [aria-disabled=\"true\"]))';\nconst hasActive = ':has(> :where(button, a):active:not(:disabled, [aria-disabled=\"true\"]))';\nconst hasHoverOnly = `${hasHover}:not(${hasActive})`;\nconst first = ':first-of-type';\nconst last = ':last-of-type';\n\nexport const splitStyles = stylex.create({\n root: {\n display: 'inline-flex',\n flexDirection: 'row',\n },\n interactionDisabled: {\n opacity: 0.5,\n },\n solidPrimary: {\n '--lobe-split-button-fill': {\n default: null,\n [hasActive]: cssVar.colorPrimaryActive,\n [hasHoverOnly]: cssVar.colorPrimaryHover,\n },\n },\n solidDanger: {\n '--lobe-split-button-fill': {\n default: null,\n [hasActive]: errorActive,\n [hasHoverOnly]: errorHover,\n },\n },\n item: {\n borderEndEndRadius: { default: null, [first]: 0 },\n borderEndStartRadius: { default: null, [last]: 0 },\n borderStartEndRadius: { default: null, [first]: 0 },\n borderStartStartRadius: { default: null, [last]: 0 },\n marginInlineStart: { default: null, [last]: -1 },\n },\n itemInteractionDisabled: {\n opacity: { default: null, [disabled]: 1 },\n },\n itemSolid: {\n // solid halves share one color, so the outline-merging overlap only adds a dark seam once each half is translucent (disabled)\n 'marginInlineStart': { default: null, [last]: 0 },\n '::before': {\n insetBlock: { default: null, [last]: 0 },\n backgroundColor: { default: null, [last]: 'currentcolor' },\n content: { default: null, [last]: \"''\" },\n insetInlineStart: { default: null, [last]: 0 },\n opacity: { default: null, [last]: 0.2 },\n pointerEvents: { default: null, [last]: 'none' },\n position: { default: null, [last]: 'absolute' },\n width: { default: null, [last]: 1 },\n },\n },\n itemFillDanger: {\n borderColor: {\n default: `var(--lobe-split-button-fill, ${cssVar.colorError})`,\n [popupOpen]: errorActive,\n },\n backgroundColor: {\n default: `var(--lobe-split-button-fill, ${cssVar.colorError})`,\n [popupOpen]: errorActive,\n },\n },\n itemFillGhost: {\n borderColor: 'var(--lobe-split-button-fill, transparent)',\n backgroundColor: 'var(--lobe-split-button-fill, transparent)',\n },\n itemFillPrimary: {\n borderColor: {\n default: `var(--lobe-split-button-fill, ${cssVar.colorPrimary})`,\n [popupOpen]: cssVar.colorPrimaryActive,\n },\n backgroundColor: {\n default: `var(--lobe-split-button-fill, ${cssVar.colorPrimary})`,\n [popupOpen]: cssVar.colorPrimaryActive,\n },\n },\n});\n\nexport const buttonStyles = Object.fromEntries(\n Object.entries(styles).map(([key, value]) => [key, stylex.props(value).className ?? '']),\n) as Record<keyof typeof styles, string>;\n"],"mappings":";;;AAGA,MAAa,sBAAsB;CACjC,OAAO;CACP,QAAQ;CACR,OAAO;AACT;AASmB,GAAsB,OAAO;AAC5B,GAAsB,OAAO;AAC7B,GAAsB,OAAO,YAAiB,OAAO;AACrD,GAAmB,OAAO,oBAAsB,OAAO;AACjD,GAAmB,OAAO,qBAAuB,OAAO;AAClE,GAAsB,OAAO;AAC7B,GAAsB,OAAO;AAC7B,GAAsB,OAAO;AAC7B,GAAsB,OAAO;AAC7B,GAAsB,OAAO;AAC7B,GAAsB,OAAO;AA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ACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;AACF;AAMA,MAAa,cAAc;CACzB,MAAM;EACJ,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;CACA,qBAAqB;EACnB,QAAQ;EACR,OAAO;CACT;CACA,cAAc;EACZ,4BAA4B;EAC5B,OAAO;CACT;CACA,aAAa;EACX,4BAA4B;EAC5B,OAAO;CACT;CACA,MAAM;EACJ,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;CACA,yBAAyB;EACvB,QAAQ;EACR,OAAO;CACT;CACA,WAAW;EACT,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;CACA,gBAAgB;EACd,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;CACA,eAAe;EACb,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;CACA,iBAAiB;EACf,QAAQ;EACR,QAAQ;EACR,OAAO;CACT;AACF;AACA,MAAa,eAAe,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,OAAO,MAAM,KAAK,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC"}
|
|
@@ -51,6 +51,7 @@ const ImageViewer = memo(({ entries, index, openerFocusElement, token }) => {
|
|
|
51
51
|
maxScale: currentEntry.options.maxScale,
|
|
52
52
|
natural,
|
|
53
53
|
onCloseRequest: requestClose,
|
|
54
|
+
pixelRatio: currentEntry.options.pixelRatio,
|
|
54
55
|
viewport
|
|
55
56
|
});
|
|
56
57
|
const fitRect = useMemo(() => computeFit(natural, viewport, rotation, fillViewport), [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageViewer.mjs","names":[],"sources":["../../../src/Image/viewer/ImageViewer.tsx"],"sourcesContent":["'use client';\n\nimport '../style.css';\n\nimport { Dialog, type DialogRootProps } from '@base-ui/react/dialog';\nimport {\n memo,\n type SyntheticEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { useAppElement } from '@/ConfigProvider/AppElementContext';\nimport { useLayerZIndex } from '@/internal/zIndex';\nimport { styleProps } from '@/styles/stylex/props';\nimport { ToastHost } from '@/Toast';\nimport { useMergeRefs } from '@/utils/mergeRefs';\n\nimport { styles } from '../style';\nimport { computeFit, type Size, unrotatedRect } from './geometry';\nimport { beginClosePreview, endClosePreview, type PreviewEntry } from './registry';\nimport { useFinalFocus } from './useFinalFocus';\nimport { useFlipTransition } from './useFlipTransition';\nimport { readNatural, useGalleryNav } from './useGalleryNav';\nimport { useRefitTransition } from './useRefitTransition';\nimport { useViewerGestures } from './useViewerGestures';\nimport { useZoomPan } from './useZoomPan';\nimport ViewerChrome from './ViewerChrome';\n\nexport interface ImageViewerProps {\n entries: PreviewEntry[];\n index: number;\n openerFocusElement: HTMLElement | null;\n token: number;\n}\n\nconst readViewport = (): Size => ({ height: window.innerHeight, width: window.innerWidth });\n\nconst prefersReducedMotion = () =>\n window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;\n\nconst ImageViewer = memo<ImageViewerProps>(({ entries, index, openerFocusElement, token }) => {\n const openerEntry = entries[index];\n const appElement = useAppElement();\n const [animated] = useState(() => !prefersReducedMotion());\n\n const { ref: layerRef, zIndex } = useLayerZIndex<HTMLDivElement>('modal');\n\n const [currentIndex, setCurrentIndex] = useState(index);\n const currentEntry = entries[currentIndex];\n const currentEntryRef = useRef(currentEntry);\n currentEntryRef.current = currentEntry;\n\n const [source, setSource] = useState(openerEntry.src);\n const [natural, setNatural] = useState<Size>(() => readNatural(openerEntry.element));\n const [viewport, setViewport] = useState<Size>(readViewport);\n\n const closeRef = useRef<(() => void) | null>(null);\n const requestClose = useCallback(() => closeRef.current?.(), []);\n\n // useZoomPan needs to gate its wheel/toolbar entry points on close-in-flight,\n // but that state only exists once useFlipTransition (below) has run — and it\n // needs useZoomPan's own transform values first. Break the cycle with a\n // stable indirection: the ref is repointed at the real isClosing once it's\n // available, written directly during render like the other *Ref fields here.\n const isClosingIndirectRef = useRef<() => boolean>(() => false);\n const isClosingIndirect = useCallback(() => isClosingIndirectRef.current(), []);\n\n const isTransitioningIndirectRef = useRef<() => boolean>(() => true);\n const isTransitioningIndirect = useCallback(() => isTransitioningIndirectRef.current(), []);\n\n const fillViewport = Boolean(\n currentEntry.previewSrc && currentEntry.previewSrc !== currentEntry.src,\n );\n\n const {\n canZoomIn,\n canZoomOut,\n dragBy,\n dragEnd,\n escIntent,\n flipHorizontal,\n flipVertical,\n flipX,\n flipY,\n getInitialScale,\n handleDoubleClick,\n handleWheel,\n isClean,\n isZoomed,\n reset,\n resetCloseTracking,\n rotate,\n rotateLeft,\n rotateRight,\n rotation,\n scale,\n setNatural: syncZoomNatural,\n setViewport: syncZoomViewport,\n toggleActualSize,\n x,\n y,\n zoomIn,\n zoomOut,\n } = useZoomPan({\n autoZoomThreshold: currentEntry.options.autoZoomThreshold,\n defaultZoom: currentEntry.options.defaultZoom,\n fillViewport,\n isClosing: isClosingIndirect,\n isTransitioning: isTransitioningIndirect,\n maxScale: currentEntry.options.maxScale,\n natural,\n onCloseRequest: requestClose,\n viewport,\n });\n\n const fitRect = useMemo(\n () => computeFit(natural, viewport, rotation, fillViewport),\n [natural, viewport, rotation, fillViewport],\n );\n const fitRectRef = useRef(fitRect);\n fitRectRef.current = fitRect;\n const getFitRect = useCallback(() => fitRectRef.current, []);\n\n const imageRect = useMemo(() => unrotatedRect(fitRect, rotation), [fitRect, rotation]);\n\n const viewportRef = useRef(viewport);\n viewportRef.current = viewport;\n const getViewportWidth = useCallback(() => viewportRef.current.width, []);\n\n const getCloseSource = useCallback(() => currentEntryRef.current.element, []);\n\n const transform = useMemo(\n () => ({ flipX, flipY, rotate, scale, x, y }),\n [flipX, flipY, rotate, scale, x, y],\n );\n const handleClosed = useCallback(() => endClosePreview(token), [token]);\n\n const {\n backdropRef,\n chromeRef,\n close,\n imageRef: flipImageRef,\n isClosing,\n isTransitioning,\n switchTo,\n } = useFlipTransition({\n animated,\n getCloseSource,\n getFitRect,\n getInitialScale,\n getViewportWidth,\n onClosed: handleClosed,\n source: openerEntry.element,\n transform,\n });\n isClosingIndirectRef.current = isClosing;\n isTransitioningIndirectRef.current = isTransitioning;\n\n useRefitTransition({\n animated,\n fillViewport,\n isTransitioning,\n natural,\n rotation,\n scale,\n viewport,\n x,\n y,\n });\n const finalFocus = useFinalFocus(openerFocusElement);\n\n const isCleanRef = useRef(isClean);\n isCleanRef.current = isClean;\n\n const handleClose = useCallback(() => {\n beginClosePreview(token);\n close({ fade: !isCleanRef.current });\n }, [close, token]);\n closeRef.current = handleClose;\n\n const handleDialogOpenChange = useCallback<NonNullable<DialogRootProps['onOpenChange']>>(\n (open, eventDetails) => {\n if (open) return;\n // Base UI fires this on every Esc regardless of whether we're already\n // mid-close (our Dialog.Root's open prop never actually flips to\n // false), so without this guard a second Esc during the close window\n // reads escIntent() off the close spring's mid-flight scale, decides\n // 'reset', and cancels the close animation out from under itself.\n if (isClosing()) return;\n if (eventDetails.reason === 'escape-key' && escIntent() === 'reset') {\n eventDetails.cancel();\n reset();\n return;\n }\n handleClose();\n },\n [escIntent, handleClose, isClosing, reset],\n );\n\n const gestures = useViewerGestures({\n dragBy,\n dragEnd,\n handleDoubleClick,\n handleWheel,\n isClean,\n isZoomed,\n onClose: handleClose,\n reset,\n zoomIn,\n zoomOut,\n });\n\n const { hasNext, hasPrev, next, prev } = useGalleryNav({\n cancelPendingClose: gestures.cancelPendingClose,\n currentIndex,\n entries,\n flipX,\n flipY,\n getInitialScale,\n resetCloseTracking,\n rotate,\n scale,\n setCurrentIndex,\n setNatural,\n setSource,\n switchTo,\n syncZoomNatural,\n x,\n y,\n });\n\n const popupNodeRef = useRef<HTMLDivElement | null>(null);\n const popupRef = useMergeRefs<HTMLDivElement>([layerRef, gestures.popupRef, popupNodeRef]);\n const imageRef = useMergeRefs<HTMLImageElement>([flipImageRef, gestures.imageRef]);\n\n const handleLoad = useCallback(\n (event: SyntheticEvent<HTMLImageElement>) => {\n const loaded = event.currentTarget;\n if (!loaded.naturalWidth || !loaded.naturalHeight) return;\n const next = { height: loaded.naturalHeight, width: loaded.naturalWidth };\n setNatural((prev) =>\n prev.width === next.width && prev.height === next.height ? prev : next,\n );\n syncZoomNatural(next);\n },\n [syncZoomNatural],\n );\n\n useEffect(() => {\n const handleResize = () => {\n const next = readViewport();\n setViewport(next);\n syncZoomViewport(next);\n };\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }, [syncZoomViewport]);\n\n useEffect(() => {\n const { previewSrc, src } = currentEntry;\n if (!previewSrc || previewSrc === src) return;\n let cancelled = false;\n const loader = new window.Image();\n const handleLoaded = () => {\n if (!cancelled) setSource(previewSrc);\n };\n loader.addEventListener('load', handleLoaded);\n loader.src = previewSrc;\n return () => {\n cancelled = true;\n loader.removeEventListener('load', handleLoaded);\n };\n }, [currentEntry]);\n\n useEffect(\n () => () => {\n const thumbnailWasRemoved = !openerEntry.element.isConnected;\n if (thumbnailWasRemoved) endClosePreview(token);\n },\n [openerEntry, token],\n );\n\n return (\n <Dialog.Root modal open onOpenChange={handleDialogOpenChange}>\n <Dialog.Portal container={appElement ?? undefined}>\n {/* Base UI drops a nested dialog's backdrop so overlays don't stack. The viewer is\n not an overlay on the surface it opened from — it replaces the screen — so it\n keeps its own scrim, or a viewer opened from a maskless drawer would show the\n page straight through the letterbox around the image. */}\n <Dialog.Backdrop\n forceRender\n {...styleProps(styles.viewerBackdrop, 'lobe-image-viewer-backdrop')}\n ref={backdropRef}\n style={zIndex === undefined ? undefined : { zIndex }}\n onClick={gestures.onSurfaceClick}\n />\n <Dialog.Popup\n aria-label={currentEntry.element.alt || undefined}\n {...styleProps(styles.viewerPopup, 'lobe-image-viewer-popup')}\n finalFocus={finalFocus}\n // Focus the popup itself instead of Base UI's default (the first\n // tabbable — the close button): a focus-visible close button pins\n // the idle auto-hide open forever and pops its tooltip on open.\n initialFocus={popupNodeRef}\n ref={popupRef}\n style={zIndex === undefined ? undefined : { zIndex: zIndex + 1 }}\n tabIndex={-1}\n onClick={gestures.onSurfaceClick}\n onPointerCancel={gestures.onPointerFinish}\n onPointerDown={gestures.onPointerDown}\n onPointerMove={gestures.onPointerMove}\n onPointerUp={gestures.onPointerFinish}\n >\n <img\n alt={currentEntry.element.alt}\n {...styleProps(styles.viewerImage, 'lobe-image-viewer-image')}\n ref={imageRef}\n src={source}\n style={{\n cursor: gestures.cursor,\n height: imageRect.height,\n left: imageRect.x,\n top: imageRect.y,\n width: imageRect.width,\n }}\n onClick={gestures.onImageClick}\n onDoubleClick={gestures.onImageDoubleClick}\n onLoad={handleLoad}\n />\n <ViewerChrome\n canZoomIn={canZoomIn}\n canZoomOut={canZoomOut}\n chromeRef={chromeRef}\n current={currentIndex}\n fetchImage={currentEntry.options.fetchImage}\n fitRect={fitRect}\n flipHorizontal={flipHorizontal}\n flipVertical={flipVertical}\n hasNext={hasNext}\n hasPrev={hasPrev}\n natural={natural}\n next={next}\n prev={prev}\n rotateLeft={rotateLeft}\n rotateRight={rotateRight}\n rotation={rotation}\n scale={scale}\n source={source}\n toggleActualSize={toggleActualSize}\n toolbarAddon={currentEntry.options.toolbarAddon}\n total={entries.length}\n zoomIn={zoomIn}\n zoomOut={zoomOut}\n onClose={handleClose}\n onDownload={currentEntry.options.onDownload}\n />\n </Dialog.Popup>\n <ToastHost root={appElement ?? undefined} />\n </Dialog.Portal>\n </Dialog.Root>\n );\n});\n\nImageViewer.displayName = 'ImageViewer';\n\nexport default ImageViewer;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,sBAA4B;CAAE,QAAQ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MACA;MACM;MACC;MACH;MACH;MACC;MACU;MAClB,cAAc,aAAa,QAAQ;MACnC,OAAO,QAAQ;MACP;MACC;MACT,SAAS;MACT,YAAY,aAAa,QAAQ;KAClC,CAAA,CACW;;IACd,oBAAC,WAAD,EAAW,MAAM,cAAc,KAAA,EAAY,CAAA;GAC9B;;CACJ,CAAA;AAEjB,CAAC;AAED,YAAY,cAAc"}
|
|
1
|
+
{"version":3,"file":"ImageViewer.mjs","names":[],"sources":["../../../src/Image/viewer/ImageViewer.tsx"],"sourcesContent":["'use client';\n\nimport '../style.css';\n\nimport { Dialog, type DialogRootProps } from '@base-ui/react/dialog';\nimport {\n memo,\n type SyntheticEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { useAppElement } from '@/ConfigProvider/AppElementContext';\nimport { useLayerZIndex } from '@/internal/zIndex';\nimport { styleProps } from '@/styles/stylex/props';\nimport { ToastHost } from '@/Toast';\nimport { useMergeRefs } from '@/utils/mergeRefs';\n\nimport { styles } from '../style';\nimport { computeFit, type Size, unrotatedRect } from './geometry';\nimport { beginClosePreview, endClosePreview, type PreviewEntry } from './registry';\nimport { useFinalFocus } from './useFinalFocus';\nimport { useFlipTransition } from './useFlipTransition';\nimport { readNatural, useGalleryNav } from './useGalleryNav';\nimport { useRefitTransition } from './useRefitTransition';\nimport { useViewerGestures } from './useViewerGestures';\nimport { useZoomPan } from './useZoomPan';\nimport ViewerChrome from './ViewerChrome';\n\nexport interface ImageViewerProps {\n entries: PreviewEntry[];\n index: number;\n openerFocusElement: HTMLElement | null;\n token: number;\n}\n\nconst readViewport = (): Size => ({ height: window.innerHeight, width: window.innerWidth });\n\nconst prefersReducedMotion = () =>\n window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;\n\nconst ImageViewer = memo<ImageViewerProps>(({ entries, index, openerFocusElement, token }) => {\n const openerEntry = entries[index];\n const appElement = useAppElement();\n const [animated] = useState(() => !prefersReducedMotion());\n\n const { ref: layerRef, zIndex } = useLayerZIndex<HTMLDivElement>('modal');\n\n const [currentIndex, setCurrentIndex] = useState(index);\n const currentEntry = entries[currentIndex];\n const currentEntryRef = useRef(currentEntry);\n currentEntryRef.current = currentEntry;\n\n const [source, setSource] = useState(openerEntry.src);\n const [natural, setNatural] = useState<Size>(() => readNatural(openerEntry.element));\n const [viewport, setViewport] = useState<Size>(readViewport);\n\n const closeRef = useRef<(() => void) | null>(null);\n const requestClose = useCallback(() => closeRef.current?.(), []);\n\n // useZoomPan needs to gate its wheel/toolbar entry points on close-in-flight,\n // but that state only exists once useFlipTransition (below) has run — and it\n // needs useZoomPan's own transform values first. Break the cycle with a\n // stable indirection: the ref is repointed at the real isClosing once it's\n // available, written directly during render like the other *Ref fields here.\n const isClosingIndirectRef = useRef<() => boolean>(() => false);\n const isClosingIndirect = useCallback(() => isClosingIndirectRef.current(), []);\n\n const isTransitioningIndirectRef = useRef<() => boolean>(() => true);\n const isTransitioningIndirect = useCallback(() => isTransitioningIndirectRef.current(), []);\n\n const fillViewport = Boolean(\n currentEntry.previewSrc && currentEntry.previewSrc !== currentEntry.src,\n );\n\n const {\n canZoomIn,\n canZoomOut,\n dragBy,\n dragEnd,\n escIntent,\n flipHorizontal,\n flipVertical,\n flipX,\n flipY,\n getInitialScale,\n handleDoubleClick,\n handleWheel,\n isClean,\n isZoomed,\n reset,\n resetCloseTracking,\n rotate,\n rotateLeft,\n rotateRight,\n rotation,\n scale,\n setNatural: syncZoomNatural,\n setViewport: syncZoomViewport,\n toggleActualSize,\n x,\n y,\n zoomIn,\n zoomOut,\n } = useZoomPan({\n autoZoomThreshold: currentEntry.options.autoZoomThreshold,\n defaultZoom: currentEntry.options.defaultZoom,\n fillViewport,\n isClosing: isClosingIndirect,\n isTransitioning: isTransitioningIndirect,\n maxScale: currentEntry.options.maxScale,\n natural,\n onCloseRequest: requestClose,\n pixelRatio: currentEntry.options.pixelRatio,\n viewport,\n });\n\n const fitRect = useMemo(\n () => computeFit(natural, viewport, rotation, fillViewport),\n [natural, viewport, rotation, fillViewport],\n );\n const fitRectRef = useRef(fitRect);\n fitRectRef.current = fitRect;\n const getFitRect = useCallback(() => fitRectRef.current, []);\n\n const imageRect = useMemo(() => unrotatedRect(fitRect, rotation), [fitRect, rotation]);\n\n const viewportRef = useRef(viewport);\n viewportRef.current = viewport;\n const getViewportWidth = useCallback(() => viewportRef.current.width, []);\n\n const getCloseSource = useCallback(() => currentEntryRef.current.element, []);\n\n const transform = useMemo(\n () => ({ flipX, flipY, rotate, scale, x, y }),\n [flipX, flipY, rotate, scale, x, y],\n );\n const handleClosed = useCallback(() => endClosePreview(token), [token]);\n\n const {\n backdropRef,\n chromeRef,\n close,\n imageRef: flipImageRef,\n isClosing,\n isTransitioning,\n switchTo,\n } = useFlipTransition({\n animated,\n getCloseSource,\n getFitRect,\n getInitialScale,\n getViewportWidth,\n onClosed: handleClosed,\n source: openerEntry.element,\n transform,\n });\n isClosingIndirectRef.current = isClosing;\n isTransitioningIndirectRef.current = isTransitioning;\n\n useRefitTransition({\n animated,\n fillViewport,\n isTransitioning,\n natural,\n rotation,\n scale,\n viewport,\n x,\n y,\n });\n const finalFocus = useFinalFocus(openerFocusElement);\n\n const isCleanRef = useRef(isClean);\n isCleanRef.current = isClean;\n\n const handleClose = useCallback(() => {\n beginClosePreview(token);\n close({ fade: !isCleanRef.current });\n }, [close, token]);\n closeRef.current = handleClose;\n\n const handleDialogOpenChange = useCallback<NonNullable<DialogRootProps['onOpenChange']>>(\n (open, eventDetails) => {\n if (open) return;\n // Base UI fires this on every Esc regardless of whether we're already\n // mid-close (our Dialog.Root's open prop never actually flips to\n // false), so without this guard a second Esc during the close window\n // reads escIntent() off the close spring's mid-flight scale, decides\n // 'reset', and cancels the close animation out from under itself.\n if (isClosing()) return;\n if (eventDetails.reason === 'escape-key' && escIntent() === 'reset') {\n eventDetails.cancel();\n reset();\n return;\n }\n handleClose();\n },\n [escIntent, handleClose, isClosing, reset],\n );\n\n const gestures = useViewerGestures({\n dragBy,\n dragEnd,\n handleDoubleClick,\n handleWheel,\n isClean,\n isZoomed,\n onClose: handleClose,\n reset,\n zoomIn,\n zoomOut,\n });\n\n const { hasNext, hasPrev, next, prev } = useGalleryNav({\n cancelPendingClose: gestures.cancelPendingClose,\n currentIndex,\n entries,\n flipX,\n flipY,\n getInitialScale,\n resetCloseTracking,\n rotate,\n scale,\n setCurrentIndex,\n setNatural,\n setSource,\n switchTo,\n syncZoomNatural,\n x,\n y,\n });\n\n const popupNodeRef = useRef<HTMLDivElement | null>(null);\n const popupRef = useMergeRefs<HTMLDivElement>([layerRef, gestures.popupRef, popupNodeRef]);\n const imageRef = useMergeRefs<HTMLImageElement>([flipImageRef, gestures.imageRef]);\n\n const handleLoad = useCallback(\n (event: SyntheticEvent<HTMLImageElement>) => {\n const loaded = event.currentTarget;\n if (!loaded.naturalWidth || !loaded.naturalHeight) return;\n const next = { height: loaded.naturalHeight, width: loaded.naturalWidth };\n setNatural((prev) =>\n prev.width === next.width && prev.height === next.height ? prev : next,\n );\n syncZoomNatural(next);\n },\n [syncZoomNatural],\n );\n\n useEffect(() => {\n const handleResize = () => {\n const next = readViewport();\n setViewport(next);\n syncZoomViewport(next);\n };\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }, [syncZoomViewport]);\n\n useEffect(() => {\n const { previewSrc, src } = currentEntry;\n if (!previewSrc || previewSrc === src) return;\n let cancelled = false;\n const loader = new window.Image();\n const handleLoaded = () => {\n if (!cancelled) setSource(previewSrc);\n };\n loader.addEventListener('load', handleLoaded);\n loader.src = previewSrc;\n return () => {\n cancelled = true;\n loader.removeEventListener('load', handleLoaded);\n };\n }, [currentEntry]);\n\n useEffect(\n () => () => {\n const thumbnailWasRemoved = !openerEntry.element.isConnected;\n if (thumbnailWasRemoved) endClosePreview(token);\n },\n [openerEntry, token],\n );\n\n return (\n <Dialog.Root modal open onOpenChange={handleDialogOpenChange}>\n <Dialog.Portal container={appElement ?? undefined}>\n {/* Base UI drops a nested dialog's backdrop so overlays don't stack. The viewer is\n not an overlay on the surface it opened from — it replaces the screen — so it\n keeps its own scrim, or a viewer opened from a maskless drawer would show the\n page straight through the letterbox around the image. */}\n <Dialog.Backdrop\n forceRender\n {...styleProps(styles.viewerBackdrop, 'lobe-image-viewer-backdrop')}\n ref={backdropRef}\n style={zIndex === undefined ? undefined : { zIndex }}\n onClick={gestures.onSurfaceClick}\n />\n <Dialog.Popup\n aria-label={currentEntry.element.alt || undefined}\n {...styleProps(styles.viewerPopup, 'lobe-image-viewer-popup')}\n finalFocus={finalFocus}\n // Focus the popup itself instead of Base UI's default (the first\n // tabbable — the close button): a focus-visible close button pins\n // the idle auto-hide open forever and pops its tooltip on open.\n initialFocus={popupNodeRef}\n ref={popupRef}\n style={zIndex === undefined ? undefined : { zIndex: zIndex + 1 }}\n tabIndex={-1}\n onClick={gestures.onSurfaceClick}\n onPointerCancel={gestures.onPointerFinish}\n onPointerDown={gestures.onPointerDown}\n onPointerMove={gestures.onPointerMove}\n onPointerUp={gestures.onPointerFinish}\n >\n <img\n alt={currentEntry.element.alt}\n {...styleProps(styles.viewerImage, 'lobe-image-viewer-image')}\n ref={imageRef}\n src={source}\n style={{\n cursor: gestures.cursor,\n height: imageRect.height,\n left: imageRect.x,\n top: imageRect.y,\n width: imageRect.width,\n }}\n onClick={gestures.onImageClick}\n onDoubleClick={gestures.onImageDoubleClick}\n onLoad={handleLoad}\n />\n <ViewerChrome\n canZoomIn={canZoomIn}\n canZoomOut={canZoomOut}\n chromeRef={chromeRef}\n current={currentIndex}\n fetchImage={currentEntry.options.fetchImage}\n fitRect={fitRect}\n flipHorizontal={flipHorizontal}\n flipVertical={flipVertical}\n hasNext={hasNext}\n hasPrev={hasPrev}\n natural={natural}\n next={next}\n prev={prev}\n rotateLeft={rotateLeft}\n rotateRight={rotateRight}\n rotation={rotation}\n scale={scale}\n source={source}\n toggleActualSize={toggleActualSize}\n toolbarAddon={currentEntry.options.toolbarAddon}\n total={entries.length}\n zoomIn={zoomIn}\n zoomOut={zoomOut}\n onClose={handleClose}\n onDownload={currentEntry.options.onDownload}\n />\n </Dialog.Popup>\n <ToastHost root={appElement ?? undefined} />\n </Dialog.Portal>\n </Dialog.Root>\n );\n});\n\nImageViewer.displayName = 'ImageViewer';\n\nexport default ImageViewer;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,sBAA4B;CAAE,QAAQ,OAAO;CAAa,OAAO,OAAO;AAAW;AAEzF,MAAM,6BACJ,OAAO,aAAa,kCAAkC,CAAC,CAAC,WAAW;AAErE,MAAM,cAAc,MAAwB,EAAE,SAAS,OAAO,oBAAoB,YAAY;CAC5F,MAAM,cAAc,QAAQ;CAC5B,MAAM,aAAa,cAAc;CACjC,MAAM,CAAC,YAAY,eAAe,CAAC,qBAAqB,CAAC;CAEzD,MAAM,EAAE,KAAK,UAAU,WAAW,eAA+B,OAAO;CAExE,MAAM,CAAC,cAAc,mBAAmB,SAAS,KAAK;CACtD,MAAM,eAAe,QAAQ;CAC7B,MAAM,kBAAkB,OAAO,YAAY;CAC3C,gBAAgB,UAAU;CAE1B,MAAM,CAAC,QAAQ,aAAa,SAAS,YAAY,GAAG;CACpD,MAAM,CAAC,SAAS,cAAc,eAAqB,YAAY,YAAY,OAAO,CAAC;CACnF,MAAM,CAAC,UAAU,eAAe,SAAe,YAAY;CAE3D,MAAM,WAAW,OAA4B,IAAI;CACjD,MAAM,eAAe,kBAAkB,SAAS,UAAU,GAAG,CAAC,CAAC;CAO/D,MAAM,uBAAuB,aAA4B,KAAK;CAC9D,MAAM,oBAAoB,kBAAkB,qBAAqB,QAAQ,GAAG,CAAC,CAAC;CAE9E,MAAM,6BAA6B,aAA4B,IAAI;CACnE,MAAM,0BAA0B,kBAAkB,2BAA2B,QAAQ,GAAG,CAAC,CAAC;CAE1F,MAAM,eAAe,QACnB,aAAa,cAAc,aAAa,eAAe,aAAa,GACtE;CAEA,MAAM,EACJ,WACA,YACA,QACA,SACA,WACA,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D,KAAK;MACL,KAAK;MACL,OAAO;OACL,QAAQ,SAAS;OACjB,QAAQ,UAAU;OAClB,MAAM,UAAU;OAChB,KAAK,UAAU;OACf,OAAO,UAAU;MACnB;MACA,SAAS,SAAS;MAClB,eAAe,SAAS;MACxB,QAAQ;KACT,CAAA,GACD,oBAAC,cAAD;MACa;MACC;MACD;MACX,SAAS;MACT,YAAY,aAAa,QAAQ;MACxB;MACO;MACF;MACL;MACA;MACA;MACH;MACA;MACM;MACC;MACH;MACH;MACC;MACU;MAClB,cAAc,aAAa,QAAQ;MACnC,OAAO,QAAQ;MACP;MACC;MACT,SAAS;MACT,YAAY,aAAa,QAAQ;KAClC,CAAA,CACW;;IACd,oBAAC,WAAD,EAAW,MAAM,cAAc,KAAA,EAAY,CAAA;GAC9B;;CACJ,CAAA;AAEjB,CAAC;AAED,YAAY,cAAc"}
|
|
@@ -80,11 +80,11 @@ const normalizeWheelDelta = (deltaY, deltaMode = 0, viewportHeight = 0) => {
|
|
|
80
80
|
return deltaY;
|
|
81
81
|
};
|
|
82
82
|
const naturalScale = (natural, fitRect, rotate) => effectiveSize(natural, rotate).width / fitRect.width;
|
|
83
|
-
const resolveInitialScale = (policy, natural, fitRect, rotate, threshold = 2) => {
|
|
83
|
+
const resolveInitialScale = (policy, natural, fitRect, rotate, threshold = 2, pixelRatio = 1) => {
|
|
84
84
|
if (policy === "fit") return 1;
|
|
85
85
|
const target = naturalScale(natural, fitRect, rotate);
|
|
86
86
|
if (!Number.isFinite(target) || target <= 0) return 1;
|
|
87
|
-
if (policy === "auto" && target > threshold) return 1;
|
|
87
|
+
if (policy === "auto" && (target <= pixelRatio || target > threshold)) return 1;
|
|
88
88
|
return Math.max(1, target);
|
|
89
89
|
};
|
|
90
90
|
const doubleClickTarget = (currentScale, natural, fitRect, rotate) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.mjs","names":[],"sources":["../../../src/Image/viewer/geometry.ts"],"sourcesContent":["export interface Size {\n height: number;\n width: number;\n}\n\nexport interface Point {\n x: number;\n y: number;\n}\n\nexport interface Rect {\n height: number;\n width: number;\n x: number;\n y: number;\n}\n\nexport type Rotation = 0 | 90 | 180 | 270;\n\nexport type ZoomPolicy = 'auto' | 'actual' | 'fit';\n\nexport interface TransformState {\n scale: number;\n x: number;\n y: number;\n}\n\nexport interface AxisBounds {\n max: number;\n min: number;\n}\n\nexport const VIEWPORT_MARGIN = 24;\nexport const MIN_SCALE = 1;\nexport const DEFAULT_MAX_SCALE = 8;\nexport const DEFAULT_RUBBER_BAND_FACTOR = 0.15;\nexport const WHEEL_ZOOM_SENSITIVITY = 0.002;\nexport const DEFAULT_AUTO_ZOOM_THRESHOLD = 2;\nexport const WHEEL_LINE_HEIGHT = 16;\n\nexport const normalizeRotation = (degrees: number): Rotation =>\n (((degrees % 360) + 360) % 360) as Rotation;\n\nconst effectiveSize = (natural: Size, rotate: Rotation): Size =>\n rotate === 90 || rotate === 270 ? { height: natural.width, width: natural.height } : natural;\n\nexport const computeFit = (\n natural: Size,\n viewport: Size,\n rotate: Rotation,\n fillViewport = false,\n): Rect => {\n const effective = effectiveSize(natural, rotate);\n const availableWidth = Math.max(viewport.width - VIEWPORT_MARGIN * 2, 0);\n const availableHeight = Math.max(viewport.height - VIEWPORT_MARGIN * 2, 0);\n // fillViewport drops the no-upscale cap: a dual-source thumbnail is a\n // stand-in for the hi-res image, so it must open at the viewport fit the\n // hi-res will land in — otherwise the swap re-fits mid-open.\n const containScale = Math.min(\n availableWidth / effective.width,\n availableHeight / effective.height,\n ...(fillViewport ? [] : [1]),\n );\n const width = effective.width * containScale;\n const height = effective.height * containScale;\n\n return {\n height,\n width,\n x: (viewport.width - width) / 2,\n y: (viewport.height - height) / 2,\n };\n};\n\n// computeFit returns the box the image occupies *after* the CSS rotation, but\n// the element it is applied to is sized before that rotation runs. For quarter\n// turns the two disagree, so the element box has to be the transpose about the\n// same center — otherwise `object-fit: contain` letterboxes the image down to\n// the short side and everything downstream (pan bounds, natural scale) is\n// measuring a box the viewer never actually paints.\nexport const unrotatedRect = (fit: Rect, rotate: Rotation): Rect => {\n if (rotate !== 90 && rotate !== 270) return fit;\n\n const centerX = fit.x + fit.width / 2;\n const centerY = fit.y + fit.height / 2;\n\n return {\n height: fit.width,\n width: fit.height,\n x: centerX - fit.height / 2,\n y: centerY - fit.width / 2,\n };\n};\n\nexport const anchoredZoom = (\n current: TransformState,\n targetScale: number,\n anchor: Point,\n fitRect: Rect,\n): TransformState => {\n const centerX = fitRect.x + fitRect.width / 2;\n const centerY = fitRect.y + fitRect.height / 2;\n const ratio = targetScale / current.scale;\n\n return {\n scale: targetScale,\n x: anchor.x - centerX - ratio * (anchor.x - centerX - current.x),\n y: anchor.y - centerY - ratio * (anchor.y - centerY - current.y),\n };\n};\n\nexport const panBounds = (\n state: TransformState,\n fitRect: Rect,\n viewport: Size,\n): { x: AxisBounds; y: AxisBounds } => {\n const centerX = fitRect.x + fitRect.width / 2;\n const centerY = fitRect.y + fitRect.height / 2;\n const scaledWidth = fitRect.width * state.scale;\n const scaledHeight = fitRect.height * state.scale;\n\n const axis = (center: number, scaledSize: number, viewportSize: number): AxisBounds => {\n const overflow = scaledSize - viewportSize;\n if (overflow <= 0) return { max: 0, min: 0 };\n return { max: scaledSize / 2 - center, min: viewportSize - center - scaledSize / 2 };\n };\n\n return {\n x: axis(centerX, scaledWidth, viewport.width),\n y: axis(centerY, scaledHeight, viewport.height),\n };\n};\n\nexport const clampPan = (state: TransformState, fitRect: Rect, viewport: Size): Point => {\n const bounds = panBounds(state, fitRect, viewport);\n return {\n x: Math.min(Math.max(state.x, bounds.x.min), bounds.x.max),\n y: Math.min(Math.max(state.y, bounds.y.min), bounds.y.max),\n };\n};\n\nexport const rubberBand = (\n value: number,\n min: number,\n max: number,\n factor: number = DEFAULT_RUBBER_BAND_FACTOR,\n): number => {\n if (value < min) return min - (min - value) * factor;\n if (value > max) return max + (value - max) * factor;\n return value;\n};\n\nexport const clampScale = (scale: number, maxScale: number = DEFAULT_MAX_SCALE): number =>\n Math.min(Math.max(scale, MIN_SCALE), maxScale);\n\nexport const wheelZoomFactor = (deltaY: number): number =>\n Math.exp(-deltaY * WHEEL_ZOOM_SENSITIVITY);\n\n// Firefox on Windows/Linux reports wheel notches as DOM_DELTA_LINE with a\n// deltaY around 3, where Chrome/Safari report ~100 pixels for the same notch.\n// Feeding those raw into wheelZoomFactor is a ~30x under-zoom (0.6% per notch,\n// ~115 notches to double) and an equally dead scroll-to-close accumulator.\nexport const normalizeWheelDelta = (deltaY: number, deltaMode = 0, viewportHeight = 0): number => {\n if (deltaMode === 1) return deltaY * WHEEL_LINE_HEIGHT;\n if (deltaMode === 2) return deltaY * (viewportHeight || WHEEL_LINE_HEIGHT * 40);\n return deltaY;\n};\n\nexport const naturalScale = (natural: Size, fitRect: Rect, rotate: Rotation): number =>\n effectiveSize(natural, rotate).width / fitRect.width;\n\n// The scale the viewer opens at, expressed like every other scale here:\n// relative to the fit rect, so MIN_SCALE is always still fit. Opening above\n// MIN_SCALE is what makes a screenshot legible on open and — because the image\n// then overflows the viewport — what gives panBounds something to work with.\nexport const resolveInitialScale = (\n policy: ZoomPolicy,\n natural: Size,\n fitRect: Rect,\n rotate: Rotation,\n threshold: number = DEFAULT_AUTO_ZOOM_THRESHOLD,\n): number => {\n if (policy === 'fit') return MIN_SCALE;\n\n const target = naturalScale(natural, fitRect, rotate);\n if (!Number.isFinite(target) || target <= 0) return MIN_SCALE;\n if (policy === 'auto' && target > threshold) return MIN_SCALE;\n\n // fillViewport drops computeFit's no-upscale cap, so the fit rect can be\n // larger than the image and target can land below the zoom floor.\n return Math.max(MIN_SCALE, target);\n};\n\nexport const doubleClickTarget = (\n currentScale: number,\n natural: Size,\n fitRect: Rect,\n rotate: Rotation,\n): number => {\n if (currentScale > 1) return MIN_SCALE;\n return Math.max(2, naturalScale(natural, fitRect, rotate));\n};\n"],"mappings":"AAmCA,MAAa,6BAA6B;AAC1C,MAAa,yBAAyB;AAItC,M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O;AACT;AAEA,MAAa,gBAAgB,SAAe,SAAe,WACzD,cAAc,SAAS,MAAM,CAAC,CAAC,QAAQ,QAAQ;
|
|
1
|
+
{"version":3,"file":"geometry.mjs","names":[],"sources":["../../../src/Image/viewer/geometry.ts"],"sourcesContent":["export interface Size {\n height: number;\n width: number;\n}\n\nexport interface Point {\n x: number;\n y: number;\n}\n\nexport interface Rect {\n height: number;\n width: number;\n x: number;\n y: number;\n}\n\nexport type Rotation = 0 | 90 | 180 | 270;\n\nexport type ZoomPolicy = 'auto' | 'actual' | 'fit';\n\nexport interface TransformState {\n scale: number;\n x: number;\n y: number;\n}\n\nexport interface AxisBounds {\n max: number;\n min: number;\n}\n\nexport const VIEWPORT_MARGIN = 24;\nexport const MIN_SCALE = 1;\nexport const DEFAULT_MAX_SCALE = 8;\nexport const DEFAULT_RUBBER_BAND_FACTOR = 0.15;\nexport const WHEEL_ZOOM_SENSITIVITY = 0.002;\nexport const DEFAULT_AUTO_ZOOM_THRESHOLD = 2;\nexport const WHEEL_LINE_HEIGHT = 16;\n\nexport const normalizeRotation = (degrees: number): Rotation =>\n (((degrees % 360) + 360) % 360) as Rotation;\n\nconst effectiveSize = (natural: Size, rotate: Rotation): Size =>\n rotate === 90 || rotate === 270 ? { height: natural.width, width: natural.height } : natural;\n\nexport const computeFit = (\n natural: Size,\n viewport: Size,\n rotate: Rotation,\n fillViewport = false,\n): Rect => {\n const effective = effectiveSize(natural, rotate);\n const availableWidth = Math.max(viewport.width - VIEWPORT_MARGIN * 2, 0);\n const availableHeight = Math.max(viewport.height - VIEWPORT_MARGIN * 2, 0);\n // fillViewport drops the no-upscale cap: a dual-source thumbnail is a\n // stand-in for the hi-res image, so it must open at the viewport fit the\n // hi-res will land in — otherwise the swap re-fits mid-open.\n const containScale = Math.min(\n availableWidth / effective.width,\n availableHeight / effective.height,\n ...(fillViewport ? [] : [1]),\n );\n const width = effective.width * containScale;\n const height = effective.height * containScale;\n\n return {\n height,\n width,\n x: (viewport.width - width) / 2,\n y: (viewport.height - height) / 2,\n };\n};\n\n// computeFit returns the box the image occupies *after* the CSS rotation, but\n// the element it is applied to is sized before that rotation runs. For quarter\n// turns the two disagree, so the element box has to be the transpose about the\n// same center — otherwise `object-fit: contain` letterboxes the image down to\n// the short side and everything downstream (pan bounds, natural scale) is\n// measuring a box the viewer never actually paints.\nexport const unrotatedRect = (fit: Rect, rotate: Rotation): Rect => {\n if (rotate !== 90 && rotate !== 270) return fit;\n\n const centerX = fit.x + fit.width / 2;\n const centerY = fit.y + fit.height / 2;\n\n return {\n height: fit.width,\n width: fit.height,\n x: centerX - fit.height / 2,\n y: centerY - fit.width / 2,\n };\n};\n\nexport const anchoredZoom = (\n current: TransformState,\n targetScale: number,\n anchor: Point,\n fitRect: Rect,\n): TransformState => {\n const centerX = fitRect.x + fitRect.width / 2;\n const centerY = fitRect.y + fitRect.height / 2;\n const ratio = targetScale / current.scale;\n\n return {\n scale: targetScale,\n x: anchor.x - centerX - ratio * (anchor.x - centerX - current.x),\n y: anchor.y - centerY - ratio * (anchor.y - centerY - current.y),\n };\n};\n\nexport const panBounds = (\n state: TransformState,\n fitRect: Rect,\n viewport: Size,\n): { x: AxisBounds; y: AxisBounds } => {\n const centerX = fitRect.x + fitRect.width / 2;\n const centerY = fitRect.y + fitRect.height / 2;\n const scaledWidth = fitRect.width * state.scale;\n const scaledHeight = fitRect.height * state.scale;\n\n const axis = (center: number, scaledSize: number, viewportSize: number): AxisBounds => {\n const overflow = scaledSize - viewportSize;\n if (overflow <= 0) return { max: 0, min: 0 };\n return { max: scaledSize / 2 - center, min: viewportSize - center - scaledSize / 2 };\n };\n\n return {\n x: axis(centerX, scaledWidth, viewport.width),\n y: axis(centerY, scaledHeight, viewport.height),\n };\n};\n\nexport const clampPan = (state: TransformState, fitRect: Rect, viewport: Size): Point => {\n const bounds = panBounds(state, fitRect, viewport);\n return {\n x: Math.min(Math.max(state.x, bounds.x.min), bounds.x.max),\n y: Math.min(Math.max(state.y, bounds.y.min), bounds.y.max),\n };\n};\n\nexport const rubberBand = (\n value: number,\n min: number,\n max: number,\n factor: number = DEFAULT_RUBBER_BAND_FACTOR,\n): number => {\n if (value < min) return min - (min - value) * factor;\n if (value > max) return max + (value - max) * factor;\n return value;\n};\n\nexport const clampScale = (scale: number, maxScale: number = DEFAULT_MAX_SCALE): number =>\n Math.min(Math.max(scale, MIN_SCALE), maxScale);\n\nexport const wheelZoomFactor = (deltaY: number): number =>\n Math.exp(-deltaY * WHEEL_ZOOM_SENSITIVITY);\n\n// Firefox on Windows/Linux reports wheel notches as DOM_DELTA_LINE with a\n// deltaY around 3, where Chrome/Safari report ~100 pixels for the same notch.\n// Feeding those raw into wheelZoomFactor is a ~30x under-zoom (0.6% per notch,\n// ~115 notches to double) and an equally dead scroll-to-close accumulator.\nexport const normalizeWheelDelta = (deltaY: number, deltaMode = 0, viewportHeight = 0): number => {\n if (deltaMode === 1) return deltaY * WHEEL_LINE_HEIGHT;\n if (deltaMode === 2) return deltaY * (viewportHeight || WHEEL_LINE_HEIGHT * 40);\n return deltaY;\n};\n\nexport const naturalScale = (natural: Size, fitRect: Rect, rotate: Rotation): number =>\n effectiveSize(natural, rotate).width / fitRect.width;\n\n// The scale the viewer opens at, expressed like every other scale here:\n// relative to the fit rect, so MIN_SCALE is always still fit. Opening above\n// MIN_SCALE is what makes a screenshot legible on open and — because the image\n// then overflows the viewport — what gives panBounds something to work with.\n//\n// `pixelRatio` is how many image pixels made one CSS pixel when the image was\n// captured. Up to that ratio fit still shows the image at least at its captured\n// size with every pixel intact — a 2x screenshot fitted on a 2x screen looks as\n// it did on screen — so auto stays at fit, where 100% would only double it.\nexport const resolveInitialScale = (\n policy: ZoomPolicy,\n natural: Size,\n fitRect: Rect,\n rotate: Rotation,\n threshold: number = DEFAULT_AUTO_ZOOM_THRESHOLD,\n pixelRatio: number = 1,\n): number => {\n if (policy === 'fit') return MIN_SCALE;\n\n const target = naturalScale(natural, fitRect, rotate);\n if (!Number.isFinite(target) || target <= 0) return MIN_SCALE;\n if (policy === 'auto' && (target <= pixelRatio || target > threshold)) return MIN_SCALE;\n\n // fillViewport drops computeFit's no-upscale cap, so the fit rect can be\n // larger than the image and target can land below the zoom floor.\n return Math.max(MIN_SCALE, target);\n};\n\nexport const doubleClickTarget = (\n currentScale: number,\n natural: Size,\n fitRect: Rect,\n rotate: Rotation,\n): number => {\n if (currentScale > 1) return MIN_SCALE;\n return Math.max(2, naturalScale(natural, fitRect, rotate));\n};\n"],"mappings":"AAmCA,MAAa,6BAA6B;AAC1C,MAAa,yBAAyB;AAItC,MAAa,qBAAqB,aAC7B,UAAU,MAAO,OAAO;AAE7B,MAAM,iBAAiB,SAAe,WACpC,WAAW,MAAM,WAAW,MAAM;CAAE,QAAQ,QAAQ;CAAO,OAAO,QAAQ;AAAO,IAAI;AAEvF,MAAa,cACX,SACA,UACA,QACA,eAAe,UACN;CACT,MAAM,YAAY,cAAc,SAAS,MAAM;CAC/C,MAAM,iBAAiB,KAAK,IAAI,SAAS,QAAQ,IAAqB,CAAC;CACvE,MAAM,kBAAkB,KAAK,IAAI,SAAS,SAAS,IAAqB,CAAC;CAIzE,MAAM,eAAe,KAAK,IACxB,iBAAiB,UAAU,OAC3B,kBAAkB,UAAU,QAC5B,GAAI,eAAe,CAAC,IAAI,CAAC,CAAC,CAC5B;CACA,MAAM,QAAQ,UAAU,QAAQ;CAChC,MAAM,SAAS,UAAU,SAAS;CAElC,OAAO;EACL;EACA;EACA,IAAI,SAAS,QAAQ,SAAS;EAC9B,IAAI,SAAS,SAAS,UAAU;CAClC;AACF;AAQA,MAAa,iBAAiB,KAAW,WAA2B;CAClE,IAAI,WAAW,MAAM,WAAW,KAAK,OAAO;CAE5C,MAAM,UAAU,IAAI,IAAI,IAAI,QAAQ;CACpC,MAAM,UAAU,IAAI,IAAI,IAAI,SAAS;CAErC,OAAO;EACL,QAAQ,IAAI;EACZ,OAAO,IAAI;EACX,GAAG,UAAU,IAAI,SAAS;EAC1B,GAAG,UAAU,I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AI,QAAQ,KAAK,OAAO,OAAO,QAAQ,OAAO;CAC9C,OAAO;AACT;AAEA,MAAa,cAAc,OAAe,WAAA,MACxC,KAAK,IAAI,KAAK,IAAI,OAAA,CAAgB,GAAG,QAAQ;AAE/C,MAAa,mBAAmB,WAC9B,KAAK,IAAI,CAAC,SAAS,sBAAsB;AAM3C,MAAa,uBAAuB,QAAgB,YAAY,GAAG,iBAAiB,MAAc;CAChG,IAAI,cAAc,GAAG,OAAO,SAAA;CAC5B,IAAI,cAAc,GAAG,OAAO,UAAU,kBAAkB;CACxD,OAAO;AACT;AAEA,MAAa,gBAAgB,SAAe,SAAe,WACzD,cAAc,SAAS,MAAM,CAAC,CAAC,QAAQ,QAAQ;AAWjD,MAAa,uBACX,QACA,SACA,SACA,QACA,YAAA,GACA,aAAqB,MACV;CACX,IAAI,WAAW,OAAO,OAAA;CAEtB,MAAM,SAAS,aAAa,SAAS,SAAS,MAAM;CACpD,IAAI,CAAC,OAAO,SAAS,MAAM,KAAK,UAAU,GAAG,OAAA;CAC7C,IAAI,WAAW,WAAW,UAAU,cAAc,SAAS,YAAY,OAAA;CAIvE,OAAO,KAAK,IAAA,GAAe,MAAM;AACnC;AAEA,MAAa,qBACX,cACA,SACA,SACA,WACW;CACX,IAAI,eAAe,GAAG,OAAA;CACtB,OAAO,KAAK,IAAI,GAAG,aAAa,SAAS,SAAS,MAAM,CAAC;AAC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.mjs","names":[],"sources":["../../../src/Image/viewer/registry.ts"],"sourcesContent":["import { type RefObject, useCallback, useSyncExternalStore } from 'react';\n\nimport type { ImagePreviewOptions } from '../type';\nimport type { ZoomPolicy } from './geometry';\n\nexport interface ResolvedPreviewOptions extends Omit<\n ImagePreviewOptions,\n 'autoZoomThreshold' | 'defaultZoom' | 'maxScale'\n> {\n autoZoomThreshold: number;\n defaultZoom: ZoomPolicy;\n maxScale: number;\n}\n\nexport interface PreviewEntry {\n element: HTMLImageElement;\n options: ResolvedPreviewOptions;\n previewSrc?: string;\n src: string;\n}\n\nexport interface PreviewSession {\n entries: PreviewEntry[];\n index: number;\n openerFocusElement: HTMLElement | null;\n token: number;\n}\n\ninterface HostState extends PreviewSession {\n closing: boolean;\n onOpenChange?: (open: boolean) => void;\n}\n\nlet state: HostState | null = null;\nlet nextToken = 0;\n\nconst listeners = new Set<() => void>();\n\nconst emit = () => {\n for (const listener of listeners) listener();\n};\n\nconst flushClosed = () => {\n if (!state || state.closing) return;\n state.closing = true;\n state.onOpenChange?.(false);\n};\n\n// openerFocusElement must be captured by the caller at pointerdown, not read here:\n// clicking a non-focusable thumbnail already blurs to document.body before its\n// click handler (and therefore this call) runs.\nexport const openPreview = (\n entry: PreviewEntry,\n entries?: PreviewEntry[],\n index = 0,\n openerFocusElement: HTMLElement | null = null,\n): void => {\n flushClosed();\n nextToken += 1;\n const resolvedEntries = entries && entries.length > 0 ? entries : [entry];\n const resolvedIndex =\n entries && entries.length > 0 ? Math.min(Math.max(index, 0), entries.length - 1) : 0;\n state = {\n closing: false,\n entries: resolvedEntries,\n index: resolvedIndex,\n onOpenChange: entry.options.onOpenChange,\n openerFocusElement,\n token: nextToken,\n };\n emit();\n entry.options.onOpenChange?.(true);\n};\n\nexport const beginClosePreview = (token: number): void => {\n if (state?.token !== token) return;\n flushClosed();\n};\n\nexport const endClosePreview = (token: number): void => {\n if (state?.token !== token) return;\n flushClosed();\n state = null;\n emit();\n};\n\nconst subscribe = (listener: () => void) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n};\n\nconst getServerSnapshot = (): PreviewSession | null => null;\n\nexport const usePreviewSession = (\n elementRef: RefObject<HTMLImageElement | null>,\n): PreviewSession | null => {\n const getSnapshot = useCallback(\n () => (state && state.entries[state.index]?.element === elementRef.current ? state : null),\n [elementRef],\n );\n\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n};\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"registry.mjs","names":[],"sources":["../../../src/Image/viewer/registry.ts"],"sourcesContent":["import { type RefObject, useCallback, useSyncExternalStore } from 'react';\n\nimport type { ImagePreviewOptions } from '../type';\nimport type { ZoomPolicy } from './geometry';\n\nexport interface ResolvedPreviewOptions extends Omit<\n ImagePreviewOptions,\n 'autoZoomThreshold' | 'defaultZoom' | 'maxScale'\n> {\n autoZoomThreshold: number;\n defaultZoom: ZoomPolicy;\n maxScale: number;\n /**\n * Image pixels per CSS pixel at the size the source was captured. Raster\n * previews leave it unset and the viewer assumes the screen's\n * devicePixelRatio; vector sources pass 1.\n */\n pixelRatio?: number;\n}\n\nexport interface PreviewEntry {\n element: HTMLImageElement;\n options: ResolvedPreviewOptions;\n previewSrc?: string;\n src: string;\n}\n\nexport interface PreviewSession {\n entries: PreviewEntry[];\n index: number;\n openerFocusElement: HTMLElement | null;\n token: number;\n}\n\ninterface HostState extends PreviewSession {\n closing: boolean;\n onOpenChange?: (open: boolean) => void;\n}\n\nlet state: HostState | null = null;\nlet nextToken = 0;\n\nconst listeners = new Set<() => void>();\n\nconst emit = () => {\n for (const listener of listeners) listener();\n};\n\nconst flushClosed = () => {\n if (!state || state.closing) return;\n state.closing = true;\n state.onOpenChange?.(false);\n};\n\n// openerFocusElement must be captured by the caller at pointerdown, not read here:\n// clicking a non-focusable thumbnail already blurs to document.body before its\n// click handler (and therefore this call) runs.\nexport const openPreview = (\n entry: PreviewEntry,\n entries?: PreviewEntry[],\n index = 0,\n openerFocusElement: HTMLElement | null = null,\n): void => {\n flushClosed();\n nextToken += 1;\n const resolvedEntries = entries && entries.length > 0 ? entries : [entry];\n const resolvedIndex =\n entries && entries.length > 0 ? Math.min(Math.max(index, 0), entries.length - 1) : 0;\n state = {\n closing: false,\n entries: resolvedEntries,\n index: resolvedIndex,\n onOpenChange: entry.options.onOpenChange,\n openerFocusElement,\n token: nextToken,\n };\n emit();\n entry.options.onOpenChange?.(true);\n};\n\nexport const beginClosePreview = (token: number): void => {\n if (state?.token !== token) return;\n flushClosed();\n};\n\nexport const endClosePreview = (token: number): void => {\n if (state?.token !== token) return;\n flushClosed();\n state = null;\n emit();\n};\n\nconst subscribe = (listener: () => void) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n};\n\nconst getServerSnapshot = (): PreviewSession | null => null;\n\nexport const usePreviewSession = (\n elementRef: RefObject<HTMLImageElement | null>,\n): PreviewSession | null => {\n const getSnapshot = useCallback(\n () => (state && state.entries[state.index]?.element === elementRef.current ? state : null),\n [elementRef],\n );\n\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n};\n"],"mappings":";;AAuCA,IAAI,QAA0B;AAC9B,IAAI,YAAY;AAEhB,MAAM,4BAAY,IAAI,IAAgB;AAEtC,MAAM,aAAa;CACjB,KAAK,MAAM,YAAY,WAAW,SAAS;AAC7C;AAEA,MAAM,oBAAoB;CACxB,IAAI,CAAC,SAAS,MAAM,SAAS;CAC7B,MAAM,UAAU;CAChB,MAAM,eAAe,KAAK;AAC5B;AAKA,MAAa,eACX,OACA,SACA,QAAQ,GACR,qBAAyC,SAChC;CACT,YAAY;CACZ,aAAa;CAIb,QAAQ;EACN,SAAS;EACT,SALsB,WAAW,QAAQ,SAAS,IAAI,UAAU,CAAC,KAAK;EAMtE,OAJA,WAAW,QAAQ,SAAS,IAAI,KAAK,IAAI,KAAK,IAAI,OAAO,CAAC,GAAG,QAAQ,SAAS,CAAC,IAAI;EAKnF,cAAc,MAAM,QAAQ;EAC5B;EACA,OAAO;CACT;CACA,KAAK;CACL,MAAM,QAAQ,eAAe,IAAI;AACnC;AAEA,MAAa,qBAAqB,UAAwB;CACxD,IAAI,OAAO,UAAU,OAAO;CAC5B,YAAY;AACd;AAEA,MAAa,mBAAmB,UAAwB;CACtD,IAAI,OAAO,UAAU,OAAO;CAC5B,YAAY;CACZ,QAAQ;CACR,KAAK;AACP;AAEA,MAAM,aAAa,aAAyB;CAC1C,UAAU,IAAI,QAAQ;CACtB,aAAa;EACX,UAAU,OAAO,QAAQ;CAC3B;AACF;AAEA,MAAM,0BAAiD;AAEvD,MAAa,qBACX,eAC0B;CAC1B,MAAM,cAAc,kBACX,SAAS,MAAM,QAAQ,MAAM,MAAM,EAAE,YAAY,WAAW,UAAU,QAAQ,MACrF,CAAC,UAAU,CACb;CAEA,OAAO,qBAAqB,WAAW,aAAa,iBAAiB;AACvE"}
|
|
@@ -11,7 +11,8 @@ const RESET_TRANSITION = {
|
|
|
11
11
|
type: "spring"
|
|
12
12
|
};
|
|
13
13
|
const CLEAN_EPSILON = .01;
|
|
14
|
-
const
|
|
14
|
+
const screenPixelRatio = () => typeof window === "undefined" ? 1 : window.devicePixelRatio || 1;
|
|
15
|
+
const useZoomPan = ({ natural, viewport, maxScale, onCloseRequest, isClosing, isTransitioning, fillViewport, defaultZoom, autoZoomThreshold, pixelRatio }) => {
|
|
15
16
|
const naturalRef = useRef(natural);
|
|
16
17
|
const viewportRef = useRef(viewport);
|
|
17
18
|
const maxScaleRef = useRef(maxScale ?? 8);
|
|
@@ -22,9 +23,11 @@ const useZoomPan = ({ natural, viewport, maxScale, onCloseRequest, isClosing, is
|
|
|
22
23
|
policyRef.current = defaultZoom ?? "auto";
|
|
23
24
|
const thresholdRef = useRef(autoZoomThreshold ?? 2);
|
|
24
25
|
thresholdRef.current = autoZoomThreshold ?? 2;
|
|
26
|
+
const pixelRatioRef = useRef(pixelRatio);
|
|
27
|
+
pixelRatioRef.current = pixelRatio;
|
|
25
28
|
const computeInitialScale = useCallback((rotation = 0) => {
|
|
26
29
|
const fitRect = computeFit(naturalRef.current, viewportRef.current, rotation, fillViewportRef.current);
|
|
27
|
-
return resolveInitialScale(policyRef.current, naturalRef.current, fitRect, rotation, thresholdRef.current);
|
|
30
|
+
return resolveInitialScale(policyRef.current, naturalRef.current, fitRect, rotation, thresholdRef.current, pixelRatioRef.current ?? screenPixelRatio());
|
|
28
31
|
}, []);
|
|
29
32
|
const [initialScaleSeed] = useState(computeInitialScale);
|
|
30
33
|
const initialScaleRef = useRef(initialScaleSeed);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useZoomPan.mjs","names":[],"sources":["../../../src/Image/viewer/useZoomPan.ts"],"sourcesContent":["import type { MotionValue } from 'motion/react';\nimport { animate, motionValue } from 'motion/react';\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport type { Point, Rect, Rotation, Size, TransformState, ZoomPolicy } from './geometry';\nimport {\n anchoredZoom,\n clampPan,\n clampScale,\n computeFit,\n DEFAULT_AUTO_ZOOM_THRESHOLD,\n DEFAULT_MAX_SCALE,\n doubleClickTarget,\n MIN_SCALE,\n naturalScale,\n normalizeRotation,\n normalizeWheelDelta,\n panBounds,\n resolveInitialScale,\n rubberBand,\n wheelZoomFactor,\n} from './geometry';\n\nconst WHEEL_CLOSE_THRESHOLD = 100;\nconst WHEEL_IDLE_MS = 300;\nconst ZOOM_STEP = 1.5;\nconst RESET_TRANSITION = { damping: 30, stiffness: 300, type: 'spring' as const };\nconst CLEAN_EPSILON = 0.01;\n\nexport interface WheelLikeEvent {\n clientX: number;\n clientY: number;\n ctrlKey?: boolean;\n deltaMode?: number;\n deltaY: number;\n metaKey?: boolean;\n preventDefault?: () => void;\n}\n\nexport interface UseZoomPanOptions {\n autoZoomThreshold?: number;\n defaultZoom?: ZoomPolicy;\n fillViewport?: boolean;\n isClosing?: () => boolean;\n isTransitioning?: () => boolean;\n maxScale?: number;\n natural: Size;\n onCloseRequest?: () => void;\n viewport: Size;\n}\n\nexport interface UseZoomPanResult {\n canZoomIn: boolean;\n canZoomOut: boolean;\n dragBy: (delta: Point) => void;\n dragEnd: () => void;\n escIntent: () => 'reset' | 'close';\n flipHorizontal: () => void;\n flipVertical: () => void;\n flipX: MotionValue<boolean>;\n flipY: MotionValue<boolean>;\n getInitialScale: () => number;\n handleDoubleClick: (point: Point) => void;\n handleWheel: (event: WheelLikeEvent) => void;\n isClean: boolean;\n isZoomed: boolean;\n reset: () => void;\n resetCloseTracking: () => void;\n rotate: MotionValue<number>;\n rotateLeft: () => void;\n rotateRight: () => void;\n rotation: Rotation;\n scale: MotionValue<number>;\n setNatural: (natural: Size) => void;\n setViewport: (viewport: Size) => void;\n toggleActualSize: () => void;\n x: MotionValue<number>;\n y: MotionValue<number>;\n zoomIn: () => void;\n zoomOut: () => void;\n}\n\ninterface DerivedState {\n canZoomIn: boolean;\n canZoomOut: boolean;\n isClean: boolean;\n isZoomed: boolean;\n rotation: Rotation;\n}\n\nexport const useZoomPan = ({\n natural,\n viewport,\n maxScale,\n onCloseRequest,\n isClosing,\n isTransitioning,\n fillViewport,\n defaultZoom,\n autoZoomThreshold,\n}: UseZoomPanOptions): UseZoomPanResult => {\n const naturalRef = useRef(natural);\n const viewportRef = useRef(viewport);\n const maxScaleRef = useRef(maxScale ?? DEFAULT_MAX_SCALE);\n maxScaleRef.current = maxScale ?? DEFAULT_MAX_SCALE;\n const fillViewportRef = useRef(fillViewport ?? false);\n fillViewportRef.current = fillViewport ?? false;\n const policyRef = useRef(defaultZoom ?? 'auto');\n policyRef.current = defaultZoom ?? 'auto';\n const thresholdRef = useRef(autoZoomThreshold ?? DEFAULT_AUTO_ZOOM_THRESHOLD);\n thresholdRef.current = autoZoomThreshold ?? DEFAULT_AUTO_ZOOM_THRESHOLD;\n\n const computeInitialScale = useCallback((rotation: Rotation = 0) => {\n const fitRect = computeFit(\n naturalRef.current,\n viewportRef.current,\n rotation,\n fillViewportRef.current,\n );\n return resolveInitialScale(\n policyRef.current,\n naturalRef.current,\n fitRect,\n rotation,\n thresholdRef.current,\n );\n }, []);\n\n const [initialScaleSeed] = useState(computeInitialScale);\n const initialScaleRef = useRef(initialScaleSeed);\n const getInitialScale = useCallback(() => initialScaleRef.current, []);\n\n const [{ scale, x, y, rotate, flipX, flipY }] = useState(() => ({\n flipX: motionValue(false),\n flipY: motionValue(false),\n rotate: motionValue(0),\n scale: motionValue(initialScaleRef.current),\n x: motionValue(0),\n y: motionValue(0),\n }));\n\n // The ceiling has to clear the opening scale, otherwise a very large image\n // (naturalScale > maxScale) is clamped below the 100% it was asked to open at.\n const effectiveMaxScale = useCallback(\n () => Math.max(maxScaleRef.current, initialScaleRef.current),\n [],\n );\n\n const onCloseRequestRef = useRef(onCloseRequest);\n onCloseRequestRef.current = onCloseRequest;\n\n const isClosingRef = useRef(isClosing);\n isClosingRef.current = isClosing;\n\n const isTransitioningRef = useRef(isTransitioning);\n isTransitioningRef.current = isTransitioning;\n\n const closeAccumRef = useRef(0);\n const disarmedRef = useRef(false);\n const idleTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const resetCloseTracking = useCallback(() => {\n if (idleTimerRef.current !== null) {\n clearTimeout(idleTimerRef.current);\n idleTimerRef.current = null;\n }\n closeAccumRef.current = 0;\n disarmedRef.current = false;\n }, []);\n\n // The close FLIP spring animates these same scale/x/y values. Any of\n // these entry points still firing during the ~300ms close window would\n // either fight that spring visually or, for wheel/reset specifically,\n // race escIntent()/isCleanState() into cancelling the close outright.\n const closing = useCallback(() => isClosingRef.current?.() ?? false, []);\n\n // Three questions that used to share one answer, and stop sharing it the\n // moment the viewer can open at something other than fit:\n // isAtFitFloor — no zoom-out left, so a further scroll down has\n // nowhere to go and becomes the dismiss gesture.\n // isOrientationClean — no rotation/flip to lose, so dismissing is safe.\n // Guards the wheel the same way layered Esc does:\n // state the user built is never thrown away by a\n // gesture that merely ran out of room.\n // isCleanState — both of the above *and* untouched zoom, i.e. \"the\n // user hasn't changed anything at all\", which is what\n // lets Esc/click close outright and lets the close\n // animation FLIP back to the thumbnail instead of fade.\n // All three coincide only while initialScale === MIN_SCALE.\n const isAtFitFloor = useCallback(() => scale.get() <= MIN_SCALE + CLEAN_EPSILON, [scale]);\n\n const isOrientationClean = useCallback(\n () => Math.abs(rotate.get()) < CLEAN_EPSILON && !flipX.get() && !flipY.get(),\n [flipX, flipY, rotate],\n );\n\n const isCleanState = useCallback(\n () => Math.abs(scale.get() - initialScaleRef.current) < CLEAN_EPSILON && isOrientationClean(),\n [isOrientationClean, scale],\n );\n\n const computeDerived = useCallback((): DerivedState => {\n const currentScale = scale.get();\n return {\n canZoomIn: currentScale < effectiveMaxScale(),\n canZoomOut: currentScale > MIN_SCALE,\n isClean: isCleanState(),\n isZoomed: currentScale > MIN_SCALE,\n rotation: normalizeRotation(rotate.get()),\n };\n }, [effectiveMaxScale, isCleanState, rotate, scale]);\n\n const [derived, setDerived] = useState<DerivedState>(computeDerived);\n\n const syncDerived = useCallback(() => {\n setDerived((prev) => {\n const next = computeDerived();\n if (\n prev.canZoomIn === next.canZoomIn &&\n prev.canZoomOut === next.canZoomOut &&\n prev.isClean === next.isClean &&\n prev.isZoomed === next.isZoomed &&\n prev.rotation === next.rotation\n ) {\n return prev;\n }\n return next;\n });\n }, [computeDerived]);\n\n useEffect(() => {\n const unsubscribers = [scale, rotate, flipX, flipY].map((value) =>\n value.on('change', syncDerived),\n );\n syncDerived();\n return () => {\n for (const unsubscribe of unsubscribers) unsubscribe();\n };\n }, [flipX, flipY, rotate, scale, syncDerived]);\n\n const getFitRect = useCallback(\n () =>\n computeFit(\n naturalRef.current,\n viewportRef.current,\n normalizeRotation(rotate.get()),\n fillViewportRef.current,\n ),\n [rotate],\n );\n\n const applyTransform = useCallback(\n (next: TransformState, fitRect: Rect) => {\n const clamped = clampPan(next, fitRect, viewportRef.current);\n // .jump(), not .set(): a surviving spring on these same values (e.g. a\n // dragEnd clamp-back or wheel snap-back still in flight) would otherwise\n // keep animating toward its own target and silently overwrite this\n // instant write on its next tick — motion's set() never stops an\n // active animation, only jump() does.\n scale.jump(next.scale);\n x.jump(clamped.x);\n y.jump(clamped.y);\n },\n [scale, x, y],\n );\n\n // Wheel/pinch stays on the instant applyTransform for 1:1 gesture tracking;\n // stepped inputs (toolbar/keyboard zoom, double-click) animate instead.\n const animateTransform = useCallback(\n (next: TransformState, fitRect: Rect) => {\n const clamped = clampPan(next, fitRect, viewportRef.current);\n animate(scale, next.scale, RESET_TRANSITION);\n animate(x, clamped.x, RESET_TRANSITION);\n animate(y, clamped.y, RESET_TRANSITION);\n },\n [scale, x, y],\n );\n\n const zoomBy = useCallback(\n (factor: number) => {\n if (closing()) return;\n const currentScale = scale.get();\n const targetScale = clampScale(currentScale * factor, effectiveMaxScale());\n const fitRect = getFitRect();\n const anchor: Point = { x: viewportRef.current.width / 2, y: viewportRef.current.height / 2 };\n const next = anchoredZoom(\n { scale: currentScale, x: x.get(), y: y.get() },\n targetScale,\n anchor,\n fitRect,\n );\n animateTransform(next, fitRect);\n },\n [animateTransform, closing, effectiveMaxScale, getFitRect, scale, x, y],\n );\n\n const zoomIn = useCallback(() => zoomBy(ZOOM_STEP), [zoomBy]);\n const zoomOut = useCallback(() => zoomBy(1 / ZOOM_STEP), [zoomBy]);\n\n const handleDoubleClick = useCallback(\n (point: Point) => {\n if (closing()) return;\n const currentScale = scale.get();\n const fitRect = getFitRect();\n const target = doubleClickTarget(\n currentScale,\n naturalRef.current,\n fitRect,\n normalizeRotation(rotate.get()),\n );\n const targetScale = clampScale(target, effectiveMaxScale());\n const next = anchoredZoom(\n { scale: currentScale, x: x.get(), y: y.get() },\n targetScale,\n point,\n fitRect,\n );\n animateTransform(next, fitRect);\n },\n [animateTransform, closing, effectiveMaxScale, getFitRect, rotate, scale, x, y],\n );\n\n const toggleActualSize = useCallback(() => {\n if (closing()) return;\n const currentScale = scale.get();\n const fitRect = getFitRect();\n const actual = naturalScale(naturalRef.current, fitRect, normalizeRotation(rotate.get()));\n const atActual = Math.abs(currentScale - actual) < CLEAN_EPSILON;\n const targetScale = clampScale(atActual ? MIN_SCALE : actual, effectiveMaxScale());\n const anchor: Point = { x: viewportRef.current.width / 2, y: viewportRef.current.height / 2 };\n const next = anchoredZoom(\n { scale: currentScale, x: x.get(), y: y.get() },\n targetScale,\n anchor,\n fitRect,\n );\n animateTransform(next, fitRect);\n }, [animateTransform, closing, effectiveMaxScale, getFitRect, rotate, scale, x, y]);\n\n const handleWheel = useCallback(\n (event: WheelLikeEvent) => {\n event.preventDefault?.();\n if (closing()) return;\n\n if (idleTimerRef.current !== null) clearTimeout(idleTimerRef.current);\n idleTimerRef.current = setTimeout(() => {\n idleTimerRef.current = null;\n closeAccumRef.current = 0;\n disarmedRef.current = false;\n }, WHEEL_IDLE_MS);\n\n const delta = normalizeWheelDelta(event.deltaY, event.deltaMode, viewportRef.current.height);\n\n const currentScale = scale.get();\n const isPinch = !!(event.ctrlKey || event.metaKey);\n // Zooming in is never gated on the current scale: gating it was what made\n // a plain wheel inert at the zoom floor, which reads as enormous damping.\n // Only scrolling *down* while already at the floor has nowhere left to go,\n // and that is precisely where the dismiss gesture takes over.\n const zoomingIn = delta < 0;\n\n if (isPinch || zoomingIn || !isAtFitFloor()) {\n disarmedRef.current = true;\n closeAccumRef.current = 0;\n\n const rawTarget = currentScale * wheelZoomFactor(delta);\n\n if (rawTarget <= MIN_SCALE) {\n animate(scale, MIN_SCALE, RESET_TRANSITION);\n animate(x, 0, RESET_TRANSITION);\n animate(y, 0, RESET_TRANSITION);\n return;\n }\n\n const targetScale = clampScale(rawTarget, effectiveMaxScale());\n const fitRect = getFitRect();\n const anchor: Point = { x: event.clientX, y: event.clientY };\n const next = anchoredZoom(\n { scale: currentScale, x: x.get(), y: y.get() },\n targetScale,\n anchor,\n fitRect,\n );\n applyTransform(next, fitRect);\n return;\n }\n\n // Deliberately not isCleanState(): an image that opened at 100% and was\n // scrolled back down to fit has \"changed\" by that measure, yet it is\n // exactly where the dismiss gesture belongs. Only orientation is worth\n // protecting here.\n if (disarmedRef.current || !isOrientationClean()) return;\n\n closeAccumRef.current += Math.abs(delta);\n if (closeAccumRef.current >= WHEEL_CLOSE_THRESHOLD) {\n closeAccumRef.current = 0;\n onCloseRequestRef.current?.();\n }\n },\n [\n applyTransform,\n closing,\n effectiveMaxScale,\n getFitRect,\n isAtFitFloor,\n isOrientationClean,\n scale,\n x,\n y,\n ],\n );\n\n const rotateBy = useCallback(\n (delta: 90 | -90) => {\n if (closing()) return;\n rotate.jump(normalizeRotation(rotate.get() + delta));\n scale.jump(1);\n x.jump(0);\n y.jump(0);\n },\n [closing, rotate, scale, x, y],\n );\n\n const rotateLeft = useCallback(() => rotateBy(-90), [rotateBy]);\n const rotateRight = useCallback(() => rotateBy(90), [rotateBy]);\n\n const flipHorizontal = useCallback(() => {\n if (closing()) return;\n flipX.set(!flipX.get());\n }, [closing, flipX]);\n\n const flipVertical = useCallback(() => {\n if (closing()) return;\n flipY.set(!flipY.get());\n }, [closing, flipY]);\n\n const reset = useCallback(() => {\n if (closing()) return;\n // Back to how the viewer opened, which is not necessarily fit.\n animate(scale, initialScaleRef.current, RESET_TRANSITION);\n animate(x, 0, RESET_TRANSITION);\n animate(y, 0, RESET_TRANSITION);\n animate(rotate, 0, RESET_TRANSITION);\n flipX.set(false);\n flipY.set(false);\n }, [closing, flipX, flipY, rotate, scale, x, y]);\n\n const dragBy = useCallback(\n (delta: Point) => {\n // A pointer can still be down when close starts (e.g. pinch to just\n // over 1x — inside isClean's epsilon, so Esc/wheel reads 'close' —\n // while the same gesture is still panning). Gated for consistency\n // with the other entry points even though .set() here can't cancel\n // the close spring outright, only cause a self-correcting flicker.\n if (closing()) return;\n const fitRect = getFitRect();\n const bounds = panBounds({ scale: scale.get(), x: 0, y: 0 }, fitRect, viewportRef.current);\n x.set(rubberBand(x.get() + delta.x, bounds.x.min, bounds.x.max));\n y.set(rubberBand(y.get() + delta.y, bounds.y.min, bounds.y.max));\n },\n [closing, getFitRect, scale, x, y],\n );\n\n const dragEnd = useCallback(() => {\n if (closing()) return;\n const fitRect = getFitRect();\n const clamped = clampPan(\n { scale: scale.get(), x: x.get(), y: y.get() },\n fitRect,\n viewportRef.current,\n );\n animate(x, clamped.x, RESET_TRANSITION);\n animate(y, clamped.y, RESET_TRANSITION);\n }, [closing, getFitRect, scale, x, y]);\n\n const escIntent = useCallback(\n (): 'reset' | 'close' => (isCleanState() ? 'close' : 'reset'),\n [isCleanState],\n );\n\n const setViewport = useCallback(\n (next: Size) => {\n viewportRef.current = next;\n const fitRect = computeFit(\n naturalRef.current,\n next,\n normalizeRotation(rotate.get()),\n fillViewportRef.current,\n );\n const clamped = clampPan({ scale: scale.get(), x: x.get(), y: y.get() }, fitRect, next);\n x.set(clamped.x);\n y.set(clamped.y);\n },\n [rotate, scale, x, y],\n );\n\n const setNatural = useCallback(\n (next: Size) => {\n const wasClean = isCleanState();\n naturalRef.current = next;\n const rotation = normalizeRotation(rotate.get());\n initialScaleRef.current = computeInitialScale(rotation);\n\n // A dual-source entry opens on the thumbnail's intrinsic size and only\n // learns the hi-res one here, which can move the opening scale (a 400px\n // stand-in is fit-sized; the 2000px original it becomes is not). Re-land\n // only if the user hasn't taken over — and never mid-transition, where\n // .jump() would kill the open FLIP's spring instead of joining it.\n if (wasClean && !closing() && !isTransitioningRef.current?.()) {\n scale.jump(initialScaleRef.current);\n }\n\n const fitRect = computeFit(next, viewportRef.current, rotation, fillViewportRef.current);\n const clamped = clampPan(\n { scale: scale.get(), x: x.get(), y: y.get() },\n fitRect,\n viewportRef.current,\n );\n x.set(clamped.x);\n y.set(clamped.y);\n },\n [closing, computeInitialScale, isCleanState, rotate, scale, x, y],\n );\n\n return {\n canZoomIn: derived.canZoomIn,\n canZoomOut: derived.canZoomOut,\n dragBy,\n dragEnd,\n escIntent,\n flipHorizontal,\n flipVertical,\n flipX,\n flipY,\n getInitialScale,\n handleDoubleClick,\n handleWheel,\n isClean: derived.isClean,\n isZoomed: derived.isZoomed,\n reset,\n resetCloseTracking,\n rotate,\n rotateLeft,\n rotateRight,\n rotation: derived.rotation,\n scale,\n setNatural,\n setViewport,\n toggleActualSize,\n x,\n y,\n zoomIn,\n zoomOut,\n };\n};\n\nexport type { Point, Rotation, Size, ZoomPolicy } from './geometry';\n"],"mappings":";;;;AAuBA,MAAM,wBAAwB;AAC9B,MAAM,gBAAgB;AACtB,MAAM,YAAY;AAClB,MAAM,mBAAmB;CAAE,SAAS;CAAI,WAAW;CAAK,MAAM;AAAkB;AAChF,MAAM,g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CAAC;EACf,EAAE,IAAI,QAAQ,CAAC;CACjB,GACA;EAAC;EAAS;EAAqB;EAAc;EAAQ;EAAO;EAAG;CAAC,CAClE;CAEA,OAAO;EACL,WAAW,QAAQ;EACnB,YAAY,QAAQ;EACpB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,SAAS,QAAQ;EACjB,UAAU,QAAQ;EAClB;EACA;EACA;EACA;EACA;EACA,UAAU,QAAQ;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useZoomPan.mjs","names":[],"sources":["../../../src/Image/viewer/useZoomPan.ts"],"sourcesContent":["import type { MotionValue } from 'motion/react';\nimport { animate, motionValue } from 'motion/react';\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport type { Point, Rect, Rotation, Size, TransformState, ZoomPolicy } from './geometry';\nimport {\n anchoredZoom,\n clampPan,\n clampScale,\n computeFit,\n DEFAULT_AUTO_ZOOM_THRESHOLD,\n DEFAULT_MAX_SCALE,\n doubleClickTarget,\n MIN_SCALE,\n naturalScale,\n normalizeRotation,\n normalizeWheelDelta,\n panBounds,\n resolveInitialScale,\n rubberBand,\n wheelZoomFactor,\n} from './geometry';\n\nconst WHEEL_CLOSE_THRESHOLD = 100;\nconst WHEEL_IDLE_MS = 300;\nconst ZOOM_STEP = 1.5;\nconst RESET_TRANSITION = { damping: 30, stiffness: 300, type: 'spring' as const };\nconst CLEAN_EPSILON = 0.01;\n\nconst screenPixelRatio = () => (typeof window === 'undefined' ? 1 : window.devicePixelRatio || 1);\n\nexport interface WheelLikeEvent {\n clientX: number;\n clientY: number;\n ctrlKey?: boolean;\n deltaMode?: number;\n deltaY: number;\n metaKey?: boolean;\n preventDefault?: () => void;\n}\n\nexport interface UseZoomPanOptions {\n autoZoomThreshold?: number;\n defaultZoom?: ZoomPolicy;\n fillViewport?: boolean;\n isClosing?: () => boolean;\n isTransitioning?: () => boolean;\n maxScale?: number;\n natural: Size;\n onCloseRequest?: () => void;\n /**\n * Image pixels per CSS pixel at the size the source was captured, read by\n * `defaultZoom: 'auto'`. Defaults to the screen's devicePixelRatio, the best\n * guess for a raster screenshot; vector sources pass 1.\n */\n pixelRatio?: number;\n viewport: Size;\n}\n\nexport interface UseZoomPanResult {\n canZoomIn: boolean;\n canZoomOut: boolean;\n dragBy: (delta: Point) => void;\n dragEnd: () => void;\n escIntent: () => 'reset' | 'close';\n flipHorizontal: () => void;\n flipVertical: () => void;\n flipX: MotionValue<boolean>;\n flipY: MotionValue<boolean>;\n getInitialScale: () => number;\n handleDoubleClick: (point: Point) => void;\n handleWheel: (event: WheelLikeEvent) => void;\n isClean: boolean;\n isZoomed: boolean;\n reset: () => void;\n resetCloseTracking: () => void;\n rotate: MotionValue<number>;\n rotateLeft: () => void;\n rotateRight: () => void;\n rotation: Rotation;\n scale: MotionValue<number>;\n setNatural: (natural: Size) => void;\n setViewport: (viewport: Size) => void;\n toggleActualSize: () => void;\n x: MotionValue<number>;\n y: MotionValue<number>;\n zoomIn: () => void;\n zoomOut: () => void;\n}\n\ninterface DerivedState {\n canZoomIn: boolean;\n canZoomOut: boolean;\n isClean: boolean;\n isZoomed: boolean;\n rotation: Rotation;\n}\n\nexport const useZoomPan = ({\n natural,\n viewport,\n maxScale,\n onCloseRequest,\n isClosing,\n isTransitioning,\n fillViewport,\n defaultZoom,\n autoZoomThreshold,\n pixelRatio,\n}: UseZoomPanOptions): UseZoomPanResult => {\n const naturalRef = useRef(natural);\n const viewportRef = useRef(viewport);\n const maxScaleRef = useRef(maxScale ?? DEFAULT_MAX_SCALE);\n maxScaleRef.current = maxScale ?? DEFAULT_MAX_SCALE;\n const fillViewportRef = useRef(fillViewport ?? false);\n fillViewportRef.current = fillViewport ?? false;\n const policyRef = useRef(defaultZoom ?? 'auto');\n policyRef.current = defaultZoom ?? 'auto';\n const thresholdRef = useRef(autoZoomThreshold ?? DEFAULT_AUTO_ZOOM_THRESHOLD);\n thresholdRef.current = autoZoomThreshold ?? DEFAULT_AUTO_ZOOM_THRESHOLD;\n const pixelRatioRef = useRef(pixelRatio);\n pixelRatioRef.current = pixelRatio;\n\n const computeInitialScale = useCallback((rotation: Rotation = 0) => {\n const fitRect = computeFit(\n naturalRef.current,\n viewportRef.current,\n rotation,\n fillViewportRef.current,\n );\n return resolveInitialScale(\n policyRef.current,\n naturalRef.current,\n fitRect,\n rotation,\n thresholdRef.current,\n pixelRatioRef.current ?? screenPixelRatio(),\n );\n }, []);\n\n const [initialScaleSeed] = useState(computeInitialScale);\n const initialScaleRef = useRef(initialScaleSeed);\n const getInitialScale = useCallback(() => initialScaleRef.current, []);\n\n const [{ scale, x, y, rotate, flipX, flipY }] = useState(() => ({\n flipX: motionValue(false),\n flipY: motionValue(false),\n rotate: motionValue(0),\n scale: motionValue(initialScaleRef.current),\n x: motionValue(0),\n y: motionValue(0),\n }));\n\n // The ceiling has to clear the opening scale, otherwise a very large image\n // (naturalScale > maxScale) is clamped below the 100% it was asked to open at.\n const effectiveMaxScale = useCallback(\n () => Math.max(maxScaleRef.current, initialScaleRef.current),\n [],\n );\n\n const onCloseRequestRef = useRef(onCloseRequest);\n onCloseRequestRef.current = onCloseRequest;\n\n const isClosingRef = useRef(isClosing);\n isClosingRef.current = isClosing;\n\n const isTransitioningRef = useRef(isTransitioning);\n isTransitioningRef.current = isTransitioning;\n\n const closeAccumRef = useRef(0);\n const disarmedRef = useRef(false);\n const idleTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const resetCloseTracking = useCallback(() => {\n if (idleTimerRef.current !== null) {\n clearTimeout(idleTimerRef.current);\n idleTimerRef.current = null;\n }\n closeAccumRef.current = 0;\n disarmedRef.current = false;\n }, []);\n\n // The close FLIP spring animates these same scale/x/y values. Any of\n // these entry points still firing during the ~300ms close window would\n // either fight that spring visually or, for wheel/reset specifically,\n // race escIntent()/isCleanState() into cancelling the close outright.\n const closing = useCallback(() => isClosingRef.current?.() ?? false, []);\n\n // Three questions that used to share one answer, and stop sharing it the\n // moment the viewer can open at something other than fit:\n // isAtFitFloor — no zoom-out left, so a further scroll down has\n // nowhere to go and becomes the dismiss gesture.\n // isOrientationClean — no rotation/flip to lose, so dismissing is safe.\n // Guards the wheel the same way layered Esc does:\n // state the user built is never thrown away by a\n // gesture that merely ran out of room.\n // isCleanState — both of the above *and* untouched zoom, i.e. \"the\n // user hasn't changed anything at all\", which is what\n // lets Esc/click close outright and lets the close\n // animation FLIP back to the thumbnail instead of fade.\n // All three coincide only while initialScale === MIN_SCALE.\n const isAtFitFloor = useCallback(() => scale.get() <= MIN_SCALE + CLEAN_EPSILON, [scale]);\n\n const isOrientationClean = useCallback(\n () => Math.abs(rotate.get()) < CLEAN_EPSILON && !flipX.get() && !flipY.get(),\n [flipX, flipY, rotate],\n );\n\n const isCleanState = useCallback(\n () => Math.abs(scale.get() - initialScaleRef.current) < CLEAN_EPSILON && isOrientationClean(),\n [isOrientationClean, scale],\n );\n\n const computeDerived = useCallback((): DerivedState => {\n const currentScale = scale.get();\n return {\n canZoomIn: currentScale < effectiveMaxScale(),\n canZoomOut: currentScale > MIN_SCALE,\n isClean: isCleanState(),\n isZoomed: currentScale > MIN_SCALE,\n rotation: normalizeRotation(rotate.get()),\n };\n }, [effectiveMaxScale, isCleanState, rotate, scale]);\n\n const [derived, setDerived] = useState<DerivedState>(computeDerived);\n\n const syncDerived = useCallback(() => {\n setDerived((prev) => {\n const next = computeDerived();\n if (\n prev.canZoomIn === next.canZoomIn &&\n prev.canZoomOut === next.canZoomOut &&\n prev.isClean === next.isClean &&\n prev.isZoomed === next.isZoomed &&\n prev.rotation === next.rotation\n ) {\n return prev;\n }\n return next;\n });\n }, [computeDerived]);\n\n useEffect(() => {\n const unsubscribers = [scale, rotate, flipX, flipY].map((value) =>\n value.on('change', syncDerived),\n );\n syncDerived();\n return () => {\n for (const unsubscribe of unsubscribers) unsubscribe();\n };\n }, [flipX, flipY, rotate, scale, syncDerived]);\n\n const getFitRect = useCallback(\n () =>\n computeFit(\n naturalRef.current,\n viewportRef.current,\n normalizeRotation(rotate.get()),\n fillViewportRef.current,\n ),\n [rotate],\n );\n\n const applyTransform = useCallback(\n (next: TransformState, fitRect: Rect) => {\n const clamped = clampPan(next, fitRect, viewportRef.current);\n // .jump(), not .set(): a surviving spring on these same values (e.g. a\n // dragEnd clamp-back or wheel snap-back still in flight) would otherwise\n // keep animating toward its own target and silently overwrite this\n // instant write on its next tick — motion's set() never stops an\n // active animation, only jump() does.\n scale.jump(next.scale);\n x.jump(clamped.x);\n y.jump(clamped.y);\n },\n [scale, x, y],\n );\n\n // Wheel/pinch stays on the instant applyTransform for 1:1 gesture tracking;\n // stepped inputs (toolbar/keyboard zoom, double-click) animate instead.\n const animateTransform = useCallback(\n (next: TransformState, fitRect: Rect) => {\n const clamped = clampPan(next, fitRect, viewportRef.current);\n animate(scale, next.scale, RESET_TRANSITION);\n animate(x, clamped.x, RESET_TRANSITION);\n animate(y, clamped.y, RESET_TRANSITION);\n },\n [scale, x, y],\n );\n\n const zoomBy = useCallback(\n (factor: number) => {\n if (closing()) return;\n const currentScale = scale.get();\n const targetScale = clampScale(currentScale * factor, effectiveMaxScale());\n const fitRect = getFitRect();\n const anchor: Point = { x: viewportRef.current.width / 2, y: viewportRef.current.height / 2 };\n const next = anchoredZoom(\n { scale: currentScale, x: x.get(), y: y.get() },\n targetScale,\n anchor,\n fitRect,\n );\n animateTransform(next, fitRect);\n },\n [animateTransform, closing, effectiveMaxScale, getFitRect, scale, x, y],\n );\n\n const zoomIn = useCallback(() => zoomBy(ZOOM_STEP), [zoomBy]);\n const zoomOut = useCallback(() => zoomBy(1 / ZOOM_STEP), [zoomBy]);\n\n const handleDoubleClick = useCallback(\n (point: Point) => {\n if (closing()) return;\n const currentScale = scale.get();\n const fitRect = getFitRect();\n const target = doubleClickTarget(\n currentScale,\n naturalRef.current,\n fitRect,\n normalizeRotation(rotate.get()),\n );\n const targetScale = clampScale(target, effectiveMaxScale());\n const next = anchoredZoom(\n { scale: currentScale, x: x.get(), y: y.get() },\n targetScale,\n point,\n fitRect,\n );\n animateTransform(next, fitRect);\n },\n [animateTransform, closing, effectiveMaxScale, getFitRect, rotate, scale, x, y],\n );\n\n const toggleActualSize = useCallback(() => {\n if (closing()) return;\n const currentScale = scale.get();\n const fitRect = getFitRect();\n const actual = naturalScale(naturalRef.current, fitRect, normalizeRotation(rotate.get()));\n const atActual = Math.abs(currentScale - actual) < CLEAN_EPSILON;\n const targetScale = clampScale(atActual ? MIN_SCALE : actual, effectiveMaxScale());\n const anchor: Point = { x: viewportRef.current.width / 2, y: viewportRef.current.height / 2 };\n const next = anchoredZoom(\n { scale: currentScale, x: x.get(), y: y.get() },\n targetScale,\n anchor,\n fitRect,\n );\n animateTransform(next, fitRect);\n }, [animateTransform, closing, effectiveMaxScale, getFitRect, rotate, scale, x, y]);\n\n const handleWheel = useCallback(\n (event: WheelLikeEvent) => {\n event.preventDefault?.();\n if (closing()) return;\n\n if (idleTimerRef.current !== null) clearTimeout(idleTimerRef.current);\n idleTimerRef.current = setTimeout(() => {\n idleTimerRef.current = null;\n closeAccumRef.current = 0;\n disarmedRef.current = false;\n }, WHEEL_IDLE_MS);\n\n const delta = normalizeWheelDelta(event.deltaY, event.deltaMode, viewportRef.current.height);\n\n const currentScale = scale.get();\n const isPinch = !!(event.ctrlKey || event.metaKey);\n // Zooming in is never gated on the current scale: gating it was what made\n // a plain wheel inert at the zoom floor, which reads as enormous damping.\n // Only scrolling *down* while already at the floor has nowhere left to go,\n // and that is precisely where the dismiss gesture takes over.\n const zoomingIn = delta < 0;\n\n if (isPinch || zoomingIn || !isAtFitFloor()) {\n disarmedRef.current = true;\n closeAccumRef.current = 0;\n\n const rawTarget = currentScale * wheelZoomFactor(delta);\n\n if (rawTarget <= MIN_SCALE) {\n animate(scale, MIN_SCALE, RESET_TRANSITION);\n animate(x, 0, RESET_TRANSITION);\n animate(y, 0, RESET_TRANSITION);\n return;\n }\n\n const targetScale = clampScale(rawTarget, effectiveMaxScale());\n const fitRect = getFitRect();\n const anchor: Point = { x: event.clientX, y: event.clientY };\n const next = anchoredZoom(\n { scale: currentScale, x: x.get(), y: y.get() },\n targetScale,\n anchor,\n fitRect,\n );\n applyTransform(next, fitRect);\n return;\n }\n\n // Deliberately not isCleanState(): an image that opened at 100% and was\n // scrolled back down to fit has \"changed\" by that measure, yet it is\n // exactly where the dismiss gesture belongs. Only orientation is worth\n // protecting here.\n if (disarmedRef.current || !isOrientationClean()) return;\n\n closeAccumRef.current += Math.abs(delta);\n if (closeAccumRef.current >= WHEEL_CLOSE_THRESHOLD) {\n closeAccumRef.current = 0;\n onCloseRequestRef.current?.();\n }\n },\n [\n applyTransform,\n closing,\n effectiveMaxScale,\n getFitRect,\n isAtFitFloor,\n isOrientationClean,\n scale,\n x,\n y,\n ],\n );\n\n const rotateBy = useCallback(\n (delta: 90 | -90) => {\n if (closing()) return;\n rotate.jump(normalizeRotation(rotate.get() + delta));\n scale.jump(1);\n x.jump(0);\n y.jump(0);\n },\n [closing, rotate, scale, x, y],\n );\n\n const rotateLeft = useCallback(() => rotateBy(-90), [rotateBy]);\n const rotateRight = useCallback(() => rotateBy(90), [rotateBy]);\n\n const flipHorizontal = useCallback(() => {\n if (closing()) return;\n flipX.set(!flipX.get());\n }, [closing, flipX]);\n\n const flipVertical = useCallback(() => {\n if (closing()) return;\n flipY.set(!flipY.get());\n }, [closing, flipY]);\n\n const reset = useCallback(() => {\n if (closing()) return;\n // Back to how the viewer opened, which is not necessarily fit.\n animate(scale, initialScaleRef.current, RESET_TRANSITION);\n animate(x, 0, RESET_TRANSITION);\n animate(y, 0, RESET_TRANSITION);\n animate(rotate, 0, RESET_TRANSITION);\n flipX.set(false);\n flipY.set(false);\n }, [closing, flipX, flipY, rotate, scale, x, y]);\n\n const dragBy = useCallback(\n (delta: Point) => {\n // A pointer can still be down when close starts (e.g. pinch to just\n // over 1x — inside isClean's epsilon, so Esc/wheel reads 'close' —\n // while the same gesture is still panning). Gated for consistency\n // with the other entry points even though .set() here can't cancel\n // the close spring outright, only cause a self-correcting flicker.\n if (closing()) return;\n const fitRect = getFitRect();\n const bounds = panBounds({ scale: scale.get(), x: 0, y: 0 }, fitRect, viewportRef.current);\n x.set(rubberBand(x.get() + delta.x, bounds.x.min, bounds.x.max));\n y.set(rubberBand(y.get() + delta.y, bounds.y.min, bounds.y.max));\n },\n [closing, getFitRect, scale, x, y],\n );\n\n const dragEnd = useCallback(() => {\n if (closing()) return;\n const fitRect = getFitRect();\n const clamped = clampPan(\n { scale: scale.get(), x: x.get(), y: y.get() },\n fitRect,\n viewportRef.current,\n );\n animate(x, clamped.x, RESET_TRANSITION);\n animate(y, clamped.y, RESET_TRANSITION);\n }, [closing, getFitRect, scale, x, y]);\n\n const escIntent = useCallback(\n (): 'reset' | 'close' => (isCleanState() ? 'close' : 'reset'),\n [isCleanState],\n );\n\n const setViewport = useCallback(\n (next: Size) => {\n viewportRef.current = next;\n const fitRect = computeFit(\n naturalRef.current,\n next,\n normalizeRotation(rotate.get()),\n fillViewportRef.current,\n );\n const clamped = clampPan({ scale: scale.get(), x: x.get(), y: y.get() }, fitRect, next);\n x.set(clamped.x);\n y.set(clamped.y);\n },\n [rotate, scale, x, y],\n );\n\n const setNatural = useCallback(\n (next: Size) => {\n const wasClean = isCleanState();\n naturalRef.current = next;\n const rotation = normalizeRotation(rotate.get());\n initialScaleRef.current = computeInitialScale(rotation);\n\n // A dual-source entry opens on the thumbnail's intrinsic size and only\n // learns the hi-res one here, which can move the opening scale (a 400px\n // stand-in is fit-sized; the 2000px original it becomes is not). Re-land\n // only if the user hasn't taken over — and never mid-transition, where\n // .jump() would kill the open FLIP's spring instead of joining it.\n if (wasClean && !closing() && !isTransitioningRef.current?.()) {\n scale.jump(initialScaleRef.current);\n }\n\n const fitRect = computeFit(next, viewportRef.current, rotation, fillViewportRef.current);\n const clamped = clampPan(\n { scale: scale.get(), x: x.get(), y: y.get() },\n fitRect,\n viewportRef.current,\n );\n x.set(clamped.x);\n y.set(clamped.y);\n },\n [closing, computeInitialScale, isCleanState, rotate, scale, x, y],\n );\n\n return {\n canZoomIn: derived.canZoomIn,\n canZoomOut: derived.canZoomOut,\n dragBy,\n dragEnd,\n escIntent,\n flipHorizontal,\n flipVertical,\n flipX,\n flipY,\n getInitialScale,\n handleDoubleClick,\n handleWheel,\n isClean: derived.isClean,\n isZoomed: derived.isZoomed,\n reset,\n resetCloseTracking,\n rotate,\n rotateLeft,\n rotateRight,\n rotation: derived.rotation,\n scale,\n setNatural,\n setViewport,\n toggleActualSize,\n x,\n y,\n zoomIn,\n zoomOut,\n };\n};\n\nexport type { Point, Rotation, Size, ZoomPolicy } from './geometry';\n"],"mappings":";;;;AAuBA,MAAM,wBAAwB;AAC9B,MAAM,gBAAgB;AACtB,MAAM,YAAY;AAClB,MAAM,mBAAmB;CAAE,SAAS;CAAI,WAAW;CAAK,MAAM;AAAkB;AAChF,MAAM,gBAAgB;AAEtB,MAAM,yBAA0B,OAAO,WAAW,cAAc,IAAI,OAAO,oBAAoB;AAqE/F,MAAa,cAAc,EACzB,SACA,UACA,UACA,gBACA,WACA,iBACA,cACA,aACA,mBACA,iBACyC;CACzC,MAAM,aAAa,OAAO,OAAO;CACjC,MAAM,cAAc,OAAO,QAAQ;CACnC,MAAM,cAAc,OAAO,YAAA,CAA6B;CACxD,YAAY,UAAU,YAAA;CACtB,MAAM,kBAAkB,OAAO,gBAAgB,KAAK;CACpD,gBAAgB,UAAU,gBAAgB;CAC1C,MAAM,YAAY,OAAO,eAAe,MAAM;CAC9C,UAAU,UAAU,eAAe;CACnC,MAAM,eAAe,OAAO,qBAAA,CAAgD;CAC5E,aAAa,UAAU,qBAAA;CACvB,MAAM,gBAAgB,OAAO,UAAU;CACvC,cAAc,UAAU;CAExB,MAAM,sBAAsB,aAAa,WAAqB,MAAM;EAClE,MAAM,UAAU,WACd,WAAW,SACX,YAAY,SACZ,UACA,gBAAgB,OAClB;EACA,OAAO,oBACL,UAAU,SACV,WAAW,SACX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CAAC,GAC9B,gBAAgB,OAClB;EACA,MAAM,UAAU,SAAS;GAAE,OAAO,MAAM,IAAI;GAAG,GAAG,EAAE,IAAI;GAAG,GAAG,EAAE,IAAI;EAAE,GAAG,SAAS,IAAI;EACtF,EAAE,IAAI,QAAQ,CAAC;EACf,EAAE,IAAI,QAAQ,CAAC;CACjB,GACA;EAAC;EAAQ;EAAO;EAAG;CAAC,CACtB;CAEA,MAAM,aAAa,aAChB,SAAe;EACd,MAAM,WAAW,aAAa;EAC9B,WAAW,UAAU;EACrB,MAAM,WAAW,kBAAkB,OAAO,IAAI,CAAC;EAC/C,gBAAgB,UAAU,oBAAoB,QAAQ;EAOtD,IAAI,YAAY,CAAC,QAAQ,KAAK,CAAC,mBAAmB,UAAU,GAC1D,MAAM,KAAK,gBAAgB,OAAO;EAGpC,MAAM,UAAU,WAAW,MAAM,YAAY,SAAS,UAAU,gBAAgB,OAAO;EACvF,MAAM,UAAU,SACd;GAAE,OAAO,MAAM,IAAI;GAAG,GAAG,EAAE,IAAI;GAAG,GAAG,EAAE,IAAI;EAAE,GAC7C,SACA,YAAY,OACd;EACA,EAAE,IAAI,QAAQ,CAAC;EACf,EAAE,IAAI,QAAQ,CAAC;CACjB,GACA;EAAC;EAAS;EAAqB;EAAc;EAAQ;EAAO;EAAG;CAAC,CAClE;CAEA,OAAO;EACL,WAAW,QAAQ;EACnB,YAAY,QAAQ;EACpB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,SAAS,QAAQ;EACjB,UAAU,QAAQ;EAClB;EACA;EACA;EACA;EACA;EACA,UAAU,QAAQ;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MermaidSvg.mjs","names":[],"sources":["../../../src/Mermaid/SyntaxMermaid/MermaidSvg.tsx"],"sourcesContent":["'use client';\n\nimport * as stylex from '@stylexjs/stylex';\nimport { memo, type Ref, useCallback, useEffect, useRef, useState } from 'react';\n\nimport { DEFAULT_AUTO_ZOOM_THRESHOLD, DEFAULT_MAX_SCALE } from '@/Image/viewer/geometry';\nimport PreviewOutlet from '@/Image/viewer/PreviewOutlet';\nimport { openPreview } from '@/Image/viewer/registry';\n\nimport { toStandaloneSvgString } from './standaloneSvg';\nimport { styles } from './style';\n\ninterface MermaidSvgProps {\n className?: string;\n dataAttributes?: Record<`data-${string}`, string>;\n ref?: Ref<HTMLDivElement>;\n style?: React.CSSProperties;\n svg: string;\n}\n\n// The viewer flies the image out of the element it was opened from, so the\n// diagram needs a real <img> to measure — hence a hidden anchor tracking the\n// diagram box rather than a display:none preview image.\nconst anchorStyle: React.CSSProperties = {\n height: '100%',\n insetBlockStart: 0,\n insetInlineStart: 0,\n pointerEvents: 'none',\n position: 'absolute',\n visibility: 'hidden',\n width: '100%',\n};\n\nconst MermaidSvg = memo<MermaidSvgProps>(({ className, dataAttributes, ref, style, svg }) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const anchorRef = useRef<HTMLImageElement>(null);\n const [previewUrl, setPreviewUrl] = useState<string>();\n\n useEffect(() => {\n return () => {\n if (previewUrl) URL.revokeObjectURL(previewUrl);\n };\n }, [previewUrl]);\n\n // The preview copy is only built on demand: it has to bake in the resolved\n // CSS variables, which the inline copy does not need.\n const handleOpen = useCallback(() => {\n const element = containerRef.current?.querySelector('svg');\n const anchor = anchorRef.current;\n if (!element || !anchor) return;\n\n const standalone = toStandaloneSvgString(element);\n const url = URL.createObjectURL(new Blob([standalone], { type: 'image/svg+xml' }));\n setPreviewUrl((previous) => {\n if (previous) URL.revokeObjectURL(previous);\n return url;\n });\n\n openPreview({\n element: anchor,\n options: {\n autoZoomThreshold: DEFAULT_AUTO_ZOOM_THRESHOLD,\n defaultZoom: 'auto',\n maxScale: DEFAULT_MAX_SCALE,\n },\n src: url,\n });\n }, []);\n\n return (\n <div {...dataAttributes} className={className} ref={ref} style={style}>\n <div\n {...stylex.props(styles.zoomIn)}\n dangerouslySetInnerHTML={{ __html: svg }}\n ref={containerRef}\n onClick={handleOpen}\n />\n <img aria-hidden alt=\"\" ref={anchorRef} src={previewUrl} style={anchorStyle} />\n <PreviewOutlet elementRef={anchorRef} />\n </div>\n );\n});\n\nMermaidSvg.displayName = 'MermaidSvg';\n\nexport default MermaidSvg;\n"],"mappings":";;;;;;;;;AAoBA,MAAM,cAAmC;CACvC,QAAQ;CACR,iBAAiB;CACjB,kBAAkB;CAClB,eAAe;CACf,UAAU;CACV,YAAY;CACZ,OAAO;AACT;AACA,MAAM,aAAa,MAAuB,EACxC,WACA,gBACA,KACA,OACA,UACI;CACJ,MAAM,eAAe,OAAuB,IAAI;CAChD,MAAM,YAAY,OAAyB,IAAI;CAC/C,MAAM,CAAC,YAAY,iBAAiB,SAAiB;CACrD,gBAAgB;EACd,aAAa;GACX,IAAI,YAAY,IAAI,gBAAgB,UAAU;EAChD;CACF,GAAG,CAAC,UAAU,CAAC;CAIf,MAAM,aAAa,kBAAkB;EACnC,MAAM,UAAU,aAAa,SAAS,cAAc,KAAK;EACzD,MAAM,SAAS,UAAU;EACzB,IAAI,CAAC,WAAW,CAAC,QAAQ;EACzB,MAAM,aAAa,sBAAsB,OAAO;EAChD,MAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,UAAU,GAAG,EACrD,MAAM,gBACR,CAAC,CAAC;EACF,eAAc,aAAY;GACxB,IAAI,UAAU,IAAI,gBAAgB,QAAQ;GAC1C,OAAO;EACT,CAAC;EACD,YAAY;GACV,SAAS;GACT,SAAS;IACP,mBAAA;IACA,aAAa;IACb,UAAA;
|
|
1
|
+
{"version":3,"file":"MermaidSvg.mjs","names":[],"sources":["../../../src/Mermaid/SyntaxMermaid/MermaidSvg.tsx"],"sourcesContent":["'use client';\n\nimport * as stylex from '@stylexjs/stylex';\nimport { memo, type Ref, useCallback, useEffect, useRef, useState } from 'react';\n\nimport { DEFAULT_AUTO_ZOOM_THRESHOLD, DEFAULT_MAX_SCALE } from '@/Image/viewer/geometry';\nimport PreviewOutlet from '@/Image/viewer/PreviewOutlet';\nimport { openPreview } from '@/Image/viewer/registry';\n\nimport { toStandaloneSvgString } from './standaloneSvg';\nimport { styles } from './style';\n\ninterface MermaidSvgProps {\n className?: string;\n dataAttributes?: Record<`data-${string}`, string>;\n ref?: Ref<HTMLDivElement>;\n style?: React.CSSProperties;\n svg: string;\n}\n\n// The viewer flies the image out of the element it was opened from, so the\n// diagram needs a real <img> to measure — hence a hidden anchor tracking the\n// diagram box rather than a display:none preview image.\nconst anchorStyle: React.CSSProperties = {\n height: '100%',\n insetBlockStart: 0,\n insetInlineStart: 0,\n pointerEvents: 'none',\n position: 'absolute',\n visibility: 'hidden',\n width: '100%',\n};\n\nconst MermaidSvg = memo<MermaidSvgProps>(({ className, dataAttributes, ref, style, svg }) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const anchorRef = useRef<HTMLImageElement>(null);\n const [previewUrl, setPreviewUrl] = useState<string>();\n\n useEffect(() => {\n return () => {\n if (previewUrl) URL.revokeObjectURL(previewUrl);\n };\n }, [previewUrl]);\n\n // The preview copy is only built on demand: it has to bake in the resolved\n // CSS variables, which the inline copy does not need.\n const handleOpen = useCallback(() => {\n const element = containerRef.current?.querySelector('svg');\n const anchor = anchorRef.current;\n if (!element || !anchor) return;\n\n const standalone = toStandaloneSvgString(element);\n const url = URL.createObjectURL(new Blob([standalone], { type: 'image/svg+xml' }));\n setPreviewUrl((previous) => {\n if (previous) URL.revokeObjectURL(previous);\n return url;\n });\n\n openPreview({\n element: anchor,\n options: {\n autoZoomThreshold: DEFAULT_AUTO_ZOOM_THRESHOLD,\n defaultZoom: 'auto',\n maxScale: DEFAULT_MAX_SCALE,\n // The SVG's natural size is already in CSS pixels on any screen.\n pixelRatio: 1,\n },\n src: url,\n });\n }, []);\n\n return (\n <div {...dataAttributes} className={className} ref={ref} style={style}>\n <div\n {...stylex.props(styles.zoomIn)}\n dangerouslySetInnerHTML={{ __html: svg }}\n ref={containerRef}\n onClick={handleOpen}\n />\n <img aria-hidden alt=\"\" ref={anchorRef} src={previewUrl} style={anchorStyle} />\n <PreviewOutlet elementRef={anchorRef} />\n </div>\n );\n});\n\nMermaidSvg.displayName = 'MermaidSvg';\n\nexport default MermaidSvg;\n"],"mappings":";;;;;;;;;AAoBA,MAAM,cAAmC;CACvC,QAAQ;CACR,iBAAiB;CACjB,kBAAkB;CAClB,eAAe;CACf,UAAU;CACV,YAAY;CACZ,OAAO;AACT;AACA,MAAM,aAAa,MAAuB,EACxC,WACA,gBACA,KACA,OACA,UACI;CACJ,MAAM,eAAe,OAAuB,IAAI;CAChD,MAAM,YAAY,OAAyB,IAAI;CAC/C,MAAM,CAAC,YAAY,iBAAiB,SAAiB;CACrD,gBAAgB;EACd,aAAa;GACX,IAAI,YAAY,IAAI,gBAAgB,UAAU;EAChD;CACF,GAAG,CAAC,UAAU,CAAC;CAIf,MAAM,aAAa,kBAAkB;EACnC,MAAM,UAAU,aAAa,SAAS,cAAc,KAAK;EACzD,MAAM,SAAS,UAAU;EACzB,IAAI,CAAC,WAAW,CAAC,QAAQ;EACzB,MAAM,aAAa,sBAAsB,OAAO;EAChD,MAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,UAAU,GAAG,EACrD,MAAM,gBACR,CAAC,CAAC;EACF,eAAc,aAAY;GACxB,IAAI,UAAU,IAAI,gBAAgB,QAAQ;GAC1C,OAAO;EACT,CAAC;EACD,YAAY;GACV,SAAS;GACT,SAAS;IACP,mBAAA;IACA,aAAa;IACb,UAAA;IAEA,YAAY;GACd;GACA,KAAK;EACP,CAAC;CACH,GAAG,CAAC,CAAC;CACL,OAAO,qBAAC,OAAD;EAAK,GAAI;EAA2B;EAAgB;EAAY;EAAhE,UAAA;GACH,oBAAC,OAAD;IAAK,GAAI,OAAO,MAAM,OAAO,MAAM;IAAG,yBAAyB,EAC/D,QAAQ,IACV;IAAG,KAAK;IAAc,SAAS;GAAa,CAAA;GAC1C,oBAAC,OAAD;IAAK,eAAA;IAAY,KAAI;IAAG,KAAK;IAAW,KAAK;IAAY,OAAO;GAAc,CAAA;GAC9E,oBAAC,eAAD,EAAe,YAAY,UAAY,CAAA;EACpC;;AACT,CAAC;AACD,WAAW,cAAc"}
|
package/es/Tabs/style.d.mts
CHANGED
package/es/style.css
CHANGED
|
@@ -5999,6 +5999,10 @@
|
|
|
5999
5999
|
transition: transform .16s var(--lobe-motion-ease-out);
|
|
6000
6000
|
}
|
|
6001
6001
|
|
|
6002
|
+
.lb1ja9v0h {
|
|
6003
|
+
transition: transform .18s cubic-bezier(.22, 1, .36, 1), opacity .18s ease-out;
|
|
6004
|
+
}
|
|
6005
|
+
|
|
6002
6006
|
.lblhg8ld {
|
|
6003
6007
|
transition: transform .24s var(--lobe-motion-ease-out);
|
|
6004
6008
|
}
|
|
@@ -6027,8 +6031,8 @@
|
|
|
6027
6031
|
transition: width .2s, background .2s;
|
|
6028
6032
|
}
|
|
6029
6033
|
|
|
6030
|
-
.
|
|
6031
|
-
transition: width .
|
|
6034
|
+
.lbp7890b {
|
|
6035
|
+
transition: width .3s cubic-bezier(.22, 1, .36, 1), margin .3s cubic-bezier(.22, 1, .36, 1);
|
|
6032
6036
|
}
|
|
6033
6037
|
|
|
6034
6038
|
.lb15cnf4b {
|
|
@@ -8875,6 +8879,10 @@
|
|
|
8875
8879
|
transform: rotateX(60deg);
|
|
8876
8880
|
}
|
|
8877
8881
|
|
|
8882
|
+
.lb1a33avv {
|
|
8883
|
+
transform: scale(.5);
|
|
8884
|
+
}
|
|
8885
|
+
|
|
8878
8886
|
.lb10078c2 {
|
|
8879
8887
|
transform: scale(.66);
|
|
8880
8888
|
}
|
|
@@ -8883,6 +8891,10 @@
|
|
|
8883
8891
|
transform: scale(.75);
|
|
8884
8892
|
}
|
|
8885
8893
|
|
|
8894
|
+
.lb3oybdh {
|
|
8895
|
+
transform: scale(1);
|
|
8896
|
+
}
|
|
8897
|
+
|
|
8886
8898
|
.lb1ufz0iv {
|
|
8887
8899
|
transform: scaleX(0);
|
|
8888
8900
|
}
|