Skip to content

Commit ae7825c

Browse files
committed
feat: allow extraction of css to external files
1 parent 624b8c5 commit ae7825c

8 files changed

Lines changed: 207 additions & 103 deletions

File tree

package-lock.json

Lines changed: 77 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"axios": "^0.21.4",
5959
"luxon": "^1.28.0",
6060
"popper.js": "^1.16.1",
61+
"rollup-plugin-import-css": "^3.2.1",
6162
"showdown": "^2.0.0",
6263
"simpletoast": "github:feildmaster/SimpleToast",
6364
"tippy.js": "^4.3.5"

rollup.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const { nodeResolve } = require('@rollup/plugin-node-resolve');
55
const cleanup = require('rollup-plugin-cleanup');
66
const multi = require('@rollup/plugin-multi-entry');
77
const externals = require('rollup-plugin-external-globals');
8+
const css = require('rollup-plugin-import-css');
9+
810
const { version } = require('./package.json');
911

1012
const debug = process.argv.includes('--configDebug');
@@ -64,6 +66,7 @@ module.exports = [{
6466
external: ['luxon', 'showdown', 'axios', 'tippy.js'],
6567
plugins: [
6668
nodeResolve({ browser: true }),
69+
css(),
6770
multi({
6871
exports: false,
6972
}),

src/base/updates.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ wrap(() => {
9797
latest.set(data);
9898
if (updateToast) updateToast.close('stale');
9999
const path = `underscript@${data.version}/${data.unpkg}`;
100-
const css = {
100+
const baseStyle = {
101101
border: '',
102102
height: '',
103103
background: '',
@@ -112,19 +112,19 @@ wrap(() => {
112112
buttons: [{
113113
text: 'Update (github)',
114114
className: 'dismiss',
115-
css,
115+
css: baseStyle,
116116
}, {
117117
text: 'Update (unpkg)',
118118
className: 'dismiss',
119-
css,
119+
css: baseStyle,
120120
onclick(e) {
121121
location.href = `${baseURL}/${path}`;
122122
this.close('update');
123123
},
124124
}, {
125125
text: 'Update (jsdelivr)',
126126
className: 'dismiss',
127-
css,
127+
css: baseStyle,
128128
onclick: (e) => {
129129
location.href = `https://cdn.jsdelivr.net/npm/${path}`;
130130
this.close('update');

src/utils/css.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
export default function css(strings = [], ...values) {
22
const evaluated = strings.reduce((acc, string, i) => {
3-
acc.push(string
4-
.trimStart()
5-
// .replace(/[ ]{2}/g, ' ')
6-
// trim " }" and " \n"
7-
.replace(/^[ ]+(?<last>[\n}])/gm, '$<last>')
8-
// trim " *"
9-
.replace(/(?:^|})\n+[ ]{1,2}(?<last>[^ /])/gm, '}\n\n$<last>'));
3+
if (string) {
4+
acc.push(string
5+
.trimStart()
6+
// .replace(/[ ]{2}/g, ' ')
7+
// trim " }" and " \n"
8+
.replace(/^[ ]+(?<last>[\n}])/gm, '$<last>')
9+
// trim " *"
10+
.replace(/(?:^|})\n+[ ]{1,2}(?<last>[^ /])/gm, '}\n\n$<last>'));
11+
}
1012
const value = values[i];
1113
if (value) acc.push(value.toString());
1214
return acc;

src/utils/settings/RegisteredSetting.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,33 @@ import SettingType from './types/setting.js';
44
export default class RegisteredSetting {
55
/** @type {string} */
66
#key;
7-
/** @type {string} */
7+
/** @type {string | function(): string} */
88
#name;
99
/** @type {SettingType} */
1010
#type;
1111
/** @type {string} (or plugin) */
1212
#page;
1313
/** @type {string} */
1414
#category;
15-
/** @type {any} */
1615
#default;
17-
/** @type {boolean | Function} */
16+
/** @type {boolean | null | function(): boolean?} */
1817
#disabled;
19-
/** @type {boolean | Function} */
18+
/** @type {boolean | null | function(): boolean?} */
2019
#hidden;
21-
/** @type {boolean | Function} */
20+
/** @type {boolean | null | function(): boolean?} */
2221
#remove;
23-
/** @type {boolean | Function} */
22+
/** @type {boolean | null | function(): boolean?} */
2423
#export;
25-
/** @type {string} */
24+
/** @type {string?} */
2625
#prefix;
27-
/** @type {boolean | Function} */
26+
/** @type {boolean | null | function(): boolean?} */
2827
#reset;
2928
#data;
30-
/** @type {string | Function} */
29+
/** @type {string | null | function(): string?} */
3130
#note;
32-
/** @type {boolean | Function} */
31+
/** @type {boolean | null | function(): boolean?} */
3332
#refresh;
34-
/** @type {Function} */
33+
/** @type {function(any, any): never} */
3534
#onChange;
3635
/** @type {EventEmitter} */
3736
#events;
@@ -83,8 +82,11 @@ export default class RegisteredSetting {
8382
return this.#key;
8483
}
8584

85+
/**
86+
* @returns {string}
87+
*/
8688
get name() {
87-
return this.#name;
89+
return this.#value(this.#name);
8890
}
8991

9092
get type() {
@@ -123,15 +125,18 @@ export default class RegisteredSetting {
123125
return this.#value(this.#reset) === true;
124126
}
125127

128+
/**
129+
* @returns {unknown}
130+
*/
126131
get data() {
127-
return this.#data;
132+
return this.#value(this.#data);
128133
}
129134

130135
get note() {
131136
const notes = [];
132137

133138
const note = this.#value(this.#note);
134-
if (note) {
139+
if (typeof note === 'string') {
135140
notes.push(note);
136141
}
137142

@@ -161,6 +166,10 @@ export default class RegisteredSetting {
161166
this.#events.emit('setting:change', key, val, prev);
162167
}
163168

169+
set value(val) {
170+
this.update(val);
171+
}
172+
164173
get value() {
165174
const val = localStorage.getItem(this.key);
166175
if (!val) {
@@ -169,6 +178,9 @@ export default class RegisteredSetting {
169178
return this.type.value(val);
170179
}
171180

181+
/**
182+
* @returns {unknown}
183+
*/
172184
get default() {
173185
const val = this.#default;
174186
if (val !== undefined) {

0 commit comments

Comments
 (0)