@operato/scene-clock 8.0.0-beta.1 → 9.0.0-beta.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.
@@ -1,183 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { Component, ComponentNature, Ellipse } from '@hatiolab/things-scene'
6
-
7
- const NATURE: ComponentNature = {
8
- mutable: false,
9
- resizable: true,
10
- rotatable: true,
11
- properties: [
12
- {
13
- type: 'number',
14
- label: 'hour-width',
15
- name: 'hourWidth',
16
- property: 'hourWidth'
17
- },
18
- {
19
- type: 'number',
20
- label: 'minute-width',
21
- name: 'minuteWidth',
22
- property: 'minuteWidth'
23
- },
24
- {
25
- type: 'number',
26
- label: 'second-width',
27
- name: 'secondWidth',
28
- property: 'secondWidth'
29
- },
30
- {
31
- type: 'checkbox',
32
- label: 'needle-round',
33
- name: 'needleRound',
34
- property: 'needleRound'
35
- },
36
- {
37
- type: 'checkbox',
38
- label: 'show-second',
39
- name: 'showSecond',
40
- property: 'showSecond'
41
- },
42
- {
43
- type: 'checkbox',
44
- label: 'show-number',
45
- name: 'showNumber',
46
- property: 'showNumber'
47
- },
48
- {
49
- type: 'number',
50
- label: 'inner-circle-size',
51
- name: 'innerCircleSize',
52
- property: 'innerCircleSize'
53
- },
54
- {
55
- type: 'color',
56
- label: 'inner-circle-color',
57
- name: 'innerCircleColor',
58
- property: 'innerCircleColor'
59
- }
60
- ],
61
- help: 'scene/component/analog-clock'
62
- }
63
-
64
- function drawHand(ctx: CanvasRenderingContext2D, pos: number, length: number, rx: number, needleRound: boolean) {
65
- ctx.beginPath()
66
- ctx.lineWidth = rx
67
- ctx.lineCap = needleRound ? 'round' : 'square'
68
- ctx.moveTo(0, 0)
69
- ctx.rotate(pos)
70
- ctx.lineTo(0, -length)
71
- ctx.stroke()
72
- ctx.rotate(-pos)
73
- }
74
-
75
- export default class ClockAnalog extends Ellipse {
76
- is3dish() {
77
- return false
78
- }
79
-
80
- render(ctx: CanvasRenderingContext2D) {
81
- var {
82
- cx,
83
- cy,
84
- rx,
85
- ry,
86
- fillStyle,
87
- strokeStyle,
88
- fontColor = '#000',
89
- lineWidth,
90
- hourWidth,
91
- minuteWidth,
92
- secondWidth,
93
- needleRound = false,
94
- showSecond = true,
95
- showNumber = true,
96
- innerCircleSize = 5,
97
- innerCircleColor = '#000'
98
- } = this.state
99
-
100
- // 시계 원 그리기.
101
- ctx.beginPath()
102
- ctx.ellipse(cx, cy, Math.abs(rx), Math.abs(ry), 0, 0, 2 * Math.PI)
103
-
104
- ctx.fillStyle = fillStyle
105
-
106
- ctx.strokeStyle = strokeStyle
107
- ctx.lineWidth = lineWidth || rx * 0.1
108
- this.drawFill(ctx)
109
- this.drawStroke(ctx)
110
-
111
- ctx.beginPath()
112
- ctx.translate(cx, cy)
113
- ctx.scale(1, ry / rx)
114
-
115
- // 시계 숫자 그리기
116
- if (showNumber) {
117
- var ang
118
- var num
119
- ctx.font = rx * 0.15 + 'px arial'
120
- ctx.textBaseline = 'middle'
121
- ctx.textAlign = 'center'
122
- ctx.fillStyle = fontColor
123
-
124
- for (num = 1; num < 13; num++) {
125
- ang = (num * Math.PI) / 6
126
- ctx.rotate(ang)
127
- ctx.translate(0, -rx * 0.85)
128
- ctx.rotate(-ang)
129
- ctx.fillText(num.toString(), 0, 0)
130
- ctx.rotate(ang)
131
- ctx.translate(0, rx * 0.85)
132
- ctx.rotate(-ang)
133
- }
134
- }
135
-
136
- // 시계 침 그리기
137
- var now = new Date()
138
- var hour = now.getHours()
139
- var minute = now.getMinutes()
140
- var second = now.getSeconds()
141
-
142
- // hour needle
143
- hour = hour % 12
144
- hour = (hour * Math.PI) / 6 + (minute * Math.PI) / (6 * 60) + (second * Math.PI) / (360 * 60)
145
-
146
- drawHand(ctx, hour, rx * 0.55, hourWidth || rx * 0.07, needleRound)
147
-
148
- // minute needle
149
- minute = (minute * Math.PI) / 30 + (second * Math.PI) / (30 * 60)
150
- drawHand(ctx, minute, rx * 0.8, minuteWidth || rx * 0.07, needleRound)
151
-
152
- // second needle
153
- if (showSecond) {
154
- second = (second * Math.PI) / 30
155
- drawHand(ctx, second, rx * 0.9, secondWidth || rx * 0.02, needleRound)
156
- }
157
-
158
- ctx.beginPath()
159
-
160
- // Inner Circle
161
- if (innerCircleSize) {
162
- ctx.ellipse(0, 0, innerCircleSize, innerCircleSize, 0, 0, 2 * Math.PI)
163
- ctx.fillStyle = innerCircleColor
164
- ctx.fill()
165
- }
166
-
167
- ctx.beginPath()
168
-
169
- ctx.scale(1, rx / ry)
170
- ctx.translate(-cx, -cy)
171
-
172
- var timeOut = setTimeout(() => {
173
- this.invalidate()
174
- clearTimeout(timeOut)
175
- }, 1000)
176
- }
177
-
178
- get nature() {
179
- return NATURE
180
- }
181
- }
182
-
183
- Component.register('clock-analog', ClockAnalog)
package/src/clock-text.ts DELETED
@@ -1,112 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import 'dayjs/esm/locale/ko'
6
- import 'dayjs/esm/locale/zh-cn'
7
- import 'dayjs/esm/locale/ja'
8
-
9
- import dayjs from 'dayjs/esm/index'
10
- import utc from 'dayjs/esm/plugin/utc'
11
-
12
- import { Component, ComponentNature, Text } from '@hatiolab/things-scene'
13
-
14
- dayjs.extend(utc)
15
-
16
- const NATURE: ComponentNature = {
17
- mutable: false,
18
- resizable: true,
19
- rotatable: true,
20
- properties: [
21
- {
22
- type: 'string',
23
- label: 'time-format',
24
- name: 'timeFormat'
25
- },
26
- {
27
- type: 'checkbox',
28
- label: 'is-local-time',
29
- name: 'localTime'
30
- },
31
- {
32
- type: 'number',
33
- label: 'utc',
34
- name: 'utc'
35
- },
36
- {
37
- type: 'select',
38
- label: 'week-language',
39
- name: 'weekLanguage',
40
- property: {
41
- options: [
42
- {
43
- display: 'English',
44
- value: 'en'
45
- },
46
- {
47
- display: 'Korean',
48
- value: 'ko'
49
- },
50
- {
51
- display: 'Chinese',
52
- value: 'zh-cn'
53
- },
54
- {
55
- display: 'Japanese',
56
- value: 'ja'
57
- }
58
- ]
59
- }
60
- }
61
- ],
62
- help: 'scene/component/clock-text'
63
- }
64
-
65
- export default class ClockText extends Text {
66
- private _raf?: number
67
-
68
- is3dish() {
69
- return false
70
- }
71
-
72
- get nature() {
73
- return NATURE
74
- }
75
-
76
- ready() {
77
- this.timing()
78
- }
79
-
80
- timing() {
81
- this._raf = requestAnimationFrame(() => {
82
- setTimeout(() => {
83
- this.setState('data', this._getTimeStamp())
84
-
85
- this.timing()
86
- }, 1000)
87
- })
88
- }
89
-
90
- _getTimeStamp() {
91
- var d = dayjs()
92
-
93
- var utc = this.getState('utc')
94
- var formatStr = this.getState('timeFormat') || 'YYYY-MM-DD HH:mm:ss'
95
- var week_lang = this.getState('weekLanguage')
96
- if (!this.getState('weekLanguage')) {
97
- week_lang = 'en'
98
- }
99
- if (this.getState('localTime')) {
100
- return d.local().locale(week_lang).format(formatStr)
101
- } else {
102
- return d.utc().utcOffset(Number(utc)).locale(week_lang).format(formatStr)
103
- }
104
- }
105
-
106
- dispose() {
107
- super.dispose()
108
- this._raf !== undefined && cancelAnimationFrame(this._raf)
109
- }
110
- }
111
-
112
- Component.register('clock-text', ClockText)
package/src/index.ts DELETED
@@ -1,5 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- export { default as ClockAnalog } from './clock-analog'
5
- export { default as ClockText } from './clock-text'
@@ -1,67 +0,0 @@
1
- <!doctype html>
2
- <!--
3
- @license
4
- Copyright © HatioLab Inc. All rights reserved.
5
- -->
6
- <html>
7
- <head>
8
- <meta charset="utf-8">
9
- <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
10
-
11
- <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
12
- <script src="../../web-component-tester/browser.js"></script>
13
-
14
- <!-- Step 1: import the element to test -->
15
- <link rel="import" href="../things-scene-clock.html">
16
- </head>
17
- <body>
18
-
19
- <!-- You can use the document as a place to set up your fixtures. -->
20
- <test-fixture id="things-scene-clock-fixture">
21
- <template>
22
- <things-scene-clock>
23
- <h2>things-scene-clock</h2>
24
- </things-scene-clock>
25
- </template>
26
- </test-fixture>
27
-
28
- <script>
29
- suite('<things-scene-clock>', function() {
30
-
31
- var myEl;
32
-
33
- setup(function() {
34
- myEl = fixture('things-scene-clock-fixture');
35
- });
36
-
37
- test('defines the "author" property', function() {
38
- assert.equal(myEl.author.name, 'Dimitri Glazkov');
39
- assert.equal(myEl.author.image, 'http://addyosmani.com/blog/wp-content/uploads/2013/04/unicorn.jpg');
40
- });
41
-
42
- test('says hello', function() {
43
- assert.equal(myEl.sayHello(), 'things-scene-clock says, Hello World!');
44
-
45
- var greetings = myEl.sayHello('greetings Earthlings');
46
- assert.equal(greetings, 'things-scene-clock says, greetings Earthlings');
47
- });
48
-
49
- test('fires lasers', function(done) {
50
- myEl.addEventListener('things-scene-clock-lasers', function(event) {
51
- assert.equal(event.detail.sound, 'Pew pew!');
52
- done();
53
- });
54
- myEl.fireLasers();
55
- });
56
-
57
- test('distributed children', function() {
58
- var els = myEl.getContentChildren();
59
- assert.equal(els.length, 1, 'one distributed node');
60
- assert.equal(els[0], myEl.querySelector('h2'), 'content distributed correctly');
61
- });
62
-
63
- });
64
- </script>
65
-
66
- </body>
67
- </html>
package/test/index.html DELETED
@@ -1,22 +0,0 @@
1
- <!doctype html>
2
- <!--
3
- @license
4
- Copyright © HatioLab Inc. All rights reserved.
5
- -->
6
- <html><head>
7
- <meta charset="utf-8">
8
- <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
9
-
10
- <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
11
- <script src="../../web-component-tester/browser.js"></script>
12
- </head>
13
- <body>
14
- <script>
15
- // Load and run all tests (.html, .js):
16
- WCT.loadSuites([
17
- 'basic-test.html',
18
- 'basic-test.html?dom=shadow'
19
- ]);
20
- </script>
21
-
22
- </body></html>
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
- }