kaabalah 6.6.3 → 6.6.4

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
@@ -9857,15 +9857,14 @@ function labelBoundsCircleOverflow(center, bounds, maxRadius) {
9857
9857
  );
9858
9858
  return farthestCorner - maxRadius;
9859
9859
  }
9860
- function hasLabelBoundsCollision(bounds, placed) {
9861
- return placed.some((other) => labelBoundsOverlap(bounds, other));
9862
- }
9863
- function labelBoundsOverlap(a, b) {
9864
- return !(a.x + a.width <= b.x || b.x + b.width <= a.x || a.y + a.height <= b.y || b.y + b.height <= a.y);
9865
- }
9866
9860
  function formatLabelBounds(bounds) {
9867
9861
  return `${fmt(bounds.x)} ${fmt(bounds.y)} ${fmt(bounds.width)} ${fmt(bounds.height)}`;
9868
9862
  }
9863
+ function projectedLabelWidthAlongTangent(angleRad, bounds) {
9864
+ const tangentX = -Math.sin(angleRad);
9865
+ const tangentY = Math.cos(angleRad);
9866
+ return Math.abs(tangentX) * bounds.width + Math.abs(tangentY) * bounds.height;
9867
+ }
9869
9868
  function resolvePointGlyph(name) {
9870
9869
  const key = name.trim().toLocaleLowerCase().replace(/[_-]+/g, " ").replace(/\s+/g, " ");
9871
9870
  const resolved = POINT_GLYPH_ALIASES[key] ?? key;
@@ -9987,108 +9986,109 @@ function buildPointLayer(params) {
9987
9986
  ) : requestedRadius;
9988
9987
  const isExternalLayer = radius > rings.houses.r2 + scale;
9989
9988
  const tickLength = Math.min(14 * scale, thickness * 0.34);
9990
- const glyphMinSepDeg = glyphFontSize * 0.9 / Math.max(radius, 1) * (180 / Math.PI);
9991
- const collisionThresholdDegrees = clamp(
9992
- layer.collisionThresholdDegrees ?? Math.max(2, Math.min(8, glyphMinSepDeg)),
9993
- 0,
9994
- 30
9995
- );
9996
- const tangentStep = glyphFontSize * (isExternalLayer ? 0.68 : 0.74);
9997
9989
  const collisionPadding = Math.max(2 * scale, 1.5);
9998
9990
  const zodiacKeepOutGap = Math.max(5 * scale, 4);
9999
9991
  const labelMaxRadius = isExternalLayer ? Number.POSITIVE_INFINITY : rings.zodiac.r1 - zodiacKeepOutGap;
10000
9992
  const seeds = getPointSeeds(layer, excludedBodies);
10001
- const clusters = clusterPointSeeds(seeds, collisionThresholdDegrees);
10002
9993
  const color = layer.color ?? palette.planetGlyph;
10003
9994
  const tickColor = layer.tickColor ?? color;
10004
- const placedLabelBounds = [];
10005
- const points = clusters.flatMap((cluster) => {
10006
- const clusterMidpoint = (cluster.length - 1) / 2;
10007
- return cluster.map((seed, index) => {
10008
- const tickAngle = angleOf(seed.longitude);
10009
- const pointGlyphFontSize = seed.kind === "vertex" ? glyphFontSize * 0.82 : glyphFontSize;
10010
- const rawGlyphRadius = radius;
10011
- const glyphRadius = isExternalLayer ? rawGlyphRadius : clamp(
10012
- rawGlyphRadius,
10013
- rings.aspects.r2 + pointGlyphFontSize * 0.65,
10014
- labelMaxRadius - pointGlyphFontSize * 0.5
10015
- );
10016
- const tickLine = isExternalLayer ? lineFromPolar(
10017
- center,
10018
- rings.houses.r2 + 2 * scale,
10019
- Math.max(rings.houses.r2 + 6 * scale, radius - glyphFontSize * 0.44),
10020
- tickAngle
10021
- ) : lineFromPolar(center, ring.r2 - tickLength, ring.r2, tickAngle);
10022
- const leaderStartRadius = isExternalLayer ? Math.max(rings.houses.r2 + 6 * scale, radius - glyphFontSize * 0.44) : radius;
10023
- const leaderStart = polarToXY(center.x, center.y, leaderStartRadius, tickAngle);
10024
- let tangentOffset = cluster.length > 1 ? (index - clusterMidpoint) * tangentStep : 0;
10025
- const nudgeDirection = index - clusterMidpoint >= 0 ? 1 : -1;
10026
- const makePoint = () => {
10027
- const labelAngle = tickAngle + tangentOffset / Math.max(glyphRadius, 1);
10028
- let glyphPosition = polarToXY(center.x, center.y, glyphRadius, labelAngle);
10029
- const labelDisplaced = Math.abs(tangentOffset) > 0.01;
10030
- let point2 = {
10031
- layerId: layer.id,
10032
- key: seed.key,
10033
- name: seed.name,
10034
- kind: seed.kind,
10035
- glyph: seed.glyph,
10036
- glyphKey: seed.glyphKey,
10037
- longitude: normalizeAngle2(seed.longitude),
10038
- displayLongitude: normalizeAngle2(seed.longitude),
10039
- zodiacPosition: seed.zodiacPosition,
10040
- tickLine,
10041
- labelAngle,
10042
- leaderLine: labelDisplaced ? {
10043
- x1: leaderStart.x,
10044
- y1: leaderStart.y,
10045
- x2: glyphPosition.x,
10046
- y2: glyphPosition.y
10047
- } : void 0,
10048
- glyphPosition,
10049
- glyphFontSize: pointGlyphFontSize,
10050
- retrograde: seed.retrograde,
10051
- color,
10052
- tickColor
10053
- };
10054
- const layout = getPointLabelLayout(point2, scale);
10055
- const constrainedLabel = constrainLabelInsideCircle({
10056
- center,
10057
- position: glyphPosition,
10058
- layout,
10059
- padding: collisionPadding,
10060
- maxRadius: labelMaxRadius
10061
- });
10062
- if (constrainedLabel.moved) {
10063
- glyphPosition = constrainedLabel.position;
10064
- point2 = {
10065
- ...point2,
10066
- glyphPosition,
10067
- leaderLine: {
10068
- x1: leaderStart.x,
10069
- y1: leaderStart.y,
10070
- x2: glyphPosition.x,
10071
- y2: glyphPosition.y
10072
- }
10073
- };
9995
+ const pointIntents = seeds.map((seed) => {
9996
+ const tickAngle = angleOf(seed.longitude);
9997
+ const pointGlyphFontSize = seed.kind === "vertex" ? glyphFontSize * 0.82 : glyphFontSize;
9998
+ const rawGlyphRadius = radius;
9999
+ const glyphRadius = isExternalLayer ? rawGlyphRadius : clamp(
10000
+ rawGlyphRadius,
10001
+ rings.aspects.r2 + pointGlyphFontSize * 0.65,
10002
+ labelMaxRadius - pointGlyphFontSize * 0.5
10003
+ );
10004
+ const tickLine = isExternalLayer ? lineFromPolar(
10005
+ center,
10006
+ rings.houses.r2 + 2 * scale,
10007
+ Math.max(rings.houses.r2 + 6 * scale, radius - glyphFontSize * 0.44),
10008
+ tickAngle
10009
+ ) : lineFromPolar(center, ring.r2 - tickLength, ring.r2, tickAngle);
10010
+ const leaderStartRadius = isExternalLayer ? Math.max(rings.houses.r2 + 6 * scale, radius - glyphFontSize * 0.44) : radius;
10011
+ const leaderStart = polarToXY(center.x, center.y, leaderStartRadius, tickAngle);
10012
+ const idealPosition = polarToXY(center.x, center.y, glyphRadius, tickAngle);
10013
+ const point = makeAstroWheelPoint({
10014
+ layer,
10015
+ seed,
10016
+ tickLine,
10017
+ leaderStart,
10018
+ tickAngle,
10019
+ labelAngle: tickAngle,
10020
+ glyphPosition: idealPosition,
10021
+ glyphFontSize: pointGlyphFontSize,
10022
+ color,
10023
+ tickColor
10024
+ });
10025
+ const layout = getPointLabelLayout(point, scale);
10026
+ const labelBounds = labelBoundsFor(idealPosition, layout, collisionPadding);
10027
+ const labelTangentDemandPx = projectedLabelWidthAlongTangent(tickAngle, labelBounds);
10028
+ const configuredTangentDemandPx = layer.collisionThresholdDegrees ? deg2rad(clamp(layer.collisionThresholdDegrees, 0, 30)) * glyphRadius : 0;
10029
+ const tangentDemandPx = Math.max(labelTangentDemandPx, configuredTangentDemandPx);
10030
+ return {
10031
+ seed,
10032
+ tickAngle,
10033
+ tickLine,
10034
+ leaderStart,
10035
+ glyphRadius,
10036
+ pointGlyphFontSize,
10037
+ tangentDemandPx
10038
+ };
10039
+ });
10040
+ const solvedLabels = solveCircularLabelAngles(
10041
+ pointIntents.map((intent) => ({
10042
+ item: intent,
10043
+ idealAngle: intent.tickAngle,
10044
+ radius: intent.glyphRadius,
10045
+ tangentDemandPx: intent.tangentDemandPx
10046
+ })),
10047
+ collisionPadding
10048
+ );
10049
+ const visualAngleByKey = Object.fromEntries(
10050
+ solvedLabels.map(({ item, visualAngle }) => [item.seed.key, visualAngle])
10051
+ );
10052
+ const points = pointIntents.map((intent) => {
10053
+ const visualAngle = visualAngleByKey[intent.seed.key] ?? intent.tickAngle;
10054
+ let glyphPosition = polarToXY(center.x, center.y, intent.glyphRadius, visualAngle);
10055
+ let point = makeAstroWheelPoint({
10056
+ layer,
10057
+ seed: intent.seed,
10058
+ tickLine: intent.tickLine,
10059
+ leaderStart: intent.leaderStart,
10060
+ tickAngle: intent.tickAngle,
10061
+ labelAngle: visualAngle,
10062
+ glyphPosition,
10063
+ glyphFontSize: intent.pointGlyphFontSize,
10064
+ color,
10065
+ tickColor
10066
+ });
10067
+ const layout = getPointLabelLayout(point, scale);
10068
+ const constrainedLabel = constrainLabelInsideCircle({
10069
+ center,
10070
+ position: glyphPosition,
10071
+ layout,
10072
+ padding: collisionPadding,
10073
+ maxRadius: labelMaxRadius
10074
+ });
10075
+ if (constrainedLabel.moved) {
10076
+ glyphPosition = constrainedLabel.position;
10077
+ point = {
10078
+ ...point,
10079
+ glyphPosition,
10080
+ leaderLine: {
10081
+ x1: intent.leaderStart.x,
10082
+ y1: intent.leaderStart.y,
10083
+ x2: glyphPosition.x,
10084
+ y2: glyphPosition.y
10074
10085
  }
10075
- return {
10076
- ...point2,
10077
- labelBounds: constrainedLabel.bounds
10078
- };
10079
10086
  };
10080
- let point = makePoint();
10081
- let attempts = 0;
10082
- while (point.labelBounds && hasLabelBoundsCollision(point.labelBounds, placedLabelBounds) && attempts < 16) {
10083
- tangentOffset += nudgeDirection * (tangentStep * 0.45 + collisionPadding);
10084
- point = makePoint();
10085
- attempts += 1;
10086
- }
10087
- if (point.labelBounds) {
10088
- placedLabelBounds.push(point.labelBounds);
10089
- }
10090
- return point;
10091
- });
10087
+ }
10088
+ return {
10089
+ ...point,
10090
+ labelBounds: constrainedLabel.bounds
10091
+ };
10092
10092
  });
10093
10093
  return {
10094
10094
  id: layer.id,
@@ -10099,6 +10099,45 @@ function buildPointLayer(params) {
10099
10099
  points
10100
10100
  };
10101
10101
  }
10102
+ function makeAstroWheelPoint(params) {
10103
+ const {
10104
+ layer,
10105
+ seed,
10106
+ tickLine,
10107
+ leaderStart,
10108
+ tickAngle,
10109
+ labelAngle,
10110
+ glyphPosition,
10111
+ glyphFontSize,
10112
+ color,
10113
+ tickColor
10114
+ } = params;
10115
+ const labelDisplaced = circularAngleDistance(labelAngle, tickAngle) > 1e-4;
10116
+ return {
10117
+ layerId: layer.id,
10118
+ key: seed.key,
10119
+ name: seed.name,
10120
+ kind: seed.kind,
10121
+ glyph: seed.glyph,
10122
+ glyphKey: seed.glyphKey,
10123
+ longitude: normalizeAngle2(seed.longitude),
10124
+ displayLongitude: normalizeAngle2(seed.longitude),
10125
+ zodiacPosition: seed.zodiacPosition,
10126
+ tickLine,
10127
+ labelAngle,
10128
+ leaderLine: labelDisplaced ? {
10129
+ x1: leaderStart.x,
10130
+ y1: leaderStart.y,
10131
+ x2: glyphPosition.x,
10132
+ y2: glyphPosition.y
10133
+ } : void 0,
10134
+ glyphPosition,
10135
+ glyphFontSize,
10136
+ retrograde: seed.retrograde,
10137
+ color,
10138
+ tickColor
10139
+ };
10140
+ }
10102
10141
  function buildAspectLayer(params) {
10103
10142
  const { layer, chart, pointByKey, center, angleOf, rings, palette, excludedBodies } = params;
10104
10143
  const sourceEdges = getSourceAspectEdges(chart, {
@@ -10221,37 +10260,81 @@ function pointSeed(point, layerId) {
10221
10260
  zodiacPosition: point.zodiacPosition
10222
10261
  };
10223
10262
  }
10224
- function clusterPointSeeds(seeds, minSepDeg) {
10225
- if (seeds.length === 0) {
10263
+ function solveCircularLabelAngles(items, paddingPx) {
10264
+ if (items.length === 0) {
10226
10265
  return [];
10227
10266
  }
10228
- const clusters = [];
10229
- let current = [];
10230
- for (const seed of seeds) {
10231
- if (current.length === 0) {
10232
- current.push(seed);
10233
- continue;
10267
+ const normalized = items.map((item) => ({
10268
+ ...item,
10269
+ idealAngle: clampRad(item.idealAngle)
10270
+ })).sort((a, b) => a.idealAngle - b.idealAngle);
10271
+ if (normalized.length === 1) {
10272
+ return [{ ...normalized[0], visualAngle: normalized[0].idealAngle }];
10273
+ }
10274
+ let largestGap = -Infinity;
10275
+ let seamIndex = 0;
10276
+ for (let i = 0; i < normalized.length; i++) {
10277
+ const current = normalized[i];
10278
+ const next = normalized[(i + 1) % normalized.length];
10279
+ const nextAngle = i === normalized.length - 1 ? next.idealAngle + TAU : next.idealAngle;
10280
+ const gap = nextAngle - current.idealAngle;
10281
+ if (gap > largestGap) {
10282
+ largestGap = gap;
10283
+ seamIndex = (i + 1) % normalized.length;
10234
10284
  }
10235
- const previous = current[current.length - 1];
10236
- const delta = clamp360(seed.longitude - previous.longitude);
10237
- if (delta <= minSepDeg) {
10238
- current.push(seed);
10239
- } else {
10240
- clusters.push(current);
10241
- current = [seed];
10285
+ }
10286
+ const linear = [
10287
+ ...normalized.slice(seamIndex),
10288
+ ...normalized.slice(0, seamIndex)
10289
+ ].map((item, index) => {
10290
+ const wrapped = seamIndex > 0 && index >= normalized.length - seamIndex;
10291
+ return {
10292
+ ...item,
10293
+ idealAngle: item.idealAngle + (wrapped ? TAU : 0)
10294
+ };
10295
+ });
10296
+ for (let i = 1; i < linear.length; i++) {
10297
+ while (linear[i].idealAngle <= linear[i - 1].idealAngle) {
10298
+ linear[i] = {
10299
+ ...linear[i],
10300
+ idealAngle: linear[i].idealAngle + TAU
10301
+ };
10302
+ }
10303
+ }
10304
+ const solved = linear.map((item) => ({
10305
+ ...item,
10306
+ visualAngle: item.idealAngle
10307
+ }));
10308
+ for (let i = 1; i < solved.length; i++) {
10309
+ const previous = solved[i - 1];
10310
+ const current = solved[i];
10311
+ const minGap = labelAngularHalfDemand(previous, paddingPx) + labelAngularHalfDemand(current, paddingPx);
10312
+ if (current.visualAngle < previous.visualAngle + minGap) {
10313
+ current.visualAngle = previous.visualAngle + minGap;
10242
10314
  }
10243
10315
  }
10244
- clusters.push(current);
10245
- if (clusters.length > 1) {
10246
- const first = clusters[0];
10247
- const last = clusters[clusters.length - 1];
10248
- const wrapDelta = clamp360(first[0].longitude - last[last.length - 1].longitude);
10249
- if (wrapDelta <= minSepDeg) {
10250
- clusters[0] = [...last, ...first];
10251
- clusters.pop();
10316
+ for (let i = solved.length - 2; i >= 0; i--) {
10317
+ const current = solved[i];
10318
+ const next = solved[i + 1];
10319
+ const minGap = labelAngularHalfDemand(current, paddingPx) + labelAngularHalfDemand(next, paddingPx);
10320
+ if (current.visualAngle > next.visualAngle - minGap) {
10321
+ current.visualAngle = next.visualAngle - minGap;
10252
10322
  }
10253
10323
  }
10254
- return clusters;
10324
+ return solved.map((item) => ({
10325
+ ...item,
10326
+ visualAngle: clampRad(item.visualAngle)
10327
+ }));
10328
+ }
10329
+ function labelAngularHalfDemand(item, paddingPx) {
10330
+ return (item.tangentDemandPx / 2 + paddingPx) / Math.max(item.radius, 1);
10331
+ }
10332
+ function clampRad(value) {
10333
+ return (value % TAU + TAU) % TAU;
10334
+ }
10335
+ function circularAngleDistance(a, b) {
10336
+ const delta = Math.abs(clampRad(a) - clampRad(b));
10337
+ return Math.min(delta, TAU - delta);
10255
10338
  }
10256
10339
  function getSourceAspectEdges(chart, options) {
10257
10340
  if (options.edges) {
@@ -19639,7 +19722,7 @@ var import_config3 = require("dotenv/config");
19639
19722
  // package.json
19640
19723
  var package_default = {
19641
19724
  name: "kaabalah",
19642
- version: "6.6.3",
19725
+ version: "6.6.4",
19643
19726
  description: "The de-facto library for any esoteric calculations and tooling",
19644
19727
  engines: {
19645
19728
  node: ">=18.18.0"