@progressive-development/pd-content 0.9.1 → 1.0.0

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 (119) hide show
  1. package/LICENSE +21 -2
  2. package/README.md +42 -57
  3. package/dist/_virtual/_commonjsHelpers.js +7 -0
  4. package/dist/_virtual/prism-java.js +3 -0
  5. package/dist/_virtual/prism-java2.js +3 -0
  6. package/dist/_virtual/prism-python.js +3 -0
  7. package/dist/_virtual/prism-python2.js +3 -0
  8. package/dist/_virtual/prism-typescript.js +3 -0
  9. package/dist/_virtual/prism-typescript2.js +3 -0
  10. package/dist/_virtual/prism.js +7 -0
  11. package/dist/_virtual/prism2.js +3 -0
  12. package/dist/generated/locales/be.d.ts +10 -0
  13. package/dist/generated/locales/be.d.ts.map +1 -1
  14. package/dist/generated/locales/de.d.ts +10 -0
  15. package/dist/generated/locales/de.d.ts.map +1 -1
  16. package/dist/generated/locales/en.d.ts +10 -0
  17. package/dist/generated/locales/en.d.ts.map +1 -1
  18. package/dist/index.d.ts +8 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +9 -0
  21. package/dist/locales/be.js +11 -1
  22. package/dist/locales/de.js +11 -1
  23. package/dist/locales/en.js +11 -1
  24. package/dist/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-bash.js +235 -0
  25. package/dist/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-java.js +135 -0
  26. package/dist/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-json.js +27 -0
  27. package/dist/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-markdown.js +415 -0
  28. package/dist/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-python.js +76 -0
  29. package/dist/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-sql.js +32 -0
  30. package/dist/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-typescript.js +71 -0
  31. package/dist/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-yaml.js +83 -0
  32. package/dist/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/prism.js +1959 -0
  33. package/dist/pd-box-view/PdBoxView.d.ts +9 -0
  34. package/dist/pd-box-view/PdBoxView.d.ts.map +1 -1
  35. package/dist/pd-box-view/pd-box-view.stories.d.ts +41 -8
  36. package/dist/pd-box-view/pd-box-view.stories.d.ts.map +1 -1
  37. package/dist/pd-code-snippet/PdCodeSnippet.d.ts +105 -0
  38. package/dist/pd-code-snippet/PdCodeSnippet.d.ts.map +1 -0
  39. package/dist/pd-code-snippet/PdCodeSnippet.js +504 -0
  40. package/dist/pd-code-snippet/pd-code-snippet.d.ts +4 -0
  41. package/dist/pd-code-snippet/pd-code-snippet.d.ts.map +1 -0
  42. package/dist/pd-code-snippet/pd-code-snippet.js +5 -0
  43. package/dist/pd-code-snippet/pd-code-snippet.stories.d.ts +55 -0
  44. package/dist/pd-code-snippet/pd-code-snippet.stories.d.ts.map +1 -0
  45. package/dist/pd-collapse/PdCollapse.d.ts +31 -7
  46. package/dist/pd-collapse/PdCollapse.d.ts.map +1 -1
  47. package/dist/pd-collapse/PdCollapse.js +73 -18
  48. package/dist/pd-collapse/pd-collapse.stories.d.ts +49 -21
  49. package/dist/pd-collapse/pd-collapse.stories.d.ts.map +1 -1
  50. package/dist/pd-collapse-group/PdCollapseGroup.d.ts +8 -7
  51. package/dist/pd-collapse-group/PdCollapseGroup.d.ts.map +1 -1
  52. package/dist/pd-collapse-group/PdCollapseGroup.js +7 -6
  53. package/dist/pd-collapse-group/pd-collapse-group.stories.d.ts +39 -4
  54. package/dist/pd-collapse-group/pd-collapse-group.stories.d.ts.map +1 -1
  55. package/dist/pd-edit-content/PdEditContent.d.ts +13 -0
  56. package/dist/pd-edit-content/PdEditContent.d.ts.map +1 -1
  57. package/dist/pd-edit-content/PdEditContent.js +33 -10
  58. package/dist/pd-edit-content/pd-edit-content.stories.d.ts +54 -10
  59. package/dist/pd-edit-content/pd-edit-content.stories.d.ts.map +1 -1
  60. package/dist/pd-loading-state/PdLoadingState.d.ts +64 -0
  61. package/dist/pd-loading-state/PdLoadingState.d.ts.map +1 -0
  62. package/dist/pd-loading-state/PdLoadingState.js +219 -0
  63. package/dist/pd-loading-state/pd-loading-state.d.ts +6 -0
  64. package/dist/pd-loading-state/pd-loading-state.d.ts.map +1 -0
  65. package/dist/pd-loading-state/pd-loading-state.stories.d.ts +48 -0
  66. package/dist/pd-loading-state/pd-loading-state.stories.d.ts.map +1 -0
  67. package/dist/pd-loading-state.d.ts +2 -0
  68. package/dist/pd-loading-state.js +1 -0
  69. package/dist/pd-more-info/PdMoreInfo.d.ts +6 -2
  70. package/dist/pd-more-info/PdMoreInfo.d.ts.map +1 -1
  71. package/dist/pd-more-info/PdMoreInfo.js +30 -4
  72. package/dist/pd-more-info/pd-more-info.stories.d.ts +41 -5
  73. package/dist/pd-more-info/pd-more-info.stories.d.ts.map +1 -1
  74. package/dist/pd-notice-box/PdNoticeBox.d.ts +88 -0
  75. package/dist/pd-notice-box/PdNoticeBox.d.ts.map +1 -0
  76. package/dist/pd-notice-box/PdNoticeBox.js +224 -0
  77. package/dist/pd-notice-box/pd-notice-box.d.ts +3 -0
  78. package/dist/pd-notice-box/pd-notice-box.d.ts.map +1 -0
  79. package/dist/pd-notice-box/pd-notice-box.js +8 -0
  80. package/dist/pd-notice-box/pd-notice-box.stories.d.ts +58 -0
  81. package/dist/pd-notice-box/pd-notice-box.stories.d.ts.map +1 -0
  82. package/dist/pd-panel-viewer/PdPanel.d.ts +5 -0
  83. package/dist/pd-panel-viewer/PdPanel.d.ts.map +1 -1
  84. package/dist/pd-panel-viewer/PdPanelViewer.d.ts +53 -2
  85. package/dist/pd-panel-viewer/PdPanelViewer.d.ts.map +1 -1
  86. package/dist/pd-panel-viewer/PdPanelViewer.js +188 -33
  87. package/dist/pd-panel-viewer/pd-panel-viewer.stories.d.ts +46 -0
  88. package/dist/pd-panel-viewer/pd-panel-viewer.stories.d.ts.map +1 -0
  89. package/dist/pd-resize-content/PdResizeContent.d.ts +12 -10
  90. package/dist/pd-resize-content/PdResizeContent.d.ts.map +1 -1
  91. package/dist/pd-resize-content/PdResizeContent.js +19 -9
  92. package/dist/pd-resize-content/pd-resize-content.stories.d.ts +36 -4
  93. package/dist/pd-resize-content/pd-resize-content.stories.d.ts.map +1 -1
  94. package/dist/pd-tab/PdTab.d.ts +35 -2
  95. package/dist/pd-tab/PdTab.d.ts.map +1 -1
  96. package/dist/pd-tab/PdTab.js +181 -71
  97. package/dist/pd-tab/pd-tab.stories.d.ts +51 -21
  98. package/dist/pd-tab/pd-tab.stories.d.ts.map +1 -1
  99. package/dist/pd-timeline/PdTimeline.d.ts +50 -0
  100. package/dist/pd-timeline/PdTimeline.d.ts.map +1 -0
  101. package/dist/pd-timeline/PdTimeline.js +315 -0
  102. package/dist/pd-timeline/pd-timeline.d.ts +3 -0
  103. package/dist/pd-timeline/pd-timeline.d.ts.map +1 -0
  104. package/dist/pd-timeline/pd-timeline.stories.d.ts +56 -0
  105. package/dist/pd-timeline/pd-timeline.stories.d.ts.map +1 -0
  106. package/dist/pd-timeline-wizard/PdTimelineWizard.d.ts +39 -0
  107. package/dist/pd-timeline-wizard/PdTimelineWizard.d.ts.map +1 -0
  108. package/dist/pd-timeline-wizard/PdTimelineWizard.js +150 -0
  109. package/dist/pd-timeline-wizard/pd-timeline-wizard.d.ts +3 -0
  110. package/dist/pd-timeline-wizard/pd-timeline-wizard.d.ts.map +1 -0
  111. package/dist/pd-timeline-wizard/pd-timeline-wizard.stories.d.ts +54 -0
  112. package/dist/pd-timeline-wizard/pd-timeline-wizard.stories.d.ts.map +1 -0
  113. package/dist/pd-timeline-wizard.d.ts +2 -0
  114. package/dist/pd-timeline-wizard.js +8 -0
  115. package/dist/pd-timeline.d.ts +2 -0
  116. package/dist/pd-timeline.js +8 -0
  117. package/dist/types.d.ts +25 -0
  118. package/dist/types.d.ts.map +1 -1
  119. package/package.json +17 -8
