cortico-world-hands 0.20.40 → 0.20.42
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.
- package/dist/index.js +79 -11
- 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();
|
|
@@ -1923,12 +1939,12 @@ var HANDS_TOOL_DECLS = [
|
|
|
1923
1939
|
{
|
|
1924
1940
|
name: "canvas_new",
|
|
1925
1941
|
tags: ["act"],
|
|
1926
|
-
description: "\u65B0\u5F00\u4E00\u5F20\u753B\u5E03\uFF08\u9ED8\u8BA4
|
|
1942
|
+
description: "\u65B0\u5F00\u4E00\u5F20\u753B\u5E03\uFF08\u9ED8\u8BA4 768\xD7768\uFF0C\u80CC\u666F\u900F\u660E\u6216\u767D\u8272\uFF09\uFF0C\u4F1A\u628A\u5F53\u524D\u8FD9\u5F20\u6E05\u6389\u3002",
|
|
1927
1943
|
parameters: {
|
|
1928
1944
|
type: "object",
|
|
1929
1945
|
properties: {
|
|
1930
|
-
w: { type: "integer", description: "\u5BBD\uFF0C\u9ED8\u8BA4
|
|
1931
|
-
h: { type: "integer", description: "\u9AD8\uFF0C\u9ED8\u8BA4
|
|
1946
|
+
w: { type: "integer", description: "\u5BBD\uFF0C\u9ED8\u8BA4 768" },
|
|
1947
|
+
h: { type: "integer", description: "\u9AD8\uFF0C\u9ED8\u8BA4 768" },
|
|
1932
1948
|
bg: { type: "string", description: "transparent \u6216 white" }
|
|
1933
1949
|
}
|
|
1934
1950
|
}
|
|
@@ -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\
|
|
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
|
|
1961
|
+
width: { type: "integer", description: "\u7B14\u753B\u7C97\u7EC6\uFF0C\u9ED8\u8BA4 2\uFF08\u7EC6\u4E00\u70B9\u66F4\u50CF\u624B\u7ED8\uFF09" },
|
|
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":
|
|
@@ -3372,8 +3423,8 @@ ${text.slice(0, 2200)}`;
|
|
|
3372
3423
|
}
|
|
3373
3424
|
}
|
|
3374
3425
|
async canvasNew(args) {
|
|
3375
|
-
const w = args.w === void 0 ?
|
|
3376
|
-
const h = args.h === void 0 ?
|
|
3426
|
+
const w = args.w === void 0 ? 768 : Math.max(64, Math.min(2048, Math.round(Number(args.w))));
|
|
3427
|
+
const h = args.h === void 0 ? 768 : Math.max(64, Math.min(2048, Math.round(Number(args.h))));
|
|
3377
3428
|
const bg = typeof args.bg === "string" && args.bg ? args.bg : "transparent";
|
|
3378
3429
|
return await this.hands.canvasNew(w, h, bg);
|
|
3379
3430
|
}
|
|
@@ -3390,8 +3441,25 @@ ${text.slice(0, 2200)}`;
|
|
|
3390
3441
|
}
|
|
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
|
-
const width = args.width === void 0 ?
|
|
3394
|
-
|
|
3444
|
+
const width = args.width === void 0 ? 2 : Math.max(1, Math.min(40, Math.round(Number(args.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.
|
|
3
|
+
"version": "0.20.42",
|
|
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",
|