satorigear 0.0.0 → 0.0.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/LICENSE CHANGED
@@ -1,22 +1,21 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2023-2024 KazariEX
3
+ Copyright (c) 2025-present KazariEX
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the “Software”), to deal in
7
- the Software without restriction, including without limitation the rights to use,
8
- copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9
- Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
11
 
12
12
  The above copyright notice and this permission notice shall be included in all
13
13
  copies or substantial portions of the Software.
14
14
 
15
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ 奔走も虚しく、技術・流通を手に入れた地霊殿は、兵器の開発に乗り出した。
2
+
3
+ その兵器の名は——
4
+
5
+ <h1 align="center">サトリギア</h1>
6
+
7
+ <pre align="center">🧪 Working in Progress</pre>
8
+
9
+ <p align="center">
10
+ <a href="https://www.npmjs.com/package/satorigear"><img
11
+ src="https://img.shields.io/npm/v/satorigear?color=EA7FA0&labelColor=232122"
12
+ alt="[version]"
13
+ ></a>
14
+ <a href="https://www.npmjs.com/package/satorigear"><img
15
+ src="https://img.shields.io/npm/dm/satorigear?color=EA7FA0&labelColor=232122"
16
+ alt="[downloads]"
17
+ ></a>
18
+ <a href="https://github.com/KazariEX/satorigear/blob/main/LICENSE"><img
19
+ src="https://img.shields.io/github/license/KazariEX/satorigear?color=EA7FA0&labelColor=232122"
20
+ alt="[license]"
21
+ ></a>
22
+ </p>
23
+
24
+ SatoriGear is a blazing fast markdown parser with full incremental support that outputs MDAST.
25
+
26
+ It includes built-in support for GFM and MDC syntax and is fully compliant with the CommonMark specification. The plugin API is not yet public.
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pnpm i satorigear
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ```ts
37
+ import { createParser } from "satorigear";
38
+
39
+ const parser = createParser({
40
+ features: {
41
+ attributes: true,
42
+ binding: true,
43
+ component: true,
44
+ footnote: true,
45
+ frontmatter: true,
46
+ math: true,
47
+ strikethrough: true,
48
+ table: true,
49
+ },
50
+ });
51
+
52
+ // one-shot parse
53
+ const mdast = parser.parse("...");
54
+
55
+ // incremental edit
56
+ const document = parser.createDocument("...");
57
+ document.edit([
58
+ { start: 66, end: 66, text: ":" },
59
+ { start: 67, end: 67, text: "nuxt-img" },
60
+ ]);
61
+ const mdast = document.snapthot();
62
+ ```
63
+
64
+ ## Performance
65
+
66
+ Benchmarked against Sätteri and Remark, which also produce MDAST, with feature sets kept as equivalent as possible for each profile. Since Sätteri's `markdownToMdast` returns a lazily materialized tree, parse-only and fully materialized results are reported separately.
67
+
68
+ <!-- benchmark:start environment -->
69
+
70
+ > Median of 5 isolated mean-time runs at commit [`9570c63`](https://github.com/KazariEX/satorigear/commit/9570c634a28feffd6f437f3544071ff139f16f2f) on Apple M3, node 26.5.0, arm64-darwin. SatoriGear and Sätteri run in paired AB/BA order; comparisons are normalized to SatoriGear (↑ faster, ↓ slower). Lower time and higher throughput are better.
71
+
72
+ <!-- benchmark:end -->
73
+
74
+ <!-- benchmark:start parse only -->
75
+
76
+ <details>
77
+ <summary><strong>Parse only</strong></summary>
78
+
79
+ #### CommonMark
80
+
81
+ ##### CommonMark 0.31.2 specification, 205025 bytes, 1 document
82
+
83
+ | Engine | Mean time | vs. SatoriGear | Throughput |
84
+ | --- | ---: | ---: | ---: |
85
+ | **SatoriGear** | 2.46 ms | baseline | 79.5 MiB/s |
86
+ | Sätteri | 1.13 ms | ↑ 2.17× | 173 MiB/s |
87
+ | Remark | 62.0 ms | ↓ 25.00× | 3.16 MiB/s |
88
+
89
+ ##### CommonMark 0.31.2 examples, 14919 bytes, 652 documents
90
+
91
+ | Engine | Mean time | vs. SatoriGear | Throughput |
92
+ | --- | ---: | ---: | ---: |
93
+ | **SatoriGear** | 1.10 ms | baseline | 13.0 MiB/s |
94
+ | Sätteri | 2.70 ms | ↓ 2.46× | 5.28 MiB/s |
95
+ | Remark | 26.8 ms | ↓ 24.44× | 0.53 MiB/s |
96
+
97
+ #### Built-in features
98
+
99
+ ##### Rust release history, 910115 bytes, 1 document
100
+
101
+ | Engine | Mean time | vs. SatoriGear | Throughput |
102
+ | --- | ---: | ---: | ---: |
103
+ | **SatoriGear** | 24.8 ms | baseline | 35.1 MiB/s |
104
+ | Sätteri | 26.6 ms | ↓ 1.07× | 32.7 MiB/s |
105
+
106
+ ##### Public APIs README, 232580 bytes, 1 document
107
+
108
+ | Engine | Mean time | vs. SatoriGear | Throughput |
109
+ | --- | ---: | ---: | ---: |
110
+ | **SatoriGear** | 7.35 ms | baseline | 30.2 MiB/s |
111
+ | Sätteri | 2.41 ms | ↑ 3.06× | 92.2 MiB/s |
112
+
113
+ </details>
114
+
115
+ <!-- benchmark:end -->
116
+
117
+ <!-- benchmark:start fully materialized -->
118
+
119
+ <details>
120
+ <summary><strong>Fully materialized</strong></summary>
121
+
122
+ #### CommonMark
123
+
124
+ ##### CommonMark 0.31.2 specification, 205025 bytes, 1 document
125
+
126
+ | Engine | Mean time | vs. SatoriGear | Throughput |
127
+ | --- | ---: | ---: | ---: |
128
+ | **SatoriGear** | 2.50 ms | baseline | 78.1 MiB/s |
129
+ | Sätteri | 5.52 ms | ↓ 2.20× | 35.4 MiB/s |
130
+ | Remark | 60.2 ms | ↓ 24.11× | 3.25 MiB/s |
131
+
132
+ ##### CommonMark 0.31.2 examples, 14919 bytes, 652 documents
133
+
134
+ | Engine | Mean time | vs. SatoriGear | Throughput |
135
+ | --- | ---: | ---: | ---: |
136
+ | **SatoriGear** | 1.12 ms | baseline | 12.7 MiB/s |
137
+ | Sätteri | 5.91 ms | ↓ 5.30× | 2.41 MiB/s |
138
+ | Remark | 26.3 ms | ↓ 23.29× | 0.54 MiB/s |
139
+
140
+ #### Built-in features
141
+
142
+ ##### Rust release history, 910115 bytes, 1 document
143
+
144
+ | Engine | Mean time | vs. SatoriGear | Throughput |
145
+ | --- | ---: | ---: | ---: |
146
+ | **SatoriGear** | 25.2 ms | baseline | 34.5 MiB/s |
147
+ | Sätteri | 79.8 ms | ↓ 3.20× | 10.9 MiB/s |
148
+
149
+ ##### Public APIs README, 232580 bytes, 1 document
150
+
151
+ | Engine | Mean time | vs. SatoriGear | Throughput |
152
+ | --- | ---: | ---: | ---: |
153
+ | **SatoriGear** | 7.82 ms | baseline | 28.4 MiB/s |
154
+ | Sätteri | 20.8 ms | ↓ 2.66× | 10.7 MiB/s |
155
+
156
+ </details>
157
+
158
+ <!-- benchmark:end -->
package/dist/index.d.mts CHANGED
@@ -1,2 +1,114 @@
1
-
2
- export { }
1
+ import { Literal, Node, PhrasingContent, Root, RootContent } from "mdast";
2
+ //#region src/source-view.d.ts
3
+ interface SourceSpan {
4
+ end: number;
5
+ start: number;
6
+ }
7
+ interface TextEdit extends SourceSpan {
8
+ text: string;
9
+ }
10
+ //#endregion
11
+ //#region src/document.d.ts
12
+ interface EditResult {
13
+ changedSpan: SourceSpan;
14
+ }
15
+ interface Document {
16
+ readonly source: string;
17
+ edit: (edits: readonly TextEdit[]) => EditResult;
18
+ snapshot: () => Root;
19
+ }
20
+ //#endregion
21
+ //#region src/profile/features/formatting.d.ts
22
+ interface StrikethroughOptions {
23
+ singleTilde?: boolean;
24
+ }
25
+ //#endregion
26
+ //#region src/profile/features/frontmatter.d.ts
27
+ type FrontmatterMarker = "+" | "-";
28
+ interface FrontmatterOptions {
29
+ marker: FrontmatterMarker;
30
+ }
31
+ //#endregion
32
+ //#region src/profile/features/math/types.d.ts
33
+ interface MathOptions {
34
+ singleDollarTextMath?: boolean;
35
+ }
36
+ interface Math extends Literal {
37
+ type: "math";
38
+ meta: string | null;
39
+ }
40
+ interface InlineMath extends Literal {
41
+ type: "inlineMath";
42
+ }
43
+ declare module "mdast" {
44
+ interface BlockContentMap {
45
+ math: Math;
46
+ }
47
+ interface PhrasingContentMap {
48
+ inlineMath: InlineMath;
49
+ }
50
+ interface RootContentMap {
51
+ inlineMath: InlineMath;
52
+ math: Math;
53
+ }
54
+ }
55
+ //#endregion
56
+ //#region src/profile/index.d.ts
57
+ interface FeatureOptions {
58
+ attributes?: boolean;
59
+ binding?: boolean;
60
+ component?: boolean;
61
+ footnote?: boolean;
62
+ frontmatter?: boolean | FrontmatterOptions;
63
+ math?: boolean | MathOptions;
64
+ strikethrough?: boolean | StrikethroughOptions;
65
+ table?: boolean;
66
+ }
67
+ //#endregion
68
+ //#region src/parser.d.ts
69
+ interface Parser {
70
+ createDocument: (source: string) => Document;
71
+ parse: (source: string) => Root;
72
+ }
73
+ interface ParserOptions {
74
+ features?: FeatureOptions;
75
+ }
76
+ declare function createParser(options?: ParserOptions): Parser;
77
+ //#endregion
78
+ //#region src/profile/features/attributes/types.d.ts
79
+ type AttributeValue = string | number | boolean | null | AttributeValue[] | {
80
+ [key: string]: AttributeValue;
81
+ };
82
+ type Attributes = Record<string, AttributeValue>;
83
+ declare module "mdast" {
84
+ interface Node {
85
+ attributes?: Attributes;
86
+ }
87
+ }
88
+ //#endregion
89
+ //#region src/profile/features/component/types.d.ts
90
+ interface BlockComponent extends Node {
91
+ type: "blockComponent";
92
+ name: string;
93
+ attributes: Attributes;
94
+ children: RootContent[];
95
+ }
96
+ interface InlineComponent extends Node {
97
+ type: "inlineComponent";
98
+ name: string;
99
+ attributes: Attributes;
100
+ children: PhrasingContent[];
101
+ }
102
+ declare module "mdast" {
103
+ interface BlockContentMap {
104
+ blockComponent: BlockComponent;
105
+ }
106
+ interface PhrasingContentMap {
107
+ inlineComponent: InlineComponent;
108
+ }
109
+ interface RootContentMap {
110
+ blockComponent: BlockComponent;
111
+ }
112
+ }
113
+ //#endregion
114
+ export { type AttributeValue, type Attributes, type BlockComponent, type Document, type EditResult, type FeatureOptions, type FrontmatterMarker, type FrontmatterOptions, type InlineComponent, type InlineMath, type Math, type MathOptions, Parser, ParserOptions, type StrikethroughOptions, type TextEdit, createParser };