@unfold-mdx/react 0.0.1
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 +21 -0
- package/README.md +275 -0
- package/dist/chunk-OX5XKYQT.js +218 -0
- package/dist/codeDiff-BVwZfdt9.d.cts +19 -0
- package/dist/codeDiff-BVwZfdt9.d.ts +19 -0
- package/dist/diff/index.cjs +248 -0
- package/dist/diff/index.d.cts +37 -0
- package/dist/diff/index.d.ts +37 -0
- package/dist/diff/index.js +14 -0
- package/dist/index.cjs +626 -0
- package/dist/index.d.cts +65 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +378 -0
- package/dist/shiki/index.cjs +125 -0
- package/dist/shiki/index.d.cts +14 -0
- package/dist/shiki/index.d.ts +14 -0
- package/dist/shiki/index.js +100 -0
- package/package.json +88 -0
- package/theme.css +212 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/diff/index.ts
|
|
21
|
+
var diff_exports = {};
|
|
22
|
+
__export(diff_exports, {
|
|
23
|
+
codeDiff: () => codeDiff,
|
|
24
|
+
sentenceDiff: () => sentenceDiff,
|
|
25
|
+
tokenize: () => tokenize,
|
|
26
|
+
tokenizeCodeLine: () => tokenizeCodeLine,
|
|
27
|
+
tokenizeLines: () => tokenizeLines
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(diff_exports);
|
|
30
|
+
|
|
31
|
+
// src/diff/tokenize.ts
|
|
32
|
+
function tokenize(text) {
|
|
33
|
+
if (!text) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
const splitRegex = /(?<=(?:(?<!\.)\.(?!\.)|[!?]))(?=\s|$)/;
|
|
37
|
+
return text.split(splitRegex).map((token) => token.trim()).filter((token) => token.length > 0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/diff/sentenceDiff.ts
|
|
41
|
+
var import_diff_match_patch = require("diff-match-patch");
|
|
42
|
+
function sentenceDiff(prev, next) {
|
|
43
|
+
const prevSentences = tokenize(prev);
|
|
44
|
+
const nextSentences = tokenize(next);
|
|
45
|
+
const sentenceToChar = /* @__PURE__ */ new Map();
|
|
46
|
+
const charToSentence = [];
|
|
47
|
+
function getCharForSentence(sentence) {
|
|
48
|
+
let char = sentenceToChar.get(sentence);
|
|
49
|
+
if (char === void 0) {
|
|
50
|
+
const code = charToSentence.length;
|
|
51
|
+
char = String.fromCharCode(code);
|
|
52
|
+
sentenceToChar.set(sentence, char);
|
|
53
|
+
charToSentence.push(sentence);
|
|
54
|
+
}
|
|
55
|
+
return char;
|
|
56
|
+
}
|
|
57
|
+
const prevChars = prevSentences.map(getCharForSentence).join("");
|
|
58
|
+
const nextChars = nextSentences.map(getCharForSentence).join("");
|
|
59
|
+
const dmp = new import_diff_match_patch.diff_match_patch();
|
|
60
|
+
const diffs = dmp.diff_main(prevChars, nextChars);
|
|
61
|
+
dmp.diff_cleanupSemantic(diffs);
|
|
62
|
+
const result = [];
|
|
63
|
+
let i = 0;
|
|
64
|
+
while (i < diffs.length) {
|
|
65
|
+
const [op, text] = diffs[i];
|
|
66
|
+
if (op === 0) {
|
|
67
|
+
for (let j = 0; j < text.length; j++) {
|
|
68
|
+
result.push({
|
|
69
|
+
kind: "equal",
|
|
70
|
+
sentence: charToSentence[text.charCodeAt(j)]
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
i++;
|
|
74
|
+
} else if (op === -1 && i + 1 < diffs.length && diffs[i + 1][0] === 1) {
|
|
75
|
+
const deleteText = text;
|
|
76
|
+
const insertText = diffs[i + 1][1];
|
|
77
|
+
const deleteLen = deleteText.length;
|
|
78
|
+
const insertLen = insertText.length;
|
|
79
|
+
const minLen = Math.min(deleteLen, insertLen);
|
|
80
|
+
for (let j = 0; j < minLen; j++) {
|
|
81
|
+
result.push({
|
|
82
|
+
kind: "modified",
|
|
83
|
+
before: charToSentence[deleteText.charCodeAt(j)],
|
|
84
|
+
after: charToSentence[insertText.charCodeAt(j)]
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
for (let j = minLen; j < deleteLen; j++) {
|
|
88
|
+
result.push({
|
|
89
|
+
kind: "removed",
|
|
90
|
+
sentence: charToSentence[deleteText.charCodeAt(j)]
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
for (let j = minLen; j < insertLen; j++) {
|
|
94
|
+
result.push({
|
|
95
|
+
kind: "added",
|
|
96
|
+
sentence: charToSentence[insertText.charCodeAt(j)]
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
i += 2;
|
|
100
|
+
} else if (op === -1) {
|
|
101
|
+
for (let j = 0; j < text.length; j++) {
|
|
102
|
+
result.push({
|
|
103
|
+
kind: "removed",
|
|
104
|
+
sentence: charToSentence[text.charCodeAt(j)]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
i++;
|
|
108
|
+
} else if (op === 1) {
|
|
109
|
+
for (let j = 0; j < text.length; j++) {
|
|
110
|
+
result.push({
|
|
111
|
+
kind: "added",
|
|
112
|
+
sentence: charToSentence[text.charCodeAt(j)]
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
i++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/diff/codeTokenize.ts
|
|
122
|
+
function tokenizeLines(code) {
|
|
123
|
+
if (code === "") return [];
|
|
124
|
+
return code.split(/\r?\n/);
|
|
125
|
+
}
|
|
126
|
+
function tokenizeCodeLine(line) {
|
|
127
|
+
if (line === "") return [];
|
|
128
|
+
const regex = /([a-zA-Z0-9_]+|\s+|[^a-zA-Z0-9_\s])/g;
|
|
129
|
+
const tokens = [];
|
|
130
|
+
let match;
|
|
131
|
+
while ((match = regex.exec(line)) !== null) {
|
|
132
|
+
if (match[0].length > 0) {
|
|
133
|
+
tokens.push(match[0]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return tokens;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/diff/codeDiff.ts
|
|
140
|
+
var import_diff_match_patch2 = require("diff-match-patch");
|
|
141
|
+
function codeDiff(prev, next) {
|
|
142
|
+
if (prev === "" && next !== "") {
|
|
143
|
+
return tokenizeLines(next).map((line) => ({
|
|
144
|
+
kind: "added",
|
|
145
|
+
tokens: tokenizeCodeLine(line).map((t) => ({ kind: "added", text: t }))
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
const prevLines = tokenizeLines(prev);
|
|
149
|
+
const nextLines = tokenizeLines(next);
|
|
150
|
+
const lineToChar = /* @__PURE__ */ new Map();
|
|
151
|
+
const charToLine = [];
|
|
152
|
+
function getCharForLine(line) {
|
|
153
|
+
let char = lineToChar.get(line);
|
|
154
|
+
if (char === void 0) {
|
|
155
|
+
const code = charToLine.length;
|
|
156
|
+
char = String.fromCharCode(code);
|
|
157
|
+
lineToChar.set(line, char);
|
|
158
|
+
charToLine.push(line);
|
|
159
|
+
}
|
|
160
|
+
return char;
|
|
161
|
+
}
|
|
162
|
+
const prevChars = prevLines.map(getCharForLine).join("");
|
|
163
|
+
const nextChars = nextLines.map(getCharForLine).join("");
|
|
164
|
+
const dmp = new import_diff_match_patch2.diff_match_patch();
|
|
165
|
+
const diffs = dmp.diff_main(prevChars, nextChars);
|
|
166
|
+
dmp.diff_cleanupSemantic(diffs);
|
|
167
|
+
const result = [];
|
|
168
|
+
let i = 0;
|
|
169
|
+
while (i < diffs.length) {
|
|
170
|
+
const [op, text] = diffs[i];
|
|
171
|
+
if (op === 0) {
|
|
172
|
+
for (let j = 0; j < text.length; j++) {
|
|
173
|
+
result.push({
|
|
174
|
+
kind: "equal",
|
|
175
|
+
line: charToLine[text.charCodeAt(j)]
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
i++;
|
|
179
|
+
} else if (op === -1 && i + 1 < diffs.length && diffs[i + 1][0] === 1) {
|
|
180
|
+
const deleteText = text;
|
|
181
|
+
const insertText = diffs[i + 1][1];
|
|
182
|
+
const deleteLen = deleteText.length;
|
|
183
|
+
const insertLen = insertText.length;
|
|
184
|
+
const minLen = Math.min(deleteLen, insertLen);
|
|
185
|
+
for (let j = 0; j < minLen; j++) {
|
|
186
|
+
let getCharForToken2 = function(tok) {
|
|
187
|
+
let char = tokenToChar.get(tok);
|
|
188
|
+
if (char === void 0) {
|
|
189
|
+
const code = charToToken.length;
|
|
190
|
+
char = String.fromCharCode(code);
|
|
191
|
+
tokenToChar.set(tok, char);
|
|
192
|
+
charToToken.push(tok);
|
|
193
|
+
}
|
|
194
|
+
return char;
|
|
195
|
+
};
|
|
196
|
+
var getCharForToken = getCharForToken2;
|
|
197
|
+
const prevLine = charToLine[deleteText.charCodeAt(j)];
|
|
198
|
+
const nextLine = charToLine[insertText.charCodeAt(j)];
|
|
199
|
+
const prevTokens = tokenizeCodeLine(prevLine);
|
|
200
|
+
const nextTokens = tokenizeCodeLine(nextLine);
|
|
201
|
+
const tokenToChar = /* @__PURE__ */ new Map();
|
|
202
|
+
const charToToken = [];
|
|
203
|
+
const prevTokChars = prevTokens.map(getCharForToken2).join("");
|
|
204
|
+
const nextTokChars = nextTokens.map(getCharForToken2).join("");
|
|
205
|
+
const tokDiffs = dmp.diff_main(prevTokChars, nextTokChars);
|
|
206
|
+
dmp.diff_cleanupSemantic(tokDiffs);
|
|
207
|
+
const tokens = [];
|
|
208
|
+
for (let k = 0; k < tokDiffs.length; k++) {
|
|
209
|
+
const [tokOp, tokText] = tokDiffs[k];
|
|
210
|
+
if (tokOp === 0) {
|
|
211
|
+
for (let c = 0; c < tokText.length; c++) {
|
|
212
|
+
tokens.push({ kind: "equal", text: charToToken[tokText.charCodeAt(c)] });
|
|
213
|
+
}
|
|
214
|
+
} else if (tokOp === 1) {
|
|
215
|
+
for (let c = 0; c < tokText.length; c++) {
|
|
216
|
+
tokens.push({ kind: "added", text: charToToken[tokText.charCodeAt(c)] });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
result.push({ kind: "changed", tokens });
|
|
221
|
+
}
|
|
222
|
+
for (let j = minLen; j < insertLen; j++) {
|
|
223
|
+
const line = charToLine[insertText.charCodeAt(j)];
|
|
224
|
+
const tokens = tokenizeCodeLine(line).map((t) => ({ kind: "added", text: t }));
|
|
225
|
+
result.push({ kind: "added", tokens });
|
|
226
|
+
}
|
|
227
|
+
i += 2;
|
|
228
|
+
} else if (op === -1) {
|
|
229
|
+
i++;
|
|
230
|
+
} else if (op === 1) {
|
|
231
|
+
for (let j = 0; j < text.length; j++) {
|
|
232
|
+
const line = charToLine[text.charCodeAt(j)];
|
|
233
|
+
const tokens = tokenizeCodeLine(line).map((t) => ({ kind: "added", text: t }));
|
|
234
|
+
result.push({ kind: "added", tokens });
|
|
235
|
+
}
|
|
236
|
+
i++;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
242
|
+
0 && (module.exports = {
|
|
243
|
+
codeDiff,
|
|
244
|
+
sentenceDiff,
|
|
245
|
+
tokenize,
|
|
246
|
+
tokenizeCodeLine,
|
|
247
|
+
tokenizeLines
|
|
248
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export { C as CodeLineDiff, a as CodeToken, c as codeDiff } from '../codeDiff-BVwZfdt9.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Splits a prose string into an ordered array of sentence strings.
|
|
5
|
+
*
|
|
6
|
+
* Rules:
|
|
7
|
+
* - Split on '.', '!', '?' followed by whitespace or end-of-string.
|
|
8
|
+
* - Treat ellipsis ('...') as non-splitting.
|
|
9
|
+
* - Trim leading/trailing whitespace from each token; discard empty tokens.
|
|
10
|
+
* - Pure function — no side effects.
|
|
11
|
+
*/
|
|
12
|
+
declare function tokenize(text: string): string[];
|
|
13
|
+
|
|
14
|
+
type SentenceDiff = {
|
|
15
|
+
kind: "equal";
|
|
16
|
+
sentence: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "added";
|
|
19
|
+
sentence: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: "removed";
|
|
22
|
+
sentence: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "modified";
|
|
25
|
+
before: string;
|
|
26
|
+
after: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Given two consecutive full-snapshot strings, returns a structured diff
|
|
30
|
+
* describing which sentences are unchanged, added, removed, or modified.
|
|
31
|
+
*/
|
|
32
|
+
declare function sentenceDiff(prev: string, next: string): SentenceDiff[];
|
|
33
|
+
|
|
34
|
+
declare function tokenizeLines(code: string): string[];
|
|
35
|
+
declare function tokenizeCodeLine(line: string): string[];
|
|
36
|
+
|
|
37
|
+
export { type SentenceDiff, sentenceDiff, tokenize, tokenizeCodeLine, tokenizeLines };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export { C as CodeLineDiff, a as CodeToken, c as codeDiff } from '../codeDiff-BVwZfdt9.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Splits a prose string into an ordered array of sentence strings.
|
|
5
|
+
*
|
|
6
|
+
* Rules:
|
|
7
|
+
* - Split on '.', '!', '?' followed by whitespace or end-of-string.
|
|
8
|
+
* - Treat ellipsis ('...') as non-splitting.
|
|
9
|
+
* - Trim leading/trailing whitespace from each token; discard empty tokens.
|
|
10
|
+
* - Pure function — no side effects.
|
|
11
|
+
*/
|
|
12
|
+
declare function tokenize(text: string): string[];
|
|
13
|
+
|
|
14
|
+
type SentenceDiff = {
|
|
15
|
+
kind: "equal";
|
|
16
|
+
sentence: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "added";
|
|
19
|
+
sentence: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: "removed";
|
|
22
|
+
sentence: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "modified";
|
|
25
|
+
before: string;
|
|
26
|
+
after: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Given two consecutive full-snapshot strings, returns a structured diff
|
|
30
|
+
* describing which sentences are unchanged, added, removed, or modified.
|
|
31
|
+
*/
|
|
32
|
+
declare function sentenceDiff(prev: string, next: string): SentenceDiff[];
|
|
33
|
+
|
|
34
|
+
declare function tokenizeLines(code: string): string[];
|
|
35
|
+
declare function tokenizeCodeLine(line: string): string[];
|
|
36
|
+
|
|
37
|
+
export { type SentenceDiff, sentenceDiff, tokenize, tokenizeCodeLine, tokenizeLines };
|