@element-plus/nightly 0.0.20231009 → 0.0.20231011
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/attributes.json +1 -1
- package/dist/index.css +1 -1
- package/dist/index.full.js +1016 -538
- package/dist/index.full.min.js +25 -25
- package/dist/index.full.min.js.map +1 -1
- package/dist/index.full.min.mjs +23 -23
- package/dist/index.full.min.mjs.map +1 -1
- package/dist/index.full.mjs +1016 -538
- package/dist/locale/af.js +1 -1
- package/dist/locale/af.min.js +1 -1
- package/dist/locale/af.min.mjs +1 -1
- package/dist/locale/af.mjs +1 -1
- package/dist/locale/ar.js +1 -1
- package/dist/locale/ar.min.js +1 -1
- package/dist/locale/ar.min.mjs +1 -1
- package/dist/locale/ar.mjs +1 -1
- package/dist/locale/az.js +1 -1
- package/dist/locale/az.min.js +1 -1
- package/dist/locale/az.min.mjs +1 -1
- package/dist/locale/az.mjs +1 -1
- package/dist/locale/bg.js +1 -1
- package/dist/locale/bg.min.js +1 -1
- package/dist/locale/bg.min.mjs +1 -1
- package/dist/locale/bg.mjs +1 -1
- package/dist/locale/bn.js +1 -1
- package/dist/locale/bn.min.js +1 -1
- package/dist/locale/bn.min.mjs +1 -1
- package/dist/locale/bn.mjs +1 -1
- package/dist/locale/ca.js +1 -1
- package/dist/locale/ca.min.js +1 -1
- package/dist/locale/ca.min.mjs +1 -1
- package/dist/locale/ca.mjs +1 -1
- package/dist/locale/ckb.js +1 -1
- package/dist/locale/ckb.min.js +1 -1
- package/dist/locale/ckb.min.mjs +1 -1
- package/dist/locale/ckb.mjs +1 -1
- package/dist/locale/cs.js +1 -1
- package/dist/locale/cs.min.js +1 -1
- package/dist/locale/cs.min.mjs +1 -1
- package/dist/locale/cs.mjs +1 -1
- package/dist/locale/da.js +1 -1
- package/dist/locale/da.min.js +1 -1
- package/dist/locale/da.min.mjs +1 -1
- package/dist/locale/da.mjs +1 -1
- package/dist/locale/de.js +1 -1
- package/dist/locale/de.min.js +1 -1
- package/dist/locale/de.min.mjs +1 -1
- package/dist/locale/de.mjs +1 -1
- package/dist/locale/el.js +1 -1
- package/dist/locale/el.min.js +1 -1
- package/dist/locale/el.min.mjs +1 -1
- package/dist/locale/el.mjs +1 -1
- package/dist/locale/en.js +1 -1
- package/dist/locale/en.min.js +1 -1
- package/dist/locale/en.min.mjs +1 -1
- package/dist/locale/en.mjs +1 -1
- package/dist/locale/eo.js +1 -1
- package/dist/locale/eo.min.js +1 -1
- package/dist/locale/eo.min.mjs +1 -1
- package/dist/locale/eo.mjs +1 -1
- package/dist/locale/es.js +1 -1
- package/dist/locale/es.min.js +1 -1
- package/dist/locale/es.min.mjs +1 -1
- package/dist/locale/es.mjs +1 -1
- package/dist/locale/et.js +1 -1
- package/dist/locale/et.min.js +1 -1
- package/dist/locale/et.min.mjs +1 -1
- package/dist/locale/et.mjs +1 -1
- package/dist/locale/eu.js +1 -1
- package/dist/locale/eu.min.js +1 -1
- package/dist/locale/eu.min.mjs +1 -1
- package/dist/locale/eu.mjs +1 -1
- package/dist/locale/fa.js +1 -1
- package/dist/locale/fa.min.js +1 -1
- package/dist/locale/fa.min.mjs +1 -1
- package/dist/locale/fa.mjs +1 -1
- package/dist/locale/fi.js +1 -1
- package/dist/locale/fi.min.js +1 -1
- package/dist/locale/fi.min.mjs +1 -1
- package/dist/locale/fi.mjs +1 -1
- package/dist/locale/fr.js +1 -1
- package/dist/locale/fr.min.js +1 -1
- package/dist/locale/fr.min.mjs +1 -1
- package/dist/locale/fr.mjs +1 -1
- package/dist/locale/he.js +1 -1
- package/dist/locale/he.min.js +1 -1
- package/dist/locale/he.min.mjs +1 -1
- package/dist/locale/he.mjs +1 -1
- package/dist/locale/hr.js +1 -1
- package/dist/locale/hr.min.js +1 -1
- package/dist/locale/hr.min.mjs +1 -1
- package/dist/locale/hr.mjs +1 -1
- package/dist/locale/hu.js +1 -1
- package/dist/locale/hu.min.js +1 -1
- package/dist/locale/hu.min.mjs +1 -1
- package/dist/locale/hu.mjs +1 -1
- package/dist/locale/hy-am.js +1 -1
- package/dist/locale/hy-am.min.js +1 -1
- package/dist/locale/hy-am.min.mjs +1 -1
- package/dist/locale/hy-am.mjs +1 -1
- package/dist/locale/id.js +1 -1
- package/dist/locale/id.min.js +1 -1
- package/dist/locale/id.min.mjs +1 -1
- package/dist/locale/id.mjs +1 -1
- package/dist/locale/it.js +1 -1
- package/dist/locale/it.min.js +1 -1
- package/dist/locale/it.min.mjs +1 -1
- package/dist/locale/it.mjs +1 -1
- package/dist/locale/ja.js +1 -1
- package/dist/locale/ja.min.js +1 -1
- package/dist/locale/ja.min.mjs +1 -1
- package/dist/locale/ja.mjs +1 -1
- package/dist/locale/kk.js +1 -1
- package/dist/locale/kk.min.js +1 -1
- package/dist/locale/kk.min.mjs +1 -1
- package/dist/locale/kk.mjs +1 -1
- package/dist/locale/km.js +1 -1
- package/dist/locale/km.min.js +1 -1
- package/dist/locale/km.min.mjs +1 -1
- package/dist/locale/km.mjs +1 -1
- package/dist/locale/ko.js +1 -1
- package/dist/locale/ko.min.js +1 -1
- package/dist/locale/ko.min.mjs +1 -1
- package/dist/locale/ko.mjs +1 -1
- package/dist/locale/ku.js +1 -1
- package/dist/locale/ku.min.js +1 -1
- package/dist/locale/ku.min.mjs +1 -1
- package/dist/locale/ku.mjs +1 -1
- package/dist/locale/ky.js +1 -1
- package/dist/locale/ky.min.js +1 -1
- package/dist/locale/ky.min.mjs +1 -1
- package/dist/locale/ky.mjs +1 -1
- package/dist/locale/lt.js +1 -1
- package/dist/locale/lt.min.js +1 -1
- package/dist/locale/lt.min.mjs +1 -1
- package/dist/locale/lt.mjs +1 -1
- package/dist/locale/lv.js +1 -1
- package/dist/locale/lv.min.js +1 -1
- package/dist/locale/lv.min.mjs +1 -1
- package/dist/locale/lv.mjs +1 -1
- package/dist/locale/mg.js +1 -1
- package/dist/locale/mg.min.js +1 -1
- package/dist/locale/mg.min.mjs +1 -1
- package/dist/locale/mg.mjs +1 -1
- package/dist/locale/mn.js +1 -1
- package/dist/locale/mn.min.js +1 -1
- package/dist/locale/mn.min.mjs +1 -1
- package/dist/locale/mn.mjs +1 -1
- package/dist/locale/nb-no.js +1 -1
- package/dist/locale/nb-no.min.js +1 -1
- package/dist/locale/nb-no.min.mjs +1 -1
- package/dist/locale/nb-no.mjs +1 -1
- package/dist/locale/nl.js +1 -1
- package/dist/locale/nl.min.js +1 -1
- package/dist/locale/nl.min.mjs +1 -1
- package/dist/locale/nl.mjs +1 -1
- package/dist/locale/pa.js +1 -1
- package/dist/locale/pa.min.js +1 -1
- package/dist/locale/pa.min.mjs +1 -1
- package/dist/locale/pa.mjs +1 -1
- package/dist/locale/pl.js +1 -1
- package/dist/locale/pl.min.js +1 -1
- package/dist/locale/pl.min.mjs +1 -1
- package/dist/locale/pl.mjs +1 -1
- package/dist/locale/pt-br.js +1 -1
- package/dist/locale/pt-br.min.js +1 -1
- package/dist/locale/pt-br.min.mjs +1 -1
- package/dist/locale/pt-br.mjs +1 -1
- package/dist/locale/pt.js +1 -1
- package/dist/locale/pt.min.js +1 -1
- package/dist/locale/pt.min.mjs +1 -1
- package/dist/locale/pt.mjs +1 -1
- package/dist/locale/ro.js +1 -1
- package/dist/locale/ro.min.js +1 -1
- package/dist/locale/ro.min.mjs +1 -1
- package/dist/locale/ro.mjs +1 -1
- package/dist/locale/ru.js +1 -1
- package/dist/locale/ru.min.js +1 -1
- package/dist/locale/ru.min.mjs +1 -1
- package/dist/locale/ru.mjs +1 -1
- package/dist/locale/sk.js +1 -1
- package/dist/locale/sk.min.js +1 -1
- package/dist/locale/sk.min.mjs +1 -1
- package/dist/locale/sk.mjs +1 -1
- package/dist/locale/sl.js +1 -1
- package/dist/locale/sl.min.js +1 -1
- package/dist/locale/sl.min.mjs +1 -1
- package/dist/locale/sl.mjs +1 -1
- package/dist/locale/sr.js +1 -1
- package/dist/locale/sr.min.js +1 -1
- package/dist/locale/sr.min.mjs +1 -1
- package/dist/locale/sr.mjs +1 -1
- package/dist/locale/sv.js +1 -1
- package/dist/locale/sv.min.js +1 -1
- package/dist/locale/sv.min.mjs +1 -1
- package/dist/locale/sv.mjs +1 -1
- package/dist/locale/ta.js +1 -1
- package/dist/locale/ta.min.js +1 -1
- package/dist/locale/ta.min.mjs +1 -1
- package/dist/locale/ta.mjs +1 -1
- package/dist/locale/th.js +1 -1
- package/dist/locale/th.min.js +1 -1
- package/dist/locale/th.min.mjs +1 -1
- package/dist/locale/th.mjs +1 -1
- package/dist/locale/tk.js +1 -1
- package/dist/locale/tk.min.js +1 -1
- package/dist/locale/tk.min.mjs +1 -1
- package/dist/locale/tk.mjs +1 -1
- package/dist/locale/tr.js +1 -1
- package/dist/locale/tr.min.js +1 -1
- package/dist/locale/tr.min.mjs +1 -1
- package/dist/locale/tr.mjs +1 -1
- package/dist/locale/ug-cn.js +1 -1
- package/dist/locale/ug-cn.min.js +1 -1
- package/dist/locale/ug-cn.min.mjs +1 -1
- package/dist/locale/ug-cn.mjs +1 -1
- package/dist/locale/uk.js +1 -1
- package/dist/locale/uk.min.js +1 -1
- package/dist/locale/uk.min.mjs +1 -1
- package/dist/locale/uk.mjs +1 -1
- package/dist/locale/uz-uz.js +1 -1
- package/dist/locale/uz-uz.min.js +1 -1
- package/dist/locale/uz-uz.min.mjs +1 -1
- package/dist/locale/uz-uz.mjs +1 -1
- package/dist/locale/vi.js +1 -1
- package/dist/locale/vi.min.js +1 -1
- package/dist/locale/vi.min.mjs +1 -1
- package/dist/locale/vi.mjs +1 -1
- package/dist/locale/zh-cn.js +1 -1
- package/dist/locale/zh-cn.min.js +1 -1
- package/dist/locale/zh-cn.min.mjs +1 -1
- package/dist/locale/zh-cn.mjs +1 -1
- package/dist/locale/zh-tw.js +1 -1
- package/dist/locale/zh-tw.min.js +1 -1
- package/dist/locale/zh-tw.min.mjs +1 -1
- package/dist/locale/zh-tw.mjs +1 -1
- package/es/component.mjs +3 -1
- package/es/component.mjs.map +1 -1
- package/es/components/carousel/index.d.ts +5 -0
- package/es/components/carousel/src/carousel.vue.d.ts +5 -0
- package/es/components/carousel/src/carousel2.mjs +7 -2
- package/es/components/carousel/src/carousel2.mjs.map +1 -1
- package/es/components/carousel/src/use-carousel.d.ts +6 -0
- package/es/components/carousel/src/use-carousel.mjs +33 -1
- package/es/components/carousel/src/use-carousel.mjs.map +1 -1
- package/es/components/checkbox/index.d.ts +12 -0
- package/es/components/checkbox/src/checkbox-button.vue.d.ts +4 -0
- package/es/components/checkbox/src/checkbox.d.ts +1 -0
- package/es/components/checkbox/src/checkbox.mjs +2 -1
- package/es/components/checkbox/src/checkbox.mjs.map +1 -1
- package/es/components/checkbox/src/checkbox.vue.d.ts +4 -0
- package/es/components/checkbox/src/composables/use-checkbox-status.mjs +2 -2
- package/es/components/checkbox/src/composables/use-checkbox-status.mjs.map +1 -1
- package/es/components/color-picker/index.d.ts +18 -1
- package/es/components/color-picker/src/color-picker.d.ts +2 -0
- package/es/components/color-picker/src/color-picker.mjs +3 -1
- package/es/components/color-picker/src/color-picker.mjs.map +1 -1
- package/es/components/color-picker/src/color-picker.vue.d.ts +18 -1
- package/es/components/color-picker/src/color-picker2.mjs +83 -11
- package/es/components/color-picker/src/color-picker2.mjs.map +1 -1
- package/es/components/descriptions/src/description-item.mjs.map +1 -1
- package/es/components/descriptions/src/description.mjs.map +1 -1
- package/es/components/drawer/index.mjs +2 -2
- package/es/components/drawer/src/drawer.mjs +26 -176
- package/es/components/drawer/src/drawer.mjs.map +1 -1
- package/es/components/drawer/src/drawer2.mjs +176 -26
- package/es/components/drawer/src/drawer2.mjs.map +1 -1
- package/es/components/index.mjs +1 -1
- package/es/components/table/src/table.mjs +2 -1
- package/es/components/table/src/table.mjs.map +1 -1
- package/es/components/transfer/index.d.ts +40 -0
- package/es/components/transfer/src/transfer-panel.vue.d.ts +8 -0
- package/es/components/transfer/src/transfer.vue.d.ts +40 -0
- package/es/components/tree-v2/index.d.ts +8 -0
- package/es/components/tree-v2/src/tree-node.vue.d.ts +8 -0
- package/es/components/tree-v2/src/tree.vue.d.ts +8 -0
- package/es/components/watermark/index.d.ts +94 -0
- package/es/components/watermark/index.mjs +9 -0
- package/es/components/watermark/index.mjs.map +1 -0
- package/es/components/watermark/src/useClips.d.ts +7 -0
- package/es/components/watermark/src/useClips.mjs +82 -0
- package/es/components/watermark/src/useClips.mjs.map +1 -0
- package/es/components/watermark/src/utils.d.ts +8 -0
- package/es/components/watermark/src/utils.mjs +22 -0
- package/es/components/watermark/src/utils.mjs.map +1 -0
- package/es/components/watermark/src/watermark.d.ts +32 -0
- package/es/components/watermark/src/watermark.mjs +33 -0
- package/es/components/watermark/src/watermark.mjs.map +1 -0
- package/es/components/watermark/src/watermark.vue.d.ts +94 -0
- package/es/components/watermark/src/watermark2.mjs +202 -0
- package/es/components/watermark/src/watermark2.mjs.map +1 -0
- package/es/components/watermark/style/index.d.ts +0 -0
- package/es/components/watermark/style/index.mjs +2 -0
- package/es/components/watermark/style/index.mjs.map +1 -0
- package/es/hooks/use-focus-controller/index.d.ts +6 -1
- package/es/hooks/use-focus-controller/index.mjs +5 -2
- package/es/hooks/use-focus-controller/index.mjs.map +1 -1
- package/es/index.mjs +1 -1
- package/es/version.d.ts +1 -1
- package/es/version.mjs +1 -1
- package/es/version.mjs.map +1 -1
- package/lib/component.js +3 -1
- package/lib/component.js.map +1 -1
- package/lib/components/carousel/index.d.ts +5 -0
- package/lib/components/carousel/src/carousel.vue.d.ts +5 -0
- package/lib/components/carousel/src/carousel2.js +7 -2
- package/lib/components/carousel/src/carousel2.js.map +1 -1
- package/lib/components/carousel/src/use-carousel.d.ts +6 -0
- package/lib/components/carousel/src/use-carousel.js +32 -0
- package/lib/components/carousel/src/use-carousel.js.map +1 -1
- package/lib/components/checkbox/index.d.ts +12 -0
- package/lib/components/checkbox/src/checkbox-button.vue.d.ts +4 -0
- package/lib/components/checkbox/src/checkbox.d.ts +1 -0
- package/lib/components/checkbox/src/checkbox.js +2 -1
- package/lib/components/checkbox/src/checkbox.js.map +1 -1
- package/lib/components/checkbox/src/checkbox.vue.d.ts +4 -0
- package/lib/components/checkbox/src/composables/use-checkbox-status.js +1 -1
- package/lib/components/checkbox/src/composables/use-checkbox-status.js.map +1 -1
- package/lib/components/color-picker/index.d.ts +18 -1
- package/lib/components/color-picker/src/color-picker.d.ts +2 -0
- package/lib/components/color-picker/src/color-picker.js +3 -1
- package/lib/components/color-picker/src/color-picker.js.map +1 -1
- package/lib/components/color-picker/src/color-picker.vue.d.ts +18 -1
- package/lib/components/color-picker/src/color-picker2.js +93 -21
- package/lib/components/color-picker/src/color-picker2.js.map +1 -1
- package/lib/components/descriptions/src/description-item.js.map +1 -1
- package/lib/components/descriptions/src/description.js.map +1 -1
- package/lib/components/drawer/index.js +2 -2
- package/lib/components/drawer/src/drawer.js +27 -176
- package/lib/components/drawer/src/drawer.js.map +1 -1
- package/lib/components/drawer/src/drawer2.js +176 -27
- package/lib/components/drawer/src/drawer2.js.map +1 -1
- package/lib/components/index.js +1 -1
- package/lib/components/table/src/table.js +2 -1
- package/lib/components/table/src/table.js.map +1 -1
- package/lib/components/transfer/index.d.ts +40 -0
- package/lib/components/transfer/src/transfer-panel.vue.d.ts +8 -0
- package/lib/components/transfer/src/transfer.vue.d.ts +40 -0
- package/lib/components/tree-v2/index.d.ts +8 -0
- package/lib/components/tree-v2/src/tree-node.vue.d.ts +8 -0
- package/lib/components/tree-v2/src/tree.vue.d.ts +8 -0
- package/lib/components/watermark/index.d.ts +94 -0
- package/lib/components/watermark/index.js +15 -0
- package/lib/components/watermark/index.js.map +1 -0
- package/lib/components/watermark/src/useClips.d.ts +7 -0
- package/lib/components/watermark/src/useClips.js +87 -0
- package/lib/components/watermark/src/useClips.js.map +1 -0
- package/lib/components/watermark/src/utils.d.ts +8 -0
- package/lib/components/watermark/src/utils.js +29 -0
- package/lib/components/watermark/src/utils.js.map +1 -0
- package/lib/components/watermark/src/watermark.d.ts +32 -0
- package/lib/components/watermark/src/watermark.js +37 -0
- package/lib/components/watermark/src/watermark.js.map +1 -0
- package/lib/components/watermark/src/watermark.vue.d.ts +94 -0
- package/lib/components/watermark/src/watermark2.js +206 -0
- package/lib/components/watermark/src/watermark2.js.map +1 -0
- package/lib/components/watermark/style/index.d.ts +0 -0
- package/lib/components/watermark/style/index.js +3 -0
- package/lib/components/watermark/style/index.js.map +1 -0
- package/lib/hooks/use-focus-controller/index.d.ts +6 -1
- package/lib/hooks/use-focus-controller/index.js +5 -2
- package/lib/hooks/use-focus-controller/index.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/package.json +2 -2
- package/tags.json +1 -1
- package/theme-chalk/el-color-picker.css +1 -1
- package/theme-chalk/el-table-v2.css +1 -1
- package/theme-chalk/el-table.css +1 -1
- package/theme-chalk/index.css +1 -1
- package/theme-chalk/src/color-picker.scss +8 -2
- package/theme-chalk/src/common/var.scss +1 -0
- package/theme-chalk/src/table.scss +16 -9
- package/web-types.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const FontGap = 3;
|
|
2
|
+
function prepareCanvas(width, height, ratio = 1) {
|
|
3
|
+
const canvas = document.createElement("canvas");
|
|
4
|
+
const ctx = canvas.getContext("2d");
|
|
5
|
+
const realWidth = width * ratio;
|
|
6
|
+
const realHeight = height * ratio;
|
|
7
|
+
canvas.setAttribute("width", `${realWidth}px`);
|
|
8
|
+
canvas.setAttribute("height", `${realHeight}px`);
|
|
9
|
+
ctx.save();
|
|
10
|
+
return [ctx, canvas, realWidth, realHeight];
|
|
11
|
+
}
|
|
12
|
+
function useClips() {
|
|
13
|
+
function getClips(content, rotate, ratio, width, height, font, gapX, gapY) {
|
|
14
|
+
const [ctx, canvas, contentWidth, contentHeight] = prepareCanvas(width, height, ratio);
|
|
15
|
+
if (content instanceof HTMLImageElement) {
|
|
16
|
+
ctx.drawImage(content, 0, 0, contentWidth, contentHeight);
|
|
17
|
+
} else {
|
|
18
|
+
const { color, fontSize, fontStyle, fontWeight, fontFamily } = font;
|
|
19
|
+
const mergedFontSize = Number(fontSize) * ratio;
|
|
20
|
+
ctx.font = `${fontStyle} normal ${fontWeight} ${mergedFontSize}px/${height}px ${fontFamily}`;
|
|
21
|
+
ctx.fillStyle = color;
|
|
22
|
+
ctx.textAlign = "center";
|
|
23
|
+
ctx.textBaseline = "top";
|
|
24
|
+
const contents = Array.isArray(content) ? content : [content];
|
|
25
|
+
contents == null ? void 0 : contents.forEach((item, index) => {
|
|
26
|
+
ctx.fillText(item != null ? item : "", contentWidth / 2, index * (mergedFontSize + FontGap * ratio));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const angle = Math.PI / 180 * Number(rotate);
|
|
30
|
+
const maxSize = Math.max(width, height);
|
|
31
|
+
const [rCtx, rCanvas, realMaxSize] = prepareCanvas(maxSize, maxSize, ratio);
|
|
32
|
+
rCtx.translate(realMaxSize / 2, realMaxSize / 2);
|
|
33
|
+
rCtx.rotate(angle);
|
|
34
|
+
if (contentWidth > 0 && contentHeight > 0) {
|
|
35
|
+
rCtx.drawImage(canvas, -contentWidth / 2, -contentHeight / 2);
|
|
36
|
+
}
|
|
37
|
+
function getRotatePos(x, y) {
|
|
38
|
+
const targetX = x * Math.cos(angle) - y * Math.sin(angle);
|
|
39
|
+
const targetY = x * Math.sin(angle) + y * Math.cos(angle);
|
|
40
|
+
return [targetX, targetY];
|
|
41
|
+
}
|
|
42
|
+
let left = 0;
|
|
43
|
+
let right = 0;
|
|
44
|
+
let top = 0;
|
|
45
|
+
let bottom = 0;
|
|
46
|
+
const halfWidth = contentWidth / 2;
|
|
47
|
+
const halfHeight = contentHeight / 2;
|
|
48
|
+
const points = [
|
|
49
|
+
[0 - halfWidth, 0 - halfHeight],
|
|
50
|
+
[0 + halfWidth, 0 - halfHeight],
|
|
51
|
+
[0 + halfWidth, 0 + halfHeight],
|
|
52
|
+
[0 - halfWidth, 0 + halfHeight]
|
|
53
|
+
];
|
|
54
|
+
points.forEach(([x, y]) => {
|
|
55
|
+
const [targetX, targetY] = getRotatePos(x, y);
|
|
56
|
+
left = Math.min(left, targetX);
|
|
57
|
+
right = Math.max(right, targetX);
|
|
58
|
+
top = Math.min(top, targetY);
|
|
59
|
+
bottom = Math.max(bottom, targetY);
|
|
60
|
+
});
|
|
61
|
+
const cutLeft = left + realMaxSize / 2;
|
|
62
|
+
const cutTop = top + realMaxSize / 2;
|
|
63
|
+
const cutWidth = right - left;
|
|
64
|
+
const cutHeight = bottom - top;
|
|
65
|
+
const realGapX = gapX * ratio;
|
|
66
|
+
const realGapY = gapY * ratio;
|
|
67
|
+
const filledWidth = (cutWidth + realGapX) * 2;
|
|
68
|
+
const filledHeight = cutHeight + realGapY;
|
|
69
|
+
const [fCtx, fCanvas] = prepareCanvas(filledWidth, filledHeight);
|
|
70
|
+
function drawImg(targetX = 0, targetY = 0) {
|
|
71
|
+
fCtx.drawImage(rCanvas, cutLeft, cutTop, cutWidth, cutHeight, targetX, targetY, cutWidth, cutHeight);
|
|
72
|
+
}
|
|
73
|
+
drawImg();
|
|
74
|
+
drawImg(cutWidth + realGapX, -cutHeight / 2 - realGapY / 2);
|
|
75
|
+
drawImg(cutWidth + realGapX, +cutHeight / 2 + realGapY / 2);
|
|
76
|
+
return [fCanvas.toDataURL(), filledWidth / ratio, filledHeight / ratio];
|
|
77
|
+
}
|
|
78
|
+
return getClips;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { FontGap, useClips as default };
|
|
82
|
+
//# sourceMappingURL=useClips.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useClips.mjs","sources":["../../../../../../packages/components/watermark/src/useClips.ts"],"sourcesContent":["import type { WatermarkProps } from './watermark'\n\nexport const FontGap = 3\n\nfunction prepareCanvas(\n width: number,\n height: number,\n ratio = 1\n): [\n ctx: CanvasRenderingContext2D,\n canvas: HTMLCanvasElement,\n realWidth: number,\n realHeight: number\n] {\n const canvas = document.createElement('canvas')\n const ctx = canvas.getContext('2d')!\n const realWidth = width * ratio\n const realHeight = height * ratio\n canvas.setAttribute('width', `${realWidth}px`)\n canvas.setAttribute('height', `${realHeight}px`)\n ctx.save()\n\n return [ctx, canvas, realWidth, realHeight]\n}\n\n/**\n * Get the clips of text content.\n * This is a lazy hook function since SSR no need this\n */\nexport default function useClips() {\n // Get single clips\n function getClips(\n content: NonNullable<WatermarkProps['content']> | HTMLImageElement,\n rotate: number,\n ratio: number,\n width: number,\n height: number,\n font: Required<NonNullable<WatermarkProps['font']>>,\n gapX: number,\n gapY: number\n ): [dataURL: string, finalWidth: number, finalHeight: number] {\n // ================= Text / Image =================\n const [ctx, canvas, contentWidth, contentHeight] = prepareCanvas(\n width,\n height,\n ratio\n )\n\n if (content instanceof HTMLImageElement) {\n // Image\n ctx.drawImage(content, 0, 0, contentWidth, contentHeight)\n } else {\n // Text\n const { color, fontSize, fontStyle, fontWeight, fontFamily } = font\n const mergedFontSize = Number(fontSize) * ratio\n\n ctx.font = `${fontStyle} normal ${fontWeight} ${mergedFontSize}px/${height}px ${fontFamily}`\n ctx.fillStyle = color\n ctx.textAlign = 'center'\n ctx.textBaseline = 'top'\n const contents = Array.isArray(content) ? content : [content]\n contents?.forEach((item, index) => {\n ctx.fillText(\n item ?? '',\n contentWidth / 2,\n index * (mergedFontSize + FontGap * ratio)\n )\n })\n }\n\n // ==================== Rotate ====================\n const angle = (Math.PI / 180) * Number(rotate)\n const maxSize = Math.max(width, height)\n const [rCtx, rCanvas, realMaxSize] = prepareCanvas(maxSize, maxSize, ratio)\n\n // Copy from `ctx` and rotate\n rCtx.translate(realMaxSize / 2, realMaxSize / 2)\n rCtx.rotate(angle)\n if (contentWidth > 0 && contentHeight > 0) {\n rCtx.drawImage(canvas, -contentWidth / 2, -contentHeight / 2)\n }\n\n // Get boundary of rotated text\n function getRotatePos(x: number, y: number) {\n const targetX = x * Math.cos(angle) - y * Math.sin(angle)\n const targetY = x * Math.sin(angle) + y * Math.cos(angle)\n return [targetX, targetY]\n }\n\n let left = 0\n let right = 0\n let top = 0\n let bottom = 0\n\n const halfWidth = contentWidth / 2\n const halfHeight = contentHeight / 2\n const points = [\n [0 - halfWidth, 0 - halfHeight],\n [0 + halfWidth, 0 - halfHeight],\n [0 + halfWidth, 0 + halfHeight],\n [0 - halfWidth, 0 + halfHeight],\n ]\n points.forEach(([x, y]) => {\n const [targetX, targetY] = getRotatePos(x, y)\n left = Math.min(left, targetX)\n right = Math.max(right, targetX)\n top = Math.min(top, targetY)\n bottom = Math.max(bottom, targetY)\n })\n\n const cutLeft = left + realMaxSize / 2\n const cutTop = top + realMaxSize / 2\n const cutWidth = right - left\n const cutHeight = bottom - top\n\n // ================ Fill Alternate ================\n const realGapX = gapX * ratio\n const realGapY = gapY * ratio\n const filledWidth = (cutWidth + realGapX) * 2\n const filledHeight = cutHeight + realGapY\n\n const [fCtx, fCanvas] = prepareCanvas(filledWidth, filledHeight)\n\n function drawImg(targetX = 0, targetY = 0) {\n fCtx.drawImage(\n rCanvas,\n cutLeft,\n cutTop,\n cutWidth,\n cutHeight,\n targetX,\n targetY,\n cutWidth,\n cutHeight\n )\n }\n drawImg()\n drawImg(cutWidth + realGapX, -cutHeight / 2 - realGapY / 2)\n drawImg(cutWidth + realGapX, +cutHeight / 2 + realGapY / 2)\n\n return [fCanvas.toDataURL(), filledWidth / ratio, filledHeight / ratio]\n }\n\n return getClips\n}\n"],"names":[],"mappings":"AAAY,MAAC,OAAO,GAAG,EAAE;AACzB,SAAS,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE;AACjD,EAAE,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AAClD,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACtC,EAAE,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,CAAC;AAClC,EAAE,MAAM,UAAU,GAAG,MAAM,GAAG,KAAK,C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,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,WAAW,GAAG,KAAK,EAAE,YAAY,GAAG,KAAK,CAAC,CAAC;AAC5E,GAAG;AACH,EAAE,OAAO,QAAQ,CAAC;AAClB;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CSSProperties } from 'vue';
|
|
2
|
+
/** converting camel-cased strings to be lowercase and link it with Separato */
|
|
3
|
+
export declare function toLowercaseSeparator(key: string): string;
|
|
4
|
+
export declare function getStyleStr(style: CSSProperties): string;
|
|
5
|
+
/** Returns the ratio of the device's physical pixel resolution to the css pixel resolution */
|
|
6
|
+
export declare function getPixelRatio(): number;
|
|
7
|
+
/** Whether to re-render the watermark */
|
|
8
|
+
export declare const reRendering: (mutation: MutationRecord, watermarkElement?: HTMLElement | undefined) => boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function toLowercaseSeparator(key) {
|
|
2
|
+
return key.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
3
|
+
}
|
|
4
|
+
function getStyleStr(style) {
|
|
5
|
+
return Object.keys(style).map((key) => `${toLowercaseSeparator(key)}: ${style[key]};`).join(" ");
|
|
6
|
+
}
|
|
7
|
+
function getPixelRatio() {
|
|
8
|
+
return window.devicePixelRatio || 1;
|
|
9
|
+
}
|
|
10
|
+
const reRendering = (mutation, watermarkElement) => {
|
|
11
|
+
let flag = false;
|
|
12
|
+
if (mutation.removedNodes.length && watermarkElement) {
|
|
13
|
+
flag = Array.from(mutation.removedNodes).includes(watermarkElement);
|
|
14
|
+
}
|
|
15
|
+
if (mutation.type === "attributes" && mutation.target === watermarkElement) {
|
|
16
|
+
flag = true;
|
|
17
|
+
}
|
|
18
|
+
return flag;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { getPixelRatio, getStyleStr, reRendering, toLowercaseSeparator };
|
|
22
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../../../../packages/components/watermark/src/utils.ts"],"sourcesContent":["import type { CSSProperties } from 'vue'\n\n/** converting camel-cased strings to be lowercase and link it with Separato */\nexport function toLowercaseSeparator(key: string) {\n return key.replace(/([A-Z])/g, '-$1').toLowerCase()\n}\n\nexport function getStyleStr(style: CSSProperties): string {\n return Object.keys(style)\n .map(\n (key) =>\n `${toLowercaseSeparator(key)}: ${style[key as keyof CSSProperties]};`\n )\n .join(' ')\n}\n\n/** Returns the ratio of the device's physical pixel resolution to the css pixel resolution */\nexport function getPixelRatio() {\n return window.devicePixelRatio || 1\n}\n\n/** Whether to re-render the watermark */\nexport const reRendering = (\n mutation: MutationRecord,\n watermarkElement?: HTMLElement\n) => {\n let flag = false\n // Whether to delete the watermark node\n if (mutation.removedNodes.length && watermarkElement) {\n flag = Array.from(mutation.removedNodes).includes(watermarkElement)\n }\n // Whether the watermark dom property value has been modified\n if (mutation.type === 'attributes' && mutation.target === watermarkElement) {\n flag = true\n }\n return flag\n}\n"],"names":[],"mappings":"AAAO,SAAS,oBAAoB,CAAC,GAAG,EAAE;AAC1C,EAAE,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AACtD,CAAC;AACM,SAAS,WAAW,CAAC,KAAK,EAAE;AACnC,EAAE,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnG,CAAC;AACM,SAAS,aAAa,GAAG;AAChC,EAAE,OAAO,MAAM,CAAC,gBAAgB,IAAI,CAAC,CAAC;AACtC,CAAC;AACW,MAAC,WAAW,GAAG,CAAC,QAAQ,EAAE,gBAAgB,KAAK;AAC3D,EAAE,IAAI,IAAI,GAAG,KAAK,CAAC;AACnB,EAAE,IAAI,QAAQ,CAAC,YAAY,CAAC,MAAM,IAAI,gBAAgB,EAAE;AACxD,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACxE,GAAG;AACH,EAAE,IAAI,QAAQ,CAAC,IAAI,KAAK,YAAY,IAAI,QAAQ,CAAC,MAAM,KAAK,gBAAgB,EAAE;AAC9E,IAAI,IAAI,GAAG,IAAI,CAAC;AAChB,GAAG;AACH,EAAE,OAAO,IAAI,CAAC;AACd;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ExtractPropTypes } from 'vue';
|
|
2
|
+
import type Watermark from './watermark.vue';
|
|
3
|
+
export interface WatermarkFontType {
|
|
4
|
+
color?: string;
|
|
5
|
+
fontSize?: number | string;
|
|
6
|
+
fontWeight?: 'normal' | 'light' | 'weight' | number;
|
|
7
|
+
fontStyle?: 'none' | 'normal' | 'italic' | 'oblique';
|
|
8
|
+
fontFamily?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const watermarkProps: {
|
|
11
|
+
readonly zIndex: import("@element-plus/nightly/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 9, boolean>;
|
|
12
|
+
readonly rotate: import("@element-plus/nightly/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, -22, boolean>;
|
|
13
|
+
readonly width: NumberConstructor;
|
|
14
|
+
readonly height: NumberConstructor;
|
|
15
|
+
readonly image: StringConstructor;
|
|
16
|
+
readonly content: import("@element-plus/nightly/es/utils").EpPropFinalized<(new (...args: any[]) => (string | string[]) & {}) | (() => string | string[]) | ((new (...args: any[]) => (string | string[]) & {}) | (() => string | string[]))[], unknown, unknown, "Element Plus", boolean>;
|
|
17
|
+
readonly font: {
|
|
18
|
+
readonly type: import("vue").PropType<WatermarkFontType>;
|
|
19
|
+
readonly required: false;
|
|
20
|
+
readonly validator: ((val: unknown) => boolean) | undefined;
|
|
21
|
+
__epPropKey: true;
|
|
22
|
+
};
|
|
23
|
+
readonly gap: import("@element-plus/nightly/es/utils").EpPropFinalized<(new (...args: any[]) => [number, number]) | (() => [number, number]) | ((new (...args: any[]) => [number, number]) | (() => [number, number]))[], unknown, unknown, () => number[], boolean>;
|
|
24
|
+
readonly offset: {
|
|
25
|
+
readonly type: import("vue").PropType<[number, number]>;
|
|
26
|
+
readonly required: false;
|
|
27
|
+
readonly validator: ((val: unknown) => boolean) | undefined;
|
|
28
|
+
__epPropKey: true;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export declare type WatermarkProps = ExtractPropTypes<typeof watermarkProps>;
|
|
32
|
+
export declare type WatermarkInstance = InstanceType<typeof Watermark>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import '../../../utils/index.mjs';
|
|
2
|
+
import { buildProps, definePropType } from '../../../utils/vue/props/runtime.mjs';
|
|
3
|
+
|
|
4
|
+
const watermarkProps = buildProps({
|
|
5
|
+
zIndex: {
|
|
6
|
+
type: Number,
|
|
7
|
+
default: 9
|
|
8
|
+
},
|
|
9
|
+
rotate: {
|
|
10
|
+
type: Number,
|
|
11
|
+
default: -22
|
|
12
|
+
},
|
|
13
|
+
width: Number,
|
|
14
|
+
height: Number,
|
|
15
|
+
image: String,
|
|
16
|
+
content: {
|
|
17
|
+
type: definePropType([String, Array]),
|
|
18
|
+
default: "Element Plus"
|
|
19
|
+
},
|
|
20
|
+
font: {
|
|
21
|
+
type: definePropType(Object)
|
|
22
|
+
},
|
|
23
|
+
gap: {
|
|
24
|
+
type: definePropType(Array),
|
|
25
|
+
default: () => [100, 100]
|
|
26
|
+
},
|
|
27
|
+
offset: {
|
|
28
|
+
type: definePropType(Array)
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export { watermarkProps };
|
|
33
|
+
//# sourceMappingURL=watermark.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watermark.mjs","sources":["../../../../../../packages/components/watermark/src/watermark.ts"],"sourcesContent":["import { buildProps, definePropType } from '@element-plus/utils'\n\nimport type { ExtractPropTypes } from 'vue'\nimport type Watermark from './watermark.vue'\n\nexport interface WatermarkFontType {\n color?: string\n fontSize?: number | string\n fontWeight?: 'normal' | 'light' | 'weight' | number\n fontStyle?: 'none' | 'normal' | 'italic' | 'oblique'\n fontFamily?: string\n}\n\nexport const watermarkProps = buildProps({\n /**\n * @description The z-index of the appended watermark element\n */\n zIndex: {\n type: Number,\n default: 9,\n },\n /**\n * @description The rotation angle of the watermark\n */\n rotate: {\n type: Number,\n default: -22,\n },\n /**\n * @description The width of the watermark\n */\n width: Number,\n /**\n * @description The height of the watermark\n */\n height: Number,\n /**\n * @description Image source, it is recommended to export 2x or 3x image, high priority (support base64 format)\n */\n image: String,\n /**\n * @description Watermark text content\n */\n content: {\n type: definePropType<string | string[]>([String, Array]),\n default: 'Element Plus',\n },\n /**\n * @description Text style\n */\n font: {\n type: definePropType<WatermarkFontType>(Object),\n },\n /**\n * @description The spacing between watermarks\n */\n gap: {\n type: definePropType<[number, number]>(Array),\n default: () => [100, 100],\n },\n /**\n * @description The offset of the watermark from the upper left corner of the container. The default is gap/2\n */\n offset: {\n type: definePropType<[number, number]>(Array),\n },\n} as const)\n\nexport type WatermarkProps = ExtractPropTypes<typeof watermarkProps>\nexport type WatermarkInstance = InstanceType<typeof Watermark>\n"],"names":[],"mappings":";;;AACY,MAAC,cAAc,GAAG,UAAU,CAAC;AACzC,EAAE,MAAM,EAAE;AACV,IAAI,IAAI,EAAE,MAAM;AAChB,IAAI,OAAO,EAAE,CAAC;AACd,GAAG;AACH,EAAE,MAAM,EAAE;AACV,IAAI,IAAI,EAAE,MAAM;AAChB,IAAI,OAAO,EAAE,CAAC,EAAE;AAChB,GAAG;AACH,EAAE,KAAK,EAAE,MAAM;AACf,EAAE,MAAM,EAAE,MAAM;AAChB,EAAE,KAAK,EAAE,MAAM;AACf,EAAE,OAAO,EAAE;AACX,IAAI,IAAI,EAAE,cAAc,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACzC,IAAI,OAAO,EAAE,cAAc;AAC3B,GAAG;AACH,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC;AAChC,GAAG;AACH,EAAE,GAAG,EAAE;AACP,IAAI,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC;AAC/B,IAAI,OAAO,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC;AAC7B,GAAG;AACH,EAAE,MAAM,EAAE;AACV,IAAI,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC;AAC/B,GAAG;AACH,CAAC;;;;"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { CSSProperties } from 'vue';
|
|
2
|
+
declare const _default: import("vue").DefineComponent<{
|
|
3
|
+
readonly zIndex: import("../../../utils").EpPropFinalized<NumberConstructor, unknown, unknown, 9, boolean>;
|
|
4
|
+
readonly rotate: import("../../../utils").EpPropFinalized<NumberConstructor, unknown, unknown, -22, boolean>;
|
|
5
|
+
readonly width: NumberConstructor;
|
|
6
|
+
readonly height: NumberConstructor;
|
|
7
|
+
readonly image: StringConstructor;
|
|
8
|
+
readonly content: import("../../../utils").EpPropFinalized<(new (...args: any[]) => (string | string[]) & {}) | (() => string | string[]) | ((new (...args: any[]) => (string | string[]) & {}) | (() => string | string[]))[], unknown, unknown, "Element Plus", boolean>;
|
|
9
|
+
readonly font: {
|
|
10
|
+
readonly type: import("vue").PropType<import("./watermark").WatermarkFontType>;
|
|
11
|
+
readonly required: false;
|
|
12
|
+
readonly validator: ((val: unknown) => boolean) | undefined;
|
|
13
|
+
__epPropKey: true;
|
|
14
|
+
};
|
|
15
|
+
readonly gap: import("../../../utils").EpPropFinalized<(new (...args: any[]) => [number, number]) | (() => [number, number]) | ((new (...args: any[]) => [number, number]) | (() => [number, number]))[], unknown, unknown, () => number[], boolean>;
|
|
16
|
+
readonly offset: {
|
|
17
|
+
readonly type: import("vue").PropType<[number, number]>;
|
|
18
|
+
readonly required: false;
|
|
19
|
+
readonly validator: ((val: unknown) => boolean) | undefined;
|
|
20
|
+
__epPropKey: true;
|
|
21
|
+
};
|
|
22
|
+
}, {
|
|
23
|
+
style: CSSProperties;
|
|
24
|
+
props: Readonly<import("@vue/shared").LooseRequired<Readonly<import("vue").ExtractPropTypes<{
|
|
25
|
+
readonly zIndex: import("../../../utils").EpPropFinalized<NumberConstructor, unknown, unknown, 9, boolean>;
|
|
26
|
+
readonly rotate: import("../../../utils").EpPropFinalized<NumberConstructor, unknown, unknown, -22, boolean>;
|
|
27
|
+
readonly width: NumberConstructor;
|
|
28
|
+
readonly height: NumberConstructor;
|
|
29
|
+
readonly image: StringConstructor;
|
|
30
|
+
readonly content: import("../../../utils").EpPropFinalized<(new (...args: any[]) => (string | string[]) & {}) | (() => string | string[]) | ((new (...args: any[]) => (string | string[]) & {}) | (() => string | string[]))[], unknown, unknown, "Element Plus", boolean>;
|
|
31
|
+
readonly font: {
|
|
32
|
+
readonly type: import("vue").PropType<import("./watermark").WatermarkFontType>;
|
|
33
|
+
readonly required: false;
|
|
34
|
+
readonly validator: ((val: unknown) => boolean) | undefined;
|
|
35
|
+
__epPropKey: true;
|
|
36
|
+
};
|
|
37
|
+
readonly gap: import("../../../utils").EpPropFinalized<(new (...args: any[]) => [number, number]) | (() => [number, number]) | ((new (...args: any[]) => [number, number]) | (() => [number, number]))[], unknown, unknown, () => number[], boolean>;
|
|
38
|
+
readonly offset: {
|
|
39
|
+
readonly type: import("vue").PropType<[number, number]>;
|
|
40
|
+
readonly required: false;
|
|
41
|
+
readonly validator: ((val: unknown) => boolean) | undefined;
|
|
42
|
+
__epPropKey: true;
|
|
43
|
+
};
|
|
44
|
+
}>> & {
|
|
45
|
+
[x: string & `on${string}`]: ((...args: any[]) => any) | ((...args: unknown[]) => any) | undefined;
|
|
46
|
+
}>>;
|
|
47
|
+
color: import("vue").ComputedRef<string>;
|
|
48
|
+
fontSize: import("vue").ComputedRef<string | number>;
|
|
49
|
+
fontWeight: import("vue").ComputedRef<number | "light" | "normal" | "weight">;
|
|
50
|
+
fontStyle: import("vue").ComputedRef<"none" | "normal" | "italic" | "oblique">;
|
|
51
|
+
fontFamily: import("vue").ComputedRef<string>;
|
|
52
|
+
gapX: import("vue").ComputedRef<number>;
|
|
53
|
+
gapY: import("vue").ComputedRef<number>;
|
|
54
|
+
gapXCenter: import("vue").ComputedRef<number>;
|
|
55
|
+
gapYCenter: import("vue").ComputedRef<number>;
|
|
56
|
+
offsetLeft: import("vue").ComputedRef<number>;
|
|
57
|
+
offsetTop: import("vue").ComputedRef<number>;
|
|
58
|
+
getMarkStyle: () => CSSProperties;
|
|
59
|
+
containerRef: import("vue").ShallowRef<HTMLDivElement | null>;
|
|
60
|
+
watermarkRef: import("vue").ShallowRef<HTMLDivElement | undefined>;
|
|
61
|
+
stopObservation: import("vue").Ref<boolean>;
|
|
62
|
+
destroyWatermark: () => void;
|
|
63
|
+
appendWatermark: (base64Url: string, markWidth: number) => void;
|
|
64
|
+
getMarkSize: (ctx: CanvasRenderingContext2D) => readonly [number, number];
|
|
65
|
+
getClips: (content: HTMLImageElement | import("../../../utils").EpPropMergeType<(new (...args: any[]) => (string | string[]) & {}) | (() => string | string[]) | ((new (...args: any[]) => (string | string[]) & {}) | (() => string | string[]))[], unknown, unknown>, rotate: number, ratio: number, width: number, height: number, font: Required<import("./watermark").WatermarkFontType>, gapX: number, gapY: number) => [dataURL: string, finalWidth: number, finalHeight: number];
|
|
66
|
+
renderWatermark: () => void;
|
|
67
|
+
onMutate: (mutations: MutationRecord[]) => void;
|
|
68
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
69
|
+
readonly zIndex: import("../../../utils").EpPropFinalized<NumberConstructor, unknown, unknown, 9, boolean>;
|
|
70
|
+
readonly rotate: import("../../../utils").EpPropFinalized<NumberConstructor, unknown, unknown, -22, boolean>;
|
|
71
|
+
readonly width: NumberConstructor;
|
|
72
|
+
readonly height: NumberConstructor;
|
|
73
|
+
readonly image: StringConstructor;
|
|
74
|
+
readonly content: import("../../../utils").EpPropFinalized<(new (...args: any[]) => (string | string[]) & {}) | (() => string | string[]) | ((new (...args: any[]) => (string | string[]) & {}) | (() => string | string[]))[], unknown, unknown, "Element Plus", boolean>;
|
|
75
|
+
readonly font: {
|
|
76
|
+
readonly type: import("vue").PropType<import("./watermark").WatermarkFontType>;
|
|
77
|
+
readonly required: false;
|
|
78
|
+
readonly validator: ((val: unknown) => boolean) | undefined;
|
|
79
|
+
__epPropKey: true;
|
|
80
|
+
};
|
|
81
|
+
readonly gap: import("../../../utils").EpPropFinalized<(new (...args: any[]) => [number, number]) | (() => [number, number]) | ((new (...args: any[]) => [number, number]) | (() => [number, number]))[], unknown, unknown, () => number[], boolean>;
|
|
82
|
+
readonly offset: {
|
|
83
|
+
readonly type: import("vue").PropType<[number, number]>;
|
|
84
|
+
readonly required: false;
|
|
85
|
+
readonly validator: ((val: unknown) => boolean) | undefined;
|
|
86
|
+
__epPropKey: true;
|
|
87
|
+
};
|
|
88
|
+
}>>, {
|
|
89
|
+
readonly zIndex: number;
|
|
90
|
+
readonly content: import("../../../utils").EpPropMergeType<(new (...args: any[]) => (string | string[]) & {}) | (() => string | string[]) | ((new (...args: any[]) => (string | string[]) & {}) | (() => string | string[]))[], unknown, unknown>;
|
|
91
|
+
readonly rotate: number;
|
|
92
|
+
readonly gap: [number, number];
|
|
93
|
+
}>;
|
|
94
|
+
export default _default;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { defineComponent, computed, shallowRef, ref, onMounted, watch, onBeforeUnmount, openBlock, createElementBlock, normalizeStyle, renderSlot } from 'vue';
|
|
2
|
+
import { useMutationObserver } from '@vueuse/core';
|
|
3
|
+
import { watermarkProps } from './watermark.mjs';
|
|
4
|
+
import { getStyleStr, getPixelRatio, reRendering } from './utils.mjs';
|
|
5
|
+
import useClips, { FontGap } from './useClips.mjs';
|
|
6
|
+
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
|
|
7
|
+
|
|
8
|
+
const __default__ = defineComponent({
|
|
9
|
+
name: "ElWatermark"
|
|
10
|
+
});
|
|
11
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
12
|
+
...__default__,
|
|
13
|
+
props: watermarkProps,
|
|
14
|
+
setup(__props) {
|
|
15
|
+
const props = __props;
|
|
16
|
+
const style = {
|
|
17
|
+
position: "relative"
|
|
18
|
+
};
|
|
19
|
+
const color = computed(() => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
return (_b = (_a = props.font) == null ? void 0 : _a.color) != null ? _b : "rgba(0,0,0,.15)";
|
|
22
|
+
});
|
|
23
|
+
const fontSize = computed(() => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
return (_b = (_a = props.font) == null ? void 0 : _a.fontSize) != null ? _b : 16;
|
|
26
|
+
});
|
|
27
|
+
const fontWeight = computed(() => {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
return (_b = (_a = props.font) == null ? void 0 : _a.fontWeight) != null ? _b : "normal";
|
|
30
|
+
});
|
|
31
|
+
const fontStyle = computed(() => {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
return (_b = (_a = props.font) == null ? void 0 : _a.fontStyle) != null ? _b : "normal";
|
|
34
|
+
});
|
|
35
|
+
const fontFamily = computed(() => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
return (_b = (_a = props.font) == null ? void 0 : _a.fontFamily) != null ? _b : "sans-serif";
|
|
38
|
+
});
|
|
39
|
+
const gapX = computed(() => props.gap[0]);
|
|
40
|
+
const gapY = computed(() => props.gap[1]);
|
|
41
|
+
const gapXCenter = computed(() => gapX.value / 2);
|
|
42
|
+
const gapYCenter = computed(() => gapY.value / 2);
|
|
43
|
+
const offsetLeft = computed(() => {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
return (_b = (_a = props.offset) == null ? void 0 : _a[0]) != null ? _b : gapXCenter.value;
|
|
46
|
+
});
|
|
47
|
+
const offsetTop = computed(() => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
return (_b = (_a = props.offset) == null ? void 0 : _a[1]) != null ? _b : gapYCenter.value;
|
|
50
|
+
});
|
|
51
|
+
const getMarkStyle = () => {
|
|
52
|
+
const markStyle = {
|
|
53
|
+
zIndex: props.zIndex,
|
|
54
|
+
position: "absolute",
|
|
55
|
+
left: 0,
|
|
56
|
+
top: 0,
|
|
57
|
+
width: "100%",
|
|
58
|
+
height: "100%",
|
|
59
|
+
pointerEvents: "none",
|
|
60
|
+
backgroundRepeat: "repeat"
|
|
61
|
+
};
|
|
62
|
+
let positionLeft = offsetLeft.value - gapXCenter.value;
|
|
63
|
+
let positionTop = offsetTop.value - gapYCenter.value;
|
|
64
|
+
if (positionLeft > 0) {
|
|
65
|
+
markStyle.left = `${positionLeft}px`;
|
|
66
|
+
markStyle.width = `calc(100% - ${positionLeft}px)`;
|
|
67
|
+
positionLeft = 0;
|
|
68
|
+
}
|
|
69
|
+
if (positionTop > 0) {
|
|
70
|
+
markStyle.top = `${positionTop}px`;
|
|
71
|
+
markStyle.height = `calc(100% - ${positionTop}px)`;
|
|
72
|
+
positionTop = 0;
|
|
73
|
+
}
|
|
74
|
+
markStyle.backgroundPosition = `${positionLeft}px ${positionTop}px`;
|
|
75
|
+
return markStyle;
|
|
76
|
+
};
|
|
77
|
+
const containerRef = shallowRef(null);
|
|
78
|
+
const watermarkRef = shallowRef();
|
|
79
|
+
const stopObservation = ref(false);
|
|
80
|
+
const destroyWatermark = () => {
|
|
81
|
+
if (watermarkRef.value) {
|
|
82
|
+
watermarkRef.value.remove();
|
|
83
|
+
watermarkRef.value = void 0;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const appendWatermark = (base64Url, markWidth) => {
|
|
87
|
+
var _a;
|
|
88
|
+
if (containerRef.value && watermarkRef.value) {
|
|
89
|
+
stopObservation.value = true;
|
|
90
|
+
watermarkRef.value.setAttribute("style", getStyleStr({
|
|
91
|
+
...getMarkStyle(),
|
|
92
|
+
backgroundImage: `url('${base64Url}')`,
|
|
93
|
+
backgroundSize: `${Math.floor(markWidth)}px`
|
|
94
|
+
}));
|
|
95
|
+
(_a = containerRef.value) == null ? void 0 : _a.append(watermarkRef.value);
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
stopObservation.value = false;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const getMarkSize = (ctx) => {
|
|
102
|
+
let defaultWidth = 120;
|
|
103
|
+
let defaultHeight = 64;
|
|
104
|
+
const image = props.image;
|
|
105
|
+
const content = props.content;
|
|
106
|
+
const width = props.width;
|
|
107
|
+
const height = props.height;
|
|
108
|
+
if (!image && ctx.measureText) {
|
|
109
|
+
ctx.font = `${Number(fontSize.value)}px ${fontFamily.value}`;
|
|
110
|
+
const contents = Array.isArray(content) ? content : [content];
|
|
111
|
+
const sizes = contents.map((item) => {
|
|
112
|
+
const metrics = ctx.measureText(item);
|
|
113
|
+
return [
|
|
114
|
+
metrics.width,
|
|
115
|
+
metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent
|
|
116
|
+
];
|
|
117
|
+
});
|
|
118
|
+
defaultWidth = Math.ceil(Math.max(...sizes.map((size) => size[0])));
|
|
119
|
+
defaultHeight = Math.ceil(Math.max(...sizes.map((size) => size[1]))) * contents.length + (contents.length - 1) * FontGap;
|
|
120
|
+
}
|
|
121
|
+
return [width != null ? width : defaultWidth, height != null ? height : defaultHeight];
|
|
122
|
+
};
|
|
123
|
+
const getClips = useClips();
|
|
124
|
+
const renderWatermark = () => {
|
|
125
|
+
const canvas = document.createElement("canvas");
|
|
126
|
+
const ctx = canvas.getContext("2d");
|
|
127
|
+
const image = props.image;
|
|
128
|
+
const content = props.content;
|
|
129
|
+
const rotate = props.rotate;
|
|
130
|
+
if (ctx) {
|
|
131
|
+
if (!watermarkRef.value) {
|
|
132
|
+
watermarkRef.value = document.createElement("div");
|
|
133
|
+
}
|
|
134
|
+
const ratio = getPixelRatio();
|
|
135
|
+
const [markWidth, markHeight] = getMarkSize(ctx);
|
|
136
|
+
const drawCanvas = (drawContent) => {
|
|
137
|
+
const [textClips, clipWidth] = getClips(drawContent || "", rotate, ratio, markWidth, markHeight, {
|
|
138
|
+
color: color.value,
|
|
139
|
+
fontSize: fontSize.value,
|
|
140
|
+
fontStyle: fontStyle.value,
|
|
141
|
+
fontWeight: fontWeight.value,
|
|
142
|
+
fontFamily: fontFamily.value
|
|
143
|
+
}, gapX.value, gapY.value);
|
|
144
|
+
appendWatermark(textClips, clipWidth);
|
|
145
|
+
};
|
|
146
|
+
if (image) {
|
|
147
|
+
const img = new Image();
|
|
148
|
+
img.onload = () => {
|
|
149
|
+
drawCanvas(img);
|
|
150
|
+
};
|
|
151
|
+
img.onerror = () => {
|
|
152
|
+
drawCanvas(content);
|
|
153
|
+
};
|
|
154
|
+
img.crossOrigin = "anonymous";
|
|
155
|
+
img.referrerPolicy = "no-referrer";
|
|
156
|
+
img.src = image;
|
|
157
|
+
} else {
|
|
158
|
+
drawCanvas(content);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
onMounted(() => {
|
|
163
|
+
renderWatermark();
|
|
164
|
+
});
|
|
165
|
+
watch(() => props, () => {
|
|
166
|
+
renderWatermark();
|
|
167
|
+
}, {
|
|
168
|
+
deep: true,
|
|
169
|
+
flush: "post"
|
|
170
|
+
});
|
|
171
|
+
onBeforeUnmount(() => {
|
|
172
|
+
destroyWatermark();
|
|
173
|
+
});
|
|
174
|
+
const onMutate = (mutations) => {
|
|
175
|
+
if (stopObservation.value) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
mutations.forEach((mutation) => {
|
|
179
|
+
if (reRendering(mutation, watermarkRef.value)) {
|
|
180
|
+
destroyWatermark();
|
|
181
|
+
renderWatermark();
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
useMutationObserver(containerRef, onMutate, {
|
|
186
|
+
attributes: true
|
|
187
|
+
});
|
|
188
|
+
return (_ctx, _cache) => {
|
|
189
|
+
return openBlock(), createElementBlock("div", {
|
|
190
|
+
ref_key: "containerRef",
|
|
191
|
+
ref: containerRef,
|
|
192
|
+
style: normalizeStyle([style])
|
|
193
|
+
}, [
|
|
194
|
+
renderSlot(_ctx.$slots, "default")
|
|
195
|
+
], 4);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
var Watermark = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/watermark/src/watermark.vue"]]);
|
|
200
|
+
|
|
201
|
+
export { Watermark as default };
|
|
202
|
+
//# sourceMappingURL=watermark2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watermark2.mjs","sources":["../../../../../../packages/components/watermark/src/watermark.vue"],"sourcesContent":["<template>\n <div ref=\"containerRef\" :style=\"[style]\">\n <slot />\n </div>\n</template>\n\n<script lang=\"ts\" setup>\nimport {\n computed,\n onBeforeUnmount,\n onMounted,\n ref,\n shallowRef,\n watch,\n} from 'vue'\nimport { useMutationObserver } from '@vueuse/core'\nimport { watermarkProps } from './watermark'\nimport { getPixelRatio, getStyleStr, reRendering } from './utils'\nimport useClips, { FontGap } from './useClips'\nimport type { WatermarkProps } from './watermark'\nimport type { CSSProperties } from 'vue'\n\ndefineOptions({\n name: 'ElWatermark',\n})\n\nconst style: CSSProperties = {\n position: 'relative',\n}\n\nconst props = defineProps(watermarkProps)\nconst color = computed(() => props.font?.color ?? 'rgba(0,0,0,.15)')\nconst fontSize = computed(() => props.font?.fontSize ?? 16)\nconst fontWeight = computed(() => props.font?.fontWeight ?? 'normal')\nconst fontStyle = computed(() => props.font?.fontStyle ?? 'normal')\nconst fontFamily = computed(() => props.font?.fontFamily ?? 'sans-serif')\n\nconst gapX = computed(() => props.gap[0])\nconst gapY = computed(() => props.gap[1])\nconst gapXCenter = computed(() => gapX.value / 2)\nconst gapYCenter = computed(() => gapY.value / 2)\nconst offsetLeft = computed(() => props.offset?.[0] ?? gapXCenter.value)\nconst offsetTop = computed(() => props.offset?.[1] ?? gapYCenter.value)\n\nconst getMarkStyle = () => {\n const markStyle: CSSProperties = {\n zIndex: props.zIndex,\n position: 'absolute',\n left: 0,\n top: 0,\n width: '100%',\n height: '100%',\n pointerEvents: 'none',\n backgroundRepeat: 'repeat',\n }\n\n /** Calculate the style of the offset */\n let positionLeft = offsetLeft.value - gapXCenter.value\n let positionTop = offsetTop.value - gapYCenter.value\n if (positionLeft > 0) {\n markStyle.left = `${positionLeft}px`\n markStyle.width = `calc(100% - ${positionLeft}px)`\n positionLeft = 0\n }\n if (positionTop > 0) {\n markStyle.top = `${positionTop}px`\n markStyle.height = `calc(100% - ${positionTop}px)`\n positionTop = 0\n }\n markStyle.backgroundPosition = `${positionLeft}px ${positionTop}px`\n\n return markStyle\n}\n\nconst containerRef = shallowRef<HTMLDivElement | null>(null)\nconst watermarkRef = shallowRef<HTMLDivElement>()\nconst stopObservation = ref(false)\n\nconst destroyWatermark = () => {\n if (watermarkRef.value) {\n watermarkRef.value.remove()\n watermarkRef.value = undefined\n }\n}\nconst appendWatermark = (base64Url: string, markWidth: number) => {\n if (containerRef.value && watermarkRef.value) {\n stopObservation.value = true\n watermarkRef.value.setAttribute(\n 'style',\n getStyleStr({\n ...getMarkStyle(),\n backgroundImage: `url('${base64Url}')`,\n backgroundSize: `${Math.floor(markWidth)}px`,\n })\n )\n containerRef.value?.append(watermarkRef.value)\n // Delayed execution\n setTimeout(() => {\n stopObservation.value = false\n })\n }\n}\n\n/**\n * Get the width and height of the watermark. The default values are as follows\n * Image: [120, 64]; Content: It's calculated by content;\n */\nconst getMarkSize = (ctx: CanvasRenderingContext2D) => {\n let defaultWidth = 120\n let defaultHeight = 64\n const image = props.image\n const content = props.content\n const width = props.width\n const height = props.height\n if (!image && ctx.measureText) {\n ctx.font = `${Number(fontSize.value)}px ${fontFamily.value}`\n const contents = Array.isArray(content) ? content : [content]\n const sizes = contents.map((item) => {\n const metrics = ctx.measureText(item!)\n\n return [\n metrics.width,\n metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent,\n ]\n })\n defaultWidth = Math.ceil(Math.max(...sizes.map((size) => size[0])))\n defaultHeight =\n Math.ceil(Math.max(...sizes.map((size) => size[1]))) * contents.length +\n (contents.length - 1) * FontGap\n }\n return [width ?? defaultWidth, height ?? defaultHeight] as const\n}\n\nconst getClips = useClips()\n\nconst renderWatermark = () => {\n const canvas = document.createElement('canvas')\n const ctx = canvas.getContext('2d')\n const image = props.image\n const content = props.content\n const rotate = props.rotate\n\n if (ctx) {\n if (!watermarkRef.value) {\n watermarkRef.value = document.createElement('div')\n }\n\n const ratio = getPixelRatio()\n const [markWidth, markHeight] = getMarkSize(ctx)\n\n const drawCanvas = (\n drawContent?: NonNullable<WatermarkProps['content']> | HTMLImageElement\n ) => {\n const [textClips, clipWidth] = getClips(\n drawContent || '',\n rotate,\n ratio,\n markWidth,\n markHeight,\n {\n color: color.value,\n fontSize: fontSize.value,\n fontStyle: fontStyle.value,\n fontWeight: fontWeight.value,\n fontFamily: fontFamily.value,\n },\n gapX.value,\n gapY.value\n )\n\n appendWatermark(textClips, clipWidth)\n }\n\n if (image) {\n const img = new Image()\n img.onload = () => {\n drawCanvas(img)\n }\n img.onerror = () => {\n drawCanvas(content)\n }\n img.crossOrigin = 'anonymous'\n img.referrerPolicy = 'no-referrer'\n img.src = image\n } else {\n drawCanvas(content)\n }\n }\n}\n\nonMounted(() => {\n renderWatermark()\n})\n\nwatch(\n () => props,\n () => {\n renderWatermark()\n },\n {\n deep: true,\n flush: 'post',\n }\n)\n\nonBeforeUnmount(() => {\n destroyWatermark()\n})\n\nconst onMutate = (mutations: MutationRecord[]) => {\n if (stopObservation.value) {\n return\n }\n mutations.forEach((mutation) => {\n if (reRendering(mutation, watermarkRef.value)) {\n destroyWatermark()\n renderWatermark()\n }\n })\n}\n\nuseMutationObserver(containerRef, onMutate, {\n attributes: true,\n})\n</script>\n"],"names":[],"mappings":";;;;;;;mCAsBc,CAAA;AAAA,EACZ,IAAM,EAAA,aAAA;AACR,CAAA,CAAA,CAAA;;;;;;AAEA,IAAA,MAAM,KAAuB,GAAA;AAAA,MAC3B,QAAU,EAAA,UAAA;AAAA,KACZ,CAAA;AAGA,IAAA,MAAM,QAAQ,QAAS,CAAA,MAAM;AAC7B,MAAA,IAAM;AACN,MAAA,mBAA4B,KAAA,CAAA,IAAA,KAAY,IAAA,GAAA,iBAAoB,KAAQ,IAAA,GAAA,EAAA,GAAA,iBAAA,CAAA;AACpE,KAAA,CAAA,CAAA;AACA,IAAA,MAAM,mBAAsB,CAAA,MAAA;AAE5B,MAAA,IAAM,EAAO,EAAA,EAAA,CAAA;AACb,MAAA,OAAa,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,KAAe,CAAA,IAAA,SAAY,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,QAAA,KAAA,IAAA,GAAA,EAAA,GAAA,EAAA,CAAA;AACxC,KAAA,CAAA,CAAA;AACA,IAAA,MAAM,UAAa,GAAA,QAAA,CAAS,MAAM;AAClC,MAAA,IAAM;AACN,MAAA,gBAAkB,GAAS,KAAA,CAAA,IAAA,SAAqB,GAAA,KAAA,CAAA,GAAA,EAAM,WAAW,KAAK,IAAA,GAAA,EAAA,GAAA,QAAA,CAAA;AAEtE,KAAA,CAAA,CAAA;AACE,IAAA,MAAA,SAAiC,GAAA,QAAA,CAAA,MAAA;AAAA,MAAA,UACvB,CAAM;AAAA,MAAA,OACJ,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,KAAA,CAAA,IAAA,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA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AEA,YAAA,UAAsB,CAAA,GAAA,CAAA,CAAA;AACpB,WAAiB,CAAA;AAAA,UAClB,GAAA,CAAA,OAAA,GAAA,MAAA;AAED,YAAM,UAAY,CAAgC,OAAA,CAAA,CAAA;AAChD;AACE,UAAA,GAAA,CAAA,WAAA,GAAA,WAAA,CAAA;AAAA,UACF,GAAA,CAAA,cAAA,GAAA,aAAA,CAAA;AACA,UAAU,GAAA,CAAA,GAAA,GAAA,KAAS,CAAa;AAC9B,SAAA,MAAgB;AACd,UAAiB,UAAA,CAAA,OAAA,CAAA,CAAA;AACjB,SAAgB;AAAA,OAClB;AAAA,KAAA,CACF;AAAC,IACH,SAAA,CAAA,MAAA;AAEA,MAAA,eAAA,EAAA,CAAoB;AAAwB,KAAA,CAC1C,CAAY;AAAA,IACd,KAAC,CAAA,MAAA,KAAA,EAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { ShallowRef } from 'vue';
|
|
2
2
|
interface UseFocusControllerOptions {
|
|
3
3
|
afterFocus?: () => void;
|
|
4
|
+
/**
|
|
5
|
+
* return true to cancel blur
|
|
6
|
+
* @param event FocusEvent
|
|
7
|
+
*/
|
|
8
|
+
beforeBlur?: (event: FocusEvent) => boolean | undefined;
|
|
4
9
|
afterBlur?: () => void;
|
|
5
10
|
}
|
|
6
|
-
export declare function useFocusController<T extends HTMLElement>(target: ShallowRef<T | undefined>, { afterFocus, afterBlur }?: UseFocusControllerOptions): {
|
|
11
|
+
export declare function useFocusController<T extends HTMLElement>(target: ShallowRef<T | undefined>, { afterFocus, beforeBlur, afterBlur }?: UseFocusControllerOptions): {
|
|
7
12
|
wrapperRef: ShallowRef<HTMLElement | undefined>;
|
|
8
13
|
isFocused: import("vue").Ref<boolean>;
|
|
9
14
|
handleFocus: (event: FocusEvent) => void;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { getCurrentInstance, shallowRef, ref, watch } from 'vue';
|
|
2
2
|
import { useEventListener } from '@vueuse/core';
|
|
3
|
+
import '../../utils/index.mjs';
|
|
4
|
+
import { isFunction } from '@vue/shared';
|
|
3
5
|
|
|
4
|
-
function useFocusController(target, { afterFocus, afterBlur } = {}) {
|
|
6
|
+
function useFocusController(target, { afterFocus, beforeBlur, afterBlur } = {}) {
|
|
5
7
|
const instance = getCurrentInstance();
|
|
6
8
|
const { emit } = instance;
|
|
7
9
|
const wrapperRef = shallowRef();
|
|
@@ -15,7 +17,8 @@ function useFocusController(target, { afterFocus, afterBlur } = {}) {
|
|
|
15
17
|
};
|
|
16
18
|
const handleBlur = (event) => {
|
|
17
19
|
var _a;
|
|
18
|
-
|
|
20
|
+
const cancelBlur = isFunction(beforeBlur) ? beforeBlur(event) : false;
|
|
21
|
+
if (cancelBlur || event.relatedTarget && ((_a = wrapperRef.value) == null ? void 0 : _a.contains(event.relatedTarget)))
|
|
19
22
|
return;
|
|
20
23
|
isFocused.value = false;
|
|
21
24
|
emit("blur", event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../../packages/hooks/use-focus-controller/index.ts"],"sourcesContent":["import { getCurrentInstance, ref, shallowRef, watch } from 'vue'\nimport { useEventListener } from '@vueuse/core'\nimport type { ShallowRef } from 'vue'\n\ninterface UseFocusControllerOptions {\n afterFocus?: () => void\n afterBlur?: () => void\n}\n\nexport function useFocusController<T extends HTMLElement>(\n target: ShallowRef<T | undefined>,\n { afterFocus, afterBlur }: UseFocusControllerOptions = {}\n) {\n const instance = getCurrentInstance()!\n const { emit } = instance\n const wrapperRef = shallowRef<HTMLElement>()\n const isFocused = ref(false)\n\n const handleFocus = (event: FocusEvent) => {\n if (isFocused.value) return\n isFocused.value = true\n emit('focus', event)\n afterFocus?.()\n }\n\n const handleBlur = (event: FocusEvent) => {\n if (\n event.relatedTarget &&\n
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../../packages/hooks/use-focus-controller/index.ts"],"sourcesContent":["import { getCurrentInstance, ref, shallowRef, watch } from 'vue'\nimport { useEventListener } from '@vueuse/core'\nimport { isFunction } from '@element-plus/utils'\nimport type { ShallowRef } from 'vue'\n\ninterface UseFocusControllerOptions {\n afterFocus?: () => void\n /**\n * return true to cancel blur\n * @param event FocusEvent\n */\n beforeBlur?: (event: FocusEvent) => boolean | undefined\n afterBlur?: () => void\n}\n\nexport function useFocusController<T extends HTMLElement>(\n target: ShallowRef<T | undefined>,\n { afterFocus, beforeBlur, afterBlur }: UseFocusControllerOptions = {}\n) {\n const instance = getCurrentInstance()!\n const { emit } = instance\n const wrapperRef = shallowRef<HTMLElement>()\n const isFocused = ref(false)\n\n const handleFocus = (event: FocusEvent) => {\n if (isFocused.value) return\n isFocused.value = true\n emit('focus', event)\n afterFocus?.()\n }\n\n const handleBlur = (event: FocusEvent) => {\n const cancelBlur = isFunction(beforeBlur) ? beforeBlur(event) : false\n if (\n cancelBlur ||\n (event.relatedTarget &&\n wrapperRef.value?.contains(event.relatedTarget as Node))\n )\n return\n\n isFocused.value = false\n emit('blur', event)\n afterBlur?.()\n }\n\n const handleClick = () => {\n target.value?.focus()\n }\n\n watch(wrapperRef, (el) => {\n if (el) {\n el.setAttribute('tabindex', '-1')\n }\n })\n\n // TODO: using useEventListener will fail the test\n // useEventListener(target, 'focus', handleFocus)\n // useEventListener(target, 'blur', handleBlur)\n useEventListener(wrapperRef, 'click', handleClick)\n\n return {\n wrapperRef,\n isFocused,\n handleFocus,\n handleBlur,\n }\n}\n"],"names":[],"mappings":";;;;;AAGO,SAAS,kBAAkB,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE;AACvF,EAAE,MAAM,QAAQ,GAAG,kBAAkB,EAAE,CAAC;AACxC,EAAE,MA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,KAAK,CAAC,UAAU,EAAE,CAAC,EAAE,KAAK;AAC5B,IAAI,IAAI,EAAE,EAAE;AACZ,MAAM,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACxC,KAAK;AACL,GAAG,CAAC,CAAC;AACL,EAAE,gBAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AACrD,EAAE,OAAO;AACT,IAAI,UAAU;AACd,IAAI,SAAS;AACb,IAAI,WAAW;AACf,IAAI,UAAU;AACd,GAAG,CAAC;AACJ;;;;"}
|
package/es/index.mjs
CHANGED
|
@@ -72,7 +72,7 @@ export { dialogInjectionKey } from './components/dialog/src/constants.mjs';
|
|
|
72
72
|
export { ElDialog } from './components/dialog/index.mjs';
|
|
73
73
|
export { dividerProps } from './components/divider/src/divider.mjs';
|
|
74
74
|
export { ElDivider } from './components/divider/index.mjs';
|
|
75
|
-
export { drawerEmits, drawerProps } from './components/drawer/src/
|
|
75
|
+
export { drawerEmits, drawerProps } from './components/drawer/src/drawer.mjs';
|
|
76
76
|
export { ElDrawer } from './components/drawer/index.mjs';
|
|
77
77
|
export { DROPDOWN_COLLECTION_INJECTION_KEY, DROPDOWN_COLLECTION_ITEM_INJECTION_KEY, ElCollection, ElCollectionItem, FIRST_KEYS, FIRST_LAST_KEYS, LAST_KEYS, dropdownItemProps, dropdownMenuProps, dropdownProps } from './components/dropdown/src/dropdown.mjs';
|
|
78
78
|
export { DROPDOWN_INJECTION_KEY } from './components/dropdown/src/tokens.mjs';
|
package/es/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.0.
|
|
1
|
+
export declare const version = "0.0.20231011";
|
package/es/version.mjs
CHANGED