@blogmcp/mdx-render-vue 0.1.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.
- package/dist/_virtual/_plugin-vue_export-helper.js +10 -0
- package/dist/_virtual/constants.js +4 -0
- package/dist/_virtual/index.js +5 -0
- package/dist/_virtual/index2.js +4 -0
- package/dist/composables/index.d.ts +11 -0
- package/dist/composables/index.js +24 -0
- package/dist/composables/useAudioPlayer.d.ts +22 -0
- package/dist/composables/useAudioPlayer.js +58 -0
- package/dist/composables/useCallout.d.ts +43 -0
- package/dist/composables/useCallout.js +71 -0
- package/dist/composables/useCodeBlock.d.ts +23 -0
- package/dist/composables/useCodeBlock.js +67 -0
- package/dist/composables/useGallery.d.ts +37 -0
- package/dist/composables/useGallery.js +84 -0
- package/dist/composables/useMedia.d.ts +18 -0
- package/dist/composables/useMedia.js +9 -0
- package/dist/composables/useYouTube.d.ts +31 -0
- package/dist/composables/useYouTube.js +32 -0
- package/dist/edit/AlertEdit.vue.d.ts +12 -0
- package/dist/edit/AlertEdit.vue.js +4 -0
- package/dist/edit/AlertEdit.vue2.js +18 -0
- package/dist/edit/AudioPlayerEdit.vue.d.ts +3 -0
- package/dist/edit/AudioPlayerEdit.vue.js +117 -0
- package/dist/edit/AudioPlayerEdit.vue2.js +4 -0
- package/dist/edit/BadgeEdit.vue.d.ts +2 -0
- package/dist/edit/BadgeEdit.vue.js +4 -0
- package/dist/edit/BadgeEdit.vue2.js +13 -0
- package/dist/edit/ButtonEdit.vue.d.ts +2 -0
- package/dist/edit/ButtonEdit.vue.js +4 -0
- package/dist/edit/ButtonEdit.vue2.js +13 -0
- package/dist/edit/CalloutEdit.vue.d.ts +13 -0
- package/dist/edit/CalloutEdit.vue.js +85 -0
- package/dist/edit/CalloutEdit.vue2.js +4 -0
- package/dist/edit/CardEdit.vue.d.ts +12 -0
- package/dist/edit/CardEdit.vue.js +4 -0
- package/dist/edit/CardEdit.vue2.js +18 -0
- package/dist/edit/CodeBlockEdit.vue.d.ts +12 -0
- package/dist/edit/CodeBlockEdit.vue.js +7 -0
- package/dist/edit/CodeBlockEdit.vue2.js +89 -0
- package/dist/edit/GalleryEdit.vue.d.ts +3 -0
- package/dist/edit/GalleryEdit.vue.js +64 -0
- package/dist/edit/GalleryEdit.vue2.js +4 -0
- package/dist/edit/IconEdit.vue.d.ts +2 -0
- package/dist/edit/IconEdit.vue.js +4 -0
- package/dist/edit/IconEdit.vue2.js +13 -0
- package/dist/edit/TooltipEdit.vue.d.ts +16 -0
- package/dist/edit/TooltipEdit.vue.js +4 -0
- package/dist/edit/TooltipEdit.vue2.js +24 -0
- package/dist/edit/YouTubeEdit.vue.d.ts +3 -0
- package/dist/edit/YouTubeEdit.vue.js +41 -0
- package/dist/edit/YouTubeEdit.vue2.js +4 -0
- package/dist/edit/index.d.ts +29 -0
- package/dist/edit/index.js +35 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +75 -0
- package/dist/mdx-render-vue.css +31 -0
- package/dist/node_modules/@ark-ui/vue/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/factory.js +35 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/presence/use-presence-context.js +6 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/presence/use-presence.js +40 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-arrow-tip.js +5 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-arrow-tip.vue_vue_type_script_setup_true_lang.js +21 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-arrow.js +5 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-arrow.vue_vue_type_script_setup_true_lang.js +21 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-content.js +5 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-content.vue_vue_type_script_setup_true_lang.js +25 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-context.js +5 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-context.vue_vue_type_script_setup_true_lang.js +14 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-positioner.js +5 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-positioner.vue_vue_type_script_setup_true_lang.js +23 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-root-provider.js +5 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-root-provider.vue_vue_type_script_setup_true_lang.js +38 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-root.js +5 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-root.vue_vue_type_script_setup_true_lang.js +68 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-trigger.js +5 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip-trigger.vue_vue_type_script_setup_true_lang.js +25 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/tooltip.js +22 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/use-tooltip-context.js +6 -0
- package/dist/node_modules/@ark-ui/vue/dist/components/tooltip/use-tooltip.js +36 -0
- package/dist/node_modules/@ark-ui/vue/dist/providers/environment/use-environment-context.js +13 -0
- package/dist/node_modules/@ark-ui/vue/dist/providers/locale/use-locale-context.js +12 -0
- package/dist/node_modules/@ark-ui/vue/dist/utils/clean-props.js +8 -0
- package/dist/node_modules/@ark-ui/vue/dist/utils/create-context.js +14 -0
- package/dist/node_modules/@ark-ui/vue/dist/utils/dynamic.js +34 -0
- package/dist/node_modules/@ark-ui/vue/dist/utils/unref-element.js +8 -0
- package/dist/node_modules/@ark-ui/vue/dist/utils/use-forward-expose.js +46 -0
- package/dist/node_modules/@ark-ui/vue/dist/utils/use-render-strategy.js +5 -0
- package/dist/node_modules/@braintree/sanitize-url/dist/constants.js +20 -0
- package/dist/node_modules/@braintree/sanitize-url/dist/index.js +75 -0
- package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js +728 -0
- package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js +629 -0
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js +176 -0
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +151 -0
- package/dist/node_modules/@iconify/vue/dist/iconify.js +1691 -0
- package/dist/node_modules/@zag-js/anatomy/dist/create-anatomy.js +29 -0
- package/dist/node_modules/@zag-js/core/dist/create-machine.js +28 -0
- package/dist/node_modules/@zag-js/core/dist/merge-props.js +55 -0
- package/dist/node_modules/@zag-js/core/dist/scope.js +20 -0
- package/dist/node_modules/@zag-js/core/dist/state.js +176 -0
- package/dist/node_modules/@zag-js/core/dist/types.js +11 -0
- package/dist/node_modules/@zag-js/dom-query/dist/chunk-QZ7TP4HQ.js +6 -0
- package/dist/node_modules/@zag-js/dom-query/dist/computed-style.js +11 -0
- package/dist/node_modules/@zag-js/dom-query/dist/event.js +37 -0
- package/dist/node_modules/@zag-js/dom-query/dist/node.js +64 -0
- package/dist/node_modules/@zag-js/dom-query/dist/overflow.js +28 -0
- package/dist/node_modules/@zag-js/dom-query/dist/platform.js +23 -0
- package/dist/node_modules/@zag-js/dom-query/dist/query.js +6 -0
- package/dist/node_modules/@zag-js/dom-query/dist/raf.js +52 -0
- package/dist/node_modules/@zag-js/dom-query/dist/set.js +22 -0
- package/dist/node_modules/@zag-js/dom-query/dist/shared.js +8 -0
- package/dist/node_modules/@zag-js/focus-visible/dist/index.js +159 -0
- package/dist/node_modules/@zag-js/popper/dist/get-anchor.js +39 -0
- package/dist/node_modules/@zag-js/popper/dist/get-placement.js +296 -0
- package/dist/node_modules/@zag-js/popper/dist/get-styles.js +47 -0
- package/dist/node_modules/@zag-js/popper/dist/middleware.js +79 -0
- package/dist/node_modules/@zag-js/popper/dist/placement.js +7 -0
- package/dist/node_modules/@zag-js/presence/dist/presence.connect.js +18 -0
- package/dist/node_modules/@zag-js/presence/dist/presence.machine.js +175 -0
- package/dist/node_modules/@zag-js/tooltip/dist/tooltip.anatomy.js +7 -0
- package/dist/node_modules/@zag-js/tooltip/dist/tooltip.connect.js +155 -0
- package/dist/node_modules/@zag-js/tooltip/dist/tooltip.dom.js +24 -0
- package/dist/node_modules/@zag-js/tooltip/dist/tooltip.machine.js +416 -0
- package/dist/node_modules/@zag-js/tooltip/dist/tooltip.store.js +9 -0
- package/dist/node_modules/@zag-js/types/dist/prop-types.js +14 -0
- package/dist/node_modules/@zag-js/utils/dist/array.js +7 -0
- package/dist/node_modules/@zag-js/utils/dist/equal.js +36 -0
- package/dist/node_modules/@zag-js/utils/dist/functions.js +11 -0
- package/dist/node_modules/@zag-js/utils/dist/guard.js +26 -0
- package/dist/node_modules/@zag-js/utils/dist/object.js +16 -0
- package/dist/node_modules/@zag-js/utils/dist/store.js +44 -0
- package/dist/node_modules/@zag-js/utils/dist/warning.js +31 -0
- package/dist/node_modules/@zag-js/vue/dist/bindable.js +48 -0
- package/dist/node_modules/@zag-js/vue/dist/machine.js +258 -0
- package/dist/node_modules/@zag-js/vue/dist/normalize-props.js +42 -0
- package/dist/node_modules/@zag-js/vue/dist/refs.js +14 -0
- package/dist/node_modules/@zag-js/vue/dist/track.js +22 -0
- package/dist/node_modules/dompurify/dist/purify.es.js +1190 -0
- package/dist/registry.d.ts +76 -0
- package/dist/registry.js +164 -0
- package/dist/render/alert/Alert.vue.d.ts +18 -0
- package/dist/render/alert/Alert.vue.js +4 -0
- package/dist/render/alert/Alert.vue2.js +43 -0
- package/dist/render/alert/index.d.ts +2 -0
- package/dist/render/audioplayer/AudioPlayerDefault.vue.d.ts +3 -0
- package/dist/render/audioplayer/AudioPlayerDefault.vue.js +116 -0
- package/dist/render/audioplayer/AudioPlayerDefault.vue2.js +4 -0
- package/dist/render/audioplayer/index.d.ts +5 -0
- package/dist/render/audioplayer/index.js +5 -0
- package/dist/render/badge/Badge.vue.d.ts +10 -0
- package/dist/render/badge/Badge.vue.js +4 -0
- package/dist/render/badge/Badge.vue2.js +28 -0
- package/dist/render/badge/index.d.ts +2 -0
- package/dist/render/button/Button.vue.d.ts +13 -0
- package/dist/render/button/Button.vue.js +4 -0
- package/dist/render/button/Button.vue2.js +42 -0
- package/dist/render/button/index.d.ts +2 -0
- package/dist/render/callout/CalloutDefault.vue.d.ts +13 -0
- package/dist/render/callout/CalloutDefault.vue.js +86 -0
- package/dist/render/callout/CalloutDefault.vue2.js +4 -0
- package/dist/render/callout/CalloutMinimal.vue.d.ts +13 -0
- package/dist/render/callout/CalloutMinimal.vue.js +27 -0
- package/dist/render/callout/CalloutMinimal.vue2.js +4 -0
- package/dist/render/callout/index.d.ts +6 -0
- package/dist/render/callout/index.js +7 -0
- package/dist/render/card/Card.vue.d.ts +15 -0
- package/dist/render/card/Card.vue.js +4 -0
- package/dist/render/card/Card.vue2.js +29 -0
- package/dist/render/card/index.d.ts +2 -0
- package/dist/render/codeblock/CodeBlockDefault.vue.d.ts +12 -0
- package/dist/render/codeblock/CodeBlockDefault.vue.js +7 -0
- package/dist/render/codeblock/CodeBlockDefault.vue2.js +92 -0
- package/dist/render/codeblock/index.d.ts +5 -0
- package/dist/render/codeblock/index.js +5 -0
- package/dist/render/gallery/GalleryGrid.vue.d.ts +3 -0
- package/dist/render/gallery/GalleryGrid.vue.js +125 -0
- package/dist/render/gallery/GalleryGrid.vue2.js +4 -0
- package/dist/render/gallery/GalleryLightbox.vue.d.ts +16 -0
- package/dist/render/gallery/GalleryLightbox.vue.js +7 -0
- package/dist/render/gallery/GalleryLightbox.vue2.js +170 -0
- package/dist/render/gallery/index.d.ts +6 -0
- package/dist/render/gallery/index.js +7 -0
- package/dist/render/icon/Icon.vue.d.ts +9 -0
- package/dist/render/icon/Icon.vue.js +4 -0
- package/dist/render/icon/Icon.vue2.js +25 -0
- package/dist/render/icon/index.d.ts +2 -0
- package/dist/render/index.d.ts +40 -0
- package/dist/render/index.js +63 -0
- package/dist/render/tooltip/Tooltip.vue.d.ts +18 -0
- package/dist/render/tooltip/Tooltip.vue.js +4 -0
- package/dist/render/tooltip/Tooltip.vue2.js +58 -0
- package/dist/render/tooltip/index.d.ts +2 -0
- package/dist/render/youtube/YouTubeDefault.vue.d.ts +3 -0
- package/dist/render/youtube/YouTubeDefault.vue.js +79 -0
- package/dist/render/youtube/YouTubeDefault.vue2.js +4 -0
- package/dist/render/youtube/index.d.ts +5 -0
- package/dist/render/youtube/index.js +5 -0
- package/dist/useAudioPlayer.d.ts +22 -0
- package/dist/useCallout.d.ts +46 -0
- package/dist/useCodeBlock.d.ts +25 -0
- package/dist/useGallery.d.ts +44 -0
- package/dist/useMedia.d.ts +16 -0
- package/dist/useYouTube.d.ts +32 -0
- package/package.json +125 -0
- package/src/composables/index.ts +16 -0
- package/src/composables/useAudioPlayer.ts +84 -0
- package/src/composables/useCallout.ts +103 -0
- package/src/composables/useCodeBlock.ts +90 -0
- package/src/composables/useGallery.ts +143 -0
- package/src/composables/useMedia.ts +23 -0
- package/src/composables/useYouTube.ts +58 -0
- package/src/edit/AlertEdit.vue +9 -0
- package/src/edit/AudioPlayerEdit.vue +92 -0
- package/src/edit/BadgeEdit.vue +7 -0
- package/src/edit/ButtonEdit.vue +10 -0
- package/src/edit/CalloutEdit.vue +107 -0
- package/src/edit/CardEdit.vue +9 -0
- package/src/edit/CodeBlockEdit.vue +76 -0
- package/src/edit/GalleryEdit.vue +65 -0
- package/src/edit/IconEdit.vue +7 -0
- package/src/edit/TooltipEdit.vue +15 -0
- package/src/edit/YouTubeEdit.vue +33 -0
- package/src/edit/index.ts +32 -0
- package/src/index.ts +62 -0
- package/src/registry.ts +272 -0
- package/src/render/alert/Alert.vue +32 -0
- package/src/render/alert/index.ts +2 -0
- package/src/render/audioplayer/AudioPlayerDefault.vue +89 -0
- package/src/render/audioplayer/index.ts +8 -0
- package/src/render/badge/Badge.vue +25 -0
- package/src/render/badge/index.ts +2 -0
- package/src/render/button/Button.vue +41 -0
- package/src/render/button/index.ts +2 -0
- package/src/render/callout/CalloutDefault.vue +101 -0
- package/src/render/callout/CalloutMinimal.vue +31 -0
- package/src/render/callout/index.ts +9 -0
- package/src/render/card/Card.vue +15 -0
- package/src/render/card/index.ts +2 -0
- package/src/render/codeblock/CodeBlockDefault.vue +76 -0
- package/src/render/codeblock/index.ts +8 -0
- package/src/render/gallery/GalleryGrid.vue +162 -0
- package/src/render/gallery/GalleryLightbox.vue +162 -0
- package/src/render/gallery/index.ts +9 -0
- package/src/render/icon/Icon.vue +22 -0
- package/src/render/icon/index.ts +2 -0
- package/src/render/index.ts +76 -0
- package/src/render/tooltip/Tooltip.vue +35 -0
- package/src/render/tooltip/index.ts +2 -0
- package/src/render/youtube/YouTubeDefault.vue +72 -0
- package/src/render/youtube/index.ts +8 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var createAnatomy = (name, parts = []) => ({
|
|
2
|
+
parts: (...values) => {
|
|
3
|
+
if (isEmpty(parts)) {
|
|
4
|
+
return createAnatomy(name, values);
|
|
5
|
+
}
|
|
6
|
+
throw new Error("createAnatomy().parts(...) should only be called once. Did you mean to use .extendWith(...) ?");
|
|
7
|
+
},
|
|
8
|
+
extendWith: (...values) => createAnatomy(name, [...parts, ...values]),
|
|
9
|
+
omit: (...values) => createAnatomy(name, parts.filter((part) => !values.includes(part))),
|
|
10
|
+
rename: (newName) => createAnatomy(newName, parts),
|
|
11
|
+
keys: () => parts,
|
|
12
|
+
build: () => [...new Set(parts)].reduce(
|
|
13
|
+
(prev, part) => Object.assign(prev, {
|
|
14
|
+
[part]: {
|
|
15
|
+
selector: [
|
|
16
|
+
`&[data-scope="${toKebabCase(name)}"][data-part="${toKebabCase(part)}"]`,
|
|
17
|
+
`& [data-scope="${toKebabCase(name)}"][data-part="${toKebabCase(part)}"]`
|
|
18
|
+
].join(", "),
|
|
19
|
+
attrs: { "data-scope": toKebabCase(name), "data-part": toKebabCase(part) }
|
|
20
|
+
}
|
|
21
|
+
}),
|
|
22
|
+
{}
|
|
23
|
+
)
|
|
24
|
+
});
|
|
25
|
+
var toKebabCase = (value) => value.replace(/([A-Z])([A-Z])/g, "$1-$2").replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
26
|
+
var isEmpty = (v) => v.length === 0;
|
|
27
|
+
export {
|
|
28
|
+
createAnatomy
|
|
29
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ensureStateIndex } from "./state.js";
|
|
2
|
+
function createGuards() {
|
|
3
|
+
return {
|
|
4
|
+
and: (...guards) => {
|
|
5
|
+
return function andGuard(params) {
|
|
6
|
+
return guards.every((str) => params.guard(str));
|
|
7
|
+
};
|
|
8
|
+
},
|
|
9
|
+
or: (...guards) => {
|
|
10
|
+
return function orGuard(params) {
|
|
11
|
+
return guards.some((str) => params.guard(str));
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
not: (guard) => {
|
|
15
|
+
return function notGuard(params) {
|
|
16
|
+
return !params.guard(guard);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function createMachine(config) {
|
|
22
|
+
ensureStateIndex(config);
|
|
23
|
+
return config;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
createGuards,
|
|
27
|
+
createMachine
|
|
28
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { callAll } from "../../utils/dist/functions.js";
|
|
2
|
+
import { isString } from "../../utils/dist/guard.js";
|
|
3
|
+
var clsx = (...args) => args.map((str) => str?.trim?.()).filter(Boolean).join(" ");
|
|
4
|
+
var CSS_REGEX = /((?:--)?(?:\w+-?)+)\s*:\s*([^;]*)/g;
|
|
5
|
+
var serialize = (style) => {
|
|
6
|
+
const res = {};
|
|
7
|
+
let match;
|
|
8
|
+
while (match = CSS_REGEX.exec(style)) {
|
|
9
|
+
res[match[1]] = match[2];
|
|
10
|
+
}
|
|
11
|
+
return res;
|
|
12
|
+
};
|
|
13
|
+
var css = (a, b) => {
|
|
14
|
+
if (isString(a)) {
|
|
15
|
+
if (isString(b)) return `${a};${b}`;
|
|
16
|
+
a = serialize(a);
|
|
17
|
+
} else if (isString(b)) {
|
|
18
|
+
b = serialize(b);
|
|
19
|
+
}
|
|
20
|
+
return Object.assign({}, a ?? {}, b ?? {});
|
|
21
|
+
};
|
|
22
|
+
function mergeProps(...args) {
|
|
23
|
+
let result = {};
|
|
24
|
+
for (let props of args) {
|
|
25
|
+
if (!props) continue;
|
|
26
|
+
for (let key in result) {
|
|
27
|
+
if (key.startsWith("on") && typeof result[key] === "function" && typeof props[key] === "function") {
|
|
28
|
+
result[key] = callAll(props[key], result[key]);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (key === "className" || key === "class") {
|
|
32
|
+
result[key] = clsx(result[key], props[key]);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (key === "style") {
|
|
36
|
+
result[key] = css(result[key], props[key]);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
result[key] = props[key] !== void 0 ? props[key] : result[key];
|
|
40
|
+
}
|
|
41
|
+
for (let key in props) {
|
|
42
|
+
if (result[key] === void 0) {
|
|
43
|
+
result[key] = props[key];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const symbols = Object.getOwnPropertySymbols(props);
|
|
47
|
+
for (let symbol of symbols) {
|
|
48
|
+
result[symbol] = props[symbol];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
mergeProps
|
|
55
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isActiveElement, getActiveElement, getDocument } from "../../dom-query/dist/node.js";
|
|
2
|
+
function createScope(props) {
|
|
3
|
+
const getRootNode = () => props.getRootNode?.() ?? document;
|
|
4
|
+
const getDoc = () => getDocument(getRootNode());
|
|
5
|
+
const getWin = () => getDoc().defaultView ?? window;
|
|
6
|
+
const getActiveElementFn = () => getActiveElement(getRootNode());
|
|
7
|
+
const getById = (id) => getRootNode().getElementById(id);
|
|
8
|
+
return {
|
|
9
|
+
...props,
|
|
10
|
+
getRootNode,
|
|
11
|
+
getDoc,
|
|
12
|
+
getWin,
|
|
13
|
+
getActiveElement: getActiveElementFn,
|
|
14
|
+
isActiveElement,
|
|
15
|
+
getById
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
createScope
|
|
20
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { ensure, invariant } from "../../utils/dist/warning.js";
|
|
2
|
+
var STATE_DELIMITER = ".";
|
|
3
|
+
var ABSOLUTE_PREFIX = "#";
|
|
4
|
+
var stateIndexCache = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
var stateIdIndexCache = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
function joinStatePath(parts) {
|
|
7
|
+
return parts.join(STATE_DELIMITER);
|
|
8
|
+
}
|
|
9
|
+
function isAbsoluteStatePath(value) {
|
|
10
|
+
return value.includes(STATE_DELIMITER);
|
|
11
|
+
}
|
|
12
|
+
function isExplicitAbsoluteStatePath(value) {
|
|
13
|
+
return value.startsWith(ABSOLUTE_PREFIX);
|
|
14
|
+
}
|
|
15
|
+
function isChildTarget(value) {
|
|
16
|
+
return value.startsWith(STATE_DELIMITER);
|
|
17
|
+
}
|
|
18
|
+
function stripAbsolutePrefix(value) {
|
|
19
|
+
return isExplicitAbsoluteStatePath(value) ? value.slice(ABSOLUTE_PREFIX.length) : value;
|
|
20
|
+
}
|
|
21
|
+
function appendStatePath(base, segment) {
|
|
22
|
+
return base ? `${base}${STATE_DELIMITER}${segment}` : segment;
|
|
23
|
+
}
|
|
24
|
+
function buildStateIndex(machine) {
|
|
25
|
+
const index = /* @__PURE__ */ new Map();
|
|
26
|
+
const idIndex = /* @__PURE__ */ new Map();
|
|
27
|
+
const visit = (basePath, state) => {
|
|
28
|
+
index.set(basePath, state);
|
|
29
|
+
const stateId = state.id;
|
|
30
|
+
if (stateId) {
|
|
31
|
+
if (idIndex.has(stateId)) {
|
|
32
|
+
invariant(`[zag-js] Duplicate state id: "${stateId}"`);
|
|
33
|
+
}
|
|
34
|
+
idIndex.set(stateId, basePath);
|
|
35
|
+
}
|
|
36
|
+
const childStates = state.states;
|
|
37
|
+
if (!childStates) return;
|
|
38
|
+
ensure(state.initial, () => `[zag-js] Compound state "${basePath}" has child states but no "initial" property`);
|
|
39
|
+
if (!(state.initial in childStates)) {
|
|
40
|
+
invariant(
|
|
41
|
+
`[zag-js] Compound state "${basePath}" has initial "${String(state.initial)}" which is not a child state`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
for (const [childKey, childState] of Object.entries(childStates)) {
|
|
45
|
+
if (!childState) continue;
|
|
46
|
+
const childPath = appendStatePath(basePath, childKey);
|
|
47
|
+
visit(childPath, childState);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
for (const [topKey, topState] of Object.entries(machine.states)) {
|
|
51
|
+
if (!topState) continue;
|
|
52
|
+
visit(topKey, topState);
|
|
53
|
+
}
|
|
54
|
+
return { index, idIndex };
|
|
55
|
+
}
|
|
56
|
+
function ensureStateIndex(machine) {
|
|
57
|
+
const cached = stateIndexCache.get(machine);
|
|
58
|
+
if (cached) return cached;
|
|
59
|
+
const { index, idIndex } = buildStateIndex(machine);
|
|
60
|
+
stateIndexCache.set(machine, index);
|
|
61
|
+
stateIdIndexCache.set(machine, idIndex);
|
|
62
|
+
return index;
|
|
63
|
+
}
|
|
64
|
+
function getStatePathById(machine, stateId) {
|
|
65
|
+
ensureStateIndex(machine);
|
|
66
|
+
return stateIdIndexCache.get(machine)?.get(stateId);
|
|
67
|
+
}
|
|
68
|
+
function toSegments(value) {
|
|
69
|
+
if (!value) return [];
|
|
70
|
+
return String(value).split(STATE_DELIMITER).filter(Boolean);
|
|
71
|
+
}
|
|
72
|
+
function getStateChain(machine, state) {
|
|
73
|
+
if (!state) return [];
|
|
74
|
+
const stateIndex = ensureStateIndex(machine);
|
|
75
|
+
const segments = toSegments(state);
|
|
76
|
+
const chain = [];
|
|
77
|
+
const statePath = [];
|
|
78
|
+
for (const segment of segments) {
|
|
79
|
+
statePath.push(segment);
|
|
80
|
+
const path = joinStatePath(statePath);
|
|
81
|
+
const current = stateIndex.get(path);
|
|
82
|
+
if (!current) break;
|
|
83
|
+
chain.push({ path, state: current });
|
|
84
|
+
}
|
|
85
|
+
return chain;
|
|
86
|
+
}
|
|
87
|
+
function resolveAbsoluteStateValue(machine, value) {
|
|
88
|
+
const stateIndex = ensureStateIndex(machine);
|
|
89
|
+
const segments = toSegments(value);
|
|
90
|
+
if (!segments.length) return value;
|
|
91
|
+
const resolved = [];
|
|
92
|
+
for (const segment of segments) {
|
|
93
|
+
resolved.push(segment);
|
|
94
|
+
const path = joinStatePath(resolved);
|
|
95
|
+
if (!stateIndex.has(path)) return value;
|
|
96
|
+
}
|
|
97
|
+
let resolvedPath = joinStatePath(resolved);
|
|
98
|
+
let current = stateIndex.get(resolvedPath);
|
|
99
|
+
while (current?.initial) {
|
|
100
|
+
const nextPath = `${resolvedPath}${STATE_DELIMITER}${current.initial}`;
|
|
101
|
+
const nextState = stateIndex.get(nextPath);
|
|
102
|
+
if (!nextState) break;
|
|
103
|
+
resolvedPath = nextPath;
|
|
104
|
+
current = nextState;
|
|
105
|
+
}
|
|
106
|
+
return resolvedPath;
|
|
107
|
+
}
|
|
108
|
+
function hasStatePath(machine, value) {
|
|
109
|
+
const stateIndex = ensureStateIndex(machine);
|
|
110
|
+
return stateIndex.has(value);
|
|
111
|
+
}
|
|
112
|
+
function resolveStateValue(machine, value, source) {
|
|
113
|
+
const stateValue = String(value);
|
|
114
|
+
if (isExplicitAbsoluteStatePath(stateValue)) {
|
|
115
|
+
const stateId = stripAbsolutePrefix(stateValue);
|
|
116
|
+
const statePath = getStatePathById(machine, stateId);
|
|
117
|
+
ensure(statePath, () => `[zag-js] Unknown state id: "${stateId}"`);
|
|
118
|
+
return resolveAbsoluteStateValue(machine, statePath);
|
|
119
|
+
}
|
|
120
|
+
if (isChildTarget(stateValue) && source) {
|
|
121
|
+
const childPath = appendStatePath(source, stateValue.slice(1));
|
|
122
|
+
return resolveAbsoluteStateValue(machine, childPath);
|
|
123
|
+
}
|
|
124
|
+
if (!isAbsoluteStatePath(stateValue) && source) {
|
|
125
|
+
const sourceSegments = toSegments(source);
|
|
126
|
+
for (let index = sourceSegments.length - 1; index >= 1; index--) {
|
|
127
|
+
const base = sourceSegments.slice(0, index).join(STATE_DELIMITER);
|
|
128
|
+
const candidate = appendStatePath(base, stateValue);
|
|
129
|
+
if (hasStatePath(machine, candidate)) return resolveAbsoluteStateValue(machine, candidate);
|
|
130
|
+
}
|
|
131
|
+
if (hasStatePath(machine, stateValue)) return resolveAbsoluteStateValue(machine, stateValue);
|
|
132
|
+
}
|
|
133
|
+
return resolveAbsoluteStateValue(machine, stateValue);
|
|
134
|
+
}
|
|
135
|
+
function findTransition(machine, state, eventType) {
|
|
136
|
+
const chain = getStateChain(machine, state);
|
|
137
|
+
for (let index = chain.length - 1; index >= 0; index--) {
|
|
138
|
+
const transitionMap = chain[index]?.state.on;
|
|
139
|
+
const transition = transitionMap?.[eventType];
|
|
140
|
+
if (transition) return { transitions: transition, source: chain[index]?.path };
|
|
141
|
+
}
|
|
142
|
+
const rootTransitionMap = machine.on;
|
|
143
|
+
return { transitions: rootTransitionMap?.[eventType], source: void 0 };
|
|
144
|
+
}
|
|
145
|
+
function getExitEnterStates(machine, prevState, nextState, reenter) {
|
|
146
|
+
const prevChain = prevState ? getStateChain(machine, prevState) : [];
|
|
147
|
+
const nextChain = getStateChain(machine, nextState);
|
|
148
|
+
let commonIndex = 0;
|
|
149
|
+
while (commonIndex < prevChain.length && commonIndex < nextChain.length && prevChain[commonIndex]?.path === nextChain[commonIndex]?.path) {
|
|
150
|
+
commonIndex += 1;
|
|
151
|
+
}
|
|
152
|
+
let exiting = prevChain.slice(commonIndex).reverse();
|
|
153
|
+
let entering = nextChain.slice(commonIndex);
|
|
154
|
+
const sameLeaf = prevChain.at(-1)?.path === nextChain.at(-1)?.path;
|
|
155
|
+
if (reenter && sameLeaf) {
|
|
156
|
+
exiting = prevChain.slice().reverse();
|
|
157
|
+
entering = nextChain;
|
|
158
|
+
}
|
|
159
|
+
return { exiting, entering };
|
|
160
|
+
}
|
|
161
|
+
function matchesState(current, value) {
|
|
162
|
+
if (!current) return false;
|
|
163
|
+
return current === value || current.startsWith(`${value}${STATE_DELIMITER}`);
|
|
164
|
+
}
|
|
165
|
+
function hasTag(machine, state, tag) {
|
|
166
|
+
return getStateChain(machine, state).some((item) => item.state.tags?.includes(tag));
|
|
167
|
+
}
|
|
168
|
+
export {
|
|
169
|
+
ensureStateIndex,
|
|
170
|
+
findTransition,
|
|
171
|
+
getExitEnterStates,
|
|
172
|
+
getStateChain,
|
|
173
|
+
hasTag,
|
|
174
|
+
matchesState,
|
|
175
|
+
resolveStateValue
|
|
176
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var MachineStatus = /* @__PURE__ */ ((MachineStatus2) => {
|
|
2
|
+
MachineStatus2["NotStarted"] = "Not Started";
|
|
3
|
+
MachineStatus2["Started"] = "Started";
|
|
4
|
+
MachineStatus2["Stopped"] = "Stopped";
|
|
5
|
+
return MachineStatus2;
|
|
6
|
+
})(MachineStatus || {});
|
|
7
|
+
var INIT_STATE = "__init__";
|
|
8
|
+
export {
|
|
9
|
+
INIT_STATE,
|
|
10
|
+
MachineStatus
|
|
11
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
export {
|
|
5
|
+
__publicField
|
|
6
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getWindow } from "./node.js";
|
|
2
|
+
var styleCache = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function getComputedStyle(el) {
|
|
4
|
+
if (!styleCache.has(el)) {
|
|
5
|
+
styleCache.set(el, getWindow(el).getComputedStyle(el));
|
|
6
|
+
}
|
|
7
|
+
return styleCache.get(el);
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
getComputedStyle
|
|
11
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isAndroid } from "./platform.js";
|
|
2
|
+
function getComposedPath(event) {
|
|
3
|
+
return event.composedPath?.() ?? event.nativeEvent?.composedPath?.();
|
|
4
|
+
}
|
|
5
|
+
function getEventTarget(event) {
|
|
6
|
+
const composedPath = getComposedPath(event);
|
|
7
|
+
return composedPath?.[0] ?? event.target;
|
|
8
|
+
}
|
|
9
|
+
function isComposingEvent(event) {
|
|
10
|
+
return getNativeEvent(event).isComposing || event.keyCode === 229;
|
|
11
|
+
}
|
|
12
|
+
function isVirtualClick(e) {
|
|
13
|
+
if (e.pointerType === "" && e.isTrusted) return true;
|
|
14
|
+
if (isAndroid() && e.pointerType) {
|
|
15
|
+
return e.type === "click" && e.buttons === 1;
|
|
16
|
+
}
|
|
17
|
+
return e.detail === 0 && !e.pointerType;
|
|
18
|
+
}
|
|
19
|
+
var isLeftClick = (e) => e.button === 0;
|
|
20
|
+
function getNativeEvent(event) {
|
|
21
|
+
return event.nativeEvent ?? event;
|
|
22
|
+
}
|
|
23
|
+
var addDomEvent = (target, eventName, handler, options) => {
|
|
24
|
+
const node = typeof target === "function" ? target() : target;
|
|
25
|
+
node?.addEventListener(eventName, handler, options);
|
|
26
|
+
return () => {
|
|
27
|
+
node?.removeEventListener(eventName, handler, options);
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
addDomEvent,
|
|
32
|
+
getEventTarget,
|
|
33
|
+
getNativeEvent,
|
|
34
|
+
isComposingEvent,
|
|
35
|
+
isLeftClick,
|
|
36
|
+
isVirtualClick
|
|
37
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { isObject } from "./shared.js";
|
|
2
|
+
var ELEMENT_NODE = 1;
|
|
3
|
+
var DOCUMENT_NODE = 9;
|
|
4
|
+
var DOCUMENT_FRAGMENT_NODE = 11;
|
|
5
|
+
var isHTMLElement = (el) => isObject(el) && el.nodeType === ELEMENT_NODE && typeof el.nodeName === "string";
|
|
6
|
+
var isDocument = (el) => isObject(el) && el.nodeType === DOCUMENT_NODE;
|
|
7
|
+
var isWindow = (el) => isObject(el) && el === el.window;
|
|
8
|
+
var getNodeName = (node) => {
|
|
9
|
+
if (isHTMLElement(node)) return node.localName || "";
|
|
10
|
+
return "#document";
|
|
11
|
+
};
|
|
12
|
+
function isRootElement(node) {
|
|
13
|
+
return ["html", "body", "#document"].includes(getNodeName(node));
|
|
14
|
+
}
|
|
15
|
+
var isNode = (el) => isObject(el) && el.nodeType !== void 0;
|
|
16
|
+
var isShadowRoot = (el) => isNode(el) && el.nodeType === DOCUMENT_FRAGMENT_NODE && "host" in el;
|
|
17
|
+
function isActiveElement(element) {
|
|
18
|
+
if (!element) return false;
|
|
19
|
+
const rootNode = element.getRootNode();
|
|
20
|
+
return getActiveElement(rootNode) === element;
|
|
21
|
+
}
|
|
22
|
+
function getDocument(el) {
|
|
23
|
+
if (isDocument(el)) return el;
|
|
24
|
+
if (isWindow(el)) return el.document;
|
|
25
|
+
return el?.ownerDocument ?? document;
|
|
26
|
+
}
|
|
27
|
+
function getDocumentElement(el) {
|
|
28
|
+
return getDocument(el).documentElement;
|
|
29
|
+
}
|
|
30
|
+
function getWindow(el) {
|
|
31
|
+
if (isShadowRoot(el)) return getWindow(el.host);
|
|
32
|
+
if (isDocument(el)) return el.defaultView ?? window;
|
|
33
|
+
if (isHTMLElement(el)) return el.ownerDocument?.defaultView ?? window;
|
|
34
|
+
return window;
|
|
35
|
+
}
|
|
36
|
+
function getActiveElement(rootNode) {
|
|
37
|
+
let activeElement = rootNode.activeElement;
|
|
38
|
+
while (activeElement?.shadowRoot) {
|
|
39
|
+
const el = activeElement.shadowRoot.activeElement;
|
|
40
|
+
if (!el || el === activeElement) break;
|
|
41
|
+
else activeElement = el;
|
|
42
|
+
}
|
|
43
|
+
return activeElement;
|
|
44
|
+
}
|
|
45
|
+
function getParentNode(node) {
|
|
46
|
+
if (getNodeName(node) === "html") return node;
|
|
47
|
+
const result = node.assignedSlot || node.parentNode || isShadowRoot(node) && node.host || getDocumentElement(node);
|
|
48
|
+
return isShadowRoot(result) ? result.host : result;
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
getActiveElement,
|
|
52
|
+
getDocument,
|
|
53
|
+
getDocumentElement,
|
|
54
|
+
getNodeName,
|
|
55
|
+
getParentNode,
|
|
56
|
+
getWindow,
|
|
57
|
+
isActiveElement,
|
|
58
|
+
isDocument,
|
|
59
|
+
isHTMLElement,
|
|
60
|
+
isNode,
|
|
61
|
+
isRootElement,
|
|
62
|
+
isShadowRoot,
|
|
63
|
+
isWindow
|
|
64
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getWindow, getParentNode, isRootElement, getDocument, isHTMLElement } from "./node.js";
|
|
2
|
+
function getNearestOverflowAncestor(el) {
|
|
3
|
+
const parentNode = getParentNode(el);
|
|
4
|
+
if (isRootElement(parentNode)) return getDocument(parentNode).body;
|
|
5
|
+
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) return parentNode;
|
|
6
|
+
return getNearestOverflowAncestor(parentNode);
|
|
7
|
+
}
|
|
8
|
+
function getOverflowAncestors(el, list = []) {
|
|
9
|
+
const scrollableAncestor = getNearestOverflowAncestor(el);
|
|
10
|
+
const isBody = scrollableAncestor === el.ownerDocument.body;
|
|
11
|
+
const win = getWindow(scrollableAncestor);
|
|
12
|
+
if (isBody) {
|
|
13
|
+
return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : []);
|
|
14
|
+
}
|
|
15
|
+
return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, []));
|
|
16
|
+
}
|
|
17
|
+
var OVERFLOW_RE = /auto|scroll|overlay|hidden|clip/;
|
|
18
|
+
var nonOverflowValues = /* @__PURE__ */ new Set(["inline", "contents"]);
|
|
19
|
+
function isOverflowElement(el) {
|
|
20
|
+
const win = getWindow(el);
|
|
21
|
+
const { overflow, overflowX, overflowY, display } = win.getComputedStyle(el);
|
|
22
|
+
return OVERFLOW_RE.test(overflow + overflowY + overflowX) && !nonOverflowValues.has(display);
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
getNearestOverflowAncestor,
|
|
26
|
+
getOverflowAncestors,
|
|
27
|
+
isOverflowElement
|
|
28
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var isDom = () => typeof document !== "undefined";
|
|
2
|
+
function getPlatform() {
|
|
3
|
+
const agent = navigator.userAgentData;
|
|
4
|
+
return agent?.platform ?? navigator.platform;
|
|
5
|
+
}
|
|
6
|
+
function getUserAgent() {
|
|
7
|
+
const ua2 = navigator.userAgentData;
|
|
8
|
+
if (ua2 && Array.isArray(ua2.brands)) {
|
|
9
|
+
return ua2.brands.map(({ brand, version }) => `${brand}/${version}`).join(" ");
|
|
10
|
+
}
|
|
11
|
+
return navigator.userAgent;
|
|
12
|
+
}
|
|
13
|
+
var pt = (v) => isDom() && v.test(getPlatform());
|
|
14
|
+
var ua = (v) => isDom() && v.test(getUserAgent());
|
|
15
|
+
var isMac = () => pt(/^Mac/i);
|
|
16
|
+
var isAndroid = () => ua(/Android/i);
|
|
17
|
+
export {
|
|
18
|
+
getPlatform,
|
|
19
|
+
getUserAgent,
|
|
20
|
+
isAndroid,
|
|
21
|
+
isDom,
|
|
22
|
+
isMac
|
|
23
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { __publicField } from "./chunk-QZ7TP4HQ.js";
|
|
2
|
+
var AnimationFrame = class _AnimationFrame {
|
|
3
|
+
constructor() {
|
|
4
|
+
__publicField(this, "id", null);
|
|
5
|
+
__publicField(this, "fn_cleanup");
|
|
6
|
+
__publicField(this, "cleanup", () => {
|
|
7
|
+
this.cancel();
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
static create() {
|
|
11
|
+
return new _AnimationFrame();
|
|
12
|
+
}
|
|
13
|
+
request(fn) {
|
|
14
|
+
this.cancel();
|
|
15
|
+
this.id = globalThis.requestAnimationFrame(() => {
|
|
16
|
+
this.id = null;
|
|
17
|
+
this.fn_cleanup = fn?.();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
cancel() {
|
|
21
|
+
if (this.id !== null) {
|
|
22
|
+
globalThis.cancelAnimationFrame(this.id);
|
|
23
|
+
this.id = null;
|
|
24
|
+
}
|
|
25
|
+
this.fn_cleanup?.();
|
|
26
|
+
this.fn_cleanup = void 0;
|
|
27
|
+
}
|
|
28
|
+
isActive() {
|
|
29
|
+
return this.id !== null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
function raf(fn) {
|
|
33
|
+
const frame = AnimationFrame.create();
|
|
34
|
+
frame.request(fn);
|
|
35
|
+
return frame.cleanup;
|
|
36
|
+
}
|
|
37
|
+
function nextTick(fn) {
|
|
38
|
+
const set = /* @__PURE__ */ new Set();
|
|
39
|
+
function raf2(fn2) {
|
|
40
|
+
const id = globalThis.requestAnimationFrame(fn2);
|
|
41
|
+
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
42
|
+
}
|
|
43
|
+
raf2(() => raf2(fn));
|
|
44
|
+
return function cleanup() {
|
|
45
|
+
set.forEach((fn2) => fn2());
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
AnimationFrame,
|
|
50
|
+
nextTick,
|
|
51
|
+
raf
|
|
52
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { noop } from "./shared.js";
|
|
2
|
+
function setStyle(el, style) {
|
|
3
|
+
if (!el) return noop;
|
|
4
|
+
const prev = Object.keys(style).reduce((acc, key) => {
|
|
5
|
+
acc[key] = el.style.getPropertyValue(key);
|
|
6
|
+
return acc;
|
|
7
|
+
}, {});
|
|
8
|
+
if (isEqual(prev, style)) return noop;
|
|
9
|
+
Object.assign(el.style, style);
|
|
10
|
+
return () => {
|
|
11
|
+
Object.assign(el.style, prev);
|
|
12
|
+
if (el.style.length === 0) {
|
|
13
|
+
el.removeAttribute("style");
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function isEqual(a, b) {
|
|
18
|
+
return Object.keys(a).every((key) => a[key] === b[key]);
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
setStyle
|
|
22
|
+
};
|