@carbon/ai-chat 0.1.6 → 0.1.7-alpha0

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 (144) hide show
  1. package/dist/cjs/{cds-aichat-internal.js → AppContainer.js} +615 -7203
  2. package/dist/cjs/Carousel.js +24 -16
  3. package/dist/cjs/Chat.js +813 -805
  4. package/dist/cjs/GenesysMessengerServiceDesk.js +60 -52
  5. package/dist/cjs/HumanAgentServiceImpl.js +103 -95
  6. package/dist/cjs/NiceDFOServiceDesk.js +56 -48
  7. package/dist/cjs/PDFViewerContainer.js +58 -149
  8. package/dist/cjs/ReactPlayer.js +2 -2
  9. package/dist/cjs/SFServiceDesk.js +66 -58
  10. package/dist/cjs/ServiceDeskImpl.js +2 -2
  11. package/dist/cjs/Table.js +457 -341
  12. package/dist/cjs/ZendeskServiceDesk.js +36 -28
  13. package/dist/cjs/_node-resolve_empty.js +2 -2
  14. package/dist/cjs/agentActions.js +5 -5
  15. package/dist/cjs/aiChatEntry.js +163 -144
  16. package/dist/cjs/anonymousUserIDStorage.js +8 -8
  17. package/dist/cjs/ar-dz.js +4 -4
  18. package/dist/cjs/ar-kw.js +4 -4
  19. package/dist/cjs/ar-ly.js +4 -4
  20. package/dist/cjs/ar-ma.js +4 -4
  21. package/dist/cjs/ar-sa.js +4 -4
  22. package/dist/cjs/ar-tn.js +4 -4
  23. package/dist/cjs/ar.js +4 -4
  24. package/dist/cjs/ar2.js +2 -2
  25. package/dist/cjs/cds-aichat-container.js +111 -23
  26. package/dist/cjs/cds-aichat-custom-element.js +42 -30
  27. package/dist/cjs/cs.js +4 -4
  28. package/dist/cjs/cs2.js +2 -2
  29. package/dist/cjs/de-at.js +4 -4
  30. package/dist/cjs/de-ch.js +4 -4
  31. package/dist/cjs/de.js +4 -4
  32. package/dist/cjs/de2.js +2 -2
  33. package/dist/cjs/en-au.js +4 -4
  34. package/dist/cjs/en-ca.js +4 -4
  35. package/dist/cjs/en-gb.js +4 -4
  36. package/dist/cjs/en-ie.js +4 -4
  37. package/dist/cjs/en-il.js +4 -4
  38. package/dist/cjs/en-nz.js +4 -4
  39. package/dist/cjs/es-do.js +4 -4
  40. package/dist/cjs/es-us.js +4 -4
  41. package/dist/cjs/es.js +4 -4
  42. package/dist/cjs/es2.js +2 -2
  43. package/dist/cjs/export.js +3 -3
  44. package/dist/cjs/export.legacy.js +3 -3
  45. package/dist/cjs/fontUtils.js +2 -2
  46. package/dist/cjs/fr-ca.js +4 -4
  47. package/dist/cjs/fr-ch.js +4 -4
  48. package/dist/cjs/fr.js +4 -4
  49. package/dist/cjs/fr2.js +2 -2
  50. package/dist/cjs/highlight_js.js +2 -2
  51. package/dist/cjs/it-ch.js +4 -4
  52. package/dist/cjs/it.js +4 -4
  53. package/dist/cjs/it2.js +2 -2
  54. package/dist/cjs/ja.js +4 -4
  55. package/dist/cjs/ja2.js +2 -2
  56. package/dist/cjs/ko.js +4 -4
  57. package/dist/cjs/ko2.js +2 -2
  58. package/dist/cjs/markdown.js +2362 -14
  59. package/dist/cjs/mockServiceDesk.js +42 -34
  60. package/dist/cjs/nl.js +4 -4
  61. package/dist/cjs/nl2.js +2 -2
  62. package/dist/cjs/pt-br.js +4 -4
  63. package/dist/cjs/pt-br2.js +2 -2
  64. package/dist/cjs/pt.js +4 -4
  65. package/dist/cjs/render.js +18 -10
  66. package/dist/cjs/zh-cn.js +4 -4
  67. package/dist/cjs/zh-tw.js +4 -4
  68. package/dist/cjs/zh-tw2.js +2 -2
  69. package/dist/cjs/zh.js +2 -2
  70. package/dist/es/{cds-aichat-internal.js → AppContainer.js} +1117 -7671
  71. package/dist/es/Carousel.js +16 -8
  72. package/dist/es/Chat.js +16 -8
  73. package/dist/es/GenesysMessengerServiceDesk.js +16 -8
  74. package/dist/es/HumanAgentServiceImpl.js +16 -8
  75. package/dist/es/NiceDFOServiceDesk.js +16 -8
  76. package/dist/es/PDFViewerContainer.js +16 -107
  77. package/dist/es/ReactPlayer.js +2 -2
  78. package/dist/es/SFServiceDesk.js +16 -8
  79. package/dist/es/ServiceDeskImpl.js +2 -2
  80. package/dist/es/Table.js +426 -310
  81. package/dist/es/ZendeskServiceDesk.js +16 -8
  82. package/dist/es/_node-resolve_empty.js +2 -2
  83. package/dist/es/agentActions.js +3 -3
  84. package/dist/es/aiChatEntry.js +136 -117
  85. package/dist/es/anonymousUserIDStorage.js +3 -3
  86. package/dist/es/ar-dz.js +3 -3
  87. package/dist/es/ar-kw.js +3 -3
  88. package/dist/es/ar-ly.js +3 -3
  89. package/dist/es/ar-ma.js +3 -3
  90. package/dist/es/ar-sa.js +3 -3
  91. package/dist/es/ar-tn.js +3 -3
  92. package/dist/es/ar.js +3 -3
  93. package/dist/es/ar2.js +2 -2
  94. package/dist/es/cds-aichat-container.js +103 -15
  95. package/dist/es/cds-aichat-custom-element.js +30 -18
  96. package/dist/es/cs.js +3 -3
  97. package/dist/es/cs2.js +2 -2
  98. package/dist/es/de-at.js +3 -3
  99. package/dist/es/de-ch.js +3 -3
  100. package/dist/es/de.js +3 -3
  101. package/dist/es/de2.js +2 -2
  102. package/dist/es/en-au.js +3 -3
  103. package/dist/es/en-ca.js +3 -3
  104. package/dist/es/en-gb.js +3 -3
  105. package/dist/es/en-ie.js +3 -3
  106. package/dist/es/en-il.js +3 -3
  107. package/dist/es/en-nz.js +3 -3
  108. package/dist/es/es-do.js +3 -3
  109. package/dist/es/es-us.js +3 -3
  110. package/dist/es/es.js +3 -3
  111. package/dist/es/es2.js +2 -2
  112. package/dist/es/export.js +3 -3
  113. package/dist/es/export.legacy.js +3 -3
  114. package/dist/es/fontUtils.js +2 -2
  115. package/dist/es/fr-ca.js +3 -3
  116. package/dist/es/fr-ch.js +3 -3
  117. package/dist/es/fr.js +3 -3
  118. package/dist/es/fr2.js +2 -2
  119. package/dist/es/highlight_js.js +2 -2
  120. package/dist/es/it-ch.js +3 -3
  121. package/dist/es/it.js +3 -3
  122. package/dist/es/it2.js +2 -2
  123. package/dist/es/ja.js +3 -3
  124. package/dist/es/ja2.js +2 -2
  125. package/dist/es/ko.js +3 -3
  126. package/dist/es/ko2.js +2 -2
  127. package/dist/es/markdown.js +2361 -15
  128. package/dist/es/mockServiceDesk.js +16 -8
  129. package/dist/es/nl.js +3 -3
  130. package/dist/es/nl2.js +2 -2
  131. package/dist/es/pt-br.js +3 -3
  132. package/dist/es/pt-br2.js +2 -2
  133. package/dist/es/pt.js +3 -3
  134. package/dist/es/render.js +17 -9
  135. package/dist/es/zh-cn.js +3 -3
  136. package/dist/es/zh-tw.js +3 -3
  137. package/dist/es/zh-tw2.js +2 -2
  138. package/dist/es/zh.js +2 -2
  139. package/dist/types/aiChatEntry.d.ts +69 -9
  140. package/package.json +27 -14
  141. package/dist/cjs/jstz.min.js +0 -43
  142. package/dist/cjs/markdown_attrs.js +0 -805
  143. package/dist/es/jstz.min.js +0 -41
  144. package/dist/es/markdown_attrs.js +0 -803
