@operato/scene-timer 0.0.11
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/@types/global/index.d.ts +1 -0
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/assets/duetimer.png +0 -0
- package/assets/timer.png +0 -0
- package/dist/duetimer.d.ts +35 -0
- package/dist/duetimer.js +113 -0
- package/dist/duetimer.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/libs/format.d.ts +7 -0
- package/dist/libs/format.js +42 -0
- package/dist/libs/format.js.map +1 -0
- package/dist/templates/duetimer.d.ts +22 -0
- package/dist/templates/duetimer.js +24 -0
- package/dist/templates/duetimer.js.map +1 -0
- package/dist/templates/index.d.ts +18 -0
- package/dist/templates/index.js +4 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/timer.d.ts +18 -0
- package/dist/templates/timer.js +20 -0
- package/dist/templates/timer.js.map +1 -0
- package/dist/timer.d.ts +34 -0
- package/dist/timer.js +129 -0
- package/dist/timer.js.map +1 -0
- package/helps/scene/component/duetimer.ko.md +41 -0
- package/helps/scene/component/duetimer.md +40 -0
- package/helps/scene/component/duetimer.zh.md +39 -0
- package/helps/scene/component/timer.ko.md +64 -0
- package/helps/scene/component/timer.md +62 -0
- package/helps/scene/component/timer.zh.md +63 -0
- package/helps/scene/images/rect-button.png +0 -0
- package/helps/scene/images/timer-data-bind.png +0 -0
- package/helps/scene/images/timer-fill-color.png +0 -0
- package/package.json +62 -0
- package/src/duetimer.ts +138 -0
- package/src/index.ts +4 -0
- package/src/libs/format.ts +47 -0
- package/src/templates/duetimer.ts +24 -0
- package/src/templates/index.ts +4 -0
- package/src/templates/timer.ts +20 -0
- package/src/timer.ts +156 -0
- package/things-scene.config.js +5 -0
- package/translations/en.json +11 -0
- package/translations/ko.json +11 -0
- package/translations/ms.json +11 -0
- package/translations/zh.json +11 -0
- package/tsconfig.json +23 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '*.png'
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
### [0.0.11](https://github.com/things-scene/operato-scene/compare/v0.0.10...v0.0.11) (2021-12-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### :rocket: New Features
|
|
10
|
+
|
|
11
|
+
* add wheel-sorter, legend, timer and compass ([dc90f73](https://github.com/things-scene/operato-scene/commit/dc90f73054424c0867a1c4a28d51da6e7fab8b85))
|
|
12
|
+
* add wheel-sorter, legend, timer and compass ([518950c](https://github.com/things-scene/operato-scene/commit/518950cb5476048504a415a1dd0a1fd2d4359a77))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Hearty, Oh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
## node package를 설치한다.
|
|
2
|
+
|
|
3
|
+
`$ yarn`
|
|
4
|
+
|
|
5
|
+
## 실행
|
|
6
|
+
|
|
7
|
+
`$ yarn serve`
|
|
8
|
+
`$ yarn serve:dev`
|
|
9
|
+
|
|
10
|
+
## 포트를 바꾸려면, -p 3001 식으로 추가해준다.
|
|
11
|
+
|
|
12
|
+
`$ yarn serve`
|
|
13
|
+
`$ yarn serve -p 3001`
|
|
14
|
+
|
|
15
|
+
## test in browser
|
|
16
|
+
|
|
17
|
+
http://localhost:3000
|
|
18
|
+
|
|
19
|
+
## build
|
|
20
|
+
|
|
21
|
+
`$ yarn build`
|
|
22
|
+
|
|
23
|
+
| type | filename | for | tested |
|
|
24
|
+
| ---- | ------------------------------------------ | -------------- | ------ |
|
|
25
|
+
| UMD | things-scene-timer.js | modern browser | O |
|
|
26
|
+
| UMD | things-scene-timer-ie.js | ie 11 | O |
|
|
27
|
+
| ESM | things-scene-timer.mjs | modern browser | O |
|
|
28
|
+
|
|
29
|
+
## publish
|
|
30
|
+
|
|
31
|
+
`$ yarn publish`
|
|
Binary file
|
package/assets/timer.png
ADDED
|
Binary file
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Properties, Shape } from '@hatiolab/things-scene';
|
|
2
|
+
declare const DueTimer_base: typeof Shape;
|
|
3
|
+
export default class DueTimer extends DueTimer_base {
|
|
4
|
+
static get nature(): {
|
|
5
|
+
mutable: boolean;
|
|
6
|
+
resizable: boolean;
|
|
7
|
+
rotatable: boolean;
|
|
8
|
+
properties: ({
|
|
9
|
+
type: string;
|
|
10
|
+
label: string;
|
|
11
|
+
name: string;
|
|
12
|
+
placeholder: string;
|
|
13
|
+
property?: undefined;
|
|
14
|
+
} | {
|
|
15
|
+
type: string;
|
|
16
|
+
label: string;
|
|
17
|
+
name: string;
|
|
18
|
+
property: string;
|
|
19
|
+
placeholder?: undefined;
|
|
20
|
+
})[];
|
|
21
|
+
'value-property': string;
|
|
22
|
+
help: string;
|
|
23
|
+
};
|
|
24
|
+
ready(): void;
|
|
25
|
+
onchange(after: Properties): void;
|
|
26
|
+
counting(): void;
|
|
27
|
+
render(context: CanvasRenderingContext2D): void;
|
|
28
|
+
postrender(context: CanvasRenderingContext2D): void;
|
|
29
|
+
get timeout(): number;
|
|
30
|
+
set timeout(timeout: number);
|
|
31
|
+
get due(): number;
|
|
32
|
+
set due(due: number);
|
|
33
|
+
get countdown(): number;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
package/dist/duetimer.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Component, RectPath, Shape } from '@hatiolab/things-scene';
|
|
2
|
+
/*
|
|
3
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
import format from './libs/format';
|
|
6
|
+
const NATURE = {
|
|
7
|
+
mutable: false,
|
|
8
|
+
resizable: true,
|
|
9
|
+
rotatable: true,
|
|
10
|
+
properties: [
|
|
11
|
+
{
|
|
12
|
+
type: 'number',
|
|
13
|
+
label: 'due',
|
|
14
|
+
name: 'due',
|
|
15
|
+
placeholder: 'timestamp'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
type: 'string',
|
|
19
|
+
label: 'format-run',
|
|
20
|
+
name: 'format-run',
|
|
21
|
+
placeholder: 'hh:mm:ss'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: 'string',
|
|
25
|
+
label: 'format-stop',
|
|
26
|
+
name: 'format-stop',
|
|
27
|
+
placeholder: '--:--:--'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: 'color',
|
|
31
|
+
label: 'background-color',
|
|
32
|
+
name: 'backgroundColor',
|
|
33
|
+
property: 'backgroundColor'
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
'value-property': 'due',
|
|
37
|
+
help: 'scene/component/duetimer'
|
|
38
|
+
};
|
|
39
|
+
export default class DueTimer extends RectPath(Shape) {
|
|
40
|
+
static get nature() {
|
|
41
|
+
return NATURE;
|
|
42
|
+
}
|
|
43
|
+
ready() {
|
|
44
|
+
if (!this.app.isViewMode) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
var { due = 0 } = this.state;
|
|
48
|
+
this.timeout = Math.max(Math.round((due - Date.now()) / 1000), 0);
|
|
49
|
+
}
|
|
50
|
+
onchange(after) {
|
|
51
|
+
if ('due' in after) {
|
|
52
|
+
this.timeout = Math.max(Math.round((this.due - Date.now()) / 1000), 0);
|
|
53
|
+
this.counting();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
counting() {
|
|
57
|
+
requestAnimationFrame(() => {
|
|
58
|
+
const countdown = this.countdown;
|
|
59
|
+
if (countdown > 0) {
|
|
60
|
+
this.set('data', format(countdown, this.getState('format-run')));
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
this.counting();
|
|
63
|
+
}, 1000);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.set('data', this.getState('format-stop'));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
render(context) {
|
|
71
|
+
var { top, left, height, width, backgroundColor = 'transparent' } = this.model;
|
|
72
|
+
// background의 색상
|
|
73
|
+
context.beginPath();
|
|
74
|
+
context.rect(left, top, width, height);
|
|
75
|
+
context.fillStyle = backgroundColor;
|
|
76
|
+
context.fill();
|
|
77
|
+
// value의 색상
|
|
78
|
+
context.beginPath();
|
|
79
|
+
var progress = (this.countdown / this.timeout) * 100;
|
|
80
|
+
if (!isNaN(progress)) {
|
|
81
|
+
progress = width - (width * progress) / 100;
|
|
82
|
+
progress = Math.max(Math.min(progress, width), 0);
|
|
83
|
+
context.rect(left, top, progress, height);
|
|
84
|
+
this.drawFill(context);
|
|
85
|
+
context.beginPath();
|
|
86
|
+
}
|
|
87
|
+
// stroke
|
|
88
|
+
context.rect(left, top, width, height);
|
|
89
|
+
}
|
|
90
|
+
postrender(context) {
|
|
91
|
+
this.drawStroke(context);
|
|
92
|
+
this.drawText(context);
|
|
93
|
+
}
|
|
94
|
+
get timeout() {
|
|
95
|
+
return Number(this.getState('timeout') || 0);
|
|
96
|
+
}
|
|
97
|
+
set timeout(timeout) {
|
|
98
|
+
this.setState('timeout', Number(timeout) || 0);
|
|
99
|
+
}
|
|
100
|
+
get due() {
|
|
101
|
+
return Number(this.getState('due') || 0);
|
|
102
|
+
}
|
|
103
|
+
set due(due) {
|
|
104
|
+
this.setState('due', due);
|
|
105
|
+
}
|
|
106
|
+
get countdown() {
|
|
107
|
+
const due = this.due;
|
|
108
|
+
const now = Date.now();
|
|
109
|
+
return Math.max(Math.round((due - now) / 1000), 0);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
Component.register('duetimer', DueTimer);
|
|
113
|
+
//# sourceMappingURL=duetimer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duetimer.js","sourceRoot":"","sources":["../src/duetimer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAc,QAAQ,EAAE,KAAK,EAAS,MAAM,wBAAwB,CAAA;AAEtF;;GAEG;AACH,OAAO,MAAM,MAAM,eAAe,CAAA;AAElC,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,KAAK;IACd,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,IAAI;IACf,UAAU,EAAE;QACV;YACE,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,KAAK;YACZ,IAAI,EAA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hatiolab/things-scene'\n\n/*\n * Copyright © HatioLab Inc. All rights reserved.\n */\nimport format from './libs/format'\n\nconst NATURE = {\n mutable: false,\n resizable: true,\n rotatable: true,\n properties: [\n {\n type: 'number',\n label: 'due',\n name: 'due',\n placeholder: 'timestamp'\n },\n {\n type: 'string',\n label: 'format-run',\n name: 'format-run',\n placeholder: 'hh:mm:ss'\n },\n {\n type: 'string',\n label: 'format-stop',\n name: 'format-stop',\n placeholder: '--:--:--'\n },\n {\n type: 'color',\n label: 'background-color',\n name: 'backgroundColor',\n property: 'backgroundColor'\n }\n ],\n 'value-property': 'due',\n help: 'scene/component/duetimer'\n}\n\nexport default class DueTimer extends RectPath(Shape) {\n static get nature() {\n return NATURE\n }\n\n ready() {\n if (!this.app.isViewMode) {\n return\n }\n\n var { due = 0 } = this.state\n\n this.timeout = Math.max(Math.round((due - Date.now()) / 1000), 0)\n }\n\n onchange(after: Properties) {\n if ('due' in after) {\n this.timeout = Math.max(Math.round((this.due - Date.now()) / 1000), 0)\n this.counting()\n }\n }\n\n counting() {\n requestAnimationFrame(() => {\n const countdown = this.countdown\n\n if (countdown > 0) {\n this.set('data', format(countdown, this.getState('format-run')))\n\n setTimeout(() => {\n this.counting()\n }, 1000)\n } else {\n this.set('data', this.getState('format-stop'))\n }\n })\n }\n\n render(context: CanvasRenderingContext2D) {\n var { top, left, height, width, backgroundColor = 'transparent' } = this.model\n\n // background의 색상\n context.beginPath()\n context.rect(left, top, width, height)\n\n context.fillStyle = backgroundColor\n context.fill()\n\n // value의 색상\n context.beginPath()\n\n var progress = (this.countdown / this.timeout) * 100\n\n if (!isNaN(progress)) {\n progress = width - (width * progress) / 100\n progress = Math.max(Math.min(progress, width), 0)\n\n context.rect(left, top, progress, height)\n this.drawFill(context)\n\n context.beginPath()\n }\n\n // stroke\n context.rect(left, top, width, height)\n }\n\n postrender(context: CanvasRenderingContext2D) {\n this.drawStroke(context)\n this.drawText(context)\n }\n\n get timeout() {\n return Number(this.getState('timeout') || 0)\n }\n\n set timeout(timeout) {\n this.setState('timeout', Number(timeout) || 0)\n }\n\n get due() {\n return Number(this.getState('due') || 0)\n }\n\n set due(due) {\n this.setState('due', due)\n }\n\n get countdown() {\n const due = this.due\n const now = Date.now()\n\n return Math.max(Math.round((due - now) / 1000), 0)\n }\n}\n\nComponent.register('duetimer', DueTimer)\n"]}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,QAAQ,MAAM,YAAY,CAAA;AAEjC,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA","sourcesContent":["import Timer from './timer'\nimport DueTimer from './duetimer'\n\nexport default [Timer, DueTimer]\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 문자열 길이를 늘려주는 함수
|
|
3
|
+
*
|
|
4
|
+
* @param {String} i
|
|
5
|
+
* @param {Number} len
|
|
6
|
+
*/
|
|
7
|
+
function ii(i, len) {
|
|
8
|
+
var s = i + '';
|
|
9
|
+
len = len || 2;
|
|
10
|
+
while (s.length < len)
|
|
11
|
+
s = '0' + s;
|
|
12
|
+
return s;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 시간 표시 포맷을 맞추는 함수
|
|
16
|
+
*
|
|
17
|
+
* @param {Number} seconds seconds
|
|
18
|
+
* @param {string} format hh:mm:ss
|
|
19
|
+
*/
|
|
20
|
+
export default function format(seconds = 0, format = '') {
|
|
21
|
+
var h = 0, m = 0, s = 0;
|
|
22
|
+
var formated = '';
|
|
23
|
+
h = Math.floor(seconds / 3600);
|
|
24
|
+
formated = format.replace(/(^|[^\\])hh+/g, '$1' + ii(h));
|
|
25
|
+
formated = formated.replace(/(^|[^\\])h/g, '$1' + h);
|
|
26
|
+
if (format != formated) {
|
|
27
|
+
format = formated;
|
|
28
|
+
seconds %= 1440;
|
|
29
|
+
}
|
|
30
|
+
m = Math.floor(seconds / 60);
|
|
31
|
+
formated = format.replace(/(^|[^\\])mm+/g, '$1' + ii(m));
|
|
32
|
+
formated = formated.replace(/(^|[^\\])m/g, '$1' + m);
|
|
33
|
+
if (format != formated) {
|
|
34
|
+
format = formated;
|
|
35
|
+
seconds %= 60;
|
|
36
|
+
}
|
|
37
|
+
s = seconds;
|
|
38
|
+
formated = format.replace(/(^|[^\\])ss+/g, '$1' + ii(s));
|
|
39
|
+
formated = formated.replace(/(^|[^\\])s/g, '$1' + s);
|
|
40
|
+
return formated;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/libs/format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,SAAS,EAAE,CAAC,CAAS,EAAE,GAAY;IACjC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;IACd,GAAG,GAAG,GAAG,IAAI,CAAC,CAAA;IACd,OAAO,CAAC,CAAC,MAAM,GAAG,GAAG;QAAE,CAAC,GAAG,GAAG,GAAG,CAAC,CAAA;IAClC,OAAO,CAAC,CAAA;AACV,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,GAAG,CAAC,EAAE,MAAM,GAAG,EAAE;IACrD,IAAI,CAAC,GAAG,CAAC,EACP,CAAC,GAAG,CAAC,EACL,CAAC,GAAG,CAAC,CAAA;IACP,IAAI,QAAQ,GAAG,EAAE,CAAA;IAEjB,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAC9B,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACxD,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,GAAG,CAAC,CAAC,CAAA;IACpD,IAAI,MAAM,IAAI,QAAQ,EAAE;QACtB,MAAM,GAAG,QAAQ,CAAA;QACjB,OAAO,IAAI,IAAI,CAAA;KAChB;IAED,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAA;IAC5B,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACxD,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,GAAG,CAAC,CAAC,CAAA;IACpD,IAAI,MAAM,IAAI,QAAQ,EAAE;QACtB,MAAM,GAAG,QAAQ,CAAA;QACjB,OAAO,IAAI,EAAE,CAAA;KACd;IAED,CAAC,GAAG,OAAO,CAAA;IACX,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACxD,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,GAAG,CAAC,CAAC,CAAA;IAEpD,OAAO,QAAQ,CAAA;AACjB,CAAC","sourcesContent":["/**\n * 문자열 길이를 늘려주는 함수\n *\n * @param {String} i\n * @param {Number} len\n */\nfunction ii(i: number, len?: number) {\n var s = i + ''\n len = len || 2\n while (s.length < len) s = '0' + s\n return s\n}\n\n/**\n * 시간 표시 포맷을 맞추는 함수\n *\n * @param {Number} seconds seconds\n * @param {string} format hh:mm:ss\n */\nexport default function format(seconds = 0, format = '') {\n var h = 0,\n m = 0,\n s = 0\n var formated = ''\n\n h = Math.floor(seconds / 3600)\n formated = format.replace(/(^|[^\\\\])hh+/g, '$1' + ii(h))\n formated = formated.replace(/(^|[^\\\\])h/g, '$1' + h)\n if (format != formated) {\n format = formated\n seconds %= 1440\n }\n\n m = Math.floor(seconds / 60)\n formated = format.replace(/(^|[^\\\\])mm+/g, '$1' + ii(m))\n formated = formated.replace(/(^|[^\\\\])m/g, '$1' + m)\n if (format != formated) {\n format = formated\n seconds %= 60\n }\n\n s = seconds\n formated = format.replace(/(^|[^\\\\])ss+/g, '$1' + ii(s))\n formated = formated.replace(/(^|[^\\\\])s/g, '$1' + s)\n\n return formated\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
type: string;
|
|
3
|
+
description: string;
|
|
4
|
+
group: string;
|
|
5
|
+
icon: any;
|
|
6
|
+
model: {
|
|
7
|
+
type: string;
|
|
8
|
+
left: number;
|
|
9
|
+
top: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
strokeStyle: string;
|
|
13
|
+
text: string;
|
|
14
|
+
days: number;
|
|
15
|
+
hours: number;
|
|
16
|
+
minutes: number;
|
|
17
|
+
seconds: number;
|
|
18
|
+
'format-run': string;
|
|
19
|
+
'format-stop': string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export default _default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import icon from '../../assets/timer.png';
|
|
2
|
+
export default {
|
|
3
|
+
type: 'timer',
|
|
4
|
+
description: 'timer',
|
|
5
|
+
group: 'etc',
|
|
6
|
+
/* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
|
|
7
|
+
icon,
|
|
8
|
+
model: {
|
|
9
|
+
type: 'timer',
|
|
10
|
+
left: 10,
|
|
11
|
+
top: 10,
|
|
12
|
+
width: 100,
|
|
13
|
+
height: 100,
|
|
14
|
+
strokeStyle: 'darkgray',
|
|
15
|
+
text: '#{data}',
|
|
16
|
+
days: 0,
|
|
17
|
+
hours: 0,
|
|
18
|
+
minutes: 0,
|
|
19
|
+
seconds: 0,
|
|
20
|
+
'format-run': 'mm:ss',
|
|
21
|
+
'format-stop': '--:--'
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=duetimer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duetimer.js","sourceRoot":"","sources":["../../src/templates/duetimer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,wBAAwB,CAAA;AAEzC,eAAe;IACb,IAAI,EAAE,OAAO;IACb,WAAW,EAAE,OAAO;IACpB,KAAK,EAAE,KAAK;IACZ,gGAAgG;IAChG,IAAI;IACJ,KAAK,EAAE;QACL,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,EAAE;QACR,GAAG,EAAE,EAAE;QACP,KAAK,EAAE,GAAG;QACV,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,UAAU;QACvB,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,CAAC;QACR,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;QACV,YAAY,EAAE,OAAO;QACrB,aAAa,EAAE,OAAO;KACvB;CACF,CAAA","sourcesContent":["import icon from '../../assets/timer.png'\n\nexport default {\n type: 'timer',\n description: 'timer',\n group: 'etc',\n /* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */\n icon,\n model: {\n type: 'timer',\n left: 10,\n top: 10,\n width: 100,\n height: 100,\n strokeStyle: 'darkgray',\n text: '#{data}',\n days: 0,\n hours: 0,\n minutes: 0,\n seconds: 0,\n 'format-run': 'mm:ss',\n 'format-stop': '--:--'\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
type: string;
|
|
3
|
+
description: string;
|
|
4
|
+
group: string;
|
|
5
|
+
icon: any;
|
|
6
|
+
model: {
|
|
7
|
+
type: string;
|
|
8
|
+
left: number;
|
|
9
|
+
top: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
strokeStyle: string;
|
|
13
|
+
text: string;
|
|
14
|
+
'format-run': string;
|
|
15
|
+
'format-stop': string;
|
|
16
|
+
};
|
|
17
|
+
}[];
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,QAAQ,MAAM,YAAY,CAAA;AAEjC,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA","sourcesContent":["import timer from './timer'\nimport duetimer from './duetimer'\n\nexport default [timer, duetimer]\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
type: string;
|
|
3
|
+
description: string;
|
|
4
|
+
group: string;
|
|
5
|
+
icon: any;
|
|
6
|
+
model: {
|
|
7
|
+
type: string;
|
|
8
|
+
left: number;
|
|
9
|
+
top: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
strokeStyle: string;
|
|
13
|
+
text: string;
|
|
14
|
+
'format-run': string;
|
|
15
|
+
'format-stop': string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import icon from '../../assets/duetimer.png';
|
|
2
|
+
export default {
|
|
3
|
+
type: 'duetimer',
|
|
4
|
+
description: 'duetimer',
|
|
5
|
+
group: 'etc',
|
|
6
|
+
/* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
|
|
7
|
+
icon,
|
|
8
|
+
model: {
|
|
9
|
+
type: 'duetimer',
|
|
10
|
+
left: 10,
|
|
11
|
+
top: 10,
|
|
12
|
+
width: 100,
|
|
13
|
+
height: 100,
|
|
14
|
+
strokeStyle: 'darkgray',
|
|
15
|
+
text: '#{data}',
|
|
16
|
+
'format-run': 'mm:ss',
|
|
17
|
+
'format-stop': '--:--'
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=timer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../../src/templates/timer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,2BAA2B,CAAA;AAE5C,eAAe;IACb,IAAI,EAAE,UAAU;IAChB,WAAW,EAAE,UAAU;IACvB,KAAK,EAAE,KAAK;IACZ,gGAAgG;IAChG,IAAI;IACJ,KAAK,EAAE;QACL,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,EAAE;QACR,GAAG,EAAE,EAAE;QACP,KAAK,EAAE,GAAG;QACV,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,UAAU;QACvB,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,OAAO;QACrB,aAAa,EAAE,OAAO;KACvB;CACF,CAAA","sourcesContent":["import icon from '../../assets/duetimer.png'\n\nexport default {\n type: 'duetimer',\n description: 'duetimer',\n group: 'etc',\n /* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */\n icon,\n model: {\n type: 'duetimer',\n left: 10,\n top: 10,\n width: 100,\n height: 100,\n strokeStyle: 'darkgray',\n text: '#{data}',\n 'format-run': 'mm:ss',\n 'format-stop': '--:--'\n }\n}\n"]}
|
package/dist/timer.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Properties, Shape } from '@hatiolab/things-scene';
|
|
2
|
+
declare const Timer_base: typeof Shape;
|
|
3
|
+
export default class Timer extends Timer_base {
|
|
4
|
+
private _due?;
|
|
5
|
+
static get nature(): {
|
|
6
|
+
mutable: boolean;
|
|
7
|
+
resizable: boolean;
|
|
8
|
+
rotatable: boolean;
|
|
9
|
+
properties: ({
|
|
10
|
+
type: string;
|
|
11
|
+
label: string;
|
|
12
|
+
name: string;
|
|
13
|
+
placeholder: string;
|
|
14
|
+
property?: undefined;
|
|
15
|
+
} | {
|
|
16
|
+
type: string;
|
|
17
|
+
label: string;
|
|
18
|
+
name: string;
|
|
19
|
+
property: string;
|
|
20
|
+
placeholder?: undefined;
|
|
21
|
+
})[];
|
|
22
|
+
'value-property': string;
|
|
23
|
+
help: string;
|
|
24
|
+
};
|
|
25
|
+
ready(): void;
|
|
26
|
+
onchange(after: Properties): void;
|
|
27
|
+
counting(): void;
|
|
28
|
+
render(context: CanvasRenderingContext2D): void;
|
|
29
|
+
postrender(context: CanvasRenderingContext2D): void;
|
|
30
|
+
get timeout(): number;
|
|
31
|
+
set timeout(timeout: number);
|
|
32
|
+
get countdown(): number;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
package/dist/timer.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { Component, RectPath, Shape } from '@hatiolab/things-scene';
|
|
5
|
+
import format from './libs/format';
|
|
6
|
+
const NATURE = {
|
|
7
|
+
mutable: false,
|
|
8
|
+
resizable: true,
|
|
9
|
+
rotatable: true,
|
|
10
|
+
properties: [
|
|
11
|
+
{
|
|
12
|
+
type: 'number',
|
|
13
|
+
label: 'days',
|
|
14
|
+
name: 'days',
|
|
15
|
+
placeholder: 'days'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
type: 'number',
|
|
19
|
+
label: 'hours',
|
|
20
|
+
name: 'hours',
|
|
21
|
+
placeholder: 'hours'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: 'number',
|
|
25
|
+
label: 'minutes',
|
|
26
|
+
name: 'minutes',
|
|
27
|
+
placeholder: 'minutes'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: 'number',
|
|
31
|
+
label: 'seconds',
|
|
32
|
+
name: 'seconds',
|
|
33
|
+
placeholder: 'seconds'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: 'string',
|
|
37
|
+
label: 'format-run',
|
|
38
|
+
name: 'format-run',
|
|
39
|
+
placeholder: 'hh:mm:ss'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: 'string',
|
|
43
|
+
label: 'format-stop',
|
|
44
|
+
name: 'format-stop',
|
|
45
|
+
placeholder: '--:--:--'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type: 'color',
|
|
49
|
+
label: 'background-color',
|
|
50
|
+
name: 'backgroundColor',
|
|
51
|
+
property: 'backgroundColor'
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
'value-property': 'timeout',
|
|
55
|
+
help: 'scene/component/timer'
|
|
56
|
+
};
|
|
57
|
+
export default class Timer extends RectPath(Shape) {
|
|
58
|
+
static get nature() {
|
|
59
|
+
return NATURE;
|
|
60
|
+
}
|
|
61
|
+
ready() {
|
|
62
|
+
if (!this.app.isViewMode) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
var { days = 0, hours = 0, minutes = 0, seconds = 0 } = this.state;
|
|
66
|
+
this.timeout = days * 86400 + hours * 3600 + minutes * 60 + seconds;
|
|
67
|
+
}
|
|
68
|
+
onchange(after) {
|
|
69
|
+
if ('timeout' in after) {
|
|
70
|
+
this._due = Date.now() + this.timeout * 1000;
|
|
71
|
+
this.counting();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
counting() {
|
|
75
|
+
requestAnimationFrame(() => {
|
|
76
|
+
const countdown = this.countdown;
|
|
77
|
+
if (countdown > 0) {
|
|
78
|
+
this.set('data', format(countdown, this.getState('format-run')));
|
|
79
|
+
setTimeout(() => {
|
|
80
|
+
this.counting();
|
|
81
|
+
}, 1000);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.set('data', this.getState('format-stop'));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
render(context) {
|
|
89
|
+
var { top, left, height, width, backgroundColor = 'transparent' } = this.model;
|
|
90
|
+
// background의 색상
|
|
91
|
+
context.beginPath();
|
|
92
|
+
context.rect(left, top, width, height);
|
|
93
|
+
context.fillStyle = backgroundColor;
|
|
94
|
+
context.fill();
|
|
95
|
+
// value의 색상
|
|
96
|
+
context.beginPath();
|
|
97
|
+
var progress = (this.countdown / this.timeout) * 100;
|
|
98
|
+
if (!isNaN(progress)) {
|
|
99
|
+
progress = width - (width * progress) / 100;
|
|
100
|
+
progress = Math.max(Math.min(progress, width), 0);
|
|
101
|
+
context.rect(left, top, progress, height);
|
|
102
|
+
this.drawFill(context);
|
|
103
|
+
context.beginPath();
|
|
104
|
+
}
|
|
105
|
+
// stroke
|
|
106
|
+
context.rect(left, top, width, height);
|
|
107
|
+
}
|
|
108
|
+
postrender(context) {
|
|
109
|
+
this.drawStroke(context);
|
|
110
|
+
this.drawText(context);
|
|
111
|
+
}
|
|
112
|
+
get timeout() {
|
|
113
|
+
return Number(this.getState('timeout') || 0);
|
|
114
|
+
}
|
|
115
|
+
set timeout(timeout) {
|
|
116
|
+
this.setState('timeout', Number(timeout) || 0);
|
|
117
|
+
}
|
|
118
|
+
get countdown() {
|
|
119
|
+
const timeout = this.timeout;
|
|
120
|
+
if (!timeout || timeout < 0) {
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
const due = this._due || 0;
|
|
124
|
+
const now = Date.now();
|
|
125
|
+
return Math.max(Math.round((due - now) / 1000), 0);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
Component.register('timer', Timer);
|
|
129
|
+
//# sourceMappingURL=timer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../src/timer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAc,QAAQ,EAAE,KAAK,EAAS,MAAM,wBAAwB,CAAA;AAEtF,OAAO,MAAM,MAAM,eAAe,CAAA;AAElC,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,KAAK;IACd,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,IAAI;IACf,UAAU,EAAE;QACV;YACE,I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IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;IACpD,CAAC;CACF;AAED,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA","sourcesContent":["/*\n * Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport { Component, Properties, RectPath, Shape, error } from '@hatiolab/things-scene'\n\nimport format from './libs/format'\n\nconst NATURE = {\n mutable: false,\n resizable: true,\n rotatable: true,\n properties: [\n {\n type: 'number',\n label: 'days',\n name: 'days',\n placeholder: 'days'\n },\n {\n type: 'number',\n label: 'hours',\n name: 'hours',\n placeholder: 'hours'\n },\n {\n type: 'number',\n label: 'minutes',\n name: 'minutes',\n placeholder: 'minutes'\n },\n {\n type: 'number',\n label: 'seconds',\n name: 'seconds',\n placeholder: 'seconds'\n },\n {\n type: 'string',\n label: 'format-run',\n name: 'format-run',\n placeholder: 'hh:mm:ss'\n },\n {\n type: 'string',\n label: 'format-stop',\n name: 'format-stop',\n placeholder: '--:--:--'\n },\n {\n type: 'color',\n label: 'background-color',\n name: 'backgroundColor',\n property: 'backgroundColor'\n }\n ],\n 'value-property': 'timeout',\n help: 'scene/component/timer'\n}\n\nexport default class Timer extends RectPath(Shape) {\n private _due?: number\n\n static get nature() {\n return NATURE\n }\n\n ready() {\n if (!this.app.isViewMode) {\n return\n }\n\n var { days = 0, hours = 0, minutes = 0, seconds = 0 } = this.state\n\n this.timeout = days * 86400 + hours * 3600 + minutes * 60 + seconds\n }\n\n onchange(after: Properties) {\n if ('timeout' in after) {\n this._due = Date.now() + this.timeout * 1000\n this.counting()\n }\n }\n\n counting() {\n requestAnimationFrame(() => {\n const countdown = this.countdown\n\n if (countdown > 0) {\n this.set('data', format(countdown, this.getState('format-run')))\n\n setTimeout(() => {\n this.counting()\n }, 1000)\n } else {\n this.set('data', this.getState('format-stop'))\n }\n })\n }\n\n render(context: CanvasRenderingContext2D) {\n var { top, left, height, width, backgroundColor = 'transparent' } = this.model\n\n // background의 색상\n context.beginPath()\n context.rect(left, top, width, height)\n\n context.fillStyle = backgroundColor\n context.fill()\n\n // value의 색상\n context.beginPath()\n\n var progress = (this.countdown / this.timeout) * 100\n\n if (!isNaN(progress)) {\n progress = width - (width * progress) / 100\n progress = Math.max(Math.min(progress, width), 0)\n\n context.rect(left, top, progress, height)\n this.drawFill(context)\n\n context.beginPath()\n }\n\n // stroke\n context.rect(left, top, width, height)\n }\n\n postrender(context: CanvasRenderingContext2D) {\n this.drawStroke(context)\n this.drawText(context)\n }\n\n get timeout() {\n return Number(this.getState('timeout') || 0)\n }\n\n set timeout(timeout) {\n this.setState('timeout', Number(timeout) || 0)\n }\n\n get countdown() {\n const timeout = this.timeout\n if (!timeout || timeout < 0) {\n return 0\n }\n\n const due = this._due || 0\n const now = Date.now()\n\n return Math.max(Math.round((due - now) / 1000), 0)\n }\n}\n\nComponent.register('timer', Timer)\n"]}
|