poe-svelte-ui-lib 2.7.1 → 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +13 -12
  2. package/dist/Button/Button.svelte +6 -3
  3. package/dist/Button/README.md +2 -2
  4. package/dist/FileAttach/FileAttach.svelte +6 -5
  5. package/dist/FileAttach/README.md +20 -19
  6. package/dist/Graph/Graph.svelte +58 -23
  7. package/dist/Graph/README.md +2 -1
  8. package/dist/InfoHint.svelte +2 -1
  9. package/dist/Input/Input.svelte +9 -4
  10. package/dist/Input/README.md +2 -2
  11. package/dist/Select/README.md +1 -1
  12. package/dist/Select/Select.svelte +5 -4
  13. package/dist/Table/README.md +5 -1
  14. package/dist/Table/Table.svelte +56 -12
  15. package/dist/Table/TableProps.svelte +4 -3
  16. package/dist/Table/XPoeDebugModal.svelte +6 -3
  17. package/dist/Table/xPoeDebugColumns.d.ts +1 -1
  18. package/dist/Table/xPoeDebugColumns.js +35 -4
  19. package/dist/Tabs/README.md +1 -0
  20. package/dist/Tabs/Tabs.svelte +6 -5
  21. package/dist/WidgetDeviceInfo/WidgetDeviceInfo.svelte +1 -1
  22. package/dist/WidgetFileSystem/WidgetFileSystem.svelte +1 -1
  23. package/dist/dictionaries/README.md +77 -0
  24. package/dist/{protocols/dictionary.yaml → dictionaries/commands.yaml} +1 -1
  25. package/dist/dictionaries/firmware/api_har.h +109 -0
  26. package/dist/dictionaries/firmware/api_msg.h +57 -0
  27. package/dist/{protocols/dictionaryCodes.js → dictionaries/generated/commands.js} +1 -1
  28. package/dist/dictionaries/generated/messages.d.ts +19 -0
  29. package/dist/dictionaries/generated/messages.js +84 -0
  30. package/dist/dictionaries/messages.yaml +57 -0
  31. package/dist/libIcons/ArrowIcon.svelte +1 -1
  32. package/dist/libIcons/ButtonClear.svelte +1 -1
  33. package/dist/libIcons/InfoIcon.svelte +1 -1
  34. package/dist/libIcons/Library.svelte +1 -1
  35. package/dist/libIcons/MoveVerticalIcon.svelte +1 -1
  36. package/dist/locales/translations.d.ts +20 -0
  37. package/dist/locales/translations.js +4 -0
  38. package/dist/options.js +1 -1
  39. package/dist/popup.d.ts +1 -0
  40. package/dist/popup.js +12 -0
  41. package/dist/protocols/PROTOCOL.md +168 -32
  42. package/dist/protocols/dictionary.d.ts +1 -1
  43. package/dist/protocols/dictionary.js +2 -2
  44. package/dist/protocols/index.d.ts +2 -1
  45. package/dist/protocols/index.js +4 -2
  46. package/dist/protocols/messages.d.ts +15 -0
  47. package/dist/protocols/messages.js +31 -0
  48. package/dist/protocols/xPoeDebug.d.ts +6 -1
  49. package/dist/protocols/xPoeDebug.js +41 -17
  50. package/dist/protocols/xPoeDebugView.d.ts +4 -1
  51. package/dist/protocols/xPoeDebugView.js +37 -65
  52. package/dist/protocols/xPoeYaml.d.ts +6 -0
  53. package/dist/protocols/xPoeYaml.js +294 -0
  54. package/package.json +2 -2
  55. /package/dist/{protocols/dictionaryCodes.d.ts → dictionaries/generated/commands.d.ts} +0 -0
