@deepraxis/cli 0.3.0-dev.bc829d1 → 0.3.0-dev.dc553d7

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 (3) hide show
  1. package/COMMANDS.md +11 -8
  2. package/dist/praxis.js +1306 -71
  3. package/package.json +1 -1
package/dist/praxis.js CHANGED
@@ -14312,6 +14312,16 @@ file at the root of that directory.`
14312
14312
  required: false,
14313
14313
  description: "可省略;账户使用 default 项目。"
14314
14314
  },
14315
+ {
14316
+ name: "visibility",
14317
+ type: "string",
14318
+ enum: [
14319
+ "private",
14320
+ "organization"
14321
+ ],
14322
+ required: false,
14323
+ description: "谁能看到这个新会话:默认 private 只有创建者;organization 允许同组织其他成员只读观看画面。"
14324
+ },
14315
14325
  {
14316
14326
  name: "keepAlive",
14317
14327
  type: "boolean",
@@ -14503,6 +14513,42 @@ file at the root of that directory.`
14503
14513
  }
14504
14514
  ]
14505
14515
  },
14516
+ {
14517
+ resource: "browser.sessions",
14518
+ method: "retrieveFrame",
14519
+ summary: "读取会话只读画面帧",
14520
+ description: "读取会话的一张只读画面帧(JPEG 字节)。创建者可读,同组织其他成员只在该会话声明为组织可见时可读;其余情况一律返回 404 SESSION_NOT_FOUND,不提示会话是否存在。响应体没有任何可控制浏览器的凭据,且不接受任何动作参数。",
14521
+ http: "GET",
14522
+ path: "/browser/v1/sessions/{sessionId}/frame",
14523
+ streaming: "no",
14524
+ pagination: false,
14525
+ pathParams: [
14526
+ {
14527
+ name: "sessionId",
14528
+ sdkName: "sessionId",
14529
+ description: "浏览器会话 ID;使用创建或列出会话返回的 id,以 bss_ 开头。"
14530
+ }
14531
+ ],
14532
+ query: []
14533
+ },
14534
+ {
14535
+ resource: "browser.sessions",
14536
+ method: "frames",
14537
+ summary: "订阅会话只读画面",
14538
+ description: "SSE:只推送只读画面帧,event 为 frame 或 end,data 为帧的 JSON 或 null;帧 data 是 JPEG 的 base64 编码,ts 是浏览器产生该帧的时刻(epoch 毫秒),约每秒最多 5 帧。评论 ping 每 15 秒一次,end 后关闭。这条通道与 /sessions/{sessionId}/stream 相互独立:它的消息只含画面,绝不含 wsUrl、signingKey、connectUrl、debuggerUrl、debuggerFullscreenUrl。创建者可订阅,同组织其他成员只在该会话声明为组织可见时可订阅;其余情况一律返回 404 SESSION_NOT_FOUND。",
14539
+ http: "GET",
14540
+ path: "/browser/v1/sessions/{sessionId}/frames",
14541
+ streaming: "always",
14542
+ pagination: false,
14543
+ pathParams: [
14544
+ {
14545
+ name: "sessionId",
14546
+ sdkName: "sessionId",
14547
+ description: "浏览器会话 ID;使用创建或列出会话返回的 id,以 bss_ 开头。"
14548
+ }
14549
+ ],
14550
+ query: []
14551
+ },
14506
14552
  {
14507
14553
  resource: "browser.sessions.handoff",
14508
14554
  method: "create",
@@ -14599,6 +14645,16 @@ file at the root of that directory.`
14599
14645
  type: "string",
14600
14646
  required: true,
14601
14647
  description: "当前观看者的稳定标识;同一观看者重复心跳应使用相同值,长度为 1–128 个 UTF-16 代码单元。"
14648
+ },
14649
+ {
14650
+ name: "kind",
14651
+ type: "string",
14652
+ enum: [
14653
+ "control",
14654
+ "readonly"
14655
+ ],
14656
+ required: false,
14657
+ description: "观看者类型:control 是需要控制浏览器的客户端,readonly 是只读观看者。只读观看者发送 control 也会按 readonly 记录。"
14602
14658
  }
14603
14659
  ]
14604
14660
  }
@@ -21832,7 +21888,7 @@ The default is return=minimal: success returns HTTP 201 with an empty body. Send
21832
21888
  resource: "media.libraries.assets",
21833
21889
  method: "list",
21834
21890
  summary: "List assets",
21835
- description: "Upload content into an active library and return a Cloudinary-compatible resource. Use file for a multipart file, data URI, public HTTPS URL or same-owner file identifier. Reusing public_id overwrites by default; overwrite=false returns the existing resource. Chunk uploads require both chunk headers.",
21891
+ description: "Upload content into an active library and return the stored asset. Use file for a multipart file, data URI, public HTTPS URL or same-owner file identifier. Reusing public_id overwrites by default; overwrite=false returns the existing asset. Chunk uploads require both chunk headers.",
21836
21892
  http: "GET",
21837
21893
  path: "/media/v1/libraries/{library_id}/assets",
21838
21894
  streaming: "no",
@@ -21851,17 +21907,6 @@ The default is return=minimal: success returns HTTP 201 with an empty body. Send
21851
21907
  required: false,
21852
21908
  description: "Filter by the exact organizational folder path; an empty value selects assets at the root. Descendant folders are not included."
21853
21909
  },
21854
- {
21855
- name: "resource_type",
21856
- type: "string",
21857
- enum: [
21858
- "image",
21859
- "video",
21860
- "raw"
21861
- ],
21862
- required: false,
21863
- description: "image, video (including audio), raw; auto is accepted by Upload actions only, and listing with auto returns 400."
21864
- },
21865
21910
  {
21866
21911
  name: "material_type",
21867
21912
  type: "string",
@@ -21876,10 +21921,11 @@ The default is return=minimal: success returns HTTP 201 with an empty body. Send
21876
21921
  "text_template",
21877
21922
  "animation_preset",
21878
21923
  "lut",
21879
- "transition_map"
21924
+ "transition_map",
21925
+ "file"
21880
21926
  ],
21881
21927
  required: false,
21882
- description: "Filter assets to one kind of material, independent of the stored resource_type. Omit to list every material type. Assets stored before this field existed match no material_type filter."
21928
+ description: "Filter assets to one kind of material. Audio is one material type; use audio_role to tell speech, music and sound effects apart. Omit to list every material type."
21883
21929
  },
21884
21930
  {
21885
21931
  name: "cursor",
@@ -21994,18 +22040,6 @@ The default is return=minimal: success returns HTTP 201 with an empty body. Send
21994
22040
  required: false,
21995
22041
  description: "Requires an image and visual understanding enabled in the library; otherwise returns UNSUPPORTED. Tagging is asynchronous."
21996
22042
  },
21997
- {
21998
- name: "resource_type",
21999
- type: "string",
22000
- enum: [
22001
- "image",
22002
- "video",
22003
- "raw",
22004
- "auto"
22005
- ],
22006
- required: false,
22007
- description: "Upload category: image for images, video for video or audio, raw for unprocessed files, or auto to detect the category. Defaults to auto."
22008
- },
22009
22043
  {
22010
22044
  name: "type",
22011
22045
  type: "string",
@@ -22117,18 +22151,6 @@ The default is return=minimal: success returns HTTP 201 with an empty body. Send
22117
22151
  required: false,
22118
22152
  description: "Minimum confidence for adding generated labels to tags, from 0 to 1 inclusive. Requires an image and enabled visual understanding; labels appear after processing completes."
22119
22153
  },
22120
- {
22121
- name: "resource_type",
22122
- type: "string",
22123
- enum: [
22124
- "image",
22125
- "video",
22126
- "raw",
22127
- "auto"
22128
- ],
22129
- required: false,
22130
- description: "Upload category: image for images, video for video or audio, raw for unprocessed files, or auto to detect the category. Defaults to auto."
22131
- },
22132
22154
  {
22133
22155
  name: "type",
22134
22156
  type: "string",
@@ -23052,10 +23074,11 @@ The default is return=minimal: success returns HTTP 201 with an empty body. Send
23052
23074
  "text_template",
23053
23075
  "animation_preset",
23054
23076
  "lut",
23055
- "transition_map"
23077
+ "transition_map",
23078
+ "file"
23056
23079
  ],
23057
23080
  required: false,
23058
- description: "What this asset is as a reusable material, as opposed to resource_type (its stored file category). Omitted on assets stored before this field existed and on raw assets that are not materials."
23081
+ description: "What this asset is as a reusable material. Always present: a file whose specific kind cannot be identified is file."
23059
23082
  }
23060
23083
  ]
23061
23084
  }
@@ -23121,7 +23144,7 @@ The default is return=minimal: success returns HTTP 201 with an empty body. Send
23121
23144
  type: "array",
23122
23145
  itemType: "string",
23123
23146
  enum: [
23124
- "resource_type",
23147
+ "material_type",
23125
23148
  "format",
23126
23149
  "asset_folder",
23127
23150
  "processing_state"
@@ -23194,10 +23217,11 @@ The default is return=minimal: success returns HTTP 201 with an empty body. Send
23194
23217
  "text_template",
23195
23218
  "animation_preset",
23196
23219
  "lut",
23197
- "transition_map"
23220
+ "transition_map",
23221
+ "file"
23198
23222
  ],
23199
23223
  required: false,
23200
- description: "What this asset is as a reusable material, as opposed to resource_type (its stored file category). Omitted on assets stored before this field existed and on raw assets that are not materials."
23224
+ description: "What this asset is as a reusable material. Always present: a file whose specific kind cannot be identified is file."
23201
23225
  }
23202
23226
  ]
23203
23227
  }
@@ -25093,7 +25117,8 @@ for more details.`
25093
25117
  "openai.images.generations",
25094
25118
  "openai.responses",
25095
25119
  "openai.videos",
25096
- "typesafe.systemone"
25120
+ "typesafe.systemone",
25121
+ "volcengine.voice_clone"
25097
25122
  ],
25098
25123
  required: false,
25099
25124
  description: "Match any comma-separated declared protocol ID; omitted or empty includes all models. Combined with type and output_modalities using AND. Invalid IDs return 400 with all legal values."
@@ -29193,6 +29218,12 @@ for more details.`
29193
29218
  required: true,
29194
29219
  description: "Name as the text will mention it; it must be unique inside this library after normalization, and it is what a unit claims when it links this entry."
29195
29220
  },
29221
+ {
29222
+ name: "group",
29223
+ type: "string",
29224
+ required: false,
29225
+ description: "Free-text group to file this entry under, such as a layer of the setting, a faction or a cast, so people and later sessions find related entries together; leave it out or send an empty string for no group. At most 60 characters."
29226
+ },
29196
29227
  {
29197
29228
  name: "aliases",
29198
29229
  type: "array",
@@ -29364,6 +29395,12 @@ for more details.`
29364
29395
  required: false,
29365
29396
  description: "New name for this entry, which also changes what the text has to mention for detection to find it."
29366
29397
  },
