diff --git a/dist/pagemap.min.js b/dist/pagemap.min.js index 62270d4..af1e6d0 100644 --- a/dist/pagemap.min.js +++ b/dist/pagemap.min.js @@ -1,2 +1,2 @@ -/*! pagemap v0.2.0 - https://larsjung.de/pagemap/ */ +/*! pagemap v0.3.0 - https://larsjung.de/pagemap/ */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.pagemap=e():t.pagemap=e()}(this,function(){return function(t){function e(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var o={};return e.m=t,e.c=o,e.p="",e(0)}([function(t,e,o){(function(e){"use strict";var n=o(1),r=e.window,i=r.document,c=i.querySelector("body"),u=function(t){return"rgba(0,0,0,"+t/100+")"},f={viewport:null,styles:{"header,footer,section,article":u(8),"h1,a":u(10),"h2,h3,h4":u(8)},back:u(2),view:u(5),drag:u(10),interval:null},l=function(t,e,o,n){return o.split(/\s+/).forEach(function(o){return t[e](o,n)})},s=function(t,e,o){return l(t,"addEventListener",e,o)},a=function(t,e,o){return l(t,"removeEventListener",e,o)};t.exports=function(t,e){var o=Object.assign({},f,e),u=t.getContext("2d"),l=function(){var e=t.clientWidth,o=t.clientHeight;return function(t,n){return Math.min(e/t,o/n)}}(),p=function(e,o){t.width=e,t.height=o,t.style.width=e+"px",t.style.height=o+"px"},h=o.viewport,d=function(t){return Array.from((h||i).querySelectorAll(t))},v=!1,y=void 0,g=void 0,w=void 0,x=void 0,m=void 0,b=function(t,e){e&&(u.beginPath(),u.rect(t.x,t.y,t.w,t.h),u.fillStyle=e,u.fill())},T=function(t){Object.keys(t).forEach(function(e){var o=t[e];d(e).forEach(function(t){b(n.ofElement(t).relativeTo(y),o)})})},E=function(){y=h?n.ofContent(h):n.ofDocument(),g=h?n.ofViewport(h):n.ofWindow(),w=l(y.w,y.h),p(y.w*w,y.h*w),u.setTransform(1,0,0,1,0,0),u.clearRect(0,0,t.width,t.height),u.scale(w,w),b(y.relativeTo(y),o.back),T(o.styles),b(g.relativeTo(y),v?o.drag:o.view)},O=function(e){e.preventDefault();var o=n.ofViewport(t),i=(e.pageX-o.x)/w-g.w*x,c=(e.pageY-o.y)/w-g.h*m;h?(h.scrollLeft=i,h.scrollTop=c):r.scrollTo(i,c),E()},W=function L(e){v=!1,t.style.cursor="pointer",c.style.cursor="auto",a(r,"mousemove",O),a(r,"mouseup",L),O(e)},j=function(e){v=!0;var o=n.ofViewport(t),i=g.relativeTo(y);x=((e.pageX-o.x)/w-i.x)/i.w,m=((e.pageY-o.y)/w-i.y)/i.h,(0>x||x>1||0>m||m>1)&&(x=.5,m=.5),t.style.cursor="crosshair",c.style.cursor="crosshair",s(r,"mousemove",O),s(r,"mouseup",W),O(e)},H=function(){t.style.cursor="pointer",s(t,"mousedown",j),s(h||r,"load resize scroll",E),o.interval>0&&setInterval(function(){return E()},o.interval),E()};return H(),{redraw:E}}}).call(e,function(){return this}())},function(t,e){(function(e){"use strict";var o=e.window,n=o.document.documentElement,r=t.exports=function(t,e,o,n){return Object.assign(Object.create(r.prototype),{x:t,y:e,w:o,h:n})};r.prototype={constructor:r,relativeTo:function(){var t=arguments.length<=0||void 0===arguments[0]?{x:0,y:0}:arguments[0];return r(this.x-t.x,this.y-t.y,this.w,this.h)}},r.ofDocument=function(){return r(0,0,n.scrollWidth,n.scrollHeight)},r.ofWindow=function(){return r(o.pageXOffset,o.pageYOffset,n.clientWidth,n.clientHeight)};var i=function(t){var e=t.getBoundingClientRect();return{x:e.left+o.pageXOffset,y:e.top+o.pageYOffset}};r.ofElement=function(t){var e=i(t),o=e.x,n=e.y;return r(o,n,t.offsetWidth,t.offsetHeight)},r.ofViewport=function(t){var e=i(t),o=e.x,n=e.y;return r(o+t.clientLeft,n+t.clientTop,t.clientWidth,t.clientHeight)},r.ofContent=function(t){var e=i(t),o=e.x,n=e.y;return r(o+t.clientLeft-t.scrollLeft,n+t.clientTop-t.scrollTop,t.scrollWidth,t.scrollHeight)}}).call(e,function(){return this}())}])}); \ No newline at end of file diff --git a/ghu.js b/ghu.js new file mode 100644 index 0000000..8b83e39 --- /dev/null +++ b/ghu.js @@ -0,0 +1,80 @@ +const {resolve, join} = require('path'); +const {ghu, jszip, mapfn, read, remove, run, uglify, webpack, wrap, write} = require('ghu'); + +const NAME = 'pagemap'; + +const ROOT = resolve(__dirname); +const SRC = join(ROOT, 'src'); +const DEMO = join(SRC, 'demo'); +const BUILD = join(ROOT, 'build'); +const DIST = join(ROOT, 'dist'); + +ghu.defaults('release'); + +ghu.before(runtime => { + runtime.pkg = Object.assign({}, require('./package.json')); + runtime.comment = `${NAME} v${runtime.pkg.version} - ${runtime.pkg.homepage}`; + runtime.commentJs = `/*! ${runtime.comment} */\n`; + console.log(runtime.comment); +}); + +ghu.task('clean', () => { + return remove(`${BUILD}, ${DIST}`); +}); + +ghu.task('lint', () => { + return run('eslint .', {stdio: 'inherit'}); +}); + +ghu.task('build:script', runtime => { + const webpackConfig = { + output: { + library: NAME, + libraryTarget: 'umd' + }, + module: { + loaders: [ + { + include: [SRC], + loader: 'babel-loader', + query: { + cacheDirectory: true, + presets: ['es2015'] + } + } + ] + } + }; + + return read(`${SRC}/${NAME}.js`) + .then(webpack(webpackConfig, {showStats: false})) + .then(uglify({compressor: {warnings: false}})) + .then(wrap(runtime.commentJs)) + .then(write(`${DIST}/${NAME}.min.js`, {overwrite: true})) + .then(write(`${BUILD}/${NAME}-${runtime.pkg.version}.min.js`, {overwrite: true})); +}); + +ghu.task('build:copy', () => { + return read(`${ROOT}/*.md`) + .then(write(mapfn.p(ROOT, BUILD), {overwrite: true})); +}); + +ghu.task('build:demo', ['build:script'], () => { + return Promise.all([ + read(`${DEMO}: *`) + .then(write(mapfn.p(SRC, BUILD), {overwrite: true})), + + read(`${BUILD}: ${NAME}-*.min.js`) + .then(write(`${BUILD}/demo/${NAME}.min.js`, {overwrite: true})) + ]); +}); + +ghu.task('build', ['build:script', 'build:copy', 'build:demo']); + +ghu.task('zip', ['build'], runtime => { + return read(`${BUILD}/**`) + .then(jszip({dir: BUILD, level: 9})) + .then(write(`${BUILD}/${NAME}-${runtime.pkg.version}.zip`, {overwrite: true})); +}); + +ghu.task('release', ['clean', 'zip']); diff --git a/package.json b/package.json index 1b3fd23..fd3ba8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pagemap", - "version": "0.2.0", + "version": "0.3.0", "description": "Mini map for web pages.", "homepage": "https://larsjung.de/pagemap/", "bugs": "https://github.com/lrsjng/pagemap/issues", @@ -13,15 +13,14 @@ "main": "dist/pagemap", "scripts": { "lint": "eslint .", - "build": "rimraf dist && webpack", + "build": "node ghu release", "precommit": "npm run -s lint && npm run -s build" }, "devDependencies": { "babel-loader": "6.2.4", "babel-preset-es2015": "6.9.0", - "eslint": "2.12.0", - "rimraf": "2.5.2", - "webpack": "1.13.1" + "eslint": "3.0.0", + "ghu": "0.6.0" }, "engines": { "node": ">=6.0.0" diff --git a/demo/boxes.css b/src/demo/boxes.css similarity index 100% rename from demo/boxes.css rename to src/demo/boxes.css diff --git a/demo/boxes.html b/src/demo/boxes.html similarity index 93% rename from demo/boxes.html rename to src/demo/boxes.html index acb97c6..4d699ba 100644 --- a/demo/boxes.html +++ b/src/demo/boxes.html @@ -16,7 +16,7 @@ - + + diff --git a/lib/pagemap.js b/src/pagemap.js similarity index 100% rename from lib/pagemap.js rename to src/pagemap.js diff --git a/lib/rect.js b/src/rect.js similarity index 100% rename from lib/rect.js rename to src/rect.js diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 9e6e1e0..0000000 --- a/webpack.config.js +++ /dev/null @@ -1,28 +0,0 @@ -const webpack = require('webpack'); -const pkg = require('./package.json'); -const banner = `${pkg.name} v${pkg.version} - ${pkg.homepage}`; - -module.exports = { - entry: './lib/pagemap.js', - output: { - path: './dist', - filename: 'pagemap.min.js', - library: 'pagemap', - libraryTarget: 'umd' - }, - module: { - loaders: [{ - test: /\.js$/, - exclude: /node_modules/, - loader: 'babel-loader', - query: { - cacheDirectory: true, - presets: ['es2015'] - } - }] - }, - plugins: [ - new webpack.BannerPlugin(banner), - new webpack.optimize.UglifyJsPlugin() - ] -};