Skip to content

Commit 8d928ec

Browse files
committed
feat: umd/cjs modern build
1 parent cfc8e3d commit 8d928ec

37 files changed

+2406
-2976
lines changed

.github/workflows/npm-publish.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
name: publish-to-npm
22

33
on:
4-
workflow_dispatch:
5-
release:
6-
types: [ created ]
4+
workflow_dispatch:
5+
release:
6+
types: [ created ]
77

88
jobs:
9-
publish-npm:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions/setup-node@v1
14-
with:
15-
node-version: 18
16-
registry-url: https://registry.npmjs.org/
17-
always-auth: true
18-
- run: yarn
19-
- run: yarn publish
20-
env:
21-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
9+
publish-npm:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: 20
16+
registry-url: https://registry.npmjs.org/
17+
always-auth: true
18+
- run: yarn
19+
- run: yarn publish
20+
env:
21+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

demo/slider-multi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ScrollSnapSlider } from '../dist/scroll-snap-slider.js'
1+
import { ScrollSnapSlider } from '../dist/scroll-snap-slider.mjs'
22

33
const sliderMultiElement = document.querySelector('.scroll-snap-slider.-multi')
44
const sliderMulti = new ScrollSnapSlider({ element: sliderMultiElement })

demo/slider-responsive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ScrollSnapSlider } from '../dist/scroll-snap-slider.js'
1+
import { ScrollSnapSlider } from '../dist/scroll-snap-slider.mjs'
22

33
const sliderResponsiveElement = document.querySelector('.scroll-snap-slider.-responsive')
44
const sliderResponsive = new ScrollSnapSlider({ element: sliderResponsiveElement })

demo/slider-simple.js

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import {ScrollSnapAutoplay, ScrollSnapDraggable, ScrollSnapLoop, ScrollSnapSlider} from '../dist/scroll-snap-slider.js'
1+
import {
2+
ScrollSnapAutoplay,
3+
ScrollSnapDraggable,
4+
ScrollSnapLoop,
5+
ScrollSnapSlider
6+
} from '../dist/scroll-snap-slider.mjs'
27

38
const sliderSimpleElement = document.querySelector('.scroll-snap-slider.-simple')
49
const slides = sliderSimpleElement.getElementsByClassName('scroll-snap-slide')
5-
const sliderSimple = new ScrollSnapSlider({element: sliderSimpleElement})
10+
const sliderSimple = new ScrollSnapSlider({ element: sliderSimpleElement })
611

712
sliderSimple.name = 'simple'
813

@@ -20,38 +25,38 @@ const prev = document.querySelector('.indicators.-simple .arrow.-prev')
2025
const next = document.querySelector('.indicators.-simple .arrow.-next')
2126

