137 lines
4.3 KiB
JavaScript
137 lines
4.3 KiB
JavaScript
import Find from './Find/Find.js';
|
|
|
|
const ROOT_OBJECT = 'root';
|
|
|
|
const STANDARD = 0;
|
|
const NO_MODULE = 1;
|
|
|
|
class App extends Find.createApp() {
|
|
constructor(name) {
|
|
const root = Find.search(name);
|
|
super(root);
|
|
}
|
|
|
|
init() {
|
|
this.select('com.find.minify');
|
|
this.setMeta();
|
|
this.setTitle();
|
|
this.setForms();
|
|
this.render();
|
|
this.attachEvents();
|
|
}
|
|
|
|
setMeta() {
|
|
this.meta([
|
|
Find.css('bulma.min.css'),
|
|
Find.content('<meta name="viewport" content="width=device-width, initial-scale=1">'),
|
|
Find.content(
|
|
`<style>
|
|
body {
|
|
margin: 20px;
|
|
}
|
|
</style>`
|
|
)
|
|
]);
|
|
}
|
|
|
|
setTitle() {
|
|
this.title('Минификатор Find.js на Find.js');
|
|
}
|
|
|
|
setForms() {
|
|
this.add([
|
|
Find.content(
|
|
`<div class="card">
|
|
<div class="card-header">
|
|
<p class="card-header-title">
|
|
<span id="title">Минификация Find.js</span>
|
|
<span id="hand_error" class="has-text-danger"></span>
|
|
</p>
|
|
</div>
|
|
<div class="card-content">
|
|
<div class="content">
|
|
<span class="has-text-weight-bold">
|
|
Минифицируйте Find.js прямо сейчас!
|
|
</span>
|
|
<button
|
|
class="button"
|
|
id="minify"
|
|
style="width: 100%; margin-top: 10px; margin-bottom: 10px;"
|
|
>Минифицировать</button>
|
|
<span class="has-text-weight-bold">
|
|
Или же скачайте no-module версию:
|
|
</span>
|
|
<button
|
|
class="button"
|
|
id="no-module"
|
|
style="width: 100%; margin-top: 10px;"
|
|
>Скачать</button>
|
|
</div>
|
|
</div>
|
|
</div>`
|
|
)
|
|
]);
|
|
}
|
|
|
|
mwait(t, x) {
|
|
const root = this.component();
|
|
const title = root.id('title');
|
|
if (t === true) {
|
|
title.text('Минификация Find.js в процессе...');
|
|
} else {
|
|
if (typeof t === "string") {
|
|
title.text(t);
|
|
if (arguments.length > 1) {
|
|
root.id("hand_error").text(x);
|
|
}
|
|
} else {
|
|
title.text('Минификация Find.js');
|
|
}
|
|
}
|
|
}
|
|
|
|
attachEvents() {
|
|
const root = this.component();
|
|
root.id('minify').attach('click', () => {
|
|
this.mwait(true);
|
|
this.minifyFind(STANDARD);
|
|
});
|
|
root.id('no-module').attach('click', () => {
|
|
this.mwait(true);
|
|
this.minifyFind(NO_MODULE);
|
|
});
|
|
}
|
|
|
|
async minifyFind(mode) {
|
|
try {
|
|
let response = await fetch('Find/Find.js');
|
|
if (response.ok) {
|
|
let code = await response.text();
|
|
let name = 'find.min.js';
|
|
if (mode == NO_MODULE) {
|
|
code = code.replace('export default class Find', 'class Find');
|
|
name = 'nomodule-' + name;
|
|
}
|
|
let minif = await Terser.minify(code, { sourceMap: false });
|
|
this.uploadFile(name, 'application/javascript', minif.code);
|
|
this.mwait(false);
|
|
} else {
|
|
this.mwait('Ошибка HTTP', response.status);
|
|
}
|
|
} catch (err) {
|
|
this.mwait('Ошибка: ', err);
|
|
}
|
|
}
|
|
|
|
uploadFile(filename, mime, content) {
|
|
const blob = new Blob([content], { type: mime });
|
|
const link = document.createElement('a');
|
|
link.href = URL.createObjectURL(blob);
|
|
link.download = filename;
|
|
link.click();
|
|
URL.revokeObjectURL(link.href);
|
|
}
|
|
}
|
|
|
|
const app = new App(ROOT_OBJECT);
|
|
app.init(); |