@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.
Files changed (84) hide show
  1. package/LICENSE +201 -0
  2. package/dist/auth.d.ts +79 -0
  3. package/dist/auth.mjs +266 -0
  4. package/dist/auto-link.d.ts +3 -2
  5. package/dist/auto-link.mjs +21 -0
  6. package/dist/base64.mjs +9 -0
  7. package/dist/blobs.d.ts +170 -0
  8. package/dist/blobs.mjs +51 -0
  9. package/dist/block-diff.mjs +17 -0
  10. package/dist/blocks-to-markdown.mjs +22 -0
  11. package/dist/capability.d.ts +7 -2
  12. package/dist/capability.mjs +14 -0
  13. package/dist/cbor.d.ts +13 -0
  14. package/dist/cbor.mjs +13 -0
  15. package/dist/change.d.ts +8 -7
  16. package/dist/change.mjs +24 -0
  17. package/dist/chunk-2MD3FXKB.mjs +14 -0
  18. package/dist/chunk-37WRGUK4.mjs +125 -0
  19. package/dist/chunk-3KESF5XJ.mjs +297 -0
  20. package/dist/chunk-3TPCJCVO.mjs +24 -0
  21. package/dist/chunk-4Q3SAL5R.mjs +75 -0
  22. package/dist/chunk-52P3E6H6.mjs +459 -0
  23. package/dist/chunk-BUPMCRR4.mjs +48 -0
  24. package/dist/chunk-CBELM7KX.mjs +29 -0
  25. package/dist/{chunk-KCR3277A.mjs → chunk-DBHL3BYB.mjs} +9 -14
  26. package/dist/chunk-DR3HJ6BV.mjs +25 -0
  27. package/dist/chunk-EU36RFR3.mjs +159 -0
  28. package/dist/chunk-EY6RQVAP.mjs +138 -0
  29. package/dist/chunk-H7L4TI6X.mjs +705 -0
  30. package/dist/chunk-HBIVZA6C.mjs +102 -0
  31. package/dist/chunk-IT5LLTMP.mjs +209 -0
  32. package/dist/chunk-JT57MV7Y.mjs +136 -0
  33. package/dist/chunk-KO4XH5L2.mjs +475 -0
  34. package/dist/chunk-LVAHHQIK.mjs +41 -0
  35. package/dist/chunk-LYECQKZE.mjs +49 -0
  36. package/dist/chunk-N3P7S5YZ.mjs +118 -0
  37. package/dist/chunk-NPG76WUS.mjs +348 -0
  38. package/dist/chunk-NYWCMQTH.mjs +412 -0
  39. package/dist/chunk-OZKQOI2X.mjs +334 -0
  40. package/dist/chunk-PJ2RFT5A.mjs +113 -0
  41. package/dist/chunk-PPAY4WZX.mjs +40 -0
  42. package/dist/chunk-S2PVJK2P.mjs +517 -0
  43. package/dist/chunk-SHOAYNJY.mjs +289 -0
  44. package/dist/chunk-T5BTAJPW.mjs +725 -0
  45. package/dist/{chunk-EGCUJ6D6.mjs → chunk-UOL3F6XQ.mjs} +0 -12
  46. package/dist/chunk-VN7F33SS.mjs +108 -0
  47. package/dist/chunk-YNVFRCUH.mjs +171 -0
  48. package/dist/client.d.ts +3 -2
  49. package/dist/client.mjs +15 -0
  50. package/dist/comment.d.ts +5 -4
  51. package/dist/comment.mjs +19 -0
  52. package/dist/contact.d.ts +5 -4
  53. package/dist/contact.mjs +15 -0
  54. package/dist/document-state.mjs +8 -0
  55. package/dist/editor-types.mjs +0 -0
  56. package/dist/editorblock-to-hmblock.mjs +11 -0
  57. package/dist/encryption.mjs +13 -0
  58. package/dist/errors.mjs +11 -0
  59. package/dist/file-to-ipfs.mjs +13 -0
  60. package/dist/grobid.mjs +11 -0
  61. package/dist/hm-resolver.mjs +10 -0
  62. package/dist/hmauth.d.ts +169 -0
  63. package/dist/hmauth.mjs +53 -0
  64. package/dist/hmblock-to-editorblock.mjs +12 -0
  65. package/dist/index.d.ts +2 -0
  66. package/dist/index.mjs +132 -5453
  67. package/dist/keyfile.mjs +19 -0
  68. package/dist/markdown-to-blocks.mjs +15 -0
  69. package/dist/pdf-to-blocks-embedded.mjs +7 -0
  70. package/dist/pdf-to-blocks.mjs +11 -0
  71. package/dist/ref.d.ts +5 -4
  72. package/dist/ref.mjs +13 -0
  73. package/dist/resource-read.mjs +15 -0
  74. package/dist/signer.d.ts +42 -0
  75. package/dist/signer.mjs +9 -0
  76. package/dist/signing.d.ts +10 -2
  77. package/dist/signing.mjs +16 -0
  78. package/dist/tei-to-blocks.mjs +8 -0
  79. package/dist/unicode.mjs +19 -0
  80. package/dist/vault-local.mjs +10 -6
  81. package/dist/vault.d.ts +14 -4
  82. package/dist/vault.mjs +6 -2
  83. package/package.json +18 -28
  84. package/src/index.ts +0 -144