@@ -0,0 +1,1959 @@
1
+ import { commonjsGlobal } from '../../../../../_virtual/_commonjsHelpers.js';
2
+ import { __module as prism } from '../../../../../_virtual/prism2.js';
3
+
4
+ var hasRequiredPrism;
5
+
6
+ function requirePrism () {
7
+ if (hasRequiredPrism) return prism.exports;
8
+ hasRequiredPrism = 1;
9
+ (function (module) {
10
+ /* **********************************************
11
+ Begin prism-core.js
12
+ ********************************************** */
13
+
14
+ /// <reference lib="WebWorker"/>
15
+
16
+ var _self = (typeof window !== 'undefined')
17
+ ? window // if in browser
18
+ : (
19
+ (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
20
+ ? self // if in worker
21
+ : {} // if in node js
22
+ );
23
+
24
+ /**
25
+ * Prism: Lightweight, robust, elegant syntax highlighting
26
+ *
27
+ * @license MIT <https://opensource.org/licenses/MIT>
28
+ * @author Lea Verou <https://lea.verou.me>
29
+ * @namespace
30
+ * @public
31
+ */
32
+ var Prism = (function (_self) {
33
+
34
+ // Private helper vars
35
+ var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
36
+ var uniqueId = 0;
37
+
38
+ // The grammar object for plaintext
39
+ var plainTextGrammar = {};
40
+
41
+
42
+ var _ = {
43
+ /**
44
+ * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
45
+ * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
46
+ * additional languages or plugins yourself.
47
+ *
48
+ * By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
49
+ *
50
+ * You obviously have to change this value before the automatic highlighting started. To do this, you can add an
51
+ * empty Prism object into the global scope before loading the Prism script like this:
52
+ *
53
+ * ```js
54
+ * window.Prism = window.Prism || {};
55
+ * Prism.manual = true;
56
+ * // add a new <script> to load Prism's script
57
+ * ```
58
+ *
59
+ * @default false
60
+ * @type {boolean}
61
+ * @memberof Prism
62
+ * @public
63
+ */
64
+ manual: _self.Prism && _self.Prism.manual,
65
+ /**
66
+ * By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
67
+ * `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
68
+ * own worker, you don't want it to do this.
69
+ *
70
+ * By setting this value to `true`, Prism will not add its own listeners to the worker.
71
+ *
72
+ * You obviously have to change this value before Prism executes. To do this, you can add an
73
+ * empty Prism object into the global scope before loading the Prism script like this:
74
+ *
75
+ * ```js
76
+ * window.Prism = window.Prism || {};
77
+ * Prism.disableWorkerMessageHandler = true;
78
+ * // Load Prism's script
79
+ * ```
80
+ *
81
+ * @default false
82
+ * @type {boolean}
83
+ * @memberof Prism
84
+ * @public
85
+ */
86
+ disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
87
+
88
+ /**
89
+ * A namespace for utility methods.
90
+ *
91
+ * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
92
+ * change or disappear at any time.
93
+ *
94
+ * @namespace
95
+ * @memberof Prism
96
+ */
97
+ util: {
98
+ encode: function encode(tokens) {
99
+ if (tokens instanceof Token) {
100
+ return new Token(tokens.type, encode(tokens.content), tokens.alias);
101
+ } else if (Array.isArray(tokens)) {
102
+ return tokens.map(encode);
103
+ } else {
104
+ return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
105
+ }
106
+ },
107
+
108
+ /**
109
+ * Returns the name of the type of the given value.
110
+ *
111
+ * @param {any} o
112
+ * @returns {string}
113
+ * @example
114
+ * type(null) === 'Null'
115
+ * type(undefined) === 'Undefined'
116
+ * type(123) === 'Number'
117
+ * type('foo') === 'String'
118
+ * type(true) === 'Boolean'
119
+ * type([1, 2]) === 'Array'
120
+ * type({}) === 'Object'
121
+ * type(String) === 'Function'
122
+ * type(/abc+/) === 'RegExp'
123
+ */
124
+ type: function (o) {
125
+ return Object.prototype.toString.call(o).slice(8, -1);
126
+ },
127
+
128
+ /**
129
+ * Returns a unique number for the given object. Later calls will still return the same number.
130
+ *
131
+ * @param {Object} obj
132
+ * @returns {number}
133
+ */
134
+ objId: function (obj) {
135
+ if (!obj['__id']) {
136
+ Object.defineProperty(obj, '__id', { value: ++uniqueId });
137
+ }
138
+ return obj['__id'];
139
+ },
140
+
141
+ /**
142
+ * Creates a deep clone of the given object.
143
+ *
144
+ * The main intended use of this function is to clone language definitions.
145
+ *
146
+ * @param {T} o
147
+ * @param {Record<number, any>} [visited]
148
+ * @returns {T}
149
+ * @template T
150
+ */
151
+ clone: function deepClone(o, visited) {
152
+ visited = visited || {};
153
+
154
+ var clone; var id;
155
+ switch (_.util.type(o)) {
156
+ case 'Object':
157
+ id = _.util.objId(o);
158
+ if (visited[id]) {
159
+ return visited[id];
160
+ }
161
+ clone = /** @type {Record<string, any>} */ ({});
162
+ visited[id] = clone;
163
+
164
+ for (var key in o) {
165
+ if (o.hasOwnProperty(key)) {
166
+ clone[key] = deepClone(o[key], visited);
167
+ }
168
+ }
169
+
170
+ return /** @type {any} */ (clone);
171
+
172
+ case 'Array':
173
+ id = _.util.objId(o);
174
+ if (visited[id]) {
175
+ return visited[id];
176
+ }
177
+ clone = [];
178
+ visited[id] = clone;
179
+
180
+ (/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) {
181
+ clone[i] = deepClone(v, visited);
182
+ });
183
+
184
+ return /** @type {any} */ (clone);
185
+
186
+ default:
187
+ return o;
188
+ }
189
+ },
190
+
191
+ /**
192
+ * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
193
+ *
194
+ * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
195
+ *
196
+ * @param {Element} element
197
+ * @returns {string}
198
+ */
199
+ getLanguage: function (element) {
200
+ while (element) {
201
+ var m = lang.exec(element.className);
202
+ if (m) {
203
+ return m[1].toLowerCase();
204
+ }
205
+ element = element.parentElement;
206
+ }
207
+ return 'none';
208
+ },
209
+
210
+ /**
211
+ * Sets the Prism `language-xxxx` class of the given element.
212
+ *
213
+ * @param {Element} element
214
+ * @param {string} language
215
+ * @returns {void}
216
+ */
217
+ setLanguage: function (element, language) {
218
+ // remove all `language-xxxx` classes
219
+ // (this might leave behind a leading space)
220
+ element.className = element.className.replace(RegExp(lang, 'gi'), '');
221
+
222
+ // add the new `language-xxxx` class
223
+ // (using `classList` will automatically clean up spaces for us)
224
+ element.classList.add('language-' + language);
225
+ },
226
+
227
+ /**
228
+ * Returns the script element that is currently executing.
229
+ *
230
+ * This does __not__ work for line script element.
231
+ *
232
+ * @returns {HTMLScriptElement | null}
233
+ */
234
+ currentScript: function () {
235
+ if (typeof document === 'undefined') {
236
+ return null;
237
+ }
238
+ if (document.currentScript && document.currentScript.tagName === 'SCRIPT' && 1 < 2 /* hack to trip TS' flow analysis */) {
239
+ return /** @type {any} */ (document.currentScript);
240
+ }
241
+
242
+ // IE11 workaround
243
+ // we'll get the src of the current script by parsing IE11's error stack trace
244
+ // this will not work for inline scripts
245
+
246
+ try {
247
+ throw new Error();
248
+ } catch (err) {
249
+ // Get file src url from stack. Specifically works with the format of stack traces in IE.
250
+ // A stack will look like this:
251
+ //
252
+ // Error
253
+ // at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
254
+ // at Global code (http://localhost/components/prism-core.js:606:1)
255
+
256
+ var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
257
+ if (src) {
258
+ var scripts = document.getElementsByTagName('script');
259
+ for (var i in scripts) {
260
+ if (scripts[i].src == src) {
261
+ return scripts[i];
262
+ }
263
+ }
264
+ }
265
+ return null;
266
+ }
267
+ },
268
+
269
+ /**
270
+ * Returns whether a given class is active for `element`.
271
+ *
272
+ * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
273
+ * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
274
+ * given class is just the given class with a `no-` prefix.
275
+ *
276
+ * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
277
+ * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
278
+ * ancestors have the given class or the negated version of it, then the default activation will be returned.
279
+ *
280
+ * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
281
+ * version of it, the class is considered active.
282
+ *
283
+ * @param {Element} element
284
+ * @param {string} className
285
+ * @param {boolean} [defaultActivation=false]
286
+ * @returns {boolean}
287
+ */
288
+ isActive: function (element, className, defaultActivation) {
289
+ var no = 'no-' + className;
290
+
291
+ while (element) {
292
+ var classList = element.classList;
293
+ if (classList.contains(className)) {
294
+ return true;
295
+ }
296
+ if (classList.contains(no)) {
297
+ return false;
298
+ }
299
+ element = element.parentElement;
300
+ }
301
+ return !!defaultActivation;
302
+ }
303
+ },
304
+
305
+ /**
306
+ * This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
307
+ *
308
+ * @namespace
309
+ * @memberof Prism
310
+ * @public
311
+ */
312
+ languages: {
313
+ /**
314
+ * The grammar for plain, unformatted text.
315
+ */
316
+ plain: plainTextGrammar,
317
+ plaintext: plainTextGrammar,
318
+ text: plainTextGrammar,
319
+ txt: plainTextGrammar,
320
+
321
+ /**
322
+ * Creates a deep copy of the language with the given id and appends the given tokens.
323
+ *
324
+ * If a token in `redef` also appears in the copied language, then the existing token in the copied language
325
+ * will be overwritten at its original position.
326
+ *
327
+ * ## Best practices
328
+ *
329
+ * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
330
+ * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
331
+ * understand the language definition because, normally, the order of tokens matters in Prism grammars.
332
+ *
333
+ * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
334
+ * Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
335
+ *
336
+ * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
337
+ * @param {Grammar} redef The new tokens to append.
338
+ * @returns {Grammar} The new language created.
339
+ * @public
340
+ * @example
341
+ * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
342
+ * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
343
+ * // at its original position
344
+ * 'comment': { ... },
345
+ * // CSS doesn't have a 'color' token, so this token will be appended
346
+ * 'color': /\b(?:red|green|blue)\b/
347
+ * });
348
+ */
349
+ extend: function (id, redef) {
350
+ var lang = _.util.clone(_.languages[id]);
351
+
352
+ for (var key in redef) {
353
+ lang[key] = redef[key];
354
+ }
355
+
356
+ return lang;
357
+ },
358
+
359
+ /**
360
+ * Inserts tokens _before_ another token in a language definition or any other grammar.
361
+ *
362
+ * ## Usage
363
+ *
364
+ * This helper method makes it easy to modify existing languages. For example, the CSS language definition
365
+ * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
366
+ * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
367
+ * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
368
+ * this:
369
+ *
370
+ * ```js
371
+ * Prism.languages.markup.style = {
372
+ * // token
373
+ * };
374
+ * ```
375
+ *
376
+ * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
377
+ * before existing tokens. For the CSS example above, you would use it like this:
378
+ *
379
+ * ```js
380
+ * Prism.languages.insertBefore('markup', 'cdata', {
381
+ * 'style': {
382
+ * // token
383
+ * }
384
+ * });
385
+ * ```
386
+ *
387
+ * ## Special cases
388
+ *
389
+ * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
390
+ * will be ignored.
391
+ *
392
+ * This behavior can be used to insert tokens after `before`:
393
+ *
394
+ * ```js
395
+ * Prism.languages.insertBefore('markup', 'comment', {
396
+ * 'comment': Prism.languages.markup.comment,
397
+ * // tokens after 'comment'
398
+ * });
399
+ * ```
400
+ *
401
+ * ## Limitations
402
+ *
403
+ * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
404
+ * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
405
+ * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
406
+ * deleting properties which is necessary to insert at arbitrary positions.
407
+ *
408
+ * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
409
+ * Instead, it will create a new object and replace all references to the target object with the new one. This
410
+ * can be done without temporarily deleting properties, so the iteration order is well-defined.
411
+ *
412
+ * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
413
+ * you hold the target object in a variable, then the value of the variable will not change.
414
+ *
415
+ * ```js
416
+ * var oldMarkup = Prism.languages.markup;
417
+ * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
418
+ *
419
+ * assert(oldMarkup !== Prism.languages.markup);
420
+ * assert(newMarkup === Prism.languages.markup);
421
+ * ```
422
+ *
423
+ * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
424
+ * object to be modified.
425
+ * @param {string} before The key to insert before.
426
+ * @param {Grammar} insert An object containing the key-value pairs to be inserted.
427
+ * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
428
+ * object to be modified.
429
+ *
430
+ * Defaults to `Prism.languages`.
431
+ * @returns {Grammar} The new grammar object.
432
+ * @public
433
+ */
434
+ insertBefore: function (inside, before, insert, root) {
435
+ root = root || /** @type {any} */ (_.languages);
436
+ var grammar = root[inside];
437
+ /** @type {Grammar} */
438
+ var ret = {};
439
+
440
+ for (var token in grammar) {
441
+ if (grammar.hasOwnProperty(token)) {
442
+
443
+ if (token == before) {
444
+ for (var newToken in insert) {
445
+ if (insert.hasOwnProperty(newToken)) {
446
+ ret[newToken] = insert[newToken];
447
+ }
448
+ }
449
+ }
450
+
451
+ // Do not insert token which also occur in insert. See #1525
452
+ if (!insert.hasOwnProperty(token)) {
453
+ ret[token] = grammar[token];
454
+ }
455
+ }
456
+ }
457
+
458
+ var old = root[inside];
459
+ root[inside] = ret;
460
+
461
+ // Update references in other language definitions
462
+ _.languages.DFS(_.languages, function (key, value) {
463
+ if (value === old && key != inside) {
464
+ this[key] = ret;
465
+ }
466
+ });
467
+
468
+ return ret;
469
+ },
470
+
471
+ // Traverse a language definition with Depth First Search
472
+ DFS: function DFS(o, callback, type, visited) {
473
+ visited = visited || {};
474
+
475
+ var objId = _.util.objId;
476
+
477
+ for (var i in o) {
478
+ if (o.hasOwnProperty(i)) {
479
+ callback.call(o, i, o[i], type || i);
480
+
481
+ var property = o[i];
482
+ var propertyType = _.util.type(property);
483
+
484
+ if (propertyType === 'Object' && !visited[objId(property)]) {
485
+ visited[objId(property)] = true;
486
+ DFS(property, callback, null, visited);
487
+ } else if (propertyType === 'Array' && !visited[objId(property)]) {
488
+ visited[objId(property)] = true;
489
+ DFS(property, callback, i, visited);
490
+ }
491
+ }
492
+ }
493
+ }
494
+ },
495
+
496
+ plugins: {},
497
+
498
+ /**
499
+ * This is the most high-level function in Prism’s API.
500
+ * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
501
+ * each one of them.
502
+ *
503
+ * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
504
+ *
505
+ * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
506
+ * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
507
+ * @memberof Prism
508
+ * @public
509
+ */
510
+ highlightAll: function (async, callback) {
511
+ _.highlightAllUnder(document, async, callback);
512
+ },
513
+
514
+ /**
515
+ * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
516
+ * {@link Prism.highlightElement} on each one of them.
517
+ *
518
+ * The following hooks will be run:
519
+ * 1. `before-highlightall`
520
+ * 2. `before-all-elements-highlight`
521
+ * 3. All hooks of {@link Prism.highlightElement} for each element.
522
+ *
523
+ * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
524
+ * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
525
+ * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
526
+ * @memberof Prism
527
+ * @public
528
+ */
529
+ highlightAllUnder: function (container, async, callback) {
530
+ var env = {
531
+ callback: callback,
532
+ container: container,
533
+ selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
534
+ };
535
+
536
+ _.hooks.run('before-highlightall', env);
537
+
538
+ env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
539
+
540
+ _.hooks.run('before-all-elements-highlight', env);
541
+
542
+ for (var i = 0, element; (element = env.elements[i++]);) {
543
+ _.highlightElement(element, async === true, env.callback);
544
+ }
545
+ },
546
+
547
+ /**
548
+ * Highlights the code inside a single element.
549
+ *
550
+ * The following hooks will be run:
551
+ * 1. `before-sanity-check`
552
+ * 2. `before-highlight`
553
+ * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
554
+ * 4. `before-insert`
555
+ * 5. `after-highlight`
556
+ * 6. `complete`
557
+ *
558
+ * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
559
+ * the element's language.
560
+ *
561
+ * @param {Element} element The element containing the code.
562
+ * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
563
+ * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
564
+ * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
565
+ * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
566
+ *
567
+ * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
568
+ * asynchronous highlighting to work. You can build your own bundle on the
569
+ * [Download page](https://prismjs.com/download.html).
570
+ * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
571
+ * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
572
+ * @memberof Prism
573
+ * @public
574
+ */
575
+ highlightElement: function (element, async, callback) {
576
+ // Find language
577
+ var language = _.util.getLanguage(element);
578
+ var grammar = _.languages[language];
579
+
580
+ // Set language on the element, if not present
581
+ _.util.setLanguage(element, language);
582
+
583
+ // Set language on the parent, for styling
584
+ var parent = element.parentElement;
585
+ if (parent && parent.nodeName.toLowerCase() === 'pre') {
586
+ _.util.setLanguage(parent, language);
587
+ }
588
+
589
+ var code = element.textContent;
590
+
591
+ var env = {
592
+ element: element,
593
+ language: language,
594
+ grammar: grammar,
595
+ code: code
596
+ };
597
+
598
+ function insertHighlightedCode(highlightedCode) {
599
+ env.highlightedCode = highlightedCode;
600
+
601
+ _.hooks.run('before-insert', env);
602
+
603
+ env.element.innerHTML = env.highlightedCode;
604
+
605
+ _.hooks.run('after-highlight', env);
606
+ _.hooks.run('complete', env);
607
+ callback && callback.call(env.element);
608
+ }
609
+
610
+ _.hooks.run('before-sanity-check', env);
611
+
612
+ // plugins may change/add the parent/element
613
+ parent = env.element.parentElement;
614
+ if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
615
+ parent.setAttribute('tabindex', '0');
616
+ }
617
+
618
+ if (!env.code) {
619
+ _.hooks.run('complete', env);
620
+ callback && callback.call(env.element);
621
+ return;
622
+ }
623
+
624
+ _.hooks.run('before-highlight', env);
625
+
626
+ if (!env.grammar) {
627
+ insertHighlightedCode(_.util.encode(env.code));
628
+ return;
629
+ }
630
+
631
+ if (async && _self.Worker) {
632
+ var worker = new Worker(_.filename);
633
+
634
+ worker.onmessage = function (evt) {
635
+ insertHighlightedCode(evt.data);
636
+ };
637
+
638
+ worker.postMessage(JSON.stringify({
639
+ language: env.language,
640
+ code: env.code,
641
+ immediateClose: true
642
+ }));
643
+ } else {
644
+ insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
645
+ }
646
+ },
647
+
648
+ /**
649
+ * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
650
+ * and the language definitions to use, and returns a string with the HTML produced.
651
+ *
652
+ * The following hooks will be run:
653
+ * 1. `before-tokenize`
654
+ * 2. `after-tokenize`
655
+ * 3. `wrap`: On each {@link Token}.
656
+ *
657
+ * @param {string} text A string with the code to be highlighted.
658
+ * @param {Grammar} grammar An object containing the tokens to use.
659
+ *
660
+ * Usually a language definition like `Prism.languages.markup`.
661
+ * @param {string} language The name of the language definition passed to `grammar`.
662
+ * @returns {string} The highlighted HTML.
663
+ * @memberof Prism
664
+ * @public
665
+ * @example
666
+ * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
667
+ */
668
+ highlight: function (text, grammar, language) {
669
+ var env = {
670
+ code: text,
671
+ grammar: grammar,
672
+ language: language
673
+ };
674
+ _.hooks.run('before-tokenize', env);
675
+ if (!env.grammar) {
676
+ throw new Error('The language "' + env.language + '" has no grammar.');
677
+ }
678
+ env.tokens = _.tokenize(env.code, env.grammar);
679
+ _.hooks.run('after-tokenize', env);
680
+ return Token.stringify(_.util.encode(env.tokens), env.language);
681
+ },
682
+
683
+ /**
684
+ * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
685
+ * and the language definitions to use, and returns an array with the tokenized code.
686
+ *
687
+ * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
688
+ *
689
+ * This method could be useful in other contexts as well, as a very crude parser.
690
+ *
691
+ * @param {string} text A string with the code to be highlighted.
692
+ * @param {Grammar} grammar An object containing the tokens to use.
693
+ *
694
+ * Usually a language definition like `Prism.languages.markup`.
695
+ * @returns {TokenStream} An array of strings and tokens, a token stream.
696
+ * @memberof Prism
697
+ * @public
698
+ * @example
699
+ * let code = `var foo = 0;`;
700
+ * let tokens = Prism.tokenize(code, Prism.languages.javascript);
701
+ * tokens.forEach(token => {
702
+ * if (token instanceof Prism.Token && token.type === 'number') {
703
+ * console.log(`Found numeric literal: ${token.content}`);
704
+ * }
705
+ * });
706
+ */
707
+ tokenize: function (text, grammar) {
708
+ var rest = grammar.rest;
709
+ if (rest) {
710
+ for (var token in rest) {
711
+ grammar[token] = rest[token];
712
+ }
713
+
714
+ delete grammar.rest;
715
+ }
716
+
717
+ var tokenList = new LinkedList();
718
+ addAfter(tokenList, tokenList.head, text);
719
+
720
+ matchGrammar(text, tokenList, grammar, tokenList.head, 0);
721
+
722
+ return toArray(tokenList);
723
+ },
724
+
725
+ /**
726
+ * @namespace
727
+ * @memberof Prism
728
+ * @public
729
+ */
730
+ hooks: {
731
+ all: {},
732
+
733
+ /**
734
+ * Adds the given callback to the list of callbacks for the given hook.
735
+ *
736
+ * The callback will be invoked when the hook it is registered for is run.
737
+ * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
738
+ *
739
+ * One callback function can be registered to multiple hooks and the same hook multiple times.
740
+ *
741
+ * @param {string} name The name of the hook.
742
+ * @param {HookCallback} callback The callback function which is given environment variables.
743
+ * @public
744
+ */
745
+ add: function (name, callback) {
746
+ var hooks = _.hooks.all;
747
+
748
+ hooks[name] = hooks[name] || [];
749
+
750
+ hooks[name].push(callback);
751
+ },
752
+
753
+ /**
754
+ * Runs a hook invoking all registered callbacks with the given environment variables.
755
+ *
756
+ * Callbacks will be invoked synchronously and in the order in which they were registered.
757
+ *
758
+ * @param {string} name The name of the hook.
759
+ * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
760
+ * @public
761
+ */
762
+ run: function (name, env) {
763
+ var callbacks = _.hooks.all[name];
764
+
765
+ if (!callbacks || !callbacks.length) {
766
+ return;
767
+ }
768
+
769
+ for (var i = 0, callback; (callback = callbacks[i++]);) {
770
+ callback(env);
771
+ }
772
+ }
773
+ },
774
+
775
+ Token: Token
776
+ };
777
+ _self.Prism = _;
778
+
779
+
780
+ // Typescript note:
781
+ // The following can be used to import the Token type in JSDoc:
782
+ //
783
+ // @typedef {InstanceType<import("./prism-core")["Token"]>} Token
784
+
785
+ /**
786
+ * Creates a new token.
787
+ *
788
+ * @param {string} type See {@link Token#type type}
789
+ * @param {string | TokenStream} content See {@link Token#content content}
790
+ * @param {string|string[]} [alias] The alias(es) of the token.
791
+ * @param {string} [matchedStr=""] A copy of the full string this token was created from.
792
+ * @class
793
+ * @global
794
+ * @public
795
+ */
796
+ function Token(type, content, alias, matchedStr) {
797
+ /**
798
+ * The type of the token.
799
+ *
800
+ * This is usually the key of a pattern in a {@link Grammar}.
801
+ *
802
+ * @type {string}
803
+ * @see GrammarToken
804
+ * @public
805
+ */
806
+ this.type = type;
807
+ /**
808
+ * The strings or tokens contained by this token.
809
+ *
810
+ * This will be a token stream if the pattern matched also defined an `inside` grammar.
811
+ *
812
+ * @type {string | TokenStream}
813
+ * @public
814
+ */
815
+ this.content = content;
816
+ /**
817
+ * The alias(es) of the token.
818
+ *
819
+ * @type {string|string[]}
820
+ * @see GrammarToken
821
+ * @public
822
+ */
823
+ this.alias = alias;
824
+ // Copy of the full string this token was created from
825
+ this.length = (matchedStr || '').length | 0;
826
+ }
827
+
828
+ /**
829
+ * A token stream is an array of strings and {@link Token Token} objects.
830
+ *
831
+ * Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
832
+ * them.
833
+ *
834
+ * 1. No adjacent strings.
835
+ * 2. No empty strings.
836
+ *
837
+ * The only exception here is the token stream that only contains the empty string and nothing else.
838
+ *
839
+ * @typedef {Array<string | Token>} TokenStream
840
+ * @global
841
+ * @public
842
+ */
843
+
844
+ /**
845
+ * Converts the given token or token stream to an HTML representation.
846
+ *
847
+ * The following hooks will be run:
848
+ * 1. `wrap`: On each {@link Token}.
849
+ *
850
+ * @param {string | Token | TokenStream} o The token or token stream to be converted.
851
+ * @param {string} language The name of current language.
852
+ * @returns {string} The HTML representation of the token or token stream.
853
+ * @memberof Token
854
+ * @static
855
+ */
856
+ Token.stringify = function stringify(o, language) {
857
+ if (typeof o == 'string') {
858
+ return o;
859
+ }
860
+ if (Array.isArray(o)) {
861
+ var s = '';
862
+ o.forEach(function (e) {
863
+ s += stringify(e, language);
864
+ });
865
+ return s;
866
+ }
867
+
868
+ var env = {
869
+ type: o.type,
870
+ content: stringify(o.content, language),
871
+ tag: 'span',
872
+ classes: ['token', o.type],
873
+ attributes: {},
874
+ language: language
875
+ };
876
+
877
+ var aliases = o.alias;
878
+ if (aliases) {
879
+ if (Array.isArray(aliases)) {
880
+ Array.prototype.push.apply(env.classes, aliases);
881
+ } else {
882
+ env.classes.push(aliases);
883
+ }
884
+ }
885
+
886
+ _.hooks.run('wrap', env);
887
+
888
+ var attributes = '';
889
+ for (var name in env.attributes) {
890
+ attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
891
+ }
892
+
893
+ return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
894
+ };
895
+
896
+ /**
897
+ * @param {RegExp} pattern
898
+ * @param {number} pos
899
+ * @param {string} text
900
+ * @param {boolean} lookbehind
901
+ * @returns {RegExpExecArray | null}
902
+ */
903
+ function matchPattern(pattern, pos, text, lookbehind) {
904
+ pattern.lastIndex = pos;
905
+ var match = pattern.exec(text);
906
+ if (match && lookbehind && match[1]) {
907
+ // change the match to remove the text matched by the Prism lookbehind group
908
+ var lookbehindLength = match[1].length;
909
+ match.index += lookbehindLength;
910
+ match[0] = match[0].slice(lookbehindLength);
911
+ }
912
+ return match;
913
+ }
914
+
915
+ /**
916
+ * @param {string} text
917
+ * @param {LinkedList<string | Token>} tokenList
918
+ * @param {any} grammar
919
+ * @param {LinkedListNode<string | Token>} startNode
920
+ * @param {number} startPos
921
+ * @param {RematchOptions} [rematch]
922
+ * @returns {void}
923
+ * @private
924
+ *
925
+ * @typedef RematchOptions
926
+ * @property {string} cause
927
+ * @property {number} reach
928
+ */
929
+ function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
930
+ for (var token in grammar) {
931
+ if (!grammar.hasOwnProperty(token) || !grammar[token]) {
932
+ continue;
933
+ }
934
+
935
+ var patterns = grammar[token];
936
+ patterns = Array.isArray(patterns) ? patterns : [patterns];
937
+
938
+ for (var j = 0; j < patterns.length; ++j) {
939
+ if (rematch && rematch.cause == token + ',' + j) {
940
+ return;
941
+ }
942
+
943
+ var patternObj = patterns[j];
944
+ var inside = patternObj.inside;
945
+ var lookbehind = !!patternObj.lookbehind;
946
+ var greedy = !!patternObj.greedy;
947
+ var alias = patternObj.alias;
948
+
949
+ if (greedy && !patternObj.pattern.global) {
950
+ // Without the global flag, lastIndex won't work
951
+ var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
952
+ patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
953
+ }
954
+
955
+ /** @type {RegExp} */
956
+ var pattern = patternObj.pattern || patternObj;
957
+
958
+ for ( // iterate the token list and keep track of the current token/string position
959
+ var currentNode = startNode.next, pos = startPos;
960
+ currentNode !== tokenList.tail;
961
+ pos += currentNode.value.length, currentNode = currentNode.next
962
+ ) {
963
+
964
+ if (rematch && pos >= rematch.reach) {
965
+ break;
966
+ }
967
+
968
+ var str = currentNode.value;
969
+
970
+ if (tokenList.length > text.length) {
971
+ // Something went terribly wrong, ABORT, ABORT!
972
+ return;
973
+ }
974
+
975
+ if (str instanceof Token) {
976
+ continue;
977
+ }
978
+
979
+ var removeCount = 1; // this is the to parameter of removeBetween
980
+ var match;
981
+
982
+ if (greedy) {
983
+ match = matchPattern(pattern, pos, text, lookbehind);
984
+ if (!match || match.index >= text.length) {
985
+ break;
986
+ }
987
+
988
+ var from = match.index;
989
+ var to = match.index + match[0].length;
990
+ var p = pos;
991
+
992
+ // find the node that contains the match
993
+ p += currentNode.value.length;
994
+ while (from >= p) {
995
+ currentNode = currentNode.next;
996
+ p += currentNode.value.length;
997
+ }
998
+ // adjust pos (and p)
999
+ p -= currentNode.value.length;
1000
+ pos = p;
1001
+
1002
+ // the current node is a Token, then the match starts inside another Token, which is invalid
1003
+ if (currentNode.value instanceof Token) {
1004
+ continue;
1005
+ }
1006
+
1007
+ // find the last node which is affected by this match
1008
+ for (
1009
+ var k = currentNode;
1010
+ k !== tokenList.tail && (p < to || typeof k.value === 'string');
1011
+ k = k.next
1012
+ ) {
1013
+ removeCount++;
1014
+ p += k.value.length;
1015
+ }
1016
+ removeCount--;
1017
+
1018
+ // replace with the new match
1019
+ str = text.slice(pos, p);
1020
+ match.index -= pos;
1021
+ } else {
1022
+ match = matchPattern(pattern, 0, str, lookbehind);
1023
+ if (!match) {
1024
+ continue;
1025
+ }
1026
+ }
1027
+
1028
+ // eslint-disable-next-line no-redeclare
1029
+ var from = match.index;
1030
+ var matchStr = match[0];
1031
+ var before = str.slice(0, from);
1032
+ var after = str.slice(from + matchStr.length);
1033
+
1034
+ var reach = pos + str.length;
1035
+ if (rematch && reach > rematch.reach) {
1036
+ rematch.reach = reach;
1037
+ }
1038
+
1039
+ var removeFrom = currentNode.prev;
1040
+
1041
+ if (before) {
1042
+ removeFrom = addAfter(tokenList, removeFrom, before);
1043
+ pos += before.length;
1044
+ }
1045
+
1046
+ removeRange(tokenList, removeFrom, removeCount);
1047
+
1048
+ var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
1049
+ currentNode = addAfter(tokenList, removeFrom, wrapped);
1050
+
1051
+ if (after) {
1052
+ addAfter(tokenList, currentNode, after);
1053
+ }
1054
+
1055
+ if (removeCount > 1) {
1056
+ // at least one Token object was removed, so we have to do some rematching
1057
+ // this can only happen if the current pattern is greedy
1058
+
1059
+ /** @type {RematchOptions} */
1060
+ var nestedRematch = {
1061
+ cause: token + ',' + j,
1062
+ reach: reach
1063
+ };
1064
+ matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
1065
+
1066
+ // the reach might have been extended because of the rematching
1067
+ if (rematch && nestedRematch.reach > rematch.reach) {
1068
+ rematch.reach = nestedRematch.reach;
1069
+ }
1070
+ }
1071
+ }
1072
+ }
1073
+ }
1074
+ }
1075
+
1076
+ /**
1077
+ * @typedef LinkedListNode
1078
+ * @property {T} value
1079
+ * @property {LinkedListNode<T> | null} prev The previous node.
1080
+ * @property {LinkedListNode<T> | null} next The next node.
1081
+ * @template T
1082
+ * @private
1083
+ */
1084
+
1085
+ /**
1086
+ * @template T
1087
+ * @private
1088
+ */
1089
+ function LinkedList() {
1090
+ /** @type {LinkedListNode<T>} */
1091
+ var head = { value: null, prev: null, next: null };
1092
+ /** @type {LinkedListNode<T>} */
1093
+ var tail = { value: null, prev: head, next: null };
1094
+ head.next = tail;
1095
+
1096
+ /** @type {LinkedListNode<T>} */
1097
+ this.head = head;
1098
+ /** @type {LinkedListNode<T>} */
1099
+ this.tail = tail;
1100
+ this.length = 0;
1101
+ }
1102
+
1103
+ /**
1104
+ * Adds a new node with the given value to the list.
1105
+ *
1106
+ * @param {LinkedList<T>} list
1107
+ * @param {LinkedListNode<T>} node
1108
+ * @param {T} value
1109
+ * @returns {LinkedListNode<T>} The added node.
1110
+ * @template T
1111
+ */
1112
+ function addAfter(list, node, value) {
1113
+ // assumes that node != list.tail && values.length >= 0
1114
+ var next = node.next;
1115
+
1116
+ var newNode = { value: value, prev: node, next: next };
1117
+ node.next = newNode;
1118
+ next.prev = newNode;
1119
+ list.length++;
1120
+
1121
+ return newNode;
1122
+ }
1123
+ /**
1124
+ * Removes `count` nodes after the given node. The given node will not be removed.
1125
+ *
1126
+ * @param {LinkedList<T>} list
1127
+ * @param {LinkedListNode<T>} node
1128
+ * @param {number} count
1129
+ * @template T
1130
+ */
1131
+ function removeRange(list, node, count) {
1132
+ var next = node.next;
1133
+ for (var i = 0; i < count && next !== list.tail; i++) {
1134
+ next = next.next;
1135
+ }
1136
+ node.next = next;
1137
+ next.prev = node;
1138
+ list.length -= i;
1139
+ }
1140
+ /**
1141
+ * @param {LinkedList<T>} list
1142
+ * @returns {T[]}
1143
+ * @template T
1144
+ */
1145
+ function toArray(list) {
1146
+ var array = [];
1147
+ var node = list.head.next;
1148
+ while (node !== list.tail) {
1149
+ array.push(node.value);
1150
+ node = node.next;
1151
+ }
1152
+ return array;
1153
+ }
1154
+
1155
+
1156
+ if (!_self.document) {
1157
+ if (!_self.addEventListener) {
1158
+ // in Node.js
1159
+ return _;
1160
+ }
1161
+
1162
+ if (!_.disableWorkerMessageHandler) {
1163
+ // In worker
1164
+ _self.addEventListener('message', function (evt) {
1165
+ var message = JSON.parse(evt.data);
1166
+ var lang = message.language;
1167
+ var code = message.code;
1168
+ var immediateClose = message.immediateClose;
1169
+
1170
+ _self.postMessage(_.highlight(code, _.languages[lang], lang));
1171
+ if (immediateClose) {
1172
+ _self.close();
1173
+ }
1174
+ }, false);
1175
+ }
1176
+
1177
+ return _;
1178
+ }
1179
+
1180
+ // Get current script and highlight
1181
+ var script = _.util.currentScript();
1182
+
1183
+ if (script) {
1184
+ _.filename = script.src;
1185
+
1186
+ if (script.hasAttribute('data-manual')) {
1187
+ _.manual = true;
1188
+ }
1189
+ }
1190
+
1191
+ function highlightAutomaticallyCallback() {
1192
+ if (!_.manual) {
1193
+ _.highlightAll();
1194
+ }
1195
+ }
1196
+
1197
+ if (!_.manual) {
1198
+ // If the document state is "loading", then we'll use DOMContentLoaded.
1199
+ // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
1200
+ // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
1201
+ // might take longer one animation frame to execute which can create a race condition where only some plugins have
1202
+ // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
1203
+ // See https://github.com/PrismJS/prism/issues/2102
1204
+ var readyState = document.readyState;
1205
+ if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
1206
+ document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
1207
+ } else {
1208
+ if (window.requestAnimationFrame) {
1209
+ window.requestAnimationFrame(highlightAutomaticallyCallback);
1210
+ } else {
1211
+ window.setTimeout(highlightAutomaticallyCallback, 16);
1212
+ }
1213
+ }
1214
+ }
1215
+
1216
+ return _;
1217
+
1218
+ }(_self));
1219
+
1220
+ if (module.exports) {
1221
+ module.exports = Prism;
1222
+ }
1223
+
1224
+ // hack for components to work correctly in node.js
1225
+ if (typeof commonjsGlobal !== 'undefined') {
1226
+ commonjsGlobal.Prism = Prism;
1227
+ }
1228
+
1229
+ // some additional documentation/types
1230
+
1231
+ /**
1232
+ * The expansion of a simple `RegExp` literal to support additional properties.
1233
+ *
1234
+ * @typedef GrammarToken
1235
+ * @property {RegExp} pattern The regular expression of the token.
1236
+ * @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
1237
+ * behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
1238
+ * @property {boolean} [greedy=false] Whether the token is greedy.
1239
+ * @property {string|string[]} [alias] An optional alias or list of aliases.
1240
+ * @property {Grammar} [inside] The nested grammar of this token.
1241
+ *
1242
+ * The `inside` grammar will be used to tokenize the text value of each token of this kind.
1243
+ *
1244
+ * This can be used to make nested and even recursive language definitions.
1245
+ *
1246
+ * Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
1247
+ * each another.
1248
+ * @global
1249
+ * @public
1250
+ */
1251
+
1252
+ /**
1253
+ * @typedef Grammar
1254
+ * @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
1255
+ * @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
1256
+ * @global
1257
+ * @public
1258
+ */
1259
+
1260
+ /**
1261
+ * A function which will invoked after an element was successfully highlighted.
1262
+ *
1263
+ * @callback HighlightCallback
1264
+ * @param {Element} element The element successfully highlighted.
1265
+ * @returns {void}
1266
+ * @global
1267
+ * @public
1268
+ */
1269
+
1270
+ /**
1271
+ * @callback HookCallback
1272
+ * @param {Object<string, any>} env The environment variables of the hook.
1273
+ * @returns {void}
1274
+ * @global
1275
+ * @public
1276
+ */
1277
+
1278
+
1279
+ /* **********************************************
1280
+ Begin prism-markup.js
1281
+ ********************************************** */
1282
+
1283
+ Prism.languages.markup = {
1284
+ 'comment': {
1285
+ pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
1286
+ greedy: true
1287
+ },
1288
+ 'prolog': {
1289
+ pattern: /<\?[\s\S]+?\?>/,
1290
+ greedy: true
1291
+ },
1292
+ 'doctype': {
1293
+ // https://www.w3.org/TR/xml/#NT-doctypedecl
1294
+ pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
1295
+ greedy: true,
1296
+ inside: {
1297
+ 'internal-subset': {
1298
+ pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
1299
+ lookbehind: true,
1300
+ greedy: true,
1301
+ inside: null // see below
1302
+ },
1303
+ 'string': {
1304
+ pattern: /"[^"]*"|'[^']*'/,
1305
+ greedy: true
1306
+ },
1307
+ 'punctuation': /^<!|>$|[[\]]/,
1308
+ 'doctype-tag': /^DOCTYPE/i,
1309
+ 'name': /[^\s<>'"]+/
1310
+ }
1311
+ },
1312
+ 'cdata': {
1313
+ pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
1314
+ greedy: true
1315
+ },
1316
+ 'tag': {
1317
+ pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
1318
+ greedy: true,
1319
+ inside: {
1320
+ 'tag': {
1321
+ pattern: /^<\/?[^\s>\/]+/,
1322
+ inside: {
1323
+ 'punctuation': /^<\/?/,
1324
+ 'namespace': /^[^\s>\/:]+:/
1325
+ }
1326
+ },
1327
+ 'special-attr': [],
1328
+ 'attr-value': {
1329
+ pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
1330
+ inside: {
1331
+ 'punctuation': [
1332
+ {
1333
+ pattern: /^=/,
1334
+ alias: 'attr-equals'
1335
+ },
1336
+ {
1337
+ pattern: /^(\s*)["']|["']$/,
1338
+ lookbehind: true
1339
+ }
1340
+ ]
1341
+ }
1342
+ },
1343
+ 'punctuation': /\/?>/,
1344
+ 'attr-name': {
1345
+ pattern: /[^\s>\/]+/,
1346
+ inside: {
1347
+ 'namespace': /^[^\s>\/:]+:/
1348
+ }
1349
+ }
1350
+
1351
+ }
1352
+ },
1353
+ 'entity': [
1354
+ {
1355
+ pattern: /&[\da-z]{1,8};/i,
1356
+ alias: 'named-entity'
1357
+ },
1358
+ /&#x?[\da-f]{1,8};/i
1359
+ ]
1360
+ };
1361
+
1362
+ Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
1363
+ Prism.languages.markup['entity'];
1364
+ Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
1365
+
1366
+ // Plugin to make entity title show the real entity, idea by Roman Komarov
1367
+ Prism.hooks.add('wrap', function (env) {
1368
+
1369
+ if (env.type === 'entity') {
1370
+ env.attributes['title'] = env.content.replace(/&amp;/, '&');
1371
+ }
1372
+ });
1373
+
1374
+ Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
1375
+ /**
1376
+ * Adds an inlined language to markup.
1377
+ *
1378
+ * An example of an inlined language is CSS with `<style>` tags.
1379
+ *
1380
+ * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
1381
+ * case insensitive.
1382
+ * @param {string} lang The language key.
1383
+ * @example
1384
+ * addInlined('style', 'css');
1385
+ */
1386
+ value: function addInlined(tagName, lang) {
1387
+ var includedCdataInside = {};
1388
+ includedCdataInside['language-' + lang] = {
1389
+ pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
1390
+ lookbehind: true,
1391
+ inside: Prism.languages[lang]
1392
+ };
1393
+ includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
1394
+
1395
+ var inside = {
1396
+ 'included-cdata': {
1397
+ pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
1398
+ inside: includedCdataInside
1399
+ }
1400
+ };
1401
+ inside['language-' + lang] = {
1402
+ pattern: /[\s\S]+/,
1403
+ inside: Prism.languages[lang]
1404
+ };
1405
+
1406
+ var def = {};
1407
+ def[tagName] = {
1408
+ pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
1409
+ lookbehind: true,
1410
+ greedy: true,
1411
+ inside: inside
1412
+ };
1413
+
1414
+ Prism.languages.insertBefore('markup', 'cdata', def);
1415
+ }
1416
+ });
1417
+ Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
1418
+ /**
1419
+ * Adds an pattern to highlight languages embedded in HTML attributes.
1420
+ *
1421
+ * An example of an inlined language is CSS with `style` attributes.
1422
+ *
1423
+ * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
1424
+ * case insensitive.
1425
+ * @param {string} lang The language key.
1426
+ * @example
1427
+ * addAttribute('style', 'css');
1428
+ */
1429
+ value: function (attrName, lang) {
1430
+ Prism.languages.markup.tag.inside['special-attr'].push({
1431
+ pattern: RegExp(
1432
+ /(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
1433
+ 'i'
1434
+ ),
1435
+ lookbehind: true,
1436
+ inside: {
1437
+ 'attr-name': /^[^\s=]+/,
1438
+ 'attr-value': {
1439
+ pattern: /=[\s\S]+/,
1440
+ inside: {
1441
+ 'value': {
1442
+ pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
1443
+ lookbehind: true,
1444
+ alias: [lang, 'language-' + lang],
1445
+ inside: Prism.languages[lang]
1446
+ },
1447
+ 'punctuation': [
1448
+ {
1449
+ pattern: /^=/,
1450
+ alias: 'attr-equals'
1451
+ },
1452
+ /"|'/
1453
+ ]
1454
+ }
1455
+ }
1456
+ }
1457
+ });
1458
+ }
1459
+ });
1460
+
1461
+ Prism.languages.html = Prism.languages.markup;
1462
+ Prism.languages.mathml = Prism.languages.markup;
1463
+ Prism.languages.svg = Prism.languages.markup;
1464
+
1465
+ Prism.languages.xml = Prism.languages.extend('markup', {});
1466
+ Prism.languages.ssml = Prism.languages.xml;
1467
+ Prism.languages.atom = Prism.languages.xml;
1468
+ Prism.languages.rss = Prism.languages.xml;
1469
+
1470
+
1471
+ /* **********************************************
1472
+ Begin prism-css.js
1473
+ ********************************************** */
1474
+
1475
+ (function (Prism) {
1476
+
1477
+ var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
1478
+
1479
+ Prism.languages.css = {
1480
+ 'comment': /\/\*[\s\S]*?\*\//,
1481
+ 'atrule': {
1482
+ pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
1483
+ inside: {
1484
+ 'rule': /^@[\w-]+/,
1485
+ 'selector-function-argument': {
1486
+ pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
1487
+ lookbehind: true,
1488
+ alias: 'selector'
1489
+ },
1490
+ 'keyword': {
1491
+ pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
1492
+ lookbehind: true
1493
+ }
1494
+ // See rest below
1495
+ }
1496
+ },
1497
+ 'url': {
1498
+ // https://drafts.csswg.org/css-values-3/#urls
1499
+ pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
1500
+ greedy: true,
1501
+ inside: {
1502
+ 'function': /^url/i,
1503
+ 'punctuation': /^\(|\)$/,
1504
+ 'string': {
1505
+ pattern: RegExp('^' + string.source + '$'),
1506
+ alias: 'url'
1507
+ }
1508
+ }
1509
+ },
1510
+ 'selector': {
1511
+ pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
1512
+ lookbehind: true
1513
+ },
1514
+ 'string': {
1515
+ pattern: string,
1516
+ greedy: true
1517
+ },
1518
+ 'property': {
1519
+ pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
1520
+ lookbehind: true
1521
+ },
1522
+ 'important': /!important\b/i,
1523
+ 'function': {
1524
+ pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
1525
+ lookbehind: true
1526
+ },
1527
+ 'punctuation': /[(){};:,]/
1528
+ };
1529
+
1530
+ Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
1531
+
1532
+ var markup = Prism.languages.markup;
1533
+ if (markup) {
1534
+ markup.tag.addInlined('style', 'css');
1535
+ markup.tag.addAttribute('style', 'css');
1536
+ }
1537
+
1538
+ }(Prism));
1539
+
1540
+
1541
+ /* **********************************************
1542
+ Begin prism-clike.js
1543
+ ********************************************** */
1544
+
1545
+ Prism.languages.clike = {
1546
+ 'comment': [
1547
+ {
1548
+ pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
1549
+ lookbehind: true,
1550
+ greedy: true
1551
+ },
1552
+ {
1553
+ pattern: /(^|[^\\:])\/\/.*/,
1554
+ lookbehind: true,
1555
+ greedy: true
1556
+ }
1557
+ ],
1558
+ 'string': {
1559
+ pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
1560
+ greedy: true
1561
+ },
1562
+ 'class-name': {
1563
+ pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
1564
+ lookbehind: true,
1565
+ inside: {
1566
+ 'punctuation': /[.\\]/
1567
+ }
1568
+ },
1569
+ 'keyword': /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
1570
+ 'boolean': /\b(?:false|true)\b/,
1571
+ 'function': /\b\w+(?=\()/,
1572
+ 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
1573
+ 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
1574
+ 'punctuation': /[{}[\];(),.:]/
1575
+ };
1576
+
1577
+
1578
+ /* **********************************************
1579
+ Begin prism-javascript.js
1580
+ ********************************************** */
1581
+
1582
+ Prism.languages.javascript = Prism.languages.extend('clike', {
1583
+ 'class-name': [
1584
+ Prism.languages.clike['class-name'],
1585
+ {
1586
+ pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
1587
+ lookbehind: true
1588
+ }
1589
+ ],
1590
+ 'keyword': [
1591
+ {
1592
+ pattern: /((?:^|\})\s*)catch\b/,
1593
+ lookbehind: true
1594
+ },
1595
+ {
1596
+ pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
1597
+ lookbehind: true
1598
+ },
1599
+ ],
1600
+ // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
1601
+ 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
1602
+ 'number': {
1603
+ pattern: RegExp(
1604
+ /(^|[^\w$])/.source +
1605
+ '(?:' +
1606
+ (
1607
+ // constant
1608
+ /NaN|Infinity/.source +
1609
+ '|' +
1610
+ // binary integer
1611
+ /0[bB][01]+(?:_[01]+)*n?/.source +
1612
+ '|' +
1613
+ // octal integer
1614
+ /0[oO][0-7]+(?:_[0-7]+)*n?/.source +
1615
+ '|' +
1616
+ // hexadecimal integer
1617
+ /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source +
1618
+ '|' +
1619
+ // decimal bigint
1620
+ /\d+(?:_\d+)*n/.source +
1621
+ '|' +
1622
+ // decimal number (integer or float) but no bigint
1623
+ /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source
1624
+ ) +
1625
+ ')' +
1626
+ /(?![\w$])/.source
1627
+ ),
1628
+ lookbehind: true
1629
+ },
1630
+ 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
1631
+ });
1632
+
1633
+ Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
1634
+
1635
+ Prism.languages.insertBefore('javascript', 'keyword', {
1636
+ 'regex': {
1637
+ pattern: RegExp(
1638
+ // lookbehind
1639
+ // eslint-disable-next-line regexp/no-dupe-characters-character-class
1640
+ /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source +
1641
+ // Regex pattern:
1642
+ // There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
1643
+ // classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
1644
+ // with the only syntax, so we have to define 2 different regex patterns.
1645
+ /\//.source +
1646
+ '(?:' +
1647
+ /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source +
1648
+ '|' +
1649
+ // `v` flag syntax. This supports 3 levels of nested character classes.
1650
+ /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source +
1651
+ ')' +
1652
+ // lookahead
1653
+ /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
1654
+ ),
1655
+ lookbehind: true,
1656
+ greedy: true,
1657
+ inside: {
1658
+ 'regex-source': {
1659
+ pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
1660
+ lookbehind: true,
1661
+ alias: 'language-regex',
1662
+ inside: Prism.languages.regex
1663
+ },
1664
+ 'regex-delimiter': /^\/|\/$/,
1665
+ 'regex-flags': /^[a-z]+$/,
1666
+ }
1667
+ },
1668
+ // This must be declared before keyword because we use "function" inside the look-forward
1669
+ 'function-variable': {
1670
+ pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
1671
+ alias: 'function'
1672
+ },
1673
+ 'parameter': [
1674
+ {
1675
+ pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
1676
+ lookbehind: true,
1677
+ inside: Prism.languages.javascript
1678
+ },
1679
+ {
1680
+ pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
1681
+ lookbehind: true,
1682
+ inside: Prism.languages.javascript
1683
+ },
1684
+ {
1685
+ pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
1686
+ lookbehind: true,
1687
+ inside: Prism.languages.javascript
1688
+ },
1689
+ {
1690
+ pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,
1691
+ lookbehind: true,
1692
+ inside: Prism.languages.javascript
1693
+ }
1694
+ ],
1695
+ 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
1696
+ });
1697
+
1698
+ Prism.languages.insertBefore('javascript', 'string', {
1699
+ 'hashbang': {
1700
+ pattern: /^#!.*/,
1701
+ greedy: true,
1702
+ alias: 'comment'
1703
+ },
1704
+ 'template-string': {
1705
+ pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
1706
+ greedy: true,
1707
+ inside: {
1708
+ 'template-punctuation': {
1709
+ pattern: /^`|`$/,
1710
+ alias: 'string'
1711
+ },
1712
+ 'interpolation': {
1713
+ pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
1714
+ lookbehind: true,
1715
+ inside: {
1716
+ 'interpolation-punctuation': {
1717
+ pattern: /^\$\{|\}$/,
1718
+ alias: 'punctuation'
1719
+ },
1720
+ rest: Prism.languages.javascript
1721
+ }
1722
+ },
1723
+ 'string': /[\s\S]+/
1724
+ }
1725
+ },
1726
+ 'string-property': {
1727
+ pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
1728
+ lookbehind: true,
1729
+ greedy: true,
1730
+ alias: 'property'
1731
+ }
1732
+ });
1733
+
1734
+ Prism.languages.insertBefore('javascript', 'operator', {
1735
+ 'literal-property': {
1736
+ pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
1737
+ lookbehind: true,
1738
+ alias: 'property'
1739
+ },
1740
+ });
1741
+
1742
+ if (Prism.languages.markup) {
1743
+ Prism.languages.markup.tag.addInlined('script', 'javascript');
1744
+
1745
+ // add attribute support for all DOM events.
1746
+ // https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events
1747
+ Prism.languages.markup.tag.addAttribute(
1748
+ /on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,
1749
+ 'javascript'
1750
+ );
1751
+ }
1752
+
1753
+ Prism.languages.js = Prism.languages.javascript;
1754
+
1755
+
1756
+ /* **********************************************
1757
+ Begin prism-file-highlight.js
1758
+ ********************************************** */
1759
+
1760
+ (function () {
1761
+
1762
+ if (typeof Prism === 'undefined' || typeof document === 'undefined') {
1763
+ return;
1764
+ }
1765
+
1766
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
1767
+ if (!Element.prototype.matches) {
1768
+ Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
1769
+ }
1770
+
1771
+ var LOADING_MESSAGE = 'Loading…';
1772
+ var FAILURE_MESSAGE = function (status, message) {
1773
+ return '✖ Error ' + status + ' while fetching file: ' + message;
1774
+ };
1775
+ var FAILURE_EMPTY_MESSAGE = '✖ Error: File does not exist or is empty';
1776
+
1777
+ var EXTENSIONS = {
1778
+ 'js': 'javascript',
1779
+ 'py': 'python',
1780
+ 'rb': 'ruby',
1781
+ 'ps1': 'powershell',
1782
+ 'psm1': 'powershell',
1783
+ 'sh': 'bash',
1784
+ 'bat': 'batch',
1785
+ 'h': 'c',
1786
+ 'tex': 'latex'
1787
+ };
1788
+
1789
+ var STATUS_ATTR = 'data-src-status';
1790
+ var STATUS_LOADING = 'loading';
1791
+ var STATUS_LOADED = 'loaded';
1792
+ var STATUS_FAILED = 'failed';
1793
+
1794
+ var SELECTOR = 'pre[data-src]:not([' + STATUS_ATTR + '="' + STATUS_LOADED + '"])'
1795
+ + ':not([' + STATUS_ATTR + '="' + STATUS_LOADING + '"])';
1796
+
1797
+ /**
1798
+ * Loads the given file.
1799
+ *
1800
+ * @param {string} src The URL or path of the source file to load.
1801
+ * @param {(result: string) => void} success
1802
+ * @param {(reason: string) => void} error
1803
+ */
1804
+ function loadFile(src, success, error) {
1805
+ var xhr = new XMLHttpRequest();
1806
+ xhr.open('GET', src, true);
1807
+ xhr.onreadystatechange = function () {
1808
+ if (xhr.readyState == 4) {
1809
+ if (xhr.status < 400 && xhr.responseText) {
1810
+ success(xhr.responseText);
1811
+ } else {
1812
+ if (xhr.status >= 400) {
1813
+ error(FAILURE_MESSAGE(xhr.status, xhr.statusText));
1814
+ } else {
1815
+ error(FAILURE_EMPTY_MESSAGE);
1816
+ }
1817
+ }
1818
+ }
1819
+ };
1820
+ xhr.send(null);
1821
+ }
1822
+
1823
+ /**
1824
+ * Parses the given range.
1825
+ *
1826
+ * This returns a range with inclusive ends.
1827
+ *
1828
+ * @param {string | null | undefined} range
1829
+ * @returns {[number, number | undefined] | undefined}
1830
+ */
1831
+ function parseRange(range) {
1832
+ var m = /^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(range || '');
1833
+ if (m) {
1834
+ var start = Number(m[1]);
1835
+ var comma = m[2];
1836
+ var end = m[3];
1837
+
1838
+ if (!comma) {
1839
+ return [start, start];
1840
+ }
1841
+ if (!end) {
1842
+ return [start, undefined];
1843
+ }
1844
+ return [start, Number(end)];
1845
+ }
1846
+ return undefined;
1847
+ }
1848
+
1849
+ Prism.hooks.add('before-highlightall', function (env) {
1850
+ env.selector += ', ' + SELECTOR;
1851
+ });
1852
+
1853
+ Prism.hooks.add('before-sanity-check', function (env) {
1854
+ var pre = /** @type {HTMLPreElement} */ (env.element);
1855
+ if (pre.matches(SELECTOR)) {
1856
+ env.code = ''; // fast-path the whole thing and go to complete
1857
+
1858
+ pre.setAttribute(STATUS_ATTR, STATUS_LOADING); // mark as loading
1859
+
1860
+ // add code element with loading message
1861
+ var code = pre.appendChild(document.createElement('CODE'));
1862
+ code.textContent = LOADING_MESSAGE;
1863
+
1864
+ var src = pre.getAttribute('data-src');
1865
+
1866
+ var language = env.language;
1867
+ if (language === 'none') {
1868
+ // the language might be 'none' because there is no language set;
1869
+ // in this case, we want to use the extension as the language
1870
+ var extension = (/\.(\w+)$/.exec(src) || [, 'none'])[1];
1871
+ language = EXTENSIONS[extension] || extension;
1872
+ }
1873
+
1874
+ // set language classes
1875
+ Prism.util.setLanguage(code, language);
1876
+ Prism.util.setLanguage(pre, language);
1877
+
1878
+ // preload the language
1879
+ var autoloader = Prism.plugins.autoloader;
1880
+ if (autoloader) {
1881
+ autoloader.loadLanguages(language);
1882
+ }
1883
+
1884
+ // load file
1885
+ loadFile(
1886
+ src,
1887
+ function (text) {
1888
+ // mark as loaded
1889
+ pre.setAttribute(STATUS_ATTR, STATUS_LOADED);
1890
+
1891
+ // handle data-range
1892
+ var range = parseRange(pre.getAttribute('data-range'));
1893
+ if (range) {
1894
+ var lines = text.split(/\r\n?|\n/g);
1895
+
1896
+ // the range is one-based and inclusive on both ends
1897
+ var start = range[0];
1898
+ var end = range[1] == null ? lines.length : range[1];
1899
+
1900
+ if (start < 0) { start += lines.length; }
1901
+ start = Math.max(0, Math.min(start - 1, lines.length));
1902
+ if (end < 0) { end += lines.length; }
1903
+ end = Math.max(0, Math.min(end, lines.length));
1904
+
1905
+ text = lines.slice(start, end).join('\n');
1906
+
1907
+ // add data-start for line numbers
1908
+ if (!pre.hasAttribute('data-start')) {
1909
+ pre.setAttribute('data-start', String(start + 1));
1910
+ }
1911
+ }
1912
+
1913
+ // highlight code
1914
+ code.textContent = text;
1915
+ Prism.highlightElement(code);
1916
+ },
1917
+ function (error) {
1918
+ // mark as failed
1919
+ pre.setAttribute(STATUS_ATTR, STATUS_FAILED);
1920
+
1921
+ code.textContent = error;
1922
+ }
1923
+ );
1924
+ }
1925
+ });
1926
+
1927
+ Prism.plugins.fileHighlight = {
1928
+ /**
1929
+ * Executes the File Highlight plugin for all matching `pre` elements under the given container.
1930
+ *
1931
+ * Note: Elements which are already loaded or currently loading will not be touched by this method.
1932
+ *
1933
+ * @param {ParentNode} [container=document]
1934
+ */
1935
+ highlight: function highlight(container) {
1936
+ var elements = (container || document).querySelectorAll(SELECTOR);
1937
+
1938
+ for (var i = 0, element; (element = elements[i++]);) {
1939
+ Prism.highlightElement(element);
1940
+ }
1941
+ }
1942
+ };
1943
+
1944
+ var logged = false;
1945
+ /** @deprecated Use `Prism.plugins.fileHighlight.highlight` instead. */
1946
+ Prism.fileHighlight = function () {
1947
+ if (!logged) {
1948
+ console.warn('Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead.');
1949
+ logged = true;
1950
+ }
1951
+ Prism.plugins.fileHighlight.highlight.apply(this, arguments);
1952
+ };
1953
+
1954
+ }());
1955
+ } (prism));
1956
+ return prism.exports;
1957
+ }
1958
+
1959
+ export { requirePrism as __require };