@operato/scene-timer 8.0.0-beta.1 → 8.0.0

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/src/duetimer.ts DELETED
@@ -1,168 +0,0 @@
1
- import { Component, ComponentNature, Properties, RectPath, Shape } from '@hatiolab/things-scene'
2
-
3
- /*
4
- * Copyright © HatioLab Inc. All rights reserved.
5
- */
6
- import format from './libs/format'
7
-
8
- const NATURE: ComponentNature = {
9
- mutable: false,
10
- resizable: true,
11
- rotatable: true,
12
- properties: [
13
- {
14
- type: 'number',
15
- label: 'due',
16
- name: 'due',
17
- placeholder: 'timestamp'
18
- },
19
- {
20
- type: 'string',
21
- label: 'format-run',
22
- name: 'format-run',
23
- placeholder: 'hh:mm:ss'
24
- },
25
- {
26
- type: 'string',
27
- label: 'format-stop',
28
- name: 'format-stop',
29
- placeholder: '--:--:--'
30
- },
31
- {
32
- type: 'select',
33
- label: 'data-reflection',
34
- name: 'dataReflection',
35
- property: {
36
- options: ['', 'countdown', 'round']
37
- }
38
- },
39
- {
40
- type: 'color',
41
- label: 'progress-color',
42
- name: 'progressColor',
43
- property: 'progressColor'
44
- }
45
- ],
46
- 'value-property': 'due',
47
- help: 'scene/component/duetimer'
48
- }
49
-
50
- export default class DueTimer extends RectPath(Shape) {
51
- private _round: number = 0
52
-
53
- get nature() {
54
- return NATURE
55
- }
56
-
57
- ready() {
58
- if (!this.app.isViewMode) {
59
- return
60
- }
61
-
62
- var { due = 0 } = this.state
63
-
64
- this.timeout = Math.max(Math.round((due - Date.now()) / 1000), 0)
65
- }
66
-
67
- onchange(after: Properties) {
68
- if ('timeout' in after) {
69
- this.timeout = Math.max(Math.round((this.due - Date.now()) / 1000), 0)
70
- this.counting()
71
- }
72
- }
73
-
74
- counting() {
75
- // @ts-ignore
76
- if (this.disposed) {
77
- return
78
- }
79
-
80
- requestAnimationFrame(() => {
81
- const countdown = this.countdown
82
- const { dataReflection = 'countdown' } = this.state
83
-
84
- if (countdown > 0) {
85
- const text = format(countdown, this.getState('format-run'))
86
-
87
- this.text = text
88
-
89
- if (dataReflection != 'round') {
90
- this.setState('data', text)
91
- }
92
-
93
- setTimeout(() => {
94
- this.counting()
95
- }, 1000)
96
- } else {
97
- const text = format(countdown, this.getState('format-stop'))
98
-
99
- this.text = text
100
-
101
- this.setState('data', dataReflection != 'round' ? text : ++this._round)
102
- }
103
- })
104
- }
105
-
106
- render(context: CanvasRenderingContext2D) {
107
- var { top, left, height, width, progressColor = 'transparent' } = this.state
108
-
109
- // progress의 색상
110
- context.beginPath()
111
- context.rect(left, top, width, height)
112
-
113
- this.drawFill(context)
114
-
115
- // value의 색상
116
- context.beginPath()
117
-
118
- var progress = (this.countdown / this.timeout) * 100
119
-
120
- if (!isNaN(progress)) {
121
- progress = width - (width * progress) / 100
122
- progress = Math.max(Math.min(progress, width), 0)
123
-
124
- context.rect(left, top, progress, height)
125
- context.fillStyle = progressColor
126
- context.fill()
127
-
128
- context.beginPath()
129
- }
130
-
131
- // stroke
132
- context.rect(left, top, width, height)
133
- }
134
-
135
- postrender(context: CanvasRenderingContext2D) {
136
- this.drawStroke(context)
137
- this.drawText(context)
138
- }
139
-
140
- get timeout() {
141
- return Number(this.getState('timeout') || 0)
142
- }
143
-
144
- set timeout(timeout) {
145
- this.setState('timeout', Number(timeout) || 0)
146
- }
147
-
148
- get due() {
149
- return Number(this.getState('due') || 0)
150
- }
151
-
152
- set due(due) {
153
- this.setState('due', due)
154
- }
155
-
156
- get countdown() {
157
- const due = this.due
158
- const now = Date.now()
159
-
160
- return Math.max(Math.round((due - now) / 1000), 0)
161
- }
162
-
163
- get round() {
164
- return this._round
165
- }
166
- }
167
-
168
- Component.register('duetimer', DueTimer)
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- import Timer from './timer'
2
- import DueTimer from './duetimer'
3
-
4
- export default [Timer, DueTimer]
@@ -1,47 +0,0 @@
1
- /**
2
- * 문자열 길이를 늘려주는 함수
3
- *
4
- * @param {String} i
5
- * @param {Number} len
6
- */
7
- function ii(i: string, len?: number) {
8
- var s = i
9
- len = len || 2
10
- while (s.length < len) s = '0' + s
11
- return s
12
- }
13
-
14
- /**
15
- * 시간 표시 포맷을 맞추는 함수
16
- *
17
- * @param {Number} seconds seconds
18
- * @param {string} timeFormat hh:mm:ss
19
- */
20
- export default function formatTime(seconds = 0, timeFormat = '') {
21
- var h = 0,
22
- m = 0,
23
- s = 0
24
- var formatted = ''
25
-
26
- h = Math.floor(seconds / 3600)
27
- formatted = timeFormat.replace(/(^|[^\\])hh+/g, '$1' + ii(h.toString()))
28
- formatted = formatted.replace(/(^|[^\\])h/g, '$1' + h)
29
- if (timeFormat !== formatted) {
30
- timeFormat = formatted
31
- seconds %= 3600
32
- }
33
-
34
- m = Math.floor(seconds / 60)
35
- formatted = timeFormat.replace(/(^|[^\\])mm+/g, '$1' + ii(m.toString()))
36
- formatted = formatted.replace(/(^|[^\\])m/g, '$1' + m)
37
- if (timeFormat !== formatted) {
38
- timeFormat = formatted
39
- seconds %= 60
40
- }
41
-
42
- s = seconds
43
- formatted = timeFormat.replace(/(^|[^\\])ss+/g, '$1' + ii(s.toString()))
44
- formatted = formatted.replace(/(^|[^\\])s/g, '$1' + s)
45
-
46
- return formatted
47
- }
@@ -1,23 +0,0 @@
1
- const icon = new URL('../../icons/timer.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'timer',
5
- description: 'timer',
6
- group: 'etc',
7
- /* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
8
- icon,
9
- model: {
10
- type: 'timer',
11
- left: 10,
12
- top: 10,
13
- width: 100,
14
- height: 100,
15
- strokeStyle: 'darkgray',
16
- days: 0,
17
- hours: 0,
18
- minutes: 0,
19
- seconds: 0,
20
- 'format-run': 'mm:ss',
21
- 'format-stop': '--:--'
22
- }
23
- }
@@ -1,4 +0,0 @@
1
- import timer from './timer'
2
- import duetimer from './duetimer'
3
-
4
- export default [timer, duetimer]
@@ -1,19 +0,0 @@
1
- const icon = new URL('../../icons/duetimer.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'duetimer',
5
- description: 'duetimer',
6
- group: 'etc',
7
- /* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
8
- icon,
9
- model: {
10
- type: 'duetimer',
11
- left: 10,
12
- top: 10,
13
- width: 100,
14
- height: 100,
15
- strokeStyle: 'darkgray',
16
- 'format-run': 'mm:ss',
17
- 'format-stop': '--:--'
18
- }
19
- }
package/src/timer.ts DELETED
@@ -1,193 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { Component, ComponentNature, Properties, RectPath, Shape } from '@hatiolab/things-scene'
6
-
7
- import format from './libs/format'
8
-
9
- const NATURE: ComponentNature = {
10
- mutable: false,
11
- resizable: true,
12
- rotatable: true,
13
- properties: [
14
- {
15
- type: 'number',
16
- label: 'days',
17
- name: 'days',
18
- placeholder: 'days'
19
- },
20
- {
21
- type: 'number',
22
- label: 'hours',
23
- name: 'hours',
24
- placeholder: 'hours'
25
- },
26
- {
27
- type: 'number',
28
- label: 'minutes',
29
- name: 'minutes',
30
- placeholder: 'minutes'
31
- },
32
- {
33
- type: 'number',
34
- label: 'seconds',
35
- name: 'seconds',
36
- placeholder: 'seconds'
37
- },
38
- {
39
- type: 'string',
40
- label: 'format-run',
41
- name: 'format-run',
42
- placeholder: 'hh:mm:ss'
43
- },
44
- {
45
- type: 'string',
46
- label: 'format-stop',
47
- name: 'format-stop',
48
- placeholder: '--:--:--'
49
- },
50
- {
51
- type: 'color',
52
- label: 'progress-color',
53
- name: 'progressColor',
54
- property: 'progressColor'
55
- },
56
- {
57
- type: 'select',
58
- label: 'data-reflection',
59
- name: 'dataReflection',
60
- property: {
61
- options: ['countdown', 'round']
62
- }
63
- },
64
- {
65
- type: 'boolean',
66
- label: 'repeat',
67
- name: 'repeat'
68
- }
69
- ],
70
- 'value-property': 'timeout',
71
- help: 'scene/component/timer'
72
- }
73
-
74
- export default class Timer extends RectPath(Shape) {
75
- private _due?: number
76
- private _round: number = 0
77
-
78
- get nature() {
79
- return NATURE
80
- }
81
-
82
- ready() {
83
- if (!this.app.isViewMode) {
84
- return
85
- }
86
-
87
- var { days = 0, hours = 0, minutes = 0, seconds = 0 } = this.state
88
-
89
- this.timeout = days * 86400 + hours * 3600 + minutes * 60 + seconds
90
- }
91
-
92
- onchange(after: Properties) {
93
- if ('timeout' in after) {
94
- this._due = Date.now() + this.timeout * 1000
95
- this.counting()
96
- }
97
- }
98
-
99
- counting() {
100
- // @ts-ignore
101
- if (this.disposed) {
102
- return
103
- }
104
-
105
- const { dataReflection = 'countdown' } = this.state
106
-
107
- requestAnimationFrame(() => {
108
- const countdown = this.countdown
109
-
110
- if (countdown > 0) {
111
- const text = format(countdown, this.getState('format-run'))
112
- this.text = text
113
-
114
- if (dataReflection != 'round') {
115
- this.setState('data', text)
116
- }
117
-
118
- setTimeout(() => {
119
- this.counting()
120
- }, 1000)
121
- } else {
122
- const text = format(countdown, this.getState('format-stop'))
123
- this.text = text
124
-
125
- this.setState('data', dataReflection != 'round' ? text : ++this._round)
126
-
127
- if (this.state.repeat) {
128
- this._due = Date.now() + this.timeout * 1000
129
- this.counting()
130
- }
131
- }
132
- })
133
- }
134
-
135
- render(context: CanvasRenderingContext2D) {
136
- var { top, left, height, width, progressColor = 'transparent' } = this.state
137
-
138
- // progress의 색상
139
- context.beginPath()
140
- context.rect(left, top, width, height)
141
- this.drawFill(context)
142
-
143
- // value의 색상
144
- context.beginPath()
145
-
146
- var progress = (this.countdown / this.timeout) * 100
147
-
148
- if (!isNaN(progress)) {
149
- progress = width - (width * progress) / 100
150
- progress = Math.max(Math.min(progress, width), 0)
151
-
152
- context.rect(left, top, progress, height)
153
- context.fillStyle = progressColor
154
- context.fill()
155
-
156
- context.beginPath()
157
- }
158
-
159
- // stroke
160
- context.rect(left, top, width, height)
161
- }
162
-
163
- postrender(context: CanvasRenderingContext2D) {
164
- this.drawStroke(context)
165
- this.drawText(context)
166
- }
167
-
168
- get timeout() {
169
- return Number(this.getState('timeout') || 0)
170
- }
171
-
172
- set timeout(timeout) {
173
- this.setState('timeout', Number(timeout) || 0)
174
- }
175
-
176
- get countdown() {
177
- const timeout = this.timeout
178
- if (!timeout || timeout < 0) {
179
- return 0
180
- }
181
-
182
- const due = this._due || 0
183
- const now = Date.now()
184
-
185
- return Math.max(Math.round((due - now) / 1000), 0)
186
- }
187
-
188
- get round() {
189
- return this._round
190
- }
191
- }
192
-
193
- Component.register('timer', Timer)
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2018",
4
- "module": "esnext",
5
- "moduleResolution": "node",
6
- "noEmitOnError": true,
7
- "lib": ["es2019", "dom"],
8
- "strict": true,
9
- "esModuleInterop": false,
10
- "allowJs": true,
11
- "allowSyntheticDefaultImports": true,
12
- "experimentalDecorators": true,
13
- "importHelpers": true,
14
- "outDir": "dist",
15
- "sourceMap": true,
16
- "inlineSources": true,
17
- "rootDir": "src",
18
- "declaration": true,
19
- "incremental": true,
20
- "skipLibCheck": true
21
- },
22
- "include": ["**/*.ts", "*.d.ts"]
23
- }