@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.
@@ -0,0 +1,127 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+ import { Component, Model, RectPath, Shape } from '@hatiolab/things-scene';
5
+ const NATURE = {
6
+ mutable: false,
7
+ resizable: true,
8
+ rotatable: true,
9
+ properties: [
10
+ {
11
+ type: 'number',
12
+ label: 'duration',
13
+ name: 'duration',
14
+ property: 'duration',
15
+ placeholder: 'milli-seconds'
16
+ },
17
+ {
18
+ type: 'id-input',
19
+ label: 'target',
20
+ name: 'target'
21
+ },
22
+ {
23
+ type: 'checkbox',
24
+ label: 'repeat',
25
+ name: 'repeat',
26
+ property: 'repeat'
27
+ },
28
+ {
29
+ type: 'checkbox',
30
+ label: 'autostart',
31
+ name: 'autostart',
32
+ property: 'autostart'
33
+ },
34
+ {
35
+ type: 'number',
36
+ label: 'targetRetention',
37
+ name: 'targetRetention',
38
+ property: 'targetRetention',
39
+ placeholder: 'milli-seconds'
40
+ }
41
+ ],
42
+ 'value-property': 'started',
43
+ help: 'scene/component/clone'
44
+ };
45
+ function clone(cloner, target, targetRetention) {
46
+ var targetComponent = cloner.root.findById(target);
47
+ if (!targetComponent)
48
+ return;
49
+ var clone = Object.assign(targetComponent.hierarchy, {
50
+ templatePrefix: '',
51
+ id: ''
52
+ });
53
+ if (targetRetention)
54
+ clone.retention = targetRetention;
55
+ var component = Model.compile(clone, cloner.app);
56
+ var index = targetComponent.parent.indexOf(targetComponent);
57
+ targetComponent.parent.insertComponentAt(component, index + 1);
58
+ return component;
59
+ }
60
+ export default class Clone extends RectPath(Shape) {
61
+ constructor() {
62
+ super(...arguments);
63
+ this._started = false;
64
+ }
65
+ added(parent) {
66
+ this.started = false;
67
+ setTimeout(() => {
68
+ if (this.get('autostart'))
69
+ this.started = true;
70
+ }, 500);
71
+ }
72
+ dispose() {
73
+ this.started = false;
74
+ super.dispose();
75
+ }
76
+ _draw(ctx) {
77
+ var { left, top, width, height } = this.bounds;
78
+ ctx.beginPath();
79
+ ctx.fillStyle = 'black';
80
+ ctx.strokeStyle = 'black';
81
+ ctx.rect(left, top, width * 0.8, height * 0.8);
82
+ ctx.fill();
83
+ ctx.stroke();
84
+ ctx.beginPath();
85
+ ctx.rect(left + width * 0.2, top + height * 0.2, width * 0.8, height * 0.8);
86
+ }
87
+ get nature() {
88
+ return NATURE;
89
+ }
90
+ get started() {
91
+ return this._started;
92
+ }
93
+ set started(started) {
94
+ var _a;
95
+ if (!!this.started == !!started)
96
+ return;
97
+ this._started = !!started;
98
+ if (!((_a = this.app) === null || _a === void 0 ? void 0 : _a.isViewMode))
99
+ return;
100
+ if (this._started) {
101
+ var { repeat, duration, target, targetRetention } = this.model;
102
+ if (!target)
103
+ return;
104
+ if (duration < 500)
105
+ duration = 500;
106
+ let self = this;
107
+ function _() {
108
+ if (!self._started || !clone(self, target, targetRetention) || !duration || !repeat) {
109
+ self._started = false;
110
+ return;
111
+ }
112
+ self._timeout = setTimeout(() => {
113
+ requestAnimationFrame(_);
114
+ }, duration);
115
+ }
116
+ requestAnimationFrame(_);
117
+ }
118
+ else {
119
+ if (this._timeout) {
120
+ clearTimeout(this._timeout);
121
+ delete this._timeout;
122
+ }
123
+ }
124
+ }
125
+ }
126
+ Component.register('clone', Clone);
127
+ //# sourceMappingURL=clone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clone.js","sourceRoot":"","sources":["../../src/clone.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAa,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAErF,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,KAAK;IACd,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,IAAI;IACf,UAAU,EAAE;QACV;YACE,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,UAAU;Y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\n\nconst NATURE = {\n mutable: false,\n resizable: true,\n rotatable: true,\n properties: [\n {\n type: 'number',\n label: 'duration',\n name: 'duration',\n property: 'duration',\n placeholder: 'milli-seconds'\n },\n {\n type: 'id-input',\n label: 'target',\n name: 'target'\n },\n {\n type: 'checkbox',\n label: 'repeat',\n name: 'repeat',\n property: 'repeat'\n },\n {\n type: 'checkbox',\n label: 'autostart',\n name: 'autostart',\n property: 'autostart'\n },\n {\n type: 'number',\n label: 'targetRetention',\n name: 'targetRetention',\n property: 'targetRetention',\n placeholder: 'milli-seconds'\n }\n ],\n 'value-property': 'started',\n help: 'scene/component/clone'\n}\n\nfunction clone(cloner: Component, target: string, targetRetention: number) {\n var targetComponent = cloner.root.findById(target)\n if (!targetComponent) return\n\n var clone = Object.assign(targetComponent.hierarchy, {\n templatePrefix: '',\n id: ''\n })\n\n if (targetRetention) clone.retention = targetRetention\n\n var component = Model.compile(clone, cloner.app)\n var index = targetComponent.parent.indexOf(targetComponent)\n targetComponent.parent.insertComponentAt(component, index + 1)\n\n return component\n}\n\nexport default class Clone extends RectPath(Shape) {\n private _started: boolean = false\n private _timeout?: NodeJS.Timeout\n\n added(parent: Container) {\n this.started = false\n setTimeout(() => {\n if (this.get('autostart')) this.started = true\n }, 500)\n }\n\n dispose() {\n this.started = false\n super.dispose()\n }\n\n _draw(ctx: CanvasRenderingContext2D) {\n var { left, top, width, height } = this.bounds\n\n ctx.beginPath()\n\n ctx.fillStyle = 'black'\n ctx.strokeStyle = 'black'\n\n ctx.rect(left, top, width * 0.8, height * 0.8)\n ctx.fill()\n ctx.stroke()\n\n ctx.beginPath()\n\n ctx.rect(left + width * 0.2, top + height * 0.2, width * 0.8, height * 0.8)\n }\n\n get nature() {\n return NATURE\n }\n\n get started() {\n return this._started\n }\n\n set started(started) {\n if (!!this.started == !!started) return\n\n this._started = !!started\n\n if (!this.app?.isViewMode) return\n\n if (this._started) {\n var { repeat, duration, target, targetRetention } = this.model\n\n if (!target) return\n\n if (duration < 500) duration = 500\n\n let self = this\n\n function _() {\n if (!self._started || !clone(self, target, targetRetention) || !duration || !repeat) {\n self._started = false\n return\n }\n\n self._timeout = setTimeout(() => {\n requestAnimationFrame(_)\n }, duration)\n }\n\n requestAnimationFrame(_)\n } else {\n if (this._timeout) {\n clearTimeout(this._timeout)\n delete this._timeout\n }\n }\n }\n}\n\nComponent.register('clone', Clone)\n"]}
@@ -0,0 +1 @@
1
+ export { default as Clone } from './clone';
@@ -0,0 +1,5 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+ export { default as Clone } from './clone';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAA","sourcesContent":["/*\n * Copyright © HatioLab Inc. All rights reserved.\n */\nexport { default as Clone } from './clone'\n"]}
@@ -0,0 +1 @@
1
+ {"program":{"fileNames":["../../../node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../node_modules/tslib/tslib.d.ts","../node_modules/@hatiolab/things-scene/things-scene.d.ts","../src/clone.ts","../src/index.ts","../../../node_modules/@types/node/assert.d.ts","../../../node_modules/@types/node/assert/strict.d.ts","../../../node_modules/@types/node/globals.d.ts","../../../node_modules/@types/node/async_hooks.d.ts","../../../node_modules/@types/node/buffer.d.ts","../../../node_modules/@types/node/child_process.d.ts","../../../node_modules/@types/node/cluster.d.ts","../../../node_modules/@types/node/console.d.ts","../../../node_modules/@types/node/constants.d.ts","../../../node_modules/@types/node/crypto.d.ts","../../../node_modules/@types/node/dgram.d.ts","../../../node_modules/@types/node/diagnostics_channel.d.ts","../../../node_modules/@types/node/dns.d.ts","../../../node_modules/@types/node/dns/promises.d.ts","../../../node_modules/@types/node/domain.d.ts","../../../node_modules/@types/node/events.d.ts","../../../node_modules/@types/node/fs.d.ts","../../../node_modules/@types/node/fs/promises.d.ts","../../../node_modules/@types/node/http.d.ts","../../../node_modules/@types/node/http2.d.ts","../../../node_modules/@types/node/https.d.ts","../../../node_modules/@types/node/inspector.d.ts","../../../node_modules/@types/node/module.d.ts","../../../node_modules/@types/node/net.d.ts","../../../node_modules/@types/node/os.d.ts","../../../node_modules/@types/node/path.d.ts","../../../node_modules/@types/node/perf_hooks.d.ts","../../../node_modules/@types/node/process.d.ts","../../../node_modules/@types/node/punycode.d.ts","../../../node_modules/@types/node/querystring.d.ts","../../../node_modules/@types/node/readline.d.ts","../../../node_modules/@types/node/repl.d.ts","../../../node_modules/@types/node/stream.d.ts","../../../node_modules/@types/node/stream/promises.d.ts","../../../node_modules/@types/node/stream/consumers.d.ts","../../../node_modules/@types/node/stream/web.d.ts","../../../node_modules/@types/node/string_decoder.d.ts","../../../node_modules/@types/node/timers.d.ts","../../../node_modules/@types/node/timers/promises.d.ts","../../../node_modules/@types/node/tls.d.ts","../../../node_modules/@types/node/trace_events.d.ts","../../../node_modules/@types/node/tty.d.ts","../../../node_modules/@types/node/url.d.ts","../../../node_modules/@types/node/util.d.ts","../../../node_modules/@types/node/v8.d.ts","../../../node_modules/@types/node/vm.d.ts","../../../node_modules/@types/node/wasi.d.ts","../../../node_modules/@types/node/worker_threads.d.ts","../../../node_modules/@types/node/zlib.d.ts","../../../node_modules/@types/node/globals.global.d.ts","../../../node_modules/@types/node/index.d.ts"],"fileInfos":[{"version":"6adbf5efd0e374ff5f427a4f26a5a413e9734eee5067a0e86da69aea41910b52","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","e21c071ca3e1b4a815d5f04a7475adcaeea5d64367e840dd0154096d705c3940",{"version":"abba1071bfd89e55e88a054b0c851ea3e8a494c340d0f3fab19eb18f6afb0c9e","affectsGlobalScope":true},{"version":"d8996609230d17e90484a2dd58f22668f9a05a3bfe00bfb1d6271171e54a31fb","affectsGlobalScope":true},{"version":"43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"4378fc8122ec9d1a685b01eb66c46f62aba6b239ca7228bb6483bcf8259ee493","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"810627a82ac06fb5166da5ada4159c4ec11978dfbb0805fe804c86406dab8357","affectsGlobalScope":true},{"version":"62d80405c46c3f4c527ee657ae9d43fda65a0bf582292429aea1e69144a522a6","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"1b3fe904465430e030c93239a348f05e1be80640d91f2f004c3512c2c2c89f34","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"d071129cba6a5f2700be09c86c07ad2791ab67d4e5ed1eb301d6746c62745ea4","affectsGlobalScope":true},{"version":"10bbdc1981b8d9310ee75bfac28ee0477bb2353e8529da8cff7cb26c409cb5e8","affectsGlobalScope":true},"12f4cfe2fe60b810c3174537bc2ddb20c1067b7768643d12cb1266fd183afb75","4ddc7832014ce8dae75461c71b8e6af7281cfb2eba4d6e4c2deb6300044cf4ce",{"version":"88b49b77136a025f0ed21725d1af4caf3aaf164c40e2d618db57954f36c94e1b","signature":"72100f0e3d43bef297abefa2ab1a2433730d942431053d3bdfbca199d972df33"},{"version":"4c57b59ee41fd3a5ddcd8deddca3d8ed8c83fa5f68f7e1c7442856fd6e4bec4a","signature":"012dd2a6f9487b470c8eb3db99b9aa576b2fd707c02d6083575bca84f0250fb6"},"0d5a2ee1fdfa82740e0103389b9efd6bfe145a20018a2da3c02b89666181f4d9","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"92d63add669d18ebc349efbacd88966d6f2ccdddfb1b880b2db98ae3aa7bf7c4","affectsGlobalScope":true},"ccc94049a9841fe47abe5baef6be9a38fc6228807974ae675fb15dc22531b4be",{"version":"9acfe4d1ff027015151ce81d60797b04b52bffe97ad8310bb0ec2e8fd61e1303","affectsGlobalScope":true},"95843d5cfafced8f3f8a5ce57d2335f0bcd361b9483587d12a25e4bd403b8216","afc6e96061af46bcff47246158caee7e056f5288783f2d83d6858cd25be1c565",{"version":"34f5bcac12b36d70304b73de5f5aab3bb91bd9919f984be80579ebcad03a624e","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","2f520601649a893e6a49a8851ebfcf4be8ce090dc1281c2a08a871cb04e8251f","f50c975ab7b50e25a69e3d8a3773894125b44e9698924105f23b812bf7488baf","2b8c764f856a1dd0a9a2bf23e5efddbff157de8138b0754010be561ae5fcaa90","76650408392bf49a8fbf3e2b6b302712a92d76af77b06e2da1cc8077359c4409","0af3121e68297b2247dd331c0d24dba599e50736a7517a5622d5591aae4a3122","6972fca26f6e9bd56197568d4379f99071a90766e06b4fcb5920a0130a9202be",{"version":"4a2628e95962c8ab756121faa3ac2ed348112ff7a87b5c286dd2cc3326546b4c","affectsGlobalScope":true},"80793b2277f31baa199234daed806fff0fb11491d1ebd3357e520c3558063f00","a049a59a02009fc023684fcfaf0ac526fe36c35dcc5d2b7d620c1750ba11b083","5533392c50c51b1a5c32b89f13145db929c574ef1c5949cf67a074a05ea107d9","b287b810b5035d5685f1df6e1e418f1ca452a3ed4f59fd5cc081dbf2045f0d9b","4b9a003b5c556c96784132945bb41c655ea11273b1917f5c8d0c154dd5fd20dd","a458dc78104cc80048ac24fdc02fe6dce254838094c2f25641b3f954d9721241",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"902cd98bf46e95caf4118a0733fb801e9e90eec3edaed6abdad77124afec9ca2","abc1c425b2ad6720433f40f1877abfa4223f0f3dd486c9c28c492179ca183cb6","cd4854d38f4eb5592afd98ab95ca17389a7dfe38013d9079e802d739bdbcc939","94eed4cc2f5f658d5e229ff1ccd38860bddf4233e347bf78edd2154dee1f2b99",{"version":"bd1a08e30569b0fb2f0b21035eb9b039871f68faa9b98accf847e9c878c5e0a9","affectsGlobalScope":true},"9f1069b9e2c051737b1f9b4f1baf50e4a63385a6a89c32235549ae87fc3d5492","ee18f2da7a037c6ceeb112a084e485aead9ea166980bf433474559eac1b46553","29c2706fa0cc49a2bd90c83234da33d08bb9554ecec675e91c1f85087f5a5324","0acbf26bf958f9e80c1ffa587b74749d2697b75b484062d36e103c137c562bc3","d7838022c7dab596357a9604b9c6adffe37dc34085ce0779c958ce9545bd7139","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff",{"version":"806ef4cac3b3d9fa4a48d849c8e084d7c72fcd7b16d76e06049a9ed742ff79c0","affectsGlobalScope":true},"a7971f9fb2a32ec7788ec6cda9d7a33c02023dfe9a62db2030ad1359649d8050","c33a6ea7147af60d8e98f1ac127047f4b0d4e2ce28b8f08ff3de07ca7cc00637",{"version":"b42b47e17b8ece2424ae8039feb944c2e3ba4b262986aebd582e51efbdca93dc","affectsGlobalScope":true},"664d8f2d59164f2e08c543981453893bc7e003e4dfd29651ce09db13e9457980","2408611d9b4146e35d1dbd1f443ccd8e187c74614a54b80300728277529dbf11","998a3de5237518c0b3ac00a11b3b4417affb008aa20aedee52f3fdae3cb86151","ad41008ffe077206e1811fc873f4d9005b5fd7f6ab52bb6118fef600815a5cb4","d88ecca73348e7c337541c4b8b60a50aca5e87384f6b8a422fc6603c637e4c21","badae0df9a8016ac36994b0a0e7b82ba6aaa3528e175a8c3cb161e4683eec03e","c3db860bcaaaeb3bbc23f353bbda1f8ab82756c8d5e973bebb3953cb09ea68f2","235a53595bd20b0b0eeb1a29cb2887c67c48375e92f03749b2488fbd46d0b1a0","bc09393cd4cd13f69cf1366d4236fbae5359bb550f0de4e15767e9a91d63dfb1","9c266243b01545e11d2733a55ad02b4c00ecdbda99c561cd1674f96e89cdc958","c71155c05fc76ff948a4759abc1cb9feec036509f500174bc18dad4c7827a60c",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"1cdb8f094b969dcc183745dc88404e2d8fcf2a858c6e7cc2441011476573238e"],"options":{"allowSyntheticDefaultImports":true,"declaration":true,"esModuleInterop":false,"experimentalDecorators":true,"importHelpers":true,"inlineSources":true,"module":99,"noEmitOnError":true,"outDir":"./","rootDir":"..","sourceMap":true,"strict":true,"target":5},"fileIdsList":[[44,87],[47,87],[48,53,87],[49,59,60,67,76,86,87],[49,50,59,67,87],[51,87],[52,53,60,68,87],[53,76,83,87],[54,56,59,67,87],[55,87],[56,57,87],[58,59,87],[59,87],[59,60,61,76,86,87],[59,60,61,76,87],[87],[62,67,76,86,87],[59,60,62,63,67,76,83,86,87],[62,64,76,83,86,87],[44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93],[59,65,87],[66,86,87],[56,59,67,76,87],[68,87],[69,87],[47,70,87],[71,85,87,91],[72,87],[73,87],[59,74,87],[74,75,87,89],[59,76,77,78,87],[76,78,87],[76,77,87],[79,87],[80,87],[59,81,82,87],[81,82,87],[53,67,83,87],[84,87],[67,85,87],[48,62,73,86,87],[53,87],[76,87,88],[87,89],[87,90],[48,53,59,61,70,76,86,87,89,91],[76,87,92],[40,41,87],[40,42,87],[41],[42]],"referencedMap":[[44,1],[45,1],[47,2],[48,3],[49,4],[50,5],[51,6],[52,7],[53,8],[54,9],[55,10],[56,11],[57,11],[58,12],[59,13],[60,14],[61,15],[46,16],[93,16],[62,17],[63,18],[64,19],[94,20],[65,21],[66,22],[67,23],[68,24],[69,25],[70,26],[71,27],[72,28],[73,29],[74,30],[75,31],[76,32],[78,33],[77,34],[79,35],[80,36],[81,37],[82,38],[83,39],[84,40],[85,41],[86,42],[87,43],[88,44],[89,45],[90,46],[91,47],[92,48],[40,16],[8,16],[10,16],[9,16],[2,16],[11,16],[12,16],[13,16],[14,16],[15,16],[16,16],[17,16],[18,16],[3,16],[4,16],[22,16],[19,16],[20,16],[21,16],[23,16],[24,16],[25,16],[5,16],[26,16],[27,16],[28,16],[29,16],[6,16],[30,16],[31,16],[32,16],[33,16],[7,16],[38,16],[34,16],[35,16],[36,16],[37,16],[1,16],[39,16],[41,16],[42,49],[43,50]],"exportedModulesMap":[[44,1],[45,1],[47,2],[48,3],[49,4],[50,5],[51,6],[52,7],[53,8],[54,9],[55,10],[56,11],[57,11],[58,12],[59,13],[60,14],[61,15],[46,16],[93,16],[62,17],[63,18],[64,19],[94,20],[65,21],[66,22],[67,23],[68,24],[69,25],[70,26],[71,27],[72,28],[73,29],[74,30],[75,31],[76,32],[78,33],[77,34],[79,35],[80,36],[81,37],[82,38],[83,39],[84,40],[85,41],[86,42],[87,43],[88,44],[89,45],[90,46],[91,47],[92,48],[40,16],[8,16],[10,16],[9,16],[2,16],[11,16],[12,16],[13,16],[14,16],[15,16],[16,16],[17,16],[18,16],[3,16],[4,16],[22,16],[19,16],[20,16],[21,16],[23,16],[24,16],[25,16],[5,16],[26,16],[27,16],[28,16],[29,16],[6,16],[30,16],[31,16],[32,16],[33,16],[7,16],[38,16],[34,16],[35,16],[36,16],[37,16],[1,16],[39,16],[41,16],[42,51],[43,52]],"semanticDiagnosticsPerFile":[44,45,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,46,93,62,63,64,94,65,66,67,68,69,70,71,72,73,74,75,76,78,77,79,80,81,82,83,84,85,86,87,88,89,90,91,92,40,8,10,9,2,11,12,13,14,15,16,17,18,3,4,22,19,20,21,23,24,25,5,26,27,28,29,6,30,31,32,33,7,38,34,35,36,37,1,39,41,42,43]},"version":"4.5.2"}
@@ -0,0 +1,22 @@
1
+ # Clone
2
+
3
+ 컴포넌트를 복제하는 컴포넌트이다.
4
+
5
+ ## properties
6
+ - 반복 주기
7
+ - 반복 설정된 경우, 반복 주기를 milli-seconds 단위로 입력한다.
8
+ - 최소값은 500ms 이다.
9
+ - 최초 복제는 이 컴포넌트가 시작되는 즉시 실행된다. 즉, duration 값은 최초 컴포넌트 복제의 delay에 적용되지 않는다.
10
+ - 대상
11
+ - 복제 대상 컴포넌트의 id를 입력한다.
12
+ - 반복
13
+ - 컴포넌트 복제 작업을 반복적으로 실행할 것인지를 설정한다.
14
+ - 반복 설정이 되면, 반복 주기에 따라 반복적으로 실행한다.
15
+ - 자동 시작
16
+ - 컴포넌트 복제 작업을 자동으로 시작할 지를 설정한다.
17
+ - 자동 시작 설정을 하지 않은 경우, started 또는 value 속성을 true/false 로 시작시키거나 종료시킬 수 있다.
18
+ - 대상 유지기간
19
+ - 복제된 컴포넌트를 얼마동안 유지할 것이지를 설정 (milli-seconds)
20
+ - 복제된 컴포넌트의 retention 속성으로 설정됨
21
+ - started (value property)
22
+ - 모델러 속성창에서 설정할 수 없지만, 데이타 전파나 탭이벤트 핸들링으로 설정할 수 있다.
@@ -0,0 +1,23 @@
1
+ # Clone
2
+
3
+ It is a component that duplicates a component.
4
+
5
+ ## properties
6
+
7
+ - duration
8
+ - If "Repeat" is set, enter the "Repeat" period in milli-seconds.
9
+ - The minimum value is 500ms.
10
+ - Initial cloning is executed as soon as this component is started. That is, the duration value is not applied to the delay of the initial component replication.
11
+ - target
12
+ - Enter the id of the component to be cloned.
13
+ - repeat
14
+ - Set whether to repeatedly execute the component replication task.
15
+ - If it is set to repeat, it is repeatedly executed according to the duration setting period.
16
+ - auto start
17
+ - Set whether or not to automatically start component clone work.
18
+ - If "auto start" is not set, the "started" or "value" attribute can be started or terminated with "true/false".
19
+ - target retention
20
+ - How long to keep the cloned component alive (milli-seconds)
21
+ - Set with the retention attribute of the cloned component
22
+ - started (value property)
23
+ - It cannot be set in the modeler property window, but it can be set by data propagation or tap event handling.
@@ -0,0 +1,22 @@
1
+ # 克隆
2
+
3
+ 克隆是复制组件的组件。
4
+
5
+ ## properties
6
+ - 持续期间
7
+ - 进行重复设置(以毫秒为单位)。
8
+ - 最小值为500毫秒。
9
+ - 一旦启动此组件,就会执行克隆。即,持续时间值不应用于初始组件复制的延迟。
10
+ - 目标
11
+ - 输入要复制的组件的ID。
12
+ - 重复
13
+ - 设置是否重复执行组件复制工作。
14
+ - 如果设置为重复,则根据持续时间设置周期重复执行。
15
+ - 自动开始
16
+ - 设置是否自动开始组件复制工作。
17
+ - 如果未设置自动启动,则可以使用true / false启动或终止启动或值属性。
18
+ - 保留期间
19
+ - 复制的组件保持活动状态的时间(毫秒)
20
+ - 设置会传递到复制对象组件的保留期间属性中
21
+ - started (value property)
22
+ - 不能在建模器属性窗口中设置,但是可以通过数据传播或点击事件处理来设置。
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@operato/scene-clone",
3
+ "description": "Thing Scene component instance auto cloner.",
4
+ "license": "MIT",
5
+ "author": "heartyoh",
6
+ "version": "0.0.4",
7
+ "main": "dist/src/index.js",
8
+ "module": "dist/src/index.js",
9
+ "things-scene": true,
10
+ "publishConfig": {
11
+ "access": "public",
12
+ "@oprato:registry": "https://registry.npmjs.org"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/hatiolab/things-factory.git",
17
+ "directory": "packages/scene-clone"
18
+ },
19
+ "scripts": {
20
+ "serve": "tsc && things-factory-dev",
21
+ "start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
22
+ "build": "tsc",
23
+ "prepublish": "tsc",
24
+ "lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",
25
+ "format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore",
26
+ "migration": "things-factory-migration"
27
+ },
28
+ "dependencies": {
29
+ "lit": "^2.0.2"
30
+ },
31
+ "devDependencies": {
32
+ "@hatiolab/prettier-config": "^1.0.0",
33
+ "@hatiolab/things-scene": "^2.7.15",
34
+ "@operato/board": "^0.2.27",
35
+ "@things-factory/builder": "^4.0.6",
36
+ "@things-factory/operato-board": "^4.0.6",
37
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
38
+ "@typescript-eslint/parser": "^4.33.0",
39
+ "@web/dev-server": "^0.1.28",
40
+ "concurrently": "^5.3.0",
41
+ "eslint": "^7.32.0",
42
+ "eslint-config-prettier": "^8.3.0",
43
+ "husky": "^4.3.8",
44
+ "lint-staged": "^10.5.4",
45
+ "prettier": "^2.4.1",
46
+ "tslib": "^2.3.1",
47
+ "typescript": "^4.5.2"
48
+ },
49
+ "prettier": "@hatiolab/prettier-config",
50
+ "husky": {
51
+ "hooks": {
52
+ "pre-commit": "lint-staged"
53
+ }
54
+ },
55
+ "lint-staged": {
56
+ "*.ts": [
57
+ "eslint --fix",
58
+ "prettier --write"
59
+ ]
60
+ },
61
+ "gitHead": "853ccc00f65e96f0d4807400d792a76fe9ef62d1"
62
+ }
package/src/clone.ts ADDED
@@ -0,0 +1,143 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+ import { Component, Container, Model, RectPath, Shape } from '@hatiolab/things-scene'
5
+
6
+ const NATURE = {
7
+ mutable: false,
8
+ resizable: true,
9
+ rotatable: true,
10
+ properties: [
11
+ {
12
+ type: 'number',
13
+ label: 'duration',
14
+ name: 'duration',
15
+ property: 'duration',
16
+ placeholder: 'milli-seconds'
17
+ },
18
+ {
19
+ type: 'id-input',
20
+ label: 'target',
21
+ name: 'target'
22
+ },
23
+ {
24
+ type: 'checkbox',
25
+ label: 'repeat',
26
+ name: 'repeat',
27
+ property: 'repeat'
28
+ },
29
+ {
30
+ type: 'checkbox',
31
+ label: 'autostart',
32
+ name: 'autostart',
33
+ property: 'autostart'
34
+ },
35
+ {
36
+ type: 'number',
37
+ label: 'targetRetention',
38
+ name: 'targetRetention',
39
+ property: 'targetRetention',
40
+ placeholder: 'milli-seconds'
41
+ }
42
+ ],
43
+ 'value-property': 'started',
44
+ help: 'scene/component/clone'
45
+ }
46
+
47
+ function clone(cloner: Component, target: string, targetRetention: number) {
48
+ var targetComponent = cloner.root.findById(target)
49
+ if (!targetComponent) return
50
+
51
+ var clone = Object.assign(targetComponent.hierarchy, {
52
+ templatePrefix: '',
53
+ id: ''
54
+ })
55
+
56
+ if (targetRetention) clone.retention = targetRetention
57
+
58
+ var component = Model.compile(clone, cloner.app)
59
+ var index = targetComponent.parent.indexOf(targetComponent)
60
+ targetComponent.parent.insertComponentAt(component, index + 1)
61
+
62
+ return component
63
+ }
64
+
65
+ export default class Clone extends RectPath(Shape) {
66
+ private _started: boolean = false
67
+ private _timeout?: NodeJS.Timeout
68
+
69
+ added(parent: Container) {
70
+ this.started = false
71
+ setTimeout(() => {
72
+ if (this.get('autostart')) this.started = true
73
+ }, 500)
74
+ }
75
+
76
+ dispose() {
77
+ this.started = false
78
+ super.dispose()
79
+ }
80
+
81
+ _draw(ctx: CanvasRenderingContext2D) {
82
+ var { left, top, width, height } = this.bounds
83
+
84
+ ctx.beginPath()
85
+
86
+ ctx.fillStyle = 'black'
87
+ ctx.strokeStyle = 'black'
88
+
89
+ ctx.rect(left, top, width * 0.8, height * 0.8)
90
+ ctx.fill()
91
+ ctx.stroke()
92
+
93
+ ctx.beginPath()
94
+
95
+ ctx.rect(left + width * 0.2, top + height * 0.2, width * 0.8, height * 0.8)
96
+ }
97
+
98
+ get nature() {
99
+ return NATURE
100
+ }
101
+
102
+ get started() {
103
+ return this._started
104
+ }
105
+
106
+ set started(started) {
107
+ if (!!this.started == !!started) return
108
+
109
+ this._started = !!started
110
+
111
+ if (!this.app?.isViewMode) return
112
+
113
+ if (this._started) {
114
+ var { repeat, duration, target, targetRetention } = this.model
115
+
116
+ if (!target) return
117
+
118
+ if (duration < 500) duration = 500
119
+
120
+ let self = this
121
+
122
+ function _() {
123
+ if (!self._started || !clone(self, target, targetRetention) || !duration || !repeat) {
124
+ self._started = false
125
+ return
126
+ }
127
+
128
+ self._timeout = setTimeout(() => {
129
+ requestAnimationFrame(_)
130
+ }, duration)
131
+ }
132
+
133
+ requestAnimationFrame(_)
134
+ } else {
135
+ if (this._timeout) {
136
+ clearTimeout(this._timeout)
137
+ delete this._timeout
138
+ }
139
+ }
140
+ }
141
+ }
142
+
143
+ Component.register('clone', Clone)
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+ export { default as Clone } from './clone'