@operato/scene-basic 8.0.0-beta.1 → 8.0.0-beta.2

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/cloud.ts DELETED
@@ -1,40 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { Component } from '@hatiolab/things-scene'
6
-
7
- export default class Cloud extends Component {
8
- prerender(ctx: CanvasRenderingContext2D) {
9
- //TODO center()를 구현할 때까지, 아무 구현없이 오버라이드한다.
10
- }
11
-
12
- render(ctx: CanvasRenderingContext2D) {
13
- var { x, y } = this.state
14
-
15
- ctx.beginPath()
16
-
17
- ctx.moveTo(x, y)
18
-
19
- ctx.bezierCurveTo(x - 40, y + 20, x - 40, y + 70, x + 50, y + 70)
20
- ctx.bezierCurveTo(x + 80, y + 100, x + 150, y + 100, x + 170, y + 70)
21
- ctx.bezierCurveTo(x + 250, y + 70, x + 250, y + 40, x + 220, y + 30)
22
- ctx.bezierCurveTo(x + 260, y - 40, x + 200, y - 50, x + 170, y - 30)
23
- ctx.bezierCurveTo(x + 150, y - 75, x + 80, y - 60, x + 80, y - 30)
24
- ctx.bezierCurveTo(x + 30, y - 75, x - 20, y - 60, x, y)
25
-
26
- ctx.closePath()
27
- }
28
-
29
- get path() {
30
- var { x, y } = this.state
31
-
32
- return [{ x, y }]
33
- }
34
-
35
- set path(path) {
36
- /* do nothing */
37
- }
38
- }
39
-
40
- Component.register('cloud', Cloud)
package/src/donut.ts DELETED
@@ -1,92 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { Component, ComponentNature, POSITION } from '@hatiolab/things-scene'
6
- import Ellipse from './ellipse'
7
-
8
- const NATURE: ComponentNature = {
9
- mutable: false,
10
- resizable: true,
11
- rotatable: true,
12
- properties: [
13
- {
14
- type: 'number',
15
- label: 'ratio',
16
- name: 'ratio',
17
- property: 'ratio'
18
- }
19
- ],
20
- help: 'scene/component/donut'
21
- }
22
-
23
- var controlHandler = {
24
- ondragmove: function (point: POSITION, index: number, component: Component) {
25
- var { cx, rx } = component.model
26
- rx = Math.abs(rx)
27
-
28
- var transcoorded = component.transcoordP2S(point.x, point.y)
29
-
30
- var ratio = ((transcoorded.x - cx) / rx) * 100
31
-
32
- ratio = ratio >= 100 || ratio <= -100 ? 100 : Math.abs(ratio)
33
-
34
- component.set({ ratio })
35
- }
36
- }
37
-
38
- export default class Donut extends Ellipse {
39
- is3dish() {
40
- return false
41
- }
42
-
43
- render(ctx: CanvasRenderingContext2D) {
44
- var { ratio = 50, cx, cy, rx, ry, startAngle, endAngle, anticlockwise } = this.state
45
- rx = Math.abs(rx)
46
- ry = Math.abs(ry)
47
-
48
- ctx.beginPath()
49
- ctx.ellipse(cx, cy, rx, ry, 0, startAngle || 0, endAngle || 2 * Math.PI, anticlockwise)
50
-
51
- ctx.moveTo(cx + (rx / 100) * ratio, cy)
52
- // 맨 마지막 속성이 true면 원의 범위만큼 공백이 됨
53
- ctx.ellipse(cx, cy, (rx / 100) * ratio, (ry / 100) * ratio, 0, startAngle || 0, endAngle || 2 * Math.PI, true)
54
- }
55
-
56
- contains(x: number, y: number) {
57
- var { cx, cy, rx, ry, ratio } = this.state
58
- rx = Math.abs(rx)
59
- ry = Math.abs(ry)
60
-
61
- var normx = (x - cx) / (rx * 2 - 0.5)
62
- var normy = (y - cy) / (ry * 2 - 0.5)
63
- var ratiox = (x - cx) / ((rx / 100) * ratio * 2 - 0.5)
64
- var ratioy = (y - cy) / ((ry / 100) * ratio * 2 - 0.5)
65
- var result = false
66
-
67
- if (normx * normx + normy * normy < 0.25 && ratiox * ratiox + ratioy * ratioy > 0.25) result = !result
68
-
69
- return result
70
- }
71
-
72
- get controls() {
73
- var { cx, cy, rx, ratio } = this.state
74
- rx = Math.abs(rx)
75
-
76
- return [
77
- {
78
- x: cx + (rx / 100) * ratio,
79
- y: cy,
80
- handler: controlHandler
81
- }
82
- ]
83
- }
84
-
85
- get nature() {
86
- return NATURE
87
- }
88
- }
89
-
90
- Component.memoize(Donut.prototype, 'controls', false)
91
-
92
- Component.register('donut', Donut)
package/src/ellipse.ts DELETED
@@ -1,90 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { Anchor, Component, ComponentNature, Connectable, Shape } from '@hatiolab/things-scene'
6
-
7
- import ellipseAnchors from './anchors/ellipse-anchors'
8
- import ellipseOutline from './outline/ellipse-outline'
9
-
10
- const NATURE: ComponentNature = {
11
- mutable: false,
12
- resizable: true,
13
- rotatable: true,
14
- properties: [],
15
- 'value-property': 'text'
16
- }
17
-
18
- export default class Ellipse extends Connectable(Shape) {
19
- is3dish() {
20
- return true
21
- }
22
-
23
- render(context: CanvasRenderingContext2D) {
24
- var { cx, cy, rx, ry, startAngle, endAngle, anticlockwise } = this.state
25
-
26
- context.beginPath()
27
-
28
- context.ellipse(cx, cy, Math.abs(rx), Math.abs(ry), 0, startAngle || 0, endAngle || 2 * Math.PI, anticlockwise)
29
- }
30
-
31
- get path() {
32
- var { cx, cy, rx, ry } = this.state
33
-
34
- return [
35
- {
36
- x: cx - rx,
37
- y: cy - ry
38
- },
39
- {
40
- x: cx + rx,
41
- y: cy - ry
42
- },
43
- {
44
- x: cx + rx,
45
- y: cy + ry
46
- },
47
- {
48
- x: cx - rx,
49
- y: cy + ry
50
- }
51
- ]
52
- }
53
-
54
- set path(path) {
55
- var left_top = path[0]
56
- var right_bottom = path[2]
57
-
58
- this.set({
59
- cx: left_top.x + (right_bottom.x - left_top.x) / 2,
60
- cy: left_top.y + (right_bottom.y - left_top.y) / 2,
61
- rx: (right_bottom.x - left_top.x) / 2,
62
- ry: (right_bottom.y - left_top.y) / 2
63
- })
64
- }
65
-
66
- contains(x: number, y: number) {
67
- var { cx, cy, rx, ry } = this.state
68
-
69
- var normx = (x - cx) / (rx * 2 - 0.5)
70
- var normy = (y - cy) / (ry * 2 - 0.5)
71
-
72
- return normx * normx + normy * normy < 0.25
73
- }
74
-
75
- outline(progress: number) {
76
- return ellipseOutline(this, progress)
77
- }
78
-
79
- get anchors(): Array<Anchor> {
80
- return ellipseAnchors(this)
81
- }
82
-
83
- get nature() {
84
- return NATURE
85
- }
86
- }
87
-
88
- Component.memoize(Ellipse.prototype, 'path', false)
89
-
90
- Component.register('ellipse', Ellipse)
package/src/gif-view.ts DELETED
@@ -1,146 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- import { Component, ComponentNature, HTMLOverlayElement, Properties, RectPath, Shape } from '@hatiolab/things-scene'
5
- import { SuperGif } from '@wizpanda/super-gif'
6
-
7
- const NATURE: ComponentNature = {
8
- mutable: false,
9
- resizable: true,
10
- rotatable: true,
11
- properties: [
12
- {
13
- type: 'string',
14
- label: 'src',
15
- name: 'src'
16
- },
17
- {
18
- type: 'checkbox',
19
- label: 'play',
20
- name: 'play'
21
- }
22
- ],
23
- 'value-property': 'src',
24
- help: 'scene/component/gif-view'
25
- }
26
-
27
- const NOIMAGE_DATA_URI =
28
- 'data:image/gif;base64,R0lGODlhYABIAPcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0NDQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8fHyAgICEhISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDExMTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkNDQ0REREVFRUZGRkdHR0hISElJSUpKSktLS0xMTE1NTU5OTk9PT1BQUFFRUVJSUlNTU1RUVFVVVVZWVldXV1hYWFlZWVpaWltbW1xcXF1dXV5eXl9fX2BgYGFhYWJiYmNjY2RkZGVlZWZmZmdnZ2hoaGlpaWpqamtra2xsbG1tbW5ubm9vb3BwcHFxcXJycnNzc3R0dHV1dXZ2dnd3d3h4eHl5eXp6ent7e3x8fH19fX5+fn9/f4CAgIGBgYKCgoODg4SEhIWFhYaGhoeHh4iIiImJiYqKio+Pj5iYmKCgoKampqurq66urrCwsLGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrOzs7S0tLa2tre3t7m5ubu7u7+/v8DAwMHBwcPDw8XFxcfHx8vLy8/Pz9LS0tXV1dfX193d3eTk5Onp6fj4+Pz8/P7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v///////////////////////////////////////////////////////////////////////////////yH5BAkAAPUAIf47R2VuZXJhdGVkIGJ5IGpzZ2lmIChodHRwczovL2dpdGh1Yi5jb20vYW50aW1hdHRlcjE1L2pzZ2lmLykALAAAAABgAEgAAAj+AGcJHEiwoMGDCBMqXMiwocOHECNKnEixosWLGDNq3Mixo8ePIEOKHEmypMmR9VKqXMmypcuXMGPKnJkSIs2bOHPqZGlzp8+fQOv1DEq0KMyhRpMmRaq0KVCmTqPmhCq1qkyqLrFRSyYwGTVsVo1iZXmNa8Fk18ISHasSm1mDycCq/ck2JTWF1ObSfTjz7cFken3WFbow8M7BDA3rHOwXruKpfGXeTZg3qDVrUge7RRg3KLZjx+Q2HVyvLNy0QaMJjBaVdD2tZr2K/mmNIObRkR+n9AsYt0Pddg1WXppb8bWDx1CLLW74GcJnSl3TtDY8Zu2Et4tKl7n52eyWnxXvhl7+26jqrspbnlfIWjtz2gWPZV95neH8veU9NxZYfbfD3kFt99J6Bnmn0mQO9XfYezrVxxlmx0GUXIAM4hSeffsxBN1TFd5E4Ef3QZbfTg6CNJ5gHXJ3TEntLThiTh+KFCJNAqZU4kgAitjQTheepOBMNcZI0oQ6JpbTjSZtiNN2PZ400IxHpdiSc07G911M0iFZZYtAStnWilUeBGVLrlEZpmM0elmPlmfO8iOZXl4DZpsGEYmll2bSWWCXLwJXVY1+urhjoGEBSuiSah6K36CKtpZoo4s9CimielZq6aWYZqrpppx26umnoIZ6UkAAOw=='
29
-
30
- export default class GifView extends HTMLOverlayElement {
31
- _superGif?: SuperGif
32
-
33
- async oncreate_element(div: HTMLDivElement) {
34
- var { src, play } = this.state
35
-
36
- this.onchangesrc(src)
37
- this.onchangeplay(play)
38
- }
39
-
40
- buildImg() {
41
- /* clear first */
42
- var div = this.element
43
- div.innerHTML = ''
44
-
45
- var gif = document.createElement('img')
46
- gif.style.width = '100%'
47
- gif.style.height = '100%'
48
-
49
- div.appendChild(gif)
50
-
51
- return gif
52
- }
53
-
54
- onchange(after: Properties, before: Properties) {
55
- super.onchange(after, before)
56
-
57
- 'src' in after && this.onchangesrc(after.src)
58
- 'play' in after && this.onchangeplay(after.play)
59
- }
60
-
61
- setElementProperties(div: HTMLDivElement) {}
62
-
63
- onchangeplay(play: boolean) {
64
- var superGif = this._superGif
65
-
66
- if (!superGif || !superGif.isReady()) {
67
- return
68
- }
69
-
70
- if (play) {
71
- superGif.play()
72
- } else {
73
- superGif.pause()
74
- }
75
- }
76
-
77
- onchangesrc(src: string) {
78
- var gif = this.buildImg()
79
-
80
- if (!src) src = NOIMAGE_DATA_URI
81
-
82
- gif.src = src
83
- gif.setAttribute('rel:animated_src', src)
84
- gif.setAttribute('rel:auto_play', '0')
85
-
86
- this._superGif = new SuperGif(gif, {
87
- autoPlay: false /* Without this setting, the first play's framerate is too fast. */
88
- })
89
- //@ts-ignore
90
- this._superGif!.init()
91
-
92
- for (const child of this.element.children as any) {
93
- child.style.width = '100%'
94
- child.style.height = '100%'
95
- }
96
-
97
- var canvas = this._superGif!.getCanvas()
98
- canvas.style.width = '100%'
99
- canvas.style.height = '100%'
100
-
101
- this._superGif.load(() => {
102
- this._superGif!.moveTo(0)
103
-
104
- /*
105
- * FIXME. this.play 는 컴포넌트의 getState()를 통해서 가져오게 되는데, 체크박스의 경우 문제가 있는 것 같다.
106
- * 문제 해결 후 this.get("play") => this.play로 수정할 것.
107
- */
108
- this.play && this._superGif!.play()
109
- })
110
- }
111
-
112
- ondropfile(transfered: DataTransferItemList, files: FileList) {
113
- for (let i = 0; i < transfered.length; i++) {
114
- if (/\.gif$/.test((transfered[i] as any).name)) {
115
- this.src = files[i]
116
- return
117
- }
118
- }
119
- }
120
-
121
- get src() {
122
- return this.getState('src')
123
- }
124
-
125
- set src(src) {
126
- this.setState('src', src)
127
- }
128
-
129
- get play() {
130
- return this.getState('play')
131
- }
132
-
133
- set play(play) {
134
- this.setState('play', play)
135
- }
136
-
137
- get nature() {
138
- return NATURE
139
- }
140
-
141
- get tagName() {
142
- return 'div'
143
- }
144
- }
145
-
146
- Component.register('gif-view', GifView)
package/src/image-view.ts DELETED
@@ -1,215 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { error, Component, ComponentNature, Properties, RectPath, Shape } from '@hatiolab/things-scene'
6
-
7
- const NATURE: ComponentNature = {
8
- mutable: false,
9
- resizable: true,
10
- rotatable: true,
11
- properties: [
12
- {
13
- type: 'image-selector',
14
- label: 'image-src',
15
- name: 'src',
16
- property: {
17
- displayField: 'id',
18
- displayFullUrl: true,
19
- baseUrlAlias: '$base_url',
20
- defaultStorage: 'scene-image',
21
- storageFilters: {
22
- type: Array,
23
- value: [
24
- {
25
- name: 'category',
26
- value: 'image'
27
- }
28
- ]
29
- },
30
- useUpload: true
31
- }
32
- },
33
- {
34
- type: 'select',
35
- label: 'cross-origin',
36
- name: 'crossOrigin',
37
- property: {
38
- options: ['', 'anonymous', 'use-credentials']
39
- }
40
- }
41
- ],
42
- 'value-property': 'src',
43
- help: 'scene/component/image-view'
44
- }
45
-
46
- const NOIMAGE_DATA_URI =
47
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABIBAMAAAD7Se1QAAAAIVBMVEUAAABHcEwBAQEREREBAQEEBAQGBgYLCwsDAwMDAwMICAi6HF9tAAAAC3RSTlNNAEAERiMYCS41Eac10lYAAAEgSURBVHhe7dY9asQwEAXgh7DNertNiJy48pIitY3SB7bYdk0ukL1BDDmA9gZecoH4pmFQ3MQayUMguPBrNPD4wD9TCMvJmt3M/AtYwXOlXiWgqADVCUBD46MAnGhMBaCiUQmAm8VA/Eh/eWl9Fn5WcxD+OLuRrUYJDKLluwH2InACUgkoACSdADxQc50Bytadb9RkM0CT13TcvlCT1HFg8UTHvasuUVACCa3El6u2UdD8LFTlKhUFFgA+d3dj10aABkUN72N3jAADCrJq7PIIsPidcxBoTHIIAjMFmyCwmGYIAA1P9gFgfCANAOsDSccCDW+uLDB+kLGg94OkZoAGkwsDDAe2DOg5oPxAg03rBR88OHpBz4N8UVeHFSwma74BTW6Ge4rIRa4AAAAASUVORK5CYII='
48
-
49
- export default class ImageView extends RectPath(Shape) {
50
- static NOIMAGE?: any
51
-
52
- static get noimage() {
53
- if (!ImageView.NOIMAGE) {
54
- ImageView.NOIMAGE = new Image()
55
- ImageView.NOIMAGE.src = NOIMAGE_DATA_URI
56
- }
57
-
58
- return ImageView.NOIMAGE
59
- }
60
-
61
- _offcanvas?: HTMLCanvasElement
62
- _image?: any
63
-
64
- dispose() {
65
- super.dispose()
66
- delete this._offcanvas
67
- delete this._image
68
- }
69
-
70
- render(ctx: CanvasRenderingContext2D) {
71
- var { left, top, width, height, isGray = false, alpha = 1, src } = this.state
72
-
73
- this.prepareIf(!this._image && src)
74
-
75
- // 박스 그리기
76
- ctx.beginPath()
77
- ctx.globalAlpha *= alpha
78
-
79
- if (this._image && this._image.complete) {
80
- if (isGray && this._offcanvas) {
81
- ctx.drawImage(this._offcanvas, left, top, width, height)
82
- } else {
83
- try {
84
- ctx.drawImage(this._image, left, top, width, height)
85
- } catch (e) {
86
- ctx.drawImage(ImageView.noimage, left, top, width, height)
87
- }
88
- }
89
- } else {
90
- !this.app.isViewMode && ctx.drawImage(ImageView.noimage, left, top, width, height)
91
- }
92
- }
93
-
94
- get nature() {
95
- return NATURE
96
- }
97
-
98
- get hasTextProperty() {
99
- return false
100
- }
101
-
102
- ready() {
103
- super.ready()
104
- this.prepareIf(!this._image && this.state.src)
105
- }
106
-
107
- prepare(resolve: (ret?: any) => void, reject: (e?: any) => void) {
108
- var { src, crossOrigin } = this.state
109
-
110
- if (!src) {
111
- resolve(this)
112
- return
113
- }
114
-
115
- this._image = new Image()
116
-
117
- try {
118
- if (crossOrigin) {
119
- this._image.crossOrigin = crossOrigin
120
- }
121
-
122
- this._image.src = this.app.url(src) || ''
123
- } catch (e) {
124
- reject(e)
125
- return
126
- }
127
-
128
- this._image.onload = () => {
129
- if (this.getState('isGray')) {
130
- let width = this._image.width
131
- let height = this._image.height
132
-
133
- this._offcanvas = Component.createCanvas(width, height)
134
-
135
- let offcontext = this._offcanvas!.getContext('2d') as CanvasRenderingContext2D
136
- offcontext!.drawImage(this._image, 0, 0)
137
-
138
- let imageData = makeGrayImage(offcontext, width, height)
139
- offcontext!.putImageData(imageData!, 0, 0)
140
- }
141
-
142
- resolve(this)
143
- }
144
-
145
- this._image.onerror = (e: any) => {
146
- if (this._image && !this._image.currentSrc) this._image = null
147
- reject(e)
148
- }
149
- }
150
-
151
- get src() {
152
- return this.getState('src')
153
- }
154
-
155
- set src(src) {
156
- this.setState('src', src)
157
- }
158
-
159
- onchange(after: Properties, before: Properties) {
160
- if (after.hasOwnProperty('src') || after.hasOwnProperty('isGray')) {
161
- delete this._offcanvas
162
- delete this._image
163
- this.prepareIf(after.src)
164
- }
165
- }
166
-
167
- ondropfile(transfered: DataTransferItemList, files: FileList) {
168
- for (let i = 0; i < transfered.length; i++) {
169
- if (transfered[i].type.startsWith('image/')) {
170
- this.src = files[i]
171
- return
172
- }
173
- }
174
- }
175
- }
176
-
177
- function makeGrayImage(ctx: CanvasRenderingContext2D, width: number, height: number) {
178
- try {
179
- var img = ctx.getImageData(0, 0, width, height)
180
- } catch (e: any) {
181
- error('Get Image Data Error: ' + e.message)
182
- return null
183
- }
184
-
185
- var data = img.data
186
- // Loop through data.
187
- for (let i = 0; i < width * height * 4; i += 4) {
188
- // First bytes are red bytes.
189
- // Get red value.
190
- let red = data[i]
191
-
192
- // Second bytes are green bytes.
193
- // Get green value.
194
- let green = data[i + 1]
195
-
196
- // Third bytes are blue bytes.
197
- // Get blue value.
198
- let blue = data[i + 2]
199
-
200
- // Fourth bytes are alpha bytes
201
- // We don't care about alpha here.
202
- // Add the three values and divide by three.
203
- // Make it an integer.
204
- let gray = parseInt(String((red + green + blue) / 3))
205
-
206
- // Assign average to red, green, and blue.
207
- img.data[i] = gray
208
- img.data[i + 1] = gray
209
- img.data[i + 2] = gray
210
- }
211
-
212
- return img
213
- }
214
-
215
- Component.register('image-view', ImageView)
package/src/index.ts DELETED
@@ -1,16 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- export { default as Ellipse } from './ellipse'
6
- export { default as Rect } from './rect'
7
- export { default as Polygon } from './polygon'
8
- export { default as Polyline } from './polyline'
9
- export { default as ImageView } from './image-view'
10
- export { default as GifView } from './gif-view'
11
- export { default as AudioPlayer } from './audio'
12
- export { default as Text } from './text'
13
-
14
- export { default as Triangle } from './triangle'
15
- export { default as Donut } from './donut'
16
- export { default as Star } from './star'
@@ -1,15 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { Component } from '@hatiolab/things-scene'
6
-
7
- export default function ellipseOutline(component: Component, progress: number) {
8
- var { cx, cy, rx, ry } = component.model
9
- var theta = Math.PI * 2 * progress
10
-
11
- var x = cx + rx * Math.cos(theta)
12
- var y = cy + ry * Math.sin(theta)
13
-
14
- return component.transcoordS2T(x, y)
15
- }