mirror of
https://github.com/kognise/water.css.git
synced 2025-08-09 14:47:08 +02:00
Add Standard linting and fix problems
This commit is contained in:
20
gulpfile.js
20
gulpfile.js
@@ -15,22 +15,22 @@ const postcssImport = require('postcss-import')
|
|||||||
const postcssInlineSvg = require('postcss-inline-svg')
|
const postcssInlineSvg = require('postcss-inline-svg')
|
||||||
const postcssColorModFunction = require('postcss-color-mod-function').bind(null, {
|
const postcssColorModFunction = require('postcss-color-mod-function').bind(null, {
|
||||||
/* Use `.toRGBLegacy()` as other methods can result in lots of decimals */
|
/* Use `.toRGBLegacy()` as other methods can result in lots of decimals */
|
||||||
stringifier: color => color.toRGBLegacy(),
|
stringifier: color => color.toRGBLegacy()
|
||||||
})
|
})
|
||||||
|
|
||||||
const paths = {
|
const paths = {
|
||||||
srcDir: 'src/*',
|
srcDir: 'src/*',
|
||||||
docsDir: '*',
|
docsDir: '*',
|
||||||
styles: { src: 'src/builds/*.css', dest: 'dist' },
|
styles: { src: 'src/builds/*.css', dest: 'dist' }
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/a/20732091
|
// https://stackoverflow.com/a/20732091
|
||||||
function humanFileSize(size) {
|
function humanFileSize (size) {
|
||||||
var i = Math.floor(Math.log(size) / Math.log(1024))
|
var i = Math.floor(Math.log(size) / Math.log(1024))
|
||||||
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]
|
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatByteMessage(source, data) {
|
function formatByteMessage (source, data) {
|
||||||
const prettyStartSize = humanFileSize(data.startSize)
|
const prettyStartSize = humanFileSize(data.startSize)
|
||||||
let message = ''
|
let message = ''
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ function formatByteMessage(source, data) {
|
|||||||
return chalk`{cyan ${source.padStart(12, ' ')}}: {bold ${data.fileName}} ${message}`
|
return chalk`{cyan ${source.padStart(12, ' ')}}: {bold ${data.fileName}} ${message}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function style() {
|
function style () {
|
||||||
const isLegacy = path => /legacy/.test(path)
|
const isLegacy = path => /legacy/.test(path)
|
||||||
|
|
||||||
const excludeModern = filter(file => isLegacy(file.path), { restore: true })
|
const excludeModern = filter(file => isLegacy(file.path), { restore: true })
|
||||||
@@ -70,7 +70,7 @@ function style() {
|
|||||||
.pipe(bytediff.start())
|
.pipe(bytediff.start())
|
||||||
// autoprefix
|
// autoprefix
|
||||||
.pipe(postcss([autoprefixer({
|
.pipe(postcss([autoprefixer({
|
||||||
env: "legacy"
|
env: 'legacy'
|
||||||
})]))
|
})]))
|
||||||
// Write the amount gained by autoprefixing
|
// Write the amount gained by autoprefixing
|
||||||
.pipe(bytediff.stop(data => formatByteMessage('autoprefixer', data)))
|
.pipe(bytediff.stop(data => formatByteMessage('autoprefixer', data)))
|
||||||
@@ -82,7 +82,7 @@ function style() {
|
|||||||
.pipe(bytediff.start())
|
.pipe(bytediff.start())
|
||||||
// autoprefix modern builds
|
// autoprefix modern builds
|
||||||
.pipe(postcss([autoprefixer({
|
.pipe(postcss([autoprefixer({
|
||||||
env: "modern"
|
env: 'modern'
|
||||||
})]))
|
})]))
|
||||||
// Write the amount gained by autoprefixing
|
// Write the amount gained by autoprefixing
|
||||||
.pipe(bytediff.stop(data => formatByteMessage('autoprefixer', data)))
|
.pipe(bytediff.stop(data => formatByteMessage('autoprefixer', data)))
|
||||||
@@ -114,14 +114,14 @@ function style() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function watch() {
|
function watch () {
|
||||||
style()
|
style()
|
||||||
|
|
||||||
browserSync.init({
|
browserSync.init({
|
||||||
server: {
|
server: {
|
||||||
baseDir: './',
|
baseDir: './'
|
||||||
},
|
},
|
||||||
startPath: 'index.html',
|
startPath: 'index.html'
|
||||||
})
|
})
|
||||||
|
|
||||||
gulp.watch(paths.srcDir, style)
|
gulp.watch(paths.srcDir, style)
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "gulp style",
|
"build": "gulp style",
|
||||||
"dev": "gulp watch",
|
"dev": "gulp watch",
|
||||||
|
"lint": "standard --fix",
|
||||||
"prepublishOnly": "yarn build"
|
"prepublishOnly": "yarn build"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
85
script.js
85
script.js
@@ -1,4 +1,6 @@
|
|||||||
!(function() {
|
/* global matchMedia, faviconModeSwitcher */
|
||||||
|
|
||||||
|
(function () {
|
||||||
const iconModeSwitcher = window.faviconModeSwitcher && faviconModeSwitcher.default
|
const iconModeSwitcher = window.faviconModeSwitcher && faviconModeSwitcher.default
|
||||||
if (!iconModeSwitcher) return
|
if (!iconModeSwitcher) return
|
||||||
iconModeSwitcher([
|
iconModeSwitcher([
|
||||||
@@ -16,99 +18,100 @@
|
|||||||
}
|
}
|
||||||
])
|
])
|
||||||
})()
|
})()
|
||||||
|
|
||||||
;(function (ThemeSwitcher) {
|
;(function (ThemeSwitcher) {
|
||||||
const themeSwitcher = new ThemeSwitcher('stylesheet');
|
const themeSwitcher = new ThemeSwitcher('stylesheet')
|
||||||
const themeSwitchBtn = document.getElementById('switch');
|
const themeSwitchBtn = document.getElementById('switch')
|
||||||
const themes = {
|
const themes = {
|
||||||
dark: 'dark',
|
dark: 'dark',
|
||||||
darkStandalone: 'dark.standalone',
|
darkStandalone: 'dark.standalone',
|
||||||
light: 'light',
|
light: 'light',
|
||||||
lightStandalone: 'light.standalone'
|
lightStandalone: 'light.standalone'
|
||||||
};
|
}
|
||||||
const getSwitchThemeName = function () {
|
const getSwitchThemeName = function () {
|
||||||
// Case: switch to "light.standalone.css"
|
// Case: switch to "light.standalone.css"
|
||||||
if (
|
if (
|
||||||
(themeSwitcher.current === themes.dark) && themeSwitcher.isDark ||
|
((themeSwitcher.current === themes.dark) && themeSwitcher.isDark) ||
|
||||||
(themeSwitcher.current === themes.light) && themeSwitcher.isDark ||
|
((themeSwitcher.current === themes.light) && themeSwitcher.isDark) ||
|
||||||
themeSwitcher.current === themes.darkStandalone
|
themeSwitcher.current === themes.darkStandalone
|
||||||
) {
|
) {
|
||||||
return themes.lightStandalone
|
return themes.lightStandalone
|
||||||
|
|
||||||
// Case: switch to "dark.standalone.css"
|
// Case: switch to "dark.standalone.css"
|
||||||
} else if (
|
} else if (
|
||||||
(themeSwitcher.current === themes.dark) && themeSwitcher.isLight ||
|
((themeSwitcher.current === themes.dark) && themeSwitcher.isLight) ||
|
||||||
(themeSwitcher.current === themes.light) && themeSwitcher.isLight ||
|
((themeSwitcher.current === themes.light) && themeSwitcher.isLight) ||
|
||||||
themeSwitcher.current === themes.lightStandalone
|
themeSwitcher.current === themes.lightStandalone
|
||||||
) {
|
) {
|
||||||
return themes.darkStandalone;
|
return themes.darkStandalone
|
||||||
|
|
||||||
// Case: switch to "light.css"
|
// Case: switch to "light.css"
|
||||||
} else if (themeSwitcher.current === themes.dark) {
|
} else if (themeSwitcher.current === themes.dark) {
|
||||||
return themes.light;
|
return themes.light
|
||||||
|
|
||||||
// Case: switch to "dark.css"
|
// Case: switch to "dark.css"
|
||||||
} else if (themeSwitcher.current === themes.light) {
|
} else if (themeSwitcher.current === themes.light) {
|
||||||
return themes.dark;
|
return themes.dark
|
||||||
|
|
||||||
// Case: switch destination is unknown
|
// Case: switch destination is unknown
|
||||||
} else {
|
} else {
|
||||||
return themeSwitcher.current;
|
return themeSwitcher.current
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
const getGeneralThemeName = function () {
|
const getGeneralThemeName = function () {
|
||||||
return themeSwitcher.current.replace(/\.standalone/g, '');
|
return themeSwitcher.current.replace(/\.standalone/g, '')
|
||||||
};
|
}
|
||||||
|
|
||||||
themeSwitchBtn.addEventListener('click', function() {
|
themeSwitchBtn.addEventListener('click', function () {
|
||||||
themeSwitcher.switch(getSwitchThemeName());
|
themeSwitcher.switch(getSwitchThemeName())
|
||||||
});
|
})
|
||||||
|
|
||||||
themeSwitcher.onChangeDark = function () {
|
themeSwitcher.onChangeDark = function () {
|
||||||
themeSwitcher.switch(getGeneralThemeName());
|
themeSwitcher.switch(getGeneralThemeName())
|
||||||
};
|
}
|
||||||
|
|
||||||
themeSwitcher.onChangeLight = function () {
|
themeSwitcher.onChangeLight = function () {
|
||||||
themeSwitcher.switch(getGeneralThemeName());
|
themeSwitcher.switch(getGeneralThemeName())
|
||||||
};
|
}
|
||||||
})(
|
})(
|
||||||
(function () {
|
(function () {
|
||||||
const ThemeSwitcher = function(stylesheet) {
|
const ThemeSwitcher = function (stylesheet) {
|
||||||
const darkSchemeMql = matchMedia('(prefers-color-scheme: dark)');
|
const darkSchemeMql = matchMedia('(prefers-color-scheme: dark)')
|
||||||
const lightSchemeMql = matchMedia('(prefers-color-scheme: light)');
|
const lightSchemeMql = matchMedia('(prefers-color-scheme: light)')
|
||||||
const that = this;
|
const that = this
|
||||||
|
|
||||||
this.themeDir = 'dist/';
|
this.themeDir = 'dist/'
|
||||||
this.stylesheet = document.getElementById(stylesheet);
|
this.stylesheet = document.getElementById(stylesheet)
|
||||||
this.current = this.getThemeName(this.stylesheet.href);
|
this.current = this.getThemeName(this.stylesheet.href)
|
||||||
this.isDark = darkSchemeMql.matches;
|
this.isDark = darkSchemeMql.matches
|
||||||
this.isLight = lightSchemeMql.matches;
|
this.isLight = lightSchemeMql.matches
|
||||||
|
|
||||||
darkSchemeMql.addListener(function (mql) {
|
darkSchemeMql.addListener(function (mql) {
|
||||||
if (mql.matches && typeof that.onChangeDark === 'function') {
|
if (mql.matches && typeof that.onChangeDark === 'function') {
|
||||||
that.onChangeDark()
|
that.onChangeDark()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
lightSchemeMql.addListener(function (mql) {
|
lightSchemeMql.addListener(function (mql) {
|
||||||
if (mql.matches && typeof that.onChangeLight === 'function') {
|
if (mql.matches && typeof that.onChangeLight === 'function') {
|
||||||
that.onChangeLight()
|
that.onChangeLight()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
ThemeSwitcher.prototype = {
|
ThemeSwitcher.prototype = {
|
||||||
switch: function (themeName) {
|
switch: function (themeName) {
|
||||||
this.stylesheet.href = this.themeDir + themeName + '.css';
|
this.stylesheet.href = this.themeDir + themeName + '.css'
|
||||||
this.current = themeName;
|
this.current = themeName
|
||||||
},
|
},
|
||||||
getThemeName: function () {
|
getThemeName: function () {
|
||||||
const reg = new RegExp(this.themeDir + '(|.+?).css');
|
const reg = new RegExp(this.themeDir + '(|.+?).css')
|
||||||
return stylesheet.getAttribute('href').replace(reg, '$1');
|
return this.stylesheet.getAttribute('href').replace(reg, '$1')
|
||||||
},
|
},
|
||||||
onChangeDark: null,
|
onChangeDark: null,
|
||||||
onChangeLight: null
|
onChangeLight: null
|
||||||
};
|
}
|
||||||
|
|
||||||
return ThemeSwitcher;
|
return ThemeSwitcher
|
||||||
})()
|
})()
|
||||||
);
|
)
|
||||||
|
Reference in New Issue
Block a user