Skip to content
Permalink
Browse files

Initial commit

  • Loading branch information...
dimitrinicolas committed Jun 5, 2018
0 parents commit 73b599019cabd86e72af251f8d4249faefd54372
@@ -0,0 +1,6 @@
node_modules
.npm-debug.log
logs
*.log*
tmp
.DS_Store
20 LICENSE
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2018 Dimitri Nicolas

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,6 @@
const defaultCLIConfig = {
watch: true,
input: null
};

module.exports = defaultCLIConfig;
@@ -0,0 +1,46 @@
#!/usr/bin/env node

const lepto = require('../');

const path = require('path');
const cosmiconfig = require('cosmiconfig');
const chalk = require('chalk');

const argv = require('minimist')(process.argv.slice(2), {
alias: {
w: 'watch',
c: 'config'
}
});

const defaultConfig = require('./default-cli-config.js');


const configExplorer = cosmiconfig('lepto');

let loadedConfig = null;

const searchedFor = configExplorer.searchSync();
if (searchedFor && !searchedFor.isEmpty) {
loadedConfig = searchedFor.config;
}

if (argv.config) {
const configPath = path.resolve(argv.config);
const loaded = configExplorer.loadSync(configPath);
if (!loaded.isEmpty) {
loadedConfig = loaded.config;
}
else {
console.log(chalk.red.bold('Lepto - Empty config file: ', configPath));
}
}

if (!loadedConfig) {
console.log(chalk.red.bold('Lepto - No config file found'));
return;
}

const config = Object.assign(defaultConfig, loadedConfig || {});

lepto(config);
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +13.4 KB demo/input/image.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +603 Bytes demo/output/image.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,12 @@
const plugin = (options) => {
return function(input, fulfill) {
let res = Object.assign({}, input, {
data: {
incr: input.data.incr ? input.data.incr + 1 : 1
}
})
setTimeout(fulfill.bind(null, res), 100);
};
};

module.exports = plugin;
@@ -0,0 +1,12 @@
const plugin2 = (options) => {
return function(input, fulfill) {
let res = Object.assign({}, input, {
data: {
incr: input.data.incr ? input.data.incr + 1 : 1
}
})
setTimeout(fulfill.bind(null, res), 100);
};
};

module.exports = plugin2;
@@ -0,0 +1,103 @@
'use strict';

var topColor = void 0;
var bottomColor = void 0;
var currentColor = void 0;

var styleTag = void 0;

var setBgColor = function setBgColor(color) {

if (currentColor !== color) {
currentColor = color;

var css = 'html{background:' + color + ';}';

if (!styleTag) {
styleTag = document.createElement('style');
var head = document.head || document.getElementsByTagName('head')[0];
head.appendChild(styleTag);
}

if (styleTag.styleSheet) {
styleTag.styleSheet.cssText = css;
} else {
styleTag.innerHTML = css;
}
}
};

var checkScroll = function checkScroll() {

if (document.body.scrollHeight === window.innerHeight) {
setBgColor(bottomColor);
} else {
var scrollFromMiddle = window.innerHeight - document.body.scrollHeight + 2 * Math.max(document.body.scrollTop, document.documentElement.scrollTop);
setBgColor(scrollFromMiddle < 0 ? topColor : bottomColor);
}
};

var initOverflowColor = function initOverflowColor() {

var shortcutEl = document.querySelector('[data-oc]');
if (shortcutEl) {
var split = shortcutEl.getAttribute('data-oc').split(',');
if (split.length > 1) {
topColor = split[0];
bottomColor = split[1];
} else if (split.length === 1) {
topColor = bottomColor = split[0];
}
} else {
var topEl = document.querySelector('[data-oc-top]');
var bottomEl = document.querySelector('[data-oc-bottom]');
if (topEl) {
topColor = topEl.getAttribute('data-oc-top');
}
if (bottomEl) {
bottomColor = bottomEl.getAttribute('data-oc-bottom');
}
}

if (topColor || bottomColor) {

if (!topColor && bottomColor) {
topColor = bottomColor;
} else if (topColor && !bottomColor) {
bottomColor = topColor;
}

var bodyComputedStyle = window.getComputedStyle(document.body, null);
var bodyBackground = bodyComputedStyle.getPropertyValue('background');
if (bodyBackground === '' || bodyComputedStyle.getPropertyValue('background-color') === 'rgba(0, 0, 0, 0)' && bodyBackground.substring(21, 17) === 'none') {
bodyBackground = 'white';
}
document.body.style.background = 'transparent';
var bodyWrap = document.createElement('div');
bodyWrap.setAttribute('data-oc-wrap', '');
bodyWrap.style.background = bodyBackground;
for (var i = 0, l = document.body.childNodes.length; i < l; i++) {
bodyWrap.appendChild(document.body.childNodes[0]);
}
document.body.appendChild(bodyWrap);

checkScroll();
if (typeof window.addEventListener !== 'undefined') {
window.addEventListener('scroll', checkScroll, false);
window.addEventListener('resize', checkScroll, false);
} else {
window.attachEvent('scroll', checkScroll);
window.attachEvent('resize', checkScroll);
}
}
};

