@univerjs/design 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/lib/cjs/index.js +4212 -25
  2. package/lib/cjs/locale/ca-ES.js +54 -1
  3. package/lib/cjs/locale/en-US.js +69 -1
  4. package/lib/cjs/locale/es-ES.js +54 -1
  5. package/lib/cjs/locale/fa-IR.js +54 -1
  6. package/lib/cjs/locale/fr-FR.js +54 -1
  7. package/lib/cjs/locale/ja-JP.js +54 -1
  8. package/lib/cjs/locale/ko-KR.js +54 -1
  9. package/lib/cjs/locale/ru-RU.js +54 -1
  10. package/lib/cjs/locale/sk-SK.js +54 -1
  11. package/lib/cjs/locale/vi-VN.js +54 -1
  12. package/lib/cjs/locale/zh-CN.js +54 -1
  13. package/lib/cjs/locale/zh-TW.js +54 -1
  14. package/lib/es/index.js +4146 -25
  15. package/lib/es/locale/ca-ES.js +53 -1
  16. package/lib/es/locale/en-US.js +68 -1
  17. package/lib/es/locale/es-ES.js +53 -1
  18. package/lib/es/locale/fa-IR.js +53 -1
  19. package/lib/es/locale/fr-FR.js +53 -1
  20. package/lib/es/locale/ja-JP.js +53 -1
  21. package/lib/es/locale/ko-KR.js +53 -1
  22. package/lib/es/locale/ru-RU.js +53 -1
  23. package/lib/es/locale/sk-SK.js +53 -1
  24. package/lib/es/locale/vi-VN.js +53 -1
  25. package/lib/es/locale/zh-CN.js +53 -1
  26. package/lib/es/locale/zh-TW.js +53 -1
  27. package/lib/index.js +4146 -25
  28. package/lib/locale/ca-ES.js +53 -1
  29. package/lib/locale/en-US.js +68 -1
  30. package/lib/locale/es-ES.js +53 -1
  31. package/lib/locale/fa-IR.js +53 -1
  32. package/lib/locale/fr-FR.js +53 -1
  33. package/lib/locale/ja-JP.js +53 -1
  34. package/lib/locale/ko-KR.js +53 -1
  35. package/lib/locale/ru-RU.js +53 -1
  36. package/lib/locale/sk-SK.js +53 -1
  37. package/lib/locale/vi-VN.js +53 -1
  38. package/lib/locale/zh-CN.js +53 -1
  39. package/lib/locale/zh-TW.js +53 -1
  40. package/lib/umd/index.js +23 -23
  41. package/package.json +4 -4
package/lib/cjs/index.js CHANGED
@@ -1,84 +1,4271 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/icons`),t=require(`react`),n=require(`clsx`),r=require(`tailwind-merge`),i=require(`react/jsx-runtime`),a=require(`class-variance-authority`),o=require(`@radix-ui/react-slot`),s=require(`@radix-ui/react-dialog`),c=require(`@radix-ui/react-popover`),l=require(`react-dom`),u=require(`@radix-ui/react-dropdown-menu`),d=require(`@radix-ui/react-hover-card`),f=require(`sonner`),p=require(`react-transition-group`),m=require(`@radix-ui/react-separator`),h=require(`react-dom/client`);function g(...e){return(0,r.twMerge)((0,n.clsx)(e))}function _(n){let{className:r,items:a}=n,[o,s]=(0,t.useState)(null),c=e=>{s(o===e?null:e)};return(0,i.jsx)(`div`,{"data-u-comp":`accordion`,className:g(`univer-divide-x-0 univer-divide-y univer-divide-solid univer-divide-gray-200 dark:!univer-divide-gray-600`,r),children:a.map((t,n)=>(0,i.jsxs)(`div`,{children:[(0,i.jsxs)(`button`,{className:`univer-box-border univer-flex univer-w-full univer-cursor-pointer univer-items-center univer-gap-1.5 univer-border-none univer-bg-transparent univer-p-4 univer-text-left univer-text-gray-700 hover:univer-text-gray-900 focus:univer-outline-none dark:!univer-text-gray-200 dark:hover:!univer-text-white`,type:`button`,onClick:()=>c(n),children:[(0,i.jsx)(e.DownIcon,{className:g(`univer-size-2.5 univer-flex-shrink-0 univer-transition-transform`,{"-univer-rotate-90":o!==n,"univer-rotate-0":o===n})}),(0,i.jsx)(`span`,{className:`univer-font-medium`,children:t.label})]}),(0,i.jsx)(`div`,{className:g(`univer-overflow-hidden univer-transition-[max-height,opacity] univer-duration-500 univer-ease-in-out`,{"univer-max-h-screen":o===n,"univer-max-h-0":o!==n}),children:(0,i.jsx)(`div`,{className:`univer-box-border univer-px-4 univer-py-1.5`,children:t.children})})]},n))})}const v=(0,a.cva)(`
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _univerjs_icons = require("@univerjs/icons");
3
+ let react = require("react");
4
+ let clsx = require("clsx");
5
+ let tailwind_merge = require("tailwind-merge");
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+ let class_variance_authority = require("class-variance-authority");
8
+ let _radix_ui_react_slot = require("@radix-ui/react-slot");
9
+ let _radix_ui_react_dialog = require("@radix-ui/react-dialog");
10
+ let _radix_ui_react_popover = require("@radix-ui/react-popover");
11
+ let react_dom = require("react-dom");
12
+ let _radix_ui_react_dropdown_menu = require("@radix-ui/react-dropdown-menu");
13
+ let _radix_ui_react_hover_card = require("@radix-ui/react-hover-card");
14
+ let sonner = require("sonner");
15
+ let react_transition_group = require("react-transition-group");
16
+ let _radix_ui_react_separator = require("@radix-ui/react-separator");
17
+ let react_dom_client = require("react-dom/client");
18
+
19
+ //#region src/helper/clsx.ts
20
+ function clsx$1(...inputs) {
21
+ return (0, tailwind_merge.twMerge)((0, clsx.clsx)(inputs));
22
+ }
23
+
24
+ //#endregion
25
+ //#region src/components/accordion/Accordion.tsx
26
+ function Accordion(props) {
27
+ const { className, items } = props;
28
+ const [openIndex, setOpenIndex] = (0, react.useState)(null);
29
+ const toggleItem = (index) => {
30
+ setOpenIndex(openIndex === index ? null : index);
31
+ };
32
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
33
+ "data-u-comp": "accordion",
34
+ className: clsx$1("univer-divide-x-0 univer-divide-y univer-divide-solid univer-divide-gray-200 dark:!univer-divide-gray-600", className),
35
+ children: items.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
36
+ className: "univer-box-border univer-flex univer-w-full univer-cursor-pointer univer-items-center univer-gap-1.5 univer-border-none univer-bg-transparent univer-p-4 univer-text-left univer-text-gray-700 hover:univer-text-gray-900 focus:univer-outline-none dark:!univer-text-gray-200 dark:hover:!univer-text-white",
37
+ type: "button",
38
+ onClick: () => toggleItem(index),
39
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DownIcon, { className: clsx$1("univer-size-2.5 univer-flex-shrink-0 univer-transition-transform", {
40
+ "-univer-rotate-90": openIndex !== index,
41
+ "univer-rotate-0": openIndex === index
42
+ }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
43
+ className: "univer-font-medium",
44
+ children: item.label
45
+ })]
46
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
47
+ className: clsx$1("univer-overflow-hidden univer-transition-[max-height,opacity] univer-duration-500 univer-ease-in-out", {
48
+ "univer-max-h-screen": openIndex === index,
49
+ "univer-max-h-0": openIndex !== index
50
+ }),
51
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
52
+ className: "univer-box-border univer-px-4 univer-py-1.5",
53
+ children: item.children
54
+ })
55
+ })] }, index))
56
+ });
57
+ }
58
+
59
+ //#endregion
60
+ //#region src/components/avatar/Avatar.tsx
61
+ const avatarVariants = (0, class_variance_authority.cva)(`
2
62
  univer-relative univer-inline-block univer-overflow-hidden univer-whitespace-nowrap univer-bg-gray-200
3
63
  univer-text-center univer-align-middle univer-text-white
4
- `,{variants:{shape:{circle:`univer-rounded-full`,square:`univer-rounded`},size:{middle:`univer-size-9 univer-leading-9`,small:`univer-size-7 univer-leading-7`}},defaultVariants:{shape:`circle`,size:`middle`}});function y(e){let{children:t,className:n,style:r,title:a,alt:o,shape:s=`circle`,size:c=`middle`,src:l,fit:u=`fill`,onError:d,onLoad:f}=e,p=typeof c==`number`?{width:`${c}px`,height:`${c}px`,lineHeight:`${c}px`}:{},m={objectFit:u};return(0,i.jsxs)(`span`,{className:g(v({shape:s,size:typeof c==`number`?`middle`:c}),{"univer-bg-transparent":l},n),style:{...p,...r,...l&&m},children:[l&&(0,i.jsx)(`img`,{className:`univer-block univer-size-full`,src:l,title:a,alt:o,onError:d,onLoad:f}),t]})}function b(t){let{className:n,children:r,closable:a=!1,onClose:o}=t;return(0,i.jsxs)(`span`,{"data-u-comp":`badge`,className:g(`univer-box-border univer-inline-flex univer-items-center univer-gap-1 univer-truncate univer-rounded-md univer-border univer-border-solid univer-border-gray-100 univer-bg-gray-100 univer-px-2.5 univer-py-0.5 univer-text-xs univer-font-medium univer-text-gray-900 dark:!univer-border-gray-500 dark:!univer-bg-gray-700 dark:!univer-text-gray-300`,n),children:[(0,i.jsx)(`span`,{className:`univer-flex-1 univer-truncate`,children:r}),a&&(0,i.jsx)(`button`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-border-none univer-p-0 univer-outline-none univer-transition-opacity hover:univer-opacity-70`,type:`button`,"aria-label":`Close badge`,onClick:o,children:(0,i.jsx)(e.CloseIcon,{className:`univer-text-current`})})]})}const x=(0,a.cva)(`
64
+ `, {
65
+ variants: {
66
+ shape: {
67
+ circle: "univer-rounded-full",
68
+ square: "univer-rounded"
69
+ },
70
+ size: {
71
+ middle: "univer-size-9 univer-leading-9",
72
+ small: "univer-size-7 univer-leading-7"
73
+ }
74
+ },
75
+ defaultVariants: {
76
+ shape: "circle",
77
+ size: "middle"
78
+ }
79
+ });
80
+ /**
81
+ * Avatar Component
82
+ */
83
+ function Avatar(props) {
84
+ const { children, className, style, title, alt, shape = "circle", size = "middle", src, fit = "fill", onError, onLoad } = props;
85
+ const sizeStyle = typeof size === "number" ? {
86
+ width: `${size}px`,
87
+ height: `${size}px`,
88
+ lineHeight: `${size}px`
89
+ } : {};
90
+ const fitStyle = { objectFit: fit };
91
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
92
+ className: clsx$1(avatarVariants({
93
+ shape,
94
+ size: typeof size === "number" ? "middle" : size
95
+ }), { "univer-bg-transparent": src }, className),
96
+ style: {
97
+ ...sizeStyle,
98
+ ...style,
99
+ ...src && fitStyle
100
+ },
101
+ children: [src && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
102
+ className: "univer-block univer-size-full",
103
+ src,
104
+ title,
105
+ alt,
106
+ onError,
107
+ onLoad
108
+ }), children]
109
+ });
110
+ }
111
+
112
+ //#endregion
113
+ //#region src/components/badge/Badge.tsx
114
+ function Badge(props) {
115
+ const { className, children, closable = false, onClose } = props;
116
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
117
+ "data-u-comp": "badge",
118
+ className: clsx$1("univer-box-border univer-inline-flex univer-items-center univer-gap-1 univer-truncate univer-rounded-md univer-border univer-border-solid univer-border-gray-100 univer-bg-gray-100 univer-px-2.5 univer-py-0.5 univer-text-xs univer-font-medium univer-text-gray-900 dark:!univer-border-gray-500 dark:!univer-bg-gray-700 dark:!univer-text-gray-300", className),
119
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
120
+ className: "univer-flex-1 univer-truncate",
121
+ children
122
+ }), closable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
123
+ className: "univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-border-none univer-p-0 univer-outline-none univer-transition-opacity hover:univer-opacity-70",
124
+ type: "button",
125
+ "aria-label": "Close badge",
126
+ onClick: onClose,
127
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CloseIcon, { className: "univer-text-current" })
128
+ })]
129
+ });
130
+ }
131
+
132
+ //#endregion
133
+ //#region src/components/button/Button.tsx
134
+ const buttonVariants = (0, class_variance_authority.cva)(`
5
135
  univer-box-border univer-inline-flex univer-cursor-pointer univer-select-none univer-items-center
6
136
  univer-justify-center univer-gap-2 univer-whitespace-nowrap univer-rounded-md univer-border univer-border-solid
7
137
  univer-text-sm univer-font-medium univer-transition-colors
8
138
  disabled:univer-pointer-events-none disabled:univer-cursor-not-allowed disabled:univer-opacity-50
9
139
  [&_svg]:univer-pointer-events-none [&_svg]:univer-size-4 [&_svg]:univer-shrink-0
10
- `,{variants:{variant:{default:`
140
+ `, {
141
+ variants: {
142
+ variant: {
143
+ default: `
11
144
  univer-border-gray-200 univer-bg-white univer-text-gray-700
12
145
  hover:univer-bg-gray-100
13
146
  active:univer-bg-gray-200
14
147
  dark:!univer-border-gray-600 dark:!univer-bg-gray-700 dark:!univer-text-white
15
148
  dark:hover:!univer-bg-gray-600
16
149
  dark:active:!univer-bg-gray-700
17
- `,primary:`
150
+ `,
151
+ primary: `
18
152
  univer-border-primary-600 univer-bg-primary-600 univer-text-white
19
153
  hover:univer-bg-primary-500
20
154
  active:univer-bg-primary-700
21
- `,danger:`
155
+ `,
156
+ danger: `
22
157
  univer-border-red-500 univer-bg-red-500 univer-text-white
23
158
  hover:univer-border-red-400 hover:univer-bg-red-400
24
159
  active:univer-border-red-600 active:univer-bg-red-600
25
- `,text:`
160
+ `,
161
+ text: `
26
162
  univer-border-transparent univer-bg-transparent univer-text-gray-900
27
163
  hover:univer-bg-gray-100
28
164
  active:univer-bg-gray-200
29
165
  dark:!univer-text-white
30
166
  dark:hover:!univer-bg-gray-700
31
167
  dark:active:!univer-bg-gray-600
32
- `,link:`
168
+ `,
169
+ link: `
33
170
  univer-underline-current univer-border-transparent univer-bg-transparent univer-text-primary-600
34
171
  univer-underline-offset-4
35
172
  hover:univer-text-primary-500 hover:univer-underline
36
173
  active:univer-text-primary-700
37
- `,ghost:`
174
+ `,
175
+ ghost: `
38
176
  univer-border-transparent univer-bg-transparent univer-text-gray-900
39
177
  hover:univer-bg-gray-100
40
178
  active:univer-bg-gray-200
41
179
  dark:!univer-text-white
42
180
  dark:hover:!univer-bg-gray-700
43
181
  dark:active:!univer-bg-gray-600
44
- `},size:{small:`univer-h-6 univer-rounded-md univer-px-1.5 univer-text-xs`,middle:`univer-h-8 univer-rounded-lg univer-px-2 univer-text-sm`,large:`univer-h-10 univer-rounded-lg univer-px-3 univer-text-sm`}},defaultVariants:{variant:`default`,size:`middle`}}),S=(0,t.forwardRef)(({className:e,variant:t,size:n,asChild:r=!1,...a},s)=>(0,i.jsx)(r?o.Slot:`button`,{className:g(x({variant:t,size:n,className:e})),ref:s,"data-u-comp":`button`,...a}));S.displayName=`Button`;const C=({className:e,orientation:n=`horizontal`,children:r})=>{let a=t.Children.count(r),o=n===`horizontal`,s=n===`vertical`;return(0,i.jsx)(`div`,{className:g(`univer-grid`,{"univer-grid-flow-row":s,"univer-w-fit":s},e),children:t.Children.map(r,(e,n)=>{let r=n===0,i=n===a-1;return(0,t.cloneElement)(e,{className:g({"!univer-rounded-l-none":o&&!r,"!univer-rounded-r-none":o&&!i,"!univer-border-l-0":o&&!r,"!univer-rounded-t-none":s&&!r,"!univer-rounded-b-none":s&&!i,"!univer-border-t-0":s&&!r},e.props.className)})})})};function w(){return typeof window<`u`&&typeof document<`u`}const T=(0,t.createContext)({mountContainer:w()?document.body:null});function E(e){let{children:n,locale:r,mountContainer:a}=e,o=(0,t.useMemo)(()=>({locale:r,mountContainer:a}),[r,a]);return(0,i.jsx)(T.Provider,{value:o,children:n})}const D=`univer-scrollbar-thin univer-scrollbar-track-gray-50 univer-scrollbar-thumb-gray-300 dark:!univer-scrollbar-track-gray-900 dark:!univer-scrollbar-thumb-gray-700`,O=`univer-border-gray-200 dark:!univer-border-gray-600 univer-border-solid`,k=g(O,`univer-border`),A=g(O,`univer-border-l univer-border-b univer-border-t-0 univer-border-r-0`),j=g(O,`univer-border-l univer-border-b-0 univer-border-t-0 univer-border-r-0`),M=g(O,`univer-border-b-0 univer-border-t-0 rtl:univer-border-l-0 rtl:univer-border-r`),N=g(O,`univer-border-l-0 univer-border-b-0 univer-border-t univer-border-r-0`),P=g(O,`univer-border-l-0 univer-border-b univer-border-t-0 univer-border-r-0`),F=g(O,`univer-border-l-0 univer-border-b-0 univer-border-t-0 univer-border-r`);function I(e,t=2){return String(e).padStart(t,`0`)}function L(e,t){let n=e==null?new Date:e;if(Number.isNaN(n.getTime()))return`Invalid Date`;let r={YYYY:String(n.getFullYear()),MM:I(n.getMonth()+1),DD:I(n.getDate()),HH:I(n.getHours()),mm:I(n.getMinutes()),ss:I(n.getSeconds())};return t.replace(/YYYY|MM|DD|HH|mm|ss/g,e=>{var t;return(t=r[e])==null?e:t})}function R(t){let{className:n,value:r,onValueChange:a}=t;function o(e){let[t,n,i]=e.target.value.split(`:`).map(Number),o=new Date(r==null?Date.now():r);o.setHours(t,n,i,0),a==null||a(o)}return(0,i.jsxs)(`div`,{"data-u-comp":`time-input`,className:`univer-relative univer-mx-auto univer-mt-1 univer-w-fit`,children:[(0,i.jsx)(e.ClockIcon,{className:`univer-absolute univer-left-2 univer-top-1/2 -univer-translate-y-1/2 univer-text-gray-600 dark:!univer-text-gray-400`}),(0,i.jsx)(`input`,{className:g(`univer-block univer-h-7 univer-w-fit univer-appearance-none univer-rounded-md univer-bg-transparent univer-pl-6 univer-pr-2 univer-text-center univer-text-gray-800 univer-shadow univer-outline-none univer-transition-all univer-duration-200 focus:univer-border-primary-600 dark:!univer-text-white dark:focus:!univer-border-primary-500 [&::-webkit-calendar-picker-indicator]:univer-hidden [&::-webkit-calendar-picker-indicator]:univer-appearance-none`,k,n),type:`time`,step:`1`,value:L(r,`HH:mm:ss`),onChange:o})]})}function z(e,t){return new Date(e,t+1,0).getDate()}function ee(e,t){return new Date(e,t,1).getDay()}function B(e){let{className:t,...n}=e;return(0,i.jsx)(`button`,{className:g(`univer-size-7 univer-rounded-md univer-border-none univer-bg-transparent univer-p-1 univer-transition-all hover:univer-bg-gray-200 dark:hover:!univer-bg-gray-600`,t),type:`button`,...n})}function V(n){let{className:r,max:a,min:o,showTime:s=!1,value:c,onValueChange:l}=n,{locale:u}=(0,t.useContext)(T),{year:d,weekDays:f,months:p}=u==null?void 0:u.Calendar,m=new Date,[h,_]=(0,t.useState)((c==null?m:c).getFullYear()),[v,y]=(0,t.useState)((c==null?m:c).getMonth());function b(){y(e=>e===0?(_(e=>e-1),11):e-1)}function x(){y(e=>e===11?(_(e=>e+1),0):e+1)}let S=z(h,v),C=ee(h,v),w=(0,t.useMemo)(()=>{let e=[];for(let t=0;t<C;t++)e.push(null);for(let t=1;t<=S;t++)e.push(t);return e},[S,C]);function E(e){return e&&h===(c==null?void 0:c.getFullYear())&&v===(c==null?void 0:c.getMonth())&&e===(c==null?void 0:c.getDate())}function D(e){return e&&h===m.getFullYear()&&v===m.getMonth()&&e===m.getDate()}function O(e){var t,n,r;if(!e)return!1;let i=(t=c==null?void 0:c.getHours())==null?m.getHours():t,s=(n=c==null?void 0:c.getMinutes())==null?m.getMinutes():n,l=(r=c==null?void 0:c.getSeconds())==null?m.getSeconds():r,u=new Date(h,v,e,i,s,l);return!!(o&&u<o||a&&u>a)}function k(e){var t,n,r;if(O(e))return;let i=(t=c==null?void 0:c.getHours())==null?m.getHours():t,a=(n=c==null?void 0:c.getMinutes())==null?m.getMinutes():n,o=(r=c==null?void 0:c.getSeconds())==null?m.getSeconds():r;l==null||l(new Date(h,v,e,i,a,o))}function A(e){var t;let n=e.getHours(),r=e.getMinutes(),i=e.getSeconds(),a=new Date(h,v,(t=c==null?void 0:c.getDate())==null?m.getDate():t,n,r,i);l==null||l(a)}return(0,i.jsxs)(`div`,{"data-u-comp":`calendar`,className:g(`univer-mx-auto univer-max-w-xs univer-select-none univer-rounded univer-bg-white univer-text-gray-900 dark:!univer-bg-gray-900 dark:!univer-text-white`,r),children:[(0,i.jsxs)(`nav`,{className:`univer-mb-4 univer-flex univer-items-center univer-justify-between`,children:[(0,i.jsx)(B,{className:`univer-text-lg univer-text-gray-500 dark:!univer-text-gray-200`,"aria-label":`Previous Month`,onClick:b,children:(0,i.jsx)(e.MoreRightIcon,{className:`univer-rotate-180`})}),(0,i.jsxs)(`span`,{className:`univer-flex univer-gap-0.5 univer-text-sm univer-font-medium`,children:[(0,i.jsx)(`span`,{children:h}),(0,i.jsx)(`span`,{children:d}),(0,i.jsx)(`span`,{children:p[v]})]}),(0,i.jsx)(B,{className:`univer-text-lg univer-text-gray-500 dark:!univer-text-gray-200`,"aria-label":`Next Month`,onClick:x,children:(0,i.jsx)(e.MoreRightIcon,{})})]}),(0,i.jsx)(`div`,{className:`univer-mb-1 univer-grid univer-grid-cols-7 univer-gap-1 univer-text-center univer-text-sm univer-text-gray-500 dark:!univer-text-gray-200`,children:f.map(e=>(0,i.jsx)(`div`,{children:e},e))}),(0,i.jsx)(`div`,{className:`univer-grid univer-grid-cols-7 univer-gap-1 univer-text-center`,children:w.map((e,t)=>e?(0,i.jsx)(B,{className:g({"!univer-bg-primary-600 univer-font-bold univer-text-white":!D(e)&&E(e),"dark:!univer-text-white":!D(e)&&!E(e),"!univer-bg-primary-600 univer-text-white":D(e)&&E(e),"univer-font-semibold univer-text-primary-600 dark:!univer-text-primary-500":D(e)&&!E(e),"univer-cursor-not-allowed univer-opacity-40":O(e),"univer-hover:bg-primary-100 univer-cursor-pointer univer-text-gray-800":!E(e)&&!O(e)}),onClick:()=>k(e),disabled:O(e),children:e},t):(0,i.jsx)(`div`,{},t))}),s&&(0,i.jsx)(R,{value:c,onValueChange:A})]})}function H({emptyText:e}){return(0,i.jsx)(`section`,{className:`univer-h-8 univer-px-2 univer-pr-32 univer-text-sm/8 univer-text-gray-600 dark:!univer-text-gray-200`,children:e})}function te(n){let{value:r,options:a=[],onChange:o,contentClassName:s,wrapperClassName:c}=n,{locale:l}=(0,t.useContext)(T),u=(0,t.useMemo)(()=>{let e=[a];return r.forEach((t,n)=>{let r=e[n].find(e=>e.value===t);r!=null&&r.children&&e.push(r.children)}),e},[r]);function d(e,t){if(t===r[e])return;if(r[e+1]){let n=r.slice(0,e+1);n[e]=t,o(n);return}let n=[...r];n[e]=t,o(n)}return(0,i.jsxs)(`section`,{"data-u-comp":`cascader-list`,className:g(`univer-overflow-auto-y univer-grid univer-h-full univer-max-h-80 univer-grid-flow-col univer-rounded univer-py-2 univer-text-gray-900 dark:!univer-text-white [&>ul:not(:last-child)]:univer-border-0 [&>ul:not(:last-child)]:univer-border-r [&>ul:not(:last-child)]:univer-border-solid [&>ul:not(:last-child)]:univer-border-r-gray-200`,k,D,c),children:[u.map((t,n)=>t.length?(0,i.jsx)(`ul`,{className:g(`univer-m-0 univer-h-full univer-max-h-full univer-list-none univer-overflow-auto univer-px-2`,D,s),children:t.map(t=>(0,i.jsx)(`li`,{children:(0,i.jsxs)(`a`,{className:g(`univer-relative univer-block univer-h-8 univer-cursor-pointer univer-rounded univer-text-sm/8`,{"univer-px-7":n>0,"univer-px-1.5":n===0,"univer-bg-gray-200 dark:!univer-bg-gray-600":t.value===r[n]}),onClick:()=>d(n,t.value),children:[n>0&&(0,i.jsx)(`span`,{className:`univer-absolute univer-left-2 univer-flex univer-h-full univer-items-center`,children:t.value===r[n]&&(0,i.jsx)(e.CheckMarkIcon,{className:`univer-text-primary-600`})}),(0,i.jsx)(`span`,{children:t.label})]})},t.value))},n):(0,i.jsx)(H,{emptyText:l==null?void 0:l.CascaderList.empty},n)),r.length<=0&&(0,i.jsx)(H,{emptyText:l==null?void 0:l.CascaderList.empty})]})}function ne(e){let{children:n,className:r,style:a,value:o,disabled:s,direction:c=`horizontal`,onChange:l}=e,u=e=>{o.includes(e)?l(o.filter(t=>t!==e)):l([...o,e])};return(0,i.jsx)(`div`,{className:g(`univer-flex univer-gap-2`,{"univer-flex-col":c===`vertical`},r),style:a,children:t.Children.map(n,(e,n)=>(0,t.isValidElement)(e)?(0,t.cloneElement)(e,{key:n,children:e.props.children,checked:e.props.value?o.includes(e.props.value):!1,disabled:s==null?e.props.disabled:s,onChange:u}):e)})}function re(n){let{children:r,className:a,style:o,checked:s=!1,indeterminate:c=!1,value:l,disabled:u=!1,onChange:d,contentClassName:f}=n,p=(0,t.useRef)(null);function m(e){if(e.stopPropagation(),!(!d||u))if(l!==void 0)d==null||d(l);else{var t,n;let e=(t=p==null||(n=p.current)==null?void 0:n.checked)==null?!1:t;d==null||d(e)}}return(0,i.jsxs)(`label`,{"data-u-comp":`checkbox`,className:g(`univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-text-sm`,{"univer-cursor-pointer univer-text-gray-900 dark:!univer-text-white":!u,"univer-text-gray-400":u},a),style:o,children:[(0,i.jsxs)(`span`,{className:`univer-relative univer-block`,children:[(0,i.jsx)(`input`,{ref:p,className:`univer-absolute univer-size-0 univer-opacity-0`,type:`checkbox`,checked:s,disabled:u,onChange:m}),(0,i.jsxs)(`span`,{className:g(`univer-relative univer-box-border univer-flex univer-size-4 univer-items-center univer-justify-center univer-overflow-hidden univer-rounded univer-border univer-border-solid univer-transition-colors`,{"univer-opacity-50":u,"univer-border-primary-600 univer-bg-primary-600":s||c,"univer-border-gray-300 univer-bg-gray-50 dark:!univer-border-gray-500 dark:!univer-bg-gray-600":!s&&!c}),children:[s&&(0,i.jsx)(e.CheckMarkIcon,{className:`univer-absolute univer-left-1/2 univer-top-1/2 univer-block univer-size-3 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-text-white`}),c&&!s&&(0,i.jsx)(`span`,{className:`univer-absolute univer-left-1/2 univer-top-1/2 univer-block univer-h-0.5 univer-w-2.5 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-rounded univer-bg-white`})]})]}),(0,i.jsx)(`span`,{className:g(`univer-select-none`,f),children:r})]})}const ie=s.Root,ae=s.Portal,oe=(0,t.forwardRef)(({className:e,...t},n)=>(0,i.jsx)(s.Overlay,{ref:n,className:g(`data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 univer-fixed univer-inset-0 univer-z-[1080] univer-bg-[rgba(0,0,0,0.8)]`,e),...t}));oe.displayName=s.Overlay.displayName;const se=(0,t.forwardRef)(({className:t,children:n,closable:r=!0,onClickClose:a,...o},c)=>(0,i.jsxs)(ae,{children:[(0,i.jsx)(oe,{}),(0,i.jsxs)(s.Content,{ref:c,className:g(`data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=open]:univer-slide-in-from-left-1/2 data-[state=open]:univer-slide-in-from-top-[48%] data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[state=closed]:univer-slide-out-to-left-1/2 data-[state=closed]:univer-slide-out-to-top-[48%] univer-fixed univer-left-1/2 univer-top-1/2 univer-z-[1080] univer-box-border univer-grid univer-w-full univer-max-w-lg -univer-translate-x-1/2 -univer-translate-y-1/2 univer-gap-4 univer-bg-white univer-p-4 univer-text-gray-500 univer-shadow-md univer-duration-200 sm:!univer-rounded-lg dark:!univer-bg-gray-700 dark:!univer-text-gray-400`,k,t),...o,children:[n,r&&(0,i.jsxs)(s.Close,{className:`univer-absolute univer-right-4 univer-top-4 univer-size-6 univer-cursor-pointer univer-rounded-sm univer-border-none univer-bg-transparent univer-p-0 univer-transition-opacity hover:univer-opacity-100 disabled:univer-pointer-events-none`,onClick:a,children:[(0,i.jsx)(e.CloseIcon,{className:`univer-size-4 univer-text-gray-400`}),(0,i.jsx)(`span`,{className:`univer-sr-only`,children:`Close`})]})]})]}));se.displayName=s.Content.displayName;const ce=({className:e,...t})=>(0,i.jsx)(`div`,{className:g(`univer-flex univer-flex-col univer-space-y-1.5 univer-text-center sm:!univer-text-left`,e),...t});ce.displayName=`DialogHeader`;const le=({className:e,...t})=>(0,i.jsx)(`div`,{className:g(`univer-flex univer-flex-col-reverse sm:!univer-flex-row sm:!univer-justify-end sm:!univer-space-x-2`,e),...t});le.displayName=`DialogFooter`;const ue=(0,t.forwardRef)(({className:e,...t},n)=>(0,i.jsx)(s.Title,{ref:n,className:g(`univer-my-0 univer-text-lg univer-font-semibold univer-leading-none univer-tracking-tight univer-text-gray-900 dark:!univer-text-white`,e),...t}));ue.displayName=s.Title.displayName;const de=(0,t.forwardRef)(({className:e,...t},n)=>(0,i.jsx)(s.Description,{ref:n,className:g(`univer-text-sm univer-text-gray-500`,e),...t}));de.displayName=s.Description.displayName;function fe(e={}){let n=(0,t.useCallback)(()=>{let{innerWidth:e,innerHeight:t}=window;return{x:Math.max(0,(e-0)/2),y:Math.max(0,(t-0)/2)}},[]),{defaultPosition:r=n(),enabled:i=!1}=e,[a,o]=(0,t.useState)(r),[s,c]=(0,t.useState)(!1),l=(0,t.useRef)(null),u=(0,t.useRef)({x:0,y:0}),d=(0,t.useRef)({x:0,y:0}),f=(0,t.useRef)(!1);(0,t.useEffect)(()=>{if(!l.current||f.current||e.defaultPosition)return;let{width:t,height:n}=l.current.getBoundingClientRect(),{innerWidth:r,innerHeight:i}=window,a=Math.max(0,(r-t)/2),s=Math.max(0,(i-n)/2);o({x:a,y:s}),u.current={x:a,y:s},f.current=!0},[e.defaultPosition]);let p=(0,t.useCallback)((e,t)=>{if(!l.current)return{x:e,y:t};let n=l.current.getBoundingClientRect(),{clientWidth:r,clientHeight:i}=document.documentElement,a=u.current.x+(e-d.current.x),o=u.current.y+(t-d.current.y);return a<0&&(a=0),o<0&&(o=0),a+n.width>r&&(a=r-n.width),o+n.height>i&&(o=i-n.height),{x:a,y:o}},[]),m=(0,t.useCallback)(e=>{i&&(e.preventDefault(),e.stopPropagation(),u.current={...a},d.current={x:e.clientX,y:e.clientY},c(!0),document.body.style.userSelect=`none`)},[i,a]),h=(0,t.useCallback)(e=>{s&&(e.preventDefault(),e.stopPropagation(),o(p(e.clientX,e.clientY)))},[s,p]),g=(0,t.useCallback)(()=>{c(!1),document.body.style.userSelect=``},[]);return(0,t.useEffect)(()=>{if(i)return document.addEventListener(`mousemove`,h),document.addEventListener(`mouseup`,g),()=>{document.removeEventListener(`mousemove`,h),document.removeEventListener(`mouseup`,g)}},[i,h,g]),{position:a,isDragging:s,elementRef:l,setElementRef:t=>{if(l.current=t,t&&!f.current&&!e.defaultPosition){let{width:e,height:n}=t.getBoundingClientRect(),{innerWidth:r,innerHeight:i}=window,a=Math.max(0,(r-e)/2),s=Math.max(0,(i-n)/2);o({x:a,y:s}),u.current={x:a,y:s},f.current=!0}},handleMouseDown:m}}function U(e){var n,r,a,o;let{className:s,children:c,style:l,open:u=!1,title:d,width:f,draggable:p=!1,defaultPosition:m,footer:h,mask:_=!0,keyboard:v=!0,closable:y=!0,maskClosable:b=!0,showOk:x,showCancel:C,onOpenChange:w,onClose:E,onOk:D,onCancel:O}=e,{locale:k}=(0,t.useContext)(T),{position:A,isDragging:j,setElementRef:M,handleMouseDown:N}=fe({defaultPosition:m,enabled:p}),P=h==null?x||C?(0,i.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-2`,children:[C&&(0,i.jsx)(S,{onClick:O,children:(n=k==null||(r=k.Confirm)==null?void 0:r.cancel)==null?`Cancel`:n}),x&&(0,i.jsx)(S,{variant:`primary`,onClick:D,children:(a=k==null||(o=k.Confirm)==null?void 0:o.confirm)==null?`OK`:a})]}):null:h,F=(0,t.useCallback)(e=>{e&&p&&M(e)},[p,M]),I=(0,t.useCallback)(e=>{!_&&!e||(w==null||w(e),e||E==null||E())},[E,w]);function L(){w==null||w(!1),E==null||E()}return(0,i.jsx)(ie,{open:u,onOpenChange:I,modal:_!==!1,children:(0,i.jsxs)(se,{ref:F,className:g(s,{"!univer-animate-none":p}),style:{...l,width:f?typeof f==`number`?`${f}px`:f:void 0,maxWidth:f?`initial`:void 0,...p?{position:`absolute`,margin:0,left:0,top:0,transform:`translate(${A.x}px, ${A.y}px)`,transition:j?`none`:void 0,cursor:j?`grabbing`:void 0}:{}},closable:y,onClickClose:L,onEscapeKeyDown:e=>{v&&L(),e.preventDefault()},onPointerDownOutside:e=>{b&&L(),e.preventDefault()},children:[(0,i.jsxs)(ce,{className:g({"!univer-hidden":!d}),"data-drag-handle":p?`true`:void 0,style:{cursor:p?`grab`:void 0,userSelect:p?`none`:void 0,touchAction:p?`none`:void 0},onMouseDown:p?N:void 0,children:[(0,i.jsx)(ue,{children:d}),(0,i.jsx)(de,{className:`univer-hidden`})]}),c,P&&(0,i.jsx)(le,{children:P})]})})}const W=(e,t,n)=>{t/=100,n/=100;let r=n*t,i=r*(1-Math.abs(e/60%2-1)),a=n-r,o=0,s=0,c=0;return e>=0&&e<60?(o=r,s=i,c=0):e>=60&&e<120?(o=i,s=r,c=0):e>=120&&e<180?(o=0,s=r,c=i):e>=180&&e<240?(o=0,s=i,c=r):e>=240&&e<300?(o=i,s=0,c=r):e>=300&&e<360&&(o=r,s=0,c=i),[Math.round((o+a)*255),Math.round((s+a)*255),Math.round((c+a)*255)]},pe=(e,t,n)=>{let r=e=>e.toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`},G=(e,t,n)=>{e/=255,t/=255,n/=255;let r=Math.max(e,t,n),i=r-Math.min(e,t,n),a=0,o=0,s=r;return r!==0&&(o=i/r),i!==0&&(r===e?a=(t-n)/i+(t<n?6:0):r===t?a=(n-e)/i+2:r===n&&(a=(e-t)/i+4),a*=60),[a,o*100,s*100]},K=e=>{e.length===4&&(e=`#${e.slice(1).split(``).map(e=>e+e).join(``)}`);let[t,n,r]=e.match(/\w\w/g).map(e=>Number.parseInt(e,16));return G(t,n,r)},q=(e,t,n)=>{let[r,i,a]=W(e,t,n);return pe(r,i,a)},me=(e,t,n,r)=>{let[i,a,o]=W(e,t,n);return`rgba(${i}, ${a}, ${o}, ${r})`},he=e=>{let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d+))?\)/);if(!t)throw Error(`Invalid RGBA string`);return[Number.parseInt(t[1],10),Number.parseInt(t[2],10),Number.parseInt(t[3],10),t[4]?Number.parseFloat(t[4]):1]};function ge({hsv:e,alpha:n,onChange:r,onChanged:a}){let[o,s]=(0,t.useState)(!1),c=(0,t.useRef)(null),l=(0,t.useRef)(null),u=(0,t.useCallback)(e=>{var t,n;let i=c.current;if(!i)return;let a=(t=(n=l.current)==null?void 0:n.clientWidth)==null?0:t,o=i.getBoundingClientRect(),s=o.width-a;if(s<=0){r(0);return}let u=Math.max(0,Math.min(e-o.left,s));r(Math.round(u/s*100)/100)},[r]),d=(0,t.useCallback)(e=>{o&&u(e.clientX)},[o,u]),f=(0,t.useCallback)(()=>{s(!1),a==null||a(n)},[n]);(0,t.useEffect)(()=>(o&&(window.addEventListener(`pointermove`,d),window.addEventListener(`pointerup`,f),window.addEventListener(`mouseup`,f)),()=>{window.removeEventListener(`pointermove`,d),window.removeEventListener(`pointerup`,f),window.removeEventListener(`mouseup`,f)}),[o,d,f]);let p=()=>{var e,t,r,i;let a=Math.min(Math.max(n*100,0),100),o=(e=(t=l.current)==null?void 0:t.clientWidth)==null?0:e,s=(r=(i=c.current)==null?void 0:i.clientWidth)==null?0:r,u=s>0?o/s*100:0;return`${a/100*(100-u)}%`},m=W(...e);return(0,i.jsxs)(`div`,{className:`univer-relative univer-w-full univer-select-none`,children:[(0,i.jsx)(`div`,{className:`univer-absolute univer-inset-0 univer-rounded-full`,style:{backgroundImage:`linear-gradient(45deg, #E3E5EA 25%, transparent 25%), linear-gradient(-45deg, #E3E5EA 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #E3E5EA 75%), linear-gradient(-45deg, transparent 75%, #E3E5EA 75%)`,backgroundPosition:`0 0, 0 4px, 4px -4px, -4px 0`,backgroundSize:`8px 8px`}}),(0,i.jsx)(`div`,{ref:c,className:`univer-relative univer-h-2 univer-w-full univer-cursor-pointer univer-rounded-full univer-shadow-inner`,style:{background:`linear-gradient(to right, transparent, rgb(${m.join(`,`)}))`},onPointerDown:e=>{s(!0),u(e.clientX)},children:(0,i.jsx)(`div`,{ref:l,className:`univer-absolute univer-top-1/2 univer-box-border univer-size-2 univer-rounded-full univer-bg-transparent univer-shadow-md univer-ring-2 univer-ring-white univer-transition-transform univer-duration-75 univer-will-change-transform`,style:{left:p(),transform:`translateY(-50%)`,transition:o?`none`:`all 0.1s ease-out`}})})]})}function _e({hsv:e,onChange:n}){let[r,a]=(0,t.useState)(``),o=(0,t.useMemo)(()=>q(e[0],e[1],e[2]),[e]);(0,t.useEffect)(()=>{a(o.replace(/^#/,``))},[o]);let s=e=>/^[0-9A-Fa-f]{6}$/.test(e);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`input`,{className:g(`univer-w-full univer-px-2 !univer-pl-4 univer-uppercase focus:univer-border-primary-500 focus:univer-outline-none dark:!univer-text-white`,k),value:r,onChange:e=>{let t=e.target.value.trim();if(!(t.length>6)&&!(t!==``&&!/^[0-9A-Fa-f]*$/.test(t))&&(a(t),s(t))){let e=K(t);e&&n&&n(...e)}},onBlur:()=>{s(r)||a(o.replace(/^#/,``))},maxLength:6,spellCheck:!1}),(0,i.jsx)(`span`,{className:`univer-absolute univer-left-1.5 univer-top-1/2 -univer-translate-y-1/2 univer-text-sm univer-text-gray-400`,children:`#`})]})}function ve({hsv:e,alpha:n,format:r,onChange:a}){let[o,s]=(0,t.useState)({r:0,g:0,b:0,a:1});(0,t.useEffect)(()=>{let[t,r,i]=W(e[0],e[1],e[2]);s({r:Math.round(t),g:Math.round(r),b:Math.round(i),a:n==null?1:n})},[e,n]);let c=(t,n)=>{if(t===`a`){if(n!==``&&!/^\d*\.?\d*$/.test(n))return;let t=n===``?0:Number.parseFloat(n);if(t>1)return;s({...o,a:t}),a&&a(e[0],e[1],e[2],t);return}if(n!==``&&!/^\d*$/.test(n))return;let r=n===``?0:Number.parseInt(n,10);if(r>255)return;let i={...o,[t]:r};s(i),a&&a(...G(i.r,i.g,i.b),o.a)},l=()=>{let[t,r,i]=W(e[0],e[1],e[2]);s({r:Math.round(t),g:Math.round(r),b:Math.round(i),a:n==null?1:n})};return(0,i.jsxs)(`div`,{className:`univer-flex univer-items-center univer-gap-2 [&>input]:univer-w-11 [&>input]:univer-border-gray-200 [&>input]:focus:univer-border-primary-500 dark:[&>input]:!univer-border-gray-600 dark:[&>input]:!univer-text-white`,children:[(0,i.jsx)(`input`,{value:o.r,onChange:e=>c(`r`,e.target.value),onBlur:l,maxLength:3}),(0,i.jsx)(`input`,{value:o.g,onChange:e=>c(`g`,e.target.value),onBlur:l,maxLength:3}),(0,i.jsx)(`input`,{value:o.b,onChange:e=>c(`b`,e.target.value),onBlur:l,maxLength:3}),r===`rgba`&&(0,i.jsx)(`input`,{value:o.a,onChange:e=>c(`a`,e.target.value),onBlur:l,maxLength:4})]})}function ye({hsv:e,alpha:t,format:n,onChange:r}){return(0,i.jsx)(`div`,{className:`dark:![&_input]:univer-border-gray-600 dark:![&_input]:univer-text-white univer-flex univer-gap-2 [&_input]:univer-box-border [&_input]:univer-flex [&_input]:univer-h-7 [&_input]:univer-items-center [&_input]:univer-rounded [&_input]:univer-border [&_input]:univer-border-solid [&_input]:univer-border-gray-200 [&_input]:univer-bg-transparent [&_input]:univer-px-1.5 [&_input]:univer-text-sm [&_input]:univer-text-gray-700 [&_input]:univer-outline-none`,children:(0,i.jsxs)(`div`,{className:`univer-relative univer-flex univer-flex-1 univer-gap-2`,children:[(0,i.jsx)(_e,{hsv:e,onChange:r}),(0,i.jsx)(ve,{hsv:e,alpha:t,format:n,onChange:r})]})})}const be=[[`#FFFFFF`,`#E1EFFE`,`#FDE8E8`,`#FEECDC`,`#FFF4B9`,`#DEF7EC`,`#D5F5F6`,`#EDEBFE`,`#FCE8F3`],[`#CDD0D8`,`#A4CAFE`,`#F8B4B4`,`#FDBA8C`,`#FAC815`,`#84E1BC`,`#7EDCE2`,`#CABFFD`,`#F8B4D9`],[`#979DAC`,`#3F83F8`,`#F05252`,`#FF5A1F`,`#D49D0F`,`#0DA471`,`#0694A2`,`#9061F9`,`#E74694`],[`#414657`,`#1A56DB`,`#C81E1E`,`#B43403`,`#9A6D15`,`#046C4E`,`#036672`,`#6C2BD9`,`#BF125D`],[`#000000`,`#233876`,`#771D1D`,`#8A2C0D`,`#634312`,`#014737`,`#014451`,`#4A1D96`,`#751A3D`]];function xe({hsv:e,onChange:n}){let r=(0,t.useCallback)(e=>{let[t,r,i]=K(e);n(t,r,i)},[n]),a=q(e[0],e[1],e[2]);return(0,i.jsx)(`div`,{"data-u-comp":`color-picker-presets`,className:`univer-grid univer-content-center univer-gap-2`,children:be.map((e,t)=>(0,i.jsx)(`div`,{className:`univer-grid univer-grid-flow-col univer-items-center univer-justify-between univer-gap-2`,children:e.map((e,n)=>(0,i.jsx)(`button`,{type:`button`,className:g(`univer-box-border univer-size-5 univer-cursor-pointer univer-rounded-full univer-border univer-border-solid univer-border-transparent univer-bg-gray-300 univer-transition-shadow`,{"univer-ring-2 univer-ring-offset-2 univer-ring-offset-white dark:!univer-ring-primary-600 dark:!univer-ring-offset-gray-600":e.toUpperCase()===a.toUpperCase(),"!univer-border-gray-200":t===0&&n===0}),style:{backgroundColor:e},onClick:()=>r(e)},n))},t))})}function Se({hsv:e,onChange:n,onChanged:r}){let a=(0,t.useRef)(null),o=(0,t.useRef)(null),[s,c]=(0,t.useState)(!1);(0,t.useEffect)(()=>{let t=a.current;if(!t)return;let n=t.getContext(`2d`);if(!n)return;let r=n.createLinearGradient(0,0,t.width,0);r.addColorStop(0,`hsl(${e[0]}, 0%, 50%)`),r.addColorStop(1,`hsl(${e[0]}, 100%, 50%)`),n.fillStyle=r,n.fillRect(0,0,t.width,t.height);let i=n.createLinearGradient(0,0,0,t.height);i.addColorStop(0,`rgba(255, 255, 255, 0)`),i.addColorStop(1,`rgba(0, 0, 0, 1)`),n.fillStyle=i,n.fillRect(0,0,t.width,t.height)},[e]);let l=t=>{t.stopPropagation();let r=a.current;if(!r)return;let i=r.getBoundingClientRect(),o=Math.max(0,Math.min(t.clientX-i.left,i.width)),s=Math.max(0,Math.min(t.clientY-i.top,i.height)),c=o/i.width*100,l=100-s/i.height*100;n(e[0],c,l)},u=(0,t.useCallback)(()=>{c(!1)},[e]);function d(){r==null||r(e[0],e[1],e[2])}(0,t.useEffect)(()=>{var e;return(e=o.current)==null||e.addEventListener(`mouseup`,d),window.addEventListener(`pointerup`,u),window.addEventListener(`mouseup`,u),()=>{var e;(e=o.current)==null||e.removeEventListener(`mouseup`,d),window.removeEventListener(`pointerup`,u),window.removeEventListener(`mouseup`,u)}},[e]);let f=()=>{var t,n,r,i;let a=(t=(n=o.current)==null?void 0:n.clientWidth)==null?0:t,c=(r=(i=o.current)==null?void 0:i.clientHeight)==null?0:r;return{transform:`translate(${e[1]/100*a-8}px, ${(100-e[2])/100*c-8}px)`,transition:s?`none`:`transform 0.1s ease-out`}};return(0,t.useEffect)(()=>{let e=()=>{c(!1)};return window.addEventListener(`pointerup`,e),window.addEventListener(`mouseup`,e),()=>{window.removeEventListener(`pointerup`,e),window.removeEventListener(`mouseup`,e)}},[]),(0,i.jsxs)(`div`,{"data-u-comp":`color-picker-spectrum`,ref:o,className:`univer-relative univer-overflow-hidden`,children:[(0,i.jsx)(`canvas`,{ref:a,className:`univer-size-full univer-cursor-crosshair univer-rounded`,onPointerDown:e=>{c(!0),l(e)},onPointerMove:e=>s&&l(e)}),(0,i.jsx)(`div`,{className:`univer-pointer-events-none univer-absolute univer-left-0 univer-top-0 univer-size-4 univer-rounded-full univer-border-2 univer-border-white univer-shadow-md univer-ring-2 univer-ring-white univer-will-change-transform`,style:f()})]})}function Ce({hsv:e,onChange:n,onChanged:r}){let[a,o]=(0,t.useState)(!1),s=(0,t.useRef)(null),c=(0,t.useRef)(null),l=(0,t.useCallback)(t=>{var r,i;let a=s.current;if(!a)return;let o=(r=(i=c.current)==null?void 0:i.clientWidth)==null?0:r,l=a.getBoundingClientRect(),u=l.width-o;if(u<=0){n(0,e[1],e[2]);return}let d=Math.max(0,Math.min(t-l.left,u));n(Math.round(d/u*360),e[1],e[2])},[e,n]),u=(0,t.useCallback)(e=>{e.stopPropagation(),a&&l(e.clientX)},[a,l]),d=(0,t.useCallback)(()=>{o(!1),r==null||r(e[0],e[1],e[2])},[e,r]);(0,t.useEffect)(()=>(a&&(window.addEventListener(`pointermove`,u),window.addEventListener(`pointerup`,d),window.addEventListener(`mouseup`,d)),()=>{window.removeEventListener(`pointermove`,u),window.removeEventListener(`pointerup`,d),window.removeEventListener(`mouseup`,d)}),[a,u,d]);let f=()=>{var t,n,r,i;let a=Math.min(Math.max(e[0],0),360),o=(t=(n=c.current)==null?void 0:n.clientWidth)==null?0:t,l=(r=(i=s.current)==null?void 0:i.clientWidth)==null?0:r,u=l>0?o/l*100:0;return`${a/360*(100-u)}%`};return(0,i.jsx)(`div`,{"data-u-comp":`color-picker-hue-slider`,className:`univer-relative univer-w-full univer-select-none`,children:(0,i.jsx)(`div`,{ref:s,className:`univer-relative univer-h-2 univer-w-full univer-cursor-pointer univer-rounded-full univer-shadow-inner`,style:{background:`linear-gradient(to right,
182
+ `
183
+ },
184
+ size: {
185
+ small: "univer-h-6 univer-rounded-md univer-px-1.5 univer-text-xs",
186
+ middle: "univer-h-8 univer-rounded-lg univer-px-2 univer-text-sm",
187
+ large: "univer-h-10 univer-rounded-lg univer-px-3 univer-text-sm"
188
+ }
189
+ },
190
+ defaultVariants: {
191
+ variant: "default",
192
+ size: "middle"
193
+ }
194
+ });
195
+ const Button = (0, react.forwardRef)(({ className, variant, size, asChild = false, ...props }, ref) => {
196
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(asChild ? _radix_ui_react_slot.Slot : "button", {
197
+ className: clsx$1(buttonVariants({
198
+ variant,
199
+ size,
200
+ className
201
+ })),
202
+ ref,
203
+ "data-u-comp": "button",
204
+ ...props
205
+ });
206
+ });
207
+ Button.displayName = "Button";
208
+
209
+ //#endregion
210
+ //#region src/components/button/ButtonGroup.tsx
211
+ const ButtonGroup = ({ className, orientation = "horizontal", children }) => {
212
+ const totalButtons = react.Children.count(children);
213
+ const isHorizontal = orientation === "horizontal";
214
+ const isVertical = orientation === "vertical";
215
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
216
+ className: clsx$1("univer-grid", {
217
+ "univer-grid-flow-row": isVertical,
218
+ "univer-w-fit": isVertical
219
+ }, className),
220
+ children: react.Children.map(children, (child, index) => {
221
+ const isFirst = index === 0;
222
+ const isLast = index === totalButtons - 1;
223
+ return (0, react.cloneElement)(child, { className: clsx$1({
224
+ "!univer-rounded-l-none": isHorizontal && !isFirst,
225
+ "!univer-rounded-r-none": isHorizontal && !isLast,
226
+ "!univer-border-l-0": isHorizontal && !isFirst,
227
+ "!univer-rounded-t-none": isVertical && !isFirst,
228
+ "!univer-rounded-b-none": isVertical && !isLast,
229
+ "!univer-border-t-0": isVertical && !isFirst
230
+ }, child.props.className) });
231
+ })
232
+ });
233
+ };
234
+
235
+ //#endregion
236
+ //#region src/helper/is-browser.ts
237
+ /**
238
+ * Copyright 2023-present DreamNum Co., Ltd.
239
+ *
240
+ * Licensed under the Apache License, Version 2.0 (the "License");
241
+ * you may not use this file except in compliance with the License.
242
+ * You may obtain a copy of the License at
243
+ *
244
+ * http://www.apache.org/licenses/LICENSE-2.0
245
+ *
246
+ * Unless required by applicable law or agreed to in writing, software
247
+ * distributed under the License is distributed on an "AS IS" BASIS,
248
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
249
+ * See the License for the specific language governing permissions and
250
+ * limitations under the License.
251
+ */
252
+ function isBrowser() {
253
+ return typeof window !== "undefined" && typeof document !== "undefined";
254
+ }
255
+
256
+ //#endregion
257
+ //#region src/components/config-provider/ConfigProvider.tsx
258
+ const ConfigContext = (0, react.createContext)({ mountContainer: isBrowser() ? document.body : null });
259
+ function ConfigProvider(props) {
260
+ const { children, locale, mountContainer } = props;
261
+ const value = (0, react.useMemo)(() => {
262
+ return {
263
+ locale,
264
+ mountContainer
265
+ };
266
+ }, [locale, mountContainer]);
267
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConfigContext.Provider, {
268
+ value,
269
+ children
270
+ });
271
+ }
272
+
273
+ //#endregion
274
+ //#region src/helper/class-utilities.ts
275
+ /**
276
+ * Copyright 2023-present DreamNum Co., Ltd.
277
+ *
278
+ * Licensed under the Apache License, Version 2.0 (the "License");
279
+ * you may not use this file except in compliance with the License.
280
+ * You may obtain a copy of the License at
281
+ *
282
+ * http://www.apache.org/licenses/LICENSE-2.0
283
+ *
284
+ * Unless required by applicable law or agreed to in writing, software
285
+ * distributed under the License is distributed on an "AS IS" BASIS,
286
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
287
+ * See the License for the specific language governing permissions and
288
+ * limitations under the License.
289
+ */
290
+ const scrollbarClassName = "univer-scrollbar-thin univer-scrollbar-track-gray-50 univer-scrollbar-thumb-gray-300 dark:!univer-scrollbar-track-gray-900 dark:!univer-scrollbar-thumb-gray-700";
291
+ const borderBasicClassName = "univer-border-gray-200 dark:!univer-border-gray-600 univer-border-solid";
292
+ const borderClassName = clsx$1(borderBasicClassName, "univer-border");
293
+ const borderLeftBottomClassName = clsx$1(borderBasicClassName, "univer-border-l univer-border-b univer-border-t-0 univer-border-r-0");
294
+ const borderLeftClassName = clsx$1(borderBasicClassName, "univer-border-l univer-border-b-0 univer-border-t-0 univer-border-r-0");
295
+ const borderLeftRTLClassName = clsx$1(borderBasicClassName, "univer-border-b-0 univer-border-t-0 rtl:univer-border-l-0 rtl:univer-border-r");
296
+ const borderTopClassName = clsx$1(borderBasicClassName, "univer-border-l-0 univer-border-b-0 univer-border-t univer-border-r-0");
297
+ const borderBottomClassName = clsx$1(borderBasicClassName, "univer-border-l-0 univer-border-b univer-border-t-0 univer-border-r-0");
298
+ const borderRightClassName = clsx$1(borderBasicClassName, "univer-border-l-0 univer-border-b-0 univer-border-t-0 univer-border-r");
299
+ const divideYClassName = "univer-divide-gray-200 dark:!univer-divide-gray-600 univer-divide-y univer-divide-x-0 univer-divide-solid";
300
+ const divideXClassName = "univer-divide-gray-200 dark:!univer-divide-gray-600 univer-divide-x univer-divide-y-0 univer-divide-solid";
301
+
302
+ //#endregion
303
+ //#region src/helper/date.ts
304
+ /**
305
+ * Copyright 2023-present DreamNum Co., Ltd.
306
+ *
307
+ * Licensed under the Apache License, Version 2.0 (the "License");
308
+ * you may not use this file except in compliance with the License.
309
+ * You may obtain a copy of the License at
310
+ *
311
+ * http://www.apache.org/licenses/LICENSE-2.0
312
+ *
313
+ * Unless required by applicable law or agreed to in writing, software
314
+ * distributed under the License is distributed on an "AS IS" BASIS,
315
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
316
+ * See the License for the specific language governing permissions and
317
+ * limitations under the License.
318
+ */
319
+ function pad(value, length = 2) {
320
+ return String(value).padStart(length, "0");
321
+ }
322
+ function formatDateWithPattern(value, pattern) {
323
+ const date = value !== null && value !== void 0 ? value : /* @__PURE__ */ new Date();
324
+ if (Number.isNaN(date.getTime())) return "Invalid Date";
325
+ const tokenMap = {
326
+ YYYY: String(date.getFullYear()),
327
+ MM: pad(date.getMonth() + 1),
328
+ DD: pad(date.getDate()),
329
+ HH: pad(date.getHours()),
330
+ mm: pad(date.getMinutes()),
331
+ ss: pad(date.getSeconds())
332
+ };
333
+ return pattern.replace(/YYYY|MM|DD|HH|mm|ss/g, (token) => {
334
+ var _tokenMap$token;
335
+ return (_tokenMap$token = tokenMap[token]) !== null && _tokenMap$token !== void 0 ? _tokenMap$token : token;
336
+ });
337
+ }
338
+
339
+ //#endregion
340
+ //#region src/components/time-input/TimeInput.tsx
341
+ function TimeInput(props) {
342
+ const { className, value, onValueChange } = props;
343
+ function handleChangeTime(event) {
344
+ const [hours, minutes, seconds] = event.target.value.split(":").map(Number);
345
+ const newValue = new Date(value !== null && value !== void 0 ? value : Date.now());
346
+ newValue.setHours(hours, minutes, seconds, 0);
347
+ onValueChange === null || onValueChange === void 0 || onValueChange(newValue);
348
+ }
349
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
350
+ "data-u-comp": "time-input",
351
+ className: "univer-relative univer-mx-auto univer-mt-1 univer-w-fit",
352
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.ClockIcon, { className: "univer-absolute univer-left-2 univer-top-1/2 -univer-translate-y-1/2 univer-text-gray-600 dark:!univer-text-gray-400" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
353
+ className: clsx$1("univer-block univer-h-7 univer-w-fit univer-appearance-none univer-rounded-md univer-bg-transparent univer-pl-6 univer-pr-2 univer-text-center univer-text-gray-800 univer-shadow univer-outline-none univer-transition-all univer-duration-200 focus:univer-border-primary-600 dark:!univer-text-white dark:focus:!univer-border-primary-500 [&::-webkit-calendar-picker-indicator]:univer-hidden [&::-webkit-calendar-picker-indicator]:univer-appearance-none", borderClassName, className),
354
+ type: "time",
355
+ step: "1",
356
+ value: formatDateWithPattern(value, "HH:mm:ss"),
357
+ onChange: handleChangeTime
358
+ })]
359
+ });
360
+ }
361
+
362
+ //#endregion
363
+ //#region src/components/calendar/Calendar.tsx
364
+ function getDaysInMonth(year, month) {
365
+ return new Date(year, month + 1, 0).getDate();
366
+ }
367
+ function getFirstDayOfWeek(year, month) {
368
+ return new Date(year, month, 1).getDay();
369
+ }
370
+ function DayButton(props) {
371
+ const { className, ...restProps } = props;
372
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
373
+ className: clsx$1("univer-size-7 univer-rounded-md univer-border-none univer-bg-transparent univer-p-1 univer-transition-all hover:univer-bg-gray-200 dark:hover:!univer-bg-gray-600", className),
374
+ type: "button",
375
+ ...restProps
376
+ });
377
+ }
378
+ function Calendar(props) {
379
+ const { className, max, min, showTime = false, value, onValueChange } = props;
380
+ const { locale } = (0, react.useContext)(ConfigContext);
381
+ const { year, weekDays, months } = locale === null || locale === void 0 ? void 0 : locale.Calendar;
382
+ const today = /* @__PURE__ */ new Date();
383
+ const [currentYear, setCurrentYear] = (0, react.useState)((value !== null && value !== void 0 ? value : today).getFullYear());
384
+ const [currentMonth, setCurrentMonth] = (0, react.useState)((value !== null && value !== void 0 ? value : today).getMonth());
385
+ function prevMonth() {
386
+ setCurrentMonth((prev) => {
387
+ if (prev === 0) {
388
+ setCurrentYear((y) => y - 1);
389
+ return 11;
390
+ }
391
+ return prev - 1;
392
+ });
393
+ }
394
+ function nextMonth() {
395
+ setCurrentMonth((prev) => {
396
+ if (prev === 11) {
397
+ setCurrentYear((y) => y + 1);
398
+ return 0;
399
+ }
400
+ return prev + 1;
401
+ });
402
+ }
403
+ const daysInMonth = getDaysInMonth(currentYear, currentMonth);
404
+ const firstDay = getFirstDayOfWeek(currentYear, currentMonth);
405
+ const days = (0, react.useMemo)(() => {
406
+ const daysArray = [];
407
+ for (let i = 0; i < firstDay; i++) daysArray.push(null);
408
+ for (let d = 1; d <= daysInMonth; d++) daysArray.push(d);
409
+ return daysArray;
410
+ }, [daysInMonth, firstDay]);
411
+ function isSelected(day) {
412
+ return day && currentYear === (value === null || value === void 0 ? void 0 : value.getFullYear()) && currentMonth === (value === null || value === void 0 ? void 0 : value.getMonth()) && day === (value === null || value === void 0 ? void 0 : value.getDate());
413
+ }
414
+ function isToday(day) {
415
+ return day && currentYear === today.getFullYear() && currentMonth === today.getMonth() && day === today.getDate();
416
+ }
417
+ function isDisabled(day) {
418
+ var _value$getHours, _value$getMinutes, _value$getSeconds;
419
+ if (!day) return false;
420
+ const hours = (_value$getHours = value === null || value === void 0 ? void 0 : value.getHours()) !== null && _value$getHours !== void 0 ? _value$getHours : today.getHours();
421
+ const minutes = (_value$getMinutes = value === null || value === void 0 ? void 0 : value.getMinutes()) !== null && _value$getMinutes !== void 0 ? _value$getMinutes : today.getMinutes();
422
+ const seconds = (_value$getSeconds = value === null || value === void 0 ? void 0 : value.getSeconds()) !== null && _value$getSeconds !== void 0 ? _value$getSeconds : today.getSeconds();
423
+ const d = new Date(currentYear, currentMonth, day, hours, minutes, seconds);
424
+ if (min && d < min) return true;
425
+ if (max && d > max) return true;
426
+ return false;
427
+ }
428
+ function handleChangeDate(day) {
429
+ var _value$getHours2, _value$getMinutes2, _value$getSeconds2;
430
+ if (isDisabled(day)) return;
431
+ const hours = (_value$getHours2 = value === null || value === void 0 ? void 0 : value.getHours()) !== null && _value$getHours2 !== void 0 ? _value$getHours2 : today.getHours();
432
+ const minutes = (_value$getMinutes2 = value === null || value === void 0 ? void 0 : value.getMinutes()) !== null && _value$getMinutes2 !== void 0 ? _value$getMinutes2 : today.getMinutes();
433
+ const seconds = (_value$getSeconds2 = value === null || value === void 0 ? void 0 : value.getSeconds()) !== null && _value$getSeconds2 !== void 0 ? _value$getSeconds2 : today.getSeconds();
434
+ const selectedDate = new Date(currentYear, currentMonth, day, hours, minutes, seconds);
435
+ onValueChange === null || onValueChange === void 0 || onValueChange(selectedDate);
436
+ }
437
+ function handleChangeTime(time) {
438
+ var _value$getDate;
439
+ const hours = time.getHours();
440
+ const minutes = time.getMinutes();
441
+ const seconds = time.getSeconds();
442
+ const updatedDate = new Date(currentYear, currentMonth, (_value$getDate = value === null || value === void 0 ? void 0 : value.getDate()) !== null && _value$getDate !== void 0 ? _value$getDate : today.getDate(), hours, minutes, seconds);
443
+ onValueChange === null || onValueChange === void 0 || onValueChange(updatedDate);
444
+ }
445
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
446
+ "data-u-comp": "calendar",
447
+ className: clsx$1("univer-mx-auto univer-max-w-xs univer-select-none univer-rounded univer-bg-white univer-text-gray-900 dark:!univer-bg-gray-900 dark:!univer-text-white", className),
448
+ children: [
449
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("nav", {
450
+ className: "univer-mb-4 univer-flex univer-items-center univer-justify-between",
451
+ children: [
452
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, {
453
+ className: "univer-text-lg univer-text-gray-500 dark:!univer-text-gray-200",
454
+ "aria-label": "Previous Month",
455
+ onClick: prevMonth,
456
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreRightIcon, { className: "univer-rotate-180" })
457
+ }),
458
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
459
+ className: "univer-flex univer-gap-0.5 univer-text-sm univer-font-medium",
460
+ children: [
461
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: currentYear }),
462
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: year }),
463
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: months[currentMonth] })
464
+ ]
465
+ }),
466
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, {
467
+ className: "univer-text-lg univer-text-gray-500 dark:!univer-text-gray-200",
468
+ "aria-label": "Next Month",
469
+ onClick: nextMonth,
470
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreRightIcon, {})
471
+ })
472
+ ]
473
+ }),
474
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
475
+ className: "univer-mb-1 univer-grid univer-grid-cols-7 univer-gap-1 univer-text-center univer-text-sm univer-text-gray-500 dark:!univer-text-gray-200",
476
+ children: weekDays.map((wd) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: wd }, wd))
477
+ }),
478
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
479
+ className: "univer-grid univer-grid-cols-7 univer-gap-1 univer-text-center",
480
+ children: days.map((day, idx) => day ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, {
481
+ className: clsx$1({
482
+ "!univer-bg-primary-600 univer-font-bold univer-text-white": !isToday(day) && isSelected(day),
483
+ "dark:!univer-text-white": !isToday(day) && !isSelected(day),
484
+ "!univer-bg-primary-600 univer-text-white": isToday(day) && isSelected(day),
485
+ "univer-font-semibold univer-text-primary-600 dark:!univer-text-primary-500": isToday(day) && !isSelected(day),
486
+ "univer-cursor-not-allowed univer-opacity-40": isDisabled(day),
487
+ "univer-hover:bg-primary-100 univer-cursor-pointer univer-text-gray-800": !isSelected(day) && !isDisabled(day)
488
+ }),
489
+ onClick: () => handleChangeDate(day),
490
+ disabled: isDisabled(day),
491
+ children: day
492
+ }, idx) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {}, idx))
493
+ }),
494
+ showTime && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TimeInput, {
495
+ value,
496
+ onValueChange: handleChangeTime
497
+ })
498
+ ]
499
+ });
500
+ }
501
+
502
+ //#endregion
503
+ //#region src/components/cascader-list/CascaderList.tsx
504
+ /**
505
+ * Copyright 2023-present DreamNum Co., Ltd.
506
+ *
507
+ * Licensed under the Apache License, Version 2.0 (the "License");
508
+ * you may not use this file except in compliance with the License.
509
+ * You may obtain a copy of the License at
510
+ *
511
+ * http://www.apache.org/licenses/LICENSE-2.0
512
+ *
513
+ * Unless required by applicable law or agreed to in writing, software
514
+ * distributed under the License is distributed on an "AS IS" BASIS,
515
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
516
+ * See the License for the specific language governing permissions and
517
+ * limitations under the License.
518
+ */
519
+ function Empty({ emptyText }) {
520
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
521
+ className: "univer-h-8 univer-px-2 univer-pr-32 univer-text-sm/8 univer-text-gray-600 dark:!univer-text-gray-200",
522
+ children: emptyText
523
+ });
524
+ }
525
+ function CascaderList(props) {
526
+ const { value, options = [], onChange, contentClassName, wrapperClassName } = props;
527
+ const { locale } = (0, react.useContext)(ConfigContext);
528
+ const activeOptions = (0, react.useMemo)(() => {
529
+ const activeOptions = [options];
530
+ value.forEach((item, index) => {
531
+ const option = activeOptions[index].find((option) => option.value === item);
532
+ if (option === null || option === void 0 ? void 0 : option.children) activeOptions.push(option.children);
533
+ });
534
+ return activeOptions;
535
+ }, [value]);
536
+ function handleChange(index, v) {
537
+ if (v === value[index]) return;
538
+ if (value[index + 1]) {
539
+ const newValue = value.slice(0, index + 1);
540
+ newValue[index] = v;
541
+ onChange(newValue);
542
+ return;
543
+ }
544
+ const newValue = [...value];
545
+ newValue[index] = v;
546
+ onChange(newValue);
547
+ }
548
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
549
+ "data-u-comp": "cascader-list",
550
+ className: clsx$1("univer-overflow-auto-y univer-grid univer-h-full univer-max-h-80 univer-grid-flow-col univer-rounded univer-py-2 univer-text-gray-900 dark:!univer-text-white [&>ul:not(:last-child)]:univer-border-0 [&>ul:not(:last-child)]:univer-border-r [&>ul:not(:last-child)]:univer-border-solid [&>ul:not(:last-child)]:univer-border-r-gray-200", borderClassName, scrollbarClassName, wrapperClassName),
551
+ children: [activeOptions.map((options, index) => options.length ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
552
+ className: clsx$1("univer-m-0 univer-h-full univer-max-h-full univer-list-none univer-overflow-auto univer-px-2", scrollbarClassName, contentClassName),
553
+ children: options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
554
+ className: clsx$1("univer-relative univer-block univer-h-8 univer-cursor-pointer univer-rounded univer-text-sm/8", {
555
+ "univer-px-7": index > 0,
556
+ "univer-px-1.5": index === 0,
557
+ "univer-bg-gray-200 dark:!univer-bg-gray-600": option.value === value[index]
558
+ }),
559
+ onClick: () => handleChange(index, option.value),
560
+ children: [index > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
561
+ className: "univer-absolute univer-left-2 univer-flex univer-h-full univer-items-center",
562
+ children: option.value === value[index] && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CheckMarkIcon, { className: "univer-text-primary-600" })
563
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: option.label })]
564
+ }) }, option.value))
565
+ }, index) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Empty, { emptyText: locale === null || locale === void 0 ? void 0 : locale.CascaderList.empty }, index)), value.length <= 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Empty, { emptyText: locale === null || locale === void 0 ? void 0 : locale.CascaderList.empty })]
566
+ });
567
+ }
568
+
569
+ //#endregion
570
+ //#region src/components/checkbox-group/CheckboxGroup.tsx
571
+ /**
572
+ * CheckboxGroup Component
573
+ */
574
+ function CheckboxGroup(props) {
575
+ const { children, className, style, value, disabled, direction = "horizontal", onChange } = props;
576
+ const handleChange = (item) => {
577
+ if (value.includes(item)) onChange(value.filter((i) => i !== item));
578
+ else onChange([...value, item]);
579
+ };
580
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
581
+ className: clsx$1("univer-flex univer-gap-2", { "univer-flex-col": direction === "vertical" }, className),
582
+ style,
583
+ children: react.Children.map(children, (child, index) => {
584
+ if ((0, react.isValidElement)(child)) return (0, react.cloneElement)(child, {
585
+ key: index,
586
+ children: child.props.children,
587
+ checked: child.props.value ? value.includes(child.props.value) : false,
588
+ disabled: disabled !== null && disabled !== void 0 ? disabled : child.props.disabled,
589
+ onChange: handleChange
590
+ });
591
+ return child;
592
+ })
593
+ });
594
+ }
595
+
596
+ //#endregion
597
+ //#region src/components/checkbox/Checkbox.tsx
598
+ /**
599
+ * Checkbox Component
600
+ */
601
+ function Checkbox(props) {
602
+ const { children, className, style, checked = false, indeterminate = false, value, disabled = false, onChange, contentClassName } = props;
603
+ const inputRef = (0, react.useRef)(null);
604
+ function handleChange(e) {
605
+ e.stopPropagation();
606
+ if (!onChange || disabled) return;
607
+ if (typeof value !== "undefined") onChange === null || onChange === void 0 || onChange(value);
608
+ else {
609
+ var _inputRef$current$che, _inputRef$current;
610
+ const checked = (_inputRef$current$che = inputRef === null || inputRef === void 0 || (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.checked) !== null && _inputRef$current$che !== void 0 ? _inputRef$current$che : false;
611
+ onChange === null || onChange === void 0 || onChange(checked);
612
+ }
613
+ }
614
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
615
+ "data-u-comp": "checkbox",
616
+ className: clsx$1("univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-text-sm", {
617
+ "univer-cursor-pointer univer-text-gray-900 dark:!univer-text-white": !disabled,
618
+ "univer-text-gray-400": disabled
619
+ }, className),
620
+ style,
621
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
622
+ className: "univer-relative univer-block",
623
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
624
+ ref: inputRef,
625
+ className: "univer-absolute univer-size-0 univer-opacity-0",
626
+ type: "checkbox",
627
+ checked,
628
+ disabled,
629
+ onChange: handleChange
630
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
631
+ className: clsx$1("univer-relative univer-box-border univer-flex univer-size-4 univer-items-center univer-justify-center univer-overflow-hidden univer-rounded univer-border univer-border-solid univer-transition-colors", {
632
+ "univer-opacity-50": disabled,
633
+ "univer-border-primary-600 univer-bg-primary-600": checked || indeterminate,
634
+ "univer-border-gray-300 univer-bg-gray-50 dark:!univer-border-gray-500 dark:!univer-bg-gray-600": !checked && !indeterminate
635
+ }),
636
+ children: [checked && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CheckMarkIcon, { className: "univer-absolute univer-left-1/2 univer-top-1/2 univer-block univer-size-3 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-text-white" }), indeterminate && !checked && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "univer-absolute univer-left-1/2 univer-top-1/2 univer-block univer-h-0.5 univer-w-2.5 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-rounded univer-bg-white" })]
637
+ })]
638
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
639
+ className: clsx$1("univer-select-none", contentClassName),
640
+ children
641
+ })]
642
+ });
643
+ }
644
+
645
+ //#endregion
646
+ //#region src/components/dialog/DialogPrimitive.tsx
647
+ const Dialog$1 = _radix_ui_react_dialog.Root;
648
+ const DialogPortal = _radix_ui_react_dialog.Portal;
649
+ const DialogOverlay = (0, react.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dialog.Overlay, {
650
+ ref,
651
+ className: clsx$1("data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 univer-fixed univer-inset-0 univer-z-[1080] univer-bg-[rgba(0,0,0,0.8)]", className),
652
+ ...props
653
+ }));
654
+ DialogOverlay.displayName = _radix_ui_react_dialog.Overlay.displayName;
655
+ const DialogContent = (0, react.forwardRef)(({ className, children, closable = true, onClickClose, ...props }, ref) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DialogPortal, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DialogOverlay, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_radix_ui_react_dialog.Content, {
656
+ ref,
657
+ className: clsx$1("data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=open]:univer-slide-in-from-left-1/2 data-[state=open]:univer-slide-in-from-top-[48%] data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[state=closed]:univer-slide-out-to-left-1/2 data-[state=closed]:univer-slide-out-to-top-[48%] univer-fixed univer-left-1/2 univer-top-1/2 univer-z-[1080] univer-box-border univer-grid univer-w-full univer-max-w-lg -univer-translate-x-1/2 -univer-translate-y-1/2 univer-gap-4 univer-bg-white univer-p-4 univer-text-gray-500 univer-shadow-md univer-duration-200 sm:!univer-rounded-lg dark:!univer-bg-gray-700 dark:!univer-text-gray-400", borderClassName, className),
658
+ ...props,
659
+ children: [children, closable && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_radix_ui_react_dialog.Close, {
660
+ className: "univer-absolute univer-right-4 univer-top-4 univer-size-6 univer-cursor-pointer univer-rounded-sm univer-border-none univer-bg-transparent univer-p-0 univer-transition-opacity hover:univer-opacity-100 disabled:univer-pointer-events-none",
661
+ onClick: onClickClose,
662
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CloseIcon, { className: "univer-size-4 univer-text-gray-400" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
663
+ className: "univer-sr-only",
664
+ children: "Close"
665
+ })]
666
+ })]
667
+ })] }));
668
+ DialogContent.displayName = _radix_ui_react_dialog.Content.displayName;
669
+ const DialogHeader = ({ className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
670
+ className: clsx$1("univer-flex univer-flex-col univer-space-y-1.5 univer-text-center sm:!univer-text-left", className),
671
+ ...props
672
+ });
673
+ DialogHeader.displayName = "DialogHeader";
674
+ const DialogFooter = ({ className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
675
+ className: clsx$1("univer-flex univer-flex-col-reverse sm:!univer-flex-row sm:!univer-justify-end sm:!univer-space-x-2", className),
676
+ ...props
677
+ });
678
+ DialogFooter.displayName = "DialogFooter";
679
+ const DialogTitle = (0, react.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dialog.Title, {
680
+ ref,
681
+ className: clsx$1("univer-my-0 univer-text-lg univer-font-semibold univer-leading-none univer-tracking-tight univer-text-gray-900 dark:!univer-text-white", className),
682
+ ...props
683
+ }));
684
+ DialogTitle.displayName = _radix_ui_react_dialog.Title.displayName;
685
+ const DialogDescription = (0, react.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dialog.Description, {
686
+ ref,
687
+ className: clsx$1("univer-text-sm univer-text-gray-500", className),
688
+ ...props
689
+ }));
690
+ DialogDescription.displayName = _radix_ui_react_dialog.Description.displayName;
691
+
692
+ //#endregion
693
+ //#region src/components/dialog/Dialog.tsx
694
+ function useDraggable(options = {}) {
695
+ const getCenteredPosition = (0, react.useCallback)(() => {
696
+ const { innerWidth, innerHeight } = window;
697
+ return {
698
+ x: Math.max(0, (innerWidth - 0) / 2),
699
+ y: Math.max(0, (innerHeight - 0) / 2)
700
+ };
701
+ }, []);
702
+ const { defaultPosition = getCenteredPosition(), enabled = false } = options;
703
+ const [position, setPosition] = (0, react.useState)(defaultPosition);
704
+ const [isDragging, setIsDragging] = (0, react.useState)(false);
705
+ const elementRef = (0, react.useRef)(null);
706
+ const startPosRef = (0, react.useRef)({
707
+ x: 0,
708
+ y: 0
709
+ });
710
+ const startClientRef = (0, react.useRef)({
711
+ x: 0,
712
+ y: 0
713
+ });
714
+ const initializedRef = (0, react.useRef)(false);
715
+ (0, react.useEffect)(() => {
716
+ if (!elementRef.current || initializedRef.current || options.defaultPosition) return;
717
+ const { width, height } = elementRef.current.getBoundingClientRect();
718
+ const { innerWidth, innerHeight } = window;
719
+ const centeredX = Math.max(0, (innerWidth - width) / 2);
720
+ const centeredY = Math.max(0, (innerHeight - height) / 2);
721
+ setPosition({
722
+ x: centeredX,
723
+ y: centeredY
724
+ });
725
+ startPosRef.current = {
726
+ x: centeredX,
727
+ y: centeredY
728
+ };
729
+ initializedRef.current = true;
730
+ }, [options.defaultPosition]);
731
+ const calculateBounds = (0, react.useCallback)((clientX, clientY) => {
732
+ if (!elementRef.current) return {
733
+ x: clientX,
734
+ y: clientY
735
+ };
736
+ const rect = elementRef.current.getBoundingClientRect();
737
+ const { clientWidth, clientHeight } = document.documentElement;
738
+ let newX = startPosRef.current.x + (clientX - startClientRef.current.x);
739
+ let newY = startPosRef.current.y + (clientY - startClientRef.current.y);
740
+ if (newX < 0) newX = 0;
741
+ if (newY < 0) newY = 0;
742
+ if (newX + rect.width > clientWidth) newX = clientWidth - rect.width;
743
+ if (newY + rect.height > clientHeight) newY = clientHeight - rect.height;
744
+ return {
745
+ x: newX,
746
+ y: newY
747
+ };
748
+ }, []);
749
+ const startDrag = (0, react.useCallback)((e) => {
750
+ if (!enabled) return;
751
+ e.preventDefault();
752
+ e.stopPropagation();
753
+ startPosRef.current = { ...position };
754
+ startClientRef.current = {
755
+ x: e.clientX,
756
+ y: e.clientY
757
+ };
758
+ setIsDragging(true);
759
+ document.body.style.userSelect = "none";
760
+ }, [enabled, position]);
761
+ const onDrag = (0, react.useCallback)((e) => {
762
+ if (!isDragging) return;
763
+ e.preventDefault();
764
+ e.stopPropagation();
765
+ setPosition(calculateBounds(e.clientX, e.clientY));
766
+ }, [isDragging, calculateBounds]);
767
+ const endDrag = (0, react.useCallback)(() => {
768
+ setIsDragging(false);
769
+ document.body.style.userSelect = "";
770
+ }, []);
771
+ (0, react.useEffect)(() => {
772
+ if (enabled) {
773
+ document.addEventListener("mousemove", onDrag);
774
+ document.addEventListener("mouseup", endDrag);
775
+ return () => {
776
+ document.removeEventListener("mousemove", onDrag);
777
+ document.removeEventListener("mouseup", endDrag);
778
+ };
779
+ }
780
+ }, [
781
+ enabled,
782
+ onDrag,
783
+ endDrag
784
+ ]);
785
+ return {
786
+ position,
787
+ isDragging,
788
+ elementRef,
789
+ setElementRef: (el) => {
790
+ elementRef.current = el;
791
+ if (el && !initializedRef.current && !options.defaultPosition) {
792
+ const { width, height } = el.getBoundingClientRect();
793
+ const { innerWidth, innerHeight } = window;
794
+ const centeredX = Math.max(0, (innerWidth - width) / 2);
795
+ const centeredY = Math.max(0, (innerHeight - height) / 2);
796
+ setPosition({
797
+ x: centeredX,
798
+ y: centeredY
799
+ });
800
+ startPosRef.current = {
801
+ x: centeredX,
802
+ y: centeredY
803
+ };
804
+ initializedRef.current = true;
805
+ }
806
+ },
807
+ handleMouseDown: startDrag
808
+ };
809
+ }
810
+ function Dialog(props) {
811
+ var _locale$Confirm$cance, _locale$Confirm, _locale$Confirm$confi, _locale$Confirm2;
812
+ const { className, children, style, open = false, title, width, draggable = false, defaultPosition, footer: propFooter, mask = true, keyboard = true, closable = true, maskClosable = true, showOk, showCancel, onOpenChange, onClose, onOk, onCancel } = props;
813
+ const { locale } = (0, react.useContext)(ConfigContext);
814
+ const { position, isDragging, setElementRef, handleMouseDown } = useDraggable({
815
+ defaultPosition,
816
+ enabled: draggable
817
+ });
818
+ const footer = propFooter !== null && propFooter !== void 0 ? propFooter : showOk || showCancel ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
819
+ className: "univer-flex univer-justify-end univer-gap-2",
820
+ children: [showCancel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
821
+ onClick: onCancel,
822
+ children: (_locale$Confirm$cance = locale === null || locale === void 0 || (_locale$Confirm = locale.Confirm) === null || _locale$Confirm === void 0 ? void 0 : _locale$Confirm.cancel) !== null && _locale$Confirm$cance !== void 0 ? _locale$Confirm$cance : "Cancel"
823
+ }), showOk && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
824
+ variant: "primary",
825
+ onClick: onOk,
826
+ children: (_locale$Confirm$confi = locale === null || locale === void 0 || (_locale$Confirm2 = locale.Confirm) === null || _locale$Confirm2 === void 0 ? void 0 : _locale$Confirm2.confirm) !== null && _locale$Confirm$confi !== void 0 ? _locale$Confirm$confi : "OK"
827
+ })]
828
+ }) : null;
829
+ const handleContentRef = (0, react.useCallback)((node) => {
830
+ if (node && draggable) setElementRef(node);
831
+ }, [draggable, setElementRef]);
832
+ const handleOpenChange = (0, react.useCallback)((isOpen) => {
833
+ if (!mask && !isOpen) return;
834
+ onOpenChange === null || onOpenChange === void 0 || onOpenChange(isOpen);
835
+ if (!isOpen) onClose === null || onClose === void 0 || onClose();
836
+ }, [onClose, onOpenChange]);
837
+ function handleClickClose() {
838
+ onOpenChange === null || onOpenChange === void 0 || onOpenChange(false);
839
+ onClose === null || onClose === void 0 || onClose();
840
+ }
841
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Dialog$1, {
842
+ open,
843
+ onOpenChange: handleOpenChange,
844
+ modal: mask !== false,
845
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DialogContent, {
846
+ ref: handleContentRef,
847
+ className: clsx$1(className, { "!univer-animate-none": draggable }),
848
+ style: {
849
+ ...style,
850
+ width: width ? typeof width === "number" ? `${width}px` : width : void 0,
851
+ maxWidth: width ? "initial" : void 0,
852
+ ...draggable ? {
853
+ position: "absolute",
854
+ margin: 0,
855
+ left: 0,
856
+ top: 0,
857
+ transform: `translate(${position.x}px, ${position.y}px)`,
858
+ transition: isDragging ? "none" : void 0,
859
+ cursor: isDragging ? "grabbing" : void 0
860
+ } : {}
861
+ },
862
+ closable,
863
+ onClickClose: handleClickClose,
864
+ onEscapeKeyDown: (e) => {
865
+ if (keyboard) handleClickClose();
866
+ e.preventDefault();
867
+ },
868
+ onPointerDownOutside: (e) => {
869
+ if (maskClosable) handleClickClose();
870
+ e.preventDefault();
871
+ },
872
+ children: [
873
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DialogHeader, {
874
+ className: clsx$1({ "!univer-hidden": !title }),
875
+ "data-drag-handle": draggable ? "true" : void 0,
876
+ style: {
877
+ cursor: draggable ? "grab" : void 0,
878
+ userSelect: draggable ? "none" : void 0,
879
+ touchAction: draggable ? "none" : void 0
880
+ },
881
+ onMouseDown: draggable ? handleMouseDown : void 0,
882
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DialogTitle, { children: title }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DialogDescription, { className: "univer-hidden" })]
883
+ }),
884
+ children,
885
+ footer && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DialogFooter, { children: footer })
886
+ ]
887
+ })
888
+ });
889
+ }
890
+
891
+ //#endregion
892
+ //#region src/components/color-picker/color-conversion.ts
893
+ /**
894
+ * Copyright 2023-present DreamNum Co., Ltd.
895
+ *
896
+ * Licensed under the Apache License, Version 2.0 (the "License");
897
+ * you may not use this file except in compliance with the License.
898
+ * You may obtain a copy of the License at
899
+ *
900
+ * http://www.apache.org/licenses/LICENSE-2.0
901
+ *
902
+ * Unless required by applicable law or agreed to in writing, software
903
+ * distributed under the License is distributed on an "AS IS" BASIS,
904
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
905
+ * See the License for the specific language governing permissions and
906
+ * limitations under the License.
907
+ */
908
+ const hsvToRgb = (h, s, v) => {
909
+ s = s / 100;
910
+ v = v / 100;
911
+ const c = v * s;
912
+ const x = c * (1 - Math.abs(h / 60 % 2 - 1));
913
+ const m = v - c;
914
+ let r = 0;
915
+ let g = 0;
916
+ let b = 0;
917
+ if (h >= 0 && h < 60) {
918
+ r = c;
919
+ g = x;
920
+ b = 0;
921
+ } else if (h >= 60 && h < 120) {
922
+ r = x;
923
+ g = c;
924
+ b = 0;
925
+ } else if (h >= 120 && h < 180) {
926
+ r = 0;
927
+ g = c;
928
+ b = x;
929
+ } else if (h >= 180 && h < 240) {
930
+ r = 0;
931
+ g = x;
932
+ b = c;
933
+ } else if (h >= 240 && h < 300) {
934
+ r = x;
935
+ g = 0;
936
+ b = c;
937
+ } else if (h >= 300 && h < 360) {
938
+ r = c;
939
+ g = 0;
940
+ b = x;
941
+ }
942
+ return [
943
+ Math.round((r + m) * 255),
944
+ Math.round((g + m) * 255),
945
+ Math.round((b + m) * 255)
946
+ ];
947
+ };
948
+ const rgbToHex = (r, g, b) => {
949
+ const toHex = (n) => n.toString(16).padStart(2, "0");
950
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
951
+ };
952
+ const rgbToHsv = (r, g, b) => {
953
+ r /= 255;
954
+ g /= 255;
955
+ b /= 255;
956
+ const max = Math.max(r, g, b);
957
+ const d = max - Math.min(r, g, b);
958
+ let h = 0;
959
+ let s = 0;
960
+ const v = max;
961
+ if (max !== 0) s = d / max;
962
+ if (d !== 0) {
963
+ if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
964
+ else if (max === g) h = (b - r) / d + 2;
965
+ else if (max === b) h = (r - g) / d + 4;
966
+ h *= 60;
967
+ }
968
+ return [
969
+ h,
970
+ s * 100,
971
+ v * 100
972
+ ];
973
+ };
974
+ const hexToHsv = (hex) => {
975
+ if (hex.length === 4) hex = `#${hex.slice(1).split("").map((i) => i + i).join("")}`;
976
+ const [r, g, b] = hex.match(/\w\w/g).map((x) => Number.parseInt(x, 16));
977
+ return rgbToHsv(r, g, b);
978
+ };
979
+ const hsvToHex = (h, s, v) => {
980
+ const [r, g, b] = hsvToRgb(h, s, v);
981
+ return rgbToHex(r, g, b);
982
+ };
983
+ const hsvToRgba = (h, s, v, a) => {
984
+ const [r, g, b] = hsvToRgb(h, s, v);
985
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
986
+ };
987
+ const parseRgba = (rgba) => {
988
+ const match = rgba.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d+))?\)/);
989
+ if (!match) throw new Error("Invalid RGBA string");
990
+ return [
991
+ Number.parseInt(match[1], 10),
992
+ Number.parseInt(match[2], 10),
993
+ Number.parseInt(match[3], 10),
994
+ match[4] ? Number.parseFloat(match[4]) : 1
995
+ ];
996
+ };
997
+
998
+ //#endregion
999
+ //#region src/components/color-picker/AlphaSlider.tsx
1000
+ /**
1001
+ * Copyright 2023-present DreamNum Co., Ltd.
1002
+ *
1003
+ * Licensed under the Apache License, Version 2.0 (the "License");
1004
+ * you may not use this file except in compliance with the License.
1005
+ * You may obtain a copy of the License at
1006
+ *
1007
+ * http://www.apache.org/licenses/LICENSE-2.0
1008
+ *
1009
+ * Unless required by applicable law or agreed to in writing, software
1010
+ * distributed under the License is distributed on an "AS IS" BASIS,
1011
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1012
+ * See the License for the specific language governing permissions and
1013
+ * limitations under the License.
1014
+ */
1015
+ function AlphaSlider({ hsv, alpha, onChange, onChanged }) {
1016
+ const [isDragging, setIsDragging] = (0, react.useState)(false);
1017
+ const sliderRef = (0, react.useRef)(null);
1018
+ const thumbRef = (0, react.useRef)(null);
1019
+ const calculateAlpha = (0, react.useCallback)((clientX) => {
1020
+ var _thumbRef$current$cli, _thumbRef$current;
1021
+ const slider = sliderRef.current;
1022
+ if (!slider) return;
1023
+ const thumbSize = (_thumbRef$current$cli = (_thumbRef$current = thumbRef.current) === null || _thumbRef$current === void 0 ? void 0 : _thumbRef$current.clientWidth) !== null && _thumbRef$current$cli !== void 0 ? _thumbRef$current$cli : 0;
1024
+ const rect = slider.getBoundingClientRect();
1025
+ const maxX = rect.width - thumbSize;
1026
+ if (maxX <= 0) {
1027
+ onChange(0);
1028
+ return;
1029
+ }
1030
+ const x = Math.max(0, Math.min(clientX - rect.left, maxX));
1031
+ onChange(Math.round(x / maxX * 100) / 100);
1032
+ }, [onChange]);
1033
+ const handlePointerMove = (0, react.useCallback)((e) => {
1034
+ if (!isDragging) return;
1035
+ calculateAlpha(e.clientX);
1036
+ }, [isDragging, calculateAlpha]);
1037
+ const handlePointerUp = (0, react.useCallback)(() => {
1038
+ setIsDragging(false);
1039
+ onChanged === null || onChanged === void 0 || onChanged(alpha);
1040
+ }, [alpha]);
1041
+ (0, react.useEffect)(() => {
1042
+ if (isDragging) {
1043
+ window.addEventListener("pointermove", handlePointerMove);
1044
+ window.addEventListener("pointerup", handlePointerUp);
1045
+ window.addEventListener("mouseup", handlePointerUp);
1046
+ }
1047
+ return () => {
1048
+ window.removeEventListener("pointermove", handlePointerMove);
1049
+ window.removeEventListener("pointerup", handlePointerUp);
1050
+ window.removeEventListener("mouseup", handlePointerUp);
1051
+ };
1052
+ }, [
1053
+ isDragging,
1054
+ handlePointerMove,
1055
+ handlePointerUp
1056
+ ]);
1057
+ const getThumbPosition = () => {
1058
+ var _thumbRef$current$cli2, _thumbRef$current2, _sliderRef$current$cl, _sliderRef$current;
1059
+ const safeAlpha = Math.min(Math.max(alpha * 100, 0), 100);
1060
+ const thumbSize = (_thumbRef$current$cli2 = (_thumbRef$current2 = thumbRef.current) === null || _thumbRef$current2 === void 0 ? void 0 : _thumbRef$current2.clientWidth) !== null && _thumbRef$current$cli2 !== void 0 ? _thumbRef$current$cli2 : 0;
1061
+ const sliderWidth = (_sliderRef$current$cl = (_sliderRef$current = sliderRef.current) === null || _sliderRef$current === void 0 ? void 0 : _sliderRef$current.clientWidth) !== null && _sliderRef$current$cl !== void 0 ? _sliderRef$current$cl : 0;
1062
+ const thumbOffsetPercent = sliderWidth > 0 ? thumbSize / sliderWidth * 100 : 0;
1063
+ return `${safeAlpha / 100 * (100 - thumbOffsetPercent)}%`;
1064
+ };
1065
+ const color = hsvToRgb(...hsv);
1066
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1067
+ className: "univer-relative univer-w-full univer-select-none",
1068
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1069
+ className: "univer-absolute univer-inset-0 univer-rounded-full",
1070
+ style: {
1071
+ backgroundImage: "linear-gradient(45deg, #E3E5EA 25%, transparent 25%), linear-gradient(-45deg, #E3E5EA 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #E3E5EA 75%), linear-gradient(-45deg, transparent 75%, #E3E5EA 75%)",
1072
+ backgroundPosition: "0 0, 0 4px, 4px -4px, -4px 0",
1073
+ backgroundSize: "8px 8px"
1074
+ }
1075
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1076
+ ref: sliderRef,
1077
+ className: "univer-relative univer-h-2 univer-w-full univer-cursor-pointer univer-rounded-full univer-shadow-inner",
1078
+ style: { background: `linear-gradient(to right, transparent, rgb(${color.join(",")}))` },
1079
+ onPointerDown: (e) => {
1080
+ setIsDragging(true);
1081
+ calculateAlpha(e.clientX);
1082
+ },
1083
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1084
+ ref: thumbRef,
1085
+ className: "univer-absolute univer-top-1/2 univer-box-border univer-size-2 univer-rounded-full univer-bg-transparent univer-shadow-md univer-ring-2 univer-ring-white univer-transition-transform univer-duration-75 univer-will-change-transform",
1086
+ style: {
1087
+ left: getThumbPosition(),
1088
+ transform: "translateY(-50%)",
1089
+ transition: isDragging ? "none" : "all 0.1s ease-out"
1090
+ }
1091
+ })
1092
+ })]
1093
+ });
1094
+ }
1095
+
1096
+ //#endregion
1097
+ //#region src/components/color-picker/ColorInput.tsx
1098
+ function HexInput({ hsv, onChange }) {
1099
+ const [inputValue, setInputValue] = (0, react.useState)("");
1100
+ const hexValue = (0, react.useMemo)(() => hsvToHex(hsv[0], hsv[1], hsv[2]), [hsv]);
1101
+ (0, react.useEffect)(() => {
1102
+ setInputValue(hexValue.replace(/^#/, ""));
1103
+ }, [hexValue]);
1104
+ const isValidHex = (hex) => {
1105
+ return /^[0-9A-Fa-f]{6}$/.test(hex);
1106
+ };
1107
+ const handleChange = (e) => {
1108
+ const newValue = e.target.value.trim();
1109
+ if (newValue.length > 6) return;
1110
+ if (newValue !== "" && !/^[0-9A-Fa-f]*$/.test(newValue)) return;
1111
+ setInputValue(newValue);
1112
+ if (isValidHex(newValue)) {
1113
+ const hsvValue = hexToHsv(newValue);
1114
+ if (hsvValue && onChange) onChange(...hsvValue);
1115
+ }
1116
+ };
1117
+ const handleBlur = () => {
1118
+ if (!isValidHex(inputValue)) setInputValue(hexValue.replace(/^#/, ""));
1119
+ };
1120
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1121
+ className: clsx$1("univer-w-full univer-px-2 !univer-pl-4 univer-uppercase focus:univer-border-primary-500 focus:univer-outline-none dark:!univer-text-white", borderClassName),
1122
+ value: inputValue,
1123
+ onChange: handleChange,
1124
+ onBlur: handleBlur,
1125
+ maxLength: 6,
1126
+ spellCheck: false
1127
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1128
+ className: "univer-absolute univer-left-1.5 univer-top-1/2 -univer-translate-y-1/2 univer-text-sm univer-text-gray-400",
1129
+ children: "#"
1130
+ })] });
1131
+ }
1132
+ function RgbInput({ hsv, alpha, format, onChange }) {
1133
+ const [localValues, setLocalValues] = (0, react.useState)({
1134
+ r: 0,
1135
+ g: 0,
1136
+ b: 0,
1137
+ a: 1
1138
+ });
1139
+ (0, react.useEffect)(() => {
1140
+ const [r, g, b] = hsvToRgb(hsv[0], hsv[1], hsv[2]);
1141
+ setLocalValues({
1142
+ r: Math.round(r),
1143
+ g: Math.round(g),
1144
+ b: Math.round(b),
1145
+ a: alpha !== null && alpha !== void 0 ? alpha : 1
1146
+ });
1147
+ }, [hsv, alpha]);
1148
+ const handleChange = (color, value) => {
1149
+ if (color === "a") {
1150
+ if (value !== "" && !/^\d*\.?\d*$/.test(value)) return;
1151
+ const numValue = value === "" ? 0 : Number.parseFloat(value);
1152
+ if (numValue > 1) return;
1153
+ setLocalValues({
1154
+ ...localValues,
1155
+ a: numValue
1156
+ });
1157
+ if (onChange) onChange(hsv[0], hsv[1], hsv[2], numValue);
1158
+ return;
1159
+ }
1160
+ if (value !== "" && !/^\d*$/.test(value)) return;
1161
+ const numValue = value === "" ? 0 : Number.parseInt(value, 10);
1162
+ if (numValue > 255) return;
1163
+ const newValues = {
1164
+ ...localValues,
1165
+ [color]: numValue
1166
+ };
1167
+ setLocalValues(newValues);
1168
+ if (onChange) onChange(...rgbToHsv(newValues.r, newValues.g, newValues.b), localValues.a);
1169
+ };
1170
+ const handleBlur = () => {
1171
+ const [r, g, b] = hsvToRgb(hsv[0], hsv[1], hsv[2]);
1172
+ setLocalValues({
1173
+ r: Math.round(r),
1174
+ g: Math.round(g),
1175
+ b: Math.round(b),
1176
+ a: alpha !== null && alpha !== void 0 ? alpha : 1
1177
+ });
1178
+ };
1179
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1180
+ className: "univer-flex univer-items-center univer-gap-2 [&>input]:univer-w-11 [&>input]:univer-border-gray-200 [&>input]:focus:univer-border-primary-500 dark:[&>input]:!univer-border-gray-600 dark:[&>input]:!univer-text-white",
1181
+ children: [
1182
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1183
+ value: localValues.r,
1184
+ onChange: (e) => handleChange("r", e.target.value),
1185
+ onBlur: handleBlur,
1186
+ maxLength: 3
1187
+ }),
1188
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1189
+ value: localValues.g,
1190
+ onChange: (e) => handleChange("g", e.target.value),
1191
+ onBlur: handleBlur,
1192
+ maxLength: 3
1193
+ }),
1194
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1195
+ value: localValues.b,
1196
+ onChange: (e) => handleChange("b", e.target.value),
1197
+ onBlur: handleBlur,
1198
+ maxLength: 3
1199
+ }),
1200
+ format === "rgba" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1201
+ value: localValues.a,
1202
+ onChange: (e) => handleChange("a", e.target.value),
1203
+ onBlur: handleBlur,
1204
+ maxLength: 4
1205
+ })
1206
+ ]
1207
+ });
1208
+ }
1209
+ function ColorInput({ hsv, alpha, format, onChange }) {
1210
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1211
+ className: "dark:![&_input]:univer-border-gray-600 dark:![&_input]:univer-text-white univer-flex univer-gap-2 [&_input]:univer-box-border [&_input]:univer-flex [&_input]:univer-h-7 [&_input]:univer-items-center [&_input]:univer-rounded [&_input]:univer-border [&_input]:univer-border-solid [&_input]:univer-border-gray-200 [&_input]:univer-bg-transparent [&_input]:univer-px-1.5 [&_input]:univer-text-sm [&_input]:univer-text-gray-700 [&_input]:univer-outline-none",
1212
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1213
+ className: "univer-relative univer-flex univer-flex-1 univer-gap-2",
1214
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(HexInput, {
1215
+ hsv,
1216
+ onChange
1217
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RgbInput, {
1218
+ hsv,
1219
+ alpha,
1220
+ format,
1221
+ onChange
1222
+ })]
1223
+ })
1224
+ });
1225
+ }
1226
+
1227
+ //#endregion
1228
+ //#region src/components/color-picker/presets.ts
1229
+ /**
1230
+ * Copyright 2023-present DreamNum Co., Ltd.
1231
+ *
1232
+ * Licensed under the Apache License, Version 2.0 (the "License");
1233
+ * you may not use this file except in compliance with the License.
1234
+ * You may obtain a copy of the License at
1235
+ *
1236
+ * http://www.apache.org/licenses/LICENSE-2.0
1237
+ *
1238
+ * Unless required by applicable law or agreed to in writing, software
1239
+ * distributed under the License is distributed on an "AS IS" BASIS,
1240
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1241
+ * See the License for the specific language governing permissions and
1242
+ * limitations under the License.
1243
+ */
1244
+ const colorPresets = [
1245
+ [
1246
+ "#FFFFFF",
1247
+ "#E1EFFE",
1248
+ "#FDE8E8",
1249
+ "#FEECDC",
1250
+ "#FFF4B9",
1251
+ "#DEF7EC",
1252
+ "#D5F5F6",
1253
+ "#EDEBFE",
1254
+ "#FCE8F3"
1255
+ ],
1256
+ [
1257
+ "#CDD0D8",
1258
+ "#A4CAFE",
1259
+ "#F8B4B4",
1260
+ "#FDBA8C",
1261
+ "#FAC815",
1262
+ "#84E1BC",
1263
+ "#7EDCE2",
1264
+ "#CABFFD",
1265
+ "#F8B4D9"
1266
+ ],
1267
+ [
1268
+ "#979DAC",
1269
+ "#3F83F8",
1270
+ "#F05252",
1271
+ "#FF5A1F",
1272
+ "#D49D0F",
1273
+ "#0DA471",
1274
+ "#0694A2",
1275
+ "#9061F9",
1276
+ "#E74694"
1277
+ ],
1278
+ [
1279
+ "#414657",
1280
+ "#1A56DB",
1281
+ "#C81E1E",
1282
+ "#B43403",
1283
+ "#9A6D15",
1284
+ "#046C4E",
1285
+ "#036672",
1286
+ "#6C2BD9",
1287
+ "#BF125D"
1288
+ ],
1289
+ [
1290
+ "#000000",
1291
+ "#233876",
1292
+ "#771D1D",
1293
+ "#8A2C0D",
1294
+ "#634312",
1295
+ "#014737",
1296
+ "#014451",
1297
+ "#4A1D96",
1298
+ "#751A3D"
1299
+ ]
1300
+ ];
1301
+
1302
+ //#endregion
1303
+ //#region src/components/color-picker/ColorPresets.tsx
1304
+ /**
1305
+ * Copyright 2023-present DreamNum Co., Ltd.
1306
+ *
1307
+ * Licensed under the Apache License, Version 2.0 (the "License");
1308
+ * you may not use this file except in compliance with the License.
1309
+ * You may obtain a copy of the License at
1310
+ *
1311
+ * http://www.apache.org/licenses/LICENSE-2.0
1312
+ *
1313
+ * Unless required by applicable law or agreed to in writing, software
1314
+ * distributed under the License is distributed on an "AS IS" BASIS,
1315
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1316
+ * See the License for the specific language governing permissions and
1317
+ * limitations under the License.
1318
+ */
1319
+ function ColorPresets({ hsv, onChange }) {
1320
+ const handleSelectPreset = (0, react.useCallback)((color) => {
1321
+ const [h, s, v] = hexToHsv(color);
1322
+ onChange(h, s, v);
1323
+ }, [onChange]);
1324
+ const currentColor = hsvToHex(hsv[0], hsv[1], hsv[2]);
1325
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1326
+ "data-u-comp": "color-picker-presets",
1327
+ className: "univer-grid univer-content-center univer-gap-2",
1328
+ children: colorPresets.map((row, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1329
+ className: "univer-grid univer-grid-flow-col univer-items-center univer-justify-between univer-gap-2",
1330
+ children: row.map((color, j) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1331
+ type: "button",
1332
+ className: clsx$1("univer-box-border univer-size-5 univer-cursor-pointer univer-rounded-full univer-border univer-border-solid univer-border-transparent univer-bg-gray-300 univer-transition-shadow", {
1333
+ "univer-ring-2 univer-ring-offset-2 univer-ring-offset-white dark:!univer-ring-primary-600 dark:!univer-ring-offset-gray-600": color.toUpperCase() === currentColor.toUpperCase(),
1334
+ "!univer-border-gray-200": i === 0 && j === 0
1335
+ }),
1336
+ style: { backgroundColor: color },
1337
+ onClick: () => handleSelectPreset(color)
1338
+ }, j))
1339
+ }, i))
1340
+ });
1341
+ }
1342
+
1343
+ //#endregion
1344
+ //#region src/components/color-picker/ColorSpectrum.tsx
1345
+ function ColorSpectrum({ hsv, onChange, onChanged }) {
1346
+ const canvasRef = (0, react.useRef)(null);
1347
+ const containerRef = (0, react.useRef)(null);
1348
+ const [isDragging, setIsDragging] = (0, react.useState)(false);
1349
+ (0, react.useEffect)(() => {
1350
+ const canvas = canvasRef.current;
1351
+ if (!canvas) return;
1352
+ const ctx = canvas.getContext("2d");
1353
+ if (!ctx) return;
1354
+ const gradientS = ctx.createLinearGradient(0, 0, canvas.width, 0);
1355
+ gradientS.addColorStop(0, `hsl(${hsv[0]}, 0%, 50%)`);
1356
+ gradientS.addColorStop(1, `hsl(${hsv[0]}, 100%, 50%)`);
1357
+ ctx.fillStyle = gradientS;
1358
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
1359
+ const gradientV = ctx.createLinearGradient(0, 0, 0, canvas.height);
1360
+ gradientV.addColorStop(0, "rgba(255, 255, 255, 0)");
1361
+ gradientV.addColorStop(1, "rgba(0, 0, 0, 1)");
1362
+ ctx.fillStyle = gradientV;
1363
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
1364
+ }, [hsv]);
1365
+ const handlePointerEvent = (e) => {
1366
+ e.stopPropagation();
1367
+ const canvas = canvasRef.current;
1368
+ if (!canvas) return;
1369
+ const rect = canvas.getBoundingClientRect();
1370
+ const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width));
1371
+ const y = Math.max(0, Math.min(e.clientY - rect.top, rect.height));
1372
+ const s = x / rect.width * 100;
1373
+ const v = 100 - y / rect.height * 100;
1374
+ onChange(hsv[0], s, v);
1375
+ };
1376
+ const handlePointerUp = (0, react.useCallback)(() => {
1377
+ setIsDragging(false);
1378
+ }, [hsv]);
1379
+ function handleChange() {
1380
+ onChanged === null || onChanged === void 0 || onChanged(hsv[0], hsv[1], hsv[2]);
1381
+ }
1382
+ (0, react.useEffect)(() => {
1383
+ var _containerRef$current;
1384
+ (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 || _containerRef$current.addEventListener("mouseup", handleChange);
1385
+ window.addEventListener("pointerup", handlePointerUp);
1386
+ window.addEventListener("mouseup", handlePointerUp);
1387
+ return () => {
1388
+ var _containerRef$current2;
1389
+ (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 || _containerRef$current2.removeEventListener("mouseup", handleChange);
1390
+ window.removeEventListener("pointerup", handlePointerUp);
1391
+ window.removeEventListener("mouseup", handlePointerUp);
1392
+ };
1393
+ }, [hsv]);
1394
+ const getIndicatorStyles = () => {
1395
+ var _containerRef$current3, _containerRef$current4, _containerRef$current5, _containerRef$current6;
1396
+ const halfIndicatorSize = 16 / 2;
1397
+ const w = (_containerRef$current3 = (_containerRef$current4 = containerRef.current) === null || _containerRef$current4 === void 0 ? void 0 : _containerRef$current4.clientWidth) !== null && _containerRef$current3 !== void 0 ? _containerRef$current3 : 0;
1398
+ const h = (_containerRef$current5 = (_containerRef$current6 = containerRef.current) === null || _containerRef$current6 === void 0 ? void 0 : _containerRef$current6.clientHeight) !== null && _containerRef$current5 !== void 0 ? _containerRef$current5 : 0;
1399
+ return {
1400
+ transform: `translate(${hsv[1] / 100 * w - halfIndicatorSize}px, ${(100 - hsv[2]) / 100 * h - halfIndicatorSize}px)`,
1401
+ transition: isDragging ? "none" : "transform 0.1s ease-out"
1402
+ };
1403
+ };
1404
+ (0, react.useEffect)(() => {
1405
+ const handlePointerUp = () => {
1406
+ setIsDragging(false);
1407
+ };
1408
+ window.addEventListener("pointerup", handlePointerUp);
1409
+ window.addEventListener("mouseup", handlePointerUp);
1410
+ return () => {
1411
+ window.removeEventListener("pointerup", handlePointerUp);
1412
+ window.removeEventListener("mouseup", handlePointerUp);
1413
+ };
1414
+ }, []);
1415
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1416
+ "data-u-comp": "color-picker-spectrum",
1417
+ ref: containerRef,
1418
+ className: "univer-relative univer-overflow-hidden",
1419
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("canvas", {
1420
+ ref: canvasRef,
1421
+ className: "univer-size-full univer-cursor-crosshair univer-rounded",
1422
+ onPointerDown: (e) => {
1423
+ setIsDragging(true);
1424
+ handlePointerEvent(e);
1425
+ },
1426
+ onPointerMove: (e) => isDragging && handlePointerEvent(e)
1427
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1428
+ className: "univer-pointer-events-none univer-absolute univer-left-0 univer-top-0 univer-size-4 univer-rounded-full univer-border-2 univer-border-white univer-shadow-md univer-ring-2 univer-ring-white univer-will-change-transform",
1429
+ style: getIndicatorStyles()
1430
+ })]
1431
+ });
1432
+ }
1433
+
1434
+ //#endregion
1435
+ //#region src/components/color-picker/HueSlider.tsx
1436
+ /**
1437
+ * Copyright 2023-present DreamNum Co., Ltd.
1438
+ *
1439
+ * Licensed under the Apache License, Version 2.0 (the "License");
1440
+ * you may not use this file except in compliance with the License.
1441
+ * You may obtain a copy of the License at
1442
+ *
1443
+ * http://www.apache.org/licenses/LICENSE-2.0
1444
+ *
1445
+ * Unless required by applicable law or agreed to in writing, software
1446
+ * distributed under the License is distributed on an "AS IS" BASIS,
1447
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1448
+ * See the License for the specific language governing permissions and
1449
+ * limitations under the License.
1450
+ */
1451
+ function HueSlider({ hsv, onChange, onChanged }) {
1452
+ const [isDragging, setIsDragging] = (0, react.useState)(false);
1453
+ const sliderRef = (0, react.useRef)(null);
1454
+ const thumbRef = (0, react.useRef)(null);
1455
+ const calculateHue = (0, react.useCallback)((clientX) => {
1456
+ var _thumbRef$current$cli, _thumbRef$current;
1457
+ const slider = sliderRef.current;
1458
+ if (!slider) return;
1459
+ const thumbSize = (_thumbRef$current$cli = (_thumbRef$current = thumbRef.current) === null || _thumbRef$current === void 0 ? void 0 : _thumbRef$current.clientWidth) !== null && _thumbRef$current$cli !== void 0 ? _thumbRef$current$cli : 0;
1460
+ const rect = slider.getBoundingClientRect();
1461
+ const maxX = rect.width - thumbSize;
1462
+ if (maxX <= 0) {
1463
+ onChange(0, hsv[1], hsv[2]);
1464
+ return;
1465
+ }
1466
+ const x = Math.max(0, Math.min(clientX - rect.left, maxX));
1467
+ onChange(Math.round(x / maxX * 360), hsv[1], hsv[2]);
1468
+ }, [hsv, onChange]);
1469
+ const handlePointerMove = (0, react.useCallback)((e) => {
1470
+ e.stopPropagation();
1471
+ if (!isDragging) return;
1472
+ calculateHue(e.clientX);
1473
+ }, [isDragging, calculateHue]);
1474
+ const handlePointerUp = (0, react.useCallback)(() => {
1475
+ setIsDragging(false);
1476
+ onChanged === null || onChanged === void 0 || onChanged(hsv[0], hsv[1], hsv[2]);
1477
+ }, [hsv, onChanged]);
1478
+ (0, react.useEffect)(() => {
1479
+ if (isDragging) {
1480
+ window.addEventListener("pointermove", handlePointerMove);
1481
+ window.addEventListener("pointerup", handlePointerUp);
1482
+ window.addEventListener("mouseup", handlePointerUp);
1483
+ }
1484
+ return () => {
1485
+ window.removeEventListener("pointermove", handlePointerMove);
1486
+ window.removeEventListener("pointerup", handlePointerUp);
1487
+ window.removeEventListener("mouseup", handlePointerUp);
1488
+ };
1489
+ }, [
1490
+ isDragging,
1491
+ handlePointerMove,
1492
+ handlePointerUp
1493
+ ]);
1494
+ const getThumbPosition = () => {
1495
+ var _thumbRef$current$cli2, _thumbRef$current2, _sliderRef$current$cl, _sliderRef$current;
1496
+ const safeHue = Math.min(Math.max(hsv[0], 0), 360);
1497
+ const thumbSize = (_thumbRef$current$cli2 = (_thumbRef$current2 = thumbRef.current) === null || _thumbRef$current2 === void 0 ? void 0 : _thumbRef$current2.clientWidth) !== null && _thumbRef$current$cli2 !== void 0 ? _thumbRef$current$cli2 : 0;
1498
+ const sliderWidth = (_sliderRef$current$cl = (_sliderRef$current = sliderRef.current) === null || _sliderRef$current === void 0 ? void 0 : _sliderRef$current.clientWidth) !== null && _sliderRef$current$cl !== void 0 ? _sliderRef$current$cl : 0;
1499
+ const thumbOffsetPercent = sliderWidth > 0 ? thumbSize / sliderWidth * 100 : 0;
1500
+ return `${safeHue / 360 * (100 - thumbOffsetPercent)}%`;
1501
+ };
1502
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1503
+ "data-u-comp": "color-picker-hue-slider",
1504
+ className: "univer-relative univer-w-full univer-select-none",
1505
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1506
+ ref: sliderRef,
1507
+ className: "univer-relative univer-h-2 univer-w-full univer-cursor-pointer univer-rounded-full univer-shadow-inner",
1508
+ style: { background: `linear-gradient(to right,
45
1509
  hsl(0, 100%, 50%),
46
1510
  hsl(60, 100%, 50%),
47
1511
  hsl(120, 100%, 50%),
48
1512
  hsl(180, 100%, 50%),
49
1513
  hsl(240, 100%, 50%),
50
1514
  hsl(300, 100%, 50%),
51
- hsl(360, 100%, 50%))`},onPointerDown:e=>{o(!0),l(e.clientX)},children:(0,i.jsx)(`div`,{ref:c,className:`univer-absolute univer-top-1/2 univer-box-border univer-size-2 univer-rounded-full univer-bg-transparent univer-shadow-md univer-ring-2 univer-ring-white univer-transition-transform univer-duration-75 univer-will-change-transform`,style:{left:f(),transform:`translateY(-50%)`,transition:a?`none`:`all 0.1s ease-out`}})})})}const we=(0,t.memo)(Se),Te=(0,t.memo)(Ce),Ee=(0,t.memo)(ge),De=(0,t.memo)(ye),Oe=(0,t.memo)(xe);function ke({format:e=`hex`,value:n,onChange:r}){if(!w)return null;let{locale:a}=(0,t.useContext)(T),[o,s]=(0,t.useState)([0,100,100]),[c,l]=(0,t.useState)(1),[u,d]=(0,t.useState)(!1),f=(0,t.useCallback)((e,t,n)=>W(e,t,n),[]);(0,t.useEffect)(()=>{try{let t=n||(e===`hex`?`#000000`:`rgba(0, 0, 0, 1)`);if(e===`hex`){let[e,n,r]=K(t);s([e,n,r]),l(1)}else if(e===`rgba`){let[e,n,r,i]=he(t),[a,o,c]=G(e,n,r);s([a,o,c]),l(i)}}catch(e){console.error(`Invalid value:`,e)}},[n,e]);function p(e,t,n){s([e,t,n])}function m(e){l(e)}function h(t,n,i,a=c){if(e===`hex`){let[e,a,o]=f(t,n,i),s=pe(e,a,o);r==null||r(s)}else if(e===`rgba`){let[e,o,s]=f(t,n,i);r==null||r(`rgba(${e}, ${o}, ${s}, ${a})`)}}function g(){let[t,n,i]=o;if(e===`hex`){let e=q(t,n,i);r==null||r(e)}else if(e===`rgba`){let[e,a,o]=f(t,n,i);r==null||r(`rgba(${e}, ${a}, ${o}, ${c})`)}d(!1)}return(0,i.jsxs)(`div`,{"data-u-comp":`color-picker`,className:`univer-cursor-default univer-space-y-2 univer-rounded-lg`,onClick:e=>e.stopPropagation(),children:[(0,i.jsx)(Oe,{hsv:o,onChange:(e,t,n)=>{p(e,t,n),m(1),h(e,t,n,1)}}),(0,i.jsx)(`div`,{className:`univer-flex univer-h-7 univer-items-center`,children:(0,i.jsx)(`a`,{className:`univer-cursor-pointer univer-gap-2 univer-text-sm univer-text-gray-900 univer-transition-opacity hover:univer-opacity-80 dark:!univer-text-white`,onClick:()=>d(!0),children:a==null?void 0:a.ColorPicker.more})}),(0,i.jsx)(U,{className:`!univer-w-fit !univer-p-2.5`,closable:!1,maskClosable:!1,open:u,onOpenChange:d,children:(0,i.jsxs)(`div`,{className:`univer-grid univer-w-64 univer-gap-2`,children:[(0,i.jsx)(we,{hsv:o,onChange:p}),(0,i.jsxs)(`div`,{className:`univer-flex univer-items-center univer-gap-2`,children:[(0,i.jsx)(`div`,{className:`univer-size-6 univer-flex-shrink-0 univer-rounded-sm`,style:{backgroundColor:e===`hex`?q(...o):me(...o,c)}}),(0,i.jsxs)(`div`,{className:`univer-flex-1 univer-space-y-2`,children:[(0,i.jsx)(Te,{hsv:o,onChange:p}),e===`rgba`&&(0,i.jsx)(Ee,{hsv:o,alpha:c,onChange:m})]})]}),(0,i.jsx)(De,{hsv:o,alpha:c,format:e,onChange:(e,t,n,r)=>{p(e,t,n),r!==void 0&&m(r)}}),(0,i.jsxs)(`footer`,{className:`univer-flex univer-items-center univer-justify-end univer-gap-2`,children:[(0,i.jsx)(S,{onClick:()=>d(!1),children:a==null?void 0:a.ColorPicker.cancel}),(0,i.jsx)(S,{variant:`primary`,onClick:g,children:a==null?void 0:a.ColorPicker.confirm})]})]})})]})}function Ae(e){let{locale:t,cancelText:n,confirmText:r,onClose:a,onConfirm:o,closable:s=!0}=e;return(0,i.jsxs)(`footer`,{className:`univer-flex univer-items-center univer-justify-end univer-gap-2`,children:[s&&(0,i.jsx)(S,{onClick:a,children:n==null?t==null?void 0:t.Confirm.cancel:n}),(0,i.jsx)(S,{variant:`primary`,onClick:o,children:r==null?t==null?void 0:t.Confirm.confirm:r})]})}function je(e){let{children:n,visible:r=!1,title:a,cancelText:o,confirmText:s,width:c,onClose:l,onConfirm:u,closable:d=!0}=e,{locale:f}=(0,t.useContext)(T);return(0,i.jsx)(U,{open:r,title:a,maskClosable:!1,footer:(0,i.jsx)(Ae,{locale:f,cancelText:o,confirmText:s,onClose:l,onConfirm:u,closable:d}),onClose:l,width:c,closable:d,children:n})}function Me({...e}){return(0,i.jsx)(c.Root,{"data-slot":`popover`,...e})}function Ne({...e}){return(0,i.jsx)(c.Trigger,{"data-slot":`popover-trigger`,...e})}function Pe({className:e,align:t=`center`,sideOffset:n=4,...r}){return(0,i.jsx)(c.Portal,{children:(0,i.jsx)(c.Content,{"data-slot":`popover-content`,align:t,sideOffset:n,className:g(`univer-outline-hidden data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-max-h-[--radix-popper-available-height] univer-overflow-y-auto univer-rounded-md univer-bg-white univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-900 dark:!univer-text-white dark:focus-visible:!univer-border-gray-600`,k,D,e),...r})})}function Fe(e){let{children:n,overlay:r,disabled:a,open:o,onOpenChange:s,...c}=e,[l,u]=(0,t.useState)(!1),d=o!==void 0,f=d?o:l;function p(e){a||(d||u(e),s==null||s(e))}return(0,i.jsxs)(Me,{open:f,onOpenChange:p,children:[(0,i.jsx)(Ne,{asChild:!0,children:n}),(0,i.jsx)(Pe,{...c,children:r})]})}function Ie(n){let{value:r,onValueChange:a,className:o}=n,[s,c]=(0,t.useState)(!1);function l(e){a==null||a(e),c(!1)}return(0,i.jsx)(Fe,{align:`start`,overlay:(0,i.jsx)(`div`,{className:`univer-p-2`,children:(0,i.jsx)(V,{value:r,onValueChange:l})}),open:s,onOpenChange:c,children:(0,i.jsxs)(`button`,{className:g(`univer-flex univer-h-8 univer-items-center univer-justify-between univer-gap-2 univer-rounded-md univer-bg-transparent univer-px-2 univer-text-sm univer-text-gray-800 univer-transition-all hover:univer-border-primary-600 dark:!univer-text-white`,k,o),type:`button`,children:[L(r,`YYYY-MM-DD`),(0,i.jsx)(e.CalendarIcon,{className:`univer-text-gray-600 dark:!univer-text-gray-400`})]})})}function Le(n){let{value:r=[new Date,new Date],onValueChange:a,className:o}=n,[s,c]=(0,t.useState)(!1);function l(e){let[t,n]=e;t>n&&([t,n]=[n,t]),a==null||a([t,n]),c(!1)}return(0,i.jsx)(Fe,{align:`start`,overlay:(0,i.jsxs)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2 univer-p-2`,children:[(0,i.jsx)(V,{value:r[0],max:r[1],onValueChange:e=>{l([e,r[1]])}}),(0,i.jsx)(V,{value:r[1],min:r[0],onValueChange:e=>{l([r[0],e])}})]}),open:s,onOpenChange:c,children:(0,i.jsxs)(`button`,{className:g(`univer-flex univer-h-8 univer-items-center univer-justify-between univer-gap-2 univer-rounded-md univer-bg-transparent univer-px-2 univer-text-sm univer-text-gray-800 univer-transition-all hover:univer-border-primary-600 dark:!univer-text-white`,k,o),type:`button`,children:[(0,i.jsxs)(`span`,{className:`univer-flex univer-gap-1`,children:[(0,i.jsx)(`span`,{children:L(r[0],`YYYY-MM-DD`)}),(0,i.jsx)(`span`,{children:`-`}),(0,i.jsx)(`span`,{children:L(r[1],`YYYY-MM-DD`)})]}),(0,i.jsx)(e.CalendarIcon,{className:`univer-text-gray-600 dark:!univer-text-gray-400`})]})})}function Re(e,t,n){if(t===n||t<0||n<0||t>=e.length||n>=e.length)return e;let r=[...e],[i]=r.splice(t,1);return r.splice(n,0,i),r}function ze(e){let{list:n,onListChange:r,idKey:a,itemRender:o,className:s,style:c,draggableHandle:u,rowHeight:d,margin:f=[0,0],onDragStart:p,onDragStop:m,...h}=e,[_,v]=(0,t.useState)(n),y=(0,t.useRef)(n),[b,x]=(0,t.useState)(null),[S,C]=(0,t.useState)(null),[w,T]=(0,t.useState)(null),[E,D]=(0,t.useState)(null),[O,k]=(0,t.useState)(!1),A=(0,t.useRef)(null),j=(0,t.useRef)({x:0,y:0}),M=(0,t.useRef)({width:0,height:0}),N=(0,t.useRef)(null),P=(0,t.useRef)(null),F=(0,t.useRef)(null),I=(0,t.useRef)(-1);(0,t.useEffect)(()=>{b||(v(n),y.current=n)},[b,n]),(0,t.useEffect)(()=>{k(typeof document<`u`)},[]),(0,t.useEffect)(()=>{let e=N.current;e&&(e.replaceChildren(),w&&e.appendChild(w))},[w]),(0,t.useEffect)(()=>{if(!b)return;let e=e=>{let t=F.current;if(!t||A.current!==e.pointerId)return;D({x:e.clientX-j.current.x,y:e.clientY-j.current.y});let n=document.elementFromPoint(e.clientX,e.clientY),r=n==null?void 0:n.closest(`[data-draggable-list-item-id]`),i=r==null?void 0:r.dataset.draggableListItemId;!i||i===t||(C(i),v(e=>{let n=e.findIndex(e=>R(e)===t),r=e.findIndex(e=>R(e)===i);if(n<0||r<0||n===r)return e;let a=Re(e,n,r);return y.current=a,a}))},t=e=>{if(A.current!==e.pointerId)return;let t=F.current,n=I.current,i=y.current;if(t){let e=i.findIndex(e=>R(e)===t);m==null||m(void 0,{y:n},{y:e}),n>=0&&r([...i])}A.current=null,P.current=null,F.current=null,I.current=-1,C(null),T(null),D(null),x(null)};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t),window.addEventListener(`pointercancel`,t),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t),window.removeEventListener(`pointercancel`,t)}},[b,m,r]);let L=(0,t.useMemo)(()=>{let[e,t]=f;return{rowGap:`${t}px`,paddingLeft:e?`${e}px`:void 0,paddingRight:e?`${e}px`:void 0,...c}},[f,c]),R=e=>String(e[a]),z=b?_.find(e=>R(e)===b):null;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{...h,className:g(`univer-flex univer-flex-col`,b&&`univer-cursor-grabbing univer-select-none`,s),style:L,children:_.map((e,t)=>{let n=R(e),r=b===n,a=S===n&&!r;return(0,i.jsxs)(`div`,{"data-draggable-list-item-id":n,className:g(`univer-relative univer-transition-all univer-duration-150`,r&&`univer-opacity-0`,a&&`
1515
+ hsl(360, 100%, 50%))` },
1516
+ onPointerDown: (e) => {
1517
+ setIsDragging(true);
1518
+ calculateHue(e.clientX);
1519
+ },
1520
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1521
+ ref: thumbRef,
1522
+ className: "univer-absolute univer-top-1/2 univer-box-border univer-size-2 univer-rounded-full univer-bg-transparent univer-shadow-md univer-ring-2 univer-ring-white univer-transition-transform univer-duration-75 univer-will-change-transform",
1523
+ style: {
1524
+ left: getThumbPosition(),
1525
+ transform: "translateY(-50%)",
1526
+ transition: isDragging ? "none" : "all 0.1s ease-out"
1527
+ }
1528
+ })
1529
+ })
1530
+ });
1531
+ }
1532
+
1533
+ //#endregion
1534
+ //#region src/components/color-picker/ColorPicker.tsx
1535
+ /**
1536
+ * Copyright 2023-present DreamNum Co., Ltd.
1537
+ *
1538
+ * Licensed under the Apache License, Version 2.0 (the "License");
1539
+ * you may not use this file except in compliance with the License.
1540
+ * You may obtain a copy of the License at
1541
+ *
1542
+ * http://www.apache.org/licenses/LICENSE-2.0
1543
+ *
1544
+ * Unless required by applicable law or agreed to in writing, software
1545
+ * distributed under the License is distributed on an "AS IS" BASIS,
1546
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1547
+ * See the License for the specific language governing permissions and
1548
+ * limitations under the License.
1549
+ */
1550
+ const MemoizedColorSpectrum = (0, react.memo)(ColorSpectrum);
1551
+ const MemoizedHueSlider = (0, react.memo)(HueSlider);
1552
+ const MemoizedAlphaSlider = (0, react.memo)(AlphaSlider);
1553
+ const MemoizedColorInput = (0, react.memo)(ColorInput);
1554
+ const MemoizedColorPresets = (0, react.memo)(ColorPresets);
1555
+ function ColorPicker({ format = "hex", value, onChange }) {
1556
+ if (!isBrowser) return null;
1557
+ const { locale } = (0, react.useContext)(ConfigContext);
1558
+ const [hsv, setHsv] = (0, react.useState)([
1559
+ 0,
1560
+ 100,
1561
+ 100
1562
+ ]);
1563
+ const [alpha, setAlpha] = (0, react.useState)(1);
1564
+ const [visible, setVisible] = (0, react.useState)(false);
1565
+ const getRgb = (0, react.useCallback)((h, s, v) => {
1566
+ return hsvToRgb(h, s, v);
1567
+ }, []);
1568
+ (0, react.useEffect)(() => {
1569
+ try {
1570
+ const actualValue = value || (format === "hex" ? "#000000" : "rgba(0, 0, 0, 1)");
1571
+ if (format === "hex") {
1572
+ const [h, s, v] = hexToHsv(actualValue);
1573
+ setHsv([
1574
+ h,
1575
+ s,
1576
+ v
1577
+ ]);
1578
+ setAlpha(1);
1579
+ } else if (format === "rgba") {
1580
+ const [r, g, b, a] = parseRgba(actualValue);
1581
+ const [h, s, v] = rgbToHsv(r, g, b);
1582
+ setHsv([
1583
+ h,
1584
+ s,
1585
+ v
1586
+ ]);
1587
+ setAlpha(a);
1588
+ }
1589
+ } catch (error) {
1590
+ console.error("Invalid value:", error);
1591
+ }
1592
+ }, [value, format]);
1593
+ function handleColorChange(h, s, v) {
1594
+ setHsv([
1595
+ h,
1596
+ s,
1597
+ v
1598
+ ]);
1599
+ }
1600
+ function handleAlphaChange(a) {
1601
+ setAlpha(a);
1602
+ }
1603
+ function handleColorChanged(h, s, v, a = alpha) {
1604
+ if (format === "hex") {
1605
+ const [r, g, b] = getRgb(h, s, v);
1606
+ const hex = rgbToHex(r, g, b);
1607
+ onChange === null || onChange === void 0 || onChange(hex);
1608
+ } else if (format === "rgba") {
1609
+ const [r, g, b] = getRgb(h, s, v);
1610
+ onChange === null || onChange === void 0 || onChange(`rgba(${r}, ${g}, ${b}, ${a})`);
1611
+ }
1612
+ }
1613
+ function handleConfirmCustomColor() {
1614
+ const [h, s, v] = hsv;
1615
+ if (format === "hex") {
1616
+ const hex = hsvToHex(h, s, v);
1617
+ onChange === null || onChange === void 0 || onChange(hex);
1618
+ } else if (format === "rgba") {
1619
+ const [r, g, b] = getRgb(h, s, v);
1620
+ onChange === null || onChange === void 0 || onChange(`rgba(${r}, ${g}, ${b}, ${alpha})`);
1621
+ }
1622
+ setVisible(false);
1623
+ }
1624
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1625
+ "data-u-comp": "color-picker",
1626
+ className: "univer-cursor-default univer-space-y-2 univer-rounded-lg",
1627
+ onClick: (e) => e.stopPropagation(),
1628
+ children: [
1629
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoizedColorPresets, {
1630
+ hsv,
1631
+ onChange: (h, s, v) => {
1632
+ handleColorChange(h, s, v);
1633
+ handleAlphaChange(1);
1634
+ handleColorChanged(h, s, v, 1);
1635
+ }
1636
+ }),
1637
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1638
+ className: "univer-flex univer-h-7 univer-items-center",
1639
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
1640
+ className: "univer-cursor-pointer univer-gap-2 univer-text-sm univer-text-gray-900 univer-transition-opacity hover:univer-opacity-80 dark:!univer-text-white",
1641
+ onClick: () => setVisible(true),
1642
+ children: locale === null || locale === void 0 ? void 0 : locale.ColorPicker.more
1643
+ })
1644
+ }),
1645
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Dialog, {
1646
+ className: "!univer-w-fit !univer-p-2.5",
1647
+ closable: false,
1648
+ maskClosable: false,
1649
+ open: visible,
1650
+ onOpenChange: setVisible,
1651
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1652
+ className: "univer-grid univer-w-64 univer-gap-2",
1653
+ children: [
1654
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoizedColorSpectrum, {
1655
+ hsv,
1656
+ onChange: handleColorChange
1657
+ }),
1658
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1659
+ className: "univer-flex univer-items-center univer-gap-2",
1660
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1661
+ className: "univer-size-6 univer-flex-shrink-0 univer-rounded-sm",
1662
+ style: { backgroundColor: format === "hex" ? hsvToHex(...hsv) : hsvToRgba(...hsv, alpha) }
1663
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1664
+ className: "univer-flex-1 univer-space-y-2",
1665
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoizedHueSlider, {
1666
+ hsv,
1667
+ onChange: handleColorChange
1668
+ }), format === "rgba" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoizedAlphaSlider, {
1669
+ hsv,
1670
+ alpha,
1671
+ onChange: handleAlphaChange
1672
+ })]
1673
+ })]
1674
+ }),
1675
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoizedColorInput, {
1676
+ hsv,
1677
+ alpha,
1678
+ format,
1679
+ onChange: (h, s, v, a) => {
1680
+ handleColorChange(h, s, v);
1681
+ if (a !== void 0) handleAlphaChange(a);
1682
+ }
1683
+ }),
1684
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("footer", {
1685
+ className: "univer-flex univer-items-center univer-justify-end univer-gap-2",
1686
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
1687
+ onClick: () => setVisible(false),
1688
+ children: locale === null || locale === void 0 ? void 0 : locale.ColorPicker.cancel
1689
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
1690
+ variant: "primary",
1691
+ onClick: handleConfirmCustomColor,
1692
+ children: locale === null || locale === void 0 ? void 0 : locale.ColorPicker.confirm
1693
+ })]
1694
+ })
1695
+ ]
1696
+ })
1697
+ })
1698
+ ]
1699
+ });
1700
+ }
1701
+
1702
+ //#endregion
1703
+ //#region src/components/confirm/Confirm.tsx
1704
+ function Footer(props) {
1705
+ const { locale, cancelText, confirmText, onClose, onConfirm, closable = true } = props;
1706
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("footer", {
1707
+ className: "univer-flex univer-items-center univer-justify-end univer-gap-2",
1708
+ children: [closable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
1709
+ onClick: onClose,
1710
+ children: cancelText !== null && cancelText !== void 0 ? cancelText : locale === null || locale === void 0 ? void 0 : locale.Confirm.cancel
1711
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
1712
+ variant: "primary",
1713
+ onClick: onConfirm,
1714
+ children: confirmText !== null && confirmText !== void 0 ? confirmText : locale === null || locale === void 0 ? void 0 : locale.Confirm.confirm
1715
+ })]
1716
+ });
1717
+ }
1718
+ function Confirm(props) {
1719
+ const { children, visible = false, title, cancelText, confirmText, width, onClose, onConfirm, closable = true } = props;
1720
+ const { locale } = (0, react.useContext)(ConfigContext);
1721
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Dialog, {
1722
+ open: visible,
1723
+ title,
1724
+ maskClosable: false,
1725
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Footer, {
1726
+ locale,
1727
+ cancelText,
1728
+ confirmText,
1729
+ onClose,
1730
+ onConfirm,
1731
+ closable
1732
+ }),
1733
+ onClose,
1734
+ width,
1735
+ closable,
1736
+ children
1737
+ });
1738
+ }
1739
+
1740
+ //#endregion
1741
+ //#region src/components/dropdown/PopoverPrimitive.tsx
1742
+ function PopoverPrimitive({ ...props }) {
1743
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_popover.Root, {
1744
+ "data-slot": "popover",
1745
+ ...props
1746
+ });
1747
+ }
1748
+ function PopoverTrigger({ ...props }) {
1749
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_popover.Trigger, {
1750
+ "data-slot": "popover-trigger",
1751
+ ...props
1752
+ });
1753
+ }
1754
+ function PopoverContent({ className, align = "center", sideOffset = 4, ...props }) {
1755
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_popover.Portal, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_popover.Content, {
1756
+ "data-slot": "popover-content",
1757
+ align,
1758
+ sideOffset,
1759
+ className: clsx$1("univer-outline-hidden data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-max-h-[--radix-popper-available-height] univer-overflow-y-auto univer-rounded-md univer-bg-white univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-900 dark:!univer-text-white dark:focus-visible:!univer-border-gray-600", borderClassName, scrollbarClassName, className),
1760
+ ...props
1761
+ }) });
1762
+ }
1763
+
1764
+ //#endregion
1765
+ //#region src/components/dropdown/Dropdown.tsx
1766
+ function Dropdown(props) {
1767
+ const { children, overlay, disabled, open: controlledOpen, onOpenChange: controlledOnOpenChange, ...restProps } = props;
1768
+ const [uncontrolledOpen, setUncontrolledOpen] = (0, react.useState)(false);
1769
+ const isControlled = controlledOpen !== void 0;
1770
+ const open = isControlled ? controlledOpen : uncontrolledOpen;
1771
+ function handleChangeOpen(newOpen) {
1772
+ if (disabled) return;
1773
+ if (!isControlled) setUncontrolledOpen(newOpen);
1774
+ controlledOnOpenChange === null || controlledOnOpenChange === void 0 || controlledOnOpenChange(newOpen);
1775
+ }
1776
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(PopoverPrimitive, {
1777
+ open,
1778
+ onOpenChange: handleChangeOpen,
1779
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(PopoverTrigger, {
1780
+ asChild: true,
1781
+ children
1782
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PopoverContent, {
1783
+ ...restProps,
1784
+ children: overlay
1785
+ })]
1786
+ });
1787
+ }
1788
+
1789
+ //#endregion
1790
+ //#region src/components/date-picker/DatePicker.tsx
1791
+ /**
1792
+ * Copyright 2023-present DreamNum Co., Ltd.
1793
+ *
1794
+ * Licensed under the Apache License, Version 2.0 (the "License");
1795
+ * you may not use this file except in compliance with the License.
1796
+ * You may obtain a copy of the License at
1797
+ *
1798
+ * http://www.apache.org/licenses/LICENSE-2.0
1799
+ *
1800
+ * Unless required by applicable law or agreed to in writing, software
1801
+ * distributed under the License is distributed on an "AS IS" BASIS,
1802
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1803
+ * See the License for the specific language governing permissions and
1804
+ * limitations under the License.
1805
+ */
1806
+ function DatePicker(props) {
1807
+ const { value, onValueChange, className } = props;
1808
+ const [open, setOpen] = (0, react.useState)(false);
1809
+ function handleValueChange(date) {
1810
+ onValueChange === null || onValueChange === void 0 || onValueChange(date);
1811
+ setOpen(false);
1812
+ }
1813
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Dropdown, {
1814
+ align: "start",
1815
+ overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1816
+ className: "univer-p-2",
1817
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Calendar, {
1818
+ value,
1819
+ onValueChange: handleValueChange
1820
+ })
1821
+ }),
1822
+ open,
1823
+ onOpenChange: setOpen,
1824
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1825
+ className: clsx$1("univer-flex univer-h-8 univer-items-center univer-justify-between univer-gap-2 univer-rounded-md univer-bg-transparent univer-px-2 univer-text-sm univer-text-gray-800 univer-transition-all hover:univer-border-primary-600 dark:!univer-text-white", borderClassName, className),
1826
+ type: "button",
1827
+ children: [formatDateWithPattern(value, "YYYY-MM-DD"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CalendarIcon, { className: "univer-text-gray-600 dark:!univer-text-gray-400" })]
1828
+ })
1829
+ });
1830
+ }
1831
+
1832
+ //#endregion
1833
+ //#region src/components/date-range-picker/DateRangePicker.tsx
1834
+ /**
1835
+ * Copyright 2023-present DreamNum Co., Ltd.
1836
+ *
1837
+ * Licensed under the Apache License, Version 2.0 (the "License");
1838
+ * you may not use this file except in compliance with the License.
1839
+ * You may obtain a copy of the License at
1840
+ *
1841
+ * http://www.apache.org/licenses/LICENSE-2.0
1842
+ *
1843
+ * Unless required by applicable law or agreed to in writing, software
1844
+ * distributed under the License is distributed on an "AS IS" BASIS,
1845
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1846
+ * See the License for the specific language governing permissions and
1847
+ * limitations under the License.
1848
+ */
1849
+ function DateRangePicker(props) {
1850
+ const { value = [/* @__PURE__ */ new Date(), /* @__PURE__ */ new Date()], onValueChange, className } = props;
1851
+ const [open, setOpen] = (0, react.useState)(false);
1852
+ function handleValueChange(date) {
1853
+ let [start, end] = date;
1854
+ if (start > end) [start, end] = [end, start];
1855
+ onValueChange === null || onValueChange === void 0 || onValueChange([start, end]);
1856
+ setOpen(false);
1857
+ }
1858
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Dropdown, {
1859
+ align: "start",
1860
+ overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1861
+ className: "univer-grid univer-grid-cols-2 univer-gap-2 univer-p-2",
1862
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Calendar, {
1863
+ value: value[0],
1864
+ max: value[1],
1865
+ onValueChange: (date) => {
1866
+ handleValueChange([date, value[1]]);
1867
+ }
1868
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Calendar, {
1869
+ value: value[1],
1870
+ min: value[0],
1871
+ onValueChange: (date) => {
1872
+ handleValueChange([value[0], date]);
1873
+ }
1874
+ })]
1875
+ }),
1876
+ open,
1877
+ onOpenChange: setOpen,
1878
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1879
+ className: clsx$1("univer-flex univer-h-8 univer-items-center univer-justify-between univer-gap-2 univer-rounded-md univer-bg-transparent univer-px-2 univer-text-sm univer-text-gray-800 univer-transition-all hover:univer-border-primary-600 dark:!univer-text-white", borderClassName, className),
1880
+ type: "button",
1881
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1882
+ className: "univer-flex univer-gap-1",
1883
+ children: [
1884
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: formatDateWithPattern(value[0], "YYYY-MM-DD") }),
1885
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "-" }),
1886
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: formatDateWithPattern(value[1], "YYYY-MM-DD") })
1887
+ ]
1888
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CalendarIcon, { className: "univer-text-gray-600 dark:!univer-text-gray-400" })]
1889
+ })
1890
+ });
1891
+ }
1892
+
1893
+ //#endregion
1894
+ //#region src/components/draggable-list/DraggableList.tsx
1895
+ function moveItemByIndex(list, fromIndex, toIndex) {
1896
+ if (fromIndex === toIndex || fromIndex < 0 || toIndex < 0 || fromIndex >= list.length || toIndex >= list.length) return list;
1897
+ const next = [...list];
1898
+ const [item] = next.splice(fromIndex, 1);
1899
+ next.splice(toIndex, 0, item);
1900
+ return next;
1901
+ }
1902
+ function DraggableList(props) {
1903
+ const { list, onListChange, idKey, itemRender, className, style, draggableHandle, rowHeight, margin = [0, 0], onDragStart, onDragStop, ...restProps } = props;
1904
+ const [displayList, setDisplayList] = (0, react.useState)(list);
1905
+ const displayListRef = (0, react.useRef)(list);
1906
+ const [draggingId, setDraggingId] = (0, react.useState)(null);
1907
+ const [dragOverId, setDragOverId] = (0, react.useState)(null);
1908
+ const [ghostElement, setGhostElement] = (0, react.useState)(null);
1909
+ const [ghostPosition, setGhostPosition] = (0, react.useState)(null);
1910
+ const [canUsePortal, setCanUsePortal] = (0, react.useState)(false);
1911
+ const pointerIdRef = (0, react.useRef)(null);
1912
+ const dragPointerOffsetRef = (0, react.useRef)({
1913
+ x: 0,
1914
+ y: 0
1915
+ });
1916
+ const dragItemSizeRef = (0, react.useRef)({
1917
+ width: 0,
1918
+ height: 0
1919
+ });
1920
+ const ghostContainerRef = (0, react.useRef)(null);
1921
+ const pressedHandleIdRef = (0, react.useRef)(null);
1922
+ const dragSourceIdRef = (0, react.useRef)(null);
1923
+ const dragStartIndexRef = (0, react.useRef)(-1);
1924
+ (0, react.useEffect)(() => {
1925
+ if (!draggingId) {
1926
+ setDisplayList(list);
1927
+ displayListRef.current = list;
1928
+ }
1929
+ }, [draggingId, list]);
1930
+ (0, react.useEffect)(() => {
1931
+ setCanUsePortal(typeof document !== "undefined");
1932
+ }, []);
1933
+ (0, react.useEffect)(() => {
1934
+ const container = ghostContainerRef.current;
1935
+ if (!container) return;
1936
+ container.replaceChildren();
1937
+ if (ghostElement) container.appendChild(ghostElement);
1938
+ }, [ghostElement]);
1939
+ (0, react.useEffect)(() => {
1940
+ if (!draggingId) return;
1941
+ const handlePointerMove = (evt) => {
1942
+ const sourceId = dragSourceIdRef.current;
1943
+ if (!sourceId || pointerIdRef.current !== evt.pointerId) return;
1944
+ setGhostPosition({
1945
+ x: evt.clientX - dragPointerOffsetRef.current.x,
1946
+ y: evt.clientY - dragPointerOffsetRef.current.y
1947
+ });
1948
+ const element = document.elementFromPoint(evt.clientX, evt.clientY);
1949
+ const itemElement = element === null || element === void 0 ? void 0 : element.closest("[data-draggable-list-item-id]");
1950
+ const targetId = itemElement === null || itemElement === void 0 ? void 0 : itemElement.dataset.draggableListItemId;
1951
+ if (!targetId || targetId === sourceId) return;
1952
+ setDragOverId(targetId);
1953
+ setDisplayList((prev) => {
1954
+ const fromIndex = prev.findIndex((it) => getItemId(it) === sourceId);
1955
+ const toIndex = prev.findIndex((it) => getItemId(it) === targetId);
1956
+ if (fromIndex < 0 || toIndex < 0 || fromIndex === toIndex) return prev;
1957
+ const next = moveItemByIndex(prev, fromIndex, toIndex);
1958
+ displayListRef.current = next;
1959
+ return next;
1960
+ });
1961
+ };
1962
+ const handlePointerUp = (evt) => {
1963
+ if (pointerIdRef.current !== evt.pointerId) return;
1964
+ const sourceId = dragSourceIdRef.current;
1965
+ const startIndex = dragStartIndexRef.current;
1966
+ const currentList = displayListRef.current;
1967
+ if (sourceId) {
1968
+ const finalIndex = currentList.findIndex((it) => getItemId(it) === sourceId);
1969
+ onDragStop === null || onDragStop === void 0 || onDragStop(void 0, { y: startIndex }, { y: finalIndex });
1970
+ if (startIndex >= 0) onListChange([...currentList]);
1971
+ }
1972
+ pointerIdRef.current = null;
1973
+ pressedHandleIdRef.current = null;
1974
+ dragSourceIdRef.current = null;
1975
+ dragStartIndexRef.current = -1;
1976
+ setDragOverId(null);
1977
+ setGhostElement(null);
1978
+ setGhostPosition(null);
1979
+ setDraggingId(null);
1980
+ };
1981
+ window.addEventListener("pointermove", handlePointerMove);
1982
+ window.addEventListener("pointerup", handlePointerUp);
1983
+ window.addEventListener("pointercancel", handlePointerUp);
1984
+ return () => {
1985
+ window.removeEventListener("pointermove", handlePointerMove);
1986
+ window.removeEventListener("pointerup", handlePointerUp);
1987
+ window.removeEventListener("pointercancel", handlePointerUp);
1988
+ };
1989
+ }, [
1990
+ draggingId,
1991
+ onDragStop,
1992
+ onListChange
1993
+ ]);
1994
+ const gapStyle = (0, react.useMemo)(() => {
1995
+ const [horizontal, vertical] = margin;
1996
+ return {
1997
+ rowGap: `${vertical}px`,
1998
+ paddingLeft: horizontal ? `${horizontal}px` : void 0,
1999
+ paddingRight: horizontal ? `${horizontal}px` : void 0,
2000
+ ...style
2001
+ };
2002
+ }, [margin, style]);
2003
+ const getItemId = (item) => String(item[idKey]);
2004
+ const draggingItem = draggingId ? displayList.find((item) => getItemId(item) === draggingId) : null;
2005
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2006
+ ...restProps,
2007
+ className: clsx$1("univer-flex univer-flex-col", draggingId && "univer-cursor-grabbing univer-select-none", className),
2008
+ style: gapStyle,
2009
+ children: displayList.map((item, index) => {
2010
+ const itemId = getItemId(item);
2011
+ const isDraggingItem = draggingId === itemId;
2012
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2013
+ "data-draggable-list-item-id": itemId,
2014
+ className: clsx$1("univer-relative univer-transition-all univer-duration-150", isDraggingItem && "univer-opacity-0", dragOverId === itemId && !isDraggingItem && `
52
2015
  univer-bg-primary-50/60
53
2016
  dark:!univer-bg-primary-900/20
54
2017
  univer-rounded univer-border univer-border-primary-200
55
2018
  dark:!univer-border-primary-700
56
- `),onPointerDownCapture:e=>{if(A.current!==null||(u?P.current=e.target.closest(u)?n:null:P.current=n,P.current!==n))return;let r=e.currentTarget.getBoundingClientRect();j.current={x:e.clientX-r.left,y:e.clientY-r.top},M.current={width:r.width,height:r.height},D({x:r.left,y:r.top}),T(e.currentTarget.cloneNode(!0)),A.current=e.pointerId,F.current=n,I.current=t,x(n),y.current=_,p==null||p(void 0,{y:t}),e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId)},style:{...d?{minHeight:`${d}px`}:void 0,cursor:b?`grabbing`:void 0},children:[r&&(0,i.jsx)(`div`,{className:`
57
- univer-bg-primary-50/50 univer-absolute univer-inset-0 univer-rounded
58
- univer-border univer-border-dashed univer-border-primary-300
59
- `}),o(e,t)]},n)})}),O&&z&&E&&(0,l.createPortal)((0,i.jsx)(`div`,{className:g(`univer-pointer-events-none univer-fixed univer-rounded-md univer-border univer-border-gray-200 univer-bg-white univer-shadow-lg dark:!univer-border-gray-700 dark:!univer-bg-gray-800`),style:{zIndex:2147483647,left:`${E.x}px`,top:`${E.y}px`,width:`${M.current.width}px`,height:`${M.current.height}px`,opacity:.95},children:w?(0,i.jsx)(`div`,{ref:N}):o(z,_.findIndex(e=>R(e)===R(z)))}),document.body)]})}function Be({...e}){return(0,i.jsx)(u.Root,{"data-slot":`dropdown-menu`,...e})}function Ve({...e}){return(0,i.jsx)(u.Portal,{"data-slot":`dropdown-menu-portal`,...e})}function He({...e}){return(0,i.jsx)(u.Trigger,{"data-slot":`dropdown-menu-trigger`,...e})}function Ue({...e}){return(0,i.jsx)(u.Sub,{"data-slot":`dropdown-menu-sub`,...e})}function We({...e}){return(0,i.jsx)(u.RadioGroup,{"data-slot":`dropdown-menu-radio-group`,...e})}function Ge({className:t,inset:n,children:r,...a}){return(0,i.jsxs)(u.SubTrigger,{"data-slot":`dropdown-menu-sub-trigger`,"data-inset":n,className:g(`univer-flex univer-cursor-default univer-select-none univer-items-center univer-justify-between univer-gap-2 univer-rounded univer-px-2 univer-py-1.5 univer-text-sm univer-outline-none data-[state=open]:univer-bg-gray-100 focus:univer-bg-gray-100 dark:data-[state=open]:!univer-bg-gray-600 dark:focus:!univer-bg-gray-600 [&_svg]:univer-pointer-events-none [&_svg]:univer-size-4 [&_svg]:univer-shrink-0`,t),...a,children:[r,(0,i.jsx)(e.MoreRightIcon,{className:`ml-auto`})]})}function Ke({className:e,...t}){return(0,i.jsx)(u.SubContent,{"data-slot":`dropdown-menu-sub-content`,className:g(`data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-box-border univer-max-h-[--radix-popper-available-height] univer-overflow-y-auto univer-rounded-md univer-bg-white univer-p-1.5 univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-700 dark:!univer-text-white`,k,D,e),...t})}function qe({className:e,sideOffset:t=4,...n}){return(0,i.jsx)(u.Portal,{children:(0,i.jsx)(u.Content,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:g(`data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-box-border univer-max-h-[--radix-popper-available-height] univer-overflow-y-auto univer-rounded-md univer-bg-white univer-p-1.5 univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-700 dark:!univer-text-white`,k,D,e),...n})})}function Je({className:e,inset:t,variant:n=`default`,...r}){return(0,i.jsx)(u.Item,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:g(`univer-relative univer-flex univer-cursor-default univer-select-none univer-items-center univer-gap-2 univer-rounded univer-px-2 univer-py-1.5 univer-text-sm univer-outline-none univer-transition-colors data-[disabled]:univer-pointer-events-none data-[disabled]:univer-opacity-50 focus:univer-bg-gray-100 dark:focus:!univer-bg-gray-600 [&>svg]:univer-size-4 [&>svg]:univer-shrink-0`,e),...r})}function Ye({className:t,children:n,hideIndicator:r,checked:a,...o}){return(0,i.jsxs)(u.CheckboxItem,{"data-slot":`dropdown-menu-checkbox-item`,className:g(`univer-relative univer-flex univer-cursor-default univer-select-none univer-items-center univer-rounded univer-py-1.5 univer-pr-2 univer-text-sm univer-outline-none univer-transition-colors data-[disabled]:univer-pointer-events-none data-[disabled]:univer-opacity-50 focus:univer-bg-gray-100 dark:focus:!univer-bg-gray-600`,{"univer-pl-8":!r,"univer-pl-2":r},t),checked:a,...o,children:[!r&&(0,i.jsx)(`span`,{className:`univer-absolute univer-left-2 univer-flex univer-size-3.5 univer-items-center univer-justify-center`,children:(0,i.jsx)(u.ItemIndicator,{children:(0,i.jsx)(e.CheckMarkIcon,{className:`univer-block univer-size-4 univer-fill-current univer-text-primary-600`})})}),n]})}function Xe({className:t,children:n,hideIndicator:r,...a}){return(0,i.jsxs)(u.RadioItem,{"data-slot":`dropdown-menu-radio-item`,className:g(`univer-relative univer-flex univer-cursor-default univer-select-none univer-items-center univer-rounded univer-py-1.5 univer-pr-2 univer-text-sm univer-outline-none univer-transition-colors data-[disabled]:univer-pointer-events-none data-[disabled]:univer-opacity-50 focus:univer-bg-gray-100 dark:focus:!univer-bg-gray-600`,{"univer-pl-8":!r,"univer-pl-2":r},t),...a,children:[!r&&(0,i.jsx)(`span`,{className:`univer-absolute univer-left-2 univer-flex univer-size-3.5 univer-items-center univer-justify-center`,children:(0,i.jsx)(u.ItemIndicator,{children:(0,i.jsx)(e.CheckMarkIcon,{className:`univer-block univer-size-4 univer-fill-current univer-text-primary-600`})})}),n]})}function Ze({className:e,...t}){return(0,i.jsx)(u.Separator,{className:g(`-univer-mx-1 univer-my-1 univer-h-px univer-bg-gray-200 dark:!univer-bg-gray-600`,e),...t})}function Qe(e){let{children:n,items:r,disabled:a,open:o,onOpenChange:s,...c}=e,[l,u]=(0,t.useState)(!1),d=o!==void 0,f=d?o:l;function p(e){a||(d||u(e),s==null||s(e))}function m(e,t){let{className:n,type:r}=e;if(r===`separator`)return(0,i.jsx)(Ze,{className:n},t);if(r===`radio`)return(0,i.jsx)(We,{className:n,value:e.value,onValueChange:e.onSelect,children:e.options.map((t,n)=>{if(`type`in t){if(t.type===`separator`)return(0,i.jsx)(Ze,{className:t.className},n)}else{if(t.value===void 0)throw Error("[DropdownMenu]: `value` is required");return(0,i.jsx)(Xe,{value:t.value,disabled:t.disabled,hideIndicator:e.hideIndicator,children:t.label},t.value)}return null})},t);if(r===`checkbox`)return(0,i.jsx)(Ye,{className:n,disabled:e.disabled,checked:e.checked,onSelect:()=>{var t;(t=e.onSelect)==null||t.call(e,e.value)},children:e.label},t);if(r===`item`)return(0,i.jsx)(Je,{className:n,disabled:e.disabled,onSelect:()=>{var t;(t=e.onSelect)==null||t.call(e,e)},children:e.children},t);if(r===`subItem`){var a;return(0,i.jsxs)(Ue,{children:[(0,i.jsx)(Ge,{children:e.children}),(0,i.jsx)(Ve,{children:(0,i.jsx)(Ke,{sideOffset:12,children:(a=e.options)==null?void 0:a.map((e,t)=>m(e,t))})})]},t)}}return(0,i.jsxs)(Be,{modal:!1,open:f,onOpenChange:p,children:[(0,i.jsx)(He,{asChild:!0,children:n}),(0,i.jsx)(qe,{className:`univer-text-sm`,collisionPadding:{top:12,bottom:12},onWheel:e=>e.stopPropagation(),...c,children:r.map((e,t)=>m(e,t))})]})}const $e=(0,t.createContext)(!1),et=n=>{let{label:r,desc:a,children:o,style:s,className:c,error:l,contentStyle:u,collapsable:d=!1,defaultCollapsed:f=!1}=n,[p,m]=(0,t.useState)(f);return(0,i.jsx)($e.Provider,{value:!0,children:(0,i.jsxs)(`div`,{"data-u-comp":`form-layout`,className:g(`univer-mb-3 univer-flex univer-flex-col`,c),style:s,children:[r&&(0,i.jsxs)(`div`,{className:g(`univer-mb-2 univer-flex univer-min-h-3.5 univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white`,{"univer-cursor-pointer":d}),onClick:()=>m(!p),children:[r,d&&(0,i.jsx)(e.MoreUpIcon,{className:g(`univer-ml-1 univer-transition-transform`,{"univer-rotate-180":p})})]}),p&&d?null:(0,i.jsxs)(i.Fragment,{children:[a&&(0,i.jsx)(`div`,{className:`univer-mt-1 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200`,children:a}),o?(0,i.jsxs)(`div`,{className:g(`last:univer-mb-0 [&_[data-u-comp=input]]:univer-w-full [&_[data-u-comp=select]]:univer-w-full`,{"[&_[data-u-comp=input]]:univer-border-red-500":l,"[&_[data-u-comp=select]]:univer-border-red-500":l}),style:u,children:[o,l?(0,i.jsx)(`div`,{className:`univer-mt-1 univer-text-xs univer-text-red-500`,children:l}):null]}):null]})]})})},tt=e=>(0,i.jsx)(`div`,{className:`univer-flex univer-justify-between [&_[data-u-comp=form-layout]]:univer-max-w-[calc(50%-8px)] [&_[data-u-comp=form-layout]]:univer-shrink [&_[data-u-comp=form-layout]]:univer-grow`,children:e.children});function nt(n){let{className:r,value:a=0,total:o=0,loop:s,text:c,onChange:l}=n,u=(0,t.useMemo)(()=>c==null?`${a}/${o}`:c,[a,o,c]),d=o>0,f=()=>{a===1?s&&(l==null||l(o)):l==null||l(a-1)},p=()=>{a===o?s&&(l==null||l(1)):l==null||l(a+1)};return(0,i.jsx)(`div`,{"data-u-comp":`pager`,className:g(`univer-flex univer-flex-shrink-0 univer-items-center univer-text-sm univer-text-gray-700 dark:!univer-text-gray-400`,r),children:d?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`button`,{"data-u-comp":`pager-left-arrow`,className:`univer-inline-flex univer-size-4 univer-cursor-pointer univer-items-center univer-rounded univer-border-none univer-bg-transparent univer-p-0 hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-600`,type:`button`,role:`button`,onClick:f,children:(0,i.jsx)(e.MoreLeftIcon,{})}),(0,i.jsx)(`span`,{className:`univer-mx-1`,children:u}),(0,i.jsx)(`button`,{"data-u-comp":`pager-right-arrow`,className:`univer-inline-flex univer-size-4 univer-cursor-pointer univer-items-center univer-rounded univer-border-none univer-bg-transparent univer-p-0 hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-600`,type:`button`,role:`button`,onClick:p,children:(0,i.jsx)(e.MoreRightIcon,{})})]}):(0,i.jsx)(`div`,{className:`univer-mx-1`,children:u})})}const rt=`
2019
+ `),
2020
+ onPointerDownCapture: (e) => {
2021
+ if (pointerIdRef.current !== null) return;
2022
+ if (!draggableHandle) pressedHandleIdRef.current = itemId;
2023
+ else pressedHandleIdRef.current = !!e.target.closest(draggableHandle) ? itemId : null;
2024
+ if (pressedHandleIdRef.current !== itemId) return;
2025
+ const rect = e.currentTarget.getBoundingClientRect();
2026
+ dragPointerOffsetRef.current = {
2027
+ x: e.clientX - rect.left,
2028
+ y: e.clientY - rect.top
2029
+ };
2030
+ dragItemSizeRef.current = {
2031
+ width: rect.width,
2032
+ height: rect.height
2033
+ };
2034
+ setGhostPosition({
2035
+ x: rect.left,
2036
+ y: rect.top
2037
+ });
2038
+ setGhostElement(e.currentTarget.cloneNode(true));
2039
+ pointerIdRef.current = e.pointerId;
2040
+ dragSourceIdRef.current = itemId;
2041
+ dragStartIndexRef.current = index;
2042
+ setDraggingId(itemId);
2043
+ displayListRef.current = displayList;
2044
+ onDragStart === null || onDragStart === void 0 || onDragStart(void 0, { y: index });
2045
+ e.preventDefault();
2046
+ e.currentTarget.setPointerCapture(e.pointerId);
2047
+ },
2048
+ style: {
2049
+ ...rowHeight ? { minHeight: `${rowHeight}px` } : void 0,
2050
+ cursor: draggingId ? "grabbing" : void 0
2051
+ },
2052
+ children: [isDraggingItem && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "\n univer-bg-primary-50/50 univer-absolute univer-inset-0 univer-rounded\n univer-border univer-border-dashed univer-border-primary-300\n " }), itemRender(item, index)]
2053
+ }, itemId);
2054
+ })
2055
+ }), canUsePortal && draggingItem && ghostPosition && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2056
+ className: clsx$1("univer-pointer-events-none univer-fixed univer-rounded-md univer-border univer-border-gray-200 univer-bg-white univer-shadow-lg dark:!univer-border-gray-700 dark:!univer-bg-gray-800"),
2057
+ style: {
2058
+ zIndex: 2147483647,
2059
+ left: `${ghostPosition.x}px`,
2060
+ top: `${ghostPosition.y}px`,
2061
+ width: `${dragItemSizeRef.current.width}px`,
2062
+ height: `${dragItemSizeRef.current.height}px`,
2063
+ opacity: .95
2064
+ },
2065
+ children: ghostElement ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ref: ghostContainerRef }) : itemRender(draggingItem, displayList.findIndex((item) => getItemId(item) === getItemId(draggingItem)))
2066
+ }), document.body)] });
2067
+ }
2068
+
2069
+ //#endregion
2070
+ //#region src/components/dropdown-menu/DropdownMenuPrimitive.tsx
2071
+ function DropdownMenuPrimitive({ ...props }) {
2072
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Root, {
2073
+ "data-slot": "dropdown-menu",
2074
+ ...props
2075
+ });
2076
+ }
2077
+ function DropdownMenuPortal({ ...props }) {
2078
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Portal, {
2079
+ "data-slot": "dropdown-menu-portal",
2080
+ ...props
2081
+ });
2082
+ }
2083
+ function DropdownMenuTrigger({ ...props }) {
2084
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Trigger, {
2085
+ "data-slot": "dropdown-menu-trigger",
2086
+ ...props
2087
+ });
2088
+ }
2089
+ function DropdownMenuSub({ ...props }) {
2090
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Sub, {
2091
+ "data-slot": "dropdown-menu-sub",
2092
+ ...props
2093
+ });
2094
+ }
2095
+ function DropdownMenuRadioGroup({ ...props }) {
2096
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.RadioGroup, {
2097
+ "data-slot": "dropdown-menu-radio-group",
2098
+ ...props
2099
+ });
2100
+ }
2101
+ function DropdownMenuSubTrigger({ className, inset, children, ...props }) {
2102
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_radix_ui_react_dropdown_menu.SubTrigger, {
2103
+ "data-slot": "dropdown-menu-sub-trigger",
2104
+ "data-inset": inset,
2105
+ className: clsx$1("univer-flex univer-cursor-default univer-select-none univer-items-center univer-justify-between univer-gap-2 univer-rounded univer-px-2 univer-py-1.5 univer-text-sm univer-outline-none data-[state=open]:univer-bg-gray-100 focus:univer-bg-gray-100 dark:data-[state=open]:!univer-bg-gray-600 dark:focus:!univer-bg-gray-600 [&_svg]:univer-pointer-events-none [&_svg]:univer-size-4 [&_svg]:univer-shrink-0", className),
2106
+ ...props,
2107
+ children: [children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreRightIcon, { className: "ml-auto" })]
2108
+ });
2109
+ }
2110
+ function DropdownMenuSubContent({ className, ...props }) {
2111
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.SubContent, {
2112
+ "data-slot": "dropdown-menu-sub-content",
2113
+ className: clsx$1("data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-box-border univer-max-h-[--radix-popper-available-height] univer-overflow-y-auto univer-rounded-md univer-bg-white univer-p-1.5 univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-700 dark:!univer-text-white", borderClassName, scrollbarClassName, className),
2114
+ ...props
2115
+ });
2116
+ }
2117
+ function DropdownMenuContent({ className, sideOffset = 4, ...props }) {
2118
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Portal, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Content, {
2119
+ "data-slot": "dropdown-menu-content",
2120
+ sideOffset,
2121
+ className: clsx$1("data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-box-border univer-max-h-[--radix-popper-available-height] univer-overflow-y-auto univer-rounded-md univer-bg-white univer-p-1.5 univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-700 dark:!univer-text-white", borderClassName, scrollbarClassName, className),
2122
+ ...props
2123
+ }) });
2124
+ }
2125
+ function DropdownMenuItem({ className, inset, variant = "default", ...props }) {
2126
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Item, {
2127
+ "data-slot": "dropdown-menu-item",
2128
+ "data-inset": inset,
2129
+ "data-variant": variant,
2130
+ className: clsx$1("univer-relative univer-flex univer-cursor-default univer-select-none univer-items-center univer-gap-2 univer-rounded univer-px-2 univer-py-1.5 univer-text-sm univer-outline-none univer-transition-colors data-[disabled]:univer-pointer-events-none data-[disabled]:univer-opacity-50 focus:univer-bg-gray-100 dark:focus:!univer-bg-gray-600 [&>svg]:univer-size-4 [&>svg]:univer-shrink-0", className),
2131
+ ...props
2132
+ });
2133
+ }
2134
+ function DropdownMenuCheckboxItem({ className, children, hideIndicator, checked, ...props }) {
2135
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_radix_ui_react_dropdown_menu.CheckboxItem, {
2136
+ "data-slot": "dropdown-menu-checkbox-item",
2137
+ className: clsx$1("univer-relative univer-flex univer-cursor-default univer-select-none univer-items-center univer-rounded univer-py-1.5 univer-pr-2 univer-text-sm univer-outline-none univer-transition-colors data-[disabled]:univer-pointer-events-none data-[disabled]:univer-opacity-50 focus:univer-bg-gray-100 dark:focus:!univer-bg-gray-600", {
2138
+ "univer-pl-8": !hideIndicator,
2139
+ "univer-pl-2": hideIndicator
2140
+ }, className),
2141
+ checked,
2142
+ ...props,
2143
+ children: [!hideIndicator && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2144
+ className: "univer-absolute univer-left-2 univer-flex univer-size-3.5 univer-items-center univer-justify-center",
2145
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.ItemIndicator, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CheckMarkIcon, { className: "univer-block univer-size-4 univer-fill-current univer-text-primary-600" }) })
2146
+ }), children]
2147
+ });
2148
+ }
2149
+ function DropdownMenuRadioItem({ className, children, hideIndicator, ...props }) {
2150
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_radix_ui_react_dropdown_menu.RadioItem, {
2151
+ "data-slot": "dropdown-menu-radio-item",
2152
+ className: clsx$1("univer-relative univer-flex univer-cursor-default univer-select-none univer-items-center univer-rounded univer-py-1.5 univer-pr-2 univer-text-sm univer-outline-none univer-transition-colors data-[disabled]:univer-pointer-events-none data-[disabled]:univer-opacity-50 focus:univer-bg-gray-100 dark:focus:!univer-bg-gray-600", {
2153
+ "univer-pl-8": !hideIndicator,
2154
+ "univer-pl-2": hideIndicator
2155
+ }, className),
2156
+ ...props,
2157
+ children: [!hideIndicator && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2158
+ className: "univer-absolute univer-left-2 univer-flex univer-size-3.5 univer-items-center univer-justify-center",
2159
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.ItemIndicator, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CheckMarkIcon, { className: "univer-block univer-size-4 univer-fill-current univer-text-primary-600" }) })
2160
+ }), children]
2161
+ });
2162
+ }
2163
+ function DropdownMenuSeparator({ className, ...props }) {
2164
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Separator, {
2165
+ className: clsx$1("-univer-mx-1 univer-my-1 univer-h-px univer-bg-gray-200 dark:!univer-bg-gray-600", className),
2166
+ ...props
2167
+ });
2168
+ }
2169
+
2170
+ //#endregion
2171
+ //#region src/components/dropdown-menu/DropdownMenu.tsx
2172
+ function DropdownMenu(props) {
2173
+ const { children, items, disabled, open: controlledOpen, onOpenChange: controlledOnOpenChange, ...restProps } = props;
2174
+ const [uncontrolledOpen, setUncontrolledOpen] = (0, react.useState)(false);
2175
+ const isControlled = controlledOpen !== void 0;
2176
+ const open = isControlled ? controlledOpen : uncontrolledOpen;
2177
+ function handleChangeOpen(newOpen) {
2178
+ if (disabled) return;
2179
+ if (!isControlled) setUncontrolledOpen(newOpen);
2180
+ controlledOnOpenChange === null || controlledOnOpenChange === void 0 || controlledOnOpenChange(newOpen);
2181
+ }
2182
+ function renderMenuItem(item, index) {
2183
+ const { className, type } = item;
2184
+ if (type === "separator") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuSeparator, { className }, index);
2185
+ else if (type === "radio") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuRadioGroup, {
2186
+ className,
2187
+ value: item.value,
2188
+ onValueChange: item.onSelect,
2189
+ children: item.options.map((option, index) => {
2190
+ if ("type" in option) {
2191
+ if (option.type === "separator") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuSeparator, { className: option.className }, index);
2192
+ } else {
2193
+ if (option.value === void 0) throw new Error("[DropdownMenu]: `value` is required");
2194
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuRadioItem, {
2195
+ value: option.value,
2196
+ disabled: option.disabled,
2197
+ hideIndicator: item.hideIndicator,
2198
+ children: option.label
2199
+ }, option.value);
2200
+ }
2201
+ return null;
2202
+ })
2203
+ }, index);
2204
+ else if (type === "checkbox") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuCheckboxItem, {
2205
+ className,
2206
+ disabled: item.disabled,
2207
+ checked: item.checked,
2208
+ onSelect: () => {
2209
+ var _item$onSelect;
2210
+ (_item$onSelect = item.onSelect) === null || _item$onSelect === void 0 || _item$onSelect.call(item, item.value);
2211
+ },
2212
+ children: item.label
2213
+ }, index);
2214
+ else if (type === "item") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuItem, {
2215
+ className,
2216
+ disabled: item.disabled,
2217
+ onSelect: () => {
2218
+ var _item$onSelect2;
2219
+ (_item$onSelect2 = item.onSelect) === null || _item$onSelect2 === void 0 || _item$onSelect2.call(item, item);
2220
+ },
2221
+ children: item.children
2222
+ }, index);
2223
+ else if (type === "subItem") {
2224
+ var _item$options;
2225
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DropdownMenuSub, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuSubTrigger, { children: item.children }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuPortal, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuSubContent, {
2226
+ sideOffset: 12,
2227
+ children: (_item$options = item.options) === null || _item$options === void 0 ? void 0 : _item$options.map((subItem, subIndex) => renderMenuItem(subItem, subIndex))
2228
+ }) })] }, index);
2229
+ }
2230
+ }
2231
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DropdownMenuPrimitive, {
2232
+ modal: false,
2233
+ open,
2234
+ onOpenChange: handleChangeOpen,
2235
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuTrigger, {
2236
+ asChild: true,
2237
+ children
2238
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuContent, {
2239
+ className: "univer-text-sm",
2240
+ collisionPadding: {
2241
+ top: 12,
2242
+ bottom: 12
2243
+ },
2244
+ onWheel: (e) => e.stopPropagation(),
2245
+ ...restProps,
2246
+ children: items.map((item, index) => renderMenuItem(item, index))
2247
+ })]
2248
+ });
2249
+ }
2250
+
2251
+ //#endregion
2252
+ //#region src/components/form-layout/FormLayout.tsx
2253
+ const FormLayoutContext = (0, react.createContext)(false);
2254
+ const FormLayout = (props) => {
2255
+ const { label, desc, children, style, className, error, contentStyle, collapsable = false, defaultCollapsed = false } = props;
2256
+ const [collapsed, setCollapsed] = (0, react.useState)(defaultCollapsed);
2257
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormLayoutContext.Provider, {
2258
+ value: true,
2259
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2260
+ "data-u-comp": "form-layout",
2261
+ className: clsx$1("univer-mb-3 univer-flex univer-flex-col", className),
2262
+ style,
2263
+ children: [label && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2264
+ className: clsx$1("univer-mb-2 univer-flex univer-min-h-3.5 univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white", { "univer-cursor-pointer": collapsable }),
2265
+ onClick: () => setCollapsed(!collapsed),
2266
+ children: [label, collapsable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreUpIcon, { className: clsx$1("univer-ml-1 univer-transition-transform", { "univer-rotate-180": collapsed }) })]
2267
+ }), collapsed && collapsable ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [desc && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2268
+ className: "univer-mt-1 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",
2269
+ children: desc
2270
+ }), children ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2271
+ className: clsx$1("last:univer-mb-0 [&_[data-u-comp=input]]:univer-w-full [&_[data-u-comp=select]]:univer-w-full", {
2272
+ "[&_[data-u-comp=input]]:univer-border-red-500": error,
2273
+ "[&_[data-u-comp=select]]:univer-border-red-500": error
2274
+ }),
2275
+ style: contentStyle,
2276
+ children: [children, error ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2277
+ className: "univer-mt-1 univer-text-xs univer-text-red-500",
2278
+ children: error
2279
+ }) : null]
2280
+ }) : null] })]
2281
+ })
2282
+ });
2283
+ };
2284
+ /**
2285
+ * A dual columns layout component for the form.
2286
+ * @param props props of the component
2287
+ */
2288
+ const FormDualColumnLayout = (props) => {
2289
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2290
+ className: "univer-flex univer-justify-between [&_[data-u-comp=form-layout]]:univer-max-w-[calc(50%-8px)] [&_[data-u-comp=form-layout]]:univer-shrink [&_[data-u-comp=form-layout]]:univer-grow",
2291
+ children: props.children
2292
+ });
2293
+ };
2294
+
2295
+ //#endregion
2296
+ //#region src/components/pager/Pager.tsx
2297
+ /**
2298
+ * Copyright 2023-present DreamNum Co., Ltd.
2299
+ *
2300
+ * Licensed under the Apache License, Version 2.0 (the "License");
2301
+ * you may not use this file except in compliance with the License.
2302
+ * You may obtain a copy of the License at
2303
+ *
2304
+ * http://www.apache.org/licenses/LICENSE-2.0
2305
+ *
2306
+ * Unless required by applicable law or agreed to in writing, software
2307
+ * distributed under the License is distributed on an "AS IS" BASIS,
2308
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2309
+ * See the License for the specific language governing permissions and
2310
+ * limitations under the License.
2311
+ */
2312
+ function Pager(props) {
2313
+ const { className, value: current = 0, total: count = 0, loop, text: propText, onChange } = props;
2314
+ const text = (0, react.useMemo)(() => propText !== null && propText !== void 0 ? propText : `${current}/${count}`, [
2315
+ current,
2316
+ count,
2317
+ propText
2318
+ ]);
2319
+ const hasValue = count > 0;
2320
+ const onClickLeftArrow = () => {
2321
+ if (current === 1) {
2322
+ if (loop) onChange === null || onChange === void 0 || onChange(count);
2323
+ } else onChange === null || onChange === void 0 || onChange(current - 1);
2324
+ };
2325
+ const onClickRightArrow = () => {
2326
+ if (current === count) {
2327
+ if (loop) onChange === null || onChange === void 0 || onChange(1);
2328
+ } else onChange === null || onChange === void 0 || onChange(current + 1);
2329
+ };
2330
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2331
+ "data-u-comp": "pager",
2332
+ className: clsx$1("univer-flex univer-flex-shrink-0 univer-items-center univer-text-sm univer-text-gray-700 dark:!univer-text-gray-400", className),
2333
+ children: hasValue ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
2334
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2335
+ "data-u-comp": "pager-left-arrow",
2336
+ className: "univer-inline-flex univer-size-4 univer-cursor-pointer univer-items-center univer-rounded univer-border-none univer-bg-transparent univer-p-0 hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-600",
2337
+ type: "button",
2338
+ role: "button",
2339
+ onClick: onClickLeftArrow,
2340
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreLeftIcon, {})
2341
+ }),
2342
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2343
+ className: "univer-mx-1",
2344
+ children: text
2345
+ }),
2346
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2347
+ "data-u-comp": "pager-right-arrow",
2348
+ className: "univer-inline-flex univer-size-4 univer-cursor-pointer univer-items-center univer-rounded univer-border-none univer-bg-transparent univer-p-0 hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-600",
2349
+ type: "button",
2350
+ role: "button",
2351
+ onClick: onClickRightArrow,
2352
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreRightIcon, {})
2353
+ })
2354
+ ] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2355
+ className: "univer-mx-1",
2356
+ children: text
2357
+ })
2358
+ });
2359
+ }
2360
+
2361
+ //#endregion
2362
+ //#region src/components/gallery/Gallery.tsx
2363
+ /**
2364
+ * Copyright 2023-present DreamNum Co., Ltd.
2365
+ *
2366
+ * Licensed under the Apache License, Version 2.0 (the "License");
2367
+ * you may not use this file except in compliance with the License.
2368
+ * You may obtain a copy of the License at
2369
+ *
2370
+ * http://www.apache.org/licenses/LICENSE-2.0
2371
+ *
2372
+ * Unless required by applicable law or agreed to in writing, software
2373
+ * distributed under the License is distributed on an "AS IS" BASIS,
2374
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2375
+ * See the License for the specific language governing permissions and
2376
+ * limitations under the License.
2377
+ */
2378
+ const buttonClassName = `
60
2379
  univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-border-none
61
2380
  univer-bg-transparent univer-p-0 univer-text-current
62
2381
  hover:univer-text-white
63
- `;function it(n){let{className:r,images:a,open:o,onOpenChange:s}=n,[c,u]=(0,t.useState)(!1),[d,f]=(0,t.useState)(0),[p,m]=(0,t.useState)(1),h=(0,t.useRef)(null),_=(0,t.useMemo)(()=>a[d],[d,a]);if((0,t.useEffect)(()=>{o&&h.current&&h.current.focus()},[o]),(0,t.useEffect)(()=>{if(!o)return;let e=e=>{e.key===`Escape`&&(s==null||s(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o,s]),(0,t.useEffect)(()=>{if(o)u(!0);else{let e=setTimeout(()=>{u(!1)},150);return()=>clearTimeout(e)}},[o]),(0,t.useEffect)(()=>{if(!o)return;let e=e=>{e.preventDefault();let t=-e.deltaY*.001;m(e=>Math.min(Math.max(.5,e+t),2))};return window.addEventListener(`wheel`,e,{passive:!1}),()=>{window.removeEventListener(`wheel`,e)}},[o]),!o&&!c)return null;function v(e){if(e===`reset`){m(1);return}let t=p+e;t<.5||t>2||m(t)}return(0,l.createPortal)((0,i.jsxs)(`div`,{"data-u-comp":`gallery`,role:`dialog`,"aria-modal":`true`,"aria-label":`Image gallery`,tabIndex:-1,ref:h,className:g(`univer-absolute univer-inset-0 univer-z-[1080] univer-flex univer-size-full univer-select-none univer-items-center univer-justify-center`,{"univer-animate-in univer-fade-in":o,"univer-animate-out univer-fade-out":!o},r),children:[(0,i.jsx)(`div`,{className:`univer-absolute univer-inset-0 univer-size-full univer-bg-gray-900 univer-opacity-80`,"aria-hidden":`true`,onClick:()=>s==null?void 0:s(!1)}),(0,i.jsx)(`div`,{className:`univer-relative`,children:_&&(0,i.jsx)(`img`,{className:`univer-max-h-[40vh] univer-max-w-[60vw] univer-transition-transform univer-duration-300 univer-ease-out`,style:{transform:`scale(${p})`},src:_,alt:`Image ${d+1} of ${a.length}`,draggable:!1})}),(0,i.jsxs)(`footer`,{className:`univer-absolute univer-bottom-6 univer-left-1/2 univer-flex -univer-translate-x-1/2 univer-items-center univer-gap-3 univer-rounded-full univer-bg-gray-800 univer-px-6 univer-py-3 univer-text-gray-400`,children:[(0,i.jsx)(nt,{className:`!univer-text-gray-400 [&_[data-u-comp=pager-left-arrow]:hover]:!univer-bg-gray-600 [&_[data-u-comp=pager-right-arrow]:hover]:!univer-bg-gray-600`,value:d+1,total:a.length,onChange:e=>f(e-1)}),(0,i.jsx)(`button`,{type:`button`,"aria-label":`Zoom in`,className:rt,onClick:()=>v(.25),children:(0,i.jsx)(e.ZoomInIcon,{"aria-hidden":`true`})}),(0,i.jsx)(`button`,{type:`button`,"aria-label":`Zoom out`,className:rt,onClick:()=>v(-.25),children:(0,i.jsx)(e.ZoomOutIcon,{"aria-hidden":`true`})}),(0,i.jsx)(`button`,{type:`button`,"aria-label":`Reset zoom`,className:rt,onClick:()=>v(`reset`),children:(0,i.jsx)(e.OneToOneIcon,{"aria-hidden":`true`})})]})]}),document.body)}const at=(0,a.cva)(`
2382
+ `;
2383
+ function Gallery(props) {
2384
+ const { className, images, open, onOpenChange } = props;
2385
+ const [isVisible, setIsVisible] = (0, react.useState)(false);
2386
+ const [activeImageIndex, setActiveImageIndex] = (0, react.useState)(0);
2387
+ const [zoomLevel, setZoomLevel] = (0, react.useState)(1);
2388
+ const dialogRef = (0, react.useRef)(null);
2389
+ const activeImage = (0, react.useMemo)(() => images[activeImageIndex], [activeImageIndex, images]);
2390
+ (0, react.useEffect)(() => {
2391
+ if (open && dialogRef.current) dialogRef.current.focus();
2392
+ }, [open]);
2393
+ (0, react.useEffect)(() => {
2394
+ if (!open) return;
2395
+ const handler = (e) => {
2396
+ if (e.key === "Escape") onOpenChange === null || onOpenChange === void 0 || onOpenChange(false);
2397
+ };
2398
+ window.addEventListener("keydown", handler);
2399
+ return () => window.removeEventListener("keydown", handler);
2400
+ }, [open, onOpenChange]);
2401
+ (0, react.useEffect)(() => {
2402
+ if (open) setIsVisible(true);
2403
+ else {
2404
+ const timer = setTimeout(() => {
2405
+ setIsVisible(false);
2406
+ }, 150);
2407
+ return () => clearTimeout(timer);
2408
+ }
2409
+ }, [open]);
2410
+ (0, react.useEffect)(() => {
2411
+ if (!open) return;
2412
+ const handleWheel = (e) => {
2413
+ e.preventDefault();
2414
+ const step = -e.deltaY * .001;
2415
+ setZoomLevel((prev) => Math.min(Math.max(.5, prev + step), 2));
2416
+ };
2417
+ window.addEventListener("wheel", handleWheel, { passive: false });
2418
+ return () => {
2419
+ window.removeEventListener("wheel", handleWheel);
2420
+ };
2421
+ }, [open]);
2422
+ if (!open && !isVisible) return null;
2423
+ function handleToggleZoom(ratio) {
2424
+ if (ratio === "reset") {
2425
+ setZoomLevel(1);
2426
+ return;
2427
+ }
2428
+ const newZoomLevel = zoomLevel + ratio;
2429
+ if (newZoomLevel < .5) return;
2430
+ if (newZoomLevel > 2) return;
2431
+ setZoomLevel(newZoomLevel);
2432
+ }
2433
+ return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2434
+ "data-u-comp": "gallery",
2435
+ role: "dialog",
2436
+ "aria-modal": "true",
2437
+ "aria-label": "Image gallery",
2438
+ tabIndex: -1,
2439
+ ref: dialogRef,
2440
+ className: clsx$1("univer-absolute univer-inset-0 univer-z-[1080] univer-flex univer-size-full univer-select-none univer-items-center univer-justify-center", {
2441
+ "univer-animate-in univer-fade-in": open,
2442
+ "univer-animate-out univer-fade-out": !open
2443
+ }, className),
2444
+ children: [
2445
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2446
+ className: "univer-absolute univer-inset-0 univer-size-full univer-bg-gray-900 univer-opacity-80",
2447
+ "aria-hidden": "true",
2448
+ onClick: () => onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(false)
2449
+ }),
2450
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2451
+ className: "univer-relative",
2452
+ children: activeImage && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
2453
+ className: "univer-max-h-[40vh] univer-max-w-[60vw] univer-transition-transform univer-duration-300 univer-ease-out",
2454
+ style: { transform: `scale(${zoomLevel})` },
2455
+ src: activeImage,
2456
+ alt: `Image ${activeImageIndex + 1} of ${images.length}`,
2457
+ draggable: false
2458
+ })
2459
+ }),
2460
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("footer", {
2461
+ className: "univer-absolute univer-bottom-6 univer-left-1/2 univer-flex -univer-translate-x-1/2 univer-items-center univer-gap-3 univer-rounded-full univer-bg-gray-800 univer-px-6 univer-py-3 univer-text-gray-400",
2462
+ children: [
2463
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Pager, {
2464
+ className: "!univer-text-gray-400 [&_[data-u-comp=pager-left-arrow]:hover]:!univer-bg-gray-600 [&_[data-u-comp=pager-right-arrow]:hover]:!univer-bg-gray-600",
2465
+ value: activeImageIndex + 1,
2466
+ total: images.length,
2467
+ onChange: (value) => setActiveImageIndex(value - 1)
2468
+ }),
2469
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2470
+ type: "button",
2471
+ "aria-label": "Zoom in",
2472
+ className: buttonClassName,
2473
+ onClick: () => handleToggleZoom(.25),
2474
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.ZoomInIcon, { "aria-hidden": "true" })
2475
+ }),
2476
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2477
+ type: "button",
2478
+ "aria-label": "Zoom out",
2479
+ className: buttonClassName,
2480
+ onClick: () => handleToggleZoom(-.25),
2481
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.ZoomOutIcon, { "aria-hidden": "true" })
2482
+ }),
2483
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2484
+ type: "button",
2485
+ "aria-label": "Reset zoom",
2486
+ className: buttonClassName,
2487
+ onClick: () => handleToggleZoom("reset"),
2488
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.OneToOneIcon, { "aria-hidden": "true" })
2489
+ })
2490
+ ]
2491
+ })
2492
+ ]
2493
+ }), document.body);
2494
+ }
2495
+
2496
+ //#endregion
2497
+ //#region src/components/input/Input.tsx
2498
+ const inputVariants = (0, class_variance_authority.cva)(`
64
2499
  univer-box-border univer-w-full univer-rounded-md univer-bg-white univer-transition-colors univer-duration-200
65
2500
  placeholder:univer-text-gray-400
66
2501
  focus:univer-border-primary-600 focus:univer-outline-none focus:univer-ring-2 focus:univer-ring-primary-50
67
2502
  dark:!univer-bg-gray-700 dark:!univer-text-white
68
2503
  dark:focus:!univer-ring-primary-900
69
- `,{variants:{size:{mini:`univer-h-7 univer-px-1.5 univer-text-sm`,small:`univer-h-8 univer-px-2 univer-text-sm`,middle:`univer-h-10 univer-px-3 univer-text-base`,large:`univer-h-12 univer-px-4 univer-text-lg`}},defaultVariants:{size:`small`}}),ot=(0,t.forwardRef)(({autoFocus:n=!1,className:r,style:a,type:o=`text`,placeholder:s,value:c,size:l=`small`,allowClear:u=!1,disabled:d=!1,onClick:f,onKeyDown:p,onChange:m,onFocus:h,onBlur:_,slot:v,inputClass:y,inputStyle:b,...x},S)=>{let C=e=>{e.stopPropagation(),m==null||m(``)},w=e=>{m==null||m(e.target.value)},T=(0,t.useMemo)(()=>u&&c&&!d||v,[u,d,v,c]),[E,D]=(0,t.useState)(0),O=(0,t.useRef)(null);return(0,t.useEffect)(()=>{let e=null;return v&&O.current&&(e=new MutationObserver(()=>{O.current&&D(O.current.offsetWidth+8)}),e.observe(O.current,{childList:!0,subtree:!0}),D(O.current.offsetWidth+8)),()=>e==null?void 0:e.disconnect()},[O.current]),(0,t.useEffect)(()=>{u&&!(v&&O.current)&&D(26)},[]),(0,i.jsxs)(`div`,{"data-u-comp":`input`,className:g(`univer-relative univer-inline-flex univer-w-full univer-items-center univer-rounded-md`,d&&`univer-cursor-not-allowed`,r),style:a,children:[(0,i.jsx)(`input`,{ref:S,type:o,className:g(at({size:l}),k,d&&`
2504
+ `, {
2505
+ variants: { size: {
2506
+ mini: "univer-h-7 univer-px-1.5 univer-text-sm",
2507
+ small: "univer-h-8 univer-px-2 univer-text-sm",
2508
+ middle: "univer-h-10 univer-px-3 univer-text-base",
2509
+ large: "univer-h-12 univer-px-4 univer-text-lg"
2510
+ } },
2511
+ defaultVariants: { size: "small" }
2512
+ });
2513
+ const Input = (0, react.forwardRef)(({ autoFocus = false, className, style, type = "text", placeholder, value, size = "small", allowClear = false, disabled = false, onClick, onKeyDown, onChange, onFocus, onBlur, slot, inputClass, inputStyle, ...props }, ref) => {
2514
+ const handleClear = (e) => {
2515
+ e.stopPropagation();
2516
+ onChange === null || onChange === void 0 || onChange("");
2517
+ };
2518
+ const handleChange = (e) => {
2519
+ onChange === null || onChange === void 0 || onChange(e.target.value);
2520
+ };
2521
+ const hasSlotContent = (0, react.useMemo)(() => {
2522
+ return allowClear && value && !disabled || slot;
2523
+ }, [
2524
+ allowClear,
2525
+ disabled,
2526
+ slot,
2527
+ value
2528
+ ]);
2529
+ const [paddingRight, setPaddingRight] = (0, react.useState)(0);
2530
+ const slotRef = (0, react.useRef)(null);
2531
+ (0, react.useEffect)(() => {
2532
+ let observer = null;
2533
+ if (slot && slotRef.current) {
2534
+ observer = new MutationObserver(() => {
2535
+ if (slotRef.current) setPaddingRight(slotRef.current.offsetWidth + 8);
2536
+ });
2537
+ observer.observe(slotRef.current, {
2538
+ childList: true,
2539
+ subtree: true
2540
+ });
2541
+ setPaddingRight(slotRef.current.offsetWidth + 8);
2542
+ }
2543
+ return () => observer === null || observer === void 0 ? void 0 : observer.disconnect();
2544
+ }, [slotRef.current]);
2545
+ (0, react.useEffect)(() => {
2546
+ if (allowClear && !(slot && slotRef.current)) setPaddingRight(26);
2547
+ }, []);
2548
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2549
+ "data-u-comp": "input",
2550
+ className: clsx$1("univer-relative univer-inline-flex univer-w-full univer-items-center univer-rounded-md", disabled && "univer-cursor-not-allowed", className),
2551
+ style,
2552
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
2553
+ ref,
2554
+ type,
2555
+ className: clsx$1(inputVariants({ size }), borderClassName, disabled && `
70
2556
  univer-cursor-not-allowed univer-bg-gray-50 univer-text-gray-400
71
2557
  dark:!univer-text-gray-500
72
- `,u&&!v&&`univer-pr-8`,y),placeholder:s,value:c,disabled:d,autoFocus:n,onClick:f,onKeyDown:p,onChange:w,onFocus:h,onBlur:_,style:{...b,paddingRight:E},...x}),T&&(0,i.jsxs)(`div`,{className:`univer-absolute univer-right-2 univer-flex univer-items-center univer-gap-1 univer-rounded-full`,ref:O,children:[v,u&&c&&!d&&(0,i.jsx)(`button`,{type:`button`,onClick:C,className:`univer-flex univer-size-4 univer-cursor-pointer univer-items-center univer-rounded-full univer-border-none univer-bg-transparent univer-p-1 univer-text-gray-400 univer-transition-colors univer-duration-200 hover:univer-text-gray-500 focus:univer-outline-none`,children:(0,i.jsx)(e.CloseIcon,{className:`univer-size-3`})})]})]})}),st=(0,t.forwardRef)(({value:e,defaultValue:n,size:r=`small`,min:a=-(2**53-1),max:o=2**53-1,step:s=1,precision:c,formatter:l,parser:u,controls:d=!0,className:f,inputClassName:p,controlsClassName:m,disabled:h,onChange:_,onKeyDown:v,onPressEnter:y,onFocus:b,onBlur:x,allowEmpty:S=!1},C)=>{let[w,T]=(0,t.useState)(e===void 0?n===void 0?null:n:e),E=(0,t.useRef)(w),[D,O]=(0,t.useState)(F(w)),k=(0,t.useRef)(null),A=(0,t.useRef)(null),N=(0,t.useRef)(null),P=e=>{C&&(typeof C==`function`?C(e):C.current=e),k.current=e};(0,t.useEffect)(()=>{e!==void 0&&e!==w&&(T(e),E.current=e,O(F(e)))},[e]),(0,t.useEffect)(()=>{w!==null&&(E.current=w)},[w]),(0,t.useEffect)(()=>()=>{A.current&&clearTimeout(A.current),N.current&&clearInterval(N.current)},[]);function F(e){if(e==null)return``;let t=e;return c!==void 0&&(t=Number(e).toFixed(c)),l?l(t):String(t)}function I(e){if(!e)return null;let t=e;u&&(t=u(e));try{let e=t.replace(/[^\d.-]/g,``).split(`.`),n=e[0],r=e.length>1?e.slice(1).join(``):``,i=n+(r?`.${r}`:``),s=Number(i);if(Number.isNaN(s))return null;let l;if(c!==void 0){let e=10**c,t=Math.round(s*e)/e;l=t.toString().includes(`e`)?Number.parseFloat(t.toFixed(c)):t}else l=s.toString().includes(`e`)?Number.parseFloat(s.toFixed(16).replace(/\.?0+$/,``)):s;return o!==void 0&&l>o&&(l=o),a!==void 0&&l<a&&(l=a),l}catch{return null}}function L(e){if(O(e),S&&e===``){T(null),_==null||_(null);return}let t=I(e);T(t),_==null||_(t)}function R(e){if(w===null){if(D===``&&S)_&&_(null);else{let e=E.current;T(e),O(F(e)),_&&_(e)}x==null||x(e);return}let t=w;o!==void 0&&t>o&&(t=o),a!==void 0&&t<a&&(t=a),t===w?O(F(w)):(T(t),O(F(t)),_==null||_(t)),x==null||x(e)}function z(e){if(h)return;let t=e?s:-s,n;n=w===null?E.current===null?a>0?a:0:E.current:w;let r=n+t;o!==void 0&&r>o&&(r=o),a!==void 0&&r<a&&(r=a),r!==n&&(T(r),E.current=r,O(F(r)),_==null||_(r))}function ee(e){h||(v==null||v(e),e.key===`ArrowUp`?(e.preventDefault(),z(!0)):e.key===`ArrowDown`?(e.preventDefault(),z(!1)):e.key===`Enter`&&(y==null||y(e)))}function B(e){var t;h||(z(e),(t=k.current)==null||t.focus())}let V=h||o!==void 0&&w!==null&&w>=o,H=h||a!==void 0&&w!==null&&w<=a;return(0,i.jsx)(`div`,{className:g(`univer-inline-block`,f),children:(0,i.jsxs)(`div`,{className:`univer-relative univer-w-full`,children:[(0,i.jsx)(ot,{ref:P,className:g(`univer-box-border`,p),size:r,value:D,disabled:h,onChange:L,onFocus:b,onBlur:R,onKeyDown:ee}),d&&(0,i.jsxs)(`div`,{className:g(`univer-absolute univer-right-px univer-top-px univer-flex univer-h-[calc(100%-2px)] univer-flex-col univer-overflow-hidden univer-rounded-r-md before:univer-absolute before:univer-top-1/2 before:univer-block before:univer-h-px before:univer-w-full before:-univer-translate-y-1/2 before:univer-bg-gray-200 before:univer-content-[""] rtl:univer-left-px rtl:univer-right-auto rtl:univer-rounded-l-md rtl:univer-rounded-r-none dark:before:!univer-bg-gray-600`,j,M,m),children:[(0,i.jsx)(`span`,{className:g(`univer-box-border univer-flex univer-h-1/2 univer-w-5 univer-cursor-pointer univer-items-center univer-justify-center univer-border-none univer-bg-transparent univer-p-0 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-600`,V&&`univer-cursor-not-allowed univer-opacity-60`),role:`button`,"aria-label":`increment`,"aria-disabled":V,tabIndex:-1,onMouseDown:e=>e.preventDefault(),onClick:()=>{V||B(!0)},children:`+`}),(0,i.jsx)(`span`,{className:g(`univer-box-border univer-flex univer-h-1/2 univer-w-5 univer-cursor-pointer univer-items-center univer-justify-center univer-border-none univer-bg-transparent univer-p-0 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-600`,H&&`univer-cursor-not-allowed univer-opacity-60`),role:`button`,"aria-label":`decrement`,"aria-disabled":H,tabIndex:-1,onMouseDown:e=>e.preventDefault(),onClick:()=>{H||B(!1)},children:`-`})]})]})})});function ct({items:e,value:n,defaultValue:r,onChange:a,className:o=``}){let[s,c]=(0,t.useState)(n===void 0?r||e[0].value:n),[l,u]=(0,t.useState)({}),d=(0,t.useRef)(new Map),f=(0,t.useRef)(null);(0,t.useEffect)(()=>{n!==void 0&&n!==s&&c(n)},[n]);let p=(e,t)=>{let n=d.current.get(e),r=t?d.current.get(t):null;if(n&&f.current){let e=f.current.getBoundingClientRect(),t=n.getBoundingClientRect(),i=t.left-e.left-4;if(r){let n=r.getBoundingClientRect().left-e.left-4;u({"--slide-from":`${n}px`,"--slide-to":`${i}px`,width:`${t.width}px`,transform:`translateX(${i}px)`})}else u({width:`${t.width}px`,transform:`translateX(${i}px)`})}};(0,t.useEffect)(()=>{p(s)},[s]);let m=e=>{let t=s;c(e),a==null||a(e),p(e,t)};return(0,i.jsxs)(`div`,{"data-u-comp":`segmented`,ref:f,className:g(`univer-relative univer-box-border univer-flex univer-gap-4 univer-rounded-lg univer-bg-gray-100 univer-p-1 dark:!univer-bg-gray-800`,o),children:[(0,i.jsx)(`div`,{className:`univer-animate-univer-slide univer-absolute univer-h-6 univer-rounded-md univer-bg-white univer-shadow-sm univer-transition-all univer-duration-200 dark:!univer-bg-gray-700 dark:!univer-text-gray-400`,style:l}),e.map(e=>(0,i.jsx)(`button`,{ref:t=>{t&&d.current.set(e.value,t)},className:g(`univer-relative univer-box-border univer-flex-1 univer-cursor-pointer univer-border-none univer-bg-transparent univer-px-3 univer-py-1 univer-text-xs univer-font-medium univer-transition-colors`,{"univer-text-gray-900 dark:!univer-text-white":s===e.value,"univer-text-gray-500 hover:univer-text-gray-900 dark:hover:!univer-text-white":s!==e.value}),type:`button`,onClick:()=>m(e.value),children:e.label},String(e.value)))]})}function lt(e){let{children:n,className:r,asChild:a=!0,title:o,placement:s=`bottom`,showIfEllipsis:c=!1,visible:u,onVisibleChange:d}=e,[f,p]=(0,t.useState)(!1),m=u!==void 0,h=m?u:f,_=(0,t.useRef)(null),v=(0,t.useRef)(null),y=(0,t.useRef)(null),[b,x]=(0,t.useState)(null),[S,C]=(0,t.useState)(s);function w(e){return Math.abs(e.scrollWidth-e.clientWidth)>1}function T(){m?d==null||d(!0):p(!0)}function E(){m?d==null||d(!1):p(!1)}(0,t.useLayoutEffect)(()=>{if(!h)return;let e=_.current,t=v.current;if(!e||!t)return;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=window.innerWidth,a=window.innerHeight,o=[s,`bottom`,`top`,`right`,`left`],c=s,l=0,u=0,d=e=>{let t=0,i=0;return e===`bottom`?(t=n.bottom+8,i=n.left+n.width/2-r.width/2):e===`top`?(t=n.top-r.height-8,i=n.left+n.width/2-r.width/2):e===`left`?(t=n.top+n.height/2-r.height/2,i=n.left-r.width-8):(t=n.top+n.height/2-r.height/2,i=n.right+8),{t,l:i}};for(let e of o){let{t,l:n}=d(e),o=n>=0&&n+r.width<=i,s=t>=0&&t+r.height<=a;if(o&&s){c=e,l=t,u=n;break}}if(!l&&!u){let e=d(s);l=Math.min(Math.max(0,e.t),a-r.height),u=Math.min(Math.max(0,e.l),i-r.width)}C(c),x({top:Math.round(l+window.scrollY),left:Math.round(u+window.scrollX)})},[h,s]),(0,t.useEffect)(()=>{if(!h)return;let e=()=>{if(!_.current||!v.current)return;let e=_.current.getBoundingClientRect(),t=v.current.getBoundingClientRect(),n=0,r=0;S===`bottom`?(n=e.bottom+8,r=e.left+e.width/2-t.width/2):S===`top`?(n=e.top-t.height-8,r=e.left+e.width/2-t.width/2):S===`left`?(n=e.top+e.height/2-t.height/2,r=e.left-t.width-8):(n=e.top+e.height/2-t.height/2,r=e.right+8),x({top:Math.round(n+window.scrollY),left:Math.round(r+window.scrollX)})};return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[h,S]);let D={ref:e=>_.current=e,onMouseEnter:()=>{c&&_.current&&!w(_.current)||T()},onMouseLeave:()=>E(),onFocus:()=>T(),onBlur:()=>E()},O=a?(0,i.jsx)(`span`,{...D,className:`univer-inline-block univer-max-w-full univer-truncate`,children:n}):(0,i.jsx)(`button`,{type:`button`,...D,children:n}),k=null;if(typeof document<`u`&&h&&o&&document.body){var A,j;k=(0,l.createPortal)((0,i.jsxs)(`div`,{ref:v,role:`tooltip`,className:g(`univer-animate-in univer-fade-in-0 univer-zoom-in-95 univer-pointer-events-auto univer-absolute univer-z-[1081] univer-box-border univer-w-fit univer-max-w-sm univer-text-balance univer-rounded-lg univer-bg-gray-700 univer-px-2.5 univer-py-2 univer-text-xs univer-font-medium univer-text-white univer-shadow-lg univer-drop-shadow-sm dark:!univer-bg-gray-100 dark:!univer-text-gray-900`,r),style:{top:(A=b==null?void 0:b.top)==null?-9999:A,left:(j=b==null?void 0:b.left)==null?-9999:j},onMouseEnter:()=>T(),onMouseLeave:()=>E(),children:[(0,i.jsx)(`div`,{className:`univer-break-words`,children:o}),(0,i.jsx)(`div`,{ref:y,className:`univer-absolute univer-size-2.5 univer-rotate-45 univer-rounded-sm univer-bg-gray-700 dark:!univer-bg-gray-100`,style:{...S===`bottom`&&{top:-5,left:`50%`,transform:`translateX(-50%) rotate(45deg)`},...S===`top`&&{bottom:-5,left:`50%`,transform:`translateX(-50%) rotate(45deg)`},...S===`left`&&{right:-5,top:`50%`,transform:`translateY(-50%) rotate(45deg)`},...S===`right`&&{left:-5,top:`50%`,transform:`translateY(-50%) rotate(45deg)`}}})]}),document.body)}return(0,i.jsxs)(i.Fragment,{children:[O,k]})}const ut={type:`linear`,stops:[{color:`#ffffff`,offset:0},{color:`#000000`,offset:100}],angle:90};function dt(n){var r,a;let{className:o,value:s=ut,onChange:c}=n,{locale:l}=(0,t.useContext)(T),[u,d]=(0,t.useState)(0),f=(0,t.useRef)(null),p=(0,t.useMemo)(()=>[...s.stops].sort((e,t)=>e.offset-t.offset),[s.stops]),m=e=>{c==null||c({...s,type:e})},h=e=>{c==null||c({...s,angle:e==null?0:e})},_=e=>{let t=[...s.stops];t[u]={...t[u],color:e},c==null||c({...s,stops:t})},v=e=>{if(e===null)return;let t=[...s.stops];t[u]={...t[u],offset:e},c==null||c({...s,stops:t})},y=e=>{if(!f.current)return;let t=f.current.getBoundingClientRect(),n=Math.round((e.clientX-t.left)/t.width*100),r={color:([...p].reverse().find(e=>e.offset<=n)||p[0]).color,offset:n},i=[...s.stops,r];c==null||c({...s,stops:i}),d(i.length-1)},b=()=>{if(s.stops.length<=2)return;let e=s.stops.filter((e,t)=>t!==u);c==null||c({...s,stops:e}),d(0)},x=(0,t.useMemo)(()=>`linear-gradient(to right, ${p.map(e=>`${e.color} ${e.offset}%`).join(`, `)})`,[p]),C=(0,t.useMemo)(()=>{let e=p.map(e=>`${e.color} ${e.offset}%`).join(`, `);switch(s.type){case`linear`:return`linear-gradient(${s.angle}deg, ${e})`;case`radial`:return`radial-gradient(circle, ${e})`;case`angular`:return`conic-gradient(from ${s.angle}deg, ${e})`;case`diamond`:return`radial-gradient(circle, ${e})`;default:return`linear-gradient(${s.angle}deg, ${e})`}},[s,p]);return(0,i.jsxs)(`div`,{className:g(`univer-flex univer-w-64 univer-flex-col univer-gap-4 univer-rounded-lg univer-bg-white univer-p-4 univer-shadow-lg dark:!univer-bg-gray-800`,o),children:[(0,i.jsx)(ct,{items:[{label:l==null?void 0:l.GradientColorPicker.linear,value:`linear`},{label:l==null?void 0:l.GradientColorPicker.radial,value:`radial`},{label:l==null?void 0:l.GradientColorPicker.angular,value:`angular`},{label:l==null?void 0:l.GradientColorPicker.diamond,value:`diamond`}],value:s.type,onChange:e=>m(e)}),(0,i.jsx)(`div`,{className:`univer-h-32 univer-w-full univer-rounded-md univer-border univer-border-gray-200 dark:!univer-border-gray-600`,style:{background:C}}),(0,i.jsxs)(`div`,{className:`univer-relative univer-mt-4 univer-h-6`,children:[(0,i.jsx)(`div`,{ref:f,className:`univer-absolute univer-inset-x-0 univer-top-1/2 univer-h-2 -univer-translate-y-1/2 univer-cursor-crosshair univer-rounded-full`,style:{background:x},onClick:y}),s.stops.map((e,t)=>(0,i.jsx)(`div`,{className:g(`univer-absolute univer-top-1/2 univer-size-4 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-cursor-pointer univer-rounded-full univer-border-2 univer-border-white univer-shadow-md`,u===t?`univer-z-10 univer-ring-2 univer-ring-primary-500`:`univer-z-0`),style:{left:`${e.offset}%`,backgroundColor:e.color},onClick:e=>{e.stopPropagation(),d(t)},onPointerDown:n=>{let r=n.clientX,i=e.offset,a=e=>{if(!f.current)return;let n=f.current.getBoundingClientRect(),a=(e.clientX-r)/n.width*100,o=Math.max(0,Math.min(100,Math.round(i+a))),l=[...s.stops];l[t]={...l[t],offset:o},c==null||c({...s,stops:l})},o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o)};window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o)}},t))]}),(0,i.jsxs)(`div`,{className:`univer-flex univer-items-end univer-gap-2`,children:[(0,i.jsxs)(`div`,{className:`univer-flex-1`,children:[(0,i.jsx)(`div`,{className:`univer-mb-1 univer-text-xs univer-text-gray-500`,children:l==null?void 0:l.GradientColorPicker.offset}),(0,i.jsx)(st,{value:(r=s.stops[u])==null?void 0:r.offset,min:0,max:100,onChange:v})]}),(s.type===`linear`||s.type===`angular`)&&(0,i.jsxs)(`div`,{className:`univer-flex-1`,children:[(0,i.jsx)(`div`,{className:`univer-mb-1 univer-text-xs univer-text-gray-500`,children:l==null?void 0:l.GradientColorPicker.angle}),(0,i.jsx)(st,{value:s.angle,min:0,max:360,onChange:h})]}),(0,i.jsx)(`div`,{className:`univer-flex univer-gap-1`,children:(0,i.jsx)(lt,{title:l==null?void 0:l.GradientColorPicker.delete,children:(0,i.jsx)(S,{variant:`danger`,onClick:b,disabled:s.stops.length<=2,children:(0,i.jsx)(e.DeleteIcon,{})})})})]}),(0,i.jsx)(`div`,{className:`univer-border-t univer-border-gray-100 univer-pt-4 dark:!univer-border-gray-700`,children:(0,i.jsx)(ke,{value:(a=s.stops[u])==null?void 0:a.color,onChange:_})})]})}const ft=d.Root,pt=d.Portal,mt=d.Trigger,ht=(0,t.forwardRef)(({className:e,align:t=`center`,sideOffset:n=4,...r},a)=>(0,i.jsx)(d.Content,{ref:a,align:t,sideOffset:n,className:g(`data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-w-64 univer-origin-[--radix-hover-card-content-transform-origin] univer-rounded-md univer-bg-white univer-text-gray-900 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900 dark:!univer-text-white`,k,e),...r}));ht.displayName=d.Content.displayName;function gt(e){let{children:n,overlay:r,disabled:a,openDelay:o=200,open:s,onOpenChange:c,...l}=e,[u,d]=(0,t.useState)(!1),f=s!==void 0,p=f?s:u;function m(e){a||(f||d(e),c==null||c(e))}return(0,i.jsxs)(ft,{open:p,onOpenChange:m,openDelay:o,children:[(0,i.jsx)(mt,{asChild:!0,children:n}),(0,i.jsx)(pt,{children:(0,i.jsx)(ht,{...l,children:r})})]})}function _t(e){let{keyboard:t,className:n}=e,r=t.split(`+`);return(0,i.jsx)(`span`,{className:g(`univer-inline-block univer-h-6 univer-select-none univer-whitespace-nowrap univer-rounded-md univer-bg-gray-50 univer-px-2 univer-font-mono univer-text-xs/6 univer-font-medium univer-text-gray-700 dark:!univer-bg-gray-700 dark:!univer-text-white`,k,n),children:r.map((e,t)=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`kbd`,{className:`univer-inline-block univer-h-full`,children:e}),t<r.length-1&&(0,i.jsx)(`span`,{className:`univer-inline-block univer-h-full univer-px-1`,children:`+`})]},t))})}let J=function(e){return e.Success=`success`,e.Info=`info`,e.Warning=`warning`,e.Error=`error`,e.Loading=`loading`,e}({});const vt=`univer-message-toaster`,yt=3e3,Y=new Set,bt=(0,i.jsx)(e.LoadingMultiIcon,{className:`univer-animate-spin univer-text-violet-500`});let xt=0;const St={[J.Success]:(0,i.jsx)(e.SuccessIcon,{className:`univer-text-green-500`}),[J.Info]:(0,i.jsx)(e.InfoIcon,{className:`univer-text-sky-500 dark:!univer-text-sky-400`}),[J.Warning]:(0,i.jsx)(e.WarningIcon,{className:`univer-text-amber-500`}),[J.Error]:(0,i.jsx)(e.ErrorIcon,{className:`univer-text-red-500`}),[J.Loading]:bt},X={[J.Success]:`[&_[data-icon]]:univer-text-green-500`,[J.Info]:`[&_[data-icon]]:univer-text-sky-500`,[J.Warning]:`[&_[data-icon]]:univer-text-amber-500`,[J.Error]:`[&_[data-icon]]:univer-text-red-500`,[J.Loading]:`[&_[data-icon]]:univer-text-violet-500`},Ct=e=>{switch(e){case J.Success:return f.toast.success;case J.Warning:return f.toast.warning;case J.Error:return f.toast.error;case J.Loading:return f.toast.loading;case J.Info:default:return f.toast.info}},wt=()=>{let e=`univer-message-${xt}`;return xt+=1,e},Tt=({className:e,...t})=>(0,i.jsx)(f.Toaster,{id:vt,position:`top-center`,visibleToasts:4,closeButton:!1,expand:!1,icons:{loading:bt},offset:{top:16},className:g(`[&_[data-sonner-toast]]:univer-bg-white/95 dark:[&_[data-sonner-toast]]:!univer-bg-gray-800/95 [&_[data-sonner-toast]]:univer-rounded-2xl [&_[data-sonner-toast]]:univer-border [&_[data-sonner-toast]]:univer-border-solid [&_[data-sonner-toast]]:univer-border-gray-200 [&_[data-sonner-toast]]:univer-shadow-[0_16px_40px_-20px_rgba(15,23,42,0.55)] [&_[data-sonner-toast]]:univer-backdrop-blur-sm dark:[&_[data-sonner-toast]]:!univer-border-gray-600`,e),toastOptions:{duration:yt,classNames:{toast:`
2558
+ `, allowClear && !slot && "univer-pr-8", inputClass),
2559
+ placeholder,
2560
+ value,
2561
+ disabled,
2562
+ autoFocus,
2563
+ onClick,
2564
+ onKeyDown,
2565
+ onChange: handleChange,
2566
+ onFocus,
2567
+ onBlur,
2568
+ style: {
2569
+ ...inputStyle,
2570
+ paddingRight
2571
+ },
2572
+ ...props
2573
+ }), hasSlotContent && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2574
+ className: "univer-absolute univer-right-2 univer-flex univer-items-center univer-gap-1 univer-rounded-full",
2575
+ ref: slotRef,
2576
+ children: [slot, allowClear && value && !disabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2577
+ type: "button",
2578
+ onClick: handleClear,
2579
+ className: "univer-flex univer-size-4 univer-cursor-pointer univer-items-center univer-rounded-full univer-border-none univer-bg-transparent univer-p-1 univer-text-gray-400 univer-transition-colors univer-duration-200 hover:univer-text-gray-500 focus:univer-outline-none",
2580
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CloseIcon, { className: "univer-size-3" })
2581
+ })]
2582
+ })]
2583
+ });
2584
+ });
2585
+
2586
+ //#endregion
2587
+ //#region src/components/input-number/InputNumber.tsx
2588
+ const InputNumber = (0, react.forwardRef)(({ value, defaultValue, size = "small", min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER, step = 1, precision, formatter, parser, controls = true, className, inputClassName, controlsClassName, disabled, onChange, onKeyDown, onPressEnter, onFocus, onBlur, allowEmpty = false }, ref) => {
2589
+ const [internalValue, setInternalValue] = (0, react.useState)(value !== void 0 ? value : defaultValue !== void 0 ? defaultValue : null);
2590
+ const lastValidValueRef = (0, react.useRef)(internalValue);
2591
+ const [inputValue, setInputValue] = (0, react.useState)(formatValue(internalValue));
2592
+ const inputRef = (0, react.useRef)(null);
2593
+ const longPressTimerRef = (0, react.useRef)(null);
2594
+ const longPressIntervalRef = (0, react.useRef)(null);
2595
+ const mergedRef = (node) => {
2596
+ if (ref) if (typeof ref === "function") ref(node);
2597
+ else ref.current = node;
2598
+ inputRef.current = node;
2599
+ };
2600
+ (0, react.useEffect)(() => {
2601
+ if (value !== void 0 && value !== internalValue) {
2602
+ setInternalValue(value);
2603
+ lastValidValueRef.current = value;
2604
+ setInputValue(formatValue(value));
2605
+ }
2606
+ }, [value]);
2607
+ (0, react.useEffect)(() => {
2608
+ if (internalValue !== null) lastValidValueRef.current = internalValue;
2609
+ }, [internalValue]);
2610
+ (0, react.useEffect)(() => {
2611
+ return () => {
2612
+ if (longPressTimerRef.current) clearTimeout(longPressTimerRef.current);
2613
+ if (longPressIntervalRef.current) clearInterval(longPressIntervalRef.current);
2614
+ };
2615
+ }, []);
2616
+ function formatValue(val) {
2617
+ if (val === null || val === void 0) return "";
2618
+ let formattedValue = val;
2619
+ if (precision !== void 0) formattedValue = Number(val).toFixed(precision);
2620
+ if (formatter) return formatter(formattedValue);
2621
+ return String(formattedValue);
2622
+ }
2623
+ function parseValue(val) {
2624
+ if (!val) return null;
2625
+ let parsedValue = val;
2626
+ if (parser) parsedValue = parser(val);
2627
+ try {
2628
+ const parts = parsedValue.replace(/[^\d.-]/g, "").split(".");
2629
+ const firstPart = parts[0];
2630
+ const secondPart = parts.length > 1 ? parts.slice(1).join("") : "";
2631
+ const normalizedValue = firstPart + (secondPart ? `.${secondPart}` : "");
2632
+ const num = Number(normalizedValue);
2633
+ if (Number.isNaN(num)) return null;
2634
+ let result;
2635
+ if (precision !== void 0) {
2636
+ const factor = 10 ** precision;
2637
+ const roundedNum = Math.round(num * factor) / factor;
2638
+ if (roundedNum.toString().includes("e")) result = Number.parseFloat(roundedNum.toFixed(precision));
2639
+ else result = roundedNum;
2640
+ } else if (num.toString().includes("e")) result = Number.parseFloat(num.toFixed(16).replace(/\.?0+$/, ""));
2641
+ else result = num;
2642
+ if (max !== void 0 && result > max) result = max;
2643
+ if (min !== void 0 && result < min) result = min;
2644
+ return result;
2645
+ } catch (e) {
2646
+ return null;
2647
+ }
2648
+ }
2649
+ function handleInputChange(value) {
2650
+ setInputValue(value);
2651
+ if (allowEmpty && value === "") {
2652
+ setInternalValue(null);
2653
+ onChange === null || onChange === void 0 || onChange(null);
2654
+ return;
2655
+ }
2656
+ const parsedValue = parseValue(value);
2657
+ setInternalValue(parsedValue);
2658
+ onChange === null || onChange === void 0 || onChange(parsedValue);
2659
+ }
2660
+ function handleBlur(e) {
2661
+ if (internalValue === null) {
2662
+ if (inputValue === "" && allowEmpty) {
2663
+ if (onChange) onChange(null);
2664
+ } else {
2665
+ const valueToRestore = lastValidValueRef.current;
2666
+ setInternalValue(valueToRestore);
2667
+ setInputValue(formatValue(valueToRestore));
2668
+ if (onChange) onChange(valueToRestore);
2669
+ }
2670
+ onBlur === null || onBlur === void 0 || onBlur(e);
2671
+ return;
2672
+ }
2673
+ let valueInRange = internalValue;
2674
+ if (max !== void 0 && valueInRange > max) valueInRange = max;
2675
+ if (min !== void 0 && valueInRange < min) valueInRange = min;
2676
+ if (valueInRange !== internalValue) {
2677
+ setInternalValue(valueInRange);
2678
+ setInputValue(formatValue(valueInRange));
2679
+ onChange === null || onChange === void 0 || onChange(valueInRange);
2680
+ } else setInputValue(formatValue(internalValue));
2681
+ onBlur === null || onBlur === void 0 || onBlur(e);
2682
+ }
2683
+ function handleStep(isUp) {
2684
+ if (disabled) return;
2685
+ const stepValue = isUp ? step : -step;
2686
+ let currentValue;
2687
+ if (internalValue !== null) currentValue = internalValue;
2688
+ else if (lastValidValueRef.current !== null) currentValue = lastValidValueRef.current;
2689
+ else currentValue = min > 0 ? min : 0;
2690
+ let newValue = currentValue + stepValue;
2691
+ if (max !== void 0 && newValue > max) newValue = max;
2692
+ if (min !== void 0 && newValue < min) newValue = min;
2693
+ if (newValue === currentValue) return;
2694
+ setInternalValue(newValue);
2695
+ lastValidValueRef.current = newValue;
2696
+ setInputValue(formatValue(newValue));
2697
+ onChange === null || onChange === void 0 || onChange(newValue);
2698
+ }
2699
+ function handleKeyDown(e) {
2700
+ if (disabled) return;
2701
+ onKeyDown === null || onKeyDown === void 0 || onKeyDown(e);
2702
+ if (e.key === "ArrowUp") {
2703
+ e.preventDefault();
2704
+ handleStep(true);
2705
+ } else if (e.key === "ArrowDown") {
2706
+ e.preventDefault();
2707
+ handleStep(false);
2708
+ } else if (e.key === "Enter") onPressEnter === null || onPressEnter === void 0 || onPressEnter(e);
2709
+ }
2710
+ function handleClick(isUp) {
2711
+ var _inputRef$current;
2712
+ if (disabled) return;
2713
+ handleStep(isUp);
2714
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
2715
+ }
2716
+ const incrementDisabled = disabled || max !== void 0 && internalValue !== null && internalValue >= max;
2717
+ const decrementDisabled = disabled || min !== void 0 && internalValue !== null && internalValue <= min;
2718
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2719
+ className: clsx$1("univer-inline-block", className),
2720
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2721
+ className: "univer-relative univer-w-full",
2722
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Input, {
2723
+ ref: mergedRef,
2724
+ className: clsx$1("univer-box-border", inputClassName),
2725
+ size,
2726
+ value: inputValue,
2727
+ disabled,
2728
+ onChange: handleInputChange,
2729
+ onFocus,
2730
+ onBlur: handleBlur,
2731
+ onKeyDown: handleKeyDown
2732
+ }), controls && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2733
+ className: clsx$1("univer-absolute univer-right-px univer-top-px univer-flex univer-h-[calc(100%-2px)] univer-flex-col univer-overflow-hidden univer-rounded-r-md before:univer-absolute before:univer-top-1/2 before:univer-block before:univer-h-px before:univer-w-full before:-univer-translate-y-1/2 before:univer-bg-gray-200 before:univer-content-[\"\"] rtl:univer-left-px rtl:univer-right-auto rtl:univer-rounded-l-md rtl:univer-rounded-r-none dark:before:!univer-bg-gray-600", borderLeftClassName, borderLeftRTLClassName, controlsClassName),
2734
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2735
+ className: clsx$1("univer-box-border univer-flex univer-h-1/2 univer-w-5 univer-cursor-pointer univer-items-center univer-justify-center univer-border-none univer-bg-transparent univer-p-0 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-600", incrementDisabled && "univer-cursor-not-allowed univer-opacity-60"),
2736
+ role: "button",
2737
+ "aria-label": "increment",
2738
+ "aria-disabled": incrementDisabled,
2739
+ tabIndex: -1,
2740
+ onMouseDown: (e) => e.preventDefault(),
2741
+ onClick: () => {
2742
+ if (incrementDisabled) return;
2743
+ handleClick(true);
2744
+ },
2745
+ children: "+"
2746
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2747
+ className: clsx$1("univer-box-border univer-flex univer-h-1/2 univer-w-5 univer-cursor-pointer univer-items-center univer-justify-center univer-border-none univer-bg-transparent univer-p-0 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-600", decrementDisabled && "univer-cursor-not-allowed univer-opacity-60"),
2748
+ role: "button",
2749
+ "aria-label": "decrement",
2750
+ "aria-disabled": decrementDisabled,
2751
+ tabIndex: -1,
2752
+ onMouseDown: (e) => e.preventDefault(),
2753
+ onClick: () => {
2754
+ if (decrementDisabled) return;
2755
+ handleClick(false);
2756
+ },
2757
+ children: "-"
2758
+ })]
2759
+ })]
2760
+ })
2761
+ });
2762
+ });
2763
+
2764
+ //#endregion
2765
+ //#region src/components/segmented/Segmented.tsx
2766
+ function Segmented({ items, value, defaultValue, onChange, className = "" }) {
2767
+ const [selectedItem, setSelectedItem] = (0, react.useState)(value !== void 0 ? value : defaultValue || items[0].value);
2768
+ const [slideStyle, setSlideStyle] = (0, react.useState)({});
2769
+ const itemRefs = (0, react.useRef)(/* @__PURE__ */ new Map());
2770
+ const containerRef = (0, react.useRef)(null);
2771
+ (0, react.useEffect)(() => {
2772
+ if (value !== void 0 && value !== selectedItem) setSelectedItem(value);
2773
+ }, [value]);
2774
+ const updateSliderPosition = (newValue, oldValue) => {
2775
+ const newItemElement = itemRefs.current.get(newValue);
2776
+ const oldItemElement = oldValue ? itemRefs.current.get(oldValue) : null;
2777
+ if (newItemElement && containerRef.current) {
2778
+ const containerRect = containerRef.current.getBoundingClientRect();
2779
+ const newRect = newItemElement.getBoundingClientRect();
2780
+ const newLeft = newRect.left - containerRect.left - 4;
2781
+ if (oldItemElement) setSlideStyle({
2782
+ "--slide-from": `${oldItemElement.getBoundingClientRect().left - containerRect.left - 4}px`,
2783
+ "--slide-to": `${newLeft}px`,
2784
+ width: `${newRect.width}px`,
2785
+ transform: `translateX(${newLeft}px)`
2786
+ });
2787
+ else setSlideStyle({
2788
+ width: `${newRect.width}px`,
2789
+ transform: `translateX(${newLeft}px)`
2790
+ });
2791
+ }
2792
+ };
2793
+ (0, react.useEffect)(() => {
2794
+ updateSliderPosition(selectedItem);
2795
+ }, [selectedItem]);
2796
+ const handleClick = (itemValue) => {
2797
+ const oldValue = selectedItem;
2798
+ setSelectedItem(itemValue);
2799
+ onChange === null || onChange === void 0 || onChange(itemValue);
2800
+ updateSliderPosition(itemValue, oldValue);
2801
+ };
2802
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2803
+ "data-u-comp": "segmented",
2804
+ ref: containerRef,
2805
+ className: clsx$1("univer-relative univer-box-border univer-flex univer-gap-4 univer-rounded-lg univer-bg-gray-100 univer-p-1 dark:!univer-bg-gray-800", className),
2806
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2807
+ className: "univer-animate-univer-slide univer-absolute univer-h-6 univer-rounded-md univer-bg-white univer-shadow-sm univer-transition-all univer-duration-200 dark:!univer-bg-gray-700 dark:!univer-text-gray-400",
2808
+ style: slideStyle
2809
+ }), items.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2810
+ ref: (el) => {
2811
+ if (el) itemRefs.current.set(item.value, el);
2812
+ },
2813
+ className: clsx$1("univer-relative univer-box-border univer-flex-1 univer-cursor-pointer univer-border-none univer-bg-transparent univer-px-3 univer-py-1 univer-text-xs univer-font-medium univer-transition-colors", {
2814
+ "univer-text-gray-900 dark:!univer-text-white": selectedItem === item.value,
2815
+ "univer-text-gray-500 hover:univer-text-gray-900 dark:hover:!univer-text-white": selectedItem !== item.value
2816
+ }),
2817
+ type: "button",
2818
+ onClick: () => handleClick(item.value),
2819
+ children: item.label
2820
+ }, String(item.value)))]
2821
+ });
2822
+ }
2823
+
2824
+ //#endregion
2825
+ //#region src/components/tooltip/Tooltip.tsx
2826
+ function Tooltip(props) {
2827
+ const { children, className, asChild = true, title, placement = "bottom", showIfEllipsis = false, visible: controlledVisible, onVisibleChange } = props;
2828
+ const [uncontrolledVisible, setUncontrolledVisible] = (0, react.useState)(false);
2829
+ const isControlled = controlledVisible !== void 0;
2830
+ const visible = isControlled ? controlledVisible : uncontrolledVisible;
2831
+ const triggerRef = (0, react.useRef)(null);
2832
+ const tooltipRef = (0, react.useRef)(null);
2833
+ const arrowRef = (0, react.useRef)(null);
2834
+ const [coords, setCoords] = (0, react.useState)(null);
2835
+ const [currentPlacement, setCurrentPlacement] = (0, react.useState)(placement);
2836
+ function isContentOverflowing(element) {
2837
+ return Math.abs(element.scrollWidth - element.clientWidth) > 1;
2838
+ }
2839
+ function showTooltip() {
2840
+ if (isControlled) onVisibleChange === null || onVisibleChange === void 0 || onVisibleChange(true);
2841
+ else setUncontrolledVisible(true);
2842
+ }
2843
+ function hideTooltip() {
2844
+ if (isControlled) onVisibleChange === null || onVisibleChange === void 0 || onVisibleChange(false);
2845
+ else setUncontrolledVisible(false);
2846
+ }
2847
+ (0, react.useLayoutEffect)(() => {
2848
+ if (!visible) return;
2849
+ const trigger = triggerRef.current;
2850
+ const tip = tooltipRef.current;
2851
+ if (!trigger || !tip) return;
2852
+ const triggerRect = trigger.getBoundingClientRect();
2853
+ const tipRect = tip.getBoundingClientRect();
2854
+ const offset = 8;
2855
+ const viewportWidth = window.innerWidth;
2856
+ const viewportHeight = window.innerHeight;
2857
+ const placements = [
2858
+ placement,
2859
+ "bottom",
2860
+ "top",
2861
+ "right",
2862
+ "left"
2863
+ ];
2864
+ let chosen = placement;
2865
+ let top = 0;
2866
+ let left = 0;
2867
+ const computeFor = (p) => {
2868
+ let t = 0;
2869
+ let l = 0;
2870
+ if (p === "bottom") {
2871
+ t = triggerRect.bottom + offset;
2872
+ l = triggerRect.left + triggerRect.width / 2 - tipRect.width / 2;
2873
+ } else if (p === "top") {
2874
+ t = triggerRect.top - tipRect.height - offset;
2875
+ l = triggerRect.left + triggerRect.width / 2 - tipRect.width / 2;
2876
+ } else if (p === "left") {
2877
+ t = triggerRect.top + triggerRect.height / 2 - tipRect.height / 2;
2878
+ l = triggerRect.left - tipRect.width - offset;
2879
+ } else {
2880
+ t = triggerRect.top + triggerRect.height / 2 - tipRect.height / 2;
2881
+ l = triggerRect.right + offset;
2882
+ }
2883
+ return {
2884
+ t,
2885
+ l
2886
+ };
2887
+ };
2888
+ for (const p of placements) {
2889
+ const { t, l } = computeFor(p);
2890
+ const fitsHorizontally = l >= 0 && l + tipRect.width <= viewportWidth;
2891
+ const fitsVertically = t >= 0 && t + tipRect.height <= viewportHeight;
2892
+ if (fitsHorizontally && fitsVertically) {
2893
+ chosen = p;
2894
+ top = t;
2895
+ left = l;
2896
+ break;
2897
+ }
2898
+ }
2899
+ if (!top && !left) {
2900
+ const c = computeFor(placement);
2901
+ top = Math.min(Math.max(0, c.t), viewportHeight - tipRect.height);
2902
+ left = Math.min(Math.max(0, c.l), viewportWidth - tipRect.width);
2903
+ }
2904
+ setCurrentPlacement(chosen);
2905
+ setCoords({
2906
+ top: Math.round(top + window.scrollY),
2907
+ left: Math.round(left + window.scrollX)
2908
+ });
2909
+ }, [visible, placement]);
2910
+ (0, react.useEffect)(() => {
2911
+ if (!visible) return;
2912
+ const handler = () => {
2913
+ if (!triggerRef.current || !tooltipRef.current) return;
2914
+ const triggerRect = triggerRef.current.getBoundingClientRect();
2915
+ const tipRect = tooltipRef.current.getBoundingClientRect();
2916
+ const offset = 8;
2917
+ let top = 0;
2918
+ let left = 0;
2919
+ if (currentPlacement === "bottom") {
2920
+ top = triggerRect.bottom + offset;
2921
+ left = triggerRect.left + triggerRect.width / 2 - tipRect.width / 2;
2922
+ } else if (currentPlacement === "top") {
2923
+ top = triggerRect.top - tipRect.height - offset;
2924
+ left = triggerRect.left + triggerRect.width / 2 - tipRect.width / 2;
2925
+ } else if (currentPlacement === "left") {
2926
+ top = triggerRect.top + triggerRect.height / 2 - tipRect.height / 2;
2927
+ left = triggerRect.left - tipRect.width - offset;
2928
+ } else {
2929
+ top = triggerRect.top + triggerRect.height / 2 - tipRect.height / 2;
2930
+ left = triggerRect.right + offset;
2931
+ }
2932
+ setCoords({
2933
+ top: Math.round(top + window.scrollY),
2934
+ left: Math.round(left + window.scrollX)
2935
+ });
2936
+ };
2937
+ window.addEventListener("scroll", handler, true);
2938
+ window.addEventListener("resize", handler);
2939
+ return () => {
2940
+ window.removeEventListener("scroll", handler, true);
2941
+ window.removeEventListener("resize", handler);
2942
+ };
2943
+ }, [visible, currentPlacement]);
2944
+ const commonProps = {
2945
+ ref: (node) => triggerRef.current = node,
2946
+ onMouseEnter: () => {
2947
+ if (showIfEllipsis && triggerRef.current) {
2948
+ if (!isContentOverflowing(triggerRef.current)) return;
2949
+ }
2950
+ showTooltip();
2951
+ },
2952
+ onMouseLeave: () => hideTooltip(),
2953
+ onFocus: () => showTooltip(),
2954
+ onBlur: () => hideTooltip()
2955
+ };
2956
+ const triggerElement = asChild ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2957
+ ...commonProps,
2958
+ className: "univer-inline-block univer-max-w-full univer-truncate",
2959
+ children
2960
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2961
+ type: "button",
2962
+ ...commonProps,
2963
+ children
2964
+ });
2965
+ let tooltipNode = null;
2966
+ if (typeof document !== "undefined" && visible && title && document.body) {
2967
+ var _coords$top, _coords$left;
2968
+ tooltipNode = (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2969
+ ref: tooltipRef,
2970
+ role: "tooltip",
2971
+ className: clsx$1("univer-animate-in univer-fade-in-0 univer-zoom-in-95 univer-pointer-events-auto univer-absolute univer-z-[1081] univer-box-border univer-w-fit univer-max-w-sm univer-text-balance univer-rounded-lg univer-bg-gray-700 univer-px-2.5 univer-py-2 univer-text-xs univer-font-medium univer-text-white univer-shadow-lg univer-drop-shadow-sm dark:!univer-bg-gray-100 dark:!univer-text-gray-900", className),
2972
+ style: {
2973
+ top: (_coords$top = coords === null || coords === void 0 ? void 0 : coords.top) !== null && _coords$top !== void 0 ? _coords$top : -9999,
2974
+ left: (_coords$left = coords === null || coords === void 0 ? void 0 : coords.left) !== null && _coords$left !== void 0 ? _coords$left : -9999
2975
+ },
2976
+ onMouseEnter: () => showTooltip(),
2977
+ onMouseLeave: () => hideTooltip(),
2978
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2979
+ className: "univer-break-words",
2980
+ children: title
2981
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2982
+ ref: arrowRef,
2983
+ className: "univer-absolute univer-size-2.5 univer-rotate-45 univer-rounded-sm univer-bg-gray-700 dark:!univer-bg-gray-100",
2984
+ style: {
2985
+ ...currentPlacement === "bottom" && {
2986
+ top: -5,
2987
+ left: "50%",
2988
+ transform: "translateX(-50%) rotate(45deg)"
2989
+ },
2990
+ ...currentPlacement === "top" && {
2991
+ bottom: -5,
2992
+ left: "50%",
2993
+ transform: "translateX(-50%) rotate(45deg)"
2994
+ },
2995
+ ...currentPlacement === "left" && {
2996
+ right: -5,
2997
+ top: "50%",
2998
+ transform: "translateY(-50%) rotate(45deg)"
2999
+ },
3000
+ ...currentPlacement === "right" && {
3001
+ left: -5,
3002
+ top: "50%",
3003
+ transform: "translateY(-50%) rotate(45deg)"
3004
+ }
3005
+ }
3006
+ })]
3007
+ }), document.body);
3008
+ }
3009
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [triggerElement, tooltipNode] });
3010
+ }
3011
+
3012
+ //#endregion
3013
+ //#region src/components/gradient-color-picker/GradientColorPicker.tsx
3014
+ /**
3015
+ * Copyright 2023-present DreamNum Co., Ltd.
3016
+ *
3017
+ * Licensed under the Apache License, Version 2.0 (the "License");
3018
+ * you may not use this file except in compliance with the License.
3019
+ * You may obtain a copy of the License at
3020
+ *
3021
+ * http://www.apache.org/licenses/LICENSE-2.0
3022
+ *
3023
+ * Unless required by applicable law or agreed to in writing, software
3024
+ * distributed under the License is distributed on an "AS IS" BASIS,
3025
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3026
+ * See the License for the specific language governing permissions and
3027
+ * limitations under the License.
3028
+ */
3029
+ const DEFAULT_VALUE = {
3030
+ type: "linear",
3031
+ stops: [{
3032
+ color: "#ffffff",
3033
+ offset: 0
3034
+ }, {
3035
+ color: "#000000",
3036
+ offset: 100
3037
+ }],
3038
+ angle: 90
3039
+ };
3040
+ function GradientColorPicker(props) {
3041
+ var _value$stops$selected, _value$stops$selected2;
3042
+ const { className, value = DEFAULT_VALUE, onChange } = props;
3043
+ const { locale } = (0, react.useContext)(ConfigContext);
3044
+ const [selectedIndex, setSelectedIndex] = (0, react.useState)(0);
3045
+ const barRef = (0, react.useRef)(null);
3046
+ const stops = (0, react.useMemo)(() => {
3047
+ return [...value.stops].sort((a, b) => a.offset - b.offset);
3048
+ }, [value.stops]);
3049
+ const handleTypeChange = (type) => {
3050
+ onChange === null || onChange === void 0 || onChange({
3051
+ ...value,
3052
+ type
3053
+ });
3054
+ };
3055
+ const handleAngleChange = (angle) => {
3056
+ onChange === null || onChange === void 0 || onChange({
3057
+ ...value,
3058
+ angle: angle !== null && angle !== void 0 ? angle : 0
3059
+ });
3060
+ };
3061
+ const handleStopColorChange = (color) => {
3062
+ const newStops = [...value.stops];
3063
+ newStops[selectedIndex] = {
3064
+ ...newStops[selectedIndex],
3065
+ color
3066
+ };
3067
+ onChange === null || onChange === void 0 || onChange({
3068
+ ...value,
3069
+ stops: newStops
3070
+ });
3071
+ };
3072
+ const handleStopOffsetChange = (offset) => {
3073
+ if (offset === null) return;
3074
+ const newStops = [...value.stops];
3075
+ newStops[selectedIndex] = {
3076
+ ...newStops[selectedIndex],
3077
+ offset
3078
+ };
3079
+ onChange === null || onChange === void 0 || onChange({
3080
+ ...value,
3081
+ stops: newStops
3082
+ });
3083
+ };
3084
+ const handleAddStop = (e) => {
3085
+ if (!barRef.current) return;
3086
+ const rect = barRef.current.getBoundingClientRect();
3087
+ const offset = Math.round((e.clientX - rect.left) / rect.width * 100);
3088
+ const newStop = {
3089
+ color: ([...stops].reverse().find((s) => s.offset <= offset) || stops[0]).color,
3090
+ offset
3091
+ };
3092
+ const newStops = [...value.stops, newStop];
3093
+ onChange === null || onChange === void 0 || onChange({
3094
+ ...value,
3095
+ stops: newStops
3096
+ });
3097
+ setSelectedIndex(newStops.length - 1);
3098
+ };
3099
+ const handleRemoveStop = () => {
3100
+ if (value.stops.length <= 2) return;
3101
+ const newStops = value.stops.filter((_, i) => i !== selectedIndex);
3102
+ onChange === null || onChange === void 0 || onChange({
3103
+ ...value,
3104
+ stops: newStops
3105
+ });
3106
+ setSelectedIndex(0);
3107
+ };
3108
+ const gradientPreview = (0, react.useMemo)(() => {
3109
+ return `linear-gradient(to right, ${stops.map((s) => `${s.color} ${s.offset}%`).join(", ")})`;
3110
+ }, [stops]);
3111
+ const mainPreview = (0, react.useMemo)(() => {
3112
+ const stopsStr = stops.map((s) => `${s.color} ${s.offset}%`).join(", ");
3113
+ switch (value.type) {
3114
+ case "linear": return `linear-gradient(${value.angle}deg, ${stopsStr})`;
3115
+ case "radial": return `radial-gradient(circle, ${stopsStr})`;
3116
+ case "angular": return `conic-gradient(from ${value.angle}deg, ${stopsStr})`;
3117
+ case "diamond": return `radial-gradient(circle, ${stopsStr})`;
3118
+ default: return `linear-gradient(${value.angle}deg, ${stopsStr})`;
3119
+ }
3120
+ }, [value, stops]);
3121
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3122
+ className: clsx$1("univer-flex univer-w-64 univer-flex-col univer-gap-4 univer-rounded-lg univer-bg-white univer-p-4 univer-shadow-lg dark:!univer-bg-gray-800", className),
3123
+ children: [
3124
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Segmented, {
3125
+ items: [
3126
+ {
3127
+ label: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.linear,
3128
+ value: "linear"
3129
+ },
3130
+ {
3131
+ label: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.radial,
3132
+ value: "radial"
3133
+ },
3134
+ {
3135
+ label: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.angular,
3136
+ value: "angular"
3137
+ },
3138
+ {
3139
+ label: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.diamond,
3140
+ value: "diamond"
3141
+ }
3142
+ ],
3143
+ value: value.type,
3144
+ onChange: (v) => handleTypeChange(v)
3145
+ }),
3146
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3147
+ className: "univer-h-32 univer-w-full univer-rounded-md univer-border univer-border-gray-200 dark:!univer-border-gray-600",
3148
+ style: { background: mainPreview }
3149
+ }),
3150
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3151
+ className: "univer-relative univer-mt-4 univer-h-6",
3152
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3153
+ ref: barRef,
3154
+ className: "univer-absolute univer-inset-x-0 univer-top-1/2 univer-h-2 -univer-translate-y-1/2 univer-cursor-crosshair univer-rounded-full",
3155
+ style: { background: gradientPreview },
3156
+ onClick: handleAddStop
3157
+ }), value.stops.map((stop, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3158
+ className: clsx$1("univer-absolute univer-top-1/2 univer-size-4 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-cursor-pointer univer-rounded-full univer-border-2 univer-border-white univer-shadow-md", selectedIndex === index ? "univer-z-10 univer-ring-2 univer-ring-primary-500" : "univer-z-0"),
3159
+ style: {
3160
+ left: `${stop.offset}%`,
3161
+ backgroundColor: stop.color
3162
+ },
3163
+ onClick: (e) => {
3164
+ e.stopPropagation();
3165
+ setSelectedIndex(index);
3166
+ },
3167
+ onPointerDown: (e) => {
3168
+ const startX = e.clientX;
3169
+ const startOffset = stop.offset;
3170
+ const handlePointerMove = (moveEvent) => {
3171
+ if (!barRef.current) return;
3172
+ const rect = barRef.current.getBoundingClientRect();
3173
+ const deltaOffset = (moveEvent.clientX - startX) / rect.width * 100;
3174
+ const newOffset = Math.max(0, Math.min(100, Math.round(startOffset + deltaOffset)));
3175
+ const newStops = [...value.stops];
3176
+ newStops[index] = {
3177
+ ...newStops[index],
3178
+ offset: newOffset
3179
+ };
3180
+ onChange === null || onChange === void 0 || onChange({
3181
+ ...value,
3182
+ stops: newStops
3183
+ });
3184
+ };
3185
+ const handlePointerUp = () => {
3186
+ window.removeEventListener("pointermove", handlePointerMove);
3187
+ window.removeEventListener("pointerup", handlePointerUp);
3188
+ };
3189
+ window.addEventListener("pointermove", handlePointerMove);
3190
+ window.addEventListener("pointerup", handlePointerUp);
3191
+ }
3192
+ }, index))]
3193
+ }),
3194
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3195
+ className: "univer-flex univer-items-end univer-gap-2",
3196
+ children: [
3197
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3198
+ className: "univer-flex-1",
3199
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3200
+ className: "univer-mb-1 univer-text-xs univer-text-gray-500",
3201
+ children: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.offset
3202
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InputNumber, {
3203
+ value: (_value$stops$selected = value.stops[selectedIndex]) === null || _value$stops$selected === void 0 ? void 0 : _value$stops$selected.offset,
3204
+ min: 0,
3205
+ max: 100,
3206
+ onChange: handleStopOffsetChange
3207
+ })]
3208
+ }),
3209
+ (value.type === "linear" || value.type === "angular") && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3210
+ className: "univer-flex-1",
3211
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3212
+ className: "univer-mb-1 univer-text-xs univer-text-gray-500",
3213
+ children: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.angle
3214
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InputNumber, {
3215
+ value: value.angle,
3216
+ min: 0,
3217
+ max: 360,
3218
+ onChange: handleAngleChange
3219
+ })]
3220
+ }),
3221
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3222
+ className: "univer-flex univer-gap-1",
3223
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Tooltip, {
3224
+ title: locale === null || locale === void 0 ? void 0 : locale.GradientColorPicker.delete,
3225
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
3226
+ variant: "danger",
3227
+ onClick: handleRemoveStop,
3228
+ disabled: value.stops.length <= 2,
3229
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, {})
3230
+ })
3231
+ })
3232
+ })
3233
+ ]
3234
+ }),
3235
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3236
+ className: "univer-border-t univer-border-gray-100 univer-pt-4 dark:!univer-border-gray-700",
3237
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ColorPicker, {
3238
+ value: (_value$stops$selected2 = value.stops[selectedIndex]) === null || _value$stops$selected2 === void 0 ? void 0 : _value$stops$selected2.color,
3239
+ onChange: handleStopColorChange
3240
+ })
3241
+ })
3242
+ ]
3243
+ });
3244
+ }
3245
+
3246
+ //#endregion
3247
+ //#region src/components/hover-card/HoverCardPrimitive.tsx
3248
+ const HoverCardPrimitive = _radix_ui_react_hover_card.Root;
3249
+ const HoverCardPortal = _radix_ui_react_hover_card.Portal;
3250
+ const HoverCardTrigger = _radix_ui_react_hover_card.Trigger;
3251
+ const HoverCardContent = (0, react.forwardRef)(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_hover_card.Content, {
3252
+ ref,
3253
+ align,
3254
+ sideOffset,
3255
+ className: clsx$1("data-[state=open]:univer-animate-in data-[state=open]:univer-fade-in-0 data-[state=open]:univer-zoom-in-95 data-[state=closed]:univer-animate-out data-[state=closed]:univer-fade-out-0 data-[state=closed]:univer-zoom-out-95 data-[side=bottom]:univer-slide-in-from-top-2 data-[side=left]:univer-slide-in-from-right-2 data-[side=right]:univer-slide-in-from-left-2 data-[side=top]:univer-slide-in-from-bottom-2 univer-z-[1080] univer-w-64 univer-origin-[--radix-hover-card-content-transform-origin] univer-rounded-md univer-bg-white univer-text-gray-900 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900 dark:!univer-text-white", borderClassName, className),
3256
+ ...props
3257
+ }));
3258
+ HoverCardContent.displayName = _radix_ui_react_hover_card.Content.displayName;
3259
+
3260
+ //#endregion
3261
+ //#region src/components/hover-card/HoverCard.tsx
3262
+ function HoverCard(props) {
3263
+ const { children, overlay, disabled, openDelay = 200, open: controlledOpen, onOpenChange: controlledOnOpenChange, ...restProps } = props;
3264
+ const [uncontrolledOpen, setUncontrolledOpen] = (0, react.useState)(false);
3265
+ const isControlled = controlledOpen !== void 0;
3266
+ const open = isControlled ? controlledOpen : uncontrolledOpen;
3267
+ function handleChangeOpen(newOpen) {
3268
+ if (disabled) return;
3269
+ if (!isControlled) setUncontrolledOpen(newOpen);
3270
+ controlledOnOpenChange === null || controlledOnOpenChange === void 0 || controlledOnOpenChange(newOpen);
3271
+ }
3272
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(HoverCardPrimitive, {
3273
+ open,
3274
+ onOpenChange: handleChangeOpen,
3275
+ openDelay,
3276
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(HoverCardTrigger, {
3277
+ asChild: true,
3278
+ children
3279
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HoverCardPortal, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HoverCardContent, {
3280
+ ...restProps,
3281
+ children: overlay
3282
+ }) })]
3283
+ });
3284
+ }
3285
+
3286
+ //#endregion
3287
+ //#region src/components/kbd/Kbd.tsx
3288
+ /**
3289
+ * Copyright 2023-present DreamNum Co., Ltd.
3290
+ *
3291
+ * Licensed under the Apache License, Version 2.0 (the "License");
3292
+ * you may not use this file except in compliance with the License.
3293
+ * You may obtain a copy of the License at
3294
+ *
3295
+ * http://www.apache.org/licenses/LICENSE-2.0
3296
+ *
3297
+ * Unless required by applicable law or agreed to in writing, software
3298
+ * distributed under the License is distributed on an "AS IS" BASIS,
3299
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3300
+ * See the License for the specific language governing permissions and
3301
+ * limitations under the License.
3302
+ */
3303
+ function KBD(props) {
3304
+ const { keyboard, className } = props;
3305
+ const keys = keyboard.split("+");
3306
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3307
+ className: clsx$1("univer-inline-block univer-h-6 univer-select-none univer-whitespace-nowrap univer-rounded-md univer-bg-gray-50 univer-px-2 univer-font-mono univer-text-xs/6 univer-font-medium univer-text-gray-700 dark:!univer-bg-gray-700 dark:!univer-text-white", borderClassName, className),
3308
+ children: keys.map((text, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("kbd", {
3309
+ className: "univer-inline-block univer-h-full",
3310
+ children: text
3311
+ }), index < keys.length - 1 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3312
+ className: "univer-inline-block univer-h-full univer-px-1",
3313
+ children: "+"
3314
+ })] }, index))
3315
+ });
3316
+ }
3317
+
3318
+ //#endregion
3319
+ //#region src/components/message/Message.tsx
3320
+ let MessageType = /* @__PURE__ */ function(MessageType) {
3321
+ MessageType["Success"] = "success";
3322
+ MessageType["Info"] = "info";
3323
+ MessageType["Warning"] = "warning";
3324
+ MessageType["Error"] = "error";
3325
+ MessageType["Loading"] = "loading";
3326
+ return MessageType;
3327
+ }({});
3328
+ const MESSAGE_TOASTER_ID = "univer-message-toaster";
3329
+ const DEFAULT_MESSAGE_DURATION = 3e3;
3330
+ const activeMessageIds = /* @__PURE__ */ new Set();
3331
+ const loadingIcon = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.LoadingMultiIcon, { className: "univer-animate-spin univer-text-violet-500" });
3332
+ let messageCount = 0;
3333
+ const iconMap = {
3334
+ [MessageType.Success]: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.SuccessIcon, { className: "univer-text-green-500" }),
3335
+ [MessageType.Info]: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.InfoIcon, { className: "univer-text-sky-500 dark:!univer-text-sky-400" }),
3336
+ [MessageType.Warning]: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.WarningIcon, { className: "univer-text-amber-500" }),
3337
+ [MessageType.Error]: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.ErrorIcon, { className: "univer-text-red-500" }),
3338
+ [MessageType.Loading]: loadingIcon
3339
+ };
3340
+ const typeClassMap = {
3341
+ [MessageType.Success]: "[&_[data-icon]]:univer-text-green-500",
3342
+ [MessageType.Info]: "[&_[data-icon]]:univer-text-sky-500",
3343
+ [MessageType.Warning]: "[&_[data-icon]]:univer-text-amber-500",
3344
+ [MessageType.Error]: "[&_[data-icon]]:univer-text-red-500",
3345
+ [MessageType.Loading]: "[&_[data-icon]]:univer-text-violet-500"
3346
+ };
3347
+ const resolveToastMethod = (type) => {
3348
+ switch (type) {
3349
+ case MessageType.Success: return sonner.toast.success;
3350
+ case MessageType.Warning: return sonner.toast.warning;
3351
+ case MessageType.Error: return sonner.toast.error;
3352
+ case MessageType.Loading: return sonner.toast.loading;
3353
+ case MessageType.Info:
3354
+ default: return sonner.toast.info;
3355
+ }
3356
+ };
3357
+ const createMessageId = () => {
3358
+ const id = `univer-message-${messageCount}`;
3359
+ messageCount += 1;
3360
+ return id;
3361
+ };
3362
+ const Messager = ({ className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(sonner.Toaster, {
3363
+ id: MESSAGE_TOASTER_ID,
3364
+ position: "top-center",
3365
+ visibleToasts: 4,
3366
+ closeButton: false,
3367
+ expand: false,
3368
+ icons: { loading: loadingIcon },
3369
+ offset: { top: 16 },
3370
+ className: clsx$1("[&_[data-sonner-toast]]:univer-bg-white/95 dark:[&_[data-sonner-toast]]:!univer-bg-gray-800/95 [&_[data-sonner-toast]]:univer-rounded-2xl [&_[data-sonner-toast]]:univer-border [&_[data-sonner-toast]]:univer-border-solid [&_[data-sonner-toast]]:univer-border-gray-200 [&_[data-sonner-toast]]:univer-shadow-[0_16px_40px_-20px_rgba(15,23,42,0.55)] [&_[data-sonner-toast]]:univer-backdrop-blur-sm dark:[&_[data-sonner-toast]]:!univer-border-gray-600", className),
3371
+ toastOptions: {
3372
+ duration: DEFAULT_MESSAGE_DURATION,
3373
+ classNames: {
3374
+ toast: `
73
3375
  univer-group univer-min-h-0 univer-min-w-[320px] univer-max-w-[520px] univer-px-3.5 univer-py-3
74
3376
  univer-font-sans univer-transition-all univer-duration-300
75
- `,title:`
3377
+ `,
3378
+ title: `
76
3379
  univer-m-0 univer-font-sans univer-text-sm univer-font-medium univer-leading-5 univer-text-gray-700
77
3380
  dark:!univer-text-gray-100
78
- `,content:`univer-gap-2.5`,icon:`[&>svg]:univer-block [&>svg]:univer-size-4`,success:X[J.Success],info:X[J.Info],warning:X[J.Warning],error:X[J.Error],loading:X[J.Loading]}},...t}),Et=({content:e,duration:t,id:n,onClose:r,type:i=J.Info})=>{let a=n==null?wt():n,o=Ct(i),s=!1,c=()=>{s||(s=!0,Y.delete(a),r==null||r())};return o(e,{id:a,toasterId:vt,duration:t==null?yt:t,icon:i===J.Loading?void 0:St[i],onDismiss:c,onAutoClose:c}),Y.add(a),a},Dt=e=>{if(e!==void 0){f.toast.dismiss(e),Y.delete(e);return}Y.forEach(e=>{f.toast.dismiss(e)}),Y.clear()},Ot=[-9999,-9999];function kt(e){let{children:n,visible:r=!1,offset:a=[0,0],overflowVisible:o=!1,placementY:s=`below`}=e,c=(0,t.useRef)(null),[u,d]=(0,t.useState)(Ot),{mountContainer:f}=(0,t.useContext)(T),m=()=>{let e=c.current;if(!e)return null;let[t,n]=a,{clientWidth:r,clientHeight:i}=e,{innerWidth:o,innerHeight:l}=window,u=Math.max(0,o-r-2),d=Math.max(0,l-i-2),f=Math.min(Math.max(t,0),u),p=s===`above`?n-i:n;return[f,Math.min(Math.max(p,0),d)]};(0,t.useLayoutEffect)(()=>{if(!r){d(Ot);return}let e=m();e&&d(e)},[a,s,r]),(0,t.useEffect)(()=>{if(!r)return;let e=()=>{let e=m();e&&d(e)};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[a,s,r]);function h(e){e.preventDefault()}return(0,l.createPortal)((0,i.jsx)(p.CSSTransition,{in:r,nodeRef:c,timeout:500,classNames:{enter:`univer-popup-enter`,enterActive:`univer-popup-enter-active`,enterDone:`univer-popup-enter-done`,exitActive:`univer-popup-exit`,exitDone:`univer-popup-exit-active`},children:(0,i.jsx)(`section`,{ref:c,className:`univer-popup`,style:{left:u[0]+2,top:u[1]+2,overflow:o?`visible`:void 0},onContextMenu:h,children:n})}),f)}function At(e){let{children:n,className:r,style:a,value:o,disabled:s=!1,direction:c=`horizontal`,onChange:l}=e,u=e=>{l(e)};return(0,i.jsx)(`div`,{className:g(`univer-flex univer-gap-2`,{"univer-flex-col":c===`vertical`},r),style:a,children:t.Children.map(n,(e,n)=>(0,t.isValidElement)(e)?(0,t.cloneElement)(e,{key:n,children:e.props.children,value:e.props.value,checked:o===e.props.value,disabled:s==null?e.props.disabled:s,onChange:u}):e)})}function jt(e){let{children:n,checked:r,value:a,disabled:o=!1,onChange:s}=e,c=(0,t.useRef)(null);function l(e){if(e.stopPropagation(),!(!s||o))if(a!==void 0)s&&s(a);else{let e=c.current.checked;s&&s(e)}}return(0,i.jsxs)(`label`,{"data-u-comp":`radio`,className:g(`univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-text-sm`,{"univer-cursor-pointer univer-text-gray-900 dark:!univer-text-white":!o,"univer-text-gray-400":o}),children:[(0,i.jsxs)(`span`,{className:`univer-relative univer-block`,children:[(0,i.jsx)(`input`,{ref:c,className:`univer-absolute univer-size-0 univer-opacity-0`,type:`radio`,checked:r,disabled:o,onChange:l}),(0,i.jsx)(`span`,{className:g(`univer-relative univer-box-border univer-flex univer-size-4 univer-items-center univer-justify-center univer-overflow-hidden univer-rounded-full univer-border univer-border-solid univer-transition-colors`,{"univer-opacity-50":o,"univer-border-primary-600 univer-bg-primary-600 dark:!univer-bg-primary-600":r,"univer-border-gray-300 univer-bg-gray-50 dark:!univer-border-gray-500 dark:!univer-bg-gray-600":!r}),children:r&&(0,i.jsx)(`span`,{className:`univer-absolute univer-left-1/2 univer-top-1/2 univer-block univer-size-2 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-rounded-full univer-bg-white`})})]}),(0,i.jsx)(`span`,{children:n})]})}function Mt(t){let{value:n,options:r=[],hideCheckMark:a=!1,onChange:o,multiple:s,className:c,optionClassName:l}=t,u=Array.isArray(n)?n:[n];function d(e){let t=u.indexOf(e);o(s?t>-1?u.filter(t=>t===e):[...u,e]:t>-1?void 0:e)}return(0,i.jsx)(`ul`,{className:g(`univer-m-0 univer-grid univer-max-h-80 univer-list-none univer-gap-1 univer-overflow-y-auto univer-rounded univer-p-1.5`,k,D,c),children:r.map((t,n)=>{let r=u.indexOf(t.value)>-1;return(0,i.jsx)(`li`,{children:(0,i.jsxs)(`a`,{className:g(`univer-relative univer-block univer-cursor-pointer univer-select-none univer-rounded univer-py-1.5 univer-pl-8 univer-pr-2 univer-text-sm univer-text-gray-900 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-600`,l,{"univer-bg-gray-200 dark:!univer-bg-gray-500":r}),onClick:()=>d(t.value),children:[!a&&r&&(0,i.jsx)(e.CheckMarkIcon,{className:`univer-absolute univer-left-0 univer-top-1/2 -univer-translate-y-1/2 univer-pl-2 univer-text-primary-600`}),(0,i.jsx)(`span`,{style:{color:t.color},children:t.label})]})},n)})})}const Nt=g(`univer-box-border univer-inline-flex univer-h-8 univer-min-w-36 univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200 dark:!univer-bg-gray-700 dark:!univer-text-white`,k);function Pt(n){let{className:r,value:a,disabled:o=!1,options:s=[],borderless:c=!1,onChange:l}=n,[u,d]=(0,t.useState)(!1);function f(e){d(e)}let p=(0,t.useMemo)(()=>{let e=[];for(let t of s)t.options?(t.options.forEach(t=>{e.push({label:t.label,value:t.value,disabled:t.disabled})}),e.push({type:`separator`})):e.push({label:t.label,value:t.value,disabled:t.disabled});return[{type:`radio`,value:a,hideIndicator:!0,options:e,onSelect:e=>{l(e)}}]},[s]),m=(0,t.useMemo)(()=>{let e=null;for(let t of s)if(t.options){for(let n of t.options)if(n.value===a){e=n.label;break}}else if(t.value===a){e=t.label;break}return e||a},[s,a]);return(0,i.jsx)(Qe,{className:`max-h univer-w-[--radix-popper-anchor-width] univer-min-w-36`,align:`start`,open:u,items:p,disabled:o,onOpenChange:f,children:(0,i.jsxs)(`div`,{"data-u-comp":`select`,className:g(Nt,{"univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-ring-primary-900":u&&!c,"univer-border-transparent univer-bg-transparent hover:univer-border-transparent":c,"univer-cursor-not-allowed":o,"hover:univer-border-primary-600":!o&&!c,"univer-cursor-pointer":!o&&!u},r),children:[(0,i.jsx)(`div`,{className:`univer-flex-1 univer-truncate univer-text-sm univer-text-gray-500 dark:!univer-text-white`,children:m}),(0,i.jsx)(e.MoreDownIcon,{className:`univer-flex-shrink-0 dark:!univer-text-white`})]})})}function Ft(n){let{className:r,value:a=[],disabled:o=!1,options:s=[],borderless:c=!1,onChange:l}=n,[u,d]=(0,t.useState)(!1);function f(e){d(e)}let p=(0,t.useMemo)(()=>s.map(e=>({type:`checkbox`,value:e.value,label:e.label,disabled:e.disabled,checked:a.includes(e.value),onSelect:e=>{l(a.includes(e)?a.filter(t=>t!==e):[...a,e])}})),[s]);function m(e){l(a.filter(t=>t!==e))}let h=(0,t.useMemo)(()=>s.filter(e=>a.includes(e.value)).map((e,t)=>(0,i.jsx)(b,{className:`univer-max-w-32`,closable:!0,onClose:()=>m(e.value),children:e.label},t)),[s,a]);return(0,i.jsx)(Qe,{className:`univer-w-[--radix-popper-anchor-width] univer-min-w-36`,align:`start`,open:u,items:p,disabled:o,onOpenChange:f,children:(0,i.jsxs)(`div`,{"data-u-comp":`multiple-select`,className:g(Nt,{"univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-ring-primary-900":u&&!c,"univer-border-transparent univer-bg-transparent hover:univer-border-transparent":c,"univer-cursor-not-allowed":o,"hover:univer-border-primary-600":!o&&!c,"univer-cursor-pointer":!o&&!u},r),children:[(0,i.jsx)(`div`,{className:`univer-box-border univer-flex univer-w-[calc(100%-16px)] univer-gap-2 univer-pr-2`,children:h}),(0,i.jsx)(e.MoreDownIcon,{className:`univer-flex-shrink-0 dark:!univer-text-white`})]})})}function It({className:e,orientation:t=`horizontal`,decorative:n=!0,...r}){return(0,i.jsx)(m.Root,{"data-u-comp":`separator`,"data-slot":`separator-root`,decorative:n,orientation:t,className:g(`univer-shrink-0 univer-bg-gray-200 data-[orientation=horizontal]:univer-h-px data-[orientation=vertical]:univer-h-full data-[orientation=horizontal]:univer-w-full data-[orientation=vertical]:univer-w-px dark:!univer-bg-gray-600`,e),...r})}const Lt=e=>{let{defaultChecked:n=!1,onChange:r}=e,[a,o]=(0,t.useState)(n);return(0,t.useEffect)(()=>{o(n)},[n]),(0,i.jsx)(`div`,{className:`univer-h-4`,children:(0,i.jsxs)(`label`,{className:`univer-relative univer-inline-block univer-h-4 univer-w-7`,children:[(0,i.jsx)(`input`,{className:`univer-size-0 univer-opacity-0`,type:`checkbox`,checked:a,onChange:()=>{o(!a),r==null||r(!a)}}),(0,i.jsx)(`span`,{className:g(`univer-absolute univer-inset-0 univer-cursor-pointer univer-rounded-2xl univer-transition-colors univer-duration-200`,{"univer-bg-primary-600":a,"univer-bg-gray-200 dark:!univer-bg-gray-600":!a}),children:(0,i.jsx)(`span`,{className:g(`univer-absolute univer-bottom-0.5 univer-left-0.5 univer-size-3 univer-rounded-full univer-bg-white univer-transition-transform univer-duration-200`,{"univer-translate-x-3":a})})})]})})},Rt=(0,t.forwardRef)((e,n)=>{let r=(0,t.useRef)(null),a=(0,t.useRef)({width:0,height:0}),{className:o,onResize:s,onValueChange:c,...l}=e;(0,t.useImperativeHandle)(n,()=>r.current,[]),(0,t.useLayoutEffect)(()=>{let e=r.current;if(e&&s){let t=new ResizeObserver(e=>{let{width:t,height:n}=e[0].target.getBoundingClientRect();t===0||n===0||(a.current.width!==t||a.current.height!==n)&&(a.current={width:t,height:n},s(t,n))});return t.observe(e),()=>{t.unobserve(e),t.disconnect()}}},[s]);function u(e){let t=e.target.value;c==null||c(t)}return(0,i.jsx)(`textarea`,{ref:r,"data-u-comp":`textarea`,"data-slot":`textarea`,className:g(`univer-box-border univer-flex univer-w-full univer-resize univer-rounded-md univer-bg-transparent univer-p-2 univer-text-base univer-text-gray-900 univer-outline-none univer-transition-[color,box-shadow] placeholder:univer-text-gray-200 disabled:univer-cursor-not-allowed disabled:univer-opacity-50 dark:!univer-text-white`,k,D,o),onChange:u,...l})});function zt({visibleToasts:e,...t}){return(0,i.jsx)(f.Toaster,{className:`dark:![&_[data-description]]:univer-text-gray-200 [&_[data-description]]:univer-text-sm [&_[data-description]]:univer-text-gray-600 [&_[data-icon]>svg]:univer-relative [&_[data-icon]>svg]:univer-top-1 [&_[data-icon]]:univer-self-baseline [&_[data-sonner-toast]]:univer-shadow-md [&_[data-title]]:univer-text-sm [&_[data-title]]:univer-text-gray-900`,toastOptions:{classNames:{content:`univer-leading-normal`,success:`[&_[data-icon]]:univer-text-green-500`,info:`[&_[data-icon]]:univer-text-primary-600`,error:`[&_[data-icon]]:univer-text-red-500`,warning:`[&_[data-icon]]:univer-text-yellow-500`}},visibleToasts:e==null?5:e,...t})}function Bt(e){let{data:n,itemKey:r,children:a,height:o,itemHeight:s,overscan:c=2,className:l,style:u}=e,[d,f]=(0,t.useState)(0);if(!o||!s||s<=0)return(0,i.jsx)(`div`,{className:l,style:u,children:n.map((e,t)=>{let n=typeof r==`function`?r(e):e[r];return(0,i.jsx)(`div`,{children:a(e,t)},n)})});let p=Math.max(0,Math.floor(d/s)-c),m=Math.ceil(o/s)+c*2,h=Math.min(n.length,p+m),g=p*s,_=n.length*s,v=n.slice(p,h);return(0,i.jsx)(`div`,{className:l,style:{...u,height:o,overflowY:`auto`},onScroll:e=>f(e.currentTarget.scrollTop),children:(0,i.jsx)(`div`,{style:{height:_,position:`relative`},children:(0,i.jsx)(`div`,{style:{transform:`translateY(${g}px)`},children:v.map((e,t)=>{let n=typeof r==`function`?r(e):e[r];return(0,i.jsx)(`div`,{children:a(e,p+t)},n)})})})})}const Vt=(e,t)=>{let n=[],r=e=>{var i;if(n.push(e.key),t===e.key||(i=e.children)!=null&&i.length&&e.children.some(r))return!0;n.pop()};return e.some(r),n},Ht=(e,t)=>{let n=t==null?new Map:t,r=e;return{findNodePathFromTreeWithCache:e=>{let t=n.get(e);if(t)return t;let i=Vt(r,e);return i.map((e,t,n)=>{let r=[];for(let e=0;e<=t;e++)r.push(n[e]);return r}).reverse().forEach(e=>{let t=e[e.length-1];n.set(t,e)}),i},reset:e=>{n.clear(),e&&(r=e)}}},Z=(e,t)=>t.length?t.reduce((e,t)=>{let n=e.find(e=>e.key===t);return(n==null?void 0:n.children)||[]},e):e,Ut=(e,t)=>{let n=t.slice(0),r=n.pop();return Z(e,n).find(e=>e.key===r)},Wt=(e,t,n)=>{let r=new Set(t),i=n[n.length-1],a=Z(e,n);if(r.has(i)){if(a.length){let e=t=>{r.delete(t.key),t.children&&t.children.forEach(t=>e(t))};a.forEach(e)}n.map((e,t,n)=>{let r=[];for(let e=0;e<=t;e++)r.push(n[e]);return r}).reverse().some(t=>{let n=Z(e,t),i=t[t.length-1];if(n.every(e=>!r.has(e.key)))r.delete(i);else return!0;return!1})}else{let e=t=>{r.add(t.key),t.children&&t.children.forEach(t=>e(t))};n.forEach(e=>r.add(e)),a.length&&a.forEach(e)}return[...r]},Gt=(e,t)=>{let n=t.children||[],r=t=>{var n;return(n=t.children)!=null&&n.length?!!t.children.every(r):e.has(t.key)};return n.length?n.some(e=>!r(e)):!1},Kt=(e,t)=>{let n=[],r=Ht(e);return t.forEach(t=>{let i=Ut(e,r.findNodePathFromTreeWithCache(t));if(i){var a;(a=i.children)!=null&&a.length||n.push(i)}}),n};let qt=function(e){return e[e.ONLY_LEAF_NODE=0]=`ONLY_LEAF_NODE`,e[e.ALL=1]=`ALL`,e}({});function Jt(e,t,n=1){let r=[];return e.forEach(e=>{r.push({...e,level:n}),e.children&&t.has(e.key)&&r.push(...Jt(e.children,t,n+1))}),r}function Yt(n){let{data:r=[],defaultCache:a,style:o,defaultExpandAll:s=!1,selectionMode:c=qt.ALL,valueGroup:l=[],onChange:u,onExpend:d,height:f=200,itemHeight:p=32,attachRender:m}=n,[h,_]=(0,t.useState)({}),v=(0,t.useMemo)(()=>new Set,[]),y=(0,t.useMemo)(()=>Ht(r,a),[r,a]),b=(0,t.useMemo)(()=>{let e=new Set;return l.forEach(t=>{y.findNodePathFromTreeWithCache(t).forEach(t=>e.add(t))}),e},[l,y]);(0,t.useEffect)(()=>{function e(t){var n;v.add(t.key),(n=t.children)==null||n.forEach(e)}s&&r.forEach(e),_({})},[s,r]);let x=(0,t.useMemo)(()=>Jt(r,v),[r,h,v]);function S(e){var t;(t=e.children)!=null&&t.length&&(v.has(e.key)?v.delete(e.key):v.add(e.key),_({})),!(c===qt.ONLY_LEAF_NODE&&e.children)&&(d==null||d(e.key))}function C(t){let{title:r,key:a,level:o=0}=t,s=n.treeNodeClassName,c=v.has(a),l=b.has(a),d=Gt(b,t);return(0,i.jsx)(`div`,{className:g(`univer-relative univer-text-[13px]`,s),style:{paddingLeft:`${o*20}px`},children:(0,i.jsxs)(`div`,{className:`univer-relative univer-my-1 univer-flex univer-w-full univer-items-center`,children:[t.children&&t.children.length>0&&(0,i.jsx)(`span`,{className:g(`univer-absolute univer-left-[-16px] univer-top-1/2 univer-flex univer--translate-y-1/2 univer-items-center univer-justify-center univer-text-[8px]`,{"univer-rotate-[-90deg]":!c}),onClick:e=>{e.stopPropagation(),S(t)},children:(0,i.jsx)(e.DropdownIcon,{})}),(0,i.jsx)(re,{checked:l&&!d,indeterminate:l&&d,onChange:()=>{u==null||u(t)}}),(0,i.jsx)(`div`,{className:`
79
- univer-mx-1 univer-flex univer-h-full univer-shrink univer-items-center univer-overflow-hidden
80
- univer-text-ellipsis univer-whitespace-nowrap
81
- `,onClick:e=>{e.stopPropagation(),S(t)},children:(0,i.jsx)(lt,{className:`univer-block`,showIfEllipsis:!0,placement:`top`,title:r,children:(0,i.jsx)(`span`,{className:`univer-block`,children:r})})}),m&&m(t)]})},a)}return(0,i.jsx)(`section`,{className:`
82
- univer-relative univer-select-none univer-text-gray-900
83
- dark:!univer-text-white
84
- `,children:(0,i.jsx)(`div`,{className:`univer-m-0 univer-h-full univer-list-none univer-p-0`,style:o,children:(0,i.jsx)(Bt,{data:x,itemKey:e=>e.key,height:f,itemHeight:p,children:e=>C(e)})})})}const Q=new WeakMap;function Xt(e,t){let n=Q.get(t);n||(n=(0,h.createRoot)(t),Q.set(t,n)),n.render(e)}function Zt(e){let t=Q.get(e);t&&(t.unmount(),Q.delete(e))}const Qt=new Set;let $;function $t(e){return $||($=new ResizeObserver((...e)=>{Qt.forEach(t=>t(...e))})),{observe(t,n){Qt.add(e),$.observe(t,n)},unobserve(t){Qt.delete(e),$.unobserve(t)}}}exports.Accordion=_,exports.Avatar=y,exports.Badge=b,exports.Button=S,exports.ButtonGroup=C,exports.Calendar=V,exports.CascaderList=te,exports.Checkbox=re,exports.CheckboxGroup=ne,exports.ColorPicker=ke,exports.ConfigContext=T,exports.ConfigProvider=E,exports.Confirm=je,exports.DatePicker=Ie,exports.DateRangePicker=Le,exports.Dialog=U,exports.DraggableList=ze,exports.Dropdown=Fe,exports.DropdownMenu=Qe,exports.FormDualColumnLayout=tt,exports.FormLayout=et,exports.Gallery=it,exports.GradientColorPicker=dt,exports.HoverCard=gt,exports.Input=ot,exports.InputNumber=st,exports.KBD=_t,exports.MessageType=J,exports.Messager=Tt,exports.MultipleSelect=Ft,exports.Pager=nt,exports.Popup=kt,exports.Radio=jt,exports.RadioGroup=At,exports.Segmented=ct,exports.Select=Pt,exports.SelectList=Mt,exports.Separator=It,exports.Switch=Lt,exports.Textarea=Rt,exports.TimeInput=R,exports.Toaster=zt,exports.Tooltip=lt,exports.Tree=Yt,exports.TreeSelectionMode=qt,exports.borderBottomClassName=P,exports.borderClassName=k,exports.borderLeftBottomClassName=A,exports.borderLeftClassName=j,exports.borderRightClassName=F,exports.borderTopClassName=N,exports.clsx=g,exports.divideXClassName=`univer-divide-gray-200 dark:!univer-divide-gray-600 univer-divide-x univer-divide-y-0 univer-divide-solid`,exports.divideYClassName=`univer-divide-gray-200 dark:!univer-divide-gray-600 univer-divide-y univer-divide-x-0 univer-divide-solid`,exports.filterLeafNode=Kt,exports.findNodePathFromTree=Vt,exports.findSubTreeFromPath=Z,exports.isBrowser=w,exports.mergeTreeSelected=Wt,exports.message=Et,exports.removeMessage=Dt,exports.render=Xt,exports.resizeObserverCtor=$t,exports.scrollbarClassName=D,exports.toast=f.toast,exports.unmount=Zt;
3381
+ `,
3382
+ content: "univer-gap-2.5",
3383
+ icon: "[&>svg]:univer-block [&>svg]:univer-size-4",
3384
+ success: typeClassMap[MessageType.Success],
3385
+ info: typeClassMap[MessageType.Info],
3386
+ warning: typeClassMap[MessageType.Warning],
3387
+ error: typeClassMap[MessageType.Error],
3388
+ loading: typeClassMap[MessageType.Loading]
3389
+ }
3390
+ },
3391
+ ...props
3392
+ });
3393
+ const message = ({ content, duration, id, onClose, type = MessageType.Info }) => {
3394
+ const messageId = id !== null && id !== void 0 ? id : createMessageId();
3395
+ const method = resolveToastMethod(type);
3396
+ let closed = false;
3397
+ const handleClose = () => {
3398
+ if (closed) return;
3399
+ closed = true;
3400
+ activeMessageIds.delete(messageId);
3401
+ onClose === null || onClose === void 0 || onClose();
3402
+ };
3403
+ method(content, {
3404
+ id: messageId,
3405
+ toasterId: MESSAGE_TOASTER_ID,
3406
+ duration: duration !== null && duration !== void 0 ? duration : DEFAULT_MESSAGE_DURATION,
3407
+ icon: type === MessageType.Loading ? void 0 : iconMap[type],
3408
+ onDismiss: handleClose,
3409
+ onAutoClose: handleClose
3410
+ });
3411
+ activeMessageIds.add(messageId);
3412
+ return messageId;
3413
+ };
3414
+ const removeMessage = (id) => {
3415
+ if (typeof id !== "undefined") {
3416
+ sonner.toast.dismiss(id);
3417
+ activeMessageIds.delete(id);
3418
+ return;
3419
+ }
3420
+ activeMessageIds.forEach((messageId) => {
3421
+ sonner.toast.dismiss(messageId);
3422
+ });
3423
+ activeMessageIds.clear();
3424
+ };
3425
+
3426
+ //#endregion
3427
+ //#region src/components/popup/Popup.tsx
3428
+ const POPUP_POINTER_OFFSET = 2;
3429
+ const HIDDEN_POPUP_OFFSET = [-9999, -9999];
3430
+ function Popup(props) {
3431
+ const { children, visible = false, offset = [0, 0], overflowVisible = false, placementY = "below" } = props;
3432
+ const nodeRef = (0, react.useRef)(null);
3433
+ const [realOffset, setRealOffset] = (0, react.useState)(HIDDEN_POPUP_OFFSET);
3434
+ const { mountContainer } = (0, react.useContext)(ConfigContext);
3435
+ const calculateOffset = () => {
3436
+ const element = nodeRef.current;
3437
+ if (!element) return null;
3438
+ const [left, top] = offset;
3439
+ const { clientWidth, clientHeight } = element;
3440
+ const { innerWidth, innerHeight } = window;
3441
+ const maxX = Math.max(0, innerWidth - clientWidth - POPUP_POINTER_OFFSET);
3442
+ const maxY = Math.max(0, innerHeight - clientHeight - POPUP_POINTER_OFFSET);
3443
+ const x = Math.min(Math.max(left, 0), maxX);
3444
+ const topWithPlacement = placementY === "above" ? top - clientHeight : top;
3445
+ return [x, Math.min(Math.max(topWithPlacement, 0), maxY)];
3446
+ };
3447
+ (0, react.useLayoutEffect)(() => {
3448
+ if (!visible) {
3449
+ setRealOffset(HIDDEN_POPUP_OFFSET);
3450
+ return;
3451
+ }
3452
+ const nextOffset = calculateOffset();
3453
+ if (nextOffset) setRealOffset(nextOffset);
3454
+ }, [
3455
+ offset,
3456
+ placementY,
3457
+ visible
3458
+ ]);
3459
+ (0, react.useEffect)(() => {
3460
+ if (!visible) return;
3461
+ const handleResize = () => {
3462
+ const nextOffset = calculateOffset();
3463
+ if (nextOffset) setRealOffset(nextOffset);
3464
+ };
3465
+ window.addEventListener("resize", handleResize);
3466
+ return () => {
3467
+ window.removeEventListener("resize", handleResize);
3468
+ };
3469
+ }, [
3470
+ offset,
3471
+ placementY,
3472
+ visible
3473
+ ]);
3474
+ function preventDefault(event) {
3475
+ event.preventDefault();
3476
+ }
3477
+ return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_transition_group.CSSTransition, {
3478
+ in: visible,
3479
+ nodeRef,
3480
+ timeout: 500,
3481
+ classNames: {
3482
+ enter: "univer-popup-enter",
3483
+ enterActive: "univer-popup-enter-active",
3484
+ enterDone: "univer-popup-enter-done",
3485
+ exitActive: "univer-popup-exit",
3486
+ exitDone: "univer-popup-exit-active"
3487
+ },
3488
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
3489
+ ref: nodeRef,
3490
+ className: "univer-popup",
3491
+ style: {
3492
+ left: realOffset[0] + POPUP_POINTER_OFFSET,
3493
+ top: realOffset[1] + POPUP_POINTER_OFFSET,
3494
+ overflow: overflowVisible ? "visible" : void 0
3495
+ },
3496
+ onContextMenu: preventDefault,
3497
+ children
3498
+ })
3499
+ }), mountContainer);
3500
+ }
3501
+
3502
+ //#endregion
3503
+ //#region src/components/radio-group/RadioGroup.tsx
3504
+ /**
3505
+ * RadioGroup Component
3506
+ */
3507
+ function RadioGroup(props) {
3508
+ const { children, className, style, value, disabled = false, direction = "horizontal", onChange } = props;
3509
+ const handleChange = (value) => {
3510
+ onChange(value);
3511
+ };
3512
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3513
+ className: clsx$1("univer-flex univer-gap-2", { "univer-flex-col": direction === "vertical" }, className),
3514
+ style,
3515
+ children: react.Children.map(children, (child, index) => {
3516
+ if ((0, react.isValidElement)(child)) return (0, react.cloneElement)(child, {
3517
+ key: index,
3518
+ children: child.props.children,
3519
+ value: child.props.value,
3520
+ checked: value === child.props.value,
3521
+ disabled: disabled !== null && disabled !== void 0 ? disabled : child.props.disabled,
3522
+ onChange: handleChange
3523
+ });
3524
+ return child;
3525
+ })
3526
+ });
3527
+ }
3528
+
3529
+ //#endregion
3530
+ //#region src/components/radio/Radio.tsx
3531
+ /**
3532
+ * Radio Component
3533
+ */
3534
+ function Radio(props) {
3535
+ const { children, checked, value, disabled = false, onChange } = props;
3536
+ const inputRef = (0, react.useRef)(null);
3537
+ function handleChange(e) {
3538
+ e.stopPropagation();
3539
+ if (!onChange || disabled) return;
3540
+ if (typeof value !== "undefined") onChange && onChange(value);
3541
+ else {
3542
+ const checked = inputRef.current.checked;
3543
+ onChange && onChange(checked);
3544
+ }
3545
+ }
3546
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
3547
+ "data-u-comp": "radio",
3548
+ className: clsx$1("univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-text-sm", {
3549
+ "univer-cursor-pointer univer-text-gray-900 dark:!univer-text-white": !disabled,
3550
+ "univer-text-gray-400": disabled
3551
+ }),
3552
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
3553
+ className: "univer-relative univer-block",
3554
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
3555
+ ref: inputRef,
3556
+ className: "univer-absolute univer-size-0 univer-opacity-0",
3557
+ type: "radio",
3558
+ checked,
3559
+ disabled,
3560
+ onChange: handleChange
3561
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3562
+ className: clsx$1("univer-relative univer-box-border univer-flex univer-size-4 univer-items-center univer-justify-center univer-overflow-hidden univer-rounded-full univer-border univer-border-solid univer-transition-colors", {
3563
+ "univer-opacity-50": disabled,
3564
+ "univer-border-primary-600 univer-bg-primary-600 dark:!univer-bg-primary-600": checked,
3565
+ "univer-border-gray-300 univer-bg-gray-50 dark:!univer-border-gray-500 dark:!univer-bg-gray-600": !checked
3566
+ }),
3567
+ children: checked && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "univer-absolute univer-left-1/2 univer-top-1/2 univer-block univer-size-2 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-rounded-full univer-bg-white" })
3568
+ })]
3569
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children })]
3570
+ });
3571
+ }
3572
+
3573
+ //#endregion
3574
+ //#region src/components/select-list/SelectList.tsx
3575
+ /**
3576
+ * Copyright 2023-present DreamNum Co., Ltd.
3577
+ *
3578
+ * Licensed under the Apache License, Version 2.0 (the "License");
3579
+ * you may not use this file except in compliance with the License.
3580
+ * You may obtain a copy of the License at
3581
+ *
3582
+ * http://www.apache.org/licenses/LICENSE-2.0
3583
+ *
3584
+ * Unless required by applicable law or agreed to in writing, software
3585
+ * distributed under the License is distributed on an "AS IS" BASIS,
3586
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3587
+ * See the License for the specific language governing permissions and
3588
+ * limitations under the License.
3589
+ */
3590
+ function SelectList(props) {
3591
+ const { value: _value, options = [], hideCheckMark = false, onChange, multiple, className, optionClassName } = props;
3592
+ const value = Array.isArray(_value) ? _value : [_value];
3593
+ function handleSelect(newValue) {
3594
+ const index = value.indexOf(newValue);
3595
+ if (!multiple) if (index > -1) onChange(void 0);
3596
+ else onChange(newValue);
3597
+ else if (index > -1) onChange(value.filter((i) => i === newValue));
3598
+ else onChange([...value, newValue]);
3599
+ }
3600
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
3601
+ className: clsx$1("univer-m-0 univer-grid univer-max-h-80 univer-list-none univer-gap-1 univer-overflow-y-auto univer-rounded univer-p-1.5", borderClassName, scrollbarClassName, className),
3602
+ children: options.map((option, index) => {
3603
+ const checked = value.indexOf(option.value) > -1;
3604
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
3605
+ className: clsx$1("univer-relative univer-block univer-cursor-pointer univer-select-none univer-rounded univer-py-1.5 univer-pl-8 univer-pr-2 univer-text-sm univer-text-gray-900 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-600", optionClassName, { "univer-bg-gray-200 dark:!univer-bg-gray-500": checked }),
3606
+ onClick: () => handleSelect(option.value),
3607
+ children: [!hideCheckMark && checked && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CheckMarkIcon, { className: "univer-absolute univer-left-0 univer-top-1/2 -univer-translate-y-1/2 univer-pl-2 univer-text-primary-600" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3608
+ style: { color: option.color },
3609
+ children: option.label
3610
+ })]
3611
+ }) }, index);
3612
+ })
3613
+ });
3614
+ }
3615
+
3616
+ //#endregion
3617
+ //#region src/components/select/Select.tsx
3618
+ const selectClassName = clsx$1("univer-box-border univer-inline-flex univer-h-8 univer-min-w-36 univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200 dark:!univer-bg-gray-700 dark:!univer-text-white", borderClassName);
3619
+ function Select(props) {
3620
+ const { className, value, disabled = false, options = [], borderless = false, onChange } = props;
3621
+ const [open, setOpen] = (0, react.useState)(false);
3622
+ function handleOpenChange(open) {
3623
+ setOpen(open);
3624
+ }
3625
+ const items = (0, react.useMemo)(() => {
3626
+ const selectOptions = [];
3627
+ for (const option of options) if (option.options) {
3628
+ option.options.forEach((opt) => {
3629
+ selectOptions.push({
3630
+ label: opt.label,
3631
+ value: opt.value,
3632
+ disabled: opt.disabled
3633
+ });
3634
+ });
3635
+ selectOptions.push({ type: "separator" });
3636
+ } else selectOptions.push({
3637
+ label: option.label,
3638
+ value: option.value,
3639
+ disabled: option.disabled
3640
+ });
3641
+ return [{
3642
+ type: "radio",
3643
+ value,
3644
+ hideIndicator: true,
3645
+ options: selectOptions,
3646
+ onSelect: (item) => {
3647
+ onChange(item);
3648
+ }
3649
+ }];
3650
+ }, [options]);
3651
+ const displayValue = (0, react.useMemo)(() => {
3652
+ let label = null;
3653
+ for (const option of options) if (option.options) {
3654
+ for (const opt of option.options) if (opt.value === value) {
3655
+ label = opt.label;
3656
+ break;
3657
+ }
3658
+ } else if (option.value === value) {
3659
+ label = option.label;
3660
+ break;
3661
+ }
3662
+ return label || value;
3663
+ }, [options, value]);
3664
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenu, {
3665
+ className: "max-h univer-w-[--radix-popper-anchor-width] univer-min-w-36",
3666
+ align: "start",
3667
+ open,
3668
+ items,
3669
+ disabled,
3670
+ onOpenChange: handleOpenChange,
3671
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3672
+ "data-u-comp": "select",
3673
+ className: clsx$1(selectClassName, {
3674
+ "univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-ring-primary-900": open && !borderless,
3675
+ "univer-border-transparent univer-bg-transparent hover:univer-border-transparent": borderless,
3676
+ "univer-cursor-not-allowed": disabled,
3677
+ "hover:univer-border-primary-600": !disabled && !borderless,
3678
+ "univer-cursor-pointer": !disabled && !open
3679
+ }, className),
3680
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3681
+ className: "univer-flex-1 univer-truncate univer-text-sm univer-text-gray-500 dark:!univer-text-white",
3682
+ children: displayValue
3683
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "univer-flex-shrink-0 dark:!univer-text-white" })]
3684
+ })
3685
+ });
3686
+ }
3687
+
3688
+ //#endregion
3689
+ //#region src/components/select/MultipleSelect.tsx
3690
+ function MultipleSelect(props) {
3691
+ const { className, value = [], disabled = false, options = [], borderless = false, onChange } = props;
3692
+ const [open, setOpen] = (0, react.useState)(false);
3693
+ function handleOpenChange(open) {
3694
+ setOpen(open);
3695
+ }
3696
+ const items = (0, react.useMemo)(() => {
3697
+ return options.map((option) => {
3698
+ return {
3699
+ type: "checkbox",
3700
+ value: option.value,
3701
+ label: option.label,
3702
+ disabled: option.disabled,
3703
+ checked: value.includes(option.value),
3704
+ onSelect: (item) => {
3705
+ onChange(value.includes(item) ? value.filter((v) => v !== item) : [...value, item]);
3706
+ }
3707
+ };
3708
+ });
3709
+ }, [options]);
3710
+ function handleClose(item) {
3711
+ onChange(value.filter((v) => v !== item));
3712
+ }
3713
+ const displayValue = (0, react.useMemo)(() => {
3714
+ return options.filter((option) => value.includes(option.value)).map((option, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Badge, {
3715
+ className: "univer-max-w-32",
3716
+ closable: true,
3717
+ onClose: () => handleClose(option.value),
3718
+ children: option.label
3719
+ }, index));
3720
+ }, [options, value]);
3721
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenu, {
3722
+ className: "univer-w-[--radix-popper-anchor-width] univer-min-w-36",
3723
+ align: "start",
3724
+ open,
3725
+ items,
3726
+ disabled,
3727
+ onOpenChange: handleOpenChange,
3728
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3729
+ "data-u-comp": "multiple-select",
3730
+ className: clsx$1(selectClassName, {
3731
+ "univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-ring-primary-900": open && !borderless,
3732
+ "univer-border-transparent univer-bg-transparent hover:univer-border-transparent": borderless,
3733
+ "univer-cursor-not-allowed": disabled,
3734
+ "hover:univer-border-primary-600": !disabled && !borderless,
3735
+ "univer-cursor-pointer": !disabled && !open
3736
+ }, className),
3737
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3738
+ className: "univer-box-border univer-flex univer-w-[calc(100%-16px)] univer-gap-2 univer-pr-2",
3739
+ children: displayValue
3740
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "univer-flex-shrink-0 dark:!univer-text-white" })]
3741
+ })
3742
+ });
3743
+ }
3744
+
3745
+ //#endregion
3746
+ //#region src/components/separator/Separator.tsx
3747
+ function Separator({ className, orientation = "horizontal", decorative = true, ...props }) {
3748
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_separator.Root, {
3749
+ "data-u-comp": "separator",
3750
+ "data-slot": "separator-root",
3751
+ decorative,
3752
+ orientation,
3753
+ className: clsx$1("univer-shrink-0 univer-bg-gray-200 data-[orientation=horizontal]:univer-h-px data-[orientation=vertical]:univer-h-full data-[orientation=horizontal]:univer-w-full data-[orientation=vertical]:univer-w-px dark:!univer-bg-gray-600", className),
3754
+ ...props
3755
+ });
3756
+ }
3757
+
3758
+ //#endregion
3759
+ //#region src/components/switch/Switch.tsx
3760
+ /**
3761
+ * Copyright 2023-present DreamNum Co., Ltd.
3762
+ *
3763
+ * Licensed under the Apache License, Version 2.0 (the "License");
3764
+ * you may not use this file except in compliance with the License.
3765
+ * You may obtain a copy of the License at
3766
+ *
3767
+ * http://www.apache.org/licenses/LICENSE-2.0
3768
+ *
3769
+ * Unless required by applicable law or agreed to in writing, software
3770
+ * distributed under the License is distributed on an "AS IS" BASIS,
3771
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3772
+ * See the License for the specific language governing permissions and
3773
+ * limitations under the License.
3774
+ */
3775
+ const Switch = (props) => {
3776
+ const { defaultChecked = false, onChange } = props;
3777
+ const [checked, setChecked] = (0, react.useState)(defaultChecked);
3778
+ const handleChange = () => {
3779
+ setChecked(!checked);
3780
+ onChange === null || onChange === void 0 || onChange(!checked);
3781
+ };
3782
+ (0, react.useEffect)(() => {
3783
+ setChecked(defaultChecked);
3784
+ }, [defaultChecked]);
3785
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3786
+ className: "univer-h-4",
3787
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
3788
+ className: "univer-relative univer-inline-block univer-h-4 univer-w-7",
3789
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
3790
+ className: "univer-size-0 univer-opacity-0",
3791
+ type: "checkbox",
3792
+ checked,
3793
+ onChange: handleChange
3794
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3795
+ className: clsx$1("univer-absolute univer-inset-0 univer-cursor-pointer univer-rounded-2xl univer-transition-colors univer-duration-200", {
3796
+ "univer-bg-primary-600": checked,
3797
+ "univer-bg-gray-200 dark:!univer-bg-gray-600": !checked
3798
+ }),
3799
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: clsx$1("univer-absolute univer-bottom-0.5 univer-left-0.5 univer-size-3 univer-rounded-full univer-bg-white univer-transition-transform univer-duration-200", { "univer-translate-x-3": checked }) })
3800
+ })]
3801
+ })
3802
+ });
3803
+ };
3804
+
3805
+ //#endregion
3806
+ //#region src/components/textarea/Textarea.tsx
3807
+ const Textarea = (0, react.forwardRef)((props, ref) => {
3808
+ const textareaRef = (0, react.useRef)(null);
3809
+ const lastSizeRef = (0, react.useRef)({
3810
+ width: 0,
3811
+ height: 0
3812
+ });
3813
+ const { className, onResize, onValueChange, ...restProps } = props;
3814
+ (0, react.useImperativeHandle)(ref, () => textareaRef.current, []);
3815
+ (0, react.useLayoutEffect)(() => {
3816
+ const textarea = textareaRef.current;
3817
+ if (textarea && onResize) {
3818
+ const resizeObserver = new ResizeObserver((entries) => {
3819
+ const { width, height } = entries[0].target.getBoundingClientRect();
3820
+ if (width === 0 || height === 0) return;
3821
+ if (lastSizeRef.current.width !== width || lastSizeRef.current.height !== height) {
3822
+ lastSizeRef.current = {
3823
+ width,
3824
+ height
3825
+ };
3826
+ onResize(width, height);
3827
+ }
3828
+ });
3829
+ resizeObserver.observe(textarea);
3830
+ return () => {
3831
+ resizeObserver.unobserve(textarea);
3832
+ resizeObserver.disconnect();
3833
+ };
3834
+ }
3835
+ }, [onResize]);
3836
+ function handleChange(event) {
3837
+ const value = event.target.value;
3838
+ onValueChange === null || onValueChange === void 0 || onValueChange(value);
3839
+ }
3840
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
3841
+ ref: textareaRef,
3842
+ "data-u-comp": "textarea",
3843
+ "data-slot": "textarea",
3844
+ className: clsx$1("univer-box-border univer-flex univer-w-full univer-resize univer-rounded-md univer-bg-transparent univer-p-2 univer-text-base univer-text-gray-900 univer-outline-none univer-transition-[color,box-shadow] placeholder:univer-text-gray-200 disabled:univer-cursor-not-allowed disabled:univer-opacity-50 dark:!univer-text-white", borderClassName, scrollbarClassName, className),
3845
+ onChange: handleChange,
3846
+ ...restProps
3847
+ });
3848
+ });
3849
+
3850
+ //#endregion
3851
+ //#region src/components/toaster/Toaster.tsx
3852
+ function Toaster({ visibleToasts, ...props }) {
3853
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(sonner.Toaster, {
3854
+ className: "dark:![&_[data-description]]:univer-text-gray-200 [&_[data-description]]:univer-text-sm [&_[data-description]]:univer-text-gray-600 [&_[data-icon]>svg]:univer-relative [&_[data-icon]>svg]:univer-top-1 [&_[data-icon]]:univer-self-baseline [&_[data-sonner-toast]]:univer-shadow-md [&_[data-title]]:univer-text-sm [&_[data-title]]:univer-text-gray-900",
3855
+ toastOptions: { classNames: {
3856
+ content: "univer-leading-normal",
3857
+ success: "[&_[data-icon]]:univer-text-green-500",
3858
+ info: "[&_[data-icon]]:univer-text-primary-600",
3859
+ error: "[&_[data-icon]]:univer-text-red-500",
3860
+ warning: "[&_[data-icon]]:univer-text-yellow-500"
3861
+ } },
3862
+ visibleToasts: visibleToasts !== null && visibleToasts !== void 0 ? visibleToasts : 5,
3863
+ ...props
3864
+ });
3865
+ }
3866
+
3867
+ //#endregion
3868
+ //#region src/components/virtual-list/VirtualList.tsx
3869
+ function VirtualList(props) {
3870
+ const { data, itemKey, children, height, itemHeight, overscan = 2, className, style } = props;
3871
+ const [scrollTop, setScrollTop] = (0, react.useState)(0);
3872
+ if (!height || !itemHeight || itemHeight <= 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3873
+ className,
3874
+ style,
3875
+ children: data.map((item, index) => {
3876
+ const key = typeof itemKey === "function" ? itemKey(item) : item[itemKey];
3877
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: children(item, index) }, key);
3878
+ })
3879
+ });
3880
+ const start = Math.max(0, Math.floor(scrollTop / itemHeight) - overscan);
3881
+ const visibleCount = Math.ceil(height / itemHeight) + overscan * 2;
3882
+ const end = Math.min(data.length, start + visibleCount);
3883
+ const offsetY = start * itemHeight;
3884
+ const totalHeight = data.length * itemHeight;
3885
+ const visibleItems = data.slice(start, end);
3886
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3887
+ className,
3888
+ style: {
3889
+ ...style,
3890
+ height,
3891
+ overflowY: "auto"
3892
+ },
3893
+ onScroll: (e) => setScrollTop(e.currentTarget.scrollTop),
3894
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3895
+ style: {
3896
+ height: totalHeight,
3897
+ position: "relative"
3898
+ },
3899
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3900
+ style: { transform: `translateY(${offsetY}px)` },
3901
+ children: visibleItems.map((item, index) => {
3902
+ const key = typeof itemKey === "function" ? itemKey(item) : item[itemKey];
3903
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: children(item, start + index) }, key);
3904
+ })
3905
+ })
3906
+ })
3907
+ });
3908
+ }
3909
+
3910
+ //#endregion
3911
+ //#region src/components/tree/util.ts
3912
+ const findNodePathFromTree = (tree, key) => {
3913
+ const result = [];
3914
+ const recursive = (node) => {
3915
+ var _node$children;
3916
+ result.push(node.key);
3917
+ if (key === node.key) return true;
3918
+ if ((_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.length) {
3919
+ if (node.children.some(recursive)) return true;
3920
+ }
3921
+ result.pop();
3922
+ };
3923
+ tree.some(recursive);
3924
+ return result;
3925
+ };
3926
+ const createCacheWithFindNodePathFromTree = (tree, defaultCache) => {
3927
+ const cache = defaultCache !== null && defaultCache !== void 0 ? defaultCache : /* @__PURE__ */ new Map();
3928
+ let cacheTree = tree;
3929
+ return {
3930
+ findNodePathFromTreeWithCache: (key) => {
3931
+ const cacheValue = cache.get(key);
3932
+ if (cacheValue) return cacheValue;
3933
+ const path = findNodePathFromTree(cacheTree, key);
3934
+ path.map((k, index, arr) => {
3935
+ const result = [];
3936
+ for (let i = 0; i <= index; i++) result.push(arr[i]);
3937
+ return result;
3938
+ }).reverse().forEach((list) => {
3939
+ const key = list[list.length - 1];
3940
+ cache.set(key, list);
3941
+ });
3942
+ return path;
3943
+ },
3944
+ reset: (newTree) => {
3945
+ cache.clear();
3946
+ if (newTree) cacheTree = newTree;
3947
+ }
3948
+ };
3949
+ };
3950
+ const findSubTreeFromPath = (tree, path) => {
3951
+ if (!path.length) return tree;
3952
+ return path.reduce((list, key) => {
3953
+ const item = list.find((node) => node.key === key);
3954
+ return (item === null || item === void 0 ? void 0 : item.children) || [];
3955
+ }, tree);
3956
+ };
3957
+ const findNodeFromPath = (tree, _path) => {
3958
+ const path = _path.slice(0);
3959
+ const key = path.pop();
3960
+ return findSubTreeFromPath(tree, path).find((node) => node.key === key);
3961
+ };
3962
+ const mergeTreeSelected = (treeData, treeSelected, path) => {
3963
+ const set = new Set(treeSelected);
3964
+ const key = path[path.length - 1];
3965
+ const subTree = findSubTreeFromPath(treeData, path);
3966
+ if (!set.has(key)) {
3967
+ const addRecursive = (node) => {
3968
+ set.add(node.key);
3969
+ if (node.children) node.children.forEach((n) => addRecursive(n));
3970
+ };
3971
+ path.forEach((k) => set.add(k));
3972
+ if (subTree.length) subTree.forEach(addRecursive);
3973
+ } else {
3974
+ if (subTree.length) {
3975
+ const deleteRecursive = (node) => {
3976
+ set.delete(node.key);
3977
+ if (node.children) node.children.forEach((n) => deleteRecursive(n));
3978
+ };
3979
+ subTree.forEach(deleteRecursive);
3980
+ }
3981
+ path.map((k, index, arr) => {
3982
+ const result = [];
3983
+ for (let i = 0; i <= index; i++) result.push(arr[i]);
3984
+ return result;
3985
+ }).reverse().some((path) => {
3986
+ const list = findSubTreeFromPath(treeData, path);
3987
+ const key = path[path.length - 1];
3988
+ if (list.every((e) => !set.has(e.key))) set.delete(key);
3989
+ else return true;
3990
+ return false;
3991
+ });
3992
+ }
3993
+ return [...set];
3994
+ };
3995
+ const isIntermediated = (treeSelected, node) => {
3996
+ const list = node.children || [];
3997
+ const checkIsSelected = (node) => {
3998
+ var _node$children2;
3999
+ if ((_node$children2 = node.children) === null || _node$children2 === void 0 ? void 0 : _node$children2.length) {
4000
+ if (node.children.every(checkIsSelected)) return true;
4001
+ return false;
4002
+ }
4003
+ return treeSelected.has(node.key);
4004
+ };
4005
+ if (list.length) return list.some((node) => !checkIsSelected(node));
4006
+ return false;
4007
+ };
4008
+ const filterLeafNode = (tree, keyList) => {
4009
+ const result = [];
4010
+ const find = createCacheWithFindNodePathFromTree(tree);
4011
+ keyList.forEach((key) => {
4012
+ const node = findNodeFromPath(tree, find.findNodePathFromTreeWithCache(key));
4013
+ if (node) {
4014
+ var _node$children3;
4015
+ if (!((_node$children3 = node.children) === null || _node$children3 === void 0 ? void 0 : _node$children3.length)) result.push(node);
4016
+ }
4017
+ });
4018
+ return result;
4019
+ };
4020
+
4021
+ //#endregion
4022
+ //#region src/components/tree/Tree.tsx
4023
+ let TreeSelectionMode = /* @__PURE__ */ function(TreeSelectionMode) {
4024
+ TreeSelectionMode[TreeSelectionMode["ONLY_LEAF_NODE"] = 0] = "ONLY_LEAF_NODE";
4025
+ TreeSelectionMode[TreeSelectionMode["ALL"] = 1] = "ALL";
4026
+ return TreeSelectionMode;
4027
+ }({});
4028
+ function flattenTree(items, expandedKeys, level = 1) {
4029
+ const flatItems = [];
4030
+ items.forEach((item) => {
4031
+ flatItems.push({
4032
+ ...item,
4033
+ level
4034
+ });
4035
+ if (item.children && expandedKeys.has(item.key)) flatItems.push(...flattenTree(item.children, expandedKeys, level + 1));
4036
+ });
4037
+ return flatItems;
4038
+ }
4039
+ /**
4040
+ * Tree Component
4041
+ */
4042
+ function Tree(props) {
4043
+ const { data = [], defaultCache, style, defaultExpandAll = false, selectionMode = TreeSelectionMode.ALL, valueGroup = [], onChange, onExpend, height = 200, itemHeight = 32, attachRender } = props;
4044
+ const [update, forceUpdate] = (0, react.useState)({});
4045
+ const expandKeySet = (0, react.useMemo)(() => {
4046
+ return /* @__PURE__ */ new Set();
4047
+ }, []);
4048
+ const findNode = (0, react.useMemo)(() => createCacheWithFindNodePathFromTree(data, defaultCache), [data, defaultCache]);
4049
+ const selectedNodeKeySet = (0, react.useMemo)(() => {
4050
+ const set = /* @__PURE__ */ new Set();
4051
+ valueGroup.forEach((key) => {
4052
+ findNode.findNodePathFromTreeWithCache(key).forEach((k) => set.add(k));
4053
+ });
4054
+ return set;
4055
+ }, [valueGroup, findNode]);
4056
+ (0, react.useEffect)(() => {
4057
+ function walkData(item) {
4058
+ var _item$children;
4059
+ expandKeySet.add(item.key);
4060
+ (_item$children = item.children) === null || _item$children === void 0 || _item$children.forEach(walkData);
4061
+ }
4062
+ if (defaultExpandAll) data.forEach(walkData);
4063
+ forceUpdate({});
4064
+ }, [defaultExpandAll, data]);
4065
+ const flatData = (0, react.useMemo)(() => flattenTree(data, expandKeySet), [
4066
+ data,
4067
+ update,
4068
+ expandKeySet
4069
+ ]);
4070
+ function handleExpendItem(treeItem) {
4071
+ var _treeItem$children;
4072
+ if ((_treeItem$children = treeItem.children) === null || _treeItem$children === void 0 ? void 0 : _treeItem$children.length) {
4073
+ if (expandKeySet.has(treeItem.key)) expandKeySet.delete(treeItem.key);
4074
+ else expandKeySet.add(treeItem.key);
4075
+ forceUpdate({});
4076
+ }
4077
+ if (selectionMode === TreeSelectionMode.ONLY_LEAF_NODE) {
4078
+ if (treeItem.children) return;
4079
+ }
4080
+ onExpend === null || onExpend === void 0 || onExpend(treeItem.key);
4081
+ }
4082
+ function renderTreeItem(treeItem) {
4083
+ const { title, key, level = 0 } = treeItem;
4084
+ const treeNodeClassName = props.treeNodeClassName;
4085
+ const expended = expandKeySet.has(key);
4086
+ const selected = selectedNodeKeySet.has(key);
4087
+ const intermediated = isIntermediated(selectedNodeKeySet, treeItem);
4088
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4089
+ className: clsx$1("univer-relative univer-text-[13px]", treeNodeClassName),
4090
+ style: { paddingLeft: `${level * 20}px` },
4091
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4092
+ className: "univer-relative univer-my-1 univer-flex univer-w-full univer-items-center",
4093
+ children: [
4094
+ treeItem.children && treeItem.children.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
4095
+ className: clsx$1("univer-absolute univer-left-[-16px] univer-top-1/2 univer-flex univer--translate-y-1/2 univer-items-center univer-justify-center univer-text-[8px]", { "univer-rotate-[-90deg]": !expended }),
4096
+ onClick: (e) => {
4097
+ e.stopPropagation();
4098
+ handleExpendItem(treeItem);
4099
+ },
4100
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DropdownIcon, {})
4101
+ }),
4102
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Checkbox, {
4103
+ checked: selected && !intermediated,
4104
+ indeterminate: selected && intermediated,
4105
+ onChange: () => {
4106
+ onChange === null || onChange === void 0 || onChange(treeItem);
4107
+ }
4108
+ }),
4109
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4110
+ className: "\n univer-mx-1 univer-flex univer-h-full univer-shrink univer-items-center univer-overflow-hidden\n univer-text-ellipsis univer-whitespace-nowrap\n ",
4111
+ onClick: (e) => {
4112
+ e.stopPropagation();
4113
+ handleExpendItem(treeItem);
4114
+ },
4115
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Tooltip, {
4116
+ className: "univer-block",
4117
+ showIfEllipsis: true,
4118
+ placement: "top",
4119
+ title,
4120
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
4121
+ className: "univer-block",
4122
+ children: title
4123
+ })
4124
+ })
4125
+ }),
4126
+ attachRender && attachRender(treeItem)
4127
+ ]
4128
+ })
4129
+ }, key);
4130
+ }
4131
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
4132
+ className: "\n univer-relative univer-select-none univer-text-gray-900\n dark:!univer-text-white\n ",
4133
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4134
+ className: "univer-m-0 univer-h-full univer-list-none univer-p-0",
4135
+ style,
4136
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(VirtualList, {
4137
+ data: flatData,
4138
+ itemKey: (item) => item.key,
4139
+ height,
4140
+ itemHeight,
4141
+ children: (item) => renderTreeItem(item)
4142
+ })
4143
+ })
4144
+ });
4145
+ }
4146
+
4147
+ //#endregion
4148
+ //#region src/helper/react-dom.ts
4149
+ const rootMap = /* @__PURE__ */ new WeakMap();
4150
+ function render(node, container) {
4151
+ let root = rootMap.get(container);
4152
+ if (!root) {
4153
+ root = (0, react_dom_client.createRoot)(container);
4154
+ rootMap.set(container, root);
4155
+ }
4156
+ root.render(node);
4157
+ }
4158
+ function unmount(container) {
4159
+ const root = rootMap.get(container);
4160
+ if (root) {
4161
+ root.unmount();
4162
+ rootMap.delete(container);
4163
+ }
4164
+ }
4165
+
4166
+ //#endregion
4167
+ //#region src/helper/resize-observer.ts
4168
+ /**
4169
+ * Copyright 2023-present DreamNum Co., Ltd.
4170
+ *
4171
+ * Licensed under the Apache License, Version 2.0 (the "License");
4172
+ * you may not use this file except in compliance with the License.
4173
+ * You may obtain a copy of the License at
4174
+ *
4175
+ * http://www.apache.org/licenses/LICENSE-2.0
4176
+ *
4177
+ * Unless required by applicable law or agreed to in writing, software
4178
+ * distributed under the License is distributed on an "AS IS" BASIS,
4179
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4180
+ * See the License for the specific language governing permissions and
4181
+ * limitations under the License.
4182
+ */
4183
+ /**
4184
+ * All elements are observed by a single ResizeObserver is got greater performance than each element observed by separate ResizeObserver
4185
+ * See issue https://github.com/WICG/resize-observer/issues/59#issuecomment-408098151
4186
+ */
4187
+ const _resizeObserverCallbacks = /* @__PURE__ */ new Set();
4188
+ let _resizeObserver;
4189
+ function resizeObserverCtor(callback) {
4190
+ if (!_resizeObserver) _resizeObserver = new ResizeObserver((...args) => {
4191
+ _resizeObserverCallbacks.forEach((callback) => callback(...args));
4192
+ });
4193
+ return {
4194
+ observe(target, options) {
4195
+ _resizeObserverCallbacks.add(callback);
4196
+ _resizeObserver.observe(target, options);
4197
+ },
4198
+ unobserve(target) {
4199
+ _resizeObserverCallbacks.delete(callback);
4200
+ _resizeObserver.unobserve(target);
4201
+ }
4202
+ };
4203
+ }
4204
+
4205
+ //#endregion
4206
+ exports.Accordion = Accordion;
4207
+ exports.Avatar = Avatar;
4208
+ exports.Badge = Badge;
4209
+ exports.Button = Button;
4210
+ exports.ButtonGroup = ButtonGroup;
4211
+ exports.Calendar = Calendar;
4212
+ exports.CascaderList = CascaderList;
4213
+ exports.Checkbox = Checkbox;
4214
+ exports.CheckboxGroup = CheckboxGroup;
4215
+ exports.ColorPicker = ColorPicker;
4216
+ exports.ConfigContext = ConfigContext;
4217
+ exports.ConfigProvider = ConfigProvider;
4218
+ exports.Confirm = Confirm;
4219
+ exports.DatePicker = DatePicker;
4220
+ exports.DateRangePicker = DateRangePicker;
4221
+ exports.Dialog = Dialog;
4222
+ exports.DraggableList = DraggableList;
4223
+ exports.Dropdown = Dropdown;
4224
+ exports.DropdownMenu = DropdownMenu;
4225
+ exports.FormDualColumnLayout = FormDualColumnLayout;
4226
+ exports.FormLayout = FormLayout;
4227
+ exports.Gallery = Gallery;
4228
+ exports.GradientColorPicker = GradientColorPicker;
4229
+ exports.HoverCard = HoverCard;
4230
+ exports.Input = Input;
4231
+ exports.InputNumber = InputNumber;
4232
+ exports.KBD = KBD;
4233
+ exports.MessageType = MessageType;
4234
+ exports.Messager = Messager;
4235
+ exports.MultipleSelect = MultipleSelect;
4236
+ exports.Pager = Pager;
4237
+ exports.Popup = Popup;
4238
+ exports.Radio = Radio;
4239
+ exports.RadioGroup = RadioGroup;
4240
+ exports.Segmented = Segmented;
4241
+ exports.Select = Select;
4242
+ exports.SelectList = SelectList;
4243
+ exports.Separator = Separator;
4244
+ exports.Switch = Switch;
4245
+ exports.Textarea = Textarea;
4246
+ exports.TimeInput = TimeInput;
4247
+ exports.Toaster = Toaster;
4248
+ exports.Tooltip = Tooltip;
4249
+ exports.Tree = Tree;
4250
+ exports.TreeSelectionMode = TreeSelectionMode;
4251
+ exports.borderBottomClassName = borderBottomClassName;
4252
+ exports.borderClassName = borderClassName;
4253
+ exports.borderLeftBottomClassName = borderLeftBottomClassName;
4254
+ exports.borderLeftClassName = borderLeftClassName;
4255
+ exports.borderRightClassName = borderRightClassName;
4256
+ exports.borderTopClassName = borderTopClassName;
4257
+ exports.clsx = clsx$1;
4258
+ exports.divideXClassName = divideXClassName;
4259
+ exports.divideYClassName = divideYClassName;
4260
+ exports.filterLeafNode = filterLeafNode;
4261
+ exports.findNodePathFromTree = findNodePathFromTree;
4262
+ exports.findSubTreeFromPath = findSubTreeFromPath;
4263
+ exports.isBrowser = isBrowser;
4264
+ exports.mergeTreeSelected = mergeTreeSelected;
4265
+ exports.message = message;
4266
+ exports.removeMessage = removeMessage;
4267
+ exports.render = render;
4268
+ exports.resizeObserverCtor = resizeObserverCtor;
4269
+ exports.scrollbarClassName = scrollbarClassName;
4270
+ exports.toast = sonner.toast;
4271
+ exports.unmount = unmount;