zartui 1.0.20 → 1.0.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/lib/zart.js CHANGED
@@ -837,27 +837,27 @@ module.exports = g;
837
837
  /* WEBPACK VAR INJECTION */(function(process) {/* harmony import */ var _componentFactory_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(12);
838
838
  //
839
839
 
840
- __webpack_require__(14);
841
-
840
+ __webpack_require__(14);
842
841
 
843
- if ( process.env.VUE_ENV !== 'server' ) {
844
842
 
845
- var pdfjsWrapper = __webpack_require__(31).default;
846
- var PDFJS = window.pdfjsLib;
843
+ if ( process.env.VUE_ENV !== 'server' ) {
847
844
 
848
- if ( typeof window !== 'undefined' && 'Worker' in window && navigator.appVersion.indexOf('MSIE 10') === -1 ) {
845
+ var pdfjsWrapper = __webpack_require__(31).default;
846
+ var PDFJS = window.pdfjsLib;
849
847
 
850
- var PdfjsWorker = __webpack_require__(33);
851
- PDFJS.GlobalWorkerOptions.workerPort = new PdfjsWorker();
852
- }
853
-
854
- var component = Object(_componentFactory_js__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(pdfjsWrapper(PDFJS));
855
- } else {
848
+ if ( typeof window !== 'undefined' && 'Worker' in window && navigator.appVersion.indexOf('MSIE 10') === -1 ) {
856
849
 
857
- var component = Object(_componentFactory_js__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])({});
850
+ var PdfjsWorker = __webpack_require__(33);
851
+ PDFJS.GlobalWorkerOptions.workerPort = new PdfjsWorker();
858
852
  }
859
853
 
860
- /* harmony default export */ __webpack_exports__["a"] = (component);
854
+ var component = Object(_componentFactory_js__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(pdfjsWrapper(PDFJS));
855
+ } else {
856
+
857
+ var component = Object(_componentFactory_js__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])({});
858
+ }
859
+
860
+ /* harmony default export */ __webpack_exports__["a"] = (component);
861
861
 
862
862
  /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(13)))
863
863
 
@@ -1096,8 +1096,8 @@ function normalizeComponent (
1096
1096
 
1097
1097
  // CONCATENATED MODULE: ./node_modules/vue-resize-sensor/src/resize-sensor.vue?vue&type=script&lang=js&
1098
1098
  /* harmony default export */ var src_resize_sensorvue_type_script_lang_js_ = (resize_sensorvue_type_script_lang_js_);
1099
- // EXTERNAL MODULE: ./node_modules/vue-resize-sensor/src/resize-sensor.vue?vue&type=style&index=0&id=38cddd49&prod&lang=css&
1100
- var resize_sensorvue_type_style_index_0_id_38cddd49_prod_lang_css_ = __webpack_require__(29);
1099
+ // EXTERNAL MODULE: ./node_modules/vue-resize-sensor/src/resize-sensor.vue?vue&type=style&index=0&lang=css&
1100
+ var resize_sensorvue_type_style_index_0_lang_css_ = __webpack_require__(29);
1101
1101
 
1102
1102
  // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
1103
1103
  var componentNormalizer = __webpack_require__(11);
@@ -46839,8 +46839,8 @@ module.exports = Array.isArray || function (arr) {
46839
46839
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
46840
46840
 
46841
46841
  "use strict";
46842
- /* harmony import */ var _style_loader_dist_cjs_js_css_loader_dist_cjs_js_vue_loader_lib_loaders_stylePostLoader_js_postcss_loader_src_index_js_ref_3_2_cache_loader_dist_cjs_js_ref_0_0_vue_loader_lib_index_js_vue_loader_options_resize_sensor_vue_vue_type_style_index_0_id_38cddd49_prod_lang_css___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(15);
46843
- /* harmony import */ var _style_loader_dist_cjs_js_css_loader_dist_cjs_js_vue_loader_lib_loaders_stylePostLoader_js_postcss_loader_src_index_js_ref_3_2_cache_loader_dist_cjs_js_ref_0_0_vue_loader_lib_index_js_vue_loader_options_resize_sensor_vue_vue_type_style_index_0_id_38cddd49_prod_lang_css___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_style_loader_dist_cjs_js_css_loader_dist_cjs_js_vue_loader_lib_loaders_stylePostLoader_js_postcss_loader_src_index_js_ref_3_2_cache_loader_dist_cjs_js_ref_0_0_vue_loader_lib_index_js_vue_loader_options_resize_sensor_vue_vue_type_style_index_0_id_38cddd49_prod_lang_css___WEBPACK_IMPORTED_MODULE_0__);
46842
+ /* harmony import */ var _style_loader_dist_cjs_js_css_loader_dist_cjs_js_vue_loader_lib_loaders_stylePostLoader_js_postcss_loader_src_index_js_ref_3_2_cache_loader_dist_cjs_js_ref_0_0_vue_loader_lib_index_js_vue_loader_options_resize_sensor_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(15);
46843
+ /* harmony import */ var _style_loader_dist_cjs_js_css_loader_dist_cjs_js_vue_loader_lib_loaders_stylePostLoader_js_postcss_loader_src_index_js_ref_3_2_cache_loader_dist_cjs_js_ref_0_0_vue_loader_lib_index_js_vue_loader_options_resize_sensor_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_style_loader_dist_cjs_js_css_loader_dist_cjs_js_vue_loader_lib_loaders_stylePostLoader_js_postcss_loader_src_index_js_ref_3_2_cache_loader_dist_cjs_js_ref_0_0_vue_loader_lib_index_js_vue_loader_options_resize_sensor_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0__);
46844
46844
  /* unused harmony reexport * */
46845
46845
 
46846
46846
 
@@ -55012,8 +55012,8 @@ module.exports = function() {
55012
55012
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
55013
55013
 
55014
55014
  "use strict";
55015
- /* harmony import */ var _style_loader_dist_cjs_js_css_loader_dist_cjs_js_vue_loader_lib_loaders_stylePostLoader_js_postcss_loader_src_index_js_ref_3_2_annotationLayer_css_vue_type_style_index_0_prod_lang_css___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(18);
55016
- /* harmony import */ var _style_loader_dist_cjs_js_css_loader_dist_cjs_js_vue_loader_lib_loaders_stylePostLoader_js_postcss_loader_src_index_js_ref_3_2_annotationLayer_css_vue_type_style_index_0_prod_lang_css___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_style_loader_dist_cjs_js_css_loader_dist_cjs_js_vue_loader_lib_loaders_stylePostLoader_js_postcss_loader_src_index_js_ref_3_2_annotationLayer_css_vue_type_style_index_0_prod_lang_css___WEBPACK_IMPORTED_MODULE_0__);
55015
+ /* harmony import */ var _style_loader_dist_cjs_js_css_loader_dist_cjs_js_vue_loader_lib_loaders_stylePostLoader_js_postcss_loader_src_index_js_ref_3_2_annotationLayer_css_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(18);
55016
+ /* harmony import */ var _style_loader_dist_cjs_js_css_loader_dist_cjs_js_vue_loader_lib_loaders_stylePostLoader_js_postcss_loader_src_index_js_ref_3_2_annotationLayer_css_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_style_loader_dist_cjs_js_css_loader_dist_cjs_js_vue_loader_lib_loaders_stylePostLoader_js_postcss_loader_src_index_js_ref_3_2_annotationLayer_css_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0__);
55017
55017
  /* unused harmony reexport * */
55018
55018
 
55019
55019
 
