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