Compare commits

...

16 commits

Author SHA1 Message Date
29d46ea17f fix move 2022-12-07 22:23:21 +01:00
66b219990a updated submodule 2022-12-07 22:22:32 +01:00
5e85ac4a5b added jsx 2022-12-07 22:21:00 +01:00
36356a5743 fix 2022-11-03 22:21:52 +01:00
fb72684328 example restructure 2022-11-03 22:12:53 +01:00
21062d92da fix 2022-11-02 19:09:14 +01:00
210ba52685 jsx 2022-11-02 14:45:56 +01:00
3c7c19a3d2 fix 2022-10-09 16:42:40 +02:00
7ac811ff97 include 2022-10-09 16:36:35 +02:00
fa8fbfe1ff updated Readme und example 2022-08-13 17:52:45 +02:00
9d78ed2f80 submodule update 2022-06-10 23:49:20 +02:00
787809b8da submodule update 2022-06-10 23:02:00 +02:00
a6a5d9035f submodule update 2022-06-10 15:04:09 +02:00
7126448016 Merge branch 'main2' into 'main'
Deleted stear/extra/Elements/loading1.js, stear/extra/Pages/alert.js,...

See merge request jusax23/stear!1
2022-06-10 10:46:57 +00:00
d53be1b334 added submodule 2022-06-10 12:43:10 +02:00
53d03e22d8 Deleted stear/extra/Elements/loading1.js, stear/extra/Pages/alert.js, stear/extra/Pages/showStatus.js, stear/main.js, stear/utils.js 2022-06-10 10:13:47 +00:00
24 changed files with 2838 additions and 640 deletions

4
.gitmodules vendored Normal file
View file

@ -0,0 +1,4 @@
[submodule "stear"]
path = stear
url = https://jusax.de/git/jusax23/stear.git
branch = submodule

101
README.md
View file