@@ -1,803 +0,0 @@
1
- /*
2
-
3
-
4
- (C) Copyright IBM Corp. 2017, 2025. All Rights Reserved.
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7
- in compliance with the License. You may obtain a copy of the License at
8
-
9
- http://www.apache.org/licenses/LICENSE-2.0
10
-
11
- Unless required by applicable law or agreed to in writing, software distributed under the License
12
- is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13
- or implied. See the License for the specific language governing permissions and limitations under
14
- the License.
15
-
16
- @carbon/ai-chat 0.1.6
17
-
18
- Built: Feb 3 2025 9:58 am -05:00
19
-
20
-
21
-
22
- */
23
- import { g as getDefaultExportFromCjs } from './highlight_js.js';
24
-
25
- var utils$1 = {};
26
-
27
- /**
28
- * parse {.class #id key=val} strings
29
- * @param {string} str: string to parse
30
- * @param {int} start: where to start parsing (including {)
31
- * @returns {2d array}: [['key', 'val'], ['class', 'red']]
32
- */
33
-
34
- utils$1.getAttrs = function (str, start, options) {
35
- // not tab, line feed, form feed, space, solidus, greater than sign, quotation mark, apostrophe and equals sign
36
- const allowedKeyChars = /[^\t\n\f />"'=]/;
37
- const pairSeparator = ' ';
38
- const keySeparator = '=';
39
- const classChar = '.';
40
- const idChar = '#';
41
-
42
- const attrs = [];
43
- let key = '';
44
- let value = '';
45
- let parsingKey = true;
46
- let valueInsideQuotes = false;
47
-
48
- // read inside {}
49
- // start + left delimiter length to avoid beginning {
50
- // breaks when } is found or end of string
51
- for (let i = start + options.leftDelimiter.length; i < str.length; i++) {
52
- if (str.slice(i, i + options.rightDelimiter.length) === options.rightDelimiter) {
53
- if (key !== '') { attrs.push([key, value]); }
54
- break;
55
- }
56
- const char_ = str.charAt(i);
57
-
58
- // switch to reading value if equal sign
59
- if (char_ === keySeparator && parsingKey) {
60
- parsingKey = false;
61
- continue;
62
- }
63
-
64
- // {.class} {..css-module}
65
- if (char_ === classChar && key === '') {
66
- if (str.charAt(i + 1) === classChar) {
67
- key = 'css-module';
68
- i += 1;
69
- } else {
70
- key = 'class';
71
- }
72
- parsingKey = false;
73
- continue;
74
- }
75
-
76
- // {#id}
77
- if (char_ === idChar && key === '') {
78
- key = 'id';
79
- parsingKey = false;
80
- continue;
81
- }
82
-
83
- // {value="inside quotes"}
84
- if (char_ === '"' && value === '' && !valueInsideQuotes) {
85
- valueInsideQuotes = true;
86
- continue;
87
- }
88
- if (char_ === '"' && valueInsideQuotes) {
89
- valueInsideQuotes = false;
90
- continue;
91
- }
92
-
93
- // read next key/value pair
94
- if ((char_ === pairSeparator && !valueInsideQuotes)) {
95
- if (key === '') {
96
- // beginning or ending space: { .red } vs {.red}
97
- continue;
98
- }
99
- attrs.push([key, value]);
100
- key = '';
101
- value = '';
102
- parsingKey = true;
103
- continue;
104
- }
105
-
106
- // continue if character not allowed
107
- if (parsingKey && char_.search(allowedKeyChars) === -1) {
108
- continue;
109
- }
110
-
111
- // no other conditions met; append to key/value
112
- if (parsingKey) {
113
- key += char_;
114
- continue;
115
- }
116
- value += char_;
117
- }
118
-
119
- if (options.allowedAttributes && options.allowedAttributes.length) {
120
- const allowedAttributes = options.allowedAttributes;
121
-
122
- return attrs.filter(function (attrPair) {
123
- const attr = attrPair[0];
124
-
125
- function isAllowedAttribute (allowedAttribute) {
126
- return (attr === allowedAttribute
127
- || (allowedAttribute instanceof RegExp && allowedAttribute.test(attr))
128
- );
129
- }
130
-
131
- return allowedAttributes.some(isAllowedAttribute);
132
- });
133
-
134
- }
135
- return attrs;
136
-
137
- };
138
-
139
- /**
140
- * add attributes from [['key', 'val']] list
141
- * @param {array} attrs: [['key', 'val']]
142
- * @param {token} token: which token to add attributes
143
- * @returns token
144
- */
145
- utils$1.addAttrs = function (attrs, token) {
146
- for (let j = 0, l = attrs.length; j < l; ++j) {
147
- const key = attrs[j][0];
148
- if (key === 'class') {
149
- token.attrJoin('class', attrs[j][1]);
150
- } else if (key === 'css-module') {
151
- token.attrJoin('css-module', attrs[j][1]);
152
- } else {
153
- token.attrPush(attrs[j]);
154
- }
155
- }
156
- return token;
157
- };
158
-
159
- /**
160
- * Does string have properly formatted curly?
161
- *
162
- * start: '{.a} asdf'
163
- * end: 'asdf {.a}'
164
- * only: '{.a}'
165
- *
166
- * @param {string} where to expect {} curly. start, end or only.
167
- * @return {function(string)} Function which testes if string has curly.
168
- */
169
- utils$1.hasDelimiters = function (where, options) {
170
-
171
- if (!where) {
172
- throw new Error('Parameter `where` not passed. Should be "start", "end" or "only".');
173
- }
174
-
175
- /**
176
- * @param {string} str
177
- * @return {boolean}
178
- */
179
- return function (str) {
180
- // we need minimum three chars, for example {b}
181
- const minCurlyLength = options.leftDelimiter.length + 1 + options.rightDelimiter.length;
182
- if (!str || typeof str !== 'string' || str.length < minCurlyLength) {
183
- return false;
184
- }
185
-
186
- function validCurlyLength (curly) {
187
- const isClass = curly.charAt(options.leftDelimiter.length) === '.';
188
- const isId = curly.charAt(options.leftDelimiter.length) === '#';
189
- return (isClass || isId)
190
- ? curly.length >= (minCurlyLength + 1)
191
- : curly.length >= minCurlyLength;
192
- }
193
-
194
- let start, end, slice, nextChar;
195
- const rightDelimiterMinimumShift = minCurlyLength - options.rightDelimiter.length;
196
- switch (where) {
197
- case 'start':
198
- // first char should be {, } found in char 2 or more
199
- slice = str.slice(0, options.leftDelimiter.length);
200
- start = slice === options.leftDelimiter ? 0 : -1;
201
- end = start === -1 ? -1 : str.indexOf(options.rightDelimiter, rightDelimiterMinimumShift);
202
- // check if next character is not one of the delimiters
203
- nextChar = str.charAt(end + options.rightDelimiter.length);
204
- if (nextChar && options.rightDelimiter.indexOf(nextChar) !== -1) {
205
- end = -1;
206
- }
207
- break;
208
-
209
- case 'end':
210
- // last char should be }
211
- start = str.lastIndexOf(options.leftDelimiter);
212
- end = start === -1 ? -1 : str.indexOf(options.rightDelimiter, start + rightDelimiterMinimumShift);
213
- end = end === str.length - options.rightDelimiter.length ? end : -1;
214
- break;
215
-
216
- case 'only':
217
- // '{.a}'
218
- slice = str.slice(0, options.leftDelimiter.length);
219
- start = slice === options.leftDelimiter ? 0 : -1;
220
- slice = str.slice(str.length - options.rightDelimiter.length);
221
- end = slice === options.rightDelimiter ? str.length - options.rightDelimiter.length : -1;
222
- break;
223
-
224
- default:
225
- throw new Error(`Unexpected case ${where}, expected 'start', 'end' or 'only'`);
226
- }
227
-
228
- return start !== -1 && end !== -1 && validCurlyLength(str.substring(start, end + options.rightDelimiter.length));
229
- };
230
- };
231
-
232
- /**
233
- * Removes last curly from string.
234
- */
235
- utils$1.removeDelimiter = function (str, options) {
236
- const start = escapeRegExp(options.leftDelimiter);
237
- const end = escapeRegExp(options.rightDelimiter);
238
-
239
- const curly = new RegExp(
240
- '[ \\n]?' + start + '[^' + start + end + ']+' + end + '$'
241
- );
242
- const pos = str.search(curly);
243
-
244
- return pos !== -1 ? str.slice(0, pos) : str;
245
- };
246
-
247
- /**
248
- * Escapes special characters in string s such that the string
249
- * can be used in `new RegExp`. For example "[" becomes "\\[".
250
- *
251
- * @param {string} s Regex string.
252
- * @return {string} Escaped string.
253
- */
254
- function escapeRegExp (s) {
255
- return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
256
- }
257
- utils$1.escapeRegExp = escapeRegExp;
258
-
259
- /**
260
- * find corresponding opening block
261
- */
262
- utils$1.getMatchingOpeningToken = function (tokens, i) {
263
- if (tokens[i].type === 'softbreak') {
264
- return false;
265
- }
266
- // non closing blocks, example img
267
- if (tokens[i].nesting === 0) {
268
- return tokens[i];
269
- }
270
-
271
- const level = tokens[i].level;
272
- const type = tokens[i].type.replace('_close', '_open');
273
-
274
- for (; i >= 0; --i) {
275
- if (tokens[i].type === type && tokens[i].level === level) {
276
- return tokens[i];
277
- }
278
- }
279
-
280
- return false;
281
- };
282
-
283
-
284
- /**
285
- * from https://github.com/markdown-it/markdown-it/blob/master/lib/common/utils.js
286
- */
287
- const HTML_ESCAPE_TEST_RE = /[&<>"]/;
288
- const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g;
289
- const HTML_REPLACEMENTS = {
290
- '&': '&amp;',
291
- '<': '&lt;',
292
- '>': '&gt;',
293
- '"': '&quot;'
294
- };
295
-
296
- function replaceUnsafeChar(ch) {
297
- return HTML_REPLACEMENTS[ch];
298
- }
299
-
300
- utils$1.escapeHtml = function (str) {
301
- if (HTML_ESCAPE_TEST_RE.test(str)) {
302
- return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar);
303
- }
304
- return str;
305
- };
306
-
307
- /**
308
- * If a pattern matches the token stream,
309
- * then run transform.
310
- */
311
-
312
- const utils = utils$1;
313
-
314
- var patterns = options => {
315
- const __hr = new RegExp('^ {0,3}[-*_]{3,} ?'
316
- + utils.escapeRegExp(options.leftDelimiter)
317
- + '[^' + utils.escapeRegExp(options.rightDelimiter) + ']');
318
-
319
- return ([
320
- {
321
- /**
322
- * ```python {.cls}
323
- * for i in range(10):
324
- * print(i)
325
- * ```
326
- */
327
- name: 'fenced code blocks',
328
- tests: [
329
- {
330
- shift: 0,
331
- block: true,
332
- info: utils.hasDelimiters('end', options)
333
- }
334
- ],
335
- transform: (tokens, i) => {
336
- const token = tokens[i];
337
- const start = token.info.lastIndexOf(options.leftDelimiter);
338
- const attrs = utils.getAttrs(token.info, start, options);
339
- utils.addAttrs(attrs, token);
340
- token.info = utils.removeDelimiter(token.info, options);
341
- }
342
- }, {
343
- /**
344
- * bla `click()`{.c} ![](img.png){.d}
345
- *
346
- * differs from 'inline attributes' as it does
347
- * not have a closing tag (nesting: -1)
348
- */
349
- name: 'inline nesting 0',
350
- tests: [
351
- {
352
- shift: 0,
353
- type: 'inline',
354
- children: [
355
- {
356
- shift: -1,
357
- type: (str) => str === 'image' || str === 'code_inline'
358
- }, {
359
- shift: 0,
360
- type: 'text',
361
- content: utils.hasDelimiters('start', options)
362
- }
363
- ]
364
- }
365
- ],
366
- transform: (tokens, i, j) => {
367
- const token = tokens[i].children[j];
368
- const endChar = token.content.indexOf(options.rightDelimiter);
369
- const attrToken = tokens[i].children[j - 1];
370
- const attrs = utils.getAttrs(token.content, 0, options);
371
- utils.addAttrs(attrs, attrToken);
372
- if (token.content.length === (endChar + options.rightDelimiter.length)) {
373
- tokens[i].children.splice(j, 1);
374
- } else {
375
- token.content = token.content.slice(endChar + options.rightDelimiter.length);
376
- }
377
- }
378
- }, {
379
- /**
380
- * | h1 |
381
- * | -- |
382
- * | c1 |
383
- *
384
- * {.c}
385
- */
386
- name: 'tables',
387
- tests: [
388
- {
389
- // let this token be i, such that for-loop continues at
390
- // next token after tokens.splice
391
- shift: 0,
392
- type: 'table_close'
393
- }, {
394
- shift: 1,
395
- type: 'paragraph_open'
396
- }, {
397
- shift: 2,
398
- type: 'inline',
399
- content: utils.hasDelimiters('only', options)
400
- }
401
- ],
402
- transform: (tokens, i) => {
403
- const token = tokens[i + 2];
404
- const tableOpen = utils.getMatchingOpeningToken(tokens, i);
405
- const attrs = utils.getAttrs(token.content, 0, options);
406
- // add attributes
407
- utils.addAttrs(attrs, tableOpen);
408
- // remove <p>{.c}</p>
409
- tokens.splice(i + 1, 3);
410
- }
411
- }, {
412
- /**
413
- * *emphasis*{.with attrs=1}
414
- */
415
- name: 'inline attributes',
416
- tests: [
417
- {
418
- shift: 0,
419
- type: 'inline',
420
- children: [
421
- {
422
- shift: -1,
423
- nesting: -1 // closing inline tag, </em>{.a}
424
- }, {
425
- shift: 0,
426
- type: 'text',
427
- content: utils.hasDelimiters('start', options)
428
- }
429
- ]
430
- }
431
- ],
432
- transform: (tokens, i, j) => {
433
- const token = tokens[i].children[j];
434
- const content = token.content;
435
- const attrs = utils.getAttrs(content, 0, options);
436
- const openingToken = utils.getMatchingOpeningToken(tokens[i].children, j - 1);
437
- utils.addAttrs(attrs, openingToken);
438
- token.content = content.slice(content.indexOf(options.rightDelimiter) + options.rightDelimiter.length);
439
- }
440
- }, {
441
- /**
442
- * - item
443
- * {.a}
444
- */
445
- name: 'list softbreak',
446
- tests: [
447
- {
448
- shift: -2,
449
- type: 'list_item_open'
450
- }, {
451
- shift: 0,
452
- type: 'inline',
453
- children: [
454
- {
455
- position: -2,
456
- type: 'softbreak'
457
- }, {
458
- position: -1,
459
- type: 'text',
460
- content: utils.hasDelimiters('only', options)
461
- }
462
- ]
463
- }
464
- ],
465
- transform: (tokens, i, j) => {
466
- const token = tokens[i].children[j];
467
- const content = token.content;
468
- const attrs = utils.getAttrs(content, 0, options);
469
- let ii = i - 2;
470
- while (tokens[ii - 1] &&
471
- tokens[ii - 1].type !== 'ordered_list_open' &&
472
- tokens[ii - 1].type !== 'bullet_list_open') { ii--; }
473
- utils.addAttrs(attrs, tokens[ii - 1]);
474
- tokens[i].children = tokens[i].children.slice(0, -2);
475
- }
476
- }, {
477
- /**
478
- * - nested list
479
- * - with double \n
480
- * {.a} <-- apply to nested ul
481
- *
482
- * {.b} <-- apply to root <ul>
483
- */
484
- name: 'list double softbreak',
485
- tests: [
486
- {
487
- // let this token be i = 0 so that we can erase
488
- // the <p>{.a}</p> tokens below
489
- shift: 0,
490
- type: (str) =>
491
- str === 'bullet_list_close' ||
492
- str === 'ordered_list_close'
493
- }, {
494
- shift: 1,
495
- type: 'paragraph_open'
496
- }, {
497
- shift: 2,
498
- type: 'inline',
499
- content: utils.hasDelimiters('only', options),
500
- children: (arr) => arr.length === 1
501
- }, {
502
- shift: 3,
503
- type: 'paragraph_close'
504
- }
505
- ],
506
- transform: (tokens, i) => {
507
- const token = tokens[i + 2];
508
- const content = token.content;
509
- const attrs = utils.getAttrs(content, 0, options);
510
- const openingToken = utils.getMatchingOpeningToken(tokens, i);
511
- utils.addAttrs(attrs, openingToken);
512
- tokens.splice(i + 1, 3);
513
- }
514
- }, {
515
- /**
516
- * - end of {.list-item}
517
- */
518
- name: 'list item end',
519
- tests: [
520
- {
521
- shift: -2,
522
- type: 'list_item_open'
523
- }, {
524
- shift: 0,
525
- type: 'inline',
526
- children: [
527
- {
528
- position: -1,
529
- type: 'text',
530
- content: utils.hasDelimiters('end', options)
531
- }
532
- ]
533
- }
534
- ],
535
- transform: (tokens, i, j) => {
536
- const token = tokens[i].children[j];
537
- const content = token.content;
538
- const attrs = utils.getAttrs(content, content.lastIndexOf(options.leftDelimiter), options);
539
- utils.addAttrs(attrs, tokens[i - 2]);
540
- const trimmed = content.slice(0, content.lastIndexOf(options.leftDelimiter));
541
- token.content = last$1(trimmed) !== ' ' ?
542
- trimmed : trimmed.slice(0, -1);
543
- }
544
- }, {
545
- /**
546
- * something with softbreak
547
- * {.cls}
548
- */
549
- name: '\n{.a} softbreak then curly in start',
550
- tests: [
551
- {
552
- shift: 0,
553
- type: 'inline',
554
- children: [
555
- {
556
- position: -2,
557
- type: 'softbreak'
558
- }, {
559
- position: -1,
560
- type: 'text',
561
- content: utils.hasDelimiters('only', options)
562
- }
563
- ]
564
- }
565
- ],
566
- transform: (tokens, i, j) => {
567
- const token = tokens[i].children[j];
568
- const attrs = utils.getAttrs(token.content, 0, options);
569
- // find last closing tag
570
- let ii = i + 1;
571
- while (tokens[ii + 1] && tokens[ii + 1].nesting === -1) { ii++; }
572
- const openingToken = utils.getMatchingOpeningToken(tokens, ii);
573
- utils.addAttrs(attrs, openingToken);
574
- tokens[i].children = tokens[i].children.slice(0, -2);
575
- }
576
- }, {
577
- /**
578
- * horizontal rule --- {#id}
579
- */
580
- name: 'horizontal rule',
581
- tests: [
582
- {
583
- shift: 0,
584
- type: 'paragraph_open'
585
- },
586
- {
587
- shift: 1,
588
- type: 'inline',
589
- children: (arr) => arr.length === 1,
590
- content: (str) => str.match(__hr) !== null,
591
- },
592
- {
593
- shift: 2,
594
- type: 'paragraph_close'
595
- }
596
- ],
597
- transform: (tokens, i) => {
598
- const token = tokens[i];
599
- token.type = 'hr';
600
- token.tag = 'hr';
601
- token.nesting = 0;
602
- const content = tokens[i + 1].content;
603
- const start = content.lastIndexOf(options.leftDelimiter);
604
- const attrs = utils.getAttrs(content, start, options);
605
- utils.addAttrs(attrs, token);
606
- token.markup = content;
607
- tokens.splice(i + 1, 2);
608
- }
609
- }, {
610
- /**
611
- * end of {.block}
612
- */
613
- name: 'end of block',
614
- tests: [
615
- {
616
- shift: 0,
617
- type: 'inline',
618
- children: [
619
- {
620
- position: -1,
621
- content: utils.hasDelimiters('end', options),
622
- type: (t) => t !== 'code_inline' && t !== 'math_inline'
623
- }
624
- ]
625
- }
626
- ],
627
- transform: (tokens, i, j) => {
628
- const token = tokens[i].children[j];
629
- const content = token.content;
630
- const attrs = utils.getAttrs(content, content.lastIndexOf(options.leftDelimiter), options);
631
- let ii = i + 1;
632
- while (tokens[ii + 1] && tokens[ii + 1].nesting === -1) { ii++; }
633
- const openingToken = utils.getMatchingOpeningToken(tokens, ii);
634
- utils.addAttrs(attrs, openingToken);
635
- const trimmed = content.slice(0, content.lastIndexOf(options.leftDelimiter));
636
- token.content = last$1(trimmed) !== ' ' ?
637
- trimmed : trimmed.slice(0, -1);
638
- }
639
- }
640
- ]);
641
- };
642
-
643
- // get last element of array or string
644
- function last$1(arr) {
645
- return arr.slice(-1)[0];
646
- }
647
-
648
- const patternsConfig = patterns;
649
-
650
- const defaultOptions = {
651
- leftDelimiter: '{',
652
- rightDelimiter: '}',
653
- allowedAttributes: []
654
- };
655
-
656
- var markdownItAttrs = function attributes(md, options_) {
657
- let options = Object.assign({}, defaultOptions);
658
- options = Object.assign(options, options_);
659
-
660
- const patterns = patternsConfig(options);
661
-
662
- function curlyAttrs(state) {
663
- const tokens = state.tokens;
664
-
665
- for (let i = 0; i < tokens.length; i++) {
666
- for (let p = 0; p < patterns.length; p++) {
667
- const pattern = patterns[p];
668
- let j = null; // position of child with offset 0
669
- const match = pattern.tests.every(t => {
670
- const res = test(tokens, i, t);
671
- if (res.j !== null) { j = res.j; }
672
- return res.match;
673
- });
674
- if (match) {
675
- pattern.transform(tokens, i, j);
676
- if (pattern.name === 'inline attributes' || pattern.name === 'inline nesting 0') {
677
- // retry, may be several inline attributes
678
- p--;
679
- }
680
- }
681
- }
682
- }
683
- }
684
-
685
- md.core.ruler.before('linkify', 'curly_attributes', curlyAttrs);
686
- };
687
-
688
- /**
689
- * Test if t matches token stream.
690
- *
691
- * @param {array} tokens
692
- * @param {number} i
693
- * @param {object} t Test to match.
694
- * @return {object} { match: true|false, j: null|number }
695
- */
696
- function test(tokens, i, t) {
697
- const res = {
698
- match: false,
699
- j: null // position of child
700
- };
701
-
702
- const ii = t.shift !== undefined
703
- ? i + t.shift
704
- : t.position;
705
-
706
- if (t.shift !== undefined && ii < 0) {
707
- // we should never shift to negative indexes (rolling around to back of array)
708
- return res;
709
- }
710
-
711
- const token = get(tokens, ii); // supports negative ii
712
-
713
-
714
- if (token === undefined) { return res; }
715
-
716
- for (const key of Object.keys(t)) {
717
- if (key === 'shift' || key === 'position') { continue; }
718
-
719
- if (token[key] === undefined) { return res; }
720
-
721
- if (key === 'children' && isArrayOfObjects(t.children)) {
722
- if (token.children.length === 0) {
723
- return res;
724
- }
725
- let match;
726
- const childTests = t.children;
727
- const children = token.children;
728
- if (childTests.every(tt => tt.position !== undefined)) {
729
- // positions instead of shifts, do not loop all children
730
- match = childTests.every(tt => test(children, tt.position, tt).match);
731
- if (match) {
732
- // we may need position of child in transform
733
- const j = last(childTests).position;
734
- res.j = j >= 0 ? j : children.length + j;
735
- }
736
- } else {
737
- for (let j = 0; j < children.length; j++) {
738
- match = childTests.every(tt => test(children, j, tt).match);
739
- if (match) {
740
- res.j = j;
741
- // all tests true, continue with next key of pattern t
742
- break;
743
- }
744
- }
745
- }
746
-
747
- if (match === false) { return res; }
748
-
749
- continue;
750
- }
751
-
752
- switch (typeof t[key]) {
753
- case 'boolean':
754
- case 'number':
755
- case 'string':
756
- if (token[key] !== t[key]) { return res; }
757
- break;
758
- case 'function':
759
- if (!t[key](token[key])) { return res; }
760
- break;
761
- case 'object':
762
- if (isArrayOfFunctions(t[key])) {
763
- const r = t[key].every(tt => tt(token[key]));
764
- if (r === false) { return res; }
765
- break;
766
- }
767
- // fall through for objects !== arrays of functions
768
- default:
769
- throw new Error(`Unknown type of pattern test (key: ${key}). Test should be of type boolean, number, string, function or array of functions.`);
770
- }
771
- }
772
-
773
- // no tests returned false -> all tests returns true
774
- res.match = true;
775
- return res;
776
- }
777
-
778
- function isArrayOfObjects(arr) {
779
- return Array.isArray(arr) && arr.length && arr.every(i => typeof i === 'object');
780
- }
781
-
782
- function isArrayOfFunctions(arr) {
783
- return Array.isArray(arr) && arr.length && arr.every(i => typeof i === 'function');
784
- }
785
-
786
- /**
787
- * Get n item of array. Supports negative n, where -1 is last
788
- * element in array.
789
- * @param {array} arr
790
- * @param {number} n
791
- */
792
- function get(arr, n) {
793
- return n >= 0 ? arr[n] : arr[arr.length + n];
794
- }
795
-
796
- // get last element of array, safe - returns {} if not found
797
- function last(arr) {
798
- return arr.slice(-1)[0] || {};
799
- }
800
-
801
- var markdownItAttrs$1 = /*@__PURE__*/getDefaultExportFromCjs(markdownItAttrs);
802
-
803
- export { markdownItAttrs$1 as m };