@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/meta.json +72 -6
- package/dist/nowline.esm.js +4 -4
- package/dist/nowline.esm.js.map +3 -3
- package/dist/nowline.min.js +49 -49
- package/dist/nowline.min.js.map +3 -3
- package/dist/share.d.ts +1 -44
- package/dist/share.d.ts.map +1 -1
- package/dist/share.js +6 -74
- package/dist/share.js.map +1 -1
- package/package.json +6 -6
- package/src/share.ts +13 -108
package/dist/share.d.ts
CHANGED
|
@@ -1,45 +1,2 @@
|
|
|
1
|
-
export
|
|
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
|
package/dist/share.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"share.d.ts","sourceRoot":"","sources":["../src/share.ts"],"names":[],"mappings":"
|
|
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
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
|
|
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,
|
|
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.
|
|
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/
|
|
45
|
-
"@nowline/core": "0.
|
|
46
|
-
"@nowline/
|
|
47
|
-
"@nowline/renderer": "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
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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';
|