smartphoto 1.6.4 → 2.0.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 (67) hide show
  1. package/README.md +401 -0
  2. package/css/smartphoto.css +78 -81
  3. package/css/smartphoto.css.map +1 -0
  4. package/css/smartphoto.min.css +1 -1
  5. package/js/jquery-smartphoto.js +1706 -3809
  6. package/js/jquery-smartphoto.min.js +5 -55
  7. package/js/smartphoto.js +1722 -3794
  8. package/js/smartphoto.min.js +6 -55
  9. package/lib/smartphoto.js +1823 -0
  10. package/lib/smartphoto.mjs +1799 -0
  11. package/lib/types/adaptor/jquery.d.ts +5 -0
  12. package/lib/types/core/gestures.d.ts +12 -0
  13. package/lib/types/core/index.d.ts +68 -0
  14. package/lib/types/core/state.d.ts +20 -0
  15. package/lib/types/core/types.d.ts +147 -0
  16. package/lib/types/core/view.d.ts +48 -0
  17. package/lib/types/index.d.ts +2 -0
  18. package/lib/types/lib/util.d.ts +11 -0
  19. package/package.json +60 -52
  20. package/.babelrc +0 -9
  21. package/.csscomb.json +0 -314
  22. package/.editorconfig +0 -24
  23. package/.eslintrc +0 -24
  24. package/.git +0 -1
  25. package/.node-version +0 -1
  26. package/circle.yml +0 -15
  27. package/examples/assets/bear.jpg +0 -0
  28. package/examples/assets/camel.jpg +0 -0
  29. package/examples/assets/castle.jpg +0 -0
  30. package/examples/assets/hippo.jpg +0 -0
  31. package/examples/assets/koala.jpg +0 -0
  32. package/examples/assets/large-bear.jpg +0 -0
  33. package/examples/assets/large-camel.jpg +0 -0
  34. package/examples/assets/large-hippo.jpg +0 -0
  35. package/examples/assets/large-koala.jpg +0 -0
  36. package/examples/assets/large-lion.jpg +0 -0
  37. package/examples/assets/large-rhino.jpg +0 -0
  38. package/examples/assets/lion.jpg +0 -0
  39. package/examples/assets/rhino.jpg +0 -0
  40. package/examples/assets/sample.png +0 -0
  41. package/examples/assets/style.css +0 -98
  42. package/examples/assets/test.png +0 -0
  43. package/examples/event.html +0 -78
  44. package/examples/jquery.html +0 -80
  45. package/examples/lazy.html +0 -81
  46. package/examples/multiple.html +0 -91
  47. package/examples/noimage.html +0 -22
  48. package/examples/resizeFit.html +0 -56
  49. package/examples/vanilla.html +0 -57
  50. package/images/icon_arrow_next.svg +0 -1
  51. package/images/icon_arrow_prev.svg +0 -1
  52. package/images/icon_close.svg +0 -1
  53. package/index.d.ts +0 -64
  54. package/lib/adaptor/jquery.js +0 -25
  55. package/lib/core/index.js +0 -1573
  56. package/lib/index.js +0 -3
  57. package/lib/lib/util.js +0 -183
  58. package/readme.md +0 -210
  59. package/scss/smartphoto.scss +0 -442
  60. package/src/adaptor/jquery.js +0 -24
  61. package/src/core/index.js +0 -1202
  62. package/src/core/viwer.html +0 -49
  63. package/src/index.js +0 -3
  64. package/src/lib/util.js +0 -141
  65. package/test/preload.js +0 -47
  66. package/test/test.js +0 -49
  67. package/tools/index.js +0 -34
