1
0
Fork 0
digital-art-composition-book/.obsidian/plugins/litegallery/main.js
2024-09-14 11:25:13 -04:00

215 lines
8 KiB
JavaScript

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// main.ts
var main_exports = {};
__export(main_exports, {
default: () => LiteGallery
});
module.exports = __toCommonJS(main_exports);
var import_obsidian2 = require("obsidian");
// settingtab.ts
var import_obsidian = require("obsidian");
var LiteGallerySettingTab = class extends import_obsidian.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
this.plugin = plugin;
}
display() {
let { containerEl } = this;
containerEl.empty();
new import_obsidian.Setting(containerEl).setName("Image folders").setDesc("Comma separated list of folders to search for images (in order of priority).").addText(
(text) => text.setPlaceholder("/").setValue(this.plugin.settings.image_folders.join(",")).onChange(async (value) => {
this.plugin.settings.image_folders = value.split(",");
await this.plugin.save_settings();
})
);
}
};
// main.ts
var DEFAULT_SETTINGS = {
image_folders: []
};
var LiteGallery = class extends import_obsidian2.Plugin {
async load_settings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async save_settings() {
await this.saveData(this.settings);
}
async onload() {
await this.load_settings();
this.addSettingTab(new LiteGallerySettingTab(this.app, this));
this.registerMarkdownCodeBlockProcessor("litegal", async (source, el, ctx) => {
let active_slide = 0;
let preview_scroll_speed = 0;
const image_list = source.split("\n").map((line) => line.replace(/!?\[\[/, "").replace("]]", "").trim()).filter((line) => line).map(
(image) => {
let image_exists = false;
let image_path = void 0;
let path_options = this.settings.image_folders.map((folder) => {
return `${folder.slice(-1) == "/" ? folder == "/" ? "" : folder : (
// If folder doesn't need a trailing slash, don't add it (if it's root dir should just be empty string)
`${folder}/`
)}${image}`;
});
for (const test_path of path_options) {
const file = this.app.vault.getAbstractFileByPath(test_path);
if (file instanceof import_obsidian2.TFile) {
image_exists = true;
image_path = this.app.vault.adapter.getResourcePath(test_path);
break;
}
}
if (image_path == void 0) {
new import_obsidian2.Notice(`LiteGallery: Image not found: ${image}`);
}
return image_path;
}
).filter((image_path) => image_path !== void 0);
const lightbox_container = document.body.createEl("div", {
cls: "litegal-lightbox-container hidden"
});
lightbox_container.onclick = () => {
lightbox_container.addClass("hidden");
};
const lightbox = lightbox_container.createEl("div");
lightbox.classList.add("litegal-lightbox");
lightbox.onclick = (event) => {
event.stopPropagation();
};
const gallery = el.createEl("div", { cls: "litegal" });
gallery.classList.add("litegal");
if (image_list.length > 0) {
const active_image_container = gallery.createEl("div", {
cls: "litegal-active"
});
const active_image_container_inner = active_image_container.createEl("div", {
cls: "litegal-active-inner"
});
const active_image = active_image_container_inner.createEl("img");
active_image.src = image_list[active_slide];
active_image.onclick = () => {
lightbox_container.removeClass("hidden");
lightbox_image.src = image_list[active_slide];
};
const larrow = active_image_container.createEl("div", {
text: "<",
cls: "litegal-arrow litegal-arrow-left"
});
larrow.onclick = () => {
active_slide = (active_slide - 1 + image_list.length) % image_list.length;
active_image.src = image_list[active_slide];
};
const rarrow = active_image_container.createEl("div", {
text: ">",
cls: "litegal-arrow litegal-arrow-right"
});
rarrow.onclick = () => {
active_slide = (active_slide + 1) % image_list.length;
active_image.src = image_list[active_slide];
};
const preview_outer_container = gallery.createEl("div", { cls: "litegal-preview-outer" });
const preview_larrow = preview_outer_container.createEl("div", {
text: "<",
cls: "litegal-arrow litegal-arrow-left"
});
preview_larrow.onmouseenter = () => {
preview_scroll_speed = -5;
};
preview_larrow.onmouseleave = () => {
preview_scroll_speed = 0;
};
const preview_rarrow = preview_outer_container.createEl("div", {
text: ">",
cls: "litegal-arrow litegal-arrow-right"
});
preview_rarrow.onmouseenter = () => {
preview_scroll_speed = 5;
};
preview_rarrow.onmouseleave = () => {
preview_scroll_speed = 0;
};
const preview_container = preview_outer_container.createEl("div", {
cls: "litegal-preview"
});
setInterval(() => {
preview_container.scrollLeft += preview_scroll_speed;
}, 10);
image_list.forEach(async (image_path, i) => {
const preview_elem = preview_container.createEl("img", {
cls: "litegal-preview-img"
});
preview_elem.src = image_path;
preview_elem.onclick = () => {
active_slide = i;
active_image.src = `${image_list[active_slide]}`;
};
});
const lightbox_larrow = lightbox.createEl("div", {
text: "<",
cls: "litegal-arrow litegal-arrow-left"
});
lightbox_larrow.onclick = () => {
active_slide = (active_slide - 1 + image_list.length) % image_list.length;
lightbox_image.src = image_list[active_slide];
active_image.src = image_list[active_slide];
};
const lightbox_rarrow = lightbox.createEl("div", {
text: ">",
cls: "litegal-arrow litegal-arrow-right"
});
lightbox_rarrow.onclick = () => {
active_slide = (active_slide + 1) % image_list.length;
lightbox_image.src = image_list[active_slide];
active_image.src = image_list[active_slide];
};
const lightbox_image = lightbox.createEl("img", {
cls: "litegal-lightbox-image"
});
const lightbox_exit = lightbox.createEl("div", {
text: "X",
cls: "litegal-lightbox-exit"
});
lightbox_exit.onclick = () => {
lightbox_container.addClass("hidden");
};
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
lightbox_container.addClass("hidden");
}
});
} else {
gallery.createEl("p", {
text: 'No images found, please check your image list. If your images are not found, please check your "image folders" in settings.',
cls: "litegal-no-images"
});
}
});
}
onunload() {
}
};