@@ -74804,1036 +74804,1272 @@ function checkIsWindows() {
74804
74804
 
74805
74805
  //# sourceMappingURL=index.js.map
74806
74806
  // CONCATENATED MODULE: ./node_modules/@egova/media/lib/watermark.js
74807
- /**
74808
- * 水印配置 {@link http://faq.egova.com.cn:7777/projects/redmine/wiki/%E6%8B%8D%E7%85%A7%E6%B0%B4%E5%8D%B0%E9%85%8D%E7%BD%AE|文档}
74809
- * @description 水印渲染类
74810
- * @author Jiaji Yin
74811
- * @date 2021-11-05
74812
- */
74813
-
74814
- var Point = /** @class */ (function () {
74815
- function Point(x, y) {
74816
- this.x = x;
74817
- this.y = y;
74818
- }
74819
- return Point;
74820
- }());
74821
- var Size = /** @class */ (function () {
74822
- function Size(width, height) {
74823
- this.width = width;
74824
- this.height = height;
74825
- }
74826
- return Size;
74827
- }());
74828
- var clamp = function (value, min, max) { return Math.min(Math.max(value, min), max); };
74829
- var subString = function (str, startIndex, length) {
74830
- if (checkIsUndefinedOrNull(length)) {
74831
- return str.substring(startIndex);
74832
- }
74833
- else {
74834
- return str.substring(startIndex, startIndex + length);
74835
- }
74836
- };
74837
- /**
74838
- * {@link http://faq.egova.com.cn:7777/files/ueditor/image/20180621/1529574697677847.png|水印位置图}
74839
- */
74840
- var WatermarkPosition;
74841
- (function (WatermarkPosition) {
74842
- WatermarkPosition["LeftTop"] = "lefttop";
74843
- WatermarkPosition["CenterTop"] = "centertop";
74844
- WatermarkPosition["RightTop"] = "righttop";
74845
- WatermarkPosition["LeftCenter"] = "leftcenter";
74846
- WatermarkPosition["Center"] = "center";
74847
- WatermarkPosition["RightCenter"] = "rightcenter";
74848
- WatermarkPosition["LeftBottom"] = "leftbottom";
74849
- WatermarkPosition["CenterBottom"] = "centerbottom";
74850
- WatermarkPosition["RightBottom"] = "rightbottom";
74851
- })(WatermarkPosition || (WatermarkPosition = {}));
74852
- var WatermarkFontWeight;
74853
- (function (WatermarkFontWeight) {
74854
- WatermarkFontWeight["Normal"] = "normal";
74855
- WatermarkFontWeight["Bold"] = "bold";
74856
- })(WatermarkFontWeight || (WatermarkFontWeight = {}));
74857
- var DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
74858
- var DEFAULT_TIME_FORMAT = "HH:mm";
74859
- var WatermarkContent;
74860
- (function (WatermarkContent) {
74861
- WatermarkContent["Raw"] = "";
74862
- WatermarkContent["Date"] = "date{(.*?)}|date";
74863
- WatermarkContent["Time"] = "time";
74864
- WatermarkContent["Address"] = "address";
74865
- WatermarkContent["HumanName"] = "humanname";
74866
- WatermarkContent["ProjectName"] = "projectName";
74867
- WatermarkContent["Logo"] = "{logo}";
74868
- })(WatermarkContent || (WatermarkContent = {}));
74869
- var ColorMap = {
74870
- "transparent": "#00000000",
74871
- "white": "#FFFFFF",
74872
- "black": "#000000",
74873
- "darkgray": "#444444",
74874
- "gray": "#888888",
74875
- "lightgray": "#CCCCCC",
74876
- "darkgrey": "#444444",
74877
- "grey": "#888888",
74878
- "lightgrey": "#CCCCCC",
74879
- "red": "#FF0000",
74880
- "green": "#00FF00",
74881
- "blue": "#0000FF",
74882
- "yellow": "#FFFF00",
74883
- "cyan": "#00FFFF",
74884
- "magenta": "#FF00FF",
74885
- "aqua": "#00FFFF",
74886
- "fuchsia": "#FF00FF",
74887
- "lime": "#00FF00",
74888
- "maroon": "#800000",
74889
- "navy": "#000080",
74890
- "olive": "#808000",
74891
- "purple": "#800080",
74892
- "silver": "#C0C0C0",
74893
- "teal": "#008080",
74894
- "orange": "#FF9933",
74895
- };
74896
- function getColorValue(key) {
74897
- for (var _i = 0, _a = Object.getOwnPropertyNames(ColorMap); _i < _a.length; _i++) {
74898
- var k = _a[_i];
74899
- if (k === key) {
74900
- return ColorMap[k];
74901
- }
74902
- }
74903
- return null;
74904
- }
74905
- var CONTENT_PADDING = 10;
74906
- var DEFAULT_PADDING = 2;
74907
- var DEFAULT_FONT_SIZE = 25.0;
74908
- var DEFAULT_CANVAS_SIZE = 480.0;
74909
- var DEFAULT_BACKGROUND_OPACITY = 128;
74910
- var WatermarkStyle = /** @class */ (function () {
74911
- /**
74912
- * Watermark Style
74913
- * @param fontName
74914
- * @param fontWeight
74915
- * @param fontColor
74916
- * @param fontSize
74917
- * @param backgroundColor
74918
- * @param backgroundOpacity
74919
- * @param paddingTop
74920
- * @param paddingBottom
74921
- * @param position
74922
- * @param scale
74923
- * @param simplified
74924
- */
74925
- function WatermarkStyle(fontName, fontWeight, fontColor, fontSize, backgroundColor, backgroundOpacity, paddingTop, paddingBottom, position, scale, simplified) {
74926
- this.fontName = fontName;
74927
- this.fontWeight = fontWeight;
74928
- this.fontColor = fontColor;
74929
- this.fontSize = fontSize;
74930
- this.backgroundColor = backgroundColor;
74931
- this.backgroundOpacity = backgroundOpacity;
74932
- this.paddingTop = paddingTop;
74933
- this.paddingBottom = paddingBottom;
74934
- this.position = position;
74935
- this.scale = scale;
74936
- this.simplified = simplified;
74937
- }
74938
- return WatermarkStyle;
74939
- }());
74940
- var WatermarkImage = /** @class */ (function () {
74941
- function WatermarkImage(image) {
74942
- this.image = image;
74943
- }
74944
- return WatermarkImage;
74945
- }());
74946
- var Watermark = /** @class */ (function () {
74947
- /**
74948
- * 水印对象,包含需要渲染的文本、图像,以及相应的style
74949
- * @param content
74950
- * @param watermarkStyle
74951
- */
74952
- function Watermark(content, watermarkStyle) {
74953
- this.content = content;
74954
- this.style = watermarkStyle;
74955
- }
74956
- return Watermark;
74957
- }());
74958
- var WatermarkContext = /** @class */ (function () {
74959
- /**
74960
- * 打水印需要的环境信息
74961
- * @param address
74962
- * @param watermarkTime
74963
- * @param humanName
74964
- * @param projectName
74965
- * @param logo
74966
- */
74967
- function WatermarkContext(params) {
74968
- this.address = params.address;
74969
- this.watermarkTime = params.watermarkTime;
74970
- this.humanName = params.humanName;
74971
- this.projectName = params.projectName;
74972
- this.logo = params.logo;
74973
- }
74974
- return WatermarkContext;
74975
- }());
74976
-
74977
- var WatermarkOptions = /** @class */ (function () {
74978
- /**
74979
- * 水印配置项
74980
- * @param enabled, 是否开启水印
74981
- * @param watermarkConfigString,水印配置的字符串
74982
- * @param context,打水印需要的环境信息
74983
- */
74984
- function WatermarkOptions(params) {
74985
- this.enabled = params.enabled;
74986
- this.watermarkConfigString = params.watermarkConfigString;
74987
- this.context = params.context;
74988
- }
74989
- return WatermarkOptions;
74990
- }());
74991
-
74992
- function parseWatermarkStyle(styleString, canvasSize) {
74993
- if (!checkIsStringValid(styleString)) {
74994
- return null;
74995
- }
74996
- var styleParts = styleString.split("$");
74997
- if (styleParts.length <= 0) {
74998
- return null;
74999
- }
75000
- var scale = Math.min(canvasSize.width, canvasSize.height) / DEFAULT_CANVAS_SIZE;
75001
- /**
75002
- 1. 20190314版本开始可以使用简化版配置,格式为[文字大小]$[水印位置]$[上下padding]*#*[水印内容] 其中[上下padding]一般不设置,如需设置,格式为"上padding_下padding",下padding可省略
75003
- 2. 简化版配置使用条件:字体(黑体)、字体样式(normal)、文字颜色(transparent)、背景颜色(transparent)、背景不透明度(128)全部使用默认值(括号中的值)
75004
- */
75005
- if (parseInteger(styleParts[0], -1) !== -1) { // 第一项为数字,则为新的简化配置
75006
- var fontSize = Math.round(parseDecimal(styleParts[0], DEFAULT_FONT_SIZE) * scale);
75007
- var position = WatermarkPosition.LeftTop;
75008
- if (styleParts[1]) {
75009
- position = styleParts[1];
75010
- }
75011
- var paddingTop = DEFAULT_PADDING * scale;
75012
- var paddingBottom = DEFAULT_PADDING * scale;
75013
- if (styleParts[2]) {
75014
- var paddingParts = styleParts[2].split("_");
75015
- paddingTop = parseInteger(paddingParts[0], DEFAULT_PADDING) * scale;
75016
- if (paddingParts[1]) {
75017
- paddingBottom = parseInteger(paddingParts[1], DEFAULT_PADDING) * scale;
75018
- }
75019
- }
75020
- var fontName = getHeitiFontFamily();
75021
- var fontWeight = WatermarkFontWeight.Normal;
75022
- var fontColor = ColorMap.transparent;
75023
- var backgroundColor = ColorMap.transparent;
75024
- var backgroundOpacity = 128;
75025
- return new WatermarkStyle(fontName, fontWeight, fontColor, fontSize, backgroundColor, backgroundOpacity, paddingTop, paddingBottom, position, scale, true);
75026
- }
75027
- else { // [字体]$[文字样式]$[文字颜色]$[文字大小]$[背景颜色]$[水印位置]$[背景不透明度]$[上下padding]*#*[水印内容]
75028
- var fontName = styleParts[0] + ', ' + getHeitiFontFamily();
75029
- var fontWeight = WatermarkFontWeight.Normal;
75030
- if (styleParts[1]) {
75031
- fontWeight = styleParts[1];
75032
- }
75033
- var fontColor = ColorMap.white;
75034
- if (styleParts[2]) {
75035
- var color = getColorValue(styleParts[2]);
75036
- if (color) {
75037
- fontColor = color;
75038
- }
75039
- }
75040
- var fontSize = Math.round(DEFAULT_FONT_SIZE * scale);
75041
- if (styleParts[3]) {
75042
- fontSize = Math.round(parseDecimal(styleParts[3], DEFAULT_FONT_SIZE) * scale);
75043
- }
75044
- var backgroundColor = ColorMap.blue;
75045
- if (styleParts[4]) {
75046
- var color = getColorValue(styleParts[4]);
75047
- if (color) {
75048
- backgroundColor = color;
75049
- }
75050
- }
75051
- var position = WatermarkPosition.LeftTop;
75052
- if (styleParts[5]) {
75053
- position = styleParts[5];
75054
- }
75055
- var backgroundOpacity = 255;
75056
- if (styleParts[6]) {
75057
- var opacity = parseInteger(styleParts[6], DEFAULT_BACKGROUND_OPACITY);
75058
- opacity = clamp(opacity, 0, 255);
75059
- backgroundOpacity = opacity;
75060
- }
75061
- var paddingTop = DEFAULT_PADDING * scale;
75062
- var paddingBottom = DEFAULT_PADDING * scale;
75063
- if (styleParts[7]) {
75064
- var paddingParts = styleParts[7].split("_");
75065
- paddingTop = parseInteger(paddingParts[0], DEFAULT_PADDING) * scale;
75066
- if (paddingParts[1]) {
75067
- paddingBottom = parseInteger(paddingParts[1], DEFAULT_PADDING) * scale;
75068
- }
75069
- }
75070
- return new WatermarkStyle(fontName, fontWeight, fontColor, fontSize, backgroundColor, backgroundOpacity, paddingTop, paddingBottom, position, scale, false);
75071
- }
75072
- }
75073
- /**
75074
- * A JavaScript Scanner like Java's
75075
- * @see java.util.Scanner
75076
- */
75077
- var watermark_TextScanner = /** @class */ (function () {
75078
- /**
75079
- * The content to scan
75080
- * @param text
75081
- */
75082
- function TextScanner(text) {
75083
- this.text = text;
75084
- this.cursor = 0;
75085
- }
75086
- TextScanner.prototype.hasNext = function (obj) {
75087
- if (checkIsUndefinedOrNull(obj)) {
75088
- return this.cursor < this.text.length;
75089
- }
75090
- else if (checkIsString(obj)) {
75091
- var str = obj;
75092
- var current = subString(this.text, this.cursor, str.length);
75093
- if (current === str) {
75094
- return true;
75095
- }
75096
- }
75097
- else if (checkIsRegExp(obj)) {
75098
- var regex = obj;
75099
- var subText = subString(this.text, this.cursor);
75100
- var matchResults = subText.match(regex);
75101
- if (matchResults) {
75102
- if (matchResults.index === 0) {
75103
- return true;
75104
- }
75105
- }
75106
- }
75107
- return false;
75108
- };
75109
- TextScanner.prototype.next = function (obj) {
75110
- if (checkIsUndefinedOrNull(obj)) {
75111
- return subString(this.text, this.cursor, 1);
75112
- }
75113
- else if (checkIsString(obj)) {
75114
- var str = obj;
75115
- if (subString(this.text, this.cursor, str.length) === str) {
75116
- return str;
75117
- }
75118
- }
75119
- else if (checkIsRegExp(obj)) {
75120
- var regex = obj;
75121
- var subText = subString(this.text, this.cursor);
75122
- var matchResults = subText.match(regex);
75123
- if (matchResults) {
75124
- if (matchResults.index === 0) {
75125
- return matchResults;
75126
- }
75127
- }
75128
- }
75129
- return null;
75130
- };
75131
- TextScanner.prototype.skip = function (obj) {
75132
- if (checkIsUndefinedOrNull(obj)) {
75133
- this.cursor += 1;
75134
- }
75135
- else if (checkIsStringValid(obj)) {
75136
- var str = obj;
75137
- this.cursor += str.length;
75138
- }
75139
- return this;
75140
- };
75141
- return TextScanner;
75142
- }());
75143
-
75144
- function buildContent(contentConfigString, watermarkContext) {
75145
- var content = "";
75146
- var scanner = new watermark_TextScanner(contentConfigString);
75147
- var steps = 0;
75148
- while (scanner.hasNext() &&
75149
- /* 防止scanner代码错误产生无限循环,设置一个最大scan步数*/
75150
- steps < contentConfigString.length) {
75151
- var dateRegex = new RegExp(WatermarkContent.Date);
75152
- if (scanner.hasNext(dateRegex)) {
75153
- var regexResult = scanner.next(dateRegex);
75154
- if (regexResult) {
75155
- var matchResults = regexResult;
75156
- var format = date_FORMAT.FORMAT_YMD;
75157
- if (matchResults && matchResults.length >= 2) {
75158
- if (checkIsStringValid(matchResults[1])) {
75159
- format = matchResults[1];
75160
- }
75161
- }
75162
- content += date_formatDate(watermarkContext.watermarkTime, format);
75163
- scanner.skip(matchResults.input);
75164
- }
75165
- }
75166
- else if (scanner.hasNext(WatermarkContent.Time)) {
75167
- var value = date_formatDate(watermarkContext.watermarkTime, date_FORMAT.FORMAT_HM);
75168
- content += value;
75169
- scanner.skip(WatermarkContent.Time);
75170
- }
75171
- else if (scanner.hasNext(WatermarkContent.Address)) {
75172
- content += watermarkContext.address;
75173
- scanner.skip(WatermarkContent.Address);
75174
- }
75175
- else if (scanner.hasNext(WatermarkContent.HumanName)) {
75176
- content += watermarkContext.humanName;
75177
- scanner.skip(WatermarkContent.HumanName);
75178
- }
75179
- else if (scanner.hasNext(WatermarkContent.ProjectName)) {
75180
- content += watermarkContext.projectName;
75181
- scanner.skip(WatermarkContent.ProjectName);
75182
- }
75183
- else if (scanner.hasNext(WatermarkContent.Logo)) {
75184
- console.error("watermark logo ignored");
75185
- scanner.skip(WatermarkContent.Logo);
75186
- }
75187
- else {
75188
- var nextChar = scanner.next();
75189
- // console.log(`next out "${nextChar}"`)
75190
- if (checkIsString(nextChar)) {
75191
- // console.log(`next in "${nextChar}"`)
75192
- content += nextChar;
75193
- }
75194
- scanner.skip();
75195
- }
75196
- steps++;
75197
- }
75198
- return content;
75199
- }
75200
- function parseWatermarks(watermarkConfigString, canvasSize, watermarkContext) {
75201
- var watermarks = [];
75202
- var configStringArray = watermarkConfigString.split("###");
75203
- for (var i = 0; i < configStringArray.length; i++) {
75204
- var configString = configStringArray[i];
75205
- //console.log('config string ' + configString);
75206
- var configParts = configString.split("*#*");
75207
- //console.log(JSON.stringify(configParts));
75208
- if (configParts.length === 2) {
75209
- var styleString = configParts[0];
75210
- var contentString = configParts[1];
75211
- var style = parseWatermarkStyle(styleString, canvasSize);
75212
- var content = buildContent(contentString, watermarkContext);
75213
- if (style && content) {
75214
- var watermark = new Watermark(content, style);
75215
- watermarks.push(watermark);
75216
- }
75217
- }
75218
- }
75219
- return watermarks;
75220
- }
75221
- /**
75222
- * 画水印默认使用黑体
75223
- * @see {@link https://www.zhihu.com/question/19911793|使用黑体}
75224
- */
75225
- function getHeitiFontFamily() {
75226
- if (checkIsAndroid()) {
75227
- return "'Roboto Black', 'Droid Sans'";
75228
- }
75229
- else if (checkIsIOS()) {
75230
- return "'PingFang SC Medium'";
75231
- }
75232
- else {
75233
- return '"PingFang SC Medium", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif';
75234
- }
75235
- }
75236
- /**
75237
- * 可以渲染的内容
75238
- */
75239
- var Tile = /** @class */ (function () {
75240
- function Tile(origin, size, lineHeight, lineWidths, lines, style) {
75241
- this.origin = origin;
75242
- this.size = size;
75243
- this.lineHeight = lineHeight;
75244
- this.lineWidths = lineWidths;
75245
- this.lines = lines;
75246
- this.style = style;
75247
- }
75248
- return Tile;
75249
- }());
75250
- function buildTile(canvas, content, style) {
75251
- var origin = new Point(0, 0);
75252
- var size = new Size(0, 0);
75253
- var lines = [];
75254
- var ctx = canvas.getContext("2d");
75255
- if (!ctx) {
75256
- return null;
75257
- }
75258
- ctx.font = style.fontWeight + " " + style.fontSize + "px " + style.fontName;
75259
- var contentPadding = getCanvasScale(canvas, CONTENT_PADDING);
75260
- var contentWidth = canvas.width - contentPadding * 2;
75261
- // @see {@link https://stackoverflow.com/questions/1134586/how-can-you-find-the-height-of-text-on-an-html-canvas}
75262
- var lineHeight = ctx.measureText('M').width;
75263
- var lineWidths = [];
75264
- // content超过宽度就换行
75265
- var temp = "";
75266
- var lastWidth = 0;
75267
- for (var i = 0; i < content.length; i++) {
75268
- var lineWidth = ctx.measureText(temp).width;
75269
- if (lineWidth >= contentWidth) {
75270
- lines.push(temp);
75271
- lineWidths.push(lineWidth);
75272
- temp = "";
75273
- }
75274
- lastWidth = lineWidth;
75275
- temp += content[i];
75276
- }
75277
- lines.push(temp);
75278
- lineWidths.push(lastWidth);
75279
- size.width = contentWidth;
75280
- size.height = lines.length * lineHeight;
75281
- return new Tile(origin, size, lineHeight, lineWidths, lines, style);
75282
- }
75283
- /**
75284
- * 画文字,默认{@link https://stackoverflow.com/questions/43242709/how-can-i-draw-text-that-looks-embossed-using-kinetic-js-and-canvas|浮雕效果}
75285
- * @param canvas
75286
- * @param text
75287
- */
75288
- // function getEmbossTextImageData(text: string, size: Size): ImageData | null {
75289
- // // constants
75290
- // const canvas = document.createElement('canvas');
75291
- // document.body.appendChild(canvas);
75292
- // const ctx = canvas.getContext("2d");
75293
- // if (!ctx) {
75294
- // return null
75295
- // }
75296
- //
75297
- // canvas.width = size.width;
75298
- // canvas.height = size.height;
75299
- //
75300
- // // constants
75301
- // const blur = 2;
75302
- // const highLight = "rgba(100,190,256,0.75)";
75303
- // const shadow = "rgba(0,0,0,0.65)";
75304
- // const font = "84px arial black";
75305
- // const background = "linear-gradient(to right, #1e5799 0%,#3096e5 100%)";
75306
- // const border = "2px solid #6CF"
75307
- //
75308
- // // create canvas add styles and put on page
75309
- //
75310
- // const w = (canvas.width = innerWidth - 24) / 2; // set size and get centers
75311
- // const h = (canvas.height = innerHeight - 24) / 2;
75312
- // canvas.style.background = background;
75313
- // canvas.style.border = border;
75314
- //
75315
- //
75316
- // // set up font and font rendering alignment
75317
- // ctx.font = font;
75318
- // ctx.textAlign = "center";
75319
- // ctx.textBaseline = "middle";
75320
- //
75321
- // // draw dark shadow
75322
- // ctx.shadowBlur = blur; // shadow
75323
- // ctx.fillStyle = ctx.shadowColor = shadow;
75324
- // ctx.shadowOffsetY = ctx.shadowOffsetX = blur;
75325
- // ctx.fillText(text, w, h);
75326
- //
75327
- // // draw highLight
75328
- // ctx.fillStyle = ctx.shadowColor = highLight;
75329
- // ctx.shadowOffsetY = ctx.shadowOffsetX = -blur;
75330
- // ctx.fillText(text, w, h);
75331
- //
75332
- // // draw center text that removes pixels
75333
- // ctx.shadowColor = "rgba(0,0,0,0.0)"; // turn off shadow
75334
- // ctx.fillStyle = "black";
75335
- // ctx.globalCompositeOperation = "destination-out"; // New pixels will remove old pixels making them transparent
75336
- // ctx.fillText(text, w, h);
75337
- // ctx.globalCompositeOperation = "source-over"; // restore default composite operation.
75338
- //
75339
- // return ctx.getImageData(0, 0, size.width, size.height)
75340
- // }
75341
- function getAxisPoint(canvasWidth, origin, style) {
75342
- var padding = (CONTENT_PADDING + DEFAULT_PADDING) * style.scale;
75343
- var axisPoint = new Point(padding, origin.y);
75344
- if (style.position.startsWith("center")) {
75345
- axisPoint = new Point(canvasWidth / 2, origin.y);
75346
- }
75347
- else if (style.position.startsWith("right")) {
75348
- axisPoint = new Point(canvasWidth - padding, origin.y);
75349
- }
75350
- return axisPoint;
75351
- }
75352
- function getTextAlign(style) {
75353
- var align = "left";
75354
- if (style.position.startsWith("center")) {
75355
- align = "center";
75356
- }
75357
- else if (style.position.startsWith("right")) {
75358
- align = "right";
75359
- }
75360
- return align;
75361
- }
75362
- function drawLine(canvas, line, origin, style) {
75363
- var ctx = canvas.getContext("2d");
75364
- if (!ctx) {
75365
- return;
75366
- }
75367
- /**
75368
- * The fillText's second argument is the Y coordinate for the baseline of the text (the default textBaseline is "alphabetic") ,
75369
- * so the text is being drawn above the visible canvas element when you use 0.
75370
- * @see {@link https://stackoverflow.com/questions/14289331/html5-canvas-doesnt-fill-text-at-coordinates-0-0}
75371
- */
75372
- ctx.textBaseline = "top";
75373
- ctx.font = style.fontWeight + " " + style.fontSize + "px " + style.fontName;
75374
- var axisPoint = getAxisPoint(canvas.width, origin, style);
75375
- ctx.textAlign = getTextAlign(style);
75376
- if (style.simplified) {
75377
- ctx.shadowBlur = 4; // shadow
75378
- // ctx.shadowColor = "rgba(220,220,220,0.75)";
75379
- ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
75380
- var offset = clamp(style.fontSize / 40, 2, 4);
75381
- ctx.shadowOffsetY = offset;
75382
- ctx.shadowOffsetX = offset;
75383
- ctx.fillStyle = "rgba(255,255,255, 0.5)";
75384
- }
75385
- else {
75386
- ctx.fillStyle = style.fontColor;
75387
- }
75388
- ctx.fillText(line, Math.round(axisPoint.x), Math.round(axisPoint.y));
75389
- }
75390
- function hexToRGB(hex, alpha) {
75391
- var r = parseInt(hex.slice(1, 3), 16), g = parseInt(hex.slice(3, 5), 16), b = parseInt(hex.slice(5, 7), 16);
75392
- if (alpha) {
75393
- return "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
75394
- }
75395
- else {
75396
- return "rgb(" + r + ", " + g + ", " + b + ")";
75397
- }
75398
- }
75399
- function drawBackground(canvas, tile) {
75400
- var ctx = canvas.getContext("2d");
75401
- if (!ctx) {
75402
- return;
75403
- }
75404
- var backgroundColor = tile.style.backgroundColor;
75405
- var backgroundOpacity = parseDecimal(String(tile.style.backgroundOpacity), -1);
75406
- if (backgroundOpacity > 255) {
75407
- backgroundOpacity = 255;
75408
- }
75409
- var paddingTop = 2;
75410
- var paddingBottom = 10;
75411
- if (backgroundColor !== 'transparent') {
75412
- if (backgroundColor.startsWith("#") && backgroundOpacity >= 0) {
75413
- backgroundColor = hexToRGB(backgroundColor, backgroundOpacity / 255.0);
75414
- }
75415
- ctx.fillStyle = backgroundColor;
75416
- var style = tile.style;
75417
- var padding = (CONTENT_PADDING + DEFAULT_PADDING) * style.scale;
75418
- var paddingScale = tile.style.fontSize / DEFAULT_FONT_SIZE;
75419
- for (var j = 0; j < tile.lineWidths.length; j++) {
75420
- var lineHeight = tile.lineHeight;
75421
- var lineWidth = tile.lineWidths[j];
75422
- var paddingRight = 30 * paddingScale;
75423
- var paddingLeft = 10 * paddingScale;
75424
- var axisPoint = new Point(padding - paddingLeft, tile.origin.y);
75425
- if (style.position.startsWith("center")) {
75426
- paddingLeft = 20 * paddingScale;
75427
- paddingRight = 20 * paddingScale;
75428
- axisPoint = new Point((canvas.width - lineWidth) / 2 - paddingLeft, tile.origin.y);
75429
- }
75430
- else if (style.position.startsWith("right")) {
75431
- paddingLeft = 30 * paddingScale;
75432
- paddingRight = 10 * paddingScale;
75433
- axisPoint = new Point(canvas.width - lineWidth - padding - paddingLeft, tile.origin.y);
75434
- }
75435
- // padding top
75436
- if (j === 0) {
75437
- ctx.fillRect(axisPoint.x, (axisPoint.y - paddingTop > 0) ? (axisPoint.y - paddingTop) : 0, paddingLeft + lineWidth + paddingRight, paddingTop);
75438
- }
75439
- ctx.fillRect(axisPoint.x, axisPoint.y + j * lineHeight, paddingLeft + lineWidth + paddingRight, lineHeight);
75440
- // padding bottom
75441
- if (j === tile.lineWidths.length - 1) {
75442
- ctx.fillRect(axisPoint.x, axisPoint.y + (j + 1) * lineHeight, paddingLeft + lineWidth + paddingRight, paddingBottom);
75443
- }
75444
- }
75445
- }
75446
- }
75447
- function drawTile(canvas, tile) {
75448
- if (!tile.style.simplified) { // 复杂配置绘制背景颜色
75449
- drawBackground(canvas, tile);
75450
- }
75451
- for (var i = 0; i < tile.lines.length; i++) {
75452
- var origin_1 = new Point(tile.origin.x, i * tile.lineHeight + tile.origin.y);
75453
- drawLine(canvas, tile.lines[i], origin_1, tile.style);
75454
- }
75455
- }
75456
- function getCanvasScale(canvas, len) {
75457
- var min = Math.min(canvas.width, canvas.height);
75458
- return min / DEFAULT_CANVAS_SIZE * len;
75459
- }
75460
- var GroupPosition;
75461
- (function (GroupPosition) {
75462
- GroupPosition["Top"] = "top";
75463
- GroupPosition["Center"] = "center";
75464
- GroupPosition["Bottom"] = "bottom";
75465
- })(GroupPosition || (GroupPosition = {}));
75466
- function drawGroupedWatermarks(canvas, watermarks, groupPosition) {
75467
- if (!watermarks || watermarks.length === 0) {
75468
- return;
75469
- }
75470
- var tiles = [];
75471
- //NOTE: 每个watermark 都占满整个宽度,一行只放一个watermark
75472
- var totalHeight = 0;
75473
- for (var i = 0; i < watermarks.length; i++) {
75474
- var watermark = watermarks[i];
75475
- var tile = buildTile(canvas, watermark.content, watermark.style);
75476
- if (tile) {
75477
- tiles.push(tile);
75478
- totalHeight += tile.size.height;
75479
- }
75480
- }
75481
- if (totalHeight <= 0) {
75482
- // no need draw
75483
- console.error('watermarks height ' + totalHeight);
75484
- console.error(JSON.stringify(watermarks));
75485
- return;
75486
- }
75487
- var contentPadding = getCanvasScale(canvas, CONTENT_PADDING);
75488
- var baseOrigin = new Point(contentPadding, contentPadding);
75489
- if (groupPosition === GroupPosition.Center) {
75490
- baseOrigin = new Point(contentPadding, Math.round((canvas.height - totalHeight) / 2));
75491
- }
75492
- else if (groupPosition === GroupPosition.Bottom) {
75493
- baseOrigin = new Point(contentPadding, canvas.height - totalHeight - contentPadding);
75494
- }
75495
- else if (groupPosition === GroupPosition.Top) {
75496
- baseOrigin = new Point(contentPadding, contentPadding);
75497
- }
75498
- // update all the tiles' origin
75499
- var lastMarginTop = 0;
75500
- for (var i = 0; i < tiles.length; i++) {
75501
- var tile = tiles[i];
75502
- lastMarginTop += tile.style.paddingTop;
75503
- tile.origin = new Point(tile.origin.x + baseOrigin.x, lastMarginTop + baseOrigin.y);
75504
- lastMarginTop += tile.size.height;
75505
- lastMarginTop += tile.style.paddingBottom;
75506
- }
75507
- // draw all tiles
75508
- for (var i = 0; i < tiles.length; i++) {
75509
- var tile = tiles[i];
75510
- drawTile(canvas, tile);
75511
- }
75512
- }
75513
- /**
75514
- * 把watermark 分为 上、中、三组
75515
- * @param watermarks
75516
- */
75517
- function groupingWatermarks(watermarks) {
75518
- var _a;
75519
- var topList = [];
75520
- var centerList = [];
75521
- var bottomList = [];
75522
- for (var i = 0; i < watermarks.length; i++) {
75523
- var watermark = watermarks[i];
75524
- if (watermark.style.position.endsWith("top")) {
75525
- topList.push(watermark);
75526
- }
75527
- else if (watermark.style.position.endsWith("center")) {
75528
- centerList.push(watermark);
75529
- }
75530
- else if (watermark.style.position.endsWith("bottom")) {
75531
- bottomList.push(watermark);
75532
- }
75533
- }
75534
- return _a = {},
75535
- _a[GroupPosition.Top] = topList,
75536
- _a[GroupPosition.Center] = centerList,
75537
- _a[GroupPosition.Bottom] = bottomList,
75538
- _a;
75539
- }
75540
- function renderWatermark(canvas, options) {
75541
- // console.log("canvas width " + canvas.width);
75542
- // console.log("canvas height " + canvas.height);
75543
- if (!options.enabled || options.watermarkConfigString === "no") {
75544
- return Promise.resolve(canvas);
75545
- }
75546
- var watermarkConfigString = options.watermarkConfigString;
75547
- if (watermarkConfigString === "default") {
75548
- watermarkConfigString = "50$lefttop$50*#*time###25$lefttop*#*date";
75549
- }
75550
- var watermarks = parseWatermarks(watermarkConfigString, new Size(canvas.width, canvas.height), options.context);
75551
- var groupedWatermarks = groupingWatermarks(watermarks);
75552
- drawGroupedWatermarks(canvas, groupedWatermarks[GroupPosition.Top], GroupPosition.Top);
75553
- drawGroupedWatermarks(canvas, groupedWatermarks[GroupPosition.Center], GroupPosition.Center);
75554
- drawGroupedWatermarks(canvas, groupedWatermarks[GroupPosition.Bottom], GroupPosition.Bottom);
75555
- return Promise.resolve(canvas);
75556
- }
75557
- function checkWatermarkConfigSupported(watermarkConfigString) {
75558
- if (watermarkConfigString.indexOf("{logo}") > -1) {
75559
- console.error("水印不支持logo");
75560
- return false;
75561
- }
75562
- var configStringArray = watermarkConfigString.split("###");
75563
- for (var i = 0; i < configStringArray.length; i++) {
75564
- var configString = configStringArray[i];
75565
- //console.log('config string ' + configString);
75566
- var configParts = configString.split("*#*");
75567
- //console.log(JSON.stringify(configParts));
75568
- if (configParts.length === 2) {
75569
- var styleString = configParts[0];
75570
- var styleParts = styleString.split("$");
75571
- if (styleParts.length <= 0) {
75572
- console.error("水印配置不合法");
75573
- return false;
75574
- }
75575
- }
75576
- }
75577
- return true;
75578
- }
74807
+ /**
74808
+ * 水印配置 {@link http://faq.egova.com.cn:7777/projects/redmine/wiki/%E6%8B%8D%E7%85%A7%E6%B0%B4%E5%8D%B0%E9%85%8D%E7%BD%AE|文档}
74809
+ * @description 水印渲染类
74810
+ * @author Jiaji Yin
74811
+ * @date 2021-11-05
74812
+ */
74813
+ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
74814
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
74815
+ return new (P || (P = Promise))(function (resolve, reject) {
74816
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
74817
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
74818
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
74819
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
74820
+ });
74821
+ };
74822
+ var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
74823
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
74824
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
74825
+ function verb(n) { return function (v) { return step([n, v]); }; }
74826
+ function step(op) {
74827
+ if (f) throw new TypeError("Generator is already executing.");
74828
+ while (_) try {
74829
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
74830
+ if (y = 0, t) op = [op[0] & 2, t.value];
74831
+ switch (op[0]) {
74832
+ case 0: case 1: t = op; break;
74833
+ case 4: _.label++; return { value: op[1], done: false };
74834
+ case 5: _.label++; y = op[1]; op = [0]; continue;
74835
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
74836
+ default:
74837
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
74838
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
74839
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
74840
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
74841
+ if (t[2]) _.ops.pop();
74842
+ _.trys.pop(); continue;
74843
+ }
74844
+ op = body.call(thisArg, _);
74845
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
74846
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
74847
+ }
74848
+ };
74849
+
74850
+ var WatermarkImageEnum;
74851
+ (function (WatermarkImageEnum) {
74852
+ WatermarkImageEnum[WatermarkImageEnum["POSITION_LEFT"] = 0] = "POSITION_LEFT";
74853
+ WatermarkImageEnum[WatermarkImageEnum["POSITION_RIGHT"] = 1] = "POSITION_RIGHT";
74854
+ })(WatermarkImageEnum || (WatermarkImageEnum = {}));
74855
+ var Point = /** @class */ (function () {
74856
+ function Point(x, y) {
74857
+ this.x = x;
74858
+ this.y = y;
74859
+ }
74860
+ return Point;
74861
+ }());
74862
+ var Size = /** @class */ (function () {
74863
+ function Size(width, height) {
74864
+ this.width = width;
74865
+ this.height = height;
74866
+ }
74867
+ return Size;
74868
+ }());
74869
+ var clamp = function (value, min, max) {
74870
+ return Math.min(Math.max(value, min), max);
74871
+ };
74872
+ var subString = function (str, startIndex, length) {
74873
+ if (checkIsUndefinedOrNull(length)) {
74874
+ return str.substring(startIndex);
74875
+ }
74876
+ else {
74877
+ return str.substring(startIndex, startIndex + length);
74878
+ }
74879
+ };
74880
+ /**
74881
+ * {@link http://faq.egova.com.cn:7777/files/ueditor/image/20180621/1529574697677847.png|水印位置图}
74882
+ */
74883
+ var WatermarkPosition;
74884
+ (function (WatermarkPosition) {
74885
+ WatermarkPosition["LeftTop"] = "lefttop";
74886
+ WatermarkPosition["CenterTop"] = "centertop";
74887
+ WatermarkPosition["RightTop"] = "righttop";
74888
+ WatermarkPosition["LeftCenter"] = "leftcenter";
74889
+ WatermarkPosition["Center"] = "center";
74890
+ WatermarkPosition["RightCenter"] = "rightcenter";
74891
+ WatermarkPosition["LeftBottom"] = "leftbottom";
74892
+ WatermarkPosition["CenterBottom"] = "centerbottom";
74893
+ WatermarkPosition["RightBottom"] = "rightbottom";
74894
+ })(WatermarkPosition || (WatermarkPosition = {}));
74895
+ var WatermarkFontWeight;
74896
+ (function (WatermarkFontWeight) {
74897
+ WatermarkFontWeight["Normal"] = "normal";
74898
+ WatermarkFontWeight["Bold"] = "bold";
74899
+ })(WatermarkFontWeight || (WatermarkFontWeight = {}));
74900
+ var DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
74901
+ var DEFAULT_TIME_FORMAT = "HH:mm";
74902
+ var WatermarkContent;
74903
+ (function (WatermarkContent) {
74904
+ WatermarkContent["Raw"] = "";
74905
+ WatermarkContent["Date"] = "date{(.*?)}|date";
74906
+ WatermarkContent["Time"] = "time";
74907
+ WatermarkContent["Address"] = "address";
74908
+ WatermarkContent["HumanName"] = "humanname";
74909
+ WatermarkContent["ProjectName"] = "projectName";
74910
+ WatermarkContent["ApplicationName"] = "applicationName";
74911
+ })(WatermarkContent || (WatermarkContent = {}));
74912
+ var ColorMap = {
74913
+ transparent: "#00000000",
74914
+ white: "#FFFFFF",
74915
+ black: "#000000",
74916
+ darkgray: "#444444",
74917
+ gray: "#888888",
74918
+ lightgray: "#CCCCCC",
74919
+ darkgrey: "#444444",
74920
+ grey: "#888888",
74921
+ lightgrey: "#CCCCCC",
74922
+ red: "#FF0000",
74923
+ green: "#00FF00",
74924
+ blue: "#0000FF",
74925
+ yellow: "#FFFF00",
74926
+ cyan: "#00FFFF",
74927
+ magenta: "#FF00FF",
74928
+ aqua: "#00FFFF",
74929
+ fuchsia: "#FF00FF",
74930
+ lime: "#00FF00",
74931
+ maroon: "#800000",
74932
+ navy: "#000080",
74933
+ olive: "#808000",
74934
+ purple: "#800080",
74935
+ silver: "#C0C0C0",
74936
+ teal: "#008080",
74937
+ orange: "#FF9933",
74938
+ };
74939
+ function getColorValue(key) {
74940
+ for (var _i = 0, _a = Object.getOwnPropertyNames(ColorMap); _i < _a.length; _i++) {
74941
+ var k = _a[_i];
74942
+ if (k === key) {
74943
+ return ColorMap[k];
74944
+ }
74945
+ }
74946
+ return null;
74947
+ }
74948
+ var CONTENT_PADDING = 10;
74949
+ var DEFAULT_PADDING = 2;
74950
+ var DEFAULT_FONT_SIZE = 25.0;
74951
+ var DEFAULT_CANVAS_SIZE = 480.0;
74952
+ var DEFAULT_BACKGROUND_OPACITY = 128;
74953
+ var WatermarkStyle = /** @class */ (function () {
74954
+ /**
74955
+ * Watermark Style
74956
+ * @param fontName
74957
+ * @param fontWeight
74958
+ * @param fontColor
74959
+ * @param fontSize
74960
+ * @param backgroundColor
74961
+ * @param backgroundOpacity
74962
+ * @param paddingTop
74963
+ * @param paddingBottom
74964
+ * @param position
74965
+ * @param scale
74966
+ * @param simplified
74967
+ */
74968
+ function WatermarkStyle(fontName, fontWeight, fontColor, fontSize, backgroundColor, backgroundOpacity, paddingTop, paddingBottom, position, scale, simplified) {
74969
+ this.fontName = fontName;
74970
+ this.fontWeight = fontWeight;
74971
+ this.fontColor = fontColor;
74972
+ this.fontSize = fontSize;
74973
+ this.backgroundColor = backgroundColor;
74974
+ this.backgroundOpacity = backgroundOpacity;
74975
+ this.paddingTop = paddingTop;
74976
+ this.paddingBottom = paddingBottom;
74977
+ this.position = position;
74978
+ this.scale = scale;
74979
+ this.simplified = simplified;
74980
+ }
74981
+ return WatermarkStyle;
74982
+ }());
74983
+ var WatermarkImage = /** @class */ (function () {
74984
+ function WatermarkImage(image, width, height, position) {
74985
+ if (image === void 0) { image = ""; }
74986
+ if (width === void 0) { width = 20; }
74987
+ if (height === void 0) { height = 20; }
74988
+ if (position === void 0) { position = WatermarkImageEnum.POSITION_LEFT; }
74989
+ this.image = image;
74990
+ this.width = width;
74991
+ this.height = height;
74992
+ this.position = position;
74993
+ }
74994
+ return WatermarkImage;
74995
+ }());
74996
+ var Watermark = /** @class */ (function () {
74997
+ /**
74998
+ * 水印对象,包含需要渲染的文本、图像,以及相应的style
74999
+ * @param content
75000
+ * @param watermarkStyle
75001
+ */
75002
+ function Watermark(content, watermarkStyle, watermarkImage) {
75003
+ this.content = content;
75004
+ this.style = watermarkStyle;
75005
+ this.watermarkImage = watermarkImage;
75006
+ }
75007
+ return Watermark;
75008
+ }());
75009
+ var WatermarkContext = /** @class */ (function () {
75010
+ /**
75011
+ * 打水印需要的环境信息
75012
+ * @param address
75013
+ * @param watermarkTime
75014
+ * @param humanName
75015
+ * @param projectName
75016
+ * @param logo
75017
+ */
75018
+ function WatermarkContext(params) {
75019
+ this.address = params.address;
75020
+ this.watermarkTime = params.watermarkTime;
75021
+ this.humanName = params.humanName;
75022
+ this.projectName = params.projectName;
75023
+ this.logo = params.logo;
75024
+ this.applicationName = params.applicationName;
75025
+ }
75026
+ return WatermarkContext;
75027
+ }());
75028
+
75029
+ var WatermarkOptions = /** @class */ (function () {
75030
+ /**
75031
+ * 水印配置项
75032
+ * @param enabled, 是否开启水印
75033
+ * @param watermarkConfigString,水印配置的字符串
75034
+ * @param context,打水印需要的环境信息
75035
+ */
75036
+ function WatermarkOptions(params) {
75037
+ this.enabled = params.enabled;
75038
+ this.watermarkConfigString = params.watermarkConfigString;
75039
+ this.context = params.context;
75040
+ }
75041
+ return WatermarkOptions;
75042
+ }());
75043
+
75044
+ /**
75045
+ * 画水印默认使用黑体
75046
+ * @see {@link https://www.zhihu.com/question/19911793|使用黑体}
75047
+ */
75048
+ function getHeitiFontFamily() {
75049
+ if (checkIsAndroid()) {
75050
+ return "'Roboto Black', 'Droid Sans'";
75051
+ }
75052
+ else if (checkIsIOS()) {
75053
+ return "'PingFang SC Medium'";
75054
+ }
75055
+ else {
75056
+ return '"PingFang SC Medium", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif';
75057
+ }
75058
+ }
75059
+ function parseWatermarkStyle(styleString, canvasSize) {
75060
+ if (!checkIsStringValid(styleString)) {
75061
+ return null;
75062
+ }
75063
+ var styleParts = styleString.split("$");
75064
+ if (styleParts.length <= 0) {
75065
+ return null;
75066
+ }
75067
+ var scale = Math.min(canvasSize.width, canvasSize.height) / DEFAULT_CANVAS_SIZE;
75068
+ /**
75069
+ 1. 20190314版本开始可以使用简化版配置,格式为[文字大小]$[水印位置]$[上下padding]*#*[水印内容] 其中[上下padding]一般不设置,如需设置,格式为"上padding_下padding",下padding可省略
75070
+ 2. 简化版配置使用条件:字体(黑体)、字体样式(normal)、文字颜色(transparent)、背景颜色(transparent)、背景不透明度(128)全部使用默认值(括号中的值)
75071
+ */
75072
+ if (parseInteger(styleParts[0], -1) !== -1) {
75073
+ // 第一项为数字,则为新的简化配置
75074
+ var fontSize = Math.round(parseDecimal(styleParts[0], DEFAULT_FONT_SIZE) * scale);
75075
+ var position = WatermarkPosition.LeftTop;
75076
+ if (styleParts[1]) {
75077
+ position = styleParts[1];
75078
+ }
75079
+ var paddingTop = DEFAULT_PADDING * scale;
75080
+ var paddingBottom = DEFAULT_PADDING * scale;
75081
+ if (styleParts[2]) {
75082
+ var paddingParts = styleParts[2].split("_");
75083
+ paddingTop = parseInteger(paddingParts[0], DEFAULT_PADDING) * scale;
75084
+ if (paddingParts[1]) {
75085
+ paddingBottom = parseInteger(paddingParts[1], DEFAULT_PADDING) * scale;
75086
+ }
75087
+ }
75088
+ var fontName = getHeitiFontFamily();
75089
+ var fontWeight = WatermarkFontWeight.Normal;
75090
+ var fontColor = ColorMap.transparent;
75091
+ var backgroundColor = ColorMap.transparent;
75092
+ var backgroundOpacity = 128;
75093
+ return new WatermarkStyle(fontName, fontWeight, fontColor, fontSize, backgroundColor, backgroundOpacity, paddingTop, paddingBottom, position, scale, true);
75094
+ }
75095
+ else {
75096
+ // [字体]$[文字样式]$[文字颜色]$[文字大小]$[背景颜色]$[水印位置]$[背景不透明度]$[上下padding]*#*[水印内容]
75097
+ var fontName = styleParts[0] + ", " + getHeitiFontFamily();
75098
+ var fontWeight = WatermarkFontWeight.Normal;
75099
+ if (styleParts[1]) {
75100
+ fontWeight = styleParts[1];
75101
+ }
75102
+ var fontColor = ColorMap.white;
75103
+ if (styleParts[2]) {
75104
+ var color = getColorValue(styleParts[2]);
75105
+ if (color) {
75106
+ fontColor = color;
75107
+ }
75108
+ }
75109
+ var fontSize = Math.round(DEFAULT_FONT_SIZE * scale);
75110
+ if (styleParts[3]) {
75111
+ fontSize = Math.round(parseDecimal(styleParts[3], DEFAULT_FONT_SIZE) * scale);
75112
+ }
75113
+ var backgroundColor = ColorMap.blue;
75114
+ if (styleParts[4]) {
75115
+ var color = getColorValue(styleParts[4]);
75116
+ if (color) {
75117
+ backgroundColor = color;
75118
+ }
75119
+ }
75120
+ var position = WatermarkPosition.LeftTop;
75121
+ if (styleParts[5]) {
75122
+ position = styleParts[5];
75123
+ }
75124
+ var backgroundOpacity = 255;
75125
+ if (styleParts[6]) {
75126
+ var opacity = parseInteger(styleParts[6], DEFAULT_BACKGROUND_OPACITY);
75127
+ opacity = clamp(opacity, 0, 255);
75128
+ backgroundOpacity = opacity;
75129
+ }
75130
+ var paddingTop = DEFAULT_PADDING * scale;
75131
+ var paddingBottom = DEFAULT_PADDING * scale;
75132
+ if (styleParts[7]) {
75133
+ var paddingParts = styleParts[7].split("_");
75134
+ paddingTop = parseInteger(paddingParts[0], DEFAULT_PADDING) * scale;
75135
+ if (paddingParts[1]) {
75136
+ paddingBottom = parseInteger(paddingParts[1], DEFAULT_PADDING) * scale;
75137
+ }
75138
+ }
75139
+ return new WatermarkStyle(fontName, fontWeight, fontColor, fontSize, backgroundColor, backgroundOpacity, paddingTop, paddingBottom, position, scale, false);
75140
+ }
75141
+ }
75142
+ /**
75143
+ * A JavaScript Scanner like Java's
75144
+ * @see java.util.Scanner
75145
+ */
75146
+ var watermark_TextScanner = /** @class */ (function () {
75147
+ /**
75148
+ * The content to scan
75149
+ * @param text
75150
+ */
75151
+ function TextScanner(text) {
75152
+ this.text = text;
75153
+ this.cursor = 0;
75154
+ }
75155
+ TextScanner.prototype.hasNext = function (obj) {
75156
+ if (checkIsUndefinedOrNull(obj)) {
75157
+ return this.cursor < this.text.length;
75158
+ }
75159
+ else if (checkIsString(obj)) {
75160
+ var str = obj;
75161
+ var current = subString(this.text, this.cursor, str.length);
75162
+ if (current === str) {
75163
+ return true;
75164
+ }
75165
+ }
75166
+ else if (checkIsRegExp(obj)) {
75167
+ var regex = obj;
75168
+ var subText = subString(this.text, this.cursor);
75169
+ var matchResults = subText.match(regex);
75170
+ if (matchResults) {
75171
+ if (matchResults.index === 0) {
75172
+ return true;
75173
+ }
75174
+ }
75175
+ }
75176
+ return false;
75177
+ };
75178
+ TextScanner.prototype.next = function (obj) {
75179
+ if (checkIsUndefinedOrNull(obj)) {
75180
+ return subString(this.text, this.cursor, 1);
75181
+ }
75182
+ else if (checkIsString(obj)) {
75183
+ var str = obj;
75184
+ if (subString(this.text, this.cursor, str.length) === str) {
75185
+ return str;
75186
+ }
75187
+ }
75188
+ else if (checkIsRegExp(obj)) {
75189
+ var regex = obj;
75190
+ var subText = subString(this.text, this.cursor);
75191
+ var matchResults = subText.match(regex);
75192
+ if (matchResults) {
75193
+ if (matchResults.index === 0) {
75194
+ return matchResults;
75195
+ }
75196
+ }
75197
+ }
75198
+ return null;
75199
+ };
75200
+ TextScanner.prototype.skip = function (obj) {
75201
+ if (checkIsUndefinedOrNull(obj)) {
75202
+ this.cursor += 1;
75203
+ }
75204
+ else if (checkIsStringValid(obj)) {
75205
+ var str = obj;
75206
+ this.cursor += str.length;
75207
+ }
75208
+ return this;
75209
+ };
75210
+ return TextScanner;
75211
+ }());
75212
+
75213
+ function buildContent(contentConfigString, watermarkContext, style) {
75214
+ var content = "";
75215
+ var watermarkImage = new WatermarkImage();
75216
+ if (contentConfigString.includes("{logo")) {
75217
+ var start = contentConfigString.indexOf("{logo");
75218
+ var end = contentConfigString.indexOf("}", start);
75219
+ if (end != -1) {
75220
+ var logoConfigWithBrace = contentConfigString.substring(start, end + 1);
75221
+ if (contentConfigString.startsWith(logoConfigWithBrace) ||
75222
+ contentConfigString.endsWith(logoConfigWithBrace)) {
75223
+ if (contentConfigString.startsWith(logoConfigWithBrace)) {
75224
+ watermarkImage.position = WatermarkImageEnum.POSITION_LEFT;
75225
+ }
75226
+ else {
75227
+ watermarkImage.position = WatermarkImageEnum.POSITION_RIGHT;
75228
+ }
75229
+ var imgWidthHeight = (style === null || style === void 0 ? void 0 : style.fontSize) || 20;
75230
+ watermarkImage.image = watermarkContext.logo;
75231
+ watermarkImage.height = imgWidthHeight;
75232
+ watermarkImage.width = imgWidthHeight;
75233
+ }
75234
+ var applicationName = contentConfigString.replace(logoConfigWithBrace, "");
75235
+ if (applicationName) {
75236
+ content = watermarkContext.applicationName;
75237
+ }
75238
+ }
75239
+ }
75240
+ else {
75241
+ var scanner = new watermark_TextScanner(contentConfigString);
75242
+ var steps = 0;
75243
+ while (scanner.hasNext() &&
75244
+ /* 防止scanner代码错误产生无限循环,设置一个最大scan步数*/
75245
+ steps < contentConfigString.length) {
75246
+ var dateRegex = new RegExp(WatermarkContent.Date);
75247
+ if (scanner.hasNext(dateRegex)) {
75248
+ var regexResult = scanner.next(dateRegex);
75249
+ if (regexResult) {
75250
+ var matchResults = regexResult;
75251
+ var format = date_FORMAT.FORMAT_YMD;
75252
+ if (matchResults && matchResults.length >= 2) {
75253
+ if (checkIsStringValid(matchResults[1])) {
75254
+ format = matchResults[1];
75255
+ }
75256
+ }
75257
+ content += date_formatDate(watermarkContext.watermarkTime, format);
75258
+ scanner.skip(matchResults.input);
75259
+ }
75260
+ }
75261
+ else if (scanner.hasNext(WatermarkContent.Time)) {
75262
+ var value = date_formatDate(watermarkContext.watermarkTime, date_FORMAT.FORMAT_HM);
75263
+ content += value;
75264
+ scanner.skip(WatermarkContent.Time);
75265
+ }
75266
+ else if (scanner.hasNext(WatermarkContent.Address)) {
75267
+ content += watermarkContext.address;
75268
+ scanner.skip(WatermarkContent.Address);
75269
+ }
75270
+ else if (scanner.hasNext(WatermarkContent.HumanName)) {
75271
+ content += watermarkContext.humanName;
75272
+ scanner.skip(WatermarkContent.HumanName);
75273
+ }
75274
+ else if (scanner.hasNext(WatermarkContent.ProjectName)) {
75275
+ content += watermarkContext.projectName;
75276
+ scanner.skip(WatermarkContent.ProjectName);
75277
+ }
75278
+ else if (scanner.hasNext(WatermarkContent.ApplicationName)) {
75279
+ content += watermarkContext.applicationName;
75280
+ scanner.skip(WatermarkContent.ApplicationName);
75281
+ }
75282
+ else {
75283
+ var nextChar = scanner.next();
75284
+ // console.log(`next out "${nextChar}"`)
75285
+ if (checkIsString(nextChar)) {
75286
+ // console.log(`next in "${nextChar}"`)
75287
+ content += nextChar;
75288
+ }
75289
+ scanner.skip();
75290
+ }
75291
+ steps++;
75292
+ }
75293
+ }
75294
+ return { content: content, watermarkImage: watermarkImage };
75295
+ }
75296
+ function parseWatermarks(watermarkConfigString, canvasSize, watermarkContext) {
75297
+ var watermarks = [];
75298
+ var configStringArray = watermarkConfigString.split("###");
75299
+ for (var i = 0; i < configStringArray.length; i++) {
75300
+ var configString = configStringArray[i];
75301
+ //console.log('config string ' + configString);
75302
+ var configParts = configString.split("*#*");
75303
+ //console.log(JSON.stringify(configParts));
75304
+ if (configParts.length === 2) {
75305
+ var styleString = configParts[0];
75306
+ var contentString = configParts[1];
75307
+ var style = parseWatermarkStyle(styleString, canvasSize);
75308
+ var data = buildContent(contentString, watermarkContext, style);
75309
+ if (style && (data.content || data.watermarkImage.image)) {
75310
+ var watermark = new Watermark(data.content, style, data.watermarkImage);
75311
+ watermarks.push(watermark);
75312
+ }
75313
+ }
75314
+ }
75315
+ return watermarks;
75316
+ }
75317
+ /**
75318
+ * 可以渲染的内容
75319
+ */
75320
+ var Tile = /** @class */ (function () {
75321
+ function Tile(origin, size, lineHeight, lineWidths, lines, style, watermarkImage) {
75322
+ this.origin = origin;
75323
+ this.size = size;
75324
+ this.lineHeight = lineHeight;
75325
+ this.lineWidths = lineWidths;
75326
+ this.lines = lines;
75327
+ this.style = style;
75328
+ this.watermarkImage = watermarkImage;
75329
+ }
75330
+ return Tile;
75331
+ }());
75332
+ function getCanvasScale(canvas, len) {
75333
+ var min = Math.min(canvas.width, canvas.height);
75334
+ return (min / DEFAULT_CANVAS_SIZE) * len;
75335
+ }
75336
+ function buildTile(canvas, watermark) {
75337
+ var content = watermark.content, style = watermark.style, watermarkImage = watermark.watermarkImage;
75338
+ var origin = new Point(0, 0);
75339
+ var size = new Size(0, 0);
75340
+ var lines = [];
75341
+ var ctx = canvas.getContext("2d");
75342
+ if (!ctx) {
75343
+ return null;
75344
+ }
75345
+ ctx.font = style.fontWeight + " " + style.fontSize + "px " + style.fontName;
75346
+ var contentPadding = getCanvasScale(canvas, CONTENT_PADDING);
75347
+ var contentWidth = canvas.width - contentPadding * 2;
75348
+ // @see {@link https://stackoverflow.com/questions/1134586/how-can-you-find-the-height-of-text-on-an-html-canvas}
75349
+ var lineHeight = ctx.measureText("M").width;
75350
+ var lineWidths = [];
75351
+ // content超过宽度就换行
75352
+ var temp = "";
75353
+ var lastWidth = 0;
75354
+ for (var i = 0; i < content.length; i++) {
75355
+ var lineWidth = ctx.measureText(temp).width;
75356
+ if (lineWidth >= contentWidth) {
75357
+ lines.push(temp);
75358
+ lineWidths.push(lineWidth);
75359
+ temp = "";
75360
+ }
75361
+ lastWidth = lineWidth;
75362
+ temp += content[i];
75363
+ }
75364
+ lines.push(temp);
75365
+ lineWidths.push(lastWidth);
75366
+ size.width = contentWidth;
75367
+ size.height = lines.length * lineHeight;
75368
+ return new Tile(origin, size, lineHeight, lineWidths, lines, style, watermarkImage);
75369
+ }
75370
+ /**
75371
+ * 画文字,默认{@link https://stackoverflow.com/questions/43242709/how-can-i-draw-text-that-looks-embossed-using-kinetic-js-and-canvas|浮雕效果}
75372
+ * @param canvas
75373
+ * @param text
75374
+ */
75375
+ // function getEmbossTextImageData(text: string, size: Size): ImageData | null {
75376
+ // // constants
75377
+ // const canvas = document.createElement('canvas');
75378
+ // document.body.appendChild(canvas);
75379
+ // const ctx = canvas.getContext("2d");
75380
+ // if (!ctx) {
75381
+ // return null
75382
+ // }
75383
+ //
75384
+ // canvas.width = size.width;
75385
+ // canvas.height = size.height;
75386
+ //
75387
+ // // constants
75388
+ // const blur = 2;
75389
+ // const highLight = "rgba(100,190,256,0.75)";
75390
+ // const shadow = "rgba(0,0,0,0.65)";
75391
+ // const font = "84px arial black";
75392
+ // const background = "linear-gradient(to right, #1e5799 0%,#3096e5 100%)";
75393
+ // const border = "2px solid #6CF"
75394
+ //
75395
+ // // create canvas add styles and put on page
75396
+ //
75397
+ // const w = (canvas.width = innerWidth - 24) / 2; // set size and get centers
75398
+ // const h = (canvas.height = innerHeight - 24) / 2;
75399
+ // canvas.style.background = background;
75400
+ // canvas.style.border = border;
75401
+ //
75402
+ //
75403
+ // // set up font and font rendering alignment
75404
+ // ctx.font = font;
75405
+ // ctx.textAlign = "center";
75406
+ // ctx.textBaseline = "middle";
75407
+ //
75408
+ // // draw dark shadow
75409
+ // ctx.shadowBlur = blur; // shadow
75410
+ // ctx.fillStyle = ctx.shadowColor = shadow;
75411
+ // ctx.shadowOffsetY = ctx.shadowOffsetX = blur;
75412
+ // ctx.fillText(text, w, h);
75413
+ //
75414
+ // // draw highLight
75415
+ // ctx.fillStyle = ctx.shadowColor = highLight;
75416
+ // ctx.shadowOffsetY = ctx.shadowOffsetX = -blur;
75417
+ // ctx.fillText(text, w, h);
75418
+ //
75419
+ // // draw center text that removes pixels
75420
+ // ctx.shadowColor = "rgba(0,0,0,0.0)"; // turn off shadow
75421
+ // ctx.fillStyle = "black";
75422
+ // ctx.globalCompositeOperation = "destination-out"; // New pixels will remove old pixels making them transparent
75423
+ // ctx.fillText(text, w, h);
75424
+ // ctx.globalCompositeOperation = "source-over"; // restore default composite operation.
75425
+ //
75426
+ // return ctx.getImageData(0, 0, size.width, size.height)
75427
+ // }
75428
+ function getAxisPoint(canvasWidth, width, origin, style, watermarkImage) {
75429
+ var padding = (CONTENT_PADDING + DEFAULT_PADDING) * style.scale;
75430
+ var axisPoint = new Point(padding, origin.y);
75431
+ if (style.position.startsWith("center")) {
75432
+ axisPoint = new Point(canvasWidth / 2, origin.y);
75433
+ }
75434
+ else if (style.position.startsWith("right")) {
75435
+ axisPoint = new Point(canvasWidth - padding, origin.y);
75436
+ }
75437
+ var imagePoint = new Point(axisPoint.x, axisPoint.y);
75438
+ if (watermarkImage.image) {
75439
+ if (watermarkImage.position === WatermarkImageEnum.POSITION_LEFT) {
75440
+ if (style.position.startsWith("left")) {
75441
+ axisPoint.x = axisPoint.x + watermarkImage.width;
75442
+ }
75443
+ else if (style.position.startsWith("center")) {
75444
+ axisPoint.x = axisPoint.x + watermarkImage.width / 2;
75445
+ imagePoint.x = imagePoint.x - width / 2 - watermarkImage.width;
75446
+ }
75447
+ else {
75448
+ imagePoint.x = imagePoint.x - width - 2 * watermarkImage.width;
75449
+ }
75450
+ }
75451
+ else {
75452
+ if (style.position.startsWith("left")) {
75453
+ imagePoint.x = axisPoint.x + width + watermarkImage.width;
75454
+ }
75455
+ else if (style.position.startsWith("center")) {
75456
+ axisPoint.x = axisPoint.x - watermarkImage.width / 2;
75457
+ imagePoint.x = imagePoint.x + width / 2;
75458
+ }
75459
+ else {
75460
+ axisPoint.x = axisPoint.x - watermarkImage.width;
75461
+ imagePoint.x = imagePoint.x - watermarkImage.width;
75462
+ }
75463
+ }
75464
+ }
75465
+ return {
75466
+ text: axisPoint,
75467
+ image: imagePoint,
75468
+ };
75469
+ }
75470
+ function getTextAlign(style) {
75471
+ var align = "left";
75472
+ if (style.position.startsWith("center")) {
75473
+ align = "center";
75474
+ }
75475
+ else if (style.position.startsWith("right")) {
75476
+ align = "right";
75477
+ }
75478
+ return align;
75479
+ }
75480
+ function loadImage(url) {
75481
+ return new Promise(function (resolve, reject) {
75482
+ var img = new Image();
75483
+ img.src = url;
75484
+ img.crossOrigin = "anonymous";
75485
+ img.onload = function (e) {
75486
+ if (img.complete) {
75487
+ resolve(img);
75488
+ }
75489
+ else {
75490
+ console.error(e);
75491
+ reject(new Error("文件加载失败"));
75492
+ }
75493
+ };
75494
+ });
75495
+ }
75496
+ function drawLine(canvas, line, width, origin, tile) {
75497
+ return __awaiter(this, void 0, void 0, function () {
75498
+ var ctx, style, watermarkImage, point, image, offset;
75499
+ return __generator(this, function (_a) {
75500
+ switch (_a.label) {
75501
+ case 0:
75502
+ ctx = canvas.getContext("2d");
75503
+ if (!ctx) {
75504
+ return [2 /*return*/];
75505
+ }
75506
+ style = tile.style, watermarkImage = tile.watermarkImage;
75507
+ /**
75508
+ * The fillText's second argument is the Y coordinate for the baseline of the text (the default textBaseline is "alphabetic") ,
75509
+ * so the text is being drawn above the visible canvas element when you use 0.
75510
+ * @see {@link https://stackoverflow.com/questions/14289331/html5-canvas-doesnt-fill-text-at-coordinates-0-0}
75511
+ */
75512
+ ctx.textBaseline = "top";
75513
+ ctx.font = style.fontWeight + " " + style.fontSize + "px " + style.fontName;
75514
+ point = getAxisPoint(canvas.width, width, origin, style, watermarkImage);
75515
+ ctx.textAlign = getTextAlign(style);
75516
+ if (!watermarkImage.image) return [3 /*break*/, 2];
75517
+ return [4 /*yield*/, loadImage(watermarkImage.image)];
75518
+ case 1:
75519
+ image = _a.sent();
75520
+ ctx.drawImage(image, Math.round(point.image.x), Math.round(point.image.y), watermarkImage.width, watermarkImage.height);
75521
+ _a.label = 2;
75522
+ case 2:
75523
+ if (style.simplified) {
75524
+ ctx.shadowBlur = 4; // shadow
75525
+ // ctx.shadowColor = "rgba(220,220,220,0.75)";
75526
+ ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
75527
+ offset = clamp(style.fontSize / 40, 2, 4);
75528
+ ctx.shadowOffsetY = offset;
75529
+ ctx.shadowOffsetX = offset;
75530
+ ctx.fillStyle = "rgba(255,255,255, 0.5)";
75531
+ }
75532
+ else {
75533
+ ctx.fillStyle = style.fontColor;
75534
+ }
75535
+ ctx.fillText(line, Math.round(point.text.x), Math.round(point.text.y));
75536
+ return [2 /*return*/];
75537
+ }
75538
+ });
75539
+ });
75540
+ }
75541
+ function hexToRGB(hex, alpha) {
75542
+ var r = parseInt(hex.slice(1, 3), 16), g = parseInt(hex.slice(3, 5), 16), b = parseInt(hex.slice(5, 7), 16);
75543
+ if (alpha) {
75544
+ return "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
75545
+ }
75546
+ else {
75547
+ return "rgb(" + r + ", " + g + ", " + b + ")";
75548
+ }
75549
+ }
75550
+ function drawBackground(canvas, tile) {
75551
+ var ctx = canvas.getContext("2d");
75552
+ if (!ctx) {
75553
+ return;
75554
+ }
75555
+ var backgroundColor = tile.style.backgroundColor;
75556
+ var backgroundOpacity = parseDecimal(String(tile.style.backgroundOpacity), -1);
75557
+ if (backgroundOpacity > 255) {
75558
+ backgroundOpacity = 255;
75559
+ }
75560
+ var paddingTop = 2;
75561
+ var paddingBottom = 10;
75562
+ if (backgroundColor !== "transparent") {
75563
+ if (backgroundColor.startsWith("#") && backgroundOpacity >= 0) {
75564
+ backgroundColor = hexToRGB(backgroundColor, backgroundOpacity / 255.0);
75565
+ }
75566
+ ctx.fillStyle = backgroundColor;
75567
+ var style = tile.style;
75568
+ var padding = (CONTENT_PADDING + DEFAULT_PADDING) * style.scale;
75569
+ var paddingScale = tile.style.fontSize / DEFAULT_FONT_SIZE;
75570
+ for (var j = 0; j < tile.lineWidths.length; j++) {
75571
+ var lineHeight = tile.lineHeight;
75572
+ var lineWidth = tile.lineWidths[j];
75573
+ var paddingRight = 30 * paddingScale;
75574
+ var paddingLeft = 10 * paddingScale;
75575
+ var axisPoint = new Point(padding - paddingLeft, tile.origin.y);
75576
+ if (style.position.startsWith("center")) {
75577
+ paddingLeft = 20 * paddingScale;
75578
+ paddingRight = 20 * paddingScale;
75579
+ axisPoint = new Point((canvas.width - lineWidth) / 2 - paddingLeft, tile.origin.y);
75580
+ }
75581
+ else if (style.position.startsWith("right")) {
75582
+ paddingLeft = 30 * paddingScale;
75583
+ paddingRight = 10 * paddingScale;
75584
+ axisPoint = new Point(canvas.width - lineWidth - padding - paddingLeft, tile.origin.y);
75585
+ }
75586
+ // padding top
75587
+ if (j === 0) {
75588
+ ctx.fillRect(axisPoint.x, axisPoint.y - paddingTop > 0 ? axisPoint.y - paddingTop : 0, paddingLeft + lineWidth + paddingRight, paddingTop);
75589
+ }
75590
+ ctx.fillRect(axisPoint.x, axisPoint.y + j * lineHeight, paddingLeft + lineWidth + paddingRight, lineHeight);
75591
+ // padding bottom
75592
+ if (j === tile.lineWidths.length - 1) {
75593
+ ctx.fillRect(axisPoint.x, axisPoint.y + (j + 1) * lineHeight, paddingLeft + lineWidth + paddingRight, paddingBottom);
75594
+ }
75595
+ }
75596
+ }
75597
+ }
75598
+ function drawTile(canvas, tile) {
75599
+ return __awaiter(this, void 0, void 0, function () {
75600
+ var i, origin_1;
75601
+ return __generator(this, function (_a) {
75602
+ switch (_a.label) {
75603
+ case 0:
75604
+ if (!tile.style.simplified) {
75605
+ // 复杂配置绘制背景颜色
75606
+ drawBackground(canvas, tile);
75607
+ }
75608
+ i = 0;
75609
+ _a.label = 1;
75610
+ case 1:
75611
+ if (!(i < tile.lines.length)) return [3 /*break*/, 4];
75612
+ origin_1 = new Point(tile.origin.x, i * tile.lineHeight + tile.origin.y);
75613
+ return [4 /*yield*/, drawLine(canvas, tile.lines[i], tile.lineWidths[i], origin_1, tile)];
75614
+ case 2:
75615
+ _a.sent();
75616
+ _a.label = 3;
75617
+ case 3:
75618
+ i++;
75619
+ return [3 /*break*/, 1];
75620
+ case 4: return [2 /*return*/];
75621
+ }
75622
+ });
75623
+ });
75624
+ }
75625
+ var GroupPosition;
75626
+ (function (GroupPosition) {
75627
+ GroupPosition["Top"] = "top";
75628
+ GroupPosition["Center"] = "center";
75629
+ GroupPosition["Bottom"] = "bottom";
75630
+ })(GroupPosition || (GroupPosition = {}));
75631
+ function drawGroupedWatermarks(canvas, watermarks, groupPosition) {
75632
+ return __awaiter(this, void 0, void 0, function () {
75633
+ var tiles, totalHeight, i, watermark, tile, contentPadding, baseOrigin, lastMarginTop, i, tile, i, tile;
75634
+ return __generator(this, function (_a) {
75635
+ switch (_a.label) {
75636
+ case 0:
75637
+ if (!watermarks || watermarks.length === 0) {
75638
+ return [2 /*return*/];
75639
+ }
75640
+ tiles = [];
75641
+ totalHeight = 0;
75642
+ for (i = 0; i < watermarks.length; i++) {
75643
+ watermark = watermarks[i];
75644
+ tile = buildTile(canvas, watermark);
75645
+ if (tile) {
75646
+ tiles.push(tile);
75647
+ totalHeight += tile.size.height + CONTENT_PADDING;
75648
+ }
75649
+ }
75650
+ if (totalHeight <= 0) {
75651
+ // no need draw
75652
+ console.error("watermarks height " + totalHeight);
75653
+ console.error(JSON.stringify(watermarks));
75654
+ return [2 /*return*/];
75655
+ }
75656
+ contentPadding = getCanvasScale(canvas, CONTENT_PADDING);
75657
+ baseOrigin = new Point(contentPadding, contentPadding);
75658
+ if (groupPosition === GroupPosition.Center) {
75659
+ baseOrigin = new Point(contentPadding, Math.round((canvas.height - totalHeight) / 2));
75660
+ }
75661
+ else if (groupPosition === GroupPosition.Bottom) {
75662
+ baseOrigin = new Point(contentPadding, canvas.height - totalHeight - contentPadding);
75663
+ }
75664
+ else if (groupPosition === GroupPosition.Top) {
75665
+ baseOrigin = new Point(contentPadding, contentPadding);
75666
+ }
75667
+ lastMarginTop = 0;
75668
+ for (i = 0; i < tiles.length; i++) {
75669
+ tile = tiles[i];
75670
+ lastMarginTop += tile.style.paddingTop;
75671
+ tile.origin = new Point(tile.origin.x + baseOrigin.x, lastMarginTop + baseOrigin.y);
75672
+ lastMarginTop += tile.size.height;
75673
+ lastMarginTop += tile.style.paddingBottom;
75674
+ }
75675
+ i = 0;
75676
+ _a.label = 1;
75677
+ case 1:
75678
+ if (!(i < tiles.length)) return [3 /*break*/, 4];
75679
+ tile = tiles[i];
75680
+ return [4 /*yield*/, drawTile(canvas, tile)];
75681
+ case 2:
75682
+ _a.sent();
75683
+ _a.label = 3;
75684
+ case 3:
75685
+ i++;
75686
+ return [3 /*break*/, 1];
75687
+ case 4: return [2 /*return*/];
75688
+ }
75689
+ });
75690
+ });
75691
+ }
75692
+ /**
75693
+ * 把watermark 分为 上、中、三组
75694
+ * @param watermarks
75695
+ */
75696
+ function groupingWatermarks(watermarks) {
75697
+ var _a;
75698
+ var topList = [];
75699
+ var centerList = [];
75700
+ var bottomList = [];
75701
+ for (var i = 0; i < watermarks.length; i++) {
75702
+ var watermark = watermarks[i];
75703
+ if (watermark.style.position.endsWith("top")) {
75704
+ topList.push(watermark);
75705
+ }
75706
+ else if (watermark.style.position.endsWith("center")) {
75707
+ centerList.push(watermark);
75708
+ }
75709
+ else if (watermark.style.position.endsWith("bottom")) {
75710
+ bottomList.push(watermark);
75711
+ }
75712
+ }
75713
+ return _a = {},
75714
+ _a[GroupPosition.Top] = topList,
75715
+ _a[GroupPosition.Center] = centerList,
75716
+ _a[GroupPosition.Bottom] = bottomList,
75717
+ _a;
75718
+ }
75719
+ function renderWatermark(canvas, options) {
75720
+ return __awaiter(this, void 0, void 0, function () {
75721
+ var watermarkConfigString, watermarks, groupedWatermarks;
75722
+ return __generator(this, function (_a) {
75723
+ switch (_a.label) {
75724
+ case 0:
75725
+ // console.log("canvas width " + canvas.width);
75726
+ // console.log("canvas height " + canvas.height);
75727
+ if (!options.enabled || options.watermarkConfigString === "no") {
75728
+ return [2 /*return*/, Promise.resolve(canvas)];
75729
+ }
75730
+ watermarkConfigString = options.watermarkConfigString;
75731
+ if (watermarkConfigString === "default") {
75732
+ watermarkConfigString = "50$lefttop$50*#*time###25$lefttop*#*date";
75733
+ }
75734
+ watermarks = parseWatermarks(watermarkConfigString, new Size(canvas.width, canvas.height), options.context);
75735
+ groupedWatermarks = groupingWatermarks(watermarks);
75736
+ return [4 /*yield*/, drawGroupedWatermarks(canvas, groupedWatermarks[GroupPosition.Top], GroupPosition.Top)];
75737
+ case 1:
75738
+ _a.sent();
75739
+ return [4 /*yield*/, drawGroupedWatermarks(canvas, groupedWatermarks[GroupPosition.Center], GroupPosition.Center)];
75740
+ case 2:
75741
+ _a.sent();
75742
+ return [4 /*yield*/, drawGroupedWatermarks(canvas, groupedWatermarks[GroupPosition.Bottom], GroupPosition.Bottom)];
75743
+ case 3:
75744
+ _a.sent();
75745
+ return [2 /*return*/, Promise.resolve(canvas)];
75746
+ }
75747
+ });
75748
+ });
75749
+ }
75750
+ function checkWatermarkConfigSupported(watermarkConfigString) {
75751
+ var configStringArray = watermarkConfigString.split("###");
75752
+ for (var i = 0; i < configStringArray.length; i++) {
75753
+ var configString = configStringArray[i];
75754
+ //console.log('config string ' + configString);
75755
+ var configParts = configString.split("*#*");
75756
+ //console.log(JSON.stringify(configParts));
75757
+ if (configParts.length === 2) {
75758
+ var styleString = configParts[0];
75759
+ var styleParts = styleString.split("$");
75760
+ if (styleParts.length <= 0) {
75761
+ console.error("水印配置不合法");
75762
+ return false;
75763
+ }
75764
+ }
75765
+ }
75766
+ return true;
75767
+ }
75579
75768
  //# sourceMappingURL=watermark.js.map
