diff --git a/app.js b/app.js index 3d177790..c6e2f2f9 100644 --- a/app.js +++ b/app.js @@ -427,7 +427,7 @@ function initModule(mod, file, dir) { logger: log.new }, inject: (code, file, opt = {}) => { - console.log({ inject: opt, code, file }); + // console.log({ inject: opt, code, file }); let codelist = script[code]; if (!codelist) { return logger.log(`inject missing target "${code}"`); @@ -576,11 +576,17 @@ function handleVersion(req, res, next) { req.url = req.app.path = '/v2/lib/pack/mesh-work.js'; } else if (path === '/v2/lib/main/mesh.js') { req.url = req.app.path = '/v2/lib/pack/mesh-main.js'; - } else if (path === '/v2/lib/kiri/worker.js') { + } else if (path === '/v2/lib/kiri-run/minion.js') { + req.url = req.app.path = '/v2/lib/pack/kiri-pool.js'; + } else if (path === '/v2/lib/kiri-run/worker.js') { req.url = req.app.path = '/v2/lib/pack/kiri-work.js'; } else if (path === '/v2/lib/main/kiri.js') { req.url = req.app.path = '/v2/lib/pack/kiri-main.js'; } + if (path !== req.url) { + addCorsHeaders(req, res); + // console.log('rewrite', path, req.url); + } next(); } else { next(); @@ -938,7 +944,8 @@ function rewriteHtmlVersion(req, res, next) { if ([ "/v2/kiri/", "/v2/lib/kiri-run/minion.js", - "/v2/lib/kiri-run/worker.js" + "/v2/lib/kiri-run/worker.js", + "/v2/lib/kiri-run/minion.js" ].indexOf(req.app.path) >= 0) { addCorsHeaders(req, res); } else if ([ @@ -960,16 +967,16 @@ function rewriteHtmlVersion(req, res, next) { } res.write = function() { try { - console.log('res.write', req.app.path, arguments[0].length); + // console.log('res.write', req.app.path, arguments[0].length); arguments[0] = arguments[0].toString().replace(/{{version}}/g,vstr); - console.log('new length', arguments[0].length); + // console.log('new length', arguments[0].length); real_write.apply(res, arguments); } catch (err) { console.log({ rewrite_error: err }); } }; res.end = function() { - console.log('res.write', req.app.path, arguments[0]?.length); + // console.log('res.write', req.app.path, arguments[0]?.length); if (arguments[0]) { arguments[0] = arguments[0].toString().replace(/{{version}}/g,vstr); } diff --git a/package.json b/package.json index e94f8b3f..9463cba6 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "buffer-crc32": "^0.2.13", "compression": "^1.7.4", "connect": "^3.7.0", - "earcut": "^2.2.3", + "earcut": "^3.0.1", "express-useragent": "^1.0.13", "fast-glob": "^3.3.3", "jszip": "^3.7.1", diff --git a/src2/ext/earcut.js b/src2/ext/earcut.js index b09ba965..980715ff 120000 --- a/src2/ext/earcut.js +++ b/src2/ext/earcut.js @@ -1 +1 @@ -../../node_modules/earcut/dist/earcut.dev.js \ No newline at end of file +../../node_modules/earcut/src/earcut.js \ No newline at end of file diff --git a/src2/ext/three.js b/src2/ext/three.js index 7c7e1b26..b8c5e46c 100644 --- a/src2/ext/three.js +++ b/src2/ext/three.js @@ -31,6 +31,20 @@ /******/ })(); /******/ /************************************************************************/ +var __webpack_exports__ = {}; + +// EXPORTS +__webpack_require__.d(__webpack_exports__, { + wT: () => (/* reexport */ BufferGeometryUtils_namespaceObject), + Xk: () => (/* reexport */ Line2), + vK: () => (/* reexport */ LineGeometry), + GV: () => (/* reexport */ LineMaterial), + bF: () => (/* reexport */ LineSegments2), + n3: () => (/* reexport */ LineSegmentsGeometry), + Z5: () => (/* reexport */ index_module_namespaceObject), + cK: () => (/* reexport */ SVGLoader_namespaceObject), + ZH: () => (/* reexport */ three_module_namespaceObject) +}); // NAMESPACE OBJECT: ./node_modules/three/build/three.module.js var three_module_namespaceObject = {}; @@ -80690,4 +80704,13 @@ const shaderIntersectFunction = ` -export { BufferGeometryUtils_namespaceObject as BufferGeometryUtils, Line2, LineGeometry, LineMaterial, LineSegments2, LineSegmentsGeometry, index_module_namespaceObject as MeshBVHLib, SVGLoader_namespaceObject as SVGLoader, three_module_namespaceObject as THREE }; +var __webpack_exports__BufferGeometryUtils = __webpack_exports__.wT; +var __webpack_exports__Line2 = __webpack_exports__.Xk; +var __webpack_exports__LineGeometry = __webpack_exports__.vK; +var __webpack_exports__LineMaterial = __webpack_exports__.GV; +var __webpack_exports__LineSegments2 = __webpack_exports__.bF; +var __webpack_exports__LineSegmentsGeometry = __webpack_exports__.n3; +var __webpack_exports__MeshBVHLib = __webpack_exports__.Z5; +var __webpack_exports__SVGLoader = __webpack_exports__.cK; +var __webpack_exports__THREE = __webpack_exports__.ZH; +export { __webpack_exports__BufferGeometryUtils as BufferGeometryUtils, __webpack_exports__Line2 as Line2, __webpack_exports__LineGeometry as LineGeometry, __webpack_exports__LineMaterial as LineMaterial, __webpack_exports__LineSegments2 as LineSegments2, __webpack_exports__LineSegmentsGeometry as LineSegmentsGeometry, __webpack_exports__MeshBVHLib as MeshBVHLib, __webpack_exports__SVGLoader as SVGLoader, __webpack_exports__THREE as THREE }; diff --git a/src2/geo/base.js b/src2/geo/base.js index e0b3ad99..9db22f7e 100644 --- a/src2/geo/base.js +++ b/src2/geo/base.js @@ -1,6 +1,7 @@ /** Copyright Stewart Allen -- All Rights Reserved */ import { newPoint } from './point.js'; +import earcut from '../ext/earcut.js'; const round_decimal_precision = 5; @@ -843,9 +844,5 @@ function v2pr(rec) { return p; } -const earcut = self.earcut; - -// Export the base object and its properties -export { base }; -export { earcut }; +export { base, earcut }; export const { config, key, util, paths } = base; diff --git a/src2/geo/polygon.js b/src2/geo/polygon.js index 7dafa190..fe5e6472 100644 --- a/src2/geo/polygon.js +++ b/src2/geo/polygon.js @@ -2,12 +2,11 @@ "use strict"; -import { base, config, util } from './base.js'; +import { base, config, earcut, util } from './base.js'; import { ClipperLib } from '../ext/clip2.esm.js'; import { newBounds } from './bounds.js'; import { newPoint, pointFromClipper } from './point.js'; import { polygons as POLY } from './polygons.js'; -import { earcut } from '../geo/base.js'; const { Vector3 } = THREE; diff --git a/src2/kiri-mode/cam/slice.js b/src2/kiri-mode/cam/slice.js index dc3cc881..a3b49f08 100644 --- a/src2/kiri-mode/cam/slice.js +++ b/src2/kiri-mode/cam/slice.js @@ -33,8 +33,6 @@ export async function cam_slice(settings, widget, onupdate, ondone) { top_stock, top_part, top_gap, top_z, workarea; - console.log('CAM_SLICE', [...arguments]); - // allow recomputing later if widget or settings changes const var_compute = () => { let { camStockX, camStockY, camStockZ, camStockOffset } = proc; @@ -797,32 +795,14 @@ export function computeShadowAt(widget, z, ztop) { } } - // const lines = {}; - // function addline(p1, p2) { - // let key = p1.key < p2.key ? p1.key + ',' + p2.key : p2.key + ',' + p1.key; - // let rec = lines[key]; - // if (rec) { - // rec.count++; - // } else { - // lines[key] = { p1, p2, count: 1 }; - // } - // } - // for (let face of found) { - // addline(face[0], face[1]); - // addline(face[1], face[2]); - // addline(face[2], face[0]); - // } - // const singles = Object.entries(lines).filter(a => a[1].count === 1).map(a => a[1]); - // const loops = POLY.nest(sliceConnect(singles, z)); - let polys = found.map(a => { return newPolygon() .add(a[0].x,a[0].y,a[0].z) .add(a[1].x,a[1].y,a[1].z) .add(a[2].x,a[2].y,a[2].z); }); + polys = POLY.union(polys, 0.001, true); - // console.log({z, loops, polys}); - // return loops; + return polys; } diff --git a/src2/kiri-run/worker.js b/src2/kiri-run/worker.js index 91935b5f..05b70985 100644 --- a/src2/kiri-run/worker.js +++ b/src2/kiri-run/worker.js @@ -1,7 +1,6 @@ /** Copyright Stewart Allen -- All Rights Reserved */ -import "../ext/clip2.js"; -import "../ext/earcut.js"; +// import "../ext/clip2.js"; import '../add/array.js'; import '../add/class.js'; import '../add/three.js'; @@ -87,7 +86,6 @@ const minwork = { console.log({ MINION_MESSAGE_ERROR: error }); error.preventDefault(); }; - console.log({ minion }); minion.onmessage = minhandler; minion.postMessage({ cmd: "label", name: `#${i}` }); minions.push(minion); @@ -395,8 +393,6 @@ const dispatch = { const driver = drivers[mode]; const widget = wcache[data.id]; - console.log('WSLICE', { settings, mode, driver, widget }); - if (!(driver && driver.prepare)) { return console.log({ invalid_print_driver: mode, driver }); } diff --git a/src2/kiri/api.js b/src2/kiri/api.js index aa995035..bcbd1a75 100644 --- a/src2/kiri/api.js +++ b/src2/kiri/api.js @@ -121,7 +121,7 @@ export const api = { clone, // <-- color, conf: settings.conf, - const: { LANG, LOCAL, MODES, SETUP, SECURE, STACKS, VIEWS }, + const: { LANG, LISTS: lists, LOCAL, MODES, SETUP, SECURE, STACKS, VIEWS }, devel, // <-- device, devices, diff --git a/src2/kiri/client.js b/src2/kiri/client.js index cb273e9b..9e1535c0 100644 --- a/src2/kiri/client.js +++ b/src2/kiri/client.js @@ -75,7 +75,6 @@ export const client = { console.log({ WORKER_MESSAGE_ERROR: error }); error.preventDefault(); }; - console.log({ worker }); return worker; } }, @@ -196,7 +195,6 @@ export const client = { // called once for each widget slice(settings, widget, callback) { - console.log('CSLICE', { settings, widget, callback }); send("slice", { id: widget.id, anno: widget.annotations(), diff --git a/src2/kiri/do.js b/src2/kiri/do.js index 862adf2b..2432eab3 100644 --- a/src2/kiri/do.js +++ b/src2/kiri/do.js @@ -1,13 +1,8 @@ /** Copyright Stewart Allen -- All Rights Reserved */ -import { kiri } from './kiri.js'; -import { moto } from '../moto.js'; + import { api } from './api.js'; import { space } from '../moto/space.js'; - -const { kiri, moto } = root; -const { api } = kiri; -const { space } = moto; const { event } = api; let stack = []; @@ -44,7 +39,7 @@ let clear = api.doit.clear = function() { }; function updateButtons() { - let isArrange = api.view.get() === kiri.consts.VIEWS.ARRANGE; + let isArrange = api.view.get() === api.consts.VIEWS.ARRANGE; $('doit').style.display = isArrange && stack.length ? 'flex' : 'none'; $('undo').disabled = stpos === 0; $('redo').disabled = stpos == stack.length; @@ -175,6 +170,3 @@ event.on('mouse.drag.done', () => { }); moved = {x:0, y:0}; }); - - -// No direct exports; extends api.doit diff --git a/src2/kiri/init.js b/src2/kiri/init.js index be0772d2..96a82af7 100644 --- a/src2/kiri/init.js +++ b/src2/kiri/init.js @@ -13,7 +13,7 @@ import { beta, version } from '../moto/license.js'; import { settings as set_ctrl } from './settings.js'; let { CAM, SLA, FDM, LASER, DRAG, WJET, WEDM } = MODES, - { client, catalog, platform, selection } = api, + { consts, client, catalog, platform, selection } = api, LANG = api.language.current, WIN = self.window, DOC = self.document, @@ -1850,7 +1850,7 @@ function init_two() { if (SETUP.s) SETUP.s.forEach(function(lib) { let scr = DOC.createElement('script'); scr.setAttribute('defer',true); - scr.setAttribute('src',`/code/${lib}.js?${kiri.version}`); + scr.setAttribute('src',`/code/${lib}.js?${version}`); DOC.body.appendChild(scr); stats.add('load_'+lib); api.event.emit('load.lib', lib); @@ -1862,7 +1862,7 @@ function init_two() { let ss = DOC.createElement('link'); ss.setAttribute("type", "text/css"); ss.setAttribute("rel", "stylesheet"); - ss.setAttribute("href", `${style}.css?${kiri.version}`); + ss.setAttribute("href", `${style}.css?${version}`); DOC.body.appendChild(ss); }); @@ -1901,7 +1901,7 @@ function init_two() { if (!control.devel) { // TODO: hide thin type 3 during development - kiri.consts.LISTS.thin.length = 3; + consts.LISTS.thin.length = 3; } platform.deselect(); @@ -2081,7 +2081,7 @@ function init_two() { try { if (WIN.self !== WIN.top) $('top-sep').style.display = 'flex' } catch (e) { console.log(e) } // warn users they are running a beta release - if (beta && beta > 0 && sdb.kiri_beta != kiri.beta) { + if (beta && beta > 0 && sdb.kiri_beta != beta) { api.show.alert("CAUTION"); api.show.alert("this is a development release"); api.show.alert("and may not function properly"); @@ -2152,4 +2152,5 @@ function init_lang() { export function run() { init_lang(); + return api; } diff --git a/src2/main/kiri.js b/src2/main/kiri.js index a3f879dd..e66498ac 100644 --- a/src2/main/kiri.js +++ b/src2/main/kiri.js @@ -1,21 +1,44 @@ /** Copyright Stewart Allen -- All Rights Reserved */ +// import "../ext/clip2.js"; import '../add/array.js'; import '../add/class.js'; import '../add/three.js'; import '../kiri/lang.js'; import '../kiri/lang-en.js'; + import { run } from '../kiri/init.js'; console.log('KIRI V2'); +const load = []; + function checkReady() { if (document.readyState === 'complete') { console.trace('READY!'); - run(); + let api = run(); + kiri.api = api; + for (let fn of load) { + try { + fn(api); + } catch (error) { + console.log('load error', fn, error); + } + } } } +self.kiri = { + load(fn) { + console.log('KIRI LOAD', [...arguments]); + load.push(fn); + } +}; + +self.moto = { + +}; + // when dom + scripts complete document.onreadystatechange = checkReady; diff --git a/src2/webpack/esbuild.config.mjs b/src2/webpack/esbuild.config.mjs index d588d8c7..3d82dc8d 100644 --- a/src2/webpack/esbuild.config.mjs +++ b/src2/webpack/esbuild.config.mjs @@ -10,14 +10,19 @@ console.log(`Building in ${mode} mode...`); const MESH_OUTFILE = 'src2/pack/mesh-main.js'; const MESH_EXTRAS = [ - 'mod/*/mesh.js', - 'mod/*/tra1.js' + // 'mod/*/electron.js', + // 'mod/*/tra0m.js', + // 'mod/*/src/space.js' ]; const KIRI_OUTFILE = 'src2/pack/kiri-main.js'; const KIRI_EXTRAS = [ - 'mod/*/kiri.js', - 'mod/*/tra1.js' + // 'mod/*/electron.js', + // 'mod/*/sync.js', + // 'mod/*/don8.js', + // 'mod/*/onshape.js', + // 'mod/*/tra0.js', + // 'mod/*/src/space.js' ]; async function appendExtraModules(extras, outfile, minify = false) { @@ -78,7 +83,7 @@ async function buildApp() { } }); - // Bundle mesh main app + // Bundle kiri main app await build({ entryPoints: [ 'src2/main/kiri.js' ], bundle: true, @@ -96,7 +101,7 @@ async function buildApp() { appendExtraModules(KIRI_EXTRAS, KIRI_OUTFILE, isProd); - // Bundle mesh worker + // Bundle kiri worker await build({ entryPoints: [ 'src2/kiri-run/worker.js' ], bundle: true, @@ -112,6 +117,22 @@ async function buildApp() { } }); + // Bundle kiri minion + await build({ + entryPoints: [ 'src2/kiri-run/minion.js' ], + bundle: true, + outfile: 'src2/pack/kiri-pool.js', + format: 'esm', + external: ['module'], + sourcemap: !isProd, // true for dev, false for prod + minify: isProd, // false for dev, true for prod + target: 'es2020', + platform: 'browser', + define: { + 'process.env.NODE_ENV': `"${mode}"` + } + }); + console.log(`Build completed successfully in ${mode} mode!`); } catch (error) { console.error('Build failed:', error);