Add miniPaint as new frontend base

This commit is contained in:
motion
2026-01-26 12:20:16 -05:00
parent bb859105ff
commit 6ae4cbcb77
306 changed files with 60729 additions and 4050 deletions
+82
View File
@@ -0,0 +1,82 @@
import config from "../../config";
import Base_layers_class from './../../core/base-layers.js';
import File_save_class from './../file/save.js';
import Helper_class from './../../libs/helpers.js';
import alertify from './../../../../node_modules/alertifyjs/build/alertify.min.js';
var instance = null;
class Copy_class {
constructor() {
//singleton
if (instance) {
return instance;
}
instance = this;
this.Base_layers = new Base_layers_class();
this.Helper = new Helper_class();
this.File_save = new File_save_class();
//events
document.addEventListener('keydown', (event) => {
var code = event.key.toLowerCase();
var ctrlDown = event.ctrlKey || event.metaKey;
if (this.Helper.is_input(event.target))
return;
if (code == "c" && ctrlDown == true) {
//copy to clipboard
this.copy_to_clipboard();
}
}, false);
}
async copy_to_clipboard(){
var _this = this;
const canWriteToClipboard = await this.askWritePermission();
if (canWriteToClipboard) {
//get data - current layer
var canvas = this.Base_layers.convert_layer_to_canvas();
var ctx = canvas.getContext("2d");
if (config.TRANSPARENCY == false) {
//add white background
ctx.globalCompositeOperation = 'destination-over';
this.File_save.fillCanvasBackground(ctx, '#ffffff');
ctx.globalCompositeOperation = 'source-over';
}
//save using lib
canvas.toBlob(function (blob) {
_this.setToClipboard(blob);
});
}
else{
alertify.error('Missing permissions to write to Clipboard.cc');
}
}
async setToClipboard(blob) {
const data = [new ClipboardItem({ [blob.type]: blob })];
await navigator.clipboard.write(data);
}
async askWritePermission() {
try {
// The clipboard-write permission is granted automatically to pages
// when they are the active tab. So it's not required, but it's more safe.
const { state } = await navigator.permissions.query({ name: 'clipboard-write' })
return state === 'granted';
}
catch (error) {
// Browser compatibility / Security error (ONLY HTTPS) ...
return false;
}
}
}
export default Copy_class;
+10
View File
@@ -0,0 +1,10 @@
import alertify from './../../../../node_modules/alertifyjs/build/alertify.min.js';
class Edit_paste_class {
paste() {
alertify.error('Use Ctrl+V keyboard shortcut to paste from Clipboard.');
}
}
export default Edit_paste_class;
+14
View File
@@ -0,0 +1,14 @@
import Base_state_class from './../../core/base-state.js';
class Edit_redo_class {
constructor() {
this.Base_state = new Base_state_class();
}
redo() {
this.Base_state.redo();
}
}
export default Edit_redo_class;
+26
View File
@@ -0,0 +1,26 @@
import config from './../../config.js';
import Base_layers_class from './../../core/base-layers.js';
import Selection_class from './../../tools/selection.js';
import alertify from './../../../../node_modules/alertifyjs/build/alertify.min.js';
class Edit_selection_class {
constructor() {
this.Base_layers = new Base_layers_class();
this.Selection = new Selection_class(this.Base_layers.ctx);
}
select_all() {
if (config.layer.type != 'image') {
alertify.error('This layer must contain an image. Please convert it to raster to apply this tool.');
return;
}
this.Selection.select_all();
}
delete() {
this.Selection.delete_selection();
}
}
export default Edit_selection_class;
+31
View File
@@ -0,0 +1,31 @@
import Base_state_class from './../../core/base-state.js';
var instance = null;
class Edit_undo_class {
constructor() {
//singleton
if (instance) {
return instance;
}
instance = this;
this.Base_state = new Base_state_class();
this.events();
}
events(){
var _this = this;
document.querySelector('#undo_button').addEventListener('click', function (event) {
_this.Base_state.undo();
});
}
undo() {
this.Base_state.undo();
}
}
export default Edit_undo_class;