@operato/scene-wheel-sorter 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.
@@ -1,117 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- import { Class, Component, ValueHolder } from '@hatiolab/things-scene'
5
-
6
- const FILL_STYLES = ['#ccc', '#afd0f1', '#ffba00', '#e9746b'] // IDLE, RUN, WARN, ERROR
7
- const STROKE_STYLES = ['#999', '#87b1db', '#d96f21', '#a73928'] // IDLE, RUN, WARN, ERROR
8
-
9
- export default (superclass: Class) => {
10
- var A = class extends ValueHolder(superclass) {
11
- animOnState() {
12
- if (this.value !== 1 || this.disposed) return
13
-
14
- var self = this
15
-
16
- var alpha = Math.floor(Math.random() * 100)
17
- if (alpha < 10) alpha = 2
18
- else if (alpha > 90) alpha = 1
19
- else alpha = 0
20
-
21
- requestAnimationFrame(function () {
22
- self.delta('tilt', alpha)
23
- self.clearCache('fillStyle')
24
- self.invalidate()
25
- })
26
- }
27
-
28
- _draw_pattern(ctx: CanvasRenderingContext2D) {
29
- var { width, height, left, top } = this.bounds
30
-
31
- var { tilt = 0, wheelSize = 3 } = this.state
32
-
33
- tilt += this.delta('tilt') || 0
34
- tilt %= 3
35
- tilt -= 1
36
-
37
- var color = FILL_STYLES[this.value] || FILL_STYLES[0]
38
- var stroke = STROKE_STYLES[this.value] || STROKE_STYLES[0]
39
- var lineWidth = 1
40
-
41
- var pattern_size = wheelSize * 10 || Math.min(width / 5, height / 5)
42
-
43
- ctx.beginPath()
44
- ctx.fillStyle = color
45
- ctx.rect(left, top, width, height)
46
- ctx.fill()
47
-
48
- ctx.strokeStyle = stroke
49
- ctx.lineWidth = lineWidth
50
-
51
- this._draw_wheel(ctx, pattern_size, tilt)
52
- }
53
-
54
- _draw_circle(ctx: CanvasRenderingContext2D, size: number) {
55
- var { width, height } = this.bounds
56
-
57
- var offsetX = 0,
58
- offsetY = 0
59
-
60
- while (offsetY < height) {
61
- offsetX = 0
62
- while (offsetX < width) {
63
- ctx.moveTo(offsetX + size / 2 + size / 3, offsetY + size / 2)
64
- ctx.ellipse(offsetX + size / 2, offsetY + size / 2, size / 3, size / 3, 0, 0, 2 * Math.PI, false)
65
-
66
- offsetX += size
67
- }
68
- offsetY += size
69
- }
70
-
71
- ctx.stroke()
72
- }
73
-
74
- _draw_inner(ctx: CanvasRenderingContext2D, size: number, tilt: number) {
75
- var { width, height } = this.bounds
76
-
77
- var offsetX = 0,
78
- offsetY = 0
79
-
80
- while (offsetY < height) {
81
- offsetX = 0
82
- while (offsetX < width) {
83
- ctx.translate(offsetX, offsetY)
84
- ctx.beginPath()
85
- ctx.translate(size / 2, size / 2)
86
- ctx.rotate(tilt)
87
-
88
- ctx.moveTo(-size / 6, -size / 6)
89
- ctx.lineTo(-size / 6, size / 6)
90
- ctx.moveTo(size / 6, -size / 6)
91
- ctx.lineTo(size / 6, size / 6)
92
-
93
- ctx.stroke()
94
- ctx.rotate(-tilt)
95
- ctx.translate(-size / 2, -size / 2)
96
- ctx.translate(-offsetX, -offsetY)
97
-
98
- offsetX += size
99
- }
100
- offsetY += size
101
- }
102
- }
103
-
104
- _draw_wheel(ctx: CanvasRenderingContext2D, size: number, tilt: number) {
105
- var { left, top } = this.bounds
106
-
107
- ctx.beginPath()
108
- ctx.translate(left, top)
109
- this._draw_circle(ctx, size)
110
- this._draw_inner(ctx, size, tilt)
111
- }
112
- }
113
-
114
- Component.memoize(A.prototype, 'fillStyle', false)
115
-
116
- return A
117
- }
package/src/scanner.ts DELETED
@@ -1,54 +0,0 @@
1
- import { Component, ComponentNature, RectPath, Shape } from '@hatiolab/things-scene'
2
-
3
- /*
4
- * Copyright © HatioLab Inc. All rights reserved.
5
- */
6
- import MixinScanner from './mixin-scanner'
7
-
8
- const NATURE: ComponentNature = {
9
- mutable: false,
10
- resizable: true,
11
- rotatable: true,
12
- properties: [
13
- {
14
- type: 'number',
15
- label: 'value',
16
- name: 'value'
17
- }
18
- ]
19
- }
20
-
21
- const STAT_IDLE = 0
22
- const STAT_RUN = 1
23
- const STAT_CHUTE_FULL = 2
24
- const STAT_ERROR = 3
25
-
26
- export default class Scanner extends MixinScanner(RectPath(Shape)) {
27
- get nature() {
28
- return NATURE
29
- }
30
-
31
- render(ctx: CanvasRenderingContext2D) {
32
- var { width, height, left, top } = this.state
33
-
34
- var radius = width / 10
35
-
36
- ctx.beginPath()
37
- ctx.moveTo(left + radius, top)
38
- ctx.lineTo(left + width - radius, top)
39
- ctx.quadraticCurveTo(left + width, top, left + width, top + radius)
40
- ctx.lineTo(left + width, top + height - radius)
41
- ctx.quadraticCurveTo(left + width, top + height, left + width - radius, top + height)
42
- ctx.lineTo(left + radius, top + height)
43
- ctx.quadraticCurveTo(left, top + height, left, top + height - radius)
44
- ctx.lineTo(left, top + radius)
45
- ctx.quadraticCurveTo(left, top, left + radius, top)
46
- ctx.clip()
47
- }
48
-
49
- is3dish() {
50
- return false
51
- }
52
- }
53
-
54
- Component.register('scanner', Scanner as any)
@@ -1,123 +0,0 @@
1
- const conveyor = new URL('../../icons/conveyor.png', import.meta.url).href
2
- const conveyorBelt = new URL('../../icons/conveyor-belt.png', import.meta.url).href
3
- const conveyorJoin = new URL('../../icons/conveyor-join.png', import.meta.url).href
4
- const conveyorJoinTrapezoid = new URL('../../icons/conveyor-join-trapezoid.png', import.meta.url).href
5
- const scanner = new URL('../../icons/scanner.png', import.meta.url).href
6
- const wheelSorter = new URL('../../icons/wheel-sorter.png', import.meta.url).href
7
-
8
- export default [
9
- {
10
- type: 'conveyor',
11
- description: 'roller type conveyor',
12
- group: 'warehouse',
13
- icon: conveyor,
14
- model: {
15
- type: 'conveyor',
16
- top: 350,
17
- left: 100,
18
- width: 500,
19
- height: 100,
20
- strokeStyle: '#999',
21
- lineWidth: 1,
22
- lineStyle: '#999',
23
- value: 1,
24
- rollWidth: 13
25
- }
26
- },
27
- {
28
- type: 'conveyor-belt',
29
- description: 'belt type conveyor',
30
- group: 'warehouse',
31
- icon: conveyorBelt,
32
- model: {
33
- type: 'conveyor-belt',
34
- top: 500,
35
- left: 100,
36
- width: 500,
37
- height: 100,
38
- strokeStyle: '#999',
39
- lineWidth: 1,
40
- lineStyle: '#999',
41
- value: 1,
42
- conveyorType: 1,
43
- rollWidth: 13
44
- }
45
- },
46
- {
47
- type: 'conveyor-join',
48
- description: 'join shaped conveyor',
49
- group: 'warehouse',
50
- icon: conveyorJoin,
51
- model: {
52
- type: 'conveyor-join',
53
- cx: 100,
54
- cy: 150,
55
- rx: 100,
56
- ry: 100,
57
- startAngle: -Math.PI / 4,
58
- endAngle: Math.PI / 4,
59
- ratio: 34,
60
- lineWidth: 1,
61
- strokeStyle: 'black',
62
- value: 2,
63
- rollWidth: 12
64
- }
65
- },
66
- {
67
- type: 'scanner',
68
- description: 'box scanner',
69
- group: 'warehouse',
70
- icon: scanner,
71
- model: {
72
- type: 'scanner',
73
- top: 100,
74
- left: 450,
75
- width: 150,
76
- height: 100,
77
- lineWidth: 1,
78
- strokeStyle: '#999',
79
- fillStyle: 'transparent',
80
- value: 2,
81
- rollWidth: 3
82
- }
83
- },
84
- {
85
- type: 'conveyor-join-trapezoid',
86
- description: 'conveyor join trapezoid',
87
- group: 'warehouse',
88
- icon: conveyorJoinTrapezoid,
89
- model: {
90
- type: 'conveyor-join-trapezoid',
91
- lineWidth: 1,
92
- path: [
93
- { x: 50, y: 150 },
94
- { x: 150, y: 150 },
95
- { x: 150, y: 250 },
96
- { x: 100, y: 300 },
97
- { x: 50, y: 250 }
98
- ],
99
- strokeStyle: '#999',
100
- fillStyle: 'transparent',
101
- value: 3,
102
- rollWidth: 10
103
- }
104
- },
105
- {
106
- type: 'wheel-sorter',
107
- description: 'wheel sorter',
108
- group: 'warehouse',
109
- icon: wheelSorter,
110
- model: {
111
- type: 'wheel-sorter',
112
- top: 50,
113
- left: 200,
114
- width: 200,
115
- height: 200,
116
- strokeStyle: '#999',
117
- fillStyle: 'transparent',
118
- lineWidth: 2,
119
- value: 1,
120
- tilt: 1
121
- }
122
- }
123
- ]
@@ -1,63 +0,0 @@
1
- import { Component, ComponentNature, RectPath, Shape } from '@hatiolab/things-scene'
2
-
3
- /*
4
- * Copyright © HatioLab Inc. All rights reserved.
5
- */
6
- import MixinWheelSorter from './mixin-wheel-sorter'
7
-
8
- const NATURE: ComponentNature = {
9
- mutable: false,
10
- resizable: true,
11
- rotatable: true,
12
- properties: [
13
- {
14
- type: 'number',
15
- label: 'tilt',
16
- name: 'tilt'
17
- },
18
- {
19
- type: 'number',
20
- label: 'wheel-size',
21
- name: 'wheelSize'
22
- },
23
- {
24
- type: 'number',
25
- label: 'value',
26
- name: 'value'
27
- },
28
- {
29
- type: 'checkbox',
30
- label: 'animation',
31
- name: 'animated'
32
- }
33
- ],
34
- help: 'scene/component/wheel-sorter'
35
- }
36
-
37
- export default class WheelSorter extends MixinWheelSorter(RectPath(Shape)) {
38
- get nature() {
39
- return NATURE
40
- }
41
-
42
- render(ctx: CanvasRenderingContext2D) {
43
- var { width, height, left, top, animated } = this.state
44
-
45
- animated && this.animOnState()
46
-
47
- ctx.beginPath()
48
- ctx.rect(left, top, width, height)
49
-
50
- ctx.clip() // bound를 벗어난 영역에도 그려지는 것을 예방.
51
- }
52
-
53
- postrender(ctx: CanvasRenderingContext2D) {
54
- super.postrender(ctx)
55
- this._draw_pattern(ctx)
56
- }
57
-
58
- is3dish() {
59
- return false
60
- }
61
- }
62
-
63
- Component.register('wheel-sorter', WheelSorter as any)
@@ -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-wheel-sorter.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-wheel-sorter-fixture">
21
- <template>
22
- <things-scene-wheel-sorter>
23
- <h2>things-scene-wheel-sorter</h2>
24
- </things-scene-wheel-sorter>
25
- </template>
26
- </test-fixture>
27
-
28
- <script>
29
- suite('<things-scene-wheel-sorter>', function() {
30
-
31
- var myEl;
32
-
33
- setup(function() {
34
- myEl = fixture('things-scene-wheel-sorter-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-wheel-sorter says, Hello World!');
44
-
45
- var greetings = myEl.sayHello('greetings Earthlings');
46
- assert.equal(greetings, 'things-scene-wheel-sorter says, greetings Earthlings');
47
- });
48
-
49
- test('fires lasers', function(done) {
50
- myEl.addEventListener('things-scene-wheel-sorter-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>
@@ -1,35 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- import './util'
5
-
6
- import { expect } from 'chai'
7
-
8
- import '../../bower_components/things-scene-core/things-scene-min'
9
- import { Conveyor } from '../../src/index'
10
-
11
- describe('Conveyor', function () {
12
-
13
- var board;
14
-
15
- beforeEach(function () {
16
- board = scene.create({
17
- model: {
18
- components: [{
19
- id: 'conveyor',
20
- type: 'conveyor',
21
- rows: 2,
22
- columns: 2
23
- }]
24
- }
25
- })
26
- });
27
-
28
- it('XXXX.', function () {
29
-
30
- var conveyor = board.findById('conveyor')
31
-
32
- expect(conveyor.get('id')).to.equal('conveyor')
33
- });
34
-
35
- });
package/test/unit/util.js DELETED
@@ -1,21 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- var noop = () => {}
5
-
6
- global.Canvas = require('canvas');
7
-
8
- Canvas.prototype.setAttribute = noop;
9
- Canvas.prototype.style = {};
10
-
11
- global.Image = Canvas.Image;
12
- global.screen = {
13
- width: 1280,
14
- height: 800
15
- };
16
-
17
- global.window = global;
18
-
19
- global.addEventListener = noop;
20
- global.location = {};
21
- global.getComputedStyle = noop;
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
- }