@rpascene/shared 0.30.8
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/README.md +9 -0
- package/dist/es/baseDB.mjs +109 -0
- package/dist/es/build/copy-static.mjs +29 -0
- package/dist/es/common.mjs +37 -0
- package/dist/es/constants/example-code.mjs +202 -0
- package/dist/es/constants/index.mjs +74 -0
- package/dist/es/env/basic.mjs +6 -0
- package/dist/es/env/constants.mjs +97 -0
- package/dist/es/env/decide-model-config.mjs +172 -0
- package/dist/es/env/global-config-manager.mjs +82 -0
- package/dist/es/env/helper.mjs +45 -0
- package/dist/es/env/index.mjs +5 -0
- package/dist/es/env/init-debug.mjs +18 -0
- package/dist/es/env/model-config-manager.mjs +99 -0
- package/dist/es/env/parse.mjs +69 -0
- package/dist/es/env/types.mjs +265 -0
- package/dist/es/env/utils.mjs +18 -0
- package/dist/es/extractor/constants.mjs +2 -0
- package/dist/es/extractor/cs_postmessage.mjs +61 -0
- package/dist/es/extractor/customLocator.mjs +646 -0
- package/dist/es/extractor/debug.mjs +6 -0
- package/dist/es/extractor/dom-util.mjs +92 -0
- package/dist/es/extractor/index.mjs +7 -0
- package/dist/es/extractor/locator.mjs +95 -0
- package/dist/es/extractor/tree.mjs +81 -0
- package/dist/es/extractor/util.mjs +244 -0
- package/dist/es/extractor/web-extractor.mjs +361 -0
- package/dist/es/img/box-select.mjs +184 -0
- package/dist/es/img/draw-box.mjs +42 -0
- package/dist/es/img/get-jimp.mjs +10 -0
- package/dist/es/img/get-photon.mjs +19 -0
- package/dist/es/img/get-sharp.mjs +11 -0
- package/dist/es/img/index.mjs +5 -0
- package/dist/es/img/info.mjs +32 -0
- package/dist/es/img/transform.mjs +192 -0
- package/dist/es/index.mjs +3 -0
- package/dist/es/logger.mjs +61 -0
- package/dist/es/node/fs.mjs +44 -0
- package/dist/es/node/index.mjs +1 -0
- package/dist/es/polyfills/async-hooks.mjs +2 -0
- package/dist/es/polyfills/index.mjs +1 -0
- package/dist/es/types/index.mjs +3 -0
- package/dist/es/us-keyboard-layout.mjs +1414 -0
- package/dist/es/us-keyboard-layout.mjs.LICENSE.txt +5 -0
- package/dist/es/utils.mjs +66 -0
- package/dist/lib/baseDB.js +149 -0
- package/dist/lib/build/copy-static.js +77 -0
- package/dist/lib/common.js +93 -0
- package/dist/lib/constants/example-code.js +239 -0
- package/dist/lib/constants/index.js +153 -0
- package/dist/lib/env/basic.js +40 -0
- package/dist/lib/env/constants.js +143 -0
- package/dist/lib/env/decide-model-config.js +212 -0
- package/dist/lib/env/global-config-manager.js +116 -0
- package/dist/lib/env/helper.js +85 -0
- package/dist/lib/env/index.js +94 -0
- package/dist/lib/env/init-debug.js +52 -0
- package/dist/lib/env/model-config-manager.js +133 -0
- package/dist/lib/env/parse.js +106 -0
- package/dist/lib/env/types.js +650 -0
- package/dist/lib/env/utils.js +61 -0
- package/dist/lib/extractor/constants.js +42 -0
- package/dist/lib/extractor/cs_postmessage.js +98 -0
- package/dist/lib/extractor/customLocator.js +698 -0
- package/dist/lib/extractor/debug.js +12 -0
- package/dist/lib/extractor/dom-util.js +150 -0
- package/dist/lib/extractor/index.js +153 -0
- package/dist/lib/extractor/locator.js +141 -0
- package/dist/lib/extractor/tree.js +127 -0
- package/dist/lib/extractor/util.js +335 -0
- package/dist/lib/extractor/web-extractor.js +407 -0
- package/dist/lib/img/box-select.js +232 -0
- package/dist/lib/img/draw-box.js +89 -0
- package/dist/lib/img/get-jimp.js +72 -0
- package/dist/lib/img/get-photon.js +76 -0
- package/dist/lib/img/get-sharp.js +63 -0
- package/dist/lib/img/index.js +102 -0
- package/dist/lib/img/info.js +86 -0
- package/dist/lib/img/transform.js +279 -0
- package/dist/lib/index.js +43 -0
- package/dist/lib/logger.js +114 -0
- package/dist/lib/node/fs.js +97 -0
- package/dist/lib/node/index.js +60 -0
- package/dist/lib/polyfills/async-hooks.js +36 -0
- package/dist/lib/polyfills/index.js +60 -0
- package/dist/lib/types/index.js +37 -0
- package/dist/lib/us-keyboard-layout.js +1457 -0
- package/dist/lib/us-keyboard-layout.js.LICENSE.txt +5 -0
- package/dist/lib/utils.js +136 -0
- package/dist/types/baseDB.d.ts +25 -0
- package/dist/types/build/copy-static.d.ts +31 -0
- package/dist/types/common.d.ts +12 -0
- package/dist/types/constants/example-code.d.ts +2 -0
- package/dist/types/constants/index.d.ts +23 -0
- package/dist/types/env/basic.d.ts +6 -0
- package/dist/types/env/constants.d.ts +40 -0
- package/dist/types/env/decide-model-config.d.ts +14 -0
- package/dist/types/env/global-config-manager.d.ts +32 -0
- package/dist/types/env/helper.d.ts +6 -0
- package/dist/types/env/index.d.ts +4 -0
- package/dist/types/env/init-debug.d.ts +1 -0
- package/dist/types/env/model-config-manager.d.ts +24 -0
- package/dist/types/env/parse.d.ts +12 -0
- package/dist/types/env/types.d.ts +295 -0
- package/dist/types/env/utils.d.ts +7 -0
- package/dist/types/extractor/constants.d.ts +1 -0
- package/dist/types/extractor/cs_postmessage.d.ts +2 -0
- package/dist/types/extractor/customLocator.d.ts +69 -0
- package/dist/types/extractor/debug.d.ts +1 -0
- package/dist/types/extractor/dom-util.d.ts +26 -0
- package/dist/types/extractor/index.d.ts +36 -0
- package/dist/types/extractor/locator.d.ts +7 -0
- package/dist/types/extractor/tree.d.ts +9 -0
- package/dist/types/extractor/util.d.ts +43 -0
- package/dist/types/extractor/web-extractor.d.ts +19 -0
- package/dist/types/img/box-select.d.ts +25 -0
- package/dist/types/img/draw-box.d.ts +15 -0
- package/dist/types/img/get-jimp.d.ts +2 -0
- package/dist/types/img/get-photon.d.ts +8 -0
- package/dist/types/img/get-sharp.d.ts +3 -0
- package/dist/types/img/index.d.ts +4 -0
- package/dist/types/img/info.d.ts +29 -0
- package/dist/types/img/transform.d.ts +88 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/logger.d.ts +4 -0
- package/dist/types/node/fs.d.ts +15 -0
- package/dist/types/node/index.d.ts +1 -0
- package/dist/types/polyfills/async-hooks.d.ts +6 -0
- package/dist/types/polyfills/index.d.ts +4 -0
- package/dist/types/types/index.d.ts +37 -0
- package/dist/types/us-keyboard-layout.d.ts +32 -0
- package/dist/types/utils.d.ts +22 -0
- package/package.json +102 -0
- package/src/baseDB.ts +158 -0
- package/src/build/copy-static.ts +62 -0
- package/src/common.ts +67 -0
- package/src/constants/example-code.ts +202 -0
- package/src/constants/index.ts +81 -0
- package/src/env/basic.ts +12 -0
- package/src/env/constants.ts +291 -0
- package/src/env/decide-model-config.ts +319 -0
- package/src/env/global-config-manager.ts +174 -0
- package/src/env/helper.ts +80 -0
- package/src/env/index.ts +4 -0
- package/src/env/init-debug.ts +29 -0
- package/src/env/model-config-manager.ts +145 -0
- package/src/env/parse.ts +131 -0
- package/src/env/types.ts +573 -0
- package/src/env/utils.ts +39 -0
- package/src/extractor/constants.ts +5 -0
- package/src/extractor/cs_postmessage.ts +101 -0
- package/src/extractor/customLocator.ts +1138 -0
- package/src/extractor/debug.ts +10 -0
- package/src/extractor/dom-util.ts +141 -0
- package/src/extractor/index.ts +54 -0
- package/src/extractor/locator.ts +179 -0
- package/src/extractor/tree.ts +179 -0
- package/src/extractor/util.ts +468 -0
- package/src/extractor/web-extractor.ts +559 -0
- package/src/img/box-select.ts +346 -0
- package/src/img/draw-box.ts +60 -0
- package/src/img/get-jimp.ts +12 -0
- package/src/img/get-photon.ts +48 -0
- package/src/img/get-sharp.ts +18 -0
- package/src/img/index.ts +24 -0
- package/src/img/info.ts +79 -0
- package/src/img/jimp.d.ts +4 -0
- package/src/img/transform.ts +396 -0
- package/src/index.ts +6 -0
- package/src/logger.ts +93 -0
- package/src/node/fs.ts +84 -0
- package/src/node/index.ts +1 -0
- package/src/polyfills/async-hooks.ts +6 -0
- package/src/polyfills/index.ts +4 -0
- package/src/types/index.ts +53 -0
- package/src/us-keyboard-layout.ts +723 -0
- package/src/utils.ts +127 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
collectElementInfo: ()=>collectElementInfo,
|
|
28
|
+
extractTreeNodeAsString: ()=>extractTreeNodeAsString,
|
|
29
|
+
extractTreeNode: ()=>extractTreeNode,
|
|
30
|
+
mergeElementAndChildrenRects: ()=>mergeElementAndChildrenRects,
|
|
31
|
+
extractTextWithPosition: ()=>extractTextWithPosition
|
|
32
|
+
});
|
|
33
|
+
const index_js_namespaceObject = require("../constants/index.js");
|
|
34
|
+
const external_dom_util_js_namespaceObject = require("./dom-util.js");
|
|
35
|
+
const external_tree_js_namespaceObject = require("./tree.js");
|
|
36
|
+
const external_util_js_namespaceObject = require("./util.js");
|
|
37
|
+
const external_cs_postmessage_js_namespaceObject = require("./cs_postmessage.js");
|
|
38
|
+
const external_customLocator_js_namespaceObject = require("./customLocator.js");
|
|
39
|
+
let indexId = 0;
|
|
40
|
+
function tagNameOfNode(node, currentWindow = globalThis) {
|
|
41
|
+
let tagName = '';
|
|
42
|
+
if (node instanceof currentWindow.HTMLElement) {
|
|
43
|
+
var _node_tagName;
|
|
44
|
+
tagName = null == (_node_tagName = node.tagName) ? void 0 : _node_tagName.toLowerCase();
|
|
45
|
+
} else {
|
|
46
|
+
const parentElement = node.parentElement;
|
|
47
|
+
if (parentElement && parentElement instanceof currentWindow.HTMLElement) {
|
|
48
|
+
var _parentElement_tagName;
|
|
49
|
+
tagName = null == (_parentElement_tagName = parentElement.tagName) ? void 0 : _parentElement_tagName.toLowerCase();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return tagName ? `<${tagName}>` : '';
|
|
53
|
+
}
|
|
54
|
+
function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = {
|
|
55
|
+
left: 0,
|
|
56
|
+
top: 0
|
|
57
|
+
}, isContainer = false) {
|
|
58
|
+
const rect = (0, external_util_js_namespaceObject.elementRect)(node, currentWindow, currentDocument, baseZoom);
|
|
59
|
+
if (!rect) return null;
|
|
60
|
+
if (rect.width < index_js_namespaceObject.CONTAINER_MINI_WIDTH || rect.height < index_js_namespaceObject.CONTAINER_MINI_HEIGHT) return null;
|
|
61
|
+
if (0 !== basePoint.left || 0 !== basePoint.top) {
|
|
62
|
+
rect.left += basePoint.left;
|
|
63
|
+
rect.top += basePoint.top;
|
|
64
|
+
}
|
|
65
|
+
if (rect.height >= window.innerHeight && rect.width >= window.innerWidth) return null;
|
|
66
|
+
if ((0, external_dom_util_js_namespaceObject.isFormElement)(node, currentWindow)) {
|
|
67
|
+
const attributes = (0, external_util_js_namespaceObject.getNodeAttributes)(node, currentWindow);
|
|
68
|
+
let valueContent = attributes.value || attributes.placeholder || node.textContent || '';
|
|
69
|
+
const nodeHashId = (0, external_util_js_namespaceObject.rpasceneGenerateHash)(node, valueContent, rect);
|
|
70
|
+
const tagName = node.tagName.toLowerCase();
|
|
71
|
+
if ('select' === node.tagName.toLowerCase()) {
|
|
72
|
+
const selectedOption = node.options[node.selectedIndex];
|
|
73
|
+
valueContent = (null == selectedOption ? void 0 : selectedOption.textContent) || '';
|
|
74
|
+
}
|
|
75
|
+
if (('input' === node.tagName.toLowerCase() || 'textarea' === node.tagName.toLowerCase()) && node.value) valueContent = node.value;
|
|
76
|
+
const elementInfo = {
|
|
77
|
+
id: nodeHashId,
|
|
78
|
+
nodeHashId,
|
|
79
|
+
nodeType: index_js_namespaceObject.NodeType.FORM_ITEM,
|
|
80
|
+
indexId: indexId++,
|
|
81
|
+
attributes: {
|
|
82
|
+
...attributes,
|
|
83
|
+
htmlTagName: `<${tagName}>`,
|
|
84
|
+
nodeType: index_js_namespaceObject.NodeType.FORM_ITEM
|
|
85
|
+
},
|
|
86
|
+
content: valueContent.trim(),
|
|
87
|
+
rect,
|
|
88
|
+
center: [
|
|
89
|
+
Math.round(rect.left + rect.width / 2),
|
|
90
|
+
Math.round(rect.top + rect.height / 2)
|
|
91
|
+
],
|
|
92
|
+
zoom: rect.zoom,
|
|
93
|
+
isVisible: rect.isVisible
|
|
94
|
+
};
|
|
95
|
+
return elementInfo;
|
|
96
|
+
}
|
|
97
|
+
if ((0, external_dom_util_js_namespaceObject.isButtonElement)(node, currentWindow)) {
|
|
98
|
+
const rect = mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom);
|
|
99
|
+
if (!rect) return null;
|
|
100
|
+
const attributes = (0, external_util_js_namespaceObject.getNodeAttributes)(node, currentWindow);
|
|
101
|
+
const pseudo = (0, external_util_js_namespaceObject.getPseudoElementContent)(node, currentWindow);
|
|
102
|
+
const content = node.innerText || pseudo.before || pseudo.after || '';
|
|
103
|
+
const nodeHashId = (0, external_util_js_namespaceObject.rpasceneGenerateHash)(node, content, rect);
|
|
104
|
+
const elementInfo = {
|
|
105
|
+
id: nodeHashId,
|
|
106
|
+
indexId: indexId++,
|
|
107
|
+
nodeHashId,
|
|
108
|
+
nodeType: index_js_namespaceObject.NodeType.BUTTON,
|
|
109
|
+
attributes: {
|
|
110
|
+
...attributes,
|
|
111
|
+
htmlTagName: tagNameOfNode(node, currentWindow),
|
|
112
|
+
nodeType: index_js_namespaceObject.NodeType.BUTTON
|
|
113
|
+
},
|
|
114
|
+
content,
|
|
115
|
+
rect,
|
|
116
|
+
center: [
|
|
117
|
+
Math.round(rect.left + rect.width / 2),
|
|
118
|
+
Math.round(rect.top + rect.height / 2)
|
|
119
|
+
],
|
|
120
|
+
zoom: rect.zoom,
|
|
121
|
+
isVisible: rect.isVisible
|
|
122
|
+
};
|
|
123
|
+
return elementInfo;
|
|
124
|
+
}
|
|
125
|
+
if ((0, external_dom_util_js_namespaceObject.isImgElement)(node, currentWindow)) {
|
|
126
|
+
var _node_nodeName;
|
|
127
|
+
const attributes = (0, external_util_js_namespaceObject.getNodeAttributes)(node, currentWindow);
|
|
128
|
+
const nodeHashId = (0, external_util_js_namespaceObject.rpasceneGenerateHash)(node, '', rect);
|
|
129
|
+
const elementInfo = {
|
|
130
|
+
id: nodeHashId,
|
|
131
|
+
indexId: indexId++,
|
|
132
|
+
nodeHashId,
|
|
133
|
+
attributes: {
|
|
134
|
+
...attributes,
|
|
135
|
+
...(null == (_node_nodeName = node.nodeName) ? void 0 : _node_nodeName.toLowerCase()) === 'svg' ? {
|
|
136
|
+
svgContent: 'true'
|
|
137
|
+
} : {},
|
|
138
|
+
nodeType: index_js_namespaceObject.NodeType.IMG,
|
|
139
|
+
htmlTagName: tagNameOfNode(node, currentWindow)
|
|
140
|
+
},
|
|
141
|
+
nodeType: index_js_namespaceObject.NodeType.IMG,
|
|
142
|
+
content: '',
|
|
143
|
+
rect,
|
|
144
|
+
center: [
|
|
145
|
+
Math.round(rect.left + rect.width / 2),
|
|
146
|
+
Math.round(rect.top + rect.height / 2)
|
|
147
|
+
],
|
|
148
|
+
zoom: rect.zoom,
|
|
149
|
+
isVisible: rect.isVisible
|
|
150
|
+
};
|
|
151
|
+
return elementInfo;
|
|
152
|
+
}
|
|
153
|
+
if ((0, external_dom_util_js_namespaceObject.isTextElement)(node, currentWindow)) {
|
|
154
|
+
var _node_textContent;
|
|
155
|
+
const text = null == (_node_textContent = node.textContent) ? void 0 : _node_textContent.trim().replace(/\n+/g, ' ');
|
|
156
|
+
if (!text) return null;
|
|
157
|
+
const attributes = (0, external_util_js_namespaceObject.getNodeAttributes)(node, currentWindow);
|
|
158
|
+
const attributeKeys = Object.keys(attributes);
|
|
159
|
+
if (!text.trim() && 0 === attributeKeys.length) return null;
|
|
160
|
+
const nodeHashId = (0, external_util_js_namespaceObject.rpasceneGenerateHash)(node, text, rect);
|
|
161
|
+
const elementInfo = {
|
|
162
|
+
id: nodeHashId,
|
|
163
|
+
indexId: indexId++,
|
|
164
|
+
nodeHashId,
|
|
165
|
+
nodeType: index_js_namespaceObject.NodeType.TEXT,
|
|
166
|
+
attributes: {
|
|
167
|
+
...attributes,
|
|
168
|
+
nodeType: index_js_namespaceObject.NodeType.TEXT,
|
|
169
|
+
htmlTagName: tagNameOfNode(node, currentWindow)
|
|
170
|
+
},
|
|
171
|
+
center: [
|
|
172
|
+
Math.round(rect.left + rect.width / 2),
|
|
173
|
+
Math.round(rect.top + rect.height / 2)
|
|
174
|
+
],
|
|
175
|
+
content: text,
|
|
176
|
+
rect,
|
|
177
|
+
zoom: rect.zoom,
|
|
178
|
+
isVisible: rect.isVisible
|
|
179
|
+
};
|
|
180
|
+
return elementInfo;
|
|
181
|
+
}
|
|
182
|
+
if ((0, external_dom_util_js_namespaceObject.isAElement)(node, currentWindow)) {
|
|
183
|
+
const attributes = (0, external_util_js_namespaceObject.getNodeAttributes)(node, currentWindow);
|
|
184
|
+
const pseudo = (0, external_util_js_namespaceObject.getPseudoElementContent)(node, currentWindow);
|
|
185
|
+
const content = node.innerText || pseudo.before || pseudo.after || '';
|
|
186
|
+
const nodeHashId = (0, external_util_js_namespaceObject.rpasceneGenerateHash)(node, content, rect);
|
|
187
|
+
const elementInfo = {
|
|
188
|
+
id: nodeHashId,
|
|
189
|
+
indexId: indexId++,
|
|
190
|
+
nodeHashId,
|
|
191
|
+
nodeType: index_js_namespaceObject.NodeType.A,
|
|
192
|
+
attributes: {
|
|
193
|
+
...attributes,
|
|
194
|
+
htmlTagName: tagNameOfNode(node, currentWindow),
|
|
195
|
+
nodeType: index_js_namespaceObject.NodeType.A
|
|
196
|
+
},
|
|
197
|
+
content,
|
|
198
|
+
rect,
|
|
199
|
+
center: [
|
|
200
|
+
Math.round(rect.left + rect.width / 2),
|
|
201
|
+
Math.round(rect.top + rect.height / 2)
|
|
202
|
+
],
|
|
203
|
+
zoom: rect.zoom,
|
|
204
|
+
isVisible: rect.isVisible
|
|
205
|
+
};
|
|
206
|
+
return elementInfo;
|
|
207
|
+
}
|
|
208
|
+
if ((0, external_dom_util_js_namespaceObject.isContainerElement)(node, currentWindow) || isContainer) {
|
|
209
|
+
const attributes = (0, external_util_js_namespaceObject.getNodeAttributes)(node, currentWindow);
|
|
210
|
+
const nodeHashId = (0, external_util_js_namespaceObject.rpasceneGenerateHash)(node, '', rect);
|
|
211
|
+
const elementInfo = {
|
|
212
|
+
id: nodeHashId,
|
|
213
|
+
nodeHashId,
|
|
214
|
+
indexId: indexId++,
|
|
215
|
+
nodeType: index_js_namespaceObject.NodeType.CONTAINER,
|
|
216
|
+
attributes: {
|
|
217
|
+
...attributes,
|
|
218
|
+
nodeType: index_js_namespaceObject.NodeType.CONTAINER,
|
|
219
|
+
htmlTagName: tagNameOfNode(node, currentWindow)
|
|
220
|
+
},
|
|
221
|
+
content: '',
|
|
222
|
+
rect,
|
|
223
|
+
center: [
|
|
224
|
+
Math.round(rect.left + rect.width / 2),
|
|
225
|
+
Math.round(rect.top + rect.height / 2)
|
|
226
|
+
],
|
|
227
|
+
zoom: rect.zoom,
|
|
228
|
+
isVisible: rect.isVisible
|
|
229
|
+
};
|
|
230
|
+
return elementInfo;
|
|
231
|
+
}
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
async function extractTextWithPosition(initNode, debugMode = false) {
|
|
235
|
+
const elementNode = await extractTreeNode(initNode, debugMode);
|
|
236
|
+
const elementInfoArray = [];
|
|
237
|
+
function dfsTopChildren(node) {
|
|
238
|
+
if (node.node) elementInfoArray.push(node.node);
|
|
239
|
+
for(let i = 0; i < node.children.length; i++)dfsTopChildren(node.children[i]);
|
|
240
|
+
}
|
|
241
|
+
dfsTopChildren({
|
|
242
|
+
children: elementNode.children,
|
|
243
|
+
node: elementNode.node
|
|
244
|
+
});
|
|
245
|
+
console.log(elementInfoArray, 'elementInfoArray');
|
|
246
|
+
return elementInfoArray;
|
|
247
|
+
}
|
|
248
|
+
async function extractTreeNodeAsString(initNode, visibleOnly = false, debugMode = false) {
|
|
249
|
+
const elementNode = await extractTreeNode(initNode, debugMode);
|
|
250
|
+
return (0, external_tree_js_namespaceObject.descriptionOfTree)(elementNode, void 0, false, visibleOnly);
|
|
251
|
+
}
|
|
252
|
+
async function extractTreeNode(initNode, debugMode = false, basePoint = {
|
|
253
|
+
left: 0,
|
|
254
|
+
top: 0
|
|
255
|
+
}, baseZoom = 1, containerPaths = []) {
|
|
256
|
+
(0, external_util_js_namespaceObject.setDebugMode)(debugMode);
|
|
257
|
+
indexId = 0;
|
|
258
|
+
let containerPathClone = [
|
|
259
|
+
...containerPaths
|
|
260
|
+
];
|
|
261
|
+
const topDocument = (0, external_util_js_namespaceObject.getTopDocument)();
|
|
262
|
+
const startNode = initNode || topDocument;
|
|
263
|
+
const topChildren = [];
|
|
264
|
+
function dfs(node, currentWindow, currentDocument, baseZoom = 1, basePoint = {
|
|
265
|
+
left: 0,
|
|
266
|
+
top: 0
|
|
267
|
+
}) {
|
|
268
|
+
if (!node) return null;
|
|
269
|
+
if (node.nodeType && 10 === node.nodeType) return null;
|
|
270
|
+
const elementInfo = collectElementInfo(node, currentWindow, currentDocument, baseZoom, basePoint, false);
|
|
271
|
+
if (elementInfo) {
|
|
272
|
+
const allPaths = (0, external_customLocator_js_namespaceObject.getLocators)(node);
|
|
273
|
+
elementInfo.allPaths = allPaths;
|
|
274
|
+
elementInfo.containerPaths = containerPathClone;
|
|
275
|
+
}
|
|
276
|
+
if (node instanceof currentWindow.HTMLIFrameElement) {
|
|
277
|
+
if (node.contentWindow && node.contentWindow) return null;
|
|
278
|
+
}
|
|
279
|
+
const nodeInfo = {
|
|
280
|
+
node: elementInfo,
|
|
281
|
+
children: []
|
|
282
|
+
};
|
|
283
|
+
if ((null == elementInfo ? void 0 : elementInfo.nodeType) === index_js_namespaceObject.NodeType.BUTTON || (null == elementInfo ? void 0 : elementInfo.nodeType) === index_js_namespaceObject.NodeType.IMG || (null == elementInfo ? void 0 : elementInfo.nodeType) === index_js_namespaceObject.NodeType.TEXT || (null == elementInfo ? void 0 : elementInfo.nodeType) === index_js_namespaceObject.NodeType.FORM_ITEM || (null == elementInfo ? void 0 : elementInfo.nodeType) === index_js_namespaceObject.NodeType.CONTAINER) return nodeInfo;
|
|
284
|
+
const rect = (0, external_util_js_namespaceObject.getRect)(node, baseZoom, currentWindow);
|
|
285
|
+
for(let i = 0; i < node.childNodes.length; i++){
|
|
286
|
+
(0, external_util_js_namespaceObject.logger)('will dfs', node.childNodes[i]);
|
|
287
|
+
const childNodeInfo = dfs(node.childNodes[i], currentWindow, currentDocument, rect.zoom, basePoint);
|
|
288
|
+
if (Array.isArray(childNodeInfo)) nodeInfo.children.push(...childNodeInfo);
|
|
289
|
+
else if (childNodeInfo) nodeInfo.children.push(childNodeInfo);
|
|
290
|
+
}
|
|
291
|
+
if (null === nodeInfo.node) {
|
|
292
|
+
if (0 === nodeInfo.children.length) return null;
|
|
293
|
+
return nodeInfo.children;
|
|
294
|
+
}
|
|
295
|
+
return nodeInfo;
|
|
296
|
+
}
|
|
297
|
+
function getCssScale(ele) {
|
|
298
|
+
try {
|
|
299
|
+
const { width, height } = ele.getBoundingClientRect();
|
|
300
|
+
return {
|
|
301
|
+
cssScaleX: Number((width / ele.offsetWidth).toFixed(1)),
|
|
302
|
+
cssScaleY: Number((height / ele.offsetHeight).toFixed(1))
|
|
303
|
+
};
|
|
304
|
+
} catch (error) {
|
|
305
|
+
return {
|
|
306
|
+
cssScaleX: 1,
|
|
307
|
+
cssScaleY: 1
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const rootNodeInfo = dfs(startNode, window, document, baseZoom, basePoint);
|
|
312
|
+
if (Array.isArray(rootNodeInfo)) topChildren.push(...rootNodeInfo);
|
|
313
|
+
else if (rootNodeInfo) topChildren.push(rootNodeInfo);
|
|
314
|
+
if (startNode === topDocument) {
|
|
315
|
+
const iframes = document.querySelectorAll('iframe');
|
|
316
|
+
for(let i = 0; i < iframes.length; i++){
|
|
317
|
+
const iframe = iframes[i];
|
|
318
|
+
const iframeInfo = collectElementInfo(iframe, window, document, 1);
|
|
319
|
+
const baseZoom = getCssScale(iframe).cssScaleX;
|
|
320
|
+
const containerPath = (0, external_customLocator_js_namespaceObject.getContainerPath)(iframe);
|
|
321
|
+
containerPathClone = containerPathClone.concat(containerPath);
|
|
322
|
+
if (iframeInfo) if (iframe.contentDocument && iframe.contentWindow) {
|
|
323
|
+
console.log("iframe\u540C\u57DF");
|
|
324
|
+
const iframeChildren = dfs(iframe.contentDocument.body, iframe.contentWindow, iframe.contentDocument, baseZoom, {
|
|
325
|
+
left: iframeInfo.rect.left,
|
|
326
|
+
top: iframeInfo.rect.top
|
|
327
|
+
});
|
|
328
|
+
if (Array.isArray(iframeChildren)) topChildren.push(...iframeChildren);
|
|
329
|
+
else if (iframeChildren) topChildren.push(iframeChildren);
|
|
330
|
+
} else {
|
|
331
|
+
console.log(iframeInfo, "iframe\u8DE8\u57DF\u4E86");
|
|
332
|
+
const iframeChildren = await (0, external_cs_postmessage_js_namespaceObject.postWindowMessage)(iframe.contentWindow, window, {
|
|
333
|
+
action: 'extractTreeNode',
|
|
334
|
+
data: {
|
|
335
|
+
basePoint: {
|
|
336
|
+
left: iframeInfo.rect.left,
|
|
337
|
+
top: iframeInfo.rect.top
|
|
338
|
+
},
|
|
339
|
+
baseZoom,
|
|
340
|
+
containerPaths: containerPathClone
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
if (Array.isArray(iframeChildren)) topChildren.push(...iframeChildren);
|
|
344
|
+
else if (iframeChildren) topChildren.push(iframeChildren);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
node: null,
|
|
350
|
+
children: topChildren
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom = 1) {
|
|
354
|
+
const selfRect = (0, external_util_js_namespaceObject.elementRect)(node, currentWindow, currentDocument, baseZoom);
|
|
355
|
+
if (!selfRect) return null;
|
|
356
|
+
let minLeft = selfRect.left;
|
|
357
|
+
let minTop = selfRect.top;
|
|
358
|
+
let maxRight = selfRect.left + selfRect.width;
|
|
359
|
+
let maxBottom = selfRect.top + selfRect.height;
|
|
360
|
+
function traverse(child) {
|
|
361
|
+
for(let i = 0; i < child.childNodes.length; i++){
|
|
362
|
+
const sub = child.childNodes[i];
|
|
363
|
+
if (1 === sub.nodeType) {
|
|
364
|
+
const rect = (0, external_util_js_namespaceObject.elementRect)(sub, currentWindow, currentDocument, baseZoom);
|
|
365
|
+
if (rect) {
|
|
366
|
+
minLeft = Math.min(minLeft, rect.left);
|
|
367
|
+
minTop = Math.min(minTop, rect.top);
|
|
368
|
+
maxRight = Math.max(maxRight, rect.left + rect.width);
|
|
369
|
+
maxBottom = Math.max(maxBottom, rect.top + rect.height);
|
|
370
|
+
}
|
|
371
|
+
traverse(sub);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
traverse(node);
|
|
376
|
+
return {
|
|
377
|
+
...selfRect,
|
|
378
|
+
left: minLeft,
|
|
379
|
+
top: minTop,
|
|
380
|
+
width: maxRight - minLeft,
|
|
381
|
+
height: maxBottom - minTop
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
if ('undefined' != typeof window) (0, external_cs_postmessage_js_namespaceObject.onWindowMessage)(window, async ({ action, data }, { source })=>{
|
|
385
|
+
if ('extractTreeNode' === action) try {
|
|
386
|
+
return await extractTreeNode(document.body, false, data.basePoint, data.baseZoom, data.containerPaths);
|
|
387
|
+
} catch (error) {
|
|
388
|
+
return {
|
|
389
|
+
error: 'error message'
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
exports.collectElementInfo = __webpack_exports__.collectElementInfo;
|
|
394
|
+
exports.extractTextWithPosition = __webpack_exports__.extractTextWithPosition;
|
|
395
|
+
exports.extractTreeNode = __webpack_exports__.extractTreeNode;
|
|
396
|
+
exports.extractTreeNodeAsString = __webpack_exports__.extractTreeNodeAsString;
|
|
397
|
+
exports.mergeElementAndChildrenRects = __webpack_exports__.mergeElementAndChildrenRects;
|
|
398
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
399
|
+
"collectElementInfo",
|
|
400
|
+
"extractTextWithPosition",
|
|
401
|
+
"extractTreeNode",
|
|
402
|
+
"extractTreeNodeAsString",
|
|
403
|
+
"mergeElementAndChildrenRects"
|
|
404
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
405
|
+
Object.defineProperty(exports, '__esModule', {
|
|
406
|
+
value: true
|
|
407
|
+
});
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
processImageElementInfo: ()=>processImageElementInfo,
|
|
37
|
+
compositeElementInfoImg: ()=>compositeElementInfoImg
|
|
38
|
+
});
|
|
39
|
+
const external_node_assert_namespaceObject = require("node:assert");
|
|
40
|
+
var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
|
|
41
|
+
const external_get_jimp_js_namespaceObject = require("./get-jimp.js");
|
|
42
|
+
var external_get_jimp_js_default = /*#__PURE__*/ __webpack_require__.n(external_get_jimp_js_namespaceObject);
|
|
43
|
+
const external_index_js_namespaceObject = require("./index.js");
|
|
44
|
+
let cachedFont = null;
|
|
45
|
+
const loadFonts = async ()=>{
|
|
46
|
+
const Jimp = await external_get_jimp_js_default()();
|
|
47
|
+
try {
|
|
48
|
+
const fonts = await Jimp.loadFont(Jimp.FONT_SANS_16_WHITE);
|
|
49
|
+
return fonts;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.warn('Error loading font, will try to load online fonts', error);
|
|
52
|
+
const onlineFonts = 'https://cdn.jsdelivr.net/npm/jimp-compact@0.16.1-2/fonts/open-sans/open-sans-16-white/open-sans-16-white.fnt';
|
|
53
|
+
const fonts = await Jimp.loadFont(onlineFonts);
|
|
54
|
+
return fonts;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const createSvgOverlay = async (elements, imageWidth, imageHeight, boxPadding = 5, borderThickness = 2, prompt)=>{
|
|
58
|
+
const Jimp = await external_get_jimp_js_default()();
|
|
59
|
+
const image = new Jimp(imageWidth, imageHeight, 0x00000000);
|
|
60
|
+
const colors = [
|
|
61
|
+
{
|
|
62
|
+
rect: 0xc62300ff,
|
|
63
|
+
text: 0xffffffff
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
rect: 0x0000ffff,
|
|
67
|
+
text: 0xffffffff
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
rect: 0x8b4513ff,
|
|
71
|
+
text: 0xffffffff
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
rect: 0x3e7b27ff,
|
|
75
|
+
text: 0xffffffff
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
rect: 0x500073ff,
|
|
79
|
+
text: 0xffffffff
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
if (prompt) try {
|
|
83
|
+
cachedFont = cachedFont || await loadFonts();
|
|
84
|
+
const promptPadding = 10;
|
|
85
|
+
const promptMargin = 20;
|
|
86
|
+
const promptHeight = 30;
|
|
87
|
+
const promptY = imageHeight - promptHeight - promptMargin;
|
|
88
|
+
image.scan(0, promptY, imageWidth, promptHeight, (x, y, idx)=>{
|
|
89
|
+
image.bitmap.data[idx + 0] = 0x00;
|
|
90
|
+
image.bitmap.data[idx + 1] = 0x00;
|
|
91
|
+
image.bitmap.data[idx + 2] = 0x00;
|
|
92
|
+
image.bitmap.data[idx + 3] = 0xcc;
|
|
93
|
+
});
|
|
94
|
+
image.print(cachedFont, promptPadding, promptY, {
|
|
95
|
+
text: prompt,
|
|
96
|
+
alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT,
|
|
97
|
+
alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE
|
|
98
|
+
}, imageWidth - 2 * promptPadding, promptHeight);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error('Error drawing prompt text', error);
|
|
101
|
+
}
|
|
102
|
+
for(let index = 0; index < elements.length; index++){
|
|
103
|
+
const element = elements[index];
|
|
104
|
+
const color = colors[index % colors.length];
|
|
105
|
+
const paddedLeft = Math.max(0, element.rect.left - boxPadding);
|
|
106
|
+
const paddedTop = Math.max(0, element.rect.top - boxPadding);
|
|
107
|
+
const paddedWidth = Math.min(imageWidth - paddedLeft, element.rect.width + 2 * boxPadding);
|
|
108
|
+
const paddedHeight = Math.min(imageHeight - paddedTop, element.rect.height + 2 * boxPadding);
|
|
109
|
+
const paddedRect = {
|
|
110
|
+
left: paddedLeft,
|
|
111
|
+
top: paddedTop,
|
|
112
|
+
width: paddedWidth,
|
|
113
|
+
height: paddedHeight
|
|
114
|
+
};
|
|
115
|
+
image.scan(paddedRect.left, paddedRect.top, paddedRect.width, paddedRect.height, (x, y, idx)=>{
|
|
116
|
+
if (x >= paddedRect.left && x < paddedRect.left + borderThickness || x <= paddedRect.left + paddedRect.width - 1 && x > paddedRect.left + paddedRect.width - borderThickness || y >= paddedRect.top && y < paddedRect.top + borderThickness || y <= paddedRect.top + paddedRect.height - 1 && y > paddedRect.top + paddedRect.height - borderThickness) {
|
|
117
|
+
image.bitmap.data[idx + 0] = color.rect >> 24 & 0xff;
|
|
118
|
+
image.bitmap.data[idx + 1] = color.rect >> 16 & 0xff;
|
|
119
|
+
image.bitmap.data[idx + 2] = color.rect >> 8 & 0xff;
|
|
120
|
+
image.bitmap.data[idx + 3] = 0xff & color.rect;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const indexId = element.indexId;
|
|
124
|
+
if ('number' != typeof indexId) continue;
|
|
125
|
+
const textWidth = 8 * indexId.toString().length;
|
|
126
|
+
const textHeight = 12;
|
|
127
|
+
const rectWidth = textWidth + 5;
|
|
128
|
+
const rectHeight = textHeight + 4;
|
|
129
|
+
let rectX = paddedRect.left - rectWidth;
|
|
130
|
+
let rectY = paddedRect.top + paddedRect.height / 2 - textHeight / 2 - 2;
|
|
131
|
+
const checkOverlap = (x, y)=>elements.slice(0, index).some((otherElement)=>x < otherElement.rect.left + otherElement.rect.width && x + rectWidth > otherElement.rect.left && y < otherElement.rect.top + otherElement.rect.height && y + rectHeight > otherElement.rect.top);
|
|
132
|
+
const isWithinBounds = (x, y)=>x >= 0 && x + rectWidth <= imageWidth && y >= 0 && y + rectHeight <= imageHeight;
|
|
133
|
+
if (checkOverlap(rectX, rectY) || !isWithinBounds(rectX, rectY)) if (!checkOverlap(paddedRect.left, paddedRect.top - rectHeight - 2) && isWithinBounds(paddedRect.left, paddedRect.top - rectHeight - 2)) {
|
|
134
|
+
rectX = paddedRect.left;
|
|
135
|
+
rectY = paddedRect.top - rectHeight - 2;
|
|
136
|
+
} else if (!checkOverlap(paddedRect.left, paddedRect.top + paddedRect.height + 2) && isWithinBounds(paddedRect.left, paddedRect.top + paddedRect.height + 2)) {
|
|
137
|
+
rectX = paddedRect.left;
|
|
138
|
+
rectY = paddedRect.top + paddedRect.height + 2;
|
|
139
|
+
} else if (!checkOverlap(paddedRect.left + paddedRect.width + 2, paddedRect.top) && isWithinBounds(paddedRect.left + paddedRect.width + 2, paddedRect.top)) {
|
|
140
|
+
rectX = paddedRect.left + paddedRect.width + 2;
|
|
141
|
+
rectY = paddedRect.top;
|
|
142
|
+
} else {
|
|
143
|
+
rectX = paddedRect.left;
|
|
144
|
+
rectY = paddedRect.top + 2;
|
|
145
|
+
}
|
|
146
|
+
image.scan(rectX, rectY, rectWidth, rectHeight, (x, y, idx)=>{
|
|
147
|
+
image.bitmap.data[idx + 0] = color.rect >> 24 & 0xff;
|
|
148
|
+
image.bitmap.data[idx + 1] = color.rect >> 16 & 0xff;
|
|
149
|
+
image.bitmap.data[idx + 2] = color.rect >> 8 & 0xff;
|
|
150
|
+
image.bitmap.data[idx + 3] = 0xff & color.rect;
|
|
151
|
+
});
|
|
152
|
+
try {
|
|
153
|
+
cachedFont = cachedFont || await loadFonts();
|
|
154
|
+
} catch (error) {
|
|
155
|
+
console.error('Error loading font', error);
|
|
156
|
+
}
|
|
157
|
+
image.print(cachedFont, rectX, rectY, {
|
|
158
|
+
text: indexId.toString(),
|
|
159
|
+
alignmentX: Jimp.HORIZONTAL_ALIGN_CENTER,
|
|
160
|
+
alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE
|
|
161
|
+
}, rectWidth, rectHeight);
|
|
162
|
+
}
|
|
163
|
+
return image;
|
|
164
|
+
};
|
|
165
|
+
const compositeElementInfoImg = async (options)=>{
|
|
166
|
+
external_node_assert_default()(options.inputImgBase64, 'inputImgBase64 is required');
|
|
167
|
+
let width = 0;
|
|
168
|
+
let height = 0;
|
|
169
|
+
let jimpImage;
|
|
170
|
+
const Jimp = await external_get_jimp_js_default()();
|
|
171
|
+
if (options.size) {
|
|
172
|
+
width = options.size.width;
|
|
173
|
+
height = options.size.height;
|
|
174
|
+
}
|
|
175
|
+
if (width && height) {
|
|
176
|
+
const imageBuffer = await (0, external_index_js_namespaceObject.bufferFromBase64)(options.inputImgBase64);
|
|
177
|
+
jimpImage = await Jimp.read(imageBuffer);
|
|
178
|
+
const imageBitmap = jimpImage.bitmap;
|
|
179
|
+
if (imageBitmap.width !== width || imageBitmap.height !== height) jimpImage.resize(width, height, Jimp.RESIZE_NEAREST_NEIGHBOR);
|
|
180
|
+
} else {
|
|
181
|
+
const info = await (0, external_index_js_namespaceObject.imageInfoOfBase64)(options.inputImgBase64);
|
|
182
|
+
width = info.width;
|
|
183
|
+
height = info.height;
|
|
184
|
+
jimpImage = info.jimpImage;
|
|
185
|
+
}
|
|
186
|
+
if (!width || !height) throw Error('Image processing failed because width or height is undefined');
|
|
187
|
+
const { elementsPositionInfo, prompt } = options;
|
|
188
|
+
const result = await Promise.resolve(jimpImage).then(async (image)=>{
|
|
189
|
+
const svgOverlay = await createSvgOverlay(elementsPositionInfo, width, height, options.annotationPadding, options.borderThickness, prompt);
|
|
190
|
+
const svgImage = await Jimp.read(svgOverlay);
|
|
191
|
+
const compositeImage = await image.composite(svgImage, 0, 0, {
|
|
192
|
+
mode: Jimp.BLEND_SOURCE_OVER,
|
|
193
|
+
opacitySource: 1,
|
|
194
|
+
opacityDest: 1
|
|
195
|
+
});
|
|
196
|
+
return compositeImage;
|
|
197
|
+
}).then(async (compositeImage)=>{
|
|
198
|
+
compositeImage.quality(90);
|
|
199
|
+
const base64 = await compositeImage.getBase64Async(Jimp.MIME_JPEG);
|
|
200
|
+
return base64;
|
|
201
|
+
}).catch((error)=>{
|
|
202
|
+
throw error;
|
|
203
|
+
});
|
|
204
|
+
return result;
|
|
205
|
+
};
|
|
206
|
+
const processImageElementInfo = async (options)=>{
|
|
207
|
+
const base64Image = options.inputImgBase64.split(';base64,').pop();
|
|
208
|
+
external_node_assert_default()(base64Image, 'base64Image is undefined');
|
|
209
|
+
const [compositeElementInfoImgBase64, compositeElementInfoImgWithoutTextBase64] = await Promise.all([
|
|
210
|
+
compositeElementInfoImg({
|
|
211
|
+
inputImgBase64: options.inputImgBase64,
|
|
212
|
+
elementsPositionInfo: options.elementsPositionInfo
|
|
213
|
+
}),
|
|
214
|
+
compositeElementInfoImg({
|
|
215
|
+
inputImgBase64: options.inputImgBase64,
|
|
216
|
+
elementsPositionInfo: options.elementsPositionInfoWithoutText
|
|
217
|
+
})
|
|
218
|
+
]);
|
|
219
|
+
return {
|
|
220
|
+
compositeElementInfoImgBase64,
|
|
221
|
+
compositeElementInfoImgWithoutTextBase64
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
exports.compositeElementInfoImg = __webpack_exports__.compositeElementInfoImg;
|
|
225
|
+
exports.processImageElementInfo = __webpack_exports__.processImageElementInfo;
|
|
226
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
227
|
+
"compositeElementInfoImg",
|
|
228
|
+
"processImageElementInfo"
|
|
229
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
230
|
+
Object.defineProperty(exports, '__esModule', {
|
|
231
|
+
value: true
|
|
232
|
+
});
|