@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.
- package/dist/Button/CopyToClipboardButton/CopyToClipboardButton.cjs +17 -8
- package/dist/Button/CopyToClipboardButton/CopyToClipboardButton.js +17 -8
- package/dist/Button/CopyToClipboardButton/CopyToClipboardButton.types.d.ts +5 -1
- package/dist/CodeBlock/CodeBlock.cjs +29 -14
- package/dist/CodeBlock/CodeBlock.js +29 -14
- package/dist/CodeBlock/CodeBlock.style.d.ts +4 -3
- package/dist/CodeBlock/CodeBlock.types.cjs +7 -0
- package/dist/CodeBlock/CodeBlock.types.d.ts +4 -0
- package/dist/CodeBlock/CodeBlock.types.js +7 -1
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.cjs +29 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.constants.cjs +34 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.constants.d.ts +25 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.constants.js +32 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.d.ts +6 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.js +29 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.types.d.ts +10 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.types.js +1 -0
- package/dist/Inputs/Input/Input.cjs +9 -2
- package/dist/Inputs/Input/Input.d.ts +4 -1
- package/dist/Inputs/Input/Input.js +9 -2
- package/dist/Inputs/Input/Input.types.d.ts +5 -1
- package/dist/Inputs/PasswordInput/components/Compose/Compose.types.d.ts +1 -1
- package/dist/Inputs/TextArea/TextArea.cjs +16 -6
- package/dist/Inputs/TextArea/TextArea.d.ts +3 -1
- package/dist/Inputs/TextArea/TextArea.js +16 -6
- package/dist/Inputs/TextArea/TextArea.types.d.ts +4 -1
- package/dist/Inputs/TextArea/components/CopyButton/CopyButton.cjs +7 -0
- package/dist/Inputs/TextArea/components/CopyButton/CopyButton.d.ts +2 -0
- package/dist/Inputs/TextArea/components/CopyButton/CopyButton.js +7 -0
- package/dist/Inputs/TextArea/components/CopyButton/CopyButton.style.cjs +17 -0
- package/dist/Inputs/TextArea/components/CopyButton/CopyButton.style.d.ts +1 -0
- package/dist/Inputs/TextArea/components/CopyButton/CopyButton.style.js +15 -0
- package/dist/Inputs/TextArea/components/TextAreaTag/TextAreaTag.cjs +3 -1
- package/dist/Inputs/TextArea/components/TextAreaTag/TextAreaTag.js +4 -2
- package/dist/Inputs/TextArea/components/TextAreaTag/TextAreaTag.style.cjs +8 -1
- package/dist/Inputs/TextArea/components/TextAreaTag/TextAreaTag.style.js +8 -1
- package/dist/Inputs/components/Compose/CommonCompose.cjs +23 -18
- package/dist/Inputs/components/Compose/CommonCompose.d.ts +1 -1
- package/dist/Inputs/components/Compose/CommonCompose.js +24 -19
- package/dist/Inputs/components/Compose/CommonCompose.types.d.ts +2 -0
- package/dist/Inputs/components/Compose/Compose.style.cjs +7 -0
- package/dist/Inputs/components/Compose/Compose.style.js +7 -0
- package/dist/Inputs/components/Compose/NumericCompose.types.d.ts +1 -1
- package/dist/Inputs/components/CopyButton/CopyButton.cjs +15 -0
- package/dist/Inputs/components/CopyButton/CopyButton.d.ts +2 -0
- package/dist/Inputs/components/CopyButton/CopyButton.js +15 -0
- package/dist/Inputs/components/CopyButton/CopyButton.style.cjs +17 -0
- package/dist/Inputs/components/CopyButton/CopyButton.style.d.ts +1 -0
- package/dist/Inputs/components/CopyButton/CopyButton.style.js +15 -0
- package/dist/Inputs/components/CopyButton/CopyButton.types.d.ts +6 -0
- package/dist/Inputs/components/CopyButton/CopyButton.types.js +1 -0
- package/dist/Inputs/components/InputTag/InputTag.cjs +3 -1
- package/dist/Inputs/components/InputTag/InputTag.js +4 -2
- package/dist/Inputs/components/InputTag/InputTag.style.cjs +1 -1
- package/dist/Inputs/components/InputTag/InputTag.style.js +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.js +2 -2
- package/dist/node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.cjs +8 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js +8 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.cjs +7 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js +7 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/defineProperty.cjs +12 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/defineProperty.js +12 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/extends.cjs +17 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/extends.js +12 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/iterableToArray.cjs +6 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/iterableToArray.js +6 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/nonIterableSpread.cjs +6 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js +6 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.cjs +13 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js +13 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.cjs +12 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +12 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/toConsumableArray.cjs +10 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/toConsumableArray.js +10 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/toPrimitive.cjs +14 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +14 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/toPropertyKey.cjs +9 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/toPropertyKey.js +9 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/typeof.cjs +16 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/typeof.js +11 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.cjs +11 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js +11 -0
- package/dist/node_modules/character-entities-legacy/index.cjs +116 -0
- package/dist/node_modules/character-entities-legacy/index.js +116 -0
- package/dist/node_modules/character-reference-invalid/index.cjs +38 -0
- package/dist/node_modules/character-reference-invalid/index.js +38 -0
- package/dist/node_modules/comma-separated-tokens/index.cjs +43 -0
- package/dist/node_modules/comma-separated-tokens/index.js +43 -0
- package/dist/node_modules/decode-named-character-reference/index.dom.cjs +15 -0
- package/dist/node_modules/decode-named-character-reference/index.dom.js +15 -0
- package/dist/node_modules/hast-util-parse-selector/lib/index.cjs +76 -0
- package/dist/node_modules/hast-util-parse-selector/lib/index.js +76 -0
- package/dist/node_modules/hastscript/lib/create-h.cjs +262 -0
- package/dist/node_modules/hastscript/lib/create-h.js +262 -0
- package/dist/node_modules/hastscript/lib/index.cjs +21 -0
- package/dist/node_modules/hastscript/lib/index.js +21 -0
- package/dist/node_modules/hastscript/lib/svg-case-sensitive-tag-names.cjs +49 -0
- package/dist/node_modules/hastscript/lib/svg-case-sensitive-tag-names.js +49 -0
- package/dist/node_modules/is-alphabetical/index.cjs +14 -0
- package/dist/node_modules/is-alphabetical/index.js +14 -0
- package/dist/node_modules/is-alphanumerical/index.cjs +15 -0
- package/dist/node_modules/is-alphanumerical/index.js +15 -0
- package/dist/node_modules/is-decimal/index.cjs +14 -0
- package/dist/node_modules/is-decimal/index.js +14 -0
- package/dist/node_modules/is-hexadecimal/index.cjs +14 -0
- package/dist/node_modules/is-hexadecimal/index.js +14 -0
- package/dist/node_modules/parse-entities/lib/index.cjs +232 -0
- package/dist/node_modules/parse-entities/lib/index.js +232 -0
- package/dist/node_modules/property-information/index.cjs +27 -0
- package/dist/node_modules/property-information/index.js +26 -0
- package/dist/node_modules/property-information/lib/aria.cjs +60 -0
- package/dist/node_modules/property-information/lib/aria.js +61 -0
- package/dist/node_modules/property-information/lib/find.cjs +81 -0
- package/dist/node_modules/property-information/lib/find.js +81 -0
- package/dist/node_modules/property-information/lib/html.cjs +326 -0
- package/dist/node_modules/property-information/lib/html.js +326 -0
- package/dist/node_modules/property-information/lib/normalize.cjs +15 -0
- package/dist/node_modules/property-information/lib/normalize.js +15 -0
- package/dist/node_modules/property-information/lib/svg.cjs +564 -0
- package/dist/node_modules/property-information/lib/svg.js +564 -0
- package/dist/node_modules/property-information/lib/util/case-insensitive-transform.cjs +15 -0
- package/dist/node_modules/property-information/lib/util/case-insensitive-transform.js +15 -0
- package/dist/node_modules/property-information/lib/util/case-sensitive-transform.cjs +14 -0
- package/dist/node_modules/property-information/lib/util/case-sensitive-transform.js +14 -0
- package/dist/node_modules/property-information/lib/util/create.cjs +53 -0
- package/dist/node_modules/property-information/lib/util/create.js +53 -0
- package/dist/node_modules/property-information/lib/util/defined-info.cjs +49 -0
- package/dist/node_modules/property-information/lib/util/defined-info.js +49 -0
- package/dist/node_modules/property-information/lib/util/info.cjs +33 -0
- package/dist/node_modules/property-information/lib/util/info.js +33 -0
- package/dist/node_modules/property-information/lib/util/merge.cjs +26 -0
- package/dist/node_modules/property-information/lib/util/merge.js +26 -0
- package/dist/node_modules/property-information/lib/util/schema.cjs +27 -0
- package/dist/node_modules/property-information/lib/util/schema.js +27 -0
- package/dist/node_modules/property-information/lib/util/types.cjs +35 -0
- package/dist/node_modules/property-information/lib/util/types.js +24 -0
- package/dist/node_modules/property-information/lib/xlink.cjs +18 -0
- package/dist/node_modules/property-information/lib/xlink.js +19 -0
- package/dist/node_modules/property-information/lib/xml.cjs +14 -0
- package/dist/node_modules/property-information/lib/xml.js +15 -0
- package/dist/node_modules/property-information/lib/xmlns.cjs +14 -0
- package/dist/node_modules/property-information/lib/xmlns.js +14 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/checkForListedLanguage.cjs +6 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/checkForListedLanguage.js +6 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/create-element.cjs +183 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/create-element.js +181 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/highlight.cjs +308 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/highlight.js +306 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/bash.cjs +4 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/bash.js +5 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/json.cjs +4 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/json.js +5 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/python.cjs +4 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/python.js +5 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/typescript.cjs +4 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/typescript.js +5 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/prism-light.cjs +12 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/prism-light.js +12 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/styles/prism/vs.cjs +121 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/styles/prism/vs.js +121 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/styles/prism/vsc-dark-plus.cjs +147 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/styles/prism/vsc-dark-plus.js +147 -0
- package/dist/node_modules/refractor/lang/bash.cjs +190 -0
- package/dist/node_modules/refractor/lang/bash.js +190 -0
- package/dist/node_modules/refractor/lang/clike.cjs +37 -0
- package/dist/node_modules/refractor/lang/clike.js +37 -0
- package/dist/node_modules/refractor/lang/javascript.cjs +122 -0
- package/dist/node_modules/refractor/lang/javascript.js +122 -0
- package/dist/node_modules/refractor/lang/json.cjs +36 -0
- package/dist/node_modules/refractor/lang/json.js +36 -0
- package/dist/node_modules/refractor/lang/python.cjs +71 -0
- package/dist/node_modules/refractor/lang/python.js +71 -0
- package/dist/node_modules/refractor/lang/typescript.cjs +55 -0
- package/dist/node_modules/refractor/lang/typescript.js +55 -0
- package/dist/node_modules/refractor/lib/core.cjs +214 -0
- package/dist/node_modules/refractor/lib/core.js +214 -0
- package/dist/node_modules/refractor/lib/prism-core.cjs +595 -0
- package/dist/node_modules/refractor/lib/prism-core.js +595 -0
- package/dist/node_modules/space-separated-tokens/index.cjs +15 -0
- package/dist/node_modules/space-separated-tokens/index.js +15 -0
- package/package.json +4 -2
- package/skills/redis-ui-components/references/CodeBlock.md +23 -5
- package/skills/redis-ui-components/references/CopyToClipboardButton.md +23 -1
- package/skills/redis-ui-components/references/Input.md +39 -2
- package/skills/redis-ui-components/references/SearchInput.md +1 -1
- package/skills/redis-ui-components/references/TextArea.md +19 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
const require_index = require("../../hastscript/lib/index.cjs");
|
|
2
|
+
const require_index$1 = require("../../parse-entities/lib/index.cjs");
|
|
3
|
+
const require_prism_core = require("./prism-core.cjs");
|
|
4
|
+
//#region ../../node_modules/refractor/lib/core.js
|
|
5
|
+
/**
|
|
6
|
+
* @import {Element, Root, Text} from 'hast'
|
|
7
|
+
* @import {Grammar, Languages} from 'prismjs'
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @typedef _Token
|
|
11
|
+
* Hidden Prism token.
|
|
12
|
+
* @property {string} alias
|
|
13
|
+
* Alias.
|
|
14
|
+
* @property {string} content
|
|
15
|
+
* Content.
|
|
16
|
+
* @property {number} length
|
|
17
|
+
* Length.
|
|
18
|
+
* @property {string} type
|
|
19
|
+
* Type.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @typedef _Env
|
|
23
|
+
* Hidden Prism environment.
|
|
24
|
+
* @property {Record<string, string>} attributes
|
|
25
|
+
* Attributes.
|
|
26
|
+
* @property {Array<string>} classes
|
|
27
|
+
* Classes.
|
|
28
|
+
* @property {Array<Element | Text> | Element | Text} content
|
|
29
|
+
* Content.
|
|
30
|
+
* @property {string} language
|
|
31
|
+
* Language.
|
|
32
|
+
* @property {string} tag
|
|
33
|
+
* Tag.
|
|
34
|
+
* @property {string} type
|
|
35
|
+
* Type.
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {((prism: Refractor) => undefined | void) & {aliases?: Array<string> | undefined, displayName: string}} Syntax
|
|
39
|
+
* Refractor syntax function.
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* @typedef Refractor
|
|
43
|
+
* Virtual syntax highlighting
|
|
44
|
+
* @property {typeof alias} alias
|
|
45
|
+
* @property {Languages} languages
|
|
46
|
+
* @property {typeof listLanguages} listLanguages
|
|
47
|
+
* @property {typeof highlight} highlight
|
|
48
|
+
* @property {typeof registered} registered
|
|
49
|
+
* @property {typeof register} register
|
|
50
|
+
*/
|
|
51
|
+
function Refractor() {}
|
|
52
|
+
Refractor.prototype = require_prism_core.Prism;
|
|
53
|
+
/** @type {Refractor} */
|
|
54
|
+
var refractor = new Refractor();
|
|
55
|
+
refractor.highlight = highlight;
|
|
56
|
+
refractor.register = register;
|
|
57
|
+
refractor.alias = alias;
|
|
58
|
+
refractor.registered = registered;
|
|
59
|
+
refractor.listLanguages = listLanguages;
|
|
60
|
+
refractor.util.encode = encode;
|
|
61
|
+
refractor.Token.stringify = stringify;
|
|
62
|
+
/**
|
|
63
|
+
* Highlight `value` (code) as `language` (programming language).
|
|
64
|
+
*
|
|
65
|
+
* @param {string} value
|
|
66
|
+
* Code to highlight.
|
|
67
|
+
* @param {Grammar | string} language
|
|
68
|
+
* Programming language name, alias, or grammar.
|
|
69
|
+
* @returns {Root}
|
|
70
|
+
* Node representing highlighted code.
|
|
71
|
+
*/
|
|
72
|
+
function highlight(value, language) {
|
|
73
|
+
if (typeof value !== "string") throw new TypeError("Expected `string` for `value`, got `" + value + "`");
|
|
74
|
+
/** @type {Grammar} */
|
|
75
|
+
let grammar;
|
|
76
|
+
/** @type {string | undefined} */
|
|
77
|
+
let name;
|
|
78
|
+
/* c8 ignore next 2 */
|
|
79
|
+
if (language && typeof language === "object") grammar = language;
|
|
80
|
+
else {
|
|
81
|
+
name = language;
|
|
82
|
+
if (typeof name !== "string") throw new TypeError("Expected `string` for `name`, got `" + name + "`");
|
|
83
|
+
if (Object.hasOwn(refractor.languages, name)) grammar = refractor.languages[name];
|
|
84
|
+
else throw new Error("Unknown language: `" + name + "` is not registered");
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
type: "root",
|
|
88
|
+
children: require_prism_core.Prism.highlight.call(refractor, value, grammar, name)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Register a syntax.
|
|
93
|
+
*
|
|
94
|
+
* @param {Syntax} syntax
|
|
95
|
+
* Language function made for refractor, as in, the files in
|
|
96
|
+
* `refractor/lang/*.js`.
|
|
97
|
+
* @returns {undefined}
|
|
98
|
+
* Nothing.
|
|
99
|
+
*/
|
|
100
|
+
function register(syntax) {
|
|
101
|
+
if (typeof syntax !== "function" || !syntax.displayName) throw new Error("Expected `function` for `syntax`, got `" + syntax + "`");
|
|
102
|
+
if (!Object.hasOwn(refractor.languages, syntax.displayName)) syntax(refractor);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Register aliases for already registered languages.
|
|
106
|
+
*
|
|
107
|
+
* @param {Record<string, ReadonlyArray<string> | string> | string} language
|
|
108
|
+
* Language to alias.
|
|
109
|
+
* @param {ReadonlyArray<string> | string | null | undefined} [alias]
|
|
110
|
+
* Aliases.
|
|
111
|
+
* @returns {undefined}
|
|
112
|
+
* Nothing.
|
|
113
|
+
*/
|
|
114
|
+
function alias(language, alias) {
|
|
115
|
+
const languages = refractor.languages;
|
|
116
|
+
/** @type {Record<string, ReadonlyArray<string> | string>} */
|
|
117
|
+
let map = {};
|
|
118
|
+
if (typeof language === "string") {
|
|
119
|
+
if (alias) map[language] = alias;
|
|
120
|
+
} else map = language;
|
|
121
|
+
/** @type {string} */
|
|
122
|
+
let key;
|
|
123
|
+
for (key in map) if (Object.hasOwn(map, key)) {
|
|
124
|
+
const value = map[key];
|
|
125
|
+
const list = typeof value === "string" ? [value] : value;
|
|
126
|
+
let index = -1;
|
|
127
|
+
while (++index < list.length) languages[list[index]] = languages[key];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check whether an `alias` or `language` is registered.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} aliasOrLanguage
|
|
134
|
+
* Language or alias to check.
|
|
135
|
+
* @returns {boolean}
|
|
136
|
+
* Whether the language is registered.
|
|
137
|
+
*/
|
|
138
|
+
function registered(aliasOrLanguage) {
|
|
139
|
+
if (typeof aliasOrLanguage !== "string") throw new TypeError("Expected `string` for `aliasOrLanguage`, got `" + aliasOrLanguage + "`");
|
|
140
|
+
return Object.hasOwn(refractor.languages, aliasOrLanguage);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* List all registered languages (names and aliases).
|
|
144
|
+
*
|
|
145
|
+
* @returns {Array<string>}
|
|
146
|
+
* List of language names.
|
|
147
|
+
*/
|
|
148
|
+
function listLanguages() {
|
|
149
|
+
const languages = refractor.languages;
|
|
150
|
+
/** @type {Array<string>} */
|
|
151
|
+
const list = [];
|
|
152
|
+
/** @type {string} */
|
|
153
|
+
let language;
|
|
154
|
+
for (language in languages) if (Object.hasOwn(languages, language) && typeof languages[language] === "object") list.push(language);
|
|
155
|
+
return list;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @param {Array<_Token | string> | _Token | string} value
|
|
159
|
+
* Token to stringify.
|
|
160
|
+
* @param {string} language
|
|
161
|
+
* Language of the token.
|
|
162
|
+
* @returns {Array<Element | Text> | Element | Text}
|
|
163
|
+
* Node representing the token.
|
|
164
|
+
*/
|
|
165
|
+
function stringify(value, language) {
|
|
166
|
+
if (typeof value === "string") return {
|
|
167
|
+
type: "text",
|
|
168
|
+
value
|
|
169
|
+
};
|
|
170
|
+
if (Array.isArray(value)) {
|
|
171
|
+
/** @type {Array<Element | Text>} */
|
|
172
|
+
const result = [];
|
|
173
|
+
let index = -1;
|
|
174
|
+
while (++index < value.length) if (value[index] !== null && value[index] !== void 0 && value[index] !== "") result.push(stringify(value[index], language));
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
/** @type {_Env} */
|
|
178
|
+
const env = {
|
|
179
|
+
attributes: {},
|
|
180
|
+
classes: ["token", value.type],
|
|
181
|
+
content: stringify(value.content, language),
|
|
182
|
+
language,
|
|
183
|
+
tag: "span",
|
|
184
|
+
type: value.type
|
|
185
|
+
};
|
|
186
|
+
if (value.alias) env.classes.push(...typeof value.alias === "string" ? [value.alias] : value.alias);
|
|
187
|
+
refractor.hooks.run("wrap", env);
|
|
188
|
+
return require_index.h(env.tag + "." + env.classes.join("."), attributes(env.attributes), env.content);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* @template {unknown} T
|
|
192
|
+
* Tokens.
|
|
193
|
+
* @param {T} tokens
|
|
194
|
+
* Input.
|
|
195
|
+
* @returns {T}
|
|
196
|
+
* Output, same as input.
|
|
197
|
+
*/
|
|
198
|
+
function encode(tokens) {
|
|
199
|
+
return tokens;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* @param {Record<string, string>} record
|
|
203
|
+
* Attributes.
|
|
204
|
+
* @returns {Record<string, string>}
|
|
205
|
+
* Attributes.
|
|
206
|
+
*/
|
|
207
|
+
function attributes(record) {
|
|
208
|
+
/** @type {string} */
|
|
209
|
+
let key;
|
|
210
|
+
for (key in record) if (Object.hasOwn(record, key)) record[key] = require_index$1.parseEntities(record[key]);
|
|
211
|
+
return record;
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
exports.refractor = refractor;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { h } from "../../hastscript/lib/index.js";
|
|
2
|
+
import { parseEntities } from "../../parse-entities/lib/index.js";
|
|
3
|
+
import { Prism } from "./prism-core.js";
|
|
4
|
+
//#region ../../node_modules/refractor/lib/core.js
|
|
5
|
+
/**
|
|
6
|
+
* @import {Element, Root, Text} from 'hast'
|
|
7
|
+
* @import {Grammar, Languages} from 'prismjs'
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @typedef _Token
|
|
11
|
+
* Hidden Prism token.
|
|
12
|
+
* @property {string} alias
|
|
13
|
+
* Alias.
|
|
14
|
+
* @property {string} content
|
|
15
|
+
* Content.
|
|
16
|
+
* @property {number} length
|
|
17
|
+
* Length.
|
|
18
|
+
* @property {string} type
|
|
19
|
+
* Type.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @typedef _Env
|
|
23
|
+
* Hidden Prism environment.
|
|
24
|
+
* @property {Record<string, string>} attributes
|
|
25
|
+
* Attributes.
|
|
26
|
+
* @property {Array<string>} classes
|
|
27
|
+
* Classes.
|
|
28
|
+
* @property {Array<Element | Text> | Element | Text} content
|
|
29
|
+
* Content.
|
|
30
|
+
* @property {string} language
|
|
31
|
+
* Language.
|
|
32
|
+
* @property {string} tag
|
|
33
|
+
* Tag.
|
|
34
|
+
* @property {string} type
|
|
35
|
+
* Type.
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {((prism: Refractor) => undefined | void) & {aliases?: Array<string> | undefined, displayName: string}} Syntax
|
|
39
|
+
* Refractor syntax function.
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* @typedef Refractor
|
|
43
|
+
* Virtual syntax highlighting
|
|
44
|
+
* @property {typeof alias} alias
|
|
45
|
+
* @property {Languages} languages
|
|
46
|
+
* @property {typeof listLanguages} listLanguages
|
|
47
|
+
* @property {typeof highlight} highlight
|
|
48
|
+
* @property {typeof registered} registered
|
|
49
|
+
* @property {typeof register} register
|
|
50
|
+
*/
|
|
51
|
+
function Refractor() {}
|
|
52
|
+
Refractor.prototype = Prism;
|
|
53
|
+
/** @type {Refractor} */
|
|
54
|
+
var refractor = new Refractor();
|
|
55
|
+
refractor.highlight = highlight;
|
|
56
|
+
refractor.register = register;
|
|
57
|
+
refractor.alias = alias;
|
|
58
|
+
refractor.registered = registered;
|
|
59
|
+
refractor.listLanguages = listLanguages;
|
|
60
|
+
refractor.util.encode = encode;
|
|
61
|
+
refractor.Token.stringify = stringify;
|
|
62
|
+
/**
|
|
63
|
+
* Highlight `value` (code) as `language` (programming language).
|
|
64
|
+
*
|
|
65
|
+
* @param {string} value
|
|
66
|
+
* Code to highlight.
|
|
67
|
+
* @param {Grammar | string} language
|
|
68
|
+
* Programming language name, alias, or grammar.
|
|
69
|
+
* @returns {Root}
|
|
70
|
+
* Node representing highlighted code.
|
|
71
|
+
*/
|
|
72
|
+
function highlight(value, language) {
|
|
73
|
+
if (typeof value !== "string") throw new TypeError("Expected `string` for `value`, got `" + value + "`");
|
|
74
|
+
/** @type {Grammar} */
|
|
75
|
+
let grammar;
|
|
76
|
+
/** @type {string | undefined} */
|
|
77
|
+
let name;
|
|
78
|
+
/* c8 ignore next 2 */
|
|
79
|
+
if (language && typeof language === "object") grammar = language;
|
|
80
|
+
else {
|
|
81
|
+
name = language;
|
|
82
|
+
if (typeof name !== "string") throw new TypeError("Expected `string` for `name`, got `" + name + "`");
|
|
83
|
+
if (Object.hasOwn(refractor.languages, name)) grammar = refractor.languages[name];
|
|
84
|
+
else throw new Error("Unknown language: `" + name + "` is not registered");
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
type: "root",
|
|
88
|
+
children: Prism.highlight.call(refractor, value, grammar, name)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Register a syntax.
|
|
93
|
+
*
|
|
94
|
+
* @param {Syntax} syntax
|
|
95
|
+
* Language function made for refractor, as in, the files in
|
|
96
|
+
* `refractor/lang/*.js`.
|
|
97
|
+
* @returns {undefined}
|
|
98
|
+
* Nothing.
|
|
99
|
+
*/
|
|
100
|
+
function register(syntax) {
|
|
101
|
+
if (typeof syntax !== "function" || !syntax.displayName) throw new Error("Expected `function` for `syntax`, got `" + syntax + "`");
|
|
102
|
+
if (!Object.hasOwn(refractor.languages, syntax.displayName)) syntax(refractor);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Register aliases for already registered languages.
|
|
106
|
+
*
|
|
107
|
+
* @param {Record<string, ReadonlyArray<string> | string> | string} language
|
|
108
|
+
* Language to alias.
|
|
109
|
+
* @param {ReadonlyArray<string> | string | null | undefined} [alias]
|
|
110
|
+
* Aliases.
|
|
111
|
+
* @returns {undefined}
|
|
112
|
+
* Nothing.
|
|
113
|
+
*/
|
|
114
|
+
function alias(language, alias) {
|
|
115
|
+
const languages = refractor.languages;
|
|
116
|
+
/** @type {Record<string, ReadonlyArray<string> | string>} */
|
|
117
|
+
let map = {};
|
|
118
|
+
if (typeof language === "string") {
|
|
119
|
+
if (alias) map[language] = alias;
|
|
120
|
+
} else map = language;
|
|
121
|
+
/** @type {string} */
|
|
122
|
+
let key;
|
|
123
|
+
for (key in map) if (Object.hasOwn(map, key)) {
|
|
124
|
+
const value = map[key];
|
|
125
|
+
const list = typeof value === "string" ? [value] : value;
|
|
126
|
+
let index = -1;
|
|
127
|
+
while (++index < list.length) languages[list[index]] = languages[key];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check whether an `alias` or `language` is registered.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} aliasOrLanguage
|
|
134
|
+
* Language or alias to check.
|
|
135
|
+
* @returns {boolean}
|
|
136
|
+
* Whether the language is registered.
|
|
137
|
+
*/
|
|
138
|
+
function registered(aliasOrLanguage) {
|
|
139
|
+
if (typeof aliasOrLanguage !== "string") throw new TypeError("Expected `string` for `aliasOrLanguage`, got `" + aliasOrLanguage + "`");
|
|
140
|
+
return Object.hasOwn(refractor.languages, aliasOrLanguage);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* List all registered languages (names and aliases).
|
|
144
|
+
*
|
|
145
|
+
* @returns {Array<string>}
|
|
146
|
+
* List of language names.
|
|
147
|
+
*/
|
|
148
|
+
function listLanguages() {
|
|
149
|
+
const languages = refractor.languages;
|
|
150
|
+
/** @type {Array<string>} */
|
|
151
|
+
const list = [];
|
|
152
|
+
/** @type {string} */
|
|
153
|
+
let language;
|
|
154
|
+
for (language in languages) if (Object.hasOwn(languages, language) && typeof languages[language] === "object") list.push(language);
|
|
155
|
+
return list;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @param {Array<_Token | string> | _Token | string} value
|
|
159
|
+
* Token to stringify.
|
|
160
|
+
* @param {string} language
|
|
161
|
+
* Language of the token.
|
|
162
|
+
* @returns {Array<Element | Text> | Element | Text}
|
|
163
|
+
* Node representing the token.
|
|
164
|
+
*/
|
|
165
|
+
function stringify(value, language) {
|
|
166
|
+
if (typeof value === "string") return {
|
|
167
|
+
type: "text",
|
|
168
|
+
value
|
|
169
|
+
};
|
|
170
|
+
if (Array.isArray(value)) {
|
|
171
|
+
/** @type {Array<Element | Text>} */
|
|
172
|
+
const result = [];
|
|
173
|
+
let index = -1;
|
|
174
|
+
while (++index < value.length) if (value[index] !== null && value[index] !== void 0 && value[index] !== "") result.push(stringify(value[index], language));
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
/** @type {_Env} */
|
|
178
|
+
const env = {
|
|
179
|
+
attributes: {},
|
|
180
|
+
classes: ["token", value.type],
|
|
181
|
+
content: stringify(value.content, language),
|
|
182
|
+
language,
|
|
183
|
+
tag: "span",
|
|
184
|
+
type: value.type
|
|
185
|
+
};
|
|
186
|
+
if (value.alias) env.classes.push(...typeof value.alias === "string" ? [value.alias] : value.alias);
|
|
187
|
+
refractor.hooks.run("wrap", env);
|
|
188
|
+
return h(env.tag + "." + env.classes.join("."), attributes(env.attributes), env.content);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* @template {unknown} T
|
|
192
|
+
* Tokens.
|
|
193
|
+
* @param {T} tokens
|
|
194
|
+
* Input.
|
|
195
|
+
* @returns {T}
|
|
196
|
+
* Output, same as input.
|
|
197
|
+
*/
|
|
198
|
+
function encode(tokens) {
|
|
199
|
+
return tokens;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* @param {Record<string, string>} record
|
|
203
|
+
* Attributes.
|
|
204
|
+
* @returns {Record<string, string>}
|
|
205
|
+
* Attributes.
|
|
206
|
+
*/
|
|
207
|
+
function attributes(record) {
|
|
208
|
+
/** @type {string} */
|
|
209
|
+
let key;
|
|
210
|
+
for (key in record) if (Object.hasOwn(record, key)) record[key] = parseEntities(record[key]);
|
|
211
|
+
return record;
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
export { refractor };
|