@contractspec/lib.presentation-runtime-core 3.9.4 → 3.9.6

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.
@@ -1,314 +1,19 @@
1
- // src/transform-engine.markdown.ts
2
- import TurndownService from "turndown";
3
- function renderTextNode(node) {
4
- const text = node.text ?? "";
5
- if (!node.marks || node.marks.length === 0)
6
- return text;
7
- return node.marks.reduce((acc, mark) => {
8
- switch (mark.type) {
9
- case "bold":
10
- return `**${acc}**`;
11
- case "italic":
12
- return `*${acc}*`;
13
- case "underline":
14
- return `__${acc}__`;
15
- case "strike":
16
- return `~~${acc}~~`;
17
- case "code":
18
- return `\`${acc}\``;
19
- case "link": {
20
- const href = mark.attrs?.href ?? "";
21
- return href ? `[${acc}](${href})` : acc;
22
- }
23
- default:
24
- return acc;
25
- }
26
- }, text);
27
- }
28
- function renderInline(nodes) {
29
- if (!nodes?.length)
30
- return "";
31
- return nodes.map((child) => renderNode(child)).join("");
32
- }
33
- function renderList(nodes, ordered = false) {
34
- if (!nodes?.length)
35
- return "";
36
- let counter = 1;
37
- return nodes.map((item) => {
38
- const body = renderInline(item.content ?? []);
39
- if (!body)
40
- return "";
41
- const prefix = ordered ? `${counter++}. ` : "- ";
42
- return `${prefix}${body}`;
43
- }).filter(Boolean).join(`
44
- `);
45
- }
46
- function renderNode(node) {
47
- switch (node.type) {
48
- case "doc":
49
- return renderInline(node.content);
50
- case "paragraph": {
51
- const text = renderInline(node.content);
52
- return text.trim().length ? text : "";
53
- }
54
- case "heading": {
55
- const levelAttr = node.attrs?.level;
56
- const levelVal = typeof levelAttr === "number" ? levelAttr : 1;
57
- const level = Math.min(Math.max(levelVal, 1), 6);
58
- return `${"#".repeat(level)} ${renderInline(node.content)}`.trim();
59
- }
60
- case "bullet_list":
61
- return renderList(node.content, false);
62
- case "ordered_list":
63
- return renderList(node.content, true);
64
- case "list_item":
65
- return renderInline(node.content);
66
- case "blockquote": {
67
- const body = renderInline(node.content);
68
- return body.split(`
69
- `).map((line) => `> ${line}`).join(`
70
- `);
71
- }
72
- case "code_block": {
73
- const body = renderInline(node.content);
74
- return body ? `\`\`\`
75
- ${body}
76
- \`\`\`` : "";
77
- }
78
- case "horizontal_rule":
79
- return "---";
80
- case "hard_break":
81
- return `
82
- `;
83
- case "text":
84
- return renderTextNode(node);
85
- default:
86
- if (node.text)
87
- return renderTextNode(node);
88
- return "";
89
- }
90
- }
91
- function createMarkdownTurndownService() {
92
- const turndownService = new TurndownService({
93
- headingStyle: "atx",
94
- codeBlockStyle: "fenced",
95
- bulletListMarker: "-"
96
- });
97
- turndownService.addRule("link", {
98
- filter: "a",
99
- replacement: (content, node) => {
100
- const candidate = node;
101
- const href = candidate.getAttribute?.("href") ?? (typeof candidate.href === "string" ? candidate.href : "");
102
- if (href && content) {
103
- return `[${content}](${href})`;
104
- }
105
- return content || "";
106
- }
107
- });
108
- return turndownService;
109
- }
110
- var defaultTurndown = createMarkdownTurndownService();
111
- function htmlToMarkdown(html) {
112
- return defaultTurndown.turndown(html);
113
- }
114
- function blockNoteToMarkdown(docJson) {
115
- if (typeof docJson === "string")
116
- return docJson;
117
- if (docJson && typeof docJson === "object" && "html" in docJson) {
118
- const html = String(docJson.html);
119
- return htmlToMarkdown(html);
120
- }
121
- const root = docJson;
122
- if (root?.type === "doc" || root?.content) {
123
- const blocks = (root.content ?? []).map((node) => renderNode(node)).filter(Boolean);
124
- return blocks.join(`
1
+ import y from"turndown";function m(n){let t=n.text??"";if(!n.marks||n.marks.length===0)return t;return n.marks.reduce((r,u)=>{switch(u.type){case"bold":return`**${r}**`;case"italic":return`*${r}*`;case"underline":return`__${r}__`;case"strike":return`~~${r}~~`;case"code":return`\`${r}\``;case"link":{let i=u.attrs?.href??"";return i?`[${r}](${i})`:r}default:return r}},t)}function f(n){if(!n?.length)return"";return n.map((t)=>p(t)).join("")}function S(n,t=!1){if(!n?.length)return"";let r=1;return n.map((u)=>{let i=f(u.content??[]);if(!i)return"";return`${t?`${r++}. `:"- "}${i}`}).filter(Boolean).join(`
2
+ `)}function p(n){switch(n.type){case"doc":return f(n.content);case"paragraph":{let t=f(n.content);return t.trim().length?t:""}case"heading":{let t=n.attrs?.level,u=Math.min(Math.max(typeof t==="number"?t:1,1),6);return`${"#".repeat(u)} ${f(n.content)}`.trim()}case"bullet_list":return S(n.content,!1);case"ordered_list":return S(n.content,!0);case"list_item":return f(n.content);case"blockquote":return f(n.content).split(`
3
+ `).map((r)=>`> ${r}`).join(`
4
+ `);case"code_block":{let t=f(n.content);return t?`\`\`\`
5
+ ${t}
6
+ \`\`\``:""}case"horizontal_rule":return"---";case"hard_break":return`
7
+ `;case"text":return m(n);default:if(n.text)return m(n);return""}}function M(){let n=new y({headingStyle:"atx",codeBlockStyle:"fenced",bulletListMarker:"-"});return n.addRule("link",{filter:"a",replacement:(t,r)=>{let u=r,i=u.getAttribute?.("href")??(typeof u.href==="string"?u.href:"");if(i&&t)return`[${t}](${i})`;return t||""}}),n}var R=M();function L(n){return R.turndown(n)}function b(n){if(typeof n==="string")return n;if(n&&typeof n==="object"&&"html"in n){let r=String(n.html);return L(r)}let t=n;if(t?.type==="doc"||t?.content)return(t.content??[]).map((u)=>p(u)).filter(Boolean).join(`
125
8
 
126
- `).trim();
127
- }
128
- try {
129
- return JSON.stringify(docJson, null, 2);
130
- } catch {
131
- return String(docJson);
132
- }
133
- }
9
+ `).trim();try{return JSON.stringify(n,null,2)}catch{return String(n)}}import{schemaToMarkdown as g}from"@contractspec/lib.contracts-spec/schema-to-markdown";function _(n,t){let r;try{r=JSON.parse(JSON.stringify(t))}catch{r=t}let u=n.policy?.pii??[],i=(k,B)=>{let N=B.replace(/^\//,"").replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean),l=k;for(let o=0;o<N.length-1;o++){let h=N[o];if(!h||!l||typeof l!=="object"||!(h in l))return;l=l[h]}let $=N[N.length-1];if(l&&typeof l==="object"&&$&&$ in l)l[$]="[REDACTED]"};for(let k of u)i(r,k);return r}class x{renderers=new Map;validators=[];register(n){let t=this.renderers.get(n.target)??[];return t.push(n),this.renderers.set(n.target,t),this}prependRegister(n){let t=this.renderers.get(n.target)??[];return t.unshift(n),this.renderers.set(n.target,t),this}addValidator(n){return this.validators.push(n),this}async render(n,t,r){if(!t.targets.includes(n))throw Error(`Target ${n} not declared for ${t.meta.key}.v${t.meta.version}`);for(let i of this.validators)await i.validate(t,n,r);let u=this.renderers.get(n)??[];for(let i of u)try{return await i.render(t,r)}catch{}throw Error(`No renderer available for ${n}`)}}function T(){let n=new x;return n.register({target:"markdown",async render(t,r){let u=r?.data;if(!u&&r?.fetchData)u=await r.fetchData();if(t.source.type==="component"&&t.source.props&&u!==void 0){let o=Array.isArray(u),h=!o&&typeof u==="object"&&u!==null&&!Object.values(u).some((w)=>Array.isArray(w)||typeof w==="object"&&w!==null);if(o||h)return{mimeType:"text/markdown",body:g(t.source.props,u,{title:t.meta.description??t.meta.key,description:`${t.meta.key} v${t.meta.version}`})};throw Error(`Complex data structure for ${t.meta.key} - expecting custom renderer`)}if(t.source.type==="blocknotejs"){let o=_(t,{text:b(t.source.docJson)});return{mimeType:"text/markdown",body:String(o.text??"")}}if(t.source.type==="component"&&u!==void 0)throw Error(`No schema (source.props) available for ${t.meta.key} - expecting custom renderer`);if(t.source.type!=="component")throw Error("unsupported");let i=`# ${t.meta.key} v${t.meta.version}`,k=t.meta.description?`
134
10
 
