@iyio/syn-taxi 0.5.18 → 0.6.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 (43) hide show
  1. package/esm/src/lib/CodeInput.d.ts +7 -1
  2. package/esm/src/lib/CodeInput.js +130 -35
  3. package/esm/src/lib/CodeInput.js.map +1 -1
  4. package/esm/src/lib/CodeView.d.ts +3 -0
  5. package/esm/src/lib/CodeView.js +6 -3
  6. package/esm/src/lib/CodeView.js.map +1 -1
  7. package/esm/src/lib/LineNumbers.d.ts +3 -0
  8. package/esm/src/lib/LineNumbers.js +3 -0
  9. package/esm/src/lib/LineNumbers.js.map +1 -1
  10. package/esm/src/lib/grammar/atDotCss.d.ts +1349 -0
  11. package/esm/src/lib/grammar/atDotCss.js +2157 -0
  12. package/esm/src/lib/grammar/atDotCss.js.map +1 -0
  13. package/esm/src/lib/grammar/convo.d.ts +534 -0
  14. package/esm/src/lib/grammar/convo.js +570 -0
  15. package/esm/src/lib/grammar/convo.js.map +1 -0
  16. package/esm/src/lib/grammar/mdx.d.ts +2812 -0
  17. package/esm/src/lib/grammar/mdx.js +3758 -0
  18. package/esm/src/lib/grammar/mdx.js.map +1 -0
  19. package/esm/src/lib/shiki.d.ts +8 -3
  20. package/esm/src/lib/shiki.js +119 -445
  21. package/esm/src/lib/shiki.js.map +1 -1
  22. package/package.json +10 -11
  23. package/src/lib/CodeInput.d.ts +7 -1
  24. package/src/lib/CodeInput.js +128 -33
  25. package/src/lib/CodeInput.js.map +1 -1
  26. package/src/lib/CodeView.d.ts +3 -0
  27. package/src/lib/CodeView.js +6 -3
  28. package/src/lib/CodeView.js.map +1 -1
  29. package/src/lib/LineNumbers.d.ts +3 -0
  30. package/src/lib/LineNumbers.js +3 -0
  31. package/src/lib/LineNumbers.js.map +1 -1
  32. package/src/lib/grammar/atDotCss.d.ts +1349 -0
  33. package/src/lib/grammar/atDotCss.js +2160 -0
  34. package/src/lib/grammar/atDotCss.js.map +1 -0
  35. package/src/lib/grammar/convo.d.ts +534 -0
  36. package/src/lib/grammar/convo.js +573 -0
  37. package/src/lib/grammar/convo.js.map +1 -0
  38. package/src/lib/grammar/mdx.d.ts +2812 -0
  39. package/src/lib/grammar/mdx.js +3761 -0
  40. package/src/lib/grammar/mdx.js.map +1 -0
  41. package/src/lib/shiki.d.ts +8 -3
  42. package/src/lib/shiki.js +123 -447
  43. package/src/lib/shiki.js.map +1 -1
@@ -1,47 +1,122 @@
1
1
  import { __awaiter } from "tslib";
2
- import { createBase64DataUrl } from '@iyio/common';
3
2
  import { useEffect, useState } from 'react';
4
- import { BUNDLED_LANGUAGES, getHighlighter } from 'shiki';
3
+ import { Subject } from 'rxjs';
4
+ import { bundledLanguages } from 'shiki/langs';
5
+ import { atDotCssGrammar } from './grammar/atDotCss';
6
+ import { convoGrammar } from './grammar/convo';
7
+ import { mdxGrammar } from './grammar/mdx';
5
8
  let defaultHighlighter;
9
+ const autoLoadMdCodeBlocksKey = 'autoLoadMdCodeBlocks';
10
+ const autoLoadMdCodeBlocksList = [
11
+ 'markdown',
12
+ ];
13
+ const loadedLangInfo = {};
6
14
  const loadLangMap = {};
