// 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;
// Optional: export `$` only when explicitly requested
if (g.XJS_GLOBAL_DOLLAR && !g.$ && g.xjs) g.$ = g.xjs;
} 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);
// xjs.js - combined single-file build (animal + layer)
// Generated from source files in this repo.
// Usage:
//
// Globals:
// - window.xjs (primary, same as animal)
// - window.animal (compat)
// - window.Layer
// Optional:
// - set window.XJS_GLOBAL_DOLLAR = true before loading to also export window.$ (only if not already defined)
(function(){
var __GLOBAL__ = (typeof window !== 'undefined') ? window : (typeof globalThis !== 'undefined' ? globalThis : this);
/* --- layer.js --- */
(function (global, factory) {
const LayerClass = factory();
// Allow usage as `Layer({...})` or `new Layer()`
// But Layer is a class. We can wrap it in a proxy or factory function.
function LayerFactory(options) {
if (options && typeof options === 'object') {
return LayerClass.$(options);
}
return new LayerClass();
}
// Copy static methods (including non-enumerable class statics like `fire` / `$`)
// Class static methods are non-enumerable by default, so Object.assign() would miss them.
const copyStatic = (to, from) => {
try {
Object.getOwnPropertyNames(from).forEach((k) => {
if (k === 'prototype' || k === 'name' || k === 'length') return;
const desc = Object.getOwnPropertyDescriptor(from, k);
if (!desc) return;
Object.defineProperty(to, k, desc);
});
} catch (e) {
// Best-effort fallback
try { Object.assign(to, from); } catch {}
}
};
copyStatic(LayerFactory, LayerClass);
// Also copy prototype for instanceof checks if needed (though tricky with factory)
LayerFactory.prototype = LayerClass.prototype;
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = LayerFactory :
typeof define === 'function' && define.amd ? define(() => LayerFactory) :
(global.Layer = LayerFactory);
}(__GLOBAL__, (function () {
'use strict';
const PREFIX = 'layer-';
// Ensure library CSS is loaded (xjs.css)
// - CSS is centralized in xjs.css (no runtime