@v-c/resize-observer 0.0.2 → 0.0.3
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/bump.config.ts +6 -0
- package/dist/Collection.cjs +44 -1
- package/dist/Collection.js +31 -23
- package/dist/SingleObserver/DomWrapper.cjs +11 -1
- package/dist/SingleObserver/DomWrapper.js +6 -9
- package/dist/SingleObserver/index.cjs +105 -1
- package/dist/SingleObserver/index.js +78 -57
- package/dist/index.cjs +56 -1
- package/dist/index.js +35 -25
- package/dist/utils/observerUtil.cjs +33 -1
- package/dist/utils/observerUtil.js +27 -18
- package/package.json +5 -4
package/bump.config.ts
ADDED
package/dist/Collection.cjs
CHANGED
|
@@ -1 +1,44 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const CollectionContext = Symbol("CollectionContext");
|
|
5
|
+
const Collection = /* @__PURE__ */ vue.defineComponent({
|
|
6
|
+
props: {
|
|
7
|
+
onBatchResize: {
|
|
8
|
+
type: Function,
|
|
9
|
+
required: false,
|
|
10
|
+
default: void 0
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
setup(props, {
|
|
14
|
+
slots
|
|
15
|
+
}) {
|
|
16
|
+
const resizeIdRef = vue.shallowRef(0);
|
|
17
|
+
const resizeInfosRef = vue.shallowRef([]);
|
|
18
|
+
const onCollectionResize = vue.inject(CollectionContext, () => {
|
|
19
|
+
});
|
|
20
|
+
const onResize = (size, element, data) => {
|
|
21
|
+
const resizeId = resizeIdRef.value + 1;
|
|
22
|
+
resizeIdRef.value = resizeId;
|
|
23
|
+
resizeInfosRef.value.push({
|
|
24
|
+
size,
|
|
25
|
+
element,
|
|
26
|
+
data
|
|
27
|
+
});
|
|
28
|
+
Promise.resolve().then(() => {
|
|
29
|
+
if (resizeIdRef.value === resizeId) {
|
|
30
|
+
const resizeInfos = resizeInfosRef.value;
|
|
31
|
+
resizeInfosRef.value = [];
|
|
32
|
+
props.onBatchResize?.(resizeInfos);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
onCollectionResize?.(size, element, data);
|
|
36
|
+
};
|
|
37
|
+
vue.provide(CollectionContext, onResize);
|
|
38
|
+
return () => {
|
|
39
|
+
return slots.default?.();
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
exports.Collection = Collection;
|
|
44
|
+
exports.CollectionContext = CollectionContext;
|
package/dist/Collection.js
CHANGED
|
@@ -1,36 +1,44 @@
|
|
|
1
|
-
import { defineComponent
|
|
2
|
-
const
|
|
1
|
+
import { defineComponent, shallowRef, inject, provide } from "vue";
|
|
2
|
+
const CollectionContext = Symbol("CollectionContext");
|
|
3
|
+
const Collection = /* @__PURE__ */ defineComponent({
|
|
3
4
|
props: {
|
|
4
5
|
onBatchResize: {
|
|
5
6
|
type: Function,
|
|
6
|
-
required:
|
|
7
|
+
required: false,
|
|
8
|
+
default: void 0
|
|
7
9
|
}
|
|
8
10
|
},
|
|
9
|
-
setup(
|
|
10
|
-
slots
|
|
11
|
+
setup(props, {
|
|
12
|
+
slots
|
|
11
13
|
}) {
|
|
12
|
-
const
|
|
14
|
+
const resizeIdRef = shallowRef(0);
|
|
15
|
+
const resizeInfosRef = shallowRef([]);
|
|
16
|
+
const onCollectionResize = inject(CollectionContext, () => {
|
|
13
17
|
});
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
const onResize = (size, element, data) => {
|
|
19
|
+
const resizeId = resizeIdRef.value + 1;
|
|
20
|
+
resizeIdRef.value = resizeId;
|
|
21
|
+
resizeInfosRef.value.push({
|
|
22
|
+
size,
|
|
23
|
+
element,
|
|
24
|
+
data
|
|
25
|
+
});
|
|
26
|
+
Promise.resolve().then(() => {
|
|
27
|
+
if (resizeIdRef.value === resizeId) {
|
|
28
|
+
const resizeInfos = resizeInfosRef.value;
|
|
29
|
+
resizeInfosRef.value = [];
|
|
30
|
+
props.onBatchResize?.(resizeInfos);
|
|
25
31
|
}
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
});
|
|
33
|
+
onCollectionResize?.(size, element, data);
|
|
34
|
+
};
|
|
35
|
+
provide(CollectionContext, onResize);
|
|
36
|
+
return () => {
|
|
37
|
+
return slots.default?.();
|
|
30
38
|
};
|
|
31
39
|
}
|
|
32
40
|
});
|
|
33
41
|
export {
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
Collection,
|
|
43
|
+
CollectionContext
|
|
36
44
|
};
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const DomWrapper = /* @__PURE__ */ vue.defineComponent({
|
|
5
|
+
setup(_, {
|
|
6
|
+
slots
|
|
7
|
+
}) {
|
|
8
|
+
return () => slots.default?.();
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
exports.default = DomWrapper;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { defineComponent
|
|
2
|
-
const
|
|
3
|
-
setup(
|
|
4
|
-
slots
|
|
1
|
+
import { defineComponent } from "vue";
|
|
2
|
+
const DomWrapper = /* @__PURE__ */ defineComponent({
|
|
3
|
+
setup(_, {
|
|
4
|
+
slots
|
|
5
5
|
}) {
|
|
6
|
-
return () =>
|
|
7
|
-
var r;
|
|
8
|
-
return (r = e.default) == null ? void 0 : r.call(e);
|
|
9
|
-
};
|
|
6
|
+
return () => slots.default?.();
|
|
10
7
|
}
|
|
11
8
|
});
|
|
12
9
|
export {
|
|
13
|
-
|
|
10
|
+
DomWrapper as default
|
|
14
11
|
};
|
|
@@ -1 +1,105 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const findDOMNode = require("@v-c/util/dist/Dom/findDOMNode");
|
|
5
|
+
const Collection = require("../Collection.cjs");
|
|
6
|
+
const observerUtil = require("../utils/observerUtil.cjs");
|
|
7
|
+
const DomWrapper = require("./DomWrapper.cjs");
|
|
8
|
+
const SingleObserver = /* @__PURE__ */ vue.defineComponent({
|
|
9
|
+
props: {
|
|
10
|
+
data: {
|
|
11
|
+
type: null,
|
|
12
|
+
required: false,
|
|
13
|
+
default: void 0
|
|
14
|
+
},
|
|
15
|
+
disabled: {
|
|
16
|
+
type: Boolean,
|
|
17
|
+
required: false,
|
|
18
|
+
default: void 0
|
|
19
|
+
},
|
|
20
|
+
onResize: {
|
|
21
|
+
type: Function,
|
|
22
|
+
required: false,
|
|
23
|
+
default: void 0
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
name: "SingleObserver",
|
|
27
|
+
inheritAttrs: false,
|
|
28
|
+
setup(props, {
|
|
29
|
+
expose,
|
|
30
|
+
slots
|
|
31
|
+
}) {
|
|
32
|
+
const elementRef = vue.shallowRef();
|
|
33
|
+
const wrapperRef = vue.shallowRef();
|
|
34
|
+
const onCollectionResize = vue.inject(Collection.CollectionContext, () => {
|
|
35
|
+
});
|
|
36
|
+
const sizeRef = vue.shallowRef({
|
|
37
|
+
width: -1,
|
|
38
|
+
height: -1,
|
|
39
|
+
offsetWidth: -1,
|
|
40
|
+
offsetHeight: -1
|
|
41
|
+
});
|
|
42
|
+
const getDom = () => {
|
|
43
|
+
const dom = findDOMNode(elementRef) || (elementRef.value && typeof elementRef.value === "object" ? findDOMNode(elementRef.value.nativeElement) : null) || findDOMNode(wrapperRef.value);
|
|
44
|
+
if (dom && dom.nodeType === 3 && dom.nextElementSibling) return dom.nextElementSibling;
|
|
45
|
+
return dom;
|
|
46
|
+
};
|
|
47
|
+
const onInternalResize = (target) => {
|
|
48
|
+
const {
|
|
49
|
+
onResize,
|
|
50
|
+
data
|
|
51
|
+
} = props;
|
|
52
|
+
const {
|
|
53
|
+
width,
|
|
54
|
+
height
|
|
55
|
+
} = target.getBoundingClientRect();
|
|
56
|
+
const {
|
|
57
|
+
offsetHeight,
|
|
58
|
+
offsetWidth
|
|
59
|
+
} = target;
|
|
60
|
+
const fixedWidth = Math.floor(width);
|
|
61
|
+
const fixedHeight = Math.floor(height);
|
|
62
|
+
if (sizeRef.value.width !== fixedWidth || sizeRef.value.height !== fixedHeight || sizeRef.value.offsetWidth !== offsetWidth || sizeRef.value.offsetHeight !== offsetHeight) {
|
|
63
|
+
const size = {
|
|
64
|
+
width: fixedWidth,
|
|
65
|
+
height: fixedHeight,
|
|
66
|
+
offsetWidth,
|
|
67
|
+
offsetHeight
|
|
68
|
+
};
|
|
69
|
+
sizeRef.value = size;
|
|
70
|
+
const mergedOffsetWidth = offsetWidth === Math.round(width) ? width : offsetWidth;
|
|
71
|
+
const mergedOffsetHeight = offsetHeight === Math.round(height) ? height : offsetHeight;
|
|
72
|
+
const sizeInfo = {
|
|
73
|
+
...size,
|
|
74
|
+
offsetWidth: mergedOffsetWidth,
|
|
75
|
+
offsetHeight: mergedOffsetHeight
|
|
76
|
+
};
|
|
77
|
+
onCollectionResize?.(sizeInfo, target, data);
|
|
78
|
+
if (onResize) {
|
|
79
|
+
Promise.resolve().then(() => {
|
|
80
|
+
onResize(sizeInfo, target);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
let currentElement;
|
|
86
|
+
vue.onMounted(() => {
|
|
87
|
+
currentElement = getDom();
|
|
88
|
+
if (currentElement && !props.disabled) observerUtil.observe(currentElement, onInternalResize);
|
|
89
|
+
});
|
|
90
|
+
vue.onBeforeUnmount(() => {
|
|
91
|
+
if (currentElement) observerUtil.unobserve(currentElement, onInternalResize);
|
|
92
|
+
});
|
|
93
|
+
expose({
|
|
94
|
+
getDom
|
|
95
|
+
});
|
|
96
|
+
return () => {
|
|
97
|
+
return vue.createVNode(DomWrapper.default, {
|
|
98
|
+
"ref": wrapperRef
|
|
99
|
+
}, {
|
|
100
|
+
default: () => [slots.default?.()]
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
exports.default = SingleObserver;
|
|
@@ -1,84 +1,105 @@
|
|
|
1
|
-
import { defineComponent
|
|
2
|
-
import
|
|
3
|
-
import { CollectionContext
|
|
4
|
-
import { observe
|
|
5
|
-
import
|
|
6
|
-
const
|
|
1
|
+
import { defineComponent, shallowRef, inject, onMounted, onBeforeUnmount, createVNode } from "vue";
|
|
2
|
+
import findDOMNode from "@v-c/util/dist/Dom/findDOMNode";
|
|
3
|
+
import { CollectionContext } from "../Collection.js";
|
|
4
|
+
import { observe, unobserve } from "../utils/observerUtil.js";
|
|
5
|
+
import DomWrapper from "./DomWrapper.js";
|
|
6
|
+
const SingleObserver = /* @__PURE__ */ defineComponent({
|
|
7
7
|
props: {
|
|
8
8
|
data: {
|
|
9
9
|
type: null,
|
|
10
|
-
required:
|
|
10
|
+
required: false,
|
|
11
|
+
default: void 0
|
|
11
12
|
},
|
|
12
13
|
disabled: {
|
|
13
14
|
type: Boolean,
|
|
14
|
-
required:
|
|
15
|
+
required: false,
|
|
16
|
+
default: void 0
|
|
15
17
|
},
|
|
16
18
|
onResize: {
|
|
17
19
|
type: Function,
|
|
18
|
-
required:
|
|
20
|
+
required: false,
|
|
21
|
+
default: void 0
|
|
19
22
|
}
|
|
20
23
|
},
|
|
21
24
|
name: "SingleObserver",
|
|
22
|
-
inheritAttrs:
|
|
23
|
-
setup(
|
|
24
|
-
expose
|
|
25
|
-
slots
|
|
25
|
+
inheritAttrs: false,
|
|
26
|
+
setup(props, {
|
|
27
|
+
expose,
|
|
28
|
+
slots
|
|
26
29
|
}) {
|
|
27
|
-
const
|
|
28
|
-
|
|
30
|
+
const elementRef = shallowRef();
|
|
31
|
+
const wrapperRef = shallowRef();
|
|
32
|
+
const onCollectionResize = inject(CollectionContext, () => {
|
|
33
|
+
});
|
|
34
|
+
const sizeRef = shallowRef({
|
|
29
35
|
width: -1,
|
|
30
36
|
height: -1,
|
|
31
37
|
offsetWidth: -1,
|
|
32
38
|
offsetHeight: -1
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
});
|
|
40
|
+
const getDom = () => {
|
|
41
|
+
const dom = findDOMNode(elementRef) || (elementRef.value && typeof elementRef.value === "object" ? findDOMNode(elementRef.value.nativeElement) : null) || findDOMNode(wrapperRef.value);
|
|
42
|
+
if (dom && dom.nodeType === 3 && dom.nextElementSibling) return dom.nextElementSibling;
|
|
43
|
+
return dom;
|
|
44
|
+
};
|
|
45
|
+
const onInternalResize = (target) => {
|
|
46
|
+
const {
|
|
47
|
+
onResize,
|
|
48
|
+
data
|
|
49
|
+
} = props;
|
|
50
|
+
const {
|
|
51
|
+
width,
|
|
52
|
+
height
|
|
53
|
+
} = target.getBoundingClientRect();
|
|
37
54
|
const {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
width: v,
|
|
50
|
-
height: b,
|
|
51
|
-
offsetWidth: f,
|
|
52
|
-
offsetHeight: i
|
|
55
|
+
offsetHeight,
|
|
56
|
+
offsetWidth
|
|
57
|
+
} = target;
|
|
58
|
+
const fixedWidth = Math.floor(width);
|
|
59
|
+
const fixedHeight = Math.floor(height);
|
|
60
|
+
if (sizeRef.value.width !== fixedWidth || sizeRef.value.height !== fixedHeight || sizeRef.value.offsetWidth !== offsetWidth || sizeRef.value.offsetHeight !== offsetHeight) {
|
|
61
|
+
const size = {
|
|
62
|
+
width: fixedWidth,
|
|
63
|
+
height: fixedHeight,
|
|
64
|
+
offsetWidth,
|
|
65
|
+
offsetHeight
|
|
53
66
|
};
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
sizeRef.value = size;
|
|
68
|
+
const mergedOffsetWidth = offsetWidth === Math.round(width) ? width : offsetWidth;
|
|
69
|
+
const mergedOffsetHeight = offsetHeight === Math.round(height) ? height : offsetHeight;
|
|
70
|
+
const sizeInfo = {
|
|
71
|
+
...size,
|
|
72
|
+
offsetWidth: mergedOffsetWidth,
|
|
73
|
+
offsetHeight: mergedOffsetHeight
|
|
59
74
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
75
|
+
onCollectionResize?.(sizeInfo, target, data);
|
|
76
|
+
if (onResize) {
|
|
77
|
+
Promise.resolve().then(() => {
|
|
78
|
+
onResize(sizeInfo, target);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
63
81
|
}
|
|
64
82
|
};
|
|
65
|
-
let
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}), () => S(D, {
|
|
73
|
-
ref: m
|
|
74
|
-
}, {
|
|
75
|
-
default: () => {
|
|
76
|
-
var e;
|
|
77
|
-
return [(e = r.default) == null ? void 0 : e.call(r)];
|
|
78
|
-
}
|
|
83
|
+
let currentElement;
|
|
84
|
+
onMounted(() => {
|
|
85
|
+
currentElement = getDom();
|
|
86
|
+
if (currentElement && !props.disabled) observe(currentElement, onInternalResize);
|
|
87
|
+
});
|
|
88
|
+
onBeforeUnmount(() => {
|
|
89
|
+
if (currentElement) unobserve(currentElement, onInternalResize);
|
|
79
90
|
});
|
|
91
|
+
expose({
|
|
92
|
+
getDom
|
|
93
|
+
});
|
|
94
|
+
return () => {
|
|
95
|
+
return createVNode(DomWrapper, {
|
|
96
|
+
"ref": wrapperRef
|
|
97
|
+
}, {
|
|
98
|
+
default: () => [slots.default?.()]
|
|
99
|
+
});
|
|
100
|
+
};
|
|
80
101
|
}
|
|
81
102
|
});
|
|
82
103
|
export {
|
|
83
|
-
|
|
104
|
+
SingleObserver as default
|
|
84
105
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,56 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const util = require("@v-c/util");
|
|
5
|
+
const toArray = require("@v-c/util/dist/Children/toArray");
|
|
6
|
+
const Collection = require("./Collection.cjs");
|
|
7
|
+
const index = require("./SingleObserver/index.cjs");
|
|
8
|
+
const observerUtil = require("./utils/observerUtil.cjs");
|
|
9
|
+
function _isSlot(s) {
|
|
10
|
+
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
|
|
11
|
+
}
|
|
12
|
+
const INTERNAL_PREFIX_KEY = "vc-observer-key";
|
|
13
|
+
const ResizeObserver = /* @__PURE__ */ vue.defineComponent({
|
|
14
|
+
props: {
|
|
15
|
+
data: {
|
|
16
|
+
type: null,
|
|
17
|
+
required: false,
|
|
18
|
+
default: void 0
|
|
19
|
+
},
|
|
20
|
+
disabled: {
|
|
21
|
+
type: Boolean,
|
|
22
|
+
required: false,
|
|
23
|
+
default: void 0
|
|
24
|
+
},
|
|
25
|
+
onResize: {
|
|
26
|
+
type: Function,
|
|
27
|
+
required: false,
|
|
28
|
+
default: void 0
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
setup(props, {
|
|
32
|
+
slots
|
|
33
|
+
}) {
|
|
34
|
+
return () => {
|
|
35
|
+
const childNodes = toArray.toArray(slots.default?.());
|
|
36
|
+
if (process.env.NODE_ENV !== "production") {
|
|
37
|
+
if (childNodes.length > 1) {
|
|
38
|
+
util.warning(false, "Find more than one child node with `children` in ResizeObserver. Please use ResizeObserver.Collection instead.");
|
|
39
|
+
} else if (childNodes.length === 0) {
|
|
40
|
+
util.warning(false, "`children` of ResizeObserver is empty. Nothing is in observe.");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return childNodes.map((child, index$1) => {
|
|
44
|
+
const key = child?.key || `${INTERNAL_PREFIX_KEY}-${index$1}`;
|
|
45
|
+
return vue.createVNode(index.default, vue.mergeProps(props, {
|
|
46
|
+
"key": key
|
|
47
|
+
}), _isSlot(child) ? child : {
|
|
48
|
+
default: () => [child]
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
ResizeObserver.Collection = Collection.Collection;
|
|
55
|
+
exports._rs = observerUtil._rs;
|
|
56
|
+
exports.default = ResizeObserver;
|
package/dist/index.js
CHANGED
|
@@ -1,46 +1,56 @@
|
|
|
1
|
-
import { defineComponent
|
|
2
|
-
import { warning
|
|
3
|
-
import { toArray
|
|
4
|
-
import { Collection
|
|
5
|
-
import
|
|
6
|
-
import { _rs
|
|
7
|
-
function
|
|
8
|
-
return typeof
|
|
1
|
+
import { defineComponent, createVNode, mergeProps, isVNode } from "vue";
|
|
2
|
+
import { warning } from "@v-c/util";
|
|
3
|
+
import { toArray } from "@v-c/util/dist/Children/toArray";
|
|
4
|
+
import { Collection } from "./Collection.js";
|
|
5
|
+
import SingleObserver from "./SingleObserver/index.js";
|
|
6
|
+
import { _rs } from "./utils/observerUtil.js";
|
|
7
|
+
function _isSlot(s) {
|
|
8
|
+
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const INTERNAL_PREFIX_KEY = "vc-observer-key";
|
|
11
|
+
const ResizeObserver = /* @__PURE__ */ defineComponent({
|
|
11
12
|
props: {
|
|
12
13
|
data: {
|
|
13
14
|
type: null,
|
|
14
|
-
required:
|
|
15
|
+
required: false,
|
|
16
|
+
default: void 0
|
|
15
17
|
},
|
|
16
18
|
disabled: {
|
|
17
19
|
type: Boolean,
|
|
18
|
-
required:
|
|
20
|
+
required: false,
|
|
21
|
+
default: void 0
|
|
19
22
|
},
|
|
20
23
|
onResize: {
|
|
21
24
|
type: Function,
|
|
22
|
-
required:
|
|
25
|
+
required: false,
|
|
26
|
+
default: void 0
|
|
23
27
|
}
|
|
24
28
|
},
|
|
25
|
-
setup(
|
|
26
|
-
slots
|
|
29
|
+
setup(props, {
|
|
30
|
+
slots
|
|
27
31
|
}) {
|
|
28
32
|
return () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
33
|
+
const childNodes = toArray(slots.default?.());
|
|
34
|
+
if (process.env.NODE_ENV !== "production") {
|
|
35
|
+
if (childNodes.length > 1) {
|
|
36
|
+
warning(false, "Find more than one child node with `children` in ResizeObserver. Please use ResizeObserver.Collection instead.");
|
|
37
|
+
} else if (childNodes.length === 0) {
|
|
38
|
+
warning(false, "`children` of ResizeObserver is empty. Nothing is in observe.");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return childNodes.map((child, index) => {
|
|
42
|
+
const key = child?.key || `${INTERNAL_PREFIX_KEY}-${index}`;
|
|
43
|
+
return createVNode(SingleObserver, mergeProps(props, {
|
|
44
|
+
"key": key
|
|
45
|
+
}), _isSlot(child) ? child : {
|
|
46
|
+
default: () => [child]
|
|
37
47
|
});
|
|
38
48
|
});
|
|
39
49
|
};
|
|
40
50
|
}
|
|
41
51
|
});
|
|
42
|
-
|
|
52
|
+
ResizeObserver.Collection = Collection;
|
|
43
53
|
export {
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
_rs,
|
|
55
|
+
ResizeObserver as default
|
|
46
56
|
};
|
|
@@ -1 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const ResizeObserver = require("resize-observer-polyfill");
|
|
4
|
+
const elementListeners = /* @__PURE__ */ new Map();
|
|
5
|
+
function onResize(entities) {
|
|
6
|
+
entities.forEach((entity) => {
|
|
7
|
+
const { target } = entity;
|
|
8
|
+
elementListeners.get(target)?.forEach((listener) => listener(target));
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
const resizeObserver = new ResizeObserver(onResize);
|
|
12
|
+
const _el = process.env.NODE_ENV !== "production" ? elementListeners : null;
|
|
13
|
+
const _rs = process.env.NODE_ENV !== "production" ? onResize : null;
|
|
14
|
+
function observe(element, callback) {
|
|
15
|
+
if (!elementListeners.has(element)) {
|
|
16
|
+
elementListeners.set(element, /* @__PURE__ */ new Set());
|
|
17
|
+
resizeObserver.observe(element);
|
|
18
|
+
}
|
|
19
|
+
elementListeners?.get?.(element)?.add?.(callback);
|
|
20
|
+
}
|
|
21
|
+
function unobserve(element, callback) {
|
|
22
|
+
if (elementListeners.has(element)) {
|
|
23
|
+
elementListeners?.get?.(element)?.delete?.(callback);
|
|
24
|
+
if (!elementListeners?.get?.(element)?.size) {
|
|
25
|
+
resizeObserver.unobserve(element);
|
|
26
|
+
elementListeners.delete(element);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports._el = _el;
|
|
31
|
+
exports._rs = _rs;
|
|
32
|
+
exports.observe = observe;
|
|
33
|
+
exports.unobserve = unobserve;
|
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
(f = o.get(r)) == null || f.forEach((u) => u(r));
|
|
1
|
+
import ResizeObserver from "resize-observer-polyfill";
|
|
2
|
+
const elementListeners = /* @__PURE__ */ new Map();
|
|
3
|
+
function onResize(entities) {
|
|
4
|
+
entities.forEach((entity) => {
|
|
5
|
+
const { target } = entity;
|
|
6
|
+
elementListeners.get(target)?.forEach((listener) => listener(target));
|
|
8
7
|
});
|
|
9
8
|
}
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const resizeObserver = new ResizeObserver(onResize);
|
|
10
|
+
const _el = process.env.NODE_ENV !== "production" ? elementListeners : null;
|
|
11
|
+
const _rs = process.env.NODE_ENV !== "production" ? onResize : null;
|
|
12
|
+
function observe(element, callback) {
|
|
13
|
+
if (!elementListeners.has(element)) {
|
|
14
|
+
elementListeners.set(element, /* @__PURE__ */ new Set());
|
|
15
|
+
resizeObserver.observe(element);
|
|
16
|
+
}
|
|
17
|
+
elementListeners?.get?.(element)?.add?.(callback);
|
|
14
18
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
function unobserve(element, callback) {
|
|
20
|
+
if (elementListeners.has(element)) {
|
|
21
|
+
elementListeners?.get?.(element)?.delete?.(callback);
|
|
22
|
+
if (!elementListeners?.get?.(element)?.size) {
|
|
23
|
+
resizeObserver.unobserve(element);
|
|
24
|
+
elementListeners.delete(element);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
18
27
|
}
|
|
19
28
|
export {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
_el,
|
|
30
|
+
_rs,
|
|
31
|
+
observe,
|
|
32
|
+
unobserve
|
|
24
33
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-c/resize-observer",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -16,11 +16,12 @@
|
|
|
16
16
|
"vue": "^3.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"classnames": "^2.5.1",
|
|
20
19
|
"resize-observer-polyfill": "^1.5.1",
|
|
21
|
-
"@v-c/util": "0.0.
|
|
20
|
+
"@v-c/util": "0.0.13"
|
|
22
21
|
},
|
|
23
22
|
"scripts": {
|
|
24
|
-
"build": "vite build"
|
|
23
|
+
"build": "vite build",
|
|
24
|
+
"prepublish": "pnpm build",
|
|
25
|
+
"bump": "bumpp --release patch"
|
|
25
26
|
}
|
|
26
27
|
}
|