@operato/scene-manufacturing 1.3.18 → 1.3.20

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/tact-timer.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Component, ComponentNature, Properties, RectPath, Shape } from '@hatiolab/things-scene'
2
2
  import format from './libs/format'
3
-
4
- const mask = new URL('../icons/tact-timer-mask.svg', import.meta.url).href
3
+ import { MASK } from './tact-timer-mask'
5
4
 
6
5
  const NATURE: ComponentNature = {
7
6
  mutable: false,
@@ -34,6 +33,11 @@ const NATURE: ComponentNature = {
34
33
  options: ['', 'increase', 'decrease']
35
34
  }
36
35
  },
36
+ {
37
+ type: 'color',
38
+ label: 'tact-timer-mask-color',
39
+ name: 'maskColor'
40
+ },
37
41
  {
38
42
  type: 'color',
39
43
  label: 'increase-progress-color',
@@ -90,19 +94,9 @@ const NATURE: ComponentNature = {
90
94
  }
91
95
 
92
96
  export default class TactTimer extends RectPath(Shape) {
93
- static MASK: HTMLImageElement
94
-
95
- static get mask() {
96
- if (!TactTimer.MASK) {
97
- TactTimer.MASK = new Image()
98
- TactTimer.MASK.src = mask
99
- }
100
-
101
- return TactTimer.MASK
102
- }
103
-
104
97
  private _start: number = 0
105
98
  private _due: number = 0
99
+ private imageElement?: HTMLImageElement
106
100
 
107
101
  get nature() {
108
102
  return NATURE
@@ -136,6 +130,21 @@ export default class TactTimer extends RectPath(Shape) {
136
130
  if ('startTime' in after || 'endTime' in after) {
137
131
  this.start()
138
132
  }
133
+ if ('maskColor' in after) {
134
+ delete this.imageElement
135
+ }
136
+ }
137
+
138
+ getImageElement(): HTMLImageElement | undefined {
139
+ if (!this.imageElement) {
140
+ const { maskColor = 'black' } = this.state
141
+
142
+ this.imageElement = new Image()
143
+ this.imageElement.src =
144
+ 'data:image/svg+xml;charset=UTF-8;base64,' + btoa(MASK.replace(/{{fillColor}}/g, maskColor))
145
+ }
146
+
147
+ return this.imageElement
139
148
  }
140
149
 
141
150
  counting() {
@@ -170,6 +179,7 @@ export default class TactTimer extends RectPath(Shape) {
170
179
  width,
171
180
  round = 0,
172
181
  fontColor,
182
+ maskColor,
173
183
  increaseFontColor,
174
184
  decreaseFontColor,
175
185
  increaseProgressColor = 'transparent',
@@ -177,8 +187,7 @@ export default class TactTimer extends RectPath(Shape) {
177
187
  underThresholdColor = 'transparent',
178
188
  progressDirection = 'increase',
179
189
  progressThreshold = 0,
180
- showProgress,
181
- showTimer
190
+ showProgress
182
191
  } = this.state
183
192
 
184
193
  const increase = this.countdown > 0
@@ -220,7 +229,9 @@ export default class TactTimer extends RectPath(Shape) {
220
229
  context.beginPath()
221
230
  }
222
231
 
223
- this.drawImage(context, TactTimer.mask, left, top, width, height)
232
+ const image = this.getImageElement()
233
+ this.drawImage(context, image!, left, top, width, height)
234
+
224
235
  context.roundRect(left, top, width, height, round)
225
236
 
226
237
  this.setState('fontColor', (increase ? increaseFontColor : decreaseFontColor) || fontColor)
@@ -11,5 +11,6 @@
11
11
  "label.show-progress": "show progress",
12
12
  "label.show-timer": "show timer",
13
13
  "label.start-time": "start time",
14
- "label.end-time": "end time"
14
+ "label.end-time": "end time",
15
+ "label.tact-timer-mask-color": "mask color"
15
16
  }
@@ -11,5 +11,6 @@
11
11
  "label.show-progress": "進捗を表示",
12
12
  "label.show-timer": "タイマーを表示",
13
13
  "label.start-time": "開始時間",
14
- "label.end-time": "終了時間"
14
+ "label.end-time": "終了時間",
15
+ "label.tact-timer-mask-color": "マスクの色"
15
16
  }
@@ -11,5 +11,6 @@
11
11
  "label.show-progress": "진행색상 보이기",
12
12
  "label.show-timer": "타이머 보이기",
13
13
  "label.start-time": "시작 시간",
14
- "label.end-time": "완료 시간"
14
+ "label.end-time": "완료 시간",
15
+ "label.tact-timer-mask-color": "마스크 색상"
15
16
  }
@@ -11,5 +11,6 @@
11
11
  "label.show-progress": "tunjuk kemajuan",
12
12
  "label.show-timer": "tunjuk pemasa",
13
13
  "label.start-time": "masa mula",
14
- "label.end-time": "masa tamat"
14
+ "label.end-time": "masa tamat",
15
+ "label.tact-timer-mask-color": "warna topeng"
15
16
  }
@@ -11,5 +11,6 @@
11
11
  "label.show-progress": "显示进度",
12
12
  "label.show-timer": "显示计时器",
13
13
  "label.start-time": "开始时间",
14
- "label.end-time": "完成时间"
14
+ "label.end-time": "完成时间",
15
+ "label.tact-timer-mask-color": "遮罩颜色"
15
16
  }