@vtx/components 3.1.16 → 3.1.18

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.
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.extractImageDataFromRtf = extractImageDataFromRtf;
9
+ exports.findAllImgSrcsFromHtml = findAllImgSrcsFromHtml;
10
+ exports.replaceImagesFileSourceWithInlineRepresentation = replaceImagesFileSourceWithInlineRepresentation;
11
+ exports.withEmptyHtml = withEmptyHtml;
12
+
13
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
14
+
15
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
16
+
17
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
18
+
19
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
20
+
21
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
22
+
23
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
24
+
25
+ function findAllImgSrcsFromHtml(htmlData) {
26
+ var imgReg = /<img.*?(?:>|\/>)/gi; //匹配图片中的img标签
27
+
28
+ var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; // 匹配图片中的src
29
+
30
+ var widthReg = /width=[\'\"]?([^\'\"]*)[\'\"]?/i; // 匹配图片中的width
31
+
32
+ var heightReg = /height=[\'\"]?([^\'\"]*)[\'\"]?/i; // 匹配图片中的height
33
+
34
+ var arr = htmlData.match(imgReg); //筛选出所有的img
35
+
36
+ if (!arr || Array.isArray(arr) && !arr.length) {
37
+ return false;
38
+ }
39
+
40
+ var srcArr = [];
41
+
42
+ for (var i = 0; i < arr.length; i++) {
43
+ var src = arr[i].match(srcReg);
44
+ var width = arr[i].match(widthReg);
45
+ var height = arr[i].match(heightReg); // 获取图片地址
46
+
47
+ srcArr.push({
48
+ width: width[1],
49
+ height: height[1],
50
+ url: src[1],
51
+ img: arr[i]
52
+ });
53
+ }
54
+
55
+ return srcArr;
56
+ } // 处理为空的时候
57
+
58
+
59
+ function withEmptyHtml(editor) {
60
+ var getHtml = editor.getHtml;
61
+ var newEditor = editor;
62
+
63
+ newEditor.getHtml = function () {
64
+ if (newEditor.isEmpty()) {
65
+ return '';
66
+ }
67
+
68
+ return getHtml();
69
+ };
70
+
71
+ return newEditor;
72
+ }
73
+
74
+ function extractImageDataFromRtf(rtfData) {
75
+ if (!rtfData) {
76
+ return [];
77
+ }
78
+
79
+ var regexPictureHeader = /{\\pict[\s\S]+?({\\\*\\blipuid\s?[\da-fA-F]+)[\s}]*/;
80
+ var regexPicture = new RegExp('(?:(' + regexPictureHeader.source + '))([\\da-fA-F\\s]+)\\}', 'g');
81
+ var images = rtfData.match(regexPicture);
82
+ var result = [];
83
+
84
+ if (images) {
85
+ var _iterator = _createForOfIteratorHelper(images),
86
+ _step;
87
+
88
+ try {
89
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
90
+ var image = _step.value;
91
+ var imageType = false;
92
+
93
+ if (image.includes('\\pngblip')) {
94
+ imageType = 'image/png';
95
+ } else if (image.includes('\\jpegblip')) {
96
+ imageType = 'image/jpeg';
97
+ }
98
+
99
+ if (imageType) {
100
+ result.push({
101
+ hex: image.replace(regexPictureHeader, '').replace(/[^\da-fA-F]/g, ''),
102
+ type: imageType
103
+ });
104
+ }
105
+ }
106
+ } catch (err) {
107
+ _iterator.e(err);
108
+ } finally {
109
+ _iterator.f();
110
+ }
111
+ }
112
+
113
+ return result;
114
+ }
115
+
116
+ function replaceImagesFileSourceWithInlineRepresentation(_x, _x2, _x3) {
117
+ return _replaceImagesFileSourceWithInlineRepresentation.apply(this, arguments);
118
+ }
119
+
120
+ function _replaceImagesFileSourceWithInlineRepresentation() {
121
+ _replaceImagesFileSourceWithInlineRepresentation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(htmlData, imageSrcs, imagesHexSources) {
122
+ var isBase64Data,
123
+ uploadUrl,
124
+ downloadUrl,
125
+ i,
126
+ _imageSrcs$i,
127
+ _imageSrcs$i2,
128
+ _imageSrcs$i3,
129
+ _imageSrcs$i4,
130
+ _url$split,
131
+ _url$split$slice,
132
+ url,
133
+ width,
134
+ height,
135
+ img,
136
+ newSrc,
137
+ formData,
138
+ blob,
139
+ imgName,
140
+ file,
141
+ res,
142
+ _args = arguments;
143
+
144
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
145
+ while (1) {
146
+ switch (_context.prev = _context.next) {
147
+ case 0:
148
+ isBase64Data = _args.length > 3 && _args[3] !== undefined ? _args[3] : true;
149
+ uploadUrl = _args.length > 4 ? _args[4] : undefined;
150
+ downloadUrl = _args.length > 5 ? _args[5] : undefined;
151
+
152
+ if (!(imageSrcs.length === imagesHexSources.length)) {
153
+ _context.next = 23;
154
+ break;
155
+ }
156
+
157
+ i = 0;
158
+
159
+ case 5:
160
+ if (!(i < imageSrcs.length)) {
161
+ _context.next = 23;
162
+ break;
163
+ }
164
+
165
+ url = imageSrcs === null || imageSrcs === void 0 ? void 0 : (_imageSrcs$i = imageSrcs[i]) === null || _imageSrcs$i === void 0 ? void 0 : _imageSrcs$i.url;
166
+ width = imageSrcs === null || imageSrcs === void 0 ? void 0 : (_imageSrcs$i2 = imageSrcs[i]) === null || _imageSrcs$i2 === void 0 ? void 0 : _imageSrcs$i2.width;
167
+ height = imageSrcs === null || imageSrcs === void 0 ? void 0 : (_imageSrcs$i3 = imageSrcs[i]) === null || _imageSrcs$i3 === void 0 ? void 0 : _imageSrcs$i3.height;
168
+ img = imageSrcs === null || imageSrcs === void 0 ? void 0 : (_imageSrcs$i4 = imageSrcs[i]) === null || _imageSrcs$i4 === void 0 ? void 0 : _imageSrcs$i4.img;
169
+ newSrc = isBase64Data ? "data:".concat(imagesHexSources[i].type, ";base64,").concat(_convertHexToBase64(imagesHexSources[i].hex)) : imagesHexSources[i];
170
+ formData = new FormData();
171
+ blob = convertBase64UrlToBlob(newSrc);
172
+ imgName = ((_url$split = url.split('\\')) === null || _url$split === void 0 ? void 0 : (_url$split$slice = _url$split.slice(-1)) === null || _url$split$slice === void 0 ? void 0 : _url$split$slice[0]) || 'image.jpg';
173
+ file = new File([blob], imgName);
174
+ formData.append('file', file);
175
+ _context.next = 18;
176
+ return window.fetch(uploadUrl, {
177
+ method: 'POST',
178
+ body: formData
179
+ }).then(function (response) {
180
+ return response.json();
181
+ });
182
+
183
+ case 18:
184
+ res = _context.sent;
185
+ htmlData = htmlData.replace(img, "<img src=\"".concat(downloadUrl).concat(res.data[0].id, "\" style=\"width:").concat(width, "px;height:").concat(height, "px\""));
186
+
187
+ case 20:
188
+ i++;
189
+ _context.next = 5;
190
+ break;
191
+
192
+ case 23:
193
+ return _context.abrupt("return", htmlData);
194
+
195
+ case 24:
196
+ case "end":
197
+ return _context.stop();
198
+ }
199
+ }
200
+ }, _callee);
201
+ }));
202
+ return _replaceImagesFileSourceWithInlineRepresentation.apply(this, arguments);
203
+ }
204
+
205
+ function _convertHexToBase64(hexString) {
206
+ return btoa(hexString.match(/\w{2}/g).map(function (_char) {
207
+ return String.fromCharCode(parseInt(_char, 16));
208
+ }).join(''));
209
+ }
210
+
211
+ function convertBase64UrlToBlob(dataurl) {
212
+ var arr = dataurl.split(','); //注意base64的最后面中括号和引号是不转译的
213
+
214
+ var _arr = arr[1].substring(0, arr[1].length - 2);
215
+
216
+ var mime = arr[0].match(/:(.*?);/)[1],
217
+ bstr = atob(_arr),
218
+ n = bstr.length,
219
+ u8arr = new Uint8Array(n);
220
+
221
+ while (n--) {
222
+ u8arr[n] = bstr.charCodeAt(n);
223
+ }
224
+
225
+ return new Blob([u8arr], {
226
+ type: mime
227
+ });
228
+ }
229
+ //# sourceMappingURL=wangEditorUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wangEditorUtil.js","names":["findAllImgSrcsFromHtml","htmlData","imgReg","srcReg","widthReg","heightReg","arr","match","Array","isArray","length","srcArr","i","src","width","height","push","url","img","withEmptyHtml","editor","getHtml","newEditor","isEmpty","extractImageDataFromRtf","rtfData","regexPictureHeader","regexPicture","RegExp","source","images","result","image","imageType","includes","hex","replace","type","replaceImagesFileSourceWithInlineRepresentation","imageSrcs","imagesHexSources","isBase64Data","uploadUrl","downloadUrl","newSrc","_convertHexToBase64","formData","FormData","blob","convertBase64UrlToBlob","imgName","split","slice","file","File","append","window","fetch","method","body","then","response","json","res","data","id","hexString","btoa","map","char","String","fromCharCode","parseInt","join","dataurl","_arr","substring","mime","bstr","atob","n","u8arr","Uint8Array","charCodeAt","Blob"],"sources":["vtx-wang-editor/wangEditorUtil.js"],"sourcesContent":["export function findAllImgSrcsFromHtml(htmlData) {\r\n let imgReg = /<img.*?(?:>|\\/>)/gi; //匹配图片中的img标签\r\n let srcReg = /src=[\\'\\\"]?([^\\'\\\"]*)[\\'\\\"]?/i; // 匹配图片中的src\r\n let widthReg = /width=[\\'\\\"]?([^\\'\\\"]*)[\\'\\\"]?/i; // 匹配图片中的width\r\n let heightReg = /height=[\\'\\\"]?([^\\'\\\"]*)[\\'\\\"]?/i; // 匹配图片中的height\r\n\r\n let arr = htmlData.match(imgReg); //筛选出所有的img\r\n if (!arr || (Array.isArray(arr) && !arr.length)) {\r\n return false;\r\n }\r\n\r\n let srcArr = [];\r\n for (let i = 0; i < arr.length; i++) {\r\n let src = arr[i].match(srcReg);\r\n let width = arr[i].match(widthReg);\r\n let height = arr[i].match(heightReg);\r\n // 获取图片地址\r\n srcArr.push({\r\n width: width[1],\r\n height: height[1],\r\n url: src[1],\r\n img: arr[i],\r\n });\r\n }\r\n\r\n return srcArr;\r\n}\r\n// 处理为空的时候\r\nexport function withEmptyHtml(editor) {\r\n const { getHtml } = editor;\r\n const newEditor = editor;\r\n newEditor.getHtml = () => {\r\n if (newEditor.isEmpty()) {\r\n return '';\r\n }\r\n return getHtml();\r\n };\r\n\r\n return newEditor;\r\n}\r\n\r\nexport function extractImageDataFromRtf(rtfData) {\r\n if (!rtfData) {\r\n return [];\r\n }\r\n\r\n const regexPictureHeader = /{\\\\pict[\\s\\S]+?({\\\\\\*\\\\blipuid\\s?[\\da-fA-F]+)[\\s}]*/;\r\n const regexPicture = new RegExp(\r\n '(?:(' + regexPictureHeader.source + '))([\\\\da-fA-F\\\\s]+)\\\\}',\r\n 'g',\r\n );\r\n const images = rtfData.match(regexPicture);\r\n const result = [];\r\n\r\n if (images) {\r\n for (const image of images) {\r\n let imageType = false;\r\n\r\n if (image.includes('\\\\pngblip')) {\r\n imageType = 'image/png';\r\n } else if (image.includes('\\\\jpegblip')) {\r\n imageType = 'image/jpeg';\r\n }\r\n\r\n if (imageType) {\r\n result.push({\r\n hex: image.replace(regexPictureHeader, '').replace(/[^\\da-fA-F]/g, ''),\r\n type: imageType,\r\n });\r\n }\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n\r\nexport async function replaceImagesFileSourceWithInlineRepresentation(\r\n htmlData,\r\n imageSrcs,\r\n imagesHexSources,\r\n isBase64Data = true,\r\n uploadUrl,\r\n downloadUrl,\r\n) {\r\n if (imageSrcs.length === imagesHexSources.length) {\r\n for (let i = 0; i < imageSrcs.length; i++) {\r\n const url = imageSrcs?.[i]?.url;\r\n const width = imageSrcs?.[i]?.width;\r\n const height = imageSrcs?.[i]?.height;\r\n const img = imageSrcs?.[i]?.img;\r\n const newSrc = isBase64Data\r\n ? `data:${imagesHexSources[i].type};base64,${_convertHexToBase64(\r\n imagesHexSources[i].hex,\r\n )}`\r\n : imagesHexSources[i];\r\n const formData = new FormData();\r\n let blob = convertBase64UrlToBlob(newSrc);\r\n let imgName = url.split('\\\\')?.slice(-1)?.[0] || 'image.jpg';\r\n let file = new File([blob], imgName);\r\n formData.append('file', file);\r\n const res = await window\r\n .fetch(uploadUrl, {\r\n method: 'POST',\r\n body: formData,\r\n })\r\n .then(function(response) {\r\n return response.json();\r\n });\r\n htmlData = htmlData.replace(\r\n img,\r\n `<img src=\"${downloadUrl}${res.data[0].id}\" style=\"width:${width}px;height:${height}px\"`,\r\n );\r\n }\r\n }\r\n return htmlData;\r\n}\r\n\r\nfunction _convertHexToBase64(hexString) {\r\n return btoa(\r\n hexString\r\n .match(/\\w{2}/g)\r\n .map(char => {\r\n return String.fromCharCode(parseInt(char, 16));\r\n })\r\n .join(''),\r\n );\r\n}\r\n\r\nfunction convertBase64UrlToBlob(dataurl) {\r\n var arr = dataurl.split(',');\r\n //注意base64的最后面中括号和引号是不转译的\r\n var _arr = arr[1].substring(0, arr[1].length - 2);\r\n var mime = arr[0].match(/:(.*?);/)[1],\r\n bstr = atob(_arr),\r\n n = bstr.length,\r\n u8arr = new Uint8Array(n);\r\n while (n--) {\r\n u8arr[n] = bstr.charCodeAt(n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,CAAX;;EACA,IAAImE,IAAI,GAAGvE,GAAG,CAAC,CAAD,CAAH,CAAOC,KAAP,CAAa,SAAb,EAAwB,CAAxB,CAAX;EAAA,IACIuE,IAAI,GAAGC,IAAI,CAACJ,IAAD,CADf;EAAA,IAEIK,CAAC,GAAGF,IAAI,CAACpE,MAFb;EAAA,IAGIuE,KAAK,GAAG,IAAIC,UAAJ,CAAeF,CAAf,CAHZ;;EAIA,OAAOA,CAAC,EAAR,EAAY;IACRC,KAAK,CAACD,CAAD,CAAL,GAAWF,IAAI,CAACK,UAAL,CAAgBH,CAAhB,CAAX;EACH;;EACD,OAAO,IAAII,IAAJ,CAAS,CAACH,KAAD,CAAT,EAAkB;IACrB5C,IAAI,EAAEwC;EADe,CAAlB,CAAP;AAGH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtx/components",
3
- "version": "3.1.16",
3
+ "version": "3.1.18",
4
4
  "description": "React components for Vortex",
5
5
  "keywords": [
6
6
  "react",
@@ -55,6 +55,9 @@
55
55
  "@ant-design/icons": "4.7.0",
56
56
  "@vtx/map": "latest",
57
57
  "@vtx/utils": "latest",
58
+ "@wangeditor/editor": "^5.1.21",
59
+ "@wangeditor/editor-for-react": "^1.0.5",
60
+ "@wangeditor/plugin-upload-attachment": "^1.1.0",
58
61
  "ahooks": "^3.1.5",
59
62
  "antd": "4.20.5",
60
63
  "axios": "^0.21.1",