@nowline/embed 0.6.0 → 0.7.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/dist/share.d.ts CHANGED
@@ -1,45 +1,2 @@
1
- export declare const DEFAULT_SHARE_BASE = "https://free.nowline.io/open";
2
- /**
3
- * The `share` initialize option selects where share links point.
4
- *
5
- * - `true` — use DEFAULT_SHARE_BASE (the default).
6
- * - `string` — a base URL with optional path; built via the URL API so
7
- * `https://foo.com/open` → `https://foo.com/open#text=…`.
8
- * - `false` / `'none'` — disable the share anchor entirely.
9
- * - `{ textUrl, remoteUrl }` — escape hatch for non-hash URL shapes;
10
- * `{text}` substituted with the base64url payload, `{url}` with the
11
- * percent-encoded source URL.
12
- */
13
- export type ShareOption = boolean | 'none' | string | {
14
- textUrl: string;
15
- remoteUrl: string;
16
- };
17
- /**
18
- * Encode source text → `#text=<base64url(zlib(utf8(source)))>`.
19
- *
20
- * The return value includes the `#text=` key so callers can use it
21
- * directly as a URL fragment.
22
- *
23
- * Sync, single code path, no feature-detect.
24
- */
25
- export declare function encodeText(source: string): string;
26
- export interface BuildShareLinkOptions {
27
- /** The roadmap source text (used to build the #text= fragment). */
28
- source: string;
29
- /**
30
- * Resolved source URL for the block (per-block → global → undefined).
31
- * Only `https:` URLs are emitted as `#url=`; anything else falls
32
- * back to the inline `#text=` encoding.
33
- */
34
- sourceUrl?: string | undefined;
35
- /** The `share` option from InitializeOptions. */
36
- share: ShareOption;
37
- }
38
- /**
39
- * Build the full "Share on Nowline" URL for a rendered block.
40
- *
41
- * Returns `null` when `share` is `false` or `'none'`, signalling that
42
- * no anchor should be rendered.
43
- */
44
- export declare function buildShareLink({ source, sourceUrl, share }: BuildShareLinkOptions): string | null;
1
+ export { type BuildShareLinkOptions, buildShareLink, DEFAULT_SHARE_BASE, encodeText, type ShareOption, } from '@nowline/share-link';
45
2
  //# sourceMappingURL=share.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"share.d.ts","sourceRoot":"","sources":["../src/share.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,kBAAkB,iCAAiC,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7F;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD;AAgBD,MAAM,WAAW,qBAAqB;IAClC,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,iDAAiD;IACjD,KAAK,EAAE,WAAW,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,qBAAqB,GAAG,MAAM,GAAG,IAAI,CAwBjG"}
