zartui 3.1.20 → 3.1.21
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/es/avatar/Avatar.mjs +1 -1
- package/es/icon/index.css +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.mjs +1 -1
- package/es/media-picker/MediaPicker.mjs +1 -4
- package/es/media-picker/util/media-util.d.ts +0 -55
- package/es/media-picker/util/media-util.mjs +1 -203
- package/es/tabs/Tabs.mjs +1 -0
- package/es/tabs/TabsTitle.d.ts +2 -0
- package/es/tabs/TabsTitle.mjs +24 -2
- package/es/uploader/Uploader.d.ts +1 -1
- package/es/uploader/index.d.ts +1 -1
- package/lib/avatar/Avatar.js +1 -1
- package/lib/icon/index.css +1 -1
- package/lib/index.css +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/media-picker/MediaPicker.js +5 -8
- package/lib/media-picker/util/media-util.d.ts +0 -55
- package/lib/media-picker/util/media-util.js +1 -203
- package/lib/tabs/Tabs.js +1 -0
- package/lib/tabs/TabsTitle.d.ts +2 -0
- package/lib/tabs/TabsTitle.js +23 -1
- package/lib/uploader/Uploader.d.ts +1 -1
- package/lib/uploader/index.d.ts +1 -1
- package/lib/web-types.json +1 -1
- package/lib/zartui.cjs.js +57 -1017
- package/lib/zartui.es.js +53 -1013
- package/lib/zartui.js +1116 -648
- package/lib/zartui.min.js +1 -1
- package/package.json +7 -6
- package/es/media-picker/watermark/compress-options.d.ts +0 -5
- package/es/media-picker/watermark/compress-options.mjs +0 -23
- package/es/media-picker/watermark/image-processor.d.ts +0 -12
- package/es/media-picker/watermark/image-processor.mjs +0 -97
- package/es/media-picker/watermark/resize-options.d.ts +0 -4
- package/es/media-picker/watermark/resize-options.mjs +0 -27
- package/es/media-picker/watermark/watermark.d.ts +0 -42
- package/es/media-picker/watermark/watermark.mjs +0 -653
- package/lib/media-picker/watermark/compress-options.d.ts +0 -5
- package/lib/media-picker/watermark/compress-options.js +0 -41
- package/lib/media-picker/watermark/image-processor.d.ts +0 -12
- package/lib/media-picker/watermark/image-processor.js +0 -110
- package/lib/media-picker/watermark/resize-options.d.ts +0 -4
- package/lib/media-picker/watermark/resize-options.js +0 -45
- package/lib/media-picker/watermark/watermark.d.ts +0 -42
- package/lib/media-picker/watermark/watermark.js +0 -664
package/lib/zartui.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
3
|
const vue = require("vue");
|
|
4
4
|
const use = require("@zartui/use");
|
|
5
|
-
const
|
|
5
|
+
const appMediaUtils = require("@egova-mobile/app-media-utils");
|
|
6
6
|
const vue$1 = require("@floating-ui/vue");
|
|
7
7
|
const popperjs = require("@zartui/popperjs");
|
|
8
8
|
const isDef = (val) => val !== void 0 && val !== null;
|
|
@@ -11,20 +11,8 @@ const isObject = (val) => val !== null && typeof val === "object";
|
|
|
11
11
|
const isPromise = (val) => isObject(val) && isFunction(val.then) && isFunction(val.catch);
|
|
12
12
|
const isDate = (val) => Object.prototype.toString.call(val) === "[object Date]" && !Number.isNaN(val.getTime());
|
|
13
13
|
const isNumeric = (val) => typeof val === "number" || /^\d+(\.\d+)?$/.test(val);
|
|
14
|
-
const isString = (val) => typeof val === "string";
|
|
15
|
-
const isValidString = (val) => typeof val === "string" && val !== "";
|
|
16
|
-
const isRegExp = (val) => Object.prototype.toString.call(val).replace(/\[object (\w+)\]/, "$1").toLowerCase() === "regexp";
|
|
17
14
|
const isIOS$1 = () => inBrowser ? /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()) : false;
|
|
18
|
-
const isAndroid = () => inBrowser ? /android/.test(navigator.userAgent.toLowerCase()) : false;
|
|
19
15
|
const isWeixin = () => inBrowser ? /micromessenger/.test(navigator.userAgent.toLowerCase()) : false;
|
|
20
|
-
const getIosVersion = () => {
|
|
21
|
-
const reg = /CPU iPhone OS (.*?) like Mac OS/i;
|
|
22
|
-
const verStr = navigator.userAgent.match(reg);
|
|
23
|
-
if (verStr && verStr[1]) {
|
|
24
|
-
return verStr[1].replace(/_/g, ".");
|
|
25
|
-
}
|
|
26
|
-
return "";
|
|
27
|
-
};
|
|
28
16
|
function noop() {
|
|
29
17
|
}
|
|
30
18
|
const extend = Object.assign;
|
|
@@ -225,7 +213,7 @@ function padZero(num, targetLength = 2) {
|
|
|
225
213
|
}
|
|
226
214
|
return str;
|
|
227
215
|
}
|
|
228
|
-
const clamp
|
|
216
|
+
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
|
|
229
217
|
function trimExtraChar(value, char, regExp) {
|
|
230
218
|
const index = value.indexOf(char);
|
|
231
219
|
if (index === -1) {
|
|
@@ -1617,7 +1605,7 @@ var stdin_default$1I = vue.defineComponent({
|
|
|
1617
1605
|
"style": style.value,
|
|
1618
1606
|
"src": props.src
|
|
1619
1607
|
}, {
|
|
1620
|
-
error: renderText()
|
|
1608
|
+
error: () => renderText()
|
|
1621
1609
|
});
|
|
1622
1610
|
};
|
|
1623
1611
|
}
|
|
@@ -3371,7 +3359,8 @@ var stdin_default$1z = vue.defineComponent({
|
|
|
3371
3359
|
maxWidth: {
|
|
3372
3360
|
type: String,
|
|
3373
3361
|
default: "112px"
|
|
3374
|
-
}
|
|
3362
|
+
},
|
|
3363
|
+
setLine: Function
|
|
3375
3364
|
},
|
|
3376
3365
|
setup(props, {
|
|
3377
3366
|
slots
|
|
@@ -3431,9 +3420,30 @@ var stdin_default$1z = vue.defineComponent({
|
|
|
3431
3420
|
}
|
|
3432
3421
|
return Text;
|
|
3433
3422
|
};
|
|
3423
|
+
const mutationObserver = vue.ref();
|
|
3424
|
+
const dom = vue.ref(null);
|
|
3425
|
+
function mutation() {
|
|
3426
|
+
props.setLine && props.setLine();
|
|
3427
|
+
}
|
|
3428
|
+
vue.onMounted(() => {
|
|
3429
|
+
if (!dom.value) {
|
|
3430
|
+
return;
|
|
3431
|
+
}
|
|
3432
|
+
mutationObserver.value = new MutationObserver(mutation);
|
|
3433
|
+
mutationObserver.value.observe(dom.value, {
|
|
3434
|
+
characterData: true,
|
|
3435
|
+
childList: true,
|
|
3436
|
+
subtree: true
|
|
3437
|
+
});
|
|
3438
|
+
});
|
|
3439
|
+
vue.onBeforeUnmount(() => {
|
|
3440
|
+
var _a, _b;
|
|
3441
|
+
(_b = (_a = mutationObserver.value) == null ? void 0 : _a.unobserve) == null ? void 0 : _b.call(_a, dom.value);
|
|
3442
|
+
});
|
|
3434
3443
|
return () => vue.createVNode("div", {
|
|
3435
3444
|
"id": props.id,
|
|
3436
3445
|
"role": "tab",
|
|
3446
|
+
"ref": dom,
|
|
3437
3447
|
"class": [bem$18([props.type, {
|
|
3438
3448
|
grow: props.scrollable && !props.shrink,
|
|
3439
3449
|
shrink: props.shrink,
|
|
@@ -3526,9 +3536,9 @@ var stdin_default$1y = vue.defineComponent({
|
|
|
3526
3536
|
} = state;
|
|
3527
3537
|
if (pace) {
|
|
3528
3538
|
if (props.loop) {
|
|
3529
|
-
return clamp
|
|
3539
|
+
return clamp(active + pace, -1, count.value);
|
|
3530
3540
|
}
|
|
3531
|
-
return clamp
|
|
3541
|
+
return clamp(active + pace, 0, maxCount.value);
|
|
3532
3542
|
}
|
|
3533
3543
|
return active;
|
|
3534
3544
|
};
|
|
@@ -3539,7 +3549,7 @@ var stdin_default$1y = vue.defineComponent({
|
|
|
3539
3549
|
}
|
|
3540
3550
|
let targetOffset = offset - currentPosition;
|
|
3541
3551
|
if (!props.loop) {
|
|
3542
|
-
targetOffset = clamp
|
|
3552
|
+
targetOffset = clamp(targetOffset, minOffset.value, 0);
|
|
3543
3553
|
}
|
|
3544
3554
|
return targetOffset;
|
|
3545
3555
|
};
|
|
@@ -3652,7 +3662,7 @@ var stdin_default$1y = vue.defineComponent({
|
|
|
3652
3662
|
cb();
|
|
3653
3663
|
}
|
|
3654
3664
|
};
|
|
3655
|
-
const
|
|
3665
|
+
const resize = () => initialize(state.active);
|
|
3656
3666
|
let touchStartTime;
|
|
3657
3667
|
const onTouchStart = (event) => {
|
|
3658
3668
|
if (!props.touchable || // avoid resetting position on multi-finger touch
|
|
@@ -3781,7 +3791,7 @@ var stdin_default$1y = vue.defineComponent({
|
|
|
3781
3791
|
prev,
|
|
3782
3792
|
next,
|
|
3783
3793
|
state,
|
|
3784
|
-
resize
|
|
3794
|
+
resize,
|
|
3785
3795
|
swipeTo
|
|
3786
3796
|
});
|
|
3787
3797
|
linkChildren({
|
|
@@ -3793,7 +3803,7 @@ var stdin_default$1y = vue.defineComponent({
|
|
|
3793
3803
|
vue.watch(() => props.initialSwipe, (value) => initialize(+value));
|
|
3794
3804
|
vue.watch(count, () => initialize(state.active));
|
|
3795
3805
|
vue.watch(() => props.autoplay, autoplay);
|
|
3796
|
-
vue.watch([windowWidth, windowHeight],
|
|
3806
|
+
vue.watch([windowWidth, windowHeight], resize);
|
|
3797
3807
|
vue.watch(use.usePageVisibility(), (visible) => {
|
|
3798
3808
|
if (visible === "visible") {
|
|
3799
3809
|
autoplay();
|
|
@@ -4118,6 +4128,7 @@ var stdin_default$1w = vue.defineComponent({
|
|
|
4118
4128
|
"scrollable": scrollable.value,
|
|
4119
4129
|
"activeColor": props.titleActiveColor,
|
|
4120
4130
|
"inactiveColor": props.titleInactiveColor,
|
|
4131
|
+
"setLine": setLine,
|
|
4121
4132
|
"onClick": (event) => onClickTab(item, index, event)
|
|
4122
4133
|
}, pick(item, ["dot", "badge", "title", "disabled", "showZeroBadge"])), {
|
|
4123
4134
|
title: item.$slots.title,
|
|
@@ -5739,7 +5750,7 @@ function getColumnsType$1(columns, fields) {
|
|
|
5739
5750
|
return "default";
|
|
5740
5751
|
}
|
|
5741
5752
|
function findIndexOfEnabledOption$1(options, index) {
|
|
5742
|
-
index = clamp
|
|
5753
|
+
index = clamp(index, 0, options.length);
|
|
5743
5754
|
for (let i = index; i < options.length; i++) {
|
|
5744
5755
|
if (!options[i].disabled)
|
|
5745
5756
|
return i;
|
|
@@ -5851,7 +5862,7 @@ var stdin_default$1i = vue.defineComponent({
|
|
|
5851
5862
|
updateValueByIndex(index);
|
|
5852
5863
|
emit("clickOption", props.options[index]);
|
|
5853
5864
|
};
|
|
5854
|
-
const getIndexByOffset = (offset) => clamp
|
|
5865
|
+
const getIndexByOffset = (offset) => clamp(Math.round(-offset / props.optionHeight), 0, count() - 1);
|
|
5855
5866
|
const momentum = (distance, duration) => {
|
|
5856
5867
|
const speed = Math.abs(distance / duration);
|
|
5857
5868
|
distance = currentOffset.value + speed / 3e-3 * (distance < 0 ? -1 : 1);
|
|
@@ -5891,7 +5902,7 @@ var stdin_default$1i = vue.defineComponent({
|
|
|
5891
5902
|
moving = true;
|
|
5892
5903
|
preventDefault(event, true);
|
|
5893
5904
|
}
|
|
5894
|
-
currentOffset.value = clamp
|
|
5905
|
+
currentOffset.value = clamp(startOffset + touch.deltaY.value, -(count() * props.optionHeight), props.optionHeight);
|
|
5895
5906
|
const now = Date.now();
|
|
5896
5907
|
if (now - touchStartTime > MOMENTUM_TIME$2) {
|
|
5897
5908
|
touchStartTime = now;
|
|
@@ -6443,7 +6454,7 @@ const formatValueRange = (values, columns) => values.map((value, index) => {
|
|
|
6443
6454
|
if (column.length) {
|
|
6444
6455
|
const minValue = +column[0].value;
|
|
6445
6456
|
const maxValue = +column[column.length - 1].value;
|
|
6446
|
-
return padZero(clamp
|
|
6457
|
+
return padZero(clamp(+value, minValue, maxValue));
|
|
6447
6458
|
}
|
|
6448
6459
|
return value;
|
|
6449
6460
|
});
|
|
@@ -6530,7 +6541,7 @@ var stdin_default$1c = vue.defineComponent({
|
|
|
6530
6541
|
updateValueByIndex(index);
|
|
6531
6542
|
emit("clickOption", props.options[index]);
|
|
6532
6543
|
};
|
|
6533
|
-
const getIndexByOffset = (offset) => clamp
|
|
6544
|
+
const getIndexByOffset = (offset) => clamp(Math.round(-offset / props.optionHeight), 0, count() - 1);
|
|
6534
6545
|
const momentum = (distance, duration) => {
|
|
6535
6546
|
const speed = Math.abs(distance / duration);
|
|
6536
6547
|
distance = currentOffset.value + speed / 15e-4 * (distance < 0 ? -1 : 1);
|
|
@@ -6570,7 +6581,7 @@ var stdin_default$1c = vue.defineComponent({
|
|
|
6570
6581
|
moving = true;
|
|
6571
6582
|
preventDefault(event, true);
|
|
6572
6583
|
}
|
|
6573
|
-
currentOffset.value = clamp
|
|
6584
|
+
currentOffset.value = clamp(startOffset + touch.deltaY.value, -(count() * props.optionHeight), props.optionHeight);
|
|
6574
6585
|
const now = Date.now();
|
|
6575
6586
|
if (now - touchStartTime > MOMENTUM_TIME$1) {
|
|
6576
6587
|
touchStartTime = now;
|
|
@@ -8276,13 +8287,6 @@ const parseNumber = (obj, defaultValue = 0) => {
|
|
|
8276
8287
|
}
|
|
8277
8288
|
return result;
|
|
8278
8289
|
};
|
|
8279
|
-
const parseDecimal = (obj, defaultValue) => {
|
|
8280
|
-
let result = parseFloat(obj);
|
|
8281
|
-
if (isNaN(result)) {
|
|
8282
|
-
result = defaultValue || 0;
|
|
8283
|
-
}
|
|
8284
|
-
return result;
|
|
8285
|
-
};
|
|
8286
8290
|
const [name$K, bem$K] = createNamespace("tag");
|
|
8287
8291
|
const tagProps = {
|
|
8288
8292
|
mark: Boolean,
|
|
@@ -11425,7 +11429,7 @@ var stdin_default$R = vue.defineComponent({
|
|
|
11425
11429
|
return 0;
|
|
11426
11430
|
});
|
|
11427
11431
|
const setScale = (scale) => {
|
|
11428
|
-
scale = clamp
|
|
11432
|
+
scale = clamp(scale, +props.minZoom, +props.maxZoom + 1);
|
|
11429
11433
|
if (scale !== state.scale) {
|
|
11430
11434
|
state.scale = scale;
|
|
11431
11435
|
emit("scale", {
|
|
@@ -11486,8 +11490,8 @@ var stdin_default$R = vue.defineComponent({
|
|
|
11486
11490
|
} = touch;
|
|
11487
11491
|
const moveX = deltaX.value + startMoveX;
|
|
11488
11492
|
const moveY = deltaY.value + startMoveY;
|
|
11489
|
-
state.moveX = clamp
|
|
11490
|
-
state.moveY = clamp
|
|
11493
|
+
state.moveX = clamp(moveX, -maxMoveX.value, maxMoveX.value);
|
|
11494
|
+
state.moveY = clamp(moveY, -maxMoveY.value, maxMoveY.value);
|
|
11491
11495
|
}
|
|
11492
11496
|
if (state.zooming && touches.length === 2) {
|
|
11493
11497
|
const distance = getDistance(touches);
|
|
@@ -11536,8 +11540,8 @@ var stdin_default$R = vue.defineComponent({
|
|
|
11536
11540
|
}
|
|
11537
11541
|
if (!event.touches.length) {
|
|
11538
11542
|
if (state.zooming) {
|
|
11539
|
-
state.moveX = clamp
|
|
11540
|
-
state.moveY = clamp
|
|
11543
|
+
state.moveX = clamp(state.moveX, -maxMoveX.value, maxMoveX.value);
|
|
11544
|
+
state.moveY = clamp(state.moveY, -maxMoveY.value, maxMoveY.value);
|
|
11541
11545
|
state.zooming = false;
|
|
11542
11546
|
}
|
|
11543
11547
|
state.moving = false;
|
|
@@ -11647,7 +11651,7 @@ var stdin_default$Q = vue.defineComponent({
|
|
|
11647
11651
|
rootHeight: 0,
|
|
11648
11652
|
disableZoom: false
|
|
11649
11653
|
});
|
|
11650
|
-
const
|
|
11654
|
+
const resize = () => {
|
|
11651
11655
|
if (swipeRef.value) {
|
|
11652
11656
|
const rect = use.useRect(swipeRef.value.$el);
|
|
11653
11657
|
state.rootWidth = rect.width;
|
|
@@ -11757,8 +11761,8 @@ var stdin_default$Q = vue.defineComponent({
|
|
|
11757
11761
|
useExpose({
|
|
11758
11762
|
swipeTo
|
|
11759
11763
|
});
|
|
11760
|
-
vue.onMounted(
|
|
11761
|
-
vue.watch([windowWidth, windowHeight],
|
|
11764
|
+
vue.onMounted(resize);
|
|
11765
|
+
vue.watch([windowWidth, windowHeight], resize);
|
|
11762
11766
|
vue.watch(() => props.startPosition, (value) => setActive(+value));
|
|
11763
11767
|
vue.watch(() => props.show, (value) => {
|
|
11764
11768
|
const {
|
|
@@ -11768,7 +11772,7 @@ var stdin_default$Q = vue.defineComponent({
|
|
|
11768
11772
|
if (value) {
|
|
11769
11773
|
setActive(+startPosition);
|
|
11770
11774
|
vue.nextTick(() => {
|
|
11771
|
-
|
|
11775
|
+
resize();
|
|
11772
11776
|
swipeTo(+startPosition, {
|
|
11773
11777
|
immediate: true
|
|
11774
11778
|
});
|
|
@@ -13008,9 +13012,6 @@ var stdin_default$C = vue.defineComponent({
|
|
|
13008
13012
|
}, null)])])]);
|
|
13009
13013
|
}
|
|
13010
13014
|
});
|
|
13011
|
-
const MAX_SIDE_LENGTH = 1920;
|
|
13012
|
-
const MIN_SIDE_LENGTH = 480;
|
|
13013
|
-
const PHOTO_FILE_SIZE_LIMIT = 1e3;
|
|
13014
13015
|
function isImageType(file) {
|
|
13015
13016
|
return file.type.indexOf("image/") >= 0;
|
|
13016
13017
|
}
|
|
@@ -13034,47 +13035,6 @@ function getUniqueFileName(file, suffix = "") {
|
|
|
13034
13035
|
)}`;
|
|
13035
13036
|
return suffix ? name2 + "." + suffix : name2;
|
|
13036
13037
|
}
|
|
13037
|
-
function adjustImgOrientation(ctx, img, orientation, width, height) {
|
|
13038
|
-
switch (orientation) {
|
|
13039
|
-
case 3:
|
|
13040
|
-
ctx.rotate(180 * Math.PI / 180);
|
|
13041
|
-
ctx.drawImage(img, -width, -height, width, height);
|
|
13042
|
-
break;
|
|
13043
|
-
case 6:
|
|
13044
|
-
ctx.rotate(90 * Math.PI / 180);
|
|
13045
|
-
ctx.drawImage(img, 0, -width, height, width);
|
|
13046
|
-
break;
|
|
13047
|
-
case 8:
|
|
13048
|
-
ctx.rotate(270 * Math.PI / 180);
|
|
13049
|
-
ctx.drawImage(img, -height, 0, height, width);
|
|
13050
|
-
break;
|
|
13051
|
-
case 2:
|
|
13052
|
-
ctx.translate(width, 0);
|
|
13053
|
-
ctx.scale(-1, 1);
|
|
13054
|
-
ctx.drawImage(img, 0, 0, width, height);
|
|
13055
|
-
break;
|
|
13056
|
-
case 4:
|
|
13057
|
-
ctx.translate(width, 0);
|
|
13058
|
-
ctx.scale(-1, 1);
|
|
13059
|
-
ctx.rotate(180 * Math.PI / 180);
|
|
13060
|
-
ctx.drawImage(img, -width, -height, width, height);
|
|
13061
|
-
break;
|
|
13062
|
-
case 5:
|
|
13063
|
-
ctx.translate(width, 0);
|
|
13064
|
-
ctx.scale(-1, 1);
|
|
13065
|
-
ctx.rotate(90 * Math.PI / 180);
|
|
13066
|
-
ctx.drawImage(img, 0, -width, height, width);
|
|
13067
|
-
break;
|
|
13068
|
-
case 7:
|
|
13069
|
-
ctx.translate(width, 0);
|
|
13070
|
-
ctx.scale(-1, 1);
|
|
13071
|
-
ctx.rotate(270 * Math.PI / 180);
|
|
13072
|
-
ctx.drawImage(img, -height, 0, height, width);
|
|
13073
|
-
break;
|
|
13074
|
-
default:
|
|
13075
|
-
ctx.drawImage(img, 0, 0, width, height);
|
|
13076
|
-
}
|
|
13077
|
-
}
|
|
13078
13038
|
function file2DataURL(file) {
|
|
13079
13039
|
return new Promise((resolve, reject) => {
|
|
13080
13040
|
const a = new FileReader();
|
|
@@ -13088,39 +13048,6 @@ function file2DataURL(file) {
|
|
|
13088
13048
|
a.readAsDataURL(file);
|
|
13089
13049
|
});
|
|
13090
13050
|
}
|
|
13091
|
-
function file2Image(file) {
|
|
13092
|
-
return new Promise((resolve, reject) => {
|
|
13093
|
-
file2DataURL(file).then((url) => {
|
|
13094
|
-
const img = new Image();
|
|
13095
|
-
img.src = url;
|
|
13096
|
-
img.onload = function() {
|
|
13097
|
-
if (img.complete) {
|
|
13098
|
-
resolve(img);
|
|
13099
|
-
} else {
|
|
13100
|
-
reject(new Error("文件加载失败"));
|
|
13101
|
-
}
|
|
13102
|
-
};
|
|
13103
|
-
}).catch(reject);
|
|
13104
|
-
});
|
|
13105
|
-
}
|
|
13106
|
-
function image2Canvas(img, type, orientation, width, height) {
|
|
13107
|
-
const canvas = document.createElement("canvas");
|
|
13108
|
-
const _width = width || img.width;
|
|
13109
|
-
const _height = height || img.height;
|
|
13110
|
-
canvas.width = _width;
|
|
13111
|
-
canvas.height = _height;
|
|
13112
|
-
const ctx = canvas.getContext("2d");
|
|
13113
|
-
if (ctx) {
|
|
13114
|
-
ctx.fillStyle = "transparent";
|
|
13115
|
-
if (type === "image/jpeg") {
|
|
13116
|
-
ctx.fillStyle = "#fff";
|
|
13117
|
-
}
|
|
13118
|
-
ctx.fillRect(0, 0, _width, _height);
|
|
13119
|
-
adjustImgOrientation(ctx, img, orientation, _width, _height);
|
|
13120
|
-
return Promise.resolve(canvas);
|
|
13121
|
-
}
|
|
13122
|
-
return Promise.reject(new Error("canvas getContext return null"));
|
|
13123
|
-
}
|
|
13124
13051
|
function canvas2File(canvas, fileName, lastModified, type = "image/jpeg", quality = 0.8) {
|
|
13125
13052
|
return new Promise((resolve, reject) => {
|
|
13126
13053
|
canvas.toBlob(
|
|
@@ -13137,893 +13064,6 @@ function canvas2File(canvas, fileName, lastModified, type = "image/jpeg", qualit
|
|
|
13137
13064
|
);
|
|
13138
13065
|
});
|
|
13139
13066
|
}
|
|
13140
|
-
function canvas2Image(canvas, type = "image/jpeg", quality = 0.8) {
|
|
13141
|
-
const image = new Image();
|
|
13142
|
-
image.src = canvas.toDataURL(type, quality);
|
|
13143
|
-
return Promise.resolve(image);
|
|
13144
|
-
}
|
|
13145
|
-
function getStringFromCharCode(dataView, start, length) {
|
|
13146
|
-
let str = "";
|
|
13147
|
-
let i;
|
|
13148
|
-
length += start;
|
|
13149
|
-
for (i = start; i < length; i += 1) {
|
|
13150
|
-
str += String.fromCharCode(dataView.getUint8(i));
|
|
13151
|
-
}
|
|
13152
|
-
return str;
|
|
13153
|
-
}
|
|
13154
|
-
function getOrientation(arrayBuffer) {
|
|
13155
|
-
const dataView = new DataView(arrayBuffer);
|
|
13156
|
-
let orientation;
|
|
13157
|
-
try {
|
|
13158
|
-
let littleEndian;
|
|
13159
|
-
let app1Start;
|
|
13160
|
-
let ifdStart;
|
|
13161
|
-
if (dataView.getUint8(0) === 255 && dataView.getUint8(1) === 216) {
|
|
13162
|
-
const length = dataView.byteLength;
|
|
13163
|
-
let offset = 2;
|
|
13164
|
-
while (offset + 1 < length) {
|
|
13165
|
-
if (dataView.getUint8(offset) === 255 && dataView.getUint8(offset + 1) === 225) {
|
|
13166
|
-
app1Start = offset;
|
|
13167
|
-
break;
|
|
13168
|
-
}
|
|
13169
|
-
offset += 1;
|
|
13170
|
-
}
|
|
13171
|
-
}
|
|
13172
|
-
if (app1Start) {
|
|
13173
|
-
const exifIDCode = app1Start + 4;
|
|
13174
|
-
const tiffOffset = app1Start + 10;
|
|
13175
|
-
if (getStringFromCharCode(dataView, exifIDCode, 4) === "Exif") {
|
|
13176
|
-
const endianness = dataView.getUint16(tiffOffset);
|
|
13177
|
-
littleEndian = endianness === 18761;
|
|
13178
|
-
if (littleEndian || endianness === 19789) {
|
|
13179
|
-
if (dataView.getUint16(tiffOffset + 2, littleEndian) === 42) {
|
|
13180
|
-
const firstIFDOffset = dataView.getUint32(
|
|
13181
|
-
tiffOffset + 4,
|
|
13182
|
-
littleEndian
|
|
13183
|
-
);
|
|
13184
|
-
if (firstIFDOffset >= 8) {
|
|
13185
|
-
ifdStart = tiffOffset + firstIFDOffset;
|
|
13186
|
-
}
|
|
13187
|
-
}
|
|
13188
|
-
}
|
|
13189
|
-
}
|
|
13190
|
-
}
|
|
13191
|
-
if (ifdStart) {
|
|
13192
|
-
const _length = dataView.getUint16(ifdStart, littleEndian);
|
|
13193
|
-
let _offset;
|
|
13194
|
-
let i;
|
|
13195
|
-
for (i = 0; i < _length; i += 1) {
|
|
13196
|
-
_offset = ifdStart + i * 12 + 2;
|
|
13197
|
-
if (dataView.getUint16(_offset, littleEndian) === 274) {
|
|
13198
|
-
_offset += 8;
|
|
13199
|
-
orientation = dataView.getUint16(_offset, littleEndian);
|
|
13200
|
-
dataView.setUint16(_offset, 1, littleEndian);
|
|
13201
|
-
break;
|
|
13202
|
-
}
|
|
13203
|
-
}
|
|
13204
|
-
}
|
|
13205
|
-
} catch (e) {
|
|
13206
|
-
orientation = 1;
|
|
13207
|
-
}
|
|
13208
|
-
return orientation;
|
|
13209
|
-
}
|
|
13210
|
-
function resize(img, {
|
|
13211
|
-
inputType = "image/jpeg",
|
|
13212
|
-
orientation = 1,
|
|
13213
|
-
// 图片的方向
|
|
13214
|
-
imageWidth = -1,
|
|
13215
|
-
imageHeight = -1,
|
|
13216
|
-
// equalProportion = true, // 等比例拉伸
|
|
13217
|
-
sideLengthLimit = 640,
|
|
13218
|
-
baseOnShortSide = true,
|
|
13219
|
-
// 是否以短边为基准缩放
|
|
13220
|
-
resultType = "image"
|
|
13221
|
-
}) {
|
|
13222
|
-
let scale = 1;
|
|
13223
|
-
const scaleBaseFunc = baseOnShortSide ? Math.min : Math.max;
|
|
13224
|
-
if (imageWidth > 0 && imageHeight > 0) {
|
|
13225
|
-
scale = sideLengthLimit / scaleBaseFunc(imageWidth, imageHeight);
|
|
13226
|
-
} else if (img.width > 0 && img.height > 0) {
|
|
13227
|
-
scale = sideLengthLimit / scaleBaseFunc(img.width, img.height);
|
|
13228
|
-
imageWidth = img.width;
|
|
13229
|
-
imageHeight = img.height;
|
|
13230
|
-
} else {
|
|
13231
|
-
return Promise.reject(new Error("image width/height 无效"));
|
|
13232
|
-
}
|
|
13233
|
-
const targetWidth = scale > 1 ? imageWidth : imageWidth * scale;
|
|
13234
|
-
const targetHeight = scale > 1 ? imageHeight : imageHeight * scale;
|
|
13235
|
-
if (resultType === "image") {
|
|
13236
|
-
return image2Canvas(
|
|
13237
|
-
img,
|
|
13238
|
-
inputType,
|
|
13239
|
-
orientation,
|
|
13240
|
-
targetWidth,
|
|
13241
|
-
targetHeight
|
|
13242
|
-
).then((canvas) => canvas2Image(canvas));
|
|
13243
|
-
}
|
|
13244
|
-
return image2Canvas(img, inputType, orientation, targetWidth, targetHeight);
|
|
13245
|
-
}
|
|
13246
|
-
var __defProp$3 = Object.defineProperty;
|
|
13247
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13248
|
-
var __publicField$3 = (obj, key, value) => {
|
|
13249
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13250
|
-
return value;
|
|
13251
|
-
};
|
|
13252
|
-
class ResizeOptions {
|
|
13253
|
-
// 最大边长
|
|
13254
|
-
constructor(maxSideLength) {
|
|
13255
|
-
__publicField$3(this, "maxSideLength");
|
|
13256
|
-
if (!isDef(maxSideLength)) {
|
|
13257
|
-
this.maxSideLength = MAX_SIDE_LENGTH;
|
|
13258
|
-
} else {
|
|
13259
|
-
this.maxSideLength = maxSideLength;
|
|
13260
|
-
if (this.maxSideLength > MAX_SIDE_LENGTH) {
|
|
13261
|
-
this.maxSideLength = MAX_SIDE_LENGTH;
|
|
13262
|
-
} else if (this.maxSideLength < MIN_SIDE_LENGTH) {
|
|
13263
|
-
this.maxSideLength = MIN_SIDE_LENGTH;
|
|
13264
|
-
}
|
|
13265
|
-
}
|
|
13266
|
-
}
|
|
13267
|
-
}
|
|
13268
|
-
var __defProp$2 = Object.defineProperty;
|
|
13269
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13270
|
-
var __publicField$2 = (obj, key, value) => {
|
|
13271
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13272
|
-
return value;
|
|
13273
|
-
};
|
|
13274
|
-
class CompressOptions {
|
|
13275
|
-
constructor(photoFileSizeLimit) {
|
|
13276
|
-
__publicField$2(this, "photoFileSizeLimit");
|
|
13277
|
-
__publicField$2(this, "checkOrientation", true);
|
|
13278
|
-
if (!isDef(photoFileSizeLimit)) {
|
|
13279
|
-
this.photoFileSizeLimit = PHOTO_FILE_SIZE_LIMIT;
|
|
13280
|
-
} else {
|
|
13281
|
-
this.photoFileSizeLimit = photoFileSizeLimit;
|
|
13282
|
-
}
|
|
13283
|
-
}
|
|
13284
|
-
}
|
|
13285
|
-
var __defProp$1 = Object.defineProperty;
|
|
13286
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13287
|
-
var __publicField$1 = (obj, key, value) => {
|
|
13288
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13289
|
-
return value;
|
|
13290
|
-
};
|
|
13291
|
-
const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
13292
|
-
const subString = (str, startIndex, length) => {
|
|
13293
|
-
if (!isDef(length)) {
|
|
13294
|
-
return str.substring(startIndex);
|
|
13295
|
-
}
|
|
13296
|
-
return str.substring(startIndex, startIndex + length);
|
|
13297
|
-
};
|
|
13298
|
-
const ColorMap = {
|
|
13299
|
-
transparent: "#00000000",
|
|
13300
|
-
white: "#FFFFFF",
|
|
13301
|
-
black: "#000000",
|
|
13302
|
-
darkgray: "#444444",
|
|
13303
|
-
gray: "#888888",
|
|
13304
|
-
lightgray: "#CCCCCC",
|
|
13305
|
-
darkgrey: "#444444",
|
|
13306
|
-
grey: "#888888",
|
|
13307
|
-
lightgrey: "#CCCCCC",
|
|
13308
|
-
red: "#FF0000",
|
|
13309
|
-
green: "#00FF00",
|
|
13310
|
-
blue: "#0000FF",
|
|
13311
|
-
yellow: "#FFFF00",
|
|
13312
|
-
cyan: "#00FFFF",
|
|
13313
|
-
magenta: "#FF00FF",
|
|
13314
|
-
aqua: "#00FFFF",
|
|
13315
|
-
fuchsia: "#FF00FF",
|
|
13316
|
-
lime: "#00FF00",
|
|
13317
|
-
maroon: "#800000",
|
|
13318
|
-
navy: "#000080",
|
|
13319
|
-
olive: "#808000",
|
|
13320
|
-
purple: "#800080",
|
|
13321
|
-
silver: "#C0C0C0",
|
|
13322
|
-
teal: "#008080",
|
|
13323
|
-
orange: "#FF9933"
|
|
13324
|
-
};
|
|
13325
|
-
function getColorValue(key) {
|
|
13326
|
-
for (const k of Object.getOwnPropertyNames(ColorMap)) {
|
|
13327
|
-
if (k === key) {
|
|
13328
|
-
return ColorMap[k];
|
|
13329
|
-
}
|
|
13330
|
-
}
|
|
13331
|
-
return null;
|
|
13332
|
-
}
|
|
13333
|
-
const CONTENT_PADDING = 10;
|
|
13334
|
-
const DEFAULT_PADDING = 2;
|
|
13335
|
-
const DEFAULT_FONT_SIZE = 25;
|
|
13336
|
-
const DEFAULT_CANVAS_SIZE = 480;
|
|
13337
|
-
const DEFAULT_BACKGROUND_OPACITY = 128;
|
|
13338
|
-
function getHeitiFontFamily() {
|
|
13339
|
-
if (isAndroid()) {
|
|
13340
|
-
return "'Roboto Black', 'Droid Sans'";
|
|
13341
|
-
} else if (isIOS$1()) {
|
|
13342
|
-
return "'PingFang SC Medium'";
|
|
13343
|
-
}
|
|
13344
|
-
return '"PingFang SC Medium", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif';
|
|
13345
|
-
}
|
|
13346
|
-
function parseWatermarkStyle(styleString, canvasSize) {
|
|
13347
|
-
if (!isValidString(styleString)) {
|
|
13348
|
-
return null;
|
|
13349
|
-
}
|
|
13350
|
-
const styleParts = styleString.split("$");
|
|
13351
|
-
if (styleParts.length <= 0) {
|
|
13352
|
-
return null;
|
|
13353
|
-
}
|
|
13354
|
-
const scale = Math.min(canvasSize.width, canvasSize.height) / DEFAULT_CANVAS_SIZE;
|
|
13355
|
-
if (parseNumber(styleParts[0], -1) !== -1) {
|
|
13356
|
-
const fontSize2 = Math.round(
|
|
13357
|
-
parseDecimal(styleParts[0], DEFAULT_FONT_SIZE) * scale
|
|
13358
|
-
);
|
|
13359
|
-
let position2 = "lefttop";
|
|
13360
|
-
if (styleParts[1]) {
|
|
13361
|
-
position2 = styleParts[1];
|
|
13362
|
-
}
|
|
13363
|
-
let paddingTop2 = DEFAULT_PADDING * scale;
|
|
13364
|
-
let paddingBottom2 = DEFAULT_PADDING * scale;
|
|
13365
|
-
if (styleParts[2]) {
|
|
13366
|
-
const paddingParts = styleParts[2].split("_");
|
|
13367
|
-
paddingTop2 = parseNumber(paddingParts[0], DEFAULT_PADDING) * scale;
|
|
13368
|
-
if (paddingParts[1]) {
|
|
13369
|
-
paddingBottom2 = parseNumber(paddingParts[1], DEFAULT_PADDING) * scale;
|
|
13370
|
-
}
|
|
13371
|
-
}
|
|
13372
|
-
const fontName2 = getHeitiFontFamily();
|
|
13373
|
-
const fontWeight2 = "normal";
|
|
13374
|
-
const fontColor2 = ColorMap.transparent;
|
|
13375
|
-
const backgroundColor2 = ColorMap.transparent;
|
|
13376
|
-
const backgroundOpacity2 = 128;
|
|
13377
|
-
return {
|
|
13378
|
-
fontName: fontName2,
|
|
13379
|
-
fontWeight: fontWeight2,
|
|
13380
|
-
fontColor: fontColor2,
|
|
13381
|
-
fontSize: fontSize2,
|
|
13382
|
-
backgroundColor: backgroundColor2,
|
|
13383
|
-
backgroundOpacity: backgroundOpacity2,
|
|
13384
|
-
paddingTop: paddingTop2,
|
|
13385
|
-
paddingBottom: paddingBottom2,
|
|
13386
|
-
position: position2,
|
|
13387
|
-
scale,
|
|
13388
|
-
simplified: true
|
|
13389
|
-
};
|
|
13390
|
-
}
|
|
13391
|
-
const fontName = styleParts[0] + ", " + getHeitiFontFamily();
|
|
13392
|
-
let fontWeight = "normal";
|
|
13393
|
-
if (styleParts[1]) {
|
|
13394
|
-
fontWeight = styleParts[1];
|
|
13395
|
-
}
|
|
13396
|
-
let fontColor = ColorMap.white;
|
|
13397
|
-
if (styleParts[2]) {
|
|
13398
|
-
const color = getColorValue(styleParts[2]);
|
|
13399
|
-
if (color) {
|
|
13400
|
-
fontColor = color;
|
|
13401
|
-
}
|
|
13402
|
-
}
|
|
13403
|
-
let fontSize = Math.round(DEFAULT_FONT_SIZE * scale);
|
|
13404
|
-
if (styleParts[3]) {
|
|
13405
|
-
fontSize = Math.round(
|
|
13406
|
-
parseDecimal(styleParts[3], DEFAULT_FONT_SIZE) * scale
|
|
13407
|
-
);
|
|
13408
|
-
}
|
|
13409
|
-
let backgroundColor = ColorMap.blue;
|
|
13410
|
-
if (styleParts[4]) {
|
|
13411
|
-
const color = getColorValue(styleParts[4]);
|
|
13412
|
-
if (color) {
|
|
13413
|
-
backgroundColor = color;
|
|
13414
|
-
}
|
|
13415
|
-
}
|
|
13416
|
-
let position = "lefttop";
|
|
13417
|
-
if (styleParts[5]) {
|
|
13418
|
-
position = styleParts[5];
|
|
13419
|
-
}
|
|
13420
|
-
let backgroundOpacity = 255;
|
|
13421
|
-
if (styleParts[6]) {
|
|
13422
|
-
let opacity = parseNumber(styleParts[6], DEFAULT_BACKGROUND_OPACITY);
|
|
13423
|
-
opacity = clamp(opacity, 0, 255);
|
|
13424
|
-
backgroundOpacity = opacity;
|
|
13425
|
-
}
|
|
13426
|
-
let paddingTop = DEFAULT_PADDING * scale;
|
|
13427
|
-
let paddingBottom = DEFAULT_PADDING * scale;
|
|
13428
|
-
if (styleParts[7]) {
|
|
13429
|
-
const paddingParts = styleParts[7].split("_");
|
|
13430
|
-
paddingTop = parseNumber(paddingParts[0], DEFAULT_PADDING) * scale;
|
|
13431
|
-
if (paddingParts[1]) {
|
|
13432
|
-
paddingBottom = parseNumber(paddingParts[1], DEFAULT_PADDING) * scale;
|
|
13433
|
-
}
|
|
13434
|
-
}
|
|
13435
|
-
return {
|
|
13436
|
-
fontName,
|
|
13437
|
-
fontWeight,
|
|
13438
|
-
fontColor,
|
|
13439
|
-
fontSize,
|
|
13440
|
-
backgroundColor,
|
|
13441
|
-
backgroundOpacity,
|
|
13442
|
-
paddingTop,
|
|
13443
|
-
paddingBottom,
|
|
13444
|
-
position,
|
|
13445
|
-
scale,
|
|
13446
|
-
simplified: false
|
|
13447
|
-
};
|
|
13448
|
-
}
|
|
13449
|
-
class TextScanner {
|
|
13450
|
-
/**
|
|
13451
|
-
* The content to scan
|
|
13452
|
-
* @param text
|
|
13453
|
-
*/
|
|
13454
|
-
constructor(text) {
|
|
13455
|
-
__publicField$1(this, "text");
|
|
13456
|
-
__publicField$1(this, "cursor");
|
|
13457
|
-
this.text = text;
|
|
13458
|
-
this.cursor = 0;
|
|
13459
|
-
}
|
|
13460
|
-
hasNext(obj) {
|
|
13461
|
-
if (!isDef(obj)) {
|
|
13462
|
-
return this.cursor < this.text.length;
|
|
13463
|
-
} else if (isString(obj)) {
|
|
13464
|
-
const str = obj;
|
|
13465
|
-
const current2 = subString(this.text, this.cursor, str.length);
|
|
13466
|
-
if (current2 === str) {
|
|
13467
|
-
return true;
|
|
13468
|
-
}
|
|
13469
|
-
} else if (isRegExp(obj)) {
|
|
13470
|
-
const regex = obj;
|
|
13471
|
-
const subText = subString(this.text, this.cursor);
|
|
13472
|
-
const matchResults = subText.match(regex);
|
|
13473
|
-
if (matchResults) {
|
|
13474
|
-
if (matchResults.index === 0) {
|
|
13475
|
-
return true;
|
|
13476
|
-
}
|
|
13477
|
-
}
|
|
13478
|
-
}
|
|
13479
|
-
return false;
|
|
13480
|
-
}
|
|
13481
|
-
next(obj) {
|
|
13482
|
-
if (!isDef(obj)) {
|
|
13483
|
-
return subString(this.text, this.cursor, 1);
|
|
13484
|
-
} else if (isString(obj)) {
|
|
13485
|
-
const str = obj;
|
|
13486
|
-
if (subString(this.text, this.cursor, str.length) === str) {
|
|
13487
|
-
return str;
|
|
13488
|
-
}
|
|
13489
|
-
} else if (isRegExp(obj)) {
|
|
13490
|
-
const regex = obj;
|
|
13491
|
-
const subText = subString(this.text, this.cursor);
|
|
13492
|
-
const matchResults = subText.match(regex);
|
|
13493
|
-
if (matchResults) {
|
|
13494
|
-
if (matchResults.index === 0) {
|
|
13495
|
-
return matchResults;
|
|
13496
|
-
}
|
|
13497
|
-
}
|
|
13498
|
-
}
|
|
13499
|
-
return null;
|
|
13500
|
-
}
|
|
13501
|
-
skip(obj) {
|
|
13502
|
-
if (!isDef(obj)) {
|
|
13503
|
-
this.cursor += 1;
|
|
13504
|
-
} else if (isValidString(obj)) {
|
|
13505
|
-
const str = obj;
|
|
13506
|
-
this.cursor += str.length;
|
|
13507
|
-
}
|
|
13508
|
-
return this;
|
|
13509
|
-
}
|
|
13510
|
-
}
|
|
13511
|
-
function buildContent(contentConfigString, watermarkContext) {
|
|
13512
|
-
let content = "";
|
|
13513
|
-
const scanner = new TextScanner(contentConfigString);
|
|
13514
|
-
let steps = 0;
|
|
13515
|
-
while (scanner.hasNext() && steps < contentConfigString.length) {
|
|
13516
|
-
const dateRegex = new RegExp(
|
|
13517
|
-
"date{(.*?)}|date"
|
|
13518
|
-
/* Date */
|
|
13519
|
-
);
|
|
13520
|
-
if (scanner.hasNext(dateRegex)) {
|
|
13521
|
-
const regexResult = scanner.next(dateRegex);
|
|
13522
|
-
if (regexResult) {
|
|
13523
|
-
const matchResults = regexResult;
|
|
13524
|
-
let format = dateUtils.DATE_FORMAT.FORMAT_YMD;
|
|
13525
|
-
if (matchResults && matchResults.length >= 2) {
|
|
13526
|
-
if (isValidString(matchResults[1])) {
|
|
13527
|
-
format = matchResults[1];
|
|
13528
|
-
}
|
|
13529
|
-
}
|
|
13530
|
-
if (watermarkContext) {
|
|
13531
|
-
content += dateUtils.formatDate(watermarkContext.watermarkTime, format);
|
|
13532
|
-
}
|
|
13533
|
-
scanner.skip(matchResults.input);
|
|
13534
|
-
}
|
|
13535
|
-
} else if (scanner.hasNext(
|
|
13536
|
-
"time"
|
|
13537
|
-
/* Time */
|
|
13538
|
-
)) {
|
|
13539
|
-
if (watermarkContext) {
|
|
13540
|
-
const value = dateUtils.formatDate(
|
|
13541
|
-
watermarkContext.watermarkTime,
|
|
13542
|
-
dateUtils.DATE_FORMAT.FORMAT_HM
|
|
13543
|
-
);
|
|
13544
|
-
content += value;
|
|
13545
|
-
}
|
|
13546
|
-
scanner.skip(
|
|
13547
|
-
"time"
|
|
13548
|
-
/* Time */
|
|
13549
|
-
);
|
|
13550
|
-
} else if (scanner.hasNext(
|
|
13551
|
-
"address"
|
|
13552
|
-
/* Address */
|
|
13553
|
-
)) {
|
|
13554
|
-
if (watermarkContext) {
|
|
13555
|
-
content += watermarkContext.address;
|
|
13556
|
-
}
|
|
13557
|
-
scanner.skip(
|
|
13558
|
-
"address"
|
|
13559
|
-
/* Address */
|
|
13560
|
-
);
|
|
13561
|
-
} else if (scanner.hasNext(
|
|
13562
|
-
"humanname"
|
|
13563
|
-
/* HumanName */
|
|
13564
|
-
)) {
|
|
13565
|
-
if (watermarkContext) {
|
|
13566
|
-
content += watermarkContext.humanName;
|
|
13567
|
-
}
|
|
13568
|
-
scanner.skip(
|
|
13569
|
-
"humanname"
|
|
13570
|
-
/* HumanName */
|
|
13571
|
-
);
|
|
13572
|
-
} else if (scanner.hasNext(
|
|
13573
|
-
"projectName"
|
|
13574
|
-
/* ProjectName */
|
|
13575
|
-
)) {
|
|
13576
|
-
if (watermarkContext) {
|
|
13577
|
-
content += watermarkContext.projectName;
|
|
13578
|
-
}
|
|
13579
|
-
scanner.skip(
|
|
13580
|
-
"projectName"
|
|
13581
|
-
/* ProjectName */
|
|
13582
|
-
);
|
|
13583
|
-
} else if (scanner.hasNext(
|
|
13584
|
-
"{logo}"
|
|
13585
|
-
/* Logo */
|
|
13586
|
-
)) {
|
|
13587
|
-
console.error("watermark logo ignored");
|
|
13588
|
-
scanner.skip(
|
|
13589
|
-
"{logo}"
|
|
13590
|
-
/* Logo */
|
|
13591
|
-
);
|
|
13592
|
-
} else {
|
|
13593
|
-
const nextChar = scanner.next();
|
|
13594
|
-
if (isString(nextChar)) {
|
|
13595
|
-
content += nextChar;
|
|
13596
|
-
}
|
|
13597
|
-
scanner.skip();
|
|
13598
|
-
}
|
|
13599
|
-
steps++;
|
|
13600
|
-
}
|
|
13601
|
-
return content;
|
|
13602
|
-
}
|
|
13603
|
-
function parseWatermarks(watermarkConfigString, canvasSize, watermarkContext) {
|
|
13604
|
-
const watermarks = [];
|
|
13605
|
-
const configStringArray = watermarkConfigString.split("###");
|
|
13606
|
-
for (let i = 0; i < configStringArray.length; i++) {
|
|
13607
|
-
const configString = configStringArray[i];
|
|
13608
|
-
const configParts = configString.split("*#*");
|
|
13609
|
-
if (configParts.length === 2) {
|
|
13610
|
-
const styleString = configParts[0];
|
|
13611
|
-
const contentString = configParts[1];
|
|
13612
|
-
const style = parseWatermarkStyle(styleString, canvasSize);
|
|
13613
|
-
const content = buildContent(contentString, watermarkContext);
|
|
13614
|
-
if (style && content) {
|
|
13615
|
-
const watermark = {
|
|
13616
|
-
content,
|
|
13617
|
-
style
|
|
13618
|
-
};
|
|
13619
|
-
watermarks.push(watermark);
|
|
13620
|
-
}
|
|
13621
|
-
}
|
|
13622
|
-
}
|
|
13623
|
-
return watermarks;
|
|
13624
|
-
}
|
|
13625
|
-
function getCanvasScale(canvas, len) {
|
|
13626
|
-
const min = Math.min(canvas.width, canvas.height);
|
|
13627
|
-
return min / DEFAULT_CANVAS_SIZE * len;
|
|
13628
|
-
}
|
|
13629
|
-
function buildTile(canvas, content, style) {
|
|
13630
|
-
const origin = {
|
|
13631
|
-
x: 0,
|
|
13632
|
-
y: 0
|
|
13633
|
-
};
|
|
13634
|
-
const size = {
|
|
13635
|
-
width: 0,
|
|
13636
|
-
height: 0
|
|
13637
|
-
};
|
|
13638
|
-
const lines = [];
|
|
13639
|
-
const ctx = canvas.getContext("2d");
|
|
13640
|
-
if (!ctx) {
|
|
13641
|
-
return null;
|
|
13642
|
-
}
|
|
13643
|
-
ctx.font = `${style.fontWeight} ${style.fontSize}px ${style.fontName}`;
|
|
13644
|
-
const contentPadding = getCanvasScale(canvas, CONTENT_PADDING);
|
|
13645
|
-
const contentWidth = canvas.width - contentPadding * 2;
|
|
13646
|
-
const lineHeight = ctx.measureText("M").width;
|
|
13647
|
-
const lineWidths = [];
|
|
13648
|
-
let temp = "";
|
|
13649
|
-
let lastWidth = 0;
|
|
13650
|
-
for (let i = 0; i < content.length; i++) {
|
|
13651
|
-
const lineWidth = ctx.measureText(temp).width;
|
|
13652
|
-
if (lineWidth >= contentWidth) {
|
|
13653
|
-
lines.push(temp);
|
|
13654
|
-
lineWidths.push(lineWidth);
|
|
13655
|
-
temp = "";
|
|
13656
|
-
}
|
|
13657
|
-
lastWidth = lineWidth;
|
|
13658
|
-
temp += content[i];
|
|
13659
|
-
}
|
|
13660
|
-
lines.push(temp);
|
|
13661
|
-
lineWidths.push(lastWidth);
|
|
13662
|
-
size.width = contentWidth;
|
|
13663
|
-
size.height = lines.length * lineHeight;
|
|
13664
|
-
return { origin, size, lineHeight, lineWidths, lines, style };
|
|
13665
|
-
}
|
|
13666
|
-
function getAxisPoint(canvasWidth, origin, style) {
|
|
13667
|
-
const padding = (CONTENT_PADDING + DEFAULT_PADDING) * style.scale;
|
|
13668
|
-
let axisPoint = { x: padding, y: origin.y };
|
|
13669
|
-
if (style.position.startsWith("center")) {
|
|
13670
|
-
axisPoint = { x: canvasWidth / 2, y: origin.y };
|
|
13671
|
-
} else if (style.position.startsWith("right")) {
|
|
13672
|
-
axisPoint = { x: canvasWidth - padding, y: origin.y };
|
|
13673
|
-
}
|
|
13674
|
-
return axisPoint;
|
|
13675
|
-
}
|
|
13676
|
-
function getTextAlign(style) {
|
|
13677
|
-
let align = "left";
|
|
13678
|
-
if (style.position.startsWith("center")) {
|
|
13679
|
-
align = "center";
|
|
13680
|
-
} else if (style.position.startsWith("right")) {
|
|
13681
|
-
align = "right";
|
|
13682
|
-
}
|
|
13683
|
-
return align;
|
|
13684
|
-
}
|
|
13685
|
-
function drawLine(canvas, line, origin, style) {
|
|
13686
|
-
const ctx = canvas.getContext("2d");
|
|
13687
|
-
if (!ctx) {
|
|
13688
|
-
return;
|
|
13689
|
-
}
|
|
13690
|
-
ctx.textBaseline = "top";
|
|
13691
|
-
ctx.font = `${style.fontWeight} ${style.fontSize}px ${style.fontName}`;
|
|
13692
|
-
const axisPoint = getAxisPoint(canvas.width, origin, style);
|
|
13693
|
-
ctx.textAlign = getTextAlign(style);
|
|
13694
|
-
if (style.simplified) {
|
|
13695
|
-
ctx.shadowBlur = 4;
|
|
13696
|
-
ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
|
|
13697
|
-
const offset = clamp(style.fontSize / 40, 2, 4);
|
|
13698
|
-
ctx.shadowOffsetY = offset;
|
|
13699
|
-
ctx.shadowOffsetX = offset;
|
|
13700
|
-
ctx.fillStyle = "rgba(255,255,255, 0.5)";
|
|
13701
|
-
} else {
|
|
13702
|
-
ctx.fillStyle = style.fontColor;
|
|
13703
|
-
}
|
|
13704
|
-
ctx.fillText(line, Math.round(axisPoint.x), Math.round(axisPoint.y));
|
|
13705
|
-
}
|
|
13706
|
-
function hexToRGB(hex, alpha) {
|
|
13707
|
-
const r = parseInt(hex.slice(1, 3), 16);
|
|
13708
|
-
const g = parseInt(hex.slice(3, 5), 16);
|
|
13709
|
-
const b = parseInt(hex.slice(5, 7), 16);
|
|
13710
|
-
if (alpha) {
|
|
13711
|
-
return "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
|
|
13712
|
-
}
|
|
13713
|
-
return "rgb(" + r + ", " + g + ", " + b + ")";
|
|
13714
|
-
}
|
|
13715
|
-
function drawBackground(canvas, tile) {
|
|
13716
|
-
const ctx = canvas.getContext("2d");
|
|
13717
|
-
if (!ctx) {
|
|
13718
|
-
return;
|
|
13719
|
-
}
|
|
13720
|
-
let { backgroundColor } = tile.style;
|
|
13721
|
-
let backgroundOpacity = parseDecimal(
|
|
13722
|
-
String(tile.style.backgroundOpacity),
|
|
13723
|
-
-1
|
|
13724
|
-
);
|
|
13725
|
-
if (backgroundOpacity > 255) {
|
|
13726
|
-
backgroundOpacity = 255;
|
|
13727
|
-
}
|
|
13728
|
-
const paddingTop = 2;
|
|
13729
|
-
const paddingBottom = 10;
|
|
13730
|
-
if (backgroundColor !== "transparent") {
|
|
13731
|
-
if (backgroundColor.startsWith("#") && backgroundOpacity >= 0) {
|
|
13732
|
-
backgroundColor = hexToRGB(backgroundColor, backgroundOpacity / 255);
|
|
13733
|
-
}
|
|
13734
|
-
ctx.fillStyle = backgroundColor;
|
|
13735
|
-
const { style } = tile;
|
|
13736
|
-
const padding = (CONTENT_PADDING + DEFAULT_PADDING) * style.scale;
|
|
13737
|
-
const paddingScale = tile.style.fontSize / DEFAULT_FONT_SIZE;
|
|
13738
|
-
for (let j = 0; j < tile.lineWidths.length; j++) {
|
|
13739
|
-
const { lineHeight } = tile;
|
|
13740
|
-
const lineWidth = tile.lineWidths[j];
|
|
13741
|
-
let paddingRight = 30 * paddingScale;
|
|
13742
|
-
let paddingLeft = 10 * paddingScale;
|
|
13743
|
-
let axisPoint = {
|
|
13744
|
-
x: padding - paddingLeft,
|
|
13745
|
-
y: tile.origin.y
|
|
13746
|
-
};
|
|
13747
|
-
if (style.position.startsWith("center")) {
|
|
13748
|
-
paddingLeft = 20 * paddingScale;
|
|
13749
|
-
paddingRight = 20 * paddingScale;
|
|
13750
|
-
axisPoint = {
|
|
13751
|
-
x: (canvas.width - lineWidth) / 2 - paddingLeft,
|
|
13752
|
-
y: tile.origin.y
|
|
13753
|
-
};
|
|
13754
|
-
} else if (style.position.startsWith("right")) {
|
|
13755
|
-
paddingLeft = 30 * paddingScale;
|
|
13756
|
-
paddingRight = 10 * paddingScale;
|
|
13757
|
-
axisPoint = {
|
|
13758
|
-
x: canvas.width - lineWidth - padding - paddingLeft,
|
|
13759
|
-
y: tile.origin.y
|
|
13760
|
-
};
|
|
13761
|
-
}
|
|
13762
|
-
if (j === 0) {
|
|
13763
|
-
ctx.fillRect(
|
|
13764
|
-
axisPoint.x,
|
|
13765
|
-
axisPoint.y - paddingTop > 0 ? axisPoint.y - paddingTop : 0,
|
|
13766
|
-
paddingLeft + lineWidth + paddingRight,
|
|
13767
|
-
paddingTop
|
|
13768
|
-
);
|
|
13769
|
-
}
|
|
13770
|
-
ctx.fillRect(
|
|
13771
|
-
axisPoint.x,
|
|
13772
|
-
axisPoint.y + j * lineHeight,
|
|
13773
|
-
paddingLeft + lineWidth + paddingRight,
|
|
13774
|
-
lineHeight
|
|
13775
|
-
);
|
|
13776
|
-
if (j === tile.lineWidths.length - 1) {
|
|
13777
|
-
ctx.fillRect(
|
|
13778
|
-
axisPoint.x,
|
|
13779
|
-
axisPoint.y + (j + 1) * lineHeight,
|
|
13780
|
-
paddingLeft + lineWidth + paddingRight,
|
|
13781
|
-
paddingBottom
|
|
13782
|
-
);
|
|
13783
|
-
}
|
|
13784
|
-
}
|
|
13785
|
-
}
|
|
13786
|
-
}
|
|
13787
|
-
function drawTile(canvas, tile) {
|
|
13788
|
-
if (!tile.style.simplified) {
|
|
13789
|
-
drawBackground(canvas, tile);
|
|
13790
|
-
}
|
|
13791
|
-
for (let i = 0; i < tile.lines.length; i++) {
|
|
13792
|
-
const origin = {
|
|
13793
|
-
x: tile.origin.x,
|
|
13794
|
-
y: i * tile.lineHeight + tile.origin.y
|
|
13795
|
-
};
|
|
13796
|
-
drawLine(canvas, tile.lines[i], origin, tile.style);
|
|
13797
|
-
}
|
|
13798
|
-
}
|
|
13799
|
-
function drawGroupedWatermarks(canvas, watermarks, groupPosition) {
|
|
13800
|
-
if (!watermarks || watermarks.length === 0) {
|
|
13801
|
-
return;
|
|
13802
|
-
}
|
|
13803
|
-
const tiles = [];
|
|
13804
|
-
let totalHeight = 0;
|
|
13805
|
-
for (let i = 0; i < watermarks.length; i++) {
|
|
13806
|
-
const watermark = watermarks[i];
|
|
13807
|
-
const tile = buildTile(canvas, watermark.content, watermark.style);
|
|
13808
|
-
if (tile) {
|
|
13809
|
-
tiles.push(tile);
|
|
13810
|
-
totalHeight += tile.size.height;
|
|
13811
|
-
}
|
|
13812
|
-
}
|
|
13813
|
-
if (totalHeight <= 0) {
|
|
13814
|
-
console.error("watermarks height " + totalHeight);
|
|
13815
|
-
console.error(JSON.stringify(watermarks));
|
|
13816
|
-
return;
|
|
13817
|
-
}
|
|
13818
|
-
const contentPadding = getCanvasScale(canvas, CONTENT_PADDING);
|
|
13819
|
-
let baseOrigin = { x: contentPadding, y: contentPadding };
|
|
13820
|
-
if (groupPosition === "center") {
|
|
13821
|
-
baseOrigin = {
|
|
13822
|
-
x: contentPadding,
|
|
13823
|
-
y: Math.round((canvas.height - totalHeight) / 2)
|
|
13824
|
-
};
|
|
13825
|
-
} else if (groupPosition === "bottom") {
|
|
13826
|
-
baseOrigin = {
|
|
13827
|
-
x: contentPadding,
|
|
13828
|
-
y: canvas.height - totalHeight - contentPadding
|
|
13829
|
-
};
|
|
13830
|
-
} else if (groupPosition === "top") {
|
|
13831
|
-
baseOrigin = { x: contentPadding, y: contentPadding };
|
|
13832
|
-
}
|
|
13833
|
-
let lastMarginTop = 0;
|
|
13834
|
-
for (let i = 0; i < tiles.length; i++) {
|
|
13835
|
-
const tile = tiles[i];
|
|
13836
|
-
lastMarginTop += tile.style.paddingTop;
|
|
13837
|
-
tile.origin = {
|
|
13838
|
-
x: tile.origin.x + baseOrigin.x,
|
|
13839
|
-
y: lastMarginTop + baseOrigin.y
|
|
13840
|
-
};
|
|
13841
|
-
lastMarginTop += tile.size.height;
|
|
13842
|
-
lastMarginTop += tile.style.paddingBottom;
|
|
13843
|
-
}
|
|
13844
|
-
for (let i = 0; i < tiles.length; i++) {
|
|
13845
|
-
const tile = tiles[i];
|
|
13846
|
-
drawTile(canvas, tile);
|
|
13847
|
-
}
|
|
13848
|
-
}
|
|
13849
|
-
function groupingWatermarks(watermarks) {
|
|
13850
|
-
const topList = [];
|
|
13851
|
-
const centerList = [];
|
|
13852
|
-
const bottomList = [];
|
|
13853
|
-
for (let i = 0; i < watermarks.length; i++) {
|
|
13854
|
-
const watermark = watermarks[i];
|
|
13855
|
-
if (watermark.style.position.endsWith("top")) {
|
|
13856
|
-
topList.push(watermark);
|
|
13857
|
-
} else if (watermark.style.position.endsWith("center")) {
|
|
13858
|
-
centerList.push(watermark);
|
|
13859
|
-
} else if (watermark.style.position.endsWith("bottom")) {
|
|
13860
|
-
bottomList.push(watermark);
|
|
13861
|
-
}
|
|
13862
|
-
}
|
|
13863
|
-
return {
|
|
13864
|
-
[
|
|
13865
|
-
"top"
|
|
13866
|
-
/* Top */
|
|
13867
|
-
]: topList,
|
|
13868
|
-
[
|
|
13869
|
-
"center"
|
|
13870
|
-
/* Center */
|
|
13871
|
-
]: centerList,
|
|
13872
|
-
[
|
|
13873
|
-
"bottom"
|
|
13874
|
-
/* Bottom */
|
|
13875
|
-
]: bottomList
|
|
13876
|
-
};
|
|
13877
|
-
}
|
|
13878
|
-
function renderWatermark(canvas, options) {
|
|
13879
|
-
if (!options.enabled || options.watermarkConfigString === "no") {
|
|
13880
|
-
return Promise.resolve(canvas);
|
|
13881
|
-
}
|
|
13882
|
-
let { watermarkConfigString } = options;
|
|
13883
|
-
if (!isDef(watermarkConfigString) || watermarkConfigString === "default") {
|
|
13884
|
-
watermarkConfigString = "50$lefttop$50*#*time###25$lefttop*#*date";
|
|
13885
|
-
}
|
|
13886
|
-
const watermarks = parseWatermarks(
|
|
13887
|
-
watermarkConfigString,
|
|
13888
|
-
{
|
|
13889
|
-
width: canvas.width,
|
|
13890
|
-
height: canvas.height
|
|
13891
|
-
},
|
|
13892
|
-
options.context
|
|
13893
|
-
);
|
|
13894
|
-
const groupedWatermarks = groupingWatermarks(watermarks);
|
|
13895
|
-
drawGroupedWatermarks(
|
|
13896
|
-
canvas,
|
|
13897
|
-
groupedWatermarks[
|
|
13898
|
-
"top"
|
|
13899
|
-
/* Top */
|
|
13900
|
-
],
|
|
13901
|
-
"top"
|
|
13902
|
-
/* Top */
|
|
13903
|
-
);
|
|
13904
|
-
drawGroupedWatermarks(
|
|
13905
|
-
canvas,
|
|
13906
|
-
groupedWatermarks[
|
|
13907
|
-
"center"
|
|
13908
|
-
/* Center */
|
|
13909
|
-
],
|
|
13910
|
-
"center"
|
|
13911
|
-
/* Center */
|
|
13912
|
-
);
|
|
13913
|
-
drawGroupedWatermarks(
|
|
13914
|
-
canvas,
|
|
13915
|
-
groupedWatermarks[
|
|
13916
|
-
"bottom"
|
|
13917
|
-
/* Bottom */
|
|
13918
|
-
],
|
|
13919
|
-
"bottom"
|
|
13920
|
-
/* Bottom */
|
|
13921
|
-
);
|
|
13922
|
-
return Promise.resolve(canvas);
|
|
13923
|
-
}
|
|
13924
|
-
function checkWatermarkConfigSupported(watermarkConfigString) {
|
|
13925
|
-
if (watermarkConfigString.indexOf("{logo}") > -1) {
|
|
13926
|
-
console.error("水印不支持logo");
|
|
13927
|
-
return false;
|
|
13928
|
-
}
|
|
13929
|
-
const configStringArray = watermarkConfigString.split("###");
|
|
13930
|
-
for (let i = 0; i < configStringArray.length; i++) {
|
|
13931
|
-
const configString = configStringArray[i];
|
|
13932
|
-
const configParts = configString.split("*#*");
|
|
13933
|
-
if (configParts.length === 2) {
|
|
13934
|
-
const styleString = configParts[0];
|
|
13935
|
-
const styleParts = styleString.split("$");
|
|
13936
|
-
if (styleParts.length <= 0) {
|
|
13937
|
-
console.error("水印配置不合法");
|
|
13938
|
-
return false;
|
|
13939
|
-
}
|
|
13940
|
-
}
|
|
13941
|
-
}
|
|
13942
|
-
return true;
|
|
13943
|
-
}
|
|
13944
|
-
var __defProp = Object.defineProperty;
|
|
13945
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13946
|
-
var __publicField = (obj, key, value) => {
|
|
13947
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13948
|
-
return value;
|
|
13949
|
-
};
|
|
13950
|
-
const DEFAULT_JPEG_QUALITY = 0.8;
|
|
13951
|
-
const MIN_JPEG_QUALITY = 0.1;
|
|
13952
|
-
const JPEG_QUALITY_STEP = 0.05;
|
|
13953
|
-
class ImageProcessor {
|
|
13954
|
-
// 压缩图片的配置
|
|
13955
|
-
constructor(file, resizeOptions, watermarkOptions, compressOptions) {
|
|
13956
|
-
__publicField(this, "file");
|
|
13957
|
-
__publicField(this, "resizeOptions");
|
|
13958
|
-
__publicField(this, "watermarkOptions");
|
|
13959
|
-
__publicField(this, "compressOptions");
|
|
13960
|
-
this.file = file;
|
|
13961
|
-
this.resizeOptions = resizeOptions;
|
|
13962
|
-
this.watermarkOptions = watermarkOptions;
|
|
13963
|
-
this.compressOptions = compressOptions;
|
|
13964
|
-
}
|
|
13965
|
-
process() {
|
|
13966
|
-
const filename = this.file.name;
|
|
13967
|
-
let fileType = this.file.type;
|
|
13968
|
-
const { lastModified } = this.file;
|
|
13969
|
-
let orientation = 1;
|
|
13970
|
-
if (this.file.size > this.compressOptions.photoFileSizeLimit * 1024) {
|
|
13971
|
-
fileType = "image/jpeg";
|
|
13972
|
-
}
|
|
13973
|
-
if (isIOS$1() && fileType === "image/jpeg" && getIosVersion() < "13.4") {
|
|
13974
|
-
const reader = new FileReader();
|
|
13975
|
-
reader.readAsArrayBuffer(this.file);
|
|
13976
|
-
reader.onload = function(_ref) {
|
|
13977
|
-
const { target } = _ref;
|
|
13978
|
-
if (target == null ? void 0 : target.result) {
|
|
13979
|
-
orientation = getOrientation(target == null ? void 0 : target.result);
|
|
13980
|
-
}
|
|
13981
|
-
};
|
|
13982
|
-
}
|
|
13983
|
-
if (fileType === "image/gif") {
|
|
13984
|
-
fileType = "image/png";
|
|
13985
|
-
}
|
|
13986
|
-
return file2Image(this.file).then(
|
|
13987
|
-
(img) => (
|
|
13988
|
-
// 第一步 resize image
|
|
13989
|
-
resize(img, {
|
|
13990
|
-
inputType: fileType,
|
|
13991
|
-
orientation,
|
|
13992
|
-
sideLengthLimit: this.resizeOptions.maxSideLength,
|
|
13993
|
-
resultType: "canvas"
|
|
13994
|
-
})
|
|
13995
|
-
)
|
|
13996
|
-
).then((result) => {
|
|
13997
|
-
const canvas = result;
|
|
13998
|
-
return renderWatermark(canvas, this.watermarkOptions);
|
|
13999
|
-
}).then((canvas) => {
|
|
14000
|
-
const exportFilename = filename.replace(/\./g, "-") + ".jpg";
|
|
14001
|
-
return this.compress(
|
|
14002
|
-
canvas,
|
|
14003
|
-
exportFilename,
|
|
14004
|
-
lastModified,
|
|
14005
|
-
fileType,
|
|
14006
|
-
DEFAULT_JPEG_QUALITY
|
|
14007
|
-
);
|
|
14008
|
-
});
|
|
14009
|
-
}
|
|
14010
|
-
compress(canvas, filename, lastModified, type, quality) {
|
|
14011
|
-
return canvas2File(canvas, filename, lastModified, type, quality).then(
|
|
14012
|
-
(file) => {
|
|
14013
|
-
if (file.size > this.compressOptions.photoFileSizeLimit * 1024 && quality - JPEG_QUALITY_STEP > MIN_JPEG_QUALITY) {
|
|
14014
|
-
return this.compress(
|
|
14015
|
-
canvas,
|
|
14016
|
-
filename,
|
|
14017
|
-
lastModified,
|
|
14018
|
-
type,
|
|
14019
|
-
quality - JPEG_QUALITY_STEP
|
|
14020
|
-
);
|
|
14021
|
-
}
|
|
14022
|
-
return Promise.resolve(file);
|
|
14023
|
-
}
|
|
14024
|
-
);
|
|
14025
|
-
}
|
|
14026
|
-
}
|
|
14027
13067
|
const chooseImage = (type) => {
|
|
14028
13068
|
return new Promise((resolve, reject) => {
|
|
14029
13069
|
window.wx.chooseImage({
|
|
@@ -14389,11 +13429,11 @@ var stdin_default$B = vue.defineComponent({
|
|
|
14389
13429
|
};
|
|
14390
13430
|
const transformImageFiles = (files) => {
|
|
14391
13431
|
const promisesTodo = [];
|
|
14392
|
-
const resizeOptions = new ResizeOptions(props.maxImageSideLength);
|
|
14393
|
-
const compressOptions = new CompressOptions(props.maxImageFileSize);
|
|
13432
|
+
const resizeOptions = new appMediaUtils.ResizeOptions(props.maxImageSideLength);
|
|
13433
|
+
const compressOptions = new appMediaUtils.CompressOptions(props.maxImageFileSize);
|
|
14394
13434
|
for (let i = 0; i < files.length; i++) {
|
|
14395
13435
|
const file = files[i];
|
|
14396
|
-
const watermarkEnabled = props.watermarkOptions && props.watermarkOptions.watermarkConfigString && checkWatermarkConfigSupported(props.watermarkOptions.watermarkConfigString);
|
|
13436
|
+
const watermarkEnabled = props.watermarkOptions && props.watermarkOptions.watermarkConfigString && appMediaUtils.checkWatermarkConfigSupported(props.watermarkOptions.watermarkConfigString);
|
|
14397
13437
|
let watermarkOpt;
|
|
14398
13438
|
if (watermarkEnabled) {
|
|
14399
13439
|
watermarkOpt = {
|
|
@@ -14411,7 +13451,7 @@ var stdin_default$B = vue.defineComponent({
|
|
|
14411
13451
|
enabled: false
|
|
14412
13452
|
};
|
|
14413
13453
|
}
|
|
14414
|
-
const promise = new ImageProcessor(file, resizeOptions, watermarkOpt, compressOptions).process().then((f) => {
|
|
13454
|
+
const promise = new appMediaUtils.ImageProcessor(file, resizeOptions, watermarkOpt, compressOptions).process().then((f) => {
|
|
14415
13455
|
if (!f) {
|
|
14416
13456
|
return Promise.resolve(null);
|
|
14417
13457
|
}
|
|
@@ -16403,7 +15443,7 @@ function getColumnsType(columns, fields) {
|
|
|
16403
15443
|
return "default";
|
|
16404
15444
|
}
|
|
16405
15445
|
function findIndexOfEnabledOption(options, index) {
|
|
16406
|
-
index = clamp
|
|
15446
|
+
index = clamp(index, 0, options.length);
|
|
16407
15447
|
for (let i = index; i < options.length; i++) {
|
|
16408
15448
|
if (!options[i].disabled)
|
|
16409
15449
|
return i;
|
|
@@ -16490,7 +15530,7 @@ var stdin_default$o = vue.defineComponent({
|
|
|
16490
15530
|
const baseOffset = () => 0;
|
|
16491
15531
|
const setRangeOffset = (distance) => {
|
|
16492
15532
|
const maxOffsetVal = wrapper.value.clientHeight - props.wrapHeight;
|
|
16493
|
-
currentOffset.value = clamp
|
|
15533
|
+
currentOffset.value = clamp(distance, -maxOffsetVal, 0);
|
|
16494
15534
|
};
|
|
16495
15535
|
const isSearchEmpty = vue.computed(() => {
|
|
16496
15536
|
return !props.options.some((option) => {
|
|
@@ -17749,7 +16789,7 @@ var stdin_default$i = vue.defineComponent({
|
|
|
17749
16789
|
const min = +props.min;
|
|
17750
16790
|
const max = +props.max;
|
|
17751
16791
|
const step = +props.step;
|
|
17752
|
-
value = clamp
|
|
16792
|
+
value = clamp(value, min, max);
|
|
17753
16793
|
const diff = Math.round((value - min) / step) * step;
|
|
17754
16794
|
return addNumber(min, diff);
|
|
17755
16795
|
};
|
|
@@ -18495,7 +17535,7 @@ var stdin_default$e = vue.defineComponent({
|
|
|
18495
17535
|
if (isEdge) {
|
|
18496
17536
|
preventDefault(event, props.stopPropagation);
|
|
18497
17537
|
}
|
|
18498
|
-
state.offset = clamp
|
|
17538
|
+
state.offset = clamp(deltaX.value + startOffset, -rightWidth.value, leftWidth.value);
|
|
18499
17539
|
}
|
|
18500
17540
|
};
|
|
18501
17541
|
const onTouchEnd = () => {
|
|
@@ -20809,7 +19849,7 @@ const Lazyload = {
|
|
|
20809
19849
|
});
|
|
20810
19850
|
}
|
|
20811
19851
|
};
|
|
20812
|
-
const version = "3.1.
|
|
19852
|
+
const version = "3.1.21";
|
|
20813
19853
|
function install(app) {
|
|
20814
19854
|
const components = [
|
|
20815
19855
|
ActionSheet,
|