Skip to content

Commit

Permalink
refactor(config): rollup bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
neighborhood999 committed Nov 8, 2018
1 parent 5f67a34 commit 3bca9d7
Show file tree
Hide file tree
Showing 7 changed files with 1,998 additions and 284 deletions.
26 changes: 26 additions & 0 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"dist/vue-signature-pad.common.js": {
"bundled": 7005,
"minified": 4470,
"gzipped": 1696
},
"dist/vue-signature-pad.js": {
"bundled": 7824,
"minified": 4014,
"gzipped": 1634
},
"dist/vue-signature-pad.esm.js": {
"bundled": 6832,
"minified": 4339,
"gzipped": 1654,
"treeshaked": {
"rollup": {
"code": 3667,
"import_statements": 57
},
"webpack": {
"code": 4719
}
}
}
}
183 changes: 113 additions & 70 deletions dist/vue-signature-pad.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,64 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
var SignaturePad = _interopDefault(require('signature_pad'));
var mergeImages = _interopDefault(require('merge-images'));

var SAVE_TYPE = ['image/png', 'image/jpeg', 'image/svg+xml'];
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}

return obj;
}

function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);

var checkSaveType = function (type) { return SAVE_TYPE.includes(type); };
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}

ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}

return target;
}

function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
}

function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];

return arr2;
}
}

function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}

function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
}

var SAVE_TYPE = ['image/png', 'image/jpeg', 'image/svg+xml'];
var checkSaveType = function checkSaveType(type) {
return SAVE_TYPE.includes(type);
};
var DEFAULT_OPTIONS = {
dotSize: (0.5 + 2.5) / 2,
minWidth: 0.5,
Expand All @@ -18,15 +72,14 @@ var DEFAULT_OPTIONS = {
backgroundColor: 'rgba(0,0,0,0)',
penColor: 'black',
velocityFilterWeight: 0.7,
onBegin: function () {},
onEnd: function () {}
onBegin: function onBegin() {},
onEnd: function onEnd() {}
};
var convert2NonReactive = function convert2NonReactive(observerValue) {
return JSON.parse(JSON.stringify(observerValue));
};

var convert2NonReactive = function (observerValue) { return JSON.parse(JSON.stringify(observerValue)); };

var TRANSPARENT_PNG = {
src:
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=',
src: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=',
x: 0,
y: 0
};
Expand All @@ -51,28 +104,30 @@ var VueSignaturePad = {
},
options: {
type: Object,
default: function () { return ({}); }
default: function _default() {
return {};
}
},
images: {
type: Array,
default: function () { return []; }
default: function _default() {
return [];
}
}
},
data: function () { return ({
signaturePad: {},
cacheImages: [],
signatureData: TRANSPARENT_PNG
}); },
data: function data() {
return {
signaturePad: {},
cacheImages: [],
signatureData: TRANSPARENT_PNG
};
},
mounted: function mounted() {
var ref = this;
var options = ref.options;
var options = this.options;
var canvas = this.$refs.signaturePadCanvas;
var signaturePad = new SignaturePad(canvas, Object.assign({}, DEFAULT_OPTIONS,
options));
var signaturePad = new SignaturePad(canvas, _objectSpread({}, DEFAULT_OPTIONS, options));
this.signaturePad = signaturePad;

window.addEventListener('resize', this.resizeCanvas.bind(this), false);

this.resizeCanvas();
},
methods: {
Expand All @@ -88,28 +143,30 @@ var VueSignaturePad = {
this.signaturePad.fromData(data);
},
saveSignature: function saveSignature() {
var ref = this;
var signaturePad = ref.signaturePad;
var saveType = ref.saveType;
var status = { isEmpty: false, data: undefined };
var signaturePad = this.signaturePad,
saveType = this.saveType;
var status = {
isEmpty: false,
data: undefined
};

if (!checkSaveType(saveType)) {
throw new Error('Image type is incorrect!');
}

if (signaturePad.isEmpty()) {
return Object.assign({}, status,
{isEmpty: true});
return _objectSpread({}, status, {
isEmpty: true
});
} else {
this.signatureData = signaturePad.toDataURL(saveType);

return Object.assign({}, status,
{data: this.signatureData});
return _objectSpread({}, status, {
data: this.signatureData
});
}
},
undoSignature: function undoSignature() {
var ref = this;
var signaturePad = ref.signaturePad;
var signaturePad = this.signaturePad;
var record = signaturePad.toData();

if (record) {
Expand All @@ -118,19 +175,12 @@ var VueSignaturePad = {
},
mergeImageAndSignature: function mergeImageAndSignature(customSignature) {
this.signatureData = customSignature;

return mergeImages(this.images.concat( this.cacheImages,
[this.signatureData]
));
return mergeImages(_toConsumableArray(this.images).concat(_toConsumableArray(this.cacheImages), [this.signatureData]));
},
addImages: function addImages(images) {
if ( images === void 0 ) images = [];

this.cacheImages = this.cacheImages.concat( images);

return mergeImages(this.images.concat( this.cacheImages,
[this.signatureData]
));
addImages: function addImages() {
var images = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
this.cacheImages = _toConsumableArray(this.cacheImages).concat(_toConsumableArray(images));
return mergeImages(_toConsumableArray(this.images).concat(_toConsumableArray(this.cacheImages), [this.signatureData]));
},
fromDataURL: function fromDataURL(data) {
return this.signaturePad.fromDataURL(data);
Expand All @@ -149,7 +199,6 @@ var VueSignaturePad = {
},
clearCacheImages: function clearCacheImages() {
this.cacheImages = [];

return this.cacheImages;
},
clearSignature: function clearSignature() {
Expand All @@ -160,37 +209,31 @@ var VueSignaturePad = {
propsImagesAndCustomImages: function propsImagesAndCustomImages() {
var nonReactiveProrpImages = convert2NonReactive(this.images);
var nonReactiveCachImages = convert2NonReactive(this.cacheImages);

return nonReactiveProrpImages.concat( nonReactiveCachImages);
return _toConsumableArray(nonReactiveProrpImages).concat(_toConsumableArray(nonReactiveCachImages));
}
},
render: function render(createElement) {
var ref = this;
var width = ref.width;
var height = ref.height;
var customStyle = ref.customStyle;

return createElement(
'div',
{
style: Object.assign({}, {width: width,
height: height},
customStyle)
var width = this.width,
height = this.height,
customStyle = this.customStyle;
return createElement('div', {
style: _objectSpread({
width: width,
height: height
}, customStyle)
}, [createElement('canvas', {
style: {
width: '100%',
height: '100%'
},
[
createElement('canvas', {
style: {
width: '100%',
height: '100%'
},
ref: 'signaturePadCanvas'
})
]
);
ref: 'signaturePadCanvas'
})]);
}
};

VueSignaturePad.install = function (Vue) { return Vue.component(VueSignaturePad.name, VueSignaturePad); };
VueSignaturePad.install = function (Vue) {
return Vue.component(VueSignaturePad.name, VueSignaturePad);
};

if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(VueSignaturePad);
Expand Down
Loading

0 comments on commit 3bca9d7

Please sign in to comment.