magick-components 0.0.0-stage → 0.1.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/LICENSE.txt +89 -0
- package/README.md +353 -2
- package/fonts/FrankRuhlLibre-Bold-letters.woff2 +0 -0
- package/fonts/FrankRuhlLibre-OFL.txt +105 -0
- package/fonts/NotoSerif-BoldItalic-compass.woff2 +0 -0
- package/fonts/NotoSerif-Italic-latin1.woff2 +0 -0
- package/fonts/NotoSerif-OFL.txt +93 -0
- package/fonts/SOURCES.md +35 -0
- package/fonts/gd-hall.css +3 -0
- package/lib/astrology/Kamea.d.ts +75 -0
- package/lib/astrology/Kamea.js +73 -0
- package/lib/astrology/MercuryWidget.d.ts +21 -0
- package/lib/astrology/MercuryWidget.js +80 -0
- package/lib/astrology/Moon.d.ts +32 -0
- package/lib/astrology/Moon.js +39 -0
- package/lib/astrology/MoonWidget.d.ts +20 -0
- package/lib/astrology/MoonWidget.js +63 -0
- package/lib/astrology/PlanetarySpirit.d.ts +103 -0
- package/lib/astrology/PlanetarySpirit.js +102 -0
- package/lib/astrology/mercuryRetrograde.d.ts +20 -0
- package/lib/astrology/mercuryRetrograde.js +80 -0
- package/lib/astrology/moonPath.d.ts +20 -0
- package/lib/astrology/moonPath.js +45 -0
- package/lib/chakras/Chakras.d.ts +34 -0
- package/lib/chakras/Chakras.js +149 -0
- package/lib/cssString.d.ts +5 -0
- package/lib/cssString.js +7 -0
- package/lib/drawingVersions.d.ts +29 -0
- package/lib/drawingVersions.js +15 -0
- package/lib/enochian/Tablet.d.ts +17 -0
- package/lib/enochian/Tablet.js +24 -0
- package/lib/enochian/tabletSigils.d.ts +46 -0
- package/lib/enochian/tabletSigils.js +172 -0
- package/lib/enochian/tabletSvg.d.ts +85 -0
- package/lib/enochian/tabletSvg.js +278 -0
- package/lib/gd/FylfotCross.d.ts +60 -0
- package/lib/gd/FylfotCross.js +121 -0
- package/lib/gd/GradeTree.d.ts +10 -0
- package/lib/gd/GradeTree.js +21 -0
- package/lib/gd/Lamen.d.ts +31 -0
- package/lib/gd/Lamen.js +317 -0
- package/lib/gd/RoseSigil.d.ts +31 -0
- package/lib/gd/RoseSigil.js +49 -0
- package/lib/gd/RoseSigilImage.d.ts +38 -0
- package/lib/gd/RoseSigilImage.js +29 -0
- package/lib/gd/SevenBranchedCandlestick.d.ts +54 -0
- package/lib/gd/SevenBranchedCandlestick.js +269 -0
- package/lib/gd/TableOfShewbread.d.ts +19 -0
- package/lib/gd/TableOfShewbread.js +120 -0
- package/lib/gd/hall/GdHall.d.ts +94 -0
- package/lib/gd/hall/GdHall.js +147 -0
- package/lib/gd/hall/art/altar.d.ts +8 -0
- package/lib/gd/hall/art/altar.js +21 -0
- package/lib/gd/hall/art/altarItems.d.ts +20 -0
- package/lib/gd/hall/art/altarItems.js +113 -0
- package/lib/gd/hall/art/banner.d.ts +23 -0
- package/lib/gd/hall/art/banner.js +64 -0
- package/lib/gd/hall/art/board.d.ts +9 -0
- package/lib/gd/hall/art/board.js +49 -0
- package/lib/gd/hall/art/cards.d.ts +11 -0
- package/lib/gd/hall/art/cards.js +124 -0
- package/lib/gd/hall/art/furnishings.d.ts +12 -0
- package/lib/gd/hall/art/furnishings.js +36 -0
- package/lib/gd/hall/art/geometry.d.ts +49 -0
- package/lib/gd/hall/art/geometry.js +97 -0
- package/lib/gd/hall/art/hebrewLetter.d.ts +10 -0
- package/lib/gd/hall/art/hebrewLetter.js +38 -0
- package/lib/gd/hall/art/index.d.ts +7 -0
- package/lib/gd/hall/art/index.js +61 -0
- package/lib/gd/hall/art/items.d.ts +12 -0
- package/lib/gd/hall/art/items.js +125 -0
- package/lib/gd/hall/art/kamea.d.ts +20 -0
- package/lib/gd/hall/art/kamea.js +64 -0
- package/lib/gd/hall/art/lamen.d.ts +9 -0
- package/lib/gd/hall/art/lamen.js +52 -0
- package/lib/gd/hall/art/lightning.d.ts +13 -0
- package/lib/gd/hall/art/lightning.js +44 -0
- package/lib/gd/hall/art/lights.d.ts +13 -0
- package/lib/gd/hall/art/lights.js +64 -0
- package/lib/gd/hall/art/marker.d.ts +8 -0
- package/lib/gd/hall/art/marker.js +19 -0
- package/lib/gd/hall/art/pantacle.d.ts +10 -0
- package/lib/gd/hall/art/pantacle.js +119 -0
- package/lib/gd/hall/art/pillar.d.ts +4 -0
- package/lib/gd/hall/art/pillar.js +25 -0
- package/lib/gd/hall/art/placeholder.d.ts +8 -0
- package/lib/gd/hall/art/placeholder.js +18 -0
- package/lib/gd/hall/art/platform.d.ts +13 -0
- package/lib/gd/hall/art/platform.js +28 -0
- package/lib/gd/hall/art/seals.d.ts +23 -0
- package/lib/gd/hall/art/seals.js +151 -0
- package/lib/gd/hall/art/shared.d.ts +87 -0
- package/lib/gd/hall/art/shared.js +95 -0
- package/lib/gd/hall/art/symbols.d.ts +37 -0
- package/lib/gd/hall/art/symbols.js +134 -0
- package/lib/gd/hall/art/tarotKey.d.ts +34 -0
- package/lib/gd/hall/art/tarotKey.js +101 -0
- package/lib/gd/hall/art/veil.d.ts +8 -0
- package/lib/gd/hall/art/veil.js +22 -0
- package/lib/gd/hall/art/vessels.d.ts +19 -0
- package/lib/gd/hall/art/vessels.js +74 -0
- package/lib/gd/hall/aspect.d.ts +31 -0
- package/lib/gd/hall/aspect.js +161 -0
- package/lib/gd/hall/attributes.d.ts +52 -0
- package/lib/gd/hall/attributes.js +116 -0
- package/lib/gd/hall/describe.d.ts +38 -0
- package/lib/gd/hall/describe.js +184 -0
- package/lib/gd/hall/dimensions.d.ts +39 -0
- package/lib/gd/hall/dimensions.js +49 -0
- package/lib/gd/hall/editor.d.ts +13 -0
- package/lib/gd/hall/editor.js +13 -0
- package/lib/gd/hall/fontMetrics.json +177 -0
- package/lib/gd/hall/fonts.d.ts +45 -0
- package/lib/gd/hall/fonts.js +73 -0
- package/lib/gd/hall/hebrewLetters.d.ts +8 -0
- package/lib/gd/hall/hebrewLetters.js +40 -0
- package/lib/gd/hall/index.d.ts +19 -0
- package/lib/gd/hall/index.js +17 -0
- package/lib/gd/hall/labels.d.ts +72 -0
- package/lib/gd/hall/labels.js +109 -0
- package/lib/gd/hall/layout.d.ts +213 -0
- package/lib/gd/hall/layout.js +837 -0
- package/lib/gd/hall/planets.d.ts +13 -0
- package/lib/gd/hall/planets.js +35 -0
- package/lib/gd/hall/presets/index.d.ts +13 -0
- package/lib/gd/hall/presets/index.js +29 -0
- package/lib/gd/hall/presets/neophyte.d.ts +7 -0
- package/lib/gd/hall/presets/neophyte.js +74 -0
- package/lib/gd/hall/presets/philosophus.d.ts +30 -0
- package/lib/gd/hall/presets/philosophus.js +244 -0
- package/lib/gd/hall/presets/portal.d.ts +24 -0
- package/lib/gd/hall/presets/portal.js +241 -0
- package/lib/gd/hall/presets/practicus.d.ts +17 -0
- package/lib/gd/hall/presets/practicus.js +181 -0
- package/lib/gd/hall/presets/theoricus.d.ts +13 -0
- package/lib/gd/hall/presets/theoricus.js +178 -0
- package/lib/gd/hall/presets/types.d.ts +72 -0
- package/lib/gd/hall/presets/types.js +58 -0
- package/lib/gd/hall/presets/zelator.d.ts +12 -0
- package/lib/gd/hall/presets/zelator.js +161 -0
- package/lib/gd/hall/spec.d.ts +54 -0
- package/lib/gd/hall/spec.js +108 -0
- package/lib/gd/hall/types.d.ts +131 -0
- package/lib/gd/hall/types.js +1 -0
- package/lib/gd/hall/validate.d.ts +13 -0
- package/lib/gd/hall/validate.js +285 -0
- package/lib/gd/hall/vocabulary.d.ts +139 -0
- package/lib/gd/hall/vocabulary.js +435 -0
- package/lib/gd/lamenGlyphs.d.ts +16 -0
- package/lib/gd/lamenGlyphs.js +167 -0
- package/lib/gd/lamenGrades.d.ts +29 -0
- package/lib/gd/lamenGrades.js +36 -0
- package/lib/gd/roseSigilGeometry.d.ts +10 -0
- package/lib/gd/roseSigilGeometry.js +10 -0
- package/lib/gd/roseSigilInternals.d.ts +85 -0
- package/lib/gd/roseSigilInternals.js +343 -0
- package/lib/gd/roseSigilOptimizer.d.ts +15 -0
- package/lib/gd/roseSigilOptimizer.js +59 -0
- package/lib/gd/roseSigilVersions.d.ts +12 -0
- package/lib/gd/roseSigilVersions.js +57 -0
- package/lib/hooks/useHydrated.d.ts +9 -0
- package/lib/hooks/useHydrated.js +13 -0
- package/lib/kabbalah/TreeOfLife.d.ts +135 -0
- package/lib/kabbalah/TreeOfLife.js +312 -0
- package/lib/kabbalah/fieldPath.d.ts +25 -0
- package/lib/kabbalah/fieldPath.js +100 -0
- package/lib/kabbalah/treeLabels.d.ts +30 -0
- package/lib/kabbalah/treeLabels.js +32 -0
- package/lib/kabbalah/treeOfLifeFigure.d.ts +59 -0
- package/lib/kabbalah/treeOfLifeFigure.js +151 -0
- package/lib/svgCoordinate.d.ts +12 -0
- package/lib/svgCoordinate.js +16 -0
- package/package.json +162 -3
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { SephirahRow, TreeOfLifePathRow } from "magick-data/rows";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { ORDERED_PATHS as orderedPaths } from "./treeOfLifeFigure.tsx";
|
|
4
|
+
/**
|
|
5
|
+
* A scale the sephirot are coloured in, from magick-data's colours: the
|
|
6
|
+
* Queen's (`queen`) or the King's (`king`), each drawn with its `…Web` value.
|
|
7
|
+
*/
|
|
8
|
+
export type TreeColorScale = keyof SephirahRow["color"] extends infer Key ? Key extends `${infer Scale}Web` ? Scale : never : never;
|
|
9
|
+
/** The colour scales, as `colorScale` takes them. */
|
|
10
|
+
export declare const TREE_COLOR_SCALES: readonly TreeColorScale[];
|
|
11
|
+
/**
|
|
12
|
+
* Which tradition puts the Hebrew letters on the paths: the Golden Dawn's
|
|
13
|
+
* Hermetic Tree (`hermetic`) or the older Hebrew one (`hebrew`), as
|
|
14
|
+
* magick-data's paths give each.
|
|
15
|
+
*/
|
|
16
|
+
export type TreePathAttribution = keyof typeof orderedPaths & keyof TreeOfLifePathRow;
|
|
17
|
+
/**
|
|
18
|
+
* The Tree's props. Without any it draws as magick.ly's Tree page does by
|
|
19
|
+
* default: Roman names, numbered above and named in English below, in the
|
|
20
|
+
* Queen scale, with the Hermetic Tree's letters, and no links.
|
|
21
|
+
*/
|
|
22
|
+
export interface TreeOfLifeProps {
|
|
23
|
+
/** The SVG's width; the container's, `"100%"`, when not given. */
|
|
24
|
+
width?: string | number;
|
|
25
|
+
/** The SVG's height; from the width and the figure's shape when not given. */
|
|
26
|
+
height?: string | number;
|
|
27
|
+
/** Each sphere's label, Keter first and Da'at eleventh, in place of `field`'s. */
|
|
28
|
+
labels?: readonly string[];
|
|
29
|
+
/** The scale the spheres are coloured in: `queen` when not given. */
|
|
30
|
+
colorScale?: TreeColorScale;
|
|
31
|
+
/**
|
|
32
|
+
* What each sphere is labelled with: a field path into its magick-data
|
|
33
|
+
* row (`name.he`, `planet.name.en.en`, `stones.*.name.en`; `index` is
|
|
34
|
+
* the sphere's number), or several joined by commas, which are drawn
|
|
35
|
+
* space-separated. `name.roman` when not given or empty.
|
|
36
|
+
*/
|
|
37
|
+
field?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The field path(s) set on an arc above each sphere's label, as `field`
|
|
40
|
+
* takes them; `index` when not given, and none when empty.
|
|
41
|
+
*/
|
|
42
|
+
topText?: string;
|
|
43
|
+
/**
|
|
44
|
+
* The field path(s) set on an arc below each sphere's label, as `field`
|
|
45
|
+
* takes them; `name.en` when not given, and none when empty.
|
|
46
|
+
*/
|
|
47
|
+
bottomText?: string;
|
|
48
|
+
/** Whose letters the paths carry: `hermetic` when not given. */
|
|
49
|
+
letterAttr?: TreePathAttribution;
|
|
50
|
+
/**
|
|
51
|
+
* A sephirah's id (`"tiferet"`): that sphere is drawn and the others
|
|
52
|
+
* faded. `null` fades them all; not given, none is faded. Any other
|
|
53
|
+
* value throws, as for `activePath`.
|
|
54
|
+
*/
|
|
55
|
+
activeSephirah?: string | null;
|
|
56
|
+
/**
|
|
57
|
+
* Each path's link, given its magick-data row, or `null` for none.
|
|
58
|
+
* Without it the paths are not links.
|
|
59
|
+
*/
|
|
60
|
+
pathHref?: (path: TreeOfLifePathRow) => string | null;
|
|
61
|
+
/**
|
|
62
|
+
* Each sphere's link, given its magick-data row, or `null` for none.
|
|
63
|
+
* Without it the spheres are not links.
|
|
64
|
+
*/
|
|
65
|
+
sephirahHref?: (sephirah: SephirahRow) => string | null;
|
|
66
|
+
/**
|
|
67
|
+
* A path's id (`"1_2"`): it is drawn on top and highlighted, the rest
|
|
68
|
+
* faded. Any other value throws.
|
|
69
|
+
*/
|
|
70
|
+
activePath?: string;
|
|
71
|
+
/** Seen from behind, the body's view; the stylesheet mirrors the figure. */
|
|
72
|
+
flip?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Draws Da'at. Only the Queen scale colours it, so the King scale leaves
|
|
75
|
+
* it out.
|
|
76
|
+
*/
|
|
77
|
+
showDaat?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* The labels' font size. When not given, from `field`: 32 for `index`,
|
|
80
|
+
* 20 for `name.he` and `godName.name.he`, otherwise 10.
|
|
81
|
+
*/
|
|
82
|
+
fontSize?: string | number;
|
|
83
|
+
/** The `<svg>`, for exporting the drawing. */
|
|
84
|
+
ref?: React.Ref<SVGSVGElement>;
|
|
85
|
+
/**
|
|
86
|
+
* The `<svg>`'s id, which its stylesheet is scoped to and every id
|
|
87
|
+
* inside it begins with (`<id>-paths`, `<id>-topTextPath0`): letters,
|
|
88
|
+
* digits, `-` and `_`, starting with a letter. One from `useId` when
|
|
89
|
+
* not given, so that several Trees can share a page.
|
|
90
|
+
*/
|
|
91
|
+
id?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Where Noto Sans and Noto Sans Hebrew are served, as
|
|
94
|
+
* `NotoSans-Regular.ttf` and `NotoSansHebrew-Regular.ttf` under it. Given
|
|
95
|
+
* one, the SVG carries `@font-face` rules for them, which an exported SVG
|
|
96
|
+
* needs; the rules name the families for the whole page, as any
|
|
97
|
+
* `@font-face` does. Without it the Tree only names the families, and
|
|
98
|
+
* the page supplies them (or falls back to Arial and sans-serif).
|
|
99
|
+
*/
|
|
100
|
+
fontBaseUrl?: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The class each of the Tree's three layers carries, which a page may
|
|
104
|
+
* style by (as magick.ly's dark mode does): the paths' outlines, their
|
|
105
|
+
* letters, and the spheres with their labels. Part of the component's
|
|
106
|
+
* contract, unlike its ids.
|
|
107
|
+
*/
|
|
108
|
+
export declare const TREE_LAYER_CLASSES: {
|
|
109
|
+
readonly paths: "magick-tree-paths";
|
|
110
|
+
readonly pathLetters: "magick-tree-path-letters";
|
|
111
|
+
readonly sephirot: "magick-tree-sephirot";
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* The Tree of Life: the ten sephirot (eleven with Da'at) coloured in either
|
|
115
|
+
* scale and labelled from their magick-data rows, and the twenty-two paths
|
|
116
|
+
* with their Hebrew letters. Without props it draws as magick.ly's Tree
|
|
117
|
+
* page does by default. A sphere or a path is a link only where
|
|
118
|
+
* `sephirahHref` or `pathHref` gives it one, a plain link the browser
|
|
119
|
+
* follows. It reads the data itself and needs no client code, so it
|
|
120
|
+
* renders as a Server Component. Its ids come from `useId` when `id` is
|
|
121
|
+
* not given.
|
|
122
|
+
*/
|
|
123
|
+
export declare function TreeOfLife({ id, ...props }: TreeOfLifeProps): React.JSX.Element;
|
|
124
|
+
/** `TreeOfLifeSvg`'s props: the Tree's, its `id` required. */
|
|
125
|
+
export interface TreeOfLifeSvgProps extends TreeOfLifeProps {
|
|
126
|
+
id: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The Tree's drawing alone, with no hooks: for a renderer outside React's
|
|
130
|
+
* hook dispatcher, such as `renderToStaticMarkup` in a route handler,
|
|
131
|
+
* where `TreeOfLife`'s `useId` cannot run. It takes its `id`, so two on a
|
|
132
|
+
* page need two.
|
|
133
|
+
*/
|
|
134
|
+
export declare function TreeOfLifeSvg({ width, height, labels, colorScale, field, topText, bottomText, letterAttr, activeSephirah, pathHref, sephirahHref, activePath, flip, showDaat, fontSize, ref, id: rootId, fontBaseUrl, }: TreeOfLifeSvgProps): React.JSX.Element;
|
|
135
|
+
export default TreeOfLife;
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import Data from "magick-data";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { svgCoordinate } from "../svgCoordinate.js";
|
|
5
|
+
import { readFieldPath } from "./fieldPath.js";
|
|
6
|
+
import { labelLines, pathTitle } from "./treeLabels.js";
|
|
7
|
+
import { LineOutline, ORDERED_PATHS as orderedPaths, point, SEPHIRAH_CENTERS, sephirahWedges, TREE_GEOMETRY, } from "./treeOfLifeFigure.js";
|
|
8
|
+
const _sephirot = Object.values(Data.sephirah);
|
|
9
|
+
const _paths = Data.treeOfLifePath;
|
|
10
|
+
/** The colour scales, as `colorScale` takes them. */
|
|
11
|
+
export const TREE_COLOR_SCALES = ["queen", "king"];
|
|
12
|
+
/** A label's line height, as a multiple of its font size. */
|
|
13
|
+
const LINE_PITCH = 1.2;
|
|
14
|
+
/**
|
|
15
|
+
* A font size as a number of user units. The Tree page passes its query's
|
|
16
|
+
* text through, and a CSS size such as "12px" is a valid SVG `font-size`, so
|
|
17
|
+
* it is read leniently; anything without a number in it spaces the lines as
|
|
18
|
+
* the usual 10 would.
|
|
19
|
+
*/
|
|
20
|
+
function fontSizeNumber(size) {
|
|
21
|
+
const value = Number.parseFloat(String(size));
|
|
22
|
+
return Number.isFinite(value) && value > 0 ? value : 10;
|
|
23
|
+
}
|
|
24
|
+
/** A link, or a plain group when `href` is empty or not given. */
|
|
25
|
+
function SvgLink({ href, children, ...props }) {
|
|
26
|
+
if (!href)
|
|
27
|
+
return _jsx("g", { ...props, children: children });
|
|
28
|
+
return (_jsx("a", { ...props, xlinkHref: href, children: children }));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The class each of the Tree's three layers carries, which a page may
|
|
32
|
+
* style by (as magick.ly's dark mode does): the paths' outlines, their
|
|
33
|
+
* letters, and the spheres with their labels. Part of the component's
|
|
34
|
+
* contract, unlike its ids.
|
|
35
|
+
*/
|
|
36
|
+
export const TREE_LAYER_CLASSES = {
|
|
37
|
+
paths: "magick-tree-paths",
|
|
38
|
+
pathLetters: "magick-tree-path-letters",
|
|
39
|
+
sephirot: "magick-tree-sephirot",
|
|
40
|
+
};
|
|
41
|
+
/** A font URL may not end the CSS string or the `<style>` it sits in. */
|
|
42
|
+
const UNSAFE_FONT_URL = /["'()\\<>&\s]/;
|
|
43
|
+
/** An id the stylesheet can name without escaping. */
|
|
44
|
+
const SAFE_ID = /^[A-Za-z][\w-]*$/;
|
|
45
|
+
/** `@font-face` rules for the Tree's two families, served under `baseUrl`. */
|
|
46
|
+
function treeFontFaceCss(baseUrl) {
|
|
47
|
+
if (UNSAFE_FONT_URL.test(baseUrl))
|
|
48
|
+
throw new Error(`TreeOfLife: unsafe fontBaseUrl ${JSON.stringify(baseUrl)}; it may not hold quotes, brackets, backslashes, spaces or markup characters`);
|
|
49
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
50
|
+
return [
|
|
51
|
+
["Noto Sans", "NotoSans-Regular.ttf"],
|
|
52
|
+
["Noto Sans Hebrew", "NotoSansHebrew-Regular.ttf"],
|
|
53
|
+
]
|
|
54
|
+
.map(([family, file]) => `
|
|
55
|
+
@font-face {
|
|
56
|
+
font-family: '${family}';
|
|
57
|
+
src: local('${family}'), url('${base}/${file}') format('truetype')
|
|
58
|
+
}`)
|
|
59
|
+
.join("");
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The Tree of Life: the ten sephirot (eleven with Da'at) coloured in either
|
|
63
|
+
* scale and labelled from their magick-data rows, and the twenty-two paths
|
|
64
|
+
* with their Hebrew letters. Without props it draws as magick.ly's Tree
|
|
65
|
+
* page does by default. A sphere or a path is a link only where
|
|
66
|
+
* `sephirahHref` or `pathHref` gives it one, a plain link the browser
|
|
67
|
+
* follows. It reads the data itself and needs no client code, so it
|
|
68
|
+
* renders as a Server Component. Its ids come from `useId` when `id` is
|
|
69
|
+
* not given.
|
|
70
|
+
*/
|
|
71
|
+
export function TreeOfLife({ id, ...props }) {
|
|
72
|
+
const generatedId = `tree-of-life-${React.useId().replace(/[^A-Za-z0-9_-]/g, "_")}`;
|
|
73
|
+
return _jsx(TreeOfLifeSvg, { ...props, id: id ?? generatedId });
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The Tree's drawing alone, with no hooks: for a renderer outside React's
|
|
77
|
+
* hook dispatcher, such as `renderToStaticMarkup` in a route handler,
|
|
78
|
+
* where `TreeOfLife`'s `useId` cannot run. It takes its `id`, so two on a
|
|
79
|
+
* page need two.
|
|
80
|
+
*/
|
|
81
|
+
export function TreeOfLifeSvg({ width, height, labels, colorScale, field, topText = "index", bottomText = "name.en", letterAttr = "hermetic", activeSephirah, pathHref, sephirahHref, activePath, flip, showDaat, fontSize, ref, id: rootId, fontBaseUrl, }) {
|
|
82
|
+
if (!SAFE_ID.test(rootId))
|
|
83
|
+
throw new Error(`TreeOfLife: id ${JSON.stringify(rootId)} must be letters, digits, "-" and "_", starting with a letter`);
|
|
84
|
+
/** An id inside this Tree. */
|
|
85
|
+
const local = (name) => `${rootId}-${name}`;
|
|
86
|
+
const scale = colorScale || "queen";
|
|
87
|
+
if (!TREE_COLOR_SCALES.includes(scale))
|
|
88
|
+
throw new Error(`TreeOfLife: unknown colorScale ${JSON.stringify(scale)}; expected one of ${TREE_COLOR_SCALES.join(", ")}`);
|
|
89
|
+
const color = `${scale}Web`;
|
|
90
|
+
if (!Object.hasOwn(orderedPaths, letterAttr))
|
|
91
|
+
throw new Error(`TreeOfLife: unknown letterAttr ${JSON.stringify(letterAttr)}; expected one of ${Object.keys(orderedPaths).join(", ")}`);
|
|
92
|
+
if (activeSephirah !== undefined &&
|
|
93
|
+
activeSephirah !== null &&
|
|
94
|
+
!Object.hasOwn(Data.sephirah, activeSephirah))
|
|
95
|
+
throw new Error(`TreeOfLife: unknown activeSephirah ${JSON.stringify(activeSephirah)}; expected a sephirah's id, one of ${Object.keys(Data.sephirah).join(", ")}, or null for none`);
|
|
96
|
+
if (activePath !== undefined && !Object.hasOwn(_paths, activePath))
|
|
97
|
+
throw new Error(`TreeOfLife: unknown activePath ${JSON.stringify(activePath)}; expected a path's id, one of ${Object.keys(_paths).join(", ")}`);
|
|
98
|
+
width = width || "100%";
|
|
99
|
+
field = field || "name.roman";
|
|
100
|
+
const fieldPaths = field;
|
|
101
|
+
if (!labels)
|
|
102
|
+
labels = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((i) => fieldPaths
|
|
103
|
+
.split(",")
|
|
104
|
+
.map((field) => readFieldPath(_sephirot[i], field))
|
|
105
|
+
.join(" "));
|
|
106
|
+
const topTextArr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((i) => topText
|
|
107
|
+
.split(",")
|
|
108
|
+
.map((path) => readFieldPath(_sephirot[i], path))
|
|
109
|
+
.join(" "));
|
|
110
|
+
const bottomTextArr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((i) => bottomText
|
|
111
|
+
.split(",")
|
|
112
|
+
.map((path) => readFieldPath(_sephirot[i], path))
|
|
113
|
+
.join(" "));
|
|
114
|
+
// `name.roman` is the Tree page's 10, so that the defaults stated are
|
|
115
|
+
// the defaults; the image API, whose links predate the page, gives 12.
|
|
116
|
+
const fontSizeFromFieldName = {
|
|
117
|
+
index: 32,
|
|
118
|
+
"name.en": 10,
|
|
119
|
+
"name.he": 20,
|
|
120
|
+
"name.roman": 10,
|
|
121
|
+
"godName.name.he": 20,
|
|
122
|
+
};
|
|
123
|
+
if (!fontSize)
|
|
124
|
+
fontSize = fontSizeFromFieldName[field] || 10;
|
|
125
|
+
const { constructRadius, sephirahRadius, canvasWidth, canvasHeight } = TREE_GEOMETRY;
|
|
126
|
+
const showConstructionCircles = false;
|
|
127
|
+
const pillar = TREE_GEOMETRY.pillars.map((x) => ({ x }));
|
|
128
|
+
const rowStart = TREE_GEOMETRY.rowStart;
|
|
129
|
+
const labelled = labels;
|
|
130
|
+
/**
|
|
131
|
+
* The ith sphere: Keter first, Da'at eleventh. Da'at has no King
|
|
132
|
+
* colour, so in that scale it is left out (below).
|
|
133
|
+
*/
|
|
134
|
+
const sphere = (i) => ({
|
|
135
|
+
x: SEPHIRAH_CENTERS[i].x,
|
|
136
|
+
y: SEPHIRAH_CENTERS[i].y,
|
|
137
|
+
data: _sephirot[i],
|
|
138
|
+
// Every sphere but Da'at is coloured in both scales (magick-data).
|
|
139
|
+
color: _sephirot[i].color[color],
|
|
140
|
+
text: labelled[i] ?? "",
|
|
141
|
+
textColor: _sephirot[i].color[`${color}Text`],
|
|
142
|
+
});
|
|
143
|
+
const sephirot = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(sphere);
|
|
144
|
+
if (showDaat && _sephirot[10].color[color] !== undefined)
|
|
145
|
+
sephirot.push(sphere(10));
|
|
146
|
+
//console.log(sephirot);
|
|
147
|
+
let pathIds = orderedPaths[letterAttr];
|
|
148
|
+
if (activePath) {
|
|
149
|
+
// Bring activePath to top
|
|
150
|
+
pathIds = pathIds.filter((x) => x !== activePath);
|
|
151
|
+
pathIds.unshift(activePath);
|
|
152
|
+
}
|
|
153
|
+
// Map to path data with that id
|
|
154
|
+
const pathsToDraw = pathIds.map((id) => _paths[id]).reverse();
|
|
155
|
+
const outerSephirot = activePath ? activePath.split("_").map(Number) : [];
|
|
156
|
+
function sephirahOpacity(sephirah) {
|
|
157
|
+
if (activeSephirah === undefined && !activePath)
|
|
158
|
+
return 1;
|
|
159
|
+
if (activeSephirah && activeSephirah === sephirah.data.id)
|
|
160
|
+
return 1;
|
|
161
|
+
if (activePath) {
|
|
162
|
+
if (outerSephirot.includes(sephirah.data.index))
|
|
163
|
+
return 1;
|
|
164
|
+
}
|
|
165
|
+
return 0.1;
|
|
166
|
+
}
|
|
167
|
+
function pathLetterPos(path) {
|
|
168
|
+
// Adjust position on path to avoid being covered over by other paths
|
|
169
|
+
// prettier-ignore
|
|
170
|
+
const specialPositions = {
|
|
171
|
+
hebrew: {
|
|
172
|
+
"2_5": 0.3,
|
|
173
|
+
"3_4": 0.3, // Half way to 2_5,3_4 intersection
|
|
174
|
+
"2_6": 0.333,
|
|
175
|
+
"3_6": 0.333, // Level with y-cent of 1_6, 2_4, 3_5
|
|
176
|
+
"6_9": 0.635, // Visible between 7_8 and Yesod
|
|
177
|
+
},
|
|
178
|
+
hermetic: {
|
|
179
|
+
"2_6": 0.333,
|
|
180
|
+
"3_6": 0.333, // In line with Center 1_6, 2_4, 3_5
|
|
181
|
+
"6_9": 0.635, // Visible between 7_8 and Yesod
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
return specialPositions[letterAttr][path.id] || 0.5;
|
|
185
|
+
}
|
|
186
|
+
return (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg",
|
|
187
|
+
// The links and the labels' text paths are `xlink:href`, which an
|
|
188
|
+
// XML parser rejects without the prefix declared.
|
|
189
|
+
xmlnsXlink: "http://www.w3.org/1999/xlink", version: "1.1",
|
|
190
|
+
// viewBox="0 0 316 600"
|
|
191
|
+
// viewBox={"0 0 " + canvasWidth + " " + canvasHeight}
|
|
192
|
+
viewBox: -canvasWidth / 2 + " " + 0 + " " + canvasWidth + " " + canvasHeight, id: rootId, width: width, height: height, ref: ref, children: [_jsx("style", { type: "text/css", children: `${fontBaseUrl === undefined ? "" : treeFontFaceCss(fontBaseUrl)}
|
|
193
|
+
svg#${rootId} {
|
|
194
|
+
font-family: 'Noto Sans', 'Noto Sans Hebrew', Arial, sans-serif;
|
|
195
|
+
}
|
|
196
|
+
svg#${rootId} a:visited * {
|
|
197
|
+
fill: inherit;
|
|
198
|
+
}
|
|
199
|
+
` + (flip ? `svg#${rootId} { transform: rotateY(180deg) }` : "") }), _jsx("g", { id: local("paths"), className: TREE_LAYER_CLASSES.paths, style: {
|
|
200
|
+
stroke: "#000",
|
|
201
|
+
strokeWidth: 3,
|
|
202
|
+
fill: "#fff",
|
|
203
|
+
paintOrder: "stroke fill markers",
|
|
204
|
+
}, children: pathsToDraw.map((path) => {
|
|
205
|
+
const parts = path.id.split("_");
|
|
206
|
+
const start = sephirot[Number(parts[0]) - 1];
|
|
207
|
+
const end = sephirot[Number(parts[1]) - 1];
|
|
208
|
+
const styleActive = { fill: "#ffa" };
|
|
209
|
+
const styleInactive = { opacity: 0.2 };
|
|
210
|
+
const style = activePath
|
|
211
|
+
? activePath === path.id
|
|
212
|
+
? styleActive
|
|
213
|
+
: styleInactive
|
|
214
|
+
: null;
|
|
215
|
+
return (_jsxs(SvgLink, { id: local("path" + path.id), href: pathHref?.(path), children: [_jsx(LineOutline, { x1: start.x, y1: start.y, x2: end.x, y2: end.y, offset: 8.5, style: style ?? undefined }), _jsx("title", { children: pathTitle(path, letterAttr) })] }, path.id));
|
|
216
|
+
}) }), _jsx("g", { id: local("pathLetters"), className: TREE_LAYER_CLASSES.pathLetters, style: { fontSize: "100%" }, children: pathsToDraw.map((path) => {
|
|
217
|
+
const parts = path.id.split("_");
|
|
218
|
+
const start = sephirot[Number(parts[0]) - 1];
|
|
219
|
+
const end = sephirot[Number(parts[1]) - 1];
|
|
220
|
+
const shift = pathLetterPos(path);
|
|
221
|
+
const letterPos = {
|
|
222
|
+
x: start.x + (end.x - start.x) * shift,
|
|
223
|
+
y: start.y + (end.y - start.y) * shift,
|
|
224
|
+
};
|
|
225
|
+
const styleActive = {};
|
|
226
|
+
const styleInactive = { opacity: 0.2 };
|
|
227
|
+
const style = activePath
|
|
228
|
+
? activePath === path.id
|
|
229
|
+
? styleActive
|
|
230
|
+
: styleInactive
|
|
231
|
+
: null;
|
|
232
|
+
return (_jsx(SvgLink, { id: local("pathLetter" + path.id), href: pathHref?.(path), children: _jsx("text", { style: style || undefined, x: letterPos.x, y: letterPos.y, textAnchor: "middle", dominantBaseline: "middle", children: path[letterAttr]?.hebrewLetter?.letter?.he }, path.id) }, path.id));
|
|
233
|
+
}) }), _jsx("g", { id: local("sephirot"), className: TREE_LAYER_CLASSES.sephirot, children: sephirot.map((s, i) => (_jsxs(SvgLink, { id: local(s.data.id), href: sephirahHref?.(s.data), children: [_jsx("circle", { cx: s.x, cy: s.y, r: sephirahRadius, fill: s.color.match(",") ? undefined : s.color, style: {
|
|
234
|
+
// Override a:visited * { inherit } from style.
|
|
235
|
+
fill: s.color.match(",") ? undefined : s.color,
|
|
236
|
+
},
|
|
237
|
+
// Only Da'at is drawn dashed, and only it has these.
|
|
238
|
+
stroke: s.data.color.strokeColor || "#000", strokeWidth: "1.568", strokeDasharray: s.data.color.strokeDasharray, opacity: sephirahOpacity(s) }), (function () {
|
|
239
|
+
const colors = s.color.split(",");
|
|
240
|
+
if (colors.length < 2)
|
|
241
|
+
return null;
|
|
242
|
+
return sephirahWedges(s.x, s.y, colors).map((wedge, i) => (_jsx("path", { style: {
|
|
243
|
+
fill: wedge.fill,
|
|
244
|
+
stroke: "#000000",
|
|
245
|
+
strokeWidth: 1.568,
|
|
246
|
+
}, opacity: sephirahOpacity(s), d: wedge.d }, i)));
|
|
247
|
+
})(), field === "gdGrade.id" ? (_jsxs("g", { children: [_jsx("circle", { cx: s.x - 20, cy: s.y, r: "12", fill: "none", stroke: s.textColor || "black" }), _jsx("text", { x: s.x - 20, y: s.y + 1, textAnchor: "middle", dominantBaseline: "middle", fill: s.textColor || "black", children: s.text.split("=")[0] }), _jsx("text", { x: s.x, y: s.y + 1, textAnchor: "middle", dominantBaseline: "middle", fill: s.textColor || "black", fontSize: "150%", children: "=" }), _jsx("rect", { x: s.x + 10, y: s.y - 10, width: "20", height: "20", fill: "none", stroke: s.textColor || "black" }), _jsx("text", { x: s.x + 20, y: s.y + 1, textAnchor: "middle", dominantBaseline: "middle", fill: s.textColor || "black", children: s.text.split("=")[1] })] })) : ((function () {
|
|
248
|
+
const texts = labelLines(s.text);
|
|
249
|
+
const style = {
|
|
250
|
+
// We repeat in "style" to override a:visited * { color }
|
|
251
|
+
style: { fill: s.textColor || "black" },
|
|
252
|
+
fill: s.textColor || "black",
|
|
253
|
+
fillOpacity: sephirahOpacity(s),
|
|
254
|
+
textAnchor: "middle",
|
|
255
|
+
dominantBaseline: "middle",
|
|
256
|
+
stroke: "none",
|
|
257
|
+
fontSize: fontSize,
|
|
258
|
+
fontStyle: "normal",
|
|
259
|
+
fontWeight: "normal",
|
|
260
|
+
letterSpacing: 0,
|
|
261
|
+
wordSpacing: 0,
|
|
262
|
+
};
|
|
263
|
+
if (texts.length > 1) {
|
|
264
|
+
// Lines a little more than a font size apart, the block
|
|
265
|
+
// centred on the sphere: ±6 at the usual 10, where a fixed
|
|
266
|
+
// ±11 left a line's height of gap between two.
|
|
267
|
+
const pitch = LINE_PITCH * fontSizeNumber(fontSize);
|
|
268
|
+
return (_jsx("g", { children: texts.map((line, n) => (_jsx("text", { x: s.x, y: svgCoordinate(s.y + (n - (texts.length - 1) / 2) * pitch), ...style, children: line }, n))) }));
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
return (_jsx("text", { x: s.x, y: s.y, ...style, children: s.text }, i));
|
|
272
|
+
}
|
|
273
|
+
})()), (function () {
|
|
274
|
+
const diameter = 64;
|
|
275
|
+
const radius = diameter / 2;
|
|
276
|
+
// http://digerati-illuminatus.blogspot.com/2008/05/approximating-semicircle-with-cubic.html
|
|
277
|
+
const xValueInset = diameter * 0.05;
|
|
278
|
+
const yValueOffset = (radius * 4.0) / 3.0;
|
|
279
|
+
return (_jsxs("g", { children: [_jsx("path", { id: local("topTextPath" + i), d: `M ${point(s.x - radius, s.y)} ` +
|
|
280
|
+
`c ${point(xValueInset, -yValueOffset)} ` +
|
|
281
|
+
`${point(diameter - xValueInset, -yValueOffset)} ${diameter},0`, style: { fill: "none", stroke: "none" } }), _jsx("text", { id: local("topText_" + i), style: {
|
|
282
|
+
fontStyle: "normal",
|
|
283
|
+
fontWeight: "normal",
|
|
284
|
+
fontSize: "10px",
|
|
285
|
+
letterSpacing: "-0.5px",
|
|
286
|
+
wordSpacing: "0px",
|
|
287
|
+
fill: s.textColor || "black",
|
|
288
|
+
fillOpacity: sephirahOpacity(s),
|
|
289
|
+
stroke: "none",
|
|
290
|
+
strokeWidth: "0.8px",
|
|
291
|
+
strokeLinecap: "butt",
|
|
292
|
+
strokeLinejoin: "miter",
|
|
293
|
+
strokeOpacity: 1,
|
|
294
|
+
}, children: _jsx("textPath", { xlinkHref: "#" + local("topTextPath" + i), textAnchor: "middle", dominantBaseline: "middle", startOffset: "50%", children: topTextArr[i] }) }), _jsx("path", { id: local("bottomTextPath" + i), d: `M ${point(s.x - radius, s.y)} ` +
|
|
295
|
+
`c ${point(xValueInset, yValueOffset)} ` +
|
|
296
|
+
`${point(diameter - xValueInset, yValueOffset)} ${diameter},0`, style: { fill: "none", stroke: "none" } }), _jsx("text", { id: local("bottomText_" + i), style: {
|
|
297
|
+
fontStyle: "normal",
|
|
298
|
+
fontWeight: "normal",
|
|
299
|
+
fontSize: "10px",
|
|
300
|
+
letterSpacing: "-0.5px",
|
|
301
|
+
wordSpacing: "0px",
|
|
302
|
+
fill: s.textColor || "black",
|
|
303
|
+
fillOpacity: sephirahOpacity(s),
|
|
304
|
+
stroke: "none",
|
|
305
|
+
strokeWidth: "0.8px",
|
|
306
|
+
strokeLinecap: "butt",
|
|
307
|
+
strokeLinejoin: "miter",
|
|
308
|
+
strokeOpacity: 1,
|
|
309
|
+
}, children: _jsx("textPath", { xlinkHref: "#" + local("bottomTextPath" + i), textAnchor: "middle", dominantBaseline: "middle", startOffset: "50%", children: bottomTextArr[i] }) })] }));
|
|
310
|
+
})()] }, i))) }), showConstructionCircles && (_jsxs(_Fragment, { children: [_jsx("circle", { cx: pillar[1].x, cy: rowStart, r: constructRadius, stroke: "#f00", fill: "white", fillOpacity: "0.5" }), _jsx("circle", { cx: pillar[1].x, cy: rowStart + constructRadius, r: constructRadius, stroke: "#f00", fill: "white", fillOpacity: "0.5" }), _jsx("circle", { cx: pillar[1].x, cy: rowStart + 2 * constructRadius, r: constructRadius, stroke: "#f00", fill: "white", fillOpacity: "0.5" }), _jsx("circle", { cx: pillar[1].x, cy: rowStart + 3 * constructRadius, r: constructRadius, stroke: "#f00", fill: "white", fillOpacity: "0.5" })] }))] }));
|
|
311
|
+
}
|
|
312
|
+
export default TreeOfLife;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getProperty } from "dot-prop";
|
|
2
|
+
/** What `*` joins a list's values with: the separator the data already used. */
|
|
3
|
+
export declare const FIELD_PATH_LIST_SEPARATOR = "; ";
|
|
4
|
+
/**
|
|
5
|
+
* Reads a dotted field path such as `name.en` from a data record.
|
|
6
|
+
*
|
|
7
|
+
* dot-prop 10 throws on malformed bracket paths. Field paths arrive from the
|
|
8
|
+
* query string, so an unusable path yields `undefined` and a blank label
|
|
9
|
+
* instead of a render error.
|
|
10
|
+
*
|
|
11
|
+
* A `*` segment applied to a list reads the rest of the path from every
|
|
12
|
+
* element and joins what it finds with "; ", so `stones.*.name.en` reads
|
|
13
|
+
* "pearl; star sapphire" (plan 039, decision 4). An element the rest of the
|
|
14
|
+
* path finds nothing in, or only `null` or `""`, is left out, and a list it
|
|
15
|
+
* finds nothing in at all reads `undefined` rather than "", so a label is
|
|
16
|
+
* blank rather than empty. `*` applied to anything but a list is `undefined`.
|
|
17
|
+
* dot-prop gives `*` no meaning, so a path without one is read by dot-prop
|
|
18
|
+
* alone, exactly as before.
|
|
19
|
+
*
|
|
20
|
+
* One `*` per path, and a second makes the path `undefined`. The data needs
|
|
21
|
+
* no more, and each one multiplies the work by its list's length: through
|
|
22
|
+
* links that loop back, as `pathsFrom.*.to.pathsTo.*.from` does, a short path
|
|
23
|
+
* from a query string would read millions of rows and freeze the page.
|
|
24
|
+
*/
|
|
25
|
+
export declare function readFieldPath(source: Parameters<typeof getProperty>[0], path: string): unknown;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { getProperty, parsePath } from "dot-prop";
|
|
2
|
+
/** The segment that reads every element of a list. */
|
|
3
|
+
const EVERY = "*";
|
|
4
|
+
/** What `*` joins a list's values with: the separator the data already used. */
|
|
5
|
+
export const FIELD_PATH_LIST_SEPARATOR = "; ";
|
|
6
|
+
/**
|
|
7
|
+
* How many whole, unescaped `*` segments a path has, as dot-prop splits it:
|
|
8
|
+
* a backslash escapes the character after it, so the path `\*` is a key
|
|
9
|
+
* named `*` and `a\.*` one key, while `a\\.*` is the key `a\` and then a
|
|
10
|
+
* wildcard. Scanned rather than matched with a regular expression, which
|
|
11
|
+
* would need a lookbehind, and older Safari cannot parse one.
|
|
12
|
+
*/
|
|
13
|
+
function wildcardSegments(path) {
|
|
14
|
+
let count = 0;
|
|
15
|
+
let segment = "";
|
|
16
|
+
let escaped = false;
|
|
17
|
+
for (const character of path) {
|
|
18
|
+
if (escaped) {
|
|
19
|
+
// An escaped character is never the bare `*` a wildcard is.
|
|
20
|
+
segment += `\\${character}`;
|
|
21
|
+
escaped = false;
|
|
22
|
+
}
|
|
23
|
+
else if (character === "\\")
|
|
24
|
+
escaped = true;
|
|
25
|
+
else if (character === ".") {
|
|
26
|
+
if (segment === EVERY)
|
|
27
|
+
count++;
|
|
28
|
+
segment = "";
|
|
29
|
+
}
|
|
30
|
+
else
|
|
31
|
+
segment += character;
|
|
32
|
+
}
|
|
33
|
+
if (segment === EVERY)
|
|
34
|
+
count++;
|
|
35
|
+
return count;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Reads a dotted field path such as `name.en` from a data record.
|
|
39
|
+
*
|
|
40
|
+
* dot-prop 10 throws on malformed bracket paths. Field paths arrive from the
|
|
41
|
+
* query string, so an unusable path yields `undefined` and a blank label
|
|
42
|
+
* instead of a render error.
|
|
43
|
+
*
|
|
44
|
+
* A `*` segment applied to a list reads the rest of the path from every
|
|
45
|
+
* element and joins what it finds with "; ", so `stones.*.name.en` reads
|
|
46
|
+
* "pearl; star sapphire" (plan 039, decision 4). An element the rest of the
|
|
47
|
+
* path finds nothing in, or only `null` or `""`, is left out, and a list it
|
|
48
|
+
* finds nothing in at all reads `undefined` rather than "", so a label is
|
|
49
|
+
* blank rather than empty. `*` applied to anything but a list is `undefined`.
|
|
50
|
+
* dot-prop gives `*` no meaning, so a path without one is read by dot-prop
|
|
51
|
+
* alone, exactly as before.
|
|
52
|
+
*
|
|
53
|
+
* One `*` per path, and a second makes the path `undefined`. The data needs
|
|
54
|
+
* no more, and each one multiplies the work by its list's length: through
|
|
55
|
+
* links that loop back, as `pathsFrom.*.to.pathsTo.*.from` does, a short path
|
|
56
|
+
* from a query string would read millions of rows and freeze the page.
|
|
57
|
+
*/
|
|
58
|
+
export function readFieldPath(source, path) {
|
|
59
|
+
try {
|
|
60
|
+
const wildcards = wildcardSegments(path);
|
|
61
|
+
// A `*` inside a longer key, or escaped, is an ordinary key; dot-prop
|
|
62
|
+
// reads it as it always has.
|
|
63
|
+
if (wildcards === 0)
|
|
64
|
+
return getProperty(source, path);
|
|
65
|
+
if (wildcards > 1)
|
|
66
|
+
return undefined;
|
|
67
|
+
const segments = parsePath(path);
|
|
68
|
+
// An escaped `*` beside the wildcard parses to the same segment; rather
|
|
69
|
+
// than guess which is which, the path reads nothing. A path with a
|
|
70
|
+
// disallowed key parses to no wildcard at all.
|
|
71
|
+
if (segments.filter((segment) => segment === EVERY).length !== 1)
|
|
72
|
+
return undefined;
|
|
73
|
+
return readSegments(source, segments);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** The parsed path read from `source`, with each `*` mapped over its list. */
|
|
80
|
+
function readSegments(source, segments) {
|
|
81
|
+
if (segments.length === 0)
|
|
82
|
+
return source;
|
|
83
|
+
// dot-prop answers a path into a string or a number with the value itself;
|
|
84
|
+
// inside a list that would print an element for a field it does not have.
|
|
85
|
+
if (source === null || typeof source !== "object")
|
|
86
|
+
return undefined;
|
|
87
|
+
const at = segments.indexOf(EVERY);
|
|
88
|
+
if (at === -1)
|
|
89
|
+
return getProperty(source, segments);
|
|
90
|
+
const list = at === 0 ? source : getProperty(source, segments.slice(0, at));
|
|
91
|
+
if (!Array.isArray(list))
|
|
92
|
+
return undefined;
|
|
93
|
+
const rest = segments.slice(at + 1);
|
|
94
|
+
const values = list
|
|
95
|
+
.map((element) => readSegments(element, rest))
|
|
96
|
+
.filter((value) => value !== undefined && value !== null && value !== "");
|
|
97
|
+
return values.length === 0
|
|
98
|
+
? undefined
|
|
99
|
+
: values.join(FIELD_PATH_LIST_SEPARATOR);
|
|
100
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { TreePathAttribution } from "./TreeOfLife.tsx";
|
|
2
|
+
/**
|
|
3
|
+
* What `pathTitle` reads of a path: each attribution's letter, and the
|
|
4
|
+
* Hermetic Tree's path number and trump. A magick-data path row is one.
|
|
5
|
+
*/
|
|
6
|
+
export type TitledPath = {
|
|
7
|
+
[A in TreePathAttribution]?: {
|
|
8
|
+
hebrewLetter?: {
|
|
9
|
+
letter?: {
|
|
10
|
+
name: string;
|
|
11
|
+
he: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
pathNo?: number;
|
|
15
|
+
tarotTitle?: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A sphere's label as the lines it is drawn on. A list, which field paths
|
|
20
|
+
* join with "; " (`stones.*.name.en`), takes a line per item, so "star ruby;
|
|
21
|
+
* turquoise" breaks between the stones and not inside one; anything else
|
|
22
|
+
* breaks at its first space, as the Tree always has. Blank words are
|
|
23
|
+
* dropped, as they always were.
|
|
24
|
+
*/
|
|
25
|
+
export declare function labelLines(text: string): string[];
|
|
26
|
+
/**
|
|
27
|
+
* A path's tooltip, which search engines also read: "Path 31: Shin (ש),
|
|
28
|
+
* Judgement" in the Hermetic attribution, the letter alone in the others.
|
|
29
|
+
*/
|
|
30
|
+
export declare function pathTitle(path: TitledPath, letterAttr: TreePathAttribution): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FIELD_PATH_LIST_SEPARATOR } from "./fieldPath.js";
|
|
2
|
+
/**
|
|
3
|
+
* A sphere's label as the lines it is drawn on. A list, which field paths
|
|
4
|
+
* join with "; " (`stones.*.name.en`), takes a line per item, so "star ruby;
|
|
5
|
+
* turquoise" breaks between the stones and not inside one; anything else
|
|
6
|
+
* breaks at its first space, as the Tree always has. Blank words are
|
|
7
|
+
* dropped, as they always were.
|
|
8
|
+
*/
|
|
9
|
+
export function labelLines(text) {
|
|
10
|
+
if (text.includes(FIELD_PATH_LIST_SEPARATOR))
|
|
11
|
+
return text
|
|
12
|
+
.split(FIELD_PATH_LIST_SEPARATOR)
|
|
13
|
+
.map((item) => item.trim())
|
|
14
|
+
.filter((item) => item !== "");
|
|
15
|
+
const words = text.split(" ").filter((word) => word !== "");
|
|
16
|
+
return words.length > 1 ? [words[0], words.slice(1).join(" ")] : words;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A path's tooltip, which search engines also read: "Path 31: Shin (ש),
|
|
20
|
+
* Judgement" in the Hermetic attribution, the letter alone in the others.
|
|
21
|
+
*/
|
|
22
|
+
export function pathTitle(path, letterAttr) {
|
|
23
|
+
const attribution = path[letterAttr];
|
|
24
|
+
const letter = attribution?.hebrewLetter?.letter;
|
|
25
|
+
if (!letter)
|
|
26
|
+
return "";
|
|
27
|
+
const named = `${letter.name} (${letter.he})`;
|
|
28
|
+
if (letterAttr !== "hermetic")
|
|
29
|
+
return named;
|
|
30
|
+
const { pathNo, tarotTitle } = attribution;
|
|
31
|
+
return `Path ${pathNo}: ${named}${tarotTitle ? `, ${tarotTitle}` : ""}`;
|
|
32
|
+
}
|