mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2026-11-27 06:32:42 +00:00
2.15.1-beta-1, 0.18.0-35
This commit is contained in:
1 parent
1ee277c814
commit
425d8304d5
5 files changed
+79
-4
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "2.15.0",
|
||||
"version": "2.15.beta-1",
|
||||
"minAppVersion": "1.5.7",
|
||||
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
@@ -1201,4 +1201,9 @@ export default {
|
||||
COMP_FRAME: "Frame Actions",
|
||||
COMP_FRAME_HINT: "Toggle Marker Frame. Guide-only frames to define slides/print areas/image references. " +
|
||||
"Hidden in image exports; doesn't contain elements. Hide/show frames via canvas context menu.",
|
||||
|
||||
//CustomEmbeddable.tsx
|
||||
NOTICE_PDF_THEME: "PDF theme overridden.\n" +
|
||||
"Control via this file's 'excalidraw-embeddable-theme' document property (overrides plugin).\n\n" +
|
||||
"Values: dark, light, auto=Excalidraw, default=Obsidian.",
|
||||
};
|
||||
@@ -1,12 +1,12 @@
|
||||
|
||||
import { MAX_IMAGE_SIZE, IMAGE_TYPES, ANIMATED_IMAGE_TYPES, MD_EX_SECTIONS } from "src/constants/constants";
|
||||
import { MAX_IMAGE_SIZE, IMAGE_TYPES, ANIMATED_IMAGE_TYPES, MD_EX_SECTIONS, AUDIO_TYPES } from "src/constants/constants";
|
||||
import { App, Modal, Notice, TFile } from "obsidian";
|
||||
import { ExcalidrawAutomate } from "src/shared/ExcalidrawAutomate";
|
||||
import { REGEX_LINK, REG_LINKINDEX_HYPERLINK, getExcalidrawMarkdownHeaderSection, REGEX_TAGS, getExcalidrawMarkdownHeader } from "../shared/ExcalidrawData";
|
||||
import ExcalidrawView from "src/view/ExcalidrawView";
|
||||
import { ExcalidrawElement, ExcalidrawFrameElement, ExcalidrawImageElement } from "@zsviczian/excalidraw/types/element/src/types";
|
||||
import { getEmbeddedFilenameParts, getLinkParts, isImagePartRef } from "./utils";
|
||||
import { cleanSectionHeading } from "./obsidianUtils";
|
||||
import { cleanSectionHeading, getAudioElementHeight } from "./obsidianUtils";
|
||||
import { getEA } from "src/core";
|
||||
import { AppState, ExcalidrawImperativeAPI } from "@zsviczian/excalidraw/types/excalidraw/types";
|
||||
import { EmbeddableMDCustomProps } from "src/shared/Dialogs/EmbeddableSettings";
|
||||
@@ -66,11 +66,17 @@ export async function insertEmbeddableToView (
|
||||
if(file && (IMAGE_TYPES.contains(file.extension) || ea.isExcalidrawFile(file)) && !ANIMATED_IMAGE_TYPES.contains(file.extension)) {
|
||||
return await insertImageToView(ea, position, link??file, undefined, shouldInsertToView);
|
||||
} else {
|
||||
let height = MAX_IMAGE_SIZE;
|
||||
if (file && AUDIO_TYPES.contains(file.extension.toLowerCase())) {
|
||||
ea.style.strokeColor = "transparent";
|
||||
ea.style.backgroundColor = "transparent";
|
||||
height = getAudioElementHeight();
|
||||
}
|
||||
const id = ea.addEmbeddable(
|
||||
position.x,
|
||||
position.y,
|
||||
MAX_IMAGE_SIZE,
|
||||
MAX_IMAGE_SIZE,
|
||||
height,
|
||||
link,
|
||||
file,
|
||||
);
|
||||
|
||||
@@ -455,4 +455,53 @@ export function isUnwantedLeaf(leaf:WorkspaceLeaf):boolean {
|
||||
leaf.view?.getViewType() === "empty" && leaf.parent && !leaf.parent.parent &&
|
||||
//@ts-ignore
|
||||
leaf.parent.type === "split" && leaf.parent.children.length === 1
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the height of an audio element in Obsidian's CSS environment
|
||||
* @returns The height of the audio element in pixels
|
||||
*/
|
||||
export function getAudioElementHeight(): number {
|
||||
// Create a temporary audio element with controls
|
||||
const audioElement = document.createElement("audio");
|
||||
audioElement.controls = true;
|
||||
audioElement.src = "data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA"; // Minimal valid audio
|
||||
|
||||
// Create a wrapper to avoid affecting page layout
|
||||
const wrapper = document.createElement("div");
|
||||
wrapper.style.position = "absolute";
|
||||
wrapper.style.left = "-9999px";
|
||||
wrapper.style.visibility = "hidden";
|
||||
wrapper.style.pointerEvents = "none";
|
||||
wrapper.appendChild(audioElement);
|
||||
|
||||
// Add to document to allow CSS to be applied
|
||||
document.body.appendChild(wrapper);
|
||||
|
||||
// Get height
|
||||
let height = 0;
|
||||
try {
|
||||
// Force layout calculation
|
||||
document.body.offsetHeight;
|
||||
|
||||
// Get height from bounding rect
|
||||
const rect = audioElement.getBoundingClientRect();
|
||||
height = rect.height;
|
||||
|
||||
// Fallback to computed style if bounding rect returns 0
|
||||
if (height === 0) {
|
||||
const computedStyle = window.getComputedStyle(audioElement);
|
||||
height = parseFloat(computedStyle.height) || 0;
|
||||
|
||||
// If still 0, try measuring the wrapper
|
||||
if (height === 0) {
|
||||
height = wrapper.getBoundingClientRect().height;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
// Clean up
|
||||
document.body.removeChild(wrapper);
|
||||
}
|
||||
|
||||
return Math.round(height);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { ExcalidrawImperativeAPI, UIAppState } from "@zsviczian/excalidraw/types
|
||||
import { ObsidianCanvasNode } from "src/view/managers/CanvasNodeFactory";
|
||||
import { processLinkText, patchMobileView, setFileToLocalGraph } from "src/utils/customEmbeddableUtils";
|
||||
import { EmbeddableMDCustomProps } from "src/shared/Dialogs/EmbeddableSettings";
|
||||
import { t } from "src/lang/helpers";
|
||||
|
||||
const CANVAS_VIEWTYPES = new Set(["markdown", "bases", "audio", "video"]);
|
||||
|
||||
@@ -21,6 +22,17 @@ declare module "obsidian" {
|
||||
}
|
||||
}
|
||||
|
||||
let noticeTimer: number;
|
||||
function showNoticeOnce(message: string) {
|
||||
if (noticeTimer) {
|
||||
return
|
||||
}
|
||||
noticeTimer = window.setTimeout(() => {
|
||||
noticeTimer = undefined;
|
||||
}, 1000);
|
||||
new Notice(message,6000);
|
||||
}
|
||||
|
||||
function getTheme (view: ExcalidrawView, theme:string): string {
|
||||
return view.excalidrawData.embeddableTheme === "dark"
|
||||
? "theme-dark"
|
||||
@@ -380,6 +392,9 @@ function RenderObsidianView(
|
||||
pdfObserverDisabledRef.current = true;
|
||||
try {
|
||||
setPDFViewTheme(view, pdfView);
|
||||
if(view.excalidrawData.embeddableTheme !== "default") {
|
||||
showNoticeOnce(t("NOTICE_PDF_THEME"));
|
||||
}
|
||||
} finally {
|
||||
requestAnimationFrame(() => { pdfObserverDisabledRef.current = false; });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user