dpzvc-ui 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/README.md +102 -18
  2. package/build-style.js +56 -29
  3. package/dist/dpzvc.js +9132 -13154
  4. package/dist/dpzvc.js.map +1 -0
  5. package/dist/dpzvc.min.js +2 -0
  6. package/dist/dpzvc.min.js.map +1 -0
  7. package/dist/styles/base/font.css +1 -0
  8. package/dist/styles/base/reset.css +1 -0
  9. package/dist/styles/base/variable.css +0 -0
  10. package/dist/styles/components/actionSheet.css +1 -0
  11. package/dist/styles/components/badge.css +1 -0
  12. package/dist/styles/components/button.css +1 -0
  13. package/dist/styles/components/card.css +1 -0
  14. package/dist/styles/components/cell-swipe.css +1 -0
  15. package/dist/styles/components/cell.css +1 -0
  16. package/dist/styles/components/checkBox.css +1 -0
  17. package/dist/styles/components/editor.css +1 -0
  18. package/dist/styles/components/header.css +1 -0
  19. package/dist/styles/components/indicator.css +1 -0
  20. package/dist/styles/components/loadmore.css +1 -0
  21. package/dist/styles/components/message.css +1 -0
  22. package/dist/styles/components/modal.css +1 -0
  23. package/dist/styles/components/number.css +1 -0
  24. package/dist/styles/components/picker.css +1 -0
  25. package/dist/styles/components/popup.css +1 -0
  26. package/dist/styles/components/progress.css +1 -0
  27. package/dist/styles/components/prompt.css +1 -0
  28. package/dist/styles/components/radioBox.css +1 -0
  29. package/dist/styles/components/slide-Bar.css +1 -0
  30. package/dist/styles/components/spinner.css +1 -0
  31. package/dist/styles/components/swipe.css +1 -0
  32. package/dist/styles/components/switchBar.css +1 -0
  33. package/dist/styles/components/tab.css +1 -0
  34. package/dist/styles/components/text.css +1 -0
  35. package/dist/styles/components/toTop.css +1 -0
  36. package/dist/styles/components/upload.css +1 -0
  37. package/dist/styles/utils/1px.css +1 -0
  38. package/dist/styles/utils/animation.css +1 -0
  39. package/dist/styles/utils/nowrap.css +1 -0
  40. package/dist-prod/968.b06f8ff038ced2ac25a8.js +3 -0
  41. package/dist-prod/968.b06f8ff038ced2ac25a8.js.LICENSE.txt +5 -0
  42. package/dist-prod/968.b06f8ff038ced2ac25a8.js.map +1 -0
  43. package/dist-prod/actionsheet.6c90edde5704622a1342.chunk.js +2 -0
  44. package/dist-prod/actionsheet.6c90edde5704622a1342.chunk.js.map +1 -0
  45. package/dist-prod/badge.c84c021f3e486ef7d942.chunk.js +2 -0
  46. package/dist-prod/badge.c84c021f3e486ef7d942.chunk.js.map +1 -0
  47. package/dist-prod/button.367cc8c72a5fe6ab23f9.chunk.js +2 -0
  48. package/dist-prod/button.367cc8c72a5fe6ab23f9.chunk.js.map +1 -0
  49. package/dist-prod/card.9408612c4388b6dfa16c.chunk.js +2 -0
  50. package/dist-prod/card.9408612c4388b6dfa16c.chunk.js.map +1 -0
  51. package/dist-prod/cell.9a4993caa97ef40ff5c1.chunk.js +2 -0
  52. package/dist-prod/cell.9a4993caa97ef40ff5c1.chunk.js.map +1 -0
  53. package/dist-prod/cellswipe.2f66e4563a8b0ea4e66a.chunk.js +2 -0
  54. package/dist-prod/cellswipe.2f66e4563a8b0ea4e66a.chunk.js.map +1 -0
  55. package/dist-prod/checkbox.bfb070917fbd916b9246.chunk.js +2 -0
  56. package/dist-prod/checkbox.bfb070917fbd916b9246.chunk.js.map +1 -0
  57. package/dist-prod/guide.92857dbbd3214f172073.chunk.js +2 -0
  58. package/dist-prod/guide.92857dbbd3214f172073.chunk.js.map +1 -0
  59. package/dist-prod/header.ad70269632b1900dc1f0.chunk.js +2 -0
  60. package/dist-prod/header.ad70269632b1900dc1f0.chunk.js.map +1 -0
  61. package/dist-prod/index.html +19 -26
  62. package/dist-prod/indicator.791ff82f539499ebcc6b.chunk.js +2 -0
  63. package/dist-prod/indicator.791ff82f539499ebcc6b.chunk.js.map +1 -0
  64. package/dist-prod/loadmore.766550bbcff49be9ca23.chunk.js +2 -0
  65. package/dist-prod/loadmore.766550bbcff49be9ca23.chunk.js.map +1 -0
  66. package/dist-prod/main.87546d094b4cc2de2d01.js +2 -0
  67. package/dist-prod/main.87546d094b4cc2de2d01.js.map +1 -0
  68. package/dist-prod/main.c3a7cb52315b8816357b.js +2 -0
  69. package/dist-prod/main.c3a7cb52315b8816357b.js.map +1 -0
  70. package/dist-prod/message.878a621e560c57ca9f90.chunk.js +2 -0
  71. package/dist-prod/message.878a621e560c57ca9f90.chunk.js.map +1 -0
  72. package/dist-prod/modal.e4087ee82601de76b61d.chunk.js +2 -0
  73. package/dist-prod/modal.e4087ee82601de76b61d.chunk.js.map +1 -0
  74. package/dist-prod/picker.3cfdf594676698f7ef0b.chunk.js +2 -0
  75. package/dist-prod/picker.3cfdf594676698f7ef0b.chunk.js.map +1 -0
  76. package/dist-prod/popup.f46d0b3c57b2f2d0dfe3.chunk.js +2 -0
  77. package/dist-prod/popup.f46d0b3c57b2f2d0dfe3.chunk.js.map +1 -0
  78. package/dist-prod/progress.dd5c95445a81a94ae446.chunk.js +2 -0
  79. package/dist-prod/progress.dd5c95445a81a94ae446.chunk.js.map +1 -0
  80. package/dist-prod/prompt.793312afaee597d3e887.chunk.js +2 -0
  81. package/dist-prod/prompt.793312afaee597d3e887.chunk.js.map +1 -0
  82. package/dist-prod/radiobox.f684060ebfc8df084d9c.chunk.js +2 -0
  83. package/dist-prod/radiobox.f684060ebfc8df084d9c.chunk.js.map +1 -0
  84. package/dist-prod/rater.18672a3b68842b5ec0ae.chunk.js +2 -0
  85. package/dist-prod/rater.18672a3b68842b5ec0ae.chunk.js.map +1 -0
  86. package/dist-prod/slidebar.58eb1b07a6995df3fc47.chunk.js +2 -0
  87. package/dist-prod/slidebar.58eb1b07a6995df3fc47.chunk.js.map +1 -0
  88. package/dist-prod/spinner.2c686ac402a1e1b29270.chunk.js +2 -0
  89. package/dist-prod/spinner.2c686ac402a1e1b29270.chunk.js.map +1 -0
  90. package/dist-prod/swipe.dcc1ebcc206dae26a67e.chunk.js +2 -0
  91. package/dist-prod/swipe.dcc1ebcc206dae26a67e.chunk.js.map +1 -0
  92. package/dist-prod/switchbar.91b45e05df73e20227ce.chunk.js +2 -0
  93. package/dist-prod/switchbar.91b45e05df73e20227ce.chunk.js.map +1 -0
  94. package/dist-prod/tab.b351fd11783b6de80246.chunk.js +2 -0
  95. package/dist-prod/tab.b351fd11783b6de80246.chunk.js.map +1 -0
  96. package/dist-prod/text.c41d6ba9644f7037d1e3.chunk.js +2 -0
  97. package/dist-prod/text.c41d6ba9644f7037d1e3.chunk.js.map +1 -0
  98. package/dist-prod/totop.cb15a38b541189094b32.chunk.js +2 -0
  99. package/dist-prod/totop.cb15a38b541189094b32.chunk.js.map +1 -0
  100. package/dist-prod/upload.e953d4a54b0a230de7d6.chunk.js +2 -0
  101. package/dist-prod/upload.e953d4a54b0a230de7d6.chunk.js.map +1 -0
  102. package/dist-prod/vendors.5b7cff021a01dbbbcdf2.js +3 -0
  103. package/dist-prod/vendors.5b7cff021a01dbbbcdf2.js.LICENSE.txt +5 -0
  104. package/dist-prod/vendors.5b7cff021a01dbbbcdf2.js.map +1 -0
  105. package/package.json +33 -27
  106. package/postcss.config.js +5 -0
  107. package/src/components/app.vue +1 -1
  108. package/src/components/upload/upload.vue +2 -1
  109. package/src/config/config.js +1 -1
  110. package/src/index.js +115 -49
  111. package/src/lib/MegaPixImage.js +59 -154
  112. package/src/main.js +18 -60
  113. package/src/router.js +30 -223
  114. package/src/styles/base/reset.less +77 -11
  115. package/src/styles/components/badge.less +2 -0
  116. package/src/styles/components/button.less +1 -0
  117. package/src/styles/components/checkBox.less +2 -0
  118. package/src/styles/components/header.less +2 -0
  119. package/src/styles/components/indicator.less +2 -0
  120. package/src/styles/components/modal.less +2 -0
  121. package/src/styles/components/number.less +2 -0
  122. package/src/styles/components/picker.less +2 -0
  123. package/src/styles/components/progress.less +2 -0
  124. package/src/styles/components/radioBox.less +2 -0
  125. package/src/styles/components/slide-Bar.less +2 -0
  126. package/src/styles/components/spinner.less +1 -0
  127. package/src/styles/components/tab.less +2 -0
  128. package/src/styles/components/text.less +2 -0
  129. package/src/styles/components/toTop.less +2 -0
  130. package/src/styles/utils/1px.less +2 -0
  131. package/src/styles/utils/nowrap.less +1 -1
  132. package/src/template/index.ejs +34 -20
  133. package/src/utils/util.js +1 -1
  134. package/src/views/Header.vue +6 -6
  135. package/src/views/Progress.vue +2 -2
  136. package/webpack.base.config.js +77 -70
  137. package/webpack.dev.config.js +39 -66
  138. package/webpack.dist.dev.config.js +45 -40
  139. package/webpack.dist.prod.config.js +54 -46
  140. package/webpack.prod.config.js +41 -70
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "dpzvc-ui",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Vue组件库",
5
5
  "main": "dist/dpzvc.js",
