mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2026-12-03 06:43:35 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c034b9f51 | ||
|
|
392088fed5 | ||
|
|
e97f123a83 |
No files matched your search
@@ -97,6 +97,7 @@ Follow Obsidian's **Developer Policies** and **Plugin Guidelines**. In particula
|
||||
## Mobile
|
||||
|
||||
- Don't assume desktop-only behavior unless `isDesktopOnly` is `true`.
|
||||
- Avoid using desktop only objects and functions such as Node Buffer, SharedArrayBuffer, etc. For the special case when this is required, make proper mobile safe guards.
|
||||
- Avoid large in-memory structures; be mindful of memory and storage constraints.
|
||||
|
||||
## Agent do/don't
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "2.25.1",
|
||||
"version": "2.25.2-beta.0",
|
||||
"minAppVersion": "1.8.7",
|
||||
"description": "Sketch Your Mind. Edit and view Excalidraw drawings. Enter the world of 4D Visual PKM.",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
@@ -10,4 +10,4 @@ console.log("String copied to clipboard");
|
||||
export const startupScript = () =>
|
||||
atob(
|
||||
"LyoKI2V4Y2x1ZGUKYGBganMqLwovKioKICogSWYgc2V0LCB0aGlzIGNhbGxiYWNrIGlzIHRyaWdnZXJlZCB3aGVuIHRoZSB1c2VyIGNsb3NlcyBhbiBFeGNhbGlkcmF3IHZpZXcuCiAqICAgb25WaWV3VW5sb2FkSG9vazogKHZpZXc6IEV4Y2FsaWRyYXdWaWV3KSA9PiB2b2lkID0gbnVsbDsKICovCi8vZWEub25WaWV3VW5sb2FkSG9vayA9ICh2aWV3KSA9PiB7fTsKCi8qKgogKiBJZiBzZXQsIHRoaXMgY2FsbGJhY2sgaXMgdHJpZ2dlcmVkLCB3aGVuIHRoZSB1c2VyIGNoYW5nZXMgdGhlIHZpZXcgbW9kZS4KICogWW91IGNhb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sgeDogbnVtYmVyOyB5OiBudW1iZXIgfTsgLy90aGUgcG9pbnRlciBwb3NpdGlvbiBvbiBjYW52YXMKICogICB9KSA9PiBib29sZWFuID0gbnVsbDsKICovCi8vZWEub25QYXN0ZUhvb2sgPSAoZGF0YSkgPT4ge307CgovKioKICogaWYgc2V0LCB0aGlzIGNhbGxiYWNrIGlzIHRyaWdnZXJlZCwgd2hlbiBhbiBFeGNhbGlkcmF3IGZpbGUgaXLine truncated
|
||||
);
|
||||
);
|
||||
@@ -1622,4 +1622,93 @@ Thank you & Enjoy!
|
||||
EXTRAS_GATEWAY_UPDATE_TITLE:
|
||||
"Excalidraw requires a new version of the Extras plugin",
|
||||
EXTRAS_GATEWAY_UPDATE_BTN: "Open Community Plugins",
|
||||
// PenSettingsModal.ts
|
||||
PEN_SETTINGS_TITLE: "Pen Settings",
|
||||
PEN_SETTINGS_HEADING: "Pen settings",
|
||||
PEN_SETTINGS_TYPE_NAME: "Pen type",
|
||||
PEN_SETTINGS_TYPE_DESC: "Select type of pen",
|
||||
PEN_SETTINGS_TYPE_DEFAULT: "Excalidraw Default",
|
||||
PEN_SETTINGS_TYPE_HIGHLIGHTER: "Highlighter",
|
||||
PEN_SETTINGS_TYPE_FINETIP: "Fine tip pen",
|
||||
PEN_SETTINGS_TYPE_FOUNTAIN: "Fountain pen",
|
||||
PEN_SETTINGS_TYPE_MARKER: "Marker with Outline",
|
||||
PEN_SETTINGS_TYPE_THICK_THIN: "Mindmap Thick-Thin",
|
||||
PEN_SETTINGS_TYPE_THIN_THICK_THIN: "Mindmap Thin-Thick-Thin",
|
||||
PEN_SETTINGS_APPLY: "Apply New Template",
|
||||
PEN_SETTINGS_SCOPE_FREEDRAW_ONLY:
|
||||
"Stroke & fill applies to: <b>Freedraw only</b>",
|
||||
PEN_SETTINGS_SCOPE_ALL_SHAPES: "Stroke & fill applies to: <b>All shapes</b>",
|
||||
PEN_SETTINGS_SCOPE_DESC: `<b>"All shapes"</b> means that if for example, you select a blue pen with dashed fill and then switch to a different tool (e.g. to a line, a circle, an arrow - i.e. not the freedraw tool), those will all have the same blue line and dashed fill.<br><b>"Only applies to the freedraw line"</b> means that if for example you are writing black text, and you select a custom pen (e.g. a yellow highlighter), then after using the highlighter you switch to another tool, the previous settings (e.g. black stroke color) will apply to the new shape.`,
|
||||
PEN_SETTINGS_STROKE_CURRENT: "Stroke color: <b>Current</b>",
|
||||
PEN_SETTINGS_STROKE_PRESET: "Stroke color: <b>Preset color</b>",
|
||||
PEN_SETTINGS_STROKE_DESC:
|
||||
"Use <b>current</b> stroke color of the canvas, or set a specific <b>preset color</b> for the pen",
|
||||
PEN_SETTINGS_STROKE_SELECT: "Select stroke color",
|
||||
PEN_SETTINGS_USE_CANVAS_CURRENT: "Use Canvas Current",
|
||||
PEN_SETTINGS_BG_CURRENT: "Background color: <b>Current</b>",
|
||||
PEN_SETTINGS_BG_PRESET: "Background color: <b>Preset color</b>",
|
||||
PEN_SETTINGS_BG_DESC:
|
||||
"Toggle to use the <b>current background color</b> of the canvas; or a <b>preset color</b>",
|
||||
PEN_SETTINGS_BG_TRANSPARENT: "Background: <b>Transparent</b>",
|
||||
PEN_SETTINGS_BG_COLOR_PRESET: "Color: <b>Preset color</b>",
|
||||
PEN_SETTINGS_BG_TRANSPARENT_DESC: "Background has color or is transparent",
|
||||
PEN_SETTINGS_BG_COLOR: "Background color",
|
||||
PEN_SETTINGS_FILL_STYLE: "Fill Style",
|
||||
PEN_SETTINGS_FILL_UNSET: "Unset",
|
||||
PEN_SETTINGS_FILL_DOTS: "Dots (⚠ VERY SLOW performance on large objects!)",
|
||||
PEN_SETTINGS_FILL_ZIGZAG: "Zigzag",
|
||||
PEN_SETTINGS_FILL_ZIGZAG_LINE: "Zigzag-line",
|
||||
PEN_SETTINGS_FILL_DASHED: "Dashed",
|
||||
PEN_SETTINGS_FILL_HACHURE: "Hachure",
|
||||
PEN_SETTINGS_FILL_CROSS_HATCH: "Cross-hatch",
|
||||
PEN_SETTINGS_FILL_SOLID: "Solid",
|
||||
PEN_SETTINGS_SLOPPINESS: "Sloppiness:",
|
||||
PEN_SETTINGS_NOT_SET: "Not Set",
|
||||
PEN_SETTINGS_SLOPPINESS_ARCHITECT: "Architect",
|
||||
PEN_SETTINGS_SLOPPINESS_ARTIST: "Artist",
|
||||
PEN_SETTINGS_SLOPPINESS_CARTOONIST: "Cartoonist",
|
||||
PEN_SETTINGS_SLOPPINESS_DESC: "Line sloppiness of the shape fill pattern",
|
||||
PEN_SETTINGS_STROKE_WIDTH: "Stroke Width",
|
||||
PEN_SETTINGS_STROKE_PRESET_UNSET: "---",
|
||||
PEN_SETTINGS_STROKE_PRESET_EXTRA_THIN: "Extra thin",
|
||||
PEN_SETTINGS_STROKE_PRESET_THIN: "Thin",
|
||||
PEN_SETTINGS_STROKE_PRESET_MEDIUM: "Medium",
|
||||
PEN_SETTINGS_STROKE_PRESET_BOLD: "Bold",
|
||||
PEN_SETTINGS_STROKE_PRESET_EXTRA_BOLD: "Extra bold",
|
||||
PEN_SETTINGS_HIGHLIGHTER: "Highlighter pen?",
|
||||
PEN_SETTINGS_PRESSURE: "Pressure sensitive pen?",
|
||||
PEN_SETTINGS_PRESSURE_DESC:
|
||||
"<b>toggle on</b>: pressure sensitive<br><b>toggle off</b>: constant pressure",
|
||||
PEN_SETTINGS_OUTLINE_NONE: "No outline",
|
||||
PEN_SETTINGS_OUTLINE_WIDTH: "Outline width",
|
||||
PEN_SETTINGS_OUTLINE_DESC:
|
||||
"If the stroke has an outline, this will mean the stroke color is the outline color, and the background color is the pen stroke's fill color. If the pen does not have an outline then the pen color is the stroke color. The Fill Style setting applies to the fill style of the enclosed shape, not of the line itself. The line can only have solid fill.",
|
||||
PEN_SETTINGS_PF_HEADING: "Perfect Freehand settings",
|
||||
PEN_SETTINGS_PF_DOCS: `Read the Perfect Freehand documentation following <a href="${URLs.GITHUB_COM_STEVERUIZOK_PERFECT_FREEHAND}" target="_blank">this link</a>.`,
|
||||
PEN_SETTINGS_PF_THINNING: "Thinning",
|
||||
PEN_SETTINGS_PF_THINNING_DESC: `The effect of pressure on the stroke's size.<br>To create a stroke with a steady line, set the thinning option to 0.<br>To create a stroke that gets thinner with pressure instead of thicker, use a negative number for the thinning option.`,
|
||||
PEN_SETTINGS_PF_SMOOTHING: "Smoothing",
|
||||
PEN_SETTINGS_PF_SMOOTHING_DESC: "How much to soften the stroke's edges.",
|
||||
PEN_SETTINGS_PF_STREAMLINE: "Streamline",
|
||||
PEN_SETTINGS_PF_STREAMLINE_DESC: "How much to streamline the stroke.",
|
||||
PEN_SETTINGS_EASING: "Easing function",
|
||||
PEN_SETTINGS_EASING_DESC: `An easing function for the tapering effect. For more info <a href="${URLs.EASINGS_NET}" target="_blank">click here</a>`,
|
||||
PEN_SETTINGS_SIMULATE_PRESSURE: "Simulate Pressure",
|
||||
PEN_SETTINGS_SIMULATE_PRESSURE_DESC:
|
||||
"Whether to simulate pressure based on velocity.",
|
||||
PEN_SETTINGS_SIMULATE_PRESSURE_ALWAYS: "Always",
|
||||
PEN_SETTINGS_SIMULATE_PRESSURE_NEVER: "Never",
|
||||
PEN_SETTINGS_SIMULATE_PRESSURE_MOUSE: "Yes for mouse, No for pen",
|
||||
PEN_SETTINGS_START_HEADING: "Start",
|
||||
PEN_SETTINGS_START_DESC: "Tapering options for the start of the line.",
|
||||
PEN_SETTINGS_CAP_START: "Cap Start",
|
||||
PEN_SETTINGS_CAP_DESC: "Whether to draw a cap",
|
||||
PEN_SETTINGS_TAPER: "Taper:",
|
||||
PEN_SETTINGS_TAPER_DESC:
|
||||
"The distance to taper. If set to true, the taper will be the total length of the stroke.",
|
||||
PEN_SETTINGS_END_HEADING: "End",
|
||||
PEN_SETTINGS_END_DESC: "Tapering options for the end of the line.",
|
||||
PEN_SETTINGS_CAP_END: "Cap End",
|
||||
PEN_SETTINGS_SAVE: "Save Changes",
|
||||
PEN_SETTINGS_CANCEL: "Cancel",
|
||||
};
|
||||
@@ -17,6 +17,12 @@ I build this plugin as a labor of love. Curious about the philosophy behind it?
|
||||
|
||||
<div class="ex-coffee-div"><a href="${URLs.KO_FI_COM_ZSOLT}"><img src="${URLs.CDN_KO_FI_COM_CDN_KOFI3_PNG}" border="0" alt="Buy Me a Coffee at ko-fi.com" height=45></a></div>
|
||||
`,
|
||||
"2.25.2": `
|
||||
## Fixed
|
||||
- YouTube embeddables did not render on Android devices
|
||||
- Changing custom pen settings did not save correctly. Added Save and Cancel buttons to the Pen Settings page.
|
||||
- Error generating image ID on mobile devices when uploading / pasting images to the scene
|
||||
`,
|
||||
"2.25.1": `
|
||||
This is a very minor update to fix a small regression in 2.25.0
|
||||
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
import { ExcalidrawImperativeAPI } from "@zsviczian/excalidraw/types/excalidraw/types";
|
||||
import {
|
||||
ColorComponent,
|
||||
DropdownComponent,
|
||||
Modal,
|
||||
Setting,
|
||||
SliderComponent,
|
||||
TextComponent,
|
||||
ToggleComponent,
|
||||
} from "obsidian";
|
||||
import type { StrokeWidthKey } from "@zsviczian/excalidraw/types/common/src/constants";
|
||||
import { COLOR_NAMES } from "src/constants/constants";
|
||||
import ExcalidrawView from "src/view/ExcalidrawView";
|
||||
import ExcalidrawPlugin from "src/core/main";
|
||||
import { setPen } from "src/view/components/menu/ObsidianMenu";
|
||||
import { ExtendedFillStyle, PenType } from "src/types/penTypes";
|
||||
import { ExtendedFillStyle, PenType, PenStyle } from "src/types/penTypes";
|
||||
import { getExcalidrawViews } from "src/utils/obsidianUtils";
|
||||
import { PENS } from "src/utils/pens";
|
||||
import { fragWithHTML } from "src/utils/utils";
|
||||
import { setSanitizedHtml } from "src/utils/htmlUtils";
|
||||
import { showColorPicker } from "./ColorPicker";
|
||||
import { URLs } from "src/constants/safeUrls";
|
||||
import { hideElement, showElement } from "src/utils/styleUtils";
|
||||
import { t } from "src/lang/helpers";
|
||||
|
||||
const EASINGFUNCTIONS: Record<string, string> = {
|
||||
linear: "linear",
|
||||
@@ -53,9 +56,28 @@ const EASINGFUNCTIONS: Record<string, string> = {
|
||||
easeInOutBounce: "easeInOutBounce",
|
||||
};
|
||||
|
||||
const FREEDRAW_STROKE_WIDTH_PRESETS: Readonly<Record<StrokeWidthKey, number>> =
|
||||
{
|
||||
extraThin: 0.25,
|
||||
thin: 0.5,
|
||||
medium: 1,
|
||||
bold: 2,
|
||||
extraBold: 4,
|
||||
};
|
||||
|
||||
const getStrokeWidthPresetKey = (strokeWidth: number): StrokeWidthKey | "" => {
|
||||
const normalizedStrokeWidth = Math.round(strokeWidth * 100) / 100;
|
||||
const matchedPreset = (
|
||||
Object.entries(FREEDRAW_STROKE_WIDTH_PRESETS) as [StrokeWidthKey, number][]
|
||||
).find(([, value]) => value === normalizedStrokeWidth);
|
||||
return matchedPreset?.[0] ?? "";
|
||||
};
|
||||
|
||||
export class PenSettingsModal extends Modal {
|
||||
private api: ExcalidrawImperativeAPI;
|
||||
private dirty: boolean = false;
|
||||
private shouldSave: boolean = false;
|
||||
private isDirty: boolean = false;
|
||||
private tempPenSettings: PenStyle;
|
||||
|
||||
constructor(
|
||||
private plugin: ExcalidrawPlugin,
|
||||
@@ -64,20 +86,28 @@ export class PenSettingsModal extends Modal {
|
||||
) {
|
||||
super(plugin.app);
|
||||
this.api = view.excalidrawAPI;
|
||||
// Clone the settings so changes aren't applied unless saved
|
||||
this.tempPenSettings = JSON.parse(
|
||||
JSON.stringify(this.plugin.settings.customPens[this.pen]),
|
||||
) as PenStyle;
|
||||
}
|
||||
|
||||
onOpen(): void {
|
||||
this.containerEl.classList.add("excalidraw-release");
|
||||
this.titleEl.setText(`Pen Settings`);
|
||||
this.titleEl.setText(t("PEN_SETTINGS_TITLE"));
|
||||
void this.createForm();
|
||||
}
|
||||
|
||||
onClose() {
|
||||
if (this.dirty) {
|
||||
if (this.shouldSave && this.isDirty) {
|
||||
// Overwrite actual settings with temp settings
|
||||
this.plugin.settings.customPens[this.pen] = this.tempPenSettings;
|
||||
void this.plugin.saveSettings();
|
||||
|
||||
getExcalidrawViews(this.app, true).forEach((excalidrawView) =>
|
||||
excalidrawView.updatePinnedCustomPens(),
|
||||
);
|
||||
|
||||
const pen = this.plugin.settings.customPens[this.pen];
|
||||
const api = this.view.excalidrawAPI;
|
||||
setPen(pen, api);
|
||||
@@ -85,6 +115,27 @@ export class PenSettingsModal extends Modal {
|
||||
}
|
||||
}
|
||||
|
||||
private addActionButtons(container: HTMLElement) {
|
||||
const actionContainer = container.createDiv(
|
||||
"excalidraw-pen-settings-floating-actions",
|
||||
);
|
||||
new Setting(actionContainer)
|
||||
.addButton((bt) =>
|
||||
bt
|
||||
.setButtonText(t("PEN_SETTINGS_SAVE"))
|
||||
.setCta()
|
||||
.onClick(() => {
|
||||
this.shouldSave = true;
|
||||
this.close();
|
||||
}),
|
||||
)
|
||||
.addButton((bt) =>
|
||||
bt.setButtonText(t("PEN_SETTINGS_CANCEL")).onClick(() => {
|
||||
this.close();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async createForm() {
|
||||
const hexColor = (color: string): [string, string] => {
|
||||
let opacity = "";
|
||||
@@ -119,39 +170,39 @@ export class PenSettingsModal extends Modal {
|
||||
return [null, opacity];
|
||||
};
|
||||
|
||||
const ps = this.plugin.settings.customPens[this.pen];
|
||||
const ps = this.tempPenSettings;
|
||||
const ce = this.contentEl;
|
||||
ce.empty();
|
||||
|
||||
ce.createEl("h1", { text: "Pen settings" });
|
||||
ce.createEl("h1", { text: t("PEN_SETTINGS_HEADING") });
|
||||
|
||||
new Setting(ce)
|
||||
.setName("Pen type")
|
||||
.setDesc("Select type of pen")
|
||||
.setName(t("PEN_SETTINGS_TYPE_NAME"))
|
||||
.setDesc(t("PEN_SETTINGS_TYPE_DESC"))
|
||||
.addDropdown((dropdown) => {
|
||||
dropdown
|
||||
.addOption("default", "Excalidraw Default")
|
||||
.addOption("highlighter", "Highlighter")
|
||||
.addOption("finetip", "Fine tip pen")
|
||||
.addOption("fountain", "Fountain pen")
|
||||
.addOption("marker", "Marker with Outline")
|
||||
.addOption("thick-thin", "Mindmap Thick-Thin")
|
||||
.addOption("thin-thick-thin", "Mindmap Thin-Thick-Thin")
|
||||
.addOption("default", t("PEN_SETTINGS_TYPE_DEFAULT"))
|
||||
.addOption("highlighter", t("PEN_SETTINGS_TYPE_HIGHLIGHTER"))
|
||||
.addOption("finetip", t("PEN_SETTINGS_TYPE_FINETIP"))
|
||||
.addOption("fountain", t("PEN_SETTINGS_TYPE_FOUNTAIN"))
|
||||
.addOption("marker", t("PEN_SETTINGS_TYPE_MARKER"))
|
||||
.addOption("thick-thin", t("PEN_SETTINGS_TYPE_THICK_THIN"))
|
||||
.addOption("thin-thick-thin", t("PEN_SETTINGS_TYPE_THIN_THICK_THIN"))
|
||||
.setValue(ps.type)
|
||||
.onChange((value: PenType) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.type = value;
|
||||
});
|
||||
})
|
||||
.addButton((button) =>
|
||||
button.setButtonText("Apply").onClick(() => {
|
||||
this.dirty = true;
|
||||
button.setButtonText(t("PEN_SETTINGS_APPLY")).onClick(() => {
|
||||
this.isDirty = true;
|
||||
ps.strokeColor = PENS[ps.type].strokeColor;
|
||||
ps.backgroundColor = PENS[ps.type].backgroundColor;
|
||||
ps.fillStyle = PENS[ps.type].fillStyle;
|
||||
ps.strokeWidth = PENS[ps.type].strokeWidth;
|
||||
ps.roughness = PENS[ps.type].roughness;
|
||||
ps.penOptions = { ...PENS[ps.type].penOptions };
|
||||
ce.empty();
|
||||
void this.createForm();
|
||||
}),
|
||||
);
|
||||
@@ -160,23 +211,19 @@ export class PenSettingsModal extends Modal {
|
||||
.setName(
|
||||
fragWithHTML(
|
||||
ps.freedrawOnly
|
||||
? "Stroke & fill applies to: <b>Freedraw only</b>"
|
||||
: "Stroke & fill applies to: <b>All shapes</b>",
|
||||
),
|
||||
)
|
||||
.setDesc(
|
||||
fragWithHTML(
|
||||
`<b>"All shapes"</b> means that if for example, you select a blue pen with dashed fill and then switch to a different tool (e.g. to a line, a circle, an arrow - i.e. not the freedraw tool), those will all have the same blue line and dashed fill.<br><b>"Only applies to the freedraw line"</b> means that if for example you are writing black text, and you select a custom pen (e.g. a yellow highlighter), then after using the highlighter you switch to another tool, the previous settings (e.g. black stroke color) will apply to the new shape.`,
|
||||
? t("PEN_SETTINGS_SCOPE_FREEDRAW_ONLY")
|
||||
: t("PEN_SETTINGS_SCOPE_ALL_SHAPES"),
|
||||
),
|
||||
)
|
||||
.setDesc(fragWithHTML(t("PEN_SETTINGS_SCOPE_DESC")))
|
||||
.addToggle((toggle) =>
|
||||
toggle.setValue(ps.freedrawOnly).onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
scopeSetting.setName(
|
||||
fragWithHTML(
|
||||
value
|
||||
? "Stroke & fill applies to: <b>Freedraw only</b>"
|
||||
: "Stroke & fill applies to: <b>All shapes</b>",
|
||||
? t("PEN_SETTINGS_SCOPE_FREEDRAW_ONLY")
|
||||
: t("PEN_SETTINGS_SCOPE_ALL_SHAPES"),
|
||||
),
|
||||
);
|
||||
ps.freedrawOnly = value;
|
||||
@@ -193,19 +240,15 @@ export class PenSettingsModal extends Modal {
|
||||
.setName(
|
||||
fragWithHTML(
|
||||
!ps.strokeColor
|
||||
? "Stroke color: <b>Current</b>"
|
||||
: "Stroke color: <b>Preset color</b>",
|
||||
),
|
||||
)
|
||||
.setDesc(
|
||||
fragWithHTML(
|
||||
"Use <b>current</b> stroke color of the canvas, or set a specific <b>preset color</b> for the pen",
|
||||
? t("PEN_SETTINGS_STROKE_CURRENT")
|
||||
: t("PEN_SETTINGS_STROKE_PRESET"),
|
||||
),
|
||||
)
|
||||
.setDesc(fragWithHTML(t("PEN_SETTINGS_STROKE_DESC")))
|
||||
.addToggle((toggle) => {
|
||||
strokeUseCurrentToggle = toggle;
|
||||
toggle.setValue(!ps.strokeColor).onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
if (value) {
|
||||
hideElement(scSetting.settingEl);
|
||||
} else {
|
||||
@@ -214,8 +257,8 @@ export class PenSettingsModal extends Modal {
|
||||
strokeSetting.setName(
|
||||
fragWithHTML(
|
||||
value
|
||||
? "Stroke color: <b>Current</b>"
|
||||
: "Stroke color: <b>Preset color</b>",
|
||||
? t("PEN_SETTINGS_STROKE_CURRENT")
|
||||
: t("PEN_SETTINGS_STROKE_PRESET"),
|
||||
),
|
||||
);
|
||||
if (value) {
|
||||
@@ -232,26 +275,28 @@ export class PenSettingsModal extends Modal {
|
||||
});
|
||||
|
||||
const scSetting = new Setting(ce)
|
||||
.setName("Select stroke color")
|
||||
.setName(t("PEN_SETTINGS_STROKE_SELECT"))
|
||||
.addButton((button) =>
|
||||
button.setButtonText("Use Canvas Current").onClick(() => {
|
||||
const st = this.api.getAppState();
|
||||
const color =
|
||||
st.resetCustomPen?.currentItemStrokeColor ??
|
||||
st.currentItemStrokeColor;
|
||||
[sHex, sOpacity] = hexColor(color);
|
||||
ps.strokeColor = color;
|
||||
this.dirty = true;
|
||||
sctComponent.setValue(color);
|
||||
sChangeBounce = true;
|
||||
sccpComponent.setValue(sHex);
|
||||
}),
|
||||
button
|
||||
.setButtonText(t("PEN_SETTINGS_USE_CANVAS_CURRENT"))
|
||||
.onClick(() => {
|
||||
const st = this.api.getAppState();
|
||||
const color =
|
||||
st.resetCustomPen?.currentItemStrokeColor ??
|
||||
st.currentItemStrokeColor;
|
||||
[sHex, sOpacity] = hexColor(color);
|
||||
ps.strokeColor = color;
|
||||
this.isDirty = true;
|
||||
sctComponent.setValue(color);
|
||||
sChangeBounce = true;
|
||||
sccpComponent.setValue(sHex);
|
||||
}),
|
||||
)
|
||||
.addText((text) => {
|
||||
sctComponent = text;
|
||||
text.setValue(ps.strokeColor).onChange((value) => {
|
||||
sChangeBounce = true;
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.strokeColor = value;
|
||||
[sHex, sOpacity] = hexColor(value);
|
||||
if (sHex) {
|
||||
@@ -266,7 +311,7 @@ export class PenSettingsModal extends Modal {
|
||||
sChangeBounce = false;
|
||||
return;
|
||||
}
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.strokeColor = value + sOpacity;
|
||||
sctComponent.setValue(value + sOpacity);
|
||||
});
|
||||
@@ -282,6 +327,7 @@ export class PenSettingsModal extends Modal {
|
||||
if (!selected) {
|
||||
return;
|
||||
}
|
||||
this.isDirty = true;
|
||||
strokeUseCurrentToggle?.setValue(false);
|
||||
sChangeBounce = true;
|
||||
[sHex, sOpacity] = hexColor(selected);
|
||||
@@ -309,24 +355,20 @@ export class PenSettingsModal extends Modal {
|
||||
.setName(
|
||||
fragWithHTML(
|
||||
!ps.backgroundColor
|
||||
? "Background color: <b>Current</b>"
|
||||
: "Background color: <b>Preset color</b>",
|
||||
),
|
||||
)
|
||||
.setDesc(
|
||||
fragWithHTML(
|
||||
"Toggle to use the <b>current background color</b> of the canvas; or a <b>preset color</b>",
|
||||
? t("PEN_SETTINGS_BG_CURRENT")
|
||||
: t("PEN_SETTINGS_BG_PRESET"),
|
||||
),
|
||||
)
|
||||
.setDesc(fragWithHTML(t("PEN_SETTINGS_BG_DESC")))
|
||||
.addToggle((toggle) => {
|
||||
bgUseCurrentToggle = toggle;
|
||||
toggle.setValue(!ps.backgroundColor).onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
bgSetting.setName(
|
||||
fragWithHTML(
|
||||
value
|
||||
? "Background color: <b>Current</b>"
|
||||
: "Background color: <b>Preset color</b>",
|
||||
? t("PEN_SETTINGS_BG_CURRENT")
|
||||
: t("PEN_SETTINGS_BG_PRESET"),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -358,17 +400,17 @@ export class PenSettingsModal extends Modal {
|
||||
.setName(
|
||||
fragWithHTML(
|
||||
ps.backgroundColor === "transparent"
|
||||
? "Background: <b>Transparent</b>"
|
||||
: "Color: <b>Preset color</b>",
|
||||
? t("PEN_SETTINGS_BG_TRANSPARENT")
|
||||
: t("PEN_SETTINGS_BG_COLOR_PRESET"),
|
||||
),
|
||||
)
|
||||
.setDesc("Background has color or is transparent")
|
||||
.setDesc(t("PEN_SETTINGS_BG_TRANSPARENT_DESC"))
|
||||
.addToggle((toggle) => {
|
||||
bgtComponent = toggle;
|
||||
toggle
|
||||
.setValue(ps.backgroundColor === "transparent")
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
if (value) {
|
||||
hideElement(bgcSetting.settingEl);
|
||||
hideElement(fsSetting.settingEl);
|
||||
@@ -379,8 +421,8 @@ export class PenSettingsModal extends Modal {
|
||||
bgctSetting.setName(
|
||||
fragWithHTML(
|
||||
value
|
||||
? "Background: <b>Transparent</b>"
|
||||
: "Color: <b>Preset color</b>",
|
||||
? t("PEN_SETTINGS_BG_TRANSPARENT")
|
||||
: t("PEN_SETTINGS_BG_COLOR_PRESET"),
|
||||
),
|
||||
);
|
||||
ps.backgroundColor = value
|
||||
@@ -396,26 +438,28 @@ export class PenSettingsModal extends Modal {
|
||||
}
|
||||
let bgChangeBounce: boolean = false;
|
||||
const bgcSetting = new Setting(ce)
|
||||
.setName("Background color")
|
||||
.setName(t("PEN_SETTINGS_BG_COLOR"))
|
||||
.addButton((button) =>
|
||||
button.setButtonText("Use Canvas Current").onClick(() => {
|
||||
const st = this.api.getAppState();
|
||||
const color =
|
||||
st.resetCustomPen?.currentItemBackgroundColor ??
|
||||
st.currentItemBackgroundColor;
|
||||
[bgHex, bgOpacity] = hexColor(color);
|
||||
ps.backgroundColor = color;
|
||||
this.dirty = true;
|
||||
bgctComponent.setValue(color);
|
||||
bgChangeBounce = true;
|
||||
bgcpComponent.setValue(bgHex);
|
||||
}),
|
||||
button
|
||||
.setButtonText(t("PEN_SETTINGS_USE_CANVAS_CURRENT"))
|
||||
.onClick(() => {
|
||||
const st = this.api.getAppState();
|
||||
const color =
|
||||
st.resetCustomPen?.currentItemBackgroundColor ??
|
||||
st.currentItemBackgroundColor;
|
||||
[bgHex, bgOpacity] = hexColor(color);
|
||||
ps.backgroundColor = color;
|
||||
this.isDirty = true;
|
||||
bgctComponent.setValue(color);
|
||||
bgChangeBounce = true;
|
||||
bgcpComponent.setValue(bgHex);
|
||||
}),
|
||||
)
|
||||
.addText((text) => {
|
||||
bgctComponent = text;
|
||||
text.setValue(ps.backgroundColor).onChange((value) => {
|
||||
bgChangeBounce = true;
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.backgroundColor = value;
|
||||
[bgHex, bgOpacity] = hexColor(value);
|
||||
if (bgHex) {
|
||||
@@ -430,7 +474,7 @@ export class PenSettingsModal extends Modal {
|
||||
bgChangeBounce = false;
|
||||
return;
|
||||
}
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.backgroundColor = value + bgOpacity;
|
||||
bgctComponent.setValue(value + bgOpacity);
|
||||
});
|
||||
@@ -446,6 +490,7 @@ export class PenSettingsModal extends Modal {
|
||||
if (!selected) {
|
||||
return;
|
||||
}
|
||||
this.isDirty = true;
|
||||
bgUseCurrentToggle?.setValue(false);
|
||||
bgtComponent?.setValue(false);
|
||||
bgChangeBounce = true;
|
||||
@@ -465,20 +510,20 @@ export class PenSettingsModal extends Modal {
|
||||
}
|
||||
|
||||
const fsSetting = new Setting(ce)
|
||||
.setName("Fill Style")
|
||||
.setName(t("PEN_SETTINGS_FILL_STYLE"))
|
||||
.addDropdown((dropdown) =>
|
||||
dropdown
|
||||
.addOption("", "Unset")
|
||||
.addOption("dots", "Dots (⚠ VERY SLOW performance on large objects!)")
|
||||
.addOption("zigzag", "Zigzag")
|
||||
.addOption("zigzag-line", "Zigzag-line")
|
||||
.addOption("dashed", "Dashed")
|
||||
.addOption("hachure", "Hachure")
|
||||
.addOption("cross-hatch", "Cross-hatch")
|
||||
.addOption("solid", "Solid")
|
||||
.addOption("", t("PEN_SETTINGS_FILL_UNSET"))
|
||||
.addOption("dots", t("PEN_SETTINGS_FILL_DOTS"))
|
||||
.addOption("zigzag", t("PEN_SETTINGS_FILL_ZIGZAG"))
|
||||
.addOption("zigzag-line", t("PEN_SETTINGS_FILL_ZIGZAG_LINE"))
|
||||
.addOption("dashed", t("PEN_SETTINGS_FILL_DASHED"))
|
||||
.addOption("hachure", t("PEN_SETTINGS_FILL_HACHURE"))
|
||||
.addOption("cross-hatch", t("PEN_SETTINGS_FILL_CROSS_HATCH"))
|
||||
.addOption("solid", t("PEN_SETTINGS_FILL_SOLID"))
|
||||
.setValue(ps.fillStyle)
|
||||
.onChange((value: ExtendedFillStyle) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.fillStyle = value;
|
||||
}),
|
||||
);
|
||||
@@ -488,66 +533,111 @@ export class PenSettingsModal extends Modal {
|
||||
showElement(fsSetting.settingEl);
|
||||
}
|
||||
|
||||
const getSloppinessName = (roughness: number | null) => {
|
||||
if (roughness === null) return t("PEN_SETTINGS_NOT_SET");
|
||||
if (roughness <= 0.5)
|
||||
return `${t("PEN_SETTINGS_SLOPPINESS_ARCHITECT")} (${roughness})`;
|
||||
if (roughness <= 1.5)
|
||||
return `${t("PEN_SETTINGS_SLOPPINESS_ARTIST")} (${roughness})`;
|
||||
return `${t("PEN_SETTINGS_SLOPPINESS_CARTOONIST")} (${roughness})`;
|
||||
};
|
||||
|
||||
const rSetting = new Setting(ce)
|
||||
.setName(
|
||||
fragWithHTML(
|
||||
`Sloppiness: <b>${ps.roughness === null ? "Not Set" : ps.roughness <= 0.5 ? "Architect (" : ps.roughness <= 1.5 ? "Artist (" : "Cartoonist ("}${ps.roughness === null ? "" : `${ps.roughness})`}</b>`,
|
||||
`${t("PEN_SETTINGS_SLOPPINESS")} <b>${getSloppinessName(ps.roughness)}</b>`,
|
||||
),
|
||||
)
|
||||
.setDesc("Line sloppiness of the shape fill pattern")
|
||||
.setDesc(t("PEN_SETTINGS_SLOPPINESS_DESC"))
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(-0.5, 3, 0.5)
|
||||
.setValue(ps.roughness === null ? -0.5 : ps.roughness)
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.roughness = value === -0.5 ? null : value;
|
||||
rSetting.setName(
|
||||
fragWithHTML(
|
||||
`Sloppiness: <b>${ps.roughness === null ? "Not Set" : ps.roughness <= 0.5 ? "Architect (" : ps.roughness <= 1.5 ? "Artist (" : "Cartoonist ("}${ps.roughness === null ? "" : `${ps.roughness})`}</b>`,
|
||||
`${t("PEN_SETTINGS_SLOPPINESS")} <b>${getSloppinessName(ps.roughness)}</b>`,
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
let strokeWidthSlider: SliderComponent;
|
||||
let strokeWidthPresetDropdown: DropdownComponent;
|
||||
let strokeWidthPresetUpdateInProgress = false;
|
||||
|
||||
const swSetting = new Setting(ce)
|
||||
.setName(
|
||||
fragWithHTML(
|
||||
`Stroke Width <b>${ps.strokeWidth === 0 ? "Not Set" : ps.strokeWidth}</b>`,
|
||||
`${t("PEN_SETTINGS_STROKE_WIDTH")} <b>${ps.strokeWidth === 0 ? t("PEN_SETTINGS_NOT_SET") : ps.strokeWidth}</b>`,
|
||||
),
|
||||
)
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(0.1, 8, 0.1)
|
||||
.setValue(ps.strokeWidth)
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
ps.strokeWidth = value;
|
||||
.addDropdown((dropdown) => {
|
||||
strokeWidthPresetDropdown = dropdown;
|
||||
dropdown
|
||||
.addOption("", t("PEN_SETTINGS_STROKE_PRESET_UNSET"))
|
||||
.addOption("extraThin", t("PEN_SETTINGS_STROKE_PRESET_EXTRA_THIN"))
|
||||
.addOption("thin", t("PEN_SETTINGS_STROKE_PRESET_THIN"))
|
||||
.addOption("medium", t("PEN_SETTINGS_STROKE_PRESET_MEDIUM"))
|
||||
.addOption("bold", t("PEN_SETTINGS_STROKE_PRESET_BOLD"))
|
||||
.addOption("extraBold", t("PEN_SETTINGS_STROKE_PRESET_EXTRA_BOLD"))
|
||||
.setValue(getStrokeWidthPresetKey(ps.strokeWidth))
|
||||
.onChange((value: StrokeWidthKey | "") => {
|
||||
this.isDirty = true;
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
const presetStrokeWidth = FREEDRAW_STROKE_WIDTH_PRESETS[value];
|
||||
ps.strokeWidth = presetStrokeWidth;
|
||||
strokeWidthPresetUpdateInProgress = true;
|
||||
strokeWidthSlider?.setValue(presetStrokeWidth);
|
||||
swSetting.setName(
|
||||
fragWithHTML(
|
||||
`Stroke Width <b>${ps.strokeWidth === 0 ? "Not Set" : ps.strokeWidth}</b>`,
|
||||
`${t("PEN_SETTINGS_STROKE_WIDTH")} <b>${ps.strokeWidth === 0 ? t("PEN_SETTINGS_NOT_SET") : ps.strokeWidth}</b>`,
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
});
|
||||
})
|
||||
.addSlider((slider) => {
|
||||
strokeWidthSlider = slider;
|
||||
slider
|
||||
.setLimits(0.05, 8, 0.05)
|
||||
.setValue(ps.strokeWidth)
|
||||
.onChange((value) => {
|
||||
this.isDirty = true;
|
||||
ps.strokeWidth = value;
|
||||
|
||||
new Setting(ce).setName("Highlighter pen?").addToggle((toggle) =>
|
||||
if (strokeWidthPresetUpdateInProgress) {
|
||||
strokeWidthPresetUpdateInProgress = false;
|
||||
} else {
|
||||
strokeWidthPresetDropdown.setValue(
|
||||
getStrokeWidthPresetKey(value),
|
||||
);
|
||||
}
|
||||
|
||||
swSetting.setName(
|
||||
fragWithHTML(
|
||||
`${t("PEN_SETTINGS_STROKE_WIDTH")} <b>${ps.strokeWidth === 0 ? t("PEN_SETTINGS_NOT_SET") : ps.strokeWidth}</b>`,
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(ce).setName(t("PEN_SETTINGS_HIGHLIGHTER")).addToggle((toggle) =>
|
||||
toggle.setValue(ps.penOptions.highlighter).onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.penOptions.highlighter = value;
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(ce)
|
||||
.setName("Pressure sensitive pen?")
|
||||
.setDesc(
|
||||
fragWithHTML(
|
||||
`<b>toggle on</b>: pressure sensitive<br><b>toggle off</b>: constant pressure`,
|
||||
),
|
||||
)
|
||||
.setName(t("PEN_SETTINGS_PRESSURE"))
|
||||
.setDesc(fragWithHTML(t("PEN_SETTINGS_PRESSURE_DESC")))
|
||||
.addToggle((toggle) =>
|
||||
toggle.setValue(!ps.penOptions.constantPressure).onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.penOptions.constantPressure = !value;
|
||||
if (ps.penOptions.constantPressure) {
|
||||
hideElement(spSetting.settingEl);
|
||||
@@ -559,127 +649,128 @@ export class PenSettingsModal extends Modal {
|
||||
|
||||
if (ps.penOptions.hasOutline && ps.penOptions.outlineWidth === 0) {
|
||||
ps.penOptions.outlineWidth = 0.5;
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
}
|
||||
|
||||
if (!ps.penOptions.hasOutline && ps.penOptions.outlineWidth > 0) {
|
||||
ps.penOptions.outlineWidth = 0;
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
}
|
||||
|
||||
const owSetting = new Setting(ce)
|
||||
.setName(
|
||||
fragWithHTML(
|
||||
ps.penOptions.outlineWidth === 0
|
||||
? `No outline`
|
||||
: `Outline width <b>${ps.penOptions.outlineWidth}</b>`,
|
||||
? t("PEN_SETTINGS_OUTLINE_NONE")
|
||||
: `${t("PEN_SETTINGS_OUTLINE_WIDTH")} <b>${ps.penOptions.outlineWidth}</b>`,
|
||||
),
|
||||
)
|
||||
.setDesc(
|
||||
"If the stroke has an outline, this will mean the stroke color is the outline color, and the background color is the pen stroke's fill color. If the pen does not have an outline then the pen color is the stroke color. The Fill Style setting applies to the fill style of the enclosed shape, not of the line itself. The line can only have solid fill.",
|
||||
)
|
||||
.setDesc(t("PEN_SETTINGS_OUTLINE_DESC"))
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(0, 8, 0.1)
|
||||
.setValue(ps.penOptions.outlineWidth)
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.penOptions.outlineWidth = value;
|
||||
ps.penOptions.hasOutline = value > 0;
|
||||
owSetting.setName(
|
||||
fragWithHTML(
|
||||
ps.penOptions.outlineWidth === 0
|
||||
? `No outline`
|
||||
: `Outline width <b>${ps.penOptions.outlineWidth}</b>`,
|
||||
? t("PEN_SETTINGS_OUTLINE_NONE")
|
||||
: `${t("PEN_SETTINGS_OUTLINE_WIDTH")} <b>${ps.penOptions.outlineWidth}</b>`,
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
ce.createEl("h2", { text: "Perfect Freehand settings" });
|
||||
ce.createEl("h2", { text: t("PEN_SETTINGS_PF_HEADING") });
|
||||
const p = ce.createEl("p");
|
||||
setSanitizedHtml(
|
||||
p,
|
||||
`Read the Perfect Freehand documentation following <a href="${URLs.GITHUB_COM_STEVERUIZOK_PERFECT_FREEHAND}" target="_blank">this link</a>.`,
|
||||
);
|
||||
setSanitizedHtml(p, t("PEN_SETTINGS_PF_DOCS"));
|
||||
|
||||
const tSetting = new Setting(ce)
|
||||
.setName(
|
||||
fragWithHTML(`Thinnning <b>${ps.penOptions.options.thinning}</b>`),
|
||||
)
|
||||
.setDesc(
|
||||
fragWithHTML(
|
||||
`The effect of pressure on the stroke's size.<br>To create a stroke with a steady line, set the thinning option to 0.<br>To create a stroke that gets thinner with pressure instead of thicker, use a negative number for the thinning option.`,
|
||||
`${t("PEN_SETTINGS_PF_THINNING")} <b>${ps.penOptions.options.thinning}</b>`,
|
||||
),
|
||||
)
|
||||
.setDesc(fragWithHTML(t("PEN_SETTINGS_PF_THINNING_DESC")))
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(-1, 1, 0.05)
|
||||
.setValue(ps.penOptions.options.thinning)
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
tSetting.setName(fragWithHTML(`Thinnning <b>${value}</b>`));
|
||||
this.isDirty = true;
|
||||
tSetting.setName(
|
||||
fragWithHTML(`${t("PEN_SETTINGS_PF_THINNING")} <b>${value}</b>`),
|
||||
);
|
||||
ps.penOptions.options.thinning = value;
|
||||
}),
|
||||
);
|
||||
|
||||
const sSetting = new Setting(ce)
|
||||
.setName(
|
||||
fragWithHTML(`Smoothing <b>${ps.penOptions.options.smoothing}</b>`),
|
||||
fragWithHTML(
|
||||
`${t("PEN_SETTINGS_PF_SMOOTHING")} <b>${ps.penOptions.options.smoothing}</b>`,
|
||||
),
|
||||
)
|
||||
.setDesc(fragWithHTML(`How much to soften the stroke's edges.`))
|
||||
.setDesc(fragWithHTML(t("PEN_SETTINGS_PF_SMOOTHING_DESC")))
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(0, 1, 0.05)
|
||||
.setValue(ps.penOptions.options.smoothing)
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
sSetting.setName(fragWithHTML(`Smoothing <b>${value}</b>`));
|
||||
this.isDirty = true;
|
||||
sSetting.setName(
|
||||
fragWithHTML(`${t("PEN_SETTINGS_PF_SMOOTHING")} <b>${value}</b>`),
|
||||
);
|
||||
ps.penOptions.options.smoothing = value;
|
||||
}),
|
||||
);
|
||||
|
||||
const slSetting = new Setting(ce)
|
||||
.setName(
|
||||
fragWithHTML(`Streamline <b>${ps.penOptions.options.streamline}</b>`),
|
||||
fragWithHTML(
|
||||
`${t("PEN_SETTINGS_PF_STREAMLINE")} <b>${ps.penOptions.options.streamline}</b>`,
|
||||
),
|
||||
)
|
||||
.setDesc(fragWithHTML(` How much to streamline the stroke.`))
|
||||
.setDesc(fragWithHTML(t("PEN_SETTINGS_PF_STREAMLINE_DESC")))
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(0, 1, 0.05)
|
||||
.setValue(ps.penOptions.options.streamline)
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
slSetting.setName(fragWithHTML(`Streamline <b>${value}</b>`));
|
||||
this.isDirty = true;
|
||||
slSetting.setName(
|
||||
fragWithHTML(
|
||||
`${t("PEN_SETTINGS_PF_STREAMLINE")} <b>${value}</b>`,
|
||||
),
|
||||
);
|
||||
ps.penOptions.options.streamline = value;
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(ce)
|
||||
.setName("Easing function")
|
||||
.setDesc(
|
||||
fragWithHTML(
|
||||
`An easing function for the tapering effect. For more info <a href="${URLs.EASINGS_NET}" target="_blank">click here</a>`,
|
||||
),
|
||||
)
|
||||
.setName(t("PEN_SETTINGS_EASING"))
|
||||
.setDesc(fragWithHTML(t("PEN_SETTINGS_EASING_DESC")))
|
||||
.addDropdown((dropdown) =>
|
||||
dropdown
|
||||
.addOptions(EASINGFUNCTIONS)
|
||||
.setValue(ps.penOptions.options.easing)
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.penOptions.options.easing = value;
|
||||
}),
|
||||
);
|
||||
|
||||
const spSetting = new Setting(ce)
|
||||
.setName("Simulate Pressure")
|
||||
.setDesc("Whether to simulate pressure based on velocity.")
|
||||
.setName(t("PEN_SETTINGS_SIMULATE_PRESSURE"))
|
||||
.setDesc(t("PEN_SETTINGS_SIMULATE_PRESSURE_DESC"))
|
||||
.addDropdown((dropdown) =>
|
||||
dropdown
|
||||
.addOption("true", "Always")
|
||||
.addOption("false", "Never")
|
||||
.addOption("", "Yes for mouse, No for pen")
|
||||
.addOption("true", t("PEN_SETTINGS_SIMULATE_PRESSURE_ALWAYS"))
|
||||
.addOption("false", t("PEN_SETTINGS_SIMULATE_PRESSURE_NEVER"))
|
||||
.addOption("", t("PEN_SETTINGS_SIMULATE_PRESSURE_MOUSE"))
|
||||
.setValue(
|
||||
ps.penOptions.options.simulatePressure === true
|
||||
? "true"
|
||||
@@ -688,7 +779,7 @@ export class PenSettingsModal extends Modal {
|
||||
: "",
|
||||
)
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
switch (value) {
|
||||
case "true":
|
||||
ps.penOptions.options.simulatePressure = true;
|
||||
@@ -708,15 +799,15 @@ export class PenSettingsModal extends Modal {
|
||||
showElement(spSetting.settingEl);
|
||||
}
|
||||
|
||||
ce.createEl("h3", { text: "Start" });
|
||||
ce.createEl("p", { text: "Tapering options for the start of the line." });
|
||||
ce.createEl("h3", { text: t("PEN_SETTINGS_START_HEADING") });
|
||||
ce.createEl("p", { text: t("PEN_SETTINGS_START_DESC") });
|
||||
|
||||
new Setting(ce)
|
||||
.setName("Cap Start")
|
||||
.setDesc("Whether to draw a cap")
|
||||
.setName(t("PEN_SETTINGS_CAP_START"))
|
||||
.setDesc(t("PEN_SETTINGS_CAP_DESC"))
|
||||
.addToggle((toggle) =>
|
||||
toggle.setValue(ps.penOptions.options.start.cap).onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.penOptions.options.start.cap = value;
|
||||
}),
|
||||
);
|
||||
@@ -724,12 +815,10 @@ export class PenSettingsModal extends Modal {
|
||||
const stSetting = new Setting(ce)
|
||||
.setName(
|
||||
fragWithHTML(
|
||||
`Taper: <b>${ps.penOptions.options.start.taper === true ? "true" : ps.penOptions.options.start.taper}</b>`,
|
||||
`${t("PEN_SETTINGS_TAPER")} <b>${ps.penOptions.options.start.taper === true ? "true" : ps.penOptions.options.start.taper}</b>`,
|
||||
),
|
||||
)
|
||||
.setDesc(
|
||||
"The distance to taper. If set to true, the taper will be the total length of the stroke.",
|
||||
)
|
||||
.setDesc(t("PEN_SETTINGS_TAPER_DESC"))
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(0, 151, 1)
|
||||
@@ -739,42 +828,38 @@ export class PenSettingsModal extends Modal {
|
||||
: ps.penOptions.options.start.taper,
|
||||
)
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.penOptions.options.start.taper = value === 151 ? true : value;
|
||||
stSetting.setName(
|
||||
fragWithHTML(
|
||||
`Taper: <b>${ps.penOptions.options.start.taper === true ? "true" : ps.penOptions.options.start.taper}</b>`,
|
||||
`${t("PEN_SETTINGS_TAPER")} <b>${ps.penOptions.options.start.taper === true ? "true" : ps.penOptions.options.start.taper}</b>`,
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(ce)
|
||||
.setName("Easing function")
|
||||
.setDesc(
|
||||
fragWithHTML(
|
||||
`An easing function for the tapering effect. For more info <a href="${URLs.EASINGS_NET}" target="_blank">click here</a>`,
|
||||
),
|
||||
)
|
||||
.setName(t("PEN_SETTINGS_EASING"))
|
||||
.setDesc(fragWithHTML(t("PEN_SETTINGS_EASING_DESC")))
|
||||
.addDropdown((dropdown) =>
|
||||
dropdown
|
||||
.addOptions(EASINGFUNCTIONS)
|
||||
.setValue(ps.penOptions.options.start.easing)
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.penOptions.options.start.easing = value;
|
||||
}),
|
||||
);
|
||||
|
||||
ce.createEl("h3", { text: "End" });
|
||||
ce.createEl("p", { text: "Tapering options for the end of the line." });
|
||||
ce.createEl("h3", { text: t("PEN_SETTINGS_END_HEADING") });
|
||||
ce.createEl("p", { text: t("PEN_SETTINGS_END_DESC") });
|
||||
|
||||
new Setting(ce)
|
||||
.setName("Cap End")
|
||||
.setDesc("Whether to draw a cap")
|
||||
.setName(t("PEN_SETTINGS_CAP_END"))
|
||||
.setDesc(t("PEN_SETTINGS_CAP_DESC"))
|
||||
.addToggle((toggle) =>
|
||||
toggle.setValue(ps.penOptions.options.end.cap).onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.penOptions.options.end.cap = value;
|
||||
}),
|
||||
);
|
||||
@@ -782,12 +867,10 @@ export class PenSettingsModal extends Modal {
|
||||
const etSetting = new Setting(ce)
|
||||
.setName(
|
||||
fragWithHTML(
|
||||
`Taper: <b>${ps.penOptions.options.end.taper === true ? "true" : ps.penOptions.options.end.taper}</b>`,
|
||||
`${t("PEN_SETTINGS_TAPER")} <b>${ps.penOptions.options.end.taper === true ? "true" : ps.penOptions.options.end.taper}</b>`,
|
||||
),
|
||||
)
|
||||
.setDesc(
|
||||
"The distance to taper. If set to true, the taper will be the total length of the stroke.",
|
||||
)
|
||||
.setDesc(t("PEN_SETTINGS_TAPER_DESC"))
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(0, 151, 1)
|
||||
@@ -797,31 +880,30 @@ export class PenSettingsModal extends Modal {
|
||||
: ps.penOptions.options.end.taper,
|
||||
)
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.penOptions.options.end.taper = value === 151 ? true : value;
|
||||
etSetting.setName(
|
||||
fragWithHTML(
|
||||
`Taper: <b>${ps.penOptions.options.end.taper === true ? "true" : ps.penOptions.options.end.taper}</b>`,
|
||||
`${t("PEN_SETTINGS_TAPER")} <b>${ps.penOptions.options.end.taper === true ? "true" : ps.penOptions.options.end.taper}</b>`,
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(ce)
|
||||
.setName("Easing function")
|
||||
.setDesc(
|
||||
fragWithHTML(
|
||||
`An easing function for the tapering effect. For more info <a href="${URLs.EASINGS_NET}" target="_blank">click here</a>`,
|
||||
),
|
||||
)
|
||||
.setName(t("PEN_SETTINGS_EASING"))
|
||||
.setDesc(fragWithHTML(t("PEN_SETTINGS_EASING_DESC")))
|
||||
.addDropdown((dropdown) =>
|
||||
dropdown
|
||||
.addOptions(EASINGFUNCTIONS)
|
||||
.setValue(ps.penOptions.options.end.easing)
|
||||
.onChange((value) => {
|
||||
this.dirty = true;
|
||||
this.isDirty = true;
|
||||
ps.penOptions.options.end.easing = value;
|
||||
}),
|
||||
);
|
||||
|
||||
// Bottom buttons
|
||||
this.addActionButtons(ce);
|
||||
}
|
||||
}
|
||||
@@ -1129,6 +1129,25 @@ export const getStrokeKeyFormLegacyWidth = (
|
||||
}
|
||||
};
|
||||
|
||||
export const getStrokeWidthKeyByWidth = (
|
||||
strokeWidth: number,
|
||||
): StrokeWidthKey | "extraBold" | undefined => {
|
||||
switch (strokeWidth) {
|
||||
case 0.25:
|
||||
return "extraThin";
|
||||
case 0.5:
|
||||
return "thin";
|
||||
case 1:
|
||||
return "medium";
|
||||
case 2:
|
||||
return "bold";
|
||||
case 4:
|
||||
return "extraBold";
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
// Returns an appState key for the stroke width
|
||||
// excalidraw.com deprected and removed currentItemStrokeWidth from appState
|
||||
// but the plugin still supports it to allow custom line width settings for scripts and custom pens
|
||||
@@ -1140,7 +1159,8 @@ export const getAppStateStrokeWidthEntry = (
|
||||
legacyStrokeWidth: number,
|
||||
) => {
|
||||
if (legacyStrokeWidth !== undefined) {
|
||||
strokeWidthKey = getStrokeKeyFormLegacyWidth(legacyStrokeWidth);
|
||||
// Reusing the combined function here
|
||||
strokeWidthKey = getStrokeWidthKeyByWidth(legacyStrokeWidth);
|
||||
}
|
||||
if (!!legacyStrokeWidth && !strokeWidthKey) {
|
||||
return { currentItemStrokeWidth: legacyStrokeWidth };
|
||||
|
||||
@@ -660,12 +660,16 @@ export function stripYamlFrontmatter(text: string): string {
|
||||
export function strictArrayBuffer(
|
||||
buffer: ArrayBuffer | SharedArrayBuffer,
|
||||
): ArrayBuffer {
|
||||
if (buffer instanceof SharedArrayBuffer) {
|
||||
// Check if SharedArrayBuffer is defined in the current environment
|
||||
if (
|
||||
typeof SharedArrayBuffer !== "undefined" &&
|
||||
buffer instanceof SharedArrayBuffer
|
||||
) {
|
||||
const strictBuffer = new ArrayBuffer(buffer.byteLength);
|
||||
new Uint8Array(strictBuffer).set(new Uint8Array(buffer));
|
||||
return strictBuffer;
|
||||
}
|
||||
return buffer;
|
||||
return buffer as ArrayBuffer;
|
||||
}
|
||||
|
||||
// 1. Map your custom 'type' strings to actual TypeScript types
|
||||
|
||||
@@ -8140,6 +8140,7 @@ export default class ExcalidrawView
|
||||
if (!api) {
|
||||
return false;
|
||||
}
|
||||
this.obsidianMenu?.invalidateCustomPenCache();
|
||||
api.updateScene({
|
||||
appState: {
|
||||
customPens: this.plugin.settings.customPens.slice(
|
||||
|
||||
@@ -151,6 +151,10 @@ export class ObsidianMenu {
|
||||
);
|
||||
}
|
||||
|
||||
public invalidateCustomPenCache() {
|
||||
this.activePens = {};
|
||||
}
|
||||
|
||||
private actionCustomPenLabelClick(index: number, pen: PenStyle) {
|
||||
const now = Date.now();
|
||||
const dblClick = now - this.clickTimestamp[index] < 500;
|
||||
|
||||
+16
@@ -1077,4 +1077,20 @@ End Obsidian Sheets Plus support
|
||||
|
||||
.excalidraw .App-tray-menu {
|
||||
min-width: calc(6 * var(--default-button-size));
|
||||
}
|
||||
|
||||
.excalidraw-pen-settings-floating-actions {
|
||||
position: sticky;
|
||||
bottom: -20px;
|
||||
margin-bottom: -20px;
|
||||
padding-bottom: 20px;
|
||||
padding-top: 15px;
|
||||
background-color: var(--background-primary);
|
||||
border-top: 1px solid var(--background-modifier-border);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.excalidraw-pen-settings-floating-actions .setting-item {
|
||||
border-top: none;
|
||||
padding: 0;
|
||||
}
|
||||
Reference in new issue
Block a user