1
+ {"version":3,"file":"share.d.ts","sourceRoot":"","sources":["../src/share.ts"],"names":[],"mappings":"AAMA,OAAO,EACH,KAAK,qBAAqB,EAC1B,cAAc,EACd,kBAAkB,EAClB,UAAU,EACV,KAAK,WAAW,GACnB,MAAM,qBAAqB,CAAC"}
package/dist/share.js CHANGED
@@ -1,75 +1,7 @@
1
- // Share-link generation for the "Share on Nowline" anchor that the
2
- // auto-scan loop appends after each rendered SVG.
3
- //
4
- // Encoding grammar (normative defined in specs/embed.md):
5
- // #text=base64url(zlib(utf8(source)))
6
- // #url=<https-url>
7
- //
8
- // zlib = RFC 1950 via fflate zlibSync (byte-compatible with native
9
- // CompressionStream('deflate')); base64url strips padding and maps
10
- // +→- /→_.
11
- //
12
- // Sync, works on every browser, no feature-detect.
13
- import { zlibSync } from 'fflate';
14
- export const DEFAULT_SHARE_BASE = 'https://free.nowline.io/open';
15
- /**
16
- * Encode source text → `#text=<base64url(zlib(utf8(source)))>`.
17
- *
18
- * The return value includes the `#text=` key so callers can use it
19
- * directly as a URL fragment.
20
- *
21
- * Sync, single code path, no feature-detect.
22
- */
23
- export function encodeText(source) {
24
- return `#text=${_encodePayload(source)}`;
25
- }
26
- /** base64url(zlib(utf8(source))) without the `#text=` prefix. */
27
- function _encodePayload(source) {
28
- const bytes = new TextEncoder().encode(source);
29
- const compressed = zlibSync(bytes);
30
- // Convert Uint8Array to binary string for btoa. Chunked to avoid
31
- // call-stack limits on large payloads.
32
- const chunk = 0x8000; // 32 KB — safe below JS engine stack limits
33
- let bin = '';
34
- for (let i = 0; i < compressed.length; i += chunk) {
35
- bin += String.fromCharCode(...compressed.subarray(i, i + chunk));
36
- }
37
- return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
38
- }
39
- /**
40
- * Build the full "Share on Nowline" URL for a rendered block.
41
- *
42
- * Returns `null` when `share` is `false` or `'none'`, signalling that
43
- * no anchor should be rendered.
44
- */
45
- export function buildShareLink({ source, sourceUrl, share }) {
46
- if (share === false || share === 'none') {
47
- return null;
48
- }
49
- if (typeof share === 'object') {
50
- // Template mode: { textUrl, remoteUrl }
51
- if (sourceUrl !== undefined && _isHttps(sourceUrl)) {
52
- return share.remoteUrl.replace('{url}', encodeURIComponent(sourceUrl));
53
- }
54
- return share.textUrl.replace('{text}', _encodePayload(source));
55
- }
56
- // share === true → DEFAULT_SHARE_BASE; share is a string → custom base URL
57
- const base = share === true ? DEFAULT_SHARE_BASE : share;
58
- const url = new URL(base);
59
- if (sourceUrl !== undefined && _isHttps(sourceUrl)) {
60
- url.hash = `url=${encodeURIComponent(sourceUrl)}`;
61
- }
62
- else {
63
- url.hash = `text=${_encodePayload(source)}`;
64
- }
65
- return url.toString();
66
- }
67
- function _isHttps(url) {
68
- try {
69
- return new URL(url).protocol === 'https:';
70
- }
71
- catch {
72
- return false;
73
- }
74
- }
1
+ // Share-link generation moved to the dependency-light @nowline/share-link
2
+ // leaf so the encoder is shared verbatim with @nowline/mcp (one
3
+ // spec-normative implementation — see specs/embed.md). This file stays as a
4
+ // thin re-export so internal importers (auto-scan.ts) and the package's
5
+ // public surface are unchanged.
6
+ export { buildShareLink, DEFAULT_SHARE_BASE, encodeText, } from '@nowline/share-link';
75
7
  //# sourceMappingURL=share.js.map
