@showlotus/open-scriptable 0.1.5 → 0.1.7

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
@@ -4,7 +4,7 @@
4
4
 
5
5
  ```javascript
6
6
  // 全局配置
7
- const globalConfig = {
7
+ const __GLOBAL_CONFIG__ = {
8
8
  name: 'World',
9
9
  };
10
10
  // 加载脚本
@@ -14,7 +14,7 @@ const code = await new Request(url).loadString();
14
14
  eval(code);
15
15
  ```
16
16
 
17
- <img src="./res/hello-world.png" alt="small" width="300">
17
+ <img src="./res/hello-world.jpeg" alt="small" width="300">
18
18
 
19
19
  ## 组件列表
20
20
 
@@ -22,21 +22,16 @@ eval(code);
22
22
 
23
23
  ```js
24
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
- ],
25
+ const __GLOBAL_CONFIG__ = {
26
+ days: {
27
+ 元旦: '2026-01-01',
28
+ 春节: '2026-02-17',
29
+ 清明节: '2026-04-04',
30
+ 劳动节: '2026-05-01',
31
+ 端午节: '2026-06-19',
32
+ 国庆节: '2026-10-01',
33
+ 中秋节: '2026-10-06',
34
+ },
40
35
  };
41
36
 
42
37
  const url = 'https://cdn.jsdelivr.net/npm/@showlotus/open-scriptable@latest/dist/count-down.js';
@@ -45,8 +40,8 @@ eval(code);
45
40
  ```
46
41
 
47
42
  <div>
48
- <img src="./res/count-down/light.png" alt="light" width="300">
49
- <img src="./res/count-down/dark.png" alt="dark" width="300">
43
+ <img src="./res/count-down/light.jpeg" alt="light" width="300">
44
+ <img src="./res/count-down/dark.jpeg" alt="dark" width="300">
50
45
  </div>
51
46
 
52
47
  ## 开发
