1
- /*
2
- * This file is part of the Symfony package.
3
- *
4
- * (c) Fabien Potencier <[email protected] >
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- 'use strict' ;
10
-
11
- function _typeof ( obj ) { "@babel/helpers - typeof" ; if ( typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ) { _typeof = function _typeof ( obj ) { return typeof obj ; } ; } else { _typeof = function _typeof ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ; } return _typeof ( obj ) ; }
12
-
13
- Object . defineProperty ( exports , "__esModule" , {
14
- value : true
15
- } ) ;
16
- exports [ "default" ] = void 0 ;
17
-
18
- var _stimulus = require ( "@hotwired/stimulus" ) ;
19
-
20
- var _cropperjs = _interopRequireDefault ( require ( "cropperjs" ) ) ;
21
-
22
- function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { "default" : obj } ; }
23
-
24
- function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
25
-
26
- function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
27
-
28
- function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
29
-
30
- function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function" ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , writable : true , configurable : true } } ) ; if ( superClass ) _setPrototypeOf ( subClass , superClass ) ; }
31
-
32
- function _setPrototypeOf ( o , p ) { _setPrototypeOf = Object . setPrototypeOf || function _setPrototypeOf ( o , p ) { o . __proto__ = p ; return o ; } ; return _setPrototypeOf ( o , p ) ; }
33
-
34
- function _createSuper ( Derived ) { var hasNativeReflectConstruct = _isNativeReflectConstruct ( ) ; return function _createSuperInternal ( ) { var Super = _getPrototypeOf ( Derived ) , result ; if ( hasNativeReflectConstruct ) { var NewTarget = _getPrototypeOf ( this ) . constructor ; result = Reflect . construct ( Super , arguments , NewTarget ) ; } else { result = Super . apply ( this , arguments ) ; } return _possibleConstructorReturn ( this , result ) ; } ; }
35
-
36
- function _possibleConstructorReturn ( self , call ) { if ( call && ( _typeof ( call ) === "object" || typeof call === "function" ) ) { return call ; } return _assertThisInitialized ( self ) ; }
37
-
38
- function _assertThisInitialized ( self ) { if ( self === void 0 ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return self ; }
39
-
40
- function _isNativeReflectConstruct ( ) { if ( typeof Reflect === "undefined" || ! Reflect . construct ) return false ; if ( Reflect . construct . sham ) return false ; if ( typeof Proxy === "function" ) return true ; try { Boolean . prototype . valueOf . call ( Reflect . construct ( Boolean , [ ] , function ( ) { } ) ) ; return true ; } catch ( e ) { return false ; } }
41
-
42
- function _getPrototypeOf ( o ) { _getPrototypeOf = Object . setPrototypeOf ? Object . getPrototypeOf : function _getPrototypeOf ( o ) { return o . __proto__ || Object . getPrototypeOf ( o ) ; } ; return _getPrototypeOf ( o ) ; }
43
-
44
- var _default = /*#__PURE__*/ function ( _Controller ) {
45
- _inherits ( _default , _Controller ) ;
46
-
47
- var _super = _createSuper ( _default ) ;
48
-
49
- function _default ( ) {
50
- _classCallCheck ( this , _default ) ;
51
-
52
- return _super . apply ( this , arguments ) ;
53
- }
54
-
55
- _createClass ( _default , [ {
56
- key : "connect" ,
57
- value : function connect ( ) {
58
- var _this = this ;
59
-
60
- // Create image view
61
- var img = document . createElement ( 'img' ) ;
62
- img . classList . add ( 'cropperjs-image' ) ;
63
- img . src = this . element . getAttribute ( 'data-public-url' ) ;
64
- var parent = this . element . parentNode ;
65
- parent . appendChild ( img ) ; // Build the cropper
66
-
67
- var options = {
68
- viewMode : parseInt ( this . element . getAttribute ( 'data-view-mode' ) ) ,
69
- dragMode : this . element . getAttribute ( 'data-drag-mode' ) ,
70
- responsive : this . element . hasAttribute ( 'data-responsive' ) ,
71
- restore : this . element . hasAttribute ( 'data-restore' ) ,
72
- checkCrossOrigin : this . element . hasAttribute ( 'data-check-cross-origin' ) ,
73
- checkOrientation : this . element . hasAttribute ( 'data-check-orientation' ) ,
74
- modal : this . element . hasAttribute ( 'data-modal' ) ,
75
- guides : this . element . hasAttribute ( 'data-guides' ) ,
76
- center : this . element . hasAttribute ( 'data-center' ) ,
77
- highlight : this . element . hasAttribute ( 'data-highlight' ) ,
78
- background : this . element . hasAttribute ( 'data-background' ) ,
79
- autoCrop : this . element . hasAttribute ( 'data-auto-crop' ) ,
80
- autoCropArea : parseFloat ( this . element . getAttribute ( 'data-auto-crop-area' ) ) ,
81
- movable : this . element . hasAttribute ( 'data-movable' ) ,
82
- rotatable : this . element . hasAttribute ( 'data-rotatable' ) ,
83
- scalable : this . element . hasAttribute ( 'data-scalable' ) ,
84
- zoomable : this . element . hasAttribute ( 'data-zoomable' ) ,
85
- zoomOnTouch : this . element . hasAttribute ( 'data-zoom-on-touch' ) ,
86
- zoomOnWheel : this . element . hasAttribute ( 'data-zoom-on-wheel' ) ,
87
- wheelZoomRatio : parseFloat ( this . element . getAttribute ( 'data-wheel-zoom-ratio' ) ) ,
88
- cropBoxMovable : this . element . hasAttribute ( 'data-crop-box-movable' ) ,
89
- cropBoxResizable : this . element . hasAttribute ( 'data-crop-box-resizable' ) ,
90
- toggleDragModeOnDblclick : this . element . hasAttribute ( 'data-toggle-drag-mode-on-dblclick' ) ,
91
- minContainerWidth : parseInt ( this . element . getAttribute ( 'data-min-container-width' ) ) ,
92
- minContainerHeight : parseInt ( this . element . getAttribute ( 'data-min-container-height' ) ) ,
93
- minCanvasWidth : parseInt ( this . element . getAttribute ( 'data-min-canvas-width' ) ) ,
94
- minCanvasHeight : parseInt ( this . element . getAttribute ( 'data-min-canvas-height' ) ) ,
95
- minCropBoxWidth : parseInt ( this . element . getAttribute ( 'data-min-crop-box-width' ) ) ,
96
- minCropBoxHeight : parseInt ( this . element . getAttribute ( 'data-min-crop-box-height' ) )
97
- } ;
98
-
99
- if ( this . element . getAttribute ( 'data-aspect-ratio' ) ) {
100
- options . aspectRatio = parseFloat ( this . element . getAttribute ( 'data-aspect-ratio' ) ) ;
101
- }
102
-
103
- if ( this . element . getAttribute ( 'data-initial-aspect-ratio' ) ) {
104
- options . initialAspectRatio = parseFloat ( this . element . getAttribute ( 'data-initial-aspect-ratio' ) ) ;
105
- }
106
-
107
- var cropper = new _cropperjs [ "default" ] ( img , options ) ;
108
- img . addEventListener ( 'crop' , function ( event ) {
109
- _this . element . value = JSON . stringify ( event . detail ) ;
110
- } ) ;
111
-
112
- this . _dispatchEvent ( 'cropperjs:connect' , {
113
- cropper : cropper ,
114
- options : options ,
115
- img : img
116
- } ) ;
1
+ import { Controller } from '@hotwired/stimulus' ;
2
+ import Cropper from 'cropperjs' ;
3
+
4
+ class controller extends Controller {
5
+ connect ( ) {
6
+ const img = document . createElement ( 'img' ) ;
7
+ img . classList . add ( 'cropperjs-image' ) ;
8
+ img . src = this . element . getAttribute ( 'data-public-url' ) ;
9
+ const parent = this . element . parentNode ;
10
+ parent . appendChild ( img ) ;
11
+ const options = {
12
+ viewMode : parseInt ( this . element . getAttribute ( 'data-view-mode' ) ) ,
13
+ dragMode : this . element . getAttribute ( 'data-drag-mode' ) ,
14
+ responsive : this . element . hasAttribute ( 'data-responsive' ) ,
15
+ restore : this . element . hasAttribute ( 'data-restore' ) ,
16
+ checkCrossOrigin : this . element . hasAttribute ( 'data-check-cross-origin' ) ,
17
+ checkOrientation : this . element . hasAttribute ( 'data-check-orientation' ) ,
18
+ modal : this . element . hasAttribute ( 'data-modal' ) ,
19
+ guides : this . element . hasAttribute ( 'data-guides' ) ,
20
+ center : this . element . hasAttribute ( 'data-center' ) ,
21
+ highlight : this . element . hasAttribute ( 'data-highlight' ) ,
22
+ background : this . element . hasAttribute ( 'data-background' ) ,
23
+ autoCrop : this . element . hasAttribute ( 'data-auto-crop' ) ,
24
+ autoCropArea : parseFloat ( this . element . getAttribute ( 'data-auto-crop-area' ) ) ,
25
+ movable : this . element . hasAttribute ( 'data-movable' ) ,
26
+ rotatable : this . element . hasAttribute ( 'data-rotatable' ) ,
27
+ scalable : this . element . hasAttribute ( 'data-scalable' ) ,
28
+ zoomable : this . element . hasAttribute ( 'data-zoomable' ) ,
29
+ zoomOnTouch : this . element . hasAttribute ( 'data-zoom-on-touch' ) ,
30
+ zoomOnWheel : this . element . hasAttribute ( 'data-zoom-on-wheel' ) ,
31
+ wheelZoomRatio : parseFloat ( this . element . getAttribute ( 'data-wheel-zoom-ratio' ) ) ,
32
+ cropBoxMovable : this . element . hasAttribute ( 'data-crop-box-movable' ) ,
33
+ cropBoxResizable : this . element . hasAttribute ( 'data-crop-box-resizable' ) ,
34
+ toggleDragModeOnDblclick : this . element . hasAttribute ( 'data-toggle-drag-mode-on-dblclick' ) ,
35
+ minContainerWidth : parseInt ( this . element . getAttribute ( 'data-min-container-width' ) ) ,
36
+ minContainerHeight : parseInt ( this . element . getAttribute ( 'data-min-container-height' ) ) ,
37
+ minCanvasWidth : parseInt ( this . element . getAttribute ( 'data-min-canvas-width' ) ) ,
38
+ minCanvasHeight : parseInt ( this . element . getAttribute ( 'data-min-canvas-height' ) ) ,
39
+ minCropBoxWidth : parseInt ( this . element . getAttribute ( 'data-min-crop-box-width' ) ) ,
40
+ minCropBoxHeight : parseInt ( this . element . getAttribute ( 'data-min-crop-box-height' ) ) ,
41
+ } ;
42
+ if ( this . element . getAttribute ( 'data-aspect-ratio' ) ) {
43
+ options . aspectRatio = parseFloat ( this . element . getAttribute ( 'data-aspect-ratio' ) ) ;
44
+ }
45
+ if ( this . element . getAttribute ( 'data-initial-aspect-ratio' ) ) {
46
+ options . initialAspectRatio = parseFloat ( this . element . getAttribute ( 'data-initial-aspect-ratio' ) ) ;
47
+ }
48
+ const cropper = new Cropper ( img , options ) ;
49
+ img . addEventListener ( 'crop' , ( event ) => {
50
+ this . element . value = JSON . stringify ( event . detail ) ;
51
+ } ) ;
52
+ this . _dispatchEvent ( 'cropperjs:connect' , { cropper, options, img } ) ;
117
53
}
118
- } , {
119
- key : "_dispatchEvent" ,
120
- value : function _dispatchEvent ( name ) {
121
- var payload = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : null ;
122
- var canBubble = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : false ;
123
- var cancelable = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : false ;
124
- var userEvent = document . createEvent ( 'CustomEvent' ) ;
125
- userEvent . initCustomEvent ( name , canBubble , cancelable , payload ) ;
126
- this . element . dispatchEvent ( userEvent ) ;
54
+ _dispatchEvent ( name , payload = null , canBubble = false , cancelable = false ) {
55
+ const userEvent = document . createEvent ( 'CustomEvent' ) ;
56
+ userEvent . initCustomEvent ( name , canBubble , cancelable , payload ) ;
57
+ this . element . dispatchEvent ( userEvent ) ;
127
58
}
128
- } ] ) ;
129
-
130
- return _default ;
131
- } ( _stimulus . Controller ) ;
59
+ }
132
60
133
- exports [ "default" ] = _default ;
61
+ export { controller as default } ;
0 commit comments