@satorijs/element 2.4.2 → 2.5.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 +31 -14
- package/lib/index.cjs.map +2 -2
- package/lib/index.d.ts +3 -2
- package/lib/index.mjs +30 -13
- package/lib/index.mjs.map +2 -2
- package/package.json +6 -6
package/lib/index.cjs
CHANGED
|
@@ -28,18 +28,20 @@ function toElementArray(content) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
__name(toElementArray, "toElementArray");
|
|
31
|
-
var
|
|
31
|
+
var _ElementConstructor = class _ElementConstructor {
|
|
32
32
|
get data() {
|
|
33
33
|
return this.attrs;
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
getTagName() {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
if (this.type === "component") {
|
|
38
|
+
return (_b = (_a = this.attrs.is) == null ? void 0 : _a.name) != null ? _b : "component";
|
|
39
|
+
} else {
|
|
40
|
+
return this.type;
|
|
38
41
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const attrs = Object.entries(this.attrs).map(([key, value]) => {
|
|
42
|
+
}
|
|
43
|
+
toAttrString() {
|
|
44
|
+
return Object.entries(this.attrs).map(([key, value]) => {
|
|
43
45
|
if ((0, import_cosmokit.isNullable)(value))
|
|
44
46
|
return "";
|
|
45
47
|
key = (0, import_cosmokit.hyphenate)(key);
|
|
@@ -49,12 +51,23 @@ var ElementConstructor = class {
|
|
|
49
51
|
return ` no-${key}`;
|
|
50
52
|
return ` ${key}="${Element.escape("" + value, true)}"`;
|
|
51
53
|
}).join("");
|
|
54
|
+
}
|
|
55
|
+
toString(strip = false) {
|
|
56
|
+
if (this.type === "text" && "content" in this.attrs) {
|
|
57
|
+
return strip ? this.attrs.content : Element.escape(this.attrs.content);
|
|
58
|
+
}
|
|
59
|
+
const inner = this.children.map((child) => child.toString(strip)).join("");
|
|
60
|
+
if (strip)
|
|
61
|
+
return inner;
|
|
62
|
+
const attrs = this.toAttrString();
|
|
63
|
+
const tag = this.getTagName();
|
|
52
64
|
if (!this.children.length)
|
|
53
|
-
return `<${
|
|
54
|
-
return `<${
|
|
65
|
+
return `<${tag}${attrs}/>`;
|
|
66
|
+
return `<${tag}${attrs}>${inner}</${tag}>`;
|
|
55
67
|
}
|
|
56
68
|
};
|
|
57
|
-
__name(
|
|
69
|
+
__name(_ElementConstructor, "ElementConstructor");
|
|
70
|
+
var ElementConstructor = _ElementConstructor;
|
|
58
71
|
(0, import_cosmokit.defineProperty)(ElementConstructor, "name", "Element");
|
|
59
72
|
(0, import_cosmokit.defineProperty)(ElementConstructor.prototype, kElement, true);
|
|
60
73
|
function Element(type, ...args) {
|
|
@@ -75,6 +88,10 @@ function Element(type, ...args) {
|
|
|
75
88
|
for (const child of args) {
|
|
76
89
|
children.push(...toElementArray(child));
|
|
77
90
|
}
|
|
91
|
+
if (typeof type === "function") {
|
|
92
|
+
attrs.is = type;
|
|
93
|
+
type = "component";
|
|
94
|
+
}
|
|
78
95
|
return Object.assign(el, { type, attrs, children });
|
|
79
96
|
}
|
|
80
97
|
__name(Element, "Element");
|
|
@@ -289,7 +306,7 @@ var evaluate = new Function("expr", "context", `
|
|
|
289
306
|
if (typeof rules === "function") {
|
|
290
307
|
return rules(element, session);
|
|
291
308
|
} else {
|
|
292
|
-
let result = (_b = (_a = rules[type]) != null ? _a : rules.default) != null ? _b : true;
|
|
309
|
+
let result = (_b = (_a = rules[typeof type === "string" ? type : ""]) != null ? _a : rules.default) != null ? _b : true;
|
|
293
310
|
if (typeof result === "function") {
|
|
294
311
|
result = result(attrs, children, session);
|
|
295
312
|
}
|
|
@@ -306,7 +323,7 @@ var evaluate = new Function("expr", "context", `
|
|
|
306
323
|
if (result === true) {
|
|
307
324
|
output.push(Element2(type, attrs, transform(children, rules, session)));
|
|
308
325
|
} else if (result !== false) {
|
|
309
|
-
output.push(...
|
|
326
|
+
output.push(...toElementArray(result));
|
|
310
327
|
}
|
|
311
328
|
});
|
|
312
329
|
return typeof source === "string" ? output.join("") : output;
|
|
@@ -321,7 +338,7 @@ var evaluate = new Function("expr", "context", `
|
|
|
321
338
|
if (result === true) {
|
|
322
339
|
return [Element2(type, attrs, await transformAsync(children2, rules, session))];
|
|
323
340
|
} else if (result !== false) {
|
|
324
|
-
return
|
|
341
|
+
return toElementArray(result);
|
|
325
342
|
} else {
|
|
326
343
|
return [];
|
|
327
344
|
}
|
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 { arrayBufferToBase64, Awaitable, camelize, defineProperty, Dict, hyphenate, is, isNullable, makeArray } from 'cosmokit'\n\nconst kElement = Symbol.for('satori.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' || typeof content === 'number' || typeof content === 'boolean') {\n content = '' + content\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\n /** @deprecated use `attrs` instead */\n data: Dict\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' && 'content' in this.attrs) {\n return strip ? this.attrs.content : Element.escape(this.attrs.content)\n }\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 if (isNullable(value)) return ''\n key = hyphenate(key)\n if (value === true) return ` ${key}`\n if (value === false) return ` no-${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 const attrs: Dict = {}, children: Element[] = []\n if (args[0] && typeof args[0] === 'object' && !isElement(args[0]) && !Array.isArray(args[0])) {\n const props = args.shift()\n for (const [key, value] of Object.entries(props)) {\n if (isNullable(value)) continue\n // https://github.com/reactjs/rfcs/pull/107\n if (key === 'children') {\n args.push(...makeArray(value))\n } else {\n attrs[camelize(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 evaluate = new Function('expr', 'context', `\n try {\n with (context) {\n return eval(expr)\n }\n } catch {}\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 Visit<T, S> = (element: Element, session: S) => T\n export type Render<T, S> = (attrs: Dict, children: Element[], session: S) => T\n export type SyncTransformer<S = never> = boolean | Fragment | Render<boolean | Fragment, S>\n export type Transformer<S = never> = boolean | Fragment | Render<Awaitable<boolean | Fragment>, S>\n\n type SyncVisitor<S> = Dict<SyncTransformer<S>> | Visit<boolean | Fragment, S>\n type Visitor<S> = Dict<Transformer<S>> | Visit<Awaitable<boolean | Fragment>, S>\n\n export function normalize(source: Fragment, context?: any) {\n if (typeof source !== 'string') return toElementArray(source)\n return Element.parse(source, context)\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 (!source || !query) return []\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 export function interpolate(expr: string, context: any) {\n expr = expr.trim()\n if (!/^[\\w.]+$/.test(expr)) {\n return evaluate(expr, context) ?? ''\n }\n let value = context\n for (const part of expr.split('.')) {\n value = value[part]\n if (isNullable(value)) return ''\n }\n return value ?? ''\n }\n\n const tagRegExp = /<!--[\\s\\S]*?-->|<(\\/?)([^!\\s>/]*)([^>]*?)\\s*(\\/?)>/\n const attrRegExp1 = /([^\\s=]+)(?:=\"([^\"]*)\"|='([^']*)')?/g\n const attrRegExp2 = /([^\\s=]+)(?:=\"([^\"]*)\"|='([^']*)'|=\\{([^}]+)\\})?/g\n const interpRegExp = /\\{([^}]*)\\}/\n\n interface Token {\n type: string\n close: string\n empty: string\n attrs: Dict\n source: string\n }\n\n export function parse(source: string, context?: any) {\n const tokens: (Element | Token)[] = []\n function pushText(content: string) {\n if (content) tokens.push(Element('text', { content }))\n }\n\n const attrRegExp = context ? attrRegExp2 : attrRegExp1\n let tagCap: RegExpExecArray\n while ((tagCap = tagRegExp.exec(source))) {\n parseContent(source.slice(0, tagCap.index))\n const [_, close, type, attrs, empty] = tagCap\n source = source.slice(tagCap.index + _.length)\n if (_.startsWith('<!')) continue\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 if (v3) {\n token.attrs[key] = interpolate(v3, context)\n } else if (!isNullable(v2)) {\n token.attrs[key] = unescape(v2)\n } else if (key.startsWith('no-')) {\n token.attrs[key.slice(3)] = false\n } else {\n token.attrs[key] = true\n }\n }\n tokens.push(token)\n }\n\n parseContent(source)\n function parseContent(source: string) {\n source = source\n .replace(/^\\s*\\n\\s*/, '')\n .replace(/\\s*\\n\\s*$/, '')\n if (context) {\n let interpCap: RegExpExecArray\n while ((interpCap = interpRegExp.exec(source))) {\n const [_, expr] = interpCap\n pushText(unescape(source.slice(0, interpCap.index)))\n source = source.slice(interpCap.index + _.length)\n const content = interpolate(expr, context)\n tokens.push(...toElementArray(content))\n }\n }\n pushText(unescape(source))\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 (isElement(token)) {\n stack[0].children.push(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 function visit<S>(element: Element, rules: Visitor<S>, session: S) {\n const { type, attrs, children } = element\n if (typeof rules === 'function') {\n return rules(element, session)\n } else {\n let result: any = rules[type] ?? rules.default ?? true\n if (typeof result === 'function') {\n result = result(attrs, children, session)\n }\n return result\n }\n }\n\n export function transform<S = never>(source: string, rules: SyncVisitor<S>, session?: S): string\n export function transform<S = never>(source: Element[], rules: SyncVisitor<S>, session?: S): Element[]\n export function transform<S>(source: string | Element[], rules: SyncVisitor<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 const result = visit(element, rules, session)\n if (result === true) {\n output.push(Element(type, attrs, transform(children, rules, session)))\n } else if (result !== false) {\n output.push(...normalize(result))\n }\n })\n return typeof source === 'string' ? output.join('') : output\n }\n\n export async function transformAsync<S = never>(source: string, rules: Visitor<S>, session?: S): Promise<string>\n export async function transformAsync<S = never>(source: Element[], rules: Visitor<S>, session?: S): Promise<Element[]>\n export async function transformAsync<S>(source: string | Element[], rules: Visitor<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 const result = await visit(element, rules, session)\n if (result === true) {\n return [Element(type, attrs, await transformAsync(children, rules, session))]\n } else if (result !== false) {\n return normalize(result)\n } else {\n return []\n }\n }))).flat(1)\n return typeof source === 'string' ? children.join('') : children\n }\n\n export type Factory<R extends any[]> = (...args: [...rest: R, attrs?: Dict]) => 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 // eslint-disable-next-line prefer-const\n export let warn: (message: string) => void = () => {}\n\n function createAssetFactory(type: string): Factory<[data: string] | [data: Buffer | ArrayBuffer, type: string]> {\n return (url, ...args) => {\n let prefix = 'base64://'\n if (typeof args[0] === 'string') {\n prefix = `data:${args.shift()};base64,`\n }\n if (is('Buffer', url)) {\n url = prefix + url.toString('base64')\n } else if (is('ArrayBuffer', url)) {\n url = prefix + arrayBufferToBase64(url)\n }\n if (url.startsWith('base64://')) {\n warn(`protocol \"base64:\" is deprecated and will be removed in the future, please use \"data:\" instead`)\n }\n return Element(type, { ...args[0] as {}, url })\n }\n }\n\n export const text = createFactory<[content: any]>('text', 'content')\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 export function i18n(path: string | Dict, children?: any[]) {\n return Element('i18n', typeof path === 'string' ? { path } : path, children)\n }\n}\n\nexport = Element\n"],
|
|
5
|
-
"mappings": ";;;;AAAA,sBAAqH;AAErH,IAAM,WAAW,OAAO,IAAI,gBAAgB;AAE5C,SAAS,UAAU,QAAgC;AACjD,SAAO,UAAU,OAAO,WAAW,YAAY,OAAO,QAAQ;AAChE;AAFS;AAIT,SAAS,UAAU,SAA2B;AAC5C,MAAI,OAAO,YAAY,YAAY,OAAO,YAAY,YAAY,OAAO,YAAY,WAAW;AAC9F,cAAU,KAAK;AACf,QAAI;AAAS,aAAO,QAAQ,QAAQ,EAAE,QAAQ,CAAC;AAAA,EACjD,WAAW,UAAU,OAAO,GAAG;AAC7B,WAAO;AAAA,EACT,WAAW,KAAC,4BAAW,OAAO,GAAG;AAC/B,UAAM,IAAI,UAAU,oBAAoB,
|
|
4
|
+
"sourcesContent": ["import { arrayBufferToBase64, Awaitable, camelize, defineProperty, Dict, hyphenate, is, isNullable, makeArray } from 'cosmokit'\n\nconst kElement = Symbol.for('satori.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' || typeof content === 'number' || typeof content === 'boolean') {\n content = '' + content\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\n /** @deprecated use `attrs` instead */\n data: Dict\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 getTagName() {\n if (this.type === 'component') {\n return this.attrs.is?.name ?? 'component'\n } else {\n return this.type\n }\n }\n\n toAttrString() {\n return Object.entries(this.attrs).map(([key, value]) => {\n if (isNullable(value)) return ''\n key = hyphenate(key)\n if (value === true) return ` ${key}`\n if (value === false) return ` no-${key}`\n return ` ${key}=\"${Element.escape('' + value, true)}\"`\n }).join('')\n }\n\n toString(strip = false) {\n if (this.type === 'text' && 'content' in this.attrs) {\n return strip ? this.attrs.content : Element.escape(this.attrs.content)\n }\n const inner = this.children.map(child => child.toString(strip)).join('')\n if (strip) return inner\n const attrs = this.toAttrString()\n const tag = this.getTagName()\n if (!this.children.length) return `<${tag}${attrs}/>`\n return `<${tag}${attrs}>${inner}</${tag}>`\n }\n}\n\ndefineProperty(ElementConstructor, 'name', 'Element')\ndefineProperty(ElementConstructor.prototype, kElement, true)\n\ntype RenderFunction = Element.Render<Element.Fragment, any>\n\nfunction Element(type: string | RenderFunction, ...children: Element.Fragment[]): Element\nfunction Element(type: string | RenderFunction, attrs: Dict, ...children: Element.Fragment[]): Element\nfunction Element(type: string | RenderFunction, ...args: any[]) {\n const el = Object.create(ElementConstructor.prototype)\n const attrs: Dict = {}, children: Element[] = []\n if (args[0] && typeof args[0] === 'object' && !isElement(args[0]) && !Array.isArray(args[0])) {\n const props = args.shift()\n for (const [key, value] of Object.entries(props)) {\n if (isNullable(value)) continue\n // https://github.com/reactjs/rfcs/pull/107\n if (key === 'children') {\n args.push(...makeArray(value))\n } else {\n attrs[camelize(key)] = value\n }\n }\n }\n for (const child of args) {\n children.push(...toElementArray(child))\n }\n if (typeof type === 'function') {\n attrs.is = type\n type = 'component'\n }\n return Object.assign(el, { type, attrs, children })\n}\n\n// eslint-disable-next-line no-new-func\nconst evaluate = new Function('expr', 'context', `\n try {\n with (context) {\n return eval(expr)\n }\n } catch {}\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 Visit<T, S> = (element: Element, session: S) => T\n export type Render<T, S> = (attrs: Dict, children: Element[], session: S) => T\n export type SyncTransformer<S = never> = boolean | Fragment | Render<boolean | Fragment, S>\n export type Transformer<S = never> = boolean | Fragment | Render<Awaitable<boolean | Fragment>, S>\n\n type SyncVisitor<S> = Dict<SyncTransformer<S>> | Visit<boolean | Fragment, S>\n type Visitor<S> = Dict<Transformer<S>> | Visit<Awaitable<boolean | Fragment>, S>\n\n export function normalize(source: Fragment, context?: any) {\n if (typeof source !== 'string') return toElementArray(source)\n return Element.parse(source, context)\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 (!source || !query) return []\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 export function interpolate(expr: string, context: any) {\n expr = expr.trim()\n if (!/^[\\w.]+$/.test(expr)) {\n return evaluate(expr, context) ?? ''\n }\n let value = context\n for (const part of expr.split('.')) {\n value = value[part]\n if (isNullable(value)) return ''\n }\n return value ?? ''\n }\n\n const tagRegExp = /<!--[\\s\\S]*?-->|<(\\/?)([^!\\s>/]*)([^>]*?)\\s*(\\/?)>/\n const attrRegExp1 = /([^\\s=]+)(?:=\"([^\"]*)\"|='([^']*)')?/g\n const attrRegExp2 = /([^\\s=]+)(?:=\"([^\"]*)\"|='([^']*)'|=\\{([^}]+)\\})?/g\n const interpRegExp = /\\{([^}]*)\\}/\n\n interface Token {\n type: string\n close: string\n empty: string\n attrs: Dict\n source: string\n }\n\n export function parse(source: string, context?: any) {\n const tokens: (Element | Token)[] = []\n function pushText(content: string) {\n if (content) tokens.push(Element('text', { content }))\n }\n\n const attrRegExp = context ? attrRegExp2 : attrRegExp1\n let tagCap: RegExpExecArray\n while ((tagCap = tagRegExp.exec(source))) {\n parseContent(source.slice(0, tagCap.index))\n const [_, close, type, attrs, empty] = tagCap\n source = source.slice(tagCap.index + _.length)\n if (_.startsWith('<!')) continue\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 if (v3) {\n token.attrs[key] = interpolate(v3, context)\n } else if (!isNullable(v2)) {\n token.attrs[key] = unescape(v2)\n } else if (key.startsWith('no-')) {\n token.attrs[key.slice(3)] = false\n } else {\n token.attrs[key] = true\n }\n }\n tokens.push(token)\n }\n\n parseContent(source)\n function parseContent(source: string) {\n source = source\n .replace(/^\\s*\\n\\s*/, '')\n .replace(/\\s*\\n\\s*$/, '')\n if (context) {\n let interpCap: RegExpExecArray\n while ((interpCap = interpRegExp.exec(source))) {\n const [_, expr] = interpCap\n pushText(unescape(source.slice(0, interpCap.index)))\n source = source.slice(interpCap.index + _.length)\n const content = interpolate(expr, context)\n tokens.push(...toElementArray(content))\n }\n }\n pushText(unescape(source))\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 (isElement(token)) {\n stack[0].children.push(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 function visit<S>(element: Element, rules: Visitor<S>, session: S) {\n const { type, attrs, children } = element\n if (typeof rules === 'function') {\n return rules(element, session)\n } else {\n let result: any = rules[typeof type === 'string' ? type : ''] ?? rules.default ?? true\n if (typeof result === 'function') {\n result = result(attrs, children, session)\n }\n return result\n }\n }\n\n export function transform<S = never>(source: string, rules: SyncVisitor<S>, session?: S): string\n export function transform<S = never>(source: Element[], rules: SyncVisitor<S>, session?: S): Element[]\n export function transform<S>(source: string | Element[], rules: SyncVisitor<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 const result = visit(element, rules, session)\n if (result === true) {\n output.push(Element(type, attrs, transform(children, rules, session)))\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 = never>(source: string, rules: Visitor<S>, session?: S): Promise<string>\n export async function transformAsync<S = never>(source: Element[], rules: Visitor<S>, session?: S): Promise<Element[]>\n export async function transformAsync<S>(source: string | Element[], rules: Visitor<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 const result = await visit(element, rules, session)\n if (result === true) {\n return [Element(type, attrs, await transformAsync(children, rules, session))]\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 export type Factory<R extends any[]> = (...args: [...rest: R, attrs?: Dict]) => 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 // eslint-disable-next-line prefer-const\n export let warn: (message: string) => void = () => {}\n\n function createAssetFactory(type: string): Factory<[data: string] | [data: Buffer | ArrayBuffer, type: string]> {\n return (url, ...args) => {\n let prefix = 'base64://'\n if (typeof args[0] === 'string') {\n prefix = `data:${args.shift()};base64,`\n }\n if (is('Buffer', url)) {\n url = prefix + url.toString('base64')\n } else if (is('ArrayBuffer', url)) {\n url = prefix + arrayBufferToBase64(url)\n }\n if (url.startsWith('base64://')) {\n warn(`protocol \"base64:\" is deprecated and will be removed in the future, please use \"data:\" instead`)\n }\n return Element(type, { ...args[0] as {}, url })\n }\n }\n\n export const text = createFactory<[content: any]>('text', 'content')\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 export function i18n(path: string | Dict, children?: any[]) {\n return Element('i18n', typeof path === 'string' ? { path } : path, children)\n }\n}\n\nexport = Element\n"],
|
|
5
|
+
"mappings": ";;;;AAAA,sBAAqH;AAErH,IAAM,WAAW,OAAO,IAAI,gBAAgB;AAE5C,SAAS,UAAU,QAAgC;AACjD,SAAO,UAAU,OAAO,WAAW,YAAY,OAAO,QAAQ;AAChE;AAFS;AAIT,SAAS,UAAU,SAA2B;AAC5C,MAAI,OAAO,YAAY,YAAY,OAAO,YAAY,YAAY,OAAO,YAAY,WAAW;AAC9F,cAAU,KAAK;AACf,QAAI;AAAS,aAAO,QAAQ,QAAQ,EAAE,QAAQ,CAAC;AAAA,EACjD,WAAW,UAAU,OAAO,GAAG;AAC7B,WAAO;AAAA,EACT,WAAW,KAAC,4BAAW,OAAO,GAAG;AAC/B,UAAM,IAAI,UAAU,oBAAoB,OAAO,EAAE;AAAA,EACnD;AACF;AATS;AAWT,SAAS,eAAe,SAA2B;AACjD,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAO,QAAQ,IAAI,SAAS,EAAE,OAAO,OAAK,CAAC;AAAA,EAC7C,OAAO;AACL,WAAO,CAAC,UAAU,OAAO,CAAC,EAAE,OAAO,OAAK,CAAC;AAAA,EAC3C;AACF;AANS;AAqBT,IAAM,sBAAN,MAAM,oBAAmB;AAAA,EACvB,IAAI,OAAO;AACT,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,aAAa;AA7Cf;AA8CI,QAAI,KAAK,SAAS,aAAa;AAC7B,cAAO,gBAAK,MAAM,OAAX,mBAAe,SAAf,YAAuB;AAAA,IAChC,OAAO;AACL,aAAO,KAAK;AAAA,IACd;AAAA,E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AAA,MAC/B;AACA,cAAI,oBAAG,UAAU,GAAG,GAAG;AACrB,cAAM,SAAS,IAAI,SAAS,QAAQ;AAAA,MACtC,eAAW,oBAAG,eAAe,GAAG,GAAG;AACjC,cAAM,aAAS,qCAAoB,GAAG;AAAA,MACxC;AACA,UAAI,IAAI,WAAW,WAAW,GAAG;AAC/B,YAAAA,SAAA,MAAK,gGAAgG;AAAA,MACvG;AACA,aAAOA,SAAQ,MAAM,EAAE,GAAG,KAAK,CAAC,GAAS,IAAI,CAAC;AAAA,IAChD;AAAA,EACF;AAhBS;AAkBF,EAAMA,SAAA,OAAO,cAA8B,QAAQ,SAAS;AAC5D,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;AAEtC,WAAS,KAAK,MAAqB,UAAkB;AAC1D,WAAOA,SAAQ,QAAQ,OAAO,SAAS,WAAW,EAAE,KAAK,IAAI,MAAM,QAAQ;AAAA,EAC7E;AAFO,EAAAA,SAAS;AAAA;AAAA,GAhUR;AAqUV,iBAAS;",
|
|
6
6
|
"names": ["Element", "source", "children"]
|
|
7
7
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -11,8 +11,9 @@ interface Element {
|
|
|
11
11
|
source?: string;
|
|
12
12
|
toString(strip?: boolean): string;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
declare function Element(type: string
|
|
14
|
+
type RenderFunction = Element.Render<Element.Fragment, any>;
|
|
15
|
+
declare function Element(type: string | RenderFunction, ...children: Element.Fragment[]): Element;
|
|
16
|
+
declare function Element(type: string | RenderFunction, attrs: Dict, ...children: Element.Fragment[]): Element;
|
|
16
17
|
declare namespace Element {
|
|
17
18
|
export const jsx: typeof Element;
|
|
18
19
|
export const jsxs: typeof Element;
|
package/lib/index.mjs
CHANGED
|
@@ -35,17 +35,21 @@ var require_src = __commonJS({
|
|
|
35
35
|
}
|
|
36
36
|
__name(toElementArray, "toElementArray");
|
|
37
37
|
var ElementConstructor = class {
|
|
38
|
+
static {
|
|
39
|
+
__name(this, "ElementConstructor");
|
|
40
|
+
}
|
|
38
41
|
get data() {
|
|
39
42
|
return this.attrs;
|
|
40
43
|
}
|
|
41
|
-
|
|
42
|
-
if (this.type === "
|
|
43
|
-
return
|
|
44
|
+
getTagName() {
|
|
45
|
+
if (this.type === "component") {
|
|
46
|
+
return this.attrs.is?.name ?? "component";
|
|
47
|
+
} else {
|
|
48
|
+
return this.type;
|
|
44
49
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const attrs = Object.entries(this.attrs).map(([key, value]) => {
|
|
50
|
+
}
|
|
51
|
+
toAttrString() {
|
|
52
|
+
return Object.entries(this.attrs).map(([key, value]) => {
|
|
49
53
|
if (isNullable(value))
|
|
50
54
|
return "";
|
|
51
55
|
key = hyphenate(key);
|
|
@@ -55,12 +59,21 @@ var require_src = __commonJS({
|
|
|
55
59
|
return ` no-${key}`;
|
|
56
60
|
return ` ${key}="${Element.escape("" + value, true)}"`;
|
|
57
61
|
}).join("");
|
|
62
|
+
}
|
|
63
|
+
toString(strip = false) {
|
|
64
|
+
if (this.type === "text" && "content" in this.attrs) {
|
|
65
|
+
return strip ? this.attrs.content : Element.escape(this.attrs.content);
|
|
66
|
+
}
|
|
67
|
+
const inner = this.children.map((child) => child.toString(strip)).join("");
|
|
68
|
+
if (strip)
|
|
69
|
+
return inner;
|
|
70
|
+
const attrs = this.toAttrString();
|
|
71
|
+
const tag = this.getTagName();
|
|
58
72
|
if (!this.children.length)
|
|
59
|
-
return `<${
|
|
60
|
-
return `<${
|
|
73
|
+
return `<${tag}${attrs}/>`;
|
|
74
|
+
return `<${tag}${attrs}>${inner}</${tag}>`;
|
|
61
75
|
}
|
|
62
76
|
};
|
|
63
|
-
__name(ElementConstructor, "ElementConstructor");
|
|
64
77
|
defineProperty(ElementConstructor, "name", "Element");
|
|
65
78
|
defineProperty(ElementConstructor.prototype, kElement, true);
|
|
66
79
|
function Element(type, ...args) {
|
|
@@ -81,6 +94,10 @@ var require_src = __commonJS({
|
|
|
81
94
|
for (const child of args) {
|
|
82
95
|
children.push(...toElementArray(child));
|
|
83
96
|
}
|
|
97
|
+
if (typeof type === "function") {
|
|
98
|
+
attrs.is = type;
|
|
99
|
+
type = "component";
|
|
100
|
+
}
|
|
84
101
|
return Object.assign(el, { type, attrs, children });
|
|
85
102
|
}
|
|
86
103
|
__name(Element, "Element");
|
|
@@ -292,7 +309,7 @@ var require_src = __commonJS({
|
|
|
292
309
|
if (typeof rules === "function") {
|
|
293
310
|
return rules(element, session);
|
|
294
311
|
} else {
|
|
295
|
-
let result = rules[type] ?? rules.default ?? true;
|
|
312
|
+
let result = rules[typeof type === "string" ? type : ""] ?? rules.default ?? true;
|
|
296
313
|
if (typeof result === "function") {
|
|
297
314
|
result = result(attrs, children, session);
|
|
298
315
|
}
|
|
@@ -309,7 +326,7 @@ var require_src = __commonJS({
|
|
|
309
326
|
if (result === true) {
|
|
310
327
|
output.push(Element2(type, attrs, transform(children, rules, session)));
|
|
311
328
|
} else if (result !== false) {
|
|
312
|
-
output.push(...
|
|
329
|
+
output.push(...toElementArray(result));
|
|
313
330
|
}
|
|
314
331
|
});
|
|
315
332
|
return typeof source === "string" ? output.join("") : output;
|
|
@@ -324,7 +341,7 @@ var require_src = __commonJS({
|
|
|
324
341
|
if (result === true) {
|
|
325
342
|
return [Element2(type, attrs, await transformAsync(children2, rules, session))];
|
|
326
343
|
} else if (result !== false) {
|
|
327
|
-
return
|
|
344
|
+
return toElementArray(result);
|
|
328
345
|
} else {
|
|
329
346
|
return [];
|
|
330
347
|
}
|
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 { arrayBufferToBase64, Awaitable, camelize, defineProperty, Dict, hyphenate, is, isNullable, makeArray } from 'cosmokit'\n\nconst kElement = Symbol.for('satori.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' || typeof content === 'number' || typeof content === 'boolean') {\n content = '' + content\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\n /** @deprecated use `attrs` instead */\n data: Dict\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' && 'content' in this.attrs) {\n return strip ? this.attrs.content : Element.escape(this.attrs.content)\n }\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 if (isNullable(value)) return ''\n key = hyphenate(key)\n if (value === true) return ` ${key}`\n if (value === false) return ` no-${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 const attrs: Dict = {}, children: Element[] = []\n if (args[0] && typeof args[0] === 'object' && !isElement(args[0]) && !Array.isArray(args[0])) {\n const props = args.shift()\n for (const [key, value] of Object.entries(props)) {\n if (isNullable(value)) continue\n // https://github.com/reactjs/rfcs/pull/107\n if (key === 'children') {\n args.push(...makeArray(value))\n } else {\n attrs[camelize(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 evaluate = new Function('expr', 'context', `\n try {\n with (context) {\n return eval(expr)\n }\n } catch {}\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 Visit<T, S> = (element: Element, session: S) => T\n export type Render<T, S> = (attrs: Dict, children: Element[], session: S) => T\n export type SyncTransformer<S = never> = boolean | Fragment | Render<boolean | Fragment, S>\n export type Transformer<S = never> = boolean | Fragment | Render<Awaitable<boolean | Fragment>, S>\n\n type SyncVisitor<S> = Dict<SyncTransformer<S>> | Visit<boolean | Fragment, S>\n type Visitor<S> = Dict<Transformer<S>> | Visit<Awaitable<boolean | Fragment>, S>\n\n export function normalize(source: Fragment, context?: any) {\n if (typeof source !== 'string') return toElementArray(source)\n return Element.parse(source, context)\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 (!source || !query) return []\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 export function interpolate(expr: string, context: any) {\n expr = expr.trim()\n if (!/^[\\w.]+$/.test(expr)) {\n return evaluate(expr, context) ?? ''\n }\n let value = context\n for (const part of expr.split('.')) {\n value = value[part]\n if (isNullable(value)) return ''\n }\n return value ?? ''\n }\n\n const tagRegExp = /<!--[\\s\\S]*?-->|<(\\/?)([^!\\s>/]*)([^>]*?)\\s*(\\/?)>/\n const attrRegExp1 = /([^\\s=]+)(?:=\"([^\"]*)\"|='([^']*)')?/g\n const attrRegExp2 = /([^\\s=]+)(?:=\"([^\"]*)\"|='([^']*)'|=\\{([^}]+)\\})?/g\n const interpRegExp = /\\{([^}]*)\\}/\n\n interface Token {\n type: string\n close: string\n empty: string\n attrs: Dict\n source: string\n }\n\n export function parse(source: string, context?: any) {\n const tokens: (Element | Token)[] = []\n function pushText(content: string) {\n if (content) tokens.push(Element('text', { content }))\n }\n\n const attrRegExp = context ? attrRegExp2 : attrRegExp1\n let tagCap: RegExpExecArray\n while ((tagCap = tagRegExp.exec(source))) {\n parseContent(source.slice(0, tagCap.index))\n const [_, close, type, attrs, empty] = tagCap\n source = source.slice(tagCap.index + _.length)\n if (_.startsWith('<!')) continue\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 if (v3) {\n token.attrs[key] = interpolate(v3, context)\n } else if (!isNullable(v2)) {\n token.attrs[key] = unescape(v2)\n } else if (key.startsWith('no-')) {\n token.attrs[key.slice(3)] = false\n } else {\n token.attrs[key] = true\n }\n }\n tokens.push(token)\n }\n\n parseContent(source)\n function parseContent(source: string) {\n source = source\n .replace(/^\\s*\\n\\s*/, '')\n .replace(/\\s*\\n\\s*$/, '')\n if (context) {\n let interpCap: RegExpExecArray\n while ((interpCap = interpRegExp.exec(source))) {\n const [_, expr] = interpCap\n pushText(unescape(source.slice(0, interpCap.index)))\n source = source.slice(interpCap.index + _.length)\n const content = interpolate(expr, context)\n tokens.push(...toElementArray(content))\n }\n }\n pushText(unescape(source))\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 (isElement(token)) {\n stack[0].children.push(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 function visit<S>(element: Element, rules: Visitor<S>, session: S) {\n const { type, attrs, children } = element\n if (typeof rules === 'function') {\n return rules(element, session)\n } else {\n let result: any = rules[type] ?? rules.default ?? true\n if (typeof result === 'function') {\n result = result(attrs, children, session)\n }\n return result\n }\n }\n\n export function transform<S = never>(source: string, rules: SyncVisitor<S>, session?: S): string\n export function transform<S = never>(source: Element[], rules: SyncVisitor<S>, session?: S): Element[]\n export function transform<S>(source: string | Element[], rules: SyncVisitor<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 const result = visit(element, rules, session)\n if (result === true) {\n output.push(Element(type, attrs, transform(children, rules, session)))\n } else if (result !== false) {\n output.push(...normalize(result))\n }\n })\n return typeof source === 'string' ? output.join('') : output\n }\n\n export async function transformAsync<S = never>(source: string, rules: Visitor<S>, session?: S): Promise<string>\n export async function transformAsync<S = never>(source: Element[], rules: Visitor<S>, session?: S): Promise<Element[]>\n export async function transformAsync<S>(source: string | Element[], rules: Visitor<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 const result = await visit(element, rules, session)\n if (result === true) {\n return [Element(type, attrs, await transformAsync(children, rules, session))]\n } else if (result !== false) {\n return normalize(result)\n } else {\n return []\n }\n }))).flat(1)\n return typeof source === 'string' ? children.join('') : children\n }\n\n export type Factory<R extends any[]> = (...args: [...rest: R, attrs?: Dict]) => 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 // eslint-disable-next-line prefer-const\n export let warn: (message: string) => void = () => {}\n\n function createAssetFactory(type: string): Factory<[data: string] | [data: Buffer | ArrayBuffer, type: string]> {\n return (url, ...args) => {\n let prefix = 'base64://'\n if (typeof args[0] === 'string') {\n prefix = `data:${args.shift()};base64,`\n }\n if (is('Buffer', url)) {\n url = prefix + url.toString('base64')\n } else if (is('ArrayBuffer', url)) {\n url = prefix + arrayBufferToBase64(url)\n }\n if (url.startsWith('base64://')) {\n warn(`protocol \"base64:\" is deprecated and will be removed in the future, please use \"data:\" instead`)\n }\n return Element(type, { ...args[0] as {}, url })\n }\n }\n\n export const text = createFactory<[content: any]>('text', 'content')\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 export function i18n(path: string | Dict, children?: any[]) {\n return Element('i18n', typeof path === 'string' ? { path } : path, children)\n }\n}\n\nexport = Element\n"],
|
|
5
|
-
"mappings": ";;;;;;;;AAAA,SAAS,qBAAgC,UAAU,gBAAsB,WAAW,IAAI,YAAY,iBAAiB;AAArH;AAAA;AAEA,QAAM,WAAW,OAAO,IAAI,gBAAgB;AAE5C,aAAS,UAAU,QAAgC;AACjD,aAAO,UAAU,OAAO,WAAW,YAAY,OAAO,QAAQ;AAAA,IAChE;AAFS;AAIT,aAAS,UAAU,SAA2B;AAC5C,UAAI,OAAO,YAAY,YAAY,OAAO,YAAY,YAAY,OAAO,YAAY,WAAW;AAC9F,kBAAU,KAAK;AACf,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,
|
|
4
|
+
"sourcesContent": ["import { arrayBufferToBase64, Awaitable, camelize, defineProperty, Dict, hyphenate, is, isNullable, makeArray } from 'cosmokit'\n\nconst kElement = Symbol.for('satori.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' || typeof content === 'number' || typeof content === 'boolean') {\n content = '' + content\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\n /** @deprecated use `attrs` instead */\n data: Dict\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 getTagName() {\n if (this.type === 'component') {\n return this.attrs.is?.name ?? 'component'\n } else {\n return this.type\n }\n }\n\n toAttrString() {\n return Object.entries(this.attrs).map(([key, value]) => {\n if (isNullable(value)) return ''\n key = hyphenate(key)\n if (value === true) return ` ${key}`\n if (value === false) return ` no-${key}`\n return ` ${key}=\"${Element.escape('' + value, true)}\"`\n }).join('')\n }\n\n toString(strip = false) {\n if (this.type === 'text' && 'content' in this.attrs) {\n return strip ? this.attrs.content : Element.escape(this.attrs.content)\n }\n const inner = this.children.map(child => child.toString(strip)).join('')\n if (strip) return inner\n const attrs = this.toAttrString()\n const tag = this.getTagName()\n if (!this.children.length) return `<${tag}${attrs}/>`\n return `<${tag}${attrs}>${inner}</${tag}>`\n }\n}\n\ndefineProperty(ElementConstructor, 'name', 'Element')\ndefineProperty(ElementConstructor.prototype, kElement, true)\n\ntype RenderFunction = Element.Render<Element.Fragment, any>\n\nfunction Element(type: string | RenderFunction, ...children: Element.Fragment[]): Element\nfunction Element(type: string | RenderFunction, attrs: Dict, ...children: Element.Fragment[]): Element\nfunction Element(type: string | RenderFunction, ...args: any[]) {\n const el = Object.create(ElementConstructor.prototype)\n const attrs: Dict = {}, children: Element[] = []\n if (args[0] && typeof args[0] === 'object' && !isElement(args[0]) && !Array.isArray(args[0])) {\n const props = args.shift()\n for (const [key, value] of Object.entries(props)) {\n if (isNullable(value)) continue\n // https://github.com/reactjs/rfcs/pull/107\n if (key === 'children') {\n args.push(...makeArray(value))\n } else {\n attrs[camelize(key)] = value\n }\n }\n }\n for (const child of args) {\n children.push(...toElementArray(child))\n }\n if (typeof type === 'function') {\n attrs.is = type\n type = 'component'\n }\n return Object.assign(el, { type, attrs, children })\n}\n\n// eslint-disable-next-line no-new-func\nconst evaluate = new Function('expr', 'context', `\n try {\n with (context) {\n return eval(expr)\n }\n } catch {}\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 Visit<T, S> = (element: Element, session: S) => T\n export type Render<T, S> = (attrs: Dict, children: Element[], session: S) => T\n export type SyncTransformer<S = never> = boolean | Fragment | Render<boolean | Fragment, S>\n export type Transformer<S = never> = boolean | Fragment | Render<Awaitable<boolean | Fragment>, S>\n\n type SyncVisitor<S> = Dict<SyncTransformer<S>> | Visit<boolean | Fragment, S>\n type Visitor<S> = Dict<Transformer<S>> | Visit<Awaitable<boolean | Fragment>, S>\n\n export function normalize(source: Fragment, context?: any) {\n if (typeof source !== 'string') return toElementArray(source)\n return Element.parse(source, context)\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 (!source || !query) return []\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 export function interpolate(expr: string, context: any) {\n expr = expr.trim()\n if (!/^[\\w.]+$/.test(expr)) {\n return evaluate(expr, context) ?? ''\n }\n let value = context\n for (const part of expr.split('.')) {\n value = value[part]\n if (isNullable(value)) return ''\n }\n return value ?? ''\n }\n\n const tagRegExp = /<!--[\\s\\S]*?-->|<(\\/?)([^!\\s>/]*)([^>]*?)\\s*(\\/?)>/\n const attrRegExp1 = /([^\\s=]+)(?:=\"([^\"]*)\"|='([^']*)')?/g\n const attrRegExp2 = /([^\\s=]+)(?:=\"([^\"]*)\"|='([^']*)'|=\\{([^}]+)\\})?/g\n const interpRegExp = /\\{([^}]*)\\}/\n\n interface Token {\n type: string\n close: string\n empty: string\n attrs: Dict\n source: string\n }\n\n export function parse(source: string, context?: any) {\n const tokens: (Element | Token)[] = []\n function pushText(content: string) {\n if (content) tokens.push(Element('text', { content }))\n }\n\n const attrRegExp = context ? attrRegExp2 : attrRegExp1\n let tagCap: RegExpExecArray\n while ((tagCap = tagRegExp.exec(source))) {\n parseContent(source.slice(0, tagCap.index))\n const [_, close, type, attrs, empty] = tagCap\n source = source.slice(tagCap.index + _.length)\n if (_.startsWith('<!')) continue\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 if (v3) {\n token.attrs[key] = interpolate(v3, context)\n } else if (!isNullable(v2)) {\n token.attrs[key] = unescape(v2)\n } else if (key.startsWith('no-')) {\n token.attrs[key.slice(3)] = false\n } else {\n token.attrs[key] = true\n }\n }\n tokens.push(token)\n }\n\n parseContent(source)\n function parseContent(source: string) {\n source = source\n .replace(/^\\s*\\n\\s*/, '')\n .replace(/\\s*\\n\\s*$/, '')\n if (context) {\n let interpCap: RegExpExecArray\n while ((interpCap = interpRegExp.exec(source))) {\n const [_, expr] = interpCap\n pushText(unescape(source.slice(0, interpCap.index)))\n source = source.slice(interpCap.index + _.length)\n const content = interpolate(expr, context)\n tokens.push(...toElementArray(content))\n }\n }\n pushText(unescape(source))\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 (isElement(token)) {\n stack[0].children.push(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 function visit<S>(element: Element, rules: Visitor<S>, session: S) {\n const { type, attrs, children } = element\n if (typeof rules === 'function') {\n return rules(element, session)\n } else {\n let result: any = rules[typeof type === 'string' ? type : ''] ?? rules.default ?? true\n if (typeof result === 'function') {\n result = result(attrs, children, session)\n }\n return result\n }\n }\n\n export function transform<S = never>(source: string, rules: SyncVisitor<S>, session?: S): string\n export function transform<S = never>(source: Element[], rules: SyncVisitor<S>, session?: S): Element[]\n export function transform<S>(source: string | Element[], rules: SyncVisitor<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 const result = visit(element, rules, session)\n if (result === true) {\n output.push(Element(type, attrs, transform(children, rules, session)))\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 = never>(source: string, rules: Visitor<S>, session?: S): Promise<string>\n export async function transformAsync<S = never>(source: Element[], rules: Visitor<S>, session?: S): Promise<Element[]>\n export async function transformAsync<S>(source: string | Element[], rules: Visitor<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 const result = await visit(element, rules, session)\n if (result === true) {\n return [Element(type, attrs, await transformAsync(children, rules, session))]\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 export type Factory<R extends any[]> = (...args: [...rest: R, attrs?: Dict]) => 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 // eslint-disable-next-line prefer-const\n export let warn: (message: string) => void = () => {}\n\n function createAssetFactory(type: string): Factory<[data: string] | [data: Buffer | ArrayBuffer, type: string]> {\n return (url, ...args) => {\n let prefix = 'base64://'\n if (typeof args[0] === 'string') {\n prefix = `data:${args.shift()};base64,`\n }\n if (is('Buffer', url)) {\n url = prefix + url.toString('base64')\n } else if (is('ArrayBuffer', url)) {\n url = prefix + arrayBufferToBase64(url)\n }\n if (url.startsWith('base64://')) {\n warn(`protocol \"base64:\" is deprecated and will be removed in the future, please use \"data:\" instead`)\n }\n return Element(type, { ...args[0] as {}, url })\n }\n }\n\n export const text = createFactory<[content: any]>('text', 'content')\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 export function i18n(path: string | Dict, children?: any[]) {\n return Element('i18n', typeof path === 'string' ? { path } : path, children)\n }\n}\n\nexport =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WAAW,WAAW,GAAG;AAC/B,gBAAAA,SAAA,MAAK,gGAAgG;AAAA,UACvG;AACA,iBAAOA,SAAQ,MAAM,EAAE,GAAG,KAAK,CAAC,GAAS,IAAI,CAAC;AAAA,QAChD;AAAA,MACF;AAhBS;AAkBF,MAAMA,SAAA,OAAO,cAA8B,QAAQ,SAAS;AAC5D,MAAMA,SAAA,KAAK,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;AAEtC,eAAS,KAAK,MAAqB,UAAkB;AAC1D,eAAOA,SAAQ,QAAQ,OAAO,SAAS,WAAW,EAAE,KAAK,IAAI,MAAM,QAAQ;AAAA,MAC7E;AAFO,MAAAA,SAAS;AAAA;AAAA,OAhUR;AAqUV,qBAAS;AAAA;AAAA;",
|
|
6
6
|
"names": ["Element", "source", "children"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@satorijs/element",
|
|
3
3
|
"description": "Element Manipulation",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.5.1",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
|
-
"
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./lib/index.mjs",
|
|
11
11
|
"require": "./lib/index.cjs",
|
|
12
|
-
"
|
|
12
|
+
"types": "./lib/index.d.ts"
|
|
13
13
|
},
|
|
14
14
|
"./jsx-runtime": {
|
|
15
15
|
"import": "./lib/index.mjs",
|
|
16
16
|
"require": "./lib/index.cjs",
|
|
17
|
-
"
|
|
17
|
+
"types": "./lib/index.d.ts"
|
|
18
18
|
},
|
|
19
19
|
"./jsx-dev-runtime": {
|
|
20
20
|
"import": "./lib/index.mjs",
|
|
21
21
|
"require": "./lib/index.cjs",
|
|
22
|
-
"
|
|
22
|
+
"types": "./lib/index.d.ts"
|
|
23
23
|
},
|
|
24
24
|
"./package.json": "./package.json"
|
|
25
25
|
},
|
|
@@ -51,6 +51,6 @@
|
|
|
51
51
|
"chai-shape": "^1.0.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"cosmokit": "^1.4.
|
|
54
|
+
"cosmokit": "^1.4.5"
|
|
55
55
|
}
|
|
56
56
|
}
|