You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

265 lines
26 KiB

2 years ago
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module2) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// main.ts
__export(exports, {
2 years ago
default: () => main_default
2 years ago
});
2 years ago
// src/App.ts
var import_obsidian3 = __toModule(require("obsidian"));
// src/Modal.ts
2 years ago
var import_obsidian = __toModule(require("obsidian"));
var CameraModal = class extends import_obsidian.Modal {
2 years ago
constructor(app2, cameraSettings) {
2 years ago
super(app2);
2 years ago
this.videoStream = null;
2 years ago
this.chosenFolderPath = cameraSettings.chosenFolderPath;
2 years ago
}
onOpen() {
return __async(this, null, function* () {
const { contentEl } = this;
const webCamContainer = contentEl.createDiv();
2 years ago
const statusMsg = webCamContainer.createEl("span", { text: "Loading.." });
2 years ago
const videoEl = webCamContainer.createEl("video");
2 years ago
const buttonsDiv = webCamContainer.createDiv();
const firstRow = buttonsDiv.createDiv();
const secondRow = buttonsDiv.createDiv();
const recordVideoButton = firstRow.createEl("button", {
2 years ago
text: "Start recording"
});
2 years ago
const switchCameraButton = firstRow.createEl("button", {
2 years ago
text: "Switch Camera"
});
2 years ago
const snapPhotoButton = firstRow.createEl("button", {
2 years ago
text: "Take a snap"
});
2 years ago
firstRow.style.display = "none";
secondRow.style.display = "none";
const filePicker = secondRow.createEl("input", {
2 years ago
placeholder: "Choose image file from system",
type: "file"
});
filePicker.accept = "image/*,video/*";
filePicker.capture = "camera";
2 years ago
const filePicker2 = secondRow.createEl("input", {
2 years ago
placeholder: "Choose image file from system",
type: "file"
});
filePicker2.accept = "image/*";
filePicker2.capture = "camera";
2 years ago
videoEl.autoplay = true;
videoEl.muted = true;
2 years ago
const chunks = [];
let recorder = null;
2 years ago
this.videoStream = null;
2 years ago
const cameras = (yield navigator.mediaDevices.enumerateDevices()).filter((d) => d.kind === "videoinput");
if (cameras.length <= 1)
switchCameraButton.style.display = "none";
let cameraIndex = 0;
const getVideoStream = () => __async(this, null, function* () {
try {
return yield navigator.mediaDevices.getUserMedia({
video: { deviceId: cameras[cameraIndex].deviceId },
audio: true
});
} catch (error) {
console.log(error);
return null;
}
});
2 years ago
this.videoStream = yield getVideoStream();
if (this.videoStream) {
firstRow.style.display = "block";
secondRow.style.display = "block";
statusMsg.style.display = "none";
} else {
secondRow.style.display = "block";
statusMsg.textContent = "Error in loading videostream in your device..";
2 years ago
}
const handleImageSelectChange = (file) => __async(this, null, function* () {
const chosenFile = file;
const bufferFile = yield chosenFile.arrayBuffer();
saveFile(bufferFile, false, chosenFile.name.split(" ").join("-"));
});
filePicker.onchange = () => handleImageSelectChange(filePicker.files[0]);
filePicker2.onchange = () => handleImageSelectChange(filePicker2.files[0]);
const view = this.app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
const saveFile = (file, isImage = false, fileName = "") => __async(this, null, function* () {
if (!fileName) {
const dateString = (new Date() + "").slice(4, 28).split(" ").join("_").split(":").join("-");
fileName = isImage ? `image_${dateString}.png` : `video_${dateString}.webm`;
}
if (!isImage)
new import_obsidian.Notice("Adding video to vault...");
2 years ago
const filePath = this.chosenFolderPath + "/" + fileName;
const folderExists = app.vault.getAbstractFileByPath(this.chosenFolderPath);
2 years ago
if (!folderExists)
2 years ago
yield app.vault.createFolder(this.chosenFolderPath);
2 years ago
const fileExists = app.vault.getAbstractFileByPath(filePath);
if (!fileExists)
yield app.vault.createBinary(filePath, file);
if (!view)
return new import_obsidian.Notice(`Saved to ${filePath}`);
const cursor = view.editor.getCursor();
view.editor.replaceRange(isImage ? `![${fileName}](${filePath})
` : `
![[${filePath}]]
`, cursor);
this.close();
});
switchCameraButton.onclick = () => __async(this, null, function* () {
cameraIndex = (cameraIndex + 1) % cameras.length;
2 years ago
this.videoStream = yield getVideoStream();
2 years ago
});
snapPhotoButton.onclick = () => {
const canvas = webCamContainer.createEl("canvas");
canvas.style.display = "none";
const { videoHeight, videoWidth } = videoEl;
canvas.height = videoHeight;
canvas.width = videoWidth;
canvas.getContext("2d").drawImage(videoEl, 0, 0, videoWidth, videoHeight);
canvas.toBlob((blob) => __async(this, null, function* () {
const bufferFile = yield blob.arrayBuffer();
saveFile(bufferFile, true);
}), "image/png");
};
2 years ago
videoEl.srcObject = this.videoStream;
2 years ago
recordVideoButton.onclick = () => __async(this, null, function* () {
switchCameraButton.disabled = true;
let isRecording = recorder && recorder.state === "recording";
if (isRecording)
recorder.stop();
isRecording = !isRecording;
recordVideoButton.innerText = isRecording ? "Stop Recording" : "Start Recording";
if (!recorder) {
2 years ago
recorder = new MediaRecorder(this.videoStream, {
2 years ago
mimeType: "video/webm"
});
}
recorder.ondataavailable = (e) => chunks.push(e.data);
2 years ago
recorder.onstop = (_) => __async(this, null, function* () {
2 years ago
const blob = new Blob(chunks, {
type: "audio/ogg; codecs=opus"
});
const bufferFile = yield blob.arrayBuffer();
saveFile(bufferFile, false);
});
recorder.start();
});
});
}
onClose() {
2 years ago
var _a;
2 years ago
const { contentEl } = this;
2 years ago
(_a = this.videoStream) == null ? void 0 : _a.getTracks().forEach((track) => {
track.stop();
});
2 years ago
contentEl.empty();
}
};
2 years ago
var Modal_default = CameraModal;
// src/SettingsTab.ts
var import_obsidian2 = __toModule(require("obsidian"));
var DEFAULT_SETTINGS = {
chosenFolderPath: "attachments/snaps"
};
var CameraSettingsTab = class extends import_obsidian2.PluginSettingTab {
constructor(app2, plugin) {
super(app2, plugin);
this.plugin = plugin;
}
display() {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl("h2", { text: "Obsidian-Camera settings" });
new import_obsidian2.Setting(containerEl).setName("Folder Path").setDesc("Folder where the videos and snaps should be saved").addText((text) => text.setPlaceholder("Enter your secret").setValue(this.plugin.settings.chosenFolderPath).onChange((value) => __async(this, null, function* () {
console.log("Chosen Folder Path: " + value);
this.plugin.settings.chosenFolderPath = value;
yield this.plugin.saveSettings();
})));
}
};
// src/App.ts
var ObsidianCamera = class extends import_obsidian3.Plugin {
onload() {
return __async(this, null, function* () {
yield this.loadSettings();
this.addRibbonIcon("camera", "Obsidian Camera", (evt) => {
new Modal_default(this.app, this.settings).open();
});
this.addSettingTab(new CameraSettingsTab(this.app, this));
this.addCommand({
id: "Open camera modal",
name: "Open camera modal / File Picker",
callback: () => {
new Modal_default(this.app, this.settings).open();
}
});
});
}
loadSettings() {
return __async(this, null, function* () {
this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData());
});
}
saveSettings() {
return __async(this, null, function* () {
yield this.saveData(this.settings);
});
}
};
// main.ts
var main_default = ObsidianCamera;
2 years ago
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6I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