@seed-hypermedia/client 0.0.68 → 0.0.70
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 +201 -0
- package/dist/auth.d.ts +79 -0
- package/dist/auth.mjs +266 -0
- package/dist/auto-link.d.ts +3 -2
- package/dist/auto-link.mjs +21 -0
- package/dist/base64.mjs +9 -0
- package/dist/blobs.d.ts +170 -0
- package/dist/blobs.mjs +51 -0
- package/dist/block-diff.mjs +17 -0
- package/dist/blocks-to-markdown.mjs +22 -0
- package/dist/capability.d.ts +7 -2
- package/dist/capability.mjs +14 -0
- package/dist/cbor.d.ts +13 -0
- package/dist/cbor.mjs +13 -0
- package/dist/change.d.ts +8 -7
- package/dist/change.mjs +24 -0
- package/dist/chunk-2MD3FXKB.mjs +14 -0
- package/dist/chunk-37WRGUK4.mjs +125 -0
- package/dist/chunk-3KESF5XJ.mjs +297 -0
- package/dist/chunk-3TPCJCVO.mjs +24 -0
- package/dist/chunk-4Q3SAL5R.mjs +75 -0
- package/dist/chunk-52P3E6H6.mjs +459 -0
- package/dist/chunk-BUPMCRR4.mjs +48 -0
- package/dist/chunk-CBELM7KX.mjs +29 -0
- package/dist/{chunk-KCR3277A.mjs → chunk-DBHL3BYB.mjs} +9 -14
- package/dist/chunk-DR3HJ6BV.mjs +25 -0
- package/dist/chunk-EU36RFR3.mjs +159 -0
- package/dist/chunk-EY6RQVAP.mjs +138 -0
- package/dist/chunk-H7L4TI6X.mjs +705 -0
- package/dist/chunk-HBIVZA6C.mjs +102 -0
- package/dist/chunk-IT5LLTMP.mjs +209 -0
- package/dist/chunk-JT57MV7Y.mjs +136 -0
- package/dist/chunk-KO4XH5L2.mjs +475 -0
- package/dist/chunk-LVAHHQIK.mjs +41 -0
- package/dist/chunk-LYECQKZE.mjs +49 -0
- package/dist/chunk-N3P7S5YZ.mjs +118 -0
- package/dist/chunk-NPG76WUS.mjs +348 -0
- package/dist/chunk-NYWCMQTH.mjs +412 -0
- package/dist/chunk-OZKQOI2X.mjs +334 -0
- package/dist/chunk-PJ2RFT5A.mjs +113 -0
- package/dist/chunk-PPAY4WZX.mjs +40 -0
- package/dist/chunk-S2PVJK2P.mjs +517 -0
- package/dist/chunk-SHOAYNJY.mjs +289 -0
- package/dist/chunk-T5BTAJPW.mjs +725 -0
- package/dist/{chunk-EGCUJ6D6.mjs → chunk-UOL3F6XQ.mjs} +0 -12
- package/dist/chunk-VN7F33SS.mjs +108 -0
- package/dist/chunk-YNVFRCUH.mjs +171 -0
- package/dist/client.d.ts +3 -2
- package/dist/client.mjs +15 -0
- package/dist/comment.d.ts +5 -4
- package/dist/comment.mjs +19 -0
- package/dist/contact.d.ts +5 -4
- package/dist/contact.mjs +15 -0
- package/dist/document-state.mjs +8 -0
- package/dist/editor-types.mjs +0 -0
- package/dist/editorblock-to-hmblock.mjs +11 -0
- package/dist/encryption.mjs +13 -0
- package/dist/errors.mjs +11 -0
- package/dist/file-to-ipfs.mjs +13 -0
- package/dist/grobid.mjs +11 -0
- package/dist/hm-resolver.mjs +10 -0
- package/dist/hmauth.d.ts +169 -0
- package/dist/hmauth.mjs +53 -0
- package/dist/hmblock-to-editorblock.mjs +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +132 -5453
- package/dist/keyfile.mjs +19 -0
- package/dist/markdown-to-blocks.mjs +15 -0
- package/dist/pdf-to-blocks-embedded.mjs +7 -0
- package/dist/pdf-to-blocks.mjs +11 -0
- package/dist/ref.d.ts +5 -4
- package/dist/ref.mjs +13 -0
- package/dist/resource-read.mjs +15 -0
- package/dist/signer.d.ts +42 -0
- package/dist/signer.mjs +9 -0
- package/dist/signing.d.ts +10 -2
- package/dist/signing.mjs +16 -0
- package/dist/tei-to-blocks.mjs +8 -0
- package/dist/unicode.mjs +19 -0
- package/dist/vault-local.mjs +10 -6
- package/dist/vault.d.ts +14 -4
- package/dist/vault.mjs +6 -2
- package/package.json +18 -28
- package/src/index.ts +0 -144
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isSurrogate
|
|
3
|
+
} from "./chunk-SQEUO7FO.mjs";
|
|
4
|
+
|
|
5
|
+
// src/hmblock-to-editorblock.ts
|
|
6
|
+
function toEditorBlockType(hmBlockType) {
|
|
7
|
+
if (hmBlockType === "Heading") return "heading";
|
|
8
|
+
if (hmBlockType === "Paragraph") return "paragraph";
|
|
9
|
+
if (hmBlockType === "Code") return "code-block";
|
|
10
|
+
if (hmBlockType === "Math") return "math";
|
|
11
|
+
if (hmBlockType === "Image") return "image";
|
|
12
|
+
if (hmBlockType === "Video") return "video";
|
|
13
|
+
if (hmBlockType === "File") return "file";
|
|
14
|
+
if (hmBlockType === "Button") return "button";
|
|
15
|
+
if (hmBlockType === "Embed") return "embed";
|
|
16
|
+
if (hmBlockType === "WebEmbed") return "web-embed";
|
|
17
|
+
if (hmBlockType === "Query") return "query";
|
|
18
|
+
if (hmBlockType === "Table") return "table";
|
|
19
|
+
if (hmBlockType === "TableRow") return "tableRow";
|
|
20
|
+
if (hmBlockType === "TableColumn") return "tableColumn";
|
|
21
|
+
return "unknown";
|
|
22
|
+
}
|
|
23
|
+
function hmBlocksToEditorContent(blocks, opts = { level: 1 }) {
|
|
24
|
+
const childRecursiveOpts = {
|
|
25
|
+
level: opts.level || 0
|
|
26
|
+
};
|
|
27
|
+
const parentIsTable = opts.parentType === "Table";
|
|
28
|
+
let rowIdx = 0;
|
|
29
|
+
let colIdx = 0;
|
|
30
|
+
return blocks.filter((hmBlock) => {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
const t = (_a = hmBlock.block) == null ? void 0 : _a.type;
|
|
33
|
+
if ((t === "TableRow" || t === "TableColumn") && !parentIsTable) {
|
|
34
|
+
console.warn(
|
|
35
|
+
`[hmBlocksToEditorContent] dropping orphan ${t} block (parent type: ${opts.parentType ?? "root"})`,
|
|
36
|
+
(_b = hmBlock.block) == null ? void 0 : _b.id
|
|
37
|
+
);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}).map((hmBlock) => {
|
|
42
|
+
var _a, _b, _c, _d, _e;
|
|
43
|
+
let positionIdx;
|
|
44
|
+
if (parentIsTable) {
|
|
45
|
+
const t = (_a = hmBlock.block) == null ? void 0 : _a.type;
|
|
46
|
+
if (t === "TableRow") positionIdx = rowIdx++;
|
|
47
|
+
else if (t === "TableColumn") positionIdx = colIdx++;
|
|
48
|
+
}
|
|
49
|
+
let res = hmBlock.block ? hmBlockToEditorBlock(hmBlock.block) : null;
|
|
50
|
+
if (res && positionIdx !== void 0 && positionIdx > 0) {
|
|
51
|
+
const props = res.props;
|
|
52
|
+
if (props && "isHeader" in props) {
|
|
53
|
+
delete props.isHeader;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (res && ((_b = hmBlock.children) == null ? void 0 : _b.length)) {
|
|
57
|
+
const childrenType = (_d = ((_c = hmBlock.block) == null ? void 0 : _c.attributes) || {}) == null ? void 0 : _d.childrenType;
|
|
58
|
+
const validChildrenType = childrenType === "Group" || childrenType === "Ordered" || childrenType === "Unordered" || childrenType === "Blockquote" || childrenType === "Grid" ? childrenType : "Group";
|
|
59
|
+
res.children = hmBlocksToEditorContent(hmBlock.children, {
|
|
60
|
+
level: childRecursiveOpts.level ? childRecursiveOpts.level + 1 : 1,
|
|
61
|
+
childrenType: validChildrenType,
|
|
62
|
+
parentType: (_e = hmBlock.block) == null ? void 0 : _e.type
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return res;
|
|
66
|
+
}).filter((block) => block !== null);
|
|
67
|
+
}
|
|
68
|
+
function hmBlockToEditorBlock(block) {
|
|
69
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
70
|
+
const blockType = toEditorBlockType(block.type);
|
|
71
|
+
if (blockType === "unknown") {
|
|
72
|
+
return {
|
|
73
|
+
id: block.id,
|
|
74
|
+
type: "unknown",
|
|
75
|
+
content: [],
|
|
76
|
+
props: {
|
|
77
|
+
revision: block.revision,
|
|
78
|
+
originalType: block.type,
|
|
79
|
+
originalData: JSON.stringify(block)
|
|
80
|
+
},
|
|
81
|
+
children: []
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
let out = {
|
|
85
|
+
id: block.id,
|
|
86
|
+
type: blockType,
|
|
87
|
+
content: [],
|
|
88
|
+
props: {
|
|
89
|
+
revision: block.revision
|
|
90
|
+
},
|
|
91
|
+
children: []
|
|
92
|
+
};
|
|
93
|
+
const attributes = block.attributes || {};
|
|
94
|
+
if ("childrenType" in attributes && attributes.childrenType) {
|
|
95
|
+
const childrenType = attributes.childrenType;
|
|
96
|
+
if (childrenType === "Group" || childrenType === "Ordered" || childrenType === "Unordered" || childrenType === "Blockquote" || childrenType === "Grid") {
|
|
97
|
+
;
|
|
98
|
+
out.props.childrenType = childrenType;
|
|
99
|
+
}
|
|
100
|
+
if (childrenType === "Grid" && attributes.columnCount != null) {
|
|
101
|
+
;
|
|
102
|
+
out.props.columnCount = String(attributes.columnCount);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (["code-block", "video", "image", "file", "button", "embed", "web-embed", "math", "nostr"].includes(blockType)) {
|
|
106
|
+
if (block.link) {
|
|
107
|
+
;
|
|
108
|
+
out.props.url = block.link;
|
|
109
|
+
}
|
|
110
|
+
if (blockType == "code-block") {
|
|
111
|
+
out.type = "code-block";
|
|
112
|
+
}
|
|
113
|
+
if (block.attributes) {
|
|
114
|
+
Object.entries(block.attributes).forEach(([key, value]) => {
|
|
115
|
+
if (value !== void 0) {
|
|
116
|
+
if (key == "width" || key == "size") {
|
|
117
|
+
if (typeof value == "number") {
|
|
118
|
+
;
|
|
119
|
+
out.props[key] = blockType === "image" && key === "width" && value > 0 && value <= 100 ? `${value}%` : String(value);
|
|
120
|
+
}
|
|
121
|
+
} else if (typeof value == "boolean") {
|
|
122
|
+
;
|
|
123
|
+
out.props[key] = String(value);
|
|
124
|
+
} else {
|
|
125
|
+
;
|
|
126
|
+
out.props[key] = value;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (block.type === "Paragraph") {
|
|
133
|
+
const columnId = (_a = block.attributes) == null ? void 0 : _a.columnId;
|
|
134
|
+
if (typeof columnId === "string" && columnId) {
|
|
135
|
+
;
|
|
136
|
+
out.props.columnId = columnId;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (block.type === "TableColumn") {
|
|
140
|
+
const width = (_b = block.attributes) == null ? void 0 : _b.width;
|
|
141
|
+
if (typeof width === "number") {
|
|
142
|
+
;
|
|
143
|
+
out.props.width = String(width);
|
|
144
|
+
}
|
|
145
|
+
const isHeader = (_c = block.attributes) == null ? void 0 : _c.isHeader;
|
|
146
|
+
if (isHeader === true) {
|
|
147
|
+
;
|
|
148
|
+
out.props.isHeader = true;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (block.type === "TableRow") {
|
|
152
|
+
const isHeader = (_d = block.attributes) == null ? void 0 : _d.isHeader;
|
|
153
|
+
if (isHeader === true) {
|
|
154
|
+
;
|
|
155
|
+
out.props.isHeader = true;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (block.type === "Query") {
|
|
159
|
+
const queryProps = out.props;
|
|
160
|
+
queryProps.style = (_e = block.attributes) == null ? void 0 : _e.style;
|
|
161
|
+
queryProps.columnCount = String(((_f = block.attributes) == null ? void 0 : _f.columnCount) || "");
|
|
162
|
+
queryProps.queryIncludes = JSON.stringify(((_h = (_g = block.attributes) == null ? void 0 : _g.query) == null ? void 0 : _h.includes) || []);
|
|
163
|
+
queryProps.querySort = JSON.stringify(((_j = (_i = block.attributes) == null ? void 0 : _i.query) == null ? void 0 : _j.sort) || {});
|
|
164
|
+
queryProps.banner = ((_k = block.attributes) == null ? void 0 : _k.banner) ? "true" : "false";
|
|
165
|
+
queryProps.queryLimit = String(((_m = (_l = block.attributes) == null ? void 0 : _l.query) == null ? void 0 : _m.limit) || "");
|
|
166
|
+
if ((_n = block.attributes) == null ? void 0 : _n.table) queryProps.tableConfig = JSON.stringify(block.attributes.table);
|
|
167
|
+
}
|
|
168
|
+
const blockText = block.text || "";
|
|
169
|
+
const leaves = out.content;
|
|
170
|
+
let leaf = null;
|
|
171
|
+
let inlineBlockContent = null;
|
|
172
|
+
let textStart = 0;
|
|
173
|
+
let i = 0;
|
|
174
|
+
const stopPoint = block.text ? block.text.length - 1 : 0;
|
|
175
|
+
let pos = 0;
|
|
176
|
+
const leafAnnotations = /* @__PURE__ */ new Set();
|
|
177
|
+
if (blockText == "") {
|
|
178
|
+
leaves.push({ type: "text", text: blockText, styles: {} });
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
while (i < blockText.length) {
|
|
182
|
+
const inlineEmbed = findInlineEmbedStartingAt(pos);
|
|
183
|
+
if (inlineEmbed) {
|
|
184
|
+
if (leaf) {
|
|
185
|
+
finishLeaf(textStart, i);
|
|
186
|
+
leaf = null;
|
|
187
|
+
}
|
|
188
|
+
if (inlineBlockContent) {
|
|
189
|
+
leaves.push(inlineBlockContent);
|
|
190
|
+
inlineBlockContent = null;
|
|
191
|
+
}
|
|
192
|
+
leaves.push({
|
|
193
|
+
type: "inline-embed",
|
|
194
|
+
styles: {},
|
|
195
|
+
link: inlineEmbed.link
|
|
196
|
+
});
|
|
197
|
+
skipToCodepoint(inlineEmbed.end);
|
|
198
|
+
textStart = i;
|
|
199
|
+
leafAnnotations.clear();
|
|
200
|
+
if (i >= blockText.length) return out;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
let ul = 1;
|
|
204
|
+
let annotationsChanged = trackPosAnnotations(pos);
|
|
205
|
+
let surrogate = isSurrogate(blockText, i);
|
|
206
|
+
if (surrogate) {
|
|
207
|
+
ul++;
|
|
208
|
+
let onlyOneSurrogate = pos + ul;
|
|
209
|
+
if (onlyOneSurrogate == blockText.length) {
|
|
210
|
+
if (!leaf) {
|
|
211
|
+
startLeaf(leafAnnotations);
|
|
212
|
+
}
|
|
213
|
+
finishLeaf(textStart, i + 2);
|
|
214
|
+
if (inlineBlockContent) {
|
|
215
|
+
const lastLeaf = leaves[leaves.length - 1];
|
|
216
|
+
if (lastLeaf && !isText(lastLeaf)) {
|
|
217
|
+
}
|
|
218
|
+
leaves.push(inlineBlockContent);
|
|
219
|
+
inlineBlockContent = null;
|
|
220
|
+
}
|
|
221
|
+
return out;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (stopPoint < 0) {
|
|
225
|
+
console.warn("STOP IS LESS THAN ZERO", block);
|
|
226
|
+
}
|
|
227
|
+
if (i == stopPoint) {
|
|
228
|
+
if (annotationsChanged) {
|
|
229
|
+
if (leaf) {
|
|
230
|
+
finishLeaf(textStart, i);
|
|
231
|
+
}
|
|
232
|
+
startLeaf(leafAnnotations);
|
|
233
|
+
} else {
|
|
234
|
+
startLeaf(leafAnnotations);
|
|
235
|
+
}
|
|
236
|
+
finishLeaf(textStart, i + 1);
|
|
237
|
+
if (inlineBlockContent) {
|
|
238
|
+
const lastLeaf = leaves[leaves.length - 1];
|
|
239
|
+
if (lastLeaf && !isText(lastLeaf)) {
|
|
240
|
+
}
|
|
241
|
+
leaves.push(inlineBlockContent);
|
|
242
|
+
inlineBlockContent = null;
|
|
243
|
+
}
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
if (!leaf) {
|
|
247
|
+
startLeaf(leafAnnotations);
|
|
248
|
+
advance(ul);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (annotationsChanged) {
|
|
252
|
+
finishLeaf(textStart, i);
|
|
253
|
+
startLeaf(leafAnnotations);
|
|
254
|
+
}
|
|
255
|
+
advance(ul);
|
|
256
|
+
if (i == blockText.length) {
|
|
257
|
+
finishLeaf(textStart, i);
|
|
258
|
+
return out;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
throw Error("BUG: should not get here");
|
|
262
|
+
function advance(codeUnits) {
|
|
263
|
+
pos++;
|
|
264
|
+
i += codeUnits;
|
|
265
|
+
}
|
|
266
|
+
function startLeaf(posAnnotations) {
|
|
267
|
+
var _a2, _b2;
|
|
268
|
+
const newLeaf = {
|
|
269
|
+
type: "text",
|
|
270
|
+
text: "",
|
|
271
|
+
styles: {}
|
|
272
|
+
};
|
|
273
|
+
leaf = newLeaf;
|
|
274
|
+
let linkAnnotation = null;
|
|
275
|
+
for (const l of Array.from(posAnnotations)) {
|
|
276
|
+
const annotationData = l;
|
|
277
|
+
if (annotationData.type === "Link") {
|
|
278
|
+
linkAnnotation = {
|
|
279
|
+
type: "Link",
|
|
280
|
+
href: annotationData.link || ""
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
if (annotationData.type === "Embed") {
|
|
284
|
+
linkAnnotation = {
|
|
285
|
+
type: "Embed",
|
|
286
|
+
link: annotationData.link || ""
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
if (["Bold", "Italic", "Strike", "Underline", "Code", "Range"].includes(annotationData.type)) {
|
|
290
|
+
const styleKey = annotationData.type.toLowerCase();
|
|
291
|
+
newLeaf.styles[styleKey] = true;
|
|
292
|
+
}
|
|
293
|
+
if (annotationData.type === "TextColor") {
|
|
294
|
+
const attrs = annotationData.attributes;
|
|
295
|
+
const color = (attrs == null ? void 0 : attrs.value) ?? (attrs == null ? void 0 : attrs.color);
|
|
296
|
+
if (typeof color === "string" && color) {
|
|
297
|
+
;
|
|
298
|
+
newLeaf.styles.textColor = color;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (annotationData.type === "BackgroundColor") {
|
|
302
|
+
const attrs = annotationData.attributes;
|
|
303
|
+
const color = (attrs == null ? void 0 : attrs.value) ?? (attrs == null ? void 0 : attrs.color);
|
|
304
|
+
if (typeof color === "string" && color) {
|
|
305
|
+
;
|
|
306
|
+
newLeaf.styles.backgroundColor = color;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (annotationData.type === "TextSize") {
|
|
310
|
+
const size = (_a2 = annotationData.attributes) == null ? void 0 : _a2.value;
|
|
311
|
+
if (typeof size === "string" && size) {
|
|
312
|
+
;
|
|
313
|
+
newLeaf.styles.textSize = size;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (annotationData.type === "TextFamily") {
|
|
317
|
+
const family = (_b2 = annotationData.attributes) == null ? void 0 : _b2.value;
|
|
318
|
+
if (typeof family === "string" && family) {
|
|
319
|
+
;
|
|
320
|
+
newLeaf.styles.textFamily = family;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (linkAnnotation) {
|
|
325
|
+
if (linkAnnotation.type === "Embed") {
|
|
326
|
+
leaves.push({
|
|
327
|
+
type: "inline-embed",
|
|
328
|
+
styles: {},
|
|
329
|
+
link: linkAnnotation.link || ""
|
|
330
|
+
});
|
|
331
|
+
textStart = i + 1;
|
|
332
|
+
} else if (inlineBlockContent) {
|
|
333
|
+
if (linkChangedIdentity(linkAnnotation)) {
|
|
334
|
+
leaves.push(inlineBlockContent);
|
|
335
|
+
if (linkAnnotation.type === "Link") {
|
|
336
|
+
inlineBlockContent = {
|
|
337
|
+
type: "link",
|
|
338
|
+
content: [],
|
|
339
|
+
href: linkAnnotation.href || ""
|
|
340
|
+
};
|
|
341
|
+
} else {
|
|
342
|
+
inlineBlockContent = {
|
|
343
|
+
type: "inline-embed",
|
|
344
|
+
styles: {},
|
|
345
|
+
link: linkAnnotation.link || ""
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
if (linkAnnotation.type === "Link") {
|
|
351
|
+
inlineBlockContent = {
|
|
352
|
+
type: "link",
|
|
353
|
+
content: [],
|
|
354
|
+
href: linkAnnotation.href || ""
|
|
355
|
+
};
|
|
356
|
+
} else {
|
|
357
|
+
inlineBlockContent = {
|
|
358
|
+
type: "inline-embed",
|
|
359
|
+
styles: {},
|
|
360
|
+
link: linkAnnotation.link || ""
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
} else {
|
|
365
|
+
if (inlineBlockContent) {
|
|
366
|
+
leaves.push(inlineBlockContent);
|
|
367
|
+
inlineBlockContent = null;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function linkChangedIdentity(annotation) {
|
|
372
|
+
if (!inlineBlockContent) return false;
|
|
373
|
+
let currentLink = inlineBlockContent.link || inlineBlockContent.href;
|
|
374
|
+
return currentLink != annotation.link && currentLink != annotation.href;
|
|
375
|
+
}
|
|
376
|
+
function finishLeaf(low, high) {
|
|
377
|
+
let newValue = blockText.substring(low, high);
|
|
378
|
+
if (leaf) leaf.text = newValue;
|
|
379
|
+
textStart = high;
|
|
380
|
+
if (inlineBlockContent) {
|
|
381
|
+
if (leaf && inlineBlockContent.type == "link") {
|
|
382
|
+
;
|
|
383
|
+
inlineBlockContent.content.push(leaf);
|
|
384
|
+
} else if (inlineBlockContent.type == "inline-embed" && leaf) {
|
|
385
|
+
} else if (leaf) {
|
|
386
|
+
const typedLeaf = {
|
|
387
|
+
type: "text",
|
|
388
|
+
text: "",
|
|
389
|
+
styles: leaf.styles
|
|
390
|
+
};
|
|
391
|
+
inlineBlockContent.content.push(typedLeaf);
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
if (leaf && !(leaf.type === "text" && leaf.text === "" && Object.keys(leaf.styles).length === 0)) {
|
|
395
|
+
leaves.push(leaf);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function trackPosAnnotations(pos2) {
|
|
400
|
+
let annotationsChanged = false;
|
|
401
|
+
if (!block.annotations) {
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
const blockAnnotations = block.annotations;
|
|
405
|
+
blockAnnotations.forEach((l) => {
|
|
406
|
+
let spanIdx = annotationContains(l, pos2);
|
|
407
|
+
if (spanIdx === -1) {
|
|
408
|
+
if (leafAnnotations.delete(l)) {
|
|
409
|
+
annotationsChanged = true;
|
|
410
|
+
}
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (leafAnnotations.has(l)) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
leafAnnotations.add(l);
|
|
417
|
+
annotationsChanged = true;
|
|
418
|
+
});
|
|
419
|
+
return annotationsChanged;
|
|
420
|
+
}
|
|
421
|
+
function findInlineEmbedStartingAt(pos2) {
|
|
422
|
+
var _a2, _b2;
|
|
423
|
+
const blockAnnotations = block.annotations;
|
|
424
|
+
if (!blockAnnotations) return null;
|
|
425
|
+
for (const annotation of blockAnnotations) {
|
|
426
|
+
const annotationData = annotation;
|
|
427
|
+
if (annotationData.type !== "Embed") continue;
|
|
428
|
+
const spanIndex = ((_a2 = annotationData.starts) == null ? void 0 : _a2.findIndex((start) => start === pos2)) ?? -1;
|
|
429
|
+
if (spanIndex === -1) continue;
|
|
430
|
+
const end = (_b2 = annotationData.ends) == null ? void 0 : _b2[spanIndex];
|
|
431
|
+
if (typeof end !== "number" || end <= pos2) continue;
|
|
432
|
+
return { link: annotationData.link || "", end };
|
|
433
|
+
}
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
function skipToCodepoint(end) {
|
|
437
|
+
while (pos < end && i < blockText.length) {
|
|
438
|
+
i += isSurrogate(blockText, i) ? 2 : 1;
|
|
439
|
+
pos++;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
function annotationContains(annotation, pos) {
|
|
444
|
+
let low = 0;
|
|
445
|
+
let high = annotation.starts.length - 1;
|
|
446
|
+
let mid = 0;
|
|
447
|
+
while (low <= high) {
|
|
448
|
+
mid = Math.floor((low + high) / 2);
|
|
449
|
+
const endAtMid = annotation.ends[mid];
|
|
450
|
+
if (endAtMid === void 0) break;
|
|
451
|
+
if (endAtMid <= pos) {
|
|
452
|
+
low = mid + 1;
|
|
453
|
+
} else {
|
|
454
|
+
high = mid - 1;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (low == annotation.starts.length) {
|
|
458
|
+
return -1;
|
|
459
|
+
}
|
|
460
|
+
const startAtLow = annotation.starts[low];
|
|
461
|
+
const endAtLow = annotation.ends[low];
|
|
462
|
+
if (startAtLow !== void 0 && endAtLow !== void 0 && startAtLow <= pos && pos < endAtLow) {
|
|
463
|
+
return low;
|
|
464
|
+
}
|
|
465
|
+
return -1;
|
|
466
|
+
}
|
|
467
|
+
function isText(entry) {
|
|
468
|
+
return (entry == null ? void 0 : entry.type) && entry.type == "text" && typeof entry.text == "string";
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export {
|
|
472
|
+
hmBlocksToEditorContent,
|
|
473
|
+
hmBlockToEditorBlock,
|
|
474
|
+
annotationContains
|
|
475
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toHMSigner
|
|
3
|
+
} from "./chunk-DR3HJ6BV.mjs";
|
|
4
|
+
|
|
5
|
+
// src/signing.ts
|
|
6
|
+
import { encode as cborEncode } from "@ipld/dag-cbor";
|
|
7
|
+
var cborCodec = {
|
|
8
|
+
code: 113,
|
|
9
|
+
encode: (input) => cborEncode(input),
|
|
10
|
+
name: "DAG-CBOR"
|
|
11
|
+
};
|
|
12
|
+
function normalizeBytes(data) {
|
|
13
|
+
const normalized = new Uint8Array(data.byteLength);
|
|
14
|
+
normalized.set(data);
|
|
15
|
+
return normalized;
|
|
16
|
+
}
|
|
17
|
+
async function signObject(signer, data) {
|
|
18
|
+
return await signer.sign(cborEncode(data));
|
|
19
|
+
}
|
|
20
|
+
async function signerPublicKey(signer) {
|
|
21
|
+
return toHMSigner(signer).getPublicKey();
|
|
22
|
+
}
|
|
23
|
+
function toPublishInput(blobData, extraBlobs) {
|
|
24
|
+
return {
|
|
25
|
+
blobs: [
|
|
26
|
+
{ data: normalizeBytes(blobData) },
|
|
27
|
+
...(extraBlobs || []).map((b) => ({
|
|
28
|
+
...b.cid ? { cid: b.cid } : {},
|
|
29
|
+
data: normalizeBytes(b.data)
|
|
30
|
+
}))
|
|
31
|
+
]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
cborCodec,
|
|
37
|
+
normalizeBytes,
|
|
38
|
+
signObject,
|
|
39
|
+
signerPublicKey,
|
|
40
|
+
toPublishInput
|
|
41
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
teiToBlocks
|
|
3
|
+
} from "./chunk-S2PVJK2P.mjs";
|
|
4
|
+
import {
|
|
5
|
+
embeddedPdfToBlocks
|
|
6
|
+
} from "./chunk-52P3E6H6.mjs";
|
|
7
|
+
import {
|
|
8
|
+
isGrobidAvailable,
|
|
9
|
+
processFulltextDocument
|
|
10
|
+
} from "./chunk-PPAY4WZX.mjs";
|
|
11
|
+
|
|
12
|
+
// src/pdf-to-blocks.ts
|
|
13
|
+
async function pdfToBlocks(pdfData, options = {}) {
|
|
14
|
+
const { grobidUrl, grobidTimeoutMs = 3e3, teiOptions = {}, grobidOptions = {} } = options;
|
|
15
|
+
if (grobidUrl) {
|
|
16
|
+
const available = await isGrobidAvailable(grobidUrl, grobidTimeoutMs);
|
|
17
|
+
if (!available) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
`GROBID server is not reachable at ${grobidUrl}.
|
|
20
|
+
Start a GROBID instance with:
|
|
21
|
+
docker run --rm -p 8070:8070 grobid/grobid:0.8.2-full`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return useGrobidExtraction(pdfData, grobidUrl, grobidOptions, teiOptions);
|
|
25
|
+
}
|
|
26
|
+
return useEmbeddedExtraction(pdfData);
|
|
27
|
+
}
|
|
28
|
+
async function useGrobidExtraction(pdfData, grobidUrl, grobidOpts, teiOpts) {
|
|
29
|
+
const teiXml = await processFulltextDocument(pdfData, {
|
|
30
|
+
grobidUrl,
|
|
31
|
+
teiCoordinates: grobidOpts.teiCoordinates || ["figure"]
|
|
32
|
+
});
|
|
33
|
+
const { metadata, blocks } = await teiToBlocks(teiXml, teiOpts);
|
|
34
|
+
return { metadata, blocks, source: "grobid" };
|
|
35
|
+
}
|
|
36
|
+
async function useEmbeddedExtraction(pdfData) {
|
|
37
|
+
const { metadata, blocks } = await embeddedPdfToBlocks(pdfData);
|
|
38
|
+
return {
|
|
39
|
+
metadata: {
|
|
40
|
+
name: metadata.name
|
|
41
|
+
},
|
|
42
|
+
blocks,
|
|
43
|
+
source: "embedded"
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
pdfToBlocks
|
|
49
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// src/unicode.ts
|
|
2
|
+
var AnnotationSet = class {
|
|
3
|
+
annotations;
|
|
4
|
+
constructor() {
|
|
5
|
+
this.annotations = /* @__PURE__ */ new Map();
|
|
6
|
+
}
|
|
7
|
+
addSpan(type, attributes, start, end) {
|
|
8
|
+
const id = this._annotationId(type, attributes);
|
|
9
|
+
let annotation = this.annotations.get(id);
|
|
10
|
+
if (!annotation) {
|
|
11
|
+
const annAttrs = attributes ? { ...attributes } : {};
|
|
12
|
+
let link;
|
|
13
|
+
if (type == "Link" || type == "Embed") {
|
|
14
|
+
link = attributes == null ? void 0 : attributes.link;
|
|
15
|
+
delete annAttrs.link;
|
|
16
|
+
}
|
|
17
|
+
annotation = {
|
|
18
|
+
type,
|
|
19
|
+
attributes: annAttrs,
|
|
20
|
+
link: link || "",
|
|
21
|
+
starts: [],
|
|
22
|
+
ends: []
|
|
23
|
+
};
|
|
24
|
+
this.annotations.set(id, annotation);
|
|
25
|
+
}
|
|
26
|
+
addSpanToAnnotation(annotation, start, end);
|
|
27
|
+
}
|
|
28
|
+
_annotationId(type, attributes) {
|
|
29
|
+
if (attributes) {
|
|
30
|
+
if (attributes.link) {
|
|
31
|
+
return `${type}-${attributes.link}`;
|
|
32
|
+
}
|
|
33
|
+
if (attributes.href) {
|
|
34
|
+
return `${type}-${attributes.href}`;
|
|
35
|
+
}
|
|
36
|
+
if (attributes.value) {
|
|
37
|
+
return `${type}-${attributes.value}`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return type;
|
|
41
|
+
}
|
|
42
|
+
list() {
|
|
43
|
+
const keys = Array.from(this.annotations.keys()).sort();
|
|
44
|
+
let out = new Array(keys.length);
|
|
45
|
+
for (let i in keys) {
|
|
46
|
+
const annotation = this.annotations.get(keys[i]);
|
|
47
|
+
if (annotation) out[i] = annotation;
|
|
48
|
+
}
|
|
49
|
+
out = out.sort((a, b) => {
|
|
50
|
+
let startA = a.starts[0];
|
|
51
|
+
let startB = b.starts[0];
|
|
52
|
+
return (startA || 0) - (startB || 0);
|
|
53
|
+
});
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
function addSpanToAnnotation(annotation, start, end) {
|
|
58
|
+
if (!annotation.starts) {
|
|
59
|
+
annotation.starts = [];
|
|
60
|
+
}
|
|
61
|
+
if (!annotation.ends) {
|
|
62
|
+
annotation.ends = [];
|
|
63
|
+
}
|
|
64
|
+
if (annotation.starts.length == 0) {
|
|
65
|
+
pushSpanToAnnotation(annotation, start, end);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const lastIdx = annotation.starts.length - 1;
|
|
69
|
+
if (annotation.ends[lastIdx] == start) {
|
|
70
|
+
annotation.ends[lastIdx] = end;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
pushSpanToAnnotation(annotation, start, end);
|
|
74
|
+
}
|
|
75
|
+
function pushSpanToAnnotation(annotation, start, end) {
|
|
76
|
+
annotation.starts.push(start);
|
|
77
|
+
annotation.ends.push(end);
|
|
78
|
+
}
|
|
79
|
+
var EXCLUSIVE_TYPES = ["TextColor", "BackgroundColor", "TextSize", "TextFamily"];
|
|
80
|
+
function spansOverlap(a, b) {
|
|
81
|
+
for (let i = 0; i < a.starts.length; i++) {
|
|
82
|
+
const aStart = a.starts[i];
|
|
83
|
+
const aEnd = a.ends[i];
|
|
84
|
+
if (aStart === void 0 || aEnd === void 0) continue;
|
|
85
|
+
for (let j = 0; j < b.starts.length; j++) {
|
|
86
|
+
const bStart = b.starts[j];
|
|
87
|
+
const bEnd = b.ends[j];
|
|
88
|
+
if (bStart === void 0 || bEnd === void 0) continue;
|
|
89
|
+
if (aStart < bEnd && bStart < aEnd) return true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
function validateExclusiveAnnotations(annotations) {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
for (const type of EXCLUSIVE_TYPES) {
|
|
97
|
+
const ofType = annotations.filter((a) => a.type === type);
|
|
98
|
+
for (let i = 0; i < ofType.length; i++) {
|
|
99
|
+
for (let j = i + 1; j < ofType.length; j++) {
|
|
100
|
+
const a = ofType[i];
|
|
101
|
+
const b = ofType[j];
|
|
102
|
+
const aVal = (_a = a.attributes) == null ? void 0 : _a.value;
|
|
103
|
+
const bVal = (_b = b.attributes) == null ? void 0 : _b.value;
|
|
104
|
+
if (aVal && bVal && aVal === bVal) continue;
|
|
105
|
+
if (spansOverlap(a, b)) {
|
|
106
|
+
throw new Error(`${type} annotations with different values have overlapping ranges`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
AnnotationSet,
|
|
115
|
+
addSpanToAnnotation,
|
|
116
|
+
pushSpanToAnnotation,
|
|
117
|
+
validateExclusiveAnnotations
|
|
118
|
+
};
|