diff options
author | MetroWind <chris.corsair@gmail.com> | 2025-09-27 13:05:27 -0700 |
---|---|---|
committer | MetroWind <chris.corsair@gmail.com> | 2025-09-27 13:05:27 -0700 |
commit | 81b539d6a63dd4921686fb50f05daf1b1d725e3b (patch) | |
tree | 5d6d832d73f7f946ebf40924221ffcda980f9837 /button-maker/scripts/lib.js | |
parent | 925b5fcea3b85df08eea6574caf76639018a1937 (diff) |
Add button maker. Support basic editing.
Diffstat (limited to 'button-maker/scripts/lib.js')
-rw-r--r-- | button-maker/scripts/lib.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/button-maker/scripts/lib.js b/button-maker/scripts/lib.js new file mode 100644 index 0000000..372d9d7 --- /dev/null +++ b/button-maker/scripts/lib.js | |||
@@ -0,0 +1,79 @@ | |||
1 | // In Firefox (on Mac only?), for <input type="color">, setting value | ||
2 | // to abbreviated hex form (e.g. #123) doesn’t work. So all colors | ||
3 | // should be specified in full form. | ||
4 | const DEFAULT_NETSCAPE_PARAMS = { | ||
5 | color_bg: "#c0c0c0", | ||
6 | logo_url: "https://upload.wikimedia.org/wikipedia/commons/0/08/Netscape_icon.svg", | ||
7 | text_top: { | ||
8 | content: "Netscape", | ||
9 | pos: [31, 11], | ||
10 | font_size: 10.5, | ||
11 | color: "#000000", | ||
12 | }, | ||
13 | text_bottom: { | ||
14 | content: "Now!", | ||
15 | pos: [30, 28], | ||
16 | font_size: 17.5, | ||
17 | color: "#ff0000", | ||
18 | }, | ||
19 | banner: { | ||
20 | style: "corner_bottom_right", // corner_bottom_right or right | ||
21 | color: "#008080", | ||
22 | text: { | ||
23 | content: "5.0", | ||
24 | pos: [65, 46], | ||
25 | font_size: 8, | ||
26 | color: "#ffffff", | ||
27 | }, | ||
28 | }, | ||
29 | }; | ||
30 | |||
31 | const DEFAULT_APP_STATE = { | ||
32 | button_type: "netscape", | ||
33 | button_params: DEFAULT_NETSCAPE_PARAMS, | ||
34 | } | ||
35 | |||
36 | const SVG_ATTRIBUTES = {viewBox: "0 0 88 31", width: 88, height: 31}; | ||
37 | |||
38 | // Return three integers as an array. | ||
39 | function parseHexColor(color_str) | ||
40 | { | ||
41 | console.debug("Parsing", color_str); | ||
42 | m = color_str.match(/^#([0-9a-f]{3})$/i); | ||
43 | if(m) | ||
44 | { | ||
45 | // in three-character format, each value is multiplied by 0x11 to give an | ||
46 | // even scale from 0x00 to 0xff | ||
47 | return [ | ||
48 | parseInt(m[1].charAt(0),16)*0x11, | ||
49 | parseInt(m[1].charAt(1),16)*0x11, | ||
50 | parseInt(m[1].charAt(2),16)*0x11 | ||
51 | ]; | ||
52 | } | ||
53 | |||
54 | m = color_str.match(/^#([0-9a-f]{6})$/i); | ||
55 | if(m) | ||
56 | { | ||
57 | return [ | ||
58 | parseInt(m[1].substr(0,2),16), | ||
59 | parseInt(m[1].substr(2,2),16), | ||
60 | parseInt(m[1].substr(4,2),16) | ||
61 | ]; | ||
62 | } | ||
63 | return null; | ||
64 | } | ||
65 | |||
66 | function lighten(rgb, delta) | ||
67 | { | ||
68 | return [rgb[0] + delta, rgb[1] + delta, rgb[2] + delta]; | ||
69 | } | ||
70 | |||
71 | function darken(rgb, delta) | ||
72 | { | ||
73 | return [rgb[0] - delta, rgb[1] - delta, rgb[2] - delta]; | ||
74 | } | ||
75 | |||
76 | function color2Str(color) | ||
77 | { | ||
78 | return `rgb(${color[0]} ${color[1]} ${color[2]})`; | ||
79 | } | ||