UNPKG

6.8 kBJavaScriptView Raw
1/*!
2 * The Sutton SignWriting Web Components
3 */
4import { r as registerInstance, h, H as Host, g as getElement } from './_commonjsHelpers-383fba37.js';
5import { c as convert, H as HomeIcon, C as ChevronUpIcon, A as ArrowLeftIcon, a as ArrowRightIcon, b as ArrowUpIcon, d as ArrowDownIcon } from './icons-472d6293.js';
6import { d as iswa2010SWU, p as padArrayInner, b as padArray, h as hasSize } from './global-4493408c.js';
7
8const sgnwPaletteCss = ".sc-sgnw-palette-h{width:100%;height:100%;display:flex}.sc-sgnw-palette-h nav.sc-sgnw-palette{height:100%;width:100%;flex:0 0 10%;display:flex;align-items:center}.sc-sgnw-palette-h nav.sc-sgnw-palette fsw-button.sc-sgnw-palette,.sc-sgnw-palette-h nav.sc-sgnw-palette div.sc-sgnw-palette{flex:25%;height:100%;width:100%;margin:1%}.sc-sgnw-palette-h main.sc-sgnw-palette{flex:0 0 90%;width:100%;height:100%;display:grid}.horizontal.sc-sgnw-palette-h{flex-direction:row}.horizontal.sc-sgnw-palette-h nav.sc-sgnw-palette{flex-direction:column}.horizontal.small.sc-sgnw-palette-h main.sc-sgnw-palette{grid-template-columns:repeat(10,1fr)}.horizontal.medium.sc-sgnw-palette-h main.sc-sgnw-palette{grid-template-columns:repeat(10,1fr)}.horizontal.large.sc-sgnw-palette-h main.sc-sgnw-palette{grid-template-columns:repeat(16,1fr)}.vertical.sc-sgnw-palette-h{flex-direction:column}.vertical.sc-sgnw-palette-h nav.sc-sgnw-palette{flex-direction:row}.vertical.sc-sgnw-palette-h main.sc-sgnw-palette{grid-auto-flow:column}.vertical.small.sc-sgnw-palette-h main.sc-sgnw-palette{grid-template-rows:repeat(10,1fr)}.vertical.medium.sc-sgnw-palette-h main.sc-sgnw-palette{grid-template-rows:repeat(10,1fr)}.vertical.large.sc-sgnw-palette-h main.sc-sgnw-palette{grid-template-rows:repeat(16,1fr)}";
9
10const SgnwPalette = class {
11 constructor(hostRef) {
12 registerInstance(this, hostRef);
13 /** orientation of palette */
14 this.orientation = "vertical";
15 this.major = 10;
16 this.minor = 3;
17 this.total = 30;
18 /** size of palette */
19 this.size = "small";
20 /** set of symbols */
21 this.alphabet = iswa2010SWU;
22 /** top level symbol selection */
23 this.group = null;
24 /** mid level symbol selection */
25 this.base = null;
26 /** flag for small palette */
27 this.more = false;
28 this.hasMore = false;
29 /** flag for small and medium palette */
30 this.lower = false;
31 this.hasLower = false;
32 this.palette = [];
33 }
34 parseSizeProp(newValue) {
35 switch (newValue) {
36 case "large":
37 this.major = 16;
38 this.minor = 6;
39 break;
40 case "medium":
41 this.major = 10;
42 this.minor = 6;
43 break;
44 case "small":
45 default:
46 this.major = 10;
47 this.minor = 3;
48 break;
49 }
50 this.total = this.major * this.minor;
51 }
52 watchGroup() {
53 if (this.group == null && this.base != null) {
54 this.base = null;
55 }
56 else {
57 this.setPalette();
58 }
59 }
60 watchBase() {
61 this.setPalette();
62 }
63 watchMore() {
64 this.setPalette();
65 }
66 watchLower() {
67 this.setPalette();
68 }
69 getPaletteAll() {
70 let keys = Object.keys(this.alphabet);
71 if (this.size == 'large') {
72 keys = padArrayInner(keys, 10, 16);
73 }
74 keys = padArray(keys, this.total);
75 this.more = false;
76 this.hasMore = false;
77 this.lower = false;
78 this.hasLower = false;
79 return keys;
80 }
81 getPaletteGroup() {
82 let keys = this.alphabet[this.group];
83 if (this.size == 'large') {
84 keys = padArrayInner(keys, 10, 16);
85 }
86 keys = padArray(keys, this.total);
87 if (keys.length > this.total) {
88 this.hasMore = true;
89 if (!this.more) {
90 keys = keys.slice(0, this.total);
91 }
92 else {
93 keys = keys.slice(this.total, this.total * 2);
94 }
95 }
96 else {
97 this.more = false;
98 this.hasMore = false;
99 }
100 this.lower = false;
101 this.hasLower = false;
102 return keys;
103 }
104 getPaletteBase() {
105 const base = convert.swu2key(this.base).slice(0, 4);
106 let key;
107 const lower1 = base + "08";
108 const lower2 = base + "18";
109 const more1 = base + "30";
110 let r1 = 0;
111 let r2 = 16;
112 let f1 = 0;
113 let f2 = 6;
114 if (this.size != "large") {
115 this.hasLower = (hasSize(convert.key2id(lower1)) || hasSize(convert.key2id(lower2)));
116 if (!this.lower) {
117 r2 = 8;
118 }
119 else {
120 r1 = 8;
121 }
122 }
123 if (this.size == "small") {
124 this.hasMore = hasSize(convert.key2id(more1));
125 if (!this.more) {
126 f2 = 3;
127 }
128 else {
129 f1 = 3;
130 }
131 }
132 let keys = [];
133 for (var f = f1; f < f2; f++) {
134 for (var r = r1; r < r2; r++) {
135 key = base + f + r.toString(16);
136 keys.push(convert.key2swu(key));
137 }
138 }
139 if (this.size != "large") {
140 keys = padArrayInner(keys, 8, 10);
141 }
142 return keys;
143 }
144 setPalette() {
145 let palette;
146 switch (true) {
147 case !this.group:
148 palette = this.getPaletteAll();
149 break;
150 case !!this.group && !!this.base:
151 palette = this.getPaletteBase();
152 break;
153 case !!this.group:
154 palette = this.getPaletteGroup();
155 break;
156 }
157 this.palette = [...palette];
158 }
159 paletteSymbolClickHandler(event) {
160 switch (true) {
161 case !this.group:
162 this.group = event.detail;
163 break;
164 case !!this.group && !!this.base:
165 break;
166 case !!this.group:
167 this.base = event.detail;
168 this.more = false;
169 }
170 }
171 componentWillLoad() {
172 if (typeof this.alphabet == "string") {
173 this.alphabet = JSON.parse(this.alphabet);
174 }
175 this.parseSizeProp(this.size);
176 this.setPalette();
177 }
178 render() {
179 return (h(Host, { class: this.orientation + " " + this.size }, h("nav", null, h("sgnw-button", { svg: HomeIcon, onClick: () => { this.group = null; } }), this.group ? h("sgnw-button", { svg: ChevronUpIcon, onClick: () => {
180 if (this.base) {
181 this.base = null;
182 this.more = null;
183 }
184 else {
185 this.group = null;
186 }
187 } }) : h("div", null), this.hasMore ? h("sgnw-button", { svg: this.more ? ArrowLeftIcon : ArrowRightIcon, onClick: () => { this.more = !this.more; } }) : (this.size == "small" ? h("div", null) : null), this.hasLower ? h("sgnw-button", { svg: this.lower ? ArrowUpIcon : ArrowDownIcon, onClick: () => { this.lower = !this.lower; } }) : (this.size != "large" ? h("div", null) : null)), h("main", null, this.palette.map(key => h("sgnw-palette-symbol", { symbol: key })))));
188 }
189 get el() { return getElement(this); }
190 static get watchers() { return {
191 "size": ["parseSizeProp"],
192 "group": ["watchGroup"],
193 "base": ["watchBase"],
194 "more": ["watchMore"],
195 "lower": ["watchLower"]
196 }; }
197};
198SgnwPalette.style = sgnwPaletteCss;
199
200export { SgnwPalette as sgnw_palette };