@showlotus/open-scriptable 0.1.1 → 0.1.3
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 +57 -3
- package/dist/count-down.js +1 -0
- package/dist/hello-world.js +1 -1
- package/package.json +2 -1
- package/scriptable.d.ts +64 -30
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Open-source Scriptable scripts for iOS
|
|
1
|
+
# Open-source Scriptable scripts for iOS Widgets
|
|
2
2
|
|
|
3
3
|
## 使用示例
|
|
4
4
|
|
|
@@ -8,10 +8,64 @@ const globalConfig = {
|
|
|
8
8
|
name: 'World',
|
|
9
9
|
};
|
|
10
10
|
// 加载脚本
|
|
11
|
-
const url = 'https://cdn.jsdelivr.net/npm/@showlotus/open-scriptable@
|
|
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
14
|
eval(code);
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
<img src="./res/hello-world.png" alt="small" width="300">
|
|
18
|
+
|
|
19
|
+
## 组件列表
|
|
20
|
+
|
|
21
|
+
### 倒计时组件
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
// 全局配置
|
|
25
|
+
const globalConfig = {
|
|
26
|
+
days: [
|
|
27
|
+
{
|
|
28
|
+
name: '生日',
|
|
29
|
+
date: '2025-12-23',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: '元旦',
|
|
33
|
+
date: '2026-01-01',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: '除夕',
|
|
37
|
+
date: '2026-02-16',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const url = 'https://cdn.jsdelivr.net/npm/@showlotus/open-scriptable@latest/dist/count-down.js';
|
|
43
|
+
const code = await new Request(url).loadString();
|
|
44
|
+
eval(code);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
<div>
|
|
48
|
+
<img src="./res/count-down/small.png" alt="small" width="300">
|
|
49
|
+
<img src="./res/count-down/medium.png" alt="medium" width="300">
|
|
50
|
+
<img src="./res/count-down/large.png" alt="large" width="300">
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
## 开发
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# 安装依赖
|
|
57
|
+
pnpm install
|
|
58
|
+
|
|
59
|
+
# 启动开发服务器
|
|
60
|
+
pnpm dev
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
在 Scriptable 中加载 `http://192.168.5.6:3000/src/hello-world.ts` 脚本,即可看到效果。
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
// 加载脚本
|
|
67
|
+
const url = 'http://192.168.5.6:3000/src/hello-world.ts';
|
|
68
|
+
const code = await new Request(url).loadString();
|
|
69
|
+
// 执行脚本
|
|
70
|
+
eval(code);
|
|
71
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=config.widgetFamily||"small",e={small:3,medium:3,large:7}[t]||3;const o=new ListWidget;o.backgroundColor=Color.dynamic(new Color("#FFFFFF"),new Color("#1c1c1c")),o.spacing=10;const n=(globalConfig.days||[]).sort((t,e)=>t.date>e.date?1:-1).slice(0,e);if(n.length<e)for(let a=n.length;a<e;a++)n.push({name:" ",date:""});if(n.forEach(e=>{const n=o.addStack();n.layoutHorizontally(),n.spacing=10;const a=n.addStack();a.layoutVertically(),a.spacing=4;const l=a.addStack();l.layoutHorizontally(),l.spacing=6;const r=l.addText(e.name);r.font=Font.systemFont(16),r.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF"));const c=a.addStack();c.layoutHorizontally(),c.spacing=8;const i=function(t){const[e,o,n]=t.split("-");return e&&o&&n?new Date(parseInt(e),parseInt(o)-1,parseInt(n)):null}(e.date),s=c.addText(i?function(e){const o=["周日","周一","周二","周三","周四","周五","周六"][e.getDay()],n=(e.getMonth()+1).toString().padStart(2,"0"),a=e.getDate().toString().padStart(2,"0");return`${e.getFullYear()}/${n}/${a}${"small"===t?"":`, ${o}`}`}(i):" ");s.font=Font.regularRoundedSystemFont(10),s.textColor=Color.dynamic(new Color("#979797"),new Color("#8e8e8e")),n.addSpacer();const d=n.addStack();d.layoutHorizontally(),d.bottomAlignContent();const g=i?function(t){const e=new Date;if(t<e){const o=e.getTime()-t.getTime();return-Math.ceil(o/864e5)}const o=t.getTime()-e.getTime();return Math.ceil(o/864e5)}(i):" ",m=d.addText(g.toString());m.font=Font.boldRoundedSystemFont(24),m.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF")),m.rightAlignText()}),config.runsInWidget)Script.setWidget(o);else switch(args.widgetParameter){case"large":o.presentLarge();break;case"medium":o.presentMedium();break;default:o.presentSmall()}Script.complete();
|
package/dist/hello-world.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=new ListWidget;
|
|
1
|
+
const e=new ListWidget,t=new LinearGradient;t.colors=[new Color("#ffcb8e"),new Color("#6e35ff")],t.locations=[0,1],t.startPoint=new Point(0,0),t.endPoint=new Point(1,1),e.backgroundGradient=t;const n=e.addText(`Hello, ${globalConfig.name||"World"}`);if(n.font=Font.boldSystemFont(16),n.centerAlignText(),config.runsInWidget)Script.setWidget(e);else switch(args.widgetParameter){case"medium":e.presentMedium();break;case"large":e.presentLarge();break;default:e.presentSmall()}Script.complete();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@showlotus/open-scriptable",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Open-source Scriptable scripts for iOS Widgets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@8.10.0",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"lint-staged": "^16.2.6",
|
|
33
33
|
"prettier": "^3.6.2",
|
|
34
34
|
"terser": "^5.44.0",
|
|
35
|
+
"typescript": "^5.9.3",
|
|
35
36
|
"vite": "^7.1.12"
|
|
36
37
|
},
|
|
37
38
|
"lint-staged": {
|
package/scriptable.d.ts
CHANGED
|
@@ -7,36 +7,9 @@ declare global {
|
|
|
7
7
|
* 字体类
|
|
8
8
|
*/
|
|
9
9
|
class Font {
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
static italicSystemFont(size: number): Font;
|
|
14
|
-
/** 细体系统字体 */
|
|
15
|
-
static lightSystemFont(size: number): Font;
|
|
16
|
-
/** 中等系统字体 */
|
|
17
|
-
static mediumSystemFont(size: number): Font;
|
|
18
|
-
/** 常规系统字体 */
|
|
19
|
-
static regularSystemFont(size: number): Font;
|
|
20
|
-
/** 半粗体系统字体 */
|
|
21
|
-
static semiboldSystemFont(size: number): Font;
|
|
22
|
-
/** 系统字体 */
|
|
23
|
-
static systemFont(size: number): Font;
|
|
24
|
-
/** 超细系统字体 */
|
|
25
|
-
static ultraLightSystemFont(size: number): Font;
|
|
26
|
-
/** 极细系统字体 */
|
|
27
|
-
static thinSystemFont(size: number): Font;
|
|
28
|
-
/** 重磅系统字体 */
|
|
29
|
-
static heavySystemFont(size: number): Font;
|
|
30
|
-
/** 黑色系统字体 */
|
|
31
|
-
static blackSystemFont(size: number): Font;
|
|
32
|
-
/** 等宽系统字体 */
|
|
33
|
-
static monospacedSystemFont(size: number, weight: number): Font;
|
|
34
|
-
/** 等宽数字系统字体 */
|
|
35
|
-
static monospacedDigitSystemFont(size: number, weight: number): Font;
|
|
36
|
-
/** 圆角系统字体 */
|
|
37
|
-
static roundedSystemFont(size: number, weight: number): Font;
|
|
38
|
-
/** 自定义字体 */
|
|
39
|
-
static custom(name: string, size: number): Font;
|
|
10
|
+
/** 构造函数,创建自定义字体 */
|
|
11
|
+
constructor(name: string, size: number);
|
|
12
|
+
|
|
40
13
|
/** 大标题字体 */
|
|
41
14
|
static largeTitle(): Font;
|
|
42
15
|
/** 标题 1 字体 */
|
|
@@ -59,6 +32,67 @@ declare global {
|
|
|
59
32
|
static caption1(): Font;
|
|
60
33
|
/** 说明 2 字体 */
|
|
61
34
|
static caption2(): Font;
|
|
35
|
+
|
|
36
|
+
/** 系统字体 */
|
|
37
|
+
static systemFont(size: number): Font;
|
|
38
|
+
/** 超细系统字体 */
|
|
39
|
+
static ultraLightSystemFont(size: number): Font;
|
|
40
|
+
/** 极细系统字体 */
|
|
41
|
+
static thinSystemFont(size: number): Font;
|
|
42
|
+
/** 细体系统字体 */
|
|
43
|
+
static lightSystemFont(size: number): Font;
|
|
44
|
+
/** 常规系统字体 */
|
|
45
|
+
static regularSystemFont(size: number): Font;
|
|
46
|
+
/** 中等系统字体 */
|
|
47
|
+
static mediumSystemFont(size: number): Font;
|
|
48
|
+
/** 半粗体系统字体 */
|
|
49
|
+
static semiboldSystemFont(size: number): Font;
|
|
50
|
+
/** 粗体系统字体 */
|
|
51
|
+
static boldSystemFont(size: number): Font;
|
|
52
|
+
/** 重磅系统字体 */
|
|
53
|
+
static heavySystemFont(size: number): Font;
|
|
54
|
+
/** 黑色系统字体 */
|
|
55
|
+
static blackSystemFont(size: number): Font;
|
|
56
|
+
/** 斜体系统字体 */
|
|
57
|
+
static italicSystemFont(size: number): Font;
|
|
58
|
+
|
|
59
|
+
/** 超细等宽系统字体 */
|
|
60
|
+
static ultraLightMonospacedSystemFont(size: number): Font;
|
|
61
|
+
/** 极细等宽系统字体 */
|
|
62
|
+
static thinMonospacedSystemFont(size: number): Font;
|
|
63
|
+
/** 细体等宽系统字体 */
|
|
64
|
+
static lightMonospacedSystemFont(size: number): Font;
|
|
65
|
+
/** 常规等宽系统字体 */
|
|
66
|
+
static regularMonospacedSystemFont(size: number): Font;
|
|
67
|
+
/** 中等等宽系统字体 */
|
|
68
|
+
static mediumMonospacedSystemFont(size: number): Font;
|
|
69
|
+
/** 半粗体等宽系统字体 */
|
|
70
|
+
static semiboldMonospacedSystemFont(size: number): Font;
|
|
71
|
+
/** 粗体等宽系统字体 */
|
|
72
|
+
static boldMonospacedSystemFont(size: number): Font;
|
|
73
|
+
/** 重磅等宽系统字体 */
|
|
74
|
+
static heavyMonospacedSystemFont(size: number): Font;
|
|
75
|
+
/** 黑色等宽系统字体 */
|
|
76
|
+
static blackMonospacedSystemFont(size: number): Font;
|
|
77
|
+
|
|
78
|
+
/** 超细圆角系统字体 */
|
|
79
|
+
static ultraLightRoundedSystemFont(size: number): Font;
|
|
80
|
+
/** 极细圆角系统字体 */
|
|
81
|
+
static thinRoundedSystemFont(size: number): Font;
|
|
82
|
+
/** 细体圆角系统字体 */
|
|
83
|
+
static lightRoundedSystemFont(size: number): Font;
|
|
84
|
+
/** 常规圆角系统字体 */
|
|
85
|
+
static regularRoundedSystemFont(size: number): Font;
|
|
86
|
+
/** 中等圆角系统字体 */
|
|
87
|
+
static mediumRoundedSystemFont(size: number): Font;
|
|
88
|
+
/** 半粗体圆角系统字体 */
|
|
89
|
+
static semiboldRoundedSystemFont(size: number): Font;
|
|
90
|
+
/** 粗体圆角系统字体 */
|
|
91
|
+
static boldRoundedSystemFont(size: number): Font;
|
|
92
|
+
/** 重磅圆角系统字体 */
|
|
93
|
+
static heavyRoundedSystemFont(size: number): Font;
|
|
94
|
+
/** 黑色圆角系统字体 */
|
|
95
|
+
static blackRoundedSystemFont(size: number): Font;
|
|
62
96
|
}
|
|
63
97
|
|
|
64
98
|
/**
|