(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i 0.01) { // Apply the scale to the base scale (not multiplying current scale) image.scaleX = _baseImageScale.x * scaleFactor; image.scaleY = _baseImageScale.y * scaleFactor; image.setCoords(); // Recalculate viewport with the new image scale _data = util.calcCrop(image, width, height, units); } var cropData = canvas.getImageData().getCropData(); var isAspectTheSame = !!(cropData && !util.isAspectChanged(cropData.viewportWidth, cropData.viewportHeight, width, height)); if (!isAspectTheSame) { canvas.getImageData().removeCropData(); } apply(); this.getGores().reset(); this.getRulers().reset(); if (canvas.getImage().__cropped && !isAspectTheSame) { canvas.getApertures().setTransparent(true); // Trigger event to tell the image needs to be dragged. $(document).trigger('PIE:needs-dragging', { axis: _data.axis }); } canvas.getButtonMenu().bringToFront(); return this; }; /** * @param {string} frameType white|black|image|none * @return {Viewport} */ this.setFrame = function (frameType) { this.getFrameHandler().setFrames(frameType); canvas.getButtonMenu().bringToFront(); }; this.getData = function () { return _data; }; var _frameHandler = null; this.getFrameHandler = function () { return _frameHandler || (_frameHandler = new FrameHandler(this)); }; this.getGores = function () { return this.__goreHandler || (this.__goreHandler = new GoreHandler(this)); }; this.getRulers = function () { return this.__rulerHandler || (this.__rulerHandler = new RulerHandler(this)); }; } module.exports = Viewport; },{"./FrameHandler":7,"./GoreHandler":8,"./RulerHandler":12,"./util":24}],15:[function(require,module,exports){ 'use strict'; module.exports = { frames: require('./config/frames'), textButton: require('./config/text-button'), buttonMenu: require('./config/button-menu'), rulerHandle: require('./config/ruler-handle'), dragHandle: require('./config/drag-handle'), dragBar: require('./config/drag-bar') }; },{"./config/button-menu":16,"./config/drag-bar":17,"./config/drag-handle":18,"./config/frames":19,"./config/ruler-handle":20,"./config/text-button":21}],16:[function(require,module,exports){ 'use strict'; module.exports = { canvas: { margin: 5, text: { fill: '#ffffff', activeFill: '#ffffff', }, rect: { fill: '#343434', activeFill: '#494949', }, }, 'photo-wallpaper': { margin: 5, text: { fill: '#ffffff', activeFill: '#ffffff', }, rect: { fill: '#000000', activeFill: '#444444', }, }, wallpaper: { margin: 5, text: { fill: '#ffffff', activeFill: '#ffffff', }, rect: { fill: '#343434', activeFill: '#494949', }, } }; },{}],17:[function(require,module,exports){ 'use strict'; module.exports = { fill: '#bbbbbb', size: 20, }; },{}],18:[function(require,module,exports){ 'use strict'; module.exports = { text: { fontFamily: 'Urbanist', fontSize: 12, fill: '#ffffff', originX: 'center', top: 2, }, rect: { fill: '#666666', height: 20, originX: 'center', }, }; },{}],19:[function(require,module,exports){ 'use strict'; module.exports = { default: { fill: '#000000', stroke: '#f31fb3', width: 1, height: 1, }, image: { fill: 'rgba(0,0,0,0.2)', strokeWidth: 1, }, black: { fill: '#000000', strokeWidth: 0, }, white: { fill: '#ffffff', strokeWidth: 0, }, }; },{}],20:[function(require,module,exports){ 'use strict'; module.exports = { line: function(axis, bounds) { return { evented: false, strokeDashArray: [5, 5], stroke: '#000', strokeWidth: 1, top: axis === 'x' ? bounds.top + bounds.height / 2 : bounds.top, left: axis === 'y' ? bounds.left + bounds.width / 2 : bounds.left }; }, text: { fontSize: 12, width: 75, height: 20, fill: '#FFFFFF', }, x: function(lines, bounds) { return { axis: 'left', marker: lines.y, top: Math.ceil(bounds.top + bounds.height + 5), left: lines.y.left, originX: 'center', lockMovementY: true, moveCursor: 'ew-resize', hoverCursor: 'ew-resize', }; }, y: function(lines, bounds) { return { axis: 'top', marker: lines.x, top: lines.x.top, left: Math.ceil(bounds.left + bounds.width + 5), originY: 'center', lockMovementX: true, moveCursor: 'ns-resize', hoverCursor: 'ns-resize', }; } }; },{}],21:[function(require,module,exports){ 'use strict'; module.exports = { rect: function(width, height) { return { fill: '#343434', activeFill: '#494949', disabledFill: '#494949', originX: 'center', originY: 'center', width: width || 1, dynamicW: !width, height: height || 1, dynamicH: !height, }; }, text: { fill: '#ffffff', disabledFill: '#999999', fontFamily: 'Urbanist', fontSize: 14, originX: 'center', originY: 'center', }, cursor: 'pointer', disabledCursor: 'default', padding: 17, }; },{}],22:[function(require,module,exports){ 'use strict'; /* globals $, fabric */ var Draggable = require('./Draggable'); var util = require('./util'); function ExtendFabricFunctionality() { // Set default values for the fabric canvas $.extend(fabric.Object.prototype, { cornerSize: 0, hasBorders: false, hasControls: false, padding: 0, selectable: false, strokeWidth: 0, addTo: function(canvas) { canvas.add(this); return this; }, }); util.setProperties(fabric.Image.prototype, { drag: { get: function() { return this.__draggable || (this.__draggable = new Draggable(this)); } } }); $.extend(fabric.Rect.prototype, { /** * Gets the inner bounds of this fabric.Rect * @return {Object} */ getInsideBoundingRect: function() { var bounds = this.getBoundingRect(); var returnValue = { left: bounds.left + this.strokeWidth, top: bounds.top + this.strokeWidth, width: bounds.width - this.strokeWidth * 2, height: bounds.height - this.strokeWidth * 2 }; returnValue.right = returnValue.left + returnValue.width; returnValue.bottom = returnValue.top + returnValue.height; returnValue.min = { left: returnValue.left, top: returnValue.top }; returnValue.max = { left: returnValue.left + returnValue.width, top: returnValue.top + returnValue.height }; return returnValue; } }); } module.exports = ExtendFabricFunctionality; },{"./Draggable":6,"./util":24}],23:[function(require,module,exports){ 'use strict'; (function() { /** * Fabric functionality is extended with some custom functionality. This is done before * we do anything else. */ require('./extend-fabric-functionality')(); /** * ImageEditor is the starting point of all files. Here the image editor is created and * it receives attributes from the initialisation. As this is done from outside of this file, * the ImageEditor should be available on globally. */ window.ImageEditor = require('./ImageEditor'); }()); },{"./ImageEditor":10,"./extend-fabric-functionality":22}],24:[function(require,module,exports){ 'use strict'; module.exports = { assertKeyValuePair: require('./utils/assert-key-value-pair'), assertBetween: require('./utils/assert-between'), calcCrop: require('./utils/calc-crop'), setPositionInside: require('./utils/set-position-inside'), setProperties: require('./utils/set-properties'), toggleFullscreen: require('./utils/toggle-fullscreen'), isMobile: require('./utils/is-mobile'), MouseMetrics: require('./utils/mouse-metrics'), supportsFullscreen: require('./utils/supports-fullscreen'), isFullscreen: require('./utils/is-fullscreen'), isAspectChanged: require('./utils/is-aspect-changed'), }; },{"./utils/assert-between":25,"./utils/assert-key-value-pair":26,"./utils/calc-crop":27,"./utils/is-aspect-changed":28,"./utils/is-fullscreen":29,"./utils/is-mobile":30,"./utils/mouse-metrics":31,"./utils/set-position-inside":32,"./utils/set-properties":33,"./utils/supports-fullscreen":34,"./utils/toggle-fullscreen":35}],25:[function(require,module,exports){ 'use strict'; function assertBetween(value, min, max) { if (value < min) { return min; } if (value > max) { return max; } return value; } module.exports = assertBetween; },{}],26:[function(require,module,exports){ 'use strict'; function assertKeyValuePair(key, value) { if (typeof key === 'object') { return key; } var returnValue = {}; returnValue[key] = value; return returnValue; } module.exports = assertKeyValuePair; },{}],27:[function(require,module,exports){ 'use strict'; /** * @param {fabric.Image} obj * @param {int} width * @param {int} height * @param {string} units * @return {Object} * axis: STRING, * dim: OBJECT( width: NUMBER, height: NUMBER), * width: NUMBER, * height: NUMBER, * ppmm: NUMBER */ function calcCrop(obj, width, height, units) { var cropRatio = width / height; var objRatio = obj.width / obj.height; var inchToCm = units === 'inch' ? 2.54 : 1; var returnValue = { image: obj, axis: objRatio > cropRatio ? 'x' : 'y', dim: { width: Number(width), height: Number(height), units: units }, width: obj.width * obj.scaleX, height: obj.height * obj.scaleY, objectRatio: objRatio, cropRatio: cropRatio }; if (objRatio > cropRatio) { returnValue.width *= cropRatio / objRatio; } else { returnValue.height /= cropRatio / objRatio; } // Pixels per millimeter var ppmm = returnValue.width / ((returnValue.dim.width * inchToCm * obj.scaleX) * 10); //Round to four decimal places to avoid precision issues. At least 4 decimals is needed though //for correct calculation of number of gores on wide wallpaperes in editor. returnValue.ppmm = Math.round(ppmm * 1e4) / 1e4; return returnValue; } module.exports = calcCrop; },{}],28:[function(require,module,exports){ 'use strict'; function isAspectChanged(x1, y1, x2, y2) { return (Math.abs(x1 / y1 - x2 / y2) > 0.005); } module.exports = isAspectChanged; },{}],29:[function(require,module,exports){ 'use strict'; function isFullscreen() { return document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement; } module.exports = isFullscreen; },{}],30:[function(require,module,exports){ 'use strict'; function isMobile() { return window.innerWidth < 768; } module.exports = isMobile; },{}],31:[function(require,module,exports){ 'use strict'; var MouseMetrics = { previousMouseData: { x: null, y: null }, deletePreviousMouseData: function() { MouseMetrics.previousMouseData = { x: null, y: null }; }, setPreviousMouseData: function(values) { MouseMetrics.previousMouseData = { x: values.x || null, y: values.y || null, }; }, }; module.exports = MouseMetrics; },{}],32:[function(require,module,exports){ 'use strict'; /** * @param {fabric.Object} obj * @param {Object} bounds * @return {fabric.Object} */ function setPositionInside(obj, bounds) { ['left', 'top'].forEach(function (v) { if (obj[v] < bounds[v].min) { obj.set(v, bounds[v].min).setCoords(); } if (obj[v] > bounds[v].max) { obj.set(v, bounds[v].max).setCoords(); } }); return obj; } module.exports = setPositionInside; },{}],33:[function(require,module,exports){ 'use strict'; /** * @param {Object} obj * @param {Object} properties */ function setProperties(obj, properties) { for (var o in properties) { if (Object.prototype.hasOwnProperty.call(properties, o) ) { Object.defineProperty(obj, o, properties[o]); } } } module.exports = setProperties; },{}],34:[function(require,module,exports){ 'use strict'; function supportsFullscreen() { return document.documentElement.requestFullscreen || document.documentElement.webkitRequestFullScreen || document.documentElement.mozRequestFullScreen || document.documentElement.msRequestFullscreen; } module.exports = supportsFullscreen; },{}],35:[function(require,module,exports){ 'use strict'; var isFullscreen = require('./is-fullscreen'); /** * Toggles the full screen state for passed DOM object * @param {HTMLElement} elem */ function toggleFullscreen(elem) { if (isFullscreen()) { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.webkitCancelFullScreen) { document.webkitCancelFullScreen(); } return; } if (elem.requestFullscreen) { elem.requestFullscreen(); } else if (elem.webkitRequestFullScreen) { elem.webkitRequestFullScreen(); } else if (elem.mozRequestFullScreen) { elem.mozRequestFullScreen(); } else if (elem.msRequestFullscreen) { elem.msRequestFullscreen(); } } module.exports = toggleFullscreen; },{"./is-fullscreen":29}]},{},[23]);