@elastic/isomer-sdk 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/NOTICE.txt +0 -286
  2. package/README.md +13 -2
  3. package/THIRD_PARTY_LICENSES.md +1 -885
  4. package/dist/author/authored_fields.d.ts +93 -18
  5. package/dist/author/authored_fields.d.ts.map +1 -1
  6. package/dist/author/authored_fields.js +63 -43
  7. package/dist/author/authored_fields.js.map +1 -1
  8. package/dist/author/authoring_input.d.ts +7 -0
  9. package/dist/author/authoring_input.d.ts.map +1 -0
  10. package/dist/author/authoring_input.js +66 -0
  11. package/dist/author/authoring_input.js.map +1 -0
  12. package/dist/author/authoring_model.d.ts +33 -0
  13. package/dist/author/authoring_model.d.ts.map +1 -0
  14. package/dist/author/authoring_model.js +142 -0
  15. package/dist/author/authoring_model.js.map +1 -0
  16. package/dist/author/declarations.d.ts +13 -0
  17. package/dist/author/declarations.d.ts.map +1 -0
  18. package/dist/author/declarations.js +288 -0
  19. package/dist/author/declarations.js.map +1 -0
  20. package/dist/author/index.d.ts +4 -1
  21. package/dist/author/index.d.ts.map +1 -1
  22. package/dist/author/index.js +4 -1
  23. package/dist/author/index.js.map +1 -1
  24. package/dist/author/jsx_shim.d.ts +50 -30
  25. package/dist/author/jsx_shim.d.ts.map +1 -1
  26. package/dist/author/jsx_shim.js +146 -138
  27. package/dist/author/jsx_shim.js.map +1 -1
  28. package/dist/author/print_jsx.d.ts +19 -0
  29. package/dist/author/print_jsx.d.ts.map +1 -0
  30. package/dist/author/print_jsx.js +372 -0
  31. package/dist/author/print_jsx.js.map +1 -0
  32. package/dist/author/prompt.d.ts +2 -2
  33. package/dist/author/prompt.d.ts.map +1 -1
  34. package/dist/author/prompt.js +7 -2
  35. package/dist/author/prompt.js.map +1 -1
  36. package/dist/author/schema_to_typescript.d.ts +37 -0
  37. package/dist/author/schema_to_typescript.d.ts.map +1 -0
  38. package/dist/author/schema_to_typescript.js +289 -0
  39. package/dist/author/schema_to_typescript.js.map +1 -0
  40. package/dist/cjs/author/authored_fields.js +68 -47
  41. package/dist/cjs/author/authored_fields.js.map +1 -1
  42. package/dist/cjs/author/authoring_input.js +70 -0
  43. package/dist/cjs/author/authoring_input.js.map +1 -0
  44. package/dist/cjs/author/authoring_model.js +149 -0
  45. package/dist/cjs/author/authoring_model.js.map +1 -0
  46. package/dist/cjs/author/declarations.js +292 -0
  47. package/dist/cjs/author/declarations.js.map +1 -0
  48. package/dist/cjs/author/index.js +10 -1
  49. package/dist/cjs/author/index.js.map +1 -1
  50. package/dist/cjs/author/jsx_shim.js +148 -140
  51. package/dist/cjs/author/jsx_shim.js.map +1 -1
  52. package/dist/cjs/author/print_jsx.js +378 -0
  53. package/dist/cjs/author/print_jsx.js.map +1 -0
  54. package/dist/cjs/author/prompt.js +7 -2
  55. package/dist/cjs/author/prompt.js.map +1 -1
  56. package/dist/cjs/author/schema_to_typescript.js +298 -0
  57. package/dist/cjs/author/schema_to_typescript.js.map +1 -0
  58. package/dist/cjs/composition/body_node_base.js +11 -4
  59. package/dist/cjs/composition/body_node_base.js.map +1 -1
  60. package/dist/cjs/composition/error.js +2 -0
  61. package/dist/cjs/composition/error.js.map +1 -1
  62. package/dist/cjs/composition/index.js +2 -1
  63. package/dist/cjs/composition/index.js.map +1 -1
  64. package/dist/cjs/composition/structured_value.js.map +1 -1
  65. package/dist/cjs/define/frame.js +2 -3
  66. package/dist/cjs/define/frame.js.map +1 -1
  67. package/dist/cjs/define/index.js +7 -1
  68. package/dist/cjs/define/index.js.map +1 -1
  69. package/dist/cjs/define/primitive_example.js +26 -0
  70. package/dist/cjs/define/primitive_example.js.map +1 -0
  71. package/dist/cjs/define/primitive_icon.js +17 -0
  72. package/dist/cjs/define/primitive_icon.js.map +1 -0
  73. package/dist/cjs/define/primitive_module.js +24 -7
  74. package/dist/cjs/define/primitive_module.js.map +1 -1
  75. package/dist/cjs/define/slack_assets.js.map +1 -1
  76. package/dist/cjs/entries/index.js +8 -2
  77. package/dist/cjs/entries/index.js.map +1 -1
  78. package/dist/cjs/entries/markdown.js +2 -1
  79. package/dist/cjs/entries/markdown.js.map +1 -1
  80. package/dist/cjs/entries/slack.js +1 -2
  81. package/dist/cjs/entries/slack.js.map +1 -1
  82. package/dist/cjs/pack/capabilities.js +17 -11
  83. package/dist/cjs/pack/capabilities.js.map +1 -1
  84. package/dist/cjs/pack/compose.js +4 -1
  85. package/dist/cjs/pack/compose.js.map +1 -1
  86. package/dist/cjs/pack/index.js +2 -1
  87. package/dist/cjs/pack/index.js.map +1 -1
  88. package/dist/cjs/pack/primitive_pack.js +27 -5
  89. package/dist/cjs/pack/primitive_pack.js.map +1 -1
  90. package/dist/cjs/render/anchors.js +1 -1
  91. package/dist/cjs/render/anchors.js.map +1 -1
  92. package/dist/cjs/render/format_number.js +2 -1
  93. package/dist/cjs/render/format_number.js.map +1 -1
  94. package/dist/cjs/render/html/envelope.js +12 -6
  95. package/dist/cjs/render/html/envelope.js.map +1 -1
  96. package/dist/cjs/render/layout_check.js.map +1 -1
  97. package/dist/cjs/render/markdown/builder.js +18 -8
  98. package/dist/cjs/render/markdown/builder.js.map +1 -1
  99. package/dist/cjs/render/markdown/format.js +70 -30
  100. package/dist/cjs/render/markdown/format.js.map +1 -1
  101. package/dist/cjs/render/markdown/host_tags.js +67 -0
  102. package/dist/cjs/render/markdown/host_tags.js.map +1 -0
  103. package/dist/cjs/render/markdown/index.js +3 -1
  104. package/dist/cjs/render/markdown/index.js.map +1 -1
  105. package/dist/cjs/render/markdown/split.js +325 -0
  106. package/dist/cjs/render/markdown/split.js.map +1 -0
  107. package/dist/cjs/render/primitive_dispatch.js +11 -25
  108. package/dist/cjs/render/primitive_dispatch.js.map +1 -1
  109. package/dist/cjs/render/react/content.js +3 -1
  110. package/dist/cjs/render/react/content.js.map +1 -1
  111. package/dist/cjs/render/slack/format.js +1 -601
  112. package/dist/cjs/render/slack/format.js.map +1 -1
  113. package/dist/cjs/render/slack/index.js +1 -2
  114. package/dist/cjs/render/slack/index.js.map +1 -1
  115. package/dist/cjs/render/slack/markdown_content.js +172 -115
  116. package/dist/cjs/render/slack/markdown_content.js.map +1 -1
  117. package/dist/cjs/testing/conformance.js +40 -24
  118. package/dist/cjs/testing/conformance.js.map +1 -1
  119. package/dist/cjs/testing/icon.js +248 -0
  120. package/dist/cjs/testing/icon.js.map +1 -0
  121. package/dist/cjs/testing/index.js +3 -1
  122. package/dist/cjs/testing/index.js.map +1 -1
  123. package/dist/cjs/testing/registration.js +5 -3
  124. package/dist/cjs/testing/registration.js.map +1 -1
  125. package/dist/cjs/validate/authoring_schema.js +17 -1
  126. package/dist/cjs/validate/authoring_schema.js.map +1 -1
  127. package/dist/cjs/validate/index.js +2 -1
  128. package/dist/cjs/validate/index.js.map +1 -1
  129. package/dist/cjs/validate/json_schema.js +10 -3
  130. package/dist/cjs/validate/json_schema.js.map +1 -1
  131. package/dist/cjs/validate/url.js +2 -1
  132. package/dist/cjs/validate/url.js.map +1 -1
  133. package/dist/cjs/validate/validation.js +2 -45
  134. package/dist/cjs/validate/validation.js.map +1 -1
  135. package/dist/composition/body_node_base.d.ts +7 -6
  136. package/dist/composition/body_node_base.d.ts.map +1 -1
  137. package/dist/composition/body_node_base.js +10 -3
  138. package/dist/composition/body_node_base.js.map +1 -1
  139. package/dist/composition/error.d.ts +2 -0
  140. package/dist/composition/error.d.ts.map +1 -1
  141. package/dist/composition/error.js +2 -0
  142. package/dist/composition/error.js.map +1 -1
  143. package/dist/composition/index.d.ts +1 -1
  144. package/dist/composition/index.d.ts.map +1 -1
  145. package/dist/composition/index.js +1 -1
  146. package/dist/composition/index.js.map +1 -1
  147. package/dist/composition/structured_value.d.ts +3 -3
  148. package/dist/composition/structured_value.d.ts.map +1 -1
  149. package/dist/composition/structured_value.js.map +1 -1
  150. package/dist/define/frame.d.ts +9 -20
  151. package/dist/define/frame.d.ts.map +1 -1
  152. package/dist/define/frame.js +2 -3
  153. package/dist/define/frame.js.map +1 -1
  154. package/dist/define/index.d.ts +3 -1
  155. package/dist/define/index.d.ts.map +1 -1
  156. package/dist/define/index.js +3 -1
  157. package/dist/define/index.js.map +1 -1
  158. package/dist/define/primitive_example.d.ts +30 -0
  159. package/dist/define/primitive_example.d.ts.map +1 -0
  160. package/dist/define/primitive_example.js +21 -0
  161. package/dist/define/primitive_example.js.map +1 -0
  162. package/dist/define/primitive_icon.d.ts +11 -0
  163. package/dist/define/primitive_icon.d.ts.map +1 -0
  164. package/dist/define/primitive_icon.js +14 -0
  165. package/dist/define/primitive_icon.js.map +1 -0
  166. package/dist/define/primitive_module.d.ts +45 -24
  167. package/dist/define/primitive_module.d.ts.map +1 -1
  168. package/dist/define/primitive_module.js +24 -7
  169. package/dist/define/primitive_module.js.map +1 -1
  170. package/dist/define/slack_assets.d.ts +1 -1
  171. package/dist/define/slack_assets.d.ts.map +1 -1
  172. package/dist/define/slack_assets.js.map +1 -1
  173. package/dist/entries/index.d.ts +3 -3
  174. package/dist/entries/index.d.ts.map +1 -1
  175. package/dist/entries/index.js +3 -3
  176. package/dist/entries/index.js.map +1 -1
  177. package/dist/entries/markdown.d.ts +1 -1
  178. package/dist/entries/markdown.d.ts.map +1 -1
  179. package/dist/entries/markdown.js +1 -1
  180. package/dist/entries/markdown.js.map +1 -1
  181. package/dist/entries/slack.d.ts +1 -1
  182. package/dist/entries/slack.d.ts.map +1 -1
  183. package/dist/entries/slack.js +1 -1
  184. package/dist/entries/slack.js.map +1 -1
  185. package/dist/pack/capabilities.d.ts +24 -10
  186. package/dist/pack/capabilities.d.ts.map +1 -1
  187. package/dist/pack/capabilities.js +17 -11
  188. package/dist/pack/capabilities.js.map +1 -1
  189. package/dist/pack/compose.d.ts +4 -1
  190. package/dist/pack/compose.d.ts.map +1 -1
  191. package/dist/pack/compose.js +4 -1
  192. package/dist/pack/compose.js.map +1 -1
  193. package/dist/pack/index.d.ts +2 -2
  194. package/dist/pack/index.d.ts.map +1 -1
  195. package/dist/pack/index.js +2 -2
  196. package/dist/pack/index.js.map +1 -1
  197. package/dist/pack/primitive_pack.d.ts +14 -3
  198. package/dist/pack/primitive_pack.d.ts.map +1 -1
  199. package/dist/pack/primitive_pack.js +25 -4
  200. package/dist/pack/primitive_pack.js.map +1 -1
  201. package/dist/render/anchors.d.ts +2 -2
  202. package/dist/render/anchors.d.ts.map +1 -1
  203. package/dist/render/anchors.js +1 -1
  204. package/dist/render/anchors.js.map +1 -1
  205. package/dist/render/format_number.d.ts.map +1 -1
  206. package/dist/render/format_number.js +2 -1
  207. package/dist/render/format_number.js.map +1 -1
  208. package/dist/render/html/envelope.d.ts +3 -3
  209. package/dist/render/html/envelope.js +12 -6
  210. package/dist/render/html/envelope.js.map +1 -1
  211. package/dist/render/layout_check.d.ts +1 -1
  212. package/dist/render/layout_check.d.ts.map +1 -1
  213. package/dist/render/layout_check.js.map +1 -1
  214. package/dist/render/markdown/builder.d.ts +5 -4
  215. package/dist/render/markdown/builder.d.ts.map +1 -1
  216. package/dist/render/markdown/builder.js +16 -7
  217. package/dist/render/markdown/builder.js.map +1 -1
  218. package/dist/render/markdown/format.d.ts +9 -0
  219. package/dist/render/markdown/format.d.ts.map +1 -1
  220. package/dist/render/markdown/format.js +67 -31
  221. package/dist/render/markdown/format.js.map +1 -1
  222. package/dist/render/markdown/host_tags.d.ts +14 -0
  223. package/dist/render/markdown/host_tags.d.ts.map +1 -0
  224. package/dist/render/markdown/host_tags.js +63 -0
  225. package/dist/render/markdown/host_tags.js.map +1 -0
  226. package/dist/render/markdown/index.d.ts +1 -0
  227. package/dist/render/markdown/index.d.ts.map +1 -1
  228. package/dist/render/markdown/index.js +1 -0
  229. package/dist/render/markdown/index.js.map +1 -1
  230. package/dist/render/markdown/split.d.ts +32 -0
  231. package/dist/render/markdown/split.d.ts.map +1 -0
  232. package/dist/render/markdown/split.js +321 -0
  233. package/dist/render/markdown/split.js.map +1 -0
  234. package/dist/render/primitive_dispatch.d.ts +6 -6
  235. package/dist/render/primitive_dispatch.d.ts.map +1 -1
  236. package/dist/render/primitive_dispatch.js +12 -26
  237. package/dist/render/primitive_dispatch.js.map +1 -1
  238. package/dist/render/react/content.d.ts +1 -1
  239. package/dist/render/react/content.d.ts.map +1 -1
  240. package/dist/render/react/content.js +3 -1
  241. package/dist/render/react/content.js.map +1 -1
  242. package/dist/render/slack/format.d.ts +0 -25
  243. package/dist/render/slack/format.d.ts.map +1 -1
  244. package/dist/render/slack/format.js +1 -599
  245. package/dist/render/slack/format.js.map +1 -1
  246. package/dist/render/slack/index.d.ts +1 -1
  247. package/dist/render/slack/index.d.ts.map +1 -1
  248. package/dist/render/slack/index.js +1 -1
  249. package/dist/render/slack/index.js.map +1 -1
  250. package/dist/render/slack/markdown_content.d.ts +10 -4
  251. package/dist/render/slack/markdown_content.d.ts.map +1 -1
  252. package/dist/render/slack/markdown_content.js +169 -113
  253. package/dist/render/slack/markdown_content.js.map +1 -1
  254. package/dist/testing/conformance.d.ts +19 -14
  255. package/dist/testing/conformance.d.ts.map +1 -1
  256. package/dist/testing/conformance.js +40 -24
  257. package/dist/testing/conformance.js.map +1 -1
  258. package/dist/testing/icon.d.ts +11 -0
  259. package/dist/testing/icon.d.ts.map +1 -0
  260. package/dist/testing/icon.js +244 -0
  261. package/dist/testing/icon.js.map +1 -0
  262. package/dist/testing/index.d.ts +2 -1
  263. package/dist/testing/index.d.ts.map +1 -1
  264. package/dist/testing/index.js +1 -0
  265. package/dist/testing/index.js.map +1 -1
  266. package/dist/testing/registration.d.ts +1 -1
  267. package/dist/testing/registration.d.ts.map +1 -1
  268. package/dist/testing/registration.js +6 -4
  269. package/dist/testing/registration.js.map +1 -1
  270. package/dist/validate/authoring_schema.d.ts +6 -0
  271. package/dist/validate/authoring_schema.d.ts.map +1 -1
  272. package/dist/validate/authoring_schema.js +15 -0
  273. package/dist/validate/authoring_schema.js.map +1 -1
  274. package/dist/validate/index.d.ts +1 -1
  275. package/dist/validate/index.d.ts.map +1 -1
  276. package/dist/validate/index.js +1 -1
  277. package/dist/validate/index.js.map +1 -1
  278. package/dist/validate/json_schema.d.ts.map +1 -1
  279. package/dist/validate/json_schema.js +10 -3
  280. package/dist/validate/json_schema.js.map +1 -1
  281. package/dist/validate/url.d.ts.map +1 -1
  282. package/dist/validate/url.js +2 -1
  283. package/dist/validate/url.js.map +1 -1
  284. package/dist/validate/validation.d.ts +1 -11
  285. package/dist/validate/validation.d.ts.map +1 -1
  286. package/dist/validate/validation.js +3 -46
  287. package/dist/validate/validation.js.map +1 -1
  288. package/package.json +3 -2