75580
75769
  // CONCATENATED MODULE: ./node_modules/@egova/media/lib/image-util.js
75581
- /**
75582
- * Convert File to data schema url
75583
- * @param file
75584
- */
75585
- function file2DataURL(file) {
75586
- return new Promise(function (resolve, reject) {
75587
- var a = new FileReader();
75588
- a.onload = function (res) {
75589
- if (res && res.target) {
75590
- resolve(res.target.result);
75591
- }
75592
- else {
75593
- reject(new Error('读取文件url失败'));
75594
- }
75595
- };
75596
- a.readAsDataURL(file);
75597
- });
75598
- }
75599
- /**
75600
- * Convert file to image
75601
- * @param file
75602
- */
75603
- function file2Image(file) {
75604
- return new Promise(function (resolve, reject) {
75605
- file2DataURL(file).then(function (url) {
75606
- var img = new Image();
75607
- img.src = url;
75608
- img.onload = function (e) {
75609
- if (img.complete) {
75610
- resolve(img);
75611
- }
75612
- else {
75613
- reject(new Error('文件加载失败'));
75614
- }
75615
- };
75616
- }).catch(reject);
75617
- });
75618
- }
75619
- function image2file(img, fileName, lastModified, type, quality) {
75620
- if (type === void 0) { type = "image/jpeg"; }
75621
- if (quality === void 0) { quality = 0.8; }
75622
- return image2Canvas(img, type).then(function (canvas) {
75623
- return canvas2File(canvas, fileName, lastModified, type, quality);
75624
- });
75625
- }
75626
- /**
75627
- * Draw image on canvas
75628
- * @param img
75629
- * @param width
75630
- * @param height
75631
- */
75632
- function image2Canvas(img, type, width, height) {
75633
- var canvas = document.createElement('canvas');
75634
- if (!width) {
75635
- width = img.width;
75636
- }
75637
- if (!height) {
75638
- height = img.height;
75639
- }
75640
- canvas.width = width;
75641
- canvas.height = height;
75642
- var ctx = canvas.getContext('2d');
75643
- if (ctx) {
75644
- // png经canvas.toDataURL转换后背景变成黑色,这里提前填充白色
75645
- ctx.fillStyle = 'transparent';
75646
- if (type === 'image/jpeg') {
75647
- ctx.fillStyle = '#fff';
75648
- }
75649
- ctx.drawImage(img, 0, 0, width, height);
75650
- return Promise.resolve(canvas);
75651
- }
75652
- else {
75653
- return Promise.reject(null);
75654
- }
75655
- }
75656
- /**
75657
- * Export Image from canvas
75658
- * @param canvas
75659
- * @param type
75660
- * @param quality
75661
- * @see {@link https://meshworld.in/convert-canvas-to-an-image-using-javascript/}
75662
- */
75663
- function canvas2Image(canvas, type, quality) {
75664
- if (type === void 0) { type = "image/jpeg"; }
75665
- if (quality === void 0) { quality = 0.8; }
75666
- var image = new Image();
75667
- image.src = canvas.toDataURL(type, quality);
75668
- return Promise.resolve(image);
75669
- }
75670
- /**
75671
- * Export File from canvas
75672
- * @param canvas
75673
- * @param fileName
75674
- * @param lastModified
75675
- * @param type
75676
- * @param quality
75677
- * @see {@link https://meshworld.in/convert-canvas-to-an-image-using-javascript/}
75678
- */
75679
- function canvas2File(canvas, fileName, lastModified, type, quality) {
75680
- if (type === void 0) { type = "image/jpeg"; }
75681
- if (quality === void 0) { quality = 0.8; }
75682
- return new Promise(function (resolve, reject) {
75683
- canvas.toBlob(function (blob) {
75684
- if (!blob) {
75685
- reject(new Error('canvas文件导出失败'));
75686
- }
75687
- else {
75688
- var file = new File([blob], fileName, { lastModified: lastModified, type: type });
75689
- // console.log("file size " + file.size / 1024 + "kb");
75690
- // console.log(file)
75691
- resolve(file);
75692
- }
75693
- }, type, quality);
75694
- });
75695
- }
75696
- /**
75697
- * 缩放图片
75698
- * @param img:HTMLImageElement 图片对象
75699
- * @param inputType 图片类型
75700
- * @param imageWidth 图片宽度
75701
- * @param imageHeight 图片高度
75702
- * @param equalProportion 是否等比例拉伸,默认是,目前只支持等比例拉伸
75703
- * @param sideLengthLimit 图片边长限制
75704
- * @param baseOnShortSide 是否以短边为限制
75705
- * @param resultType: ResizeResultType, "image" | "canvas"
75706
- */
75707
- function resize(img, _a) {
75708
- var _b = _a.inputType, inputType = _b === void 0 ? 'image/jpeg' : _b, _c = _a.imageWidth, imageWidth = _c === void 0 ? -1 : _c, _d = _a.imageHeight, imageHeight = _d === void 0 ? -1 : _d, _e = _a.equalProportion, equalProportion = _e === void 0 ? true : _e, //等比例拉伸
75709
- _f = _a.sideLengthLimit, //等比例拉伸
75710
- sideLengthLimit = _f === void 0 ? 640 : _f, _g = _a.baseOnShortSide, baseOnShortSide = _g === void 0 ? true : _g, // 是否以短边为基准缩放
75711
- _h = _a.resultType, // 是否以短边为基准缩放
75712
- resultType = _h === void 0 ? "image" : _h;
75713
- var scale = 1;
75714
- var scaleBaseFunc = baseOnShortSide ? Math.min : Math.max;
75715
- if (imageWidth > 0 && imageHeight > 0) {
75716
- scale = sideLengthLimit / scaleBaseFunc(imageWidth, imageHeight);
75717
- }
75718
- else if (img.width > 0 && img.height > 0) {
75719
- scale = sideLengthLimit / scaleBaseFunc(img.width, img.height);
75720
- imageWidth = img.width;
75721
- imageHeight = img.height;
75722
- }
75723
- else {
75724
- return Promise.reject(new Error('image width/height 无效'));
75725
- }
75726
- var targetWidth = scale > 1 ? imageWidth : imageWidth * scale;
75727
- var targetHeight = scale > 1 ? imageHeight : imageHeight * scale;
75728
- if (resultType === "image") {
75729
- return image2Canvas(img, inputType, targetWidth, targetHeight).then(function (canvas) {
75730
- return canvas2Image(canvas);
75731
- });
75732
- }
75733
- else {
75734
- return image2Canvas(img, inputType, targetWidth, targetHeight);
75735
- }
75736
- }
75770
+ /**
75771
+ * Convert File to data schema url
75772
+ * @param file
75773
+ */
75774
+ function file2DataURL(file) {
75775
+ return new Promise(function (resolve, reject) {
75776
+ var a = new FileReader();
75777
+ a.onload = function (res) {
75778
+ if (res && res.target) {
75779
+ resolve(res.target.result);
75780
+ }
75781
+ else {
75782
+ reject(new Error('读取文件url失败'));
75783
+ }
75784
+ };
75785
+ a.readAsDataURL(file);
75786
+ });
75787
+ }
75788
+ /**
75789
+ * Convert file to image
75790
+ * @param file
75791
+ */
75792
+ function file2Image(file) {
75793
+ return new Promise(function (resolve, reject) {
75794
+ file2DataURL(file).then(function (url) {
75795
+ var img = new Image();
75796
+ img.src = url;
75797
+ img.onload = function (e) {
75798
+ if (img.complete) {
75799
+ resolve(img);
75800
+ }
75801
+ else {
75802
+ reject(new Error('文件加载失败'));
75803
+ }
75804
+ };
75805
+ }).catch(reject);
75806
+ });
75807
+ }
75808
+ function image2file(img, fileName, lastModified, type, quality) {
75809
+ if (type === void 0) { type = "image/jpeg"; }
75810
+ if (quality === void 0) { quality = 0.8; }
75811
+ return image2Canvas(img, type).then(function (canvas) {
75812
+ return canvas2File(canvas, fileName, lastModified, type, quality);
75813
+ });
75814
+ }
75815
+ /**
75816
+ * Draw image on canvas
75817
+ * @param img
75818
+ * @param width
75819
+ * @param height
75820
+ */
75821
+ function image2Canvas(img, type, width, height) {
75822
+ var canvas = document.createElement('canvas');
75823
+ if (!width) {
75824
+ width = img.width;
75825
+ }
75826
+ if (!height) {
75827
+ height = img.height;
75828
+ }
75829
+ canvas.width = width;
75830
+ canvas.height = height;
75831
+ var ctx = canvas.getContext('2d');
75832
+ if (ctx) {
75833
+ // png经canvas.toDataURL转换后背景变成黑色,这里提前填充白色
75834
+ ctx.fillStyle = 'transparent';
75835
+ if (type === 'image/jpeg') {
75836
+ ctx.fillStyle = '#fff';
75837
+ }
75838
+ ctx.drawImage(img, 0, 0, width, height);
75839
+ return Promise.resolve(canvas);
75840
+ }
75841
+ else {
75842
+ return Promise.reject(null);
75843
+ }
75844
+ }
75845
+ /**
75846
+ * Export Image from canvas
75847
+ * @param canvas
75848
+ * @param type
75849
+ * @param quality
75850
+ * @see {@link https://meshworld.in/convert-canvas-to-an-image-using-javascript/}
75851
+ */
75852
+ function canvas2Image(canvas, type, quality) {
75853
+ if (type === void 0) { type = "image/jpeg"; }
75854
+ if (quality === void 0) { quality = 0.8; }
75855
+ var image = new Image();
75856
+ image.src = canvas.toDataURL(type, quality);
75857
+ return Promise.resolve(image);
75858
+ }
75859
+ /**
75860
+ * Export File from canvas
75861
+ * @param canvas
75862
+ * @param fileName
75863
+ * @param lastModified
75864
+ * @param type
75865
+ * @param quality
75866
+ * @see {@link https://meshworld.in/convert-canvas-to-an-image-using-javascript/}
75867
+ */
75868
+ function canvas2File(canvas, fileName, lastModified, type, quality) {
75869
+ if (type === void 0) { type = "image/jpeg"; }
75870
+ if (quality === void 0) { quality = 0.8; }
75871
+ return new Promise(function (resolve, reject) {
75872
+ canvas.toBlob(function (blob) {
75873
+ if (!blob) {
75874
+ reject(new Error('canvas文件导出失败'));
75875
+ }
75876
+ else {
75877
+ var file = new File([blob], fileName, { lastModified: lastModified, type: type });
75878
+ // console.log("file size " + file.size / 1024 + "kb");
75879
+ // console.log(file)
75880
+ resolve(file);
75881
+ }
75882
+ }, type, quality);
75883
+ });
75884
+ }
75885
+ /**
75886
+ * 缩放图片
75887
+ * @param img:HTMLImageElement 图片对象
75888
+ * @param inputType 图片类型
75889
+ * @param imageWidth 图片宽度
75890
+ * @param imageHeight 图片高度
75891
+ * @param equalProportion 是否等比例拉伸,默认是,目前只支持等比例拉伸
75892
+ * @param sideLengthLimit 图片边长限制
75893
+ * @param baseOnShortSide 是否以短边为限制
75894
+ * @param resultType: ResizeResultType, "image" | "canvas"
75895
+ */
75896
+ function resize(img, _a) {
75897
+ var _b = _a.inputType, inputType = _b === void 0 ? 'image/jpeg' : _b, _c = _a.imageWidth, imageWidth = _c === void 0 ? -1 : _c, _d = _a.imageHeight, imageHeight = _d === void 0 ? -1 : _d, _e = _a.equalProportion, equalProportion = _e === void 0 ? true : _e, //等比例拉伸
75898
+ _f = _a.sideLengthLimit, //等比例拉伸
75899
+ sideLengthLimit = _f === void 0 ? 640 : _f, _g = _a.baseOnShortSide, baseOnShortSide = _g === void 0 ? true : _g, // 是否以短边为基准缩放
75900
+ _h = _a.resultType, // 是否以短边为基准缩放
75901
+ resultType = _h === void 0 ? "image" : _h;
75902
+ var scale = 1;
75903
+ var scaleBaseFunc = baseOnShortSide ? Math.min : Math.max;
75904
+ if (imageWidth > 0 && imageHeight > 0) {
75905
+ scale = sideLengthLimit / scaleBaseFunc(imageWidth, imageHeight);
75906
+ }
75907
+ else if (img.width > 0 && img.height > 0) {
75908
+ scale = sideLengthLimit / scaleBaseFunc(img.width, img.height);
75909
+ imageWidth = img.width;
75910
+ imageHeight = img.height;
75911
+ }
75912
+ else {
75913
+ return Promise.reject(new Error('image width/height 无效'));
75914
+ }
75915
+ var targetWidth = scale > 1 ? imageWidth : imageWidth * scale;
75916
+ var targetHeight = scale > 1 ? imageHeight : imageHeight * scale;
75917
+ if (resultType === "image") {
75918
+ return image2Canvas(img, inputType, targetWidth, targetHeight).then(function (canvas) {
75919
+ return canvas2Image(canvas);
75920
+ });
75921
+ }
75922
+ else {
75923
+ return image2Canvas(img, inputType, targetWidth, targetHeight);
75924
+ }
75925
+ }
75737
75926
  //# sourceMappingURL=image-util.js.map
