@vouchfor/embeds 0.0.0-experiment.90d5928 → 0.0.0-experiment.90dc1dd

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. package/dist/es/browser-91e16108.js +733 -0
  2. package/dist/es/browser-91e16108.js.map +1 -0
  3. package/dist/es/embeds.js +12 -1499
  4. package/dist/es/embeds.js.map +1 -1
  5. package/dist/es/index-14de0872.js +16482 -0
  6. package/dist/es/index-14de0872.js.map +1 -0
  7. package/dist/es/src/components/DialogEmbed/DialogOverlay.d.ts +19 -0
  8. package/dist/es/src/components/DialogEmbed/DialogPortal.d.ts +35 -0
  9. package/dist/es/src/components/DialogEmbed/index.d.ts +36 -0
  10. package/dist/es/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
  11. package/dist/es/{components/Embed → src/components/PlayerEmbed}/controllers/fetcher.d.ts +5 -4
  12. package/dist/es/src/components/PlayerEmbed/controllers/tracking/index.d.ts +36 -0
  13. package/dist/es/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
  14. package/dist/es/{components/Embed → src/components/PlayerEmbed}/index.d.ts +28 -19
  15. package/dist/es/src/components/PlayerEmbed/tests/data.d.ts +3 -0
  16. package/dist/es/src/index.d.ts +2 -0
  17. package/dist/iife/dialog-embed/browser-8829205f.js +433 -0
  18. package/dist/iife/dialog-embed/browser-8829205f.js.map +1 -0
  19. package/dist/iife/dialog-embed/embed.iife.js +1722 -0
  20. package/dist/iife/dialog-embed/embed.iife.js.map +1 -0
  21. package/dist/iife/dialog-embed/embed.js +5 -0
  22. package/dist/iife/dialog-embed/embed.js.map +1 -0
  23. package/dist/iife/dialog-embed/index-64277c3d.js +33265 -0
  24. package/dist/iife/dialog-embed/index-64277c3d.js.map +1 -0
  25. package/dist/iife/dialog-embed/src/components/DialogEmbed/DialogOverlay.d.ts +19 -0
  26. package/dist/iife/dialog-embed/src/components/DialogEmbed/DialogPortal.d.ts +35 -0
  27. package/dist/iife/dialog-embed/src/components/DialogEmbed/index.d.ts +36 -0
  28. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
  29. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/fetcher.d.ts +14 -0
  30. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/tracking/index.d.ts +36 -0
  31. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
  32. package/dist/iife/dialog-embed/src/components/PlayerEmbed/index.d.ts +73 -0
  33. package/dist/iife/dialog-embed/src/components/PlayerEmbed/tests/data.d.ts +3 -0
  34. package/dist/iife/dialog-embed/src/index.d.ts +2 -0
  35. package/dist/iife/dialog-embed/src/utils/env.d.ts +12 -0
  36. package/dist/iife/dialog-embed/src/utils/events.d.ts +2 -0
  37. package/dist/iife/embeds.iife.js +642 -326
  38. package/dist/iife/embeds.iife.js.map +1 -1
  39. package/dist/iife/player-embed/browser-5865adfa.js +433 -0
  40. package/dist/iife/player-embed/browser-5865adfa.js.map +1 -0
  41. package/dist/iife/player-embed/embed.iife.js +1584 -0
  42. package/dist/iife/player-embed/embed.iife.js.map +1 -0
  43. package/dist/iife/player-embed/embed.js +5 -0
  44. package/dist/iife/player-embed/embed.js.map +1 -0
  45. package/dist/iife/player-embed/index-653d8046.js +32820 -0
  46. package/dist/iife/player-embed/index-653d8046.js.map +1 -0
  47. package/dist/iife/player-embed/src/components/DialogEmbed/DialogOverlay.d.ts +19 -0
  48. package/dist/iife/player-embed/src/components/DialogEmbed/DialogPortal.d.ts +35 -0
  49. package/dist/iife/player-embed/src/components/DialogEmbed/index.d.ts +36 -0
  50. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
  51. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/fetcher.d.ts +14 -0
  52. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/tracking/index.d.ts +36 -0
  53. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
  54. package/dist/iife/player-embed/src/components/PlayerEmbed/index.d.ts +73 -0
  55. package/dist/iife/player-embed/src/components/PlayerEmbed/tests/data.d.ts +3 -0
  56. package/dist/iife/player-embed/src/index.d.ts +2 -0
  57. package/dist/iife/player-embed/src/utils/env.d.ts +12 -0
  58. package/dist/iife/player-embed/src/utils/events.d.ts +2 -0
  59. package/package.json +13 -5
  60. package/src/components/DialogEmbed/Dialog.stories.ts +91 -0
  61. package/src/components/DialogEmbed/DialogOverlay.ts +131 -0
  62. package/src/components/DialogEmbed/DialogPortal.ts +126 -0
  63. package/src/components/DialogEmbed/index.ts +97 -0
  64. package/src/components/{Embed/Embed.stories.ts → PlayerEmbed/PlayerEmbed.stories.ts} +27 -14
  65. package/src/components/{Embed → PlayerEmbed}/controllers/event-forwarder.ts +6 -5
  66. package/src/components/PlayerEmbed/controllers/fetcher.ts +152 -0
  67. package/src/components/PlayerEmbed/controllers/tracking/index.ts +224 -0
  68. package/src/components/PlayerEmbed/controllers/tracking/utils.ts +95 -0
  69. package/src/components/{Embed → PlayerEmbed}/index.ts +78 -27
  70. package/src/components/PlayerEmbed/tests/PlayerEmbed.spec.ts +80 -0
  71. package/src/components/PlayerEmbed/tests/data.ts +183 -0
  72. package/src/index.ts +2 -1
  73. package/dist/es/components/Embed/controllers/tracking.d.ts +0 -28
  74. package/dist/es/index.d.ts +0 -1
  75. package/src/components/Embed/controllers/fetcher.ts +0 -113
  76. package/src/components/Embed/controllers/tracking.ts +0 -261
  77. /package/dist/es/{utils → src/utils}/env.d.ts +0 -0
  78. /package/dist/es/{utils → src/utils}/events.d.ts +0 -0