@@ -0,0 +1,459 @@
1
+ // src/pdf-to-blocks-embedded.ts
2
+ function generateBlockId() {
3
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
4
+ let id = "";
5
+ for (let i = 0; i < 8; i++) {
6
+ id += chars[Math.floor(Math.random() * chars.length)];
7
+ }
8
+ return id;
9
+ }
10
+ function isTextItem(item) {
11
+ return "str" in item;
12
+ }
13
+ function isBoldFont(fontName) {
14
+ const lower = fontName.toLowerCase();
15
+ return lower.includes("bold") || lower.includes("heavy") || lower.includes("black");
16
+ }
17
+ function isItalicFont(fontName) {
18
+ const lower = fontName.toLowerCase();
19
+ return lower.includes("italic") || lower.includes("oblique") || lower.includes("slant");
20
+ }
21
+ function isMonospaceFont(fontName) {
22
+ const lower = fontName.toLowerCase();
23
+ return lower.includes("mono") || lower.includes("courier") || lower.includes("consolas") || lower.includes("menlo") || lower.includes("firacode") || lower.includes("inconsolata") || lower.includes("source code") || lower.includes("dejavu sans mono") || lower.includes("lucida console");
24
+ }
25
+ function makeBlock(type, text, extra = {}) {
26
+ return {
27
+ block: {
28
+ id: generateBlockId(),
29
+ type,
30
+ text,
31
+ revision: "",
32
+ link: "",
33
+ attributes: {},
34
+ annotations: [],
35
+ ...extra
36
+ },
37
+ children: []
38
+ };
39
+ }
40
+ function makeHeading(text, annotations = []) {
41
+ return makeBlock("Heading", text, {
42
+ attributes: { childrenType: "Group" },
43
+ annotations
44
+ });
45
+ }
46
+ function makeParagraph(text, annotations = []) {
47
+ return makeBlock("Paragraph", text, { annotations });
48
+ }
49
+ function makeCode(text, language = "") {
50
+ return makeBlock("Code", text, {
51
+ attributes: language ? { language } : {}
52
+ });
53
+ }
54
+ function makeList(items, listType) {
55
+ const container = makeBlock("Paragraph", "", {
56
+ attributes: { childrenType: listType }
57
+ });
58
+ container.children = items;
59
+ return container;
60
+ }
61
+ var MIN_HEADING_TEXT_LENGTH = 4;
62
+ function clusterFontSizes(lines) {
63
+ const sizeCount = /* @__PURE__ */ new Map();
64
+ for (const line of lines) {
65
+ if (line.runs.length === 0) continue;
66
+ const size = Math.round(line.fontSize * 10) / 10;
67
+ sizeCount.set(size, (sizeCount.get(size) || 0) + 1);
68
+ }
69
+ if (sizeCount.size === 0) {
70
+ return { bodySize: 12, headingLevels: /* @__PURE__ */ new Map(), boldHeadingLevel: 1 };
71
+ }
72
+ const clusters = Array.from(sizeCount.entries()).map(([size, count]) => ({ size, count })).sort((a, b) => b.count - a.count);
73
+ const bodySize = clusters[0].size;
74
+ const headingSizeCount = /* @__PURE__ */ new Map();
75
+ for (const line of lines) {
76
+ if (line.runs.length === 0) continue;
77
+ const text = line.runs.map((r) => r.text).join("").trim();
78
+ if (text.length < MIN_HEADING_TEXT_LENGTH) continue;
79
+ const size = Math.round(line.fontSize * 10) / 10;
80
+ if (size > bodySize + 1) {
81
+ headingSizeCount.set(size, (headingSizeCount.get(size) || 0) + 1);
82
+ }
83
+ }
84
+ const headingSizes = Array.from(headingSizeCount.keys()).sort((a, b) => b - a);
85
+ const headingLevels = /* @__PURE__ */ new Map();
86
+ for (let i = 0; i < headingSizes.length && i < 6; i++) {
87
+ headingLevels.set(headingSizes[i], i + 1);
88
+ }
89
+ const boldHeadingLevel = Math.min(headingLevels.size + 1, 6);
90
+ return { bodySize, headingLevels, boldHeadingLevel };
91
+ }
92
+ var BULLET_PATTERNS = /^[\u2022\u2023\u25E6\u2043\u2219•·‣⁃○◦▪▸►–—-]\s+/;
93
+ var NUMBERED_PATTERN = /^(\d+)[.)]\s+/;
94
+ var LETTER_PATTERN = /^[a-zA-Z][.)]\s+/;
95
+ function detectListType(text) {
96
+ const bulletMatch = text.match(BULLET_PATTERNS);
97
+ if (bulletMatch) {
98
+ return { type: "bullet", content: text.slice(bulletMatch[0].length) };
99
+ }
100
+ const numberedMatch = text.match(NUMBERED_PATTERN);
101
+ if (numberedMatch) {
102
+ return { type: "numbered", content: text.slice(numberedMatch[0].length) };
103
+ }
104
+ const letterMatch = text.match(LETTER_PATTERN);
105
+ if (letterMatch) {
106
+ return { type: "numbered", content: text.slice(letterMatch[0].length) };
107
+ }
108
+ return null;
109
+ }
110
+ async function extractTextRuns(doc) {
111
+ const allLines = [];
112
+ for (let pageNum = 1; pageNum <= doc.numPages; pageNum++) {
113
+ const page = await doc.getPage(pageNum);
114
+ await page.getOperatorList();
115
+ const textContent = await page.getTextContent({ includeMarkedContent: false });
116
+ const items = textContent.items.filter(isTextItem);
117
+ const styles = textContent.styles;
118
+ if (items.length === 0) continue;
119
+ const fontInfoCache = /* @__PURE__ */ new Map();
120
+ const getFontInfo = (fontName) => {
121
+ const cached = fontInfoCache.get(fontName);
122
+ if (cached) return cached;
123
+ let bold = false;
124
+ let italic = false;
125
+ let monospace = false;
126
+ try {
127
+ if (page.commonObjs.has(fontName)) {
128
+ const fontObj = page.commonObjs.get(fontName);
129
+ if (fontObj) {
130
+ bold = fontObj.bold === true || fontObj.black === true;
131
+ italic = fontObj.italic === true;
132
+ monospace = fontObj.isMonospace === true;
133
+ if (fontObj.name) {
134
+ if (!monospace) monospace = isMonospaceFont(fontObj.name);
135
+ if (!bold) bold = isBoldFont(fontObj.name);
136
+ if (!italic) italic = isItalicFont(fontObj.name);
137
+ }
138
+ }
139
+ }
140
+ } catch {
141
+ }
142
+ if (!bold && !italic && !monospace) {
143
+ const style = styles[fontName];
144
+ if (style == null ? void 0 : style.fontFamily) {
145
+ monospace = style.fontFamily === "monospace" || isMonospaceFont(style.fontFamily);
146
+ }
147
+ }
148
+ if (!bold) bold = isBoldFont(fontName);
149
+ if (!italic) italic = isItalicFont(fontName);
150
+ if (!monospace) monospace = isMonospaceFont(fontName);
151
+ const info = { bold, italic, monospace };
152
+ fontInfoCache.set(fontName, info);
153
+ return info;
154
+ };
155
+ const lineGroups = [];
156
+ let currentLineItems = [];
157
+ let currentY = null;
158
+ const Y_TOLERANCE = 2;
159
+ const sorted = [...items].sort((a, b) => {
160
+ const yDiff = b.transform[5] - a.transform[5];
161
+ if (Math.abs(yDiff) > Y_TOLERANCE) return yDiff;
162
+ return a.transform[4] - b.transform[4];
163
+ });
164
+ for (const item of sorted) {
165
+ const y = item.transform[5];
166
+ if (currentY === null || Math.abs(y - currentY) > Y_TOLERANCE) {
167
+ if (currentLineItems.length > 0) lineGroups.push(currentLineItems);
168
+ currentLineItems = [item];
169
+ currentY = y;
170
+ } else {
171
+ currentLineItems.push(item);
172
+ }
173
+ }
174
+ if (currentLineItems.length > 0) lineGroups.push(currentLineItems);
175
+ for (const group of lineGroups) {
176
+ group.sort((a, b) => a.transform[4] - b.transform[4]);
177
+ const runs = group.filter((item) => item.str.length > 0).map((item) => {
178
+ const fontInfo = getFontInfo(item.fontName);
179
+ return {
180
+ text: item.str,
181
+ fontSize: Math.abs(item.transform[3]),
182
+ fontName: item.fontName,
183
+ x: item.transform[4],
184
+ y: item.transform[5],
185
+ width: item.width,
186
+ bold: fontInfo.bold,
187
+ italic: fontInfo.italic,
188
+ monospace: fontInfo.monospace
189
+ };
190
+ });
191
+ if (runs.length === 0) continue;
192
+ const firstRun = runs[0];
193
+ allLines.push({
194
+ runs,
195
+ y: firstRun.y,
196
+ x: firstRun.x,
197
+ fontSize: firstRun.fontSize,
198
+ fontName: firstRun.fontName,
199
+ bold: runs.every((r) => r.bold),
200
+ italic: runs.every((r) => r.italic),
201
+ monospace: runs.every((r) => r.monospace),
202
+ pageIndex: pageNum - 1
203
+ });
204
+ }
205
+ }
206
+ return allLines;
207
+ }
208
+ var BOLD_HEADING_MAX_LENGTH = 100;
209
+ function normalizeForComparison(text) {
210
+ return text.trim().replace(/\s+/g, " ").toLowerCase();
211
+ }
212
+ function groupLinesIntoParagraphs(lines, bodySize, headingLevels, boldHeadingLevel) {
213
+ const groups = [];
214
+ let currentGroup = null;
215
+ for (let i = 0; i < lines.length; i++) {
216
+ const line = lines[i];
217
+ const roundedSize = Math.round(line.fontSize * 10) / 10;
218
+ let headingLevel = headingLevels.get(roundedSize);
219
+ const lineText = line.runs.map((r) => r.text).join("");
220
+ const listInfo = detectListType(lineText);
221
+ const isCode = line.monospace && !headingLevel;
222
+ if (!headingLevel && !isCode && line.bold && lineText.length > 0 && lineText.length <= BOLD_HEADING_MAX_LENGTH && Math.abs(roundedSize - bodySize) <= 1.5) {
223
+ headingLevel = boldHeadingLevel;
224
+ }
225
+ let lineType;
226
+ if (headingLevel) {
227
+ lineType = "heading";
228
+ } else if (isCode) {
229
+ lineType = "code";
230
+ } else if (listInfo) {
231
+ lineType = listInfo.type === "bullet" ? "list-bullet" : "list-numbered";
232
+ } else {
233
+ lineType = "paragraph";
234
+ }
235
+ const isPageBreak = i > 0 && lines[i - 1].pageIndex !== line.pageIndex;
236
+ const shouldStartNew = !currentGroup || isPageBreak || lineType === "heading" || currentGroup.type === "heading" || lineType === "list-bullet" || lineType === "list-numbered" || currentGroup.type === "list-bullet" || currentGroup.type === "list-numbered" || lineType === "code" !== (currentGroup.type === "code") || i > 0 && !isPageBreak && Math.abs(lines[i - 1].y - line.y) > line.fontSize * 1.8 && lineType !== "code";
237
+ if (shouldStartNew) {
238
+ if (currentGroup && currentGroup.lines.length > 0) groups.push(currentGroup);
239
+ currentGroup = { lines: [line], type: lineType, headingLevel };
240
+ } else {
241
+ currentGroup.lines.push(line);
242
+ }
243
+ }
244
+ if (currentGroup && currentGroup.lines.length > 0) groups.push(currentGroup);
245
+ return groups;
246
+ }
247
+ function runsToTextAndAnnotations(runs, allBold, allItalic) {
248
+ const annotations = [];
249
+ let text = "";
250
+ for (const run of runs) {
251
+ if (run.text.length === 0) continue;
252
+ const start = text.length;
253
+ text += run.text;
254
+ const end = text.length;
255
+ if (run.bold && !allBold) {
256
+ annotations.push({ type: "Bold", starts: [start], ends: [end] });
257
+ }
258
+ if (run.italic && !allItalic) {
259
+ annotations.push({ type: "Italic", starts: [start], ends: [end] });
260
+ }
261
+ if (run.monospace) {
262
+ annotations.push({ type: "Code", starts: [start], ends: [end] });
263
+ }
264
+ }
265
+ const merged = mergeAdjacentAnnotations(annotations);
266
+ return { text, annotations: merged };
267
+ }
268
+ function mergeAdjacentAnnotations(annotations) {
269
+ if (annotations.length <= 1) return annotations;
270
+ const byType = /* @__PURE__ */ new Map();
271
+ for (const ann of annotations) {
272
+ const list = byType.get(ann.type) || [];
273
+ list.push(ann);
274
+ byType.set(ann.type, list);
275
+ }
276
+ const result = [];
277
+ for (const [, anns] of Array.from(byType)) {
278
+ anns.sort((a, b) => (a.starts[0] ?? 0) - (b.starts[0] ?? 0));
279
+ let current = { ...anns[0], starts: [...anns[0].starts], ends: [...anns[0].ends] };
280
+ for (let i = 1; i < anns.length; i++) {
281
+ const next = anns[i];
282
+ if ((current.ends[0] ?? 0) >= (next.starts[0] ?? 0)) {
283
+ current.ends[0] = Math.max(current.ends[0] ?? 0, next.ends[0] ?? 0);
284
+ } else {
285
+ result.push(current);
286
+ current = { ...next, starts: [...next.starts], ends: [...next.ends] };
287
+ }
288
+ }
289
+ result.push(current);
290
+ }
291
+ result.sort((a, b) => (a.starts[0] ?? 0) - (b.starts[0] ?? 0));
292
+ return result;
293
+ }
294
+ function buildHierarchy(blocks) {
295
+ const result = [];
296
+ const stack = [];
297
+ for (const { block, headingLevel } of blocks) {
298
+ if (headingLevel && headingLevel > 0) {
299
+ while (stack.length && stack[stack.length - 1].level >= headingLevel) {
300
+ stack.pop();
301
+ }
302
+ const parent = stack[stack.length - 1];
303
+ if (parent) {
304
+ if (!parent.node.children) parent.node.children = [];
305
+ parent.node.children.push(block);
306
+ } else {
307
+ result.push(block);
308
+ }
309
+ stack.push({ level: headingLevel, node: block });
310
+ } else {
311
+ const parent = stack[stack.length - 1];
312
+ if (parent) {
313
+ if (!parent.node.children) parent.node.children = [];
314
+ parent.node.children.push(block);
315
+ } else {
316
+ result.push(block);
317
+ }
318
+ }
319
+ }
320
+ return result;
321
+ }
322
+ async function extractTitle(doc) {
323
+ var _a;
324
+ if (doc.numPages === 0) return void 0;
325
+ const page = await doc.getPage(1);
326
+ await page.getOperatorList();
327
+ const textContent = await page.getTextContent({ includeMarkedContent: false });
328
+ const items = textContent.items.filter(isTextItem);
329
+ if (items.length === 0) return void 0;
330
+ let maxFontSize = 0;
331
+ let titleItems = [];
332
+ for (const item of items) {
333
+ const fontSize = Math.abs(item.transform[3]);
334
+ if (fontSize > maxFontSize + 0.5) {
335
+ maxFontSize = fontSize;
336
+ titleItems = [item];
337
+ } else if (Math.abs(fontSize - maxFontSize) <= 0.5) {
338
+ titleItems.push(item);
339
+ }
340
+ }
341
+ const sizeCount = /* @__PURE__ */ new Map();
342
+ for (const item of items) {
343
+ const size = Math.round(Math.abs(item.transform[3]) * 10) / 10;
344
+ sizeCount.set(size, (sizeCount.get(size) || 0) + 1);
345
+ }
346
+ const bodySize = ((_a = Array.from(sizeCount.entries()).sort((a, b) => b[1] - a[1])[0]) == null ? void 0 : _a[0]) || 12;
347
+ if (maxFontSize <= bodySize + 0.5) {
348
+ return items.slice(0, 10).map((item) => item.str).join("").trim().slice(0, 100) || void 0;
349
+ }
350
+ titleItems.sort((a, b) => a.transform[4] - b.transform[4]);
351
+ return titleItems.map((item) => item.str).join("").trim() || void 0;
352
+ }
353
+ async function embeddedPdfToBlocks(pdfData) {
354
+ let pdfjsLib;
355
+ try {
356
+ pdfjsLib = await import("pdfjs-dist");
357
+ } catch {
358
+ throw new Error(
359
+ "pdfjs-dist is not installed. Install it for embedded PDF extraction:\n pnpm add pdfjs-dist\nOr provide a GROBID server URL for higher-fidelity extraction."
360
+ );
361
+ }
362
+ const loadingTask = pdfjsLib.getDocument({ data: new Uint8Array(pdfData) });
363
+ const doc = await loadingTask.promise;
364
+ if (doc.numPages === 0) {
365
+ return { metadata: { name: void 0 }, blocks: [] };
366
+ }
367
+ const title = await extractTitle(doc);
368
+ const lines = await extractTextRuns(doc);
369
+ if (lines.length === 0) {
370
+ return { metadata: { name: title }, blocks: [] };
371
+ }
372
+ const { bodySize, headingLevels, boldHeadingLevel } = clusterFontSizes(lines);
373
+ const paragraphGroups = groupLinesIntoParagraphs(lines, bodySize, headingLevels, boldHeadingLevel);
374
+ const flatBlocks = [];
375
+ for (const group of paragraphGroups) {
376
+ switch (group.type) {
377
+ case "heading": {
378
+ const allRuns = group.lines.flatMap((l) => l.runs);
379
+ const { text, annotations } = runsToTextAndAnnotations(allRuns, true, false);
380
+ if (text) {
381
+ flatBlocks.push({
382
+ block: makeHeading(text, annotations),
383
+ headingLevel: group.headingLevel
384
+ });
385
+ }
386
+ break;
387
+ }
388
+ case "code": {
389
+ const codeText = group.lines.map((l) => l.runs.map((r) => r.text).join("")).join("\n");
390
+ if (codeText) {
391
+ flatBlocks.push({ block: makeCode(codeText) });
392
+ }
393
+ break;
394
+ }
395
+ case "list-bullet":
396
+ case "list-numbered": {
397
+ const listType = group.type === "list-bullet" ? "Unordered" : "Ordered";
398
+ const items = [];
399
+ for (const line of group.lines) {
400
+ const lineText = line.runs.map((r) => r.text).join("");
401
+ const listInfo = detectListType(lineText);
402
+ const contentText = listInfo ? listInfo.content : lineText;
403
+ items.push(makeParagraph(contentText));
404
+ }
405
+ if (items.length) {
406
+ flatBlocks.push({ block: makeList(items, listType) });
407
+ }
408
+ break;
409
+ }
410
+ case "paragraph":
411
+ default: {
412
+ const allRuns = [];
413
+ const allBold = group.lines.every((l) => l.bold);
414
+ const allItalic = group.lines.every((l) => l.italic);
415
+ for (let i = 0; i < group.lines.length; i++) {
416
+ const line = group.lines[i];
417
+ if (i > 0 && allRuns.length > 0) {
418
+ const lastRun = allRuns[allRuns.length - 1];
419
+ if (lastRun.text.endsWith("-")) {
420
+ lastRun.text = lastRun.text.slice(0, -1);
421
+ } else if (!lastRun.text.endsWith(" ")) {
422
+ allRuns.push({ ...line.runs[0], text: " ", width: 0 });
423
+ }
424
+ }
425
+ allRuns.push(...line.runs);
426
+ }
427
+ const { text, annotations } = runsToTextAndAnnotations(allRuns, allBold, allItalic);
428
+ if (text) {
429
+ flatBlocks.push({ block: makeParagraph(text, annotations) });
430
+ }
431
+ break;
432
+ }
433
+ }
434
+ }
435
+ const PAGE_NUMBER_RE = /^\d{1,3}$/;
436
+ for (let i = flatBlocks.length - 1; i >= 0; i--) {
437
+ const entry = flatBlocks[i];
438
+ if (entry.headingLevel) continue;
439
+ const blockText = (entry.block.block.text || "").trim();
440
+ if (PAGE_NUMBER_RE.test(blockText)) {
441
+ flatBlocks.splice(i, 1);
442
+ }
443
+ }
444
+ if (title && flatBlocks.length > 0) {
445
+ const first = flatBlocks[0];
446
+ if (first.headingLevel) {
447
+ const blockText = first.block.block.text || "";
448
+ if (normalizeForComparison(blockText) === normalizeForComparison(title)) {
449
+ flatBlocks.shift();
450
+ }
451
+ }
452
+ }
453
+ const blocks = buildHierarchy(flatBlocks);
454
+ return { metadata: { name: title }, blocks };
455
+ }
456
+
457
+ export {
458
+ embeddedPdfToBlocks
459
+ };
@@ -0,0 +1,48 @@
1
+ import {
2
+ toPublishInput
3
+ } from "./chunk-LVAHHQIK.mjs";
4
+ import {
5
+ createCapability
6
+ } from "./chunk-IT5LLTMP.mjs";
7
+ import {
8
+ entityQueryPathToHmIdPath,
9
+ packBaseId
10
+ } from "./chunk-SQEUO7FO.mjs";
11
+
12
+ // src/capability.ts
13
+ import { base58btc } from "multiformats/bases/base58";
14
+ async function createCapability2(input, signer) {
15
+ const encoded = await createCapability(
16
+ signer,
17
+ new Uint8Array(base58btc.decode(input.delegateUid)),
18
+ input.role,
19
+ Date.now(),
20
+ { path: input.path || void 0, label: input.label || void 0 }
21
+ );
22
+ return toPublishInput(encoded.data);
23
+ }
24
+ async function resolveCapability(client, targetAccount, signerAccount, path) {
25
+ if (targetAccount === signerAccount) return void 0;
26
+ const pathSegments = path ? entityQueryPathToHmIdPath(path) : null;
27
+ const targetId = {
28
+ id: packBaseId(targetAccount, pathSegments),
29
+ uid: targetAccount,
30
+ path: pathSegments,
31
+ version: null,
32
+ blockRef: null,
33
+ blockRange: null,
34
+ hostname: null,
35
+ latest: true,
36
+ scheme: null
37
+ };
38
+ const caps = await client.request("ListCapabilities", { targetId });
39
+ const match = caps.capabilities.find(
40
+ (c) => c.delegate === signerAccount && (c.role === "WRITER" || c.role === "AGENT")
41
+ );
42
+ return match == null ? void 0 : match.id;
43
+ }
44
+
45
+ export {
46
+ createCapability2 as createCapability,
47
+ resolveCapability
48
+ };
@@ -0,0 +1,29 @@
1
+ // src/errors.ts
2
+ var SeedClientError = class extends Error {
3
+ status;
4
+ body;
5
+ constructor(message, status, body) {
6
+ super(message);
7
+ this.name = "SeedClientError";
8
+ this.status = status;
9
+ this.body = body;
10
+ }
11
+ };
12
+ var SeedNetworkError = class extends Error {
13
+ constructor(message, options) {
14
+ super(message, options);
15
+ this.name = "SeedNetworkError";
16
+ }
17
+ };
18
+ var SeedValidationError = class extends Error {
19
+ constructor(message) {
20
+ super(message);
21
+ this.name = "SeedValidationError";
22
+ }
23
+ };
24
+
25
+ export {
26
+ SeedClientError,
27
+ SeedNetworkError,
28
+ SeedValidationError
29
+ };
@@ -1,12 +1,15 @@
1
1
  import {
2
2
  decrypt
3
- } from "./chunk-EGCUJ6D6.mjs";
3
+ } from "./chunk-UOL3F6XQ.mjs";
4
+ import {
5
+ principalFromEd25519,
6
+ principalToString
7
+ } from "./chunk-IT5LLTMP.mjs";
4
8
 
