diff --git a/app.js b/app.js index 6e704409..cac0ac06 100644 --- a/app.js +++ b/app.js @@ -228,10 +228,10 @@ const script = { "ext/three-svg", "ext/jszip", "add/license", - "ext/clip2", // work.test + "ext/clip2", "ext/tween", "ext/fsave", - "ext/earcut", // work.test + "ext/earcut", "ext/base64", "add/array", "add/three", @@ -258,7 +258,7 @@ const script = { "moto/load-url", "moto/load-file", "moto/broker", - "moto/db", + "moto/idb", "kiri/ui", "kiri/do", "kiri/lang", @@ -421,7 +421,7 @@ const script = { "moto/space", "moto/load-obj", "moto/load-stl", - "moto/db", + "moto/idb", "moto/ui", "kiri/catalog", "main/meta" @@ -437,7 +437,6 @@ const script = { "ext/fsave", "add/array", "add/three", - "geo/mesh", "moto/ctrl", "moto/space", "moto/load-3mf", @@ -447,7 +446,7 @@ const script = { "moto/load-url", "moto/load-file", "moto/broker", - "moto/db" + "moto/idb" ], mesh_work : [ "moto/worker", @@ -468,6 +467,8 @@ const script = { "geo/polygon", "geo/polygons", "geo/mesh", + "moto/broker", + "moto/idb" ] }; diff --git a/src/moto/client.js b/src/moto/client.js index 2376967a..ccb1dfbe 100644 --- a/src/moto/client.js +++ b/src/moto/client.js @@ -4,7 +4,7 @@ (function() { -let MOTO = self.moto = self.moto || {}, +let moto = self.moto = self.moto || {}, time = function() { return new Date().getTime() }, restarting = false, running = {}, @@ -12,8 +12,10 @@ let MOTO = self.moto = self.moto || {}, worker = null, seqid = 1; +if (moto.client) return; + /** - * @param {Function} fn name of function in MOTO.worker + * @param {Function} fn name of function in moto.worker * @param {Object} data to send to server * @param {Function} onreply function to call on reply messages * @param {Object[]} zerocopy array of objects to pass using zerocopy @@ -39,7 +41,7 @@ function send(fn, data, onreply, zerocopy) { } // code is running in the browser / client context -let CLIENT = MOTO.client = { +let client = moto.client = { send: send, // factory can be overridden @@ -69,7 +71,7 @@ let CLIENT = MOTO.client = { // same as restart start: function(url) { - CLIENT.restart(url); + client.restart(url); }, restart: function(url) { @@ -78,7 +80,7 @@ let CLIENT = MOTO.client = { return; } - CLIENT.stop(); + client.stop(); restarting = true; @@ -90,15 +92,20 @@ let CLIENT = MOTO.client = { } running = {}; - worker = CLIENT.newWorker(url); + worker = client.newWorker(url); - // bind to CLIENT to enable synth injections - CLIENT.onmessage = worker.onmessage = function(e) { + // bind to client to enable synth injections + client.onmessage = worker.onmessage = function(e) { let now = time(), reply = e.data, record = running[reply.seq], onreply = record ? record.fn : undefined; + if (reply.register) { + // console.log({register: reply.register}); + return; + } + if (reply.done) { delete running[reply.seq]; } diff --git a/src/moto/db.js b/src/moto/idb.js similarity index 98% rename from src/moto/db.js rename to src/moto/idb.js index bad39de1..5df2dc49 100644 --- a/src/moto/db.js +++ b/src/moto/idb.js @@ -4,10 +4,10 @@ (function() { - if (!self.moto) self.moto = {}; - if (self.moto.Storage) return; + let moto = self.moto = self.moto || {}; + if (moto.IDB) return; - self.moto.Storage = Storage; + moto.IDB = moto.Storage = Storage; // https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API diff --git a/src/moto/kv.js b/src/moto/kv.js index 459bbd6f..452b41cc 100644 --- a/src/moto/kv.js +++ b/src/moto/kv.js @@ -4,14 +4,9 @@ (function() { - if (!self.moto) self.moto = {}; - if (self.moto.KV) return; + let moto = self.moto = self.moto = {}; + if (moto.KV) return; - /** - * @param {String} dbname - * @param {number} [version] - * @constructor - */ function KV() { this.__data__ = {}; this.__mem__ = true; @@ -33,22 +28,18 @@ }; KP.clear = function() { - var d = this.__data__, key; - for (key in d) { - if (d.hasOwnProperty(key)) { - delete d[key]; - delete this[key]; - } - } + this.__data__ = {}; }; try { - self.moto.KV = self.localStorage; - self.moto.KV.setItem('__test', 1); - self.moto.KV.getItem('__test'); + let KV = moto.KV = self.localStorage, + testkey = '__test'; + KV.setItem(testkey, 1); + KV.getItem(testkey); + KV.removeItem(testkey); } catch (e) { - self.moto.KV = new KV(); - let msg = "in private or restricted browsing mode. local storage blocked. application may not function."; + moto.KV = new KV(); + let msg = "in private or restricted browsing mode. local storage blocked. application may not function properly."; console.log(msg); alert(msg); } diff --git a/src/moto/worker.js b/src/moto/worker.js index 9a9635f3..81b3c86f 100644 --- a/src/moto/worker.js +++ b/src/moto/worker.js @@ -4,29 +4,48 @@ (function() { -let MOTO = self.moto = self.moto || {}, +let moto = self.moto = self.moto || {}, time = Date.now; +if (moto.worker) return; + // allow license to inject module -self.gapp = self.gapp || MOTO; +self.gapp = self.gapp || moto; + +let isinit = false; +let endpoints = {}; // code is running in the worker / server context -const dispatch = MOTO.worker = { +const dispatch = moto.worker = { + + register: (name, fn) => { + endpoints[name] = fn; + sync(name); + }, send: (msg) => { self.postMessage(msg); }, + sync: (name) => { + if (name) { + if (isinit) dispatch.send({register: [name]}); + } else { + dispatch.send({register: Object.keys(endpoints)}); + } + }, + onmessage: (e) => { if (e.data === '--init--') { - console.log('worker got init'); + isinit = true; + dispatch.sync(); return; } let time_recv = time(), msg = e.data || {}, - run = dispatch[msg.task], + run = endpoints[msg.task], send = { data : function(data,direct) { dispatch.send({ diff --git a/web/kiri/index.css b/web/kiri/index.css index 70dbcb34..ddf7b048 100644 --- a/web/kiri/index.css +++ b/web/kiri/index.css @@ -9,7 +9,7 @@ } @font-face { font-family: 'Russo One'; - src: url('ext/russo-one.ttf'); + src: url('/moto/russo-one.ttf'); } a, a:hover, a:visited { border: none; diff --git a/web/mesh/index.css b/web/mesh/index.css index 2627ec42..07b87bc6 100644 --- a/web/mesh/index.css +++ b/web/mesh/index.css @@ -10,7 +10,7 @@ @font-face { font-family: 'Russo One'; - src: url('/kiri/ext/russo-one.ttf'); + src: url('/moto/russo-one.ttf'); } a, a:hover, a:visited { @@ -19,7 +19,7 @@ a, a:hover, a:visited { text-decoration: none; } -div { +body, div { position: relative; display: flex; padding: 0; @@ -30,20 +30,24 @@ div { #app { position: fixed; overflow: hidden; - font-weight: normal; + flex-direction: column; font-family: sans-serif; + font-weight: normal; font-size: larger; - top: 0; - left: 0; - right: 0; bottom: 0; + right: 0; + left: 0; + top: 0; } #app-info { + z-index: 50; top: 50%; left: 50%; transform: translateX(-50%) translateY(-50%); - z-index: 50; + cursor: pointer; + flex-direction: column; + align-items: center; } #app-info:hover #app-vers { @@ -67,24 +71,58 @@ div { background-color: white; } -#app-info { - cursor: pointer; +#app-body { + flex-grow: 1; +} + +#app-body > div { + z-index: 2; +} + +#curtain { + z-index: 50000; + top: 0; + left: 0; + right: 0; + bottom: 0; + position: fixed; + background-color: #fff; + font-family: 'Russo One', sans-serif; + justify-content: center; + align-items: center; +} + +#container { + z-index: 1; + position: fixed; + width: 100%; + height: 100%; +} + +#container canvas { + width: 100%; + height: 100%; + overflow: hidden; +} + +#top { + z-index: 2; + padding: 3px; + flex-direction: row; + font-family: 'Russo One', sans-serif; + background-color: rgba(255,255,255,0.75); +} + +#top > div { + margin: 0 5px 0 5px; } #top-sep { - z-index: 14; + z-index: 2; height: 1px; background-image: var(--gradbar); } -#loading { - width: 40px; - height: 40px; - padding-right: 15px; - position: fixed; - display: none; -} - .noselect { -khtml-user-select: none; -moz-user-select: none; @@ -92,52 +130,6 @@ div { user-select: none; } -.hide { - display: none !important; -} -.noshow { - display: none; -} -.grid { - display: grid; -} -.f-row { - flex-direction: row; -} -.f-col { - flex-direction: column; -} -.grow { - flex-grow: 1; -} -.a-start { - align-items: flex-start; -} -.a-center { - align-items: center; -} -.a-end { - align-items: flex-end; -} -.a-stretch { - align-items: stretch; -} -.j-start { - justify-content: flex-start; -} -.j-center { - justify-content: center; -} -.j-end { - justify-content: flex-end; -} -.center { - text-align: center; -} -.russo { - font-family: 'Russo One', sans-serif; -} - :-moz-any() { overflow-x: hidden !important; overflow-y: hidden !important; @@ -148,38 +140,3 @@ div { margin-right: -14px !important; margin-bottom: -14px !important; } - -#curtain { - top: 0; - left: 0; - right: 0; - bottom: 0; - position: fixed; - background-color: #fff; - font-family: 'Russo One', sans-serif; - z-index: 50000; -} - -#container { - position: fixed; - z-index: -1; - width: 100%; - height: 100%; -} - -#container canvas { - width: 100%; - height: 100%; - overflow: hidden; -} - -#top { - font-family: 'Russo One', sans-serif; - background-color: rgba(255,255,255,0.75); - padding: 3px; - z-index: 15; -} - -#top > div { - margin: 0 5px 0 5px; -} diff --git a/web/mesh/index.html b/web/mesh/index.html index 1bd6d5cb..766b9fe1 100644 --- a/web/mesh/index.html +++ b/web/mesh/index.html @@ -6,29 +6,28 @@ - - + + - Mesh:Tool - - + -
-
loading...
+
+
loading...
-
-
-
version
+
+
+
version
+
diff --git a/web/kiri/ext/russo-one.ttf b/web/moto/russo-one.ttf similarity index 100% rename from web/kiri/ext/russo-one.ttf rename to web/moto/russo-one.ttf