if (['interactive', 'complete', 'loaded'].indexOf(document.readyState) >= 0) {
initOverflowColor();
} else if (typeof document.addEventListener !== 'undefined') {
document.addEventListener('DOMContentLoaded', initOverflowColor, false);
} else {
document.attachEvent('onreadystatechange', initOverflowColor);
}

module.exports = initOverflowColor;
@@ -0,0 +1,101 @@
var topColor = void 0;
var bottomColor = void 0;
var currentColor = void 0;

var styleTag = void 0;

var setBgColor = function setBgColor(color) {

if (currentColor !== color) {
currentColor = color;

var css = 'html{background:' + color + ';}';

if (!styleTag) {
styleTag = document.createElement('style');
var head = document.head || document.getElementsByTagName('head')[0];
head.appendChild(styleTag);
}

if (styleTag.styleSheet) {
styleTag.styleSheet.cssText = css;
} else {
styleTag.innerHTML = css;
}
}
};

var checkScroll = function checkScroll() {

if (document.body.scrollHeight === window.innerHeight) {
setBgColor(bottomColor);
} else {
var scrollFromMiddle = window.innerHeight - document.body.scrollHeight + 2 * Math.max(document.body.scrollTop, document.documentElement.scrollTop);
setBgColor(scrollFromMiddle < 0 ? topColor : bottomColor);
}
};

var initOverflowColor = function initOverflowColor() {

var shortcutEl = document.querySelector('[data-oc]');
if (shortcutEl) {
var split = shortcutEl.getAttribute('data-oc').split(',');
if (split.length > 1) {
topColor = split[0];
bottomColor = split[1];
} else if (split.length === 1) {
topColor = bottomColor = split[0];
}
} else {
var topEl = document.querySelector('[data-oc-top]');
var bottomEl = document.querySelector('[data-oc-bottom]');
if (topEl) {
topColor = topEl.getAttribute('data-oc-top');
}
if (bottomEl) {
bottomColor = bottomEl.getAttribute('data-oc-bottom');
}
}

if (topColor || bottomColor) {

if (!topColor && bottomColor) {
topColor = bottomColor;
} else if (topColor && !bottomColor) {
bottomColor = topColor;
}

var bodyComputedStyle = window.getComputedStyle(document.body, null);
var bodyBackground = bodyComputedStyle.getPropertyValue('background');
if (bodyBackground === '' || bodyComputedStyle.getPropertyValue('background-color') === 'rgba(0, 0, 0, 0)' && bodyBackground.substring(21, 17) === 'none') {
bodyBackground = 'white';
}
document.body.style.background = 'transparent';
var bodyWrap = document.createElement('div');
bodyWrap.setAttribute('data-oc-wrap', '');
bodyWrap.style.background = bodyBackground;
for (var i = 0, l = document.body.childNodes.length; i < l; i++) {
bodyWrap.appendChild(document.body.childNodes[0]);
}
document.body.appendChild(bodyWrap);

checkScroll();
if (typeof window.addEventListener !== 'undefined') {
window.addEventListener('scroll', checkScroll, false);
window.addEventListener('resize', checkScroll, false);
} else {
window.attachEvent('scroll', checkScroll);
window.attachEvent('resize', checkScroll);
}
}
};

if (['interactive', 'complete', 'loaded'].indexOf(document.readyState) >= 0) {
initOverflowColor();
} else if (typeof document.addEventListener !== 'undefined') {
document.addEventListener('DOMContentLoaded', initOverflowColor, false);
} else {
document.attachEvent('onreadystatechange', initOverflowColor);
}

export default initOverflowColor;

0 comments on commit 73b5990

Please sign in to comment.
You can’t perform that action at this time.