@mdsvex/render 1.0.0-next.0 → 1.0.0-next.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/dist/component.d.ts +43 -0
- package/dist/component.js +32 -11
- package/dist/entities.d.ts +2 -0
- package/dist/html_cursor.d.ts +397 -0
- package/dist/html_cursor.js +4754 -436
- package/dist/index.d.ts +9 -0
- package/dist/index.js +24 -18
- package/dist/mappings.d.ts +117 -0
- package/dist/mappings.js +151 -8
- package/dist/scope.d.ts +52 -0
- package/dist/sourcemap.d.ts +108 -0
- package/dist/sourcemap.js +832 -68
- package/dist/stream.d.ts +87 -0
- package/dist/stream.js +123 -0
- package/package.json +22 -14
- package/src/Node.svelte +290 -114
- package/src/component.ts +31 -8
- package/src/entities.ts +226 -0
- package/src/html_cursor.ts +7166 -593
- package/src/index.ts +36 -9
- package/src/mappings.ts +239 -4
- package/src/scope.ts +127 -0
- package/src/sourcemap.ts +1713 -99
- package/src/stream.ts +223 -0
- package/CHANGELOG.md +0 -16
- package/test/_gen_chain.mjs +0 -67
- package/test/_vite_debug.mjs +0 -91
- package/test/_vite_debug2.mjs +0 -34
- package/test/component.spec.ts +0 -120
- package/test/html_cursor.spec.ts +0 -231
- package/test/mappings.spec.ts +0 -436
- package/test/wire_tree_builder.spec.ts +0 -139
- package/tsconfig.json +0 -11
- package/vite.config.build.ts +0 -33
package/dist/stream.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* what a streaming view needs from plugins, what they wrote, live, for the
|
|
3
|
+
* components that read it, and the nodes their deferred work changed
|
|
4
|
+
*
|
|
5
|
+
* const stream = new PluginStream({ plugins });
|
|
6
|
+
* stream.renderers.push(renderer);
|
|
7
|
+
* stream.on_change(() => renderer.update(stream.buffer, ''));
|
|
8
|
+
* for await (const batch of batches) stream.apply(batch);
|
|
9
|
+
* await stream.end();
|
|
10
|
+
*
|
|
11
|
+
* a component reads the data from the context under PLUGIN_DATA, which a
|
|
12
|
+
* compiled document sets too, so it reads the same in a stream and a compile
|
|
13
|
+
*/
|
|
14
|
+
import { PluginDispatcher } from '@mdsvex/parse';
|
|
15
|
+
import type { DataChange, DirectiveTable, HeadingIds, ParsePlugin, PluginDocument } from '@mdsvex/parse';
|
|
16
|
+
import type { NodeBuffer } from '@mdsvex/parse/utils';
|
|
17
|
+
import { WireTreeBuilder } from '@mdsvex/parse/wire-tree-builder';
|
|
18
|
+
/** the context key of what plugins wrote, the same in every copy of this module */
|
|
19
|
+
export declare const PLUGIN_DATA: unique symbol;
|
|
20
|
+
/** what plugins wrote, by plugin name, undefined while none wrote anything */
|
|
21
|
+
export type PluginDataValue = Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
22
|
+
/** the value under PLUGIN_DATA, current is read again as it changes */
|
|
23
|
+
export interface PluginDataContext {
|
|
24
|
+
readonly current: PluginDataValue | undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* what plugins wrote, followed through on_data, current is a new object after
|
|
28
|
+
* each change, read in a component or an effect it runs again when that comes
|
|
29
|
+
*/
|
|
30
|
+
export declare class LiveData implements PluginDataContext {
|
|
31
|
+
#private;
|
|
32
|
+
get current(): PluginDataValue | undefined;
|
|
33
|
+
/** the value of a key after a change, undefined once it holds nothing */
|
|
34
|
+
change({ plugin, key, value }: DataChange): void;
|
|
35
|
+
/** follows a dispatcher, returns what stops it */
|
|
36
|
+
follow(dispatcher: PluginDispatcher): () => void;
|
|
37
|
+
/** nothing written, for the next document */
|
|
38
|
+
reset(): void;
|
|
39
|
+
}
|
|
40
|
+
/** a renderer that caches blocks, a patched node renders its block again */
|
|
41
|
+
export interface PatchedBlocks {
|
|
42
|
+
invalidate(buf: NodeBuffer, nodes: readonly number[]): void;
|
|
43
|
+
}
|
|
44
|
+
export interface PluginStreamOptions {
|
|
45
|
+
plugins?: ParsePlugin[];
|
|
46
|
+
directive_handlers?: DirectiveTable[];
|
|
47
|
+
/** makes the id of each heading as it arrives, make_heading_ids in mdsvex */
|
|
48
|
+
headings?: HeadingIds;
|
|
49
|
+
/** what the handlers learn about the document, see set_document */
|
|
50
|
+
document?: PluginDocument;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* a document arriving over the wire with its plugins, the builder, the
|
|
54
|
+
* dispatcher, the data as it changes, and the nodes deferred tasks patch
|
|
55
|
+
*/
|
|
56
|
+
export declare class PluginStream {
|
|
57
|
+
readonly builder: WireTreeBuilder;
|
|
58
|
+
/** null for a stream with no plugin */
|
|
59
|
+
readonly dispatcher: PluginDispatcher | null;
|
|
60
|
+
/** what plugins wrote, for the components that read it */
|
|
61
|
+
readonly data: LiveData;
|
|
62
|
+
/** renderers whose cached blocks a patch drops */
|
|
63
|
+
readonly renderers: PatchedBlocks[];
|
|
64
|
+
private listeners;
|
|
65
|
+
private stops;
|
|
66
|
+
private ended;
|
|
67
|
+
constructor(options?: PluginStreamOptions);
|
|
68
|
+
/** the buffer the builder fills */
|
|
69
|
+
get buffer(): NodeBuffer;
|
|
70
|
+
/** a batch of the wire, then the deferred work that is ready */
|
|
71
|
+
apply(batch: unknown[][]): void;
|
|
72
|
+
/**
|
|
73
|
+
* the stream ended, after finish of the parser, runs the sequential passes,
|
|
74
|
+
* waits for the deferred tasks still running, then runs the document hooks,
|
|
75
|
+
* a promise when any of that waits, every block renders again after it
|
|
76
|
+
*/
|
|
77
|
+
end(): Promise<void> | undefined;
|
|
78
|
+
/** applies the deferred tasks that are ready, true when one patched a node */
|
|
79
|
+
patch(): boolean;
|
|
80
|
+
/** listener runs after each batch and each patch, so a view renders again */
|
|
81
|
+
on_change(listener: () => void): () => void;
|
|
82
|
+
/** stops following the dispatcher, a task still running applies nowhere */
|
|
83
|
+
stop(): void;
|
|
84
|
+
/** the whole tree may have changed, every block renders again */
|
|
85
|
+
private everything;
|
|
86
|
+
private changed;
|
|
87
|
+
}
|
package/dist/stream.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
var g = (i) => {
|
|
2
|
+
throw TypeError(i);
|
|
3
|
+
};
|
|
4
|
+
var b = (i, e, t) => e.has(i) || g("Cannot " + t);
|
|
5
|
+
var d = (i, e, t) => (b(i, e, "read from private field"), t ? t.call(i) : e.get(i)), u = (i, e, t) => e.has(i) ? g("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(i) : e.set(i, t), l = (i, e, t, s) => (b(i, e, "write to private field"), s ? s.call(i, t) : e.set(i, t), t);
|
|
6
|
+
import { PluginDispatcher as v, WireTextSource as _ } from "@mdsvex/parse";
|
|
7
|
+
import { WireTreeBuilder as m } from "@mdsvex/parse/wire-tree-builder";
|
|
8
|
+
import { createSubscriber as w } from "svelte/reactivity";
|
|
9
|
+
const y = 4294967295, P = Symbol.for(
|
|
10
|
+
"mdsvex.plugin_data"
|
|
11
|
+
);
|
|
12
|
+
var r, o, f;
|
|
13
|
+
class x {
|
|
14
|
+
constructor() {
|
|
15
|
+
u(this, r);
|
|
16
|
+
u(this, o, null);
|
|
17
|
+
u(this, f, w((e) => (l(this, o, e), () => {
|
|
18
|
+
l(this, o, null);
|
|
19
|
+
})));
|
|
20
|
+
}
|
|
21
|
+
get current() {
|
|
22
|
+
return d(this, f).call(this), d(this, r);
|
|
23
|
+
}
|
|
24
|
+
/** the value of a key after a change, undefined once it holds nothing */
|
|
25
|
+
change({ plugin: e, key: t, value: s }) {
|
|
26
|
+
var p;
|
|
27
|
+
const n = d(this, r), c = { ...n == null ? void 0 : n[e] };
|
|
28
|
+
s === void 0 ? delete c[t] : c[t] = s;
|
|
29
|
+
const a = { ...n };
|
|
30
|
+
Object.keys(c).length === 0 ? delete a[e] : a[e] = c, l(this, r, Object.keys(a).length === 0 ? void 0 : a), (p = d(this, o)) == null || p.call(this);
|
|
31
|
+
}
|
|
32
|
+
/** follows a dispatcher, returns what stops it */
|
|
33
|
+
follow(e) {
|
|
34
|
+
return e.on_data((t) => this.change(t));
|
|
35
|
+
}
|
|
36
|
+
/** nothing written, for the next document */
|
|
37
|
+
reset() {
|
|
38
|
+
var e;
|
|
39
|
+
d(this, r) !== void 0 && (l(this, r, void 0), (e = d(this, o)) == null || e.call(this));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
r = new WeakMap(), o = new WeakMap(), f = new WeakMap();
|
|
43
|
+
class T {
|
|
44
|
+
constructor(e = {}) {
|
|
45
|
+
this.data = new x(), this.renderers = [], this.listeners = [], this.stops = [], this.ended = !1;
|
|
46
|
+
const { plugins: t, directive_handlers: s } = e, h = t !== void 0 && t.length > 0 || s !== void 0 && s.length > 0 ? new v(
|
|
47
|
+
t,
|
|
48
|
+
new _([]),
|
|
49
|
+
s
|
|
50
|
+
) : null;
|
|
51
|
+
this.dispatcher = h, this.builder = new m(128, h ?? void 0), e.headings !== void 0 && this.builder.set_headings(e.headings), h !== null && (h.set_document(e.document), this.stops.push(
|
|
52
|
+
this.data.follow(h),
|
|
53
|
+
// a task that settled applies at once, and its node renders again
|
|
54
|
+
h.on_settled(() => {
|
|
55
|
+
this.patch() && this.changed();
|
|
56
|
+
})
|
|
57
|
+
));
|
|
58
|
+
}
|
|
59
|
+
/** the buffer the builder fills */
|
|
60
|
+
get buffer() {
|
|
61
|
+
return this.builder.get_buffer();
|
|
62
|
+
}
|
|
63
|
+
/** a batch of the wire, then the deferred work that is ready */
|
|
64
|
+
apply(e) {
|
|
65
|
+
this.builder.apply(e), this.patch(), this.changed();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* the stream ended, after finish of the parser, runs the sequential passes,
|
|
69
|
+
* waits for the deferred tasks still running, then runs the document hooks,
|
|
70
|
+
* a promise when any of that waits, every block renders again after it
|
|
71
|
+
*/
|
|
72
|
+
end() {
|
|
73
|
+
if (this.ended) return;
|
|
74
|
+
this.ended = !0, this.builder.end();
|
|
75
|
+
const e = this.dispatcher;
|
|
76
|
+
if (e === null) return;
|
|
77
|
+
const t = this.buffer;
|
|
78
|
+
e.run_sequential(t);
|
|
79
|
+
const s = e.finish(t);
|
|
80
|
+
if (this.everything(), s !== void 0)
|
|
81
|
+
return s.then(() => this.everything());
|
|
82
|
+
}
|
|
83
|
+
/** applies the deferred tasks that are ready, true when one patched a node */
|
|
84
|
+
patch() {
|
|
85
|
+
const e = this.dispatcher;
|
|
86
|
+
if (e === null) return !1;
|
|
87
|
+
const t = e.apply_ready();
|
|
88
|
+
if (t === null) return !1;
|
|
89
|
+
const s = this.buffer;
|
|
90
|
+
for (const n of this.renderers) n.invalidate(s, t);
|
|
91
|
+
return !0;
|
|
92
|
+
}
|
|
93
|
+
/** listener runs after each batch and each patch, so a view renders again */
|
|
94
|
+
on_change(e) {
|
|
95
|
+
return this.listeners.push(e), () => {
|
|
96
|
+
const t = this.listeners.indexOf(e);
|
|
97
|
+
t !== -1 && this.listeners.splice(t, 1);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** stops following the dispatcher, a task still running applies nowhere */
|
|
101
|
+
stop() {
|
|
102
|
+
for (const e of this.stops) e();
|
|
103
|
+
this.stops.length = 0, this.listeners.length = 0;
|
|
104
|
+
}
|
|
105
|
+
/** the whole tree may have changed, every block renders again */
|
|
106
|
+
everything() {
|
|
107
|
+
const e = this.buffer, t = [];
|
|
108
|
+
let s = e.first_child_at(0);
|
|
109
|
+
for (; s !== y && e.parent_at(s) === 0; )
|
|
110
|
+
t.push(s), s = e.next_at(s);
|
|
111
|
+
if (t.length !== 0)
|
|
112
|
+
for (const n of this.renderers) n.invalidate(e, t);
|
|
113
|
+
this.changed();
|
|
114
|
+
}
|
|
115
|
+
changed() {
|
|
116
|
+
for (const e of this.listeners.slice()) e();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export {
|
|
120
|
+
x as LiveData,
|
|
121
|
+
P as PLUGIN_DATA,
|
|
122
|
+
T as PluginStream
|
|
123
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdsvex/render",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/pngwn/MDsveX.git",
|
|
@@ -8,26 +8,34 @@
|
|
|
8
8
|
},
|
|
9
9
|
"description": "Renderers for the PFM parser wire format",
|
|
10
10
|
"type": "module",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"src"
|
|
14
|
+
],
|
|
11
15
|
"exports": {
|
|
12
16
|
".": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
15
19
|
},
|
|
16
20
|
"./html-cursor": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
21
|
+
"types": "./dist/html_cursor.d.ts",
|
|
22
|
+
"import": "./dist/html_cursor.js"
|
|
19
23
|
},
|
|
20
24
|
"./component": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
25
|
+
"types": "./dist/component.d.ts",
|
|
26
|
+
"import": "./dist/component.js"
|
|
23
27
|
},
|
|
24
28
|
"./mappings": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
29
|
+
"types": "./dist/mappings.d.ts",
|
|
30
|
+
"import": "./dist/mappings.js"
|
|
27
31
|
},
|
|
28
32
|
"./sourcemap": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
33
|
+
"types": "./dist/sourcemap.d.ts",
|
|
34
|
+
"import": "./dist/sourcemap.js"
|
|
35
|
+
},
|
|
36
|
+
"./stream": {
|
|
37
|
+
"types": "./dist/stream.d.ts",
|
|
38
|
+
"import": "./dist/stream.js"
|
|
31
39
|
},
|
|
32
40
|
"./Node.svelte": {
|
|
33
41
|
"types": "./src/Node.svelte",
|
|
@@ -36,7 +44,7 @@
|
|
|
36
44
|
}
|
|
37
45
|
},
|
|
38
46
|
"peerDependencies": {
|
|
39
|
-
"svelte": "^5.
|
|
47
|
+
"svelte": "^5.7.0"
|
|
40
48
|
},
|
|
41
49
|
"peerDependenciesMeta": {
|
|
42
50
|
"svelte": {
|
|
@@ -44,13 +52,13 @@
|
|
|
44
52
|
}
|
|
45
53
|
},
|
|
46
54
|
"dependencies": {
|
|
47
|
-
"@mdsvex/parse": "1.0.0-next.
|
|
55
|
+
"@mdsvex/parse": "1.0.0-next.2"
|
|
48
56
|
},
|
|
49
57
|
"author": "pngwn <hello@pngwn.io>",
|
|
50
58
|
"license": "MIT",
|
|
51
59
|
"scripts": {
|
|
52
60
|
"test": "vitest --disableConsoleIntercept",
|
|
53
61
|
"test:run": "vitest run --silent",
|
|
54
|
-
"build": "vite build --config vite.config.build.ts"
|
|
62
|
+
"build": "vite build --config vite.config.build.ts && tsc --rootDir src --declaration --emitDeclarationOnly --outDir dist"
|
|
55
63
|
}
|
|
56
64
|
}
|