@issuegraph/viewer 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.
Files changed (67) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +156 -0
  3. package/dist/clusters.d.ts +34 -0
  4. package/dist/clusters.d.ts.map +1 -0
  5. package/dist/clusters.js +195 -0
  6. package/dist/clusters.js.map +1 -0
  7. package/dist/document.d.ts +190 -0
  8. package/dist/document.d.ts.map +1 -0
  9. package/dist/document.js +308 -0
  10. package/dist/document.js.map +1 -0
  11. package/dist/element.d.ts +95 -0
  12. package/dist/element.d.ts.map +1 -0
  13. package/dist/element.js +174 -0
  14. package/dist/element.js.map +1 -0
  15. package/dist/index.d.ts +40 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +33 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/layout.d.ts +122 -0
  20. package/dist/layout.d.ts.map +1 -0
  21. package/dist/layout.js +297 -0
  22. package/dist/layout.js.map +1 -0
  23. package/dist/mount.d.ts +64 -0
  24. package/dist/mount.d.ts.map +1 -0
  25. package/dist/mount.js +402 -0
  26. package/dist/mount.js.map +1 -0
  27. package/dist/navigation.d.ts +56 -0
  28. package/dist/navigation.d.ts.map +1 -0
  29. package/dist/navigation.js +121 -0
  30. package/dist/navigation.js.map +1 -0
  31. package/dist/parts.d.ts +89 -0
  32. package/dist/parts.d.ts.map +1 -0
  33. package/dist/parts.js +214 -0
  34. package/dist/parts.js.map +1 -0
  35. package/dist/projections/graph.d.ts +30 -0
  36. package/dist/projections/graph.d.ts.map +1 -0
  37. package/dist/projections/graph.js +644 -0
  38. package/dist/projections/graph.js.map +1 -0
  39. package/dist/projections/linear.d.ts +35 -0
  40. package/dist/projections/linear.d.ts.map +1 -0
  41. package/dist/projections/linear.js +157 -0
  42. package/dist/projections/linear.js.map +1 -0
  43. package/dist/projections/tree.d.ts +17 -0
  44. package/dist/projections/tree.d.ts.map +1 -0
  45. package/dist/projections/tree.js +209 -0
  46. package/dist/projections/tree.js.map +1 -0
  47. package/dist/render.d.ts +35 -0
  48. package/dist/render.d.ts.map +1 -0
  49. package/dist/render.js +45 -0
  50. package/dist/render.js.map +1 -0
  51. package/dist/scene.d.ts +94 -0
  52. package/dist/scene.d.ts.map +1 -0
  53. package/dist/scene.js +48 -0
  54. package/dist/scene.js.map +1 -0
  55. package/dist/styles.d.ts +17 -0
  56. package/dist/styles.d.ts.map +1 -0
  57. package/dist/styles.js +389 -0
  58. package/dist/styles.js.map +1 -0
  59. package/dist/theme.d.ts +71 -0
  60. package/dist/theme.d.ts.map +1 -0
  61. package/dist/theme.js +169 -0
  62. package/dist/theme.js.map +1 -0
  63. package/dist/vocabulary.d.ts +107 -0
  64. package/dist/vocabulary.d.ts.map +1 -0
  65. package/dist/vocabulary.js +98 -0
  66. package/dist/vocabulary.js.map +1 -0
  67. package/package.json +56 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # @issuegraph/viewer