6
6
  "scripts": {
7
7
  "init": "webpack --progress --config webpack.dev.config.js",
8
- "dev": "webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js",
8
+ "dev": "webpack serve --config webpack.dev.config.js --open",
9
9
  "build:style": "gulp --gulpfile build-style.js",
10
10
  "build:dev": "webpack --config webpack.dist.dev.config.js",
11
- "build:prod": "webpack -p --config webpack.dist.prod.config.js",
11
+ "build:prod": "webpack --config webpack.dist.prod.config.js",
12
12
  "build": "npm run build:style && npm run build:dev && npm run build:prod",
13
- "dist": "webpack --progress --hide-modules --config webpack.prod.config.js"
13
+ "dist": "webpack --progress --config webpack.prod.config.js"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
@@ -26,55 +26,61 @@
26
26
  "dependencies": {
27
27
  "china-area-data": "^3.0.0",
28
28
  "core-js": "^2.4.1",
29
- "deepmerge": "^1.3.1",
30
- "vue": "^2.3.2"
29
+ "deepmerge": "^1.3.1"
31
30
  },
32
31
  "devDependencies": {
32
+ "@babel/core": "^7.28.5",
33
+ "@babel/plugin-transform-runtime": "^7.28.5",
34
+ "@babel/preset-env": "^7.28.5",
35
+ "@babel/runtime": "^7.28.4",
33
36
  "autoprefixer": "^10.4.23",
34
37
  "autoprefixer-loader": "^2.0.0",
35
38
  "babel": "^6.23.0",
36
- "babel-core": "^6.25.0",
37
- "babel-loader": "^6.2.4",
39
+ "babel-core": "^6.26.3",
40
+ "babel-loader": "^8.4.1",
38
41
  "babel-plugin-transform-object-rest-spread": "^6.23.0",
39
- "babel-plugin-transform-runtime": "^6.12.0",
40
- "babel-preset-es2015": "^6.9.0",
42
+ "babel-plugin-transform-runtime": "^6.23.0",
43
+ "babel-preset-es2015": "^6.24.1",
41
44
  "babel-preset-latest": "^6.24.1",
42
45
  "babel-preset-stage-0": "^6.24.1",
43
- "babel-runtime": "^6.23.0",
46
+ "babel-runtime": "^6.26.0",
44
47
  "cross-env": "^3.1.4",
45
- "css-loader": "^0.23.1",
48
+ "css-loader": "^6.11.0",
46
49
  "eslint": "^3.12.2",
47
50
  "eslint-plugin-html": "^1.7.0",
48
51
  "exif-js": "^2.2.1",
49
- "extract-text-webpack-plugin": "^2.1.2",
50
52
  "file-loader": "^0.8.5",
51
- "friendly-errors-webpack-plugin": "^1.6.1",
52
53
  "function-bind": "^1.1.0",
53
54
  "gh-pages": "^6.3.0",
54
55
  "gulp": "^4.0.2",
55
56
  "gulp-clean-css": "^4.3.0",
56
57
  "gulp-cli": "^2.3.0",
58
+ "gulp-header": "^2.0.9",
57
59
  "gulp-less": "^5.0.0",
58
60
  "gulp-postcss": "^10.0.0",
59
61
  "gulp-rename": "^2.1.0",
60
62
  "html-loader": "^0.3.0",
61
- "html-webpack-plugin": "^2.28.0",
63
+ "html-webpack-plugin": "^5.6.5",
62
64
  "less": "^4.5.1",
63
- "less-loader": "^2.2.3",
65
+ "less-loader": "^11.1.4",
64
66
  "lolex": "^1.5.2",
65
- "postcss-loader": "^2.0.9",
66
- "style-loader": "^0.13.1",
67
- "url-loader": "^0.5.7",
68
- "vue": "^2.2.1",
67
+ "mini-css-extract-plugin": "^2.9.4",
68
+ "postcss": "^8.5.6",
69
+ "postcss-loader": "^6.2.1",
70
+ "style-loader": "^3.3.4",
71
+ "terser-webpack-plugin": "^4.2.3",
72
+ "url-loader": "^0.5.9",
73
+ "vue": "^2.7.16",
69
74
  "vue-hot-reload-api": "^1.3.3",
70
75
  "vue-html-loader": "^1.2.3",
71
- "vue-loader": "^11.0.0",
72
- "vue-router": "^2.2.1",
73
- "vue-style-loader": "^1.0.0",
74
- "vue-template-compiler": "^2.2.1",
75
- "webpack": "^2.2.1",
76
- "webpack-dev-server": "^2.4.1",
77
- "webpack-merge": "^3.0.0"
76
+ "vue-loader": "^15.11.1",
77
+ "vue-router": "^3.6.5",
78
+ "vue-style-loader": "^4.1.3",
79
+ "vue-template-compiler": "^2.7.16",
80
+ "webpack": "^5.104.1",
81
+ "webpack-cli": "^5.1.4",
82
+ "webpack-dev-server": "^4.15.2",
83
+ "webpack-merge": "^5.10.0"
78
84
  },
79
85
  "author": "yishide",
80
86
  "license": "MIT",
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ plugins: [
3
+ require('autoprefixer')()
4
+ ]
5
+ }
@@ -1,5 +1,5 @@
1
1
 
