@trishchuk/coolors-mcp 1.0.1 → 1.1.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 (105) hide show
  1. package/.github/workflows/ci.yml +23 -20
  2. package/.github/workflows/deploy-docs.yml +6 -3
  3. package/.github/workflows/release.yml +11 -9
  4. package/README.md +123 -14
  5. package/dist/bin/server.js +997 -256
  6. package/dist/bin/server.js.map +1 -1
  7. package/dist/{chunk-P3ARRKLS.js → chunk-HOMDMKUY.js} +3 -1
  8. package/dist/{chunk-P3ARRKLS.js.map → chunk-HOMDMKUY.js.map} +1 -1
  9. package/dist/{chunk-IQ7NN26V.js → chunk-LHW2ZTOU.js} +14 -2
  10. package/dist/chunk-LHW2ZTOU.js.map +1 -0
  11. package/dist/color/index.js +1 -1
  12. package/dist/coolors-mcp.d.ts +4 -4
  13. package/dist/coolors-mcp.js +1 -1
  14. package/eslint.config.ts +13 -0
  15. package/jsr.json +1 -1
  16. package/package.json +16 -12
  17. package/src/bin/server.ts +13 -1
  18. package/src/color/__tests__/extract-colors.test.ts +20 -30
  19. package/src/color/apca.ts +105 -0
  20. package/src/color/color-blindness.ts +109 -0
  21. package/src/coolors-mcp.ts +1 -1
  22. package/src/session.ts +10 -2
  23. package/src/theme/matcher.ts +1 -1
  24. package/src/theme/refactor.ts +1 -1
  25. package/src/theme/types.ts +3 -0
  26. package/src/tools/__tests__/cohesion.test.ts +97 -0
  27. package/src/tools/__tests__/color-blindness.test.ts +45 -0
  28. package/src/tools/__tests__/color-conversion.test.ts +38 -0
  29. package/src/tools/__tests__/contrast-checker.test.ts +56 -0
  30. package/src/tools/__tests__/palette-export.test.ts +54 -0
  31. package/src/tools/adjust-color.tool.ts +80 -0
  32. package/src/tools/cohesion.tools.ts +380 -0
  33. package/src/tools/color-blindness.tool.ts +168 -0
  34. package/src/tools/color-conversion.tool.ts +1 -1
  35. package/src/tools/contrast-checker.tool.ts +53 -14
  36. package/src/tools/dislike-analyzer.tool.ts +41 -54
  37. package/src/tools/image-extraction.tools.ts +62 -115
  38. package/src/tools/index.ts +15 -2
  39. package/src/tools/palette-export.tool.ts +174 -0
  40. package/src/tools/palette-with-locks.tool.ts +8 -6
  41. package/src/types.ts +2 -3
  42. package/tsconfig.json +12 -2
  43. package/vitest.config.js +1 -3
  44. package/.claude/settings.local.json +0 -35
  45. package/.env +0 -2
  46. package/.mcp.json +0 -12
  47. package/CLAUDE.md +0 -201
  48. package/DOCUMENTATION.md +0 -274
  49. package/GEMINI.md +0 -54
  50. package/TOOLS_UK.md +0 -233
  51. package/demo/content_based_color.png +0 -0
  52. package/demo/music-player.html +0 -621
  53. package/demo/podcast-player.html +0 -903
  54. package/dist/chunk-IQ7NN26V.js.map +0 -1
  55. package/docs/.vitepress/cache/deps/@braintree_sanitize-url.js +0 -111
  56. package/docs/.vitepress/cache/deps/@braintree_sanitize-url.js.map +0 -7
  57. package/docs/.vitepress/cache/deps/_metadata.json +0 -127
  58. package/docs/.vitepress/cache/deps/chunk-BUSYA2B4.js +0 -12
  59. package/docs/.vitepress/cache/deps/chunk-BUSYA2B4.js.map +0 -7
  60. package/docs/.vitepress/cache/deps/chunk-JD3CXNQ6.js +0 -13614
  61. package/docs/.vitepress/cache/deps/chunk-JD3CXNQ6.js.map +0 -7
  62. package/docs/.vitepress/cache/deps/chunk-SYPOPCWC.js +0 -10698
  63. package/docs/.vitepress/cache/deps/chunk-SYPOPCWC.js.map +0 -7
  64. package/docs/.vitepress/cache/deps/cytoscape-cose-bilkent.js +0 -5609
  65. package/docs/.vitepress/cache/deps/cytoscape-cose-bilkent.js.map +0 -7
  66. package/docs/.vitepress/cache/deps/cytoscape.js +0 -36234
  67. package/docs/.vitepress/cache/deps/cytoscape.js.map +0 -7
  68. package/docs/.vitepress/cache/deps/dayjs.js +0 -507
  69. package/docs/.vitepress/cache/deps/dayjs.js.map +0 -7
  70. package/docs/.vitepress/cache/deps/debug.js +0 -512
  71. package/docs/.vitepress/cache/deps/debug.js.map +0 -7
  72. package/docs/.vitepress/cache/deps/package.json +0 -3
  73. package/docs/.vitepress/cache/deps/prismjs.js +0 -1638
  74. package/docs/.vitepress/cache/deps/prismjs.js.map +0 -7
  75. package/docs/.vitepress/cache/deps/prismjs_components_prism-bash.js +0 -235
  76. package/docs/.vitepress/cache/deps/prismjs_components_prism-bash.js.map +0 -7
  77. package/docs/.vitepress/cache/deps/prismjs_components_prism-javascript.js +0 -173
  78. package/docs/.vitepress/cache/deps/prismjs_components_prism-javascript.js.map +0 -7
  79. package/docs/.vitepress/cache/deps/prismjs_components_prism-json.js +0 -27
  80. package/docs/.vitepress/cache/deps/prismjs_components_prism-json.js.map +0 -7
  81. package/docs/.vitepress/cache/deps/prismjs_components_prism-python.js +0 -72
  82. package/docs/.vitepress/cache/deps/prismjs_components_prism-python.js.map +0 -7
  83. package/docs/.vitepress/cache/deps/prismjs_components_prism-typescript.js +0 -56
  84. package/docs/.vitepress/cache/deps/prismjs_components_prism-typescript.js.map +0 -7
  85. package/docs/.vitepress/cache/deps/prismjs_components_prism-yaml.js +0 -107
  86. package/docs/.vitepress/cache/deps/prismjs_components_prism-yaml.js.map +0 -7
  87. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +0 -5074
  88. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +0 -7
  89. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +0 -584
  90. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +0 -7
  91. package/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js +0 -1483
  92. package/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js.map +0 -7
  93. package/docs/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js +0 -1779
  94. package/docs/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js.map +0 -7
  95. package/docs/.vitepress/cache/deps/vitepress___minisearch.js +0 -2023
  96. package/docs/.vitepress/cache/deps/vitepress___minisearch.js.map +0 -7
  97. package/docs/.vitepress/cache/deps/vue.js +0 -344
  98. package/docs/.vitepress/cache/deps/vue.js.map +0 -7
  99. package/examples/theme-matching.md +0 -113
  100. package/mcp-config.json +0 -8
  101. package/note.md +0 -34
  102. package/research_results.md +0 -53
  103. package/src/tools/colors.ts +0 -31
  104. package/src/tools/registry.ts +0 -142
  105. package/src/tools/simple-tools.ts +0 -37
