@showlotus/open-scriptable 0.1.1 → 0.1.2

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 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@0.1.0/dist/hello-world.js';
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
- <!-- ![demo.png](./res/demo.png) -->
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("#000000")),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.systemFont(9),s.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF")),n.addSpacer();const d=n.addStack();d.layoutVertically(),d.spacing=2;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):" ",F=d.addText(g.toString());F.font=Font.boldSystemFont(24),F.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF")),F.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();
@@ -1 +1 @@
1
- const e=new ListWidget;if(e.addText(`Hello, ${globalConfig.name||"World"}!`).centerAlignText(),e.setPadding(16,16,16,16),e.backgroundColor=Color.dynamic(new Color("#FFFFFF"),new Color("#1f1f23")),config.runsInWidget)Script.setWidget(e);else switch(args.widgetParameter){case"medium":e.presentMedium();break;case"large":e.presentLarge();break;default:e.presentSmall()}Script.complete();
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.1",
3
+ "version": "0.1.2",
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": {