@operato/scene-clone 0.0.4
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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/assets/clone.png +0 -0
- package/demo/index-clone-bug-2.html +188 -0
- package/demo/index-clone-bug.html +185 -0
- package/demo/index-polyline-outline.html +368 -0
- package/demo/index.html +174 -0
- package/demo/things-scene-clone.html +5 -0
- package/dist/src/clone.d.ts +38 -0
- package/dist/src/clone.js +127 -0
- package/dist/src/clone.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/helps/scene/component/clone.ko.md +22 -0
- package/helps/scene/component/clone.md +23 -0
- package/helps/scene/component/clone.zh.md +22 -0
- package/package.json +62 -0
- package/src/clone.ts +143 -0
- package/src/index.ts +4 -0
- package/src/things-scene.x._ts +251 -0
- package/templates/index.js +18 -0
- package/test/basic-test.html +67 -0
- package/test/index.html +22 -0
- package/test/unit/test-clone.js +32 -0
- package/test/unit/util.js +21 -0
- package/things-scene.config.js +5 -0
- package/translations/en.json +7 -0
- package/translations/ko.json +7 -0
- package/translations/zh.json +7 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
declare module '@hatiolab/things-scene' {
|
|
2
|
+
type Constructor<T = {}> = new (...args: any[]) => T
|
|
3
|
+
|
|
4
|
+
enum SCENE_MODE {
|
|
5
|
+
MODE_VIEW = 0,
|
|
6
|
+
MODE_EDIT = 1,
|
|
7
|
+
MODE_SHIFT = 2
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type FITMODE = 'both' | 'ratio' | 'width' | 'height' | 'center' | 'none'
|
|
11
|
+
type DIMENSION = { x: number; y: number }
|
|
12
|
+
type SCALE = DIMENSION
|
|
13
|
+
type TRANSLATE = DIMENSION
|
|
14
|
+
type POSITION = DIMENSION
|
|
15
|
+
|
|
16
|
+
function create({
|
|
17
|
+
target,
|
|
18
|
+
model,
|
|
19
|
+
style,
|
|
20
|
+
layers,
|
|
21
|
+
handlers,
|
|
22
|
+
mode,
|
|
23
|
+
refProvider,
|
|
24
|
+
baseUrl,
|
|
25
|
+
fitMode
|
|
26
|
+
}: {
|
|
27
|
+
target?: HTMLElement
|
|
28
|
+
model: Object
|
|
29
|
+
style?: any
|
|
30
|
+
layers?: Array<any>
|
|
31
|
+
handlers?: Array<any>
|
|
32
|
+
mode?: SCENE_MODE
|
|
33
|
+
refProvider?: any
|
|
34
|
+
baseUrl?: string | undefined
|
|
35
|
+
fitMode?: FITMODE
|
|
36
|
+
}): Scene
|
|
37
|
+
|
|
38
|
+
class Anchor {
|
|
39
|
+
constructor({ component, anchor, position }: { component: Component; anchor: string; position: POSITION })
|
|
40
|
+
|
|
41
|
+
position: POSITION
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class Model {
|
|
45
|
+
static compile(model: Model, context: any): Component
|
|
46
|
+
|
|
47
|
+
type: string;
|
|
48
|
+
[key: string]: any
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
class ApplicationContext {
|
|
52
|
+
readonly refProvider: any
|
|
53
|
+
readonly isViewMode: boolean
|
|
54
|
+
|
|
55
|
+
mode: SCENE_MODE
|
|
56
|
+
baseUrl: string
|
|
57
|
+
|
|
58
|
+
dispose(): void
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// type RectPath<T = {}> = new (...args: any[]) => T
|
|
62
|
+
function RectPath<TBase extends Constructor>(Base: TBase): TBase
|
|
63
|
+
|
|
64
|
+
class Component {
|
|
65
|
+
static register(type: string, Clazz: typeof Component): void
|
|
66
|
+
|
|
67
|
+
state: { [key: string]: any }
|
|
68
|
+
bounds: { top: number; left: number; width: number; height: number }
|
|
69
|
+
root: RootContainer
|
|
70
|
+
parent: Container
|
|
71
|
+
app: ApplicationContext /* application context */
|
|
72
|
+
model: Model
|
|
73
|
+
hierarchy: Model
|
|
74
|
+
path: Array<DIMENSION>
|
|
75
|
+
anchors: Array<Anchor>
|
|
76
|
+
|
|
77
|
+
dispose(): void
|
|
78
|
+
setState(state: any): void
|
|
79
|
+
get(state: string): any
|
|
80
|
+
reposition(): void
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
class Container extends Component {
|
|
84
|
+
indexOf(component: Component): number
|
|
85
|
+
insertComponentAt(target: Component, idx: number): void
|
|
86
|
+
findById(id: string): Component
|
|
87
|
+
}
|
|
88
|
+
class RootContainer extends Container {}
|
|
89
|
+
|
|
90
|
+
class Shape extends Component {}
|
|
91
|
+
class HTMLOverlayElement extends Component {
|
|
92
|
+
element: HTMLElement
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
class HTMLOverlayContainer extends Container {
|
|
96
|
+
readonly layout: any
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
class Scene {
|
|
100
|
+
static readonly residents: WeakSet<Scene>
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* scene에 컴포넌트를 추가한다.
|
|
104
|
+
* @param models {object} - Component Model Object
|
|
105
|
+
* @param boundsOrOffset {object} - x, y, cx, cy, ...
|
|
106
|
+
* @param onto {string} - onto
|
|
107
|
+
*/
|
|
108
|
+
add({ models, boundsOrOffset, onto }: { models: object; boundsOrOffset: object; onto: string }): Component
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* scene의 컴포넌트를 복제한다.
|
|
112
|
+
* 현재 선택되어있는 컴포넌트가 복제되므로, 컴포넌트를 복제하기 위해서는
|
|
113
|
+
* 먼저 복제하고자하는 컴포넌트를 선택된 상태로 만든 후에(참조. {@link select} 메쏘드) 이 메쏘드를 호출한다.
|
|
114
|
+
*/
|
|
115
|
+
duplicate(): void
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* scene의 컴포넌트를 삭제한다.
|
|
119
|
+
* 현재 선택되어있는 컴포넌트가 삭제되므로, 컴포넌트를 삭제하기 위해서는
|
|
120
|
+
* 먼저 삭제하고자하는 컴포넌트를 선택된 상태로 만든 후에(참조. {@link select} 메쏘드) 이 메쏘드를 호출한다.
|
|
121
|
+
*/
|
|
122
|
+
remove(): void
|
|
123
|
+
|
|
124
|
+
animate({
|
|
125
|
+
duration /* unit: milli-second, 1000 milli-seconds by default */,
|
|
126
|
+
delay /* default 30 */,
|
|
127
|
+
step /* step function */,
|
|
128
|
+
delta /* delta function */,
|
|
129
|
+
ease /* ease function */,
|
|
130
|
+
options,
|
|
131
|
+
repeat /* default false */
|
|
132
|
+
}: {
|
|
133
|
+
duration: number
|
|
134
|
+
delay: number
|
|
135
|
+
step: Function
|
|
136
|
+
delta: 'linear' | 'quad' | 'circ' | 'back' | 'bounce' | 'elastic' | Function
|
|
137
|
+
ease: 'out' | 'inout'
|
|
138
|
+
options?: object
|
|
139
|
+
repeat: boolean
|
|
140
|
+
}): {
|
|
141
|
+
start: Function /* start function */
|
|
142
|
+
stop: Function /* stop function */
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* scene이 그려지고 있는 컨테이너를 전체화면 모드에서 표시되도록 한다.
|
|
147
|
+
*/
|
|
148
|
+
fullscreen(): void
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 파라미터로 주어지는 id를 가진 컴포넌트의 data 값을 변경한다.
|
|
152
|
+
* @param id {string} - component id
|
|
153
|
+
* @param value {any} - data value
|
|
154
|
+
*/
|
|
155
|
+
variable(id: string, value: any): any
|
|
156
|
+
|
|
157
|
+
target: HTMLElement
|
|
158
|
+
scale: SCALE
|
|
159
|
+
translate: TRANSLATE
|
|
160
|
+
|
|
161
|
+
readonly unit: string /* 'px' */
|
|
162
|
+
readonly PPM: number
|
|
163
|
+
readonly PPI: number
|
|
164
|
+
readonly DPPX: number
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Scene 모델의 단위(unit)을 감안한 기본 Scale 값을 제공한다.
|
|
168
|
+
* 통산 'mm', 'cm' 단위의 Scene은 각 값에 10배를 곱한 수치로 모델링된다.(값을 10으로 나눈값이 실제 단위와 일치한다.)
|
|
169
|
+
* unitScale의 의미는 scene에 unitScale값으로 scale하면, 각 단위값이 화면과 일치한다는 의미이다.
|
|
170
|
+
*
|
|
171
|
+
* 모델링의 수치단위가 픽셀이 아니고, mm, cm, inch 등의 단위인 경우에,
|
|
172
|
+
* 화면에서의 크기가 실물과 유사하게 보이는 수준의 기본 스케일을 제공하는 기능이다.
|
|
173
|
+
* 이 값은 내부적으로는, Ruler에서 눈금을 실제 자의 눈금과 일치시키기 위해서 사용한다.
|
|
174
|
+
*/
|
|
175
|
+
readonly unitScale: string
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* scene이 그려질 모니터 화면의 크기정보 (inch)
|
|
179
|
+
* 예시) 17, 20, 24, 27, 30, ...
|
|
180
|
+
* @type {number}
|
|
181
|
+
*/
|
|
182
|
+
screen: number
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 컨테이너의 크기에 맞게 크기를 조정한다.
|
|
186
|
+
*/
|
|
187
|
+
resize(): void
|
|
188
|
+
|
|
189
|
+
dispose(): void
|
|
190
|
+
|
|
191
|
+
/* Selection Based API - Modeling APIs */
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* scene 내에서 선택된 컴포넌트의 리스트
|
|
195
|
+
* @type {object-array}
|
|
196
|
+
*/
|
|
197
|
+
selected: Array<Component>
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* scene이 그리고 있는 컴포넌트 모델정보
|
|
201
|
+
* @type {object}
|
|
202
|
+
*/
|
|
203
|
+
model: Component
|
|
204
|
+
|
|
205
|
+
/*
|
|
206
|
+
* root는 모델의 최상위 컨테이너인 모델레이어를 의미한다.
|
|
207
|
+
*/
|
|
208
|
+
readonly root: Container
|
|
209
|
+
|
|
210
|
+
/*
|
|
211
|
+
* selector에 해당하는 모든 컴포넌트들을 찾는다.
|
|
212
|
+
* @params selector {string}
|
|
213
|
+
*/
|
|
214
|
+
findAll(selector: string): Array<Component>
|
|
215
|
+
|
|
216
|
+
/*
|
|
217
|
+
* selector에 해당하는 첫번째 컴포넌트를 찾는다.
|
|
218
|
+
* @params selector {string}
|
|
219
|
+
*/
|
|
220
|
+
findFirst(selector: string): Component
|
|
221
|
+
|
|
222
|
+
/*
|
|
223
|
+
* id를 갖는 컴포넌트를 찾는다.
|
|
224
|
+
* @params id {string}
|
|
225
|
+
*/
|
|
226
|
+
findById(id: string): Component
|
|
227
|
+
|
|
228
|
+
/*
|
|
229
|
+
* scene이 그리는 모델 오브젝트를 JSON 텍스트로 리턴한다.
|
|
230
|
+
*/
|
|
231
|
+
serialize(): string
|
|
232
|
+
|
|
233
|
+
on(event: string, listener: Function, context: any): void
|
|
234
|
+
once(event: string, listener: Function, context: any): void
|
|
235
|
+
off(event: string, listener: Function, context: any): void
|
|
236
|
+
|
|
237
|
+
toDataURL(): string
|
|
238
|
+
|
|
239
|
+
fit(type: FITMODE): void
|
|
240
|
+
|
|
241
|
+
readonly fitMode: FITMODE
|
|
242
|
+
readonly ids: string[]
|
|
243
|
+
|
|
244
|
+
data: object
|
|
245
|
+
|
|
246
|
+
// @deprecated
|
|
247
|
+
variables: object
|
|
248
|
+
|
|
249
|
+
baseUrl: string
|
|
250
|
+
}
|
|
251
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import icon from '../assets/clone.png';
|
|
2
|
+
|
|
3
|
+
export default [{
|
|
4
|
+
type: 'clone',
|
|
5
|
+
description: 'component cloner',
|
|
6
|
+
group: 'etc',
|
|
7
|
+
icon,
|
|
8
|
+
model: {
|
|
9
|
+
type: 'clone',
|
|
10
|
+
top: 350,
|
|
11
|
+
left: 100,
|
|
12
|
+
width: 30,
|
|
13
|
+
height: 30,
|
|
14
|
+
strokeStyle: '#999',
|
|
15
|
+
lineWidth: 1,
|
|
16
|
+
lineStyle: '#999'
|
|
17
|
+
}
|
|
18
|
+
}]
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<!--
|
|
3
|
+
@license
|
|
4
|
+
Copyright © 2017 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-clone.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-clone-fixture">
|
|
21
|
+
<template>
|
|
22
|
+
<things-scene-clone>
|
|
23
|
+
<h2>things-scene-clone</h2>
|
|
24
|
+
</things-scene-clone>
|
|
25
|
+
</template>
|
|
26
|
+
</test-fixture>
|
|
27
|
+
|
|
28
|
+
<script>
|
|
29
|
+
suite('<things-scene-clone>', function() {
|
|
30
|
+
|
|
31
|
+
var myEl;
|
|
32
|
+
|
|
33
|
+
setup(function() {
|
|
34
|
+
myEl = fixture('things-scene-clone-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-clone says, Hello World!');
|
|
44
|
+
|
|
45
|
+
var greetings = myEl.sayHello('greetings Earthlings');
|
|
46
|
+
assert.equal(greetings, 'things-scene-clone says, greetings Earthlings');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('fires lasers', function(done) {
|
|
50
|
+
myEl.addEventListener('things-scene-clone-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
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<!--
|
|
3
|
+
@license
|
|
4
|
+
Copyright © 2017 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>
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { Clone } from '../../src/index'
|
|
10
|
+
|
|
11
|
+
describe('Clone', function () {
|
|
12
|
+
|
|
13
|
+
var board;
|
|
14
|
+
|
|
15
|
+
beforeEach(function () {
|
|
16
|
+
board = scene.create({
|
|
17
|
+
model: {
|
|
18
|
+
components: [{
|
|
19
|
+
id: 'clone',
|
|
20
|
+
type: 'clone'
|
|
21
|
+
}]
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('component should be found by its id.', function () {
|
|
27
|
+
|
|
28
|
+
var component = board.findById('clone')
|
|
29
|
+
|
|
30
|
+
expect(!!component).not.to.equal(false);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2018",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"noEmitOnError": true,
|
|
7
|
+
"lib": ["es2017", "dom"],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": false,
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"experimentalDecorators": true,
|
|
12
|
+
"importHelpers": true,
|
|
13
|
+
"outDir": "dist",
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"inlineSources": true,
|
|
16
|
+
"rootDir": "./",
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"incremental": true,
|
|
19
|
+
"types": ["node"]
|
|
20
|
+
},
|
|
21
|
+
"include": ["**/*.ts", "*.d.ts"]
|
|
22
|
+
}
|