29398
+ {
29399
+ name: "group",
29400
+ type: "string",
29401
+ required: false,
29402
+ description: "New group, replacing the previous one when group is named in the update mask; an empty string removes the entry from its group. At most 60 characters."
29403
+ },
29367
29404
  {
29368
29405
  name: "aliases",
29369
29406
  type: "array",
@@ -32261,6 +32298,31 @@ for more details.`
32261
32298
  }
32262
32299
  ]
32263
32300
  },
32301
+ {
32302
+ resource: "ticket.repositories",
32303
+ method: "update",
32304
+ summary: "Update repositories",
32305
+ description: "Update repositories within the authenticated organization. Obtain resource identifiers from the corresponding list or create response. Writes complete synchronously; read the returned resource to observe the result. Service authorization applies to the verified human subject.",
32306
+ http: "PATCH",
32307
+ path: "/ticket/v1/repositories/{id}",
32308
+ streaming: "no",
32309
+ pagination: false,
32310
+ pathParams: [
32311
+ {
32312
+ name: "id",
32313
+ sdkName: "id",
32314
+ description: "Identifier returned by the matching create or list operation; number paths take repository-local numbers."
32315
+ }
32316
+ ],
32317
+ query: [
32318
+ {
32319
+ name: "repository",
32320
+ type: "string",
32321
+ required: false,
32322
+ description: "Repository id from GET /ticket/v1/repositories; omit for the default tickets container."
32323
+ }
32324
+ ]
32325
+ },
32264
32326
  {
32265
32327
  resource: "ticket.tickets",
32266
32328
  method: "list",
@@ -35680,6 +35742,15 @@ var browserViewerHeartbeat = (options) => (options.client ?? client).post({
35680
35742
  ...options.headers
35681
35743
  }
35682
35744
  });
35745
+ var browserGetSessionFrame = (options) => (options.client ?? client).get({
35746
+ security: [{
35747
+ key: "BrowserBearer",
35748
+ scheme: "bearer",
35749
+ type: "http"
35750
+ }],
35751
+ url: "/browser/v1/sessions/{sessionId}/frame",
35752
+ ...options
35753
+ });
35683
35754
  var browserListContexts = (options) => (options?.client ?? client).get({
35684
35755
  security: [{
35685
35756
  key: "BrowserBearer",
@@ -35768,6 +35839,15 @@ var browserStreamSession = (options) => (options.client ?? client).sse.get({
35768
35839
  url: "/browser/v1/sessions/{sessionId}/stream",
35769
35840
  ...options
35770
35841
  });
35842
+ var browserStreamSessionFrames = (options) => (options.client ?? client).sse.get({
35843
+ security: [{
35844
+ key: "BrowserBearer",
35845
+ scheme: "bearer",
35846
+ type: "http"
35847
+ }],
35848
+ url: "/browser/v1/sessions/{sessionId}/frames",
35849
+ ...options
35850
+ });
35771
35851
  var browserSeleniumUnsupported = (options) => (options?.client ?? client).get({
35772
35852
  security: [{
35773
35853
  key: "BrowserBearer",
@@ -44187,6 +44267,19 @@ var ticketGetRepositories = (options) => (options?.client ?? client).get({
44187
44267
  url: "/ticket/v1/repositories",
44188
44268
  ...options
44189
44269
  });
44270
+ var ticketPatchRepositoriesId = (options) => (options.client ?? client).patch({
44271
+ security: [{
44272
+ key: "BearerAuth",
44273
+ scheme: "bearer",
44274
+ type: "http"
44275
+ }, {
44276
+ key: "ApiKeyAuth",
44277
+ name: "X-API-Key",
44278
+ type: "apiKey"
44279
+ }],
44280
+ url: "/ticket/v1/repositories/{id}",
44281
+ ...options
44282
+ });
44190
44283
 
44191
44284
  // ../../packages/sdk/typescript/src/core/pagination.ts
44192
44285
  class Page {
@@ -44634,6 +44727,7 @@ function createBrowser(transport) {
44634
44727
  events: {
44635
44728
  list: bind(transport, browserListEvents)
44636
44729
  },
44730
+ frames: bindStream(transport, browserStreamSessionFrames),
44637
44731
  handoff: {
44638
44732
  complete: bind(transport, browserCompleteHandoff),
44639
44733
  create: bind(transport, browserRequestHandoff)
@@ -44641,6 +44735,7 @@ function createBrowser(transport) {
44641
44735
  list: bind(transport, browserListSessions),
44642
44736
  retrieve: bind(transport, browserGetSession),
44643
44737
  retrieveDebug: bind(transport, browserGetDebug),
44738
+ retrieveFrame: bind(transport, browserGetSessionFrame),
44644
44739
  stream: bindStream(transport, browserStreamSession),
44645
44740
  update: bind(transport, browserCloseSession),
44646
44741
  viewer: {
@@ -45480,7 +45575,8 @@ function createTicket(transport) {
45480
45575
  update: bind(transport, ticketPatchMilestonesNumber)
45481
45576
  },
45482
45577
  repositories: {
45483
- list: bind(transport, ticketGetRepositories)
45578
+ list: bind(transport, ticketGetRepositories),
45579
+ update: bind(transport, ticketPatchRepositoriesId)
45484
45580
  },
45485
45581
  tickets: {
45486
45582
  comments: {
@@ -48176,8 +48272,33 @@ Enter code: ${code.user_code}` });
48176
48272
  if (ports.json)
48177
48273
  ports.emit({ kind: "object", data: { env: config.env, ...shadowedBy ? { shadowed_by: shadowedBy } : {} } });
48178
48274
  }
48275
+ function jwtClaims(token) {
48276
+ const part = token.split(".")[1];
48277
+ if (!part)
48278
+ return null;
48279
+ try {
48280
+ const claims = JSON.parse(Buffer.from(part, "base64url").toString("utf8"));
48281
+ return claims && typeof claims === "object" ? claims : null;
48282
+ } catch {
48283
+ return null;
48284
+ }
48285
+ }
48179
48286
  async function whoami(auth, env, org) {
48180
48287
  const credential = await auth.get(org);
48288
+ if (credential.source === "machine-token" || credential.source === "managed-login") {
48289
+ const claims = jwtClaims(credential.token);
48290
+ const exp = typeof claims?.exp === "number" ? claims.exp * 1000 : credential.expiresAt;
48291
+ const str = (v) => typeof v === "string" && v ? v : null;
48292
+ return {
48293
+ subject: str(claims?.sub),
48294
+ organization: str(claims?.org) ?? credential.organizationId ?? null,
48295
+ env,
48296
+ source: credential.source,
48297
+ ...credential.storedIn ? { "stored in": credential.storedIn } : {},
48298
+ expires_at: exp ? new Date(exp).toISOString() : null,
48299
+ note: credential.source === "machine-token" ? "The machine token determines the organization." : "The managed login determines the organization; the platform renews it."
48300
+ };
48301
+ }
48181
48302
  const me = await auth.rpc("identity.me.get", {}, org);
48182
48303
  return {
48183
48304
  email: me.user.email,
@@ -48186,7 +48307,7 @@ async function whoami(auth, env, org) {
48186
48307
  source: credential.source,
48187
48308
  ...credential.storedIn ? { "stored in": credential.storedIn } : {},
48188
48309
  expires_at: credential.expiresAt ? new Date(credential.expiresAt).toISOString() : null,
48189
- ...credential.source === "api-key" ? { note: "The API key determines the organization." } : credential.source === "machine-token" ? { note: "The machine token determines the organization." } : credential.source === "managed-login" ? { note: "The managed login determines the organization; the platform renews it." } : {}
48310
+ ...credential.source === "api-key" ? { note: "The API key determines the organization." } : {}
48190
48311
  };
48191
48312
  }
48192
48313
 
@@ -49741,6 +49862,251 @@ function retop(store, id, top, rev) {
49741
49862
  retop(store, c, top, rev);
49742
49863
  }
49743
49864
  }
49865
+ // ../../packages/canvas/document/src/connector.ts
49866
+ var MAGNETS = ["auto", "center", "top", "right", "bottom", "left"];
49867
+ var ARROWS = ["end", "start", "both", "none"];
49868
+ var ROUTES = ["straight", "elbow"];
49869
+ var ARROW_LENGTH_FACTOR = 6;
49870
+ var ARROW_HALF_ANGLE_DEG = 25;
49871
+ var EPSILON = 0.000000001;
49872
+ function centerOf(box) {
49873
+ return { x: box.x + box.width / 2, y: box.y + box.height / 2 };
49874
+ }
49875
+ function inside(p, box) {
49876
+ return p.x > box.x && p.x < box.x + box.width && p.y > box.y && p.y < box.y + box.height;
49877
+ }
49878
+ function magnetPoint(box, magnet) {
49879
+ const c = centerOf(box);
49880
+ switch (magnet) {
49881
+ case "center":
49882
+ return c;
49883
+ case "top":
49884
+ return { x: c.x, y: box.y };
49885
+ case "bottom":
49886
+ return { x: c.x, y: box.y + box.height };
49887
+ case "left":
49888
+ return { x: box.x, y: c.y };
49889
+ case "right":
49890
+ return { x: box.x + box.width, y: c.y };
49891
+ }
49892
+ }
49893
+ function intersectBorder(box, shape, cornerRadius, toward) {
49894
+ const c = centerOf(box);
49895
+ const dx = toward.x - c.x;
49896
+ const dy = toward.y - c.y;
49897
+ if (dx === 0 && dy === 0)
49898
+ return c;
49899
+ const hw = box.width / 2;
49900
+ const hh = box.height / 2;
49901
+ if (hw <= 0 || hh <= 0)
49902
+ return c;
49903
+ if (shape === "ellipse") {
49904
+ const t2 = 1 / Math.hypot(dx / hw, dy / hh);
49905
+ return { x: c.x + dx * t2, y: c.y + dy * t2 };
49906
+ }
49907
+ const r = Math.max(0, Math.min(cornerRadius, Math.min(hw, hh)));
49908
+ const a = hw - r;
49909
+ const b = hh - r;
49910
+ let t = Infinity;
49911
+ if (dx !== 0) {
49912
+ const candidate = (a + r) / Math.abs(dx);
49913
+ if (Math.abs(dy) * candidate <= b + EPSILON)
49914
+ t = Math.min(t, candidate);
49915
+ }
49916
+ if (dy !== 0) {
49917
+ const candidate = (b + r) / Math.abs(dy);
49918
+ if (Math.abs(dx) * candidate <= a + EPSILON)
49919
+ t = Math.min(t, candidate);
49920
+ }
49921
+ if (!Number.isFinite(t)) {
49922
+ const ex = Math.sign(dx) * a;
49923
+ const ey = Math.sign(dy) * b;
49924
+ const qa = dx * dx + dy * dy;
49925
+ const qb = -2 * (dx * ex + dy * ey);
49926
+ const qc = ex * ex + ey * ey - r * r;
49927
+ const disc = Math.max(0, qb * qb - 4 * qa * qc);
49928
+ t = (-qb + Math.sqrt(disc)) / (2 * qa);
49929
+ }
49930
+ return { x: c.x + dx * t, y: c.y + dy * t };
49931
+ }
49932
+ function endPoint(end, magnet, toward) {
49933
+ if (magnet === "center")
49934
+ return centerOf(end.box);
49935
+ if (magnet === "auto")
49936
+ return intersectBorder(end.box, end.shape, end.cornerRadius, toward);
49937
+ return magnetPoint(end.box, magnet);
49938
+ }
49939
+ function arrowHead(tip, into, strokeWidth) {
49940
+ const length = strokeWidth * ARROW_LENGTH_FACTOR;
49941
+ const half = Math.tan(ARROW_HALF_ANGLE_DEG * Math.PI / 180) * length;
49942
+ const baseX = tip.x + into.x * length;
49943
+ const baseY = tip.y + into.y * length;
49944
+ const px = -into.y;
49945
+ const py = into.x;
49946
+ return {
49947
+ tip,
49948
+ left: { x: baseX + px * half, y: baseY + py * half },
49949
+ right: { x: baseX - px * half, y: baseY - py * half }
49950
+ };
49951
+ }
49952
+ function normalize(p) {
49953
+ const l = Math.hypot(p.x, p.y);
49954
+ return { x: p.x / l, y: p.y / l };
49955
+ }
49956
+ function rectsOverlap(a, b) {
49957
+ return a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
49958
+ }
49959
+ function segmentCrossesBox(a, b, box) {
49960
+ const shrink = 0.000001;
49961
+ const dx = b.x - a.x;
49962
+ const dy = b.y - a.y;
49963
+ let t0 = 0;
49964
+ let t1 = 1;
49965
+ const slab = (start, delta, min, max) => {
49966
+ if (Math.abs(delta) < 0.000000000001)
49967
+ return start > min && start < max;
49968
+ const ta = (min - start) / delta;
49969
+ const tb = (max - start) / delta;
49970
+ t0 = Math.max(t0, Math.min(ta, tb));
49971
+ t1 = Math.min(t1, Math.max(ta, tb));
49972
+ return t0 <= t1;
49973
+ };
49974
+ if (!slab(a.x, dx, box.x + shrink, box.x + box.width - shrink))
49975
+ return false;
49976
+ if (!slab(a.y, dy, box.y + shrink, box.y + box.height - shrink))
49977
+ return false;
49978
+ return t1 > t0;
49979
+ }
49980
+ function dashRanges(length, dash) {
49981
+ const pattern = (dash ?? []).filter((d) => typeof d === "number" && Number.isFinite(d) && d > 0);
49982
+ if (!pattern.length)
49983
+ return [[0, length]];
49984
+ const cycle = pattern.length % 2 ? [...pattern, ...pattern] : pattern;
49985
+ const out = [];
49986
+ let pos = 0;
49987
+ for (let i = 0;pos < length; i += 2) {
49988
+ const on = cycle[i % cycle.length];
49989
+ const off = cycle[(i + 1) % cycle.length];
49990
+ const end = Math.min(pos + on, length);
49991
+ if (end > pos)
49992
+ out.push([pos, end]);
49993
+ pos = end + off;
49994
+ }
49995
+ return out;
49996
+ }
49997
+ function n(value) {
49998
+ const rounded = Math.round(value * 100) / 100;
49999
+ return String(Object.is(rounded, -0) ? 0 : rounded);
50000
+ }
50001
+ var isHorizontal = (side) => side === "left" || side === "right";
50002
+ function elbowPath(from, to, fromMagnet, toMagnet) {
50003
+ if (fromMagnet === "center" || toMagnet === "center")
50004
+ throw new OpRejectedError({
50005
+ code: "INVALID_VALUE",
50006
+ property: fromMagnet === "center" ? "fromMagnet" : "toMagnet",
50007
+ reason: "elbow routing needs an edge, not the centre"
50008
+ });
50009
+ const dx = centerOf(to.box).x - centerOf(from.box).x;
50010
+ const dy = centerOf(to.box).y - centerOf(from.box).y;
50011
+ const across = Math.abs(dx) > Math.abs(dy);
50012
+ const fromSide = fromMagnet === "auto" ? across ? dx > 0 ? "right" : "left" : dy > 0 ? "bottom" : "top" : fromMagnet;
50013
+ const toSide = toMagnet === "auto" ? across ? dx > 0 ? "left" : "right" : dy > 0 ? "top" : "bottom" : toMagnet;
50014
+ const p1 = magnetPoint(from.box, fromSide);
50015
+ const p2 = magnetPoint(to.box, toSide);
50016
+ const out = [p1];
50017
+ if (isHorizontal(fromSide) === isHorizontal(toSide)) {
50018
+ if (isHorizontal(fromSide)) {
50019
+ const midX = (p1.x + p2.x) / 2;
50020
+ out.push({ x: midX, y: p1.y }, { x: midX, y: p2.y });
50021
+ } else {
50022
+ const midY = (p1.y + p2.y) / 2;
50023
+ out.push({ x: p1.x, y: midY }, { x: p2.x, y: midY });
50024
+ }
50025
+ } else {
50026
+ out.push(isHorizontal(fromSide) ? { x: p2.x, y: p1.y } : { x: p1.x, y: p2.y });
50027
+ }
50028
+ out.push(p2);
50029
+ const kept = [];
50030
+ for (const p of out) {
50031
+ const last = kept[kept.length - 1];
50032
+ if (last && last.x === p.x && last.y === p.y)
50033
+ continue;
50034
+ if (last && kept.length >= 2) {
50035
+ const before = kept[kept.length - 2];
50036
+ if (before.x === last.x && last.x === p.x || before.y === last.y && last.y === p.y)
50037
+ kept.pop();
50038
+ }
50039
+ kept.push(p);
50040
+ }
50041
+ return kept;
50042
+ }
50043
+ function cumulative(points) {
50044
+ const cum = [0];
50045
+ for (let i = 1;i < points.length; i++)
50046
+ cum.push(cum[i - 1] + Math.hypot(points[i].x - points[i - 1].x, points[i].y - points[i - 1].y));
50047
+ return cum;
50048
+ }
50049
+ function pointAt(points, cum, s) {
50050
+ const total = cum[cum.length - 1];
50051
+ const at = Math.max(0, Math.min(s, total));
50052
+ let i = 0;
50053
+ while (i < points.length - 2 && cum[i + 1] < at)
50054
+ i++;
50055
+ const span = cum[i + 1] - cum[i];
50056
+ const f = span < EPSILON ? 0 : (at - cum[i]) / span;
50057
+ const a = points[i];
50058
+ const b = points[i + 1];
50059
+ return { x: a.x + (b.x - a.x) * f, y: a.y + (b.y - a.y) * f };
50060
+ }
50061
+ function connectorGeometry(from, to, opts = {}) {
50062
+ const arrow = opts.arrow ?? "end";
50063
+ const strokeWidth = opts.strokeWidth ?? 1.5;
50064
+ const labelPos = opts.labelPos ?? 0.5;
50065
+ const fromMagnet = opts.fromMagnet ?? "auto";
50066
+ const toMagnet = opts.toMagnet ?? "auto";
50067
+ if (rectsOverlap(from.box, to.box))
50068
+ throw new OpRejectedError({ code: "INVALID_VALUE", property: "from", reason: "nodes overlap" });
50069
+ const points = (opts.route ?? "straight") === "elbow" ? elbowPath(from, to, fromMagnet, toMagnet) : [endPoint(from, fromMagnet, centerOf(to.box)), endPoint(to, toMagnet, centerOf(from.box))];
50070
+ const cum = cumulative(points);
50071
+ const length = cum[cum.length - 1];
50072
+ const p1 = points[0];
50073
+ const p2 = points[points.length - 1];
50074
+ if (length < EPSILON || inside(p1, to.box) || inside(p2, from.box))
50075
+ throw new OpRejectedError({ code: "INVALID_VALUE", property: "from", reason: "nodes overlap" });
50076
+ const dir1 = normalize({ x: points[1].x - p1.x, y: points[1].y - p1.y });
50077
+ const dir2 = normalize({ x: p2.x - points[points.length - 2].x, y: p2.y - points[points.length - 2].y });
50078
+ const back = { x: -dir2.x, y: -dir2.y };
50079
+ const arrowHeads = [];
50080
+ if (arrow === "end" || arrow === "both")
50081
+ arrowHeads.push(arrowHead(p2, back, strokeWidth));
50082
+ if (arrow === "start" || arrow === "both")
50083
+ arrowHeads.push(arrowHead(p1, dir1, strokeWidth));
50084
+ const xs = points.map((p) => p.x);
50085
+ const ys = points.map((p) => p.y);
50086
+ for (const head of arrowHeads) {
50087
+ xs.push(head.tip.x, head.left.x, head.right.x);
50088
+ ys.push(head.tip.y, head.left.y, head.right.y);
50089
+ }
50090
+ const bbox = { x: Math.min(...xs), y: Math.min(...ys), width: Math.max(...xs) - Math.min(...xs), height: Math.max(...ys) - Math.min(...ys) };
50091
+ const local = (p) => ({ x: p.x - bbox.x, y: p.y - bbox.y });
50092
+ const parts = [];
50093
+ for (const [start, end] of dashRanges(length, opts.dash)) {
50094
+ const run = [pointAt(points, cum, start)];
50095
+ for (let i = 1;i < points.length - 1; i++)
50096
+ if (cum[i] > start + EPSILON && cum[i] < end - EPSILON)
50097
+ run.push(points[i]);
50098
+ run.push(pointAt(points, cum, end));
50099
+ const traced = run.length > 2 ? [...run, ...run.slice(0, -1).reverse()] : run;
50100
+ parts.push(traced.map((p, i) => `${i ? "L" : "M"}${n(local(p).x)} ${n(local(p).y)}`).join(""));
50101
+ }
50102
+ for (const head of arrowHeads) {
50103
+ const t = local(head.tip);
50104
+ const l = local(head.left);
50105
+ const r = local(head.right);
50106
+ parts.push(`M${n(t.x)} ${n(t.y)}L${n(l.x)} ${n(l.y)}L${n(r.x)} ${n(r.y)}Z`);
50107
+ }
50108
+ return { points: [p1, p2], polyline: points, arrowHeads, bbox, labelCenter: pointAt(points, cum, labelPos * length), geometry: parts.join("") };
50109
+ }
49744
50110
  // ../../packages/canvas/document/src/expand.ts
49745
50111
  function defaultTheme(themes) {
49746
50112
  const t = {};
@@ -50018,8 +50384,514 @@ function checkLiveNode(node2) {
50018
50384
  return { warnings };
50019
50385
  }
50020
50386
 
50387
+ // ../../packages/canvas/document/src/kit.ts
50388
+ function kitStampOf(node2) {
50389
+ const meta = node2?.metadata;
50390
+ const stamp = meta?.kit;
50391
+ if (!stamp || typeof stamp.key !== "string" || typeof stamp.version !== "number" || typeof stamp.name !== "string")
50392
+ return;
50393
+ return { name: stamp.name, version: stamp.version, key: stamp.key };
50394
+ }
50395
+ function remapRefs(node2, refId) {
50396
+ const { children, ...rest } = node2;
50397
+ const out = { ...rest };
50398
+ if (typeof out.ref === "string")
50399
+ out.ref = refId.get(out.ref) ?? out.ref;
50400
+ const descendants = out.descendants;
50401
+ if (descendants && typeof descendants === "object" && !Array.isArray(descendants)) {
50402
+ const mapped = {};
50403
+ for (const [path, value] of Object.entries(descendants)) {
50404
+ const rewritten = path.split("/").map((seg) => refId.get(seg) ?? seg).join("/");
50405
+ mapped[rewritten] = value;
50406
+ }
50407
+ out.descendants = mapped;
50408
+ }
50409
+ if (Array.isArray(children))
50410
+ out.children = children.map((c) => remapRefs(c, refId));
50411
+ return out;
50412
+ }
50413
+ function planKit(existing, kit) {
50414
+ const canvasId = new Map;
50415
+ const haveVersion = new Map;
50416
+ for (const node2 of existing) {
50417
+ if (canvasId.has(node2.key))
50418
+ continue;
50419
+ canvasId.set(node2.key, node2.id);
50420
+ haveVersion.set(node2.key, node2.version);
50421
+ }
50422
+ const refId = new Map;
50423
+ const keys2 = new Set;
50424
+ for (const component of kit.components) {
50425
+ const stamp = kitStampOf(component);
50426
+ if (!stamp)
50427
+ throw new Error(`kit ${kit.name}: component ${component.id} carries no metadata.kit stamp`);
50428
+ if (keys2.has(stamp.key))
50429
+ throw new Error(`kit ${kit.name}: duplicate component key ${stamp.key}`);
50430
+ keys2.add(stamp.key);
50431
+ refId.set(component.id, canvasId.get(stamp.key) ?? component.id);
50432
+ }
50433
+ const plan = { add: [], update: [], unchanged: 0, variables: Object.keys(kit.variables).length };
50434
+ for (const component of kit.components) {
50435
+ const stamp = kitStampOf(component);
50436
+ const id = refId.get(component.id);
50437
+ const node2 = id === component.id ? remapRefs(component, refId) : { ...remapRefs(component, refId), id };
50438
+ const version = haveVersion.get(stamp.key);
50439
+ if (version === undefined)
50440
+ plan.add.push(node2);
50441
+ else if (version >= kit.version)
50442
+ plan.unchanged++;
50443
+ else
50444
+ plan.update.push({ id, node: node2 });
50445
+ }
50446
+ return plan;
50447
+ }
50448
+ function existingKitNodesIn(store, kitName) {
50449
+ const out = [];
50450
+ const walk = (id) => {
50451
+ const row = store.get(id);
50452
+ if (!row)
50453
+ return;
50454
+ const stamp = kitStampOf(row.props);
50455
+ if (stamp && (kitName === undefined || stamp.name === kitName))
50456
+ out.push({ key: stamp.key, version: stamp.version, id });
50457
+ for (const child of store.children(id))
50458
+ walk(child);
50459
+ };
50460
+ for (const top of store.children(null))
50461
+ walk(top);
50462
+ return out;
50463
+ }
50464
+ function kitFrameIn(store, frame) {
50465
+ return store.children(null).find((id) => {
50466
+ const props = store.get(id)?.props;
50467
+ return props?.type === "frame" && props.name === frame;
50468
+ });
50469
+ }
50470
+ var componentName = (node2) => {
50471
+ const name = node2.name;
50472
+ return typeof name === "string" && name !== "" ? name : kitStampOf(node2).key;
50473
+ };
50474
+ function kitPlanNames(plan) {
50475
+ return { added: plan.add.map(componentName), updated: plan.update.map((u) => componentName(u.node)) };
50476
+ }
50477
+ function planRefs(plan) {
50478
+ const ids = new Set;
50479
+ const refs = [];
50480
+ const visit2 = (node2, collectIds) => {
50481
+ if (collectIds)
50482
+ ids.add(node2.id);
50483
+ if (node2.type === "ref" && typeof node2.ref === "string")
50484
+ refs.push(node2.ref);
50485
+ for (const child of Array.isArray(node2.children) ? node2.children : [])
50486
+ visit2(child, collectIds);
50487
+ };
50488
+ for (const node2 of plan.add)
50489
+ visit2(node2, true);
50490
+ for (const entry of plan.update)
50491
+ visit2(entry.node, false);
50492
+ return { refs, ids };
50493
+ }
50494
+
50495
+ // ../../packages/canvas/document/src/kit-builders.ts
50496
+ var PRAXIS_UI_LITERALS = {
50497
+ "v3-surface-2": "#F1F3F2",
50498
+ "v3-border": "#E3E7E4",
50499
+ "v3-border-strong": "#CDD3CF",
50500
+ "v3-fg": "#0D1310",
50501
+ "v3-fg-2": "#4A5550",
50502
+ "v3-fg-3": "#6E7872",
50503
+ "v3-green-50": "#EEFBF3",
50504
+ "v3-green-700": "#167A43",
50505
+ "v3-code-bg": "#0F1512",
50506
+ "v3-code-fg": "#D6E2DB",
50507
+ "v3-danger": "#D92D20",
50508
+ "v3-danger-soft": "#FEF0EE",
50509
+ "v3-warning": "#C76A00",
50510
+ "v3-warning-soft": "#FFF6E5",
50511
+ "v3-info": "#2563EB",
50512
+ "v3-info-soft": "#EEF4FF",
50513
+ "v3-font": "Geist",
50514
+ "v3-mono": "Geist Mono",
50515
+ "r-md": 8
50516
+ };
50517
+ function token(ctx, name) {
50518
+ return ctx.variables.has(name) ? `$${name}` : PRAXIS_UI_LITERALS[name];
50519
+ }
50520
+ var KIT_LIMITS = {
50521
+ tableRows: 200,
50522
+ codeLines: 200,
50523
+ keyWidth: 240,
50524
+ minColumn: 24
50525
+ };
50526
+ var COLUMN_GAP = 12;
50527
+ var ROW_PADDING = 10;
50528
+ var BODY_SIZE = 13;
50529
+ var HEADER_SIZE = 12;
50530
+ function invalid(property, reason) {
50531
+ throw new OpRejectedError({ code: "INVALID_VALUE", property, reason });
50532
+ }
50533
+ function optionKeys(value, allowed, name) {
50534
+ if (value === undefined || value === null)
50535
+ return {};
50536
+ if (typeof value !== "object" || Array.isArray(value))
50537
+ return invalid(name, "expected an options object");
50538
+ for (const key of Object.keys(value))
50539
+ if (!allowed.includes(key))
50540
+ return invalid(key, `${name} does not take ${key}`);
50541
+ return value;
50542
+ }
50543
+ function requiredString(value, property) {
50544
+ if (typeof value !== "string" || value === "")
50545
+ return invalid(property, "expected a non-empty string");
50546
+ return value;
50547
+ }
50548
+ function optionalString(value, property) {
50549
+ if (value === undefined || value === null)
50550
+ return;
50551
+ return requiredString(value, property);
50552
+ }
50553
+ function containerWidth(value, property) {
50554
+ if (value === undefined || value === null || value === "fill_container")
50555
+ return "fill_container";
50556
+ if (typeof value === "number" && Number.isFinite(value) && value > 0)
50557
+ return value;
50558
+ return invalid(property, 'expected a positive number or "fill_container"');
50559
+ }
50560
+ var TABLE_KEYS = ["columns", "rows", "zebra", "width"];
50561
+ var COLUMN_KEYS = ["key", "title", "width", "align"];
50562
+ var requestOf = (width) => typeof width === "number" ? width : KIT_LIMITS.minColumn;
50563
+ function planColumns(columns, total, gap = COLUMN_GAP) {
50564
+ const fills = columns.filter((c) => typeof c.width !== "number").length;
50565
+ if (total === null)
50566
+ return columns.map((c) => typeof c.width === "number" ? c.width : "fill_container");
50567
+ const available = Math.max(0, total - gap * Math.max(0, columns.length - 1));
50568
+ const pinned = columns.reduce((sum, c) => sum + (typeof c.width === "number" ? c.width : 0), 0);
50569
+ const leftover = available - pinned;
50570
+ if (leftover > 0) {
50571
+ if (!fills)
50572
+ return columns.map((c) => c.width);
50573
+ const share = round2(leftover / fills);
50574
+ return columns.map((c) => typeof c.width === "number" ? c.width : share);
50575
+ }
50576
+ const requested = columns.reduce((sum, c) => sum + requestOf(c.width), 0);
50577
+ const scale = requested > 0 ? available / requested : 1;
50578
+ return columns.map((c) => Math.max(1, round2(requestOf(c.width) * scale)));
50579
+ }
50580
+ var round2 = (n2) => Math.round(n2 * 100) / 100;
50581
+ function cellRow(name, cells) {
50582
+ return { type: "frame", name, layout: "horizontal", gap: COLUMN_GAP, padding: [ROW_PADDING, 0], width: "fill_container", children: cells };
50583
+ }
50584
+ function planTable(options, ctx) {
50585
+ const o = optionKeys(options, TABLE_KEYS, "Kit.Table");
50586
+ if (!Array.isArray(o.columns) || o.columns.length === 0)
50587
+ invalid("columns", "expected a non-empty array of { key, title }");
50588
+ const rows = o.rows;
50589
+ if (!Array.isArray(rows))
50590
+ invalid("rows", "expected an array of row objects");
50591
+ if (rows.length > KIT_LIMITS.tableRows)
50592
+ invalid("rows", `${rows.length} rows; a table renders at most ${KIT_LIMITS.tableRows} — split it, or build the frame by hand`);
50593
+ const columns = o.columns.map((raw, i) => {
50594
+ const c = optionKeys(raw, COLUMN_KEYS, `columns[${i}]`);
50595
+ const width2 = c.width;
50596
+ if (width2 !== undefined && width2 !== null && width2 !== "fill" && !(typeof width2 === "number" && Number.isFinite(width2) && width2 > 0))
50597
+ invalid(`columns[${i}].width`, 'expected a positive number or "fill"');
50598
+ const align = c.align;
50599
+ if (align !== undefined && align !== null && align !== "left" && align !== "right")
50600
+ invalid(`columns[${i}].align`, 'expected "left" or "right"');
50601
+ return { key: requiredString(c.key, `columns[${i}].key`), title: requiredString(c.title, `columns[${i}].title`), width: width2, align };
50602
+ });
50603
+ const width = containerWidth(o.width, "width");
50604
+ const widths = planColumns(columns, typeof width === "number" ? width : null, COLUMN_GAP);
50605
+ const font = token(ctx, "v3-font");
50606
+ const headerCell = (title, w, align) => ({
50607
+ type: "text",
50608
+ name: title,
50609
+ content: title,
50610
+ width: w,
50611
+ textGrowth: "fixed-width",
50612
+ fontFamily: font,
50613
+ fontSize: HEADER_SIZE,
50614
+ fontWeight: 600,
50615
+ fill: token(ctx, "v3-fg-2"),
50616
+ ...align === "right" ? { textAlign: "right" } : {}
50617
+ });
50618
+ const dataCell = (title, content, w, align) => ({
50619
+ type: "text",
50620
+ name: title,
50621
+ content,
50622
+ width: w,
50623
+ textGrowth: "fixed-width",
50624
+ fontFamily: font,
50625
+ fontSize: BODY_SIZE,
50626
+ fill: token(ctx, "v3-fg"),
50627
+ ...align === "right" ? { textAlign: "right" } : {}
50628
+ });
50629
+ const children = [
50630
+ {
50631
+ type: "frame",
50632
+ name: "Header",
50633
+ layout: "vertical",
50634
+ gap: 0,
50635
+ width: "fill_container",
50636
+ stroke: token(ctx, "v3-border-strong"),
50637
+ strokeWidth: { bottom: 1 },
50638
+ strokeAlignment: "inner",
50639
+ children: [cellRow("HeaderRow", columns.map((c, i) => headerCell(c.title, widths[i], c.align)))]
50640
+ }
50641
+ ];
50642
+ rows.forEach((row, i) => {
50643
+ const record = row && typeof row === "object" && !Array.isArray(row) ? row : {};
50644
+ children.push({
50645
+ type: "frame",
50646
+ name: "Row",
50647
+ layout: "vertical",
50648
+ gap: 0,
50649
+ width: "fill_container",
50650
+ stroke: token(ctx, "v3-border"),
50651
+ strokeWidth: { bottom: 1 },
50652
+ strokeAlignment: "inner",
50653
+ ...o.zebra === true && i % 2 === 1 ? { fill: token(ctx, "v3-surface-2") } : {},
50654
+ children: [cellRow("RowCells", columns.map((c, j) => dataCell(c.key, textOf(record[c.key]), widths[j], c.align)))]
50655
+ });
50656
+ });
50657
+ return { type: "frame", name: "Table", layout: "vertical", gap: 0, width, children };
50658
+ }
50659
+ function textOf(value) {
50660
+ if (value === undefined || value === null)
50661
+ return "";
50662
+ return typeof value === "string" ? value : String(value);
50663
+ }
50664
+ function requiredText(value, property) {
50665
+ if (typeof value !== "string" && typeof value !== "number")
50666
+ return invalid(property, "expected a string or number");
50667
+ return String(value);
50668
+ }
50669
+ var CALLOUT_KEYS = ["tone", "title", "body"];
50670
+ var CALLOUT_TONES = {
50671
+ info: { soft: "v3-info-soft", ink: "v3-info" },
50672
+ success: { soft: "v3-green-50", ink: "v3-green-700" },
50673
+ warning: { soft: "v3-warning-soft", ink: "v3-warning" },
50674
+ danger: { soft: "v3-danger-soft", ink: "v3-danger" }
50675
+ };
50676
+ function planCallout(options, ctx) {
50677
+ const o = optionKeys(options, CALLOUT_KEYS, "Kit.Callout");
50678
+ const tone = o.tone;
50679
+ if (typeof tone !== "string" || !Object.hasOwn(CALLOUT_TONES, tone))
50680
+ invalid("tone", `expected one of ${Object.keys(CALLOUT_TONES).join(", ")}`);
50681
+ const body = requiredString(o.body, "body");
50682
+ const title = optionalString(o.title, "title");
50683
+ const pair = CALLOUT_TONES[tone];
50684
+ const font = token(ctx, "v3-font");
50685
+ const bodyChildren = [];
50686
+ if (title !== undefined)
50687
+ bodyChildren.push({ type: "text", name: "Title", content: title, fontFamily: font, fontSize: BODY_SIZE, fontWeight: 600, fill: token(ctx, pair.ink) });
50688
+ bodyChildren.push({
50689
+ type: "text",
50690
+ name: "Body",
50691
+ content: body,
50692
+ fontFamily: font,
50693
+ fontSize: BODY_SIZE,
50694
+ lineHeight: 1.5,
50695
+ width: "fill_container",
50696
+ textGrowth: "fixed-width",
50697
+ fill: token(ctx, "v3-fg")
50698
+ });
50699
+ return {
50700
+ type: "frame",
50701
+ name: "Callout",
50702
+ layout: "horizontal",
50703
+ gap: 0,
50704
+ width: "fill_container",
50705
+ fill: token(ctx, pair.soft),
50706
+ cornerRadius: token(ctx, "r-md"),
50707
+ clip: true,
50708
+ children: [
50709
+ { type: "rectangle", name: "Bar", width: 3, height: "fill_container", fill: token(ctx, pair.ink) },
50710
+ { type: "frame", name: "Content", layout: "vertical", gap: 6, padding: [12, 14], width: "fill_container", children: bodyChildren }
50711
+ ]
50712
+ };
50713
+ }
50714
+ var CODE_KEYS = ["lang", "text"];
50715
+ function planCode(options, ctx) {
50716
+ const o = optionKeys(options, CODE_KEYS, "Kit.Code");
50717
+ const lang = optionalString(o.lang, "lang");
50718
+ const text = requiredString(o.text, "text");
50719
+ const lines = text.split(`
50720
+ `);
50721
+ const shown = lines.length > KIT_LIMITS.codeLines ? [...lines.slice(0, KIT_LIMITS.codeLines), `… ${lines.length - KIT_LIMITS.codeLines} more lines`] : lines;
50722
+ const children = [];
50723
+ if (lang !== undefined)
50724
+ children.push({
50725
+ type: "text",
50726
+ name: "Lang",
50727
+ content: lang,
50728
+ width: "fill_container",
50729
+ textGrowth: "fixed-width",
50730
+ textAlign: "right",
50731
+ fontFamily: token(ctx, "v3-mono"),
50732
+ fontSize: 11,
50733
+ fill: token(ctx, "v3-fg-3")
50734
+ });
50735
+ children.push({
50736
+ type: "text",
50737
+ name: "Lines",
50738
+ content: shown.join(`
50739
+ `),
50740
+ fontFamily: token(ctx, "v3-mono"),
50741
+ fontSize: 12,
50742
+ lineHeight: 1.5,
50743
+ width: "fill_container",
50744
+ textGrowth: "fixed-width",
50745
+ fill: token(ctx, "v3-code-fg")
50746
+ });
50747
+ return {
50748
+ type: "frame",
50749
+ name: "Code",
50750
+ layout: "vertical",
50751
+ gap: 6,
50752
+ width: "fill_container",
50753
+ fill: token(ctx, "v3-code-bg"),
50754
+ cornerRadius: token(ctx, "r-md"),
50755
+ padding: 12,
50756
+ clip: true,
50757
+ children
50758
+ };
50759
+ }
50760
+ function indexed(index) {
50761
+ return /^\d+$/.test(index) ? index.padStart(2, "0") : index;
50762
+ }
50763
+ var SECTION_KEYS = ["index", "title", "subtitle"];
50764
+ function planSection(options, ctx) {
50765
+ const o = optionKeys(options, SECTION_KEYS, "Kit.Section");
50766
+ const title = requiredString(o.title, "title");
50767
+ const subtitle = optionalString(o.subtitle, "subtitle");
50768
+ const index = o.index === undefined || o.index === null ? undefined : textOf(o.index);
50769
+ if (index !== undefined && index === "")
50770
+ invalid("index", "expected a non-empty string or number");
50771
+ const font = token(ctx, "v3-font");
50772
+ const heading = {
50773
+ type: "frame",
50774
+ name: "Heading",
50775
+ layout: "horizontal",
50776
+ gap: 8,
50777
+ alignItems: "center",
50778
+ width: "fill_container",
50779
+ children: [
50780
+ ...index === undefined ? [] : [{ type: "text", name: "Index", content: indexed(index), fontFamily: font, fontSize: 14, fill: token(ctx, "v3-fg-3") }],
50781
+ { type: "text", name: "Title", content: title, fontFamily: font, fontSize: 20, fontWeight: 600, fill: token(ctx, "v3-fg"), width: "fill_container", textGrowth: "fixed-width" }
50782
+ ]
50783
+ };
50784
+ const children = [heading];
50785
+ if (subtitle !== undefined)
50786
+ children.push({ type: "text", name: "Subtitle", content: subtitle, fontFamily: font, fontSize: BODY_SIZE, fill: token(ctx, "v3-fg-2"), width: "fill_container", textGrowth: "fixed-width" });
50787
+ return { type: "frame", name: "Section", layout: "vertical", gap: 4, padding: [0, 0, 16, 0], width: "fill_container", children };
50788
+ }
50789
+ function planKeyValue(rows, ctx) {
50790
+ if (!Array.isArray(rows) || rows.length === 0)
50791
+ invalid("rows", "expected a non-empty array of { key, value }");
50792
+ const font = token(ctx, "v3-font");
50793
+ const parsed = rows.map((raw, i) => {
50794
+ const r = optionKeys(raw, ["key", "value"], `rows[${i}]`);
50795
+ return { key: requiredString(r.key, `rows[${i}].key`), value: requiredText(r.value, `rows[${i}].value`) };
50796
+ });
50797
+ const measured = Math.max(...parsed.map((r) => ctx.measure({ content: r.key, fontFamily: String(font), fontSize: BODY_SIZE }).width));
50798
+ const keyWidth = Math.min(KIT_LIMITS.keyWidth, Math.max(1, Math.ceil(measured)));
50799
+ return {
50800
+ type: "frame",
50801
+ name: "KeyValue",
50802
+ layout: "vertical",
50803
+ gap: 0,
50804
+ width: "fill_container",
50805
+ children: parsed.map((r) => ({
50806
+ type: "frame",
50807
+ name: "KeyValueRow",
50808
+ layout: "horizontal",
50809
+ gap: 12,
50810
+ padding: [6, 0],
50811
+ width: "fill_container",
50812
+ children: [
50813
+ { type: "text", name: "Key", content: r.key, fontFamily: font, fontSize: BODY_SIZE, fill: token(ctx, "v3-fg-3"), width: keyWidth, textGrowth: "fixed-width" },
50814
+ { type: "text", name: "Value", content: r.value, fontFamily: font, fontSize: BODY_SIZE, fill: token(ctx, "v3-fg"), width: "fill_container", textGrowth: "fixed-width" }
50815
+ ]
50816
+ }))
50817
+ };
50818
+ }
50819
+ var KIT_BUILDERS = {
50820
+ table: planTable,
50821
+ callout: planCallout,
50822
+ code: planCode,
50823
+ section: planSection,
50824
+ "key-value": planKeyValue
50825
+ };
50826
+ function planKitNode(kind, options, ctx) {
50827
+ const build = typeof kind === "string" && Object.hasOwn(KIT_BUILDERS, kind) ? KIT_BUILDERS[kind] : undefined;
50828
+ if (!build)
50829
+ return invalid("kind", `unknown builder ${JSON.stringify(kind)}; expected one of ${Object.keys(KIT_BUILDERS).join(", ")}`);
50830
+ return build(options, ctx);
50831
+ }
50832
+
50021
50833
  // ../../packages/canvas/document/src/execute-api.ts
50022
- var LIMITS = { ops: 5000, printBytes: 64 * 1024, screenshots: 4 };
50834
+ var MOVING_KEYS = ["x", "y", "width", "height", "layout", "layoutPosition", "padding", "gap", "justifyContent", "alignItems", "cornerRadius", "rotation"];
50835
+ var CONNECT_KEYS = new Set(["route", "fromMagnet", "toMagnet", "arrow", "label", "labelPos", "stroke", "strokeWidth", "dash", "behind", "parent", "name"]);
50836
+ function connectorMetaOf(props) {
50837
+ const meta = props?.metadata?.connector;
50838
+ if (!meta || typeof meta !== "object")
50839
+ return null;
50840
+ const m = meta;
50841
+ if (typeof m.from !== "string" || typeof m.to !== "string")
50842
+ return null;
50843
+ return {
50844
+ from: m.from,
50845
+ to: m.to,
50846
+ fromMagnet: m.fromMagnet ?? "auto",
50847
+ toMagnet: m.toMagnet ?? "auto",
50848
+ route: m.route ?? "straight",
50849
+ arrow: m.arrow ?? "end",
50850
+ labelPos: typeof m.labelPos === "number" ? m.labelPos : 0.5,
50851
+ ...Array.isArray(m.dash) ? { dash: m.dash } : {},
50852
+ ...typeof m.labelId === "string" ? { labelId: m.labelId } : {}
50853
+ };
50854
+ }
50855
+ var MEASURE_KEYS = new Set(["fontFamily", "fontSize", "fontWeight", "lineHeight", "letterSpacing", "width"]);
50856
+ function invalid2(property, reason) {
50857
+ throw new OpRejectedError({ code: "INVALID_VALUE", property, reason });
50858
+ }
50859
+ function pickOption(value, allowed, property, fallback) {
50860
+ if (value === undefined || value === null)
50861
+ return fallback;
50862
+ if (typeof value === "string" && allowed.includes(value))
50863
+ return value;
50864
+ return invalid2(property, `expected one of ${allowed.join(", ")}`);
50865
+ }
50866
+ function numberOption(value, property, fallback, positive = false) {
50867
+ if (value === undefined || value === null)
50868
+ return fallback;
50869
+ if (typeof value !== "number" || !Number.isFinite(value) || positive && value <= 0)
50870
+ return invalid2(property, positive ? "expected a positive number" : "expected a number");
50871
+ return value;
50872
+ }
50873
+ function optionKeys2(value, allowed, name) {
50874
+ if (value === undefined || value === null)
50875
+ return {};
50876
+ if (typeof value !== "object" || Array.isArray(value))
50877
+ return invalid2(name, "expected an options object");
50878
+ for (const key of Object.keys(value))
50879
+ if (!allowed.has(key))
50880
+ return invalid2(key, `${name} does not take ${key}`);
50881
+ return value;
50882
+ }
50883
+ function dashOption(value) {
50884
+ if (value === undefined || value === null)
50885
+ return;
50886
+ if (!Array.isArray(value) || !value.every((d) => typeof d === "number" && Number.isFinite(d) && d > 0))
50887
+ invalid2("dash", "expected an array of positive numbers");
50888
+ return value;
50889
+ }
50890
+ var LIMITS = { ops: 5000, printBytes: 64 * 1024, screenshots: 4, vectorize: 2 };
50891
+ var VECTORIZE_MODES = ["auto", "mono", "flat"];
50892
+ var VECTORIZE_KEYS = new Set(["mode", "maxColors", "allowComplex"]);
50893
+ var KIT_FRAME_GAP = 24;
50894
+ var KIT_FRAME_PADDING = 24;
50023
50895
  var ID_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
50024
50896
  function undeclared(node2, key) {
50025
50897
  return node2[key] === undefined || node2[key] === null;
@@ -50061,15 +50933,21 @@ class ExecuteApi {
50061
50933
  bounds;
50062
50934
  rev;
50063
50935
  random;
50936
+ measureText;
50937
+ kits;
50064
50938
  document = "document";
50065
50939
  layoutCache = new Map;
50066
50940
  defaults = {};
50067
- constructor(store, rec, bounds, rev, random = Math.random) {
50941
+ connectors = new Map;
50942
+ connectorsIndexed = false;
50943
+ constructor(store, rec, bounds, rev, random = Math.random, measureText, kits) {
50068
50944
  this.store = store;
50069
50945
  this.rec = rec;
50070
50946
  this.bounds = bounds;
50071
50947
  this.rev = rev;
50072
50948
  this.random = random;
50949
+ this.measureText = measureText;
50950
+ this.kits = kits;
50073
50951
  }
50074
50952
  setDefaults(value) {
50075
50953
  const raw = value;
@@ -50117,6 +50995,12 @@ class ExecuteApi {
50117
50995
  if (op.op === "setVariables")
50118
50996
  this.layoutCache.clear();
50119
50997
  }
50998
+ rowOf(path) {
50999
+ const row = this.store.get(path);
51000
+ if (!row)
51001
+ throw new OpRejectedError({ code: "NODE_NOT_FOUND", path });
51002
+ return row;
51003
+ }
50120
51004
  parentId(parent) {
50121
51005
  if (parent === "document" || parent === "" || parent == null)
50122
51006
  return null;
@@ -50216,7 +51100,7 @@ class ExecuteApi {
50216
51100
  return;
50217
51101
  if (this.rec.warnings.length >= 20 || this.rec.warnings.some((w) => w.code === "PATH_BOX_MISMATCH" && w.nodeId === nodeId))
50218
51102
  return;
50219
- const round = (n) => Number(n.toFixed(2));
51103
+ const round = (n2) => Number(n2.toFixed(2));
50220
51104
  this.rec.warnings.push({
50221
51105
  code: "PATH_BOX_MISMATCH",
50222
51106
  nodeId,
@@ -50233,9 +51117,9 @@ class ExecuteApi {
50233
51117
  const byName = new Map;
50234
51118
  const walk = (id) => {
50235
51119
  for (const c of this.store.children(id)) {
50236
- const n = this.store.get(c).props;
50237
- if (n.name)
50238
- byName.set(n.name, [...byName.get(n.name) ?? [], c]);
51120
+ const n2 = this.store.get(c).props;
51121
+ if (n2.name)
51122
+ byName.set(n2.name, [...byName.get(n2.name) ?? [], c]);
50239
51123
  walk(c);
50240
51124
  }
50241
51125
  };
@@ -50278,11 +51162,11 @@ class ExecuteApi {
50278
51162
  } else {
50279
51163
  const tree = subtree(this.store, src.id);
50280
51164
  const descMap = descendants ? this.resolveDescendantKeys(src.id, descendants) : {};
50281
- const apply = (n) => {
50282
- const d = descMap[n.id];
50283
- let out = d && typeof d.type === "string" ? { ...d } : { ...n, ...d ?? {} };
50284
- if (Array.isArray(n.children) && !(d && typeof d.type === "string"))
50285
- out = { ...out, children: n.children.map(apply) };
51165
+ const apply = (n2) => {
51166
+ const d = descMap[n2.id];
51167
+ let out = d && typeof d.type === "string" ? { ...d } : { ...n2, ...d ?? {} };
51168
+ if (Array.isArray(n2.children) && !(d && typeof d.type === "string"))
51169
+ out = { ...out, children: n2.children.map(apply) };
50286
51170
  return out;
50287
51171
  };
50288
51172
  node2 = this.withIds({ ...apply(tree), ...over });
@@ -50317,6 +51201,8 @@ class ExecuteApi {
50317
51201
  patch.descendants = { ...row.props.descendants ?? {}, ...this.resolveDescendantKeys(row.props.ref, patch.descendants) };
50318
51202
  this.warnProps({ ...patch, ...row.props.type === "ref" ? { ref: row.props.ref } : {} }, row.props.type, row.id);
50319
51203
  this.commit({ op: "update", id: row.id, patch });
51204
+ if (MOVING_KEYS.some((k) => (k in patch)) || patch.descendants && this.store.get(row.id))
51205
+ this.finalizeConnectors();
50320
51206
  }
50321
51207
  Replace(path, nodeData) {
50322
51208
  const inst = this.splitInstancePath(path);
@@ -50354,6 +51240,7 @@ class ExecuteApi {
50354
51240
  const before = i > 0 ? this.store.get(siblings[i - 1]).ord : null;
50355
51241
  const after = i < siblings.length ? this.store.get(siblings[i]).ord : null;
50356
51242
  this.commit({ op: "move", id: row.id, parent: p, ord: between(before, after) });
51243
+ this.finalizeConnectors();
50357
51244
  }
50358
51245
  Delete(path) {
50359
51246
  if (path === "document")
@@ -50363,6 +51250,14 @@ class ExecuteApi {
50363
51250
  if (!this.store.get(path))
50364
51251
  throw new OpRejectedError({ code: "NODE_NOT_FOUND", path });
50365
51252
  this.commit({ op: "delete", id: path });
51253
+ this.finalizeConnectors();
51254
+ }
51255
+ MoveToBack(path) {
51256
+ this.Move(path, undefined, 0);
51257
+ }
51258
+ MoveToFront(path) {
51259
+ const row = this.rowOf(path);
51260
+ this.Move(path, undefined, this.store.children(row.parent).length);
50366
51261
  }
50367
51262
  SetVariables(variables, replace = false) {
50368
51263
  const themes = {};
@@ -50483,9 +51378,9 @@ class ExecuteApi {
50483
51378
  if (!tree)
50484
51379
  return null;
50485
51380
  const index = new Map;
50486
- const walk = (n) => {
50487
- index.set(n.path, n);
50488
- n.children.forEach(walk);
51381
+ const walk = (n2) => {
51382
+ index.set(n2.path, n2);
51383
+ n2.children.forEach(walk);
50489
51384
  };
50490
51385
  walk(tree);
50491
51386
  hit = { rev: this.mutations, index };
@@ -50594,6 +51489,254 @@ class ExecuteApi {
50594
51489
  problems: p ? p.code === "FULLY_CLIPPED" ? "fully clipped" : "partially clipped" : undefined
50595
51490
  };
50596
51491
  }
51492
+ MeasureText(content, options) {
51493
+ if (typeof content !== "string")
51494
+ invalid2("content", "expected a string");
51495
+ if (!this.measureText)
51496
+ invalid2("MeasureText", "this host has no font set, so text cannot be measured");
51497
+ const o = optionKeys2(options, MEASURE_KEYS, "MeasureText");
51498
+ if (typeof o.fontFamily !== "string" || o.fontFamily === "")
51499
+ invalid2("fontFamily", "expected a font family name");
51500
+ if (o.fontSize === undefined || o.fontSize === null)
51501
+ invalid2("fontSize", "expected a positive number");
51502
+ return this.measureText({
51503
+ content,
51504
+ fontFamily: o.fontFamily,
51505
+ fontSize: numberOption(o.fontSize, "fontSize", 14, true),
51506
+ fontWeight: o.fontWeight,
51507
+ lineHeight: o.lineHeight === undefined || o.lineHeight === null ? undefined : numberOption(o.lineHeight, "lineHeight", 0, true),
51508
+ letterSpacing: o.letterSpacing === undefined || o.letterSpacing === null ? undefined : numberOption(o.letterSpacing, "letterSpacing", 0),
51509
+ width: o.width === undefined || o.width === null ? undefined : numberOption(o.width, "width", 0, true)
51510
+ });
51511
+ }
51512
+ absoluteBounds(path) {
51513
+ return this.absoluteOf(path) ?? { x: 0, y: 0, width: 0, height: 0 };
51514
+ }
51515
+ Connect(from, to, options) {
51516
+ if (typeof from !== "string" || typeof to !== "string")
51517
+ invalid2("from", "expected a node id");
51518
+ if (from === to)
51519
+ invalid2("to", "a node cannot be connected to itself");
51520
+ this.rowOf(from);
51521
+ this.rowOf(to);
51522
+ const o = optionKeys2(options, CONNECT_KEYS, "Connect");
51523
+ const route = pickOption(o.route, ROUTES, "route", "straight");
51524
+ const fromMagnet = pickOption(o.fromMagnet, MAGNETS, "fromMagnet", "auto");
51525
+ const toMagnet = pickOption(o.toMagnet, MAGNETS, "toMagnet", "auto");
51526
+ const arrow = pickOption(o.arrow, ARROWS, "arrow", "end");
51527
+ const labelPos = numberOption(o.labelPos, "labelPos", 0.5);
51528
+ if (labelPos < 0 || labelPos > 1)
51529
+ invalid2("labelPos", "expected a number between 0 and 1");
51530
+ const strokeWidth = numberOption(o.strokeWidth, "strokeWidth", 1.5, true);
51531
+ const stroke = o.stroke === undefined || o.stroke === null ? "#64748B" : o.stroke;
51532
+ if (typeof stroke !== "string")
51533
+ invalid2("stroke", "expected a colour string");
51534
+ const dash = dashOption(o.dash);
51535
+ const behind = o.behind === undefined || o.behind === null ? true : o.behind;
51536
+ if (typeof behind !== "boolean")
51537
+ invalid2("behind", "expected a boolean");
51538
+ const name = o.name === undefined || o.name === null ? "Connector" : o.name;
51539
+ if (typeof name !== "string")
51540
+ invalid2("name", "expected a string");
51541
+ if (o.label !== undefined && o.label !== null && typeof o.label !== "string")
51542
+ invalid2("label", "expected a string");
51543
+ const ends = { from: this.connectorEnd(from, "from"), to: this.connectorEnd(to, "to") };
51544
+ const geom = connectorGeometry(ends.from, ends.to, { route, fromMagnet, toMagnet, arrow, strokeWidth, labelPos, dash });
51545
+ const parent = o.parent === undefined || o.parent === null ? this.commonParent(from, to) : this.parentId(String(o.parent));
51546
+ const target = parent ?? "document";
51547
+ const origin = this.originOf(parent);
51548
+ const absolute = this.inFlow(parent);
51549
+ const place = (box) => ({ x: box.x - origin.x, y: box.y - origin.y, width: box.width, height: box.height, ...absolute ? { layoutPosition: "absolute" } : {} });
51550
+ let labelId;
51551
+ if (typeof o.label === "string" && o.label !== "") {
51552
+ const size = this.MeasureText(o.label, { fontFamily: "Inter", fontSize: 12 });
51553
+ const width = size.width + 8;
51554
+ const height = size.height + 4;
51555
+ labelId = this.Insert(target, {
51556
+ id: "",
51557
+ type: "frame",
51558
+ name: `${name}-label`,
51559
+ ...place({ x: geom.labelCenter.x - width / 2, y: geom.labelCenter.y - height / 2, width, height }),
51560
+ fill: "#FFFFFF",
51561
+ padding: [2, 4],
51562
+ layout: "none",
51563
+ children: [{ id: "", type: "text", x: 4, y: 2, content: o.label, fontFamily: "Inter", fontSize: 12, fill: "#334155" }]
51564
+ });
51565
+ }
51566
+ const id = this.Insert(target, {
51567
+ id: "",
51568
+ type: "path",
51569
+ name,
51570
+ ...place(geom.bbox),
51571
+ viewBox: [0, 0, geom.bbox.width, geom.bbox.height],
51572
+ geometry: geom.geometry,
51573
+ fill: stroke,
51574
+ stroke,
51575
+ strokeWidth,
51576
+ metadata: { connector: { from, to, fromMagnet, toMagnet, route, arrow, labelPos, ...dash ? { dash } : {}, ...labelId ? { labelId } : {} } }
51577
+ });
51578
+ this.connectors.set(id, { from, to, fromMagnet, toMagnet, route, arrow, labelPos, ...dash ? { dash } : {}, ...labelId ? { labelId } : {} });
51579
+ if (behind)
51580
+ this.Move(id, target, 0);
51581
+ this.warnConnector(id, geom);
51582
+ return id;
51583
+ }
51584
+ finalizeConnectors() {
51585
+ if (!this.mutations)
51586
+ return;
51587
+ for (const id of this.knownConnectors())
51588
+ this.redrawConnector(id);
51589
+ }
51590
+ knownConnectors() {
51591
+ if (!this.connectorsIndexed) {
51592
+ this.connectorsIndexed = true;
51593
+ const walk = (parent) => {
51594
+ for (const id of this.store.children(parent)) {
51595
+ const props = this.store.get(id)?.props;
51596
+ if (!props)
51597
+ continue;
51598
+ const meta = connectorMetaOf(props);
51599
+ if (meta && !this.connectors.has(id))
51600
+ this.connectors.set(id, meta);
51601
+ walk(id);
51602
+ }
51603
+ };
51604
+ walk(null);
51605
+ }
51606
+ return [...this.connectors.keys()];
51607
+ }
51608
+ redrawConnector(id) {
51609
+ const row = this.store.get(id);
51610
+ const meta = row ? connectorMetaOf(row.props) : null;
51611
+ if (!row || !meta) {
51612
+ this.connectors.delete(id);
51613
+ return;
51614
+ }
51615
+ const from = this.absoluteOf(meta.from);
51616
+ const to = this.absoluteOf(meta.to);
51617
+ if (!from || !to || from.width === 0 && from.height === 0 || to.width === 0 && to.height === 0) {
51618
+ this.warnOnce("CONNECTOR_ENDPOINT_GONE", id, `connector ${String(row.props.name ?? id)}: ${meta.from} or ${meta.to} is gone or has no laid-out box; the line was left where it was`);
51619
+ return;
51620
+ }
51621
+ const end = (box2, path) => {
51622
+ const props = this.store.get(path).props;
51623
+ return { box: box2, shape: String(props.type), cornerRadius: typeof props.cornerRadius === "number" ? props.cornerRadius : 0 };
51624
+ };
51625
+ const geom = connectorGeometry(end(from, meta.from), end(to, meta.to), {
51626
+ route: meta.route,
51627
+ fromMagnet: meta.fromMagnet,
51628
+ toMagnet: meta.toMagnet,
51629
+ arrow: meta.arrow,
51630
+ labelPos: meta.labelPos,
51631
+ dash: meta.dash,
51632
+ strokeWidth: typeof row.props.strokeWidth === "number" ? row.props.strokeWidth : 1.5
51633
+ });
51634
+ const origin = this.originOf(row.parent);
51635
+ const box = { x: geom.bbox.x - origin.x, y: geom.bbox.y - origin.y, width: geom.bbox.width, height: geom.bbox.height };
51636
+ const viewBox = [0, 0, geom.bbox.width, geom.bbox.height];
51637
+ const patch = {};
51638
+ for (const [key, value] of Object.entries({ ...box, viewBox, geometry: geom.geometry }))
51639
+ if (JSON.stringify(row.props[key]) !== JSON.stringify(value))
51640
+ patch[key] = value;
51641
+ if (Object.keys(patch).length)
51642
+ this.commit({ op: "update", id, patch });
51643
+ if (meta.labelId) {
51644
+ const label = this.store.get(meta.labelId);
51645
+ const labelBox = this.absoluteOf(meta.labelId);
51646
+ if (label && labelBox) {
51647
+ const x = geom.labelCenter.x - labelBox.width / 2 - origin.x;
51648
+ const y = geom.labelCenter.y - labelBox.height / 2 - origin.y;
51649
+ const labelPatch = {};
51650
+ if (label.props.x !== x)
51651
+ labelPatch.x = x;
51652
+ if (label.props.y !== y)
51653
+ labelPatch.y = y;
51654
+ if (Object.keys(labelPatch).length)
51655
+ this.commit({ op: "update", id: meta.labelId, patch: labelPatch });
51656
+ }
51657
+ }
51658
+ this.warnConnector(id, geom);
51659
+ }
51660
+ warnOnce(code, nodeId, message) {
51661
+ if (this.rec.warnings.length >= 20)
51662
+ return;
51663
+ if (this.rec.warnings.some((w) => w.code === code && w.nodeId === nodeId))
51664
+ return;
51665
+ this.rec.warnings.push({ code, nodeId, message });
51666
+ }
51667
+ warnConnector(id, geom) {
51668
+ const row = this.store.get(id);
51669
+ if (!row)
51670
+ return;
51671
+ const meta = connectorMetaOf(row.props);
51672
+ const labelIds = new Set;
51673
+ for (const m of this.connectors.values())
51674
+ if (m.labelId)
51675
+ labelIds.add(m.labelId);
51676
+ let labelBox = null;
51677
+ for (const sibling of this.store.children(row.parent)) {
51678
+ const props = this.store.get(sibling)?.props;
51679
+ if (!props || sibling === id)
51680
+ continue;
51681
+ const box = this.absoluteOf(sibling);
51682
+ if (!box || box.width === 0 && box.height === 0)
51683
+ continue;
51684
+ if (sibling === meta?.labelId) {
51685
+ labelBox = box;
51686
+ continue;
51687
+ }
51688
+ if (!labelIds.has(sibling) && !this.connectors.has(sibling) && sibling !== meta?.from && sibling !== meta?.to) {
51689
+ for (let i = 1;i < geom.polyline.length; i++)
51690
+ if (segmentCrossesBox(geom.polyline[i - 1], geom.polyline[i], box)) {
51691
+ this.warnOnce("CONNECTOR_CROSSES_NODE", id, `line crosses ${String(props.name ?? sibling)}`);
51692
+ break;
51693
+ }
51694
+ }
51695
+ if (labelBox && rectsOverlap(labelBox, box))
51696
+ this.warnOnce("LABEL_OVERLAP", id, `label overlaps ${String(props.name ?? sibling)}`);
51697
+ }
51698
+ }
51699
+ absoluteOf(path) {
51700
+ if (path === null || path === "")
51701
+ return { x: 0, y: 0, width: 0, height: 0 };
51702
+ const row = this.store.get(path.split("/")[0]);
51703
+ if (!row)
51704
+ return null;
51705
+ const b = this.layoutOf(row.top).boxes.get(path);
51706
+ return b ? { x: b.wx, y: b.wy, width: b.width, height: b.height } : null;
51707
+ }
51708
+ originOf(parent) {
51709
+ if (parent === null)
51710
+ return { x: 0, y: 0 };
51711
+ const box = this.absoluteOf(parent);
51712
+ if (!box)
51713
+ invalid2("parent", `${parent} has no laid-out box`);
51714
+ return { x: box.x, y: box.y };
51715
+ }
51716
+ connectorEnd(id, property) {
51717
+ const row = this.rowOf(id);
51718
+ const box = this.absoluteOf(id);
51719
+ if (!box || box.width === 0 && box.height === 0)
51720
+ invalid2(property, `${id} has no laid-out box to attach to`);
51721
+ return { box, shape: String(row.props.type), cornerRadius: typeof row.props.cornerRadius === "number" ? row.props.cornerRadius : 0 };
51722
+ }
51723
+ commonParent(a, b) {
51724
+ this.rowOf(a);
51725
+ this.rowOf(b);
51726
+ const ancestors = new Set;
51727
+ for (let cur = this.store.get(a).parent;cur !== null; cur = this.store.get(cur)?.parent ?? null)
51728
+ ancestors.add(cur);
51729
+ for (let cur = this.store.get(b).parent;cur !== null; cur = this.store.get(cur)?.parent ?? null)
51730
+ if (ancestors.has(cur))
51731
+ return cur;
51732
+ return null;
51733
+ }
51734
+ inFlow(parent) {
51735
+ if (parent === null)
51736
+ return false;
51737
+ const props = this.store.get(parent)?.props;
51738
+ return props?.type === "frame" && props.layout !== "none";
51739
+ }
50597
51740
  FindEmptySpace(input) {
50598
51741
  const dir = input.direction ?? "right";
50599
51742
  const pad = input.padding ?? 0;
@@ -50621,6 +51764,69 @@ class ExecuteApi {
50621
51764
  return { x: minX, y: maxY + pad };
50622
51765
  return { x: minX, y: minY - pad - input.height };
50623
51766
  }
51767
+ KitPlan(kind, options) {
51768
+ const variables = this.store.variables();
51769
+ return planKitNode(kind, options, {
51770
+ variables: new Set(Object.keys(variables)),
51771
+ measure: (request) => {
51772
+ const family = typeof request.fontFamily === "string" && request.fontFamily.startsWith("$") ? variables[request.fontFamily.slice(1)]?.value : request.fontFamily;
51773
+ const { content, ...options2 } = { ...request, fontFamily: typeof family === "string" && family !== "" ? family : "Geist" };
51774
+ return this.MeasureText(content, options2);
51775
+ }
51776
+ });
51777
+ }
51778
+ ListKits() {
51779
+ return this.kits?.list() ?? [];
51780
+ }
51781
+ UseKit(name) {
51782
+ if (typeof name !== "string" || name === "")
51783
+ invalid2("name", "expected a kit name");
51784
+ const entry = this.kits?.get(name);
51785
+ if (!entry)
51786
+ invalid2("name", `unknown kit ${JSON.stringify(name)}; available: ${this.kits?.names().join(", ") || "none"}`);
51787
+ const plan = planKit(existingKitNodesIn(this.store, entry.kit.name), entry.kit);
51788
+ const { refs, ids } = planRefs(plan);
51789
+ for (const ref of refs)
51790
+ if (!ids.has(ref) && !this.store.get(ref))
51791
+ throw new OpRejectedError({ code: "UNKNOWN_REF", ref });
51792
+ this.SetVariables(entry.kit.variables, false);
51793
+ const frame = kitFrameIn(this.store, entry.frame) ?? this.createKitFrame(entry.frame);
51794
+ for (const node2 of plan.add)
51795
+ this.insertKitComponent(frame, null, node2);
51796
+ for (const { id, node: node2 } of plan.update) {
51797
+ const row = this.rowOf(id);
51798
+ this.commit({ op: "delete", id });
51799
+ this.insertKitComponent(row.parent, row.ord, node2);
51800
+ }
51801
+ const names = kitPlanNames(plan);
51802
+ return { version: entry.kit.version, added: names.added, updated: names.updated, unchanged: plan.unchanged, variables: plan.variables };
51803
+ }
51804
+ createKitFrame(name) {
51805
+ const at = this.FindEmptySpace({ width: 0, height: 0, direction: "right", padding: KIT_FRAME_GAP });
51806
+ return this.Insert("document", {
51807
+ id: "",
51808
+ type: "frame",
51809
+ name,
51810
+ x: at.x,
51811
+ y: at.y,
51812
+ layout: "vertical",
51813
+ gap: KIT_FRAME_GAP,
51814
+ padding: KIT_FRAME_PADDING
51815
+ });
51816
+ }
51817
+ insertKitComponent(parent, ord, node2) {
51818
+ const tree = applyTextDefaults(migrateLegacyProps(node2), this.defaults.text);
51819
+ const seen = new Set;
51820
+ const check = (n2) => {
51821
+ if (seen.has(n2.id) || this.store.get(n2.id))
51822
+ throw new OpRejectedError({ code: "INVALID_VALUE", property: "id", reason: `kit component id ${n2.id} is already taken on this canvas` });
51823
+ seen.add(n2.id);
51824
+ for (const child of Array.isArray(n2.children) ? n2.children : [])
51825
+ check(child);
51826
+ };
51827
+ check(tree);
51828
+ this.commit({ op: "insert", parent, ord: ord ?? between(this.lastOrd(parent), null), node: tree });
51829
+ }
50624
51830
  Print(...values) {
50625
51831
  const line = values.map((v) => typeof v === "string" ? v : JSON.stringify(v)).join(" ");
50626
51832
  this.rec.printBytes += line.length;
@@ -50633,6 +51839,35 @@ class ExecuteApi {
50633
51839
  if (this.rec.screenshots.length < LIMITS.screenshots)
50634
51840
  this.rec.screenshots.push(id);
50635
51841
  }
51842
+ Vectorize(frameId, fileId, opts) {
51843
+ if (typeof frameId !== "string" || frameId === "")
51844
+ invalid2("frameId", "expected a frame id");
51845
+ if (typeof fileId !== "string" || fileId === "")
51846
+ invalid2("fileId", "expected a file id");
51847
+ const options = optionKeys2(opts, VECTORIZE_KEYS, "Vectorize");
51848
+ const mode = options.mode === undefined || options.mode === null ? undefined : pickOption(options.mode, VECTORIZE_MODES, "mode", "auto");
51849
+ const maxColors = options.maxColors === undefined || options.maxColors === null ? undefined : options.maxColors;
51850
+ if (maxColors !== undefined && (typeof maxColors !== "number" || !Number.isInteger(maxColors) || maxColors < 1))
51851
+ invalid2("maxColors", "expected a positive integer");
51852
+ const allowComplex = options.allowComplex === undefined || options.allowComplex === null ? undefined : options.allowComplex;
51853
+ if (allowComplex !== undefined && typeof allowComplex !== "boolean")
51854
+ invalid2("allowComplex", "expected a boolean");
51855
+ if (this.rec.pendingVectorize.length >= LIMITS.vectorize)
51856
+ throw new Error(`SCRIPT_LIMIT: at most ${LIMITS.vectorize} Vectorize calls in one execute — ask for one image per execute, or trace one combined image`);
51857
+ const requestId = this.newRequestId();
51858
+ const carried = { ...mode === undefined ? {} : { mode }, ...maxColors === undefined ? {} : { maxColors }, ...allowComplex === undefined ? {} : { allowComplex } };
51859
+ this.rec.pendingVectorize.push({ requestId, frameId, fileId, ...Object.keys(carried).length ? { opts: carried } : {} });
51860
+ return { requestId };
51861
+ }
51862
+ newRequestId() {
51863
+ for (;; ) {
51864
+ let id = "vz-";
51865
+ for (let i = 0;i < 10; i++)
51866
+ id += ID_CHARS[Math.floor(this.random() * ID_CHARS.length)];
51867
+ if (!this.rec.pendingVectorize.some((p) => p.requestId === id))
51868
+ return id;
51869
+ }
51870
+ }
50636
51871
  }
50637
51872
  function toPen(e, depth, _resolved, _instances, shallow = false) {
50638
51873
  const node2 = { ...e.props, id: e.path, type: e.type };
@@ -51030,8 +52265,8 @@ function relative(iso, now) {
51030
52265
  const delta = now - Date.parse(iso), seconds = Math.floor(Math.abs(delta) / 1000);
51031
52266
  if (Math.abs(delta) < 60000)
51032
52267
  return "just now";
51033
- const [n, unit] = seconds < 60 ? [seconds, "s"] : seconds < 3600 ? [Math.floor(seconds / 60), "m"] : seconds < 86400 ? [Math.floor(seconds / 3600), "h"] : [Math.floor(seconds / 86400), "d"];
51034
- return delta < 0 ? `in ${n}${unit}` : `${n}${unit} ago`;
52268
+ const [n2, unit] = seconds < 60 ? [seconds, "s"] : seconds < 3600 ? [Math.floor(seconds / 60), "m"] : seconds < 86400 ? [Math.floor(seconds / 3600), "h"] : [Math.floor(seconds / 86400), "d"];
52269
+ return delta < 0 ? `in ${n2}${unit}` : `${n2}${unit} ago`;
51035
52270
  }
51036
52271
  function scalar(value) {
51037
52272
  return value === undefined ? "" : value === null ? "null" : typeof value === "object" ? JSON.stringify(value) : String(value);
@@ -51123,7 +52358,7 @@ function projectList(items, op) {
51123
52358
  }
51124
52359
 
51125
52360
  // src/output/human.ts
51126
- var count2 = (n, noun) => `${n} ${noun}${n === 1 ? "" : "s"}`;
52361
+ var count2 = (n2, noun) => `${n2} ${noun}${n2 === 1 ? "" : "s"}`;
51127
52362
  function identity2(result, ctx) {
51128
52363
  const op = "op" in result ? result.op : undefined;
51129
52364
  const split = op?.lastIndexOf(".") ?? -1;
@@ -51585,7 +52820,7 @@ function startProgress(ctx, write = (text) => writeOutput({ stderr: text })) {
51585
52820
  }
51586
52821
 
51587
52822
  // src/main.ts
51588
- var version = "0.3.0-dev.bc829d1";
52823
+ var version = "0.3.0-dev.dc553d7";
51589
52824
  var commands = commandTree(operations);
51590
52825
  var manual = [...workflows.map((w) => w.words), [API_WORD]];
51591
52826
  function route(argv) {
@@ -51605,10 +52840,10 @@ function route(argv) {
51605
52840
  words.push(arg);
51606
52841
  if (words.length === 1 && words[0] === API_WORD && HTTP_METHOD.test(argv[i + 1] ?? ""))
51607
52842
  return { words, args: [...args, ...argv.slice(i + 1)] };
51608
- const command = commands.find((c) => c.words.length === words.length && c.words.every((w, n) => w === words[n]));
52843
+ const command = commands.find((c) => c.words.length === words.length && c.words.every((w, n2) => w === words[n2]));
51609
52844
  if (words.length === 1 && words[0] === API_WORD && argv[i + 1] !== undefined && !argv[i + 1].startsWith("-"))
51610
52845
  continue;
51611
- if (command || manual.some((c) => c.length === words.length && c.every((w, n) => w === words[n])))
52846
+ if (command || manual.some((c) => c.length === words.length && c.every((w, n2) => w === words[n2])))
51612
52847
  return { words, args: [...args, ...argv.slice(i + 1)], command };
51613
52848
  }
51614
52849
  return { words, args };
@@ -51839,16 +53074,16 @@ Examples:
51839
53074
  const cursor = result instanceof Page ? result.next_cursor : record(result).next_cursor ?? record(result).nextToken;
51840
53075
  if (typeof cursor === "string" && cursor)
51841
53076
  ctx.nextCommand = nextPageCommand(selected.command, parsed, cursor);
51842
- const pageToken = pageTokenField(op), token = pageToken?.sdkName ?? pageToken?.name;
51843
- const firstPage = flags.all && !(result instanceof Page) && token ? pageOf(result) : undefined;
51844
- if (flags.all && !(result instanceof Page) && token && !firstPage)
51845
- throw new UsageError(`--all cannot find the list in ${op.resource}.${op.method}'s response; page with --${token.replace(/_/g, "-")} instead`);
53077
+ const pageToken = pageTokenField(op), token2 = pageToken?.sdkName ?? pageToken?.name;
53078
+ const firstPage = flags.all && !(result instanceof Page) && token2 ? pageOf(result) : undefined;
53079
+ if (flags.all && !(result instanceof Page) && token2 && !firstPage)
53080
+ throw new UsageError(`--all cannot find the list in ${op.resource}.${op.method}'s response; page with --${token2.replace(/_/g, "-")} instead`);
51846
53081
  if (firstPage) {
51847
53082
  const items = [...firstPage.items];
51848
53083
  const seen = new Set;
51849
53084
  for (let next = firstPage.token;next && !seen.has(next); next = pageOf(result)?.token) {
51850
53085
  seen.add(next);
51851
- result = await owner[op.method]({ ...opts, query: { ...opts.query, [token]: next } });
53086
+ result = await owner[op.method]({ ...opts, query: { ...opts.query, [token2]: next } });
51852
53087
  items.push(...pageOf(result)?.items ?? []);
51853
53088
  }
51854
53089
  ctx.nextCommand = undefined;