From efc4c49a7fcacbd86badab425f45567561cb20de Mon Sep 17 00:00:00 2001 From: octospacc Date: Mon, 24 Apr 2023 15:03:51 +0200 Subject: [PATCH] Build with assets; Misc app work --- App/Elems.js | 17 ++++++++++++++--- App/Main.js | 37 +++++++++++++++++++++++++++++++++---- Build.py | 25 +++++++++++++++++++++---- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/App/Elems.js b/App/Elems.js index afe9a2b..d7d62d3 100644 --- a/App/Elems.js +++ b/App/Elems.js @@ -1,11 +1,22 @@ -function MakeWindow(Attrs) { - var Window = document.createElement('div'); +function HtmlEl(Tag, Attrs) { + var El = document.createElement(Tag); if (Attrs) { Object.keys(Attrs).forEach(function(Attr){ - Window[Attr] = Attrs[Attr]; + El[Attr] = Attrs[Attr]; }); }; + return El; +}; + +function MakeWindow(Attrs) { + var Window = HtmlEl('div', Attrs); Window.className += ' Window'; Root.appendChild(Window); return Window; }; + +function Dropdown(Attrs) { + var Menu = HtmlEl('div', Attrs); + Window.className += ' Dropdown'; + return Menu; +}; diff --git a/App/Main.js b/App/Main.js index fa06c64..017c575 100644 --- a/App/Main.js +++ b/App/Main.js @@ -3,6 +3,16 @@ var Present = CopyObj(Persist); var Tasker = {}; var ApiCache = {Urls: {},}; +Assets._ = function _(Name) { + if (Name in Assets) { + if (Assets[Name].startsWith('data:')) { + return Assets[Name]; + } else { + return `./Assets/${Assets[Name]}`; + }; + }; +}; + function DoAsync(First, Then, Data) { var Job = RndId(); Tasker[Job] = { @@ -149,10 +159,29 @@ function PostNote(Text) { function ManageSettings() { MakeWindow().innerHTML = ` - * Sources - * Identities - * Data Import/Export - * Cache Persistance +

Settings

+

Misc

+

+ Language: ${Dropdown()} +

+

+ Theme: +

+

+ +

+

Identities

+ ... +

Sources

+ ... +

Data

+

+ + +

+

+ +

`; }; diff --git a/Build.py b/Build.py index c35b975..04af32a 100755 --- a/Build.py +++ b/Build.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 import os +from base64 import b64encode +from mimetypes import guess_type from pathlib import Path os.chdir(os.path.dirname(os.path.abspath(__file__))) @@ -17,11 +19,26 @@ def FragReplace(Find, Replace, Pattern='*.*'): with open(File, 'r') as Frag: Frag = Replace.format(File=File, Frag=Frag.read()) for Prefix in ('', './'): - File = Prefix + File - Base = Base.replace(Find.format(File=File), Frag) + Name = Prefix + File + Base = Base.replace(Find.format(File=Name), Frag) -#BaseNew = [] -#BaseNew += Base.split('' +Frags = Frags[1].split(Split) +for File in Path('./Assets').rglob('*.*'): + File = str(File) + Mime = guess_type(File) + Mime = (Mime[0] if Mime else 'application/octet-stream') + with open(File, 'rb') as Frag: + Frag = b64encode(Frag.read()).decode() + for Prefix in ('', './'): + Name = Prefix + '/'.join(File.split('/')[1:]) + Frags[0] = Frags[0].replace(f'"{Name}"', f'"data:{Mime};base64,{Frag}"') +BaseNew += Split.join(Frags) +Base = BaseNew FragReplace('', '', '*.css') FragReplace('', '', '*.js')