@ -1,10 +1,10 @@
# Stear
## Introduction
A simple Framework. Its more a try to get a WindowManger and getting rid of self written HTML and CSS
A simple Framework. Combine all Content in one File in an Modular way and native JavaScript.
## Getting started
Download the stear Directory and add it to your Project.
Download the stear Submodule and add it to your Project.
## Features
### Create Stear Instance
```javascript
@ -14,45 +14,42 @@ var stear = new Stear(document.querySelector("#stear"));
### Addind Windows
```javascript
stear.addElement("connect", new SWindow(connect));
stear.addElement("start", new SWindow(start));
stear.addElement("connect", connect);
stear.addElement("start", start);
```
Windows don't necessarily have to be add this Way, but it is recommented.
Windows don't necessarily have to be add this Way.
An SWindow is an Extendion of the SFrame class. SWindow adds an DIV Element around the page content in Fullscreen.
### Calling Windows
```javascript
stear.call(stear.g("start"), {});
```
The first Argument must be an SFrame Instance. The secound Argument can be used to pass Data to the new Window.
import start from "./start.js";
An Window/Frame is could be build by extending SFrame or SWindow, but the recommanded way is to create an ES6 Module and passing it into the SWindow or SFrame class
stear.call(stear.g("start"), {});
stear.call(start, {});
```
The first Argument must be an SFrame Instance. The secound Argument can be used to pass Data to the new Window.
This Methode returns a Promise. When the Promise will be resolved, the return Value can be accessed. The Promise can be awaited.
### Creating a Window
```javascript
import { _ } from "./stear/main.js";
import { fadein, fadeout, wait } from "./stear/utils.js";
import { Stear, SWindow, _ } from "../stear/main.js";
const call = async (stear, { find, resolve, render, call, event }, args) => {
export const preRender = true;
return _({
export const render = ({}, {}) => {
}, [
return _({}, [
]);
}
export const call = async (stear, { find, resolve, render, call }, args) => {
}
export default new SWindow({ call, preRender:true, backgroundColor: "#dde" });
```
**preRender**: If actived render() will only be called once. If deactived you have to call the provided render() function in the call() function yourself.
**preRender**: This is set to true by default. When set to true the content will be rendered imidiatly. Atherwise only when called render().
**render**: A sync function returning your Page Content. (for Detail look deeper) The first Argument is not used right now. The scound one can contain Args passt in the render() function inside call().
**call**: When calling a Window this function will be called. The first Argument is the used Stear Instance. The secound Argument contains some SterungTools. The third Argument are the Arguments passt in the call request.
**call**: When calling a Window this function will be called. The first Argument is the used Stear Instance. The secound Argument contains some StearingTools. The third Argument are the Arguments passt in the call request. This function must return the page Content or function which returns the page content.
### Creating Page Content / class_ class
```javascript
@ -63,25 +60,34 @@ _({
color:"#fff",
backgroundColor:"black",
},
event: {
click: ()=>{
}
}
//other Attributes
},[
//pass here other class_ Instances
//pass here other class_ Instances or Strings or Language Sentences
//or functions that generats things like this
])
```
The function _(settings, childs) returns an class\_ Instance.
Attributes of the Settings Object while be applyed as HTML-Element Attribute.
Exeptions are find, type and style (all can be empty):
Exeptions are find, type, style, event (all can be empty):
**type**: The type Attribute determines the DOMElement Type. The Default is div.
**find**: The find Attribute is an identifier for the call() function. With find.someString you can get this Element. With find.someString._ you get the underlying DOMElement.
**find**: The find Attribute is an identifier. With find.someString you can get this Element. With find.someString._ you get the underlying DOMElement.
**style**: The content of the style Attribute will be applied as css style.
**event**: The content of the style Attribute will be applied with addEventListener.
Other Methodes:
```javascript
var element = _({},[]);
var newRenderedHTMLElement = await element.build(someArgsInArray); //Executs functions to create dynamic Structures
var newRenderedHTMLElement = element.render ;
var HTMLElement = element._ ; //Same as line befor when Element was completly rendered
element.childs = [
@ -92,6 +98,20 @@ element.settings = {
}
```
### Intelligent Content / StearingTools
- find: Contains all Elements labeled with find.
- resolve: This function resolves the call, like a regular Promise. The secound Argument determies wheser the SWindow shut be closed.
- close: This will close the SWindow.
- render: This function, will (re-)render the page content (executes every function in Content Tree (again).)
- call: The way to call an other SWindow/SFrame with an appropriate zIndex.
- event: An objects with callback functions, that can be overriden:
- onloaded: Called after initial Content render.
- onresolve: Will be awaited to execute operations on resolve or to delay it, when async.
- onclose: Will be executed on calling close(). It will delay the closing process if async.
- onBeforRerender: This will be executed befor the (re-)render while called render(). When async the render will be delayed.
- onAfterRerender: This will be executed befor the (re-)render while called render(). When async it will delay the resolve of the render() function.
### Globel functions
#### Adding Global CSS the Oldway
@ -128,6 +148,31 @@ var KeyframeName = Stear.addAnimation({
}/*,name*/);
```
#### Language
This Tool can be used in MultiLingual Projects.
Default Schema:
```javascript
const pool = Stear.addLanguagePool("poolname");
const sentences1 = pool.add("sentences1", "Some Text"); //id, default Text
const sentences2 = pool.add("sentences2", "Some {} Text with {}.");
sentences1 // Some Text
sentences2 // Some {} Text with {}.
sentences2.r("nice","a good flavour") // Some nice Text with a good flavour.
```
The Language System is a two level System. It is recomendet, to use the Name of the Window as poolname.
The LanguageString can be used like a normal String. The Methode .r() can repalace "{}" in the Text.
When useing Stear.addLanguagePool or pool.add twise the same instance will be returned.
Other Language functions
```javascript
var someJSON = Stear.getLanguageFile;//contains all Defaults created yet.
Stear.lang = "de"; //change Language
Stear.addLanguageFile(fileJSON/*like someJSON*/,lang); //Language code like.
```
### Utils
#### wait
```javascript
@ -139,9 +184,9 @@ Simpel Methode of Timedelay in an async fcuntion
await fadein(elems,ms,force);
await fadeout(elems,ms,force);
```
**elems**: contains Element to Fade in or an Array of Elements
**ms** Fade time
**force** If set to true a alredy invisible/visible Element will be refaded out/in.
- **elems**: contains Element to Fade in or an Array of Elements
- **ms** Fade time
- **force** If set to true a alredy invisible/visible Element will be refaded out/in.
### Extras
loading1.js: simple to use Loadinganimation

View file

@ -1,16 +0,0 @@
import { _ } from "./stear/main.js";
import { fadein, fadeout, wait } from "./stear/utils.js";
export const preRender = true;
export const render = ({}, {}) => {
return _({}, [
]);
}
export const call = async (stear, { find, resolve, render, call }, { }) => {
}

View file

@ -1,44 +0,0 @@
import l1 from "../stear/extra/Elements/loading1.js";
import showStatus from "../stear/extra/Pages/showStatus.js";
import { _ } from "../stear/main.js";
import { fadein, fadeout, wait } from "../stear/utils.js";
export const preRender = true;
export const render = ({},{}) =>
_({find:"main"},[
_({type:"p",find:"text",style:{
position: "absolute",
minWidth: "90%",
textAlign: "center",
top: "25%",
left: "50%",
transform: "translate(-50%,-50%)",
}}),
_({style:{
position: "absolute",
left: "50%",
top: "50%",
transform: "translate(-50%, -50%)",
}}, l1())
]);
export const call = async (stear, { find, resolve, render, call }, {name,id}) => {
find.text._.innerText = "Connecting to: " + name + " (" + id + ")";
await fadein(find.main._, 200, true);
//do connection
await wait(1000);
if (Math.random() > 0.25){
call(showStatus, { text: "Connected" });
await fadeout(find.main._);
return resolve(true);
}else{
call(showStatus, { text: "Error while Connecting to: "+name, color:"red" });
await fadeout(find.main._);
return resolve(false);
}
}

View file

@ -1,28 +0,0 @@
import { Stear, SWindow } from "../stear/main.js";
import * as connect from "./connect.js";
import * as start from "./start.js";
var stear = new Stear(document.querySelector("#stear"));
stear.style({
backgroundColor: "#dde",
fontFamily: "Helvetica Neue",
fontWeight: "lighter",
fontSize: "0.9em",
color: "#2a2a2a",
});
stear.addElement("connect", new SWindow(connect));
stear.addElement("start", new SWindow(start));
stear.call(stear.g("start"), {});
setTimeout(()=>{
document.dispatchEvent(new Event("deviceready"));
},10);
window.s = stear;

21
example/menu/apps.jsx Normal file
View file

@ -0,0 +1,21 @@
import { Stear, SWindow, _, s } from "../../stear/main.js";
const call = async (stear, { find, resolve, close, render, call, event }, args) => {
/*event.onloaded = () => { }*/
/*event.onresolve = async () => { }*/
/*event.onclose = async () => { }*/
/*event.onBeforRerender = async () => { }*/
/*event.onAfterRerender = async () => { }*/
return <div style={{
display:"flex",
alignItems: "center",
justifyContent: "center",
height: "100%",
}}>
Appscreen
</div>
}
export default new SWindow({ call, backgroundColor: "#dde" });

56
example/menu/connect.js Normal file
View file

@ -0,0 +1,56 @@
import l1 from "../../stear/extra/Elements/loading1.js";
import showStatus from "../../stear/extra/Pages/showStatus.js";
import { Stear, SWindow, _ } from "../../stear/main.js";
import { fadein, fadeout, wait } from "../../stear/utils.js";
const pool = Stear.addLanguagePool("connect");
const connectingto = pool.add("connectingto", "Connecting to: {} ({})");
const connected = pool.add("connected", "connected");
const connecterror = pool.add("connecterror", "Error while Connecting to: {}");
export const call = async (stear, { find, resolve, render, call, event }, {name,id}) => {
event.onloaded = async ()=>{
await fadein(find.main, 200, true);
//do connection
await wait(1000);
if (Math.random() > 0.25) {
call(showStatus, { text: connected });
return resolve(true);
} else {
call(showStatus, { text: connecterror.r(name), color: "red" });
return resolve(false);
}
};
event.onresolve = async ()=>{
await fadeout(find.main);
}
return _({ find: "main" }, [
_({
type: "p",
style: {
position: "absolute",
minWidth: "90%",
textAlign: "center",
top: "25%",
left: "50%",
transform: "translate(-50%,-50%)",
}
}, connectingto.r(name, id)),
_({
style: {
position: "absolute",
left: "50%",
top: "50%",
transform: "translate(-50%, -50%)",
}
}, l1())
]);
}
export default new SWindow({ preRender: true, call, backgroundColor: "#dde" });

20
example/menu/empty.js Normal file
View file

@ -0,0 +1,20 @@
import { Stear, SWindow, _ } from "../../stear/main.js";
const call = async (stear, { find, resolve, close, render, call, event }, args) => {
/*event.onloaded = () => { }*/
/*event.onresolve = async () => { }*/
/*event.onclose = async () => { }*/
/*event.onBeforRerender = async () => { }*/
/*event.onAfterRerender = async () => { }*/
/*event.onParentRender = () => { }*/
/*event.onGlobalRenderRequest = () => { return [false -> no auto rerendering]}*/
return _({
}, [
]);
}
export default new SWindow({ call, backgroundColor: "#dde" });

19
example/menu/index.js Normal file
View file

@ -0,0 +1,19 @@
import { Stear, SWindow } from "../../stear/main.js";
import start from "./start";
var stear = new Stear(document.querySelector("#stear"));
stear.style({
backgroundColor: "#dde",
fontFamily: "Helvetica Neue",
fontWeight: "lighter",
fontSize: "0.9em",
color: "#2a2a2a",
});
/*stear.addElement("connect", connect);
stear.addElement("start", start);*/
stear.call(start, {});

BIN
example/menu/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

69
example/menu/menu.jsx Normal file
View file

@ -0,0 +1,69 @@
import { Stear, SWindow, _, s } from "../../stear/main.js";
import apps from "./apps";
import settings from "./settings";
import splash from "./splash";
const call = async (stear, { find, resolve, close, render, call, include, event }, args) => {
/*event.onloaded = () => { }*/
/*event.onresolve = async () => { }*/
/*event.onclose = async () => { }*/
/*event.onBeforRerender = async () => { }*/
/*event.onAfterRerender = async () => { }*/
let menu = [
include(splash),
include(apps),
include(settings),
];
window.dddd = menu[0];
let show = 0;
return <div style={{
display: "flex",
height: "100%",
width: "100%",
flexDirection: "column",
}}>
<div style={{
position: "relative",
width: "100%",
height: "100%",
}}>{() => {
menu[show].opts.render();
return menu[show].render({
style: {
height: "100%",
width: "100%"
}
});
}}</div>
<div style={{
height: "2rem",
width: "calc(100% - 2rem)",
padding: "1rem",
backgroundColor: "#fee",
display: "flex",
flexDirection: "row",
alignItems: "center",
justifyContent: "space-evenly",
borderRadius: "2rem 2rem 0 0",
}}>
{() => menu.map((m, i) => {
return <div event={{
click: () => {
show = i;
render();
}
}} style={{
height: "1rem",
width: "1rem",
backgroundColor: show == i ? "red" : "green"
}}></div>;
})}
</div>
</div>;
}
export default new SWindow({ call, backgroundColor: "#dde"});

26
example/menu/settings.jsx Normal file
View file

@ -0,0 +1,26 @@
import prompt from "../../stear/extra/Pages/prompt.js";
import { Stear, SWindow, _, s } from "../../stear/main.js";
const call = async (stear, { find, resolve, close, render, call, event }, args) => {
/*event.onloaded = () => { }*/
/*event.onresolve = async () => { }*/
/*event.onclose = async () => { }*/
/*event.onBeforRerender = async () => { }*/
/*event.onAfterRerender = async () => { }*/
/*event.onParentRender = () => { }*/
event.onParentRender = () => call(prompt, { text: "settings" }).then(console.log);
return <div style={{
display:"flex",
alignItems: "center",
justifyContent: "center",
height: "100%",
}}>
Settings
</div>
}
export default new SWindow({ call, backgroundColor: "#dde" });

21
example/menu/splash.jsx Normal file
View file

@ -0,0 +1,21 @@
import { Stear, SWindow, _, s } from "../../stear/main.js";
const call = async (stear, { find, resolve, close, render, call, event }, args) => {
/*event.onloaded = () => { }*/
/*event.onresolve = async () => { }*/
/*event.onclose = async () => { }*/
/*event.onBeforRerender = async () => { }*/
/*event.onAfterRerender = async () => { }*/
return <div style={{
display:"flex",
alignItems: "center",
justifyContent: "center",
height: "100%",
}}>
Splashscreen
</div>
}
export default new SWindow({ call, backgroundColor: "#dde" });

42
example/menu/start.jsx Normal file
View file

@ -0,0 +1,42 @@
import { Stear, SWindow, _,s } from "../../stear/main.js";
import { fadein, fadeout, wait } from "../../stear/utils.js";
//import connect from "./connect.js";
import menu from "./menu";
export const preRender = true;
var wobel = Stear.addAnimation({
"0%": {
transform: "translate(-50%, -50%) scale(100%)"
},
"50%": {
transform: "translate(-50%, -50%) scale(110%)"
},
"100%": {
transform: "translate(-50%, -50%) scale(100%)"
}
});
export const call = (stear, { find, resolve, render, call, event }, args) => {
event.onloaded = async ()=>{
await wait(Math.max(1, 1000 - performance.now()));
await fadeout(find.main);
call(menu/*, { id: "123-456", name: "Device" }*/);
resolve();
}
return <div style={{zIndex:1000}} find="main">
<img src="logo.png" style={{
width: "75vw",
maxWidth: "75vh",
maxHeight: "75vh",
position: "absolute",
left: "50%",
top: "50%",
transform: "translate(-50%, -50%)",
animation: `${wobel} 1s ease-in-out 0s infinite`,
}}/>
</div>;
}
export default new SWindow({ preRender: true, call, backgroundColor:"#dde"});

View file

@ -1,41 +0,0 @@
import { Stear, _ } from "../stear/main.js";
import { fadein, fadeout, wait } from "../stear/utils.js";
export const preRender = true;
export const render = ({},{}) => {
var wobel = Stear.addAnimation({
"0%":{
transform: "translate(-50%, -50%) scale(100%)"
},
"50%": {
transform: "translate(-50%, -50%) scale(110%)"
},
"100%": {
transform: "translate(-50%, -50%) scale(100%)"
}
});
console.log(wobel)
return _({style:{zindex:1000},find:"main"}, [
_({type:"img",src:"http://localhost:82/images/logo.png",style:{
width: "80vw",
maxWidth: "75vh",
position: "absolute",
left: "50%",
top: "50%",
transform: "translate(-50%, -50%)",
animation: `${wobel} 2s ease-in-out 0s infinite`,
}})
]);
}
export const call = (stear, { find, resolve, render, call }, args) => {
document.addEventListener('deviceready', async ()=>{
await wait(Math.max(1, 1000 - performance.now()));
await fadeout(find.main._);
call(stear.g("connect"),{id:"123-456",name:"Device"});
resolve();
}, false);
}

2459
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

27
package.json Normal file
View file

@ -0,0 +1,27 @@
{
"name": "stear",
"version": "0.5.0",
"description": "A simple js/jsx based Framework",
"main": "index.js",
"directories": {
"example": "example"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serveMenu": "esbuild example/menu/index.js --jsx-factory=s --loader:.js=jsx --loader:.html=text --bundle --minify --servedir=example/menu #--sourcemap"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/jusax23/stear.git"
},
"author": "jusax23",
"license": "UNLICENSED",
"bugs": {
"url": "https://gitlab.com/jusax23/stear/issues"
},
"homepage": "https://gitlab.com/jusax23/stear#readme",
"devDependencies": {
"esbuild": "^0.15.12",
"jsdoc-to-markdown": "^7.1.1"
}
}

1
stear Submodule

@ -0,0 +1 @@
Subproject commit 9c2af40b36a17a99269349a5af00a31a097cfea1

View file

@ -1,55 +0,0 @@
import { class_, Stear, _ } from "../../main.js";
export class loading1 extends class_{
constructor(color){
super({ class: "box" }, [
_({ style: { backgroundColor: color}}),
_({ style: { backgroundColor: color}}),
_({ style: { backgroundColor: color}}),
]);
}
}
export const l1 = (color="black") => new loading1(color);
export default l1;
var animation = Stear.addAnimation({
"0%": { left: "4%", top: "4%" },
"8.33%": { left: "52%", top: "4%" },
"25%": { left: "52%", top: "4%" },
"33.33%": { left: "52%", top: "52%" },
"50%": { left: "52%", top: "52%" },
"58.33%": { left: "4%", top: "52%" },
"75%": { left: "4%", top: "52%" },
"83.33%": { left: "4%", top: "4%" },
"100%": { left: "4%", top: "4%" },
});
Stear.addGlobalStyleJSON({
display: "inline-block",
position: "relative",
width: "80px",
height: "80px",
}, ".box");
Stear.addGlobalStyleJSON({
position: "absolute",
height: "44%",
width: "44%",
borderRadius: "25%",
animation: `${animation} 6s linear infinite`,
}, ".box div");
Stear.addGlobalStyleJSON({
animationDelay: "0s"
}, ".box div:nth-child(1)");
Stear.addGlobalStyleJSON({
animationDelay: "-2s"
}, ".box div:nth-child(2)");
Stear.addGlobalStyleJSON({
animationDelay: "-4s"
}, ".box div:nth-child(3)");

View file

@ -1,53 +0,0 @@
import { SFrame, _ } from "../../main.js";
import { fadein, fadeout } from "../../utils.js";
const preRender = false;
const render = ({ }, {titel,text,callback}) => {
return _({
find:"main",
class:"stear_alert",
style: {
position:"fixed",
left: "0",
top: "0",
height:"100%",
width:"100%",
backgroundColor:"rgba(0,0,0,0.5)"
}
}, _({
style:{
left: "50%",
top: "50%",
transform: "translate(-50%, -50%)",
padding: "1rem",
paddingTop: "0",
position: "absolute",
backgroundColor: "#eee",
minHeight: "4rem",
minWidth: "8rem",
borderRadius: "1rem",
textAlign: "center"
}
}, [
_({ type: "h2", style: { marginBottom: 0 }}, titel),
_({ type: "p"}, text),
_({ type: "button", find:"btn", event: {click: callback}, style:{
borderRadius:"0.5rem",
}},"OK"),
]));
}
const call = async (stear, { find, resolve, render, call }, {text,titel=""}) => {
render({titel,text,callback:()=>{
resolve();
fadeout(find.main._);
}});
await fadein (find.main._, 200, true);
find.btn._.focus();
}
export default new SFrame({
preRender, render, call
});

View file

@ -1,87 +0,0 @@
import { SFrame, Stear, _ } from "../../main.js";
import { fadein, fadeout, wait } from "../../utils.js";
const preRender = true;
Stear.addGlobalStyleJSON({
position: "fixed",
left: "50%",
bottom: "1rem",
transform: "translate(-50%, -50%)",
textAlign: "center",
border: `2px soild transparent`,
borderRadius: "1rem",
padding: "1rem",
transition: "background-color 200ms",
backgroundColor: "#212121",
color:"#fafafa",
webkitUserSelect: "none",
},".stear_status");
const render = ({ }, { }) => {
return _({
find:"main",
class:"stear_status",
});
}
const statusList = [];
var statusActive = false;
const call = async (stear, { find, resolve, render, call }, { text, color="grey" }) => {
statusList.push({ text, color, resolve});
if (statusActive) return;
statusActive = true;
var next = statusList.shift();
var last;
find.main.settings = {style:{
border: "2px solid " + next.color
}};
find.main._.innerText = next.text;
await fadein(find.main._, 200, true);
find.main._.style.transition = "";
async function loop(){
last = next;
next = statusList.shift();
if (next == null) return finish();
last.resolve(null, false);
find.main.settings = { style: { backgroundColor: "#555" } };
await wait(200);
find.main.settings = {
style: {
backgroundColor: "",
border: "2px solid " + next.color
}
};
find.main._.innerText = next.text;
timeoutId = setTimeout(loop,3000);
}
var timeoutId = setTimeout(loop, 3000);
find.main._.onclick = ()=>{
if(timeoutId<0)return;
clearTimeout(timeoutId);
timeoutId = -1;
loop();
};
async function finish(){
if (timeoutId >= 0)clearTimeout(timeoutId);
timeoutId = -1;
statusActive = false;
await fadeout(find.main._);
last.resolve();
}
}
export default new SFrame({
preRender, render, call
});

View file

@ -1,227 +0,0 @@
var counter = 0;
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("");
}
export class Stear{
elem;
#childs = {};
constructor(elem){
this.elem = elem;
elem.style.position="relative";
}
style(css){
Object.entries(css).forEach(([k, d]) => {
this.elem.style[k] = d;
});
}
addElement (id,elem){
if(!(elem instanceof SFrame))throw new TypeError("Cannot add Element not extending from SFrame");
this.#childs[id] = elem;
}
getElement (id) {
return this.g(id);
}
g(id){
return this.#childs[id];
}
async call (elem, args, layer = 1){
return await elem.call(this, args, layer);
}
static addGlobalStyleText(text){
globalStyle.innerHTML+="\n"+text;
}
static addAnimation(steps, name = "stearAnimation_" + counter++){
Stear.addGlobalStyleText(`@keyframes ${name} {
${
Object.entries(steps).map(([k,d])=>
` ${k} {
${Object.entries(d).map(d => " " + toCssAttr(d[0]) + ": " + d[1] + ";").join("\n")}
}`).join("\n")
}
}`);
return name;
}
static addGlobalStyleJSON(json, name = ".stearClass_" + counter++){
Stear.addGlobalStyleText(`
${name} {
${Object.entries(json).map(d => " " + toCssAttr(d[0]) + ": " + d[1] + ";").join("\n")}
}
`)
return name;
}
}
export class SFrame{
#preRender;
#render;
#call;
#lastRender;
constructor({ preRender, render, call }){
this.#preRender = preRender;
this.#render = render;
this.#call = call;
if(this.#preRender){
this.render();
}
}
render(args={}){
this.#lastRender = this.#render({}, args);
this.#lastRender.render;
return this.#lastRender;
}
async call(stear, args, layer = 1){
if(this.#preRender){
stear.elem.appendChild(this.#lastRender._);
this.#lastRender._.style.zIndex = layer;
}
var find = (this.#lastRender?.find) ?? {};
return new Promise((res,rej)=>{
this.#call(stear,{
find,
render: (args) => {
this.render(args);
for (var member in find) delete find[member];
Object.assign(find, (this.#lastRender?.find) ?? {});
if ([...(stear.elem.children)].indexOf(this.#lastRender._) >= 0) stear.elem.removeChild(this.#lastRender._);
stear.elem.appendChild(this.#lastRender._);
this.#lastRender._.style.zIndex = layer;
return find;
},
resolve: (r,close=true)=>{
if (close&&[...(stear.elem.children)].indexOf(this.#lastRender._) >= 0) stear.elem.removeChild(this.#lastRender._);
res(r);
},
call: (elem, args)=>{
return stear.call(elem,args,layer+1);
}
}, args);
});
}
}
export class SWindow extends SFrame{
#Frame;
constructor({ preRender, render, call, backgroundColor = "transparent"}){
var Frame = _({
style: {
top: "0px",
left: "0px",
position: "absolute",
height: "100%",
width: "100%",
display: "block",
backgroundColor,
overflow:"scroll"
},
find:"main"
}, []);
super({
preRender, render: (settings, args) => {
Frame.childs = [render(settings, args)];
return Frame;
}, call
});
this.#Frame = Frame;
}
}
export class class_ {
#elem;
#childs;
#find;
constructor(settings,childs){
this.#elem = document.createElement(settings.type ?? "div");
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])=>{
this.#elem.style[k] = d;
});
} else if (key == "find"){
this.#find = settings[key];
} else if (key == "event"){
Object.entries(settings[key]).forEach(([k, d]) => {
this.#elem.addEventListener(k,d);
});
} else {
this.#elem.setAttribute(key,settings[key]);
}
}
}
set childs(childs){
this.#childs = Array.isArray(childs) ? childs : [childs];
}
set settings(settings){
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]);
}
}
}
get render (){
this.#elem.innerHTML = "";
for (let i = 0; i < this.#childs.length; i++) {
const elem = this.#childs[i];
if(typeof elem == "string"){
this.#elem.appendChild(document.createTextNode(elem));
}else{
this.#elem.appendChild(elem.render);
}
}
return this.#elem;
}
get _ (){
return this.#elem;
}
get find (){
var out = {};
this.#childs.forEach(d=>{
Object.assign(out,d.find);
});
if (this.#find) out[this.#find]=this;
return out;
}
}
export const _ = (settings = {}, childs = []) => new class_(settings, Array.isArray(childs) ? childs : [childs]);

View file

@ -1,61 +0,0 @@
export const wait = (ms) => {
return new Promise((res, rej) => {
setTimeout(res, ms);
});
}
export const fadeout = async (elems, ms = 200, force = false) => {
if (!Array.isArray(elems)) elems = [elems];
for (let i = 0; i < elems.length; i++) {
elems[i].style.transition = `opacity ${ms}ms`;
if(force){
elems[i].style.opacity = "1";
elems[i].style.display = "";
}
}
await wait(10);
for (let i = 0; i < elems.length; i++) {
elems[i].style.opacity = "0";
}
await wait(ms);
for (let i = 0; i < elems.length; i++) {
elems[i].style.display = "none";
}
}
export const fadein = async (elems, ms = 200, force = false) => {
if (!Array.isArray(elems)) elems = [elems];
for (let i = 0; i < elems.length; i++) {
elems[i].style.transition = `opacity ${ms}ms`;
elems[i].style.display = "";
if (force) {
elems[i].style.opacity = "0";
}
}
await wait(10);
for (let i = 0; i < elems.length; i++) {
elems[i].style.opacity = "1";
}
await wait(ms);
}
var bStack = [];
export const subCancel = (callback) => {
bStack.push(callback);
return ()=>{
var id;
if ((id = bStack.indexOf(callback)) >= 0) {
bStack.splice(id, 1);
}
}
}
function back() {
if (bStack.length) {
bStack.pop()();
}
}
document.addEventListener("backbutton", back, false);
document.addEventListener('keyup', (e)=>{
if (e.code == "Escape")back();
});