@showlotus/open-scriptable 0.1.11 → 0.1.14
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 +9 -4
- package/dist/count-down.js +1 -1
- package/dist/dev.js +1 -0
- package/dist/hello-world.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,9 @@ const __GLOBAL_CONFIG__ = {
|
|
|
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
|
-
|
|
14
|
+
const body = `const __GLOBAL_CONFIG__ = ${JSON.stringify(__GLOBAL_CONFIG__)};\n${code}`;
|
|
15
|
+
const render = new Function(body);
|
|
16
|
+
await render();
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
<div>
|
|
@@ -39,7 +41,9 @@ const __GLOBAL_CONFIG__ = {
|
|
|
39
41
|
|
|
40
42
|
const url = 'https://cdn.jsdelivr.net/npm/@showlotus/open-scriptable@latest/dist/count-down.js';
|
|
41
43
|
const code = await new Request(url).loadString();
|
|
42
|
-
|
|
44
|
+
const body = `const __GLOBAL_CONFIG__ = ${JSON.stringify(__GLOBAL_CONFIG__)};\n${code}`;
|
|
45
|
+
const render = new Function(body);
|
|
46
|
+
await render();
|
|
43
47
|
```
|
|
44
48
|
|
|
45
49
|
<!-- <div>
|
|
@@ -52,7 +56,7 @@ eval(code);
|
|
|
52
56
|
<img src="./res/count-down/dark-v2.jpeg" alt="dark" width="300">
|
|
53
57
|
</div>
|
|
54
58
|
|
|
55
|
-
### 月度消费组件
|
|
59
|
+
<!-- ### 月度消费组件 -->
|
|
56
60
|
|
|
57
61
|
## 开发
|
|
58
62
|
|
|
@@ -71,5 +75,6 @@ pnpm dev
|
|
|
71
75
|
const url = 'http://192.168.5.6:3000/src/hello-world.ts';
|
|
72
76
|
const code = await new Request(url).loadString();
|
|
73
77
|
// 执行脚本
|
|
74
|
-
|
|
78
|
+
const render = new Function(code);
|
|
79
|
+
await render();
|
|
75
80
|
```
|
package/dist/count-down.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){let t;t=config.runsInWidget?config.widgetFamily||"small":"medium";const e={small:3,medium:3,large:7}[t],
|
|
1
|
+
!function(){let t;t=config.runsInWidget?config.widgetFamily||"small":"medium";const e={small:3,medium:3,large:7}[t],o=new ListWidget;o.backgroundColor=Color.dynamic(new Color("#FFFFFF"),new Color("#1c1c1c")),o.spacing=8;const n=Object.entries(function(t,e=""){try{return __GLOBAL_CONFIG__[t]}catch(o){return e}}("days",{})||{}).map(([t,e])=>({name:t,date:e})).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()||e===a.getFullYear()&&(o>a.getMonth()+1||o===a.getMonth()+1&&n>=a.getDate())}).slice(0,e);if(n.length>0&&n.length<e)for(let a=n.length;a<e;a++)n.push({name:"",date:"",isEmpty:!0});n.forEach((e,a)=>{const l=o.addStack();l.layoutHorizontally();const r=l.addStack();r.layoutVertically(),r.spacing=1;const i=r.addStack();i.layoutHorizontally(),i.spacing=2;const c=i.addText(e.name);c.font=Font.mediumRoundedSystemFont(14),c.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF"));const d=r.addStack();d.layoutHorizontally(),d.spacing=2;const s=e.isEmpty?null:function(t){try{const[e,o,n]=t.split("-").map(Number);return new Date(e,o-1,n)}catch(e){return null}}(e.date),g=d.addText(e.isEmpty?" ":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}`}`}(s));g.font=Font.regularRoundedSystemFont(10),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=e.isEmpty?" ":function(t){const e=new Date;e.setHours(0,0,0,0);const o=t.getTime()-e.getTime();return Math.floor(o/864e5)}(s),y=m.addStack();y.spacing=2,y.topAlignContent();const C=y.addText(u.toString());C.font=Font.mediumRoundedSystemFont(24),C.textColor=Color.dynamic(new Color("#000000"),new Color("#FFFFFF")),C.rightAlignText();const F=m.addStack();if(F.setPadding(0,0,4,0),!e.isEmpty){const t=F.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=o.addStack();n.layoutHorizontally(),n.centerAlignContent();const a="small"===t?126:305,l=1,r=new DrawContext;if(r.size=new Size(a,l),r.opaque=!1,r.respectScreenScale=!0,e.isEmpty)r.setFillColor(new Color("#ffffff",0));else{const t=Color.dynamic(new Color("#E5E5E5"),new Color("#333333"));r.setFillColor(t),r.setStrokeColor(t),r.setTextColor(t)}const i=new Path;i.addRoundedRect(new Rect(0,0,a,l),l/2,l/2),r.addPath(i),r.fillPath();n.addImage(r.getImage()).centerAlignImage()}}),config.runsInWidget?Script.setWidget(o):config.runsInApp&&("small"===t?o.presentSmall():"medium"===t?o.presentMedium():"large"===t&&o.presentLarge()),Script.complete()}();
|
package/dist/dev.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=(e,n,t)=>new Promise((r,l)=>{var o=e=>{try{i(t.next(e))}catch(n){l(n)}},c=e=>{try{i(t.throw(e))}catch(n){l(n)}},i=e=>e.done?r(e.value):Promise.resolve(e.value).then(o,c);i((t=t.apply(e,n)).next())});!function(){e(this,null,function*(){try{const n="http://192.168.5.2:3000/src/hello-world.ts",t=yield function(n,t=3e3){return e(this,null,function*(){const r=e(null,null,function*(){const e=new Request(n);return yield e.loadString()}),l=e(null,null,function*(){throw yield new Promise(e=>{Timer.schedule(t,!1,e)}),new Error(`Timeout after ${t} ms`)});return Promise.race([r,l])})}(n),r=new Function(t);yield r()}catch(n){console.error(n)}finally{Script.complete()}})}();
|
package/dist/hello-world.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){let
|
|
1
|
+
!function(){return n=this,e=null,o=function*(){let n,e;function o(n){const e=new ListWidget;e.backgroundColor=Color.dynamic(new Color("#FFFFFF"),new Color("#1c1c1c"));const o=e.addText(`Hello, ${function(n,e=""){try{return __GLOBAL_CONFIG__[n]}catch(o){return e}}("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)),e}return n=config.runsInWidget&&config.widgetFamily||"small",config.runsInWidget?(e=o(),Script.setWidget(e)):(e=o(),"small"===n?e.presentSmall():"medium"===n?e.presentMedium():"large"===n&&e.presentLarge()),e},new Promise((t,r)=>{var l=n=>{try{i(o.next(n))}catch(e){r(e)}},c=n=>{try{i(o.throw(n))}catch(e){r(e)}},i=n=>n.done?t(n.value):Promise.resolve(n.value).then(l,c);i((o=o.apply(n,e)).next())});var n,e,o}();
|