Initial commit
This commit is contained in:
31
src/util/Loader.js
Executable file
31
src/util/Loader.js
Executable file
@@ -0,0 +1,31 @@
|
||||
// $loader alternative that can be bind to other scopes
|
||||
|
||||
class Loader {
|
||||
constructor(document = window.document) {
|
||||
this.document = document
|
||||
}
|
||||
|
||||
createElement(tag, resource, rel) {
|
||||
const executor = (resolve, reject) => {
|
||||
const { document } = this,
|
||||
element = document.createElement(tag)
|
||||
|
||||
element[tag === 'script' ? 'src' : 'href'] = resource
|
||||
element.rel = rel
|
||||
element.onload = () => resolve(element)
|
||||
document.head.appendChild(element)
|
||||
}
|
||||
|
||||
return new Promise(executor)
|
||||
}
|
||||
|
||||
script(src) {
|
||||
return this.createElement('script', src)
|
||||
}
|
||||
|
||||
css(href) {
|
||||
return this.createElement('link', href, 'stylesheet')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Loader
|
||||
58
src/util/_handleIframe_preprocessor.js
Normal file
58
src/util/_handleIframe_preprocessor.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const Loader = require('./Loader')
|
||||
|
||||
const wrapProcessor = (preprocessor, path, handle) => async data => {
|
||||
let ext = $fs.utils.getExt(path),
|
||||
processed = await preprocessor(data, path).catch(console.error),
|
||||
blob = new Blob([ processed ], { type: le._get.ext.mime[ext] })
|
||||
|
||||
handle( URL.createObjectURL(blob) )
|
||||
}
|
||||
|
||||
const handleIframe = async (iframe, path = '/') => {
|
||||
const convert = (tag, from, to, preprocessor) => {
|
||||
let elements = iframe.contentDocument.querySelectorAll(tag)
|
||||
|
||||
for(let element of elements) {
|
||||
let original = element.getAttribute(from)
|
||||
|
||||
if(!original)
|
||||
continue
|
||||
|
||||
let handle = url => {
|
||||
element[to] = url
|
||||
}
|
||||
|
||||
$bundle.for(path).open(original, preprocessor ? 'String' : 'URL')
|
||||
.then(preprocessor ? wrapProcessor(preprocessor, path, handle) : handle)
|
||||
}
|
||||
}
|
||||
|
||||
convert('script', 'lsrc', 'src')
|
||||
convert('img', 'lsrc', 'src')
|
||||
convert('link', 'lhref', 'href', async (stylesheet, path) => {
|
||||
let matches = stylesheet.matchAll(/url\(("(.+?)"|'(.+?)'|(.+?))\)/g),
|
||||
fromIndex = 0,
|
||||
out = []
|
||||
|
||||
console.log(matches)
|
||||
|
||||
for(let match of matches) {
|
||||
let bundle = $bundle.for( $fs.utils.getFolderPath(path) )
|
||||
|
||||
console.log(bundle.access(match[2]))
|
||||
|
||||
out.concat([
|
||||
stylesheet.slice(fromIndex, match.index),
|
||||
'url("' + await bundle.open(match[2], 'URL') + '")'
|
||||
])
|
||||
|
||||
fromIndex = match.index + match[0].length
|
||||
}
|
||||
|
||||
console.log(out, fromIndex)
|
||||
|
||||
return out.join('')
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = handleIframe
|
||||
71
src/util/constants.json
Executable file
71
src/util/constants.json
Executable file
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"app": {
|
||||
"id": "xash",
|
||||
"categories": "Game",
|
||||
"version": "0.0.0b"
|
||||
},
|
||||
"emf": {
|
||||
"id": "emf",
|
||||
"ext": ".emf",
|
||||
"categories": "Utility"
|
||||
},
|
||||
"paths": {
|
||||
"modPath": "/a/.config/xash/mods/",
|
||||
"saves": "/a/.config/xash/saves/"
|
||||
},
|
||||
"manifestScheme": {
|
||||
"definitions": {},
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$id": "https://example.com/object1619767958.json",
|
||||
"title": "Root",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"name",
|
||||
"entry"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"$id": "#root/name",
|
||||
"title": "Name",
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"Half-life Deathmatch"
|
||||
],
|
||||
"pattern": "^.*$"
|
||||
},
|
||||
"description": {
|
||||
"$id": "#root/description",
|
||||
"title": "Description",
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"hurrr durr big p"
|
||||
],
|
||||
"pattern": "^.*$"
|
||||
},
|
||||
"entry": {
|
||||
"$id": "#root/entry",
|
||||
"title": "Entry",
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"./hldm.js"
|
||||
],
|
||||
"pattern": "^.*$"
|
||||
},
|
||||
"compressed": {
|
||||
"$id": "#root/compressed",
|
||||
"title": "Compressed",
|
||||
"type": "boolean",
|
||||
"examples": [
|
||||
true
|
||||
],
|
||||
"default": true
|
||||
},
|
||||
"readme": {
|
||||
"$id": "#root/readme",
|
||||
"title": "Readme",
|
||||
"type": "string",
|
||||
"pattern": "^.*$"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/util/gzip.js
Executable file
8
src/util/gzip.js
Executable file
@@ -0,0 +1,8 @@
|
||||
// Require will import EVERYTHING no matter what I do,
|
||||
// so I'm making a fool of myself with this stupid
|
||||
// util script. Should've listened to robbie and
|
||||
// gotten used to ES6 syntax but noooo I had to be
|
||||
// a special snowflake with my stupid CJS garbage.
|
||||
import { gzip } from "fflate"
|
||||
|
||||
export { gzip }
|
||||
24
src/util/handleIframe.js
Executable file
24
src/util/handleIframe.js
Executable file
@@ -0,0 +1,24 @@
|
||||
const Loader = require('./Loader')
|
||||
|
||||
const handleIframe = async (iframe, path = '/') => {
|
||||
const convert = (tag, from, to) => {
|
||||
let elements = iframe.contentDocument.querySelectorAll(tag)
|
||||
|
||||
for(let element of elements) {
|
||||
let original = element.getAttribute(from)
|
||||
|
||||
if(!original)
|
||||
continue
|
||||
|
||||
$bundle.for(path).open(original, 'URL').then(url => {
|
||||
element[to] = url
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
convert('script', 'lsrc', 'src')
|
||||
convert('img', 'lsrc', 'src')
|
||||
convert('link', 'lhref', 'href')
|
||||
}
|
||||
|
||||
module.exports = handleIframe
|
||||
17
src/util/promisify.js
Executable file
17
src/util/promisify.js
Executable file
@@ -0,0 +1,17 @@
|
||||
const promisify = original => {
|
||||
const async = (...args) => {
|
||||
const executor = (resolve, reject) => {
|
||||
try {
|
||||
original(...args, resolve)
|
||||
} catch(error) {
|
||||
reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise(executor)
|
||||
}
|
||||
|
||||
return async
|
||||
}
|
||||
|
||||
module.exports = promisify
|
||||
Reference in New Issue
Block a user