// xjs.js (development loader) // - Dev/test: lightweight loader that imports source files (animal.js + layer.js) // - Production: use the bundled output from `go run main.go build` (defaults to dist/xjs.js) ;(function (global) { 'use strict'; const g = global || (typeof window !== 'undefined' ? window : globalThis); const doc = (typeof document !== 'undefined') ? document : null; if (!doc) return; // Avoid double-loading if (g.xjs && g.Layer) return; const current = doc.currentScript; const base = (() => { try { const u = new URL(current && current.src ? current.src : 'xjs.js', location.href); return u.href.replace(/[^/]*$/, ''); // directory of xjs.js } catch { return ''; } })(); const loadScript = (src) => new Promise((resolve, reject) => { const s = doc.createElement('script'); s.src = src; s.async = false; // preserve execution order s.onload = () => resolve(); s.onerror = () => reject(new Error('Failed to load: ' + src)); (doc.head || doc.documentElement).appendChild(s); }); const ensureGlobals = () => { try { if (g.animal && !g.xjs) g.xjs = g.animal; if (g.xjs && !g.$) g.$ = g.xjs; if (g.$ && !g.xjs) g.xjs = g.$; if (g.$ && !g.animal) g.animal = g.$; } catch {} }; (async () => { // Load animal first so xjs alias is available before layer tries to query it if (!g.animal) await loadScript(base + 'animal.js'); ensureGlobals(); if (!g.Layer) await loadScript(base + 'layer.js'); ensureGlobals(); })().catch((err) => { try { console.error('[xjs.dev] load failed', err); } catch {} }); })(typeof window !== 'undefined' ? window : globalThis);