@nowline/embed 0.2.2

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 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.
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # @nowline/embed
2
+
3
+ Browser bundle that finds ` ```nowline ` fenced code blocks in a page
4
+ and renders them as SVG roadmaps. Mirrors the
5
+ [Mermaid](https://mermaid.js.org) embed surface — drop a `<script>`
6
+ tag and Nowline blocks light up.
7
+
8
+ ## Quick start
9
+
10
+ ```html
11
+ <!-- pin a version in production; @latest is convenient for prototypes -->
12
+ <script src="https://embed.nowline.io/0.2.0/nowline.min.js"></script>
13
+ ```
14
+
15
+ That's it. Every `<pre><code class="language-nowline">…</code></pre>`
16
+ block on the page renders on `DOMContentLoaded`.
17
+
18
+ > **Status note (m4 in progress):** the bundle is published to npm
19
+ > today, but the branded `embed.nowline.io` CDN deploy is still
20
+ > pending — see [`specs/handoffs/handoff-m4-embed.md`](../../specs/handoffs/handoff-m4-embed.md)
21
+ > "Carried forward". Until that lands, install via npm and serve the
22
+ > bundle yourself (see [ESM consumers](#esm-consumers) below) or
23
+ > drop in `import { initialize } from '@nowline/embed'` from your
24
+ > app bundle.
25
+
26
+ ## Configuration
27
+
28
+ ```html
29
+ <script src="https://embed.nowline.io/0.2.0/nowline.min.js"></script>
30
+ <script>
31
+ nowline.initialize({
32
+ theme: 'dark', // 'light' | 'dark' | 'auto' (reads prefers-color-scheme once)
33
+ startOnLoad: true, // auto-run on DOMContentLoaded
34
+ selector: 'pre code.language-nowline',
35
+ locale: 'fr-CA',
36
+ width: 1024,
37
+ });
38
+ </script>
39
+ ```
40
+
41
+ Theme precedence (highest to lowest):
42
+
43
+ 1. The `initialize({ theme })` flag.
44
+ 2. The file's own `nowline v1 theme:` directive.
45
+ 3. `prefers-color-scheme` — captured **once** on init, not reactive.
46
+
47
+ ## Manual rendering
48
+
49
+ For dynamically loaded blocks or custom containers:
50
+
51
+ ```html
52
+ <script src="https://embed.nowline.io/0.2.0/nowline.min.js"></script>
53
+ <script>
54
+ const svg = await nowline.render(`
55
+ roadmap "My Roadmap"
56
+ swimlane team
57
+ item a "Task A" duration:1w
58
+ item b "Task B" duration:2w after:a
59
+ `);
60
+ document.getElementById('target').innerHTML = svg;
61
+ </script>
62
+ ```
63
+
64
+ The bundle also exposes `nowline.parse(source)` for editor-style
65
+ applications that want diagnostics without running layout / render, and
66
+ `nowline.run()` (alias of `init`) to manually re-scan after the page
67
+ mutates.
68
+
69
+ ## CDN URLs
70
+
71
+ The documented channel is the branded `embed.nowline.io` / `embed.nowline.dev`
72
+ CDN, served from a Firebase Hosting deploy that runs on each release.
73
+ See [`specs/embed.md`](../../specs/embed.md) "Distribution" for the
74
+ full URL matrix (immutable patch, mutable minor, `latest`, dev
75
+ channel, per-PR ephemeral previews) and cache-control posture.
76
+
77
+ | URL pattern | Stability | Audience |
78
+ |-------------|-----------|----------|
79
+ | `https://embed.nowline.io/{X.Y.Z}/nowline.min.js` | immutable per patch | production embedders pinning a known-good build |
80
+ | `https://embed.nowline.io/{X.Y}/nowline.min.js` | mutable within minor | embedders who want patch fixes auto-rolled in |
81
+ | `https://embed.nowline.io/latest/nowline.min.js` | mutable, latest stable | docs, demos, prototypes |
82
+ | `https://embed.nowline.dev/nowline.min.js` | mutable, no SLA | "next" preview, opt-in only |
83
+
84
+ Pin the version in production so a release does not silently re-render
85
+ your roadmap.
86
+
87
+ > **Bootstrap pending:** `embed.nowline.{io,dev}` is not live yet —
88
+ > see [`specs/handoffs/handoff-m4-embed.md`](../../specs/handoffs/handoff-m4-embed.md)
89
+ > "Carried forward". For now, consume the package over npm.
90
+
91
+ ## Limitations
92
+
93
+ - **`include`-directives are skipped.** The embed runs in single-file
94
+ mode; a one-shot `console.warn` fires when a multi-file roadmap is
95
+ loaded. Use the CLI or the GitHub Action for multi-file rendering.
96
+ - **No asset resolver.** `<script>` tags can't read the host
97
+ filesystem; logos are not embedded by the browser bundle. The CLI
98
+ is the path for embedded raster assets.
99
+ - **Hosts that strip `<script>` tags** (GitHub READMEs, email,
100
+ Slack, Discord, Confluence rich text) cannot run the embed. The
101
+ GitHub Action exists for those.
102
+
103
+ ## ESM consumers
104
+
105
+ Frameworks that bundle their own JS can install the package and import
106
+ named exports:
107
+
108
+ ```ts
109
+ import { render, initialize } from '@nowline/embed';
110
+ ```
111
+
112
+ The package is `"type": "module"` and `"sideEffects": false`, so a
113
+ modern bundler (esbuild, Rollup, Webpack 5+, Vite) tree-shakes the
114
+ auto-scan bootstrap when it's unused.
115
+
116
+ ## License
117
+
118
+ Apache-2.0. See [LICENSE](../../LICENSE).
@@ -0,0 +1,23 @@
1
+ import type { ThemeName } from '@nowline/layout';
2
+ export interface AutoScanInputs {
3
+ selector: string;
4
+ theme?: ThemeName;
5
+ locale?: string;
6
+ width?: number;
7
+ today?: Date;
8
+ /**
9
+ * Document to scan. Defaults to `globalThis.document`. Tests inject
10
+ * a happy-dom document; the IIFE running on a real page picks up
11
+ * the live document.
12
+ */
13
+ document?: Document;
14
+ }
15
+ export interface AutoScanResult {
16
+ /** Number of code blocks that were successfully replaced with SVG. */
17
+ rendered: number;
18
+ /** Number of blocks that failed to render (logged to console.error). */
19
+ failed: number;
20
+ }
21
+ export declare function runAutoScan(inputs: AutoScanInputs): Promise<AutoScanResult>;
22
+ export declare function __resetAutoScanForTests(): void;
23
+ //# sourceMappingURL=auto-scan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-scan.d.ts","sourceRoot":"","sources":["../src/auto-scan.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,MAAM,WAAW,cAAc;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,IAAI,CAAC;IACb;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC3B,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC;CAClB;AAID,wBAAsB,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CA2CjF;AA8BD,wBAAgB,uBAAuB,IAAI,IAAI,CAE9C"}
@@ -0,0 +1,71 @@
1
+ // DOM scanner that finds `<pre><code class="language-nowline">…</code></pre>`
2
+ // blocks (or whatever selector the caller registered) and replaces each
3
+ // with its rendered SVG. Each block gets a unique `idPrefix` so two
4
+ // roadmaps on the same page never share `<style>` ids.
5
+ import { renderSource } from './pipeline.js';
6
+ let runCounter = 0;
7
+ export async function runAutoScan(inputs) {
8
+ const doc = inputs.document ?? globalThis.document;
9
+ if (!doc) {
10
+ return { rendered: 0, failed: 0 };
11
+ }
12
+ const blocks = doc.querySelectorAll(inputs.selector);
13
+ let rendered = 0;
14
+ let failed = 0;
15
+ const baseRunId = ++runCounter;
16
+ const tasks = [];
17
+ let blockIndex = 0;
18
+ for (const code of Array.from(blocks)) {
19
+ const target = pickReplacementTarget(code);
20
+ if (!target) {
21
+ continue;
22
+ }
23
+ const source = readBlockSource(code);
24
+ const idPrefix = `nl-r${baseRunId}-${blockIndex++}`;
25
+ const opts = {
26
+ theme: inputs.theme,
27
+ locale: inputs.locale,
28
+ width: inputs.width,
29
+ today: inputs.today,
30
+ idPrefix,
31
+ };
32
+ tasks.push(renderSource(source, opts).then((svg) => {
33
+ replaceWithSvg(target, svg);
34
+ rendered++;
35
+ }, (err) => {
36
+ failed++;
37
+ console.error('nowline: render failed', err);
38
+ }));
39
+ }
40
+ await Promise.all(tasks);
41
+ return { rendered, failed };
42
+ }
43
+ // Markdown-rendered Nowline blocks usually look like
44
+ // `<pre><code class="language-nowline">…</code></pre>`. We replace the
45
+ // outer `<pre>` so the spacing the markdown processor reserved for the
46
+ // fenced block is reused by the SVG. When the matched element has no
47
+ // `<pre>` ancestor (custom hosting) we replace the matched element
48
+ // itself.
49
+ function pickReplacementTarget(matched) {
50
+ const parent = matched.parentElement;
51
+ if (parent && parent.tagName.toUpperCase() === 'PRE') {
52
+ return parent;
53
+ }
54
+ return matched;
55
+ }
56
+ function readBlockSource(code) {
57
+ // `textContent` preserves whitespace and newlines; `innerText` would
58
+ // collapse them per CSS, which would corrupt indentation-sensitive
59
+ // .nowline source.
60
+ return code.textContent ?? '';
61
+ }
62
+ function replaceWithSvg(target, svg) {
63
+ // `outerHTML` parses the SVG string into a real `<svg>` element and
64
+ // swaps it into the DOM, preserving each render's per-`idPrefix`
65
+ // `<style>` scope so two blocks on the page can never bleed styles.
66
+ target.outerHTML = svg;
67
+ }
68
+ export function __resetAutoScanForTests() {
69
+ runCounter = 0;
70
+ }
71
+ //# sourceMappingURL=auto-scan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-scan.js","sourceRoot":"","sources":["../src/auto-scan.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,wEAAwE;AACxE,oEAAoE;AACpE,uDAAuD;AAGvD,OAAO,EAA2B,YAAY,EAAE,MAAM,eAAe,CAAC;AAuBtE,IAAI,UAAU,GAAG,CAAC,CAAC;AAEnB,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAsB;IACpD,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,IAAK,UAAsC,CAAC,QAAQ,CAAC;IAChF,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IACtC,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,CAAC,gBAAgB,CAAc,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClE,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,MAAM,SAAS,GAAG,EAAE,UAAU,CAAC;IAE/B,MAAM,KAAK,GAAyB,EAAE,CAAC;IACvC,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM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AED,SAAS,eAAe,CAAC,IAAiB;IACtC,qEAAqE;IACrE,mEAAmE;IACnE,mBAAmB;IACnB,OAAO,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC;AAClC,CAAC;AAED,SAAS,cAAc,CAAC,MAAmB,EAAE,GAAW;IACpD,oEAAoE;IACpE,iEAAiE;IACjE,oEAAoE;IACpE,MAAM,CAAC,SAAS,GAAG,GAAG,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,uBAAuB;IACnC,UAAU,GAAG,CAAC,CAAC;AACnB,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { type AutoScanInputs, type AutoScanResult } from './auto-scan.js';
2
+ import { type EmbedParseResult, EmbedRenderError, type EmbedRenderOptions } from './pipeline.js';
3
+ import { type EmbedTheme } from './theme.js';
4
+ export { type AutoScanResult, type EmbedParseResult, EmbedRenderError, type EmbedTheme };
5
+ export interface InitializeOptions {
6
+ /** `light`, `dark`, or `auto` (read once via `prefers-color-scheme`). */
7
+ theme?: EmbedTheme;
8
+ /**
9
+ * Auto-run `init()` on `DOMContentLoaded`. Defaults to `true`.
10
+ * Setting this to `false` defers rendering until the page calls
11
+ * `nowline.init()` (or `nowline.run()`) manually.
12
+ */
13
+ startOnLoad?: boolean;
14
+ /**
15
+ * CSS selector used to locate Nowline blocks. The default matches
16
+ * markdown-renderer output (`<pre><code class="language-nowline">…</code></pre>`)
17
+ * plus standalone `<code class="language-nowline">` for hosts that
18
+ * skip the `<pre>` wrapper.
19
+ */
20
+ selector?: string;
21
+ /** BCP-47 locale forwarded to the layout engine for axis labels and the now-pill. */
22
+ locale?: string;
23
+ /** Layout canvas width in pixels. Layout's default is 1280. */
24
+ width?: number;
25
+ /** Pin a `today` for deterministic snapshots; defaults to live `new Date()` per render. */
26
+ today?: Date;
27
+ }
28
+ export declare function initialize(options?: InitializeOptions): void;
29
+ /**
30
+ * Render a single Nowline source string to an SVG. Useful for
31
+ * applications that want to control exactly when and where the SVG
32
+ * lands (custom `<div>` containers, dynamically loaded blocks, etc.).
33
+ */
34
+ export declare function render(source: string, options?: EmbedRenderOptions): Promise<string>;
35
+ /**
36
+ * Parse a Nowline source string. Returns the AST and any lexer /
37
+ * parser / validator errors. Does not run layout or render — useful for
38
+ * editor experiences that want diagnostics without paying the render
39
+ * cost.
40
+ */
41
+ export declare function parse(source: string): Promise<EmbedParseResult>;
42
+ /**
43
+ * Scan the DOM for Nowline blocks and replace each with its rendered
44
+ * SVG. Aliased as `run` for parity with Mermaid's recent API.
45
+ */
46
+ export declare function init(overrides?: Partial<AutoScanInputs>): Promise<AutoScanResult>;
47
+ /** Alias for `init`, matching Mermaid's `mermaid.run()`. */
48
+ export declare const run: typeof init;
49
+ export declare function __resetForTests(): void;
50
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAEH,KAAK,cAAc,EACnB,KAAK,cAAc,EAEtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEH,KAAK,gBAAgB,EACrB,gBAAgB,EAChB,KAAK,kBAAkB,EAG1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,UAAU,EAAsC,MAAM,YAAY,CAAC;AAEjF,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,CAAC;AAIzF,MAAM,WAAW,iBAAiB;IAC9B,yEAAyE;IACzE,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2FAA2F;IAC3F,KAAK,CAAC,EAAE,IAAI,CAAC;CAChB;AAuBD,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,IAAI,CAchE;AAYD;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAM9F;AAED;;;;;GAKG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAErE;AAED;;;GAGG;AACH,wBAAsB,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,CAUvF;AAED,4DAA4D;AAC5D,eAAO,MAAM,GAAG,aAAO,CAAC;AAgCxB,wBAAgB,eAAe,IAAI,IAAI,CAKtC"}
package/dist/index.js ADDED
@@ -0,0 +1,119 @@
1
+ // Public API for `@nowline/embed`. Mirrors Mermaid's surface
2
+ // (`initialize`, `render`, `parse`, `init`/`run`) so users coming from
3
+ // Mermaid don't have to relearn anything.
4
+ //
5
+ // The IIFE bundle exposes everything below as `window.nowline.*`. ESM
6
+ // consumers import named exports from the package root.
7
+ import { __resetAutoScanForTests, runAutoScan, } from './auto-scan.js';
8
+ import { __resetEmbedPipelineForTests, EmbedRenderError, parseSource, renderSource, } from './pipeline.js';
9
+ import { effectiveTheme, resolveSystemTheme } from './theme.js';
10
+ export { EmbedRenderError };
11
+ const DEFAULT_SELECTOR = 'pre code.language-nowline, code.language-nowline';
12
+ const initialConfig = {
13
+ theme: 'auto',
14
+ startOnLoad: true,
15
+ selector: DEFAULT_SELECTOR,
16
+ systemTheme: resolveSystemTheme(),
17
+ };
18
+ let config = { ...initialConfig };
19
+ let autoStartScheduled = false;
20
+ export function initialize(options = {}) {
21
+ config = {
22
+ theme: options.theme ?? config.theme,
23
+ startOnLoad: options.startOnLoad ?? config.startOnLoad,
24
+ selector: options.selector ?? config.selector,
25
+ locale: options.locale ?? config.locale,
26
+ width: options.width ?? config.width,
27
+ today: options.today ?? config.today,
28
+ // Re-read `prefers-color-scheme` on every initialize() so callers
29
+ // who explicitly want the latest system theme can ask for it by
30
+ // calling initialize() again. Auto-scan paths still use the value
31
+ // captured at initialize time.
32
+ systemTheme: resolveSystemTheme(),
33
+ };
34
+ }
35
+ /** Build the EmbedRenderOptions used by `render` and the auto-scan path. */
36
+ function renderOptionsFromConfig() {
37
+ return {
38
+ theme: effectiveTheme(config.theme, config.systemTheme),
39
+ locale: config.locale,
40
+ width: config.width,
41
+ today: config.today,
42
+ };
43
+ }
44
+ /**
45
+ * Render a single Nowline source string to an SVG. Useful for
46
+ * applications that want to control exactly when and where the SVG
47
+ * lands (custom `<div>` containers, dynamically loaded blocks, etc.).
48
+ */
49
+ export async function render(source, options = {}) {
50
+ const merged = {
51
+ ...renderOptionsFromConfig(),
52
+ ...options,
53
+ };
54
+ return renderSource(source, merged);
55
+ }
56
+ /**
57
+ * Parse a Nowline source string. Returns the AST and any lexer /
58
+ * parser / validator errors. Does not run layout or render — useful for
59
+ * editor experiences that want diagnostics without paying the render
60
+ * cost.
61
+ */
62
+ export async function parse(source) {
63
+ return parseSource(source);
64
+ }
65
+ /**
66
+ * Scan the DOM for Nowline blocks and replace each with its rendered
67
+ * SVG. Aliased as `run` for parity with Mermaid's recent API.
68
+ */
69
+ export async function init(overrides) {
70
+ const inputs = {
71
+ selector: overrides?.selector ?? config.selector,
72
+ theme: overrides?.theme ?? renderOptionsFromConfig().theme,
73
+ locale: overrides?.locale ?? config.locale,
74
+ width: overrides?.width ?? config.width,
75
+ today: overrides?.today ?? config.today,
76
+ document: overrides?.document,
77
+ };
78
+ return runAutoScan(inputs);
79
+ }
80
+ /** Alias for `init`, matching Mermaid's `mermaid.run()`. */
81
+ export const run = init;
82
+ // IIFE-bundle bootstrap. When the bundled script tag loads on a page,
83
+ // the bundler invokes the module body; we schedule auto-scan to fire on
84
+ // DOMContentLoaded unless the page disables it with
85
+ // `nowline.initialize({ startOnLoad: false })` synchronously after the
86
+ // script tag.
87
+ //
88
+ // Guarded by `typeof document !== 'undefined'` so ESM consumers
89
+ // (Node tests, build pipelines, server-side rendering) don't trigger
90
+ // the auto-scan branch.
91
+ if (typeof document !== 'undefined' && !autoStartScheduled) {
92
+ autoStartScheduled = true;
93
+ const start = () => {
94
+ if (!config.startOnLoad)
95
+ return;
96
+ // Fire-and-forget; render errors are surfaced via `console.error`
97
+ // inside `runAutoScan`.
98
+ void init();
99
+ };
100
+ if (document.readyState === 'loading') {
101
+ document.addEventListener('DOMContentLoaded', start, { once: true });
102
+ }
103
+ else {
104
+ // Document is already parsed; defer to next microtask so any
105
+ // synchronous `initialize({ startOnLoad: false })` after the
106
+ // script tag still wins the race.
107
+ queueMicrotask(start);
108
+ }
109
+ }
110
+ // Test-only escape hatch. Exposed as a named export so tests can reset
111
+ // the module's hidden state (config, system-theme cache, the once-only
112
+ // console.warn latch) between cases.
113
+ export function __resetForTests() {
114
+ config = { ...initialConfig, systemTheme: resolveSystemTheme() };
115
+ autoStartScheduled = false;
116
+ __resetEmbedPipelineForTests();
117
+ __resetAutoScanForTests();
118
+ }
119
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,uEAAuE;AACvE,0CAA0C;AAC1C,EAAE;AACF,sEAAsE;AACtE,wDAAwD;AAExD,OAAO,EACH,uBAAuB,EAGvB,WAAW,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACH,4BAA4B,EAE5B,gBAAgB,EAEhB,WAAW,EACX,YAAY,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAmB,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEjF,OAAO,EAA8C,gBAAgB,EAAmB,CAAC;AAEzF,MAAM,gBAAgB,GAAG,kDAAkD,CAAC;AAqC5E,MAAM,aAAa,GAAmB;IAClC,KAAK,EAAE,MAAM;IACb,WAAW,EAAE,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