@@ -1 +1 @@
1
- const t=config.widgetFamily||"small",o={small:3,medium:3,large:7}[t]||3;const e=new ListWidget;e.backgroundColor=Color.dynamic(new Color("#FFFFFF"),new Color("#1c1c1c")),e.spacing=8;const n=(globalConfig.days||[]).sort((t,o)=>t.date>o.date?1:-1).slice(0,o);if(n.length<o)for(let a=n.length;a<o;a++)n.push({name:" ",date:""});if(n.forEach((o,a)=>{const l=0===o.name.trim().length,r=e.addStack();r.layoutHorizontally();const i=r.addStack();i.layoutVertically(),i.spacing=1;const d=i.addStack();d.layoutHorizontally(),d.spacing=2;const c=d.addText(o.name);c.font=Font.systemFont(16),c.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF"));const s=i.addStack();s.layoutHorizontally(),s.spacing=2;const g=l?null:function(t){const[o,e,n]=t.split("-");return o&&e&&n?new Date(parseInt(o),parseInt(e)-1,parseInt(n)):null}(o.date),F=s.addText(l?" ":function(o){const e=["周日","周一","周二","周三","周四","周五","周六"][o.getDay()],n=(o.getMonth()+1).toString().padStart(2,"0"),a=o.getDate().toString().padStart(2,"0");return`${o.getFullYear()}/${n}/${a}${"small"===t?"":`, ${e}`}`}(g));F.font=Font.regularRoundedSystemFont(9),F.textColor=Color.dynamic(new Color("#979797"),new Color("#8e8e8e")),r.addSpacer();const m=r.addStack();m.layoutHorizontally(),m.bottomAlignContent(),m.spacing=2;const u=l?" ":function(t){const o=new Date;if(t<o){const e=o.getTime()-t.getTime();return-Math.ceil(e/864e5)}const e=t.getTime()-o.getTime();return Math.ceil(e/864e5)}(g),C=m.addStack();C.spacing=2,C.topAlignContent();const y=C.addText(u.toString());y.font=Font.boldRoundedSystemFont(22),y.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF")),y.rightAlignText();const p=m.addStack();if(p.setPadding(0,0,4,0),!l){const t=p.addText("天");t.font=Font.boldRoundedSystemFont(10),t.textColor=Color.dynamic(new Color("#979797"),new Color("#8e8e8e")),t.rightAlignText()}if(a<n.length-1){const o=e.addStack();o.layoutHorizontally(),o.setPadding(0,0,0,0),o.size=new Size("small"===t?126:306,1),o.borderWidth=1,o.borderColor=l?new Color("#FFFFFF",0):Color.dynamic(new Color("#E5E5E5"),new Color("#333333")),o.cornerRadius=1}}),config.runsInWidget)Script.setWidget(e);else switch(args.widgetParameter){case"large":e.presentLarge();break;case"medium":e.presentMedium();break;default:e.presentSmall()}Script.complete();
1
+ let t;t=config.runsInWidget?config.widgetFamily||"small":"large";const o={small:3,medium:3,large:7}[t];const e=new ListWidget;e.useDefaultPadding(),e.backgroundColor=Color.dynamic(new Color("#FFFFFF"),new Color("#1c1c1c")),e.spacing=8;const n=Object.entries(__IS_DEV__?{"昨天":"2025-11-06","今天":"2025-11-07","元旦":"2026-01-01","春节":"2026-02-17","清明节":"2026-04-04","劳动节":"2026-05-01","端午节":"2026-06-19","国庆节":"2026-10-01","中秋节":"2026-10-06"}:__GLOBAL_CONFIG__.days||{}).map(([t,o])=>({name:t,date:o})).sort((t,o)=>t.date>o.date?1:-1).filter(t=>{const[o,e,n]=t.date.split("-").map(Number),a=new Date;return o>a.getFullYear()||o===a.getFullYear()&&(e>a.getMonth()+1||e===a.getMonth()+1&&n>=a.getDate())}).slice(0,o);if(n.length<o)for(let a=n.length;a<o;a++)n.push({name:"",date:"",isEmpty:!0});n.forEach((o,a)=>{const l=e.addStack();l.layoutHorizontally();const r=l.addStack();r.layoutVertically(),r.spacing=1;const i=r.addStack();i.layoutHorizontally(),i.spacing=2;const d=i.addText(o.name);d.font=Font.systemFont(16),d.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF"));const s=r.addStack();s.layoutHorizontally(),s.spacing=2;const c=o.isEmpty?null:function(t){try{const[o,e,n]=t.split("-").map(Number);return new Date(o,e-1,n)}catch(o){return null}}(o.date),g=s.addText(o.isEmpty?" ":function(o){const e=["周日","周一","周二","周三","周四","周五","周六"][o.getDay()],n=(o.getMonth()+1).toString().padStart(2,"0"),a=o.getDate().toString().padStart(2,"0");return`${o.getFullYear()}/${n}/${a}${"small"===t?"":`, ${e}`}`}(c));g.font=Font.regularRoundedSystemFont(9),g.textColor=Color.dynamic(new Color("#979797"),new Color("#8e8e8e")),l.addSpacer();const m=l.addStack();m.layoutHorizontally(),m.bottomAlignContent(),m.spacing=2;const u=o.isEmpty?" ":function(t){const o=new Date;o.setHours(0,0,0,0);const e=t.getTime()-o.getTime();return Math.floor(e/864e5)}(c),F=m.addStack();F.spacing=2,F.topAlignContent();const y=F.addText(u.toString());y.font=Font.boldRoundedSystemFont(22),y.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF")),y.rightAlignText();const p=m.addStack();if(p.setPadding(0,0,4,0),!o.isEmpty){const t=p.addText("天");t.font=Font.boldRoundedSystemFont(10),t.textColor=Color.dynamic(new Color("#979797"),new Color("#8e8e8e")),t.rightAlignText()}if(a<n.length-1){const n=e.addStack();n.layoutHorizontally(),n.setPadding(0,0,0,0),n.size=new Size("small"===t?126:306,1),n.borderWidth=1,n.borderColor=o.isEmpty?new Color("#FFFFFF",0):Color.dynamic(new Color("#E5E5E5"),new Color("#333333")),n.cornerRadius=1}}),config.runsInWidget?Script.setWidget(e):config.runsInApp&&("small"===t?e.presentSmall():"medium"===t?e.presentMedium():"large"===t&&e.presentLarge()),Script.complete();
@@ -1 +1 @@
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();
1
+ let e;e=config.runsInWidget&&config.widgetFamily||"small";const n=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),n.backgroundGradient=t;const o=n.addText(`Hello, ${__GLOBAL_CONFIG__.name||"World"}`);o.font=Font.boldSystemFont(16),o.textColor=Color.dynamic(new Color("#FFFFFF"),new Color("#000000")),o.centerAlignText(),config.runsInWidget?Script.setWidget(n):"small"===e?n.presentSmall():"medium"===e?n.presentMedium():"large"===e&&n.presentLarge(),Script.complete();
package/globalconfig.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export {};
2
2
 
3
3
  declare global {
4
- const globalConfig: any;
4
+ const __GLOBAL_CONFIG__: any;
5
+ const __IS_DEV__: boolean;
5
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@showlotus/open-scriptable",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Open-source Scriptable scripts for iOS Widgets",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@8.10.0",