75738
75927
  // CONCATENATED MODULE: ./node_modules/@egova/media/lib/image-processor.js
75739
-
75740
-
75741
-
75742
- var MAX_SIDE_LENGTH = 1920;
75743
- var MIN_SIDE_LEnGTH = 480;
75744
- var PHOTO_FILE_SIZE_LIMIT = 1000; // 1000kb
75745
- var DEFAULT_JPEG_QUALITY = 0.8;
75746
- var MIN_JPEG_QUALITY = 0.1;
75747
- var JPEG_QUALITY_STEP = 0.05;
75748
- var image_processor_ResizeOptions = /** @class */ (function () {
75749
- function ResizeOptions(maxSideLength) {
75750
- if (checkIsUndefinedOrNull(maxSideLength)) {
75751
- this.maxSideLength = MAX_SIDE_LENGTH;
75752
- }
75753
- else {
75754
- this.maxSideLength = maxSideLength;
75755
- if (this.maxSideLength > MAX_SIDE_LENGTH) {
75756
- this.maxSideLength = MAX_SIDE_LENGTH;
75757
- }
75758
- else if (this.maxSideLength < MIN_SIDE_LEnGTH) {
75759
- this.maxSideLength = MIN_SIDE_LEnGTH;
75760
- }
75761
- }
75762
- }
75763
- return ResizeOptions;
75764
- }());
75765
-
75766
- var image_processor_CompressOptions = /** @class */ (function () {
75767
- function CompressOptions(photoFileSizeLimit) {
75768
- if (checkIsUndefinedOrNull(photoFileSizeLimit)) {
75769
- this.photoFileSizeLimit = PHOTO_FILE_SIZE_LIMIT;
75770
- }
75771
- else {
75772
- this.photoFileSizeLimit = photoFileSizeLimit;
75773
- }
75774
- }
75775
- return CompressOptions;
75776
- }());
75777
-
75778
- var image_processor_ImageProcessor = /** @class */ (function () {
75779
- function ImageProcessor(file, resizeOptions, watermarkOptions, compressOptions) {
75780
- this.file = file;
75781
- this.resizeOptions = resizeOptions;
75782
- this.watermarkOptions = watermarkOptions;
75783
- this.compressOptions = compressOptions;
75784
- }
75785
- ImageProcessor.prototype.process = function () {
75786
- var _this = this;
75787
- var filename = this.file.name;
75788
- var lastModified = this.file.lastModified;
75789
- var fileType = this.file.type;
75790
- if (this.file.size > this.compressOptions.photoFileSizeLimit * 1024) {
75791
- fileType = 'image/jpeg';
75792
- }
75793
- if (fileType === 'image/gif') {
75794
- fileType = 'image/png';
75795
- }
75796
- return file2Image(this.file).then(function (img) {
75797
- //第一步 resize image
75798
- return resize(img, {
75799
- inputType: fileType,
75800
- sideLengthLimit: _this.resizeOptions.maxSideLength,
75801
- resultType: "canvas"
75802
- });
75803
- }).then(function (result) {
75804
- var canvas = result;
75805
- //第二步 打水印
75806
- return renderWatermark(canvas, _this.watermarkOptions);
75807
- }).then(function (canvas) {
75808
- var exportFilename = filename.replace(/\./g, "-") + '.jpg';
75809
- return _this.compress(canvas, exportFilename, lastModified, fileType, DEFAULT_JPEG_QUALITY);
75810
- });
75811
- };
75812
- ImageProcessor.prototype.compress = function (canvas, filename, lastModified, type, quality) {
75813
- var _this = this;
75814
- return canvas2File(canvas, filename, lastModified, type, quality).then(function (file) {
75815
- if (file.size > _this.compressOptions.photoFileSizeLimit * 1024 &&
75816
- quality - JPEG_QUALITY_STEP > MIN_JPEG_QUALITY) {
75817
- return _this.compress(canvas, filename, lastModified, type, quality - JPEG_QUALITY_STEP);
75818
- }
75819
- else {
75820
- return Promise.resolve(file);
75821
- }
75822
- });
75823
- };
75824
- return ImageProcessor;
75825
- }());
75826
-
75928
+ var image_processor_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
75929
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
75930
+ return new (P || (P = Promise))(function (resolve, reject) {
75931
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
75932
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
75933
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
75934
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
75935
+ });
75936
+ };
75937
+ var image_processor_generator = (undefined && undefined.__generator) || function (thisArg, body) {
75938
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
75939
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
75940
+ function verb(n) { return function (v) { return step([n, v]); }; }
75941
+ function step(op) {
75942
+ if (f) throw new TypeError("Generator is already executing.");
75943
+ while (_) try {
75944
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
75945
+ if (y = 0, t) op = [op[0] & 2, t.value];
75946
+ switch (op[0]) {
75947
+ case 0: case 1: t = op; break;
75948
+ case 4: _.label++; return { value: op[1], done: false };
75949
+ case 5: _.label++; y = op[1]; op = [0]; continue;
75950
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
75951
+ default:
75952
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
75953
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
75954
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
75955
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
75956
+ if (t[2]) _.ops.pop();
75957
+ _.trys.pop(); continue;
75958
+ }
75959
+ op = body.call(thisArg, _);
75960
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
75961
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
75962
+ }
75963
+ };
75964
+
75965
+
75966
+
75967
+ var MAX_SIDE_LENGTH = 1920;
75968
+ var MIN_SIDE_LENGTH = 480;
75969
+ var PHOTO_FILE_SIZE_LIMIT = 1000; // 1000kb
75970
+ var DEFAULT_JPEG_QUALITY = 0.8;
75971
+ var MIN_JPEG_QUALITY = 0.1;
75972
+ var JPEG_QUALITY_STEP = 0.05;
75973
+ var image_processor_ResizeOptions = /** @class */ (function () {
75974
+ function ResizeOptions(maxSideLength) {
75975
+ if (checkIsUndefinedOrNull(maxSideLength)) {
75976
+ this.maxSideLength = MAX_SIDE_LENGTH;
75977
+ }
75978
+ else {
75979
+ this.maxSideLength = maxSideLength;
75980
+ if (this.maxSideLength > MAX_SIDE_LENGTH) {
75981
+ this.maxSideLength = MAX_SIDE_LENGTH;
75982
+ }
75983
+ else if (this.maxSideLength < MIN_SIDE_LENGTH) {
75984
+ this.maxSideLength = MIN_SIDE_LENGTH;
75985
+ }
75986
+ }
75987
+ }
75988
+ return ResizeOptions;
75989
+ }());
75990
+
75991
+ var image_processor_CompressOptions = /** @class */ (function () {
75992
+ function CompressOptions(photoFileSizeLimit) {
75993
+ if (checkIsUndefinedOrNull(photoFileSizeLimit)) {
75994
+ this.photoFileSizeLimit = PHOTO_FILE_SIZE_LIMIT;
75995
+ }
75996
+ else {
75997
+ this.photoFileSizeLimit = photoFileSizeLimit;
75998
+ }
75999
+ }
76000
+ return CompressOptions;
76001
+ }());
76002
+
76003
+ var image_processor_ImageProcessor = /** @class */ (function () {
76004
+ function ImageProcessor(file, resizeOptions, watermarkOptions, compressOptions) {
76005
+ this.file = file;
76006
+ this.resizeOptions = resizeOptions;
76007
+ this.watermarkOptions = watermarkOptions;
76008
+ this.compressOptions = compressOptions;
76009
+ }
76010
+ ImageProcessor.prototype.process = function () {
76011
+ var _this = this;
76012
+ var filename = this.file.name;
76013
+ var lastModified = this.file.lastModified;
76014
+ var fileType = this.file.type;
76015
+ if (this.file.size > this.compressOptions.photoFileSizeLimit * 1024) {
76016
+ fileType = "image/jpeg";
76017
+ }
76018
+ if (fileType === "image/gif") {
76019
+ fileType = "image/png";
76020
+ }
76021
+ return file2Image(this.file)
76022
+ .then(function (img) {
76023
+ //第一步 resize image
76024
+ return resize(img, {
76025
+ inputType: fileType,
76026
+ sideLengthLimit: _this.resizeOptions.maxSideLength,
76027
+ resultType: "canvas",
76028
+ });
76029
+ })
76030
+ .then(function (result) { return image_processor_awaiter(_this, void 0, void 0, function () {
76031
+ var canvas;
76032
+ return image_processor_generator(this, function (_a) {
76033
+ switch (_a.label) {
76034
+ case 0:
76035
+ canvas = result;
76036
+ return [4 /*yield*/, renderWatermark(canvas, this.watermarkOptions)];
76037
+ case 1:
76038
+ //第二步 打水印
76039
+ return [2 /*return*/, _a.sent()];
76040
+ }
76041
+ });
76042
+ }); })
76043
+ .then(function (canvas) {
76044
+ var exportFilename = filename.replace(/\./g, "-") + ".jpg";
76045
+ return _this.compress(canvas, exportFilename, lastModified, fileType, DEFAULT_JPEG_QUALITY);
76046
+ });
76047
+ };
76048
+ ImageProcessor.prototype.compress = function (canvas, filename, lastModified, type, quality) {
76049
+ var _this = this;
76050
+ return canvas2File(canvas, filename, lastModified, type, quality).then(function (file) {
76051
+ if (file.size > _this.compressOptions.photoFileSizeLimit * 1024 &&
76052
+ quality - JPEG_QUALITY_STEP > MIN_JPEG_QUALITY) {
76053
+ return _this.compress(canvas, filename, lastModified, type, quality - JPEG_QUALITY_STEP);
76054
+ }
76055
+ else {
76056
+ return Promise.resolve(file);
76057
+ }
76058
+ });
76059
+ };
76060
+ return ImageProcessor;
76061
+ }());
76062
+
75827
76063
  //# sourceMappingURL=image-processor.js.map
75828
76064
  // CONCATENATED MODULE: ./node_modules/@egova/media/lib/index.js
75829
- /**
75830
- * @description 水印渲染类
75831
- * @author Jiaji Yin
75832
- * @date 2021-11-05
75833
- */
75834
-
75835
-
75836
-
76065
+ /**
76066
+ * @description 水印渲染类
76067
+ * @author Jiaji Yin
76068
+ * @date 2021-11-05
76069
+ */
76070
+
76071
+
76072
+
75837
76073
  //# sourceMappingURL=index.js.map
75838
76074
  // CONCATENATED MODULE: ./es/media-picker/image/TakePhotoIcon.js
75839
76075
  /* harmony default export */ var TakePhotoIcon = ({
@@ -77024,6 +77260,8 @@ var media_picker_createNamespace = Object(utils["b" /* createNamespace */])('med
77024
77260
  address: _this4.watermarkOptions.address || "",
77025
77261
  humanName: _this4.watermarkOptions.humanName || "",
77026
77262
  projectName: _this4.watermarkOptions.projectName || "",
77263
+ logo: _this4.watermarkOptions.logo || "",
77264
+ applicationName: _this4.watermarkOptions.applicationName || "",
77027
77265
  watermarkTime: new Date()
77028
77266
  }
77029
77267
  });
@@ -79286,8 +79524,8 @@ var vuePdfNoSssvue_type_script_lang_js_ = __webpack_require__(10);
79286
79524
 
79287
79525
  // CONCATENATED MODULE: ./node_modules/egova-vue-pdf/src/vuePdfNoSss.vue?vue&type=script&lang=js&
79288
79526
  /* harmony default export */ var src_vuePdfNoSssvue_type_script_lang_js_ = (vuePdfNoSssvue_type_script_lang_js_["a" /* default */]);
79289
- // EXTERNAL MODULE: ./node_modules/egova-vue-pdf/src/annotationLayer.css?vue&type=style&index=0&prod&lang=css&
79290
- var annotationLayervue_type_style_index_0_prod_lang_css_ = __webpack_require__(34);
79527
+ // EXTERNAL MODULE: ./node_modules/egova-vue-pdf/src/annotationLayer.css?vue&type=style&index=0&lang=css&
79528
+ var annotationLayervue_type_style_index_0_lang_css_ = __webpack_require__(34);
79291
79529
 
79292
79530
  // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
79293
79531
  var componentNormalizer = __webpack_require__(11);
@@ -80438,10 +80676,10 @@ var right = 'right';
80438
80676
  var esm_left = 'left';
80439
80677
  var auto = 'auto';
80440
80678
  var basePlacements = [esm_top, esm_bottom, right, esm_left];
80441
- var start = 'start';
80442
- var end = 'end';
80679
+ var esm_start = 'start';
80680
+ var esm_end = 'end';
80443
80681
  var placements = /*#__PURE__*/[].concat(basePlacements, [auto]).reduce(function (acc, placement) {
80444
- return acc.concat([placement, placement + "-" + start, placement + "-" + end]);
80682
+ return acc.concat([placement, placement + "-" + esm_start, placement + "-" + esm_end]);
80445
80683
  }, []); // modifiers that need to read the DOM
80446
80684
 
80447
80685
  var beforeRead = 'beforeRead';
@@ -80694,11 +80932,11 @@ function computeOffsets(_ref) {
80694
80932
  var len = mainAxis === 'y' ? 'height' : 'width';
80695
80933
 
80696
80934
  switch (variation) {
80697
- case start:
80935
+ case esm_start:
80698
80936
  offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
80699
80937
  break;
80700
80938
 
80701
- case end:
80939
+ case esm_end:
80702
80940
  offsets[mainAxis] = offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
80703
80941
  break;
80704
80942
  }
@@ -84964,7 +85202,9 @@ var uploader_createNamespace = Object(utils["b" /* createNamespace */])('uploade
84964
85202
  address: _this.watermarkOptions.address || "",
84965
85203
  watermarkTime: new Date(),
84966
85204
  humanName: _this.watermarkOptions.humanName || "",
84967
- projectName: _this.watermarkOptions.projectName || ""
85205
+ projectName: _this.watermarkOptions.projectName || "",
85206
+ logo: _this.watermarkOptions.logo || "",
85207
+ applicationName: _this.watermarkOptions.applicationName || ""
84968
85208
  });
84969
85209
  var watermarkOptions = new WatermarkOptions({
84970
85210
  enabled: true,
@@ -85451,7 +85691,7 @@ var uploader_createNamespace = Object(utils["b" /* createNamespace */])('uploade
85451
85691
 
85452
85692
 
85453
85693
 
85454
- var version = '1.0.20';
85694
+ var version = '1.0.21';
85455
85695
 
85456
85696
  function install(Vue) {
85457
85697
  var components = [action_sheet, es_area, avatar, back_top, badge, es_button, calendar, cascader, cell, cell_group, es_checkbox, checkbox_group, circle, col, collapse, collapse_item, count_down, datetime_picker, dialog, divider, dropdown_item, dropdown_menu, empty, es_field, fold_dialog, es_form, grid, grid_item, hierarchy_select, es_icon, es_image, image_preview, index_anchor, index_bar, es_info, lazyload, es_list, es_loading, locale["a" /* default */], media_picker, media_player, multiple_picker, nav_bar, notice_bar, number_keyboard, es_overlay, password_input, pdf_viewer, pdf_viewer_v2, es_picker, popover, popup, pull_refresh, es_radio, radio_group, es_rate, row, search, signature, skeleton, slider, es_step, stepper, es_steps, es_sticky, swipe, swipe_cell, swipe_item, es_switch, switch_cell, tab, tabbar, tabbar_item, table, tabs, es_tag, timeline, es_toast, uploader];