@glyphjs/schemas 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -26,8 +26,7 @@ var graphSchema = z.object({
26
26
  })
27
27
  ),
28
28
  layout: z.enum(["top-down", "left-right", "bottom-up", "radial", "force"]).optional(),
29
- interactionMode: z.enum(["modifier-key", "click-to-activate", "always"]).default("modifier-key"),
30
- markdown: z.boolean().default(false)
29
+ interactionMode: z.enum(["modifier-key", "click-to-activate", "always"]).default("modifier-key")
31
30
  });
32
31
  var tableSchema = z.object({
33
32
  columns: z.array(
@@ -45,8 +44,7 @@ var tableSchema = z.object({
45
44
  column: z.string(),
46
45
  function: z.enum(["sum", "avg", "count", "min", "max"])
47
46
  })
48
- ).optional(),
49
- markdown: z.boolean().default(false)
47
+ ).optional()
50
48
  });
51
49
  var chartSchema = z.object({
52
50
  type: z.enum(["line", "bar", "area", "ohlc"]),
@@ -58,8 +56,7 @@ var chartSchema = z.object({
58
56
  ),
59
57
  xAxis: z.object({ key: z.string(), label: inlineContentSchema.optional() }).optional(),
60
58
  yAxis: z.object({ key: z.string(), label: inlineContentSchema.optional() }).optional(),
61
- legend: z.boolean().optional(),
62
- markdown: z.boolean().default(false)
59
+ legend: z.boolean().optional()
63
60
  });
64
61
  var relationSchema = z.object({
65
62
  entities: z.array(
@@ -84,26 +81,31 @@ var relationSchema = z.object({
84
81
  })
85
82
  ),
86
83
  layout: z.enum(["top-down", "left-right"]).optional(),
87
- interactionMode: z.enum(["modifier-key", "click-to-activate", "always"]).default("modifier-key"),
88
- markdown: z.boolean().default(false)
84
+ interactionMode: z.enum(["modifier-key", "click-to-activate", "always"]).default("modifier-key")
85
+ });
86
+ var baseEventFields = {
87
+ title: inlineContentSchema,
88
+ description: inlineContentSchema.optional(),
89
+ type: z.string().optional()
90
+ };
91
+ var eventWithDate = z.object({
92
+ ...baseEventFields,
93
+ date: z.string(),
94
+ label: z.string().optional()
95
+ });
96
+ var eventWithLabel = z.object({
97
+ ...baseEventFields,
98
+ date: z.string().optional(),
99
+ label: z.string()
89
100
  });
90
101
  var timelineSchema = z.object({
91
- events: z.array(
92
- z.object({
93
- date: z.string(),
94
- title: inlineContentSchema,
95
- description: inlineContentSchema.optional(),
96
- type: z.string().optional()
97
- })
98
- ),
99
- orientation: z.enum(["vertical", "horizontal"]).optional(),
100
- markdown: z.boolean().default(false)
102
+ events: z.array(z.union([eventWithDate, eventWithLabel])),
103
+ orientation: z.enum(["vertical", "horizontal"]).optional()
101
104
  });
102
105
  var calloutSchema = z.object({
103
106
  type: z.enum(["info", "warning", "error", "tip"]),
104
107
  title: inlineContentSchema.optional(),
105
- content: inlineContentSchema,
106
- markdown: z.boolean().default(false)
108
+ content: inlineContentSchema
107
109
  });
108
110
  var tabsSchema = z.object({
109
111
  tabs: z.array(
@@ -112,7 +114,7 @@ var tabsSchema = z.object({
112
114
  content: inlineContentSchema
113
115
  })
114
116
  ),
115
- markdown: z.boolean().default(false)
117
+ _slotChildCounts: z.array(z.number()).optional()
116
118
  });
117
119
  var stepsSchema = z.object({
118
120
  steps: z.array(
@@ -122,7 +124,7 @@ var stepsSchema = z.object({
122
124
  content: inlineContentSchema
123
125
  })
124
126
  ),
125
- markdown: z.boolean().default(false)
127
+ _slotChildCounts: z.array(z.number()).optional()
126
128
  });
127
129
  var iconEnum = z.enum([
128
130
  "server",
@@ -176,8 +178,7 @@ var kpiSchema = z.object({
176
178
  unit: z.string().optional()
177
179
  })
178
180
  ).min(1).max(8),
179
- columns: z.number().min(1).max(4).optional(),
180
- markdown: z.boolean().default(false)
181
+ columns: z.number().min(1).max(4).optional()
181
182
  });