@@ -0,0 +1,298 @@
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.createTypePrinter = exports.jsDoc = exports.pascalCase = exports.ownDef = exports.parseDefRef = exports.isJsonObject = exports.IDENTIFIER = exports.ANONYMOUS_DEF = exports.DEF_PREFIX = void 0;
10
+ exports.DEF_PREFIX = '#/$defs/';
11
+ /** Ids `z.toJSONSchema` gives a def no one named. */
12
+ exports.ANONYMOUS_DEF = /^__schema\d+$/;
13
+ const STRUCTURAL_KEYS = [
14
+ 'type',
15
+ 'const',
16
+ 'enum',
17
+ 'properties',
18
+ 'additionalProperties',
19
+ 'patternProperties',
20
+ 'propertyNames',
21
+ 'items',
22
+ 'prefixItems',
23
+ 'oneOf',
24
+ 'anyOf',
25
+ 'allOf',
26
+ ];
27
+ const INDENT = ' ';
28
+ exports.IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
29
+ const isJsonObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
30
+ exports.isJsonObject = isJsonObject;
31
+ const parseDefRef = (ref) => typeof ref === 'string' && ref.startsWith(exports.DEF_PREFIX)
32
+ ? ref.slice(exports.DEF_PREFIX.length)
33
+ : undefined;
34
+ exports.parseDefRef = parseDefRef;
35
+ const ownDef = (defs, id) => Object.hasOwn(defs, id) ? defs[id] : undefined;
36
+ exports.ownDef = ownDef;
37
+ /** `slideStats` becomes `SlideStats`; anything but letters and digits splits words. */
38
+ const pascalCase = (value) => {
39
+ const name = value
40
+ .split(/[^A-Za-z0-9]+/)
41
+ .filter(Boolean)
42
+ .map((word) => `${word.slice(0, 1).toUpperCase()}${word.slice(1)}`)
43
+ .join('');
44
+ if (name === '') {
45
+ return 'Type';
46
+ }
47
+ return /^\d/.test(name) ? `_${name}` : name;
48
+ };
49
+ exports.pascalCase = pascalCase;
50
+ /** A JSDoc block for `lines`, or `''` when there are none. */
51
+ const jsDoc = (lines, pad) => {
52
+ const text = lines
53
+ .flatMap((line) => line.split('\n'))
54
+ .map((line) => line.replaceAll('*/', '*\\/').trimEnd());
55
+ while (text[0] === '') {
56
+ text.shift();
57
+ }
58
+ while (text.at(-1) === '') {
59
+ text.pop();
60
+ }
61
+ if (text.length === 0) {
62
+ return '';
63
+ }
64
+ const [only] = text;
65
+ if (text.length === 1 && only !== undefined) {
66
+ return `${pad}/** ${only} */\n`;
67
+ }
68
+ return `${pad}/**\n${text
69
+ .map((line) => (line === '' ? `${pad} *` : `${pad} * ${line}`))
70
+ .join('\n')}\n${pad} */\n`;
71
+ };
72
+ exports.jsDoc = jsDoc;
73
+ const propertyKey = (key) => exports.IDENTIFIER.test(key) ? key : JSON.stringify(key);
74
+ const literal = (value) => {
75
+ if (value === null) {
76
+ return 'null';
77
+ }
78
+ switch (typeof value) {
79
+ case 'string':
80
+ return JSON.stringify(value);
81
+ case 'number':
82
+ case 'boolean':
83
+ return String(value);
84
+ default:
85
+ return 'unknown';
86
+ }
87
+ };
88
+ const atom = (text) => ({ text, kind: 'atom' });
89
+ const union = (members) => {
90
+ if (members.some(({ text }) => text === 'unknown')) {
91
+ return atom('unknown');
92
+ }
93
+ const unique = new Map(members.map((member) => [member.text, member]));
94
+ const [only] = [...unique.values()];
95
+ if (unique.size === 0) {
96
+ return atom('never');
97
+ }
98
+ return unique.size === 1 && only
99
+ ? only
100
+ : { text: [...unique.keys()].join(' | '), kind: 'union' };
101
+ };
102
+ const intersection = (members) => {
103
+ const unique = new Map(members.map((member) => [member.text, member]));
104
+ const [only] = [...unique.values()];
105
+ if (!only) {
106
+ return atom('unknown');
107
+ }
108
+ if (unique.size === 1 && only) {
109
+ return only;
110
+ }
111
+ return {
112
+ text: [...unique.values()]
113
+ .map(({ text, kind }) => (kind === 'union' ? `(${text})` : text))
114
+ .join(' & '),
115
+ kind: 'intersection',
116
+ };
117
+ };
118
+ const arrayOf = ({ text, kind }) => atom(kind === 'atom' ? `${text}[]` : `(${text})[]`);
119
+ /** A TypeScript printer over the subset of JSON Schema `z.toJSONSchema` emits. */
120
+ const createTypePrinter = ({ defs, names, claim, }) => {
121
+ const promotedNames = new Map();
122
+ const printRef = (id, depth, active) => {
123
+ const named = names.get(id);
124
+ if (named !== undefined) {
125
+ return atom(named);
126
+ }
127
+ const target = (0, exports.ownDef)(defs, id);
128
+ if (target === undefined) {
129
+ return atom('unknown');
130
+ }
131
+ if (active.has(id)) {
132
+ const name = promotedNames.get(id) ?? claim((0, exports.pascalCase)(id));
133
+ promotedNames.set(id, name);
134
+ return atom(name);
135
+ }
136
+ return printNode(target, depth, new Set([...active, id]));
137
+ };
138
+ const printNode = (node, depth, active) => {
139
+ if (node === false) {
140
+ return atom('never');
141
+ }
142
+ if (!(0, exports.isJsonObject)(node)) {
143
+ return atom('unknown');
144
+ }
145
+ const parts = [];
146
+ const ref = (0, exports.parseDefRef)(node.$ref);
147
+ if (ref !== undefined) {
148
+ parts.push(printRef(ref, depth, active));
149
+ }
150
+ if (STRUCTURAL_KEYS.some((key) => Object.hasOwn(node, key))) {
151
+ parts.push(printStructure(node, depth, active));
152
+ }
153
+ return parts.length === 0 ? atom('unknown') : intersection(parts);
154
+ };
155
+ const printStructure = (node, depth, active) => {
156
+ const parts = [];
157
+ const own = printOwn(node, depth, active);
158
+ if (own) {
159
+ parts.push(own);
160
+ }
161
+ for (const key of ['oneOf', 'anyOf']) {
162
+ const members = node[key];
163
+ if (Array.isArray(members)) {
164
+ parts.push(union(members.map((member) => printNode(member, depth, active))));
165
+ }
166
+ }
167
+ if (Array.isArray(node.allOf)) {
168
+ parts.push(intersection(node.allOf.map((member) => printNode(member, depth, active))));
169
+ }
170
+ return parts.length === 0 ? atom('unknown') : intersection(parts);
171
+ };
172
+ // `undefined` when the node only combines other schemas.
173
+ const printOwn = (node, depth, active) => {
174
+ if (Object.hasOwn(node, 'const')) {
175
+ return atom(literal(node.const));
176
+ }
177
+ if (Array.isArray(node.enum)) {
178
+ return union(node.enum.map((value) => atom(literal(value))));
179
+ }
180
+ const { type } = node;
181
+ if (Array.isArray(type)) {
182
+ return union(type.map((member) => printTyped(member, node, depth, active)));
183
+ }
184
+ if (typeof type === 'string') {
185
+ return printTyped(type, node, depth, active);
186
+ }
187
+ if (Object.hasOwn(node, 'properties') ||
188
+ Object.hasOwn(node, 'additionalProperties')) {
189
+ return printObject(node, depth, active);
190
+ }
191
+ if (Object.hasOwn(node, 'items') || Object.hasOwn(node, 'prefixItems')) {
192
+ return printArray(node, depth, active);
193
+ }
194
+ return undefined;
195
+ };
196
+ const printTyped = (type, node, depth, active) => {
197
+ switch (type) {
198
+ case 'string':
199
+ return atom('string');
200
+ case 'number':
201
+ case 'integer':
202
+ return atom('number');
203
+ case 'boolean':
204
+ return atom('boolean');
205
+ case 'null':
206
+ return atom('null');
207
+ case 'array':
208
+ return printArray(node, depth, active);
209
+ case 'object':
210
+ return printObject(node, depth, active);
211
+ default:
212
+ return atom('unknown');
213
+ }
214
+ };
215
+ const printArray = (node, depth, active) => {
216
+ const { prefixItems, items } = node;
217
+ if (Array.isArray(prefixItems)) {
218
+ const required = typeof node.minItems === 'number' ? node.minItems : 0;
219
+ const elements = prefixItems.map((item, index) => {
220
+ const printed = printNode(item, depth, active);
221
+ return index < required
222
+ ? printed.text
223
+ : `${printed.kind === 'atom' ? printed.text : `(${printed.text})`}?`;
224
+ });
225
+ if (items !== undefined && items !== false) {
226
+ elements.push(`...${arrayOf(printNode(items, depth, active)).text}`);
227
+ }
228
+ return atom(`[${elements.join(', ')}]`);
229
+ }
230
+ return arrayOf(items === undefined ? atom('unknown') : printNode(items, depth, active));
231
+ };
232
+ const printObject = (node, depth, active) => {
233
+ const properties = (0, exports.isJsonObject)(node.properties) ? node.properties : {};
234
+ const lines = printMembers(node, depth, active, {});
235
+ const extra = node.additionalProperties;
236
+ const patterns = (0, exports.isJsonObject)(node.patternProperties)
237
+ ? Object.values(node.patternProperties)
238
+ : [];
239
+ const open = extra !== false;
240
+ const values = [
241
+ ...patterns.map((schema) => printNode(schema, depth, active)),
242
+ ];
243
+ if (open) {
244
+ values.push(extra === undefined || extra === true
245
+ ? atom('unknown')
246
+ : printNode(extra, depth, active));
247
+ }
248
+ const index = values.length === 0
249
+ ? Object.keys(properties).length === 0
250
+ ? `${INDENT.repeat(depth + 1)}[key: string]: never;\n`
251
+ : ''
252
+ : `${INDENT.repeat(depth + 1)}[key: string]: ${union([
253
+ ...values,
254
+ ...Object.values(properties).map((schema) => printNode(schema, depth, active)),
255
+ ...(Object.keys(properties).some((key) => !Array.isArray(node.required) || !node.required.includes(key))
256
+ ? [atom('undefined')]
257
+ : []),
258
+ ]).text};\n`;
259
+ return atom(`{\n${lines}${index}${INDENT.repeat(depth)}}`);
260
+ };
261
+ const printMembers = (node, depth, active, { omit, optional }) => {
262
+ const pad = INDENT.repeat(depth + 1);
263
+ const required = new Set(Array.isArray(node.required)
264
+ ? node.required.filter((key) => typeof key === 'string')
265
+ : []);
266
+ const properties = (0, exports.isJsonObject)(node.properties) ? node.properties : {};
267
+ return Object.entries(properties)
268
+ .filter(([key]) => !omit?.has(key))
269
+ .map(([key, property]) => {
270
+ const doc = (0, exports.isJsonObject)(property)
271
+ ? (0, exports.jsDoc)([
272
+ typeof property.description === 'string'
273
+ ? property.description
274
+ : '',
275
+ ...(Object.hasOwn(property, 'default')
276
+ ? [`@default ${JSON.stringify(property.default)}`]
277
+ : []),
278
+ ], pad)
279
+ : '';
280
+ const mark = required.has(key) && !optional?.has(key) ? '' : '?';
281
+ return `${doc}${pad}${propertyKey(key)}${mark}: ${printNode(property, depth + 1, active).text};\n`;
282
+ })
283
+ .join('');
284
+ };
285
+ return {
286
+ print: (schema, depth = 0) => printNode(schema, depth, new Set()).text,
287
+ members: (schema, depth, options = {}) => printMembers(schema, depth, new Set(), options),
288
+ promoted: () => {
289
+ const aliases = [];
290
+ for (const [id, name] of promotedNames) {
291
+ aliases.push(`type ${name} = ${printNode((0, exports.ownDef)(defs, id), 0, new Set([id])).text};`);
292
+ }
293
+ return aliases;
294
+ },
295
+ };
296
+ };
297
+ exports.createTypePrinter = createTypePrinter;
298
+ //# sourceMappingURL=schema_to_typescript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema_to_typescript.js","sourceRoot":"","sources":["../../../src/author/schema_to_typescript.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIU,QAAA,UAAU,GAAG,UAAU,CAAC;AAErC,qDAAqD;AACxC,QAAA,aAAa,GAAG,eAAe,CAAC;AAE7C,MAAM,eAAe,GAAG;IACtB,MAAM;IACN,OAAO;IACP,MAAM;IACN,YAAY;IACZ,sBAAsB;IACtB,mBAAmB;IACnB,eAAe;IACf,OAAO;IACP,aAAa;IACb,OAAO;IACP,OAAO;IACP,OAAO;CACC,CAAC;AAEX,MAAM,MAAM,GAAG,IAAI,CAAC;AAEP,QAAA,UAAU,GAAG,oBAAoB,CAAC;AAExC,MAAM,YAAY,GAAG,CAAC,KAAc,EAAuB,EAAE,CAClE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAD1D,QAAA,YAAY,gBAC8C;AAEhE,MAAM,WAAW,GAAG,CAAC,GAAY,EAAsB,EAAE,CAC9D,OA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C,IAAI,aAAa,EAAE,CAAC;gBACvC,OAAO,CAAC,IAAI,CACV,QAAQ,IAAI,MAAM,SAAS,CAAC,IAAA,cAAM,EAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CACxE,CAAC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AA/PW,QAAA,iBAAiB,qBA+P5B","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 type JsonObject = Record<string, unknown>;\n\nexport const DEF_PREFIX = '#/$defs/';\n\n/** Ids `z.toJSONSchema` gives a def no one named. */\nexport const ANONYMOUS_DEF = /^__schema\\d+$/;\n\nconst STRUCTURAL_KEYS = [\n 'type',\n 'const',\n 'enum',\n 'properties',\n 'additionalProperties',\n 'patternProperties',\n 'propertyNames',\n 'items',\n 'prefixItems',\n 'oneOf',\n 'anyOf',\n 'allOf',\n] as const;\n\nconst INDENT = ' ';\n\nexport const IDENTIFIER = /^[A-Za-z_$][\\w$]*$/;\n\nexport const isJsonObject = (value: unknown): value is JsonObject =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nexport const parseDefRef = (ref: unknown): string | undefined =>\n typeof ref === 'string' && ref.startsWith(DEF_PREFIX)\n ? ref.slice(DEF_PREFIX.length)\n : undefined;\n\nexport const ownDef = (defs: JsonObject, id: string): unknown =>\n Object.hasOwn(defs, id) ? defs[id] : undefined;\n\n/** `slideStats` becomes `SlideStats`; anything but letters and digits splits words. */\nexport const pascalCase = (value: string): string => {\n const name = value\n .split(/[^A-Za-z0-9]+/)\n .filter(Boolean)\n .map((word) => `${word.slice(0, 1).toUpperCase()}${word.slice(1)}`)\n .join('');\n if (name === '') {\n return 'Type';\n }\n return /^\\d/.test(name) ? `_${name}` : name;\n};\n\n/** A JSDoc block for `lines`, or `''` when there are none. */\nexport const jsDoc = (lines: readonly string[], pad: string): string => {\n const text = lines\n .flatMap((line) => line.split('\\n'))\n .map((line) => line.replaceAll('*/', '*\\\\/').trimEnd());\n while (text[0] === '') {\n text.shift();\n }\n while (text.at(-1) === '') {\n text.pop();\n }\n if (text.length === 0) {\n return '';\n }\n const [only] = text;\n if (text.length === 1 && only !== undefined) {\n return `${pad}/** ${only} */\\n`;\n }\n return `${pad}/**\\n${text\n .map((line) => (line === '' ? `${pad} *` : `${pad} * ${line}`))\n .join('\\n')}\\n${pad} */\\n`;\n};\n\nconst propertyKey = (key: string): string =>\n IDENTIFIER.test(key) ? key : JSON.stringify(key);\n\nconst literal = (value: unknown): string => {\n if (value === null) {\n return 'null';\n }\n switch (typeof value) {\n case 'string':\n return JSON.stringify(value);\n case 'number':\n case 'boolean':\n return String(value);\n default:\n return 'unknown';\n }\n};\n\ninterface Printed {\n text: string;\n kind: 'atom' | 'union' | 'intersection';\n}\n\nconst atom = (text: string): Printed => ({ text, kind: 'atom' });\n\nconst union = (members: readonly Printed[]): Printed => {\n if (members.some(({ text }) => text === 'unknown')) {\n return atom('unknown');\n }\n const unique = new Map(members.map((member) => [member.text, member]));\n const [only] = [...unique.values()];\n if (unique.size === 0) {\n return atom('never');\n }\n return unique.size === 1 && only\n ? only\n : { text: [...unique.keys()].join(' | '), kind: 'union' };\n};\n\nconst intersection = (members: readonly Printed[]): Printed => {\n const unique = new Map(members.map((member) => [member.text, member]));\n const [only] = [...unique.values()];\n if (!only) {\n return atom('unknown');\n }\n if (unique.size === 1 && only) {\n return only;\n }\n return {\n text: [...unique.values()]\n .map(({ text, kind }) => (kind === 'union' ? `(${text})` : text))\n .join(' & '),\n kind: 'intersection',\n };\n};\n\nconst arrayOf = ({ text, kind }: Printed): Printed =>\n atom(kind === 'atom' ? `${text}[]` : `(${text})[]`);\n\n/** What {@link TypePrinter.members} prints and how. */\nexport interface MemberOptions {\n /** Properties left out. */\n omit?: ReadonlySet<string>;\n /** Properties printed optional whether or not the schema requires them. */\n optional?: ReadonlySet<string>;\n}\n\nexport interface TypePrinterOptions {\n defs: JsonObject;\n /** TypeScript names for defs printed by reference; every other def is inlined. */\n names: ReadonlyMap<string, string>;\n /** A fresh, unused name, for a def inlining cannot express. */\n claim: (base: string) => string;\n}\n\nexport interface TypePrinter {\n /** `schema` as a TypeScript type, written at `depth` levels of indent. */\n print: (schema: unknown, depth?: number) => string;\n /** The `key?: Type;` members of an object schema, with their JSDoc, at `depth + 1`. */\n members: (\n schema: JsonObject,\n depth: number,\n options?: MemberOptions\n ) => string;\n /** Type aliases for the anonymous defs that refer to themselves. Call last. */\n promoted: () => string[];\n}\n\n/** A TypeScript printer over the subset of JSON Schema `z.toJSONSchema` emits. */\nexport const createTypePrinter = ({\n defs,\n names,\n claim,\n}: TypePrinterOptions): TypePrinter => {\n const promotedNames = new Map<string, string>();\n\n const printRef = (\n id: string,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n const named = names.get(id);\n if (named !== undefined) {\n return atom(named);\n }\n const target = ownDef(defs, id);\n if (target === undefined) {\n return atom('unknown');\n }\n if (active.has(id)) {\n const name = promotedNames.get(id) ?? claim(pascalCase(id));\n promotedNames.set(id, name);\n return atom(name);\n }\n return printNode(target, depth, new Set([...active, id]));\n };\n\n const printNode = (\n node: unknown,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n if (node === false) {\n return atom('never');\n }\n if (!isJsonObject(node)) {\n return atom('unknown');\n }\n const parts: Printed[] = [];\n const ref = parseDefRef(node.$ref);\n if (ref !== undefined) {\n parts.push(printRef(ref, depth, active));\n }\n if (STRUCTURAL_KEYS.some((key) => Object.hasOwn(node, key))) {\n parts.push(printStructure(node, depth, active));\n }\n return parts.length === 0 ? atom('unknown') : intersection(parts);\n };\n\n const printStructure = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n const parts: Printed[] = [];\n const own = printOwn(node, depth, active);\n if (own) {\n parts.push(own);\n }\n for (const key of ['oneOf', 'anyOf'] as const) {\n const members = node[key];\n if (Array.isArray(members)) {\n parts.push(\n union(members.map((member) => printNode(member, depth, active)))\n );\n }\n }\n if (Array.isArray(node.allOf)) {\n parts.push(\n intersection(\n node.allOf.map((member) => printNode(member, depth, active))\n )\n );\n }\n return parts.length === 0 ? atom('unknown') : intersection(parts);\n };\n\n // `undefined` when the node only combines other schemas.\n const printOwn = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed | undefined => {\n if (Object.hasOwn(node, 'const')) {\n return atom(literal(node.const));\n }\n if (Array.isArray(node.enum)) {\n return union(node.enum.map((value) => atom(literal(value))));\n }\n const { type } = node;\n if (Array.isArray(type)) {\n return union(\n type.map((member) => printTyped(member, node, depth, active))\n );\n }\n if (typeof type === 'string') {\n return printTyped(type, node, depth, active);\n }\n if (\n Object.hasOwn(node, 'properties') ||\n Object.hasOwn(node, 'additionalProperties')\n ) {\n return printObject(node, depth, active);\n }\n if (Object.hasOwn(node, 'items') || Object.hasOwn(node, 'prefixItems')) {\n return printArray(node, depth, active);\n }\n return undefined;\n };\n\n const printTyped = (\n type: unknown,\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n switch (type) {\n case 'string':\n return atom('string');\n case 'number':\n case 'integer':\n return atom('number');\n case 'boolean':\n return atom('boolean');\n case 'null':\n return atom('null');\n case 'array':\n return printArray(node, depth, active);\n case 'object':\n return printObject(node, depth, active);\n default:\n return atom('unknown');\n }\n };\n\n const printArray = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n const { prefixItems, items } = node;\n if (Array.isArray(prefixItems)) {\n const required = typeof node.minItems === 'number' ? node.minItems : 0;\n const elements = prefixItems.map((item, index) => {\n const printed = printNode(item, depth, active);\n return index < required\n ? printed.text\n : `${printed.kind === 'atom' ? printed.text : `(${printed.text})`}?`;\n });\n if (items !== undefined && items !== false) {\n elements.push(`...${arrayOf(printNode(items, depth, active)).text}`);\n }\n return atom(`[${elements.join(', ')}]`);\n }\n return arrayOf(\n items === undefined ? atom('unknown') : printNode(items, depth, active)\n );\n };\n\n const printObject = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n const properties = isJsonObject(node.properties) ? node.properties : {};\n const lines = printMembers(node, depth, active, {});\n const extra = node.additionalProperties;\n const patterns = isJsonObject(node.patternProperties)\n ? Object.values(node.patternProperties)\n : [];\n const open = extra !== false;\n const values = [\n ...patterns.map((schema) => printNode(schema, depth, active)),\n ];\n if (open) {\n values.push(\n extra === undefined || extra === true\n ? atom('unknown')\n : printNode(extra, depth, active)\n );\n }\n const index =\n values.length === 0\n ? Object.keys(properties).length === 0\n ? `${INDENT.repeat(depth + 1)}[key: string]: never;\\n`\n : ''\n : `${INDENT.repeat(depth + 1)}[key: string]: ${\n union([\n ...values,\n ...Object.values(properties).map((schema) =>\n printNode(schema, depth, active)\n ),\n ...(Object.keys(properties).some(\n (key) =>\n !Array.isArray(node.required) || !node.required.includes(key)\n )\n ? [atom('undefined')]\n : []),\n ]).text\n };\\n`;\n return atom(`{\\n${lines}${index}${INDENT.repeat(depth)}}`);\n };\n\n const printMembers = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>,\n { omit, optional }: MemberOptions\n ): string => {\n const pad = INDENT.repeat(depth + 1);\n const required = new Set(\n Array.isArray(node.required)\n ? node.required.filter((key) => typeof key === 'string')\n : []\n );\n const properties = isJsonObject(node.properties) ? node.properties : {};\n return Object.entries(properties)\n .filter(([key]) => !omit?.has(key))\n .map(([key, property]) => {\n const doc = isJsonObject(property)\n ? jsDoc(\n [\n typeof property.description === 'string'\n ? property.description\n : '',\n ...(Object.hasOwn(property, 'default')\n ? [`@default ${JSON.stringify(property.default)}`]\n : []),\n ],\n pad\n )\n : '';\n const mark = required.has(key) && !optional?.has(key) ? '' : '?';\n return `${doc}${pad}${propertyKey(key)}${mark}: ${\n printNode(property, depth + 1, active).text\n };\\n`;\n })\n .join('');\n };\n\n return {\n print: (schema, depth = 0) => printNode(schema, depth, new Set()).text,\n members: (schema, depth, options = {}) =>\n printMembers(schema, depth, new Set(), options),\n promoted: () => {\n const aliases: string[] = [];\n for (const [id, name] of promotedNames) {\n aliases.push(\n `type ${name} = ${printNode(ownDef(defs, id), 0, new Set([id])).text};`\n );\n }\n return aliases;\n },\n };\n};\n"]}
@@ -6,15 +6,22 @@
6
6
  * 2.0.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.rendersOnSurface = exports.isVisibleOnSurface = exports.someBodyNode = exports.childNodePath = exports.createChildNodeWalker = exports.BODY_NODE_SURFACES = void 0;
