@squinch/core 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 +202 -0
- package/NOTICE +41 -0
- package/dist/api.d.ts +91 -0
- package/dist/api.js +232 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.js +9 -0
- package/dist/diff/diff.d.ts +30 -0
- package/dist/diff/diff.js +365 -0
- package/dist/fonts.generated.d.ts +1 -0
- package/dist/fonts.generated.js +6 -0
- package/dist/grammar/parser.js +22 -0
- package/dist/grammar/parser.terms.js +115 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/layout/layout.d.ts +197 -0
- package/dist/layout/layout.js +1721 -0
- package/dist/metrics.d.ts +20 -0
- package/dist/metrics.generated.d.ts +4 -0
- package/dist/metrics.generated.js +4 -0
- package/dist/metrics.js +57 -0
- package/dist/model/build.d.ts +8 -0
- package/dist/model/build.js +1343 -0
- package/dist/model/packs.d.ts +13 -0
- package/dist/model/packs.js +29 -0
- package/dist/model/source.d.ts +10 -0
- package/dist/model/source.js +28 -0
- package/dist/model/suggest.d.ts +2 -0
- package/dist/model/suggest.js +24 -0
- package/dist/model/types.d.ts +226 -0
- package/dist/model/types.js +24 -0
- package/dist/packs/node-fs.d.ts +1 -0
- package/dist/packs/node-fs.js +37 -0
- package/dist/packs/registry.d.ts +61 -0
- package/dist/packs/registry.js +122 -0
- package/dist/packs/sanitize.d.ts +12 -0
- package/dist/packs/sanitize.js +127 -0
- package/dist/packs/sysGlyphs.d.ts +2 -0
- package/dist/packs/sysGlyphs.js +21 -0
- package/dist/render/adaptive.d.ts +13 -0
- package/dist/render/adaptive.js +112 -0
- package/dist/render/html/runtime.d.ts +1 -0
- package/dist/render/html/runtime.generated.d.ts +1 -0
- package/dist/render/html/runtime.generated.js +6 -0
- package/dist/render/html/runtime.js +362 -0
- package/dist/render/html.d.ts +39 -0
- package/dist/render/html.js +235 -0
- package/dist/render/svg.d.ts +75 -0
- package/dist/render/svg.js +1403 -0
- package/dist/render/validate.d.ts +4 -0
- package/dist/render/validate.js +9 -0
- package/dist/themes/index.d.ts +84 -0
- package/dist/themes/index.js +90 -0
- package/dist/view/dive.d.ts +55 -0
- package/dist/view/dive.js +57 -0
- package/dist/view/navigate.d.ts +38 -0
- package/dist/view/navigate.js +81 -0
- package/dist/view/resolve.d.ts +92 -0
- package/dist/view/resolve.js +591 -0
- package/fonts/inter-400.ttf +0 -0
- package/fonts/inter-500.ttf +0 -0
- package/fonts/inter-600.ttf +0 -0
- package/fonts/mono-400.ttf +0 -0
- package/metrics.json +510 -0
- package/package.json +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 the Squinch authors
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
@squinch/core
|
|
2
|
+
Copyright 2026 the Squinch authors
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
--------------------------------------------------------------------------------
|
|
7
|
+
Bundled fonts
|
|
8
|
+
--------------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
This package ships font data, and those files are NOT under Apache-2.0:
|
|
11
|
+
|
|
12
|
+
fonts/inter-400.ttf, fonts/inter-500.ttf, fonts/inter-600.ttf
|
|
13
|
+
and the same faces embedded as woff2 data-URIs inside dist/
|
|
14
|
+
|
|
15
|
+
Inter, Copyright 2016 The Inter Project Authors
|
|
16
|
+
(https://github.com/rsms/inter), licensed under the SIL Open Font
|
|
17
|
+
License, Version 1.1.
|
|
18
|
+
|
|
19
|
+
fonts/mono-400.ttf
|
|
20
|
+
and the same face embedded as a woff2 data-URI inside dist/
|
|
21
|
+
|
|
22
|
+
IBM Plex Mono, Copyright 2017 IBM Corp.
|
|
23
|
+
(https://github.com/IBM/plex), licensed under the SIL Open Font
|
|
24
|
+
License, Version 1.1.
|
|
25
|
+
|
|
26
|
+
Both are subsetted, not modified in outline. The OFL requires this notice to
|
|
27
|
+
travel with the font data, which is why it is in the published package and not
|
|
28
|
+
only in the repository.
|
|
29
|
+
|
|
30
|
+
Rendered SVGs embed these faces so that a viewer draws the exact font the
|
|
31
|
+
layout was measured against — see the "Text metrics never come from the
|
|
32
|
+
environment" rule in CLAUDE.md.
|
|
33
|
+
|
|
34
|
+
--------------------------------------------------------------------------------
|
|
35
|
+
Icon artwork
|
|
36
|
+
--------------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
This package depends on @squinch/pack-aws, -azure, -k8s, -logos and -sys. Their
|
|
39
|
+
artwork is third-party and carries its own terms — AWS's is no-derivatives and
|
|
40
|
+
Microsoft's is limited to architecture diagrams, training and documentation.
|
|
41
|
+
Each pack ships its own NOTICE with the full text; none of it is Apache-2.0.
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { buildModel, buildProject, formatDiagnostics, type ProjectFile } from "./model/build.js";
|
|
2
|
+
import { layoutView } from "./layout/layout.js";
|
|
3
|
+
import { renderSVG } from "./render/svg.js";
|
|
4
|
+
export { allFaces, fontFaceCSS } from "./render/svg.js";
|
|
5
|
+
import { validateSVG } from "./render/validate.js";
|
|
6
|
+
import { themes } from "./themes/index.js";
|
|
7
|
+
import { allPackNames, iconIds, iconMeta, iconExists, packExists, iconTitle } from "./model/packs.js";
|
|
8
|
+
import { diffModels, formatDiff, formatDiffMarkdown } from "./diff/diff.js";
|
|
9
|
+
import type { Diagnostic } from "./model/types.js";
|
|
10
|
+
export { buildModel, buildProject, formatDiagnostics, layoutView, renderSVG, validateSVG, themes };
|
|
11
|
+
export { normalizeSource } from "./model/source.js";
|
|
12
|
+
export { allPackNames, iconIds, iconMeta, iconExists, packExists, iconTitle };
|
|
13
|
+
export { diffModels, formatDiff, formatDiffMarkdown };
|
|
14
|
+
export * from "./view/navigate.js";
|
|
15
|
+
export * from "./view/dive.js";
|
|
16
|
+
export { exportHTML } from "./render/html.js";
|
|
17
|
+
export type { HTMLExportOpts, HTMLExportResult } from "./render/html.js";
|
|
18
|
+
export type { Change, ChangeKind, DiffResult, Weight } from "./diff/diff.js";
|
|
19
|
+
/** Diff two projects by source — the common entry point. */
|
|
20
|
+
export declare function diffProjects(before: ProjectFile[], after: ProjectFile[]): import("./diff/diff.js").DiffResult;
|
|
21
|
+
/** Every icon a source references — preload these before rendering in a browser. */
|
|
22
|
+
export declare function iconsUsedBy(files: ProjectFile[] | string): {
|
|
23
|
+
pack: string;
|
|
24
|
+
id: string;
|
|
25
|
+
}[];
|
|
26
|
+
/** Icon search across installed packs — powers `squinch icons search`.
|
|
27
|
+
*
|
|
28
|
+
* Matches every whitespace-separated word of the query against the id *and*
|
|
29
|
+
* the human title, treating `-` as a space. A raw substring test against the
|
|
30
|
+
* id alone is what shipped, and it failed on the most natural query anyone
|
|
31
|
+
* types: "front door", "key vault", "api management", "container registry"
|
|
32
|
+
* and "data factory" all returned nothing while the icons were right there.
|
|
33
|
+
*
|
|
34
|
+
* A canonical id and its alias never both appear — one icon, one row. Callers
|
|
35
|
+
* that want to *show* the short forms (the CLI does, because SKILL.md teaches
|
|
36
|
+
* them and a result of only `azure/key-vaults` reads as proof that
|
|
37
|
+
* `azure/key-vault` doesn't exist) can look them up via `packInfo`. */
|
|
38
|
+
export declare function searchIcons(query: string, pack?: string): string[];
|
|
39
|
+
export type { ProjectFile };
|
|
40
|
+
export type * from "./model/types.js";
|
|
41
|
+
export { HUES } from "./model/types.js";
|
|
42
|
+
export { hueOf } from "./themes/index.js";
|
|
43
|
+
export type { Positioned } from "./layout/layout.js";
|
|
44
|
+
export type { Theme } from "./themes/index.js";
|
|
45
|
+
export interface RenderResult {
|
|
46
|
+
svg?: string;
|
|
47
|
+
diagnostics: Diagnostic[];
|
|
48
|
+
ok: boolean;
|
|
49
|
+
/** Present when the view shows a flow. `steps` counts the hops that actually
|
|
50
|
+
* render *at this altitude* — a step whose endpoints both lift into one card
|
|
51
|
+
* has nothing to draw — so it is the real length of the story, and the bound
|
|
52
|
+
* a viewer should step to. */
|
|
53
|
+
flow?: {
|
|
54
|
+
label: string;
|
|
55
|
+
steps: number;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Views a source declares, with the container each one scopes to (zoom targets). */
|
|
59
|
+
export declare function viewIndex(src: string): {
|
|
60
|
+
name: string;
|
|
61
|
+
scope?: string;
|
|
62
|
+
title?: string;
|
|
63
|
+
auto?: boolean;
|
|
64
|
+
}[];
|
|
65
|
+
/** One-call pipeline: source → SVG for a view (default: first/implicit view). */
|
|
66
|
+
export declare function render(src: string, opts?: {
|
|
67
|
+
view?: string;
|
|
68
|
+
theme?: string;
|
|
69
|
+
embedFonts?: boolean;
|
|
70
|
+
flowStep?: number;
|
|
71
|
+
/** Emit one file carrying both palettes, switched by `prefers-color-scheme`
|
|
72
|
+
* — for embedding somewhere you do not control the background. Requires a
|
|
73
|
+
* theme with a `pairsWith` counterpart. */
|
|
74
|
+
adaptive?: boolean;
|
|
75
|
+
}): Promise<RenderResult>;
|
|
76
|
+
/** Multi-file project pipeline: files merge into one model namespace (SPEC §2). */
|
|
77
|
+
export declare function renderProject(input: ProjectFile[], opts?: {
|
|
78
|
+
view?: string;
|
|
79
|
+
theme?: string;
|
|
80
|
+
embedFonts?: boolean;
|
|
81
|
+
flowStep?: number;
|
|
82
|
+
/** Emit one file carrying both palettes, switched by `prefers-color-scheme`
|
|
83
|
+
* — for embedding somewhere you do not control the background. Requires a
|
|
84
|
+
* theme with a `pairsWith` counterpart. */
|
|
85
|
+
adaptive?: boolean;
|
|
86
|
+
/** Hoist shared definitions out of this SVG — see `RenderOpts.collectDefs`.
|
|
87
|
+
* Used by the interactive HTML export, where every view shares a document
|
|
88
|
+
* and therefore one set of defs. */
|
|
89
|
+
collectDefs?: Map<string, string>;
|
|
90
|
+
defsScope?: string;
|
|
91
|
+
}): Promise<RenderResult>;
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// The pipeline itself: parse → model → layout → render. No host-specific I/O —
|
|
2
|
+
// see index.ts (Node) and browser.ts for how packs get registered.
|
|
3
|
+
import { buildModel, buildProject, formatDiagnostics } from "./model/build.js";
|
|
4
|
+
import { normalizeFiles } from "./model/source.js";
|
|
5
|
+
import { layoutView } from "./layout/layout.js";
|
|
6
|
+
import { renderSVG } from "./render/svg.js";
|
|
7
|
+
// the bundled face inventory — the HTML export hoists it, tests assert against it
|
|
8
|
+
export { allFaces, fontFaceCSS } from "./render/svg.js";
|
|
9
|
+
import { validateSVG } from "./render/validate.js";
|
|
10
|
+
import { mergeAdaptive } from "./render/adaptive.js";
|
|
11
|
+
import { themes } from "./themes/index.js";
|
|
12
|
+
import { allPackNames, iconIds, iconMeta, iconExists, packExists, iconTitle } from "./model/packs.js";
|
|
13
|
+
import { packInfo } from "./packs/registry.js";
|
|
14
|
+
import { diffModels, formatDiff, formatDiffMarkdown } from "./diff/diff.js";
|
|
15
|
+
import { suggest } from "./model/suggest.js";
|
|
16
|
+
export { buildModel, buildProject, formatDiagnostics, layoutView, renderSVG, validateSVG, themes };
|
|
17
|
+
// CRLF → LF, exported for hosts that map core's Loc offsets back into their own
|
|
18
|
+
// buffer: normalize that buffer first, or the positions are off by one per line
|
|
19
|
+
// on a Windows checkout (packages/vscode/src/features.ts is the one that does).
|
|
20
|
+
export { normalizeSource } from "./model/source.js";
|
|
21
|
+
// pack introspection — the editor tooling needs the same view of packs
|
|
22
|
+
// the compiler has (completion lists, hovers, validation).
|
|
23
|
+
export { allPackNames, iconIds, iconMeta, iconExists, packExists, iconTitle };
|
|
24
|
+
// semantic diff (SPEC §diff): model comparison, no layout involved
|
|
25
|
+
export { diffModels, formatDiff, formatDiffMarkdown };
|
|
26
|
+
// altitude navigation (DESIGN §11): scope arithmetic and the dive geometry.
|
|
27
|
+
// Pure, and shared — the playground and the interactive export must perform
|
|
28
|
+
// the same motion, so neither owns a copy of it.
|
|
29
|
+
export * from "./view/navigate.js";
|
|
30
|
+
export * from "./view/dive.js";
|
|
31
|
+
// the interactive export: every view of a project in one self-contained file
|
|
32
|
+
export { exportHTML } from "./render/html.js";
|
|
33
|
+
/** Diff two projects by source — the common entry point. */
|
|
34
|
+
export function diffProjects(before, after) {
|
|
35
|
+
return diffModels(buildProject(before).model, buildProject(after).model);
|
|
36
|
+
}
|
|
37
|
+
/** Every icon a source references — preload these before rendering in a browser. */
|
|
38
|
+
export function iconsUsedBy(files) {
|
|
39
|
+
const project = typeof files === "string" ? [{ name: "input", src: files }] : files;
|
|
40
|
+
const { model } = buildProject(project);
|
|
41
|
+
const refs = new Map();
|
|
42
|
+
for (const n of model.nodes.values()) {
|
|
43
|
+
if (n.icon)
|
|
44
|
+
refs.set(`${n.icon.pack}/${n.icon.id}`, n.icon);
|
|
45
|
+
const b = n.attrs["badge"];
|
|
46
|
+
if (b?.includes("/"))
|
|
47
|
+
refs.set(b, { pack: b.split("/")[0], id: b.split("/")[1] });
|
|
48
|
+
}
|
|
49
|
+
for (const z of model.zones)
|
|
50
|
+
if (z.icon)
|
|
51
|
+
refs.set(`${z.icon.pack}/${z.icon.id}`, z.icon);
|
|
52
|
+
for (const c of model.containers.values()) {
|
|
53
|
+
const g = c.attrs["glyph"];
|
|
54
|
+
if (g?.includes("/"))
|
|
55
|
+
refs.set(g, { pack: g.split("/")[0], id: g.split("/")[1] });
|
|
56
|
+
}
|
|
57
|
+
return [...refs.values()];
|
|
58
|
+
}
|
|
59
|
+
/** Icon search across installed packs — powers `squinch icons search`.
|
|
60
|
+
*
|
|
61
|
+
* Matches every whitespace-separated word of the query against the id *and*
|
|
62
|
+
* the human title, treating `-` as a space. A raw substring test against the
|
|
63
|
+
* id alone is what shipped, and it failed on the most natural query anyone
|
|
64
|
+
* types: "front door", "key vault", "api management", "container registry"
|
|
65
|
+
* and "data factory" all returned nothing while the icons were right there.
|
|
66
|
+
*
|
|
67
|
+
* A canonical id and its alias never both appear — one icon, one row. Callers
|
|
68
|
+
* that want to *show* the short forms (the CLI does, because SKILL.md teaches
|
|
69
|
+
* them and a result of only `azure/key-vaults` reads as proof that
|
|
70
|
+
* `azure/key-vault` doesn't exist) can look them up via `packInfo`. */
|
|
71
|
+
export function searchIcons(query, pack) {
|
|
72
|
+
// Vendors are inconsistent about number — Azure has "Container Registries"
|
|
73
|
+
// and "Data Factories" where everyone searches "container registry" and
|
|
74
|
+
// "data factory" — so both sides are singularized before comparing.
|
|
75
|
+
// Short words are left alone: stemming `sqs` to `sq` makes it match the `sq`
|
|
76
|
+
// inside `postgresql`, and acronyms are exactly what people search by.
|
|
77
|
+
const stem = (w) => w.length < 5 ? w
|
|
78
|
+
: w.endsWith("ies") ? `${w.slice(0, -3)}y`
|
|
79
|
+
: w.endsWith("s") ? w.slice(0, -1)
|
|
80
|
+
: w;
|
|
81
|
+
const norm = (s) => s.toLowerCase().split(/[\s-]+/).filter(Boolean).map(stem).join(" ");
|
|
82
|
+
// A query word that names an installed pack is a filter, not a search term:
|
|
83
|
+
// `sys` should list the sys glyphs and `logos stripe` should look inside
|
|
84
|
+
// logos — matching the literal letters instead surfaced azure's
|
|
85
|
+
// `defender-…-system` rows while the pack itself stayed invisible, which
|
|
86
|
+
// read as "there are no sys icons". Detected on the raw words, before
|
|
87
|
+
// stemming turns `logos` into `logo`; an explicit `pack` argument wins, and
|
|
88
|
+
// the word then stays an ordinary term. With no terms left, every icon in
|
|
89
|
+
// the pack matches — the browsing listing that motivated this.
|
|
90
|
+
let packFilter = pack;
|
|
91
|
+
let rawWords = query.toLowerCase().split(/[\s-]+/).filter(Boolean);
|
|
92
|
+
if (!packFilter) {
|
|
93
|
+
const packWord = rawWords.find((w) => allPackNames().includes(w));
|
|
94
|
+
if (packWord) {
|
|
95
|
+
packFilter = packWord;
|
|
96
|
+
rawWords = rawWords.filter((w) => w !== packWord);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const words = rawWords.map(stem);
|
|
100
|
+
const hits = [];
|
|
101
|
+
for (const name of allPackNames()) {
|
|
102
|
+
if (packFilter && name !== packFilter)
|
|
103
|
+
continue;
|
|
104
|
+
const aliases = packInfo(name)?.aliases ?? {};
|
|
105
|
+
const haystack = (id) => norm(`${id} ${iconTitle(name, id) ?? ""}`);
|
|
106
|
+
const matched = new Set(iconIds(name).filter((id) => words.every((w) => haystack(id).includes(w))));
|
|
107
|
+
for (const id of [...matched].sort()) {
|
|
108
|
+
if (aliases[id] && matched.has(aliases[id]))
|
|
109
|
+
continue; // canonical covers it
|
|
110
|
+
hits.push(`${name}/${id}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return hits.sort();
|
|
114
|
+
}
|
|
115
|
+
// the one colour vocabulary, for editors that complete it and tests that sweep it
|
|
116
|
+
export { HUES } from "./model/types.js";
|
|
117
|
+
export { hueOf } from "./themes/index.js";
|
|
118
|
+
/** Views a source declares, with the container each one scopes to (zoom targets). */
|
|
119
|
+
export function viewIndex(src) {
|
|
120
|
+
const { model } = buildModel(src);
|
|
121
|
+
return model.views.map((v) => ({ name: v.name, scope: v.scope, title: v.title, auto: v.auto }));
|
|
122
|
+
}
|
|
123
|
+
/** One-call pipeline: source → SVG for a view (default: first/implicit view). */
|
|
124
|
+
export async function render(src, opts = {}) {
|
|
125
|
+
return renderProject([{ name: "input", src }], opts);
|
|
126
|
+
}
|
|
127
|
+
/** Multi-file project pipeline: files merge into one model namespace (SPEC §2). */
|
|
128
|
+
export async function renderProject(input, opts = {}) {
|
|
129
|
+
// Normalized here as well as inside buildProject: this is a public entry
|
|
130
|
+
// point, so anything it derives from the source text — today the model, and
|
|
131
|
+
// whatever a later render option reads — sees LF regardless of how the file
|
|
132
|
+
// was checked out (model/source.ts). Idempotent, so the second pass is free.
|
|
133
|
+
const files = normalizeFiles(input);
|
|
134
|
+
const built = buildProject(files);
|
|
135
|
+
if (!built.ok)
|
|
136
|
+
return { diagnostics: built.diagnostics, ok: false };
|
|
137
|
+
let view = opts.view
|
|
138
|
+
? built.model.views.find((v) => v.name === opts.view)
|
|
139
|
+
: built.model.views[0];
|
|
140
|
+
// A view name that doesn't exist used to fall through to the implicit default
|
|
141
|
+
// below: a *different* diagram, rendered successfully, exit 0. In an agent
|
|
142
|
+
// loop driven by exit codes that is the worst possible failure — a typo buys
|
|
143
|
+
// you a plausible picture with none of your view's settings.
|
|
144
|
+
if (opts.view && !view) {
|
|
145
|
+
const names = built.model.views.map((v) => v.name);
|
|
146
|
+
return {
|
|
147
|
+
diagnostics: [
|
|
148
|
+
...built.diagnostics,
|
|
149
|
+
{
|
|
150
|
+
severity: "error",
|
|
151
|
+
message: `unknown view \`${opts.view}\``,
|
|
152
|
+
fix: names.length
|
|
153
|
+
? ((m) => (m ? `did you mean \`${m}\`? ` : "") + `views: ${names.join(", ")}`)(suggest(opts.view, names))
|
|
154
|
+
: "this project declares no views",
|
|
155
|
+
loc: { from: 0, to: 0, line: 1, col: 1 },
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
ok: false,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (!view) {
|
|
162
|
+
// implicit default view: everything (auto view of sole top-level container)
|
|
163
|
+
const first = [...built.model.containers.keys()][0];
|
|
164
|
+
view = {
|
|
165
|
+
name: first ?? "default", scope: first,
|
|
166
|
+
only: [], include: [], includeStar: false, exclude: [], expand: [], expandStar: false, detail: [],
|
|
167
|
+
context: "auto", highlight: [], colors: [], showDescriptions: false, legend: false, notes: [],
|
|
168
|
+
layout: { place: [], routes: [], align: [], channels: [] },
|
|
169
|
+
loc: { from: 0, to: 0, line: 1, col: 1 },
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const themeName = opts.theme ?? view.theme ?? built.model.fileTheme ?? "light";
|
|
173
|
+
const theme = themes[themeName];
|
|
174
|
+
const diagnostics = [...built.diagnostics];
|
|
175
|
+
if (!theme)
|
|
176
|
+
return {
|
|
177
|
+
diagnostics: [...diagnostics, {
|
|
178
|
+
severity: "error",
|
|
179
|
+
message: `unknown theme \`${themeName}\``,
|
|
180
|
+
fix: `available: ${Object.keys(themes).join(", ")}`,
|
|
181
|
+
loc: view.loc,
|
|
182
|
+
}],
|
|
183
|
+
ok: false,
|
|
184
|
+
};
|
|
185
|
+
const { positioned, diagnostics: layoutDiags } = await layoutView(built.model, view, theme.font);
|
|
186
|
+
diagnostics.push(...layoutDiags);
|
|
187
|
+
if (diagnostics.some((d) => d.severity === "error"))
|
|
188
|
+
return { diagnostics, ok: false };
|
|
189
|
+
const flow = positioned.flow
|
|
190
|
+
? {
|
|
191
|
+
label: positioned.flow.label,
|
|
192
|
+
// distinct hops that render *here*, which is what `flowStep` counts
|
|
193
|
+
steps: new Set(Object.values(positioned.flow.byEdge).flat()).size,
|
|
194
|
+
}
|
|
195
|
+
: undefined;
|
|
196
|
+
// One geometry, drawn once per palette. Layout depends on the theme only
|
|
197
|
+
// through its font, and an adaptive pair shares that font — so both draws
|
|
198
|
+
// come off the same `positioned` and cannot disagree about anything but
|
|
199
|
+
// colour. That is what makes folding them into one file safe.
|
|
200
|
+
const draw = (th) => renderSVG(positioned, th, {
|
|
201
|
+
highlight: view.highlight,
|
|
202
|
+
colors: view.colors,
|
|
203
|
+
notes: view.notes,
|
|
204
|
+
showDescriptions: view.showDescriptions,
|
|
205
|
+
legend: view.legend,
|
|
206
|
+
titleblock: view.titleblock,
|
|
207
|
+
title: view.title,
|
|
208
|
+
embedFonts: opts.embedFonts,
|
|
209
|
+
flowStep: opts.flowStep,
|
|
210
|
+
collectDefs: opts.collectDefs,
|
|
211
|
+
defsScope: opts.defsScope,
|
|
212
|
+
});
|
|
213
|
+
let svg = draw(theme);
|
|
214
|
+
if (opts.adaptive) {
|
|
215
|
+
const pair = theme.pairsWith ? themes[theme.pairsWith] : undefined;
|
|
216
|
+
if (!pair) {
|
|
217
|
+
const pairable = Object.values(themes).filter((x) => x.pairsWith).map((x) => x.name);
|
|
218
|
+
return {
|
|
219
|
+
diagnostics: [...diagnostics, {
|
|
220
|
+
severity: "error",
|
|
221
|
+
message: `theme \`${themeName}\` has no dark counterpart to pair with`,
|
|
222
|
+
fix: "an adaptive SVG is a light theme carrying a dark override; " +
|
|
223
|
+
`render one of: ${pairable.join(", ")}`,
|
|
224
|
+
loc: view.loc,
|
|
225
|
+
}],
|
|
226
|
+
ok: false,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
svg = mergeAdaptive(svg, draw(pair));
|
|
230
|
+
}
|
|
231
|
+
return { svg, diagnostics, ok: true, ...(flow ? { flow } : {}) };
|
|
232
|
+
}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Browser entry: everything from the core pipeline, minus the Node pack source.
|
|
2
|
+
// Hosts register packs themselves:
|
|
3
|
+
//
|
|
4
|
+
// import { registerPack, preloadIcons, render } from "@squinch/core/browser";
|
|
5
|
+
// registerPack(manifest, (file) => fetch(`/icons/${file}`).then(r => r.text()));
|
|
6
|
+
// await preloadIcons(iconsUsedBy(source));
|
|
7
|
+
// const { svg } = await render(source, { view, theme });
|
|
8
|
+
export * from "./api.js";
|
|
9
|
+
export { registerPack, preloadIcons, packInfo, iconIds, hasIcon, glyph } from "./packs/registry.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { SModel } from "../model/types.js";
|
|
2
|
+
export type ChangeKind = "added" | "removed" | "changed";
|
|
3
|
+
export type Weight = "structural" | "cosmetic";
|
|
4
|
+
export interface Change {
|
|
5
|
+
kind: ChangeKind;
|
|
6
|
+
weight: Weight;
|
|
7
|
+
/** what sort of thing changed — node, edge, zone… */
|
|
8
|
+
subject: "system" | "container" | "node" | "edge" | "zone" | "flow" | "view";
|
|
9
|
+
/** stable identity of the thing (path, edge signature, view name…) */
|
|
10
|
+
id: string;
|
|
11
|
+
/** one-line human summary */
|
|
12
|
+
detail: string;
|
|
13
|
+
/** set on `changed`: what it was, and what it now is */
|
|
14
|
+
before?: string;
|
|
15
|
+
after?: string;
|
|
16
|
+
/** `possible rename of x` — a hint, never an assumption */
|
|
17
|
+
note?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface DiffResult {
|
|
20
|
+
changes: Change[];
|
|
21
|
+
structural: number;
|
|
22
|
+
cosmetic: number;
|
|
23
|
+
/** true when the two models are semantically identical */
|
|
24
|
+
same: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function diffModels(before: SModel, after: SModel): DiffResult;
|
|
27
|
+
/** Human-readable report, grouped by weight. */
|
|
28
|
+
export declare function formatDiff(d: DiffResult): string;
|
|
29
|
+
/** Markdown for a PR comment. */
|
|
30
|
+
export declare function formatDiffMarkdown(d: DiffResult): string;
|