182
183
  var accordionSchema = z.object({
183
184
  title: z.string().optional(),
@@ -188,8 +189,7 @@ var accordionSchema = z.object({
188
189
  })
189
190
  ).min(1),
190
191
  defaultOpen: z.array(z.number()).optional(),
191
- multiple: z.boolean().default(true),
192
- markdown: z.boolean().default(false)
192
+ multiple: z.boolean().default(true)
193
193
  });
194
194
  var comparisonSchema = z.object({
195
195
  title: z.string().optional(),
@@ -204,8 +204,7 @@ var comparisonSchema = z.object({
204
204
  name: z.string(),
205
205
  values: z.array(inlineContentSchema)
206
206
  })
207
- ).min(1),
208
- markdown: z.boolean().default(false)
207
+ ).min(1)
209
208
  }).refine((data) => data.features.every((f) => f.values.length === data.options.length), {
210
209
  message: "Each feature must have one value per option"
211
210
  });
@@ -214,8 +213,7 @@ var codediffSchema = z.object({
214
213
  before: z.string(),
215
214
  after: z.string(),
216
215
  beforeLabel: inlineContentSchema.optional(),
217
- afterLabel: inlineContentSchema.optional(),
218
- markdown: z.boolean().default(false)
216
+ afterLabel: inlineContentSchema.optional()
219
217
  });
220
218
  var flowchartSchema = z.object({
221
219
  title: inlineContentSchema.optional(),
@@ -234,8 +232,7 @@ var flowchartSchema = z.object({
234
232
  })
235
233
  ).min(1),
236
234
  direction: z.enum(["top-down", "left-right"]).default("top-down"),
237
- interactionMode: z.enum(["modifier-key", "click-to-activate", "always"]).default("modifier-key"),
238
- markdown: z.boolean().default(false)
235
+ interactionMode: z.enum(["modifier-key", "click-to-activate", "always"]).default("modifier-key")
239
236
  });
240
237
  var fileNodeSchema = z.object({
241
238
  name: z.string(),
@@ -262,8 +259,7 @@ var sequenceSchema = z.object({
262
259
  label: inlineContentSchema,
263
260
  type: z.enum(["message", "reply", "self"]).default("message")
264
261
  })
265
- ).min(1),
266
- markdown: z.boolean().default(false)
262
+ ).min(1)
267
263
  });
