@nowline/browser 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/LICENSE +190 -0
- package/dist/diagnostic-row.d.ts +68 -0
- package/dist/diagnostic-row.d.ts.map +1 -0
- package/dist/diagnostic-row.js +95 -0
- package/dist/diagnostic-row.js.map +1 -0
- package/dist/generated/showcase.d.ts +2 -0
- package/dist/generated/showcase.d.ts.map +1 -0
- package/dist/generated/showcase.js +5 -0
- package/dist/generated/showcase.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/no-op-include-resolver.d.ts +22 -0
- package/dist/no-op-include-resolver.d.ts.map +1 -0
- package/dist/no-op-include-resolver.js +20 -0
- package/dist/no-op-include-resolver.js.map +1 -0
- package/dist/pipeline.d.ts +96 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +131 -0
- package/dist/pipeline.js.map +1 -0
- package/package.json +62 -0
- package/src/diagnostic-row.ts +145 -0
- package/src/generated/showcase.ts +5 -0
- package/src/index.ts +38 -0
- package/src/no-op-include-resolver.ts +30 -0
- package/src/pipeline.ts +238 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
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 the 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 the 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 any 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
|
+
Copyright 2026 Lolay, Inc.
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ResolveDiagnostic } from '@nowline/core';
|
|
2
|
+
/**
|
|
3
|
+
* JSON-friendly diagnostic shape consumed by browser preview surfaces.
|
|
4
|
+
*
|
|
5
|
+
* Single source of truth shared by the VS Code preview's webview table,
|
|
6
|
+
* the embed's error path, and any other browser tool that wants
|
|
7
|
+
* structured Nowline diagnostics. Field semantics mirror VS Code's
|
|
8
|
+
* Problems panel: `line` and `column` are 1-based (the editor displays
|
|
9
|
+
* "Ln 12, Col 5"); `file` is an absolute fs path (or a synthetic
|
|
10
|
+
* embed-side path) so callers can map back to a source location.
|
|
11
|
+
*/
|
|
12
|
+
export interface DiagnosticRow {
|
|
13
|
+
severity: 'error' | 'warning';
|
|
14
|
+
code: string;
|
|
15
|
+
message: string;
|
|
16
|
+
suggestion?: string;
|
|
17
|
+
file: string;
|
|
18
|
+
line: number;
|
|
19
|
+
column: number;
|
|
20
|
+
}
|
|
21
|
+
/** Minimal LSP-style diagnostic shape. Mirrors `LangiumLikeDiagnostic` in the CLI. */
|
|
22
|
+
export interface LangiumLikeDiagnostic {
|
|
23
|
+
message: string;
|
|
24
|
+
severity?: number;
|
|
25
|
+
code?: string | number;
|
|
26
|
+
range?: {
|
|
27
|
+
start: {
|
|
28
|
+
line: number;
|
|
29
|
+
character: number;
|
|
30
|
+
};
|
|
31
|
+
end: {
|
|
32
|
+
line: number;
|
|
33
|
+
character: number;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
interface ChevrotainParserError {
|
|
38
|
+
message: string;
|
|
39
|
+
token?: {
|
|
40
|
+
startLine?: number;
|
|
41
|
+
startColumn?: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
interface ChevrotainLexerError {
|
|
45
|
+
message: string;
|
|
46
|
+
line?: number;
|
|
47
|
+
column?: number;
|
|
48
|
+
}
|
|
49
|
+
export declare function fromLangiumDiagnostic(diag: LangiumLikeDiagnostic, file: string): DiagnosticRow;
|
|
50
|
+
export declare function fromParserError(err: ChevrotainParserError, file: string): DiagnosticRow;
|
|
51
|
+
export declare function fromLexerError(err: ChevrotainLexerError, file: string): DiagnosticRow;
|
|
52
|
+
/**
|
|
53
|
+
* Adapt a `ResolveDiagnostic` (cross-file include resolution). The line
|
|
54
|
+
* is 0-based in the resolver (it comes from a CST range) and may be
|
|
55
|
+
* undefined for whole-file diagnostics like circular include — fall
|
|
56
|
+
* back to line 1 so a click-to-jump still puts the cursor near the top
|
|
57
|
+
* of the offending file.
|
|
58
|
+
*/
|
|
59
|
+
export declare function fromResolveDiagnostic(diag: ResolveDiagnostic): DiagnosticRow;
|
|
60
|
+
/**
|
|
61
|
+
* Adapt a render-time warning message into a diagnostic row. Renderer
|
|
62
|
+
* warnings are bare strings without a source location, so callers
|
|
63
|
+
* supply the source `file`; in `strict` mode the caller upgrades
|
|
64
|
+
* severity to `error` before passing the result on.
|
|
65
|
+
*/
|
|
66
|
+
export declare function fromRenderWarning(message: string, file: string, severity?: DiagnosticRow['severity']): DiagnosticRow;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=diagnostic-row.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostic-row.d.ts","sourceRoot":"","sources":["../src/diagnostic-row.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa;IAC1B,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,sFAAsF;AACtF,MAAM,WAAW,qBAAqB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE;QACJ,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAC;QAC3C,GAAG,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAC;KAC5C,CAAC;CACL;AAED,UAAU,qBAAqB;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE;QACJ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;CACL;AAED,UAAU,oBAAoB;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAID,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CAU9F;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CASvF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CASrF;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,GAAG,aAAa,CAS5E;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC7B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,aAAa,CAAC,UAAU,CAAa,GAChD,aAAa,CASf"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const DID_YOU_MEAN_RE = /did you mean ['"]?([^'"?]+)['"]?\??/i;
|
|
2
|
+
export function fromLangiumDiagnostic(diag, file) {
|
|
3
|
+
return {
|
|
4
|
+
severity: diag.severity === 2 ? 'warning' : 'error',
|
|
5
|
+
code: diagnosticCode(diag),
|
|
6
|
+
message: diag.message,
|
|
7
|
+
suggestion: extractSuggestion(diag.message),
|
|
8
|
+
file,
|
|
9
|
+
line: (diag.range?.start.line ?? 0) + 1,
|
|
10
|
+
column: (diag.range?.start.character ?? 0) + 1,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function fromParserError(err, file) {
|
|
14
|
+
return {
|
|
15
|
+
severity: 'error',
|
|
16
|
+
code: 'parse-error',
|
|
17
|
+
message: err.message,
|
|
18
|
+
file,
|
|
19
|
+
line: err.token?.startLine ?? 1,
|
|
20
|
+
column: err.token?.startColumn ?? 1,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function fromLexerError(err, file) {
|
|
24
|
+
return {
|
|
25
|
+
severity: 'error',
|
|
26
|
+
code: 'lex-error',
|
|
27
|
+
message: err.message,
|
|
28
|
+
file,
|
|
29
|
+
line: err.line ?? 1,
|
|
30
|
+
column: err.column ?? 1,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Adapt a `ResolveDiagnostic` (cross-file include resolution). The line
|
|
35
|
+
* is 0-based in the resolver (it comes from a CST range) and may be
|
|
36
|
+
* undefined for whole-file diagnostics like circular include — fall
|
|
37
|
+
* back to line 1 so a click-to-jump still puts the cursor near the top
|
|
38
|
+
* of the offending file.
|
|
39
|
+
*/
|
|
40
|
+
export function fromResolveDiagnostic(diag) {
|
|
41
|
+
return {
|
|
42
|
+
severity: diag.severity,
|
|
43
|
+
code: 'include',
|
|
44
|
+
message: diag.message,
|
|
45
|
+
file: diag.sourcePath,
|
|
46
|
+
line: diag.line !== undefined ? diag.line + 1 : 1,
|
|
47
|
+
column: 1,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Adapt a render-time warning message into a diagnostic row. Renderer
|
|
52
|
+
* warnings are bare strings without a source location, so callers
|
|
53
|
+
* supply the source `file`; in `strict` mode the caller upgrades
|
|
54
|
+
* severity to `error` before passing the result on.
|
|
55
|
+
*/
|
|
56
|
+
export function fromRenderWarning(message, file, severity = 'warning') {
|
|
57
|
+
return {
|
|
58
|
+
severity,
|
|
59
|
+
code: 'render.warning',
|
|
60
|
+
message,
|
|
61
|
+
file,
|
|
62
|
+
line: 1,
|
|
63
|
+
column: 1,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function diagnosticCode(diag) {
|
|
67
|
+
if (typeof diag.code === 'string' && diag.code !== '')
|
|
68
|
+
return diag.code;
|
|
69
|
+
if (typeof diag.code === 'number')
|
|
70
|
+
return String(diag.code);
|
|
71
|
+
return inferCodeFromMessage(diag.message);
|
|
72
|
+
}
|
|
73
|
+
function inferCodeFromMessage(message) {
|
|
74
|
+
const lower = message.toLowerCase();
|
|
75
|
+
if (lower.includes('duplicate identifier'))
|
|
76
|
+
return 'duplicate-identifier';
|
|
77
|
+
if (lower.includes('unknown reference') || lower.includes('did you mean'))
|
|
78
|
+
return 'unknown-reference';
|
|
79
|
+
if (lower.includes('circular'))
|
|
80
|
+
return 'circular-dependency';
|
|
81
|
+
if (lower.includes('requires') && lower.includes('date:'))
|
|
82
|
+
return 'missing-date';
|
|
83
|
+
if (lower.includes('duration'))
|
|
84
|
+
return 'duration';
|
|
85
|
+
if (lower.includes('include'))
|
|
86
|
+
return 'include';
|
|
87
|
+
if (lower.includes('indent'))
|
|
88
|
+
return 'indentation';
|
|
89
|
+
return 'validation';
|
|
90
|
+
}
|
|
91
|
+
function extractSuggestion(message) {
|
|
92
|
+
const match = message.match(DID_YOU_MEAN_RE);
|
|
93
|
+
return match ? match[1].trim() : undefined;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=diagnostic-row.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostic-row.js","sourceRoot":"","sources":["../src/diagnostic-row.ts"],"names":[],"mappings":"AA+CA,MAAM,eAAe,GAAG,sCAAsC,CAAC;AAE/D,MAAM,UAAU,qBAAqB,CAAC,IAA2B,EAAE,IAAY;IAC3E,OAAO;QACH,QAAQ,EAAE,IAAI,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO;QACnD,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC;QAC1B,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,UAAU,EAAE,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC;QAC3C,IAAI;QACJ,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC;QACvC,MAAM,E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C,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const showcaseSource = "nowline v1\n\nroadmap showcase \"Nowline Showcase\" start:2026-01-05 scale:1m author:\"Nowline\"\n\nanchor kickoff date:2026-01-05\n\nswimlane engineering \"Engineering\"\n item design \"Design spec\" duration:2w after:kickoff status:done\n parallel after:design\n group build \"Build\"\n item api \"API surface\" duration:3w status:in-progress remaining:1w\n item ui \"Web client\" duration:3w status:in-progress remaining:2w\n item integrate \"Integration tests\" duration:2w\n item ship \"Ship\" duration:1w after:integrate\n\nswimlane marketing \"Marketing\"\n item brief \"Launch brief\" duration:1w after:kickoff status:done\n item assets \"Launch assets\" duration:3w after:brief\n item announce \"Announcement\" duration:1w after:ship\n\nmilestone launch \"Launch\" after:[ship, announce]\n";
|
|
2
|
+
//# sourceMappingURL=showcase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"showcase.d.ts","sourceRoot":"","sources":["../../src/generated/showcase.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,yzBAAyzB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// AUTO-GENERATED by `packages/browser/scripts/bundle-showcase.mjs`.
|
|
2
|
+
// Do not edit by hand; this file is regenerated from
|
|
3
|
+
// `examples/showcase.nowline` on every build / test run.
|
|
4
|
+
export const showcaseSource = "nowline v1\n\nroadmap showcase \"Nowline Showcase\" start:2026-01-05 scale:1m author:\"Nowline\"\n\nanchor kickoff date:2026-01-05\n\nswimlane engineering \"Engineering\"\n item design \"Design spec\" duration:2w after:kickoff status:done\n parallel after:design\n group build \"Build\"\n item api \"API surface\" duration:3w status:in-progress remaining:1w\n item ui \"Web client\" duration:3w status:in-progress remaining:2w\n item integrate \"Integration tests\" duration:2w\n item ship \"Ship\" duration:1w after:integrate\n\nswimlane marketing \"Marketing\"\n item brief \"Launch brief\" duration:1w after:kickoff status:done\n item assets \"Launch assets\" duration:3w after:brief\n item announce \"Announcement\" duration:1w after:ship\n\nmilestone launch \"Launch\" after:[ship, announce]\n";
|
|
5
|
+
//# sourceMappingURL=showcase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"showcase.js","sourceRoot":"","sources":["../../src/generated/showcase.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,qDAAqD;AACrD,yDAAyD;AAEzD,MAAM,CAAC,MAAM,cAAc,GAAG,szBAAszB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { type DiagnosticRow, fromLangiumDiagnostic, fromLexerError, fromParserError, fromRenderWarning, fromResolveDiagnostic, type LangiumLikeDiagnostic, } from './diagnostic-row.js';
|
|
2
|
+
export { showcaseSource } from './generated/showcase.js';
|
|
3
|
+
export { isNoOpIncludeDiagnosticMessage, NOWLINE_BROWSER_NOOP_INCLUDE_TAG, noOpIncludeReadFile, type SkippedInclude, } from './no-op-include-resolver.js';
|
|
4
|
+
export { __resetBrowserPipelineForTests, DEFAULT_SYNTHETIC_PATH, type ParseOptions, type ParseResult, parseSource, type RenderOptions, type RenderResult, renderSource, } from './pipeline.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EACH,KAAK,aAAa,EAClB,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,qBAAqB,GAC7B,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EACH,8BAA8B,EAC9B,gCAAgC,EAChC,mBAAmB,EACnB,KAAK,cAAc,GACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACH,8BAA8B,EAC9B,sBAAsB,EACtB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,YAAY,GACf,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Public API for `@nowline/browser`.
|
|
2
|
+
//
|
|
3
|
+
// The package's job is to give every browser-side surface (the embed
|
|
4
|
+
// CDN bundle, the VS Code preview, the Free SPA, and any third-party
|
|
5
|
+
// tool) the same parse → resolveIncludes → layout → render pipeline so
|
|
6
|
+
// behaviour cannot drift between them. Surface-specific concerns (DOM
|
|
7
|
+
// auto-scan, postMessage transport, save/copy commands) belong in the
|
|
8
|
+
// consumer; this package stays a pure data transform.
|
|
9
|
+
export { fromLangiumDiagnostic, fromLexerError, fromParserError, fromRenderWarning, fromResolveDiagnostic, } from './diagnostic-row.js';
|
|
10
|
+
// Showcase source string is generated from `examples/showcase.nowline`
|
|
11
|
+
// by `scripts/bundle-showcase.mjs` (m4.7 slice F) and re-exported here
|
|
12
|
+
// for empty-state content in browser SPAs.
|
|
13
|
+
export { showcaseSource } from './generated/showcase.js';
|
|
14
|
+
export { isNoOpIncludeDiagnosticMessage, NOWLINE_BROWSER_NOOP_INCLUDE_TAG, noOpIncludeReadFile, } from './no-op-include-resolver.js';
|
|
15
|
+
export { __resetBrowserPipelineForTests, DEFAULT_SYNTHETIC_PATH, parseSource, renderSource, } from './pipeline.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,EAAE;AACF,qEAAqE;AACrE,qEAAqE;AACrE,uEAAuE;AACvE,sEAAsE;AACtE,sEAAsE;AACtE,sDAAsD;AAEtD,OAAO,EAEH,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,qBAAqB,GAExB,MAAM,qBAAqB,CAAC;AAC7B,uEAAuE;AACvE,uEAAuE;AACvE,2CAA2C;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EACH,8BAA8B,EAC9B,gCAAgC,EAChC,mBAAmB,GAEtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACH,8BAA8B,EAC9B,sBAAsB,EAGtB,WAAW,EAGX,YAAY,GACf,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side `readFile` that always rejects with a stable, sniff-able
|
|
3
|
+
* error tag. The pipeline catches matching include diagnostics and
|
|
4
|
+
* surfaces them through the `onSkippedInclude` callback so callers can
|
|
5
|
+
* implement their own warn-once-per-page behaviour without inheriting
|
|
6
|
+
* a `console.warn` side effect from this package.
|
|
7
|
+
*
|
|
8
|
+
* A real HTTP-fetch resolver is intentionally out of scope here (see
|
|
9
|
+
* `specs/handoffs/handoff-m4-embed.md`): CORS, relative-URL semantics,
|
|
10
|
+
* and waterfall performance each warrant their own decision and are
|
|
11
|
+
* best handled behind an opt-in flag in a follow-up.
|
|
12
|
+
*/
|
|
13
|
+
export declare const NOWLINE_BROWSER_NOOP_INCLUDE_TAG = "__nowline_browser_noop_include__";
|
|
14
|
+
export declare function noOpIncludeReadFile(absPath: string): Promise<string>;
|
|
15
|
+
export declare function isNoOpIncludeDiagnosticMessage(message: string): boolean;
|
|
16
|
+
export interface SkippedInclude {
|
|
17
|
+
/** Absolute path of the include that was skipped. */
|
|
18
|
+
sourcePath: string;
|
|
19
|
+
/** The diagnostic message verbatim, including the sniff tag. */
|
|
20
|
+
message: string;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=no-op-include-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-op-include-resolver.d.ts","sourceRoot":"","sources":["../src/no-op-include-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gCAAgC,qCAAqC,CAAC;AAEnF,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAI1E;AAED,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED,MAAM,WAAW,cAAc;IAC3B,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side `readFile` that always rejects with a stable, sniff-able
|
|
3
|
+
* error tag. The pipeline catches matching include diagnostics and
|
|
4
|
+
* surfaces them through the `onSkippedInclude` callback so callers can
|
|
5
|
+
* implement their own warn-once-per-page behaviour without inheriting
|
|
6
|
+
* a `console.warn` side effect from this package.
|
|
7
|
+
*
|
|
8
|
+
* A real HTTP-fetch resolver is intentionally out of scope here (see
|
|
9
|
+
* `specs/handoffs/handoff-m4-embed.md`): CORS, relative-URL semantics,
|
|
10
|
+
* and waterfall performance each warrant their own decision and are
|
|
11
|
+
* best handled behind an opt-in flag in a follow-up.
|
|
12
|
+
*/
|
|
13
|
+
export const NOWLINE_BROWSER_NOOP_INCLUDE_TAG = '__nowline_browser_noop_include__';
|
|
14
|
+
export async function noOpIncludeReadFile(absPath) {
|
|
15
|
+
throw new Error(`${NOWLINE_BROWSER_NOOP_INCLUDE_TAG}: include "${absPath}" was skipped — running in single-file mode.`);
|
|
16
|
+
}
|
|
17
|
+
export function isNoOpIncludeDiagnosticMessage(message) {
|
|
18
|
+
return message.includes(NOWLINE_BROWSER_NOOP_INCLUDE_TAG);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=no-op-include-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-op-include-resolver.js","sourceRoot":"","sources":["../src/no-op-include-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,kCAAkC,CAAC;AAEnF,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAAe;IACrD,MAAM,IAAI,KAAK,CACX,GAAG,gCAAgC,cAAc,OAAO,8CAA8C,CACzG,CAAC;AACN,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,OAAe;IAC1D,OAAO,OAAO,CAAC,QAAQ,CAAC,gCAAgC,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type NowlineFile } from '@nowline/core';
|
|
2
|
+
import { type ThemeName } from '@nowline/layout';
|
|
3
|
+
import { type AssetResolver } from '@nowline/renderer';
|
|
4
|
+
import { type DiagnosticRow } from './diagnostic-row.js';
|
|
5
|
+
import { type SkippedInclude } from './no-op-include-resolver.js';
|
|
6
|
+
/**
|
|
7
|
+
* Synthetic path stamped on diagnostics that have no real source file
|
|
8
|
+
* (the embed renders strings, not files). Consumers can re-key it to
|
|
9
|
+
* a more user-meaningful label by setting `filePath`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_SYNTHETIC_PATH = "/browser-source.nowline";
|
|
12
|
+
export interface ParseOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Absolute path (or synthetic path) used to seed include resolution
|
|
15
|
+
* and tag parse/validation diagnostics. Defaults to a synthetic
|
|
16
|
+
* `/browser-source.nowline` so embedded blocks have a stable label.
|
|
17
|
+
*/
|
|
18
|
+
filePath?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Callback that resolves an `include "..."` directive to file
|
|
21
|
+
* contents. When omitted, falls back to `noOpIncludeReadFile`
|
|
22
|
+
* (every include is skipped and surfaced via `onSkippedInclude`).
|
|
23
|
+
* VS Code passes a Node `fs.readFile` shim; the embed passes
|
|
24
|
+
* nothing.
|
|
25
|
+
*/
|
|
26
|
+
readFile?: (absPath: string) => Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Fires once per skipped include when the noop reader rejects it.
|
|
29
|
+
* Use this to surface a single page-level warning without coupling
|
|
30
|
+
* the pipeline to `console.warn`.
|
|
31
|
+
*/
|
|
32
|
+
onSkippedInclude?: (info: SkippedInclude) => void;
|
|
33
|
+
}
|
|
34
|
+
export interface ParseResult {
|
|
35
|
+
ast: NowlineFile;
|
|
36
|
+
diagnostics: DiagnosticRow[];
|
|
37
|
+
}
|
|
38
|
+
export interface RenderOptions extends ParseOptions {
|
|
39
|
+
theme?: ThemeName;
|
|
40
|
+
/**
|
|
41
|
+
* "Today" override threaded into the layout engine. Pass an
|
|
42
|
+
* explicit `Date` for deterministic snapshots; pass `null` to
|
|
43
|
+
* suppress the now-line entirely (mirrors the CLI's `--now -`);
|
|
44
|
+
* leave undefined to use `new Date()` per render.
|
|
45
|
+
*/
|
|
46
|
+
today?: Date | null;
|
|
47
|
+
/** BCP-47 locale forwarded to the layout engine for axis labels. */
|
|
48
|
+
locale?: string;
|
|
49
|
+
/** Total canvas width in px. Layout's default is 1280. */
|
|
50
|
+
width?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Override the deterministic id prefix used for in-SVG `<style>`
|
|
53
|
+
* scoping. Multi-block surfaces (auto-scan) supply a fresh prefix
|
|
54
|
+
* per block so two roadmaps cannot bleed styles into each other.
|
|
55
|
+
*/
|
|
56
|
+
idPrefix?: string;
|
|
57
|
+
/** Inverse of the CLI's `--no-links`. When false, link icons are dropped. */
|
|
58
|
+
showLinks?: boolean;
|
|
59
|
+
/** Promote renderer warnings to errors in the diagnostic table. */
|
|
60
|
+
strict?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Asset resolver invoked by the renderer for image references
|
|
63
|
+
* (`icon:` declarations, etc.). When omitted, image assets are
|
|
64
|
+
* silently dropped — match the embed's "no filesystem" posture.
|
|
65
|
+
*/
|
|
66
|
+
assetResolver?: AssetResolver;
|
|
67
|
+
}
|
|
68
|
+
export type RenderResult = {
|
|
69
|
+
kind: 'svg';
|
|
70
|
+
svg: string;
|
|
71
|
+
warnings: DiagnosticRow[];
|
|
72
|
+
} | {
|
|
73
|
+
kind: 'diagnostics';
|
|
74
|
+
diagnostics: DiagnosticRow[];
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Parse + validate the source. Returns the AST plus any diagnostics
|
|
78
|
+
* normalized to the shared {@link DiagnosticRow} shape. Does not run
|
|
79
|
+
* include resolution, layout, or rendering — useful for editor
|
|
80
|
+
* experiences that want diagnostics without paying the render cost.
|
|
81
|
+
*/
|
|
82
|
+
export declare function parseSource(source: string, options?: ParseOptions): Promise<ParseResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Run the full pipeline (parse + validate + resolveIncludes + layout
|
|
85
|
+
* + render) and return either the SVG or a list of diagnostics. The
|
|
86
|
+
* `RenderResult` discriminated union mirrors the CLI's success/failure
|
|
87
|
+
* split so callers can render either path without try/catch plumbing.
|
|
88
|
+
*/
|
|
89
|
+
export declare function renderSource(source: string, options?: RenderOptions): Promise<RenderResult>;
|
|
90
|
+
/**
|
|
91
|
+
* Test-only escape hatch. Resets cached Langium services and the
|
|
92
|
+
* URI counter between cases so a `parseSource` failure in one test
|
|
93
|
+
* doesn't poison the next one's document builder.
|
|
94
|
+
*/
|
|
95
|
+
export declare function __resetBrowserPipelineForTests(): void;
|
|
96
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAmBA,OAAO,EAEH,KAAK,WAAW,EAGnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,KAAK,aAAa,EAAa,MAAM,mBAAmB,CAAC;AAElE,OAAO,EACH,KAAK,aAAa,EAOrB,MAAM,qBAAqB,CAAC;AA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B,OAAO,CAAC,WAAW,CAAC,CAkBtB;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,aAAkB,GAC5B,OAAO,CAAC,YAAY,CAAC,CAyDvB;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,IAAI,IAAI,CAGrD"}
|
package/dist/pipeline.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Browser-safe render pipeline shared by every browser surface that
|
|
2
|
+
// needs to turn `.nowline` source into SVG. Consolidates two prior
|
|
3
|
+
// implementations:
|
|
4
|
+
//
|
|
5
|
+
// - `packages/embed/src/pipeline.ts` (single-file, no Node, throws on
|
|
6
|
+
// error, fires a console.warn the first time an include is skipped).
|
|
7
|
+
// - `packages/vscode-extension/src/preview/render-pipeline.ts` (full
|
|
8
|
+
// options matrix incl. Node-backed include resolver + asset resolver,
|
|
9
|
+
// returns a discriminated union instead of throwing).
|
|
10
|
+
//
|
|
11
|
+
// The seam between them is dependency injection. Callers that have
|
|
12
|
+
// access to a filesystem (VS Code, future Node browsers) supply a
|
|
13
|
+
// `readFile` callback and an `assetResolver`; callers that don't (embed,
|
|
14
|
+
// Free SPA) omit both, get the noop include reader, and receive a
|
|
15
|
+
// `SkippedInclude` callback when an `include` directive is encountered.
|
|
16
|
+
//
|
|
17
|
+
// The package itself imports zero `node:*` modules so the embed esbuild
|
|
18
|
+
// bundle stays free of any Node literal even before tree-shaking.
|
|
19
|
+
import { createNowlineServices, resolveIncludes, } from '@nowline/core';
|
|
20
|
+
import { layoutRoadmap } from '@nowline/layout';
|
|
21
|
+
import { renderSvg } from '@nowline/renderer';
|
|
22
|
+
import { URI } from 'langium';
|
|
23
|
+
import { fromLangiumDiagnostic, fromLexerError, fromParserError, fromRenderWarning, fromResolveDiagnostic, } from './diagnostic-row.js';
|
|
24
|
+
import { isNoOpIncludeDiagnosticMessage, noOpIncludeReadFile, } from './no-op-include-resolver.js';
|
|
25
|
+
/**
|
|
26
|
+
* Synthetic path stamped on diagnostics that have no real source file
|
|
27
|
+
* (the embed renders strings, not files). Consumers can re-key it to
|
|
28
|
+
* a more user-meaningful label by setting `filePath`.
|
|
29
|
+
*/
|
|
30
|
+
export const DEFAULT_SYNTHETIC_PATH = '/browser-source.nowline';
|
|
31
|
+
let cachedServices;
|
|
32
|
+
let docCounter = 0;
|
|
33
|
+
function getServices() {
|
|
34
|
+
if (!cachedServices)
|
|
35
|
+
cachedServices = createNowlineServices();
|
|
36
|
+
return cachedServices;
|
|
37
|
+
}
|
|
38
|
+
function freshUri() {
|
|
39
|
+
// Each render mints a fresh URI; reusing one would let Langium's
|
|
40
|
+
// DocumentBuilder mutate the prior document under us.
|
|
41
|
+
return URI.parse(`memory:///nowline-browser-${++docCounter}.nowline`);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Parse + validate the source. Returns the AST plus any diagnostics
|
|
45
|
+
* normalized to the shared {@link DiagnosticRow} shape. Does not run
|
|
46
|
+
* include resolution, layout, or rendering — useful for editor
|
|
47
|
+
* experiences that want diagnostics without paying the render cost.
|
|
48
|
+
*/
|
|
49
|
+
export async function parseSource(source, options = {}) {
|
|
50
|
+
const filePath = options.filePath ?? DEFAULT_SYNTHETIC_PATH;
|
|
51
|
+
const services = getServices();
|
|
52
|
+
const docFactory = services.shared.workspace.LangiumDocumentFactory;
|
|
53
|
+
const doc = docFactory.fromString(source, freshUri());
|
|
54
|
+
await services.shared.workspace.DocumentBuilder.build([doc], { validation: true });
|
|
55
|
+
const diagnostics = [];
|
|
56
|
+
for (const err of doc.parseResult.lexerErrors) {
|
|
57
|
+
diagnostics.push(fromLexerError(err, filePath));
|
|
58
|
+
}
|
|
59
|
+
for (const err of doc.parseResult.parserErrors) {
|
|
60
|
+
diagnostics.push(fromParserError(err, filePath));
|
|
61
|
+
}
|
|
62
|
+
for (const diag of doc.diagnostics ?? []) {
|
|
63
|
+
diagnostics.push(fromLangiumDiagnostic(diag, filePath));
|
|
64
|
+
}
|
|
65
|
+
return { ast: doc.parseResult.value, diagnostics };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Run the full pipeline (parse + validate + resolveIncludes + layout
|
|
69
|
+
* + render) and return either the SVG or a list of diagnostics. The
|
|
70
|
+
* `RenderResult` discriminated union mirrors the CLI's success/failure
|
|
71
|
+
* split so callers can render either path without try/catch plumbing.
|
|
72
|
+
*/
|
|
73
|
+
export async function renderSource(source, options = {}) {
|
|
74
|
+
const filePath = options.filePath ?? DEFAULT_SYNTHETIC_PATH;
|
|
75
|
+
const parsed = await parseSource(source, { filePath });
|
|
76
|
+
if (parsed.diagnostics.some((d) => d.severity === 'error')) {
|
|
77
|
+
return { kind: 'diagnostics', diagnostics: parsed.diagnostics };
|
|
78
|
+
}
|
|
79
|
+
const services = getServices();
|
|
80
|
+
const readFile = options.readFile ?? noOpIncludeReadFile;
|
|
81
|
+
const resolved = await resolveIncludes(parsed.ast, filePath, {
|
|
82
|
+
services: services.Nowline,
|
|
83
|
+
readFile,
|
|
84
|
+
});
|
|
85
|
+
const rows = [...parsed.diagnostics];
|
|
86
|
+
for (const diag of resolved.diagnostics) {
|
|
87
|
+
if (diag.severity === 'error' && isNoOpIncludeDiagnosticMessage(diag.message)) {
|
|
88
|
+
options.onSkippedInclude?.({
|
|
89
|
+
sourcePath: diag.sourcePath,
|
|
90
|
+
message: diag.message,
|
|
91
|
+
});
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
rows.push(fromResolveDiagnostic(diag));
|
|
95
|
+
}
|
|
96
|
+
if (rows.some((r) => r.severity === 'error')) {
|
|
97
|
+
return { kind: 'diagnostics', diagnostics: rows };
|
|
98
|
+
}
|
|
99
|
+
const today = options.today === null ? undefined : options.today;
|
|
100
|
+
const model = layoutRoadmap(parsed.ast, resolved, {
|
|
101
|
+
theme: options.theme,
|
|
102
|
+
today,
|
|
103
|
+
locale: options.locale,
|
|
104
|
+
width: options.width,
|
|
105
|
+
});
|
|
106
|
+
const showLinks = options.showLinks !== false;
|
|
107
|
+
const strict = options.strict === true;
|
|
108
|
+
const warnMessages = [];
|
|
109
|
+
const svg = await renderSvg(model, {
|
|
110
|
+
idPrefix: options.idPrefix,
|
|
111
|
+
assetResolver: options.assetResolver,
|
|
112
|
+
noLinks: !showLinks,
|
|
113
|
+
strict,
|
|
114
|
+
warn: (msg) => warnMessages.push(msg),
|
|
115
|
+
});
|
|
116
|
+
const warnings = warnMessages.map((m) => fromRenderWarning(m, filePath, strict ? 'error' : 'warning'));
|
|
117
|
+
if (strict && warnings.length > 0) {
|
|
118
|
+
return { kind: 'diagnostics', diagnostics: [...rows, ...warnings] };
|
|
119
|
+
}
|
|
120
|
+
return { kind: 'svg', svg, warnings };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Test-only escape hatch. Resets cached Langium services and the
|
|
124
|
+
* URI counter between cases so a `parseSource` failure in one test
|
|
125
|
+
* doesn't poison the next one's document builder.
|
|
126
|
+
*/
|
|
127
|
+
export function __resetBrowserPipelineForTests() {
|
|
128
|
+
cachedServices = undefined;
|
|
129
|
+
docCounter = 0;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,mEAAmE;AACnE,mBAAmB;AACnB,EAAE;AACF,uEAAuE;AACvE,wEAAwE;AACxE,sEAAsE;AACtE,yEAAyE;AACzE,yDAAyD;AACzD,EAAE;AACF,mEAAmE;AACnE,kEAAkE;AAClE,yEAAyE;AACzE,kEAAkE;AAClE,wEAAwE;AACxE,EAAE;AACF,wEAAwE;AACxE,kEAAkE;AAElE,OAAO,EACH,qBAAqB,EAGrB,eAAe,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAkB,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAsB,SAA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,EAAE,OAAO,CAAC,QAAQ;QAC1B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,OAAO,EAAE,CAAC,SAAS;QACnB,MAAM;QACN,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC;KACxC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACpC,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAC/D,CAAC;IACF,IAAI,MAAM,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC;IACxE,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,8BAA8B;IAC1C,cAAc,GAAG,SAAS,CAAC;IAC3B,UAAU,GAAG,CAAC,CAAC;AACnB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nowline/browser",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Browser-safe Nowline pipeline: parse + validate + resolve includes + layout + render with pluggable I/O hooks. Consumed by @nowline/embed, the VS Code preview, and any third-party browser tool.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=22",
|
|
8
|
+
"pnpm": ">=11"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/",
|
|
22
|
+
"src/"
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/lolay/nowline.git",
|
|
27
|
+
"directory": "packages/browser"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/lolay/nowline",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/lolay/nowline/issues"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"nowline",
|
|
35
|
+
"roadmap",
|
|
36
|
+
"gantt",
|
|
37
|
+
"browser",
|
|
38
|
+
"pipeline"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"langium": "~4.2.4",
|
|
42
|
+
"@nowline/core": "0.4.0",
|
|
43
|
+
"@nowline/layout": "0.4.0",
|
|
44
|
+
"@nowline/renderer": "0.4.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^25.9.1",
|
|
48
|
+
"happy-dom": "^20.9.0",
|
|
49
|
+
"typescript": "^6.0.3",
|
|
50
|
+
"vitest": "^4.1.7"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"prebuild": "node scripts/bundle-showcase.mjs",
|
|
54
|
+
"build": "tsc -b tsconfig.json",
|
|
55
|
+
"watch": "tsc -b tsconfig.json --watch",
|
|
56
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
57
|
+
"pretest": "node scripts/bundle-showcase.mjs",
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"test:watch": "vitest",
|
|
60
|
+
"bundle-showcase": "node scripts/bundle-showcase.mjs"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { ResolveDiagnostic } from '@nowline/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* JSON-friendly diagnostic shape consumed by browser preview surfaces.
|
|
5
|
+
*
|
|
6
|
+
* Single source of truth shared by the VS Code preview's webview table,
|
|
7
|
+
* the embed's error path, and any other browser tool that wants
|
|
8
|
+
* structured Nowline diagnostics. Field semantics mirror VS Code's
|
|
9
|
+
* Problems panel: `line` and `column` are 1-based (the editor displays
|
|
10
|
+
* "Ln 12, Col 5"); `file` is an absolute fs path (or a synthetic
|
|
11
|
+
* embed-side path) so callers can map back to a source location.
|
|
12
|
+
*/
|
|
13
|
+
export interface DiagnosticRow {
|
|
14
|
+
severity: 'error' | 'warning';
|
|
15
|
+
code: string;
|
|
16
|
+
message: string;
|
|
17
|
+
suggestion?: string;
|
|
18
|
+
file: string;
|
|
19
|
+
line: number;
|
|
20
|
+
column: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Minimal LSP-style diagnostic shape. Mirrors `LangiumLikeDiagnostic` in the CLI. */
|
|
24
|
+
export interface LangiumLikeDiagnostic {
|
|
25
|
+
message: string;
|
|
26
|
+
severity?: number;
|
|
27
|
+
code?: string | number;
|
|
28
|
+
range?: {
|
|
29
|
+
start: { line: number; character: number };
|
|
30
|
+
end: { line: number; character: number };
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface ChevrotainParserError {
|
|
35
|
+
message: string;
|
|
36
|
+
token?: {
|
|
37
|
+
startLine?: number;
|
|
38
|
+
startColumn?: number;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface ChevrotainLexerError {
|
|
43
|
+
message: string;
|
|
44
|
+
line?: number;
|
|
45
|
+
column?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const DID_YOU_MEAN_RE = /did you mean ['"]?([^'"?]+)['"]?\??/i;
|
|
49
|
+
|
|
50
|
+
export function fromLangiumDiagnostic(diag: LangiumLikeDiagnostic, file: string): DiagnosticRow {
|
|
51
|
+
return {
|
|
52
|
+
severity: diag.severity === 2 ? 'warning' : 'error',
|
|
53
|
+
code: diagnosticCode(diag),
|
|
54
|
+
message: diag.message,
|
|
55
|
+
suggestion: extractSuggestion(diag.message),
|
|
56
|
+
file,
|
|
57
|
+
line: (diag.range?.start.line ?? 0) + 1,
|
|
58
|
+
column: (diag.range?.start.character ?? 0) + 1,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function fromParserError(err: ChevrotainParserError, file: string): DiagnosticRow {
|
|
63
|
+
return {
|
|
64
|
+
severity: 'error',
|
|
65
|
+
code: 'parse-error',
|
|
66
|
+
message: err.message,
|
|
67
|
+
file,
|
|
68
|
+
line: err.token?.startLine ?? 1,
|
|
69
|
+
column: err.token?.startColumn ?? 1,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function fromLexerError(err: ChevrotainLexerError, file: string): DiagnosticRow {
|
|
74
|
+
return {
|
|
75
|
+
severity: 'error',
|
|
76
|
+
code: 'lex-error',
|
|
77
|
+
message: err.message,
|
|
78
|
+
file,
|
|
79
|
+
line: err.line ?? 1,
|
|
80
|
+
column: err.column ?? 1,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Adapt a `ResolveDiagnostic` (cross-file include resolution). The line
|
|
86
|
+
* is 0-based in the resolver (it comes from a CST range) and may be
|
|
87
|
+
* undefined for whole-file diagnostics like circular include — fall
|
|
88
|
+
* back to line 1 so a click-to-jump still puts the cursor near the top
|
|
89
|
+
* of the offending file.
|
|
90
|
+
*/
|
|
91
|
+
export function fromResolveDiagnostic(diag: ResolveDiagnostic): DiagnosticRow {
|
|
92
|
+
return {
|
|
93
|
+
severity: diag.severity,
|
|
94
|
+
code: 'include',
|
|
95
|
+
message: diag.message,
|
|
96
|
+
file: diag.sourcePath,
|
|
97
|
+
line: diag.line !== undefined ? diag.line + 1 : 1,
|
|
98
|
+
column: 1,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Adapt a render-time warning message into a diagnostic row. Renderer
|
|
104
|
+
* warnings are bare strings without a source location, so callers
|
|
105
|
+
* supply the source `file`; in `strict` mode the caller upgrades
|
|
106
|
+
* severity to `error` before passing the result on.
|
|
107
|
+
*/
|
|
108
|
+
export function fromRenderWarning(
|
|
109
|
+
message: string,
|
|
110
|
+
file: string,
|
|
111
|
+
severity: DiagnosticRow['severity'] = 'warning',
|
|
112
|
+
): DiagnosticRow {
|
|
113
|
+
return {
|
|
114
|
+
severity,
|
|
115
|
+
code: 'render.warning',
|
|
116
|
+
message,
|
|
117
|
+
file,
|
|
118
|
+
line: 1,
|
|
119
|
+
column: 1,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function diagnosticCode(diag: LangiumLikeDiagnostic): string {
|
|
124
|
+
if (typeof diag.code === 'string' && diag.code !== '') return diag.code;
|
|
125
|
+
if (typeof diag.code === 'number') return String(diag.code);
|
|
126
|
+
return inferCodeFromMessage(diag.message);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function inferCodeFromMessage(message: string): string {
|
|
130
|
+
const lower = message.toLowerCase();
|
|
131
|
+
if (lower.includes('duplicate identifier')) return 'duplicate-identifier';
|
|
132
|
+
if (lower.includes('unknown reference') || lower.includes('did you mean'))
|
|
133
|
+
return 'unknown-reference';
|
|
134
|
+
if (lower.includes('circular')) return 'circular-dependency';
|
|
135
|
+
if (lower.includes('requires') && lower.includes('date:')) return 'missing-date';
|
|
136
|
+
if (lower.includes('duration')) return 'duration';
|
|
137
|
+
if (lower.includes('include')) return 'include';
|
|
138
|
+
if (lower.includes('indent')) return 'indentation';
|
|
139
|
+
return 'validation';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function extractSuggestion(message: string): string | undefined {
|
|
143
|
+
const match = message.match(DID_YOU_MEAN_RE);
|
|
144
|
+
return match ? match[1].trim() : undefined;
|
|
145
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// AUTO-GENERATED by `packages/browser/scripts/bundle-showcase.mjs`.
|
|
2
|
+
// Do not edit by hand; this file is regenerated from
|
|
3
|
+
// `examples/showcase.nowline` on every build / test run.
|
|
4
|
+
|
|
5
|
+
export const showcaseSource = "nowline v1\n\nroadmap showcase \"Nowline Showcase\" start:2026-01-05 scale:1m author:\"Nowline\"\n\nanchor kickoff date:2026-01-05\n\nswimlane engineering \"Engineering\"\n item design \"Design spec\" duration:2w after:kickoff status:done\n parallel after:design\n group build \"Build\"\n item api \"API surface\" duration:3w status:in-progress remaining:1w\n item ui \"Web client\" duration:3w status:in-progress remaining:2w\n item integrate \"Integration tests\" duration:2w\n item ship \"Ship\" duration:1w after:integrate\n\nswimlane marketing \"Marketing\"\n item brief \"Launch brief\" duration:1w after:kickoff status:done\n item assets \"Launch assets\" duration:3w after:brief\n item announce \"Announcement\" duration:1w after:ship\n\nmilestone launch \"Launch\" after:[ship, announce]\n";
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Public API for `@nowline/browser`.
|
|
2
|
+
//
|
|
3
|
+
// The package's job is to give every browser-side surface (the embed
|
|
4
|
+
// CDN bundle, the VS Code preview, the Free SPA, and any third-party
|
|
5
|
+
// tool) the same parse → resolveIncludes → layout → render pipeline so
|
|
6
|
+
// behaviour cannot drift between them. Surface-specific concerns (DOM
|
|
7
|
+
// auto-scan, postMessage transport, save/copy commands) belong in the
|
|
8
|
+
// consumer; this package stays a pure data transform.
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
type DiagnosticRow,
|
|
12
|
+
fromLangiumDiagnostic,
|
|
13
|
+
fromLexerError,
|
|
14
|
+
fromParserError,
|
|
15
|
+
fromRenderWarning,
|
|
16
|
+
fromResolveDiagnostic,
|
|
17
|
+
type LangiumLikeDiagnostic,
|
|
18
|
+
} from './diagnostic-row.js';
|
|
19
|
+
// Showcase source string is generated from `examples/showcase.nowline`
|
|
20
|
+
// by `scripts/bundle-showcase.mjs` (m4.7 slice F) and re-exported here
|
|
21
|
+
// for empty-state content in browser SPAs.
|
|
22
|
+
export { showcaseSource } from './generated/showcase.js';
|
|
23
|
+
export {
|
|
24
|
+
isNoOpIncludeDiagnosticMessage,
|
|
25
|
+
NOWLINE_BROWSER_NOOP_INCLUDE_TAG,
|
|
26
|
+
noOpIncludeReadFile,
|
|
27
|
+
type SkippedInclude,
|
|
28
|
+
} from './no-op-include-resolver.js';
|
|
29
|
+
export {
|
|
30
|
+
__resetBrowserPipelineForTests,
|
|
31
|
+
DEFAULT_SYNTHETIC_PATH,
|
|
32
|
+
type ParseOptions,
|
|
33
|
+
type ParseResult,
|
|
34
|
+
parseSource,
|
|
35
|
+
type RenderOptions,
|
|
36
|
+
type RenderResult,
|
|
37
|
+
renderSource,
|
|
38
|
+
} from './pipeline.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side `readFile` that always rejects with a stable, sniff-able
|
|
3
|
+
* error tag. The pipeline catches matching include diagnostics and
|
|
4
|
+
* surfaces them through the `onSkippedInclude` callback so callers can
|
|
5
|
+
* implement their own warn-once-per-page behaviour without inheriting
|
|
6
|
+
* a `console.warn` side effect from this package.
|
|
7
|
+
*
|
|
8
|
+
* A real HTTP-fetch resolver is intentionally out of scope here (see
|
|
9
|
+
* `specs/handoffs/handoff-m4-embed.md`): CORS, relative-URL semantics,
|
|
10
|
+
* and waterfall performance each warrant their own decision and are
|
|
11
|
+
* best handled behind an opt-in flag in a follow-up.
|
|
12
|
+
*/
|
|
13
|
+
export const NOWLINE_BROWSER_NOOP_INCLUDE_TAG = '__nowline_browser_noop_include__';
|
|
14
|
+
|
|
15
|
+
export async function noOpIncludeReadFile(absPath: string): Promise<string> {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`${NOWLINE_BROWSER_NOOP_INCLUDE_TAG}: include "${absPath}" was skipped — running in single-file mode.`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isNoOpIncludeDiagnosticMessage(message: string): boolean {
|
|
22
|
+
return message.includes(NOWLINE_BROWSER_NOOP_INCLUDE_TAG);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface SkippedInclude {
|
|
26
|
+
/** Absolute path of the include that was skipped. */
|
|
27
|
+
sourcePath: string;
|
|
28
|
+
/** The diagnostic message verbatim, including the sniff tag. */
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
package/src/pipeline.ts
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
// Browser-safe render pipeline shared by every browser surface that
|
|
2
|
+
// needs to turn `.nowline` source into SVG. Consolidates two prior
|
|
3
|
+
// implementations:
|
|
4
|
+
//
|
|
5
|
+
// - `packages/embed/src/pipeline.ts` (single-file, no Node, throws on
|
|
6
|
+
// error, fires a console.warn the first time an include is skipped).
|
|
7
|
+
// - `packages/vscode-extension/src/preview/render-pipeline.ts` (full
|
|
8
|
+
// options matrix incl. Node-backed include resolver + asset resolver,
|
|
9
|
+
// returns a discriminated union instead of throwing).
|
|
10
|
+
//
|
|
11
|
+
// The seam between them is dependency injection. Callers that have
|
|
12
|
+
// access to a filesystem (VS Code, future Node browsers) supply a
|
|
13
|
+
// `readFile` callback and an `assetResolver`; callers that don't (embed,
|
|
14
|
+
// Free SPA) omit both, get the noop include reader, and receive a
|
|
15
|
+
// `SkippedInclude` callback when an `include` directive is encountered.
|
|
16
|
+
//
|
|
17
|
+
// The package itself imports zero `node:*` modules so the embed esbuild
|
|
18
|
+
// bundle stays free of any Node literal even before tree-shaking.
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
createNowlineServices,
|
|
22
|
+
type NowlineFile,
|
|
23
|
+
type NowlineServices,
|
|
24
|
+
resolveIncludes,
|
|
25
|
+
} from '@nowline/core';
|
|
26
|
+
import { layoutRoadmap, type ThemeName } from '@nowline/layout';
|
|
27
|
+
import { type AssetResolver, renderSvg } from '@nowline/renderer';
|
|
28
|
+
import { URI } from 'langium';
|
|
29
|
+
import {
|
|
30
|
+
type DiagnosticRow,
|
|
31
|
+
fromLangiumDiagnostic,
|
|
32
|
+
fromLexerError,
|
|
33
|
+
fromParserError,
|
|
34
|
+
fromRenderWarning,
|
|
35
|
+
fromResolveDiagnostic,
|
|
36
|
+
type LangiumLikeDiagnostic,
|
|
37
|
+
} from './diagnostic-row.js';
|
|
38
|
+
import {
|
|
39
|
+
isNoOpIncludeDiagnosticMessage,
|
|
40
|
+
noOpIncludeReadFile,
|
|
41
|
+
type SkippedInclude,
|
|
42
|
+
} from './no-op-include-resolver.js';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Synthetic path stamped on diagnostics that have no real source file
|
|
46
|
+
* (the embed renders strings, not files). Consumers can re-key it to
|
|
47
|
+
* a more user-meaningful label by setting `filePath`.
|
|
48
|
+
*/
|
|
49
|
+
export const DEFAULT_SYNTHETIC_PATH = '/browser-source.nowline';
|
|
50
|
+
|
|
51
|
+
export interface ParseOptions {
|
|
52
|
+
/**
|
|
53
|
+
* Absolute path (or synthetic path) used to seed include resolution
|
|
54
|
+
* and tag parse/validation diagnostics. Defaults to a synthetic
|
|
55
|
+
* `/browser-source.nowline` so embedded blocks have a stable label.
|
|
56
|
+
*/
|
|
57
|
+
filePath?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Callback that resolves an `include "..."` directive to file
|
|
60
|
+
* contents. When omitted, falls back to `noOpIncludeReadFile`
|
|
61
|
+
* (every include is skipped and surfaced via `onSkippedInclude`).
|
|
62
|
+
* VS Code passes a Node `fs.readFile` shim; the embed passes
|
|
63
|
+
* nothing.
|
|
64
|
+
*/
|
|
65
|
+
readFile?: (absPath: string) => Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Fires once per skipped include when the noop reader rejects it.
|
|
68
|
+
* Use this to surface a single page-level warning without coupling
|
|
69
|
+
* the pipeline to `console.warn`.
|
|
70
|
+
*/
|
|
71
|
+
onSkippedInclude?: (info: SkippedInclude) => void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface ParseResult {
|
|
75
|
+
ast: NowlineFile;
|
|
76
|
+
diagnostics: DiagnosticRow[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface RenderOptions extends ParseOptions {
|
|
80
|
+
theme?: ThemeName;
|
|
81
|
+
/**
|
|
82
|
+
* "Today" override threaded into the layout engine. Pass an
|
|
83
|
+
* explicit `Date` for deterministic snapshots; pass `null` to
|
|
84
|
+
* suppress the now-line entirely (mirrors the CLI's `--now -`);
|
|
85
|
+
* leave undefined to use `new Date()` per render.
|
|
86
|
+
*/
|
|
87
|
+
today?: Date | null;
|
|
88
|
+
/** BCP-47 locale forwarded to the layout engine for axis labels. */
|
|
89
|
+
locale?: string;
|
|
90
|
+
/** Total canvas width in px. Layout's default is 1280. */
|
|
91
|
+
width?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Override the deterministic id prefix used for in-SVG `<style>`
|
|
94
|
+
* scoping. Multi-block surfaces (auto-scan) supply a fresh prefix
|
|
95
|
+
* per block so two roadmaps cannot bleed styles into each other.
|
|
96
|
+
*/
|
|
97
|
+
idPrefix?: string;
|
|
98
|
+
/** Inverse of the CLI's `--no-links`. When false, link icons are dropped. */
|
|
99
|
+
showLinks?: boolean;
|
|
100
|
+
/** Promote renderer warnings to errors in the diagnostic table. */
|
|
101
|
+
strict?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Asset resolver invoked by the renderer for image references
|
|
104
|
+
* (`icon:` declarations, etc.). When omitted, image assets are
|
|
105
|
+
* silently dropped — match the embed's "no filesystem" posture.
|
|
106
|
+
*/
|
|
107
|
+
assetResolver?: AssetResolver;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export type RenderResult =
|
|
111
|
+
| { kind: 'svg'; svg: string; warnings: DiagnosticRow[] }
|
|
112
|
+
| { kind: 'diagnostics'; diagnostics: DiagnosticRow[] };
|
|
113
|
+
|
|
114
|
+
interface CachedServices {
|
|
115
|
+
shared: ReturnType<typeof createNowlineServices>['shared'];
|
|
116
|
+
Nowline: NowlineServices;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let cachedServices: CachedServices | undefined;
|
|
120
|
+
let docCounter = 0;
|
|
121
|
+
|
|
122
|
+
function getServices(): CachedServices {
|
|
123
|
+
if (!cachedServices) cachedServices = createNowlineServices();
|
|
124
|
+
return cachedServices;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function freshUri(): URI {
|
|
128
|
+
// Each render mints a fresh URI; reusing one would let Langium's
|
|
129
|
+
// DocumentBuilder mutate the prior document under us.
|
|
130
|
+
return URI.parse(`memory:///nowline-browser-${++docCounter}.nowline`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Parse + validate the source. Returns the AST plus any diagnostics
|
|
135
|
+
* normalized to the shared {@link DiagnosticRow} shape. Does not run
|
|
136
|
+
* include resolution, layout, or rendering — useful for editor
|
|
137
|
+
* experiences that want diagnostics without paying the render cost.
|
|
138
|
+
*/
|
|
139
|
+
export async function parseSource(
|
|
140
|
+
source: string,
|
|
141
|
+
options: ParseOptions = {},
|
|
142
|
+
): Promise<ParseResult> {
|
|
143
|
+
const filePath = options.filePath ?? DEFAULT_SYNTHETIC_PATH;
|
|
144
|
+
const services = getServices();
|
|
145
|
+
const docFactory = services.shared.workspace.LangiumDocumentFactory;
|
|
146
|
+
const doc = docFactory.fromString<NowlineFile>(source, freshUri());
|
|
147
|
+
await services.shared.workspace.DocumentBuilder.build([doc], { validation: true });
|
|
148
|
+
|
|
149
|
+
const diagnostics: DiagnosticRow[] = [];
|
|
150
|
+
for (const err of doc.parseResult.lexerErrors) {
|
|
151
|
+
diagnostics.push(fromLexerError(err, filePath));
|
|
152
|
+
}
|
|
153
|
+
for (const err of doc.parseResult.parserErrors) {
|
|
154
|
+
diagnostics.push(fromParserError(err, filePath));
|
|
155
|
+
}
|
|
156
|
+
for (const diag of doc.diagnostics ?? []) {
|
|
157
|
+
diagnostics.push(fromLangiumDiagnostic(diag as LangiumLikeDiagnostic, filePath));
|
|
158
|
+
}
|
|
159
|
+
return { ast: doc.parseResult.value, diagnostics };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Run the full pipeline (parse + validate + resolveIncludes + layout
|
|
164
|
+
* + render) and return either the SVG or a list of diagnostics. The
|
|
165
|
+
* `RenderResult` discriminated union mirrors the CLI's success/failure
|
|
166
|
+
* split so callers can render either path without try/catch plumbing.
|
|
167
|
+
*/
|
|
168
|
+
export async function renderSource(
|
|
169
|
+
source: string,
|
|
170
|
+
options: RenderOptions = {},
|
|
171
|
+
): Promise<RenderResult> {
|
|
172
|
+
const filePath = options.filePath ?? DEFAULT_SYNTHETIC_PATH;
|
|
173
|
+
const parsed = await parseSource(source, { filePath });
|
|
174
|
+
if (parsed.diagnostics.some((d) => d.severity === 'error')) {
|
|
175
|
+
return { kind: 'diagnostics', diagnostics: parsed.diagnostics };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const services = getServices();
|
|
179
|
+
const readFile = options.readFile ?? noOpIncludeReadFile;
|
|
180
|
+
const resolved = await resolveIncludes(parsed.ast, filePath, {
|
|
181
|
+
services: services.Nowline,
|
|
182
|
+
readFile,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const rows: DiagnosticRow[] = [...parsed.diagnostics];
|
|
186
|
+
for (const diag of resolved.diagnostics) {
|
|
187
|
+
if (diag.severity === 'error' && isNoOpIncludeDiagnosticMessage(diag.message)) {
|
|
188
|
+
options.onSkippedInclude?.({
|
|
189
|
+
sourcePath: diag.sourcePath,
|
|
190
|
+
message: diag.message,
|
|
191
|
+
});
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
rows.push(fromResolveDiagnostic(diag));
|
|
195
|
+
}
|
|
196
|
+
if (rows.some((r) => r.severity === 'error')) {
|
|
197
|
+
return { kind: 'diagnostics', diagnostics: rows };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const today = options.today === null ? undefined : options.today;
|
|
201
|
+
const model = layoutRoadmap(parsed.ast, resolved, {
|
|
202
|
+
theme: options.theme,
|
|
203
|
+
today,
|
|
204
|
+
locale: options.locale,
|
|
205
|
+
width: options.width,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const showLinks = options.showLinks !== false;
|
|
209
|
+
const strict = options.strict === true;
|
|
210
|
+
const warnMessages: string[] = [];
|
|
211
|
+
|
|
212
|
+
const svg = await renderSvg(model, {
|
|
213
|
+
idPrefix: options.idPrefix,
|
|
214
|
+
assetResolver: options.assetResolver,
|
|
215
|
+
noLinks: !showLinks,
|
|
216
|
+
strict,
|
|
217
|
+
warn: (msg) => warnMessages.push(msg),
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
const warnings = warnMessages.map((m) =>
|
|
221
|
+
fromRenderWarning(m, filePath, strict ? 'error' : 'warning'),
|
|
222
|
+
);
|
|
223
|
+
if (strict && warnings.length > 0) {
|
|
224
|
+
return { kind: 'diagnostics', diagnostics: [...rows, ...warnings] };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return { kind: 'svg', svg, warnings };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Test-only escape hatch. Resets cached Langium services and the
|
|
232
|
+
* URI counter between cases so a `parseSource` failure in one test
|
|
233
|
+
* doesn't poison the next one's document builder.
|
|
234
|
+
*/
|
|
235
|
+
export function __resetBrowserPipelineForTests(): void {
|
|
236
|
+
cachedServices = undefined;
|
|
237
|
+
docCounter = 0;
|
|
238
|
+
}
|