@@ -0,0 +1,294 @@
1
+ /* Вид CBOR в стиле YAML для xPOE-Debug: строка VALUE - поток (корневая карта без скобок), окно - блок с отступом 2; разбор поля Value - поток YAML или JSON */
2
+ import { base64ToBytes } from "./cbor/base64.js";
3
+ import { encodeCbor } from "./cbor/encoder.js";
4
+ import { bytesToHex, hexToBytes } from "./hex.js";
5
+ const plain = (_kind, text) => text;
6
+ /* float32 с провода - кратчайшая запись, дающая то же float32 (0.12, а не 0.12000000476837158); double и целые - как есть */
7
+ export const shortNumber = (value) => {
8
+ if (Number.isInteger(value) || !Number.isFinite(value) || Math.fround(value) !== value)
9
+ return value;
10
+ for (let digits = 1; digits <= 9; digits++) {
11
+ const short = Number(value.toPrecision(digits));
12
+ if (Math.fround(short) === value)
13
+ return short;
14
+ }
15
+ return value;
16
+ };
17
+ const NUMBER = /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;
18
+ const SPECIAL = /^(?:null|Null|NULL|~|true|True|TRUE|false|False|FALSE|[-+]?\.(?:inf|Inf|INF)|\.(?:nan|NaN|NAN))$/;
19
+ /* Строка без кавычек только если читается обратно той же строкой: не похожа на число, true/false/null, не пустая, без «:,[]{}#», управляющих символов и крайних пробелов, не начинается с кавычки, h' или знака YAML */
20
+ const needsQuotes = (text) => !text ||
21
+ text !== text.trim() ||
22
+ /[:,[\]{}#\x00-\x1f\x7f]/.test(text) ||
23
+ /^(?:["'!&*|>%@`]|h'|- |\? )/.test(text) ||
24
+ /^[-+.]?\d/.test(text) ||
25
+ /^0[xX]/.test(text) ||
26
+ SPECIAL.test(text) ||
27
+ SPECIAL.test(text.toLowerCase());
28
+ const quote = (text) => (needsQuotes(text) ? JSON.stringify(text) : text);
29
+ const formatNumber = (value) => Number.isNaN(value) ? ".nan" : value === Infinity ? ".inf" : value === -Infinity ? "-.inf" : String(shortNumber(value));
30
+ const scalar = (value, paint) => {
31
+ if (value === null || value === undefined)
32
+ return paint("null", "null");
33
+ if (typeof value === "boolean")
34
+ return paint("boolean", String(value));
35
+ if (typeof value === "number")
36
+ return paint("number", formatNumber(value));
37
+ if (typeof value === "bigint")
38
+ return paint("number", String(value));
39
+ if (typeof value === "string")
40
+ return paint("string", quote(value));
41
+ if (value instanceof Uint8Array)
42
+ return paint("bytes", `h'${bytesToHex(value)}'`);
43
+ return null;
44
+ };
45
+ /* Пары карты: CBOR-карта приходит Map (ключи любого типа, порядок как на проводе) или объектом */
46
+ const entriesOf = (value) => {
47
+ if (value instanceof Map)
48
+ return [...value];
49
+ if (value && typeof value === "object" && !Array.isArray(value) && !(value instanceof Uint8Array))
50
+ return Object.entries(value);
51
+ return null;
52
+ };
53
+ const flow = (value, paint) => {
54
+ const simple = scalar(value, paint);
55
+ if (simple !== null)
56
+ return simple;
57
+ if (Array.isArray(value))
58
+ return `[${value.map((item) => flow(item, paint)).join(", ")}]`;
59
+ const entries = entriesOf(value) ?? [];
60
+ return `{${flowEntries(entries, paint)}}`;
61
+ };
62
+ /* Ключ-строка - по правилам кавычек («"1"» - строка), ключ-число и прочие - как значение («1» - число) */
63
+ const keyText = (key, paint) => paint("key", `${typeof key === "string" ? quote(key) : flow(key, plain)}:`);
64
+ const flowEntries = (entries, paint) => entries.map(([key, item]) => `${keyText(key, paint)} ${flow(item, paint)}`).join(", ");
65
+ /* Одна строка: корневая карта без внешних скобок («A: 1, B: [1, 2]»), пустая - {}; остальное - значение потока */
66
+ export const formatYamlFlow = (value, paint = plain) => {
67
+ const entries = Array.isArray(value) ? null : entriesOf(value);
68
+ return entries?.length ? flowEntries(entries, paint) : flow(value, paint);
69
+ };
70
+ /* Непустая карта или массив - блоком с новой строки */
71
+ const isBlock = (value) => (Array.isArray(value) ? value.length > 0 : !!entriesOf(value)?.length);
72
+ const blockLines = (value, paint, indent) => {
73
+ if (Array.isArray(value))
74
+ return value.map((item) => {
75
+ if (!isBlock(item))
76
+ return `${indent}- ${flow(item, paint)}`;
77
+ /* Вложенное - компактно: первая строка после «- », остальные с отступом +2 */
78
+ const [first, ...rest] = blockLines(item, paint, `${indent} `);
79
+ return [`${indent}- ${first.slice(indent.length + 2)}`, ...rest].join("\n");
80
+ });
81
+ return (entriesOf(value) ?? []).map(([key, item]) => {
82
+ const head = `${indent}${keyText(key, paint)}`;
83
+ return isBlock(item) ? [head, ...blockLines(item, paint, `${indent} `)].join("\n") : `${head} ${flow(item, paint)}`;
84
+ });
85
+ };
86
+ /* Несколько строк: блочный YAML с отступом 2; скаляр, пустые {} и [] - как в потоке */
87
+ export const formatYamlBlock = (value, paint = plain) => isBlock(value) ? blockLines(value, paint, "").join("\n") : flow(value, paint);
88
+ /* Разбор потока YAML (и JSON как его подмножества) в значение CBOR: h'..' - байтовая строка, корневая карта может быть без скобок */
89
+ class FlowParser {
90
+ text;
91
+ binBase64;
92
+ pos = 0;
93
+ constructor(text, binBase64) {
94
+ this.text = text;
95
+ this.binBase64 = binBase64;
96
+ }
97
+ fail(reason) {
98
+ throw new Error(`${reason} (позиция ${this.pos + 1})`);
99
+ }
100
+ skip() {
101
+ while (this.pos < this.text.length && /\s/.test(this.text[this.pos]))
102
+ this.pos++;
103
+ }
104
+ peek = () => this.text[this.pos];
105
+ root() {
106
+ this.skip();
107
+ const start = this.pos;
108
+ const first = this.peek();
109
+ /* Корень без скобок - карта, если начинается с «ключ: » */
110
+ if (first !== "{" && first !== "[" && this.tryKey(true) !== undefined) {
111
+ this.pos = start;
112
+ const map = this.entries(null);
113
+ return map;
114
+ }
115
+ this.pos = start;
116
+ const value = this.value();
117
+ this.skip();
118
+ if (this.pos < this.text.length)
119
+ this.fail(`лишний текст «${this.text.slice(this.pos, this.pos + 20)}»`);
120
+ return value;
121
+ }
122
+ /* Пары до закрывающей скобки или конца текста */
123
+ entries(close) {
124
+ const map = new Map();
125
+ for (;;) {
126
+ this.skip();
127
+ if (close && this.peek() === close)
128
+ break;
129
+ if (this.pos >= this.text.length) {
130
+ if (close)
131
+ this.fail(`ожидалась «${close}»`);
132
+ break;
133
+ }
134
+ const key = this.tryKey(!close);
135
+ if (key === undefined)
136
+ this.fail("ожидалась пара «ключ: значение»");
137
+ this.skip();
138
+ /* «ключ:» без значения - null */
139
+ const empty = this.pos >= this.text.length || this.peek() === "," || this.peek() === close;
140
+ const value = empty ? null : this.value();
141
+ /* JSON: строка под ключом на BIN (FileBin, DataBIN) - Base64 байтов */
142
+ map.set(key, this.binBase64 && typeof value === "string" && typeof key === "string" && /bin$/i.test(key) ? base64ToBytes(value) : value);
143
+ this.skip();
144
+ if (this.peek() === ",") {
145
+ this.pos++;
146
+ continue;
147
+ }
148
+ if (close ? this.peek() !== close : this.pos < this.text.length)
149
+ this.fail(close ? "ожидалась «,» или «}»" : "ожидалась «,»");
150
+ }
151
+ if (close)
152
+ this.pos++;
153
+ return map;
154
+ }
155
+ /* Ключ с двоеточием после него; нет - undefined (позиция не восстанавливается). В кавычках - строка, без - по виду («1» - число). В корне простой ключ требует пробел после «:» */
156
+ tryKey(atRoot) {
157
+ this.skip();
158
+ const char = this.peek();
159
+ let key;
160
+ if (char === '"' || char === "'") {
161
+ try {
162
+ key = this.quoted();
163
+ }
164
+ catch {
165
+ return undefined;
166
+ }
167
+ this.skip();
168
+ }
169
+ else {
170
+ const start = this.pos;
171
+ while (this.pos < this.text.length && !/[:,[\]{}]/.test(this.peek()))
172
+ this.pos++;
173
+ const token = this.text.slice(start, this.pos).trim();
174
+ if (!token || token.startsWith("h'"))
175
+ return undefined;
176
+ if (atRoot && this.peek() === ":" && this.pos + 1 < this.text.length && !/[\s,]/.test(this.text[this.pos + 1]))
177
+ return undefined;
178
+ key = resolvePlain(token);
179
+ }
180
+ if (this.peek() !== ":")
181
+ return undefined;
182
+ this.pos++;
183
+ return key;
184
+ }
185
+ value() {
186
+ this.skip();
187
+ const char = this.peek();
188
+ if (char === undefined)
189
+ this.fail("нет значения");
190
+ if (char === "{") {
191
+ this.pos++;
192
+ return this.entries("}");
193
+ }
194
+ if (char === "[") {
195
+ this.pos++;
196
+ const list = [];
197
+ for (;;) {
198
+ this.skip();
199
+ if (this.peek() === "]")
200
+ break;
201
+ list.push(this.value());
202
+ this.skip();
203
+ if (this.peek() === ",") {
204
+ this.pos++;
205
+ continue;
206
+ }
207
+ if (this.peek() !== "]")
208
+ this.fail("ожидалась «,» или «]»");
209
+ }
210
+ this.pos++;
211
+ return list;
212
+ }
213
+ if (char === '"' || char === "'")
214
+ return this.quoted();
215
+ if (char === "h" && this.text[this.pos + 1] === "'") {
216
+ const end = this.text.indexOf("'", this.pos + 2);
217
+ if (end < 0)
218
+ this.fail("не закрыта h'..'");
219
+ const bytes = hexToBytes(this.text.slice(this.pos + 2, end));
220
+ if (!bytes)
221
+ this.fail(`h'..': нужны HEX-цифры парами`);
222
+ this.pos = end + 1;
223
+ return bytes;
224
+ }
225
+ if (char === "}" || char === "]" || char === ",")
226
+ this.fail(`неожиданный «${char}»`);
227
+ return this.plainScalar();
228
+ }
229
+ /* "..." - экранирование как в JSON, '...' - кавычка удваивается */
230
+ quoted() {
231
+ const open = this.peek();
232
+ const start = this.pos;
233
+ this.pos++;
234
+ if (open === "'") {
235
+ let out = "";
236
+ for (;;) {
237
+ if (this.pos >= this.text.length)
238
+ this.fail("не закрыта строка в кавычках");
239
+ const char = this.text[this.pos++];
240
+ if (char !== "'")
241
+ out += char;
242
+ else if (this.peek() === "'") {
243
+ out += "'";
244
+ this.pos++;
245
+ }
246
+ else
247
+ return out;
248
+ }
249
+ }
250
+ while (this.pos < this.text.length && this.peek() !== '"')
251
+ this.pos += this.peek() === "\\" ? 2 : 1;
252
+ if (this.pos >= this.text.length) {
253
+ this.pos = start;
254
+ this.fail("не закрыта строка в кавычках");
255
+ }
256
+ this.pos++;
257
+ try {
258
+ return JSON.parse(this.text.slice(start, this.pos));
259
+ }
260
+ catch {
261
+ this.pos = start;
262
+ return this.fail("неверное экранирование в строке");
263
+ }
264
+ }
265
+ /* Простое значение до «,» или скобки */
266
+ plainScalar() {
267
+ const start = this.pos;
268
+ while (this.pos < this.text.length && !/[,[\]{}]/.test(this.peek()))
269
+ this.pos++;
270
+ return resolvePlain(this.text.slice(start, this.pos).trim());
271
+ }
272
+ }
273
+ /* Простое значение по виду: число, true/false, null, .inf/.nan, остальное - строка */
274
+ const resolvePlain = (token) => {
275
+ if (/^(?:null|Null|NULL|~)$/.test(token))
276
+ return null;
277
+ if (/^(?:true|True|TRUE)$/.test(token))
278
+ return true;
279
+ if (/^(?:false|False|FALSE)$/.test(token))
280
+ return false;
281
+ if (/^[-+]?\.(?:inf|Inf|INF)$/.test(token))
282
+ return token.startsWith("-") ? -Infinity : Infinity;
283
+ if (/^\.(?:nan|NaN|NAN)$/.test(token))
284
+ return NaN;
285
+ if (NUMBER.test(token)) {
286
+ /* Целое вне safe integer - bigint (uint64 устройства) */
287
+ if (/^[-+]?\d+$/.test(token) && !Number.isSafeInteger(Number(token)))
288
+ return BigInt(token);
289
+ return Number(token);
290
+ }
291
+ return token;
292
+ };
293
+ /* Поток YAML в байты CBOR; binBase64 - строки под ключами на BIN как Base64 байтов (так читается JSON); ошибка - с причиной и позицией */
294
+ export const yamlFlowToCbor = (text, binBase64 = false) => encodeCbor(new FlowParser(text, binBase64).root());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-svelte-ui-lib",
3
- "version": "2.7.1",
3
+ "version": "2.8.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Oleg-Perevyshin/ElementsUI.git"
@@ -35,7 +35,7 @@
35
35
  "types": "./dist/protocols/index.d.ts",
36
36
  "default": "./dist/protocols/index.js"
37
37
  },
38
- "./protocols/dictionary.yaml": "./dist/protocols/dictionary.yaml",
38
+ "./dictionaries/*": "./dist/dictionaries/*",
39
39
  "./constructor": {
40
40
  "types": "./dist/constructor.d.ts",
41
41
  "svelte": "./dist/constructor.js"