@showlotus/open-scriptable 0.1.18 → 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 CHANGED
@@ -3,17 +3,16 @@
3
3
  ## 使用示例
4
4
 
5
5
  ```javascript
6
- // 全局配置
7
- const __GLOBAL_CONFIG__ = {
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 body = `const __GLOBAL_CONFIG__ = ${JSON.stringify(__GLOBAL_CONFIG__)};\n${code}`;
15
- const render = new Function(body);
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 body = `const __GLOBAL_CONFIG__ = ${JSON.stringify(__GLOBAL_CONFIG__)};\n${code}`;
45
- const render = new Function(body);
30
+ const render = new Function(code)();
46
31
  await render();
47
32
  ```
48
33
 
@@ -1 +1,32 @@
1
- function I(r,y=""){try{return __GLOBAL_CONFIG__[r]}catch(d){return y}}function L(){let r;config.runsInWidget?r=config.widgetFamily||"small":r="large";const d={small:3,medium:3,large:7}[r];function S(t){const e=new Date;e.setHours(0,0,0,0);const o=t.getTime()-e.getTime();return Math.floor(o/(1e3*60*60*24))}function h(t){const o=["周日","周一","周二","周三","周四","周五","周六"][t.getDay()],n=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0");return`${t.getFullYear()}/${n}/${a}${r==="small"?"":`, ${o}`}`}function x(t){try{const[e,o,n]=t.split("-").map(Number);return new Date(e,o-1,n)}catch(e){return null}}function D(t,e,o){const n=new DrawContext;n.size=new Size(t,e),n.opaque=!1,n.respectScreenScale=!0,n.setFillColor(o);const a=new Path;return a.addRoundedRect(new Rect(0,0,t,e),e/2,e/2),n.addPath(a),n.fillPath(),n.getImage()}const l=new ListWidget;l.backgroundColor=Color.dynamic(new Color("#FFFFFF"),new Color("#1c1c1c")),l.spacing=8;const s=Object.entries(I("days",{})||{}).map(([t,e])=>({name:t,date:e,isEmpty:!1})).sort((t,e)=>t.date>e.date?1:-1).filter(t=>{const[e,o,n]=t.date.split("-").map(Number),a=new Date;return e>a.getFullYear()?!0:e===a.getFullYear()?o>a.getMonth()+1||o===a.getMonth()+1&&n>=a.getDate():!1}).slice(0,d);if(s.length>0&&s.length<d)for(let t=s.length;t<d;t++)s.push({name:"",date:"",isEmpty:!0});s.forEach((t,e)=>{const o=l.addStack();o.layoutHorizontally();const n=o.addStack();n.layoutVertically(),n.spacing=1;const a=n.addStack();a.layoutHorizontally(),a.spacing=2;const g=a.addText(t.name);g.font=Font.mediumRoundedSystemFont(14),g.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF"));const m=n.addStack();m.layoutHorizontally(),m.spacing=2;const p=t.isEmpty?null:x(t.date),C=m.addText(t.isEmpty?" ":h(p));C.font=Font.regularRoundedSystemFont(10),C.textColor=Color.dynamic(new Color("#979797"),new Color("#8e8e8e")),o.addSpacer();const c=o.addStack();c.layoutHorizontally(),c.bottomAlignContent(),c.spacing=2;const T=t.isEmpty?" ":S(p),f=c.addStack();f.spacing=2,f.topAlignContent();const u=f.addText(T.toString());u.font=Font.mediumRoundedSystemFont(24),u.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF")),u.rightAlignText();const F=c.addStack();if(F.setPadding(0,0,4,0),!t.isEmpty){const i=F.addText("天");i.font=Font.boldRoundedSystemFont(10),i.textColor=Color.dynamic(new Color("#979797"),new Color("#8e8e8e")),i.rightAlignText()}if(e<s.length-1){const i=l.addStack();i.layoutHorizontally(),i.centerAlignContent();const k=r==="small"?126:305,z=1;let w=new Color("#8C8C8C",.2);t.isEmpty&&(w=new Color("#ffffff",0)),i.addImage(D(k,z,w)).centerAlignImage()}}),config.runsInWidget?Script.setWidget(l):config.runsInApp&&(r==="small"?l.presentSmall():r==="medium"?l.presentMedium():r==="large"&&l.presentLarge()),Script.complete()}L();
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
- var n=(a,t,e)=>new Promise((o,c)=>{var s=r=>{try{i(e.next(r))}catch(l){c(l)}},u=r=>{try{i(e.throw(r))}catch(l){c(l)}},i=r=>r.done?o(r.value):Promise.resolve(r.value).then(s,u);i((e=e.apply(a,t)).next())});function w(){return n(this,null,function*(){function a(t,e=3e3){return n(this,null,function*(){const o=n(null,null,function*(){return yield new Request(t).loadString()}),c=n(null,null,function*(){throw yield new Promise(s=>{Timer.schedule(e,!1,s)}),new Error(`Timeout after ${e} ms`)});return Promise.race([o,c])})}try{const e=yield a("http://192.168.5.2:3000/src/hello-world.ts");yield new Function(e)()}catch(t){console.error(t)}finally{Script.complete()}})}w();
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();
@@ -1 +1 @@
1
- var s=(n,o,e)=>new Promise((g,i)=>{var l=t=>{try{r(e.next(t))}catch(c){i(c)}},d=t=>{try{r(e.throw(t))}catch(c){i(c)}},r=t=>t.done?g(t.value):Promise.resolve(t.value).then(l,d);r((e=e.apply(n,o)).next())});function f(n,o=""){try{return __GLOBAL_CONFIG__[n]}catch(e){return o}}function F(){return s(this,null,function*(){let n;config.runsInWidget?n=config.widgetFamily||"small":n="small";function o(g){const i=new ListWidget;i.backgroundColor=Color.dynamic(new Color("#FFFFFF"),new Color("#1c1c1c"));const l=i.addText(`Hello, ${f("name","World")}`);return l.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF")),l.font=Font.boldSystemFont(16),l.centerAlignText(),console.log("config:"),console.log(JSON.stringify(config,null,2)),i}let e;return config.runsInWidget?(e=o(),Script.setWidget(e)):(e=o(),n==="small"?e.presentSmall():n==="medium"?e.presentMedium():n==="large"&&e.presentLarge()),e})}F();
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@showlotus/open-scriptable",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "Open-source Scriptable scripts for iOS Widgets",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@8.10.0",
@@ -8,11 +8,6 @@
8
8
  "type": "git",
9
9
  "url": "https://github.com/showlotus/open-scriptable"
10
10
  },
11
- "exports": {
12
- "./count-down": "./dist/count-down.js",
13
- "./hello-world": "./dist/hello-world.js",
14
- "./dev": "./dist/dev.js"
15
- },
16
11
  "files": [
17
12
  "dist",
18
13
  "*.d.ts"
@@ -51,6 +46,7 @@
51
46
  "scripts": {
52
47
  "dev": "vite",
53
48
  "build": "vite build",
54
- "lint-staged": "lint-staged"
49
+ "lint-staged": "lint-staged",
50
+ "release": "node scripts/release.js"
55
51
  }
56
52
  }
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
  /**