@showlotus/open-scriptable 0.1.19 → 0.1.20
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/README.md +5 -20
- package/dist/count-down.js +32 -1
- package/dist/dev.js +11 -1
- package/dist/hello-world.js +1 -1
- package/package.json +1 -1
- package/scriptable.d.ts +45 -0
package/README.md
CHANGED
|
@@ -3,17 +3,16 @@
|
|
|
3
3
|
## 使用示例
|
|
4
4
|
|
|
5
5
|
```javascript
|
|
6
|
-
//
|
|
7
|
-
const
|
|
6
|
+
// 配置
|
|
7
|
+
const config = {
|
|
8
8
|
name: 'World',
|
|
9
9
|
};
|
|
10
10
|
// 加载脚本
|
|
11
11
|
const url = 'https://cdn.jsdelivr.net/npm/@showlotus/open-scriptable@latest/dist/hello-world.js';
|
|
12
12
|
const code = await new Request(url).loadString();
|
|
13
13
|
// 执行脚本
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
await render();
|
|
14
|
+
const render = new Function(code)();
|
|
15
|
+
await render(config);
|
|
17
16
|
```
|
|
18
17
|
|
|
19
18
|
<div>
|
|
@@ -26,23 +25,9 @@ await render();
|
|
|
26
25
|
### 倒计时组件
|
|
27
26
|
|
|
28
27
|
```js
|
|
29
|
-
// 全局配置
|
|
30
|
-
const __GLOBAL_CONFIG__ = {
|
|
31
|
-
days: {
|
|
32
|
-
元旦: '2026-01-01',
|
|
33
|
-
春节: '2026-02-17',
|
|
34
|
-
清明节: '2026-04-04',
|
|
35
|
-
劳动节: '2026-05-01',
|
|
36
|
-
端午节: '2026-06-19',
|
|
37
|
-
国庆节: '2026-10-01',
|
|
38
|
-
中秋节: '2026-10-06',
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
28
|
const url = 'https://cdn.jsdelivr.net/npm/@showlotus/open-scriptable@latest/dist/count-down.js';
|
|
43
29
|
const code = await new Request(url).loadString();
|
|
44
|
-
const
|
|
45
|
-
const render = new Function(body);
|
|
30
|
+
const render = new Function(code)();
|
|
46
31
|
await render();
|
|
47
32
|
```
|
|
48
33
|
|
package/dist/count-down.js
CHANGED
|
@@ -1 +1,32 @@
|
|
|
1
|
-
function
|
|
1
|
+
return async function W(D) { var F; const h = { small: 3, medium: 3, large: 7 }; let l; config.runsInWidget ? l = config.widgetFamily || "small" : l = "large"; const y = h[l], f = (F = args.widgetParameter) == null ? void 0 : F.trim(), [C = "", M = "default"] = (f == null ? void 0 : f.split(",")) || [], p = { default: { backgroundColor: Color.dynamic(new Color("#FFFFFF"), new Color("#1c1c1c")), dateTitleTextColor: Color.dynamic(new Color("#000000"), new Color("#FFFFFF")), dateDescriptionTextColor: Color.dynamic(new Color("#979797"), new Color("#8e8e8e")), daysTextColor: Color.dynamic(new Color("#000000"), new Color("#FFFFFF")), daysUnitTextColor: Color.dynamic(new Color("#979797"), new Color("#8e8e8e")), lineColor: new Color("#8C8C8C", .2), emptyLineColor: new Color("#ffffff", 0) } }, k = w("theme", "default"), s = p[k] || p.default; function w(e, t) { return D[e] || t; } function E(e, t) { const o = new DateFormatter; return o.dateFormat = t, o.string(e); } function z(e) { const t = new Date; t.setHours(0, 0, 0, 0); const o = e.getTime() - t.getTime(); return Math.floor(o / (1e3 * 60 * 60 * 24)); } function L(e, t, o) { const n = new DrawContext; n.size = new Size(e, t), n.opaque = !1, n.respectScreenScale = !0, n.setFillColor(o); const r = new Path; return r.addRoundedRect(new Rect(0, 0, e, t), t / 2, t / 2), n.addPath(r), n.fillPath(), n.getImage(); } async function R() { const e = await Calendar.forEvents(), t = new Date, o = new Date; return o.setMonth(o.getMonth() + 6), (await CalendarEvent.between(t, o, e)).map(a => { const c = E(a.startDate, `yyyy/MM/dd${a.isAllDay ? "" : " HH:mm"}${l === "small" ? "" : ", EEEE"}`); return { name: a.title, date: a.startDate, dateStr: c, isEmpty: !1, type: a.calendar.title, color: "#" + a.calendar.color.hex }; }).filter(a => !(a.type === "中国大陆节假日" && /(|)/.test(a.name))).filter(a => C.trim().length > 0 ? C.split("/").includes(a.type) : !0); } const b = await R(), i = new ListWidget; i.backgroundColor = s.backgroundColor, i.spacing = 8, Object.entries(w("days", {}) || {}).map(([e, t]) => ({ name: e, date: t, isEmpty: !1 })).sort((e, t) => e.date > t.date ? 1 : -1).filter(e => { const [t, o, n] = e.date.split("-").map(Number), r = new Date; return t > r.getFullYear() ? !0 : t === r.getFullYear() ? o > r.getMonth() + 1 || o === r.getMonth() + 1 && n >= r.getDate() : !1; }).slice(0, y); for (let e = 0; e < y; e++) {
|
|
2
|
+
const t = b[e] || { name: "", date: "", isEmpty: !0 }, o = i.addStack();
|
|
3
|
+
o.layoutHorizontally();
|
|
4
|
+
const n = o.addStack();
|
|
5
|
+
n.layoutVertically(), n.spacing = 1;
|
|
6
|
+
const r = n.addStack();
|
|
7
|
+
r.layoutHorizontally(), r.spacing = 2;
|
|
8
|
+
const a = r.addText(t.name);
|
|
9
|
+
a.font = Font.mediumRoundedSystemFont(14), a.textColor = t.color ? new Color(t.color) : s.dateTitleTextColor;
|
|
10
|
+
const c = n.addStack();
|
|
11
|
+
c.layoutHorizontally(), c.spacing = 2;
|
|
12
|
+
const x = c.addText(t.isEmpty ? " " : t.dateStr);
|
|
13
|
+
x.font = Font.mediumRoundedSystemFont(10), x.textColor = s.dateDescriptionTextColor, o.addSpacer();
|
|
14
|
+
const m = o.addStack();
|
|
15
|
+
m.layoutHorizontally(), m.bottomAlignContent(), m.spacing = 2;
|
|
16
|
+
const A = t.isEmpty ? " " : z(t.date), u = m.addStack();
|
|
17
|
+
u.spacing = 2, u.topAlignContent();
|
|
18
|
+
const g = u.addText(A.toString());
|
|
19
|
+
g.font = Font.mediumRoundedSystemFont(24), g.textColor = t.color ? new Color(t.color) : s.daysTextColor, g.rightAlignText();
|
|
20
|
+
const S = m.addStack();
|
|
21
|
+
if (S.setPadding(0, 0, 4, 0), !t.isEmpty) {
|
|
22
|
+
const d = S.addText("天");
|
|
23
|
+
d.font = Font.mediumRoundedSystemFont(10), d.textColor = s.daysUnitTextColor, d.rightAlignText();
|
|
24
|
+
}
|
|
25
|
+
if (e < y - 1) {
|
|
26
|
+
const d = i.addStack();
|
|
27
|
+
d.layoutHorizontally(), d.centerAlignContent();
|
|
28
|
+
const H = l === "small" ? 126 : 305, I = 1;
|
|
29
|
+
let T = s.lineColor;
|
|
30
|
+
t.isEmpty && (T = s.emptyLineColor), d.addImage(L(H, I, T)).centerAlignImage();
|
|
31
|
+
}
|
|
32
|
+
} config.runsInWidget ? Script.setWidget(i) : config.runsInApp && (l === "small" ? i.presentSmall() : l === "medium" ? i.presentMedium() : l === "large" && i.presentLarge()), Script.complete(); }
|
package/dist/dev.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
return async function s() { async function o(e, r = 3e3) { const t = (async () => await new Request(e).loadString())(), c = (async () => { throw await new Promise(n => { Timer.schedule(r, !1, n); }), new Error(`Timeout after ${r} ms`); })(); return Promise.race([t, c]); } try {
|
|
2
|
+
const r = await o("http://192.168.5.2:3000/src/hello-world.ts");
|
|
3
|
+
await new Function(r)();
|
|
4
|
+
}
|
|
5
|
+
catch (e) {
|
|
6
|
+
console.error(e);
|
|
7
|
+
}
|
|
8
|
+
finally {
|
|
9
|
+
Script.complete();
|
|
10
|
+
} }
|
|
11
|
+
s();
|
package/dist/hello-world.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
return async function c(r) { let n; config.runsInWidget ? n = config.widgetFamily || "small" : n = "small"; function g(l, t) { return r[l] || t; } function i(l) { const t = new ListWidget; t.backgroundColor = Color.dynamic(new Color("#FFFFFF"), new Color("#1c1c1c")); const o = t.addText(`Hello, ${args.widgetParameter || g("name", "World")}`); return o.textColor = Color.dynamic(new Color("#000000"), new Color("#FFFFFF")), o.font = Font.boldSystemFont(16), o.centerAlignText(), console.log("config:"), console.log(JSON.stringify(config, null, 2)), t; } let e; config.runsInWidget ? (e = i(), Script.setWidget(e)) : (e = i(), n === "small" ? e.presentSmall() : n === "medium" ? e.presentMedium() : n === "large" && e.presentLarge()); }
|
package/package.json
CHANGED
package/scriptable.d.ts
CHANGED
|
@@ -389,16 +389,61 @@ declare global {
|
|
|
389
389
|
|
|
390
390
|
/**
|
|
391
391
|
* 颜色类
|
|
392
|
+
* 存储颜色数据,包括透明度
|
|
392
393
|
*/
|
|
393
394
|
class Color {
|
|
395
|
+
/** HEX 表示 */
|
|
396
|
+
readonly hex: string;
|
|
397
|
+
/** 红色分量 */
|
|
398
|
+
readonly red: number;
|
|
399
|
+
/** 绿色分量 */
|
|
400
|
+
readonly green: number;
|
|
401
|
+
/** 蓝色分量 */
|
|
402
|
+
readonly blue: number;
|
|
403
|
+
/** 透明度 */
|
|
404
|
+
readonly alpha: number;
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* 构造函数
|
|
408
|
+
* 使用十六进制值创建颜色,可选透明度
|
|
409
|
+
* @param hex 十六进制值,例如 #FF0000、#00ff0080、#00f、#ff(# 可选)
|
|
410
|
+
* @param alpha 透明度值(可选)
|
|
411
|
+
*/
|
|
394
412
|
constructor(hex: string, alpha?: number);
|
|
413
|
+
|
|
395
414
|
/** 创建动态颜色(支持亮色和暗色模式) */
|
|
396
415
|
static dynamic(lightColor: Color, darkColor: Color): Color;
|
|
416
|
+
|
|
417
|
+
/** 创建黑色 */
|
|
397
418
|
static black(): Color;
|
|
419
|
+
/** 创建深灰色 */
|
|
420
|
+
static darkGray(): Color;
|
|
421
|
+
/** 创建浅灰色 */
|
|
422
|
+
static lightGray(): Color;
|
|
423
|
+
/** 创建白色 */
|
|
398
424
|
static white(): Color;
|
|
425
|
+
/** 创建灰色 */
|
|
426
|
+
static gray(): Color;
|
|
427
|
+
/** 创建红色 */
|
|
399
428
|
static red(): Color;
|
|
429
|
+
/** 创建绿色 */
|
|
400
430
|
static green(): Color;
|
|
431
|
+
/** 创建蓝色 */
|
|
401
432
|
static blue(): Color;
|
|
433
|
+
/** 创建青色 */
|
|
434
|
+
static cyan(): Color;
|
|
435
|
+
/** 创建黄色 */
|
|
436
|
+
static yellow(): Color;
|
|
437
|
+
/** 创建洋红色 */
|
|
438
|
+
static magenta(): Color;
|
|
439
|
+
/** 创建橙色 */
|
|
440
|
+
static orange(): Color;
|
|
441
|
+
/** 创建紫色 */
|
|
442
|
+
static purple(): Color;
|
|
443
|
+
/** 创建棕色 */
|
|
444
|
+
static brown(): Color;
|
|
445
|
+
/** 创建透明色 */
|
|
446
|
+
static clear(): Color;
|
|
402
447
|
}
|
|
403
448
|
|
|
404
449
|
/**
|