move src2 -> src, web2 -> web, remove old module system, fix deps

This commit is contained in:
Stewart Allen 2025-07-06 23:44:33 -04:00
commit ce4f5d6e78
488 changed files with 26179 additions and 26609 deletions

View file

@ -1,19 +1,13 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
"use strict";
// dep: data.local
gapp.register("moto.ajax", [], (root, exports) => {
import { local } from '../data/local.js';
function rnd() {
return Math.round(Math.random()*0xffffffff).toString(36);
}
const { data } = root;
const { local } = data;
const KEY = "moto-ajax";
const MOID = moto.id = local.getItem(KEY) || (Date.now().toString(36)+rnd()+rnd());
const MOID = local.getItem(KEY) || (Date.now().toString(36)+rnd()+rnd());
local.setItem(KEY, MOID);
@ -69,14 +63,13 @@ function call(url, handler) {
}
function restore(id) {
MOID = moto.id = id;
MOID = id;
local.setItem(KEY, MOID);
}
exports({
new(cb, rt) { return new Ajax(cb, rt) },
export const ajax = {
new: (cb, rt) => new Ajax(cb, rt),
call,
restore,
});
});
id: MOID
};

View file

@ -1,15 +1,12 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
"use strict";
gapp.register("moto.broker", [], (root, exports) => {
class Broker {
#debug = false;
#topics = {};
#used = {};
#send = {};
constructor() {
this.topics = {};
this.used = {};
this.send = {};
// using the pattern "broker.send(msg)" induces runtime errors
// when there is not at least one registered listener for a topic
// while also allowing for a more natural function call interface
@ -17,7 +14,11 @@ class Broker {
}
topics() {
return Object.keys(this.topics);
return Object.keys(this.#topics);
}
get send() {
return this.#send;
}
// create subscriptions for all functions in an object
@ -42,16 +43,19 @@ class Broker {
return this;
}
if (typeof topic !== 'string') {
console.trace({invalid_topic: topic});
for (let [ key, fn ] of Object.entries(topic)) {
this.subscribe(key, fn.bind(listener));
}
// console.trace({invalid_topic: topic});
return;
}
let topics = this.topics;
let topics = this.#topics;
let channel = topics[topic];
if (!channel) {
channel = topics[topic] = [];
}
if (channel.indexOf(listener) < 0) {
let send = this.send;
let send = this.#send;
let name = topic.replace(/[\\ \.-]/g, '_');
send[name] = send[name] = this.bind(topic);
channel.push(listener);
@ -61,7 +65,7 @@ class Broker {
}
unsubscribe(topic, listener) {
let channel = this.topics[topic];
let channel = this.#topics[topic];
if (!channel) {
return;
}
@ -71,7 +75,7 @@ class Broker {
}
channel.splice(index,1);
if (channel.length === 0) {
delete this.topics[topic];
delete this.#topics[topic];
this.publish(".topic.remove", topic);
}
}
@ -86,10 +90,13 @@ class Broker {
if (topic !== ".topic.publish") {
this.publish(".topic.publish", {topic, message, options});
}
if (this.#debug && !topic.startsWith(".")) {
console.log({ topic, message });
}
// store last seen message on a topic
// acts as a tracker for all used topics
this.used[topic] = message;
let channel = this.topics[topic];
this.#used[topic] = message;
let channel = this.#topics[topic];
if (channel && channel.length) {
for (let listener of channel) {
try {
@ -136,10 +143,6 @@ class Broker {
}
}
}
}
const { moto } = root;
gapp.broker = moto.broker = new Broker();
});
export const broker = new Broker();

View file

@ -2,9 +2,7 @@
"use strict";
// dep: add.array
// dep: moto.broker
gapp.register("moto.client", [], (root, exports) => {
import { broker } from './broker.js';
let ccvalue = self.navigator ? navigator.hardwareConcurrency || 1 : 1,
ccmax = ccvalue > 3 ? ccvalue - 1 : 1,
@ -22,8 +20,7 @@ function dispatch(topic, message) {
}
// code is running in the browser / client context
const client = exports({
const client = {
/** @returns [integer] total number of workers **/
live: () => {
return workers.length;
@ -153,7 +150,7 @@ const client = exports({
if (self.createWorker) {
return self.createWorker();
} else {
return new Worker(workurl = url);
return new Worker(workurl = url, { type: 'module' });
}
},
@ -191,9 +188,14 @@ const client = exports({
let worker = client.spawn(workurl);
worker.run = null;
worker.index = i;
worker.onerror = function(e) {
console.log({ worker_error: e });
}
worker.onmessageerror = function(e) {
console.log({ worker_message_error: e });
}
worker.onmessage = function(e) {
let reply = e.data;
// handle special case for task binding
if (reply.bind) {
client.bind(reply.bind);
@ -208,7 +210,7 @@ const client = exports({
// handle special case for broker publish
if (reply.publish) {
gapp.broker.publish(reply.publish, reply.message);
broker.publish(reply.publish, reply.message);
return;
}
@ -251,7 +253,6 @@ const client = exports({
client.kick();
}
};
});
});
export { client };

View file

@ -1,27 +1,11 @@
(function() {
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
const is_self = typeof(self) !== 'undefined';
const terms = {
COPYRIGHT: "Copyright (C) Stewart Allen <sa@grid.space> - All Rights Reserved",
LICENSE: "See the license.md file included with the source distribution",
VERSION: "4.3.0"
};
let terms = {
COPYRIGHT: "Copyright (C) Stewart Allen <sa@grid.space> - All Rights Reserved",
LICENSE: "See the license.md file included with the source distribution",
VERSION: (is_self ? self : this).debug_version || "4.2.0"
};
if (typeof(module) === 'object') {
module.exports = terms;
}
// allow license to be required() by app without gapp
if (is_self && self.gapp) {
let app = self.gapp;
app.license = terms.LICENSE;
app.version = terms.VERSION;
app.copyright = terms.COPYRIGHT;
// satisfy resolver
gapp.register('moto.license');
// for earcut and other modules
(self.module = self.module || {}).exports = terms;
}
})();
export const beta = 1;
export const license = terms;
export const version = terms.VERSION;

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,7 @@
// code for a ServiceWorker that provides support for running cached/offline
const version = self.gapp.version;
import { version } from './license.js';
const origin = self.location.origin;
const stats = {
hit: 0,

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,5 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
"use strict";
// dep: moto.license
// dep: add.array
gapp.register("moto.webui", [], (root, exports) => {
let nextid = 1;
@ -47,8 +42,11 @@ function build(data, context) {
func[key] = val;
elid = elid || `_${nextid++}`;
} else if (tov === 'object') {
if (val.length)
html.push(` ${key}="${val.filter(v => v !== undefined).join(' ')}"`);
if (Array.isArray(val)) {
html.push(` ${key}="${val.filter(v => v !== undefined).join(' ')}"`);
} else {
html.push(` ${key}="${val}"`);
}
} else if (tov !== 'undefined') {
html.push(` ${key}="${val}"`);
}
@ -77,7 +75,7 @@ function build(data, context) {
}
// core html builder funtions
let h = exports({
const h = {
bind: (el, data, opt = {}) => {
let ctx = [];
let html = build(data, ctx).join('');
@ -118,43 +116,39 @@ let h = exports({
build: (data) => {
return build(data, []).join('');
}
});
};
// window ui helpers
gapp.overlay(root, {
$: (id) => {
return document.getElementById(id);
},
const $ = (id) => {
return document.getElementById(id);
};
$d: (id, v) => {
$(id).style.display = v;
},
const $d = (id, v) => {
$(id).style.display = v;
};
$h: (id, h) => {
$(id).innerHTML = h;
},
const $h = (id, h) => {
$(id).innerHTML = h;
};
$c: (id, add, del) => {
if (add) $(id).classList.add(add);
if (del) $(id).classList.remove(del);
},
const $c = (id, add, del) => {
if (add) $(id).classList.add(add);
if (del) $(id).classList.remove(del);
};
$C: (clazz, add, del) => {
let el = [...document.getElementsByClassName(clazz)];
for (let e of el) {
if (add) e.classList.add(add);
if (del) e.classList.remove(del);
}
return el;
},
h,
estop: (evt) => {
evt.stopPropagation();
evt.preventDefault();
const $C = (clazz, add, del) => {
let el = [...document.getElementsByClassName(clazz)];
for (let e of el) {
if (add) e.classList.add(add);
if (del) e.classList.remove(del);
}
});
return el;
};
const estop = (evt) => {
evt.stopPropagation();
evt.preventDefault();
};
// add common element types
[
@ -166,4 +160,12 @@ gapp.overlay(root, {
}
});
});
export {
$,
$d,
$h,
$c,
$C,
h,
estop
};

View file

@ -1,14 +1,9 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
"use strict";
gapp.register("moto.worker", [], (root, exports) => {
let endpoints = {};
// code is running in the worker / server context
const dispatch = exports({
const dispatch = {
// bind an endpoint name to a function
bind(name, fn) {
endpoints[name] = fn;
@ -95,10 +90,9 @@ const dispatch = exports({
send.error(`no registered endpoint: ${msg.task}`);
}
}
});
};
// attach onmessage hanler
self.onmessage = dispatch.onmessage;
});
export const worker = dispatch;