cortico-world-hands 0.20.40 → 0.20.41

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 (2) hide show
  1. package/dist/index.js +73 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1465,7 +1465,7 @@ var Hands = class {
1465
1465
  return res.body.toString("utf8");
1466
1466
  }
1467
1467
  /** 画板:画一笔。 */
1468
- async canvasStroke(points, color = "#111111", width = 4) {
1468
+ async canvasStroke(points, color = "#111111", width = 4, tool = "pen") {
1469
1469
  const cfg = this.cfg();
1470
1470
  const credential = this.readToken();
1471
1471
  const t = credential ? `t=${encodeURIComponent(credential)}` : "";
@@ -1473,6 +1473,22 @@ var Hands = class {
1473
1473
  const res = await post(this.port(cfg.handPort), `/canvas/stroke?${t}`, body, ACTION_TIMEOUT_MS);
1474
1474
  return res.body.toString("utf8");
1475
1475
  }
1476
+ /** 画板:油漆桶填充。 */
1477
+ async canvasFill(x, y, color = "#6BFFB0") {
1478
+ const cfg = this.cfg();
1479
+ const t = cfg.token ? `t=${encodeURIComponent(cfg.token)}` : "";
1480
+ const body = JSON.stringify({ x, y, color });
1481
+ const res = await post(this.port(cfg.handPort), `/canvas/fill?${t}`, body, ACTION_TIMEOUT_MS);
1482
+ return res.text;
1483
+ }
1484
+ /** 画板:写文字(支持中文)。 */
1485
+ async canvasText(text, x = 24, y = 72, size = 32, color = "#111111") {
1486
+ const cfg = this.cfg();
1487
+ const t = cfg.token ? `t=${encodeURIComponent(cfg.token)}` : "";
1488
+ const body = JSON.stringify({ text, x, y, size, color });
1489
+ const res = await post(this.port(cfg.handPort), `/canvas/text?${t}`, body, ACTION_TIMEOUT_MS);
1490
+ return res.text;
1491
+ }
1476
1492
  /** 画板:撤销 / 清空 / 保存 / 列表。 */
1477
1493
  async canvasOp(op) {
1478
1494
  const cfg = this.cfg();
@@ -1936,17 +1952,48 @@ var HANDS_TOOL_DECLS = [
1936
1952
  {
1937
1953
  name: "canvas_stroke",
1938
1954
  tags: ["act"],
1939
- description: "\u5728\u753B\u5E03\u4E0A\u753B\u4E00\u7B14\uFF1A\u7ED9\u4E00\u4E32\u5750\u6807\u70B9\u3001\u989C\u8272\u3001\u7C97\u7EC6\u3002\u60F3\u753B\u66F2\u7EBF\u5C31\u591A\u7ED9\u70B9\uFF0C\u6BCF\u7B14\u6700\u591A\u51E0\u5341\u4E2A\u70B9\uFF1B\u753B\u6B6A\u4E86\u5C31 canvas_undo\u3002",
1955
+ description: "\u5728\u753B\u5E03\u4E0A\u753B\u4E00\u7B14\uFF1A\u7ED9\u4E00\u4E32\u5750\u6807\u70B9\u3001\u989C\u8272\u3001\u7C97\u7EC6\u3002\u7EBF\u6761\u4F1A\u81EA\u52A8\u5E73\u6ED1\uFF08\u5706\u80FD\u753B\u5706\uFF09\uFF0C\u4E0D\u7528\u5BC6\u96C6\u70B9\u63CF\u3002tool=eraser \u65F6\u5F53\u6A61\u76AE\u3002",
1940
1956
  parameters: {
1941
1957
  type: "object",
1942
1958
  properties: {
1943
- points: { type: "array", description: "\u5750\u6807 [[x,y],[x,y],\u2026]\uFF0C\u539F\u70B9\u662F\u753B\u5E03\u5DE6\u4E0A\u89D2" },
1959
+ points: { type: "array", description: "\u5750\u6807 [[x,y],[x,y],\u2026]\uFF0C\u539F\u70B9\u662F\u753B\u5E03\u5DE6\u4E0A\u89D2\uFF1B\u753B\u5706\u7ED9 6\uFF5E10 \u4E2A\u70B9\u5C31\u591F" },
1944
1960
  color: { type: "string", description: "\u989C\u8272\uFF0C#RRGGBB" },
1945
- width: { type: "integer", description: "\u7B14\u753B\u7C97\u7EC6\uFF0C\u9ED8\u8BA4 4" }
1961
+ width: { type: "integer", description: "\u7B14\u753B\u7C97\u7EC6\uFF0C\u9ED8\u8BA4 4" },
1962
+ tool: { type: "string", enum: ["pen", "eraser"], description: "pen=\u753B\u7B14\uFF0Ceraser=\u6A61\u76AE" }
1946
1963
  },
1947
1964
  required: ["points"]
1948
1965
  }
1949
1966
  },
1967
+ {
1968
+ name: "canvas_fill",
1969
+ tags: ["act"],
1970
+ description: "\u6CB9\u6F06\u6876\uFF1A\u70B9\u4E00\u4E0B\u628A\u76F8\u8FDE\u7684\u540C\u8272\u533A\u57DF\u586B\u6210\u6307\u5B9A\u989C\u8272\uFF08\u7ED9 XY \u548C\u989C\u8272\uFF09\u3002",
1971
+ parameters: {
1972
+ type: "object",
1973
+ properties: {
1974
+ x: { type: "integer", description: "\u8981\u586B\u8272\u4F4D\u7F6E\u7684 x" },
1975
+ y: { type: "integer", description: "\u8981\u586B\u8272\u4F4D\u7F6E\u7684 y" },
1976
+ color: { type: "string", description: "\u989C\u8272 #RRGGBB" }
1977
+ },
1978
+ required: ["x", "y"]
1979
+ }
1980
+ },
1981
+ {
1982
+ name: "canvas_text",
1983
+ tags: ["act"],
1984
+ description: "\u5728\u753B\u5E03\u4E0A\u5199\u5B57\uFF08\u652F\u6301\u4E2D\u6587\uFF09\uFF0C\u6309\u57FA\u7EBF\u4F4D\u7F6E\u653E\u3002",
1985
+ parameters: {
1986
+ type: "object",
1987
+ properties: {
1988
+ text: { type: "string", description: "\u8981\u5199\u7684\u5B57" },
1989
+ x: { type: "integer", description: "\u5DE6\u4E0B\u8D77\u70B9 x\uFF0C\u9ED8\u8BA4 24" },
1990
+ y: { type: "integer", description: "\u57FA\u7EBF y\uFF0C\u9ED8\u8BA4 72" },
1991
+ size: { type: "integer", description: "\u5B57\u53F7\uFF0C\u9ED8\u8BA4 32" },
1992
+ color: { type: "string", description: "\u989C\u8272 #RRGGBB" }
1993
+ },
1994
+ required: ["text"]
1995
+ }
1996
+ },
1950
1997
  {
1951
1998
  name: "canvas_undo",
1952
1999
  tags: ["act"],
@@ -3127,6 +3174,10 @@ ${text.slice(0, 2200)}`;
3127
3174
  return await this.canvasNew(args);
3128
3175
  case "canvas_stroke":
3129
3176
  return await this.canvasStroke(args);
3177
+ case "canvas_fill":
3178
+ return await this.canvasFill(args);
3179
+ case "canvas_text":
3180
+ return await this.canvasText(args);
3130
3181
  case "canvas_undo":
3131
3182
  return await this.canvasSimple("undo");
3132
3183
  case "canvas_clear":
@@ -3391,7 +3442,24 @@ ${text.slice(0, 2200)}`;
3391
3442
  if (points.length === 0) return failed("points \u91CC\u6CA1\u6709\u5408\u6CD5\u5750\u6807\u3002");
3392
3443
  const color = typeof args.color === "string" && /^#[0-9a-fA-F]{6}$/.test(args.color) ? args.color : "#111111";
3393
3444
  const width = args.width === void 0 ? 4 : Math.max(1, Math.min(40, Math.round(Number(args.width))));
3394
- return await this.hands.canvasStroke(points, color, width);
3445
+ const tool = args.tool === "eraser" ? "eraser" : "pen";
3446
+ return await this.hands.canvasStroke(points, color, width, tool);
3447
+ }
3448
+ async canvasFill(args) {
3449
+ const x = Math.round(Number(args.x));
3450
+ const y = Math.round(Number(args.y));
3451
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return failed("\u8981 x\u3001y\u3002");
3452
+ const color = typeof args.color === "string" && /^#[0-9a-fA-F]{6}$/.test(args.color) ? args.color : "#6BFFB0";
3453
+ return await this.hands.canvasFill(x, y, color);
3454
+ }
3455
+ async canvasText(args) {
3456
+ const text = typeof args.text === "string" ? args.text.trim() : "";
3457
+ if (!text) return failed("\u8981 text\u3002");
3458
+ const x = args.x === void 0 ? 24 : Math.round(Number(args.x));
3459
+ const y = args.y === void 0 ? 72 : Math.round(Number(args.y));
3460
+ const size = args.size === void 0 ? 32 : Math.max(10, Math.min(120, Math.round(Number(args.size))));
3461
+ const color = typeof args.color === "string" && /^#[0-9a-fA-F]{6}$/.test(args.color) ? args.color : "#111111";
3462
+ return await this.hands.canvasText(text, x, y, size, color);
3395
3463
  }
3396
3464
  async canvasSimple(op) {
3397
3465
  return await this.hands.canvasOp(op);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-hands",
3
- "version": "0.20.40",
3
+ "version": "0.20.41",
4
4
  "type": "module",
5
5
  "description": "Cortico World: hands for the desktop pet — looks at the phone screen, then taps, swipes, pinches, drags, types and presses keys through whatever actuator the device actually has",
6
6
  "license": "MIT",