kaabalah 6.4.3 → 6.5.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/cli.js CHANGED
@@ -8932,7 +8932,7 @@ var import_config3 = require("dotenv/config");
8932
8932
  // package.json
8933
8933
  var package_default = {
8934
8934
  name: "kaabalah",
8935
- version: "6.4.3",
8935
+ version: "6.5.0",
8936
8936
  description: "The de-facto library for any esoteric calculations and tooling",
8937
8937
  engines: {
8938
8938
  node: ">=18.18.0"
@@ -9215,11 +9215,20 @@ var COMMANDS = [
9215
9215
  args: [],
9216
9216
  flags: [
9217
9217
  { name: "system", type: "string", default: "kaabalah", description: "Tree system: kaabalah, hermetic-qabalah, lurianic-kabbalah" },
9218
- { name: "units", type: "string", default: "both", description: "Coordinate space: percentages, viewBoxUnits, or both" }
9218
+ { name: "units", type: "string", default: "both", description: "Coordinate space: percentages, viewBoxUnits, or both" },
9219
+ { name: "render-model", type: "boolean", default: false, description: "Return activation-aware render model geometry instead of the basic layout" },
9220
+ { name: "activations", type: "string", description: "Path to activation JSON array or object with an activations array" },
9221
+ { name: "palette", type: "string", default: "color", description: 'Render-model palette metadata: "color" or "monochrome"' },
9222
+ { name: "daath-layer", type: "string", default: "front", description: 'Render-model Daath layer: "front" or "back"' },
9223
+ { name: "viewbox-width", type: "number", description: "Override render-model viewBox width" },
9224
+ { name: "viewbox-height", type: "number", description: "Override render-model viewBox height" },
9225
+ { name: "viewbox-min-x", type: "number", default: 0, description: "Override render-model viewBox min-x" },
9226
+ { name: "viewbox-min-y", type: "number", default: 0, description: "Override render-model viewBox min-y" }
9219
9227
  ],
9220
9228
  examples: [
9221
9229
  "kaabalah tree:layout --json --compact",
9222
- "kaabalah tree:layout --system=hermetic-qabalah --units=percentages --json"
9230
+ "kaabalah tree:layout --system=hermetic-qabalah --units=percentages --json",
9231
+ "kaabalah tree:layout --render-model --activations=activations.json --json --compact"
9223
9232
  ]
9224
9233
  },
9225
9234
  {
@@ -9233,6 +9242,7 @@ var COMMANDS = [
9233
9242
  { name: "background", type: "string", default: "white", description: 'Background fill color, or "transparent"' },
9234
9243
  { name: "palette", type: "string", default: "color", description: 'Palette: "color" or "monochrome"' },
9235
9244
  { name: "daath-layer", type: "string", default: "front", description: 'Render Daath in front of or behind the paths: "front" or "back"' },
9245
+ { name: "activations", type: "string", description: "Path to activation JSON array or object with an activations array" },
9236
9246
  { name: "output", type: "string", description: "Write the SVG to a file instead of stdout" },
9237
9247
  { name: "viewbox-width", type: "number", description: "Override SVG viewBox width" },
9238
9248
  { name: "viewbox-height", type: "number", description: "Override SVG viewBox height" },
@@ -9242,7 +9252,8 @@ var COMMANDS = [
9242
9252
  examples: [
9243
9253
  "kaabalah tree:svg --json --compact --fields=svg",
9244
9254
  "kaabalah tree:svg --background=transparent --palette=monochrome --output=tree.svg --json",
9245
- "kaabalah tree:svg --background=transparent --daath-layer=back --json --compact"
9255
+ "kaabalah tree:svg --background=transparent --daath-layer=back --json --compact",
9256
+ "kaabalah tree:svg --background=transparent --activations=activations.json --json --compact --fields=svg"
9246
9257
  ]
9247
9258
  },
9248
9259
  {
@@ -19931,34 +19942,58 @@ kaabalah v${VERSION}
19931
19942
  }
19932
19943
 
19933
19944
  // src/ifa/index.ts
19945
+ function isMidnight(date, mode) {
19946
+ if (mode === "utc") {
19947
+ return date.getUTCHours() === 0 && date.getUTCMinutes() === 0 && date.getUTCSeconds() === 0 && date.getUTCMilliseconds() === 0;
19948
+ }
19949
+ return date.getHours() === 0 && date.getMinutes() === 0 && date.getSeconds() === 0 && date.getMilliseconds() === 0;
19950
+ }
19951
+ function extractDateParts(date) {
19952
+ if (!(date instanceof Date) || Number.isNaN(date.getTime())) {
19953
+ throw new Error("Date must be a valid Date object");
19954
+ }
19955
+ const useLocalDate = isMidnight(date, "local") && !isMidnight(date, "utc");
19956
+ if (useLocalDate) {
19957
+ return {
19958
+ day: date.getDate().toString().padStart(2, "0"),
19959
+ month: (date.getMonth() + 1).toString().padStart(2, "0"),
19960
+ year: date.getFullYear().toString().padStart(4, "0")
19961
+ };
19962
+ }
19963
+ const formattedDate = date.toISOString().split("T")[0];
19964
+ const [year, month, day] = formattedDate.split("-");
19965
+ return { day, month, year };
19966
+ }
19967
+ function reduceNumber(num) {
19968
+ if (num <= 16) {
19969
+ return num;
19970
+ }
19971
+ return reduceNumber(
19972
+ num.toString().split("").reduce((sum, digit) => sum + Number.parseInt(digit, 10), 0)
19973
+ );
19974
+ }
19934
19975
  function calculateOdu(date) {
19935
- const day = date.getDate().toString().padStart(2, "0");
19936
- const month = (date.getMonth() + 1).toString().padStart(2, "0");
19937
- const year = date.getFullYear().toString();
19976
+ const { day, month, year } = extractDateParts(date);
19938
19977
  const leftNumbers = [
19939
- parseInt(day[0]),
19978
+ Number.parseInt(day[0], 10),
19940
19979
  // First digit of day
19941
- parseInt(month[0]),
19980
+ Number.parseInt(month[0], 10),
19942
19981
  // First digit of month
19943
- parseInt(year[0]),
19982
+ Number.parseInt(year[0], 10),
19944
19983
  // First digit of year
19945
- parseInt(year[2])
19984
+ Number.parseInt(year[2], 10)
19946
19985
  // Third digit of year
19947
19986
  ];
19948
19987
  const rightNumbers = [
19949
- parseInt(day[1]),
19988
+ Number.parseInt(day[1], 10),
19950
19989
  // Second digit of day
19951
- parseInt(month[1]),
19990
+ Number.parseInt(month[1], 10),
19952
19991
  // Second digit of month
19953
- parseInt(year[1]),
19992
+ Number.parseInt(year[1], 10),
19954
19993
  // Second digit of year
19955
- parseInt(year[3])
19994
+ Number.parseInt(year[3], 10)
19956
19995
  // Fourth digit of year
19957
19996
  ];
19958
- function reduceNumber(num) {
19959
- if (num <= 16) return num;
19960
- return reduceNumber(num.toString().split("").reduce((a, b) => a + parseInt(b), 0));
19961
- }
19962
19997
  const rawLeftSum = leftNumbers.reduce((a, b) => a + b, 0);
19963
19998
  const rawRightSum = rightNumbers.reduce((a, b) => a + b, 0);
19964
19999
  const north = reduceNumber(rawLeftSum);
@@ -22882,6 +22917,9 @@ var DEFAULT_SPHERE_RADIUS = 30;
22882
22917
  var DEFAULT_PATH_EDGE_WIDTH = 26;
22883
22918
  var DEFAULT_PATH_MAIN_WIDTH = 22;
22884
22919
  var DEFAULT_PATH_HIGHLIGHT_WIDTH = 8;
22920
+ var DEFAULT_SPHERE_HIT_RADIUS = DEFAULT_SPHERE_RADIUS + 8;
22921
+ var DEFAULT_PATH_HIT_STROKE_WIDTH = DEFAULT_PATH_EDGE_WIDTH + 8;
22922
+ var MUTED_TARGET_COLOR = "#AAA";
22885
22923
  var sphereId = (name) => id("sphere" /* SPHERE */, name);
22886
22924
  var pathId = (pathNumber) => id("path" /* PATH */, String(pathNumber));
22887
22925
  var TREE_SPHERE_IDS = TREE_SPHERE_NAMES.map(
@@ -22919,6 +22957,155 @@ function getTreeLayout(system = "kaabalah") {
22919
22957
  viewBoxUnits
22920
22958
  };
22921
22959
  }
22960
+ function getTreeRenderModel(options = {}) {
22961
+ const system = options.system ?? "kaabalah";
22962
+ const tree = createTree({ system, parts: ["colors"] });
22963
+ const viewBox = normalizeViewBox(options.viewBox);
22964
+ const palette = resolvePalette(options.palette);
22965
+ const highlights = resolveHighlights(options.highlights);
22966
+ const activationMap = resolveActivationMap(options.activations);
22967
+ const layout = getTreeLayout(system);
22968
+ const spherePositions = scaleCoordinates(CANONICAL_SPHERE_PERCENTAGES, viewBox);
22969
+ const viewBoxLayout = buildLayoutMap(tree, spherePositions);
22970
+ const scale = Math.min(
22971
+ viewBox.width / TREE_SVG_DEFAULT_VIEWBOX.width,
22972
+ viewBox.height / TREE_SVG_DEFAULT_VIEWBOX.height
22973
+ );
22974
+ const radius = round(DEFAULT_SPHERE_RADIUS * scale);
22975
+ const pathEdgeWidth = round(DEFAULT_PATH_EDGE_WIDTH * scale);
22976
+ const pathMainWidth = round(DEFAULT_PATH_MAIN_WIDTH * scale);
22977
+ const pathHighlightWidth = round(DEFAULT_PATH_HIGHLIGHT_WIDTH * scale);
22978
+ const sphereHitRadius = round(DEFAULT_SPHERE_HIT_RADIUS * scale);
22979
+ const pathHitStrokeWidth = round(DEFAULT_PATH_HIT_STROKE_WIDTH * scale);
22980
+ const layers = [
22981
+ { name: "background", order: 0, description: "Background rectangle when requested." },
22982
+ ...options.daathLayer === "back" ? [{ name: "spheres-behind-paths", order: 1, description: "Daath behind the paths." }] : [],
22983
+ { name: "paths", order: options.daathLayer === "back" ? 2 : 1, description: "Canonical paths and activation emphasis." },
22984
+ { name: "spheres", order: options.daathLayer === "back" ? 3 : 2, description: "Canonical sphere material and activation halos." },
22985
+ { name: "hit-targets", order: options.daathLayer === "back" ? 4 : 3, description: "Invisible anchors for interaction." }
22986
+ ];
22987
+ const layerOrder = layers.map((layer) => layer.name);
22988
+ const spheres = TREE_SPHERE_NAMES.map((sphereName) => {
22989
+ const sphereIdValue = sphereId(sphereName);
22990
+ const canonicalColor = resolveSphereCanonicalColor({
22991
+ palette,
22992
+ sphereId: sphereIdValue,
22993
+ tree
22994
+ });
22995
+ const point = spherePositions[sphereIdValue];
22996
+ const activation = resolveTargetActivation({
22997
+ activation: activationMap.get(sphereIdValue),
22998
+ canonicalColor
22999
+ });
23000
+ const activeFill = resolveSphereDisplayFill({
23001
+ palette,
23002
+ highlights,
23003
+ sphereId: sphereIdValue,
23004
+ canonicalColor,
23005
+ activation
23006
+ });
23007
+ return {
23008
+ id: sphereIdValue,
23009
+ name: sphereName,
23010
+ slug: sphereName.toLowerCase(),
23011
+ canonicalColor,
23012
+ geometry: {
23013
+ percentages: {
23014
+ center: { ...layout.percentages.spheres[sphereIdValue] },
23015
+ anchor: getPercentageAnchor(layout.percentages.spheres[sphereIdValue])
23016
+ },
23017
+ viewBoxUnits: {
23018
+ center: { ...point },
23019
+ anchor: getViewBoxAnchor(point, viewBox),
23020
+ hitTarget: {
23021
+ kind: "circle",
23022
+ cx: point.x,
23023
+ cy: point.y,
23024
+ r: sphereHitRadius
23025
+ }
23026
+ },
23027
+ radius: {
23028
+ viewBoxUnits: radius
23029
+ }
23030
+ },
23031
+ material: getSphereMaterial({
23032
+ sphereName,
23033
+ preserveSpecialMaterial: shouldPreserveSpecialRenderer({
23034
+ palette,
23035
+ highlights,
23036
+ hasPaintOverride: activation !== null || highlights.sphereFills[sphereIdValue] !== void 0,
23037
+ activation
23038
+ })
23039
+ }),
23040
+ activation,
23041
+ displayFill: activeFill
23042
+ };
23043
+ });
23044
+ const paths = TREE_PATH_IDS.map((pathIdValue) => {
23045
+ const canonicalColor = resolvePathCanonicalColor({
23046
+ palette,
23047
+ tree,
23048
+ pathId: pathIdValue
23049
+ });
23050
+ const path = viewBoxLayout.paths[pathIdValue];
23051
+ const activation = resolveTargetActivation({
23052
+ activation: activationMap.get(pathIdValue),
23053
+ canonicalColor
23054
+ });
23055
+ const displayColor = activation ? resolvePathDisplayColor({
23056
+ canonicalColor,
23057
+ activation
23058
+ }) : resolvePathBaseColor({
23059
+ canonicalColor,
23060
+ highlights,
23061
+ pathId: pathIdValue
23062
+ });
23063
+ return {
23064
+ id: pathIdValue,
23065
+ canonicalColor,
23066
+ geometry: {
23067
+ percentages: {
23068
+ from: { ...layout.percentages.paths[pathIdValue].from },
23069
+ to: { ...layout.percentages.paths[pathIdValue].to },
23070
+ anchor: getPercentagePathAnchor(layout.percentages.paths[pathIdValue])
23071
+ },
23072
+ viewBoxUnits: {
23073
+ from: { ...path.from },
23074
+ to: { ...path.to },
23075
+ anchor: getViewBoxPathAnchor(path, viewBox),
23076
+ hitTarget: {
23077
+ kind: "line",
23078
+ x1: path.from.x,
23079
+ y1: path.from.y,
23080
+ x2: path.to.x,
23081
+ y2: path.to.y,
23082
+ strokeWidth: pathHitStrokeWidth
23083
+ }
23084
+ },
23085
+ widths: {
23086
+ edge: pathEdgeWidth,
23087
+ main: pathMainWidth,
23088
+ highlight: pathHighlightWidth,
23089
+ hitTarget: pathHitStrokeWidth
23090
+ }
23091
+ },
23092
+ activation,
23093
+ displayColor
23094
+ };
23095
+ });
23096
+ return {
23097
+ system,
23098
+ viewBox,
23099
+ scale,
23100
+ layout,
23101
+ layerOrder,
23102
+ layers,
23103
+ spheres,
23104
+ paths,
23105
+ sphereById: Object.fromEntries(spheres.map((entry) => [entry.id, entry])),
23106
+ pathById: Object.fromEntries(paths.map((entry) => [entry.id, entry]))
23107
+ };
23108
+ }
22922
23109
  function generateTreeSvg(options = {}) {
22923
23110
  const system = options.system ?? "kaabalah";
22924
23111
  const daathLayer = options.daathLayer ?? "front";
@@ -22926,6 +23113,7 @@ function generateTreeSvg(options = {}) {
22926
23113
  const viewBox = normalizeViewBox(options.viewBox);
22927
23114
  const palette = resolvePalette(options.palette);
22928
23115
  const highlights = resolveHighlights(options.highlights);
23116
+ const activationMap = resolveActivationMap(options.activations);
22929
23117
  const spherePositions = scaleCoordinates(CANONICAL_SPHERE_PERCENTAGES, viewBox);
22930
23118
  const layout = buildLayoutMap(tree, spherePositions);
22931
23119
  const scale = Math.min(
@@ -23003,6 +23191,14 @@ function generateTreeSvg(options = {}) {
23003
23191
  push(`<g id="spheres-behind-paths">`);
23004
23192
  renderSphere(push, {
23005
23193
  highlights,
23194
+ activation: resolveTargetActivation({
23195
+ activation: activationMap.get(sphereId("Daath")),
23196
+ canonicalColor: resolveSphereCanonicalColor({
23197
+ palette,
23198
+ sphereId: sphereId("Daath"),
23199
+ tree
23200
+ })
23201
+ }),
23006
23202
  tree,
23007
23203
  palette,
23008
23204
  radius,
@@ -23015,12 +23211,24 @@ function generateTreeSvg(options = {}) {
23015
23211
  push(`<g id="paths">`);
23016
23212
  for (const currentPathId of TREE_PATH_IDS) {
23017
23213
  const path = layout.paths[currentPathId];
23018
- const color = resolvePathColor({
23019
- highlights,
23214
+ const canonicalColor = resolvePathCanonicalColor({
23020
23215
  palette,
23021
23216
  tree,
23022
23217
  pathId: currentPathId
23023
23218
  });
23219
+ const baseColor = resolvePathBaseColor({
23220
+ canonicalColor,
23221
+ highlights,
23222
+ pathId: currentPathId
23223
+ });
23224
+ const activation = resolveTargetActivation({
23225
+ activation: activationMap.get(currentPathId),
23226
+ canonicalColor
23227
+ });
23228
+ const color = activation ? resolvePathDisplayColor({
23229
+ canonicalColor,
23230
+ activation
23231
+ }) : baseColor;
23024
23232
  const edgeColor = resolvePathEdgeColor({
23025
23233
  palette,
23026
23234
  pathColor: color
@@ -23028,6 +23236,11 @@ function generateTreeSvg(options = {}) {
23028
23236
  push(
23029
23237
  `<line x1="${path.from.x}" y1="${path.from.y}" x2="${path.to.x}" y2="${path.to.y}" stroke="${escapeAttr(edgeColor)}" stroke-width="${pathEdgeWidth}" stroke-linecap="round"${palette.pathEdgeUseFilter ? ` filter="url(#pathDarken)"` : ""}/>`
23030
23238
  );
23239
+ if (activation?.visible && activation.emphasis > 0) {
23240
+ push(
23241
+ `<line x1="${path.from.x}" y1="${path.from.y}" x2="${path.to.x}" y2="${path.to.y}" stroke="${escapeAttr(color)}" stroke-opacity="${round(0.18 + activation.emphasis * 0.28)}" stroke-width="${round(pathEdgeWidth + activation.emphasis * 10)}" stroke-linecap="round"/>`
23242
+ );
23243
+ }
23031
23244
  push(
23032
23245
  `<line x1="${path.from.x}" y1="${path.from.y}" x2="${path.to.x}" y2="${path.to.y}" stroke="${escapeAttr(color)}" stroke-width="${pathMainWidth}" stroke-linecap="round"/>`
23033
23246
  );
@@ -23039,8 +23252,18 @@ function generateTreeSvg(options = {}) {
23039
23252
  const frontSphereNames = daathLayer === "back" ? TREE_SPHERE_NAMES.filter((name) => name !== "Daath") : TREE_SPHERE_NAMES;
23040
23253
  push(`<g id="spheres">`);
23041
23254
  for (const sphereName of frontSphereNames) {
23255
+ const currentSphereId = sphereId(sphereName);
23256
+ const canonicalColor = resolveSphereCanonicalColor({
23257
+ palette,
23258
+ sphereId: currentSphereId,
23259
+ tree
23260
+ });
23042
23261
  renderSphere(push, {
23043
23262
  highlights,
23263
+ activation: resolveTargetActivation({
23264
+ activation: activationMap.get(currentSphereId),
23265
+ canonicalColor
23266
+ }),
23044
23267
  tree,
23045
23268
  palette,
23046
23269
  radius,
@@ -23069,9 +23292,23 @@ function renderSphere(push, params) {
23069
23292
  sphereId: currentSphereId,
23070
23293
  defaultColors: colorData
23071
23294
  });
23072
- const highlightFill = params.highlights.sphereFills[currentSphereId];
23073
- const activeFill = highlightFill ?? sphereFill;
23074
- const preserveSpecialRenderer = params.palette.specialSphereMode === "preserve" && (highlightFill === void 0 || params.highlights.specialSphereMode === "preserve");
23295
+ const activationFill = params.activation && (params.activation.state === "inactive" || params.activation.colorOverride) ? params.activation.displayColor : void 0;
23296
+ const highlightFill = activationFill ?? params.highlights.sphereFills[currentSphereId];
23297
+ const activeFill = params.activation ? params.activation.displayColor : highlightFill ?? sphereFill;
23298
+ const preserveSpecialRenderer = shouldPreserveSpecialRenderer({
23299
+ palette: params.palette,
23300
+ highlights: params.highlights,
23301
+ hasPaintOverride: highlightFill !== void 0,
23302
+ activation: params.activation
23303
+ });
23304
+ if (params.activation?.visible && params.activation.emphasis > 0) {
23305
+ const haloStrokeWidth = round(3.2 + params.activation.emphasis * 4.8);
23306
+ const haloRadius = round(params.radius + haloStrokeWidth / 2 + 0.7);
23307
+ const haloColor = params.activation.displayColor;
23308
+ push(
23309
+ `<circle cx="${point.x}" cy="${point.y}" r="${haloRadius}" fill="none" stroke="${escapeAttr(haloColor)}" stroke-opacity="${round(0.24 + params.activation.emphasis * 0.28)}" stroke-width="${haloStrokeWidth}"/>`
23310
+ );
23311
+ }
23075
23312
  push(`<g id="sphere-${slug}" clip-path="url(#clip-${slug})">`);
23076
23313
  if (preserveSpecialRenderer) {
23077
23314
  if (params.sphereName === "Kether") {
@@ -23175,6 +23412,160 @@ function normalizeViewBox(viewBox) {
23175
23412
  height: viewBox?.height ?? TREE_SVG_DEFAULT_VIEWBOX.height
23176
23413
  };
23177
23414
  }
23415
+ function resolveActivationMap(activations) {
23416
+ const map = /* @__PURE__ */ new Map();
23417
+ for (const activation of activations ?? []) {
23418
+ map.set(activation.targetId, activation);
23419
+ }
23420
+ return map;
23421
+ }
23422
+ function resolveTargetActivation(params) {
23423
+ if (!params.activation) {
23424
+ return null;
23425
+ }
23426
+ const state = params.activation.state ?? (params.activation.count > 0 ? "active" : "inactive");
23427
+ const strength = clamp01(
23428
+ params.activation.strength ?? (params.activation.total > 0 ? params.activation.count / params.activation.total : 0)
23429
+ );
23430
+ const displayColor = state === "inactive" ? params.activation.color ?? MUTED_TARGET_COLOR : params.activation.color ?? params.canonicalColor;
23431
+ return {
23432
+ state,
23433
+ count: params.activation.count,
23434
+ total: params.activation.total,
23435
+ strength,
23436
+ canonicalColor: params.canonicalColor,
23437
+ displayColor,
23438
+ colorOverride: params.activation.color,
23439
+ mutedColor: MUTED_TARGET_COLOR,
23440
+ visible: state !== "inactive",
23441
+ emphasis: state === "selected" ? clamp01(Math.max(strength, 0.9)) : state === "hovered" ? clamp01(Math.max(strength, 0.72)) : state === "active" ? clamp01(Math.max(strength, 0.56)) : 0
23442
+ };
23443
+ }
23444
+ function resolveSphereCanonicalColor(params) {
23445
+ const override = params.palette.sphereFills[params.sphereId];
23446
+ if (override) {
23447
+ return toPrimaryFill(override, params.palette.defaultSphereFill);
23448
+ }
23449
+ if (params.palette.mode === "monochrome" || params.palette.mode === "custom") {
23450
+ return params.palette.defaultSphereFill;
23451
+ }
23452
+ const treeColor = params.tree.relatedFirst(params.sphereId, "color" /* COLOR */)?.data?.colorHexCodes?.[0];
23453
+ return treeColor ?? params.palette.defaultSphereFill;
23454
+ }
23455
+ function resolvePathCanonicalColor(params) {
23456
+ const override = params.palette.pathColors[params.pathId];
23457
+ if (override) {
23458
+ return override;
23459
+ }
23460
+ if (params.palette.mode === "monochrome" || params.palette.mode === "custom") {
23461
+ return params.palette.defaultPathColor;
23462
+ }
23463
+ const treeColor = params.tree.relatedFirst(params.pathId, "color" /* COLOR */)?.data?.colorHexCodes?.[0];
23464
+ return treeColor ?? params.palette.defaultPathColor;
23465
+ }
23466
+ function resolvePathBaseColor(params) {
23467
+ const highlightOverride = params.highlights.pathColors[params.pathId];
23468
+ if (highlightOverride) {
23469
+ return highlightOverride;
23470
+ }
23471
+ return params.canonicalColor;
23472
+ }
23473
+ function resolveSphereDisplayFill(params) {
23474
+ const highlightOverride = params.highlights.sphereFills[params.sphereId];
23475
+ const fallbackFill = Array.isArray(params.canonicalColor) ? params.canonicalColor[0] ?? params.palette.defaultSphereFill : params.canonicalColor;
23476
+ if (params.activation) {
23477
+ if (params.activation.state !== "inactive" && !params.activation.colorOverride) {
23478
+ return params.canonicalColor ?? fallbackFill;
23479
+ }
23480
+ return params.activation.displayColor;
23481
+ }
23482
+ if (highlightOverride) {
23483
+ return highlightOverride;
23484
+ }
23485
+ return params.canonicalColor ?? fallbackFill;
23486
+ }
23487
+ function resolvePathDisplayColor(params) {
23488
+ if (!params.activation) {
23489
+ return params.canonicalColor;
23490
+ }
23491
+ return params.activation.displayColor;
23492
+ }
23493
+ function getPercentageAnchor(point) {
23494
+ return {
23495
+ x: point.x,
23496
+ y: point.y,
23497
+ vertical: point.y < 18 ? "below" : "above"
23498
+ };
23499
+ }
23500
+ function getViewBoxAnchor(point, viewBox) {
23501
+ return {
23502
+ x: point.x,
23503
+ y: point.y,
23504
+ vertical: point.y - viewBox.minY < viewBox.height * 0.18 ? "below" : "above"
23505
+ };
23506
+ }
23507
+ function getPercentagePathAnchor(path) {
23508
+ const y = round((path.from.y + path.to.y) / 2);
23509
+ return {
23510
+ x: round((path.from.x + path.to.x) / 2),
23511
+ y,
23512
+ vertical: y < 18 ? "below" : "above"
23513
+ };
23514
+ }
23515
+ function getViewBoxPathAnchor(path, viewBox) {
23516
+ const y = round((path.from.y + path.to.y) / 2);
23517
+ return {
23518
+ x: round((path.from.x + path.to.x) / 2),
23519
+ y,
23520
+ vertical: y - viewBox.minY < viewBox.height * 0.18 ? "below" : "above"
23521
+ };
23522
+ }
23523
+ function shouldPreserveSpecialRenderer(params) {
23524
+ return params.palette.specialSphereMode === "preserve" && (params.activation !== null || !params.hasPaintOverride || params.highlights.specialSphereMode === "preserve");
23525
+ }
23526
+ function getSphereMaterial(params) {
23527
+ if (!params.preserveSpecialMaterial) {
23528
+ return {
23529
+ kind: "standard",
23530
+ preserveOnActivation: false
23531
+ };
23532
+ }
23533
+ if (params.sphereName === "Kether") {
23534
+ return {
23535
+ kind: "special",
23536
+ specialSphereName: "Kether",
23537
+ preserveOnActivation: true
23538
+ };
23539
+ }
23540
+ if (params.sphereName === "Chokhmah") {
23541
+ return {
23542
+ kind: "special",
23543
+ specialSphereName: "Chokhmah",
23544
+ preserveOnActivation: true
23545
+ };
23546
+ }
23547
+ if (params.sphereName === "Daath") {
23548
+ return {
23549
+ kind: "special",
23550
+ specialSphereName: "Daath",
23551
+ preserveOnActivation: true
23552
+ };
23553
+ }
23554
+ if (params.sphereName === "Malkuth") {
23555
+ return {
23556
+ kind: "special",
23557
+ specialSphereName: "Malkuth",
23558
+ preserveOnActivation: true
23559
+ };
23560
+ }
23561
+ return {
23562
+ kind: "standard",
23563
+ preserveOnActivation: false
23564
+ };
23565
+ }
23566
+ function clamp01(value) {
23567
+ return Math.max(0, Math.min(1, value));
23568
+ }
23178
23569
  function resolvePalette(palette) {
23179
23570
  if (palette === void 0 || palette === "color") {
23180
23571
  return {
@@ -23228,21 +23619,6 @@ function resolveHighlights(highlights) {
23228
23619
  specialSphereMode: highlights?.specialSphereMode ?? "preserve"
23229
23620
  };
23230
23621
  }
23231
- function resolvePathColor(params) {
23232
- const highlightOverride = params.highlights.pathColors[params.pathId];
23233
- if (highlightOverride) {
23234
- return highlightOverride;
23235
- }
23236
- const override = params.palette.pathColors[params.pathId];
23237
- if (override) {
23238
- return override;
23239
- }
23240
- if (params.palette.mode === "monochrome" || params.palette.mode === "custom") {
23241
- return params.palette.defaultPathColor;
23242
- }
23243
- const treeColor = params.tree.relatedFirst(params.pathId, "color" /* COLOR */)?.data?.colorHexCodes?.[0];
23244
- return treeColor ?? params.palette.defaultPathColor;
23245
- }
23246
23622
  function resolvePathEdgeColor(params) {
23247
23623
  if (params.palette.mode === "color") {
23248
23624
  return params.pathColor;
@@ -23571,6 +23947,20 @@ function serializeLayout(layout, units) {
23571
23947
  }
23572
23948
  return base;
23573
23949
  }
23950
+ function serializeRenderModel(model) {
23951
+ return {
23952
+ system: model.system,
23953
+ viewBox: model.viewBox,
23954
+ scale: model.scale,
23955
+ layerOrder: model.layerOrder,
23956
+ layers: model.layers,
23957
+ layout: model.layout,
23958
+ spheres: model.spheres,
23959
+ paths: model.paths,
23960
+ sphereById: model.sphereById,
23961
+ pathById: model.pathById
23962
+ };
23963
+ }
23574
23964
  function buildViewBox(flags) {
23575
23965
  const width = getFlagNumber(flags, "viewbox-width");
23576
23966
  const height = getFlagNumber(flags, "viewbox-height");
@@ -23593,6 +23983,97 @@ function buildViewBox(flags) {
23593
23983
  height
23594
23984
  };
23595
23985
  }
23986
+ var TREE_SPHERE_ID_SET = new Set(TREE_SPHERE_IDS);
23987
+ var TREE_PATH_ID_SET = new Set(TREE_PATH_IDS);
23988
+ var TREE_TARGET_STATES = /* @__PURE__ */ new Set(["active", "hovered", "selected", "inactive"]);
23989
+ function readJsonFile(pathFlag, flags) {
23990
+ const filePath = (0, import_node_path2.resolve)(pathFlag);
23991
+ let raw;
23992
+ try {
23993
+ raw = (0, import_node_fs2.readFileSync)(filePath, "utf8");
23994
+ } catch (err) {
23995
+ exitWithError(
23996
+ "INVALID_ARGUMENT",
23997
+ `Could not read activations file "${filePath}": ${err instanceof Error ? err.message : String(err)}.`,
23998
+ flags
23999
+ );
24000
+ }
24001
+ try {
24002
+ return JSON.parse(raw);
24003
+ } catch {
24004
+ exitWithError(
24005
+ "INVALID_JSON",
24006
+ `Invalid JSON in activations file "${filePath}".`,
24007
+ flags
24008
+ );
24009
+ }
24010
+ }
24011
+ function validateActivationEntry(entry, index, flags) {
24012
+ const label = `activations[${index}]`;
24013
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
24014
+ exitWithError("INVALID_JSON", `${label} must be a JSON object.`, flags);
24015
+ }
24016
+ const raw = entry;
24017
+ const targetId = raw.targetId;
24018
+ const targetType = raw.targetType;
24019
+ const count = raw.count;
24020
+ const total = raw.total;
24021
+ const strength = raw.strength;
24022
+ const state = raw.state;
24023
+ const color = raw.color;
24024
+ if (typeof targetId !== "string" || !targetId) {
24025
+ exitWithError("INVALID_JSON", `${label}.targetId must be a non-empty string.`, flags);
24026
+ }
24027
+ if (targetType !== "sphere" && targetType !== "path") {
24028
+ exitWithError("INVALID_JSON", `${label}.targetType must be "sphere" or "path".`, flags);
24029
+ }
24030
+ if (targetType === "sphere" && !TREE_SPHERE_ID_SET.has(targetId)) {
24031
+ exitWithError("INVALID_ARGUMENT", `${label}.targetId "${targetId}" is not a known sphere target.`, flags);
24032
+ }
24033
+ if (targetType === "path" && !TREE_PATH_ID_SET.has(targetId)) {
24034
+ exitWithError("INVALID_ARGUMENT", `${label}.targetId "${targetId}" is not a known path target.`, flags);
24035
+ }
24036
+ if (!Number.isFinite(count) || typeof count !== "number" || count < 0) {
24037
+ exitWithError("INVALID_JSON", `${label}.count must be a non-negative number.`, flags);
24038
+ }
24039
+ if (!Number.isFinite(total) || typeof total !== "number" || total < 0) {
24040
+ exitWithError("INVALID_JSON", `${label}.total must be a non-negative number.`, flags);
24041
+ }
24042
+ if (strength !== void 0 && (typeof strength !== "number" || !Number.isFinite(strength) || strength < 0 || strength > 1)) {
24043
+ exitWithError("INVALID_JSON", `${label}.strength must be a number between 0 and 1.`, flags);
24044
+ }
24045
+ if (state !== void 0 && (typeof state !== "string" || !TREE_TARGET_STATES.has(state))) {
24046
+ exitWithError("INVALID_JSON", `${label}.state must be active, hovered, selected, or inactive.`, flags);
24047
+ }
24048
+ if (color !== void 0 && typeof color !== "string") {
24049
+ exitWithError("INVALID_JSON", `${label}.color must be a string when provided.`, flags);
24050
+ }
24051
+ return {
24052
+ targetId,
24053
+ targetType,
24054
+ count,
24055
+ total,
24056
+ ...strength !== void 0 ? { strength } : {},
24057
+ ...state !== void 0 ? { state } : {},
24058
+ ...color !== void 0 ? { color } : {}
24059
+ };
24060
+ }
24061
+ function readActivations(flags) {
24062
+ const activationsPath = getFlagString(flags, "activations");
24063
+ if (!activationsPath) {
24064
+ return void 0;
24065
+ }
24066
+ const parsed = readJsonFile(activationsPath, flags);
24067
+ const payload = Array.isArray(parsed) ? parsed : typeof parsed === "object" && parsed !== null && Array.isArray(parsed.activations) ? parsed.activations : null;
24068
+ if (!payload) {
24069
+ exitWithError(
24070
+ "INVALID_JSON",
24071
+ 'Activations file must be a JSON array or an object with an "activations" array.',
24072
+ flags
24073
+ );
24074
+ }
24075
+ return payload.map((entry, index) => validateActivationEntry(entry, index, flags));
24076
+ }
23596
24077
  function buildSvgOptions(flags) {
23597
24078
  const palette = getFlagString(flags, "palette");
23598
24079
  if (palette && palette !== "color" && palette !== "monochrome") {
@@ -23617,7 +24098,33 @@ function buildSvgOptions(flags) {
23617
24098
  background: getFlagString(flags, "background") ?? void 0,
23618
24099
  palette: palette ?? void 0,
23619
24100
  viewBox: buildViewBox(flags),
23620
- daathLayer: daathLayer ?? void 0
24101
+ daathLayer: daathLayer ?? void 0,
24102
+ activations: readActivations(flags)
24103
+ };
24104
+ }
24105
+ function buildRenderModelOptions(flags) {
24106
+ const palette = getFlagString(flags, "palette");
24107
+ if (palette && palette !== "color" && palette !== "monochrome") {
24108
+ exitWithError(
24109
+ "INVALID_ARGUMENT",
24110
+ `Unknown SVG palette "${palette}". Expected "color" or "monochrome".`,
24111
+ flags
24112
+ );
24113
+ }
24114
+ const daathLayer = getFlagString(flags, "daath-layer");
24115
+ if (daathLayer && daathLayer !== "front" && daathLayer !== "back") {
24116
+ exitWithError(
24117
+ "INVALID_ARGUMENT",
24118
+ `Unknown Daath layer "${daathLayer}". Expected "front" or "back".`,
24119
+ flags
24120
+ );
24121
+ }
24122
+ return {
24123
+ system: resolveSystem(flags),
24124
+ palette: palette ?? void 0,
24125
+ viewBox: buildViewBox(flags),
24126
+ daathLayer: daathLayer ?? void 0,
24127
+ activations: readActivations(flags)
23621
24128
  };
23622
24129
  }
23623
24130
  function renderAsciiTree(layout, columns, rows) {
@@ -23900,6 +24407,29 @@ Tree search
23900
24407
  console.log();
23901
24408
  }
23902
24409
  function cmdTreeLayout(flags) {
24410
+ if (getFlagBool(flags, "render-model")) {
24411
+ const modelOptions = buildRenderModelOptions(flags);
24412
+ const model = getTreeRenderModel(modelOptions);
24413
+ const payload2 = serializeRenderModel(model);
24414
+ if (isJsonMode(flags)) {
24415
+ outputJson(payload2, flags);
24416
+ return;
24417
+ }
24418
+ console.log(`
24419
+ Tree render model (${model.system})
24420
+ `);
24421
+ console.log(
24422
+ ` ViewBox: ${model.viewBox.minX} ${model.viewBox.minY} ${model.viewBox.width} ${model.viewBox.height}`
24423
+ );
24424
+ console.log(` Layers: ${model.layerOrder.join(" -> ")}`);
24425
+ console.log(` Spheres: ${model.spheres.length}`);
24426
+ console.log(` Paths: ${model.paths.length}`);
24427
+ console.log(
24428
+ ` Activations: ${model.spheres.filter((sphere) => sphere.activation).length + model.paths.filter((path) => path.activation).length}
24429
+ `
24430
+ );
24431
+ return;
24432
+ }
23903
24433
  const system = resolveSystem(flags);
23904
24434
  const units = resolveLayoutUnits(flags);
23905
24435
  const layout = getTreeLayout(system);
@@ -23946,7 +24476,8 @@ function cmdTreeSvg(flags) {
23946
24476
  background: svgOptions.background ?? null,
23947
24477
  palette: svgOptions.palette ?? "color",
23948
24478
  viewBox: svgOptions.viewBox ?? null,
23949
- daathLayer: svgOptions.daathLayer ?? "front"
24479
+ daathLayer: svgOptions.daathLayer ?? "front",
24480
+ activationCount: svgOptions.activations?.length ?? 0
23950
24481
  }
23951
24482
  },
23952
24483
  flags
@@ -23960,7 +24491,8 @@ function cmdTreeSvg(flags) {
23960
24491
  outputJson(
23961
24492
  {
23962
24493
  system,
23963
- svg
24494
+ svg,
24495
+ activationCount: svgOptions.activations?.length ?? 0
23964
24496
  },
23965
24497
  flags
23966
24498
  );