@esri/solutions-components 0.10.35 → 0.10.37
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/dist/cjs/basemap-gallery_7.cjs.entry.js +1 -0
- package/dist/cjs/calcite-action-pad_2.cjs.entry.js +2 -2
- package/dist/cjs/calcite-alert_5.cjs.entry.js +3 -3
- package/dist/cjs/calcite-block_5.cjs.entry.js +2 -2
- package/dist/cjs/card-manager_3.cjs.entry.js +2 -2
- package/dist/cjs/{constants-0a4fc296.js → constants-51cf394f.js} +57 -1
- package/dist/cjs/crowdsource-manager.cjs.entry.js +25 -29
- package/dist/cjs/{downloadUtils-20637f89.js → downloadUtils-76bc7e30.js} +6 -5
- package/dist/cjs/feature-list.cjs.entry.js +3 -3
- package/dist/cjs/{helpers-415179ad.js → helpers-afcac967.js} +1 -1
- package/dist/cjs/{index.es-a242cb45.js → index.es-8336efed.js} +2 -2
- package/dist/cjs/instant-apps-app-guide.cjs.entry.js +26 -13
- package/dist/cjs/instant-apps-export.cjs.entry.js +1086 -59
- package/dist/cjs/instant-apps-interactive-legend-classic.cjs.entry.js +8 -4
- package/dist/cjs/instant-apps-interactive-legend-count_2.cjs.entry.js +10 -5
- package/dist/cjs/instant-apps-interactive-legend-group-legend-element-caption.cjs.entry.js +1 -1
- package/dist/cjs/instant-apps-interactive-legend-group-legend-element_5.cjs.entry.js +52 -12
- package/dist/cjs/instant-apps-interactive-legend.cjs.entry.js +9 -3
- package/dist/cjs/instant-apps-landing-page.cjs.entry.js +19 -13
- package/dist/cjs/instant-apps-language-switcher.cjs.entry.js +3 -2
- package/dist/cjs/instant-apps-language-translator.cjs.entry.js +1 -1
- package/dist/cjs/instant-apps-measurement.cjs.entry.js +2 -2
- package/dist/cjs/instant-apps-popover.cjs.entry.js +1 -1
- package/dist/cjs/instant-apps-scoreboard.cjs.entry.js +1 -1
- package/dist/cjs/instant-apps-sign-in.cjs.entry.js +13 -9
- package/dist/cjs/instant-apps-splash.cjs.entry.js +1 -1
- package/dist/cjs/instant-apps-time-filter.cjs.entry.js +11 -9
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/map-select-tools_3.cjs.entry.js +2 -2
- package/dist/cjs/{popupUtils-d477705b.js → popupUtils-bc762034.js} +1 -1
- package/dist/cjs/public-notification.cjs.entry.js +2 -2
- package/dist/cjs/solution-item-accordion.cjs.entry.js +7 -3
- package/dist/cjs/solutions-components.cjs.js +1 -1
- package/dist/collection/components/crowdsource-manager/crowdsource-manager.js +27 -29
- package/dist/collection/components/map-legend/map-legend.js +1 -0
- package/dist/collection/components/solution-item-accordion/solution-item-accordion.js +7 -3
- package/dist/collection/demos/solution-item-accordion.html +32 -0
- package/dist/collection/utils/downloadUtils.js +5 -3
- package/dist/collection/utils/downloadUtils.ts +6 -3
- package/dist/collection/utils/test/downloadUtils.spec.tsx +10 -12
- package/dist/components/crowdsource-manager.js +26 -29
- package/dist/components/downloadUtils.js +5 -4
- package/dist/components/instant-apps-app-guide.js +28 -14
- package/dist/components/instant-apps-export.js +1119 -76
- package/dist/components/instant-apps-interactive-legend-classic2.js +8 -4
- package/dist/components/instant-apps-interactive-legend-count2.js +6 -3
- package/dist/components/instant-apps-interactive-legend-layer-element-caption2.js +5 -2
- package/dist/components/instant-apps-interactive-legend-legend-element-caption2.js +52 -12
- package/dist/components/instant-apps-interactive-legend.js +13 -4
- package/dist/components/instant-apps-landing-page.js +19 -13
- package/dist/components/instant-apps-language-switcher.js +3 -1
- package/dist/components/instant-apps-language-translator2.js +57 -1
- package/dist/components/instant-apps-measurement-tool2.js +2 -2
- package/dist/components/instant-apps-measurement.js +2 -2
- package/dist/components/instant-apps-popover.js +1 -1
- package/dist/components/instant-apps-scoreboard.js +1 -1
- package/dist/components/instant-apps-sign-in2.js +14 -9
- package/dist/components/instant-apps-social-share2.js +2 -2
- package/dist/components/instant-apps-splash.js +1 -1
- package/dist/components/instant-apps-time-filter.js +11 -9
- package/dist/components/map-legend2.js +1 -0
- package/dist/components/solution-item-accordion.js +7 -3
- package/dist/components/store.js +1 -1
- package/dist/esm/basemap-gallery_7.entry.js +1 -0
- package/dist/esm/calcite-action-pad_2.entry.js +2 -2
- package/dist/esm/calcite-alert_5.entry.js +3 -3
- package/dist/esm/calcite-block_5.entry.js +2 -2
- package/dist/esm/card-manager_3.entry.js +2 -2
- package/dist/esm/{constants-045d6a1b.js → constants-886c7c2c.js} +57 -1
- package/dist/esm/crowdsource-manager.entry.js +25 -29
- package/dist/esm/{downloadUtils-e266e98d.js → downloadUtils-bc7a4ba1.js} +6 -5
- package/dist/esm/feature-list.entry.js +3 -3
- package/dist/esm/{helpers-f9bf9c0b.js → helpers-91087955.js} +1 -1
- package/dist/esm/{index.es-c5f258e2.js → index.es-0d189a34.js} +2 -2
- package/dist/esm/instant-apps-app-guide.entry.js +26 -13
- package/dist/esm/instant-apps-export.entry.js +1086 -59
- package/dist/esm/instant-apps-interactive-legend-classic.entry.js +8 -4
- package/dist/esm/instant-apps-interactive-legend-count_2.entry.js +10 -5
- package/dist/esm/instant-apps-interactive-legend-group-legend-element-caption.entry.js +1 -1
- package/dist/esm/instant-apps-interactive-legend-group-legend-element_5.entry.js +52 -12
- package/dist/esm/instant-apps-interactive-legend.entry.js +9 -3
- package/dist/esm/instant-apps-landing-page.entry.js +19 -13
- package/dist/esm/instant-apps-language-switcher.entry.js +3 -2
- package/dist/esm/instant-apps-language-translator.entry.js +1 -1
- package/dist/esm/instant-apps-measurement.entry.js +2 -2
- package/dist/esm/instant-apps-popover.entry.js +1 -1
- package/dist/esm/instant-apps-scoreboard.entry.js +1 -1
- package/dist/esm/instant-apps-sign-in.entry.js +13 -9
- package/dist/esm/instant-apps-splash.entry.js +1 -1
- package/dist/esm/instant-apps-time-filter.entry.js +11 -9
- package/dist/esm/loader.js +1 -1
- package/dist/esm/map-select-tools_3.entry.js +2 -2
- package/dist/esm/{popupUtils-4570096e.js → popupUtils-03dc398a.js} +1 -1
- package/dist/esm/public-notification.entry.js +2 -2
- package/dist/esm/solution-item-accordion.entry.js +7 -3
- package/dist/esm/solutions-components.js +1 -1
- package/dist/node_modules/@esri/instant-apps-components/dist/collection/components/instant-apps-app-guide/instant-apps-app-guide.css +0 -5
- package/dist/node_modules/@esri/instant-apps-components/dist/collection/components/instant-apps-export/instant-apps-export.css +4 -0
- package/dist/node_modules/@esri/instant-apps-components/dist/collection/components/instant-apps-interactive-legend/instant-apps-interactive-legend-classic/instant-apps-interactive-legend-classic.css +14 -0
- package/dist/node_modules/@esri/instant-apps-components/dist/collection/components/instant-apps-interactive-legend/instant-apps-interactive-legend-count/instant-apps-interactive-legend-count.css +9 -0
- package/dist/node_modules/@esri/instant-apps-components/dist/collection/components/instant-apps-interactive-legend/instant-apps-interactive-legend-layer-element-caption/instant-apps-interactive-legend-layer-element-caption.css +5 -3
- package/dist/node_modules/@esri/instant-apps-components/dist/collection/components/instant-apps-interactive-legend/instant-apps-interactive-legend-legend-element-caption/instant-apps-interactive-legend-legend-element-caption.css +29 -0
- package/dist/node_modules/@esri/instant-apps-components/dist/collection/components/instant-apps-landing-page/instant-apps-landing-page.css +8 -0
- package/dist/node_modules/@esri/instant-apps-components/dist/collection/components/instant-apps-sign-in/instant-apps-sign-in.css +22 -0
- package/dist/solutions-components/demos/solution-item-accordion.html +32 -0
- package/dist/solutions-components/{p-cb3199f9.entry.js → p-04ab956c.entry.js} +1 -1
- package/dist/solutions-components/p-1e14b3d0.entry.js +6 -0
- package/dist/solutions-components/p-2542d5c9.entry.js +6 -0
- package/dist/solutions-components/{p-70ecc979.entry.js → p-374ddead.entry.js} +1 -1
- package/dist/solutions-components/{p-146acd9a.entry.js → p-3fc18283.entry.js} +1 -1
- package/dist/solutions-components/p-43699470.entry.js +6 -0
- package/dist/solutions-components/p-5585dcd3.entry.js +6 -0
- package/dist/solutions-components/{p-3a513c67.entry.js → p-5b3c0418.entry.js} +1 -1
- package/dist/solutions-components/{p-f7e7b830.entry.js → p-6438d1ea.entry.js} +1 -1
- package/dist/solutions-components/{p-a568af9f.js → p-6f606cdb.js} +1 -1
- package/dist/solutions-components/p-720de4db.entry.js +6 -0
- package/dist/solutions-components/p-750b3277.entry.js +6 -0
- package/dist/solutions-components/p-8779ee41.entry.js +6 -0
- package/dist/solutions-components/p-90fc786f.entry.js +6 -0
- package/dist/solutions-components/p-97fe6ec5.entry.js +6 -0
- package/dist/solutions-components/{p-43165ebd.entry.js → p-9c170b30.entry.js} +1 -1
- package/dist/solutions-components/{p-b4c49411.entry.js → p-9c4fef09.entry.js} +1 -1
- package/dist/solutions-components/p-a5b751e2.entry.js +6 -0
- package/dist/solutions-components/{p-89046451.entry.js → p-aac0c89c.entry.js} +1 -1
- package/dist/solutions-components/p-af573e0d.js +6 -0
- package/dist/solutions-components/p-bb8b1ee2.entry.js +6 -0
- package/dist/solutions-components/{p-b79f296d.entry.js → p-c48be45f.entry.js} +2 -2
- package/dist/solutions-components/p-ca3cbd29.entry.js +6 -0
- package/dist/solutions-components/p-cd482a33.js +21 -0
- package/dist/solutions-components/p-ceb1030b.js +6 -0
- package/dist/solutions-components/{p-b86b2664.entry.js → p-d2612c30.entry.js} +1 -1
- package/dist/solutions-components/{p-29047e77.entry.js → p-e1391389.entry.js} +1 -1
- package/dist/solutions-components/{p-588adf13.entry.js → p-e345f9c4.entry.js} +1 -1
- package/dist/solutions-components/p-f3b71784.entry.js +6 -0
- package/dist/solutions-components/{p-759d0beb.entry.js → p-f728af86.entry.js} +1 -1
- package/dist/solutions-components/{p-46c8015c.js → p-ff9e28d1.js} +30 -30
- package/dist/solutions-components/solutions-components.esm.js +1 -1
- package/dist/solutions-components/utils/downloadUtils.ts +6 -3
- package/dist/solutions-components/utils/test/downloadUtils.spec.tsx +10 -12
- package/dist/types/components/crowdsource-manager/crowdsource-manager.d.ts +4 -7
- package/package.json +8 -7
- package/dist/solutions-components/p-07a194e6.entry.js +0 -6
- package/dist/solutions-components/p-14d78748.entry.js +0 -6
- package/dist/solutions-components/p-2360802a.js +0 -21
- package/dist/solutions-components/p-24e3f09f.entry.js +0 -6
- package/dist/solutions-components/p-3a33ef72.entry.js +0 -6
- package/dist/solutions-components/p-402301cb.js +0 -6
- package/dist/solutions-components/p-41a6f03d.entry.js +0 -6
- package/dist/solutions-components/p-4db86c5e.entry.js +0 -6
- package/dist/solutions-components/p-5eb9a413.entry.js +0 -6
- package/dist/solutions-components/p-750f234e.entry.js +0 -6
- package/dist/solutions-components/p-7e97d4d6.entry.js +0 -6
- package/dist/solutions-components/p-7eb5d31a.js +0 -6
- package/dist/solutions-components/p-90d2aadc.entry.js +0 -6
- package/dist/solutions-components/p-b78a4ce7.entry.js +0 -6
- package/dist/solutions-components/p-ecf642c2.entry.js +0 -6
- package/dist/solutions-components/p-efb4cb43.entry.js +0 -6
@@ -15,6 +15,838 @@ require('./esri-loader-08dc41bd.js');
|
|
15
15
|
require('./_commonjsHelpers-baf43783.js');
|
16
16
|
require('./languageUtil-a3e1eafd.js');
|
17
17
|
|
18
|
+
function resolveUrl(url, baseUrl) {
|
19
|
+
// url is absolute already
|
20
|
+
if (url.match(/^[a-z]+:\/\//i)) {
|
21
|
+
return url;
|
22
|
+
}
|
23
|
+
// url is absolute already, without protocol
|
24
|
+
if (url.match(/^\/\//)) {
|
25
|
+
return window.location.protocol + url;
|
26
|
+
}
|
27
|
+
// dataURI, mailto:, tel:, etc.
|
28
|
+
if (url.match(/^[a-z]+:/i)) {
|
29
|
+
return url;
|
30
|
+
}
|
31
|
+
const doc = document.implementation.createHTMLDocument();
|
32
|
+
const base = doc.createElement('base');
|
33
|
+
const a = doc.createElement('a');
|
34
|
+
doc.head.appendChild(base);
|
35
|
+
doc.body.appendChild(a);
|
36
|
+
if (baseUrl) {
|
37
|
+
base.href = baseUrl;
|
38
|
+
}
|
39
|
+
a.href = url;
|
40
|
+
return a.href;
|
41
|
+
}
|
42
|
+
const uuid = (() => {
|
43
|
+
// generate uuid for className of pseudo elements.
|
44
|
+
// We should not use GUIDs, otherwise pseudo elements sometimes cannot be captured.
|
45
|
+
let counter = 0;
|
46
|
+
// ref: http://stackoverflow.com/a/6248722/2519373
|
47
|
+
const random = () =>
|
48
|
+
// eslint-disable-next-line no-bitwise
|
49
|
+
`0000${((Math.random() * 36 ** 4) << 0).toString(36)}`.slice(-4);
|
50
|
+
return () => {
|
51
|
+
counter += 1;
|
52
|
+
return `u${random()}${counter}`;
|
53
|
+
};
|
54
|
+
})();
|
55
|
+
function toArray(arrayLike) {
|
56
|
+
const arr = [];
|
57
|
+
for (let i = 0, l = arrayLike.length; i < l; i++) {
|
58
|
+
arr.push(arrayLike[i]);
|
59
|
+
}
|
60
|
+
return arr;
|
61
|
+
}
|
62
|
+
function px(node, styleProperty) {
|
63
|
+
const win = node.ownerDocument.defaultView || window;
|
64
|
+
const val = win.getComputedStyle(node).getPropertyValue(styleProperty);
|
65
|
+
return val ? parseFloat(val.replace('px', '')) : 0;
|
66
|
+
}
|
67
|
+
function getNodeWidth(node) {
|
68
|
+
const leftBorder = px(node, 'border-left-width');
|
69
|
+
const rightBorder = px(node, 'border-right-width');
|
70
|
+
return node.clientWidth + leftBorder + rightBorder;
|
71
|
+
}
|
72
|
+
function getNodeHeight(node) {
|
73
|
+
const topBorder = px(node, 'border-top-width');
|
74
|
+
const bottomBorder = px(node, 'border-bottom-width');
|
75
|
+
return node.clientHeight + topBorder + bottomBorder;
|
76
|
+
}
|
77
|
+
function getImageSize(targetNode, options = {}) {
|
78
|
+
const width = options.width || getNodeWidth(targetNode);
|
79
|
+
const height = options.height || getNodeHeight(targetNode);
|
80
|
+
return { width, height };
|
81
|
+
}
|
82
|
+
function getPixelRatio() {
|
83
|
+
let ratio;
|
84
|
+
let FINAL_PROCESS;
|
85
|
+
try {
|
86
|
+
FINAL_PROCESS = process;
|
87
|
+
}
|
88
|
+
catch (e) {
|
89
|
+
// pass
|
90
|
+
}
|
91
|
+
const val = FINAL_PROCESS && FINAL_PROCESS.env
|
92
|
+
? FINAL_PROCESS.env.devicePixelRatio
|
93
|
+
: null;
|
94
|
+
if (val) {
|
95
|
+
ratio = parseInt(val, 10);
|
96
|
+
if (Number.isNaN(ratio)) {
|
97
|
+
ratio = 1;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
return ratio || window.devicePixelRatio || 1;
|
101
|
+
}
|
102
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas#maximum_canvas_size
|
103
|
+
const canvasDimensionLimit = 16384;
|
104
|
+
function checkCanvasDimensions(canvas) {
|
105
|
+
if (canvas.width > canvasDimensionLimit ||
|
106
|
+
canvas.height > canvasDimensionLimit) {
|
107
|
+
if (canvas.width > canvasDimensionLimit &&
|
108
|
+
canvas.height > canvasDimensionLimit) {
|
109
|
+
if (canvas.width > canvas.height) {
|
110
|
+
canvas.height *= canvasDimensionLimit / canvas.width;
|
111
|
+
canvas.width = canvasDimensionLimit;
|
112
|
+
}
|
113
|
+
else {
|
114
|
+
canvas.width *= canvasDimensionLimit / canvas.height;
|
115
|
+
canvas.height = canvasDimensionLimit;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
else if (canvas.width > canvasDimensionLimit) {
|
119
|
+
canvas.height *= canvasDimensionLimit / canvas.width;
|
120
|
+
canvas.width = canvasDimensionLimit;
|
121
|
+
}
|
122
|
+
else {
|
123
|
+
canvas.width *= canvasDimensionLimit / canvas.height;
|
124
|
+
canvas.height = canvasDimensionLimit;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
function createImage(url) {
|
129
|
+
return new Promise((resolve, reject) => {
|
130
|
+
const img = new Image();
|
131
|
+
img.decode = () => resolve(img);
|
132
|
+
img.onload = () => resolve(img);
|
133
|
+
img.onerror = reject;
|
134
|
+
img.crossOrigin = 'anonymous';
|
135
|
+
img.decoding = 'async';
|
136
|
+
img.src = url;
|
137
|
+
});
|
138
|
+
}
|
139
|
+
async function svgToDataURL(svg) {
|
140
|
+
return Promise.resolve()
|
141
|
+
.then(() => new XMLSerializer().serializeToString(svg))
|
142
|
+
.then(encodeURIComponent)
|
143
|
+
.then((html) => `data:image/svg+xml;charset=utf-8,${html}`);
|
144
|
+
}
|
145
|
+
async function nodeToDataURL(node, width, height) {
|
146
|
+
const xmlns = 'http://www.w3.org/2000/svg';
|
147
|
+
const svg = document.createElementNS(xmlns, 'svg');
|
148
|
+
const foreignObject = document.createElementNS(xmlns, 'foreignObject');
|
149
|
+
svg.setAttribute('width', `${width}`);
|
150
|
+
svg.setAttribute('height', `${height}`);
|
151
|
+
svg.setAttribute('viewBox', `0 0 ${width} ${height}`);
|
152
|
+
foreignObject.setAttribute('width', '100%');
|
153
|
+
foreignObject.setAttribute('height', '100%');
|
154
|
+
foreignObject.setAttribute('x', '0');
|
155
|
+
foreignObject.setAttribute('y', '0');
|
156
|
+
foreignObject.setAttribute('externalResourcesRequired', 'true');
|
157
|
+
svg.appendChild(foreignObject);
|
158
|
+
foreignObject.appendChild(node);
|
159
|
+
return svgToDataURL(svg);
|
160
|
+
}
|
161
|
+
const isInstanceOfElement = (node, instance) => {
|
162
|
+
if (node instanceof instance)
|
163
|
+
return true;
|
164
|
+
const nodePrototype = Object.getPrototypeOf(node);
|
165
|
+
if (nodePrototype === null)
|
166
|
+
return false;
|
167
|
+
return (nodePrototype.constructor.name === instance.name ||
|
168
|
+
isInstanceOfElement(nodePrototype, instance));
|
169
|
+
};
|
170
|
+
|
171
|
+
function formatCSSText(style) {
|
172
|
+
const content = style.getPropertyValue('content');
|
173
|
+
return `${style.cssText} content: '${content.replace(/'|"/g, '')}';`;
|
174
|
+
}
|
175
|
+
function formatCSSProperties(style) {
|
176
|
+
return toArray(style)
|
177
|
+
.map((name) => {
|
178
|
+
const value = style.getPropertyValue(name);
|
179
|
+
const priority = style.getPropertyPriority(name);
|
180
|
+
return `${name}: ${value}${priority ? ' !important' : ''};`;
|
181
|
+
})
|
182
|
+
.join(' ');
|
183
|
+
}
|
184
|
+
function getPseudoElementStyle(className, pseudo, style) {
|
185
|
+
const selector = `.${className}:${pseudo}`;
|
186
|
+
const cssText = style.cssText
|
187
|
+
? formatCSSText(style)
|
188
|
+
: formatCSSProperties(style);
|
189
|
+
return document.createTextNode(`${selector}{${cssText}}`);
|
190
|
+
}
|
191
|
+
function clonePseudoElement(nativeNode, clonedNode, pseudo) {
|
192
|
+
const style = window.getComputedStyle(nativeNode, pseudo);
|
193
|
+
const content = style.getPropertyValue('content');
|
194
|
+
if (content === '' || content === 'none') {
|
195
|
+
return;
|
196
|
+
}
|
197
|
+
const className = uuid();
|
198
|
+
try {
|
199
|
+
clonedNode.className = `${clonedNode.className} ${className}`;
|
200
|
+
}
|
201
|
+
catch (err) {
|
202
|
+
return;
|
203
|
+
}
|
204
|
+
const styleElement = document.createElement('style');
|
205
|
+
styleElement.appendChild(getPseudoElementStyle(className, pseudo, style));
|
206
|
+
clonedNode.appendChild(styleElement);
|
207
|
+
}
|
208
|
+
function clonePseudoElements(nativeNode, clonedNode) {
|
209
|
+
clonePseudoElement(nativeNode, clonedNode, ':before');
|
210
|
+
clonePseudoElement(nativeNode, clonedNode, ':after');
|
211
|
+
}
|
212
|
+
|
213
|
+
const WOFF = 'application/font-woff';
|
214
|
+
const JPEG = 'image/jpeg';
|
215
|
+
const mimes = {
|
216
|
+
woff: WOFF,
|
217
|
+
woff2: WOFF,
|
218
|
+
ttf: 'application/font-truetype',
|
219
|
+
eot: 'application/vnd.ms-fontobject',
|
220
|
+
png: 'image/png',
|
221
|
+
jpg: JPEG,
|
222
|
+
jpeg: JPEG,
|
223
|
+
gif: 'image/gif',
|
224
|
+
tiff: 'image/tiff',
|
225
|
+
svg: 'image/svg+xml',
|
226
|
+
webp: 'image/webp',
|
227
|
+
};
|
228
|
+
function getExtension(url) {
|
229
|
+
const match = /\.([^./]*?)$/g.exec(url);
|
230
|
+
return match ? match[1] : '';
|
231
|
+
}
|
232
|
+
function getMimeType(url) {
|
233
|
+
const extension = getExtension(url).toLowerCase();
|
234
|
+
return mimes[extension] || '';
|
235
|
+
}
|
236
|
+
|
237
|
+
function getContentFromDataUrl(dataURL) {
|
238
|
+
return dataURL.split(/,/)[1];
|
239
|
+
}
|
240
|
+
function isDataUrl(url) {
|
241
|
+
return url.search(/^(data:)/) !== -1;
|
242
|
+
}
|
243
|
+
function makeDataUrl(content, mimeType) {
|
244
|
+
return `data:${mimeType};base64,${content}`;
|
245
|
+
}
|
246
|
+
async function fetchAsDataURL(url, init, process) {
|
247
|
+
const res = await fetch(url, init);
|
248
|
+
if (res.status === 404) {
|
249
|
+
throw new Error(`Resource "${res.url}" not found`);
|
250
|
+
}
|
251
|
+
const blob = await res.blob();
|
252
|
+
return new Promise((resolve, reject) => {
|
253
|
+
const reader = new FileReader();
|
254
|
+
reader.onerror = reject;
|
255
|
+
reader.onloadend = () => {
|
256
|
+
try {
|
257
|
+
resolve(process({ res, result: reader.result }));
|
258
|
+
}
|
259
|
+
catch (error) {
|
260
|
+
reject(error);
|
261
|
+
}
|
262
|
+
};
|
263
|
+
reader.readAsDataURL(blob);
|
264
|
+
});
|
265
|
+
}
|
266
|
+
const cache = {};
|
267
|
+
function getCacheKey(url, contentType, includeQueryParams) {
|
268
|
+
let key = url.replace(/\?.*/, '');
|
269
|
+
if (includeQueryParams) {
|
270
|
+
key = url;
|
271
|
+
}
|
272
|
+
// font resource
|
273
|
+
if (/ttf|otf|eot|woff2?/i.test(key)) {
|
274
|
+
key = key.replace(/.*\//, '');
|
275
|
+
}
|
276
|
+
return contentType ? `[${contentType}]${key}` : key;
|
277
|
+
}
|
278
|
+
async function resourceToDataURL(resourceUrl, contentType, options) {
|
279
|
+
const cacheKey = getCacheKey(resourceUrl, contentType, options.includeQueryParams);
|
280
|
+
if (cache[cacheKey] != null) {
|
281
|
+
return cache[cacheKey];
|
282
|
+
}
|
283
|
+
// ref: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache
|
284
|
+
if (options.cacheBust) {
|
285
|
+
// eslint-disable-next-line no-param-reassign
|
286
|
+
resourceUrl += (/\?/.test(resourceUrl) ? '&' : '?') + new Date().getTime();
|
287
|
+
}
|
288
|
+
let dataURL;
|
289
|
+
try {
|
290
|
+
const content = await fetchAsDataURL(resourceUrl, options.fetchRequestInit, ({ res, result }) => {
|
291
|
+
if (!contentType) {
|
292
|
+
// eslint-disable-next-line no-param-reassign
|
293
|
+
contentType = res.headers.get('Content-Type') || '';
|
294
|
+
}
|
295
|
+
return getContentFromDataUrl(result);
|
296
|
+
});
|
297
|
+
dataURL = makeDataUrl(content, contentType);
|
298
|
+
}
|
299
|
+
catch (error) {
|
300
|
+
dataURL = options.imagePlaceholder || '';
|
301
|
+
let msg = `Failed to fetch resource: ${resourceUrl}`;
|
302
|
+
if (error) {
|
303
|
+
msg = typeof error === 'string' ? error : error.message;
|
304
|
+
}
|
305
|
+
if (msg) {
|
306
|
+
console.warn(msg);
|
307
|
+
}
|
308
|
+
}
|
309
|
+
cache[cacheKey] = dataURL;
|
310
|
+
return dataURL;
|
311
|
+
}
|
312
|
+
|
313
|
+
async function cloneCanvasElement(canvas) {
|
314
|
+
const dataURL = canvas.toDataURL();
|
315
|
+
if (dataURL === 'data:,') {
|
316
|
+
return canvas.cloneNode(false);
|
317
|
+
}
|
318
|
+
return createImage(dataURL);
|
319
|
+
}
|
320
|
+
async function cloneVideoElement(video, options) {
|
321
|
+
if (video.currentSrc) {
|
322
|
+
const canvas = document.createElement('canvas');
|
323
|
+
const ctx = canvas.getContext('2d');
|
324
|
+
canvas.width = video.clientWidth;
|
325
|
+
canvas.height = video.clientHeight;
|
326
|
+
ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
327
|
+
const dataURL = canvas.toDataURL();
|
328
|
+
return createImage(dataURL);
|
329
|
+
}
|
330
|
+
const poster = video.poster;
|
331
|
+
const contentType = getMimeType(poster);
|
332
|
+
const dataURL = await resourceToDataURL(poster, contentType, options);
|
333
|
+
return createImage(dataURL);
|
334
|
+
}
|
335
|
+
async function cloneIFrameElement(iframe) {
|
336
|
+
var _a;
|
337
|
+
try {
|
338
|
+
if ((_a = iframe === null || iframe === void 0 ? void 0 : iframe.contentDocument) === null || _a === void 0 ? void 0 : _a.body) {
|
339
|
+
return (await cloneNode(iframe.contentDocument.body, {}, true));
|
340
|
+
}
|
341
|
+
}
|
342
|
+
catch (_b) {
|
343
|
+
// Failed to clone iframe
|
344
|
+
}
|
345
|
+
return iframe.cloneNode(false);
|
346
|
+
}
|
347
|
+
async function cloneSingleNode(node, options) {
|
348
|
+
if (isInstanceOfElement(node, HTMLCanvasElement)) {
|
349
|
+
return cloneCanvasElement(node);
|
350
|
+
}
|
351
|
+
if (isInstanceOfElement(node, HTMLVideoElement)) {
|
352
|
+
return cloneVideoElement(node, options);
|
353
|
+
}
|
354
|
+
if (isInstanceOfElement(node, HTMLIFrameElement)) {
|
355
|
+
return cloneIFrameElement(node);
|
356
|
+
}
|
357
|
+
return node.cloneNode(false);
|
358
|
+
}
|
359
|
+
const isSlotElement = (node) => node.tagName != null && node.tagName.toUpperCase() === 'SLOT';
|
360
|
+
async function cloneChildren(nativeNode, clonedNode, options) {
|
361
|
+
var _a, _b;
|
362
|
+
let children = [];
|
363
|
+
if (isSlotElement(nativeNode) && nativeNode.assignedNodes) {
|
364
|
+
children = toArray(nativeNode.assignedNodes());
|
365
|
+
}
|
366
|
+
else if (isInstanceOfElement(nativeNode, HTMLIFrameElement) &&
|
367
|
+
((_a = nativeNode.contentDocument) === null || _a === void 0 ? void 0 : _a.body)) {
|
368
|
+
children = toArray(nativeNode.contentDocument.body.childNodes);
|
369
|
+
}
|
370
|
+
else {
|
371
|
+
children = toArray(((_b = nativeNode.shadowRoot) !== null && _b !== void 0 ? _b : nativeNode).childNodes);
|
372
|
+
}
|
373
|
+
if (children.length === 0 ||
|
374
|
+
isInstanceOfElement(nativeNode, HTMLVideoElement)) {
|
375
|
+
return clonedNode;
|
376
|
+
}
|
377
|
+
await children.reduce((deferred, child) => deferred
|
378
|
+
.then(() => cloneNode(child, options))
|
379
|
+
.then((clonedChild) => {
|
380
|
+
if (clonedChild) {
|
381
|
+
clonedNode.appendChild(clonedChild);
|
382
|
+
}
|
383
|
+
}), Promise.resolve());
|
384
|
+
return clonedNode;
|
385
|
+
}
|
386
|
+
function cloneCSSStyle(nativeNode, clonedNode) {
|
387
|
+
const targetStyle = clonedNode.style;
|
388
|
+
if (!targetStyle) {
|
389
|
+
return;
|
390
|
+
}
|
391
|
+
const sourceStyle = window.getComputedStyle(nativeNode);
|
392
|
+
if (sourceStyle.cssText) {
|
393
|
+
targetStyle.cssText = sourceStyle.cssText;
|
394
|
+
targetStyle.transformOrigin = sourceStyle.transformOrigin;
|
395
|
+
}
|
396
|
+
else {
|
397
|
+
toArray(sourceStyle).forEach((name) => {
|
398
|
+
let value = sourceStyle.getPropertyValue(name);
|
399
|
+
if (name === 'font-size' && value.endsWith('px')) {
|
400
|
+
const reducedFont = Math.floor(parseFloat(value.substring(0, value.length - 2))) - 0.1;
|
401
|
+
value = `${reducedFont}px`;
|
402
|
+
}
|
403
|
+
if (isInstanceOfElement(nativeNode, HTMLIFrameElement) &&
|
404
|
+
name === 'display' &&
|
405
|
+
value === 'inline') {
|
406
|
+
value = 'block';
|
407
|
+
}
|
408
|
+
if (name === 'd' && clonedNode.getAttribute('d')) {
|
409
|
+
value = `path(${clonedNode.getAttribute('d')})`;
|
410
|
+
}
|
411
|
+
targetStyle.setProperty(name, value, sourceStyle.getPropertyPriority(name));
|
412
|
+
});
|
413
|
+
}
|
414
|
+
}
|
415
|
+
function cloneInputValue(nativeNode, clonedNode) {
|
416
|
+
if (isInstanceOfElement(nativeNode, HTMLTextAreaElement)) {
|
417
|
+
clonedNode.innerHTML = nativeNode.value;
|
418
|
+
}
|
419
|
+
if (isInstanceOfElement(nativeNode, HTMLInputElement)) {
|
420
|
+
clonedNode.setAttribute('value', nativeNode.value);
|
421
|
+
}
|
422
|
+
}
|
423
|
+
function cloneSelectValue(nativeNode, clonedNode) {
|
424
|
+
if (isInstanceOfElement(nativeNode, HTMLSelectElement)) {
|
425
|
+
const clonedSelect = clonedNode;
|
426
|
+
const selectedOption = Array.from(clonedSelect.children).find((child) => nativeNode.value === child.getAttribute('value'));
|
427
|
+
if (selectedOption) {
|
428
|
+
selectedOption.setAttribute('selected', '');
|
429
|
+
}
|
430
|
+
}
|
431
|
+
}
|
432
|
+
function decorate(nativeNode, clonedNode) {
|
433
|
+
if (isInstanceOfElement(clonedNode, Element)) {
|
434
|
+
cloneCSSStyle(nativeNode, clonedNode);
|
435
|
+
clonePseudoElements(nativeNode, clonedNode);
|
436
|
+
cloneInputValue(nativeNode, clonedNode);
|
437
|
+
cloneSelectValue(nativeNode, clonedNode);
|
438
|
+
}
|
439
|
+
return clonedNode;
|
440
|
+
}
|
441
|
+
async function ensureSVGSymbols(clone, options) {
|
442
|
+
const uses = clone.querySelectorAll ? clone.querySelectorAll('use') : [];
|
443
|
+
if (uses.length === 0) {
|
444
|
+
return clone;
|
445
|
+
}
|
446
|
+
const processedDefs = {};
|
447
|
+
for (let i = 0; i < uses.length; i++) {
|
448
|
+
const use = uses[i];
|
449
|
+
const id = use.getAttribute('xlink:href');
|
450
|
+
if (id) {
|
451
|
+
const exist = clone.querySelector(id);
|
452
|
+
const definition = document.querySelector(id);
|
453
|
+
if (!exist && definition && !processedDefs[id]) {
|
454
|
+
// eslint-disable-next-line no-await-in-loop
|
455
|
+
processedDefs[id] = (await cloneNode(definition, options, true));
|
456
|
+
}
|
457
|
+
}
|
458
|
+
}
|
459
|
+
const nodes = Object.values(processedDefs);
|
460
|
+
if (nodes.length) {
|
461
|
+
const ns = 'http://www.w3.org/1999/xhtml';
|
462
|
+
const svg = document.createElementNS(ns, 'svg');
|
463
|
+
svg.setAttribute('xmlns', ns);
|
464
|
+
svg.style.position = 'absolute';
|
465
|
+
svg.style.width = '0';
|
466
|
+
svg.style.height = '0';
|
467
|
+
svg.style.overflow = 'hidden';
|
468
|
+
svg.style.display = 'none';
|
469
|
+
const defs = document.createElementNS(ns, 'defs');
|
470
|
+
svg.appendChild(defs);
|
471
|
+
for (let i = 0; i < nodes.length; i++) {
|
472
|
+
defs.appendChild(nodes[i]);
|
473
|
+
}
|
474
|
+
clone.appendChild(svg);
|
475
|
+
}
|
476
|
+
return clone;
|
477
|
+
}
|
478
|
+
async function cloneNode(node, options, isRoot) {
|
479
|
+
if (!isRoot && options.filter && !options.filter(node)) {
|
480
|
+
return null;
|
481
|
+
}
|
482
|
+
return Promise.resolve(node)
|
483
|
+
.then((clonedNode) => cloneSingleNode(clonedNode, options))
|
484
|
+
.then((clonedNode) => cloneChildren(node, clonedNode, options))
|
485
|
+
.then((clonedNode) => decorate(node, clonedNode))
|
486
|
+
.then((clonedNode) => ensureSVGSymbols(clonedNode, options));
|
487
|
+
}
|
488
|
+
|
489
|
+
const URL_REGEX = /url\((['"]?)([^'"]+?)\1\)/g;
|
490
|
+
const URL_WITH_FORMAT_REGEX = /url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g;
|
491
|
+
const FONT_SRC_REGEX = /src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;
|
492
|
+
function toRegex(url) {
|
493
|
+
// eslint-disable-next-line no-useless-escape
|
494
|
+
const escaped = url.replace(/([.*+?^${}()|\[\]\/\\])/g, '\\$1');
|
495
|
+
return new RegExp(`(url\\(['"]?)(${escaped})(['"]?\\))`, 'g');
|
496
|
+
}
|
497
|
+
function parseURLs(cssText) {
|
498
|
+
const urls = [];
|
499
|
+
cssText.replace(URL_REGEX, (raw, quotation, url) => {
|
500
|
+
urls.push(url);
|
501
|
+
return raw;
|
502
|
+
});
|
503
|
+
return urls.filter((url) => !isDataUrl(url));
|
504
|
+
}
|
505
|
+
async function embed(cssText, resourceURL, baseURL, options, getContentFromUrl) {
|
506
|
+
try {
|
507
|
+
const resolvedURL = baseURL ? resolveUrl(resourceURL, baseURL) : resourceURL;
|
508
|
+
const contentType = getMimeType(resourceURL);
|
509
|
+
let dataURL;
|
510
|
+
if (getContentFromUrl) {
|
511
|
+
const content = await getContentFromUrl(resolvedURL);
|
512
|
+
dataURL = makeDataUrl(content, contentType);
|
513
|
+
}
|
514
|
+
else {
|
515
|
+
dataURL = await resourceToDataURL(resolvedURL, contentType, options);
|
516
|
+
}
|
517
|
+
return cssText.replace(toRegex(resourceURL), `$1${dataURL}$3`);
|
518
|
+
}
|
519
|
+
catch (error) {
|
520
|
+
// pass
|
521
|
+
}
|
522
|
+
return cssText;
|
523
|
+
}
|
524
|
+
function filterPreferredFontFormat(str, { preferredFontFormat }) {
|
525
|
+
return !preferredFontFormat
|
526
|
+
? str
|
527
|
+
: str.replace(FONT_SRC_REGEX, (match) => {
|
528
|
+
// eslint-disable-next-line no-constant-condition
|
529
|
+
while (true) {
|
530
|
+
const [src, , format] = URL_WITH_FORMAT_REGEX.exec(match) || [];
|
531
|
+
if (!format) {
|
532
|
+
return '';
|
533
|
+
}
|
534
|
+
if (format === preferredFontFormat) {
|
535
|
+
return `src: ${src};`;
|
536
|
+
}
|
537
|
+
}
|
538
|
+
});
|
539
|
+
}
|
540
|
+
function shouldEmbed(url) {
|
541
|
+
return url.search(URL_REGEX) !== -1;
|
542
|
+
}
|
543
|
+
async function embedResources(cssText, baseUrl, options) {
|
544
|
+
if (!shouldEmbed(cssText)) {
|
545
|
+
return cssText;
|
546
|
+
}
|
547
|
+
const filteredCSSText = filterPreferredFontFormat(cssText, options);
|
548
|
+
const urls = parseURLs(filteredCSSText);
|
549
|
+
return urls.reduce((deferred, url) => deferred.then((css) => embed(css, url, baseUrl, options)), Promise.resolve(filteredCSSText));
|
550
|
+
}
|
551
|
+
|
552
|
+
async function embedProp(propName, node, options) {
|
553
|
+
var _a;
|
554
|
+
const propValue = (_a = node.style) === null || _a === void 0 ? void 0 : _a.getPropertyValue(propName);
|
555
|
+
if (propValue) {
|
556
|
+
const cssString = await embedResources(propValue, null, options);
|
557
|
+
node.style.setProperty(propName, cssString, node.style.getPropertyPriority(propName));
|
558
|
+
return true;
|
559
|
+
}
|
560
|
+
return false;
|
561
|
+
}
|
562
|
+
async function embedBackground(clonedNode, options) {
|
563
|
+
if (!(await embedProp('background', clonedNode, options))) {
|
564
|
+
await embedProp('background-image', clonedNode, options);
|
565
|
+
}
|
566
|
+
if (!(await embedProp('mask', clonedNode, options))) {
|
567
|
+
await embedProp('mask-image', clonedNode, options);
|
568
|
+
}
|
569
|
+
}
|
570
|
+
async function embedImageNode(clonedNode, options) {
|
571
|
+
const isImageElement = isInstanceOfElement(clonedNode, HTMLImageElement);
|
572
|
+
if (!(isImageElement && !isDataUrl(clonedNode.src)) &&
|
573
|
+
!(isInstanceOfElement(clonedNode, SVGImageElement) &&
|
574
|
+
!isDataUrl(clonedNode.href.baseVal))) {
|
575
|
+
return;
|
576
|
+
}
|
577
|
+
const url = isImageElement ? clonedNode.src : clonedNode.href.baseVal;
|
578
|
+
const dataURL = await resourceToDataURL(url, getMimeType(url), options);
|
579
|
+
await new Promise((resolve, reject) => {
|
580
|
+
clonedNode.onload = resolve;
|
581
|
+
clonedNode.onerror = reject;
|
582
|
+
const image = clonedNode;
|
583
|
+
if (image.decode) {
|
584
|
+
image.decode = resolve;
|
585
|
+
}
|
586
|
+
if (image.loading === 'lazy') {
|
587
|
+
image.loading = 'eager';
|
588
|
+
}
|
589
|
+
if (isImageElement) {
|
590
|
+
clonedNode.srcset = '';
|
591
|
+
clonedNode.src = dataURL;
|
592
|
+
}
|
593
|
+
else {
|
594
|
+
clonedNode.href.baseVal = dataURL;
|
595
|
+
}
|
596
|
+
});
|
597
|
+
}
|
598
|
+
async function embedChildren(clonedNode, options) {
|
599
|
+
const children = toArray(clonedNode.childNodes);
|
600
|
+
const deferreds = children.map((child) => embedImages(child, options));
|
601
|
+
await Promise.all(deferreds).then(() => clonedNode);
|
602
|
+
}
|
603
|
+
async function embedImages(clonedNode, options) {
|
604
|
+
if (isInstanceOfElement(clonedNode, Element)) {
|
605
|
+
await embedBackground(clonedNode, options);
|
606
|
+
await embedImageNode(clonedNode, options);
|
607
|
+
await embedChildren(clonedNode, options);
|
608
|
+
}
|
609
|
+
}
|
610
|
+
|
611
|
+
function applyStyle(node, options) {
|
612
|
+
const { style } = node;
|
613
|
+
if (options.backgroundColor) {
|
614
|
+
style.backgroundColor = options.backgroundColor;
|
615
|
+
}
|
616
|
+
if (options.width) {
|
617
|
+
style.width = `${options.width}px`;
|
618
|
+
}
|
619
|
+
if (options.height) {
|
620
|
+
style.height = `${options.height}px`;
|
621
|
+
}
|
622
|
+
const manual = options.style;
|
623
|
+
if (manual != null) {
|
624
|
+
Object.keys(manual).forEach((key) => {
|
625
|
+
style[key] = manual[key];
|
626
|
+
});
|
627
|
+
}
|
628
|
+
return node;
|
629
|
+
}
|
630
|
+
|
631
|
+
const cssFetchCache = {};
|
632
|
+
async function fetchCSS(url) {
|
633
|
+
let cache = cssFetchCache[url];
|
634
|
+
if (cache != null) {
|
635
|
+
return cache;
|
636
|
+
}
|
637
|
+
const res = await fetch(url);
|
638
|
+
const cssText = await res.text();
|
639
|
+
cache = { url, cssText };
|
640
|
+
cssFetchCache[url] = cache;
|
641
|
+
return cache;
|
642
|
+
}
|
643
|
+
async function embedFonts(data, options) {
|
644
|
+
let cssText = data.cssText;
|
645
|
+
const regexUrl = /url\(["']?([^"')]+)["']?\)/g;
|
646
|
+
const fontLocs = cssText.match(/url\([^)]+\)/g) || [];
|
647
|
+
const loadFonts = fontLocs.map(async (loc) => {
|
648
|
+
let url = loc.replace(regexUrl, '$1');
|
649
|
+
if (!url.startsWith('https://')) {
|
650
|
+
url = new URL(url, data.url).href;
|
651
|
+
}
|
652
|
+
return fetchAsDataURL(url, options.fetchRequestInit, ({ result }) => {
|
653
|
+
cssText = cssText.replace(loc, `url(${result})`);
|
654
|
+
return [loc, result];
|
655
|
+
});
|
656
|
+
});
|
657
|
+
return Promise.all(loadFonts).then(() => cssText);
|
658
|
+
}
|
659
|
+
function parseCSS(source) {
|
660
|
+
if (source == null) {
|
661
|
+
return [];
|
662
|
+
}
|
663
|
+
const result = [];
|
664
|
+
const commentsRegex = /(\/\*[\s\S]*?\*\/)/gi;
|
665
|
+
// strip out comments
|
666
|
+
let cssText = source.replace(commentsRegex, '');
|
667
|
+
// eslint-disable-next-line prefer-regex-literals
|
668
|
+
const keyframesRegex = new RegExp('((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})', 'gi');
|
669
|
+
// eslint-disable-next-line no-constant-condition
|
670
|
+
while (true) {
|
671
|
+
const matches = keyframesRegex.exec(cssText);
|
672
|
+
if (matches === null) {
|
673
|
+
break;
|
674
|
+
}
|
675
|
+
result.push(matches[0]);
|
676
|
+
}
|
677
|
+
cssText = cssText.replace(keyframesRegex, '');
|
678
|
+
const importRegex = /@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi;
|
679
|
+
// to match css & media queries together
|
680
|
+
const combinedCSSRegex = '((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]' +
|
681
|
+
'*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})';
|
682
|
+
// unified regex
|
683
|
+
const unifiedRegex = new RegExp(combinedCSSRegex, 'gi');
|
684
|
+
// eslint-disable-next-line no-constant-condition
|
685
|
+
while (true) {
|
686
|
+
let matches = importRegex.exec(cssText);
|
687
|
+
if (matches === null) {
|
688
|
+
matches = unifiedRegex.exec(cssText);
|
689
|
+
if (matches === null) {
|
690
|
+
break;
|
691
|
+
}
|
692
|
+
else {
|
693
|
+
importRegex.lastIndex = unifiedRegex.lastIndex;
|
694
|
+
}
|
695
|
+
}
|
696
|
+
else {
|
697
|
+
unifiedRegex.lastIndex = importRegex.lastIndex;
|
698
|
+
}
|
699
|
+
result.push(matches[0]);
|
700
|
+
}
|
701
|
+
return result;
|
702
|
+
}
|
703
|
+
async function getCSSRules(styleSheets, options) {
|
704
|
+
const ret = [];
|
705
|
+
const deferreds = [];
|
706
|
+
// First loop inlines imports
|
707
|
+
styleSheets.forEach((sheet) => {
|
708
|
+
if ('cssRules' in sheet) {
|
709
|
+
try {
|
710
|
+
toArray(sheet.cssRules || []).forEach((item, index) => {
|
711
|
+
if (item.type === CSSRule.IMPORT_RULE) {
|
712
|
+
let importIndex = index + 1;
|
713
|
+
const url = item.href;
|
714
|
+
const deferred = fetchCSS(url)
|
715
|
+
.then((metadata) => embedFonts(metadata, options))
|
716
|
+
.then((cssText) => parseCSS(cssText).forEach((rule) => {
|
717
|
+
try {
|
718
|
+
sheet.insertRule(rule, rule.startsWith('@import')
|
719
|
+
? (importIndex += 1)
|
720
|
+
: sheet.cssRules.length);
|
721
|
+
}
|
722
|
+
catch (error) {
|
723
|
+
console.error('Error inserting rule from remote css', {
|
724
|
+
rule,
|
725
|
+
error,
|
726
|
+
});
|
727
|
+
}
|
728
|
+
}))
|
729
|
+
.catch((e) => {
|
730
|
+
console.error('Error loading remote css', e.toString());
|
731
|
+
});
|
732
|
+
deferreds.push(deferred);
|
733
|
+
}
|
734
|
+
});
|
735
|
+
}
|
736
|
+
catch (e) {
|
737
|
+
const inline = styleSheets.find((a) => a.href == null) || document.styleSheets[0];
|
738
|
+
if (sheet.href != null) {
|
739
|
+
deferreds.push(fetchCSS(sheet.href)
|
740
|
+
.then((metadata) => embedFonts(metadata, options))
|
741
|
+
.then((cssText) => parseCSS(cssText).forEach((rule) => {
|
742
|
+
inline.insertRule(rule, sheet.cssRules.length);
|
743
|
+
}))
|
744
|
+
.catch((err) => {
|
745
|
+
console.error('Error loading remote stylesheet', err);
|
746
|
+
}));
|
747
|
+
}
|
748
|
+
console.error('Error inlining remote css file', e);
|
749
|
+
}
|
750
|
+
}
|
751
|
+
});
|
752
|
+
return Promise.all(deferreds).then(() => {
|
753
|
+
// Second loop parses rules
|
754
|
+
styleSheets.forEach((sheet) => {
|
755
|
+
if ('cssRules' in sheet) {
|
756
|
+
try {
|
757
|
+
toArray(sheet.cssRules || []).forEach((item) => {
|
758
|
+
ret.push(item);
|
759
|
+
});
|
760
|
+
}
|
761
|
+
catch (e) {
|
762
|
+
console.error(`Error while reading CSS rules from ${sheet.href}`, e);
|
763
|
+
}
|
764
|
+
}
|
765
|
+
});
|
766
|
+
return ret;
|
767
|
+
});
|
768
|
+
}
|
769
|
+
function getWebFontRules(cssRules) {
|
770
|
+
return cssRules
|
771
|
+
.filter((rule) => rule.type === CSSRule.FONT_FACE_RULE)
|
772
|
+
.filter((rule) => shouldEmbed(rule.style.getPropertyValue('src')));
|
773
|
+
}
|
774
|
+
async function parseWebFontRules(node, options) {
|
775
|
+
if (node.ownerDocument == null) {
|
776
|
+
throw new Error('Provided element is not within a Document');
|
777
|
+
}
|
778
|
+
const styleSheets = toArray(node.ownerDocument.styleSheets);
|
779
|
+
const cssRules = await getCSSRules(styleSheets, options);
|
780
|
+
return getWebFontRules(cssRules);
|
781
|
+
}
|
782
|
+
async function getWebFontCSS(node, options) {
|
783
|
+
const rules = await parseWebFontRules(node, options);
|
784
|
+
const cssTexts = await Promise.all(rules.map((rule) => {
|
785
|
+
const baseUrl = rule.parentStyleSheet ? rule.parentStyleSheet.href : null;
|
786
|
+
return embedResources(rule.cssText, baseUrl, options);
|
787
|
+
}));
|
788
|
+
return cssTexts.join('\n');
|
789
|
+
}
|
790
|
+
async function embedWebFonts(clonedNode, options) {
|
791
|
+
const cssText = options.fontEmbedCSS != null
|
792
|
+
? options.fontEmbedCSS
|
793
|
+
: options.skipFonts
|
794
|
+
? null
|
795
|
+
: await getWebFontCSS(clonedNode, options);
|
796
|
+
if (cssText) {
|
797
|
+
const styleNode = document.createElement('style');
|
798
|
+
const sytleContent = document.createTextNode(cssText);
|
799
|
+
styleNode.appendChild(sytleContent);
|
800
|
+
if (clonedNode.firstChild) {
|
801
|
+
clonedNode.insertBefore(styleNode, clonedNode.firstChild);
|
802
|
+
}
|
803
|
+
else {
|
804
|
+
clonedNode.appendChild(styleNode);
|
805
|
+
}
|
806
|
+
}
|
807
|
+
}
|
808
|
+
|
809
|
+
async function toSvg(node, options = {}) {
|
810
|
+
const { width, height } = getImageSize(node, options);
|
811
|
+
const clonedNode = (await cloneNode(node, options, true));
|
812
|
+
await embedWebFonts(clonedNode, options);
|
813
|
+
await embedImages(clonedNode, options);
|
814
|
+
applyStyle(clonedNode, options);
|
815
|
+
const datauri = await nodeToDataURL(clonedNode, width, height);
|
816
|
+
return datauri;
|
817
|
+
}
|
818
|
+
async function toCanvas(node, options = {}) {
|
819
|
+
const { width, height } = getImageSize(node, options);
|
820
|
+
const svg = await toSvg(node, options);
|
821
|
+
const img = await createImage(svg);
|
822
|
+
const canvas = document.createElement('canvas');
|
823
|
+
const context = canvas.getContext('2d');
|
824
|
+
const ratio = options.pixelRatio || getPixelRatio();
|
825
|
+
const canvasWidth = options.canvasWidth || width;
|
826
|
+
const canvasHeight = options.canvasHeight || height;
|
827
|
+
canvas.width = canvasWidth * ratio;
|
828
|
+
canvas.height = canvasHeight * ratio;
|
829
|
+
if (!options.skipAutoScale) {
|
830
|
+
checkCanvasDimensions(canvas);
|
831
|
+
}
|
832
|
+
canvas.style.width = `${canvasWidth}`;
|
833
|
+
canvas.style.height = `${canvasHeight}`;
|
834
|
+
if (options.backgroundColor) {
|
835
|
+
context.fillStyle = options.backgroundColor;
|
836
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
837
|
+
}
|
838
|
+
context.drawImage(img, 0, 0, canvas.width, canvas.height);
|
839
|
+
return canvas;
|
840
|
+
}
|
841
|
+
async function toPng(node, options = {}) {
|
842
|
+
const canvas = await toCanvas(node, options);
|
843
|
+
return canvas.toDataURL();
|
844
|
+
}
|
845
|
+
async function toJpeg(node, options = {}) {
|
846
|
+
const canvas = await toCanvas(node, options);
|
847
|
+
return canvas.toDataURL('image/jpeg', options.quality || 1);
|
848
|
+
}
|
849
|
+
|
18
850
|
const printStyling = `
|
19
851
|
@media print {
|
20
852
|
@page {
|
@@ -39,15 +871,27 @@ const printStyling = `
|
|
39
871
|
|
40
872
|
|
41
873
|
.instant-apps-export-print {
|
42
|
-
height: 100%;
|
43
|
-
width: 100%;
|
44
874
|
position: absolute;
|
45
875
|
z-index: -999;
|
46
876
|
color: #323232 !important;
|
877
|
+
--esri-calcite-mode-name: "light";
|
878
|
+
}
|
879
|
+
|
880
|
+
.instant-apps-export-print__pdf {
|
881
|
+
height: 100%;
|
882
|
+
width: 100%;
|
47
883
|
display: grid;
|
48
884
|
gap: 24px;
|
49
885
|
grid-auto-flow: row;
|
50
|
-
|
886
|
+
}
|
887
|
+
|
888
|
+
.instant-apps-export-print__img {
|
889
|
+
display: grid;
|
890
|
+
width: auto;
|
891
|
+
}
|
892
|
+
|
893
|
+
.instant-apps-export-print__img--extra-content {
|
894
|
+
grid-template-columns: 2fr minmax(0, 325px);
|
51
895
|
}
|
52
896
|
|
53
897
|
.instant-apps-export-print, .instant-apps-export-print * {
|
@@ -65,30 +909,55 @@ const printStyling = `
|
|
65
909
|
justify-content: center;
|
66
910
|
}
|
67
911
|
|
912
|
+
.instant-apps-export-print__img .instant-apps-export-print__view-container {
|
913
|
+
grid-row: 1;
|
914
|
+
grid-column: 1;
|
915
|
+
}
|
916
|
+
|
68
917
|
.instant-apps-export-print__view-wrapper {
|
69
918
|
height: fit-content;
|
70
919
|
width: fit-content;
|
71
920
|
position: relative;
|
72
921
|
display: flex;
|
73
922
|
flex-direction: column;
|
74
|
-
border: 2pt solid #323232;
|
75
923
|
overflow: hidden;
|
76
924
|
}
|
77
925
|
|
926
|
+
.instant-apps-export-print__pdf .instant-apps-export-print__view-wrapper {
|
927
|
+
border: 2pt solid #323232;
|
928
|
+
}
|
929
|
+
|
930
|
+
.instant-apps-export-print__img .instant-apps-export-print__view-wrapper {
|
931
|
+
border: 1pt solid #323232;
|
932
|
+
}
|
933
|
+
|
78
934
|
.instant-apps-export-print__view {
|
79
935
|
object-fit: contain;
|
80
936
|
}
|
81
937
|
|
938
|
+
.instant-apps-export-print__extra-container {
|
939
|
+
grid-row: 1 / span 2;
|
940
|
+
grid-column: 2;
|
941
|
+
}
|
942
|
+
|
82
943
|
.instant-apps-export-print__popup-container {
|
83
944
|
height: min-content;
|
84
|
-
max-width:
|
945
|
+
max-width: 325px;
|
85
946
|
display: none;
|
86
947
|
color: #323232;
|
87
948
|
background: #fff;
|
88
|
-
border: 1pt solid #323232;
|
89
949
|
break-inside: avoid;
|
90
950
|
}
|
91
951
|
|
952
|
+
.instant-apps-export-print__pdf .instant-apps-export-print__popup-container {
|
953
|
+
border: 1pt solid #323232;
|
954
|
+
}
|
955
|
+
|
956
|
+
.instant-apps-export-print__img .instant-apps-export-print__popup-container {
|
957
|
+
grid-row: 1 / span 2;
|
958
|
+
grid-column: 2;
|
959
|
+
}
|
960
|
+
|
92
961
|
.instant-apps-export-print__popup-title {
|
93
962
|
border-bottom: 1pt solid #323232;
|
94
963
|
}
|
@@ -108,6 +977,12 @@ const printStyling = `
|
|
108
977
|
overflow: unset;
|
109
978
|
}
|
110
979
|
|
980
|
+
.instant-apps-export-print__img .instant-apps-export-print__legend-container {
|
981
|
+
margin: 14px;
|
982
|
+
grid-row: 2;
|
983
|
+
grid-column: 1;
|
984
|
+
}
|
985
|
+
|
111
986
|
.esri-legend--card, .esri-legend--card__service-content {
|
112
987
|
flex-flow: row wrap;
|
113
988
|
}
|
@@ -117,7 +992,7 @@ const printStyling = `
|
|
117
992
|
color: #323232;
|
118
993
|
}
|
119
994
|
|
120
|
-
.instant-apps-export-print__popup-content * {
|
995
|
+
.instant-apps-export-print__popup-content *, .instant-apps-export-print__img .esri-feature.esri-widget * {
|
121
996
|
color: #323232;
|
122
997
|
}
|
123
998
|
|
@@ -306,7 +1181,6 @@ const screenshotStyling = `
|
|
306
1181
|
max-height: 75%;
|
307
1182
|
max-width: 75%;
|
308
1183
|
object-fit: contain;
|
309
|
-
border: 10px solid white;
|
310
1184
|
box-shadow: 2px 2px 5px 0 rgba(0, 0, 0, 0.5);
|
311
1185
|
margin-bottom: 0.5em;
|
312
1186
|
}
|
@@ -326,7 +1200,7 @@ const screenshotStyling = `
|
|
326
1200
|
margin: 5px;
|
327
1201
|
}`;
|
328
1202
|
|
329
|
-
const instantAppsExportCss = ":host{display:block;--instant-apps-export-action-background:var(--calcite-color-foreground-1);--instant-apps-export-action-background-hover:var(--calcite-color-foreground-2);--instant-apps-export-action-background-press:var(--calcite-color-foreground-3);--instant-apps-export-action-height:100%;--instant-apps-export-action-width:fit-content;--instant-apps-export-action-icon-color:var(--calcite-color-text-3);--instant-apps-export-action-icon-hover-color:var(--calcite-color-text-1);--instant-apps-export-background:var(--calcite-color-foreground-1);--instant-apps-export-text-color:var(--calcite-color-text-1);--instant-apps-export-popover-width:250px}.instant-apps-export{height:100%}.instant-apps-export *{box-sizing:border-box}.instant-apps-export__popover-container,.instant-apps-export__inline-container{padding:12px;background:var(--instant-apps-export-background);--calcite-color-text-1:var(--instant-apps-export-text-color)}.instant-apps-export__popover-container{width:var(--instant-apps-export-popover-width)}.instant-apps-export calcite-action{height:var(--instant-apps-export-action-height);width:var(--instant-apps-export-action-width);--calcite-color-foreground-1:var(--instant-apps-export-action-background);--calcite-color-foreground-2:var(--instant-apps-export-action-background-hover);--calcite-color-foreground-3:var(--instant-apps-export-action-background-press);--calcite-color-text-3:var(--instant-apps-export-action-icon-color);--calcite-color-text-1:var(--instant-apps-export-action-icon-hover-color)}.instant-apps-export .instant-apps-export-print{display:none}.instant-apps-export__visually-hidden{position:absolute;top:0;z-index:-1;visibility:hidden}.instant-apps-export calcite-input{--calcite-color-foreground-1:var(--instant-apps-export-background);--calcite-color-text-1:var(--instant-apps-export-text-color)}.instant-apps-export calcite-popover{--calcite-color-foreground-1:var(--instant-apps-export-background)}.instant-apps-export calcite-switch{--calcite-color-foreground-1:#fff;--calcite-color-foreground-2:#f3f3f3}.instant-apps-export calcite-button:last-of-type{margin-top:0.5rem}.instant-apps-export .calcite-mode-dark calcite-switch{--calcite-color-foreground-1:#2b2b2b;--calcite-color-foreground-2:#202020}.instant-apps-export__compass-container.esri-widget{background:#fff;box-shadow:0 1px 2px rgba(0, 0, 0, 0.3)}.instant-apps-export__compass-container.esri-widget .esri-compass__icon.esri-icon-compass{color:#6e6e6e}.hide{display:none}.screenshotCursor{cursor:crosshair}";
|
1203
|
+
const instantAppsExportCss = ":host{display:block;--instant-apps-export-action-background:var(--calcite-color-foreground-1);--instant-apps-export-action-background-hover:var(--calcite-color-foreground-2);--instant-apps-export-action-background-press:var(--calcite-color-foreground-3);--instant-apps-export-action-height:100%;--instant-apps-export-action-width:fit-content;--instant-apps-export-action-icon-color:var(--calcite-color-text-3);--instant-apps-export-action-icon-hover-color:var(--calcite-color-text-1);--instant-apps-export-background:var(--calcite-color-foreground-1);--instant-apps-export-text-color:var(--calcite-color-text-1);--instant-apps-export-popover-width:250px}.instant-apps-export{height:100%}.instant-apps-export *{box-sizing:border-box}.instant-apps-export__popover-container,.instant-apps-export__inline-container{padding:12px;background:var(--instant-apps-export-background);--calcite-color-text-1:var(--instant-apps-export-text-color)}.instant-apps-export__popover-container{width:var(--instant-apps-export-popover-width)}.instant-apps-export calcite-action{height:var(--instant-apps-export-action-height);width:var(--instant-apps-export-action-width);--calcite-color-foreground-1:var(--instant-apps-export-action-background);--calcite-color-foreground-2:var(--instant-apps-export-action-background-hover);--calcite-color-foreground-3:var(--instant-apps-export-action-background-press);--calcite-color-text-3:var(--instant-apps-export-action-icon-color);--calcite-color-text-1:var(--instant-apps-export-action-icon-hover-color)}.instant-apps-export .instant-apps-export-print{display:none}.instant-apps-export .instant-apps-export-print_img{display:flex;flex-flow:row wrap}.instant-apps-export__visually-hidden{position:absolute;top:0;z-index:-1;visibility:hidden}.instant-apps-export calcite-input{--calcite-color-foreground-1:var(--instant-apps-export-background);--calcite-color-text-1:var(--instant-apps-export-text-color)}.instant-apps-export calcite-popover{--calcite-color-foreground-1:var(--instant-apps-export-background)}.instant-apps-export calcite-switch{--calcite-color-foreground-1:#fff;--calcite-color-foreground-2:#f3f3f3}.instant-apps-export calcite-button:last-of-type{margin-top:0.5rem}.instant-apps-export .calcite-mode-dark calcite-switch{--calcite-color-foreground-1:#2b2b2b;--calcite-color-foreground-2:#202020}.instant-apps-export__compass-container.esri-widget{background:#fff;box-shadow:0 1px 2px rgba(0, 0, 0, 0.3)}.instant-apps-export__compass-container.esri-widget .esri-compass__icon.esri-icon-compass{color:#6e6e6e}.hide{display:none}.screenshotCursor{cursor:crosshair}";
|
330
1204
|
const InstantAppsExportStyle0 = instantAppsExportCss;
|
331
1205
|
|
332
1206
|
const CSS = {
|
@@ -336,7 +1210,9 @@ const CSS = {
|
|
336
1210
|
popoverContainer: 'instant-apps-export__popover-container',
|
337
1211
|
hidden: 'instant-apps-export__visually-hidden',
|
338
1212
|
print: {
|
339
|
-
|
1213
|
+
pdfBase: 'instant-apps-export-print instant-apps-export-print__pdf',
|
1214
|
+
imgBase: 'instant-apps-export-print instant-apps-export-print__img',
|
1215
|
+
imgExtraContent: 'instant-apps-export-print__img--extra-content',
|
340
1216
|
contentContainer: 'instant-apps-export-print__content-container',
|
341
1217
|
extraContainer: 'instant-apps-export-print__extra-container',
|
342
1218
|
legendContainer: 'instant-apps-export-print__legend-container',
|
@@ -356,16 +1232,20 @@ const InstantAppsExport = class {
|
|
356
1232
|
constructor(hostRef) {
|
357
1233
|
index.registerInstance(this, hostRef);
|
358
1234
|
this.exportOutputUpdated = index.createEvent(this, "exportOutputUpdated", 7);
|
1235
|
+
this.fileTypes = ['PDF', 'JPG', 'PNG'];
|
359
1236
|
this.output = undefined;
|
360
1237
|
this.beforeExport = () => Promise.resolve();
|
361
1238
|
this.popoverIcon = 'export';
|
362
1239
|
this.extraContent = undefined;
|
363
1240
|
this.extraContentLabel = undefined;
|
364
1241
|
this.headerTitle = '';
|
1242
|
+
this.logoImage = '';
|
365
1243
|
this.includeExtraContent = true;
|
1244
|
+
this.showExtraContentInImg = false;
|
366
1245
|
this.includeLegend = true;
|
367
1246
|
this.includeMap = true;
|
368
1247
|
this.includePopup = false;
|
1248
|
+
this.includeFileFormat = true;
|
369
1249
|
this.mode = 'popover';
|
370
1250
|
this.popoverPositioning = 'absolute';
|
371
1251
|
this.popoverPlacement = 'auto';
|
@@ -381,6 +1261,7 @@ const InstantAppsExport = class {
|
|
381
1261
|
this.baseClass = CSS.baseLight;
|
382
1262
|
this.exportIsLoading = undefined;
|
383
1263
|
this.messages = undefined;
|
1264
|
+
this.selectedFileType = 'PDF';
|
384
1265
|
}
|
385
1266
|
watchIncludeMap(includeMap) {
|
386
1267
|
if (includeMap) {
|
@@ -408,7 +1289,7 @@ const InstantAppsExport = class {
|
|
408
1289
|
render() {
|
409
1290
|
const mode = this.mode === 'popover' ? this.renderPopover() : this.renderPanel();
|
410
1291
|
const compass = this.renderCompass();
|
411
|
-
return (index.h(index.Host, { key: '
|
1292
|
+
return (index.h(index.Host, { key: '9811c244faf2c794db3edaad498a9a902cb3faad' }, index.h("div", { key: 'cb880c04d46ec06a9588cedc0bd90ab62d25c0ac', class: this.baseClass, onMouseEnter: this.handleWidgetCreation.bind(this), onFocusin: this.handleWidgetCreation.bind(this) }, mode, index.h("div", { key: 'fc7ccd1eeb4b6a82bd9804d1aa73c4f242085a56', class: CSS.hidden }, compass))));
|
412
1293
|
}
|
413
1294
|
renderPopover() {
|
414
1295
|
var _a, _b, _c;
|
@@ -419,25 +1300,31 @@ const InstantAppsExport = class {
|
|
419
1300
|
];
|
420
1301
|
}
|
421
1302
|
renderPanel() {
|
422
|
-
var _a, _b;
|
1303
|
+
var _a, _b, _c;
|
423
1304
|
const headerTitle = this.showHeaderTitle ? this.renderTitle() : null;
|
424
|
-
const includeExtraContent = this.extraContent != null ? this.renderSwitch('includeExtraContent', this.extraContentLabel) : null;
|
425
|
-
const includeMap = this.showIncludeMap ? this.renderSwitch('includeMap') : null;
|
1305
|
+
const includeExtraContent = this.extraContent != null ? this.renderSwitch('includeExtraContent', this.extraContentLabel, this.selectedFileType !== 'PDF' && !this.showExtraContentInImg) : null;
|
1306
|
+
const includeMap = this.showIncludeMap ? this.renderSwitch('includeMap', undefined, this.selectedFileType !== 'PDF') : null;
|
426
1307
|
const options = this.includeMap ? this.renderMapOptions() : null;
|
427
|
-
const
|
1308
|
+
const fileType = this.includeFileFormat ? this.renderSelectFileType() : null;
|
1309
|
+
const print = this.selectedFileType === 'PDF' ? this.renderPrint() : this.renderImg();
|
428
1310
|
const panelClass = this.mode === 'inline' ? CSS.inlineContainer : CSS.popoverContainer;
|
429
|
-
return (index.h("div", { class: panelClass }, headerTitle, includeExtraContent, includeMap, options, this.includeMap ? (index.h("calcite-button", { appearance: "transparent", width: "full", onClick: this.setMapAreaOnClick.bind(this), disabled: this.exportIsLoading }, (_a = this.messages) === null || _a === void 0 ? void 0 : _a.setMapArea)) : null, index.h("calcite-button", { width: "full", onClick: this.exportOnClick.bind(this), disabled: this.exportIsLoading }, (_b = this.messages) === null || _b === void 0 ? void 0 : _b.export), print));
|
1311
|
+
return (index.h("div", { class: panelClass }, headerTitle, includeExtraContent, includeMap, options, fileType, this.includeMap ? (index.h("calcite-button", { appearance: "transparent", width: "full", onClick: this.setMapAreaOnClick.bind(this, true), disabled: this.exportIsLoading }, (_a = this.messages) === null || _a === void 0 ? void 0 : _a.setMapArea)) : null, index.h("calcite-button", { width: "full", onClick: this.exportOnClick.bind(this), disabled: this.exportIsLoading }, this.selectedFileType === 'PDF' ? (_b = this.messages) === null || _b === void 0 ? void 0 : _b.export : (_c = this.messages) === null || _c === void 0 ? void 0 : _c.preview), print));
|
430
1312
|
}
|
431
1313
|
renderTitle() {
|
432
1314
|
var _a;
|
433
1315
|
return (index.h("calcite-label", null, (_a = this.messages) === null || _a === void 0 ? void 0 :
|
434
1316
|
_a.title, index.h("calcite-input", { value: this.headerTitle, onCalciteInputInput: this.updateHeaderTitle.bind(this) })));
|
435
1317
|
}
|
436
|
-
renderSwitch(value, label) {
|
1318
|
+
renderSwitch(value, label, disabled) {
|
437
1319
|
var _a;
|
438
1320
|
const checked = this[value];
|
439
1321
|
const title = label != null ? label : (_a = this.messages) === null || _a === void 0 ? void 0 : _a[value];
|
440
|
-
return (index.h("calcite-label", { layout: "inline-space-between" }, title, index.h("calcite-switch", { checked: checked, value: value, onCalciteSwitchChange: this.optionOnChange.bind(this) })));
|
1322
|
+
return (index.h("calcite-label", { layout: "inline-space-between" }, title, index.h("calcite-switch", { checked: checked, value: value, onCalciteSwitchChange: this.optionOnChange.bind(this), disabled: disabled })));
|
1323
|
+
}
|
1324
|
+
renderSelectFileType() {
|
1325
|
+
var _a;
|
1326
|
+
return (index.h("calcite-label", null, (_a = this.messages) === null || _a === void 0 ? void 0 :
|
1327
|
+
_a.fileType, index.h("calcite-select", { onCalciteSelectChange: this.handleSelectFileType.bind(this) }, this.fileTypes.map(fileType => (index.h("calcite-option", { value: fileType, selected: fileType === this.selectedFileType }, fileType))))));
|
441
1328
|
}
|
442
1329
|
renderMapOptions() {
|
443
1330
|
const includeLegend = this.showIncludeLegend ? this.renderSwitch('includeLegend') : null;
|
@@ -449,10 +1336,10 @@ const InstantAppsExport = class {
|
|
449
1336
|
const extraContent = this.renderExtraContent();
|
450
1337
|
const legend = this.includeMap && this.showIncludeLegend ? this.renderLegend() : null;
|
451
1338
|
const popup = this.includeMap && this.showIncludePopup ? this.renderPopup() : null;
|
452
|
-
return (index.h("div", { ref: (el) => (this.printContainerEl = el) }, index.h("div", { class: CSS.print.
|
1339
|
+
return (index.h("div", { ref: (el) => (this.printContainerEl = el) }, index.h("div", { class: CSS.print.pdfBase, ref: (el) => (this.printEl = el) }, printMap, legend, index.h("div", { class: CSS.print.contentContainer }, popup, extraContent))));
|
453
1340
|
}
|
454
1341
|
renderPrintMap() {
|
455
|
-
return (index.h("div", { class: CSS.print.viewContainer, ref: (el) => (this.viewContainerEl = el) }, index.h("div", { class: CSS.print.viewWrapper, ref: (el) => (this.viewWrapperEl = el) }, this.headerTitle ? index.h("instant-apps-header", { titleText: this.headerTitle, backgroundColor: "#fff", textColor: "#323232" }) : null, index.h("img", { class: CSS.print.view, ref: (el) => (this.viewEl = el) }), index.h("div", { class: CSS.print.scaleBarContainer, ref: (el) => (this.scaleBarContainerEl = el) }))));
|
1342
|
+
return (index.h("div", { class: CSS.print.viewContainer, ref: (el) => (this.viewContainerEl = el) }, index.h("div", { class: CSS.print.viewWrapper, ref: (el) => (this.viewWrapperEl = el) }, this.headerTitle ? (index.h("instant-apps-header", { logoImage: this.logoImage, logoScale: "s", titleText: this.headerTitle, backgroundColor: "#fff", textColor: "#323232" })) : null, index.h("img", { class: CSS.print.view, ref: (el) => (this.viewEl = el) }), index.h("div", { class: CSS.print.scaleBarContainer, ref: (el) => (this.scaleBarContainerEl = el) }))));
|
456
1343
|
}
|
457
1344
|
renderLegend() {
|
458
1345
|
return index.h("div", { class: CSS.print.legendContainer, ref: (el) => (this.legendContainerEl = el) });
|
@@ -466,6 +1353,18 @@ const InstantAppsExport = class {
|
|
466
1353
|
renderExtraContent() {
|
467
1354
|
return index.h("div", { class: CSS.print.extraContainer, id: "export-content", ref: (el) => (this.extraContainerEl = el) });
|
468
1355
|
}
|
1356
|
+
renderImg() {
|
1357
|
+
const printMap = this.includeMap ? this.renderPrintMap() : null;
|
1358
|
+
const legend = this.includeMap && this.showIncludeLegend ? this.renderLegend() : null;
|
1359
|
+
let content;
|
1360
|
+
if (this.includeMap && this.showIncludePopup) {
|
1361
|
+
content = this.renderPopup();
|
1362
|
+
}
|
1363
|
+
else if (this.showExtraContentInImg && this.extraContent != null && this.includeExtraContent) {
|
1364
|
+
content = this.renderExtraContent();
|
1365
|
+
}
|
1366
|
+
return (index.h("div", { ref: (el) => (this.printContainerEl = el) }, index.h("div", { class: CSS.print.imgBase, ref: (el) => (this.printEl = el) }, printMap, legend, content)));
|
1367
|
+
}
|
469
1368
|
optionOnChange(e) {
|
470
1369
|
const { checked, value } = e.target;
|
471
1370
|
this[value] = checked;
|
@@ -486,6 +1385,40 @@ const InstantAppsExport = class {
|
|
486
1385
|
this.popoverEl.open = false;
|
487
1386
|
}
|
488
1387
|
}
|
1388
|
+
async exportPreviewOnClick() {
|
1389
|
+
if (this.selectedFileType === 'PDF') {
|
1390
|
+
await this.exportPDF();
|
1391
|
+
}
|
1392
|
+
else {
|
1393
|
+
this.exportImg();
|
1394
|
+
}
|
1395
|
+
}
|
1396
|
+
async exportPDF() {
|
1397
|
+
this.removeScreenshotElements();
|
1398
|
+
await this.beforeExport();
|
1399
|
+
if (this.viewWrapperEl != null && !this.viewWrapperEl.contains(this.compassContainerEl)) {
|
1400
|
+
this.viewWrapperEl.append(this.compassContainerEl);
|
1401
|
+
}
|
1402
|
+
this.handleViewExportOnClick();
|
1403
|
+
if (this.popoverEl != null) {
|
1404
|
+
this.popoverEl.open = false;
|
1405
|
+
}
|
1406
|
+
}
|
1407
|
+
exportImg() {
|
1408
|
+
var _a;
|
1409
|
+
this.resetPopupVisibility();
|
1410
|
+
if (this.dataUrl == null)
|
1411
|
+
return;
|
1412
|
+
const downloadLink = document.createElement('a');
|
1413
|
+
downloadLink.id = 'download-link';
|
1414
|
+
downloadLink.href = this.dataUrl;
|
1415
|
+
downloadLink.download = (_a = this.headerTitle) !== null && _a !== void 0 ? _a : document.title;
|
1416
|
+
downloadLink.click();
|
1417
|
+
this.dataUrl = null;
|
1418
|
+
this.exportIsLoading = false;
|
1419
|
+
this.removeScreenshotElements();
|
1420
|
+
this.resetPrintContent();
|
1421
|
+
}
|
489
1422
|
async handleViewExportOnClick() {
|
490
1423
|
if (this.view != null) {
|
491
1424
|
this.addPrintStyling();
|
@@ -493,7 +1426,6 @@ const InstantAppsExport = class {
|
|
493
1426
|
this.handleExtraContent();
|
494
1427
|
if (this.includeMap) {
|
495
1428
|
this.updateScaleBar();
|
496
|
-
this.updatePopupToPrint();
|
497
1429
|
this.viewScreenshot();
|
498
1430
|
this.handleImgLoaded();
|
499
1431
|
}
|
@@ -517,7 +1449,9 @@ const InstantAppsExport = class {
|
|
517
1449
|
handleImgLoaded() {
|
518
1450
|
this.exportIsLoading = true;
|
519
1451
|
setTimeout(() => {
|
520
|
-
this.
|
1452
|
+
if (this.selectedFileType === 'PDF') {
|
1453
|
+
this.exportIsLoading = false;
|
1454
|
+
}
|
521
1455
|
this.setupViewPrintElements();
|
522
1456
|
}, 1500);
|
523
1457
|
}
|
@@ -525,7 +1459,10 @@ const InstantAppsExport = class {
|
|
525
1459
|
const extraContainerEl = this.printEl.querySelector('#export-content');
|
526
1460
|
if (extraContainerEl != null) {
|
527
1461
|
extraContainerEl.innerHTML = '';
|
528
|
-
|
1462
|
+
const hasExtraContent = this.extraContent != null && this.includeExtraContent;
|
1463
|
+
const imgAndFeatureVisible = this.selectedFileType !== 'PDF' && this.showExtraContentInImg && hasExtraContent;
|
1464
|
+
this.printEl.classList.toggle(CSS.print.imgExtraContent, imgAndFeatureVisible);
|
1465
|
+
if (hasExtraContent) {
|
529
1466
|
extraContainerEl.style.display = 'block';
|
530
1467
|
extraContainerEl.append(this.extraContent.cloneNode(true));
|
531
1468
|
}
|
@@ -533,13 +1470,17 @@ const InstantAppsExport = class {
|
|
533
1470
|
extraContainerEl.style.display = 'none';
|
534
1471
|
}
|
535
1472
|
}
|
1473
|
+
else if (this.showExtraContentInImg && this.selectedFileType !== 'PDF' && !this.includeExtraContent) {
|
1474
|
+
this.printEl.classList.toggle(CSS.print.imgExtraContent, false);
|
1475
|
+
}
|
536
1476
|
}
|
537
1477
|
resetPrintContent() {
|
538
|
-
var _a, _b;
|
1478
|
+
var _a, _b, _c;
|
539
1479
|
if (this.view != null) {
|
540
1480
|
this.screenshot = null;
|
541
1481
|
(_a = this.printContainerEl) === null || _a === void 0 ? void 0 : _a.prepend(this.printEl);
|
542
1482
|
(_b = this.printStyleEl) === null || _b === void 0 ? void 0 : _b.remove();
|
1483
|
+
(_c = this.tmpPopupTitleEl) === null || _c === void 0 ? void 0 : _c.remove();
|
543
1484
|
this.printStyleEl = undefined;
|
544
1485
|
const extraContainerEl = this.printEl.querySelector('#export-content');
|
545
1486
|
if (extraContainerEl) {
|
@@ -549,20 +1490,26 @@ const InstantAppsExport = class {
|
|
549
1490
|
}
|
550
1491
|
async updatePopupToPrint() {
|
551
1492
|
var _a, _b;
|
552
|
-
if (this.view
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
1493
|
+
if (this.view == null || this.popupContainerEl == null)
|
1494
|
+
return;
|
1495
|
+
this.popupContainerEl.style.display = this.includePopup && this.view.popup.visible ? 'block' : 'none';
|
1496
|
+
this.checkPopupOpen();
|
1497
|
+
const popupVisible = this.includePopup && (this.view.popup.visible || this.popupHiddenByMapArea) && this.view.popup.selectedFeature != null;
|
1498
|
+
this.printEl.classList.toggle(CSS.print.imgExtraContent, this.selectedFileType !== 'PDF' && popupVisible);
|
1499
|
+
if (popupVisible) {
|
1500
|
+
const heading = document.createElement(`h${(_a = this.view.popup.headingLevel) !== null && _a !== void 0 ? _a : 2}`);
|
1501
|
+
heading.innerHTML = (_b = this.view.popup.title) !== null && _b !== void 0 ? _b : '';
|
1502
|
+
heading.className = 'esri-widget__heading esri-popup__header-title';
|
1503
|
+
if (this.popupTitleEl == null) {
|
1504
|
+
this.tmpPopupTitleEl = document.createElement('div');
|
1505
|
+
this.tmpPopupTitleEl.prepend(heading);
|
1506
|
+
this.tmpPopupTitleEl.style.display = this.view.popup.title ? 'block' : 'none';
|
1507
|
+
this.popupContainerEl.prepend(this.tmpPopupTitleEl);
|
1508
|
+
}
|
1509
|
+
else {
|
1510
|
+
this.popupTitleEl.style.display = this.view.popup.title ? 'block' : 'none';
|
1511
|
+
this.popupTitleEl.innerHTML = '';
|
1512
|
+
this.popupTitleEl.prepend(heading);
|
566
1513
|
}
|
567
1514
|
}
|
568
1515
|
}
|
@@ -585,17 +1532,40 @@ const InstantAppsExport = class {
|
|
585
1532
|
setupViewPrintElements() {
|
586
1533
|
if (this.view != null) {
|
587
1534
|
this.handleLegendSetup();
|
588
|
-
|
589
|
-
|
590
|
-
|
1535
|
+
if (this.selectedFileType === 'PDF') {
|
1536
|
+
const title = document.title;
|
1537
|
+
if (this.showHeaderTitle && this.headerTitle) {
|
1538
|
+
document.title = this.headerTitle;
|
1539
|
+
}
|
1540
|
+
window.print();
|
1541
|
+
document.title = title;
|
1542
|
+
setTimeout(() => {
|
1543
|
+
this.resetPrintContent();
|
1544
|
+
}, 1000);
|
1545
|
+
}
|
1546
|
+
else {
|
1547
|
+
this.convertToImage();
|
591
1548
|
}
|
592
|
-
window.print();
|
593
|
-
document.title = title;
|
594
|
-
setTimeout(() => {
|
595
|
-
this.resetPrintContent();
|
596
|
-
}, 1000);
|
597
1549
|
}
|
598
1550
|
}
|
1551
|
+
convertToImage() {
|
1552
|
+
const options = { backgroundColor: '#FFF', skipFonts: true };
|
1553
|
+
if (this.selectedFileType === 'JPG') {
|
1554
|
+
toJpeg(this.printEl, options).then(this.handleGetImage.bind(this));
|
1555
|
+
}
|
1556
|
+
else {
|
1557
|
+
toPng(this.printEl, options).then(this.handleGetImage.bind(this));
|
1558
|
+
}
|
1559
|
+
}
|
1560
|
+
handleGetImage(dataUrl) {
|
1561
|
+
var _a;
|
1562
|
+
this.resetPrintContent();
|
1563
|
+
this.dataUrl = dataUrl;
|
1564
|
+
this.setMapAreaOnClick(false);
|
1565
|
+
this.showPreview(dataUrl);
|
1566
|
+
(_a = this.view) === null || _a === void 0 ? void 0 : _a.container.classList.remove('screenshot-cursor');
|
1567
|
+
this.setMaskPosition(null);
|
1568
|
+
}
|
599
1569
|
handleLegendSetup() {
|
600
1570
|
var _a;
|
601
1571
|
if (this.showIncludeLegend && this.view != null && this.includeMap && this.legendContainerEl != null) {
|
@@ -607,6 +1577,7 @@ const InstantAppsExport = class {
|
|
607
1577
|
if (this.includeMap) {
|
608
1578
|
this.handleLegendCreation();
|
609
1579
|
this.handleCompassCreation();
|
1580
|
+
this.updatePopupToPrint();
|
610
1581
|
}
|
611
1582
|
}
|
612
1583
|
handleIncludePopup() {
|
@@ -617,6 +1588,8 @@ const InstantAppsExport = class {
|
|
617
1588
|
(_b = this.reactiveUtils) === null || _b === void 0 ? void 0 : _b.whenOnce(() => { var _a; return (_a = this.view) === null || _a === void 0 ? void 0 : _a.ready; }).then(() => {
|
618
1589
|
var _a;
|
619
1590
|
(_a = this.handles) === null || _a === void 0 ? void 0 : _a.add(this.reactiveUtils.watch(() => { var _a, _b; return (_b = (_a = this.view) === null || _a === void 0 ? void 0 : _a.popup) === null || _b === void 0 ? void 0 : _b.visible; }, (visible) => {
|
1591
|
+
if (this.settingMapArea)
|
1592
|
+
return;
|
620
1593
|
this.includePopup = visible;
|
621
1594
|
}), handleId);
|
622
1595
|
});
|
@@ -648,6 +1621,7 @@ const InstantAppsExport = class {
|
|
648
1621
|
this.legend = new Legend({
|
649
1622
|
container: legendCont,
|
650
1623
|
view,
|
1624
|
+
respectLayerDefinitionExpression: true,
|
651
1625
|
style: {
|
652
1626
|
type: 'card',
|
653
1627
|
layout: 'side-by-side',
|
@@ -715,7 +1689,9 @@ const InstantAppsExport = class {
|
|
715
1689
|
}
|
716
1690
|
}
|
717
1691
|
setMaxRowHeightOnViewContainer() {
|
718
|
-
this.
|
1692
|
+
if (this.selectedFileType === 'PDF') {
|
1693
|
+
this.printEl.style.gridTemplateRows = 'minmax(auto, 70%)';
|
1694
|
+
}
|
719
1695
|
this.viewEl.style.height = '100%';
|
720
1696
|
this.viewEl.style.width = '';
|
721
1697
|
this.viewWrapperEl.style.height = '100%';
|
@@ -759,7 +1735,7 @@ const InstantAppsExport = class {
|
|
759
1735
|
}
|
760
1736
|
}
|
761
1737
|
createScreenshot() {
|
762
|
-
var _a, _b;
|
1738
|
+
var _a, _b, _c;
|
763
1739
|
if (this.view != null) {
|
764
1740
|
this.screenshotPreview = document.createElement('div');
|
765
1741
|
this.screenshotPreview.className = 'screenshot-preview hide';
|
@@ -769,10 +1745,10 @@ const InstantAppsExport = class {
|
|
769
1745
|
const screenshotBtnContainer = document.createElement('div');
|
770
1746
|
const exportBtn = document.createElement('calcite-button');
|
771
1747
|
const returnBtn = document.createElement('calcite-button');
|
772
|
-
exportBtn.innerHTML = (_a = this.messages) === null || _a === void 0 ? void 0 : _a.export;
|
773
|
-
returnBtn.innerHTML = (
|
1748
|
+
exportBtn.innerHTML = this.selectedFileType === 'PDF' ? (_a = this.messages) === null || _a === void 0 ? void 0 : _a.export : (_b = this.messages) === null || _b === void 0 ? void 0 : _b.downloadImage;
|
1749
|
+
returnBtn.innerHTML = (_c = this.messages) === null || _c === void 0 ? void 0 : _c.returnToMap;
|
774
1750
|
returnBtn.appearance = 'outline-fill';
|
775
|
-
exportBtn.onclick = this.
|
1751
|
+
exportBtn.onclick = this.exportPreviewOnClick.bind(this);
|
776
1752
|
returnBtn.onclick = this.screenshotReturn.bind(this);
|
777
1753
|
screenshotBtnContainer.append(returnBtn, exportBtn);
|
778
1754
|
this.screenshotImgContainer.append(this.screenshotImg, screenshotBtnContainer);
|
@@ -797,10 +1773,19 @@ const InstantAppsExport = class {
|
|
797
1773
|
this.removeScreenshotElements();
|
798
1774
|
this.exportIsLoading = false;
|
799
1775
|
this.screenshot = null;
|
1776
|
+
this.resetPopupVisibility();
|
800
1777
|
}
|
801
|
-
setMapAreaOnClick() {
|
1778
|
+
setMapAreaOnClick(handlePopup) {
|
802
1779
|
if (this.view == null)
|
803
1780
|
return;
|
1781
|
+
this.settingMapArea = true;
|
1782
|
+
if (handlePopup) {
|
1783
|
+
if (this.view.popup.visible) {
|
1784
|
+
this.popupHiddenByMapArea = true;
|
1785
|
+
const popupContainer = this.view.popup.container;
|
1786
|
+
popupContainer.style.display = 'none';
|
1787
|
+
}
|
1788
|
+
}
|
804
1789
|
this.exportIsLoading = true;
|
805
1790
|
this.createMaskDiv();
|
806
1791
|
this.createScreenshot();
|
@@ -845,9 +1830,21 @@ const InstantAppsExport = class {
|
|
845
1830
|
this.view.takeScreenshot({ area: this.area, width: width * 2, height: height * 2, format: 'jpg' }).then(screenshot => {
|
846
1831
|
var _a;
|
847
1832
|
this.screenshot = screenshot;
|
848
|
-
this.showPreview();
|
849
1833
|
(_a = this.view) === null || _a === void 0 ? void 0 : _a.container.classList.remove('screenshot-cursor');
|
850
1834
|
this.setMaskPosition(null);
|
1835
|
+
if (this.selectedFileType === 'PDF') {
|
1836
|
+
this.showPreview(screenshot === null || screenshot === void 0 ? void 0 : screenshot.dataUrl);
|
1837
|
+
this.resetPopupVisibility();
|
1838
|
+
}
|
1839
|
+
else {
|
1840
|
+
if (this.viewWrapperEl != null && !this.viewWrapperEl.contains(this.compassContainerEl)) {
|
1841
|
+
this.viewWrapperEl.append(this.compassContainerEl);
|
1842
|
+
}
|
1843
|
+
this.handleViewExportOnClick();
|
1844
|
+
if (this.popoverEl != null) {
|
1845
|
+
this.popoverEl.open = false;
|
1846
|
+
}
|
1847
|
+
}
|
851
1848
|
});
|
852
1849
|
}
|
853
1850
|
}
|
@@ -866,10 +1863,12 @@ const InstantAppsExport = class {
|
|
866
1863
|
clamp(value, from, to) {
|
867
1864
|
return value < from ? from : value > to ? to : value;
|
868
1865
|
}
|
869
|
-
showPreview() {
|
1866
|
+
showPreview(dataUrl) {
|
1867
|
+
if (!dataUrl)
|
1868
|
+
return;
|
870
1869
|
this.screenshotPreview.classList.remove('hide');
|
871
|
-
if (this.screenshotImg != null
|
872
|
-
this.screenshotImg.src =
|
1870
|
+
if (this.screenshotImg != null) {
|
1871
|
+
this.screenshotImg.src = dataUrl;
|
873
1872
|
}
|
874
1873
|
}
|
875
1874
|
handleScaleBarSize() {
|
@@ -893,9 +1892,37 @@ const InstantAppsExport = class {
|
|
893
1892
|
}
|
894
1893
|
}
|
895
1894
|
removeScreenshotElements() {
|
896
|
-
var _a, _b;
|
897
|
-
(_a = this.
|
898
|
-
(_b = this.
|
1895
|
+
var _a, _b, _c;
|
1896
|
+
(_a = this.view) === null || _a === void 0 ? void 0 : _a.removeHandles(dragHandlerName);
|
1897
|
+
(_b = this.screenshotPreview) === null || _b === void 0 ? void 0 : _b.remove();
|
1898
|
+
(_c = this.screenshotStyle) === null || _c === void 0 ? void 0 : _c.remove();
|
1899
|
+
}
|
1900
|
+
resetPopupVisibility() {
|
1901
|
+
if (this.view && this.settingMapArea && this.popupHiddenByMapArea) {
|
1902
|
+
const popupContainer = this.view.popup.container;
|
1903
|
+
popupContainer.style.display = '';
|
1904
|
+
}
|
1905
|
+
this.settingMapArea = false;
|
1906
|
+
this.popupHiddenByMapArea = false;
|
1907
|
+
}
|
1908
|
+
handleSelectFileType(e) {
|
1909
|
+
const node = e.target;
|
1910
|
+
this.selectedFileType = node.value;
|
1911
|
+
if (this.selectedFileType === 'PDF') {
|
1912
|
+
this.includeMap = this.pdfIncludeMap;
|
1913
|
+
if (!this.showExtraContentInImg) {
|
1914
|
+
this.includeExtraContent = this.pdfIncludeExtraContent;
|
1915
|
+
}
|
1916
|
+
}
|
1917
|
+
else {
|
1918
|
+
this.pdfIncludeMap = this.includeMap;
|
1919
|
+
this.includeMap = true;
|
1920
|
+
if (!this.showExtraContentInImg) {
|
1921
|
+
this.pdfIncludeExtraContent = this.includeExtraContent;
|
1922
|
+
this.includeMap = true;
|
1923
|
+
this.includeExtraContent = false;
|
1924
|
+
}
|
1925
|
+
}
|
899
1926
|
}
|
900
1927
|
get el() { return index.getElement(this); }
|
901
1928
|
static get watchers() { return {
|