Skip to content

Commit 8750724

Browse files
authored
Merge pull request #140 from arrowtype/sn-simoncozens-slider-fix
Merge slider fix with fontkit fix
2 parents 0abdd94 + 7722576 commit 8750724

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

dist/popup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<label class="all-caps">Elements</label>
115115
<textarea rows="1" name="selectors"></textarea>
116116
<label class="all-caps">CSS Styles</label>
117-
<textarea rows="3" name="css"></textarea>
117+
<textarea rows="3" name="css">/* Your styles here! */</textarea>
118118
<div class="additional-button-container">
119119
<button type="button" class="all-caps show-fallbacks">
120120
Fallback fonts...

dist/popup.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/form.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getFiles
1010
} from "./font";
1111
import { callTypeX, showReloadAnimation } from "./popup";
12+
import { defaultFonts } from "./recursive-fonts.js";
1213

1314
const localFonts: Record<string, FontFile> = {};
1415

@@ -308,6 +309,7 @@ async function getFont(id: string): Promise<Font | null> {
308309
console.error("Couldn't find font with ID", id);
309310
return null;
310311
}
312+
await updateFont(font);
311313
return font;
312314
}
313315

@@ -324,6 +326,11 @@ async function applyNamedInstance(e: Event) {
324326

325327
font.inherit = sel.value == "--inherit--";
326328

329+
sliders.querySelectorAll(".variable-slider").forEach(slider => {
330+
let input = slider.querySelector("input");
331+
input.disabled = font.inherit;
332+
});
333+
327334
if (font.inherit) {
328335
sliders.classList.add("mute");
329336
await updateFont(font);
@@ -357,6 +364,10 @@ async function addVariableSliders(font: Font, el: HTMLElement) {
357364
}
358365
container.classList.add("show");
359366
}
367+
// If we start with inherit, we start muted
368+
if (font.inherit) {
369+
container.classList.add("mute");
370+
}
360371
}
361372

362373
function addSlider(font: Font, axis: Axis, parent: HTMLElement) {
@@ -369,6 +380,8 @@ function addSlider(font: Font, axis: Axis, parent: HTMLElement) {
369380
const label: HTMLLabelElement = el.querySelector("label");
370381
const value: HTMLSpanElement = el.querySelector(".slider-value");
371382

383+
input.disabled = font.inherit;
384+
372385
label.innerText = axis.name;
373386

374387
input.name = `var-${axis.id}`;
@@ -415,7 +428,24 @@ function unhighlight(e: Event) {
415428
e.stopPropagation();
416429
}
417430

431+
async function setStorageKeyIfNotFound(key: string, defaultValue: Font[]) {
432+
try {
433+
const result = await chrome.storage.local.get(key);
434+
if (result[key] === undefined) {
435+
// Value not found, set it
436+
await chrome.storage.local.set({ [key]: defaultValue });
437+
console.log(`${key} set to:`, defaultValue);
438+
} else {
439+
// Value already exists
440+
console.log(`${key} already exists with value:`, result[key]);
441+
}
442+
} catch (error) {
443+
console.error("Error accessing chrome.storage.local:", error);
444+
}
445+
}
446+
418447
async function updateFont(font: Font) {
448+
setStorageKeyIfNotFound("fonts", defaultFonts);
419449
let { fonts } = await chrome.storage.local.get("fonts");
420450
let fontId = font.id;
421451
fonts = fonts.map((f: Font) => (f.id === fontId ? font : f));

src/recursive-fonts.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)