@roxyapi/ui 0.31.0 → 0.31.1

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.
@@ -21,12 +21,16 @@ interface CenterGeometry {
21
21
  label: string;
22
22
  color: CenterColor;
23
23
  points: Point[];
24
+ /** Where the centre name sits, when the shape's middle is taken by a gate number. Defaults to the centroid. */
25
+ labelAt?: Point;
24
26
  }
25
27
  /** Traditional center color group: gold for Head and G, green for Ajna, red for the Heart and Sacral motors, brown for the rest. A defined center is filled with it; an open one takes the card surface so the wiring passes behind. */
26
28
  export type CenterColor = 'gold' | 'green' | 'red' | 'brown';
27
29
  /** Gate circle and number size, in grid units. Bounded by the closest pair on the chart (Throat 12 and 45, 2.3 apart) and by fitting two digits inside the circle. */
28
30
  export declare const GATE_RADIUS: number;
29
31
  export declare const GATE_FONT_SIZE: number;
32
+ /** The centre name behind the numbers. Smaller than a gate number so it reads as ground rather than as another value. */
33
+ export declare const CENTER_NAME_FONT_SIZE: number;
30
34
  /**
31
35
  * The viewBox-space gate anchors ({@link GATE_POINTS}) and the gate to center
32
36
  * index ({@link GATE_CENTER}). Exported so the geometry tests can assert the
@@ -1 +1 @@
1
- {"version":3,"file":"bodygraph-render.d.ts","sourceRoot":"","sources":["../../src/utils/bodygraph-render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAG1C;;;;;GAKG;AAEH,MAAM,MAAM,iBAAiB,GAC1B,MAAM,GACN,MAAM,GACN,QAAQ,GACR,GAAG,GACH,OAAO,GACP,QAAQ,GACR,cAAc,GACd,QAAQ,GACR,MAAM,CAAC;AAEV,UAAU,KAAK;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACV;AAED,oLAAoL;AACpL,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;CACf;AAED,8HAA8H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AAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACvC,6JAA6J;IAC7J,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC9C,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,qRAAqR;IACrR,WAAW,CAAC,EAAE,WAAW,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IACrD,uJAAuJ;IACvJ,UAAU,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C;AAED,eAAO,MAAM,iBAAiB,gBAA4B,CAAC;AAE3D;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,oBAAoB,GACzB,cAAc,CAWhB"}
@@ -1 +1 @@
1
- {"version":3,"file":"bodygraph-styles.d.ts","sourceRoot":"","sources":["../../src/utils/bodygraph-styles.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,yBA6JhC,CAAC"}
1
+ {"version":3,"file":"bodygraph-styles.d.ts","sourceRoot":"","sources":["../../src/utils/bodygraph-styles.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,yBA6KhC,CAAC"}
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const ROXY_UI_VERSION = "0.31.0";
1
+ export declare const ROXY_UI_VERSION = "0.31.1";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roxyapi/ui",
3
- "version": "0.31.0",
3
+ "version": "0.31.1",
4
4
  "description": "Web components for the RoxyAPI catalog. Drop-in charts, tables, cards, forms for astrology, tarot, numerology, biorhythm, I Ching, crystals, dreams, angel numbers, and more. One key, beautiful in 30 minutes.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -36,6 +36,8 @@ interface CenterGeometry {
36
36
  label: string;
37
37
  color: CenterColor;
38
38
  points: Point[];
39
+ /** Where the centre name sits, when the shape's middle is taken by a gate number. Defaults to the centroid. */
40
+ labelAt?: Point;
39
41
  }
40
42
 
41
43
  /** Traditional center color group: gold for Head and G, green for Ajna, red for the Heart and Sacral motors, brown for the rest. A defined center is filled with it; an open one takes the card surface so the wiring passes behind. */
@@ -65,6 +67,8 @@ const mirrorX = (x: number): number => 2 * AXIS - x;
65
67
  /** Gate circle and number size, in grid units. Bounded by the closest pair on the chart (Throat 12 and 45, 2.3 apart) and by fitting two digits inside the circle. */
66
68
  export const GATE_RADIUS = 1.02 * UNIT;
67
69
  export const GATE_FONT_SIZE = 1.35 * UNIT;
70
+ /** The centre name behind the numbers. Smaller than a gate number so it reads as ground rather than as another value. */
71
+ export const CENTER_NAME_FONT_SIZE = 1.15 * UNIT;
68
72
 
69
73
  /** The three x offsets from {@link AXIS} a central-column gate sits on: the inner triples, the outer column of the square centers, and the G's wider waist pair. Named so they cannot drift apart one edit at a time. */
70
74
  const COL = 2.87;
