@elastic/isomer-sdk 0.2.0 → 0.4.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.
Files changed (251) hide show
  1. package/NOTICE.txt +0 -286
  2. package/THIRD_PARTY_LICENSES.md +1 -885
  3. package/dist/author/authored_fields.d.ts +37 -12
  4. package/dist/author/authored_fields.d.ts.map +1 -1
  5. package/dist/author/authored_fields.js +45 -69
  6. package/dist/author/authored_fields.js.map +1 -1
  7. package/dist/author/authoring_input.d.ts.map +1 -1
  8. package/dist/author/authoring_input.js +12 -6
  9. package/dist/author/authoring_input.js.map +1 -1
  10. package/dist/author/authoring_model.d.ts +8 -2
  11. package/dist/author/authoring_model.d.ts.map +1 -1
  12. package/dist/author/authoring_model.js +67 -23
  13. package/dist/author/authoring_model.js.map +1 -1
  14. package/dist/author/declarations.d.ts.map +1 -1
  15. package/dist/author/declarations.js +45 -34
  16. package/dist/author/declarations.js.map +1 -1
  17. package/dist/author/index.d.ts +2 -1
  18. package/dist/author/index.d.ts.map +1 -1
  19. package/dist/author/index.js +2 -1
  20. package/dist/author/index.js.map +1 -1
  21. package/dist/author/jsx_shim.d.ts +49 -30
  22. package/dist/author/jsx_shim.d.ts.map +1 -1
  23. package/dist/author/jsx_shim.js +131 -40
  24. package/dist/author/jsx_shim.js.map +1 -1
  25. package/dist/author/print_jsx.d.ts +19 -0
  26. package/dist/author/print_jsx.d.ts.map +1 -0
  27. package/dist/author/print_jsx.js +372 -0
  28. package/dist/author/print_jsx.js.map +1 -0
  29. package/dist/author/prompt.d.ts +2 -2
  30. package/dist/author/prompt.d.ts.map +1 -1
  31. package/dist/author/prompt.js +7 -2
  32. package/dist/author/prompt.js.map +1 -1
  33. package/dist/author/schema_to_typescript.d.ts.map +1 -1
  34. package/dist/author/schema_to_typescript.js +6 -3
  35. package/dist/author/schema_to_typescript.js.map +1 -1
  36. package/dist/cjs/author/authored_fields.js +47 -70
  37. package/dist/cjs/author/authored_fields.js.map +1 -1
  38. package/dist/cjs/author/authoring_input.js +12 -6
  39. package/dist/cjs/author/authoring_input.js.map +1 -1
  40. package/dist/cjs/author/authoring_model.js +69 -24
  41. package/dist/cjs/author/authoring_model.js.map +1 -1
  42. package/dist/cjs/author/declarations.js +44 -33
  43. package/dist/cjs/author/declarations.js.map +1 -1
  44. package/dist/cjs/author/index.js +5 -1
  45. package/dist/cjs/author/index.js.map +1 -1
  46. package/dist/cjs/author/jsx_shim.js +130 -39
  47. package/dist/cjs/author/jsx_shim.js.map +1 -1
  48. package/dist/cjs/author/print_jsx.js +378 -0
  49. package/dist/cjs/author/print_jsx.js.map +1 -0
  50. package/dist/cjs/author/prompt.js +7 -2
  51. package/dist/cjs/author/prompt.js.map +1 -1
  52. package/dist/cjs/author/schema_to_typescript.js +6 -3
  53. package/dist/cjs/author/schema_to_typescript.js.map +1 -1
  54. package/dist/cjs/composition/error.js +2 -0
  55. package/dist/cjs/composition/error.js.map +1 -1
  56. package/dist/cjs/composition/structured_value.js.map +1 -1
  57. package/dist/cjs/define/index.js.map +1 -1
  58. package/dist/cjs/define/primitive_module.js +10 -4
  59. package/dist/cjs/define/primitive_module.js.map +1 -1
  60. package/dist/cjs/define/slack_blocks.js.map +1 -1
  61. package/dist/cjs/entries/index.js +5 -2
  62. package/dist/cjs/entries/index.js.map +1 -1
  63. package/dist/cjs/entries/markdown.js +3 -1
  64. package/dist/cjs/entries/markdown.js.map +1 -1
  65. package/dist/cjs/entries/react.js +2 -1
  66. package/dist/cjs/entries/react.js.map +1 -1
  67. package/dist/cjs/entries/slack.js +5 -1
  68. package/dist/cjs/entries/slack.js.map +1 -1
  69. package/dist/cjs/pack/enhancements.js.map +1 -1
  70. package/dist/cjs/pack/index.js +2 -1
  71. package/dist/cjs/pack/index.js.map +1 -1
  72. package/dist/cjs/pack/primitive_pack.js +14 -4
  73. package/dist/cjs/pack/primitive_pack.js.map +1 -1
  74. package/dist/cjs/render/format_number.js +2 -1
  75. package/dist/cjs/render/format_number.js.map +1 -1
  76. package/dist/cjs/render/html/envelope.js +12 -6
  77. package/dist/cjs/render/html/envelope.js.map +1 -1
  78. package/dist/cjs/render/markdown/blocks.js +82 -0
  79. package/dist/cjs/render/markdown/blocks.js.map +1 -0
  80. package/dist/cjs/render/markdown/builder.js +6 -2
  81. package/dist/cjs/render/markdown/builder.js.map +1 -1
  82. package/dist/cjs/render/markdown/format.js +46 -24
  83. package/dist/cjs/render/markdown/format.js.map +1 -1
  84. package/dist/cjs/render/markdown/host_tags.js +67 -0
  85. package/dist/cjs/render/markdown/host_tags.js.map +1 -0
  86. package/dist/cjs/render/markdown/index.js +5 -1
  87. package/dist/cjs/render/markdown/index.js.map +1 -1
  88. package/dist/cjs/render/markdown/split.js +325 -0
  89. package/dist/cjs/render/markdown/split.js.map +1 -0
  90. package/dist/cjs/render/primitive_dispatch.js +36 -6
  91. package/dist/cjs/render/primitive_dispatch.js.map +1 -1
  92. package/dist/cjs/render/react/content.js +3 -1
  93. package/dist/cjs/render/react/content.js.map +1 -1
  94. package/dist/cjs/render/react/index.js +3 -1
  95. package/dist/cjs/render/react/index.js.map +1 -1
  96. package/dist/cjs/render/react/markdown_content.js +143 -0
  97. package/dist/cjs/render/react/markdown_content.js.map +1 -0
  98. package/dist/cjs/render/slack/blocks.js +7 -0
  99. package/dist/cjs/render/slack/blocks.js.map +1 -1
  100. package/dist/cjs/render/slack/container.js +62 -0
  101. package/dist/cjs/render/slack/container.js.map +1 -0
  102. package/dist/cjs/render/slack/envelope.js +70 -14
  103. package/dist/cjs/render/slack/envelope.js.map +1 -1
  104. package/dist/cjs/render/slack/format.js +56 -6
  105. package/dist/cjs/render/slack/format.js.map +1 -1
  106. package/dist/cjs/render/slack/index.js +7 -1
  107. package/dist/cjs/render/slack/index.js.map +1 -1
  108. package/dist/cjs/render/slack/markdown_content.js +36 -77
  109. package/dist/cjs/render/slack/markdown_content.js.map +1 -1
  110. package/dist/cjs/render/slack/unmodeled.js +38 -0
  111. package/dist/cjs/render/slack/unmodeled.js.map +1 -0
  112. package/dist/cjs/testing/conformance.js +15 -1
  113. package/dist/cjs/testing/conformance.js.map +1 -1
  114. package/dist/cjs/testing/index.js +2 -1
  115. package/dist/cjs/testing/index.js.map +1 -1
  116. package/dist/cjs/validate/json_schema.js +10 -3
  117. package/dist/cjs/validate/json_schema.js.map +1 -1
  118. package/dist/cjs/validate/url.js +2 -1
  119. package/dist/cjs/validate/url.js.map +1 -1
  120. package/dist/composition/error.d.ts +2 -0
  121. package/dist/composition/error.d.ts.map +1 -1
  122. package/dist/composition/error.js +2 -0
  123. package/dist/composition/error.js.map +1 -1
  124. package/dist/composition/structured_value.d.ts +3 -3
  125. package/dist/composition/structured_value.d.ts.map +1 -1
  126. package/dist/composition/structured_value.js.map +1 -1
  127. package/dist/define/index.d.ts +1 -1
  128. package/dist/define/index.d.ts.map +1 -1
  129. package/dist/define/index.js.map +1 -1
  130. package/dist/define/primitive_module.d.ts +14 -5
  131. package/dist/define/primitive_module.d.ts.map +1 -1
  132. package/dist/define/primitive_module.js +10 -4
  133. package/dist/define/primitive_module.js.map +1 -1
  134. package/dist/define/slack_blocks.d.ts +31 -1
  135. package/dist/define/slack_blocks.d.ts.map +1 -1
  136. package/dist/define/slack_blocks.js.map +1 -1
  137. package/dist/entries/index.d.ts +2 -2
  138. package/dist/entries/index.d.ts.map +1 -1
  139. package/dist/entries/index.js +2 -2
  140. package/dist/entries/index.js.map +1 -1
  141. package/dist/entries/markdown.d.ts +1 -1
  142. package/dist/entries/markdown.d.ts.map +1 -1
  143. package/dist/entries/markdown.js +1 -1
  144. package/dist/entries/markdown.js.map +1 -1
  145. package/dist/entries/react.d.ts +1 -1
  146. package/dist/entries/react.d.ts.map +1 -1
  147. package/dist/entries/react.js +1 -1
  148. package/dist/entries/react.js.map +1 -1
  149. package/dist/entries/slack.d.ts +1 -1
  150. package/dist/entries/slack.d.ts.map +1 -1
  151. package/dist/entries/slack.js +1 -1
  152. package/dist/entries/slack.js.map +1 -1
  153. package/dist/pack/enhancements.d.ts +4 -0
  154. package/dist/pack/enhancements.d.ts.map +1 -1
  155. package/dist/pack/enhancements.js.map +1 -1
  156. package/dist/pack/index.d.ts +1 -1
  157. package/dist/pack/index.d.ts.map +1 -1
  158. package/dist/pack/index.js +1 -1
  159. package/dist/pack/index.js.map +1 -1
  160. package/dist/pack/primitive_pack.d.ts +3 -1
  161. package/dist/pack/primitive_pack.d.ts.map +1 -1
  162. package/dist/pack/primitive_pack.js +13 -3
  163. package/dist/pack/primitive_pack.js.map +1 -1
  164. package/dist/render/format_number.d.ts.map +1 -1
  165. package/dist/render/format_number.js +2 -1
  166. package/dist/render/format_number.js.map +1 -1
  167. package/dist/render/html/envelope.js +12 -6
  168. package/dist/render/html/envelope.js.map +1 -1
  169. package/dist/render/markdown/blocks.d.ts +6 -0
  170. package/dist/render/markdown/blocks.d.ts.map +1 -0
  171. package/dist/render/markdown/blocks.js +77 -0
  172. package/dist/render/markdown/blocks.js.map +1 -0
  173. package/dist/render/markdown/builder.d.ts +3 -0
  174. package/dist/render/markdown/builder.d.ts.map +1 -1
  175. package/dist/render/markdown/builder.js +3 -1
  176. package/dist/render/markdown/builder.js.map +1 -1
  177. package/dist/render/markdown/format.d.ts +2 -0
  178. package/dist/render/markdown/format.d.ts.map +1 -1
  179. package/dist/render/markdown/format.js +42 -22
  180. package/dist/render/markdown/format.js.map +1 -1
  181. package/dist/render/markdown/host_tags.d.ts +14 -0
  182. package/dist/render/markdown/host_tags.d.ts.map +1 -0
  183. package/dist/render/markdown/host_tags.js +63 -0
  184. package/dist/render/markdown/host_tags.js.map +1 -0
  185. package/dist/render/markdown/index.d.ts +2 -0
  186. package/dist/render/markdown/index.d.ts.map +1 -1
  187. package/dist/render/markdown/index.js +2 -0
  188. package/dist/render/markdown/index.js.map +1 -1
  189. package/dist/render/markdown/split.d.ts +32 -0
  190. package/dist/render/markdown/split.d.ts.map +1 -0
  191. package/dist/render/markdown/split.js +321 -0
  192. package/dist/render/markdown/split.js.map +1 -0
  193. package/dist/render/primitive_dispatch.d.ts +4 -2
  194. package/dist/render/primitive_dispatch.d.ts.map +1 -1
  195. package/dist/render/primitive_dispatch.js +36 -6
  196. package/dist/render/primitive_dispatch.js.map +1 -1
  197. package/dist/render/react/content.d.ts +1 -1
  198. package/dist/render/react/content.d.ts.map +1 -1
  199. package/dist/render/react/content.js +3 -1
  200. package/dist/render/react/content.js.map +1 -1
  201. package/dist/render/react/index.d.ts +1 -0
  202. package/dist/render/react/index.d.ts.map +1 -1
  203. package/dist/render/react/index.js +1 -0
  204. package/dist/render/react/index.js.map +1 -1
  205. package/dist/render/react/markdown_content.d.ts +9 -0
  206. package/dist/render/react/markdown_content.d.ts.map +1 -0
  207. package/dist/render/react/markdown_content.js +139 -0
  208. package/dist/render/react/markdown_content.js.map +1 -0
  209. package/dist/render/slack/blocks.d.ts +8 -1
  210. package/dist/render/slack/blocks.d.ts.map +1 -1
  211. package/dist/render/slack/blocks.js +7 -0
  212. package/dist/render/slack/blocks.js.map +1 -1
  213. package/dist/render/slack/container.d.ts +25 -0
  214. package/dist/render/slack/container.d.ts.map +1 -0
  215. package/dist/render/slack/container.js +55 -0
  216. package/dist/render/slack/container.js.map +1 -0
  217. package/dist/render/slack/envelope.d.ts +6 -4
  218. package/dist/render/slack/envelope.d.ts.map +1 -1
  219. package/dist/render/slack/envelope.js +71 -15
  220. package/dist/render/slack/envelope.js.map +1 -1
  221. package/dist/render/slack/format.d.ts +15 -3
  222. package/dist/render/slack/format.d.ts.map +1 -1
  223. package/dist/render/slack/format.js +54 -5
  224. package/dist/render/slack/format.js.map +1 -1
  225. package/dist/render/slack/index.d.ts +4 -2
  226. package/dist/render/slack/index.d.ts.map +1 -1
  227. package/dist/render/slack/index.js +2 -0
  228. package/dist/render/slack/index.js.map +1 -1
  229. package/dist/render/slack/markdown_content.d.ts +3 -2
  230. package/dist/render/slack/markdown_content.d.ts.map +1 -1
  231. package/dist/render/slack/markdown_content.js +27 -68
  232. package/dist/render/slack/markdown_content.js.map +1 -1
  233. package/dist/render/slack/unmodeled.d.ts +16 -0
  234. package/dist/render/slack/unmodeled.d.ts.map +1 -0
  235. package/dist/render/slack/unmodeled.js +32 -0
  236. package/dist/render/slack/unmodeled.js.map +1 -0
  237. package/dist/testing/conformance.d.ts +3 -1
  238. package/dist/testing/conformance.d.ts.map +1 -1
  239. package/dist/testing/conformance.js +14 -0
  240. package/dist/testing/conformance.js.map +1 -1
  241. package/dist/testing/index.d.ts +1 -1
  242. package/dist/testing/index.d.ts.map +1 -1
  243. package/dist/testing/index.js +1 -1
  244. package/dist/testing/index.js.map +1 -1
  245. package/dist/validate/json_schema.d.ts.map +1 -1
  246. package/dist/validate/json_schema.js +10 -3
  247. package/dist/validate/json_schema.js.map +1 -1
  248. package/dist/validate/url.d.ts.map +1 -1
  249. package/dist/validate/url.js +2 -1
  250. package/dist/validate/url.js.map +1 -1
  251. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"enhancements.js","sourceRoot":"","sources":["../../../src/pack/enhancements.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,gDAAmD;AAwCnD;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,CACjC,IAA8B,EAC9B,IAAqB,EACrB,WAA6C,EAC7C,SAA6B,EACJ,EAAE;IAC3B,MAAM,MAAM,GAAG,SAAS,IAAI,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;IAC/C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;QACvC,IACE,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACtB,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YACtC,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,EACjC,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAnBW,QAAA,mBAAmB,uBAmB9B;AAEF;;;GAGG;AACI,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,aAAa,IAAI,SAAS,CAAC;AAAnE,QAAA,WAAW,eAAwD;AAEhF,iEAAiE;AACpD,QAAA,yBAAyB,GAAG,oBAAoB,CAAC;AAE9D;;;;;;;;;;;GAWG;AACI,MAAM,oBAAoB,GAAG,CAAC,EAAU,EAAE,IAAa,EAAQ,EAAE;IACtE,6EAA6E;IAC7E,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,mBAAW,CACnB,0BAA0B,EAC1B,uFAAuF,CACxF,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,aAAa,CAAC,UAAU,iCAAyB,GAAG,CAAC,EAAE,CAAC;QAC/D,OAAO,CAAC,IAAI,CACV,mHAAmH,CACpH,CAAC;IACJ,CAAC;IACD,IAAI,EAAE,EAAE,CAAC;QACP,6GAA6G;QAC7G,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE,CAA4B,CAAC;QAChE,GAAG,CAAC,IAAI,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAlBW,QAAA,oBAAoB,wBAkB/B","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 type { ChildNodeWalker } from '../composition/body_node_base';\nimport { IsomerError } from '../composition/error';\nimport type { PrimitiveNode } from '../composition/node';\n\n/**\n * A progressive enhancement any vocabulary pack may declare.\n *\n * Ids are open strings rather than a closed union so a second pack can\n * register one without editing a shared type. Duplicate ids across packs in\n * one runtime are rejected at construction.\n */\nexport interface EnhancementDefinition {\n /** What a renderer tests for via `context.enhancements`. Unique across a runtime's packs. */\n id: string;\n /**\n * Whether this composition has anything for the enhancement to act on.\n * Gating on content rather than the opt-in alone is what keeps a composition\n * with no matching node from shipping the script.\n *\n * `walk` is the composition's child walker, so a match nested inside a\n * container from another pack is still found.\n */\n appliesTo: (body: readonly PrimitiveNode[], walk: ChildNodeWalker) => boolean;\n /**\n * A function body with `root: Element`, the render's `.isomer` section, in\n * scope. It runs in its own function, so a top-level `const` or `return`\n * cannot reach another enhancement. Absent when the host drives the\n * enhancement itself.\n *\n * It must not look for its root through `document.currentScript`, which is\n * `null` inside a shadow root. It must address markup through `data-*`\n * attributes rather than class names: class names are minified per render,\n * and a selector written against one is a contract nothing checks. An event\n * meant for the host sets `composed: true` as well as `bubbles: true`, or it\n * stops at a shadow boundary.\n */\n script?: string;\n /** Renders node anchors when resolved, for an enhancement that finds nodes with `findNodeElementPairs`. */\n anchors?: true;\n}\n\n/**\n * The `definitions` that apply to `body`, the first of each id, limited to\n * `requested` ids when given. The HTML and React surfaces both resolve through\n * it, so the two cannot disagree on which enhancements a render carries.\n */\nexport const resolveEnhancements = (\n body: readonly PrimitiveNode[],\n walk: ChildNodeWalker,\n definitions: readonly EnhancementDefinition[],\n requested?: readonly string[]\n): EnhancementDefinition[] => {\n const wanted = requested && new Set(requested);\n const ids = new Set<string>();\n return definitions.filter((definition) => {\n if (\n ids.has(definition.id) ||\n (wanted && !wanted.has(definition.id)) ||\n !definition.appliesTo(body, walk)\n ) {\n return false;\n }\n ids.add(definition.id);\n return true;\n });\n};\n\n/**\n * Wraps one script body in its own function, so its `const`s and a top-level\n * `return` stay its own. Anything that joins script bodies scopes each first.\n */\nexport const scopeScript = (body: string): string => `(() => {\\n${body}\\n})();`;\n\n/** Marks the `<script>` a `scripts: 'embedded'` render emits. */\nexport const EMBEDDED_SCRIPT_ATTRIBUTE = 'data-isomer-script';\n\n/**\n * Runs a `scripts: 'host'` render's `js` against the\n * `.isomer` section the host inserted.\n *\n * Needed wherever the HTML is inserted by the host rather than parsed with the\n * page, including every shadow root: such a `<script>` never runs, and one\n * that did would find no `document.currentScript`.\n *\n * Compiles with `new Function`, so a strict Content-Security-Policy must allow\n * `'unsafe-eval'`. A host that cannot should render with `scripts: 'embedded'`\n * into light DOM.\n */\nexport const runEnhancementScript = (js: string, root: Element): void => {\n // Guards untyped callers; typed ones already handled `querySelector`'s null.\n if (!root) {\n throw new IsomerError(\n 'ENHANCEMENT_ROOT_MISSING',\n 'runEnhancementScript: no root element; pass the `.isomer` section the render produced'\n );\n }\n if (root.querySelector(`script[${EMBEDDED_SCRIPT_ATTRIBUTE}]`)) {\n console.warn(\n \"isomer: this HTML was rendered with scripts: 'embedded'; render with scripts: 'host' so its enhancements run once\"\n );\n }\n if (js) {\n // eslint-disable-next-line @typescript-eslint/no-implied-eval -- compiling the render's script is the point.\n const run = new Function('root', js) as (root: Element) => void;\n run(root);\n }\n};\n"]}
