1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | const num2swu$1 = num => String.fromCodePoint(0x1D80C + parseInt(num) - 250);
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | const coord2swu$1 = coord => coord.map(num => num2swu$1(num)).join('');
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | const swu2code$1 = swuSym => parseInt(swuSym.codePointAt(0));
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | const code2swu = code => String.fromCodePoint(code);
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | const swu2id = swuSym => swu2code$1(swuSym) - 0x40000;
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | const swu2key = swuSym => {
|
84 | const symcode = swu2code$1(swuSym) - 0x40001;
|
85 | const base = parseInt(symcode / 96);
|
86 | const fill = parseInt((symcode - base * 96) / 16);
|
87 | const rotation = parseInt(symcode - base * 96 - fill * 16);
|
88 | return 'S' + (base + 0x100).toString(16) + fill.toString(16) + rotation.toString(16);
|
89 | };
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | 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));
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 | let re$1 = {
|
128 | 'symbol': '(?:(?:\uD8C0[\uDC01-\uDFFF])|(?:[\uD8C1-\uD8FC][\uDC00-\uDFFF])|(?:\uD8FD[\uDC00-\uDC80]))',
|
129 | 'coord': '(?:\uD836[\uDC0C-\uDDFF]){2}',
|
130 | 'sort': '\uD836\uDC00',
|
131 | 'box': '\uD836[\uDC01-\uDC04]'
|
132 | };
|
133 | re$1.prefix = `(?:${re$1.sort}(?:${re$1.symbol})+)`;
|
134 | re$1.spatial = `${re$1.symbol}${re$1.coord}`;
|
135 | re$1.signbox = `${re$1.box}${re$1.coord}(?:${re$1.spatial})*`;
|
136 | re$1.sign = `${re$1.prefix}?${re$1.signbox}`;
|
137 | re$1.sortable = `${re$1.prefix}${re$1.signbox}`;
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | let re$2 = {
|
161 | 'colorize': 'C',
|
162 | 'colorhex': '(?:[0-9a-fA-F]{3}){1,2}',
|
163 | 'colorname': '[a-zA-Z]+',
|
164 | 'padding': 'P[0-9]{2}',
|
165 | 'zoom': 'Z(?:[0-9]+(?:\\.[0-9]+)?|x)',
|
166 | 'classbase': '-?[_a-zA-Z][_a-zA-Z0-9-]{0,100}',
|
167 | 'id': '[a-zA-Z][_a-zA-Z0-9-]{0,100}'
|
168 | };
|
169 | re$2.colorbase = `(?:${re$2.colorhex}|${re$2.colorname})`;
|
170 | re$2.color = `_${re$2.colorbase}_`;
|
171 | re$2.colors = `_${re$2.colorbase}(?:,${re$2.colorbase})?_`;
|
172 | re$2.background = `G${re$2.color}`;
|
173 | re$2.detail = `D${re$2.colors}`;
|
174 | re$2.detailsym = `D[0-9]{2}${re$2.colors}`;
|
175 | re$2.classes = `${re$2.classbase}(?: ${re$2.classbase})*`;
|
176 | 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})!)?)?`;
|
177 |
|
178 | const prefixColor$1 = color => {
|
179 | const regex = new RegExp(`^${re$2.colorhex}$`);
|
180 | return (regex.test(color) ? '#' : '') + color;
|
181 | };
|
182 | const definedProps$1 = obj => Object.fromEntries(Object.entries(obj).filter(([k, v]) => v !== undefined));
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 | const parse$1 = styleString => {
|
200 | const regex = `^${re$2.full}`;
|
201 | const m = (typeof styleString === 'string' ? styleString.match(new RegExp(regex)) : []) || [];
|
202 | return definedProps$1({
|
203 | 'colorize': !m[1] ? undefined : !!m[1],
|
204 | 'padding': !m[2] ? undefined : parseInt(m[2].slice(1)),
|
205 | 'background': !m[3] ? undefined : prefixColor$1(m[3].slice(2, -1)),
|
206 | 'detail': !m[4] ? undefined : m[4].slice(2, -1).split(',').map(prefixColor$1),
|
207 | 'zoom': !m[5] ? undefined : m[5] === 'Zx' ? 'x' : parseFloat(m[5].slice(1)),
|
208 | 'detailsym': !m[6] ? undefined : m[6].match(new RegExp(re$2.detailsym, 'g')).map(val => {
|
209 | const parts = val.split('_');
|
210 | const detail = parts[1].split(',').map(prefixColor$1);
|
211 | return {
|
212 | 'index': parseInt(parts[0].slice(1)),
|
213 | 'detail': detail
|
214 | };
|
215 | }),
|
216 | 'classes': !m[7] ? undefined : m[7],
|
217 | 'id': !m[8] ? undefined : m[8]
|
218 | });
|
219 | };
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 | const swu2num = swuNum => parseInt(swuNum.codePointAt(0)) - 0x1D80C + 250;
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | const num2swu = num => String.fromCodePoint(0x1D80C + parseInt(num) - 250);
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 | const swu2coord = swuCoord => [swu2num(swuCoord.slice(0, 2)), swu2num(swuCoord.slice(2, 4))];
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 | const coord2swu = coord => coord.map(num => num2swu(num)).join('');
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 | const swu2code = swuSym => parseInt(swuSym.codePointAt(0));
|
285 |
|
286 | const parse$2 = {
|
287 | |
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 | symbol: swuSym => {
|
302 | const regex = `^(${re$1.symbol})(${re$1.coord})?(${re$2.full})?`;
|
303 | const symbol = typeof swuSym === 'string' ? swuSym.match(new RegExp(regex)) : undefined;
|
304 | return {
|
305 | 'symbol': symbol ? symbol[1] : undefined,
|
306 | 'coord': symbol && symbol[2] ? swu2coord(symbol[2]) : undefined,
|
307 | 'style': symbol ? symbol[3] : undefined
|
308 | };
|
309 | },
|
310 | |
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 | sign: swuSign => {
|
344 | const regex = `^(${re$1.prefix})?(${re$1.signbox})(${re$2.full})?`;
|
345 | const sign = typeof swuSign === 'string' ? swuSign.match(new RegExp(regex)) : undefined;
|
346 | if (sign) {
|
347 | return {
|
348 | 'sequence': sign[1] ? sign[1].slice(2).match(/.{2}/g) : undefined,
|
349 | 'box': sign[2].slice(0, 2),
|
350 | 'max': swu2coord(sign[2].slice(2, 6)),
|
351 | 'spatials': sign[2].length < 7 ? undefined : sign[2].slice(6).match(/(.{6})/g).map(m => {
|
352 | return {
|
353 | symbol: m.slice(0, 2),
|
354 | coord: swu2coord(m.slice(2))
|
355 | };
|
356 | }),
|
357 | 'style': sign[3]
|
358 | };
|
359 | } else {
|
360 | return {};
|
361 | }
|
362 | },
|
363 | |
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 | text: swuText => {
|
378 | if (typeof swuText !== 'string') return [];
|
379 | const regex = `(${re$1.sign}(${re$2.full})?|${re$1.spatial}(${re$2.full})?)`;
|
380 | const matches = swuText.match(new RegExp(regex, 'g'));
|
381 | return matches ? [...matches] : [];
|
382 | }
|
383 | };
|
384 |
|
385 | const compose$1 = {
|
386 | |
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 | symbol: swuSymObject => {
|
401 | if (typeof swuSymObject !== 'object' || swuSymObject === null) return undefined;
|
402 | if (typeof swuSymObject.symbol === 'string') {
|
403 | const symbol = (swuSymObject.symbol.match(re$1.symbol) || [''])[0];
|
404 | if (symbol) {
|
405 | const x = swuSymObject.coord && swuSymObject.coord[0] || '';
|
406 | const y = swuSymObject.coord && swuSymObject.coord[1] || '';
|
407 | const coord = x && y ? coord2swu([x, y]) : '';
|
408 | const styleStr = typeof swuSymObject.style === 'string' && (swuSymObject.style.match(re$2.full) || [''])[0] || '';
|
409 | return symbol + coord + styleStr;
|
410 | }
|
411 | }
|
412 | return undefined;
|
413 | },
|
414 | |
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
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 |
|
447 | sign: swuSignObject => {
|
448 | if (typeof swuSignObject !== 'object' || swuSignObject === null) return undefined;
|
449 | let box = typeof swuSignObject.box !== 'string' ? '𝠃' : (swuSignObject.box + '𝠃').match(re$1.box);
|
450 | const x = swuSignObject.max && swuSignObject.max[0] || '';
|
451 | const y = swuSignObject.max && swuSignObject.max[1] || '';
|
452 | const max = x && y ? coord2swu([x, y]) : undefined;
|
453 | if (!max) return undefined;
|
454 | let prefix = '';
|
455 | if (swuSignObject.sequence && Array.isArray(swuSignObject.sequence)) {
|
456 | prefix = swuSignObject.sequence.map(key => (key.match(re$1.symbol) || [''])[0]).join('');
|
457 | prefix = prefix ? '𝠀' + prefix : '';
|
458 | }
|
459 | let signbox = '';
|
460 | if (swuSignObject.spatials && Array.isArray(swuSignObject.spatials)) {
|
461 | signbox = swuSignObject.spatials.map(spatial => {
|
462 | if (typeof spatial.symbol === 'string') {
|
463 | const symbol = (spatial.symbol.match(re$1.symbol) || [''])[0];
|
464 | if (symbol) {
|
465 | const x = spatial.coord && spatial.coord[0] || '';
|
466 | const y = spatial.coord && spatial.coord[1] || '';
|
467 | const coord = x && y ? coord2swu([x, y]) : '';
|
468 | if (coord) {
|
469 | return symbol + coord;
|
470 | }
|
471 | }
|
472 | }
|
473 | return '';
|
474 | }).join('');
|
475 | }
|
476 | const styleStr = typeof swuSignObject.style === 'string' && (swuSignObject.style.match(re$2.full) || [''])[0] || '';
|
477 | return prefix + box + max + signbox + styleStr;
|
478 | }
|
479 | };
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 | const info = swu => {
|
501 | let lanes = {
|
502 | '𝠁': 0,
|
503 | '𝠂': -1,
|
504 | '𝠃': 0,
|
505 | '𝠄': 1
|
506 | };
|
507 | let parsed = parse$2.sign(swu);
|
508 | let width, height, segment, x1, x2, y1, y2, lane;
|
509 | if (parsed.spatials) {
|
510 | x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
511 | x2 = parsed.max[0];
|
512 | width = x2 - x1;
|
513 | y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
514 | y2 = parsed.max[1];
|
515 | height = y2 - y1;
|
516 | segment = 'sign';
|
517 | lane = parsed.box;
|
518 | } else {
|
519 | parsed = parse$2.symbol(swu);
|
520 | lane = "𝠃";
|
521 | if (parsed.coord) {
|
522 | x1 = parsed.coord[0];
|
523 | width = (500 - x1) * 2;
|
524 | y1 = parsed.coord[1];
|
525 | height = (500 - y1) * 2;
|
526 | segment = 'symbol';
|
527 | } else {
|
528 | x1 = 490;
|
529 | width = 20;
|
530 | y1 = 490;
|
531 | height = 20;
|
532 | segment = 'none';
|
533 | }
|
534 | }
|
535 | let style = parse$1(parsed.style);
|
536 | let zoom = style.zoom || 1;
|
537 | let padding = style.padding || 0;
|
538 | return {
|
539 | minX: x1,
|
540 | minY: y1,
|
541 | width: width,
|
542 | height: height,
|
543 | segment: segment,
|
544 | lane: lanes[lane],
|
545 | padding: padding,
|
546 | zoom: zoom
|
547 | };
|
548 | };
|
549 |
|
550 | const columnDefaults = {
|
551 | 'height': 500,
|
552 | 'width': 150,
|
553 | 'offset': 50,
|
554 | 'pad': 20,
|
555 | 'margin': 5,
|
556 | 'dynamic': false,
|
557 | 'background': undefined,
|
558 | 'punctuation': {
|
559 | 'spacing': true,
|
560 | 'pad': 30,
|
561 | 'pull': true
|
562 | },
|
563 | 'style': {
|
564 | 'detail': ['black', 'white'],
|
565 | 'zoom': 1
|
566 | }
|
567 | };
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 | const columnDefaultsMerge = options => {
|
600 | if (typeof options !== 'object') options = {};
|
601 | return {
|
602 | ...columnDefaults,
|
603 | ...options,
|
604 | punctuation: {
|
605 | ...columnDefaults.punctuation,
|
606 | ...options.punctuation
|
607 | },
|
608 | style: {
|
609 | ...columnDefaults.style,
|
610 | ...options.style
|
611 | }
|
612 | };
|
613 | };
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 | const columns = (swuText, options) => {
|
695 | if (typeof swuText !== 'string') return {};
|
696 | const values = columnDefaultsMerge(options);
|
697 | let input = parse$2.text(swuText);
|
698 | let cursor = 0;
|
699 | let cols = [];
|
700 | let col = [];
|
701 | let plus = 0;
|
702 | let center = parseInt(values.width / 2);
|
703 | let maxHeight = values.height - values.margin;
|
704 | let pullable = true;
|
705 | let finalize = false;
|
706 | for (let val of input) {
|
707 | let informed = info(val);
|
708 | cursor += plus;
|
709 | if (values.punctuation.spacing) {
|
710 | cursor += informed.segment == 'sign' ? values.pad : 0;
|
711 | } else {
|
712 | cursor += values.pad;
|
713 | }
|
714 | finalize = cursor + informed.height > maxHeight;
|
715 | if (finalize && informed.segment == 'symbol' && values.punctuation.pull && pullable) {
|
716 | finalize = false;
|
717 | pullable = false;
|
718 | }
|
719 | if (col.length == 0) {
|
720 | finalize = false;
|
721 | }
|
722 | if (finalize) {
|
723 | cursor = values.pad;
|
724 | cols.push(col);
|
725 | col = [];
|
726 | pullable = true;
|
727 | }
|
728 | col.push(Object.assign(informed, {
|
729 | x: center + values.offset * informed.lane - (500 - informed.minX) * informed.zoom * values.style.zoom,
|
730 | y: cursor,
|
731 | text: val
|
732 | }));
|
733 | cursor += informed.height * informed.zoom * values.style.zoom;
|
734 | if (values.punctuation.spacing) {
|
735 | plus = informed.segment == 'sign' ? values.pad : values.punctuation.pad;
|
736 | } else {
|
737 | plus = values.pad;
|
738 | }
|
739 | }
|
740 | if (col.length) {
|
741 | cols.push(col);
|
742 | }
|
743 |
|
744 |
|
745 | if (values.punctuation.pull) {
|
746 | for (let col of cols) {
|
747 | let last = col[col.length - 1];
|
748 | let diff = last.y + last.height - (values.height - values.margin);
|
749 | if (diff > 0) {
|
750 | let adj = parseInt(diff / col.length) + 1;
|
751 | for (let i in col) {
|
752 | col[i].y -= adj * i + adj;
|
753 | }
|
754 | }
|
755 | }
|
756 | }
|
757 |
|
758 |
|
759 | let widths = [];
|
760 | for (let col of cols) {
|
761 | let min = [center - values.offset - values.pad];
|
762 | let max = [center + values.offset + values.pad];
|
763 | for (let item of col) {
|
764 | min.push(item.x - values.pad);
|
765 | max.push(item.x + item.width + values.pad);
|
766 | }
|
767 | min = Math.min(...min);
|
768 | max = Math.max(...max);
|
769 | let width = values.width;
|
770 | let adj = 0;
|
771 | if (!values.dynamic) {
|
772 | adj = center - parseInt((min + max) / 2);
|
773 | } else {
|
774 | width = max - min;
|
775 | adj = -min;
|
776 | }
|
777 | for (let item of col) {
|
778 | item.x += adj;
|
779 | }
|
780 | widths.push(width);
|
781 | }
|
782 | return {
|
783 | 'options': values,
|
784 | 'widths': widths,
|
785 | 'columns': cols
|
786 | };
|
787 | };
|
788 |
|
789 |
|
790 |
|
791 |
|
792 |
|
793 |
|
794 | const category = [0x40001, 0x461e1, 0x4bca1, 0x4bfa1, 0x4e8e1, 0x4efa1, 0x4f2a1];
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 | const ranges = {
|
804 | 'all': [0x40001, 0x4f480],
|
805 | 'writing': [0x40001, 0x4efa0],
|
806 | 'hand': [0x40001, 0x461e0],
|
807 | 'movement': [0x461e1, 0x4bca0],
|
808 | 'dynamic': [0x4bca1, 0x4bfa0],
|
809 | 'head': [0x4bfa1, 0x4e8e0],
|
810 | 'hcenter': [0x4bfa1, 0x4e8e0],
|
811 | 'vcenter': [0x4bfa1, 0x4ec40],
|
812 | 'trunk': [0x4e8e1, 0x4ec40],
|
813 | 'limb': [0x4ec41, 0x4efa0],
|
814 | 'location': [0x4efa1, 0x4f2a0],
|
815 | 'punctuation': [0x4f2a1, 0x4f480]
|
816 | };
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 | const colors = ['#0000CC', '#CC0000', '#FF0099', '#006600', '#000000', '#884411', '#FF9900'];
|
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 |
|
832 |
|
833 |
|
834 |
|
835 | const colorize = swuSym => {
|
836 | const parsed = parse$2.symbol(swuSym);
|
837 | let color = '#000000';
|
838 | if (parsed.symbol) {
|
839 | const code = swu2code(parsed.symbol);
|
840 | const index = category.findIndex(val => val > code);
|
841 | color = colors[index < 0 ? 6 : index - 1];
|
842 | }
|
843 | return color;
|
844 | };
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 | let sizes = {};
|
851 | const zoom = 2;
|
852 | const bound = 76 * zoom;
|
853 | let context;
|
854 |
|
855 |
|
856 |
|
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 | const symbolSize$1 = function (id) {
|
866 | if (id in sizes) {
|
867 | return [...sizes[id]];
|
868 | }
|
869 | if (!context) {
|
870 | const canvaser = document.createElement("canvas");
|
871 | canvaser.width = bound;
|
872 | canvaser.height = bound;
|
873 | context = canvaser.getContext("2d", {
|
874 | willReadFrequently: true
|
875 | });
|
876 | }
|
877 | context.clearRect(0, 0, bound, bound);
|
878 | context.font = 30 * zoom + "px 'SuttonSignWritingLine'";
|
879 | context.fillText(String.fromCodePoint(id + 0xF0000), 0, 0);
|
880 | const imgData = context.getImageData(0, 0, bound, bound).data;
|
881 | let w, h, i, s;
|
882 | wloop: for (w = bound - 1; w >= 0; w--) {
|
883 | for (h = 0; h < bound; h += 1) {
|
884 | for (s = 0; s < 4; s += 1) {
|
885 | i = w * 4 + h * 4 * bound + s;
|
886 | if (imgData[i]) {
|
887 | break wloop;
|
888 | }
|
889 | }
|
890 | }
|
891 | }
|
892 | var width = w;
|
893 | hloop: for (h = bound - 1; h >= 0; h--) {
|
894 | for (w = 0; w < width; w += 1) {
|
895 | for (s = 0; s < 4; s += 1) {
|
896 | i = w * 4 + h * 4 * bound + s;
|
897 | if (imgData[i]) {
|
898 | break hloop;
|
899 | }
|
900 | }
|
901 | }
|
902 | }
|
903 | var height = h + 1;
|
904 | width = Math.ceil(width / zoom);
|
905 | height = Math.ceil(height / zoom);
|
906 |
|
907 | if (14394 == id) {
|
908 | width = 19;
|
909 | }
|
910 | 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)) {
|
911 | width = 20;
|
912 | }
|
913 | if (31921 == id) {
|
914 | width = 22;
|
915 | }
|
916 | if (38460 == id) {
|
917 | width = 23;
|
918 | }
|
919 | if ([20164, 20212].includes(id)) {
|
920 | width = 25;
|
921 | }
|
922 | if (31894 == id) {
|
923 | width = 28;
|
924 | }
|
925 | if (46698 == id) {
|
926 | width = 29;
|
927 | }
|
928 | if (29606 == id) {
|
929 | width = 30;
|
930 | }
|
931 | if (44855 == id) {
|
932 | width = 40;
|
933 | }
|
934 | if (32667 == id) {
|
935 | width = 50;
|
936 | }
|
937 | if ([11088, 11474, 11490, 11506].includes(id)) {
|
938 | height = 20;
|
939 | }
|
940 | if (6285 == id) {
|
941 | height = 21;
|
942 | }
|
943 | if (40804 == id) {
|
944 | height = 31;
|
945 | }
|
946 | if (41475 == id) {
|
947 | height = 36;
|
948 | }
|
949 |
|
950 |
|
951 | if (width == 0 && height == 0) {
|
952 | const sizefix = {
|
953 | 9: [15, 30],
|
954 | 10: [21, 30],
|
955 | 11: [30, 15],
|
956 | 12: [30, 21],
|
957 | 13: [15, 30],
|
958 | 14: [21, 30]
|
959 | };
|
960 | if (id in sizefix) {
|
961 | width = sizefix[id][0];
|
962 | height = sizefix[id][1];
|
963 | }
|
964 | }
|
965 | if (width == 0 && height == 0) {
|
966 | return undefined;
|
967 | }
|
968 | sizes[id] = [width, height];
|
969 | return [width, height];
|
970 | };
|
971 |
|
972 |
|
973 |
|
974 |
|
975 |
|
976 |
|
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 | const symbolSize = function (swu) {
|
983 | const parsed = parse$2.symbol(swu);
|
984 | if (!parsed.symbol) {
|
985 | return undefined;
|
986 | }
|
987 | return symbolSize$1(swu2id(swu));
|
988 | };
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 | const symbolLine$1 = function (id) {
|
1001 | return String.fromCodePoint(id + 0xF0000);
|
1002 | };
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 | const symbolFill$1 = function (id) {
|
1015 | return String.fromCodePoint(id + 0x100000);
|
1016 | };
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 | const symbolText$1 = function (id) {
|
1030 | return ` <text class="sym-fill" fill="white" style="pointer-events:none;font-family:'SuttonSignWritingFill';font-size:30px;">${symbolFill$1(id)}</text>
|
1031 | <text class="sym-line" fill="black" style="pointer-events:none;font-family:'SuttonSignWritingLine';font-size:30px;">${symbolLine$1(id)}</text>`;
|
1032 | };
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 | const symbolLine = function (swu) {
|
1045 | return symbolLine$1(swu2id(swu));
|
1046 | };
|
1047 |
|
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 | const symbolFill = function (swu) {
|
1059 | return symbolFill$1(swu2id(swu));
|
1060 | };
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 | const symbolText = function (swu) {
|
1074 | return symbolText$1(swu2id(swu));
|
1075 | };
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 | let re = {
|
1105 | 'colorize': 'C',
|
1106 | 'colorhex': '(?:[0-9a-fA-F]{3}){1,2}',
|
1107 | 'colorname': '[a-zA-Z]+',
|
1108 | 'padding': 'P[0-9]{2}',
|
1109 | 'zoom': 'Z(?:[0-9]+(?:\\.[0-9]+)?|x)',
|
1110 | 'classbase': '-?[_a-zA-Z][_a-zA-Z0-9-]{0,100}',
|
1111 | 'id': '[a-zA-Z][_a-zA-Z0-9-]{0,100}'
|
1112 | };
|
1113 | re.colorbase = `(?:${re.colorhex}|${re.colorname})`;
|
1114 | re.color = `_${re.colorbase}_`;
|
1115 | re.colors = `_${re.colorbase}(?:,${re.colorbase})?_`;
|
1116 | re.background = `G${re.color}`;
|
1117 | re.detail = `D${re.colors}`;
|
1118 | re.detailsym = `D[0-9]{2}${re.colors}`;
|
1119 | re.classes = `${re.classbase}(?: ${re.classbase})*`;
|
1120 | re.full = `-(${re.colorize})?(${re.padding})?(${re.background})?(${re.detail})?(${re.zoom})?(?:-((?:${re.detailsym})*))?(?:-(${re.classes})?!(?:(${re.id})!)?)?`;
|
1121 |
|
1122 | const prefixColor = color => {
|
1123 | const regex = new RegExp(`^${re.colorhex}$`);
|
1124 | return (regex.test(color) ? '#' : '') + color;
|
1125 | };
|
1126 | const definedProps = obj => Object.fromEntries(Object.entries(obj).filter(([k, v]) => v !== undefined));
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 | const parse = styleString => {
|
1144 | const regex = `^${re.full}`;
|
1145 | const m = (typeof styleString === 'string' ? styleString.match(new RegExp(regex)) : []) || [];
|
1146 | return definedProps({
|
1147 | 'colorize': !m[1] ? undefined : !!m[1],
|
1148 | 'padding': !m[2] ? undefined : parseInt(m[2].slice(1)),
|
1149 | 'background': !m[3] ? undefined : prefixColor(m[3].slice(2, -1)),
|
1150 | 'detail': !m[4] ? undefined : m[4].slice(2, -1).split(',').map(prefixColor),
|
1151 | 'zoom': !m[5] ? undefined : m[5] === 'Zx' ? 'x' : parseFloat(m[5].slice(1)),
|
1152 | 'detailsym': !m[6] ? undefined : m[6].match(new RegExp(re.detailsym, 'g')).map(val => {
|
1153 | const parts = val.split('_');
|
1154 | const detail = parts[1].split(',').map(prefixColor);
|
1155 | return {
|
1156 | 'index': parseInt(parts[0].slice(1)),
|
1157 | 'detail': detail
|
1158 | };
|
1159 | }),
|
1160 | 'classes': !m[7] ? undefined : m[7],
|
1161 | 'id': !m[8] ? undefined : m[8]
|
1162 | });
|
1163 | };
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 |
|
1179 |
|
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 |
|
1185 |
|
1186 |
|
1187 |
|
1188 |
|
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 | const compose = styleObject => {
|
1194 | if (typeof styleObject !== 'object' || styleObject === null) return undefined;
|
1195 |
|
1196 |
|
1197 | let style1 = '-';
|
1198 | style1 += !styleObject.colorize ? '' : 'C';
|
1199 | const padding = parseInt(styleObject.padding);
|
1200 | style1 += !padding || padding <= 0 || padding > 99 ? '' : 'P' + (padding > 9 ? padding : '0' + padding);
|
1201 | const background = !styleObject.background || !(typeof styleObject.background === 'string') ? undefined : styleObject.background.match(re.colorbase)[0];
|
1202 | style1 += !background ? '' : 'G_' + background + '_';
|
1203 | const detail1 = !styleObject.detail || !styleObject.detail[0] || !(typeof styleObject.detail[0] === 'string') ? undefined : styleObject.detail[0].match(re.colorbase)[0];
|
1204 | const detail2 = !styleObject.detail || !styleObject.detail[1] || !(typeof styleObject.detail[1] === 'string') ? undefined : styleObject.detail[1].match(re.colorbase)[0];
|
1205 | if (detail1) {
|
1206 | style1 += 'D_' + detail1;
|
1207 | if (detail2) {
|
1208 | style1 += ',' + detail2;
|
1209 | }
|
1210 | style1 += '_';
|
1211 | }
|
1212 | const zoom = styleObject.zoom === 'x' ? 'x' : parseFloat(styleObject.zoom);
|
1213 | style1 += !zoom || zoom <= 0 ? '' : 'Z' + zoom;
|
1214 | let style2 = '';
|
1215 | const detailsym = !styleObject.detailsym || !Array.isArray(styleObject.detailsym) ? [] : styleObject.detailsym.map(styleObject => {
|
1216 | const index = parseInt(styleObject.index);
|
1217 | if (!index || index <= 0 || index > 99) return '';
|
1218 | let style = 'D' + (index > 9 ? index : '0' + index);
|
1219 | const detail1 = !styleObject.detail || !styleObject.detail[0] ? undefined : styleObject.detail[0].match(re.colorbase)[0];
|
1220 | const detail2 = !styleObject.detail || !styleObject.detail[1] ? undefined : styleObject.detail[1].match(re.colorbase)[0];
|
1221 | if (detail1) {
|
1222 | style += '_' + detail1;
|
1223 | if (detail2) {
|
1224 | style += ',' + detail2;
|
1225 | }
|
1226 | style += '_';
|
1227 | }
|
1228 | return style;
|
1229 | });
|
1230 | style2 += detailsym.join('');
|
1231 | let style3 = '';
|
1232 | const classes = !styleObject.classes || !(typeof styleObject.classes === 'string') ? undefined : styleObject.classes.match(re.classes)[0];
|
1233 | style3 += !classes ? '' : classes;
|
1234 | const id = !styleObject.id || !(typeof styleObject.id === 'string') ? undefined : styleObject.id.match(re.id)[0];
|
1235 | style3 += classes || id ? '!' : '';
|
1236 | style3 += !id ? '' : id + '!';
|
1237 | return style1 + (style2 || style3 ? '-' + style2 : '') + (style3 ? '-' + style3 : '');
|
1238 | };
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 |
|
1248 |
|
1249 |
|
1250 |
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 |
|
1257 |
|
1258 | const symbolSvgBody = swuSym => {
|
1259 | const parsed = parse$2.symbol(swuSym);
|
1260 | const blank = '';
|
1261 | if (!parsed.symbol) return blank;
|
1262 | let styling = parse(parsed.style);
|
1263 | let x1, y1, x2, y2;
|
1264 | if (parsed.coord) {
|
1265 | x1 = parsed.coord[0];
|
1266 | y1 = parsed.coord[1];
|
1267 | x2 = 500 + (500 - x1);
|
1268 | y2 = 500 + (500 - y1);
|
1269 | } else {
|
1270 | let size = symbolSize(parsed.symbol);
|
1271 | if (!size) return blank;
|
1272 | x1 = 500 - parseInt((size[0] + 1) / 2);
|
1273 | y1 = 500 - parseInt((size[1] + 1) / 2);
|
1274 | x2 = 500 + (500 - x1);
|
1275 | y2 = 500 + (500 - y1);
|
1276 | }
|
1277 | let symSvg = symbolText(parsed.symbol);
|
1278 | symSvg = ` <g transform="translate(${x1},${y1})">
|
1279 | ${symSvg}
|
1280 | </g>`;
|
1281 | let line;
|
1282 | if (styling.colorize) {
|
1283 | line = colorize(parsed.symbol);
|
1284 | } else if (styling.detail) {
|
1285 | line = styling.detail[0];
|
1286 | }
|
1287 | if (line) {
|
1288 | symSvg = symSvg.replace(/class="sym-line" fill="black"/, `class="sym-line" fill="${line}"`);
|
1289 | }
|
1290 | let fill = styling.detail && styling.detail[1];
|
1291 | if (fill) {
|
1292 | symSvg = symSvg.replace(/class="sym-fill" fill="white"/, `class="sym-fill" fill="${fill}"`);
|
1293 | }
|
1294 | let background = '';
|
1295 | if (styling.padding) {
|
1296 | x1 -= styling.padding;
|
1297 | y1 -= styling.padding;
|
1298 | x2 += styling.padding;
|
1299 | y2 += styling.padding;
|
1300 | }
|
1301 | if (styling.background) {
|
1302 | background = `\n <rect x="${x1}" y="${y1}" width="${x2 - x1}" height="${y2 - y1}" style="fill:${styling.background};" />`;
|
1303 | }
|
1304 | return ` <text font-size="0">${swuSym}</text>${background}
|
1305 | ${symSvg}`;
|
1306 | };
|
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 |
|
1312 |
|
1313 |
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 | const symbolSvg = swuSym => {
|
1325 | const parsed = parse$2.symbol(swuSym);
|
1326 | const blank = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>';
|
1327 | if (!parsed.symbol) return blank;
|
1328 | let styling = parse(parsed.style);
|
1329 | let x1, y1, x2, y2;
|
1330 | if (parsed.coord) {
|
1331 | x1 = parsed.coord[0];
|
1332 | y1 = parsed.coord[1];
|
1333 | x2 = 500 + (500 - x1);
|
1334 | y2 = 500 + (500 - y1);
|
1335 | } else {
|
1336 | let size = symbolSize(parsed.symbol);
|
1337 | if (!size) return blank;
|
1338 | x1 = parseInt(500 - size[0] / 2);
|
1339 | y1 = parseInt(500 - size[1] / 2);
|
1340 | x2 = x1 + size[0];
|
1341 | y2 = y1 + size[1];
|
1342 | }
|
1343 | let classes = '';
|
1344 | if (styling.classes) {
|
1345 | classes = ` class="${styling.classes}"`;
|
1346 | }
|
1347 | let id = '';
|
1348 | if (styling.id) {
|
1349 | id = ` id="${styling.id}"`;
|
1350 | }
|
1351 | if (styling.padding) {
|
1352 | x1 -= styling.padding;
|
1353 | y1 -= styling.padding;
|
1354 | x2 += styling.padding;
|
1355 | y2 += styling.padding;
|
1356 | }
|
1357 | let sizing = '';
|
1358 | if (styling.zoom != 'x') {
|
1359 | sizing = ` width="${(x2 - x1) * (styling.zoom ? styling.zoom : 1)}" height="${(y2 - y1) * (styling.zoom ? styling.zoom : 1)}"`;
|
1360 | }
|
1361 | return `<svg${classes}${id} version="1.1" xmlns="http://www.w3.org/2000/svg"${sizing} viewBox="${x1} ${y1} ${x2 - x1} ${y2 - y1}">
|
1362 | ${symbolSvgBody(swuSym)}
|
1363 | </svg>`;
|
1364 | };
|
1365 |
|
1366 | const symbolCanvas = function (swuSym) {
|
1367 | const parsed = parse$2.symbol(swuSym);
|
1368 | if (parsed.symbol) {
|
1369 | let size = symbolSize(parsed.symbol);
|
1370 | if (size) {
|
1371 | const canvas = document.createElement('canvas');
|
1372 | const context = canvas.getContext('2d');
|
1373 | let styling = parse(parsed.style);
|
1374 | let line = 'black';
|
1375 | if (styling.colorize) {
|
1376 | line = colorize(parsed.symbol);
|
1377 | } else if (styling.detail) {
|
1378 | line = styling.detail[0];
|
1379 | }
|
1380 | let fill = styling.detail && styling.detail[1] || 'white';
|
1381 | let x1 = 500;
|
1382 | let x2 = x1 + size[0];
|
1383 | let y1 = 500;
|
1384 | let y2 = y1 + size[1];
|
1385 | if (styling.padding) {
|
1386 | x1 -= styling.padding;
|
1387 | y1 -= styling.padding;
|
1388 | x2 += styling.padding;
|
1389 | y2 += styling.padding;
|
1390 | }
|
1391 | let sizing = 1;
|
1392 | if (styling.zoom != 'x') {
|
1393 | sizing = styling.zoom;
|
1394 | }
|
1395 | let w = (x2 - x1) * sizing;
|
1396 | let h = (y2 - y1) * sizing;
|
1397 | canvas.width = w ? w : 1;
|
1398 | canvas.height = h ? h : 1;
|
1399 | if (styling.background) {
|
1400 | context.rect(0, 0, w, h);
|
1401 | context.fillStyle = styling.background;
|
1402 | context.fill();
|
1403 | }
|
1404 | context.font = 30 * sizing + "px 'SuttonSignWritingFill'";
|
1405 | context.fillStyle = fill;
|
1406 | context.fillText(symbolFill(parsed.symbol), (500 - x1) * sizing, (500 - y1) * sizing);
|
1407 | context.font = 30 * sizing + "px 'SuttonSignWritingLine'";
|
1408 | context.fillStyle = line;
|
1409 | context.fillText(symbolLine(parsed.symbol), (500 - x1) * sizing, (500 - y1) * sizing);
|
1410 | return canvas;
|
1411 | }
|
1412 | }
|
1413 | };
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 |
|
1419 |
|
1420 |
|
1421 |
|
1422 |
|
1423 |
|
1424 |
|
1425 | const symbolPng = swuSym => {
|
1426 | const canvas = symbolCanvas(swuSym);
|
1427 | const png = canvas.toDataURL("image/png");
|
1428 | canvas.remove();
|
1429 | return png;
|
1430 | };
|
1431 |
|
1432 | const blank = null;
|
1433 |
|
1434 |
|
1435 |
|
1436 |
|
1437 |
|
1438 |
|
1439 |
|
1440 |
|
1441 |
|
1442 |
|
1443 |
|
1444 | const symbolNormalize = swuSym => {
|
1445 | const parsed = parse$2.symbol(swuSym);
|
1446 | if (parsed.symbol) {
|
1447 | let size = symbolSize(parsed.symbol);
|
1448 | if (size) {
|
1449 | return `${parsed.symbol}${coord2swu$1([500 - parseInt((size[0] + 1) / 2), 500 - parseInt((size[1] + 1) / 2)])}${parsed.style || ''}`;
|
1450 | }
|
1451 | } else {
|
1452 | return blank;
|
1453 | }
|
1454 | };
|
1455 |
|
1456 |
|
1457 |
|
1458 |
|
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 |
|
1464 |
|
1465 |
|
1466 | const symbolMirror = swuSym => {
|
1467 | let parsed = parse$2.symbol(swuSym);
|
1468 | if (!parsed.symbol) {
|
1469 | return swuSym;
|
1470 | }
|
1471 | const size = symbolSize(parsed.symbol);
|
1472 | if (!size) {
|
1473 | return swuSym;
|
1474 | }
|
1475 | parsed.symbol = swu2key(parsed.symbol);
|
1476 | const base = parsed.symbol.slice(0, 4);
|
1477 | let fill = parsed.symbol.slice(4, 5);
|
1478 | let rot = parseInt(parsed.symbol.slice(5, 6), 16);
|
1479 | const key1 = base + "08";
|
1480 | const key2 = base + "18";
|
1481 | var rAdd;
|
1482 | if (symbolSize(key2swu(key1)) || symbolSize(key2swu(key2))) {
|
1483 | rAdd = 8;
|
1484 | } else {
|
1485 | if (rot === 0 || rot == 4) {
|
1486 | rAdd = 0;
|
1487 | }
|
1488 | if (rot == 1 || rot == 5) {
|
1489 | rAdd = 6;
|
1490 | }
|
1491 | if (rot == 2 || rot == 6) {
|
1492 | rAdd = 4;
|
1493 | }
|
1494 | if (rot == 3 || rot == 7) {
|
1495 | rAdd = 2;
|
1496 | }
|
1497 | }
|
1498 | let key = '';
|
1499 | while (!key || !symbolSize(key2swu(key))) {
|
1500 | rot += rAdd;
|
1501 | if (rot > 7 && rAdd < 8) {
|
1502 | rot = rot - 8;
|
1503 | }
|
1504 | if (rot > 15) {
|
1505 | rot = rot - 16;
|
1506 | }
|
1507 | key = base + fill + rot.toString(16);
|
1508 | }
|
1509 | parsed.symbol = key2swu(key);
|
1510 | return compose$1.symbol(parsed);
|
1511 | };
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 | const symbolRotate = (swuSym, clockwise = true) => {
|
1525 | let parsed = parse$2.symbol(swuSym);
|
1526 | if (!parsed.symbol) {
|
1527 | return swuSym;
|
1528 | }
|
1529 | const size = symbolSize(parsed.symbol);
|
1530 | if (!size) {
|
1531 | return swuSym;
|
1532 | }
|
1533 | parsed.symbol = swu2key(parsed.symbol);
|
1534 | const step = clockwise ? 1 : -1;
|
1535 | const base = parsed.symbol.slice(0, 4);
|
1536 | let fill = parsed.symbol.slice(4, 5);
|
1537 | let rot = parseInt(parsed.symbol.slice(5, 6), 16);
|
1538 | let key = '';
|
1539 | while (!key || !symbolSize(key2swu(key))) {
|
1540 | if (rot > 7) {
|
1541 | rot += step;
|
1542 | if (rot > 15) {
|
1543 | rot = 8;
|
1544 | }
|
1545 | if (rot < 8) {
|
1546 | rot = 15;
|
1547 | }
|
1548 | key = base + fill + rot.toString(16);
|
1549 | } else {
|
1550 | rot -= step;
|
1551 | if (rot > 7) {
|
1552 | rot = 0;
|
1553 | }
|
1554 | if (rot < 0) {
|
1555 | rot = 7;
|
1556 | }
|
1557 | key = base + fill + rot;
|
1558 | }
|
1559 | }
|
1560 | parsed.symbol = key2swu(key);
|
1561 | return compose$1.symbol(parsed);
|
1562 | };
|
1563 |
|
1564 |
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 |
|
1571 |
|
1572 |
|
1573 |
|
1574 |
|
1575 | const symbolFlop = (swuSym, positive = true) => {
|
1576 | let parsed = parse$2.symbol(swuSym);
|
1577 | if (!parsed.symbol) {
|
1578 | return swuSym;
|
1579 | }
|
1580 | const size = symbolSize(parsed.symbol);
|
1581 | if (!size) {
|
1582 | return swuSym;
|
1583 | }
|
1584 | parsed.symbol = swu2key(parsed.symbol);
|
1585 | const step = positive ? 1 : -1;
|
1586 | const base = parsed.symbol.slice(0, 4);
|
1587 | let fill = parseInt(parsed.symbol.slice(4, 5));
|
1588 | let rot = parsed.symbol.slice(5, 6);
|
1589 | let key = '';
|
1590 | while (!key || !symbolSize(key2swu(key))) {
|
1591 | fill += step;
|
1592 | if (fill > 5) {
|
1593 | fill = 0;
|
1594 | }
|
1595 | if (fill < 0) {
|
1596 | fill = 5;
|
1597 | }
|
1598 | key = base + fill + rot;
|
1599 | }
|
1600 | parsed.symbol = key2swu(key);
|
1601 | return compose$1.symbol(parsed);
|
1602 | };
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 | const symbolScroll = (swuSym, positive = true) => {
|
1616 | let parsed = parse$2.symbol(swuSym);
|
1617 | if (!parsed.symbol) {
|
1618 | return swuSym;
|
1619 | }
|
1620 | const size = symbolSize(parsed.symbol);
|
1621 | if (!size) {
|
1622 | return swuSym;
|
1623 | }
|
1624 | parsed.symbol = swu2key(parsed.symbol);
|
1625 | const step = positive ? 1 : -1;
|
1626 | const base = parseInt(parsed.symbol.slice(1, 4), 16) + step;
|
1627 | const fill = parsed.symbol.slice(4, 5);
|
1628 | const rot = parsed.symbol.slice(5, 6);
|
1629 | const key = 'S' + base.toString(16) + fill + rot;
|
1630 | if (key.length == 6 && symbolSize(key2swu(key))) {
|
1631 | parsed.symbol = key;
|
1632 | }
|
1633 | parsed.symbol = key2swu(parsed.symbol);
|
1634 | return compose$1.symbol(parsed);
|
1635 | };
|
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 |
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 |
|
1653 |
|
1654 |
|
1655 |
|
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 |
|
1663 | const signSvgBody = swuSign => {
|
1664 | let parsed = parse$2.sign(swuSign);
|
1665 | const blank = '';
|
1666 | if (parsed.spatials) {
|
1667 | let styling = parse(parsed.style);
|
1668 | if (styling.detailsym) {
|
1669 | styling.detailsym.forEach(sym => {
|
1670 | if (parsed.spatials[sym.index - 1]) {
|
1671 | parsed.spatials[sym.index - 1].detail = sym.detail;
|
1672 | }
|
1673 | });
|
1674 | }
|
1675 | let x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
1676 | let y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
1677 | let x2 = parsed.max[0];
|
1678 | let y2 = parsed.max[1];
|
1679 | let background = '';
|
1680 | if (styling.padding) {
|
1681 | x1 -= styling.padding;
|
1682 | y1 -= styling.padding;
|
1683 | x2 += styling.padding;
|
1684 | y2 += styling.padding;
|
1685 | }
|
1686 | if (styling.background) {
|
1687 | background = `\n <rect x="${x1}" y="${y1}" width="${x2 - x1}" height="${y2 - y1}" style="fill:${styling.background};" />`;
|
1688 | }
|
1689 | let svg = ` <text font-size="0">${swuSign}</text>${background}`;
|
1690 | const line = styling.detail && styling.detail[0];
|
1691 | const fill = styling.detail && styling.detail[1];
|
1692 | svg += '\n' + parsed.spatials.map(spatial => {
|
1693 | let svg = symbolText(spatial.symbol);
|
1694 | let symLine = line;
|
1695 | if (spatial.detail) {
|
1696 | symLine = spatial.detail[0];
|
1697 | } else if (styling.colorize) {
|
1698 | symLine = colorize(spatial.symbol);
|
1699 | }
|
1700 | if (symLine) {
|
1701 | svg = svg.replace(/class="sym-line" fill="black"/, `class="sym-line" fill="${symLine}"`);
|
1702 | }
|
1703 | let symFill = fill;
|
1704 | if (spatial.detail && spatial.detail[1]) {
|
1705 | symFill = spatial.detail[1];
|
1706 | }
|
1707 | if (symFill) {
|
1708 | svg = svg.replace(/class="sym-fill" fill="white"/, `class="sym-fill" fill="${symFill}"`);
|
1709 | }
|
1710 | return ` <g transform="translate(${spatial.coord[0]},${spatial.coord[1]})">
|
1711 | ${svg}
|
1712 | </g>`;
|
1713 | }).join('\n');
|
1714 | return svg;
|
1715 | }
|
1716 | return blank;
|
1717 | };
|
1718 |
|
1719 |
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 |
|
1730 |
|
1731 |
|
1732 |
|
1733 |
|
1734 |
|
1735 |
|
1736 |
|
1737 |
|
1738 |
|
1739 |
|
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 |
|
1745 |
|
1746 |
|
1747 | const signSvg = swuSign => {
|
1748 | let parsed = parse$2.sign(swuSign);
|
1749 | const blank = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>';
|
1750 | if (parsed.spatials) {
|
1751 | let styling = parse(parsed.style);
|
1752 | let x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
1753 | let y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
1754 | let x2 = parsed.max[0];
|
1755 | let y2 = parsed.max[1];
|
1756 | let classes = '';
|
1757 | if (styling.classes) {
|
1758 | classes = ` class="${styling.classes}"`;
|
1759 | }
|
1760 | let id = '';
|
1761 | if (styling.id) {
|
1762 | id = ` id="${styling.id}"`;
|
1763 | }
|
1764 | if (styling.padding) {
|
1765 | x1 -= styling.padding;
|
1766 | y1 -= styling.padding;
|
1767 | x2 += styling.padding;
|
1768 | y2 += styling.padding;
|
1769 | }
|
1770 | let sizing = '';
|
1771 | if (styling.zoom != 'x') {
|
1772 | sizing = ` width="${(x2 - x1) * (styling.zoom ? styling.zoom : 1)}" height="${(y2 - y1) * (styling.zoom ? styling.zoom : 1)}"`;
|
1773 | }
|
1774 | let svg = `<svg${classes}${id} version="1.1" xmlns="http://www.w3.org/2000/svg"${sizing} viewBox="${x1} ${y1} ${x2 - x1} ${y2 - y1}">
|
1775 | `;
|
1776 | svg += signSvgBody(swuSign);
|
1777 | svg += '\n</svg>';
|
1778 | return svg;
|
1779 | }
|
1780 | return blank;
|
1781 | };
|
1782 |
|
1783 | const signCanvas = function (swuSign) {
|
1784 | const parsed = parse$2.sign(swuSign);
|
1785 | if (parsed.spatials) {
|
1786 | const canvas = document.createElement('canvas');
|
1787 | const context = canvas.getContext('2d');
|
1788 | let styling = parse(parsed.style);
|
1789 | if (styling.detailsym) {
|
1790 | styling.detailsym.forEach(sym => {
|
1791 | if (parsed.spatials[sym.index - 1]) {
|
1792 | parsed.spatials[sym.index - 1].detail = sym.detail;
|
1793 | }
|
1794 | });
|
1795 | }
|
1796 | let x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
1797 | let y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
1798 | let x2 = parsed.max[0];
|
1799 | let y2 = parsed.max[1];
|
1800 | if (styling.padding) {
|
1801 | x1 -= styling.padding;
|
1802 | y1 -= styling.padding;
|
1803 | x2 += styling.padding;
|
1804 | y2 += styling.padding;
|
1805 | }
|
1806 | let sizing = 1;
|
1807 | if (styling.zoom != 'x') {
|
1808 | sizing = styling.zoom;
|
1809 | }
|
1810 | let w = (x2 - x1) * sizing;
|
1811 | let h = (y2 - y1) * sizing;
|
1812 | canvas.width = w ? w : 1;
|
1813 | canvas.height = h ? h : 1;
|
1814 | if (styling.background) {
|
1815 | context.rect(0, 0, w, h);
|
1816 | context.fillStyle = styling.background;
|
1817 | context.fill();
|
1818 | }
|
1819 | const line = styling.detail && styling.detail[0] || "black";
|
1820 | const fill = styling.detail && styling.detail[1] || "white";
|
1821 | parsed.spatials.forEach(spatial => {
|
1822 | let symLine = line;
|
1823 | if (spatial.detail) {
|
1824 | symLine = spatial.detail[0];
|
1825 | } else if (styling.colorize) {
|
1826 | symLine = colorize(spatial.symbol);
|
1827 | }
|
1828 | let symFill = fill;
|
1829 | if (spatial.detail && spatial.detail[1]) {
|
1830 | symFill = spatial.detail[1];
|
1831 | }
|
1832 | context.font = 30 * sizing + "px 'SuttonSignWritingFill'";
|
1833 | context.fillStyle = symFill;
|
1834 | context.fillText(symbolFill(spatial.symbol), (spatial.coord[0] - x1) * sizing, (spatial.coord[1] - y1) * sizing);
|
1835 | context.font = 30 * sizing + "px 'SuttonSignWritingLine'";
|
1836 | context.fillStyle = symLine;
|
1837 | context.fillText(symbolLine(spatial.symbol), (spatial.coord[0] - x1) * sizing, (spatial.coord[1] - y1) * sizing);
|
1838 | });
|
1839 | return canvas;
|
1840 | }
|
1841 | };
|
1842 |
|
1843 |
|
1844 |
|
1845 |
|
1846 |
|
1847 |
|
1848 |
|
1849 |
|
1850 |
|
1851 |
|
1852 |
|
1853 | const signPng = swuSign => {
|
1854 | const canvas = signCanvas(swuSign);
|
1855 | const png = canvas.toDataURL("image/png");
|
1856 | canvas.remove();
|
1857 | return png;
|
1858 | };
|
1859 |
|
1860 |
|
1861 |
|
1862 |
|
1863 |
|
1864 |
|
1865 |
|
1866 |
|
1867 |
|
1868 |
|
1869 |
|
1870 | const signNormalize = swuSign => {
|
1871 | const parsed = parse$2.sign(swuSign);
|
1872 | if (parsed.spatials) {
|
1873 | const symbolsizes = parsed.spatials.reduce((output, spatial) => {
|
1874 | const size = symbolSize(spatial.symbol);
|
1875 | output[spatial.symbol] = {
|
1876 | width: size[0],
|
1877 | height: size[1]
|
1878 | };
|
1879 | return output;
|
1880 | }, {});
|
1881 | const bbox = symbols => {
|
1882 | const x1 = Math.min(...symbols.map(spatial => spatial.coord[0]));
|
1883 | const y1 = Math.min(...symbols.map(spatial => spatial.coord[1]));
|
1884 | const x2 = Math.max(...symbols.map(spatial => spatial.coord[0] + parseInt(symbolsizes[spatial.symbol].width)));
|
1885 | const y2 = Math.max(...symbols.map(spatial => spatial.coord[1] + parseInt(symbolsizes[spatial.symbol].height)));
|
1886 | return {
|
1887 | x1: x1,
|
1888 | y1: y1,
|
1889 | x2: x2,
|
1890 | y2: y2
|
1891 | };
|
1892 | };
|
1893 | const hrange = ranges['hcenter'];
|
1894 | const hsyms = parsed.spatials.filter(spatial => {
|
1895 | const dec = parseInt(spatial.symbol.slice(1, 4), 16);
|
1896 | return hrange[0] <= dec && hrange[1] >= dec;
|
1897 | });
|
1898 | const vrange = ranges['vcenter'];
|
1899 | const vsyms = parsed.spatials.filter(spatial => {
|
1900 | const dec = parseInt(spatial.symbol.slice(1, 4), 16);
|
1901 | return vrange[0] <= dec && vrange[1] >= dec;
|
1902 | });
|
1903 | let abox = bbox(parsed.spatials);
|
1904 | let max = [abox.x2, abox.y2];
|
1905 | if (hsyms.length) {
|
1906 | const hbox = bbox(hsyms);
|
1907 | abox.x1 = hbox.x1;
|
1908 | abox.x2 = hbox.x2;
|
1909 | }
|
1910 | if (vsyms.length) {
|
1911 | const vbox = bbox(vsyms);
|
1912 | abox.y1 = vbox.y1;
|
1913 | abox.y2 = vbox.y2;
|
1914 | }
|
1915 | const offset = [parseInt((abox.x2 + abox.x1) / 2) - 500, parseInt((abox.y2 + abox.y1) / 2) - 500];
|
1916 | const swuout = (parsed.sequence ? '𝠀' + parsed.sequence.join('') : '') + parsed.box + coord2swu$1([max[0] - offset[0], max[1] - offset[1]]) + parsed.spatials.map(spatial => spatial.symbol + coord2swu$1([spatial.coord[0] - offset[0], spatial.coord[1] - offset[1]])).join('') + (parsed.style || '');
|
1917 | return swuout;
|
1918 | }
|
1919 | };
|
1920 |
|
1921 |
|
1922 |
|
1923 |
|
1924 |
|
1925 |
|
1926 |
|
1927 |
|
1928 |
|
1929 |
|
1930 |
|
1931 |
|
1932 |
|
1933 |
|
1934 |
|
1935 |
|
1936 |
|
1937 |
|
1938 |
|
1939 |
|
1940 |
|
1941 |
|
1942 |
|
1943 |
|
1944 |
|
1945 |
|
1946 |
|
1947 |
|
1948 |
|
1949 |
|
1950 |
|
1951 |
|
1952 |
|
1953 |
|
1954 |
|
1955 |
|
1956 |
|
1957 |
|
1958 |
|
1959 |
|
1960 |
|
1961 |
|
1962 |
|
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 | const columnSvg = (swuColumn, options) => {
|
2015 |
|
2016 | if (typeof options !== 'object') options = {};
|
2017 | const values = Object.assign(columnDefaults, options);
|
2018 | let x1 = 0;
|
2019 | let y1 = 0;
|
2020 | let x2 = values.width;
|
2021 | let y2 = values.height;
|
2022 | let background = '';
|
2023 | if (values.background) {
|
2024 | background = `\n <rect x="${x1}" y="${y1}" width="${x2 - x1}" height="${y2 - y1}" style="fill:${values.background};" />`;
|
2025 | }
|
2026 | let sizing = ` width="${values.width}" height="${values.height}"`;
|
2027 | let svg = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg"${sizing} viewBox="${x1} ${y1} ${x2 - x1} ${y2 - y1}">
|
2028 | <text font-size="0">${x1}</text>${background}`;
|
2029 | svg += swuColumn.map(item => {
|
2030 | const dash = item.text.indexOf('-');
|
2031 | if (dash > 0) {
|
2032 | const itemStyle = item.text.substring(dash);
|
2033 | const newStyle = {
|
2034 | ...values.style,
|
2035 | ...parse(itemStyle)
|
2036 | };
|
2037 | item.text = item.text.replace(itemStyle, compose(newStyle));
|
2038 | } else {
|
2039 | item.text += compose(values.style);
|
2040 | }
|
2041 | item.zoom = item.zoom * values.style.zoom;
|
2042 | 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>';
|
2043 | }).join('\n');
|
2044 | svg += '\n</svg>';
|
2045 | return svg;
|
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 | const columnsSvg = function (swuText, options) {
|
2101 | if (typeof options !== 'object') options = {};
|
2102 | let values = columns(swuText, options);
|
2103 | let cols = values.columns.map((col, i) => {
|
2104 | return columnSvg(col, {
|
2105 | ...values.options,
|
2106 | ...{
|
2107 | width: values.widths[i]
|
2108 | }
|
2109 | });
|
2110 | });
|
2111 | return cols;
|
2112 | };
|
2113 |
|
2114 | const columnCanvas = function (swuColumn, options) {
|
2115 | if (typeof options !== 'object') options = {};
|
2116 | const values = Object.assign(columnDefaults, options);
|
2117 | const canvas = document.createElement('canvas');
|
2118 | canvas.width = values.width;
|
2119 | canvas.height = values.height;
|
2120 | const context = canvas.getContext('2d');
|
2121 | if (values.background) {
|
2122 | context.rect(0, 0, values.width, values.height);
|
2123 | context.fillStyle = values.background;
|
2124 | context.fill();
|
2125 | }
|
2126 | swuColumn.map(item => {
|
2127 | const dash = item.text.indexOf('-');
|
2128 | if (dash > 0) {
|
2129 | const itemStyle = item.text.substring(dash);
|
2130 | const newStyle = {
|
2131 | ...values.style,
|
2132 | ...parse(itemStyle)
|
2133 | };
|
2134 | item.text = item.text.replace(itemStyle, compose(newStyle));
|
2135 | } else {
|
2136 | item.text += compose(values.style);
|
2137 | }
|
2138 | item.zoom = item.zoom * values.style.zoom;
|
2139 | let parsed = {};
|
2140 | if (item.segment == "sign") {
|
2141 | parsed = parse$2.sign(item.text);
|
2142 | } else {
|
2143 | let sym = parse$2.symbol(item.text);
|
2144 | parsed.style = sym.style;
|
2145 | parsed.spatials = [sym];
|
2146 | }
|
2147 | let styling = parse(parsed.style);
|
2148 | if (styling.background) {
|
2149 | context.fillStyle = styling.background;
|
2150 | 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);
|
2151 | }
|
2152 | if (styling.detailsym) {
|
2153 | styling.detailsym.forEach(sym => {
|
2154 | if (parsed.spatials[sym.index - 1]) {
|
2155 | parsed.spatials[sym.index - 1].detail = sym.detail;
|
2156 | }
|
2157 | });
|
2158 | }
|
2159 | const line = styling.detail && styling.detail[0] || "black";
|
2160 | const fill = styling.detail && styling.detail[1] || "white";
|
2161 | parsed.spatials.forEach(spatial => {
|
2162 | let symLine = line;
|
2163 | if (spatial.detail) {
|
2164 | symLine = spatial.detail[0];
|
2165 | } else if (styling.colorize) {
|
2166 | symLine = colorize(spatial.symbol);
|
2167 | }
|
2168 | let symFill = fill;
|
2169 | if (spatial.detail && spatial.detail[1]) {
|
2170 | symFill = spatial.detail[1];
|
2171 | }
|
2172 | context.font = 30 * item.zoom + "px 'SuttonSignWritingFill'";
|
2173 | context.fillStyle = symFill;
|
2174 | context.fillText(symbolFill(spatial.symbol), item.x + (spatial.coord[0] - item.minX) * item.zoom, item.y + (spatial.coord[1] - item.minY) * item.zoom);
|
2175 | context.font = 30 * item.zoom + "px 'SuttonSignWritingLine'";
|
2176 | context.fillStyle = symLine;
|
2177 | context.fillText(symbolLine(spatial.symbol), item.x + (spatial.coord[0] - item.minX) * item.zoom, item.y + (spatial.coord[1] - item.minY) * item.zoom);
|
2178 | });
|
2179 | });
|
2180 | return canvas;
|
2181 | };
|
2182 |
|
2183 |
|
2184 |
|
2185 |
|
2186 |
|
2187 |
|
2188 |
|
2189 |
|
2190 |
|
2191 |
|
2192 |
|
2193 |
|
2194 |
|
2195 |
|
2196 |
|
2197 |
|
2198 |
|
2199 |
|
2200 |
|
2201 |
|
2202 |
|
2203 |
|
2204 |
|
2205 |
|
2206 |
|
2207 |
|
2208 |
|
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 |
|
2214 |
|
2215 |
|
2216 |
|
2217 |
|
2218 |
|
2219 |
|
2220 |
|
2221 |
|
2222 |
|
2223 |
|
2224 |
|
2225 |
|
2226 |
|
2227 |
|
2228 |
|
2229 |
|
2230 |
|
2231 |
|
2232 |
|
2233 |
|
2234 |
|
2235 |
|
2236 |
|
2237 |
|
2238 | const columnPng = (swuColumn, options) => {
|
2239 | const canvas = columnCanvas(swuColumn, options);
|
2240 | const png = canvas.toDataURL("image/png");
|
2241 | canvas.remove();
|
2242 | return png;
|
2243 | };
|
2244 |
|
2245 |
|
2246 |
|
2247 |
|
2248 |
|
2249 |
|
2250 |
|
2251 |
|
2252 |
|
2253 |
|
2254 |
|
2255 |
|
2256 |
|
2257 |
|
2258 |
|
2259 | const columnsPng = function (swuText, options) {
|
2260 | if (typeof options !== 'object') options = {};
|
2261 | let values = columns(swuText, options);
|
2262 | let cols = values.columns.map((col, i) => {
|
2263 | return columnPng(col, {
|
2264 | ...values.options,
|
2265 | ...{
|
2266 | width: values.widths[i]
|
2267 | }
|
2268 | });
|
2269 | });
|
2270 | return cols;
|
2271 | };
|
2272 |
|
2273 | export { columnPng, columnSvg, columnsPng, columnsSvg, signNormalize, signPng, signSvg, signSvgBody, symbolFill, symbolFlop, symbolLine, symbolMirror, symbolNormalize, symbolPng, symbolRotate, symbolScroll, symbolSize, symbolSvg, symbolSvgBody, symbolText };
|
2274 |
|
2275 |
|