@redis-ui/components 51.26.0 → 51.28.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 (187) hide show
  1. package/dist/Button/CopyToClipboardButton/CopyToClipboardButton.cjs +17 -8
  2. package/dist/Button/CopyToClipboardButton/CopyToClipboardButton.js +17 -8
  3. package/dist/Button/CopyToClipboardButton/CopyToClipboardButton.types.d.ts +5 -1
  4. package/dist/CodeBlock/CodeBlock.cjs +29 -14
  5. package/dist/CodeBlock/CodeBlock.js +29 -14
  6. package/dist/CodeBlock/CodeBlock.style.d.ts +4 -3
  7. package/dist/CodeBlock/CodeBlock.types.cjs +7 -0
  8. package/dist/CodeBlock/CodeBlock.types.d.ts +4 -0
  9. package/dist/CodeBlock/CodeBlock.types.js +7 -1
  10. package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.cjs +29 -0
  11. package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.constants.cjs +34 -0
  12. package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.constants.d.ts +25 -0
  13. package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.constants.js +32 -0
  14. package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.d.ts +6 -0
  15. package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.js +29 -0
  16. package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.types.d.ts +10 -0
  17. package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.types.js +1 -0
  18. package/dist/Inputs/Input/Input.cjs +9 -2
  19. package/dist/Inputs/Input/Input.d.ts +4 -1
  20. package/dist/Inputs/Input/Input.js +9 -2
  21. package/dist/Inputs/Input/Input.types.d.ts +5 -1
  22. package/dist/Inputs/PasswordInput/components/Compose/Compose.types.d.ts +1 -1
  23. package/dist/Inputs/TextArea/TextArea.cjs +16 -6
  24. package/dist/Inputs/TextArea/TextArea.d.ts +3 -1
  25. package/dist/Inputs/TextArea/TextArea.js +16 -6
  26. package/dist/Inputs/TextArea/TextArea.types.d.ts +4 -1
  27. package/dist/Inputs/TextArea/components/CopyButton/CopyButton.cjs +7 -0
  28. package/dist/Inputs/TextArea/components/CopyButton/CopyButton.d.ts +2 -0
  29. package/dist/Inputs/TextArea/components/CopyButton/CopyButton.js +7 -0
  30. package/dist/Inputs/TextArea/components/CopyButton/CopyButton.style.cjs +17 -0
  31. package/dist/Inputs/TextArea/components/CopyButton/CopyButton.style.d.ts +1 -0
  32. package/dist/Inputs/TextArea/components/CopyButton/CopyButton.style.js +15 -0
  33. package/dist/Inputs/TextArea/components/TextAreaTag/TextAreaTag.cjs +3 -1
  34. package/dist/Inputs/TextArea/components/TextAreaTag/TextAreaTag.js +4 -2
  35. package/dist/Inputs/TextArea/components/TextAreaTag/TextAreaTag.style.cjs +8 -1
  36. package/dist/Inputs/TextArea/components/TextAreaTag/TextAreaTag.style.js +8 -1
  37. package/dist/Inputs/components/Compose/CommonCompose.cjs +23 -18
  38. package/dist/Inputs/components/Compose/CommonCompose.d.ts +1 -1
  39. package/dist/Inputs/components/Compose/CommonCompose.js +24 -19
  40. package/dist/Inputs/components/Compose/CommonCompose.types.d.ts +2 -0
  41. package/dist/Inputs/components/Compose/Compose.style.cjs +7 -0
  42. package/dist/Inputs/components/Compose/Compose.style.js +7 -0
  43. package/dist/Inputs/components/Compose/NumericCompose.types.d.ts +1 -1
  44. package/dist/Inputs/components/CopyButton/CopyButton.cjs +15 -0
  45. package/dist/Inputs/components/CopyButton/CopyButton.d.ts +2 -0
  46. package/dist/Inputs/components/CopyButton/CopyButton.js +15 -0
  47. package/dist/Inputs/components/CopyButton/CopyButton.style.cjs +17 -0
  48. package/dist/Inputs/components/CopyButton/CopyButton.style.d.ts +1 -0
  49. package/dist/Inputs/components/CopyButton/CopyButton.style.js +15 -0
  50. package/dist/Inputs/components/CopyButton/CopyButton.types.d.ts +6 -0
  51. package/dist/Inputs/components/CopyButton/CopyButton.types.js +1 -0
  52. package/dist/Inputs/components/InputTag/InputTag.cjs +3 -1
  53. package/dist/Inputs/components/InputTag/InputTag.js +4 -2
  54. package/dist/Inputs/components/InputTag/InputTag.style.cjs +1 -1
  55. package/dist/Inputs/components/InputTag/InputTag.style.js +1 -1
  56. package/dist/index.cjs +1 -0
  57. package/dist/index.js +2 -2
  58. package/dist/node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.cjs +8 -0
  59. package/dist/node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js +8 -0
  60. package/dist/node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.cjs +7 -0
  61. package/dist/node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js +7 -0
  62. package/dist/node_modules/@babel/runtime/helpers/esm/defineProperty.cjs +12 -0
  63. package/dist/node_modules/@babel/runtime/helpers/esm/defineProperty.js +12 -0
  64. package/dist/node_modules/@babel/runtime/helpers/esm/extends.cjs +17 -0
  65. package/dist/node_modules/@babel/runtime/helpers/esm/extends.js +12 -0
  66. package/dist/node_modules/@babel/runtime/helpers/esm/iterableToArray.cjs +6 -0
  67. package/dist/node_modules/@babel/runtime/helpers/esm/iterableToArray.js +6 -0
  68. package/dist/node_modules/@babel/runtime/helpers/esm/nonIterableSpread.cjs +6 -0
  69. package/dist/node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js +6 -0
  70. package/dist/node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.cjs +13 -0
  71. package/dist/node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js +13 -0
  72. package/dist/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.cjs +12 -0
  73. package/dist/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +12 -0
  74. package/dist/node_modules/@babel/runtime/helpers/esm/toConsumableArray.cjs +10 -0
  75. package/dist/node_modules/@babel/runtime/helpers/esm/toConsumableArray.js +10 -0
  76. package/dist/node_modules/@babel/runtime/helpers/esm/toPrimitive.cjs +14 -0
  77. package/dist/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +14 -0
  78. package/dist/node_modules/@babel/runtime/helpers/esm/toPropertyKey.cjs +9 -0
  79. package/dist/node_modules/@babel/runtime/helpers/esm/toPropertyKey.js +9 -0
  80. package/dist/node_modules/@babel/runtime/helpers/esm/typeof.cjs +16 -0
  81. package/dist/node_modules/@babel/runtime/helpers/esm/typeof.js +11 -0
  82. package/dist/node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.cjs +11 -0
  83. package/dist/node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js +11 -0
  84. package/dist/node_modules/character-entities-legacy/index.cjs +116 -0
  85. package/dist/node_modules/character-entities-legacy/index.js +116 -0
  86. package/dist/node_modules/character-reference-invalid/index.cjs +38 -0
  87. package/dist/node_modules/character-reference-invalid/index.js +38 -0
  88. package/dist/node_modules/comma-separated-tokens/index.cjs +43 -0
  89. package/dist/node_modules/comma-separated-tokens/index.js +43 -0
  90. package/dist/node_modules/decode-named-character-reference/index.dom.cjs +15 -0
  91. package/dist/node_modules/decode-named-character-reference/index.dom.js +15 -0
  92. package/dist/node_modules/hast-util-parse-selector/lib/index.cjs +76 -0
  93. package/dist/node_modules/hast-util-parse-selector/lib/index.js +76 -0
  94. package/dist/node_modules/hastscript/lib/create-h.cjs +262 -0
  95. package/dist/node_modules/hastscript/lib/create-h.js +262 -0
  96. package/dist/node_modules/hastscript/lib/index.cjs +21 -0
  97. package/dist/node_modules/hastscript/lib/index.js +21 -0
  98. package/dist/node_modules/hastscript/lib/svg-case-sensitive-tag-names.cjs +49 -0
  99. package/dist/node_modules/hastscript/lib/svg-case-sensitive-tag-names.js +49 -0
  100. package/dist/node_modules/is-alphabetical/index.cjs +14 -0
  101. package/dist/node_modules/is-alphabetical/index.js +14 -0
  102. package/dist/node_modules/is-alphanumerical/index.cjs +15 -0
  103. package/dist/node_modules/is-alphanumerical/index.js +15 -0
  104. package/dist/node_modules/is-decimal/index.cjs +14 -0
  105. package/dist/node_modules/is-decimal/index.js +14 -0
  106. package/dist/node_modules/is-hexadecimal/index.cjs +14 -0
  107. package/dist/node_modules/is-hexadecimal/index.js +14 -0
  108. package/dist/node_modules/parse-entities/lib/index.cjs +232 -0
  109. package/dist/node_modules/parse-entities/lib/index.js +232 -0
  110. package/dist/node_modules/property-information/index.cjs +27 -0
  111. package/dist/node_modules/property-information/index.js +26 -0
  112. package/dist/node_modules/property-information/lib/aria.cjs +60 -0
  113. package/dist/node_modules/property-information/lib/aria.js +61 -0
  114. package/dist/node_modules/property-information/lib/find.cjs +81 -0
  115. package/dist/node_modules/property-information/lib/find.js +81 -0
  116. package/dist/node_modules/property-information/lib/html.cjs +326 -0
  117. package/dist/node_modules/property-information/lib/html.js +326 -0
  118. package/dist/node_modules/property-information/lib/normalize.cjs +15 -0
  119. package/dist/node_modules/property-information/lib/normalize.js +15 -0
  120. package/dist/node_modules/property-information/lib/svg.cjs +564 -0
  121. package/dist/node_modules/property-information/lib/svg.js +564 -0
  122. package/dist/node_modules/property-information/lib/util/case-insensitive-transform.cjs +15 -0
  123. package/dist/node_modules/property-information/lib/util/case-insensitive-transform.js +15 -0
  124. package/dist/node_modules/property-information/lib/util/case-sensitive-transform.cjs +14 -0
  125. package/dist/node_modules/property-information/lib/util/case-sensitive-transform.js +14 -0
  126. package/dist/node_modules/property-information/lib/util/create.cjs +53 -0
  127. package/dist/node_modules/property-information/lib/util/create.js +53 -0
  128. package/dist/node_modules/property-information/lib/util/defined-info.cjs +49 -0
  129. package/dist/node_modules/property-information/lib/util/defined-info.js +49 -0
  130. package/dist/node_modules/property-information/lib/util/info.cjs +33 -0
  131. package/dist/node_modules/property-information/lib/util/info.js +33 -0
  132. package/dist/node_modules/property-information/lib/util/merge.cjs +26 -0
  133. package/dist/node_modules/property-information/lib/util/merge.js +26 -0
  134. package/dist/node_modules/property-information/lib/util/schema.cjs +27 -0
  135. package/dist/node_modules/property-information/lib/util/schema.js +27 -0
  136. package/dist/node_modules/property-information/lib/util/types.cjs +35 -0
  137. package/dist/node_modules/property-information/lib/util/types.js +24 -0
  138. package/dist/node_modules/property-information/lib/xlink.cjs +18 -0
  139. package/dist/node_modules/property-information/lib/xlink.js +19 -0
  140. package/dist/node_modules/property-information/lib/xml.cjs +14 -0
  141. package/dist/node_modules/property-information/lib/xml.js +15 -0
  142. package/dist/node_modules/property-information/lib/xmlns.cjs +14 -0
  143. package/dist/node_modules/property-information/lib/xmlns.js +14 -0
  144. package/dist/node_modules/react-syntax-highlighter/dist/esm/checkForListedLanguage.cjs +6 -0
  145. package/dist/node_modules/react-syntax-highlighter/dist/esm/checkForListedLanguage.js +6 -0
  146. package/dist/node_modules/react-syntax-highlighter/dist/esm/create-element.cjs +183 -0
  147. package/dist/node_modules/react-syntax-highlighter/dist/esm/create-element.js +181 -0
  148. package/dist/node_modules/react-syntax-highlighter/dist/esm/highlight.cjs +308 -0
  149. package/dist/node_modules/react-syntax-highlighter/dist/esm/highlight.js +306 -0
  150. package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/bash.cjs +4 -0
  151. package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/bash.js +5 -0
  152. package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/json.cjs +4 -0
  153. package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/json.js +5 -0
  154. package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/python.cjs +4 -0
  155. package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/python.js +5 -0
  156. package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/typescript.cjs +4 -0
  157. package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/typescript.js +5 -0
  158. package/dist/node_modules/react-syntax-highlighter/dist/esm/prism-light.cjs +12 -0
  159. package/dist/node_modules/react-syntax-highlighter/dist/esm/prism-light.js +12 -0
  160. package/dist/node_modules/react-syntax-highlighter/dist/esm/styles/prism/vs.cjs +121 -0
  161. package/dist/node_modules/react-syntax-highlighter/dist/esm/styles/prism/vs.js +121 -0
  162. package/dist/node_modules/react-syntax-highlighter/dist/esm/styles/prism/vsc-dark-plus.cjs +147 -0
  163. package/dist/node_modules/react-syntax-highlighter/dist/esm/styles/prism/vsc-dark-plus.js +147 -0
  164. package/dist/node_modules/refractor/lang/bash.cjs +190 -0
  165. package/dist/node_modules/refractor/lang/bash.js +190 -0
  166. package/dist/node_modules/refractor/lang/clike.cjs +37 -0
  167. package/dist/node_modules/refractor/lang/clike.js +37 -0
  168. package/dist/node_modules/refractor/lang/javascript.cjs +122 -0
  169. package/dist/node_modules/refractor/lang/javascript.js +122 -0
  170. package/dist/node_modules/refractor/lang/json.cjs +36 -0
  171. package/dist/node_modules/refractor/lang/json.js +36 -0
  172. package/dist/node_modules/refractor/lang/python.cjs +71 -0
  173. package/dist/node_modules/refractor/lang/python.js +71 -0
  174. package/dist/node_modules/refractor/lang/typescript.cjs +55 -0
  175. package/dist/node_modules/refractor/lang/typescript.js +55 -0
  176. package/dist/node_modules/refractor/lib/core.cjs +214 -0
  177. package/dist/node_modules/refractor/lib/core.js +214 -0
  178. package/dist/node_modules/refractor/lib/prism-core.cjs +595 -0
  179. package/dist/node_modules/refractor/lib/prism-core.js +595 -0
  180. package/dist/node_modules/space-separated-tokens/index.cjs +15 -0
  181. package/dist/node_modules/space-separated-tokens/index.js +15 -0
  182. package/package.json +4 -2
  183. package/skills/redis-ui-components/references/CodeBlock.md +23 -5
  184. package/skills/redis-ui-components/references/CopyToClipboardButton.md +23 -1
  185. package/skills/redis-ui-components/references/Input.md +39 -2
  186. package/skills/redis-ui-components/references/SearchInput.md +1 -1
  187. package/skills/redis-ui-components/references/TextArea.md +19 -1
