@showlotus/open-scriptable 0.1.23 → 0.1.24

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
@@ -35,6 +35,16 @@ const render = new Function(code)();
35
35
  await render();
36
36
  ```
37
37
 
38
+ 小组件参数格式:`日历类型,布局`(逗号分隔,中英文逗号均可,两段均可选)
39
+
40
+ - **日历类型**:只显示指定类型的日历事件,多个类型用 `/` 分隔(如 `节假日/生日`),留空显示全部
41
+ - **布局**:`double` 为两列布局(中号 2 列 × 3 行、大号 2 列 × 7 行),默认 `single` 单列
42
+ - 只传一段时,若为 `single`/`double` 关键词则视为布局,例如直接填 `double` = 全部日历 + 双列
43
+
44
+ 示例:小组件参数填写 `节假日,double`
45
+
46
+ 使用指南:[【iOS】倒计时小组件可以自动关联日历啦✨ - showlotus](https://www.xiaohongshu.com/discovery/item/693ad4e1000000001b0213f9?source=webshare&xhsshare=pc_web&xsec_token=AB7rXUtVvD9i-FRNDkZ48ctiVz2JxS_fcZY2waWv-enoA=&xsec_source=pc_share)
47
+
38
48
  <!-- <div>
39
49
  <img src="./res/count-down/light.jpeg" alt="light" width="300">
40
50
  <img src="./res/count-down/dark.jpeg" alt="dark" width="300">
@@ -1,32 +1,23 @@
1
- return async function W(h = {}) { var F; const D = { small: 3, medium: 3, large: 7 }; let l; config.runsInWidget ? l = config.widgetFamily || "small" : l = "large"; const f = D[l], u = (F = args.widgetParameter) == null ? void 0 : F.trim(), [C = "", I = "default"] = (u == null ? void 0 : u.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 h[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(); } function M(e) { return `calshow:${Math.floor(e.getTime() / 1e3) - 978307200}`; } async function R() { const e = await Calendar.forEvents(), t = new Date, o = new Date; return o.setMonth(o.getMonth() + 12), (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, eventUrl: `x-apple-calevent://${a.identifier.replace(/:/g, "/")}`, calshowUrl: M(a.startDate) }; }).filter(a => !(a.type === "中国大陆节假日" && /(|)/.test(a.name))).filter(a => C.trim().length > 0 ? C.split("/").includes(a.type) : !0); } const U = 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, f); for (let e = 0; e < f; e++) {
2
- const t = U[e] || { name: "", date: "", isEmpty: !0, eventUrl: "" }, o = i.addStack();
3
- o.layoutHorizontally();
4
- const n = o.addStack();
5
- n.layoutVertically(), n.spacing = 1, t.eventUrl && (n.url = t.eventUrl);
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 b = t.isEmpty ? " " : z(t.date), y = m.addStack();
17
- y.spacing = 2, y.topAlignContent();
18
- const g = y.addText(b.toString());
19
- g.font = Font.mediumRoundedSystemFont(24), g.textColor = t.color ? new Color(t.color) : s.daysTextColor, g.rightAlignText();
20
- const T = m.addStack();
21
- if (T.setPadding(0, 0, 4, 0), !t.isEmpty) {
22
- const d = T.addText("天");
23
- d.font = Font.mediumRoundedSystemFont(10), d.textColor = s.daysUnitTextColor, d.rightAlignText();
1
+ return async function G(H = {}) { var b, M; let c; config.runsInWidget ? c = config.widgetFamily || "small" : c = "large"; const f = (b = args.widgetParameter) == null ? void 0 : b.trim(), L = (f == null ? void 0 : f.split(/,|,/).map(o => o.trim())) || [], [g = "", D = ""] = L, h = !D && ["single", "double"].includes(g.toLowerCase()), k = h ? "" : g, C = ((M = p("layout", (h ? g : D).toLowerCase() === "double" ? "double" : "single")) != null ? M : "single") === "double" && c !== "small", y = (C ? { small: 3, medium: 6, large: 14 } : { small: 3, medium: 3, large: 7 })[c], E = { 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) } }, U = p("theme", "default"), d = E[U] || E.default; function p(o, t) { return H[o] || t; } function I(o, t) { const e = new DateFormatter; return e.dateFormat = t, e.string(o); } function R(o) { const t = new Date; t.setHours(0, 0, 0, 0); const e = o.getTime() - t.getTime(); return Math.floor(e / (1e3 * 60 * 60 * 24)); } function A(o) { return `calshow:${Math.floor(o.getTime() / 1e3) - 978307200}`; } async function P() { const o = await Calendar.forEvents(), t = new Date, e = new Date; return e.setMonth(e.getMonth() + 12), (await CalendarEvent.between(t, e, o)).map(n => { const r = c === "small" ? "yyyy/MM/dd" : C ? "yyyy/MM/dd EEEE" : `yyyy/MM/dd EEEE${n.isAllDay ? "" : " HH:mm"}`, s = I(n.startDate, r); return { name: n.title, date: n.startDate, dateStr: s, 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 => k.trim().length > 0 ? k.split("/").includes(n.type) : !0); } const W = await P(), i = new ListWidget; i.backgroundColor = d.backgroundColor, i.spacing = 8, Object.entries(p("days", {}) || {}).map(([o, t]) => ({ name: o, date: t, isEmpty: !1 })).sort((o, t) => o.date > t.date ? 1 : -1).filter(o => { const [t, e, a] = o.date.split("-").map(Number), l = new Date; return t > l.getFullYear() ? !0 : t === l.getFullYear() ? e > l.getMonth() + 1 || e === l.getMonth() + 1 && a >= l.getDate() : !1; }).slice(0, y); function w(o) { return W[o] || { name: "", date: "", isEmpty: !0, eventUrl: "", calshowUrl: "" }; } function F(o, t) { const e = o.addStack(); e.layoutVertically(), e.spacing = 1, t.eventUrl && (e.url = t.eventUrl); const a = e.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 = e.addStack(); n.layoutHorizontally(), n.spacing = 2; const r = n.addText(t.isEmpty ? " " : t.dateStr); r.font = Font.mediumRoundedSystemFont(10), r.textColor = d.dateDescriptionTextColor, o.addSpacer(); const s = o.addStack(); s.layoutHorizontally(), s.bottomAlignContent(), s.spacing = 2; const m = t.isEmpty ? " " : R(t.date), u = s.addStack(); u.spacing = 2, u.topAlignContent(); const T = u.addText(m.toString()); T.font = Font.mediumRoundedSystemFont(24), T.textColor = t.color ? new Color(t.color) : d.daysTextColor, T.rightAlignText(); const z = s.addStack(); if (z.setPadding(0, 0, 4, 0), !t.isEmpty) {
2
+ const x = z.addText("天");
3
+ x.font = Font.mediumRoundedSystemFont(10), x.textColor = d.daysUnitTextColor, x.rightAlignText();
4
+ } } function S(o, t) { const e = o.addStack(); e.layoutHorizontally(), e.addSpacer(), e.backgroundColor = t.isEmpty ? d.emptyLineColor : d.lineColor, e.setPadding(.5, 0, .5, 0); } if (C) {
5
+ const t = y / 2;
6
+ for (let e = 0; e < t; e++) {
7
+ const a = i.addStack();
8
+ a.layoutHorizontally();
9
+ const l = w(e * 2), n = w(e * 2 + 1), r = a.addStack();
10
+ r.layoutVertically(), r.spacing = 8;
11
+ const s = r.addStack();
12
+ s.layoutHorizontally(), F(s, l), e < t - 1 && S(r, l), a.addSpacer(12);
13
+ const m = a.addStack();
14
+ m.layoutVertically(), m.spacing = 8;
15
+ const u = m.addStack();
16
+ u.layoutHorizontally(), F(u, n), e < t - 1 && S(m, n);
24
17
  }
25
- if (e < f - 1) {
26
- const d = i.addStack();
27
- d.layoutHorizontally(), d.centerAlignContent();
28
- const A = l === "small" ? 126 : 305, H = 1;
29
- let S = s.lineColor;
30
- t.isEmpty && (S = s.emptyLineColor), d.addImage(L(A, H, S)).centerAlignImage();
31
- }
32
- } config.runsInWidget ? Script.setWidget(i) : config.runsInApp && (l === "small" ? i.presentSmall() : l === "medium" ? i.presentMedium() : l === "large" && i.presentLarge()), Script.complete(); }
18
+ }
19
+ else
20
+ for (let o = 0; o < y; o++) {
21
+ const t = w(o), e = i.addStack();
22
+ e.layoutHorizontally(), F(e, t), o < y - 1 && S(i, t);
23
+ } config.runsInWidget ? Script.setWidget(i) : config.runsInApp && (c === "small" ? i.presentSmall() : c === "medium" ? i.presentMedium() : c === "large" && i.presentLarge()), Script.complete(); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@showlotus/open-scriptable",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "Open-source Scriptable scripts for iOS Widgets",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@8.10.0",