stear/main.js

770 lines
20 KiB
JavaScript
Raw Permalink Normal View History

2022-10-09 16:38:50 +02:00
import { LanguagePool, LanguagePoolString } from "./language.js"
2022-06-09 15:29:53 +02:00
var counter = 0;
2022-06-10 12:40:04 +02:00
2022-06-09 15:29:53 +02:00
var globalStyle = document.createElement("style");
document.head.appendChild(globalStyle);
String.prototype.map = Array.prototype.map;
function toCssAttr(txt) {
return txt.map(d => (d.toUpperCase() === d && d !== d.toLowerCase()) ? "-" + d.toLowerCase() : d).join("");
2022-10-09 16:38:50 +02:00
};
class callPromise extends Promise {
2022-10-09 16:38:50 +02:00
#opts = {};
constructor(cb) {
2022-10-09 16:38:50 +02:00
super(cb);
};
set opts(opts) {
2022-10-09 16:38:50 +02:00
this.#opts = opts;
}
get opts() {
2022-10-09 16:38:50 +02:00
return this.#opts;
}
2022-06-09 15:29:53 +02:00
}
2022-08-11 16:33:28 +02:00
const pools = {
};
2022-12-07 20:27:57 +01:00
const stears = [];
2022-11-12 14:17:48 +01:00
/** Stear class */
export class Stear {
2022-06-09 15:29:53 +02:00
elem;
#childs = {};
2022-11-12 14:17:48 +01:00
#frames = [];
2022-06-09 15:29:53 +02:00
2022-11-12 14:17:48 +01:00
/**
* Creating a Stear class. It can be used to render "stear" in an Element.
*
* @param {HTMLElement} elem
*/
constructor(elem) {
2022-06-09 15:29:53 +02:00
this.elem = elem;
elem.style.position = "relative";
2022-12-07 20:27:57 +01:00
stears.push(this);
}
destroy() {
2022-12-07 20:27:57 +01:00
let i = stears.indexOf(this);
if (i == -1) return;
stears.splice(i, 1);
2022-12-07 20:27:57 +01:00
delete this;
2022-06-09 15:29:53 +02:00
}
2022-11-12 14:17:48 +01:00
/**
* Change the Style of the render Element.
*
* @param {JSON} css
*/
style(css) {
2022-06-09 15:29:53 +02:00
Object.entries(css).forEach(([k, d]) => {
this.elem.style[k] = d;
});
}
2022-11-12 14:17:48 +01:00
/**
* An Store for Frames
*
* @param {string} id
* @param {SFrame} elem
*/
addElement(id, elem) {
if (!(elem instanceof SFrame)) throw new TypeError("Cannot add Element not extending from SFrame");
2022-06-09 15:29:53 +02:00
this.#childs[id] = elem;
}
2022-11-12 14:17:48 +01:00
/**
* Access an Element from the Frame Store
*
* @param {string} id
2022-11-12 14:45:05 +01:00
* @returns {SFrame}
2022-11-12 14:17:48 +01:00
*/
getElement(id) {
2022-06-09 15:29:53 +02:00
return this.g(id);
}
g(id) {
2022-06-09 15:29:53 +02:00
return this.#childs[id];
}
2022-11-12 14:17:48 +01:00
/**
* Render an Element gloabal.
*
* @param {SFrame} elem
* @param {*} args
* @param {number} layer
2022-11-12 14:45:05 +01:00
* @returns {callPromise}
2022-11-12 14:17:48 +01:00
*/
async call(elem, args, layer = 1) {
2022-11-12 14:17:48 +01:00
return await elem.call(this, args, this.#frames, layer);
2022-06-09 15:29:53 +02:00
}
2022-12-11 21:40:14 +01:00
async callInParent(elem, args, layer, renderParent = this.elem) {
return await elem.call(this, args, this.#frames, layer, renderParent);
}
2022-11-12 14:17:48 +01:00
/**
* Render an Element in annother Element.
*
* @param {SFrame} elem
* @param {*} args
* @param {HTMLElement} renderParent
* @param {number} layer
2022-11-12 14:45:05 +01:00
* @returns {callPromise}
2022-11-12 14:17:48 +01:00
*/
include(elem, args, renderParent, layer = 1) {
2022-11-12 14:17:48 +01:00
return elem.call(this, args, this.#frames, layer, renderParent);
2022-08-11 16:33:28 +02:00
}
2022-11-12 14:17:48 +01:00
/**
* Rernder everthing.
*
* @param {*} arg
2022-11-12 14:45:05 +01:00
* @returns {Promise}
2022-11-12 14:17:48 +01:00
*/
rerenderGlobal(arg) {
return new Promise((res, rej) => {
if (this.#frames.length == 0) return void res();
2022-11-12 14:17:48 +01:00
let running = this.#frames.length;
for (let i = 0; i < this.#frames.length; i++) {
const element = this.#frames[i];
element.globalRenderRequest(arg)
.then(() => {
running--;
if (running == 0) res();
});
2022-11-12 14:17:48 +01:00
}
});
2022-11-12 14:17:48 +01:00
}
/**
* Add raw css Data.
*
* @param {string} text
*/
static addGlobalStyleText(text) {
globalStyle.innerHTML += "\n" + text;
2022-06-09 15:29:53 +02:00
}
2022-11-12 14:17:48 +01:00
/**
* Add a css Animation
*
* @param {object} steps - css like json Syntax
* @param {string} name
* @returns {string} name
*/
static addAnimation(steps, name = "stearAnimation_" + counter++) {
2022-06-09 15:29:53 +02:00
Stear.addGlobalStyleText(`@keyframes ${name} {
${Object.entries(steps).map(([k, d]) =>
` ${k} {
2022-06-09 15:29:53 +02:00
${Object.entries(d).map(d => " " + toCssAttr(d[0]) + ": " + d[1] + ";").join("\n")}
}`).join("\n")
}
2022-06-09 15:29:53 +02:00
}`);
return name;
}
2022-11-12 14:17:48 +01:00
/**
*
* @param {object} json - css like json Syntax
* @param {string} name - e.g. .classname
* @returns {string} name
*/
static addGlobalStyleJSON(json, name = ".stearClass_" + counter++) {
2022-06-09 15:29:53 +02:00
Stear.addGlobalStyleText(`
${name} {
${Object.entries(json).map(d => " " + toCssAttr(d[0]) + ": " + d[1] + ";").join("\n")}
}
`)
return name;
}
2022-08-11 16:33:28 +02:00
2022-11-12 14:17:48 +01:00
/**
* Add A Language Pool. E.g. for a subpage.
*
* @param {string} name
* @returns {LanguagePool}
*/
static addLanguagePool(name) {
if (typeof pools[name] == "undefined") {
2022-08-11 16:33:28 +02:00
pools[name] = new LanguagePool();
}
return pools[name];
}
2022-11-12 14:17:48 +01:00
/**
* Add a file containing translations.
*
* @param {JSON} data
* @param {string} lang
*/
static addLanguageFile(data, lang) {
Object.entries(data).forEach(([k, d]) => {
2022-08-11 16:33:28 +02:00
if (typeof pools[k] == "undefined") pools[k] = new LanguagePool();
pools[k].addFile(d, lang);
2022-08-11 16:33:28 +02:00
});
}
2022-08-11 16:33:28 +02:00
2022-11-12 14:17:48 +01:00
/**
* Used Language
*/
static set lang(lang) {
2022-08-11 16:33:28 +02:00
Object.entries(pools).forEach(([k, d]) => {
d.lang = lang;
});
stears.forEach(s => s.rerenderGlobal());
2022-08-11 16:33:28 +02:00
}
2022-11-12 14:17:48 +01:00
/**
* Generate Language File with defaults
*/
static get getLanguageFile() {
2022-08-11 16:33:28 +02:00
var out = {};
Object.entries(pools).forEach(([k, d]) => {
out[k] = d.getFile;
});
return out;
}
}
2022-11-12 14:17:48 +01:00
////////////////////////////////////////////////////////////////////////
//utils
/**
* Can be called to close a frame and return a response.
* @async
* @callback utilsResolveCallback
* @param {*} returnValue
* @param {boolean} close
*/
/**
* Remove this Frame from Screen
* @async
* @callback utilsCloseCallback
*/
/**
* Rerender the local Content
* @async
* @callback utilsRenderCallback
* @param {...*} args
* @return {objectt} find
*/
/**
* Open and run another frame with the ability to return data.
* @async
* @callback utilsCallCallback
* @param {SFrame} elem
2022-12-11 21:40:14 +01:00
* @param {*} [args={}]
* @param {boolean} [global=true]
2022-11-12 14:17:48 +01:00
* @return {callPromise}
*/
/**
* Embet another Frame
* @async
* @callback utilsIncludeCallback
* @param {SFrame} elem
* @param {*} args
* @return {includeFrame}
*/
/////////////////////////////////////////////////////////////////////////
//eventCallbacks
/**
* Called when Page is fully loaded.
* @callback eventOnLoadedCallback
*/
/**
* Will be called and awaited bevor resolving.
* @async
* @callback eventOnResolveCallback
*/
/**
* Will be called and awaited bevor closing.
* @async
* @callback eventOnCloseCallback
*/
/**
* Will be called and awaited bevor rerendering.
* @async
* @callback eventOnBeforRerenderCallback
* @param {...*} args - any given param
*/
/**
* Will be called and awaited after rerendering.
* @async
* @callback eventOnAfterRerenderCallback
* @param {...*} args - any given param
*/
/**
* Will be called when included in another Frame and that Frame rerenders.
* @callback eventOnParentRenderCallback
*/
/**
* Will be called when included in another Frame and that Frame rerenders.
* @callback eventOnGlobalRenderCallback
*/
/**
* @typedef callUtils
* @type {Object}
* @property {Object} find - find an element in local tree
* @property {utilsResolveCallback} resolve - Return the Data
* @property {utilsCloseCallback} close - Close the Frame
* @property {utilsRenderCallback} render - Rerender the Frame
* @property {utilsCallCallback} call - Use another Frame
* @property {utilsIncludeCallback} include - Include another Frame
* @property {Object} event - local Events
* @property {eventOnLoadedCallback} event.onloaded
* @property {eventOnResolveCallback} event.onresolve
* @property {eventOnCloseCallback} event.close
* @property {eventOnBeforRerenderCallback} event.onBeforRerender
* @property {eventOnAfterRerenderCallback} event.onAfterRerender
* @property {eventOnParentRenderCallback} event.onParentRender
* @property {eventOnGlobalRenderCallback} event.onGlobalRenderRequest
*/
/**
* This callback will be called, when a frame should be opened.
* @callback callCallback
* @param {Stear} stear
* @param {callUtils} utils - lots of utils for Frame manipulation
* @param {*} args
*/
/**
* SFrame class
*/
export class SFrame {
2022-06-09 15:29:53 +02:00
#preRender;
#call;
2022-11-12 14:17:48 +01:00
/**
*
* @param {Object} args
* @param {callCallback} args.call
* @param {boolean} [args.preRender]
*/
constructor({ call, preRender = true }) {
2022-06-09 15:29:53 +02:00
this.#preRender = preRender;
this.#call = call;
}
call(stear, args, frames, layer = 1, renderParent = stear.elem) {
2022-08-10 21:56:12 +02:00
let lastRender;
let renderElem;
let event = { onloaded: () => { }, onclose: () => { }, onresolve: () => { }, onBeforRerender: () => { }, onAfterRerender: () => { }, onParentRender: () => { }, onGlobalRenderRequest: () => true };
2022-08-10 21:56:12 +02:00
let find = {};
let resolved = false;
async function render(args) {
if (!renderElem) return;
2022-12-11 21:40:14 +01:00
//if (lastRender) if ([...(renderParent.children)].includes(lastRender._)) renderParent.removeChild(lastRender._);
2022-08-10 21:56:12 +02:00
let now = renderElem;
2022-12-11 21:40:14 +01:00
if (typeof now == "function") {
if (lastRender) if ([...(renderParent.children)].includes(lastRender._)) renderParent.removeChild(lastRender._);
now = await now();
}
if (!(now instanceof class_)) throw new Error("The Element to render is not an instance of class_");
2022-08-10 21:56:12 +02:00
await now.build(args);
2022-12-11 21:40:14 +01:00
now.render
if (!lastRender || ![...(renderParent.children)].includes(lastRender._)) renderParent.appendChild(now._);
2022-08-10 21:56:12 +02:00
lastRender = now;
now._.style.zIndex = layer;
for (var member in find) delete find[member];
Object.assign(find, now.find);
return lastRender;
2022-06-09 17:30:40 +02:00
}
2022-10-09 16:38:50 +02:00
const ppp = new callPromise(async (res, rej) => {
2022-11-12 14:17:48 +01:00
const globalRegister = {
globalRenderRequest: async (...args) => {
2022-11-12 14:17:48 +01:00
const arg = await event.onGlobalRenderRequest(...args);
if (arg === false) return;
2022-11-12 14:17:48 +01:00
await options.render(arg);
}
}
frames.push(globalRegister);
2022-10-09 16:38:50 +02:00
const options = {
2022-08-10 21:56:12 +02:00
find,
render: async (...args) => {
await event.onBeforRerender(...args);
2022-10-09 16:38:50 +02:00
if (renderElem) await render(args);
2022-08-10 21:56:12 +02:00
firstRender = true;
await event.onAfterRerender(...args);
return find;
2022-06-09 15:29:53 +02:00
},
2022-10-09 16:38:50 +02:00
resolve: async (r, close = true) => {
2022-08-10 21:56:12 +02:00
if (resolved) return;
resolved = true;
await event.onresolve();
2022-08-11 16:33:28 +02:00
if (close && lastRender && [...(renderParent.children)].includes(lastRender._)) renderParent.removeChild(lastRender._);
2022-11-12 14:17:48 +01:00
let i = frames.indexOf(globalRegister);
if (i > -1) frames.splice(i, 1);
2022-06-09 15:29:53 +02:00
res(r);
},
2022-12-11 21:40:14 +01:00
call: (elem, args = {}, global = true) => {
if (global) return stear.call(elem, args, layer + 1);
else return stear.callInParent(elem, args, layer + 1, renderParent);
2022-06-10 23:00:47 +02:00
},
2022-10-09 16:38:50 +02:00
close: async () => {
2022-08-10 21:56:12 +02:00
await event.onclose();
2022-11-12 14:17:48 +01:00
if (lastRender && [...(renderParent.children)].includes(lastRender._)) renderParent.removeChild(lastRender._);
2022-08-10 21:56:12 +02:00
},
2022-10-09 16:38:50 +02:00
include: (frame, args = {}) => {
let iFrame = new includeFrame(stear, frame, layer + 1, args);
return iFrame;
},
event,
};
window.queueMicrotask(() => ppp.opts = options);
2022-10-09 16:38:50 +02:00
let firstRender = false;
renderElem = await this.#call(stear, options, args);
if (!renderElem) {
} else {
2022-08-10 21:56:12 +02:00
if (this.#preRender | firstRender) await render([]);
event.onloaded();
}
2022-06-09 15:29:53 +02:00
});
2022-10-09 16:38:50 +02:00
return ppp;
2022-06-09 15:29:53 +02:00
}
}
2022-11-12 14:17:48 +01:00
/** Create a SWindow, a Fullscreen Frame. */
export class SWindow extends SFrame {
2022-06-09 15:29:53 +02:00
2022-06-10 01:07:55 +02:00
#Frame;
2022-11-12 14:17:48 +01:00
/**
*
* @param {Object} args
* @param {callCallback} args.call
* @param {boolean} [args.preRender]
*/
constructor({ call, preRender = true, backgroundColor = "transparent" }) {
2022-11-12 14:17:48 +01:00
/*var Frame = _({
2022-06-09 17:30:40 +02:00
style: {
top: "0px",
left: "0px",
position: "absolute",
height: "100%",
width: "100%",
2022-06-10 01:07:55 +02:00
display: "block",
backgroundColor,
2022-06-10 15:01:23 +02:00
//overflow:"scroll"
2022-06-10 01:07:55 +02:00
},
find:"main"
2022-11-12 14:17:48 +01:00
}, []);*/
2022-06-09 17:30:40 +02:00
super({
call: async (...args) => _({
2022-08-10 21:56:12 +02:00
style: {
top: "0px",
left: "0px",
position: "absolute",
height: "100%",
width: "100%",
display: "block",
backgroundColor,
//overflow:"scroll"
},
find: "main"
}, await call(...args)),
2022-08-10 21:56:12 +02:00
preRender
2022-06-09 17:30:40 +02:00
});
2022-11-12 14:17:48 +01:00
//this.#Frame = Frame;
2022-06-09 15:29:53 +02:00
}
2022-06-09 15:29:53 +02:00
}
2022-11-12 14:17:48 +01:00
/**
* @typedef renderNodeSettings
* @type {Object}
* @property {string}[type]
* @property {string}[find]
* @property {Object}[event]
* @property {Object}[attr]
*/
/** Create a Render node, */
2022-06-09 15:29:53 +02:00
export class class_ {
#elem;
#childs;
2022-08-10 21:56:12 +02:00
#build;
2022-06-09 15:29:53 +02:00
#find;
2022-10-09 16:38:50 +02:00
#doBuild;
2022-06-09 15:29:53 +02:00
#dynamicState = 0;
2022-12-11 21:40:14 +01:00
#dynamicStyle = {};
2022-11-12 14:17:48 +01:00
/**
* Generate a new Stear render Node.
*
* @param {renderNodeSettings} settings
2022-11-12 14:45:05 +01:00
* @param {Array} childs
2022-11-12 14:17:48 +01:00
* @param {boolean} doBuild
*/
constructor(settings, childs, doBuild = true) {
2022-12-19 23:03:37 +01:00
const type = settings.type ?? "div";
if((["circle", "ellipse", "line", "path", "polygon", "polyline", "rect","svg" ]).includes(type))
this.#elem = document.createElementNS("http://www.w3.org/2000/svg",type);
else this.#elem = document.createElement(type);
2022-06-09 15:29:53 +02:00
this.#childs = childs;
var keys = Object.keys(settings);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (key == "type") { } else if (key == "style") {
Object.entries(settings[key]).forEach(([k, d]) => {
2022-12-11 21:40:14 +01:00
if (typeof d == "function") this.#dynamicStyle[k] = d;
else this.#elem.style[k] = d;
2022-06-09 15:29:53 +02:00
});
} else if (key == "find") {
2022-06-09 15:29:53 +02:00
this.#find = settings[key];
} else if (key == "event") {
2022-06-09 17:30:40 +02:00
Object.entries(settings[key]).forEach(([k, d]) => {
this.#elem.addEventListener(k, d);
2022-06-09 17:30:40 +02:00
});
} else if (key == "attr") {
2022-10-09 16:38:50 +02:00
Object.entries(settings[key]).forEach(([k, d]) => {
this.#elem.setAttribute(k, d);
});
2022-06-09 17:30:40 +02:00
} else {
this.#elem.setAttribute(key, settings[key]);
2022-06-09 15:29:53 +02:00
}
}
2022-10-09 16:38:50 +02:00
this.#doBuild = doBuild;
2022-06-09 15:29:53 +02:00
}
2022-11-12 14:17:48 +01:00
/**
2022-11-12 14:45:05 +01:00
* @param {Array} childs
2022-11-12 14:17:48 +01:00
*/
set childs(childs) {
if (!this.#doBuild) return;
2022-06-09 21:37:23 +02:00
this.#childs = Array.isArray(childs) ? childs : [childs];
this.#dynamicState = 0;
2022-06-09 15:29:53 +02:00
}
2022-08-10 21:56:12 +02:00
2022-11-12 14:17:48 +01:00
/**
* @param {renderNodeSettings} settings
*/
set settings(settings) {
2022-06-09 15:29:53 +02:00
var keys = Object.keys(settings);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (key == "type") { } else if (key == "style") {
Object.entries(settings[key]).forEach(([k, d]) => {
this.#elem.style[k] = d;
});
} else if (key == "find") {
this.#find = settings[key];
} else {
this.#elem.setAttribute(key, settings[key]);
}
}
}
2022-12-11 21:40:14 +01:00
async updateDynamicStyle(args) {
for (const key in this.#dynamicStyle) {
this.#elem.style[key] = await this.#dynamicStyle[key](args);
}
}
async #syncBuild(args) {
for (let i = 0; i < this.#childs.length; i++) {
let elem = this.#childs[i];
if (Array.isArray(elem)) {
for (let j = 0; j < elem.length; j++) {
if (elem[j] instanceof class_) await elem[j].build(args);
}
} else {
if (elem instanceof class_) await elem.build(args);
}
}
}
2022-11-12 14:17:48 +01:00
/**
* Build Stear Structure
*
* @param {*} args
*/
async build(args) {
if (!this.#doBuild) return;
2022-12-11 21:40:14 +01:00
this.updateDynamicStyle(args);
if (this.#dynamicState < 0) return void await this.#syncBuild(args);
2022-08-10 21:56:12 +02:00
this.#build = [];
for (let i = 0; i < this.#childs.length; i++) {
let elem = this.#childs[i];
if (typeof elem == "function") {
elem = (await elem(...args)) ?? [];
this.#dynamicState = 2;
}
2022-08-10 21:56:12 +02:00
if (Array.isArray(elem)) {
2022-08-10 21:56:12 +02:00
for (let j = 0; j < elem.length; j++) {
if (elem[j] instanceof class_) await elem[j].build(args);
}
this.#build.push(...elem);
} else {
if (elem instanceof class_) await elem.build(args);
2022-08-10 21:56:12 +02:00
this.#build.push(elem);
}
}
if (this.#dynamicState <= 0) this.#dynamicState = -1;
}
#syncRender() {
let out = [];
for (let i = 0; i < this.#build.length; i++) {
const elem = this.#build[i];
if (typeof elem != "string" && !(elem instanceof LanguagePoolString)) {
out[i] = elem.render;
}
}
2022-08-10 21:56:12 +02:00
}
2022-11-12 14:17:48 +01:00
/**
* Genereate HTML Structure
*
* @return {HTMLElement}
*/
get render() {
2022-10-09 16:38:50 +02:00
if (!this.#doBuild) return this.#elem;
if (this.#dynamicState < -1) {
this.#syncRender();
return this.#elem;
}
2022-12-07 20:27:57 +01:00
let out = [];
2022-12-11 21:40:14 +01:00
let needReplace = false;
2022-08-10 21:56:12 +02:00
for (let i = 0; i < this.#build.length; i++) {
const elem = this.#build[i];
2022-08-11 16:33:28 +02:00
if (typeof elem == "string" || elem instanceof LanguagePoolString) {
2022-12-07 20:27:57 +01:00
out[i] = document.createTextNode(String(elem));
2022-08-10 21:56:12 +02:00
} else {
2022-12-07 20:27:57 +01:00
out[i] = elem.render;
}
2022-12-19 23:03:37 +01:00
if (!needReplace && this.#elem.children[i] != out[i]) needReplace = true;
2022-06-09 15:29:53 +02:00
}
2022-12-19 23:03:37 +01:00
if (needReplace||out.length==0) this.#elem.replaceChildren(...out);
if (this.#dynamicState < 0) this.#dynamicState = -2;
2022-06-09 15:29:53 +02:00
return this.#elem;
}
2022-11-12 14:17:48 +01:00
/**
* @return {HTMLElement}
*/
get _() {
2022-06-09 15:29:53 +02:00
return this.#elem;
}
2022-12-07 22:11:36 +01:00
/**
* Rerender only this and child nodes.
* @param {any[]} args Arguments, that should be given all render methodes
*/
async rerender(args = []) {
await this.build(args);
this.render;
}
2022-11-12 14:17:48 +01:00
/**
* Returns find Object
*
* @return {Object} find
*/
get find() {
var out = {};
if (this.#doBuild) {
this.#build.forEach(d => {
Object.assign(out, d.find);
2022-10-09 16:38:50 +02:00
});
}
if (this.#find) out[this.#find] = this;
2022-06-09 15:29:53 +02:00
return out;
}
}
2022-11-12 14:17:48 +01:00
/**
*
* @param {renderNodeSettings} [settings]
2022-11-12 14:45:05 +01:00
* @param {Array} [childs]
* @returns {class_}
2022-11-12 14:17:48 +01:00
*/
2022-06-09 16:49:03 +02:00
export const _ = (settings = {}, childs = []) => new class_(settings, Array.isArray(childs) ? childs : [childs]);
export const s = (type, settings, ...childs) => {
2022-11-12 14:17:48 +01:00
settings = settings ?? {};
2022-11-02 14:45:15 +01:00
settings.type = type;
return new class_(settings, childs);
2022-11-02 14:45:15 +01:00
}
2022-06-09 15:29:53 +02:00
2022-11-12 14:17:48 +01:00
/** includeFrame */
class includeFrame {
2022-10-09 16:38:50 +02:00
#elem;
#call;
2022-11-12 14:17:48 +01:00
/**
* Call another Frame and generate an includeFrame.
*
* @param {Stear} stear
* @param {SFrame} frame
* @param {number} layer
* @param {*} args
*/
constructor(stear, frame, layer, args = {}) {
this.#elem = new class_({}, [], false);
2022-10-09 16:38:50 +02:00
this.#call = stear.include(frame, args, this.#elem._, layer);
this.#call.then(() => {
2022-10-09 16:38:50 +02:00
})
.catch(() => {
2022-10-09 16:38:50 +02:00
});
2022-10-09 16:38:50 +02:00
}
2022-11-12 14:17:48 +01:00
/**
* @return {callUtils} utils from included Frame
*/
get opts() {
2022-10-09 16:38:50 +02:00
return this.#call.opts;
}
2022-11-12 14:17:48 +01:00
/**
* Close the included Frame.
*/
close() {
if (this.#call) {
2022-10-09 16:38:50 +02:00
this.#call.opts.close();
}
}
2022-11-12 14:17:48 +01:00
/**
* Trigger onParentRender event
*
* @param {*} settings
2022-11-12 14:45:05 +01:00
* @returns {HTMLElement}
2022-11-12 14:17:48 +01:00
*/
render(settings = {}) {
2022-10-09 16:38:50 +02:00
this.#elem.settings = settings;
this.#call.opts.event.onParentRender();
return this.#elem;
}
2022-10-09 16:38:50 +02:00
};