2
+
3
+ Render an [Issuegraph](https://github.com/autnmy/issuegraph) document as a **work order** — the ordered spine with readiness stations, the five edge treatments, and three projections over one normalised document.
4
+
5
+ The innermost UI layer, and the whole of its contract:
6
+
7
+ ```
8
+ in { issues, edges, order } + a projection choice
9
+ out onSelect, onHover
10
+ never fetching, mutation, auth, persistence, or a host's vocabulary
11
+ ```
12
+
13
+ ```sh
14
+ npm install @issuegraph/viewer
15
+ ```
16
+
17
+ Framework-free and bundler-free. One runtime dependency ([`@issuegraph/core`](../core), for the format's field names), no CSS import, and an entry that loads on a bare Node runtime.
18
+
19
+ ## Two entry points
20
+
21
+ ```ts
22
+ import { renderViewer, mountViewer } from '@issuegraph/viewer';
23
+
24
+ // Pure: markup and styles, for server rendering and for tests.
25
+ const { markup, styles, scene, diagnostics } = renderViewer(document, { projection: 'graph' });
26
+
27
+ // The DOM shell: the same tree as nodes, plus the two callbacks.
28
+ const handle = mountViewer(container, document, {
29
+ projection: 'linear',
30
+ onSelect: (key) => console.log('selected', key),
31
+ onHover: (key) => console.log('hovered', key),
32
+ });
33
+
34
+ handle.setProjection('tree'); // the subject survives; only the representation changes
35
+ handle.destroy(); // removes every listener it added
36
+ ```
37
+
38
+ `mountViewer` reaches no global — it builds into `container.ownerDocument` — which is why the package loads where there is no DOM.
39
+
40
+ ## The document
41
+
42
+ Plain and JSON-safe, so it crosses a wire. It is structurally a projection of what [`@issuegraph/derive`](../derive) returns, which a host maps across in a few lines:
43
+
44
+ ```ts
45
+ const document = {
46
+ issues: [{ key: '102', title: 'Backfill the ledger', url: '…', open: true, priority: 3 }],
47
+ edges: [{ field: 'blocked-by', from: '101', to: '102' }],
48
+ order: {
49
+ slots: [{ rank: 1, lead: '102', members: ['102'], ready: true, holds: [] }],
50
+ excluded: [{ key: '106', canonical: '105', reason: 'duplicate-of' }],
51
+ },
52
+ };
53
+ ```
54
+
55
+ **The order is an input, never something this computes.** `@issuegraph/derive` owns the derivation; a second implementation here would be a mirror whose input space drifts. Everything the viewer draws was given to it — including titles and deep links, because knowing a tracker's URL shape is exactly the knowledge this layer must not carry.
56
+
57
+ `normalizeDocument` never throws. A hand-built document is untrusted input, so a dangling edge is dropped with a diagnostic rather than taking the render down.
58
+
59
+ **A deep link is checked, not just escaped.** `url` is the one field that becomes an executable surface in the DOM, so only `http:`, `https:`, `mailto:` and relative values are linked — a `javascript:` or `data:` value is dropped with a diagnostic. Escaping the attribute would not have stopped it.
60
+
61
+ ## The three projections
62
+
63
+ | projection | question it answers |
64
+ |---|---|
65
+ | `linear` | what gets worked next — the order as rows. Complete at any size. |
66
+ | `graph` | what surrounds this issue — the spine with gutters and arcs. Bounded; see below. |
67
+ | `tree` | where this work came from — the `decomposed-from` hierarchy. |
68
+
69
+ **Held slots keep their position.** A hold the graph itself imposes renders *inline at the rank the work would have taken*, with `—` for the rank and a dashed station, because "why isn't my P1 running" has to be answerable in place. A hold the runner or tracker imposes is not a fact about the work, earns no rank slot, and collapses into a footer group with duplicates.
70
+
71
+ **The rail sits on the canvas, not above it.** Ranks and readiness stations are HTML — SVG text is not selectable, not reflowable and announces poorly — but they are the labels *for* the spine nodes, so each row is positioned at the coordinates the layout computed for its own node. One stage carries both at the layout's own size, so one SVG unit is one CSS pixel and the two cannot drift; it scrolls rather than shrinking, because shrinking would silently break that alignment.
72
+
73
+ **The graph refuses rather than degrades.** Past 60 nodes it stops drawing and shows connected components as capsules — size, blocking count, cycle flag, chain depth — and past 300 it shows clusters only. Each refusal names the next move. A refusal with a route forward reads as competence; a hairball reads as a bug.
74
+
75
+ ## The edge grammar
76
+
77
+ Every relationship is separable on **four** channels — dash, terminal marker, glyph, and hue — so removing colour entirely leaves all five distinguishable. That is asserted as a property of the table, not claimed about the rendering.
78
+
79
+ | field | dash | terminal | glyph | ordering effect |
80
+ |---|---|---|---|---|
81
+ | `blocked-by` | solid | filled arrow | `⊘` | strict, directed |
82
+ | `serialize-with` | double | none | `⇄` | exclusive, unordered |
83
+ | `together-with` | enclosure | enclosure | `⧉` | shares one rank |
84
+ | `duplicate-of` | dotted | hollow circle | `≡` | never worked |
85
+ | `decomposed-from` | dashed | tee bar | `⑃` | none — provenance only |
86
+
87
+ The `together-with` **connector** lives in this layer, declared deliberately: a click target cannot be added from outside without the viewer knowing where members are.
88
+
89
+ **Two identities, not one.** Every focusable element carries `data-ig-key`, and exactly one element per key does — otherwise focus lands on whichever the renderer emitted first. The enclosure and its connector are decoration painted *behind* the nodes, so they carry `data-ig-group` instead and stay out of the focus index while remaining clickable: `mountViewer` reads both, so a pointer on either still names its slot.
90
+
91
+ ## Theming
92
+
93
+ **Every colour, type and spacing value is a CSS custom property.** The shipped palette is the *default theme*, not the styling — a host retheming it forks nothing.
94
+
95
+ ```ts
96
+ import { defaultTheme, extendTheme, renderViewer, viewerStylesheet } from '@issuegraph/viewer';
97
+
98
+ const paper = extendTheme(defaultTheme, {
99
+ colors: {
100
+ '--ig-bg': '#FBFAF7',
101
+ '--ig-surface': '#FFFFFF',
102
+ '--ig-surface-2': '#F2F0EA',
103
+ '--ig-line': '#D9D4C7',
104
+ '--ig-text': '#1B1A17',
105
+ '--ig-text-body': '#3B3A35',
106
+ '--ig-text-muted': '#5E5B52',
107
+ '--ig-accent': '#0A5B8A',
108
+ '--ig-focus': '#0A5B8A',
109
+ '--ig-station-ready': '#0A5B8A',
110
+ '--ig-station-pending': '#5E5B52',
111
+ '--ig-station-held': '#8A857A',
112
+ '--ig-edge-blocked-by': '#A32020',
113
+ '--ig-edge-serialize-with': '#7A5A00',
114
+ '--ig-edge-together-with': '#0A5B8A',
115
+ '--ig-edge-duplicate-of': '#6B2E9E',
116
+ '--ig-edge-decomposed-from': '#A31257',
117
+ },
118
+ });
119
+
120
+ const { markup, styles } = renderViewer(document, { theme: paper });
121
+ ```
122
+
123
+ That exact theme is the one `acceptance.test.ts` uses, so the example cannot drift from what is tested.
124
+
125
+ **Geometry is theme data too.** `metrics` are numbers, in CSS pixels, and they are what the layout maths reads — so retheming the row height moves the drawing and the stylesheet together rather than only one of them.
126
+
127
+ **The proof that theming is real**: rendering the same document under two themes produces **byte-identical markup** and different styles. If any colour reached the markup, that equality would fail.
128
+
129
+ **CSS ships as a string, not a `.css` file.** An entry that imports CSS cannot be loaded by a bare Node runtime, and a string means no consumer needs a bundler. Install `viewerStylesheet` once and `themeCss(theme)` per theme.
130
+
131
+ ## Accessibility
132
+
133
+ - **WCAG AA, measured.** Every text token clears 4.5:1 against all three surfaces and every edge hue clears the 3:1 non-text bar — asserted against the palette, for the default theme *and* the documented second one.
134
+ - **Colour-blind safe**, by the four-channel rule above.
135
+ - **Keyboard navigable.** `↑` `↓` walk the order, `←` `→` traverse to gutter neighbours, `Enter` or `Space` selects, `Home` and `End` jump to the ends. Movement never wraps: the ends of the order are the ends of the work.
136
+ - **Rank order, never geometric.** The graph places boxes where the geometry puts them and publishes its traversal in *rank* order; recovering an order from coordinates is what the design forbids, and `navigate` cannot see a coordinate.
137
+ - **No graph-theory literacy assumed.** The tree is a nested list announced as one; every relationship carries a written label alongside its glyph.
138
+ - **A nested control keeps its own keyboard.** `keydown` bubbles, so Enter or Space on a row's deep-link chip follows the link rather than selecting the row — a link a keyboard cannot follow is not exposed. Movement keys stay the viewer's, so a reader can still arrow away from a link.
139
+ - **The canvas is a group, not a picture.** `role="img"` would flatten every descendant into one image node and hide the roles and labels that make gutter and held nodes reachable at all.
140
+ - **Plain list semantics, deliberately.** Rows carry a deep-link chip, and `role="option"` / `role="treeitem"` forbid a focusable descendant — so selection is announced with `aria-current` and hierarchy with nesting, which leaves the link legal instead of making it a violation.
141
+
142
+ Navigation is a pure reducer (`navigate`), so the whole key map is testable without a DOM — and the shell has nothing left to get wrong except wiring.
143
+
144
+ ## What this package will not do
145
+
146
+ Fetch, mutate, authenticate, persist, or derive the order. It is layer 1 of a three-layer seam: the **editor** owns everything that mutates and composes this through its public surface, and a host's **chrome** — shell, nav, brand, freshness, links out — stays the host's.
147
+
148
+ The seam test is the acceptance test: strip the editor and the chrome, and the viewer still renders a correct, legible order.
149
+
150
+ ## Versioning
151
+
152
+ `0.x`, and unstable. This tracks a draft specification, so breaking changes before `1.0` are expected and a minor bump may break you — pin exactly if that matters.
153
+
154
+ ---
155
+
156
+ Stewarded by [Autonomy LLC](https://github.com/autnmy). Apache-2.0.
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Connected components, for the graph's refusal mode.
3
+ *
4
+ * Above the node budget the canvas declines to draw a hairball and shows the
5
+ * shape instead: how many components there are, how big each is, how many
6
+ * `blocked-by` edges it carries, whether it contains a cycle, and how deep its
7
+ * longest blocking chain runs. A refusal with a route forward reads as
8
+ * competence; a hairball reads as a bug.
9
+ *
10
+ * Components are undirected — every relationship connects, whatever its
11
+ * direction — while the depth and cycle questions are asked of `blocked-by`
12
+ * alone, because that is the only field that orders anything.
13
+ */
14
+ import type { NormalizedDocument } from './document.ts';
15
+ export interface Cluster {
16
+ /** Members in the document's own key order, so the output is deterministic. */
17
+ readonly members: readonly string[];
18
+ readonly blockedByEdges: number;
19
+ readonly hasCycle: boolean;
20
+ /** The longest `blocked-by` chain, in edges. `0` when nothing blocks. */
21
+ readonly chainDepth: number;
22
+ }
23
+ /** Every component the document declares, largest first, then by first member. */
24
+ export declare function clustersOf(document: NormalizedDocument,
25
+ /**
26
+ * The keys the canvas would actually draw — `layout.nodes`' key set.
27
+ *
28
+ * Passing it makes the returned components a PARTITION of exactly the nodes
29
+ * the refusal counted, which is the property the refusal's own text depends
30
+ * on. Omitting it keeps the older edge-derived reading for callers that are
31
+ * describing a document rather than explaining a refusal.
32
+ */
33
+ drawn?: ReadonlySet<string>): readonly Cluster[];
34
+ //# sourceMappingURL=clusters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clusters.d.ts","sourceRoot":"","sources":["../src/clusters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,MAAM,WAAW,OAAO;IACtB,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,yEAAyE;IACzE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAkID,kFAAkF;AAClF,wBAAgB,UAAU,CACxB,QAAQ,EAAE,kBAAkB;AAC5B;;;;;;;GAOG;AACH,KAAK,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAC1B,SAAS,OAAO,EAAE,CAyCpB"}
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Connected components, for the graph's refusal mode.
3
+ *
4
+ * Above the node budget the canvas declines to draw a hairball and shows the
5
+ * shape instead: how many components there are, how big each is, how many
6
+ * `blocked-by` edges it carries, whether it contains a cycle, and how deep its
7
+ * longest blocking chain runs. A refusal with a route forward reads as
8
+ * competence; a hairball reads as a bug.
9
+ *
10
+ * Components are undirected — every relationship connects, whatever its
11
+ * direction — while the depth and cycle questions are asked of `blocked-by`
12
+ * alone, because that is the only field that orders anything.
13
+ */
14
+ function connectedComponents(document, drawn) {
15
+ const adjacency = new Map();
16
+ const touch = (key) => {
17
+ const existing = adjacency.get(key);
18
+ if (existing !== undefined)
19
+ return existing;
20
+ const created = [];
21
+ adjacency.set(key, created);
22
+ return created;
23
+ };
24
+ for (const edge of document.edges) {
25
+ touch(edge.from).push(edge.to);
26
+ touch(edge.to).push(edge.from);
27
+ }
28
+ const seen = new Set();
29
+ const components = [];
30
+ // Walk in the document's issue order so the component list is stable.
31
+ for (const issue of document.issues) {
32
+ if (seen.has(issue.key))
33
+ continue;
34
+ // AN EDGE-FREE NODE IS A COMPONENT OF ONE, and dropping it broke the only
35
+ // promise the refusal makes. The refusal fires on how many nodes the canvas
36
+ // would DRAW, but the component list was built from nodes that have an
37
+ // EDGE — so an over-budget document with no relationships in it refused to
38
+ // draw and then listed nothing, under a sentence pointing at the list.
39
+ // A partition of the drawn set cannot disagree with the count that
40
+ // triggered it, whatever the document contains.
41
+ if (!adjacency.has(issue.key)) {
42
+ if (drawn !== undefined && drawn.has(issue.key))
43
+ components.push([issue.key]);
44
+ continue;
45
+ }
46
+ // AN EDGE ENDPOINT THE CANVAS DOES NOT DRAW IS STILL NOT DRAWN. `drawn`
47
+ // bounds both arms or it bounds neither, and bounding only the singletons
48
+ // would trade an under-count for an over-count.
49
+ if (drawn !== undefined && !drawn.has(issue.key))
50
+ continue;
51
+ const members = [];
52
+ const stack = [issue.key];
53
+ seen.add(issue.key);
54
+ while (stack.length > 0) {
55
+ const key = stack.pop();
56
+ members.push(key);
57
+ for (const next of adjacency.get(key) ?? []) {
58
+ if (seen.has(next))
59
+ continue;
60
+ seen.add(next);
61
+ stack.push(next);
62
+ }
63
+ }
64
+ members.sort();
65
+ components.push(members);
66
+ }
67
+ return components;
68
+ }
69
+ /**
70
+ * The longest `blocked-by` chain inside one component, and whether that
71
+ * component contains a cycle.
72
+ *
73
+ * A cycle makes "longest chain" undefined, so the walk reports the depth it
74
+ * reached over the acyclic part and says a cycle exists rather than looping or
75
+ * inventing a number. Both facts are useful to a reader; a hang is not.
76
+ */
77
+ function depthAndCycle(members, blockedBy) {
78
+ const memo = new Map();
79
+ const onPath = new Set();
80
+ let hasCycle = false;
81
+ // The edges the discovery pass refused to follow, keyed `from\u0000to` so a
82
+ // cycle through one member does not suppress that member's other edges.
83
+ const backEdges = new Set();
84
+ // ITERATIVE, NOT RECURSIVE. This runs on the graph's REFUSAL path, which is
85
+ // reached precisely because the component is large — so a per-node call frame
86
+ // is a stack overflow waiting for the input the code exists to handle. A long
87
+ // `blocked-by` chain is the ordinary shape of a big backlog, not a pathology.
88
+ for (const start of members) {
89
+ if (memo.has(start))
90
+ continue;
91
+ const stack = [{ key: start, expanded: false }];
92
+ while (stack.length > 0) {
93
+ const frame = stack[stack.length - 1];
94
+ if (memo.has(frame.key)) {
95
+ stack.pop();
96
+ continue;
97
+ }
98
+ if (!frame.expanded) {
99
+ frame.expanded = true;
100
+ onPath.add(frame.key);
101
+ for (const next of blockedBy.get(frame.key) ?? []) {
102
+ if (onPath.has(next)) {
103
+ hasCycle = true;
104
+ // REMEMBER WHICH EDGE CLOSED THE CYCLE, not just that one did. The
105
+ // collecting pass below walks the same adjacency and has no other
106
+ // way to tell a back-edge from an ordinary one, so it counted this
107
+ // edge against a memo that was never written — `?? 0` — and every
108
+ // cycle came out one edge too long. Measured: a two-node cycle
109
+ // published `chainDepth: 2` beside its cycle badge when the longest
110
+ // acyclic chain through it is one edge, and a three-node cycle
111
+ // published 3 for a chain of two.
112
+ backEdges.add(`${frame.key}\u0000${next}`);
113
+ continue;
114
+ }
115
+ if (!memo.has(next))
116
+ stack.push({ key: next, expanded: false });
117
+ }
118
+ continue;
119
+ }
120
+ let best = 0;
121
+ for (const next of blockedBy.get(frame.key) ?? []) {
122
+ // SKIPPED, WHICH ALSO MAKES THE FALLBACK BELOW UNREACHABLE. Every other
123
+ // child was either pushed and memoized or was memoized already, so
124
+ // `?? 0` now covers nothing — it stays only because a missing memo must
125
+ // never silently become a depth of zero if this walk ever changes.
126
+ if (backEdges.has(`${frame.key}\u0000${next}`))
127
+ continue;
128
+ best = Math.max(best, 1 + (memo.get(next) ?? 0));
129
+ }
130
+ memo.set(frame.key, best);
131
+ onPath.delete(frame.key);
132
+ stack.pop();
133
+ }
134
+ }
135
+ let depth = 0;
136
+ for (const member of members)
137
+ depth = Math.max(depth, memo.get(member) ?? 0);
138
+ return { depth, hasCycle };
139
+ }
140
+ /** Every component the document declares, largest first, then by first member. */
141
+ export function clustersOf(document,
142
+ /**
143
+ * The keys the canvas would actually draw — `layout.nodes`' key set.
144
+ *
145
+ * Passing it makes the returned components a PARTITION of exactly the nodes
146
+ * the refusal counted, which is the property the refusal's own text depends
147
+ * on. Omitting it keeps the older edge-derived reading for callers that are
148
+ * describing a document rather than explaining a refusal.
149
+ */
150
+ drawn) {
151
+ const blockedBy = new Map();
152
+ for (const edge of document.edges) {
153
+ if (edge.field !== 'blocked-by')
154
+ continue;
155
+ const existing = blockedBy.get(edge.from);
156
+ if (existing === undefined)
157
+ blockedBy.set(edge.from, [edge.to]);
158
+ else
159
+ existing.push(edge.to);
160
+ }
161
+ const clusters = connectedComponents(document, drawn).map((members) => {
162
+ // SUMMED OFF THE ADJACENCY ABOVE, NOT RE-FILTERED PER COMPONENT. This used to
163
+ // scan the WHOLE edge array once per component, which is quadratic in exactly
164
+ // the shape that reaches it: refusal mode exists for documents too big to
165
+ // draw, and a fragmented one is the worst case — 10,000 disconnected pairs
166
+ // means 10,000 components each scanning 10,000 edges, ~100 million checks to
167
+ // produce a SUMMARY. The refusal would then freeze the browser it was added
168
+ // to protect.
169
+ // The value is identical, not an approximation: `blockedBy` maps each origin
170
+ // to its `blocked-by` targets, members are distinct, and the filter counted
171
+ // exactly the edges whose origin is a member — so summing each member's list
172
+ // length counts the same edges once each. Linear in members, so the whole
173
+ // pass is linear in nodes plus edges.
174
+ let blockedByEdges = 0;
175
+ for (const member of members)
176
+ blockedByEdges += blockedBy.get(member)?.length ?? 0;
177
+ const { depth, hasCycle } = depthAndCycle(members, blockedBy);
178
+ return { members, blockedByEdges, hasCycle, chainDepth: depth };
179
+ });
180
+ // CODE UNITS, NOT `localeCompare`. This package promises deterministic
181
+ // rendering, and `localeCompare` without an explicit locale uses the RUNTIME's
182
+ // default — so a server and a reader's browser can order two equal-sized
183
+ // components differently and produce markup that does not match, which is a
184
+ // hydration mismatch rather than a cosmetic one. The comparison is the same
185
+ // one `document.ts` already uses to canonicalize a symmetric edge's endpoint
186
+ // pair, so the package has one ordering rule rather than two.
187
+ return clusters.sort((a, b) => {
188
+ if (a.members.length !== b.members.length)
189
+ return b.members.length - a.members.length;
190
+ const left = a.members[0] ?? '';
191
+ const right = b.members[0] ?? '';
192
+ return left < right ? -1 : left > right ? 1 : 0;
193
+ });
194
+ }
195
+ //# sourceMappingURL=clusters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clusters.js","sourceRoot":"","sources":["../src/clusters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAaH,SAAS,mBAAmB,CAC1B,QAA4B,EAC5B,KAAsC;IAEtC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC9C,MAAM,KAAK,GAAG,CAAC,GAAW,EAAY,EAAE;QACtC,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,QAAQ,KAAK,SAAS;YAAE,OAAO,QAAQ,CAAC;QAC5C,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC5B,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IACF,KAAK,MAAM,IAAI,IAA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