@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,348 @@
1
+ import {
2
+ AnnotationSet
3
+ } from "./chunk-N3P7S5YZ.mjs";
4
+ import {
5
+ HMBlockButtonAlignmentSchema,
6
+ HMBlockSchema,
7
+ codePointLength,
8
+ toNumber
9
+ } from "./chunk-SQEUO7FO.mjs";
10
+
11
+ // src/editorblock-to-hmblock.ts
12
+ function toHMBlockType(editorBlockType) {
13
+ if (editorBlockType === "heading") return "Heading";
14
+ if (editorBlockType === "paragraph") return "Paragraph";
15
+ if (editorBlockType === "code-block") return "Code";
16
+ if (editorBlockType === "math") return "Math";
17
+ if (editorBlockType === "image") return "Image";
18
+ if (editorBlockType === "video") return "Video";
19
+ if (editorBlockType === "file") return "File";
20
+ if (editorBlockType === "button") return "Button";
21
+ if (editorBlockType === "embed") return "Embed";
22
+ if (editorBlockType === "web-embed") return "WebEmbed";
23
+ if (editorBlockType === "query") return "Query";
24
+ if (editorBlockType === "table") return "Table";
25
+ if (editorBlockType === "tableRow") return "TableRow";
26
+ if (editorBlockType === "tableColumn") return "TableColumn";
27
+ return void 0;
28
+ }
29
+ function toImageWidthNumber(width) {
30
+ if (width == null ? void 0 : width.trim().endsWith("%")) {
31
+ const percentage = Number(width.trim().slice(0, -1));
32
+ return Number.isFinite(percentage) && percentage > 0 ? percentage : null;
33
+ }
34
+ if (width == null || width === "") return null;
35
+ return toNumber(width);
36
+ }
37
+ function unknownEditorBlockToHMBlock(editorBlock) {
38
+ const props = editorBlock.props ?? {};
39
+ if (props.originalData) {
40
+ try {
41
+ const parsed = JSON.parse(props.originalData);
42
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
43
+ return { ...parsed, id: editorBlock.id };
44
+ }
45
+ } catch {
46
+ }
47
+ }
48
+ return {
49
+ id: editorBlock.id,
50
+ type: props.originalType || "unknown",
51
+ text: "",
52
+ annotations: [],
53
+ attributes: {}
54
+ };
55
+ }
56
+ function editorBlockToHMBlock(editorBlock) {
57
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
58
+ if (editorBlock.type === "unknown") {
59
+ return unknownEditorBlockToHMBlock(editorBlock);
60
+ }
61
+ const blockType = toHMBlockType(editorBlock.type);
62
+ if (!blockType) throw new Error("Unsupported block type " + editorBlock.type);
63
+ let block = {
64
+ id: normalizeEditorBlockId(editorBlock.id),
65
+ type: blockType,
66
+ attributes: {},
67
+ text: "",
68
+ annotations: []
69
+ };
70
+ let leaves = flattenLeaves(editorBlock.content);
71
+ if (editorBlock.props.childrenType == "Group") {
72
+ block.attributes.childrenType = "Group";
73
+ } else if (editorBlock.props.childrenType == "Unordered") {
74
+ block.attributes.childrenType = "Unordered";
75
+ } else if (editorBlock.props.childrenType == "Ordered") {
76
+ block.attributes.childrenType = "Ordered";
77
+ } else if (editorBlock.props.childrenType == "Blockquote") {
78
+ block.attributes.childrenType = "Blockquote";
79
+ } else if (editorBlock.props.childrenType == "Grid") {
80
+ block.attributes.childrenType = "Grid";
81
+ if (editorBlock.props.columnCount) {
82
+ block.attributes.columnCount = Number(editorBlock.props.columnCount);
83
+ }
84
+ }
85
+ const annotations = new AnnotationSet();
86
+ let pos = 0;
87
+ for (let leaf of leaves) {
88
+ const start = pos;
89
+ const charCount = codePointLength(leaf.text);
90
+ const end = start + charCount;
91
+ if ((_a = leaf.styles) == null ? void 0 : _a.bold) {
92
+ annotations.addSpan("Bold", null, start, end);
93
+ }
94
+ if ((_b = leaf.styles) == null ? void 0 : _b.italic) {
95
+ annotations.addSpan("Italic", null, start, end);
96
+ }
97
+ if ((_c = leaf.styles) == null ? void 0 : _c.underline) {
98
+ annotations.addSpan("Underline", null, start, end);
99
+ }
100
+ if ((_d = leaf.styles) == null ? void 0 : _d.strike) {
101
+ annotations.addSpan("Strike", null, start, end);
102
+ }
103
+ if ((_e = leaf.styles) == null ? void 0 : _e.code) {
104
+ annotations.addSpan("Code", null, start, end);
105
+ }
106
+ if ((_f = leaf.styles) == null ? void 0 : _f.math) {
107
+ annotations.addSpan("Math", null, start, end);
108
+ }
109
+ if (leaf.type == "inline-embed") {
110
+ annotations.addSpan("Embed", { link: leaf.link }, start, end);
111
+ }
112
+ if (leaf.type == "link") {
113
+ annotations.addSpan("Link", { link: leaf.href }, start, end);
114
+ }
115
+ if ((_g = leaf.styles) == null ? void 0 : _g.textColor) {
116
+ annotations.addSpan("TextColor", { value: leaf.styles.textColor }, start, end);
117
+ }
118
+ if ((_h = leaf.styles) == null ? void 0 : _h.backgroundColor) {
119
+ annotations.addSpan("BackgroundColor", { value: leaf.styles.backgroundColor }, start, end);
120
+ }
121
+ if ((_i = leaf.styles) == null ? void 0 : _i.textSize) {
122
+ annotations.addSpan("TextSize", { value: leaf.styles.textSize }, start, end);
123
+ }
124
+ if ((_j = leaf.styles) == null ? void 0 : _j.textFamily) {
125
+ annotations.addSpan("TextFamily", { value: leaf.styles.textFamily }, start, end);
126
+ }
127
+ block.text += leaf.text;
128
+ pos += charCount;
129
+ }
130
+ let outAnnotations = annotations.list();
131
+ if (outAnnotations) {
132
+ block.annotations = outAnnotations;
133
+ }
134
+ const blockCode = block.type === "Code" ? block : void 0;
135
+ if (blockCode && editorBlock.type == "code-block") {
136
+ blockCode.attributes.language = editorBlock.props.language;
137
+ }
138
+ const blockImage = block.type === "Image" ? block : void 0;
139
+ if (blockImage && editorBlock.type == "image") {
140
+ if (editorBlock.props.url && !editorBlock.props.mediaRef) {
141
+ blockImage.link = editorBlock.props.url;
142
+ } else if (editorBlock.props.mediaRef) {
143
+ blockImage.link = "";
144
+ } else if (editorBlock.props.displaySrc) {
145
+ blockImage.link = editorBlock.props.displaySrc;
146
+ } else if (editorBlock.props.src) {
147
+ blockImage.link = editorBlock.props.src;
148
+ } else {
149
+ blockImage.link = "";
150
+ }
151
+ const width = toImageWidthNumber(editorBlock.props.width);
152
+ if (width) {
153
+ blockImage.attributes.width = width;
154
+ }
155
+ }
156
+ const blockVideo = block.type === "Video" ? block : void 0;
157
+ if (blockVideo && editorBlock.type == "video") {
158
+ blockVideo.text = "";
159
+ if (editorBlock.props.url && !editorBlock.props.mediaRef) {
160
+ blockVideo.link = editorBlock.props.url;
161
+ } else if (editorBlock.props.mediaRef) {
162
+ blockVideo.link = "";
163
+ }
164
+ if (editorBlock.props.width != null && editorBlock.props.width !== "") {
165
+ const width = toNumber(editorBlock.props.width);
166
+ if (width) blockVideo.attributes.width = width;
167
+ }
168
+ if (editorBlock.props.name) {
169
+ blockVideo.attributes.name = editorBlock.props.name;
170
+ }
171
+ if (editorBlock.props.autoplay === "true") {
172
+ blockVideo.attributes.autoplay = true;
173
+ }
174
+ if (editorBlock.props.loop === "true") {
175
+ blockVideo.attributes.loop = true;
176
+ }
177
+ if (editorBlock.props.muted === "true") {
178
+ blockVideo.attributes.muted = true;
179
+ }
180
+ }
181
+ const blockFile = block.type === "File" ? block : void 0;
182
+ if (blockFile && editorBlock.type == "file") {
183
+ if (editorBlock.props.url && !editorBlock.props.mediaRef) {
184
+ blockFile.link = editorBlock.props.url;
185
+ } else if (editorBlock.props.mediaRef) {
186
+ blockFile.link = "";
187
+ }
188
+ if (editorBlock.props.name) blockFile.attributes.name = editorBlock.props.name;
189
+ if (editorBlock.props.size != null && editorBlock.props.size !== "") {
190
+ const size = toNumber(editorBlock.props.size);
191
+ if (size) blockFile.attributes.size = size;
192
+ }
193
+ }
194
+ const blockButton = block.type === "Button" ? block : void 0;
195
+ if (blockButton && editorBlock.type == "button") {
196
+ if (editorBlock.props.url) blockButton.link = editorBlock.props.url;
197
+ if (editorBlock.props.name) blockButton.attributes.name = editorBlock.props.name;
198
+ if (editorBlock.props.alignment)
199
+ blockButton.attributes.alignment = HMBlockButtonAlignmentSchema.parse(editorBlock.props.alignment);
200
+ }
201
+ const blockWebEmbed = block.type === "WebEmbed" ? block : void 0;
202
+ if (blockWebEmbed && editorBlock.type == "web-embed" && editorBlock.props.url) {
203
+ blockWebEmbed.link = editorBlock.props.url;
204
+ }
205
+ const blockEmbed = block.type === "Embed" ? block : void 0;
206
+ if (blockEmbed && editorBlock.type == "embed") {
207
+ block.text = "";
208
+ if (editorBlock.props.url) blockEmbed.link = editorBlock.props.url;
209
+ if (editorBlock.props.view) blockEmbed.attributes.view = editorBlock.props.view;
210
+ }
211
+ const blockParagraph = block.type === "Paragraph" ? block : void 0;
212
+ if (blockParagraph && editorBlock.type == "paragraph") {
213
+ if (editorBlock.props.columnId) {
214
+ blockParagraph.attributes.columnId = editorBlock.props.columnId;
215
+ }
216
+ }
217
+ const blockTable = block.type === "Table" ? block : void 0;
218
+ if (blockTable && editorBlock.type == "table") {
219
+ blockTable.text = "";
220
+ }
221
+ const blockTableRow = block.type === "TableRow" ? block : void 0;
222
+ if (blockTableRow && editorBlock.type == "tableRow") {
223
+ blockTableRow.text = "";
224
+ if (editorBlock.props.isHeader) blockTableRow.attributes.isHeader = true;
225
+ }
226
+ const blockTableColumn = block.type === "TableColumn" ? block : void 0;
227
+ if (blockTableColumn && editorBlock.type == "tableColumn") {
228
+ blockTableColumn.text = "";
229
+ if (editorBlock.props.width != null && editorBlock.props.width !== "") {
230
+ const width = toNumber(editorBlock.props.width);
231
+ if (width) blockTableColumn.attributes.width = width;
232
+ }
233
+ if (editorBlock.props.isHeader) blockTableColumn.attributes.isHeader = true;
234
+ }
235
+ const blockQuery = block.type === "Query" ? block : void 0;
236
+ if (blockQuery && editorBlock.type == "query") {
237
+ blockQuery.attributes.style = editorBlock.props.style;
238
+ blockQuery.attributes.columnCount = Number(editorBlock.props.columnCount);
239
+ const query = {
240
+ includes: [],
241
+ sort: []
242
+ };
243
+ if (editorBlock.props.queryIncludes) query.includes = JSON.parse(editorBlock.props.queryIncludes);
244
+ if (editorBlock.props.querySort) query.sort = JSON.parse(editorBlock.props.querySort);
245
+ if (editorBlock.props.queryLimit) query.limit = Number(editorBlock.props.queryLimit);
246
+ blockQuery.attributes.query = query;
247
+ blockQuery.attributes.banner = editorBlock.props.banner == "true";
248
+ if (editorBlock.props.tableConfig) blockQuery.attributes.table = JSON.parse(editorBlock.props.tableConfig);
249
+ }
250
+ const blockParse = HMBlockSchema.safeParse(block);
251
+ if (blockParse.success) {
252
+ return blockParse.data;
253
+ }
254
+ const failedParse = blockParse;
255
+ console.error("Failed to validate block for writing", block, failedParse.error);
256
+ throw new Error("Failed to validate block for writing " + JSON.stringify(failedParse.error));
257
+ }
258
+ function editorBlocksToHMBlockNodes(editorBlocks, parentEditorType) {
259
+ const parentIsTable = parentEditorType === "table";
260
+ let rowIdx = 0;
261
+ let colIdx = 0;
262
+ return editorBlocks.filter((block) => {
263
+ if ((block.type === "tableRow" || block.type === "tableColumn") && !parentIsTable) {
264
+ console.warn(
265
+ `[editorBlocksToHMBlockNodes] dropping orphan ${block.type} block (parent type: ${parentEditorType ?? "root"})`,
266
+ block.id
267
+ );
268
+ return false;
269
+ }
270
+ return true;
271
+ }).map((block) => {
272
+ var _a, _b, _c;
273
+ let positionIdx;
274
+ if (parentIsTable) {
275
+ if (block.type === "tableRow") positionIdx = rowIdx++;
276
+ else if (block.type === "tableColumn") positionIdx = colIdx++;
277
+ }
278
+ let hmNode;
279
+ try {
280
+ hmNode = {
281
+ block: editorBlockToHMBlock(block),
282
+ children: ((_a = block.children) == null ? void 0 : _a.length) ? editorBlocksToHMBlockNodes(block.children, block.type) : void 0
283
+ };
284
+ } catch {
285
+ hmNode = {
286
+ block: {
287
+ id: block.id || "unknown",
288
+ type: "Paragraph",
289
+ text: `[Unsupported block type: ${block.type}]`,
290
+ annotations: [],
291
+ attributes: {}
292
+ },
293
+ children: ((_b = block.children) == null ? void 0 : _b.length) ? editorBlocksToHMBlockNodes(block.children, block.type) : void 0
294
+ };
295
+ }
296
+ if (positionIdx !== void 0 && positionIdx > 0) {
297
+ const attrs = (_c = hmNode.block) == null ? void 0 : _c.attributes;
298
+ if (attrs && "isHeader" in attrs) {
299
+ delete attrs.isHeader;
300
+ }
301
+ }
302
+ return hmNode;
303
+ }).filter(Boolean);
304
+ }
305
+ function flattenLeaves(content) {
306
+ let result = [];
307
+ for (let i = 0; i < content.length; i++) {
308
+ const leaf = content[i];
309
+ if (!leaf) continue;
310
+ if (leaf.type == "link") {
311
+ let nestedLeaves = flattenLeaves(leaf.content).map(
312
+ (l) => ({
313
+ ...l,
314
+ href: leaf.href,
315
+ type: "link"
316
+ })
317
+ );
318
+ result.push(...nestedLeaves);
319
+ }
320
+ if (leaf.type == "inline-embed") {
321
+ result.push({
322
+ ...leaf,
323
+ text: "\uFFFC",
324
+ link: leaf.link
325
+ });
326
+ }
327
+ if (leaf.type == "text") {
328
+ result.push(leaf);
329
+ }
330
+ }
331
+ return result;
332
+ }
333
+ function normalizeEditorBlockId(id) {
334
+ return id && id !== "empty" ? id : generateBlockId();
335
+ }
336
+ function generateBlockId(length = 8) {
337
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
338
+ let result = "";
339
+ for (let i = 0; i < length; i++) {
340
+ result += characters.charAt(Math.floor(Math.random() * characters.length));
341
+ }
342
+ return result;
343
+ }
344
+
345
+ export {
346
+ editorBlockToHMBlock,
347
+ editorBlocksToHMBlockNodes
348
+ };