@nesso-how/plugin 0.5.0 → 0.7.0

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.
@@ -1,5 +1,11 @@
1
1
  import { z } from "zod";
2
- //#region ../errors/src/index.ts
2
+ //#region ../errors/dist/index.js
3
+ function validationIssues(issues, prefix = "") {
4
+ return issues.map(({ path, message }) => ({
5
+ path: path.reduce((result, key) => typeof key === "number" ? `${result}[${key}]` : result ? `${result}.${String(key)}` : String(key), prefix),
6
+ message
7
+ }));
8
+ }
3
9
  var NessoError = class extends Error {
4
10
  name = "NessoError";
5
11
  issues;
@@ -21,6 +27,17 @@ const boundText = (text, limit) => {
21
27
  }
22
28
  return result;
23
29
  };
30
+ const pluginErrorCodes = [
31
+ "invalid-input",
32
+ "denied",
33
+ "stale-state",
34
+ "stale-context",
35
+ "unavailable",
36
+ "cancelled",
37
+ "timeout",
38
+ "closed",
39
+ "failed"
40
+ ];
24
41
  var PluginError = class extends NessoError {
25
42
  name = "PluginError";
26
43
  code;
@@ -52,7 +69,62 @@ function parseOrThrow(schema, value, prefix = "") {
52
69
  return parsed.data;
53
70
  }
54
71
  //#endregion
55
- //#region ../schema/src/core.ts
72
+ //#region src/files.ts
73
+ const fileTextLimit = 16777216;
74
+ const mediaType = z.string().max(128).regex(/^[\w!#$&^.+-]+\/[\w!#$&^.+-]+$/);
75
+ const fileOpenOptions = z.strictObject({
76
+ extensions: z.array(z.string().regex(/^[a-zA-Z0-9]{1,16}$/)).min(1).max(16),
77
+ mimeTypes: z.array(mediaType).max(16)
78
+ });
79
+ const fileFields = {
80
+ name: z.string().trim().min(1).max(240).regex(/^[^/\\]+$/).refine((value) => value !== "." && value !== ".." && [...value].every((character) => character.charCodeAt(0) >= 32 && character.charCodeAt(0) !== 127)),
81
+ mediaType
82
+ };
83
+ const fileText = z.string().max(fileTextLimit).refine((value) => new TextEncoder().encode(value).byteLength <= fileTextLimit, "File text byte limit exceeded");
84
+ const fileBase64 = z.string().max(4 * Math.ceil(fileTextLimit / 3)).regex(/^[A-Za-z0-9+/]*={0,2}$/).refine((value) => {
85
+ const size = value.length / 4 * 3 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0);
86
+ try {
87
+ return value.length % 4 === 0 && size <= 16777216 && btoa(atob(value)) === value;
88
+ } catch {
89
+ return false;
90
+ }
91
+ }, "Invalid base64 or file byte limit exceeded");
92
+ const fileSaveOptions = z.union([z.strictObject({
93
+ ...fileFields,
94
+ text: fileText
95
+ }), z.strictObject({
96
+ ...fileFields,
97
+ base64: fileBase64
98
+ })]);
99
+ const fileOpenResult = z.strictObject({
100
+ name: z.string().min(1).max(240),
101
+ mediaType,
102
+ text: fileText
103
+ }).nullable();
104
+ function parseFileOptions(kind, value) {
105
+ return parseOrThrow(kind === "open" ? fileOpenOptions : fileSaveOptions, value);
106
+ }
107
+ //#endregion
108
+ //#region src/images.ts
109
+ const imageRenderOptions = z.strictObject({
110
+ format: z.literal("png"),
111
+ scale: z.union([z.literal(2), z.literal(4)]).optional()
112
+ });
113
+ const renderedImage = z.strictObject({
114
+ mediaType: z.literal("image/png"),
115
+ base64: fileBase64
116
+ });
117
+ //#endregion
118
+ //#region ../schema/dist/core.js
119
+ const conceptKeys = [
120
+ "@id",
121
+ "rdfs:label",
122
+ "rdfs:comment",
123
+ "position",
124
+ "color",
125
+ "bold",
126
+ "italic"
127
+ ];
56
128
  const newIri = () => `urn:uuid:${crypto.randomUUID()}`;
57
129
  const isAbsoluteIri = (value) => typeof value === "string" && /^[a-z][a-z0-9+.-]*:/i.test(value);
58
130
  const relationKey = ({ source, predicate, target }) => JSON.stringify([
@@ -61,7 +133,230 @@ const relationKey = ({ source, predicate, target }) => JSON.stringify([
61
133
  target
62
134
  ]);
63
135
  //#endregion
64
- //#region src/commands.ts
136
+ //#region ../schema/dist/types.js
137
+ const iriSchema = z.string({ error: "Expected an absolute IRI" }).refine(isAbsoluteIri, "Expected an absolute IRI");
138
+ const positionSchema = z.strictObject({
139
+ x: z.number(),
140
+ y: z.number()
141
+ });
142
+ const conceptSchema = z.strictObject({
143
+ id: iriSchema,
144
+ label: z.string(),
145
+ notes: z.string().optional(),
146
+ color: z.string().regex(/^#[0-9a-fA-F]{6}$/).optional(),
147
+ bold: z.boolean().optional(),
148
+ italic: z.boolean().optional(),
149
+ position: positionSchema
150
+ });
151
+ const relationTypeSchema = z.strictObject({
152
+ id: iriSchema.refine((id) => !conceptKeys.includes(id), "Reserved concept property IRI"),
153
+ label: z.string()
154
+ });
155
+ const relationSchema = z.strictObject({
156
+ source: iriSchema,
157
+ predicate: iriSchema,
158
+ target: iriSchema
159
+ });
160
+ const graphSchema = z.strictObject({
161
+ concepts: z.array(conceptSchema),
162
+ relationTypes: z.array(relationTypeSchema),
163
+ relations: z.array(relationSchema)
164
+ }).superRefine((graph, context) => {
165
+ const concepts = /* @__PURE__ */ new Set();
166
+ const types = /* @__PURE__ */ new Set();
167
+ const relations = /* @__PURE__ */ new Set();
168
+ for (const [index, concept] of graph.concepts.entries()) {
169
+ if (concepts.has(concept.id)) context.addIssue({
170
+ code: "custom",
171
+ path: [
172
+ "concepts",
173
+ index,
174
+ "id"
175
+ ],
176
+ message: `Duplicate concept IRI: ${concept.id}`
177
+ });
178
+ concepts.add(concept.id);
179
+ }
180
+ for (const [index, type] of graph.relationTypes.entries()) {
181
+ if (types.has(type.id) || concepts.has(type.id)) context.addIssue({
182
+ code: "custom",
183
+ path: [
184
+ "relationTypes",
185
+ index,
186
+ "id"
187
+ ],
188
+ message: `Duplicate relation IRI: ${type.id}`
189
+ });
190
+ types.add(type.id);
191
+ }
192
+ for (const [index, relation] of graph.relations.entries()) {
193
+ const key = relationKey(relation);
194
+ if (!concepts.has(relation.source) || !concepts.has(relation.target)) context.addIssue({
195
+ code: "custom",
196
+ path: ["relations", index],
197
+ message: `Unknown concept in relation: ${key}`
198
+ });
199
+ if (!types.has(relation.predicate)) context.addIssue({
200
+ code: "custom",
201
+ path: [
202
+ "relations",
203
+ index,
204
+ "predicate"
205
+ ],
206
+ message: `Unknown relation type: ${relation.predicate}`
207
+ });
208
+ if (relations.has(key)) context.addIssue({
209
+ code: "custom",
210
+ path: ["relations", index],
211
+ message: `Duplicate relation: ${key}`
212
+ });
213
+ relations.add(key);
214
+ }
215
+ });
216
+ //#endregion
217
+ //#region ../schema/dist/validate.js
218
+ function validateGraph(graph) {
219
+ const result = graphSchema.safeParse(graph);
220
+ return result.success ? [] : validationIssues(result.error.issues);
221
+ }
222
+ //#endregion
223
+ //#region ../schema/dist/jsonld.js
224
+ const jsonObject = z.record(z.string(), z.unknown());
225
+ z.strictObject({
226
+ "@context": jsonObject,
227
+ "@graph": z.array(jsonObject)
228
+ });
229
+ z.strictObject({
230
+ "@id": iriSchema,
231
+ "@type": z.literal("rdf:Property"),
232
+ "rdfs:label": z.string()
233
+ });
234
+ z.object({
235
+ "@id": iriSchema,
236
+ "rdfs:label": conceptSchema.shape.label,
237
+ "rdfs:comment": conceptSchema.shape.notes,
238
+ position: positionSchema.optional(),
239
+ color: conceptSchema.shape.color,
240
+ bold: conceptSchema.shape.bold,
241
+ italic: conceptSchema.shape.italic
242
+ }).catchall(z.unknown());
243
+ //#endregion
244
+ //#region src/definitions.ts
245
+ const themeColors = [
246
+ "background",
247
+ "foreground",
248
+ "canvas",
249
+ "sidebar",
250
+ "primary",
251
+ "primary-hover",
252
+ "primary-foreground",
253
+ "muted",
254
+ "muted-foreground",
255
+ "hover",
256
+ "pressed",
257
+ "border",
258
+ "ring",
259
+ "selection-halo",
260
+ "node-border",
261
+ "edge",
262
+ "handle"
263
+ ];
264
+ const contributionId = z.string().max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/);
265
+ const color = z.string().regex(/^#[\da-fA-F]{6}([\da-fA-F]{2})?$/);
266
+ const fontFace = z.strictObject({
267
+ path: z.string().max(240).regex(/^(?:[\w-]+\/)*[\w-]+\.woff2$/),
268
+ weight: z.tuple([z.number().int().min(1).max(1e3), z.number().int().min(1).max(1e3)]).refine(([min, max]) => min <= max),
269
+ style: z.enum(["normal", "italic"]),
270
+ unicodeRange: z.array(z.tuple([z.number().int().min(0).max(1114111), z.number().int().min(0).max(1114111)]).refine(([min, max]) => min <= max)).min(1).max(64).optional()
271
+ });
272
+ const font = z.strictObject({ faces: z.array(fontFace).max(32) });
273
+ const luminance = (value) => {
274
+ const linear = [
275
+ 1,
276
+ 3,
277
+ 5
278
+ ].map((offset) => parseInt(value.slice(offset, offset + 2), 16) / 255).map((value) => value <= .04045 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4);
279
+ return linear[0] * .2126 + linear[1] * .7152 + linear[2] * .0722;
280
+ };
281
+ const opaque = (value) => value.length === 7 || value.slice(7).toLowerCase() === "ff";
282
+ const contrast = (left, right) => (Math.max(luminance(left), luminance(right)) + .05) / (Math.min(luminance(left), luminance(right)) + .05);
283
+ const themeDefinition = z.strictObject({
284
+ id: contributionId,
285
+ colors: z.strictObject(Object.fromEntries(themeColors.map((key) => [key, color]))),
286
+ metrics: z.strictObject({
287
+ "radius-control": z.number().min(0).max(16),
288
+ "radius-object": z.number().min(0).max(16),
289
+ "duration-state": z.number().int().min(0).max(300)
290
+ }),
291
+ fonts: z.strictObject({
292
+ sans: font,
293
+ mono: font
294
+ })
295
+ }).superRefine(({ colors, fonts }, context) => {
296
+ for (const key of [
297
+ "background",
298
+ "canvas",
299
+ "sidebar"
300
+ ]) {
301
+ if (!opaque(colors[key]) || luminance(colors[key]) < .8) context.addIssue({
302
+ code: "custom",
303
+ path: ["colors", key],
304
+ message: "Expected an opaque light surface"
305
+ });
306
+ if (!opaque(colors.foreground) || contrast(colors.foreground, colors[key]) < 4.5) context.addIssue({
307
+ code: "custom",
308
+ path: ["colors", "foreground"],
309
+ message: "Insufficient foreground contrast"
310
+ });
311
+ }
312
+ if (!opaque(colors.primary) || !opaque(colors["primary-foreground"]) || contrast(colors.primary, colors["primary-foreground"]) < 4.5) context.addIssue({
313
+ code: "custom",
314
+ path: ["colors", "primary-foreground"],
315
+ message: "Insufficient primary contrast"
316
+ });
317
+ if (fonts.sans.faces.length + fonts.mono.faces.length > 32) context.addIssue({
318
+ code: "custom",
319
+ path: ["fonts"],
320
+ message: "Font face limit exceeded"
321
+ });
322
+ });
323
+ const vocabRelationType = z.strictObject({
324
+ id: z.string().min(1).max(2048),
325
+ label: z.string().max(30),
326
+ translations: z.strictObject({
327
+ en: z.string().trim().min(1).max(30).optional(),
328
+ it: z.string().trim().min(1).max(30).optional(),
329
+ "zh-CN": z.string().trim().min(1).max(30).optional()
330
+ }).optional()
331
+ });
332
+ const vocabDefinition = z.strictObject({
333
+ id: contributionId,
334
+ relationTypes: z.array(vocabRelationType).min(1),
335
+ defaultTypeId: z.string().min(1).max(2048)
336
+ }).superRefine(({ relationTypes, defaultTypeId }, context) => {
337
+ for (const issue of validateGraph({
338
+ concepts: [],
339
+ relations: [],
340
+ relationTypes: relationTypes.map(({ id, label }) => ({
341
+ id,
342
+ label
343
+ }))
344
+ })) context.addIssue({
345
+ code: "custom",
346
+ path: ["relationTypes"],
347
+ message: issue.message
348
+ });
349
+ if (!relationTypes.some(({ id }) => id === defaultTypeId)) context.addIssue({
350
+ code: "custom",
351
+ path: ["defaultTypeId"],
352
+ message: "Default type must be offered by the vocabulary"
353
+ });
354
+ });
355
+ function parseDefinition(kind, value) {
356
+ return parseOrThrow(kind === "theme" ? themeDefinition : vocabDefinition, value);
357
+ }
358
+ //#endregion
359
+ //#region ../core/dist/commands.js
65
360
  function createWriteCommands(applyOperations, created) {
66
361
  return {
67
362
  undo: () => applyOperations([{ kind: "history.undo" }]),
@@ -88,8 +383,8 @@ function createWriteCommands(applyOperations, created) {
88
383
  id,
89
384
  value
90
385
  }], historyGroup ? { historyGroup } : void 0),
91
- setConceptDescription: (id, value, historyGroup) => applyOperations([{
92
- kind: "concept.description",
386
+ setConceptNotes: (id, value, historyGroup) => applyOperations([{
387
+ kind: "concept.notes",
93
388
  id,
94
389
  value
95
390
  }], historyGroup ? { historyGroup } : void 0),
@@ -199,200 +494,6 @@ function createWriteCommands(applyOperations, created) {
199
494
  };
200
495
  }
201
496
  //#endregion
202
- //#region ../schema/src/validate.ts
203
- function validateGraph(graph) {
204
- const issues = [];
205
- const concepts = /* @__PURE__ */ new Set();
206
- const types = /* @__PURE__ */ new Set();
207
- const relations = /* @__PURE__ */ new Set();
208
- for (const [index, concept] of graph.concepts.entries()) {
209
- if (!isAbsoluteIri(concept.id)) issues.push({
210
- path: `concepts[${index}].id`,
211
- message: `Expected an absolute IRI: ${concept.id}`
212
- });
213
- else if (concepts.has(concept.id)) issues.push({
214
- path: `concepts[${index}].id`,
215
- message: `Duplicate concept IRI: ${concept.id}`
216
- });
217
- concepts.add(concept.id);
218
- if (concept.description !== void 0 && typeof concept.description !== "string") issues.push({
219
- path: `concepts[${index}].description`,
220
- message: "Expected a string"
221
- });
222
- if (!Number.isFinite(concept.position.x) || !Number.isFinite(concept.position.y)) issues.push({
223
- path: `concepts[${index}].position`,
224
- message: `Invalid position: ${concept.id}`
225
- });
226
- if (concept.color !== void 0 && !/^#[0-9a-fA-F]{6}$/.test(concept.color)) issues.push({
227
- path: `concepts[${index}].color`,
228
- message: `Invalid color: ${concept.id}`
229
- });
230
- if (concept.bold !== void 0 && typeof concept.bold !== "boolean") issues.push({
231
- path: `concepts[${index}].bold`,
232
- message: "Expected a boolean"
233
- });
234
- if (concept.italic !== void 0 && typeof concept.italic !== "boolean") issues.push({
235
- path: `concepts[${index}].italic`,
236
- message: "Expected a boolean"
237
- });
238
- }
239
- for (const [index, type] of graph.relationTypes.entries()) {
240
- if (!isAbsoluteIri(type.id)) issues.push({
241
- path: `relationTypes[${index}].id`,
242
- message: `Expected an absolute IRI: ${type.id}`
243
- });
244
- else if (types.has(type.id) || concepts.has(type.id)) issues.push({
245
- path: `relationTypes[${index}].id`,
246
- message: `Duplicate relation IRI: ${type.id}`
247
- });
248
- types.add(type.id);
249
- }
250
- for (const [index, relation] of graph.relations.entries()) {
251
- if (!concepts.has(relation.source) || !concepts.has(relation.target)) issues.push({
252
- path: `relations[${index}]`,
253
- message: `Unknown concept in relation: ${relationKey(relation)}`
254
- });
255
- if (!types.has(relation.predicate)) issues.push({
256
- path: `relations[${index}].predicate`,
257
- message: `Unknown relation type: ${relation.predicate}`
258
- });
259
- const key = relationKey(relation);
260
- if (relations.has(key)) issues.push({
261
- path: `relations[${index}]`,
262
- message: `Duplicate relation: ${key}`
263
- });
264
- relations.add(key);
265
- }
266
- return issues;
267
- }
268
- //#endregion
269
- //#region src/definitions.ts
270
- const themeColors = [
271
- "background",
272
- "foreground",
273
- "canvas",
274
- "sidebar",
275
- "primary",
276
- "primary-hover",
277
- "primary-foreground",
278
- "muted",
279
- "muted-foreground",
280
- "hover",
281
- "pressed",
282
- "border",
283
- "ring",
284
- "selection-halo",
285
- "node-border",
286
- "edge",
287
- "handle"
288
- ];
289
- const contributionId = z.string().max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/);
290
- const color = z.string().regex(/^#[\da-fA-F]{6}([\da-fA-F]{2})?$/);
291
- const fontFace = z.strictObject({
292
- path: z.string().max(240).regex(/^(?:[\w-]+\/)*[\w-]+\.woff2$/),
293
- weight: z.tuple([z.number().int().min(1).max(1e3), z.number().int().min(1).max(1e3)]).refine(([min, max]) => min <= max),
294
- style: z.enum(["normal", "italic"]),
295
- unicodeRange: z.array(z.tuple([z.number().int().min(0).max(1114111), z.number().int().min(0).max(1114111)]).refine(([min, max]) => min <= max)).min(1).max(64).optional()
296
- });
297
- const font = z.strictObject({ faces: z.array(fontFace).max(32) });
298
- const luminance = (value) => {
299
- const linear = [
300
- 1,
301
- 3,
302
- 5
303
- ].map((offset) => parseInt(value.slice(offset, offset + 2), 16) / 255).map((value) => value <= .04045 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4);
304
- return linear[0] * .2126 + linear[1] * .7152 + linear[2] * .0722;
305
- };
306
- const opaque = (value) => value.length === 7 || value.slice(7).toLowerCase() === "ff";
307
- const contrast = (left, right) => (Math.max(luminance(left), luminance(right)) + .05) / (Math.min(luminance(left), luminance(right)) + .05);
308
- const themeDefinition = z.strictObject({
309
- id: contributionId,
310
- colors: z.strictObject(Object.fromEntries(themeColors.map((key) => [key, color]))),
311
- metrics: z.strictObject({
312
- "radius-control": z.number().min(0).max(16),
313
- "radius-object": z.number().min(0).max(16),
314
- "duration-state": z.number().int().min(0).max(300)
315
- }),
316
- fonts: z.strictObject({
317
- sans: font,
318
- mono: font
319
- })
320
- }).superRefine(({ colors, fonts }, context) => {
321
- for (const key of [
322
- "background",
323
- "canvas",
324
- "sidebar"
325
- ]) {
326
- if (!opaque(colors[key]) || luminance(colors[key]) < .8) context.addIssue({
327
- code: "custom",
328
- path: ["colors", key],
329
- message: "Expected an opaque light surface"
330
- });
331
- if (!opaque(colors.foreground) || contrast(colors.foreground, colors[key]) < 4.5) context.addIssue({
332
- code: "custom",
333
- path: ["colors", "foreground"],
334
- message: "Insufficient foreground contrast"
335
- });
336
- }
337
- if (!opaque(colors.primary) || !opaque(colors["primary-foreground"]) || contrast(colors.primary, colors["primary-foreground"]) < 4.5) context.addIssue({
338
- code: "custom",
339
- path: ["colors", "primary-foreground"],
340
- message: "Insufficient primary contrast"
341
- });
342
- if (fonts.sans.faces.length + fonts.mono.faces.length > 32) context.addIssue({
343
- code: "custom",
344
- path: ["fonts"],
345
- message: "Font face limit exceeded"
346
- });
347
- });
348
- const vocabDefinition = z.strictObject({
349
- id: contributionId,
350
- relationTypes: z.array(z.strictObject({
351
- id: z.string().min(1).max(2048),
352
- label: z.string().max(30)
353
- })).min(1),
354
- defaultTypeId: z.string().min(1).max(2048)
355
- }).superRefine(({ relationTypes, defaultTypeId }, context) => {
356
- for (const issue of validateGraph({
357
- concepts: [],
358
- relations: [],
359
- relationTypes
360
- })) context.addIssue({
361
- code: "custom",
362
- path: ["relationTypes"],
363
- message: issue.message
364
- });
365
- if (!relationTypes.some(({ id }) => id === defaultTypeId)) context.addIssue({
366
- code: "custom",
367
- path: ["defaultTypeId"],
368
- message: "Default type must be offered by the vocabulary"
369
- });
370
- });
371
- function parseDefinition(kind, value) {
372
- return parseOrThrow(kind === "theme" ? themeDefinition : vocabDefinition, value);
373
- }
374
- //#endregion
375
- //#region src/files.ts
376
- const fileTextLimit = 16777216;
377
- const mediaType = z.string().max(128).regex(/^[\w!#$&^.+-]+\/[\w!#$&^.+-]+$/);
378
- const fileOpenOptions = z.strictObject({
379
- extensions: z.array(z.string().regex(/^[a-zA-Z0-9]{1,16}$/)).min(1).max(16),
380
- mimeTypes: z.array(mediaType).max(16)
381
- });
382
- const fileSaveOptions = z.strictObject({
383
- name: z.string().trim().min(1).max(240).regex(/^[^/\\]+$/).refine((value) => value !== "." && value !== ".." && [...value].every((character) => character.charCodeAt(0) >= 32 && character.charCodeAt(0) !== 127)),
384
- mediaType,
385
- text: z.string().max(fileTextLimit).refine((value) => new TextEncoder().encode(value).byteLength <= fileTextLimit, "File text byte limit exceeded")
386
- });
387
- const fileOpenResult = z.strictObject({
388
- name: z.string().min(1).max(240),
389
- mediaType,
390
- text: fileSaveOptions.shape.text
391
- }).nullable();
392
- function parseFileOptions(kind, value) {
393
- return parseOrThrow(kind === "open" ? fileOpenOptions : fileSaveOptions, value);
394
- }
395
- //#endregion
396
497
  //#region src/i18n.ts
397
498
  const text = (limit) => z.string().max(limit).refine((value) => new TextEncoder().encode(value).byteLength <= limit, "Text byte limit exceeded");
398
499
  const localizedText = (limit) => z.strictObject({
@@ -404,33 +505,41 @@ const resolvePluginText = (value, locale) => value[locale] ?? value.en;
404
505
  //#endregion
405
506
  //#region src/data.ts
406
507
  function checkMessageSize(value, limit, maximumDepth = 32) {
508
+ const exceeded = () => new PluginError("invalid-input", [{
509
+ path: "message",
510
+ message: "Message limit exceeded"
511
+ }]);
512
+ let size = 0;
407
513
  const visit = (value, depth) => {
408
514
  if (depth > maximumDepth) throw new PluginError("invalid-input", [{
409
515
  path: "message",
410
516
  message: "Nesting limit exceeded"
411
517
  }]);
518
+ if (value === void 0) return;
519
+ size += typeof value === "string" ? value.length + 1 : 1;
520
+ if (size > limit) throw exceeded();
412
521
  if (value === null) return;
413
522
  if (typeof value === "object") {
414
- if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype) throw new PluginError("invalid-input", [{
523
+ const array = Array.isArray(value);
524
+ if (!array && Object.getPrototypeOf(value) !== Object.prototype) throw new PluginError("invalid-input", [{
415
525
  path: "message",
416
526
  message: "Expected plain data"
417
527
  }]);
418
- for (const item of Object.values(value)) visit(item, depth + 1);
528
+ for (const [key, item] of Object.entries(value)) {
529
+ if (!array && item !== void 0) size += key.length;
530
+ visit(item, depth + 1);
531
+ }
419
532
  } else if (![
420
533
  "string",
421
534
  "number",
422
- "boolean",
423
- "undefined"
535
+ "boolean"
424
536
  ].includes(typeof value) || typeof value === "number" && !Number.isFinite(value)) throw new PluginError("invalid-input", [{
425
537
  path: "message",
426
538
  message: "Expected serializable data"
427
539
  }]);
428
540
  };
429
541
  visit(value, 0);
430
- if (new TextEncoder().encode(JSON.stringify(value)).byteLength > limit) throw new PluginError("invalid-input", [{
431
- path: "message",
432
- message: "Message limit exceeded"
433
- }]);
542
+ if (new TextEncoder().encode(JSON.stringify(value)).byteLength > limit) throw exceeded();
434
543
  }
435
544
  //#endregion
436
545
  //#region src/storage.ts
@@ -450,9 +559,16 @@ const isJsonValue = (value, depth = 0) => {
450
559
  if (Array.isArray(value)) return Reflect.ownKeys(value).length === value.length + 1 && Array.from(value).every((item) => isJsonValue(item, depth + 1));
451
560
  return Object.getPrototypeOf(value) === Object.prototype && Reflect.ownKeys(value).length === Object.keys(value).length && Object.values(value).every((item) => isJsonValue(item, depth + 1));
452
561
  };
562
+ const pluginStorageScope = z.discriminatedUnion("kind", [z.strictObject({
563
+ kind: z.literal("concept"),
564
+ id: z.string().max(2048)
565
+ }), z.strictObject({
566
+ kind: z.literal("view"),
567
+ id: z.string().max(2048)
568
+ })]);
453
569
  const fields = {
454
570
  key: z.string().min(1).max(128),
455
- conceptId: z.string().max(2048).optional()
571
+ scope: pluginStorageScope.optional()
456
572
  };
457
573
  const pluginStorageKey = z.strictObject(fields);
458
574
  const pluginStorageRecord = z.strictObject({
@@ -486,6 +602,17 @@ function parsePluginStorageKey(value) {
486
602
  return parseOrThrow(pluginStorageKey, value);
487
603
  }
488
604
  //#endregion
605
+ //#region src/theme-fonts.ts
606
+ const fontFaces = (ranges, stem, weight) => ({ faces: Object.entries(ranges).map(([subset, intervals]) => ({
607
+ path: `fonts/${stem.replace("{subset}", subset)}.woff2`,
608
+ weight,
609
+ style: "normal",
610
+ unicodeRange: intervals.split(",").map((interval) => {
611
+ const [from, to = from] = interval.slice(2).split("-");
612
+ return [parseInt(from, 16), parseInt(to, 16)];
613
+ })
614
+ })) });
615
+ //#endregion
489
616
  //#region src/runtime.ts
490
617
  const runtimeLimits = {
491
618
  request: 33554432,
@@ -497,6 +624,17 @@ const runtimeLimits = {
497
624
  action: 12e4,
498
625
  heartbeat: 15e3
499
626
  };
627
+ const badgeLimits = {
628
+ value: 999999,
629
+ execution: 2e3,
630
+ refresh: 15e3,
631
+ rate: 1e3
632
+ };
633
+ const actionBadgeResult = z.strictObject({
634
+ value: z.number().int().min(0).max(badgeLimits.value).nullable(),
635
+ refreshAt: z.number().int().min(0).max(864e13).optional()
636
+ });
637
+ const parseActionBadgeResult = (value) => parseOrThrow(actionBadgeResult, value);
500
638
  const themeTokens = [
501
639
  ...themeColors,
502
640
  "font-sans",
@@ -506,10 +644,7 @@ const themeTokens = [
506
644
  "duration-state"
507
645
  ];
508
646
  const id = z.string().min(1).max(2048);
509
- const position = z.strictObject({
510
- x: z.number(),
511
- y: z.number()
512
- });
647
+ const position = positionSchema;
513
648
  const selection = z.array(z.strictObject({
514
649
  kind: z.enum(["concept", "relation"]),
515
650
  id
@@ -530,7 +665,7 @@ const operation = z.discriminatedUnion("kind", [
530
665
  value: z.string()
531
666
  }),
532
667
  z.strictObject({
533
- kind: z.literal("concept.description"),
668
+ kind: z.literal("concept.notes"),
534
669
  id,
535
670
  value: z.string()
536
671
  }),
@@ -677,12 +812,12 @@ function parsePluginI18n(value) {
677
812
  checkMessageSize(value, 65536);
678
813
  return parseOrThrow(pluginI18n, value, "i18n.");
679
814
  }
680
- const manifestFields = { apiVersion: z.literal(1) };
815
+ const manifestFields = { apiVersion: z.literal(2) };
681
816
  const jsEntry = z.string().max(240).regex(/^(?:[\w-]+\/)*[\w-]+\.js$/);
682
817
  const jsonEntry = z.string().max(240).regex(/^(?:[\w-]+\/)*[\w-]+\.json$/);
683
818
  const operationDeclarations = z.array(z.enum([
684
819
  "concept.label",
685
- "concept.description",
820
+ "concept.notes",
686
821
  "concept.color",
687
822
  "concept.bold",
688
823
  "concept.italic",
@@ -705,6 +840,7 @@ const manifest = z.discriminatedUnion("kind", [z.strictObject({
705
840
  writes: operationDeclarations,
706
841
  capabilities: z.array(z.enum([
707
842
  "files",
843
+ "images",
708
844
  "notifications",
709
845
  "storage",
710
846
  "ui"
@@ -773,20 +909,15 @@ const request = z.discriminatedUnion("method", [
773
909
  ...envelope,
774
910
  method: z.literal("files.save"),
775
911
  params: fileSaveOptions
912
+ }),
913
+ z.strictObject({
914
+ ...envelope,
915
+ method: z.literal("images.renderView"),
916
+ params: imageRenderOptions
776
917
  })
777
918
  ]);
778
919
  const wireError = z.strictObject({
779
- code: z.enum([
780
- "invalid-input",
781
- "denied",
782
- "stale-state",
783
- "stale-context",
784
- "unavailable",
785
- "cancelled",
786
- "timeout",
787
- "closed",
788
- "failed"
789
- ]),
920
+ code: z.enum(pluginErrorCodes),
790
921
  issues: z.array(z.strictObject({
791
922
  path: text(256),
792
923
  message: text(2048)
@@ -804,6 +935,10 @@ const message = z.union([
804
935
  type: z.literal("contribution"),
805
936
  value: z.unknown()
806
937
  }),
938
+ z.strictObject({
939
+ type: z.literal("badge-result"),
940
+ value: actionBadgeResult
941
+ }),
807
942
  z.strictObject({
808
943
  type: z.literal("close"),
809
944
  reason: z.string().max(2048)
@@ -822,7 +957,8 @@ const actionDescriptor = z.strictObject({
822
957
  id: z.string().max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
823
958
  label: localizedText(128),
824
959
  icon: z.string().min(1).max(32).regex(/^[a-z]+(?:-[a-z]+)*$/).optional(),
825
- ui: z.literal(true).optional()
960
+ ui: z.literal(true).optional(),
961
+ badge: z.literal(true).optional()
826
962
  });
827
963
  const actionIconNames = [
828
964
  "arrow-right",
@@ -833,12 +969,14 @@ const actionIconNames = [
833
969
  "file-down",
834
970
  "file-up",
835
971
  "folder",
972
+ "glasses",
836
973
  "globe",
837
974
  "layers",
838
975
  "pencil",
839
976
  "play",
840
977
  "plus",
841
978
  "refresh",
979
+ "repeat",
842
980
  "scissors",
843
981
  "search",
844
982
  "share",
@@ -852,35 +990,18 @@ function parseContribution(kind, value) {
852
990
  if (kind === "theme" || kind === "vocab") return parseDefinition(kind, value);
853
991
  return parseOrThrow(actionDescriptors, value);
854
992
  }
855
- const graph = z.strictObject({
856
- concepts: z.array(z.strictObject({
857
- id,
858
- label: z.string(),
859
- description: z.string().optional(),
860
- color: z.string().regex(/^#[0-9a-fA-F]{6}$/).optional(),
861
- bold: z.boolean().optional(),
862
- italic: z.boolean().optional(),
863
- position
864
- })),
865
- relationTypes: z.array(relationType),
866
- relations: z.array(z.strictObject({
867
- source: id,
868
- predicate: id,
869
- target: id
870
- }))
871
- });
872
993
  const actionStateSchema = z.strictObject({
873
994
  revision: z.number().int().nonnegative(),
874
995
  contextId: id,
875
996
  locale,
876
997
  theme: z.strictObject(Object.fromEntries(themeTokens.map((token) => [token, z.string().max(512).regex(/^[#\w\s.,()%/"'-]*$/)]))),
877
998
  conceptPlacementOffset: position,
878
- viewGraph: graph,
999
+ viewGraph: graphSchema,
879
1000
  selected: selection,
880
1001
  targetViewId: id.nullable(),
881
1002
  activeVocab: z.strictObject({
882
1003
  id,
883
- relationTypes: z.array(relationType),
1004
+ relationTypes: z.array(vocabRelationType),
884
1005
  defaultTypeId: id
885
1006
  }).nullable(),
886
1007
  history: z.strictObject({
@@ -939,7 +1060,8 @@ const results = {
939
1060
  }),
940
1061
  "notifications.notify": id,
941
1062
  "files.open": fileOpenResult,
942
- "files.save": z.strictObject({ saved: z.boolean() })
1063
+ "files.save": z.strictObject({ saved: z.boolean() }),
1064
+ "images.renderView": renderedImage
943
1065
  };
944
1066
  function parsePluginMessage(value) {
945
1067
  checkMessageSize(value, runtimeLimits.request);
@@ -1106,23 +1228,24 @@ function createPluginClient(port, initial) {
1106
1228
  applyOperations
1107
1229
  },
1108
1230
  notifications: { notify: (value) => call("notifications.notify", value) },
1231
+ images: { renderView: (options) => call("images.renderView", options) },
1109
1232
  files: {
1110
1233
  open: (options) => call("files.open", options),
1111
1234
  save: (options) => call("files.save", options)
1112
1235
  },
1113
1236
  storage: {
1114
1237
  list: listStorage,
1115
- set: (key, value, conceptId) => mutateStorage("storage.set", conceptId === void 0 ? {
1238
+ set: (key, value, scope) => mutateStorage("storage.set", scope === void 0 ? {
1116
1239
  key,
1117
1240
  value
1118
1241
  } : {
1119
1242
  key,
1120
1243
  value,
1121
- conceptId
1244
+ scope
1122
1245
  }),
1123
- delete: (key, conceptId) => mutateStorage("storage.delete", conceptId === void 0 ? { key } : {
1246
+ delete: (key, scope) => mutateStorage("storage.delete", scope === void 0 ? { key } : {
1124
1247
  key,
1125
- conceptId
1248
+ scope
1126
1249
  })
1127
1250
  },
1128
1251
  signal: controller.signal
@@ -1135,4 +1258,4 @@ function createPluginClient(port, initial) {
1135
1258
  };
1136
1259
  }
1137
1260
  //#endregion
1138
- export { parseOrThrow as S, parseFileOptions as _, parsePluginManifest as a, createWriteCommands as b, sha256Hex as c, parsePluginStorageRecord as d, parsePluginStorageSnapshot as f, fileTextLimit as g, resolvePluginText as h, parsePluginI18n as i, themeTokens as l, checkMessageSize as m, createPluginClient as n, parsePluginMessage as o, pluginStorageLimits as p, parseContribution as r, runtimeLimits as s, actionIconNames as t, parsePluginStorageKey as u, parseDefinition as v, PluginError as x, themeColors as y };
1261
+ export { PluginError as C, parseFileOptions as S, checkMessageSize as _, parseContribution as a, themeColors as b, parsePluginMessage as c, themeTokens as d, fontFaces as f, pluginStorageLimits as g, parsePluginStorageSnapshot as h, parseActionBadgeResult as i, runtimeLimits as l, parsePluginStorageRecord as m, badgeLimits as n, parsePluginI18n as o, parsePluginStorageKey as p, createPluginClient as r, parsePluginManifest as s, actionIconNames as t, sha256Hex as u, resolvePluginText as v, parseOrThrow as w, fileTextLimit as x, parseDefinition as y };