@elastic/isomer-sdk 0.1.0 → 0.2.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/README.md +13 -2
- package/dist/author/authored_fields.d.ts +61 -11
- package/dist/author/authored_fields.d.ts.map +1 -1
- package/dist/author/authored_fields.js +73 -29
- 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 +60 -0
- package/dist/author/authoring_input.js.map +1 -0
- package/dist/author/authoring_model.d.ts +27 -0
- package/dist/author/authoring_model.d.ts.map +1 -0
- package/dist/author/authoring_model.js +98 -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 +277 -0
- package/dist/author/declarations.js.map +1 -0
- package/dist/author/index.d.ts +3 -1
- package/dist/author/index.d.ts.map +1 -1
- package/dist/author/index.js +3 -1
- package/dist/author/index.js.map +1 -1
- package/dist/author/jsx_shim.d.ts +6 -5
- package/dist/author/jsx_shim.d.ts.map +1 -1
- package/dist/author/jsx_shim.js +28 -111
- package/dist/author/jsx_shim.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 +286 -0
- package/dist/author/schema_to_typescript.js.map +1 -0
- package/dist/cjs/author/authored_fields.js +77 -33
- package/dist/cjs/author/authored_fields.js.map +1 -1
- package/dist/cjs/author/authoring_input.js +64 -0
- package/dist/cjs/author/authoring_input.js.map +1 -0
- package/dist/cjs/author/authoring_model.js +104 -0
- package/dist/cjs/author/authoring_model.js.map +1 -0
- package/dist/cjs/author/declarations.js +281 -0
- package/dist/cjs/author/declarations.js.map +1 -0
- package/dist/cjs/author/index.js +6 -1
- package/dist/cjs/author/index.js.map +1 -1
- package/dist/cjs/author/jsx_shim.js +31 -114
- package/dist/cjs/author/jsx_shim.js.map +1 -1
- package/dist/cjs/author/schema_to_typescript.js +295 -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 +1 -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/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 +14 -3
- 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 +7 -2
- package/dist/cjs/entries/index.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.map +1 -1
- package/dist/cjs/pack/primitive_pack.js +14 -2
- 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/html/envelope.js.map +1 -1
- package/dist/cjs/render/layout_check.js.map +1 -1
- package/dist/cjs/render/markdown/builder.js +14 -8
- package/dist/cjs/render/markdown/builder.js.map +1 -1
- package/dist/cjs/render/markdown/format.js +30 -12
- package/dist/cjs/render/markdown/format.js.map +1 -1
- package/dist/cjs/render/primitive_dispatch.js +11 -25
- package/dist/cjs/render/primitive_dispatch.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 +166 -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/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 +1 -0
- package/dist/composition/error.d.ts.map +1 -1
- package/dist/composition/error.js +1 -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/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 +38 -24
- package/dist/define/primitive_module.d.ts.map +1 -1
- package/dist/define/primitive_module.js +14 -3
- 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 +2 -2
- package/dist/entries/index.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 +1 -1
- package/dist/pack/index.d.ts.map +1 -1
- package/dist/pack/index.js +1 -1
- package/dist/pack/index.js.map +1 -1
- package/dist/pack/primitive_pack.d.ts +11 -2
- package/dist/pack/primitive_pack.d.ts.map +1 -1
- package/dist/pack/primitive_pack.js +12 -1
- 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/html/envelope.d.ts +3 -3
- 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 +2 -4
- package/dist/render/markdown/builder.d.ts.map +1 -1
- package/dist/render/markdown/builder.js +14 -7
- package/dist/render/markdown/builder.js.map +1 -1
- package/dist/render/markdown/format.d.ts +7 -0
- package/dist/render/markdown/format.d.ts.map +1 -1
- package/dist/render/markdown/format.js +27 -11
- package/dist/render/markdown/format.js.map +1 -1
- 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/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 +163 -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/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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slack.js","sourceRoot":"","sources":["../../src/entries/slack.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EA8CL,YAAY,EACZ,IAAI,EACJ,cAAc,EACd,IAAI,EACJ,SAAS,EACT,yBAAyB,EACzB,YAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"slack.js","sourceRoot":"","sources":["../../src/entries/slack.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EA8CL,YAAY,EACZ,IAAI,EACJ,cAAc,EACd,IAAI,EACJ,SAAS,EACT,yBAAyB,EACzB,YAAY,EACZ,wBAAwB,EACxB,MAAM,EACN,IAAI,EACJ,4BAA4B,EAC5B,mBAAmB,EACnB,YAAY,EACZ,MAAM,GACP,MAAM,iBAAiB,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\nexport {\n type SlackActionElement,\n type SlackActionsBlock,\n type SlackAssetCollector,\n type SlackAssetRequest,\n type SlackBlock,\n type SlackButtonElement,\n type SlackCheckboxesElement,\n type SlackContextBlock,\n type SlackDividerBlock,\n type SlackEnvelopeDispatcher,\n type SlackEnvelopeOptions,\n type SlackEnvelopeResult,\n type SlackFileReference,\n type SlackHeaderBlock,\n type SlackHeaderLevel,\n type SlackImageBlock,\n type SlackImageElement,\n type SlackMrkdwnTextObject,\n type SlackMultiStaticSelectElement,\n type SlackOptionGroup,\n type SlackOptionObject,\n type SlackOverflowElement,\n type SlackPlainTextObject,\n type SlackRadioButtonsElement,\n type SlackRawTextElement,\n type SlackRichTextBlock,\n type SlackRichTextBlockElement,\n type SlackRichTextInline,\n type SlackRichTextLink,\n type SlackRichTextList,\n type SlackRichTextPreformatted,\n type SlackRichTextQuote,\n type SlackRichTextSection,\n type SlackRichTextStyle,\n type SlackRichTextTag,\n type SlackRichTextText,\n type SlackSectionAccessory,\n type SlackSectionBlock,\n type SlackStaticSelectElement,\n type SlackTableBlock,\n type SlackTableCell,\n type SlackTableColumnSetting,\n type SlackTagColor,\n type SlackTextObject,\n type SlackVideoBlock,\n SLACK_LIMITS,\n bold,\n clampSlackText,\n code,\n codeBlock,\n createSlackAssetCollector,\n escapeMrkdwn,\n isSlackReachableImageUrl,\n italic,\n link,\n markdownContentToSlackBlocks,\n renderSlackEnvelope,\n slackLinkUrl,\n strike,\n} from '../render/slack';\n"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { AnyPrimitivePack } from './primitive_pack.js';
|
|
2
|
+
/** `native` renders through the primitive's own renderer, `fallback` through another surface's (Slack via markdown). */
|
|
3
|
+
export type SurfaceSupport = 'native' | 'fallback';
|
|
2
4
|
/**
|
|
3
5
|
* What a runtime or a pack supports. Enhancement ids are open strings: each
|
|
4
6
|
* pack declares its own on {@link PrimitivePack.enhancements}, and a runtime
|
|
@@ -7,21 +9,33 @@ import type { AnyPrimitivePack } from './primitive_pack.js';
|
|
|
7
9
|
export interface HostCapabilities<TEnhancement extends string = string> {
|
|
8
10
|
/** Primitive `type` values that can be dispatched. */
|
|
9
11
|
primitives: string[];
|
|
10
|
-
/**
|
|
12
|
+
/** Surfaces that render, e.g. `html`, `slack`, `snapshot`. */
|
|
13
|
+
surfaces: string[];
|
|
14
|
+
/** Formats the host can ship, e.g. `html`, `slack`, `png`. Never `snapshot`, which only a rasterizer turns into a format. */
|
|
11
15
|
formats: string[];
|
|
16
|
+
/**
|
|
17
|
+
* How each of `surfaces` renders each primitive, keyed by `type` then surface.
|
|
18
|
+
* `slack` is `fallback` for a primitive with no `slack` renderer; every other
|
|
19
|
+
* surface renders from `react`, `text`, or `markdown`, which are required.
|
|
20
|
+
*/
|
|
21
|
+
support: Record<string, Record<string, SurfaceSupport>>;
|
|
12
22
|
/** Progressive enhancements the packs declare, by id, which an HTML or React render may request. */
|
|
13
23
|
enhancements?: Partial<Record<TEnhancement, boolean>>;
|
|
14
24
|
}
|
|
25
|
+
/** What {@link describeCapabilities} reports beyond the packs themselves. */
|
|
26
|
+
export interface CapabilitySources {
|
|
27
|
+
/** The surfaces the caller built; `snapshot` exists only when a host supplied a frame. */
|
|
28
|
+
surfaces: readonly string[];
|
|
29
|
+
/** Formats produced outside the surfaces, such as a rasterizer's `png`. */
|
|
30
|
+
formats?: readonly string[];
|
|
31
|
+
}
|
|
15
32
|
/**
|
|
16
|
-
* Reports the primitive types and
|
|
33
|
+
* Reports the primitive types, surfaces, and formats a set of packs supports.
|
|
17
34
|
*
|
|
18
|
-
* `
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* particular depends on a frame, which is a runtime input and not a pack's to
|
|
23
|
-
* report.
|
|
24
|
-
* @param formats Candidate formats this caller can reach.
|
|
35
|
+
* `surfaces` is passed rather than derived because only the caller knows which
|
|
36
|
+
* exist. Every surface but `snapshot` is also a format; `formats` adds the ones
|
|
37
|
+
* no surface produces on its own, so a `png` is reported only when a host
|
|
38
|
+
* registers the rasterizer that writes it.
|
|
25
39
|
*/
|
|
26
|
-
export declare const describeCapabilities: (packs: readonly AnyPrimitivePack[], formats:
|
|
40
|
+
export declare const describeCapabilities: (packs: readonly AnyPrimitivePack[], { surfaces, formats }: CapabilitySources) => HostCapabilities;
|
|
27
41
|
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/pack/capabilities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/pack/capabilities.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,wHAAwH;AACxH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEnD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB,CAAC,YAAY,SAAS,MAAM,GAAG,MAAM;IACpE,sDAAsD;IACtD,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,6HAA6H;IAC7H,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IACxD,oGAAoG;IACpG,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC;CACvD;AAED,6EAA6E;AAC7E,MAAM,WAAW,iBAAiB;IAChC,0FAA0F;IAC1F,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,2EAA2E;IAC3E,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B;AAKD;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAC/B,OAAO,SAAS,gBAAgB,EAAE,EAClC,uBAA4B,iBAAiB,KAC5C,gBA2BF,CAAC"}
|
|
@@ -4,22 +4,27 @@
|
|
|
4
4
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
5
|
* 2.0.
|
|
6
6
|
*/
|
|
7
|
+
/** The one surface whose output is not itself a shippable format. */
|
|
8
|
+
const SNAPSHOT = 'snapshot';
|
|
7
9
|
/**
|
|
8
|
-
* Reports the primitive types and
|
|
10
|
+
* Reports the primitive types, surfaces, and formats a set of packs supports.
|
|
9
11
|
*
|
|
10
|
-
* `
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* particular depends on a frame, which is a runtime input and not a pack's to
|
|
15
|
-
* report.
|
|
16
|
-
* @param formats Candidate formats this caller can reach.
|
|
12
|
+
* `surfaces` is passed rather than derived because only the caller knows which
|
|
13
|
+
* exist. Every surface but `snapshot` is also a format; `formats` adds the ones
|
|
14
|
+
* no surface produces on its own, so a `png` is reported only when a host
|
|
15
|
+
* registers the rasterizer that writes it.
|
|
17
16
|
*/
|
|
18
|
-
export const describeCapabilities = (packs, formats) => {
|
|
17
|
+
export const describeCapabilities = (packs, { surfaces, formats = [] }) => {
|
|
19
18
|
const enhancementIds = packs.flatMap((pack) => pack.enhancements.map((definition) => definition.id));
|
|
19
|
+
const definitions = packs.flatMap((pack) => pack.primitives);
|
|
20
20
|
return {
|
|
21
|
-
primitives:
|
|
22
|
-
|
|
21
|
+
primitives: definitions.map(({ type }) => type),
|
|
22
|
+
surfaces: [...surfaces],
|
|
23
|
+
formats: [...new Set([...surfaces, ...formats])].filter((format) => format !== SNAPSHOT),
|
|
24
|
+
support: Object.fromEntries(definitions.map((definition) => [
|
|
25
|
+
definition.type,
|
|
26
|
+
Object.fromEntries(surfaces.map((surface) => [surface, supportOn(definition, surface)])),
|
|
27
|
+
])),
|
|
23
28
|
...(enhancementIds.length > 0
|
|
24
29
|
? {
|
|
25
30
|
enhancements: Object.fromEntries(enhancementIds.map((id) => [id, true])),
|
|
@@ -27,4 +32,5 @@ export const describeCapabilities = (packs, formats) => {
|
|
|
27
32
|
: {}),
|
|
28
33
|
};
|
|
29
34
|
};
|
|
35
|
+
const supportOn = ({ renderers }, surface) => surface === 'slack' && renderers.slack === undefined ? 'fallback' : 'native';
|
|
30
36
|
//# sourceMappingURL=capabilities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../src/pack/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
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YAC3B,CAAC,CAAC;gBACE,YAAY,EAAE,MAAM,CAAC,WAAW,CAC9B,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CACvC;aACF;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAChB,EAAE,SAAS,EAA0B,EACrC,OAAe,EACC,EAAE,CAClB,OAAO,KAAK,OAAO,IAAI,SAAS,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,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// What a host can render, reported from packs rather than asserted by hand.\n//\n// Lives in the sdk so both the assembly layer and a pack import it from the\n// same place; a pack must not have to depend on the assembly layer for it.\n\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\n\nimport type { AnyPrimitivePack } from './primitive_pack';\n\n/** `native` renders through the primitive's own renderer, `fallback` through another surface's (Slack via markdown). */\nexport type SurfaceSupport = 'native' | 'fallback';\n\n/**\n * What a runtime or a pack supports. Enhancement ids are open strings: each\n * pack declares its own on {@link PrimitivePack.enhancements}, and a runtime\n * reports the union.\n */\nexport interface HostCapabilities<TEnhancement extends string = string> {\n /** Primitive `type` values that can be dispatched. */\n primitives: string[];\n /** Surfaces that render, e.g. `html`, `slack`, `snapshot`. */\n surfaces: string[];\n /** Formats the host can ship, e.g. `html`, `slack`, `png`. Never `snapshot`, which only a rasterizer turns into a format. */\n formats: string[];\n /**\n * How each of `surfaces` renders each primitive, keyed by `type` then surface.\n * `slack` is `fallback` for a primitive with no `slack` renderer; every other\n * surface renders from `react`, `text`, or `markdown`, which are required.\n */\n support: Record<string, Record<string, SurfaceSupport>>;\n /** Progressive enhancements the packs declare, by id, which an HTML or React render may request. */\n enhancements?: Partial<Record<TEnhancement, boolean>>;\n}\n\n/** What {@link describeCapabilities} reports beyond the packs themselves. */\nexport interface CapabilitySources {\n /** The surfaces the caller built; `snapshot` exists only when a host supplied a frame. */\n surfaces: readonly string[];\n /** Formats produced outside the surfaces, such as a rasterizer's `png`. */\n formats?: readonly string[];\n}\n\n/** The one surface whose output is not itself a shippable format. */\nconst SNAPSHOT = 'snapshot';\n\n/**\n * Reports the primitive types, surfaces, and formats a set of packs supports.\n *\n * `surfaces` is passed rather than derived because only the caller knows which\n * exist. Every surface but `snapshot` is also a format; `formats` adds the ones\n * no surface produces on its own, so a `png` is reported only when a host\n * registers the rasterizer that writes it.\n */\nexport const describeCapabilities = (\n packs: readonly AnyPrimitivePack[],\n { surfaces, formats = [] }: CapabilitySources\n): HostCapabilities => {\n const enhancementIds = packs.flatMap((pack) =>\n pack.enhancements.map((definition) => definition.id)\n );\n const definitions = packs.flatMap((pack) => pack.primitives);\n return {\n primitives: definitions.map(({ type }) => type),\n surfaces: [...surfaces],\n formats: [...new Set([...surfaces, ...formats])].filter(\n (format) => format !== SNAPSHOT\n ),\n support: Object.fromEntries(\n definitions.map((definition) => [\n definition.type,\n Object.fromEntries(\n surfaces.map((surface) => [surface, supportOn(definition, surface)])\n ),\n ])\n ),\n ...(enhancementIds.length > 0\n ? {\n enhancements: Object.fromEntries(\n enhancementIds.map((id) => [id, true])\n ),\n }\n : {}),\n };\n};\n\nconst supportOn = (\n { renderers }: AnyPrimitiveDefinition,\n surface: string\n): SurfaceSupport =>\n surface === 'slack' && renderers.slack === undefined ? 'fallback' : 'native';\n"]}
|
package/dist/pack/compose.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { PrimitiveIcon } from '../define/primitive_icon.js';
|
|
1
2
|
import type { AnyPrimitiveDefinition } from '../define/primitive_module.js';
|
|
2
3
|
import type { EnhancementDefinition } from './enhancements.js';
|
|
3
|
-
import type
|
|
4
|
+
import { type AnyPrimitivePack } from './primitive_pack.js';
|
|
4
5
|
/**
|
|
5
6
|
* One flattened inventory owned by {@link composePacks}.
|
|
6
7
|
*
|
|
@@ -10,6 +11,8 @@ import type { AnyPrimitivePack } from './primitive_pack.js';
|
|
|
10
11
|
export interface ComposedPacks {
|
|
11
12
|
readonly definitions: readonly AnyPrimitiveDefinition[];
|
|
12
13
|
readonly enhancements: readonly EnhancementDefinition[];
|
|
14
|
+
/** Every definition's `icon` by type, in one frozen null-prototype dictionary. */
|
|
15
|
+
readonly icons: Readonly<Record<string, PrimitiveIcon>>;
|
|
13
16
|
readonly slackAssetTypes: ReadonlySet<string>;
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/pack/compose.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEzE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/pack/compose.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEzE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,KAAK,gBAAgB,EAAe,MAAM,kBAAkB,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,WAAW,EAAE,SAAS,sBAAsB,EAAE,CAAC;IACxD,QAAQ,CAAC,YAAY,EAAE,SAAS,qBAAqB,EAAE,CAAC;IACxD,kFAAkF;IAClF,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;IACxD,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC/C;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,GACvB,OAAO,SAAS,gBAAgB,EAAE,KACjC,aAyCF,CAAC"}
|
package/dist/pack/compose.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* 2.0.
|
|
6
6
|
*/
|
|
7
7
|
import { IsomerError } from '../composition/error.js';
|
|
8
|
+
import { iconsByType } from './primitive_pack.js';
|
|
8
9
|
/**
|
|
9
10
|
* Flattens `packs` into one inventory, rejecting cross-pack duplicate node
|
|
10
11
|
* types and duplicate enhancement ids. Every offender is named in one error,
|
|
@@ -34,9 +35,11 @@ export const composePacks = (packs) => {
|
|
|
34
35
|
}
|
|
35
36
|
assertUnique('DUPLICATE_PRIMITIVE_TYPE', 'primitive type', typeOwners);
|
|
36
37
|
assertUnique('DUPLICATE_ENHANCEMENT', 'enhancement', enhancementOwners);
|
|
38
|
+
const definitions = packs.flatMap((pack) => [...pack.primitives]);
|
|
37
39
|
return Object.freeze({
|
|
38
|
-
definitions: Object.freeze(
|
|
40
|
+
definitions: Object.freeze(definitions),
|
|
39
41
|
enhancements: Object.freeze(packs.flatMap((pack) => [...pack.enhancements])),
|
|
42
|
+
icons: iconsByType(definitions),
|
|
40
43
|
slackAssetTypes: new Set(packs.flatMap((pack) => [...pack.slackAssetTypes])),
|
|
41
44
|
});
|
|
42
45
|
};
|
package/dist/pack/compose.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/pack/compose.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/pack/compose.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,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f,GAAG,IAAI,KAAK,GAAG,mBAAmB,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CACjF;SACA,IAAI,CAAC,IAAI,CAAC,CACd,CAAC;AACJ,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 { IsomerError } from '../composition/error';\nimport type { PrimitiveIcon } from '../define/primitive_icon';\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\n\nimport type { EnhancementDefinition } from './enhancements';\nimport { type AnyPrimitivePack, iconsByType } from './primitive_pack';\n\n/**\n * One flattened inventory owned by {@link composePacks}.\n *\n * `definitions` is a stable array identity, which is what the composition\n * schema cache keys on — pass it through rather than flattening packs per call.\n */\nexport interface ComposedPacks {\n readonly definitions: readonly AnyPrimitiveDefinition[];\n readonly enhancements: readonly EnhancementDefinition[];\n /** Every definition's `icon` by type, in one frozen null-prototype dictionary. */\n readonly icons: Readonly<Record<string, PrimitiveIcon>>;\n readonly slackAssetTypes: ReadonlySet<string>;\n}\n\n/**\n * Flattens `packs` into one inventory, rejecting cross-pack duplicate node\n * types and duplicate enhancement ids. Every offender is named in one error,\n * so a bad three-pack composition reports all three at once.\n */\nexport const composePacks = (\n packs: readonly AnyPrimitivePack[]\n): ComposedPacks => {\n const typeOwners = new Map<string, string[]>();\n const enhancementOwners = new Map<string, string[]>();\n for (const pack of packs) {\n for (const { type } of pack.primitives) {\n typeOwners.set(type, [...(typeOwners.get(type) ?? []), pack.id]);\n }\n for (const { id } of pack.enhancements) {\n enhancementOwners.set(id, [\n ...(enhancementOwners.get(id) ?? []),\n pack.id,\n ]);\n }\n }\n const repeated = [\n ...new Set(\n packs\n .map(({ id }) => id)\n .filter((id, index, ids) => ids.indexOf(id) !== index)\n ),\n ];\n if (repeated.length > 0) {\n throw new IsomerError(\n 'DUPLICATE_PACK_ID',\n `composePacks: ${repeated.map((id) => `\"${id}\"`).join(', ')} names more than one pack; pack ids must be unique`\n );\n }\n assertUnique('DUPLICATE_PRIMITIVE_TYPE', 'primitive type', typeOwners);\n assertUnique('DUPLICATE_ENHANCEMENT', 'enhancement', enhancementOwners);\n\n const definitions = packs.flatMap((pack) => [...pack.primitives]);\n return Object.freeze({\n definitions: Object.freeze(definitions),\n enhancements: Object.freeze(\n packs.flatMap((pack) => [...pack.enhancements])\n ),\n icons: iconsByType(definitions),\n slackAssetTypes: new Set(\n packs.flatMap((pack) => [...pack.slackAssetTypes])\n ),\n });\n};\n\nconst assertUnique = (\n code: 'DUPLICATE_ENHANCEMENT' | 'DUPLICATE_PRIMITIVE_TYPE',\n noun: string,\n owners: ReadonlyMap<string, readonly string[]>\n): void => {\n const duplicates = [...owners].filter(([, packs]) => packs.length > 1);\n if (duplicates.length === 0) {\n return;\n }\n throw new IsomerError(\n code,\n duplicates\n .map(\n ([key, packs]) =>\n `${noun} \"${key}\" registered by ${packs.map((id) => `\"${id}\"`).join(' and ')}`\n )\n .join('; ')\n );\n};\n"]}
|
package/dist/pack/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type HostCapabilities, describeCapabilities } from './capabilities.js';
|
|
1
|
+
export { type CapabilitySources, type HostCapabilities, type SurfaceSupport, describeCapabilities, } from './capabilities.js';
|
|
2
2
|
export { type ComposedPacks, composePacks } from './compose.js';
|
|
3
3
|
export { type EnhancementDefinition, scopeScript } from './enhancements.js';
|
|
4
4
|
export { type AnyPrimitivePack, type PackAuthoringOptions, type PackStyleAdapter, type PrimitiveGroup, type PrimitivePack, type PrimitivePackInput, definePrimitivePack, } from './primitive_pack.js';
|
package/dist/pack/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pack/index.ts"],"names":[],"mappings":"AAOA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pack/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,KAAK,qBAAqB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
|
package/dist/pack/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
5
|
* 2.0.
|
|
6
6
|
*/
|
|
7
|
-
export { describeCapabilities } from './capabilities.js';
|
|
7
|
+
export { describeCapabilities, } from './capabilities.js';
|
|
8
8
|
export { composePacks } from './compose.js';
|
|
9
9
|
export { scopeScript } from './enhancements.js';
|
|
10
10
|
export { definePrimitivePack, } from './primitive_pack.js';
|
package/dist/pack/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pack/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pack/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAIL,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAsB,YAAY,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAA8B,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAOL,mBAAmB,GACpB,MAAM,kBAAkB,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\nexport {\n type CapabilitySources,\n type HostCapabilities,\n type SurfaceSupport,\n describeCapabilities,\n} from './capabilities';\nexport { type ComposedPacks, composePacks } from './compose';\nexport { type EnhancementDefinition, scopeScript } from './enhancements';\nexport {\n type AnyPrimitivePack,\n type PackAuthoringOptions,\n type PackStyleAdapter,\n type PrimitiveGroup,\n type PrimitivePack,\n type PrimitivePackInput,\n definePrimitivePack,\n} from './primitive_pack';\n"]}
|
|
@@ -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
|
/**
|
|
@@ -98,7 +99,7 @@ export interface PrimitivePackInput {
|
|
|
98
99
|
* A pack as the runtime sees it.
|
|
99
100
|
*
|
|
100
101
|
* `TTheme` is the palette this pack's `react` renderers read as `env.theme`
|
|
101
|
-
* when drawn through the `
|
|
102
|
+
* when drawn through the `snapshot` surface — a *lower bound* on whatever theme
|
|
102
103
|
* the runtime holding it supplies. It is carried by
|
|
103
104
|
* {@link PrimitivePack.__theme} rather than by any real field, because
|
|
104
105
|
* `primitives` is erased to `AnyPrimitiveDefinition[]` and a heterogeneous
|
|
@@ -119,6 +120,12 @@ export interface PrimitivePack<TTheme = unknown> {
|
|
|
119
120
|
readonly primitives: readonly AnyPrimitiveDefinition[];
|
|
120
121
|
/** Node types this pack owns, for duplicate detection across packs. */
|
|
121
122
|
readonly types: ReadonlySet<string>;
|
|
123
|
+
/**
|
|
124
|
+
* Each primitive's `icon` by type, for the primitives that declare one, so a host listing them need not walk `primitives`.
|
|
125
|
+
*
|
|
126
|
+
* 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`.
|
|
127
|
+
*/
|
|
128
|
+
readonly icons?: Readonly<Record<string, PrimitiveIcon>>;
|
|
122
129
|
/** See {@link PrimitivePackInput.enhancements}. */
|
|
123
130
|
readonly enhancements: readonly EnhancementDefinition[];
|
|
124
131
|
/** See {@link PrimitivePackInput.slackAssetTypes}. */
|
|
@@ -148,8 +155,10 @@ export type AnyPrimitivePack = PrimitivePack<never>;
|
|
|
148
155
|
* Builds a {@link PrimitivePack}.
|
|
149
156
|
*
|
|
150
157
|
* `TTheme` is the palette a frame must supply for this pack's nodes to be drawn
|
|
151
|
-
* on the `
|
|
158
|
+
* on the `snapshot` surface: `definePrimitivePack<CoreTokens>(input)`. Omitted, it is
|
|
152
159
|
* `unknown`, which requires nothing.
|
|
153
160
|
*/
|
|
154
161
|
export declare const definePrimitivePack: <TTheme = unknown>(input: PrimitivePackInput) => PrimitivePack<TTheme>;
|
|
162
|
+
/** Each definition's `icon` by type, null-prototype so a type such as `__proto__` is an ordinary key. */
|
|
163
|
+
export declare const iconsByType: (primitives: readonly AnyPrimitiveDefinition[]) => Readonly<Record<string, PrimitiveIcon>>;
|
|
155
164
|
//# 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,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C,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"}
|
|
@@ -12,7 +12,7 @@ import { IsomerError } from '../composition/error.js';
|
|
|
12
12
|
* Builds a {@link PrimitivePack}.
|
|
13
13
|
*
|
|
14
14
|
* `TTheme` is the palette a frame must supply for this pack's nodes to be drawn
|
|
15
|
-
* on the `
|
|
15
|
+
* on the `snapshot` surface: `definePrimitivePack<CoreTokens>(input)`. Omitted, it is
|
|
16
16
|
* `unknown`, which requires nothing.
|
|
17
17
|
*/
|
|
18
18
|
export const definePrimitivePack = (input) => {
|
|
@@ -34,6 +34,7 @@ export const definePrimitivePack = (input) => {
|
|
|
34
34
|
surfaces: input.surfaces ?? [],
|
|
35
35
|
primitives: input.primitives,
|
|
36
36
|
types,
|
|
37
|
+
icons: iconsByType(input.primitives),
|
|
37
38
|
enhancements: input.enhancements ?? [],
|
|
38
39
|
slackAssetTypes: new Set(input.slackAssetTypes ?? []),
|
|
39
40
|
...(input.styleAdapter !== undefined
|
|
@@ -43,6 +44,16 @@ export const definePrimitivePack = (input) => {
|
|
|
43
44
|
...(input.authoring !== undefined ? { authoring: input.authoring } : {}),
|
|
44
45
|
};
|
|
45
46
|
};
|
|
47
|
+
/** Each definition's `icon` by type, null-prototype so a type such as `__proto__` is an ordinary key. */
|
|
48
|
+
export const iconsByType = (primitives) => {
|
|
49
|
+
const icons = Object.create(null);
|
|
50
|
+
for (const { type, icon } of primitives) {
|
|
51
|
+
if (icon !== undefined) {
|
|
52
|
+
icons[type] = icon;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return Object.freeze(icons);
|
|
56
|
+
};
|
|
46
57
|
/** Throws if `primitives` repeats a type. */
|
|
47
58
|
const assertUniquePrimitiveTypes = (id, primitives) => {
|
|
48
59
|
const seen = new Set();
|
|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G,EAAU,CAAC;IAClC,KAAK,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,MAAM,EAAE,CAAC;QAC/C,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,MAAM,IAAI,WAAW,CACnB,wBAAwB,EACxB,mBAAmB,EAAE,aAAa,KAAK,2BAA2B,IAAI,qCAAqC,CAC5G,CAAC;YACJ,CAAC;YACD,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtB,MAAM,IAAI,WAAW,CACnB,0BAA0B,EAC1B,mBAAmB,EAAE,sBAAsB,IAAI,oBAAoB,CACpE,CAAC;YACJ,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,mEAAmE;AACnE,MAAM,0BAA0B,GAAG,CACjC,EAAU,EACV,YAA8C,EACxC,EAAE;IACR,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;QACtC,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,WAAW,CACnB,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;AAsKnD;;;;;;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,KAAK,CAAC,CAAC;IAClE,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,eAAe,IAAI,EAAE,EAAE,CAAC;QAC/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CA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ACpB,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,mEAAmE;AACnE,MAAM,0BAA0B,GAAG,CACjC,EAAU,EACV,YAA8C,EACxC,EAAE;IACR,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;QACtC,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,WAAW,CACnB,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 { 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. */\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 `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 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 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 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"]}
|
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;;;;GAI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O,EAAE,OAAO,GAAG,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,CA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/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 `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,MA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ClC,IAAI,CAAC,GAAG,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"]}
|
|
@@ -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. */
|