268
264
  var mindmapNodeSchema = z.object({
269
265
  label: z.string(),
@@ -282,8 +278,7 @@ var equationSchema = z.object({
282
278
  expression: z.string(),
283
279
  annotation: inlineContentSchema.optional()
284
280
  })
285
- ).optional(),
286
- markdown: z.boolean().default(false)
281
+ ).optional()
287
282
  }).refine(
288
283
  (data) => data.expression !== void 0 || data.steps !== void 0 && data.steps.length > 0,
289
284
  { message: "Either expression or steps must be provided" }
@@ -316,8 +311,7 @@ var quizQuestion = z.discriminatedUnion("type", [
316
311
  var quizSchema = z.object({
317
312
  questions: z.array(quizQuestion).min(1),
318
313
  showScore: z.boolean().default(true),
319
- title: z.string().optional(),
320
- markdown: z.boolean().default(false)
314
+ title: z.string().optional()
321
315
  });
322
316
  var cardActionSchema = z.object({
323
317
  label: z.string(),
@@ -335,8 +329,7 @@ var cardSchema = z.object({
335
329
  title: z.string().optional(),
336
330
  cards: z.array(cardItemSchema).min(1).max(12),
337
331
  variant: z.enum(["default", "outlined", "elevated"]).default("default"),
338
- columns: z.number().min(1).max(4).optional(),
339
- markdown: z.boolean().default(false)
332
+ columns: z.number().min(1).max(4).optional()
340
333
  });
341
334
  var statItemSchema = z.object({
342
335
  type: z.literal("stat"),
@@ -397,16 +390,14 @@ var infographicSectionSchema = z.object({
397
390
  });
398
391
  var infographicSchema = z.object({
399
392
  title: z.string().optional(),
400
- sections: z.array(infographicSectionSchema).min(1).max(8),
401
- markdown: z.boolean().default(false)
393
+ sections: z.array(infographicSectionSchema).min(1).max(8)
402
394
  });
403
395
  var pollSchema = z.object({
404
396
  question: inlineContentSchema,
405
- options: z.array(z.string()).min(2).max(10),
397
+ options: z.array(inlineContentSchema).min(2).max(10),
406
398
  multiple: z.boolean().default(false),
407
399
  showResults: z.boolean().default(true),
408
- title: z.string().optional(),
409
- markdown: z.boolean().default(false)
400
+ title: z.string().optional()
410
401
  });
411
402
  var ratingItem = z.object({
412
403
  label: z.string(),
@@ -420,8 +411,7 @@ var ratingSchema = z.object({
420
411
  low: z.string(),
421
412
  high: z.string()
422
413
  }).optional(),
423
- items: z.array(ratingItem).min(1),
424
- markdown: z.boolean().default(false)
414
+ items: z.array(ratingItem).min(1)
425
415
  });
426
416
  var rankerItem = z.object({
427
417
  id: z.string(),
@@ -430,8 +420,7 @@ var rankerItem = z.object({
430
420
  });
431
421
  var rankerSchema = z.object({
432
422
  title: z.string().optional(),
433
- items: z.array(rankerItem).min(2),
434
- markdown: z.boolean().default(false)
423
+ items: z.array(rankerItem).min(2)
435
424
  });
436
425
  var sliderParameter = z.object({
437
426
  id: z.string(),
@@ -445,8 +434,7 @@ var sliderParameter = z.object({
445
434
  var sliderSchema = z.object({
446
435
  title: z.string().optional(),
447
436
  layout: z.enum(["vertical", "horizontal"]).default("vertical"),
448
- parameters: z.array(sliderParameter).min(1),
449
- markdown: z.boolean().default(false)
437
+ parameters: z.array(sliderParameter).min(1)
450
438
  });
451
439
  var matrixColumn = z.object({
452
440
  id: z.string(),
@@ -462,8 +450,7 @@ var matrixSchema = z.object({
462
450
  scale: z.number().int().min(2).max(10).default(5),
463
451
  showTotals: z.boolean().default(true),
464
452
  columns: z.array(matrixColumn).min(1),
465
- rows: z.array(matrixRow).min(1),
466
- markdown: z.boolean().default(false)
453
+ rows: z.array(matrixRow).min(1)
467
454
  });
468
455
  var textField = z.object({
469
456
  type: z.literal("text"),
@@ -517,8 +504,7 @@ var formSchema = z.object({
517
504
  title: z.string().optional(),
518
505
  description: inlineContentSchema.optional(),
519
506
  submitLabel: z.string().default("Submit"),
520
- fields: z.array(formField).min(1),
521
- markdown: z.boolean().default(false)
507
+ fields: z.array(formField).min(1)
522
508
  });
523
509
  var kanbanCard = z.object({
524
510
  id: z.string(),
@@ -535,8 +521,7 @@ var kanbanColumn = z.object({
535
521
  });
536
522
  var kanbanSchema = z.object({
537
523
  title: z.string().optional(),
538
- columns: z.array(kanbanColumn).min(1),
539
- markdown: z.boolean().default(false)
524
+ columns: z.array(kanbanColumn).min(1)
540
525
  });
541
526
  var annotateLabel = z.object({
542
527
  name: z.string(),
@@ -552,8 +537,70 @@ var annotateSchema = z.object({
552
537
  title: z.string().optional(),
553
538
  labels: z.array(annotateLabel).min(1),
554
539
  text: z.string(),
555
- annotations: z.array(annotation).default([]),
556
- markdown: z.boolean().default(false)
540
+ annotations: z.array(annotation).default([])
541
+ });
542
+ var sankeyNodeSchema = z.object({
543
+ id: z.string(),
544
+ label: z.string(),
545
+ color: z.string().optional()
546
+ });
547
+ var sankeyFlowSchema = z.object({
548
+ from: z.string(),
549
+ to: z.string(),
550
+ value: z.number().positive(),
551
+ label: z.string().optional()
552
+ });
553
+ function hasCycle(nodes, flows) {
554
+ const ids = new Set(nodes.map((n) => n.id));
555
+ const indegree = /* @__PURE__ */ new Map();
556
+ const adjacency = /* @__PURE__ */ new Map();
557
+ for (const id of ids) {
558
+ indegree.set(id, 0);
559
+ adjacency.set(id, []);
560
+ }
561
+ for (const flow of flows) {
562
+ if (!ids.has(flow.from) || !ids.has(flow.to)) continue;
563
+ if (flow.from === flow.to) return true;
564
+ const fromList = adjacency.get(flow.from);
565
+ if (!fromList) continue;
566
+ fromList.push(flow.to);
567
+ indegree.set(flow.to, (indegree.get(flow.to) ?? 0) + 1);
568
+ }
569
+ const queue = [];
570
+ for (const [id, deg] of indegree) {
571
+ if (deg === 0) queue.push(id);
572
+ }
573
+ let visited = 0;
574
+ while (queue.length > 0) {
575
+ const id = queue.shift();
576
+ if (id === void 0) break;
577
+ visited += 1;
578
+ for (const next of adjacency.get(id) ?? []) {
579
+ const nextDeg = (indegree.get(next) ?? 0) - 1;
580
+ indegree.set(next, nextDeg);
581
+ if (nextDeg === 0) queue.push(next);
582
+ }
583
+ }
584
+ return visited !== ids.size;
585
+ }
586
+ var sankeySchema = z.object({
587
+ title: z.string().optional(),
588
+ nodes: z.array(sankeyNodeSchema).min(2),
589
+ flows: z.array(sankeyFlowSchema).min(1),
590
+ orientation: z.enum(["left-right", "top-down"]).default("left-right"),
591
+ unit: z.string().optional()
592
+ }).refine(
593
+ (data) => {
594
+ const ids = new Set(data.nodes.map((n) => n.id));
595
+ return data.flows.every((f) => ids.has(f.from) && ids.has(f.to));
596
+ },
597
+ {
598
+ message: "Every flow must reference declared node IDs (from/to).",
599
+ path: ["flows"]
600
+ }
601
+ ).refine((data) => !hasCycle(data.nodes, data.flows), {
602
+ message: "Sankey must be a DAG \u2014 cycles are not allowed.",
603
+ path: ["flows"]
557
604
  });
558
605
  var columnsSchema = z.object({
559
606
  children: z.array(z.string()).min(1),
@@ -570,6 +617,181 @@ var panelSchema = z.object({
570
617
  style: z.enum(["card", "bordered", "elevated", "ghost"]).optional(),
571
618
  padding: z.string().optional()
572
619
  });
620
+ var heatmapSchema = z.object({
621
+ title: z.string().optional(),
622
+ rows: z.array(z.string()).min(1),
623
+ cols: z.array(z.string()).min(1),
624
+ values: z.array(z.array(z.number().nullable())).min(1),
625
+ scale: z.enum(["sequential", "diverging"]).default("sequential"),
626
+ domain: z.tuple([z.number(), z.number()]).optional(),
627
+ unit: z.string().optional(),
628
+ showValues: z.boolean().default(false),
629
+ legend: z.boolean().default(true)
630
+ }).refine(
631
+ (d) => d.values.length === d.rows.length && d.values.every((r) => r.length === d.cols.length),
632
+ { message: "values matrix dimensions must match rows \xD7 cols" }
633
+ );
634
+ var funnelSchema = z.object({
635
+ title: z.string().optional(),
636
+ stages: z.array(
637
+ z.object({
638
+ label: z.string(),
639
+ value: z.number().nonnegative(),
640
+ description: z.string().optional()
641
+ })
642
+ ).min(2).max(12),
643
+ showConversion: z.boolean().default(true),
644
+ orientation: z.enum(["vertical", "horizontal"]).default("vertical"),
645
+ unit: z.string().optional()
646
+ }).refine(
647
+ (d) => {
648
+ for (let i = 1; i < d.stages.length; i++) {
649
+ const prev = d.stages[i - 1];
650
+ const curr = d.stages[i];
651
+ if (prev === void 0 || curr === void 0) return false;
652
+ if (curr.value > prev.value) return false;
653
+ }
654
+ return true;
655
+ },
656
+ { message: "funnel stages must be monotonically non-increasing" }
657
+ );
658
+ var decisiontreeNodeSchema = z.object({
659
+ id: z.string(),
660
+ type: z.enum(["question", "outcome"]).default("question"),
661
+ label: z.string(),
662
+ sentiment: z.enum(["positive", "neutral", "negative"]).optional(),
663
+ confidence: z.number().min(0).max(1).optional()
664
+ });
665
+ var decisiontreeEdgeSchema = z.object({
666
+ from: z.string(),
667
+ to: z.string(),
668
+ condition: z.string().optional()
669
+ });
670
+ var decisiontreeSchema = z.object({
671
+ title: z.string().optional(),
672
+ nodes: z.array(decisiontreeNodeSchema).min(1),
673
+ edges: z.array(decisiontreeEdgeSchema).default([]),
674
+ orientation: z.enum(["left-right", "top-down"]).default("left-right")
675
+ }).superRefine((data, ctx) => {
676
+ const nodeIds = /* @__PURE__ */ new Set();
677
+ for (const node of data.nodes) {
678
+ if (nodeIds.has(node.id)) {
679
+ ctx.addIssue({
680
+ code: z.ZodIssueCode.custom,
681
+ message: `duplicate node id: ${node.id}`,
682
+ path: ["nodes"]
683
+ });
684
+ return;
685
+ }
686
+ nodeIds.add(node.id);
687
+ }
688
+ for (const edge of data.edges) {
689
+ if (!nodeIds.has(edge.from)) {
690
+ ctx.addIssue({
691
+ code: z.ZodIssueCode.custom,
692
+ message: `edge references unknown node: ${edge.from}`,
693
+ path: ["edges"]
694
+ });
695
+ return;
696
+ }
697
+ if (!nodeIds.has(edge.to)) {
698
+ ctx.addIssue({
699
+ code: z.ZodIssueCode.custom,
700
+ message: `edge references unknown node: ${edge.to}`,
701
+ path: ["edges"]
702
+ });
703
+ return;
704
+ }
705
+ }
706
+ const parentCount = /* @__PURE__ */ new Map();
707
+ for (const id of nodeIds) parentCount.set(id, 0);
708
+ for (const edge of data.edges) {
709
+ parentCount.set(edge.to, (parentCount.get(edge.to) ?? 0) + 1);
710
+ }
711
+ const roots = [];
712
+ for (const [id, count] of parentCount) {
713
+ if (count === 0) roots.push(id);
714
+ if (count > 1) {
715
+ ctx.addIssue({
716
+ code: z.ZodIssueCode.custom,
717
+ message: `node has multiple parents (tree requires exactly one): ${id}`,
718
+ path: ["edges"]
719
+ });
720
+ return;
721
+ }
722
+ }
723
+ if (roots.length === 0) {
724
+ ctx.addIssue({
725
+ code: z.ZodIssueCode.custom,
726
+ message: "decision tree has no root (cycle detected)",
727
+ path: ["nodes"]
728
+ });
729
+ return;
730
+ }
731
+ if (roots.length > 1) {
732
+ ctx.addIssue({
733
+ code: z.ZodIssueCode.custom,
734
+ message: `decision tree must have exactly one root, found ${String(roots.length)}: ${roots.join(", ")}`,
735
+ path: ["nodes"]
736
+ });
737
+ return;
738
+ }
739
+ const root = roots[0];
740
+ if (root === void 0) return;
741
+ const adjacency = /* @__PURE__ */ new Map();
742
+ for (const id of nodeIds) adjacency.set(id, []);
743
+ for (const edge of data.edges) {
744
+ const list = adjacency.get(edge.from);
745
+ if (list) list.push(edge.to);
746
+ }
747
+ const visited = /* @__PURE__ */ new Set();
748
+ const queue = [root];
749
+ while (queue.length > 0) {
750
+ const current = queue.shift();
751
+ if (current === void 0) break;
752
+ if (visited.has(current)) {
753
+ ctx.addIssue({
754
+ code: z.ZodIssueCode.custom,
755
+ message: `cycle detected at node: ${current}`,
756
+ path: ["edges"]
757
+ });
758
+ return;
759
+ }
760
+ visited.add(current);
761
+ for (const next of adjacency.get(current) ?? []) {
762
+ queue.push(next);
763
+ }
764
+ }
765
+ if (visited.size !== nodeIds.size) {
766
+ const orphans = [];
767
+ for (const id of nodeIds) {
768
+ if (!visited.has(id)) orphans.push(id);
769
+ }
770
+ ctx.addIssue({
771
+ code: z.ZodIssueCode.custom,
772
+ message: `orphan nodes not reachable from root: ${orphans.join(", ")}`,
773
+ path: ["nodes"]
774
+ });
775
+ }
776
+ });
777
+ var gaugeSchema = z.object({
778
+ label: z.string(),
779
+ value: z.number(),
780
+ min: z.number().default(0),
781
+ max: z.number(),
782
+ unit: z.string().optional(),
783
+ zones: z.array(
784
+ z.object({
785
+ max: z.number(),
786
+ label: z.string().optional(),
787
+ sentiment: z.enum(["positive", "neutral", "negative"]).optional()
788
+ })
789
+ ).min(1).max(6).optional(),
790
+ target: z.number().optional(),
791
+ shape: z.enum(["semicircle", "full"]).default("semicircle")
792
+ }).refine((d) => d.min < d.max, { message: "min must be less than max" }).refine((d) => d.value >= d.min && d.value <= d.max, {
793
+ message: "value must fall within [min, max]"
794
+ });
573
795
  var entries = [
574
796
  ["graph", graphSchema],
575
797
  ["table", tableSchema],
@@ -600,9 +822,14 @@ var entries = [
600
822
  ["form", formSchema],
601
823
  ["kanban", kanbanSchema],
602
824
  ["annotate", annotateSchema],
825
+ ["sankey", sankeySchema],
603
826
  ["columns", columnsSchema],
604
827
  ["rows", rowsSchema],
605
- ["panel", panelSchema]
828
+ ["panel", panelSchema],
829
+ ["heatmap", heatmapSchema],
830
+ ["funnel", funnelSchema],
831
+ ["decisiontree", decisiontreeSchema],
832
+ ["gauge", gaugeSchema]
606
833
  ];
607
834
  var componentSchemas = new Map(entries);
608
835
  function getJsonSchema(componentType) {
@@ -611,6 +838,6 @@ function getJsonSchema(componentType) {
611
838
  return zodToJsonSchema(schema);
612
839
  }
613
840
 
614
- export { accordionSchema, annotateSchema, architectureSchema, calloutSchema, cardSchema, chartSchema, codediffSchema, columnsSchema, comparisonSchema, componentSchemas, equationSchema, filetreeSchema, flowchartSchema, formSchema, getJsonSchema, graphSchema, infographicSchema, inlineContentSchema, kanbanSchema, kpiSchema, matrixSchema, mindmapSchema, panelSchema, pollSchema, quizSchema, rankerSchema, ratingSchema, relationSchema, rowsSchema, sequenceSchema, sliderSchema, stepsSchema, tableSchema, tabsSchema, timelineSchema };
841
+ export { accordionSchema, annotateSchema, architectureSchema, calloutSchema, cardSchema, chartSchema, codediffSchema, columnsSchema, comparisonSchema, componentSchemas, decisiontreeSchema, equationSchema, filetreeSchema, flowchartSchema, formSchema, funnelSchema, gaugeSchema, getJsonSchema, graphSchema, heatmapSchema, infographicSchema, inlineContentSchema, kanbanSchema, kpiSchema, matrixSchema, mindmapSchema, panelSchema, pollSchema, quizSchema, rankerSchema, ratingSchema, relationSchema, rowsSchema, sankeySchema, sequenceSchema, sliderSchema, stepsSchema, tableSchema, tabsSchema, timelineSchema };
615
842
  //# sourceMappingURL=index.js.map
616
843
  //# sourceMappingURL=index.js.map