15
+ const onLangLoad = new Subject();
7
16
  export const loadShikiLangAsync = (name) => {
8
17
  var _a;
9
- return (_a = loadLangMap[name]) !== null && _a !== void 0 ? _a : (loadLangMap[name] = _loadShikiLangAsync(name));
18
+ return (_a = loadLangMap[name]) !== null && _a !== void 0 ? _a : (loadLangMap[name] = _loadShikiLangAsync(0, name));
10
19
  };
11
- const _loadShikiLangAsync = (name, scope = `source.${name}`) => __awaiter(void 0, void 0, void 0, function* () {
20
+ const langDeps = {
21
+ //mdx:['tsx'],
22
+ //convo:['json','xml','javascript','python'],
23
+ };
24
+ const _loadShikiLangAsync = (depth, name) => __awaiter(void 0, void 0, void 0, function* () {
25
+ var _a, _b;
26
+ if (depth > 10 || name === 'elm' || name === 'erlang') {
27
+ return false;
28
+ }
12
29
  const sh = yield getShikiAsync();
13
30
  if (sh.getLoadedLanguages().includes(name)) {
14
- return;
31
+ return false;
15
32
  }
16
- if (BUNDLED_LANGUAGES.some(l => l.id === name)) {
17
- yield sh.loadLanguage(name);
33
+ const custom = (name === 'convo' ?
34
+ convoGrammar
35
+ : name === 'atdot' ?
36
+ atDotCssGrammar
37
+ : name === 'mdx' ?
38
+ mdxGrammar
39
+ :
40
+ null);
41
+ try {
42
+ yield sh.loadLanguage(custom !== null && custom !== void 0 ? custom : name);
43
+ onLangLoad.next(name);
18
44
  }
19
- else {
20
- yield sh.loadLanguage({
21
- id: name,
22
- scopeName: scope,
23
- displayName: name,
24
- path: name === 'convo' ? createBase64DataUrl(JSON.stringify(convo), 'application/json') : `highlighting/languages/${name}.tmLanguage.json`,
25
- });
45
+ catch (_c) {
46
+ //
47
+ }
48
+ const bundled = custom ? [custom] : ((_b = (yield ((_a = bundledLanguages[name]) === null || _a === void 0 ? void 0 : _a.call(bundledLanguages)))) === null || _b === void 0 ? void 0 : _b.default);
49
+ const depList = langDeps[name];
50
+ if (depList) {
51
+ for (const dep of depList) {
52
+ yield _loadShikiLangAsync(depth + 1, dep);
53
+ }
54
+ }
55
+ if (bundled) {
56
+ for (const b of bundled) {
57
+ loadedLangInfo[b.name] = {
58
+ embeddedLangsLazy: b.embeddedLangsLazy,
59
+ [autoLoadMdCodeBlocksKey]: b[autoLoadMdCodeBlocksKey] || autoLoadMdCodeBlocksList.includes(b.name),
60
+ };
61
+ if (b.embeddedLangs) {
62
+ for (const e of b.embeddedLangs) {
63
+ yield _loadShikiLangAsync(depth + 1, e);
64
+ }
65
+ }
66
+ }
26
67
  }
68
+ return true;
27
69
  });
28
- export const getShikiAsync = () => {
70
+ export const supportsMdCodeBlocks = (lang) => {
71
+ var _a, _b;
72
+ return (_b = (_a = loadedLangInfo[lang]) === null || _a === void 0 ? void 0 : _a[autoLoadMdCodeBlocksKey]) !== null && _b !== void 0 ? _b : false;
73
+ };
74
+ const codeBlockMap = {
75
+ js: 'javascript',
76
+ ts: 'typescript',
77
+ style: 'atdot',
78
+ yml: 'yaml',
79
+ sh: 'shellscript',
80
+ shell: 'shellscript',
81
+ bash: 'shellscript',
82
+ py: 'python',
83
+ };
84
+ export const loadMdCodeBlocks = (lang, code) => {
85
+ var _a, _b;
86
+ const info = loadedLangInfo[lang];
87
+ if (!(info === null || info === void 0 ? void 0 : info[autoLoadMdCodeBlocksKey]) || !(info === null || info === void 0 ? void 0 : info.embeddedLangsLazy)) {
88
+ return false;
89
+ }
90
+ let loadStarted = false;
91
+ codeBlockReg.lastIndex = 0;
92
+ let match;
93
+ while (match = codeBlockReg.exec(code)) {
94
+ const bl = (_a = match[2]) === null || _a === void 0 ? void 0 : _a.toLowerCase();
95
+ const blockLang = (_b = codeBlockMap[bl !== null && bl !== void 0 ? bl : '']) !== null && _b !== void 0 ? _b : bl;
96
+ if (!blockLang || loadLangMap[blockLang] || !info.embeddedLangsLazy.includes(blockLang)) {
97
+ continue;
98
+ }
99
+ loadShikiLangAsync(blockLang);
100
+ loadStarted = true;
101
+ }
102
+ return loadStarted;
103
+ };
104
+ const codeBlockReg = /(^|\n)```\s*([\w\-]+)/g;
105
+ export const getShikiAsync = () => __awaiter(void 0, void 0, void 0, function* () {
29
106
  if (!defaultHighlighter) {
30
- defaultHighlighter = getHighlighter({
31
- theme: 'dark-plus',
32
- langs: [],
33
- paths: {
34
- themes: '/highlighting/themes',
35
- languages: '/highlighting/languages',
36
- wasm: '/highlighting'
37
- }
38
- });
107
+ defaultHighlighter = (() => __awaiter(void 0, void 0, void 0, function* () {
108
+ const sh = yield import('shiki');
109
+ return sh.createHighlighter({
110
+ themes: ['dark-plus'],
111
+ langs: [],
112
+ });
113
+ }))();
39
114
  }
40
115
  return defaultHighlighter;
41
- };
116
+ });
42
117
  export const useShiki = (language) => {
43
118
  const [sh, setSh] = useState(null);
44
- const [langSh, setLangSh] = useState(null);
119
+ const [loadIndex, setLoadIndex] = useState(0);
45
120
  useEffect(() => {
46
121
  let m = true;
47
122
  getShikiAsync().then(v => {
@@ -54,437 +129,36 @@ export const useShiki = (language) => {
54
129
  };
55
130
  }, []);
56
131
  useEffect(() => {
57
- setLangSh(null);
132
+ setLoadIndex(v => v + 1);
58
133
  if (!sh || !language) {
59
134
  return;
60
135
  }
61
136
  let m = true;
62
137
  loadShikiLangAsync(language).then(() => {
63
138
  if (m) {
64
- setLangSh(sh);
139
+ setLoadIndex(v => v + 1);
65
140
  }
66
141
  });
67
142
  return () => {
68
143
  m = false;
69
144
  };
70
145
  }, [language, sh]);
71
- return language ? langSh : sh;
72
- };
73
- const convo = {
74
- "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
75
- "name": "convo",
76
- "scopeName": "source.convo",
77
- "uuid": "B7A8C571-820A-4958-A997-76DFD822B0FE",
78
- "fileTypes": ["convo"],
79
- "patterns": [
80
- { "include": "#expression" }
81
- ],
82
- "repository": {
83
- "expression": {
84
- "patterns": [
85
- { "include": "#interpolation" },
86
- { "include": "#topLevelStatements" },
87
- { "include": "#function" },
88
- { "include": "#role" },
89
- { "include": "#functionBody" },
90
- { "include": "#msgStringStartMsg" },
91
- { "include": "#msgStringBackslash" },
92
- { "include": "#embedEscape" },
93
- { "include": "#embed" },
94
- { "include": "#markdownLink" },
95
- { "include": "#comment" },
96
- { "include": "#tag" }
97
- ]
98
- },
99
- "interpolation": {
100
- "contentName": "meta.embedded.line.ts",
101
- "begin": "\\${",
102
- "beginCaptures": {
103
- "0": {
104
- "name": "punctuation.definition.interpolation.begin.bracket.curly.scss punctuation.definition.template-expression.begin.js"
105
- }
106
- },
107
- "end": "}",
108
- "endCaptures": {
109
- "0": {
110
- "name": "punctuation.definition.interpolation.end.bracket.curly.scss punctuation.definition.template-expression.end.js"
111
- }
112
- },
113
- "name": "variable.interpolation.scss",
114
- "patterns": [
115
- {
116
- "include": "source.ts#expression"
117
- },
118
- {
119
- "include": "#interpolation"
120
- }
121
- ]
122
- },
123
- "role": {
124
- "match": "^\\s*(>)\\s*(\\w+)\\s*([\\*\\?!]*)",
125
- "captures": {
126
- "1": {
127
- "name": "keyword.control"
128
- },
129
- "2": {
130
- "name": "storage.modifier"
131
- },
132
- "3": {
133
- "name": "entity.name.type"
134
- }
135
- }
136
- },
137
- "embedEscape": {
138
- "match": "(\\\\){\\{",
139
- "captures": {
140
- "1": {
141
- "name": "constant.character.escape"
142
- }
143
- }
144
- },
145
- "embed": {
146
- "begin": "\\{\\{",
147
- "end": "\\}\\}",
148
- "beginCaptures": {
149
- "0": {
150
- "name": "entity.name.tag"
151
- }
152
- },
153
- "endCaptures": {
154
- "0": {
155
- "name": "entity.name.tag"
156
- }
157
- },
158
- "patterns": [{ "include": "#lineExpression" }]
159
- },
160
- "topLevelStatements": {
161
- "begin": "^\\s*(>)\\s*(do|result|define|debug|end)",
162
- "end": "(?=\\s*>)",
163
- "beginCaptures": {
164
- "1": {
165
- "name": "keyword.control"
166
- },
167
- "2": {
168
- "name": "keyword.control"
169
- }
170
- },
171
- "patterns": [
172
- { "include": "#comment" },
173
- { "include": "#tag" },
174
- { "include": "#functionCall" },
175
- { "include": "#paramLineExpression" }
176
- ]
177
- },
178
- "function": {
179
- "begin": "^\\s*(>)\\s*(\\w+)?\\s+(\\w+)\\s*([\\*\\?!]*)\\s*(\\()",
180
- "end": "\\)",
181
- "beginCaptures": {
182
- "1": {
183
- "name": "keyword.control"
184
- },
185
- "2": {
186
- "name": "storage.modifier"
187
- },
188
- "3": {
189
- "name": "support.function"
190
- },
191
- "4": {
192
- "name": "entity.name.type"
193
- },
194
- "5": {
195
- "name": "keyword.control"
196
- }
197
- },
198
- "endCaptures": {
199
- "0": {
200
- "name": "keyword.control"
201
- }
202
- },
203
- "patterns": [
204
- { "include": "#comment" },
205
- { "include": "#tag" },
206
- { "include": "#functionCall" },
207
- { "include": "#paramLineExpression" }
208
- ]
209
- },
210
- "functionBody": {
211
- "begin": "(\\w+)?\\s*(->)\\s*(\\w+)?\\s*(\\()",
212
- "end": "\\)",
213
- "beginCaptures": {
214
- "1": {
215
- "name": "entity.name.type"
216
- },
217
- "2": {
218
- "name": "keyword.operator"
219
- },
220
- "3": {
221
- "name": "entity.name.type"
222
- },
223
- "4": {
224
- "name": "keyword.control"
225
- }
226
- },
227
- "endCaptures": {
228
- "0": {
229
- "name": "keyword.control"
230
- }
231
- },
232
- "patterns": [
233
- { "include": "#comment" },
234
- { "include": "#tag" },
235
- { "include": "#functionCall" },
236
- { "include": "#lineExpression" }
237
- ]
238
- },
239
- "functionCall": {
240
- "begin": "(\\w+)\\s*(\\()",
241
- "end": "\\)",
242
- "beginCaptures": {
243
- "1": {
244
- "name": "support.function",
245
- "patterns": [
246
- { "include": "#operators" },
247
- { "include": "#typeFunctions" },
248
- { "include": "#logicOperators" },
249
- { "include": "#systemFunctions" }
250
- ]
251
- },
252
- "2": {
253
- "name": "meta.parameters"
254
- }
255
- },
256
- "endCaptures": {
257
- "0": {
258
- "name": "meta.parameters"
259
- }
260
- },
261
- "patterns": [
262
- { "include": "#lineExpression" }
263
- ]
264
- },
265
- "comment": {
266
- "patterns": [
267
- {
268
- "match": "#.*",
269
- "name": "comment"
270
- },
271
- {
272
- "match": "//.*",
273
- "name": "emphasis",
274
- "captures": {
275
- "0": { "name": "comment" }
276
- }
277
- }
278
- ]
279
- },
280
- "tag": {
281
- "match": "(@)\\s*(\\w*)\\s*=?(.*)",
282
- "captures": {
283
- "1": {
284
- "name": "entity.name.tag"
285
- },
286
- "2": {
287
- "name": "entity.name.tag"
288
- },
289
- "3": {
290
- "name": "string"
291
- }
292
- }
293
- },
294
- "lineExpression": {
295
- "patterns": [
296
- { "include": "#comment" },
297
- { "include": "#tag" },
298
- { "include": "#heredoc" },
299
- { "include": "#stringDq" },
300
- { "include": "#stringSq" },
301
- { "include": "#pipe" },
302
- { "include": "#functionCall" },
303
- { "include": "#label" },
304
- { "include": "#typeKeyword" },
305
- { "include": "#number" },
306
- { "include": "#constValue" },
307
- { "include": "#userDefinedType" },
308
- { "include": "#lineVar" }
309
- ]
310
- },
311
- "paramLineExpression": {
312
- "patterns": [
313
- { "include": "#comment" },
314
- { "include": "#tag" },
315
- { "include": "#heredoc" },
316
- { "include": "#stringDq" },
317
- { "include": "#stringSq" },
318
- { "include": "#pipe" },
319
- { "include": "#functionCall" },
320
- { "include": "#paramLabel" },
321
- { "include": "#typeKeyword" },
322
- { "include": "#number" },
323
- { "include": "#constValue" },
324
- { "include": "#userDefinedType" },
325
- { "include": "#lineVar" }
326
- ]
327
- },
328
- "userDefinedType": {
329
- "match": "\\b[A-Z]\\w*\\b",
330
- "captures": {
331
- "0": {
332
- "name": "entity.name.type"
333
- }
334
- }
335
- },
336
- "lineVar": {
337
- "match": "\\b\\w+\\b",
338
- "captures": {
339
- "0": {
340
- "name": "variable"
341
- }
342
- }
343
- },
344
- "label": {
345
- "match": "(\\w+)\\s*(\\?)?\\s*:",
346
- "captures": {
347
- "1": {
348
- "name": "entity.name"
349
- }
350
- }
351
- },
352
- "paramLabel": {
353
- "match": "(\\w+)\\s*(\\?)?\\s*:",
354
- "captures": {
355
- "1": {
356
- "name": "variable"
357
- }
358
- }
359
- },
360
- "stringDq": {
361
- "begin": "\"",
362
- "end": "\"",
363
- "name": "string",
364
- "patterns": [
365
- { "include": "#stringBackslash" },
366
- {
367
- "match": "(\\\\)(\")",
368
- "captures": {
369
- "1": { "name": "constant.character.escape" },
370
- "2": { "name": "string" }
371
- }
372
- }
373
- ]
374
- },
375
- "stringSq": {
376
- "begin": "'",
377
- "end": "'",
378
- "name": "string",
379
- "patterns": [
380
- { "include": "#stringBackslash" },
381
- {
382
- "match": "(\\\\)(')",
383
- "captures": {
384
- "1": { "name": "constant.character.escape" },
385
- "2": { "name": "string" }
386
- }
387
- },
388
- { "include": "#embedEscape" },
389
- { "include": "#embed" }
390
- ]
391
- },
392
- "markdownLink": {
393
- "begin": "!?\\[",
394
- "end": "(\\]\\()([^\\)]*)(\\))",
395
- "beginCaptures": {
396
- "0": { "name": "keyword.control" }
397
- },
398
- "endCaptures": {
399
- "1": { "name": "keyword.control" },
400
- "2": { "name": "string" },
401
- "3": { "name": "keyword.control" }
402
- },
403
- "contentName": "comment"
404
- },
405
- "stringBackslash": {
406
- "match": "(\\\\)\\\\",
407
- "captures": {
408
- "1": { "name": "constant.character.escape" }
409
- }
410
- },
411
- "msgStringBackslash": {
412
- "match": "(\\\\)\\\\(?=\\{\\{)",
413
- "captures": {
414
- "1": { "name": "constant.character.escape" }
415
- }
416
- },
417
- "msgStringStartMsg": {
418
- "match": "^[ \\t]*(\\\\)\\\\*>",
419
- "captures": {
420
- "1": { "name": "constant.character.escape" }
421
- }
422
- },
423
- "typeKeyword": {
424
- "match": "\\b(string|number|int|boolean|time|void|any|map|array)\\b",
425
- "captures": {
426
- "1": {
427
- "name": "entity.name.type"
428
- }
429
- }
430
- },
431
- "systemFunctions": {
432
- "match": "\\b(elif|if|else|while|break|foreach|for|in|do|then|fn|return|case|default|switch|test)$",
433
- "captures": {
434
- "1": {
435
- "name": "keyword.control"
436
- }
437
- }
438
- },
439
- "typeFunctions": {
440
- "match": "\\b(enum|struct|array)$",
441
- "captures": {
442
- "1": {
443
- "name": "keyword.control"
444
- }
445
- }
446
- },
447
- "operators": {
448
- "match": "\\b(lt|lte|eq|gt|gte|is|add|sub|mul|div|not|mod|pow|inc|dec)$",
449
- "captures": {
450
- "1": {
451
- "name": "keyword"
452
- }
453
- }
454
- },
455
- "logicOperators": {
456
- "match": "\\b(and|or)$",
457
- "captures": {
458
- "1": {
459
- "name": "keyword"
146
+ useEffect(() => {
147
+ let iv = undefined;
148
+ let m = true;
149
+ const sub = onLangLoad.subscribe(() => {
150
+ iv = setTimeout(() => {
151
+ clearTimeout(iv);
152
+ if (m) {
153
+ setLoadIndex(v => v + 1);
460
154
  }
461
- }
462
- },
463
- "number": {
464
- "match": "-?(\\d+\\.\\d+|\\.\\d+|\\d+)+",
465
- "name": "entity.name.type"
466
- },
467
- "constValue": {
468
- "match": "\\b(true|false|null|undefined|convo|__args|__return|__error|__debug|__disableAutoComplete)\\b",
469
- "name": "constant.language"
470
- },
471
- "heredoc": {
472
- "begin": "-{3,}",
473
- "end": "-{3,}",
474
- "beginCaptures": {
475
- "0": { "name": "comment" }
476
- },
477
- "endCaptures": {
478
- "0": { "name": "comment" }
479
- },
480
- "patterns": [
481
- { "include": "#expression" }
482
- ]
483
- },
484
- "pipe": {
485
- "match": "<<",
486
- "name": "keyword.control"
487
- }
488
- }
155
+ }, 100);
156
+ });
157
+ return () => {
158
+ sub.unsubscribe();
159
+ m = false;
160
+ };
161
+ }, []);
162
+ return { sh, loadIndex };
489
163
  };
490
164
  //# sourceMappingURL=shiki.js.map