package/README.md ADDED
@@ -0,0 +1,401 @@
1
+ # SmartPhoto
2
+ [![npm version](https://badge.fury.io/js/smartphoto.svg)](https://badge.fury.io/js/smartphoto)
3
+ [![npm download](http://img.shields.io/npm/dm/smartphoto.svg)](https://www.npmjs.com/package/smartphoto)
4
+ [![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://raw.githubusercontent.com/appleple/SmartPhoto/master/LICENSE)
5
+
6
+ The most easy to use responsive image viewer especially for mobile devices
7
+
8
+ See [https://appleple.github.io/SmartPhoto/](https://appleple.github.io/SmartPhoto/) for complete docs and demos<br/>
9
+ If you are Japasese, See here [https://www.appleple.com/blog/javascript/smartphoto-js.html](https://www.appleple.com/blog/javascript/smartphoto-js.html) instead.
10
+
11
+ ## Feature
12
+ - Intuitive gestures such as pinch-in/pinch-out/drag/swipe
13
+ - Use Accelerometer to move images
14
+ - Accessible from keyboards and screen-readers
15
+ - Show pictures via URL hash
16
+ - Can make photo groups
17
+
18
+ ## Installation
19
+ - [npm](https://www.npmjs.com/package/smartphoto)
20
+ - [standalone](https://raw.githubusercontent.com/appleple/smart-photo/master/js/smartphoto.js)
21
+
22
+ via npm
23
+ ```shell
24
+ npm install smartphoto --save
25
+ ```
26
+
27
+ or yarn
28
+
29
+ ```shell
30
+ yarn add smartphoto
31
+ ```
32
+
33
+ ## Usage
34
+ require
35
+ ```js
36
+ const SmartPhoto = require('smartphoto');
37
+ ```
38
+
39
+ smartphoto.js
40
+ ```js
41
+ document.addEventListener('DOMContentLoaded',function(){
42
+ new SmartPhoto(".js-smartphoto");
43
+ });
44
+ ```
45
+
46
+ jquery-smartphoto.js
47
+ ```js
48
+ $(function(){
49
+ $(".js-smartphoto").SmartPhoto();
50
+ });
51
+ ```
52
+
53
+ ### Basic Standalone Usage
54
+
55
+ ```html
56
+ <a href="./assets/large-bear.jpg" class="js-smartphoto" data-caption="bear" data-id="bear" data-group="0">
57
+ <img src="./assets/bear.jpg" width="360"/>
58
+ </a>
59
+ <a href="./assets/large-camel.jpg" class="js-smartphoto" data-caption="camel" data-id="camel" data-group="0">
60
+ <img src="./assets/camel.jpg" width="360"/>
61
+ </a>
62
+ <a href="./assets/large-rhinoceros.jpg" class="js-smartphoto" data-caption="rhinoceros" data-id="sai" data-group="0">
63
+ <img src="./assets/rhinoceros.jpg" width="360"/>
64
+ </a>
65
+ <link rel="stylesheet" href="./css/smartphoto.min.css">
66
+ <script src="./js/smartphoto.js"></script>
67
+ <script>
68
+ document.addEventListener('DOMContentLoaded',function(){
69
+ new SmartPhoto(".js-smartphoto");
70
+ });
71
+ </script>
72
+ ```
73
+
74
+ ### Programmatic usage (data source mode)
75
+
76
+ Instead of scanning `<a>` elements in the page, you can pass an array of slide objects directly (inspired by [yet-another-react-lightbox](https://yet-another-react-lightbox.com/)). This is useful when your images come from an API or a JS-rendered list.
77
+
78
+ ```js
79
+ const photo = new SmartPhoto([
80
+ { src: "/img/bear-large.jpg", thumb: "/img/bear.jpg", caption: "bear", id: "bear" },
81
+ { src: "/img/camel-large.jpg", thumb: "/img/camel.jpg", caption: "camel", id: "camel", width: 1200, height: 800 },
82
+ ]);
83
+
84
+ photo.show(0); // open by index
85
+ photo.show("camel"); // or by id
86
+ photo.next();
87
+ photo.prev();
88
+ photo.hide();
89
+ photo.on("change", () => { /* ... */ }); // same event contract as HTML mode
90
+ ```
91
+
92
+ Slide fields:
93
+
94
+ <table>
95
+ <tr>
96
+ <th>field</th>
97
+ <th>required</th>
98
+ <th>description</th>
99
+ </tr>
100
+ <tr>
101
+ <td>src</td>
102
+ <td>yes</td>
103
+ <td>full-size image URL (equivalent to <code>href</code> in HTML mode)</td>
104
+ </tr>
105
+ <tr>
106
+ <td>thumb</td>
107
+ <td>no</td>
108
+ <td>thumbnail URL used in the nav strip. Falls back to <code>src</code></td>
109
+ </tr>
110
+ <tr>
111
+ <td>caption</td>
112
+ <td>no</td>
113
+ <td>caption text (equivalent to <code>data-caption</code>)</td>
114
+ </tr>
115
+ <tr>
116
+ <td>alt</td>
117
+ <td>no</td>
118
+ <td>image alt text. Falls back to caption, then src</td>
119
+ </tr>
120
+ <tr>
121
+ <td>id</td>
122
+ <td>no</td>
123
+ <td>identifier used by <code>show(id)</code> and the URL hash. Falls back to the index</td>
124
+ </tr>
125
+ <tr>
126
+ <td>group</td>
127
+ <td>no</td>
128
+ <td>group name (equivalent to <code>data-group</code>). Falls back to <code>"nogroup"</code></td>
129
+ </tr>
130
+ <tr>
131
+ <td>width / height</td>
132
+ <td>no</td>
133
+ <td>natural image size in px. When given, SmartPhoto skips the preload used to measure the image</td>
134
+ </tr>
135
+ </table>
136
+
137
+ `show(indexOrId, options)` also accepts `options.group` (which group to open) and `options.trigger` (the element to animate from / return focus to). Both HTML mode and data source mode share the exact same public API, options, and events.
138
+
139
+ ### Option
140
+
141
+ <table>
142
+ <tr>
143
+ <th>variable</th>
144
+ <th>description</th>
145
+ <th>default</th>
146
+ </tr>
147
+ <tr>
148
+ <td>arrows</td>
149
+ <td>prev/next arrows</td>
150
+ <td>true</td>
151
+ </tr>
152
+ <tr>
153
+ <td>nav</td>
154
+ <td>navigation images at the bottom</td>
155
+ <td>true</td>
156
+ </tr>
157
+ <tr>
158
+ <td>showAnimation</td>
159
+ <td>animate the open/close transition</td>
160
+ <td>true</td>
161
+ </tr>
162
+ <tr>
163
+ <td>verticalGravity</td>
164
+ <td>apply device-tilt gravity to the vertical axis too (in addition to horizontal)</td>
165
+ <td>false</td>
166
+ </tr>
167
+ <tr>
168
+ <td>useOrientationApi</td>
169
+ <td>use the accelerometer (deviceorientation) to move a zoomed image</td>
170
+ <td>false</td>
171
+ </tr>
172
+ <tr>
173
+ <td>useHistoryApi</td>
174
+ <td>update the URL hash (<code>#group=…&photo=…</code>) via the History API</td>
175
+ <td>true</td>
176
+ </tr>
177
+ <tr>
178
+ <td>swipeTopToClose</td>
179
+ <td>close the viewer on an upward swipe</td>
180
+ <td>false</td>
181
+ </tr>
182
+ <tr>
183
+ <td>swipeBottomToClose</td>
184
+ <td>close the viewer on a downward swipe</td>
185
+ <td>true</td>
186
+ </tr>
187
+ <tr>
188
+ <td>swipeOffset</td>
189
+ <td>minimum swipe distance (px) to trigger navigation/close</td>
190
+ <td>100</td>
191
+ </tr>
192
+ <tr>
193
+ <td>headerHeight</td>
194
+ <td>height (px) reserved for the header when fitting images</td>
195
+ <td>60</td>
196
+ </tr>
197
+ <tr>
198
+ <td>footerHeight</td>
199
+ <td>height (px) reserved for the footer when fitting images</td>
200
+ <td>60</td>
201
+ </tr>
202
+ <tr>
203
+ <td>resizeStyle</td>
204
+ <td>resize images to fill/fit on the screen</td>
205
+ <td>'fit'</td>
206
+ </tr>
207
+ <tr>
208
+ <td>animationSpeed</td>
209
+ <td>animation speed (ms) when switching/opening/closing images</td>
210
+ <td>300</td>
211
+ </tr>
212
+ <tr>
213
+ <td>forceInterval</td>
214
+ <td>frequency (ms) to apply force to images</td>
215
+ <td>10</td>
216
+ </tr>
217
+ <tr>
218
+ <td>registance</td>
219
+ <td>friction applied to the inertia scroll of a zoomed image</td>
220
+ <td>0.5</td>
221
+ </tr>
222
+ <tr>
223
+ <td>loadOffset</td>
224
+ <td>number of neighboring slides to preload around the current one</td>
225
+ <td>2</td>
226
+ </tr>
227
+ <tr>
228
+ <td>lazyAttribute</td>
229
+ <td>attribute read for a lazy-loaded thumbnail (HTML mode only)</td>
230
+ <td>'data-src'</td>
231
+ </tr>
232
+ <tr>
233
+ <td>classNames</td>
234
+ <td>override any of the generated CSS class names</td>
235
+ <td>see source</td>
236
+ </tr>
237
+ <tr>
238
+ <td>message</td>
239
+ <td>override screen-reader text (<code>gotoNextImage</code> / <code>gotoPrevImage</code> / <code>closeDialog</code> / <code>carouselLabel</code>)</td>
240
+ <td>see source</td>
241
+ </tr>
242
+ </table>
243
+
244
+ #### Hide parts
245
+ ```js
246
+ document.addEventListener('DOMContentLoaded',function(){
247
+ new SmartPhoto(".js-smartphoto",{
248
+ arrows: false,
249
+ nav: false
250
+ });
251
+ });
252
+ ```
253
+
254
+ #### Fit/Fill Option
255
+
256
+ You can choose if you want to scale images to fit/fill
257
+
258
+ ```js
259
+ document.addEventListener('DOMContentLoaded',function(){
260
+ new SmartPhoto(".js-smartphoto",{
261
+ resizeStyle: 'fit'
262
+ });
263
+ });
264
+ ```
265
+
266
+ ### Event
267
+
268
+ ```js
269
+ // when the modal opened
270
+ photo.on('open',function(){
271
+ console.log('open');
272
+ });
273
+ // when the modal closed
274
+ photo.on('close',function(){
275
+ console.log('close');
276
+ });
277
+ // when all images are loaded
278
+ photo.on('loadall',function(){
279
+ console.log('loadall');
280
+ });
281
+ // when photo is changed
282
+ photo.on('change',function(){
283
+ console.log('change');
284
+ });
285
+ // when swipe started
286
+ photo.on('swipestart',function(){
287
+ console.log('swipestart');
288
+ });
289
+ // when swipe ended
290
+ photo.on('swipeend',function(){
291
+ console.log('swipeend');
292
+ });
293
+ // when zoomed in
294
+ photo.on('zoomin',function(){
295
+ console.log('zoomin');
296
+ });
297
+ // when zoomed out
298
+ photo.on('zoomout',function(){
299
+ console.log('zoomout');
300
+ });
301
+ ```
302
+
303
+ ### Methods
304
+
305
+ <table>
306
+ <tr>
307
+ <th>method</th>
308
+ <th>description</th>
309
+ </tr>
310
+ <tr>
311
+ <td><code>on(event, listener)</code></td>
312
+ <td>subscribe to one of the events listed above</td>
313
+ </tr>
314
+ <tr>
315
+ <td><code>destroy()</code></td>
316
+ <td>remove the viewer and all of its event listeners</td>
317
+ </tr>
318
+ <tr>
319
+ <td><code>gotoSlide(index)</code></td>
320
+ <td>go to the slide at <code>index</code> within the current group</td>
321
+ </tr>
322
+ <tr>
323
+ <td><code>hidePhoto(dir?)</code></td>
324
+ <td>close the viewer. <code>dir</code> is <code>'bottom'</code> (default) or <code>'top'</code> and controls the close animation direction</td>
325
+ </tr>
326
+ <tr>
327
+ <td><code>zoomPhoto()</code> / <code>zoomOutPhoto()</code></td>
328
+ <td>zoom the current image in/out programmatically</td>
329
+ </tr>
330
+ <tr>
331
+ <td><code>addNewItem(element)</code></td>
332
+ <td>register a new <code>&lt;a&gt;</code> thumbnail element (HTML mode)</td>
333
+ </tr>
334
+ <tr>
335
+ <td><code>show(indexOrId?, options?)</code></td>
336
+ <td>open the viewer, by index or id. Works in both HTML mode and data source mode. <code>options.group</code> picks the group; <code>options.trigger</code> sets the element to animate from and to return focus to</td>
337
+ </tr>
338
+ <tr>
339
+ <td><code>hide()</code></td>
340
+ <td>alias of <code>hidePhoto()</code></td>
341
+ </tr>
342
+ <tr>
343
+ <td><code>next()</code> / <code>prev()</code></td>
344
+ <td>go to the next/previous slide. No-op at the start/end of the group</td>
345
+ </tr>
346
+ <tr>
347
+ <td><code>addItem(slideOrElement)</code></td>
348
+ <td>add a new item. Accepts a slide object (data source mode) or an <code>Element</code> (HTML mode, same as <code>addNewItem</code>)</td>
349
+ </tr>
350
+ <tr>
351
+ <td><code>currentIndex</code></td>
352
+ <td>(getter) the index currently displayed within its group</td>
353
+ </tr>
354
+ </table>
355
+
356
+ ### SCSS
357
+
358
+ <table>
359
+ <tr>
360
+ <th>variable</th>
361
+ <th>description</th>
362
+ <th>default</th>
363
+ </tr>
364
+ <tr>
365
+ <td>$animation-speed</td>
366
+ <td>animation speed when switching images</td>
367
+ <td>.3s</td>
368
+ </tr>
369
+ <tr>
370
+ <td>$backdrop-color</td>
371
+ <td>backdrop color when viewing images</td>
372
+ <td>rgba(0, 0, 0, 1)</td>
373
+ </tr>
374
+ <tr>
375
+ <td>$header-color</td>
376
+ <td>header color</td>
377
+ <td>rgba(0, 0, 0, .2)</td>
378
+ </tr>
379
+ </table>
380
+
381
+ `$animation-speed` is the SCSS build-time default. At runtime it is overridden per-instance by the `animationSpeed` JS option via the `--smartphoto-animation-speed` CSS custom property set on the `dialog` element.
382
+
383
+ Every SCSS variable above is also exposed as a CSS custom property (`--smartphoto-animation-speed`, `--smartphoto-animation-function`, `--smartphoto-backdrop-color`, `--smartphoto-header-color`), so they can be overridden without recompiling SCSS, e.g.:
384
+
385
+ ```css
386
+ .smartphoto {
387
+ --smartphoto-animation-function: ease-in-out;
388
+ --smartphoto-backdrop-color: rgba(0, 0, 0, 0.9);
389
+ --smartphoto-header-color: rgba(0, 0, 0, 0.4);
390
+ }
391
+ ```
392
+
393
+
394
+ ## Download
395
+ [Download ZIP](https://github.com/appleple/SmartPhoto/archive/master.zip)
396
+
397
+ ## Github
398
+ [https://github.com/appleple/SmartPhoto](https://github.com/appleple/SmartPhoto)
399
+
400
+ ## License
401
+ Code and documentation copyright 2017 by appleple, Inc. Code released under the [MIT License](https://github.com/appleple/SmartPhoto/blob/master/LICENSE).