@particle-academy/fancy-3d 0.5.0 → 0.6.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.cjs CHANGED
@@ -554,6 +554,63 @@ var domEngine = {
554
554
  };
555
555
  }
556
556
  };
557
+
558
+ // src/frame.ts
559
+ var PX_PER_UNIT = 100;
560
+ var DEFAULT_NODE_SIZE = { w: 240, h: 150 };
561
+ var FIT_PADDING = 40;
562
+ var FIT_MAX_ZOOM = 1.5;
563
+ function nodeSize(node) {
564
+ return node.size ?? DEFAULT_NODE_SIZE;
565
+ }
566
+ function sceneBounds(scene) {
567
+ if (scene.nodes.length === 0) return null;
568
+ let minX = Infinity;
569
+ let minY = Infinity;
570
+ let maxX = -Infinity;
571
+ let maxY = -Infinity;
572
+ for (const node of scene.nodes) {
573
+ const { w, h } = nodeSize(node);
574
+ minX = Math.min(minX, node.position.x);
575
+ minY = Math.min(minY, node.position.y);
576
+ maxX = Math.max(maxX, node.position.x + w);
577
+ maxY = Math.max(maxY, node.position.y + h);
578
+ }
579
+ return { minX, minY, maxX, maxY };
580
+ }
581
+ function fitZoom(bounds, width, height) {
582
+ const contentW = bounds.maxX - bounds.minX + FIT_PADDING * 2;
583
+ const contentH = bounds.maxY - bounds.minY + FIT_PADDING * 2;
584
+ if (width <= 0 || height <= 0 || contentW <= 0 || contentH <= 0) return 1;
585
+ return Math.min(width / contentW, height / contentH, FIT_MAX_ZOOM);
586
+ }
587
+ function sceneToWorld(scene, pxPerUnit = PX_PER_UNIT) {
588
+ const bounds = sceneBounds(scene);
589
+ if (!bounds) return [];
590
+ const midX = (bounds.minX + bounds.maxX) / 2;
591
+ const midY = (bounds.minY + bounds.maxY) / 2;
592
+ return scene.nodes.map((node) => {
593
+ const { w, h } = nodeSize(node);
594
+ return {
595
+ id: node.id,
596
+ x: (node.position.x + w / 2 - midX) / pxPerUnit,
597
+ y: (midY - (node.position.y + h / 2)) / pxPerUnit,
598
+ z: (node.position.z ?? 0) / pxPerUnit,
599
+ width: w / pxPerUnit,
600
+ height: h / pxPerUnit,
601
+ pixelWidth: w,
602
+ pixelHeight: h
603
+ };
604
+ });
605
+ }
606
+ function frameScene(scene, opts) {
607
+ const pxPerUnit = opts.pxPerUnit ?? PX_PER_UNIT;
608
+ const bounds = sceneBounds(scene);
609
+ const zoom = bounds ? fitZoom(bounds, opts.width, opts.height) : 1;
610
+ const height = opts.height > 0 ? opts.height : 1;
611
+ const distance = height / (2 * Math.tan(opts.fovY / 2) * zoom * pxPerUnit);
612
+ return { target: [0, 0, 0], distance, beta: Math.PI / 2, zoom };
613
+ }
557
614
  function resolveEngine(spec) {
558
615
  if (!spec || spec === "dom") return domEngine;
559
616
  return spec;
@@ -633,12 +690,12 @@ function CanvasRoot({
633
690
  maxX = Math.max(maxX, r.x + r.width);
634
691
  maxY = Math.max(maxY, r.y + r.height);
635
692
  });
636
- const padding = 40;
693
+ const padding = FIT_PADDING;
637
694
  const contentW = maxX - minX + padding * 2;
638
695
  const contentH = maxY - minY + padding * 2;
639
696
  const cw = container.clientWidth;
640
697
  const ch = container.clientHeight;
641
- const zoom = Math.min(cw / contentW, ch / contentH, 1.5);
698
+ const zoom = fitZoom({ minX, minY, maxX, maxY }, cw, ch);
642
699
  const panX = (cw - contentW * zoom) / 2 - minX * zoom + padding * zoom;
643
700
  const panY = (ch - contentH * zoom) / 2 - minY * zoom + padding * zoom;
644
701
  setViewport({ panX, panY, zoom });
@@ -730,6 +787,489 @@ var Canvas = Object.assign(CanvasRoot, {
730
787
  Minimap: CanvasMinimap,
731
788
  Controls: CanvasControls
732
789
  });
790
+
791
+ // src/theme.ts
792
+ var SCENE_PALETTES = {
793
+ light: {
794
+ canvas: "#fafafa",
795
+ grid: "rgba(161, 161, 170, 0.3)",
796
+ card: "#ffffff",
797
+ cardBorder: "#e4e4e7",
798
+ edge: "#d4d4d8",
799
+ text: "#18181b",
800
+ body: "#3f3f46",
801
+ muted: "#71717a",
802
+ subtle: "#f4f4f5",
803
+ accent: "#6366f1",
804
+ onAccent: "#ffffff",
805
+ avatar: "#e4e4e7",
806
+ avatarText: "#3f3f46",
807
+ success: "#059669",
808
+ warning: "#d97706",
809
+ danger: "#e11d48",
810
+ info: "#2563eb",
811
+ code: "#18181b",
812
+ codeText: "#f4f4f5"
813
+ },
814
+ dark: {
815
+ canvas: "#09090b",
816
+ grid: "rgba(161, 161, 170, 0.3)",
817
+ card: "#18181b",
818
+ cardBorder: "#3f3f46",
819
+ edge: "#27272a",
820
+ text: "#f4f4f5",
821
+ body: "#d4d4d8",
822
+ muted: "#a1a1aa",
823
+ subtle: "#27272a",
824
+ accent: "#818cf8",
825
+ onAccent: "#ffffff",
826
+ avatar: "#3f3f46",
827
+ avatarText: "#e4e4e7",
828
+ success: "#10b981",
829
+ warning: "#f59e0b",
830
+ danger: "#f43f5e",
831
+ info: "#60a5fa",
832
+ code: "#09090b",
833
+ codeText: "#f4f4f5"
834
+ }
835
+ };
836
+ var DARK_THEME_SELECTOR = '.dark, [data-theme="dark"]';
837
+ function resolveSceneTheme(theme, el) {
838
+ if (theme === "light" || theme === "dark") return theme;
839
+ const start = el ?? (typeof document !== "undefined" ? document.documentElement : null);
840
+ if (!start) return "light";
841
+ return start.closest(DARK_THEME_SELECTOR) ? "dark" : "light";
842
+ }
843
+ function scenePalette(theme, el) {
844
+ return SCENE_PALETTES[resolveSceneTheme(theme, el)];
845
+ }
846
+
847
+ // src/paint.ts
848
+ var SANS = "ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif";
849
+ var MONO = "ui-monospace, SFMono-Regular, Menlo, monospace";
850
+ var PAD = 16;
851
+ var RADIUS = 12;
852
+ function font(weight, px, family = SANS) {
853
+ return `${weight} ${px}px ${family}`;
854
+ }
855
+ function roundRect(ctx, x, y, w, h, r) {
856
+ const rr = Math.max(0, Math.min(r, w / 2, h / 2));
857
+ ctx.beginPath();
858
+ ctx.moveTo(x + rr, y);
859
+ ctx.arcTo(x + w, y, x + w, y + h, rr);
860
+ ctx.arcTo(x + w, y + h, x, y + h, rr);
861
+ ctx.arcTo(x, y + h, x, y, rr);
862
+ ctx.arcTo(x, y, x + w, y, rr);
863
+ ctx.closePath();
864
+ }
865
+ function paintCard(ctx, w, h, p, selected) {
866
+ roundRect(ctx, 0.5, 0.5, w - 1, h - 1, RADIUS);
867
+ ctx.fillStyle = p.card;
868
+ ctx.fill();
869
+ ctx.strokeStyle = selected ? p.accent : p.cardBorder;
870
+ ctx.lineWidth = selected ? 2 : 1;
871
+ ctx.stroke();
872
+ }
873
+ function paintLabel(ctx, text, x, y, p) {
874
+ ctx.fillStyle = p.muted;
875
+ ctx.font = font(500, 12);
876
+ ctx.textBaseline = "top";
877
+ ctx.fillText(text.toUpperCase(), x, y);
878
+ }
879
+ function withAlpha(hex, alpha) {
880
+ const m = /^#([0-9a-f]{6})$/i.exec(hex);
881
+ if (!m) return hex;
882
+ const n = parseInt(m[1], 16);
883
+ return `rgba(${n >> 16 & 255}, ${n >> 8 & 255}, ${n & 255}, ${alpha})`;
884
+ }
885
+ function paintSparkline(ctx, values, x, y, w, h, variant, color) {
886
+ if (values.length === 0 || w <= 0 || h <= 0) return;
887
+ const max = Math.max(...values, 1);
888
+ const min = Math.min(...values, 0);
889
+ const range = max - min || 1;
890
+ const step = w / Math.max(values.length - 1, 1);
891
+ const yOf = (v) => y + h - (v - min) / range * h;
892
+ if (variant === "bar") {
893
+ const gap = 2;
894
+ const bw = w / values.length - gap;
895
+ ctx.fillStyle = color;
896
+ values.forEach((v, i) => {
897
+ const bh = Math.max((v - min) / range * h, 0.5);
898
+ roundRect(ctx, x + i * (bw + gap), y + h - bh, bw, bh, 1);
899
+ ctx.fill();
900
+ });
901
+ return;
902
+ }
903
+ const trace = () => {
904
+ ctx.beginPath();
905
+ values.forEach((v, i) => i === 0 ? ctx.moveTo(x + i * step, yOf(v)) : ctx.lineTo(x + i * step, yOf(v)));
906
+ };
907
+ if (variant === "area") {
908
+ trace();
909
+ ctx.lineTo(x + w, y + h);
910
+ ctx.lineTo(x, y + h);
911
+ ctx.closePath();
912
+ ctx.fillStyle = withAlpha(color, 0.18);
913
+ ctx.fill();
914
+ }
915
+ trace();
916
+ ctx.strokeStyle = color;
917
+ ctx.lineWidth = 1.5;
918
+ ctx.lineJoin = "round";
919
+ ctx.stroke();
920
+ }
921
+ function wrapText(ctx, text, x, y, maxW, lineH, maxY) {
922
+ const words = text.split(" ");
923
+ let line = "";
924
+ let yy = y;
925
+ for (const word of words) {
926
+ const test = line ? `${line} ${word}` : word;
927
+ if (ctx.measureText(test).width > maxW && line) {
928
+ if (maxY !== void 0 && yy > maxY) return;
929
+ ctx.fillText(line, x, yy);
930
+ line = word;
931
+ yy += lineH;
932
+ } else {
933
+ line = test;
934
+ }
935
+ }
936
+ if (line && (maxY === void 0 || yy <= maxY)) ctx.fillText(line, x, yy);
937
+ }
938
+ function paintAtScenePx(ctx, spec, w, h, selected, p) {
939
+ ctx.textAlign = "left";
940
+ ctx.textBaseline = "top";
941
+ if (spec.kind === "screen") {
942
+ paintScreen(ctx, spec, w, h);
943
+ return;
944
+ }
945
+ if (spec.kind === "callout") {
946
+ const tone = spec.tone === "danger" ? p.danger : spec.tone === "warning" ? p.warning : spec.tone === "success" ? p.success : p.info;
947
+ roundRect(ctx, 0.5, 0.5, w - 1, h - 1, RADIUS);
948
+ ctx.fillStyle = p.card;
949
+ ctx.fill();
950
+ ctx.fillStyle = withAlpha(tone, 0.1);
951
+ ctx.fill();
952
+ ctx.strokeStyle = selected ? p.accent : withAlpha(tone, 0.35);
953
+ ctx.lineWidth = selected ? 2 : 1;
954
+ ctx.stroke();
955
+ ctx.fillStyle = tone;
956
+ ctx.font = font(600, 14);
957
+ ctx.fillText(spec.title, PAD, PAD);
958
+ ctx.fillStyle = p.body;
959
+ ctx.font = font(400, 12);
960
+ wrapText(ctx, spec.body, PAD, PAD + 22, w - PAD * 2, 16, h - PAD - 12);
961
+ return;
962
+ }
963
+ paintCard(ctx, w, h, p, selected);
964
+ switch (spec.kind) {
965
+ case "kpi": {
966
+ paintLabel(ctx, spec.label, PAD, PAD, p);
967
+ ctx.textBaseline = "alphabetic";
968
+ const baseline = PAD + 44;
969
+ ctx.fillStyle = p.text;
970
+ ctx.font = font(700, 24);
971
+ ctx.fillText(spec.value, PAD, baseline);
972
+ if (spec.delta) {
973
+ const valueW = ctx.measureText(spec.value).width;
974
+ ctx.fillStyle = spec.trend === "up" ? p.success : spec.trend === "down" ? p.danger : p.muted;
975
+ ctx.font = font(500, 12);
976
+ ctx.fillText(spec.delta, PAD + valueW + 8, baseline);
977
+ }
978
+ break;
979
+ }
980
+ case "chart": {
981
+ paintLabel(ctx, spec.title, PAD, PAD, p);
982
+ const top = PAD + 16 + 8;
983
+ paintSparkline(ctx, spec.series, PAD, top, w - PAD * 2, h - PAD - top, spec.variant, spec.color ?? p.accent);
984
+ break;
985
+ }
986
+ case "profile": {
987
+ const r = 20;
988
+ const cx = PAD + r;
989
+ const cy = PAD + r;
990
+ ctx.fillStyle = p.avatar;
991
+ ctx.beginPath();
992
+ ctx.arc(cx, cy, r, 0, Math.PI * 2);
993
+ ctx.fill();
994
+ ctx.fillStyle = p.avatarText;
995
+ ctx.font = font(500, 14);
996
+ ctx.textAlign = "center";
997
+ ctx.textBaseline = "middle";
998
+ ctx.fillText(spec.initials, cx, cy);
999
+ ctx.textAlign = "left";
1000
+ if (spec.status) {
1001
+ const dot = spec.status === "online" ? p.success : spec.status === "away" ? p.warning : p.muted;
1002
+ ctx.fillStyle = p.card;
1003
+ ctx.beginPath();
1004
+ ctx.arc(cx + r * 0.72, cy + r * 0.72, 6, 0, Math.PI * 2);
1005
+ ctx.fill();
1006
+ ctx.fillStyle = dot;
1007
+ ctx.beginPath();
1008
+ ctx.arc(cx + r * 0.72, cy + r * 0.72, 4.5, 0, Math.PI * 2);
1009
+ ctx.fill();
1010
+ }
1011
+ const tx = PAD + r * 2 + 12;
1012
+ ctx.textBaseline = "alphabetic";
1013
+ ctx.fillStyle = p.text;
1014
+ ctx.font = font(500, 16);
1015
+ ctx.fillText(spec.name, tx, cy - 2);
1016
+ ctx.fillStyle = p.muted;
1017
+ ctx.font = font(400, 14);
1018
+ ctx.fillText(spec.role, tx, cy + 16);
1019
+ break;
1020
+ }
1021
+ case "kanban": {
1022
+ const gap = 8;
1023
+ const n = Math.max(spec.columns.length, 1);
1024
+ const colW = (w - PAD * 2 - (n - 1) * gap) / n;
1025
+ spec.columns.forEach((col, i) => {
1026
+ const x = PAD + i * (colW + gap);
1027
+ ctx.fillStyle = p.subtle;
1028
+ roundRect(ctx, x, PAD, colW, h - PAD * 2, 8);
1029
+ ctx.fill();
1030
+ ctx.fillStyle = p.muted;
1031
+ ctx.font = font(600, 10);
1032
+ ctx.textBaseline = "top";
1033
+ ctx.fillText(col.title.toUpperCase(), x + 8, PAD + 8);
1034
+ col.cards.forEach((c, j) => {
1035
+ const y = PAD + 28 + j * 32;
1036
+ ctx.fillStyle = p.card;
1037
+ roundRect(ctx, x + 8, y, colW - 16, 26, 4);
1038
+ ctx.fill();
1039
+ ctx.strokeStyle = p.cardBorder;
1040
+ ctx.lineWidth = 1;
1041
+ ctx.stroke();
1042
+ ctx.fillStyle = p.body;
1043
+ ctx.font = font(400, 12);
1044
+ ctx.fillText(c, x + 16, y + 7);
1045
+ });
1046
+ });
1047
+ break;
1048
+ }
1049
+ case "table": {
1050
+ paintLabel(ctx, spec.title, PAD, PAD, p);
1051
+ const n = Math.max(spec.columns.length, 1);
1052
+ const colW = (w - PAD * 2) / n;
1053
+ ctx.fillStyle = p.muted;
1054
+ ctx.font = font(500, 12);
1055
+ spec.columns.forEach((c, i) => ctx.fillText(c, PAD + i * colW, PAD + 30));
1056
+ ctx.fillStyle = p.body;
1057
+ ctx.font = font(400, 12);
1058
+ spec.rows.forEach((row, ri) => {
1059
+ row.forEach((cell, ci) => ctx.fillText(String(cell), PAD + ci * colW, PAD + 56 + ri * 26));
1060
+ });
1061
+ break;
1062
+ }
1063
+ case "form": {
1064
+ paintLabel(ctx, spec.title, PAD, PAD, p);
1065
+ spec.fields.forEach((f, i) => {
1066
+ const y = PAD + 28 + i * 34;
1067
+ ctx.fillStyle = p.body;
1068
+ ctx.font = font(400, 12);
1069
+ ctx.fillText(f.label, PAD, y + 7);
1070
+ if (f.type === "switch") {
1071
+ ctx.fillStyle = p.accent;
1072
+ roundRect(ctx, w - PAD - 36, y + 2, 36, 20, 10);
1073
+ ctx.fill();
1074
+ ctx.fillStyle = p.onAccent;
1075
+ ctx.beginPath();
1076
+ ctx.arc(w - PAD - 12, y + 12, 8, 0, Math.PI * 2);
1077
+ ctx.fill();
1078
+ } else {
1079
+ ctx.fillStyle = p.card;
1080
+ roundRect(ctx, w - PAD - 112, y, 112, 26, 4);
1081
+ ctx.fill();
1082
+ ctx.strokeStyle = p.cardBorder;
1083
+ ctx.lineWidth = 1;
1084
+ ctx.stroke();
1085
+ }
1086
+ });
1087
+ break;
1088
+ }
1089
+ case "action": {
1090
+ paintLabel(ctx, spec.title, PAD, PAD, p);
1091
+ let bx = PAD;
1092
+ const by = PAD + 26;
1093
+ ctx.font = font(500, 12);
1094
+ spec.buttons.forEach((b) => {
1095
+ const tw = ctx.measureText(b.label).width + 20;
1096
+ if (b.variant === "primary") {
1097
+ ctx.fillStyle = p.accent;
1098
+ roundRect(ctx, bx, by, tw, 28, 6);
1099
+ ctx.fill();
1100
+ } else if (b.variant !== "ghost") {
1101
+ ctx.fillStyle = p.card;
1102
+ roundRect(ctx, bx, by, tw, 28, 6);
1103
+ ctx.fill();
1104
+ ctx.strokeStyle = p.cardBorder;
1105
+ ctx.lineWidth = 1;
1106
+ ctx.stroke();
1107
+ }
1108
+ ctx.fillStyle = b.variant === "primary" ? p.onAccent : p.text;
1109
+ ctx.fillText(b.label, bx + 10, by + 8);
1110
+ bx += tw + 8;
1111
+ });
1112
+ break;
1113
+ }
1114
+ case "timeline": {
1115
+ paintLabel(ctx, spec.title, PAD, PAD, p);
1116
+ spec.events.forEach((e, i) => {
1117
+ const y = PAD + 28 + i * 28;
1118
+ ctx.fillStyle = p.accent;
1119
+ ctx.beginPath();
1120
+ ctx.arc(PAD + 4, y + 7, 4, 0, Math.PI * 2);
1121
+ ctx.fill();
1122
+ if (i < spec.events.length - 1) {
1123
+ ctx.strokeStyle = p.cardBorder;
1124
+ ctx.lineWidth = 1;
1125
+ ctx.beginPath();
1126
+ ctx.moveTo(PAD + 4, y + 12);
1127
+ ctx.lineTo(PAD + 4, y + 28);
1128
+ ctx.stroke();
1129
+ }
1130
+ ctx.fillStyle = p.muted;
1131
+ ctx.font = font(500, 11, MONO);
1132
+ ctx.fillText(e.at, PAD + 16, y);
1133
+ ctx.fillStyle = p.body;
1134
+ ctx.font = font(400, 12);
1135
+ ctx.fillText(e.label, PAD + 64, y);
1136
+ });
1137
+ break;
1138
+ }
1139
+ case "code": {
1140
+ paintLabel(ctx, spec.title, PAD, PAD, p);
1141
+ const top = PAD + 24;
1142
+ ctx.fillStyle = p.code;
1143
+ roundRect(ctx, PAD, top, w - PAD * 2, h - PAD - top, 4);
1144
+ ctx.fill();
1145
+ ctx.fillStyle = p.codeText;
1146
+ ctx.font = font(400, 11, MONO);
1147
+ spec.code.split("\n").forEach((ln, i) => ctx.fillText(ln, PAD + 8, top + 8 + i * 18));
1148
+ break;
1149
+ }
1150
+ case "image": {
1151
+ ctx.fillStyle = p.subtle;
1152
+ roundRect(ctx, 1, 1, w - 2, h - 2, RADIUS - 1);
1153
+ ctx.fill();
1154
+ ctx.fillStyle = p.muted;
1155
+ ctx.font = font(400, 12);
1156
+ ctx.textAlign = "center";
1157
+ ctx.textBaseline = "middle";
1158
+ ctx.fillText(spec.alt, w / 2, h / 2);
1159
+ ctx.textAlign = "left";
1160
+ break;
1161
+ }
1162
+ case "text": {
1163
+ ctx.fillStyle = p.text;
1164
+ ctx.font = font(600, 14);
1165
+ ctx.fillText(spec.heading, PAD, PAD);
1166
+ ctx.fillStyle = p.body;
1167
+ ctx.font = font(400, 12);
1168
+ wrapText(ctx, spec.body, PAD, PAD + 22, w - PAD * 2, 16, h - PAD - 12);
1169
+ break;
1170
+ }
1171
+ case "demoPage": {
1172
+ const headerH = 34;
1173
+ ctx.save();
1174
+ roundRect(ctx, 0.5, 0.5, w - 1, h - 1, RADIUS);
1175
+ ctx.clip();
1176
+ ctx.fillStyle = spec.accent;
1177
+ ctx.fillRect(0, 0, w, headerH);
1178
+ ctx.restore();
1179
+ ctx.font = font(700, 10);
1180
+ const chip = spec.category.toUpperCase();
1181
+ const chipW = ctx.measureText(chip).width + 16;
1182
+ ctx.fillStyle = "rgba(255,255,255,0.2)";
1183
+ roundRect(ctx, 12, 8, chipW, 18, 9);
1184
+ ctx.fill();
1185
+ ctx.fillStyle = "#ffffff";
1186
+ ctx.fillText(chip, 20, 12);
1187
+ ctx.fillStyle = "rgba(255,255,255,0.85)";
1188
+ ctx.font = font(400, 10, MONO);
1189
+ ctx.textAlign = "right";
1190
+ ctx.fillText(spec.path, w - 12, 12);
1191
+ ctx.textAlign = "left";
1192
+ ctx.fillStyle = p.text;
1193
+ ctx.font = font(800, 16);
1194
+ ctx.fillText(spec.name, PAD, headerH + PAD);
1195
+ ctx.fillStyle = p.muted;
1196
+ ctx.font = font(400, 12);
1197
+ const ctaH = 22;
1198
+ const ctaY = h - PAD - ctaH;
1199
+ wrapText(ctx, spec.description, PAD, headerH + PAD + 26, w - PAD * 2, 16, ctaY - 20);
1200
+ ctx.font = font(600, 11);
1201
+ const cta = "Open demo \u2192";
1202
+ ctx.fillStyle = spec.accent;
1203
+ roundRect(ctx, PAD, ctaY, ctx.measureText(cta).width + 16, ctaH, 6);
1204
+ ctx.fill();
1205
+ ctx.fillStyle = "#0f172a";
1206
+ ctx.fillText(cta, PAD + 8, ctaY + 6);
1207
+ break;
1208
+ }
1209
+ }
1210
+ }
1211
+ function paintScreen(ctx, spec, w, h) {
1212
+ const bezel = spec.bezel ?? "#0b0f17";
1213
+ const t = spec.bezelThickness ?? 14;
1214
+ const on = spec.on ?? true;
1215
+ const brightness = spec.brightness ?? (on ? 1 : 0.06);
1216
+ const bg = spec.background ?? "#020617";
1217
+ ctx.fillStyle = bezel;
1218
+ roundRect(ctx, 0, 0, w, h, 16);
1219
+ ctx.fill();
1220
+ const sw = w - t * 2;
1221
+ const sh = h - t * 2;
1222
+ ctx.save();
1223
+ ctx.fillStyle = bg;
1224
+ roundRect(ctx, t, t, sw, sh, 6);
1225
+ ctx.fill();
1226
+ roundRect(ctx, t, t, sw, sh, 6);
1227
+ ctx.clip();
1228
+ ctx.translate(t, t);
1229
+ ctx.globalAlpha = brightness;
1230
+ const c = spec.content;
1231
+ if (c.type === "label") {
1232
+ ctx.fillStyle = "#f4f4f5";
1233
+ ctx.font = font(700, 18);
1234
+ ctx.textAlign = "center";
1235
+ ctx.textBaseline = "middle";
1236
+ ctx.fillText(c.title, sw / 2, sh / 2 - (c.subtitle ? 10 : 0));
1237
+ if (c.subtitle) {
1238
+ ctx.fillStyle = "#a1a1aa";
1239
+ ctx.font = font(400, 12);
1240
+ ctx.fillText(c.subtitle, sw / 2, sh / 2 + 12);
1241
+ }
1242
+ } else if (c.type === "paint") {
1243
+ c.paint(ctx, sw, sh);
1244
+ } else {
1245
+ ctx.fillStyle = "#71717a";
1246
+ ctx.font = font(500, 12);
1247
+ ctx.textAlign = "center";
1248
+ ctx.textBaseline = "middle";
1249
+ ctx.fillText(c.alt ?? "image", sw / 2, sh / 2);
1250
+ }
1251
+ ctx.globalAlpha = 1;
1252
+ ctx.restore();
1253
+ ctx.textAlign = "left";
1254
+ ctx.fillStyle = on ? "#10b981" : "#475569";
1255
+ ctx.beginPath();
1256
+ ctx.arc(w - t / 2 - 3, h - t / 2 - 3, 3, 0, Math.PI * 2);
1257
+ ctx.fill();
1258
+ }
1259
+ function paletteOf(theme) {
1260
+ if (theme && typeof theme === "object") return theme;
1261
+ return theme === "light" || theme === "dark" ? SCENE_PALETTES[theme] : scenePalette();
1262
+ }
1263
+ function paintWidget(ctx, spec, w, h, opts = {}) {
1264
+ const p = paletteOf(opts.theme);
1265
+ const scenePx = opts.scenePx ?? (h >= DEFAULT_NODE_SIZE.h ? { w, h } : { w: w * DEFAULT_NODE_SIZE.h / h, h: DEFAULT_NODE_SIZE.h });
1266
+ const sx = w / scenePx.w;
1267
+ const sy = h / scenePx.h;
1268
+ ctx.save();
1269
+ ctx.scale(sx, sy);
1270
+ paintAtScenePx(ctx, spec, scenePx.w, scenePx.h, opts.selected ?? false, p);
1271
+ ctx.restore();
1272
+ }
733
1273
  /*! Bundled license information:
734
1274
 
735
1275
  lucide-react/dist/esm/shared/src/utils.js:
@@ -750,9 +1290,23 @@ lucide-react/dist/esm/lucide-react.js:
750
1290
  */
751
1291
 
752
1292
  exports.Canvas = Canvas;
1293
+ exports.DARK_THEME_SELECTOR = DARK_THEME_SELECTOR;
1294
+ exports.DEFAULT_NODE_SIZE = DEFAULT_NODE_SIZE;
1295
+ exports.FIT_MAX_ZOOM = FIT_MAX_ZOOM;
1296
+ exports.FIT_PADDING = FIT_PADDING;
1297
+ exports.PX_PER_UNIT = PX_PER_UNIT;
1298
+ exports.SCENE_PALETTES = SCENE_PALETTES;
753
1299
  exports.domEngine = domEngine;
1300
+ exports.fitZoom = fitZoom;
1301
+ exports.frameScene = frameScene;
754
1302
  exports.nextId = nextId;
1303
+ exports.nodeSize = nodeSize;
1304
+ exports.paintWidget = paintWidget;
755
1305
  exports.renderScene = renderScene;
1306
+ exports.resolveSceneTheme = resolveSceneTheme;
1307
+ exports.sceneBounds = sceneBounds;
1308
+ exports.scenePalette = scenePalette;
1309
+ exports.sceneToWorld = sceneToWorld;
756
1310
  exports.useCanvas = useCanvas;
757
1311
  //# sourceMappingURL=index.cjs.map
758
1312
  //# sourceMappingURL=index.cjs.map