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