@satorijs/element 2.0.0 → 2.1.1
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/lib/index.cjs +67 -34
- package/lib/index.cjs.map +2 -2
- package/lib/index.d.ts +7 -3
- package/lib/index.mjs +67 -34
- package/lib/index.mjs.map +2 -2
- package/package.json +19 -1
- package/lib/utils.d.ts +0 -7
package/lib/index.cjs
CHANGED
|
@@ -9,20 +9,21 @@ function isElement(source) {
|
|
|
9
9
|
}
|
|
10
10
|
__name(isElement, "isElement");
|
|
11
11
|
function toElement(content) {
|
|
12
|
-
if (typeof content
|
|
12
|
+
if (typeof content === "string") {
|
|
13
|
+
if (content)
|
|
14
|
+
return Element("text", { content });
|
|
15
|
+
} else if (isElement(content)) {
|
|
13
16
|
return content;
|
|
14
|
-
|
|
17
|
+
} else if (!(0, import_cosmokit.isNullable)(content)) {
|
|
18
|
+
throw new TypeError(`Invalid content: ${content}`);
|
|
19
|
+
}
|
|
15
20
|
}
|
|
16
21
|
__name(toElement, "toElement");
|
|
17
|
-
function toElementArray(
|
|
18
|
-
if (Array.isArray(
|
|
19
|
-
return
|
|
20
|
-
} else if (typeof input === "string") {
|
|
21
|
-
return [toElement(input)];
|
|
22
|
-
} else if (!input.type) {
|
|
23
|
-
return input.children;
|
|
22
|
+
function toElementArray(content) {
|
|
23
|
+
if (Array.isArray(content)) {
|
|
24
|
+
return content.map(toElement).filter((x) => x);
|
|
24
25
|
} else {
|
|
25
|
-
return [
|
|
26
|
+
return [toElement(content)].filter((x) => x);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
__name(toElementArray, "toElementArray");
|
|
@@ -34,11 +35,9 @@ var ElementConstructor = class {
|
|
|
34
35
|
if (this.type === "text")
|
|
35
36
|
return Element.escape(this.attrs.content);
|
|
36
37
|
const inner = this.children.map((child) => child.toString(strip)).join("");
|
|
37
|
-
if (
|
|
38
|
+
if (strip)
|
|
38
39
|
return inner;
|
|
39
40
|
const attrs = Object.entries(this.attrs).map(([key, value]) => {
|
|
40
|
-
if ((0, import_cosmokit.isNullable)(value))
|
|
41
|
-
return "";
|
|
42
41
|
key = (0, import_cosmokit.hyphenate)(key);
|
|
43
42
|
if (value === "")
|
|
44
43
|
return ` ${key}`;
|
|
@@ -59,21 +58,38 @@ function Element(type, ...args) {
|
|
|
59
58
|
for (const [key, value] of Object.entries(args.shift())) {
|
|
60
59
|
if ((0, import_cosmokit.isNullable)(value))
|
|
61
60
|
continue;
|
|
62
|
-
if (
|
|
61
|
+
if (key === "children") {
|
|
62
|
+
children = toElementArray(value);
|
|
63
|
+
} else if (value === true) {
|
|
63
64
|
attrs[key] = "";
|
|
64
65
|
} else if (value === false) {
|
|
65
66
|
attrs["no" + (0, import_cosmokit.capitalize)(key)] = "";
|
|
66
|
-
} else {
|
|
67
|
+
} else if (!(0, import_cosmokit.isNullable)(value)) {
|
|
67
68
|
attrs[key] = "" + value;
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
-
children
|
|
72
|
+
for (const child of args) {
|
|
73
|
+
children.push(...toElementArray(child));
|
|
74
|
+
}
|
|
73
75
|
return Object.assign(el, { type, attrs, children });
|
|
74
76
|
}
|
|
75
77
|
__name(Element, "Element");
|
|
78
|
+
var interpolate = new Function("expr", "context", `
|
|
79
|
+
try {
|
|
80
|
+
with (context) {
|
|
81
|
+
const result = eval(expr)
|
|
82
|
+
return result === undefined || result === null ? '' : result
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
return ''
|
|
86
|
+
}
|
|
87
|
+
`);
|
|
76
88
|
((Element2) => {
|
|
89
|
+
Element2.jsx = Element2;
|
|
90
|
+
Element2.jsxs = Element2;
|
|
91
|
+
Element2.jsxDEV = Element2;
|
|
92
|
+
Element2.Fragment = "template";
|
|
77
93
|
function normalize(source) {
|
|
78
94
|
if (typeof source !== "string")
|
|
79
95
|
return toElementArray(source);
|
|
@@ -88,7 +104,7 @@ __name(Element, "Element");
|
|
|
88
104
|
Element2.escape = escape;
|
|
89
105
|
__name(escape, "escape");
|
|
90
106
|
function unescape(source) {
|
|
91
|
-
return source.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/&/g, "&");
|
|
107
|
+
return source.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/&#(\d+);/g, (_, code) => code === "38" ? _ : String.fromCharCode(+code)).replace(/&#x([0-9a-f]+);/gi, (_, code) => code === "26" ? _ : String.fromCharCode(parseInt(code, 16))).replace(/&(amp|#38|#x26);/g, "&");
|
|
92
108
|
}
|
|
93
109
|
Element2.unescape = unescape;
|
|
94
110
|
__name(unescape, "unescape");
|
|
@@ -160,28 +176,45 @@ __name(Element, "Element");
|
|
|
160
176
|
}
|
|
161
177
|
Element2.select = select;
|
|
162
178
|
__name(select, "select");
|
|
163
|
-
const tagRegExp = /<(\/?)\s*([^\s>/]
|
|
164
|
-
const
|
|
165
|
-
|
|
179
|
+
const tagRegExp = /<(\/?)\s*([^\s>/]*)([^>]*?)\s*(\/?)>/;
|
|
180
|
+
const attrRegExp1 = /([^\s=]+)(?:="([^"]*)"|='([^']*)')?/g;
|
|
181
|
+
const attrRegExp2 = /([^\s=]+)(?:="([^"]*)"|='([^']*)'|=\{([^}]+)\})?/g;
|
|
182
|
+
const interpRegExp = /\{([^}]+)\}/g;
|
|
183
|
+
function parse(source, context) {
|
|
166
184
|
const tokens = [];
|
|
185
|
+
const attrRegExp = context ? attrRegExp2 : attrRegExp1;
|
|
167
186
|
let tagCap;
|
|
168
187
|
while (tagCap = tagRegExp.exec(source)) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
const [_, close, tag, attrs, empty] = tagCap;
|
|
173
|
-
const token = { source: _, tag, close, empty, attrs: {} };
|
|
188
|
+
pushText(source.slice(0, tagCap.index));
|
|
189
|
+
const [_, close, type, attrs, empty] = tagCap;
|
|
190
|
+
const token = { source: _, type: type || Element2.Fragment, close, empty, attrs: {} };
|
|
174
191
|
let attrCap;
|
|
175
192
|
while (attrCap = attrRegExp.exec(attrs)) {
|
|
176
|
-
const [_2, key, v1 = "", v2 = v1] = attrCap;
|
|
177
|
-
token.attrs[(0, import_cosmokit.camelize)(key)] = unescape(v2);
|
|
193
|
+
const [_2, key, v1 = "", v2 = v1, v3] = attrCap;
|
|
194
|
+
token.attrs[(0, import_cosmokit.camelize)(key)] = v3 ? interpolate(v3, context) : unescape(v2);
|
|
178
195
|
}
|
|
179
196
|
tokens.push(token);
|
|
180
|
-
source = source.slice(tagCap.index +
|
|
197
|
+
source = source.slice(tagCap.index + _.length);
|
|
198
|
+
}
|
|
199
|
+
pushText(source);
|
|
200
|
+
function pushText(source2) {
|
|
201
|
+
source2 = source2.replace(/^\s*\n\s*/, "").replace(/\s*\n\s*$/, "");
|
|
202
|
+
let result = "";
|
|
203
|
+
if (context) {
|
|
204
|
+
let interpCap;
|
|
205
|
+
while (interpCap = interpRegExp.exec(source2)) {
|
|
206
|
+
const [_, expr] = interpCap;
|
|
207
|
+
result += unescape(source2.slice(0, interpCap.index));
|
|
208
|
+
result += interpolate(expr, context);
|
|
209
|
+
source2 = source2.slice(interpCap.index + _.length);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
result += unescape(source2);
|
|
213
|
+
if (result)
|
|
214
|
+
tokens.push(result);
|
|
181
215
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const stack = [Element2(null)];
|
|
216
|
+
__name(pushText, "pushText");
|
|
217
|
+
const stack = [Element2(Element2.Fragment)];
|
|
185
218
|
function rollback(index) {
|
|
186
219
|
for (; index > 0; index--) {
|
|
187
220
|
const { children } = stack.shift();
|
|
@@ -196,7 +229,7 @@ __name(Element, "Element");
|
|
|
196
229
|
stack[0].children.push(Element2("text", { content: token }));
|
|
197
230
|
} else if (token.close) {
|
|
198
231
|
let index = 0;
|
|
199
|
-
while (index < stack.length && stack[index].type !== token.
|
|
232
|
+
while (index < stack.length && stack[index].type !== token.type)
|
|
200
233
|
index++;
|
|
201
234
|
if (index === stack.length) {
|
|
202
235
|
stack[0].children.push(Element2("text", { content: token.source }));
|
|
@@ -206,7 +239,7 @@ __name(Element, "Element");
|
|
|
206
239
|
delete element.source;
|
|
207
240
|
}
|
|
208
241
|
} else {
|
|
209
|
-
const element = Element2(token.
|
|
242
|
+
const element = Element2(token.type, token.attrs);
|
|
210
243
|
stack[0].children.push(element);
|
|
211
244
|
if (!token.empty) {
|
|
212
245
|
element.source = token.source;
|
package/lib/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { Awaitable, camelize, capitalize, defineProperty, Dict, hyphenate, is, isNullable } from 'cosmokit'\n\nconst kElement = Symbol('element')\n\nfunction isElement(source: any): source is Element {\n return source && typeof source === 'object' && source[kElement]\n}\n\nfunction toElement(content: string | Element) {\n if (typeof content !== 'string') return content\n return Element('text', { content })\n}\n\nfunction toElementArray(input: Element.Fragment) {\n if (Array.isArray(input)) {\n return input.map(toElement)\n } else if (typeof input === 'string') {\n return [toElement(input)]\n } else if (!input.type) {\n return input.children\n } else {\n return [input]\n }\n}\n\ninterface Element {\n [kElement]: true\n type: string\n attrs: Dict<string>\n /** @deprecated use `attrs` instead */\n data: Dict<string>\n children: Element[]\n source?: string\n toString(strip?: boolean): string\n}\n\ninterface ElementConstructor extends Element {}\n\nclass ElementConstructor {\n get data() {\n return this.attrs\n }\n\n toString(strip = false) {\n if (this.type === 'text') return Element.escape(this.attrs.content)\n const inner = this.children.map(child => child.toString(strip)).join('')\n if (!this.type || strip) return inner\n const attrs = Object.entries(this.attrs).map(([key, value]) => {\n if (isNullable(value)) return ''\n key = hyphenate(key)\n if (value === '') return ` ${key}`\n return ` ${key}=\"${Element.escape(value, true)}\"`\n }).join('')\n if (!this.children.length) return `<${this.type}${attrs}/>`\n return `<${this.type}${attrs}>${inner}</${this.type}>`\n }\n}\n\ndefineProperty(ElementConstructor, 'name', 'Element')\ndefineProperty(ElementConstructor.prototype, kElement, true)\n\nfunction Element(type: string, children?: Element.Fragment): Element\nfunction Element(type: string, attrs: Dict<any>, children?: Element.Fragment): Element\nfunction Element(type: string, ...args: any[]) {\n const el = Object.create(ElementConstructor.prototype)\n let attrs: Dict<string> = {}, children: Element[] = []\n if (args[0] && typeof args[0] === 'object' && !isElement(args[0]) && !Array.isArray(args[0])) {\n for (const [key, value] of Object.entries(args.shift())) {\n if (isNullable(value)) continue\n if (value === true) {\n attrs[key] = ''\n } else if (value === false) {\n attrs['no' + capitalize(key)] = ''\n } else {\n attrs[key] = '' + value\n }\n }\n }\n if (args[0]) children = toElementArray(args[0])\n return Object.assign(el, { type, attrs, children })\n}\n\nnamespace Element {\n export type Fragment = string | Element | (string | Element)[]\n export type Render<T, S> = (attrs: Dict<any>, children: Element[], session: S) => T\n export type Transformer<S> = boolean | Fragment | Render<boolean | Fragment, S>\n export type AsyncTransformer<S> = boolean | Fragment | Render<Awaitable<boolean | Fragment>, S>\n\n export function normalize(source: Fragment) {\n if (typeof source !== 'string') return toElementArray(source)\n return Element.parse(source)\n }\n\n export function escape(source: string, inline = false) {\n const result = source\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n return inline\n ? result.replace(/\"/g, '"')\n : result\n }\n\n export function unescape(source: string) {\n return source\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/"/g, '\"')\n .replace(/&/g, '&')\n }\n\n export interface FindOptions {\n type?: string\n caret?: boolean\n }\n\n /** @deprecated use `Element.select()` instead */\n export function from(source: string, options: FindOptions = {}): Element {\n const elements = parse(source)\n if (options.caret) {\n if (options.type && elements[0]?.type !== options.type) return\n return elements[0]\n }\n return select(elements, options.type || '*')[0]\n }\n\n type Combinator = ' ' | '>' | '+' | '~'\n\n export interface Selector {\n type: string\n combinator: Combinator\n }\n\n const combRegExp = / *([ >+~]) */g\n\n export function parseSelector(input: string): Selector[][] {\n return input.split(',').map((query) => {\n const selectors: Selector[] = []\n query = query.trim()\n let combCap: RegExpExecArray, combinator: Combinator = ' '\n while ((combCap = combRegExp.exec(query))) {\n selectors.push({ type: query.slice(0, combCap.index), combinator })\n combinator = combCap[1] as Combinator\n query = query.slice(combCap.index + combCap[0].length)\n }\n selectors.push({ type: query, combinator })\n return selectors\n })\n }\n\n export function select(source: string | Element[], query: string | Selector[][]): Element[] {\n if (typeof source === 'string') source = parse(source)\n if (typeof query === 'string') query = parseSelector(query)\n if (!query.length) return\n let adjacent: Selector[][] = []\n const results: Element[] = []\n for (const [index, element] of source.entries()) {\n const inner: Selector[][] = []\n const local = [...query, ...adjacent]\n adjacent = []\n let matched = false\n for (const group of local) {\n const { type, combinator } = group[0]\n if (type === element.type || type === '*') {\n if (group.length === 1) {\n matched = true\n } else if ([' ', '>'].includes(group[1].combinator)) {\n inner.push(group.slice(1))\n } else if (group[1].combinator === '+') {\n adjacent.push(group.slice(1))\n } else {\n query.push(group.slice(1))\n }\n }\n if (combinator === ' ') {\n inner.push(group)\n }\n }\n if (matched) results.push(source[index])\n results.push(...select(element.children, inner))\n }\n return results\n }\n\n const tagRegExp = /<(\\/?)\\s*([^\\s>/]+)([^>]*?)\\s*(\\/?)>/\n const attrRegExp = /([^\\s=]+)(?:=\"([^\"]*)\"|=([^\"\\s]+))?/g\n\n interface Token {\n tag: string\n close: string\n empty: string\n attrs: Dict<string>\n source: string\n }\n\n export function parse(source: string) {\n const tokens: (string | Token)[] = []\n let tagCap: RegExpExecArray\n while ((tagCap = tagRegExp.exec(source))) {\n if (tagCap.index) {\n tokens.push(unescape(source.slice(0, tagCap.index)))\n }\n const [_, close, tag, attrs, empty] = tagCap\n const token: Token = { source: _, tag, close, empty, attrs: {} }\n let attrCap: RegExpExecArray\n while ((attrCap = attrRegExp.exec(attrs))) {\n const [_, key, v1 = '', v2 = v1] = attrCap\n token.attrs[camelize(key)] = unescape(v2)\n }\n tokens.push(token)\n source = source.slice(tagCap.index + tagCap[0].length)\n }\n if (source) tokens.push(unescape(source))\n const stack = [Element(null)]\n function rollback(index: number) {\n for (; index > 0; index--) {\n const { children } = stack.shift()\n const { source } = stack[0].children.pop()\n stack[0].children.push(Element('text', { content: source }))\n stack[0].children.push(...children)\n }\n }\n for (const token of tokens) {\n if (typeof token === 'string') {\n stack[0].children.push(Element('text', { content: token }))\n } else if (token.close) {\n let index = 0\n while (index < stack.length && stack[index].type !== token.tag) index++\n if (index === stack.length) {\n // no matching open tag\n stack[0].children.push(Element('text', { content: token.source }))\n } else {\n rollback(index)\n const element = stack.shift()\n delete element.source\n }\n } else {\n const element = Element(token.tag, token.attrs)\n stack[0].children.push(element)\n if (!token.empty) {\n element.source = token.source\n stack.unshift(element)\n }\n }\n }\n rollback(stack.length - 1)\n return stack[0].children\n }\n\n export function transform<S>(source: string, rules: Dict<Transformer<S>>, session?: S): string\n export function transform<S>(source: Element[], rules: Dict<Transformer<S>>, session?: S): Element[]\n export function transform<S>(source: string | Element[], rules: Dict<Transformer<S>>, session?: S) {\n const elements = typeof source === 'string' ? parse(source) : source\n const output: Element[] = []\n elements.forEach((element) => {\n const { type, attrs, children } = element\n let result = rules[type] ?? rules.default ?? true\n if (typeof result === 'function') {\n result = result(attrs, children, session)\n }\n if (result === true) {\n output.push(Element(type, attrs, transform(children, rules)))\n } else if (result !== false) {\n output.push(...toElementArray(result))\n }\n })\n return typeof source === 'string' ? output.join('') : output\n }\n\n export async function transformAsync<S>(source: string, rules: Dict<AsyncTransformer<S>>, session?: S): Promise<string>\n export async function transformAsync<S>(source: Element[], rules: Dict<AsyncTransformer<S>>, session?: S): Promise<Element[]>\n export async function transformAsync<S>(source: string | Element[], rules: Dict<AsyncTransformer<S>>, session?: S) {\n const elements = typeof source === 'string' ? parse(source) : source\n const children = (await Promise.all(elements.map(async (element) => {\n const { type, attrs, children } = element\n let result = rules[type] ?? rules.default ?? true\n if (typeof result === 'function') {\n result = await result(attrs, children, session)\n }\n if (result === true) {\n return [Element(type, attrs, await transformAsync(children, rules))]\n } else if (result !== false) {\n return toElementArray(result)\n } else {\n return []\n }\n }))).flat(1)\n return typeof source === 'string' ? children.join('') : children\n }\n\n /** @deprecated use `elements.join('')` instead */\n export function join(elements: Element[]) {\n return elements.join('')\n }\n\n export type Factory<R extends any[]> = (...args: [...rest: R, attrs?: Dict<any>]) => Element\n\n function createFactory<R extends any[] = any[]>(type: string, ...keys: string[]): Factory<R> {\n return (...args: any[]) => {\n const element = Element(type)\n keys.forEach((key, index) => {\n if (!isNullable(args[index])) {\n element.attrs[key] = args[index]\n }\n })\n if (args[keys.length]) {\n Object.assign(element.attrs, args[keys.length])\n }\n return element\n }\n }\n\n function createAssetFactory(type: string): Factory<[data: string | Buffer | ArrayBuffer]> {\n return (value, attrs = {}) => {\n if (is('Buffer', value)) {\n value = 'base64://' + value.toString('base64')\n } else if (is('ArrayBuffer', value)) {\n value = 'base64://' + Buffer.from(value).toString('base64')\n }\n return Element(type, { ...attrs, url: value })\n }\n }\n\n export const at = createFactory<[id: any]>('at', 'id')\n export const sharp = createFactory<[id: any]>('sharp', 'id')\n export const quote = createFactory<[id: any]>('quote', 'id')\n export const image = createAssetFactory('image')\n export const video = createAssetFactory('video')\n export const audio = createAssetFactory('audio')\n export const file = createAssetFactory('file')\n}\n\nexport = Element\n"],
|
|
5
|
-
"mappings": ";;;;AAAA,sBAAiG;AAEjG,IAAM,WAAW,OAAO,SAAS;AAEjC,SAAS,UAAU,QAAgC;AACjD,SAAO,UAAU,OAAO,WAAW,YAAY,OAAO;AACxD;AAFS;AAIT,SAAS,UAAU,SAA2B;AAC5C,MAAI,OAAO,YAAY;
|
|
4
|
+
"sourcesContent": ["import { Awaitable, camelize, capitalize, defineProperty, Dict, hyphenate, is, isNullable } from 'cosmokit'\n\nconst kElement = Symbol('element')\n\nfunction isElement(source: any): source is Element {\n return source && typeof source === 'object' && source[kElement]\n}\n\nfunction toElement(content: string | Element) {\n if (typeof content === 'string') {\n if (content) return Element('text', { content })\n } else if (isElement(content)) {\n return content\n } else if (!isNullable(content)) {\n throw new TypeError(`Invalid content: ${content}`)\n }\n}\n\nfunction toElementArray(content: Element.Fragment) {\n if (Array.isArray(content)) {\n return content.map(toElement).filter(x => x)\n } else {\n return [toElement(content)].filter(x => x)\n }\n}\n\ninterface Element {\n [kElement]: true\n type: string\n attrs: Dict<string>\n /** @deprecated use `attrs` instead */\n data: Dict<string>\n children: Element[]\n source?: string\n toString(strip?: boolean): string\n}\n\ninterface ElementConstructor extends Element {}\n\nclass ElementConstructor {\n get data() {\n return this.attrs\n }\n\n toString(strip = false) {\n if (this.type === 'text') return Element.escape(this.attrs.content)\n const inner = this.children.map(child => child.toString(strip)).join('')\n if (strip) return inner\n const attrs = Object.entries(this.attrs).map(([key, value]) => {\n key = hyphenate(key)\n if (value === '') return ` ${key}`\n return ` ${key}=\"${Element.escape(value, true)}\"`\n }).join('')\n if (!this.children.length) return `<${this.type}${attrs}/>`\n return `<${this.type}${attrs}>${inner}</${this.type}>`\n }\n}\n\ndefineProperty(ElementConstructor, 'name', 'Element')\ndefineProperty(ElementConstructor.prototype, kElement, true)\n\nfunction Element(type: string, ...children: Element.Fragment[]): Element\nfunction Element(type: string, attrs: Dict, ...children: Element.Fragment[]): Element\nfunction Element(type: string, ...args: any[]) {\n const el = Object.create(ElementConstructor.prototype)\n let attrs: Dict<string> = {}, children: Element[] = []\n if (args[0] && typeof args[0] === 'object' && !isElement(args[0]) && !Array.isArray(args[0])) {\n for (const [key, value] of Object.entries(args.shift())) {\n if (isNullable(value)) continue\n // https://github.com/reactjs/rfcs/pull/107\n if (key === 'children') {\n children = toElementArray(value as Element.Fragment)\n } else if (value === true) {\n attrs[key] = ''\n } else if (value === false) {\n attrs['no' + capitalize(key)] = ''\n } else if (!isNullable(value)) {\n attrs[key] = '' + value\n }\n }\n }\n for (const child of args) {\n children.push(...toElementArray(child))\n }\n return Object.assign(el, { type, attrs, children })\n}\n\n// eslint-disable-next-line no-new-func\nconst interpolate = new Function('expr', 'context', `\n try {\n with (context) {\n const result = eval(expr)\n return result === undefined || result === null ? '' : result\n }\n } catch {\n return ''\n }\n`) as ((expr: string, context: object) => string)\n\nnamespace Element {\n export const jsx = Element\n export const jsxs = Element\n export const jsxDEV = Element\n export const Fragment = 'template'\n\n export type Fragment = string | Element | (string | Element)[]\n export type Render<T, S> = (attrs: Dict<any>, children: Element[], session: S) => T\n export type Transformer<S> = boolean | Fragment | Render<boolean | Fragment, S>\n export type AsyncTransformer<S> = boolean | Fragment | Render<Awaitable<boolean | Fragment>, S>\n\n export function normalize(source: Fragment) {\n if (typeof source !== 'string') return toElementArray(source)\n return Element.parse(source)\n }\n\n export function escape(source: string, inline = false) {\n const result = source\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n return inline\n ? result.replace(/\"/g, '"')\n : result\n }\n\n export function unescape(source: string) {\n return source\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/"/g, '\"')\n .replace(/&#(\\d+);/g, (_, code) => code === '38' ? _ : String.fromCharCode(+code))\n .replace(/&#x([0-9a-f]+);/gi, (_, code) => code === '26' ? _ : String.fromCharCode(parseInt(code, 16)))\n .replace(/&(amp|#38|#x26);/g, '&')\n }\n\n export interface FindOptions {\n type?: string\n caret?: boolean\n }\n\n /** @deprecated use `Element.select()` instead */\n export function from(source: string, options: FindOptions = {}): Element {\n const elements = parse(source)\n if (options.caret) {\n if (options.type && elements[0]?.type !== options.type) return\n return elements[0]\n }\n return select(elements, options.type || '*')[0]\n }\n\n type Combinator = ' ' | '>' | '+' | '~'\n\n export interface Selector {\n type: string\n combinator: Combinator\n }\n\n const combRegExp = / *([ >+~]) */g\n\n export function parseSelector(input: string): Selector[][] {\n return input.split(',').map((query) => {\n const selectors: Selector[] = []\n query = query.trim()\n let combCap: RegExpExecArray, combinator: Combinator = ' '\n while ((combCap = combRegExp.exec(query))) {\n selectors.push({ type: query.slice(0, combCap.index), combinator })\n combinator = combCap[1] as Combinator\n query = query.slice(combCap.index + combCap[0].length)\n }\n selectors.push({ type: query, combinator })\n return selectors\n })\n }\n\n export function select(source: string | Element[], query: string | Selector[][]): Element[] {\n if (typeof source === 'string') source = parse(source)\n if (typeof query === 'string') query = parseSelector(query)\n if (!query.length) return\n let adjacent: Selector[][] = []\n const results: Element[] = []\n for (const [index, element] of source.entries()) {\n const inner: Selector[][] = []\n const local = [...query, ...adjacent]\n adjacent = []\n let matched = false\n for (const group of local) {\n const { type, combinator } = group[0]\n if (type === element.type || type === '*') {\n if (group.length === 1) {\n matched = true\n } else if ([' ', '>'].includes(group[1].combinator)) {\n inner.push(group.slice(1))\n } else if (group[1].combinator === '+') {\n adjacent.push(group.slice(1))\n } else {\n query.push(group.slice(1))\n }\n }\n if (combinator === ' ') {\n inner.push(group)\n }\n }\n if (matched) results.push(source[index])\n results.push(...select(element.children, inner))\n }\n return results\n }\n\n const tagRegExp = /<(\\/?)\\s*([^\\s>/]*)([^>]*?)\\s*(\\/?)>/\n const attrRegExp1 = /([^\\s=]+)(?:=\"([^\"]*)\"|='([^']*)')?/g\n const attrRegExp2 = /([^\\s=]+)(?:=\"([^\"]*)\"|='([^']*)'|=\\{([^}]+)\\})?/g\n const interpRegExp = /\\{([^}]+)\\}/g\n\n interface Token {\n type: string\n close: string\n empty: string\n attrs: Dict<string>\n source: string\n }\n\n export function parse(source: string, context?: any) {\n const tokens: (string | Token)[] = []\n const attrRegExp = context ? attrRegExp2 : attrRegExp1\n let tagCap: RegExpExecArray\n while ((tagCap = tagRegExp.exec(source))) {\n pushText(source.slice(0, tagCap.index))\n const [_, close, type, attrs, empty] = tagCap\n const token: Token = { source: _, type: type || Fragment, close, empty, attrs: {} }\n let attrCap: RegExpExecArray\n while ((attrCap = attrRegExp.exec(attrs))) {\n const [_, key, v1 = '', v2 = v1, v3] = attrCap\n token.attrs[camelize(key)] = v3\n ? interpolate(v3, context)\n : unescape(v2)\n }\n tokens.push(token)\n source = source.slice(tagCap.index + _.length)\n }\n\n pushText(source)\n function pushText(source: string) {\n source = source\n .replace(/^\\s*\\n\\s*/, '')\n .replace(/\\s*\\n\\s*$/, '')\n let result = ''\n if (context) {\n let interpCap: RegExpExecArray\n while ((interpCap = interpRegExp.exec(source))) {\n const [_, expr] = interpCap\n result += unescape(source.slice(0, interpCap.index))\n result += interpolate(expr, context)\n source = source.slice(interpCap.index + _.length)\n }\n }\n result += unescape(source)\n if (result) tokens.push(result)\n }\n\n const stack = [Element(Fragment)]\n function rollback(index: number) {\n for (; index > 0; index--) {\n const { children } = stack.shift()\n const { source } = stack[0].children.pop()\n stack[0].children.push(Element('text', { content: source }))\n stack[0].children.push(...children)\n }\n }\n\n for (const token of tokens) {\n if (typeof token === 'string') {\n stack[0].children.push(Element('text', { content: token }))\n } else if (token.close) {\n let index = 0\n while (index < stack.length && stack[index].type !== token.type) index++\n if (index === stack.length) {\n // no matching open tag\n stack[0].children.push(Element('text', { content: token.source }))\n } else {\n rollback(index)\n const element = stack.shift()\n delete element.source\n }\n } else {\n const element = Element(token.type, token.attrs)\n stack[0].children.push(element)\n if (!token.empty) {\n element.source = token.source\n stack.unshift(element)\n }\n }\n }\n rollback(stack.length - 1)\n return stack[0].children\n }\n\n export function transform<S>(source: string, rules: Dict<Transformer<S>>, session?: S): string\n export function transform<S>(source: Element[], rules: Dict<Transformer<S>>, session?: S): Element[]\n export function transform<S>(source: string | Element[], rules: Dict<Transformer<S>>, session?: S) {\n const elements = typeof source === 'string' ? parse(source) : source\n const output: Element[] = []\n elements.forEach((element) => {\n const { type, attrs, children } = element\n let result = rules[type] ?? rules.default ?? true\n if (typeof result === 'function') {\n result = result(attrs, children, session)\n }\n if (result === true) {\n output.push(Element(type, attrs, transform(children, rules)))\n } else if (result !== false) {\n output.push(...toElementArray(result))\n }\n })\n return typeof source === 'string' ? output.join('') : output\n }\n\n export async function transformAsync<S>(source: string, rules: Dict<AsyncTransformer<S>>, session?: S): Promise<string>\n export async function transformAsync<S>(source: Element[], rules: Dict<AsyncTransformer<S>>, session?: S): Promise<Element[]>\n export async function transformAsync<S>(source: string | Element[], rules: Dict<AsyncTransformer<S>>, session?: S) {\n const elements = typeof source === 'string' ? parse(source) : source\n const children = (await Promise.all(elements.map(async (element) => {\n const { type, attrs, children } = element\n let result = rules[type] ?? rules.default ?? true\n if (typeof result === 'function') {\n result = await result(attrs, children, session)\n }\n if (result === true) {\n return [Element(type, attrs, await transformAsync(children, rules))]\n } else if (result !== false) {\n return toElementArray(result)\n } else {\n return []\n }\n }))).flat(1)\n return typeof source === 'string' ? children.join('') : children\n }\n\n /** @deprecated use `elements.join('')` instead */\n export function join(elements: Element[]) {\n return elements.join('')\n }\n\n export type Factory<R extends any[]> = (...args: [...rest: R, attrs?: Dict<any>]) => Element\n\n function createFactory<R extends any[] = any[]>(type: string, ...keys: string[]): Factory<R> {\n return (...args: any[]) => {\n const element = Element(type)\n keys.forEach((key, index) => {\n if (!isNullable(args[index])) {\n element.attrs[key] = args[index]\n }\n })\n if (args[keys.length]) {\n Object.assign(element.attrs, args[keys.length])\n }\n return element\n }\n }\n\n function createAssetFactory(type: string): Factory<[data: string | Buffer | ArrayBuffer]> {\n return (value, attrs = {}) => {\n if (is('Buffer', value)) {\n value = 'base64://' + value.toString('base64')\n } else if (is('ArrayBuffer', value)) {\n value = 'base64://' + Buffer.from(value).toString('base64')\n }\n return Element(type, { ...attrs, url: value })\n }\n }\n\n export const at = createFactory<[id: any]>('at', 'id')\n export const sharp = createFactory<[id: any]>('sharp', 'id')\n export const quote = createFactory<[id: any]>('quote', 'id')\n export const image = createAssetFactory('image')\n export const video = createAssetFactory('video')\n export const audio = createAssetFactory('audio')\n export const file = createAssetFactory('file')\n}\n\nexport = Element\n"],
|
|
5
|
+
"mappings": ";;;;AAAA,sBAAiG;AAEjG,IAAM,WAAW,OAAO,SAAS;AAEjC,SAAS,UAAU,QAAgC;AACjD,SAAO,UAAU,OAAO,WAAW,YAAY,OAAO;AACxD;AAFS;AAIT,S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AgB;AACzB,YAAM,UAAUA,SAAQ,IAAI;AAC5B,WAAK,QAAQ,CAAC,KAAK,UAAU;AAC3B,YAAI,KAAC,4BAAW,KAAK,MAAM,GAAG;AAC5B,kBAAQ,MAAM,OAAO,KAAK;AAAA,QAC5B;AAAA,MACF,CAAC;AACD,UAAI,KAAK,KAAK,SAAS;AACrB,eAAO,OAAO,QAAQ,OAAO,KAAK,KAAK,OAAO;AAAA,MAChD;AACA,aAAO;AAAA,IACT;AAAA,EACF;AAbS;AAeT,WAAS,mBAAmB,MAA8D;AACxF,WAAO,CAAC,OAAO,QAAQ,CAAC,MAAM;AAC5B,cAAI,oBAAG,UAAU,KAAK,GAAG;AACvB,gBAAQ,cAAc,MAAM,SAAS,QAAQ;AAAA,MAC/C,eAAW,oBAAG,eAAe,KAAK,GAAG;AACnC,gBAAQ,cAAc,OAAO,KAAK,KAAK,EAAE,SAAS,QAAQ;AAAA,MAC5D;AACA,aAAOA,SAAQ,MAAM,EAAE,GAAG,OAAO,KAAK,MAAM,CAAC;AAAA,IAC/C;AAAA,EACF;AATS;AAWF,EAAMA,SAAA,KAAK,cAAyB,MAAM,IAAI;AAC9C,EAAMA,SAAA,QAAQ,cAAyB,SAAS,IAAI;AACpD,EAAMA,SAAA,QAAQ,cAAyB,SAAS,IAAI;AACpD,EAAMA,SAAA,QAAQ,mBAAmB,OAAO;AACxC,EAAMA,SAAA,QAAQ,mBAAmB,OAAO;AACxC,EAAMA,SAAA,QAAQ,mBAAmB,OAAO;AACxC,EAAMA,SAAA,OAAO,mBAAmB,MAAM;AAAA,GArRrC;AAwRV,iBAAS;",
|
|
6
6
|
"names": ["Element", "_", "source", "children"]
|
|
7
7
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -11,9 +11,13 @@ interface Element {
|
|
|
11
11
|
source?: string;
|
|
12
12
|
toString(strip?: boolean): string;
|
|
13
13
|
}
|
|
14
|
-
declare function Element(type: string, children
|
|
15
|
-
declare function Element(type: string, attrs: Dict
|
|
14
|
+
declare function Element(type: string, ...children: Element.Fragment[]): Element;
|
|
15
|
+
declare function Element(type: string, attrs: Dict, ...children: Element.Fragment[]): Element;
|
|
16
16
|
declare namespace Element {
|
|
17
|
+
export const jsx: typeof Element;
|
|
18
|
+
export const jsxs: typeof Element;
|
|
19
|
+
export const jsxDEV: typeof Element;
|
|
20
|
+
export const Fragment = "template";
|
|
17
21
|
export type Fragment = string | Element | (string | Element)[];
|
|
18
22
|
export type Render<T, S> = (attrs: Dict<any>, children: Element[], session: S) => T;
|
|
19
23
|
export type Transformer<S> = boolean | Fragment | Render<boolean | Fragment, S>;
|
|
@@ -34,7 +38,7 @@ declare namespace Element {
|
|
|
34
38
|
}
|
|
35
39
|
export function parseSelector(input: string): Selector[][];
|
|
36
40
|
export function select(source: string | Element[], query: string | Selector[][]): Element[];
|
|
37
|
-
export function parse(source: string): Element[];
|
|
41
|
+
export function parse(source: string, context?: any): Element[];
|
|
38
42
|
export function transform<S>(source: string, rules: Dict<Transformer<S>>, session?: S): string;
|
|
39
43
|
export function transform<S>(source: Element[], rules: Dict<Transformer<S>>, session?: S): Element[];
|
|
40
44
|
export function transformAsync<S>(source: string, rules: Dict<AsyncTransformer<S>>, session?: S): Promise<string>;
|
package/lib/index.mjs
CHANGED
|
@@ -15,20 +15,21 @@ var require_src = __commonJS({
|
|
|
15
15
|
}
|
|
16
16
|
__name(isElement, "isElement");
|
|
17
17
|
function toElement(content) {
|
|
18
|
-
if (typeof content
|
|
18
|
+
if (typeof content === "string") {
|
|
19
|
+
if (content)
|
|
20
|
+
return Element("text", { content });
|
|
21
|
+
} else if (isElement(content)) {
|
|
19
22
|
return content;
|
|
20
|
-
|
|
23
|
+
} else if (!isNullable(content)) {
|
|
24
|
+
throw new TypeError(`Invalid content: ${content}`);
|
|
25
|
+
}
|
|
21
26
|
}
|
|
22
27
|
__name(toElement, "toElement");
|
|
23
|
-
function toElementArray(
|
|
24
|
-
if (Array.isArray(
|
|
25
|
-
return
|
|
26
|
-
} else if (typeof input === "string") {
|
|
27
|
-
return [toElement(input)];
|
|
28
|
-
} else if (!input.type) {
|
|
29
|
-
return input.children;
|
|
28
|
+
function toElementArray(content) {
|
|
29
|
+
if (Array.isArray(content)) {
|
|
30
|
+
return content.map(toElement).filter((x) => x);
|
|
30
31
|
} else {
|
|
31
|
-
return [
|
|
32
|
+
return [toElement(content)].filter((x) => x);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
__name(toElementArray, "toElementArray");
|
|
@@ -40,11 +41,9 @@ var require_src = __commonJS({
|
|
|
40
41
|
if (this.type === "text")
|
|
41
42
|
return Element.escape(this.attrs.content);
|
|
42
43
|
const inner = this.children.map((child) => child.toString(strip)).join("");
|
|
43
|
-
if (
|
|
44
|
+
if (strip)
|
|
44
45
|
return inner;
|
|
45
46
|
const attrs = Object.entries(this.attrs).map(([key, value]) => {
|
|
46
|
-
if (isNullable(value))
|
|
47
|
-
return "";
|
|
48
47
|
key = hyphenate(key);
|
|
49
48
|
if (value === "")
|
|
50
49
|
return ` ${key}`;
|
|
@@ -65,21 +64,38 @@ var require_src = __commonJS({
|
|
|
65
64
|
for (const [key, value] of Object.entries(args.shift())) {
|
|
66
65
|
if (isNullable(value))
|
|
67
66
|
continue;
|
|
68
|
-
if (
|
|
67
|
+
if (key === "children") {
|
|
68
|
+
children = toElementArray(value);
|
|
69
|
+
} else if (value === true) {
|
|
69
70
|
attrs[key] = "";
|
|
70
71
|
} else if (value === false) {
|
|
71
72
|
attrs["no" + capitalize(key)] = "";
|
|
72
|
-
} else {
|
|
73
|
+
} else if (!isNullable(value)) {
|
|
73
74
|
attrs[key] = "" + value;
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
-
children
|
|
78
|
+
for (const child of args) {
|
|
79
|
+
children.push(...toElementArray(child));
|
|
80
|
+
}
|
|
79
81
|
return Object.assign(el, { type, attrs, children });
|
|
80
82
|
}
|
|
81
83
|
__name(Element, "Element");
|
|
84
|
+
var interpolate = new Function("expr", "context", `
|
|
85
|
+
try {
|
|
86
|
+
with (context) {
|
|
87
|
+
const result = eval(expr)
|
|
88
|
+
return result === undefined || result === null ? '' : result
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
return ''
|
|
92
|
+
}
|
|
93
|
+
`);
|
|
82
94
|
((Element2) => {
|
|
95
|
+
Element2.jsx = Element2;
|
|
96
|
+
Element2.jsxs = Element2;
|
|
97
|
+
Element2.jsxDEV = Element2;
|
|
98
|
+
Element2.Fragment = "template";
|
|
83
99
|
function normalize(source) {
|
|
84
100
|
if (typeof source !== "string")
|
|
85
101
|
return toElementArray(source);
|
|
@@ -94,7 +110,7 @@ var require_src = __commonJS({
|
|
|
94
110
|
Element2.escape = escape;
|
|
95
111
|
__name(escape, "escape");
|
|
96
112
|
function unescape(source) {
|
|
97
|
-
return source.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/&/g, "&");
|
|
113
|
+
return source.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/&#(\d+);/g, (_, code) => code === "38" ? _ : String.fromCharCode(+code)).replace(/&#x([0-9a-f]+);/gi, (_, code) => code === "26" ? _ : String.fromCharCode(parseInt(code, 16))).replace(/&(amp|#38|#x26);/g, "&");
|
|
98
114
|
}
|
|
99
115
|
Element2.unescape = unescape;
|
|
100
116
|
__name(unescape, "unescape");
|
|
@@ -165,28 +181,45 @@ var require_src = __commonJS({
|
|
|
165
181
|
}
|
|
166
182
|
Element2.select = select;
|
|
167
183
|
__name(select, "select");
|
|
168
|
-
const tagRegExp = /<(\/?)\s*([^\s>/]
|
|
169
|
-
const
|
|
170
|
-
|
|
184
|
+
const tagRegExp = /<(\/?)\s*([^\s>/]*)([^>]*?)\s*(\/?)>/;
|
|
185
|
+
const attrRegExp1 = /([^\s=]+)(?:="([^"]*)"|='([^']*)')?/g;
|
|
186
|
+
const attrRegExp2 = /([^\s=]+)(?:="([^"]*)"|='([^']*)'|=\{([^}]+)\})?/g;
|
|
187
|
+
const interpRegExp = /\{([^}]+)\}/g;
|
|
188
|
+
function parse(source, context) {
|
|
171
189
|
const tokens = [];
|
|
190
|
+
const attrRegExp = context ? attrRegExp2 : attrRegExp1;
|
|
172
191
|
let tagCap;
|
|
173
192
|
while (tagCap = tagRegExp.exec(source)) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
const [_, close, tag, attrs, empty] = tagCap;
|
|
178
|
-
const token = { source: _, tag, close, empty, attrs: {} };
|
|
193
|
+
pushText(source.slice(0, tagCap.index));
|
|
194
|
+
const [_, close, type, attrs, empty] = tagCap;
|
|
195
|
+
const token = { source: _, type: type || Element2.Fragment, close, empty, attrs: {} };
|
|
179
196
|
let attrCap;
|
|
180
197
|
while (attrCap = attrRegExp.exec(attrs)) {
|
|
181
|
-
const [_2, key, v1 = "", v2 = v1] = attrCap;
|
|
182
|
-
token.attrs[camelize(key)] = unescape(v2);
|
|
198
|
+
const [_2, key, v1 = "", v2 = v1, v3] = attrCap;
|
|
199
|
+
token.attrs[camelize(key)] = v3 ? interpolate(v3, context) : unescape(v2);
|
|
183
200
|
}
|
|
184
201
|
tokens.push(token);
|
|
185
|
-
source = source.slice(tagCap.index +
|
|
202
|
+
source = source.slice(tagCap.index + _.length);
|
|
203
|
+
}
|
|
204
|
+
pushText(source);
|
|
205
|
+
function pushText(source2) {
|
|
206
|
+
source2 = source2.replace(/^\s*\n\s*/, "").replace(/\s*\n\s*$/, "");
|
|
207
|
+
let result = "";
|
|
208
|
+
if (context) {
|
|
209
|
+
let interpCap;
|
|
210
|
+
while (interpCap = interpRegExp.exec(source2)) {
|
|
211
|
+
const [_, expr] = interpCap;
|
|
212
|
+
result += unescape(source2.slice(0, interpCap.index));
|
|
213
|
+
result += interpolate(expr, context);
|
|
214
|
+
source2 = source2.slice(interpCap.index + _.length);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
result += unescape(source2);
|
|
218
|
+
if (result)
|
|
219
|
+
tokens.push(result);
|
|
186
220
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const stack = [Element2(null)];
|
|
221
|
+
__name(pushText, "pushText");
|
|
222
|
+
const stack = [Element2(Element2.Fragment)];
|
|
190
223
|
function rollback(index) {
|
|
191
224
|
for (; index > 0; index--) {
|
|
192
225
|
const { children } = stack.shift();
|
|
@@ -201,7 +234,7 @@ var require_src = __commonJS({
|
|
|
201
234
|
stack[0].children.push(Element2("text", { content: token }));
|
|
202
235
|
} else if (token.close) {
|
|
203
236
|
let index = 0;
|
|
204
|
-
while (index < stack.length && stack[index].type !== token.
|
|
237
|
+
while (index < stack.length && stack[index].type !== token.type)
|
|
205
238
|
index++;
|
|
206
239
|
if (index === stack.length) {
|
|
207
240
|
stack[0].children.push(Element2("text", { content: token.source }));
|
|
@@ -211,7 +244,7 @@ var require_src = __commonJS({
|
|
|
211
244
|
delete element.source;
|
|
212
245
|
}
|
|
213
246
|
} else {
|
|
214
|
-
const element = Element2(token.
|
|
247
|
+
const element = Element2(token.type, token.attrs);
|
|
215
248
|
stack[0].children.push(element);
|
|
216
249
|
if (!token.empty) {
|
|
217
250
|
element.source = token.source;
|
package/lib/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { Awaitable, camelize, capitalize, defineProperty, Dict, hyphenate, is, isNullable } from 'cosmokit'\n\nconst kElement = Symbol('element')\n\nfunction isElement(source: any): source is Element {\n return source && typeof source === 'object' && source[kElement]\n}\n\nfunction toElement(content: string | Element) {\n if (typeof content !== 'string') return content\n return Element('text', { content })\n}\n\nfunction toElementArray(input: Element.Fragment) {\n if (Array.isArray(input)) {\n return input.map(toElement)\n } else if (typeof input === 'string') {\n return [toElement(input)]\n } else if (!input.type) {\n return input.children\n } else {\n return [input]\n }\n}\n\ninterface Element {\n [kElement]: true\n type: string\n attrs: Dict<string>\n /** @deprecated use `attrs` instead */\n data: Dict<string>\n children: Element[]\n source?: string\n toString(strip?: boolean): string\n}\n\ninterface ElementConstructor extends Element {}\n\nclass ElementConstructor {\n get data() {\n return this.attrs\n }\n\n toString(strip = false) {\n if (this.type === 'text') return Element.escape(this.attrs.content)\n const inner = this.children.map(child => child.toString(strip)).join('')\n if (!this.type || strip) return inner\n const attrs = Object.entries(this.attrs).map(([key, value]) => {\n if (isNullable(value)) return ''\n key = hyphenate(key)\n if (value === '') return ` ${key}`\n return ` ${key}=\"${Element.escape(value, true)}\"`\n }).join('')\n if (!this.children.length) return `<${this.type}${attrs}/>`\n return `<${this.type}${attrs}>${inner}</${this.type}>`\n }\n}\n\ndefineProperty(ElementConstructor, 'name', 'Element')\ndefineProperty(ElementConstructor.prototype, kElement, true)\n\nfunction Element(type: string, children?: Element.Fragment): Element\nfunction Element(type: string, attrs: Dict<any>, children?: Element.Fragment): Element\nfunction Element(type: string, ...args: any[]) {\n const el = Object.create(ElementConstructor.prototype)\n let attrs: Dict<string> = {}, children: Element[] = []\n if (args[0] && typeof args[0] === 'object' && !isElement(args[0]) && !Array.isArray(args[0])) {\n for (const [key, value] of Object.entries(args.shift())) {\n if (isNullable(value)) continue\n if (value === true) {\n attrs[key] = ''\n } else if (value === false) {\n attrs['no' + capitalize(key)] = ''\n } else {\n attrs[key] = '' + value\n }\n }\n }\n if (args[0]) children = toElementArray(args[0])\n return Object.assign(el, { type, attrs, children })\n}\n\nnamespace Element {\n export type Fragment = string | Element | (string | Element)[]\n export type Render<T, S> = (attrs: Dict<any>, children: Element[], session: S) => T\n export type Transformer<S> = boolean | Fragment | Render<boolean | Fragment, S>\n export type AsyncTransformer<S> = boolean | Fragment | Render<Awaitable<boolean | Fragment>, S>\n\n export function normalize(source: Fragment) {\n if (typeof source !== 'string') return toElementArray(source)\n return Element.parse(source)\n }\n\n export function escape(source: string, inline = false) {\n const result = source\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n return inline\n ? result.replace(/\"/g, '"')\n : result\n }\n\n export function unescape(source: string) {\n return source\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/"/g, '\"')\n .replace(/&/g, '&')\n }\n\n export interface FindOptions {\n type?: string\n caret?: boolean\n }\n\n /** @deprecated use `Element.select()` instead */\n export function from(source: string, options: FindOptions = {}): Element {\n const elements = parse(source)\n if (options.caret) {\n if (options.type && elements[0]?.type !== options.type) return\n return elements[0]\n }\n return select(elements, options.type || '*')[0]\n }\n\n type Combinator = ' ' | '>' | '+' | '~'\n\n export interface Selector {\n type: string\n combinator: Combinator\n }\n\n const combRegExp = / *([ >+~]) */g\n\n export function parseSelector(input: string): Selector[][] {\n return input.split(',').map((query) => {\n const selectors: Selector[] = []\n query = query.trim()\n let combCap: RegExpExecArray, combinator: Combinator = ' '\n while ((combCap = combRegExp.exec(query))) {\n selectors.push({ type: query.slice(0, combCap.index), combinator })\n combinator = combCap[1] as Combinator\n query = query.slice(combCap.index + combCap[0].length)\n }\n selectors.push({ type: query, combinator })\n return selectors\n })\n }\n\n export function select(source: string | Element[], query: string | Selector[][]): Element[] {\n if (typeof source === 'string') source = parse(source)\n if (typeof query === 'string') query = parseSelector(query)\n if (!query.length) return\n let adjacent: Selector[][] = []\n const results: Element[] = []\n for (const [index, element] of source.entries()) {\n const inner: Selector[][] = []\n const local = [...query, ...adjacent]\n adjacent = []\n let matched = false\n for (const group of local) {\n const { type, combinator } = group[0]\n if (type === element.type || type === '*') {\n if (group.length === 1) {\n matched = true\n } else if ([' ', '>'].includes(group[1].combinator)) {\n inner.push(group.slice(1))\n } else if (group[1].combinator === '+') {\n adjacent.push(group.slice(1))\n } else {\n query.push(group.slice(1))\n }\n }\n if (combinator === ' ') {\n inner.push(group)\n }\n }\n if (matched) results.push(source[index])\n results.push(...select(element.children, inner))\n }\n return results\n }\n\n const tagRegExp = /<(\\/?)\\s*([^\\s>/]+)([^>]*?)\\s*(\\/?)>/\n const attrRegExp = /([^\\s=]+)(?:=\"([^\"]*)\"|=([^\"\\s]+))?/g\n\n interface Token {\n tag: string\n close: string\n empty: string\n attrs: Dict<string>\n source: string\n }\n\n export function parse(source: string) {\n const tokens: (string | Token)[] = []\n let tagCap: RegExpExecArray\n while ((tagCap = tagRegExp.exec(source))) {\n if (tagCap.index) {\n tokens.push(unescape(source.slice(0, tagCap.index)))\n }\n const [_, close, tag, attrs, empty] = tagCap\n const token: Token = { source: _, tag, close, empty, attrs: {} }\n let attrCap: RegExpExecArray\n while ((attrCap = attrRegExp.exec(attrs))) {\n const [_, key, v1 = '', v2 = v1] = attrCap\n token.attrs[camelize(key)] = unescape(v2)\n }\n tokens.push(token)\n source = source.slice(tagCap.index + tagCap[0].length)\n }\n if (source) tokens.push(unescape(source))\n const stack = [Element(null)]\n function rollback(index: number) {\n for (; index > 0; index--) {\n const { children } = stack.shift()\n const { source } = stack[0].children.pop()\n stack[0].children.push(Element('text', { content: source }))\n stack[0].children.push(...children)\n }\n }\n for (const token of tokens) {\n if (typeof token === 'string') {\n stack[0].children.push(Element('text', { content: token }))\n } else if (token.close) {\n let index = 0\n while (index < stack.length && stack[index].type !== token.tag) index++\n if (index === stack.length) {\n // no matching open tag\n stack[0].children.push(Element('text', { content: token.source }))\n } else {\n rollback(index)\n const element = stack.shift()\n delete element.source\n }\n } else {\n const element = Element(token.tag, token.attrs)\n stack[0].children.push(element)\n if (!token.empty) {\n element.source = token.source\n stack.unshift(element)\n }\n }\n }\n rollback(stack.length - 1)\n return stack[0].children\n }\n\n export function transform<S>(source: string, rules: Dict<Transformer<S>>, session?: S): string\n export function transform<S>(source: Element[], rules: Dict<Transformer<S>>, session?: S): Element[]\n export function transform<S>(source: string | Element[], rules: Dict<Transformer<S>>, session?: S) {\n const elements = typeof source === 'string' ? parse(source) : source\n const output: Element[] = []\n elements.forEach((element) => {\n const { type, attrs, children } = element\n let result = rules[type] ?? rules.default ?? true\n if (typeof result === 'function') {\n result = result(attrs, children, session)\n }\n if (result === true) {\n output.push(Element(type, attrs, transform(children, rules)))\n } else if (result !== false) {\n output.push(...toElementArray(result))\n }\n })\n return typeof source === 'string' ? output.join('') : output\n }\n\n export async function transformAsync<S>(source: string, rules: Dict<AsyncTransformer<S>>, session?: S): Promise<string>\n export async function transformAsync<S>(source: Element[], rules: Dict<AsyncTransformer<S>>, session?: S): Promise<Element[]>\n export async function transformAsync<S>(source: string | Element[], rules: Dict<AsyncTransformer<S>>, session?: S) {\n const elements = typeof source === 'string' ? parse(source) : source\n const children = (await Promise.all(elements.map(async (element) => {\n const { type, attrs, children } = element\n let result = rules[type] ?? rules.default ?? true\n if (typeof result === 'function') {\n result = await result(attrs, children, session)\n }\n if (result === true) {\n return [Element(type, attrs, await transformAsync(children, rules))]\n } else if (result !== false) {\n return toElementArray(result)\n } else {\n return []\n }\n }))).flat(1)\n return typeof source === 'string' ? children.join('') : children\n }\n\n /** @deprecated use `elements.join('')` instead */\n export function join(elements: Element[]) {\n return elements.join('')\n }\n\n export type Factory<R extends any[]> = (...args: [...rest: R, attrs?: Dict<any>]) => Element\n\n function createFactory<R extends any[] = any[]>(type: string, ...keys: string[]): Factory<R> {\n return (...args: any[]) => {\n const element = Element(type)\n keys.forEach((key, index) => {\n if (!isNullable(args[index])) {\n element.attrs[key] = args[index]\n }\n })\n if (args[keys.length]) {\n Object.assign(element.attrs, args[keys.length])\n }\n return element\n }\n }\n\n function createAssetFactory(type: string): Factory<[data: string | Buffer | ArrayBuffer]> {\n return (value, attrs = {}) => {\n if (is('Buffer', value)) {\n value = 'base64://' + value.toString('base64')\n } else if (is('ArrayBuffer', value)) {\n value = 'base64://' + Buffer.from(value).toString('base64')\n }\n return Element(type, { ...attrs, url: value })\n }\n }\n\n export const at = createFactory<[id: any]>('at', 'id')\n export const sharp = createFactory<[id: any]>('sharp', 'id')\n export const quote = createFactory<[id: any]>('quote', 'id')\n export const image = createAssetFactory('image')\n export const video = createAssetFactory('video')\n export const audio = createAssetFactory('audio')\n export const file = createAssetFactory('file')\n}\n\nexport = Element\n"],
|
|
5
|
-
"mappings": ";;;;;;;;AAAA,SAAoB,UAAU,YAAY,gBAAsB,WAAW,IAAI,kBAAkB;AAAjG;AAAA;AAEA,QAAM,WAAW,OAAO,SAAS;AAEjC,aAAS,UAAU,QAAgC;AACjD,aAAO,UAAU,OAAO,WAAW,YAAY,OAAO;AAAA,IACxD;AAFS;AAIT,aAAS,UAAU,SAA2B;AAC5C,UAAI,OAAO,YAAY;
|
|
4
|
+
"sourcesContent": ["import { Awaitable, camelize, capitalize, defineProperty, Dict, hyphenate, is, isNullable } from 'cosmokit'\n\nconst kElement = Symbol('element')\n\nfunction isElement(source: any): source is Element {\n return source && typeof source === 'object' && source[kElement]\n}\n\nfunction toElement(content: string | Element) {\n if (typeof content === 'string') {\n if (content) return Element('text', { content })\n } else if (isElement(content)) {\n return content\n } else if (!isNullable(content)) {\n throw new TypeError(`Invalid content: ${content}`)\n }\n}\n\nfunction toElementArray(content: Element.Fragment) {\n if (Array.isArray(content)) {\n return content.map(toElement).filter(x => x)\n } else {\n return [toElement(content)].filter(x => x)\n }\n}\n\ninterface Element {\n [kElement]: true\n type: string\n attrs: Dict<string>\n /** @deprecated use `attrs` instead */\n data: Dict<string>\n children: Element[]\n source?: string\n toString(strip?: boolean): string\n}\n\ninterface ElementConstructor extends Element {}\n\nclass ElementConstructor {\n get data() {\n return this.attrs\n }\n\n toString(strip = false) {\n if (this.type === 'text') return Element.escape(this.attrs.content)\n const inner = this.children.map(child => child.toString(strip)).join('')\n if (strip) return inner\n const attrs = Object.entries(this.attrs).map(([key, value]) => {\n key = hyphenate(key)\n if (value === '') return ` ${key}`\n return ` ${key}=\"${Element.escape(value, true)}\"`\n }).join('')\n if (!this.children.length) return `<${this.type}${attrs}/>`\n return `<${this.type}${attrs}>${inner}</${this.type}>`\n }\n}\n\ndefineProperty(ElementConstructor, 'name', 'Element')\ndefineProperty(ElementConstructor.prototype, kElement, true)\n\nfunction Element(type: string, ...children: Element.Fragment[]): Element\nfunction Element(type: string, attrs: Dict, ...children: Element.Fragment[]): Element\nfunction Element(type: string, ...args: any[]) {\n const el = Object.create(ElementConstructor.prototype)\n let attrs: Dict<string> = {}, children: Element[] = []\n if (args[0] && typeof args[0] === 'object' && !isElement(args[0]) && !Array.isArray(args[0])) {\n for (const [key, value] of Object.entries(args.shift())) {\n if (isNullable(value)) continue\n // https://github.com/reactjs/rfcs/pull/107\n if (key === 'children') {\n children = toElementArray(value as Element.Fragment)\n } else if (value === true) {\n attrs[key] = ''\n } else if (value === false) {\n attrs['no' + capitalize(key)] = ''\n } else if (!isNullable(value)) {\n attrs[key] = '' + value\n }\n }\n }\n for (const child of args) {\n children.push(...toElementArray(child))\n }\n return Object.assign(el, { type, attrs, children })\n}\n\n// eslint-disable-next-line no-new-func\nconst interpolate = new Function('expr', 'context', `\n try {\n with (context) {\n const result = eval(expr)\n return result === undefined || result === null ? '' : result\n }\n } catch {\n return ''\n }\n`) as ((expr: string, context: object) => string)\n\nnamespace Element {\n export const jsx = Element\n export const jsxs = Element\n export const jsxDEV = Element\n export const Fragment = 'template'\n\n export type Fragment = string | Element | (string | Element)[]\n export type Render<T, S> = (attrs: Dict<any>, children: Element[], session: S) => T\n export type Transformer<S> = boolean | Fragment | Render<boolean | Fragment, S>\n export type AsyncTransformer<S> = boolean | Fragment | Render<Awaitable<boolean | Fragment>, S>\n\n export function normalize(source: Fragment) {\n if (typeof source !== 'string') return toElementArray(source)\n return Element.parse(source)\n }\n\n export function escape(source: string, inline = false) {\n const result = source\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n return inline\n ? result.replace(/\"/g, '"')\n : result\n }\n\n export function unescape(source: string) {\n return source\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/"/g, '\"')\n .replace(/&#(\\d+);/g, (_, code) => code === '38' ? _ : String.fromCharCode(+code))\n .replace(/&#x([0-9a-f]+);/gi, (_, code) => code === '26' ? _ : String.fromCharCode(parseInt(code, 16)))\n .replace(/&(amp|#38|#x26);/g, '&')\n }\n\n export interface FindOptions {\n type?: string\n caret?: boolean\n }\n\n /** @deprecated use `Element.select()` instead */\n export function from(source: string, options: FindOptions = {}): Element {\n const elements = parse(source)\n if (options.caret) {\n if (options.type && elements[0]?.type !== options.type) return\n return elements[0]\n }\n return select(elements, options.type || '*')[0]\n }\n\n type Combinator = ' ' | '>' | '+' | '~'\n\n export interface Selector {\n type: string\n combinator: Combinator\n }\n\n const combRegExp = / *([ >+~]) */g\n\n export function parseSelector(input: string): Selector[][] {\n return input.split(',').map((query) => {\n const selectors: Selector[] = []\n query = query.trim()\n let combCap: RegExpExecArray, combinator: Combinator = ' '\n while ((combCap = combRegExp.exec(query))) {\n selectors.push({ type: query.slice(0, combCap.index), combinator })\n combinator = combCap[1] as Combinator\n query = query.slice(combCap.index + combCap[0].length)\n }\n selectors.push({ type: query, combinator })\n return selectors\n })\n }\n\n export function select(source: string | Element[], query: string | Selector[][]): Element[] {\n if (typeof source === 'string') source = parse(source)\n if (typeof query === 'string') query = parseSelector(query)\n if (!query.length) return\n let adjacent: Selector[][] = []\n const results: Element[] = []\n for (const [index, element] of source.entries()) {\n const inner: Selector[][] = []\n const local = [...query, ...adjacent]\n adjacent = []\n let matched = false\n for (const group of local) {\n const { type, combinator } = group[0]\n if (type === element.type || type === '*') {\n if (group.length === 1) {\n matched = true\n } else if ([' ', '>'].includes(group[1].combinator)) {\n inner.push(group.slice(1))\n } else if (group[1].combinator === '+') {\n adjacent.push(group.slice(1))\n } else {\n query.push(group.slice(1))\n }\n }\n if (combinator === ' ') {\n inner.push(group)\n }\n }\n if (matched) results.push(source[index])\n results.push(...select(element.children, inner))\n }\n return results\n }\n\n const tagRegExp = /<(\\/?)\\s*([^\\s>/]*)([^>]*?)\\s*(\\/?)>/\n const attrRegExp1 = /([^\\s=]+)(?:=\"([^\"]*)\"|='([^']*)')?/g\n const attrRegExp2 = /([^\\s=]+)(?:=\"([^\"]*)\"|='([^']*)'|=\\{([^}]+)\\})?/g\n const interpRegExp = /\\{([^}]+)\\}/g\n\n interface Token {\n type: string\n close: string\n empty: string\n attrs: Dict<string>\n source: string\n }\n\n export function parse(source: string, context?: any) {\n const tokens: (string | Token)[] = []\n const attrRegExp = context ? attrRegExp2 : attrRegExp1\n let tagCap: RegExpExecArray\n while ((tagCap = tagRegExp.exec(source))) {\n pushText(source.slice(0, tagCap.index))\n const [_, close, type, attrs, empty] = tagCap\n const token: Token = { source: _, type: type || Fragment, close, empty, attrs: {} }\n let attrCap: RegExpExecArray\n while ((attrCap = attrRegExp.exec(attrs))) {\n const [_, key, v1 = '', v2 = v1, v3] = attrCap\n token.attrs[camelize(key)] = v3\n ? interpolate(v3, context)\n : unescape(v2)\n }\n tokens.push(token)\n source = source.slice(tagCap.index + _.length)\n }\n\n pushText(source)\n function pushText(source: string) {\n source = source\n .replace(/^\\s*\\n\\s*/, '')\n .replace(/\\s*\\n\\s*$/, '')\n let result = ''\n if (context) {\n let interpCap: RegExpExecArray\n while ((interpCap = interpRegExp.exec(source))) {\n const [_, expr] = interpCap\n result += unescape(source.slice(0, interpCap.index))\n result += interpolate(expr, context)\n source = source.slice(interpCap.index + _.length)\n }\n }\n result += unescape(source)\n if (result) tokens.push(result)\n }\n\n const stack = [Element(Fragment)]\n function rollback(index: number) {\n for (; index > 0; index--) {\n const { children } = stack.shift()\n const { source } = stack[0].children.pop()\n stack[0].children.push(Element('text', { content: source }))\n stack[0].children.push(...children)\n }\n }\n\n for (const token of tokens) {\n if (typeof token === 'string') {\n stack[0].children.push(Element('text', { content: token }))\n } else if (token.close) {\n let index = 0\n while (index < stack.length && stack[index].type !== token.type) index++\n if (index === stack.length) {\n // no matching open tag\n stack[0].children.push(Element('text', { content: token.source }))\n } else {\n rollback(index)\n const element = stack.shift()\n delete element.source\n }\n } else {\n const element = Element(token.type, token.attrs)\n stack[0].children.push(element)\n if (!token.empty) {\n element.source = token.source\n stack.unshift(element)\n }\n }\n }\n rollback(stack.length - 1)\n return stack[0].children\n }\n\n export function transform<S>(source: string, rules: Dict<Transformer<S>>, session?: S): string\n export function transform<S>(source: Element[], rules: Dict<Transformer<S>>, session?: S): Element[]\n export function transform<S>(source: string | Element[], rules: Dict<Transformer<S>>, session?: S) {\n const elements = typeof source === 'string' ? parse(source) : source\n const output: Element[] = []\n elements.forEach((element) => {\n const { type, attrs, children } = element\n let result = rules[type] ?? rules.default ?? true\n if (typeof result === 'function') {\n result = result(attrs, children, session)\n }\n if (result === true) {\n output.push(Element(type, attrs, transform(children, rules)))\n } else if (result !== false) {\n output.push(...toElementArray(result))\n }\n })\n return typeof source === 'string' ? output.join('') : output\n }\n\n export async function transformAsync<S>(source: string, rules: Dict<AsyncTransformer<S>>, session?: S): Promise<string>\n export async function transformAsync<S>(source: Element[], rules: Dict<AsyncTransformer<S>>, session?: S): Promise<Element[]>\n export async function transformAsync<S>(source: string | Element[], rules: Dict<AsyncTransformer<S>>, session?: S) {\n const elements = typeof source === 'string' ? parse(source) : source\n const children = (await Promise.all(elements.map(async (element) => {\n const { type, attrs, children } = element\n let result = rules[type] ?? rules.default ?? true\n if (typeof result === 'function') {\n result = await result(attrs, children, session)\n }\n if (result === true) {\n return [Element(type, attrs, await transformAsync(children, rules))]\n } else if (result !== false) {\n return toElementArray(result)\n } else {\n return []\n }\n }))).flat(1)\n return typeof source === 'string' ? children.join('') : children\n }\n\n /** @deprecated use `elements.join('')` instead */\n export function join(elements: Element[]) {\n return elements.join('')\n }\n\n export type Factory<R extends any[]> = (...args: [...rest: R, attrs?: Dict<any>]) => Element\n\n function createFactory<R extends any[] = any[]>(type: string, ...keys: string[]): Factory<R> {\n return (...args: any[]) => {\n const element = Element(type)\n keys.forEach((key, index) => {\n if (!isNullable(args[index])) {\n element.attrs[key] = args[index]\n }\n })\n if (args[keys.length]) {\n Object.assign(element.attrs, args[keys.length])\n }\n return element\n }\n }\n\n function createAssetFactory(type: string): Factory<[data: string | Buffer | ArrayBuffer]> {\n return (value, attrs = {}) => {\n if (is('Buffer', value)) {\n value = 'base64://' + value.toString('base64')\n } else if (is('ArrayBuffer', value)) {\n value = 'base64://' + Buffer.from(value).toString('base64')\n }\n return Element(type, { ...attrs, url: value })\n }\n }\n\n export const at = createFactory<[id: any]>('at', 'id')\n export const sharp = createFactory<[id: any]>('sharp', 'id')\n export const quote = createFactory<[id: any]>('quote', 'id')\n export const image = createAssetFactory('image')\n export const video = createAssetFactory('video')\n export const audio = createAssetFactory('audio')\n export const file = createAssetFactory('file')\n}\n\nexport = Element\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA,SAAoB,UAAU,YAAY,gBAAsB,WAAW,IAAI,kBAAkB;AAAjG;AAAA;AAEA,QAAM,WAAW,OAAO,SAAS;AAEjC,aAAS,UAAU,QAAgC;AACjD,aAAO,UAAU,OAAO,WAAW,YAAY,OAAO;AAAA,IACxD;AAFS;AAIT,aAAS,UAAU,SAA2B;AAC5C,UAAI,OAAO,YAAY,UAAU;AAC/B,YAAI;AAAS,iBAAO,QAAQ,QAAQ,EAAE,QAAQ,CAAC;AAAA,MACjD,WAAW,UAAU,OAAO,GAAG;AAC7B,eAAO;AAAA,MACT,WAAW,CAAC,WAAW,OAAO,GAAG;AAC/B,cAAM,IAAI,UAAU,oBAAoB,SAAS;AAAA,MACnD;AAAA,IACF;AARS;AAUT,aAAS,eAAe,SAA2B;AACjD,UAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,eAAO,QAAQ,IAAI,SAAS,EAAE,OAAO,OAAK,CAAC;AAAA,MAC7C,OAAO;AACL,eAAO,CAAC,UAAU,OAAO,CAAC,EAAE,OAAO,OAAK,CAAC;AAAA,MAC3C;AAAA,IACF;AANS;AAqBT,QAAM,qBAAN,MAAyB;AAAA,MACvB,IAAI,OAAO;AACT,eAAO,KAAK;AAAA,MACd;AAAA,MAEA,SAAS,QAAQ,OAAO;AACtB,YAAI,KAAK,SAAS;AAAQ,iBAAO,QAAQ,OAAO,KAAK,MAAM,OAAO;AAClE,cAAM,QAAQ,KAAK,SAAS,IAA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cAAyB,MAAM,IAAI;AAC9C,MAAMA,SAAA,QAAQ,cAAyB,SAAS,IAAI;AACpD,MAAMA,SAAA,QAAQ,cAAyB,SAAS,IAAI;AACpD,MAAMA,SAAA,QAAQ,mBAAmB,OAAO;AACxC,MAAMA,SAAA,QAAQ,mBAAmB,OAAO;AACxC,MAAMA,SAAA,QAAQ,mBAAmB,OAAO;AACxC,MAAMA,SAAA,OAAO,mBAAmB,MAAM;AAAA,OArRrC;AAwRV,qBAAS;AAAA;AAAA;",
|
|
6
6
|
"names": ["Element", "_", "source", "children"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@satorijs/element",
|
|
3
3
|
"description": "Element Manipulation",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.1",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./lib/index.mjs",
|
|
11
|
+
"require": "./lib/index.cjs",
|
|
12
|
+
"typings": "./lib/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./jsx-runtime": {
|
|
15
|
+
"import": "./lib/index.mjs",
|
|
16
|
+
"require": "./lib/index.cjs",
|
|
17
|
+
"typings": "./lib/index.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./jsx-dev-runtime": {
|
|
20
|
+
"import": "./lib/index.mjs",
|
|
21
|
+
"require": "./lib/index.cjs",
|
|
22
|
+
"typings": "./lib/index.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
8
26
|
"files": [
|
|
9
27
|
"lib"
|
|
10
28
|
],
|
package/lib/utils.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/// <reference types="mocha" />
|
|
2
|
-
declare type Global = NodeJS.Global & Window & typeof globalThis;
|
|
3
|
-
declare type GlobalClass = {
|
|
4
|
-
[K in keyof Global]: Global[K] extends new (...args: any[]) => infer T ? T : never;
|
|
5
|
-
};
|
|
6
|
-
export declare function isType<K extends keyof GlobalClass>(type: K, value: any): value is GlobalClass[K];
|
|
7
|
-
export {};
|