@@ -478,14 +482,78 @@ function renderCenters(
478
482
  names: ReadonlyMap<BodygraphCenterId, string> | undefined,
479
483
  stateWords: { defined: string; open: string },
480
484
  ): TemplateResult[] {
481
- return CENTER_GEOMETRY.map((c) => {
485
+ return CENTER_GEOMETRY.flatMap((c) => {
482
486
  const isDefined = defined.has(c.id);
483
487
  const cls = `bg-center bg-${c.color}${isDefined ? ' defined' : ''}`;
484
488
  const label = names?.get(c.id) || c.label;
485
- return svg`<polygon class=${cls} points=${polygonPoints(c.points)}><title>${label}: ${isDefined ? stateWords.defined : stateWords.open}</title></polygon>`;
489
+ const at = c.labelAt ?? centroid(c.points);
490
+ return [
491
+ svg`<polygon class=${cls} points=${polygonPoints(c.points)}><title>${label}: ${isDefined ? stateWords.defined : stateWords.open}</title></polygon>`,
492
+ // Drawn with the shapes, so the gate numbers paint over it. Hidden from
493
+ // the accessibility tree because the polygon `<title>` above already
494
+ // names this centre, and announcing it twice is worse than once.
495
+ renderCenterName(label, at, isDefined, c.points),
496
+ ];
486
497
  });
487
498
  }
488
499
 
500
+ /**
501
+ * The centre name as ground behind the gate numbers.
502
+ *
503
+ * @remarks
504
+ * A multi-word name stacks one word per line rather than running past the shape: the two side triangles taper to a point, so `Solar Plexus` on one line overruns its own outline while `SOLAR` over `PLEXUS` sits inside it. Splitting on whitespace is one rule for every language rather than a width measured per label, and a name that is one long word in some language simply stays one line.
505
+ */
506
+ function renderCenterName(
507
+ label: string,
508
+ at: Point,
509
+ isDefined: boolean,
510
+ points: readonly Point[],
511
+ ): TemplateResult {
512
+ const words = label.split(/\s+/).filter(Boolean);
513
+ const longest = words.reduce((n, w) => Math.max(n, w.length), 0);
514
+ // Shrink to the room the shape actually has at this height rather than
515
+ // trusting one size to fit every name: the side centres taper to a point, and
516
+ // a translated name is a different length in every language.
517
+ const room = widthAt(points, at.y) * 0.86;
518
+ const size = Math.min(
519
+ CENTER_NAME_FONT_SIZE,
520
+ room / Math.max(1, longest * UPPERCASE_EM),
521
+ );
522
+ const step = size * 1.05;
523
+ const top = at.y - (step * (words.length - 1)) / 2;
524
+ return svg`<text class="bg-center-name ${isDefined ? 'defined' : ''}" style=${`font-size:${size}px`} x=${at.x} y=${at.y} text-anchor="middle" dominant-baseline="central" aria-hidden="true">${words.map(
525
+ (w, i) => svg`<tspan x=${at.x} y=${top + i * step}>${w}</tspan>`,
526
+ )}</text>`;
527
+ }
528
+
529
+ /** Advance width of one uppercase character at the label weight, as a fraction of the font size. Approximate on purpose: it only has to keep a name inside its own outline, and it is applied with room to spare. */
530
+ const UPPERCASE_EM = 0.66;
531
+
532
+ /** Horizontal span of a convex polygon at height `y`: how much room a line of text has there. */
533
+ function widthAt(points: readonly Point[], y: number): number {
534
+ const xs: number[] = [];
535
+ for (let i = 0; i < points.length; i++) {
536
+ const a = points[i] as Point;
537
+ const b = points[(i + 1) % points.length] as Point;
538
+ if (a.y === b.y) continue;
539
+ const lo = Math.min(a.y, b.y);
540
+ const hi = Math.max(a.y, b.y);
541
+ if (y < lo || y > hi) continue;
542
+ xs.push(a.x + ((y - a.y) / (b.y - a.y)) * (b.x - a.x));
543
+ }
544
+ if (xs.length < 2) return 0;
545
+ return Math.max(...xs) - Math.min(...xs);
546
+ }
547
+
548
+ /** Average of a shape's vertices: the visual middle of every centre this chart draws, all of which are convex. */
549
+ function centroid(points: readonly Point[]): Point {
550
+ const n = points.length || 1;
551
+ return {
552
+ x: points.reduce((t, p) => t + p.x, 0) / n,
553
+ y: points.reduce((t, p) => t + p.y, 0) / n,
554
+ };
555
+ }
556
+
489
557
  /** A half-disc starting at the top of the circle and sweeping to the bottom. `sweep` 1 is the right half. */
490
558
  function halfDisc(p: Point, sweep: 0 | 1): string {
491
559
  return `M ${p.x} ${p.y - GATE_RADIUS} A ${GATE_RADIUS} ${GATE_RADIUS} 0 0 ${sweep} ${p.x} ${p.y + GATE_RADIUS} Z`;
@@ -1,5 +1,5 @@
1
1
  import { css } from 'lit';
2
- import { GATE_FONT_SIZE } from './bodygraph-render.js';
2
+ import { CENTER_NAME_FONT_SIZE, GATE_FONT_SIZE } from './bodygraph-render.js';
3
3
 
4
4
  /**
5
5
  * The stylesheet for anything `renderBodygraphSvg` draws, so a second chart on the same geometry cannot fork the first one's appearance.
@@ -106,6 +106,22 @@ export const bodygraphChartStyles = css`
106
106
  .bg-gate-dot.on {
107
107
  stroke: none;
108
108
  }
109
+ /* The centre name, drawn as ground behind the gate numbers. Muted enough to
110
+ * sit under them and never compete, and it takes the knocked-out ink on a
111
+ * filled centre so it stays readable on the saturated fills. */
112
+ .bg-center-name {
113
+ fill: var(--roxy-muted, #71717a);
114
+ opacity: 0.5;
115
+ font-size: ${CENTER_NAME_FONT_SIZE}px;
116
+ font-weight: 600;
117
+ letter-spacing: 0.08em;
118
+ text-transform: uppercase;
119
+ pointer-events: none;
120
+ }
121
+ .bg-center-name.defined {
122
+ fill: var(--roxy-surface, #fff);
123
+ opacity: 0.62;
124
+ }
109
125
  .bg-gate {
110
126
  fill: var(--roxy-muted, #71717a);
111
127
  font-size: ${GATE_FONT_SIZE}px;
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/sync-version.ts. Do not edit.
2
- export const ROXY_UI_VERSION = '0.31.0';
2
+ export const ROXY_UI_VERSION = '0.31.1';