@pixerate/editor 0.265.0 → 0.266.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,3 +1,7 @@
1
+ import {
2
+ CommandRegistry,
3
+ createCommandToolProvider
4
+ } from "../chunk-HAEB3MZD.js";
1
5
  import {
2
6
  planGenerationRequest,
3
7
  stableStringify
@@ -8,6 +12,11 @@ import {
8
12
  hatchPath,
9
13
  pathfinder
10
14
  } from "../chunk-65MDXWA7.js";
15
+ import "../chunk-PXXXRCME.js";
16
+ import {
17
+ ToolRegistry
18
+ } from "../chunk-K4BGRCSH.js";
19
+ import "../chunk-EHTX34RE.js";
11
20
  import {
12
21
  VECTOR_TRACE_MAX_PIXELS,
13
22
  bendSegment,
@@ -35,6 +44,7 @@ import {
35
44
  orderQuad,
36
45
  solve8
37
46
  } from "../chunk-OHKOFKBY.js";
47
+ import "../chunk-IVSWRVB4.js";
38
48
  import {
39
49
  correspondMorphContours,
40
50
  createVectorMorph,
@@ -590,7 +600,9 @@ import {
590
600
  import "../chunk-SIFAIGB3.js";
591
601
  import "../chunk-VDGBHYC7.js";
592
602
  import {
593
- defineEditorDocument
603
+ EDITOR_DOCUMENT_FORMAT,
604
+ defineEditorDocument,
605
+ toEditorDocumentFile
594
606
  } from "../chunk-XBQX76CT.js";
595
607
  import "../chunk-HF5QZS7Z.js";
596
608
  import {
@@ -18396,12 +18408,193 @@ function createVectorStickerHost(controller, options = {}) {
18396
18408
  }
18397
18409
  };
18398
18410
  }
18411
+
18412
+ // src/vector/contract.ts
18413
+ var VECTOR_CONTRACT_FORMAT_VERSION = 1;
18414
+ var VECTOR_DOCUMENT_JSON_SCHEMA = {
18415
+ type: "object",
18416
+ description: "A saved vector document, as the vector editor's save tools and autosave write it.",
18417
+ properties: {
18418
+ format: { type: "string", const: EDITOR_DOCUMENT_FORMAT, description: `Always "${EDITOR_DOCUMENT_FORMAT}".` },
18419
+ kind: { type: "string", const: "vector", description: 'Always "vector".' },
18420
+ formatVersion: { type: "integer", minimum: 1, description: "Version of the envelope for this kind; readers migrate older ones." },
18421
+ name: { type: "string", description: "Display name, when it has one." },
18422
+ document: {
18423
+ type: "object",
18424
+ description: "The drawing (`VectorDocument`, as get_vector_document returns it).",
18425
+ properties: {
18426
+ width: { type: "number", exclusiveMinimum: 0, description: "Artboard width in document units." },
18427
+ height: { type: "number", exclusiveMinimum: 0, description: "Artboard height in document units." },
18428
+ background: { type: "string", description: "Artboard colour (default: transparent)." },
18429
+ nodes: {
18430
+ type: "array",
18431
+ description: "Top-level nodes, bottom to top. Groups hold their own children.",
18432
+ items: {
18433
+ type: "object",
18434
+ properties: {
18435
+ id: { type: "string", description: "Node id." },
18436
+ type: { type: "string", enum: ["path", "group", "text", "instance"], description: "path, group, text or instance (of a symbol)." },
18437
+ name: { type: "string", description: "Layer name." },
18438
+ visible: { type: "boolean", description: "false hides it (default true)." },
18439
+ locked: { type: "boolean", description: "true keeps it from being selected on the canvas." },
18440
+ transform: { type: "array", items: { type: "number" }, minItems: 6, maxItems: 6, description: "Affine matrix [a, b, c, d, e, f] (default identity)." }
18441
+ },
18442
+ required: ["id", "type"]
18443
+ }
18444
+ },
18445
+ symbols: { type: "array", items: { type: "object", properties: { id: { type: "string", description: "Symbol id." } }, required: ["id"] }, description: "Symbols the document's instances draw." },
18446
+ constraints: { type: "array", items: { type: "object" }, description: "Constraints between anchors, segments and circles, solved after every edit." },
18447
+ parameters: { type: "array", items: { type: "object" }, description: "Named values the constraints' expressions use." },
18448
+ perspective: { type: ["object", "null"], description: "The perspective grid, or null." }
18449
+ },
18450
+ required: ["width", "height", "nodes"]
18451
+ }
18452
+ },
18453
+ required: ["format", "kind", "formatVersion", "document"]
18454
+ };
18455
+ function toolList(provider) {
18456
+ const tools = typeof provider.tools === "function" ? provider.tools() : provider.tools;
18457
+ return {
18458
+ id: provider.id,
18459
+ title: provider.title,
18460
+ ...provider.skill ? { skill: provider.skill } : {},
18461
+ tools: tools.map((t) => ({ name: t.name, title: t.title, description: t.description, inputSchema: t.inputSchema, annotations: t.annotations }))
18462
+ };
18463
+ }
18464
+ function uiTables() {
18465
+ return {
18466
+ tools: { order: VECTOR_TOOLS, groups: VECTOR_TOOL_GROUPS, glyphs: VECTOR_TOOL_GLYPHS, shortcuts: VECTOR_TOOL_SHORTCUTS },
18467
+ menus: {
18468
+ blendModes: VECTOR_BLEND_MODE_MENU,
18469
+ effects: VECTOR_EFFECT_MENU,
18470
+ filters: VECTOR_FILTER_MENU,
18471
+ pathActions: VECTOR_PATH_ACTIONS,
18472
+ pathfinderActions: VECTOR_PATHFINDER_ACTIONS,
18473
+ editToggles: VECTOR_EDIT_TOGGLES,
18474
+ envelopeStyles: VECTOR_ENVELOPE_STYLE_OPTIONS,
18475
+ maskTypes: VECTOR_MASK_TYPE_OPTIONS,
18476
+ textAligns: VECTOR_TEXT_ALIGN_OPTIONS,
18477
+ fontWeights: VECTOR_FONT_WEIGHTS
18478
+ },
18479
+ specs: {
18480
+ effects: { defaults: VECTOR_EFFECT_DEFAULTS, params: VECTOR_EFFECT_PARAM_SPECS },
18481
+ filters: { defaults: VECTOR_FILTER_DEFAULTS, params: VECTOR_FILTER_PARAM_SPECS },
18482
+ lenses: VECTOR_LENS_SPECS,
18483
+ widthPresets: VECTOR_WIDTH_PRESETS
18484
+ },
18485
+ labels: {
18486
+ arrowheads: VECTOR_ARROWHEAD_LABELS,
18487
+ blendModes: VECTOR_BLEND_MODE_LABELS,
18488
+ blendSpacings: VECTOR_BLEND_SPACING_LABELS,
18489
+ connectorRoutes: VECTOR_CONNECTOR_ROUTE_LABELS,
18490
+ connectorSides: VECTOR_CONNECTOR_SIDE_LABELS,
18491
+ constraints: VECTOR_CONSTRAINT_LABELS,
18492
+ constraintGlyphs: VECTOR_CONSTRAINT_GLYPHS,
18493
+ cornerKinds: VECTOR_CORNER_KIND_LABELS,
18494
+ effects: VECTOR_EFFECT_LABELS,
18495
+ filters: VECTOR_FILTER_LABELS,
18496
+ gradientInterpolations: VECTOR_GRADIENT_INTERPOLATION_LABELS,
18497
+ gradientSpreads: VECTOR_GRADIENT_SPREAD_LABELS,
18498
+ gradientTypes: VECTOR_GRADIENT_TYPE_LABELS,
18499
+ horizontalResizing: VECTOR_HORIZONTAL_RESIZING_LABELS,
18500
+ verticalResizing: VECTOR_VERTICAL_RESIZING_LABELS,
18501
+ layerKinds: VECTOR_LAYER_KIND_LABELS,
18502
+ lenses: VECTOR_LENS_LABELS,
18503
+ maskTypes: VECTOR_MASK_TYPE_LABELS,
18504
+ pathfinder: VECTOR_PATHFINDER_LABELS,
18505
+ strokeAligns: VECTOR_STROKE_ALIGN_LABELS,
18506
+ strokeGradientModes: VECTOR_STROKE_GRADIENT_MODE_LABELS,
18507
+ stylize: VECTOR_STYLIZE_LABELS,
18508
+ symmetryModes: VECTOR_SYMMETRY_MODE_LABELS,
18509
+ textAligns: VECTOR_TEXT_ALIGN_LABELS,
18510
+ warpStyles: WARP_STYLE_LABELS
18511
+ },
18512
+ overlayTheme: VECTOR_OVERLAY_THEME
18513
+ };
18514
+ }
18515
+ var FAKE_VECTOR_ART_MODELS = [{ id: "fake-svg", name: "Fake SVG", media: "text", seed: true }];
18516
+ var fakeVectorArtGenerator = (request) => {
18517
+ const n2 = (request.prompt ?? "").length;
18518
+ const r = 10 + n2 % 30;
18519
+ const hue = ["#e11d48", "#2563eb", "#16a34a", "#d97706"][n2 % 4];
18520
+ return { svg: `<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><circle cx="50" cy="50" r="${r}" fill="${hue}"/></svg>` };
18521
+ };
18522
+ function vectorProviders(controller) {
18523
+ const commands = new CommandRegistry({ context: controller, history: controller.history });
18524
+ commands.register(createVectorCommands(controller));
18525
+ return {
18526
+ commands,
18527
+ providers: [
18528
+ createCommandToolProvider(commands, { id: "vector-commands", namespace: "" }),
18529
+ createVectorEffectsToolProvider(controller, { id: "vector-effects" }),
18530
+ createVectorGenerationToolProvider(controller, { models: FAKE_VECTOR_ART_MODELS, generate: fakeVectorArtGenerator })
18531
+ ]
18532
+ };
18533
+ }
18534
+ function vectorContracts(options) {
18535
+ const controller = new VectorEditorController();
18536
+ controller.setEffectsProvider(options.effects);
18537
+ const specs = createVectorCommands(controller);
18538
+ const providers = vectorProviders(controller).providers.map(toolList);
18539
+ const document = createVectorEditorDocument(controller);
18540
+ const files = {
18541
+ "document.schema.json": { $schema: "https://json-schema.org/draft/2020-12/schema", $id: "document.schema.json", ...VECTOR_DOCUMENT_JSON_SCHEMA },
18542
+ "tools.json": { providers },
18543
+ // The commands agents run with run_command: `shortcut` is as written (`Mod` is ⌘ / Ctrl).
18544
+ "commands.json": specs.map((s) => ({
18545
+ id: s.id,
18546
+ label: s.label,
18547
+ ...s.group ? { group: s.group } : {},
18548
+ ...s.keywords?.length ? { keywords: s.keywords } : {},
18549
+ ...s.description ? { description: s.description } : {},
18550
+ params: s.params ?? { type: "object", properties: {}, additionalProperties: false },
18551
+ ...s.shortcut !== void 0 ? { shortcut: s.shortcut } : {},
18552
+ ...s.scope ? { scope: s.scope } : {},
18553
+ undoable: s.undoable !== false,
18554
+ readOnly: !!s.readOnly,
18555
+ ...s.hidden ? { hidden: true } : {}
18556
+ })),
18557
+ "ui.json": uiTables()
18558
+ };
18559
+ files["manifest.json"] = {
18560
+ domain: "vector",
18561
+ formatVersion: VECTOR_CONTRACT_FORMAT_VERSION,
18562
+ document: { kind: document.kind, formatVersion: document.formatVersion },
18563
+ counts: { providers: providers.length, tools: providers.reduce((n2, p) => n2 + p.tools.length, 0), commands: specs.length },
18564
+ files: Object.keys(files).sort()
18565
+ };
18566
+ document.destroy?.();
18567
+ return files;
18568
+ }
18569
+ function createVectorConformanceHost(setup, options) {
18570
+ const shaper = getVectorTextShaper();
18571
+ setVectorTextShaper(createMetricTextShaper());
18572
+ let next = 0;
18573
+ const sized = setup.width || setup.height ? { document: { width: setup.width ?? 800, height: setup.height ?? 600, nodes: [] } } : {};
18574
+ const controller = new VectorEditorController({ ...sized, createId: () => `n${++next}` });
18575
+ controller.setEffectsProvider(options.effects);
18576
+ const registry = new ToolRegistry({ validateArguments: true });
18577
+ for (const p of vectorProviders(controller).providers) registry.register(p);
18578
+ const document = createVectorEditorDocument(controller);
18579
+ return {
18580
+ callTool: (name, args) => registry.callTool(name, args),
18581
+ document: () => toEditorDocumentFile(document),
18582
+ pixels: () => {
18583
+ throw new Error("The vector editor has no pixels; compare its document, results and SVG export.");
18584
+ },
18585
+ dispose: () => {
18586
+ document.destroy?.();
18587
+ setVectorTextShaper(shaper);
18588
+ }
18589
+ };
18590
+ }
18399
18591
  export {
18400
18592
  DEFAULT_VECTOR_BLEND_DISTANCE,
18401
18593
  DEFAULT_VECTOR_BLEND_STEPS,
18402
18594
  DEFAULT_VECTOR_FONT,
18403
18595
  DEFAULT_VECTOR_PATH_EDIT,
18404
18596
  DEFAULT_VECTOR_SNAP,
18597
+ FAKE_VECTOR_ART_MODELS,
18405
18598
  IDENTITY_MATRIX,
18406
18599
  KAPPA,
18407
18600
  LazyMouse,
@@ -18427,12 +18620,14 @@ export {
18427
18620
  VECTOR_CONSTRAINT_KINDS,
18428
18621
  VECTOR_CONSTRAINT_LABELS,
18429
18622
  VECTOR_CONSTRUCTION_ANGLES,
18623
+ VECTOR_CONTRACT_FORMAT_VERSION,
18430
18624
  VECTOR_CORNER_KINDS,
18431
18625
  VECTOR_CORNER_KIND_LABELS,
18432
18626
  VECTOR_CORNER_WIDGET_INSET,
18433
18627
  VECTOR_DIMENSIONAL_KINDS,
18434
18628
  VECTOR_DISTORT_BRUSH_MODES,
18435
18629
  VECTOR_DISTORT_TOLERANCE,
18630
+ VECTOR_DOCUMENT_JSON_SCHEMA,
18436
18631
  VECTOR_EDIT_TOGGLES,
18437
18632
  VECTOR_EFFECT_DEFAULTS,
18438
18633
  VECTOR_EFFECT_LABELS,
@@ -18567,6 +18762,7 @@ export {
18567
18762
  createMetricTextShaper,
18568
18763
  createOutlineTextShaper,
18569
18764
  createVectorCommands,
18765
+ createVectorConformanceHost,
18570
18766
  createVectorEditorDocument,
18571
18767
  createVectorEffect,
18572
18768
  createVectorEffectsToolProvider,
@@ -18603,6 +18799,7 @@ export {
18603
18799
  expandVectorGradientSpread,
18604
18800
  expandVectorGradientStops,
18605
18801
  explicitVectorGradient,
18802
+ fakeVectorArtGenerator,
18606
18803
  findVectorAnchorById,
18607
18804
  findVectorNode,
18608
18805
  fitCornerRadius,
@@ -18914,6 +19111,7 @@ export {
18914
19111
  vectorConstraintPanel,
18915
19112
  vectorConstraintResiduals,
18916
19113
  vectorConstraintValue,
19114
+ vectorContracts,
18917
19115
  vectorCornerAt,
18918
19116
  vectorCorners,
18919
19117
  vectorCornersAttribute,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor",
3
- "version": "0.265.0",
3
+ "version": "0.266.0",
4
4
  "description": "UI-agnostic rich text and media editing core library",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",