@plotdb/lotion 0.2.0 → 0.4.2

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/vector.js ADDED
@@ -0,0 +1,2116 @@
1
+ (function(){
2
+ (function(){
3
+ var lotion, ref$, props, skip, i$, len$, s, c, textProps, unsupported, b64Bytes, b64, svgUri, fixShadow, fixUri, box, svgProps, svgSrc, bakeTransform, convert, fontCache, unquote, parseRange, parseSrc, faceOf, facesInText, facesInSheet, allFaces, getFaces, loadFont, hb, getHb, WGHT, subset, clamp, weightRank, fontsFor, render, makeCtx, prepare, vector, IDENT, mul, parseMatrix, motionMatrix, svgMatrix, viewboxMatrix, blurOf, simplify, fmt, pct, SVGGROUP, SVGSTATIC, NUMATTRS, NUMPROPS, LEAFSTYLE, POSATTRS, NUMERIC, xml, styleDiff, leaf, groupAttrs, splitTop, rgba, maskOf, clipOf, sample, drawOn, PAD, draw, attrTol, compose, animate;
4
+ lotion = window.lotion;
5
+ ref$ = lotion.libs;
6
+ ref$.satori = 'https://cdn.jsdelivr.net/npm/satori@0.36.0/+esm';
7
+ ref$.woff2 = 'https://cdn.jsdelivr.net/npm/woff2-encoder@2.0.0/dist/decompress.js';
8
+ ref$.hbsubset = 'https://cdn.jsdelivr.net/npm/harfbuzzjs@1.6.3/dist/harfbuzz-subset.wasm';
9
+ props = ['color', 'fontFamily', 'fontSize', 'fontWeight', 'fontStyle', 'lineHeight', 'letterSpacing', 'textAlign', 'whiteSpace', 'wordBreak', 'textTransform', 'textShadow', 'textIndent', 'backgroundColor', 'backgroundImage', 'backgroundPosition', 'backgroundSize', 'backgroundRepeat', 'backgroundClip', 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'borderTopStyle', 'borderRightStyle', 'borderBottomStyle', 'borderLeftStyle', 'borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'boxShadow', 'opacity', 'filter', 'clipPath', 'overflow', 'zIndex', 'transform', 'transformOrigin', 'maskImage', 'maskPosition', 'maskSize', 'maskRepeat'];
10
+ skip = {
11
+ textShadow: 'none',
12
+ textIndent: '0px',
13
+ textTransform: 'none',
14
+ backgroundColor: 'rgba(0, 0, 0, 0)',
15
+ backgroundImage: 'none',
16
+ backgroundPosition: '0% 0%',
17
+ backgroundSize: 'auto',
18
+ backgroundRepeat: 'repeat',
19
+ backgroundClip: 'border-box',
20
+ boxShadow: 'none',
21
+ opacity: '1',
22
+ filter: 'none',
23
+ clipPath: 'none',
24
+ overflow: 'visible',
25
+ zIndex: 'auto',
26
+ transform: 'none',
27
+ maskImage: 'none',
28
+ maskPosition: '0% 0%',
29
+ maskSize: 'auto',
30
+ maskRepeat: 'repeat',
31
+ lineHeight: 'normal',
32
+ letterSpacing: 'normal'
33
+ };
34
+ for (i$ = 0, len$ = (ref$ = ['Top', 'Right', 'Bottom', 'Left']).length; i$ < len$; ++i$) {
35
+ s = ref$[i$];
36
+ skip["border" + s + "Width"] = '0px';
37
+ skip["border" + s + "Style"] = 'none';
38
+ skip["padding" + s] = '0px';
39
+ }
40
+ for (i$ = 0, len$ = (ref$ = ['TopLeft', 'TopRight', 'BottomRight', 'BottomLeft']).length; i$ < len$; ++i$) {
41
+ c = ref$[i$];
42
+ skip["border" + c + "Radius"] = '0px';
43
+ }
44
+ textProps = ['color', 'fontFamily', 'fontSize', 'fontWeight', 'fontStyle', 'lineHeight', 'letterSpacing', 'textAlign', 'whiteSpace', 'wordBreak', 'textTransform', 'textShadow', 'textIndent'];
45
+ unsupported = {
46
+ backdropFilter: 'none',
47
+ textDecorationLine: 'none'
48
+ };
49
+ b64Bytes = function(buf){
50
+ var bytes, bin, i$, to$, i;
51
+ bytes = new Uint8Array(buf);
52
+ bin = '';
53
+ for (i$ = 0, to$ = bytes.length; i$ < to$; i$ += 0x8000) {
54
+ i = i$;
55
+ bin += String.fromCharCode.apply(null, bytes.subarray(i, i + 0x8000));
56
+ }
57
+ return btoa(bin);
58
+ };
59
+ b64 = function(str){
60
+ return b64Bytes(new TextEncoder().encode(str));
61
+ };
62
+ svgUri = function(xml){
63
+ return "data:image/svg+xml;base64," + b64(xml);
64
+ };
65
+ fixShadow = function(v){
66
+ var parts, ref$, depth, cur, i$, len$, ch;
67
+ parts = [];
68
+ ref$ = [0, ''], depth = ref$[0], cur = ref$[1];
69
+ for (i$ = 0, len$ = v.length; i$ < len$; ++i$) {
70
+ ch = v[i$];
71
+ if (ch === '(') {
72
+ depth++;
73
+ }
74
+ if (ch === ')') {
75
+ depth--;
76
+ }
77
+ if (ch === ',' && depth === 0) {
78
+ parts.push(cur.trim());
79
+ cur = '';
80
+ } else {
81
+ cur += ch;
82
+ }
83
+ }
84
+ parts.push(cur.trim());
85
+ return parts.map(function(p){
86
+ var m;
87
+ if (!(m = /^((?:rgba?|hsla?|color)\([^)]*\)|#[0-9a-f]+|[a-z]+)\s+(.*)$/i.exec(p)) || m[1] === 'inset') {
88
+ return p;
89
+ }
90
+ return m[2] + " " + m[1];
91
+ }).join(', ');
92
+ };
93
+ fixUri = function(v){
94
+ return v.replace(/url\("data:image\/svg\+xml(?:;charset=[^,;]+)?(?:;utf8)?,([^"]*)"\)/g, function(m, d){
95
+ var e;
96
+ return "url(\"" + svgUri((function(){
97
+ try {
98
+ return decodeURIComponent(d);
99
+ } catch (e$) {
100
+ e = e$;
101
+ return d;
102
+ }
103
+ }())) + "\")";
104
+ });
105
+ };
106
+ box = function(el, parent, cs, ctx){
107
+ var x, y, ref$, w, h;
108
+ if (el.offsetWidth != null) {
109
+ x = el.offsetLeft;
110
+ y = el.offsetTop;
111
+ if (el.offsetParent !== parent && parent.offsetParent === el.offsetParent) {
112
+ x -= parent.offsetLeft + parent.clientLeft;
113
+ y -= parent.offsetTop + parent.clientTop;
114
+ }
115
+ return [x, y, el.offsetWidth, el.offsetHeight];
116
+ }
117
+ ref$ = [parseFloat(cs.width) || 0, parseFloat(cs.height) || 0], w = ref$[0], h = ref$[1];
118
+ if ((ref$ = cs.position) === 'absolute' || ref$ === 'fixed') {
119
+ return [parseFloat(cs.left) || 0, parseFloat(cs.top) || 0, w, h];
120
+ }
121
+ ctx.warn("<" + el.tagName.toLowerCase() + "> not absolutely positioned: placed at its parent's origin");
122
+ return [0, 0, w, h];
123
+ };
124
+ svgProps = ['font-family', 'font-size', 'font-weight', 'font-style', 'letter-spacing', 'text-anchor', 'dominant-baseline', 'fill', 'fill-opacity', 'fill-rule', 'stroke', 'stroke-width', 'stroke-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'paint-order', 'opacity', 'visibility', 'display', 'filter', 'mask', 'clip-path', 'color'];
125
+ svgSrc = function(el, w, h, ctx, node){
126
+ var c, srcs, dsts, texts, ids, i$, len$, d, j$, ref$, len1$, a, re, m, defs;
127
+ c = el.cloneNode(true);
128
+ c.setAttribute('width', w);
129
+ c.setAttribute('height', h);
130
+ if (!c.getAttribute('viewBox')) {
131
+ c.setAttribute('viewBox', "0 0 " + w + " " + h);
132
+ }
133
+ c.removeAttribute('style');
134
+ srcs = [el].concat(Array.from(el.querySelectorAll('*')));
135
+ dsts = [c].concat(Array.from(c.querySelectorAll('*')));
136
+ texts = [];
137
+ srcs.map(function(e, i){
138
+ var d, cs, pcs, decl, i$, ref$, len$, k, v, f;
139
+ d = dsts[i];
140
+ cs = getComputedStyle(e);
141
+ pcs = i === 0
142
+ ? null
143
+ : getComputedStyle(e.parentNode);
144
+ decl = [];
145
+ for (i$ = 0, len$ = (ref$ = svgProps).length; i$ < len$; ++i$) {
146
+ k = ref$[i$];
147
+ v = cs.getPropertyValue(k);
148
+ if (pcs && pcs.getPropertyValue(k) === v) {
149
+ continue;
150
+ }
151
+ if (i === 0 && (k === 'opacity' || k === 'visibility' || k === 'display' || k === 'filter' || k === 'mask' || k === 'clip-path')) {
152
+ continue;
153
+ }
154
+ decl.push(k + ":" + v);
155
+ }
156
+ if (decl.length) {
157
+ d.setAttribute('style', decl.join(';'));
158
+ }
159
+ if (((ref$ = e.tagName.toLowerCase()) === 'text' || ref$ === 'tspan' || ref$ === 'textpath') && !e.querySelector('tspan, textPath')) {
160
+ f = {};
161
+ ctx.text(cs, e.textContent, f);
162
+ return texts.push([d, f]);
163
+ }
164
+ });
165
+ ids = new Set;
166
+ for (i$ = 0, len$ = dsts.length; i$ < len$; ++i$) {
167
+ d = dsts[i$];
168
+ for (j$ = 0, len1$ = (ref$ = Array.from(d.attributes)).length; j$ < len1$; ++j$) {
169
+ a = ref$[j$];
170
+ re = /url\(\s*['"]?#([^'")\s]+)['"]?\s*\)|^#(.+)$/g;
171
+ while (m = re.exec(a.value)) {
172
+ ids.add(m[1] || m[2]);
173
+ }
174
+ }
175
+ }
176
+ defs = null;
177
+ ids.forEach(function(id){
178
+ var src;
179
+ if (c.querySelector("[id=\"" + CSS.escape(id) + "\"]")) {
180
+ return;
181
+ }
182
+ if (!(src = document.getElementById(id))) {
183
+ return;
184
+ }
185
+ if (!defs) {
186
+ defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
187
+ c.insertBefore(defs, c.firstChild);
188
+ }
189
+ return defs.appendChild(src.cloneNode(true));
190
+ });
191
+ ctx.later(function(fonts){
192
+ var names, i$, ref$, len$, ref1$, d, f, st, j$, len1$, n, faces;
193
+ names = new Set;
194
+ for (i$ = 0, len$ = (ref$ = texts).length; i$ < len$; ++i$) {
195
+ ref1$ = ref$[i$], d = ref1$[0], f = ref1$[1];
196
+ if (!f.fontFamily) {
197
+ continue;
198
+ }
199
+ st = d.getAttribute('style') || '';
200
+ d.setAttribute('style', st + ";font-family:" + f.fontFamily);
201
+ for (j$ = 0, len1$ = (ref1$ = f.fontFamily.split(',')).length; j$ < len1$; ++j$) {
202
+ n = ref1$[j$];
203
+ names.add(n.trim().replace(/'/g, ''));
204
+ }
205
+ }
206
+ faces = fonts.filter(function(it){
207
+ return names.has(it.name);
208
+ }).map(function(f){
209
+ return ("@font-face{font-family:'" + f.name + "';font-weight:" + f.weight + ";font-style:" + f.style + ";") + ("src:url(data:font/ttf;base64," + b64Bytes(f.data) + ") format('truetype')}");
210
+ });
211
+ if (faces.length) {
212
+ st = document.createElementNS('http://www.w3.org/2000/svg', 'style');
213
+ st.textContent = faces.join('');
214
+ c.insertBefore(st, c.firstChild);
215
+ }
216
+ return node.props.src = svgUri(new XMLSerializer().serializeToString(c));
217
+ });
218
+ return "pending:" + new XMLSerializer().serializeToString(c);
219
+ };
220
+ bakeTransform = function(node, ctx){
221
+ var st, m, v;
222
+ st = node.props.style;
223
+ if (!(st.maskImage || st.clipPath)) {
224
+ return node;
225
+ }
226
+ if (!st.transform) {
227
+ return node;
228
+ }
229
+ m = /^matrix\(([^)]+)\)$/.exec(st.transform);
230
+ v = m ? m[1].split(',').map(function(it){
231
+ return +it;
232
+ }) : null;
233
+ if (v && v[0] === 1 && v[1] === 0 && v[2] === 0 && v[3] === 1) {
234
+ st.left += v[4];
235
+ st.top += v[5];
236
+ delete st.transform;
237
+ delete st.transformOrigin;
238
+ } else {
239
+ ctx.warn("mask / clip-path with a non-translation transform: misplaced");
240
+ }
241
+ return node;
242
+ };
243
+ convert = function(el, ctx, depth, o){
244
+ var root, cs, tag, ref$, x, y, w, h, hidden, k, v, blend, kids, texts, elems, style, i$, len$, s, node, children, text, jc, c, that;
245
+ depth == null && (depth = 0);
246
+ o == null && (o = {});
247
+ root = depth === 0;
248
+ cs = getComputedStyle(el);
249
+ if (cs.display === 'none' || +cs.opacity === 0) {
250
+ return null;
251
+ }
252
+ tag = el.tagName.toLowerCase();
253
+ ref$ = box(el, el.parentNode, cs, ctx), x = ref$[0], y = ref$[1], w = ref$[2], h = ref$[3];
254
+ hidden = cs.visibility !== 'visible';
255
+ for (k in ref$ = unsupported) {
256
+ v = ref$[k];
257
+ if (cs[k] && cs[k] !== v) {
258
+ ctx.warn(k + ": " + cs[k]);
259
+ }
260
+ }
261
+ blend = cs.mixBlendMode !== 'normal' ? cs.mixBlendMode : null;
262
+ if (blend && depth !== 1) {
263
+ ctx.warn("mixBlendMode on a nested element: " + blend + " ignored");
264
+ }
265
+ kids = Array.from(el.childNodes);
266
+ texts = kids.filter(function(n){
267
+ return n.nodeType === 3 && n.textContent.trim();
268
+ });
269
+ elems = kids.filter(function(n){
270
+ return n.nodeType === 1;
271
+ });
272
+ if (texts.length && elems.length) {
273
+ ctx.warn("mixed text and elements in <" + tag + ">");
274
+ }
275
+ style = {
276
+ display: 'flex',
277
+ boxSizing: 'border-box',
278
+ width: w,
279
+ height: h
280
+ };
281
+ if (!root) {
282
+ style.position = 'absolute';
283
+ style.left = x;
284
+ style.top = y;
285
+ }
286
+ for (i$ = 0, len$ = (ref$ = props).length; i$ < len$; ++i$) {
287
+ k = ref$[i$];
288
+ if (!texts.length && in$(k, textProps)) {
289
+ continue;
290
+ }
291
+ v = cs[k];
292
+ if (!v || skip[k] === v) {
293
+ continue;
294
+ }
295
+ style[k] = /data:image\/svg/.test(v)
296
+ ? fixUri(v)
297
+ : k === 'boxShadow' || k === 'textShadow' ? fixShadow(v) : v;
298
+ }
299
+ for (i$ = 0, len$ = (ref$ = ['Top', 'Right', 'Bottom', 'Left']).length; i$ < len$; ++i$) {
300
+ s = ref$[i$];
301
+ if (!style["border" + s + "Width"]) {
302
+ delete style["border" + s + "Color"];
303
+ }
304
+ }
305
+ if (style.overflow) {
306
+ style.overflow = 'hidden';
307
+ }
308
+ if (style.transform) {
309
+ style.transformOrigin = cs.transformOrigin;
310
+ } else {
311
+ delete style.transformOrigin;
312
+ }
313
+ if (hidden) {
314
+ for (i$ = 0, len$ = (ref$ = ['backgroundColor', 'backgroundImage', 'boxShadow', 'color', 'textShadow']).length; i$ < len$; ++i$) {
315
+ k = ref$[i$];
316
+ delete style[k];
317
+ }
318
+ for (i$ = 0, len$ = (ref$ = ['Top', 'Right', 'Bottom', 'Left']).length; i$ < len$; ++i$) {
319
+ s = ref$[i$];
320
+ delete style["border" + s + "Width"];
321
+ }
322
+ }
323
+ if (tag === 'img' || tag === 'canvas' || tag === 'svg') {
324
+ if (hidden) {
325
+ return null;
326
+ }
327
+ node = {
328
+ blend: depth === 1 ? blend : null,
329
+ type: 'img',
330
+ props: {
331
+ width: w,
332
+ height: h,
333
+ style: style
334
+ }
335
+ };
336
+ node.props.src = (function(){
337
+ switch (tag) {
338
+ case 'img':
339
+ return el.currentSrc || el.src;
340
+ case 'canvas':
341
+ return el.toDataURL();
342
+ case 'svg':
343
+ return svgSrc(el, w, h, ctx, node);
344
+ }
345
+ }());
346
+ return o.nobake
347
+ ? node
348
+ : bakeTransform(node, ctx);
349
+ }
350
+ children = [];
351
+ if (texts.length && !hidden) {
352
+ text = texts.map(function(it){
353
+ return it.textContent;
354
+ }).join('');
355
+ ctx.text(cs, text, style);
356
+ children.push(text);
357
+ jc = {
358
+ center: 'center',
359
+ right: 'flex-end',
360
+ end: 'flex-end'
361
+ }[cs.textAlign];
362
+ if (jc && !elems.length) {
363
+ style.justifyContent = jc;
364
+ }
365
+ }
366
+ if (!o.own) {
367
+ for (i$ = 0, len$ = elems.length; i$ < len$; ++i$) {
368
+ c = elems[i$];
369
+ if (that = convert(c, ctx, depth + 1)) {
370
+ children.push(that);
371
+ }
372
+ }
373
+ }
374
+ node = {
375
+ type: 'div',
376
+ props: {
377
+ style: style,
378
+ children: children
379
+ }
380
+ };
381
+ if (blend && depth === 1) {
382
+ node.blend = blend;
383
+ }
384
+ if (o.nobake) {
385
+ return node;
386
+ } else {
387
+ return bakeTransform(node, ctx);
388
+ }
389
+ };
390
+ fontCache = {};
391
+ unquote = function(s){
392
+ return s.trim().replace(/^["']|["']$/g, '');
393
+ };
394
+ parseRange = function(s){
395
+ if (!s) {
396
+ return [[0, 0x10FFFF]];
397
+ }
398
+ return s.split(',').map(function(r){
399
+ var ref$, a, b;
400
+ r = r.trim().replace(/^u\+/i, '');
401
+ if (/\?/.test(r)) {
402
+ return [parseInt(r.replace(/\?/g, '0'), 16), parseInt(r.replace(/\?/g, 'F'), 16)];
403
+ }
404
+ ref$ = r.split('-'), a = ref$[0], b = ref$[1];
405
+ return [parseInt(a, 16), parseInt(b || a, 16)];
406
+ });
407
+ };
408
+ parseSrc = function(s, base){
409
+ var ret, re, m;
410
+ ret = [];
411
+ re = /url\(\s*(['"]?)([^'")]+)\1\s*\)\s*(?:format\(\s*['"]?([^'")]+)['"]?\s*\))?/g;
412
+ while (m = re.exec(s)) {
413
+ try {
414
+ ret.push({
415
+ url: new URL(m[2], base).href,
416
+ format: (m[3] || m[2].split('.').pop()).toLowerCase()
417
+ });
418
+ } catch (e$) {}
419
+ }
420
+ return ret;
421
+ };
422
+ faceOf = function(get, base){
423
+ return {
424
+ family: unquote(get('font-family')),
425
+ weight: (get('font-weight') || '400').split(/\s+/).map(function(it){
426
+ if (it === 'normal') {
427
+ return 400;
428
+ } else if (it === 'bold') {
429
+ return 700;
430
+ } else {
431
+ return +it;
432
+ }
433
+ }),
434
+ style: get('font-style') || 'normal',
435
+ range: parseRange(get('unicode-range')),
436
+ src: parseSrc(get('src'), base)
437
+ };
438
+ };
439
+ facesInText = function(text, base){
440
+ return (text.match(/@font-face\s*\{[^}]*\}/g) || []).map(function(b){
441
+ return faceOf(function(k){
442
+ return (new RegExp("(?:^|[{;\\s])" + k + "\\s*:\\s*([^;}]+)").exec(b) || [])[1];
443
+ }, base);
444
+ });
445
+ };
446
+ facesInSheet = function(sheet){
447
+ var base, rules, e;
448
+ base = sheet.href || location.href;
449
+ try {
450
+ rules = sheet.cssRules;
451
+ } catch (e$) {
452
+ e = e$;
453
+ rules = null;
454
+ }
455
+ if (!rules) {
456
+ return sheet.href
457
+ ? fetch(sheet.href).then(function(r){
458
+ return r.text();
459
+ }).then(function(t){
460
+ return facesInText(t, base);
461
+ })['catch'](function(){
462
+ return [];
463
+ })
464
+ : Promise.resolve([]);
465
+ }
466
+ return Promise.all(Array.from(rules).map(function(r){
467
+ if (r.styleSheet) {
468
+ return facesInSheet(r.styleSheet);
469
+ }
470
+ if (r.type === 5) {
471
+ return [faceOf(function(k){
472
+ return r.style.getPropertyValue(k);
473
+ }, base)];
474
+ }
475
+ return [];
476
+ })).then(function(l){
477
+ return l.flat();
478
+ });
479
+ };
480
+ allFaces = null;
481
+ getFaces = function(){
482
+ var allFaces;
483
+ return allFaces != null
484
+ ? allFaces
485
+ : allFaces = Promise.all(Array.from(document.styleSheets).map(facesInSheet)).then(function(l){
486
+ return l.flat();
487
+ });
488
+ };
489
+ loadFont = function(src){
490
+ var pick, key$, ref$;
491
+ pick = src.find(function(it){
492
+ var ref$;
493
+ return (ref$ = it.format) === 'truetype' || ref$ === 'opentype' || ref$ === 'woff' || ref$ === 'ttf' || ref$ === 'otf';
494
+ }) || src.find(function(it){
495
+ return it.format === 'woff2';
496
+ });
497
+ if (!pick) {
498
+ return Promise.resolve(null);
499
+ }
500
+ return (ref$ = fontCache[key$ = pick.url]) != null
501
+ ? ref$
502
+ : fontCache[key$] = fetch(pick.url).then(function(r){
503
+ return r.arrayBuffer();
504
+ }).then(function(buf){
505
+ if (pick.format !== 'woff2') {
506
+ return buf;
507
+ }
508
+ return lotion.lib('woff2').then(function(m){
509
+ var decompress;
510
+ decompress = m.decompress || m['default'];
511
+ return decompress(buf);
512
+ }).then(function(u8){
513
+ return u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength);
514
+ });
515
+ });
516
+ };
517
+ hb = null;
518
+ getHb = function(){
519
+ var hb;
520
+ return hb != null
521
+ ? hb
522
+ : hb = fetch(lotion.libs.hbsubset).then(function(r){
523
+ return r.arrayBuffer();
524
+ }).then(function(b){
525
+ return WebAssembly.instantiate(b, {});
526
+ }).then(function(arg$){
527
+ var instance, e;
528
+ instance = arg$.instance;
529
+ e = instance.exports;
530
+ if (e._initialize) {
531
+ e._initialize();
532
+ }
533
+ return e;
534
+ });
535
+ };
536
+ WGHT = 0x77676874;
537
+ subset = function(buf, weight, cps){
538
+ return getHb().then(function(e){
539
+ var n, p, blob, face, input, us, i$, ref$, len$, c, sub, ret, rb, d;
540
+ n = buf.byteLength;
541
+ p = e.malloc(n);
542
+ new Uint8Array(e.memory.buffer).set(new Uint8Array(buf), p);
543
+ blob = e.hb_blob_create(p, n, 1, 0, 0);
544
+ face = e.hb_face_create(blob, 0);
545
+ e.hb_blob_destroy(blob);
546
+ input = e.hb_subset_input_create_or_fail();
547
+ us = e.hb_subset_input_unicode_set(input);
548
+ for (i$ = 0, len$ = (ref$ = cps).length; i$ < len$; ++i$) {
549
+ c = ref$[i$];
550
+ e.hb_set_add(us, c);
551
+ }
552
+ e.hb_subset_input_pin_axis_location(input, face, WGHT, weight);
553
+ sub = e.hb_subset_or_fail(face, input);
554
+ e.hb_subset_input_destroy(input);
555
+ ret = null;
556
+ if (sub) {
557
+ rb = e.hb_face_reference_blob(sub);
558
+ d = e.hb_blob_get_data(rb, 0);
559
+ ret = new Uint8Array(e.memory.buffer).slice(d, d + e.hb_blob_get_length(rb)).buffer;
560
+ e.hb_blob_destroy(rb);
561
+ e.hb_face_destroy(sub);
562
+ }
563
+ e.hb_face_destroy(face);
564
+ e.free(p);
565
+ return ret;
566
+ });
567
+ };
568
+ clamp = function(v, a, b){
569
+ return Math.min(b, Math.max(a, v));
570
+ };
571
+ weightRank = function(f, w){
572
+ var ref$, a, b;
573
+ ref$ = [f.weight[0], f.weight[1] || f.weight[0]], a = ref$[0], b = ref$[1];
574
+ if (w >= a && w <= b) {
575
+ return 0;
576
+ }
577
+ if (w > 500) {
578
+ return a > w
579
+ ? a - w
580
+ : 1000 + w - b;
581
+ }
582
+ if (w < 400) {
583
+ return b < w
584
+ ? w - b
585
+ : 1000 + a - w;
586
+ }
587
+ if (a > w && a <= 500) {
588
+ return a - w;
589
+ } else if (b < w) {
590
+ return 1000 + w - b;
591
+ } else {
592
+ return 2000 + a - w;
593
+ }
594
+ };
595
+ fontsFor = function(used, ctx){
596
+ return getFaces().then(function(faces){
597
+ var groups, missing, nGroup, key, ref$, u, i$, ref1$, len$, c, cp, f, j$, ref2$, len1$, fam, cand, same, pin, gk, g, k, v;
598
+ groups = {};
599
+ missing = 0;
600
+ nGroup = 0;
601
+ for (key in ref$ = used) {
602
+ u = ref$[key];
603
+ u.names = [];
604
+ for (i$ = 0, len$ = (ref1$ = Array.from(u.chars)).length; i$ < len$; ++i$) {
605
+ c = ref1$[i$];
606
+ cp = c.codePointAt(0);
607
+ if (cp < 33) {
608
+ continue;
609
+ }
610
+ f = null;
611
+ for (j$ = 0, len1$ = (ref2$ = u.families).length; j$ < len1$; ++j$) {
612
+ fam = ref2$[j$];
613
+ cand = faces.filter(fn$);
614
+ if (!cand.length) {
615
+ continue;
616
+ }
617
+ same = cand.filter(fn1$);
618
+ if (same.length) {
619
+ cand = same;
620
+ }
621
+ f = cand.reduce(fn2$);
622
+ break;
623
+ }
624
+ if (!f) {
625
+ missing++;
626
+ continue;
627
+ }
628
+ pin = clamp(u.weight, f.weight[0], f.weight[1] || f.weight[0]);
629
+ gk = f.src[0].url + "|" + u.weight + "|" + u.style;
630
+ g = (ref2$ = groups[gk]) != null
631
+ ? ref2$
632
+ : groups[gk] = {
633
+ name: "lotion-font-" + (nGroup++),
634
+ face: f,
635
+ weight: u.weight,
636
+ pin: pin,
637
+ style: u.style,
638
+ cps: new Set([32])
639
+ };
640
+ g.cps.add(cp);
641
+ if (!in$(g.name, u.names)) {
642
+ u.names.push(g.name);
643
+ }
644
+ }
645
+ }
646
+ if (missing) {
647
+ ctx.warn(missing + " characters have no web font ( system fonts are not available to satori )");
648
+ }
649
+ return Promise.all((function(){
650
+ var ref$, results$ = [];
651
+ for (k in ref$ = groups) {
652
+ v = ref$[k];
653
+ results$.push(v);
654
+ }
655
+ return results$;
656
+ }()).map(function(g){
657
+ return loadFont(g.face.src).then(function(buf){
658
+ if (!buf) {
659
+ return null;
660
+ }
661
+ return subset(buf, g.pin, Array.from(g.cps)).then(function(data){
662
+ if (!data) {
663
+ ctx.warn("font " + g.face.family + ": subset failed");
664
+ return null;
665
+ }
666
+ return {
667
+ name: g.name,
668
+ data: data,
669
+ weight: g.weight,
670
+ style: g.style
671
+ };
672
+ });
673
+ });
674
+ })).then(function(l){
675
+ return l.filter(function(it){
676
+ return it;
677
+ });
678
+ });
679
+ function fn$(f){
680
+ return f.family === fam && f.src.length && f.range.some(function(r){
681
+ return cp >= r[0] && cp <= r[1];
682
+ });
683
+ }
684
+ function fn1$(f){
685
+ return f.style === u.style;
686
+ }
687
+ function fn2$(a, b){
688
+ if (weightRank(b, u.weight) < weightRank(a, u.weight)) {
689
+ return b;
690
+ } else {
691
+ return a;
692
+ }
693
+ }
694
+ });
695
+ };
696
+ render = function(satori, tree, o){
697
+ var kids, segs, i$, len$, k, bare;
698
+ kids = tree.props.children;
699
+ if (!kids.some(function(it){
700
+ return it.blend;
701
+ })) {
702
+ return satori(tree, o);
703
+ }
704
+ segs = [{
705
+ kids: []
706
+ }];
707
+ for (i$ = 0, len$ = kids.length; i$ < len$; ++i$) {
708
+ k = kids[i$];
709
+ if (k.blend) {
710
+ segs.push({
711
+ blend: k.blend,
712
+ kids: [k]
713
+ });
714
+ } else if (segs[segs.length - 1].blend) {
715
+ segs.push({
716
+ kids: [k]
717
+ });
718
+ } else {
719
+ segs[segs.length - 1].kids.push(k);
720
+ }
721
+ }
722
+ bare = {
723
+ display: 'flex',
724
+ width: o.width,
725
+ height: o.height,
726
+ overflow: 'hidden'
727
+ };
728
+ return Promise.all(segs.map(function(g, i){
729
+ return satori({
730
+ type: 'div',
731
+ props: {
732
+ style: i === 0 ? tree.props.style : bare,
733
+ children: g.kids
734
+ }
735
+ }, o).then(function(svg){
736
+ var inner;
737
+ inner = svg.replace(/^<svg[^>]*>/, '').replace(/<\/svg>\s*$/, '').replace(/satori_/g, "satori_" + i + "_");
738
+ if (g.blend) {
739
+ return "<g style=\"mix-blend-mode:" + g.blend + "\">" + inner + "</g>";
740
+ } else {
741
+ return "<g>" + inner + "</g>";
742
+ }
743
+ });
744
+ })).then(function(layers){
745
+ return "<svg width=\"" + o.width + "\" height=\"" + o.height + "\" viewBox=\"0 0 " + o.width + " " + o.height + "\" xmlns=\"http://www.w3.org/2000/svg\">" + layers.join('') + "</svg>";
746
+ });
747
+ };
748
+ makeCtx = function(){
749
+ var ctx;
750
+ return ctx = {
751
+ warns: {},
752
+ used: {},
753
+ laters: [],
754
+ warn: function(m){
755
+ return ctx.warns[m] = (ctx.warns[m] || 0) + 1;
756
+ },
757
+ later: function(f){
758
+ return ctx.laters.push(f);
759
+ },
760
+ text: function(cs, text, style){
761
+ var weight, key, u, ref$, ref1$, i$, len$, c;
762
+ weight = +cs.fontWeight || 400;
763
+ key = cs.fontFamily + "|" + weight + "|" + cs.fontStyle;
764
+ u = (ref1$ = (ref$ = ctx.used)[key]) != null
765
+ ? ref1$
766
+ : ref$[key] = {
767
+ families: cs.fontFamily.split(',').map(unquote),
768
+ weight: weight,
769
+ style: cs.fontStyle,
770
+ chars: new Set,
771
+ styles: []
772
+ };
773
+ for (i$ = 0, len$ = (ref$ = Array.from(text)).length; i$ < len$; ++i$) {
774
+ c = ref$[i$];
775
+ u.chars.add(c);
776
+ }
777
+ return u.styles.push(style);
778
+ },
779
+ warnings: function(){
780
+ var k, ref$, v, results$ = [];
781
+ for (k in ref$ = ctx.warns) {
782
+ v = ref$[k];
783
+ results$.push(k + (v > 1 ? " ( x" + v + " )" : ''));
784
+ }
785
+ return results$;
786
+ }
787
+ };
788
+ };
789
+ prepare = function(ctx, opt){
790
+ var that;
791
+ return Promise.all([
792
+ (that = opt.satori)
793
+ ? Promise.resolve(that)
794
+ : lotion.lib('satori'), (that = opt.fonts)
795
+ ? Promise.resolve(that)
796
+ : fontsFor(ctx.used, ctx)
797
+ ]).then(function(arg$){
798
+ var m, fonts, k, ref$, u, i$, ref1$, len$, s;
799
+ m = arg$[0], fonts = arg$[1];
800
+ if (!opt.fonts) {
801
+ for (k in ref$ = ctx.used) {
802
+ u = ref$[k];
803
+ for (i$ = 0, len$ = (ref1$ = u.styles).length; i$ < len$; ++i$) {
804
+ s = ref1$[i$];
805
+ s.fontFamily = u.names.map(fn$).join(', ');
806
+ }
807
+ }
808
+ }
809
+ return [m['default'] || m.satori || m, fonts];
810
+ function fn$(it){
811
+ return "'" + it + "'";
812
+ }
813
+ });
814
+ };
815
+ vector = function(el, opt){
816
+ var ctx, tree, w, h, ref$;
817
+ opt == null && (opt = {});
818
+ ctx = makeCtx();
819
+ tree = convert(el, ctx);
820
+ w = opt.width || el.offsetWidth;
821
+ h = opt.height || el.offsetHeight;
822
+ ref$ = tree.props.style;
823
+ ref$.width = w;
824
+ ref$.height = h;
825
+ ref$.overflow = 'hidden';
826
+ delete tree.props.style.transform;
827
+ delete tree.props.style.transformOrigin;
828
+ return prepare(ctx, opt).then(function(arg$){
829
+ var satori, fonts, i$, ref$, len$, f;
830
+ satori = arg$[0], fonts = arg$[1];
831
+ for (i$ = 0, len$ = (ref$ = ctx.laters).length; i$ < len$; ++i$) {
832
+ f = ref$[i$];
833
+ f(fonts);
834
+ }
835
+ return render(satori, tree, {
836
+ width: w,
837
+ height: h,
838
+ fonts: fonts
839
+ });
840
+ }).then(function(svg){
841
+ return {
842
+ svg: svg,
843
+ warnings: ctx.warnings()
844
+ };
845
+ });
846
+ };
847
+ IDENT = [1, 0, 0, 1, 0, 0];
848
+ mul = function(m, n){
849
+ return [m[0] * n[0] + m[2] * n[1], m[1] * n[0] + m[3] * n[1], m[0] * n[2] + m[2] * n[3], m[1] * n[2] + m[3] * n[3], m[0] * n[4] + m[2] * n[5] + m[4], m[1] * n[4] + m[3] * n[5] + m[5]];
850
+ };
851
+ parseMatrix = function(v, ctx){
852
+ var m, a;
853
+ if (!v || v === 'none') {
854
+ return IDENT;
855
+ }
856
+ if (m = /^matrix\(([^)]+)\)$/.exec(v)) {
857
+ return m[1].split(',').map(function(it){
858
+ return +it;
859
+ });
860
+ }
861
+ if (m = /^matrix3d\(([^)]+)\)$/.exec(v)) {
862
+ a = m[1].split(',').map(function(it){
863
+ return +it;
864
+ });
865
+ ctx.warn("3d transform flattened to 2d");
866
+ return [a[0], a[1], a[4], a[5], a[12], a[13]];
867
+ }
868
+ return IDENT;
869
+ };
870
+ motionMatrix = function(x, y, cs, ctx){
871
+ var m, ref$, ox, oy;
872
+ m = parseMatrix(cs.transform, ctx);
873
+ if (m === IDENT) {
874
+ return [1, 0, 0, 1, x, y];
875
+ }
876
+ ref$ = cs.transformOrigin.split(' ').map(function(it){
877
+ return parseFloat(it) || 0;
878
+ }), ox = ref$[0], oy = ref$[1];
879
+ return mul([1, 0, 0, 1, x + ox, y + oy], mul(m, [1, 0, 0, 1, -ox, -oy]));
880
+ };
881
+ svgMatrix = function(e, cs, ctx){
882
+ var l, m;
883
+ if (cs.transform !== 'none') {
884
+ return motionMatrix(0, 0, cs, ctx);
885
+ }
886
+ l = e.transform && e.transform.baseVal;
887
+ if (!(l && l.numberOfItems)) {
888
+ return IDENT;
889
+ }
890
+ m = l.consolidate().matrix;
891
+ return [m.a, m.b, m.c, m.d, m.e, m.f];
892
+ };
893
+ viewboxMatrix = function(e, w, h){
894
+ var vb, ref$, sx, sy, par, s, ax, ay, dx, dy;
895
+ vb = e.viewBox && e.viewBox.baseVal;
896
+ if (!(vb && vb.width && vb.height)) {
897
+ return IDENT;
898
+ }
899
+ ref$ = [w / vb.width, h / vb.height], sx = ref$[0], sy = ref$[1];
900
+ par = e.preserveAspectRatio.baseVal;
901
+ if (par.align === 1) {
902
+ return [sx, 0, 0, sy, -vb.x * sx, -vb.y * sy];
903
+ }
904
+ s = par.meetOrSlice === 2
905
+ ? Math.max(sx, sy)
906
+ : Math.min(sx, sy);
907
+ ax = (par.align - 2) % 3;
908
+ ay = Math.floor((par.align - 2) / 3);
909
+ dx = (w - vb.width * s) * ax / 2;
910
+ dy = (h - vb.height * s) * ay / 2;
911
+ return [s, 0, 0, s, dx - vb.x * s, dy - vb.y * s];
912
+ };
913
+ blurOf = function(f){
914
+ var m;
915
+ if (!f || f === 'none') {
916
+ return 0;
917
+ } else if (m = /^blur\(([\d.]+)px\)$/.exec(f)) {
918
+ return +m[1];
919
+ } else {
920
+ return null;
921
+ }
922
+ };
923
+ simplify = function(vals, tol){
924
+ var n, keep, stack, ref$, a, b, worst, at, i$, i, f, j$, to$, k, e, results$ = [];
925
+ n = vals.length;
926
+ if (n < 3) {
927
+ return (function(){
928
+ var i$, to$, results$ = [];
929
+ for (i$ = 0, to$ = n; i$ < to$; ++i$) {
930
+ results$.push(i$);
931
+ }
932
+ return results$;
933
+ }());
934
+ }
935
+ keep = new Uint8Array(n);
936
+ keep[0] = keep[n - 1] = 1;
937
+ stack = [[0, n - 1]];
938
+ while (stack.length) {
939
+ ref$ = stack.pop(), a = ref$[0], b = ref$[1];
940
+ ref$ = [1, -1], worst = ref$[0], at = ref$[1];
941
+ for (i$ = a + 1; i$ < b; ++i$) {
942
+ i = i$;
943
+ f = (i - a) / (b - a);
944
+ for (j$ = 0, to$ = vals[a].length; j$ < to$; ++j$) {
945
+ k = j$;
946
+ e = Math.abs(vals[a][k] + (vals[b][k] - vals[a][k]) * f - vals[i][k]) / tol[k];
947
+ if (e > worst) {
948
+ worst = e;
949
+ at = i;
950
+ }
951
+ }
952
+ }
953
+ if (at >= 0) {
954
+ keep[at] = 1;
955
+ stack.push([a, at], [at, b]);
956
+ }
957
+ }
958
+ for (i$ = 0; i$ < n; ++i$) {
959
+ i = i$;
960
+ if (keep[i]) {
961
+ results$.push(i);
962
+ }
963
+ }
964
+ return results$;
965
+ };
966
+ fmt = function(v){
967
+ return +v.toFixed(4);
968
+ };
969
+ pct = function(i, n){
970
+ return (+(100 * i / n).toFixed(3)) + "%";
971
+ };
972
+ SVGGROUP = ['g', 'a', 'switch'];
973
+ SVGSTATIC = ['defs', 'clippath', 'mask', 'lineargradient', 'radialgradient', 'filter', 'pattern', 'symbol', 'style', 'marker', 'title', 'desc', 'metadata'];
974
+ NUMATTRS = ['x', 'y', 'x1', 'y1', 'x2', 'y2', 'cx', 'cy', 'r', 'rx', 'ry', 'width', 'height'];
975
+ NUMPROPS = ['stroke-dashoffset', 'stroke-width', 'fill-opacity', 'stroke-opacity'];
976
+ LEAFSTYLE = svgProps.filter(function(it){
977
+ return !in$(it, NUMPROPS) && !(it === 'opacity' || it === 'visibility' || it === 'display');
978
+ });
979
+ POSATTRS = {
980
+ text: ['x', 'y'],
981
+ rect: ['x', 'y'],
982
+ image: ['x', 'y'],
983
+ use: ['x', 'y'],
984
+ foreignobject: ['x', 'y'],
985
+ circle: ['cx', 'cy'],
986
+ ellipse: ['cx', 'cy']
987
+ };
988
+ NUMERIC = /^\s*-?(\d+\.?\d*|\.\d+)(e-?\d+)?\s*$/;
989
+ xml = function(e){
990
+ return new XMLSerializer().serializeToString(e);
991
+ };
992
+ styleDiff = function(e, cs){
993
+ var pcs, decl, i$, ref$, len$, k, v;
994
+ pcs = getComputedStyle(e.parentNode);
995
+ decl = [];
996
+ for (i$ = 0, len$ = (ref$ = LEAFSTYLE).length; i$ < len$; ++i$) {
997
+ k = ref$[i$];
998
+ v = cs.getPropertyValue(k);
999
+ if (pcs.getPropertyValue(k) !== v) {
1000
+ decl.push(k + ":" + v);
1001
+ }
1002
+ }
1003
+ return decl.join(';');
1004
+ };
1005
+ leaf = function(e, cs, ctx){
1006
+ var tag, c, i$, ref$, len$, k, a, v, t, pos, p, d, f;
1007
+ tag = e.tagName.toLowerCase();
1008
+ c = e.cloneNode(true);
1009
+ for (i$ = 0, len$ = (ref$ = ['transform', 'opacity', 'style', 'class']).length; i$ < len$; ++i$) {
1010
+ k = ref$[i$];
1011
+ c.removeAttribute(k);
1012
+ }
1013
+ a = {};
1014
+ for (i$ = 0, len$ = (ref$ = NUMATTRS).length; i$ < len$; ++i$) {
1015
+ k = ref$[i$];
1016
+ v = e.getAttribute(k);
1017
+ if (v != null && NUMERIC.test(v)) {
1018
+ a[k] = +v;
1019
+ c.removeAttribute(k);
1020
+ }
1021
+ }
1022
+ t = null;
1023
+ if (pos = POSATTRS[tag]) {
1024
+ t = {
1025
+ x: a[pos[0]] || 0,
1026
+ y: a[pos[1]] || 0,
1027
+ keys: pos
1028
+ };
1029
+ delete a[pos[0]];
1030
+ delete a[pos[1]];
1031
+ }
1032
+ p = {};
1033
+ for (i$ = 0, len$ = (ref$ = NUMPROPS).length; i$ < len$; ++i$) {
1034
+ k = ref$[i$];
1035
+ p[k] = parseFloat(cs.getPropertyValue(k)) || 0;
1036
+ c.removeAttribute(k);
1037
+ }
1038
+ if (d = styleDiff(e, cs)) {
1039
+ c.setAttribute('style', d);
1040
+ }
1041
+ f = null;
1042
+ if (tag === 'text') {
1043
+ f = {};
1044
+ ctx.text(cs, e.textContent, f);
1045
+ }
1046
+ return {
1047
+ c: c,
1048
+ a: a,
1049
+ t: t,
1050
+ p: p,
1051
+ f: f
1052
+ };
1053
+ };
1054
+ groupAttrs = function(e, cs){
1055
+ var ret, res$, i$, ref$, len$, at, ref1$, d;
1056
+ res$ = [];
1057
+ for (i$ = 0, len$ = (ref$ = Array.from(e.attributes)).length; i$ < len$; ++i$) {
1058
+ at = ref$[i$];
1059
+ if (!((ref1$ = at.name) === 'class' || ref1$ === 'style' || ref1$ === 'transform' || ref1$ === 'opacity')) {
1060
+ res$.push(at.name + "=\"" + at.value.replace(/"/g, '&quot;') + "\"");
1061
+ }
1062
+ }
1063
+ ret = res$;
1064
+ if (d = styleDiff(e, cs)) {
1065
+ ret.push("style=\"" + d.replace(/"/g, "'") + "\"");
1066
+ }
1067
+ return ret.join(' ');
1068
+ };
1069
+ splitTop = function(str){
1070
+ var ref$, ret, depth, cur, i$, len$, ch;
1071
+ ref$ = [[], 0, ''], ret = ref$[0], depth = ref$[1], cur = ref$[2];
1072
+ for (i$ = 0, len$ = str.length; i$ < len$; ++i$) {
1073
+ ch = str[i$];
1074
+ if (ch === '(') {
1075
+ depth++;
1076
+ }
1077
+ if (ch === ')') {
1078
+ depth--;
1079
+ }
1080
+ if (ch === ',' && depth === 0) {
1081
+ ret.push(cur.trim());
1082
+ cur = '';
1083
+ } else {
1084
+ cur += ch;
1085
+ }
1086
+ }
1087
+ ret.push(cur.trim());
1088
+ return ret;
1089
+ };
1090
+ rgba = function(c){
1091
+ var m, v, ref$;
1092
+ if (!(m = /^rgba?\(([^)]*)\)$/.exec(c))) {
1093
+ return null;
1094
+ }
1095
+ v = m[1].split(/[\s,\/]+/).filter(function(it){
1096
+ return it;
1097
+ }).map(function(it){
1098
+ return parseFloat(it);
1099
+ });
1100
+ return [v[0], v[1], v[2], (ref$ = v[3]) != null ? ref$ : 1];
1101
+ };
1102
+ maskOf = function(cs, w, h){
1103
+ var m, parts, angle, a, stops, i$, len$, p, c, col, ps, j$, len1$, q, sz, ref$, len, tw, th, pos, x, y, glen, offs, i, j, k, to$, x1, y1, x2, y2, grad;
1104
+ if (!(m = /^linear-gradient\((.*)\)$/.exec(cs.maskImage))) {
1105
+ return null;
1106
+ }
1107
+ if (!/^no-repeat( no-repeat)?$/.test(cs.maskRepeat)) {
1108
+ return null;
1109
+ }
1110
+ parts = splitTop(m[1]);
1111
+ angle = 180;
1112
+ if (a = /^(-?[\d.]+)deg$/.exec(parts[0])) {
1113
+ angle = +a[1];
1114
+ parts.shift();
1115
+ } else if (/^to /.test(parts[0])) {
1116
+ angle = {
1117
+ 'to top': 0,
1118
+ 'to right': 90,
1119
+ 'to bottom': 180,
1120
+ 'to left': 270
1121
+ }[parts[0]];
1122
+ if (angle == null) {
1123
+ return null;
1124
+ }
1125
+ parts.shift();
1126
+ }
1127
+ angle = (angle % 360 + 360) % 360;
1128
+ if (angle % 90) {
1129
+ return null;
1130
+ }
1131
+ stops = [];
1132
+ for (i$ = 0, len$ = parts.length; i$ < len$; ++i$) {
1133
+ p = parts[i$];
1134
+ if (!(c = /^(rgba?\([^)]*\))\s*(.*)$/.exec(p))) {
1135
+ return null;
1136
+ }
1137
+ col = rgba(c[1]);
1138
+ ps = c[2].split(/\s+/).filter(fn$);
1139
+ if (!ps.length) {
1140
+ stops.push({
1141
+ col: col
1142
+ });
1143
+ }
1144
+ for (j$ = 0, len1$ = ps.length; j$ < len1$; ++j$) {
1145
+ q = ps[j$];
1146
+ stops.push({
1147
+ col: col,
1148
+ q: q
1149
+ });
1150
+ }
1151
+ }
1152
+ sz = cs.maskSize.split(/\s+/);
1153
+ if ((ref$ = sz[0]) === 'cover' || ref$ === 'contain') {
1154
+ return null;
1155
+ }
1156
+ len = function(v, ref){
1157
+ if (!v || v === 'auto') {
1158
+ return ref;
1159
+ } else if (/%$/.test(v)) {
1160
+ return ref * parseFloat(v) / 100;
1161
+ } else {
1162
+ return parseFloat(v);
1163
+ }
1164
+ };
1165
+ tw = len(sz[0], w);
1166
+ th = len(sz[1], h);
1167
+ ps = cs.maskPosition.split(/\s+/);
1168
+ pos = function(v, free){
1169
+ if (/%$/.test(v)) {
1170
+ return free * parseFloat(v) / 100;
1171
+ } else {
1172
+ return parseFloat(v) || 0;
1173
+ }
1174
+ };
1175
+ x = pos(ps[0], w - tw);
1176
+ y = pos(ps[1] || '0%', h - th);
1177
+ glen = angle === 90 || angle === 270 ? tw : th;
1178
+ offs = stops.map(function(s){
1179
+ if (s.q == null) {
1180
+ return null;
1181
+ } else if (/%$/.test(s.q)) {
1182
+ return parseFloat(s.q) / 100;
1183
+ } else {
1184
+ return parseFloat(s.q) / glen;
1185
+ }
1186
+ });
1187
+ if (offs[0] == null) {
1188
+ offs[0] = 0;
1189
+ }
1190
+ if (offs[offs.length - 1] == null) {
1191
+ offs[offs.length - 1] = 1;
1192
+ }
1193
+ i = 0;
1194
+ while (i < offs.length) {
1195
+ if (offs[i] != null) {
1196
+ i++;
1197
+ continue;
1198
+ }
1199
+ j = i;
1200
+ while (offs[j] == null) {
1201
+ j++;
1202
+ }
1203
+ for (i$ = i; i$ < j; ++i$) {
1204
+ k = i$;
1205
+ offs[k] = offs[i - 1] + (offs[j] - offs[i - 1]) * (k - i + 1) / (j - i + 1);
1206
+ }
1207
+ i = j;
1208
+ }
1209
+ for (i$ = 1, to$ = offs.length; i$ < to$; ++i$) {
1210
+ i = i$;
1211
+ offs[i] = Math.max(offs[i], offs[i - 1]);
1212
+ }
1213
+ ref$ = {
1214
+ 90: [0, 0, 1, 0],
1215
+ 270: [1, 0, 0, 0],
1216
+ 180: [0, 0, 0, 1],
1217
+ 0: [0, 1, 0, 0]
1218
+ }[angle], x1 = ref$[0], y1 = ref$[1], x2 = ref$[2], y2 = ref$[3];
1219
+ grad = stops.map(function(s, i){
1220
+ return "<stop offset=\"" + fmt(offs[i]) + "\" stop-color=\"rgb(" + s.col[0] + "," + s.col[1] + "," + s.col[2] + ")\" stop-opacity=\"" + s.col[3] + "\"/>";
1221
+ }).join('');
1222
+ return {
1223
+ grad: "<linearGradient x1=\"" + x1 + "\" y1=\"" + y1 + "\" x2=\"" + x2 + "\" y2=\"" + y2 + "\">" + grad + "</linearGradient>",
1224
+ rect: [x, y, tw, th],
1225
+ key: cs.maskImage
1226
+ };
1227
+ function fn$(it){
1228
+ return it;
1229
+ }
1230
+ };
1231
+ clipOf = function(cs, w, h){
1232
+ var m, v, ref$, t, r, b, l, len;
1233
+ if (!(m = /^inset\(([^)]*)\)$/.exec(cs.clipPath)) || /round/.test(m[1])) {
1234
+ return null;
1235
+ }
1236
+ v = m[1].trim().split(/\s+/);
1237
+ if (!((ref$ = v.length) === 1 || ref$ === 2 || ref$ === 3 || ref$ === 4) || v.some(function(x){
1238
+ return !/^-?[\d.]+(px|%)$/.test(x) && x !== '0';
1239
+ })) {
1240
+ return null;
1241
+ }
1242
+ ref$ = [
1243
+ v[0], (ref$ = v[1]) != null
1244
+ ? ref$
1245
+ : v[0], (ref$ = v[2]) != null
1246
+ ? ref$
1247
+ : v[0], (ref$ = v[3]) != null
1248
+ ? ref$
1249
+ : (ref$ = v[1]) != null
1250
+ ? ref$
1251
+ : v[0]
1252
+ ], t = ref$[0], r = ref$[1], b = ref$[2], l = ref$[3];
1253
+ len = function(x, ref){
1254
+ if (/%$/.test(x)) {
1255
+ return ref * parseFloat(x) / 100;
1256
+ } else {
1257
+ return parseFloat(x) || 0;
1258
+ }
1259
+ };
1260
+ ref$ = [len(t, h), len(b, h)], t = ref$[0], b = ref$[1];
1261
+ ref$ = [len(r, w), len(l, w)], r = ref$[0], l = ref$[1];
1262
+ return [l, t, Math.max(0, w - l - r), Math.max(0, h - t - b)];
1263
+ };
1264
+ sample = function(opt, ctx){
1265
+ var el, seek, n, fps, from, recs, byEl, recOf, variant, walkSvg, walk, i$, i;
1266
+ el = opt.el, seek = opt.seek, n = opt.n, fps = opt.fps, from = opt.from;
1267
+ recs = [];
1268
+ byEl = new Map;
1269
+ recOf = function(e, parent){
1270
+ var rec;
1271
+ if (rec = byEl.get(e)) {
1272
+ return rec;
1273
+ }
1274
+ rec = {
1275
+ id: recs.length,
1276
+ el: e,
1277
+ parent: parent,
1278
+ kids: [],
1279
+ variants: [],
1280
+ keys: new Map,
1281
+ frames: []
1282
+ };
1283
+ recs.push(rec);
1284
+ byEl.set(e, rec);
1285
+ if (parent) {
1286
+ parent.kids.push(rec);
1287
+ }
1288
+ return rec;
1289
+ };
1290
+ variant = function(rec, sig, make){
1291
+ var v;
1292
+ v = rec.keys.get(sig);
1293
+ if (v == null) {
1294
+ v = rec.variants.length;
1295
+ rec.keys.set(sig, v);
1296
+ rec.variants.push(make());
1297
+ }
1298
+ return v;
1299
+ };
1300
+ walkSvg = function(e, parent, i){
1301
+ var cs, tag, rec, m, o, i$, ref$, len$, c, v, a, p, r, len, drawable;
1302
+ cs = getComputedStyle(e);
1303
+ if (cs.display === 'none') {
1304
+ return;
1305
+ }
1306
+ tag = e.tagName.toLowerCase();
1307
+ rec = recOf(e, parent);
1308
+ if (in$(tag, SVGSTATIC)) {
1309
+ if (!rec.kind) {
1310
+ rec.kind = 'static';
1311
+ rec.markup = xml(e);
1312
+ } else if (xml(e) !== rec.markup) {
1313
+ ctx.warn("<" + tag + "> changes over time: only the first frame is kept");
1314
+ }
1315
+ rec.frames[i] = {
1316
+ m: IDENT,
1317
+ o: 1,
1318
+ b: 0,
1319
+ v: -1
1320
+ };
1321
+ return;
1322
+ }
1323
+ m = svgMatrix(e, cs, ctx);
1324
+ o = +cs.opacity;
1325
+ if (cs.mixBlendMode !== 'normal') {
1326
+ rec.blend = cs.mixBlendMode;
1327
+ }
1328
+ if (in$(tag, SVGGROUP)) {
1329
+ if (!rec.kind) {
1330
+ rec.kind = 'g';
1331
+ rec.attrs = groupAttrs(e, cs);
1332
+ }
1333
+ rec.frames[i] = {
1334
+ m: m,
1335
+ o: o,
1336
+ b: 0,
1337
+ v: -1
1338
+ };
1339
+ for (i$ = 0, len$ = (ref$ = Array.from(e.children)).length; i$ < len$; ++i$) {
1340
+ c = ref$[i$];
1341
+ walkSvg(c, rec, i);
1342
+ }
1343
+ return;
1344
+ }
1345
+ rec.kind = 'leaf';
1346
+ v = -1;
1347
+ a = p = null;
1348
+ if (cs.visibility === 'visible' && o > 0) {
1349
+ r = leaf(e, cs, ctx);
1350
+ a = r.a, p = r.p;
1351
+ if (r.t) {
1352
+ rec.base == null && (rec.base = r.t);
1353
+ m = mul(m, [1, 0, 0, 1, r.t.x - rec.base.x, r.t.y - rec.base.y]);
1354
+ r.c.setAttribute(r.t.keys[0], rec.base.x);
1355
+ r.c.setAttribute(r.t.keys[1], rec.base.y);
1356
+ }
1357
+ if (e.tagName.toLowerCase() === 'path') {
1358
+ len = (function(){
1359
+ try {
1360
+ return e.getTotalLength();
1361
+ } catch (e$) {
1362
+ e = e$;
1363
+ return null;
1364
+ }
1365
+ }());
1366
+ drawable = cs.fill === 'none' && cs.strokeDasharray === 'none' && cs.markerStart === 'none' && cs.markerMid === 'none' && cs.markerEnd === 'none';
1367
+ }
1368
+ v = variant(rec, xml(r.c), function(){
1369
+ return {
1370
+ c: r.c,
1371
+ f: r.f,
1372
+ d: e.getAttribute('d'),
1373
+ len: len,
1374
+ drawable: drawable
1375
+ };
1376
+ });
1377
+ }
1378
+ return rec.frames[i] = {
1379
+ m: m,
1380
+ o: o,
1381
+ b: 0,
1382
+ v: v,
1383
+ a: a,
1384
+ p: p
1385
+ };
1386
+ };
1387
+ walk = function(e, parent, i, depth){
1388
+ var cs, tag, rec, ref$, x, y, w, h, m, gmask, gclip, masked, i$, len$, c, blur, elems, hasText, atomic, v, node, st, k, laters, results$ = [];
1389
+ cs = getComputedStyle(e);
1390
+ if (cs.display === 'none') {
1391
+ return;
1392
+ }
1393
+ tag = e.tagName.toLowerCase();
1394
+ rec = recOf(e, parent);
1395
+ ref$ = box(e, e.parentNode, cs, ctx), x = ref$[0], y = ref$[1], w = ref$[2], h = ref$[3];
1396
+ m = depth === 0
1397
+ ? IDENT
1398
+ : motionMatrix(x, y, cs, ctx);
1399
+ rec.blend = cs.mixBlendMode !== 'normal' ? cs.mixBlendMode : null;
1400
+ if (cs.zIndex !== 'auto') {
1401
+ ctx.warn("z-index ignored ( dom order is used )");
1402
+ }
1403
+ gmask = cs.maskImage !== 'none' ? maskOf(cs, w, h) : null;
1404
+ if (gmask) {
1405
+ if (!rec.mask) {
1406
+ rec.mask = gmask;
1407
+ } else if (rec.mask.key !== gmask.key) {
1408
+ ctx.warn("mask image changes over time: only the first is kept");
1409
+ }
1410
+ }
1411
+ gclip = cs.clipPath !== 'none' ? clipOf(cs, w, h) : null;
1412
+ if (gclip) {
1413
+ rec.clipped = true;
1414
+ }
1415
+ masked = (cs.maskImage !== 'none' && !gmask) || (cs.clipPath !== 'none' && !gclip);
1416
+ if (tag === 'svg' && !masked) {
1417
+ if (!rec.kind) {
1418
+ rec.kind = 'svg';
1419
+ rec.vb = viewboxMatrix(e, w, h);
1420
+ rec.clip = cs.overflow === 'visible'
1421
+ ? null
1422
+ : [w, h];
1423
+ rec.style = styleDiff(e, cs);
1424
+ }
1425
+ rec.frames[i] = {
1426
+ m: m,
1427
+ o: +cs.opacity,
1428
+ b: 0,
1429
+ v: -1,
1430
+ k: gmask && gmask.rect,
1431
+ q: gclip
1432
+ };
1433
+ if (+cs.opacity > 0) {
1434
+ for (i$ = 0, len$ = (ref$ = Array.from(e.children)).length; i$ < len$; ++i$) {
1435
+ c = ref$[i$];
1436
+ walkSvg(c, rec, i);
1437
+ }
1438
+ }
1439
+ return;
1440
+ }
1441
+ blur = blurOf(cs.filter);
1442
+ elems = Array.from(e.children);
1443
+ hasText = Array.from(e.childNodes).some(function(n){
1444
+ return n.nodeType === 3 && n.textContent.trim();
1445
+ });
1446
+ atomic = (tag === 'img' || tag === 'canvas' || tag === 'svg') || masked || !(blur != null) || (hasText && elems.length);
1447
+ rec.atomic = atomic;
1448
+ if (cs.overflow !== 'visible' && !atomic && elems.length) {
1449
+ rec.clip == null && (rec.clip = [w, h]);
1450
+ }
1451
+ v = -1;
1452
+ if (cs.visibility === 'visible' && +cs.opacity > 0) {
1453
+ ctx.laters = [];
1454
+ node = convert(e, ctx, 1, {
1455
+ own: !atomic,
1456
+ nobake: true
1457
+ });
1458
+ if (node) {
1459
+ st = node.props.style;
1460
+ for (i$ = 0, len$ = (ref$ = ['position', 'left', 'top', 'transform', 'transformOrigin', 'opacity']).length; i$ < len$; ++i$) {
1461
+ k = ref$[i$];
1462
+ delete st[k];
1463
+ }
1464
+ if (blur != null) {
1465
+ delete st.filter;
1466
+ }
1467
+ if (gmask) {
1468
+ for (i$ = 0, len$ = (ref$ = ['maskImage', 'maskPosition', 'maskSize', 'maskRepeat']).length; i$ < len$; ++i$) {
1469
+ k = ref$[i$];
1470
+ delete st[k];
1471
+ }
1472
+ }
1473
+ if (gclip) {
1474
+ delete st.clipPath;
1475
+ }
1476
+ delete node.blend;
1477
+ laters = ctx.laters;
1478
+ v = variant(rec, JSON.stringify(node), function(){
1479
+ return {
1480
+ node: node,
1481
+ w: w,
1482
+ h: h,
1483
+ laters: laters
1484
+ };
1485
+ });
1486
+ }
1487
+ }
1488
+ rec.frames[i] = {
1489
+ m: m,
1490
+ o: +cs.opacity,
1491
+ b: blur || 0,
1492
+ v: v,
1493
+ k: gmask && gmask.rect,
1494
+ q: gclip
1495
+ };
1496
+ if (!atomic && +cs.opacity > 0) {
1497
+ for (i$ = 0, len$ = elems.length; i$ < len$; ++i$) {
1498
+ c = elems[i$];
1499
+ results$.push(walk(c, rec, i, depth + 1));
1500
+ }
1501
+ return results$;
1502
+ }
1503
+ };
1504
+ for (i$ = 0; i$ < n; ++i$) {
1505
+ i = i$;
1506
+ if (opt.signal && opt.signal.aborted) {
1507
+ throw new DOMException('aborted', 'AbortError');
1508
+ }
1509
+ seek(from + i / fps);
1510
+ walk(el, null, i, 0);
1511
+ if (opt.progress) {
1512
+ opt.progress(0.5 * (i + 1) / n);
1513
+ }
1514
+ }
1515
+ return recs;
1516
+ };
1517
+ drawOn = function(rec){
1518
+ var vs, order, fams, famOf, i$, len$, k, d, f, ref$, fr, ref1$, results$ = [];
1519
+ vs = rec.variants;
1520
+ if (vs.length < 2 || !vs.every(function(v){
1521
+ return v.d != null && v.len != null && v.drawable;
1522
+ })) {
1523
+ return;
1524
+ }
1525
+ order = (function(){
1526
+ var i$, to$, results$ = [];
1527
+ for (i$ = 0, to$ = vs.length; i$ < to$; ++i$) {
1528
+ results$.push(i$);
1529
+ }
1530
+ return results$;
1531
+ }()).sort(function(a, b){
1532
+ return vs[b].d.length - vs[a].d.length;
1533
+ });
1534
+ fams = [];
1535
+ famOf = [];
1536
+ for (i$ = 0, len$ = order.length; i$ < len$; ++i$) {
1537
+ k = order[i$];
1538
+ d = vs[k].d;
1539
+ f = fams.find(fn$);
1540
+ if (!f) {
1541
+ f = {
1542
+ root: k
1543
+ };
1544
+ fams.push(f);
1545
+ }
1546
+ famOf[k] = f;
1547
+ }
1548
+ if (fams.length === vs.length) {
1549
+ return;
1550
+ }
1551
+ rec.variants = fams.map(function(f, j){
1552
+ var va;
1553
+ va = vs[f.root];
1554
+ f.j = j;
1555
+ f.L = va.len + 1;
1556
+ va.c.setAttribute('stroke-dasharray', f.L + " " + f.L);
1557
+ return va;
1558
+ });
1559
+ for (i$ = 0, len$ = (ref$ = rec.frames).length; i$ < len$; ++i$) {
1560
+ fr = ref$[i$];
1561
+ if (fr && fr.v >= 0) {
1562
+ f = famOf[fr.v];
1563
+ fr.p = (ref1$ = fr.p || {}, ref1$['stroke-dashoffset'] = f.L - vs[fr.v].len, ref1$);
1564
+ results$.push(fr.v = f.j);
1565
+ }
1566
+ }
1567
+ return results$;
1568
+ function fn$(f){
1569
+ var r;
1570
+ r = vs[f.root].d;
1571
+ return r.startsWith(d) && (r.length === d.length || /[A-Za-z]/.test(r[d.length]));
1572
+ }
1573
+ };
1574
+ PAD = 64;
1575
+ draw = function(satori, fonts, rec, k, va){
1576
+ var W, H, ref$;
1577
+ W = va.w + 2 * PAD;
1578
+ H = va.h + 2 * PAD;
1579
+ ref$ = va.node.props.style;
1580
+ ref$.position = 'absolute';
1581
+ ref$.left = PAD;
1582
+ ref$.top = PAD;
1583
+ return satori({
1584
+ type: 'div',
1585
+ props: {
1586
+ style: {
1587
+ display: 'flex',
1588
+ width: W,
1589
+ height: H
1590
+ },
1591
+ children: [va.node]
1592
+ }
1593
+ }, {
1594
+ width: W,
1595
+ height: H,
1596
+ fonts: fonts
1597
+ }).then(function(svg){
1598
+ var inner;
1599
+ inner = svg.replace(/^<svg[^>]*>/, '').replace(/<\/svg>\s*$/, '').replace(/satori_/g, "s" + rec.id + "_" + k + "_");
1600
+ return "<g transform=\"translate(" + (-PAD) + "," + (-PAD) + ")\">" + inner + "</g>";
1601
+ });
1602
+ };
1603
+ attrTol = function(k){
1604
+ if (/opacity/.test(k)) {
1605
+ return 0.008;
1606
+ } else {
1607
+ return 0.05;
1608
+ }
1609
+ };
1610
+ compose = function(recs, opt, fonts){
1611
+ var n, fps, width, height, dur, css, fontNames, tail, series, rule, track, animateEl, attrsOf, maskMarkup, withMask, NOCLIP, withClip, leafMarkup, out, body, faces, style;
1612
+ n = opt.n, fps = opt.fps, width = opt.width, height = opt.height;
1613
+ dur = n / fps;
1614
+ css = [];
1615
+ fontNames = new Set;
1616
+ tail = opt.repeat ? ' infinite' : ' forwards';
1617
+ series = function(frames){
1618
+ var last, vals;
1619
+ last = frames.find(function(it){
1620
+ return it != null;
1621
+ });
1622
+ vals = frames.map(function(f){
1623
+ return last = f != null ? f : last;
1624
+ });
1625
+ if (vals.every(function(v){
1626
+ return v.every(function(x, j){
1627
+ return x === vals[0][j];
1628
+ });
1629
+ })) {
1630
+ return [vals, false];
1631
+ } else {
1632
+ return [vals, true];
1633
+ }
1634
+ };
1635
+ rule = function(cls, base, frames, prop, tol, val, step){
1636
+ var ref$, vals, varies, idx, i, kf, name;
1637
+ ref$ = series(frames), vals = ref$[0], varies = ref$[1];
1638
+ if (!varies) {
1639
+ base.push(prop + ":" + val(vals[0]));
1640
+ return;
1641
+ }
1642
+ idx = step
1643
+ ? (function(){
1644
+ var i$, to$, results$ = [];
1645
+ for (i$ = 0, to$ = n; i$ < to$; ++i$) {
1646
+ i = i$;
1647
+ if (i === 0 || vals[i].join() !== vals[i - 1].join()) {
1648
+ results$.push(i);
1649
+ }
1650
+ }
1651
+ return results$;
1652
+ }())
1653
+ : simplify(vals, tol);
1654
+ kf = idx.map(function(i){
1655
+ return pct(i, n) + "{" + prop + ":" + val(vals[i]) + "}";
1656
+ }).join('') + ("100%{" + prop + ":" + val(vals[n - 1]) + "}");
1657
+ name = cls + "-" + prop.replace(/[^a-z]/g, '');
1658
+ css.push("@keyframes " + name + "{" + kf + "}");
1659
+ base.push(prop + ":" + val(vals[0]));
1660
+ return name;
1661
+ };
1662
+ track = function(k, frames, tol){
1663
+ var ref$, vals, varies, idx, times, vs;
1664
+ ref$ = series(frames), vals = ref$[0], varies = ref$[1];
1665
+ if (!varies) {
1666
+ return [k, fmt(vals[0][0])];
1667
+ }
1668
+ idx = simplify(vals, [tol]);
1669
+ times = idx.map(function(i){
1670
+ return i / n;
1671
+ });
1672
+ vs = idx.map(function(i){
1673
+ return fmt(vals[i][0]);
1674
+ });
1675
+ if (times[times.length - 1] < 1) {
1676
+ times.push(1);
1677
+ vs.push(fmt(vals[n - 1][0]));
1678
+ }
1679
+ return [
1680
+ k, fmt(vals[0][0]), {
1681
+ times: times,
1682
+ vs: vs
1683
+ }
1684
+ ];
1685
+ };
1686
+ animateEl = function(k, anim){
1687
+ var a;
1688
+ a = document.createElementNS('http://www.w3.org/2000/svg', 'animate');
1689
+ a.setAttribute('attributeName', k);
1690
+ a.setAttribute('dur', dur + "s");
1691
+ a.setAttribute('calcMode', 'linear');
1692
+ a.setAttribute('keyTimes', anim.times.map(function(it){
1693
+ return +it.toFixed(4);
1694
+ }).join(';'));
1695
+ a.setAttribute('values', anim.vs.join(';'));
1696
+ if (opt.repeat) {
1697
+ a.setAttribute('repeatCount', 'indefinite');
1698
+ } else {
1699
+ a.setAttribute('fill', 'freeze');
1700
+ }
1701
+ return a;
1702
+ };
1703
+ attrsOf = function(rec){
1704
+ var F, keys, i$, len$, f, k, ret;
1705
+ F = rec.frames;
1706
+ keys = new Set;
1707
+ for (i$ = 0, len$ = F.length; i$ < len$; ++i$) {
1708
+ f = F[i$];
1709
+ if (f && f.a) {
1710
+ for (k in f.a) {
1711
+ keys.add(k);
1712
+ }
1713
+ }
1714
+ }
1715
+ ret = [];
1716
+ keys.forEach(function(k){
1717
+ return ret.push(track(k, (function(){
1718
+ var i$, to$, results$ = [];
1719
+ for (i$ = 0, to$ = n; i$ < to$; ++i$) {
1720
+ results$.push(i$);
1721
+ }
1722
+ return results$;
1723
+ }()).map(function(i){
1724
+ if (F[i] && F[i].a && F[i].a[k] != null) {
1725
+ return [F[i].a[k]];
1726
+ } else {
1727
+ return null;
1728
+ }
1729
+ }), attrTol(k)));
1730
+ });
1731
+ return ret;
1732
+ };
1733
+ maskMarkup = function(rec){
1734
+ var F, r, i$, ref$, len$, j, k, ref1$, _, v, anim, grad;
1735
+ F = rec.frames;
1736
+ r = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
1737
+ r.setAttribute('fill', "url(#mg" + rec.id + ")");
1738
+ for (i$ = 0, len$ = (ref$ = ['x', 'y', 'width', 'height']).length; i$ < len$; ++i$) {
1739
+ j = i$;
1740
+ k = ref$[i$];
1741
+ ref1$ = track(k, (fn$()).map(fn1$), 0.25), _ = ref1$[0], v = ref1$[1], anim = ref1$[2];
1742
+ r.setAttribute(k, v);
1743
+ if (anim) {
1744
+ r.appendChild(animateEl(k, anim));
1745
+ }
1746
+ }
1747
+ grad = rec.mask.grad.replace('<linearGradient', "<linearGradient id=\"mg" + rec.id + "\"");
1748
+ return "<mask id=\"m" + rec.id + "\" maskUnits=\"userSpaceOnUse\" x=\"-100000\" y=\"-100000\" width=\"200000\" height=\"200000\" style=\"mask-type:alpha\">" + grad + xml(r) + "</mask>";
1749
+ function fn$(){
1750
+ var i$, to$, results$ = [];
1751
+ for (i$ = 0, to$ = n; i$ < to$; ++i$) {
1752
+ results$.push(i$);
1753
+ }
1754
+ return results$;
1755
+ }
1756
+ function fn1$(i){
1757
+ if (F[i] && F[i].k) {
1758
+ return [F[i].k[j]];
1759
+ } else {
1760
+ return null;
1761
+ }
1762
+ }
1763
+ };
1764
+ withMask = function(rec, inner){
1765
+ if (!rec.mask) {
1766
+ return inner;
1767
+ }
1768
+ return maskMarkup(rec) + "<g mask=\"url(#m" + rec.id + ")\">" + inner + "</g>";
1769
+ };
1770
+ NOCLIP = [-100000, -100000, 200000, 200000];
1771
+ withClip = function(rec, inner){
1772
+ var F, r, i$, ref$, len$, j, k, ref1$, _, v, anim;
1773
+ if (!rec.clipped) {
1774
+ return inner;
1775
+ }
1776
+ F = rec.frames;
1777
+ r = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
1778
+ for (i$ = 0, len$ = (ref$ = ['x', 'y', 'width', 'height']).length; i$ < len$; ++i$) {
1779
+ j = i$;
1780
+ k = ref$[i$];
1781
+ ref1$ = track(k, (fn$()).map(fn1$), 0.25), _ = ref1$[0], v = ref1$[1], anim = ref1$[2];
1782
+ r.setAttribute(k, v);
1783
+ if (anim) {
1784
+ r.appendChild(animateEl(k, anim));
1785
+ }
1786
+ }
1787
+ return "<clipPath id=\"q" + rec.id + "\">" + xml(r) + "</clipPath><g clip-path=\"url(#q" + rec.id + ")\">" + inner + "</g>";
1788
+ function fn$(){
1789
+ var i$, to$, results$ = [];
1790
+ for (i$ = 0, to$ = n; i$ < to$; ++i$) {
1791
+ results$.push(i$);
1792
+ }
1793
+ return results$;
1794
+ }
1795
+ function fn1$(i){
1796
+ if (F[i]) {
1797
+ return [(F[i].q || NOCLIP)[j]];
1798
+ } else {
1799
+ return null;
1800
+ }
1801
+ }
1802
+ };
1803
+ leafMarkup = function(rec, va){
1804
+ var c, i$, ref$, len$, ref1$, k, v, anim, f;
1805
+ c = va.c;
1806
+ for (i$ = 0, len$ = (ref$ = rec.tracks).length; i$ < len$; ++i$) {
1807
+ ref1$ = ref$[i$], k = ref1$[0], v = ref1$[1], anim = ref1$[2];
1808
+ c.setAttribute(k, v);
1809
+ if (anim) {
1810
+ c.appendChild(animateEl(k, anim));
1811
+ }
1812
+ }
1813
+ if (va.f && va.f.fontFamily) {
1814
+ c.setAttribute('style', (c.getAttribute('style') || '') + ";font-family:" + va.f.fontFamily);
1815
+ for (i$ = 0, len$ = (ref$ = va.f.fontFamily.split(',')).length; i$ < len$; ++i$) {
1816
+ f = ref$[i$];
1817
+ fontNames.add(f.trim().replace(/'/g, ''));
1818
+ }
1819
+ }
1820
+ return xml(c);
1821
+ };
1822
+ out = function(rec){
1823
+ var cls, base, anims, F, at, name, opa, pk, i$, len$, f, k, vs, kids, inner;
1824
+ if (rec.kind === 'static') {
1825
+ return rec.markup;
1826
+ }
1827
+ cls = "n" + rec.id;
1828
+ base = [];
1829
+ anims = [];
1830
+ F = rec.frames;
1831
+ at = function(f){
1832
+ return (function(){
1833
+ var i$, to$, results$ = [];
1834
+ for (i$ = 0, to$ = n; i$ < to$; ++i$) {
1835
+ results$.push(i$);
1836
+ }
1837
+ return results$;
1838
+ }()).map(function(i){
1839
+ if (F[i]) {
1840
+ return f(F[i]);
1841
+ } else {
1842
+ return null;
1843
+ }
1844
+ });
1845
+ };
1846
+ if (name = rule(cls, base, at(function(f){
1847
+ return f.m;
1848
+ }), 'transform', [0.005, 0.005, 0.005, 0.005, 0.25, 0.25], function(v){
1849
+ return "matrix(" + v.map(function(x, j){
1850
+ if (j > 3) {
1851
+ return +x.toFixed(2);
1852
+ } else {
1853
+ return fmt(x);
1854
+ }
1855
+ }).join(',') + ")";
1856
+ }, false)) {
1857
+ anims.push(name + " " + dur + "s linear");
1858
+ }
1859
+ opa = (function(){
1860
+ var i$, to$, results$ = [];
1861
+ for (i$ = 0, to$ = n; i$ < to$; ++i$) {
1862
+ results$.push(i$);
1863
+ }
1864
+ return results$;
1865
+ }()).map(function(i){
1866
+ return [F[i] ? F[i].o : 0];
1867
+ });
1868
+ if (name = rule(cls, base, opa, 'opacity', [0.008], function(v){
1869
+ return +v[0].toFixed(3);
1870
+ }, false)) {
1871
+ anims.push(name + " " + dur + "s linear");
1872
+ }
1873
+ if (name = rule(cls, base, at(function(f){
1874
+ return [f.b];
1875
+ }), 'filter', [0.05], function(v){
1876
+ if (v[0] > 0.01) {
1877
+ return "blur(" + fmt(v[0]) + "px)";
1878
+ } else {
1879
+ return 'none';
1880
+ }
1881
+ }, false)) {
1882
+ anims.push(name + " " + dur + "s linear");
1883
+ }
1884
+ if (rec.kind === 'leaf') {
1885
+ pk = new Set;
1886
+ for (i$ = 0, len$ = F.length; i$ < len$; ++i$) {
1887
+ f = F[i$];
1888
+ if (f && f.p) {
1889
+ for (k in f.p) {
1890
+ pk.add(k);
1891
+ }
1892
+ }
1893
+ }
1894
+ pk.forEach(function(k){
1895
+ var unit, name;
1896
+ unit = /opacity/.test(k) ? '' : 'px';
1897
+ if (name = rule(cls, base, at(function(f){
1898
+ if (f.p) {
1899
+ return [f.p[k]];
1900
+ } else {
1901
+ return null;
1902
+ }
1903
+ }), k, [attrTol(k)], function(v){
1904
+ return fmt(v[0]) + "" + unit;
1905
+ }, false)) {
1906
+ return anims.push(name + " " + dur + "s linear");
1907
+ }
1908
+ });
1909
+ }
1910
+ if (rec.blend) {
1911
+ base.push("mix-blend-mode:" + rec.blend);
1912
+ }
1913
+ if (anims.length) {
1914
+ base.push("animation:" + anims.map(function(it){
1915
+ return it + tail;
1916
+ }).join(','));
1917
+ }
1918
+ css.push("." + cls + "{" + base.join(';') + "}");
1919
+ if (rec.kind === 'leaf') {
1920
+ rec.tracks = attrsOf(rec);
1921
+ }
1922
+ vs = rec.variants.map(function(va, k){
1923
+ var vcls, vb, shown, name;
1924
+ vcls = cls + "v" + k;
1925
+ vb = [];
1926
+ shown = (function(){
1927
+ var i$, to$, results$ = [];
1928
+ for (i$ = 0, to$ = n; i$ < to$; ++i$) {
1929
+ results$.push(i$);
1930
+ }
1931
+ return results$;
1932
+ }()).map(function(i){
1933
+ return [F[i] && F[i].v === k ? 1 : 0];
1934
+ });
1935
+ if (name = rule(vcls, vb, shown, 'visibility', [0.5], function(v){
1936
+ if (v[0]) {
1937
+ return 'visible';
1938
+ } else {
1939
+ return 'hidden';
1940
+ }
1941
+ }, true)) {
1942
+ vb.push("animation:" + name + " " + dur + "s step-end" + tail);
1943
+ }
1944
+ css.push("." + vcls + "{" + vb.join(';') + "}");
1945
+ return "<g class=\"" + vcls + "\">" + (rec.kind === 'leaf'
1946
+ ? leafMarkup(rec, va)
1947
+ : va.svg) + "</g>";
1948
+ });
1949
+ kids = rec.kids.map(out).join('');
1950
+ if (rec.kind === 'svg') {
1951
+ inner = "<g transform=\"matrix(" + rec.vb.map(fmt).join(',') + ")\" style=\"" + rec.style.replace(/"/g, "'") + "\">" + kids + "</g>";
1952
+ if (rec.clip) {
1953
+ inner = "<clipPath id=\"c" + rec.id + "\"><rect width=\"" + rec.clip[0] + "\" height=\"" + rec.clip[1] + "\"/></clipPath><g clip-path=\"url(#c" + rec.id + ")\">" + inner + "</g>";
1954
+ }
1955
+ return "<g class=\"" + cls + "\">" + withClip(rec, withMask(rec, inner)) + "</g>";
1956
+ }
1957
+ if (rec.kind === 'g') {
1958
+ return "<g class=\"" + cls + "\" " + rec.attrs + ">" + kids + "</g>";
1959
+ }
1960
+ if (rec.clip && kids) {
1961
+ kids = "<clipPath id=\"c" + rec.id + "\"><rect width=\"" + rec.clip[0] + "\" height=\"" + rec.clip[1] + "\"/></clipPath><g clip-path=\"url(#c" + rec.id + ")\">" + kids + "</g>";
1962
+ }
1963
+ return "<g class=\"" + cls + "\">" + withClip(rec, withMask(rec, vs.join('') + kids)) + "</g>";
1964
+ };
1965
+ body = out(recs[0]);
1966
+ faces = fonts.filter(function(it){
1967
+ return fontNames.has(it.name);
1968
+ }).map(function(f){
1969
+ return ("@font-face{font-family:'" + f.name + "';font-weight:" + f.weight + ";font-style:" + f.style + ";") + ("src:url(data:font/ttf;base64," + b64Bytes(f.data) + ") format('truetype')}");
1970
+ });
1971
+ style = faces.join('') + "g{transform-box:view-box;transform-origin:0 0}" + css.join('');
1972
+ return "<svg width=\"" + width + "\" height=\"" + height + "\" viewBox=\"0 0 " + width + " " + height + "\" xmlns=\"http://www.w3.org/2000/svg\"><style>" + style + "</style>" + body + "</svg>";
1973
+ };
1974
+ animate = function(opt){
1975
+ var ctx, fps, from, to, ref$, n, el, o, t0, recs, i$, len$, rec, t1, fonts;
1976
+ opt == null && (opt = {});
1977
+ ctx = makeCtx();
1978
+ fps = opt.fps || 30;
1979
+ from = opt.from || 0;
1980
+ to = (ref$ = opt.to) != null
1981
+ ? ref$
1982
+ : opt.duration;
1983
+ n = Math.max(1, Math.round((to - from) * fps));
1984
+ el = opt.el;
1985
+ o = {
1986
+ el: el,
1987
+ seek: opt.seek,
1988
+ n: n,
1989
+ fps: fps,
1990
+ from: from,
1991
+ signal: opt.signal,
1992
+ progress: opt.progress
1993
+ };
1994
+ t0 = performance.now();
1995
+ recs = sample(o, ctx);
1996
+ for (i$ = 0, len$ = recs.length; i$ < len$; ++i$) {
1997
+ rec = recs[i$];
1998
+ if (rec.kind === 'leaf') {
1999
+ drawOn(rec);
2000
+ }
2001
+ }
2002
+ t1 = performance.now();
2003
+ fonts = null;
2004
+ return prepare(ctx, opt).then(function(arg$){
2005
+ var satori, f, jobs, i$, ref$, len$, rec, j$, ref1$, len1$, k, va, step;
2006
+ satori = arg$[0], f = arg$[1];
2007
+ fonts = f;
2008
+ jobs = [];
2009
+ for (i$ = 0, len$ = (ref$ = recs).length; i$ < len$; ++i$) {
2010
+ rec = ref$[i$];
2011
+ if (!rec.kind) {
2012
+ for (j$ = 0, len1$ = (ref1$ = rec.variants).length; j$ < len1$; ++j$) {
2013
+ k = j$;
2014
+ va = ref1$[j$];
2015
+ jobs.push([rec, k, va]);
2016
+ }
2017
+ }
2018
+ }
2019
+ step = function(i){
2020
+ var ref$, rec, k, va, i$, len$, f;
2021
+ if (i >= jobs.length) {
2022
+ return;
2023
+ }
2024
+ ref$ = jobs[i], rec = ref$[0], k = ref$[1], va = ref$[2];
2025
+ for (i$ = 0, len$ = (ref$ = va.laters).length; i$ < len$; ++i$) {
2026
+ f = ref$[i$];
2027
+ f(fonts);
2028
+ }
2029
+ return draw(satori, fonts, rec, k, va).then(function(svg){
2030
+ va.svg = svg;
2031
+ if (opt.progress) {
2032
+ opt.progress(0.5 + 0.5 * (i + 1) / jobs.length);
2033
+ }
2034
+ return step(i + 1);
2035
+ });
2036
+ };
2037
+ return step(0);
2038
+ }).then(function(){
2039
+ var svg, ref$, count, stats;
2040
+ svg = compose(recs, {
2041
+ n: n,
2042
+ fps: fps,
2043
+ repeat: (ref$ = opt.loop) != null ? ref$ : true,
2044
+ width: opt.width || el.offsetWidth,
2045
+ height: opt.height || el.offsetHeight
2046
+ }, fonts);
2047
+ count = function(k){
2048
+ return recs.filter(function(r){
2049
+ return (r.kind || 'html') === k;
2050
+ }).reduce(function(a, r){
2051
+ return a + r.variants.length;
2052
+ }, 0);
2053
+ };
2054
+ stats = {
2055
+ frames: n,
2056
+ elements: recs.length,
2057
+ variants: {
2058
+ html: count('html'),
2059
+ svg: count('leaf')
2060
+ },
2061
+ sampleMs: Math.round(t1 - t0),
2062
+ totalMs: Math.round(performance.now() - t0),
2063
+ bytes: svg.length
2064
+ };
2065
+ return {
2066
+ svg: svg,
2067
+ warnings: ctx.warnings(),
2068
+ stats: stats
2069
+ };
2070
+ });
2071
+ };
2072
+ lotion.animate = animate;
2073
+ lotion.player.prototype.animate = function(opt){
2074
+ var t0, p, this$ = this;
2075
+ opt == null && (opt = {});
2076
+ this.pause();
2077
+ t0 = this.t;
2078
+ p = Promise.resolve().then(function(){
2079
+ return animate(import$({
2080
+ el: this$.stage,
2081
+ seek: this$.opt.seek,
2082
+ duration: this$.duration,
2083
+ width: this$.width,
2084
+ height: this$.height
2085
+ }, opt));
2086
+ });
2087
+ return p['finally'](function(){
2088
+ return this$.opt.seek(t0);
2089
+ });
2090
+ };
2091
+ lotion.vector = vector;
2092
+ return lotion.player.prototype.vector = function(t, opt){
2093
+ var this$ = this;
2094
+ opt == null && (opt = {});
2095
+ if (t != null) {
2096
+ this.opt.seek(t);
2097
+ }
2098
+ return vector(this.stage, opt).then(function(r){
2099
+ if (t != null) {
2100
+ this$.opt.seek(this$.t);
2101
+ }
2102
+ return r;
2103
+ });
2104
+ };
2105
+ })();
2106
+ function in$(x, xs){
2107
+ var i = -1, l = xs.length >>> 0;
2108
+ while (++i < l) if (x === xs[i]) return true;
2109
+ return false;
2110
+ }
2111
+ function import$(obj, src){
2112
+ var own = {}.hasOwnProperty;
2113
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
2114
+ return obj;
2115
+ }
2116
+ }).call(this);