@honkit/honkit-plugin-fontsettings 6.0.1

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.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
package/README.md ADDED
@@ -0,0 +1,298 @@
1
+ # @honkit-plugin-fontsettings
2
+
3
+ `@honkit/honkit-plugin-fontsettings` is a fork of [Gitbook/plugin-fontsettings]@2.0.0.
4
+
5
+ This plugin adds font settings button in the HonKit website.
6
+
7
+ ### Disable this plugin
8
+
9
+ This is a default plugin and it can be disabled using a `book.json` configuration:
10
+
11
+ ```
12
+ {
13
+ plugins: ["-fontsettings"]
14
+ }
15
+ ```
16
+
17
+ ### Configuration
18
+
19
+ This plugin can be configured in the `book.json`:
20
+
21
+ Default configuration is:
22
+
23
+ ```js
24
+ {
25
+ "pluginsConfig": {
26
+ "fontsettings": {
27
+ "theme": 'white', // 'sepia', 'night' or 'white',
28
+ "family": 'sans', // 'serif' or 'sans',
29
+ "size": 2 // 1 - 4
30
+ }
31
+ }
32
+ }
33
+ ```
34
+
35
+ ### Plugin API
36
+
37
+ This plugin exposes the following API to easily allow new themes to manage the plugin behavior.
38
+
39
+ All API functions are called using the prefix `gitbook.fontsettings.`, for instance `gitbook.fontsettings.enlargeFontSize()`.
40
+
41
+ #### Font manipulation
42
+
43
+ ##### `gitbook.fontsettings.enlargeFontSize()`
44
+
45
+ Increases the font size of the document by one. Max value is `4`.
46
+
47
+ ##### `gitbook.fontsettings.reduceFontSize()`
48
+
49
+ Decreases the font size of the document by one. Min value is `1`.
50
+
51
+ #### Font families
52
+
53
+ Each font family should be described as:
54
+
55
+ ```js
56
+ var fontFamily = {
57
+ config: 'sans', // name of the font family in book.json for your theme
58
+ text: 'Sans', // display name of the font family in menu
59
+ id: 0 // the id appended to the CSS class for this font-family
60
+ };
61
+ ```
62
+
63
+ The `text` property will be used to display the font-family name in the fontsettings dropdown menu.
64
+
65
+ The `config` property allows you to let the users of your theme choose a default font family in their `book.json`. You will have to handle setting the chosen font family in your theme's frontend JavaScript.
66
+
67
+ For instance:
68
+
69
+ ```json
70
+ // book.json
71
+ {
72
+ plugins: ["my-theme"],
73
+ pluginsConfig: {
74
+ "my-theme": {
75
+ "font-family": "sans"
76
+ }
77
+ }
78
+ }
79
+ ```
80
+
81
+ ```js
82
+ // my-theme.js
83
+ require('gitbook', function(gitbook) {
84
+ var FONT_FAMILIES = [
85
+ {
86
+ config: 'sans',
87
+ text: 'Sans',
88
+ id: 0
89
+ },
90
+ {
91
+ config: 'serif',
92
+ text: 'Serif',
93
+ id: 1
94
+ }
95
+ ];
96
+
97
+ gitbook.events.on('start', function(e, config) {
98
+ // Read configuration
99
+ var themeConfig = config['my-theme'],
100
+ defaultFont = themeConfig['font-family'];
101
+
102
+ // Initialize new font families
103
+ gitbook.fontsettings.setFamilies(FONT_FAMILIES);
104
+ // Set to configured font-family
105
+ gitbook.fontsettings.setFamily(defaultFont);
106
+ });
107
+ });
108
+ ```
109
+
110
+ The `id` property lets you define a specific id to use for your CSS rules as explained below.
111
+
112
+ ##### CSS rules
113
+
114
+ The CSS class `font-family-<id>` will be applied to the theme book's root element `<div class="book">` when a font family is selected in the menu.
115
+
116
+ The CSS rules for the font-family can then easily be defined using the parent selector `.book.font-family-<id>`:
117
+
118
+ ```CSS
119
+ .book.font-family-<id> {
120
+ font-family: 'My Awesome Font';
121
+ }
122
+ ```
123
+
124
+ ##### Managing the font families
125
+
126
+ ##### `gitbook.fontsettings.getFamilies()`
127
+
128
+ Returns the currently set font families.
129
+
130
+ By default, the font families are:
131
+
132
+ ```js
133
+ // Default font families
134
+ var FAMILIES = [
135
+ {
136
+ config: 'serif',
137
+ text: 'Serif',
138
+ id: 0
139
+ },
140
+ {
141
+ config: 'sans',
142
+ text: 'Sans',
143
+ id: 1
144
+ }
145
+ ];
146
+ ```
147
+
148
+ ##### `gitbook.fontsettings.setFamilies()`
149
+
150
+ Set the new font families configuration, as an array of font family objects, used by the `plugin-fontsettings` in the form:
151
+
152
+ ```js
153
+ var FONT_FAMILIES = [
154
+ {
155
+ config: 'sans',
156
+ text: 'Sans',
157
+ id: 0
158
+ },
159
+ {
160
+ config: 'serif',
161
+ text: 'Serif',
162
+ id: 1
163
+ }
164
+ ];
165
+
166
+ gitbook.fontsettings.setFamilies(FONT_FAMILIES);
167
+ ```
168
+
169
+ This will recreate the fontsettings menu to reflect the changes.
170
+
171
+ ##### `gitbook.fontsettings.setFamily()`
172
+
173
+ Takes a font-family `config` key as an argument and updates the font-family used for this book.
174
+
175
+ This will basically apply the CSS class with the corresponding family `id`: `.font-family-<id>`.
176
+
177
+ #### Color themes
178
+
179
+ Setting and manipulating color themes follow the exact same rules as font families.
180
+
181
+ Here are the default value for the color themes in the plugin:
182
+
183
+ ```js
184
+ // Default themes
185
+ var THEMES = [
186
+ {
187
+ config: 'white',
188
+ text: 'White',
189
+ id: 0
190
+ },
191
+ {
192
+ config: 'sepia',
193
+ text: 'Sepia',
194
+ id: 1
195
+ },
196
+ {
197
+ config: 'night',
198
+ text: 'Night',
199
+ id: 2
200
+ }
201
+ ];
202
+ ```
203
+
204
+ ##### CSS rules
205
+
206
+ The applied CSS classes for color themes will be in the form: `.color-theme-<id>`.
207
+
208
+ **Caution**: No CSS class for color theme with `id: 0` will be applied. Basically, the first color theme corresponds to your default theme's colors.
209
+
210
+ For instance, using the default color themes:
211
+
212
+ ```js
213
+ gitbook.fontsettings.setTheme('night');
214
+ ```
215
+
216
+ will result in the following HTML state for the root element:
217
+
218
+ ```HTML
219
+ <div class="book color-theme-2">
220
+ ```
221
+
222
+ While:
223
+
224
+ ```js
225
+ gitbook.fontsettings.setTheme('white');
226
+ ```
227
+
228
+ will reset the HTML state for the root element:
229
+
230
+ ```HTML
231
+ <div class="book">
232
+ ```
233
+
234
+ ##### Managing the color themes
235
+
236
+ ##### `gitbook.fontsettings.getFamilies()`
237
+
238
+ Returns the currently set color themes.
239
+
240
+ By default, the font families are:
241
+
242
+ ```js
243
+ // Default themes
244
+ var THEMES = [
245
+ {
246
+ config: 'white',
247
+ text: 'White',
248
+ id: 0
249
+ },
250
+ {
251
+ config: 'sepia',
252
+ text: 'Sepia',
253
+ id: 1
254
+ },
255
+ {
256
+ config: 'night',
257
+ text: 'Night',
258
+ id: 2
259
+ }
260
+ ];
261
+ ```
262
+
263
+ ##### `gitbook.fontsettings.setThemes()`
264
+
265
+ Set the new color themes configuration, as an array of font family objects, used by the `plugin-fontsettings` in the form:
266
+
267
+ ```js
268
+ var COLOR_THEMES = [
269
+ {
270
+ config: 'light',
271
+ text: 'Light',
272
+ id: 0
273
+ },
274
+ {
275
+ config: 'dark',
276
+ text: 'Dark',
277
+ id: 1
278
+ }
279
+ ];
280
+
281
+ gitbook.fontsettings.setThemes(COLOR_THEMES);
282
+ ```
283
+
284
+ This will recreate the fontsettings menu to reflect the changes.
285
+
286
+ ##### `gitbook.fontsettings.setTheme()`
287
+
288
+ Takes a color theme `config` key as an argument and updates the color theme used for this book.
289
+
290
+ This will basically apply the CSS class with the corresponding theme `id`: `.color-theme-<id>`, or remove the applied CSS class if the selected theme `id` is `0`.
291
+
292
+ ## License
293
+
294
+ Apache-2.0 (same as [Gitbook/plugin-fontsettings])
295
+
296
+ [Gitbook/plugin-fontsettings]: https://github.com/GitbookIO/plugin-fontsettings
297
+ [gitbook-tester]: https://github.com/todvora/gitbook-tester
298
+ [honkit-tester]: https://github.com/vowstar/honkit-tester
@@ -0,0 +1,238 @@
1
+ require(["gitbook", "jquery"], (gitbook, $) => {
2
+ // Configuration
3
+ const MAX_SIZE = 4;
4
+ const MIN_SIZE = 0;
5
+ let BUTTON_ID;
6
+
7
+ // Current fontsettings state
8
+ let fontState;
9
+
10
+ // Default themes
11
+ let THEMES = [
12
+ {
13
+ config: "white",
14
+ text: "White",
15
+ id: 0
16
+ },
17
+ {
18
+ config: "sepia",
19
+ text: "Sepia",
20
+ id: 1
21
+ },
22
+ {
23
+ config: "night",
24
+ text: "Night",
25
+ id: 2
26
+ }
27
+ ];
28
+
29
+ // Default font families
30
+ let FAMILIES = [
31
+ {
32
+ config: "serif",
33
+ text: "Serif",
34
+ id: 0
35
+ },
36
+ {
37
+ config: "sans",
38
+ text: "Sans",
39
+ id: 1
40
+ }
41
+ ];
42
+
43
+ // Return configured themes
44
+ function getThemes() {
45
+ return THEMES;
46
+ }
47
+
48
+ // Modify configured themes
49
+ function setThemes(themes) {
50
+ THEMES = themes;
51
+ updateButtons();
52
+ }
53
+
54
+ // Return configured font families
55
+ function getFamilies() {
56
+ return FAMILIES;
57
+ }
58
+
59
+ // Modify configured font families
60
+ function setFamilies(families) {
61
+ FAMILIES = families;
62
+ updateButtons();
63
+ }
64
+
65
+ // Save current font settings
66
+ function saveFontSettings() {
67
+ gitbook.storage.set("fontState", fontState);
68
+ update();
69
+ }
70
+
71
+ // Increase font size
72
+ function enlargeFontSize(e) {
73
+ e.preventDefault();
74
+ if (fontState.size >= MAX_SIZE) return;
75
+
76
+ fontState.size++;
77
+ saveFontSettings();
78
+ }
79
+
80
+ // Decrease font size
81
+ function reduceFontSize(e) {
82
+ e.preventDefault();
83
+ if (fontState.size <= MIN_SIZE) return;
84
+
85
+ fontState.size--;
86
+ saveFontSettings();
87
+ }
88
+
89
+ // Change font family
90
+ function changeFontFamily(configName, e) {
91
+ if (e && e instanceof Event) {
92
+ e.preventDefault();
93
+ }
94
+
95
+ const familyId = getFontFamilyId(configName);
96
+ fontState.family = familyId;
97
+ saveFontSettings();
98
+ }
99
+
100
+ // Change type of color theme
101
+ function changeColorTheme(configName, e) {
102
+ if (e && e instanceof Event) {
103
+ e.preventDefault();
104
+ }
105
+
106
+ const $book = gitbook.state.$book;
107
+
108
+ // Remove currently applied color theme
109
+ if (fontState.theme !== 0) $book.removeClass(`color-theme-${fontState.theme}`);
110
+
111
+ // Set new color theme
112
+ const themeId = getThemeId(configName);
113
+ fontState.theme = themeId;
114
+ if (fontState.theme !== 0) $book.addClass(`color-theme-${fontState.theme}`);
115
+
116
+ saveFontSettings();
117
+ }
118
+
119
+ // Return the correct id for a font-family config key
120
+ // Default to first font-family
121
+ function getFontFamilyId(configName) {
122
+ // Search for plugin configured font family
123
+ const configFamily = $.grep(FAMILIES, (family) => {
124
+ return family.config == configName;
125
+ })[0];
126
+
127
+ // Fallback to default font family
128
+ return (configFamily && configFamily.id) || 0;
129
+ }
130
+
131
+ // Return the correct id for a theme config key
132
+ // Default to first theme
133
+ function getThemeId(configName) {
134
+ // Search for plugin configured theme
135
+ const configTheme = $.grep(THEMES, (theme) => {
136
+ return theme.config == configName;
137
+ })[0];
138
+
139
+ // Fallback to default theme
140
+ return (configTheme && configTheme.id) || 0;
141
+ }
142
+
143
+ function update() {
144
+ const $book = gitbook.state.$book;
145
+
146
+ $(".font-settings .font-family-list li").removeClass("active");
147
+ $(`.font-settings .font-family-list li:nth-child(${fontState.family + 1})`).addClass("active");
148
+
149
+ $book[0].className = $book[0].className.replace(/\bfont-\S+/g, "");
150
+ $book.addClass(`font-size-${fontState.size}`);
151
+ $book.addClass(`font-family-${fontState.family}`);
152
+
153
+ if (fontState.theme !== 0) {
154
+ $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, "");
155
+ $book.addClass(`color-theme-${fontState.theme}`);
156
+ }
157
+ }
158
+
159
+ function init(config) {
160
+ // Search for plugin configured font family
161
+ const configFamily = getFontFamilyId(config.family);
162
+ const configTheme = getThemeId(config.theme);
163
+
164
+ // Instantiate font state object
165
+ fontState = gitbook.storage.get("fontState", {
166
+ size: config.size || 2,
167
+ family: configFamily,
168
+ theme: configTheme
169
+ });
170
+
171
+ update();
172
+ }
173
+
174
+ function updateButtons() {
175
+ // Remove existing fontsettings buttons
176
+ if (BUTTON_ID) {
177
+ gitbook.toolbar.removeButton(BUTTON_ID);
178
+ }
179
+
180
+ // Create buttons in toolbar
181
+ BUTTON_ID = gitbook.toolbar.createButton({
182
+ icon: "fa fa-font",
183
+ label: "Font Settings",
184
+ className: "font-settings",
185
+ dropdown: [
186
+ [
187
+ {
188
+ text: "A",
189
+ className: "font-reduce",
190
+ onClick: reduceFontSize
191
+ },
192
+ {
193
+ text: "A",
194
+ className: "font-enlarge",
195
+ onClick: enlargeFontSize
196
+ }
197
+ ],
198
+ $.map(FAMILIES, (family) => {
199
+ family.onClick = function (e) {
200
+ return changeFontFamily(family.config, e);
201
+ };
202
+
203
+ return family;
204
+ }),
205
+ $.map(THEMES, (theme) => {
206
+ theme.onClick = function (e) {
207
+ return changeColorTheme(theme.config, e);
208
+ };
209
+
210
+ return theme;
211
+ })
212
+ ]
213
+ });
214
+ }
215
+
216
+ // Init configuration at start
217
+ gitbook.events.bind("start", (e, config) => {
218
+ const opts = config.fontsettings;
219
+
220
+ // Generate buttons at start
221
+ updateButtons();
222
+
223
+ // Init current settings
224
+ init(opts);
225
+ });
226
+
227
+ // Expose API
228
+ gitbook.fontsettings = {
229
+ enlargeFontSize: enlargeFontSize,
230
+ reduceFontSize: reduceFontSize,
231
+ setTheme: changeColorTheme,
232
+ setFamily: changeFontFamily,
233
+ getThemes: getThemes,
234
+ setThemes: setThemes,
235
+ getFamilies: getFamilies,
236
+ setFamilies: setFamilies
237
+ };
238
+ });
@@ -0,0 +1,309 @@
1
+ /*
2
+ * Theme 1
3
+ */
4
+ .color-theme-1 .dropdown-menu {
5
+ background-color: #111;
6
+ border-color: hsl(194, 5%, 52%);
7
+ }
8
+ .color-theme-1 .dropdown-menu .dropdown-caret .caret-inner {
9
+ border-bottom: 9px solid #111;
10
+ }
11
+ .color-theme-1 .dropdown-menu .buttons {
12
+ border-color: hsl(194, 5%, 52%);
13
+ }
14
+ .color-theme-1 .dropdown-menu .button {
15
+ color: #AFA790;
16
+ }
17
+ .color-theme-1 .dropdown-menu .button:hover {
18
+ color: #73553C;
19
+ }
20
+ /*
21
+ * Theme 2
22
+ */
23
+ .color-theme-2 .dropdown-menu {
24
+ background-color: hsl(229, 20%, 22%);
25
+ border-color: hsl(230, 19%, 19%);
26
+ }
27
+ .color-theme-2 .dropdown-menu .dropdown-caret .caret-inner {
28
+ border-bottom: 9px solid hsl(229, 20%, 22%);
29
+ }
30
+ .color-theme-2 .dropdown-menu .buttons {
31
+ border-color: hsl(230, 19%, 19%);
32
+ }
33
+ .color-theme-2 .dropdown-menu .button {
34
+ color: hsl(228, 13%, 44%);
35
+ }
36
+ .color-theme-2 .dropdown-menu .button:hover {
37
+ color: hsl(240, 5%, 96%);
38
+ }
39
+ .book .book-header .font-settings .font-enlarge {
40
+ line-height: 30px;
41
+ font-size: 1.4em;
42
+ }
43
+ .book .book-header .font-settings .font-reduce {
44
+ line-height: 30px;
45
+ font-size: 1em;
46
+ }
47
+ .book.color-theme-1 .book-body {
48
+ color: #704214;
49
+ background: #F3EACB;
50
+ }
51
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section {
52
+ background: #F3EACB;
53
+ }
54
+ .book.color-theme-1 #book-search-input {
55
+ background: transparent;
56
+ }
57
+ .book.color-theme-1 #book-search-results .search-results .has-results .search-results-item {
58
+ color: #b16820;
59
+ }
60
+ .book.color-theme-2 .book-body {
61
+ color: hsl(214, 29%, 80%);
62
+ background: hsl(228, 21%, 14%);
63
+ }
64
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section {
65
+ background: hsl(228, 21%, 14%);
66
+ }
67
+ .book.color-theme-2 #book-search-input {
68
+ background: transparent;
69
+ }
70
+ .book.color-theme-2 #book-search-results .search-results .has-results .search-results-item {
71
+ color: hsl(214, 29%, 65%);
72
+ }
73
+ .book.font-size-0 .book-body .page-inner section {
74
+ font-size: 1.2rem;
75
+ }
76
+ .book.font-size-1 .book-body .page-inner section {
77
+ font-size: 1.4rem;
78
+ }
79
+ .book.font-size-2 .book-body .page-inner section {
80
+ font-size: 1.6rem;
81
+ }
82
+ .book.font-size-3 .book-body .page-inner section {
83
+ font-size: 2.2rem;
84
+ }
85
+ .book.font-size-4 .book-body .page-inner section {
86
+ font-size: 4rem;
87
+ }
88
+ .book.font-family-0 {
89
+ font-family: Georgia, serif;
90
+ }
91
+ .book.font-family-1 {
92
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
93
+ }
94
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal {
95
+ color: #704214;
96
+ }
97
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal a {
98
+ color: inherit;
99
+ }
100
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1,
101
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2,
102
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h3,
103
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h4,
104
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h5,
105
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 {
106
+ color: inherit;
107
+ }
108
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1,
109
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2 {
110
+ border-color: inherit;
111
+ }
112
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 {
113
+ color: inherit;
114
+ }
115
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal hr {
116
+ background-color: inherit;
117
+ }
118
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal blockquote {
119
+ border-color: inherit;
120
+ }
121
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal pre,
122
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal code {
123
+ background: #fdf6e3;
124
+ color: #657b83;
125
+ border-color: #f8df9c;
126
+ }
127
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal .highlight {
128
+ background-color: inherit;
129
+ }
130
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table th,
131
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table td {
132
+ border-color: #f5d06c;
133
+ }
134
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr {
135
+ color: inherit;
136
+ background-color: #fdf6e3;
137
+ border-color: #444;
138
+ }
139
+ .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) {
140
+ background-color: #fbeecb;
141
+ }
142
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal {
143
+ color: hsl(214, 29%, 80%);
144
+ }
145
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal a {
146
+ color: hsl(193, 61%, 53%);
147
+ }
148
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1,
149
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2,
150
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h3,
151
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h4,
152
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h5,
153
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 {
154
+ color: hsl(60, 100%, 99%);
155
+ }
156
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1,
157
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2 {
158
+ border-color: hsl(230, 17%, 26%);
159
+ }
160
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 {
161
+ color: hsl(230, 17%, 26%);
162
+ }
163
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal hr {
164
+ background-color: hsl(230, 17%, 26%);
165
+ }
166
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal blockquote {
167
+ border-color: hsl(230, 17%, 26%);
168
+ }
169
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal pre,
170
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal code {
171
+ color: hsl(206, 43%, 73%);
172
+ background: hsl(229, 20%, 22%);
173
+ border-color: hsl(229, 20%, 22%);
174
+ }
175
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal .highlight {
176
+ background-color: hsl(233, 18%, 19%);
177
+ }
178
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table th,
179
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table td {
180
+ border-color: hsl(230, 17%, 28%);
181
+ }
182
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr {
183
+ color: hsl(216, 24%, 77%);
184
+ background-color: hsl(229, 19%, 22%);
185
+ border-color: hsl(230, 17%, 28%);
186
+ }
187
+ .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) {
188
+ background-color: hsl(229, 17%, 25%);
189
+ }
190
+ .book.color-theme-1 .book-header {
191
+ color: #AFA790;
192
+ background: transparent;
193
+ }
194
+ .book.color-theme-1 .book-header .btn {
195
+ color: #AFA790;
196
+ }
197
+ .book.color-theme-1 .book-header .btn:hover {
198
+ color: #73553C;
199
+ background: none;
200
+ }
201
+ .book.color-theme-1 .book-header h1 {
202
+ color: #704214;
203
+ }
204
+ .book.color-theme-2 .book-header {
205
+ color: #7e888b;
206
+ background: transparent;
207
+ }
208
+ .book.color-theme-2 .book-header .btn {
209
+ color: hsl(230, 17%, 28%);
210
+ }
211
+ .book.color-theme-2 .book-header .btn:hover {
212
+ color: hsl(60, 100%, 98%);
213
+ background: none;
214
+ }
215
+ .book.color-theme-2 .book-header h1 {
216
+ color: hsl(214, 29%, 80%);
217
+ }
218
+ .book.color-theme-1 .book-body .navigation {
219
+ color: #AFA790;
220
+ }
221
+ .book.color-theme-1 .book-body .navigation:hover {
222
+ color: #73553C;
223
+ }
224
+ .book.color-theme-2 .book-body .navigation {
225
+ color: hsl(224, 19%, 27%);
226
+ }
227
+ .book.color-theme-2 .book-body .navigation:hover {
228
+ color: hsl(60, 100%, 98%);
229
+ }
230
+ /*
231
+ * Theme 1
232
+ */
233
+ .book.color-theme-1 .book-summary {
234
+ color: #AFA790;
235
+ background: #111;
236
+ border-right: 1px solid rgba(0, 0, 0, 0.07);
237
+ }
238
+ .book.color-theme-1 .book-summary .book-search,
239
+ .book.color-theme-1 .book-summary #book-search-input {
240
+ background: transparent;
241
+ }
242
+ .book.color-theme-1 .book-summary .book-search input,
243
+ .book.color-theme-1 .book-summary #book-search-input input,
244
+ .book.color-theme-1 .book-summary .book-search input:focus,
245
+ .book.color-theme-1 .book-summary #book-search-input input:focus {
246
+ border: 1px solid transparent;
247
+ }
248
+ .book.color-theme-1 .book-summary ul.summary li.divider {
249
+ background: hsl(194, 5%, 52%);
250
+ box-shadow: none;
251
+ }
252
+ .book.color-theme-1 .book-summary ul.summary li i.fa-check {
253
+ color: hsl(120, 60%, 50%);
254
+ }
255
+ .book.color-theme-1 .book-summary ul.summary li.done > a {
256
+ color: #877F6A;
257
+ }
258
+ .book.color-theme-1 .book-summary ul.summary li a,
259
+ .book.color-theme-1 .book-summary ul.summary li span {
260
+ color: #877F6A;
261
+ background: transparent;
262
+ font-weight: normal;
263
+ }
264
+ .book.color-theme-1 .book-summary ul.summary li.active > a,
265
+ .book.color-theme-1 .book-summary ul.summary li a:hover {
266
+ color: #704214;
267
+ background: transparent;
268
+ font-weight: normal;
269
+ }
270
+ /*
271
+ * Theme 2
272
+ */
273
+ .book.color-theme-2 .book-summary {
274
+ color: hsl(226, 20%, 78%);
275
+ background: hsl(229, 20%, 22%);
276
+ border-right: none;
277
+ }
278
+ .book.color-theme-2 .book-summary .book-search,
279
+ .book.color-theme-2 .book-summary #book-search-input {
280
+ background: transparent;
281
+ }
282
+ .book.color-theme-2 .book-summary .book-search input,
283
+ .book.color-theme-2 .book-summary #book-search-input input,
284
+ .book.color-theme-2 .book-summary .book-search input:focus,
285
+ .book.color-theme-2 .book-summary #book-search-input input:focus {
286
+ border: 1px solid transparent;
287
+ }
288
+ .book.color-theme-2 .book-summary ul.summary li.divider {
289
+ background: hsl(230, 19%, 19%);
290
+ box-shadow: none;
291
+ }
292
+ .book.color-theme-2 .book-summary ul.summary li i.fa-check {
293
+ color: hsl(120, 60%, 50%);
294
+ }
295
+ .book.color-theme-2 .book-summary ul.summary li.done > a {
296
+ color: hsl(227, 13%, 44%);
297
+ }
298
+ .book.color-theme-2 .book-summary ul.summary li a,
299
+ .book.color-theme-2 .book-summary ul.summary li span {
300
+ color: hsl(226, 22%, 80%);
301
+ background: transparent;
302
+ font-weight: 600;
303
+ }
304
+ .book.color-theme-2 .book-summary ul.summary li.active > a,
305
+ .book.color-theme-2 .book-summary ul.summary li a:hover {
306
+ color: hsl(240, 5%, 96%);
307
+ background: hsl(233, 19%, 18%);
308
+ font-weight: 600;
309
+ }
@@ -0,0 +1,45 @@
1
+ import globals from 'globals';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import js from '@eslint/js';
5
+ import { FlatCompat } from '@eslint/eslintrc';
6
+ import stylisticJs from '@stylistic/eslint-plugin-js';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+ const compat = new FlatCompat({
11
+ baseDirectory: __dirname,
12
+ recommendedConfig: js.configs.recommended,
13
+ allConfig: js.configs.all
14
+ });
15
+
16
+ export default [...compat.extends('eslint:recommended'), {
17
+ plugins: {
18
+ '@stylistic/js': stylisticJs,
19
+ },
20
+ languageOptions: {
21
+ globals: {
22
+ ...globals.node,
23
+ ...globals.mocha,
24
+ ...globals.browser,
25
+ },
26
+ },
27
+
28
+ rules: {
29
+ '@stylistic/js/indent': [2, 4],
30
+ '@stylistic/js/quotes': [2, 'single'],
31
+ 'linebreak-style': [2, 'unix'],
32
+ semi: [2, 'always'],
33
+
34
+ 'no-unused-vars': [2, {
35
+ vars: 'all',
36
+ args: 'none',
37
+ }],
38
+
39
+ 'spaced-comment': [2, 'always'],
40
+ 'no-var': 'error',
41
+ 'prefer-arrow-callback': 'error',
42
+ 'prefer-const': 'error',
43
+ 'prefer-template': 'error',
44
+ },
45
+ }];
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ book: {
3
+ assets: "./assets",
4
+ js: ["fontsettings.js"],
5
+ css: ["website.css"]
6
+ }
7
+ };
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@honkit/honkit-plugin-fontsettings",
3
+ "description": "Fonts and colors themes settings the website for a better reading experience",
4
+ "main": "index.js",
5
+ "version": "6.0.1",
6
+ "license": "Apache-2.0",
7
+ "homepage": "https://github.com/honkit/honkit",
8
+ "engines": {
9
+ "gitbook": ">=2.4.0"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/honkit/honkit.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/honkit/honkit/issues"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "devDependencies": {
22
+ "@eslint/eslintrc": "^3.1.0",
23
+ "@eslint/js": "^9.12.0",
24
+ "eslint": "^9.12.0",
25
+ "globals": "^15.0.0",
26
+ "less": "^4.2.0"
27
+ },
28
+ "scripts": {
29
+ "build": "npm run build:css --scripts-prepend-node-path",
30
+ "build:css": "lessc ./less/website.less ./assets/website.css",
31
+ "prepublish": "npm run build",
32
+ "lint": "eslint ."
33
+ },
34
+ "gitbook": {
35
+ "properties": {
36
+ "theme": {
37
+ "type": "string",
38
+ "default": "white",
39
+ "title": "Default theme",
40
+ "enum": [
41
+ "white",
42
+ "sepia",
43
+ "night"
44
+ ]
45
+ },
46
+ "family": {
47
+ "type": "string",
48
+ "default": "sans",
49
+ "title": "Default font family",
50
+ "enum": [
51
+ "sans",
52
+ "serif"
53
+ ]
54
+ },
55
+ "size": {
56
+ "type": "number",
57
+ "default": 2,
58
+ "title": "Default font size",
59
+ "min": 1,
60
+ "max": 4
61
+ }
62
+ }
63
+ },
64
+ "gitHead": "8a67601b23ce480bce2bd1a8fb787f1f6f56656f"
65
+ }