@@ -1,1638 +0,0 @@
1
- import { __commonJS } from "./chunk-BUSYA2B4.js";
2
-
3
- // node_modules/prismjs/prism.js
4
- var require_prism = __commonJS({
5
- "node_modules/prismjs/prism.js"(exports, module) {
6
- var _self =
7
- typeof window !== "undefined"
8
- ? window
9
- : typeof WorkerGlobalScope !== "undefined" &&
10
- self instanceof WorkerGlobalScope
11
- ? self
12
- : {};
13
- var Prism = (function (_self2) {
14
- var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
15
- var uniqueId = 0;
16
- var plainTextGrammar = {};
17
- var _ = {
18
- /**
19
- * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
20
- * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
21
- * additional languages or plugins yourself.
22
- *
23
- * By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
24
- *
25
- * You obviously have to change this value before the automatic highlighting started. To do this, you can add an
26
- * empty Prism object into the global scope before loading the Prism script like this:
27
- *
28
- * ```js
29
- * window.Prism = window.Prism || {};
30
- * Prism.manual = true;
31
- * // add a new <script> to load Prism's script
32
- * ```
33
- *
34
- * @default false
35
- * @type {boolean}
36
- * @memberof Prism
37
- * @public
38
- */
39
- manual: _self2.Prism && _self2.Prism.manual,
40
- /**
41
- * By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
42
- * `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
43
- * own worker, you don't want it to do this.
44
- *
45
- * By setting this value to `true`, Prism will not add its own listeners to the worker.
46
- *
47
- * You obviously have to change this value before Prism executes. To do this, you can add an
48
- * empty Prism object into the global scope before loading the Prism script like this:
49
- *
50
- * ```js
51
- * window.Prism = window.Prism || {};
52
- * Prism.disableWorkerMessageHandler = true;
53
- * // Load Prism's script
54
- * ```
55
- *
56
- * @default false
57
- * @type {boolean}
58
- * @memberof Prism
59
- * @public
60
- */
61
- disableWorkerMessageHandler:
62
- _self2.Prism && _self2.Prism.disableWorkerMessageHandler,
63
- /**
64
- * A namespace for utility methods.
65
- *
66
- * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
67
- * change or disappear at any time.
68
- *
69
- * @namespace
70
- * @memberof Prism
71
- */
72
- util: {
73
- encode: function encode(tokens) {
74
- if (tokens instanceof Token) {
75
- return new Token(
76
- tokens.type,
77
- encode(tokens.content),
78
- tokens.alias,
79
- );
80
- } else if (Array.isArray(tokens)) {
81
- return tokens.map(encode);
82
- } else {
83
- return tokens
84
- .replace(/&/g, "&amp;")
85
- .replace(/</g, "&lt;")
86
- .replace(/\u00a0/g, " ");
87
- }
88
- },
89
- /**
90
- * Returns the name of the type of the given value.
91
- *
92
- * @param {any} o
93
- * @returns {string}
94
- * @example
95
- * type(null) === 'Null'
96
- * type(undefined) === 'Undefined'
97
- * type(123) === 'Number'
98
- * type('foo') === 'String'
99
- * type(true) === 'Boolean'
100
- * type([1, 2]) === 'Array'
101
- * type({}) === 'Object'
102
- * type(String) === 'Function'
103
- * type(/abc+/) === 'RegExp'
104
- */
105
- type: function (o) {
106
- return Object.prototype.toString.call(o).slice(8, -1);
107
- },
108
- /**
109
- * Returns a unique number for the given object. Later calls will still return the same number.
110
- *
111
- * @param {Object} obj
112
- * @returns {number}
113
- */
114
- objId: function (obj) {
115
- if (!obj["__id"]) {
116
- Object.defineProperty(obj, "__id", { value: ++uniqueId });
117
- }
118
- return obj["__id"];
119
- },
120
- /**
121
- * Creates a deep clone of the given object.
122
- *
123
- * The main intended use of this function is to clone language definitions.
124
- *
125
- * @param {T} o
126
- * @param {Record<number, any>} [visited]
127
- * @returns {T}
128
- * @template T
129
- */
130
- clone: function deepClone(o, visited) {
131
- visited = visited || {};
132
- var clone;
133
- var id;
134
- switch (_.util.type(o)) {
135
- case "Object":
136
- id = _.util.objId(o);
137
- if (visited[id]) {
138
- return visited[id];
139
- }
140
- clone = /** @type {Record<string, any>} */ {};
141
- visited[id] = clone;
142
- for (var key in o) {
143
- if (o.hasOwnProperty(key)) {
144
- clone[key] = deepClone(o[key], visited);
145
- }
146
- }
147
- return (
148
- /** @type {any} */
149
- clone
150
- );
151
- case "Array":
152
- id = _.util.objId(o);
153
- if (visited[id]) {
154
- return visited[id];
155
- }
156
- clone = [];
157
- visited[id] = clone;
158
- /** @type {Array} */
159
- /** @type {any} */
160
- o.forEach(function (v, i) {
161
- clone[i] = deepClone(v, visited);
162
- });
163
- return (
164
- /** @type {any} */
165
- clone
166
- );
167
- default:
168
- return o;
169
- }
170
- },
171
- /**
172
- * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
173
- *
174
- * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
175
- *
176
- * @param {Element} element
177
- * @returns {string}
178
- */
179
- getLanguage: function (element) {
180
- while (element) {
181
- var m = lang.exec(element.className);
182
- if (m) {
183
- return m[1].toLowerCase();
184
- }
185
- element = element.parentElement;
186
- }
187
- return "none";
188
- },
189
- /**
190
- * Sets the Prism `language-xxxx` class of the given element.
191
- *
192
- * @param {Element} element
193
- * @param {string} language
194
- * @returns {void}
195
- */
196
- setLanguage: function (element, language) {
197
- element.className = element.className.replace(
198
- RegExp(lang, "gi"),
199
- "",
200
- );
201
- element.classList.add("language-" + language);
202
- },
203
- /**
204
- * Returns the script element that is currently executing.
205
- *
206
- * This does __not__ work for line script element.
207
- *
208
- * @returns {HTMLScriptElement | null}
209
- */
210
- currentScript: function () {
211
- if (typeof document === "undefined") {
212
- return null;
213
- }
214
- if (
215
- document.currentScript &&
216
- document.currentScript.tagName === "SCRIPT" &&
217
- 1 < 2
218
- ) {
219
- return (
220
- /** @type {any} */
221
- document.currentScript
222
- );
223
- }
224
- try {
225
- throw new Error();
226
- } catch (err) {
227
- var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) ||
228
- [])[1];
229
- if (src) {
230
- var scripts = document.getElementsByTagName("script");
231
- for (var i in scripts) {
232
- if (scripts[i].src == src) {
233
- return scripts[i];
234
- }
235
- }
236
- }
237
- return null;
238
- }
239
- },
240
- /**
241
- * Returns whether a given class is active for `element`.
242
- *
243
- * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
244
- * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
245
- * given class is just the given class with a `no-` prefix.
246
- *
247
- * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
248
- * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
249
- * ancestors have the given class or the negated version of it, then the default activation will be returned.
250
- *
251
- * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
252
- * version of it, the class is considered active.
253
- *
254
- * @param {Element} element
255
- * @param {string} className
256
- * @param {boolean} [defaultActivation=false]
257
- * @returns {boolean}
258
- */
259
- isActive: function (element, className, defaultActivation) {
260
- var no = "no-" + className;
261
- while (element) {
262
- var classList = element.classList;
263
- if (classList.contains(className)) {
264
- return true;
265
- }
266
- if (classList.contains(no)) {
267
- return false;
268
- }
269
- element = element.parentElement;
270
- }
271
- return !!defaultActivation;
272
- },
273
- },
274
- /**
275
- * This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
276
- *
277
- * @namespace
278
- * @memberof Prism
279
- * @public
280
- */
281
- languages: {
282
- /**
283
- * The grammar for plain, unformatted text.
284
- */
285
- plain: plainTextGrammar,
286
- plaintext: plainTextGrammar,
287
- text: plainTextGrammar,
288
- txt: plainTextGrammar,
289
- /**
290
- * Creates a deep copy of the language with the given id and appends the given tokens.
291
- *
292
- * If a token in `redef` also appears in the copied language, then the existing token in the copied language
293
- * will be overwritten at its original position.
294
- *
295
- * ## Best practices
296
- *
297
- * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
298
- * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
299
- * understand the language definition because, normally, the order of tokens matters in Prism grammars.
300
- *
301
- * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
302
- * Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
303
- *
304
- * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
305
- * @param {Grammar} redef The new tokens to append.
306
- * @returns {Grammar} The new language created.
307
- * @public
308
- * @example
309
- * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
310
- * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
311
- * // at its original position
312
- * 'comment': { ... },
313
- * // CSS doesn't have a 'color' token, so this token will be appended
314
- * 'color': /\b(?:red|green|blue)\b/
315
- * });
316
- */
317
- extend: function (id, redef) {
318
- var lang2 = _.util.clone(_.languages[id]);
319
- for (var key in redef) {
320
- lang2[key] = redef[key];
321
- }
322
- return lang2;
323
- },
324
- /**
325
- * Inserts tokens _before_ another token in a language definition or any other grammar.
326
- *
327
- * ## Usage
328
- *
329
- * This helper method makes it easy to modify existing languages. For example, the CSS language definition
330
- * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
331
- * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
332
- * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
333
- * this:
334
- *
335
- * ```js
336
- * Prism.languages.markup.style = {
337
- * // token
338
- * };
339
- * ```
340
- *
341
- * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
342
- * before existing tokens. For the CSS example above, you would use it like this:
343
- *
344
- * ```js
345
- * Prism.languages.insertBefore('markup', 'cdata', {
346
- * 'style': {
347
- * // token
348
- * }
349
- * });
350
- * ```
351
- *
352
- * ## Special cases
353
- *
354
- * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
355
- * will be ignored.
356
- *
357
- * This behavior can be used to insert tokens after `before`:
358
- *
359
- * ```js
360
- * Prism.languages.insertBefore('markup', 'comment', {
361
- * 'comment': Prism.languages.markup.comment,
362
- * // tokens after 'comment'
363
- * });
364
- * ```
365
- *
366
- * ## Limitations
367
- *
368
- * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
369
- * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
370
- * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
371
- * deleting properties which is necessary to insert at arbitrary positions.
372
- *
373
- * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
374
- * Instead, it will create a new object and replace all references to the target object with the new one. This
375
- * can be done without temporarily deleting properties, so the iteration order is well-defined.
376
- *
377
- * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
378
- * you hold the target object in a variable, then the value of the variable will not change.
379
- *
380
- * ```js
381
- * var oldMarkup = Prism.languages.markup;
382
- * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
383
- *
384
- * assert(oldMarkup !== Prism.languages.markup);
385
- * assert(newMarkup === Prism.languages.markup);
386
- * ```
387
- *
388
- * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
389
- * object to be modified.
390
- * @param {string} before The key to insert before.
391
- * @param {Grammar} insert An object containing the key-value pairs to be inserted.
392
- * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
393
- * object to be modified.
394
- *
395
- * Defaults to `Prism.languages`.
396
- * @returns {Grammar} The new grammar object.
397
- * @public
398
- */
399
- insertBefore: function (inside, before, insert, root) {
400
- root = root || /** @type {any} */ _.languages;
401
- var grammar = root[inside];
402
- var ret = {};
403
- for (var token in grammar) {
404
- if (grammar.hasOwnProperty(token)) {
405
- if (token == before) {
406
- for (var newToken in insert) {
407
- if (insert.hasOwnProperty(newToken)) {
408
- ret[newToken] = insert[newToken];
409
- }
410
- }
411
- }
412
- if (!insert.hasOwnProperty(token)) {
413
- ret[token] = grammar[token];
414
- }
415
- }
416
- }
417
- var old = root[inside];
418
- root[inside] = ret;
419
- _.languages.DFS(_.languages, function (key, value) {
420
- if (value === old && key != inside) {
421
- this[key] = ret;
422
- }
423
- });
424
- return ret;
425
- },
426
- // Traverse a language definition with Depth First Search
427
- DFS: function DFS(o, callback, type, visited) {
428
- visited = visited || {};
429
- var objId = _.util.objId;
430
- for (var i in o) {
431
- if (o.hasOwnProperty(i)) {
432
- callback.call(o, i, o[i], type || i);
433
- var property = o[i];
434
- var propertyType = _.util.type(property);
435
- if (propertyType === "Object" && !visited[objId(property)]) {
436
- visited[objId(property)] = true;
437
- DFS(property, callback, null, visited);
438
- } else if (
439
- propertyType === "Array" &&
440
- !visited[objId(property)]
441
- ) {
442
- visited[objId(property)] = true;
443
- DFS(property, callback, i, visited);
444
- }
445
- }
446
- }
447
- },
448
- },
449
- plugins: {},
450
- /**
451
- * This is the most high-level function in Prism’s API.
452
- * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
453
- * each one of them.
454
- *
455
- * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
456
- *
457
- * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
458
- * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
459
- * @memberof Prism
460
- * @public
461
- */
462
- highlightAll: function (async, callback) {
463
- _.highlightAllUnder(document, async, callback);
464
- },
465
- /**
466
- * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
467
- * {@link Prism.highlightElement} on each one of them.
468
- *
469
- * The following hooks will be run:
470
- * 1. `before-highlightall`
471
- * 2. `before-all-elements-highlight`
472
- * 3. All hooks of {@link Prism.highlightElement} for each element.
473
- *
474
- * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
475
- * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
476
- * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
477
- * @memberof Prism
478
- * @public
479
- */
480
- highlightAllUnder: function (container, async, callback) {
481
- var env = {
482
- callback,
483
- container,
484
- selector:
485
- 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code',
486
- };
487
- _.hooks.run("before-highlightall", env);
488
- env.elements = Array.prototype.slice.apply(
489
- env.container.querySelectorAll(env.selector),
490
- );
491
- _.hooks.run("before-all-elements-highlight", env);
492
- for (var i = 0, element; (element = env.elements[i++]); ) {
493
- _.highlightElement(element, async === true, env.callback);
494
- }
495
- },
496
- /**
497
- * Highlights the code inside a single element.
498
- *
499
- * The following hooks will be run:
500
- * 1. `before-sanity-check`
501
- * 2. `before-highlight`
502
- * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
503
- * 4. `before-insert`
504
- * 5. `after-highlight`
505
- * 6. `complete`
506
- *
507
- * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
508
- * the element's language.
509
- *
510
- * @param {Element} element The element containing the code.
511
- * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
512
- * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
513
- * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
514
- * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
515
- *
516
- * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
517
- * asynchronous highlighting to work. You can build your own bundle on the
518
- * [Download page](https://prismjs.com/download.html).
519
- * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
520
- * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
521
- * @memberof Prism
522
- * @public
523
- */
524
- highlightElement: function (element, async, callback) {
525
- var language = _.util.getLanguage(element);
526
- var grammar = _.languages[language];
527
- _.util.setLanguage(element, language);
528
- var parent = element.parentElement;
529
- if (parent && parent.nodeName.toLowerCase() === "pre") {
530
- _.util.setLanguage(parent, language);
531
- }
532
- var code = element.textContent;
533
- var env = {
534
- element,
535
- language,
536
- grammar,
537
- code,
538
- };
539
- function insertHighlightedCode(highlightedCode) {
540
- env.highlightedCode = highlightedCode;
541
- _.hooks.run("before-insert", env);
542
- env.element.innerHTML = env.highlightedCode;
543
- _.hooks.run("after-highlight", env);
544
- _.hooks.run("complete", env);
545
- callback && callback.call(env.element);
546
- }
547
- _.hooks.run("before-sanity-check", env);
548
- parent = env.element.parentElement;
549
- if (
550
- parent &&
551
- parent.nodeName.toLowerCase() === "pre" &&
552
- !parent.hasAttribute("tabindex")
553
- ) {
554
- parent.setAttribute("tabindex", "0");
555
- }
556
- if (!env.code) {
557
- _.hooks.run("complete", env);
558
- callback && callback.call(env.element);
559
- return;
560
- }
561
- _.hooks.run("before-highlight", env);
562
- if (!env.grammar) {
563
- insertHighlightedCode(_.util.encode(env.code));
564
- return;
565
- }
566
- if (async && _self2.Worker) {
567
- var worker = new Worker(_.filename);
568
- worker.onmessage = function (evt) {
569
- insertHighlightedCode(evt.data);
570
- };
571
- worker.postMessage(
572
- JSON.stringify({
573
- language: env.language,
574
- code: env.code,
575
- immediateClose: true,
576
- }),
577
- );
578
- } else {
579
- insertHighlightedCode(
580
- _.highlight(env.code, env.grammar, env.language),
581
- );
582
- }
583
- },
584
- /**
585
- * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
586
- * and the language definitions to use, and returns a string with the HTML produced.
587
- *
588
- * The following hooks will be run:
589
- * 1. `before-tokenize`
590
- * 2. `after-tokenize`
591
- * 3. `wrap`: On each {@link Token}.
592
- *
593
- * @param {string} text A string with the code to be highlighted.
594
- * @param {Grammar} grammar An object containing the tokens to use.
595
- *
596
- * Usually a language definition like `Prism.languages.markup`.
597
- * @param {string} language The name of the language definition passed to `grammar`.
598
- * @returns {string} The highlighted HTML.
599
- * @memberof Prism
600
- * @public
601
- * @example
602
- * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
603
- */
604
- highlight: function (text, grammar, language) {
605
- var env = {
606
- code: text,
607
- grammar,
608
- language,
609
- };
610
- _.hooks.run("before-tokenize", env);
611
- if (!env.grammar) {
612
- throw new Error(
613
- 'The language "' + env.language + '" has no grammar.',
614
- );
615
- }
616
- env.tokens = _.tokenize(env.code, env.grammar);
617
- _.hooks.run("after-tokenize", env);
618
- return Token.stringify(_.util.encode(env.tokens), env.language);
619
- },
620
- /**
621
- * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
622
- * and the language definitions to use, and returns an array with the tokenized code.
623
- *
624
- * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
625
- *
626
- * This method could be useful in other contexts as well, as a very crude parser.
627
- *
628
- * @param {string} text A string with the code to be highlighted.
629
- * @param {Grammar} grammar An object containing the tokens to use.
630
- *
631
- * Usually a language definition like `Prism.languages.markup`.
632
- * @returns {TokenStream} An array of strings and tokens, a token stream.
633
- * @memberof Prism
634
- * @public
635
- * @example
636
- * let code = `var foo = 0;`;
637
- * let tokens = Prism.tokenize(code, Prism.languages.javascript);
638
- * tokens.forEach(token => {
639
- * if (token instanceof Prism.Token && token.type === 'number') {
640
- * console.log(`Found numeric literal: ${token.content}`);
641
- * }
642
- * });
643
- */
644
- tokenize: function (text, grammar) {
645
- var rest = grammar.rest;
646
- if (rest) {
647
- for (var token in rest) {
648
- grammar[token] = rest[token];
649
- }
650
- delete grammar.rest;
651
- }
652
- var tokenList = new LinkedList();
653
- addAfter(tokenList, tokenList.head, text);
654
- matchGrammar(text, tokenList, grammar, tokenList.head, 0);
655
- return toArray(tokenList);
656
- },
657
- /**
658
- * @namespace
659
- * @memberof Prism
660
- * @public
661
- */
662
- hooks: {
663
- all: {},
664
- /**
665
- * Adds the given callback to the list of callbacks for the given hook.
666
- *
667
- * The callback will be invoked when the hook it is registered for is run.
668
- * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
669
- *
670
- * One callback function can be registered to multiple hooks and the same hook multiple times.
671
- *
672
- * @param {string} name The name of the hook.
673
- * @param {HookCallback} callback The callback function which is given environment variables.
674
- * @public
675
- */
676
- add: function (name, callback) {
677
- var hooks = _.hooks.all;
678
- hooks[name] = hooks[name] || [];
679
- hooks[name].push(callback);
680
- },
681
- /**
682
- * Runs a hook invoking all registered callbacks with the given environment variables.
683
- *
684
- * Callbacks will be invoked synchronously and in the order in which they were registered.
685
- *
686
- * @param {string} name The name of the hook.
687
- * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
688
- * @public
689
- */
690
- run: function (name, env) {
691
- var callbacks = _.hooks.all[name];
692
- if (!callbacks || !callbacks.length) {
693
- return;
694
- }
695
- for (var i = 0, callback; (callback = callbacks[i++]); ) {
696
- callback(env);
697
- }
698
- },
699
- },
700
- Token,
701
- };
702
- _self2.Prism = _;
703
- function Token(type, content, alias, matchedStr) {
704
- this.type = type;
705
- this.content = content;
706
- this.alias = alias;
707
- this.length = (matchedStr || "").length | 0;
708
- }
709
- Token.stringify = function stringify(o, language) {
710
- if (typeof o == "string") {
711
- return o;
712
- }
713
- if (Array.isArray(o)) {
714
- var s = "";
715
- o.forEach(function (e) {
716
- s += stringify(e, language);
717
- });
718
- return s;
719
- }
720
- var env = {
721
- type: o.type,
722
- content: stringify(o.content, language),
723
- tag: "span",
724
- classes: ["token", o.type],
725
- attributes: {},
726
- language,
727
- };
728
- var aliases = o.alias;
729
- if (aliases) {
730
- if (Array.isArray(aliases)) {
731
- Array.prototype.push.apply(env.classes, aliases);
732
- } else {
733
- env.classes.push(aliases);
734
- }
735
- }
736
- _.hooks.run("wrap", env);
737
- var attributes = "";
738
- for (var name in env.attributes) {
739
- attributes +=
740
- " " +
741
- name +
742
- '="' +
743
- (env.attributes[name] || "").replace(/"/g, "&quot;") +
744
- '"';
745
- }
746
- return (
747
- "<" +
748
- env.tag +
749
- ' class="' +
750
- env.classes.join(" ") +
751
- '"' +
752
- attributes +
753
- ">" +
754
- env.content +
755
- "</" +
756
- env.tag +
757
- ">"
758
- );
759
- };
760
- function matchPattern(pattern, pos, text, lookbehind) {
761
- pattern.lastIndex = pos;
762
- var match = pattern.exec(text);
763
- if (match && lookbehind && match[1]) {
764
- var lookbehindLength = match[1].length;
765
- match.index += lookbehindLength;
766
- match[0] = match[0].slice(lookbehindLength);
767
- }
768
- return match;
769
- }
770
- function matchGrammar(
771
- text,
772
- tokenList,
773
- grammar,
774
- startNode,
775
- startPos,
776
- rematch,
777
- ) {
778
- for (var token in grammar) {
779
- if (!grammar.hasOwnProperty(token) || !grammar[token]) {
780
- continue;
781
- }
782
- var patterns = grammar[token];
783
- patterns = Array.isArray(patterns) ? patterns : [patterns];
784
- for (var j = 0; j < patterns.length; ++j) {
785
- if (rematch && rematch.cause == token + "," + j) {
786
- return;
787
- }
788
- var patternObj = patterns[j];
789
- var inside = patternObj.inside;
790
- var lookbehind = !!patternObj.lookbehind;
791
- var greedy = !!patternObj.greedy;
792
- var alias = patternObj.alias;
793
- if (greedy && !patternObj.pattern.global) {
794
- var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
795
- patternObj.pattern = RegExp(
796
- patternObj.pattern.source,
797
- flags + "g",
798
- );
799
- }
800
- var pattern = patternObj.pattern || patternObj;
801
- for (
802
- var currentNode = startNode.next, pos = startPos;
803
- currentNode !== tokenList.tail;
804
- pos += currentNode.value.length, currentNode = currentNode.next
805
- ) {
806
- if (rematch && pos >= rematch.reach) {
807
- break;
808
- }
809
- var str = currentNode.value;
810
- if (tokenList.length > text.length) {
811
- return;
812
- }
813
- if (str instanceof Token) {
814
- continue;
815
- }
816
- var removeCount = 1;
817
- var match;
818
- if (greedy) {
819
- match = matchPattern(pattern, pos, text, lookbehind);
820
- if (!match || match.index >= text.length) {
821
- break;
822
- }
823
- var from = match.index;
824
- var to = match.index + match[0].length;
825
- var p = pos;
826
- p += currentNode.value.length;
827
- while (from >= p) {
828
- currentNode = currentNode.next;
829
- p += currentNode.value.length;
830
- }
831
- p -= currentNode.value.length;
832
- pos = p;
833
- if (currentNode.value instanceof Token) {
834
- continue;
835
- }
836
- for (
837
- var k = currentNode;
838
- k !== tokenList.tail &&
839
- (p < to || typeof k.value === "string");
840
- k = k.next
841
- ) {
842
- removeCount++;
843
- p += k.value.length;
844
- }
845
- removeCount--;
846
- str = text.slice(pos, p);
847
- match.index -= pos;
848
- } else {
849
- match = matchPattern(pattern, 0, str, lookbehind);
850
- if (!match) {
851
- continue;
852
- }
853
- }
854
- var from = match.index;
855
- var matchStr = match[0];
856
- var before = str.slice(0, from);
857
- var after = str.slice(from + matchStr.length);
858
- var reach = pos + str.length;
859
- if (rematch && reach > rematch.reach) {
860
- rematch.reach = reach;
861
- }
862
- var removeFrom = currentNode.prev;
863
- if (before) {
864
- removeFrom = addAfter(tokenList, removeFrom, before);
865
- pos += before.length;
866
- }
867
- removeRange(tokenList, removeFrom, removeCount);
868
- var wrapped = new Token(
869
- token,
870
- inside ? _.tokenize(matchStr, inside) : matchStr,
871
- alias,
872
- matchStr,
873
- );
874
- currentNode = addAfter(tokenList, removeFrom, wrapped);
875
- if (after) {
876
- addAfter(tokenList, currentNode, after);
877
- }
878
- if (removeCount > 1) {
879
- var nestedRematch = {
880
- cause: token + "," + j,
881
- reach,
882
- };
883
- matchGrammar(
884
- text,
885
- tokenList,
886
- grammar,
887
- currentNode.prev,
888
- pos,
889
- nestedRematch,
890
- );
891
- if (rematch && nestedRematch.reach > rematch.reach) {
892
- rematch.reach = nestedRematch.reach;
893
- }
894
- }
895
- }
896
- }
897
- }
898
- }
899
- function LinkedList() {
900
- var head = { value: null, prev: null, next: null };
901
- var tail = { value: null, prev: head, next: null };
902
- head.next = tail;
903
- this.head = head;
904
- this.tail = tail;
905
- this.length = 0;
906
- }
907
- function addAfter(list, node, value) {
908
- var next = node.next;
909
- var newNode = { value, prev: node, next };
910
- node.next = newNode;
911
- next.prev = newNode;
912
- list.length++;
913
- return newNode;
914
- }
915
- function removeRange(list, node, count) {
916
- var next = node.next;
917
- for (var i = 0; i < count && next !== list.tail; i++) {
918
- next = next.next;
919
- }
920
- node.next = next;
921
- next.prev = node;
922
- list.length -= i;
923
- }
924
- function toArray(list) {
925
- var array = [];
926
- var node = list.head.next;
927
- while (node !== list.tail) {
928
- array.push(node.value);
929
- node = node.next;
930
- }
931
- return array;
932
- }
933
- if (!_self2.document) {
934
- if (!_self2.addEventListener) {
935
- return _;
936
- }
937
- if (!_.disableWorkerMessageHandler) {
938
- _self2.addEventListener(
939
- "message",
940
- function (evt) {
941
- var message = JSON.parse(evt.data);
942
- var lang2 = message.language;
943
- var code = message.code;
944
- var immediateClose = message.immediateClose;
945
- _self2.postMessage(_.highlight(code, _.languages[lang2], lang2));
946
- if (immediateClose) {
947
- _self2.close();
948
- }
949
- },
950
- false,
951
- );
952
- }
953
- return _;
954
- }
955
- var script = _.util.currentScript();
956
- if (script) {
957
- _.filename = script.src;
958
- if (script.hasAttribute("data-manual")) {
959
- _.manual = true;
960
- }
961
- }
962
- function highlightAutomaticallyCallback() {
963
- if (!_.manual) {
964
- _.highlightAll();
965
- }
966
- }
967
- if (!_.manual) {
968
- var readyState = document.readyState;
969
- if (
970
- readyState === "loading" ||
971
- (readyState === "interactive" && script && script.defer)
972
- ) {
973
- document.addEventListener(
974
- "DOMContentLoaded",
975
- highlightAutomaticallyCallback,
976
- );
977
- } else {
978
- if (window.requestAnimationFrame) {
979
- window.requestAnimationFrame(highlightAutomaticallyCallback);
980
- } else {
981
- window.setTimeout(highlightAutomaticallyCallback, 16);
982
- }
983
- }
984
- }
985
- return _;
986
- })(_self);
987
- if (typeof module !== "undefined" && module.exports) {
988
- module.exports = Prism;
989
- }
990
- if (typeof global !== "undefined") {
991
- global.Prism = Prism;
992
- }
993
- Prism.languages.markup = {
994
- comment: {
995
- pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
996
- greedy: true,
997
- },
998
- prolog: {
999
- pattern: /<\?[\s\S]+?\?>/,
1000
- greedy: true,
1001
- },
1002
- doctype: {
1003
- // https://www.w3.org/TR/xml/#NT-doctypedecl
1004
- pattern:
1005
- /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
1006
- greedy: true,
1007
- inside: {
1008
- "internal-subset": {
1009
- pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
1010
- lookbehind: true,
1011
- greedy: true,
1012
- inside: null,
1013
- // see below
1014
- },
1015
- string: {
1016
- pattern: /"[^"]*"|'[^']*'/,
1017
- greedy: true,
1018
- },
1019
- punctuation: /^<!|>$|[[\]]/,
1020
- "doctype-tag": /^DOCTYPE/i,
1021
- name: /[^\s<>'"]+/,
1022
- },
1023
- },
1024
- cdata: {
1025
- pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
1026
- greedy: true,
1027
- },
1028
- tag: {
1029
- pattern:
1030
- /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
1031
- greedy: true,
1032
- inside: {
1033
- tag: {
1034
- pattern: /^<\/?[^\s>\/]+/,
1035
- inside: {
1036
- punctuation: /^<\/?/,
1037
- namespace: /^[^\s>\/:]+:/,
1038
- },
1039
- },
1040
- "special-attr": [],
1041
- "attr-value": {
1042
- pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
1043
- inside: {
1044
- punctuation: [
1045
- {
1046
- pattern: /^=/,
1047
- alias: "attr-equals",
1048
- },
1049
- {
1050
- pattern: /^(\s*)["']|["']$/,
1051
- lookbehind: true,
1052
- },
1053
- ],
1054
- },
1055
- },
1056
- punctuation: /\/?>/,
1057
- "attr-name": {
1058
- pattern: /[^\s>\/]+/,
1059
- inside: {
1060
- namespace: /^[^\s>\/:]+:/,
1061
- },
1062
- },
1063
- },
1064
- },
1065
- entity: [
1066
- {
1067
- pattern: /&[\da-z]{1,8};/i,
1068
- alias: "named-entity",
1069
- },
1070
- /&#x?[\da-f]{1,8};/i,
1071
- ],
1072
- };
1073
- Prism.languages.markup["tag"].inside["attr-value"].inside["entity"] =
1074
- Prism.languages.markup["entity"];
1075
- Prism.languages.markup["doctype"].inside["internal-subset"].inside =
1076
- Prism.languages.markup;
1077
- Prism.hooks.add("wrap", function (env) {
1078
- if (env.type === "entity") {
1079
- env.attributes["title"] = env.content.replace(/&amp;/, "&");
1080
- }
1081
- });
1082
- Object.defineProperty(Prism.languages.markup.tag, "addInlined", {
1083
- /**
1084
- * Adds an inlined language to markup.
1085
- *
1086
- * An example of an inlined language is CSS with `<style>` tags.
1087
- *
1088
- * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
1089
- * case insensitive.
1090
- * @param {string} lang The language key.
1091
- * @example
1092
- * addInlined('style', 'css');
1093
- */
1094
- value: function addInlined(tagName, lang) {
1095
- var includedCdataInside = {};
1096
- includedCdataInside["language-" + lang] = {
1097
- pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
1098
- lookbehind: true,
1099
- inside: Prism.languages[lang],
1100
- };
1101
- includedCdataInside["cdata"] = /^<!\[CDATA\[|\]\]>$/i;
1102
- var inside = {
1103
- "included-cdata": {
1104
- pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
1105
- inside: includedCdataInside,
1106
- },
1107
- };
1108
- inside["language-" + lang] = {
1109
- pattern: /[\s\S]+/,
1110
- inside: Prism.languages[lang],
1111
- };
1112
- var def = {};
1113
- def[tagName] = {
1114
- pattern: RegExp(
1115
- /(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(
1116
- /__/g,
1117
- function () {
1118
- return tagName;
1119
- },
1120
- ),
1121
- "i",
1122
- ),
1123
- lookbehind: true,
1124
- greedy: true,
1125
- inside,
1126
- };
1127
- Prism.languages.insertBefore("markup", "cdata", def);
1128
- },
1129
- });
1130
- Object.defineProperty(Prism.languages.markup.tag, "addAttribute", {
1131
- /**
1132
- * Adds an pattern to highlight languages embedded in HTML attributes.
1133
- *
1134
- * An example of an inlined language is CSS with `style` attributes.
1135
- *
1136
- * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
1137
- * case insensitive.
1138
- * @param {string} lang The language key.
1139
- * @example
1140
- * addAttribute('style', 'css');
1141
- */
1142
- value: function (attrName, lang) {
1143
- Prism.languages.markup.tag.inside["special-attr"].push({
1144
- pattern: RegExp(
1145
- /(^|["'\s])/.source +
1146
- "(?:" +
1147
- attrName +
1148
- ")" +
1149
- /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
1150
- "i",
1151
- ),
1152
- lookbehind: true,
1153
- inside: {
1154
- "attr-name": /^[^\s=]+/,
1155
- "attr-value": {
1156
- pattern: /=[\s\S]+/,
1157
- inside: {
1158
- value: {
1159
- pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
1160
- lookbehind: true,
1161
- alias: [lang, "language-" + lang],
1162
- inside: Prism.languages[lang],
1163
- },
1164
- punctuation: [
1165
- {
1166
- pattern: /^=/,
1167
- alias: "attr-equals",
1168
- },
1169
- /"|'/,
1170
- ],
1171
- },
1172
- },
1173
- },
1174
- });
1175
- },
1176
- });
1177
- Prism.languages.html = Prism.languages.markup;
1178
- Prism.languages.mathml = Prism.languages.markup;
1179
- Prism.languages.svg = Prism.languages.markup;
1180
- Prism.languages.xml = Prism.languages.extend("markup", {});
1181
- Prism.languages.ssml = Prism.languages.xml;
1182
- Prism.languages.atom = Prism.languages.xml;
1183
- Prism.languages.rss = Prism.languages.xml;
1184
- (function (Prism2) {
1185
- var string =
1186
- /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
1187
- Prism2.languages.css = {
1188
- comment: /\/\*[\s\S]*?\*\//,
1189
- atrule: {
1190
- pattern: RegExp(
1191
- "@[\\w-](?:" +
1192
- /[^;{\s"']|\s+(?!\s)/.source +
1193
- "|" +
1194
- string.source +
1195
- ")*?" +
1196
- /(?:;|(?=\s*\{))/.source,
1197
- ),
1198
- inside: {
1199
- rule: /^@[\w-]+/,
1200
- "selector-function-argument": {
1201
- pattern:
1202
- /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
1203
- lookbehind: true,
1204
- alias: "selector",
1205
- },
1206
- keyword: {
1207
- pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
1208
- lookbehind: true,
1209
- },
1210
- // See rest below
1211
- },
1212
- },
1213
- url: {
1214
- // https://drafts.csswg.org/css-values-3/#urls
1215
- pattern: RegExp(
1216
- "\\burl\\((?:" +
1217
- string.source +
1218
- "|" +
1219
- /(?:[^\\\r\n()"']|\\[\s\S])*/.source +
1220
- ")\\)",
1221
- "i",
1222
- ),
1223
- greedy: true,
1224
- inside: {
1225
- function: /^url/i,
1226
- punctuation: /^\(|\)$/,
1227
- string: {
1228
- pattern: RegExp("^" + string.source + "$"),
1229
- alias: "url",
1230
- },
1231
- },
1232
- },
1233
- selector: {
1234
- pattern: RegExp(
1235
- `(^|[{}\\s])[^{}\\s](?:[^{};"'\\s]|\\s+(?![\\s{])|` +
1236
- string.source +
1237
- ")*(?=\\s*\\{)",
1238
- ),
1239
- lookbehind: true,
1240
- },
1241
- string: {
1242
- pattern: string,
1243
- greedy: true,
1244
- },
1245
- property: {
1246
- pattern:
1247
- /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
1248
- lookbehind: true,
1249
- },
1250
- important: /!important\b/i,
1251
- function: {
1252
- pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
1253
- lookbehind: true,
1254
- },
1255
- punctuation: /[(){};:,]/,
1256
- };
1257
- Prism2.languages.css["atrule"].inside.rest = Prism2.languages.css;
1258
- var markup = Prism2.languages.markup;
1259
- if (markup) {
1260
- markup.tag.addInlined("style", "css");
1261
- markup.tag.addAttribute("style", "css");
1262
- }
1263
- })(Prism);
1264
- Prism.languages.clike = {
1265
- comment: [
1266
- {
1267
- pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
1268
- lookbehind: true,
1269
- greedy: true,
1270
- },
1271
- {
1272
- pattern: /(^|[^\\:])\/\/.*/,
1273
- lookbehind: true,
1274
- greedy: true,
1275
- },
1276
- ],
1277
- string: {
1278
- pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
1279
- greedy: true,
1280
- },
1281
- "class-name": {
1282
- pattern:
1283
- /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
1284
- lookbehind: true,
1285
- inside: {
1286
- punctuation: /[.\\]/,
1287
- },
1288
- },
1289
- keyword:
1290
- /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
1291
- boolean: /\b(?:false|true)\b/,
1292
- function: /\b\w+(?=\()/,
1293
- number: /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
1294
- operator: /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
1295
- punctuation: /[{}[\];(),.:]/,
1296
- };
1297
- Prism.languages.javascript = Prism.languages.extend("clike", {
1298
- "class-name": [
1299
- Prism.languages.clike["class-name"],
1300
- {
1301
- pattern:
1302
- /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
1303
- lookbehind: true,
1304
- },
1305
- ],
1306
- keyword: [
1307
- {
1308
- pattern: /((?:^|\})\s*)catch\b/,
1309
- lookbehind: true,
1310
- },
1311
- {
1312
- pattern:
1313
- /(^|[^.]|\.\.\.\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/,
1314
- lookbehind: true,
1315
- },
1316
- ],
1317
- // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
1318
- function:
1319
- /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
1320
- number: {
1321
- pattern: RegExp(
1322
- /(^|[^\w$])/.source +
1323
- "(?:" + // constant
1324
- (/NaN|Infinity/.source +
1325
- "|" + // binary integer
1326
- /0[bB][01]+(?:_[01]+)*n?/.source +
1327
- "|" + // octal integer
1328
- /0[oO][0-7]+(?:_[0-7]+)*n?/.source +
1329
- "|" + // hexadecimal integer
1330
- /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source +
1331
- "|" + // decimal bigint
1332
- /\d+(?:_\d+)*n/.source +
1333
- "|" + // decimal number (integer or float) but no bigint
1334
- /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/
1335
- .source) +
1336
- ")" +
1337
- /(?![\w$])/.source,
1338
- ),
1339
- lookbehind: true,
1340
- },
1341
- operator:
1342
- /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/,
1343
- });
1344
- Prism.languages.javascript["class-name"][0].pattern =
1345
- /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
1346
- Prism.languages.insertBefore("javascript", "keyword", {
1347
- regex: {
1348
- pattern: RegExp(
1349
- // lookbehind
1350
- // eslint-disable-next-line regexp/no-dupe-characters-character-class
1351
- /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source + // Regex pattern:
1352
- // There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
1353
- // classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
1354
- // with the only syntax, so we have to define 2 different regex patterns.
1355
- /\//.source +
1356
- "(?:" +
1357
- /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/
1358
- .source +
1359
- "|" + // `v` flag syntax. This supports 3 levels of nested character classes.
1360
- /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/
1361
- .source +
1362
- ")" + // lookahead
1363
- /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/
1364
- .source,
1365
- ),
1366
- lookbehind: true,
1367
- greedy: true,
1368
- inside: {
1369
- "regex-source": {
1370
- pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
1371
- lookbehind: true,
1372
- alias: "language-regex",
1373
- inside: Prism.languages.regex,
1374
- },
1375
- "regex-delimiter": /^\/|\/$/,
1376
- "regex-flags": /^[a-z]+$/,
1377
- },
1378
- },
1379
- // This must be declared before keyword because we use "function" inside the look-forward
1380
- "function-variable": {
1381
- pattern:
1382
- /#?(?!\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*=>))/,
1383
- alias: "function",
1384
- },
1385
- parameter: [
1386
- {
1387
- pattern:
1388
- /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
1389
- lookbehind: true,
1390
- inside: Prism.languages.javascript,
1391
- },
1392
- {
1393
- pattern:
1394
- /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
1395
- lookbehind: true,
1396
- inside: Prism.languages.javascript,
1397
- },
1398
- {
1399
- pattern:
1400
- /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
1401
- lookbehind: true,
1402
- inside: Prism.languages.javascript,
1403
- },
1404
- {
1405
- pattern:
1406
- /((?:\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*\{)/,
1407
- lookbehind: true,
1408
- inside: Prism.languages.javascript,
1409
- },
1410
- ],
1411
- constant: /\b[A-Z](?:[A-Z_]|\dx?)*\b/,
1412
- });
1413
- Prism.languages.insertBefore("javascript", "string", {
1414
- hashbang: {
1415
- pattern: /^#!.*/,
1416
- greedy: true,
1417
- alias: "comment",
1418
- },
1419
- "template-string": {
1420
- pattern:
1421
- /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
1422
- greedy: true,
1423
- inside: {
1424
- "template-punctuation": {
1425
- pattern: /^`|`$/,
1426
- alias: "string",
1427
- },
1428
- interpolation: {
1429
- pattern:
1430
- /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
1431
- lookbehind: true,
1432
- inside: {
1433
- "interpolation-punctuation": {
1434
- pattern: /^\$\{|\}$/,
1435
- alias: "punctuation",
1436
- },
1437
- rest: Prism.languages.javascript,
1438
- },
1439
- },
1440
- string: /[\s\S]+/,
1441
- },
1442
- },
1443
- "string-property": {
1444
- pattern:
1445
- /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
1446
- lookbehind: true,
1447
- greedy: true,
1448
- alias: "property",
1449
- },
1450
- });
1451
- Prism.languages.insertBefore("javascript", "operator", {
1452
- "literal-property": {
1453
- pattern:
1454
- /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
1455
- lookbehind: true,
1456
- alias: "property",
1457
- },
1458
- });
1459
- if (Prism.languages.markup) {
1460
- Prism.languages.markup.tag.addInlined("script", "javascript");
1461
- Prism.languages.markup.tag.addAttribute(
1462
- /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)/
1463
- .source,
1464
- "javascript",
1465
- );
1466
- }
1467
- Prism.languages.js = Prism.languages.javascript;
1468
- (function () {
1469
- if (typeof Prism === "undefined" || typeof document === "undefined") {
1470
- return;
1471
- }
1472
- if (!Element.prototype.matches) {
1473
- Element.prototype.matches =
1474
- Element.prototype.msMatchesSelector ||
1475
- Element.prototype.webkitMatchesSelector;
1476
- }
1477
- var LOADING_MESSAGE = "Loading…";
1478
- var FAILURE_MESSAGE = function (status, message) {
1479
- return "✖ Error " + status + " while fetching file: " + message;
1480
- };
1481
- var FAILURE_EMPTY_MESSAGE = "✖ Error: File does not exist or is empty";
1482
- var EXTENSIONS = {
1483
- js: "javascript",
1484
- py: "python",
1485
- rb: "ruby",
1486
- ps1: "powershell",
1487
- psm1: "powershell",
1488
- sh: "bash",
1489
- bat: "batch",
1490
- h: "c",
1491
- tex: "latex",
1492
- };
1493
- var STATUS_ATTR = "data-src-status";
1494
- var STATUS_LOADING = "loading";
1495
- var STATUS_LOADED = "loaded";
1496
- var STATUS_FAILED = "failed";
1497
- var SELECTOR =
1498
- "pre[data-src]:not([" +
1499
- STATUS_ATTR +
1500
- '="' +
1501
- STATUS_LOADED +
1502
- '"]):not([' +
1503
- STATUS_ATTR +
1504
- '="' +
1505
- STATUS_LOADING +
1506
- '"])';
1507
- function loadFile(src, success, error) {
1508
- var xhr = new XMLHttpRequest();
1509
- xhr.open("GET", src, true);
1510
- xhr.onreadystatechange = function () {
1511
- if (xhr.readyState == 4) {
1512
- if (xhr.status < 400 && xhr.responseText) {
1513
- success(xhr.responseText);
1514
- } else {
1515
- if (xhr.status >= 400) {
1516
- error(FAILURE_MESSAGE(xhr.status, xhr.statusText));
1517
- } else {
1518
- error(FAILURE_EMPTY_MESSAGE);
1519
- }
1520
- }
1521
- }
1522
- };
1523
- xhr.send(null);
1524
- }
1525
- function parseRange(range) {
1526
- var m = /^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(range || "");
1527
- if (m) {
1528
- var start = Number(m[1]);
1529
- var comma = m[2];
1530
- var end = m[3];
1531
- if (!comma) {
1532
- return [start, start];
1533
- }
1534
- if (!end) {
1535
- return [start, void 0];
1536
- }
1537
- return [start, Number(end)];
1538
- }
1539
- return void 0;
1540
- }
1541
- Prism.hooks.add("before-highlightall", function (env) {
1542
- env.selector += ", " + SELECTOR;
1543
- });
1544
- Prism.hooks.add("before-sanity-check", function (env) {
1545
- var pre =
1546
- /** @type {HTMLPreElement} */
1547
- env.element;
1548
- if (pre.matches(SELECTOR)) {
1549
- env.code = "";
1550
- pre.setAttribute(STATUS_ATTR, STATUS_LOADING);
1551
- var code = pre.appendChild(document.createElement("CODE"));
1552
- code.textContent = LOADING_MESSAGE;
1553
- var src = pre.getAttribute("data-src");
1554
- var language = env.language;
1555
- if (language === "none") {
1556
- var extension = (/\.(\w+)$/.exec(src) || [, "none"])[1];
1557
- language = EXTENSIONS[extension] || extension;
1558
- }
1559
- Prism.util.setLanguage(code, language);
1560
- Prism.util.setLanguage(pre, language);
1561
- var autoloader = Prism.plugins.autoloader;
1562
- if (autoloader) {
1563
- autoloader.loadLanguages(language);
1564
- }
1565
- loadFile(
1566
- src,
1567
- function (text) {
1568
- pre.setAttribute(STATUS_ATTR, STATUS_LOADED);
1569
- var range = parseRange(pre.getAttribute("data-range"));
1570
- if (range) {
1571
- var lines = text.split(/\r\n?|\n/g);
1572
- var start = range[0];
1573
- var end = range[1] == null ? lines.length : range[1];
1574
- if (start < 0) {
1575
- start += lines.length;
1576
- }
1577
- start = Math.max(0, Math.min(start - 1, lines.length));
1578
- if (end < 0) {
1579
- end += lines.length;
1580
- }
1581
- end = Math.max(0, Math.min(end, lines.length));
1582
- text = lines.slice(start, end).join("\n");
1583
- if (!pre.hasAttribute("data-start")) {
1584
- pre.setAttribute("data-start", String(start + 1));
1585
- }
1586
- }
1587
- code.textContent = text;
1588
- Prism.highlightElement(code);
1589
- },
1590
- function (error) {
1591
- pre.setAttribute(STATUS_ATTR, STATUS_FAILED);
1592
- code.textContent = error;
1593
- },
1594
- );
1595
- }
1596
- });
1597
- Prism.plugins.fileHighlight = {
1598
- /**
1599
- * Executes the File Highlight plugin for all matching `pre` elements under the given container.
1600
- *
1601
- * Note: Elements which are already loaded or currently loading will not be touched by this method.
1602
- *
1603
- * @param {ParentNode} [container=document]
1604
- */
1605
- highlight: function highlight(container) {
1606
- var elements = (container || document).querySelectorAll(SELECTOR);
1607
- for (var i = 0, element; (element = elements[i++]); ) {
1608
- Prism.highlightElement(element);
1609
- }
1610
- },
1611
- };
1612
- var logged = false;
1613
- Prism.fileHighlight = function () {
1614
- if (!logged) {
1615
- console.warn(
1616
- "Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead.",
1617
- );
1618
- logged = true;
1619
- }
1620
- Prism.plugins.fileHighlight.highlight.apply(this, arguments);
1621
- };
1622
- })();
1623
- },
1624
- });
1625
- export default require_prism();
1626
- /*! Bundled license information:
1627
-
1628
- prismjs/prism.js:
1629
- (**
1630
- * Prism: Lightweight, robust, elegant syntax highlighting
1631
- *
1632
- * @license MIT <https://opensource.org/licenses/MIT>
1633
- * @author Lea Verou <https://lea.verou.me>
1634
- * @namespace
1635
- * @public
1636
- *)
1637
- */
1638
- //# sourceMappingURL=prismjs.js.map