@bendyline/docblocks-react 2.2.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,255 +0,0 @@
1
- import {
2
- Dialog
3
- } from "./chunk-LG6HAWCK.js";
4
-
5
- // src/preferences/theme.ts
6
- var ACCENT_COLORS = [
7
- "brown",
8
- "green",
9
- "blue",
10
- "purple",
11
- "maroon",
12
- "orange",
13
- "gray"
14
- ];
15
- var DB_CHROME_COLORS = {
16
- light: "#f3eede",
17
- dark: "#262219"
18
- };
19
- var THEME_STORAGE_KEY = "docblocks:themePreference";
20
- var ACCENT_STORAGE_KEY = "docblocks:accentColor";
21
- function loadThemePreference() {
22
- try {
23
- const raw = localStorage.getItem(THEME_STORAGE_KEY);
24
- if (raw === "light" || raw === "dark" || raw === "auto") return raw;
25
- } catch {
26
- }
27
- return "auto";
28
- }
29
- function saveThemePreference(value) {
30
- try {
31
- localStorage.setItem(THEME_STORAGE_KEY, value);
32
- } catch {
33
- }
34
- }
35
- function loadAccentColor() {
36
- try {
37
- const raw = localStorage.getItem(ACCENT_STORAGE_KEY);
38
- if (ACCENT_COLORS.some((color) => color === raw)) return raw;
39
- } catch {
40
- }
41
- return "brown";
42
- }
43
- function saveAccentColor(value) {
44
- try {
45
- localStorage.setItem(ACCENT_STORAGE_KEY, value);
46
- } catch {
47
- }
48
- }
49
-
50
- // src/preferences/write-canvas.ts
51
- var WRITE_CANVAS_TEXT_SIZE_MIN = 12;
52
- var WRITE_CANVAS_TEXT_SIZE_MAX = 32;
53
- var WRITE_CANVAS_LINE_SPACING_MIN = 1.2;
54
- var WRITE_CANVAS_LINE_SPACING_MAX = 2.4;
55
- var DEFAULT_WRITE_CANVAS_PREFERENCES = {
56
- textSize: 16,
57
- lineSpacing: 1.7
58
- };
59
- var WRITE_CANVAS_STORAGE_KEY = "docblocks:writeCanvasSettings";
60
- function loadWriteCanvasPreferences() {
61
- try {
62
- const raw = localStorage.getItem(WRITE_CANVAS_STORAGE_KEY);
63
- if (!raw) return { ...DEFAULT_WRITE_CANVAS_PREFERENCES };
64
- const stored = JSON.parse(raw);
65
- if (!isRecord(stored)) return { ...DEFAULT_WRITE_CANVAS_PREFERENCES };
66
- return {
67
- textSize: numberInRange(
68
- stored.textSize,
69
- WRITE_CANVAS_TEXT_SIZE_MIN,
70
- WRITE_CANVAS_TEXT_SIZE_MAX
71
- ) ? stored.textSize : DEFAULT_WRITE_CANVAS_PREFERENCES.textSize,
72
- lineSpacing: numberInRange(
73
- stored.lineSpacing,
74
- WRITE_CANVAS_LINE_SPACING_MIN,
75
- WRITE_CANVAS_LINE_SPACING_MAX
76
- ) ? stored.lineSpacing : DEFAULT_WRITE_CANVAS_PREFERENCES.lineSpacing
77
- };
78
- } catch {
79
- return { ...DEFAULT_WRITE_CANVAS_PREFERENCES };
80
- }
81
- }
82
- function saveWriteCanvasPreferences(value) {
83
- try {
84
- localStorage.setItem(WRITE_CANVAS_STORAGE_KEY, JSON.stringify(value));
85
- } catch {
86
- }
87
- }
88
- function numberInRange(value, min, max) {
89
- return typeof value === "number" && Number.isFinite(value) && value >= min && value <= max;
90
- }
91
- function isRecord(value) {
92
- return typeof value === "object" && value !== null && !Array.isArray(value);
93
- }
94
-
95
- // src/Settings/Settings.tsx
96
- import { jsx, jsxs } from "react/jsx-runtime";
97
- var ACCENT_LABELS = {
98
- brown: "Brown",
99
- green: "Green",
100
- blue: "Blue",
101
- purple: "Purple",
102
- maroon: "Maroon",
103
- orange: "Orange",
104
- gray: "Gray"
105
- };
106
- function SettingsDialog({ title = "Settings", onClose, children }) {
107
- return /* @__PURE__ */ jsx(Dialog, { title, onClose, size: "wide", children });
108
- }
109
- function ThemeSettings({ value, onChange, name = "theme" }) {
110
- return /* @__PURE__ */ jsxs("fieldset", { className: "db-settings-fieldset", children: [
111
- /* @__PURE__ */ jsx("legend", { className: "db-settings-legend", children: "Theme" }),
112
- /* @__PURE__ */ jsxs("label", { className: "db-settings-radio", children: [
113
- /* @__PURE__ */ jsx(
114
- "input",
115
- {
116
- type: "radio",
117
- name,
118
- value: "auto",
119
- checked: value === "auto",
120
- onChange: () => onChange("auto")
121
- }
122
- ),
123
- "System default"
124
- ] }),
125
- /* @__PURE__ */ jsxs("label", { className: "db-settings-radio", children: [
126
- /* @__PURE__ */ jsx(
127
- "input",
128
- {
129
- type: "radio",
130
- name,
131
- value: "light",
132
- checked: value === "light",
133
- onChange: () => onChange("light")
134
- }
135
- ),
136
- "Light"
137
- ] }),
138
- /* @__PURE__ */ jsxs("label", { className: "db-settings-radio", children: [
139
- /* @__PURE__ */ jsx(
140
- "input",
141
- {
142
- type: "radio",
143
- name,
144
- value: "dark",
145
- checked: value === "dark",
146
- onChange: () => onChange("dark")
147
- }
148
- ),
149
- "Dark"
150
- ] })
151
- ] });
152
- }
153
- function AccentColorSettings({
154
- value,
155
- onChange,
156
- name = "accent-color"
157
- }) {
158
- return /* @__PURE__ */ jsxs("fieldset", { className: "db-settings-fieldset", children: [
159
- /* @__PURE__ */ jsx("legend", { className: "db-settings-legend", children: "Accent color" }),
160
- /* @__PURE__ */ jsx("p", { className: "db-settings-hint", children: "Used in both light and dark appearances." }),
161
- /* @__PURE__ */ jsx("div", { className: "db-settings-accent-grid", children: ACCENT_COLORS.map((color) => /* @__PURE__ */ jsxs(
162
- "label",
163
- {
164
- className: `db-settings-accent${value === color ? " db-settings-accent--selected" : ""}`,
165
- children: [
166
- /* @__PURE__ */ jsx(
167
- "input",
168
- {
169
- className: "db-settings-accent-input",
170
- type: "radio",
171
- name,
172
- value: color,
173
- checked: value === color,
174
- onChange: () => onChange(color)
175
- }
176
- ),
177
- /* @__PURE__ */ jsx(
178
- "span",
179
- {
180
- className: `db-settings-accent-swatch db-settings-accent-swatch--${color}`,
181
- "aria-hidden": "true"
182
- }
183
- ),
184
- /* @__PURE__ */ jsx("span", { children: ACCENT_LABELS[color] })
185
- ]
186
- },
187
- color
188
- )) })
189
- ] });
190
- }
191
- function WriteCanvasSettingsControls({ value, onChange }) {
192
- return /* @__PURE__ */ jsxs("fieldset", { className: "db-settings-fieldset", children: [
193
- /* @__PURE__ */ jsx("legend", { className: "db-settings-legend", children: "Write canvas" }),
194
- /* @__PURE__ */ jsx("p", { className: "db-settings-hint", children: "Adjust the writing view without changing the document or its exported text." }),
195
- /* @__PURE__ */ jsxs("label", { className: "db-settings-slider", children: [
196
- /* @__PURE__ */ jsxs("span", { className: "db-settings-slider-header", children: [
197
- /* @__PURE__ */ jsx("span", { children: "Text size" }),
198
- /* @__PURE__ */ jsxs("output", { className: "db-settings-slider-value", "aria-hidden": "true", children: [
199
- value.textSize,
200
- "px"
201
- ] })
202
- ] }),
203
- /* @__PURE__ */ jsx(
204
- "input",
205
- {
206
- type: "range",
207
- min: WRITE_CANVAS_TEXT_SIZE_MIN,
208
- max: WRITE_CANVAS_TEXT_SIZE_MAX,
209
- step: 1,
210
- value: value.textSize,
211
- "aria-label": "Text size",
212
- "aria-valuetext": `${value.textSize} pixels`,
213
- onChange: (event) => onChange({ ...value, textSize: Number(event.currentTarget.value) })
214
- }
215
- )
216
- ] }),
217
- /* @__PURE__ */ jsxs("label", { className: "db-settings-slider", children: [
218
- /* @__PURE__ */ jsxs("span", { className: "db-settings-slider-header", children: [
219
- /* @__PURE__ */ jsx("span", { children: "Line spacing" }),
220
- /* @__PURE__ */ jsx("output", { className: "db-settings-slider-value", "aria-hidden": "true", children: formatLineSpacing(value.lineSpacing) })
221
- ] }),
222
- /* @__PURE__ */ jsx(
223
- "input",
224
- {
225
- type: "range",
226
- min: WRITE_CANVAS_LINE_SPACING_MIN,
227
- max: WRITE_CANVAS_LINE_SPACING_MAX,
228
- step: 0.1,
229
- value: value.lineSpacing,
230
- "aria-label": "Line spacing",
231
- "aria-valuetext": `${value.lineSpacing} times`,
232
- onChange: (event) => onChange({ ...value, lineSpacing: Number(event.currentTarget.value) })
233
- }
234
- )
235
- ] })
236
- ] });
237
- }
238
- function formatLineSpacing(value) {
239
- return `${value.toFixed(1).replace(/\.0$/, "")}\xD7`;
240
- }
241
-
242
- export {
243
- DEFAULT_WRITE_CANVAS_PREFERENCES,
244
- loadWriteCanvasPreferences,
245
- saveWriteCanvasPreferences,
246
- DB_CHROME_COLORS,
247
- loadThemePreference,
248
- saveThemePreference,
249
- loadAccentColor,
250
- saveAccentColor,
251
- SettingsDialog,
252
- ThemeSettings,
253
- AccentColorSettings,
254
- WriteCanvasSettingsControls
255
- };