@nowline/embed 0.0.0-dev.20260601071750.g04bdff9

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,106 @@
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 an exact version in production -->
12
+ <script src="https://cdn.jsdelivr.net/npm/@nowline/embed@0.4.2/dist/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
+ ## Configuration
19
+
20
+ ```html
21
+ <script src="https://cdn.jsdelivr.net/npm/@nowline/embed@0.4.2/dist/nowline.min.js"></script>
22
+ <script>
23
+ nowline.initialize({
24
+ theme: 'dark', // 'light' | 'dark' | 'auto' (reads prefers-color-scheme once)
25
+ startOnLoad: true, // auto-run on DOMContentLoaded
26
+ selector: 'pre code.language-nowline',
27
+ locale: 'fr-CA',
28
+ width: 1024,
29
+ });
30
+ </script>
31
+ ```
32
+
33
+ Theme precedence (highest to lowest):
34
+
35
+ 1. The `initialize({ theme })` flag.
36
+ 2. The file's own `nowline v1 theme:` directive.
37
+ 3. `prefers-color-scheme` — captured **once** on init, not reactive.
38
+
39
+ ## Manual rendering
40
+
41
+ For dynamically loaded blocks or custom containers:
42
+
43
+ ```html
44
+ <script src="https://cdn.jsdelivr.net/npm/@nowline/embed@0.4.2/dist/nowline.min.js"></script>
45
+ <script>
46
+ const svg = await nowline.render(`
47
+ roadmap "My Roadmap"
48
+ swimlane team
49
+ item a "Task A" duration:1w
50
+ item b "Task B" duration:2w after:a
51
+ `);
52
+ document.getElementById('target').innerHTML = svg;
53
+ </script>
54
+ ```
55
+
56
+ The bundle also exposes `nowline.parse(source)` for editor-style
57
+ applications that want diagnostics without running layout / render, and
58
+ `nowline.run()` (alias of `init`) to manually re-scan after the page
59
+ mutates.
60
+
61
+ ## CDN URLs
62
+
63
+ jsDelivr is the documented CDN channel. The bytes are served directly
64
+ from the npm tarball — byte-identical to `npm pack @nowline/embed@X.Y.Z`.
65
+
66
+ | URL pattern | Stability | Audience |
67
+ |-------------|-----------|----------|
68
+ | `https://cdn.jsdelivr.net/npm/@nowline/embed@X.Y.Z/dist/nowline.min.js` | immutable per patch | production embedders pinning a known-good build |
69
+ | `https://cdn.jsdelivr.net/npm/@nowline/embed@X.Y/dist/nowline.min.js` | mutable within minor | embedders who want patch fixes auto-rolled in (pre-1.0 the minor is the breaking-change boundary) |
70
+ | `https://cdn.jsdelivr.net/npm/@nowline/embed/dist/nowline.min.js` | mutable, latest stable | docs, demos, prototypes |
71
+ | `https://cdn.jsdelivr.net/npm/@nowline/embed@next/dist/nowline.min.js` | HEAD-tracking canary (`0.0.0-dev.*`) | "next" preview, opt-in only |
72
+
73
+ unpkg also works (`https://unpkg.com/@nowline/embed@X.Y.Z/dist/nowline.min.js`).
74
+
75
+ Pin the version in production so a release does not silently re-render
76
+ your roadmap. See [`specs/embed.md`](../../specs/embed.md) for the
77
+ full distribution spec.
78
+
79
+ ## Limitations
80
+
81
+ - **`include`-directives are skipped.** The embed runs in single-file
82
+ mode; a one-shot `console.warn` fires when a multi-file roadmap is
83
+ loaded. Use the CLI or the GitHub Action for multi-file rendering.
84
+ - **No asset resolver.** `<script>` tags can't read the host
85
+ filesystem; logos are not embedded by the browser bundle. The CLI
86
+ is the path for embedded raster assets.
87
+ - **Hosts that strip `<script>` tags** (GitHub READMEs, email,
88
+ Slack, Discord, Confluence rich text) cannot run the embed. The
89
+ GitHub Action exists for those.
90
+
91
+ ## ESM consumers
92
+
93
+ Frameworks that bundle their own JS can install the package and import
94
+ named exports:
95
+
96
+ ```ts
97
+ import { render, initialize } from '@nowline/embed';
98
+ ```
99
+
100
+ The package is `"type": "module"` and `"sideEffects": false`, so a
101
+ modern bundler (esbuild, Rollup, Webpack 5+, Vite) tree-shakes the
102
+ auto-scan bootstrap when it's unused.
103
+
104
+ ## License
105
+
106
+ Apache-2.0. See [LICENSE](../../LICENSE).
@@ -0,0 +1,34 @@
1
+ import type { ThemeName } from '@nowline/layout';
2
+ import { type ShareOption } from './share.js';
3
+ export interface AutoScanInputs {
4
+ selector: string;
5
+ theme?: ThemeName;
6
+ locale?: string;
7
+ width?: number;
8
+ today?: Date;
9
+ /**
10
+ * Controls the "Share on Nowline" anchor appended after each rendered
11
+ * SVG. Defaults to `true` when omitted (mirrors the config default).
12
+ */
13
+ share?: ShareOption;
14
+ /**
15
+ * Global source URL for all blocks. Per-block `data-nowline-source-url`
16
+ * overrides this for individual blocks.
17
+ */
18
+ sourceUrl?: string;
19
+ /**
20
+ * Document to scan. Defaults to `globalThis.document`. Tests inject
21
+ * a happy-dom document; the IIFE running on a real page picks up
22
+ * the live document.
23
+ */
24
+ document?: Document;
25
+ }
26
+ export interface AutoScanResult {
27
+ /** Number of code blocks that were successfully replaced with SVG. */
28
+ rendered: number;
29
+ /** Number of blocks that failed to render (logged to console.error). */
30
+ failed: number;
31
+ }
32
+ export declare function runAutoScan(inputs: AutoScanInputs): Promise<AutoScanResult>;
33
+ export declare function __resetAutoScanForTests(): void;
34
+ //# 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;AAEjD,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,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;;;OAGG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;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,CA0EjF;AA8BD,wBAAgB,uBAAuB,IAAI,IAAI,CAE9C"}
@@ -0,0 +1,99 @@
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
+ import { buildShareLink } from './share.js';
7
+ let runCounter = 0;
8
+ export async function runAutoScan(inputs) {
9
+ const doc = inputs.document ?? globalThis.document;
10
+ if (!doc) {
11
+ return { rendered: 0, failed: 0 };
12
+ }
13
+ const blocks = doc.querySelectorAll(inputs.selector);
14
+ let rendered = 0;
15
+ let failed = 0;
16
+ const baseRunId = ++runCounter;
17
+ // share defaults to true when omitted (mirrors config.share default)
18
+ const share = inputs.share ?? true;
19
+ const tasks = [];
20
+ let blockIndex = 0;
21
+ for (const code of Array.from(blocks)) {
22
+ const target = pickReplacementTarget(code);
23
+ if (!target) {
24
+ continue;
25
+ }
26
+ const source = readBlockSource(code);
27
+ const idPrefix = `nl-r${baseRunId}-${blockIndex++}`;
28
+ const opts = {
29
+ theme: inputs.theme,
30
+ locale: inputs.locale,
31
+ width: inputs.width,
32
+ today: inputs.today,
33
+ idPrefix,
34
+ };
35
+ // Capture DOM position before the async render. outerHTML replacement
36
+ // detaches `target` from the tree, so parent and nextSibling must be
37
+ // read now. The share anchor is inserted at the saved nextSibling
38
+ // position, which lands it as the immediate next sibling of the SVG.
39
+ const parent = target.parentElement;
40
+ const nextSibling = target.nextSibling;
41
+ // Per-block resolution order: data-nowline-source-url → global sourceUrl
42
+ const perBlockUrl = code.getAttribute('data-nowline-source-url') ?? undefined;
43
+ const resolvedSourceUrl = perBlockUrl ?? inputs.sourceUrl;
44
+ tasks.push(renderSource(source, opts).then((svg) => {
45
+ replaceWithSvg(target, svg);
46
+ rendered++;
47
+ if (parent !== null) {
48
+ const href = buildShareLink({
49
+ source,
50
+ sourceUrl: resolvedSourceUrl,
51
+ share,
52
+ });
53
+ if (href !== null) {
54
+ const a = doc.createElement('a');
55
+ a.className = 'nowline-share';
56
+ a.href = href;
57
+ a.target = '_blank';
58
+ a.rel = 'noopener noreferrer';
59
+ a.textContent = 'Share on Nowline';
60
+ parent.insertBefore(a, nextSibling);
61
+ }
62
+ }
63
+ }, (err) => {
64
+ failed++;
65
+ console.error('nowline: render failed', err);
66
+ }));
67
+ }
68
+ await Promise.all(tasks);
69
+ return { rendered, failed };
70
+ }
71
+ // Markdown-rendered Nowline blocks usually look like
72
+ // `<pre><code class="language-nowline">…</code></pre>`. We replace the
73
+ // outer `<pre>` so the spacing the markdown processor reserved for the
74
+ // fenced block is reused by the SVG. When the matched element has no
75
+ // `<pre>` ancestor (custom hosting) we replace the matched element
76
+ // itself.
77
+ function pickReplacementTarget(matched) {
78
+ const parent = matched.parentElement;
79
+ if (parent && parent.tagName.toUpperCase() === 'PRE') {
80
+ return parent;
81
+ }
82
+ return matched;
83
+ }
84
+ function readBlockSource(code) {
85
+ // `textContent` preserves whitespace and newlines; `innerText` would
86
+ // collapse them per CSS, which would corrupt indentation-sensitive
87
+ // .nowline source.
88
+ return code.textContent ?? '';
89
+ }
90
+ function replaceWithSvg(target, svg) {
91
+ // `outerHTML` parses the SVG string into a real `<svg>` element and
92
+ // swaps it into the DOM, preserving each render's per-`idPrefix`
93
+ // `<style>` scope so two blocks on the page can never bleed styles.
94
+ target.outerHTML = svg;
95
+ }
96
+ export function __resetAutoScanForTests() {
97
+ runCounter = 0;
98
+ }
99
+ //# sourceMappingURL=auto-scan.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CAAC,EACD,CAAC,GAAY,EAAE,EAAE;YACb,MAAM,EAAE,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAC;QACjD,CAAC,CACJ,CACJ,CAAC;IACN,CAAC;IAED,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAChC,CAAC;AAED,qDAAqD;AACrD,uEAAuE;AACvE,uEAAuE;AACvE,qEAAqE;AACrE,mEAAmE;AACnE,UAAU;AACV,SAAS,qBAAqB,CAAC,OAAoB;IAC/C,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IACrC,IAAI,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,KAAK,EAAE,CAAC;QACnD,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,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,78 @@
1
+ import { type AutoScanInputs, type AutoScanResult } from './auto-scan.js';
2
+ import { type EmbedParseResult, EmbedRenderError, type EmbedRenderOptions } from './pipeline.js';
3
+ import type { ShareOption } from './share.js';
4
+ import { type EmbedTheme } from './theme.js';
5
+ export { type AutoScanResult, type EmbedParseResult, EmbedRenderError, type EmbedTheme, type ShareOption, };
6
+ /**
7
+ * Bundle provenance, mirroring the legal-comment banner that
8
+ * `scripts/bundle.mjs` injects at the top of every artifact:
9
+ * `@nowline/embed <version> sha=<short-sha> built=<iso-utc>`.
10
+ *
11
+ * Exposed on the IIFE global as `nowline.version` / `nowline.sha` so
12
+ * pages and bug reports can identify the exact build without scraping
13
+ * the comment banner.
14
+ */
15
+ export declare const version: string;
16
+ export declare const sha: string;
17
+ export interface InitializeOptions {
18
+ /** `light`, `dark`, or `auto` (read once via `prefers-color-scheme`). */
19
+ theme?: EmbedTheme;
20
+ /**
21
+ * Auto-run `init()` on `DOMContentLoaded`. Defaults to `true`.
22
+ * Setting this to `false` defers rendering until the page calls
23
+ * `nowline.init()` (or `nowline.run()`) manually.
24
+ */
25
+ startOnLoad?: boolean;
26
+ /**
27
+ * CSS selector used to locate Nowline blocks. The default matches
28
+ * markdown-renderer output (`<pre><code class="language-nowline">…</code></pre>`)
29
+ * plus standalone `<code class="language-nowline">` for hosts that
30
+ * skip the `<pre>` wrapper.
31
+ */
32
+ selector?: string;
33
+ /** BCP-47 locale forwarded to the layout engine for axis labels and the now-pill. */
34
+ locale?: string;
35
+ /** Layout canvas width in pixels. Layout's default is 1280. */
36
+ width?: number;
37
+ /** Pin a `today` for deterministic snapshots; defaults to live `new Date()` per render. */
38
+ today?: Date;
39
+ /**
40
+ * Controls the "Share on Nowline" anchor appended after each rendered SVG.
41
+ * - `true` (default) — link to the Free app open route
42
+ * (`https://free.nowline.io/open`).
43
+ * - string — a custom base URL (may include a path); the fragment is appended.
44
+ * - `false` / `'none'` — no anchor rendered.
45
+ * - `{ textUrl, remoteUrl }` — template with `{text}` / `{url}` substitution.
46
+ */
47
+ share?: ShareOption;
48
+ /**
49
+ * Global source URL for all blocks on the page. When set, share links
50
+ * use `#url=<sourceUrl>` instead of `#text=` (inline encoding).
51
+ * Per-block `data-nowline-source-url` overrides this for individual blocks.
52
+ * Only `https:` URLs are emitted as `#url=`.
53
+ */
54
+ sourceUrl?: string;
55
+ }
56
+ export declare function initialize(options?: InitializeOptions): void;
57
+ /**
58
+ * Render a single Nowline source string to an SVG. Useful for
59
+ * applications that want to control exactly when and where the SVG
60
+ * lands (custom `<div>` containers, dynamically loaded blocks, etc.).
61
+ */
62
+ export declare function render(source: string, options?: EmbedRenderOptions): Promise<string>;
63
+ /**
64
+ * Parse a Nowline source string. Returns the AST and any lexer /
65
+ * parser / validator errors. Does not run layout or render — useful for
66
+ * editor experiences that want diagnostics without paying the render
67
+ * cost.
68
+ */
69
+ export declare function parse(source: string): Promise<EmbedParseResult>;
70
+ /**
71
+ * Scan the DOM for Nowline blocks and replace each with its rendered
72
+ * SVG. Aliased as `run` for parity with Mermaid's recent API.
73
+ */
74
+ export declare function init(overrides?: Partial<AutoScanInputs>): Promise<AutoScanResult>;
75
+ /** Alias for `init`, matching Mermaid's `mermaid.run()`. */
76
+ export declare const run: typeof init;
77
+ export declare function __resetForTests(): void;
78
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,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,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,KAAK,UAAU,EAAsC,MAAM,YAAY,CAAC;AAEjF,OAAO,EACH,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,WAAW,GACnB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,EAAE,MACoE,CAAC;AAC3F,eAAO,MAAM,GAAG,EAAE,MACkE,CAAC;AAIrF,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;IACb;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AA4BD,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,IAAI,CAgBhE;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,CAYvF;AAED,4DAA4D;AAC5D,eAAO,MAAM,GAAG,aAAO,CAAC;AAiCxB,wBAAgB,eAAe,IAAI,IAAI,CAKtC"}
package/dist/index.js ADDED
@@ -0,0 +1,135 @@
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
+ /**
12
+ * Bundle provenance, mirroring the legal-comment banner that
13
+ * `scripts/bundle.mjs` injects at the top of every artifact:
14
+ * `@nowline/embed <version> sha=<short-sha> built=<iso-utc>`.
15
+ *
16
+ * Exposed on the IIFE global as `nowline.version` / `nowline.sha` so
17
+ * pages and bug reports can identify the exact build without scraping
18
+ * the comment banner.
19
+ */
20
+ export const version = typeof __NOWLINE_EMBED_VERSION__ !== 'undefined' ? __NOWLINE_EMBED_VERSION__ : '0.0.0';
21
+ export const sha = typeof __NOWLINE_EMBED_SHA__ !== 'undefined' ? __NOWLINE_EMBED_SHA__ : 'unknown';
22
+ const DEFAULT_SELECTOR = 'pre code.language-nowline, code.language-nowline';
23
+ const initialConfig = {
24
+ theme: 'auto',
25
+ startOnLoad: true,
26
+ selector: DEFAULT_SELECTOR,
27
+ systemTheme: resolveSystemTheme(),
28
+ share: true,
29
+ };
30
+ let config = { ...initialConfig };
31
+ let autoStartScheduled = false;
32
+ export function initialize(options = {}) {
33
+ config = {
34
+ theme: options.theme ?? config.theme,
35
+ startOnLoad: options.startOnLoad ?? config.startOnLoad,
36
+ selector: options.selector ?? config.selector,
37
+ locale: options.locale ?? config.locale,
38
+ width: options.width ?? config.width,
39
+ today: options.today ?? config.today,
40
+ share: options.share ?? config.share,
41
+ sourceUrl: options.sourceUrl ?? config.sourceUrl,
42
+ // Re-read `prefers-color-scheme` on every initialize() so callers
43
+ // who explicitly want the latest system theme can ask for it by
44
+ // calling initialize() again. Auto-scan paths still use the value
45
+ // captured at initialize time.
46
+ systemTheme: resolveSystemTheme(),
47
+ };
48
+ }
49
+ /** Build the EmbedRenderOptions used by `render` and the auto-scan path. */
50
+ function renderOptionsFromConfig() {
51
+ return {
52
+ theme: effectiveTheme(config.theme, config.systemTheme),
53
+ locale: config.locale,
54
+ width: config.width,
55
+ today: config.today,
56
+ };
57
+ }
58
+ /**
59
+ * Render a single Nowline source string to an SVG. Useful for
60
+ * applications that want to control exactly when and where the SVG
61
+ * lands (custom `<div>` containers, dynamically loaded blocks, etc.).
62
+ */
63
+ export async function render(source, options = {}) {
64
+ const merged = {
65
+ ...renderOptionsFromConfig(),
66
+ ...options,
67
+ };
68
+ return renderSource(source, merged);
69
+ }
70
+ /**
71
+ * Parse a Nowline source string. Returns the AST and any lexer /
72
+ * parser / validator errors. Does not run layout or render — useful for
73
+ * editor experiences that want diagnostics without paying the render
74
+ * cost.
75
+ */
76
+ export async function parse(source) {
77
+ return parseSource(source);
78
+ }
79
+ /**
80
+ * Scan the DOM for Nowline blocks and replace each with its rendered
81
+ * SVG. Aliased as `run` for parity with Mermaid's recent API.
82
+ */
83
+ export async function init(overrides) {
84
+ const inputs = {
85
+ selector: overrides?.selector ?? config.selector,
86
+ theme: overrides?.theme ?? renderOptionsFromConfig().theme,
87
+ locale: overrides?.locale ?? config.locale,
88
+ width: overrides?.width ?? config.width,
89
+ today: overrides?.today ?? config.today,
90
+ share: overrides?.share ?? config.share,
91
+ sourceUrl: overrides?.sourceUrl ?? config.sourceUrl,
92
+ document: overrides?.document,
93
+ };
94
+ return runAutoScan(inputs);
95
+ }
96
+ /** Alias for `init`, matching Mermaid's `mermaid.run()`. */
97
+ export const run = init;
98
+ // IIFE-bundle bootstrap. When the bundled script tag loads on a page,
99
+ // the bundler invokes the module body; we schedule auto-scan to fire on
100
+ // DOMContentLoaded unless the page disables it with
101
+ // `nowline.initialize({ startOnLoad: false })` synchronously after the
102
+ // script tag.
103
+ //
104
+ // Guarded by `typeof document !== 'undefined'` so ESM consumers
105
+ // (Node tests, build pipelines, server-side rendering) don't trigger
106
+ // the auto-scan branch.
107
+ if (typeof document !== 'undefined' && !autoStartScheduled) {
108
+ autoStartScheduled = true;
109
+ const start = () => {
110
+ if (!config.startOnLoad)
111
+ return;
112
+ // Fire-and-forget; render errors are surfaced via `console.error`
113
+ // inside `runAutoScan`.
114
+ void init();
115
+ };
116
+ if (document.readyState === 'loading') {
117
+ document.addEventListener('DOMContentLoaded', start, { once: true });
118
+ }
119
+ else {
120
+ // Document is already parsed; defer to next microtask so any
121
+ // synchronous `initialize({ startOnLoad: false })` after the
122
+ // script tag still wins the race.
123
+ queueMicrotask(start);
124
+ }
125
+ }
126
+ // Test-only escape hatch. Exposed as a named export so tests can reset
127
+ // the module's hidden state (config, system-theme cache, the once-only
128
+ // console.warn latch) between cases.
129
+ export function __resetForTests() {
130
+ config = { ...initialConfig, systemTheme: resolveSystemTheme() };
131
+ autoStartScheduled = false;
132
+ __resetEmbedPipelineForTests();
133
+ __resetAutoScanForTests();
134
+ }
135
+ //# sourceMappingURL=index.js.map