@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.
@@ -0,0 +1,9 @@
1
+ export { CursorHTMLRenderer } from './html_cursor.js';
2
+ export type { CursorBlockEntry, TemplateWrapper, CodeHighlighter, HighlightedBlock, HighlightedCode, HighlightWarningCode, PreMeta, SmartPunctuation, SmartPunctuationOptions, SmartQuotes, } from './html_cursor.js';
3
+ export { _emit, _node, _children, _resolve_mappings, _out_offsets, MapSink, escape, NONE, K_ROOT, K_TEXT, K_HTML, K_LINE_BREAK, K_FRONTMATTER, K_IMPORT_STATEMENT, } from './html_cursor.js';
4
+ export { ComponentRenderer } from './component.js';
5
+ export type { ComponentBlock } from './component.js';
6
+ export { CI_TEXT, CI_CODE, CI_SVELTE, CI_STRUCTURE } from './mappings.js';
7
+ export type { Mapping, CodeInformation, MappingRole, MappingData, } from './mappings.js';
8
+ export { build_line_starts, offset_to_position, mappings_to_v3, records_to_v3, trace_to_v3, trace_to_decoded, mapped_source_lines, } from './sourcemap.js';
9
+ export type { SourceMapV3, MapTrace, DecodedSegment, DecodedSourceMapV3, } from './sourcemap.js';
package/dist/index.js CHANGED
@@ -1,27 +1,33 @@
1
- import { CursorHTMLRenderer as o, K_FRONTMATTER as r, K_HTML as T, K_IMPORT_STATEMENT as t, K_LINE_BREAK as E, K_ROOT as p, K_TEXT as n, NONE as s, _children as R, _emit as i, _node as m, _resolve_mappings as C, escape as K } from "./html_cursor.js";
2
- import { ComponentRenderer as I } from "./component.js";
3
- import { CI_CODE as d, CI_STRUCTURE as M, CI_SVELTE as N, CI_TEXT as a } from "./mappings.js";
4
- import { build_line_starts as x, mappings_to_v3 as L, offset_to_position as A } from "./sourcemap.js";
1
+ import { CursorHTMLRenderer as o, K_FRONTMATTER as r, K_HTML as t, K_IMPORT_STATEMENT as T, K_LINE_BREAK as p, K_ROOT as s, K_TEXT as n, NONE as E, _children as d, _emit as i, _node as m, _out_offsets as R, _resolve_mappings as a, escape as f } from "./html_cursor.js";
2
+ import { ComponentRenderer as c } from "./component.js";
3
+ import { CI_CODE as I, CI_STRUCTURE as M, CI_SVELTE as O, CI_TEXT as l, MapSink as N } from "./mappings.js";
4
+ import { build_line_starts as v, mapped_source_lines as x, mappings_to_v3 as L, offset_to_position as S, records_to_v3 as A, trace_to_decoded as g, trace_to_v3 as H } from "./sourcemap.js";
5
5
  export {
6
- d as CI_CODE,
6
+ I as CI_CODE,
7
7
  M as CI_STRUCTURE,
8
- N as CI_SVELTE,
9
- a as CI_TEXT,
10
- I as ComponentRenderer,
8
+ O as CI_SVELTE,
9
+ l as CI_TEXT,
10
+ c as ComponentRenderer,
11
11
  o as CursorHTMLRenderer,
12
12
  r as K_FRONTMATTER,
13
- T as K_HTML,
14
- t as K_IMPORT_STATEMENT,
15
- E as K_LINE_BREAK,
16
- p as K_ROOT,
13
+ t as K_HTML,
14
+ T as K_IMPORT_STATEMENT,
15
+ p as K_LINE_BREAK,
16
+ s as K_ROOT,
17
17
  n as K_TEXT,
18
- s as NONE,
19
- R as _children,
18
+ N as MapSink,
19
+ E as NONE,
20
+ d as _children,
20
21
  i as _emit,
21
22
  m as _node,
22
- C as _resolve_mappings,
23
- x as build_line_starts,
24
- K as escape,
23
+ R as _out_offsets,
24
+ a as _resolve_mappings,
25
+ v as build_line_starts,
26
+ f as escape,
27
+ x as mapped_source_lines,
25
28
  L as mappings_to_v3,
26
- A as offset_to_position
29
+ S as offset_to_position,
30
+ A as records_to_v3,
31
+ g as trace_to_decoded,
32
+ H as trace_to_v3
27
33
  };
