@v-c/image 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/Image.d.ts +2 -0
  2. package/dist/{Image.js → image/src/Image.js} +35 -5
  3. package/dist/{Preview → image/src/Preview}/Footer.js +6 -4
  4. package/dist/{Preview → image/src/Preview}/PrevNext.js +11 -10
  5. package/dist/{Preview → image/src/Preview}/index.js +20 -10
  6. package/dist/{PreviewGroup.js → image/src/PreviewGroup.js} +1 -1
  7. package/dist/{common.js → image/src/common.js} +2 -1
  8. package/dist/{hooks → image/src/hooks}/useImageTransform.js +2 -2
  9. package/dist/{hooks → image/src/hooks}/useMouseEvent.js +3 -4
  10. package/dist/{hooks → image/src/hooks}/useTouchEvent.js +1 -1
  11. package/dist/interface.d.ts +1 -1
  12. package/dist/util/dist/Dom/focus.js +80 -0
  13. package/dist/util/dist/Dom/isVisible.js +16 -0
  14. package/dist/util/dist/props-util/index.js +2 -15
  15. package/package.json +2 -2
  16. package/dist/portal/dist/Context.js +0 -11
  17. package/dist/portal/dist/Portal.js +0 -101
  18. package/dist/portal/dist/index.js +0 -3
  19. package/dist/portal/dist/useDom.js +0 -52
  20. package/dist/portal/dist/useEscKeyDown.js +0 -54
  21. package/dist/portal/dist/useScrollLocker.js +0 -28
  22. package/dist/portal/dist/util.js +0 -4
  23. package/dist/util/dist/Dom/contains.js +0 -11
  24. package/dist/util/dist/Dom/dynamicCSS.js +0 -79
  25. package/dist/util/dist/Dom/findDOMNode.js +0 -20
  26. package/dist/util/dist/RenderComponent.js +0 -29
  27. package/dist/util/dist/classnames.js +0 -35
  28. package/dist/util/dist/getScrollBarSize.js +0 -53
  29. package/dist/util/dist/hooks/useControlledState.js +0 -1
  30. package/dist/util/dist/hooks/useId.js +0 -5
  31. package/dist/util/dist/index.js +0 -8
  32. /package/dist/{Preview → image/src/Preview}/CloseBtn.js +0 -0
  33. /package/dist/{context.js → image/src/context.js} +0 -0
  34. /package/dist/{getFixScaleEleTransPosition.js → image/src/getFixScaleEleTransPosition.js} +0 -0
  35. /package/dist/{hooks → image/src/hooks}/usePreviewItems.js +0 -0
  36. /package/dist/{hooks → image/src/hooks}/useRegisterImage.js +0 -0
  37. /package/dist/{hooks → image/src/hooks}/useStatus.js +0 -0
  38. /package/dist/{index.js → image/src/index.js} +0 -0
  39. /package/dist/{interface.js → image/src/interface.js} +0 -0
  40. /package/dist/{previewConfig.js → image/src/previewConfig.js} +0 -0
  41. /package/dist/{util.js → image/src/util.js} +0 -0
package/dist/Image.d.ts CHANGED
@@ -39,8 +39,10 @@ export interface ImageProps extends Partial<Omit<ImageElementProps, 'src'>> {
39
39
  preview?: boolean | PreviewConfig;
40
40
  onClick?: (e: MouseEvent) => void;
41
41
  onError?: (e: Event) => void;
42
+ onKeydown?: (e: KeyboardEvent) => void;
42
43
  width?: string | number;
43
44
  height?: string | number;
45
+ fetchPriority?: HTMLImageElement['fetchPriority'];
44
46
  }
45
47
  declare const Image: import('vue').DefineSetupFnComponent<ImageProps, {}, {}, ImageProps & {}, import('vue').PublicProps>;
46
48
  export default Image;
@@ -1,14 +1,13 @@
1
- import { getAttrStyleAndClass, getStylePxValue } from "./util/dist/props-util/index.js";
2
- import { clsx } from "./util/dist/classnames.js";
3
- import { useMergedState } from "./util/dist/hooks/useMergedState.js";
4
- import "./util/dist/index.js";
5
- import { pickAttrs } from "./util/dist/pickAttrs.js";
6
1
  import { COMMON_PROPS } from "./common.js";
7
2
  import { usePreviewGroupContext } from "./context.js";
3
+ import { useMergedState } from "../../util/dist/hooks/useMergedState.js";
4
+ import { pickAttrs } from "../../util/dist/pickAttrs.js";
5
+ import { getAttrStyleAndClass, getStylePxValue } from "../../util/dist/props-util/index.js";
8
6
  import useRegisterImage from "./hooks/useRegisterImage.js";
9
7
  import useStatus from "./hooks/useStatus.js";
10
8
  import Preview_default from "./Preview/index.js";
11
9
  import { Fragment, computed, createVNode, defineComponent, mergeDefaults, mergeProps, shallowRef } from "vue";