2
- <style rel="stylesheet/less" lang="less">
2
+ <style lang="less">
3
3
  // @import '../styles/common.css';
4
4
 
5
5
  // @import '../../src/styles/index';
@@ -10,7 +10,8 @@
10
10
  <script>
11
11
 
12
12
  import EXIF from 'exif-js'
13
- import MegaPixImage from '../../lib/MegaPixImage'
13
+ // import MegaPixImage from '../../lib/MegaPixImage'
14
+ import * as MegaPixImage from '../../lib/MegaPixImage';
14
15
  import { JPEG } from '../../utils/util'
15
16
  const prefixCls = 'dpzvc-upload';
16
17
  export default {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Created by lcfevr on 16/7/18.
2
+ * Created by yishide on 16/7/18.
3
3
  */
4
4
 
5
5
 
package/src/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  /**
2
- * Created by admin on 2017/5/15.
2
+ * Created by admin on 2025/12/15.
3
3
  */
4
4
 
5
- import VButton from '@/button'
5
+ /* ========= 组件引入(保持你原有结构) ========= */
6
+
7
+ import VButton from './components/button'
6
8
  import CheckBox from './components/checkBox'
7
9
  import Header from './components/Header'
8
10
  import Message from './components/message'
@@ -15,7 +17,7 @@ import Prompt from './components/prompt'
15
17
  import SlideBar from './components/slideBar'
16
18
  import TextBar from './components/Text'
17
19
  import Upload from './components/upload'
18
- import ActionSheet from '@/action-sheet'
20
+ import ActionSheet from './components/action-sheet'
19
21
  import SwitchBar from './components/switchbar'
20
22
  import Rater from './components/rater'
21
23
  import Spinner from './components/spinner'
@@ -29,55 +31,119 @@ import CellSwipe from './components/cell-swipe'
29
31
  import Badge from './components/badge'
30
32
  import Card from './components/card'
31
33
 
32
- const dpzvc = {
33
-
34
- VButton,
35
- CheckBox,
36
- CheckBoxGroup:CheckBox.group,
37
- Radio,
38
- RadioGroup:Radio.group,
39
- Header,
40
- Message,
41
- Modal,
42
- Prompt,
43
- Picker,
44
- Swipe,
45
- Tab,
46
- SlideBar,
47
- TextBar,
48
- Number:TextBar.Number,
49
- Upload,
50
- ActionSheet,
51
- SwitchBar,
52
- Rater,
53
- Spinner,
54
- LoadMore,
55
- Popup,
56
- Indicator,
57
- Progress,
58
- ToTop,
59
- Cell,
60
- CellSwipe,
61
- Badge,
62
- Card
63
- };
64
-
65
- const install = (Vue,options)=>{
66
-
67
- Object.keys(dpzvc).forEach((key)=>{
68
- Vue.component(key,dpzvc[key])
69
- });
70
-
71
-
72
- Vue.prototype.$Message = Message;
73
- Vue.prototype.$Modal = Modal;
74
- Vue.prototype.$Prompt = Prompt;
75
- Vue.prototype.$Indicator = Indicator
34
+ /* ========= 组件集合(用于全量注册) ========= */
35
+
36
+ const components = {
37
+ VButton,
38
+ CheckBox,
39
+ CheckBoxGroup: CheckBox.group,
40
+ Radio,
41
+ RadioGroup: Radio.group,
42
+ DpHeader: Header,
43
+ Picker,
44
+ Swipe,
45
+ Tab,
46
+ SlideBar,
47
+ TextBar,
48
+ Number: TextBar.Number,
49
+ Upload,
50
+ ActionSheet,
51
+ SwitchBar,
52
+ Rater,
53
+ Spinner,
54
+ LoadMore,
55
+ Popup,
56
+ DpProgress: Progress,
57
+ ToTop,
58
+ Cell,
59
+ CellSwipe,
60
+ Badge,
61
+ Card
62
+ }
63
+
64
+ /* ========= 服务组件 ========= */
65
+
66
+ const services = {
67
+ Message,
68
+ Modal,
69
+ Prompt,
70
+ Indicator
71
+ }
72
+
73
+ /* ========= 给“单个组件”补 install(关键) ========= */
74
+
75
+ Object.keys(components).forEach(key => {
76
+ const component = components[key]
77
+ if (!component.install) {
78
+ component.install = function (Vue) {
79
+ Vue.component(key, component)
80
+ }
81
+ }
82
+ })
76
83
 
84
+ Object.keys(services).forEach(key => {
85
+ const service = services[key]
86
+ if (!service.install) {
87
+ service.install = function (Vue) {
88
+ Vue.prototype[`$${key}`] = service
89
+ }
90
+ }
91
+ })
92
+
93
+ /* ========= 全量 install ========= */
94
+
95
+ const install = function (Vue) {
96
+ if (install.installed) return
97
+ install.installed = true
98
+
99
+ // 注册组件
100
+ Object.keys(components).forEach(key => {
101
+ Vue.component(key, components[key])
102
+ })
103
+
104
+ // 注册服务
105
+ Object.keys(services).forEach(key => {
106
+ Vue.prototype[`$${key}`] = services[key]
107
+ })
77
108
  }
78
109
 
110
+ /* ========= 自动安装(script 方式) ========= */
111
+
79
112
  if (typeof window !== 'undefined' && window.Vue) {
80
- install(window.Vue);
113
+ install(window.Vue)
114
+ }
115
+
116
+ /* ========= 按需导出 + 默认导出 ========= */
117
+
118
+ export {
119
+ VButton,
120
+ CheckBox,
121
+ Header,
122
+ Message,
123
+ Modal,
124
+ Prompt,
125
+ Picker,
126
+ Radio,
127
+ Swipe,
128
+ Tab,
129
+ SlideBar,
130
+ TextBar,
131
+ Upload,
132
+ ActionSheet,
133
+ SwitchBar,
134
+ Rater,
135
+ Spinner,
136
+ LoadMore,
137
+ Popup,
138
+ Indicator,
139
+ Progress,
140
+ ToTop,
141
+ Cell,
142
+ CellSwipe,
143
+ Badge,
144
+ Card
81
145
  }
82
146
 
83
- module.exports = Object.assign(dpzvc, {install});
147
+ export default {
148
+ install
149
+ }
@@ -1,29 +1,30 @@
1
- (function() {
1
+ // MegaPixImage.js
2
+ (function (global, factory) {
3
+ if (typeof module === 'object' && typeof module.exports === 'object') {
4
+ module.exports = factory(); // CommonJS
5
+ } else if (typeof define === 'function' && define.amd) {
6
+ define([], factory); // AMD
7
+ } else {
8
+ global.MegaPixImage = factory(); // Browser global
9
+ }
10
+ }(typeof window !== 'undefined' ? window : this, function () {
2
11
 
3
- /**
4
- * Detect subsampling in loaded image.
5
- * In iOS, larger images than 2M pixels may be subsampled in rendering.
6
- */
12
+ // -------------------------
13
+ // Helper functions
14
+ // -------------------------
7
15
  function detectSubsampling(img) {
8
16
  var iw = img.naturalWidth, ih = img.naturalHeight;
9
- if (iw * ih > 1024 * 1024) { // subsampling may happen over megapixel image
17
+ if (iw * ih > 1024 * 1024) {
10
18
  var canvas = document.createElement('canvas');
11
19
  canvas.width = canvas.height = 1;
12
20
  var ctx = canvas.getContext('2d');
13
21
  ctx.drawImage(img, -iw + 1, 0);
14
- // subsampled image becomes half smaller in rendering size.
15
- // check alpha channel value to confirm image is covering edge pixel or not.
16
- // if alpha value is 0 image is not covering, hence subsampled.
17
22
  return ctx.getImageData(0, 0, 1, 1).data[3] === 0;
18
23
  } else {
19
24
  return false;
20
25
  }
21
26
  }
22
27
 
23
- /**
24
- * Detecting vertical squash in loaded image.
25
- * Fixes a bug which squash image vertically while drawing into canvas for some images.
26
- */
27
28
  function detectVerticalSquash(img, iw, ih) {
28
29
  var canvas = document.createElement('canvas');
29
30
  canvas.width = 1;
@@ -31,142 +32,78 @@
31
32
  var ctx = canvas.getContext('2d');
32
33
  ctx.drawImage(img, 0, 0);
33
34
  var data = ctx.getImageData(0, 0, 1, ih).data;
34
- // search image edge pixel position in case it is squashed vertically.
35
- var sy = 0;
36
- var ey = ih;
37
- var py = ih;
35
+ var sy = 0, ey = ih, py = ih;
38
36
  while (py > sy) {
39
37
  var alpha = data[(py - 1) * 4 + 3];
40
- if (alpha === 0) {
41
- ey = py;
42
- } else {
43
- sy = py;
44
- }
38
+ if (alpha === 0) { ey = py; } else { sy = py; }
45
39
  py = (ey + sy) >> 1;
46
40
  }
47
- var ratio = (py / ih);
48
- return (ratio===0)?1:ratio;
41
+ var ratio = py / ih;
42
+ return (ratio === 0) ? 1 : ratio;
49
43
  }
50
44
 
51
- /**
52
- * Rendering image element (with resizing) and get its data URL
53
- */
54
45
  function renderImageToDataURL(img, options, doSquash) {
55
46
  var canvas = document.createElement('canvas');
56
47
  renderImageToCanvas(img, canvas, options, doSquash);
57
48
  return canvas.toDataURL("image/jpeg", options.quality || 0.8);
58
49
  }
59
50
 
60
- /**
61
- * Rendering image element (with resizing) into the canvas element
62
- */
63
51
  function renderImageToCanvas(img, canvas, options, doSquash) {
64
52
  var iw = img.naturalWidth, ih = img.naturalHeight;
65
- if (!(iw+ih)) return;
53
+ if (!(iw + ih)) return;
66
54
  var width = options.width, height = options.height;
67
55
  var ctx = canvas.getContext('2d');
68
56
  ctx.save();
69
57
  transformCoordinate(canvas, ctx, width, height, options.orientation);
70
58
  var subsampled = detectSubsampling(img);
71
- if (subsampled) {
72
- iw /= 2;
73
- ih /= 2;
74
- }
75
- var d = 1024; // size of tiling canvas
59
+ if (subsampled) { iw /= 2; ih /= 2; }
60
+ var d = 1024;
76
61
  var tmpCanvas = document.createElement('canvas');
77
62
  tmpCanvas.width = tmpCanvas.height = d;
78
63
  var tmpCtx = tmpCanvas.getContext('2d');
79
64
  var vertSquashRatio = doSquash ? detectVerticalSquash(img, iw, ih) : 1;
80
65
  var dw = Math.ceil(d * width / iw);
81
66
  var dh = Math.ceil(d * height / ih / vertSquashRatio);
82
- var sy = 0;
83
- var dy = 0;
67
+ var sy = 0, dy = 0;
84
68
  while (sy < ih) {
85
- var sx = 0;
86
- var dx = 0;
69
+ var sx = 0, dx = 0;
87
70
  while (sx < iw) {
88
71
  tmpCtx.clearRect(0, 0, d, d);
89
72
  tmpCtx.drawImage(img, -sx, -sy);
90
73
  ctx.drawImage(tmpCanvas, 0, 0, d, d, dx, dy, dw, dh);
91
- sx += d;
92
- dx += dw;
74
+ sx += d; dx += dw;
93
75
  }
94
- sy += d;
95
- dy += dh;
76
+ sy += d; dy += dh;
96
77
  }
97
78
  ctx.restore();
98
79
  tmpCanvas = tmpCtx = null;
99
80
  }
100
81
 
101
- /**
102
- * Transform canvas coordination according to specified frame size and orientation
103
- * Orientation value is from EXIF tag
104
- */
105
82
  function transformCoordinate(canvas, ctx, width, height, orientation) {
106
83
  switch (orientation) {
107
- case 5:
108
- case 6:
109
- case 7:
110
- case 8:
111
- canvas.width = height;
112
- canvas.height = width;
113
- break;
114
- default:
115
- canvas.width = width;
116
- canvas.height = height;
84
+ case 5: case 6: case 7: case 8: canvas.width = height; canvas.height = width; break;
85
+ default: canvas.width = width; canvas.height = height;
117
86
  }
118
87
  switch (orientation) {
119
- case 2:
120
- // horizontal flip
121
- ctx.translate(width, 0);
122
- ctx.scale(-1, 1);
123
- break;
124
- case 3:
125
- // 180 rotate left
126
- ctx.translate(width, height);
127
- ctx.rotate(Math.PI);
128
- break;
129
- case 4:
130
- // vertical flip
131
- ctx.translate(0, height);
132
- ctx.scale(1, -1);
133
- break;
134
- case 5:
135
- // vertical flip + 90 rotate right
136
- ctx.rotate(0.5 * Math.PI);
137
- ctx.scale(1, -1);
138
- break;
139
- case 6:
140
- // 90 rotate right
141
- ctx.rotate(0.5 * Math.PI);
142
- ctx.translate(0, -height);
143
- break;
144
- case 7:
145
- // horizontal flip + 90 rotate right
146
- ctx.rotate(0.5 * Math.PI);
147
- ctx.translate(width, -height);
148
- ctx.scale(-1, 1);
149
- break;
150
- case 8:
151
- // 90 rotate left
152
- ctx.rotate(-0.5 * Math.PI);
153
- ctx.translate(-width, 0);
154
- break;
155
- default:
156
- break;
88
+ case 2: ctx.translate(width, 0); ctx.scale(-1, 1); break;
89
+ case 3: ctx.translate(width, height); ctx.rotate(Math.PI); break;
90
+ case 4: ctx.translate(0, height); ctx.scale(1, -1); break;
91
+ case 5: ctx.rotate(0.5 * Math.PI); ctx.scale(1, -1); break;
92
+ case 6: ctx.rotate(0.5 * Math.PI); ctx.translate(0, -height); break;
93
+ case 7: ctx.rotate(0.5 * Math.PI); ctx.translate(width, -height); ctx.scale(-1, 1); break;
94
+ case 8: ctx.rotate(-0.5 * Math.PI); ctx.translate(-width, 0); break;
157
95
  }
158
96
  }
159
97
 
160
98
  var URL = window.URL && window.URL.createObjectURL ? window.URL :
161
- window.webkitURL && window.webkitURL.createObjectURL ? window.webkitURL :
162
- null;
99
+ window.webkitURL && window.webkitURL.createObjectURL ? window.webkitURL : null;
163
100
 
164
- /**
165
- * MegaPixImage class
166
- */
101
+ // -------------------------
102
+ // MegaPixImage class
103
+ // -------------------------
167
104
  function MegaPixImage(srcImage) {
168
105
  if (window.Blob && srcImage instanceof Blob) {
169
- if (!URL) { throw Error("No createObjectURL function found to create blob url"); }
106
+ if (!URL) { throw Error("No createObjectURL function found"); }
170
107
  var img = new Image();
171
108
  img.src = URL.createObjectURL(srcImage);
172
109
  this.blob = srcImage;
@@ -174,13 +111,11 @@
174
111
  }
175
112
  if (!srcImage.naturalWidth && !srcImage.naturalHeight) {
176
113
  var _this = this;
177
- srcImage.onload = srcImage.onerror = function() {
114
+ srcImage.onload = srcImage.onerror = function () {
178
115
  var listeners = _this.imageLoadListeners;
179
116
  if (listeners) {
180
117
  _this.imageLoadListeners = null;
181
- for (var i=0, len=listeners.length; i<len; i++) {
182
- listeners[i]();
183
- }
118
+ for (var i = 0; i < listeners.length; i++) { listeners[i](); }
184
119
  }
185
120
  };
186
121
  this.imageLoadListeners = [];
@@ -188,13 +123,10 @@
188
123
  this.srcImage = srcImage;
189
124
  }
190
125
 
191
- /**
192
- * Rendering megapix image into specified target element
193
- */
194
- MegaPixImage.prototype.render = function(target, options, callback) {
126
+ MegaPixImage.prototype.render = function (target, options, callback) {
195
127
  if (this.imageLoadListeners) {
196
128
  var _this = this;
197
- this.imageLoadListeners.push(function() { _this.render(target, options, callback); });
129
+ this.imageLoadListeners.push(function () { _this.render(target, options, callback); });
198
130
  return;
199
131
  }
200
132
  options = options || {};
@@ -202,52 +134,25 @@
202
134
  width = options.width, height = options.height,
203
135
  maxWidth = options.maxWidth, maxHeight = options.maxHeight,
204
136
  doSquash = !this.blob || this.blob.type === 'image/jpeg';
205
- if (width && !height) {
206
- height = (imgHeight * width / imgWidth) << 0;
207
- } else if (height && !width) {
208
- width = (imgWidth * height / imgHeight) << 0;
209
- } else {
210
- width = imgWidth;
211
- height = imgHeight;
212
- }
213
- if (maxWidth && width > maxWidth) {
214
- width = maxWidth;
215
- height = (imgHeight * width / imgWidth) << 0;
216
- }
217
- if (maxHeight && height > maxHeight) {
218
- height = maxHeight;
219
- width = (imgWidth * height / imgHeight) << 0;
220
- }
221
- var opt = { width : width, height : height };
137
+ if (width && !height) { height = (imgHeight * width / imgWidth) << 0; }
138
+ else if (height && !width) { width = (imgWidth * height / imgHeight) << 0; }
139
+ else { width = imgWidth; height = imgHeight; }
140
+ if (maxWidth && width > maxWidth) { width = maxWidth; height = (imgHeight * width / imgWidth) << 0; }
141
+ if (maxHeight && height > maxHeight) { height = maxHeight; width = (imgWidth * height / imgHeight) << 0; }
142
+ var opt = { width: width, height: height };
222
143
  for (var k in options) opt[k] = options[k];
223
144
 
224
145
  var tagName = target.tagName.toLowerCase();
225
- if (tagName === 'img') {
226
- target.src = renderImageToDataURL(this.srcImage, opt, doSquash);
227
- } else if (tagName === 'canvas') {
228
- renderImageToCanvas(this.srcImage, target, opt, doSquash);
229
- }
230
- if (typeof this.onrender === 'function') {
231
- this.onrender(target);
232
- }
233
- if (callback) {
234
- callback();
235
- }
236
- if (this.blob) {
237
- this.blob = null;
238
- URL.revokeObjectURL(this.srcImage.src);
239
- }
146
+ if (tagName === 'img') { target.src = renderImageToDataURL(this.srcImage, opt, doSquash); }
147
+ else if (tagName === 'canvas') { renderImageToCanvas(this.srcImage, target, opt, doSquash); }
148
+ if (typeof this.onrender === 'function') { this.onrender(target); }
149
+ if (callback) { callback(); }
150
+ if (this.blob) { this.blob = null; URL.revokeObjectURL(this.srcImage.src); }
240
151
  };
241
152
 
242
- /**
243
- * Export class to global
244
- */
245
- if (typeof define === 'function' && define.amd) {
246
- define([], function() { return MegaPixImage; }); // for AMD loader
247
- } else if (typeof exports === 'object') {
248
- module.exports = MegaPixImage; // for CommonJS
249
- } else {
250
- this.MegaPixImage = MegaPixImage;
251
- }
153
+ // -------------------------
154
+ // Export as ESM default
155
+ // -------------------------
156
+ return MegaPixImage;
252
157
 
253
- })();
158
+ }));