5
9
  // src/vault.ts
6
10
  import * as dagCBOR from "@ipld/dag-cbor";
7
11
  import { ed25519 } from "@noble/curves/ed25519.js";
8
12
  import * as cborg from "cborg";
9
- import { base58btc } from "multiformats/bases/base58";
10
13
  var VAULT_VERSION = 2;
11
14
  var cborEncodeOpts = {
12
15
  ...dagCBOR.encodeOptions,
@@ -20,18 +23,10 @@ var accountExtraKey = /* @__PURE__ */ Symbol("vault-account-extra");
20
23
  var delegationExtraKey = /* @__PURE__ */ Symbol("vault-delegation-extra");
21
24
  var capabilityExtraKey = /* @__PURE__ */ Symbol("vault-capability-extra");
22
25
  var accountNamePattern = /^[A-Za-z0-9_-]+$/;
23
- var ED25519_MULTICODEC_PREFIX = new Uint8Array([237, 1]);
24
- function principalFromPublicKey(publicKey) {
25
- const principal = new Uint8Array(ED25519_MULTICODEC_PREFIX.length + publicKey.length);
26
- principal.set(ED25519_MULTICODEC_PREFIX, 0);
27
- principal.set(publicKey, ED25519_MULTICODEC_PREFIX.length);
28
- return principal;
29
- }
30
- function principalToString(principal) {
31
- return base58btc.encode(principal);
32
- }
26
+ var principalFromPublicKey = principalFromEd25519;
27
+ var principalToString2 = principalToString;
33
28
  function accountIdFromSeed(seed) {
34
- return principalToString(principalFromPublicKey(new Uint8Array(ed25519.getPublicKey(seed))));
29
+ return principalToString2(principalFromPublicKey(new Uint8Array(ed25519.getPublicKey(seed))));
35
30
  }
36
31
  function createEmpty() {
37
32
  return { version: VAULT_VERSION, accounts: [] };
@@ -314,7 +309,7 @@ async function decryptVaultState(envelope, dek) {
314
309
  export {
315
310
  VAULT_VERSION,
316
311
  principalFromPublicKey,
317
- principalToString,
312
+ principalToString2 as principalToString,
318
313
  accountIdFromSeed,
319
314
  createEmpty,
320
315
  serialize,
@@ -0,0 +1,25 @@
1
+ // src/signer.ts
2
+ function hasPrincipal(signer) {
3
+ return "principal" in signer;
4
+ }
5
+ function toHMSigner(signer) {
6
+ if (!hasPrincipal(signer)) return signer;
7
+ const { principal } = signer;
8
+ return {
9
+ getPublicKey: async () => principal,
10
+ sign: (data) => signer.sign(data)
11
+ };
12
+ }
13
+ async function toPrincipalSigner(signer) {
14
+ if (hasPrincipal(signer)) return signer;
15
+ const principal = await signer.getPublicKey();
16
+ return {
17
+ principal,
18
+ sign: (data) => signer.sign(data)
19
+ };
20
+ }
21
+
22
+ export {
23
+ toHMSigner,
24
+ toPrincipalSigner
25
+ };