@showlotus/open-scriptable 0.1.26-alpha.2 → 0.1.26-alpha.4

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.
@@ -1,34 +1,34 @@
1
- return async function G(H = {}) { let c; config.runsInWidget ? c = config.widgetFamily || "small" : c = "large"; const M = { single: "single", double: "double", 单列: "single", 双列: "double" }, g = { 透明: "transparent", transparent: "transparent" }; function f(e) { const t = e?.trim().toLowerCase(); return t ? M[t] : void 0; } const U = args.widgetParameter?.trim().split(/,|,/).map(e => e.trim()).filter(Boolean) || [], I = ["calendarTypes", "theme", "layout"], u = {}, k = []; for (const e of U) {
1
+ return async function G(H = {}) { let l; config.runsInWidget ? l = config.widgetFamily || "small" : l = "large"; const M = { single: "single", double: "double", 单列: "single", 双列: "double" }, g = { 透明: "transparent", transparent: "transparent" }; function f(e) { const t = e?.trim().toLowerCase(); return t ? M[t] : void 0; } const U = args.widgetParameter?.trim().split(/,|,/).map(e => e.trim()).filter(Boolean) || [], v = ["calendarTypes", "theme", "layout"], u = {}, h = []; for (const e of U) {
2
2
  const t = e.indexOf("=");
3
3
  if (t > 0) {
4
- const o = e.slice(0, t).trim().toLowerCase(), a = I.find(n => n.toLowerCase() === o), l = e.slice(t + 1).trim();
4
+ const o = e.slice(0, t).trim().toLowerCase(), a = v.find(n => n.toLowerCase() === o), s = e.slice(t + 1).trim();
5
5
  if (a) {
6
- const n = a === "layout" ? f(l) : g[l.trim().toLowerCase()];
7
- u[a] = n || l;
6
+ const n = a === "layout" ? f(s) : g[s.trim().toLowerCase()];
7
+ u[a] = n || s;
8
8
  }
9
9
  }
10
10
  else
11
- f(e) !== void 0 ? u.layout = f(e) : g[e.trim().toLowerCase()] ? u.theme = g[e.trim().toLowerCase()] : k.push(e);
12
- } const C = { ...H, ...u }; function v(e, t) { return C[e] || t; } const D = u.calendarTypes || k.join("/") || C.calendarTypes || "", p = (f(C.layout) ?? "single") === "double" && c !== "small", w = (p ? { small: 3, medium: 6, large: 14 } : { small: 3, medium: 3, large: 7 })[c], E = { 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) }, L = { default: E, transparent: { ...E, backgroundColor: new Color("#000000", 0) } }, b = v("theme", "default"), d = L[b] || L.default; function R(e, t) { const o = new DateFormatter; return o.dateFormat = t, o.string(e); } function A(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 K(e) { return `calshow:${Math.floor(e.getTime() / 1e3) - 978307200}`; } async function P() { const e = await Calendar.forEvents(), t = new Date, o = new Date; return o.setMonth(o.getMonth() + 12), (await CalendarEvent.between(t, o, e)).map(n => { const s = c === "small" ? "yyyy/MM/dd" : p ? "yyyy/MM/dd EEEE" : `yyyy/MM/dd EEEE${n.isAllDay ? "" : " HH:mm"}`, i = R(n.startDate, s); return { name: n.title, date: n.startDate, dateStr: i, isEmpty: !1, type: n.calendar.title, color: "#" + n.calendar.color.hex, eventUrl: `x-apple-calevent://${n.identifier.replace(/:/g, "/")}`, calshowUrl: K(n.startDate) }; }).filter(n => !(n.type === "中国大陆节假日" && /(|)/.test(n.name))).filter(n => D.trim().length > 0 ? D.split("/").includes(n.type) : !0); } const W = await P(), r = new ListWidget; r.backgroundColor = d.backgroundColor, b === "transparent" && (r.backgroundStyle = "transparent"), r.spacing = 8; function S(e) { return W[e] || { name: "", date: "", isEmpty: !0, eventUrl: "", calshowUrl: "" }; } function T(e, t) { const o = e.addStack(); o.layoutVertically(), o.spacing = 1, t.eventUrl && (o.url = t.eventUrl); const a = o.addStack(); a.layoutHorizontally(), a.spacing = 2; const l = a.addText(t.name); l.font = Font.mediumRoundedSystemFont(14), l.textColor = t.color ? new Color(t.color) : d.dateTitleTextColor; const n = o.addStack(); n.layoutHorizontally(), n.spacing = 2; const s = n.addText(t.isEmpty ? " " : t.dateStr); s.font = Font.mediumRoundedSystemFont(10), s.textColor = d.dateDescriptionTextColor, e.addSpacer(); const i = e.addStack(); i.layoutHorizontally(), i.bottomAlignContent(), i.spacing = 2; const m = t.isEmpty ? " " : A(t.date), y = i.addStack(); y.spacing = 2, y.topAlignContent(); const x = y.addText(m.toString()); x.font = Font.mediumRoundedSystemFont(24), x.textColor = t.color ? new Color(t.color) : d.daysTextColor, x.rightAlignText(); const z = i.addStack(); if (z.setPadding(0, 0, 4, 0), !t.isEmpty) {
13
- const h = z.addText("天");
14
- h.font = Font.mediumRoundedSystemFont(10), h.textColor = d.daysUnitTextColor, h.rightAlignText();
15
- } } function F(e, t) { const o = e.addStack(); o.layoutHorizontally(), o.addSpacer(), o.backgroundColor = t.isEmpty ? d.emptyLineColor : d.lineColor, o.setPadding(.5, 0, .5, 0); } if (p) {
11
+ f(e) !== void 0 ? u.layout = f(e) : g[e.trim().toLowerCase()] ? u.theme = g[e.trim().toLowerCase()] : h.push(e);
12
+ } const C = { ...H, ...u }; function I(e, t) { return C[e] || t; } const D = u.calendarTypes || h.join("/") || C.calendarTypes || "", p = (f(C.layout) ?? "single") === "double" && l !== "small", w = { small: 3, medium: 3, large: 7, extraLarge: 7, extraLargePortrait: 11 }[l] * (p ? 2 : 1), L = { 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) }, E = { default: L, transparent: { ...L, backgroundColor: void 0 } }, b = I("theme", "default"), d = E[b] || E.default; function P(e, t) { const o = new DateFormatter; return o.dateFormat = t, o.string(e); } function R(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 A(e) { return `calshow:${Math.floor(e.getTime() / 1e3) - 978307200}`; } async function K() { const e = await Calendar.forEvents(), t = new Date, o = new Date; return o.setMonth(o.getMonth() + 12), (await CalendarEvent.between(t, o, e)).map(n => { const i = l === "small" ? "yyyy/MM/dd" : p ? "yyyy/MM/dd EEEE" : `yyyy/MM/dd EEEE${n.isAllDay ? "" : " HH:mm"}`, c = P(n.startDate, i); return { name: n.title, date: n.startDate, dateStr: c, isEmpty: !1, type: n.calendar.title, color: "#" + n.calendar.color.hex, eventUrl: `x-apple-calevent://${n.identifier.replace(/:/g, "/")}`, calshowUrl: A(n.startDate) }; }).filter(n => !(n.type === "中国大陆节假日" && /(|)/.test(n.name))).filter(n => D.trim().length > 0 ? D.split("/").includes(n.type) : !0); } const W = await K(), r = new ListWidget; d.backgroundColor && (r.backgroundColor = d.backgroundColor), b === "transparent" && (r.backgroundStyle = "transparent"), r.spacing = 8; function x(e) { return W[e] || { name: "", date: "", isEmpty: !0, eventUrl: "", calshowUrl: "" }; } function S(e, t) { const o = e.addStack(); o.layoutVertically(), o.spacing = 1, t.eventUrl && (o.url = t.eventUrl); const a = o.addStack(); a.layoutHorizontally(), a.spacing = 2; const s = a.addText(t.name); s.font = Font.mediumRoundedSystemFont(14), s.textColor = t.color ? new Color(t.color) : d.dateTitleTextColor; const n = o.addStack(); n.layoutHorizontally(), n.spacing = 2; const i = n.addText(t.isEmpty ? " " : t.dateStr); i.font = Font.mediumRoundedSystemFont(10), i.textColor = d.dateDescriptionTextColor, e.addSpacer(); const c = e.addStack(); c.layoutHorizontally(), c.bottomAlignContent(), c.spacing = 2; const y = t.isEmpty ? " " : R(t.date), m = c.addStack(); m.spacing = 2, m.topAlignContent(); const F = m.addText(y.toString()); F.font = Font.mediumRoundedSystemFont(24), F.textColor = t.color ? new Color(t.color) : d.daysTextColor, F.rightAlignText(); const z = c.addStack(); if (z.setPadding(0, 0, 4, 0), !t.isEmpty) {
13
+ const k = z.addText("天");
14
+ k.font = Font.mediumRoundedSystemFont(10), k.textColor = d.daysUnitTextColor, k.rightAlignText();
15
+ } } function T(e, t) { const o = e.addStack(); o.layoutHorizontally(), o.addSpacer(), o.backgroundColor = t.isEmpty ? d.emptyLineColor : d.lineColor, o.setPadding(.5, 0, .5, 0); } if (p) {
16
16
  const t = w / 2;
17
17
  for (let o = 0; o < t; o++) {
18
18
  const a = r.addStack();
19
19
  a.layoutHorizontally();
20
- const l = S(o * 2), n = S(o * 2 + 1), s = a.addStack();
21
- s.layoutVertically(), s.spacing = 8;
22
- const i = s.addStack();
23
- i.layoutHorizontally(), T(i, l), o < t - 1 && F(s, l), a.addSpacer(12);
24
- const m = a.addStack();
25
- m.layoutVertically(), m.spacing = 8;
26
- const y = m.addStack();
27
- y.layoutHorizontally(), T(y, n), o < t - 1 && F(m, n);
20
+ const s = x(o * 2), n = x(o * 2 + 1), i = a.addStack();
21
+ i.layoutVertically(), i.spacing = 8;
22
+ const c = i.addStack();
23
+ c.layoutHorizontally(), S(c, s), o < t - 1 && T(i, s), a.addSpacer(12);
24
+ const y = a.addStack();
25
+ y.layoutVertically(), y.spacing = 8;
26
+ const m = y.addStack();
27
+ m.layoutHorizontally(), S(m, n), o < t - 1 && T(y, n);
28
28
  }
29
29
  }
30
30
  else
31
31
  for (let e = 0; e < w; e++) {
32
- const t = S(e), o = r.addStack();
33
- o.layoutHorizontally(), T(o, t), e < w - 1 && F(r, t);
34
- } config.runsInWidget ? Script.setWidget(r) : config.runsInApp && (c === "small" ? r.presentSmall() : c === "medium" ? r.presentMedium() : c === "large" && r.presentLarge()), Script.complete(); }
32
+ const t = x(e), o = r.addStack();
33
+ o.layoutHorizontally(), S(o, t), e < w - 1 && T(r, t);
34
+ } config.runsInWidget ? Script.setWidget(r) : config.runsInApp && (l === "small" ? r.presentSmall() : l === "medium" ? r.presentMedium() : l === "large" ? r.presentLarge() : l === "extraLarge" ? r.presentExtraLarge() : l === "extraLargePortrait" && r.presentExtraLargePortrait()), Script.complete(); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@showlotus/open-scriptable",
3
- "version": "0.1.26-alpha.2",
3
+ "version": "0.1.26-alpha.4",
4
4
  "description": "Open-source Scriptable scripts for iOS Widgets",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@8.10.0",
package/scriptable.d.ts CHANGED
@@ -2012,6 +2012,12 @@ declare global {
2012
2012
 
2013
2013
  // ==================== 全局对象 ====================
2014
2014
 
2015
+ /**
2016
+ * 小组件类型
2017
+ * extraLarge 仅 iPad 可用,extraLargePortrait 需 iOS 27+
2018
+ */
2019
+ type WidgetFamily = 'small' | 'medium' | 'large' | 'extraLarge' | 'extraLargePortrait';
2020
+
2015
2021
  /**
2016
2022
  * 配置对象
2017
2023
  * 提供有关脚本运行环境的信息
@@ -2031,8 +2037,8 @@ declare global {
2031
2037
  runsInActionExtension: boolean;
2032
2038
  /** 是否从主屏幕运行 */
2033
2039
  runsFromHomeScreen: boolean;
2034
- /** 小组件类型(small, medium, large, extraLarge) */
2035
- widgetFamily: string | null;
2040
+ /** 小组件类型 */
2041
+ widgetFamily: WidgetFamily | null;
2036
2042
  };
2037
2043
 
2038
2044
  /**