@elastic/isomer-sdk 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.txt +0 -286
- package/README.md +13 -2
- package/THIRD_PARTY_LICENSES.md +1 -885
- package/dist/author/authored_fields.d.ts +93 -18
- package/dist/author/authored_fields.d.ts.map +1 -1
- package/dist/author/authored_fields.js +63 -43
- package/dist/author/authored_fields.js.map +1 -1
- package/dist/author/authoring_input.d.ts +7 -0
- package/dist/author/authoring_input.d.ts.map +1 -0
- package/dist/author/authoring_input.js +66 -0
- package/dist/author/authoring_input.js.map +1 -0
- package/dist/author/authoring_model.d.ts +33 -0
- package/dist/author/authoring_model.d.ts.map +1 -0
- package/dist/author/authoring_model.js +142 -0
- package/dist/author/authoring_model.js.map +1 -0
- package/dist/author/declarations.d.ts +13 -0
- package/dist/author/declarations.d.ts.map +1 -0
- package/dist/author/declarations.js +288 -0
- package/dist/author/declarations.js.map +1 -0
- package/dist/author/index.d.ts +4 -1
- package/dist/author/index.d.ts.map +1 -1
- package/dist/author/index.js +4 -1
- package/dist/author/index.js.map +1 -1
- package/dist/author/jsx_shim.d.ts +50 -30
- package/dist/author/jsx_shim.d.ts.map +1 -1
- package/dist/author/jsx_shim.js +146 -138
- package/dist/author/jsx_shim.js.map +1 -1
- package/dist/author/print_jsx.d.ts +19 -0
- package/dist/author/print_jsx.d.ts.map +1 -0
- package/dist/author/print_jsx.js +372 -0
- package/dist/author/print_jsx.js.map +1 -0
- package/dist/author/prompt.d.ts +2 -2
- package/dist/author/prompt.d.ts.map +1 -1
- package/dist/author/prompt.js +7 -2
- package/dist/author/prompt.js.map +1 -1
- package/dist/author/schema_to_typescript.d.ts +37 -0
- package/dist/author/schema_to_typescript.d.ts.map +1 -0
- package/dist/author/schema_to_typescript.js +289 -0
- package/dist/author/schema_to_typescript.js.map +1 -0
- package/dist/cjs/author/authored_fields.js +68 -47
- package/dist/cjs/author/authored_fields.js.map +1 -1
- package/dist/cjs/author/authoring_input.js +70 -0
- package/dist/cjs/author/authoring_input.js.map +1 -0
- package/dist/cjs/author/authoring_model.js +149 -0
- package/dist/cjs/author/authoring_model.js.map +1 -0
- package/dist/cjs/author/declarations.js +292 -0
- package/dist/cjs/author/declarations.js.map +1 -0
- package/dist/cjs/author/index.js +10 -1
- package/dist/cjs/author/index.js.map +1 -1
- package/dist/cjs/author/jsx_shim.js +148 -140
- package/dist/cjs/author/jsx_shim.js.map +1 -1
- package/dist/cjs/author/print_jsx.js +378 -0
- package/dist/cjs/author/print_jsx.js.map +1 -0
- package/dist/cjs/author/prompt.js +7 -2
- package/dist/cjs/author/prompt.js.map +1 -1
- package/dist/cjs/author/schema_to_typescript.js +298 -0
- package/dist/cjs/author/schema_to_typescript.js.map +1 -0
- package/dist/cjs/composition/body_node_base.js +11 -4
- package/dist/cjs/composition/body_node_base.js.map +1 -1
- package/dist/cjs/composition/error.js +2 -0
- package/dist/cjs/composition/error.js.map +1 -1
- package/dist/cjs/composition/index.js +2 -1
- package/dist/cjs/composition/index.js.map +1 -1
- package/dist/cjs/composition/structured_value.js.map +1 -1
- package/dist/cjs/define/frame.js +2 -3
- package/dist/cjs/define/frame.js.map +1 -1
- package/dist/cjs/define/index.js +7 -1
- package/dist/cjs/define/index.js.map +1 -1
- package/dist/cjs/define/primitive_example.js +26 -0
- package/dist/cjs/define/primitive_example.js.map +1 -0
- package/dist/cjs/define/primitive_icon.js +17 -0
- package/dist/cjs/define/primitive_icon.js.map +1 -0
- package/dist/cjs/define/primitive_module.js +24 -7
- package/dist/cjs/define/primitive_module.js.map +1 -1
- package/dist/cjs/define/slack_assets.js.map +1 -1
- package/dist/cjs/entries/index.js +8 -2
- package/dist/cjs/entries/index.js.map +1 -1
- package/dist/cjs/entries/markdown.js +2 -1
- package/dist/cjs/entries/markdown.js.map +1 -1
- package/dist/cjs/entries/slack.js +1 -2
- package/dist/cjs/entries/slack.js.map +1 -1
- package/dist/cjs/pack/capabilities.js +17 -11
- package/dist/cjs/pack/capabilities.js.map +1 -1
- package/dist/cjs/pack/compose.js +4 -1
- package/dist/cjs/pack/compose.js.map +1 -1
- package/dist/cjs/pack/index.js +2 -1
- package/dist/cjs/pack/index.js.map +1 -1
- package/dist/cjs/pack/primitive_pack.js +27 -5
- package/dist/cjs/pack/primitive_pack.js.map +1 -1
- package/dist/cjs/render/anchors.js +1 -1
- package/dist/cjs/render/anchors.js.map +1 -1
- package/dist/cjs/render/format_number.js +2 -1
- package/dist/cjs/render/format_number.js.map +1 -1
- package/dist/cjs/render/html/envelope.js +12 -6
- package/dist/cjs/render/html/envelope.js.map +1 -1
- package/dist/cjs/render/layout_check.js.map +1 -1
- package/dist/cjs/render/markdown/builder.js +18 -8
- package/dist/cjs/render/markdown/builder.js.map +1 -1
- package/dist/cjs/render/markdown/format.js +70 -30
- package/dist/cjs/render/markdown/format.js.map +1 -1
- package/dist/cjs/render/markdown/host_tags.js +67 -0
- package/dist/cjs/render/markdown/host_tags.js.map +1 -0
- package/dist/cjs/render/markdown/index.js +3 -1
- package/dist/cjs/render/markdown/index.js.map +1 -1
- package/dist/cjs/render/markdown/split.js +325 -0
- package/dist/cjs/render/markdown/split.js.map +1 -0
- package/dist/cjs/render/primitive_dispatch.js +11 -25
- package/dist/cjs/render/primitive_dispatch.js.map +1 -1
- package/dist/cjs/render/react/content.js +3 -1
- package/dist/cjs/render/react/content.js.map +1 -1
- package/dist/cjs/render/slack/format.js +1 -601
- package/dist/cjs/render/slack/format.js.map +1 -1
- package/dist/cjs/render/slack/index.js +1 -2
- package/dist/cjs/render/slack/index.js.map +1 -1
- package/dist/cjs/render/slack/markdown_content.js +172 -115
- package/dist/cjs/render/slack/markdown_content.js.map +1 -1
- package/dist/cjs/testing/conformance.js +40 -24
- package/dist/cjs/testing/conformance.js.map +1 -1
- package/dist/cjs/testing/icon.js +248 -0
- package/dist/cjs/testing/icon.js.map +1 -0
- package/dist/cjs/testing/index.js +3 -1
- package/dist/cjs/testing/index.js.map +1 -1
- package/dist/cjs/testing/registration.js +5 -3
- package/dist/cjs/testing/registration.js.map +1 -1
- package/dist/cjs/validate/authoring_schema.js +17 -1
- package/dist/cjs/validate/authoring_schema.js.map +1 -1
- package/dist/cjs/validate/index.js +2 -1
- package/dist/cjs/validate/index.js.map +1 -1
- package/dist/cjs/validate/json_schema.js +10 -3
- package/dist/cjs/validate/json_schema.js.map +1 -1
- package/dist/cjs/validate/url.js +2 -1
- package/dist/cjs/validate/url.js.map +1 -1
- package/dist/cjs/validate/validation.js +2 -45
- package/dist/cjs/validate/validation.js.map +1 -1
- package/dist/composition/body_node_base.d.ts +7 -6
- package/dist/composition/body_node_base.d.ts.map +1 -1
- package/dist/composition/body_node_base.js +10 -3
- package/dist/composition/body_node_base.js.map +1 -1
- package/dist/composition/error.d.ts +2 -0
- package/dist/composition/error.d.ts.map +1 -1
- package/dist/composition/error.js +2 -0
- package/dist/composition/error.js.map +1 -1
- package/dist/composition/index.d.ts +1 -1
- package/dist/composition/index.d.ts.map +1 -1
- package/dist/composition/index.js +1 -1
- package/dist/composition/index.js.map +1 -1
- package/dist/composition/structured_value.d.ts +3 -3
- package/dist/composition/structured_value.d.ts.map +1 -1
- package/dist/composition/structured_value.js.map +1 -1
- package/dist/define/frame.d.ts +9 -20
- package/dist/define/frame.d.ts.map +1 -1
- package/dist/define/frame.js +2 -3
- package/dist/define/frame.js.map +1 -1
- package/dist/define/index.d.ts +3 -1
- package/dist/define/index.d.ts.map +1 -1
- package/dist/define/index.js +3 -1
- package/dist/define/index.js.map +1 -1
- package/dist/define/primitive_example.d.ts +30 -0
- package/dist/define/primitive_example.d.ts.map +1 -0
- package/dist/define/primitive_example.js +21 -0
- package/dist/define/primitive_example.js.map +1 -0
- package/dist/define/primitive_icon.d.ts +11 -0
- package/dist/define/primitive_icon.d.ts.map +1 -0
- package/dist/define/primitive_icon.js +14 -0
- package/dist/define/primitive_icon.js.map +1 -0
- package/dist/define/primitive_module.d.ts +45 -24
- package/dist/define/primitive_module.d.ts.map +1 -1
- package/dist/define/primitive_module.js +24 -7
- package/dist/define/primitive_module.js.map +1 -1
- package/dist/define/slack_assets.d.ts +1 -1
- package/dist/define/slack_assets.d.ts.map +1 -1
- package/dist/define/slack_assets.js.map +1 -1
- package/dist/entries/index.d.ts +3 -3
- package/dist/entries/index.d.ts.map +1 -1
- package/dist/entries/index.js +3 -3
- package/dist/entries/index.js.map +1 -1
- package/dist/entries/markdown.d.ts +1 -1
- package/dist/entries/markdown.d.ts.map +1 -1
- package/dist/entries/markdown.js +1 -1
- package/dist/entries/markdown.js.map +1 -1
- package/dist/entries/slack.d.ts +1 -1
- package/dist/entries/slack.d.ts.map +1 -1
- package/dist/entries/slack.js +1 -1
- package/dist/entries/slack.js.map +1 -1
- package/dist/pack/capabilities.d.ts +24 -10
- package/dist/pack/capabilities.d.ts.map +1 -1
- package/dist/pack/capabilities.js +17 -11
- package/dist/pack/capabilities.js.map +1 -1
- package/dist/pack/compose.d.ts +4 -1
- package/dist/pack/compose.d.ts.map +1 -1
- package/dist/pack/compose.js +4 -1
- package/dist/pack/compose.js.map +1 -1
- package/dist/pack/index.d.ts +2 -2
- package/dist/pack/index.d.ts.map +1 -1
- package/dist/pack/index.js +2 -2
- package/dist/pack/index.js.map +1 -1
- package/dist/pack/primitive_pack.d.ts +14 -3
- package/dist/pack/primitive_pack.d.ts.map +1 -1
- package/dist/pack/primitive_pack.js +25 -4
- package/dist/pack/primitive_pack.js.map +1 -1
- package/dist/render/anchors.d.ts +2 -2
- package/dist/render/anchors.d.ts.map +1 -1
- package/dist/render/anchors.js +1 -1
- package/dist/render/anchors.js.map +1 -1
- package/dist/render/format_number.d.ts.map +1 -1
- package/dist/render/format_number.js +2 -1
- package/dist/render/format_number.js.map +1 -1
- package/dist/render/html/envelope.d.ts +3 -3
- package/dist/render/html/envelope.js +12 -6
- package/dist/render/html/envelope.js.map +1 -1
- package/dist/render/layout_check.d.ts +1 -1
- package/dist/render/layout_check.d.ts.map +1 -1
- package/dist/render/layout_check.js.map +1 -1
- package/dist/render/markdown/builder.d.ts +5 -4
- package/dist/render/markdown/builder.d.ts.map +1 -1
- package/dist/render/markdown/builder.js +16 -7
- package/dist/render/markdown/builder.js.map +1 -1
- package/dist/render/markdown/format.d.ts +9 -0
- package/dist/render/markdown/format.d.ts.map +1 -1
- package/dist/render/markdown/format.js +67 -31
- package/dist/render/markdown/format.js.map +1 -1
- package/dist/render/markdown/host_tags.d.ts +14 -0
- package/dist/render/markdown/host_tags.d.ts.map +1 -0
- package/dist/render/markdown/host_tags.js +63 -0
- package/dist/render/markdown/host_tags.js.map +1 -0
- package/dist/render/markdown/index.d.ts +1 -0
- package/dist/render/markdown/index.d.ts.map +1 -1
- package/dist/render/markdown/index.js +1 -0
- package/dist/render/markdown/index.js.map +1 -1
- package/dist/render/markdown/split.d.ts +32 -0
- package/dist/render/markdown/split.d.ts.map +1 -0
- package/dist/render/markdown/split.js +321 -0
- package/dist/render/markdown/split.js.map +1 -0
- package/dist/render/primitive_dispatch.d.ts +6 -6
- package/dist/render/primitive_dispatch.d.ts.map +1 -1
- package/dist/render/primitive_dispatch.js +12 -26
- package/dist/render/primitive_dispatch.js.map +1 -1
- package/dist/render/react/content.d.ts +1 -1
- package/dist/render/react/content.d.ts.map +1 -1
- package/dist/render/react/content.js +3 -1
- package/dist/render/react/content.js.map +1 -1
- package/dist/render/slack/format.d.ts +0 -25
- package/dist/render/slack/format.d.ts.map +1 -1
- package/dist/render/slack/format.js +1 -599
- package/dist/render/slack/format.js.map +1 -1
- package/dist/render/slack/index.d.ts +1 -1
- package/dist/render/slack/index.d.ts.map +1 -1
- package/dist/render/slack/index.js +1 -1
- package/dist/render/slack/index.js.map +1 -1
- package/dist/render/slack/markdown_content.d.ts +10 -4
- package/dist/render/slack/markdown_content.d.ts.map +1 -1
- package/dist/render/slack/markdown_content.js +169 -113
- package/dist/render/slack/markdown_content.js.map +1 -1
- package/dist/testing/conformance.d.ts +19 -14
- package/dist/testing/conformance.d.ts.map +1 -1
- package/dist/testing/conformance.js +40 -24
- package/dist/testing/conformance.js.map +1 -1
- package/dist/testing/icon.d.ts +11 -0
- package/dist/testing/icon.d.ts.map +1 -0
- package/dist/testing/icon.js +244 -0
- package/dist/testing/icon.js.map +1 -0
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/registration.d.ts +1 -1
- package/dist/testing/registration.d.ts.map +1 -1
- package/dist/testing/registration.js +6 -4
- package/dist/testing/registration.js.map +1 -1
- package/dist/validate/authoring_schema.d.ts +6 -0
- package/dist/validate/authoring_schema.d.ts.map +1 -1
- package/dist/validate/authoring_schema.js +15 -0
- package/dist/validate/authoring_schema.js.map +1 -1
- package/dist/validate/index.d.ts +1 -1
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +1 -1
- package/dist/validate/index.js.map +1 -1
- package/dist/validate/json_schema.d.ts.map +1 -1
- package/dist/validate/json_schema.js +10 -3
- package/dist/validate/json_schema.js.map +1 -1
- package/dist/validate/url.d.ts.map +1 -1
- package/dist/validate/url.js +2 -1
- package/dist/validate/url.js.map +1 -1
- package/dist/validate/validation.d.ts +1 -11
- package/dist/validate/validation.d.ts.map +1 -1
- package/dist/validate/validation.js +3 -46
- package/dist/validate/validation.js.map +1 -1
- package/package.json +3 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PrimitiveIcon } from '../define/primitive_icon.js';
|
|
1
2
|
import type { AnyPrimitiveDefinition, OptionalSurface, StyleHandle } from '../define/primitive_module.js';
|
|
2
3
|
import type { EnhancementDefinition } from './enhancements.js';
|
|
3
4
|
/**
|
|
@@ -13,7 +14,7 @@ export interface PackAuthoringOptions {
|
|
|
13
14
|
describe?: Readonly<Record<string, string>>;
|
|
14
15
|
/** `$defId.property` paths to drop, from this pack's own primitives. */
|
|
15
16
|
omitProperties?: readonly string[];
|
|
16
|
-
/** Headings an index catalog sorts this pack's primitives under, in order. */
|
|
17
|
+
/** Headings an index catalog sorts this pack's primitives under, in order. A type in none is listed under {@link UNCATEGORIZED_GROUP_TITLE}. */
|
|
17
18
|
groups?: readonly PrimitiveGroup[];
|
|
18
19
|
}
|
|
19
20
|
/** A titled set of primitive types, listed together in an index catalog. */
|
|
@@ -21,6 +22,8 @@ export interface PrimitiveGroup {
|
|
|
21
22
|
title: string;
|
|
22
23
|
types: readonly string[];
|
|
23
24
|
}
|
|
25
|
+
/** The index heading for primitives in no group. A pack cannot declare a group with this title. */
|
|
26
|
+
export declare const UNCATEGORIZED_GROUP_TITLE = "Uncategorized";
|
|
24
27
|
/**
|
|
25
28
|
* The HTML style-adapter hooks a pack may declare. Typed loosely here so `pack/` does not import `render/`.
|
|
26
29
|
*/
|
|
@@ -98,7 +101,7 @@ export interface PrimitivePackInput {
|
|
|
98
101
|
* A pack as the runtime sees it.
|
|
99
102
|
*
|
|
100
103
|
* `TTheme` is the palette this pack's `react` renderers read as `env.theme`
|
|
101
|
-
* when drawn through the `
|
|
104
|
+
* when drawn through the `snapshot` surface — a *lower bound* on whatever theme
|
|
102
105
|
* the runtime holding it supplies. It is carried by
|
|
103
106
|
* {@link PrimitivePack.__theme} rather than by any real field, because
|
|
104
107
|
* `primitives` is erased to `AnyPrimitiveDefinition[]` and a heterogeneous
|
|
@@ -119,6 +122,12 @@ export interface PrimitivePack<TTheme = unknown> {
|
|
|
119
122
|
readonly primitives: readonly AnyPrimitiveDefinition[];
|
|
120
123
|
/** Node types this pack owns, for duplicate detection across packs. */
|
|
121
124
|
readonly types: ReadonlySet<string>;
|
|
125
|
+
/**
|
|
126
|
+
* Each primitive's `icon` by type, for the primitives that declare one, so a host listing them need not walk `primitives`.
|
|
127
|
+
*
|
|
128
|
+
* A frozen null-prototype dictionary: an absent type reads `undefined`, even `constructor`. Absent on a pack built by an SDK that predates icons; {@link iconsByType} derives it from `primitives`.
|
|
129
|
+
*/
|
|
130
|
+
readonly icons?: Readonly<Record<string, PrimitiveIcon>>;
|
|
122
131
|
/** See {@link PrimitivePackInput.enhancements}. */
|
|
123
132
|
readonly enhancements: readonly EnhancementDefinition[];
|
|
124
133
|
/** See {@link PrimitivePackInput.slackAssetTypes}. */
|
|
@@ -148,8 +157,10 @@ export type AnyPrimitivePack = PrimitivePack<never>;
|
|
|
148
157
|
* Builds a {@link PrimitivePack}.
|
|
149
158
|
*
|
|
150
159
|
* `TTheme` is the palette a frame must supply for this pack's nodes to be drawn
|
|
151
|
-
* on the `
|
|
160
|
+
* on the `snapshot` surface: `definePrimitivePack<CoreTokens>(input)`. Omitted, it is
|
|
152
161
|
* `unknown`, which requires nothing.
|
|
153
162
|
*/
|
|
154
163
|
export declare const definePrimitivePack: <TTheme = unknown>(input: PrimitivePackInput) => PrimitivePack<TTheme>;
|
|
164
|
+
/** Each definition's `icon` by type, null-prototype so a type such as `__proto__` is an ordinary key. */
|
|
165
|
+
export declare const iconsByType: (primitives: readonly AnyPrimitiveDefinition[]) => Readonly<Record<string, PrimitiveIcon>>;
|
|
155
166
|
//# sourceMappingURL=primitive_pack.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitive_pack.d.ts","sourceRoot":"","sources":["../../src/pack/primitive_pack.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,WAAW,EACZ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAE5D;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,wEAAwE;IACxE,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,
|
|
1
|
+
{"version":3,"file":"primitive_pack.d.ts","sourceRoot":"","sources":["../../src/pack/primitive_pack.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AAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,GAAG,OAAO,EAClD,OAAO,kBAAkB,KACxB,aAAa,CAAC,MAAM,CAoCtB,CAAC;AAEF,yGAAyG;AACzG,eAAO,MAAM,WAAW,GACtB,YAAY,SAAS,sBAAsB,EAAE,KAC5C,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAQxC,CAAC"}
|
|
@@ -8,11 +8,13 @@
|
|
|
8
8
|
// primitive in it implements. Additive: a runtime composes any number of packs,
|
|
9
9
|
// and nothing about a pack decides how a composition is framed.
|
|
10
10
|
import { IsomerError } from '../composition/error.js';
|
|
11
|
+
/** The index heading for primitives in no group. A pack cannot declare a group with this title. */
|
|
12
|
+
export const UNCATEGORIZED_GROUP_TITLE = 'Uncategorized';
|
|
11
13
|
/**
|
|
12
14
|
* Builds a {@link PrimitivePack}.
|
|
13
15
|
*
|
|
14
16
|
* `TTheme` is the palette a frame must supply for this pack's nodes to be drawn
|
|
15
|
-
* on the `
|
|
17
|
+
* on the `snapshot` surface: `definePrimitivePack<CoreTokens>(input)`. Omitted, it is
|
|
16
18
|
* `unknown`, which requires nothing.
|
|
17
19
|
*/
|
|
18
20
|
export const definePrimitivePack = (input) => {
|
|
@@ -22,7 +24,7 @@ export const definePrimitivePack = (input) => {
|
|
|
22
24
|
assertUniquePrimitiveTypes(input.id, input.primitives);
|
|
23
25
|
assertUniqueEnhancementIds(input.id, input.enhancements ?? []);
|
|
24
26
|
const types = new Set(input.primitives.map((definition) => definition.type));
|
|
25
|
-
|
|
27
|
+
assertValidGroups(input.id, input.authoring?.groups ?? [], types);
|
|
26
28
|
for (const type of input.slackAssetTypes ?? []) {
|
|
27
29
|
if (!types.has(type)) {
|
|
28
30
|
throw new IsomerError('UNKNOWN_PRIMITIVE_TYPE', `primitive pack "${input.id}": slackAssetTypes names primitive type "${type}", which the pack does not register`);
|
|
@@ -34,6 +36,7 @@ export const definePrimitivePack = (input) => {
|
|
|
34
36
|
surfaces: input.surfaces ?? [],
|
|
35
37
|
primitives: input.primitives,
|
|
36
38
|
types,
|
|
39
|
+
icons: iconsByType(input.primitives),
|
|
37
40
|
enhancements: input.enhancements ?? [],
|
|
38
41
|
slackAssetTypes: new Set(input.slackAssetTypes ?? []),
|
|
39
42
|
...(input.styleAdapter !== undefined
|
|
@@ -43,6 +46,16 @@ export const definePrimitivePack = (input) => {
|
|
|
43
46
|
...(input.authoring !== undefined ? { authoring: input.authoring } : {}),
|
|
44
47
|
};
|
|
45
48
|
};
|
|
49
|
+
/** Each definition's `icon` by type, null-prototype so a type such as `__proto__` is an ordinary key. */
|
|
50
|
+
export const iconsByType = (primitives) => {
|
|
51
|
+
const icons = Object.create(null);
|
|
52
|
+
for (const { type, icon } of primitives) {
|
|
53
|
+
if (icon !== undefined) {
|
|
54
|
+
icons[type] = icon;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return Object.freeze(icons);
|
|
58
|
+
};
|
|
46
59
|
/** Throws if `primitives` repeats a type. */
|
|
47
60
|
const assertUniquePrimitiveTypes = (id, primitives) => {
|
|
48
61
|
const seen = new Set();
|
|
@@ -53,10 +66,18 @@ const assertUniquePrimitiveTypes = (id, primitives) => {
|
|
|
53
66
|
seen.add(type);
|
|
54
67
|
}
|
|
55
68
|
};
|
|
56
|
-
/** Throws if a group names a type outside `types`, or
|
|
57
|
-
const
|
|
69
|
+
/** Throws if a group repeats or reserves a title, names a type outside `types`, or shares a type with another. */
|
|
70
|
+
const assertValidGroups = (id, groups, types) => {
|
|
71
|
+
const titles = new Set();
|
|
58
72
|
const grouped = new Set();
|
|
59
73
|
for (const { title, types: members } of groups) {
|
|
74
|
+
if (title === UNCATEGORIZED_GROUP_TITLE) {
|
|
75
|
+
throw new IsomerError('INVALID_PACK_GROUPS', `primitive pack "${id}": group title "${title}" is reserved for primitives in no group`);
|
|
76
|
+
}
|
|
77
|
+
if (titles.has(title)) {
|
|
78
|
+
throw new IsomerError('INVALID_PACK_GROUPS', `primitive pack "${id}": group title "${title}" is used twice`);
|
|
79
|
+
}
|
|
80
|
+
titles.add(title);
|
|
60
81
|
for (const type of members) {
|
|
61
82
|
if (!types.has(type)) {
|
|
62
83
|
throw new IsomerError('UNKNOWN_PRIMITIVE_TYPE', `primitive pack "${id}": group "${title}" names primitive type "${type}", which the pack does not register`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitive_pack.js","sourceRoot":"","sources":["../../src/pack/primitive_pack.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,6EAA6E;AAC7E,gFAAgF;AAChF,gEAAgE;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AA+JnD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,KAAyB,EACF,EAAE;IACzB,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,WAAW,CACnB,YAAY,EACZ,mBAAmB,KAAK,CAAC,EAAE,uCAAuC,CACnE,CAAC;IACJ,CAAC;IACD,0BAA0B,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACvD,0BAA0B,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7E,iBAAiB,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,EAAE,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,uBAAuB,EACvB,mBAAmB,EAAE,mBAAmB,UAAU,CAAC,EAAE,oBAAoB,CAC1E,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// A primitive pack as a value: a vocabulary, and the optional surfaces every\n// primitive in it implements. Additive: a runtime composes any number of packs,\n// and nothing about a pack decides how a composition is framed.\n\nimport { IsomerError } from '../composition/error';\nimport type {\n AnyPrimitiveDefinition,\n OptionalSurface,\n StyleHandle,\n} from '../define/primitive_module';\n\nimport type { EnhancementDefinition } from './enhancements';\n\n/**\n * The authoring-schema material a pack contributes for its own primitives.\n *\n * A subset of `AuthoringJsonSchemaOptions`: `$id`, `title`, `description`, and\n * `composition` describe the whole authoring schema a runtime builds, which is\n * a host decision, not a pack one. `pack/` does not import `validate/` for\n * this, so the shape is declared here rather than reused by reference.\n */\nexport interface PackAuthoringOptions {\n /** `$def` id to `description`, for this pack's own primitives. */\n describe?: Readonly<Record<string, string>>;\n /** `$defId.property` paths to drop, from this pack's own primitives. */\n omitProperties?: readonly string[];\n /** Headings an index catalog sorts this pack's primitives under, in order. */\n groups?: readonly PrimitiveGroup[];\n}\n\n/** A titled set of primitive types, listed together in an index catalog. */\nexport interface PrimitiveGroup {\n title: string;\n types: readonly string[];\n}\n\n/**\n * The HTML style-adapter hooks a pack may declare. Typed loosely here so `pack/` does not import `render/`.\n */\nexport type PackStyleAdapter = {\n /** See {@link PrimitivePackInput.styleCollector}. */\n styleCollector?: string;\n /** The hooks of `HTMLStyleAdapter` from `./html`, erased: a fresh collector per render, the context renderers receive, and the stylesheet the collector produced. */\n createCollector: (...args: never[]) => object;\n createRenderContext: (...args: never[]) => unknown;\n renderStyles: (...args: never[]) => string;\n /**\n * Whether `handle` belongs to this adapter's stylesheet. Required for a runtime to combine several packs' CSS: without it their handles cannot be routed and the host must pick one adapter.\n */\n ownsHandle?: (handle: StyleHandle) => boolean;\n};\n\n/** What a pack author passes to {@link definePrimitivePack}. */\nexport interface PrimitivePackInput {\n /** Stable identifier, used in capability reports and error messages. */\n id: string;\n /**\n * The optional surfaces this pack's primitives implement.\n *\n * Only `slack`, and it stays optional per primitive: the dispatcher converts\n * the mandatory markdown to Block Kit, so declaring it reports an intent\n * rather than imposing a requirement. Omit it entirely for a pack that\n * renders Slack through that fallback.\n */\n surfaces?: readonly OptionalSurface[];\n /** This pack's vocabulary. Node types must be unique within it, or construction throws. */\n primitives: readonly AnyPrimitiveDefinition[];\n /**\n * Progressive enhancements this pack's primitives can apply, by id.\n *\n * Declared by the pack because an enhancement is a fact about its\n * vocabulary — a sortable table, a copyable code block — and a host\n * composing packs it did not write cannot be expected to know the ids.\n * The runtime flattens these across packs; duplicate ids are rejected.\n */\n enhancements?: readonly EnhancementDefinition[];\n /**\n * Types that render as a self-contained picture rather than as text.\n *\n * A channel that cannot draw them inline uploads an image instead: the Slack\n * dispatcher swaps such a node for an `image` block and an upload request, so\n * a chart arrives as a PNG rather than as a markdown approximation of one.\n *\n * Declared by the pack because it is a fact about the vocabulary, and a host\n * composing packs it did not write cannot be expected to know it.\n */\n slackAssetTypes?: readonly string[];\n /**\n * Default HTML style adapter for this pack. A runtime that omits\n * `styleAdapter` runs the packs' own adapters, combined when more than one\n * pack declares one and each answers `ownsHandle`. Pass `styleAdapter` on\n * the runtime to replace them all.\n */\n styleAdapter?: PackStyleAdapter;\n /**\n * Names the collector shape this pack's `collectStyles` hooks mutate, so a\n * runtime can reject a pack paired with an adapter of a different tag.\n * Defaults to `styleAdapter.styleCollector`; a pack with neither opts out of\n * the check.\n */\n styleCollector?: string;\n /**\n * This pack's own contribution to the runtime's authoring JSON Schema.\n *\n * Merged across every composed pack, so a host does not hand-merge each\n * pack's `describe`/`omitProperties` into one options object itself. The\n * runtime-level `authoring` option is merged in last and wins on conflict.\n */\n authoring?: PackAuthoringOptions;\n}\n\n/**\n * A pack as the runtime sees it.\n *\n * `TTheme` is the palette this pack's `react` renderers read as `env.theme`\n * when drawn through the `svg` surface — a *lower bound* on whatever theme\n * the runtime holding it supplies. It is carried by\n * {@link PrimitivePack.__theme} rather than by any real field, because\n * `primitives` is erased to `AnyPrimitiveDefinition[]` and a heterogeneous\n * inventory has no single node type to be generic over.\n *\n * The bound is declared, not derived: nothing checks it against what the\n * renderers actually read. State it at the definition as\n * `definePrimitivePack<T>(input)`.\n * Bare `PrimitivePack` requires nothing and fits any runtime; a slot that must\n * hold packs of every palette is typed {@link AnyPrimitivePack}.\n */\nexport interface PrimitivePack<TTheme = unknown> {\n /** Unique among the packs a runtime composes, and used in error messages. */\n readonly id: string;\n /** See {@link PrimitivePackInput.surfaces}. */\n readonly surfaces: readonly OptionalSurface[];\n /** See {@link PrimitivePackInput.primitives}. */\n readonly primitives: readonly AnyPrimitiveDefinition[];\n /** Node types this pack owns, for duplicate detection across packs. */\n readonly types: ReadonlySet<string>;\n /** See {@link PrimitivePackInput.enhancements}. */\n readonly enhancements: readonly EnhancementDefinition[];\n /** See {@link PrimitivePackInput.slackAssetTypes}. */\n readonly slackAssetTypes: ReadonlySet<string>;\n /** See {@link PrimitivePackInput.styleAdapter}. */\n readonly styleAdapter?: PackStyleAdapter;\n /** See {@link PrimitivePackInput.styleCollector}. */\n readonly styleCollector?: string;\n /** See {@link PrimitivePackInput.authoring}. */\n readonly authoring?: PackAuthoringOptions;\n /**\n * Phantom: never present at runtime, never read.\n *\n * A property rather than a method so `strictFunctionTypes` checks it\n * contravariantly. A method signature is bivariant, which would let a pack\n * needing richer tokens sit in a slot supplying fewer and then read a field\n * nothing supplies — the exact failure this marker exists to prevent.\n */\n readonly __theme?: (theme: TTheme) => void;\n}\n\n/**\n * A pack of any palette, for storage positions: `never` is assignable to every\n * requirement, so a slot typed this way holds every pack.\n */\nexport type AnyPrimitivePack = PrimitivePack<never>;\n\n/**\n * Builds a {@link PrimitivePack}.\n *\n * `TTheme` is the palette a frame must supply for this pack's nodes to be drawn\n * on the `svg` surface: `definePrimitivePack<CoreTokens>(input)`. Omitted, it is\n * `unknown`, which requires nothing.\n */\nexport const definePrimitivePack = <TTheme = unknown>(\n input: PrimitivePackInput\n): PrimitivePack<TTheme> => {\n if (input.primitives.length === 0) {\n throw new IsomerError(\n 'EMPTY_PACK',\n `primitive pack \"${input.id}\": at least one primitive is required`\n );\n }\n assertUniquePrimitiveTypes(input.id, input.primitives);\n assertUniqueEnhancementIds(input.id, input.enhancements ?? []);\n const types = new Set(input.primitives.map((definition) => definition.type));\n assertGroupedOnce(input.id, input.authoring?.groups ?? [], types);\n for (const type of input.slackAssetTypes ?? []) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${input.id}\": slackAssetTypes names primitive type \"${type}\", which the pack does not register`\n );\n }\n }\n const styleCollector =\n input.styleCollector ?? input.styleAdapter?.styleCollector;\n\n return {\n id: input.id,\n surfaces: input.surfaces ?? [],\n primitives: input.primitives,\n types,\n enhancements: input.enhancements ?? [],\n slackAssetTypes: new Set(input.slackAssetTypes ?? []),\n ...(input.styleAdapter !== undefined\n ? { styleAdapter: input.styleAdapter }\n : {}),\n ...(styleCollector !== undefined ? { styleCollector } : {}),\n ...(input.authoring !== undefined ? { authoring: input.authoring } : {}),\n };\n};\n\n/** Throws if `primitives` repeats a type. */\nconst assertUniquePrimitiveTypes = (\n id: string,\n primitives: readonly AnyPrimitiveDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const { type } of primitives) {\n if (seen.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" registered twice`\n );\n }\n seen.add(type);\n }\n};\n\n/** Throws if a group names a type outside `types`, or two groups share a type. */\nconst assertGroupedOnce = (\n id: string,\n groups: readonly PrimitiveGroup[],\n types: ReadonlySet<string>\n): void => {\n const grouped = new Set<string>();\n for (const { title, types: members } of groups) {\n for (const type of members) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": group \"${title}\" names primitive type \"${type}\", which the pack does not register`\n );\n }\n if (grouped.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" is in two groups`\n );\n }\n grouped.add(type);\n }\n }\n};\n\n/** Throws if this pack registers the same enhancement id twice. */\nconst assertUniqueEnhancementIds = (\n id: string,\n enhancements: readonly EnhancementDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const definition of enhancements) {\n if (seen.has(definition.id)) {\n throw new IsomerError(\n 'DUPLICATE_ENHANCEMENT',\n `primitive pack \"${id}\": enhancement \"${definition.id}\" registered twice`\n );\n }\n seen.add(definition.id);\n }\n};\n"]}
|
|
1
|
+
{"version":3,"file":"primitive_pack.js","sourceRoot":"","sources":["../../src/pack/primitive_pack.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,6EAA6E;AAC7E,gFAAgF;AAChF,gEAAgE;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAiCnD,mGAAmG;AACnG,MAAM,CAAC,MAAM,yBAAyB,GAAG,eAAe,CAAC;AAuIzD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,KAAyB,EACF,EAAE;IACzB,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,WAAW,CACnB,YAAY,EACZ,mBAAmB,KAAK,CAAC,EAAE,uCAAuC,CACnE,CAAC;IACJ,CAAC;IACD,0BAA0B,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACvD,0BAA0B,CAAC,KAAK,CAAC,E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CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// A primitive pack as a value: a vocabulary, and the optional surfaces every\n// primitive in it implements. Additive: a runtime composes any number of packs,\n// and nothing about a pack decides how a composition is framed.\n\nimport { IsomerError } from '../composition/error';\nimport type { PrimitiveIcon } from '../define/primitive_icon';\nimport type {\n AnyPrimitiveDefinition,\n OptionalSurface,\n StyleHandle,\n} from '../define/primitive_module';\n\nimport type { EnhancementDefinition } from './enhancements';\n\n/**\n * The authoring-schema material a pack contributes for its own primitives.\n *\n * A subset of `AuthoringJsonSchemaOptions`: `$id`, `title`, `description`, and\n * `composition` describe the whole authoring schema a runtime builds, which is\n * a host decision, not a pack one. `pack/` does not import `validate/` for\n * this, so the shape is declared here rather than reused by reference.\n */\nexport interface PackAuthoringOptions {\n /** `$def` id to `description`, for this pack's own primitives. */\n describe?: Readonly<Record<string, string>>;\n /** `$defId.property` paths to drop, from this pack's own primitives. */\n omitProperties?: readonly string[];\n /** Headings an index catalog sorts this pack's primitives under, in order. A type in none is listed under {@link UNCATEGORIZED_GROUP_TITLE}. */\n groups?: readonly PrimitiveGroup[];\n}\n\n/** A titled set of primitive types, listed together in an index catalog. */\nexport interface PrimitiveGroup {\n title: string;\n types: readonly string[];\n}\n\n/** The index heading for primitives in no group. A pack cannot declare a group with this title. */\nexport const UNCATEGORIZED_GROUP_TITLE = 'Uncategorized';\n\n/**\n * The HTML style-adapter hooks a pack may declare. Typed loosely here so `pack/` does not import `render/`.\n */\nexport type PackStyleAdapter = {\n /** See {@link PrimitivePackInput.styleCollector}. */\n styleCollector?: string;\n /** The hooks of `HTMLStyleAdapter` from `./html`, erased: a fresh collector per render, the context renderers receive, and the stylesheet the collector produced. */\n createCollector: (...args: never[]) => object;\n createRenderContext: (...args: never[]) => unknown;\n renderStyles: (...args: never[]) => string;\n /**\n * Whether `handle` belongs to this adapter's stylesheet. Required for a runtime to combine several packs' CSS: without it their handles cannot be routed and the host must pick one adapter.\n */\n ownsHandle?: (handle: StyleHandle) => boolean;\n};\n\n/** What a pack author passes to {@link definePrimitivePack}. */\nexport interface PrimitivePackInput {\n /** Stable identifier, used in capability reports and error messages. */\n id: string;\n /**\n * The optional surfaces this pack's primitives implement.\n *\n * Only `slack`, and it stays optional per primitive: the dispatcher converts\n * the mandatory markdown to Block Kit, so declaring it reports an intent\n * rather than imposing a requirement. Omit it entirely for a pack that\n * renders Slack through that fallback.\n */\n surfaces?: readonly OptionalSurface[];\n /** This pack's vocabulary. Node types must be unique within it, or construction throws. */\n primitives: readonly AnyPrimitiveDefinition[];\n /**\n * Progressive enhancements this pack's primitives can apply, by id.\n *\n * Declared by the pack because an enhancement is a fact about its\n * vocabulary — a sortable table, a copyable code block — and a host\n * composing packs it did not write cannot be expected to know the ids.\n * The runtime flattens these across packs; duplicate ids are rejected.\n */\n enhancements?: readonly EnhancementDefinition[];\n /**\n * Types that render as a self-contained picture rather than as text.\n *\n * A channel that cannot draw them inline uploads an image instead: the Slack\n * dispatcher swaps such a node for an `image` block and an upload request, so\n * a chart arrives as a PNG rather than as a markdown approximation of one.\n *\n * Declared by the pack because it is a fact about the vocabulary, and a host\n * composing packs it did not write cannot be expected to know it.\n */\n slackAssetTypes?: readonly string[];\n /**\n * Default HTML style adapter for this pack. A runtime that omits\n * `styleAdapter` runs the packs' own adapters, combined when more than one\n * pack declares one and each answers `ownsHandle`. Pass `styleAdapter` on\n * the runtime to replace them all.\n */\n styleAdapter?: PackStyleAdapter;\n /**\n * Names the collector shape this pack's `collectStyles` hooks mutate, so a\n * runtime can reject a pack paired with an adapter of a different tag.\n * Defaults to `styleAdapter.styleCollector`; a pack with neither opts out of\n * the check.\n */\n styleCollector?: string;\n /**\n * This pack's own contribution to the runtime's authoring JSON Schema.\n *\n * Merged across every composed pack, so a host does not hand-merge each\n * pack's `describe`/`omitProperties` into one options object itself. The\n * runtime-level `authoring` option is merged in last and wins on conflict.\n */\n authoring?: PackAuthoringOptions;\n}\n\n/**\n * A pack as the runtime sees it.\n *\n * `TTheme` is the palette this pack's `react` renderers read as `env.theme`\n * when drawn through the `snapshot` surface — a *lower bound* on whatever theme\n * the runtime holding it supplies. It is carried by\n * {@link PrimitivePack.__theme} rather than by any real field, because\n * `primitives` is erased to `AnyPrimitiveDefinition[]` and a heterogeneous\n * inventory has no single node type to be generic over.\n *\n * The bound is declared, not derived: nothing checks it against what the\n * renderers actually read. State it at the definition as\n * `definePrimitivePack<T>(input)`.\n * Bare `PrimitivePack` requires nothing and fits any runtime; a slot that must\n * hold packs of every palette is typed {@link AnyPrimitivePack}.\n */\nexport interface PrimitivePack<TTheme = unknown> {\n /** Unique among the packs a runtime composes, and used in error messages. */\n readonly id: string;\n /** See {@link PrimitivePackInput.surfaces}. */\n readonly surfaces: readonly OptionalSurface[];\n /** See {@link PrimitivePackInput.primitives}. */\n readonly primitives: readonly AnyPrimitiveDefinition[];\n /** Node types this pack owns, for duplicate detection across packs. */\n readonly types: ReadonlySet<string>;\n /**\n * Each primitive's `icon` by type, for the primitives that declare one, so a host listing them need not walk `primitives`.\n *\n * A frozen null-prototype dictionary: an absent type reads `undefined`, even `constructor`. Absent on a pack built by an SDK that predates icons; {@link iconsByType} derives it from `primitives`.\n */\n readonly icons?: Readonly<Record<string, PrimitiveIcon>>;\n /** See {@link PrimitivePackInput.enhancements}. */\n readonly enhancements: readonly EnhancementDefinition[];\n /** See {@link PrimitivePackInput.slackAssetTypes}. */\n readonly slackAssetTypes: ReadonlySet<string>;\n /** See {@link PrimitivePackInput.styleAdapter}. */\n readonly styleAdapter?: PackStyleAdapter;\n /** See {@link PrimitivePackInput.styleCollector}. */\n readonly styleCollector?: string;\n /** See {@link PrimitivePackInput.authoring}. */\n readonly authoring?: PackAuthoringOptions;\n /**\n * Phantom: never present at runtime, never read.\n *\n * A property rather than a method so `strictFunctionTypes` checks it\n * contravariantly. A method signature is bivariant, which would let a pack\n * needing richer tokens sit in a slot supplying fewer and then read a field\n * nothing supplies — the exact failure this marker exists to prevent.\n */\n readonly __theme?: (theme: TTheme) => void;\n}\n\n/**\n * A pack of any palette, for storage positions: `never` is assignable to every\n * requirement, so a slot typed this way holds every pack.\n */\nexport type AnyPrimitivePack = PrimitivePack<never>;\n\n/**\n * Builds a {@link PrimitivePack}.\n *\n * `TTheme` is the palette a frame must supply for this pack's nodes to be drawn\n * on the `snapshot` surface: `definePrimitivePack<CoreTokens>(input)`. Omitted, it is\n * `unknown`, which requires nothing.\n */\nexport const definePrimitivePack = <TTheme = unknown>(\n input: PrimitivePackInput\n): PrimitivePack<TTheme> => {\n if (input.primitives.length === 0) {\n throw new IsomerError(\n 'EMPTY_PACK',\n `primitive pack \"${input.id}\": at least one primitive is required`\n );\n }\n assertUniquePrimitiveTypes(input.id, input.primitives);\n assertUniqueEnhancementIds(input.id, input.enhancements ?? []);\n const types = new Set(input.primitives.map((definition) => definition.type));\n assertValidGroups(input.id, input.authoring?.groups ?? [], types);\n for (const type of input.slackAssetTypes ?? []) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${input.id}\": slackAssetTypes names primitive type \"${type}\", which the pack does not register`\n );\n }\n }\n const styleCollector =\n input.styleCollector ?? input.styleAdapter?.styleCollector;\n\n return {\n id: input.id,\n surfaces: input.surfaces ?? [],\n primitives: input.primitives,\n types,\n icons: iconsByType(input.primitives),\n enhancements: input.enhancements ?? [],\n slackAssetTypes: new Set(input.slackAssetTypes ?? []),\n ...(input.styleAdapter !== undefined\n ? { styleAdapter: input.styleAdapter }\n : {}),\n ...(styleCollector !== undefined ? { styleCollector } : {}),\n ...(input.authoring !== undefined ? { authoring: input.authoring } : {}),\n };\n};\n\n/** Each definition's `icon` by type, null-prototype so a type such as `__proto__` is an ordinary key. */\nexport const iconsByType = (\n primitives: readonly AnyPrimitiveDefinition[]\n): Readonly<Record<string, PrimitiveIcon>> => {\n const icons = Object.create(null) as Record<string, PrimitiveIcon>;\n for (const { type, icon } of primitives) {\n if (icon !== undefined) {\n icons[type] = icon;\n }\n }\n return Object.freeze(icons);\n};\n\n/** Throws if `primitives` repeats a type. */\nconst assertUniquePrimitiveTypes = (\n id: string,\n primitives: readonly AnyPrimitiveDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const { type } of primitives) {\n if (seen.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" registered twice`\n );\n }\n seen.add(type);\n }\n};\n\n/** Throws if a group repeats or reserves a title, names a type outside `types`, or shares a type with another. */\nconst assertValidGroups = (\n id: string,\n groups: readonly PrimitiveGroup[],\n types: ReadonlySet<string>\n): void => {\n const titles = new Set<string>();\n const grouped = new Set<string>();\n for (const { title, types: members } of groups) {\n if (title === UNCATEGORIZED_GROUP_TITLE) {\n throw new IsomerError(\n 'INVALID_PACK_GROUPS',\n `primitive pack \"${id}\": group title \"${title}\" is reserved for primitives in no group`\n );\n }\n if (titles.has(title)) {\n throw new IsomerError(\n 'INVALID_PACK_GROUPS',\n `primitive pack \"${id}\": group title \"${title}\" is used twice`\n );\n }\n titles.add(title);\n for (const type of members) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": group \"${title}\" names primitive type \"${type}\", which the pack does not register`\n );\n }\n if (grouped.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" is in two groups`\n );\n }\n grouped.add(type);\n }\n }\n};\n\n/** Throws if this pack registers the same enhancement id twice. */\nconst assertUniqueEnhancementIds = (\n id: string,\n enhancements: readonly EnhancementDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const definition of enhancements) {\n if (seen.has(definition.id)) {\n throw new IsomerError(\n 'DUPLICATE_ENHANCEMENT',\n `primitive pack \"${id}\": enhancement \"${definition.id}\" registered twice`\n );\n }\n seen.add(definition.id);\n }\n};\n"]}
|
package/dist/render/anchors.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare const withNodeAnchors: <TContext>(context: TContext) => TContext;
|
|
|
32
32
|
/**
|
|
33
33
|
* Props a `react` renderer spreads on its root element so runtime code can find
|
|
34
34
|
* the node with {@link findNodeElementPairs}. Inside an HTML surface render the
|
|
35
|
-
* surface decides; elsewhere, on the React and `
|
|
35
|
+
* surface decides; elsewhere, on the React and `snapshot` surfaces, `context.anchors`
|
|
36
36
|
* does. Always empty under {@link withoutAnchors}.
|
|
37
37
|
*/
|
|
38
38
|
export declare const nodeAnchor: (context: unknown, { type }: {
|
|
@@ -51,7 +51,7 @@ export declare const layoutRoom: (context: unknown) => Readonly<Record<string, s
|
|
|
51
51
|
* path in validation's `body[0].items[1]` form. Nested nodes follow `react`,
|
|
52
52
|
* as a container renders them through `renderReact` on either surface.
|
|
53
53
|
*/
|
|
54
|
-
export declare const anchoredNodePaths: (body: readonly unknown[], walk: ChildNodeWalker, surface?: "react" | "
|
|
54
|
+
export declare const anchoredNodePaths: (body: readonly unknown[], walk: ChildNodeWalker, surface?: "react" | "snapshot") => {
|
|
55
55
|
node: unknown;
|
|
56
56
|
path: string;
|
|
57
57
|
}[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anchors.d.ts","sourceRoot":"","sources":["../../src/render/anchors.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,+BAA+B,CAAC;AAIvC,2GAA2G;AAC3G,eAAO,MAAM,qBAAqB,qBAAqB,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,MACmC,CAAC;AAgB/E;;;;GAIG;AACH,eAAO,MAA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AG,SAAS,CAAA;CAAE,EAYjD,CAAC"}
|
package/dist/render/anchors.js
CHANGED
|
@@ -70,7 +70,7 @@ const anchorsOn = (context) => {
|
|
|
70
70
|
/**
|
|
71
71
|
* Props a `react` renderer spreads on its root element so runtime code can find
|
|
72
72
|
* the node with {@link findNodeElementPairs}. Inside an HTML surface render the
|
|
73
|
-
* surface decides; elsewhere, on the React and `
|
|
73
|
+
* surface decides; elsewhere, on the React and `snapshot` surfaces, `context.anchors`
|
|
74
74
|
* does. Always empty under {@link withoutAnchors}.
|
|
75
75
|
*/
|
|
76
76
|
export const nodeAnchor = (context, { type }) => anchorsOn(context) ? { [NODE_ANCHOR_ATTRIBUTE]: anchorValue(type) } : {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anchors.js","sourceRoot":"","sources":["../../src/render/anchors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,aAAa,EAEb,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3D,2GAA2G;AAC3G,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAExD;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE,CAClD,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;AAE/E,oFAAoF;AACpF,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAI3D,MAAM,aAAa,GAAG,GAAwB,EAAE,CAC7C,UAA0B,CAAC,MAAM,CAAC,C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.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport {\n childNodePath,\n type ChildNodeWalker,\n isVisibleOnSurface,\n} from '../composition/body_node_base';\n\nimport { contextWith, isObjectLike } from './context_view';\n\n/** The attribute {@link nodeAnchor} sets to a node's type, escaped so HTML parsing leaves it unchanged. */\nexport const NODE_ANCHOR_ATTRIBUTE = 'data-isomer-node';\n\n/**\n * A node type as its anchor carries it. Every character outside `[A-Za-z0-9_-]`\n * becomes `%<hex code point>;`, so the value survives HTML serialization and\n * parsing unchanged and never throws. A plain identifier stays as it is.\n */\nexport const anchorValue = (type: string): string =>\n type.replace(/[^\\w-]/gu, (char) => `%${char.codePointAt(0)!.toString(16)};`);\n\n/** Marks a context whose subtree renders no anchors; see {@link withoutAnchors}. */\nconst NO_ANCHORS = Symbol.for('elastic.isomer.anchors_off');\n\n/**\n * Where an HTML render keeps its anchor decision while it runs. On `globalThis`\n * under a `Symbol.for` key, so an ESM and a CommonJS copy of the SDK share it.\n */\nconst ACTIVE = Symbol.for('elastic.isomer.anchors_active');\n\ntype AnchorScope = { [ACTIVE]?: boolean };\n\nconst activeAnchors = (): boolean | undefined =>\n (globalThis as AnchorScope)[ACTIVE];\n\n/**\n * Runs `render` with anchors on or off for every {@link nodeAnchor} it reaches,\n * whatever each render context says. The render must be synchronous; the\n * previous state comes back afterwards, even if it throws.\n */\nexport const withAnchors = <TResult>(\n on: boolean,\n render: () => TResult\n): TResult => {\n const scope = globalThis as AnchorScope;\n const outer = scope[ACTIVE];\n scope[ACTIVE] = on;\n try {\n return render();\n } finally {\n if (outer === undefined) {\n delete scope[ACTIVE];\n } else {\n scope[ACTIVE] = outer;\n }\n }\n};\n\n/**\n * `context` for content a renderer draws that is not one of its `children`,\n * such as an embedded composition: nothing under it renders an anchor.\n *\n * The result is a view of `context`, not a copy: reads go to `context` itself,\n * with methods bound to it, so getters, methods, private state, and\n * `instanceof` behave as before. The mark survives a context derived from it\n * by spreading. A context that is neither an object nor a function is\n * returned as it is.\n */\nexport const withoutAnchors = <TContext>(context: TContext): TContext =>\n contextWith(context, NO_ANCHORS, true);\n\n/**\n * `context` with node anchors on, as an enhancement declaring `anchors: true`\n * turns them on. A view like {@link withoutAnchors}, which still wins.\n */\nexport const withNodeAnchors = <TContext>(context: TContext): TContext =>\n contextWith(context, 'anchors', true);\n\nconst anchorsOn = (context: unknown): boolean => {\n const carries = isObjectLike(context);\n if (carries && Reflect.get(context, NO_ANCHORS) === true) {\n return false;\n }\n return (\n activeAnchors() ??\n (carries && (context as { anchors?: unknown }).anchors === true)\n );\n};\n\n/**\n * Props a `react` renderer spreads on its root element so runtime code can find\n * the node with {@link findNodeElementPairs}. Inside an HTML surface render the\n * surface decides; elsewhere, on the React and `svg` surfaces, `context.anchors`\n * does. Always empty under {@link withoutAnchors}.\n */\nexport const nodeAnchor = (\n context: unknown,\n { type }: { type: string }\n): Readonly<Record<string, string>> =>\n anchorsOn(context) ? { [NODE_ANCHOR_ATTRIBUTE]: anchorValue(type) } : {};\n\n/** The attribute {@link layoutRoom} sets. */\nexport const LAYOUT_ROOM_ATTRIBUTE = 'data-isomer-room';\n\n/**\n * Props a renderer spreads on an element inside its node that bounds the nodes\n * nested in it, such as a frame's body, so `checkLayout` measures them against\n * it. Rendered when {@link nodeAnchor} would be.\n */\nexport const layoutRoom = (\n context: unknown\n): Readonly<Record<string, string>> =>\n anchorsOn(context) ? { [LAYOUT_ROOM_ATTRIBUTE]: '' } : {};\n\n/**\n * The nodes of `body` a render on `surface` draws, pre-order, each with its\n * path in validation's `body[0].items[1]` form. Nested nodes follow `react`,\n * as a container renders them through `renderReact` on either surface.\n */\nexport const anchoredNodePaths = (\n body: readonly unknown[],\n walk: ChildNodeWalker,\n surface: 'react' | 'svg' = 'react'\n): { node: unknown; path: string }[] => {\n const visit = (\n node: unknown,\n path: string\n ): { node: unknown; path: string }[] => [\n { node, path },\n ...walk(node).flatMap((child) =>\n isVisibleOnSurface(child.node, 'react')\n ? visit(child.node, childNodePath(path, child.path))\n : []\n ),\n ];\n return body.flatMap((node, index) =>\n isVisibleOnSurface(node, surface) ? visit(node, `body[${index}]`) : []\n );\n};\n\n/** The `react`-visible nodes of `body`, pre-order: the order their anchors render in. */\nexport const anchoredNodes = (\n body: readonly unknown[],\n walk: ChildNodeWalker\n): unknown[] => anchoredNodePaths(body, walk).map(({ node }) => node);\n\n/** A node's `type`, when it has one. */\nexport const nodeType = (node: unknown): string | undefined => {\n const { type } = node as { type?: unknown };\n return typeof type === 'string' ? type : undefined;\n};\n\n/**\n * The item each of `nodes` pairs with, from `anchored` in document order: the\n * k-th node of a type pairs with the k-th item whose anchor value is that\n * type's. A type whose node and item counts disagree pairs with nothing.\n */\nexport const pairAnchors = <TItem>(\n anchored: Iterable<readonly [value: string, item: TItem]>,\n nodes: readonly unknown[]\n): (TItem | undefined)[] => {\n const itemsByValue = new Map<string, TItem[]>();\n for (const [value, item] of anchored) {\n const items = itemsByValue.get(value) ?? [];\n items.push(item);\n itemsByValue.set(value, items);\n }\n const counts = new Map<string, number>();\n for (const node of nodes) {\n const type = nodeType(node);\n if (type !== undefined) {\n counts.set(type, (counts.get(type) ?? 0) + 1);\n }\n }\n const seen = new Map<string, number>();\n return nodes.map((node) => {\n const type = nodeType(node);\n if (type === undefined) {\n return undefined;\n }\n const index = seen.get(type) ?? 0;\n seen.set(type, index + 1);\n const items = itemsByValue.get(anchorValue(type)) ?? [];\n return items.length === counts.get(type) ? items[index] : undefined;\n });\n};\n\n/**\n * Every `react`-visible node of `body`, walked pre-order, with the element\n * its anchor marks under `root`, paired by {@link pairAnchors}. `root` holds\n * one render.\n *\n * Pairing holds because every renderer draws its `children` in the order its\n * definition's `children` returns them. A node that rendered nothing leaves\n * its type unpaired. A node object that appears twice appears twice here,\n * each time with its own element.\n */\nexport const findNodeElementPairs = (\n root: ParentNode,\n body: readonly unknown[],\n walk: ChildNodeWalker\n): { node: unknown; element: Element | undefined }[] => {\n const nodes = anchoredNodes(body, walk);\n // Read by attribute value, so a type is never read as selector syntax.\n const elements = pairAnchors(\n Array.from(\n root.querySelectorAll(`[${NODE_ANCHOR_ATTRIBUTE}]`),\n (element) =>\n [element.getAttribute(NODE_ANCHOR_ATTRIBUTE) ?? '', element] as const\n ),\n nodes\n );\n return nodes.map((node, index) => ({ node, element: elements[index] }));\n};\n"]}
|
|
1
|
+
{"version":3,"file":"anchors.js","sourceRoot":"","sources":["../../src/render/anchors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,aAAa,EAEb,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3D,2GAA2G;AAC3G,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAExD;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE,CAClD,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;AAE/E,oFAAoF;AACpF,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAI3D,MAAM,aAAa,GAAG,GAAwB,EAAE,CAC7C,UAA0B,CAAC,MAAM,CAAC,CAAC;AAEtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,EAAW,EACX,MAAqB,EACZ,EAAE;IACX,MAAM,KAAK,GAAG,UAAyB,CAAC;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,KAAK,CAAC,MAAM,CAAC,GAAG,E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AAG,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QAC1B,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;QACxD,OAAO,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,IAAgB,EAChB,IAAwB,EACxB,IAAqB,EAC8B,EAAE;IACrD,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACxC,uEAAuE;IACvE,MAAM,QAAQ,GAAG,WAAW,CAC1B,KAAK,CAAC,IAAI,CACR,IAAI,CAAC,gBAAgB,CAAC,IAAI,qBAAqB,GAAG,CAAC,EACnD,CAAC,OAAO,EAAE,EAAE,CACV,CAAC,OAAO,CAAC,YAAY,CAAC,qBAAqB,CAAC,IAAI,EAAE,EAAE,OAAO,CAAU,CACxE,EACD,KAAK,CACN,CAAC;IACF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1E,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport {\n childNodePath,\n type ChildNodeWalker,\n isVisibleOnSurface,\n} from '../composition/body_node_base';\n\nimport { contextWith, isObjectLike } from './context_view';\n\n/** The attribute {@link nodeAnchor} sets to a node's type, escaped so HTML parsing leaves it unchanged. */\nexport const NODE_ANCHOR_ATTRIBUTE = 'data-isomer-node';\n\n/**\n * A node type as its anchor carries it. Every character outside `[A-Za-z0-9_-]`\n * becomes `%<hex code point>;`, so the value survives HTML serialization and\n * parsing unchanged and never throws. A plain identifier stays as it is.\n */\nexport const anchorValue = (type: string): string =>\n type.replace(/[^\\w-]/gu, (char) => `%${char.codePointAt(0)!.toString(16)};`);\n\n/** Marks a context whose subtree renders no anchors; see {@link withoutAnchors}. */\nconst NO_ANCHORS = Symbol.for('elastic.isomer.anchors_off');\n\n/**\n * Where an HTML render keeps its anchor decision while it runs. On `globalThis`\n * under a `Symbol.for` key, so an ESM and a CommonJS copy of the SDK share it.\n */\nconst ACTIVE = Symbol.for('elastic.isomer.anchors_active');\n\ntype AnchorScope = { [ACTIVE]?: boolean };\n\nconst activeAnchors = (): boolean | undefined =>\n (globalThis as AnchorScope)[ACTIVE];\n\n/**\n * Runs `render` with anchors on or off for every {@link nodeAnchor} it reaches,\n * whatever each render context says. The render must be synchronous; the\n * previous state comes back afterwards, even if it throws.\n */\nexport const withAnchors = <TResult>(\n on: boolean,\n render: () => TResult\n): TResult => {\n const scope = globalThis as AnchorScope;\n const outer = scope[ACTIVE];\n scope[ACTIVE] = on;\n try {\n return render();\n } finally {\n if (outer === undefined) {\n delete scope[ACTIVE];\n } else {\n scope[ACTIVE] = outer;\n }\n }\n};\n\n/**\n * `context` for content a renderer draws that is not one of its `children`,\n * such as an embedded composition: nothing under it renders an anchor.\n *\n * The result is a view of `context`, not a copy: reads go to `context` itself,\n * with methods bound to it, so getters, methods, private state, and\n * `instanceof` behave as before. The mark survives a context derived from it\n * by spreading. A context that is neither an object nor a function is\n * returned as it is.\n */\nexport const withoutAnchors = <TContext>(context: TContext): TContext =>\n contextWith(context, NO_ANCHORS, true);\n\n/**\n * `context` with node anchors on, as an enhancement declaring `anchors: true`\n * turns them on. A view like {@link withoutAnchors}, which still wins.\n */\nexport const withNodeAnchors = <TContext>(context: TContext): TContext =>\n contextWith(context, 'anchors', true);\n\nconst anchorsOn = (context: unknown): boolean => {\n const carries = isObjectLike(context);\n if (carries && Reflect.get(context, NO_ANCHORS) === true) {\n return false;\n }\n return (\n activeAnchors() ??\n (carries && (context as { anchors?: unknown }).anchors === true)\n );\n};\n\n/**\n * Props a `react` renderer spreads on its root element so runtime code can find\n * the node with {@link findNodeElementPairs}. Inside an HTML surface render the\n * surface decides; elsewhere, on the React and `snapshot` surfaces, `context.anchors`\n * does. Always empty under {@link withoutAnchors}.\n */\nexport const nodeAnchor = (\n context: unknown,\n { type }: { type: string }\n): Readonly<Record<string, string>> =>\n anchorsOn(context) ? { [NODE_ANCHOR_ATTRIBUTE]: anchorValue(type) } : {};\n\n/** The attribute {@link layoutRoom} sets. */\nexport const LAYOUT_ROOM_ATTRIBUTE = 'data-isomer-room';\n\n/**\n * Props a renderer spreads on an element inside its node that bounds the nodes\n * nested in it, such as a frame's body, so `checkLayout` measures them against\n * it. Rendered when {@link nodeAnchor} would be.\n */\nexport const layoutRoom = (\n context: unknown\n): Readonly<Record<string, string>> =>\n anchorsOn(context) ? { [LAYOUT_ROOM_ATTRIBUTE]: '' } : {};\n\n/**\n * The nodes of `body` a render on `surface` draws, pre-order, each with its\n * path in validation's `body[0].items[1]` form. Nested nodes follow `react`,\n * as a container renders them through `renderReact` on either surface.\n */\nexport const anchoredNodePaths = (\n body: readonly unknown[],\n walk: ChildNodeWalker,\n surface: 'react' | 'snapshot' = 'react'\n): { node: unknown; path: string }[] => {\n const visit = (\n node: unknown,\n path: string\n ): { node: unknown; path: string }[] => [\n { node, path },\n ...walk(node).flatMap((child) =>\n isVisibleOnSurface(child.node, 'react')\n ? visit(child.node, childNodePath(path, child.path))\n : []\n ),\n ];\n return body.flatMap((node, index) =>\n isVisibleOnSurface(node, surface) ? visit(node, `body[${index}]`) : []\n );\n};\n\n/** The `react`-visible nodes of `body`, pre-order: the order their anchors render in. */\nexport const anchoredNodes = (\n body: readonly unknown[],\n walk: ChildNodeWalker\n): unknown[] => anchoredNodePaths(body, walk).map(({ node }) => node);\n\n/** A node's `type`, when it has one. */\nexport const nodeType = (node: unknown): string | undefined => {\n const { type } = node as { type?: unknown };\n return typeof type === 'string' ? type : undefined;\n};\n\n/**\n * The item each of `nodes` pairs with, from `anchored` in document order: the\n * k-th node of a type pairs with the k-th item whose anchor value is that\n * type's. A type whose node and item counts disagree pairs with nothing.\n */\nexport const pairAnchors = <TItem>(\n anchored: Iterable<readonly [value: string, item: TItem]>,\n nodes: readonly unknown[]\n): (TItem | undefined)[] => {\n const itemsByValue = new Map<string, TItem[]>();\n for (const [value, item] of anchored) {\n const items = itemsByValue.get(value) ?? [];\n items.push(item);\n itemsByValue.set(value, items);\n }\n const counts = new Map<string, number>();\n for (const node of nodes) {\n const type = nodeType(node);\n if (type !== undefined) {\n counts.set(type, (counts.get(type) ?? 0) + 1);\n }\n }\n const seen = new Map<string, number>();\n return nodes.map((node) => {\n const type = nodeType(node);\n if (type === undefined) {\n return undefined;\n }\n const index = seen.get(type) ?? 0;\n seen.set(type, index + 1);\n const items = itemsByValue.get(anchorValue(type)) ?? [];\n return items.length === counts.get(type) ? items[index] : undefined;\n });\n};\n\n/**\n * Every `react`-visible node of `body`, walked pre-order, with the element\n * its anchor marks under `root`, paired by {@link pairAnchors}. `root` holds\n * one render.\n *\n * Pairing holds because every renderer draws its `children` in the order its\n * definition's `children` returns them. A node that rendered nothing leaves\n * its type unpaired. A node object that appears twice appears twice here,\n * each time with its own element.\n */\nexport const findNodeElementPairs = (\n root: ParentNode,\n body: readonly unknown[],\n walk: ChildNodeWalker\n): { node: unknown; element: Element | undefined }[] => {\n const nodes = anchoredNodes(body, walk);\n // Read by attribute value, so a type is never read as selector syntax.\n const elements = pairAnchors(\n Array.from(\n root.querySelectorAll(`[${NODE_ANCHOR_ATTRIBUTE}]`),\n (element) =>\n [element.getAttribute(NODE_ANCHOR_ATTRIBUTE) ?? '', element] as const\n ),\n nodes\n );\n return nodes.map((node, index) => ({ node, element: elements[index] }));\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format_number.d.ts","sourceRoot":"","sources":["../../src/render/format_number.ts"],"names":[],"mappings":"AAyBA;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,MAAM,EACb,aAAS,EACT,kBAAa,KACZ,
|
|
1
|
+
{"version":3,"file":"format_number.d.ts","sourceRoot":"","sources":["../../src/render/format_number.ts"],"names":[],"mappings":"AAyBA;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,MAAM,EACb,aAAS,EACT,kBAAa,KACZ,MAiBF,CAAC"}
|
|
@@ -28,8 +28,9 @@ const trimDecimal = (value, precision) => Number.isInteger(value)
|
|
|
28
28
|
export const formatCompactNumber = (value, unit = '', precision = 1) => {
|
|
29
29
|
const abs = Math.abs(value);
|
|
30
30
|
let index = TIERS.findIndex(({ size }) => abs >= size);
|
|
31
|
-
if (index === -1)
|
|
31
|
+
if (index === -1) {
|
|
32
32
|
index = TIERS.length - 1;
|
|
33
|
+
}
|
|
33
34
|
// A value that rounds up to the tier's next power, `999.96k`, reads as `1m`.
|
|
34
35
|
if (index > 0 &&
|
|
35
36
|
Math.abs(Number((value / TIERS[index].size).toFixed(precision))) >= 1_000) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format_number.js","sourceRoot":"","sources":["../../src/render/format_number.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,6EAA6E;AAC7E,2BAA2B;AAE3B,MAAM,KAAK,GAAG;IACZ,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,EAAE;IACxC,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE;IACpC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE;IAChC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAA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CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// Compact numeric formatting, shared by anything that has to fit a number into\n// a small space — chart axis labels, a `compact` structured display value, a\n// text-surface trend line.\n\nconst TIERS = [\n { size: 1_000_000_000_000, suffix: 't' },\n { size: 1_000_000_000, suffix: 'b' },\n { size: 1_000_000, suffix: 'm' },\n { size: 1_000, suffix: 'k' },\n { size: 1, suffix: '' },\n] as const;\n\n// Rounded to `precision` decimals, trailing zeros dropped.\nconst trimDecimal = (value: number, precision: number): string =>\n Number.isInteger(value)\n ? String(value)\n : String(Number(value.toFixed(precision)));\n\n/**\n * `1_284` to `1.3k`, `18_200_000` to `18.2m`, through `b` and `t`, with an\n * optional unit appended. `precision` is the decimals kept, `1` by default.\n *\n * `%` joins without a space because \"99.2 %\" reads wrong; every other unit gets\n * one.\n */\nexport const formatCompactNumber = (\n value: number,\n unit = '',\n precision = 1\n): string => {\n const abs = Math.abs(value);\n let index = TIERS.findIndex(({ size }) => abs >= size);\n if (index === -1) {\n index = TIERS.length - 1;\n }\n // A value that rounds up to the tier's next power, `999.96k`, reads as `1m`.\n if (\n index > 0 &&\n Math.abs(Number((value / TIERS[index]!.size).toFixed(precision))) >= 1_000\n ) {\n index -= 1;\n }\n const { size, suffix } = TIERS[index]!;\n const scaled = `${trimDecimal(value / size, precision)}${suffix}`;\n\n return unit === '' ? scaled : `${scaled}${unit === '%' ? '' : ' '}${unit}`;\n};\n"]}
|
|
@@ -43,7 +43,7 @@ export interface HTMLRenderOptions {
|
|
|
43
43
|
anchors?: boolean;
|
|
44
44
|
/**
|
|
45
45
|
* Resolves `light-dark(…)` in the stylesheet to one scheme's value. A browser
|
|
46
|
-
* resolves it itself; an image is one static frame, so the `
|
|
46
|
+
* resolves it itself; an image is one static frame, so the `snapshot` surface sets
|
|
47
47
|
* it.
|
|
48
48
|
*/
|
|
49
49
|
scheme?: 'light' | 'dark';
|
|
@@ -113,8 +113,8 @@ export interface HTMLStyleAdapter<TNode extends PrimitiveNode = PrimitiveNode, T
|
|
|
113
113
|
resolveOptions?(composition: Composition<TNode>, options: HTMLRenderOptions): HTMLRenderOptions;
|
|
114
114
|
/**
|
|
115
115
|
* The `.isomer` / `.isomer.framed` / `.isomer.fluid` rules around a rendered composition.
|
|
116
|
-
* Named for the wrapper rather than the frame, which the sdk reserves for
|
|
117
|
-
*
|
|
116
|
+
* Named for the wrapper rather than the frame, which the sdk reserves for the
|
|
117
|
+
* document a snapshot is drawn inside.
|
|
118
118
|
*/
|
|
119
119
|
collectWrapperStyles?(collector: TCollector, options: HTMLRenderOptions): void;
|
|
120
120
|
/** Walks the body into the collector, usually through {@link HTMLRenderDispatcher.collectStyles}. Runs before any markup exists. */
|
|
@@ -108,8 +108,9 @@ export const renderHTMLWithDispatcher = (input, { dispatcher, validate = createC
|
|
|
108
108
|
const embedCss = (css) => css.replace(/<\/(?=style)/gi, '<\\/');
|
|
109
109
|
// Tagged templates observe raw spelling and reuse the same frozen object per site.
|
|
110
110
|
const embedJs = (js) => {
|
|
111
|
-
if (!/<\/script|<!--/i.test(js))
|
|
111
|
+
if (!/<\/script|<!--/i.test(js)) {
|
|
112
112
|
return js;
|
|
113
|
+
}
|
|
113
114
|
const comments = [];
|
|
114
115
|
const tree = parse(js, { ecmaVersion: 'latest', onComment: comments });
|
|
115
116
|
const sites = [];
|
|
@@ -117,11 +118,13 @@ const embedJs = (js) => {
|
|
|
117
118
|
const pending = [tree];
|
|
118
119
|
while (pending.length) {
|
|
119
120
|
const node = pending.pop();
|
|
120
|
-
if (node.type === 'Identifier' && node.name)
|
|
121
|
+
if (node.type === 'Identifier' && node.name) {
|
|
121
122
|
identifiers.add(node.name);
|
|
123
|
+
}
|
|
122
124
|
if (node.type === 'TaggedTemplateExpression' &&
|
|
123
|
-
node.quasi.quasis.some(({ value: { raw } }) => /<\/script|<!--/i.test(raw)))
|
|
125
|
+
node.quasi.quasis.some(({ value: { raw } }) => /<\/script|<!--/i.test(raw))) {
|
|
124
126
|
sites.push(node);
|
|
127
|
+
}
|
|
125
128
|
for (const value of Object.values(node)) {
|
|
126
129
|
for (const child of Array.isArray(value) ? value : [value]) {
|
|
127
130
|
if (child &&
|
|
@@ -135,8 +138,9 @@ const embedJs = (js) => {
|
|
|
135
138
|
}
|
|
136
139
|
sites.sort((a, b) => a.start - b.start);
|
|
137
140
|
let prefix = '__isomerTemplate';
|
|
138
|
-
while ([...identifiers].some((name) => name.startsWith(prefix)))
|
|
141
|
+
while ([...identifiers].some((name) => name.startsWith(prefix))) {
|
|
139
142
|
prefix += '_';
|
|
143
|
+
}
|
|
140
144
|
const literal = (value) => value === null ? 'void 0' : JSON.stringify(value).replace(/</g, '\\u003c');
|
|
141
145
|
const rewrite = (start, end) => {
|
|
142
146
|
let cursor = start;
|
|
@@ -152,8 +156,9 @@ const embedJs = (js) => {
|
|
|
152
156
|
.map((comment) => ({ ...comment, index: -1, comment: comment.value })),
|
|
153
157
|
].sort((a, b) => a.start - b.start);
|
|
154
158
|
for (const edit of edits) {
|
|
155
|
-
if (edit.start < cursor || edit.end > end)
|
|
159
|
+
if (edit.start < cursor || edit.end > end) {
|
|
156
160
|
continue;
|
|
161
|
+
}
|
|
157
162
|
result += js.slice(cursor, edit.start);
|
|
158
163
|
if (edit.comment !== undefined) {
|
|
159
164
|
result += `//${edit.comment}`;
|
|
@@ -184,8 +189,9 @@ const embedJs = (js) => {
|
|
|
184
189
|
};
|
|
185
190
|
const escapedBy = (source, at) => {
|
|
186
191
|
let slashes = 0;
|
|
187
|
-
while (source[at - slashes - 1] === '\\')
|
|
192
|
+
while (source[at - slashes - 1] === '\\') {
|
|
188
193
|
slashes += 1;
|
|
194
|
+
}
|
|
189
195
|
return slashes % 2 === 1;
|
|
190
196
|
};
|
|
191
197
|
const RenderedHtmlView = ({ composition, theme, fluid, framed, styleText, scriptText, defaultAriaLabel, body, }) => wrapCompositionContent(createElement(Fragment, null, styleText
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../../src/render/html/envelope.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAGL,KAAK,GACN,MAAM,OAAO,CAAC;AAEf,OAAO,EAEL,qBAAqB,GACtB,MAAM,kCAAkC,CAAC;AAY1C,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,WAAW,GACZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,mBAAmB,EACnB,0BAA0B,EAC1B,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AACjE,OAAO,EAEL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,WAAW,EAEX,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAqNxB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAKtC,KAAyB,EACzB,EACE,UAAU,EACV,QAAQ,GAAG,0BAA0B,CAAQ,UAAU,CAAC,WAAW,CAAC,EACpE,OAAO,EAAE,UAAU,GAAG,EAAE,EACxB,gBAAgB,GAAG,MAAM,EACzB,YAAY,EACZ,UAAU,GAAG,EAAE,EACf,sBAAsB,GAAG,EAAE,GAC8B,EACzC,EAAE;IACpB,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,WAAW,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IACpD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,EAAE;IACnB,GAAG,EAAE,MAAM;IACX,uBAAuB,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;CAC1C,CAAC,EACF,UAAU;IACR,CAAC,CAAC,aAAa,CAAC,QAAQ,EAAE;QACtB,GAAG,EAAE,QAAQ;QACb,CAAC,yBAAyB,CAAC,EAAE,EAAE;QAC/B,uBAAuB,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE;KAChD,CAAC;IACJ,CAAC,CAAC,IAAI,CACT,EACD,WAAW,EACX,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAC3C,CAAC;AAEJ,4EAA4E;AAC5E,yEAAyE;AACzE,6EAA6E;AAC7E,6CAA6C;AAC7C,MAAM,SAAS,GACb,2EAA2E,CAAC;AAE9E,MAAM,UAAU,GAAG,CAAC,KAAa,EAAU,EAAE,CAC3C,KAAK;KACF,OAAO,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,OAA2B,EAAE,EAAE,CACzD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAC9C;KACA,IAAI,EAAE,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport { createElement, Fragment, type ReactNode } from 'react';\nimport { renderToStaticMarkup } from 'react-dom/server';\nimport {\n type Comment as JavaScriptComment,\n type Node as JavaScriptNode,\n parse,\n} from 'acorn';\n\nimport {\n type ChildNodeWalker,\n createChildNodeWalker,\n} from '../../composition/body_node_base';\nimport type { Composition } from '../../composition/composition';\nimport type { RenderTheme } from '../../composition/named_color';\nimport type { ValidationError } from '../../composition/validation_error';\nimport type {\n AnyPrimitiveDefinition,\n PrimitiveNode,\n PrimitiveStyleCollectionContext,\n PrimitiveStyleCollector,\n StyledRenderContext,\n StyleHandle,\n} from '../../define/primitive_module';\nimport {\n EMBEDDED_SCRIPT_ATTRIBUTE,\n resolveEnhancements,\n scopeScript,\n} from '../../pack/enhancements';\nimport {\n type CheckedValidationResult,\n compositionToRender,\n createCompositionValidator,\n enforceValidationMode,\n type ValidationErrorMode,\n} from '../../validate/validation';\nimport { withAnchors } from '../anchors';\nimport { contextWith } from '../context_view';\nimport { byteLength, type PayloadMeasurement } from '../payload';\nimport {\n type ReactContentDispatcher,\n renderCompositionContent,\n wrapCompositionContent,\n} from '../react/content';\n\nimport {\n embedScript,\n type EnhancementDefinition,\n enhancementScript,\n} from './enhancements';\n\n/** Knobs for the HTML surface. Every field defaults, so `{}` is valid. */\nexport interface HTMLRenderOptions {\n /** Overrides {@link Composition.theme}; `auto` when neither is set. */\n theme?: RenderTheme;\n /** Drops whitespace between tags that spans a line break, leaving `<pre>`, `<script>`, `<style>`, and `<textarea>` content intact. Defaults to `true`. */\n minify?: boolean;\n /** Adds the `fluid` wrapper class and reaches the pack as {@link PrimitiveStyleCollectionContext.fluid}; the adapter decides what it changes. */\n fluid?: boolean;\n /** Adds the `framed` wrapper class the adapter styles as a frame. Defaults to `true`. */\n framed?: boolean;\n /**\n * Renders the composition's title and subtitle. Defaults to `true`. Set\n * `false` when the embedding host already shows the title itself — the title\n * still backs the wrapper's `aria-label`.\n */\n heading?: boolean;\n /** Whether the collected CSS is inlined as a `<style>` element. Defaults to `'inline'`. */\n css?: 'inline' | 'separate';\n /**\n * Who runs the enhancement script. Defaults to `'embedded'`: `html` carries\n * a `<script>` that finds its own `.isomer` section when the page parses it.\n *\n * `'embedded'` never runs inside a shadow root, or anywhere the host inserts\n * `html` itself (`innerHTML`, a React tree). Use `'host'` there: `html`\n * carries no `<script>`, and the host calls `runEnhancementScript(js,\n * section)` after inserting it.\n */\n scripts?: 'embedded' | 'host';\n /** Defaults to collecting into {@link HTMLRenderResult.validationErrors}; `'throw'` raises instead. Input the budget refused raises in either mode. */\n onValidationError?: ValidationErrorMode;\n /** Opt-in by {@link EnhancementDefinition.id}. One whose content gate does not match the body is dropped. */\n enhancements?: readonly string[];\n /** `true` renders node anchors whether or not an enhancement asks for them, e.g. for tests. `false` cannot turn off anchors an enhancement needs. */\n anchors?: boolean;\n /**\n * Resolves `light-dark(…)` in the stylesheet to one scheme's value. A browser\n * resolves it itself; an image is one static frame, so the `svg` surface sets\n * it.\n */\n scheme?: 'light' | 'dark';\n}\n\n/**\n * One rendered HTML payload.\n *\n * `body` is the primitive markup alone; `html` adds the wrapper element, on\n * the default `css: 'inline'` a `<style>`, and on the default\n * `scripts: 'embedded'` a `<script>`. `css` and `js` are populated either way.\n * `validationErrors` are the messages that survived\n * {@link HTMLRenderOptions.onValidationError}.\n */\nexport interface HTMLRenderResult {\n html: string;\n css: string;\n /**\n * The enhancement script as a function body over `root`, or `''`. Under\n * `scripts: 'embedded'` the `<script>` in `html` wraps the same body; under\n * `'host'` the host runs it with `runEnhancementScript`. It is never a\n * complete script on its own.\n */\n js: string;\n body: string;\n measurement: PayloadMeasurement;\n validationErrors: ValidationError[];\n}\n\n/**\n * A pack's HTML entry point: the React renderer plus the style pass that runs\n * ahead of it.\n */\nexport interface HTMLRenderDispatcher<\n TNode extends PrimitiveNode,\n TCollector extends PrimitiveStyleCollector = PrimitiveStyleCollector,\n TContext = StyledRenderContext,\n> extends ReactContentDispatcher<TNode, TContext> {\n /** The whole composition's inventory: a child walker built from one pack's definitions cannot descend into another pack's container. */\n readonly definitions: readonly AnyPrimitiveDefinition[];\n /** One node's style pass, driven by {@link HTMLStyleAdapter.collectViewStyles} rather than called by the sdk. */\n collectStyles(\n node: TNode,\n collector: TCollector,\n context: PrimitiveStyleCollectionContext\n ): void;\n}\n\n/**\n * The composition's child walker and the enhancements every loaded pack\n * declared. Threaded into the style adapter so content-gating can see a\n * table nested inside a container from another package.\n */\nexport interface HTMLEnhancementScope {\n walk: ChildNodeWalker;\n definitions: readonly EnhancementDefinition[];\n}\n\n/**\n * How a pack turns its nodes into CSS. Optional overall — without an adapter\n * the render still produces markup, just with no class names and an empty\n * `TContext`.\n */\nexport interface HTMLStyleAdapter<\n TNode extends PrimitiveNode = PrimitiveNode,\n TCollector extends PrimitiveStyleCollector = PrimitiveStyleCollector,\n TContext = StyledRenderContext,\n> {\n /**\n * Names the collector shape {@link HTMLStyleAdapter.createCollector} returns, so a runtime can\n * reject a pack whose `collectStyles` hooks were written against a different one.\n */\n styleCollector?: string;\n /** One collector per render, shared by every other hook here and by both render passes. */\n createCollector(options: HTMLRenderOptions): TCollector;\n /**\n * Settles options that depend on the composition, before anything reads them.\n *\n * Needed by an adapter whose look is chosen per render: deciding `framed`\n * from the body has to happen before the wrapper class is written, not while\n * CSS is collected.\n */\n resolveOptions?(\n composition: Composition<TNode>,\n options: HTMLRenderOptions\n ): HTMLRenderOptions;\n /**\n * The `.isomer` / `.isomer.framed` / `.isomer.fluid` rules around a rendered composition.\n * Named for the wrapper rather than the frame, which the sdk reserves for a\n * pack's svg document surround.\n */\n collectWrapperStyles?(\n collector: TCollector,\n options: HTMLRenderOptions\n ): void;\n /** Walks the body into the collector, usually through {@link HTMLRenderDispatcher.collectStyles}. Runs before any markup exists. */\n collectViewStyles?(\n composition: Composition<TNode>,\n dispatcher: HTMLRenderDispatcher<TNode, TCollector, TContext>,\n collector: TCollector,\n context: PrimitiveStyleCollectionContext,\n options: HTMLRenderOptions,\n scope: HTMLEnhancementScope\n ): void;\n /** Runs once the collection pass has rendered the body, for styles only a renderer can discover. That markup is discarded. */\n collectAfterRender?(\n composition: Composition<TNode>,\n collector: TCollector,\n options: HTMLRenderOptions\n ): void;\n /**\n * Builds the render context handed to every `react` renderer. Called once\n * per pass, so an adapter that behaves differently while collecting returns\n * a different context then. Must be complete, because `TContext` is the\n * pack's own type. The sdk never writes to it: whether renderers anchor\n * is the surface's decision, whatever the context's `anchors` says.\n */\n createRenderContext(\n collector: TCollector,\n options: HTMLRenderOptions\n ): TContext;\n /** The collected CSS as text, with no `<style>` wrapper; the sdk adds one when `css` is `'inline'`. */\n renderStyles(collector: TCollector, options: HTMLRenderOptions): string;\n /**\n * Whether `handle` belongs to this adapter's stylesheet.\n *\n * Unused on a lone adapter. A runtime composing several packs' adapters\n * routes each handle to its owner, so CSS is neither duplicated nor\n * rendered against the wrong theme. An adapter that cannot answer this\n * cannot be combined with another.\n */\n ownsHandle?(handle: StyleHandle): boolean;\n /**\n * Appended after {@link HTMLDispatcherRenderOptions.scriptText} into the\n * render's one script. A function body with `root` in scope, under the same\n * rules as {@link EnhancementDefinition.script}.\n */\n getScriptText?(\n composition: Composition<TNode>,\n options: HTMLRenderOptions,\n scope: HTMLEnhancementScope\n ): string;\n}\n\n/** What {@link renderHTMLWithDispatcher} needs beyond the composition. */\nexport interface HTMLDispatcherRenderOptions<\n TNode extends PrimitiveNode,\n TCollector extends PrimitiveStyleCollector = PrimitiveStyleCollector,\n TContext = StyledRenderContext,\n> {\n dispatcher: HTMLRenderDispatcher<TNode, TCollector, TContext>;\n /** Runs once before rendering, which draws the composition it returns; {@link HTMLRenderOptions.onValidationError} decides what becomes of its errors. Defaults to `createCompositionValidator(dispatcher.definitions)`. */\n validate?: (\n composition: Composition<TNode>\n ) => CheckedValidationResult<TNode>;\n options?: HTMLRenderOptions;\n /** Used only when the composition has neither `meta.ariaLabel` nor a `title`. Defaults to `'View'`. */\n defaultAriaLabel?: string;\n styleAdapter?: HTMLStyleAdapter<TNode, TCollector, TContext>;\n /**\n * Emitted unescaped ahead of {@link HTMLStyleAdapter.getScriptText}. A\n * function body with `root` in scope, under the same rules as\n * {@link EnhancementDefinition.script}.\n */\n scriptText?: string;\n /**\n * Progressive enhancements declared by the packs this render was composed\n * from. The render resolves {@link HTMLRenderOptions.enhancements} against\n * them once, hands every renderer the set as `context.enhancements`, and\n * emits each resolved one's script.\n */\n enhancementDefinitions?: readonly EnhancementDefinition[];\n}\n\n/**\n * Renders a composition to standalone HTML: the wrapper element, the pack's\n * markup, and its CSS either inlined or returned separately.\n *\n * Runs the pack twice when a style adapter is present — once to collect\n * styles, once with the render context those styles produced — so a\n * `renderReact` implementation must be free of side effects.\n */\nexport const renderHTMLWithDispatcher = <\n TNode extends PrimitiveNode,\n TCollector extends PrimitiveStyleCollector = PrimitiveStyleCollector,\n TContext = StyledRenderContext,\n>(\n input: Composition<TNode>,\n {\n dispatcher,\n validate = createCompositionValidator<TNode>(dispatcher.definitions),\n options: rawOptions = {},\n defaultAriaLabel = 'View',\n styleAdapter,\n scriptText = '',\n enhancementDefinitions = [],\n }: HTMLDispatcherRenderOptions<TNode, TCollector, TContext>\n): HTMLRenderResult => {\n const validation = validate(input);\n const composition = compositionToRender(validation);\n // Resolved before the validation mode is read, so an adapter can derive\n // `onValidationError`.\n const options =\n styleAdapter?.resolveOptions?.(composition, rawOptions) ?? rawOptions;\n enforceValidationMode(validation, options.onValidationError);\n const framed = options.framed ?? true;\n const heading = options.heading ?? true;\n const theme = options.theme ?? composition.theme ?? 'auto';\n const cssMode = options.css ?? 'inline';\n const scriptsMode = options.scripts ?? 'embedded';\n const styleState = styleAdapter?.createCollector(options);\n const enhancementScope: HTMLEnhancementScope = {\n walk: createChildNodeWalker(dispatcher.definitions),\n definitions: enhancementDefinitions,\n };\n const applied = resolveEnhancements(\n composition.body,\n enhancementScope.walk,\n enhancementDefinitions,\n options.enhancements ?? []\n );\n const enhancements: ReadonlySet<string> = new Set(\n applied.map(({ id }) => id)\n );\n const anchors =\n options.anchors === true || applied.some(({ anchors }) => anchors);\n const enhanced = (context: TContext): TContext =>\n contextWith(context, 'enhancements', enhancements);\n\n if (styleState) {\n styleAdapter?.collectWrapperStyles?.(styleState, options);\n styleAdapter?.collectViewStyles?.(\n composition,\n dispatcher,\n styleState,\n { fluid: Boolean(options.fluid) },\n options,\n enhancementScope\n );\n const collectionContext = enhanced(\n styleAdapter?.createRenderContext(styleState, options) as TContext\n );\n withAnchors(anchors, () =>\n renderToStaticMarkup(\n createElement(() =>\n renderCompositionContent(composition, dispatcher, collectionContext, {\n heading,\n })\n )\n )\n );\n styleAdapter?.collectAfterRender?.(composition, styleState, options);\n }\n\n const renderContext = enhanced(\n styleState && styleAdapter\n ? styleAdapter.createRenderContext(styleState, options)\n : // No adapter means no class names and no css vars to resolve.\n ({} as TContext)\n );\n const cssText =\n styleState && styleAdapter\n ? styleAdapter.renderStyles(styleState, options)\n : '';\n const adapterScriptText =\n styleAdapter?.getScriptText?.(composition, options, enhancementScope) ?? '';\n const js = [\n ...[scriptText, adapterScriptText].filter(Boolean).map(scopeScript),\n enhancementScript(applied),\n ]\n .filter(Boolean)\n .join('\\n');\n const embeddedScript =\n js && scriptsMode === 'embedded' ? embedScript(js) : '';\n const body = withAnchors(anchors, () =>\n renderToStaticMarkup(\n createElement(() =>\n renderCompositionContent(composition, dispatcher, renderContext, {\n heading,\n })\n )\n )\n );\n const inlineCss = cssMode === 'inline' ? embedCss(cssText) : '';\n const inlineJs = embeddedScript ? embedJs(embeddedScript) : '';\n const raw = renderToStaticMarkup(\n createElement(RenderedHtmlView<TNode>, {\n composition,\n theme,\n fluid: Boolean(options.fluid),\n framed,\n styleText: inlineCss || undefined,\n scriptText: inlineJs || undefined,\n defaultAriaLabel,\n body,\n })\n );\n const html = options.minify === false ? raw : minifyHtml(raw);\n\n // Inline payloads are measured as emitted, escapes included.\n const inlineCssBytes = byteLength(inlineCss);\n const inlineJsBytes = byteLength(inlineJs);\n const separateCssBytes = cssMode === 'inline' ? 0 : byteLength(cssText);\n const separateJsBytes = embeddedScript ? 0 : byteLength(js);\n\n return {\n html,\n css: cssText,\n js,\n body,\n measurement: {\n html: byteLength(html) - inlineCssBytes - inlineJsBytes,\n css: inlineCssBytes + separateCssBytes,\n js: inlineJsBytes + separateJsBytes,\n total: byteLength(html) + separateCssBytes + separateJsBytes,\n },\n validationErrors: validation.errors,\n };\n};\n\ninterface RenderedHtmlViewProps<TNode extends PrimitiveNode> {\n composition: Composition<TNode>;\n theme: RenderTheme;\n fluid: boolean;\n framed: boolean;\n styleText?: string | undefined;\n scriptText?: string | undefined;\n defaultAriaLabel: string;\n body: string;\n}\n\n// Only `</style` ends a `<style>`. `\\/` is a CSS escape for `/`, so a string\n// holding it keeps its value.\nconst embedCss = (css: string): string => css.replace(/<\\/(?=style)/gi, '<\\\\/');\n\ninterface ScriptNode extends JavaScriptNode {\n tag: ScriptNode;\n quasi: ScriptNode;\n quasis: ScriptNode[];\n expressions: ScriptNode[];\n value: { raw: string; cooked: string | null };\n name?: string;\n}\n\n// Tagged templates observe raw spelling and reuse the same frozen object per site.\nconst embedJs = (js: string): string => {\n if (!/<\\/script|<!--/i.test(js)) return js;\n const comments: JavaScriptComment[] = [];\n const tree = parse(js, { ecmaVersion: 'latest', onComment: comments });\n const sites: ScriptNode[] = [];\n const identifiers = new Set<string>();\n const pending: JavaScriptNode[] = [tree];\n while (pending.length) {\n const node = pending.pop()! as ScriptNode;\n if (node.type === 'Identifier' && node.name) identifiers.add(node.name);\n if (\n node.type === 'TaggedTemplateExpression' &&\n node.quasi.quasis.some(({ value: { raw } }) =>\n /<\\/script|<!--/i.test(raw)\n )\n )\n sites.push(node);\n for (const value of Object.values(node)) {\n for (const child of Array.isArray(value) ? value : [value]) {\n if (\n child &&\n typeof child === 'object' &&\n 'type' in child &&\n 'start' in child\n ) {\n pending.push(child as JavaScriptNode);\n }\n }\n }\n }\n sites.sort((a, b) => a.start - b.start);\n let prefix = '__isomerTemplate';\n while ([...identifiers].some((name) => name.startsWith(prefix)))\n prefix += '_';\n const literal = (value: string | null): string =>\n value === null ? 'void 0' : JSON.stringify(value).replace(/</g, '\\\\u003c');\n const rewrite = (start: number, end: number): string => {\n let cursor = start;\n let result = '';\n const edits = [\n ...sites.map((site, index) => ({\n ...site,\n index,\n comment: undefined as string | undefined,\n })),\n ...comments\n .filter(({ start }) => /^(?:<!--|-->)/.test(js.slice(start, start + 4)))\n .map((comment) => ({ ...comment, index: -1, comment: comment.value })),\n ].sort((a, b) => a.start - b.start);\n for (const edit of edits) {\n if (edit.start < cursor || edit.end > end) continue;\n result += js.slice(cursor, edit.start);\n if (edit.comment !== undefined) {\n result += `//${edit.comment}`;\n } else {\n const site = sites[edit.index]!;\n const {\n tag,\n quasi: { quasis, expressions },\n } = site;\n const cooked = quasis\n .map(({ value }) => literal(value.cooked))\n .join(',');\n const raw = quasis.map(({ value }) => literal(value.raw)).join(',');\n const cache = `${prefix}${edit.index}`;\n const template = `${cache} ??= ${prefix}Freeze(${prefix}Define([${cooked}], 'raw', {value:${prefix}Freeze([${raw}])}))`;\n const args = expressions.map((expression) =>\n rewrite(expression.start, expression.end)\n );\n result += `(${rewrite(tag.start, tag.end)})(${template}${args.map((arg) => `,(${arg})`).join('')})`;\n }\n cursor = edit.end;\n }\n return result + js.slice(cursor, end);\n };\n const rewritten = rewrite(0, js.length);\n const scoped = sites.length\n ? `(function(){const ${prefix}Freeze=Object.freeze,${prefix}Define=Object.defineProperty;let ${sites.map((_site, index) => `${prefix}${index}`).join(',')};\\n${rewritten}\\n})();`\n : rewritten;\n return scoped\n .replace(/<\\/(?=script)/gi, '<\\\\/')\n .replace(/<!--/g, (_match, at: number, source: string) =>\n escapedBy(source, at) ? 'x3C!--' : '\\\\x3C!--'\n );\n};\n\nconst escapedBy = (source: string, at: number): boolean => {\n let slashes = 0;\n while (source[at - slashes - 1] === '\\\\') slashes += 1;\n return slashes % 2 === 1;\n};\n\nconst RenderedHtmlView = <TNode extends PrimitiveNode>({\n composition,\n theme,\n fluid,\n framed,\n styleText,\n scriptText,\n defaultAriaLabel,\n body,\n}: RenderedHtmlViewProps<TNode>): ReactNode =>\n wrapCompositionContent(\n createElement(\n Fragment,\n null,\n styleText\n ? createElement('style', {\n key: 'style',\n dangerouslySetInnerHTML: { __html: styleText },\n })\n : null,\n createElement('div', {\n key: 'body',\n dangerouslySetInnerHTML: { __html: body },\n }),\n scriptText\n ? createElement('script', {\n key: 'script',\n [EMBEDDED_SCRIPT_ATTRIBUTE]: '',\n dangerouslySetInnerHTML: { __html: scriptText },\n })\n : null\n ),\n composition,\n { framed, fluid, theme, defaultAriaLabel }\n );\n\n// Whitespace inside `pre`, `script`, `style`, and `textarea` is content, so\n// those elements match whole and pass through. Elsewhere only whitespace\n// spanning a line break is collapsed: a single space between inline elements\n// (`<b>a</b> <i>b</i>`) is authored content.\nconst MINIFY_RE =\n /<(pre|script|style|textarea)[\\s>][\\s\\S]*?(?:<\\/\\1\\s*>|$)|(?<=>)\\s+(?=<)/gi;\n\nconst minifyHtml = (value: string): string =>\n value\n .replace(MINIFY_RE, (match, element: string | undefined) =>\n element || !match.includes('\\n') ? match : ''\n )\n .trim();\n"]}
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../../src/render/html/envelope.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAGL,KAAK,GACN,MAAM,OAAO,CAAC;AAEf,OAAO,EAEL,qBAAqB,GACtB,MAAM,kCAAkC,CAAC;AAY1C,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,WAAW,GACZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,mBAAmB,EACnB,0BAA0B,EAC1B,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AACjE,OAAO,EAEL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,WAAW,EAEX,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAqNxB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAKtC,KAAyB,EACzB,EACE,UAAU,E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search B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport { createElement, Fragment, type ReactNode } from 'react';\nimport { renderToStaticMarkup } from 'react-dom/server';\nimport {\n type Comment as JavaScriptComment,\n type Node as JavaScriptNode,\n parse,\n} from 'acorn';\n\nimport {\n type ChildNodeWalker,\n createChildNodeWalker,\n} from '../../composition/body_node_base';\nimport type { Composition } from '../../composition/composition';\nimport type { RenderTheme } from '../../composition/named_color';\nimport type { ValidationError } from '../../composition/validation_error';\nimport type {\n AnyPrimitiveDefinition,\n PrimitiveNode,\n PrimitiveStyleCollectionContext,\n PrimitiveStyleCollector,\n StyledRenderContext,\n StyleHandle,\n} from '../../define/primitive_module';\nimport {\n EMBEDDED_SCRIPT_ATTRIBUTE,\n resolveEnhancements,\n scopeScript,\n} from '../../pack/enhancements';\nimport {\n type CheckedValidationResult,\n compositionToRender,\n createCompositionValidator,\n enforceValidationMode,\n type ValidationErrorMode,\n} from '../../validate/validation';\nimport { withAnchors } from '../anchors';\nimport { contextWith } from '../context_view';\nimport { byteLength, type PayloadMeasurement } from '../payload';\nimport {\n type ReactContentDispatcher,\n renderCompositionContent,\n wrapCompositionContent,\n} from '../react/content';\n\nimport {\n embedScript,\n type EnhancementDefinition,\n enhancementScript,\n} from './enhancements';\n\n/** Knobs for the HTML surface. Every field defaults, so `{}` is valid. */\nexport interface HTMLRenderOptions {\n /** Overrides {@link Composition.theme}; `auto` when neither is set. */\n theme?: RenderTheme;\n /** Drops whitespace between tags that spans a line break, leaving `<pre>`, `<script>`, `<style>`, and `<textarea>` content intact. Defaults to `true`. */\n minify?: boolean;\n /** Adds the `fluid` wrapper class and reaches the pack as {@link PrimitiveStyleCollectionContext.fluid}; the adapter decides what it changes. */\n fluid?: boolean;\n /** Adds the `framed` wrapper class the adapter styles as a frame. Defaults to `true`. */\n framed?: boolean;\n /**\n * Renders the composition's title and subtitle. Defaults to `true`. Set\n * `false` when the embedding host already shows the title itself — the title\n * still backs the wrapper's `aria-label`.\n */\n heading?: boolean;\n /** Whether the collected CSS is inlined as a `<style>` element. Defaults to `'inline'`. */\n css?: 'inline' | 'separate';\n /**\n * Who runs the enhancement script. Defaults to `'embedded'`: `html` carries\n * a `<script>` that finds its own `.isomer` section when the page parses it.\n *\n * `'embedded'` never runs inside a shadow root, or anywhere the host inserts\n * `html` itself (`innerHTML`, a React tree). Use `'host'` there: `html`\n * carries no `<script>`, and the host calls `runEnhancementScript(js,\n * section)` after inserting it.\n */\n scripts?: 'embedded' | 'host';\n /** Defaults to collecting into {@link HTMLRenderResult.validationErrors}; `'throw'` raises instead. Input the budget refused raises in either mode. */\n onValidationError?: ValidationErrorMode;\n /** Opt-in by {@link EnhancementDefinition.id}. One whose content gate does not match the body is dropped. */\n enhancements?: readonly string[];\n /** `true` renders node anchors whether or not an enhancement asks for them, e.g. for tests. `false` cannot turn off anchors an enhancement needs. */\n anchors?: boolean;\n /**\n * Resolves `light-dark(…)` in the stylesheet to one scheme's value. A browser\n * resolves it itself; an image is one static frame, so the `snapshot` surface sets\n * it.\n */\n scheme?: 'light' | 'dark';\n}\n\n/**\n * One rendered HTML payload.\n *\n * `body` is the primitive markup alone; `html` adds the wrapper element, on\n * the default `css: 'inline'` a `<style>`, and on the default\n * `scripts: 'embedded'` a `<script>`. `css` and `js` are populated either way.\n * `validationErrors` are the messages that survived\n * {@link HTMLRenderOptions.onValidationError}.\n */\nexport interface HTMLRenderResult {\n html: string;\n css: string;\n /**\n * The enhancement script as a function body over `root`, or `''`. Under\n * `scripts: 'embedded'` the `<script>` in `html` wraps the same body; under\n * `'host'` the host runs it with `runEnhancementScript`. It is never a\n * complete script on its own.\n */\n js: string;\n body: string;\n measurement: PayloadMeasurement;\n validationErrors: ValidationError[];\n}\n\n/**\n * A pack's HTML entry point: the React renderer plus the style pass that runs\n * ahead of it.\n */\nexport interface HTMLRenderDispatcher<\n TNode extends PrimitiveNode,\n TCollector extends PrimitiveStyleCollector = PrimitiveStyleCollector,\n TContext = StyledRenderContext,\n> extends ReactContentDispatcher<TNode, TContext> {\n /** The whole composition's inventory: a child walker built from one pack's definitions cannot descend into another pack's container. */\n readonly definitions: readonly AnyPrimitiveDefinition[];\n /** One node's style pass, driven by {@link HTMLStyleAdapter.collectViewStyles} rather than called by the sdk. */\n collectStyles(\n node: TNode,\n collector: TCollector,\n context: PrimitiveStyleCollectionContext\n ): void;\n}\n\n/**\n * The composition's child walker and the enhancements every loaded pack\n * declared. Threaded into the style adapter so content-gating can see a\n * table nested inside a container from another package.\n */\nexport interface HTMLEnhancementScope {\n walk: ChildNodeWalker;\n definitions: readonly EnhancementDefinition[];\n}\n\n/**\n * How a pack turns its nodes into CSS. Optional overall — without an adapter\n * the render still produces markup, just with no class names and an empty\n * `TContext`.\n */\nexport interface HTMLStyleAdapter<\n TNode extends PrimitiveNode = PrimitiveNode,\n TCollector extends PrimitiveStyleCollector = PrimitiveStyleCollector,\n TContext = StyledRenderContext,\n> {\n /**\n * Names the collector shape {@link HTMLStyleAdapter.createCollector} returns, so a runtime can\n * reject a pack whose `collectStyles` hooks were written against a different one.\n */\n styleCollector?: string;\n /** One collector per render, shared by every other hook here and by both render passes. */\n createCollector(options: HTMLRenderOptions): TCollector;\n /**\n * Settles options that depend on the composition, before anything reads them.\n *\n * Needed by an adapter whose look is chosen per render: deciding `framed`\n * from the body has to happen before the wrapper class is written, not while\n * CSS is collected.\n */\n resolveOptions?(\n composition: Composition<TNode>,\n options: HTMLRenderOptions\n ): HTMLRenderOptions;\n /**\n * The `.isomer` / `.isomer.framed` / `.isomer.fluid` rules around a rendered composition.\n * Named for the wrapper rather than the frame, which the sdk reserves for the\n * document a snapshot is drawn inside.\n */\n collectWrapperStyles?(\n collector: TCollector,\n options: HTMLRenderOptions\n ): void;\n /** Walks the body into the collector, usually through {@link HTMLRenderDispatcher.collectStyles}. Runs before any markup exists. */\n collectViewStyles?(\n composition: Composition<TNode>,\n dispatcher: HTMLRenderDispatcher<TNode, TCollector, TContext>,\n collector: TCollector,\n context: PrimitiveStyleCollectionContext,\n options: HTMLRenderOptions,\n scope: HTMLEnhancementScope\n ): void;\n /** Runs once the collection pass has rendered the body, for styles only a renderer can discover. That markup is discarded. */\n collectAfterRender?(\n composition: Composition<TNode>,\n collector: TCollector,\n options: HTMLRenderOptions\n ): void;\n /**\n * Builds the render context handed to every `react` renderer. Called once\n * per pass, so an adapter that behaves differently while collecting returns\n * a different context then. Must be complete, because `TContext` is the\n * pack's own type. The sdk never writes to it: whether renderers anchor\n * is the surface's decision, whatever the context's `anchors` says.\n */\n createRenderContext(\n collector: TCollector,\n options: HTMLRenderOptions\n ): TContext;\n /** The collected CSS as text, with no `<style>` wrapper; the sdk adds one when `css` is `'inline'`. */\n renderStyles(collector: TCollector, options: HTMLRenderOptions): string;\n /**\n * Whether `handle` belongs to this adapter's stylesheet.\n *\n * Unused on a lone adapter. A runtime composing several packs' adapters\n * routes each handle to its owner, so CSS is neither duplicated nor\n * rendered against the wrong theme. An adapter that cannot answer this\n * cannot be combined with another.\n */\n ownsHandle?(handle: StyleHandle): boolean;\n /**\n * Appended after {@link HTMLDispatcherRenderOptions.scriptText} into the\n * render's one script. A function body with `root` in scope, under the same\n * rules as {@link EnhancementDefinition.script}.\n */\n getScriptText?(\n composition: Composition<TNode>,\n options: HTMLRenderOptions,\n scope: HTMLEnhancementScope\n ): string;\n}\n\n/** What {@link renderHTMLWithDispatcher} needs beyond the composition. */\nexport interface HTMLDispatcherRenderOptions<\n TNode extends PrimitiveNode,\n TCollector extends PrimitiveStyleCollector = PrimitiveStyleCollector,\n TContext = StyledRenderContext,\n> {\n dispatcher: HTMLRenderDispatcher<TNode, TCollector, TContext>;\n /** Runs once before rendering, which draws the composition it returns; {@link HTMLRenderOptions.onValidationError} decides what becomes of its errors. Defaults to `createCompositionValidator(dispatcher.definitions)`. */\n validate?: (\n composition: Composition<TNode>\n ) => CheckedValidationResult<TNode>;\n options?: HTMLRenderOptions;\n /** Used only when the composition has neither `meta.ariaLabel` nor a `title`. Defaults to `'View'`. */\n defaultAriaLabel?: string;\n styleAdapter?: HTMLStyleAdapter<TNode, TCollector, TContext>;\n /**\n * Emitted unescaped ahead of {@link HTMLStyleAdapter.getScriptText}. A\n * function body with `root` in scope, under the same rules as\n * {@link EnhancementDefinition.script}.\n */\n scriptText?: string;\n /**\n * Progressive enhancements declared by the packs this render was composed\n * from. The render resolves {@link HTMLRenderOptions.enhancements} against\n * them once, hands every renderer the set as `context.enhancements`, and\n * emits each resolved one's script.\n */\n enhancementDefinitions?: readonly EnhancementDefinition[];\n}\n\n/**\n * Renders a composition to standalone HTML: the wrapper element, the pack's\n * markup, and its CSS either inlined or returned separately.\n *\n * Runs the pack twice when a style adapter is present — once to collect\n * styles, once with the render context those styles produced — so a\n * `renderReact` implementation must be free of side effects.\n */\nexport const renderHTMLWithDispatcher = <\n TNode extends PrimitiveNode,\n TCollector extends PrimitiveStyleCollector = PrimitiveStyleCollector,\n TContext = StyledRenderContext,\n>(\n input: Composition<TNode>,\n {\n dispatcher,\n validate = createCompositionValidator<TNode>(dispatcher.definitions),\n options: rawOptions = {},\n defaultAriaLabel = 'View',\n styleAdapter,\n scriptText = '',\n enhancementDefinitions = [],\n }: HTMLDispatcherRenderOptions<TNode, TCollector, TContext>\n): HTMLRenderResult => {\n const validation = validate(input);\n const composition = compositionToRender(validation);\n // Resolved before the validation mode is read, so an adapter can derive\n // `onValidationError`.\n const options =\n styleAdapter?.resolveOptions?.(composition, rawOptions) ?? rawOptions;\n enforceValidationMode(validation, options.onValidationError);\n const framed = options.framed ?? true;\n const heading = options.heading ?? true;\n const theme = options.theme ?? composition.theme ?? 'auto';\n const cssMode = options.css ?? 'inline';\n const scriptsMode = options.scripts ?? 'embedded';\n const styleState = styleAdapter?.createCollector(options);\n const enhancementScope: HTMLEnhancementScope = {\n walk: createChildNodeWalker(dispatcher.definitions),\n definitions: enhancementDefinitions,\n };\n const applied = resolveEnhancements(\n composition.body,\n enhancementScope.walk,\n enhancementDefinitions,\n options.enhancements ?? []\n );\n const enhancements: ReadonlySet<string> = new Set(\n applied.map(({ id }) => id)\n );\n const anchors =\n options.anchors === true || applied.some(({ anchors }) => anchors);\n const enhanced = (context: TContext): TContext =>\n contextWith(context, 'enhancements', enhancements);\n\n if (styleState) {\n styleAdapter?.collectWrapperStyles?.(styleState, options);\n styleAdapter?.collectViewStyles?.(\n composition,\n dispatcher,\n styleState,\n { fluid: Boolean(options.fluid) },\n options,\n enhancementScope\n );\n const collectionContext = enhanced(\n styleAdapter?.createRenderContext(styleState, options) as TContext\n );\n withAnchors(anchors, () =>\n renderToStaticMarkup(\n createElement(() =>\n renderCompositionContent(composition, dispatcher, collectionContext, {\n heading,\n })\n )\n )\n );\n styleAdapter?.collectAfterRender?.(composition, styleState, options);\n }\n\n const renderContext = enhanced(\n styleState && styleAdapter\n ? styleAdapter.createRenderContext(styleState, options)\n : // No adapter means no class names and no css vars to resolve.\n ({} as TContext)\n );\n const cssText =\n styleState && styleAdapter\n ? styleAdapter.renderStyles(styleState, options)\n : '';\n const adapterScriptText =\n styleAdapter?.getScriptText?.(composition, options, enhancementScope) ?? '';\n const js = [\n ...[scriptText, adapterScriptText].filter(Boolean).map(scopeScript),\n enhancementScript(applied),\n ]\n .filter(Boolean)\n .join('\\n');\n const embeddedScript =\n js && scriptsMode === 'embedded' ? embedScript(js) : '';\n const body = withAnchors(anchors, () =>\n renderToStaticMarkup(\n createElement(() =>\n renderCompositionContent(composition, dispatcher, renderContext, {\n heading,\n })\n )\n )\n );\n const inlineCss = cssMode === 'inline' ? embedCss(cssText) : '';\n const inlineJs = embeddedScript ? embedJs(embeddedScript) : '';\n const raw = renderToStaticMarkup(\n createElement(RenderedHtmlView<TNode>, {\n composition,\n theme,\n fluid: Boolean(options.fluid),\n framed,\n styleText: inlineCss || undefined,\n scriptText: inlineJs || undefined,\n defaultAriaLabel,\n body,\n })\n );\n const html = options.minify === false ? raw : minifyHtml(raw);\n\n // Inline payloads are measured as emitted, escapes included.\n const inlineCssBytes = byteLength(inlineCss);\n const inlineJsBytes = byteLength(inlineJs);\n const separateCssBytes = cssMode === 'inline' ? 0 : byteLength(cssText);\n const separateJsBytes = embeddedScript ? 0 : byteLength(js);\n\n return {\n html,\n css: cssText,\n js,\n body,\n measurement: {\n html: byteLength(html) - inlineCssBytes - inlineJsBytes,\n css: inlineCssBytes + separateCssBytes,\n js: inlineJsBytes + separateJsBytes,\n total: byteLength(html) + separateCssBytes + separateJsBytes,\n },\n validationErrors: validation.errors,\n };\n};\n\ninterface RenderedHtmlViewProps<TNode extends PrimitiveNode> {\n composition: Composition<TNode>;\n theme: RenderTheme;\n fluid: boolean;\n framed: boolean;\n styleText?: string | undefined;\n scriptText?: string | undefined;\n defaultAriaLabel: string;\n body: string;\n}\n\n// Only `</style` ends a `<style>`. `\\/` is a CSS escape for `/`, so a string\n// holding it keeps its value.\nconst embedCss = (css: string): string => css.replace(/<\\/(?=style)/gi, '<\\\\/');\n\ninterface ScriptNode extends JavaScriptNode {\n tag: ScriptNode;\n quasi: ScriptNode;\n quasis: ScriptNode[];\n expressions: ScriptNode[];\n value: { raw: string; cooked: string | null };\n name?: string;\n}\n\n// Tagged templates observe raw spelling and reuse the same frozen object per site.\nconst embedJs = (js: string): string => {\n if (!/<\\/script|<!--/i.test(js)) {\n return js;\n }\n const comments: JavaScriptComment[] = [];\n const tree = parse(js, { ecmaVersion: 'latest', onComment: comments });\n const sites: ScriptNode[] = [];\n const identifiers = new Set<string>();\n const pending: JavaScriptNode[] = [tree];\n while (pending.length) {\n const node = pending.pop()! as ScriptNode;\n if (node.type === 'Identifier' && node.name) {\n identifiers.add(node.name);\n }\n if (\n node.type === 'TaggedTemplateExpression' &&\n node.quasi.quasis.some(({ value: { raw } }) =>\n /<\\/script|<!--/i.test(raw)\n )\n ) {\n sites.push(node);\n }\n for (const value of Object.values(node)) {\n for (const child of Array.isArray(value) ? value : [value]) {\n if (\n child &&\n typeof child === 'object' &&\n 'type' in child &&\n 'start' in child\n ) {\n pending.push(child as JavaScriptNode);\n }\n }\n }\n }\n sites.sort((a, b) => a.start - b.start);\n let prefix = '__isomerTemplate';\n while ([...identifiers].some((name) => name.startsWith(prefix))) {\n prefix += '_';\n }\n const literal = (value: string | null): string =>\n value === null ? 'void 0' : JSON.stringify(value).replace(/</g, '\\\\u003c');\n const rewrite = (start: number, end: number): string => {\n let cursor = start;\n let result = '';\n const edits = [\n ...sites.map((site, index) => ({\n ...site,\n index,\n comment: undefined as string | undefined,\n })),\n ...comments\n .filter(({ start }) => /^(?:<!--|-->)/.test(js.slice(start, start + 4)))\n .map((comment) => ({ ...comment, index: -1, comment: comment.value })),\n ].sort((a, b) => a.start - b.start);\n for (const edit of edits) {\n if (edit.start < cursor || edit.end > end) {\n continue;\n }\n result += js.slice(cursor, edit.start);\n if (edit.comment !== undefined) {\n result += `//${edit.comment}`;\n } else {\n const site = sites[edit.index]!;\n const {\n tag,\n quasi: { quasis, expressions },\n } = site;\n const cooked = quasis\n .map(({ value }) => literal(value.cooked))\n .join(',');\n const raw = quasis.map(({ value }) => literal(value.raw)).join(',');\n const cache = `${prefix}${edit.index}`;\n const template = `${cache} ??= ${prefix}Freeze(${prefix}Define([${cooked}], 'raw', {value:${prefix}Freeze([${raw}])}))`;\n const args = expressions.map((expression) =>\n rewrite(expression.start, expression.end)\n );\n result += `(${rewrite(tag.start, tag.end)})(${template}${args.map((arg) => `,(${arg})`).join('')})`;\n }\n cursor = edit.end;\n }\n return result + js.slice(cursor, end);\n };\n const rewritten = rewrite(0, js.length);\n const scoped = sites.length\n ? `(function(){const ${prefix}Freeze=Object.freeze,${prefix}Define=Object.defineProperty;let ${sites.map((_site, index) => `${prefix}${index}`).join(',')};\\n${rewritten}\\n})();`\n : rewritten;\n return scoped\n .replace(/<\\/(?=script)/gi, '<\\\\/')\n .replace(/<!--/g, (_match, at: number, source: string) =>\n escapedBy(source, at) ? 'x3C!--' : '\\\\x3C!--'\n );\n};\n\nconst escapedBy = (source: string, at: number): boolean => {\n let slashes = 0;\n while (source[at - slashes - 1] === '\\\\') {\n slashes += 1;\n }\n return slashes % 2 === 1;\n};\n\nconst RenderedHtmlView = <TNode extends PrimitiveNode>({\n composition,\n theme,\n fluid,\n framed,\n styleText,\n scriptText,\n defaultAriaLabel,\n body,\n}: RenderedHtmlViewProps<TNode>): ReactNode =>\n wrapCompositionContent(\n createElement(\n Fragment,\n null,\n styleText\n ? createElement('style', {\n key: 'style',\n dangerouslySetInnerHTML: { __html: styleText },\n })\n : null,\n createElement('div', {\n key: 'body',\n dangerouslySetInnerHTML: { __html: body },\n }),\n scriptText\n ? createElement('script', {\n key: 'script',\n [EMBEDDED_SCRIPT_ATTRIBUTE]: '',\n dangerouslySetInnerHTML: { __html: scriptText },\n })\n : null\n ),\n composition,\n { framed, fluid, theme, defaultAriaLabel }\n );\n\n// Whitespace inside `pre`, `script`, `style`, and `textarea` is content, so\n// those elements match whole and pass through. Elsewhere only whitespace\n// spanning a line break is collapsed: a single space between inline elements\n// (`<b>a</b> <i>b</i>`) is authored content.\nconst MINIFY_RE =\n /<(pre|script|style|textarea)[\\s>][\\s\\S]*?(?:<\\/\\1\\s*>|$)|(?<=>)\\s+(?=<)/gi;\n\nconst minifyHtml = (value: string): string =>\n value\n .replace(MINIFY_RE, (match, element: string | undefined) =>\n element || !match.includes('\\n') ? match : ''\n )\n .trim();\n"]}
|
|
@@ -39,5 +39,5 @@ export interface LayoutFinding {
|
|
|
39
39
|
* compared. Nothing inside a scaled box is checked. A finding is advice, not an error:
|
|
40
40
|
* an overlap may be intended.
|
|
41
41
|
*/
|
|
42
|
-
export declare const checkLayout: (layout: LayoutBox, body: readonly unknown[], walk: ChildNodeWalker, surface: "react" | "
|
|
42
|
+
export declare const checkLayout: (layout: LayoutBox, body: readonly unknown[], walk: ChildNodeWalker, surface: "react" | "snapshot") => LayoutFinding[];
|
|
43
43
|
//# sourceMappingURL=layout_check.d.ts.map
|