diff --git a/README.md b/README.md index e5a1af5..b8e395a 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ +AsaJS Logo made by [Kammasy](https://www.youtube.com/channel/UCrmjDWdM8-ZSeekzLeCnftg) a.k.a **[E.G.G](https://www.youtube.com/channel/UCrmjDWdM8-ZSeekzLeCnftg)** + ![image](/resources/logo.png) diff --git a/src/compilers/Memory.ts b/src/compilers/Memory.ts index 5e8579f..ff2731e 100644 --- a/src/compilers/Memory.ts +++ b/src/compilers/Memory.ts @@ -1,6 +1,6 @@ import { AnimationKeyframe } from "../components/AnimationKeyframe.js" import { Class } from "../components/Class.js" -import { UI } from "../components/UI.js" +import { ModifyUI, UI } from "../components/UI.js" import { AnimType } from "../types/enums/AnimType.js" import { Renderer } from "../types/enums/Renderer.js" import { Type } from "../types/enums/Type.js" @@ -13,6 +13,8 @@ interface FileInterface { } type Files = Map +export const MemoryModify: Record> = {} + export class Memory extends Class { protected static files: Files = new Map() diff --git a/src/compilers/Random.ts b/src/compilers/Random.ts new file mode 100644 index 0000000..390dfdb --- /dev/null +++ b/src/compilers/Random.ts @@ -0,0 +1,7 @@ +import { RandomString } from "../components/Utils.js" + +const namespaces = Array.from({ length: 15 }, () => RandomString(16)) + +export function RandomNamespace() { + return namespaces[Math.floor(Math.random() * namespaces.length)] +} diff --git a/src/compilers/bindings/Funtion.ts b/src/compilers/bindings/Funtion.ts index 964c23f..854288b 100644 --- a/src/compilers/bindings/Funtion.ts +++ b/src/compilers/bindings/Funtion.ts @@ -55,3 +55,9 @@ FuntionMap.set("sqrt", number => { value: rtn, } }) + +FuntionMap.set("translatable", key => { + return { + value: `'%' + ${key}`, + } +}) diff --git a/src/compilers/ui/builder.ts b/src/compilers/ui/builder.ts index aba16de..47c9830 100644 --- a/src/compilers/ui/builder.ts +++ b/src/compilers/ui/builder.ts @@ -1,8 +1,38 @@ import { isBuildMode } from "../Configuration.js" import { Memory } from "../Memory.js" +import { createBuildFolder } from "./linker.js" +import fs from "fs/promises" + +async function buildUI() { + const build = Memory.build() + let i = 0 + + build.set("ui/ui_defs.json", { + ui_defs: Array.from(build.keys()), + }) + + await Promise.all( + build.entries().map(async ([file, value]) => { + const outFile = `build/build/${file}` + await fs + .stat(outFile.split(/\\|\//g).slice(0, -1).join("/")) + .catch(async () => await fs.mkdir(outFile.split(/\\|\//g).slice(0, -1).join("/"), { recursive: true })) + + await fs.writeFile(outFile, JSON.stringify(value), "utf-8") + i++ + }), + ) + + return i - 1 +} if (isBuildMode) { - process.on("beforeExit", () => { - console.log(JSON.stringify(Memory.build(), null, 2)) + let first = true + process.on("beforeExit", async () => { + if (first) { + await createBuildFolder() + await buildUI() + } + first = false }) } diff --git a/src/compilers/ui/linker.ts b/src/compilers/ui/linker.ts index e69de29..e4fd71b 100644 --- a/src/compilers/ui/linker.ts +++ b/src/compilers/ui/linker.ts @@ -0,0 +1,12 @@ +import fs from "fs/promises" + +export async function clearBuild() { + await fs.rm("build/build", { recursive: true, force: true }) +} + +export async function createBuildFolder() { + return fs + .stat("build") + .catch(() => fs.mkdir("build")) + .then(() => clearBuild()) +} diff --git a/src/components/AnimationKeyframe.ts b/src/components/AnimationKeyframe.ts index 79ec74e..5613a8e 100644 --- a/src/components/AnimationKeyframe.ts +++ b/src/components/AnimationKeyframe.ts @@ -5,6 +5,7 @@ import { KeyframeAnimationProperties } from "../types/properties/element/Animati import { Animation } from "./Animation.js" import { Class } from "./Class.js" import { RandomString } from "./Utils.js" +import { RandomNamespace } from "../compilers/Random.js" import util from "node:util" @@ -35,7 +36,7 @@ export class AnimationKeyframe extends Class { } this.name = name || RandomString(16) - this.namespace = namespace || RandomString(16) + this.namespace = namespace || RandomNamespace() this.path = path || `@/${this.namespace}` Memory.add(this) diff --git a/src/components/UI.ts b/src/components/UI.ts index b7aa9e3..6d70e70 100644 --- a/src/components/UI.ts +++ b/src/components/UI.ts @@ -11,6 +11,7 @@ import { Animation } from "./Animation.js" import { AnimationKeyframe } from "./AnimationKeyframe.js" import { Class } from "./Class.js" import { ExtendsOf, RandomString, ResolveBinding } from "./Utils.js" +import { RandomNamespace } from "../compilers/Random.js" import util from "node:util" @@ -50,7 +51,7 @@ export class UI extends Class } this.name = name?.match(/^(\w|\/)+/)?.[0] || RandomString(16) - this.namespace = namespace || RandomString(16) + this.namespace = namespace || RandomNamespace() if (!path) this.path = `@/${this.namespace}` else this.path = path diff --git a/src/components/Utils.ts b/src/components/Utils.ts index ecd46f3..bf98c40 100644 --- a/src/components/Utils.ts +++ b/src/components/Utils.ts @@ -37,8 +37,8 @@ import { AnimationKeyframe } from "./AnimationKeyframe.js" import { AnimationProperties, KeyframeAnimationProperties } from "../types/properties/element/Animation.js" import { Animation } from "./Animation.js" import { SmartAnimation } from "../types/enums/SmartAnimation.js" +import { Memory, MemoryModify } from "../compilers/Memory.js" -const CHARS = "0123456789abcdefghijklmnopqrstuvwxyz" type CompileBinding = `[${string}]` export function Color(hex: string | number): Array3 { @@ -90,7 +90,7 @@ export function ResolveBinding(...bindings: BindingItem[]) { } export function RandomString(length: number, base: number = 32) { - const chars = CHARS.slice(0, base) + const chars = "0123456789abcdefghijklmnopqrstuvwxyz".slice(0, base) const out = new Array(length) try { @@ -140,8 +140,21 @@ export function b(input: string): CompileBinding { // Quick Elements export function Modify>(namespace: T, name: K) { - // @ts-ignore -- TS cannot prove this, but runtime guarantees it - return new ModifyUI, VanillaElementChilds>(namespace, name, paths[namespace][name]) + // @ts-ignore + const memoryUI = MemoryModify[paths[namespace][name]]?.[name] + // @ts-ignore + if (memoryUI) return memoryUI as ModifyUI, VanillaElementChilds> + // @ts-ignore + const modifyUI = new ModifyUI, VanillaElementChilds>( + namespace, + name, + // @ts-ignore + paths[namespace][name], + ) + // @ts-ignore + ;(MemoryModify[paths[namespace][name]] ||= {})[name] = modifyUI + + return modifyUI } export function Panel(properties?: Panel, namespace?: string, name?: string) {