Skip to content

Commit

Permalink
release(gallery): v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Aug 23, 2024
1 parent e525fbd commit c8a78b5
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 96 deletions.
6 changes: 3 additions & 3 deletions index.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@
},
"gallery": {
"icon": true,
"dependencies": ["carousel"],
"version": "0.1.0",
"dependencies": ["carousel", "image-viewer", "toolbar"],
"version": "1.0.0",
"style": true,
"test": true,
"install": false,
Expand Down Expand Up @@ -352,7 +352,7 @@
},
"toolbar": {
"react": true,
"version": "0.5.7",
"version": "0.5.8",
"style": true,
"icon": false,
"test": true,
Expand Down
3 changes: 3 additions & 0 deletions src/gallery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0 (23 Aug 2024)

* feat: zoom in and zoom out
8 changes: 7 additions & 1 deletion src/gallery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@ Add the following script and style to your page.

```html
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/luna-carousel/luna-carousel.css" />
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/luna-image-viewer/luna-image-viewer.css" />
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/luna-toolbar/luna-toolbar.css" />
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/luna-gallery/luna-gallery.css" />
<script src="//cdn.jsdelivr.net/npm/luna-carousel/luna-carousel.js"></script>
<script src="//cdn.jsdelivr.net/npm/luna-image-viewer/luna-image-viewer.js"></script>
<script src="//cdn.jsdelivr.net/npm/luna-toolbar/luna-toolbar.js"></script>
<script src="//cdn.jsdelivr.net/npm/luna-gallery/luna-gallery.js"></script>
```

You can also get it on npm.

```bash
npm install luna-gallery luna-carousel --save
npm install luna-gallery luna-toolbar luna-image-viewer luna-carousel --save
```

```javascript
import 'luna-carousel/luna-carousel.css'
import 'luna-image-viewer/luna-image-viewer.css'
import 'luna-toolbar/luna-toolbar.css'
import 'luna-gallery/luna-gallery.css'
import LunaGallery from 'luna-gallery'
```
Expand Down
19 changes: 14 additions & 5 deletions src/gallery/icon.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@font-face {
font-family: 'luna-gallery-icon';
src: url('data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAAYUAAsAAAAACgQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAAIIAAADAIhom4k9TLzIAAAGMAAAAPQAAAFZL+UkyY21hcAAAAcwAAADhAAACrBjVl3lnbHlmAAACsAAAAS4AAAHkRg7ZYWhlYWQAAAPgAAAAMgAAADZzrb41aGhlYQAABBQAAAAcAAAAJAGSANxobXR4AAAEMAAAABUAAABQA+j//2xvY2EAAARIAAAAFgAAACoIhggIbWF4cAAABGAAAAAfAAAAIAEiAFJuYW1lAAAEgAAAASkAAAIWm5e+CnBvc3QAAAWsAAAAZgAAAI5k/pLGeJxNjTsOwkAMRF+WkM8GlpB01DlATkCFqBAVF0iFQBEV91fGRkixNVrPZ20yIDJyJlyutwdpnr4fTuT8yvz1nM2v50T1Z/JyfyvhrTkxaNfdHVNLodaFkobC1SC2F6KyB1qO6tqdrdqSSUpQumMjpVHaFLsUxXrPFuz0u1sANIkIPwAAeJxjYGQwYpzAwMrAwFDH0AMkZaB0AgMngzEDAxMDKzMDVhCQ5prCcIAh8SMrwwkgVwhMMjAwgggAZxsIuQAAAHiczdI7jsIwFIXh3+TFGwJUFIgFzKYiZqjQDAIhxAZYEBXbskQPx/adBlFScK1PiW8U+ygxUACZfEkO7ooj1EVdF/sZ3djPOWs+Y6xOTsOaDVv2HDhy8sX9rqcNK3V/2VnXxe5zOa0yY66xYGkDeowoqelrvw4VE+00ZECbqd5oxV2V1pUvVnx3KUtZ9+OtwlSK8p/kMypFu9kspGpMT1ZmJN8mfLUfU8vahJU2Rv9Z/y7pyJ+pZGsmsjNj2ZuhHMxAjqYtJ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UKSmzVQoimZ+SA0BPQZfCmLUxsr3WekGiywlyhBwhp4hyghwoY/NoYC0/fzNv3u7KAAb4hYd6ebhtar1auKE6cZv0IOyTn4U76ONFuEt/KNzDG6bCfTzinTt4/h2dAUrhFu7xIdym/ynsk7+EO3jCt3CX/o9wDyv8Cffx6g3TyBSxKdxSJ/sstGd5/q60rVJTqEkwPlsLXWgbOr1R66OqDsnUuVjF1uRqzq7OMqNKa3Y6csHWuXI2GsXiB5HJkSKCQYG4qQ5LaCTYI0MIe9W91CumLSr6tVaYIMD4KrVgqmiSIZXGhsk1jqwVDjxtStcxrfhazuSkucxq3iQjK/7vurejE9EPsG2mSsww4hNf5IPmDvk/PRFeqAAAAHicXcVJDoIwAEDRfgVBnOcRb8ChGiiEpLSEQgic3kTjxrd5YiK+fv+LmTDFw2dGQMiciAVLVqzZsGXHngNHTpy5cOXGnQdPYl4izGxvtJVZaJuyKI3UUd5p7dJGKePXsnPKq7Uc/FRbp4LR2iopTfjZdi0Zlh6DRtJQUpDT4UhR1AyMVCS0QrwBcHohhQAAAA==')
format('woff');
}

Expand All @@ -17,15 +17,24 @@
.icon-download:before {
content: '\f101';
}
.icon-fullscreen:before {
.icon-original:before {
content: '\f102';
}
.icon-pause:before {
.icon-fullscreen:before {
content: '\f103';
}
.icon-play:before {
.icon-pause:before {
content: '\f104';
}
.icon-close:before {
.icon-play:before {
content: '\f105';
}
.icon-close:before {
content: '\f106';
}
.icon-zoom-in:before {
content: '\f107';
}
.icon-zoom-out:before {
content: '\f108';
}
4 changes: 3 additions & 1 deletion src/gallery/icon/icon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
"../../share/icon/fullscreen.svg",
"../../share/icon/pause.svg",
"../../share/icon/play.svg",
"../../share/icon/close.svg"
"../../share/icon/close.svg",
"../../share/icon/zoom-in.svg",
"../../share/icon/zoom-out.svg"
]
56 changes: 56 additions & 0 deletions src/gallery/icon/original.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 64 additions & 39 deletions src/gallery/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import stripIndent from 'licia/stripIndent'
import Component, { IComponentOptions } from '../share/Component'
import LunaCarousel from 'luna-carousel'
import LunaImageViewer from 'luna-image-viewer'
import LunaToolbar, { LunaToolbarButton, LunaToolbarText } from 'luna-toolbar'
import h from 'licia/h'
import $ from 'licia/$'
import ResizeSensor from 'licia/ResizeSensor'
import throttle from 'licia/throttle'
import types from 'licia/types'
import each from 'licia/each'
import loadImg from 'licia/loadImg'
import fullscreen from 'licia/fullscreen'
Expand All @@ -29,10 +31,9 @@ export default class Gallery extends Component<IOptions> {
private carousel: LunaCarousel
private images: Image[] = []
private resizeSensor: ResizeSensor
private $toolbar: $.$
private $counter: $.$
private $playIcon: $.$
private isCycling = false
private counter: LunaToolbarText
private playBtn: LunaToolbarButton
constructor(container: HTMLElement, options: IOptions = {}) {
super(container, { compName: 'gallery' })
this.initOptions(options, {
Expand All @@ -47,13 +48,11 @@ export default class Gallery extends Component<IOptions> {

const $body = this.find('.body')
const body = $body.get(0) as HTMLElement
this.$toolbar = this.find('.toolbar')
this.$counter = this.find('.counter')
this.$playIcon = this.find('.icon-play')

this.carousel = new LunaCarousel(body)
this.resizeSensor = new ResizeSensor(container)
this.onResize = throttle(() => this.reset(), 16)
this.initToolbar()

this.bindEvent()
this.hide()
Expand Down Expand Up @@ -104,16 +103,18 @@ export default class Gallery extends Component<IOptions> {
each(this.images, (image) => image.reset())
}
cycle() {
const { carousel, c } = this
const { carousel, c, playBtn } = this
carousel.setOption('interval', 5000)
carousel.cycle()
this.$playIcon.rmClass(c('icon-play')).addClass(c('icon-pause'))
const $playIcon = playBtn.$container.find(c('.icon'))
$playIcon.rmClass(c('icon-play')).addClass(c('icon-pause'))
this.isCycling = true
}
pause() {
const { c } = this
const { c, playBtn } = this
this.carousel.pause()
this.$playIcon.addClass(c('icon-play')).rmClass(c('icon-pause'))
const $playIcon = playBtn.$container.find(c('.icon'))
$playIcon.addClass(c('icon-play')).rmClass(c('icon-pause'))
this.isCycling = false
}
destroy() {
Expand All @@ -128,56 +129,74 @@ export default class Gallery extends Component<IOptions> {
this.cycle()
}
}
private initToolbar() {
const { c } = this
const $toolbar = this.find('.toolbar')
const toolbar = new LunaToolbar($toolbar.get(0) as HTMLElement, {
theme: 'dark',
})
function appendIcon(icon: string, handler: types.AnyFn) {
const el = h(`span${c('.icon') + c(`.icon-${icon}`)}`)
return toolbar.appendButton(el, handler)
}
this.counter = toolbar.appendText('1/4')
toolbar.appendSpace()
this.playBtn = appendIcon('play', this.toggleCycle)
appendIcon('zoom-in', this.zoomIn)
appendIcon('zoom-out', this.zoomOut)
appendIcon('original', this.zoomToOriginal)
appendIcon('download', this.download)
appendIcon('fullscreen', this.toggleFullscreen)
appendIcon('close', this.hide)
}
private initTpl() {
this.$container.html(
this.c(stripIndent`
<div class="body"></div>
<div class="toolbar">
<div class="counter"></div>
<div class="button button-close">
<span class="icon icon-close"></span>
</div>
<div class="button button-fullscreen">
<span class="icon icon-fullscreen"></span>
</div>
<div class="button button-download">
<span class="icon icon-download"></span>
</div>
<div class="button button-play">
<div class="icon-play-circle">
<span class="icon icon-play"></span>
</div>
</div>
</div>
`)
<div class="toolbar"></div>`)
)
}
private toggleFullscreen = () => {
fullscreen.toggle(this.container)
}
private updateCounter = () => {
const { carousel } = this
this.$counter.html(
this.counter.setText(
`${carousel.getActiveIdx() + 1} / ${carousel.getSlides().length}`
)
}
private download = () => {
const image = this.getActiveImage()
if (image) {
image.download()
}
}
private zoomIn = () => {
const image = this.getActiveImage()
if (image) {
image.zoom(0.1)
}
}
private zoomOut = () => {
const image = this.getActiveImage()
if (image) {
image.zoom(-0.1)
}
}
private zoomToOriginal = () => {
const image = this.getActiveImage()
if (image) {
image.zoomTo(1)
}
}
private getActiveImage() {
const { carousel, images } = this
const activeIdx = carousel.getActiveIdx()
const image = images[activeIdx]
if (!image) {
return
}
image.download()
return image
}
private bindEvent() {
const { c } = this
this.resizeSensor.addListener(this.onResize)
this.$toolbar
.on('click', c('.button-close'), this.hide)
.on('click', c('.button-fullscreen'), this.toggleFullscreen)
.on('click', c('.button-play'), this.toggleCycle)
.on('click', c('.button-download'), this.download)
this.carousel.on('slide', this.updateCounter)
}
}
Expand Down Expand Up @@ -231,6 +250,12 @@ class Image {
reset() {
this.imageViewer.reset()
}
zoom(ratio: number) {
this.imageViewer.zoom(ratio)
}
zoomTo(ratio: number) {
this.imageViewer.zoomTo(ratio)
}
private initTpl() {
const { gallery } = this

Expand Down
5 changes: 3 additions & 2 deletions src/gallery/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "gallery",
"version": "0.1.0",
"version": "1.0.0",
"description": "Lightweight gallery",
"luna": {
"icon": true,
"dependencies": [
"carousel",
"image-viewer"
"image-viewer",
"toolbar"
]
}
}
2 changes: 2 additions & 0 deletions src/gallery/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'luna-gallery.css'
import Gallery from 'luna-gallery.js'
import $ from 'licia/$'
import readme from './README.md'
import changelog from './CHANGELOG.md'
import story from '../share/story'
import { button, boolean } from '@storybook/addon-knobs'

Expand Down Expand Up @@ -41,6 +42,7 @@ const def = story(
},
{
readme,
changelog,
source: __STORY__,
}
)
Expand Down
Loading

0 comments on commit c8a78b5

Please sign in to comment.