@@ -0,0 +1,117 @@
1
+ /**
2
+ * volar-compatible source mapping types.
3
+ *
4
+ * structurally compatible with @volar/source-map Mapping and
5
+ * @volar/language-core CodeInformation, no runtime dependency.
6
+ */
7
+ export interface Mapping<Data = unknown> {
8
+ sourceOffsets: number[];
9
+ generatedOffsets: number[];
10
+ lengths: number[];
11
+ generatedLengths?: number[];
12
+ data: Data;
13
+ }
14
+ export interface CodeInformation {
15
+ verification?: boolean | {
16
+ shouldReport?(source: string | undefined, code: string | number | undefined): boolean;
17
+ };
18
+ completion?: boolean | {
19
+ isAdditional?: boolean;
20
+ onlyImport?: boolean;
21
+ };
22
+ semantic?: boolean | {
23
+ shouldHighlight?(): boolean;
24
+ };
25
+ navigation?: boolean | {
26
+ shouldRename?(): boolean;
27
+ resolveRenameNewName?(newName: string): string;
28
+ resolveRenameEditText?(newText: string): string;
29
+ };
30
+ structure?: boolean;
31
+ format?: boolean;
32
+ }
33
+ /** text content: verification, semantic, navigation. */
34
+ export declare const CI_TEXT: CodeInformation;
35
+ /** code content (code spans, fences): semantic + navigation only. */
36
+ export declare const CI_CODE: CodeInformation;
37
+ /** svelte expressions: full capabilities. */
38
+ export declare const CI_SVELTE: CodeInformation;
39
+ /** generated structural elements: structure only. */
40
+ export declare const CI_STRUCTURE: CodeInformation;
41
+ export type MappingRole = 'node' | 'content' | 'open_syntax' | 'close_syntax';
42
+ export interface MappingData extends CodeInformation {
43
+ /** node buffer index: stable, monotonic in document order. */
44
+ nodeIndex: number;
45
+ /** what this mapping represents within the node. */
46
+ role: MappingRole;
47
+ }
48
+ declare function text_data(node_index: number, role: MappingRole): MappingData;
49
+ declare function code_data(node_index: number, role: MappingRole): MappingData;
50
+ declare function svelte_data(node_index: number, role: MappingRole): MappingData;
51
+ declare function structure_data(node_index: number, role: MappingRole): MappingData;
52
+ export declare const data_text: typeof text_data;
53
+ export declare const data_code: typeof code_data;
54
+ export declare const data_svelte: typeof svelte_data;
55
+ export declare const data_structure: typeof structure_data;
56
+ declare const enum Preset {
57
+ TEXT = 0,
58
+ CODE = 1,
59
+ SVELTE = 2,
60
+ STRUCTURE = 3
61
+ }
62
+ /** data preset, packed into a record code with the role */
63
+ export declare const P_TEXT = Preset.TEXT;
64
+ export declare const P_CODE = Preset.CODE;
65
+ export declare const P_SVELTE = Preset.SVELTE;
66
+ export declare const P_STRUCTURE = Preset.STRUCTURE;
67
+ export declare const R_NODE = 0;
68
+ export declare const R_CONTENT = 1;
69
+ export declare const R_OPEN_SYNTAX = 2;
70
+ export declare const R_CLOSE_SYNTAX = 3;
71
+ export declare function record_code(preset: number, role: number): number;
72
+ /**
73
+ * words per record, out index, out chunk count, source offset, source length,
74
+ * node index stored as uint32 and read back signed, and code
75
+ */
76
+ export declare const RECORD_SIZE = 6;
77
+ /** built exactly as the presets build it */
78
+ export declare function record_data(code: number, node_index: number): MappingData;
79
+ /**
80
+ * builds its arrays and data on each read, so a resolved document keeps one
81
+ * object per piece rather than four arrays and a data object
82
+ */
83
+ export declare class RecordMapping implements Mapping<MappingData> {
84
+ _source: number;
85
+ _generated: number;
86
+ _length: number;
87
+ _generated_length: number;
88
+ /** 16 * node index + 16 + record code */
89
+ _key: number;
90
+ /** the arrays of a mapping that is not one plain piece, held as given */
91
+ _arrays: Mapping<MappingData> | null;
92
+ constructor(source: number, generated: number, length: number, generated_length: number, key: number, arrays: Mapping<MappingData> | null);
93
+ get sourceOffsets(): number[];
94
+ get generatedOffsets(): number[];
95
+ get lengths(): number[];
96
+ get generatedLengths(): number[] | undefined;
97
+ get data(): MappingData;
98
+ /** keys in the order a plain literal had them */
99
+ toJSON(): Mapping<MappingData>;
100
+ }
101
+ export declare function record_mappings(rec: Uint32Array, n: number): Mapping<MappingData>[];
102
+ /**
103
+ * pending mappings as flat records until generated offsets are known, a typed
104
+ * buffer rather than objects since a walk pushes several per node
105
+ * @internal
106
+ */
107
+ export declare class MapSink {
108
+ rec: Uint32Array;
109
+ /** words used, a multiple of RECORD_SIZE */
110
+ n: number;
111
+ /** false drops syntax records, which a v3 map skips */
112
+ syntax: boolean;
113
+ grow(): Uint32Array;
114
+ begin(syntax: boolean): void;
115
+ release(): void;
116
+ }
117
+ export {};
package/dist/mappings.js CHANGED
@@ -1,23 +1,166 @@
1
- const t = {
1
+ const O = {
2
2
  verification: !0,
3
3
  semantic: !0,
4
4
  navigation: !0
5
- }, e = {
5
+ }, S = {
6
6
  semantic: !0,
7
7
  navigation: !0
8
- }, r = {
8
+ }, T = {
9
9
  verification: !0,
10
10
  completion: !0,
11
11
  semantic: !0,
12
12
  navigation: !0,
13
13
  structure: !0,
14
14
  format: !0
15
- }, i = {
15
+ }, m = {
16
16
  structure: !0
17
17
  };
18
+ function _(e, t) {
19
+ return {
20
+ verification: !0,
21
+ semantic: !0,
22
+ navigation: !0,
23
+ nodeIndex: e,
24
+ role: t
25
+ };
26
+ }
27
+ function h(e, t) {
28
+ return { semantic: !0, navigation: !0, nodeIndex: e, role: t };
29
+ }
30
+ function g(e, t) {
31
+ return {
32
+ verification: !0,
33
+ completion: !0,
34
+ semantic: !0,
35
+ navigation: !0,
36
+ structure: !0,
37
+ format: !0,
38
+ nodeIndex: e,
39
+ role: t
40
+ };
41
+ }
42
+ function l(e, t) {
43
+ return { structure: !0, nodeIndex: e, role: t };
44
+ }
45
+ const v = _, R = h, p = g, N = l, C = 0, A = 1, x = 2, P = 3, L = 0, w = 1, U = 2, M = 3;
46
+ function X(e, t) {
47
+ return e << 2 | t;
48
+ }
49
+ const i = 6, f = [
50
+ "node",
51
+ "content",
52
+ "open_syntax",
53
+ "close_syntax"
54
+ ];
55
+ function E(e, t) {
56
+ const n = f[e & 3];
57
+ switch (e >> 2) {
58
+ case 0:
59
+ return _(t, n);
60
+ case 1:
61
+ return h(t, n);
62
+ case 2:
63
+ return g(t, n);
64
+ default:
65
+ return l(t, n);
66
+ }
67
+ }
68
+ class y {
69
+ constructor(t, n, s, a, r, d) {
70
+ this._source = t, this._generated = n, this._length = s, this._generated_length = a, this._key = r, this._arrays = d;
71
+ }
72
+ get sourceOffsets() {
73
+ const t = this._arrays;
74
+ return t === null ? [this._source] : t.sourceOffsets;
75
+ }
76
+ get generatedOffsets() {
77
+ const t = this._arrays;
78
+ return t === null ? [this._generated] : t.generatedOffsets;
79
+ }
80
+ get lengths() {
81
+ const t = this._arrays;
82
+ return t === null ? [this._length] : t.lengths;
83
+ }
84
+ get generatedLengths() {
85
+ const t = this._arrays;
86
+ if (t !== null) return t.generatedLengths;
87
+ const n = this._generated_length;
88
+ return n === this._length ? void 0 : [n];
89
+ }
90
+ get data() {
91
+ return c(this._key);
92
+ }
93
+ /** keys in the order a plain literal had them */
94
+ toJSON() {
95
+ const t = this._arrays;
96
+ if (t !== null) return t;
97
+ const n = {
98
+ sourceOffsets: [this._source],
99
+ generatedOffsets: [this._generated],
100
+ lengths: [this._length],
101
+ data: c(this._key)
102
+ };
103
+ return this._generated_length !== this._length && (n.generatedLengths = [this._generated_length]), n;
104
+ }
105
+ }
106
+ function c(e) {
107
+ const t = e & 15;
108
+ return E(t, (e - t) / 16 - 1);
109
+ }
110
+ const o = 1 << 20;
111
+ function k(e, t) {
112
+ const n = t / i, s = new Array(
113
+ n < o ? n : o
114
+ );
115
+ let a = 0;
116
+ for (let r = 0; r < t; r += i)
117
+ s[a++] = new y(
118
+ e[r + 2],
119
+ e[r],
120
+ e[r + 3],
121
+ e[r + 1],
122
+ ((e[r + 4] | 0) + 1) * 16 + e[r + 5],
123
+ null
124
+ );
125
+ return s;
126
+ }
127
+ const I = 1 << 20, u = i * 256;
128
+ class D {
129
+ constructor() {
130
+ this.rec = new Uint32Array(u), this.n = 0, this.syntax = !0;
131
+ }
132
+ grow() {
133
+ const t = new Uint32Array(this.rec.length * 2);
134
+ return t.set(this.rec.subarray(0, this.n)), this.rec = t, t;
135
+ }
136
+ begin(t) {
137
+ this.n = 0, this.syntax = t;
138
+ }
139
+ release() {
140
+ this.n = 0, this.rec.length > I && (this.rec = new Uint32Array(u));
141
+ }
142
+ }
18
143
  export {
19
- e as CI_CODE,
20
- i as CI_STRUCTURE,
21
- r as CI_SVELTE,
22
- t as CI_TEXT
144
+ S as CI_CODE,
145
+ m as CI_STRUCTURE,
146
+ T as CI_SVELTE,
147
+ O as CI_TEXT,
148
+ D as MapSink,
149
+ A as P_CODE,
150
+ P as P_STRUCTURE,
151
+ x as P_SVELTE,
152
+ C as P_TEXT,
153
+ i as RECORD_SIZE,
154
+ M as R_CLOSE_SYNTAX,
155
+ w as R_CONTENT,
156
+ L as R_NODE,
157
+ U as R_OPEN_SYNTAX,
158
+ y as RecordMapping,
159
+ R as data_code,
160
+ N as data_structure,
161
+ p as data_svelte,
162
+ v as data_text,
163
+ X as record_code,
164
+ E as record_data,
165
+ k as record_mappings
23
166
  };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * a scope maps element names to imported components and chains to a parent,
3
+ * closest first, so a template or nested scope can chain in front of the root
4
+ */
5
+ /** one replacement, imported as name as local from specifier */
6
+ export interface ComponentImport {
7
+ /** the element name, also the export name */
8
+ readonly name: string;
9
+ readonly specifier: string;
10
+ /** generated local binding, internal and never api */
11
+ readonly local: string;
12
+ }
13
+ /** an element component_mode all keeps because a component can not take its directive */
14
+ export interface ReplaceWarning {
15
+ readonly tag: string;
16
+ /** the first directive it carries, such as bind:value */
17
+ readonly directive: string;
18
+ /** offset of the element in the source */
19
+ readonly start: number;
20
+ }
21
+ export interface ComponentSource {
22
+ /** emitted verbatim as an import specifier */
23
+ specifier: string;
24
+ /** the export names of the module */
25
+ names: string[];
26
+ }
27
+ export declare class ComponentScope {
28
+ readonly parent: ComponentScope | null;
29
+ /** names added here and in every parent */
30
+ readonly size: number;
31
+ private readonly own;
32
+ private readonly locals;
33
+ /**
34
+ * sources are lowest precedence first so a later one replaces a name,
35
+ * suffix keeps the locals of different scopes apart
36
+ */
37
+ constructor(sources: readonly ComponentSource[], suffix: string, parent?: ComponentScope | null);
38
+ /** the replacement for an element name, closest scope first */
39
+ get(name: string): ComponentImport | undefined;
40
+ private local_for;
41
+ }
42
+ /** a default import, a template the document is wrapped in */
43
+ export interface DefaultImport {
44
+ readonly specifier: string;
45
+ readonly local: string;
46
+ }
47
+ /**
48
+ * one statement per module and one named import per replacement in first use
49
+ * order, never a namespace import so unused components shake out, a default
50
+ * import comes first and shares the statement of its module
51
+ */
52
+ export declare function component_imports(used: readonly ComponentImport[], main?: DefaultImport): string;
@@ -0,0 +1,108 @@
1
+ /**
2
+ * sourcemap utilities: line-starts, offset to position, vlq, v3 conversion.
3
+ */
4
+ import type { Mapping, MappingData, MapSink } from './mappings.js';
5
+ /** build an array of byte offsets where each line begins. line 0 starts at 0. */
6
+ export declare function build_line_starts(source: string): Uint32Array;
7
+ /** convert a byte offset to [line, column] using a precomputed line_starts table. */
8
+ export declare function offset_to_position(line_starts: Uint32Array, offset: number): [line: number, col: number];
9
+ export interface SourceMapV3 {
10
+ version: 3;
11
+ file?: string;
12
+ sources: string[];
13
+ sourcesContent: (string | null)[];
14
+ names: string[];
15
+ mappings: string;
16
+ }
17
+ /**
18
+ * trace records as Rec records encode, dropping what the encoding skips
19
+ * @internal
20
+ */
21
+ export declare function trace_of_records(rec: Uint32Array, n: number): Uint32Array;
22
+ /**
23
+ * convert Mapping<MappingData>[] to a v3 sourcemap.
24
+ *
25
+ * emits content spans (for cursor placement) and node span start anchors
26
+ * (for block identification). skips open_syntax and close_syntax to avoid
27
+ * overlapping ranges that cause nondeterministic cursor jumps in devtools.
28
+ */
29
+ export declare function mappings_to_v3(mappings: Mapping<MappingData>[], source: string, generated: string, file?: string): SourceMapV3;
30
+ /** @internal equals mappings_to_v3 over the Mapping objects the records resolve to */
31
+ export declare function records_to_v3(sink: MapSink, offsets: Uint32Array | null, source: string, generated: string, file?: string): SourceMapV3;
32
+ /**
33
+ * records counted in out chunks as records of generated offsets, offsets holds
34
+ * the offset of each chunk then the end
35
+ * @internal
36
+ */
37
+ export declare function records_by_offset(rec: Uint32Array, n: number, offsets: Uint32Array): Uint32Array;
38
+ export declare function map_basename(file?: string): string;
39
+ /** @internal trace_to_v3 over the trace records of a sink */
40
+ export declare function trace_records_to_v3(sink: MapSink, source: string, generated: string, file?: string): SourceMapV3;
41
+ /**
42
+ * a render copied out of the shared buffers to build its map later, records
43
+ * of generated offsets from start to split, buf may hold other traces
44
+ */
45
+ export interface MapTrace {
46
+ buf: Uint32Array;
47
+ start: number;
48
+ split: number;
49
+ end: number;
50
+ }
51
+ export declare function reserve_trace(rec_words: number, offset_words: number, out: MapTrace): MapTrace;
52
+ /**
53
+ * the slab with at least words free from trace_free_at, for records written
54
+ * in place
55
+ */
56
+ export declare function trace_room(words: number): Uint32Array;
57
+ export declare function trace_free_at(): number;
58
+ /** out as the trace of words start to end written in place into buf */
59
+ export declare function trace_take(buf: Uint32Array, start: number, end: number, out: MapTrace): void;
60
+ /** @internal */
61
+ export declare function trace_to_v3(trace: MapTrace, source: string, generated: string, file?: string): SourceMapV3;
62
+ export type DecodedSegment = [
63
+ gen_col: number,
64
+ source: number,
65
+ src_line: number,
66
+ src_col: number
67
+ ];
68
+ export interface DecodedSourceMapV3 {
69
+ version: 3;
70
+ file?: string;
71
+ sources: string[];
72
+ sourcesContent: (string | null)[];
73
+ names: string[];
74
+ mappings: DecodedSegment[][];
75
+ }
76
+ /**
77
+ * only the listed generated lines hold segments, each equal to that line of
78
+ * the decoded trace_to_v3 map, so lookups on them match the full map
79
+ * @internal
80
+ */
81
+ export declare function trace_to_decoded(trace: MapTrace, source: string, generated: string, lines: ArrayLike<number>, file?: string): DecodedSourceMapV3;
82
+ /**
83
+ * source lines of v3 mappings, unordered with repeats, null when a segment is
84
+ * one decoders read differently or names another source
85
+ * @internal
86
+ */
87
+ export declare function mapped_source_lines(mappings: string | readonly (readonly number[])[][]): number[] | null;
88
+ /** the chained mappings as ascii bytes */
89
+ export interface ChainedMappings {
90
+ /** the mappings run from start for length bytes */
91
+ bytes: Uint8Array;
92
+ start: number;
93
+ length: number;
94
+ /** names in first use order, null for none */
95
+ names: string[] | null;
96
+ /** whether any segment reached the source, then it is the only source */
97
+ sourced: boolean;
98
+ }
99
+ /**
100
+ * chains a compile map from the html onto the map of the html in trace, the
101
+ * mappings and names equal @ampproject/remapping of [compile, trace_to_v3],
102
+ * null when the compile mappings are ones it leaves to remapping, the next
103
+ * call reuses the bytes, source_normalized means source holds no \r, the
104
+ * mappings go into dest from dest_start unless they outgrow it, keeping the
105
+ * bytes before dest_start, mappings_bytes is the utf8 of compile_mappings
106
+ * @internal
107
+ */
108
+ export declare function chain_trace(compile_mappings: string, compile_names: readonly string[], trace: MapTrace, source: string, generated: string, source_normalized?: boolean, dest?: Uint8Array | null, dest_start?: number, mappings_bytes?: Uint8Array | null, mappings_length?: number): ChainedMappings | null;