@ioca/react 1.3.68 → 1.3.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/affix/affix.js +5 -1
- package/lib/cjs/components/affix/affix.js.map +1 -1
- package/lib/cjs/components/drawer/drawer.js +1 -1
- package/lib/cjs/components/drawer/drawer.js.map +1 -1
- package/lib/cjs/components/editor/controls.js +5 -1
- package/lib/cjs/components/editor/controls.js.map +1 -1
- package/lib/cjs/components/modal/modal.js +7 -2
- package/lib/cjs/components/modal/modal.js.map +1 -1
- package/lib/cjs/components/popup/content.js +5 -1
- package/lib/cjs/components/popup/content.js.map +1 -1
- package/lib/cjs/components/video/video.js +4 -0
- package/lib/cjs/components/video/video.js.map +1 -1
- package/lib/cjs/js/hooks.js +90 -50
- package/lib/cjs/js/hooks.js.map +1 -1
- package/lib/cjs/js/useRipple/index.js +6 -2
- package/lib/cjs/js/useRipple/index.js.map +1 -1
- package/lib/css/index.css +1 -1
- package/lib/css/index.css.map +1 -1
- package/lib/es/components/affix/affix.js +5 -1
- package/lib/es/components/affix/affix.js.map +1 -1
- package/lib/es/components/drawer/drawer.js +1 -1
- package/lib/es/components/drawer/drawer.js.map +1 -1
- package/lib/es/components/editor/controls.js +5 -1
- package/lib/es/components/editor/controls.js.map +1 -1
- package/lib/es/components/modal/modal.js +7 -2
- package/lib/es/components/modal/modal.js.map +1 -1
- package/lib/es/components/popup/content.js +5 -1
- package/lib/es/components/popup/content.js.map +1 -1
- package/lib/es/components/video/video.js +4 -0
- package/lib/es/components/video/video.js.map +1 -1
- package/lib/es/js/hooks.js +91 -51
- package/lib/es/js/hooks.js.map +1 -1
- package/lib/es/js/useRipple/index.js +6 -2
- package/lib/es/js/useRipple/index.js.map +1 -1
- package/lib/index.js +123 -58
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drawer.js","sources":["../../../../packages/components/drawer/drawer.tsx"],"sourcesContent":["import { useReactive } from \"ahooks\";\nimport classNames from \"classnames\";\nimport { useEffect, useRef } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useKeydown } from \"../../js/hooks\";\nimport Helpericon from \"../utils/helpericon\";\nimport \"./index.css\";\nimport { IDrawer } from \"./type\";\n\nfunction Drawer(props: IDrawer) {\n\tconst {\n\t\tvisible,\n\t\tposition = \"left\",\n\t\theader,\n\t\tfooter,\n\t\tbackdropClosable = true,\n\t\thideCloseButton,\n\t\tkeepDOM,\n\t\tclassName,\n\t\tdisabledEsc,\n\t\tchildren,\n\t\tonVisibleChange,\n\t\tonClose,\n\t\t...restProps\n\t} = props;\n\tconst toggable = useRef(true);\n\tconst state = useReactive({\n\t\tshow: visible,\n\t\tactive: visible,\n\t\tinit: false,\n\t});\n\n\tuseEffect(() => {\n\t\tvisible ? handleShow() : handleHide();\n\t}, [visible]);\n\n\tconst handleShow = () => {\n\t\tif (!toggable.current) return;\n\n\t\tstate.show = true;\n\t\tonVisibleChange?.(true);\n\t\ttoggable.current = false;\n\t\tsetTimeout(() => {\n\t\t\tstate.active = true;\n\t\t\ttoggable.current = true;\n\t\t\tstate.init = true;\n\t\t}, 24);\n\t};\n\n\tconst handleHide = () => {\n\t\tif (!toggable.current) return;\n\t\ttoggable.current = false;\n\n\t\tstate.active = false;\n\t\tsetTimeout(() => {\n\t\t\tif (!keepDOM) {\n\t\t\t\tstate.show = false;\n\t\t\t}\n\t\t\tonVisibleChange?.(false);\n\t\t\ttoggable.current = true;\n\t\t\tonClose?.();\n\t\t}, 240);\n\t};\n\n\tconst handleBackdropClick = function () {\n\t\tbackdropClosable && handleHide();\n\t};\n\n\tuseKeydown(\n\t\t(e) => {\n\t\t\tif (e.code !== \"Escape\" || !visible) return;\n\t\t\thandleHide();\n\t\t},\n\t\t{\n\t\t\tdisabled: disabledEsc,\n\t\t}\n\t);\n\n\treturn createPortal(\n\t\tstate.show && (\n\t\t\t<div\n\t\t\t\tclassName={classNames(\"i-backdrop-drawer\", className, {\n\t\t\t\t\t\"i-active\": state.active,\n\t\t\t\t})}\n\t\t\t\tonClick={handleBackdropClick}\n\t\t\t\t{...restProps}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tclassName={classNames(\"i-drawer\", `i-drawer-${position}`)}\n\t\t\t\t\tonClick={(e) => e.stopPropagation()}\n\t\t\t\t>\n\t\t\t\t\t<header className='i-drawer-header'>\n\t\t\t\t\t\t{header}\n\n\t\t\t\t\t\t<Helpericon\n\t\t\t\t\t\t\tactive={!hideCloseButton}\n\t\t\t\t\t\t\tclassName='i-drawer-close'\n\t\t\t\t\t\t\tonClick={handleHide}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</header>\n\n\t\t\t\t\t<div className='i-drawer-content'>{children}</div>\n\n\t\t\t\t\t<div className='i-drawer-footer'>{footer}</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t),\n\t\tdocument
|
|
1
|
+
{"version":3,"file":"drawer.js","sources":["../../../../packages/components/drawer/drawer.tsx"],"sourcesContent":["import { useReactive } from \"ahooks\";\nimport classNames from \"classnames\";\nimport { useEffect, useRef } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useKeydown } from \"../../js/hooks\";\nimport Helpericon from \"../utils/helpericon\";\nimport \"./index.css\";\nimport { IDrawer } from \"./type\";\n\nfunction Drawer(props: IDrawer) {\n\tconst {\n\t\tvisible,\n\t\tposition = \"left\",\n\t\theader,\n\t\tfooter,\n\t\tbackdropClosable = true,\n\t\thideCloseButton,\n\t\tkeepDOM,\n\t\tclassName,\n\t\tdisabledEsc,\n\t\tchildren,\n\t\tonVisibleChange,\n\t\tonClose,\n\t\t...restProps\n\t} = props;\n\tconst toggable = useRef(true);\n\tconst state = useReactive({\n\t\tshow: visible,\n\t\tactive: visible,\n\t\tinit: false,\n\t});\n\n\tuseEffect(() => {\n\t\tvisible ? handleShow() : handleHide();\n\t}, [visible]);\n\n\tconst handleShow = () => {\n\t\tif (!toggable.current) return;\n\n\t\tstate.show = true;\n\t\tonVisibleChange?.(true);\n\t\ttoggable.current = false;\n\t\tsetTimeout(() => {\n\t\t\tstate.active = true;\n\t\t\ttoggable.current = true;\n\t\t\tstate.init = true;\n\t\t}, 24);\n\t};\n\n\tconst handleHide = () => {\n\t\tif (!toggable.current) return;\n\t\ttoggable.current = false;\n\n\t\tstate.active = false;\n\t\tsetTimeout(() => {\n\t\t\tif (!keepDOM) {\n\t\t\t\tstate.show = false;\n\t\t\t}\n\t\t\tonVisibleChange?.(false);\n\t\t\ttoggable.current = true;\n\t\t\tonClose?.();\n\t\t}, 240);\n\t};\n\n\tconst handleBackdropClick = function () {\n\t\tbackdropClosable && handleHide();\n\t};\n\n\tuseKeydown(\n\t\t(e) => {\n\t\t\tif (e.code !== \"Escape\" || !visible) return;\n\t\t\thandleHide();\n\t\t},\n\t\t{\n\t\t\tdisabled: disabledEsc,\n\t\t}\n\t);\n\n\treturn createPortal(\n\t\tstate.show && (\n\t\t\t<div\n\t\t\t\tclassName={classNames(\"i-backdrop-drawer\", className, {\n\t\t\t\t\t\"i-active\": state.active,\n\t\t\t\t})}\n\t\t\t\tonClick={handleBackdropClick}\n\t\t\t\t{...restProps}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tclassName={classNames(\"i-drawer\", `i-drawer-${position}`)}\n\t\t\t\t\tonClick={(e) => e.stopPropagation()}\n\t\t\t\t>\n\t\t\t\t\t<header className='i-drawer-header'>\n\t\t\t\t\t\t{header}\n\n\t\t\t\t\t\t<Helpericon\n\t\t\t\t\t\t\tactive={!hideCloseButton}\n\t\t\t\t\t\t\tclassName='i-drawer-close'\n\t\t\t\t\t\t\tonClick={handleHide}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</header>\n\n\t\t\t\t\t<div className='i-drawer-content'>{children}</div>\n\n\t\t\t\t\t<div className='i-drawer-footer'>{footer}</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t),\n\t\tdocument?.body ?? null\n\t);\n}\n\nexport default Drawer;\n"],"names":["_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AAA,EAAA,CAC1C,EACD,CAAA,CACN,EACD,QAAQ,EAAE,IAAI,IAAI,IAAI,CACtB;AACF;;;;"}
|
|
@@ -5,7 +5,11 @@ import '../button/index.js';
|
|
|
5
5
|
import Icon from '../icon/icon.js';
|
|
6
6
|
import Button from '../button/button.js';
|
|
7
7
|
|
|
8
|
-
const exec = (a, b, c) =>
|
|
8
|
+
const exec = (a, b, c) => {
|
|
9
|
+
if (typeof document === "undefined")
|
|
10
|
+
return;
|
|
11
|
+
return document.execCommand(a, b, c);
|
|
12
|
+
};
|
|
9
13
|
const xssOptions = {
|
|
10
14
|
onIgnoreTagAttr: function (tag, name, value) {
|
|
11
15
|
if (["data-", "style"].includes(name.substr(0, 5))) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controls.js","sources":["../../../../packages/components/editor/controls.tsx"],"sourcesContent":["import {\n\tClearAllRound,\n\tFormatBoldRound,\n\tFormatItalicRound,\n\tFormatUnderlinedRound,\n\tRedoRound,\n\tStrikethroughSRound,\n\tUndoRound,\n} from \"@ricons/material\";\nimport { Fragment } from \"react/jsx-runtime\";\nimport { escapeAttrValue } from \"xss\";\nimport Button from \"../button\";\nimport Icon from \"../icon\";\n\nexport const exec = (a, b?, c?) => document.execCommand(a, b, c);\n\nexport const xssOptions = {\n\tonIgnoreTagAttr: function (tag, name, value) {\n\t\tif ([\"data-\", \"style\"].includes(name.substr(0, 5))) {\n\t\t\treturn name + '=\"' + escapeAttrValue(value) + '\"';\n\t\t}\n\t},\n};\n\nconst fnMap = {\n\tbold: {\n\t\ticon: <FormatBoldRound />,\n\t\tonClick: () => exec(\"bold\"),\n\t\ttip: \"粗体\",\n\t},\n\titalic: {\n\t\ticon: <FormatItalicRound />,\n\t\tonClick: () => exec(\"italic\"),\n\t\ttip: \"斜体\",\n\t},\n\tunderline: {\n\t\ticon: <FormatUnderlinedRound />,\n\t\tonClick: () => exec(\"underline\"),\n\t\ttip: \"下划线\",\n\t},\n\tstrike: {\n\t\ticon: <StrikethroughSRound />,\n\t\tonClick: () => exec(\"strikeThrough\"),\n\t\ttip: \"删除线\",\n\t},\n\tredo: {\n\t\ticon: <RedoRound />,\n\t\tonClick: () => exec(\"redo\"),\n\t\ttip: \"重做\",\n\t},\n\tundo: {\n\t\ticon: <UndoRound />,\n\t\tonClick: () => exec(\"undo\"),\n\t\ttip: \"撤销\",\n\t},\n\t// color: {\n\t// \ticon: <FormatColorTextRound />,\n\t// \tonClick: () => exec(\"foreColor\", false, \"\"),\n\t// },\n\t// backColor: {\n\t// \ticon: <FormatColorFillRound />,\n\t// \tonClick: () => exec(\"backColor\", false, \"\"),\n\t// },\n\tclear: {\n\t\ticon: <ClearAllRound />,\n\t\tonClick: () => exec(\"removeFormat\"),\n\t\ttip: \"清除格式\",\n\t},\n};\n\nconst aliasMap = {\n\tsimple: [\"undo\", \"redo\", \"bold\", \"italic\", \"underline\", \"strike\", \"clear\"],\n\tall: Object.keys(fnMap),\n};\n\nexport default function getControls(fns, options) {\n\tconst { controlBtnProps } = options;\n\tconst keys = typeof fns === \"string\" ? aliasMap[fns] : fns;\n\n\treturn keys.map((k) => {\n\t\tif (fnMap[k]) {\n\t\t\tconst { icon, render, tip, onClick } = fnMap[k];\n\n\t\t\tif (render) {\n\t\t\t\treturn render(options);\n\t\t\t}\n\n\t\t\treturn (\n\t\t\t\t<Button key={k} {...controlBtnProps} onClick={onClick}>\n\t\t\t\t\t<Icon icon={icon} />\n\t\t\t\t\t{tip && <span className='i-editor-control-tip'>{tip}</span>}\n\t\t\t\t</Button>\n\t\t\t);\n\t\t}\n\t\treturn <Fragment key={k} />;\n\t});\n}\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"controls.js","sources":["../../../../packages/components/editor/controls.tsx"],"sourcesContent":["import {\n\tClearAllRound,\n\tFormatBoldRound,\n\tFormatItalicRound,\n\tFormatUnderlinedRound,\n\tRedoRound,\n\tStrikethroughSRound,\n\tUndoRound,\n} from \"@ricons/material\";\nimport { Fragment } from \"react/jsx-runtime\";\nimport { escapeAttrValue } from \"xss\";\nimport Button from \"../button\";\nimport Icon from \"../icon\";\n\nexport const exec = (a, b?, c?) => {\n\tif (typeof document === \"undefined\") return;\n\treturn document.execCommand(a, b, c);\n};\n\nexport const xssOptions = {\n\tonIgnoreTagAttr: function (tag, name, value) {\n\t\tif ([\"data-\", \"style\"].includes(name.substr(0, 5))) {\n\t\t\treturn name + '=\"' + escapeAttrValue(value) + '\"';\n\t\t}\n\t},\n};\n\nconst fnMap = {\n\tbold: {\n\t\ticon: <FormatBoldRound />,\n\t\tonClick: () => exec(\"bold\"),\n\t\ttip: \"粗体\",\n\t},\n\titalic: {\n\t\ticon: <FormatItalicRound />,\n\t\tonClick: () => exec(\"italic\"),\n\t\ttip: \"斜体\",\n\t},\n\tunderline: {\n\t\ticon: <FormatUnderlinedRound />,\n\t\tonClick: () => exec(\"underline\"),\n\t\ttip: \"下划线\",\n\t},\n\tstrike: {\n\t\ticon: <StrikethroughSRound />,\n\t\tonClick: () => exec(\"strikeThrough\"),\n\t\ttip: \"删除线\",\n\t},\n\tredo: {\n\t\ticon: <RedoRound />,\n\t\tonClick: () => exec(\"redo\"),\n\t\ttip: \"重做\",\n\t},\n\tundo: {\n\t\ticon: <UndoRound />,\n\t\tonClick: () => exec(\"undo\"),\n\t\ttip: \"撤销\",\n\t},\n\t// color: {\n\t// \ticon: <FormatColorTextRound />,\n\t// \tonClick: () => exec(\"foreColor\", false, \"\"),\n\t// },\n\t// backColor: {\n\t// \ticon: <FormatColorFillRound />,\n\t// \tonClick: () => exec(\"backColor\", false, \"\"),\n\t// },\n\tclear: {\n\t\ticon: <ClearAllRound />,\n\t\tonClick: () => exec(\"removeFormat\"),\n\t\ttip: \"清除格式\",\n\t},\n};\n\nconst aliasMap = {\n\tsimple: [\"undo\", \"redo\", \"bold\", \"italic\", \"underline\", \"strike\", \"clear\"],\n\tall: Object.keys(fnMap),\n};\n\nexport default function getControls(fns, options) {\n\tconst { controlBtnProps } = options;\n\tconst keys = typeof fns === \"string\" ? aliasMap[fns] : fns;\n\n\treturn keys.map((k) => {\n\t\tif (fnMap[k]) {\n\t\t\tconst { icon, render, tip, onClick } = fnMap[k];\n\n\t\t\tif (render) {\n\t\t\t\treturn render(options);\n\t\t\t}\n\n\t\t\treturn (\n\t\t\t\t<Button key={k} {...controlBtnProps} onClick={onClick}>\n\t\t\t\t\t<Icon icon={icon} />\n\t\t\t\t\t{tip && <span className='i-editor-control-tip'>{tip}</span>}\n\t\t\t\t</Button>\n\t\t\t);\n\t\t}\n\t\treturn <Fragment key={k} />;\n\t});\n}\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;AAca,MAAA,IAAI,GAAG,CAAC,CAAC,EAAE,CAAE,EAAE,CAAE,KAAI;IACjC,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE;IACrC,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AACrC;AAEa,MAAA,UAAU,GAAG;AACzB,IAAA,eAAe,EAAE,UAAU,GAAG,EAAE,IAAI,EAAE,KAAK,EAAA;AAC1C,QAAA,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;YACnD,OAAO,IAAI,GAAG,IAAI,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,GAAG;;KAElD;;AAGF,MAAM,KAAK,GAAG;AACb,IAAA,IAAI,EAAE;QACL,IAAI,EAAEA,GAAC,CAAA,eAAe,EAAG,EAAA,CAAA;AACzB,QAAA,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC;AAC3B,QAAA,GAAG,EAAE,IAAI;AACT,KAAA;AACD,IAAA,MAAM,EAAE;QACP,IAAI,EAAEA,GAAC,CAAA,iBAAiB,EAAG,EAAA,CAAA;AAC3B,QAAA,OAAO,EAAE,MAAM,I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eAAe,EAAE,GAAG,OAAO;AACnC,IAAA,MAAM,IAAI,GAAG,OAAO,GAAG,KAAK,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG;AAE1D,IAAA,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAI;AACrB,QAAA,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;AACb,YAAA,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;YAE/C,IAAI,MAAM,EAAE;AACX,gBAAA,OAAO,MAAM,CAAC,OAAO,CAAC;;AAGvB,YAAA,QACCC,IAAA,CAAC,MAAM,EAAA,EAAA,GAAa,eAAe,EAAE,OAAO,EAAE,OAAO,EAAA,QAAA,EAAA,CACpDD,GAAC,CAAA,IAAI,IAAC,IAAI,EAAE,IAAI,EAAA,CAAI,EACnB,GAAG,IAAIA,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,sBAAsB,EAAE,QAAA,EAAA,GAAG,EAAQ,CAAA,CAAA,EAAA,EAF/C,CAAC,CAGL;;AAGX,QAAA,OAAOA,GAAC,CAAA,QAAQ,EAAM,EAAA,EAAA,CAAC,CAAI;AAC5B,KAAC,CAAC;AACH;;;;"}
|
|
@@ -80,6 +80,11 @@ function Modal(props) {
|
|
|
80
80
|
useEffect(() => {
|
|
81
81
|
visible ? handleShow() : handleHide();
|
|
82
82
|
}, [visible]);
|
|
83
|
+
const handleClick = () => {
|
|
84
|
+
if (typeof document === "undefined")
|
|
85
|
+
return;
|
|
86
|
+
document.documentElement.click();
|
|
87
|
+
};
|
|
83
88
|
if (!show)
|
|
84
89
|
return null;
|
|
85
90
|
return createPortal(jsx("div", { className: classNames("i-modal-container", {
|
|
@@ -95,9 +100,9 @@ function Modal(props) {
|
|
|
95
100
|
height,
|
|
96
101
|
}, onClick: (e) => {
|
|
97
102
|
e.stopPropagation();
|
|
98
|
-
|
|
103
|
+
handleClick();
|
|
99
104
|
onClick?.(e);
|
|
100
|
-
}, ...restProps, children: [customized && children, !customized && (jsx(DefaultContent, { title: title, hideCloseButton: hideCloseButton, footer: footer, okButtonProps: okButtonProps, cancelButtonProps: cancelButtonProps, children: children, footerLeft: footerLeft, onOk: onOk, onClose: handleHide }))] }) }), document
|
|
105
|
+
}, ...restProps, children: [customized && children, !customized && (jsx(DefaultContent, { title: title, hideCloseButton: hideCloseButton, footer: footer, okButtonProps: okButtonProps, cancelButtonProps: cancelButtonProps, children: children, footerLeft: footerLeft, onOk: onOk, onClose: handleHide }))] }) }), document?.body ?? null);
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
export { Modal as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal.js","sources":["../../../../packages/components/modal/modal.tsx"],"sourcesContent":["import classNames from \"classnames\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useKeydown } from \"../../js/hooks\";\nimport Button from \"../button\";\nimport Helpericon from \"../utils/helpericon\";\nimport \"./index.css\";\nimport { CompositionModal, IModal, IModalContent } from \"./type\";\n\nfunction DefaultContent(props: IModalContent) {\n\tconst {\n\t\ttitle,\n\t\tfooter,\n\t\thideCloseButton,\n\t\tfooterLeft,\n\t\tokButtonProps,\n\t\tcancelButtonProps,\n\t\tchildren,\n\t\tonOk,\n\t\tonClose,\n\t} = props;\n\tconst showHeader = title || !hideCloseButton;\n\n\tconst handleOk = async () => {\n\t\tconst ret = await onOk?.();\n\n\t\tif (ret) return;\n\n\t\tonClose?.();\n\t};\n\n\tconst renderFooter = useMemo(() => {\n\t\tif (footer || footer === null) return footer;\n\n\t\tconst propsOk = Object.assign(\n\t\t\t{\n\t\t\t\tchildren: \"确定\",\n\t\t\t\tonClick: handleOk,\n\t\t\t},\n\t\t\tokButtonProps\n\t\t);\n\t\tconst propsCancel = Object.assign(\n\t\t\t{\n\t\t\t\tsecondary: true,\n\t\t\t\tchildren: \"关闭\",\n\t\t\t\tonClick: onClose,\n\t\t\t},\n\t\t\tcancelButtonProps\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{footerLeft}\n\t\t\t\t<Button {...propsOk} />\n\t\t\t\t<Button {...propsCancel} />\n\t\t\t</>\n\t\t);\n\t}, [footer, okButtonProps, cancelButtonProps]);\n\n\treturn (\n\t\t<>\n\t\t\t{showHeader && (\n\t\t\t\t<header className='i-modal-header'>\n\t\t\t\t\t{title && <b>{title}</b>}\n\n\t\t\t\t\t<Helpericon\n\t\t\t\t\t\tactive={!hideCloseButton}\n\t\t\t\t\t\tclassName='i-modal-close'\n\t\t\t\t\t\tonClick={onClose}\n\t\t\t\t\t/>\n\t\t\t\t</header>\n\t\t\t)}\n\n\t\t\t<div className='i-modal-content'>{children}</div>\n\n\t\t\t<footer className='i-modal-footer'>{renderFooter}</footer>\n\t\t</>\n\t);\n}\n\nfunction Modal(props: IModal) {\n\tconst {\n\t\tvisible,\n\t\ttitle,\n\t\tfooter,\n\t\tokButtonProps,\n\t\tcancelButtonProps,\n\t\tclosable = true,\n\t\thideBackdrop,\n\t\tbackdropClosable = true,\n\t\thideCloseButton,\n\t\tdisableEsc,\n\t\twidth,\n\t\theight,\n\t\tcustomized,\n\t\tfixed,\n\t\thideShadow,\n\t\tchildren,\n\t\tstyle,\n\t\tclassName,\n\t\tkeepDOM,\n\t\tfooterLeft,\n\t\tonClick,\n\t\tonVisibleChange,\n\t\tonClose,\n\t\tonOk,\n\t\t...restProps\n\t} = props;\n\tconst [show, setShow] = useState(visible);\n\tconst [active, setActive] = useState(false);\n\tconst [bounced, setBounced] = useState(false);\n\tconst toggable = useRef(true);\n\n\tconst handleShow = () => {\n\t\tif (!toggable.current) return;\n\n\t\t(!keepDOM || !show) && setShow(true);\n\t\ttoggable.current = false;\n\t\tsetTimeout(() => {\n\t\t\tsetActive(true);\n\t\t\tonVisibleChange?.(true);\n\t\t\ttoggable.current = true;\n\t\t}, 24);\n\t};\n\n\tconst handleHide = () => {\n\t\tif (!toggable.current) return;\n\t\ttoggable.current = false;\n\n\t\tif (!closable) {\n\t\t\tsetBounced(true);\n\t\t\tsetTimeout(() => {\n\t\t\t\tsetBounced(false);\n\t\t\t\ttoggable.current = true;\n\t\t\t}, 400);\n\t\t\treturn;\n\t\t}\n\n\t\tsetActive(false);\n\t\tsetTimeout(() => {\n\t\t\t!keepDOM && setShow(false);\n\t\t\ttoggable.current = true;\n\t\t\tonVisibleChange?.(false);\n\t\t\tonClose?.();\n\t\t}, 240);\n\t};\n\n\tconst handleBackdropClick = function () {\n\t\tbackdropClosable && handleHide();\n\t};\n\n\tuseKeydown(\n\t\t(e) => {\n\t\t\tif (e.code !== \"Escape\" || !visible) return;\n\t\t\thandleHide();\n\t\t},\n\t\t{ disabled: disableEsc }\n\t);\n\n\tuseEffect(() => {\n\t\tvisible ? handleShow() : handleHide();\n\t}, [visible]);\n\n\tif (!show) return null;\n\n\treturn createPortal(\n\t\t<div\n\t\t\tclassName={classNames(\n\t\t\t\t\"i-modal-container\",\n\t\t\t\t{\n\t\t\t\t\t\"i-modal-backdrop\": !hideBackdrop,\n\t\t\t\t\t\"i-modal-customized\": customized,\n\t\t\t\t\t\"i-modal-active\": active,\n\t\t\t\t\tfixed,\n\t\t\t\t},\n\t\t\t\tclassName\n\t\t\t)}\n\t\t\tstyle={style}\n\t\t\tonClick={handleBackdropClick}\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName={classNames(\"i-modal\", {\n\t\t\t\t\tbounced,\n\t\t\t\t\tshadow: !hideShadow,\n\t\t\t\t})}\n\t\t\t\tstyle={{\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t}}\n\t\t\t\tonClick={(e) => {\n\t\t\t\t\te.stopPropagation();\n\t\t\t\t\
|
|
1
|
+
{"version":3,"file":"modal.js","sources":["../../../../packages/components/modal/modal.tsx"],"sourcesContent":["import classNames from \"classnames\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useKeydown } from \"../../js/hooks\";\nimport Button from \"../button\";\nimport Helpericon from \"../utils/helpericon\";\nimport \"./index.css\";\nimport { CompositionModal, IModal, IModalContent } from \"./type\";\n\nfunction DefaultContent(props: IModalContent) {\n\tconst {\n\t\ttitle,\n\t\tfooter,\n\t\thideCloseButton,\n\t\tfooterLeft,\n\t\tokButtonProps,\n\t\tcancelButtonProps,\n\t\tchildren,\n\t\tonOk,\n\t\tonClose,\n\t} = props;\n\tconst showHeader = title || !hideCloseButton;\n\n\tconst handleOk = async () => {\n\t\tconst ret = await onOk?.();\n\n\t\tif (ret) return;\n\n\t\tonClose?.();\n\t};\n\n\tconst renderFooter = useMemo(() => {\n\t\tif (footer || footer === null) return footer;\n\n\t\tconst propsOk = Object.assign(\n\t\t\t{\n\t\t\t\tchildren: \"确定\",\n\t\t\t\tonClick: handleOk,\n\t\t\t},\n\t\t\tokButtonProps\n\t\t);\n\t\tconst propsCancel = Object.assign(\n\t\t\t{\n\t\t\t\tsecondary: true,\n\t\t\t\tchildren: \"关闭\",\n\t\t\t\tonClick: onClose,\n\t\t\t},\n\t\t\tcancelButtonProps\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{footerLeft}\n\t\t\t\t<Button {...propsOk} />\n\t\t\t\t<Button {...propsCancel} />\n\t\t\t</>\n\t\t);\n\t}, [footer, okButtonProps, cancelButtonProps]);\n\n\treturn (\n\t\t<>\n\t\t\t{showHeader && (\n\t\t\t\t<header className='i-modal-header'>\n\t\t\t\t\t{title && <b>{title}</b>}\n\n\t\t\t\t\t<Helpericon\n\t\t\t\t\t\tactive={!hideCloseButton}\n\t\t\t\t\t\tclassName='i-modal-close'\n\t\t\t\t\t\tonClick={onClose}\n\t\t\t\t\t/>\n\t\t\t\t</header>\n\t\t\t)}\n\n\t\t\t<div className='i-modal-content'>{children}</div>\n\n\t\t\t<footer className='i-modal-footer'>{renderFooter}</footer>\n\t\t</>\n\t);\n}\n\nfunction Modal(props: IModal) {\n\tconst {\n\t\tvisible,\n\t\ttitle,\n\t\tfooter,\n\t\tokButtonProps,\n\t\tcancelButtonProps,\n\t\tclosable = true,\n\t\thideBackdrop,\n\t\tbackdropClosable = true,\n\t\thideCloseButton,\n\t\tdisableEsc,\n\t\twidth,\n\t\theight,\n\t\tcustomized,\n\t\tfixed,\n\t\thideShadow,\n\t\tchildren,\n\t\tstyle,\n\t\tclassName,\n\t\tkeepDOM,\n\t\tfooterLeft,\n\t\tonClick,\n\t\tonVisibleChange,\n\t\tonClose,\n\t\tonOk,\n\t\t...restProps\n\t} = props;\n\tconst [show, setShow] = useState(visible);\n\tconst [active, setActive] = useState(false);\n\tconst [bounced, setBounced] = useState(false);\n\tconst toggable = useRef(true);\n\n\tconst handleShow = () => {\n\t\tif (!toggable.current) return;\n\n\t\t(!keepDOM || !show) && setShow(true);\n\t\ttoggable.current = false;\n\t\tsetTimeout(() => {\n\t\t\tsetActive(true);\n\t\t\tonVisibleChange?.(true);\n\t\t\ttoggable.current = true;\n\t\t}, 24);\n\t};\n\n\tconst handleHide = () => {\n\t\tif (!toggable.current) return;\n\t\ttoggable.current = false;\n\n\t\tif (!closable) {\n\t\t\tsetBounced(true);\n\t\t\tsetTimeout(() => {\n\t\t\t\tsetBounced(false);\n\t\t\t\ttoggable.current = true;\n\t\t\t}, 400);\n\t\t\treturn;\n\t\t}\n\n\t\tsetActive(false);\n\t\tsetTimeout(() => {\n\t\t\t!keepDOM && setShow(false);\n\t\t\ttoggable.current = true;\n\t\t\tonVisibleChange?.(false);\n\t\t\tonClose?.();\n\t\t}, 240);\n\t};\n\n\tconst handleBackdropClick = function () {\n\t\tbackdropClosable && handleHide();\n\t};\n\n\tuseKeydown(\n\t\t(e) => {\n\t\t\tif (e.code !== \"Escape\" || !visible) return;\n\t\t\thandleHide();\n\t\t},\n\t\t{ disabled: disableEsc }\n\t);\n\n\tuseEffect(() => {\n\t\tvisible ? handleShow() : handleHide();\n\t}, [visible]);\n\n\tconst handleClick = () => {\n\t\tif (typeof document === \"undefined\") return;\n\t\tdocument.documentElement.click();\n\t};\n\n\tif (!show) return null;\n\n\treturn createPortal(\n\t\t<div\n\t\t\tclassName={classNames(\n\t\t\t\t\"i-modal-container\",\n\t\t\t\t{\n\t\t\t\t\t\"i-modal-backdrop\": !hideBackdrop,\n\t\t\t\t\t\"i-modal-customized\": customized,\n\t\t\t\t\t\"i-modal-active\": active,\n\t\t\t\t\tfixed,\n\t\t\t\t},\n\t\t\t\tclassName\n\t\t\t)}\n\t\t\tstyle={style}\n\t\t\tonClick={handleBackdropClick}\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName={classNames(\"i-modal\", {\n\t\t\t\t\tbounced,\n\t\t\t\t\tshadow: !hideShadow,\n\t\t\t\t})}\n\t\t\t\tstyle={{\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t}}\n\t\t\t\tonClick={(e) => {\n\t\t\t\t\te.stopPropagation();\n\t\t\t\t\thandleClick();\n\t\t\t\t\tonClick?.(e);\n\t\t\t\t}}\n\t\t\t\t{...restProps}\n\t\t\t>\n\t\t\t\t{customized && children}\n\n\t\t\t\t{!customized && (\n\t\t\t\t\t<DefaultContent\n\t\t\t\t\t\ttitle={title}\n\t\t\t\t\t\thideCloseButton={hideCloseButton}\n\t\t\t\t\t\tfooter={footer}\n\t\t\t\t\t\tokButtonProps={okButtonProps}\n\t\t\t\t\t\tcancelButtonProps={cancelButtonProps}\n\t\t\t\t\t\tchildren={children}\n\t\t\t\t\t\tfooterLeft={footerLeft}\n\t\t\t\t\t\tonOk={onOk}\n\t\t\t\t\t\tonClose={handleHide}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</div>,\n\t\tdocument?.body ?? null\n\t);\n}\n\nexport default Modal as CompositionModal;\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;;;;AASA,SAAS,cAAc,CAAC,KAAoB,EAAA;IAC3C,MAAM,EACL,K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AAA,SAAS,EAAE,UAAU,CACpB,mBAAmB,EACnB;YACC,kBAAkB,EAAE,CAAC,YAAY;AACjC,YAAA,oBAAoB,EAAE,UAAU;AAChC,YAAA,gBAAgB,EAAE,MAAM;YACxB,KAAK;AACL,SAAA,EACD,SAAS,CACT,EACD,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,mBAAmB,YAE5BF,IACC,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE;gBAChC,OAAO;gBACP,MAAM,EAAE,CAAC,UAAU;aACnB,CAAC,EACF,KAAK,EAAE;gBACN,KAAK;gBACL,MAAM;AACN,aAAA,EACD,OAAO,EAAE,CAAC,CAAC,KAAI;gBACd,CAAC,CAAC,eAAe,EAAE;AACnB,gBAAA,WAAW,EAAE;AACb,gBAAA,OAAO,GAAG,CAAC,CAAC;AACb,aAAC,EACG,GAAA,SAAS,EAEZ,QAAA,EAAA,CAAA,UAAU,IAAI,QAAQ,EAEtB,CAAC,UAAU,KACXE,GAAA,CAAC,cAAc,EAAA,EACd,KAAK,EAAE,KAAK,EACZ,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,aAAa,EAC5B,iBAAiB,EAAE,iBAAiB,EACpC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,UAAU,EAAA,CAClB,CACF,CAAA,EAAA,CACI,EACD,CAAA,EACN,QAAQ,EAAE,IAAI,IAAI,IAAI,CACtB;AACF;;;;"}
|
|
@@ -4,7 +4,11 @@ import { useMemo } from 'react';
|
|
|
4
4
|
import { createPortal } from 'react-dom';
|
|
5
5
|
|
|
6
6
|
const Content = (props) => {
|
|
7
|
-
const { ref, getContainer = (trigger) =>
|
|
7
|
+
const { ref, getContainer = (trigger) => {
|
|
8
|
+
if (typeof document === "undefined")
|
|
9
|
+
return null;
|
|
10
|
+
return trigger?.offsetParent ?? document.body;
|
|
11
|
+
}, trigger, arrow, arrowProps = {}, className, children, ...restProps } = props;
|
|
8
12
|
const arrowCSS = useMemo(() => {
|
|
9
13
|
let { left, top, pos } = arrowProps;
|
|
10
14
|
let transform = "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","sources":["../../../../packages/components/popup/content.tsx"],"sourcesContent":["import classNames from \"classnames\";\nimport { useMemo } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { IPopupContent } from \"./type\";\n\nconst Content = (props: IPopupContent) => {\n\tconst {\n\t\tref,\n\t\tgetContainer = (trigger) => trigger?.offsetParent ?? document.body,\n\t\ttrigger,\n\t\tarrow,\n\t\tarrowProps = {},\n\t\tclassName,\n\t\tchildren,\n\t\t...restProps\n\t} = props;\n\n\tconst arrowCSS = useMemo(() => {\n\t\tlet { left, top, pos } = arrowProps;\n\t\tlet transform = \"\";\n\n\t\tswitch (pos) {\n\t\t\tcase \"left\":\n\t\t\t\tleft += 2;\n\t\t\t\ttransform = `translate(-100%, -50%) rotate(180deg)`;\n\t\t\t\tbreak;\n\t\t\tcase \"right\":\n\t\t\t\tleft -= 2;\n\t\t\t\ttransform = `translate(0, -50%)`;\n\t\t\t\tbreak;\n\t\t\tcase \"top\":\n\t\t\t\ttop -= 2;\n\t\t\t\ttransform = `translate(-50%, -50%) rotate(-90deg)`;\n\t\t\t\tbreak;\n\t\t\tcase \"bottom\":\n\t\t\t\ttop += 2;\n\t\t\t\ttransform = `translate(-50%, -50%) rotate(90deg)`;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\n\t\treturn {\n\t\t\tleft,\n\t\t\ttop,\n\t\t\ttransform,\n\t\t};\n\t}, [arrowProps]);\n\n\tconst content = (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tclassName={classNames(\"i-popup\", className)}\n\t\t\t{...restProps}\n\t\t>\n\t\t\t{arrow && (\n\t\t\t\t<svg\n\t\t\t\t\txmlns='http://www.w3.org/2000/svg'\n\t\t\t\t\tclassName='i-popup-arrow'\n\t\t\t\t\tstyle={arrowCSS}\n\t\t\t\t>\n\t\t\t\t\t<path d='M0.5 0L1.5 0C1.5 4, 3 5.5, 5 7.5S8,10 8,12S7 14.5, 5 16.5S1.5,20 1.5,24L0.5 24L0.5 0z' />\n\t\t\t\t</svg>\n\t\t\t)}\n\n\t\t\t{children}\n\t\t</div>\n\t);\n\n\treturn createPortal(content, getContainer(trigger));\n};\n\nexport default Content;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;AAKA,MAAM,OAAO,GAAG,CAAC,KAAoB,KAAI;
|
|
1
|
+
{"version":3,"file":"content.js","sources":["../../../../packages/components/popup/content.tsx"],"sourcesContent":["import classNames from \"classnames\";\nimport { useMemo } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { IPopupContent } from \"./type\";\n\nconst Content = (props: IPopupContent) => {\n\tconst {\n\t\tref,\n\t\tgetContainer = (trigger) => {\n\t\t\tif (typeof document === \"undefined\") return null;\n\t\t\treturn trigger?.offsetParent ?? document.body;\n\t\t},\n\t\ttrigger,\n\t\tarrow,\n\t\tarrowProps = {},\n\t\tclassName,\n\t\tchildren,\n\t\t...restProps\n\t} = props;\n\n\tconst arrowCSS = useMemo(() => {\n\t\tlet { left, top, pos } = arrowProps;\n\t\tlet transform = \"\";\n\n\t\tswitch (pos) {\n\t\t\tcase \"left\":\n\t\t\t\tleft += 2;\n\t\t\t\ttransform = `translate(-100%, -50%) rotate(180deg)`;\n\t\t\t\tbreak;\n\t\t\tcase \"right\":\n\t\t\t\tleft -= 2;\n\t\t\t\ttransform = `translate(0, -50%)`;\n\t\t\t\tbreak;\n\t\t\tcase \"top\":\n\t\t\t\ttop -= 2;\n\t\t\t\ttransform = `translate(-50%, -50%) rotate(-90deg)`;\n\t\t\t\tbreak;\n\t\t\tcase \"bottom\":\n\t\t\t\ttop += 2;\n\t\t\t\ttransform = `translate(-50%, -50%) rotate(90deg)`;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\n\t\treturn {\n\t\t\tleft,\n\t\t\ttop,\n\t\t\ttransform,\n\t\t};\n\t}, [arrowProps]);\n\n\tconst content = (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tclassName={classNames(\"i-popup\", className)}\n\t\t\t{...restProps}\n\t\t>\n\t\t\t{arrow && (\n\t\t\t\t<svg\n\t\t\t\t\txmlns='http://www.w3.org/2000/svg'\n\t\t\t\t\tclassName='i-popup-arrow'\n\t\t\t\t\tstyle={arrowCSS}\n\t\t\t\t>\n\t\t\t\t\t<path d='M0.5 0L1.5 0C1.5 4, 3 5.5, 5 7.5S8,10 8,12S7 14.5, 5 16.5S1.5,20 1.5,24L0.5 24L0.5 0z' />\n\t\t\t\t</svg>\n\t\t\t)}\n\n\t\t\t{children}\n\t\t</div>\n\t);\n\n\treturn createPortal(content, getContainer(trigger));\n};\n\nexport default Content;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;AAKA,MAAM,OAAO,GAAG,CAAC,KAAoB,KAAI;IACxC,MAAM,EACL,GAAG,EACH,YAAY,GAAG,CAAC,OAAO,KAAI;QAC1B,IAAI,OAAO,QAAQ,KAAK,WAAW;AAAE,YAAA,OAAO,IAAI;AAChD,QAAA,OAAO,OAAO,EAAE,YAAY,IAAI,QAAQ,CAAC,IAAI;AAC9C,KAAC,EACD,OAAO,EACP,KAAK,EACL,UAAU,GAAG,EAAE,EACf,SAAS,EACT,QAAQ,EACR,GAAG,SAAS,EACZ,GAAG,KAAK;AAET,IAAA,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAK;QAC7B,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,UAAU;QACnC,IAAI,SAAS,GAAG,EAAE;QAElB,QAAQ,GAAG;AACV,YAAA,KAAK,MAAM;gBACV,IAAI,IAAI,CAAC;gBACT,SAAS,GAAG,uCAAuC;gBACnD;AACD,YAAA,KAAK,OAAO;gBACX,IAAI,IAAI,CAAC;gBACT,SAAS,GAAG,oBAAoB;gBAChC;AACD,YAAA,KAAK,KAAK;gBACT,GAAG,IAAI,CAAC;gBACR,SAAS,GAAG,sCAAsC;gBAClD;AACD,YAAA,KAAK,QAAQ;gBACZ,GAAG,IAAI,CAAC;gBACR,SAAS,GAAG,qCAAqC;gBACjD;;QAKF,OAAO;YACN,IAAI;YACJ,GAAG;YACH,SAAS;SACT;AACF,KAAC,EAAE,CAAC,UAAU,CAAC,CAAC;IAEhB,MAAM,OAAO,IACZA,IAAA,CAAA,KAAA,EAAA,EACC,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,SAAS,CAAC,KACvC,SAAS,EAAA,QAAA,EAAA,CAEZ,KAAK,KACLC,GAAA,CAAA,KAAA,EAAA,EACC,KAAK,EAAC,4BAA4B,EAClC,SAAS,EAAC,eAAe,EACzB,KAAK,EAAE,QAAQ,EAAA,QAAA,EAEfA,cAAM,CAAC,EAAC,uFAAuF,EAAG,CAAA,EAAA,CAC7F,CACN,EAEA,QAAQ,CACJ,EAAA,CAAA,CACN;IAED,OAAO,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;AACpD;;;;"}
|
|
@@ -43,6 +43,8 @@ const Video = (props) => {
|
|
|
43
43
|
state.playing = !e.target.paused;
|
|
44
44
|
};
|
|
45
45
|
const fsChangeListener = () => {
|
|
46
|
+
if (typeof document === "undefined")
|
|
47
|
+
return;
|
|
46
48
|
const tar = videoRef.current?.parentElement;
|
|
47
49
|
if (!tar)
|
|
48
50
|
return;
|
|
@@ -144,6 +146,8 @@ const Video = (props) => {
|
|
|
144
146
|
getVideo: () => videoRef.current,
|
|
145
147
|
}));
|
|
146
148
|
useEffect(() => {
|
|
149
|
+
if (typeof document === "undefined")
|
|
150
|
+
return;
|
|
147
151
|
const v = videoRef.current;
|
|
148
152
|
if (!v)
|
|
149
153
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video.js","sources":["../../../../packages/components/video/video.tsx"],"sourcesContent":["import {\n\tFullscreenExitRound,\n\tFullscreenRound,\n\tPauseRound,\n\tPlayArrowRound,\n\tStopRound,\n\tVolumeDownRound,\n\tVolumeOffRound,\n} from \"@ricons/material\";\nimport { useReactive } from \"ahooks\";\nimport classNames from \"classnames\";\nimport { throttle } from \"radash\";\nimport { useEffect, useImperativeHandle, useRef } from \"react\";\nimport { exitFullScreen, fullScreen } from \"../../js/utils\";\nimport Button from \"../button\";\nimport Icon from \"../icon\";\nimport Progress from \"../progress\";\nimport Text from \"../text\";\nimport \"./index.css\";\nimport { IVideo } from \"./type\";\n\nconst Video = (props: IVideo) => {\n\tconst {\n\t\tref,\n\t\tstyle,\n\t\thideControls,\n\t\tautoplay,\n\t\tmuted,\n\t\tvolume = 50,\n\t\theight,\n\t\twidth,\n\t\tuseOriginControls,\n\t\ttimeProgressProps = {\n\t\t\tbarClass: \"bg-blue\",\n\t\t},\n\t\tvolumeProgressProps = {\n\t\t\tbarClass: \"bg-blue\",\n\t\t},\n\t\tclassName,\n\t\tonFullScreenChange,\n\t\t...restProps\n\t} = props;\n\tconst state = useReactive({\n\t\tplaying: autoplay,\n\t\tvolume: muted ? 0 : volume,\n\t\tvolumeCache: 0,\n\t\tmuted,\n\t\tcurrent: 0,\n\t\tduration: 0,\n\t\tisFullscreen: false,\n\t\tcontrolHidden: true,\n\t\tdraggingProgress: false,\n\t});\n\tconst videoRef = useRef<HTMLVideoElement>(null);\n\tconst hiddenTO = useRef<any>(null);\n\n\tconst timeUpdateListener = (e) => {\n\t\tconst tar = e.target;\n\t\tif (tar.paused || state.draggingProgress) return;\n\n\t\tObject.assign(state, {\n\t\t\tcurrent: tar.currentTime,\n\t\t});\n\t};\n\n\tconst playChangeListener = (e) => {\n\t\tstate.playing = !e.target.paused;\n\t};\n\n\tconst fsChangeListener = () => {\n\t\tconst tar = videoRef.current?.parentElement;\n\t\tif (!tar) return;\n\n\t\tstate.isFullscreen = document.fullscreenElement === tar;\n\t};\n\n\tconst volumeChangeListener = (e) => {\n\t\tconst tar = e.target;\n\t\tObject.assign(state, {\n\t\t\tvolume: tar.volume * 100,\n\t\t\tmuted: tar.volume === 0,\n\t\t});\n\t};\n\n\tconst handlePlay = () => {\n\t\tconst v = videoRef.current;\n\t\tif (!v) return;\n\n\t\tv.paused ? v.play() : v.pause();\n\t};\n\n\tconst handleReady = (e) => {\n\t\tconst tar = e.target;\n\t\tObject.assign(state, {\n\t\t\tduration: tar.duration,\n\t\t\tcurrent: tar.currentTime,\n\t\t});\n\t\ttar.volume = state.volume / 100;\n\t};\n\n\tconst handleMuted = () => {\n\t\tconst v = videoRef.current;\n\t\tif (!v) return;\n\n\t\tif (v.volume > 0) {\n\t\t\tstate.volumeCache = v.volume;\n\t\t\tv.volume = 0;\n\t\t\treturn;\n\t\t}\n\t\tv.volume = state.volumeCache === 0 ? 0.5 : state.volumeCache;\n\t};\n\n\tconst handleStop = () => {\n\t\tconst v = videoRef.current;\n\t\tif (!v) return;\n\n\t\tv.currentTime = 0;\n\t\tv.pause();\n\t};\n\n\tconst handleFullscreen = () => {\n\t\tconst tar = videoRef.current?.parentElement;\n\t\tif (!tar) return;\n\n\t\tstate.isFullscreen ? exitFullScreen() : fullScreen(tar);\n\t\tonFullScreenChange?.(!state.isFullscreen);\n\t};\n\n\tconst handleUpdateTime = (t) => {\n\t\tconst v = videoRef.current;\n\t\tif (!v) return;\n\n\t\tv.currentTime = (state.duration * t) / 100;\n\t};\n\n\tconst handleUpdateVolume = (t) => {\n\t\tconst v = videoRef.current;\n\t\tif (!v) return;\n\n\t\tv.volume = t / 100;\n\t};\n\n\tconst showControls = !hideControls && !useOriginControls;\n\n\tconst clearHiddenTO = () => {\n\t\tif (!hiddenTO.current) return;\n\t\tclearTimeout(hiddenTO.current);\n\t\thiddenTO.current = null;\n\t};\n\n\tconst setHiddenFalse = () => {\n\t\tif (!showControls || !state.controlHidden) return;\n\t\tstate.controlHidden = false;\n\n\t\tclearHiddenTO();\n\t\thiddenTO.current = setTimeout(() => {\n\t\t\tstate.controlHidden = true;\n\t\t}, 1000);\n\t};\n\n\tconst handleDraggingProgress = (dragging) => {\n\t\tstate.draggingProgress = dragging;\n\t};\n\n\tconst handleMouseMove = throttle({ interval: 900 }, setHiddenFalse);\n\n\tuseImperativeHandle(ref, () => ({\n\t\tplay: () => {\n\t\t\tconst v = videoRef.current;\n\t\t\tif (!v) return;\n\n\t\t\tv.play();\n\t\t},\n\t\tpause: () => {\n\t\t\tconst v = videoRef.current;\n\t\t\tif (!v) return;\n\n\t\t\tv.pause();\n\t\t},\n\t\tstop: handleStop,\n\t\tfullscreen: handleFullscreen,\n\t\tgetVideo: () => videoRef.current,\n\t}));\n\n\tuseEffect(() => {\n\t\tconst v = videoRef.current;\n\t\tif (!v) return;\n\n\t\tv.addEventListener(\"timeupdate\", timeUpdateListener);\n\t\tv.addEventListener(\"play\", playChangeListener);\n\t\tv.addEventListener(\"pause\", playChangeListener);\n\t\tv.addEventListener(\"volumechange\", volumeChangeListener);\n\t\tdocument.addEventListener(\"fullscreenchange\", fsChangeListener);\n\n\t\treturn () => {\n\t\t\tclearHiddenTO();\n\t\t\tv.removeEventListener(\"timeupdate\", timeUpdateListener);\n\t\t\tv.removeEventListener(\"play\", playChangeListener);\n\t\t\tv.removeEventListener(\"pause\", playChangeListener);\n\t\t\tv.removeEventListener(\"volumechange\", volumeChangeListener);\n\t\t\tdocument.removeEventListener(\"fullscreenchange\", fsChangeListener);\n\t\t};\n\t}, []);\n\n\tconst currentValue = (state.current / state.duration) * 100;\n\n\treturn (\n\t\t<div\n\t\t\tclassName={classNames(\"i-video\", className)}\n\t\t\tstyle={{ height, width, ...style }}\n\t\t\tonClick={handlePlay}\n\t\t\tonDoubleClick={() => handleFullscreen()}\n\t\t\tonMouseMove={handleMouseMove}\n\t\t>\n\t\t\t<video\n\t\t\t\tref={videoRef}\n\t\t\t\tonCanPlay={handleReady}\n\t\t\t\t{...restProps}\n\t\t\t\tcontrols={useOriginControls}\n\t\t\t/>\n\n\t\t\t{showControls && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={classNames(\"i-video-controls\", {\n\t\t\t\t\t\t\"i-video-controls-hidden\": state.controlHidden,\n\t\t\t\t\t})}\n\t\t\t\t\tonClick={(e) => e.stopPropagation()}\n\t\t\t\t>\n\t\t\t\t\t<Button.Toggle\n\t\t\t\t\t\tclassName='i-video-btn'\n\t\t\t\t\t\tflat\n\t\t\t\t\t\tsquare\n\t\t\t\t\t\tafter={<Icon icon={<PauseRound />} />}\n\t\t\t\t\t\tactive={state.playing}\n\t\t\t\t\t\tonClick={handlePlay}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={<PlayArrowRound />} />\n\t\t\t\t\t</Button.Toggle>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclassName='i-video-btn'\n\t\t\t\t\t\tflat\n\t\t\t\t\t\tsquare\n\t\t\t\t\t\tonClick={handleStop}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={<StopRound />} />\n\t\t\t\t\t</Button>\n\t\t\t\t\t<span className='i-video-times font-sm'>\n\t\t\t\t\t\t<Text.Time seconds={state.current} /> /\n\t\t\t\t\t\t<Text.Time seconds={state.duration} />\n\t\t\t\t\t</span>\n\t\t\t\t\t<Progress\n\t\t\t\t\t\t{...timeProgressProps}\n\t\t\t\t\t\tvalue={currentValue}\n\t\t\t\t\t\tonChange={handleUpdateTime}\n\t\t\t\t\t\tonDraggingChange={handleDraggingProgress}\n\t\t\t\t\t/>\n\n\t\t\t\t\t<div className='i-video-control-volume'>\n\t\t\t\t\t\t<Button.Toggle\n\t\t\t\t\t\t\tclassName='i-video-btn'\n\t\t\t\t\t\t\tflat\n\t\t\t\t\t\t\tsquare\n\t\t\t\t\t\t\tactive={state.volume <= 0}\n\t\t\t\t\t\t\tafter={\n\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\ticon={<VolumeOffRound />}\n\t\t\t\t\t\t\t\t\tstyle={{ padding: \".125em\" }}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonClick={handleMuted}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Icon icon={<VolumeDownRound />} />\n\t\t\t\t\t\t</Button.Toggle>\n\n\t\t\t\t\t\t<div className='i-video-volume'>\n\t\t\t\t\t\t\t<Progress\n\t\t\t\t\t\t\t\tstyle={{ height: 100 }}\n\t\t\t\t\t\t\t\tvertical\n\t\t\t\t\t\t\t\t{...volumeProgressProps}\n\t\t\t\t\t\t\t\tvalue={state.volume}\n\t\t\t\t\t\t\t\tonChange={handleUpdateVolume}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<Button.Toggle\n\t\t\t\t\t\tclassName='i-video-btn'\n\t\t\t\t\t\tflat\n\t\t\t\t\t\tsquare\n\t\t\t\t\t\tafter={<Icon icon={<FullscreenExitRound />} />}\n\t\t\t\t\t\tactive={state.isFullscreen}\n\t\t\t\t\t\tonClick={() => handleFullscreen()}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={<FullscreenRound />} />\n\t\t\t\t\t</Button.Toggle>\n\t\t\t\t</div>\n\t\t\t)}\n\t\t</div>\n\t);\n};\n\nexport default Video;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;;AAqBA,MAAM,KAAK,GAAG,CAAC,KAAa,KAAI;IAC/B,MAAM,EACL,GAAG,EACH,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,MAAM,GAAG,EAAE,EACX,MAAM,EACN,KAAK,EACL,iBAAiB,EACjB,iBAAiB,GAAG;AACnB,QAAA,QAAQ,EAAE,SAAS;AACnB,KAAA,EACD,mBAAmB,GAAG;AACrB,QAAA,QAAQ,EAAE,SAAS;KACnB,EACD,SAAS,EACT,kBAAkB,EAClB,GAAG,SAAS,EACZ,GAAG,KAAK;I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,GAAA,CAAC,IAAI,EAAA,EAAC,IAAI,EAAEA,GAAC,CAAA,eAAe,KAAG,EAAI,CAAA,EAAA,CACpB,EAEhBA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,gBAAgB,EAAA,QAAA,EAC9BA,IAAC,QAAQ,EAAA,EACR,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,EACtB,QAAQ,EACJ,IAAA,EAAA,GAAA,mBAAmB,EACvB,KAAK,EAAE,KAAK,CAAC,MAAM,EACnB,QAAQ,EAAE,kBAAkB,EAC3B,CAAA,EAAA,CACG,IACD,EAENA,GAAA,CAAC,MAAM,CAAC,MAAM,EAAA,EACb,SAAS,EAAC,aAAa,EACvB,IAAI,EACJ,IAAA,EAAA,MAAM,EACN,IAAA,EAAA,KAAK,EAAEA,GAAA,CAAC,IAAI,EAAC,EAAA,IAAI,EAAEA,GAAA,CAAC,mBAAmB,EAAA,EAAA,CAAG,EAAI,CAAA,EAC9C,MAAM,EAAE,KAAK,CAAC,YAAY,EAC1B,OAAO,EAAE,MAAM,gBAAgB,EAAE,EAAA,QAAA,EAEjCA,GAAC,CAAA,IAAI,EAAC,EAAA,IAAI,EAAEA,GAAC,CAAA,eAAe,EAAG,EAAA,CAAA,EAAA,CAAI,EACpB,CAAA,CAAA,EAAA,CACX,CACN,CAAA,EAAA,CACI;AAER;;;;"}
|
|
1
|
+
{"version":3,"file":"video.js","sources":["../../../../packages/components/video/video.tsx"],"sourcesContent":["import {\n\tFullscreenExitRound,\n\tFullscreenRound,\n\tPauseRound,\n\tPlayArrowRound,\n\tStopRound,\n\tVolumeDownRound,\n\tVolumeOffRound,\n} from \"@ricons/material\";\nimport { useReactive } from \"ahooks\";\nimport classNames from \"classnames\";\nimport { throttle } from \"radash\";\nimport { useEffect, useImperativeHandle, useRef } from \"react\";\nimport { exitFullScreen, fullScreen } from \"../../js/utils\";\nimport Button from \"../button\";\nimport Icon from \"../icon\";\nimport Progress from \"../progress\";\nimport Text from \"../text\";\nimport \"./index.css\";\nimport { IVideo } from \"./type\";\n\nconst Video = (props: IVideo) => {\n\tconst {\n\t\tref,\n\t\tstyle,\n\t\thideControls,\n\t\tautoplay,\n\t\tmuted,\n\t\tvolume = 50,\n\t\theight,\n\t\twidth,\n\t\tuseOriginControls,\n\t\ttimeProgressProps = {\n\t\t\tbarClass: \"bg-blue\",\n\t\t},\n\t\tvolumeProgressProps = {\n\t\t\tbarClass: \"bg-blue\",\n\t\t},\n\t\tclassName,\n\t\tonFullScreenChange,\n\t\t...restProps\n\t} = props;\n\tconst state = useReactive({\n\t\tplaying: autoplay,\n\t\tvolume: muted ? 0 : volume,\n\t\tvolumeCache: 0,\n\t\tmuted,\n\t\tcurrent: 0,\n\t\tduration: 0,\n\t\tisFullscreen: false,\n\t\tcontrolHidden: true,\n\t\tdraggingProgress: false,\n\t});\n\tconst videoRef = useRef<HTMLVideoElement>(null);\n\tconst hiddenTO = useRef<any>(null);\n\n\tconst timeUpdateListener = (e) => {\n\t\tconst tar = e.target;\n\t\tif (tar.paused || state.draggingProgress) return;\n\n\t\tObject.assign(state, {\n\t\t\tcurrent: tar.currentTime,\n\t\t});\n\t};\n\n\tconst playChangeListener = (e) => {\n\t\tstate.playing = !e.target.paused;\n\t};\n\n\tconst fsChangeListener = () => {\n\t\tif (typeof document === \"undefined\") return;\n\t\tconst tar = videoRef.current?.parentElement;\n\t\tif (!tar) return;\n\n\t\tstate.isFullscreen = document.fullscreenElement === tar;\n\t};\n\n\tconst volumeChangeListener = (e) => {\n\t\tconst tar = e.target;\n\t\tObject.assign(state, {\n\t\t\tvolume: tar.volume * 100,\n\t\t\tmuted: tar.volume === 0,\n\t\t});\n\t};\n\n\tconst handlePlay = () => {\n\t\tconst v = videoRef.current;\n\t\tif (!v) return;\n\n\t\tv.paused ? v.play() : v.pause();\n\t};\n\n\tconst handleReady = (e) => {\n\t\tconst tar = e.target;\n\t\tObject.assign(state, {\n\t\t\tduration: tar.duration,\n\t\t\tcurrent: tar.currentTime,\n\t\t});\n\t\ttar.volume = state.volume / 100;\n\t};\n\n\tconst handleMuted = () => {\n\t\tconst v = videoRef.current;\n\t\tif (!v) return;\n\n\t\tif (v.volume > 0) {\n\t\t\tstate.volumeCache = v.volume;\n\t\t\tv.volume = 0;\n\t\t\treturn;\n\t\t}\n\t\tv.volume = state.volumeCache === 0 ? 0.5 : state.volumeCache;\n\t};\n\n\tconst handleStop = () => {\n\t\tconst v = videoRef.current;\n\t\tif (!v) return;\n\n\t\tv.currentTime = 0;\n\t\tv.pause();\n\t};\n\n\tconst handleFullscreen = () => {\n\t\tconst tar = videoRef.current?.parentElement;\n\t\tif (!tar) return;\n\n\t\tstate.isFullscreen ? exitFullScreen() : fullScreen(tar);\n\t\tonFullScreenChange?.(!state.isFullscreen);\n\t};\n\n\tconst handleUpdateTime = (t) => {\n\t\tconst v = videoRef.current;\n\t\tif (!v) return;\n\n\t\tv.currentTime = (state.duration * t) / 100;\n\t};\n\n\tconst handleUpdateVolume = (t) => {\n\t\tconst v = videoRef.current;\n\t\tif (!v) return;\n\n\t\tv.volume = t / 100;\n\t};\n\n\tconst showControls = !hideControls && !useOriginControls;\n\n\tconst clearHiddenTO = () => {\n\t\tif (!hiddenTO.current) return;\n\t\tclearTimeout(hiddenTO.current);\n\t\thiddenTO.current = null;\n\t};\n\n\tconst setHiddenFalse = () => {\n\t\tif (!showControls || !state.controlHidden) return;\n\t\tstate.controlHidden = false;\n\n\t\tclearHiddenTO();\n\t\thiddenTO.current = setTimeout(() => {\n\t\t\tstate.controlHidden = true;\n\t\t}, 1000);\n\t};\n\n\tconst handleDraggingProgress = (dragging) => {\n\t\tstate.draggingProgress = dragging;\n\t};\n\n\tconst handleMouseMove = throttle({ interval: 900 }, setHiddenFalse);\n\n\tuseImperativeHandle(ref, () => ({\n\t\tplay: () => {\n\t\t\tconst v = videoRef.current;\n\t\t\tif (!v) return;\n\n\t\t\tv.play();\n\t\t},\n\t\tpause: () => {\n\t\t\tconst v = videoRef.current;\n\t\t\tif (!v) return;\n\n\t\t\tv.pause();\n\t\t},\n\t\tstop: handleStop,\n\t\tfullscreen: handleFullscreen,\n\t\tgetVideo: () => videoRef.current,\n\t}));\n\n\tuseEffect(() => {\n\t\tif (typeof document === \"undefined\") return;\n\n\t\tconst v = videoRef.current;\n\t\tif (!v) return;\n\n\t\tv.addEventListener(\"timeupdate\", timeUpdateListener);\n\t\tv.addEventListener(\"play\", playChangeListener);\n\t\tv.addEventListener(\"pause\", playChangeListener);\n\t\tv.addEventListener(\"volumechange\", volumeChangeListener);\n\t\tdocument.addEventListener(\"fullscreenchange\", fsChangeListener);\n\n\t\treturn () => {\n\t\t\tclearHiddenTO();\n\t\t\tv.removeEventListener(\"timeupdate\", timeUpdateListener);\n\t\t\tv.removeEventListener(\"play\", playChangeListener);\n\t\t\tv.removeEventListener(\"pause\", playChangeListener);\n\t\t\tv.removeEventListener(\"volumechange\", volumeChangeListener);\n\t\t\tdocument.removeEventListener(\"fullscreenchange\", fsChangeListener);\n\t\t};\n\t}, []);\n\n\tconst currentValue = (state.current / state.duration) * 100;\n\n\treturn (\n\t\t<div\n\t\t\tclassName={classNames(\"i-video\", className)}\n\t\t\tstyle={{ height, width, ...style }}\n\t\t\tonClick={handlePlay}\n\t\t\tonDoubleClick={() => handleFullscreen()}\n\t\t\tonMouseMove={handleMouseMove}\n\t\t>\n\t\t\t<video\n\t\t\t\tref={videoRef}\n\t\t\t\tonCanPlay={handleReady}\n\t\t\t\t{...restProps}\n\t\t\t\tcontrols={useOriginControls}\n\t\t\t/>\n\n\t\t\t{showControls && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={classNames(\"i-video-controls\", {\n\t\t\t\t\t\t\"i-video-controls-hidden\": state.controlHidden,\n\t\t\t\t\t})}\n\t\t\t\t\tonClick={(e) => e.stopPropagation()}\n\t\t\t\t>\n\t\t\t\t\t<Button.Toggle\n\t\t\t\t\t\tclassName='i-video-btn'\n\t\t\t\t\t\tflat\n\t\t\t\t\t\tsquare\n\t\t\t\t\t\tafter={<Icon icon={<PauseRound />} />}\n\t\t\t\t\t\tactive={state.playing}\n\t\t\t\t\t\tonClick={handlePlay}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={<PlayArrowRound />} />\n\t\t\t\t\t</Button.Toggle>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclassName='i-video-btn'\n\t\t\t\t\t\tflat\n\t\t\t\t\t\tsquare\n\t\t\t\t\t\tonClick={handleStop}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={<StopRound />} />\n\t\t\t\t\t</Button>\n\t\t\t\t\t<span className='i-video-times font-sm'>\n\t\t\t\t\t\t<Text.Time seconds={state.current} /> /\n\t\t\t\t\t\t<Text.Time seconds={state.duration} />\n\t\t\t\t\t</span>\n\t\t\t\t\t<Progress\n\t\t\t\t\t\t{...timeProgressProps}\n\t\t\t\t\t\tvalue={currentValue}\n\t\t\t\t\t\tonChange={handleUpdateTime}\n\t\t\t\t\t\tonDraggingChange={handleDraggingProgress}\n\t\t\t\t\t/>\n\n\t\t\t\t\t<div className='i-video-control-volume'>\n\t\t\t\t\t\t<Button.Toggle\n\t\t\t\t\t\t\tclassName='i-video-btn'\n\t\t\t\t\t\t\tflat\n\t\t\t\t\t\t\tsquare\n\t\t\t\t\t\t\tactive={state.volume <= 0}\n\t\t\t\t\t\t\tafter={\n\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\ticon={<VolumeOffRound />}\n\t\t\t\t\t\t\t\t\tstyle={{ padding: \".125em\" }}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonClick={handleMuted}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Icon icon={<VolumeDownRound />} />\n\t\t\t\t\t\t</Button.Toggle>\n\n\t\t\t\t\t\t<div className='i-video-volume'>\n\t\t\t\t\t\t\t<Progress\n\t\t\t\t\t\t\t\tstyle={{ height: 100 }}\n\t\t\t\t\t\t\t\tvertical\n\t\t\t\t\t\t\t\t{...volumeProgressProps}\n\t\t\t\t\t\t\t\tvalue={state.volume}\n\t\t\t\t\t\t\t\tonChange={handleUpdateVolume}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<Button.Toggle\n\t\t\t\t\t\tclassName='i-video-btn'\n\t\t\t\t\t\tflat\n\t\t\t\t\t\tsquare\n\t\t\t\t\t\tafter={<Icon icon={<FullscreenExitRound />} />}\n\t\t\t\t\t\tactive={state.isFullscreen}\n\t\t\t\t\t\tonClick={() => handleFullscreen()}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={<FullscreenRound />} />\n\t\t\t\t\t</Button.Toggle>\n\t\t\t\t</div>\n\t\t\t)}\n\t\t</div>\n\t);\n};\n\nexport default Video;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;;AAqBA,MAAM,KAAK,GAAG,CAAC,KAAa,KAAI;IAC/B,MAAM,EACL,GAAG,EACH,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,MAAM,GAAG,EAAE,EACX,MAAM,EACN,KAAK,EACL,iBAAiB,EACjB,iBAAiB,GAAG;AACnB,QAAA,QAAQ,EAAE,SAAS;AACnB,KAAA,EACD,mBAAmB,GAAG;AACrB,QAAA,QAAQ,EAAE,SAAS;KACnB,EACD,SAAS,EACT,kBAAkB,EAClB,GAAG,SAAS,EACZ,GAAG,KAAK;IACT,MAAM,KAAK,GAAG,WAAW,CAAC;AACzB,QAAA,OAAO,EAAE,QAAQ;QACjB,MAAM,EAAE,KAAK,GAAG,CAAC,GAAG,MAAM;AAC1B,QAAA,WAAW,EAAE,CAAC;QACd,KAAK;AACL,QAAA,OAAO,EAAE,CAAC;AACV,QAAA,QAAQ,EAAE,CAAC;AACX,QAAA,YAAY,EAAE,KAAK;AACnB,QAAA,aAAa,EAAE,IAAI;AACnB,QAAA,gBAAgB,EAAE,KAAK;AACvB,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,GAAG,EAAE,EACtB,QAAQ,EACJ,IAAA,EAAA,GAAA,mBAAmB,EACvB,KAAK,EAAE,KAAK,CAAC,MAAM,EACnB,QAAQ,EAAE,kBAAkB,EAC3B,CAAA,EAAA,CACG,IACD,EAENA,GAAA,CAAC,MAAM,CAAC,MAAM,EAAA,EACb,SAAS,EAAC,aAAa,EACvB,IAAI,EACJ,IAAA,EAAA,MAAM,EACN,IAAA,EAAA,KAAK,EAAEA,GAAA,CAAC,IAAI,EAAC,EAAA,IAAI,EAAEA,GAAA,CAAC,mBAAmB,EAAA,EAAA,CAAG,EAAI,CAAA,EAC9C,MAAM,EAAE,KAAK,CAAC,YAAY,EAC1B,OAAO,EAAE,MAAM,gBAAgB,EAAE,EAAA,QAAA,EAEjCA,GAAC,CAAA,IAAI,EAAC,EAAA,IAAI,EAAEA,GAAC,CAAA,eAAe,EAAG,EAAA,CAAA,EAAA,CAAI,EACpB,CAAA,CAAA,EAAA,CACX,CACN,CAAA,EAAA,CACI;AAER;;;;"}
|
package/lib/es/js/hooks.js
CHANGED
|
@@ -1,31 +1,41 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
3
|
+
const isBrowser = typeof window !== "undefined";
|
|
4
|
+
let MouseMoveEvents;
|
|
5
|
+
let MouseUpEvents;
|
|
6
|
+
let KeydownEvents;
|
|
7
|
+
let touchable;
|
|
8
|
+
let EVENTS;
|
|
9
|
+
if (isBrowser) {
|
|
10
|
+
MouseMoveEvents = new Set();
|
|
11
|
+
MouseUpEvents = new Set();
|
|
12
|
+
KeydownEvents = new Set();
|
|
13
|
+
touchable = "ontouchend" in document;
|
|
14
|
+
EVENTS = {
|
|
15
|
+
MOVE: touchable ? "touchmove" : "mousemove",
|
|
16
|
+
UP: touchable ? "touchend" : "mouseup",
|
|
17
|
+
KEYDOWN: "keydown",
|
|
18
|
+
};
|
|
19
|
+
document.addEventListener(EVENTS.MOVE, (e) => {
|
|
20
|
+
for (const listener of MouseMoveEvents.values()) {
|
|
21
|
+
listener(e);
|
|
22
|
+
}
|
|
23
|
+
}, { passive: false });
|
|
24
|
+
document.addEventListener(EVENTS.UP, (e) => {
|
|
25
|
+
for (const listener of MouseUpEvents.values()) {
|
|
26
|
+
listener(e);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
document.addEventListener(EVENTS.KEYDOWN, (e) => {
|
|
30
|
+
for (const listener of KeydownEvents.values()) {
|
|
31
|
+
listener(e);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
27
35
|
function useMouseMove(listener, options) {
|
|
28
36
|
useEffect(() => {
|
|
37
|
+
if (!isBrowser || options?.disabled)
|
|
38
|
+
return;
|
|
29
39
|
MouseMoveEvents.add(listener);
|
|
30
40
|
return () => {
|
|
31
41
|
MouseMoveEvents.delete(listener);
|
|
@@ -34,6 +44,8 @@ function useMouseMove(listener, options) {
|
|
|
34
44
|
}
|
|
35
45
|
function useMouseUp(listener, options) {
|
|
36
46
|
useEffect(() => {
|
|
47
|
+
if (!isBrowser || options?.disabled)
|
|
48
|
+
return;
|
|
37
49
|
MouseUpEvents.add(listener);
|
|
38
50
|
return () => {
|
|
39
51
|
MouseUpEvents.delete(listener);
|
|
@@ -42,7 +54,7 @@ function useMouseUp(listener, options) {
|
|
|
42
54
|
}
|
|
43
55
|
function useKeydown(listener, options) {
|
|
44
56
|
useEffect(() => {
|
|
45
|
-
if (options?.disabled)
|
|
57
|
+
if (!isBrowser || options?.disabled)
|
|
46
58
|
return;
|
|
47
59
|
KeydownEvents.add(listener);
|
|
48
60
|
return () => {
|
|
@@ -51,25 +63,39 @@ function useKeydown(listener, options) {
|
|
|
51
63
|
}, [listener]);
|
|
52
64
|
}
|
|
53
65
|
function useIntersectionObserver(configs) {
|
|
54
|
-
const WM = new WeakMap();
|
|
55
|
-
const IO =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
const WM = useRef(new WeakMap());
|
|
67
|
+
const IO = useRef(null);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (!isBrowser)
|
|
70
|
+
return;
|
|
71
|
+
IO.current = new IntersectionObserver((entries) => {
|
|
72
|
+
entries.map((entry) => {
|
|
73
|
+
const callback = WM.current.get(entry.target);
|
|
74
|
+
callback?.(entry.target, entry.isIntersecting);
|
|
75
|
+
});
|
|
76
|
+
}, configs);
|
|
77
|
+
return () => {
|
|
78
|
+
IO.current?.disconnect();
|
|
79
|
+
};
|
|
80
|
+
}, []);
|
|
61
81
|
function observe(target, callback) {
|
|
62
|
-
if (
|
|
82
|
+
if (!isBrowser || !IO.current || !target)
|
|
83
|
+
return;
|
|
84
|
+
if (WM.current.get(target))
|
|
63
85
|
return;
|
|
64
|
-
WM.set(target, callback);
|
|
65
|
-
|
|
86
|
+
WM.current.set(target, callback);
|
|
87
|
+
IO.current.observe(target);
|
|
66
88
|
}
|
|
67
89
|
function unobserve(target) {
|
|
68
|
-
|
|
69
|
-
|
|
90
|
+
if (!isBrowser || !IO.current || !target)
|
|
91
|
+
return;
|
|
92
|
+
IO.current.unobserve(target);
|
|
93
|
+
WM.current.delete(target);
|
|
70
94
|
}
|
|
71
95
|
function disconnect() {
|
|
72
|
-
IO.
|
|
96
|
+
if (!isBrowser || !IO.current)
|
|
97
|
+
return;
|
|
98
|
+
IO.current.disconnect();
|
|
73
99
|
}
|
|
74
100
|
return {
|
|
75
101
|
observe,
|
|
@@ -78,25 +104,39 @@ function useIntersectionObserver(configs) {
|
|
|
78
104
|
};
|
|
79
105
|
}
|
|
80
106
|
function useResizeObserver() {
|
|
81
|
-
const WM = new WeakMap();
|
|
82
|
-
const IO =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
107
|
+
const WM = useRef(new WeakMap());
|
|
108
|
+
const IO = useRef(null);
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (!isBrowser)
|
|
111
|
+
return;
|
|
112
|
+
IO.current = new ResizeObserver((entries) => {
|
|
113
|
+
entries.map((entry) => {
|
|
114
|
+
const callback = WM.current.get(entry.target);
|
|
115
|
+
callback?.(entry.target);
|
|
116
|
+
});
|
|
86
117
|
});
|
|
87
|
-
|
|
118
|
+
return () => {
|
|
119
|
+
IO.current?.disconnect();
|
|
120
|
+
};
|
|
121
|
+
}, []);
|
|
88
122
|
function observe(target, callback) {
|
|
89
|
-
if (
|
|
123
|
+
if (!isBrowser || !IO.current || !target)
|
|
90
124
|
return;
|
|
91
|
-
|
|
92
|
-
|
|
125
|
+
if (WM.current.get(target))
|
|
126
|
+
return;
|
|
127
|
+
IO.current.observe(target);
|
|
128
|
+
WM.current.set(target, callback);
|
|
93
129
|
}
|
|
94
130
|
function unobserve(target) {
|
|
95
|
-
|
|
96
|
-
|
|
131
|
+
if (!isBrowser || !IO.current || !target)
|
|
132
|
+
return;
|
|
133
|
+
IO.current.unobserve(target);
|
|
134
|
+
WM.current.delete(target);
|
|
97
135
|
}
|
|
98
136
|
function disconnect() {
|
|
99
|
-
IO.
|
|
137
|
+
if (!isBrowser || !IO.current)
|
|
138
|
+
return;
|
|
139
|
+
IO.current.disconnect();
|
|
100
140
|
}
|
|
101
141
|
return {
|
|
102
142
|
observe,
|
package/lib/es/js/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../packages/js/hooks.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\ntype TMouseEvent = (e: MouseEvent) => void;\ntype TKeyboardEvent = (e: KeyboardEvent) => void;\ntype TEventOption = {\n\tdisabled?: boolean;\n};\n\nconst ClickEvents = new Set<TMouseEvent>();\
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../packages/js/hooks.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\ntype TMouseEvent = (e: MouseEvent) => void;\ntype TKeyboardEvent = (e: KeyboardEvent) => void;\ntype TEventOption = {\n\tdisabled?: boolean;\n};\n\nconst isBrowser = typeof window !== \"undefined\";\n\nlet ClickEvents: Set<TMouseEvent>;\nlet MouseMoveEvents: Set<TMouseEvent>;\nlet MouseUpEvents: Set<TMouseEvent>;\nlet KeydownEvents: Set<TKeyboardEvent>;\nlet touchable: boolean;\nlet EVENTS: any;\n\nif (isBrowser) {\n\tClickEvents = new Set<TMouseEvent>();\n\tMouseMoveEvents = new Set<TMouseEvent>();\n\tMouseUpEvents = new Set<TMouseEvent>();\n\tKeydownEvents = new Set<TKeyboardEvent>();\n\ttouchable = \"ontouchend\" in document;\n\tEVENTS = {\n\t\tMOVE: touchable ? \"touchmove\" : \"mousemove\",\n\t\tUP: touchable ? \"touchend\" : \"mouseup\",\n\t\tKEYDOWN: \"keydown\",\n\t};\n\n\tdocument.addEventListener(\n\t\tEVENTS.MOVE,\n\t\t(e: MouseEvent) => {\n\t\t\tfor (const listener of MouseMoveEvents.values()) {\n\t\t\t\tlistener(e);\n\t\t\t}\n\t\t},\n\t\t{ passive: false }\n\t);\n\n\tdocument.addEventListener(EVENTS.UP, (e) => {\n\t\tfor (const listener of MouseUpEvents.values()) {\n\t\t\tlistener(e);\n\t\t}\n\t});\n\n\tdocument.addEventListener(EVENTS.KEYDOWN, (e) => {\n\t\tfor (const listener of KeydownEvents.values()) {\n\t\t\tlistener(e);\n\t\t}\n\t});\n}\n\nexport function useMouseMove(listener: TMouseEvent, options?: TEventOption) {\n\tuseEffect(() => {\n\t\tif (!isBrowser || options?.disabled) return;\n\n\t\tMouseMoveEvents.add(listener);\n\t\treturn () => {\n\t\t\tMouseMoveEvents.delete(listener);\n\t\t};\n\t}, [listener]);\n}\n\nexport function useMouseUp(listener: TMouseEvent, options?: TEventOption) {\n\tuseEffect(() => {\n\t\tif (!isBrowser || options?.disabled) return;\n\n\t\tMouseUpEvents.add(listener);\n\t\treturn () => {\n\t\t\tMouseUpEvents.delete(listener);\n\t\t};\n\t}, [listener]);\n}\n\nexport function useKeydown(listener: TKeyboardEvent, options?: TEventOption) {\n\tuseEffect(() => {\n\t\tif (!isBrowser || options?.disabled) return;\n\n\t\tKeydownEvents.add(listener);\n\t\treturn () => {\n\t\t\tKeydownEvents.delete(listener);\n\t\t};\n\t}, [listener]);\n}\n\nexport function useIntersectionObserver(configs?: IntersectionObserverInit) {\n\tconst WM = useRef(new WeakMap());\n\tconst IO = useRef<IntersectionObserver | null>(null);\n\n\tuseEffect(() => {\n\t\tif (!isBrowser) return;\n\n\t\tIO.current = new IntersectionObserver((entries) => {\n\t\t\tentries.map((entry) => {\n\t\t\t\tconst callback = WM.current.get(entry.target);\n\t\t\t\tcallback?.(entry.target, entry.isIntersecting);\n\t\t\t});\n\t\t}, configs);\n\n\t\treturn () => {\n\t\t\tIO.current?.disconnect();\n\t\t};\n\t}, []);\n\n\tfunction observe(target: HTMLElement, callback: Function) {\n\t\tif (!isBrowser || !IO.current || !target) return;\n\t\tif (WM.current.get(target)) return;\n\n\t\tWM.current.set(target, callback);\n\t\tIO.current.observe(target);\n\t}\n\n\tfunction unobserve(target: HTMLElement) {\n\t\tif (!isBrowser || !IO.current || !target) return;\n\t\tIO.current.unobserve(target);\n\t\tWM.current.delete(target);\n\t}\n\n\tfunction disconnect() {\n\t\tif (!isBrowser || !IO.current) return;\n\t\tIO.current.disconnect();\n\t}\n\n\treturn {\n\t\tobserve,\n\t\tunobserve,\n\t\tdisconnect,\n\t};\n}\n\nexport function useResizeObserver() {\n\tconst WM = useRef(new WeakMap());\n\tconst IO = useRef<ResizeObserver | null>(null);\n\n\tuseEffect(() => {\n\t\tif (!isBrowser) return;\n\n\t\tIO.current = new ResizeObserver((entries) => {\n\t\t\tentries.map((entry) => {\n\t\t\t\tconst callback = WM.current.get(entry.target);\n\t\t\t\tcallback?.(entry.target);\n\t\t\t});\n\t\t});\n\n\t\treturn () => {\n\t\t\tIO.current?.disconnect();\n\t\t};\n\t}, []);\n\n\tfunction observe(target: HTMLElement, callback: Function) {\n\t\tif (!isBrowser || !IO.current || !target) return;\n\t\tif (WM.current.get(target)) return;\n\n\t\tIO.current.observe(target);\n\t\tWM.current.set(target, callback);\n\t}\n\n\tfunction unobserve(target: HTMLElement) {\n\t\tif (!isBrowser || !IO.current || !target) return;\n\t\tIO.current.unobserve(target);\n\t\tWM.current.delete(target);\n\t}\n\n\tfunction disconnect() {\n\t\tif (!isBrowser || !IO.current) return;\n\t\tIO.current.disconnect();\n\t}\n\n\treturn {\n\t\tobserve,\n\t\tunobserve,\n\t\tdisconnect,\n\t};\n}\n"],"names":[],"mappings":";;AAQA,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW;AAG/C,IAAI,eAAiC;AACrC,IAAI,aAA+B;AACnC,IAAI,aAAkC;AACtC,IAAI,SAAkB;AACtB,IAAI,MAAW;AAEf,IAAI,SAAS,EAAE;AAEd,IAAA,eAAe,GAAG,IAAI,GAAG,EAAe;AACxC,IAAA,aAAa,GAAG,IAAI,GAAG,EAAe;AACtC,IAAA,aAAa,GAAG,IAAI,GAAG,EAAkB;AACzC,IAAA,SAAS,GAAG,YAAY,IAAI,QAAQ;AACpC,IAAA,MAAM,GAAG;QACR,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,WAAW;QAC3C,EAAE,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS;AACtC,QAAA,OAAO,EAAE,SAAS;KAClB;IAED,QAAQ,CAAC,gBAAgB,CACxB,MAAM,CAAC,IAAI,EACX,CAAC,CAAa,KAAI;QACjB,KAAK,MAAM,QAAQ,IAAI,eAAe,CAAC,MAAM,EAAE,EAAE;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OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;QAC1B,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;;IAGjC,SAAS,SAAS,CAAC,MAAmB,EAAA;QACrC,IAAI,CAAC,SAAS,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,CAAC,MAAM;YAAE;AAC1C,QAAA,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC;AAC5B,QAAA,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;;AAG1B,IAAA,SAAS,UAAU,GAAA;AAClB,QAAA,IAAI,CAAC,SAAS,IAAI,CAAC,EAAE,CAAC,OAAO;YAAE;AAC/B,QAAA,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE;;IAGxB,OAAO;QACN,OAAO;QACP,SAAS;QACT,UAAU;KACV;AACF;;;;"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const TIMEOUT = 500;
|
|
2
2
|
const useRipple = () => {
|
|
3
|
-
if (document
|
|
3
|
+
if (!document)
|
|
4
4
|
return;
|
|
5
|
-
document.documentElement.dataset["
|
|
5
|
+
if (document.documentElement.dataset["ioca-ripple"])
|
|
6
|
+
return;
|
|
7
|
+
document.documentElement.dataset["ioca-ripple"] = "enable";
|
|
6
8
|
document.addEventListener("mousedown", listener);
|
|
7
9
|
};
|
|
8
10
|
function listener(e) {
|
|
@@ -13,6 +15,8 @@ function listener(e) {
|
|
|
13
15
|
triggerRipple(parent, e);
|
|
14
16
|
}
|
|
15
17
|
function triggerRipple(target, e) {
|
|
18
|
+
if (!document)
|
|
19
|
+
return;
|
|
16
20
|
const [$box, $ripple] = createRipple();
|
|
17
21
|
const rect = target.getBoundingClientRect();
|
|
18
22
|
const size = Math.max(rect.width, rect.height) * 2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../packages/js/useRipple/index.ts"],"sourcesContent":["import \"./ripple.css\";\n\nconst TIMEOUT = 500;\n\nconst useRipple = () => {\n\tif (document.documentElement.dataset[\"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../packages/js/useRipple/index.ts"],"sourcesContent":["import \"./ripple.css\";\n\nconst TIMEOUT = 500;\n\nconst useRipple = () => {\n\tif (!document) return;\n\tif (document.documentElement.dataset[\"ioca-ripple\"]) return;\n\tdocument.documentElement.dataset[\"ioca-ripple\"] = \"enable\";\n\n\tdocument.addEventListener(\"mousedown\", listener);\n};\n\nfunction listener(e: MouseEvent) {\n\tconst target = e.target as HTMLElement;\n\tconst parent = target.closest(\"[data-ripple]\") as HTMLElement;\n\n\tif (!target || !parent) return;\n\n\ttriggerRipple(parent, e);\n}\n\nfunction triggerRipple(target: HTMLElement, e: MouseEvent) {\n\tif (!document) return;\n\tconst [$box, $ripple] = createRipple();\n\tconst rect = target.getBoundingClientRect();\n\tconst size = Math.max(rect.width, rect.height) * 2;\n\n\t$ripple.style.cssText = `\n left: ${e.pageX - rect.left}px;\n top: ${e.pageY - rect.top}px;\n width: ${size}px;\n height: ${size}px;\n transition: all ${TIMEOUT / 1000}s;\n `;\n\ttarget.insertAdjacentElement(\"afterbegin\", $box);\n\ttarget.offsetHeight;\n\t$ripple.classList.add(\"i-ripple-active\");\n\n\tsetTimeout(() => {\n\t\t$box.remove();\n\t}, TIMEOUT);\n}\n\nfunction createRipple() {\n\tconst $box = document.createElement(\"SPAN\");\n\tconst $ripple = document.createElement(\"SPAN\");\n\n\t$box.className = \"i-ripple-container\";\n\t$ripple.className = \"i-ripple\";\n\n\t$box.append($ripple);\n\n\treturn [$box, $ripple];\n}\n\nexport default useRipple;\n"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG,GAAG;AAEb,MAAA,SAAS,GAAG,MAAK;AACtB,IAAA,IAAI,CAAC,QAAQ;QAAE;AACf,IAAA,IAAI,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,aAAa,CAAC;QAAE;IACrD,QAAQ,CAAC,eAA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