1
+ {"version":3,"file":"enhancements.js","sourceRoot":"","sources":["../../../src/pack/enhancements.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,gDAAmD;AA4CnD;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,CACjC,IAA8B,EAC9B,IAAqB,EACrB,WAA6C,EAC7C,SAA6B,EACJ,EAAE;IAC3B,MAAM,MAAM,GAAG,SAAS,IAAI,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;IAC/C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;QACvC,IACE,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACtB,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YACtC,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,EACjC,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAnBW,QAAA,mBAAmB,uBAmB9B;AAEF;;;GAGG;AACI,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,aAAa,IAAI,SAAS,CAAC;AAAnE,QAAA,WAAW,eAAwD;AAEhF,iEAAiE;AACpD,QAAA,yBAAyB,GAAG,oBAAoB,CAAC;AAE9D;;;;;;;;;;;GAWG;AACI,MAAM,oBAAoB,GAAG,CAAC,EAAU,EAAE,IAAa,EAAQ,EAAE;IACtE,6EAA6E;IAC7E,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,mBAAW,CACnB,0BAA0B,EAC1B,uFAAuF,CACxF,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,aAAa,CAAC,UAAU,iCAAyB,GAAG,CAAC,EAAE,CAAC;QAC/D,OAAO,CAAC,IAAI,CACV,mHAAmH,CACpH,CAAC;IACJ,CAAC;IACD,IAAI,EAAE,EAAE,CAAC;QACP,6GAA6G;QAC7G,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE,CAA4B,CAAC;QAChE,GAAG,CAAC,IAAI,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAlBW,QAAA,oBAAoB,wBAkB/B","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 type { ChildNodeWalker } from '../composition/body_node_base';\nimport { IsomerError } from '../composition/error';\nimport type { PrimitiveNode } from '../composition/node';\n\n/**\n * A progressive enhancement any vocabulary pack may declare.\n *\n * Ids are open strings rather than a closed union so a second pack can\n * register one without editing a shared type. Duplicate ids across packs in\n * one runtime are rejected at construction.\n */\nexport interface EnhancementDefinition {\n /** What a renderer tests for via `context.enhancements`. Unique across a runtime's packs. */\n id: string;\n /** Short label for hosts; when omitted, use {@link EnhancementDefinition.id}. */\n name?: string;\n /** What enabling the enhancement does, for host UI and authoring material. */\n description?: string;\n /**\n * Whether this composition has anything for the enhancement to act on.\n * Gating on content rather than the opt-in alone is what keeps a composition\n * with no matching node from shipping the script.\n *\n * `walk` is the composition's child walker, so a match nested inside a\n * container from another pack is still found.\n */\n appliesTo: (body: readonly PrimitiveNode[], walk: ChildNodeWalker) => boolean;\n /**\n * A function body with `root: Element`, the render's `.isomer` section, in\n * scope. It runs in its own function, so a top-level `const` or `return`\n * cannot reach another enhancement. Absent when the host drives the\n * enhancement itself.\n *\n * It must not look for its root through `document.currentScript`, which is\n * `null` inside a shadow root. It must address markup through `data-*`\n * attributes rather than class names: class names are minified per render,\n * and a selector written against one is a contract nothing checks. An event\n * meant for the host sets `composed: true` as well as `bubbles: true`, or it\n * stops at a shadow boundary.\n */\n script?: string;\n /** Renders node anchors when resolved, for an enhancement that finds nodes with `findNodeElementPairs`. */\n anchors?: true;\n}\n\n/**\n * The `definitions` that apply to `body`, the first of each id, limited to\n * `requested` ids when given. The HTML and React surfaces both resolve through\n * it, so the two cannot disagree on which enhancements a render carries.\n */\nexport const resolveEnhancements = (\n body: readonly PrimitiveNode[],\n walk: ChildNodeWalker,\n definitions: readonly EnhancementDefinition[],\n requested?: readonly string[]\n): EnhancementDefinition[] => {\n const wanted = requested && new Set(requested);\n const ids = new Set<string>();\n return definitions.filter((definition) => {\n if (\n ids.has(definition.id) ||\n (wanted && !wanted.has(definition.id)) ||\n !definition.appliesTo(body, walk)\n ) {\n return false;\n }\n ids.add(definition.id);\n return true;\n });\n};\n\n/**\n * Wraps one script body in its own function, so its `const`s and a top-level\n * `return` stay its own. Anything that joins script bodies scopes each first.\n */\nexport const scopeScript = (body: string): string => `(() => {\\n${body}\\n})();`;\n\n/** Marks the `<script>` a `scripts: 'embedded'` render emits. */\nexport const EMBEDDED_SCRIPT_ATTRIBUTE = 'data-isomer-script';\n\n/**\n * Runs a `scripts: 'host'` render's `js` against the\n * `.isomer` section the host inserted.\n *\n * Needed wherever the HTML is inserted by the host rather than parsed with the\n * page, including every shadow root: such a `<script>` never runs, and one\n * that did would find no `document.currentScript`.\n *\n * Compiles with `new Function`, so a strict Content-Security-Policy must allow\n * `'unsafe-eval'`. A host that cannot should render with `scripts: 'embedded'`\n * into light DOM.\n */\nexport const runEnhancementScript = (js: string, root: Element): void => {\n // Guards untyped callers; typed ones already handled `querySelector`'s null.\n if (!root) {\n throw new IsomerError(\n 'ENHANCEMENT_ROOT_MISSING',\n 'runEnhancementScript: no root element; pass the `.isomer` section the render produced'\n );\n }\n if (root.querySelector(`script[${EMBEDDED_SCRIPT_ATTRIBUTE}]`)) {\n console.warn(\n \"isomer: this HTML was rendered with scripts: 'embedded'; render with scripts: 'host' so its enhancements run once\"\n );\n }\n if (js) {\n // eslint-disable-next-line @typescript-eslint/no-implied-eval -- compiling the render's script is the point.\n const run = new Function('root', js) as (root: Element) => void;\n run(root);\n }\n};\n"]}
@@ -6,7 +6,7 @@
6
6
  * 2.0.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.definePrimitivePack = exports.scopeScript = exports.composePacks = exports.describeCapabilities = void 0;
