Skip to content

Commit fa14964

Browse files
author
Bernard Xie
authored
Merge pull request #20 from terrastruct/18/add-pad-sketch-options
options: add pad/sketch options
2 parents 9508bbf + 62d2f53 commit fa14964

File tree

5 files changed

+70
-32
lines changed

5 files changed

+70
-32
lines changed

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "d2-obsidian",
33
"name": "D2",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"minAppVersion": "0.15.0",
66
"description": "The official D2 plugin for Obsidian. D2 is a modern diagram scripting language that turns text to diagrams.",
77
"author": "Terrastruct",

package.json

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
2-
"name": "d2-obsidian",
3-
"version": "1.0.0",
4-
"description": "This is the official D2 plugin for Obsidian.",
5-
"main": "main.js",
6-
"scripts": {
7-
"dev": "node esbuild.config.mjs",
8-
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
9-
"version": "node version-bump.mjs && git add manifest.json versions.json"
10-
},
11-
"keywords": [],
12-
"author": "",
13-
"license": "MIT",
14-
"devDependencies": {
15-
"@types/lodash.debounce": "^4.0.7",
16-
"@types/node": "^16.11.6",
17-
"@typescript-eslint/eslint-plugin": "5.29.0",
18-
"@typescript-eslint/parser": "5.29.0",
19-
"builtin-modules": "3.3.0",
20-
"esbuild": "0.14.47",
21-
"obsidian": "latest",
22-
"tslib": "2.4.0",
23-
"typescript": "4.7.4"
24-
},
25-
"dependencies": {
26-
"child_process": "^1.0.2",
27-
"lodash.debounce": "^4.0.8"
28-
}
2+
"name": "d2-obsidian",
3+
"version": "1.1.0",
4+
"description": "This is the official D2 plugin for Obsidian.",
5+
"main": "main.js",
6+
"scripts": {
7+
"dev": "node esbuild.config.mjs",
8+
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
9+
"version": "node version-bump.mjs && git add manifest.json versions.json"
10+
},
11+
"keywords": [],
12+
"author": "",
13+
"license": "MIT",
14+
"devDependencies": {
15+
"@types/lodash.debounce": "^4.0.7",
16+
"@types/node": "^16.11.6",
17+
"@typescript-eslint/eslint-plugin": "5.29.0",
18+
"@typescript-eslint/parser": "5.29.0",
19+
"builtin-modules": "3.3.0",
20+
"esbuild": "0.14.47",
21+
"obsidian": "latest",
22+
"tslib": "2.4.0",
23+
"typescript": "4.7.4"
24+
},
25+
"dependencies": {
26+
"child_process": "^1.0.2",
27+
"lodash.debounce": "^4.0.8"
28+
}
2929
}

src/processor.ts

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ export class D2Processor {
159159
"-",
160160
`--theme=${this.plugin.settings.theme}`,
161161
`--layout=${this.plugin.settings.layoutEngine}`,
162+
`--pad=${this.plugin.settings.pad}`,
163+
`--sketch=${this.plugin.settings.sketch}`,
162164
"--bundle=false",
163165
];
164166
const cmd = args.join(" ");

src/settings.ts

+37-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export interface D2PluginSettings {
99
debounce: number;
1010
theme: number;
1111
d2Path: string;
12+
pad: number;
13+
sketch: boolean;
1214
}
1315

1416
export const DEFAULT_SETTINGS: D2PluginSettings = {
@@ -17,6 +19,8 @@ export const DEFAULT_SETTINGS: D2PluginSettings = {
1719
theme: 0,
1820
apiToken: "",
1921
d2Path: "",
22+
pad: 100,
23+
sketch: false,
2024
};
2125

2226
export class D2SettingsTab extends PluginSettingTab {
@@ -93,7 +97,7 @@ export class D2SettingsTab extends PluginSettingTab {
9397
.setPlaceholder("Enter a theme ID")
9498
.setValue(String(this.plugin.settings.theme))
9599
.onChange(async (value) => {
96-
if (!isNaN(Number(value)) || value === undefined) {
100+
if (!isNaN(Number(value)) || value === "") {
97101
this.plugin.settings.theme = Number(value || DEFAULT_SETTINGS.theme);
98102
await this.plugin.saveSettings();
99103
} else {
@@ -102,6 +106,36 @@ export class D2SettingsTab extends PluginSettingTab {
102106
})
103107
);
104108

109+
new Setting(containerEl)
110+
.setName("Pad")
111+
.setDesc("Pixels padded around the rendered diagram")
112+
.addText((text) =>
113+
text
114+
.setPlaceholder(String(DEFAULT_SETTINGS.pad))
115+
.setValue(String(this.plugin.settings.pad))
116+
.onChange(async (value) => {
117+
if (isNaN(Number(value))) {
118+
new Notice("Please specify a valid number");
119+
this.plugin.settings.pad = Number(DEFAULT_SETTINGS.pad);
120+
} else if (value === "") {
121+
this.plugin.settings.pad = Number(DEFAULT_SETTINGS.pad);
122+
} else {
123+
this.plugin.settings.pad = Number(value);
124+
}
125+
await this.plugin.saveSettings();
126+
})
127+
);
128+
129+
new Setting(containerEl)
130+
.setName("Sketch mode")
131+
.setDesc("Render the diagram to look like it was sketched by hand")
132+
.addToggle((toggle) =>
133+
toggle.setValue(this.plugin.settings.sketch).onChange(async (value) => {
134+
this.plugin.settings.sketch = value;
135+
await this.plugin.saveSettings();
136+
})
137+
);
138+
105139
new Setting(containerEl)
106140
.setName("Debounce")
107141
.setDesc("How often should the diagram refresh in milliseconds (min 100)")
@@ -113,7 +147,7 @@ export class D2SettingsTab extends PluginSettingTab {
113147
if (isNaN(Number(value))) {
114148
new Notice("Please specify a valid number");
115149
this.plugin.settings.debounce = Number(DEFAULT_SETTINGS.debounce);
116-
} else if (value === undefined) {
150+
} else if (value === "") {
117151
this.plugin.settings.debounce = Number(DEFAULT_SETTINGS.debounce);
118152
} else if (Number(value) < 100) {
119153
new Notice("The value must be greater than 100");
@@ -128,7 +162,7 @@ export class D2SettingsTab extends PluginSettingTab {
128162
new Setting(containerEl)
129163
.setName("Path (optional)")
130164
.setDesc(
131-
"Customize the local path to the directory `d2` is installed in. This is only necessary if `d2` is not found automatically by the plugin (but is installed)."
165+
"Customize the local path to the directory `d2` is installed in (ex. if d2 is located at `/usr/local/bin/d2`, then the path is `/usr/local/bin`). This is only necessary if `d2` is not found automatically by the plugin (but is installed)."
132166
)
133167
.addText((text) => {
134168
text

versions.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"1.0.1": "0.15.0"
2+
"1.1.0": "0.15.0",
3+
"1.0.1": "0.15.0",
4+
"1.0.0": "0.15.0"
35
}

0 commit comments

Comments
 (0)