kaabalah 6.5.0 → 6.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.
@@ -1,939 +0,0 @@
1
- import { id, createTree } from './chunk-EFZUZI22.mjs';
2
-
3
- // src/visual/tree-svg.ts
4
- var TREE_SVG_DEFAULT_VIEWBOX = {
5
- minX: 0,
6
- minY: 0,
7
- width: 286,
8
- height: 561
9
- };
10
- var TREE_SPHERE_NAMES = [
11
- "Kether",
12
- "Chokhmah",
13
- "Binah",
14
- "Daath",
15
- "Chesed",
16
- "Geburah",
17
- "Tiphareth",
18
- "Netzach",
19
- "Hod",
20
- "Yesod",
21
- "Malkuth"
22
- ];
23
- var TREE_PATH_NUMBERS = Array.from({ length: 22 }, (_, index) => index + 1);
24
- var CANONICAL_X_PERCENTAGES = { left: 13.25, mid: 49.94, right: 86.66 };
25
- var CANONICAL_ROW_Y_PERCENTAGES = [
26
- 6.83,
27
- 17.68,
28
- 28.42,
29
- 39.26,
30
- 50.06,
31
- 60.85,
32
- 71.68,
33
- 93.2
34
- ];
35
- var DEFAULT_SPHERE_RADIUS = 30;
36
- var DEFAULT_PATH_EDGE_WIDTH = 26;
37
- var DEFAULT_PATH_MAIN_WIDTH = 22;
38
- var DEFAULT_PATH_HIGHLIGHT_WIDTH = 8;
39
- var DEFAULT_SPHERE_HIT_RADIUS = DEFAULT_SPHERE_RADIUS + 8;
40
- var DEFAULT_PATH_HIT_STROKE_WIDTH = DEFAULT_PATH_EDGE_WIDTH + 8;
41
- var MUTED_TARGET_COLOR = "#AAA";
42
- var sphereId = (name) => id("sphere" /* SPHERE */, name);
43
- var pathId = (pathNumber) => id("path" /* PATH */, String(pathNumber));
44
- var TREE_SPHERE_IDS = TREE_SPHERE_NAMES.map(
45
- (name) => sphereId(name)
46
- );
47
- var TREE_PATH_IDS = TREE_PATH_NUMBERS.map(
48
- (pathNumber) => pathId(pathNumber)
49
- );
50
- var CANONICAL_SPHERE_PERCENTAGES = {
51
- [sphereId("Kether")]: { x: CANONICAL_X_PERCENTAGES.mid, y: CANONICAL_ROW_Y_PERCENTAGES[0] },
52
- [sphereId("Chokhmah")]: { x: CANONICAL_X_PERCENTAGES.right, y: CANONICAL_ROW_Y_PERCENTAGES[1] },
53
- [sphereId("Binah")]: { x: CANONICAL_X_PERCENTAGES.left, y: CANONICAL_ROW_Y_PERCENTAGES[1] },
54
- [sphereId("Daath")]: { x: CANONICAL_X_PERCENTAGES.mid, y: CANONICAL_ROW_Y_PERCENTAGES[2] },
55
- [sphereId("Chesed")]: { x: CANONICAL_X_PERCENTAGES.right, y: CANONICAL_ROW_Y_PERCENTAGES[3] },
56
- [sphereId("Geburah")]: { x: CANONICAL_X_PERCENTAGES.left, y: CANONICAL_ROW_Y_PERCENTAGES[3] },
57
- [sphereId("Tiphareth")]: { x: CANONICAL_X_PERCENTAGES.mid, y: CANONICAL_ROW_Y_PERCENTAGES[4] },
58
- [sphereId("Netzach")]: { x: CANONICAL_X_PERCENTAGES.right, y: CANONICAL_ROW_Y_PERCENTAGES[5] },
59
- [sphereId("Hod")]: { x: CANONICAL_X_PERCENTAGES.left, y: CANONICAL_ROW_Y_PERCENTAGES[5] },
60
- [sphereId("Yesod")]: { x: CANONICAL_X_PERCENTAGES.mid, y: CANONICAL_ROW_Y_PERCENTAGES[6] },
61
- [sphereId("Malkuth")]: { x: CANONICAL_X_PERCENTAGES.mid, y: CANONICAL_ROW_Y_PERCENTAGES[7] }
62
- };
63
- function getTreeLayout(system = "kaabalah") {
64
- const tree = createTree({ system });
65
- const percentages = buildLayoutMap(tree, CANONICAL_SPHERE_PERCENTAGES);
66
- const viewBoxUnits = buildLayoutMap(
67
- tree,
68
- scaleCoordinates(CANONICAL_SPHERE_PERCENTAGES, TREE_SVG_DEFAULT_VIEWBOX)
69
- );
70
- return {
71
- system,
72
- viewBox: { ...TREE_SVG_DEFAULT_VIEWBOX },
73
- sphereOrder: [...TREE_SPHERE_IDS],
74
- pathOrder: [...TREE_PATH_IDS],
75
- percentages,
76
- viewBoxUnits
77
- };
78
- }
79
- function getTreeRenderModel(options = {}) {
80
- const system = options.system ?? "kaabalah";
81
- const tree = createTree({ system, parts: ["colors"] });
82
- const viewBox = normalizeViewBox(options.viewBox);
83
- const palette = resolvePalette(options.palette);
84
- const highlights = resolveHighlights(options.highlights);
85
- const activationMap = resolveActivationMap(options.activations);
86
- const layout = getTreeLayout(system);
87
- const spherePositions = scaleCoordinates(CANONICAL_SPHERE_PERCENTAGES, viewBox);
88
- const viewBoxLayout = buildLayoutMap(tree, spherePositions);
89
- const scale = Math.min(
90
- viewBox.width / TREE_SVG_DEFAULT_VIEWBOX.width,
91
- viewBox.height / TREE_SVG_DEFAULT_VIEWBOX.height
92
- );
93
- const radius = round(DEFAULT_SPHERE_RADIUS * scale);
94
- const pathEdgeWidth = round(DEFAULT_PATH_EDGE_WIDTH * scale);
95
- const pathMainWidth = round(DEFAULT_PATH_MAIN_WIDTH * scale);
96
- const pathHighlightWidth = round(DEFAULT_PATH_HIGHLIGHT_WIDTH * scale);
97
- const sphereHitRadius = round(DEFAULT_SPHERE_HIT_RADIUS * scale);
98
- const pathHitStrokeWidth = round(DEFAULT_PATH_HIT_STROKE_WIDTH * scale);
99
- const layers = [
100
- { name: "background", order: 0, description: "Background rectangle when requested." },
101
- ...options.daathLayer === "back" ? [{ name: "spheres-behind-paths", order: 1, description: "Daath behind the paths." }] : [],
102
- { name: "paths", order: options.daathLayer === "back" ? 2 : 1, description: "Canonical paths and activation emphasis." },
103
- { name: "spheres", order: options.daathLayer === "back" ? 3 : 2, description: "Canonical sphere material and activation halos." },
104
- { name: "hit-targets", order: options.daathLayer === "back" ? 4 : 3, description: "Invisible anchors for interaction." }
105
- ];
106
- const layerOrder = layers.map((layer) => layer.name);
107
- const spheres = TREE_SPHERE_NAMES.map((sphereName) => {
108
- const sphereIdValue = sphereId(sphereName);
109
- const canonicalColor = resolveSphereCanonicalColor({
110
- palette,
111
- sphereId: sphereIdValue,
112
- tree
113
- });
114
- const point = spherePositions[sphereIdValue];
115
- const activation = resolveTargetActivation({
116
- activation: activationMap.get(sphereIdValue),
117
- canonicalColor
118
- });
119
- const activeFill = resolveSphereDisplayFill({
120
- palette,
121
- highlights,
122
- sphereId: sphereIdValue,
123
- canonicalColor,
124
- activation
125
- });
126
- return {
127
- id: sphereIdValue,
128
- name: sphereName,
129
- slug: sphereName.toLowerCase(),
130
- canonicalColor,
131
- geometry: {
132
- percentages: {
133
- center: { ...layout.percentages.spheres[sphereIdValue] },
134
- anchor: getPercentageAnchor(layout.percentages.spheres[sphereIdValue])
135
- },
136
- viewBoxUnits: {
137
- center: { ...point },
138
- anchor: getViewBoxAnchor(point, viewBox),
139
- hitTarget: {
140
- kind: "circle",
141
- cx: point.x,
142
- cy: point.y,
143
- r: sphereHitRadius
144
- }
145
- },
146
- radius: {
147
- viewBoxUnits: radius
148
- }
149
- },
150
- material: getSphereMaterial({
151
- sphereName,
152
- preserveSpecialMaterial: shouldPreserveSpecialRenderer({
153
- palette,
154
- highlights,
155
- hasPaintOverride: activation !== null || highlights.sphereFills[sphereIdValue] !== void 0,
156
- activation
157
- })
158
- }),
159
- activation,
160
- displayFill: activeFill
161
- };
162
- });
163
- const paths = TREE_PATH_IDS.map((pathIdValue) => {
164
- const canonicalColor = resolvePathCanonicalColor({
165
- palette,
166
- tree,
167
- pathId: pathIdValue
168
- });
169
- const path = viewBoxLayout.paths[pathIdValue];
170
- const activation = resolveTargetActivation({
171
- activation: activationMap.get(pathIdValue),
172
- canonicalColor
173
- });
174
- const displayColor = activation ? resolvePathDisplayColor({
175
- canonicalColor,
176
- activation
177
- }) : resolvePathBaseColor({
178
- canonicalColor,
179
- highlights,
180
- pathId: pathIdValue
181
- });
182
- return {
183
- id: pathIdValue,
184
- canonicalColor,
185
- geometry: {
186
- percentages: {
187
- from: { ...layout.percentages.paths[pathIdValue].from },
188
- to: { ...layout.percentages.paths[pathIdValue].to },
189
- anchor: getPercentagePathAnchor(layout.percentages.paths[pathIdValue])
190
- },
191
- viewBoxUnits: {
192
- from: { ...path.from },
193
- to: { ...path.to },
194
- anchor: getViewBoxPathAnchor(path, viewBox),
195
- hitTarget: {
196
- kind: "line",
197
- x1: path.from.x,
198
- y1: path.from.y,
199
- x2: path.to.x,
200
- y2: path.to.y,
201
- strokeWidth: pathHitStrokeWidth
202
- }
203
- },
204
- widths: {
205
- edge: pathEdgeWidth,
206
- main: pathMainWidth,
207
- highlight: pathHighlightWidth,
208
- hitTarget: pathHitStrokeWidth
209
- }
210
- },
211
- activation,
212
- displayColor
213
- };
214
- });
215
- return {
216
- system,
217
- viewBox,
218
- scale,
219
- layout,
220
- layerOrder,
221
- layers,
222
- spheres,
223
- paths,
224
- sphereById: Object.fromEntries(spheres.map((entry) => [entry.id, entry])),
225
- pathById: Object.fromEntries(paths.map((entry) => [entry.id, entry]))
226
- };
227
- }
228
- function generateTreeSvg(options = {}) {
229
- const system = options.system ?? "kaabalah";
230
- const daathLayer = options.daathLayer ?? "front";
231
- const tree = createTree({ system, parts: ["colors"] });
232
- const viewBox = normalizeViewBox(options.viewBox);
233
- const palette = resolvePalette(options.palette);
234
- const highlights = resolveHighlights(options.highlights);
235
- const activationMap = resolveActivationMap(options.activations);
236
- const spherePositions = scaleCoordinates(CANONICAL_SPHERE_PERCENTAGES, viewBox);
237
- const layout = buildLayoutMap(tree, spherePositions);
238
- const scale = Math.min(
239
- viewBox.width / TREE_SVG_DEFAULT_VIEWBOX.width,
240
- viewBox.height / TREE_SVG_DEFAULT_VIEWBOX.height
241
- );
242
- const radius = round(DEFAULT_SPHERE_RADIUS * scale);
243
- const pathEdgeWidth = round(DEFAULT_PATH_EDGE_WIDTH * scale);
244
- const pathMainWidth = round(DEFAULT_PATH_MAIN_WIDTH * scale);
245
- const pathHighlightWidth = round(DEFAULT_PATH_HIGHLIGHT_WIDTH * scale);
246
- const sphereStrokeWidth = palette.sphereStrokeWidth ? round(palette.sphereStrokeWidth * scale) : void 0;
247
- const lines = [];
248
- const push = (line) => lines.push(line);
249
- const svgAttributes = [
250
- `xmlns="http://www.w3.org/2000/svg"`,
251
- options.width !== void 0 ? `width="${escapeAttr(String(options.width))}"` : "",
252
- options.height !== void 0 ? `height="${escapeAttr(String(options.height))}"` : "",
253
- `viewBox="${viewBox.minX} ${viewBox.minY} ${viewBox.width} ${viewBox.height}"`,
254
- `preserveAspectRatio="xMidYMid meet"`
255
- ].filter(Boolean);
256
- push(`<svg ${svgAttributes.join(" ")}>`);
257
- push(`<defs>`);
258
- push(`<filter id="pathDarken">
259
- <feComponentTransfer>
260
- <feFuncR type="linear" slope="0.65"/>
261
- <feFuncG type="linear" slope="0.65"/>
262
- <feFuncB type="linear" slope="0.65"/>
263
- </feComponentTransfer>
264
- </filter>`);
265
- for (const sphereName of TREE_SPHERE_NAMES) {
266
- const currentSphereId = sphereId(sphereName);
267
- const slug = sphereName.toLowerCase();
268
- const point = spherePositions[currentSphereId];
269
- if (!point) {
270
- continue;
271
- }
272
- push(`<radialGradient id="spec-${slug}" cx="30%" cy="25%" r="55%" fx="30%" fy="25%">
273
- <stop offset="0%" stop-color="white" stop-opacity="0.95"/>
274
- <stop offset="25%" stop-color="white" stop-opacity="0.45"/>
275
- <stop offset="50%" stop-color="white" stop-opacity="0.08"/>
276
- <stop offset="100%" stop-color="white" stop-opacity="0"/>
277
- </radialGradient>`);
278
- push(`<radialGradient id="shad-${slug}" cx="78%" cy="80%" r="55%" fx="78%" fy="80%">
279
- <stop offset="0%" stop-color="black" stop-opacity="0.32"/>
280
- <stop offset="40%" stop-color="black" stop-opacity="0.12"/>
281
- <stop offset="100%" stop-color="black" stop-opacity="0"/>
282
- </radialGradient>`);
283
- push(
284
- `<clipPath id="clip-${slug}"><circle cx="${point.x}" cy="${point.y}" r="${radius}"/></clipPath>`
285
- );
286
- }
287
- push(`<radialGradient id="kether-glow" cx="50%" cy="50%" r="50%">
288
- <stop offset="0%" stop-color="white" stop-opacity="0.95"/>
289
- <stop offset="45%" stop-color="white" stop-opacity="0.6"/>
290
- <stop offset="80%" stop-color="white" stop-opacity="0.15"/>
291
- <stop offset="100%" stop-color="white" stop-opacity="0"/>
292
- </radialGradient>`);
293
- push(`<linearGradient id="kether-facet" x1="0" y1="0" x2="0" y2="1">
294
- <stop offset="0%" stop-color="white" stop-opacity="0.9"/>
295
- <stop offset="50%" stop-color="white" stop-opacity="0.5"/>
296
- <stop offset="100%" stop-color="white" stop-opacity="0.1"/>
297
- </linearGradient>`);
298
- push(`<radialGradient id="kether-rim" cx="50%" cy="50%" r="75%">
299
- <stop offset="60%" stop-color="black" stop-opacity="0"/>
300
- <stop offset="100%" stop-color="black" stop-opacity="0.18"/>
301
- </radialGradient>`);
302
- push(`</defs>`);
303
- const background = options.background ?? "white";
304
- if (background !== "transparent") {
305
- push(
306
- `<rect x="${viewBox.minX}" y="${viewBox.minY}" width="${viewBox.width}" height="${viewBox.height}" fill="${escapeAttr(background)}"/>`
307
- );
308
- }
309
- if (daathLayer === "back") {
310
- push(`<g id="spheres-behind-paths">`);
311
- renderSphere(push, {
312
- highlights,
313
- activation: resolveTargetActivation({
314
- activation: activationMap.get(sphereId("Daath")),
315
- canonicalColor: resolveSphereCanonicalColor({
316
- palette,
317
- sphereId: sphereId("Daath"),
318
- tree
319
- })
320
- }),
321
- tree,
322
- palette,
323
- radius,
324
- sphereStrokeWidth,
325
- spherePositions,
326
- sphereName: "Daath"
327
- });
328
- push(`</g>`);
329
- }
330
- push(`<g id="paths">`);
331
- for (const currentPathId of TREE_PATH_IDS) {
332
- const path = layout.paths[currentPathId];
333
- const canonicalColor = resolvePathCanonicalColor({
334
- palette,
335
- tree,
336
- pathId: currentPathId
337
- });
338
- const baseColor = resolvePathBaseColor({
339
- canonicalColor,
340
- highlights,
341
- pathId: currentPathId
342
- });
343
- const activation = resolveTargetActivation({
344
- activation: activationMap.get(currentPathId),
345
- canonicalColor
346
- });
347
- const color = activation ? resolvePathDisplayColor({
348
- canonicalColor,
349
- activation
350
- }) : baseColor;
351
- const edgeColor = resolvePathEdgeColor({
352
- palette,
353
- pathColor: color
354
- });
355
- push(
356
- `<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)"` : ""}/>`
357
- );
358
- if (activation?.visible && activation.emphasis > 0) {
359
- push(
360
- `<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"/>`
361
- );
362
- }
363
- push(
364
- `<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"/>`
365
- );
366
- push(
367
- `<line x1="${path.from.x}" y1="${path.from.y}" x2="${path.to.x}" y2="${path.to.y}" stroke="${escapeAttr(palette.pathHighlightColor)}" stroke-opacity="${palette.pathHighlightOpacity}" stroke-width="${pathHighlightWidth}" stroke-linecap="round"/>`
368
- );
369
- }
370
- push(`</g>`);
371
- const frontSphereNames = daathLayer === "back" ? TREE_SPHERE_NAMES.filter((name) => name !== "Daath") : TREE_SPHERE_NAMES;
372
- push(`<g id="spheres">`);
373
- for (const sphereName of frontSphereNames) {
374
- const currentSphereId = sphereId(sphereName);
375
- const canonicalColor = resolveSphereCanonicalColor({
376
- palette,
377
- sphereId: currentSphereId,
378
- tree
379
- });
380
- renderSphere(push, {
381
- highlights,
382
- activation: resolveTargetActivation({
383
- activation: activationMap.get(currentSphereId),
384
- canonicalColor
385
- }),
386
- tree,
387
- palette,
388
- radius,
389
- sphereStrokeWidth,
390
- spherePositions,
391
- sphereName
392
- });
393
- }
394
- push(`</g>`);
395
- if (daathLayer === "back") {
396
- const daathPoint = spherePositions[sphereId("Daath")];
397
- push(
398
- `<circle id="sphere-daath-hit-area" data-node-id="sphere:Daath" cx="${daathPoint.x}" cy="${daathPoint.y}" r="${radius}" fill="transparent" pointer-events="all"/>`
399
- );
400
- }
401
- push(`</svg>`);
402
- return lines.join("\n");
403
- }
404
- function renderSphere(push, params) {
405
- const currentSphereId = sphereId(params.sphereName);
406
- const point = params.spherePositions[currentSphereId];
407
- const slug = params.sphereName.toLowerCase();
408
- const colorData = params.tree.relatedFirst(currentSphereId, "color" /* COLOR */)?.data?.colorHexCodes ?? [];
409
- const sphereFill = resolveSphereFill({
410
- palette: params.palette,
411
- sphereId: currentSphereId,
412
- defaultColors: colorData
413
- });
414
- const activationFill = params.activation && (params.activation.state === "inactive" || params.activation.colorOverride) ? params.activation.displayColor : void 0;
415
- const highlightFill = activationFill ?? params.highlights.sphereFills[currentSphereId];
416
- const activeFill = params.activation ? params.activation.displayColor : highlightFill ?? sphereFill;
417
- const preserveSpecialRenderer = shouldPreserveSpecialRenderer({
418
- palette: params.palette,
419
- highlights: params.highlights,
420
- hasPaintOverride: highlightFill !== void 0,
421
- activation: params.activation
422
- });
423
- if (params.activation?.visible && params.activation.emphasis > 0) {
424
- const haloStrokeWidth = round(3.2 + params.activation.emphasis * 4.8);
425
- const haloRadius = round(params.radius + haloStrokeWidth / 2 + 0.7);
426
- const haloColor = params.activation.displayColor;
427
- push(
428
- `<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}"/>`
429
- );
430
- }
431
- push(`<g id="sphere-${slug}" clip-path="url(#clip-${slug})">`);
432
- if (preserveSpecialRenderer) {
433
- if (params.sphereName === "Kether") {
434
- renderKether(
435
- push,
436
- point,
437
- params.radius,
438
- highlightFill ? toPrimaryFill(highlightFill, "#e0e0e0") : void 0
439
- );
440
- } else if (params.sphereName === "Chokhmah") {
441
- renderIridescent(push, point, params.radius);
442
- if (highlightFill) {
443
- renderSphereTintOverlay(push, point, params.radius, highlightFill, 0.62);
444
- }
445
- } else if (params.sphereName === "Daath") {
446
- renderYinYang(push, point, params.radius, highlightFill);
447
- } else if (params.sphereName === "Malkuth" && colorData.length >= 4) {
448
- const slicedColors = resolveMalkuthColors({
449
- highlightFill,
450
- paletteFill: sphereFill,
451
- defaultColors: colorData.slice(0, 4)
452
- });
453
- renderSlicedSphere(push, point, params.radius, slicedColors, -135);
454
- } else {
455
- push(
456
- `<circle cx="${point.x}" cy="${point.y}" r="${params.radius}" fill="${escapeAttr(toPrimaryFill(activeFill, params.palette.defaultSphereFill))}"/>`
457
- );
458
- }
459
- } else {
460
- push(
461
- `<circle cx="${point.x}" cy="${point.y}" r="${params.radius}" fill="${escapeAttr(toPrimaryFill(activeFill, params.palette.defaultSphereFill))}"/>`
462
- );
463
- }
464
- push(
465
- `<circle cx="${point.x}" cy="${point.y}" r="${params.radius}" fill="url(#spec-${slug})"/>`
466
- );
467
- if (!preserveSpecialRenderer || params.sphereName !== "Kether" && params.sphereName !== "Chokhmah") {
468
- push(
469
- `<circle cx="${point.x}" cy="${point.y}" r="${params.radius}" fill="url(#shad-${slug})"/>`
470
- );
471
- }
472
- push(`</g>`);
473
- if (params.palette.sphereStrokeColor && params.sphereStrokeWidth) {
474
- push(
475
- `<circle cx="${point.x}" cy="${point.y}" r="${params.radius}" fill="none" stroke="${escapeAttr(params.palette.sphereStrokeColor)}" stroke-width="${params.sphereStrokeWidth}"/>`
476
- );
477
- }
478
- }
479
- function buildLayoutMap(tree, spherePositions) {
480
- const paths = {};
481
- for (const currentPathId of TREE_PATH_IDS) {
482
- const path = tree.getNode(currentPathId);
483
- const fromId = path?.data?.from;
484
- const toId = path?.data?.to;
485
- if (!fromId || !toId) {
486
- throw new Error(`Tree path ${currentPathId} is missing endpoints.`);
487
- }
488
- const from = spherePositions[fromId];
489
- const to = spherePositions[toId];
490
- if (!from || !to) {
491
- throw new Error(
492
- `Tree path ${currentPathId} references unknown layout spheres: ${fromId}, ${toId}.`
493
- );
494
- }
495
- paths[currentPathId] = {
496
- fromId,
497
- toId,
498
- from: { ...from },
499
- to: { ...to }
500
- };
501
- }
502
- return {
503
- spheres: cloneCoordinateMap(spherePositions),
504
- paths
505
- };
506
- }
507
- function cloneCoordinateMap(coordinates) {
508
- const clone = {};
509
- for (const currentSphereId of TREE_SPHERE_IDS) {
510
- const point = coordinates[currentSphereId];
511
- clone[currentSphereId] = { ...point };
512
- }
513
- return clone;
514
- }
515
- function scaleCoordinates(coordinates, viewBox) {
516
- const scaled = {};
517
- for (const currentSphereId of TREE_SPHERE_IDS) {
518
- const point = coordinates[currentSphereId];
519
- scaled[currentSphereId] = {
520
- x: round(viewBox.minX + point.x / 100 * viewBox.width),
521
- y: round(viewBox.minY + point.y / 100 * viewBox.height)
522
- };
523
- }
524
- return scaled;
525
- }
526
- function normalizeViewBox(viewBox) {
527
- return {
528
- minX: viewBox?.minX ?? TREE_SVG_DEFAULT_VIEWBOX.minX,
529
- minY: viewBox?.minY ?? TREE_SVG_DEFAULT_VIEWBOX.minY,
530
- width: viewBox?.width ?? TREE_SVG_DEFAULT_VIEWBOX.width,
531
- height: viewBox?.height ?? TREE_SVG_DEFAULT_VIEWBOX.height
532
- };
533
- }
534
- function resolveActivationMap(activations) {
535
- const map = /* @__PURE__ */ new Map();
536
- for (const activation of activations ?? []) {
537
- map.set(activation.targetId, activation);
538
- }
539
- return map;
540
- }
541
- function resolveTargetActivation(params) {
542
- if (!params.activation) {
543
- return null;
544
- }
545
- const state = params.activation.state ?? (params.activation.count > 0 ? "active" : "inactive");
546
- const strength = clamp01(
547
- params.activation.strength ?? (params.activation.total > 0 ? params.activation.count / params.activation.total : 0)
548
- );
549
- const displayColor = state === "inactive" ? params.activation.color ?? MUTED_TARGET_COLOR : params.activation.color ?? params.canonicalColor;
550
- return {
551
- state,
552
- count: params.activation.count,
553
- total: params.activation.total,
554
- strength,
555
- canonicalColor: params.canonicalColor,
556
- displayColor,
557
- colorOverride: params.activation.color,
558
- mutedColor: MUTED_TARGET_COLOR,
559
- visible: state !== "inactive",
560
- 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
561
- };
562
- }
563
- function resolveSphereCanonicalColor(params) {
564
- const override = params.palette.sphereFills[params.sphereId];
565
- if (override) {
566
- return toPrimaryFill(override, params.palette.defaultSphereFill);
567
- }
568
- if (params.palette.mode === "monochrome" || params.palette.mode === "custom") {
569
- return params.palette.defaultSphereFill;
570
- }
571
- const treeColor = params.tree.relatedFirst(params.sphereId, "color" /* COLOR */)?.data?.colorHexCodes?.[0];
572
- return treeColor ?? params.palette.defaultSphereFill;
573
- }
574
- function resolvePathCanonicalColor(params) {
575
- const override = params.palette.pathColors[params.pathId];
576
- if (override) {
577
- return override;
578
- }
579
- if (params.palette.mode === "monochrome" || params.palette.mode === "custom") {
580
- return params.palette.defaultPathColor;
581
- }
582
- const treeColor = params.tree.relatedFirst(params.pathId, "color" /* COLOR */)?.data?.colorHexCodes?.[0];
583
- return treeColor ?? params.palette.defaultPathColor;
584
- }
585
- function resolvePathBaseColor(params) {
586
- const highlightOverride = params.highlights.pathColors[params.pathId];
587
- if (highlightOverride) {
588
- return highlightOverride;
589
- }
590
- return params.canonicalColor;
591
- }
592
- function resolveSphereDisplayFill(params) {
593
- const highlightOverride = params.highlights.sphereFills[params.sphereId];
594
- const fallbackFill = Array.isArray(params.canonicalColor) ? params.canonicalColor[0] ?? params.palette.defaultSphereFill : params.canonicalColor;
595
- if (params.activation) {
596
- if (params.activation.state !== "inactive" && !params.activation.colorOverride) {
597
- return params.canonicalColor ?? fallbackFill;
598
- }
599
- return params.activation.displayColor;
600
- }
601
- if (highlightOverride) {
602
- return highlightOverride;
603
- }
604
- return params.canonicalColor ?? fallbackFill;
605
- }
606
- function resolvePathDisplayColor(params) {
607
- if (!params.activation) {
608
- return params.canonicalColor;
609
- }
610
- return params.activation.displayColor;
611
- }
612
- function getPercentageAnchor(point) {
613
- return {
614
- x: point.x,
615
- y: point.y,
616
- vertical: point.y < 18 ? "below" : "above"
617
- };
618
- }
619
- function getViewBoxAnchor(point, viewBox) {
620
- return {
621
- x: point.x,
622
- y: point.y,
623
- vertical: point.y - viewBox.minY < viewBox.height * 0.18 ? "below" : "above"
624
- };
625
- }
626
- function getPercentagePathAnchor(path) {
627
- const y = round((path.from.y + path.to.y) / 2);
628
- return {
629
- x: round((path.from.x + path.to.x) / 2),
630
- y,
631
- vertical: y < 18 ? "below" : "above"
632
- };
633
- }
634
- function getViewBoxPathAnchor(path, viewBox) {
635
- const y = round((path.from.y + path.to.y) / 2);
636
- return {
637
- x: round((path.from.x + path.to.x) / 2),
638
- y,
639
- vertical: y - viewBox.minY < viewBox.height * 0.18 ? "below" : "above"
640
- };
641
- }
642
- function shouldPreserveSpecialRenderer(params) {
643
- return params.palette.specialSphereMode === "preserve" && (params.activation !== null || !params.hasPaintOverride || params.highlights.specialSphereMode === "preserve");
644
- }
645
- function getSphereMaterial(params) {
646
- if (!params.preserveSpecialMaterial) {
647
- return {
648
- kind: "standard",
649
- preserveOnActivation: false
650
- };
651
- }
652
- if (params.sphereName === "Kether") {
653
- return {
654
- kind: "special",
655
- specialSphereName: "Kether",
656
- preserveOnActivation: true
657
- };
658
- }
659
- if (params.sphereName === "Chokhmah") {
660
- return {
661
- kind: "special",
662
- specialSphereName: "Chokhmah",
663
- preserveOnActivation: true
664
- };
665
- }
666
- if (params.sphereName === "Daath") {
667
- return {
668
- kind: "special",
669
- specialSphereName: "Daath",
670
- preserveOnActivation: true
671
- };
672
- }
673
- if (params.sphereName === "Malkuth") {
674
- return {
675
- kind: "special",
676
- specialSphereName: "Malkuth",
677
- preserveOnActivation: true
678
- };
679
- }
680
- return {
681
- kind: "standard",
682
- preserveOnActivation: false
683
- };
684
- }
685
- function clamp01(value) {
686
- return Math.max(0, Math.min(1, value));
687
- }
688
- function resolvePalette(palette) {
689
- if (palette === void 0 || palette === "color") {
690
- return {
691
- mode: "color",
692
- defaultSphereFill: "#888888",
693
- defaultPathColor: "#888888",
694
- sphereFills: {},
695
- pathColors: {},
696
- pathEdgeColor: "#888888",
697
- pathEdgeUseFilter: true,
698
- pathHighlightColor: "white",
699
- pathHighlightOpacity: 0.25,
700
- specialSphereMode: "preserve"
701
- };
702
- }
703
- if (palette === "monochrome") {
704
- return {
705
- mode: "monochrome",
706
- defaultSphereFill: "#e6ddd0",
707
- defaultPathColor: "#e0d7ca",
708
- sphereFills: {},
709
- pathColors: {},
710
- pathEdgeColor: "#2f271e",
711
- pathEdgeUseFilter: false,
712
- sphereStrokeColor: "#2f271e",
713
- sphereStrokeWidth: 2.4,
714
- pathHighlightColor: "white",
715
- pathHighlightOpacity: 0.2,
716
- specialSphereMode: "plain"
717
- };
718
- }
719
- return {
720
- mode: "custom",
721
- defaultSphereFill: palette.defaultSphereFill ?? "#111111",
722
- defaultPathColor: palette.defaultPathColor ?? "#111111",
723
- sphereFills: palette.sphereFills ?? {},
724
- pathColors: palette.pathColors ?? {},
725
- pathEdgeColor: palette.pathEdgeColor ?? (palette.defaultPathColor ?? "#111111"),
726
- pathEdgeUseFilter: false,
727
- sphereStrokeColor: palette.sphereStrokeColor,
728
- sphereStrokeWidth: palette.sphereStrokeWidth,
729
- pathHighlightColor: palette.pathHighlightColor ?? "white",
730
- pathHighlightOpacity: palette.pathHighlightOpacity ?? 0.18,
731
- specialSphereMode: palette.specialSphereMode ?? "plain"
732
- };
733
- }
734
- function resolveHighlights(highlights) {
735
- return {
736
- pathColors: highlights?.paths ?? {},
737
- sphereFills: highlights?.spheres ?? {},
738
- specialSphereMode: highlights?.specialSphereMode ?? "preserve"
739
- };
740
- }
741
- function resolvePathEdgeColor(params) {
742
- if (params.palette.mode === "color") {
743
- return params.pathColor;
744
- }
745
- return params.palette.pathEdgeColor;
746
- }
747
- function resolveSphereFill(params) {
748
- const override = params.palette.sphereFills[params.sphereId];
749
- if (override) {
750
- return override;
751
- }
752
- if (params.palette.mode === "monochrome" || params.palette.mode === "custom") {
753
- return params.palette.defaultSphereFill;
754
- }
755
- if (params.defaultColors.length > 0) {
756
- return params.defaultColors;
757
- }
758
- return params.palette.defaultSphereFill;
759
- }
760
- function toPrimaryFill(fill, fallback) {
761
- if (Array.isArray(fill)) {
762
- return fill[0] ?? fallback;
763
- }
764
- return fill;
765
- }
766
- function resolveMalkuthColors(params) {
767
- if (params.highlightFill) {
768
- return expandColors(
769
- params.highlightFill,
770
- params.defaultColors.length,
771
- params.defaultColors
772
- );
773
- }
774
- if (Array.isArray(params.paletteFill)) {
775
- return expandColors(
776
- params.paletteFill,
777
- params.defaultColors.length,
778
- params.defaultColors
779
- );
780
- }
781
- return params.defaultColors;
782
- }
783
- function expandColors(fill, count, fallbackColors) {
784
- if (Array.isArray(fill)) {
785
- if (fill.length === 0) {
786
- return fallbackColors.slice(0, count);
787
- }
788
- return Array.from({ length: count }, (_, index) => {
789
- return fill[index] ?? fill[fill.length - 1];
790
- });
791
- }
792
- return Array.from({ length: count }, () => fill);
793
- }
794
- function round(value) {
795
- return Math.round(value * 100) / 100;
796
- }
797
- function polarToCartesian(cx, cy, radius, degrees) {
798
- const radians = Math.PI / 180 * degrees;
799
- return {
800
- x: round(cx + radius * Math.cos(radians)),
801
- y: round(cy + radius * Math.sin(radians))
802
- };
803
- }
804
- function arcPath(cx, cy, radius, startDegrees, endDegrees) {
805
- const start = polarToCartesian(cx, cy, radius, startDegrees);
806
- const end = polarToCartesian(cx, cy, radius, endDegrees);
807
- const largeArc = endDegrees - startDegrees <= 180 ? 0 : 1;
808
- return `M ${cx} ${cy} L ${start.x} ${start.y} A ${radius} ${radius} 0 ${largeArc} 1 ${end.x} ${end.y} Z`;
809
- }
810
- function renderKether(push, point, radius, baseFill = "#e0e0e0") {
811
- push(
812
- `<circle cx="${point.x}" cy="${point.y}" r="${radius}" fill="${escapeAttr(baseFill)}"/>`
813
- );
814
- push(`<circle cx="${point.x}" cy="${point.y}" r="${radius}" fill="url(#kether-glow)"/>`);
815
- const spokes = 16;
816
- const innerRadius = round(radius * 0.18);
817
- const outerRadius = round(radius * 0.92);
818
- const innerWidth = round(radius * 0.04);
819
- const angleStep = 360 / spokes;
820
- push(`<g opacity="0.85">`);
821
- for (let index = 0; index < spokes; index++) {
822
- const angle = index * angleStep;
823
- push(`<g transform="rotate(${angle} ${point.x} ${point.y})">`);
824
- const x0 = round(point.x - innerWidth);
825
- const y0 = round(point.y - innerRadius);
826
- const x1 = point.x;
827
- const y1 = round(point.y - outerRadius);
828
- const x2 = round(point.x + innerWidth);
829
- const y2 = round(point.y - innerRadius);
830
- push(
831
- `<polygon points="${x0},${y0} ${x1},${y1} ${x2},${y2} ${point.x},${point.y}" fill="url(#kether-facet)"/>`
832
- );
833
- push(`</g>`);
834
- }
835
- push(`</g>`);
836
- push(`<circle cx="${point.x}" cy="${point.y}" r="${radius}" fill="url(#kether-rim)"/>`);
837
- }
838
- function renderSlicedSphere(push, point, radius, colors, startAngle) {
839
- const segmentCount = colors.length;
840
- const step = 360 / segmentCount;
841
- let currentAngle = startAngle;
842
- for (let index = 0; index < segmentCount; index++) {
843
- const path = arcPath(point.x, point.y, radius * 0.96, currentAngle, currentAngle + step);
844
- push(`<path d="${path}" fill="${escapeAttr(colors[index])}" stroke="none"/>`);
845
- currentAngle += step;
846
- }
847
- }
848
- function renderIridescent(push, point, radius) {
849
- const stops = [
850
- [0, "#F0E8EE"],
851
- [0.1, "#ffa3e6"],
852
- [0.22, "#a7e0ff"],
853
- [0.34, "#baff9a"],
854
- [0.46, "#ffe28a"],
855
- [0.58, "#c6a4ff"],
856
- [0.7, "#9ad6ff"],
857
- [0.82, "#ffa3e6"],
858
- [1, "#F0E8EE"]
859
- ];
860
- const slices = 72;
861
- const sphereRadius = round(radius * 0.96);
862
- for (let index = 0; index < slices; index++) {
863
- const t = index / slices;
864
- const color = interpolateColorStops(stops, t);
865
- const startDegrees = t * 360 - 90;
866
- const endDegrees = startDegrees + 360 / slices + 0.5;
867
- const path = arcPath(point.x, point.y, sphereRadius, startDegrees, endDegrees);
868
- push(`<path d="${path}" fill="${color}" stroke="none"/>`);
869
- }
870
- }
871
- function interpolateColorStops(stops, t) {
872
- let lower = stops[0];
873
- let upper = stops[stops.length - 1];
874
- for (let index = 0; index < stops.length - 1; index++) {
875
- if (t >= stops[index][0] && t <= stops[index + 1][0]) {
876
- lower = stops[index];
877
- upper = stops[index + 1];
878
- break;
879
- }
880
- }
881
- const range = upper[0] - lower[0] || 1;
882
- return interpolateColor(lower[1], upper[1], (t - lower[0]) / range);
883
- }
884
- function interpolateColor(start, end, factor) {
885
- const parse = (hex) => {
886
- const match = hex.match(/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);
887
- return match ? [
888
- Number.parseInt(match[1], 16),
889
- Number.parseInt(match[2], 16),
890
- Number.parseInt(match[3], 16)
891
- ] : [0, 0, 0];
892
- };
893
- const [r1, g1, b1] = parse(start);
894
- const [r2, g2, b2] = parse(end);
895
- const mix = (left, right) => Math.round(left + (right - left) * factor);
896
- return `#${mix(r1, r2).toString(16).padStart(2, "0")}${mix(g1, g2).toString(16).padStart(2, "0")}${mix(b1, b2).toString(16).padStart(2, "0")}`;
897
- }
898
- function renderYinYang(push, point, radius, fill) {
899
- const scale = radius / 50;
900
- const circleRadius = round(48 * scale);
901
- const halfRadius = round(24 * scale);
902
- const dotRadius = round(6 * scale);
903
- const [lightFill, darkFill] = resolveDualToneFill(fill);
904
- push(`<g transform="rotate(180 ${point.x} ${point.y})">`);
905
- push(
906
- `<circle cx="${point.x}" cy="${point.y}" r="${circleRadius}" fill="${escapeAttr(lightFill)}"/>`
907
- );
908
- push(
909
- `<path d="M${point.x},${round(point.y - circleRadius)} A${circleRadius},${circleRadius} 0 1,1 ${point.x},${round(point.y + circleRadius)} A${halfRadius},${halfRadius} 0 1,0 ${point.x},${point.y} A${halfRadius},${halfRadius} 0 1,1 ${point.x},${round(point.y - circleRadius)}" fill="${escapeAttr(darkFill)}"/>`
910
- );
911
- push(
912
- `<circle cx="${point.x}" cy="${round(point.y - halfRadius)}" r="${dotRadius}" fill="${escapeAttr(lightFill)}"/>`
913
- );
914
- push(
915
- `<circle cx="${point.x}" cy="${round(point.y + halfRadius)}" r="${dotRadius}" fill="${escapeAttr(darkFill)}"/>`
916
- );
917
- push(`</g>`);
918
- }
919
- function renderSphereTintOverlay(push, point, radius, fill, opacity) {
920
- push(
921
- `<circle cx="${point.x}" cy="${point.y}" r="${radius}" fill="${escapeAttr(toPrimaryFill(fill, "#ffffff"))}" fill-opacity="${opacity}"/>`
922
- );
923
- }
924
- function resolveDualToneFill(fill) {
925
- if (Array.isArray(fill)) {
926
- return [fill[0] ?? "white", fill[1] ?? "black"];
927
- }
928
- if (fill) {
929
- return [fill, "black"];
930
- }
931
- return ["white", "black"];
932
- }
933
- function escapeAttr(value) {
934
- return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
935
- }
936
-
937
- export { TREE_PATH_IDS, TREE_SPHERE_IDS, TREE_SPHERE_NAMES, TREE_SVG_DEFAULT_VIEWBOX, generateTreeSvg, getTreeLayout, getTreeRenderModel };
938
- //# sourceMappingURL=chunk-BKNWKD32.mjs.map
939
- //# sourceMappingURL=chunk-BKNWKD32.mjs.map