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