10
- /** Every {@link SurfaceName}, for callers that iterate them. */
11
- exports.BODY_NODE_SURFACES = [
9
+ exports.rendersOnSurface = exports.isVisibleOnSurface = exports.someBodyNode = exports.childNodePath = exports.createChildNodeWalker = exports.BODY_NODE_SURFACES = exports.SURFACE_NAMES = void 0;
10
+ /**
11
+ * Every surface a node renders on or is hidden from, in render order.
12
+ *
13
+ * `html` is not here: the runtime's `html` surface wraps `react` output in a
14
+ * document, and no node targets it.
15
+ */
16
+ exports.SURFACE_NAMES = [
12
17
  'react',
13
- 'svg',
18
+ 'snapshot',
14
19
  'text',
15
20
  'markdown',
16
21
  'slack',
17
22
  ];
23
+ /** @deprecated Use {@link SURFACE_NAMES}. */
24
+ exports.BODY_NODE_SURFACES = exports.SURFACE_NAMES;
18
25
  /**
19
26
  * Builds the {@link ChildNodeWalker} for one composition's inventory.
20
27
  *
@@ -1 +1 @@
1
- {"version":3,"file":"body_node_base.js","sourceRoot":"","sources":["../../../src/composition/body_node_base.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAWH,gEAAgE;AACnD,QAAA,kBAAkB,GAA2B;IACxD,OAAO;IACP,KAAK;IACL,MAAM;IACN,UAAU;IACV,OAAO;CACR,CAAC;AAgCF;;;;;GAK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AATW,QAAA,kBAAkB,sBAS7B;AAEF;;;;;;;GAOG;AACI,MAAM,gBAAgB,GAAG,CAC9B,IAAa,EACb,OAAoB,EACpB,IAAqB,EACZ,EAAE;IACX,IAAI,CAAC,IAAA,0BAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CACvC,IAAA,wBAAgB,EAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CACvC,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,gBAAgB,oBAe3B","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/**\n * The five surfaces a node renders on or is hidden from.\n *\n * Spelled out rather than derived as `keyof SurfaceMap<…>`: the keys never vary\n * with the pack types, and TypeScript can fail to prove a `keyof` over one\n * instantiation transfers to another, silently widening to `any`.\n */\nexport type SurfaceName = 'react' | 'svg' | 'text' | 'markdown' | 'slack';\n\n/** Every {@link SurfaceName}, for callers that iterate them. */\nexport const BODY_NODE_SURFACES: readonly SurfaceName[] = [\n 'react',\n 'svg',\n 'text',\n 'markdown',\n 'slack',\n];\n\n/** The two fields every primitive node carries, whatever its pack. */\nexport interface BodyNodeBase {\n /** Unique within a composition, which `validate` enforces and `parse` does not. */\n id?: string;\n /** Surfaces this node appears on. Absent means every surface. */\n surfaces?: SurfaceName[];\n}\n\n/**\n * A child node together with the field path locating it inside its parent, so\n * an error path can name the field a child actually lives under. A container\n * that returned bare nodes would leave every caller guessing the field name.\n */\nexport interface ChildNodeRef {\n /** Erased: one walker spans every pack's node types, so it can name none of them. */\n node: unknown;\n /** Relative to the parent, e.g. `items[0].node`, `items[2].description`. */\n path: string;\n}\n\n/**\n * Walks nested nodes and, for a hybrid container, reports whether the parent\n * still produces output of its own. A non-empty `children` result is the\n * complete source of rendered content unless\n * {@link ChildNodeWalker.hasOwnContent} is true for that node.\n */\nexport type ChildNodeWalker = ((node: unknown) => ChildNodeRef[]) & {\n hasOwnContent?(node: unknown): boolean;\n};\n\n/**\n * Builds the {@link ChildNodeWalker} for one composition's inventory.\n *\n * Pass every pack's definitions: a walker missing one cannot see children of a\n * container that pack defines, and a tree walk would stop at its boundary.\n */\nexport const createChildNodeWalker = (\n definitions: readonly {\n type: string;\n children?: unknown;\n hasOwnContent?: unknown;\n }[]\n): ChildNodeWalker => {\n const childrenByType = new Map<\n string,\n (node: unknown) => readonly ChildNodeRef[]\n >();\n const ownContentByType = new Map<string, (node: unknown) => boolean>();\n for (const definition of definitions) {\n if (typeof definition.children === 'function') {\n childrenByType.set(\n definition.type,\n definition.children as (node: unknown) => readonly ChildNodeRef[]\n );\n }\n if (typeof definition.hasOwnContent === 'function') {\n ownContentByType.set(\n definition.type,\n definition.hasOwnContent as (node: unknown) => boolean\n );\n }\n }\n const walk = ((node: unknown) => {\n if (!node || typeof node !== 'object') {\n return [];\n }\n const { type } = node as { type?: unknown };\n if (typeof type !== 'string') {\n return [];\n }\n return [...(childrenByType.get(type)?.(node) ?? [])];\n }) as ChildNodeWalker;\n walk.hasOwnContent = (node) => {\n if (!node || typeof node !== 'object') {\n return false;\n }\n const { type } = node as { type?: unknown };\n if (typeof type !== 'string') {\n return false;\n }\n return ownContentByType.get(type)?.(node) ?? false;\n };\n return walk;\n};\n\n/** Joins a parent path with a {@link ChildNodeRef.path} fragment. */\nexport const childNodePath = (parent: string, child: string): string =>\n `${parent}.${child}`;\n\n/**\n * Whether any node visible on `surface` matches, descending through container\n * children via `walk`. A node (or a container ancestor) hidden from `surface`\n * is skipped along with its children.\n *\n * `walk` must span every pack in the composition: a walker built from one\n * pack's definitions cannot see children of a container defined in another.\n */\nexport const someBodyNode = (\n nodes: readonly unknown[],\n surface: SurfaceName,\n predicate: (node: unknown) => boolean,\n walk: ChildNodeWalker\n): boolean =>\n nodes.some((node) => {\n if (!isVisibleOnSurface(node, surface)) {\n return false;\n }\n return (\n predicate(node) ||\n someBodyNode(\n walk(node).map((child) => child.node),\n surface,\n predicate,\n walk\n )\n );\n });\n\n/** Whether `node`'s own `surfaces` hint admits `surface`, ignoring its children. */\nexport const isVisibleOnSurface = (\n node: unknown,\n surface: SurfaceName\n): boolean => {\n if (!node || typeof node !== 'object') {\n return false;\n }\n const { surfaces } = node as { surfaces?: unknown };\n return !Array.isArray(surfaces) || surfaces.includes(surface);\n};\n\n/**\n * Whether `node` puts anything on `surface` — itself or through a descendant.\n *\n * Stronger than {@link isVisibleOnSurface}: a container every one of whose\n * children is hidden renders nothing, even though its own hint allows the\n * surface. A hybrid container that also owns string fields declares\n * {@link ChildNodeWalker.hasOwnContent} and keeps rendering regardless.\n */\nexport const rendersOnSurface = (\n node: unknown,\n surface: SurfaceName,\n walk: ChildNodeWalker\n): boolean => {\n if (!isVisibleOnSurface(node, surface)) {\n return false;\n }\n const children = walk(node);\n if (children.length === 0 || walk.hasOwnContent?.(node)) {\n return true;\n }\n return children.some(({ node: child }) =>\n rendersOnSurface(child, surface, walk)\n );\n};\n"]}
1
+ {"version":3,"file":"body_node_base.js","sourceRoot":"","sources":["../../../src/composition/body_node_base.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH;;;;;GAKG;AACU,QAAA,aAAa,GAAG;IAC3B,OAAO;IACP,UAAU;IACV,MAAM;IACN,UAAU;IACV,OAAO;CACC,CAAC;AAKX,6CAA6C;AAChC,QAAA,kBAAkB,GAA2B,qBAAa,CAAC;AAgCxE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AC,CAAC;AATW,QAAA,kBAAkB,sBAS7B;AAEF;;;;;;;GAOG;AACI,MAAM,gBAAgB,GAAG,CAC9B,IAAa,EACb,OAAoB,EACpB,IAAqB,EACZ,EAAE;IACX,IAAI,CAAC,IAAA,0BAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CACvC,IAAA,wBAAgB,EAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CACvC,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,gBAAgB,oBAe3B","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/**\n * Every surface a node renders on or is hidden from, in render order.\n *\n * `html` is not here: the runtime's `html` surface wraps `react` output in a\n * document, and no node targets it.\n */\nexport const SURFACE_NAMES = [\n 'react',\n 'snapshot',\n 'text',\n 'markdown',\n 'slack',\n] as const;\n\n/** One of the {@link SURFACE_NAMES}. */\nexport type SurfaceName = (typeof SURFACE_NAMES)[number];\n\n/** @deprecated Use {@link SURFACE_NAMES}. */\nexport const BODY_NODE_SURFACES: readonly SurfaceName[] = SURFACE_NAMES;\n\n/** The two fields every primitive node carries, whatever its pack. */\nexport interface BodyNodeBase {\n /** Unique within a composition, which `validate` enforces and `parse` does not. */\n id?: string;\n /** Surfaces this node appears on. Absent means every surface. */\n surfaces?: SurfaceName[];\n}\n\n/**\n * A child node together with the field path locating it inside its parent, so\n * an error path can name the field a child actually lives under. A container\n * that returned bare nodes would leave every caller guessing the field name.\n */\nexport interface ChildNodeRef {\n /** Erased: one walker spans every pack's node types, so it can name none of them. */\n node: unknown;\n /** Relative to the parent, e.g. `items[0].node`, `items[2].description`. */\n path: string;\n}\n\n/**\n * Walks nested nodes and, for a hybrid container, reports whether the parent\n * still produces output of its own. A non-empty `children` result is the\n * complete source of rendered content unless\n * {@link ChildNodeWalker.hasOwnContent} is true for that node.\n */\nexport type ChildNodeWalker = ((node: unknown) => ChildNodeRef[]) & {\n hasOwnContent?(node: unknown): boolean;\n};\n\n/**\n * Builds the {@link ChildNodeWalker} for one composition's inventory.\n *\n * Pass every pack's definitions: a walker missing one cannot see children of a\n * container that pack defines, and a tree walk would stop at its boundary.\n */\nexport const createChildNodeWalker = (\n definitions: readonly {\n type: string;\n children?: unknown;\n hasOwnContent?: unknown;\n }[]\n): ChildNodeWalker => {\n const childrenByType = new Map<\n string,\n (node: unknown) => readonly ChildNodeRef[]\n >();\n const ownContentByType = new Map<string, (node: unknown) => boolean>();\n for (const definition of definitions) {\n if (typeof definition.children === 'function') {\n childrenByType.set(\n definition.type,\n definition.children as (node: unknown) => readonly ChildNodeRef[]\n );\n }\n if (typeof definition.hasOwnContent === 'function') {\n ownContentByType.set(\n definition.type,\n definition.hasOwnContent as (node: unknown) => boolean\n );\n }\n }\n const walk = ((node: unknown) => {\n if (!node || typeof node !== 'object') {\n return [];\n }\n const { type } = node as { type?: unknown };\n if (typeof type !== 'string') {\n return [];\n }\n return [...(childrenByType.get(type)?.(node) ?? [])];\n }) as ChildNodeWalker;\n walk.hasOwnContent = (node) => {\n if (!node || typeof node !== 'object') {\n return false;\n }\n const { type } = node as { type?: unknown };\n if (typeof type !== 'string') {\n return false;\n }\n return ownContentByType.get(type)?.(node) ?? false;\n };\n return walk;\n};\n\n/** Joins a parent path with a {@link ChildNodeRef.path} fragment. */\nexport const childNodePath = (parent: string, child: string): string =>\n `${parent}.${child}`;\n\n/**\n * Whether any node visible on `surface` matches, descending through container\n * children via `walk`. A node (or a container ancestor) hidden from `surface`\n * is skipped along with its children.\n *\n * `walk` must span every pack in the composition: a walker built from one\n * pack's definitions cannot see children of a container defined in another.\n */\nexport const someBodyNode = (\n nodes: readonly unknown[],\n surface: SurfaceName,\n predicate: (node: unknown) => boolean,\n walk: ChildNodeWalker\n): boolean =>\n nodes.some((node) => {\n if (!isVisibleOnSurface(node, surface)) {\n return false;\n }\n return (\n predicate(node) ||\n someBodyNode(\n walk(node).map((child) => child.node),\n surface,\n predicate,\n walk\n )\n );\n });\n\n/** Whether `node`'s own `surfaces` hint admits `surface`, ignoring its children. */\nexport const isVisibleOnSurface = (\n node: unknown,\n surface: SurfaceName\n): boolean => {\n if (!node || typeof node !== 'object') {\n return false;\n }\n const { surfaces } = node as { surfaces?: unknown };\n return !Array.isArray(surfaces) || surfaces.includes(surface);\n};\n\n/**\n * Whether `node` puts anything on `surface` — itself or through a descendant.\n *\n * Stronger than {@link isVisibleOnSurface}: a container every one of whose\n * children is hidden renders nothing, even though its own hint allows the\n * surface. A hybrid container that also owns string fields declares\n * {@link ChildNodeWalker.hasOwnContent} and keeps rendering regardless.\n */\nexport const rendersOnSurface = (\n node: unknown,\n surface: SurfaceName,\n walk: ChildNodeWalker\n): boolean => {\n if (!isVisibleOnSurface(node, surface)) {\n return false;\n }\n const children = walk(node);\n if (children.length === 0 || walk.hasOwnContent?.(node)) {\n return true;\n }\n return children.some(({ node: child }) =>\n rendersOnSurface(child, surface, walk)\n );\n};\n"]}
@@ -23,6 +23,7 @@ exports.ISOMER_ERROR_CODES = {
23
23
  CYCLIC_COMPOSITION: 'CYCLIC_COMPOSITION',
24
24
  DUPLICATE_AUTHORED_CHILD: 'DUPLICATE_AUTHORED_CHILD',
25
25
  DUPLICATE_ENHANCEMENT: 'DUPLICATE_ENHANCEMENT',
26
+ DUPLICATE_FORMAT: 'DUPLICATE_FORMAT',
26
27
  DUPLICATE_PACK_ID: 'DUPLICATE_PACK_ID',
27
28
  DUPLICATE_PRIMITIVE_TYPE: 'DUPLICATE_PRIMITIVE_TYPE',
28
29
  DUPLICATE_VIEW: 'DUPLICATE_VIEW',
@@ -40,6 +41,7 @@ exports.ISOMER_ERROR_CODES = {
40
41
  INPUT_OVER_BUDGET: 'INPUT_OVER_BUDGET',
41
42
  INVALID_BODY_NODE: 'INVALID_BODY_NODE',
42
43
  INVALID_FRAME_BODY: 'INVALID_FRAME_BODY',
44
+ INVALID_PACK_GROUPS: 'INVALID_PACK_GROUPS',
43
45
  MISSING_AUTHORED_TEXT: 'MISSING_AUTHORED_TEXT',
44
46
  MISSING_STYLE_ADAPTER: 'MISSING_STYLE_ADAPTER',
45
47
  RESERVED_NODE_FIELD: 'RESERVED_NODE_FIELD',
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/composition/error.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH;;;;;;GAMG;AACU,QAAA,kBAAkB,GAAG;IAChC,eAAe,EAAE,iBAAiB;IAClC,uBAAuB,EAAE,yBAAyB;IAClD,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAChD,mBAAmB,EAAE,qBAAqB;IAC1C,kBAAkB,EAAE,oBAAoB;IACxC,wBAAwB,EAAE,0BAA0B;IACpD,qBAAqB,EAAE,uBAAuB;IAC9C,iBAAiB,EAAE,mBAAmB;IACtC,wBAAwB,EAAE,0BAA0B;IACpD,cAAc,EAAE,gBAAgB;IAChC,YAAY,EAAE,cAAc;IAC5B,UAAU,EAAE,YAAY;IACxB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,aAAa;IAC1B,gBAAgB,EAAE,kBAAkB;IACpC,wBAAwB,EAAE,0BAA0B;IACpD,yBAAyB,EAAE,2BAA2B;IACtD,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAChD,4BAA4B,EAAE,8BAA8B;IAC5D,oBAAoB,EAAE,sBAAsB;IAC5C,iBAAiB,EAAE,mBAAmB;IACtC,iBAAiB,EAAE,mBAAmB;IACtC,kBAAkB,EAAE,oBAAoB;IACxC,qBAAqB,EAAE,uBAAuB;IAC9C,qBAAqB,EAAE,uBAAuB;IAC9C,mBAAmB,EAAE,qBAAqB;IAC1C,mBAAmB,EAAE,qBAAqB;IAC1C,aAAa,EAAE,eAAe;IAC9B,sBAAsB,EAAE,wBAAwB;IAChD,eAAe,EAAE,iBAAiB;IAClC,YAAY,EAAE,cAAc;IAC5B,sBAAsB,EAAE,wBAAwB;IAChD,kBAAkB,EAAE,oBAAoB;IACxC,qBAAqB,EAAE,uBAAuB;CACtC,CAAC;AAMX;;;;;;;GAOG;AACH,MAAa,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAkB;IAE/B,YAAY,IAAqB,EAAE,OAAe;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AARD,kCAQC","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/**\n * Stable codes for {@link IsomerError}, {@link CompositionValidationError},\n * and the runtime's `RegisteredViewInputError`. Hosts branch on `code`, not\n * on `message`. Codes name the condition, not the throwing module: duplicate\n * type at `definePrimitivePack`, `composePacks`, and `createIsomerRuntime` is the same\n * `DUPLICATE_PRIMITIVE_TYPE`; the message names the layer.\n */\nexport const ISOMER_ERROR_CODES = {\n AMBIGUOUS_FRAME: 'AMBIGUOUS_FRAME',\n AMBIGUOUS_STYLE_ADAPTER: 'AMBIGUOUS_STYLE_ADAPTER',\n AUTHOR_TYPE_MISMATCH: 'AUTHOR_TYPE_MISMATCH',\n AUTHORED_SCHEMA_REUSED: 'AUTHORED_SCHEMA_REUSED',\n COMPOSITION_INVALID: 'COMPOSITION_INVALID',\n CYCLIC_COMPOSITION: 'CYCLIC_COMPOSITION',\n DUPLICATE_AUTHORED_CHILD: 'DUPLICATE_AUTHORED_CHILD',\n DUPLICATE_ENHANCEMENT: 'DUPLICATE_ENHANCEMENT',\n DUPLICATE_PACK_ID: 'DUPLICATE_PACK_ID',\n DUPLICATE_PRIMITIVE_TYPE: 'DUPLICATE_PRIMITIVE_TYPE',\n DUPLICATE_VIEW: 'DUPLICATE_VIEW',\n EMPTY_FRAMES: 'EMPTY_FRAMES',\n EMPTY_PACK: 'EMPTY_PACK',\n EMPTY_PACKS: 'EMPTY_PACKS',\n EMPTY_PAGES: 'EMPTY_PAGES',\n EMPTY_VOCABULARY: 'EMPTY_VOCABULARY',\n ENHANCEMENT_ROOT_MISSING: 'ENHANCEMENT_ROOT_MISSING',\n EXPECTED_AUTHOR_COMPONENT: 'EXPECTED_AUTHOR_COMPONENT',\n EXPECTED_JSX_ELEMENT: 'EXPECTED_JSX_ELEMENT',\n EXPECTED_TEXT_CHILDREN: 'EXPECTED_TEXT_CHILDREN',\n INCOMPATIBLE_STYLE_COLLECTOR: 'INCOMPATIBLE_STYLE_COLLECTOR',\n INPUT_NOT_PLAIN_DATA: 'INPUT_NOT_PLAIN_DATA',\n INPUT_OVER_BUDGET: 'INPUT_OVER_BUDGET',\n INVALID_BODY_NODE: 'INVALID_BODY_NODE',\n INVALID_FRAME_BODY: 'INVALID_FRAME_BODY',\n MISSING_AUTHORED_TEXT: 'MISSING_AUTHORED_TEXT',\n MISSING_STYLE_ADAPTER: 'MISSING_STYLE_ADAPTER',\n RESERVED_NODE_FIELD: 'RESERVED_NODE_FIELD',\n UNEXPECTED_CHILDREN: 'UNEXPECTED_CHILDREN',\n UNKNOWN_FRAME: 'UNKNOWN_FRAME',\n UNKNOWN_PRIMITIVE_TYPE: 'UNKNOWN_PRIMITIVE_TYPE',\n UNKNOWN_SURFACE: 'UNKNOWN_SURFACE',\n UNKNOWN_VIEW: 'UNKNOWN_VIEW',\n UNSUPPORTED_CHILD_PATH: 'UNSUPPORTED_CHILD_PATH',\n VIEW_INPUT_INVALID: 'VIEW_INPUT_INVALID',\n VOCABULARY_UNRESOLVED: 'VOCABULARY_UNRESOLVED',\n} as const;\n\n/** One of {@link ISOMER_ERROR_CODES}. */\nexport type IsomerErrorCode =\n (typeof ISOMER_ERROR_CODES)[keyof typeof ISOMER_ERROR_CODES];\n\n/**\n * Thrown for construction and authoring failures that are not a\n * `CompositionValidationError`.\n *\n * Identify it by `name` and `code`, never `instanceof`: the SDK ships both\n * ESM and CJS builds, so a host can hold two copies of this class and an\n * identity check would miss one.\n */\nexport class IsomerError extends Error {\n readonly code: IsomerErrorCode;\n\n constructor(code: IsomerErrorCode, message: string) {\n super(message);\n this.name = 'IsomerError';\n this.code = code;\n }\n}\n"]}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/composition/error.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH;;;;;;GAMG;AACU,QAAA,kBAAkB,GAAG;IAChC,eAAe,EAAE,iBAAiB;IAClC,uBAAuB,EAAE,yBAAyB;IAClD,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAChD,mBAAmB,EAAE,qBAAqB;IAC1C,kBAAkB,EAAE,oBAAoB;IACxC,wBAAwB,EAAE,0BAA0B;IACpD,qBAAqB,EAAE,uBAAuB;IAC9C,gBAAgB,EAAE,kBAAkB;IACpC,iBAAiB,EAAE,mBAAmB;IACtC,wBAAwB,EAAE,0BAA0B;IACpD,cAAc,EAAE,gBAAgB;IAChC,YAAY,EAAE,cAAc;IAC5B,UAAU,EAAE,YAAY;IACxB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,aAAa;IAC1B,gBAAgB,EAAE,kBAAkB;IACpC,wBAAwB,EAAE,0BAA0B;IACpD,yBAAyB,EAAE,2BAA2B;IACtD,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAChD,4BAA4B,EAAE,8BAA8B;IAC5D,oBAAoB,EAAE,sBAAsB;IAC5C,iBAAiB,EAAE,mBAAmB;IACtC,iBAAiB,EAAE,mBAAmB;IACtC,kBAAkB,EAAE,oBAAoB;IACxC,mBAAmB,EAAE,qBAAqB;IAC1C,qBAAqB,EAAE,uBAAuB;IAC9C,qBAAqB,EAAE,uBAAuB;IAC9C,mBAAmB,EAAE,qBAAqB;IAC1C,mBAAmB,EAAE,qBAAqB;IAC1C,aAAa,EAAE,eAAe;IAC9B,sBAAsB,EAAE,wBAAwB;IAChD,eAAe,EAAE,iBAAiB;IAClC,YAAY,EAAE,cAAc;IAC5B,sBAAsB,EAAE,wBAAwB;IAChD,kBAAkB,EAAE,oBAAoB;IACxC,qBAAqB,EAAE,uBAAuB;CACtC,CAAC;AAMX;;;;;;;GAOG;AACH,MAAa,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAkB;IAE/B,YAAY,IAAqB,EAAE,OAAe;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AARD,kCAQC","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/**\n * Stable codes for {@link IsomerError}, {@link CompositionValidationError},\n * and the runtime's `RegisteredViewInputError`. Hosts branch on `code`, not\n * on `message`. Codes name the condition, not the throwing module: duplicate\n * type at `definePrimitivePack`, `composePacks`, and `createIsomerRuntime` is the same\n * `DUPLICATE_PRIMITIVE_TYPE`; the message names the layer.\n */\nexport const ISOMER_ERROR_CODES = {\n AMBIGUOUS_FRAME: 'AMBIGUOUS_FRAME',\n AMBIGUOUS_STYLE_ADAPTER: 'AMBIGUOUS_STYLE_ADAPTER',\n AUTHOR_TYPE_MISMATCH: 'AUTHOR_TYPE_MISMATCH',\n AUTHORED_SCHEMA_REUSED: 'AUTHORED_SCHEMA_REUSED',\n COMPOSITION_INVALID: 'COMPOSITION_INVALID',\n CYCLIC_COMPOSITION: 'CYCLIC_COMPOSITION',\n DUPLICATE_AUTHORED_CHILD: 'DUPLICATE_AUTHORED_CHILD',\n DUPLICATE_ENHANCEMENT: 'DUPLICATE_ENHANCEMENT',\n DUPLICATE_FORMAT: 'DUPLICATE_FORMAT',\n DUPLICATE_PACK_ID: 'DUPLICATE_PACK_ID',\n DUPLICATE_PRIMITIVE_TYPE: 'DUPLICATE_PRIMITIVE_TYPE',\n DUPLICATE_VIEW: 'DUPLICATE_VIEW',\n EMPTY_FRAMES: 'EMPTY_FRAMES',\n EMPTY_PACK: 'EMPTY_PACK',\n EMPTY_PACKS: 'EMPTY_PACKS',\n EMPTY_PAGES: 'EMPTY_PAGES',\n EMPTY_VOCABULARY: 'EMPTY_VOCABULARY',\n ENHANCEMENT_ROOT_MISSING: 'ENHANCEMENT_ROOT_MISSING',\n EXPECTED_AUTHOR_COMPONENT: 'EXPECTED_AUTHOR_COMPONENT',\n EXPECTED_JSX_ELEMENT: 'EXPECTED_JSX_ELEMENT',\n EXPECTED_TEXT_CHILDREN: 'EXPECTED_TEXT_CHILDREN',\n INCOMPATIBLE_STYLE_COLLECTOR: 'INCOMPATIBLE_STYLE_COLLECTOR',\n INPUT_NOT_PLAIN_DATA: 'INPUT_NOT_PLAIN_DATA',\n INPUT_OVER_BUDGET: 'INPUT_OVER_BUDGET',\n INVALID_BODY_NODE: 'INVALID_BODY_NODE',\n INVALID_FRAME_BODY: 'INVALID_FRAME_BODY',\n INVALID_PACK_GROUPS: 'INVALID_PACK_GROUPS',\n MISSING_AUTHORED_TEXT: 'MISSING_AUTHORED_TEXT',\n MISSING_STYLE_ADAPTER: 'MISSING_STYLE_ADAPTER',\n RESERVED_NODE_FIELD: 'RESERVED_NODE_FIELD',\n UNEXPECTED_CHILDREN: 'UNEXPECTED_CHILDREN',\n UNKNOWN_FRAME: 'UNKNOWN_FRAME',\n UNKNOWN_PRIMITIVE_TYPE: 'UNKNOWN_PRIMITIVE_TYPE',\n UNKNOWN_SURFACE: 'UNKNOWN_SURFACE',\n UNKNOWN_VIEW: 'UNKNOWN_VIEW',\n UNSUPPORTED_CHILD_PATH: 'UNSUPPORTED_CHILD_PATH',\n VIEW_INPUT_INVALID: 'VIEW_INPUT_INVALID',\n VOCABULARY_UNRESOLVED: 'VOCABULARY_UNRESOLVED',\n} as const;\n\n/** One of {@link ISOMER_ERROR_CODES}. */\nexport type IsomerErrorCode =\n (typeof ISOMER_ERROR_CODES)[keyof typeof ISOMER_ERROR_CODES];\n\n/**\n * Thrown for construction and authoring failures that are not a\n * `CompositionValidationError`.\n *\n * Identify it by `name` and `code`, never `instanceof`: the SDK ships both\n * ESM and CJS builds, so a host can hold two copies of this class and an\n * identity check would miss one.\n */\nexport class IsomerError extends Error {\n readonly code: IsomerErrorCode;\n\n constructor(code: IsomerErrorCode, message: string) {\n super(message);\n this.name = 'IsomerError';\n this.code = code;\n }\n}\n"]}
@@ -6,9 +6,10 @@
6
6
  * 2.0.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.formatValidationError = exports.CompositionValidationError = exports.STRUCTURED_VALUE_FORMATS = exports.quoteText = exports.oneLine = exports.nameText = exports.ALL_NAMED_COLORS = exports.mapCompositionNodes = exports.IsomerError = exports.ISOMER_ERROR_CODES = exports.someBodyNode = exports.isVisibleOnSurface = exports.createChildNodeWalker = exports.BODY_NODE_SURFACES = void 0;
9
+ exports.formatValidationError = exports.CompositionValidationError = exports.STRUCTURED_VALUE_FORMATS = exports.quoteText = exports.oneLine = exports.nameText = exports.ALL_NAMED_COLORS = exports.mapCompositionNodes = exports.IsomerError = exports.ISOMER_ERROR_CODES = exports.someBodyNode = exports.isVisibleOnSurface = exports.createChildNodeWalker = exports.SURFACE_NAMES = exports.BODY_NODE_SURFACES = void 0;
10
10
  var body_node_base_1 = require("./body_node_base");
11
11
  Object.defineProperty(exports, "BODY_NODE_SURFACES", { enumerable: true, get: function () { return body_node_base_1.BODY_NODE_SURFACES; } });
12
+ Object.defineProperty(exports, "SURFACE_NAMES", { enumerable: true, get: function () { return body_node_base_1.SURFACE_NAMES; } });
12
13
  Object.defineProperty(exports, "createChildNodeWalker", { enumerable: true, get: function () { return body_node_base_1.createChildNodeWalker; } });
13
14
  Object.defineProperty(exports, "isVisibleOnSurface", { enumerable: true, get: function () { return body_node_base_1.isVisibleOnSurface; } });
14
15
  Object.defineProperty(exports, "someBodyNode", { enumerable: true, get: function () { return body_node_base_1.someBodyNode; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/composition/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,mDAS0B;AAJxB,oHAAA,kBAAkB,OAAA;AAClB,uHAAA,qBAAqB,OAAA;AACrB,oHAAA,kBAAkB,OAAA;AAClB,8GAAA,YAAY,OAAA;AAGd,iCAAgF;AAAjD,2GAAA,kBAAkB,OAAA;AAAE,oGAAA,WAAW,OAAA;AAC9D,yCAAkD;AAAzC,gHAAA,mBAAmB,OAAA;AAC5B,6CAKuB;AADrB,+GAAA,gBAAgB,OAAA;AAGlB,uCAA0D;AAAjD,oGAAA,QAAQ,OAAA;AAAE,mGAAA,OAAO,OAAA;AAAE,qGAAA,SAAS,OAAA;AACrC,uDAK4B;AAD1B,4HAAA,wBAAwB,OAAA;AAE1B,uDAI4B;AAF1B,8HAAA,0BAA0B,OAAA;AAC1B,yHAAA,qBAAqB,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 { type ActionEventRef } from './action_event';\nexport {\n type BodyNodeBase,\n type ChildNodeRef,\n type ChildNodeWalker,\n type SurfaceName,\n BODY_NODE_SURFACES,\n createChildNodeWalker,\n isVisibleOnSurface,\n someBodyNode,\n} from './body_node_base';\nexport { type Composition, type CompositionMeta } from './composition';\nexport { type IsomerErrorCode, ISOMER_ERROR_CODES, IsomerError } from './error';\nexport { mapCompositionNodes } from './map_nodes';\nexport {\n type NamedColor,\n type NamedColorPalette,\n type RenderTheme,\n ALL_NAMED_COLORS,\n} from './named_color';\nexport { type PrimitiveNode } from './node';\nexport { nameText, oneLine, quoteText } from './one_line';\nexport {\n type DisplayValue,\n type StructuredValue,\n type StructuredValueFormat,\n STRUCTURED_VALUE_FORMATS,\n} from './structured_value';\nexport {\n type ValidationError,\n CompositionValidationError,\n formatValidationError,\n} from './validation_error';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/composition/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,mDAU0B;AALxB,oHAAA,kBAAkB,OAAA;AAClB,+GAAA,aAAa,OAAA;AACb,uHAAA,qBAAqB,OAAA;AACrB,oHAAA,kBAAkB,OAAA;AAClB,8GAAA,YAAY,OAAA;AAGd,iCAAgF;AAAjD,2GAAA,kBAAkB,OAAA;AAAE,oGAAA,WAAW,OAAA;AAC9D,yCAAkD;AAAzC,gHAAA,mBAAmB,OAAA;AAC5B,6CAKuB;AADrB,+GAAA,gBAAgB,OAAA;AAGlB,uCAA0D;AAAjD,oGAAA,QAAQ,OAAA;AAAE,mGAAA,OAAO,OAAA;AAAE,qGAAA,SAAS,OAAA;AACrC,uDAK4B;AAD1B,4HAAA,wBAAwB,OAAA;AAE1B,uDAI4B;AAF1B,8HAAA,0BAA0B,OAAA;AAC1B,yHAAA,qBAAqB,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 { type ActionEventRef } from './action_event';\nexport {\n type BodyNodeBase,\n type ChildNodeRef,\n type ChildNodeWalker,\n type SurfaceName,\n BODY_NODE_SURFACES,\n SURFACE_NAMES,\n createChildNodeWalker,\n isVisibleOnSurface,\n someBodyNode,\n} from './body_node_base';\nexport { type Composition, type CompositionMeta } from './composition';\nexport { type IsomerErrorCode, ISOMER_ERROR_CODES, IsomerError } from './error';\nexport { mapCompositionNodes } from './map_nodes';\nexport {\n type NamedColor,\n type NamedColorPalette,\n type RenderTheme,\n ALL_NAMED_COLORS,\n} from './named_color';\nexport { type PrimitiveNode } from './node';\nexport { nameText, oneLine, quoteText } from './one_line';\nexport {\n type DisplayValue,\n type StructuredValue,\n type StructuredValueFormat,\n STRUCTURED_VALUE_FORMATS,\n} from './structured_value';\nexport {\n type ValidationError,\n CompositionValidationError,\n formatValidationError,\n} from './validation_error';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"structured_value.js","sourceRoot":"","sources":["../../../src/composition/structured_value.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwD;AAC3C,QAAA,wBAAwB,GAAG;IACtC,QAAQ;IACR,SAAS;IACT,SAAS;IACT,UAAU;IACV,OAAO;IACP,UAAU;IACV,MAAM;IACN,cAAc;CACN,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/** Format hints a {@link StructuredValue} may carry. */\nexport const STRUCTURED_VALUE_FORMATS = [\n 'number',\n 'compact',\n 'percent',\n 'currency',\n 'bytes',\n 'duration',\n 'date',\n 'relativeTime',\n] as const;\n\n/** One of {@link STRUCTURED_VALUE_FORMATS}. */\nexport type StructuredValueFormat = (typeof STRUCTURED_VALUE_FORMATS)[number];\n\n/**\n * A raw quantity plus a format hint, so every surface renders the same string.\n *\n * Formatting happens once, in `formatDisplayValue`, rather than per renderer —\n * otherwise the text and Slack surfaces drift on rounding.\n */\nexport interface StructuredValue {\n /** Unformatted, in base units — a `percent` of `0.42` renders as 42%. */\n raw: number | string;\n /** How to render `raw`. Absent passes a string through and gives a number default formatting. */\n format?: StructuredValueFormat;\n /**\n * Fraction digits for numeric formats. `number`, `percent`, and `currency`\n * pad to it; omitted, `number` and `percent` keep at most two and `currency`\n * two. `compact` and `bytes` drop trailing zeros and keep one when omitted.\n */\n precision?: number;\n /** Three-letter currency code for `currency`; defaults to USD. */\n currency?: string;\n}\n\n/** A value-bearing field: preformatted prose, or a {@link StructuredValue} to format. */\nexport type DisplayValue = string | StructuredValue;\n"]}
1
+ {"version":3,"file":"structured_value.js","sourceRoot":"","sources":["../../../src/composition/structured_value.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwD;AAC3C,QAAA,wBAAwB,GAAG;IACtC,QAAQ;IACR,SAAS;IACT,SAAS;IACT,UAAU;IACV,OAAO;IACP,UAAU;IACV,MAAM;IACN,cAAc;CACN,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/** Format hints a {@link StructuredValue} may carry. */\nexport const STRUCTURED_VALUE_FORMATS = [\n 'number',\n 'compact',\n 'percent',\n 'currency',\n 'bytes',\n 'duration',\n 'date',\n 'relativeTime',\n] as const;\n\n/** One of {@link STRUCTURED_VALUE_FORMATS}. */\nexport type StructuredValueFormat = (typeof STRUCTURED_VALUE_FORMATS)[number];\n\n/**\n * A raw quantity plus a format hint, so every surface renders the same string.\n *\n * Formatting happens once, in `formatDisplayValue`, rather than per renderer —\n * otherwise the text and Slack surfaces drift on rounding.\n */\nexport interface StructuredValue {\n /** Unformatted, in base units — a `percent` of `0.42` renders as 42%. */\n raw: number | string;\n /** How to render `raw`. Absent passes a string through and gives a number default formatting. */\n format?: StructuredValueFormat | undefined;\n /**\n * Fraction digits for numeric formats. `number`, `percent`, and `currency`\n * pad to it; omitted, `number` and `percent` keep at most two and `currency`\n * two. `compact` and `bytes` drop trailing zeros and keep one when omitted.\n */\n precision?: number | undefined;\n /** Three-letter currency code for `currency`; defaults to USD. */\n currency?: string | undefined;\n}\n\n/** A value-bearing field: preformatted prose, or a {@link StructuredValue} to format. */\nexport type DisplayValue = string | StructuredValue;\n"]}
@@ -16,16 +16,15 @@ const bindFrame = (frame) => {
16
16
  const themeFor = (mode) => mode === 'dark' ? frame.theme.dark : frame.theme.light;
17
17
  return {
18
18
  defaultWidth: frame.defaultWidth,
19
- sizesFromNodeHeights: frame.sizesFromNodeHeights ?? true,
20
19
  estimateHeight: (composition, dispatcher) => frame.estimateHeight(composition, dispatcher),
21
20
  validateBody: (body) => frame.validateBody?.(body) ?? [],
22
21
  resolveTheme: (mode) => themeFor(mode),
23
22
  render: (composition, viewport, dispatcher) => {
24
23
  const theme = themeFor(viewport.mode);
25
24
  const { title, subtitle, theme: mode } = composition;
26
- return frame.wrap({ title, subtitle, theme: mode }, composition.body.map((node, index) => dispatcher.renderSvg(node, `body-${index}`)), { ...viewport, theme });
25
+ return frame.wrap({ title, subtitle, theme: mode }, composition.body.map((node, index) => dispatcher.renderSnapshot(node, `body-${index}`)), { ...viewport, theme });
27
26
  },
28
- renderNode: (node, dispatcher) => dispatcher.renderSvg(node, node.type),
27
+ renderNode: (node, dispatcher) => dispatcher.renderSnapshot(node, node.type),
29
28
  };
30
29
  };
31
30
  exports.bindFrame = bindFrame;
@@ -1 +1 @@
1
- {"version":3,"file":"frame.js","sourceRoot":"","sources":["../../../src/define/frame.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAyLH;;;;GAIG;AACI,MAAM,SAAS,GAAG,CAAS,KAAoB,EAAc,EAAE;IACpE,MAAM,QAAQ,GAAG,CAAC,IAA6B,EAAU,EAAE,CACzD,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAA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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 frame an `svg` render is drawn inside, and the geometry that sizes it.\n// Frame is a runtime input, not a pack asset: vocabulary is additive, the\n// document is exclusive.\n\nimport type { ReactNode } from 'react';\n\nimport type { RenderTheme } from '../composition/named_color';\nimport type { PrimitiveNode } from '../composition/node';\n\n/**\n * A frame's palette, per mode. An image has no media queries, so it must\n * commit to one; `auto` resolves light.\n */\nexport interface ThemePair<TTheme> {\n light: TTheme;\n dark: TTheme;\n}\n\n/**\n * Geometry and resolved theme a frame draws within.\n *\n * Named for the viewport rather than the frame because {@link Frame.wrap}\n * draws *a* frame within it; the two would otherwise read as the same thing.\n */\nexport interface FrameViewport<TTheme> {\n width: number;\n height: number;\n /** Resolved from {@link Frame.theme} for `mode`. */\n theme: TTheme;\n /** What the caller asked for, before resolution. `undefined` and `auto` both resolve light. */\n mode: RenderTheme | undefined;\n}\n\n/**\n * The two dispatcher methods a frame needs.\n *\n * The render context the nodes are drawn with is bound by the caller rather\n * than passed here: it carries the class-name resolution that pairs with the\n * stylesheet emitted alongside the frame's output, which is the surface's\n * concern and not the document's. Generic in `TNode` so a helper can be\n * written against a narrowed node union while the runtime holds the erased form.\n */\nexport interface FrameDispatcher<TNode extends PrimitiveNode = PrimitiveNode> {\n /** Draws one node on the `svg` surface. `key` must be unique among its siblings. */\n renderSvg(node: TNode, key: string): ReactNode;\n /** The node's height in pixels; `0` when it is hidden from `svg` or its primitive declares no `metrics.svgHeight`. */\n estimateSvgHeight(node: TNode): number;\n}\n\n/**\n * What {@link Frame.wrap} is told about the composition it draws around.\n *\n * The body is withheld, and {@link bindFrame} copies only these fields into a\n * fresh value, so the surround cannot branch on a pack's node types.\n */\nexport interface FrameHeader {\n title?: string | undefined;\n subtitle?: string | undefined;\n /** The caller's preference, not a resolved palette. Use {@link FrameViewport.theme} to draw. */\n theme?: RenderTheme | undefined;\n}\n\n/** {@link FrameHeader} plus the body, for the sizing and validation hooks. */\nexport interface FrameComposition extends FrameHeader {\n /** Raw nodes, for measuring and checking only. {@link FrameBody} is what gets drawn. */\n body: PrimitiveNode[];\n}\n\n/**\n * Body nodes already rendered to elements, ready to be surrounded.\n *\n * Distinct from `Composition.body`, which is the raw {@link PrimitiveNode}\n * array a frame never sees.\n */\nexport type FrameBody = readonly ReactNode[];\n\n/**\n * A document an `svg` render can produce: its geometry, the surround it draws\n * around the body, and whatever it requires of a composition it is asked to\n * draw.\n *\n * A host registers frames with the runtime and picks one per render. That is\n * what lets one runtime serve a 760px card, a 1920x1080 slide, and a\n * host-branded variant of either from the same vocabulary — and what keeps a\n * vocabulary pack additive, since nothing about a primitive decides the frame.\n * A frame is named by the key a host registers it under, not by a field it\n * carries.\n */\nexport interface Frame<TTheme> {\n /** Width used when the caller passes none. */\n defaultWidth: number;\n /**\n * Whether {@link Frame.estimateHeight} sums per-node heights, and so\n * under-sizes the frame for a node whose primitive declares no\n * `metrics.svgHeight` — `dispatcher.estimateSvgHeight` returns `0` for those.\n *\n * Defaults to `true`, because the gap is silent and a frame that measures\n * nodes is the normal case. A fixed-size frame sets `false` once and stops\n * the missing `svgHeight` warning reporting a metric nothing reads.\n */\n sizesFromNodeHeights?: boolean;\n /**\n * Palette per mode. Frame and palette vary independently — a branded card is\n * this geometry with a host's colors — so a host overrides one by spreading\n * this value rather than rebuilding anything.\n */\n theme: ThemePair<TTheme>;\n /**\n * Height for this body when the caller passes none, in the geometry this\n * document defines. See {@link Frame.sizesFromNodeHeights} for what it may\n * assume of the nodes.\n */\n estimateHeight(\n composition: FrameComposition,\n dispatcher: FrameDispatcher\n ): number;\n /**\n * What this document requires of a body. A slide document's\n * exactly-one-`slideFrame` rule is the example.\n *\n * Returned rather than thrown so a caller can decide what to do with it, but\n * note where it is *not* checked: composition validation is frame-agnostic,\n * and has to be, because the same composition can be valid in one frame and\n * not another. Only the `svg` surface consults this, on the frame a render\n * actually names, and raises before drawing. A host that wants the answer\n * earlier asks the frame directly.\n */\n validateBody?(body: readonly PrimitiveNode[]): readonly string[];\n /**\n * Draws the surround around the already-rendered body nodes, including a\n * title header if this document wants one.\n *\n * Takes the nodes as an array rather than a single `ReactNode` so a frame\n * that draws no surround can return its one root element — image layout\n * starts from a single element, and an array or a fragment is not one.\n *\n * Declared property-style, so it is checked contravariantly in `TTheme` under\n * `strictFunctionTypes`. A method signature is bivariant, which would admit a\n * frame needing a richer theme into a slot typed for a narrower one, where it\n * would read a token nothing supplies.\n */\n wrap: (\n header: FrameHeader,\n body: FrameBody,\n viewport: FrameViewport<TTheme>\n ) => ReactNode;\n}\n\n/**\n * A {@link Frame} as the runtime stores it, with its theme resolved away.\n *\n * The erasure is a closure rather than a type parameter because the runtime\n * dispatches nodes through one inventory keyed by node type, which has no\n * single theme to name. A runtime's frames are homogeneous in `TTheme`, so the\n * palette is known where it is resolved and only the resolved result is stored.\n */\nexport interface BoundFrame {\n readonly defaultWidth: number;\n /** See {@link Frame.sizesFromNodeHeights}; defaulted at binding. */\n readonly sizesFromNodeHeights: boolean;\n /** See {@link Frame.estimateHeight}. */\n estimateHeight(\n composition: FrameComposition,\n dispatcher: FrameDispatcher\n ): number;\n /** See {@link Frame.validateBody}; empty when this frame states no rule. */\n validateBody(body: readonly PrimitiveNode[]): readonly string[];\n /**\n * Resolves {@link Frame.theme} for `mode`, erased to `unknown` like the rest\n * of this type. Lets a caller hand the palette to a primitive's `env.theme`\n * without itself knowing `TTheme`.\n */\n resolveTheme(mode: RenderTheme | undefined): unknown;\n /** Renders the body and its surround at `viewport`'s geometry. */\n render(\n composition: FrameComposition,\n viewport: { width: number; height: number; mode: RenderTheme | undefined },\n dispatcher: FrameDispatcher\n ): ReactNode;\n /** One node, no surround. */\n renderNode(node: PrimitiveNode, dispatcher: FrameDispatcher): ReactNode;\n}\n\n/**\n * Erases a {@link Frame}'s `TTheme` into a {@link BoundFrame}, resolving the\n * palette per render and composing the generic body walk with the frame's own\n * surround.\n */\nexport const bindFrame = <TTheme>(frame: Frame<TTheme>): BoundFrame => {\n const themeFor = (mode: RenderTheme | undefined): TTheme =>\n mode === 'dark' ? frame.theme.dark : frame.theme.light;\n return {\n defaultWidth: frame.defaultWidth,\n sizesFromNodeHeights: frame.sizesFromNodeHeights ?? true,\n estimateHeight: (composition, dispatcher) =>\n frame.estimateHeight(composition, dispatcher),\n validateBody: (body) => frame.validateBody?.(body) ?? [],\n resolveTheme: (mode) => themeFor(mode),\n render: (composition, viewport, dispatcher) => {\n const theme = themeFor(viewport.mode);\n const { title, subtitle, theme: mode } = composition;\n return frame.wrap(\n { title, subtitle, theme: mode },\n composition.body.map((node, index) =>\n dispatcher.renderSvg(node, `body-${index}`)\n ),\n { ...viewport, theme }\n );\n },\n renderNode: (node, dispatcher) => dispatcher.renderSvg(node, node.type),\n };\n};\n"]}
1
+ {"version":3,"file":"frame.js","sourceRoot":"","sources":["../../../src/define/frame.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA8KH;;;;GAIG;AACI,MAAM,SAAS,GAAG,CAAS,KAAoB,EAAc,EAAE;IACpE,MAAM,QAAQ,GAAG,CAAC,IAA6B,EAAU,EAAE,CACzD,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;IACzD,OAAO;QACL,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,cAAc,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,EAAE,CAC1C,KAAK,CAAC,cAAc,CAAC,WAAW,EAAE,UAAU,CAAC;QAC/C,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE;QACxD,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;QACtC,MAAM,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE;YAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;YACrD,OAAO,KAAK,CAAC,IAAI,CACf,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,EAChC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACnC,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,KAAK,EAAE,CAAC,CACjD,EACD,EAAE,GAAG,QAAQ,EAAE,KAAK,EAAE,CACvB,CAAC;QACJ,CAAC;QACD,UAAU,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAC/B,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC;KAC7C,CAAC;AACJ,CAAC,CAAC;AAvBW,QAAA,SAAS,aAuBpB","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 frame a `snapshot` render is drawn inside, and the geometry that sizes it.\n// Frame is a runtime input, not a pack asset: vocabulary is additive, the\n// document is exclusive.\n\nimport type { ReactNode } from 'react';\n\nimport type { RenderTheme } from '../composition/named_color';\nimport type { PrimitiveNode } from '../composition/node';\n\n/**\n * A frame's palette, per mode. An image has no media queries, so it must\n * commit to one; `auto` resolves light.\n */\nexport interface ThemePair<TTheme> {\n light: TTheme;\n dark: TTheme;\n}\n\n/**\n * Geometry and resolved theme a frame draws within.\n *\n * Named for the viewport rather than the frame because {@link Frame.wrap}\n * draws *a* frame within it; the two would otherwise read as the same thing.\n */\nexport interface FrameViewport<TTheme> {\n width: number;\n height: number;\n /** Resolved from {@link Frame.theme} for `mode`. */\n theme: TTheme;\n /** What the caller asked for, before resolution. `undefined` and `auto` both resolve light. */\n mode: RenderTheme | undefined;\n}\n\n/**\n * The two dispatcher methods a frame needs.\n *\n * The render context the nodes are drawn with is bound by the caller rather\n * than passed here: it carries the class-name resolution that pairs with the\n * stylesheet emitted alongside the frame's output, which is the surface's\n * concern and not the document's. Generic in `TNode` so a helper can be\n * written against a narrowed node union while the runtime holds the erased form.\n */\nexport interface FrameDispatcher<TNode extends PrimitiveNode = PrimitiveNode> {\n /** Draws one node on the `snapshot` surface. `key` must be unique among its siblings. */\n renderSnapshot(node: TNode, key: string): ReactNode;\n /** The node's height in pixels; `0` when it is hidden from `snapshot` or its primitive declares no `metrics.snapshotHeight`. */\n estimateSnapshotHeight(node: TNode): number;\n}\n\n/**\n * What {@link Frame.wrap} is told about the composition it draws around.\n *\n * The body is withheld, and {@link bindFrame} copies only these fields into a\n * fresh value, so the surround cannot branch on a pack's node types.\n */\nexport interface FrameHeader {\n title?: string | undefined;\n subtitle?: string | undefined;\n /** The caller's preference, not a resolved palette. Use {@link FrameViewport.theme} to draw. */\n theme?: RenderTheme | undefined;\n}\n\n/** {@link FrameHeader} plus the body, for the sizing and validation hooks. */\nexport interface FrameComposition extends FrameHeader {\n /** Raw nodes, for measuring and checking only. {@link FrameBody} is what gets drawn. */\n body: PrimitiveNode[];\n}\n\n/**\n * Body nodes already rendered to elements, ready to be surrounded.\n *\n * Distinct from `Composition.body`, which is the raw {@link PrimitiveNode}\n * array a frame never sees.\n */\nexport type FrameBody = readonly ReactNode[];\n\n/**\n * A document a `snapshot` render can produce: its geometry, the surround it draws\n * around the body, and whatever it requires of a composition it is asked to\n * draw.\n *\n * A host registers frames with the runtime and picks one per render. That is\n * what lets one runtime serve a 760px card, a 1920x1080 slide, and a\n * host-branded variant of either from the same vocabulary — and what keeps a\n * vocabulary pack additive, since nothing about a primitive decides the frame.\n * A frame is named by the key a host registers it under, not by a field it\n * carries.\n */\nexport interface Frame<TTheme> {\n /** Width used when the caller passes none. */\n defaultWidth: number;\n /**\n * Palette per mode. Frame and palette vary independently — a branded card is\n * this geometry with a host's colors — so a host overrides one by spreading\n * this value rather than rebuilding anything.\n */\n theme: ThemePair<TTheme>;\n /**\n * Height for this body when the caller passes none, in the geometry this\n * document defines. Calling {@link FrameDispatcher.estimateSnapshotHeight} is\n * what makes a missing `metrics.snapshotHeight` size the frame short: that\n * method returns `0` for a node whose primitive declares none.\n */\n estimateHeight(\n composition: FrameComposition,\n dispatcher: FrameDispatcher\n ): number;\n /**\n * What this document requires of a body. A slide document's\n * exactly-one-`slideFrame` rule is the example.\n *\n * Returned rather than thrown so a caller can decide what to do with it, but\n * note where it is *not* checked: composition validation is frame-agnostic,\n * and has to be, because the same composition can be valid in one frame and\n * not another. Only the `snapshot` surface consults this, on the frame a render\n * actually names, and raises before drawing. A host that wants the answer\n * earlier asks the frame directly.\n */\n validateBody?(body: readonly PrimitiveNode[]): readonly string[];\n /**\n * Draws the surround around the already-rendered body nodes, including a\n * title header if this document wants one.\n *\n * Takes the nodes as an array rather than a single `ReactNode` so a frame\n * that draws no surround can return its one root element — image layout\n * starts from a single element, and an array or a fragment is not one.\n *\n * Declared property-style, so it is checked contravariantly in `TTheme` under\n * `strictFunctionTypes`. A method signature is bivariant, which would admit a\n * frame needing a richer theme into a slot typed for a narrower one, where it\n * would read a token nothing supplies.\n */\n wrap: (\n header: FrameHeader,\n body: FrameBody,\n viewport: FrameViewport<TTheme>\n ) => ReactNode;\n}\n\n/**\n * A {@link Frame} as the runtime stores it, with its theme resolved away.\n *\n * The erasure is a closure rather than a type parameter because the runtime\n * dispatches nodes through one inventory keyed by node type, which has no\n * single theme to name. A runtime's frames are homogeneous in `TTheme`, so the\n * palette is known where it is resolved and only the resolved result is stored.\n */\nexport interface BoundFrame {\n readonly defaultWidth: number;\n /** See {@link Frame.estimateHeight}. */\n estimateHeight(\n composition: FrameComposition,\n dispatcher: FrameDispatcher\n ): number;\n /** See {@link Frame.validateBody}; empty when this frame states no rule. */\n validateBody(body: readonly PrimitiveNode[]): readonly string[];\n /**\n * Resolves {@link Frame.theme} for `mode`, erased to `unknown` like the rest\n * of this type. Lets a caller hand the palette to a primitive's `env.theme`\n * without itself knowing `TTheme`.\n */\n resolveTheme(mode: RenderTheme | undefined): unknown;\n /** Renders the body and its surround at `viewport`'s geometry. */\n render(\n composition: FrameComposition,\n viewport: { width: number; height: number; mode: RenderTheme | undefined },\n dispatcher: FrameDispatcher\n ): ReactNode;\n /** One node, no surround. */\n renderNode(node: PrimitiveNode, dispatcher: FrameDispatcher): ReactNode;\n}\n\n/**\n * Erases a {@link Frame}'s `TTheme` into a {@link BoundFrame}, resolving the\n * palette per render and composing the generic body walk with the frame's own\n * surround.\n */\nexport const bindFrame = <TTheme>(frame: Frame<TTheme>): BoundFrame => {\n const themeFor = (mode: RenderTheme | undefined): TTheme =>\n mode === 'dark' ? frame.theme.dark : frame.theme.light;\n return {\n defaultWidth: frame.defaultWidth,\n estimateHeight: (composition, dispatcher) =>\n frame.estimateHeight(composition, dispatcher),\n validateBody: (body) => frame.validateBody?.(body) ?? [],\n resolveTheme: (mode) => themeFor(mode),\n render: (composition, viewport, dispatcher) => {\n const theme = themeFor(viewport.mode);\n const { title, subtitle, theme: mode } = composition;\n return frame.wrap(\n { title, subtitle, theme: mode },\n composition.body.map((node, index) =>\n dispatcher.renderSnapshot(node, `body-${index}`)\n ),\n { ...viewport, theme }\n );\n },\n renderNode: (node, dispatcher) =>\n dispatcher.renderSnapshot(node, node.type),\n };\n};\n"]}
@@ -6,10 +6,16 @@
6
6
  * 2.0.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.z = exports.requiredString = exports.formatZodIssues = exports.declaredFieldsNote = exports.validateWithSchema = exports.unresolvedBodyNodeSchema = exports.definePrimitiveFor = exports.definePrimitive = exports.bodyNodeSurfacesSchema = exports.bodyNodeIdSchema = exports.bindFrame = void 0;
9
+ exports.z = exports.requiredString = exports.formatZodIssues = exports.declaredFieldsNote = exports.validateWithSchema = exports.unresolvedBodyNodeSchema = exports.definePrimitiveFor = exports.definePrimitive = exports.bodyNodeSurfacesSchema = exports.bodyNodeIdSchema = exports.OPTIONAL_SURFACES = exports.ICON_VARS = exports.primitiveExamples = exports.exampleNodes = exports.bindFrame = void 0;
10
10
  var frame_1 = require("./frame");
11
11
  Object.defineProperty(exports, "bindFrame", { enumerable: true, get: function () { return frame_1.bindFrame; } });
12
+ var primitive_example_1 = require("./primitive_example");
13
+ Object.defineProperty(exports, "exampleNodes", { enumerable: true, get: function () { return primitive_example_1.exampleNodes; } });
14
+ Object.defineProperty(exports, "primitiveExamples", { enumerable: true, get: function () { return primitive_example_1.primitiveExamples; } });
15
+ var primitive_icon_1 = require("./primitive_icon");
16
+ Object.defineProperty(exports, "ICON_VARS", { enumerable: true, get: function () { return primitive_icon_1.ICON_VARS; } });
12
17
  var primitive_module_1 = require("./primitive_module");
18
+ Object.defineProperty(exports, "OPTIONAL_SURFACES", { enumerable: true, get: function () { return primitive_module_1.OPTIONAL_SURFACES; } });
13
19
  Object.defineProperty(exports, "bodyNodeIdSchema", { enumerable: true, get: function () { return primitive_module_1.bodyNodeIdSchema; } });
14
20
  Object.defineProperty(exports, "bodyNodeSurfacesSchema", { enumerable: true, get: function () { return primitive_module_1.bodyNodeSurfacesSchema; } });
15
21
  Object.defineProperty(exports, "definePrimitive", { enumerable: true, get: function () { return primitive_module_1.definePrimitive; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/define/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iCAUiB;AADf,kGAAA,SAAS,OAAA;AAQX,uDA6B4B;AAN1B,oHAAA,gBAAgB,OAAA;AAChB,0HAAA,sBAAsB,OAAA;AACtB,mHAAA,eAAe,OAAA;AACf,sHAAA,kBAAkB,OAAA;AAClB,4HAAA,wBAAwB,OAAA;AACxB,sHAAA,kBAAkB,OAAA;AAgDpB,2CAAmE;AAA1D,gHAAA,kBAAkB,OAAA;AAAE,6GAAA,eAAe,OAAA;AAC5C,6CAAkD;AAAzC,6GAAA,cAAc,OAAA;AAAE,gGAAA,CAAC,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 BoundFrame,\n type Frame,\n type FrameBody,\n type FrameComposition,\n type FrameDispatcher,\n type FrameHeader,\n type FrameViewport,\n type ThemePair,\n bindFrame,\n} from './frame';\nexport {\n type MarkdownBlock,\n type MarkdownContent,\n type MarkdownInline,\n type MarkdownInlineInput,\n} from './markdown_content';\nexport {\n type AnyPrimitiveDefinition,\n type DefaultPackTypes,\n type OptionalSurface,\n type PackTypes,\n type PrimitiveCatalogEntry,\n type PrimitiveChildRef,\n type PrimitiveDefinition,\n type PrimitiveMetrics,\n type PrimitiveNode,\n type PrimitiveRenderContext,\n type PrimitiveSchema,\n type PrimitiveStyleCollectionContext,\n type PrimitiveStyleCollector,\n type ReactContextArg,\n type Renderer,\n type Renderers,\n type RenderScope,\n type StyledRenderContext,\n type StyleHandle,\n type SurfaceMap,\n type ThemeTokenPath,\n type WithNodeFields,\n bodyNodeIdSchema,\n bodyNodeSurfacesSchema,\n definePrimitive,\n definePrimitiveFor,\n unresolvedBodyNodeSchema,\n validateWithSchema,\n} from './primitive_module';\nexport {\n type SlackAssetCollector,\n type SlackAssetRequest,\n} from './slack_assets';\nexport {\n type SlackActionElement,\n type SlackActionsBlock,\n type SlackBlock,\n type SlackButtonElement,\n type SlackCheckboxesElement,\n type SlackContextBlock,\n type SlackDividerBlock,\n type SlackFileReference,\n type SlackHeaderBlock,\n type SlackHeaderLevel,\n type SlackImageBlock,\n type SlackImageElement,\n type SlackMrkdwnTextObject,\n type SlackMultiStaticSelectElement,\n type SlackOptionGroup,\n type SlackOptionObject,\n type SlackOverflowElement,\n type SlackPlainTextObject,\n type SlackRadioButtonsElement,\n type SlackRawTextElement,\n type SlackRichTextBlock,\n type SlackRichTextBlockElement,\n type SlackRichTextInline,\n type SlackRichTextLink,\n type SlackRichTextList,\n type SlackRichTextPreformatted,\n type SlackRichTextQuote,\n type SlackRichTextSection,\n type SlackRichTextStyle,\n type SlackRichTextTag,\n type SlackRichTextText,\n type SlackSectionAccessory,\n type SlackSectionBlock,\n type SlackStaticSelectElement,\n type SlackTableBlock,\n type SlackTableCell,\n type SlackTableColumnSetting,\n type SlackTagColor,\n type SlackTextObject,\n type SlackVideoBlock,\n} from './slack_blocks';\nexport { declaredFieldsNote, formatZodIssues } from './zod_format';\nexport { requiredString, z } from './zod_helpers';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/define/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iCAUiB;AADf,kGAAA,SAAS,OAAA;AAQX,yDAM6B;AAF3B,iHAAA,YAAY,OAAA;AACZ,sHAAA,iBAAiB,OAAA;AAEnB,mDAAiE;AAApC,2GAAA,SAAS,OAAA;AACtC,uDA8B4B;AAP1B,qHAAA,iBAAiB,OAAA;AACjB,oHAAA,gBAAgB,OAAA;AAChB,0HAAA,sBAAsB,OAAA;AACtB,mHAAA,eAAe,OAAA;AACf,sHAAA,kBAAkB,OAAA;AAClB,4HAAA,wBAAwB,OAAA;AACxB,sHAAA,kBAAkB,OAAA;AAgDpB,2CAAmE;AAA1D,gHAAA,kBAAkB,OAAA;AAAE,6GAAA,eAAe,OAAA;AAC5C,6CAAkD;AAAzC,6GAAA,cAAc,OAAA;AAAE,gGAAA,CAAC,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 BoundFrame,\n type Frame,\n type FrameBody,\n type FrameComposition,\n type FrameDispatcher,\n type FrameHeader,\n type FrameViewport,\n type ThemePair,\n bindFrame,\n} from './frame';\nexport {\n type MarkdownBlock,\n type MarkdownContent,\n type MarkdownInline,\n type MarkdownInlineInput,\n} from './markdown_content';\nexport {\n type ExampleNode,\n type NormalizedPrimitiveExample,\n type PrimitiveExample,\n exampleNodes,\n primitiveExamples,\n} from './primitive_example';\nexport { type PrimitiveIcon, ICON_VARS } from './primitive_icon';\nexport {\n type AnyPrimitiveDefinition,\n type DefaultPackTypes,\n type OptionalSurface,\n type PackTypes,\n type PrimitiveCatalogEntry,\n type PrimitiveChildRef,\n type PrimitiveDefinition,\n type PrimitiveMetrics,\n type PrimitiveNode,\n type PrimitiveRenderContext,\n type PrimitiveSchema,\n type PrimitiveStyleCollectionContext,\n type PrimitiveStyleCollector,\n type ReactContextArg,\n type Renderer,\n type Renderers,\n type RenderScope,\n type StyledRenderContext,\n type StyleHandle,\n type SurfaceMap,\n type ThemeTokenPath,\n type WithNodeFields,\n OPTIONAL_SURFACES,\n bodyNodeIdSchema,\n bodyNodeSurfacesSchema,\n definePrimitive,\n definePrimitiveFor,\n unresolvedBodyNodeSchema,\n validateWithSchema,\n} from './primitive_module';\nexport {\n type SlackAssetCollector,\n type SlackAssetRequest,\n} from './slack_assets';\nexport {\n type SlackActionElement,\n type SlackActionsBlock,\n type SlackBlock,\n type SlackButtonElement,\n type SlackCheckboxesElement,\n type SlackContextBlock,\n type SlackDividerBlock,\n type SlackFileReference,\n type SlackHeaderBlock,\n type SlackHeaderLevel,\n type SlackImageBlock,\n type SlackImageElement,\n type SlackMrkdwnTextObject,\n type SlackMultiStaticSelectElement,\n type SlackOptionGroup,\n type SlackOptionObject,\n type SlackOverflowElement,\n type SlackPlainTextObject,\n type SlackRadioButtonsElement,\n type SlackRawTextElement,\n type SlackRichTextBlock,\n type SlackRichTextBlockElement,\n type SlackRichTextInline,\n type SlackRichTextLink,\n type SlackRichTextList,\n type SlackRichTextPreformatted,\n type SlackRichTextQuote,\n type SlackRichTextSection,\n type SlackRichTextStyle,\n type SlackRichTextTag,\n type SlackRichTextText,\n type SlackSectionAccessory,\n type SlackSectionBlock,\n type SlackStaticSelectElement,\n type SlackTableBlock,\n type SlackTableCell,\n type SlackTableColumnSetting,\n type SlackTagColor,\n type SlackTextObject,\n type SlackVideoBlock,\n} from './slack_blocks';\nexport { declaredFieldsNote, formatZodIssues } from './zod_format';\nexport { requiredString, z } from './zod_helpers';\n"]}