1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const cssAppend = function (dir = '') {
|
15 | const id = "SgnwFontCss";
|
16 |
|
17 | if (!document.getElementById(id)) {
|
18 | const style = document.createElement('style');
|
19 | style.setAttribute("id", "SgnwFontCss");
|
20 | style.appendChild(document.createTextNode(`
|
21 | @font-face {
|
22 | font-family: "SuttonSignWritingLine";
|
23 | src:
|
24 | local('SuttonSignWritingLine'),
|
25 | ${dir ? `url('${dir}SuttonSignWritingLine.ttf') format('truetype'),` : ""}
|
26 | url('https://cdn.jsdelivr.net/npm/@sutton-signwriting/font-ttf@1.0.0/font/SuttonSignWritingLine.ttf') format('truetype');
|
27 | }
|
28 | @font-face {
|
29 | font-family: "SuttonSignWritingFill";
|
30 | src:
|
31 | local('SuttonSignWritingFill'),
|
32 | ${dir ? `url('${dir}SuttonSignWritingFill.ttf') format('truetype'),` : ""}
|
33 | url('https://cdn.jsdelivr.net/npm/@sutton-signwriting/font-ttf@1.0.0/font/SuttonSignWritingFill.ttf') format('truetype');
|
34 | }
|
35 | @font-face {
|
36 | font-family: "SuttonSignWritingOneD";
|
37 | src:
|
38 | local('SuttonSignWritingOneD'),
|
39 | ${dir ? `url('${dir}SuttonSignWritingOneD.ttf') format('truetype'),` : ""}
|
40 | url('https://cdn.jsdelivr.net/npm/@sutton-signwriting/font-ttf@1.0.0/font/SuttonSignWritingOneD.ttf') format('truetype');
|
41 | }
|
42 | `));
|
43 | document.head.appendChild(style);
|
44 | }
|
45 | };
|
46 |
|
47 | let sizes = {};
|
48 | const zoom = 2;
|
49 | const bound = 76 * zoom;
|
50 | let context;
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | const symbolSize$2 = function (id) {
|
62 | if (id in sizes) {
|
63 | return [...sizes[id]];
|
64 | }
|
65 |
|
66 | if (!context) {
|
67 | const canvaser = document.createElement("canvas");
|
68 | canvaser.width = bound;
|
69 | canvaser.height = bound;
|
70 | context = canvaser.getContext("2d");
|
71 | }
|
72 |
|
73 | context.clearRect(0, 0, bound, bound);
|
74 | context.font = 30 * zoom + "px 'SuttonSignWritingLine'";
|
75 | context.fillText(String.fromCodePoint(id + 0xF0000), 0, 0);
|
76 | const imgData = context.getImageData(0, 0, bound, bound).data;
|
77 | let w, h, i, s;
|
78 |
|
79 | wloop: for (w = bound - 1; w >= 0; w--) {
|
80 | for (h = 0; h < bound; h += 1) {
|
81 | for (s = 0; s < 4; s += 1) {
|
82 | i = w * 4 + h * 4 * bound + s;
|
83 |
|
84 | if (imgData[i]) {
|
85 | break wloop;
|
86 | }
|
87 | }
|
88 | }
|
89 | }
|
90 |
|
91 | var width = w;
|
92 |
|
93 | hloop: for (h = bound - 1; h >= 0; h--) {
|
94 | for (w = 0; w < width; w += 1) {
|
95 | for (s = 0; s < 4; s += 1) {
|
96 | i = w * 4 + h * 4 * bound + s;
|
97 |
|
98 | if (imgData[i]) {
|
99 | break hloop;
|
100 | }
|
101 | }
|
102 | }
|
103 | }
|
104 |
|
105 | var height = h + 1;
|
106 | width = Math.ceil(width / zoom);
|
107 | height = Math.ceil(height / zoom);
|
108 |
|
109 | if (14394 == id) {
|
110 | width = 19;
|
111 | }
|
112 |
|
113 | if ([10468, 10480, 10496, 10512, 10500, 10532, 10548, 10862, 10878, 10894, 11058, 11074, 11476, 11488, 11492, 11504, 11508, 11520, 10516, 10910, 10926, 11042, 11082, 10942].includes(id)) {
|
114 | width = 20;
|
115 | }
|
116 |
|
117 | if (31921 == id) {
|
118 | width = 22;
|
119 | }
|
120 |
|
121 | if (38460 == id) {
|
122 | width = 23;
|
123 | }
|
124 |
|
125 | if ([20164, 20212].includes(id)) {
|
126 | width = 25;
|
127 | }
|
128 |
|
129 | if (31894 == id) {
|
130 | width = 28;
|
131 | }
|
132 |
|
133 | if (46698 == id) {
|
134 | width = 29;
|
135 | }
|
136 |
|
137 | if (29606 == id) {
|
138 | width = 30;
|
139 | }
|
140 |
|
141 | if (44855 == id) {
|
142 | width = 40;
|
143 | }
|
144 |
|
145 | if (32667 == id) {
|
146 | width = 50;
|
147 | }
|
148 |
|
149 | if ([11088, 11474, 11490, 11506].includes(id)) {
|
150 | height = 20;
|
151 | }
|
152 |
|
153 | if (6285 == id) {
|
154 | height = 21;
|
155 | }
|
156 |
|
157 | if (40804 == id) {
|
158 | height = 31;
|
159 | }
|
160 |
|
161 | if (41475 == id) {
|
162 | height = 36;
|
163 | }
|
164 |
|
165 |
|
166 |
|
167 | if (width == 0 && height == 0) {
|
168 | const sizefix = {
|
169 | 9: [15, 30],
|
170 | 10: [21, 30],
|
171 | 11: [30, 15],
|
172 | 12: [30, 21],
|
173 | 13: [15, 30],
|
174 | 14: [21, 30]
|
175 | };
|
176 |
|
177 | if (id in sizefix) {
|
178 | width = sizefix[id][0];
|
179 | height = sizefix[id][1];
|
180 | }
|
181 | }
|
182 |
|
183 | if (width == 0 && height == 0) {
|
184 | return undefined;
|
185 | }
|
186 |
|
187 | sizes[id] = [width, height];
|
188 | return [width, height];
|
189 | };
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | const symbolLine$2 = function (id) {
|
201 | return String.fromCodePoint(id + 0xF0000);
|
202 | };
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 | const symbolFill$2 = function (id) {
|
215 | return String.fromCodePoint(id + 0x100000);
|
216 | };
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 | const symbolText$2 = function (id) {
|
230 | return ` <text class="sym-fill" fill="white" style="pointer-events:none;font-family:'SuttonSignWritingFill';font-size:30px;">${symbolFill$2(id)}</text>
|
231 | <text class="sym-line" fill="black" style="pointer-events:none;font-family:'SuttonSignWritingLine';font-size:30px;">${symbolLine$2(id)}</text>`;
|
232 | };
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 | const cssLoaded = function (callback) {
|
247 | let lineReady = false;
|
248 | let fillReady = false;
|
249 | cssLoadedLine(() => {
|
250 | lineReady = true;
|
251 | });
|
252 | cssLoadedFill(() => {
|
253 | fillReady = true;
|
254 | });
|
255 | const cssCheck = setInterval(function () {
|
256 | if (lineReady && fillReady) {
|
257 | clearInterval(cssCheck);
|
258 | callback();
|
259 | }
|
260 | }, 100);
|
261 | };
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 | const cssLoadedLine = function (callback) {
|
276 | if (!symbolSize$2(1)) {
|
277 | const cssCheck = setInterval(function () {
|
278 | if (symbolSize$2(1)) {
|
279 | clearInterval(cssCheck);
|
280 | callback();
|
281 | }
|
282 | }, 100);
|
283 | } else {
|
284 | callback();
|
285 | }
|
286 | };
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 | const cssLoadedFill = function (callback) {
|
301 | const fillReady = function () {
|
302 | const canvaser = document.createElement("canvas");
|
303 | canvaser.width = 15;
|
304 | canvaser.height = 30;
|
305 | const context = canvaser.getContext("2d");
|
306 | context.font = "30px 'SuttonSignWritingFill'";
|
307 | context.fillText(symbolFill$2(1), 0, 0);
|
308 | const imgData = context.getImageData(0, 0, 15, 30).data;
|
309 | return !imgData.every(item => item === 0);
|
310 | };
|
311 |
|
312 | if (!fillReady()) {
|
313 | const cssCheck = setInterval(function () {
|
314 | if (fillReady()) {
|
315 | clearInterval(cssCheck);
|
316 | callback();
|
317 | }
|
318 | }, 100);
|
319 | } else {
|
320 | callback();
|
321 | }
|
322 | };
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 | var index$2 = Object.freeze({
|
329 | __proto__: null,
|
330 | cssAppend: cssAppend,
|
331 | cssLoaded: cssLoaded,
|
332 | cssLoadedLine: cssLoadedLine,
|
333 | cssLoadedFill: cssLoadedFill,
|
334 | symbolSize: symbolSize$2,
|
335 | symbolLine: symbolLine$2,
|
336 | symbolFill: symbolFill$2,
|
337 | symbolText: symbolText$2
|
338 | });
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 | const num2swu = num => String.fromCodePoint(0x1D80C + parseInt(num) - 250);
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 | const coord2swu = coord => coord.map(num => num2swu(num)).join('');
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 | const swu2code$1 = swuSym => parseInt(swuSym.codePointAt(0));
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 | const swu2id = swuSym => swu2code$1(swuSym) - 0x40000;
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 | const key2id = key => 1 + (parseInt(key.slice(1, 4), 16) - 256) * 96 + parseInt(key.slice(4, 5), 16) * 16 + parseInt(key.slice(5, 6), 16);
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 | const symbolSize$1 = function (fsw) {
|
423 | return symbolSize$2(key2id(fsw));
|
424 | };
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 | const symbolLine$1 = function (fsw) {
|
437 | return symbolLine$2(key2id(fsw));
|
438 | };
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 | const symbolFill$1 = function (fsw) {
|
451 | return symbolFill$2(key2id(fsw));
|
452 | };
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 | const symbolText$1 = function (fsw) {
|
466 | return symbolText$2(key2id(fsw));
|
467 | };
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 | let re$3 = {
|
497 | 'colorize': 'C',
|
498 | 'colorhex': '(?:[0-9a-fA-F]{3}){1,2}',
|
499 | 'colorname': '[a-zA-Z]+',
|
500 | 'padding': 'P[0-9]{2}',
|
501 | 'zoom': 'Z(?:[0-9]+(?:\\.[0-9]+)?|x)',
|
502 | 'classbase': '-?[_a-zA-Z][_a-zA-Z0-9-]{0,100}',
|
503 | 'id': '[a-zA-Z][_a-zA-Z0-9-]{0,100}'
|
504 | };
|
505 | re$3.colorbase = `(?:${re$3.colorhex}|${re$3.colorname})`;
|
506 | re$3.color = `_${re$3.colorbase}_`;
|
507 | re$3.colors = `_${re$3.colorbase}(?:,${re$3.colorbase})?_`;
|
508 | re$3.background = `G${re$3.color}`;
|
509 | re$3.detail = `D${re$3.colors}`;
|
510 | re$3.detailsym = `D[0-9]{2}${re$3.colors}`;
|
511 | re$3.classes = `${re$3.classbase}(?: ${re$3.classbase})*`;
|
512 | re$3.full = `-(${re$3.colorize})?(${re$3.padding})?(${re$3.background})?(${re$3.detail})?(${re$3.zoom})?(?:-((?:${re$3.detailsym})*))?(?:-(${re$3.classes})?!(?:(${re$3.id})!)?)?`;
|
513 |
|
514 | const prefixColor$2 = color => {
|
515 | const regex = new RegExp(`^${re$3.colorhex}$`);
|
516 | return (regex.test(color) ? '#' : '') + color;
|
517 | };
|
518 |
|
519 | const definedProps$2 = obj => Object.fromEntries(Object.entries(obj).filter(([k, v]) => v !== undefined));
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 | const parse$3 = styleString => {
|
538 | const regex = `^${re$3.full}`;
|
539 | const m = (typeof styleString === 'string' ? styleString.match(new RegExp(regex)) : []) || [];
|
540 | return definedProps$2({
|
541 | 'colorize': !m[1] ? undefined : !!m[1],
|
542 | 'padding': !m[2] ? undefined : parseInt(m[2].slice(1)),
|
543 | 'background': !m[3] ? undefined : prefixColor$2(m[3].slice(2, -1)),
|
544 | 'detail': !m[4] ? undefined : m[4].slice(2, -1).split(',').map(prefixColor$2),
|
545 | 'zoom': !m[5] ? undefined : m[5] === 'Zx' ? 'x' : parseFloat(m[5].slice(1)),
|
546 | 'detailsym': !m[6] ? undefined : m[6].match(new RegExp(re$3.detailsym, 'g')).map(val => {
|
547 | const parts = val.split('_');
|
548 | const detail = parts[1].split(',').map(prefixColor$2);
|
549 | return {
|
550 | 'index': parseInt(parts[0].slice(1)),
|
551 | 'detail': detail
|
552 | };
|
553 | }),
|
554 | 'classes': !m[7] ? undefined : m[7],
|
555 | 'id': !m[8] ? undefined : m[8]
|
556 | });
|
557 | };
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 | const compose = styleObject => {
|
589 | if (typeof styleObject !== 'object' || styleObject === null) return undefined;
|
590 |
|
591 | let style1 = '-';
|
592 | style1 += !styleObject.colorize ? '' : 'C';
|
593 | const padding = parseInt(styleObject.padding);
|
594 | style1 += !padding || padding <= 0 || padding > 99 ? '' : 'P' + (padding > 9 ? padding : '0' + padding);
|
595 | const background = !styleObject.background || !(typeof styleObject.background === 'string') ? undefined : styleObject.background.match(re$3.colorbase)[0];
|
596 | style1 += !background ? '' : 'G_' + background + '_';
|
597 | const detail1 = !styleObject.detail || !styleObject.detail[0] || !(typeof styleObject.detail[0] === 'string') ? undefined : styleObject.detail[0].match(re$3.colorbase)[0];
|
598 | const detail2 = !styleObject.detail || !styleObject.detail[1] || !(typeof styleObject.detail[1] === 'string') ? undefined : styleObject.detail[1].match(re$3.colorbase)[0];
|
599 |
|
600 | if (detail1) {
|
601 | style1 += 'D_' + detail1;
|
602 |
|
603 | if (detail2) {
|
604 | style1 += ',' + detail2;
|
605 | }
|
606 |
|
607 | style1 += '_';
|
608 | }
|
609 |
|
610 | const zoom = styleObject.zoom === 'x' ? 'x' : parseFloat(styleObject.zoom);
|
611 | style1 += !zoom || zoom <= 0 ? '' : 'Z' + zoom;
|
612 | let style2 = '';
|
613 | const detailsym = !styleObject.detailsym || !Array.isArray(styleObject.detailsym) ? [] : styleObject.detailsym.map(styleObject => {
|
614 | const index = parseInt(styleObject.index);
|
615 | if (!index || index <= 0 || index > 99) return '';
|
616 | let style = 'D' + (index > 9 ? index : '0' + index);
|
617 | const detail1 = !styleObject.detail || !styleObject.detail[0] ? undefined : styleObject.detail[0].match(re$3.colorbase)[0];
|
618 | const detail2 = !styleObject.detail || !styleObject.detail[1] ? undefined : styleObject.detail[1].match(re$3.colorbase)[0];
|
619 |
|
620 | if (detail1) {
|
621 | style += '_' + detail1;
|
622 |
|
623 | if (detail2) {
|
624 | style += ',' + detail2;
|
625 | }
|
626 |
|
627 | style += '_';
|
628 | }
|
629 |
|
630 | return style;
|
631 | });
|
632 | style2 += detailsym.join('');
|
633 | let style3 = '';
|
634 | const classes = !styleObject.classes || !(typeof styleObject.classes === 'string') ? undefined : styleObject.classes.match(re$3.classes)[0];
|
635 | style3 += !classes ? '' : classes;
|
636 | const id = !styleObject.id || !(typeof styleObject.id === 'string') ? undefined : styleObject.id.match(re$3.id)[0];
|
637 | style3 += classes || id ? '!' : '';
|
638 | style3 += !id ? '' : id + '!';
|
639 | return style1 + (style2 || style3 ? '-' + style2 : '') + (style3 ? '-' + style3 : '');
|
640 | };
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 | let re$1$1 = {
|
664 | 'symbol': 'S[123][0-9a-f]{2}[0-5][0-9a-f]',
|
665 | 'coord': '[0-9]{3}x[0-9]{3}',
|
666 | 'sort': 'A',
|
667 | 'box': '[BLMR]'
|
668 | };
|
669 | re$1$1.prefix = `(?:${re$1$1.sort}(?:${re$1$1.symbol})+)`;
|
670 | re$1$1.spatial = `${re$1$1.symbol}${re$1$1.coord}`;
|
671 | re$1$1.signbox = `${re$1$1.box}${re$1$1.coord}(?:${re$1$1.spatial})*`;
|
672 | re$1$1.sign = `${re$1$1.prefix}?${re$1$1.signbox}`;
|
673 | re$1$1.sortable = `${re$1$1.prefix}${re$1$1.signbox}`;
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 | let re$2 = {
|
697 | 'colorize': 'C',
|
698 | 'colorhex': '(?:[0-9a-fA-F]{3}){1,2}',
|
699 | 'colorname': '[a-zA-Z]+',
|
700 | 'padding': 'P[0-9]{2}',
|
701 | 'zoom': 'Z(?:[0-9]+(?:\\.[0-9]+)?|x)',
|
702 | 'classbase': '-?[_a-zA-Z][_a-zA-Z0-9-]{0,100}',
|
703 | 'id': '[a-zA-Z][_a-zA-Z0-9-]{0,100}'
|
704 | };
|
705 | re$2.colorbase = `(?:${re$2.colorhex}|${re$2.colorname})`;
|
706 | re$2.color = `_${re$2.colorbase}_`;
|
707 | re$2.colors = `_${re$2.colorbase}(?:,${re$2.colorbase})?_`;
|
708 | re$2.background = `G${re$2.color}`;
|
709 | re$2.detail = `D${re$2.colors}`;
|
710 | re$2.detailsym = `D[0-9]{2}${re$2.colors}`;
|
711 | re$2.classes = `${re$2.classbase}(?: ${re$2.classbase})*`;
|
712 | re$2.full = `-(${re$2.colorize})?(${re$2.padding})?(${re$2.background})?(${re$2.detail})?(${re$2.zoom})?(?:-((?:${re$2.detailsym})*))?(?:-(${re$2.classes})?!(?:(${re$2.id})!)?)?`;
|
713 |
|
714 | const prefixColor$1 = color => {
|
715 | const regex = new RegExp(`^${re$2.colorhex}$`);
|
716 | return (regex.test(color) ? '#' : '') + color;
|
717 | };
|
718 |
|
719 | const definedProps$1 = obj => Object.fromEntries(Object.entries(obj).filter(([k, v]) => v !== undefined));
|
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 | const parse$1$1 = styleString => {
|
738 | const regex = `^${re$2.full}`;
|
739 | const m = (typeof styleString === 'string' ? styleString.match(new RegExp(regex)) : []) || [];
|
740 | return definedProps$1({
|
741 | 'colorize': !m[1] ? undefined : !!m[1],
|
742 | 'padding': !m[2] ? undefined : parseInt(m[2].slice(1)),
|
743 | 'background': !m[3] ? undefined : prefixColor$1(m[3].slice(2, -1)),
|
744 | 'detail': !m[4] ? undefined : m[4].slice(2, -1).split(',').map(prefixColor$1),
|
745 | 'zoom': !m[5] ? undefined : m[5] === 'Zx' ? 'x' : parseFloat(m[5].slice(1)),
|
746 | 'detailsym': !m[6] ? undefined : m[6].match(new RegExp(re$2.detailsym, 'g')).map(val => {
|
747 | const parts = val.split('_');
|
748 | const detail = parts[1].split(',').map(prefixColor$1);
|
749 | return {
|
750 | 'index': parseInt(parts[0].slice(1)),
|
751 | 'detail': detail
|
752 | };
|
753 | }),
|
754 | 'classes': !m[7] ? undefined : m[7],
|
755 | 'id': !m[8] ? undefined : m[8]
|
756 | });
|
757 | };
|
758 |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 |
|
771 |
|
772 |
|
773 |
|
774 |
|
775 | const fsw2coord = fswCoord => fswCoord.split('x').map(num => parseInt(num));
|
776 |
|
777 | const parse$2 = {
|
778 | |
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 |
|
790 |
|
791 |
|
792 | symbol: fswSym => {
|
793 | const regex = `^(${re$1$1.symbol})(${re$1$1.coord})?(${re$2.full})?`;
|
794 | const symbol = typeof fswSym === 'string' ? fswSym.match(new RegExp(regex)) : undefined;
|
795 | return {
|
796 | 'symbol': symbol ? symbol[1] : undefined,
|
797 | 'coord': symbol && symbol[2] ? fsw2coord(symbol[2]) : undefined,
|
798 | 'style': symbol ? symbol[3] : undefined
|
799 | };
|
800 | },
|
801 |
|
802 | |
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 |
|
832 |
|
833 |
|
834 |
|
835 | sign: fswSign => {
|
836 | const regex = `^(${re$1$1.prefix})?(${re$1$1.signbox})(${re$2.full})?`;
|
837 | const sign = typeof fswSign === 'string' ? fswSign.match(new RegExp(regex)) : undefined;
|
838 |
|
839 | if (sign) {
|
840 | return {
|
841 | 'sequence': sign[1] ? sign[1].slice(1).match(/.{6}/g) : undefined,
|
842 | 'box': sign[2][0],
|
843 | 'max': fsw2coord(sign[2].slice(1, 8)),
|
844 | 'spatials': sign[2].length < 9 ? undefined : sign[2].slice(8).match(/(.{13})/g).map(m => {
|
845 | return {
|
846 | symbol: m.slice(0, 6),
|
847 | coord: [parseInt(m.slice(6, 9)), parseInt(m.slice(10, 13))]
|
848 | };
|
849 | }),
|
850 | 'style': sign[3]
|
851 | };
|
852 | } else {
|
853 | return {};
|
854 | }
|
855 | },
|
856 |
|
857 | |
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 |
|
871 | text: fswText => {
|
872 | if (typeof fswText !== 'string') return [];
|
873 | const regex = `(${re$1$1.sign}(${re$2.full})?|${re$1$1.spatial}(${re$2.full})?)`;
|
874 | const matches = fswText.match(new RegExp(regex, 'g'));
|
875 | return matches ? [...matches] : [];
|
876 | }
|
877 | };
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 | const info$1 = fsw => {
|
899 | let lanes = {
|
900 | "B": 0,
|
901 | "L": -1,
|
902 | "M": 0,
|
903 | "R": 1
|
904 | };
|
905 | let parsed = parse$2.sign(fsw);
|
906 | let width, height, segment, x1, x2, y1, y2, lane;
|
907 |
|
908 | if (parsed.spatials) {
|
909 | x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
910 | x2 = parsed.max[0];
|
911 | width = x2 - x1;
|
912 | y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
913 | y2 = parsed.max[1];
|
914 | height = y2 - y1;
|
915 | segment = 'sign';
|
916 | lane = parsed.box;
|
917 | } else {
|
918 | parsed = parse$2.symbol(fsw);
|
919 | lane = "M";
|
920 |
|
921 | if (parsed.coord) {
|
922 | x1 = parsed.coord[0];
|
923 | width = (500 - x1) * 2;
|
924 | y1 = parsed.coord[1];
|
925 | height = (500 - y1) * 2;
|
926 | segment = 'symbol';
|
927 | } else {
|
928 | x1 = 490;
|
929 | width = 20;
|
930 | y1 = 490;
|
931 | height = 20;
|
932 | segment = 'none';
|
933 | }
|
934 | }
|
935 |
|
936 | let style = parse$1$1(parsed.style);
|
937 | let zoom = style.zoom || 1;
|
938 | let padding = style.padding || 0;
|
939 | return {
|
940 | minX: x1,
|
941 | minY: y1,
|
942 | width: width,
|
943 | height: height,
|
944 | segment: segment,
|
945 | lane: lanes[lane],
|
946 | padding: padding,
|
947 | zoom: zoom
|
948 | };
|
949 | };
|
950 |
|
951 | const columnDefaults$1 = {
|
952 | 'height': 500,
|
953 | 'width': 150,
|
954 | 'offset': 50,
|
955 | 'pad': 20,
|
956 | 'margin': 5,
|
957 | 'dynamic': false,
|
958 | 'background': undefined,
|
959 | 'punctuation': {
|
960 | 'spacing': true,
|
961 | 'pad': 30,
|
962 | 'pull': true
|
963 | },
|
964 | 'style': {
|
965 | 'detail': ['black', 'white'],
|
966 | 'zoom': 1
|
967 | }
|
968 | };
|
969 |
|
970 |
|
971 |
|
972 |
|
973 |
|
974 |
|
975 |
|
976 |
|
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 | const columnDefaultsMerge$1 = options => {
|
1001 | if (typeof options !== 'object') options = {};
|
1002 | return { ...columnDefaults$1,
|
1003 | ...options,
|
1004 | punctuation: { ...columnDefaults$1.punctuation,
|
1005 | ...options.punctuation
|
1006 | },
|
1007 | style: { ...columnDefaults$1.style,
|
1008 | ...options.style
|
1009 | }
|
1010 | };
|
1011 | };
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 | const columns$1 = (fswText, options) => {
|
1094 | if (typeof fswText !== 'string') return {};
|
1095 | const values = columnDefaultsMerge$1(options);
|
1096 | let input = parse$2.text(fswText);
|
1097 | let cursor = 0;
|
1098 | let cols = [];
|
1099 | let col = [];
|
1100 | let plus = 0;
|
1101 | let center = parseInt(values.width / 2);
|
1102 | let maxHeight = values.height - values.margin;
|
1103 | let pullable = true;
|
1104 | let finalize = false;
|
1105 |
|
1106 | for (let val of input) {
|
1107 | let informed = info$1(val);
|
1108 | cursor += plus;
|
1109 |
|
1110 | if (values.punctuation.spacing) {
|
1111 | cursor += informed.segment == 'sign' ? values.pad : 0;
|
1112 | } else {
|
1113 | cursor += values.pad;
|
1114 | }
|
1115 |
|
1116 | finalize = cursor + informed.height > maxHeight;
|
1117 |
|
1118 | if (finalize && informed.segment == 'symbol' && values.punctuation.pull && pullable) {
|
1119 | finalize = false;
|
1120 | pullable = false;
|
1121 | }
|
1122 |
|
1123 | if (col.length == 0) {
|
1124 | finalize = false;
|
1125 | }
|
1126 |
|
1127 | if (finalize) {
|
1128 | cursor = values.pad;
|
1129 | cols.push(col);
|
1130 | col = [];
|
1131 | pullable = true;
|
1132 | }
|
1133 |
|
1134 | col.push(Object.assign(informed, {
|
1135 | x: center + values.offset * informed.lane - (500 - informed.minX) * informed.zoom * values.style.zoom,
|
1136 | y: cursor,
|
1137 | text: val
|
1138 | }));
|
1139 | cursor += informed.height * informed.zoom * values.style.zoom;
|
1140 |
|
1141 | if (values.punctuation.spacing) {
|
1142 | plus = informed.segment == 'sign' ? values.pad : values.punctuation.pad;
|
1143 | } else {
|
1144 | plus = values.pad;
|
1145 | }
|
1146 | }
|
1147 |
|
1148 | if (col.length) {
|
1149 | cols.push(col);
|
1150 | }
|
1151 |
|
1152 |
|
1153 | if (values.punctuation.pull) {
|
1154 | for (let col of cols) {
|
1155 | let last = col[col.length - 1];
|
1156 | let diff = last.y + last.height - (values.height - values.margin);
|
1157 |
|
1158 | if (diff > 0) {
|
1159 | let adj = parseInt(diff / col.length) + 1;
|
1160 |
|
1161 | for (let i in col) {
|
1162 | col[i].y -= adj * i + adj;
|
1163 | }
|
1164 | }
|
1165 | }
|
1166 | }
|
1167 |
|
1168 |
|
1169 | let widths = [];
|
1170 |
|
1171 | for (let col of cols) {
|
1172 | let min = [center - values.offset - values.pad];
|
1173 | let max = [center + values.offset + values.pad];
|
1174 |
|
1175 | for (let item of col) {
|
1176 | min.push(item.x - values.pad);
|
1177 | max.push(item.x + item.width + values.pad);
|
1178 | }
|
1179 |
|
1180 | min = Math.min(...min);
|
1181 | max = Math.max(...max);
|
1182 | let width = values.width;
|
1183 | let adj = 0;
|
1184 |
|
1185 | if (!values.dynamic) {
|
1186 | adj = center - parseInt((min + max) / 2);
|
1187 | } else {
|
1188 | width = max - min;
|
1189 | adj = -min;
|
1190 | }
|
1191 |
|
1192 | for (let item of col) {
|
1193 | item.x += adj;
|
1194 | }
|
1195 |
|
1196 | widths.push(width);
|
1197 | }
|
1198 |
|
1199 | return {
|
1200 | 'options': values,
|
1201 | 'widths': widths,
|
1202 | 'columns': cols
|
1203 | };
|
1204 | };
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 | const category$1 = [0x100, 0x205, 0x2f7, 0x2ff, 0x36d, 0x37f, 0x387];
|
1212 |
|
1213 |
|
1214 |
|
1215 |
|
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 | const ranges$1 = {
|
1221 | 'all': [0x100, 0x38b],
|
1222 | 'writing': [0x100, 0x37e],
|
1223 | 'hand': [0x100, 0x204],
|
1224 | 'movement': [0x205, 0x2f6],
|
1225 | 'dynamic': [0x2f7, 0x2fe],
|
1226 | 'head': [0x2ff, 0x36c],
|
1227 | 'hcenter': [0x2ff, 0x36c],
|
1228 | 'vcenter': [0x2ff, 0x375],
|
1229 | 'trunk': [0x36d, 0x375],
|
1230 | 'limb': [0x376, 0x37e],
|
1231 | 'location': [0x37f, 0x386],
|
1232 | 'punctuation': [0x387, 0x38b]
|
1233 | };
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 |
|
1241 | const colors$1 = ['#0000CC', '#CC0000', '#FF0099', '#006600', '#000000', '#884411', '#FF9900'];
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 |
|
1248 |
|
1249 |
|
1250 |
|
1251 |
|
1252 |
|
1253 | const colorize$1 = key => {
|
1254 | const parsed = parse$2.symbol(key);
|
1255 | let color = '#000000';
|
1256 |
|
1257 | if (parsed.symbol) {
|
1258 | const dec = parseInt(parsed.symbol.slice(1, 4), 16);
|
1259 | const index = category$1.findIndex(val => val > dec);
|
1260 | color = colors$1[index < 0 ? 6 : index - 1];
|
1261 | }
|
1262 |
|
1263 | return color;
|
1264 | };
|
1265 |
|
1266 |
|
1267 |
|
1268 |
|
1269 |
|
1270 |
|
1271 |
|
1272 |
|
1273 |
|
1274 |
|
1275 |
|
1276 |
|
1277 |
|
1278 |
|
1279 |
|
1280 |
|
1281 | const symbolSvgBody$1 = fswSym => {
|
1282 | const parsed = parse$2.symbol(fswSym);
|
1283 | const blank = '';
|
1284 | if (!parsed.symbol) return blank;
|
1285 | let styling = parse$3(parsed.style);
|
1286 | let x1, y1, x2, y2;
|
1287 |
|
1288 | if (parsed.coord) {
|
1289 | x1 = parsed.coord[0];
|
1290 | y1 = parsed.coord[1];
|
1291 | x2 = 500 + (500 - x1);
|
1292 | y2 = 500 + (500 - y1);
|
1293 | } else {
|
1294 | let size = symbolSize$1(parsed.symbol);
|
1295 | if (!size) return blank;
|
1296 | x1 = 500 - parseInt((size[0] + 1) / 2);
|
1297 | y1 = 500 - parseInt((size[1] + 1) / 2);
|
1298 | x2 = 500 + (500 - x1);
|
1299 | y2 = 500 + (500 - y1);
|
1300 | }
|
1301 |
|
1302 | let symSvg = symbolText$1(parsed.symbol);
|
1303 | symSvg = ` <g transform="translate(${x1},${y1})">
|
1304 | ${symSvg}
|
1305 | </g>`;
|
1306 | let line;
|
1307 |
|
1308 | if (styling.colorize) {
|
1309 | line = colorize$1(parsed.symbol);
|
1310 | } else if (styling.detail) {
|
1311 | line = styling.detail[0];
|
1312 | }
|
1313 |
|
1314 | if (line) {
|
1315 | symSvg = symSvg.replace(/class="sym-line" fill="black"/, `class="sym-line" fill="${line}"`);
|
1316 | }
|
1317 |
|
1318 | let fill = styling.detail && styling.detail[1];
|
1319 |
|
1320 | if (fill) {
|
1321 | symSvg = symSvg.replace(/class="sym-fill" fill="white"/, `class="sym-fill" fill="${fill}"`);
|
1322 | }
|
1323 |
|
1324 | let background = '';
|
1325 |
|
1326 | if (styling.padding) {
|
1327 | x1 -= styling.padding;
|
1328 | y1 -= styling.padding;
|
1329 | x2 += styling.padding;
|
1330 | y2 += styling.padding;
|
1331 | }
|
1332 |
|
1333 | if (styling.background) {
|
1334 | background = `\n <rect x="${x1}" y="${y1}" width="${x2 - x1}" height="${y2 - y1}" style="fill:${styling.background};" />`;
|
1335 | }
|
1336 |
|
1337 | return ` <text font-size="0">${fswSym}</text>${background}
|
1338 | ${symSvg}`;
|
1339 | };
|
1340 |
|
1341 |
|
1342 |
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 |
|
1352 |
|
1353 |
|
1354 |
|
1355 |
|
1356 |
|
1357 | const symbolSvg$1 = fswSym => {
|
1358 | const parsed = parse$2.symbol(fswSym);
|
1359 | const blank = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>';
|
1360 | if (!parsed.symbol) return blank;
|
1361 | let styling = parse$3(parsed.style);
|
1362 | let x1, y1, x2, y2;
|
1363 |
|
1364 | if (parsed.coord) {
|
1365 | x1 = parsed.coord[0];
|
1366 | y1 = parsed.coord[1];
|
1367 | x2 = 500 + (500 - x1);
|
1368 | y2 = 500 + (500 - y1);
|
1369 | } else {
|
1370 | let size = symbolSize$1(parsed.symbol);
|
1371 | if (!size) return blank;
|
1372 | x1 = parseInt(500 - size[0] / 2);
|
1373 | y1 = parseInt(500 - size[1] / 2);
|
1374 | x2 = x1 + size[0];
|
1375 | y2 = y1 + size[1];
|
1376 | }
|
1377 |
|
1378 | let classes = '';
|
1379 |
|
1380 | if (styling.classes) {
|
1381 | classes = ` class="${styling.classes}"`;
|
1382 | }
|
1383 |
|
1384 | let id = '';
|
1385 |
|
1386 | if (styling.id) {
|
1387 | id = ` id="${styling.id}"`;
|
1388 | }
|
1389 |
|
1390 | if (styling.padding) {
|
1391 | x1 -= styling.padding;
|
1392 | y1 -= styling.padding;
|
1393 | x2 += styling.padding;
|
1394 | y2 += styling.padding;
|
1395 | }
|
1396 |
|
1397 | let sizing = '';
|
1398 |
|
1399 | if (styling.zoom != 'x') {
|
1400 | sizing = ` width="${(x2 - x1) * (styling.zoom ? styling.zoom : 1)}" height="${(y2 - y1) * (styling.zoom ? styling.zoom : 1)}"`;
|
1401 | }
|
1402 |
|
1403 | return `<svg${classes}${id} version="1.1" xmlns="http://www.w3.org/2000/svg"${sizing} viewBox="${x1} ${y1} ${x2 - x1} ${y2 - y1}">
|
1404 | ${symbolSvgBody$1(fswSym)}
|
1405 | </svg>`;
|
1406 | };
|
1407 |
|
1408 | const symbolCanvas$1 = function (fswSym) {
|
1409 | const parsed = parse$2.symbol(fswSym);
|
1410 |
|
1411 | if (parsed.symbol) {
|
1412 | let size = symbolSize$1(parsed.symbol);
|
1413 |
|
1414 | if (size) {
|
1415 | const canvas = document.createElement('canvas');
|
1416 | const context = canvas.getContext('2d');
|
1417 | let styling = parse$3(parsed.style);
|
1418 | let line = 'black';
|
1419 |
|
1420 | if (styling.colorize) {
|
1421 | line = colorize$1(parsed.symbol);
|
1422 | } else if (styling.detail) {
|
1423 | line = styling.detail[0];
|
1424 | }
|
1425 |
|
1426 | let fill = styling.detail && styling.detail[1] || 'white';
|
1427 | let x1 = 500;
|
1428 | let x2 = x1 + size[0];
|
1429 | let y1 = 500;
|
1430 | let y2 = y1 + size[1];
|
1431 |
|
1432 | if (styling.padding) {
|
1433 | x1 -= styling.padding;
|
1434 | y1 -= styling.padding;
|
1435 | x2 += styling.padding;
|
1436 | y2 += styling.padding;
|
1437 | }
|
1438 |
|
1439 | let sizing = 1;
|
1440 |
|
1441 | if (styling.zoom != 'x') {
|
1442 | sizing = styling.zoom;
|
1443 | }
|
1444 |
|
1445 | let w = (x2 - x1) * sizing;
|
1446 | let h = (y2 - y1) * sizing;
|
1447 | canvas.width = w ? w : 1;
|
1448 | canvas.height = h ? h : 1;
|
1449 |
|
1450 | if (styling.background) {
|
1451 | context.rect(0, 0, w, h);
|
1452 | context.fillStyle = styling.background;
|
1453 | context.fill();
|
1454 | }
|
1455 |
|
1456 | context.font = 30 * sizing + "px 'SuttonSignWritingFill'";
|
1457 | context.fillStyle = fill;
|
1458 | context.fillText(symbolFill$1(parsed.symbol), (500 - x1) * sizing, (500 - y1) * sizing);
|
1459 | context.font = 30 * sizing + "px 'SuttonSignWritingLine'";
|
1460 | context.fillStyle = line;
|
1461 | context.fillText(symbolLine$1(parsed.symbol), (500 - x1) * sizing, (500 - y1) * sizing);
|
1462 | return canvas;
|
1463 | }
|
1464 | }
|
1465 | };
|
1466 |
|
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 | const symbolPng$1 = fswSym => {
|
1478 | const canvas = symbolCanvas$1(fswSym);
|
1479 | const png = canvas.toDataURL("image/png");
|
1480 | canvas.remove();
|
1481 | return png;
|
1482 | };
|
1483 |
|
1484 | const blank$1 = null;
|
1485 |
|
1486 |
|
1487 |
|
1488 |
|
1489 |
|
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 | const symbolNormalize$1 = fswSym => {
|
1496 | const parsed = parse$2.symbol(fswSym);
|
1497 |
|
1498 | if (parsed.symbol) {
|
1499 | let size = symbolSize$1(parsed.symbol);
|
1500 |
|
1501 | if (size) {
|
1502 | return `${parsed.symbol}${500 - parseInt((size[0] + 1) / 2)}x${500 - parseInt((size[1] + 1) / 2)}${parsed.style || ''}`;
|
1503 | }
|
1504 | } else {
|
1505 | return blank$1;
|
1506 | }
|
1507 | };
|
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 | const signSvgBody$1 = fswSign => {
|
1536 | let parsed = parse$2.sign(fswSign);
|
1537 | const blank = '';
|
1538 |
|
1539 | if (parsed.spatials) {
|
1540 | let styling = parse$3(parsed.style);
|
1541 |
|
1542 | if (styling.detailsym) {
|
1543 | styling.detailsym.forEach(sym => {
|
1544 | if (parsed.spatials[sym.index - 1]) {
|
1545 | parsed.spatials[sym.index - 1].detail = sym.detail;
|
1546 | }
|
1547 | });
|
1548 | }
|
1549 |
|
1550 | let x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
1551 | let y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
1552 | let x2 = parsed.max[0];
|
1553 | let y2 = parsed.max[1];
|
1554 | let background = '';
|
1555 |
|
1556 | if (styling.padding) {
|
1557 | x1 -= styling.padding;
|
1558 | y1 -= styling.padding;
|
1559 | x2 += styling.padding;
|
1560 | y2 += styling.padding;
|
1561 | }
|
1562 |
|
1563 | if (styling.background) {
|
1564 | background = `\n <rect x="${x1}" y="${y1}" width="${x2 - x1}" height="${y2 - y1}" style="fill:${styling.background};" />`;
|
1565 | }
|
1566 |
|
1567 | let svg = ` <text font-size="0">${fswSign}</text>${background}`;
|
1568 | const line = styling.detail && styling.detail[0];
|
1569 | const fill = styling.detail && styling.detail[1];
|
1570 | svg += '\n' + parsed.spatials.map(spatial => {
|
1571 | let svg = symbolText$1(spatial.symbol);
|
1572 | let symLine = line;
|
1573 |
|
1574 | if (spatial.detail) {
|
1575 | symLine = spatial.detail[0];
|
1576 | } else if (styling.colorize) {
|
1577 | symLine = colorize$1(spatial.symbol);
|
1578 | }
|
1579 |
|
1580 | if (symLine) {
|
1581 | svg = svg.replace(/class="sym-line" fill="black"/, `class="sym-line" fill="${symLine}"`);
|
1582 | }
|
1583 |
|
1584 | let symFill = fill;
|
1585 |
|
1586 | if (spatial.detail && spatial.detail[1]) {
|
1587 | symFill = spatial.detail[1];
|
1588 | }
|
1589 |
|
1590 | if (symFill) {
|
1591 | svg = svg.replace(/class="sym-fill" fill="white"/, `class="sym-fill" fill="${symFill}"`);
|
1592 | }
|
1593 |
|
1594 | return ` <g transform="translate(${spatial.coord[0]},${spatial.coord[1]})">
|
1595 | ${svg}
|
1596 | </g>`;
|
1597 | }).join('\n');
|
1598 | return svg;
|
1599 | }
|
1600 |
|
1601 | return blank;
|
1602 | };
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 |
|
1616 |
|
1617 |
|
1618 |
|
1619 |
|
1620 |
|
1621 |
|
1622 |
|
1623 |
|
1624 |
|
1625 |
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 |
|
1632 | const signSvg$1 = fswSign => {
|
1633 | let parsed = parse$2.sign(fswSign);
|
1634 | const blank = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>';
|
1635 |
|
1636 | if (parsed.spatials) {
|
1637 | let styling = parse$3(parsed.style);
|
1638 | let x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
1639 | let y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
1640 | let x2 = parsed.max[0];
|
1641 | let y2 = parsed.max[1];
|
1642 | let classes = '';
|
1643 |
|
1644 | if (styling.classes) {
|
1645 | classes = ` class="${styling.classes}"`;
|
1646 | }
|
1647 |
|
1648 | let id = '';
|
1649 |
|
1650 | if (styling.id) {
|
1651 | id = ` id="${styling.id}"`;
|
1652 | }
|
1653 |
|
1654 | if (styling.padding) {
|
1655 | x1 -= styling.padding;
|
1656 | y1 -= styling.padding;
|
1657 | x2 += styling.padding;
|
1658 | y2 += styling.padding;
|
1659 | }
|
1660 |
|
1661 | let sizing = '';
|
1662 |
|
1663 | if (styling.zoom != 'x') {
|
1664 | sizing = ` width="${(x2 - x1) * (styling.zoom ? styling.zoom : 1)}" height="${(y2 - y1) * (styling.zoom ? styling.zoom : 1)}"`;
|
1665 | }
|
1666 |
|
1667 | let svg = `<svg${classes}${id} version="1.1" xmlns="http://www.w3.org/2000/svg"${sizing} viewBox="${x1} ${y1} ${x2 - x1} ${y2 - y1}">
|
1668 | `;
|
1669 | svg += signSvgBody$1(fswSign);
|
1670 | svg += '\n</svg>';
|
1671 | return svg;
|
1672 | }
|
1673 |
|
1674 | return blank;
|
1675 | };
|
1676 |
|
1677 | const signCanvas$1 = function (fswSign) {
|
1678 | const parsed = parse$2.sign(fswSign);
|
1679 |
|
1680 | if (parsed.spatials) {
|
1681 | const canvas = document.createElement('canvas');
|
1682 | const context = canvas.getContext('2d');
|
1683 | let styling = parse$3(parsed.style);
|
1684 |
|
1685 | if (styling.detailsym) {
|
1686 | styling.detailsym.forEach(sym => {
|
1687 | if (parsed.spatials[sym.index - 1]) {
|
1688 | parsed.spatials[sym.index - 1].detail = sym.detail;
|
1689 | }
|
1690 | });
|
1691 | }
|
1692 |
|
1693 | let x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
1694 | let y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
1695 | let x2 = parsed.max[0];
|
1696 | let y2 = parsed.max[1];
|
1697 |
|
1698 | if (styling.padding) {
|
1699 | x1 -= styling.padding;
|
1700 | y1 -= styling.padding;
|
1701 | x2 += styling.padding;
|
1702 | y2 += styling.padding;
|
1703 | }
|
1704 |
|
1705 | let sizing = 1;
|
1706 |
|
1707 | if (styling.zoom != 'x') {
|
1708 | sizing = styling.zoom;
|
1709 | }
|
1710 |
|
1711 | let w = (x2 - x1) * sizing;
|
1712 | let h = (y2 - y1) * sizing;
|
1713 | canvas.width = w ? w : 1;
|
1714 | canvas.height = h ? h : 1;
|
1715 |
|
1716 | if (styling.background) {
|
1717 | context.rect(0, 0, w, h);
|
1718 | context.fillStyle = styling.background;
|
1719 | context.fill();
|
1720 | }
|
1721 |
|
1722 | const line = styling.detail && styling.detail[0] || "black";
|
1723 | const fill = styling.detail && styling.detail[1] || "white";
|
1724 | parsed.spatials.forEach(spatial => {
|
1725 | let symLine = line;
|
1726 |
|
1727 | if (spatial.detail) {
|
1728 | symLine = spatial.detail[0];
|
1729 | } else if (styling.colorize) {
|
1730 | symLine = colorize$1(spatial.symbol);
|
1731 | }
|
1732 |
|
1733 | let symFill = fill;
|
1734 |
|
1735 | if (spatial.detail && spatial.detail[1]) {
|
1736 | symFill = spatial.detail[1];
|
1737 | }
|
1738 |
|
1739 | context.font = 30 * sizing + "px 'SuttonSignWritingFill'";
|
1740 | context.fillStyle = symFill;
|
1741 | context.fillText(symbolFill$1(spatial.symbol), (spatial.coord[0] - x1) * sizing, (spatial.coord[1] - y1) * sizing);
|
1742 | context.font = 30 * sizing + "px 'SuttonSignWritingLine'";
|
1743 | context.fillStyle = symLine;
|
1744 | context.fillText(symbolLine$1(spatial.symbol), (spatial.coord[0] - x1) * sizing, (spatial.coord[1] - y1) * sizing);
|
1745 | });
|
1746 | return canvas;
|
1747 | }
|
1748 | };
|
1749 |
|
1750 |
|
1751 |
|
1752 |
|
1753 |
|
1754 |
|
1755 |
|
1756 |
|
1757 |
|
1758 |
|
1759 |
|
1760 | const signPng$1 = fswSign => {
|
1761 | const canvas = signCanvas$1(fswSign);
|
1762 | const png = canvas.toDataURL("image/png");
|
1763 | canvas.remove();
|
1764 | return png;
|
1765 | };
|
1766 |
|
1767 |
|
1768 |
|
1769 |
|
1770 |
|
1771 |
|
1772 |
|
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 | const signNormalize$1 = fswSign => {
|
1778 | const parsed = parse$2.sign(fswSign);
|
1779 |
|
1780 | if (parsed.spatials) {
|
1781 | const symbolsizes = parsed.spatials.reduce((output, spatial) => {
|
1782 | const size = symbolSize$1(spatial.symbol);
|
1783 | output[spatial.symbol] = {
|
1784 | width: size[0],
|
1785 | height: size[1]
|
1786 | };
|
1787 | return output;
|
1788 | }, {});
|
1789 |
|
1790 | const bbox = symbols => {
|
1791 | const x1 = Math.min(...symbols.map(spatial => spatial.coord[0]));
|
1792 | const y1 = Math.min(...symbols.map(spatial => spatial.coord[1]));
|
1793 | const x2 = Math.max(...symbols.map(spatial => spatial.coord[0] + parseInt(symbolsizes[spatial.symbol].width)));
|
1794 | const y2 = Math.max(...symbols.map(spatial => spatial.coord[1] + parseInt(symbolsizes[spatial.symbol].height)));
|
1795 | return {
|
1796 | x1: x1,
|
1797 | y1: y1,
|
1798 | x2: x2,
|
1799 | y2: y2
|
1800 | };
|
1801 | };
|
1802 |
|
1803 | const hrange = ranges$1['hcenter'];
|
1804 | const hsyms = parsed.spatials.filter(spatial => {
|
1805 | const dec = parseInt(spatial.symbol.slice(1, 4), 16);
|
1806 | return hrange[0] <= dec && hrange[1] >= dec;
|
1807 | });
|
1808 | const vrange = ranges$1['vcenter'];
|
1809 | const vsyms = parsed.spatials.filter(spatial => {
|
1810 | const dec = parseInt(spatial.symbol.slice(1, 4), 16);
|
1811 | return vrange[0] <= dec && vrange[1] >= dec;
|
1812 | });
|
1813 | let abox = bbox(parsed.spatials);
|
1814 | let max = [abox.x2, abox.y2];
|
1815 |
|
1816 | if (hsyms.length) {
|
1817 | const hbox = bbox(hsyms);
|
1818 | abox.x1 = hbox.x1;
|
1819 | abox.x2 = hbox.x2;
|
1820 | }
|
1821 |
|
1822 | if (vsyms.length) {
|
1823 | const vbox = bbox(vsyms);
|
1824 | abox.y1 = vbox.y1;
|
1825 | abox.y2 = vbox.y2;
|
1826 | }
|
1827 |
|
1828 | const offset = [parseInt((abox.x2 + abox.x1) / 2) - 500, parseInt((abox.y2 + abox.y1) / 2) - 500];
|
1829 | const fswout = (parsed.sequence ? 'A' + parsed.sequence.join('') : '') + parsed.box + (max[0] - offset[0]) + 'x' + (max[1] - offset[1]) + parsed.spatials.map(spatial => spatial.symbol + (spatial.coord[0] - offset[0]) + 'x' + (spatial.coord[1] - offset[1])).join('') + (parsed.style || '');
|
1830 | return fswout;
|
1831 | }
|
1832 | };
|
1833 |
|
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 |
|
1843 |
|
1844 |
|
1845 |
|
1846 |
|
1847 |
|
1848 |
|
1849 |
|
1850 |
|
1851 |
|
1852 |
|
1853 |
|
1854 |
|
1855 |
|
1856 |
|
1857 |
|
1858 |
|
1859 |
|
1860 |
|
1861 |
|
1862 |
|
1863 |
|
1864 |
|
1865 |
|
1866 |
|
1867 |
|
1868 |
|
1869 |
|
1870 |
|
1871 |
|
1872 |
|
1873 |
|
1874 |
|
1875 |
|
1876 |
|
1877 |
|
1878 |
|
1879 |
|
1880 |
|
1881 |
|
1882 |
|
1883 |
|
1884 |
|
1885 |
|
1886 |
|
1887 |
|
1888 |
|
1889 |
|
1890 |
|
1891 |
|
1892 |
|
1893 |
|
1894 |
|
1895 |
|
1896 |
|
1897 |
|
1898 |
|
1899 |
|
1900 |
|
1901 |
|
1902 |
|
1903 |
|
1904 |
|
1905 |
|
1906 |
|
1907 |
|
1908 |
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 |
|
1917 |
|
1918 |
|
1919 |
|
1920 |
|
1921 |
|
1922 |
|
1923 |
|
1924 |
|
1925 |
|
1926 |
|
1927 |
|
1928 | const columnSvg$1 = (fswColumn, options) => {
|
1929 |
|
1930 | if (typeof options !== 'object') options = {};
|
1931 | const values = Object.assign(columnDefaults$1, options);
|
1932 | let x1 = 0;
|
1933 | let y1 = 0;
|
1934 | let x2 = values.width;
|
1935 | let y2 = values.height;
|
1936 | let background = '';
|
1937 |
|
1938 | if (values.background) {
|
1939 | background = `\n <rect x="${x1}" y="${y1}" width="${x2 - x1}" height="${y2 - y1}" style="fill:${values.background};" />`;
|
1940 | }
|
1941 |
|
1942 | let sizing = ` width="${values.width}" height="${values.height}"`;
|
1943 | let svg = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg"${sizing} viewBox="${x1} ${y1} ${x2 - x1} ${y2 - y1}">
|
1944 | ${background}`;
|
1945 | svg += fswColumn.map(item => {
|
1946 | const dash = item.text.indexOf('-');
|
1947 |
|
1948 | if (dash > 0) {
|
1949 | const itemStyle = item.text.substring(dash);
|
1950 | const newStyle = { ...values.style,
|
1951 | ...parse$3(itemStyle)
|
1952 | };
|
1953 | item.text = item.text.replace(itemStyle, compose(newStyle));
|
1954 | } else {
|
1955 | item.text += compose(values.style);
|
1956 | }
|
1957 |
|
1958 | item.zoom = item.zoom * values.style.zoom;
|
1959 | return '<g transform="translate(' + item.x + ',' + item.y + ') scale(' + item.zoom + ') translate(' + -item.minX + ',' + -item.minY + ') ">' + (item.segment == "sign" ? signSvgBody$1(item.text) : symbolSvgBody$1(item.text)) + '</g>';
|
1960 | }).join('\n');
|
1961 | svg += '\n</svg>';
|
1962 | return svg;
|
1963 | };
|
1964 |
|
1965 |
|
1966 |
|
1967 |
|
1968 |
|
1969 |
|
1970 |
|
1971 |
|
1972 |
|
1973 |
|
1974 |
|
1975 |
|
1976 |
|
1977 |
|
1978 |
|
1979 |
|
1980 |
|
1981 |
|
1982 |
|
1983 |
|
1984 |
|
1985 |
|
1986 |
|
1987 |
|
1988 |
|
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 |
|
1997 |
|
1998 |
|
1999 |
|
2000 |
|
2001 |
|
2002 |
|
2003 |
|
2004 |
|
2005 |
|
2006 |
|
2007 |
|
2008 |
|
2009 |
|
2010 |
|
2011 |
|
2012 |
|
2013 |
|
2014 |
|
2015 |
|
2016 |
|
2017 |
|
2018 | const columnsSvg$1 = function (fswText, options) {
|
2019 | if (typeof options !== 'object') options = {};
|
2020 | let values = columns$1(fswText, options);
|
2021 | let cols = values.columns.map((col, i) => {
|
2022 | return columnSvg$1(col, { ...values.options,
|
2023 | ...{
|
2024 | width: values.widths[i]
|
2025 | }
|
2026 | });
|
2027 | });
|
2028 | return cols;
|
2029 | };
|
2030 |
|
2031 | const columnCanvas$1 = function (fswColumn, options) {
|
2032 | if (typeof options !== 'object') options = {};
|
2033 | const values = Object.assign(columnDefaults$1, options);
|
2034 | const canvas = document.createElement('canvas');
|
2035 | canvas.width = values.width;
|
2036 | canvas.height = values.height;
|
2037 | const context = canvas.getContext('2d');
|
2038 |
|
2039 | if (values.background) {
|
2040 | context.rect(0, 0, values.width, values.height);
|
2041 | context.fillStyle = values.background;
|
2042 | context.fill();
|
2043 | }
|
2044 |
|
2045 | fswColumn.map(item => {
|
2046 | const dash = item.text.indexOf('-');
|
2047 |
|
2048 | if (dash > 0) {
|
2049 | const itemStyle = item.text.substring(dash);
|
2050 | const newStyle = { ...values.style,
|
2051 | ...parse$3(itemStyle)
|
2052 | };
|
2053 | item.text = item.text.replace(itemStyle, compose(newStyle));
|
2054 | } else {
|
2055 | item.text += compose(values.style);
|
2056 | }
|
2057 |
|
2058 | item.zoom = item.zoom * values.style.zoom;
|
2059 | let parsed = {};
|
2060 |
|
2061 | if (item.segment == "sign") {
|
2062 | parsed = parse$2.sign(item.text);
|
2063 | } else {
|
2064 | let sym = parse$2.symbol(item.text);
|
2065 | parsed.style = sym.style;
|
2066 | parsed.spatials = [sym];
|
2067 | }
|
2068 |
|
2069 | let styling = parse$3(parsed.style);
|
2070 |
|
2071 | if (styling.background) {
|
2072 | context.fillStyle = styling.background;
|
2073 | context.fillRect(item.x - styling.padding * item.zoom, item.y - styling.padding * item.zoom, (item.width + styling.padding * 2) * item.zoom, (item.height + styling.padding * 2) * item.zoom);
|
2074 | }
|
2075 |
|
2076 | if (styling.detailsym) {
|
2077 | styling.detailsym.forEach(sym => {
|
2078 | if (parsed.spatials[sym.index - 1]) {
|
2079 | parsed.spatials[sym.index - 1].detail = sym.detail;
|
2080 | }
|
2081 | });
|
2082 | }
|
2083 |
|
2084 | const line = styling.detail && styling.detail[0] || "black";
|
2085 | const fill = styling.detail && styling.detail[1] || "white";
|
2086 | parsed.spatials.forEach(spatial => {
|
2087 | let symLine = line;
|
2088 |
|
2089 | if (spatial.detail) {
|
2090 | symLine = spatial.detail[0];
|
2091 | } else if (styling.colorize) {
|
2092 | symLine = colorize$1(spatial.symbol);
|
2093 | }
|
2094 |
|
2095 | let symFill = fill;
|
2096 |
|
2097 | if (spatial.detail && spatial.detail[1]) {
|
2098 | symFill = spatial.detail[1];
|
2099 | }
|
2100 |
|
2101 | context.font = 30 * item.zoom + "px 'SuttonSignWritingFill'";
|
2102 | context.fillStyle = symFill;
|
2103 | context.fillText(symbolFill$1(spatial.symbol), item.x + (spatial.coord[0] - item.minX) * item.zoom, item.y + (spatial.coord[1] - item.minY) * item.zoom);
|
2104 | context.font = 30 * item.zoom + "px 'SuttonSignWritingLine'";
|
2105 | context.fillStyle = symLine;
|
2106 | context.fillText(symbolLine$1(spatial.symbol), item.x + (spatial.coord[0] - item.minX) * item.zoom, item.y + (spatial.coord[1] - item.minY) * item.zoom);
|
2107 | });
|
2108 | });
|
2109 | return canvas;
|
2110 | };
|
2111 |
|
2112 |
|
2113 |
|
2114 |
|
2115 |
|
2116 |
|
2117 |
|
2118 |
|
2119 |
|
2120 |
|
2121 |
|
2122 |
|
2123 |
|
2124 |
|
2125 |
|
2126 |
|
2127 |
|
2128 |
|
2129 |
|
2130 |
|
2131 |
|
2132 |
|
2133 |
|
2134 |
|
2135 |
|
2136 |
|
2137 |
|
2138 |
|
2139 |
|
2140 |
|
2141 |
|
2142 |
|
2143 |
|
2144 |
|
2145 |
|
2146 |
|
2147 |
|
2148 |
|
2149 |
|
2150 |
|
2151 |
|
2152 |
|
2153 |
|
2154 |
|
2155 |
|
2156 |
|
2157 |
|
2158 |
|
2159 |
|
2160 |
|
2161 |
|
2162 |
|
2163 |
|
2164 |
|
2165 |
|
2166 |
|
2167 |
|
2168 | const columnPng$1 = (fswColumn, options) => {
|
2169 | const canvas = columnCanvas$1(fswColumn, options);
|
2170 | const png = canvas.toDataURL("image/png");
|
2171 | canvas.remove();
|
2172 | return png;
|
2173 | };
|
2174 |
|
2175 |
|
2176 |
|
2177 |
|
2178 |
|
2179 |
|
2180 |
|
2181 |
|
2182 |
|
2183 |
|
2184 |
|
2185 |
|
2186 |
|
2187 |
|
2188 |
|
2189 |
|
2190 | const columnsPng$1 = function (fswText, options) {
|
2191 | if (typeof options !== 'object') options = {};
|
2192 | let values = columns$1(fswText, options);
|
2193 | let cols = values.columns.map((col, i) => {
|
2194 | return columnPng$1(col, { ...values.options,
|
2195 | ...{
|
2196 | width: values.widths[i]
|
2197 | }
|
2198 | });
|
2199 | });
|
2200 | return cols;
|
2201 | };
|
2202 |
|
2203 |
|
2204 |
|
2205 |
|
2206 |
|
2207 |
|
2208 | var index$1 = Object.freeze({
|
2209 | __proto__: null,
|
2210 | symbolSize: symbolSize$1,
|
2211 | symbolLine: symbolLine$1,
|
2212 | symbolFill: symbolFill$1,
|
2213 | symbolText: symbolText$1,
|
2214 | symbolSvgBody: symbolSvgBody$1,
|
2215 | symbolSvg: symbolSvg$1,
|
2216 | symbolPng: symbolPng$1,
|
2217 | symbolNormalize: symbolNormalize$1,
|
2218 | signSvgBody: signSvgBody$1,
|
2219 | signSvg: signSvg$1,
|
2220 | signPng: signPng$1,
|
2221 | signNormalize: signNormalize$1,
|
2222 | columnSvg: columnSvg$1,
|
2223 | columnsSvg: columnsSvg$1,
|
2224 | columnPng: columnPng$1,
|
2225 | columnsPng: columnsPng$1
|
2226 | });
|
2227 |
|
2228 |
|
2229 |
|
2230 |
|
2231 |
|
2232 |
|
2233 |
|
2234 |
|
2235 |
|
2236 |
|
2237 |
|
2238 | const symbolSize = function (swu) {
|
2239 | return symbolSize$2(swu2id(swu));
|
2240 | };
|
2241 |
|
2242 |
|
2243 |
|
2244 |
|
2245 |
|
2246 |
|
2247 |
|
2248 |
|
2249 |
|
2250 |
|
2251 |
|
2252 | const symbolLine = function (swu) {
|
2253 | return symbolLine$2(swu2id(swu));
|
2254 | };
|
2255 |
|
2256 |
|
2257 |
|
2258 |
|
2259 |
|
2260 |
|
2261 |
|
2262 |
|
2263 |
|
2264 |
|
2265 |
|
2266 | const symbolFill = function (swu) {
|
2267 | return symbolFill$2(swu2id(swu));
|
2268 | };
|
2269 |
|
2270 |
|
2271 |
|
2272 |
|
2273 |
|
2274 |
|
2275 |
|
2276 |
|
2277 |
|
2278 |
|
2279 |
|
2280 |
|
2281 | const symbolText = function (swu) {
|
2282 | return symbolText$2(swu2id(swu));
|
2283 | };
|
2284 |
|
2285 |
|
2286 |
|
2287 |
|
2288 |
|
2289 |
|
2290 |
|
2291 |
|
2292 |
|
2293 |
|
2294 |
|
2295 |
|
2296 |
|
2297 |
|
2298 |
|
2299 |
|
2300 |
|
2301 |
|
2302 |
|
2303 |
|
2304 |
|
2305 | let re$1 = {
|
2306 | 'symbol': '(?:(?:\uD8C0[\uDC01-\uDFFF])|(?:[\uD8C1-\uD8FC][\uDC00-\uDFFF])|(?:\uD8FD[\uDC00-\uDC80]))',
|
2307 | 'coord': '(?:\uD836[\uDC0C-\uDDFF]){2}',
|
2308 | 'sort': '\uD836\uDC00',
|
2309 | 'box': '\uD836[\uDC01-\uDC04]'
|
2310 | };
|
2311 | re$1.prefix = `(?:${re$1.sort}(?:${re$1.symbol})+)`;
|
2312 | re$1.spatial = `${re$1.symbol}${re$1.coord}`;
|
2313 | re$1.signbox = `${re$1.box}${re$1.coord}(?:${re$1.spatial})*`;
|
2314 | re$1.sign = `${re$1.prefix}?${re$1.signbox}`;
|
2315 | re$1.sortable = `${re$1.prefix}${re$1.signbox}`;
|
2316 |
|
2317 |
|
2318 |
|
2319 |
|
2320 |
|
2321 |
|
2322 |
|
2323 |
|
2324 |
|
2325 |
|
2326 |
|
2327 |
|
2328 |
|
2329 |
|
2330 |
|
2331 |
|
2332 |
|
2333 |
|
2334 |
|
2335 |
|
2336 |
|
2337 |
|
2338 | let re = {
|
2339 | 'colorize': 'C',
|
2340 | 'colorhex': '(?:[0-9a-fA-F]{3}){1,2}',
|
2341 | 'colorname': '[a-zA-Z]+',
|
2342 | 'padding': 'P[0-9]{2}',
|
2343 | 'zoom': 'Z(?:[0-9]+(?:\\.[0-9]+)?|x)',
|
2344 | 'classbase': '-?[_a-zA-Z][_a-zA-Z0-9-]{0,100}',
|
2345 | 'id': '[a-zA-Z][_a-zA-Z0-9-]{0,100}'
|
2346 | };
|
2347 | re.colorbase = `(?:${re.colorhex}|${re.colorname})`;
|
2348 | re.color = `_${re.colorbase}_`;
|
2349 | re.colors = `_${re.colorbase}(?:,${re.colorbase})?_`;
|
2350 | re.background = `G${re.color}`;
|
2351 | re.detail = `D${re.colors}`;
|
2352 | re.detailsym = `D[0-9]{2}${re.colors}`;
|
2353 | re.classes = `${re.classbase}(?: ${re.classbase})*`;
|
2354 | re.full = `-(${re.colorize})?(${re.padding})?(${re.background})?(${re.detail})?(${re.zoom})?(?:-((?:${re.detailsym})*))?(?:-(${re.classes})?!(?:(${re.id})!)?)?`;
|
2355 |
|
2356 | const prefixColor = color => {
|
2357 | const regex = new RegExp(`^${re.colorhex}$`);
|
2358 | return (regex.test(color) ? '#' : '') + color;
|
2359 | };
|
2360 |
|
2361 | const definedProps = obj => Object.fromEntries(Object.entries(obj).filter(([k, v]) => v !== undefined));
|
2362 |
|
2363 |
|
2364 |
|
2365 |
|
2366 |
|
2367 |
|
2368 |
|
2369 |
|
2370 |
|
2371 |
|
2372 |
|
2373 |
|
2374 |
|
2375 |
|
2376 |
|
2377 |
|
2378 |
|
2379 | const parse$1 = styleString => {
|
2380 | const regex = `^${re.full}`;
|
2381 | const m = (typeof styleString === 'string' ? styleString.match(new RegExp(regex)) : []) || [];
|
2382 | return definedProps({
|
2383 | 'colorize': !m[1] ? undefined : !!m[1],
|
2384 | 'padding': !m[2] ? undefined : parseInt(m[2].slice(1)),
|
2385 | 'background': !m[3] ? undefined : prefixColor(m[3].slice(2, -1)),
|
2386 | 'detail': !m[4] ? undefined : m[4].slice(2, -1).split(',').map(prefixColor),
|
2387 | 'zoom': !m[5] ? undefined : m[5] === 'Zx' ? 'x' : parseFloat(m[5].slice(1)),
|
2388 | 'detailsym': !m[6] ? undefined : m[6].match(new RegExp(re.detailsym, 'g')).map(val => {
|
2389 | const parts = val.split('_');
|
2390 | const detail = parts[1].split(',').map(prefixColor);
|
2391 | return {
|
2392 | 'index': parseInt(parts[0].slice(1)),
|
2393 | 'detail': detail
|
2394 | };
|
2395 | }),
|
2396 | 'classes': !m[7] ? undefined : m[7],
|
2397 | 'id': !m[8] ? undefined : m[8]
|
2398 | });
|
2399 | };
|
2400 |
|
2401 |
|
2402 |
|
2403 |
|
2404 |
|
2405 |
|
2406 |
|
2407 |
|
2408 |
|
2409 |
|
2410 |
|
2411 |
|
2412 |
|
2413 |
|
2414 |
|
2415 |
|
2416 |
|
2417 | const swu2num = swuNum => parseInt(swuNum.codePointAt(0)) - 0x1D80C + 250;
|
2418 |
|
2419 |
|
2420 |
|
2421 |
|
2422 |
|
2423 |
|
2424 |
|
2425 |
|
2426 |
|
2427 |
|
2428 |
|
2429 |
|
2430 | const swu2coord = swuCoord => [swu2num(swuCoord.slice(0, 2)), swu2num(swuCoord.slice(2, 4))];
|
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 |
|
2436 |
|
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 |
|
2442 |
|
2443 | const swu2code = swuSym => parseInt(swuSym.codePointAt(0));
|
2444 |
|
2445 | const parse = {
|
2446 | |
2447 |
|
2448 |
|
2449 |
|
2450 |
|
2451 |
|
2452 |
|
2453 |
|
2454 |
|
2455 |
|
2456 |
|
2457 |
|
2458 |
|
2459 |
|
2460 | symbol: swuSym => {
|
2461 | const regex = `^(${re$1.symbol})(${re$1.coord})?(${re.full})?`;
|
2462 | const symbol = typeof swuSym === 'string' ? swuSym.match(new RegExp(regex)) : undefined;
|
2463 | return {
|
2464 | 'symbol': symbol ? symbol[1] : undefined,
|
2465 | 'coord': symbol && symbol[2] ? swu2coord(symbol[2]) : undefined,
|
2466 | 'style': symbol ? symbol[3] : undefined
|
2467 | };
|
2468 | },
|
2469 |
|
2470 | |
2471 |
|
2472 |
|
2473 |
|
2474 |
|
2475 |
|
2476 |
|
2477 |
|
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 |
|
2487 |
|
2488 |
|
2489 |
|
2490 |
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 |
|
2500 |
|
2501 |
|
2502 |
|
2503 | sign: swuSign => {
|
2504 | const regex = `^(${re$1.prefix})?(${re$1.signbox})(${re.full})?`;
|
2505 | const sign = typeof swuSign === 'string' ? swuSign.match(new RegExp(regex)) : undefined;
|
2506 |
|
2507 | if (sign) {
|
2508 | return {
|
2509 | 'sequence': sign[1] ? sign[1].slice(2).match(/.{2}/g) : undefined,
|
2510 | 'box': sign[2].slice(0, 2),
|
2511 | 'max': swu2coord(sign[2].slice(2, 6)),
|
2512 | 'spatials': sign[2].length < 7 ? undefined : sign[2].slice(6).match(/(.{6})/g).map(m => {
|
2513 | return {
|
2514 | symbol: m.slice(0, 2),
|
2515 | coord: swu2coord(m.slice(2))
|
2516 | };
|
2517 | }),
|
2518 | 'style': sign[3]
|
2519 | };
|
2520 | } else {
|
2521 | return {};
|
2522 | }
|
2523 | },
|
2524 |
|
2525 | |
2526 |
|
2527 |
|
2528 |
|
2529 |
|
2530 |
|
2531 |
|
2532 |
|
2533 |
|
2534 |
|
2535 |
|
2536 |
|
2537 |
|
2538 |
|
2539 | text: swuText => {
|
2540 | if (typeof swuText !== 'string') return [];
|
2541 | const regex = `(${re$1.sign}(${re.full})?|${re$1.spatial}(${re.full})?)`;
|
2542 | const matches = swuText.match(new RegExp(regex, 'g'));
|
2543 | return matches ? [...matches] : [];
|
2544 | }
|
2545 | };
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 |
|
2555 |
|
2556 |
|
2557 |
|
2558 |
|
2559 |
|
2560 |
|
2561 |
|
2562 |
|
2563 |
|
2564 |
|
2565 |
|
2566 | const info = swu => {
|
2567 | let lanes = {
|
2568 | '𝠁': 0,
|
2569 | '𝠂': -1,
|
2570 | '𝠃': 0,
|
2571 | '𝠄': 1
|
2572 | };
|
2573 | let parsed = parse.sign(swu);
|
2574 | let width, height, segment, x1, x2, y1, y2, lane;
|
2575 |
|
2576 | if (parsed.spatials) {
|
2577 | x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
2578 | x2 = parsed.max[0];
|
2579 | width = x2 - x1;
|
2580 | y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
2581 | y2 = parsed.max[1];
|
2582 | height = y2 - y1;
|
2583 | segment = 'sign';
|
2584 | lane = parsed.box;
|
2585 | } else {
|
2586 | parsed = parse.symbol(swu);
|
2587 | lane = "𝠃";
|
2588 |
|
2589 | if (parsed.coord) {
|
2590 | x1 = parsed.coord[0];
|
2591 | width = (500 - x1) * 2;
|
2592 | y1 = parsed.coord[1];
|
2593 | height = (500 - y1) * 2;
|
2594 | segment = 'symbol';
|
2595 | } else {
|
2596 | x1 = 490;
|
2597 | width = 20;
|
2598 | y1 = 490;
|
2599 | height = 20;
|
2600 | segment = 'none';
|
2601 | }
|
2602 | }
|
2603 |
|
2604 | let style = parse$1(parsed.style);
|
2605 | let zoom = style.zoom || 1;
|
2606 | let padding = style.padding || 0;
|
2607 | return {
|
2608 | minX: x1,
|
2609 | minY: y1,
|
2610 | width: width,
|
2611 | height: height,
|
2612 | segment: segment,
|
2613 | lane: lanes[lane],
|
2614 | padding: padding,
|
2615 | zoom: zoom
|
2616 | };
|
2617 | };
|
2618 |
|
2619 | const columnDefaults = {
|
2620 | 'height': 500,
|
2621 | 'width': 150,
|
2622 | 'offset': 50,
|
2623 | 'pad': 20,
|
2624 | 'margin': 5,
|
2625 | 'dynamic': false,
|
2626 | 'background': undefined,
|
2627 | 'punctuation': {
|
2628 | 'spacing': true,
|
2629 | 'pad': 30,
|
2630 | 'pull': true
|
2631 | },
|
2632 | 'style': {
|
2633 | 'detail': ['black', 'white'],
|
2634 | 'zoom': 1
|
2635 | }
|
2636 | };
|
2637 |
|
2638 |
|
2639 |
|
2640 |
|
2641 |
|
2642 |
|
2643 |
|
2644 |
|
2645 |
|
2646 |
|
2647 |
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 |
|
2668 | const columnDefaultsMerge = options => {
|
2669 | if (typeof options !== 'object') options = {};
|
2670 | return { ...columnDefaults,
|
2671 | ...options,
|
2672 | punctuation: { ...columnDefaults.punctuation,
|
2673 | ...options.punctuation
|
2674 | },
|
2675 | style: { ...columnDefaults.style,
|
2676 | ...options.style
|
2677 | }
|
2678 | };
|
2679 | };
|
2680 |
|
2681 |
|
2682 |
|
2683 |
|
2684 |
|
2685 |
|
2686 |
|
2687 |
|
2688 |
|
2689 |
|
2690 |
|
2691 |
|
2692 |
|
2693 |
|
2694 |
|
2695 |
|
2696 |
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 |
|
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 |
|
2708 |
|
2709 |
|
2710 |
|
2711 |
|
2712 |
|
2713 |
|
2714 |
|
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 |
|
2722 |
|
2723 |
|
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 |
|
2729 |
|
2730 |
|
2731 |
|
2732 |
|
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 |
|
2739 |
|
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 |
|
2745 |
|
2746 |
|
2747 |
|
2748 |
|
2749 |
|
2750 |
|
2751 |
|
2752 |
|
2753 |
|
2754 |
|
2755 |
|
2756 |
|
2757 |
|
2758 |
|
2759 |
|
2760 |
|
2761 | const columns = (swuText, options) => {
|
2762 | if (typeof swuText !== 'string') return {};
|
2763 | const values = columnDefaultsMerge(options);
|
2764 | let input = parse.text(swuText);
|
2765 | let cursor = 0;
|
2766 | let cols = [];
|
2767 | let col = [];
|
2768 | let plus = 0;
|
2769 | let center = parseInt(values.width / 2);
|
2770 | let maxHeight = values.height - values.margin;
|
2771 | let pullable = true;
|
2772 | let finalize = false;
|
2773 |
|
2774 | for (let val of input) {
|
2775 | let informed = info(val);
|
2776 | cursor += plus;
|
2777 |
|
2778 | if (values.punctuation.spacing) {
|
2779 | cursor += informed.segment == 'sign' ? values.pad : 0;
|
2780 | } else {
|
2781 | cursor += values.pad;
|
2782 | }
|
2783 |
|
2784 | finalize = cursor + informed.height > maxHeight;
|
2785 |
|
2786 | if (finalize && informed.segment == 'symbol' && values.punctuation.pull && pullable) {
|
2787 | finalize = false;
|
2788 | pullable = false;
|
2789 | }
|
2790 |
|
2791 | if (col.length == 0) {
|
2792 | finalize = false;
|
2793 | }
|
2794 |
|
2795 | if (finalize) {
|
2796 | cursor = values.pad;
|
2797 | cols.push(col);
|
2798 | col = [];
|
2799 | pullable = true;
|
2800 | }
|
2801 |
|
2802 | col.push(Object.assign(informed, {
|
2803 | x: center + values.offset * informed.lane - (500 - informed.minX) * informed.zoom * values.style.zoom,
|
2804 | y: cursor,
|
2805 | text: val
|
2806 | }));
|
2807 | cursor += informed.height * informed.zoom * values.style.zoom;
|
2808 |
|
2809 | if (values.punctuation.spacing) {
|
2810 | plus = informed.segment == 'sign' ? values.pad : values.punctuation.pad;
|
2811 | } else {
|
2812 | plus = values.pad;
|
2813 | }
|
2814 | }
|
2815 |
|
2816 | if (col.length) {
|
2817 | cols.push(col);
|
2818 | }
|
2819 |
|
2820 |
|
2821 | if (values.punctuation.pull) {
|
2822 | for (let col of cols) {
|
2823 | let last = col[col.length - 1];
|
2824 | let diff = last.y + last.height - (values.height - values.margin);
|
2825 |
|
2826 | if (diff > 0) {
|
2827 | let adj = parseInt(diff / col.length) + 1;
|
2828 |
|
2829 | for (let i in col) {
|
2830 | col[i].y -= adj * i + adj;
|
2831 | }
|
2832 | }
|
2833 | }
|
2834 | }
|
2835 |
|
2836 |
|
2837 | let widths = [];
|
2838 |
|
2839 | for (let col of cols) {
|
2840 | let min = [center - values.offset - values.pad];
|
2841 | let max = [center + values.offset + values.pad];
|
2842 |
|
2843 | for (let item of col) {
|
2844 | min.push(item.x - values.pad);
|
2845 | max.push(item.x + item.width + values.pad);
|
2846 | }
|
2847 |
|
2848 | min = Math.min(...min);
|
2849 | max = Math.max(...max);
|
2850 | let width = values.width;
|
2851 | let adj = 0;
|
2852 |
|
2853 | if (!values.dynamic) {
|
2854 | adj = center - parseInt((min + max) / 2);
|
2855 | } else {
|
2856 | width = max - min;
|
2857 | adj = -min;
|
2858 | }
|
2859 |
|
2860 | for (let item of col) {
|
2861 | item.x += adj;
|
2862 | }
|
2863 |
|
2864 | widths.push(width);
|
2865 | }
|
2866 |
|
2867 | return {
|
2868 | 'options': values,
|
2869 | 'widths': widths,
|
2870 | 'columns': cols
|
2871 | };
|
2872 | };
|
2873 |
|
2874 |
|
2875 |
|
2876 |
|
2877 |
|
2878 |
|
2879 | const category = [0x40001, 0x461e1, 0x4bca1, 0x4bfa1, 0x4e8e1, 0x4efa1, 0x4f2a1];
|
2880 |
|
2881 |
|
2882 |
|
2883 |
|
2884 |
|
2885 |
|
2886 |
|
2887 |
|
2888 | const ranges = {
|
2889 | 'all': [0x40001, 0x4f480],
|
2890 | 'writing': [0x40001, 0x4efa0],
|
2891 | 'hand': [0x40001, 0x461e0],
|
2892 | 'movement': [0x461e1, 0x4bca0],
|
2893 | 'dynamic': [0x4bca1, 0x4bfa0],
|
2894 | 'head': [0x4bfa1, 0x4e8e0],
|
2895 | 'hcenter': [0x4bfa1, 0x4e8e0],
|
2896 | 'vcenter': [0x4bfa1, 0x4ec40],
|
2897 | 'trunk': [0x4e8e1, 0x4ec40],
|
2898 | 'limb': [0x4ec41, 0x4efa0],
|
2899 | 'location': [0x4efa1, 0x4f2a0],
|
2900 | 'punctuation': [0x4f2a1, 0x4f480]
|
2901 | };
|
2902 |
|
2903 |
|
2904 |
|
2905 |
|
2906 |
|
2907 |
|
2908 |
|
2909 | const colors = ['#0000CC', '#CC0000', '#FF0099', '#006600', '#000000', '#884411', '#FF9900'];
|
2910 |
|
2911 |
|
2912 |
|
2913 |
|
2914 |
|
2915 |
|
2916 |
|
2917 |
|
2918 |
|
2919 |
|
2920 |
|
2921 | const colorize = swuSym => {
|
2922 | const parsed = parse.symbol(swuSym);
|
2923 | let color = '#000000';
|
2924 |
|
2925 | if (parsed.symbol) {
|
2926 | const code = swu2code(parsed.symbol);
|
2927 | const index = category.findIndex(val => val > code);
|
2928 | color = colors[index < 0 ? 6 : index - 1];
|
2929 | }
|
2930 |
|
2931 | return color;
|
2932 | };
|
2933 |
|
2934 |
|
2935 |
|
2936 |
|
2937 |
|
2938 |
|
2939 |
|
2940 |
|
2941 |
|
2942 |
|
2943 |
|
2944 |
|
2945 |
|
2946 |
|
2947 |
|
2948 |
|
2949 | const symbolSvgBody = swuSym => {
|
2950 | const parsed = parse.symbol(swuSym);
|
2951 | const blank = '';
|
2952 | if (!parsed.symbol) return blank;
|
2953 | let styling = parse$3(parsed.style);
|
2954 | let x1, y1, x2, y2;
|
2955 |
|
2956 | if (parsed.coord) {
|
2957 | x1 = parsed.coord[0];
|
2958 | y1 = parsed.coord[1];
|
2959 | x2 = 500 + (500 - x1);
|
2960 | y2 = 500 + (500 - y1);
|
2961 | } else {
|
2962 | let size = symbolSize(parsed.symbol);
|
2963 | if (!size) return blank;
|
2964 | x1 = 500 - parseInt((size[0] + 1) / 2);
|
2965 | y1 = 500 - parseInt((size[1] + 1) / 2);
|
2966 | x2 = 500 + (500 - x1);
|
2967 | y2 = 500 + (500 - y1);
|
2968 | }
|
2969 |
|
2970 | let symSvg = symbolText(parsed.symbol);
|
2971 | symSvg = ` <g transform="translate(${x1},${y1})">
|
2972 | ${symSvg}
|
2973 | </g>`;
|
2974 | let line;
|
2975 |
|
2976 | if (styling.colorize) {
|
2977 | line = colorize(parsed.symbol);
|
2978 | } else if (styling.detail) {
|
2979 | line = styling.detail[0];
|
2980 | }
|
2981 |
|
2982 | if (line) {
|
2983 | symSvg = symSvg.replace(/class="sym-line" fill="black"/, `class="sym-line" fill="${line}"`);
|
2984 | }
|
2985 |
|
2986 | let fill = styling.detail && styling.detail[1];
|
2987 |
|
2988 | if (fill) {
|
2989 | symSvg = symSvg.replace(/class="sym-fill" fill="white"/, `class="sym-fill" fill="${fill}"`);
|
2990 | }
|
2991 |
|
2992 | let background = '';
|
2993 |
|
2994 | if (styling.padding) {
|
2995 | x1 -= styling.padding;
|
2996 | y1 -= styling.padding;
|
2997 | x2 += styling.padding;
|
2998 | y2 += styling.padding;
|
2999 | }
|
3000 |
|
3001 | if (styling.background) {
|
3002 | background = `\n <rect x="${x1}" y="${y1}" width="${x2 - x1}" height="${y2 - y1}" style="fill:${styling.background};" />`;
|
3003 | }
|
3004 |
|
3005 | return ` <text font-size="0">${swuSym}</text>${background}
|
3006 | ${symSvg}`;
|
3007 | };
|
3008 |
|
3009 |
|
3010 |
|
3011 |
|
3012 |
|
3013 |
|
3014 |
|
3015 |
|
3016 |
|
3017 |
|
3018 |
|
3019 |
|
3020 |
|
3021 |
|
3022 |
|
3023 |
|
3024 |
|
3025 | const symbolSvg = swuSym => {
|
3026 | const parsed = parse.symbol(swuSym);
|
3027 | const blank = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>';
|
3028 | if (!parsed.symbol) return blank;
|
3029 | let styling = parse$3(parsed.style);
|
3030 | let x1, y1, x2, y2;
|
3031 |
|
3032 | if (parsed.coord) {
|
3033 | x1 = parsed.coord[0];
|
3034 | y1 = parsed.coord[1];
|
3035 | x2 = 500 + (500 - x1);
|
3036 | y2 = 500 + (500 - y1);
|
3037 | } else {
|
3038 | let size = symbolSize(parsed.symbol);
|
3039 | if (!size) return blank;
|
3040 | x1 = parseInt(500 - size[0] / 2);
|
3041 | y1 = parseInt(500 - size[1] / 2);
|
3042 | x2 = x1 + size[0];
|
3043 | y2 = y1 + size[1];
|
3044 | }
|
3045 |
|
3046 | let classes = '';
|
3047 |
|
3048 | if (styling.classes) {
|
3049 | classes = ` class="${styling.classes}"`;
|
3050 | }
|
3051 |
|
3052 | let id = '';
|
3053 |
|
3054 | if (styling.id) {
|
3055 | id = ` id="${styling.id}"`;
|
3056 | }
|
3057 |
|
3058 | if (styling.padding) {
|
3059 | x1 -= styling.padding;
|
3060 | y1 -= styling.padding;
|
3061 | x2 += styling.padding;
|
3062 | y2 += styling.padding;
|
3063 | }
|
3064 |
|
3065 | let sizing = '';
|
3066 |
|
3067 | if (styling.zoom != 'x') {
|
3068 | sizing = ` width="${(x2 - x1) * (styling.zoom ? styling.zoom : 1)}" height="${(y2 - y1) * (styling.zoom ? styling.zoom : 1)}"`;
|
3069 | }
|
3070 |
|
3071 | return `<svg${classes}${id} version="1.1" xmlns="http://www.w3.org/2000/svg"${sizing} viewBox="${x1} ${y1} ${x2 - x1} ${y2 - y1}">
|
3072 | ${symbolSvgBody(swuSym)}
|
3073 | </svg>`;
|
3074 | };
|
3075 |
|
3076 | const symbolCanvas = function (swuSym) {
|
3077 | const parsed = parse.symbol(swuSym);
|
3078 |
|
3079 | if (parsed.symbol) {
|
3080 | let size = symbolSize(parsed.symbol);
|
3081 |
|
3082 | if (size) {
|
3083 | const canvas = document.createElement('canvas');
|
3084 | const context = canvas.getContext('2d');
|
3085 | let styling = parse$3(parsed.style);
|
3086 | let line = 'black';
|
3087 |
|
3088 | if (styling.colorize) {
|
3089 | line = colorize(parsed.symbol);
|
3090 | } else if (styling.detail) {
|
3091 | line = styling.detail[0];
|
3092 | }
|
3093 |
|
3094 | let fill = styling.detail && styling.detail[1] || 'white';
|
3095 | let x1 = 500;
|
3096 | let x2 = x1 + size[0];
|
3097 | let y1 = 500;
|
3098 | let y2 = y1 + size[1];
|
3099 |
|
3100 | if (styling.padding) {
|
3101 | x1 -= styling.padding;
|
3102 | y1 -= styling.padding;
|
3103 | x2 += styling.padding;
|
3104 | y2 += styling.padding;
|
3105 | }
|
3106 |
|
3107 | let sizing = 1;
|
3108 |
|
3109 | if (styling.zoom != 'x') {
|
3110 | sizing = styling.zoom;
|
3111 | }
|
3112 |
|
3113 | let w = (x2 - x1) * sizing;
|
3114 | let h = (y2 - y1) * sizing;
|
3115 | canvas.width = w ? w : 1;
|
3116 | canvas.height = h ? h : 1;
|
3117 |
|
3118 | if (styling.background) {
|
3119 | context.rect(0, 0, w, h);
|
3120 | context.fillStyle = styling.background;
|
3121 | context.fill();
|
3122 | }
|
3123 |
|
3124 | context.font = 30 * sizing + "px 'SuttonSignWritingFill'";
|
3125 | context.fillStyle = fill;
|
3126 | context.fillText(symbolFill(parsed.symbol), (500 - x1) * sizing, (500 - y1) * sizing);
|
3127 | context.font = 30 * sizing + "px 'SuttonSignWritingLine'";
|
3128 | context.fillStyle = line;
|
3129 | context.fillText(symbolLine(parsed.symbol), (500 - x1) * sizing, (500 - y1) * sizing);
|
3130 | return canvas;
|
3131 | }
|
3132 | }
|
3133 | };
|
3134 |
|
3135 |
|
3136 |
|
3137 |
|
3138 |
|
3139 |
|
3140 |
|
3141 |
|
3142 |
|
3143 |
|
3144 |
|
3145 | const symbolPng = swuSym => {
|
3146 | const canvas = symbolCanvas(swuSym);
|
3147 | const png = canvas.toDataURL("image/png");
|
3148 | canvas.remove();
|
3149 | return png;
|
3150 | };
|
3151 |
|
3152 | const blank = null;
|
3153 |
|
3154 |
|
3155 |
|
3156 |
|
3157 |
|
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 |
|
3163 | const symbolNormalize = swuSym => {
|
3164 | const parsed = parse.symbol(swuSym);
|
3165 |
|
3166 | if (parsed.symbol) {
|
3167 | let size = symbolSize(parsed.symbol);
|
3168 |
|
3169 | if (size) {
|
3170 | return `${parsed.symbol}${coord2swu([500 - parseInt((size[0] + 1) / 2), 500 - parseInt((size[1] + 1) / 2)])}${parsed.style || ''}`;
|
3171 | }
|
3172 | } else {
|
3173 | return blank;
|
3174 | }
|
3175 | };
|
3176 |
|
3177 |
|
3178 |
|
3179 |
|
3180 |
|
3181 |
|
3182 |
|
3183 |
|
3184 |
|
3185 |
|
3186 |
|
3187 |
|
3188 |
|
3189 |
|
3190 |
|
3191 |
|
3192 |
|
3193 |
|
3194 |
|
3195 |
|
3196 |
|
3197 |
|
3198 |
|
3199 |
|
3200 |
|
3201 |
|
3202 |
|
3203 | const signSvgBody = swuSign => {
|
3204 | let parsed = parse.sign(swuSign);
|
3205 | const blank = '';
|
3206 |
|
3207 | if (parsed.spatials) {
|
3208 | let styling = parse$3(parsed.style);
|
3209 |
|
3210 | if (styling.detailsym) {
|
3211 | styling.detailsym.forEach(sym => {
|
3212 | if (parsed.spatials[sym.index - 1]) {
|
3213 | parsed.spatials[sym.index - 1].detail = sym.detail;
|
3214 | }
|
3215 | });
|
3216 | }
|
3217 |
|
3218 | let x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
3219 | let y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
3220 | let x2 = parsed.max[0];
|
3221 | let y2 = parsed.max[1];
|
3222 | let background = '';
|
3223 |
|
3224 | if (styling.padding) {
|
3225 | x1 -= styling.padding;
|
3226 | y1 -= styling.padding;
|
3227 | x2 += styling.padding;
|
3228 | y2 += styling.padding;
|
3229 | }
|
3230 |
|
3231 | if (styling.background) {
|
3232 | background = `\n <rect x="${x1}" y="${y1}" width="${x2 - x1}" height="${y2 - y1}" style="fill:${styling.background};" />`;
|
3233 | }
|
3234 |
|
3235 | let svg = ` <text font-size="0">${swuSign}</text>${background}`;
|
3236 | const line = styling.detail && styling.detail[0];
|
3237 | const fill = styling.detail && styling.detail[1];
|
3238 | svg += '\n' + parsed.spatials.map(spatial => {
|
3239 | let svg = symbolText(spatial.symbol);
|
3240 | let symLine = line;
|
3241 |
|
3242 | if (spatial.detail) {
|
3243 | symLine = spatial.detail[0];
|
3244 | } else if (styling.colorize) {
|
3245 | symLine = colorize(spatial.symbol);
|
3246 | }
|
3247 |
|
3248 | if (symLine) {
|
3249 | svg = svg.replace(/class="sym-line" fill="black"/, `class="sym-line" fill="${symLine}"`);
|
3250 | }
|
3251 |
|
3252 | let symFill = fill;
|
3253 |
|
3254 | if (spatial.detail && spatial.detail[1]) {
|
3255 | symFill = spatial.detail[1];
|
3256 | }
|
3257 |
|
3258 | if (symFill) {
|
3259 | svg = svg.replace(/class="sym-fill" fill="white"/, `class="sym-fill" fill="${symFill}"`);
|
3260 | }
|
3261 |
|
3262 | return ` <g transform="translate(${spatial.coord[0]},${spatial.coord[1]})">
|
3263 | ${svg}
|
3264 | </g>`;
|
3265 | }).join('\n');
|
3266 | return svg;
|
3267 | }
|
3268 |
|
3269 | return blank;
|
3270 | };
|
3271 |
|
3272 |
|
3273 |
|
3274 |
|
3275 |
|
3276 |
|
3277 |
|
3278 |
|
3279 |
|
3280 |
|
3281 |
|
3282 |
|
3283 |
|
3284 |
|
3285 |
|
3286 |
|
3287 |
|
3288 |
|
3289 |
|
3290 |
|
3291 |
|
3292 |
|
3293 |
|
3294 |
|
3295 |
|
3296 |
|
3297 |
|
3298 |
|
3299 |
|
3300 | const signSvg = swuSign => {
|
3301 | let parsed = parse.sign(swuSign);
|
3302 | const blank = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>';
|
3303 |
|
3304 | if (parsed.spatials) {
|
3305 | let styling = parse$3(parsed.style);
|
3306 | let x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
3307 | let y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
3308 | let x2 = parsed.max[0];
|
3309 | let y2 = parsed.max[1];
|
3310 | let classes = '';
|
3311 |
|
3312 | if (styling.classes) {
|
3313 | classes = ` class="${styling.classes}"`;
|
3314 | }
|
3315 |
|
3316 | let id = '';
|
3317 |
|
3318 | if (styling.id) {
|
3319 | id = ` id="${styling.id}"`;
|
3320 | }
|
3321 |
|
3322 | if (styling.padding) {
|
3323 | x1 -= styling.padding;
|
3324 | y1 -= styling.padding;
|
3325 | x2 += styling.padding;
|
3326 | y2 += styling.padding;
|
3327 | }
|
3328 |
|
3329 | let sizing = '';
|
3330 |
|
3331 | if (styling.zoom != 'x') {
|
3332 | sizing = ` width="${(x2 - x1) * (styling.zoom ? styling.zoom : 1)}" height="${(y2 - y1) * (styling.zoom ? styling.zoom : 1)}"`;
|
3333 | }
|
3334 |
|
3335 | let svg = `<svg${classes}${id} version="1.1" xmlns="http://www.w3.org/2000/svg"${sizing} viewBox="${x1} ${y1} ${x2 - x1} ${y2 - y1}">
|
3336 | `;
|
3337 | svg += signSvgBody(swuSign);
|
3338 | svg += '\n</svg>';
|
3339 | return svg;
|
3340 | }
|
3341 |
|
3342 | return blank;
|
3343 | };
|
3344 |
|
3345 | const signCanvas = function (swuSign) {
|
3346 | const parsed = parse.sign(swuSign);
|
3347 |
|
3348 | if (parsed.spatials) {
|
3349 | const canvas = document.createElement('canvas');
|
3350 | const context = canvas.getContext('2d');
|
3351 | let styling = parse$3(parsed.style);
|
3352 |
|
3353 | if (styling.detailsym) {
|
3354 | styling.detailsym.forEach(sym => {
|
3355 | if (parsed.spatials[sym.index - 1]) {
|
3356 | parsed.spatials[sym.index - 1].detail = sym.detail;
|
3357 | }
|
3358 | });
|
3359 | }
|
3360 |
|
3361 | let x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
3362 | let y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
3363 | let x2 = parsed.max[0];
|
3364 | let y2 = parsed.max[1];
|
3365 |
|
3366 | if (styling.padding) {
|
3367 | x1 -= styling.padding;
|
3368 | y1 -= styling.padding;
|
3369 | x2 += styling.padding;
|
3370 | y2 += styling.padding;
|
3371 | }
|
3372 |
|
3373 | let sizing = 1;
|
3374 |
|
3375 | if (styling.zoom != 'x') {
|
3376 | sizing = styling.zoom;
|
3377 | }
|
3378 |
|
3379 | let w = (x2 - x1) * sizing;
|
3380 | let h = (y2 - y1) * sizing;
|
3381 | canvas.width = w ? w : 1;
|
3382 | canvas.height = h ? h : 1;
|
3383 |
|
3384 | if (styling.background) {
|
3385 | context.rect(0, 0, w, h);
|
3386 | context.fillStyle = styling.background;
|
3387 | context.fill();
|
3388 | }
|
3389 |
|
3390 | const line = styling.detail && styling.detail[0] || "black";
|
3391 | const fill = styling.detail && styling.detail[1] || "white";
|
3392 | parsed.spatials.forEach(spatial => {
|
3393 | let symLine = line;
|
3394 |
|
3395 | if (spatial.detail) {
|
3396 | symLine = spatial.detail[0];
|
3397 | } else if (styling.colorize) {
|
3398 | symLine = colorize(spatial.symbol);
|
3399 | }
|
3400 |
|
3401 | let symFill = fill;
|
3402 |
|
3403 | if (spatial.detail && spatial.detail[1]) {
|
3404 | symFill = spatial.detail[1];
|
3405 | }
|
3406 |
|
3407 | context.font = 30 * sizing + "px 'SuttonSignWritingFill'";
|
3408 | context.fillStyle = symFill;
|
3409 | context.fillText(symbolFill(spatial.symbol), (spatial.coord[0] - x1) * sizing, (spatial.coord[1] - y1) * sizing);
|
3410 | context.font = 30 * sizing + "px 'SuttonSignWritingLine'";
|
3411 | context.fillStyle = symLine;
|
3412 | context.fillText(symbolLine(spatial.symbol), (spatial.coord[0] - x1) * sizing, (spatial.coord[1] - y1) * sizing);
|
3413 | });
|
3414 | return canvas;
|
3415 | }
|
3416 | };
|
3417 |
|
3418 |
|
3419 |
|
3420 |
|
3421 |
|
3422 |
|
3423 |
|
3424 |
|
3425 |
|
3426 |
|
3427 |
|
3428 | const signPng = swuSign => {
|
3429 | const canvas = signCanvas(swuSign);
|
3430 | const png = canvas.toDataURL("image/png");
|
3431 | canvas.remove();
|
3432 | return png;
|
3433 | };
|
3434 |
|
3435 |
|
3436 |
|
3437 |
|
3438 |
|
3439 |
|
3440 |
|
3441 |
|
3442 |
|
3443 |
|
3444 |
|
3445 | const signNormalize = swuSign => {
|
3446 | const parsed = parse.sign(swuSign);
|
3447 |
|
3448 | if (parsed.spatials) {
|
3449 | const symbolsizes = parsed.spatials.reduce((output, spatial) => {
|
3450 | const size = symbolSize(spatial.symbol);
|
3451 | output[spatial.symbol] = {
|
3452 | width: size[0],
|
3453 | height: size[1]
|
3454 | };
|
3455 | return output;
|
3456 | }, {});
|
3457 |
|
3458 | const bbox = symbols => {
|
3459 | const x1 = Math.min(...symbols.map(spatial => spatial.coord[0]));
|
3460 | const y1 = Math.min(...symbols.map(spatial => spatial.coord[1]));
|
3461 | const x2 = Math.max(...symbols.map(spatial => spatial.coord[0] + parseInt(symbolsizes[spatial.symbol].width)));
|
3462 | const y2 = Math.max(...symbols.map(spatial => spatial.coord[1] + parseInt(symbolsizes[spatial.symbol].height)));
|
3463 | return {
|
3464 | x1: x1,
|
3465 | y1: y1,
|
3466 | x2: x2,
|
3467 | y2: y2
|
3468 | };
|
3469 | };
|
3470 |
|
3471 | const hrange = ranges['hcenter'];
|
3472 | const hsyms = parsed.spatials.filter(spatial => {
|
3473 | const dec = parseInt(spatial.symbol.slice(1, 4), 16);
|
3474 | return hrange[0] <= dec && hrange[1] >= dec;
|
3475 | });
|
3476 | const vrange = ranges['vcenter'];
|
3477 | const vsyms = parsed.spatials.filter(spatial => {
|
3478 | const dec = parseInt(spatial.symbol.slice(1, 4), 16);
|
3479 | return vrange[0] <= dec && vrange[1] >= dec;
|
3480 | });
|
3481 | let abox = bbox(parsed.spatials);
|
3482 | let max = [abox.x2, abox.y2];
|
3483 |
|
3484 | if (hsyms.length) {
|
3485 | const hbox = bbox(hsyms);
|
3486 | abox.x1 = hbox.x1;
|
3487 | abox.x2 = hbox.x2;
|
3488 | }
|
3489 |
|
3490 | if (vsyms.length) {
|
3491 | const vbox = bbox(vsyms);
|
3492 | abox.y1 = vbox.y1;
|
3493 | abox.y2 = vbox.y2;
|
3494 | }
|
3495 |
|
3496 | const offset = [parseInt((abox.x2 + abox.x1) / 2) - 500, parseInt((abox.y2 + abox.y1) / 2) - 500];
|
3497 | const swuout = (parsed.sequence ? '𝠀' + parsed.sequence.join('') : '') + parsed.box + coord2swu([max[0] - offset[0], max[1] - offset[1]]) + parsed.spatials.map(spatial => spatial.symbol + coord2swu([spatial.coord[0] - offset[0], spatial.coord[1] - offset[1]])).join('') + (parsed.style || '');
|
3498 | return swuout;
|
3499 | }
|
3500 | };
|
3501 |
|
3502 |
|
3503 |
|
3504 |
|
3505 |
|
3506 |
|
3507 |
|
3508 |
|
3509 |
|
3510 |
|
3511 |
|
3512 |
|
3513 |
|
3514 |
|
3515 |
|
3516 |
|
3517 |
|
3518 |
|
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 |
|
3524 |
|
3525 |
|
3526 |
|
3527 |
|
3528 |
|
3529 |
|
3530 |
|
3531 |
|
3532 |
|
3533 |
|
3534 |
|
3535 |
|
3536 |
|
3537 |
|
3538 |
|
3539 |
|
3540 |
|
3541 |
|
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 |
|
3547 |
|
3548 |
|
3549 |
|
3550 |
|
3551 |
|
3552 |
|
3553 |
|
3554 |
|
3555 |
|
3556 |
|
3557 |
|
3558 |
|
3559 |
|
3560 |
|
3561 |
|
3562 |
|
3563 |
|
3564 |
|
3565 |
|
3566 |
|
3567 |
|
3568 |
|
3569 |
|
3570 |
|
3571 |
|
3572 |
|
3573 |
|
3574 |
|
3575 |
|
3576 |
|
3577 |
|
3578 |
|
3579 |
|
3580 |
|
3581 |
|
3582 |
|
3583 |
|
3584 |
|
3585 |
|
3586 |
|
3587 |
|
3588 |
|
3589 |
|
3590 |
|
3591 |
|
3592 |
|
3593 |
|
3594 |
|
3595 |
|
3596 | const columnSvg = (swuColumn, options) => {
|
3597 |
|
3598 | if (typeof options !== 'object') options = {};
|
3599 | const values = Object.assign(columnDefaults, options);
|
3600 | let x1 = 0;
|
3601 | let y1 = 0;
|
3602 | let x2 = values.width;
|
3603 | let y2 = values.height;
|
3604 | let background = '';
|
3605 |
|
3606 | if (values.background) {
|
3607 | background = `\n <rect x="${x1}" y="${y1}" width="${x2 - x1}" height="${y2 - y1}" style="fill:${values.background};" />`;
|
3608 | }
|
3609 |
|
3610 | let sizing = ` width="${values.width}" height="${values.height}"`;
|
3611 | let svg = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg"${sizing} viewBox="${x1} ${y1} ${x2 - x1} ${y2 - y1}">
|
3612 | <text font-size="0">${x1}</text>${background}`;
|
3613 | svg += swuColumn.map(item => {
|
3614 | const dash = item.text.indexOf('-');
|
3615 |
|
3616 | if (dash > 0) {
|
3617 | const itemStyle = item.text.substring(dash);
|
3618 | const newStyle = { ...values.style,
|
3619 | ...parse$3(itemStyle)
|
3620 | };
|
3621 | item.text = item.text.replace(itemStyle, compose(newStyle));
|
3622 | } else {
|
3623 | item.text += compose(values.style);
|
3624 | }
|
3625 |
|
3626 | item.zoom = item.zoom * values.style.zoom;
|
3627 | return '<g transform="translate(' + item.x + ',' + item.y + ') scale(' + item.zoom + ') translate(' + -item.minX + ',' + -item.minY + ') ">' + (item.segment == "sign" ? signSvgBody(item.text) : symbolSvgBody(item.text)) + '</g>';
|
3628 | }).join('\n');
|
3629 | svg += '\n</svg>';
|
3630 | return svg;
|
3631 | };
|
3632 |
|
3633 |
|
3634 |
|
3635 |
|
3636 |
|
3637 |
|
3638 |
|
3639 |
|
3640 |
|
3641 |
|
3642 |
|
3643 |
|
3644 |
|
3645 |
|
3646 |
|
3647 |
|
3648 |
|
3649 |
|
3650 |
|
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 |
|
3656 |
|
3657 |
|
3658 |
|
3659 |
|
3660 |
|
3661 |
|
3662 |
|
3663 |
|
3664 |
|
3665 |
|
3666 |
|
3667 |
|
3668 |
|
3669 |
|
3670 |
|
3671 |
|
3672 |
|
3673 |
|
3674 |
|
3675 |
|
3676 |
|
3677 |
|
3678 |
|
3679 |
|
3680 |
|
3681 |
|
3682 |
|
3683 |
|
3684 |
|
3685 |
|
3686 | const columnsSvg = function (swuText, options) {
|
3687 | if (typeof options !== 'object') options = {};
|
3688 | let values = columns(swuText, options);
|
3689 | let cols = values.columns.map((col, i) => {
|
3690 | return columnSvg(col, { ...values.options,
|
3691 | ...{
|
3692 | width: values.widths[i]
|
3693 | }
|
3694 | });
|
3695 | });
|
3696 | return cols;
|
3697 | };
|
3698 |
|
3699 | const columnCanvas = function (swuColumn, options) {
|
3700 | if (typeof options !== 'object') options = {};
|
3701 | const values = Object.assign(columnDefaults, options);
|
3702 | const canvas = document.createElement('canvas');
|
3703 | canvas.width = values.width;
|
3704 | canvas.height = values.height;
|
3705 | const context = canvas.getContext('2d');
|
3706 |
|
3707 | if (values.background) {
|
3708 | context.rect(0, 0, values.width, values.height);
|
3709 | context.fillStyle = values.background;
|
3710 | context.fill();
|
3711 | }
|
3712 |
|
3713 | swuColumn.map(item => {
|
3714 | const dash = item.text.indexOf('-');
|
3715 |
|
3716 | if (dash > 0) {
|
3717 | const itemStyle = item.text.substring(dash);
|
3718 | const newStyle = { ...values.style,
|
3719 | ...parse$3(itemStyle)
|
3720 | };
|
3721 | item.text = item.text.replace(itemStyle, compose(newStyle));
|
3722 | } else {
|
3723 | item.text += compose(values.style);
|
3724 | }
|
3725 |
|
3726 | item.zoom = item.zoom * values.style.zoom;
|
3727 | let parsed = {};
|
3728 |
|
3729 | if (item.segment == "sign") {
|
3730 | parsed = parse.sign(item.text);
|
3731 | } else {
|
3732 | let sym = parse.symbol(item.text);
|
3733 | parsed.style = sym.style;
|
3734 | parsed.spatials = [sym];
|
3735 | }
|
3736 |
|
3737 | let styling = parse$3(parsed.style);
|
3738 |
|
3739 | if (styling.background) {
|
3740 | context.fillStyle = styling.background;
|
3741 | context.fillRect(item.x - styling.padding * item.zoom, item.y - styling.padding * item.zoom, (item.width + styling.padding * 2) * item.zoom, (item.height + styling.padding * 2) * item.zoom);
|
3742 | }
|
3743 |
|
3744 | if (styling.detailsym) {
|
3745 | styling.detailsym.forEach(sym => {
|
3746 | if (parsed.spatials[sym.index - 1]) {
|
3747 | parsed.spatials[sym.index - 1].detail = sym.detail;
|
3748 | }
|
3749 | });
|
3750 | }
|
3751 |
|
3752 | const line = styling.detail && styling.detail[0] || "black";
|
3753 | const fill = styling.detail && styling.detail[1] || "white";
|
3754 | parsed.spatials.forEach(spatial => {
|
3755 | let symLine = line;
|
3756 |
|
3757 | if (spatial.detail) {
|
3758 | symLine = spatial.detail[0];
|
3759 | } else if (styling.colorize) {
|
3760 | symLine = colorize(spatial.symbol);
|
3761 | }
|
3762 |
|
3763 | let symFill = fill;
|
3764 |
|
3765 | if (spatial.detail && spatial.detail[1]) {
|
3766 | symFill = spatial.detail[1];
|
3767 | }
|
3768 |
|
3769 | context.font = 30 * item.zoom + "px 'SuttonSignWritingFill'";
|
3770 | context.fillStyle = symFill;
|
3771 | context.fillText(symbolFill(spatial.symbol), item.x + (spatial.coord[0] - item.minX) * item.zoom, item.y + (spatial.coord[1] - item.minY) * item.zoom);
|
3772 | context.font = 30 * item.zoom + "px 'SuttonSignWritingLine'";
|
3773 | context.fillStyle = symLine;
|
3774 | context.fillText(symbolLine(spatial.symbol), item.x + (spatial.coord[0] - item.minX) * item.zoom, item.y + (spatial.coord[1] - item.minY) * item.zoom);
|
3775 | });
|
3776 | });
|
3777 | return canvas;
|
3778 | };
|
3779 |
|
3780 |
|
3781 |
|
3782 |
|
3783 |
|
3784 |
|
3785 |
|
3786 |
|
3787 |
|
3788 |
|
3789 |
|
3790 |
|
3791 |
|
3792 |
|
3793 |
|
3794 |
|
3795 |
|
3796 |
|
3797 |
|
3798 |
|
3799 |
|
3800 |
|
3801 |
|
3802 |
|
3803 |
|
3804 |
|
3805 |
|
3806 |
|
3807 |
|
3808 |
|
3809 |
|
3810 |
|
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 |
|
3820 |
|
3821 |
|
3822 |
|
3823 |
|
3824 |
|
3825 |
|
3826 |
|
3827 |
|
3828 |
|
3829 |
|
3830 |
|
3831 |
|
3832 |
|
3833 |
|
3834 |
|
3835 |
|
3836 | const columnPng = (swuColumn, options) => {
|
3837 | const canvas = columnCanvas(swuColumn, options);
|
3838 | const png = canvas.toDataURL("image/png");
|
3839 | canvas.remove();
|
3840 | return png;
|
3841 | };
|
3842 |
|
3843 |
|
3844 |
|
3845 |
|
3846 |
|
3847 |
|
3848 |
|
3849 |
|
3850 |
|
3851 |
|
3852 |
|
3853 |
|
3854 |
|
3855 |
|
3856 |
|
3857 |
|
3858 | const columnsPng = function (swuText, options) {
|
3859 | if (typeof options !== 'object') options = {};
|
3860 | let values = columns(swuText, options);
|
3861 | let cols = values.columns.map((col, i) => {
|
3862 | return columnPng(col, { ...values.options,
|
3863 | ...{
|
3864 | width: values.widths[i]
|
3865 | }
|
3866 | });
|
3867 | });
|
3868 | return cols;
|
3869 | };
|
3870 |
|
3871 |
|
3872 |
|
3873 |
|
3874 |
|
3875 |
|
3876 | var index = Object.freeze({
|
3877 | __proto__: null,
|
3878 | symbolSize: symbolSize,
|
3879 | symbolLine: symbolLine,
|
3880 | symbolFill: symbolFill,
|
3881 | symbolText: symbolText,
|
3882 | symbolSvgBody: symbolSvgBody,
|
3883 | symbolSvg: symbolSvg,
|
3884 | symbolPng: symbolPng,
|
3885 | symbolNormalize: symbolNormalize,
|
3886 | signSvgBody: signSvgBody,
|
3887 | signSvg: signSvg,
|
3888 | signPng: signPng,
|
3889 | signNormalize: signNormalize,
|
3890 | columnSvg: columnSvg,
|
3891 | columnsSvg: columnsSvg,
|
3892 | columnPng: columnPng,
|
3893 | columnsPng: columnsPng
|
3894 | });
|
3895 |
|
3896 | export { index$2 as font, index$1 as fsw, index as swu };
|
3897 |
|
3898 |
|