compasso 0.3.0 → 0.4.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/README.md +66 -10
- package/dist/chunk-UJVU7B44.js +764 -0
- package/dist/chunk-UJVU7B44.js.map +1 -0
- package/dist/index.cjs +785 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/labels-RtFw9tX1.d.cts +91 -0
- package/dist/labels-RtFw9tX1.d.ts +91 -0
- package/dist/locales/pt-br.cjs +19 -0
- package/dist/locales/pt-br.cjs.map +1 -1
- package/dist/locales/pt-br.d.cts +4 -1
- package/dist/locales/pt-br.d.ts +4 -1
- package/dist/locales/pt-br.js +18 -1
- package/dist/locales/pt-br.js.map +1 -1
- package/dist/org-chart/index.cjs +853 -0
- package/dist/org-chart/index.cjs.map +1 -0
- package/dist/org-chart/index.d.cts +168 -0
- package/dist/org-chart/index.d.ts +168 -0
- package/dist/org-chart/index.js +4 -0
- package/dist/org-chart/index.js.map +1 -0
- package/package.json +28 -11
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { e as OrgChartInput, d as OrgBoxStyle, g as OrgChartTitleLabels, f as OrgChartSvgLabels } from '../labels-RtFw9tX1.js';
|
|
2
|
+
export { O as ORG_CHART_SVG_LABELS_EN, a as ORG_CHART_TITLE_LABELS_EN, b as ORG_REPORT_KINDS, c as ORG_VACANCIES, h as OrgPosition, i as OrgReport, j as OrgReportKind, k as OrgVacancy } from '../labels-RtFw9tX1.js';
|
|
3
|
+
import { P as Point } from '../text-DuO_PwYw.js';
|
|
4
|
+
export { e as estimateTextWidth } from '../text-DuO_PwYw.js';
|
|
5
|
+
|
|
6
|
+
/** Stable machine-readable issue codes (kebab-case; part of the public contract). */
|
|
7
|
+
type OrgChartIssueCode = "duplicate-id" | "unknown-manager" | "unknown-report" | "self-report" | "multiple-managers" | "assistant-has-reports" | "too-many-matrix-edges" | "cycle";
|
|
8
|
+
/**
|
|
9
|
+
* Routing capacity: the max number of dotted (matrix) connections one position can be an
|
|
10
|
+
* endpoint of (as manager OR report). Each such edge must escape that box's edge to a
|
|
11
|
+
* box-free column at a distinct (column, exit-y) slot; a finite box edge holds only finitely
|
|
12
|
+
* many clean orthogonal exits, so beyond this the escape columns/exit-rows would collide.
|
|
13
|
+
* 5 is the conservative bound proven collision-free even for the shortest single-line box —
|
|
14
|
+
* a position with more matrix lines than this is rejected rather than misdrawn (the
|
|
15
|
+
* reject-don't-repair doctrine). Realistic matrix orgs sit far below it.
|
|
16
|
+
*/
|
|
17
|
+
declare const ORG_MAX_MATRIX_EDGES_PER_NODE = 5;
|
|
18
|
+
interface OrgChartIssue {
|
|
19
|
+
code: OrgChartIssueCode;
|
|
20
|
+
message: string;
|
|
21
|
+
}
|
|
22
|
+
/** Thrown by computeOrgChartLayout / orgChartSvg on a structurally invalid chart. */
|
|
23
|
+
declare class OrgChartValidationError extends Error {
|
|
24
|
+
readonly issues: readonly OrgChartIssue[];
|
|
25
|
+
constructor(issues: readonly OrgChartIssue[]);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Computes ALL validation issues for the input, deduplicated and deterministically sorted
|
|
29
|
+
* (code, then message) — array order of `positions`/`reports` never changes the result.
|
|
30
|
+
* Empty input (no positions AND no reports) is valid by definition (the renderer's
|
|
31
|
+
* empty-but-valid SVG case) and reports no issues. A forest (zero/one/many roots) is
|
|
32
|
+
* valid and never reported.
|
|
33
|
+
*/
|
|
34
|
+
declare function orgChartIssues(input: OrgChartInput): readonly OrgChartIssue[];
|
|
35
|
+
/** Throws OrgChartValidationError (carrying ALL issues) when the input is invalid. */
|
|
36
|
+
declare function validateOrgChart(input: OrgChartInput): void;
|
|
37
|
+
|
|
38
|
+
/** Name line font size (px). */
|
|
39
|
+
declare const ORG_LABEL_FONT = 12;
|
|
40
|
+
/** Title + subtitle + vacant marker font size (px). */
|
|
41
|
+
declare const ORG_TITLE_FONT = 10;
|
|
42
|
+
/** Line height for stacked label lines inside a box (px). */
|
|
43
|
+
declare const ORG_LABEL_LINE_H = 14;
|
|
44
|
+
declare const ORG_STEM_ID_BASE = 1000000;
|
|
45
|
+
declare const ORG_BUS_ID_BASE = 2000000;
|
|
46
|
+
declare const ORG_DROP_ID_BASE = 3000000;
|
|
47
|
+
declare const ORG_ASSIST_ID_BASE = 4000000;
|
|
48
|
+
declare const ORG_DOTTED_ID_BASE = 5000000;
|
|
49
|
+
type OrgElementKind = "stem" | "bus" | "drop" | "assist" | "dotted";
|
|
50
|
+
interface OrgNode {
|
|
51
|
+
positionId: number;
|
|
52
|
+
/** Box center x. */
|
|
53
|
+
cx: number;
|
|
54
|
+
/** Box top y. */
|
|
55
|
+
top: number;
|
|
56
|
+
boxW: number;
|
|
57
|
+
boxH: number;
|
|
58
|
+
/** "solid" = filled, "dashed" = vacant (presentation-only derived value). */
|
|
59
|
+
style: OrgBoxStyle;
|
|
60
|
+
/** Wrapped display lines per family (drawn centered, stacked, by font size). */
|
|
61
|
+
nameLines: string[];
|
|
62
|
+
titleLines: string[];
|
|
63
|
+
subtitleLines: string[];
|
|
64
|
+
/** Localized "(vago)" marker line; null on filled boxes. */
|
|
65
|
+
vacantMarker: string | null;
|
|
66
|
+
/** True for side-branched assistant nodes (legend + harness use it). */
|
|
67
|
+
isAssistant: boolean;
|
|
68
|
+
/** Depth of the row this node lives in (assistant: its manager's row + 1 band). */
|
|
69
|
+
depth: number;
|
|
70
|
+
/** Verbatim <title> text. */
|
|
71
|
+
title: string;
|
|
72
|
+
}
|
|
73
|
+
interface OrgElement {
|
|
74
|
+
/** Namespaced id (ORG_*_ID_BASE + managerId / reportId / report.id). */
|
|
75
|
+
edgeId: number;
|
|
76
|
+
kind: OrgElementKind;
|
|
77
|
+
/** ≥2 waypoints, every consecutive pair axis-aligned (H or V). */
|
|
78
|
+
points: Point[];
|
|
79
|
+
/** True only on "dotted" elements. */
|
|
80
|
+
dashed: boolean;
|
|
81
|
+
/** Verbatim <title> text (woven from the title-label pack). */
|
|
82
|
+
title: string;
|
|
83
|
+
}
|
|
84
|
+
interface OrgChartLayout {
|
|
85
|
+
width: number;
|
|
86
|
+
height: number;
|
|
87
|
+
nodes: OrgNode[];
|
|
88
|
+
elements: OrgElement[];
|
|
89
|
+
/** Forest order, ascending id. */
|
|
90
|
+
rootPositionIds: number[];
|
|
91
|
+
}
|
|
92
|
+
interface OrgChartLayoutOptions {
|
|
93
|
+
/** Cap each box's DISPLAY label (compact preview); verbatim text stays in `title`. */
|
|
94
|
+
maxLabelChars?: number;
|
|
95
|
+
/** Locale pack for box/element <title>s — English default; see locale packs. */
|
|
96
|
+
titleLabels?: OrgChartTitleLabels;
|
|
97
|
+
}
|
|
98
|
+
/** A node's own symmetric-or-asymmetric half-extents plus its children's half-extents. */
|
|
99
|
+
interface PackNode {
|
|
100
|
+
ownHalfL: number;
|
|
101
|
+
ownHalfR: number;
|
|
102
|
+
/** One entry per child, in placement order; empty = leaf. */
|
|
103
|
+
children: {
|
|
104
|
+
halfL: number;
|
|
105
|
+
halfR: number;
|
|
106
|
+
}[];
|
|
107
|
+
}
|
|
108
|
+
interface PackGaps {
|
|
109
|
+
siblingGap: number;
|
|
110
|
+
}
|
|
111
|
+
interface PackResult {
|
|
112
|
+
/** Subtree half-extents (cover the ENTIRE subtree). */
|
|
113
|
+
halfL: number;
|
|
114
|
+
halfR: number;
|
|
115
|
+
/** Center offset of each child relative to this node's center (parallel to children). */
|
|
116
|
+
offsets: number[];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Span-packs a node's children into disjoint horizontal intervals (the fault-tree `pack`
|
|
120
|
+
* transposed top-down). Children c1..cn: x1 = 0; x_{i+1} = x_i + halfR_i + siblingGap +
|
|
121
|
+
* halfL_{i+1}. Parent axis a = (x1 + xn)/2 — centered over its line-report block. The
|
|
122
|
+
* returned offsets are each child's center MINUS the parent axis. Subtree halfL/halfR
|
|
123
|
+
* extend ownHalf* to cover the children block. Pure + deterministic.
|
|
124
|
+
*/
|
|
125
|
+
declare function packSubtree(node: PackNode, gaps: PackGaps): PackResult;
|
|
126
|
+
/**
|
|
127
|
+
* Deterministic, overlap-proof org-chart layout (pure function of the inputs). Validates
|
|
128
|
+
* first and THROWS OrgChartValidationError on a structurally invalid chart — never
|
|
129
|
+
* sanitizes. Empty input (no positions AND no reports) yields an empty, padded layout.
|
|
130
|
+
*/
|
|
131
|
+
declare function computeOrgChartLayout(input: OrgChartInput, opts?: OrgChartLayoutOptions): OrgChartLayout;
|
|
132
|
+
|
|
133
|
+
interface OrgChartSvgOptions {
|
|
134
|
+
/** Set false to suppress the legend (compact preview); default true. */
|
|
135
|
+
legend?: boolean;
|
|
136
|
+
/** Display vocabulary (legend/accessibility) — English default; see locale packs. */
|
|
137
|
+
labels?: OrgChartSvgLabels;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Emits a self-contained SVG for a computed org-chart layout. Pure + deterministic.
|
|
141
|
+
* Coordinates come straight from the layout; all interpolated text is XML-escaped; all
|
|
142
|
+
* presentation attributes are literal. The legend lists ONLY the features actually
|
|
143
|
+
* present (a solid line, an assistant, a dotted edge, a vacant box), in canonical order.
|
|
144
|
+
*/
|
|
145
|
+
declare function orgChartLayoutSvg(layout: OrgChartLayout, opts?: OrgChartSvgOptions): string;
|
|
146
|
+
|
|
147
|
+
interface OrgChartRenderOptions extends OrgChartLayoutOptions {
|
|
148
|
+
/** Set false to suppress the legend (compact preview); default true. */
|
|
149
|
+
legend?: boolean;
|
|
150
|
+
/** Display vocabulary for the emitter (legend/accessibility) — English default. */
|
|
151
|
+
svgLabels?: OrgChartSvgLabels;
|
|
152
|
+
}
|
|
153
|
+
interface OrgChartRenderResult {
|
|
154
|
+
/** Self-contained SVG (numeric width/height + matching viewBox — PDF-embedder safe). */
|
|
155
|
+
svg: string;
|
|
156
|
+
/** The computed layout, for callers that decorate or hit-test the diagram. */
|
|
157
|
+
layout: OrgChartLayout;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Renders an org-chart input to a self-contained SVG string. Deterministic: same data →
|
|
161
|
+
* same SVG (array order never matters; sibling order among reports is the ascending
|
|
162
|
+
* reportId). Throws OrgChartValidationError — carrying EVERY issue, deterministically
|
|
163
|
+
* sorted — on a structurally invalid chart. Empty input yields an empty-but-valid SVG;
|
|
164
|
+
* callers decide their own empty state.
|
|
165
|
+
*/
|
|
166
|
+
declare function orgChartSvg(input: OrgChartInput, opts?: OrgChartRenderOptions): OrgChartRenderResult;
|
|
167
|
+
|
|
168
|
+
export { ORG_ASSIST_ID_BASE, ORG_BUS_ID_BASE, ORG_DOTTED_ID_BASE, ORG_DROP_ID_BASE, ORG_LABEL_FONT, ORG_LABEL_LINE_H, ORG_MAX_MATRIX_EDGES_PER_NODE, ORG_STEM_ID_BASE, ORG_TITLE_FONT, OrgBoxStyle, OrgChartInput, type OrgChartIssue, type OrgChartIssueCode, type OrgChartLayout, type OrgChartLayoutOptions, type OrgChartRenderOptions, type OrgChartRenderResult, OrgChartSvgLabels, type OrgChartSvgOptions, OrgChartTitleLabels, OrgChartValidationError, type OrgElement, type OrgElementKind, type OrgNode, type PackGaps, type PackNode, type PackResult, Point, computeOrgChartLayout, orgChartIssues, orgChartLayoutSvg, orgChartSvg, packSubtree, validateOrgChart };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ORG_ASSIST_ID_BASE, ORG_BUS_ID_BASE, ORG_CHART_SVG_LABELS_EN, ORG_CHART_TITLE_LABELS_EN, ORG_DOTTED_ID_BASE, ORG_DROP_ID_BASE, ORG_LABEL_FONT, ORG_LABEL_LINE_H, ORG_MAX_MATRIX_EDGES_PER_NODE, ORG_REPORT_KINDS, ORG_STEM_ID_BASE, ORG_TITLE_FONT, ORG_VACANCIES, OrgChartValidationError, computeOrgChartLayout, orgChartIssues, orgChartLayoutSvg, orgChartSvg, packSubtree, validateOrgChart } from '../chunk-UJVU7B44.js';
|
|
2
|
+
export { estimateTextWidth } from '../chunk-O3BT2O42.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "compasso",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Standards-faithful relational and analytical diagrams (genogram, ecomap, fault tree, fishbone, pedigree, phylogenetic tree) as pure SVG strings. Deterministic, zero dependencies, server-safe.",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Standards-faithful relational and analytical diagrams (genogram, ecomap, fault tree, fishbone, pedigree, phylogenetic tree, org chart) as pure SVG strings. Deterministic, zero dependencies, server-safe.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Victor Canô",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/
|
|
9
|
+
"url": "git+https://github.com/Tchori-Labs/compasso.git"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
12
|
"sideEffects": false,
|
|
@@ -94,6 +94,16 @@
|
|
|
94
94
|
"default": "./dist/phylo/index.cjs"
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
|
+
"./org-chart": {
|
|
98
|
+
"import": {
|
|
99
|
+
"types": "./dist/org-chart/index.d.ts",
|
|
100
|
+
"default": "./dist/org-chart/index.js"
|
|
101
|
+
},
|
|
102
|
+
"require": {
|
|
103
|
+
"types": "./dist/org-chart/index.d.cts",
|
|
104
|
+
"default": "./dist/org-chart/index.cjs"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
97
107
|
"./locales/pt-br": {
|
|
98
108
|
"import": {
|
|
99
109
|
"types": "./dist/locales/pt-br.d.ts",
|
|
@@ -108,6 +118,15 @@
|
|
|
108
118
|
"files": [
|
|
109
119
|
"dist"
|
|
110
120
|
],
|
|
121
|
+
"scripts": {
|
|
122
|
+
"build": "tsup",
|
|
123
|
+
"test": "vitest run",
|
|
124
|
+
"test:watch": "vitest",
|
|
125
|
+
"test:update": "vitest run -u",
|
|
126
|
+
"typecheck": "tsc --noEmit",
|
|
127
|
+
"prepublishOnly": "pnpm typecheck && pnpm test && pnpm build",
|
|
128
|
+
"lint": "eslint ."
|
|
129
|
+
},
|
|
111
130
|
"keywords": [
|
|
112
131
|
"genogram",
|
|
113
132
|
"ecomap",
|
|
@@ -119,6 +138,10 @@
|
|
|
119
138
|
"phylogenetics",
|
|
120
139
|
"cladogram",
|
|
121
140
|
"phylogram",
|
|
141
|
+
"org-chart",
|
|
142
|
+
"organogram",
|
|
143
|
+
"organizational-chart",
|
|
144
|
+
"hierarchy",
|
|
122
145
|
"svg",
|
|
123
146
|
"diagram",
|
|
124
147
|
"mcgoldrick",
|
|
@@ -128,6 +151,7 @@
|
|
|
128
151
|
"engines": {
|
|
129
152
|
"node": ">=18"
|
|
130
153
|
},
|
|
154
|
+
"packageManager": "pnpm@10.33.2",
|
|
131
155
|
"devDependencies": {
|
|
132
156
|
"@types/node": "^24",
|
|
133
157
|
"eslint": "^10.4.1",
|
|
@@ -135,12 +159,5 @@
|
|
|
135
159
|
"typescript": "^5",
|
|
136
160
|
"typescript-eslint": "^8.61.0",
|
|
137
161
|
"vitest": "4.1.8"
|
|
138
|
-
},
|
|
139
|
-
"scripts": {
|
|
140
|
-
"build": "tsup",
|
|
141
|
-
"test": "vitest run",
|
|
142
|
-
"test:watch": "vitest",
|
|
143
|
-
"typecheck": "tsc --noEmit",
|
|
144
|
-
"lint": "eslint ."
|
|
145
162
|
}
|
|
146
|
-
}
|
|
163
|
+
}
|