135
- // src/transform-engine.ts
136
- import { schemaToMarkdown } from "@contractspec/lib.contracts-spec/schema-to-markdown";
137
- function applyPii(desc, obj) {
138
- let clone;
139
- try {
140
- clone = JSON.parse(JSON.stringify(obj));
141
- } catch {
142
- clone = obj;
143
- }
144
- const paths = desc.policy?.pii ?? [];
145
- const setAtPath = (root, path) => {
146
- const segments = path.replace(/^\//, "").replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
147
- let current = root;
148
- for (let i = 0;i < segments.length - 1; i++) {
149
- const key = segments[i];
150
- if (!key || !current || typeof current !== "object" || !(key in current)) {
151
- return;
152
- }
153
- current = current[key];
154
- }
155
- const last = segments[segments.length - 1];
156
- if (current && typeof current === "object" && last && last in current) {
157
- current[last] = "[REDACTED]";
158
- }
159
- };
160
- for (const path of paths) {
161
- setAtPath(clone, path);
162
- }
163
- return clone;
164
- }
11
+ ${t.meta.description}`:"",B=t.meta.tags&&t.meta.tags.length?`
165
12
 
166
- class TransformEngine {
167
- renderers = new Map;
168
- validators = [];
169
- register(renderer) {
170
- const renderers = this.renderers.get(renderer.target) ?? [];
171
- renderers.push(renderer);
172
- this.renderers.set(renderer.target, renderers);
173
- return this;
174
- }
175
- prependRegister(renderer) {
176
- const renderers = this.renderers.get(renderer.target) ?? [];
177
- renderers.unshift(renderer);
178
- this.renderers.set(renderer.target, renderers);
179
- return this;
180
- }
181
- addValidator(validator) {
182
- this.validators.push(validator);
183
- return this;
184
- }
185
- async render(target, desc, ctx) {
186
- if (!desc.targets.includes(target)) {
187
- throw new Error(`Target ${target} not declared for ${desc.meta.key}.v${desc.meta.version}`);
188
- }
189
- for (const validator of this.validators) {
190
- await validator.validate(desc, target, ctx);
191
- }
192
- const renderers = this.renderers.get(target) ?? [];
193
- for (const renderer of renderers) {
194
- try {
195
- return await renderer.render(desc, ctx);
196
- } catch {}
197
- }
198
- throw new Error(`No renderer available for ${target}`);
199
- }
200
- }
201
- function createDefaultTransformEngine() {
202
- const engine = new TransformEngine;
203
- engine.register({
204
- target: "markdown",
205
- async render(desc, ctx) {
206
- let data = ctx?.data;
207
- if (!data && ctx?.fetchData) {
208
- data = await ctx.fetchData();
209
- }
210
- if (desc.source.type === "component" && desc.source.props && data !== undefined) {
211
- const isArray = Array.isArray(data);
212
- const isSimpleObject = !isArray && typeof data === "object" && data !== null && !Object.values(data).some((value) => Array.isArray(value) || typeof value === "object" && value !== null);
213
- if (isArray || isSimpleObject) {
214
- return {
215
- mimeType: "text/markdown",
216
- body: schemaToMarkdown(desc.source.props, data, {
217
- title: desc.meta.description ?? desc.meta.key,
218
- description: `${desc.meta.key} v${desc.meta.version}`
219
- })
220
- };
221
- }
222
- throw new Error(`Complex data structure for ${desc.meta.key} - expecting custom renderer`);
223
- }
224
- if (desc.source.type === "blocknotejs") {
225
- const redacted = applyPii(desc, {
226
- text: blockNoteToMarkdown(desc.source.docJson)
227
- });
228
- return {
229
- mimeType: "text/markdown",
230
- body: String(redacted.text ?? "")
231
- };
232
- }
233
- if (desc.source.type === "component" && data !== undefined) {
234
- throw new Error(`No schema (source.props) available for ${desc.meta.key} - expecting custom renderer`);
235
- }
236
- if (desc.source.type !== "component") {
237
- throw new Error("unsupported");
238
- }
239
- const header = `# ${desc.meta.key} v${desc.meta.version}`;
240
- const about = desc.meta.description ? `
13
+ Tags: ${t.meta.tags.join(", ")}`:"",N=t.meta.owners&&t.meta.owners.length?`
241
14
 
242
- ${desc.meta.description}` : "";
243
- const tags = desc.meta.tags && desc.meta.tags.length ? `
15
+ Owners: ${t.meta.owners.join(", ")}`:"",l=`
244
16
 
245
- Tags: ${desc.meta.tags.join(", ")}` : "";
246
- const owners = desc.meta.owners && desc.meta.owners.length ? `
17
+ Component: \`${t.source.componentKey}\``,$=t.policy?.pii?.length?`
247
18
 
248
- Owners: ${desc.meta.owners.join(", ")}` : "";
249
- const component = `
250
-
251
- Component: \`${desc.source.componentKey}\``;
252
- const policy = desc.policy?.pii?.length ? `
253
-
254
- Redacted paths: ${desc.policy.pii.map((path) => `\`${path}\``).join(", ")}` : "";
255
- return {
256
- mimeType: "text/markdown",
257
- body: `${header}${about}${tags}${owners}${component}${policy}`
258
- };
259
- }
260
- });
261
- engine.register({
262
- target: "application/json",
263
- async render(desc) {
264
- const payload = applyPii(desc, { meta: desc.meta, source: desc.source });
265
- let body;
266
- try {
267
- body = JSON.stringify(payload, null, 2);
268
- } catch {
269
- body = JSON.stringify({
270
- meta: { key: desc.meta.key, version: desc.meta.version },
271
- source: "[non-serializable]"
272
- }, null, 2);
273
- }
274
- return { mimeType: "application/json", body };
275
- }
276
- });
277
- engine.register({
278
- target: "application/xml",
279
- async render(desc) {
280
- const payload = applyPii(desc, { meta: desc.meta, source: desc.source });
281
- let json;
282
- try {
283
- json = JSON.stringify(payload);
284
- } catch {
285
- json = JSON.stringify({
286
- meta: { key: desc.meta.key, version: desc.meta.version },
287
- source: "[non-serializable]"
288
- });
289
- }
290
- return {
291
- mimeType: "application/xml",
292
- body: `<presentation name="${desc.meta.key}" version="${desc.meta.version}"><json>${encodeURIComponent(json)}</json></presentation>`
293
- };
294
- }
295
- });
296
- return engine;
297
- }
298
- function registerBasicValidation(engine) {
299
- engine.addValidator({
300
- validate(desc) {
301
- if (!desc.meta.description || desc.meta.description.length < 3) {
302
- throw new Error(`Presentation ${desc.meta.key}.v${desc.meta.version} missing meta.description`);
303
- }
304
- }
305
- });
306
- return engine;
307
- }
308
- export {
309
- registerBasicValidation,
310
- htmlToMarkdown,
311
- createDefaultTransformEngine,
312
- blockNoteToMarkdown,
313
- TransformEngine
314
- };
19
+ Redacted paths: ${t.policy.pii.map((o)=>`\`${o}\``).join(", ")}`:"";return{mimeType:"text/markdown",body:`${i}${k}${B}${N}${l}${$}`}}}),n.register({target:"application/json",async render(t){let r=_(t,{meta:t.meta,source:t.source}),u;try{u=JSON.stringify(r,null,2)}catch{u=JSON.stringify({meta:{key:t.meta.key,version:t.meta.version},source:"[non-serializable]"},null,2)}return{mimeType:"application/json",body:u}}}),n.register({target:"application/xml",async render(t){let r=_(t,{meta:t.meta,source:t.source}),u;try{u=JSON.stringify(r)}catch{u=JSON.stringify({meta:{key:t.meta.key,version:t.meta.version},source:"[non-serializable]"})}return{mimeType:"application/xml",body:`<presentation name="${t.meta.key}" version="${t.meta.version}"><json>${encodeURIComponent(u)}</json></presentation>`}}}),n}function v(n){return n.addValidator({validate(t){if(!t.meta.description||t.meta.description.length<3)throw Error(`Presentation ${t.meta.key}.v${t.meta.version} missing meta.description`)}}),n}export{v as registerBasicValidation,L as htmlToMarkdown,T as createDefaultTransformEngine,b as blockNoteToMarkdown,x as TransformEngine};
@@ -1,138 +1,9 @@
1
- // src/transform-engine.markdown.ts
2
- import TurndownService from "turndown";
3
- function renderTextNode(node) {
4
- const text = node.text ?? "";
5
- if (!node.marks || node.marks.length === 0)
6
- return text;
7
- return node.marks.reduce((acc, mark) => {
8
- switch (mark.type) {
9
- case "bold":
10
- return `**${acc}**`;
11
- case "italic":
12
- return `*${acc}*`;
13
- case "underline":
14
- return `__${acc}__`;
15
- case "strike":
16
- return `~~${acc}~~`;
17
- case "code":
18
- return `\`${acc}\``;
19
- case "link": {
20
- const href = mark.attrs?.href ?? "";
21
- return href ? `[${acc}](${href})` : acc;
22
- }
23
- default:
24
- return acc;
25
- }
26
- }, text);
27
- }
28
- function renderInline(nodes) {
29
- if (!nodes?.length)
30
- return "";
31
- return nodes.map((child) => renderNode(child)).join("");
32
- }
33
- function renderList(nodes, ordered = false) {
34
- if (!nodes?.length)
35
- return "";
36
- let counter = 1;
37
- return nodes.map((item) => {
38
- const body = renderInline(item.content ?? []);
39
- if (!body)
40
- return "";
41
- const prefix = ordered ? `${counter++}. ` : "- ";
42
- return `${prefix}${body}`;
43
- }).filter(Boolean).join(`
44
- `);
45
- }
46
- function renderNode(node) {
47
- switch (node.type) {
48
- case "doc":
49
- return renderInline(node.content);
50
- case "paragraph": {
51
- const text = renderInline(node.content);
52
- return text.trim().length ? text : "";
53
- }
54
- case "heading": {
55
- const levelAttr = node.attrs?.level;
56
- const levelVal = typeof levelAttr === "number" ? levelAttr : 1;
57
- const level = Math.min(Math.max(levelVal, 1), 6);
58
- return `${"#".repeat(level)} ${renderInline(node.content)}`.trim();
59
- }
60
- case "bullet_list":
61
- return renderList(node.content, false);
62
- case "ordered_list":
63
- return renderList(node.content, true);
64
- case "list_item":
65
- return renderInline(node.content);
66
- case "blockquote": {
67
- const body = renderInline(node.content);
68
- return body.split(`
69
- `).map((line) => `> ${line}`).join(`
70
- `);
71
- }
72
- case "code_block": {
73
- const body = renderInline(node.content);
74
- return body ? `\`\`\`
75
- ${body}
76
- \`\`\`` : "";
77
- }
78
- case "horizontal_rule":
79
- return "---";
80
- case "hard_break":
81
- return `
82
- `;
83
- case "text":
84
- return renderTextNode(node);
85
- default:
86
- if (node.text)
87
- return renderTextNode(node);
88
- return "";
89
- }
90
- }
91
- function createMarkdownTurndownService() {
92
- const turndownService = new TurndownService({
93
- headingStyle: "atx",
94
- codeBlockStyle: "fenced",
95
- bulletListMarker: "-"
96
- });
97
- turndownService.addRule("link", {
98
- filter: "a",
99
- replacement: (content, node) => {
100
- const candidate = node;
101
- const href = candidate.getAttribute?.("href") ?? (typeof candidate.href === "string" ? candidate.href : "");
102
- if (href && content) {
103
- return `[${content}](${href})`;
104
- }
105
- return content || "";
106
- }
107
- });
108
- return turndownService;
109
- }
110
- var defaultTurndown = createMarkdownTurndownService();
111
- function htmlToMarkdown(html) {
112
- return defaultTurndown.turndown(html);
113
- }
114
- function blockNoteToMarkdown(docJson) {
115
- if (typeof docJson === "string")
116
- return docJson;
117
- if (docJson && typeof docJson === "object" && "html" in docJson) {
118
- const html = String(docJson.html);
119
- return htmlToMarkdown(html);
120
- }
121
- const root = docJson;
122
- if (root?.type === "doc" || root?.content) {
123
- const blocks = (root.content ?? []).map((node) => renderNode(node)).filter(Boolean);
124
- return blocks.join(`
1
+ import s from"turndown";function u(t){let e=t.text??"";if(!t.marks||t.marks.length===0)return e;return t.marks.reduce((r,n)=>{switch(n.type){case"bold":return`**${r}**`;case"italic":return`*${r}*`;case"underline":return`__${r}__`;case"strike":return`~~${r}~~`;case"code":return`\`${r}\``;case"link":{let o=n.attrs?.href??"";return o?`[${r}](${o})`:r}default:return r}},e)}function i(t){if(!t?.length)return"";return t.map((e)=>c(e)).join("")}function l(t,e=!1){if(!t?.length)return"";let r=1;return t.map((n)=>{let o=i(n.content??[]);if(!o)return"";return`${e?`${r++}. `:"- "}${o}`}).filter(Boolean).join(`
2
+ `)}function c(t){switch(t.type){case"doc":return i(t.content);case"paragraph":{let e=i(t.content);return e.trim().length?e:""}case"heading":{let e=t.attrs?.level,n=Math.min(Math.max(typeof e==="number"?e:1,1),6);return`${"#".repeat(n)} ${i(t.content)}`.trim()}case"bullet_list":return l(t.content,!1);case"ordered_list":return l(t.content,!0);case"list_item":return i(t.content);case"blockquote":return i(t.content).split(`
3
+ `).map((r)=>`> ${r}`).join(`
4
+ `);case"code_block":{let e=i(t.content);return e?`\`\`\`
5
+ ${e}
6
+ \`\`\``:""}case"horizontal_rule":return"---";case"hard_break":return`
7
+ `;case"text":return u(t);default:if(t.text)return u(t);return""}}function a(){let t=new s({headingStyle:"atx",codeBlockStyle:"fenced",bulletListMarker:"-"});return t.addRule("link",{filter:"a",replacement:(e,r)=>{let n=r,o=n.getAttribute?.("href")??(typeof n.href==="string"?n.href:"");if(o&&e)return`[${e}](${o})`;return e||""}}),t}var f=a();function k(t){return f.turndown(t)}function h(t){if(typeof t==="string")return t;if(t&&typeof t==="object"&&"html"in t){let r=String(t.html);return k(r)}let e=t;if(e?.type==="doc"||e?.content)return(e.content??[]).map((n)=>c(n)).filter(Boolean).join(`
125
8
 
126
- `).trim();
127
- }
128
- try {
129
- return JSON.stringify(docJson, null, 2);
130
- } catch {
131
- return String(docJson);
132
- }
133
- }
134
- export {
135
- htmlToMarkdown,
136
- createMarkdownTurndownService,
137
- blockNoteToMarkdown
138
- };
9
+ `).trim();try{return JSON.stringify(t,null,2)}catch{return String(t)}}export{k as htmlToMarkdown,a as createMarkdownTurndownService,h as blockNoteToMarkdown};
@@ -1,148 +1 @@
1
- // src/visualization.echarts.ts
2
- function buildVisualizationEChartsOption(model) {
3
- const thresholdLines = model.thresholds.map((threshold) => ({
4
- yAxis: threshold.value,
5
- name: threshold.label,
6
- lineStyle: {
7
- color: threshold.color ?? "#ef4444",
8
- type: "dashed"
9
- }
10
- }));
11
- const annotationLines = model.annotations.filter((annotation) => annotation.kind === "line" && annotation.y != null).map((annotation) => toMarkLine(annotation));
12
- switch (model.kind) {
13
- case "cartesian":
14
- const cartesianSeries = model.series.map((series) => ({
15
- name: series.label,
16
- type: resolveCartesianSeriesType(series.type),
17
- smooth: series.smooth,
18
- stack: series.stack,
19
- areaStyle: series.type === "area" ? {} : undefined,
20
- itemStyle: series.color ? { color: series.color } : undefined,
21
- lineStyle: series.color ? { color: series.color } : undefined,
22
- data: series.points.filter((point) => point.y != null).map((point) => [point.x, point.y]),
23
- markLine: thresholdLines.length || annotationLines.length ? { data: [...thresholdLines, ...annotationLines] } : undefined
24
- }));
25
- return {
26
- color: model.palette,
27
- tooltip: model.tooltip === false ? undefined : { trigger: "axis" },
28
- legend: { show: model.legend ?? model.series.length > 1 },
29
- xAxis: { type: model.xAxis?.type === "time" ? "time" : "category" },
30
- yAxis: { type: "value", name: model.yAxis?.label },
31
- series: cartesianSeries
32
- };
33
- case "pie":
34
- const pieSeries = [
35
- {
36
- type: "pie",
37
- radius: ["0%", "70%"],
38
- data: model.series[0]?.points.filter((point) => point.value != null).map((point) => ({
39
- name: point.name ?? "",
40
- value: point.value
41
- })) ?? []
42
- }
43
- ];
44
- return {
45
- color: model.palette,
46
- tooltip: model.tooltip === false ? undefined : { trigger: "item" },
47
- series: pieSeries
48
- };
49
- case "heatmap":
50
- const heatmapSeries = [
51
- {
52
- type: "heatmap",
53
- data: model.series[0]?.points.filter((point) => point.value != null && point.name != null).map((point) => [point.x, point.name, point.value]) ?? []
54
- }
55
- ];
56
- return {
57
- color: model.palette,
58
- tooltip: model.tooltip === false ? undefined : { position: "top" },
59
- xAxis: {
60
- type: "category",
61
- data: uniqueValues(model.series[0]?.points.map((point) => point.x))
62
- },
63
- yAxis: {
64
- type: "category",
65
- data: uniqueValues(model.series[0]?.points.map((point) => point.name))
66
- },
67
- visualMap: {
68
- min: 0,
69
- max: maxValue(model.series[0]?.points.map((point) => point.value)),
70
- calculable: true,
71
- orient: "horizontal",
72
- left: "center",
73
- bottom: 0
74
- },
75
- series: heatmapSeries
76
- };
77
- case "funnel":
78
- const funnelSeries = [
79
- {
80
- type: "funnel",
81
- data: model.series[0]?.points.filter((point) => point.value != null).map((point) => ({
82
- name: point.name ?? "",
83
- value: point.value
84
- })) ?? []
85
- }
86
- ];
87
- return {
88
- color: model.palette,
89
- tooltip: model.tooltip === false ? undefined : { trigger: "item" },
90
- series: funnelSeries
91
- };
92
- case "geo":
93
- if (!model.geo || model.geo.mode === "slippy-map" || !model.geo.geoJson) {
94
- return {};
95
- }
96
- const geoSeries = [
97
- {
98
- type: model.geo.variant === "heatmap" ? "heatmap" : "scatter",
99
- coordinateSystem: "geo",
100
- data: model.series[0]?.points.filter((point) => point.longitude != null && point.latitude != null && point.value != null).map((point) => ({
101
- name: point.name ?? "",
102
- value: [
103
- point.longitude,
104
- point.latitude,
105
- point.value
106
- ]
107
- })) ?? []
108
- }
109
- ];
110
- return {
111
- color: model.palette,
112
- tooltip: model.tooltip === false ? undefined : { trigger: "item" },
113
- geo: {
114
- map: "contractspec-visualization-geo",
115
- roam: true
116
- },
117
- series: geoSeries
118
- };
119
- default:
120
- return {};
121
- }
122
- }
123
- function uniqueValues(values) {
124
- return Array.from(new Set((values ?? []).filter((value) => value != null).map(String)));
125
- }
126
- function maxValue(values) {
127
- return Math.max(...(values ?? []).map((value) => value ?? 0), 1);
128
- }
129
- function toMarkLine(annotation) {
130
- return {
131
- yAxis: annotation.y,
132
- name: annotation.label,
133
- lineStyle: {
134
- color: annotation.color ?? "#2563eb",
135
- type: "solid"
136
- }
137
- };
138
- }
139
- function resolveCartesianSeriesType(type) {
140
- if (type === "bar")
141
- return "bar";
142
- if (type === "scatter")
143
- return "scatter";
144
- return "line";
145
- }
146
- export {
147
- buildVisualizationEChartsOption
148
- };
1
+ function m(t){let n=t.thresholds.map((a)=>({yAxis:a.value,name:a.label,lineStyle:{color:a.color??"#ef4444",type:"dashed"}})),r=t.annotations.filter((a)=>a.kind==="line"&&a.y!=null).map((a)=>f(a));switch(t.kind){case"cartesian":let a=t.series.map((e)=>({name:e.label,type:y(e.type),smooth:e.smooth,stack:e.stack,areaStyle:e.type==="area"?{}:void 0,itemStyle:e.color?{color:e.color}:void 0,lineStyle:e.color?{color:e.color}:void 0,data:e.points.filter((i)=>i.y!=null).map((i)=>[i.x,i.y]),markLine:n.length||r.length?{data:[...n,...r]}:void 0}));return{color:t.palette,tooltip:t.tooltip===!1?void 0:{trigger:"axis"},legend:{show:t.legend??t.series.length>1},xAxis:{type:t.xAxis?.type==="time"?"time":"category"},yAxis:{type:"value",name:t.yAxis?.label},series:a};case"pie":let l=[{type:"pie",radius:["0%","70%"],data:t.series[0]?.points.filter((e)=>e.value!=null).map((e)=>({name:e.name??"",value:e.value}))??[]}];return{color:t.palette,tooltip:t.tooltip===!1?void 0:{trigger:"item"},series:l};case"heatmap":let o=[{type:"heatmap",data:t.series[0]?.points.filter((e)=>e.value!=null&&e.name!=null).map((e)=>[e.x,e.name,e.value])??[]}];return{color:t.palette,tooltip:t.tooltip===!1?void 0:{position:"top"},xAxis:{type:"category",data:s(t.series[0]?.points.map((e)=>e.x))},yAxis:{type:"category",data:s(t.series[0]?.points.map((e)=>e.name))},visualMap:{min:0,max:c(t.series[0]?.points.map((e)=>e.value)),calculable:!0,orient:"horizontal",left:"center",bottom:0},series:o};case"funnel":let u=[{type:"funnel",data:t.series[0]?.points.filter((e)=>e.value!=null).map((e)=>({name:e.name??"",value:e.value}))??[]}];return{color:t.palette,tooltip:t.tooltip===!1?void 0:{trigger:"item"},series:u};case"geo":if(!t.geo||t.geo.mode==="slippy-map"||!t.geo.geoJson)return{};let p=[{type:t.geo.variant==="heatmap"?"heatmap":"scatter",coordinateSystem:"geo",data:t.series[0]?.points.filter((e)=>e.longitude!=null&&e.latitude!=null&&e.value!=null).map((e)=>({name:e.name??"",value:[e.longitude,e.latitude,e.value]}))??[]}];return{color:t.palette,tooltip:t.tooltip===!1?void 0:{trigger:"item"},geo:{map:"contractspec-visualization-geo",roam:!0},series:p};default:return{}}}function s(t){return Array.from(new Set((t??[]).filter((n)=>n!=null).map(String)))}function c(t){return Math.max(...(t??[]).map((n)=>n??0),1)}function f(t){return{yAxis:t.y,name:t.label,lineStyle:{color:t.color??"#2563eb",type:"solid"}}}function y(t){if(t==="bar")return"bar";if(t==="scatter")return"scatter";return"line"}export{m as buildVisualizationEChartsOption};