@xharness/satori-element 0.0.0-stage → 4.0.1-alpha.2
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/LICENSE +21 -0
- package/lib/index.js +871 -0
- package/lib/types/elements.d.ts +54 -0
- package/lib/types/elements.d.ts.map +1 -0
- package/lib/types/factory.d.ts +84 -0
- package/lib/types/factory.d.ts.map +1 -0
- package/lib/types/index.d.ts +15 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/normalize.d.ts +31 -0
- package/lib/types/normalize.d.ts.map +1 -0
- package/lib/types/text.d.ts +10 -0
- package/lib/types/text.d.ts.map +1 -0
- package/lib/types/variants.d.ts +30 -0
- package/lib/types/variants.d.ts.map +1 -0
- package/lib/types/vocabulary.d.ts +364 -0
- package/lib/types/vocabulary.d.ts.map +1 -0
- package/package.json +53 -3
- package/src/elements.ts +159 -0
- package/src/factory.ts +163 -0
- package/src/index.ts +16 -0
- package/src/normalize.ts +397 -0
- package/src/text.ts +161 -0
- package/src/variants.ts +83 -0
- package/src/vocabulary.ts +300 -0
- package/README.md +0 -3
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block/inline category table of the element vocabulary and the content model `normalize` enforces.
|
|
3
|
+
*/
|
|
4
|
+
import type { Tag } from './vocabulary.ts';
|
|
5
|
+
/** Element category. */
|
|
6
|
+
export type Category = 'root' | 'envelope' | 'inline' | 'block' | 'media' | 'interactive' | 'control' | 'alternative' | 'input' | 'inbound';
|
|
7
|
+
/** T1 = core fallback + at least one v1 mode; T2 = vocabulary + core fallback only. T3 tags are `reservedTags`. */
|
|
8
|
+
export type Tier = 1 | 2;
|
|
9
|
+
/**
|
|
10
|
+
* Where an element may stand: `inline` = phrasing content only (a bare run at flow level is wrapped into `<p>`),
|
|
11
|
+
* `block` = flow content only, `any` = both (media, buttons, inbound wrappers: block when standing in a flow
|
|
12
|
+
* container, inline inside phrasing content — see the `img.inline` / `button.inline` variants).
|
|
13
|
+
*/
|
|
14
|
+
export type Position = 'inline' | 'block' | 'any';
|
|
15
|
+
/**
|
|
16
|
+
* What an element may contain:
|
|
17
|
+
* - `flow`: blocks; bare inline runs are wrapped into `<p>` (message, li, td, th, blockquote);
|
|
18
|
+
* - `details`: flow content with an optional leading `<summary>`;
|
|
19
|
+
* - `phrasing`: inline content;
|
|
20
|
+
* - `text`: text only (`br` becomes `\n`);
|
|
21
|
+
* - `list` / `table` / `row` / `buttons` / `options`: only `li` / `tr` / `th|td` / `button` / `option` children;
|
|
22
|
+
* - `cases`: only `case` children, each holding content of the model of the `<fallback>`'s own parent;
|
|
23
|
+
* - `empty`: no children.
|
|
24
|
+
*/
|
|
25
|
+
export type ContentModel = 'flow' | 'details' | 'phrasing' | 'text' | 'list' | 'table' | 'row' | 'buttons' | 'options' | 'cases' | 'empty';
|
|
26
|
+
export interface ElementInfo {
|
|
27
|
+
readonly category: Category;
|
|
28
|
+
readonly tier: Tier;
|
|
29
|
+
readonly position: Position;
|
|
30
|
+
readonly content: ContentModel;
|
|
31
|
+
/** When set, the element may only be a direct child of these tags (e.g. `li` of `ul`/`ol`). */
|
|
32
|
+
readonly parents?: readonly Tag[];
|
|
33
|
+
/** Attributes that must be non-empty strings. */
|
|
34
|
+
readonly required?: readonly string[];
|
|
35
|
+
}
|
|
36
|
+
export declare const elementInfo: {
|
|
37
|
+
readonly [K in Tag]: ElementInfo;
|
|
38
|
+
};
|
|
39
|
+
/** T3: names reserved for later versions; `normalize` rejects them in v1. */
|
|
40
|
+
export declare const reservedTags: readonly ["math", "time", "sup", "sub", "mark", "sticker", "gallery", "figure", "columns", "poll", "location", "contact", "progress", "countdown"];
|
|
41
|
+
export type ReservedTag = typeof reservedTags[number];
|
|
42
|
+
/** Old Satori / HTML spellings and the v4 tag that replaces them (rejected by `normalize` with a hint). */
|
|
43
|
+
export declare const tagAliases: Readonly<Record<string, Tag>>;
|
|
44
|
+
/** Every tag of the vocabulary. */
|
|
45
|
+
export declare const tags: Tag[];
|
|
46
|
+
export declare function isTag(type: string): type is Tag;
|
|
47
|
+
export declare function isReservedTag(type: string): type is ReservedTag;
|
|
48
|
+
/** Containers whose children are blocks (bare inline runs are wrapped into `<p>`). */
|
|
49
|
+
export declare function isFlowContainer(type: string): boolean;
|
|
50
|
+
/** Containers whose children are inline (phrasing) content. */
|
|
51
|
+
export declare function isPhrasingContainer(type: string): boolean;
|
|
52
|
+
export declare function isInline(type: string): boolean;
|
|
53
|
+
export declare function isBlock(type: string): boolean;
|
|
54
|
+
//# sourceMappingURL=elements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../src/elements.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAE1C,wBAAwB;AACxB,MAAM,MAAM,QAAQ,GAChB,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,aAAa,GAAG,SAAS,GAAG,aAAa,GAAG,OAAO,GACxG,SAAS,CAAA;AAEb,mHAAmH;AACnH,MAAM,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;AAExB;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,CAAA;AAEjD;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,GACpB,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAA;AAEnH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAA;IAC9B,+FAA+F;IAC/F,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,GAAG,EAAE,CAAA;IACjC,iDAAiD;IACjD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACtC;AAUD,eAAO,MAAM,WAAW,EAAE;IAAE,QAAQ,EAAE,CAAC,IAAI,GAAG,GAAG,WAAW;CAoD3D,CAAA;AAED,6EAA6E;AAC7E,eAAO,MAAM,YAAY,oJAGf,CAAA;AACV,MAAM,MAAM,WAAW,GAAG,OAAO,YAAY,CAAC,MAAM,CAAC,CAAA;AAErD,2GAA2G;AAC3G,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAUpD,CAAA;AAED,mCAAmC;AACnC,eAAO,MAAM,IAAI,EAA+B,GAAG,EAAE,CAAA;AAErD,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,GAAG,CAE/C;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,WAAW,CAE/D;AAED,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIrD;AAED,+DAA+D;AAC/D,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIzD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7C"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed factories and the JSX runtime (`@xharness/satori-element/jsx-runtime` resolves to this package's index).
|
|
3
|
+
*/
|
|
4
|
+
import type { Child, Element, ElementMap, Fragment as FragmentType, Tag } from './vocabulary.ts';
|
|
5
|
+
type OptionalKeys<A> = {
|
|
6
|
+
[P in keyof A]-?: {} extends Pick<A, P> ? P : never;
|
|
7
|
+
}[keyof A];
|
|
8
|
+
type Simplify<T> = {
|
|
9
|
+
[P in keyof T]: T[P];
|
|
10
|
+
} & {};
|
|
11
|
+
/**
|
|
12
|
+
* Factory input for a tag's attributes: `ElementMap[K]` where optional attributes also accept `undefined`
|
|
13
|
+
* (dropped at runtime, so callers under `exactOptionalPropertyTypes` can pass `name: user.name`), plus `key`.
|
|
14
|
+
*/
|
|
15
|
+
export type Attrs<K extends Tag> = LooseAttrs<ElementMap[K]>;
|
|
16
|
+
type LooseAttrs<A> = A extends unknown ? Simplify<{
|
|
17
|
+
[P in Exclude<keyof A, OptionalKeys<A>>]: A[P];
|
|
18
|
+
} & {
|
|
19
|
+
[P in OptionalKeys<A>]?: A[P] | undefined;
|
|
20
|
+
} & {
|
|
21
|
+
key?: string | undefined;
|
|
22
|
+
}> : never;
|
|
23
|
+
/** Tags whose attributes are all optional, so `h(tag, ...children)` may omit them. */
|
|
24
|
+
export type BareTag = {
|
|
25
|
+
[K in Tag]: {} extends ElementMap[K] ? K : never;
|
|
26
|
+
}[Tag];
|
|
27
|
+
export interface ElementFactory {
|
|
28
|
+
<K extends Tag>(tag: K, attrs: Attrs<K>, ...children: Child[]): Element<K>;
|
|
29
|
+
<K extends BareTag>(tag: K, ...children: Child[]): Element<K>;
|
|
30
|
+
text(content: string): Element<'text'>;
|
|
31
|
+
/** `<markdown content>`: GFM source, expanded into elements by the IM render engine's `markdown` service. */
|
|
32
|
+
markdown(source: string): Element<'markdown'>;
|
|
33
|
+
}
|
|
34
|
+
/** Element-like check: a `cordis-element` runtime element, or a plain `{ type, attrs, children }` object. */
|
|
35
|
+
export declare function isElement(value: unknown): value is Element;
|
|
36
|
+
/** Runtime tag of a JSX fragment (`<>…</>`); flattened by the factories, `normalize` and `toText`. */
|
|
37
|
+
export declare const Fragment = "";
|
|
38
|
+
export type Fragment = FragmentType;
|
|
39
|
+
/**
|
|
40
|
+
* Parse the XML-ish `Element.toString()` form back into elements (goldens, logs, tests). Not an input format for
|
|
41
|
+
* user content: plain strings passed to `h` / `normalize` are literal text.
|
|
42
|
+
*/
|
|
43
|
+
export declare function parse(source: string): Element[];
|
|
44
|
+
/** @internal Build a runtime element without copying children. */
|
|
45
|
+
export declare function make(type: string, attrs: Record<string, unknown>, children: Element[], key?: string): Element;
|
|
46
|
+
/** Flatten children: strings and numbers become `text`, holes are skipped, fragments and arrays are spliced. */
|
|
47
|
+
export declare function toChildren(child: unknown, out?: Element[]): Element[];
|
|
48
|
+
/**
|
|
49
|
+
* Children of a `<fallback>`: every item is one candidate, kept apart as a `<case>`. A fragment or an array is one
|
|
50
|
+
* candidate holding all of its nodes; holes are skipped.
|
|
51
|
+
*/
|
|
52
|
+
export declare function toCases(items: readonly unknown[]): Element[];
|
|
53
|
+
export declare const h: ElementFactory;
|
|
54
|
+
type AnyElement = Element;
|
|
55
|
+
/** Function component: called eagerly while the tree is built (no React semantics, no state). */
|
|
56
|
+
export type Component<P = any> = (props: P) => Child;
|
|
57
|
+
type JsxProps<K extends Tag> = K extends 'markdown' ? {
|
|
58
|
+
content?: string;
|
|
59
|
+
children?: string | readonly string[];
|
|
60
|
+
} : K extends 'text' ? {
|
|
61
|
+
content: string;
|
|
62
|
+
} : Attrs<K> & {
|
|
63
|
+
children?: Child;
|
|
64
|
+
};
|
|
65
|
+
/** `<case>` is internal: JSX writes a candidate of `<fallback>` as a fragment. */
|
|
66
|
+
type IntrinsicMap = {
|
|
67
|
+
[K in Exclude<Tag, 'case'>]: JsxProps<K>;
|
|
68
|
+
};
|
|
69
|
+
export declare namespace JSX {
|
|
70
|
+
type Element = AnyElement;
|
|
71
|
+
type ElementType = Tag | Component;
|
|
72
|
+
interface ElementChildrenAttribute {
|
|
73
|
+
children: {};
|
|
74
|
+
}
|
|
75
|
+
interface IntrinsicAttributes {
|
|
76
|
+
key?: string | undefined;
|
|
77
|
+
}
|
|
78
|
+
interface IntrinsicElements extends IntrinsicMap {
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Automatic JSX runtime entry (`jsx`, `jsxs`, `jsxDEV`). */
|
|
82
|
+
export declare function jsx(type: Tag | Component | typeof Fragment, props: Record<string, unknown> | null, key?: string): Element;
|
|
83
|
+
export { jsx as jsxs, jsx as jsxDEV };
|
|
84
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/factory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,IAAI,YAAY,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAEhG,KAAK,YAAY,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAAE,CAAC,MAAM,CAAC,CAAC,CAAA;AACvF,KAAK,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAA;AAEhD;;;GAGG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;AAC5D,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,GAClC,QAAQ,CACN;KAAG,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAClD;KAAG,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS;CAAE,GAC7C;IAAE,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE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GAAG,IAAI,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAgBzH;AAED,OAAO,EAAE,GAAG,IAAI,IAAI,EAAE,GAAG,IAAI,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@xharness/satori-element`: the Satori element vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* Also the JSX runtime entry (`jsxImportSource: '@xharness/satori-element'`): `jsx`, `jsxs`, `jsxDEV`,
|
|
5
|
+
* `Fragment` and the `JSX` namespace.
|
|
6
|
+
*/
|
|
7
|
+
export * from './vocabulary.ts';
|
|
8
|
+
export * from './elements.ts';
|
|
9
|
+
export { type Attrs, type BareTag, type Component, type ElementFactory, Fragment, h, isElement, type JSX, jsx, jsxDEV, jsxs, parse } from './factory.ts';
|
|
10
|
+
export * from './normalize.ts';
|
|
11
|
+
export * from './variants.ts';
|
|
12
|
+
export * from './text.ts';
|
|
13
|
+
export { escape, unescape } from '@xharness/cordis-element';
|
|
14
|
+
export { h as default } from './factory.ts';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACxJ,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAE3D,OAAO,EAAE,CAAC,IAAI,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `normalize()`: the structural contract adapters rely on.
|
|
3
|
+
*
|
|
4
|
+
* - the root is one `<message>`;
|
|
5
|
+
* - flow containers (`message`, `li`, `td`, `th`, `blockquote`, `details`) contain blocks: bare inline runs are
|
|
6
|
+
* wrapped into `<p>`, whitespace-only runs between blocks are dropped;
|
|
7
|
+
* - envelope elements (`quote`, `title`) only appear as direct root children, at most one each, hoisted to the
|
|
8
|
+
* front in the order `quote`, `title`; `summary` is hoisted to the front of its `details`;
|
|
9
|
+
* - `<markdown>` stays one element with its source in `content` (text children are joined into it); the IM render
|
|
10
|
+
* engine expands it, so the source is never parsed here;
|
|
11
|
+
* - a `<fallback>` may stand wherever its candidates may: each candidate becomes one `<case>` normalized as content
|
|
12
|
+
* of the element the `<fallback>` stands in (a fallback of phrasing content joins the surrounding inline run);
|
|
13
|
+
* - T3 (reserved), alias and unknown tags are rejected, as are blocks inside phrasing content and children of
|
|
14
|
+
* elements that take none;
|
|
15
|
+
* - adjacent text is merged, empty text dropped. The input is never mutated; the result is idempotent.
|
|
16
|
+
*/
|
|
17
|
+
import type { Child, Element, Tag } from './vocabulary.ts';
|
|
18
|
+
/** Thrown for content that violates the v4 structure. `path` locates the offending node (`message/ul[2]/li[0]`). */
|
|
19
|
+
export declare class NormalizeError extends Error {
|
|
20
|
+
readonly path: string;
|
|
21
|
+
name: string;
|
|
22
|
+
constructor(message: string, path: string);
|
|
23
|
+
}
|
|
24
|
+
/** Normalize any content into one `<message>` root. */
|
|
25
|
+
export declare function normalize(content: Child): Element<'message'>;
|
|
26
|
+
/**
|
|
27
|
+
* Normalize content as the children of an element of tag `parent` (used for fallback output and partial trees).
|
|
28
|
+
* `path` is only used in error messages.
|
|
29
|
+
*/
|
|
30
|
+
export declare function normalizeChildren(content: Child, parent: Tag, path?: string): Element[];
|
|
31
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAE1D,oHAAoH;AACpH,qBAAa,cAAe,SAAQ,KAAK;IAEV,QAAQ,CAAC,IAAI,EAAE,MAAM;IADzC,IAAI,SAAmB;gBACpB,OAAO,EAAE,MAAM,EAAW,IAAI,EAAE,MAAM;CAGnD;AAID,uDAAuD;AACvD,wBAAgB,SAAS,CAAC,OAAO,EAAE,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,CAO5D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,GAAE,MAAe,GAAG,OAAO,EAAE,CAuB/F"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `toText()`: the plain-text projection of content (fallbacks, tests, history, agent-facing inbound text).
|
|
3
|
+
*
|
|
4
|
+
* Total: works on unnormalized trees and never throws for unknown tags (their children are projected).
|
|
5
|
+
* Blocks are separated by one newline; envelope `quote` is omitted, `title` is the first line; a `<fallback>` projects
|
|
6
|
+
* its last candidate; `<markdown>` projects its source as it is (the converter lives with the IM render engine).
|
|
7
|
+
*/
|
|
8
|
+
import type { Child } from './vocabulary.ts';
|
|
9
|
+
export declare function toText(content: Child): string;
|
|
10
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/text.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAW,MAAM,iBAAiB,CAAA;AAIrD,wBAAgB,MAAM,CAAC,OAAO,EAAE,KAAK,GAAG,MAAM,CAE7C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Variant detection: which `element.<tag>.<variant>` keys an element instance needs.
|
|
3
|
+
*/
|
|
4
|
+
import type { Element, ElementKey, Tag, VariantMap, VariantOf } from './vocabulary.ts';
|
|
5
|
+
/** Declared variants per tag, in `VariantMap` order. */
|
|
6
|
+
export declare const variantTable: {
|
|
7
|
+
readonly [K in keyof VariantMap]: readonly VariantMap[K][];
|
|
8
|
+
};
|
|
9
|
+
/** Capability key of a tag or one of its variants: `variantKey('at', 'all')` → `'element.at.all'`. */
|
|
10
|
+
export declare function variantKey<K extends Tag>(tag: K, variant?: VariantOf<K>): ElementKey;
|
|
11
|
+
/**
|
|
12
|
+
* The variant keys an element instance needs, e.g. `<at type="all">` → `['all']`, `<pre lang>` → `['lang']`.
|
|
13
|
+
*
|
|
14
|
+
* Every variant depends only on the element itself, except the position variants `img.inline` and
|
|
15
|
+
* `button.inline`, which need `ancestors` (outermost first, parent last — `RenderContext.ancestors`): they are
|
|
16
|
+
* reported when the parent holds phrasing content (`p`, headings, `b`, `a` …). Without `ancestors` an element is
|
|
17
|
+
* taken to stand in flow position.
|
|
18
|
+
*
|
|
19
|
+
* Rules: `li.checked` = `checked` is a boolean (task item); `li.nested` = the item contains a `ul`/`ol`;
|
|
20
|
+
* `pre.lang` = non-empty `lang`; `span.color` = a `color` other than `default`; `table.align` = some cell has an
|
|
21
|
+
* `align` other than `left` (left is every platform's default, so dropping it is lossless); `td.block` = the cell
|
|
22
|
+
* holds more than one block or anything but a `<p>`; `button.theme` = a `theme` other than `default`;
|
|
23
|
+
* `input.checkbox` = `type="checkbox"` (a separate platform component where one exists); `select.multiple` = the
|
|
24
|
+
* `multiple` flag (a multi-value picker where one exists). `button` variants start with its `type`, so
|
|
25
|
+
* `type="submit"` asks for `element.button.submit`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function variantsOf<K extends Tag>(el: Element<K>, ancestors?: readonly Element[]): readonly VariantOf<K>[];
|
|
28
|
+
/** Capability keys an element instance needs: its tag key followed by its variant keys. */
|
|
29
|
+
export declare function keysOf(el: Element, ancestors?: readonly Element[]): ElementKey[];
|
|
30
|
+
//# sourceMappingURL=variants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../src/variants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEtF,wDAAwD;AACxD,eAAO,MAAM,YAAY,EAAE;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,UAAU,GAAG,SAAS,UAAU,CAAC,CAAC,CAAC,EAAE;CAWtF,CAAA;AAED,sGAAsG;AACtG,wBAAgB,UAAU,CAAC,CAAC,SAAS,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,UAAU,CAEpF;AAYD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,SAAS,CAAC,CAAC,CAAC,EAAE,CAAA;AA2BlH,2FAA2F;AAC3F,wBAAgB,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,UAAU,EAAE,CAEhF"}
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Satori element vocabulary: the typed overlay over the `cordis-element` runtime.
|
|
3
|
+
*
|
|
4
|
+
* Runtime objects stay `cordis-element` elements (`type` / `attrs` / `children`, `toString()` for logs and goldens);
|
|
5
|
+
* everything here is structural typing, so no conversion is ever needed.
|
|
6
|
+
*/
|
|
7
|
+
export type Theme = 'default' | 'info' | 'success' | 'warning' | 'danger';
|
|
8
|
+
export type Color = 'default' | 'muted' | 'info' | 'success' | 'warning' | 'danger';
|
|
9
|
+
export type Align = 'left' | 'center' | 'right';
|
|
10
|
+
/**
|
|
11
|
+
* Payload of a `button[type=action]` interaction.
|
|
12
|
+
*
|
|
13
|
+
* Forward declaration: the vocabulary only knows the platform-neutral fields. `plugin-im-core` augments this
|
|
14
|
+
* interface (module augmentation of `@xharness/satori-element`) with `bot`, `user`, `chat` and `message`, which
|
|
15
|
+
* are protocol types this package cannot depend on.
|
|
16
|
+
*/
|
|
17
|
+
export interface ButtonEvent {
|
|
18
|
+
/** Button id (`button[type=action].id`). */
|
|
19
|
+
id: string;
|
|
20
|
+
/** Optional payload (≤ 256 bytes; QQ data, Lark value). */
|
|
21
|
+
data?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Values of the `<form>` the button stands in, keyed by control `name` — present when the click submitted a form
|
|
24
|
+
* (`button[type=submit]`, or a plain action button inside a `<form>` on a platform that submits with any button).
|
|
25
|
+
* A checkbox reports a boolean, a multiple `<select>` an array in option order.
|
|
26
|
+
*/
|
|
27
|
+
values?: FormValues;
|
|
28
|
+
/** Passive-reply / reply context the adapter may use (QQ event_id, Lark open_message_id). */
|
|
29
|
+
referrer: unknown;
|
|
30
|
+
time: number;
|
|
31
|
+
/**
|
|
32
|
+
* Answer the interaction on the platform, when the platform lets a click carry an answer (a Lark card callback
|
|
33
|
+
* answers with a toast). Resolves once the answer was sent; only the first call counts, and a later call resolves
|
|
34
|
+
* without effect. Absent on platforms without such an answer, and the platform answers on its own once its deadline
|
|
35
|
+
* passes, so a caller that updates the clicked message after answering awaits this first.
|
|
36
|
+
*/
|
|
37
|
+
respond?(answer: ButtonAnswer): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Claim the answer for a listener that calls {@link respond} only after asynchronous work: the platform then does
|
|
40
|
+
* not answer `{}` as soon as intake settles, and answers on its own only once its deadline passes. Absent where
|
|
41
|
+
* {@link respond} is absent.
|
|
42
|
+
*/
|
|
43
|
+
defer?(): void;
|
|
44
|
+
}
|
|
45
|
+
/** Platform-neutral answer to a button click ({@link ButtonEvent.respond}). */
|
|
46
|
+
export interface ButtonAnswer {
|
|
47
|
+
/** A short notice shown to the clicker. */
|
|
48
|
+
toast?: {
|
|
49
|
+
type: 'info' | 'success' | 'warning' | 'error';
|
|
50
|
+
content: string;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export type ButtonCallback = (event: ButtonEvent) => void | Promise<void>;
|
|
54
|
+
/** Values one `<form>` submitted, keyed by the `name` of each control. */
|
|
55
|
+
export type FormValues = Record<string, string | string[] | boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* Payload of a `<select>` interaction: the reader picked an option.
|
|
58
|
+
*
|
|
59
|
+
* The same forward-declaration rule as {@link ButtonEvent} applies — `plugin-im-core` augments this interface with
|
|
60
|
+
* `bot`, `user`, `chat` and `message`.
|
|
61
|
+
*/
|
|
62
|
+
export interface SelectEvent {
|
|
63
|
+
/** Control id (`select.id`). */
|
|
64
|
+
id: string;
|
|
65
|
+
/** Chosen option values: one for a single select, in option order for a `multiple` one. */
|
|
66
|
+
values: string[];
|
|
67
|
+
/** Optional payload (≤ 256 bytes), as on a button. */
|
|
68
|
+
data?: string;
|
|
69
|
+
/** Passive-reply / reply context the adapter may use. */
|
|
70
|
+
referrer: unknown;
|
|
71
|
+
time: number;
|
|
72
|
+
/** Answer the interaction on the platform; same contract as {@link ButtonEvent.respond}. */
|
|
73
|
+
respond?(answer: ButtonAnswer): Promise<void>;
|
|
74
|
+
/** Claim the platform's answer for asynchronous work; same contract as {@link ButtonEvent.defer}. */
|
|
75
|
+
defer?(): void;
|
|
76
|
+
}
|
|
77
|
+
export type SelectCallback = (event: SelectEvent) => void | Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Payload of a checkbox toggle: the reader checked or cleared a `input[type=checkbox]`.
|
|
80
|
+
*
|
|
81
|
+
* The same forward-declaration rule as {@link ButtonEvent} applies — `plugin-im-core` augments this interface with
|
|
82
|
+
* `bot`, `user`, `chat` and `message`.
|
|
83
|
+
*/
|
|
84
|
+
export interface CheckEvent {
|
|
85
|
+
/** Control id (`input.id`). */
|
|
86
|
+
id: string;
|
|
87
|
+
/** State after the toggle. */
|
|
88
|
+
checked: boolean;
|
|
89
|
+
/** Optional payload (≤ 256 bytes), as on a button. */
|
|
90
|
+
data?: string;
|
|
91
|
+
/** Passive-reply / reply context the adapter may use. */
|
|
92
|
+
referrer: unknown;
|
|
93
|
+
time: number;
|
|
94
|
+
/** Answer the interaction on the platform; same contract as {@link ButtonEvent.respond}. */
|
|
95
|
+
respond?(answer: ButtonAnswer): Promise<void>;
|
|
96
|
+
/** Claim the platform's answer for asynchronous work; same contract as {@link ButtonEvent.defer}. */
|
|
97
|
+
defer?(): void;
|
|
98
|
+
}
|
|
99
|
+
export type CheckCallback = (event: CheckEvent) => void | Promise<void>;
|
|
100
|
+
/** Size of a button (`ButtonStyle.size`). */
|
|
101
|
+
export type ButtonSize = 'tiny' | 'small' | 'medium' | 'large';
|
|
102
|
+
/**
|
|
103
|
+
* Exact visual type of a button on platforms that name one (the Lark card `type`); it takes precedence over `theme`
|
|
104
|
+
* there, and platforms without these types ignore it.
|
|
105
|
+
*/
|
|
106
|
+
export type ButtonVariant = 'default' | 'primary' | 'danger' | 'text' | 'primary_text' | 'danger_text' | 'primary_filled' | 'danger_filled' | 'laser';
|
|
107
|
+
/**
|
|
108
|
+
* Optional presentation of a button, shared by every `button` type; a platform ignores what it cannot show. A type
|
|
109
|
+
* alias rather than an interface, so attribute records stay assignable to `Record<string, unknown>`.
|
|
110
|
+
*/
|
|
111
|
+
export type ButtonStyle = {
|
|
112
|
+
theme?: Theme;
|
|
113
|
+
disabled?: boolean;
|
|
114
|
+
size?: ButtonSize;
|
|
115
|
+
/** `default` (fits the label), `fill` (the available width) or a width in pixels. */
|
|
116
|
+
width?: 'default' | 'fill' | number;
|
|
117
|
+
/** Platform icon token (a Feishu standard icon such as `done_outlined`). */
|
|
118
|
+
icon?: string;
|
|
119
|
+
/** Confirmation dialog shown before the click takes effect. */
|
|
120
|
+
confirm?: {
|
|
121
|
+
title: string;
|
|
122
|
+
text: string;
|
|
123
|
+
};
|
|
124
|
+
/** Hover text. */
|
|
125
|
+
tip?: string;
|
|
126
|
+
/** Hover text while `disabled`. */
|
|
127
|
+
disabledTip?: string;
|
|
128
|
+
variant?: ButtonVariant;
|
|
129
|
+
};
|
|
130
|
+
/** Merge-extensible: adapters augment it only for namespaced pure-content tags (none in v1). */
|
|
131
|
+
export interface ElementMap {
|
|
132
|
+
message: {};
|
|
133
|
+
quote: {
|
|
134
|
+
id: string;
|
|
135
|
+
};
|
|
136
|
+
title: {
|
|
137
|
+
subtitle?: string;
|
|
138
|
+
theme?: Theme;
|
|
139
|
+
};
|
|
140
|
+
text: {
|
|
141
|
+
content: string;
|
|
142
|
+
};
|
|
143
|
+
b: {};
|
|
144
|
+
i: {};
|
|
145
|
+
u: {};
|
|
146
|
+
s: {};
|
|
147
|
+
spoiler: {};
|
|
148
|
+
code: {};
|
|
149
|
+
a: {
|
|
150
|
+
href: string;
|
|
151
|
+
};
|
|
152
|
+
at: {
|
|
153
|
+
type: 'user' | 'all' | 'here' | 'role';
|
|
154
|
+
id?: string;
|
|
155
|
+
name?: string;
|
|
156
|
+
};
|
|
157
|
+
channel: {
|
|
158
|
+
id: string;
|
|
159
|
+
name?: string;
|
|
160
|
+
};
|
|
161
|
+
emoji: {
|
|
162
|
+
id: string;
|
|
163
|
+
name?: string;
|
|
164
|
+
};
|
|
165
|
+
span: {
|
|
166
|
+
color?: Color;
|
|
167
|
+
};
|
|
168
|
+
br: {};
|
|
169
|
+
p: {};
|
|
170
|
+
h1: {};
|
|
171
|
+
h2: {};
|
|
172
|
+
h3: {};
|
|
173
|
+
h4: {};
|
|
174
|
+
h5: {};
|
|
175
|
+
h6: {};
|
|
176
|
+
ul: {};
|
|
177
|
+
ol: {
|
|
178
|
+
start?: number;
|
|
179
|
+
};
|
|
180
|
+
li: {
|
|
181
|
+
checked?: boolean;
|
|
182
|
+
};
|
|
183
|
+
blockquote: {};
|
|
184
|
+
pre: {
|
|
185
|
+
lang?: string;
|
|
186
|
+
};
|
|
187
|
+
hr: {};
|
|
188
|
+
table: {};
|
|
189
|
+
tr: {};
|
|
190
|
+
th: {
|
|
191
|
+
align?: Align;
|
|
192
|
+
};
|
|
193
|
+
td: {
|
|
194
|
+
align?: Align;
|
|
195
|
+
};
|
|
196
|
+
details: {
|
|
197
|
+
open?: boolean;
|
|
198
|
+
};
|
|
199
|
+
summary: {};
|
|
200
|
+
small: {};
|
|
201
|
+
img: {
|
|
202
|
+
src: string;
|
|
203
|
+
alt?: string;
|
|
204
|
+
width?: number;
|
|
205
|
+
height?: number;
|
|
206
|
+
};
|
|
207
|
+
audio: {
|
|
208
|
+
src: string;
|
|
209
|
+
name?: string;
|
|
210
|
+
duration?: number;
|
|
211
|
+
};
|
|
212
|
+
video: {
|
|
213
|
+
src: string;
|
|
214
|
+
name?: string;
|
|
215
|
+
duration?: number;
|
|
216
|
+
poster?: string;
|
|
217
|
+
};
|
|
218
|
+
file: {
|
|
219
|
+
src: string;
|
|
220
|
+
name?: string;
|
|
221
|
+
size?: number;
|
|
222
|
+
};
|
|
223
|
+
button: ({
|
|
224
|
+
type: 'action';
|
|
225
|
+
id: string;
|
|
226
|
+
data?: string;
|
|
227
|
+
onClick?: ButtonCallback;
|
|
228
|
+
} & ButtonStyle) | ({
|
|
229
|
+
type: 'link';
|
|
230
|
+
href: string;
|
|
231
|
+
} & ButtonStyle) | ({
|
|
232
|
+
type: 'input';
|
|
233
|
+
text: string;
|
|
234
|
+
send?: boolean;
|
|
235
|
+
} & ButtonStyle) | ({
|
|
236
|
+
type: 'submit';
|
|
237
|
+
id: string;
|
|
238
|
+
data?: string;
|
|
239
|
+
onClick?: ButtonCallback;
|
|
240
|
+
} & ButtonStyle);
|
|
241
|
+
/** `width: 'fill'` shares the row among the buttons (each defaults to `width: 'fill'`); `align` places the row. */
|
|
242
|
+
'button-group': {
|
|
243
|
+
width?: 'auto' | 'fill';
|
|
244
|
+
align?: Align;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* A group of form controls whose values one submit button sends together. A platform without a form container
|
|
248
|
+
* renders the controls one by one and reports them as dropped interactions.
|
|
249
|
+
*/
|
|
250
|
+
form: {
|
|
251
|
+
name: string;
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* One form control. `checkbox` is the separate native component a platform may have, and the only one that reports
|
|
255
|
+
* itself (`onChange`); every other type delivers its value only with the enclosing `<form>`'s submit, keyed by
|
|
256
|
+
* `name`. At least one of `name` and `id` is required: `name` feeds a form, `id` names the toggle callback.
|
|
257
|
+
*/
|
|
258
|
+
input: {
|
|
259
|
+
/** Form key inside a `<form>`; absent on a live checkbox that only reports its own toggles. */
|
|
260
|
+
name?: string;
|
|
261
|
+
/** Callback identity of a live checkbox. */
|
|
262
|
+
id?: string;
|
|
263
|
+
onChange?: CheckCallback;
|
|
264
|
+
type?: 'text' | 'multiline' | 'password' | 'checkbox';
|
|
265
|
+
/** Visible text of a checkbox; the caption above a text field. */
|
|
266
|
+
label?: string;
|
|
267
|
+
placeholder?: string;
|
|
268
|
+
/** Initial value: the text of a text field, the state of a checkbox. */
|
|
269
|
+
value?: string | boolean;
|
|
270
|
+
maxLength?: number;
|
|
271
|
+
required?: boolean;
|
|
272
|
+
disabled?: boolean;
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* A choice control.
|
|
276
|
+
*
|
|
277
|
+
* `id` and `name` name the channel, and at least one is required: an `id` makes it a live control that reports its
|
|
278
|
+
* pick (`onSelect`), a `name` makes it a form field whose value arrives with the enclosing `<form>`'s submit. A
|
|
279
|
+
* `multiple` control is normally a form field — what a pick reports is one option, while the complete selection is
|
|
280
|
+
* what the submit carries.
|
|
281
|
+
*/
|
|
282
|
+
select: {
|
|
283
|
+
/** Callback identity of a live control; absent on a control that only feeds a form. */
|
|
284
|
+
id?: string;
|
|
285
|
+
data?: string;
|
|
286
|
+
onSelect?: SelectCallback;
|
|
287
|
+
multiple?: boolean;
|
|
288
|
+
/** Form key of this control inside a `<form>`; defaults to `id`. */
|
|
289
|
+
name?: string;
|
|
290
|
+
placeholder?: string;
|
|
291
|
+
/** Initially chosen option value(s). */
|
|
292
|
+
value?: string | string[];
|
|
293
|
+
required?: boolean;
|
|
294
|
+
disabled?: boolean;
|
|
295
|
+
};
|
|
296
|
+
/** One choice of a `<select>`; the label is the element's content. */
|
|
297
|
+
option: {
|
|
298
|
+
value: string;
|
|
299
|
+
selected?: boolean;
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Ordered alternatives: each direct child (a fragment counts as one) is a candidate, and a renderer uses the first
|
|
303
|
+
* candidate it renders without degrading anything, else the last candidate.
|
|
304
|
+
*/
|
|
305
|
+
fallback: {};
|
|
306
|
+
/** @internal One candidate of a `<fallback>`; created by the factories and `normalize`, never written by hand. */
|
|
307
|
+
case: {};
|
|
308
|
+
/** Input only; removed by `normalize`. */
|
|
309
|
+
markdown: {
|
|
310
|
+
content: string;
|
|
311
|
+
};
|
|
312
|
+
/** Inbound only. */
|
|
313
|
+
forward: {
|
|
314
|
+
id: string;
|
|
315
|
+
};
|
|
316
|
+
/** Inbound only. */
|
|
317
|
+
raw: {
|
|
318
|
+
platform: string;
|
|
319
|
+
type: string;
|
|
320
|
+
data?: unknown;
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
export type Tag = keyof ElementMap;
|
|
324
|
+
/** Variant vocabulary: produces `element.<tag>.<variant>` keys. */
|
|
325
|
+
export interface VariantMap {
|
|
326
|
+
at: 'user' | 'all' | 'here' | 'role';
|
|
327
|
+
li: 'checked' | 'nested';
|
|
328
|
+
pre: 'lang';
|
|
329
|
+
span: 'color';
|
|
330
|
+
table: 'align';
|
|
331
|
+
td: 'block';
|
|
332
|
+
img: 'inline';
|
|
333
|
+
button: 'action' | 'link' | 'input' | 'submit' | 'theme' | 'inline';
|
|
334
|
+
input: 'checkbox';
|
|
335
|
+
select: 'multiple';
|
|
336
|
+
}
|
|
337
|
+
/** Variants declared for a tag (`never` for tags without variants). */
|
|
338
|
+
export type VariantOf<K extends Tag> = K extends keyof VariantMap ? VariantMap[K] : never;
|
|
339
|
+
/** `element.<tag>` and `element.<tag>.<variant>` capability keys (re-exported by plugin-im-core). */
|
|
340
|
+
export type ElementKey = {
|
|
341
|
+
[K in Tag]: `element.${K}` | (K extends keyof VariantMap ? `element.${K}.${VariantMap[K]}` : never);
|
|
342
|
+
}[Tag];
|
|
343
|
+
/** One element of a specific tag. */
|
|
344
|
+
export interface TypedElement<K extends Tag> {
|
|
345
|
+
type: K;
|
|
346
|
+
attrs: ElementMap[K];
|
|
347
|
+
children: Element[];
|
|
348
|
+
/** Optional stable identity used by streaming diffs (React-like key, no React semantics). */
|
|
349
|
+
key?: string;
|
|
350
|
+
/** XML-ish form for logs and goldens (`cordis-element` runtime). */
|
|
351
|
+
toString(strip?: boolean): string;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* An element. `Element` (no argument) is the discriminated union over every tag, so `el.type === 'a'` narrows
|
|
355
|
+
* `el.attrs` to `{ href: string }`; `Element<'a'>` is that single member.
|
|
356
|
+
*/
|
|
357
|
+
export type Element<K extends Tag = Tag> = K extends Tag ? TypedElement<K> : never;
|
|
358
|
+
export type Fragment = string | Element | readonly (string | Element)[];
|
|
359
|
+
/**
|
|
360
|
+
* Anything the factories, JSX and `normalize` accept as children: a `Fragment` plus numbers, nested arrays and the
|
|
361
|
+
* conditional-rendering holes `null`, `undefined`, `true`, `false` (which render nothing).
|
|
362
|
+
*/
|
|
363
|
+
export type Child = string | number | boolean | null | undefined | Element | readonly Child[];
|
|
364
|
+
//# sourceMappingURL=vocabulary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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