10
+ import { clsx } from "@v-c/util";
12
11
  var Image_default = /* @__PURE__ */ defineComponent((props, { attrs, slots }) => {
13
12
  const groupContext = usePreviewGroupContext();
14
13
  const prefixCls = computed(() => props.prefixCls ?? "vc-image");
@@ -70,6 +69,24 @@ var Image_default = /* @__PURE__ */ defineComponent((props, { attrs, slots }) =>
70
69
  const onImgError = (e) => {
71
70
  props.onError?.(e);
72
71
  };
72
+ const onPreviewKeyDown = (event) => {
73
+ props.onKeydown?.(event);
74
+ if (!canPreview) return;
75
+ if (event.key === "Enter" || event.key === " ") {
76
+ event.preventDefault();
77
+ const rect = event.target.getBoundingClientRect();
78
+ const left = rect.x + rect.width / 2;
79
+ const top = rect.y + rect.height / 2;
80
+ if (groupContext) groupContext.onPreview(imageId, src.value || "", left, top);
81
+ else {
82
+ mousePosition.value = {
83
+ x: left,
84
+ y: top
85
+ };
86
+ triggerPreviewOpen(true);
87
+ }
88
+ }
89
+ };
73
90
  return () => {
74
91
  const { width, height } = props;
75
92
  const { className, style: attrStyle, restAttrs } = getAttrStyleAndClass(attrs);
@@ -97,6 +114,10 @@ var Image_default = /* @__PURE__ */ defineComponent((props, { attrs, slots }) =>
97
114
  return createVNode(Fragment, null, [createVNode("div", mergeProps(pickAttrs(restAttrs, false), {
98
115
  "class": rootCls,
99
116
  "onClick": canPreview.value ? onPreview : onInternalClick,
117
+ "role": canPreview ? "button" : restAttrs.role,
118
+ "tabindex": canPreview && restAttrs.tabIndex == null ? 0 : restAttrs.tabIndex,
119
+ "aria-label": canPreview ? restAttrs["aria-label"] ?? restAttrs.alt : restAttrs["aria-label"],
120
+ "onKeydown": onPreviewKeyDown,
100
121
  "style": rootStyle
101
122
  }), [
102
123
  createVNode("img", mergeProps(imgCommonProps.value, {
@@ -204,6 +225,11 @@ var Image_default = /* @__PURE__ */ defineComponent((props, { attrs, slots }) =>
204
225
  required: false,
205
226
  default: void 0
206
227
  },
228
+ onKeydown: {
229
+ type: Function,
230
+ required: false,
231
+ default: void 0
232
+ },
207
233
  width: {
208
234
  type: [String, Number],
209
235
  required: false,
@@ -213,6 +239,10 @@ var Image_default = /* @__PURE__ */ defineComponent((props, { attrs, slots }) =>
213
239
  type: [String, Number],
214
240
  required: false,
215
241
  default: void 0
242
+ },
243
+ fetchPriority: {
244
+ required: false,
245
+ default: void 0
216
246
  }
217
247
  }, {
218
248
  prefixCls: "vc-image",
@@ -1,15 +1,17 @@
1
- import { clsx } from "../util/dist/classnames.js";
2
- import "../util/dist/index.js";
3
1
  import { createVNode, defineComponent } from "vue";
2
+ import { clsx } from "@v-c/util";
4
3
  var Footer_default = /* @__PURE__ */ defineComponent((props) => {
5
4
  const renderOperation = ({ type, disabled, onClick, icon }) => {
6
5
  const actionCls = `${props.prefixCls}-actions-action`;
7
- return createVNode("div", {
6
+ return createVNode("button", {
7
+ "type": "button",
8
8
  "key": type,
9
9
  "class": clsx(actionCls, `${actionCls}-${type}`, { [`${actionCls}-disabled`]: !!disabled }),
10
10
  "onClick": () => {
11
11
  if (!disabled) onClick();
12
- }
12
+ },
13
+ "disabled": !!disabled,
14
+ "aria-label": type
13
15
  }, [icon]);
14
16
  };
15
17
  return () => {
@@ -1,23 +1,24 @@
1
- import { clsx } from "../util/dist/classnames.js";
2
- import "../util/dist/index.js";
3
1
  import { Fragment, createVNode, defineComponent } from "vue";
2
+ import { clsx } from "@v-c/util";
4
3
  var PrevNext_default = /* @__PURE__ */ defineComponent((props) => {
5
4
  return () => {
6
5
  const { prefixCls, onActive, current, count, icons } = props;
7
6
  const switchCls = `${prefixCls}-switch`;
8
7
  const prevIcon = icons.prev ?? icons.left;
9
8
  const nextIcon = icons.next ?? icons.right;
10
- const isPrevDisabled = current === 0;
11
- const isNextDisabled = current === count - 1;
12
- return createVNode(Fragment, null, [createVNode("div", {
13
- "class": clsx(switchCls, `${switchCls}-prev`, { [`${switchCls}-disabled`]: isPrevDisabled }),
9
+ const prevDisabled = current === 0;
10
+ const nextDisabled = current === count - 1;
11
+ return createVNode(Fragment, null, [createVNode("button", {
12
+ "type": "button",
13
+ "class": clsx(switchCls, `${switchCls}-prev`, { [`${switchCls}-disabled`]: prevDisabled }),
14
14
  "onClick": () => {
15
- if (!isPrevDisabled) onActive(-1);
15
+ if (!prevDisabled) onActive(-1);
16
16
  }
17
- }, [prevIcon]), createVNode("div", {
18
- "class": clsx(switchCls, `${switchCls}-next`, { [`${switchCls}-disabled`]: isNextDisabled }),
17
+ }, [prevIcon]), createVNode("button", {
18
+ "type": "button",
19
+ "class": clsx(switchCls, `${switchCls}-next`, { [`${switchCls}-disabled`]: nextDisabled }),
19
20
  "onClick": () => {
20
- if (!isNextDisabled) onActive(1);
21
+ if (!nextDisabled) onActive(1);
21
22
  }
22
23
  }, [nextIcon])]);
23
24
  };
@@ -1,11 +1,9 @@
1
- import { KeyCodeStr } from "../util/dist/KeyCode.js";
2
- import { clsx } from "../util/dist/classnames.js";
3
- import "../util/dist/index.js";
4
1
  import { usePreviewGroupContext } from "../context.js";
5
2
  import useStatus from "../hooks/useStatus.js";
6
- import { canUseDom } from "../util/dist/Dom/canUseDom.js";
7
- import { src_default } from "../portal/dist/index.js";
8
- import { getTransitionProps } from "../util/dist/utils/transition.js";
3
+ import { canUseDom } from "../../../util/dist/Dom/canUseDom.js";
4
+ import { useLockFocus } from "../../../util/dist/Dom/focus.js";
5
+ import { KeyCodeStr } from "../../../util/dist/KeyCode.js";
6
+ import { getTransitionProps } from "../../../util/dist/utils/transition.js";
9
7
  import useImageTransform from "../hooks/useImageTransform.js";
10
8
  import { BASE_SCALE_RATIO } from "../previewConfig.js";
11
9
  import useMouseEvent from "../hooks/useMouseEvent.js";
@@ -14,8 +12,11 @@ import CloseBtn_default from "./CloseBtn.js";
14
12
  import Footer_default from "./Footer.js";
15
13
  import PrevNext_default from "./PrevNext.js";
16
14
  import { Transition, computed, createVNode, defineComponent, mergeDefaults, mergeProps, nextTick, shallowRef, watch, watchEffect } from "vue";
15
+ import { clsx } from "@v-c/util";
16
+ import Portal from "@v-c/portal";
17
17
  var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots }) => {
18
18
  const imgEl = shallowRef();
19
+ const wrapperRef = shallowRef(null);
19
20
  const groupContext = usePreviewGroupContext();
20
21
  const showLeftOrRightSwitches = computed(() => !!groupContext && (props.count ?? 1) > 1);
21
22
  const showOperationsProgress = computed(() => !!groupContext && (props.count ?? 1) >= 1);
@@ -113,8 +114,9 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
113
114
  src: computed(() => props.src),
114
115
  fallback: computed(() => props.fallback)
115
116
  });
117
+ useLockFocus(portalRender, () => wrapperRef.value);
116
118
  return () => {
117
- const { prefixCls, rootClassName, src, alt, imageInfo, open, closeIcon, getContainer, current = 0, count = 1, countRender, motionName = "fade", imageRender, imgCommonProps, actionsRender = slots?.actionsRender, classNames = {}, styles = {}, mousePosition, zIndex, icons = {} } = props;
119
+ const { prefixCls, rootClassName, src, alt, imageInfo, open, closeIcon, getContainer, current = 0, count = 1, countRender, motionName = "fade", imageRender, imgCommonProps, actionsRender = slots?.actionsRender, classNames = {}, styles = {}, mousePosition, zIndex, icons = {}, movable = true } = props;
118
120
  const bodyStyle = { ...styles.body ?? {} };
119
121
  if (mousePosition) bodyStyle.transformOrigin = `${mousePosition.x}px ${mousePosition.y}px`;
120
122
  const image = {
@@ -150,9 +152,12 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
150
152
  ...attrs.style
151
153
  };
152
154
  if (zIndex) mergedRootStyle.zIndex = zIndex;
153
- const mergedRootCls = clsx(prefixCls, rootClassName, classNames.root, { [`${prefixCls}-moving`]: isMoving.value });
155
+ const mergedRootCls = clsx(prefixCls, rootClassName, classNames.root, {
156
+ [`${prefixCls}-movable`]: movable,
157
+ [`${prefixCls}-moving`]: isMoving.value
158
+ });
154
159
  const transitionProps = getTransitionProps(motionName);
155
- return createVNode(src_default, {
160
+ return createVNode(Portal, {
156
161
  "open": open || animatedVisible.value || portalRender.value,
157
162
  "getContainer": getContainer,
158
163
  "autoLock": open || animatedVisible.value
@@ -162,8 +167,13 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
162
167
  }), { default: () => {
163
168
  if (!(portalRender.value && open)) return null;
164
169
  return createVNode("div", {
170
+ "ref": wrapperRef,
165
171
  "class": mergedRootCls,
166
- "style": mergedRootStyle
172
+ "style": mergedRootStyle,
173
+ "role": "dialog",
174
+ "aria-modal": "true",
175
+ "aria-label": alt,
176
+ "tabindex": -1
167
177
  }, [
168
178
  createVNode("div", {
169
179
  "class": clsx(`${prefixCls}-mask`, classNames.mask),
@@ -1,5 +1,5 @@
1
- import { useMergedState } from "./util/dist/hooks/useMergedState.js";
2
1
  import { usePreviewGroupProvider } from "./context.js";
2
+ import { useMergedState } from "../../util/dist/hooks/useMergedState.js";
3
3
  import Preview_default from "./Preview/index.js";
4
4
  import usePreviewItems from "./hooks/usePreviewItems.js";
5
5
  import { Fragment, computed, createVNode, defineComponent, mergeDefaults, mergeProps, shallowRef, toRef, watch } from "vue";
@@ -7,6 +7,7 @@ const COMMON_PROPS = [
7
7
  "sizes",
8
8
  "srcset",
9
9
  "useMap",
10
- "alt"
10
+ "alt",
11
+ "fetchPriority"
11
12
  ];
12
13
  export { COMMON_PROPS };
@@ -1,6 +1,6 @@
1
- import { raf_default } from "../util/dist/raf.js";
2
1
  import { getClientSize } from "../util.js";
3
- import { isEqual_default } from "../util/dist/isEqual.js";
2
+ import { isEqual_default } from "../../../util/dist/isEqual.js";
3
+ import { raf_default } from "../../../util/dist/raf.js";
4
4
  import { ref, shallowRef } from "vue";
5
5
  var initialTransform = {
6
6
  x: 0,
@@ -1,9 +1,8 @@
1
- import { warning_default } from "../util/dist/warning.js";
2
- import "../util/dist/index.js";
3
- import { canUseDom } from "../util/dist/Dom/canUseDom.js";
4
1
  import getFixScaleEleTransPosition from "../getFixScaleEleTransPosition.js";
2
+ import { canUseDom } from "../../../util/dist/Dom/canUseDom.js";
5
3
  import { BASE_SCALE_RATIO, WHEEL_MAX_SCALE_RATIO } from "../previewConfig.js";
6
4
  import { shallowRef, watch } from "vue";
5
+ import { warning } from "@v-c/util";
7
6
  function useMouseEvent(imgRef, movable, open, scaleStep, transform, updateTransform, dispatchZoomChange) {
8
7
  const isMoving = shallowRef(false);
9
8
  const startPositionInfo = shallowRef({
@@ -69,7 +68,7 @@ function useMouseEvent(imgRef, movable, open, scaleStep, transform, updateTransf
69
68
  window?.top?.addEventListener("mousemove", onMouseMove, false);
70
69
  }
71
70
  } catch (e) {
72
- warning_default(false, `[vc-image] ${e}`);
71
+ warning(false, `[vc-image] ${e}`);
73
72
  }
74
73
  onCleanup(() => {
75
74
  window.removeEventListener("mouseup", onMouseUp);
@@ -1,5 +1,5 @@
1
- import { canUseDom } from "../util/dist/Dom/canUseDom.js";
2
1
  import getFixScaleEleTransPosition from "../getFixScaleEleTransPosition.js";
2
+ import { canUseDom } from "../../../util/dist/Dom/canUseDom.js";
3
3
  import { shallowRef, watchEffect } from "vue";
4
4
  function getDistance(a, b) {
5
5
  const x = a.x - b.x;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Used for PreviewGroup passed image data
3
3
  */
4
- export type ImageElementProps = Pick<HTMLImageElement, 'src' | 'crossOrigin' | 'decoding' | 'draggable' | 'loading' | 'referrerPolicy' | 'sizes' | 'srcset' | 'useMap' | 'alt'>;
4
+ export type ImageElementProps = Pick<HTMLImageElement, 'src' | 'crossOrigin' | 'decoding' | 'draggable' | 'loading' | 'referrerPolicy' | 'sizes' | 'srcset' | 'useMap' | 'alt' | 'fetchPriority'>;
5
5
  export interface PreviewImageElementProps {
6
6
  data: ImageElementProps;
7
7
  canPreview: boolean;
@@ -0,0 +1,80 @@
1
+ import { isVisible_default } from "./isVisible.js";
2
+ import { watch } from "vue";
3
+ function focusable(node, includePositive = false) {
4
+ if (isVisible_default(node)) {
5
+ const nodeName = node.nodeName.toLowerCase();
6
+ const isFocusableElement = [
7
+ "input",
8
+ "select",
9
+ "textarea",
10
+ "button"
11
+ ].includes(nodeName) || node.isContentEditable || nodeName === "a" && !!node.getAttribute("href");
12
+ const tabIndexAttr = node.getAttribute("tabindex");
13
+ const tabIndexNum = Number(tabIndexAttr);
14
+ let tabIndex = null;
15
+ if (tabIndexAttr && !Number.isNaN(tabIndexNum)) tabIndex = tabIndexNum;
16
+ else if (isFocusableElement && tabIndex === null) tabIndex = 0;
17
+ if (isFocusableElement && node.disabled) tabIndex = null;
18
+ return tabIndex !== null && (tabIndex >= 0 || includePositive && tabIndex < 0);
19
+ }
20
+ return false;
21
+ }
22
+ function getFocusNodeList(node, includePositive = false) {
23
+ const res = [...node.querySelectorAll("*")].filter((child) => {
24
+ return focusable(child, includePositive);
25
+ });
26
+ if (focusable(node, includePositive)) res.unshift(node);
27
+ return res;
28
+ }
29
+ var lastFocusElement = null;
30
+ var focusElements = [];
31
+ function getLastElement() {
32
+ return focusElements[focusElements.length - 1];
33
+ }
34
+ function hasFocus(element) {
35
+ const { activeElement } = document;
36
+ return element === activeElement || element.contains(activeElement);
37
+ }
38
+ function syncFocus() {
39
+ const lastElement = getLastElement();
40
+ const { activeElement } = document;
41
+ if (lastElement && !hasFocus(lastElement)) {
42
+ const focusableList = getFocusNodeList(lastElement);
43
+ (focusableList.includes(lastFocusElement) ? lastFocusElement : focusableList[0])?.focus();
44
+ } else lastFocusElement = activeElement;
45
+ }
46
+ function onWindowKeyDown(e) {
47
+ if (e.key === "Tab") {
48
+ const { activeElement } = document;
49
+ const focusableList = getFocusNodeList(getLastElement());
50
+ const last = focusableList[focusableList.length - 1];
51
+ if (e.shiftKey && activeElement === focusableList[0]) lastFocusElement = last;
52
+ else if (!e.shiftKey && activeElement === last) lastFocusElement = focusableList[0];
53
+ }
54
+ }
55
+ function lockFocus(element) {
56
+ if (element) {
57
+ focusElements = focusElements.filter((ele) => ele !== element);
58
+ focusElements.push(element);
59
+ window.addEventListener("focusin", syncFocus);
60
+ window.addEventListener("keydown", onWindowKeyDown, true);
61
+ syncFocus();
62
+ }
63
+ return () => {
64
+ lastFocusElement = null;
65
+ focusElements = focusElements.filter((ele) => ele !== element);
66
+ if (focusElements.length === 0) {
67
+ window.removeEventListener("focusin", syncFocus);
68
+ window.removeEventListener("keydown", onWindowKeyDown, true);
69
+ }
70
+ };
71
+ }
72
+ function useLockFocus(lock, getElement) {
73
+ watch(lock, (_, _o, onCleanup) => {
74
+ if (lock.value) {
75
+ const element = getElement();
76
+ if (element) onCleanup(lockFocus(element));
77
+ }
78
+ });
79
+ }
80
+ export { useLockFocus };
@@ -0,0 +1,16 @@
1
+ var isVisible_default = (element) => {
2
+ if (!element) return false;
3
+ if (element instanceof Element) {
4
+ if (element.offsetParent) return true;
5
+ if (element.getBBox) {
6
+ const { width, height } = element.getBBox();
7
+ if (width || height) return true;
8
+ }
9
+ if (element.getBoundingClientRect) {
10
+ const { width, height } = element.getBoundingClientRect();
11
+ if (width || height) return true;
12
+ }
13
+ }
14
+ return false;
15
+ };
16
+ export { isVisible_default };
@@ -1,18 +1,5 @@
1
1
  import { omit } from "../omit.js";
2
- import { Comment, Fragment, Text, isVNode, toRef } from "vue";
3
- function isEmptyElement(c) {
4
- return c && (c.type === Comment || c.type === Fragment && c.children.length === 0 || c.type === Text && c.children.trim() === "");
5
- }
6
- function filterEmpty(children = []) {
7
- if (!Array.isArray(children)) children = [children];
8
- const res = [];
9
- children.forEach((child) => {
10
- if (Array.isArray(child)) res.push(...child);
11
- else if (child?.type === Fragment) res.push(...filterEmpty(child.children));
12
- else res.push(child);
13
- });
14
- return res.filter((c) => !isEmptyElement(c));
15
- }
2
+ import { Fragment, toRef } from "vue";
16
3
  var defaultOptions = {
17
4
  class: true,
18
5
  style: true
@@ -42,4 +29,4 @@ function getStylePxValue(value) {
42
29
  }
43
30
  return value;
44
31
  }
45
- export { filterEmpty, getAttrStyleAndClass, getStylePxValue };
32
+ export { getAttrStyleAndClass, getStylePxValue };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/image",
3
3
  "type": "module",
4
- "version": "1.0.6",
4
+ "version": "1.0.8",
5
5
  "description": "image component",
6
6
  "author": "",
7
7
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@v-c/portal": "^1.0.8",
36
- "@v-c/util": "^1.0.18"
36
+ "@v-c/util": "^1.0.19"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@ant-design/icons-vue": "^7.0.1"
@@ -1,11 +0,0 @@
1
- import { inject, provide } from "vue";
2
- var QueueContextKey = Symbol("QueueContextKey");
3
- function useContextProvider(appendFunc) {
4
- const queueCreate = appendFunc;
5
- provide(QueueContextKey, queueCreate);
6
- return queueCreate;
7
- }
8
- function useContextState() {
9
- return inject(QueueContextKey, void 0);
10
- }
11
- export { useContextProvider, useContextState };
@@ -1,101 +0,0 @@
1
- import { filterEmpty } from "../../util/dist/props-util/index.js";
2
- import { warning_default } from "../../util/dist/warning.js";
3
- import "../../util/dist/index.js";
4
- import { useContextProvider } from "./Context.js";
5
- import { canUseDom } from "../../util/dist/Dom/canUseDom.js";
6
- import { useDom } from "./useDom.js";
7
- import { useEscKeyDown } from "./useEscKeyDown.js";
8
- import { useScrollLocker } from "./useScrollLocker.js";
9
- import { getDOM } from "../../util/dist/Dom/findDOMNode.js";
10
- import { Teleport, computed, createVNode, defineComponent, isVNode, mergeDefaults, onMounted, shallowRef, watch } from "vue";
11
- function _isSlot(s) {
12
- return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
13
- }
14
- function getPortalContainer(getContainer) {
15
- if (getContainer === false) return false;
16
- if (!canUseDom() || !getContainer) return null;
17
- if (typeof getContainer === "string") return document.querySelector(getContainer);
18
- if (typeof getContainer === "function") return getDOM(getContainer());
19
- return typeof getContainer === "object" ? getDOM(getContainer) : getContainer;
20
- }
21
- var Portal_default = /* @__PURE__ */ defineComponent((props, { slots, expose }) => {
22
- const shouldRender = shallowRef(props.open);
23
- const mergedRender = computed(() => shouldRender.value || props.open);
24
- if (process.env.NODE_ENV !== "production") warning_default(canUseDom() || !props.open, `Portal only work in client side. Please call 'useEffect' to show Portal instead default render in SSR.`);
25
- watch([() => props.open, () => props.autoDestroy], () => {
26
- if (props.autoDestroy || props.open) shouldRender.value = props.open;
27
- });
28
- const innerContainer = shallowRef(getPortalContainer(props.getContainer));
29
- onMounted(() => {
30
- innerContainer.value = getPortalContainer(props.getContainer) ?? null;
31
- });
32
- watch(() => props.getContainer, () => {
33
- innerContainer.value = getPortalContainer(props.getContainer) ?? null;
34
- });
35
- const [defaultContainer, queueCreate] = useDom(computed(() => !!(mergedRender.value && !innerContainer.value)), props.debug);
36
- useContextProvider(queueCreate);
37
- const mergedContainer = computed(() => innerContainer.value ?? defaultContainer);
38
- useScrollLocker(computed(() => !!(props.autoLock && props.open && canUseDom() && (mergedContainer.value === defaultContainer || mergedContainer.value === document.body))));
39
- useEscKeyDown(computed(() => !!props.open), (...args) => {
40
- props.onEsc?.(...args);
41
- });
42
- const elementEl = shallowRef();
43
- const setRef = (el) => {
44
- elementEl.value = el;
45
- };
46
- expose({ elementEl });
47
- return () => {
48
- if (!mergedRender.value || !canUseDom() || innerContainer.value === void 0) return null;
49
- const renderInline = mergedContainer.value === false;
50
- const reffedChildren = filterEmpty(slots.default?.() ?? []);
51
- if (renderInline) return reffedChildren;
52
- else {
53
- const child = reffedChildren.length === 1 ? isVNode(reffedChildren[0]) ? createVNode(reffedChildren[0], { ref: setRef }) : reffedChildren[0] : reffedChildren;
54
- return createVNode(Teleport, { "to": mergedContainer.value }, _isSlot(child) ? child : { default: () => [child] });
55
- }
56
- };
57
- }, {
58
- props: /* @__PURE__ */ mergeDefaults({
59
- getContainer: {
60
- type: [
61
- String,
62
- Function,
63
- Boolean
64
- ],
65
- required: false,
66
- skipCheck: true,
67
- default: void 0
68
- },
69
- open: {
70
- type: Boolean,
71
- required: false,
72
- default: void 0
73
- },
74
- autoDestroy: {
75
- type: Boolean,
76
- required: false,
77
- default: void 0
78
- },
79
- autoLock: {
80
- type: Boolean,
81
- required: false,
82
- default: void 0
83
- },
84
- onEsc: {
85
- type: Function,
86
- required: false,
87
- default: void 0
88
- },
89
- debug: {
90
- type: String,
91
- required: false,
92
- default: void 0
93
- }
94
- }, {
95
- autoDestroy: true,
96
- getContainer: void 0
97
- }),
98
- name: "Portal",
99
- inheritAttrs: false
100
- });
101
- export { Portal_default };
@@ -1,3 +0,0 @@
1
- import { Portal_default } from "./Portal.js";
2
- var src_default = Portal_default;
3
- export { src_default };
@@ -1,52 +0,0 @@
1
- import { useContextState } from "./Context.js";
2
- import { canUseDom } from "../../util/dist/Dom/canUseDom.js";
3
- import { computed, nextTick, onUnmounted, shallowRef, watch } from "vue";
4
- var EMPTY_LIST = [];
5
- function useDom(render, debug) {
6
- const eleFun = () => {
7
- if (!canUseDom()) return null;
8
- const defaultEle = document.createElement("div");
9
- if (process.env.NODE_ENV !== "production" && debug) defaultEle.setAttribute("data-debug", debug);
10
- return defaultEle;
11
- };
12
- const ele = eleFun();
13
- const appendedRef = shallowRef(false);
14
- const queueCreate = useContextState();
15
- const queue = shallowRef([]);
16
- const mergedQueueCreate = computed(() => queueCreate?.value || (appendedRef.value ? void 0 : (appendFn) => {
17
- queue.value = [appendFn, ...queue.value];
18
- }));
19
- function append() {
20
- if (!ele || !canUseDom()) return;
21
- if (!ele?.parentElement) document.body.appendChild(ele);
22
- appendedRef.value = true;
23
- }
24
- function cleanup() {
25
- if (!ele || !canUseDom()) {
26
- appendedRef.value = false;
27
- return;
28
- }
29
- if (ele?.parentElement) ele?.parentElement?.removeChild(ele);
30
- else if (appendedRef.value) document.body?.removeChild?.(ele);
31
- appendedRef.value = false;
32
- }
33
- watch(render, () => {
34
- if (render.value) if (queueCreate?.value) queueCreate.value(append);
35
- else append();
36
- else nextTick(() => {
37
- cleanup();
38
- });
39
- }, { immediate: true });
40
- onUnmounted(cleanup);
41
- watch(queue, () => {
42
- if (queue.value.length) {
43
- queue.value.forEach((fn) => fn());
44
- queue.value = [...EMPTY_LIST];
45
- }
46
- }, {
47
- flush: "post",
48
- immediate: true
49
- });
50
- return [ele, mergedQueueCreate];
51
- }
52
- export { useDom };
@@ -1,54 +0,0 @@
1
- import { canUseDom } from "../../util/dist/Dom/canUseDom.js";
2
- import { useId, watch } from "vue";
3
- var stack = [];
4
- var IME_LOCK_DURATION = 200;
5
- var lastCompositionEndTime = 0;
6
- process.env.NODE_ENV;
7
- function onGlobalKeyDown(event) {
8
- if (event.key === "Escape" && !event.isComposing) {
9
- if (Date.now() - lastCompositionEndTime < IME_LOCK_DURATION) return;
10
- const len = stack.length;
11
- for (let i = len - 1; i >= 0; i -= 1) stack?.[i]?.onEsc?.({
12
- top: i === len - 1,
13
- event
14
- });
15
- }
16
- }
17
- function onGlobalCompositionEnd() {
18
- lastCompositionEndTime = Date.now();
19
- }
20
- function attachGlobalEventListeners() {
21
- if (!canUseDom()) return;
22
- window.addEventListener("keydown", onGlobalKeyDown);
23
- window.addEventListener("compositionend", onGlobalCompositionEnd);
24
- }
25
- function detachGlobalEventListeners() {
26
- if (!canUseDom() || stack.length !== 0) return;
27
- window.removeEventListener("keydown", onGlobalKeyDown);
28
- window.removeEventListener("compositionend", onGlobalCompositionEnd);
29
- }
30
- function useEscKeyDown(open, onEsc = () => {}) {
31
- const id = useId();
32
- const onEventEsc = onEsc;
33
- const ensure = () => {
34
- if (!stack.find((item) => item.id === id)) stack.push({
35
- id,
36
- onEsc: onEventEsc
37
- });
38
- };
39
- const clear = () => {
40
- stack = stack.filter((item) => item.id !== id);
41
- };
42
- watch(open, (_, _o, onCleanup) => {
43
- if (!canUseDom()) return;
44
- if (open.value) {
45
- ensure();
46
- attachGlobalEventListeners();
47
- onCleanup(() => {
48
- clear();
49
- detachGlobalEventListeners();
50
- });
51
- } else if (!open.value) clear();
52
- }, { immediate: true });
53
- }
54
- export { useEscKeyDown };
@@ -1,28 +0,0 @@
1
- import { isBodyOverflowing } from "./util.js";
2
- import { removeCSS, updateCSS } from "../../util/dist/Dom/dynamicCSS.js";
3
- import { getTargetScrollBarSize } from "../../util/dist/getScrollBarSize.js";
4
- import { computed, shallowRef, unref, watch } from "vue";
5
- var UNIQUE_ID = `vc-util-locker-${Date.now()}`;
6
- var uuid = 0;
7
- function useScrollLocker(lock) {
8
- const mergedLock = computed(() => unref(lock));
9
- uuid += 1;
10
- const id = shallowRef(`${UNIQUE_ID}_${uuid}`);
11
- watch([id, mergedLock], async (_, _o, onCleanup) => {
12
- if (mergedLock.value) {
13
- const scrollbarSize = getTargetScrollBarSize(document.body).width;
14
- updateCSS(`
15
- html body {
16
- overflow-y: hidden;
17
- ${isBodyOverflowing() ? `width: calc(100% - ${scrollbarSize}px);` : ""}
18
- }`, id.value);
19
- onCleanup(() => {
20
- removeCSS(id.value);
21
- });
22
- } else removeCSS(id.value);
23
- }, {
24
- flush: "post",
25
- immediate: true
26
- });
27
- }
28
- export { useScrollLocker };
@@ -1,4 +0,0 @@
1
- function isBodyOverflowing() {
2
- return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
3
- }
4
- export { isBodyOverflowing };
@@ -1,11 +0,0 @@
1
- function contains(root, n) {
2
- if (!root) return false;
3
- if (root.contains) return root.contains(n);
4
- let node = n;
5
- while (node) {
6
- if (node === root) return true;
7
- node = node.parentNode;
8
- }
9
- return false;
10
- }
11
- export { contains };
@@ -1,79 +0,0 @@
1
- import { canUseDom } from "./canUseDom.js";
2
- import { contains } from "./contains.js";
3
- var APPEND_ORDER = "data-vc-order";
4
- var APPEND_PRIORITY = "data-vc-priority";
5
- var MARK_KEY = `vc-util-key`;
6
- var containerCache = /* @__PURE__ */ new Map();
7
- function getMark({ mark } = {}) {
8
- if (mark) return mark.startsWith("data-") ? mark : `data-${mark}`;
9
- return MARK_KEY;
10
- }
11
- function getContainer(option) {
12
- if (option.attachTo) return option.attachTo;
13
- return document.querySelector("head") || document.body;
14
- }
15
- function getOrder(prepend) {
16
- if (prepend === "queue") return "prependQueue";
17
- return prepend ? "prepend" : "append";
18
- }
19
- function findStyles(container) {
20
- return Array.from((containerCache.get(container) || container).children).filter((node) => node.tagName === "STYLE");
21
- }
22
- function injectCSS(css, option = {}) {
23
- if (!canUseDom()) return null;
24
- const { csp, prepend, priority = 0 } = option;
25
- const mergedOrder = getOrder(prepend);
26
- const isPrependQueue = mergedOrder === "prependQueue";
27
- const styleNode = document.createElement("style");
28
- styleNode.setAttribute(APPEND_ORDER, mergedOrder);
29
- if (isPrependQueue && priority) styleNode.setAttribute(APPEND_PRIORITY, `${priority}`);
30
- if (csp?.nonce) styleNode.nonce = csp?.nonce;
31
- styleNode.innerHTML = css;
32
- const container = getContainer(option);
33
- const { firstChild } = container;
34
- if (prepend) {
35
- if (isPrependQueue) {
36
- const existStyle = findStyles(container).filter((node) => {
37
- if (!["prepend", "prependQueue"].includes(node.getAttribute(APPEND_ORDER))) return false;
38
- return priority >= Number(node.getAttribute(APPEND_PRIORITY) || 0);
39
- });
40
- if (existStyle.length) {
41
- container.insertBefore(styleNode, existStyle[existStyle.length - 1].nextSibling);
42
- return styleNode;
43
- }
44
- }
45
- container.insertBefore(styleNode, firstChild);
46
- } else container.appendChild(styleNode);
47
- return styleNode;
48
- }
49
- function findExistNode(key, option = {}) {
50
- return findStyles(getContainer(option)).find((node) => node.getAttribute(getMark(option)) === key);
51
- }
52
- function removeCSS(key, option = {}) {
53
- if (!canUseDom()) return null;
54
- const existNode = findExistNode(key, option);
55
- if (existNode) getContainer(option).removeChild(existNode);
56
- }
57
- function syncRealContainer(container, option) {
58
- const cachedRealContainer = containerCache.get(container);
59
- if (!cachedRealContainer || !contains(document, cachedRealContainer)) {
60
- const placeholderStyle = injectCSS("", option);
61
- const { parentNode } = placeholderStyle;
62
- containerCache.set(container, parentNode);
63
- container.removeChild(placeholderStyle);
64
- }
65
- }
66
- function updateCSS(css, key, option = {}) {
67
- if (!canUseDom()) return null;
68
- syncRealContainer(getContainer(option), option);
69
- const existNode = findExistNode(key, option);
70
- if (existNode) {
71
- if (option.csp?.nonce && existNode.nonce !== option.csp?.nonce) existNode.nonce = option.csp?.nonce;
72
- if (existNode.innerHTML !== css) existNode.innerHTML = css;
73
- return existNode;
74
- }
75
- const newNode = injectCSS(css, option);
76
- newNode.setAttribute(getMark(option), key);
77
- return newNode;
78
- }
79
- export { removeCSS, updateCSS };
@@ -1,20 +0,0 @@
1
- import { canUseDom } from "./canUseDom.js";
2
- import { unref } from "vue";
3
- function isDOM(node) {
4
- return node instanceof HTMLElement || node instanceof SVGElement;
5
- }
6
- function getDOM(elementRef) {
7
- const unrefElementRef = unref(elementRef);
8
- if (!canUseDom()) return unrefElementRef;
9
- const dom = findDOMNode(unrefElementRef) || (unrefElementRef && typeof unrefElementRef === "object" ? findDOMNode(unrefElementRef.nativeElement) : null);
10
- if (dom && (dom.nodeType === 3 || dom.nodeType === 8) && dom.nextElementSibling) return dom.nextElementSibling;
11
- return dom;
12
- }
13
- function findDOMNode(_node) {
14
- const node = unref(_node);
15
- if (!canUseDom()) return node;
16
- if (isDOM(node)) return node;
17
- else if (node && "$el" in node) return node.$el;
18
- return null;
19
- }
20
- export { getDOM };
@@ -1,29 +0,0 @@
1
- import { filterEmpty } from "./props-util/index.js";
2
- import { createVNode, defineComponent, isVNode } from "vue";
3
- function checkIsBaseType(value) {
4
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return true;
5
- return typeof value === "undefined" || value === null;
6
- }
7
- defineComponent((props, { attrs }) => {
8
- return () => {
9
- const render$1 = props.render;
10
- if (render$1 && typeof render$1 === "function") {
11
- const _render = render$1?.();
12
- if (Array.isArray(_render)) return filterEmpty(_render).map((v) => {
13
- if (isVNode(v)) return createVNode(v, { ...attrs });
14
- else return v;
15
- });
16
- return _render;
17
- } else if (Array.isArray(render$1)) return filterEmpty(render$1).map((v) => {
18
- if (isVNode(v)) return createVNode(v, { ...attrs });
19
- return v;
20
- });
21
- else if (checkIsBaseType(render$1)) return render$1;
22
- if (isVNode(render$1)) return createVNode(render$1, { ...attrs });
23
- return render$1;
24
- };
25
- }, {
26
- inheritAttrs: false,
27
- name: "RenderComponent",
28
- props: ["render"]
29
- });
@@ -1,35 +0,0 @@
1
- function toVal(mix) {
2
- let str = "";
3
- if (typeof mix === "string" || typeof mix === "number") str += mix;
4
- else if (typeof mix === "object") {
5
- if (Array.isArray(mix)) {
6
- for (let k = 0; k < mix.length; k++) if (mix[k]) {
7
- const y = toVal(mix[k]);
8
- if (y) {
9
- str && (str += " ");
10
- str += y;
11
- }
12
- }
13
- } else for (const k in mix) if (mix[k]) {
14
- str && (str += " ");
15
- str += k;
16
- }
17
- }
18
- return str;
19
- }
20
- function classNames(...args) {
21
- let str = "";
22
- for (let i = 0; i < args.length; i++) {
23
- const tmp = args[i];
24
- if (tmp) {
25
- const x = toVal(tmp);
26
- if (x) {
27
- str && (str += " ");
28
- str += x;
29
- }
30
- }
31
- }
32
- return str;
33
- }
34
- var clsx = classNames;
35
- export { classNames, clsx };
@@ -1,53 +0,0 @@
1
- var cached;
2
- function getScrollBarSize(fresh) {
3
- if (typeof document === "undefined") return 0;
4
- if (fresh || cached === void 0) {
5
- const inner = document.createElement("div");
6
- inner.style.width = "100%";
7
- inner.style.height = "200px";
8
- const outer = document.createElement("div");
9
- const outerStyle = outer.style;
10
- outerStyle.position = "absolute";
11
- outerStyle.top = "0";
12
- outerStyle.left = "0";
13
- outerStyle.pointerEvents = "none";
14
- outerStyle.visibility = "hidden";
15
- outerStyle.width = "200px";
16
- outerStyle.height = "150px";
17
- outerStyle.overflow = "hidden";
18
- outer.appendChild(inner);
19
- document.body.appendChild(outer);
20
- const widthContained = inner.offsetWidth;
21
- outer.style.overflow = "scroll";
22
- let widthScroll = inner.offsetWidth;
23
- if (widthContained === widthScroll) widthScroll = outer.clientWidth;
24
- document.body.removeChild(outer);
25
- cached = widthContained - widthScroll;
26
- }
27
- return cached;
28
- }
29
- function ensureSize(str) {
30
- const match = str.match(/^(.*)px$/);
31
- const value = Number(match?.[1]);
32
- return Number.isNaN(value) ? getScrollBarSize() : value;
33
- }
34
- function getTargetScrollBarSize(target) {
35
- if (typeof document === "undefined" || !target || !(target instanceof Element)) return {
36
- width: 0,
37
- height: 0
38
- };
39
- if (typeof navigator !== "undefined" && /jsdom/i.test(navigator.userAgent)) return {
40
- width: 0,
41
- height: 0
42
- };
43
- let width = "0px";
44
- let height = "0px";
45
- try {
46
- ({width, height} = getComputedStyle(target, "::-webkit-scrollbar"));
47
- } catch {}
48
- return {
49
- width: ensureSize(width),
50
- height: ensureSize(height)
51
- };
52
- }
53
- export { getTargetScrollBarSize };
@@ -1 +0,0 @@
1
- import { nextTick, shallowRef, watch } from "vue";
@@ -1,5 +0,0 @@
1
- import { useId } from "vue";
2
- function getUseId() {
3
- return useId;
4
- }
5
- getUseId();
@@ -1,8 +0,0 @@
1
- import { raf_default } from "./raf.js";
2
- import { omit } from "./omit.js";
3
- import "./RenderComponent.js";
4
- import { classNames, clsx } from "./classnames.js";
5
- import "./hooks/useControlledState.js";
6
- import "./hooks/useId.js";
7
- import { useMergedState } from "./hooks/useMergedState.js";
8
- import { warning_default } from "./warning.js";
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes