openspecui 1.3.0 → 1.4.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.
Files changed (32) hide show
  1. package/dist/cli.mjs +2 -2
  2. package/dist/index.mjs +1 -1
  3. package/dist/{src-E2ERj6H4.mjs → src-kxKAXq88.mjs} +189 -93
  4. package/package.json +1 -1
  5. package/web/assets/{BufferResource-8LHM3mct.js → BufferResource-C85AhGv8.js} +1 -1
  6. package/web/assets/{CanvasRenderer-BSV3tOcF.js → CanvasRenderer-CgtmVcg4.js} +1 -1
  7. package/web/assets/{Filter-C5FD597y.js → Filter-Cb47-EZS.js} +1 -1
  8. package/web/assets/{RenderTargetSystem-DlUN0zsW.js → RenderTargetSystem-Cx8qJk_q.js} +1 -1
  9. package/web/assets/{WebGLRenderer-QgEdU6ZZ.js → WebGLRenderer-pIi2Bx_Q.js} +1 -1
  10. package/web/assets/{WebGPURenderer-D7lHEg9G.js → WebGPURenderer-C3CBA4dG.js} +1 -1
  11. package/web/assets/{browserAll-C7nnv_eJ.js → browserAll-C_q9nnWk.js} +1 -1
  12. package/web/assets/ghostty-web-D6mGnCnU.js +13 -0
  13. package/web/assets/{index-BJlwU-uQ.js → index-3eymcnUu.js} +183 -183
  14. package/web/assets/{index-DYX6cNJ6.js → index-B5M3Dg-Q.js} +1 -1
  15. package/web/assets/{index-C8uGGt6w.js → index-BBPTFxy1.js} +1 -1
  16. package/web/assets/index-BImvtc4B.css +1 -0
  17. package/web/assets/{index-BFbdtMlr.js → index-BSqKqaGj.js} +1 -1
  18. package/web/assets/{index-Byo82vIc.js → index-BwQ_9hzT.js} +1 -1
  19. package/web/assets/{index-BkWa50ks.js → index-C6pjde1Q.js} +1 -1
  20. package/web/assets/{index-Ar3cmjnK.js → index-C79ew42C.js} +1 -1
  21. package/web/assets/{index-Dte58iQe.js → index-CGrYIgSe.js} +1 -1
  22. package/web/assets/{index-JGA2Yc2F.js → index-CGweB5Ib.js} +1 -1
  23. package/web/assets/{index-C_c_g9pe.js → index-CyqwjCgH.js} +1 -1
  24. package/web/assets/{index-B0Q8Tr0G.js → index-D45XwNhE.js} +1 -1
  25. package/web/assets/{index-BdGDc8qr.js → index-D8KhKUsi.js} +1 -1
  26. package/web/assets/{index-CYijlhdV.js → index-LWU4Mw81.js} +1 -1
  27. package/web/assets/{index-CDAgriaJ.js → index-TCkbFaCm.js} +1 -1
  28. package/web/assets/{index-DwUe2J4w.js → index-knJhpHqo.js} +1 -1
  29. package/web/assets/{index-Nzl3W_bm.js → index-ur_rMFp9.js} +1 -1
  30. package/web/assets/{webworkerAll-CEAZP48d.js → webworkerAll-Cq063Dqj.js} +1 -1
  31. package/web/index.html +2 -2
  32. package/web/assets/index-ZMhgIxpu.css +0 -1
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as SchemaInfoSchema, c as CliExecutor, d as __commonJS, f as __toESM, i as SchemaDetailSchema, l as ConfigManager, o as SchemaResolutionSchema, r as require_dist, s as TemplatesSchema, t as startServer, u as OpenSpecAdapter } from "./src-E2ERj6H4.mjs";
2
+ import { a as SchemaInfoSchema, c as CliExecutor, d as __commonJS, f as __toESM, i as SchemaDetailSchema, l as ConfigManager, o as SchemaResolutionSchema, r as require_dist, s as TemplatesSchema, t as startServer, u as OpenSpecAdapter } from "./src-kxKAXq88.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { basename, dirname, extname, join, normalize, relative, resolve } from "path";
5
5
  import { readFile } from "node:fs/promises";
@@ -4505,7 +4505,7 @@ var yargs_default = Yargs;
4505
4505
 
4506
4506
  //#endregion
4507
4507
  //#region package.json
4508
- var version = "1.3.0";
4508
+ var version = "1.4.0";
4509
4509
  var devDependencies = {
4510
4510
  "@hono/node-server": "^1.14.1",
4511
4511
  "@openspecui/server": "workspace:*",
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { n as createServer, t as startServer } from "./src-E2ERj6H4.mjs";
1
+ import { n as createServer, t as startServer } from "./src-kxKAXq88.mjs";
2
2
 
3
3
  export { createServer, startServer };
@@ -8,7 +8,7 @@ import { dirname, join } from "path";
8
8
  import { AsyncLocalStorage } from "node:async_hooks";
9
9
  import { mkdir as mkdir$1, readFile as readFile$1, readdir, rm, stat, writeFile as writeFile$1 } from "node:fs/promises";
10
10
  import { dirname as dirname$1, join as join$1, matchesGlob, relative as relative$1, resolve as resolve$1, sep } from "node:path";
11
- import { existsSync, readFileSync, realpathSync, statSync, utimesSync } from "node:fs";
11
+ import { existsSync, lstatSync, readFileSync, realpathSync, statSync } from "node:fs";
12
12
  import { watch } from "fs";
13
13
  import { EventEmitter } from "events";
14
14
  import { exec, spawn } from "child_process";
@@ -1055,8 +1055,10 @@ const DEFAULT_IGNORE = [
1055
1055
  ".git",
1056
1056
  "**/.DS_Store"
1057
1057
  ];
1058
- /** 健康检查间隔 (ms) - 3秒 */
1059
- const HEALTH_CHECK_INTERVAL_MS = 3e3;
1058
+ /** 恢复重试间隔 (ms) */
1059
+ const RECOVERY_INTERVAL_MS = 3e3;
1060
+ /** 路径语义检查间隔 (ms) */
1061
+ const PATH_LIVENESS_INTERVAL_MS = 3e3;
1060
1062
  /**
1061
1063
  * 项目监听器
1062
1064
  *
@@ -1079,17 +1081,25 @@ var ProjectWatcher = class {
1079
1081
  ignore;
1080
1082
  initialized = false;
1081
1083
  initPromise = null;
1082
- healthCheckTimer = null;
1083
- lastEventTime = 0;
1084
- healthCheckPending = false;
1085
- enableHealthCheck;
1086
1084
  reinitializeTimer = null;
1087
1085
  reinitializePending = false;
1086
+ reinitializeReasonPending = null;
1087
+ pathLivenessTimer = null;
1088
+ projectDirFingerprint = null;
1089
+ generation = 0;
1090
+ reinitializeCount = 0;
1091
+ lastReinitializeReason = null;
1092
+ reinitializeReasonCounts = {
1093
+ "drop-events": 0,
1094
+ "watcher-error": 0,
1095
+ "missing-project-dir": 0,
1096
+ "project-dir-replaced": 0,
1097
+ manual: 0
1098
+ };
1088
1099
  constructor(projectDir, options = {}) {
1089
1100
  this.projectDir = getRealPath$1(projectDir);
1090
1101
  this.debounceMs = options.debounceMs ?? DEBOUNCE_MS$1;
1091
1102
  this.ignore = options.ignore ?? DEFAULT_IGNORE;
1092
- this.enableHealthCheck = options.enableHealthCheck ?? true;
1093
1103
  }
1094
1104
  /**
1095
1105
  * 初始化 watcher
@@ -1098,8 +1108,11 @@ var ProjectWatcher = class {
1098
1108
  async init() {
1099
1109
  if (this.initialized) return;
1100
1110
  if (this.initPromise) return this.initPromise;
1101
- this.initPromise = this.doInit();
1102
- await this.initPromise;
1111
+ this.initPromise = this.doInit().catch((error) => {
1112
+ this.initPromise = null;
1113
+ throw error;
1114
+ });
1115
+ return this.initPromise;
1103
1116
  }
1104
1117
  async doInit() {
1105
1118
  this.subscription = await (await import("@parcel/watcher")).subscribe(this.projectDir, (err, events) => {
@@ -1110,43 +1123,98 @@ var ProjectWatcher = class {
1110
1123
  this.handleEvents(events);
1111
1124
  }, { ignore: this.ignore });
1112
1125
  this.initialized = true;
1113
- this.lastEventTime = Date.now();
1114
- if (this.enableHealthCheck) this.startHealthCheck();
1126
+ this.generation += 1;
1127
+ this.projectDirFingerprint = this.getProjectDirFingerprint();
1128
+ this.startPathLivenessMonitor();
1115
1129
  }
1116
1130
  /**
1117
1131
  * 处理 watcher 错误
1118
- * 对于 FSEvents dropped 错误,触发延迟重建
1132
+ * 统一走错误驱动重建流程
1119
1133
  */
1120
1134
  handleWatcherError(err) {
1121
1135
  if ((err.message || String(err)).includes("Events were dropped")) {
1122
1136
  if (!this.reinitializePending) {
1123
1137
  console.warn("[ProjectWatcher] FSEvents dropped events, scheduling reinitialize...");
1124
- this.scheduleReinitialize();
1138
+ this.scheduleReinitialize("drop-events");
1125
1139
  }
1126
1140
  return;
1127
1141
  }
1128
- console.error("[ProjectWatcher] Error:", err);
1142
+ console.error("[ProjectWatcher] Watcher error, scheduling reinitialize:", err);
1143
+ this.scheduleReinitialize("watcher-error");
1129
1144
  }
1130
1145
  /**
1131
1146
  * 延迟重建 watcher(防抖,避免频繁重建)
1132
1147
  */
1133
- scheduleReinitialize() {
1148
+ scheduleReinitialize(reason) {
1149
+ this.reinitializeReasonPending = reason;
1134
1150
  if (this.reinitializePending) return;
1135
1151
  this.reinitializePending = true;
1136
1152
  if (this.reinitializeTimer) clearTimeout(this.reinitializeTimer);
1137
1153
  this.reinitializeTimer = setTimeout(() => {
1138
1154
  this.reinitializeTimer = null;
1139
1155
  this.reinitializePending = false;
1140
- console.log("[ProjectWatcher] Reinitializing due to FSEvents error...");
1141
- this.reinitialize();
1142
- }, 1e3);
1156
+ const pendingReason = this.reinitializeReasonPending ?? reason;
1157
+ this.reinitializeReasonPending = null;
1158
+ console.log(`[ProjectWatcher] Reinitializing (reason: ${pendingReason})...`);
1159
+ this.reinitialize(pendingReason);
1160
+ }, RECOVERY_INTERVAL_MS);
1161
+ this.reinitializeTimer.unref();
1162
+ }
1163
+ /**
1164
+ * 读取项目目录指纹(目录不存在时返回 null)
1165
+ * 用于检测 path 对应实体是否被替换(inode/dev 漂移)
1166
+ */
1167
+ getProjectDirFingerprint() {
1168
+ try {
1169
+ const stat$1 = lstatSync(this.projectDir);
1170
+ return `${stat$1.dev}:${stat$1.ino}`;
1171
+ } catch {
1172
+ return null;
1173
+ }
1174
+ }
1175
+ /**
1176
+ * 启动路径语义监测(避免 watcher 绑定到已失效句柄)
1177
+ */
1178
+ startPathLivenessMonitor() {
1179
+ this.stopPathLivenessMonitor();
1180
+ this.pathLivenessTimer = setInterval(() => {
1181
+ this.checkPathLiveness();
1182
+ }, PATH_LIVENESS_INTERVAL_MS);
1183
+ this.pathLivenessTimer.unref();
1184
+ }
1185
+ /**
1186
+ * 停止路径语义监测
1187
+ */
1188
+ stopPathLivenessMonitor() {
1189
+ if (this.pathLivenessTimer) {
1190
+ clearInterval(this.pathLivenessTimer);
1191
+ this.pathLivenessTimer = null;
1192
+ }
1193
+ }
1194
+ /**
1195
+ * 只读检查 projectDir 是否仍指向初始化时的目录实体
1196
+ */
1197
+ checkPathLiveness() {
1198
+ if (!this.initialized || this.reinitializePending) return;
1199
+ const current = this.getProjectDirFingerprint();
1200
+ if (current === null) {
1201
+ console.warn("[ProjectWatcher] Project directory missing, scheduling reinitialize...");
1202
+ this.scheduleReinitialize("missing-project-dir");
1203
+ return;
1204
+ }
1205
+ if (this.projectDirFingerprint === null) {
1206
+ this.projectDirFingerprint = current;
1207
+ return;
1208
+ }
1209
+ if (current !== this.projectDirFingerprint) {
1210
+ console.warn("[ProjectWatcher] Project directory replaced, scheduling reinitialize...");
1211
+ this.scheduleReinitialize("project-dir-replaced");
1212
+ }
1143
1213
  }
1144
1214
  /**
1145
1215
  * 处理原始事件
1146
1216
  */
1147
1217
  handleEvents(events) {
1148
- this.lastEventTime = Date.now();
1149
- this.healthCheckPending = false;
1150
1218
  const watchEvents = events.map((e) => ({
1151
1219
  type: e.type,
1152
1220
  path: e.path
@@ -1234,60 +1302,29 @@ var ProjectWatcher = class {
1234
1302
  return this.initialized;
1235
1303
  }
1236
1304
  /**
1237
- * 启动健康检查定时器
1305
+ * 获取 watcher 运行时状态
1238
1306
  */
1239
- startHealthCheck() {
1240
- this.stopHealthCheck();
1241
- this.healthCheckTimer = setInterval(() => {
1242
- this.performHealthCheck();
1243
- }, HEALTH_CHECK_INTERVAL_MS);
1244
- this.healthCheckTimer.unref();
1245
- }
1246
- /**
1247
- * 停止健康检查定时器
1248
- */
1249
- stopHealthCheck() {
1250
- if (this.healthCheckTimer) {
1251
- clearInterval(this.healthCheckTimer);
1252
- this.healthCheckTimer = null;
1253
- }
1254
- this.healthCheckPending = false;
1255
- }
1256
- /**
1257
- * 执行健康检查
1258
- *
1259
- * 工作流程:
1260
- * 1. 如果最近有事件,无需检查
1261
- * 2. 如果上次探测还在等待中,说明 watcher 可能失效,尝试重建
1262
- * 3. 否则,创建临时文件触发事件,等待下次检查验证
1263
- */
1264
- async performHealthCheck() {
1265
- if (Date.now() - this.lastEventTime < HEALTH_CHECK_INTERVAL_MS) {
1266
- this.healthCheckPending = false;
1267
- return;
1268
- }
1269
- if (this.healthCheckPending) {
1270
- console.warn("[ProjectWatcher] Health check failed, watcher appears stale. Reinitializing...");
1271
- await this.reinitialize();
1272
- return;
1273
- }
1274
- this.healthCheckPending = true;
1275
- this.sendProbe();
1307
+ get runtimeStatus() {
1308
+ return {
1309
+ generation: this.generation,
1310
+ reinitializeCount: this.reinitializeCount,
1311
+ lastReinitializeReason: this.lastReinitializeReason,
1312
+ reinitializeReasonCounts: { ...this.reinitializeReasonCounts }
1313
+ };
1276
1314
  }
1277
1315
  /**
1278
- * 发送探测:通过 utimesSync 修改项目目录的时间戳来触发 watcher 事件
1316
+ * 记录重建统计
1279
1317
  */
1280
- sendProbe() {
1281
- try {
1282
- const now = /* @__PURE__ */ new Date();
1283
- utimesSync(this.projectDir, now, now);
1284
- } catch {}
1318
+ markReinitialized(reason) {
1319
+ this.reinitializeCount += 1;
1320
+ this.lastReinitializeReason = reason;
1321
+ this.reinitializeReasonCounts[reason] += 1;
1285
1322
  }
1286
1323
  /**
1287
1324
  * 重新初始化 watcher
1288
1325
  */
1289
- async reinitialize() {
1290
- this.stopHealthCheck();
1326
+ async reinitialize(reason) {
1327
+ this.stopPathLivenessMonitor();
1291
1328
  if (this.subscription) {
1292
1329
  try {
1293
1330
  await this.subscription.unsubscribe();
@@ -1296,38 +1333,50 @@ var ProjectWatcher = class {
1296
1333
  }
1297
1334
  this.initialized = false;
1298
1335
  this.initPromise = null;
1299
- this.healthCheckPending = false;
1336
+ this.projectDirFingerprint = null;
1300
1337
  if (!existsSync(this.projectDir)) {
1301
1338
  console.warn("[ProjectWatcher] Project directory does not exist, waiting for it to be created...");
1302
- this.waitForProjectDir();
1339
+ this.waitForProjectDir("missing-project-dir");
1303
1340
  return;
1304
1341
  }
1305
1342
  try {
1306
1343
  await this.init();
1344
+ this.markReinitialized(reason);
1307
1345
  console.log("[ProjectWatcher] Reinitialized successfully");
1308
1346
  } catch (err) {
1309
1347
  console.error("[ProjectWatcher] Failed to reinitialize:", err);
1310
- setTimeout(() => this.reinitialize(), HEALTH_CHECK_INTERVAL_MS);
1348
+ this.scheduleReinitialize(reason);
1311
1349
  }
1312
1350
  }
1313
1351
  /**
1314
1352
  * 等待项目目录被创建
1315
1353
  */
1316
- waitForProjectDir() {
1317
- const checkInterval = setInterval(() => {
1318
- if (existsSync(this.projectDir)) {
1319
- clearInterval(checkInterval);
1320
- console.log("[ProjectWatcher] Project directory created, reinitializing...");
1321
- this.reinitialize();
1354
+ waitForProjectDir(reason) {
1355
+ this.reinitializeReasonPending = reason;
1356
+ this.reinitializePending = true;
1357
+ if (this.reinitializeTimer) {
1358
+ clearTimeout(this.reinitializeTimer);
1359
+ this.reinitializeTimer = null;
1360
+ }
1361
+ this.reinitializeTimer = setTimeout(() => {
1362
+ this.reinitializeTimer = null;
1363
+ this.reinitializePending = false;
1364
+ if (!existsSync(this.projectDir)) {
1365
+ this.waitForProjectDir(reason);
1366
+ return;
1322
1367
  }
1323
- }, HEALTH_CHECK_INTERVAL_MS);
1324
- checkInterval.unref();
1368
+ const pendingReason = this.reinitializeReasonPending ?? reason;
1369
+ this.reinitializeReasonPending = null;
1370
+ console.log("[ProjectWatcher] Project directory created, reinitializing...");
1371
+ this.reinitialize(pendingReason);
1372
+ }, RECOVERY_INTERVAL_MS);
1373
+ this.reinitializeTimer.unref();
1325
1374
  }
1326
1375
  /**
1327
1376
  * 关闭 watcher
1328
1377
  */
1329
1378
  async close() {
1330
- this.stopHealthCheck();
1379
+ this.stopPathLivenessMonitor();
1331
1380
  if (this.debounceTimer) {
1332
1381
  clearTimeout(this.debounceTimer);
1333
1382
  this.debounceTimer = null;
@@ -1337,6 +1386,7 @@ var ProjectWatcher = class {
1337
1386
  this.reinitializeTimer = null;
1338
1387
  }
1339
1388
  this.reinitializePending = false;
1389
+ this.reinitializeReasonPending = null;
1340
1390
  if (this.subscription) {
1341
1391
  await this.subscription.unsubscribe();
1342
1392
  this.subscription = null;
@@ -1345,6 +1395,7 @@ var ProjectWatcher = class {
1345
1395
  this.pendingEvents = [];
1346
1396
  this.initialized = false;
1347
1397
  this.initPromise = null;
1398
+ this.projectDirFingerprint = null;
1348
1399
  }
1349
1400
  };
1350
1401
  /**
@@ -1472,6 +1523,22 @@ function acquireWatcher(path$1, onChange, options = {}) {
1472
1523
  function isWatcherPoolInitialized() {
1473
1524
  return globalProjectWatcher !== null && globalProjectWatcher.isInitialized;
1474
1525
  }
1526
+ /**
1527
+ * 获取 watcher 运行时状态
1528
+ */
1529
+ function getWatcherRuntimeStatus() {
1530
+ if (!globalProjectWatcher) return null;
1531
+ const runtime = globalProjectWatcher.runtimeStatus;
1532
+ return {
1533
+ projectDir: globalProjectDir,
1534
+ initialized: globalProjectWatcher.isInitialized,
1535
+ subscriptionCount: globalProjectWatcher.subscriptionCount,
1536
+ generation: runtime.generation,
1537
+ reinitializeCount: runtime.reinitializeCount,
1538
+ lastReinitializeReason: runtime.lastReinitializeReason,
1539
+ reinitializeReasonCounts: runtime.reinitializeReasonCounts
1540
+ };
1541
+ }
1475
1542
 
1476
1543
  //#endregion
1477
1544
  //#region ../core/src/reactive-fs/reactive-fs.ts
@@ -5835,6 +5902,8 @@ const CURSOR_STYLE_VALUES = [
5835
5902
  "underline",
5836
5903
  "bar"
5837
5904
  ];
5905
+ const TERMINAL_RENDERER_ENGINE_VALUES = ["xterm", "ghostty"];
5906
+ const TerminalRendererEngineSchema = enumType(TERMINAL_RENDERER_ENGINE_VALUES);
5838
5907
  const BASE_PACKAGE_MANAGER_RUNNERS = [
5839
5908
  {
5840
5909
  id: "npx",
@@ -6172,7 +6241,8 @@ const TerminalConfigSchema = objectType({
6172
6241
  fontFamily: stringType().default(""),
6173
6242
  cursorBlink: booleanType().default(true),
6174
6243
  cursorStyle: enumType(CURSOR_STYLE_VALUES).default("block"),
6175
- scrollback: numberType().min(0).max(1e5).default(1e3)
6244
+ scrollback: numberType().min(0).max(1e5).default(1e3),
6245
+ rendererEngine: stringType().default("xterm")
6176
6246
  });
6177
6247
  /**
6178
6248
  * OpenSpecUI 配置 Schema
@@ -23468,6 +23538,16 @@ async function fetchOpsxTemplateContents(ctx, schema$6) {
23468
23538
  await ctx.kernel.ensureTemplateContents(schema$6);
23469
23539
  return ctx.kernel.getTemplateContents(schema$6);
23470
23540
  }
23541
+ function buildSystemStatus(ctx) {
23542
+ const runtime = getWatcherRuntimeStatus();
23543
+ return {
23544
+ projectDir: ctx.projectDir,
23545
+ watcherEnabled: runtime?.initialized ?? false,
23546
+ watcherGeneration: runtime?.generation ?? 0,
23547
+ watcherReinitializeCount: runtime?.reinitializeCount ?? 0,
23548
+ watcherLastReinitializeReason: runtime?.lastReinitializeReason ?? null
23549
+ };
23550
+ }
23471
23551
  /**
23472
23552
  * Spec router - spec CRUD operations
23473
23553
  */
@@ -23675,17 +23755,7 @@ const configRouter = router({
23675
23755
  "dark",
23676
23756
  "system"
23677
23757
  ]).optional(),
23678
- terminal: objectType({
23679
- fontSize: numberType().min(8).max(32).optional(),
23680
- fontFamily: stringType().optional(),
23681
- cursorBlink: booleanType().optional(),
23682
- cursorStyle: enumType([
23683
- "block",
23684
- "underline",
23685
- "bar"
23686
- ]).optional(),
23687
- scrollback: numberType().min(0).max(1e5).optional()
23688
- }).optional()
23758
+ terminal: TerminalConfigSchema.omit({ rendererEngine: true }).partial().extend({ rendererEngine: TerminalRendererEngineSchema.optional() }).optional()
23689
23759
  })).mutation(async ({ ctx, input }) => {
23690
23760
  const hasCliCommand = input.cli !== void 0 && Object.prototype.hasOwnProperty.call(input.cli, "command");
23691
23761
  const hasCliArgs = input.cli !== void 0 && Object.prototype.hasOwnProperty.call(input.cli, "args");
@@ -24130,6 +24200,26 @@ const searchRouter = router({
24130
24200
  })
24131
24201
  });
24132
24202
  /**
24203
+ * System router - runtime status and heartbeat-friendly subscription
24204
+ */
24205
+ const systemRouter = router({
24206
+ status: publicProcedure.query(({ ctx }) => {
24207
+ return buildSystemStatus(ctx);
24208
+ }),
24209
+ subscribe: publicProcedure.subscription(({ ctx }) => {
24210
+ return observable((emit) => {
24211
+ emit.next(buildSystemStatus(ctx));
24212
+ const timer = setInterval(() => {
24213
+ emit.next(buildSystemStatus(ctx));
24214
+ }, 3e3);
24215
+ timer.unref();
24216
+ return () => {
24217
+ clearInterval(timer);
24218
+ };
24219
+ });
24220
+ })
24221
+ });
24222
+ /**
24133
24223
  * Main app router
24134
24224
  */
24135
24225
  const appRouter = router({
@@ -24142,7 +24232,8 @@ const appRouter = router({
24142
24232
  cli: cliRouter,
24143
24233
  opsx: opsxRouter,
24144
24234
  kv: kvRouter,
24145
- search: searchRouter
24235
+ search: searchRouter,
24236
+ system: systemRouter
24146
24237
  });
24147
24238
 
24148
24239
  //#endregion
@@ -24448,7 +24539,12 @@ async function createWebSocketServer(server, httpServer, config) {
24448
24539
  const handler = applyWSSHandler({
24449
24540
  wss,
24450
24541
  router: appRouter,
24451
- createContext: server.createContext
24542
+ createContext: server.createContext,
24543
+ keepAlive: {
24544
+ enabled: true,
24545
+ pingMs: 3e4,
24546
+ pongWaitMs: 5e3
24547
+ }
24452
24548
  });
24453
24549
  const ptyManager = new PtyManager(config.projectDir);
24454
24550
  const ptyWss = new import_websocket_server.default({ noServer: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openspecui",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "OpenSpec UI - Visual interface for spec-driven development",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -1,4 +1,4 @@
1
- import{y as U,z as g,A as c,B as S,D as _,F as m,H as I,J as p}from"./index-BJlwU-uQ.js";const x={name:"local-uniform-bit",vertex:{header:`
1
+ import{y as U,z as g,A as c,B as S,D as _,F as m,H as I,J as p}from"./index-3eymcnUu.js";const x={name:"local-uniform-bit",vertex:{header:`
2
2
 
3
3
  struct LocalUniforms {
4
4
  uTransformMatrix:mat3x3<f32>,
@@ -1 +1 @@
1
- import{K as U,M as A,O as K,P as be,Q as ne,R as O,T as S,U as qe,y as Le,V as we,W as Ye,X as Ne,Y as Xe,Z as je,_ as $e,$ as Ke,a0 as Qe,a1 as ze,a2 as se}from"./index-BJlwU-uQ.js";import{R as Je,S as Ze,B as et,a as tt,b as nt,c as at,A as st,C as ot}from"./RenderTargetSystem-DlUN0zsW.js";import"./Filter-C5FD597y.js";let $;function Me(s){const e=U.get().createCanvas(6,1),t=e.getContext("2d");return t.fillStyle=s,t.fillRect(0,0,6,1),e}function Se(){if($!==void 0)return $;try{const s=Me("#ff00ff"),e=Me("#ffff00"),a=U.get().createCanvas(6,1).getContext("2d");a.globalCompositeOperation="multiply",a.drawImage(s,0,0),a.drawImage(e,2,0);const n=a.getImageData(2,0,1,1);if(!n)$=!1;else{const o=n.data;$=o[0]===255&&o[1]===0&&o[2]===0}}catch{$=!1}return $}const d={canvas:null,convertTintToImage:!1,cacheStepsPerColorChannel:8,canUseMultiply:Se(),tintMethod:null,_canvasSourceCache:new WeakMap,_unpremultipliedCache:new WeakMap,getCanvasSource:s=>{const e=s.source,t=e?.resource;if(!t)return null;const a=e.alphaMode==="premultiplied-alpha",n=e.resourceWidth??e.pixelWidth,o=e.resourceHeight??e.pixelHeight,r=n!==e.pixelWidth||o!==e.pixelHeight;if(a){if((t instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&t instanceof OffscreenCanvas)&&!r)return t;const i=d._unpremultipliedCache.get(e);if(i?.resourceId===e._resourceId)return i.canvas}if(t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int8Array||t instanceof Uint16Array||t instanceof Int16Array||t instanceof Uint32Array||t instanceof Int32Array||t instanceof Float32Array||t instanceof ArrayBuffer){const i=d._canvasSourceCache.get(e);if(i?.resourceId===e._resourceId)return i.canvas;const c=U.get().createCanvas(e.pixelWidth,e.pixelHeight),h=c.getContext("2d"),l=h.createImageData(e.pixelWidth,e.pixelHeight),u=l.data,m=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(e.format==="bgra8unorm")for(let v=0;v<u.length&&v+3<m.length;v+=4)u[v]=m[v+2],u[v+1]=m[v+1],u[v+2]=m[v],u[v+3]=m[v+3];else u.set(m.subarray(0,u.length));return h.putImageData(l,0,0),d._canvasSourceCache.set(e,{canvas:c,resourceId:e._resourceId}),c}if(a){const i=U.get().createCanvas(e.pixelWidth,e.pixelHeight),c=i.getContext("2d",{willReadFrequently:!0});i.width=e.pixelWidth,i.height=e.pixelHeight,c.drawImage(t,0,0);const h=c.getImageData(0,0,i.width,i.height),l=h.data;for(let u=0;u<l.length;u+=4){const m=l[u+3];if(m>0){const v=255/m;l[u]=Math.min(255,l[u]*v+.5),l[u+1]=Math.min(255,l[u+1]*v+.5),l[u+2]=Math.min(255,l[u+2]*v+.5)}}return c.putImageData(h,0,0),d._unpremultipliedCache.set(e,{canvas:i,resourceId:e._resourceId}),i}if(r){const i=d._canvasSourceCache.get(e);if(i?.resourceId===e._resourceId)return i.canvas;const c=U.get().createCanvas(e.pixelWidth,e.pixelHeight),h=c.getContext("2d");return c.width=e.pixelWidth,c.height=e.pixelHeight,h.drawImage(t,0,0),d._canvasSourceCache.set(e,{canvas:c,resourceId:e._resourceId}),c}return t},getTintedCanvas:(s,e)=>{const t=s.texture,a=K.shared.setValue(e).toHex(),n=t.tintCache||(t.tintCache={}),o=n[a],r=t.source._resourceId;if(o?.tintId===r)return o;const i=o&&"getContext"in o?o:U.get().createCanvas();return d.tintMethod(t,e,i),i.tintId=r,n[a]=i,n[a]},getTintedPattern:(s,e)=>{const t=K.shared.setValue(e).toHex(),a=s.patternCache||(s.patternCache={}),n=s.source._resourceId;let o=a[t];return o?.tintId===n||(d.canvas||(d.canvas=U.get().createCanvas()),d.tintMethod(s,e,d.canvas),o=d.canvas.getContext("2d").createPattern(d.canvas,"repeat"),o.tintId=n,a[t]=o),o},applyPatternTransform:(s,e,t=!0)=>{if(!e)return;const a=s;if(!a.setTransform)return;const n=globalThis.DOMMatrix;if(!n)return;const o=new n([e.a,e.b,e.c,e.d,e.tx,e.ty]);a.setTransform(t?o.inverse():o)},tintWithMultiply:(s,e,t)=>{const a=t.getContext("2d"),n=s.frame.clone(),o=s.source._resolution??s.source.resolution??1,r=s.rotate;n.x*=o,n.y*=o,n.width*=o,n.height*=o;const i=A.isVertical(r),c=i?n.height:n.width,h=i?n.width:n.height;t.width=Math.ceil(c),t.height=Math.ceil(h),a.save(),a.fillStyle=K.shared.setValue(e).toHex(),a.fillRect(0,0,c,h),a.globalCompositeOperation="multiply";const l=d.getCanvasSource(s);if(!l){a.restore();return}r&&d._applyInverseRotation(a,r,n.width,n.height),a.drawImage(l,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a.globalCompositeOperation="destination-atop",a.drawImage(l,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a.restore()},tintWithOverlay:(s,e,t)=>{const a=t.getContext("2d"),n=s.frame.clone(),o=s.source._resolution??s.source.resolution??1,r=s.rotate;n.x*=o,n.y*=o,n.width*=o,n.height*=o;const i=A.isVertical(r),c=i?n.height:n.width,h=i?n.width:n.height;t.width=Math.ceil(c),t.height=Math.ceil(h),a.save(),a.globalCompositeOperation="copy",a.fillStyle=K.shared.setValue(e).toHex(),a.fillRect(0,0,c,h),a.globalCompositeOperation="destination-atop";const l=d.getCanvasSource(s);if(!l){a.restore();return}r&&d._applyInverseRotation(a,r,n.width,n.height),a.drawImage(l,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a.restore()},tintWithPerPixel:(s,e,t)=>{const a=t.getContext("2d"),n=s.frame.clone(),o=s.source._resolution??s.source.resolution??1,r=s.rotate;n.x*=o,n.y*=o,n.width*=o,n.height*=o;const i=A.isVertical(r),c=i?n.height:n.width,h=i?n.width:n.height;t.width=Math.ceil(c),t.height=Math.ceil(h),a.save(),a.globalCompositeOperation="copy";const l=d.getCanvasSource(s);if(!l){a.restore();return}r&&d._applyInverseRotation(a,r,n.width,n.height),a.drawImage(l,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a.restore();const u=e>>16&255,m=e>>8&255,v=e&255,k=a.getImageData(0,0,c,h),T=k.data;for(let C=0;C<T.length;C+=4)T[C]=T[C]*u/255,T[C+1]=T[C+1]*m/255,T[C+2]=T[C+2]*v/255;a.putImageData(k,0,0)},_applyInverseRotation:(s,e,t,a)=>{const n=A.inv(e),o=A.uX(n),r=A.uY(n),i=A.vX(n),c=A.vY(n),h=-Math.min(0,o*t,i*a,o*t+i*a),l=-Math.min(0,r*t,c*a,r*t+c*a);s.transform(o,r,i,c,h,l)}};d.tintMethod=d.canUseMultiply?d.tintWithMultiply:d.tintWithPerPixel;const fe=class L{static _getPatternRepeat(e,t){const a=e&&e!=="clamp-to-edge",n=t&&t!=="clamp-to-edge";return a&&n?"repeat":a?"repeat-x":n?"repeat-y":"no-repeat"}start(e,t,a){}execute(e,t){const a=t.elements;if(!a||!a.length)return;const n=e.renderer,o=n.canvasContext,r=o.activeContext;for(let i=0;i<a.length;i++){const c=a[i];if(!c.packAsQuad)continue;const h=c,l=h.texture,u=l?d.getCanvasSource(l):null;if(!u)continue;const m=l.source.style,v=o.smoothProperty,k=m.scaleMode!=="nearest";r[v]!==k&&(r[v]=k),o.setBlendMode(t.blendMode);const T=n.globalUniforms.globalUniformData?.worldColor??4294967295,C=h.color,B=(T>>>24&255)/255,P=(C>>>24&255)/255,H=n.filter?.alphaMultiplier??1,V=B*P*H;if(V<=0)continue;r.globalAlpha=V;const J=T&16777215,b=C&16777215,F=be(ne(b,J)),W=l.frame,Q=m.addressModeU??m.addressMode,Y=m.addressModeV??m.addressMode,g=L._getPatternRepeat(Q,Y),y=l.source._resolution??l.source.resolution??1,x=h.renderable?.renderGroup?.isCachedAsTexture,G=W.x*y,N=W.y*y,w=W.width*y,E=W.height*y,_=h.bounds,I=n.renderTarget.renderTarget.isRoot,R=_.minX,z=_.minY,q=_.maxX-_.minX,D=_.maxY-_.minY,M=l.rotate,p=l.uvs,oe=Math.min(p.x0,p.x1,p.x2,p.x3,p.y0,p.y1,p.y2,p.y3),Ee=Math.max(p.x0,p.x1,p.x2,p.x3,p.y0,p.y1,p.y2,p.y3),ge=g!=="no-repeat"&&(oe<0||Ee>1),re=M&&!(!ge&&(F!==16777215||M));re?(L._tempPatternMatrix.copyFrom(h.transform),A.matrixAppendRotationInv(L._tempPatternMatrix,M,R,z,q,D),o.setContextTransform(L._tempPatternMatrix,h.roundPixels===1,void 0,x&&I)):o.setContextTransform(h.transform,h.roundPixels===1,void 0,x&&I);const Z=re?0:R,ee=re?0:z,ie=q,ce=D;if(ge){let le=u;const X=F!==16777215&&!M,j=W.width<=l.source.width&&W.height<=l.source.height;X&&j&&(le=d.getTintedCanvas({texture:l},F));const he=r.createPattern(le,g);if(!he)continue;const me=ie,ve=ce;if(me===0||ve===0)continue;const ye=1/me,Ce=1/ve,xe=(p.x1-p.x0)*ye,Te=(p.y1-p.y0)*ye,Pe=(p.x3-p.x0)*Ce,_e=(p.y3-p.y0)*Ce,Ve=p.x0-xe*Z-Pe*ee,Fe=p.y0-Te*Z-_e*ee,de=l.source.pixelWidth,pe=l.source.pixelHeight;L._tempPatternMatrix.set(xe*de,Te*pe,Pe*de,_e*pe,Ve*de,Fe*pe),d.applyPatternTransform(he,L._tempPatternMatrix),r.fillStyle=he,r.fillRect(Z,ee,ie,ce)}else{const X=F!==16777215||M?d.getTintedCanvas({texture:l},F):u,j=X!==u;r.drawImage(X,j?0:G,j?0:N,j?X.width:w,j?X.height:E,Z,ee,ie,ce)}}}};fe._tempPatternMatrix=new O;fe.extension={type:[S.CanvasPipesAdaptor],name:"batch"};let rt=fe;class ke{constructor(e){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=e}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(e,t,a){this._renderer.renderPipes.batch.break(a);const n=this._colorStack;n[this._colorStackIndex]=n[this._colorStackIndex-1]&e.mask;const o=this._colorStack[this._colorStackIndex];o!==this._currentColor&&(this._currentColor=o,a.add({renderPipeId:"colorMask",colorMask:o,canBundle:!1})),this._colorStackIndex++}pop(e,t,a){this._renderer.renderPipes.batch.break(a);const n=this._colorStack;this._colorStackIndex--;const o=n[this._colorStackIndex-1];o!==this._currentColor&&(this._currentColor=o,a.add({renderPipeId:"colorMask",colorMask:o,canBundle:!1}))}execute(e){}destroy(){this._renderer=null,this._colorStack=null}}ke.extension={type:[S.CanvasPipes],name:"colorMask"};function it(s,e,t,a,n,o){o=Math.max(0,Math.min(o,Math.min(a,n)/2)),s.moveTo(e+o,t),s.lineTo(e+a-o,t),s.quadraticCurveTo(e+a,t,e+a,t+o),s.lineTo(e+a,t+n-o),s.quadraticCurveTo(e+a,t+n,e+a-o,t+n),s.lineTo(e+o,t+n),s.quadraticCurveTo(e,t+n,e,t+n-o),s.lineTo(e,t+o),s.quadraticCurveTo(e,t,e+o,t)}function Ie(s,e){switch(e.type){case"rectangle":{const t=e;s.rect(t.x,t.y,t.width,t.height);break}case"roundedRectangle":{const t=e;it(s,t.x,t.y,t.width,t.height,t.radius);break}case"circle":{const t=e;s.moveTo(t.x+t.radius,t.y),s.arc(t.x,t.y,t.radius,0,Math.PI*2);break}case"ellipse":{const t=e;s.ellipse?(s.moveTo(t.x+t.halfWidth,t.y),s.ellipse(t.x,t.y,t.halfWidth,t.halfHeight,0,0,Math.PI*2)):(s.save(),s.translate(t.x,t.y),s.scale(t.halfWidth,t.halfHeight),s.moveTo(1,0),s.arc(0,0,1,0,Math.PI*2),s.restore());break}case"triangle":{const t=e;s.moveTo(t.x,t.y),s.lineTo(t.x2,t.y2),s.lineTo(t.x3,t.y3),s.closePath();break}default:{const t=e,a=t.points;if(!a?.length)break;s.moveTo(a[0],a[1]);for(let n=2;n<a.length;n+=2)s.lineTo(a[n],a[n+1]);t.closePath&&s.closePath();break}}}function ct(s,e){if(!e?.length)return!1;for(let t=0;t<e.length;t++){const a=e[t];if(!a?.shape)continue;const n=a.transform,o=n&&!n.isIdentity();o&&(s.save(),s.transform(n.a,n.b,n.c,n.d,n.tx,n.ty)),Ie(s,a.shape),o&&s.restore()}return!0}class Re{constructor(e){this._warnedMaskTypes=new Set,this._canvasMaskStack=[],this._renderer=e}push(e,t,a){this._renderer.renderPipes.batch.break(a),a.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,a){this._renderer.renderPipes.batch.break(a),a.add({renderPipeId:"stencilMask",action:"popMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){if(e.action!=="pushMaskBegin"&&e.action!=="popMaskEnd")return;const t=this._renderer,a=t.canvasContext,n=a?.activeContext;if(!n)return;if(e.action==="popMaskEnd"){this._canvasMaskStack.pop()&&n.restore();return}e.inverse&&this._warnOnce("inverse","CanvasRenderer: inverse masks are not supported on Canvas2D; ignoring inverse flag.");const o=e.mask.mask;if(!(o instanceof qe)){this._warnOnce("nonGraphics","CanvasRenderer: only Graphics masks are supported in Canvas2D; skipping mask."),this._canvasMaskStack.push(!1);return}const r=o,i=r.context?.instructions;if(!i?.length){this._canvasMaskStack.push(!1);return}n.save(),a.setContextTransform(r.groupTransform,(t._roundPixels|r._roundPixels)===1),n.beginPath();let c=!1,h=!1;for(let l=0;l<i.length;l++){const u=i[l],m=u.action;if(m!=="fill"&&m!=="stroke")continue;const k=u.data?.path?.shapePath;if(!k?.shapePrimitives?.length)continue;const T=k.shapePrimitives;for(let C=0;C<T.length;C++){const B=T[C];if(!B?.shape)continue;const P=B.transform,H=P&&!P.isIdentity();H&&(n.save(),n.transform(P.a,P.b,P.c,P.d,P.tx,P.ty)),Ie(n,B.shape),h=ct(n,B.holes)||h,c=!0,H&&n.restore()}}if(!c){n.restore(),this._canvasMaskStack.push(!1);return}h?n.clip("evenodd"):n.clip(),this._canvasMaskStack.push(!0)}destroy(){this._renderer=null,this._warnedMaskTypes=null,this._canvasMaskStack=null}_warnOnce(e,t){this._warnedMaskTypes.has(e)||(this._warnedMaskTypes.add(e),Le(t))}}Re.extension={type:[S.CanvasPipes],name:"stencilMask"};const f="source-over";function lt(){const s=Se(),e=Object.create(null);return e.inherit=f,e.none=f,e.normal="source-over",e.add="lighter",e.multiply=s?"multiply":f,e.screen=s?"screen":f,e.overlay=s?"overlay":f,e.darken=s?"darken":f,e.lighten=s?"lighten":f,e["color-dodge"]=s?"color-dodge":f,e["color-burn"]=s?"color-burn":f,e["hard-light"]=s?"hard-light":f,e["soft-light"]=s?"soft-light":f,e.difference=s?"difference":f,e.exclusion=s?"exclusion":f,e.saturation=s?"saturation":f,e.color=s?"color":f,e.luminosity=s?"luminosity":f,e["linear-burn"]=s?"color-burn":f,e["linear-dodge"]=s?"color-dodge":f,e["linear-light"]=s?"hard-light":f,e["pin-light"]=s?"hard-light":f,e["vivid-light"]=s?"hard-light":f,e["hard-mix"]=f,e.negation=s?"difference":f,e["normal-npm"]=e.normal,e["add-npm"]=e.add,e["screen-npm"]=e.screen,e.erase="destination-out",e.subtract=f,e.divide=f,e.min=f,e.max=f,e}const ht=new O;class Ae{constructor(e){this.activeResolution=1,this.smoothProperty="imageSmoothingEnabled",this.blendModes=lt(),this._activeBlendMode="normal",this._projTransform=null,this._outerBlend=!1,this._warnedBlendModes=new Set,this._renderer=e}resolutionChange(e){this.activeResolution=e}init(){const e=this._renderer.background.alpha<1;if(this.rootContext=this._renderer.canvas.getContext("2d",{alpha:e}),this.activeContext=this.rootContext,this.activeResolution=this._renderer.resolution,!this.rootContext.imageSmoothingEnabled){const t=this.rootContext;t.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":t.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":t.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":t.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")}}setContextTransform(e,t,a,n){const o=n?O.IDENTITY:this._renderer.globalUniforms.globalUniformData?.worldTransformMatrix||O.IDENTITY;let r=ht;r.copyFrom(o),r.append(e);const i=this._projTransform,c=this.activeResolution;if(a=a||c,i){const h=O.shared;h.copyFrom(r),h.prepend(i),r=h}t?this.activeContext.setTransform(r.a*a,r.b*a,r.c*a,r.d*a,r.tx*c|0,r.ty*c|0):this.activeContext.setTransform(r.a*a,r.b*a,r.c*a,r.d*a,r.tx*c,r.ty*c)}clear(e,t){const a=this.activeContext,n=this._renderer;if(a.clearRect(0,0,n.width,n.height),e){const o=K.shared.setValue(e);a.globalAlpha=t??o.alpha,a.fillStyle=o.toHex(),a.fillRect(0,0,n.width,n.height),a.globalAlpha=1}}setBlendMode(e){if(this._activeBlendMode===e)return;this._activeBlendMode=e,this._outerBlend=!1;const t=this.blendModes[e];if(!t){this._warnedBlendModes.has(e)||(console.warn(`CanvasRenderer: blend mode "${e}" is not supported in Canvas2D; falling back to "source-over".`),this._warnedBlendModes.add(e)),this.activeContext.globalCompositeOperation="source-over";return}this.activeContext.globalCompositeOperation=t}destroy(){this.rootContext=null,this.activeContext=null,this._warnedBlendModes.clear()}}Ae.extension={type:[S.CanvasSystem],name:"canvasContext"};class Be{constructor(){this.maxTextures=16,this.maxBatchableTextures=16,this.maxUniformBindings=0}init(){}}Be.extension={type:[S.CanvasSystem],name:"limits"};const dt="#808080",te=new O,pt=new O,ut=new O,ue=new O;function ft(s,e,t){s.beginPath();for(let a=0;a<t.length;a+=3){const n=t[a]*2,o=t[a+1]*2,r=t[a+2]*2;s.moveTo(e[n],e[n+1]),s.lineTo(e[o],e[o+1]),s.lineTo(e[r],e[r+1]),s.closePath()}s.fill()}function gt(s){return`#${(s&16777215).toString(16).padStart(6,"0")}`}function mt(s,e,t,a,n,o){o=Math.max(0,Math.min(o,Math.min(a,n)/2)),s.moveTo(e+o,t),s.lineTo(e+a-o,t),s.quadraticCurveTo(e+a,t,e+a,t+o),s.lineTo(e+a,t+n-o),s.quadraticCurveTo(e+a,t+n,e+a-o,t+n),s.lineTo(e+o,t+n),s.quadraticCurveTo(e,t+n,e,t+n-o),s.lineTo(e,t+o),s.quadraticCurveTo(e,t,e+o,t)}function ae(s,e){switch(e.type){case"rectangle":{const t=e;s.rect(t.x,t.y,t.width,t.height);break}case"roundedRectangle":{const t=e;mt(s,t.x,t.y,t.width,t.height,t.radius);break}case"circle":{const t=e;s.arc(t.x,t.y,t.radius,0,Math.PI*2);break}case"ellipse":{const t=e;s.ellipse?s.ellipse(t.x,t.y,t.halfWidth,t.halfHeight,0,0,Math.PI*2):(s.save(),s.translate(t.x,t.y),s.scale(t.halfWidth,t.halfHeight),s.arc(0,0,1,0,Math.PI*2),s.restore());break}case"triangle":{const t=e;s.moveTo(t.x,t.y),s.lineTo(t.x2,t.y2),s.lineTo(t.x3,t.y3),s.closePath();break}default:{const t=e,a=t.points;if(!a?.length)break;s.moveTo(a[0],a[1]);for(let n=2;n<a.length;n+=2)s.lineTo(a[n],a[n+1]);t.closePath&&s.closePath();break}}}function vt(s,e){if(!e?.length)return!1;for(let t=0;t<e.length;t++){const a=e[t];if(!a?.shape)continue;const n=a.transform,o=n&&!n.isIdentity();o&&(s.save(),s.transform(n.a,n.b,n.c,n.d,n.tx,n.ty)),ae(s,a.shape),o&&s.restore()}return!0}function yt(s,e,t,a){const n=s.fill;if(n instanceof je){n.buildGradient();const r=n.texture;if(r){const i=d.getTintedPattern(r,e),c=t?ue.copyFrom(t).scale(r.source.pixelWidth,r.source.pixelHeight):ue.copyFrom(n.transform);return a&&!s.textureSpace&&c.append(a),d.applyPatternTransform(i,c),i}}if(n instanceof $e){const r=d.getTintedPattern(n.texture,e);return d.applyPatternTransform(r,n.transform),r}const o=s.texture;if(o&&o!==we.WHITE){if(!o.source.resource)return dt;const r=d.getTintedPattern(o,e),i=t?ue.copyFrom(t).scale(o.source.pixelWidth,o.source.pixelHeight):s.matrix;return d.applyPatternTransform(r,i),r}return gt(e)}class He{constructor(){this.shader=null}contextChange(e){}execute(e,t){const a=e.renderer,n=a.canvasContext,o=n.activeContext,r=t.groupTransform,i=a.globalUniforms.globalUniformData?.worldColor??4294967295,c=t.groupColorAlpha,h=(i>>>24&255)/255,l=(c>>>24&255)/255,u=a.filter?.alphaMultiplier??1,m=h*l*u;if(m<=0)return;const v=i&16777215,k=c&16777215,T=be(ne(k,v)),C=a._roundPixels|t._roundPixels;o.save(),n.setContextTransform(r,C===1),n.setBlendMode(t.groupBlendMode);const B=t.context.instructions;for(let P=0;P<B.length;P++){const H=B[P];if(H.action==="texture"){const g=H.data,y=g.image,x=y?d.getCanvasSource(y):null;if(!x)continue;const G=g.alpha*m;if(G<=0)continue;const N=ne(g.style,T);o.globalAlpha=G;let w=x;N!==16777215&&(w=d.getTintedCanvas({texture:y},N));const E=y.frame,_=y.source._resolution??y.source.resolution??1;let I=E.x*_,R=E.y*_;const z=E.width*_,q=E.height*_;w!==x&&(I=0,R=0);const D=g.transform,M=D&&!D.isIdentity(),p=y.rotate;M||p?(te.copyFrom(r),M&&te.append(D),p&&A.matrixAppendRotationInv(te,p,g.dx,g.dy,g.dw,g.dh),n.setContextTransform(te,C===1)):n.setContextTransform(r,C===1),o.drawImage(w,I,R,w===x?z:w.width,w===x?q:w.height,p?0:g.dx,p?0:g.dy,g.dw,g.dh),(M||p)&&n.setContextTransform(r,C===1);continue}const V=H.data,J=V?.path?.shapePath;if(!J?.shapePrimitives?.length)continue;const b=V.style,F=ne(b.color,T),W=b.alpha*m;if(W<=0)continue;const Q=H.action==="stroke";if(o.globalAlpha=W,Q){const g=b;o.lineWidth=g.width,o.lineCap=g.cap,o.lineJoin=g.join,o.miterLimit=g.miterLimit}const Y=J.shapePrimitives;if(!Q&&V.hole?.shapePath?.shapePrimitives?.length){const g=Y[Y.length-1];g.holes=V.hole.shapePath.shapePrimitives}for(let g=0;g<Y.length;g++){const y=Y[g];if(!y?.shape)continue;const x=y.transform,G=x&&!x.isIdentity(),N=b.texture&&b.texture!==we.WHITE,w=b.textureSpace==="global"?x:null,E=N?Ye(pt,b,y.shape,w):null,_=G?ut.copyFrom(r).append(x):r,I=yt(b,F,E,_);if(G&&(o.save(),o.transform(x.a,x.b,x.c,x.d,x.tx,x.ty)),Q){const R=b;if(R.alignment!==.5&&!R.pixelLine){const q=[],D=[],M=[];if(Ne[y.shape.type]?.build(y.shape,q)){const oe=y.shape.closePath??!0;Xe(q,R,!1,oe,D,M),o.fillStyle=I,ft(o,D,M)}else o.strokeStyle=I,o.beginPath(),ae(o,y.shape),o.stroke()}else o.strokeStyle=I,o.beginPath(),ae(o,y.shape),o.stroke()}else o.fillStyle=I,o.beginPath(),ae(o,y.shape),vt(o,y.holes)?o.fill("evenodd"):o.fill();G&&o.restore()}}o.restore()}destroy(){this.shader=null}}He.extension={type:[S.CanvasPipesAdaptor],name:"graphics"};class Ct{init(e,t){this._renderer=e,this._renderTargetSystem=t}initGpuRenderTarget(e){const t=e.colorTexture,{canvas:a,context:n}=this._ensureCanvas(t);return{canvas:a,context:n,width:a.width,height:a.height}}resizeGpuRenderTarget(e){const t=e.colorTexture,{canvas:a}=this._ensureCanvas(t);a.width=e.pixelWidth,a.height=e.pixelHeight}startRenderPass(e,t,a,n){const o=this._renderTargetSystem.getGpuRenderTarget(e);this._renderer.canvasContext.activeContext=o.context,this._renderer.canvasContext.activeResolution=e.resolution,t&&this.clear(e,t,a,n)}clear(e,t,a,n){const r=this._renderTargetSystem.getGpuRenderTarget(e).context,i=n||{x:0,y:0,width:e.pixelWidth,height:e.pixelHeight};if(r.setTransform(1,0,0,1,0,0),r.clearRect(i.x,i.y,i.width,i.height),a){const c=K.shared.setValue(a);c.alpha>0&&(r.globalAlpha=c.alpha,r.fillStyle=c.toHex(),r.fillRect(i.x,i.y,i.width,i.height),r.globalAlpha=1)}}finishRenderPass(){}copyToTexture(e,t,a,n,o){const i=this._renderTargetSystem.getGpuRenderTarget(e).canvas,c=t.source,{context:h}=this._ensureCanvas(c),l=o?.x??0,u=o?.y??0;return h.drawImage(i,a.x,a.y,n.width,n.height,l,u,n.width,n.height),c.update(),t}destroyGpuRenderTarget(e){}_ensureCanvas(e){let t=e.resource;(!t||!Ke.test(t))&&(t=U.get().createCanvas(e.pixelWidth,e.pixelHeight),e.resource=t),(t.width!==e.pixelWidth||t.height!==e.pixelHeight)&&(t.width=e.pixelWidth,t.height=e.pixelHeight);const a=t.getContext("2d");return{canvas:t,context:a}}}class We extends Je{constructor(e){super(e),this.adaptor=new Ct,this.adaptor.init(e,this)}}We.extension={type:[S.CanvasSystem],name:"renderTarget"};class De{constructor(e){}init(){}initSource(e){}generateCanvas(e){const t=U.get().createCanvas(),a=t.getContext("2d"),n=d.getCanvasSource(e);if(!n)return t;const o=e.frame,r=e.source._resolution??e.source.resolution??1,i=o.x*r,c=o.y*r,h=o.width*r,l=o.height*r;return t.width=Math.ceil(h),t.height=Math.ceil(l),a.drawImage(n,i,c,h,l,0,0,h,l),t}getPixels(e){const t=this.generateCanvas(e);return{pixels:t.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,t.width,t.height).data,width:t.width,height:t.height}}destroy(){}}De.extension={type:[S.CanvasSystem],name:"texture"};const xt=[...Ze,Ae,Be,De,We],Tt=[et,tt,nt,at,st,Re,ke,ot],Pt=[rt,He],Ue=[],Oe=[],Ge=[];se.handleByNamedList(S.CanvasSystem,Ue);se.handleByNamedList(S.CanvasPipes,Oe);se.handleByNamedList(S.CanvasPipesAdaptor,Ge);se.add(...xt,...Tt,...Pt);class St extends Qe{constructor(){const e={name:"canvas",type:ze.CANVAS,systems:Ue,renderPipes:Oe,renderPipeAdaptors:Ge};super(e)}}export{St as CanvasRenderer};
1
+ import{K as U,M as A,O as K,P as be,Q as ne,R as O,T as S,U as qe,y as Le,V as we,W as Ye,X as Ne,Y as Xe,Z as je,_ as $e,$ as Ke,a0 as Qe,a1 as ze,a2 as se}from"./index-3eymcnUu.js";import{R as Je,S as Ze,B as et,a as tt,b as nt,c as at,A as st,C as ot}from"./RenderTargetSystem-Cx8qJk_q.js";import"./Filter-Cb47-EZS.js";let $;function Me(s){const e=U.get().createCanvas(6,1),t=e.getContext("2d");return t.fillStyle=s,t.fillRect(0,0,6,1),e}function Se(){if($!==void 0)return $;try{const s=Me("#ff00ff"),e=Me("#ffff00"),a=U.get().createCanvas(6,1).getContext("2d");a.globalCompositeOperation="multiply",a.drawImage(s,0,0),a.drawImage(e,2,0);const n=a.getImageData(2,0,1,1);if(!n)$=!1;else{const o=n.data;$=o[0]===255&&o[1]===0&&o[2]===0}}catch{$=!1}return $}const d={canvas:null,convertTintToImage:!1,cacheStepsPerColorChannel:8,canUseMultiply:Se(),tintMethod:null,_canvasSourceCache:new WeakMap,_unpremultipliedCache:new WeakMap,getCanvasSource:s=>{const e=s.source,t=e?.resource;if(!t)return null;const a=e.alphaMode==="premultiplied-alpha",n=e.resourceWidth??e.pixelWidth,o=e.resourceHeight??e.pixelHeight,r=n!==e.pixelWidth||o!==e.pixelHeight;if(a){if((t instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&t instanceof OffscreenCanvas)&&!r)return t;const i=d._unpremultipliedCache.get(e);if(i?.resourceId===e._resourceId)return i.canvas}if(t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int8Array||t instanceof Uint16Array||t instanceof Int16Array||t instanceof Uint32Array||t instanceof Int32Array||t instanceof Float32Array||t instanceof ArrayBuffer){const i=d._canvasSourceCache.get(e);if(i?.resourceId===e._resourceId)return i.canvas;const c=U.get().createCanvas(e.pixelWidth,e.pixelHeight),h=c.getContext("2d"),l=h.createImageData(e.pixelWidth,e.pixelHeight),u=l.data,m=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(e.format==="bgra8unorm")for(let v=0;v<u.length&&v+3<m.length;v+=4)u[v]=m[v+2],u[v+1]=m[v+1],u[v+2]=m[v],u[v+3]=m[v+3];else u.set(m.subarray(0,u.length));return h.putImageData(l,0,0),d._canvasSourceCache.set(e,{canvas:c,resourceId:e._resourceId}),c}if(a){const i=U.get().createCanvas(e.pixelWidth,e.pixelHeight),c=i.getContext("2d",{willReadFrequently:!0});i.width=e.pixelWidth,i.height=e.pixelHeight,c.drawImage(t,0,0);const h=c.getImageData(0,0,i.width,i.height),l=h.data;for(let u=0;u<l.length;u+=4){const m=l[u+3];if(m>0){const v=255/m;l[u]=Math.min(255,l[u]*v+.5),l[u+1]=Math.min(255,l[u+1]*v+.5),l[u+2]=Math.min(255,l[u+2]*v+.5)}}return c.putImageData(h,0,0),d._unpremultipliedCache.set(e,{canvas:i,resourceId:e._resourceId}),i}if(r){const i=d._canvasSourceCache.get(e);if(i?.resourceId===e._resourceId)return i.canvas;const c=U.get().createCanvas(e.pixelWidth,e.pixelHeight),h=c.getContext("2d");return c.width=e.pixelWidth,c.height=e.pixelHeight,h.drawImage(t,0,0),d._canvasSourceCache.set(e,{canvas:c,resourceId:e._resourceId}),c}return t},getTintedCanvas:(s,e)=>{const t=s.texture,a=K.shared.setValue(e).toHex(),n=t.tintCache||(t.tintCache={}),o=n[a],r=t.source._resourceId;if(o?.tintId===r)return o;const i=o&&"getContext"in o?o:U.get().createCanvas();return d.tintMethod(t,e,i),i.tintId=r,n[a]=i,n[a]},getTintedPattern:(s,e)=>{const t=K.shared.setValue(e).toHex(),a=s.patternCache||(s.patternCache={}),n=s.source._resourceId;let o=a[t];return o?.tintId===n||(d.canvas||(d.canvas=U.get().createCanvas()),d.tintMethod(s,e,d.canvas),o=d.canvas.getContext("2d").createPattern(d.canvas,"repeat"),o.tintId=n,a[t]=o),o},applyPatternTransform:(s,e,t=!0)=>{if(!e)return;const a=s;if(!a.setTransform)return;const n=globalThis.DOMMatrix;if(!n)return;const o=new n([e.a,e.b,e.c,e.d,e.tx,e.ty]);a.setTransform(t?o.inverse():o)},tintWithMultiply:(s,e,t)=>{const a=t.getContext("2d"),n=s.frame.clone(),o=s.source._resolution??s.source.resolution??1,r=s.rotate;n.x*=o,n.y*=o,n.width*=o,n.height*=o;const i=A.isVertical(r),c=i?n.height:n.width,h=i?n.width:n.height;t.width=Math.ceil(c),t.height=Math.ceil(h),a.save(),a.fillStyle=K.shared.setValue(e).toHex(),a.fillRect(0,0,c,h),a.globalCompositeOperation="multiply";const l=d.getCanvasSource(s);if(!l){a.restore();return}r&&d._applyInverseRotation(a,r,n.width,n.height),a.drawImage(l,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a.globalCompositeOperation="destination-atop",a.drawImage(l,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a.restore()},tintWithOverlay:(s,e,t)=>{const a=t.getContext("2d"),n=s.frame.clone(),o=s.source._resolution??s.source.resolution??1,r=s.rotate;n.x*=o,n.y*=o,n.width*=o,n.height*=o;const i=A.isVertical(r),c=i?n.height:n.width,h=i?n.width:n.height;t.width=Math.ceil(c),t.height=Math.ceil(h),a.save(),a.globalCompositeOperation="copy",a.fillStyle=K.shared.setValue(e).toHex(),a.fillRect(0,0,c,h),a.globalCompositeOperation="destination-atop";const l=d.getCanvasSource(s);if(!l){a.restore();return}r&&d._applyInverseRotation(a,r,n.width,n.height),a.drawImage(l,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a.restore()},tintWithPerPixel:(s,e,t)=>{const a=t.getContext("2d"),n=s.frame.clone(),o=s.source._resolution??s.source.resolution??1,r=s.rotate;n.x*=o,n.y*=o,n.width*=o,n.height*=o;const i=A.isVertical(r),c=i?n.height:n.width,h=i?n.width:n.height;t.width=Math.ceil(c),t.height=Math.ceil(h),a.save(),a.globalCompositeOperation="copy";const l=d.getCanvasSource(s);if(!l){a.restore();return}r&&d._applyInverseRotation(a,r,n.width,n.height),a.drawImage(l,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a.restore();const u=e>>16&255,m=e>>8&255,v=e&255,k=a.getImageData(0,0,c,h),T=k.data;for(let C=0;C<T.length;C+=4)T[C]=T[C]*u/255,T[C+1]=T[C+1]*m/255,T[C+2]=T[C+2]*v/255;a.putImageData(k,0,0)},_applyInverseRotation:(s,e,t,a)=>{const n=A.inv(e),o=A.uX(n),r=A.uY(n),i=A.vX(n),c=A.vY(n),h=-Math.min(0,o*t,i*a,o*t+i*a),l=-Math.min(0,r*t,c*a,r*t+c*a);s.transform(o,r,i,c,h,l)}};d.tintMethod=d.canUseMultiply?d.tintWithMultiply:d.tintWithPerPixel;const fe=class L{static _getPatternRepeat(e,t){const a=e&&e!=="clamp-to-edge",n=t&&t!=="clamp-to-edge";return a&&n?"repeat":a?"repeat-x":n?"repeat-y":"no-repeat"}start(e,t,a){}execute(e,t){const a=t.elements;if(!a||!a.length)return;const n=e.renderer,o=n.canvasContext,r=o.activeContext;for(let i=0;i<a.length;i++){const c=a[i];if(!c.packAsQuad)continue;const h=c,l=h.texture,u=l?d.getCanvasSource(l):null;if(!u)continue;const m=l.source.style,v=o.smoothProperty,k=m.scaleMode!=="nearest";r[v]!==k&&(r[v]=k),o.setBlendMode(t.blendMode);const T=n.globalUniforms.globalUniformData?.worldColor??4294967295,C=h.color,B=(T>>>24&255)/255,P=(C>>>24&255)/255,H=n.filter?.alphaMultiplier??1,V=B*P*H;if(V<=0)continue;r.globalAlpha=V;const J=T&16777215,b=C&16777215,F=be(ne(b,J)),W=l.frame,Q=m.addressModeU??m.addressMode,Y=m.addressModeV??m.addressMode,g=L._getPatternRepeat(Q,Y),y=l.source._resolution??l.source.resolution??1,x=h.renderable?.renderGroup?.isCachedAsTexture,G=W.x*y,N=W.y*y,w=W.width*y,E=W.height*y,_=h.bounds,I=n.renderTarget.renderTarget.isRoot,R=_.minX,z=_.minY,q=_.maxX-_.minX,D=_.maxY-_.minY,M=l.rotate,p=l.uvs,oe=Math.min(p.x0,p.x1,p.x2,p.x3,p.y0,p.y1,p.y2,p.y3),Ee=Math.max(p.x0,p.x1,p.x2,p.x3,p.y0,p.y1,p.y2,p.y3),ge=g!=="no-repeat"&&(oe<0||Ee>1),re=M&&!(!ge&&(F!==16777215||M));re?(L._tempPatternMatrix.copyFrom(h.transform),A.matrixAppendRotationInv(L._tempPatternMatrix,M,R,z,q,D),o.setContextTransform(L._tempPatternMatrix,h.roundPixels===1,void 0,x&&I)):o.setContextTransform(h.transform,h.roundPixels===1,void 0,x&&I);const Z=re?0:R,ee=re?0:z,ie=q,ce=D;if(ge){let le=u;const X=F!==16777215&&!M,j=W.width<=l.source.width&&W.height<=l.source.height;X&&j&&(le=d.getTintedCanvas({texture:l},F));const he=r.createPattern(le,g);if(!he)continue;const me=ie,ve=ce;if(me===0||ve===0)continue;const ye=1/me,Ce=1/ve,xe=(p.x1-p.x0)*ye,Te=(p.y1-p.y0)*ye,Pe=(p.x3-p.x0)*Ce,_e=(p.y3-p.y0)*Ce,Ve=p.x0-xe*Z-Pe*ee,Fe=p.y0-Te*Z-_e*ee,de=l.source.pixelWidth,pe=l.source.pixelHeight;L._tempPatternMatrix.set(xe*de,Te*pe,Pe*de,_e*pe,Ve*de,Fe*pe),d.applyPatternTransform(he,L._tempPatternMatrix),r.fillStyle=he,r.fillRect(Z,ee,ie,ce)}else{const X=F!==16777215||M?d.getTintedCanvas({texture:l},F):u,j=X!==u;r.drawImage(X,j?0:G,j?0:N,j?X.width:w,j?X.height:E,Z,ee,ie,ce)}}}};fe._tempPatternMatrix=new O;fe.extension={type:[S.CanvasPipesAdaptor],name:"batch"};let rt=fe;class ke{constructor(e){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=e}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(e,t,a){this._renderer.renderPipes.batch.break(a);const n=this._colorStack;n[this._colorStackIndex]=n[this._colorStackIndex-1]&e.mask;const o=this._colorStack[this._colorStackIndex];o!==this._currentColor&&(this._currentColor=o,a.add({renderPipeId:"colorMask",colorMask:o,canBundle:!1})),this._colorStackIndex++}pop(e,t,a){this._renderer.renderPipes.batch.break(a);const n=this._colorStack;this._colorStackIndex--;const o=n[this._colorStackIndex-1];o!==this._currentColor&&(this._currentColor=o,a.add({renderPipeId:"colorMask",colorMask:o,canBundle:!1}))}execute(e){}destroy(){this._renderer=null,this._colorStack=null}}ke.extension={type:[S.CanvasPipes],name:"colorMask"};function it(s,e,t,a,n,o){o=Math.max(0,Math.min(o,Math.min(a,n)/2)),s.moveTo(e+o,t),s.lineTo(e+a-o,t),s.quadraticCurveTo(e+a,t,e+a,t+o),s.lineTo(e+a,t+n-o),s.quadraticCurveTo(e+a,t+n,e+a-o,t+n),s.lineTo(e+o,t+n),s.quadraticCurveTo(e,t+n,e,t+n-o),s.lineTo(e,t+o),s.quadraticCurveTo(e,t,e+o,t)}function Ie(s,e){switch(e.type){case"rectangle":{const t=e;s.rect(t.x,t.y,t.width,t.height);break}case"roundedRectangle":{const t=e;it(s,t.x,t.y,t.width,t.height,t.radius);break}case"circle":{const t=e;s.moveTo(t.x+t.radius,t.y),s.arc(t.x,t.y,t.radius,0,Math.PI*2);break}case"ellipse":{const t=e;s.ellipse?(s.moveTo(t.x+t.halfWidth,t.y),s.ellipse(t.x,t.y,t.halfWidth,t.halfHeight,0,0,Math.PI*2)):(s.save(),s.translate(t.x,t.y),s.scale(t.halfWidth,t.halfHeight),s.moveTo(1,0),s.arc(0,0,1,0,Math.PI*2),s.restore());break}case"triangle":{const t=e;s.moveTo(t.x,t.y),s.lineTo(t.x2,t.y2),s.lineTo(t.x3,t.y3),s.closePath();break}default:{const t=e,a=t.points;if(!a?.length)break;s.moveTo(a[0],a[1]);for(let n=2;n<a.length;n+=2)s.lineTo(a[n],a[n+1]);t.closePath&&s.closePath();break}}}function ct(s,e){if(!e?.length)return!1;for(let t=0;t<e.length;t++){const a=e[t];if(!a?.shape)continue;const n=a.transform,o=n&&!n.isIdentity();o&&(s.save(),s.transform(n.a,n.b,n.c,n.d,n.tx,n.ty)),Ie(s,a.shape),o&&s.restore()}return!0}class Re{constructor(e){this._warnedMaskTypes=new Set,this._canvasMaskStack=[],this._renderer=e}push(e,t,a){this._renderer.renderPipes.batch.break(a),a.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,a){this._renderer.renderPipes.batch.break(a),a.add({renderPipeId:"stencilMask",action:"popMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){if(e.action!=="pushMaskBegin"&&e.action!=="popMaskEnd")return;const t=this._renderer,a=t.canvasContext,n=a?.activeContext;if(!n)return;if(e.action==="popMaskEnd"){this._canvasMaskStack.pop()&&n.restore();return}e.inverse&&this._warnOnce("inverse","CanvasRenderer: inverse masks are not supported on Canvas2D; ignoring inverse flag.");const o=e.mask.mask;if(!(o instanceof qe)){this._warnOnce("nonGraphics","CanvasRenderer: only Graphics masks are supported in Canvas2D; skipping mask."),this._canvasMaskStack.push(!1);return}const r=o,i=r.context?.instructions;if(!i?.length){this._canvasMaskStack.push(!1);return}n.save(),a.setContextTransform(r.groupTransform,(t._roundPixels|r._roundPixels)===1),n.beginPath();let c=!1,h=!1;for(let l=0;l<i.length;l++){const u=i[l],m=u.action;if(m!=="fill"&&m!=="stroke")continue;const k=u.data?.path?.shapePath;if(!k?.shapePrimitives?.length)continue;const T=k.shapePrimitives;for(let C=0;C<T.length;C++){const B=T[C];if(!B?.shape)continue;const P=B.transform,H=P&&!P.isIdentity();H&&(n.save(),n.transform(P.a,P.b,P.c,P.d,P.tx,P.ty)),Ie(n,B.shape),h=ct(n,B.holes)||h,c=!0,H&&n.restore()}}if(!c){n.restore(),this._canvasMaskStack.push(!1);return}h?n.clip("evenodd"):n.clip(),this._canvasMaskStack.push(!0)}destroy(){this._renderer=null,this._warnedMaskTypes=null,this._canvasMaskStack=null}_warnOnce(e,t){this._warnedMaskTypes.has(e)||(this._warnedMaskTypes.add(e),Le(t))}}Re.extension={type:[S.CanvasPipes],name:"stencilMask"};const f="source-over";function lt(){const s=Se(),e=Object.create(null);return e.inherit=f,e.none=f,e.normal="source-over",e.add="lighter",e.multiply=s?"multiply":f,e.screen=s?"screen":f,e.overlay=s?"overlay":f,e.darken=s?"darken":f,e.lighten=s?"lighten":f,e["color-dodge"]=s?"color-dodge":f,e["color-burn"]=s?"color-burn":f,e["hard-light"]=s?"hard-light":f,e["soft-light"]=s?"soft-light":f,e.difference=s?"difference":f,e.exclusion=s?"exclusion":f,e.saturation=s?"saturation":f,e.color=s?"color":f,e.luminosity=s?"luminosity":f,e["linear-burn"]=s?"color-burn":f,e["linear-dodge"]=s?"color-dodge":f,e["linear-light"]=s?"hard-light":f,e["pin-light"]=s?"hard-light":f,e["vivid-light"]=s?"hard-light":f,e["hard-mix"]=f,e.negation=s?"difference":f,e["normal-npm"]=e.normal,e["add-npm"]=e.add,e["screen-npm"]=e.screen,e.erase="destination-out",e.subtract=f,e.divide=f,e.min=f,e.max=f,e}const ht=new O;class Ae{constructor(e){this.activeResolution=1,this.smoothProperty="imageSmoothingEnabled",this.blendModes=lt(),this._activeBlendMode="normal",this._projTransform=null,this._outerBlend=!1,this._warnedBlendModes=new Set,this._renderer=e}resolutionChange(e){this.activeResolution=e}init(){const e=this._renderer.background.alpha<1;if(this.rootContext=this._renderer.canvas.getContext("2d",{alpha:e}),this.activeContext=this.rootContext,this.activeResolution=this._renderer.resolution,!this.rootContext.imageSmoothingEnabled){const t=this.rootContext;t.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":t.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":t.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":t.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")}}setContextTransform(e,t,a,n){const o=n?O.IDENTITY:this._renderer.globalUniforms.globalUniformData?.worldTransformMatrix||O.IDENTITY;let r=ht;r.copyFrom(o),r.append(e);const i=this._projTransform,c=this.activeResolution;if(a=a||c,i){const h=O.shared;h.copyFrom(r),h.prepend(i),r=h}t?this.activeContext.setTransform(r.a*a,r.b*a,r.c*a,r.d*a,r.tx*c|0,r.ty*c|0):this.activeContext.setTransform(r.a*a,r.b*a,r.c*a,r.d*a,r.tx*c,r.ty*c)}clear(e,t){const a=this.activeContext,n=this._renderer;if(a.clearRect(0,0,n.width,n.height),e){const o=K.shared.setValue(e);a.globalAlpha=t??o.alpha,a.fillStyle=o.toHex(),a.fillRect(0,0,n.width,n.height),a.globalAlpha=1}}setBlendMode(e){if(this._activeBlendMode===e)return;this._activeBlendMode=e,this._outerBlend=!1;const t=this.blendModes[e];if(!t){this._warnedBlendModes.has(e)||(console.warn(`CanvasRenderer: blend mode "${e}" is not supported in Canvas2D; falling back to "source-over".`),this._warnedBlendModes.add(e)),this.activeContext.globalCompositeOperation="source-over";return}this.activeContext.globalCompositeOperation=t}destroy(){this.rootContext=null,this.activeContext=null,this._warnedBlendModes.clear()}}Ae.extension={type:[S.CanvasSystem],name:"canvasContext"};class Be{constructor(){this.maxTextures=16,this.maxBatchableTextures=16,this.maxUniformBindings=0}init(){}}Be.extension={type:[S.CanvasSystem],name:"limits"};const dt="#808080",te=new O,pt=new O,ut=new O,ue=new O;function ft(s,e,t){s.beginPath();for(let a=0;a<t.length;a+=3){const n=t[a]*2,o=t[a+1]*2,r=t[a+2]*2;s.moveTo(e[n],e[n+1]),s.lineTo(e[o],e[o+1]),s.lineTo(e[r],e[r+1]),s.closePath()}s.fill()}function gt(s){return`#${(s&16777215).toString(16).padStart(6,"0")}`}function mt(s,e,t,a,n,o){o=Math.max(0,Math.min(o,Math.min(a,n)/2)),s.moveTo(e+o,t),s.lineTo(e+a-o,t),s.quadraticCurveTo(e+a,t,e+a,t+o),s.lineTo(e+a,t+n-o),s.quadraticCurveTo(e+a,t+n,e+a-o,t+n),s.lineTo(e+o,t+n),s.quadraticCurveTo(e,t+n,e,t+n-o),s.lineTo(e,t+o),s.quadraticCurveTo(e,t,e+o,t)}function ae(s,e){switch(e.type){case"rectangle":{const t=e;s.rect(t.x,t.y,t.width,t.height);break}case"roundedRectangle":{const t=e;mt(s,t.x,t.y,t.width,t.height,t.radius);break}case"circle":{const t=e;s.arc(t.x,t.y,t.radius,0,Math.PI*2);break}case"ellipse":{const t=e;s.ellipse?s.ellipse(t.x,t.y,t.halfWidth,t.halfHeight,0,0,Math.PI*2):(s.save(),s.translate(t.x,t.y),s.scale(t.halfWidth,t.halfHeight),s.arc(0,0,1,0,Math.PI*2),s.restore());break}case"triangle":{const t=e;s.moveTo(t.x,t.y),s.lineTo(t.x2,t.y2),s.lineTo(t.x3,t.y3),s.closePath();break}default:{const t=e,a=t.points;if(!a?.length)break;s.moveTo(a[0],a[1]);for(let n=2;n<a.length;n+=2)s.lineTo(a[n],a[n+1]);t.closePath&&s.closePath();break}}}function vt(s,e){if(!e?.length)return!1;for(let t=0;t<e.length;t++){const a=e[t];if(!a?.shape)continue;const n=a.transform,o=n&&!n.isIdentity();o&&(s.save(),s.transform(n.a,n.b,n.c,n.d,n.tx,n.ty)),ae(s,a.shape),o&&s.restore()}return!0}function yt(s,e,t,a){const n=s.fill;if(n instanceof je){n.buildGradient();const r=n.texture;if(r){const i=d.getTintedPattern(r,e),c=t?ue.copyFrom(t).scale(r.source.pixelWidth,r.source.pixelHeight):ue.copyFrom(n.transform);return a&&!s.textureSpace&&c.append(a),d.applyPatternTransform(i,c),i}}if(n instanceof $e){const r=d.getTintedPattern(n.texture,e);return d.applyPatternTransform(r,n.transform),r}const o=s.texture;if(o&&o!==we.WHITE){if(!o.source.resource)return dt;const r=d.getTintedPattern(o,e),i=t?ue.copyFrom(t).scale(o.source.pixelWidth,o.source.pixelHeight):s.matrix;return d.applyPatternTransform(r,i),r}return gt(e)}class He{constructor(){this.shader=null}contextChange(e){}execute(e,t){const a=e.renderer,n=a.canvasContext,o=n.activeContext,r=t.groupTransform,i=a.globalUniforms.globalUniformData?.worldColor??4294967295,c=t.groupColorAlpha,h=(i>>>24&255)/255,l=(c>>>24&255)/255,u=a.filter?.alphaMultiplier??1,m=h*l*u;if(m<=0)return;const v=i&16777215,k=c&16777215,T=be(ne(k,v)),C=a._roundPixels|t._roundPixels;o.save(),n.setContextTransform(r,C===1),n.setBlendMode(t.groupBlendMode);const B=t.context.instructions;for(let P=0;P<B.length;P++){const H=B[P];if(H.action==="texture"){const g=H.data,y=g.image,x=y?d.getCanvasSource(y):null;if(!x)continue;const G=g.alpha*m;if(G<=0)continue;const N=ne(g.style,T);o.globalAlpha=G;let w=x;N!==16777215&&(w=d.getTintedCanvas({texture:y},N));const E=y.frame,_=y.source._resolution??y.source.resolution??1;let I=E.x*_,R=E.y*_;const z=E.width*_,q=E.height*_;w!==x&&(I=0,R=0);const D=g.transform,M=D&&!D.isIdentity(),p=y.rotate;M||p?(te.copyFrom(r),M&&te.append(D),p&&A.matrixAppendRotationInv(te,p,g.dx,g.dy,g.dw,g.dh),n.setContextTransform(te,C===1)):n.setContextTransform(r,C===1),o.drawImage(w,I,R,w===x?z:w.width,w===x?q:w.height,p?0:g.dx,p?0:g.dy,g.dw,g.dh),(M||p)&&n.setContextTransform(r,C===1);continue}const V=H.data,J=V?.path?.shapePath;if(!J?.shapePrimitives?.length)continue;const b=V.style,F=ne(b.color,T),W=b.alpha*m;if(W<=0)continue;const Q=H.action==="stroke";if(o.globalAlpha=W,Q){const g=b;o.lineWidth=g.width,o.lineCap=g.cap,o.lineJoin=g.join,o.miterLimit=g.miterLimit}const Y=J.shapePrimitives;if(!Q&&V.hole?.shapePath?.shapePrimitives?.length){const g=Y[Y.length-1];g.holes=V.hole.shapePath.shapePrimitives}for(let g=0;g<Y.length;g++){const y=Y[g];if(!y?.shape)continue;const x=y.transform,G=x&&!x.isIdentity(),N=b.texture&&b.texture!==we.WHITE,w=b.textureSpace==="global"?x:null,E=N?Ye(pt,b,y.shape,w):null,_=G?ut.copyFrom(r).append(x):r,I=yt(b,F,E,_);if(G&&(o.save(),o.transform(x.a,x.b,x.c,x.d,x.tx,x.ty)),Q){const R=b;if(R.alignment!==.5&&!R.pixelLine){const q=[],D=[],M=[];if(Ne[y.shape.type]?.build(y.shape,q)){const oe=y.shape.closePath??!0;Xe(q,R,!1,oe,D,M),o.fillStyle=I,ft(o,D,M)}else o.strokeStyle=I,o.beginPath(),ae(o,y.shape),o.stroke()}else o.strokeStyle=I,o.beginPath(),ae(o,y.shape),o.stroke()}else o.fillStyle=I,o.beginPath(),ae(o,y.shape),vt(o,y.holes)?o.fill("evenodd"):o.fill();G&&o.restore()}}o.restore()}destroy(){this.shader=null}}He.extension={type:[S.CanvasPipesAdaptor],name:"graphics"};class Ct{init(e,t){this._renderer=e,this._renderTargetSystem=t}initGpuRenderTarget(e){const t=e.colorTexture,{canvas:a,context:n}=this._ensureCanvas(t);return{canvas:a,context:n,width:a.width,height:a.height}}resizeGpuRenderTarget(e){const t=e.colorTexture,{canvas:a}=this._ensureCanvas(t);a.width=e.pixelWidth,a.height=e.pixelHeight}startRenderPass(e,t,a,n){const o=this._renderTargetSystem.getGpuRenderTarget(e);this._renderer.canvasContext.activeContext=o.context,this._renderer.canvasContext.activeResolution=e.resolution,t&&this.clear(e,t,a,n)}clear(e,t,a,n){const r=this._renderTargetSystem.getGpuRenderTarget(e).context,i=n||{x:0,y:0,width:e.pixelWidth,height:e.pixelHeight};if(r.setTransform(1,0,0,1,0,0),r.clearRect(i.x,i.y,i.width,i.height),a){const c=K.shared.setValue(a);c.alpha>0&&(r.globalAlpha=c.alpha,r.fillStyle=c.toHex(),r.fillRect(i.x,i.y,i.width,i.height),r.globalAlpha=1)}}finishRenderPass(){}copyToTexture(e,t,a,n,o){const i=this._renderTargetSystem.getGpuRenderTarget(e).canvas,c=t.source,{context:h}=this._ensureCanvas(c),l=o?.x??0,u=o?.y??0;return h.drawImage(i,a.x,a.y,n.width,n.height,l,u,n.width,n.height),c.update(),t}destroyGpuRenderTarget(e){}_ensureCanvas(e){let t=e.resource;(!t||!Ke.test(t))&&(t=U.get().createCanvas(e.pixelWidth,e.pixelHeight),e.resource=t),(t.width!==e.pixelWidth||t.height!==e.pixelHeight)&&(t.width=e.pixelWidth,t.height=e.pixelHeight);const a=t.getContext("2d");return{canvas:t,context:a}}}class We extends Je{constructor(e){super(e),this.adaptor=new Ct,this.adaptor.init(e,this)}}We.extension={type:[S.CanvasSystem],name:"renderTarget"};class De{constructor(e){}init(){}initSource(e){}generateCanvas(e){const t=U.get().createCanvas(),a=t.getContext("2d"),n=d.getCanvasSource(e);if(!n)return t;const o=e.frame,r=e.source._resolution??e.source.resolution??1,i=o.x*r,c=o.y*r,h=o.width*r,l=o.height*r;return t.width=Math.ceil(h),t.height=Math.ceil(l),a.drawImage(n,i,c,h,l,0,0,h,l),t}getPixels(e){const t=this.generateCanvas(e);return{pixels:t.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,t.width,t.height).data,width:t.width,height:t.height}}destroy(){}}De.extension={type:[S.CanvasSystem],name:"texture"};const xt=[...Ze,Ae,Be,De,We],Tt=[et,tt,nt,at,st,Re,ke,ot],Pt=[rt,He],Ue=[],Oe=[],Ge=[];se.handleByNamedList(S.CanvasSystem,Ue);se.handleByNamedList(S.CanvasPipes,Oe);se.handleByNamedList(S.CanvasPipesAdaptor,Ge);se.add(...xt,...Tt,...Pt);class St extends Qe{constructor(){const e={name:"canvas",type:ze.CANVAS,systems:Ue,renderPipes:Oe,renderPipeAdaptors:Ge};super(e)}}export{St as CanvasRenderer};
@@ -1 +1 @@
1
- import{S as n,r as u,G as o,u as f}from"./index-BJlwU-uQ.js";const s=class i extends n{constructor(e){e={...i.defaultOptions,...e},super(e),this.enabled=!0,this._state=u.for2d(),this.blendMode=e.blendMode,this.padding=e.padding,typeof e.antialias=="boolean"?this.antialias=e.antialias?"on":"off":this.antialias=e.antialias,this.resolution=e.resolution,this.blendRequired=e.blendRequired,this.clipToViewport=e.clipToViewport,this.addResource("uTexture",0,1),e.blendRequired&&this.addResource("uBackTexture",0,3)}apply(e,t,a,r){e.applyFilter(this,t,a,r)}get blendMode(){return this._state.blendMode}set blendMode(e){this._state.blendMode=e}static from(e){const{gpu:t,gl:a,...r}=e;let l,d;return t&&(l=o.from(t)),a&&(d=f.from(a)),new i({gpuProgram:l,glProgram:d,...r})}};s.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let b=s;export{b as F};
1
+ import{S as n,r as u,G as o,u as f}from"./index-3eymcnUu.js";const s=class i extends n{constructor(e){e={...i.defaultOptions,...e},super(e),this.enabled=!0,this._state=u.for2d(),this.blendMode=e.blendMode,this.padding=e.padding,typeof e.antialias=="boolean"?this.antialias=e.antialias?"on":"off":this.antialias=e.antialias,this.resolution=e.resolution,this.blendRequired=e.blendRequired,this.clipToViewport=e.clipToViewport,this.addResource("uTexture",0,1),e.blendRequired&&this.addResource("uBackTexture",0,3)}apply(e,t,a,r){e.applyFilter(this,t,a,r)}get blendMode(){return this._state.blendMode}set blendMode(e){this._state.blendMode=e}static from(e){const{gpu:t,gl:a,...r}=e;let l,d;return t&&(l=o.from(t)),a&&(d=f.from(a)),new i({gpuProgram:l,glProgram:d,...r})}};s.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let b=s;export{b as F};
@@ -1,4 +1,4 @@
1
- import{al as Ve,af as oe,R as m,G as Ne,u as je,r as $e,am as le,T as l,a2 as W,an as w,ao as qe,ap as z,aq as T,a1 as V,ar as de,as as Ke,V as f,A as g,ad as D,at as ue,y as ce,au as ee,av as he,aw as pe,ax as fe,ay as me,a7 as P,az as Ye,O as E,K as N,ae as y,aA as G,aB as Je,a5 as Xe,aC as Qe,ab as Ze,a3 as te,aD as re,aE as p,J as et,$ as O,aF as tt,aG as rt,aH as st,aI as nt}from"./index-BJlwU-uQ.js";import{F as at}from"./Filter-C5FD597y.js";var it=`in vec2 vMaskCoord;
1
+ import{al as Ve,af as oe,R as m,G as Ne,u as je,r as $e,am as le,T as l,a2 as W,an as w,ao as qe,ap as z,aq as T,a1 as V,ar as de,as as Ke,V as f,A as g,ad as D,at as ue,y as ce,au as ee,av as he,aw as pe,ax as fe,ay as me,a7 as P,az as Ye,O as E,K as N,ae as y,aA as G,aB as Je,a5 as Xe,aC as Qe,ab as Ze,a3 as te,aD as re,aE as p,J as et,$ as O,aF as tt,aG as rt,aH as st,aI as nt}from"./index-3eymcnUu.js";import{F as at}from"./Filter-Cb47-EZS.js";var it=`in vec2 vMaskCoord;
2
2
  in vec2 vTextureCoord;
3
3
 
4
4
  uniform sampler2D uTexture;