@sswroom/sswr 1.6.19 → 1.6.20
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/Changelog +5 -0
- package/cesium.js +2 -1
- package/domtoimage/fontFaces.js +56 -0
- package/domtoimage/images.js +47 -0
- package/domtoimage/index.js +328 -0
- package/domtoimage/inliner.js +65 -0
- package/domtoimage/util.js +248 -0
- package/dummy/Cesium.d.ts +1 -0
- package/dummy/Cesium.js +1 -0
- package/exporter/XLSXExporter.js +578 -524
- package/leaflet/EasyPrint.js +731 -0
- package/package.json +1 -1
- package/web.d.ts +1 -0
- package/web.js +17 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import * as web from "../web.js";
|
|
2
|
+
export const uid = genUid();
|
|
3
|
+
|
|
4
|
+
function mimes() {
|
|
5
|
+
/*
|
|
6
|
+
* Only WOFF and EOT mime types for fonts are 'real'
|
|
7
|
+
* see http://www.iana.org/assignments/media-types/media-types.xhtml
|
|
8
|
+
*/
|
|
9
|
+
let WOFF = 'application/font-woff';
|
|
10
|
+
let JPEG = 'image/jpeg';
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
'woff': WOFF,
|
|
14
|
+
'woff2': WOFF,
|
|
15
|
+
'ttf': 'application/font-truetype',
|
|
16
|
+
'eot': 'application/vnd.ms-fontobject',
|
|
17
|
+
'png': 'image/png',
|
|
18
|
+
'jpg': JPEG,
|
|
19
|
+
'jpeg': JPEG,
|
|
20
|
+
'gif': 'image/gif',
|
|
21
|
+
'tiff': 'image/tiff',
|
|
22
|
+
'svg': 'image/svg+xml'
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} url
|
|
28
|
+
*/
|
|
29
|
+
export function parseExtension(url) {
|
|
30
|
+
let match = /\.([^\.\/]*?)$/g.exec(url);
|
|
31
|
+
if (match) return match[1];
|
|
32
|
+
else return '';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {string} url
|
|
37
|
+
* @returns {string}
|
|
38
|
+
*/
|
|
39
|
+
export function mimeType(url) {
|
|
40
|
+
let extension = parseExtension(url).toLowerCase();
|
|
41
|
+
return mimes()[extension] || '';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {string} url
|
|
46
|
+
*/
|
|
47
|
+
export function isDataUrl(url) {
|
|
48
|
+
return url.search(/^(data:)/) !== -1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {HTMLCanvasElement} canvas
|
|
53
|
+
*/
|
|
54
|
+
function toBlob(canvas) {
|
|
55
|
+
let binaryString = window.atob(canvas.toDataURL().split(',')[1]);
|
|
56
|
+
let length = binaryString.length;
|
|
57
|
+
let binaryArray = new Uint8Array(length);
|
|
58
|
+
|
|
59
|
+
for (let i = 0; i < length; i++)
|
|
60
|
+
binaryArray[i] = binaryString.charCodeAt(i);
|
|
61
|
+
|
|
62
|
+
return new Blob([binaryArray], {
|
|
63
|
+
type: 'image/png'
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {HTMLCanvasElement} canvas
|
|
69
|
+
* @returns {Promise<Blob|null>}
|
|
70
|
+
*/
|
|
71
|
+
export async function canvasToBlob(canvas) {
|
|
72
|
+
if (canvas.toBlob)
|
|
73
|
+
{
|
|
74
|
+
return await new Promise(function (resolve) {
|
|
75
|
+
canvas.toBlob(resolve);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return toBlob(canvas);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {string} url
|
|
84
|
+
* @param {string} baseUrl
|
|
85
|
+
*/
|
|
86
|
+
export function resolveUrl(url, baseUrl) {
|
|
87
|
+
let doc = document.implementation.createHTMLDocument();
|
|
88
|
+
let base = doc.createElement('base');
|
|
89
|
+
doc.head.appendChild(base);
|
|
90
|
+
let a = doc.createElement('a');
|
|
91
|
+
doc.body.appendChild(a);
|
|
92
|
+
base.href = baseUrl;
|
|
93
|
+
a.href = url;
|
|
94
|
+
return a.href;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function genUid() {
|
|
98
|
+
let index = 0;
|
|
99
|
+
|
|
100
|
+
return function () {
|
|
101
|
+
return 'u' + fourRandomChars() + index++;
|
|
102
|
+
|
|
103
|
+
function fourRandomChars() {
|
|
104
|
+
/* see http://stackoverflow.com/a/6248722/2519373 */
|
|
105
|
+
return ('0000' + (Math.random() * Math.pow(36, 4) << 0).toString(36)).slice(-4);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {string} uri
|
|
112
|
+
* @returns {Promise<HTMLImageElement>}
|
|
113
|
+
*/
|
|
114
|
+
export function makeImage(uri) {
|
|
115
|
+
return new Promise(function (resolve, reject) {
|
|
116
|
+
let image = new Image();
|
|
117
|
+
image.onload = function () {
|
|
118
|
+
resolve(image);
|
|
119
|
+
};
|
|
120
|
+
image.onerror = reject;
|
|
121
|
+
image.src = uri;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @param {string} url
|
|
127
|
+
* @param {{ cacheBust: boolean; imagePlaceholder?: string} | undefined} options
|
|
128
|
+
*/
|
|
129
|
+
export async function getAndEncode(url, options) {
|
|
130
|
+
let TIMEOUT = 30000;
|
|
131
|
+
if(options && options.cacheBust) {
|
|
132
|
+
// Cache bypass so we dont have CORS issues with cached images
|
|
133
|
+
// Source: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache
|
|
134
|
+
url += ((/\?/).test(url) ? "&" : "?") + (new Date()).getTime();
|
|
135
|
+
}
|
|
136
|
+
let placeholder;
|
|
137
|
+
if(options && options.imagePlaceholder) {
|
|
138
|
+
let split = options.imagePlaceholder.split(/,/);
|
|
139
|
+
if(split && split[1]) {
|
|
140
|
+
placeholder = split[1];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
try
|
|
144
|
+
{
|
|
145
|
+
let req = await fetch(url, {signal: AbortSignal.timeout(TIMEOUT)});
|
|
146
|
+
/** @type {string} */
|
|
147
|
+
if (!req.ok)
|
|
148
|
+
{
|
|
149
|
+
if(placeholder) {
|
|
150
|
+
return placeholder;
|
|
151
|
+
} else {
|
|
152
|
+
console.error('cannot fetch resource: ' + url + ', status: ' + req.status);
|
|
153
|
+
return "";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
let blob = await req.blob();
|
|
157
|
+
return await new Promise((resolve, reject) => {
|
|
158
|
+
let encoder = new FileReader();
|
|
159
|
+
encoder.onloadend = function () {
|
|
160
|
+
let content = encoder.result;
|
|
161
|
+
if (typeof content == 'string') resolve(content.split(/,/)[1]);
|
|
162
|
+
resolve(content);
|
|
163
|
+
};
|
|
164
|
+
encoder.readAsDataURL(blob);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
catch (error)
|
|
168
|
+
{
|
|
169
|
+
if(placeholder) {
|
|
170
|
+
return placeholder;
|
|
171
|
+
} else {
|
|
172
|
+
console.error('timeout of ' + TIMEOUT + 'ms occured while fetching resource: ' + url, error);
|
|
173
|
+
return "";
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @param {string} content
|
|
180
|
+
* @param {string} type
|
|
181
|
+
*/
|
|
182
|
+
export function dataAsUrl(content, type) {
|
|
183
|
+
return 'data:' + type + ';base64,' + content;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @param {string} string
|
|
188
|
+
*/
|
|
189
|
+
export function escape(string) {
|
|
190
|
+
return string.replace(/([.*+?^${}()|\[\]\/\\])/g, '\\$1');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @param {number | undefined} ms
|
|
195
|
+
*/
|
|
196
|
+
export function delay(ms) {
|
|
197
|
+
return function (/** @type {any} */ arg) {
|
|
198
|
+
return new Promise(function (resolve) {
|
|
199
|
+
setTimeout(function () {
|
|
200
|
+
resolve(arg);
|
|
201
|
+
}, ms);
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @param {string | any[] | StyleSheetList | NodeListOf<ChildNode>} arrayLike
|
|
208
|
+
*/
|
|
209
|
+
export function asArray(arrayLike) {
|
|
210
|
+
let array = [];
|
|
211
|
+
let length = arrayLike.length;
|
|
212
|
+
for (let i = 0; i < length; i++) array.push(arrayLike[i]);
|
|
213
|
+
return array;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @param {string} string
|
|
218
|
+
*/
|
|
219
|
+
export function escapeXhtml(string) {
|
|
220
|
+
return string.replace(/#/g, '%23').replace(/\n/g, '%0A');
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @param {Element} node
|
|
225
|
+
*/
|
|
226
|
+
export function width(node) {
|
|
227
|
+
let leftBorder = px(node, 'border-left-width');
|
|
228
|
+
let rightBorder = px(node, 'border-right-width');
|
|
229
|
+
return node.scrollWidth + leftBorder + rightBorder;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* @param {Element} node
|
|
234
|
+
*/
|
|
235
|
+
export function height(node) {
|
|
236
|
+
let topBorder = px(node, 'border-top-width');
|
|
237
|
+
let bottomBorder = px(node, 'border-bottom-width');
|
|
238
|
+
return node.scrollHeight + topBorder + bottomBorder;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* @param {Element} node
|
|
243
|
+
* @param {string} styleProperty
|
|
244
|
+
*/
|
|
245
|
+
function px(node, styleProperty) {
|
|
246
|
+
var value = window.getComputedStyle(node).getPropertyValue(styleProperty);
|
|
247
|
+
return parseFloat(value.replace('px', ''));
|
|
248
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Cesium } from "../../../cesium/Source/Cesium";
|
package/dummy/Cesium.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const Cesium = window.Cesium;
|