2227
const setSelected = function (event) {
23-
const slideElementIndex = event.detail
24-
const slideElement = slides[slideElementIndex]
25-
26-
for (const button of buttons) {
27-
const isActive = button.classList.toggle('-active', button.dataset.index === slideElement.dataset.index)
28-
if (isActive) {
29-
button.appendChild(currentIndicator)
30-
}
28+
const slideElementIndex = event.detail
29+
const slideElement = slides[slideElementIndex]
30+
31+
for (const button of buttons) {
32+
const isActive = button.classList.toggle('-active', button.dataset.index === slideElement.dataset.index)
33+
if (isActive) {
34+
button.appendChild(currentIndicator)
3135
}
36+
}
3237
}
3338

3439
for (const button of buttons) {
35-
button.addEventListener('click', function (event) {
36-
autoplayPlugin.disableTemporarily()
37-
event.preventDefault()
40+
button.addEventListener('click', function (event) {
41+
autoplayPlugin.disableTemporarily()
42+
event.preventDefault()
3843

39-
const slideElementIndex = Array.prototype.slice
40-
.call(slides)
41-
.findIndex(item => item.dataset.index === button.dataset.index)
44+
const slideElementIndex = Array.prototype.slice
45+
.call(slides)
46+
.findIndex(item => item.dataset.index === button.dataset.index)
4247

43-
sliderSimple.slideTo(slideElementIndex)
44-
})
48+
sliderSimple.slideTo(slideElementIndex)
49+
})
4550
}
4651

4752
prev.addEventListener('click', function () {
48-
autoplayPlugin.disableTemporarily()
49-
sliderSimple.slideTo(sliderSimple.slide - 1)
53+
autoplayPlugin.disableTemporarily()
54+
sliderSimple.slideTo(sliderSimple.slide - 1)
5055
})
5156

5257
next.addEventListener('click', function () {
53-
autoplayPlugin.disableTemporarily()
54-
sliderSimple.slideTo(sliderSimple.slide + 1)
58+
autoplayPlugin.disableTemporarily()
59+
sliderSimple.slideTo(sliderSimple.slide + 1)
5560
})
5661

5762
sliderSimple.addEventListener('slide-pass', setSelected)
@@ -63,43 +68,43 @@ const loopInput = document.querySelector('#loop')
6368
const draggableInput = document.querySelector('#draggable')
6469

6570
const enablePlugin = function (plugin) {
66-
plugin.enable()
67-
sliderSimple.plugins.set(plugin.id, plugin)
71+
plugin.enable()
72+
sliderSimple.plugins.set(plugin.id, plugin)
6873
}
6974

7075
const disablePlugin = function (plugin) {
71-
plugin.disable()
72-
sliderSimple.plugins.delete(plugin.id)
76+
plugin.disable()
77+
sliderSimple.plugins.delete(plugin.id)
7378
}
7479

7580
autoPlayInput.addEventListener('change', function () {
76-
autoPlayInput.checked ? enablePlugin(autoplayPlugin) : disablePlugin(autoplayPlugin)
81+
autoPlayInput.checked ? enablePlugin(autoplayPlugin) : disablePlugin(autoplayPlugin)
7782
})
7883

7984
loopInput.addEventListener('change', function () {
80-
if (loopInput.disabled) {
81-
return
82-
}
85+
if (loopInput.disabled) {
86+
return
87+
}
8388

84-
loopInput.checked ? enablePlugin(loopPlugin) : disablePlugin(loopPlugin)
89+
loopInput.checked ? enablePlugin(loopPlugin) : disablePlugin(loopPlugin)
8590
})
8691

8792
draggableInput.addEventListener('change', function () {
88-
loopInput.toggleAttribute('disabled', draggableInput.checked)
93+
loopInput.toggleAttribute('disabled', draggableInput.checked)
8994

90-
if (draggableInput.checked) {
91-
enablePlugin(draggablePlugin)
92-
93-
if (loopInput.checked) {
94-
disablePlugin(loopPlugin)
95-
}
96-
97-
return
98-
}
95+
if (draggableInput.checked) {
96+
enablePlugin(draggablePlugin)
9997

10098
if (loopInput.checked) {
101-
enablePlugin(loopPlugin)
99+
disablePlugin(loopPlugin)
102100
}
103101

104-
disablePlugin(draggablePlugin)
102+
return
103+
}
104+
105+
if (loopInput.checked) {
106+
enablePlugin(loopPlugin)
107+
}
108+
109+
disablePlugin(draggablePlugin)
105110
})

demo/test.html

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,39 +66,39 @@
6666
lang="js"
6767
type="module"
6868
>
69-
import {ScrollSnapSlider, ScrollSnapAutoplay, ScrollSnapLoop} from '/dist/scroll-snap-slider.js'
69+
import { ScrollSnapSlider, ScrollSnapAutoplay, ScrollSnapLoop } from '/dist/scroll-snap-slider.mjs'
7070

71-
const sliders = []
72-
const appElement = document.getElementById('app')
73-
const sliderTemplate = document.getElementById('sliderTemplate')
74-
const slideTemplate = document.getElementById('slideTemplate')
75-
const sliderCount = 64
76-
const slidesPerSlider = 10
77-
const interval = 1_000 / 64
71+
const sliders = []
72+
const appElement = document.getElementById('app')
73+
const sliderTemplate = document.getElementById('sliderTemplate')
74+
const slideTemplate = document.getElementById('slideTemplate')
75+
const sliderCount = 64
76+
const slidesPerSlider = 10
77+
const interval = 1_000 / 64
7878

79-
for (let index = 0; index < sliderCount; index++) {
80-
const id = `slider-${index}`
79+
for (let index = 0; index < sliderCount; index++) {
80+
const id = `slider-${index}`
8181

82-
const slides = []
83-
for (let imageIndex = 0; imageIndex < slidesPerSlider; imageIndex++) {
84-
slides.push(slideTemplate.innerHTML.replaceAll('__INDEX__', imageIndex.toString(10)))
85-
}
82+
const slides = []
83+
for (let imageIndex = 0; imageIndex < slidesPerSlider; imageIndex++) {
84+
slides.push(slideTemplate.innerHTML.replaceAll('__INDEX__', imageIndex.toString(10)))
85+
}
8686

87-
const clone = sliderTemplate.innerHTML
88-
.replace('__ID__', id)
89-
.replace('__SLIDES__', slides.join('\n'))
87+
const clone = sliderTemplate.innerHTML
88+
.replace('__ID__', id)
89+
.replace('__SLIDES__', slides.join('\n'))
9090

91-
appElement.insertAdjacentHTML('beforeend', clone)
91+
appElement.insertAdjacentHTML('beforeend', clone)
9292

93-
setTimeout(() => {
94-
const element = document.getElementById(id)
95-
sliders.push(new ScrollSnapSlider({element})
96-
.with([
97-
new ScrollSnapAutoplay(500),
98-
new ScrollSnapLoop()
99-
]))
100-
}, (index * interval))
101-
}
93+
setTimeout(() => {
94+
const element = document.getElementById(id)
95+
sliders.push(new ScrollSnapSlider({ element })
96+
.with([
97+
new ScrollSnapAutoplay(500),
98+
new ScrollSnapLoop()
99+
]))
100+
}, (index * interval))
101+
}
102102
</script>
103103
</body>
104104
</html>

dist/ScrollSnapAutoplay.d.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

dist/ScrollSnapDraggable.d.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

dist/ScrollSnapLoop.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

dist/ScrollSnapPlugin.d.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

dist/ScrollSnapSlider.d.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)