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