@@ -0,0 +1,595 @@
1
+ //#region ../../node_modules/refractor/lib/prism-core.js
2
+ var uniqueId = 0;
3
+ var plainTextGrammar = {};
4
+ var _ = {
5
+ /**
6
+ * A namespace for utility methods.
7
+ *
8
+ * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
9
+ * change or disappear at any time.
10
+ *
11
+ * @namespace
12
+ * @memberof Prism
13
+ */
14
+ util: {
15
+ /**
16
+ * Returns the name of the type of the given value.
17
+ *
18
+ * @param {any} o
19
+ * @returns {string}
20
+ * @example
21
+ * type(null) === 'Null'
22
+ * type(undefined) === 'Undefined'
23
+ * type(123) === 'Number'
24
+ * type('foo') === 'String'
25
+ * type(true) === 'Boolean'
26
+ * type([1, 2]) === 'Array'
27
+ * type({}) === 'Object'
28
+ * type(String) === 'Function'
29
+ * type(/abc+/) === 'RegExp'
30
+ */
31
+ type: function(o) {
32
+ return Object.prototype.toString.call(o).slice(8, -1);
33
+ },
34
+ /**
35
+ * Returns a unique number for the given object. Later calls will still return the same number.
36
+ *
37
+ * @param {Object} obj
38
+ * @returns {number}
39
+ */
40
+ objId: function(obj) {
41
+ if (!obj["__id"]) Object.defineProperty(obj, "__id", { value: ++uniqueId });
42
+ return obj["__id"];
43
+ },
44
+ /**
45
+ * Creates a deep clone of the given object.
46
+ *
47
+ * The main intended use of this function is to clone language definitions.
48
+ *
49
+ * @param {T} o
50
+ * @param {Record<number, any>} [visited]
51
+ * @returns {T}
52
+ * @template T
53
+ */
54
+ clone: function deepClone(o, visited) {
55
+ visited = visited || {};
56
+ var clone;
57
+ var id;
58
+ switch (_.util.type(o)) {
59
+ case "Object":
60
+ id = _.util.objId(o);
61
+ if (visited[id]) return visited[id];
62
+ clone = {};
63
+ visited[id] = clone;
64
+ for (var key in o) if (o.hasOwnProperty(key)) clone[key] = deepClone(o[key], visited);
65
+ return clone;
66
+ case "Array":
67
+ id = _.util.objId(o);
68
+ if (visited[id]) return visited[id];
69
+ clone = [];
70
+ visited[id] = clone;
71
+ /** @type {Array} */ o.forEach(function(v, i) {
72
+ clone[i] = deepClone(v, visited);
73
+ });
74
+ return clone;
75
+ default: return o;
76
+ }
77
+ }
78
+ },
79
+ /**
80
+ * This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
81
+ *
82
+ * @namespace
83
+ * @memberof Prism
84
+ * @public
85
+ */
86
+ languages: {
87
+ /**
88
+ * The grammar for plain, unformatted text.
89
+ */
90
+ plain: plainTextGrammar,
91
+ plaintext: plainTextGrammar,
92
+ text: plainTextGrammar,
93
+ txt: plainTextGrammar,
94
+ /**
95
+ * Creates a deep copy of the language with the given id and appends the given tokens.
96
+ *
97
+ * If a token in `redef` also appears in the copied language, then the existing token in the copied language
98
+ * will be overwritten at its original position.
99
+ *
100
+ * ## Best practices
101
+ *
102
+ * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
103
+ * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
104
+ * understand the language definition because, normally, the order of tokens matters in Prism grammars.
105
+ *
106
+ * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
107
+ * Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
108
+ *
109
+ * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
110
+ * @param {Grammar} redef The new tokens to append.
111
+ * @returns {Grammar} The new language created.
112
+ * @public
113
+ * @example
114
+ * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
115
+ * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
116
+ * // at its original position
117
+ * 'comment': { ... },
118
+ * // CSS doesn't have a 'color' token, so this token will be appended
119
+ * 'color': /\b(?:red|green|blue)\b/
120
+ * });
121
+ */
122
+ extend: function(id, redef) {
123
+ var lang = _.util.clone(_.languages[id]);
124
+ for (var key in redef) lang[key] = redef[key];
125
+ return lang;
126
+ },
127
+ /**
128
+ * Inserts tokens _before_ another token in a language definition or any other grammar.
129
+ *
130
+ * ## Usage
131
+ *
132
+ * This helper method makes it easy to modify existing languages. For example, the CSS language definition
133
+ * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
134
+ * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
135
+ * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
136
+ * this:
137
+ *
138
+ * ```js
139
+ * Prism.languages.markup.style = {
140
+ * // token
141
+ * };
142
+ * ```
143
+ *
144
+ * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
145
+ * before existing tokens. For the CSS example above, you would use it like this:
146
+ *
147
+ * ```js
148
+ * Prism.languages.insertBefore('markup', 'cdata', {
149
+ * 'style': {
150
+ * // token
151
+ * }
152
+ * });
153
+ * ```
154
+ *
155
+ * ## Special cases
156
+ *
157
+ * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
158
+ * will be ignored.
159
+ *
160
+ * This behavior can be used to insert tokens after `before`:
161
+ *
162
+ * ```js
163
+ * Prism.languages.insertBefore('markup', 'comment', {
164
+ * 'comment': Prism.languages.markup.comment,
165
+ * // tokens after 'comment'
166
+ * });
167
+ * ```
168
+ *
169
+ * ## Limitations
170
+ *
171
+ * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
172
+ * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
173
+ * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
174
+ * deleting properties which is necessary to insert at arbitrary positions.
175
+ *
176
+ * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
177
+ * Instead, it will create a new object and replace all references to the target object with the new one. This
178
+ * can be done without temporarily deleting properties, so the iteration order is well-defined.
179
+ *
180
+ * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
181
+ * you hold the target object in a variable, then the value of the variable will not change.
182
+ *
183
+ * ```js
184
+ * var oldMarkup = Prism.languages.markup;
185
+ * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
186
+ *
187
+ * assert(oldMarkup !== Prism.languages.markup);
188
+ * assert(newMarkup === Prism.languages.markup);
189
+ * ```
190
+ *
191
+ * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
192
+ * object to be modified.
193
+ * @param {string} before The key to insert before.
194
+ * @param {Grammar} insert An object containing the key-value pairs to be inserted.
195
+ * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
196
+ * object to be modified.
197
+ *
198
+ * Defaults to `Prism.languages`.
199
+ * @returns {Grammar} The new grammar object.
200
+ * @public
201
+ */
202
+ insertBefore: function(inside, before, insert, root) {
203
+ root = root || _.languages;
204
+ var grammar = root[inside];
205
+ /** @type {Grammar} */
206
+ var ret = {};
207
+ for (var token in grammar) if (grammar.hasOwnProperty(token)) {
208
+ if (token == before) {
209
+ for (var newToken in insert) if (insert.hasOwnProperty(newToken)) ret[newToken] = insert[newToken];
210
+ }
211
+ if (!insert.hasOwnProperty(token)) ret[token] = grammar[token];
212
+ }
213
+ var old = root[inside];
214
+ root[inside] = ret;
215
+ _.languages.DFS(_.languages, function(key, value) {
216
+ if (value === old && key != inside) this[key] = ret;
217
+ });
218
+ return ret;
219
+ },
220
+ DFS: function DFS(o, callback, type, visited) {
221
+ visited = visited || {};
222
+ var objId = _.util.objId;
223
+ for (var i in o) if (o.hasOwnProperty(i)) {
224
+ callback.call(o, i, o[i], type || i);
225
+ var property = o[i];
226
+ var propertyType = _.util.type(property);
227
+ if (propertyType === "Object" && !visited[objId(property)]) {
228
+ visited[objId(property)] = true;
229
+ DFS(property, callback, null, visited);
230
+ } else if (propertyType === "Array" && !visited[objId(property)]) {
231
+ visited[objId(property)] = true;
232
+ DFS(property, callback, i, visited);
233
+ }
234
+ }
235
+ }
236
+ },
237
+ plugins: {},
238
+ /**
239
+ * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
240
+ * and the language definitions to use, and returns a string with the HTML produced.
241
+ *
242
+ * The following hooks will be run:
243
+ * 1. `before-tokenize`
244
+ * 2. `after-tokenize`
245
+ * 3. `wrap`: On each {@link Token}.
246
+ *
247
+ * @param {string} text A string with the code to be highlighted.
248
+ * @param {Grammar} grammar An object containing the tokens to use.
249
+ *
250
+ * Usually a language definition like `Prism.languages.markup`.
251
+ * @param {string} language The name of the language definition passed to `grammar`.
252
+ * @returns {string} The highlighted HTML.
253
+ * @memberof Prism
254
+ * @public
255
+ * @example
256
+ * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
257
+ */
258
+ highlight: function(text, grammar, language) {
259
+ var env = {
260
+ code: text,
261
+ grammar,
262
+ language
263
+ };
264
+ _.hooks.run("before-tokenize", env);
265
+ if (!env.grammar) throw new Error("The language \"" + env.language + "\" has no grammar.");
266
+ env.tokens = _.tokenize(env.code, env.grammar);
267
+ _.hooks.run("after-tokenize", env);
268
+ return Token.stringify(_.util.encode(env.tokens), env.language);
269
+ },
270
+ /**
271
+ * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
272
+ * and the language definitions to use, and returns an array with the tokenized code.
273
+ *
274
+ * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
275
+ *
276
+ * This method could be useful in other contexts as well, as a very crude parser.
277
+ *
278
+ * @param {string} text A string with the code to be highlighted.
279
+ * @param {Grammar} grammar An object containing the tokens to use.
280
+ *
281
+ * Usually a language definition like `Prism.languages.markup`.
282
+ * @returns {TokenStream} An array of strings and tokens, a token stream.
283
+ * @memberof Prism
284
+ * @public
285
+ * @example
286
+ * let code = `var foo = 0;`;
287
+ * let tokens = Prism.tokenize(code, Prism.languages.javascript);
288
+ * tokens.forEach(token => {
289
+ * if (token instanceof Prism.Token && token.type === 'number') {
290
+ * console.log(`Found numeric literal: ${token.content}`);
291
+ * }
292
+ * });
293
+ */
294
+ tokenize: function(text, grammar) {
295
+ var rest = grammar.rest;
296
+ if (rest) {
297
+ for (var token in rest) grammar[token] = rest[token];
298
+ delete grammar.rest;
299
+ }
300
+ var tokenList = new LinkedList();
301
+ addAfter(tokenList, tokenList.head, text);
302
+ matchGrammar(text, tokenList, grammar, tokenList.head, 0);
303
+ return toArray(tokenList);
304
+ },
305
+ /**
306
+ * @namespace
307
+ * @memberof Prism
308
+ * @public
309
+ */
310
+ hooks: {
311
+ all: {},
312
+ /**
313
+ * Adds the given callback to the list of callbacks for the given hook.
314
+ *
315
+ * The callback will be invoked when the hook it is registered for is run.
316
+ * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
317
+ *
318
+ * One callback function can be registered to multiple hooks and the same hook multiple times.
319
+ *
320
+ * @param {string} name The name of the hook.
321
+ * @param {HookCallback} callback The callback function which is given environment variables.
322
+ * @public
323
+ */
324
+ add: function(name, callback) {
325
+ var hooks = _.hooks.all;
326
+ hooks[name] = hooks[name] || [];
327
+ hooks[name].push(callback);
328
+ },
329
+ /**
330
+ * Runs a hook invoking all registered callbacks with the given environment variables.
331
+ *
332
+ * Callbacks will be invoked synchronously and in the order in which they were registered.
333
+ *
334
+ * @param {string} name The name of the hook.
335
+ * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
336
+ * @public
337
+ */
338
+ run: function(name, env) {
339
+ var callbacks = _.hooks.all[name];
340
+ if (!callbacks || !callbacks.length) return;
341
+ for (var i = 0, callback; callback = callbacks[i++];) callback(env);
342
+ }
343
+ },
344
+ Token
345
+ };
346
+ /**
347
+ * Creates a new token.
348
+ *
349
+ * @param {string} type See {@link Token#type type}
350
+ * @param {string | TokenStream} content See {@link Token#content content}
351
+ * @param {string|string[]} [alias] The alias(es) of the token.
352
+ * @param {string} [matchedStr=""] A copy of the full string this token was created from.
353
+ * @class
354
+ * @global
355
+ * @public
356
+ */
357
+ function Token(type, content, alias, matchedStr) {
358
+ /**
359
+ * The type of the token.
360
+ *
361
+ * This is usually the key of a pattern in a {@link Grammar}.
362
+ *
363
+ * @type {string}
364
+ * @see GrammarToken
365
+ * @public
366
+ */
367
+ this.type = type;
368
+ /**
369
+ * The strings or tokens contained by this token.
370
+ *
371
+ * This will be a token stream if the pattern matched also defined an `inside` grammar.
372
+ *
373
+ * @type {string | TokenStream}
374
+ * @public
375
+ */
376
+ this.content = content;
377
+ /**
378
+ * The alias(es) of the token.
379
+ *
380
+ * @type {string|string[]}
381
+ * @see GrammarToken
382
+ * @public
383
+ */
384
+ this.alias = alias;
385
+ this.length = (matchedStr || "").length | 0;
386
+ }
387
+ /**
388
+ * A token stream is an array of strings and {@link Token Token} objects.
389
+ *
390
+ * Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
391
+ * them.
392
+ *
393
+ * 1. No adjacent strings.
394
+ * 2. No empty strings.
395
+ *
396
+ * The only exception here is the token stream that only contains the empty string and nothing else.
397
+ *
398
+ * @typedef {Array<string | Token>} TokenStream
399
+ * @global
400
+ * @public
401
+ */
402
+ /**
403
+ * @param {RegExp} pattern
404
+ * @param {number} pos
405
+ * @param {string} text
406
+ * @param {boolean} lookbehind
407
+ * @returns {RegExpExecArray | null}
408
+ */
409
+ function matchPattern(pattern, pos, text, lookbehind) {
410
+ pattern.lastIndex = pos;
411
+ var match = pattern.exec(text);
412
+ if (match && lookbehind && match[1]) {
413
+ var lookbehindLength = match[1].length;
414
+ match.index += lookbehindLength;
415
+ match[0] = match[0].slice(lookbehindLength);
416
+ }
417
+ return match;
418
+ }
419
+ /**
420
+ * @param {string} text
421
+ * @param {LinkedList<string | Token>} tokenList
422
+ * @param {any} grammar
423
+ * @param {LinkedListNode<string | Token>} startNode
424
+ * @param {number} startPos
425
+ * @param {RematchOptions} [rematch]
426
+ * @returns {void}
427
+ * @private
428
+ *
429
+ * @typedef RematchOptions
430
+ * @property {string} cause
431
+ * @property {number} reach
432
+ */
433
+ function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
434
+ for (var token in grammar) {
435
+ if (!grammar.hasOwnProperty(token) || !grammar[token]) continue;
436
+ var patterns = grammar[token];
437
+ patterns = Array.isArray(patterns) ? patterns : [patterns];
438
+ for (var j = 0; j < patterns.length; ++j) {
439
+ if (rematch && rematch.cause == token + "," + j) return;
440
+ var patternObj = patterns[j];
441
+ var inside = patternObj.inside;
442
+ var lookbehind = !!patternObj.lookbehind;
443
+ var greedy = !!patternObj.greedy;
444
+ var alias = patternObj.alias;
445
+ if (greedy && !patternObj.pattern.global) {
446
+ var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
447
+ patternObj.pattern = RegExp(patternObj.pattern.source, flags + "g");
448
+ }
449
+ /** @type {RegExp} */
450
+ var pattern = patternObj.pattern || patternObj;
451
+ for (var currentNode = startNode.next, pos = startPos; currentNode !== tokenList.tail; pos += currentNode.value.length, currentNode = currentNode.next) {
452
+ if (rematch && pos >= rematch.reach) break;
453
+ var str = currentNode.value;
454
+ if (tokenList.length > text.length) return;
455
+ if (str instanceof Token) continue;
456
+ var removeCount = 1;
457
+ var match;
458
+ if (greedy) {
459
+ match = matchPattern(pattern, pos, text, lookbehind);
460
+ if (!match || match.index >= text.length) break;
461
+ var from = match.index;
462
+ var to = match.index + match[0].length;
463
+ var p = pos;
464
+ p += currentNode.value.length;
465
+ while (from >= p) {
466
+ currentNode = currentNode.next;
467
+ p += currentNode.value.length;
468
+ }
469
+ p -= currentNode.value.length;
470
+ pos = p;
471
+ if (currentNode.value instanceof Token) continue;
472
+ for (var k = currentNode; k !== tokenList.tail && (p < to || typeof k.value === "string"); k = k.next) {
473
+ removeCount++;
474
+ p += k.value.length;
475
+ }
476
+ removeCount--;
477
+ str = text.slice(pos, p);
478
+ match.index -= pos;
479
+ } else {
480
+ match = matchPattern(pattern, 0, str, lookbehind);
481
+ if (!match) continue;
482
+ }
483
+ var from = match.index;
484
+ var matchStr = match[0];
485
+ var before = str.slice(0, from);
486
+ var after = str.slice(from + matchStr.length);
487
+ var reach = pos + str.length;
488
+ if (rematch && reach > rematch.reach) rematch.reach = reach;
489
+ var removeFrom = currentNode.prev;
490
+ if (before) {
491
+ removeFrom = addAfter(tokenList, removeFrom, before);
492
+ pos += before.length;
493
+ }
494
+ removeRange(tokenList, removeFrom, removeCount);
495
+ var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
496
+ currentNode = addAfter(tokenList, removeFrom, wrapped);
497
+ if (after) addAfter(tokenList, currentNode, after);
498
+ if (removeCount > 1) {
499
+ /** @type {RematchOptions} */
500
+ var nestedRematch = {
501
+ cause: token + "," + j,
502
+ reach
503
+ };
504
+ matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
505
+ if (rematch && nestedRematch.reach > rematch.reach) rematch.reach = nestedRematch.reach;
506
+ }
507
+ }
508
+ }
509
+ }
510
+ }
511
+ /**
512
+ * @typedef LinkedListNode
513
+ * @property {T} value
514
+ * @property {LinkedListNode<T> | null} prev The previous node.
515
+ * @property {LinkedListNode<T> | null} next The next node.
516
+ * @template T
517
+ * @private
518
+ */
519
+ /**
520
+ * @template T
521
+ * @private
522
+ */
523
+ function LinkedList() {
524
+ /** @type {LinkedListNode<T>} */
525
+ var head = {
526
+ value: null,
527
+ prev: null,
528
+ next: null
529
+ };
530
+ /** @type {LinkedListNode<T>} */
531
+ var tail = {
532
+ value: null,
533
+ prev: head,
534
+ next: null
535
+ };
536
+ head.next = tail;
537
+ /** @type {LinkedListNode<T>} */
538
+ this.head = head;
539
+ /** @type {LinkedListNode<T>} */
540
+ this.tail = tail;
541
+ this.length = 0;
542
+ }
543
+ /**
544
+ * Adds a new node with the given value to the list.
545
+ *
546
+ * @param {LinkedList<T>} list
547
+ * @param {LinkedListNode<T>} node
548
+ * @param {T} value
549
+ * @returns {LinkedListNode<T>} The added node.
550
+ * @template T
551
+ */
552
+ function addAfter(list, node, value) {
553
+ var next = node.next;
554
+ var newNode = {
555
+ value,
556
+ prev: node,
557
+ next
558
+ };
559
+ node.next = newNode;
560
+ next.prev = newNode;
561
+ list.length++;
562
+ return newNode;
563
+ }
564
+ /**
565
+ * Removes `count` nodes after the given node. The given node will not be removed.
566
+ *
567
+ * @param {LinkedList<T>} list
568
+ * @param {LinkedListNode<T>} node
569
+ * @param {number} count
570
+ * @template T
571
+ */
572
+ function removeRange(list, node, count) {
573
+ var next = node.next;
574
+ for (var i = 0; i < count && next !== list.tail; i++) next = next.next;
575
+ node.next = next;
576
+ next.prev = node;
577
+ list.length -= i;
578
+ }
579
+ /**
580
+ * @param {LinkedList<T>} list
581
+ * @returns {T[]}
582
+ * @template T
583
+ */
584
+ function toArray(list) {
585
+ var array = [];
586
+ var node = list.head.next;
587
+ while (node !== list.tail) {
588
+ array.push(node.value);
589
+ node = node.next;
590
+ }
591
+ return array;
592
+ }
593
+ var Prism = _;
594
+ //#endregion
595
+ exports.Prism = Prism;