package/dist/share.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"share.js","sourceRoot":"","sources":["../src/share.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,kDAAkD;AAClD,EAAE;AACF,4DAA4D;AAC5D,wCAAwC;AACxC,qBAAqB;AACrB,EAAE;AACF,mEAAmE;AACnE,mEAAmE;AACnE,WAAW;AACX,EAAE;AACF,mDAAmD;AAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,MAAM,CAAC,MAAM,kBAAkB,GAAG,8BAA8B,CAAC;AAejE;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc;IACrC,OAAO,SAAS,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;AAC7C,CAAC;AAED,iEAAiE;AACjE,SAAS,cAAc,CAAC,MAAc;IAClC,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACnC,iEAAiE;IACjE,uCAAuC;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,4CAA4C;IAClE,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;QAChD,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,IAAI,CAAC,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AI,CAAC;QACD,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"share.js","sourceRoot":"","sources":["../src/share.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,gEAAgE;AAChE,4EAA4E;AAC5E,wEAAwE;AACxE,gCAAgC;AAEhC,OAAO,EAEH,cAAc,EACd,kBAAkB,EAClB,UAAU,GAEb,MAAM,qBAAqB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nowline/embed",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Browser embed bundle for Nowline. Drop a <script> tag and ```nowline``` blocks render in place.",
5
5
  "license": "Apache-2.0",
6
6
  "engines": {
@@ -39,12 +39,12 @@
39
39
  "cdn"
40
40
  ],
41
41
  "dependencies": {
42
- "fflate": "^0.8.3",
43
42
  "langium": "~4.2.4",
44
- "@nowline/layout": "0.6.0",
45
- "@nowline/core": "0.6.0",
46
- "@nowline/browser": "0.6.0",
47
- "@nowline/renderer": "0.6.0"
43
+ "@nowline/browser": "0.7.0",
44
+ "@nowline/core": "0.7.0",
45
+ "@nowline/layout": "0.7.0",
46
+ "@nowline/renderer": "0.7.0",
47
+ "@nowline/share-link": "0.7.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/node": "^25.9.1",
package/src/share.ts CHANGED
@@ -1,108 +1,13 @@
1
- // Share-link generation for the "Share on Nowline" anchor that the
2
- // auto-scan loop appends after each rendered SVG.
3
- //
4
- // Encoding grammar (normative defined in specs/embed.md):
5
- // #text=base64url(zlib(utf8(source)))
6
- // #url=<https-url>
7
- //
8
- // zlib = RFC 1950 via fflate zlibSync (byte-compatible with native
9
- // CompressionStream('deflate')); base64url strips padding and maps
10
- // +→- /→_.
11
- //
12
- // Sync, works on every browser, no feature-detect.
13
-
14
- import { zlibSync } from 'fflate';
15
-
16
- export const DEFAULT_SHARE_BASE = 'https://free.nowline.io/open';
17
-
18
- /**
19
- * The `share` initialize option selects where share links point.
20
- *
21
- * - `true` — use DEFAULT_SHARE_BASE (the default).
22
- * - `string` — a base URL with optional path; built via the URL API so
23
- * `https://foo.com/open` → `https://foo.com/open#text=…`.
24
- * - `false` / `'none'` — disable the share anchor entirely.
25
- * - `{ textUrl, remoteUrl }` — escape hatch for non-hash URL shapes;
26
- * `{text}` substituted with the base64url payload, `{url}` with the
27
- * percent-encoded source URL.
28
- */
29
- export type ShareOption = boolean | 'none' | string | { textUrl: string; remoteUrl: string };
30
-
31
- /**
32
- * Encode source text → `#text=<base64url(zlib(utf8(source)))>`.
33
- *
34
- * The return value includes the `#text=` key so callers can use it
35
- * directly as a URL fragment.
36
- *
37
- * Sync, single code path, no feature-detect.
38
- */
39
- export function encodeText(source: string): string {
40
- return `#text=${_encodePayload(source)}`;
41
- }
42
-
43
- /** base64url(zlib(utf8(source))) without the `#text=` prefix. */
44
- function _encodePayload(source: string): string {
45
- const bytes = new TextEncoder().encode(source);
46
- const compressed = zlibSync(bytes);
47
- // Convert Uint8Array to binary string for btoa. Chunked to avoid
48
- // call-stack limits on large payloads.
49
- const chunk = 0x8000; // 32 KB — safe below JS engine stack limits
50
- let bin = '';
51
- for (let i = 0; i < compressed.length; i += chunk) {
52
- bin += String.fromCharCode(...compressed.subarray(i, i + chunk));
53
- }
54
- return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
55
- }
56
-
57
- export interface BuildShareLinkOptions {
58
- /** The roadmap source text (used to build the #text= fragment). */
59
- source: string;
60
- /**
61
- * Resolved source URL for the block (per-block → global → undefined).
62
- * Only `https:` URLs are emitted as `#url=`; anything else falls
63
- * back to the inline `#text=` encoding.
64
- */
65
- sourceUrl?: string | undefined;
66
- /** The `share` option from InitializeOptions. */
67
- share: ShareOption;
68
- }
69
-
70
- /**
71
- * Build the full "Share on Nowline" URL for a rendered block.
72
- *
73
- * Returns `null` when `share` is `false` or `'none'`, signalling that
74
- * no anchor should be rendered.
75
- */
76
- export function buildShareLink({ source, sourceUrl, share }: BuildShareLinkOptions): string | null {
77
- if (share === false || share === 'none') {
78
- return null;
79
- }
80
-
81
- if (typeof share === 'object') {
82
- // Template mode: { textUrl, remoteUrl }
83
- if (sourceUrl !== undefined && _isHttps(sourceUrl)) {
84
- return share.remoteUrl.replace('{url}', encodeURIComponent(sourceUrl));
85
- }
86
- return share.textUrl.replace('{text}', _encodePayload(source));
87
- }
88
-
89
- // share === true → DEFAULT_SHARE_BASE; share is a string → custom base URL
90
- const base = share === true ? DEFAULT_SHARE_BASE : share;
91
- const url = new URL(base);
92
-
93
- if (sourceUrl !== undefined && _isHttps(sourceUrl)) {
94
- url.hash = `url=${encodeURIComponent(sourceUrl)}`;
95
- } else {
96
- url.hash = `text=${_encodePayload(source)}`;
97
- }
98
-
99
- return url.toString();
100
- }
101
-
102
- function _isHttps(url: string): boolean {
103
- try {
104
- return new URL(url).protocol === 'https:';
105
- } catch {
106
- return false;
107
- }
108
- }
1
+ // Share-link generation moved to the dependency-light @nowline/share-link
2
+ // leaf so the encoder is shared verbatim with @nowline/mcp (one
3
+ // spec-normative implementation — see specs/embed.md). This file stays as a
4
+ // thin re-export so internal importers (auto-scan.ts) and the package's
5
+ // public surface are unchanged.
6
+
7
+ export {
8
+ type BuildShareLinkOptions,
9
+ buildShareLink,
10
+ DEFAULT_SHARE_BASE,
11
+ encodeText,
12
+ type ShareOption,
13
+ } from '@nowline/share-link';