@merkur/integration 0.38.0 → 0.39.0
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 +1 -1
- package/lib/index.cjs +116 -204
- package/lib/index.es9.cjs +24 -1
- package/lib/index.es9.mjs +24 -1
- package/lib/index.js +116 -204
- package/lib/index.mjs +116 -204
- package/lib/index.umd.js +1 -1
- package/package.json +4 -5
package/lib/index.mjs
CHANGED
|
@@ -1,86 +1,60 @@
|
|
|
1
1
|
let _isES9Supported;
|
|
2
2
|
let _isES11Supported;
|
|
3
3
|
let _isES13Supported;
|
|
4
|
-
|
|
5
4
|
function isES9Supported() {
|
|
6
5
|
if (_isES9Supported === undefined) {
|
|
7
|
-
_isES9Supported =
|
|
8
|
-
exported.test(
|
|
9
|
-
'return (() => { const o = { t: 1 }; return { ...o }; })() && (async () => ({}))()',
|
|
10
|
-
) && !!Object.values;
|
|
6
|
+
_isES9Supported = exported.test('return (() => { const o = { t: 1 }; return { ...o }; })() && (async () => ({}))()') && !!Object.values;
|
|
11
7
|
}
|
|
12
|
-
|
|
13
8
|
return _isES9Supported;
|
|
14
9
|
}
|
|
15
|
-
|
|
16
10
|
function isES11Supported() {
|
|
17
11
|
if (_isES11Supported === undefined) {
|
|
18
|
-
_isES11Supported =
|
|
19
|
-
exported.test(
|
|
20
|
-
'return (() => { const o = { t: { q: true } }; return o?.t?.q && (o?.a?.q ?? true); })()',
|
|
21
|
-
) &&
|
|
22
|
-
exported.test('return typeof Promise.allSettled === "function"') &&
|
|
23
|
-
exported.test('return typeof globalThis !== "undefined"') &&
|
|
24
|
-
exported.test('return typeof 9007199254740991n === "bigint"');
|
|
12
|
+
_isES11Supported = exported.test('return (() => { const o = { t: { q: true } }; return o?.t?.q && (o?.a?.q ?? true); })()') && exported.test('return typeof Promise.allSettled === "function"') && exported.test('return typeof globalThis !== "undefined"') && exported.test('return typeof 9007199254740991n === "bigint"');
|
|
25
13
|
}
|
|
26
|
-
|
|
27
14
|
return _isES11Supported;
|
|
28
15
|
}
|
|
29
|
-
|
|
30
16
|
function isES13Supported() {
|
|
31
17
|
if (_isES13Supported === undefined) {
|
|
32
|
-
_isES13Supported =
|
|
33
|
-
exported.test('return [1,1].findLast(e => e === 1)') &&
|
|
34
|
-
exported.test('return Object.hasOwn({a:1}, "a")');
|
|
18
|
+
_isES13Supported = exported.test('return [1,1].findLast(e => e === 1)') && exported.test('return Object.hasOwn({a:1}, "a")');
|
|
35
19
|
}
|
|
36
|
-
|
|
37
20
|
return _isES13Supported;
|
|
38
21
|
}
|
|
39
|
-
|
|
40
22
|
function test(snippet) {
|
|
41
23
|
try {
|
|
42
24
|
const fn = new Function(snippet);
|
|
43
25
|
const result = fn();
|
|
44
|
-
|
|
45
26
|
return !!result;
|
|
46
27
|
} catch (e) {
|
|
47
28
|
return false;
|
|
48
29
|
}
|
|
49
30
|
}
|
|
50
|
-
|
|
51
31
|
const exported = {
|
|
52
32
|
isES9Supported,
|
|
53
33
|
isES11Supported,
|
|
54
34
|
isES13Supported,
|
|
55
|
-
test
|
|
35
|
+
test
|
|
56
36
|
};
|
|
57
37
|
|
|
58
38
|
const isLoadedSymbol = Symbol.for('isLoaded');
|
|
59
39
|
const loadingPromiseSymbol = Symbol.for('loadingPromise');
|
|
60
|
-
|
|
61
40
|
function _attachElementToAsset(asset, element) {
|
|
62
41
|
return {
|
|
63
42
|
...asset,
|
|
64
|
-
element
|
|
43
|
+
element
|
|
65
44
|
};
|
|
66
45
|
}
|
|
67
|
-
|
|
68
46
|
function _handleAssetError({
|
|
69
47
|
asset,
|
|
70
|
-
message = `Error loading asset ${asset.source}
|
|
48
|
+
message = `Error loading asset ${asset.source}.`
|
|
71
49
|
}) {
|
|
72
50
|
if (asset.optional) {
|
|
73
51
|
console.warn(message);
|
|
74
|
-
|
|
75
52
|
return _attachElementToAsset(asset, null);
|
|
76
53
|
}
|
|
77
|
-
|
|
78
54
|
const error = new Error(message);
|
|
79
55
|
error.asset = asset;
|
|
80
|
-
|
|
81
56
|
throw error;
|
|
82
57
|
}
|
|
83
|
-
|
|
84
58
|
function _addListenersToAssetElement(asset, element, resolve, reject) {
|
|
85
59
|
element.addEventListener('load', () => {
|
|
86
60
|
resolve(_attachElementToAsset(asset, element));
|
|
@@ -91,116 +65,94 @@ function _addListenersToAssetElement(asset, element, resolve, reject) {
|
|
|
91
65
|
if (element.parentNode) {
|
|
92
66
|
element.remove();
|
|
93
67
|
}
|
|
94
|
-
|
|
95
68
|
try {
|
|
96
|
-
resolve(_handleAssetError({
|
|
69
|
+
resolve(_handleAssetError({
|
|
70
|
+
asset
|
|
71
|
+
}));
|
|
97
72
|
} catch (error) {
|
|
98
73
|
reject(error);
|
|
99
74
|
}
|
|
100
75
|
});
|
|
101
76
|
}
|
|
102
|
-
|
|
103
77
|
function _loadStyle(asset, root) {
|
|
104
78
|
if (asset.type === 'inlineStyle') {
|
|
105
79
|
const style = document.createElement('style');
|
|
80
|
+
style.dataset.merkurAssetName = asset.name;
|
|
106
81
|
style.innerHTML = asset.source;
|
|
107
82
|
root.appendChild(style);
|
|
108
|
-
|
|
109
83
|
return _attachElementToAsset(asset, style);
|
|
110
84
|
}
|
|
111
|
-
|
|
112
85
|
const link = document.createElement('link');
|
|
113
|
-
|
|
114
86
|
link[loadingPromiseSymbol] = new Promise((resolve, reject) => {
|
|
115
87
|
_addListenersToAssetElement(asset, link, resolve, reject);
|
|
116
88
|
link.rel = 'stylesheet';
|
|
89
|
+
link.dataset.merkurAssetName = asset.name;
|
|
117
90
|
link.href = asset.source;
|
|
118
|
-
|
|
119
91
|
root.appendChild(link);
|
|
120
92
|
});
|
|
121
|
-
|
|
122
93
|
return link[loadingPromiseSymbol];
|
|
123
94
|
}
|
|
124
|
-
|
|
125
95
|
async function loadStyleAssets(assets, root = document.head) {
|
|
126
96
|
const styleElements = Array.from(root.querySelectorAll('style'));
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (asset.type === 'stylesheet') {
|
|
138
|
-
const link = root.querySelector(`link[href='${asset.source}']`);
|
|
139
|
-
|
|
140
|
-
if (link) {
|
|
141
|
-
if (link[loadingPromiseSymbol]) {
|
|
142
|
-
return link[loadingPromiseSymbol];
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return _attachElementToAsset(asset, link);
|
|
97
|
+
return Promise.all(assets.map(asset => {
|
|
98
|
+
if (!['stylesheet', 'inlineStyle'].includes(asset.type) || !asset.source) {
|
|
99
|
+
return _attachElementToAsset(asset, null);
|
|
100
|
+
}
|
|
101
|
+
if (asset.type === 'stylesheet') {
|
|
102
|
+
const link = root.querySelector(`link[href='${asset.source}']`);
|
|
103
|
+
if (link) {
|
|
104
|
+
if (link[loadingPromiseSymbol]) {
|
|
105
|
+
return link[loadingPromiseSymbol];
|
|
146
106
|
}
|
|
107
|
+
return _attachElementToAsset(asset, link);
|
|
147
108
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
if (inlineStyle) {
|
|
155
|
-
return _attachElementToAsset(asset, inlineStyle);
|
|
156
|
-
}
|
|
109
|
+
}
|
|
110
|
+
if (asset.type === 'inlineStyle') {
|
|
111
|
+
const inlineStyle = styleElements.find(element => element.innerHTML === asset.source);
|
|
112
|
+
if (inlineStyle) {
|
|
113
|
+
return _attachElementToAsset(asset, inlineStyle);
|
|
157
114
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
);
|
|
115
|
+
}
|
|
116
|
+
return _loadStyle(asset, root);
|
|
117
|
+
}));
|
|
162
118
|
}
|
|
163
|
-
|
|
164
119
|
function _findScriptElement(scriptElements, asset) {
|
|
165
120
|
if (asset.type === 'json') {
|
|
166
|
-
return scriptElements.find(
|
|
167
|
-
(element) => element.dataset.src === asset.source,
|
|
168
|
-
);
|
|
121
|
+
return scriptElements.find(element => element.dataset.src === asset.source);
|
|
169
122
|
}
|
|
170
|
-
|
|
171
123
|
if (!['script', 'inlineScript', 'inlineJson'].includes(asset.type)) {
|
|
172
124
|
return null;
|
|
173
125
|
}
|
|
174
|
-
|
|
175
126
|
const attributeKey = asset.type === 'script' ? 'src' : 'textContent';
|
|
176
|
-
const source =
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return (
|
|
180
|
-
scriptElements.find((element) => element[attributeKey] === source) || null
|
|
181
|
-
);
|
|
127
|
+
const source = asset.type === 'inlineJson' ? JSON.stringify(asset.source) : asset.source;
|
|
128
|
+
return scriptElements.find(element => element[attributeKey] === source) || null;
|
|
182
129
|
}
|
|
183
|
-
|
|
184
130
|
function _loadScript(asset, root) {
|
|
185
131
|
const script = document.createElement('script');
|
|
132
|
+
script.dataset.merkurAssetName = asset.name;
|
|
186
133
|
|
|
134
|
+
// Set script type to module if specified
|
|
135
|
+
if (asset.module) {
|
|
136
|
+
script.type = 'module';
|
|
137
|
+
}
|
|
187
138
|
if (asset.type === 'inlineScript') {
|
|
188
139
|
script.textContent = asset.source;
|
|
189
140
|
root.appendChild(script);
|
|
190
|
-
|
|
191
141
|
return _attachElementToAsset(asset, script);
|
|
192
142
|
}
|
|
193
|
-
|
|
194
143
|
script[loadingPromiseSymbol] = new Promise((resolve, reject) => {
|
|
195
|
-
|
|
144
|
+
// Don't set defer for module scripts as it can interfere with module loading
|
|
145
|
+
if (!asset.module) {
|
|
146
|
+
script.defer = true;
|
|
147
|
+
}
|
|
196
148
|
_addListenersToAssetElement(asset, script, resolve, reject);
|
|
197
149
|
script.src = asset.source;
|
|
198
|
-
|
|
199
|
-
|
|
150
|
+
const {
|
|
151
|
+
attr
|
|
152
|
+
} = asset;
|
|
200
153
|
if (attr && Object.keys(attr).length) {
|
|
201
154
|
for (const name in attr) {
|
|
202
155
|
const value = attr[name];
|
|
203
|
-
|
|
204
156
|
if (typeof value === 'boolean') {
|
|
205
157
|
if (value) {
|
|
206
158
|
script.setAttribute(name, '');
|
|
@@ -212,86 +164,73 @@ function _loadScript(asset, root) {
|
|
|
212
164
|
}
|
|
213
165
|
}
|
|
214
166
|
}
|
|
215
|
-
|
|
216
167
|
root.appendChild(script);
|
|
217
168
|
});
|
|
218
|
-
|
|
219
169
|
return script[loadingPromiseSymbol];
|
|
220
170
|
}
|
|
221
|
-
|
|
222
171
|
async function loadScriptAssets(assets, root = document.head) {
|
|
223
172
|
const scriptElements = Array.from(root.querySelectorAll('script'));
|
|
173
|
+
return Promise.all(assets.map(asset => {
|
|
174
|
+
if (!['script', 'inlineScript'].includes(asset.type) || !asset.source) {
|
|
175
|
+
return _attachElementToAsset(asset, null);
|
|
176
|
+
}
|
|
224
177
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const _asset = Object.assign({}, asset);
|
|
233
|
-
|
|
234
|
-
if (source === Object(source)) {
|
|
235
|
-
if (source.es13 && exported.isES13Supported()) {
|
|
236
|
-
_asset.source = source.es13;
|
|
237
|
-
} else if (source.es11 && exported.isES11Supported()) {
|
|
238
|
-
_asset.source = source.es11;
|
|
239
|
-
} else if (source.es9 && exported.isES9Supported()) {
|
|
240
|
-
_asset.source = source.es9;
|
|
241
|
-
} else {
|
|
242
|
-
_asset.source = null;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (!_asset.source) {
|
|
246
|
-
return _handleAssetError({
|
|
247
|
-
asset: _asset,
|
|
248
|
-
message: `Asset '${_asset.name}' is missing ES variant and could not be loaded.`,
|
|
249
|
-
});
|
|
178
|
+
// Module scripts should not use defer attribute as it can cause issues
|
|
179
|
+
if (asset.module && asset.attr && asset.attr.defer !== false) {
|
|
180
|
+
asset = {
|
|
181
|
+
...asset,
|
|
182
|
+
attr: {
|
|
183
|
+
...asset.attr,
|
|
184
|
+
defer: false
|
|
250
185
|
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const {
|
|
189
|
+
source
|
|
190
|
+
} = asset;
|
|
191
|
+
const _asset = Object.assign({}, asset);
|
|
192
|
+
if (source === Object(source)) {
|
|
193
|
+
if (source.es13 && exported.isES13Supported()) {
|
|
194
|
+
_asset.source = source.es13;
|
|
195
|
+
} else if (source.es11 && exported.isES11Supported()) {
|
|
196
|
+
_asset.source = source.es11;
|
|
197
|
+
} else if (source.es9 && exported.isES9Supported()) {
|
|
198
|
+
_asset.source = source.es9;
|
|
199
|
+
} else {
|
|
200
|
+
_asset.source = null;
|
|
251
201
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
_asset
|
|
256
|
-
|
|
257
|
-
);
|
|
202
|
+
if (!_asset.source) {
|
|
203
|
+
return _handleAssetError({
|
|
204
|
+
asset: _asset,
|
|
205
|
+
message: `Asset '${_asset.name}' is missing ES variant and could not be loaded.`
|
|
206
|
+
});
|
|
258
207
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return new Promise((resolve, reject) =>
|
|
272
|
-
_addListenersToAssetElement(_asset, script, resolve, reject),
|
|
273
|
-
);
|
|
274
|
-
} else if (script && _asset.type === 'inlineScript') {
|
|
208
|
+
}
|
|
209
|
+
if (_asset.test && exported.test(_asset.test)) {
|
|
210
|
+
return _attachElementToAsset(_asset, _findScriptElement(scriptElements, _asset));
|
|
211
|
+
}
|
|
212
|
+
const script = _findScriptElement(scriptElements, _asset);
|
|
213
|
+
if (script && _asset.type === 'script') {
|
|
214
|
+
if (script[loadingPromiseSymbol]) {
|
|
215
|
+
return script[loadingPromiseSymbol];
|
|
216
|
+
}
|
|
217
|
+
if (script[isLoadedSymbol]) {
|
|
275
218
|
return _attachElementToAsset(_asset, script);
|
|
276
219
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
220
|
+
return new Promise((resolve, reject) => _addListenersToAssetElement(_asset, script, resolve, reject));
|
|
221
|
+
} else if (script && _asset.type === 'inlineScript') {
|
|
222
|
+
return _attachElementToAsset(_asset, script);
|
|
223
|
+
}
|
|
224
|
+
return _loadScript(_asset, root);
|
|
225
|
+
}));
|
|
281
226
|
}
|
|
282
|
-
|
|
283
227
|
async function _fetchData(source) {
|
|
284
228
|
const response = await fetch(source);
|
|
285
|
-
|
|
286
229
|
if (!response.ok) {
|
|
287
|
-
throw new Error(
|
|
288
|
-
`Failed to fetch from '${source}' with status ${response.status} ${response.statusText}.`,
|
|
289
|
-
);
|
|
230
|
+
throw new Error(`Failed to fetch from '${source}' with status ${response.status} ${response.statusText}.`);
|
|
290
231
|
}
|
|
291
|
-
|
|
292
232
|
return response.text();
|
|
293
233
|
}
|
|
294
|
-
|
|
295
234
|
function _removeElementAfterTimeout(element, timeout) {
|
|
296
235
|
if (timeout) {
|
|
297
236
|
setTimeout(() => {
|
|
@@ -301,23 +240,19 @@ function _removeElementAfterTimeout(element, timeout) {
|
|
|
301
240
|
}, timeout);
|
|
302
241
|
}
|
|
303
242
|
}
|
|
304
|
-
|
|
305
243
|
function _loadJsonAsset(asset, root) {
|
|
306
244
|
const script = document.createElement('script');
|
|
245
|
+
script.dataset.merkurAssetName = asset.name;
|
|
307
246
|
script.type = 'application/json';
|
|
308
|
-
|
|
309
247
|
if (asset.type === 'inlineJson') {
|
|
310
248
|
script.textContent = JSON.stringify(asset.source);
|
|
311
249
|
root.appendChild(script);
|
|
312
250
|
_removeElementAfterTimeout(script, asset.ttl);
|
|
313
|
-
|
|
314
251
|
return _attachElementToAsset(asset, script);
|
|
315
252
|
}
|
|
316
|
-
|
|
317
253
|
script[loadingPromiseSymbol] = new Promise((resolve, reject) => {
|
|
318
254
|
script.dataset.src = asset.source;
|
|
319
255
|
root.appendChild(script);
|
|
320
|
-
|
|
321
256
|
(async () => {
|
|
322
257
|
try {
|
|
323
258
|
const textContent = await _fetchData(asset.source);
|
|
@@ -327,57 +262,41 @@ function _loadJsonAsset(asset, root) {
|
|
|
327
262
|
resolve(_attachElementToAsset(asset, script));
|
|
328
263
|
} catch (error) {
|
|
329
264
|
script.remove();
|
|
330
|
-
|
|
331
265
|
try {
|
|
332
|
-
resolve(
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}),
|
|
337
|
-
);
|
|
266
|
+
resolve(_handleAssetError({
|
|
267
|
+
asset,
|
|
268
|
+
message: `Error loading JSON asset '${asset.name}': ${error.message}`
|
|
269
|
+
}));
|
|
338
270
|
} catch (error) {
|
|
339
271
|
reject(error);
|
|
340
272
|
}
|
|
341
273
|
}
|
|
342
274
|
})();
|
|
343
275
|
});
|
|
344
|
-
|
|
345
276
|
return script[loadingPromiseSymbol];
|
|
346
277
|
}
|
|
347
|
-
|
|
348
278
|
async function loadJsonAssets(assets, root = document.head) {
|
|
349
|
-
const scriptElements = Array.from(
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
279
|
+
const scriptElements = Array.from(root.querySelectorAll('script[type="application/json"]'));
|
|
280
|
+
return Promise.all(assets.map(asset => {
|
|
281
|
+
if (!['json', 'inlineJson'].includes(asset.type) || !asset.source) {
|
|
282
|
+
return _attachElementToAsset(asset, null);
|
|
283
|
+
}
|
|
284
|
+
const script = _findScriptElement(scriptElements, asset);
|
|
285
|
+
if (script) {
|
|
286
|
+
if (script[loadingPromiseSymbol]) {
|
|
287
|
+
return script[loadingPromiseSymbol];
|
|
357
288
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (script) {
|
|
362
|
-
if (script[loadingPromiseSymbol]) {
|
|
363
|
-
return script[loadingPromiseSymbol];
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
if (script.textContent) {
|
|
367
|
-
return _attachElementToAsset(asset, script);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
return _handleAssetError({
|
|
371
|
-
asset,
|
|
372
|
-
message: `JSON asset '${asset.name}' is missing textContent and could not be loaded.`,
|
|
373
|
-
});
|
|
289
|
+
if (script.textContent) {
|
|
290
|
+
return _attachElementToAsset(asset, script);
|
|
374
291
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
292
|
+
return _handleAssetError({
|
|
293
|
+
asset,
|
|
294
|
+
message: `JSON asset '${asset.name}' is missing textContent and could not be loaded.`
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
return _loadJsonAsset(asset, root);
|
|
298
|
+
}));
|
|
379
299
|
}
|
|
380
|
-
|
|
381
300
|
function _mergeResults(results) {
|
|
382
301
|
return results.reduce((acc, results) => {
|
|
383
302
|
results.forEach((result, index) => {
|
|
@@ -387,18 +306,11 @@ function _mergeResults(results) {
|
|
|
387
306
|
acc[index] = result;
|
|
388
307
|
}
|
|
389
308
|
});
|
|
390
|
-
|
|
391
309
|
return acc;
|
|
392
310
|
}, []);
|
|
393
311
|
}
|
|
394
|
-
|
|
395
312
|
async function loadAssets(assets, root) {
|
|
396
|
-
const results = await Promise.all([
|
|
397
|
-
loadScriptAssets(assets, root),
|
|
398
|
-
loadStyleAssets(assets, root),
|
|
399
|
-
loadJsonAssets(assets, root),
|
|
400
|
-
]);
|
|
401
|
-
|
|
313
|
+
const results = await Promise.all([loadScriptAssets(assets, root), loadStyleAssets(assets, root), loadJsonAssets(assets, root)]);
|
|
402
314
|
return _mergeResults(results);
|
|
403
315
|
}
|
|
404
316
|
|
package/lib/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){if("function"==typeof define&&define.amd)define("@merkur/integration",["exports"],t);else if("undefined"!=typeof exports)t(exports);else{var n={exports:{}};t(n.exports),e.Merkur=e.Merkur||{},e.Merkur.Integration=n.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(e){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function n(e,t,n,r,o,i,u){try{var s=e[i](u),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function r(e){return function(){var t=this,r=arguments;return new Promise((function(o,i){var u=e.apply(t,r);function s(e){n(u,o,i,s,c,"next",e)}function c(e){n(u,o,i,s,c,"throw",e)}s(void 0)}))}}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){u(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function u(e,n,r){return(n=function(e){var n=function(e,n){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,n||"default");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==t(n)?n:n+""}(n))in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}var s,c,a;Object.defineProperty(e,"__esModule",{value:!0}),e.isLoadedSymbol=void 0,e.loadAssets=function(e,t){return
|
|
1
|
+
!function(e,t){if("function"==typeof define&&define.amd)define("@merkur/integration",["exports"],t);else if("undefined"!=typeof exports)t(exports);else{var n={exports:{}};t(n.exports),e.Merkur=e.Merkur||{},e.Merkur.Integration=n.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(e){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function n(e,t,n,r,o,i,u){try{var s=e[i](u),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function r(e){return function(){var t=this,r=arguments;return new Promise((function(o,i){var u=e.apply(t,r);function s(e){n(u,o,i,s,c,"next",e)}function c(e){n(u,o,i,s,c,"throw",e)}s(void 0)}))}}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){u(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function u(e,n,r){return(n=function(e){var n=function(e,n){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,n||"default");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==t(n)?n:n+""}(n))in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}var s,c,a;Object.defineProperty(e,"__esModule",{value:!0}),e.isLoadedSymbol=void 0,e.loadAssets=function(e,t){return A.apply(this,arguments)},e.loadJsonAssets=w,e.loadScriptAssets=S,e.loadStyleAssets=v,e.testScript=e.loadingPromiseSymbol=void 0;var l=e.testScript={isES9Supported:function(){return void 0===s&&(s=l.test("return (() => { const o = { t: 1 }; return { ...o }; })() && (async () => ({}))()")&&!!Object.values),s},isES11Supported:function(){return void 0===c&&(c=l.test("return (() => { const o = { t: { q: true } }; return o?.t?.q && (o?.a?.q ?? true); })()")&&l.test('return typeof Promise.allSettled === "function"')&&l.test('return typeof globalThis !== "undefined"')&&l.test('return typeof 9007199254740991n === "bigint"')),c},isES13Supported:function(){return void 0===a&&(a=l.test("return [1,1].findLast(e => e === 1)")&&l.test('return Object.hasOwn({a:1}, "a")')),a},test:function(e){try{return!!new Function(e)()}catch(e){return!1}}},f=e.isLoadedSymbol=Symbol.for("isLoaded"),p=e.loadingPromiseSymbol=Symbol.for("loadingPromise");function d(e,t){return i(i({},e),{},{element:t})}function y(e){var t=e.asset,n=e.message,r=void 0===n?"Error loading asset ".concat(t.source,"."):n;if(t.optional)return console.warn(r),d(t,null);var o=new Error(r);throw o.asset=t,o}function m(e,t,n,r){t.addEventListener("load",(function(){n(d(e,t)),t[f]=!0,delete t[p]})),t.addEventListener("error",(function(){t.parentNode&&t.remove();try{n(y({asset:e}))}catch(e){r(e)}}))}function v(e){return b.apply(this,arguments)}function b(){return b=r((function*(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document.head,n=Array.from(t.querySelectorAll("style"));return Promise.all(e.map((function(e){if(!["stylesheet","inlineStyle"].includes(e.type)||!e.source)return d(e,null);if("stylesheet"===e.type){var r=t.querySelector("link[href='".concat(e.source,"']"));if(r)return r[p]?r[p]:d(e,r)}if("inlineStyle"===e.type){var o=n.find((function(t){return t.innerHTML===e.source}));if(o)return d(e,o)}return function(e,t){if("inlineStyle"===e.type){var n=document.createElement("style");return n.dataset.merkurAssetName=e.name,n.innerHTML=e.source,t.appendChild(n),d(e,n)}var r=document.createElement("link");return r[p]=new Promise((function(n,o){m(e,r,n,o),r.rel="stylesheet",r.dataset.merkurAssetName=e.name,r.href=e.source,t.appendChild(r)})),r[p]}(e,t)})))})),b.apply(this,arguments)}function h(e,t){if("json"===t.type)return e.find((function(e){return e.dataset.src===t.source}));if(!["script","inlineScript","inlineJson"].includes(t.type))return null;var n="script"===t.type?"src":"textContent",r="inlineJson"===t.type?JSON.stringify(t.source):t.source;return e.find((function(e){return e[n]===r}))||null}function S(e){return g.apply(this,arguments)}function g(){return g=r((function*(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document.head,n=Array.from(t.querySelectorAll("script"));return Promise.all(e.map((function(e){if(!["script","inlineScript"].includes(e.type)||!e.source)return d(e,null);e.module&&e.attr&&!1!==e.attr.defer&&(e=i(i({},e),{},{attr:i(i({},e.attr),{},{defer:!1})}));var r=e.source,o=Object.assign({},e);if(r===Object(r)&&(r.es13&&l.isES13Supported()?o.source=r.es13:r.es11&&l.isES11Supported()?o.source=r.es11:r.es9&&l.isES9Supported()?o.source=r.es9:o.source=null,!o.source))return y({asset:o,message:"Asset '".concat(o.name,"' is missing ES variant and could not be loaded.")});if(o.test&&l.test(o.test))return d(o,h(n,o));var u=h(n,o);return u&&"script"===o.type?u[p]?u[p]:u[f]?d(o,u):new Promise((function(e,t){return m(o,u,e,t)})):u&&"inlineScript"===o.type?d(o,u):function(e,t){var n=document.createElement("script");return n.dataset.merkurAssetName=e.name,e.module&&(n.type="module"),"inlineScript"===e.type?(n.textContent=e.source,t.appendChild(n),d(e,n)):(n[p]=new Promise((function(r,o){e.module||(n.defer=!0),m(e,n,r,o),n.src=e.source;var i=e.attr;if(i&&Object.keys(i).length)for(var u in i){var s=i[u];"boolean"==typeof s?s?n.setAttribute(u,""):n.removeAttribute(u):n.setAttribute(u,s)}t.appendChild(n)})),n[p])}(o,t)})))})),g.apply(this,arguments)}function O(){return(O=r((function*(e){var t=yield fetch(e);if(!t.ok)throw new Error("Failed to fetch from '".concat(e,"' with status ").concat(t.status," ").concat(t.statusText,"."));return t.text()}))).apply(this,arguments)}function P(e,t){t&&setTimeout((function(){e.parentNode&&e.remove()}),t)}function j(e,t){var n=document.createElement("script");return n.dataset.merkurAssetName=e.name,n.type="application/json","inlineJson"===e.type?(n.textContent=JSON.stringify(e.source),t.appendChild(n),P(n,e.ttl),d(e,n)):(n[p]=new Promise((function(o,i){n.dataset.src=e.source,t.appendChild(n),r((function*(){try{var t=yield function(e){return O.apply(this,arguments)}(e.source);n.textContent=t,delete n[p],P(n,e.ttl),o(d(e,n))}catch(t){n.remove();try{o(y({asset:e,message:"Error loading JSON asset '".concat(e.name,"': ").concat(t.message)}))}catch(e){i(e)}}}))()})),n[p])}function w(e){return E.apply(this,arguments)}function E(){return E=r((function*(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document.head,n=Array.from(t.querySelectorAll('script[type="application/json"]'));return Promise.all(e.map((function(e){if(!["json","inlineJson"].includes(e.type)||!e.source)return d(e,null);var r=h(n,e);return r?r[p]?r[p]:r.textContent?d(e,r):y({asset:e,message:"JSON asset '".concat(e.name,"' is missing textContent and could not be loaded.")}):j(e,t)})))})),E.apply(this,arguments)}function A(){return(A=r((function*(e,t){return function(e){return e.reduce((function(e,t){return t.forEach((function(t,n){e[n]?t.element&&(e[n]=t):e[n]=t})),e}),[])}(yield Promise.all([S(e,t),v(e,t),w(e,t)]))}))).apply(this,arguments)}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkur/integration",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"description": "Merkur module for easy integration with other apps.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"module": "lib/index",
|
|
@@ -27,8 +27,7 @@
|
|
|
27
27
|
"preversion": "npm test",
|
|
28
28
|
"test": "jest --no-watchman -c ./jest.config.js",
|
|
29
29
|
"test:es:version": "es-check es11 ./lib/index.mjs --module && es-check es9 ./lib/index.es9.mjs --module && es-check es9 ./lib/index.es9.cjs --module",
|
|
30
|
-
"build": "rollup -c rollup.config.mjs"
|
|
31
|
-
"prepare": "npm run build"
|
|
30
|
+
"build": "rollup -c rollup.config.mjs"
|
|
32
31
|
},
|
|
33
32
|
"repository": {
|
|
34
33
|
"type": "git",
|
|
@@ -49,10 +48,10 @@
|
|
|
49
48
|
},
|
|
50
49
|
"homepage": "https://merkur.js.org/",
|
|
51
50
|
"devDependencies": {
|
|
52
|
-
"@merkur/core": "^0.
|
|
51
|
+
"@merkur/core": "^0.39.0"
|
|
53
52
|
},
|
|
54
53
|
"peerDependencies": {
|
|
55
54
|
"@merkur/core": "*"
|
|
56
55
|
},
|
|
57
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "8ad2c8b26246850ce6289502a8b05e882f80ce31"
|
|
58
57
|
}
|