@operato/scene-basic 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.
package/src/polygon.ts DELETED
@@ -1,103 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { Component, ComponentNature, POINT, POSITION, Shape } from '@hatiolab/things-scene'
6
-
7
- var controlHandler = {
8
- ondragstart: function (point: POSITION, index: number, component: Component) {
9
- component.mutatePath(null, function (path: Array<POINT>) {
10
- path.splice(index + 1, 0, point)
11
- })
12
- },
13
-
14
- ondragmove: function (point: POSITION, index: number, component: Component) {
15
- component.mutatePath(null, function (path: Array<POINT>) {
16
- path[index + 1] = point
17
- })
18
- },
19
-
20
- ondragend: function (point: POSITION, index: number, component: Component) {}
21
- }
22
-
23
- const NATURE: ComponentNature = {
24
- mutable: true,
25
- resizable: false,
26
- rotatable: true,
27
- properties: [
28
- {
29
- type: 'number',
30
- label: 'round',
31
- name: 'round',
32
- property: {
33
- min: 0,
34
- max: 100,
35
- step: 1
36
- }
37
- }
38
- ],
39
- help: 'scene/component/polygon'
40
- }
41
-
42
- export default class Polygon extends Shape {
43
- is3dish() {
44
- return true
45
- }
46
-
47
- get mutable() {
48
- return true
49
- }
50
-
51
- get pathExtendable() {
52
- return true
53
- }
54
-
55
- get path() {
56
- return this.state.path
57
- }
58
-
59
- set path(path) {
60
- this.setState('path', path)
61
- }
62
-
63
- contains(x: number, y: number) {
64
- var path = this.state.path as Array<POINT>
65
- var result = false
66
-
67
- path.forEach((p, idx) => {
68
- let j = (idx + path.length + 1) % path.length
69
-
70
- let x1 = p.x
71
- let y1 = p.y
72
- let x2 = path[j].x
73
- let y2 = path[j].y
74
-
75
- if (y1 > y != y2 > y && x < ((x2 - x1) * (y - y1)) / (y2 - y1) + x1) result = !result
76
- })
77
-
78
- return result
79
- }
80
-
81
- get controls() {
82
- // 폴리곤에서의 control은 새로운 path를 추가하는 포인트이다.
83
- var path = this.path as Array<POINT>
84
-
85
- return path.map((p1, i) => {
86
- let p2 = path[i + 1 >= path.length ? 0 : i + 1]
87
-
88
- return {
89
- x: (p1.x + p2.x) / 2,
90
- y: (p1.y + p2.y) / 2,
91
- handler: controlHandler
92
- }
93
- })
94
- }
95
-
96
- get nature() {
97
- return NATURE
98
- }
99
- }
100
-
101
- Component.memoize(Polygon.prototype, 'controls', false)
102
-
103
- Component.register('polygon', Polygon)
package/src/polyline.ts DELETED
@@ -1,122 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- import { Component, ComponentNature, Properties, Line, POSITION } from '@hatiolab/things-scene'
5
-
6
- var controlHandler = {
7
- ondragstart: function (point: POSITION, index: number, component: Component) {
8
- component.mutatePath(null, function (path) {
9
- path.splice(index, 0, point) // array.insert(index, point) 의 의미임.
10
- })
11
- },
12
-
13
- ondragmove: function (point: POSITION, index: number, component: Component) {
14
- component.mutatePath(null, function (path) {
15
- path[index] = point
16
- })
17
- },
18
-
19
- ondragend: function (point: POSITION, index: number, component: Component) {}
20
- }
21
-
22
- const NATURE: ComponentNature = {
23
- mutable: false,
24
- resizable: false,
25
- rotatable: false,
26
- properties: [
27
- {
28
- type: 'number',
29
- label: 'round',
30
- name: 'round',
31
- property: {
32
- min: 0,
33
- max: 100,
34
- step: 1
35
- }
36
- }
37
- ],
38
- help: 'scene/component/polyline'
39
- }
40
-
41
- export default class Polyline extends Line {
42
- _fromEnd: any
43
- _toEnd: any
44
-
45
- get pathExtendable() {
46
- return true
47
- }
48
-
49
- get path() {
50
- const { from, to } = this.state
51
- const { path } = this.state
52
-
53
- return [
54
- this.fromEnd?.position || from?.position || path[0],
55
- ...path.slice(1, -1),
56
- this.toEnd?.position || to?.position || path[path.length - 1]
57
- ]
58
- }
59
-
60
- set path(path) {
61
- const { from, to } = this.state
62
-
63
- delete this._fromEnd
64
- delete this._toEnd
65
-
66
- this.set({
67
- from: {
68
- ...from,
69
- position: path[0]
70
- },
71
- to: {
72
- ...to,
73
- position: path[path.length - 1]
74
- },
75
- path
76
- })
77
- }
78
-
79
- get controls() {
80
- // 폴리라인에서의 control은 새로운 path를 추가하는 포인트이다.
81
- var path = this.path
82
- var controls = []
83
-
84
- for (let i = 0; i < path.length - 1; i++) {
85
- let p1 = path[i]
86
- let p2 = path[i + 1]
87
-
88
- if (i == 0) {
89
- controls.push({
90
- x: p1.x,
91
- y: p1.y,
92
- handler: controlHandler
93
- })
94
- }
95
-
96
- controls.push({
97
- x: (p1.x + p2.x) / 2,
98
- y: (p1.y + p2.y) / 2,
99
- handler: controlHandler
100
- })
101
-
102
- if (i == path.length - 2) {
103
- controls.push({
104
- x: p2.x,
105
- y: p2.y,
106
- handler: controlHandler
107
- })
108
- }
109
- }
110
-
111
- return controls
112
- }
113
-
114
- get nature() {
115
- return NATURE
116
- }
117
- }
118
-
119
- /* target anchor의 움직임이 반영되지 못하므로, 일단 controls memoize를 제거함. */
120
- // Component.memoize(Polyline.prototype, 'controls', false)
121
-
122
- Component.register('polyline', Polyline)
package/src/rect.ts DELETED
@@ -1,71 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { Component, ComponentNature, Connectable, POSITION, 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: 'number',
14
- label: 'round',
15
- name: 'round',
16
- property: {
17
- min: 0
18
- }
19
- }
20
- ],
21
- help: 'scene/component/rect'
22
- }
23
-
24
- var controlHandler = {
25
- ondragmove: function (point: POSITION, index: number, component: Component) {
26
- var { left, top, width, height } = component.model
27
-
28
- var transcoorded = component.transcoordP2S(point.x, point.y)
29
- var round = ((transcoorded.x - left) / (width / 2)) * 100
30
-
31
- round = safeRound(round, width, height)
32
-
33
- component.set({
34
- round
35
- })
36
- }
37
- }
38
-
39
- function safeRound(round: number, width: number, height: number) {
40
- var max = width > height ? (height / width) * 100 : 100
41
-
42
- if (round >= max) round = max
43
- else if (round <= 0) round = 0
44
-
45
- return round
46
- }
47
-
48
- export default class Rect extends Connectable(RectPath(Shape)) {
49
- is3dish() {
50
- return true
51
- }
52
-
53
- get controls() {
54
- var { left, top, width, round, height } = this.state
55
- round = round == undefined ? 0 : safeRound(round, width, height)
56
-
57
- return [
58
- {
59
- x: left + (width / 2) * (round / 100),
60
- y: top,
61
- handler: controlHandler
62
- }
63
- ]
64
- }
65
-
66
- get nature() {
67
- return NATURE
68
- }
69
- }
70
-
71
- Component.register('rect', Rect)
package/src/star.ts DELETED
@@ -1,104 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { Component, ComponentNature, Ellipse, POSITION } 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: 'ratio',
15
- name: 'ratio',
16
- property: 'ratio'
17
- },
18
- {
19
- type: 'number',
20
- label: 'wing',
21
- name: 'wing',
22
- property: 'wing'
23
- }
24
- ],
25
- help: 'scene/component/star'
26
- }
27
-
28
- var controlHandler = {
29
- ondragmove: function (point: POSITION, index: number, component: Component) {
30
- var controls = component.controls
31
- var { cy, ry } = component.model
32
-
33
- var transcoorded = component.transcoordP2S(point.x, point.y)
34
-
35
- var ratio = ((transcoorded.y - cy) / ry) * 100 + 100
36
-
37
- if (ratio >= 100) ratio = 100
38
- else if (ratio <= 0) ratio = 0
39
-
40
- component.set({ ratio }) // ratio: ratio => ratio
41
- }
42
- }
43
-
44
- export default class Star extends Ellipse {
45
- is3dish() {
46
- return false
47
- }
48
-
49
- render(ctx: CanvasRenderingContext2D) {
50
- var { ratio = 30, wing = 5, cx, cy, rx, ry, startAngle, endAngle, anticlockwise } = this.state
51
-
52
- // 박스 그리기
53
-
54
- if (wing < 3) return
55
-
56
- const RADIAN = 1.5707963267948966 // 90도 뒤틀기
57
- var a = (Math.PI * 2) / wing
58
- var xRatio = rx - (ratio / 100) * rx
59
- var yRatio = ry - (ratio / 100) * ry
60
-
61
- ctx.save()
62
- ctx.beginPath()
63
-
64
- ctx.translate(cx, cy)
65
-
66
- ctx.moveTo(rx * Math.cos(-RADIAN), ry * Math.sin(-RADIAN))
67
- ctx.lineTo(
68
- ((rx - xRatio) * (Math.cos(a - RADIAN) + Math.cos(0 - RADIAN))) / 2,
69
- ((ry - yRatio) * (Math.sin(a - RADIAN) + Math.sin(0 - RADIAN))) / 2
70
- )
71
-
72
- for (var i = 1; i < wing; i++) {
73
- ctx.lineTo(rx * Math.cos(a * i - RADIAN), ry * Math.sin(a * i - RADIAN))
74
-
75
- ctx.lineTo(
76
- ((rx - xRatio) * (Math.cos(a * (i + 1) - RADIAN) + Math.cos(a * i - RADIAN))) / 2,
77
- ((ry - yRatio) * (Math.sin(a * (i + 1) - RADIAN) + Math.sin(a * i - RADIAN))) / 2
78
- )
79
- }
80
- // ratio /= 1.5;
81
- ctx.closePath()
82
- ctx.restore()
83
- }
84
-
85
- get controls() {
86
- var { cx, cy, ry, ratio } = this.state
87
-
88
- return [
89
- {
90
- x: cx,
91
- y: cy - ry + ry * (ratio / 100),
92
- handler: controlHandler
93
- }
94
- ]
95
- }
96
-
97
- get nature() {
98
- return NATURE
99
- }
100
- }
101
-
102
- Component.memoize(Star.prototype, 'controls', false)
103
-
104
- Component.register('star', Star)
@@ -1,15 +0,0 @@
1
- const audio = new URL('../../icons/audio.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'audio',
5
- description: 'audio',
6
- icon: audio,
7
- group: 'textAndMedia',
8
- model: {
9
- type: 'audio',
10
- left: 100,
11
- top: 100,
12
- width: 100,
13
- height: 100
14
- }
15
- }
@@ -1,23 +0,0 @@
1
- const colorImage = new URL('../../icons/color-image.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'color image',
5
- description: 'color image',
6
- icon: colorImage,
7
- group: 'textAndMedia',
8
- model: {
9
- type: 'image-view',
10
- left: 100,
11
- top: 100,
12
- width: 100,
13
- height: 100,
14
- isGray: false,
15
- fillStyle: '#fff',
16
- strokeStyle: '#000',
17
- alpha: 1,
18
- hidden: false,
19
- lineWidth: 1,
20
- lineDash: 'solid',
21
- lineCap: 'butt'
22
- }
23
- }
@@ -1,23 +0,0 @@
1
- const donut = new URL('../../icons/donut.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'donut',
5
- description: 'donut shape',
6
- icon: donut,
7
- group: 'shape',
8
- model: {
9
- type: 'donut',
10
- rx: 50,
11
- ry: 50,
12
- cx: 150,
13
- cy: 150,
14
- ratio: 30,
15
- fillStyle: '#fff',
16
- strokeStyle: '#000',
17
- alpha: 1,
18
- hidden: false,
19
- lineWidth: 1,
20
- lineDash: 'solid',
21
- lineCap: 'butt'
22
- }
23
- }
@@ -1,22 +0,0 @@
1
- const ellipse = new URL('../../icons/ellipse.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'ellipse',
5
- description: 'ellipse shape',
6
- icon: ellipse,
7
- group: 'shape',
8
- model: {
9
- type: 'ellipse',
10
- rx: 50,
11
- ry: 50,
12
- cx: 150,
13
- cy: 150,
14
- fillStyle: '#fff',
15
- strokeStyle: '#000',
16
- alpha: 1,
17
- hidden: false,
18
- lineWidth: 1,
19
- lineDash: 'solid',
20
- lineCap: 'butt'
21
- }
22
- }
@@ -1,15 +0,0 @@
1
- const gifImage = new URL('../../icons/gif-image.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'gif image',
5
- description: 'gif image',
6
- icon: gifImage,
7
- group: 'textAndMedia',
8
- model: {
9
- type: 'gif-view',
10
- left: 100,
11
- top: 100,
12
- width: 100,
13
- height: 100
14
- }
15
- }
@@ -1,23 +0,0 @@
1
- const grayImage = new URL('../../icons/gray-image.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'gray image',
5
- description: 'gray image',
6
- icon: grayImage,
7
- group: 'textAndMedia',
8
- model: {
9
- type: 'image-view',
10
- left: 100,
11
- top: 100,
12
- width: 100,
13
- height: 100,
14
- isGray: true,
15
- fillStyle: '#fff',
16
- strokeStyle: '#000',
17
- alpha: 1,
18
- hidden: false,
19
- lineWidth: 1,
20
- lineDash: 'solid',
21
- lineCap: 'butt'
22
- }
23
- }
@@ -1,16 +0,0 @@
1
- // IMPORT
2
-
3
- import audio from './audio'
4
- import text from './text'
5
- import colorImage from './color-image'
6
- import grayImage from './gray-image'
7
- import donut from './donut'
8
- import gifImage from './gif-image'
9
- import ellipse from './ellipse'
10
- import polyline from './polyline'
11
- import polygon from './polygon'
12
- import rect from './rect'
13
- import star from './star'
14
- import triangle from './triangle'
15
-
16
- export default [audio, colorImage, grayImage, gifImage, ellipse, donut, polyline, polygon, rect, star, text, triangle]
@@ -1,25 +0,0 @@
1
- const polygon = new URL('../../icons/polygon.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'polygon',
5
- description: 'polygon shape',
6
- icon: polygon,
7
- group: 'shape',
8
- model: {
9
- type: 'polygon',
10
- path: [
11
- { x: 100, y: 100 },
12
- { x: 200, y: 100 },
13
- { x: 200, y: 200 },
14
- { x: 100, y: 200 }
15
- ],
16
- fillStyle: '#fff',
17
- strokeStyle: '#000',
18
- alpha: 1,
19
- hidden: false,
20
- lineWidth: 1,
21
- lineDash: 'solid',
22
- lineCap: 'butt',
23
- round: 10
24
- }
25
- }
@@ -1,25 +0,0 @@
1
- const polyline = new URL('../../icons/polyline.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'polyline',
5
- description: 'polyline',
6
- icon: polyline,
7
- group: 'line',
8
- model: {
9
- type: 'polyline',
10
- path: [
11
- { x: 100, y: 100 },
12
- { x: 200, y: 100 },
13
- { x: 200, y: 200 },
14
- { x: 100, y: 200 }
15
- ],
16
- fillStyle: '#fff',
17
- strokeStyle: '#000',
18
- alpha: 1,
19
- hidden: false,
20
- lineWidth: 1,
21
- lineDash: 'solid',
22
- lineCap: 'butt',
23
- round: 10
24
- }
25
- }
@@ -1,22 +0,0 @@
1
- const rect = new URL('../../icons/rect.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'rect',
5
- description: 'rectangle shape',
6
- icon: rect,
7
- group: 'shape',
8
- model: {
9
- type: 'rect',
10
- left: 100,
11
- top: 100,
12
- width: 100,
13
- height: 100,
14
- fillStyle: '#fff',
15
- strokeStyle: '#000',
16
- alpha: 1,
17
- hidden: false,
18
- lineWidth: 1,
19
- lineDash: 'solid',
20
- lineCap: 'butt'
21
- }
22
- }
@@ -1,24 +0,0 @@
1
- const star = new URL('../../icons/star.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'star',
5
- description: 'star shape',
6
- icon: star,
7
- group: 'shape',
8
- model: {
9
- type: 'star',
10
- rx: 50,
11
- ry: 50,
12
- cx: 150,
13
- cy: 150,
14
- ratio: 30,
15
- wing: 5,
16
- fillStyle: '#fff',
17
- strokeStyle: '#000',
18
- alpha: 1,
19
- hidden: false,
20
- lineWidth: 1,
21
- lineDash: 'solid',
22
- lineCap: 'butt'
23
- }
24
- }
@@ -1,28 +0,0 @@
1
- const text = new URL('../../icons/text.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'text',
5
- description: 'text',
6
- icon: text,
7
- group: 'textAndMedia',
8
- model: {
9
- type: 'text',
10
- left: 100,
11
- top: 100,
12
- width: 200,
13
- height: 50,
14
- text: 'Text',
15
- fillStyle: '#fff',
16
- strokeStyle: '#000',
17
- alpha: 1,
18
- hidden: false,
19
- lineWidth: 5,
20
- lineDash: 'solid',
21
- lineCap: 'butt',
22
- textAlign: 'left',
23
- textBaseline: 'top',
24
- textWrap: false,
25
- fontFamily: 'serif',
26
- fontSize: 30
27
- }
28
- }
@@ -1,24 +0,0 @@
1
- const triangle = new URL('../../icons/triangle.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'triangle',
5
- description: 'triangle shape',
6
- icon: triangle,
7
- group: 'shape',
8
- model: {
9
- type: 'triangle',
10
- x1: 150,
11
- y1: 100,
12
- x2: 100,
13
- y2: 200,
14
- x3: 200,
15
- y3: 200,
16
- fillStyle: '#fff',
17
- strokeStyle: '#000',
18
- alpha: 1,
19
- hidden: false,
20
- lineWidth: 1,
21
- lineDash: 'solid',
22
- lineCap: 'butt'
23
- }
24
- }