├── .babelrc
├── .gitignore
├── .npmignore
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── PictureInput.vue
├── README.md
├── package-lock.json
├── package.json
├── poi.config.js
├── test
├── PictureInput.spec.js
└── __snapshots__
│ └── PictureInput.spec.js.snap
└── umd
└── vue-picture-input.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["env", { "modules": false }]
4 | ],
5 | "env": {
6 | "test": {
7 | "presets": [
8 | ["env", { "targets": { "node": "current" }}]
9 | ]
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | dev/
4 | node_modules/
5 | dist/
6 | npm-debug.log
7 | test/unit/coverage
8 | test/e2e/reports
9 | selenium-debug.log
10 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .babelrc
2 | test
3 | dev
4 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at alessio.maffeis@me.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Contributions
2 |
3 | All contributions are welcome, as long as they are within the scope of the project.
4 |
5 | Please follow the Javascript Standard Style guidelines:
6 | https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
7 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Alessio Maffeis
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/PictureInput.vue:
--------------------------------------------------------------------------------
1 |
2 |
43 |
44 |
45 |
580 |
581 |
634 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | vue-picture-input
2 | =============
3 |
4 | Mobile-friendly picture file input component for Vue.js 2-3 with image preview, drag and drop, EXIF orientation, and more.
5 |
6 | 
7 |
8 | ## Installation
9 |
10 | ### npm
11 |
12 | ``` sh
13 | npm install --save vue-picture-input
14 | ```
15 | ### yarn
16 |
17 | ``` sh
18 | yarn add vue-picture-input
19 | ```
20 |
21 | ## Usage
22 |
23 | ```HTML
24 |
25 |
41 |
42 | ```
43 |
44 | ```javascript
45 |
70 | ```
71 |
72 | You can also use it directly in the browser through [unpkg's CDN](https://unpkg.com/vue-picture-input) (or [jsDelivr](https://cdn.jsdelivr.net/npm/vue-picture-input)):
73 |
74 | ```html
75 |
76 |
77 |
78 |
79 |
80 | In the browser!
81 |
82 |
83 |
84 |
{{ message }}
85 |
86 |
87 |
98 |
99 |
100 | ```
101 |
102 | ## Example project
103 |
104 | Try it on CodeSandbox: https://codesandbox.io/s/github/alessiomaffeis/vue-picture-input-example
105 |
106 |
107 | ## Props
108 |
109 | - **width, height**: (pixels, optional) the maximum width and height of the preview container. The picture will be resized and centered to cover this area. If width is not specified, the preview container will expand to full width. If height is not specified, it will be set equal to width.
110 | - **crop**: (boolean, optional) set *:crop="false"* if you wish to disable cropping. The image will be resized and centered in order to be fully contained in the preview container. Default value: true.
111 | - **margin**: (pixels, optional) the margin around the preview container. Default value: 0.
112 | - **radius**: (percentage, optional) The border-radius value for the container. Set *radius="50"* to get a circular container. Default value: 0.
113 | - **plain**: (boolean, optional) Set *:plain="true"* to remove the inner border and text. Default value: false.
114 | - **accept**: (media type, optional) the accepted image type(s), e.g. image/jpeg, image/gif, etc. Default value: 'image/*'.
115 | - **size**: (MB, optional) the maximum accepted file size in megabytes.
116 | - **removable**: (boolean, optional) set *:removable="true"* if you want to display a "Remove Photo" button. Default value: false.
117 | - **hideChangeButton**: (boolean, optional) set *:hideChangeButton="true"* if you want to hide the "Change Photo" button. Default value: false.
118 | - **id, name**: (string, optional) the id and name attributes of the HTML input element.
119 | - **buttonClass**: (string, optional) the class which will be applied to the 'Change Photo' button.
120 | Default value: 'btn btn-primary button'.
121 | - **removeButtonClass**: (string, optional) the class which will be applied to the 'Remove Photo' button.
122 | Default value: 'btn btn-secondary button secondary'.
123 | - **prefill**: (image url or File object, optional) use this to specify the path to a default image (or a File object) to prefill the input with. Default value: empty.
124 | - **prefillOptions**: (object, optional) use this if you prefill with a data uri scheme to specify a file name and a media or file type:
125 | ```
126 | fileName: (string, optional) the file name
127 | fileType: (string, optional) the file type of the image, i.e. "png", or
128 | mediaType: (string, optional) the media type of the image, i.e. "image/png"
129 | ```
130 | - **toggleAspectRatio**: (boolean, optional) set *:toggleAspectRatio="true"* to show a button for toggling the canvas aspect ratio (Landscape/Portrait) on a non-square canvas. Default value: false.
131 | - **autoToggleAspectRatio**: (boolean, optional) set *:autoToggleAspectRatio="true"* to enable automatic canvas aspect ratio change to match the selected picture's. Default value: false.
132 | - **changeOnClick**: (boolean, optional) set *:changeOnClick="true"* to open image selector when user click on the image. Default value: true.
133 | - **aspectButtonClass**: (string, optional) the class which will be applied to the 'Landscape/Portrait' button.
134 | Default value: 'btn btn-secondary button secondary'.
135 | - **zIndex**: (number, optional) The base z-index value. In case of issues with your layout, change *:zIndex="..."* to a value that suits you better. Default value: 10000.
136 | - **alertOnError**: (boolean, optional) Set *:alertOnError="false"* to disable displaying alerts on attemps to select file with
137 | wrong type or too big.
138 | Default value: true.
139 | - **customStrings**: (object, optional) use this to provide one or more custom strings (see the example above). Here are the available strings and their default values:
140 | - **capture**: (string, optional) use this if you want to allow image capture from capture devices (e.g. camera)
141 |
142 | ```js
143 | {
144 | upload: 'Your device does not support file uploading.
', // HTML allowed
145 | drag: 'Drag an image or
click here to select a file', // HTML allowed
146 | tap: 'Tap here to select a photo
from your gallery', // HTML allowed
147 | change: 'Change Photo', // Text only
148 | remove: 'Remove Photo', // Text only
149 | select: 'Select a Photo', // Text only
150 | selected: 'Photo successfully selected!
', // HTML allowed
151 | fileSize: 'The file size exceeds the limit', // Text only
152 | fileType: 'This file type is not supported.', // Text only
153 | aspect: 'Landscape/Portrait' // Text only
154 | }
155 | ```
156 |
157 | ## Events
158 |
159 | - **change**: emitted on (successful) picture change (prefill excluded). The image is passed along with the event as a Base64 Data URI string. If you need to access the underlying image from the parent component, add a *ref* attribute to picture-input (see the example above). You may want to use *this.$refs.pictureInput.image* (Base64 Data URI string) or *this.$refs.pictureInput.file* (File Object)
160 | - **prefill**: emitted on default image prefill.
161 | - **remove**: emitted on picture remove.
162 | - **click**: emitted on picture click.
163 | - **error**: emitted on error, along with an object with *type*, *message*, and optional additional parameters.
164 |
165 | ## TODOs
166 |
167 | - Client-side resizing and cropping
168 | - Add tests
169 |
170 | ## Contributions
171 |
172 | All contributions are welcome, as long as they are within the scope of the project. Please open a new issue before submitting a pull request.
173 |
174 | You should follow the Javascript Standard Style guidelines:
175 | https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
176 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-picture-input",
3 | "version": "3.0.1",
4 | "description": "Mobile-friendly picture file input component with image preview and drag and drop.",
5 | "main": "PictureInput.vue",
6 | "scripts": {
7 | "test": "jest",
8 | "build": "export NODE_OPTIONS=--openssl-legacy-provider; poi --prod"
9 | },
10 | "repository": {
11 | "type": "git",
12 | "url": "git+https://github.com/alessiomaffeis/vue-picture-input.git"
13 | },
14 | "keywords": [
15 | "vue",
16 | "picture",
17 | "image",
18 | "input",
19 | "preview",
20 | "form",
21 | "upload"
22 | ],
23 | "author": "alessio@maffe.is",
24 | "license": "MIT",
25 | "bugs": {
26 | "url": "https://github.com/alessiomaffeis/vue-picture-input/issues"
27 | },
28 | "homepage": "https://github.com/alessiomaffeis/vue-picture-input",
29 | "devDependencies": {
30 | "@vue/test-utils": "^1.0.0",
31 | "babel-core": "^6.26.3",
32 | "babel-preset-env": "^1.7.0",
33 | "jest": "^29.6.1",
34 | "jest-serializer-vue": "^3.1.0",
35 | "poi": "^12.10.3",
36 | "vue": "^2.7.0",
37 | "vue-jest": "^3.0.7",
38 | "vue-server-renderer": "^2.5.13",
39 | "vue-template-compiler": "^2.5.13"
40 | },
41 | "jest": {
42 | "testURL": "http://localhost/",
43 | "moduleFileExtensions": [
44 | "js",
45 | "vue"
46 | ],
47 | "moduleNameMapper": {
48 | "^@/(.*)$": "/src/$1"
49 | },
50 | "transform": {
51 | "^.+\\.js$": "/node_modules/babel-jest",
52 | ".*\\.(vue)$": "/node_modules/vue-jest"
53 | },
54 | "snapshotSerializers": [
55 | "/node_modules/jest-serializer-vue"
56 | ]
57 | },
58 | "unpkg": "umd/vue-picture-input.js",
59 | "jsdelivr": "umd/vue-picture-input.js"
60 | }
61 |
--------------------------------------------------------------------------------
/poi.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | entry: './PictureInput.vue',
3 | output: {
4 | fileNames: {
5 | js: 'vue-picture-input.js'
6 | },
7 | moduleName: 'PictureInput',
8 | dir: 'umd',
9 | sourceMap: false,
10 | html: false,
11 | format: 'umd'
12 | },
13 | css: {
14 | extract: false
15 | }
16 | }
--------------------------------------------------------------------------------
/test/PictureInput.spec.js:
--------------------------------------------------------------------------------
1 | import { shallowMount } from '@vue/test-utils'
2 | import { createRenderer } from 'vue-server-renderer'
3 |
4 | import PictureInput from '../PictureInput.vue'
5 |
6 | describe('PictureInput.vue', () => {
7 | it('matches snapshot', () => {
8 | const renderer = createRenderer()
9 | const wrapper = shallowMount(PictureInput)
10 | renderer.renderToString(wrapper.vm, (err, str) => {
11 | if (err) throw new Error(err)
12 | expect(str).toMatchSnapshot()
13 | })
14 | })
15 | })
16 |
--------------------------------------------------------------------------------
/test/__snapshots__/PictureInput.spec.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`PictureInput.vue matches snapshot 1`] = `
4 |
10 | `;
11 |
--------------------------------------------------------------------------------
/umd/vue-picture-input.js:
--------------------------------------------------------------------------------
1 | !function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t():"function"===typeof define&&define.amd?define([],t):"object"===typeof exports?exports.PictureInput=t():e.PictureInput=t()}(window,(function(){return function(e){var t={};function i(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="/",i(i.s=1)}([function(e,t,i){var n=i(3);n.__esModule&&(n=n.default),"string"===typeof n&&(n=[[e.i,n,""]]),n.locals&&(e.exports=n.locals);(0,i(6).default)("812be128",n,!0,{sourceMap:!1})},function(e,t,i){e.exports=i(5)},function(e,t,i){"use strict";i(0)},function(e,t,i){(t=i(4)(!1)).push([e.i,".picture-input[data-v-06a8c132]{width:100%;margin:0 auto;text-align:center}.preview-container[data-v-06a8c132]{width:100%;box-sizing:border-box;margin:0 auto;cursor:pointer;overflow:hidden;transform:translateZ(0)}.picture-preview[data-v-06a8c132]{width:100%;height:100%;position:relative;z-index:10001;box-sizing:border-box;background-color:hsla(0,0%,78.4%,.25)}.picture-preview.dragging-over[data-v-06a8c132]{filter:brightness(.5)}.picture-inner[data-v-06a8c132]{position:relative;z-index:10002;pointer-events:none;box-sizing:border-box;margin:1em auto;padding:.5em;border:.3em dashed rgba(66,66,66,.15);border-radius:8px;width:calc(100% - 2.5em);height:calc(100% - 2.5em);display:table}.picture-inner .picture-inner-text[data-v-06a8c132]{display:table-cell;vertical-align:middle;text-align:center;font-size:2em;line-height:1.5}button[data-v-06a8c132]{margin:1em .25em;cursor:pointer}input[type=file][data-v-06a8c132]{display:none}",""]),e.exports=t},function(e,t,i){"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var i=function(e,t){var i=e[1]||"",n=e[3];if(!n)return i;if(t&&"function"===typeof btoa){var r=function(e){var t=btoa(unescape(encodeURIComponent(JSON.stringify(e)))),i="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(t);return"/*# ".concat(i," */")}(n),a=n.sources.map((function(e){return"/*# sourceURL=".concat(n.sourceRoot||"").concat(e," */")}));return[i].concat(a).concat([r]).join("\n")}return[i].join("\n")}(t,e);return t[2]?"@media ".concat(t[2]," {").concat(i,"}"):i})).join("")},t.i=function(e,i,n){"string"===typeof e&&(e=[[null,e,""]]);var r={};if(n)for(var a=0;aYour device does not support file uploading.",drag:"Drag an image or
click here to select a file",tap:"Tap here to select a photo
from your gallery",change:"Change Photo",aspect:"Landscape/Portrait",remove:"Remove Photo",select:"Select a Photo",selected:"Photo successfully selected!
",fileSize:"The file size exceeds the limit",fileType:"This file type is not supported."}}},mounted:function(){var e=this;if(this.updateStrings(),this.prefill&&this.preloadImage(this.prefill,this.prefillOptions),this.$nextTick((function(){window.addEventListener("resize",e.onResize),e.onResize()})),this.supportsPreview){this.pixelRatio=Math.round(window.devicePixelRatio||window.screen.deviceXDPI/window.screen.logicalXDPI);var t=this.$refs.previewCanvas;t.getContext&&(this.context=t.getContext("2d"),this.context.scale(this.pixelRatio,this.pixelRatio))}"image/*"!==this.accept&&(this.fileTypes=this.accept.split(","),this.fileTypes=this.fileTypes.map((function(e){return e.trim()}))),this.canvasWidth=this.width!=Number.MAX_SAFE_INTEGER?this.width:this.$refs.container.clientWidth,this.canvasHeight=this.height!=Number.MAX_SAFE_INTEGER?this.height:this.canvasWidth,this.previewWidth=this.canvasWidth,this.previewHeight=this.canvasHeight},beforeDestroy:function(){window.removeEventListener("resize",this.onResize)},methods:{updateStrings:function(){for(var e in this.customStrings)e in this.strings&&"string"===typeof this.customStrings[e]&&(this.strings[e]=this.customStrings[e])},onClick:function(){this.imageSelected?(this.changeOnClick&&this.selectImage(),this.$emit("click")):this.selectImage()},onResize:function(){this.resizeCanvas()&&this.imageObject&&this.drawImage(this.imageObject)},onDragEnter:function(){this.supportsDragAndDrop&&(this.draggingOver=!0)},onDragLeave:function(){this.supportsDragAndDrop&&(this.draggingOver=!1)},onFileDrop:function(e){this.onDragLeave(),this.$refs.fileInput.files=e.target.files||e.dataTransfer.files,this.onFileChange(e)},onFileChange:function(e,t){var i=e.target.files||e.dataTransfer.files;if(i.length){if(i[0].size<=0||i[0].size>1024*this.size*1024)return this.$emit("error",{type:"fileSize",fileSize:i[0].size,fileType:i[0].type,fileName:i[0].name,message:this.strings.fileSize+" ("+this.size+"MB)"}),void(this.alertOnError&&alert(this.strings.fileSize+" ("+this.size+"MB)"));if(i[0].name!==this.fileName||i[0].size!==this.fileSize||this.fileModified!==i[0].lastModified){if(this.file=i[0],this.fileName=i[0].name,this.fileSize=i[0].size,this.fileModified=i[0].lastModified,this.fileType=i[0].type.split(";")[0],"image/*"===this.accept){if("image/"!==this.fileType.substr(0,6))return}else if(-1===this.fileTypes.indexOf(this.fileType))return this.$emit("error",{type:"fileType",fileSize:this.fileSize,fileType:this.fileType,fileName:this.fileName,message:this.strings.fileType}),void(this.alertOnError&&alert(this.strings.fileType));this.imageSelected=!0,this.image="",this.supportsPreview?this.loadImage(i[0],t||!1):t?this.$emit("prefill"):this.$emit("change",this.image)}}},loadImage:function(e,t){var i=this;this.getEXIFOrientation(e,(function(t){i.setOrientation(t);var n=new FileReader;n.onload=function(e){i.image=e.target.result,i.imageObject=new Image,i.imageObject.onload=function(){i.autoToggleAspectRatio&&(i.getOrientation(i.canvasWidth,i.canvasHeight)!==i.getOrientation(i.imageObject.width,i.imageObject.height)&&i.rotateCanvas());i.drawImage(i.imageObject)},i.imageObject.src=i.image},n.readAsDataURL(e)}))},drawImage:function(e){this.imageWidth=e.width,this.imageHeight=e.height,this.imageRatio=e.width/e.height;var t=0,i=0,n=this.previewWidth,r=this.previewHeight,a=this.previewWidth/this.previewHeight;this.crop?this.imageRatio>=a?(n=r*this.imageRatio,t=(this.previewWidth-n)/2):(r=n/this.imageRatio,i=(this.previewHeight-r)/2):this.imageRatio>=a?(r=n/this.imageRatio,i=(this.previewHeight-r)/2):(n=r*this.imageRatio,t=(this.previewWidth-n)/2);var s=this.$refs.previewCanvas;s.style.background="none",s.width=this.previewWidth*this.pixelRatio,s.height=this.previewHeight*this.pixelRatio,this.context.setTransform(1,0,0,1,0,0),this.context.clearRect(0,0,s.width,s.height),this.rotate&&"undefined"===typeof this.imageObject.style.imageOrientation&&(this.context.translate(t*this.pixelRatio,i*this.pixelRatio),this.context.translate(n/2*this.pixelRatio,r/2*this.pixelRatio),this.context.rotate(this.rotate),t=-n/2,i=-r/2),this.context.drawImage(e,t*this.pixelRatio,i*this.pixelRatio,n*this.pixelRatio,r*this.pixelRatio)},selectImage:function(){this.$refs.fileInput.click()},removeImage:function(){this.$refs.fileInput.value="",this.$refs.fileInput.type="",this.$refs.fileInput.type="file",this.fileName="",this.fileType="",this.fileSize=0,this.fileModified=0,this.imageSelected=!1,this.image="",this.file=null,this.imageObject=null,this.$refs.previewCanvas.style.backgroundColor="rgba(200,200,200,.25)",this.$refs.previewCanvas.width=this.previewWidth*this.pixelRatio,this.$emit("remove")},rotateImage:function(){this.rotateCanvas(),this.imageObject&&this.drawImage(this.imageObject);var e=this.getOrientation(this.canvasWidth,this.canvasHeight);this.$emit("aspectratiochange",e)},resizeCanvas:function(){var e=this.canvasWidth/this.canvasHeight,t=this.$refs.container.clientWidth;return!!t&&(!(!this.toggleAspectRatio&&!this.autoToggleAspectRatio&&t===this.containerWidth)&&(this.containerWidth=t,this.previewWidth=Math.min(this.containerWidth-2*this.margin,this.canvasWidth),this.previewHeight=this.previewWidth/e,!0))},getOrientation:function(e,t){var i="square";return e>t?i="landscape":e2&&void 0!==arguments[2]?arguments[2]:{};r(this,t);var s=a(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return s.lastModifiedDate=new Date,s.lastModified=+s.lastModifiedDate,s.name=i,s}return function(e,t){if("function"!==typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&s(e,t)}(t,Blob),t}()}if(t=Object.assign({},t),"object"===("undefined"===typeof e?"undefined":n(e)))return this.imageSelected=!0,this.image="",void(this.supportsPreview?this.loadImage(e,!0):this.$emit("prefill"));-1===e.indexOf("data:")&&(-1!==e.indexOf("?")?e+="&_="+(new Date).getTime():e+="?_="+(new Date).getTime());var l=new Headers;l.append("Accept","image/*"),fetch(e,{method:"GET",mode:"cors",headers:l}).then((function(e){return e.blob()})).then((function(n){var r={target:{files:[]}},a=t.fileName||e.split("/").slice(-1)[0],s=t.mediaType||n.type||"image/"+(t.fileType||a.split("?")[0].split(".").slice(-1)[0].split("?")[0]);"image/svg"===(s=(s=s.replace("jpg","jpeg")).replace("image/svg","image/svg+xml"))&&(s="image/svg+xml"),r.target.files[0]=new o([n],a,{type:s}),i.onFileChange(r,!0)})).catch((function(e){i.$emit("error",{type:"failedPrefill",message:"Failed loading prefill image: "+e}),i.alertOnError&&alert("Failed loading prefill image: "+e)}))}},computed:{supportsUpload:function(){if(navigator.userAgent.match(/(Android (1.0|1.1|1.5|1.6|2.0|2.1))|(Windows Phone (OS 7|8.0))|(XBLWP)|(ZuneWP)|(w(eb)?OSBrowser)|(webOS)|(Kindle\/(1.0|2.0|2.5|3.0))/))return!1;var e=document.createElement("input");return e.type="file",!e.disabled},supportsPreview:function(){return window.FileReader&&!!window.CanvasRenderingContext2D},supportsDragAndDrop:function(){var e=document.createElement("div");return("draggable"in e||"ondragstart"in e&&"ondrop"in e)&&!("ontouchstart"in window||navigator.msMaxTouchPoints)},computedClasses:function(){var e={};return e["dragging-over"]=this.draggingOver,e},fontSize:function(){return Math.min(.04*this.previewWidth,21)+"px"}}};i(2);var l=function(e,t,i,n,r,a,s,o){var l,u="function"===typeof e?e.options:e;if(t&&(u.render=t,u.staticRenderFns=i,u._compiled=!0),n&&(u.functional=!0),a&&(u._scopeId="data-v-"+a),s?(l=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"===typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),r&&r.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(s)},u._ssrRegister=l):r&&(l=o?function(){r.call(this,(u.functional?this.parent:this).$root.$options.shadowRoot)}:r),l)if(u.functional){u._injectStyles=l;var c=u.render;u.render=function(e,t){return l.call(t),c(e,t)}}else{var p=u.beforeCreate;u.beforeCreate=p?[].concat(p,l):[l]}return{exports:e,options:u}}(o,(function(){var e=this,t=e._self._c;return t("div",{ref:"container",staticClass:"picture-input",attrs:{id:"picture-input"}},[e.supportsUpload?e.supportsPreview?t("div",[t("div",{staticClass:"preview-container",style:{maxWidth:e.previewWidth+"px",height:e.previewHeight+"px",borderRadius:e.radius+"%"}},[t("canvas",{ref:"previewCanvas",staticClass:"picture-preview",class:e.computedClasses,style:{height:e.previewHeight+"px",zIndex:parseInt(e.zIndex)+1},attrs:{tabindex:"0"},on:{drag:function(e){e.stopPropagation(),e.preventDefault()},dragover:function(e){e.stopPropagation(),e.preventDefault()},dragstart:function(e){e.stopPropagation(),e.preventDefault()},dragend:function(e){e.stopPropagation(),e.preventDefault()},dragenter:function(t){return t.stopPropagation(),t.preventDefault(),e.onDragEnter.apply(null,arguments)},dragleave:function(t){return t.stopPropagation(),t.preventDefault(),e.onDragLeave.apply(null,arguments)},drop:function(t){return t.stopPropagation(),t.preventDefault(),e.onFileDrop.apply(null,arguments)},click:function(t){return t.preventDefault(),e.onClick.apply(null,arguments)},keyup:function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:e.onClick.apply(null,arguments)}}}),e._v(" "),e.imageSelected||e.plain?e._e():t("div",{staticClass:"picture-inner",style:{top:-e.previewHeight+"px",marginBottom:-e.previewHeight+"px",fontSize:e.fontSize,borderRadius:e.radius+"%",zIndex:parseInt(e.zIndex)+2}},[e.supportsDragAndDrop?t("span",{staticClass:"picture-inner-text",domProps:{innerHTML:e._s(e.strings.drag)}}):t("span",{staticClass:"picture-inner-text",domProps:{innerHTML:e._s(e.strings.tap)}})])]),e._v(" "),e.imageSelected&&!e.hideChangeButton?t("button",{class:e.buttonClass,attrs:{type:"button"},on:{click:function(t){return t.preventDefault(),e.selectImage.apply(null,arguments)}}},[e._v(e._s(e.strings.change))]):e._e(),e._v(" "),e.imageSelected&&e.removable?t("button",{class:e.removeButtonClass,attrs:{type:"button"},on:{click:function(t){return t.preventDefault(),e.removeImage.apply(null,arguments)}}},[e._v(e._s(e.strings.remove))]):e._e(),e._v(" "),e.imageSelected&&e.toggleAspectRatio&&e.width!==e.height?t("button",{class:e.aspectButtonClass,attrs:{type:"button"},on:{click:function(t){return t.preventDefault(),e.rotateImage.apply(null,arguments)}}},[e._v(e._s(e.strings.aspect))]):e._e()]):t("div",[e.imageSelected?t("div",[t("div",{domProps:{innerHTML:e._s(e.strings.selected)}}),e._v(" "),e.hideChangeButton?e._e():t("button",{class:e.buttonClass,attrs:{type:"button"},on:{click:function(t){return t.preventDefault(),e.selectImage.apply(null,arguments)}}},[e._v(e._s(e.strings.change))]),e._v(" "),e.removable?t("button",{class:e.removeButtonClass,attrs:{type:"button"},on:{click:function(t){return t.preventDefault(),e.removeImage.apply(null,arguments)}}},[e._v(e._s(e.strings.remove))]):e._e()]):t("button",{class:e.buttonClass,attrs:{type:"button"},on:{click:function(t){return t.preventDefault(),e.selectImage.apply(null,arguments)}}},[e._v(e._s(e.strings.select))])]):t("div",{domProps:{innerHTML:e._s(e.strings.upload)}}),e._v(" "),t("input",{ref:"fileInput",attrs:{type:"file",name:e.name,id:e.id,accept:e.accept,capture:e.capture},on:{change:e.onFileChange}})])}),[],!1,null,"06a8c132",null);t.default=l.exports},function(e,t,i){"use strict";function n(e,t){for(var i=[],n={},r=0;ri.parts.length&&(n.parts.length=i.parts.length)}else{var s=[];for(r=0;r