@@ -0,0 +1,733 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from "./index-14de0872.js";
8
+ function _mergeNamespaces(n, m) {
9
+ for (var i = 0; i < m.length; i++) {
10
+ const e = m[i];
11
+ if (typeof e !== "string" && !Array.isArray(e)) {
12
+ for (const k in e) {
13
+ if (k !== "default" && !(k in n)) {
14
+ const d = Object.getOwnPropertyDescriptor(e, k);
15
+ if (d) {
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: () => e[k]
19
+ });
20
+ }
21
+ }
22
+ }
23
+ }
24
+ }
25
+ return Object.freeze(Object.defineProperty(n, Symbol.toStringTag, { value: "Module" }));
26
+ }
27
+ function assertPath(path) {
28
+ if (typeof path !== "string") {
29
+ throw new TypeError("Path must be a string. Received " + JSON.stringify(path));
30
+ }
31
+ }
32
+ function normalizeStringPosix(path, allowAboveRoot) {
33
+ var res = "";
34
+ var lastSegmentLength = 0;
35
+ var lastSlash = -1;
36
+ var dots = 0;
37
+ var code;
38
+ for (var i = 0; i <= path.length; ++i) {
39
+ if (i < path.length)
40
+ code = path.charCodeAt(i);
41
+ else if (code === 47)
42
+ break;
43
+ else
44
+ code = 47;
45
+ if (code === 47) {
46
+ if (lastSlash === i - 1 || dots === 1)
47
+ ;
48
+ else if (lastSlash !== i - 1 && dots === 2) {
49
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
50
+ if (res.length > 2) {
51
+ var lastSlashIndex = res.lastIndexOf("/");
52
+ if (lastSlashIndex !== res.length - 1) {
53
+ if (lastSlashIndex === -1) {
54
+ res = "";
55
+ lastSegmentLength = 0;
56
+ } else {
57
+ res = res.slice(0, lastSlashIndex);
58
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
59
+ }
60
+ lastSlash = i;
61
+ dots = 0;
62
+ continue;
63
+ }
64
+ } else if (res.length === 2 || res.length === 1) {
65
+ res = "";
66
+ lastSegmentLength = 0;
67
+ lastSlash = i;
68
+ dots = 0;
69
+ continue;
70
+ }
71
+ }
72
+ if (allowAboveRoot) {
73
+ if (res.length > 0)
74
+ res += "/..";
75
+ else
76
+ res = "..";
77
+ lastSegmentLength = 2;
78
+ }
79
+ } else {
80
+ if (res.length > 0)
81
+ res += "/" + path.slice(lastSlash + 1, i);
82
+ else
83
+ res = path.slice(lastSlash + 1, i);
84
+ lastSegmentLength = i - lastSlash - 1;
85
+ }
86
+ lastSlash = i;
87
+ dots = 0;
88
+ } else if (code === 46 && dots !== -1) {
89
+ ++dots;
90
+ } else {
91
+ dots = -1;
92
+ }
93
+ }
94
+ return res;
95
+ }
96
+ function _format(sep, pathObject) {
97
+ var dir = pathObject.dir || pathObject.root;
98
+ var base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
99
+ if (!dir) {
100
+ return base;
101
+ }
102
+ if (dir === pathObject.root) {
103
+ return dir + base;
104
+ }
105
+ return dir + sep + base;
106
+ }
107
+ var posix = {
108
+ // path.resolve([from ...], to)
109
+ resolve: function resolve() {
110
+ var resolvedPath = "";
111
+ var resolvedAbsolute = false;
112
+ var cwd;
113
+ for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
114
+ var path;
115
+ if (i >= 0)
116
+ path = arguments[i];
117
+ else {
118
+ if (cwd === void 0)
119
+ cwd = process.cwd();
120
+ path = cwd;
121
+ }
122
+ assertPath(path);
123
+ if (path.length === 0) {
124
+ continue;
125
+ }
126
+ resolvedPath = path + "/" + resolvedPath;
127
+ resolvedAbsolute = path.charCodeAt(0) === 47;
128
+ }
129
+ resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
130
+ if (resolvedAbsolute) {
131
+ if (resolvedPath.length > 0)
132
+ return "/" + resolvedPath;
133
+ else
134
+ return "/";
135
+ } else if (resolvedPath.length > 0) {
136
+ return resolvedPath;
137
+ } else {
138
+ return ".";
139
+ }
140
+ },
141
+ normalize: function normalize(path) {
142
+ assertPath(path);
143
+ if (path.length === 0)
144
+ return ".";
145
+ var isAbsolute2 = path.charCodeAt(0) === 47;
146
+ var trailingSeparator = path.charCodeAt(path.length - 1) === 47;
147
+ path = normalizeStringPosix(path, !isAbsolute2);
148
+ if (path.length === 0 && !isAbsolute2)
149
+ path = ".";
150
+ if (path.length > 0 && trailingSeparator)
151
+ path += "/";
152
+ if (isAbsolute2)
153
+ return "/" + path;
154
+ return path;
155
+ },
156
+ isAbsolute: function isAbsolute(path) {
157
+ assertPath(path);
158
+ return path.length > 0 && path.charCodeAt(0) === 47;
159
+ },
160
+ join: function join() {
161
+ if (arguments.length === 0)
162
+ return ".";
163
+ var joined;
164
+ for (var i = 0; i < arguments.length; ++i) {
165
+ var arg = arguments[i];
166
+ assertPath(arg);
167
+ if (arg.length > 0) {
168
+ if (joined === void 0)
169
+ joined = arg;
170
+ else
171
+ joined += "/" + arg;
172
+ }
173
+ }
174
+ if (joined === void 0)
175
+ return ".";
176
+ return posix.normalize(joined);
177
+ },
178
+ relative: function relative(from, to) {
179
+ assertPath(from);
180
+ assertPath(to);
181
+ if (from === to)
182
+ return "";
183
+ from = posix.resolve(from);
184
+ to = posix.resolve(to);
185
+ if (from === to)
186
+ return "";
187
+ var fromStart = 1;
188
+ for (; fromStart < from.length; ++fromStart) {
189
+ if (from.charCodeAt(fromStart) !== 47)
190
+ break;
191
+ }
192
+ var fromEnd = from.length;
193
+ var fromLen = fromEnd - fromStart;
194
+ var toStart = 1;
195
+ for (; toStart < to.length; ++toStart) {
196
+ if (to.charCodeAt(toStart) !== 47)
197
+ break;
198
+ }
199
+ var toEnd = to.length;
200
+ var toLen = toEnd - toStart;
201
+ var length = fromLen < toLen ? fromLen : toLen;
202
+ var lastCommonSep = -1;
203
+ var i = 0;
204
+ for (; i <= length; ++i) {
205
+ if (i === length) {
206
+ if (toLen > length) {
207
+ if (to.charCodeAt(toStart + i) === 47) {
208
+ return to.slice(toStart + i + 1);
209
+ } else if (i === 0) {
210
+ return to.slice(toStart + i);
211
+ }
212
+ } else if (fromLen > length) {
213
+ if (from.charCodeAt(fromStart + i) === 47) {
214
+ lastCommonSep = i;
215
+ } else if (i === 0) {
216
+ lastCommonSep = 0;
217
+ }
218
+ }
219
+ break;
220
+ }
221
+ var fromCode = from.charCodeAt(fromStart + i);
222
+ var toCode = to.charCodeAt(toStart + i);
223
+ if (fromCode !== toCode)
224
+ break;
225
+ else if (fromCode === 47)
226
+ lastCommonSep = i;
227
+ }
228
+ var out = "";
229
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
230
+ if (i === fromEnd || from.charCodeAt(i) === 47) {
231
+ if (out.length === 0)
232
+ out += "..";
233
+ else
234
+ out += "/..";
235
+ }
236
+ }
237
+ if (out.length > 0)
238
+ return out + to.slice(toStart + lastCommonSep);
239
+ else {
240
+ toStart += lastCommonSep;
241
+ if (to.charCodeAt(toStart) === 47)
242
+ ++toStart;
243
+ return to.slice(toStart);
244
+ }
245
+ },
246
+ _makeLong: function _makeLong(path) {
247
+ return path;
248
+ },
249
+ dirname: function dirname(path) {
250
+ assertPath(path);
251
+ if (path.length === 0)
252
+ return ".";
253
+ var code = path.charCodeAt(0);
254
+ var hasRoot = code === 47;
255
+ var end = -1;
256
+ var matchedSlash = true;
257
+ for (var i = path.length - 1; i >= 1; --i) {
258
+ code = path.charCodeAt(i);
259
+ if (code === 47) {
260
+ if (!matchedSlash) {
261
+ end = i;
262
+ break;
263
+ }
264
+ } else {
265
+ matchedSlash = false;
266
+ }
267
+ }
268
+ if (end === -1)
269
+ return hasRoot ? "/" : ".";
270
+ if (hasRoot && end === 1)
271
+ return "//";
272
+ return path.slice(0, end);
273
+ },
274
+ basename: function basename(path, ext) {
275
+ if (ext !== void 0 && typeof ext !== "string")
276
+ throw new TypeError('"ext" argument must be a string');
277
+ assertPath(path);
278
+ var start = 0;
279
+ var end = -1;
280
+ var matchedSlash = true;
281
+ var i;
282
+ if (ext !== void 0 && ext.length > 0 && ext.length <= path.length) {
283
+ if (ext.length === path.length && ext === path)
284
+ return "";
285
+ var extIdx = ext.length - 1;
286
+ var firstNonSlashEnd = -1;
287
+ for (i = path.length - 1; i >= 0; --i) {
288
+ var code = path.charCodeAt(i);
289
+ if (code === 47) {
290
+ if (!matchedSlash) {
291
+ start = i + 1;
292
+ break;
293
+ }
294
+ } else {
295
+ if (firstNonSlashEnd === -1) {
296
+ matchedSlash = false;
297
+ firstNonSlashEnd = i + 1;
298
+ }
299
+ if (extIdx >= 0) {
300
+ if (code === ext.charCodeAt(extIdx)) {
301
+ if (--extIdx === -1) {
302
+ end = i;
303
+ }
304
+ } else {
305
+ extIdx = -1;
306
+ end = firstNonSlashEnd;
307
+ }
308
+ }
309
+ }
310
+ }
311
+ if (start === end)
312
+ end = firstNonSlashEnd;
313
+ else if (end === -1)
314
+ end = path.length;
315
+ return path.slice(start, end);
316
+ } else {
317
+ for (i = path.length - 1; i >= 0; --i) {
318
+ if (path.charCodeAt(i) === 47) {
319
+ if (!matchedSlash) {
320
+ start = i + 1;
321
+ break;
322
+ }
323
+ } else if (end === -1) {
324
+ matchedSlash = false;
325
+ end = i + 1;
326
+ }
327
+ }
328
+ if (end === -1)
329
+ return "";
330
+ return path.slice(start, end);
331
+ }
332
+ },
333
+ extname: function extname(path) {
334
+ assertPath(path);
335
+ var startDot = -1;
336
+ var startPart = 0;
337
+ var end = -1;
338
+ var matchedSlash = true;
339
+ var preDotState = 0;
340
+ for (var i = path.length - 1; i >= 0; --i) {
341
+ var code = path.charCodeAt(i);
342
+ if (code === 47) {
343
+ if (!matchedSlash) {
344
+ startPart = i + 1;
345
+ break;
346
+ }
347
+ continue;
348
+ }
349
+ if (end === -1) {
350
+ matchedSlash = false;
351
+ end = i + 1;
352
+ }
353
+ if (code === 46) {
354
+ if (startDot === -1)
355
+ startDot = i;
356
+ else if (preDotState !== 1)
357
+ preDotState = 1;
358
+ } else if (startDot !== -1) {
359
+ preDotState = -1;
360
+ }
361
+ }
362
+ if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
363
+ preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
364
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
365
+ return "";
366
+ }
367
+ return path.slice(startDot, end);
368
+ },
369
+ format: function format(pathObject) {
370
+ if (pathObject === null || typeof pathObject !== "object") {
371
+ throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
372
+ }
373
+ return _format("/", pathObject);
374
+ },
375
+ parse: function parse(path) {
376
+ assertPath(path);
377
+ var ret = { root: "", dir: "", base: "", ext: "", name: "" };
378
+ if (path.length === 0)
379
+ return ret;
380
+ var code = path.charCodeAt(0);
381
+ var isAbsolute2 = code === 47;
382
+ var start;
383
+ if (isAbsolute2) {
384
+ ret.root = "/";
385
+ start = 1;
386
+ } else {
387
+ start = 0;
388
+ }
389
+ var startDot = -1;
390
+ var startPart = 0;
391
+ var end = -1;
392
+ var matchedSlash = true;
393
+ var i = path.length - 1;
394
+ var preDotState = 0;
395
+ for (; i >= start; --i) {
396
+ code = path.charCodeAt(i);
397
+ if (code === 47) {
398
+ if (!matchedSlash) {
399
+ startPart = i + 1;
400
+ break;
401
+ }
402
+ continue;
403
+ }
404
+ if (end === -1) {
405
+ matchedSlash = false;
406
+ end = i + 1;
407
+ }
408
+ if (code === 46) {
409
+ if (startDot === -1)
410
+ startDot = i;
411
+ else if (preDotState !== 1)
412
+ preDotState = 1;
413
+ } else if (startDot !== -1) {
414
+ preDotState = -1;
415
+ }
416
+ }
417
+ if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
418
+ preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
419
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
420
+ if (end !== -1) {
421
+ if (startPart === 0 && isAbsolute2)
422
+ ret.base = ret.name = path.slice(1, end);
423
+ else
424
+ ret.base = ret.name = path.slice(startPart, end);
425
+ }
426
+ } else {
427
+ if (startPart === 0 && isAbsolute2) {
428
+ ret.name = path.slice(1, startDot);
429
+ ret.base = path.slice(1, end);
430
+ } else {
431
+ ret.name = path.slice(startPart, startDot);
432
+ ret.base = path.slice(startPart, end);
433
+ }
434
+ ret.ext = path.slice(startDot, end);
435
+ }
436
+ if (startPart > 0)
437
+ ret.dir = path.slice(0, startPart - 1);
438
+ else if (isAbsolute2)
439
+ ret.dir = "/";
440
+ return ret;
441
+ },
442
+ sep: "/",
443
+ delimiter: ":",
444
+ win32: null,
445
+ posix: null
446
+ };
447
+ posix.posix = posix;
448
+ var pathBrowserify = posix;
449
+ const { basename: basename2, extname: extname2 } = pathBrowserify;
450
+ class Format {
451
+ constructor() {
452
+ let isWeb = (() => typeof commonjsGlobal == "undefined")(), png = "image/png", jpg = "image/jpeg", jpeg = "image/jpeg", webp = "image/webp", pdf = "application/pdf", svg = "image/svg+xml";
453
+ Object.assign(this, {
454
+ toMime: this.toMime.bind(this),
455
+ fromMime: this.fromMime.bind(this),
456
+ expected: isWeb ? `"png", "jpg", or "webp"` : `"png", "jpg", "pdf", or "svg"`,
457
+ formats: isWeb ? { png, jpg, jpeg, webp } : { png, jpg, jpeg, pdf, svg },
458
+ mimes: isWeb ? { [png]: "png", [jpg]: "jpg", [webp]: "webp" } : { [png]: "png", [jpg]: "jpg", [pdf]: "pdf", [svg]: "svg" }
459
+ });
460
+ }
461
+ toMime(ext) {
462
+ return this.formats[(ext || "").replace(/^\./, "").toLowerCase()];
463
+ }
464
+ fromMime(mime) {
465
+ return this.mimes[mime];
466
+ }
467
+ }
468
+ function options$1(pages, { filename = "", extension = "", format: format2, page, quality, matte, density, outline, archive } = {}) {
469
+ var { fromMime, toMime, expected } = new Format(), archive = archive || "canvas", ext = format2 || extension.replace(/@\d+x$/i, "") || extname2(filename), format2 = fromMime(toMime(ext) || ext), mime = toMime(format2), pp = pages.length;
470
+ if (!ext)
471
+ throw new Error(`Cannot determine image format (use a filename extension or 'format' argument)`);
472
+ if (!format2)
473
+ throw new Error(`Unsupported file format "${ext}" (expected ${expected})`);
474
+ if (!pp)
475
+ throw new RangeError(`Canvas has no associated contexts (try calling getContext or newPage first)`);
476
+ let padding, isSequence, pattern = filename.replace(/{(\d*)}/g, (_, width) => {
477
+ isSequence = true;
478
+ width = parseInt(width, 10);
479
+ padding = isFinite(width) ? width : isFinite(padding) ? padding : -1;
480
+ return "{}";
481
+ });
482
+ let idx = page > 0 ? page - 1 : page < 0 ? pp + page : void 0;
483
+ if (isFinite(idx) && idx < 0 || idx >= pp)
484
+ throw new RangeError(
485
+ pp == 1 ? `Canvas only has a ‘page 1’ (${idx} is out of bounds)` : `Canvas has pages 1–${pp} (${idx} is out of bounds)`
486
+ );
487
+ pages = isFinite(idx) ? [pages[idx]] : isSequence || format2 == "pdf" ? pages : pages.slice(-1);
488
+ if (quality === void 0) {
489
+ quality = 0.92;
490
+ } else {
491
+ if (typeof quality != "number" || !isFinite(quality) || quality < 0 || quality > 1) {
492
+ throw new TypeError("The quality option must be an number in the 0.0–1.0 range");
493
+ }
494
+ }
495
+ if (density === void 0) {
496
+ let m = (extension || basename2(filename, ext)).match(/@(\d+)x$/i);
497
+ density = m ? parseInt(m[1], 10) : 1;
498
+ } else if (typeof density != "number" || !Number.isInteger(density) || density < 1) {
499
+ throw new TypeError("The density option must be a non-negative integer");
500
+ }
501
+ if (outline === void 0) {
502
+ outline = true;
503
+ } else if (format2 == "svg") {
504
+ outline = !!outline;
505
+ }
506
+ return { filename, pattern, format: format2, mime, pages, padding, quality, matte, density, outline, archive };
507
+ }
508
+ class Crc32 {
509
+ static for(data) {
510
+ return new Crc32().append(data).get();
511
+ }
512
+ constructor() {
513
+ this.crc = -1;
514
+ }
515
+ get() {
516
+ return ~this.crc;
517
+ }
518
+ append(data) {
519
+ var crc = this.crc | 0, table = this.table;
520
+ for (var offset = 0, len = data.length | 0; offset < len; offset++) {
521
+ crc = crc >>> 8 ^ table[(crc ^ data[offset]) & 255];
522
+ }
523
+ this.crc = crc;
524
+ return this;
525
+ }
526
+ }
527
+ Crc32.prototype.table = (() => {
528
+ var i, j, t, table = [];
529
+ for (i = 0; i < 256; i++) {
530
+ t = i;
531
+ for (j = 0; j < 8; j++) {
532
+ t = t & 1 ? t >>> 1 ^ 3988292384 : t >>> 1;
533
+ }
534
+ table[i] = t;
535
+ }
536
+ return table;
537
+ })();
538
+ function calloc(size) {
539
+ let array = new Uint8Array(size), view = new DataView(array.buffer), buf = {
540
+ array,
541
+ view,
542
+ size,
543
+ set8(at, to) {
544
+ view.setUint8(at, to);
545
+ return buf;
546
+ },
547
+ set16(at, to) {
548
+ view.setUint16(at, to, true);
549
+ return buf;
550
+ },
551
+ set32(at, to) {
552
+ view.setUint32(at, to, true);
553
+ return buf;
554
+ },
555
+ bytes(at, to) {
556
+ array.set(to, at);
557
+ return buf;
558
+ }
559
+ };
560
+ return buf;
561
+ }
562
+ const _Zip = class _Zip {
563
+ constructor(directory) {
564
+ let now = /* @__PURE__ */ new Date();
565
+ Object.assign(this, {
566
+ directory,
567
+ offset: 0,
568
+ files: [],
569
+ time: (now.getHours() << 6 | now.getMinutes()) << 5 | now.getSeconds() / 2,
570
+ date: (now.getFullYear() - 1980 << 4 | now.getMonth() + 1) << 5 | now.getDate()
571
+ });
572
+ this.add(directory);
573
+ }
574
+ async add(filename, blob) {
575
+ let folder = !blob, name = _Zip.encoder.encode(`${this.directory}/${folder ? "" : filename}`), data = new Uint8Array(folder ? 0 : await blob.arrayBuffer()), preamble = 30 + name.length, descriptor = preamble + data.length, postamble = 16, { offset } = this;
576
+ let header = calloc(26).set32(0, 134742036).set16(6, this.time).set16(8, this.date).set32(10, Crc32.for(data)).set32(14, data.length).set32(18, data.length).set16(22, name.length);
577
+ offset += preamble;
578
+ let payload = calloc(preamble + data.length + postamble).set32(0, 67324752).bytes(4, header.array).bytes(30, name).bytes(preamble, data);
579
+ offset += data.length;
580
+ payload.set32(descriptor, 134695760).bytes(descriptor + 4, header.array.slice(10, 22));
581
+ offset += postamble;
582
+ this.files.push({ offset, folder, name, header, payload });
583
+ this.offset = offset;
584
+ }
585
+ toBuffer() {
586
+ let length = this.files.reduce((len, { name: name2 }) => 46 + name2.length + len, 0), cdr = calloc(length + 22), index = 0;
587
+ for (var { offset, name, header, folder } of this.files) {
588
+ cdr.set32(index, 33639248).set16(index + 4, 20).bytes(index + 6, header.array).set8(index + 38, folder ? 16 : 0).set32(index + 42, offset).bytes(index + 46, name);
589
+ index += 46 + name.length;
590
+ }
591
+ cdr.set32(index, 101010256).set16(index + 8, this.files.length).set16(index + 10, this.files.length).set32(index + 12, length).set32(index + 16, this.offset);
592
+ let output = new Uint8Array(this.offset + cdr.size), cursor = 0;
593
+ for (var { payload } of this.files) {
594
+ output.set(payload.array, cursor);
595
+ cursor += payload.size;
596
+ }
597
+ output.set(cdr.array, cursor);
598
+ return output;
599
+ }
600
+ get blob() {
601
+ return new Blob([this.toBuffer()], { type: "application/zip" });
602
+ }
603
+ };
604
+ __publicField(_Zip, "encoder", new TextEncoder());
605
+ let Zip = _Zip;
606
+ const asBlob = (canvas, mime, quality, matte) => {
607
+ if (matte) {
608
+ let { width, height } = canvas, comp = Object.assign(document.createElement("canvas"), { width, height }), ctx = comp.getContext("2d");
609
+ ctx.fillStyle = matte;
610
+ ctx.fillRect(0, 0, width, height);
611
+ ctx.drawImage(canvas, 0, 0);
612
+ canvas = comp;
613
+ }
614
+ return new Promise((res, rej) => canvas.toBlob(res, mime, quality));
615
+ };
616
+ const asBuffer$1 = (...args) => asBlob(...args).then((b) => b.arrayBuffer());
617
+ const asDownload$1 = async (canvas, mime, quality, matte, filename) => {
618
+ _download(filename, await asBlob(canvas, mime, quality, matte));
619
+ };
620
+ const asZipDownload$1 = async (pages, mime, quality, matte, archive, pattern, padding) => {
621
+ let filenames = (i) => pattern.replace("{}", String(i + 1).padStart(padding, "0")), folder = basename2(archive, ".zip") || "archive", zip = new Zip(folder);
622
+ await Promise.all(pages.map(async (page, i) => {
623
+ let filename = filenames(i);
624
+ await zip.add(filename, await asBlob(page, mime, quality, matte));
625
+ }));
626
+ _download(`${folder}.zip`, zip.blob);
627
+ };
628
+ const _download = (filename, blob) => {
629
+ const href = window.URL.createObjectURL(blob), link = document.createElement("a");
630
+ link.style.display = "none";
631
+ link.href = href;
632
+ link.setAttribute("download", filename);
633
+ if (typeof link.download === "undefined") {
634
+ link.setAttribute("target", "_blank");
635
+ }
636
+ document.body.appendChild(link);
637
+ link.click();
638
+ document.body.removeChild(link);
639
+ setTimeout(() => window.URL.revokeObjectURL(href), 100);
640
+ };
641
+ const atScale$1 = (pages, density, matte) => pages.map((page) => {
642
+ if (density == 1 && !matte)
643
+ return page.canvas;
644
+ let scaled = document.createElement("canvas"), ctx = scaled.getContext("2d"), src = page.canvas ? page.canvas : page;
645
+ scaled.width = src.width * density;
646
+ scaled.height = src.height * density;
647
+ if (matte) {
648
+ ctx.fillStyle = matte;
649
+ ctx.fillRect(0, 0, scaled.width, scaled.height);
650
+ }
651
+ ctx.scale(density, density);
652
+ ctx.drawImage(src, 0, 0);
653
+ return scaled;
654
+ });
655
+ var io = { asBuffer: asBuffer$1, asDownload: asDownload$1, asZipDownload: asZipDownload$1, atScale: atScale$1, options: options$1 };
656
+ const { asBuffer, asDownload, asZipDownload, atScale, options } = io;
657
+ const _toURL_ = Symbol.for("toDataURL");
658
+ const loadImage = (src) => {
659
+ let img = Object.assign(new Image(), { crossOrigin: "Anonymous", src });
660
+ return img.decode().then(() => img);
661
+ };
662
+ class Canvas {
663
+ constructor(width, height) {
664
+ let elt = document.createElement("canvas"), pages = [];
665
+ Object.defineProperty(elt, "async", { value: true, writable: false, enumerable: true });
666
+ for (var [prop, get] of Object.entries({
667
+ png: () => asBuffer(elt, "image/png"),
668
+ jpg: () => asBuffer(elt, "image/jpeg"),
669
+ pages: () => pages.concat(elt).map((c) => c.getContext("2d"))
670
+ }))
671
+ Object.defineProperty(elt, prop, { get });
672
+ return Object.assign(elt, {
673
+ width,
674
+ height,
675
+ newPage(...size) {
676
+ var { width: width2, height: height2 } = elt, page = Object.assign(document.createElement("canvas"), { width: width2, height: height2 });
677
+ page.getContext("2d").drawImage(elt, 0, 0);
678
+ pages.push(page);
679
+ var [width2, height2] = size.length ? size : [width2, height2];
680
+ return Object.assign(elt, { width: width2, height: height2 }).getContext("2d");
681
+ },
682
+ saveAs(filename, args) {
683
+ args = typeof args == "number" ? { quality: args } : args;
684
+ let opts = options(this.pages, { filename, ...args }), { pattern, padding, mime, quality, matte, density, archive } = opts, pages2 = atScale(opts.pages, density);
685
+ return padding == void 0 ? asDownload(pages2[0], mime, quality, matte, filename) : asZipDownload(pages2, mime, quality, matte, archive, pattern, padding);
686
+ },
687
+ toBuffer(extension = "png", args = {}) {
688
+ args = typeof args == "number" ? { quality: args } : args;
689
+ let opts = options(this.pages, { extension, ...args }), { mime, quality, matte, pages: pages2, density } = opts, canvas = atScale(pages2, density, matte)[0];
690
+ return asBuffer(canvas, mime, quality, matte);
691
+ },
692
+ [_toURL_]: elt.toDataURL.bind(elt),
693
+ toDataURL(extension = "png", args = {}) {
694
+ args = typeof args == "number" ? { quality: args } : args;
695
+ let opts = options(this.pages, { extension, ...args }), { mime, quality, matte, pages: pages2, density } = opts, canvas = atScale(pages2, density, matte)[0], url = canvas[canvas === elt ? _toURL_ : "toDataURL"](mime, quality);
696
+ return Promise.resolve(url);
697
+ }
698
+ });
699
+ }
700
+ }
701
+ const {
702
+ CanvasRenderingContext2D,
703
+ CanvasGradient,
704
+ CanvasPattern,
705
+ Image,
706
+ ImageData,
707
+ Path2D,
708
+ DOMMatrix,
709
+ DOMRect,
710
+ DOMPoint
711
+ } = window;
712
+ var browser = {
713
+ Canvas,
714
+ loadImage,
715
+ CanvasRenderingContext2D,
716
+ CanvasGradient,
717
+ CanvasPattern,
718
+ Image,
719
+ ImageData,
720
+ Path2D,
721
+ DOMMatrix,
722
+ DOMRect,
723
+ DOMPoint
724
+ };
725
+ const browser$1 = /* @__PURE__ */ getDefaultExportFromCjs(browser);
726
+ const browser$2 = /* @__PURE__ */ _mergeNamespaces({
727
+ __proto__: null,
728
+ default: browser$1
729
+ }, [browser]);
730
+ export {
731
+ browser$2 as b
732
+ };
733
+ //# sourceMappingURL=browser-91e16108.js.map