1.3.18 fixed link hover and textElement rotate

This commit is contained in:
Zsolt Viczian
2021-10-10 20:18:17 +02:00
parent 1917dad8cd
commit 7ebdec7713
6 changed files with 10185 additions and 10136 deletions

View File

@@ -1,7 +1,7 @@
{
"id": "obsidian-excalidraw-plugin",
"name": "Excalidraw",
"version": "1.3.17",
"version": "1.3.18",
"minAppVersion": "0.12.0",
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
"author": "Zsolt Viczian",

View File

@@ -11,7 +11,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@zsviczian/excalidraw": "0.9.0-obsidian-11",
"@zsviczian/excalidraw": "0.9.0-obsidian-12",
"monkey-around": "^2.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
@@ -37,4 +37,4 @@
"tslib": "^2.3.1",
"typescript": "^4.4.3"
}
}
}

View File

@@ -34,7 +34,7 @@ import ExcalidrawPlugin from './main';
import {estimateBounds, ExcalidrawAutomate, repositionElementsToCursor} from './ExcalidrawAutomate';
import { t } from "./lang/helpers";
import { ExcalidrawData, REG_LINKINDEX_HYPERLINK, REGEX_LINK } from "./ExcalidrawData";
import { checkAndCreateFolder, download, getNewOrAdjacentLeaf, getNewUniqueFilepath, splitFolderAndFilename, viewportCoordsToSceneCoords } from "./Utils";
import { checkAndCreateFolder, download, getNewOrAdjacentLeaf, getNewUniqueFilepath, rotatedDimensions, splitFolderAndFilename, viewportCoordsToSceneCoords } from "./Utils";
import { Prompt } from "./Prompt";
import { ClipboardData } from "@zsviczian/excalidraw/types/clipboard";
@@ -707,12 +707,28 @@ export default class ExcalidrawView extends TextFileView {
const getTextElementAtPointer = (pointer:any) => {
const elements = this.excalidrawRef.current.getSceneElements()
.filter((e:ExcalidrawElement)=>{
return e.type == "text"
&& e.x<=pointer.x && (e.x+e.width)>=pointer.x
&& e.y<=pointer.y && (e.y+e.height)>=pointer.y;
if (e.type !== "text") return false;
const [x,y,w,h] = rotatedDimensions(e);
return x<=pointer.x && x+w>=pointer.x
&& y<=pointer.y && y+h>=pointer.y;
});
if(elements.length==0) return null;
return {id:elements[0].id,text:elements[0].text};
if(elements.length===1) return {id:elements[0].id,text:elements[0].text};
//if more than 1 text elements are at the location, look for one that has a link
const elementsWithLinks = elements.filter((e:ExcalidrawTextElement)=> {
const text:string = (this.textMode == TextMode.parsed)
? this.excalidrawData.getRawText(e.id)
: e.text;
if(!text) return false;
if(text.match(REG_LINKINDEX_HYPERLINK)) return true;
const parts = text.matchAll(REGEX_LINK.EXPR).next();
if(!parts.value) return false;
return true;
});
//if there are no text elements with links, return the first element without a link
if(elementsWithLinks.length==0) return {id:elements[0].id,text:elements[0].text};
//if there are still multiple text elements with links on top of each other, return the first
return {id:elementsWithLinks[0].id,text:elementsWithLinks[0].text};
}
let hoverPoint = {x:0,y:0};

View File

@@ -2,6 +2,7 @@ import { normalizePath, TAbstractFile, TFolder, Vault, WorkspaceLeaf } from "ob
import { Random } from "roughjs/bin/math";
import { Zoom } from "@zsviczian/excalidraw/types/types";
import ExcalidrawPlugin from "./main";
import { ExcalidrawElement } from "@zsviczian/excalidraw/types/element/types";
declare module "obsidian" {
interface Workspace {
@@ -109,6 +110,38 @@ export function wrapText(text:string, lineLen:number, forceWrap:boolean=false):s
return outstring.replace(/\n$/, '');
}
const rotate = (
pointX: number,
pointY: number,
centerX: number,
centerY: number,
angle: number,
): [number, number] =>
// 𝑎𝑥=(𝑎𝑥𝑐𝑥)cos𝜃(𝑎𝑦𝑐𝑦)sin𝜃+𝑐𝑥
// 𝑎𝑦=(𝑎𝑥𝑐𝑥)sin𝜃+(𝑎𝑦𝑐𝑦)cos𝜃+𝑐𝑦.
// https://math.stackexchange.com/questions/2204520/how-do-i-rotate-a-line-segment-in-a-specific-point-on-the-line
[
(pointX - centerX) * Math.cos(angle) - (pointY - centerY) * Math.sin(angle) + centerX,
(pointX - centerX) * Math.sin(angle) + (pointY - centerY) * Math.cos(angle) + centerY,
];
export const rotatedDimensions = (
element: ExcalidrawElement
): [number, number, number, number] => {
if(element.angle===0) [element.x,element.y,element.width,element.height];
const centerX = element.x+element.width/2;
const centerY = element.y+element.height/2;
const [left,top] = rotate(element.x,element.y,centerX,centerY,element.angle);
const [right,bottom] = rotate(element.x+element.width,element.y+element.height,centerX,centerY,element.angle);
return [
left<right ? left : right,
top<bottom ? top : bottom,
Math.abs(left-right),
Math.abs(top-bottom)
];
}
export const viewportCoordsToSceneCoords = (
{ clientX, clientY }: { clientX: number; clientY: number },
{

View File

@@ -1,3 +1,3 @@
{
"1.3.17": "0.11.13"
"1.3.18": "0.11.13"
}

20254
yarn.lock

File diff suppressed because it is too large Load Diff