9
+ exports.definePrimitivePack = exports.UNCATEGORIZED_GROUP_TITLE = exports.scopeScript = exports.composePacks = exports.describeCapabilities = void 0;
10
10
  var capabilities_1 = require("./capabilities");
11
11
  Object.defineProperty(exports, "describeCapabilities", { enumerable: true, get: function () { return capabilities_1.describeCapabilities; } });
12
12
  var compose_1 = require("./compose");
@@ -14,5 +14,6 @@ Object.defineProperty(exports, "composePacks", { enumerable: true, get: function
14
14
  var enhancements_1 = require("./enhancements");
15
15
  Object.defineProperty(exports, "scopeScript", { enumerable: true, get: function () { return enhancements_1.scopeScript; } });
16
16
  var primitive_pack_1 = require("./primitive_pack");
17
+ Object.defineProperty(exports, "UNCATEGORIZED_GROUP_TITLE", { enumerable: true, get: function () { return primitive_pack_1.UNCATEGORIZED_GROUP_TITLE; } });
17
18
  Object.defineProperty(exports, "definePrimitivePack", { enumerable: true, get: function () { return primitive_pack_1.definePrimitivePack; } });
18
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pack/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+CAKwB;AADtB,oHAAA,oBAAoB,OAAA;AAEtB,qCAA6D;AAAhC,uGAAA,YAAY,OAAA;AACzC,+CAAyE;AAApC,2GAAA,WAAW,OAAA;AAChD,mDAQ0B;AADxB,qHAAA,mBAAmB,OAAA","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
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pack/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+CAKwB;AADtB,oHAAA,oBAAoB,OAAA;AAEtB,qCAA6D;AAAhC,uGAAA,YAAY,OAAA;AACzC,+CAAyE;AAApC,2GAAA,WAAW,OAAA;AAChD,mDAS0B;AAFxB,2HAAA,yBAAyB,OAAA;AACzB,qHAAA,mBAAmB,OAAA","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 UNCATEGORIZED_GROUP_TITLE,\n definePrimitivePack,\n} from './primitive_pack';\n"]}
@@ -6,11 +6,13 @@
6
6
  * 2.0.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.iconsByType = exports.definePrimitivePack = void 0;
9
+ exports.iconsByType = exports.definePrimitivePack = exports.UNCATEGORIZED_GROUP_TITLE = void 0;
10
10
  // A primitive pack as a value: a vocabulary, and the optional surfaces every
11
11
  // primitive in it implements. Additive: a runtime composes any number of packs,
12
12
  // and nothing about a pack decides how a composition is framed.
13
13
  const error_1 = require("../composition/error");
14
+ /** The index heading for primitives in no group. A pack cannot declare a group with this title. */
15
+ exports.UNCATEGORIZED_GROUP_TITLE = 'Uncategorized';
14
16
  /**
15
17
  * Builds a {@link PrimitivePack}.
16
18
  *
@@ -25,7 +27,7 @@ const definePrimitivePack = (input) => {
25
27
  assertUniquePrimitiveTypes(input.id, input.primitives);
26
28
  assertUniqueEnhancementIds(input.id, input.enhancements ?? []);
27
29
  const types = new Set(input.primitives.map((definition) => definition.type));
28
- assertGroupedOnce(input.id, input.authoring?.groups ?? [], types);
30
+ assertValidGroups(input.id, input.authoring?.groups ?? [], types);
29
31
  for (const type of input.slackAssetTypes ?? []) {
30
32
  if (!types.has(type)) {
31
33
  throw new error_1.IsomerError('UNKNOWN_PRIMITIVE_TYPE', `primitive pack "${input.id}": slackAssetTypes names primitive type "${type}", which the pack does not register`);
@@ -69,10 +71,18 @@ const assertUniquePrimitiveTypes = (id, primitives) => {
69
71
  seen.add(type);
70
72
  }
71
73
  };
72
- /** Throws if a group names a type outside `types`, or two groups share a type. */
73
- const assertGroupedOnce = (id, groups, types) => {
74
+ /** Throws if a group repeats or reserves a title, names a type outside `types`, or shares a type with another. */
75
+ const assertValidGroups = (id, groups, types) => {
76
+ const titles = new Set();
74
77
  const grouped = new Set();
75
78
  for (const { title, types: members } of groups) {
79
+ if (title === exports.UNCATEGORIZED_GROUP_TITLE) {
80
+ throw new error_1.IsomerError('INVALID_PACK_GROUPS', `primitive pack "${id}": group title "${title}" is reserved for primitives in no group`);
81
+ }
82
+ if (titles.has(title)) {
83
+ throw new error_1.IsomerError('INVALID_PACK_GROUPS', `primitive pack "${id}": group title "${title}" is used twice`);
84
+ }
85
+ titles.add(title);
76
86
  for (const type of members) {
77
87
  if (!types.has(type)) {
78
88
  throw new error_1.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,gDAAmD;AAsKnD;;;;;;GAMG;AACI,MAAM,mBAAmB,GAAG,CACjC,KAAyB,EACF,EAAE;IACzB,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,mBAAW,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,CAA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AAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,MAAM,IAAI,mBAAW,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,mBAAW,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,mBAAW,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"]}
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,gDAAmD;AAiCnD,mGAAmG;AACtF,QAAA,yBAAyB,GAAG,eAAe,CAAC;AAuIzD;;;;;;GAMG;AACI,MAAM,mBAAmB,GAAG,CACjC,KAAyB,EACF,EAAE;IACzB,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,mBAAW,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,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AAE,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"]}
@@ -31,8 +31,9 @@ const trimDecimal = (value, precision) => Number.isInteger(value)
31
31
  const formatCompactNumber = (value, unit = '', precision = 1) => {
32
32
  const abs = Math.abs(value);
33
33
  let index = TIERS.findIndex(({ size }) => abs >= size);
34
- if (index === -1)
34
+ if (index === -1) {
35
35
  index = TIERS.length - 1;
36
+ }
36
37
  // A value that rounds up to the tier's next power, `999.96k`, reads as `1m`.
37
38
  if (index > 0 &&
38
39
  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,EAAE;IAC5B,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;CACf,CAAC;AAEX,2DAA2D;AAC3D,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,SAAiB,EAAU,EAAE,CAC/D,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;IACrB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IACf,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAE/C;;;;;;GAMG;AACI,MAAM,mBAAmB,GAAG,CACjC,KAAa,EACb,IAAI,GAAG,EAAE,EACT,SAAS,GAAG,CAAC,EACL,EAAE;IACV,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5B,IAAI,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;IACvD,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3C,6EAA6E;IAC7E,IACE,KAAK,GAAG,CAAC;QACT,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,EAC1E,CAAC;QACD,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,CAAE,CAAC;IACvC,MAAM,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,GAAG,IAAI,EAAE,SAAS,CAAC,GAAG,MAAM,EAAE,CAAC;IAElE,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,EAAE,CAAC;AAC7E,CAAC,CAAC;AAnBW,QAAA,mBAAmB,uBAmB9B","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) index = TIERS.length - 1;\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"]}
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,EAAE;IAC5B,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;CACf,CAAC;AAEX,2DAA2D;AAC3D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,GAAG,GAAG,IAAI,EAAE,CAAC;AAC7E,CAAC,CAAC;AArBW,QAAA,mBAAmB,uBAqB9B","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"]}
@@ -112,8 +112,9 @@ exports.renderHTMLWithDispatcher = renderHTMLWithDispatcher;
112
112
  const embedCss = (css) => css.replace(/<\/(?=style)/gi, '<\\/');
113
113
  // Tagged templates observe raw spelling and reuse the same frozen object per site.
114
114
  const embedJs = (js) => {
115
- if (!/<\/script|<!--/i.test(js))
115
+ if (!/<\/script|<!--/i.test(js)) {
116
116
  return js;
117
+ }
117
118
  const comments = [];
118
119
  const tree = (0, acorn_1.parse)(js, { ecmaVersion: 'latest', onComment: comments });
119
120
  const sites = [];
@@ -121,11 +122,13 @@ const embedJs = (js) => {
121
122
  const pending = [tree];
122
123
  while (pending.length) {
123
124
  const node = pending.pop();
124
- if (node.type === 'Identifier' && node.name)
125
+ if (node.type === 'Identifier' && node.name) {
125
126
  identifiers.add(node.name);
127
+ }
126
128
  if (node.type === 'TaggedTemplateExpression' &&
127
- node.quasi.quasis.some(({ value: { raw } }) => /<\/script|<!--/i.test(raw)))
129
+ node.quasi.quasis.some(({ value: { raw } }) => /<\/script|<!--/i.test(raw))) {
128
130
  sites.push(node);
131
+ }
129
132
  for (const value of Object.values(node)) {
130
133
  for (const child of Array.isArray(value) ? value : [value]) {
131
134
  if (child &&
@@ -139,8 +142,9 @@ const embedJs = (js) => {
139
142
  }
140
143
  sites.sort((a, b) => a.start - b.start);
141
144
  let prefix = '__isomerTemplate';
142
- while ([...identifiers].some((name) => name.startsWith(prefix)))
145
+ while ([...identifiers].some((name) => name.startsWith(prefix))) {
143
146
  prefix += '_';
147
+ }
144
148
  const literal = (value) => value === null ? 'void 0' : JSON.stringify(value).replace(/</g, '\\u003c');
145
149
  const rewrite = (start, end) => {
146
150
  let cursor = start;
@@ -156,8 +160,9 @@ const embedJs = (js) => {
156
160
  .map((comment) => ({ ...comment, index: -1, comment: comment.value })),
157
161
  ].sort((a, b) => a.start - b.start);
158
162
  for (const edit of edits) {
159
- if (edit.start < cursor || edit.end > end)
163
+ if (edit.start < cursor || edit.end > end) {
160
164
  continue;
165
+ }
161
166
  result += js.slice(cursor, edit.start);
162
167
  if (edit.comment !== undefined) {
163
168
  result += `//${edit.comment}`;
@@ -188,8 +193,9 @@ const embedJs = (js) => {
188
193
  };
189
194
  const escapedBy = (source, at) => {
190
195
  let slashes = 0;
191
- while (source[at - slashes - 1] === '\\')
196
+ while (source[at - slashes - 1] === '\\') {
192
197
  slashes += 1;
198
+ }
193
199
  return slashes % 2 === 1;
194
200
  };
195
201
  const RenderedHtmlView = ({ composition, theme, fluid, framed, styleText, scriptText, defaultAriaLabel, body, }) => (0, content_1.wrapCompositionContent)((0, react_1.createElement)(react_1.Fragment, null, styleText
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../../../src/render/html/envelope.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iCAAgE;AAChE,6CAAwD;AACxD,iCAIe;AAEf,qEAG0C;AAY1C,0DAIiC;AACjC,0DAMmC;AACnC,wCAAyC;AACzC,kDAA8C;AAC9C,wCAAiE;AACjE,8CAI0B;AAE1B,iDAIwB;AAqNxB;;;;;;;GAOG;AACI,MAAM,wBAAwB,GAAG,CAKtC,KAAyB,EACzB,EACE,UAAU,EACV,QAAQ,GAAG,IAAA,uCAA0B,EAAQ,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,IAAA,gCAAmB,EAAC,UAAU,CAAC,CAAC;IACpD,wEAAwE;IACxE,uBAAuB;IACvB,MAAM,OAAO,GACX,YAAY,EAAE,cAAc,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,IAAI,UAAU,CAAC;IACxE,IAAA,kCAAqB,EAAC,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC;IACtC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC;IACxC,MAAM,KAAK,GAAG,OAAO,CA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AAa,EAAC,QAAQ,EAAE;QACtB,GAAG,EAAE,QAAQ;QACb,CAAC,wCAAyB,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 `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)) 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,iCAAgE;AAChE,6CAAwD;AACxD,iCAIe;AAEf,qEAG0C;AAY1C,0DAIiC;AACjC,0DAMmC;AACnC,wCAAyC;AACzC,kDAA8C;AAC9C,wCAAiE;AACjE,8CAI0B;AAE1B,iDAIwB;AAqNxB;;;;;;;GAOG;AACI,MAAM,wBAAwB,GAAG,CAKtC,KAAyB,EACzB,EACE,UAAU,EACV,QAAQ,GAAG,IAAA,uCAA0B,EAAQ,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,IAAA,gCAAmB,EAAC,UAAU,CAAC,CAAC;IACpD,wEAAwE;IACxE,uBAAuB;IACvB,MAAM,OAAO,GACX,YAAY,EAAE,cAAc,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,IAAI,UAAU,CAAC;IACxE,IAAA,kCAAqB,EAAC,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC;IACtC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IA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CAAC,CAAC,IAAI,EACR,IAAA,qBAAa,EAAC,KAAK,EAAE;IACnB,GAAG,EAAE,MAAM;IACX,uBAAuB,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;CAC1C,CAAC,EACF,UAAU;IACR,CAAC,CAAC,IAAA,qBAAa,EAAC,QAAQ,EAAE;QACtB,GAAG,EAAE,QAAQ;QACb,CAAC,wCAAyB,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 `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"]}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
+ * or more contributor license agreements. Licensed under the Elastic License
5
+ * 2.0; you may not use this file except in compliance with the Elastic License
6
+ * 2.0.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.resolvedMarkdownBlocks = exports.gfmBlocks = void 0;
10
+ const builder_1 = require("./builder");
11
+ const format_1 = require("./format");
12
+ // Each reference resolved to its document's first definition.
13
+ const withReferences = (blocks) => {
14
+ const definitions = new Map();
15
+ const collect = (node) => {
16
+ if (node.type === 'definition' && !definitions.has(node.identifier)) {
17
+ definitions.set(node.identifier, node);
18
+ }
19
+ if ('children' in node) {
20
+ node.children.forEach(collect);
21
+ }
22
+ };
23
+ blocks.forEach(collect);
24
+ if (definitions.size === 0) {
25
+ return [...blocks];
26
+ }
27
+ const resolve = (node) => {
28
+ switch (node.type) {
29
+ case 'linkReference':
30
+ return {
31
+ type: 'link',
32
+ url: definitions.get(node.identifier)?.url ?? '',
33
+ title: definitions.get(node.identifier)?.title,
34
+ children: node.children.map(resolve),
35
+ };
36
+ case 'imageReference':
37
+ return {
38
+ type: 'image',
39
+ url: definitions.get(node.identifier)?.url ?? '',
40
+ title: definitions.get(node.identifier)?.title,
41
+ alt: node.alt ?? null,
42
+ };
43
+ default:
44
+ return 'children' in node
45
+ ? { ...node, children: node.children.map(resolve) }
46
+ : node;
47
+ }
48
+ };
49
+ return blocks.map(resolve);
50
+ };
51
+ const lines = (text) => text.replace(/\r\n?/g, '\n');
52
+ const literalParagraphs = (text) => lines(text)
53
+ .split(/\n[ \t]*\n/)
54
+ .filter((paragraph) => paragraph.trim() !== '')
55
+ .map((paragraph) => ({
56
+ type: 'paragraph',
57
+ children: [{ type: 'text', value: paragraph.trim() }],
58
+ }));
59
+ const parsedBlocks = (gfm) => {
60
+ const parsed = (0, format_1.parseGfmBlocks)(lines(gfm));
61
+ return parsed === null ? literalParagraphs(gfm) : withReferences(parsed);
62
+ };
63
+ /** GFM as mdast blocks with references resolved, typed `unknown[]` so no declaration names mdast; source past the parse budget is its literal paragraphs. */
64
+ const gfmBlocks = (gfm) => parsedBlocks(gfm);
65
+ exports.gfmBlocks = gfmBlocks;
66
+ // Markdown printed as written is read as the GFM it holds; authored source
67
+ // that sanitizing left inert is never parsed.
68
+ const expanded = (node) => {
69
+ if (node.type === builder_1.VERBATIM_TYPE) {
70
+ const { value, source } = node;
71
+ return source === undefined
72
+ ? parsedBlocks(value)
73
+ : literalParagraphs(source);
74
+ }
75
+ return 'children' in node
76
+ ? [{ ...node, children: node.children.flatMap(expanded) }]
77
+ : [node];
78
+ };
79
+ /** `content` as flat mdast blocks with authored source parsed, typed `unknown[]` so no declaration names mdast. */
80
+ const resolvedMarkdownBlocks = (content) => (0, builder_1.markdownBlocks)(content).flatMap(expanded);
81
+ exports.resolvedMarkdownBlocks = resolvedMarkdownBlocks;
82
+ //# sourceMappingURL=blocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocks.js","sourceRoot":"","sources":["../../../../src/render/markdown/blocks.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AASH,uCAA0D;AAC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AG,CAAC,GAAW,EAAsB,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;AAAnE,QAAA,SAAS,aAA0D;AAEhF,2EAA2E;AAC3E,8CAA8C;AAC9C,MAAM,QAAQ,GAAG,CAAC,IAAW,EAAW,EAAE;IACxC,IAAK,IAAI,CAAC,IAAe,KAAK,uBAAa,EAAE,CAAC;QAC5C,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAGzB,CAAC;QACF,OAAO,MAAM,KAAK,SAAS;YACzB,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC;YACrB,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,UAAU,IAAI,IAAI;QACvB,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAW,CAAC;QACnE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACb,CAAC,CAAC;AAEF,mHAAmH;AAC5G,MAAM,sBAAsB,GAAG,CACpC,OAAwB,EACJ,EAAE,CACrB,IAAA,wBAAc,EAAC,OAAO,CAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAHlD,QAAA,sBAAsB,0BAG4B","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// The mdast blocks behind builder content, shared by the Slack and React\n// translations so both read one parse.\n\nimport type { Definition, Nodes, PhrasingContent, RootContent } from 'mdast';\n\nimport type { MarkdownContent } from '../../define/markdown_content';\n\nimport { markdownBlocks, VERBATIM_TYPE } from './builder';\nimport { parseGfmBlocks } from './format';\n\n// Each reference resolved to its document's first definition.\nconst withReferences = (blocks: readonly RootContent[]): RootContent[] => {\n const definitions = new Map<string, Definition>();\n const collect = (node: Nodes): void => {\n if (node.type === 'definition' && !definitions.has(node.identifier)) {\n definitions.set(node.identifier, node);\n }\n if ('children' in node) {\n node.children.forEach(collect);\n }\n };\n blocks.forEach(collect);\n if (definitions.size === 0) {\n return [...blocks];\n }\n const resolve = (node: Nodes): Nodes => {\n switch (node.type) {\n case 'linkReference':\n return {\n type: 'link',\n url: definitions.get(node.identifier)?.url ?? '',\n title: definitions.get(node.identifier)?.title,\n children: node.children.map(resolve) as PhrasingContent[],\n };\n case 'imageReference':\n return {\n type: 'image',\n url: definitions.get(node.identifier)?.url ?? '',\n title: definitions.get(node.identifier)?.title,\n alt: node.alt ?? null,\n };\n default:\n return 'children' in node\n ? ({ ...node, children: node.children.map(resolve) } as Nodes)\n : node;\n }\n };\n return blocks.map(resolve) as RootContent[];\n};\n\nconst lines = (text: string): string => text.replace(/\\r\\n?/g, '\\n');\n\nconst literalParagraphs = (text: string): RootContent[] =>\n lines(text)\n .split(/\\n[ \\t]*\\n/)\n .filter((paragraph) => paragraph.trim() !== '')\n .map((paragraph) => ({\n type: 'paragraph',\n children: [{ type: 'text', value: paragraph.trim() }],\n }));\n\nconst parsedBlocks = (gfm: string): RootContent[] => {\n const parsed = parseGfmBlocks(lines(gfm)) as RootContent[] | null;\n return parsed === null ? literalParagraphs(gfm) : withReferences(parsed);\n};\n\n/** GFM as mdast blocks with references resolved, typed `unknown[]` so no declaration names mdast; source past the parse budget is its literal paragraphs. */\nexport const gfmBlocks = (gfm: string): readonly unknown[] => parsedBlocks(gfm);\n\n// Markdown printed as written is read as the GFM it holds; authored source\n// that sanitizing left inert is never parsed.\nconst expanded = (node: Nodes): Nodes[] => {\n if ((node.type as string) === VERBATIM_TYPE) {\n const { value, source } = node as unknown as {\n value: string;\n source?: string;\n };\n return source === undefined\n ? parsedBlocks(value)\n : literalParagraphs(source);\n }\n return 'children' in node\n ? [{ ...node, children: node.children.flatMap(expanded) } as Nodes]\n : [node];\n};\n\n/** `content` as flat mdast blocks with authored source parsed, typed `unknown[]` so no declaration names mdast. */\nexport const resolvedMarkdownBlocks = (\n content: MarkdownContent\n): readonly unknown[] =>\n (markdownBlocks(content) as RootContent[]).flatMap(expanded);\n"]}
@@ -6,7 +6,7 @@
6
6
  * 2.0.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.serializeMarkdown = exports.markdownBlocks = exports.md = exports.VERBATIM_TYPE = void 0;
9
+ exports.serializeMarkdown = exports.markdownBlocks = exports.printParsed = exports.md = exports.verbatim = exports.VERBATIM_TYPE = void 0;
10
10
  const mdast_util_gfm_1 = require("mdast-util-gfm");
11
11
  const mdast_util_to_markdown_1 = require("mdast-util-to-markdown");
12
12
  const one_line_1 = require("../../composition/one_line");
@@ -66,6 +66,7 @@ const verbatim = (markdown, source) => block({
66
66
  value: markdown.trimEnd(),
67
67
  ...(source === undefined ? {} : { source }),
68
68
  });
69
+ exports.verbatim = verbatim;
69
70
  // An empty wrapper prints its markers alone: `****` reads as a thematic break.
70
71
  const wrapper = (type, inputs) => {
71
72
  const children = inlineChildren(inputs);
@@ -156,7 +157,7 @@ exports.md = {
156
157
  return [];
157
158
  }
158
159
  const { markdown, inert } = (0, format_1.sanitizeAuthoredSource)(source);
159
- return verbatim(markdown, inert ? source : undefined);
160
+ return (0, exports.verbatim)(markdown, inert ? source : undefined);
160
161
  },
161
162
  };
162
163
  const asText = (node, ...rest) => mdast_util_to_markdown_1.defaultHandlers.text({ type: 'text', value: node.value ?? node.alt ?? '' }, ...rest);
@@ -186,6 +187,9 @@ const OPTIONS = {
186
187
  extensions: [(0, mdast_util_gfm_1.gfmToMarkdown)({ tablePipeAlign: false })],
187
188
  handlers: handlers,
188
189
  };
190
+ /** Parsed mdast blocks as GFM, unsanitized, for `md.authored` to sanitize as it sanitizes source. */
191
+ const printParsed = (nodes) => (0, mdast_util_to_markdown_1.toMarkdown)({ type: 'root', children: nodes }, { ...OPTIONS, handlers: {} }).replace(/\n$/, '');
192
+ exports.printParsed = printParsed;
189
193
  /** `content` as flat mdast blocks, typed `unknown` so no declaration names mdast. */
190
194
  const markdownBlocks = (content) => rootContent(content);
191
195
  exports.markdownBlocks = markdownBlocks;