@thinkpixellab-public/px-vue 3.0.1
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.
- package/.eslintrc.js +14 -0
- package/.prettierrc.js +10 -0
- package/LICENSE.md +9 -0
- package/README.md +83 -0
- package/assets/feather/activity.svg +1 -0
- package/assets/feather/airplay.svg +1 -0
- package/assets/feather/alert-circle.svg +1 -0
- package/assets/feather/alert-octagon.svg +1 -0
- package/assets/feather/alert-triangle.svg +1 -0
- package/assets/feather/align-center.svg +1 -0
- package/assets/feather/align-justify.svg +1 -0
- package/assets/feather/align-left.svg +1 -0
- package/assets/feather/align-right.svg +1 -0
- package/assets/feather/anchor.svg +1 -0
- package/assets/feather/aperture.svg +1 -0
- package/assets/feather/archive.svg +1 -0
- package/assets/feather/arrow-down-circle.svg +1 -0
- package/assets/feather/arrow-down-left.svg +1 -0
- package/assets/feather/arrow-down-right.svg +1 -0
- package/assets/feather/arrow-down.svg +1 -0
- package/assets/feather/arrow-left-circle.svg +1 -0
- package/assets/feather/arrow-left.svg +1 -0
- package/assets/feather/arrow-right-circle.svg +1 -0
- package/assets/feather/arrow-right.svg +1 -0
- package/assets/feather/arrow-up-circle.svg +1 -0
- package/assets/feather/arrow-up-left.svg +1 -0
- package/assets/feather/arrow-up-right.svg +1 -0
- package/assets/feather/arrow-up.svg +1 -0
- package/assets/feather/at-sign.svg +1 -0
- package/assets/feather/award.svg +1 -0
- package/assets/feather/bar-chart-2.svg +1 -0
- package/assets/feather/bar-chart.svg +1 -0
- package/assets/feather/battery-charging.svg +1 -0
- package/assets/feather/battery.svg +1 -0
- package/assets/feather/bell-off.svg +1 -0
- package/assets/feather/bell.svg +1 -0
- package/assets/feather/bluetooth.svg +1 -0
- package/assets/feather/bold.svg +1 -0
- package/assets/feather/book-open.svg +1 -0
- package/assets/feather/book.svg +1 -0
- package/assets/feather/bookmark.svg +1 -0
- package/assets/feather/box.svg +1 -0
- package/assets/feather/briefcase.svg +1 -0
- package/assets/feather/calendar.svg +1 -0
- package/assets/feather/camera-off.svg +1 -0
- package/assets/feather/camera.svg +1 -0
- package/assets/feather/cast.svg +1 -0
- package/assets/feather/check-circle.svg +1 -0
- package/assets/feather/check-square.svg +1 -0
- package/assets/feather/check.svg +1 -0
- package/assets/feather/chevron-down.svg +1 -0
- package/assets/feather/chevron-left.svg +1 -0
- package/assets/feather/chevron-right.svg +1 -0
- package/assets/feather/chevron-up.svg +1 -0
- package/assets/feather/chevrons-down.svg +1 -0
- package/assets/feather/chevrons-left.svg +1 -0
- package/assets/feather/chevrons-right.svg +1 -0
- package/assets/feather/chevrons-up.svg +1 -0
- package/assets/feather/chrome.svg +1 -0
- package/assets/feather/circle.svg +1 -0
- package/assets/feather/clipboard.svg +1 -0
- package/assets/feather/clock.svg +1 -0
- package/assets/feather/cloud-drizzle.svg +1 -0
- package/assets/feather/cloud-lightning.svg +1 -0
- package/assets/feather/cloud-off.svg +1 -0
- package/assets/feather/cloud-rain.svg +1 -0
- package/assets/feather/cloud-snow.svg +1 -0
- package/assets/feather/cloud.svg +1 -0
- package/assets/feather/code.svg +1 -0
- package/assets/feather/codepen.svg +1 -0
- package/assets/feather/codesandbox.svg +1 -0
- package/assets/feather/coffee.svg +1 -0
- package/assets/feather/columns.svg +1 -0
- package/assets/feather/command.svg +1 -0
- package/assets/feather/compass.svg +1 -0
- package/assets/feather/copy.svg +1 -0
- package/assets/feather/corner-down-left.svg +1 -0
- package/assets/feather/corner-down-right.svg +1 -0
- package/assets/feather/corner-left-down.svg +1 -0
- package/assets/feather/corner-left-up.svg +1 -0
- package/assets/feather/corner-right-down.svg +1 -0
- package/assets/feather/corner-right-up.svg +1 -0
- package/assets/feather/corner-up-left.svg +1 -0
- package/assets/feather/corner-up-right.svg +1 -0
- package/assets/feather/cpu.svg +1 -0
- package/assets/feather/credit-card.svg +1 -0
- package/assets/feather/crop.svg +1 -0
- package/assets/feather/crosshair.svg +1 -0
- package/assets/feather/database.svg +1 -0
- package/assets/feather/delete.svg +1 -0
- package/assets/feather/disc.svg +1 -0
- package/assets/feather/divide-circle.svg +1 -0
- package/assets/feather/divide-square.svg +1 -0
- package/assets/feather/divide.svg +1 -0
- package/assets/feather/dollar-sign.svg +1 -0
- package/assets/feather/download-cloud.svg +1 -0
- package/assets/feather/download.svg +1 -0
- package/assets/feather/dribbble.svg +1 -0
- package/assets/feather/droplet.svg +1 -0
- package/assets/feather/edit-2.svg +1 -0
- package/assets/feather/edit-3.svg +1 -0
- package/assets/feather/edit.svg +1 -0
- package/assets/feather/external-link.svg +1 -0
- package/assets/feather/eye-off.svg +1 -0
- package/assets/feather/eye.svg +1 -0
- package/assets/feather/facebook.svg +1 -0
- package/assets/feather/fast-forward.svg +1 -0
- package/assets/feather/feather.svg +1 -0
- package/assets/feather/figma.svg +1 -0
- package/assets/feather/file-minus.svg +1 -0
- package/assets/feather/file-plus.svg +1 -0
- package/assets/feather/file-text.svg +1 -0
- package/assets/feather/file.svg +1 -0
- package/assets/feather/film.svg +1 -0
- package/assets/feather/filter.svg +1 -0
- package/assets/feather/flag.svg +1 -0
- package/assets/feather/folder-minus.svg +1 -0
- package/assets/feather/folder-plus.svg +1 -0
- package/assets/feather/folder.svg +1 -0
- package/assets/feather/framer.svg +1 -0
- package/assets/feather/frown.svg +1 -0
- package/assets/feather/gift.svg +1 -0
- package/assets/feather/git-branch.svg +1 -0
- package/assets/feather/git-commit.svg +1 -0
- package/assets/feather/git-merge.svg +1 -0
- package/assets/feather/git-pull-request.svg +1 -0
- package/assets/feather/github.svg +1 -0
- package/assets/feather/gitlab.svg +1 -0
- package/assets/feather/globe.svg +1 -0
- package/assets/feather/grid.svg +1 -0
- package/assets/feather/hard-drive.svg +1 -0
- package/assets/feather/hash.svg +1 -0
- package/assets/feather/headphones.svg +1 -0
- package/assets/feather/heart.svg +1 -0
- package/assets/feather/help-circle.svg +1 -0
- package/assets/feather/hexagon.svg +1 -0
- package/assets/feather/home.svg +1 -0
- package/assets/feather/image.svg +1 -0
- package/assets/feather/inbox.svg +1 -0
- package/assets/feather/info.svg +1 -0
- package/assets/feather/instagram.svg +1 -0
- package/assets/feather/italic.svg +1 -0
- package/assets/feather/key.svg +1 -0
- package/assets/feather/layers.svg +1 -0
- package/assets/feather/layout.svg +1 -0
- package/assets/feather/life-buoy.svg +1 -0
- package/assets/feather/link-2.svg +1 -0
- package/assets/feather/link.svg +1 -0
- package/assets/feather/linkedin.svg +1 -0
- package/assets/feather/list.svg +1 -0
- package/assets/feather/loader.svg +1 -0
- package/assets/feather/lock.svg +1 -0
- package/assets/feather/log-in.svg +1 -0
- package/assets/feather/log-out.svg +1 -0
- package/assets/feather/mail.svg +1 -0
- package/assets/feather/map-pin.svg +1 -0
- package/assets/feather/map.svg +1 -0
- package/assets/feather/maximize-2.svg +1 -0
- package/assets/feather/maximize.svg +1 -0
- package/assets/feather/meh.svg +1 -0
- package/assets/feather/menu.svg +1 -0
- package/assets/feather/message-circle.svg +1 -0
- package/assets/feather/message-square.svg +1 -0
- package/assets/feather/mic-off.svg +1 -0
- package/assets/feather/mic.svg +1 -0
- package/assets/feather/minimize-2.svg +1 -0
- package/assets/feather/minimize.svg +1 -0
- package/assets/feather/minus-circle.svg +1 -0
- package/assets/feather/minus-square.svg +1 -0
- package/assets/feather/minus.svg +1 -0
- package/assets/feather/monitor.svg +1 -0
- package/assets/feather/moon.svg +1 -0
- package/assets/feather/more-horizontal.svg +1 -0
- package/assets/feather/more-vertical.svg +1 -0
- package/assets/feather/mouse-pointer.svg +1 -0
- package/assets/feather/move.svg +1 -0
- package/assets/feather/music.svg +1 -0
- package/assets/feather/navigation-2.svg +1 -0
- package/assets/feather/navigation.svg +1 -0
- package/assets/feather/octagon.svg +1 -0
- package/assets/feather/package.svg +1 -0
- package/assets/feather/paperclip.svg +1 -0
- package/assets/feather/pause-circle.svg +1 -0
- package/assets/feather/pause.svg +1 -0
- package/assets/feather/pen-tool.svg +1 -0
- package/assets/feather/percent.svg +1 -0
- package/assets/feather/phone-call.svg +1 -0
- package/assets/feather/phone-forwarded.svg +1 -0
- package/assets/feather/phone-incoming.svg +1 -0
- package/assets/feather/phone-missed.svg +1 -0
- package/assets/feather/phone-off.svg +1 -0
- package/assets/feather/phone-outgoing.svg +1 -0
- package/assets/feather/phone.svg +1 -0
- package/assets/feather/pie-chart.svg +1 -0
- package/assets/feather/play-circle.svg +1 -0
- package/assets/feather/play.svg +1 -0
- package/assets/feather/plus-circle.svg +1 -0
- package/assets/feather/plus-square.svg +1 -0
- package/assets/feather/plus.svg +1 -0
- package/assets/feather/pocket.svg +1 -0
- package/assets/feather/power.svg +1 -0
- package/assets/feather/printer.svg +1 -0
- package/assets/feather/radio.svg +1 -0
- package/assets/feather/refresh-ccw.svg +1 -0
- package/assets/feather/refresh-cw.svg +1 -0
- package/assets/feather/repeat.svg +1 -0
- package/assets/feather/rewind.svg +1 -0
- package/assets/feather/rotate-ccw.svg +1 -0
- package/assets/feather/rotate-cw.svg +1 -0
- package/assets/feather/rss.svg +1 -0
- package/assets/feather/save.svg +1 -0
- package/assets/feather/scissors.svg +1 -0
- package/assets/feather/search.svg +1 -0
- package/assets/feather/send.svg +1 -0
- package/assets/feather/server.svg +1 -0
- package/assets/feather/settings.svg +1 -0
- package/assets/feather/share-2.svg +1 -0
- package/assets/feather/share.svg +1 -0
- package/assets/feather/shield-off.svg +1 -0
- package/assets/feather/shield.svg +1 -0
- package/assets/feather/shopping-bag.svg +1 -0
- package/assets/feather/shopping-cart.svg +1 -0
- package/assets/feather/shuffle.svg +1 -0
- package/assets/feather/sidebar.svg +1 -0
- package/assets/feather/skip-back.svg +1 -0
- package/assets/feather/skip-forward.svg +1 -0
- package/assets/feather/slack.svg +1 -0
- package/assets/feather/slash.svg +1 -0
- package/assets/feather/sliders.svg +1 -0
- package/assets/feather/smartphone.svg +1 -0
- package/assets/feather/smile.svg +1 -0
- package/assets/feather/speaker.svg +1 -0
- package/assets/feather/square.svg +1 -0
- package/assets/feather/star.svg +1 -0
- package/assets/feather/stop-circle.svg +1 -0
- package/assets/feather/sun.svg +1 -0
- package/assets/feather/sunrise.svg +1 -0
- package/assets/feather/sunset.svg +1 -0
- package/assets/feather/table.svg +1 -0
- package/assets/feather/tablet.svg +1 -0
- package/assets/feather/tag.svg +1 -0
- package/assets/feather/target.svg +1 -0
- package/assets/feather/terminal.svg +1 -0
- package/assets/feather/thermometer.svg +1 -0
- package/assets/feather/thumbs-down.svg +1 -0
- package/assets/feather/thumbs-up.svg +1 -0
- package/assets/feather/toggle-left.svg +1 -0
- package/assets/feather/toggle-right.svg +1 -0
- package/assets/feather/tool.svg +1 -0
- package/assets/feather/trash-2.svg +1 -0
- package/assets/feather/trash.svg +1 -0
- package/assets/feather/trello.svg +1 -0
- package/assets/feather/trending-down.svg +1 -0
- package/assets/feather/trending-up.svg +1 -0
- package/assets/feather/triangle.svg +1 -0
- package/assets/feather/truck.svg +1 -0
- package/assets/feather/tv.svg +1 -0
- package/assets/feather/twitch.svg +1 -0
- package/assets/feather/twitter.svg +1 -0
- package/assets/feather/type.svg +1 -0
- package/assets/feather/umbrella.svg +1 -0
- package/assets/feather/underline.svg +1 -0
- package/assets/feather/unlock.svg +1 -0
- package/assets/feather/upload-cloud.svg +1 -0
- package/assets/feather/upload.svg +1 -0
- package/assets/feather/user-check.svg +1 -0
- package/assets/feather/user-minus.svg +1 -0
- package/assets/feather/user-plus.svg +1 -0
- package/assets/feather/user-x.svg +1 -0
- package/assets/feather/user.svg +1 -0
- package/assets/feather/users.svg +1 -0
- package/assets/feather/video-off.svg +1 -0
- package/assets/feather/video.svg +1 -0
- package/assets/feather/voicemail.svg +1 -0
- package/assets/feather/volume-1.svg +1 -0
- package/assets/feather/volume-2.svg +1 -0
- package/assets/feather/volume-x.svg +1 -0
- package/assets/feather/volume.svg +1 -0
- package/assets/feather/watch.svg +1 -0
- package/assets/feather/wifi-off.svg +1 -0
- package/assets/feather/wifi.svg +1 -0
- package/assets/feather/wind.svg +1 -0
- package/assets/feather/x-circle.svg +1 -0
- package/assets/feather/x-octagon.svg +1 -0
- package/assets/feather/x-square.svg +1 -0
- package/assets/feather/x.svg +1 -0
- package/assets/feather/youtube.svg +1 -0
- package/assets/feather/zap-off.svg +1 -0
- package/assets/feather/zap.svg +1 -0
- package/assets/feather/zoom-in.svg +1 -0
- package/assets/feather/zoom-out.svg +1 -0
- package/assets/icons/calendar.svg +6 -0
- package/assets/icons/check.svg +1 -0
- package/assets/icons/close-sm.svg +1 -0
- package/assets/icons/close.svg +1 -0
- package/assets/icons/copy.svg +1 -0
- package/assets/icons/dropdown.svg +8 -0
- package/assets/icons/invalid.svg +1 -0
- package/assets/icons/menu.svg +1 -0
- package/assets/icons/nav-next.svg +1 -0
- package/assets/icons/nav-prev.svg +1 -0
- package/assets/icons/sort-asc.svg +1 -0
- package/assets/icons/sort-desc.svg +1 -0
- package/assets/test/README.md +1 -0
- package/assets/test/trash.svg +8 -0
- package/babel.config.js +16 -0
- package/components/PxAspect.vue +127 -0
- package/components/PxAutoClamp.vue +75 -0
- package/components/PxBalancedText.vue +118 -0
- package/components/PxBase.vue +15 -0
- package/components/PxBaseDate.vue +27 -0
- package/components/PxBaseItems.vue +72 -0
- package/components/PxBaseItemsSelect.vue +230 -0
- package/components/PxBaseResize.vue +60 -0
- package/components/PxBaseToggle.vue +56 -0
- package/components/PxBaseVariants.vue +62 -0
- package/components/PxBaseVisible.vue +40 -0
- package/components/PxCalendar.vue +385 -0
- package/components/PxCard.vue +47 -0
- package/components/PxCardGrid.vue +386 -0
- package/components/PxClock.vue +510 -0
- package/components/PxCopyText.vue +78 -0
- package/components/PxDatePicker.vue +249 -0
- package/components/PxDropdown.vue +181 -0
- package/components/PxExpander.vue +46 -0
- package/components/PxFeatherIcon.vue +29 -0
- package/components/PxFeatherIconButton.vue +19 -0
- package/components/PxFit.vue +274 -0
- package/components/PxFlex.vue +93 -0
- package/components/PxFloat.vue +32 -0
- package/components/PxIcon.vue +43 -0
- package/components/PxIconButton.vue +115 -0
- package/components/PxIdUniquer.vue +59 -0
- package/components/PxModal.vue +365 -0
- package/components/PxNineGrid.vue +94 -0
- package/components/PxPivot.vue +207 -0
- package/components/PxPopup.vue +230 -0
- package/components/PxPortal.vue +138 -0
- package/components/PxPortalTarget.vue +25 -0
- package/components/PxProgressCircle.vue +73 -0
- package/components/PxRadioButton.vue +83 -0
- package/components/PxSideDrawer.vue +164 -0
- package/components/PxSlideTransition.vue +116 -0
- package/components/PxSlides.vue +217 -0
- package/components/PxStylesPreview.vue +129 -0
- package/components/PxSvg.vue +157 -0
- package/components/PxSwiper.vue +271 -0
- package/components/PxSwiperSlide.vue +42 -0
- package/components/PxSyncHeight.vue +137 -0
- package/components/PxTable.vue +323 -0
- package/components/PxTabs.vue +1 -0
- package/components/PxTextbox.vue +90 -0
- package/components/PxToggle.vue +125 -0
- package/components/PxToggleButton.vue +139 -0
- package/components/PxToggleButtonList.vue +131 -0
- package/components/PxTransitionExpand.vue +100 -0
- package/components/PxValidator.vue +431 -0
- package/components/PxVueTest.vue +761 -0
- package/components/README.md +0 -0
- package/dev/data/fruits.js +59 -0
- package/dev/data/random.js +13 -0
- package/dev/demos/Demo-PxBaseDrag.vue +94 -0
- package/dev/demos/Demo-PxCardGrid.vue +53 -0
- package/dev/demos/Demo-PxPivot.vue +58 -0
- package/dev/demos/Demo-PxSideDrawer.vue +72 -0
- package/dev/demos/Demo-PxSlideTransition.vue +86 -0
- package/dev/demos/Demo-PxSlides.vue +142 -0
- package/dev/demos/Demo-PxStylesPreview.vue +46 -0
- package/dev/demos/Demo-PxSwiper.vue +44 -0
- package/dev/demos/DemoPicker.vue +79 -0
- package/dev/dev.vue +56 -0
- package/dev/serve.js +17 -0
- package/package.json +45 -0
- package/plugins/common-client.js +13 -0
- package/plugins/common-lib.js +4 -0
- package/plugins/common.js +39 -0
- package/plugins/filters/aspect.js +14 -0
- package/plugins/filters/date.js +26 -0
- package/plugins/filters/kebab.js +9 -0
- package/plugins/filters/phone.js +7 -0
- package/plugins/filters/slug.js +26 -0
- package/plugins/filters/spacenator.js +11 -0
- package/plugins/filters/stringToItems.js +28 -0
- package/plugins/filters/striphtml.js +10 -0
- package/plugins/mixins/eventBus.js +23 -0
- package/px-styles.config.scss +12 -0
- package/styles/helpers.scss +14 -0
- package/styles/px.scss +6 -0
- package/utils/balanceText.js +123 -0
- package/utils/bem.js +99 -0
- package/utils/cardGrid.js +383 -0
- package/utils/cssStr.js +45 -0
- package/utils/drag.js +363 -0
- package/utils/fit.js +73 -0
- package/utils/tween.js +129 -0
- package/utils/utils.js +167 -0
- package/utils/variants.js +33 -0
- package/vue.config.js +12 -0
package/utils/drag.js
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
// https://github.com/yomotsu/inertia-drag//
|
|
2
|
+
|
|
3
|
+
const defaults = {
|
|
4
|
+
// event when drag starts (equivalent to mousedown)
|
|
5
|
+
onStart: null,
|
|
6
|
+
|
|
7
|
+
// event during drag (equivalent to mousemove)
|
|
8
|
+
onDrag: null,
|
|
9
|
+
|
|
10
|
+
// event on any move (drag or inertia movement)
|
|
11
|
+
onMove: null,
|
|
12
|
+
|
|
13
|
+
// event when drag ends (equivalent to mouse up)
|
|
14
|
+
onEnd: null,
|
|
15
|
+
|
|
16
|
+
// event just on inertia movement
|
|
17
|
+
onInertia: null,
|
|
18
|
+
|
|
19
|
+
// event on the final inertia move
|
|
20
|
+
onInertiaEnd: null,
|
|
21
|
+
|
|
22
|
+
// normally we prevent default but you can allow it with this
|
|
23
|
+
allowEventDefault: false,
|
|
24
|
+
|
|
25
|
+
// disable drag on these elements
|
|
26
|
+
excludeSelector: null,
|
|
27
|
+
|
|
28
|
+
// lock to 'x' or 'y' or nothing (null) or 'auto' (selects first to meet threshold)
|
|
29
|
+
lock: null,
|
|
30
|
+
|
|
31
|
+
// the minimum amount of drag before dragging starts (no events called until met)
|
|
32
|
+
startThreshold: 10,
|
|
33
|
+
|
|
34
|
+
// friction coefficient for inertia
|
|
35
|
+
friction: 0.96,
|
|
36
|
+
|
|
37
|
+
// initial value for the disabled property
|
|
38
|
+
disabled: false,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function Drag(element, options) {
|
|
42
|
+
this.element = element;
|
|
43
|
+
this.ops = { ...defaults, ...options };
|
|
44
|
+
this.disabled = this.ops.disabled;
|
|
45
|
+
|
|
46
|
+
// touch support test
|
|
47
|
+
this.supportsTouch = !!(
|
|
48
|
+
typeof window !== undefined &&
|
|
49
|
+
window.TouchEvent &&
|
|
50
|
+
'ontouchstart' in window
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
this.reset = () => {
|
|
54
|
+
this.thresholdMet = this.ops.startThreshold ? false : true;
|
|
55
|
+
this.previousEv = null;
|
|
56
|
+
this.startEv = null;
|
|
57
|
+
this.inertiaEv = null;
|
|
58
|
+
this.lock = this.ops.lock;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
this.onStart = nativeEvent => {
|
|
62
|
+
if (this.disabled) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (this.ops.excludeSelector) {
|
|
67
|
+
const excludeElements = this.element.querySelectorAll(this.ops.excludeSelector);
|
|
68
|
+
for (let i = 0; i < excludeElements.length; i++) {
|
|
69
|
+
if (excludeElements[i].contains(nativeEvent.target)) return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.addRuntimeEvents();
|
|
74
|
+
|
|
75
|
+
// reset
|
|
76
|
+
this.reset();
|
|
77
|
+
|
|
78
|
+
// store the start event
|
|
79
|
+
this.startEv = this.normalizeEvent(nativeEvent);
|
|
80
|
+
|
|
81
|
+
if (this.thresholdMet) {
|
|
82
|
+
this.isDragging = true;
|
|
83
|
+
if (this.ops.onStart) {
|
|
84
|
+
this.ops.onStart(this.startEv);
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
// threshold not met yet, so onStart will be called later
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
this.onDrag = nativeEvent => {
|
|
92
|
+
let ev = this.normalizeEvent(nativeEvent);
|
|
93
|
+
|
|
94
|
+
if (!this.thresholdMet) {
|
|
95
|
+
ev = this.thresholdCheck(ev);
|
|
96
|
+
if (!ev) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// if we've made it this far we've met the threshold test
|
|
102
|
+
if (!this.ops.allowEventDefault) {
|
|
103
|
+
nativeEvent.preventDefault();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.updateDeltas(ev);
|
|
107
|
+
|
|
108
|
+
// store the last delta as initial velocity
|
|
109
|
+
this.velocity = ev.delta;
|
|
110
|
+
|
|
111
|
+
if (this.ops.onDrag) {
|
|
112
|
+
this.ops.onDrag(ev);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (this.ops.onMove) {
|
|
116
|
+
this.ops.onMove(ev);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
this.onEnd = nativeEvent => {
|
|
121
|
+
this.removeRuntimeEvents();
|
|
122
|
+
|
|
123
|
+
if (this.thresholdMet) {
|
|
124
|
+
let ev = this.normalizeEvent(nativeEvent);
|
|
125
|
+
this.isDragging = false;
|
|
126
|
+
|
|
127
|
+
let prevPrevious = this.previousEv;
|
|
128
|
+
this.updateDeltas(ev);
|
|
129
|
+
|
|
130
|
+
// We need restore the previous previous event since the native event
|
|
131
|
+
// event has the same coordinates as the last drag so the calculated
|
|
132
|
+
// previous got zeroed out when we called updateDeltas.
|
|
133
|
+
ev.previous = prevPrevious;
|
|
134
|
+
ev.delta = this.velocity;
|
|
135
|
+
|
|
136
|
+
if (this.ops.onEnd) {
|
|
137
|
+
this.ops.onEnd(ev);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (this.ops.onMove || this.ops.onInertia) {
|
|
141
|
+
this.inertiaEv = ev;
|
|
142
|
+
this.inertiaEv.nativeEvent = null;
|
|
143
|
+
this.inertiaUpdate();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
this.inertiaUpdate = () => {
|
|
149
|
+
if (this.inertiaEv) {
|
|
150
|
+
if (this.disabled) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
this.inertiaEv.x += this.velocity.x;
|
|
155
|
+
this.inertiaEv.y += this.velocity.y;
|
|
156
|
+
|
|
157
|
+
this.velocity.x *= this.ops.friction;
|
|
158
|
+
this.velocity.y *= this.ops.friction;
|
|
159
|
+
|
|
160
|
+
this.updateDeltas(this.inertiaEv);
|
|
161
|
+
|
|
162
|
+
if (this.ops.onMove) {
|
|
163
|
+
this.ops.onMove(this.inertiaEv);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (this.ops.onInertia) {
|
|
167
|
+
this.ops.onInertia(this.inertiaEv);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
console.log('inertia');
|
|
171
|
+
|
|
172
|
+
// test for near zero velocity and end
|
|
173
|
+
if (Math.abs(this.velocity.x) > 0.5 || Math.abs(this.velocity.y) > 0.5) {
|
|
174
|
+
requestAnimationFrame(this.inertiaUpdate.bind(this));
|
|
175
|
+
} else {
|
|
176
|
+
if (this.ops.onInertiaEnd) {
|
|
177
|
+
this.ops.onInertiaEnd(this.inertiaEv);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
this.thresholdCheck = ev => {
|
|
184
|
+
if (!this.startEv) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const startDelta = {
|
|
189
|
+
x: ev.x - this.startEv.x,
|
|
190
|
+
y: ev.y - this.startEv.y,
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const metX = Math.abs(startDelta.x) >= this.ops.startThreshold;
|
|
194
|
+
const metY = Math.abs(startDelta.y) >= this.ops.startThreshold;
|
|
195
|
+
|
|
196
|
+
if (metX || metY) {
|
|
197
|
+
this.thresholdMet = true;
|
|
198
|
+
|
|
199
|
+
// lock == x | y
|
|
200
|
+
// if we met the threshold in a non supported direction then end
|
|
201
|
+
if ((metX && this.lock == 'y') || (metY && this.lock == 'x')) {
|
|
202
|
+
this.removeRuntimeEvents();
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// lock == auto
|
|
207
|
+
// if lock is 'auto' we need to pretend it has been all along
|
|
208
|
+
if (this.lock == 'auto') {
|
|
209
|
+
this.lock = metX ? 'x' : 'y';
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
this.previousEv = this.startEv;
|
|
213
|
+
|
|
214
|
+
this.isDragging = true;
|
|
215
|
+
|
|
216
|
+
// raise the start event now that the threshold has been met
|
|
217
|
+
if (this.ops.onStart) {
|
|
218
|
+
this.ops.onStart(ev);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// threshold has now been met so return the "revised" event
|
|
222
|
+
return ev;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// threshold has not been met so return false
|
|
226
|
+
return false;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
this.updateDeltas = ev => {
|
|
230
|
+
if (this.startEv) {
|
|
231
|
+
ev.start = this.startEv;
|
|
232
|
+
ev.startDelta = {
|
|
233
|
+
x: ev.x - ev.start.x,
|
|
234
|
+
y: ev.y - ev.start.y,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (this.previousEv) {
|
|
239
|
+
ev.previous = this.previousEv;
|
|
240
|
+
ev.delta = {
|
|
241
|
+
x: ev.x - ev.previous.x,
|
|
242
|
+
y: ev.y - ev.previous.y,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
this.previousEv = {
|
|
247
|
+
x: ev.x,
|
|
248
|
+
y: ev.y,
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
this.normalizeEvent = nativeEvent => {
|
|
253
|
+
if (!nativeEvent) {
|
|
254
|
+
return {};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const coords = {};
|
|
258
|
+
|
|
259
|
+
if (this.supportsTouch && nativeEvent) {
|
|
260
|
+
let touches = nativeEvent.targetTouches.length
|
|
261
|
+
? nativeEvent.targetTouches
|
|
262
|
+
: nativeEvent.changedTouches;
|
|
263
|
+
coords.x = touches[0].clientX;
|
|
264
|
+
coords.y = touches[0].clientY;
|
|
265
|
+
} else {
|
|
266
|
+
coords.x = nativeEvent.clientX;
|
|
267
|
+
coords.y = nativeEvent.clientY;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const ev = {
|
|
271
|
+
x: this.thresholdMet && this.startEv && this.lock == 'y' ? this.startEv.x : coords.x,
|
|
272
|
+
y: this.thresholdMet && this.startEv && this.lock == 'x' ? this.startEv.y : coords.y,
|
|
273
|
+
native: nativeEvent,
|
|
274
|
+
lock: this.lock,
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
return ev;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// element events
|
|
281
|
+
|
|
282
|
+
this.addElementEvents = () => {
|
|
283
|
+
this.element.addEventListener(
|
|
284
|
+
this.supportsTouch ? 'touchstart' : 'mousedown',
|
|
285
|
+
this.onStart
|
|
286
|
+
);
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
this.removeElementEvents = () => {
|
|
290
|
+
this.element.removeEventListener(
|
|
291
|
+
this.supportsTouch ? 'touchstart' : 'mousedown',
|
|
292
|
+
this.onStart
|
|
293
|
+
);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// document (runtime) events
|
|
297
|
+
|
|
298
|
+
this.addRuntimeEvents = () => {
|
|
299
|
+
this.removeRuntimeEvents();
|
|
300
|
+
if (this.supportsTouch) {
|
|
301
|
+
document.addEventListener('touchmove', this.onDrag, { passive: false });
|
|
302
|
+
document.addEventListener('touchend', this.onEnd);
|
|
303
|
+
} else {
|
|
304
|
+
document.addEventListener('mousemove', this.onDrag, { passive: false });
|
|
305
|
+
document.addEventListener('mouseup', this.onEnd);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
this.removeRuntimeEvents = () => {
|
|
310
|
+
if (this.supportsTouch) {
|
|
311
|
+
document.removeEventListener('touchmove', this.onDrag, { passive: false });
|
|
312
|
+
document.removeEventListener('touchend', this.onEnd);
|
|
313
|
+
} else {
|
|
314
|
+
document.removeEventListener('mousemove', this.onDrag, { passive: false });
|
|
315
|
+
document.removeEventListener('mouseup', this.onEnd);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
// mouse down on element
|
|
320
|
+
|
|
321
|
+
this.addElementEvents();
|
|
322
|
+
|
|
323
|
+
// public
|
|
324
|
+
|
|
325
|
+
this.cancel = () => {
|
|
326
|
+
this.reset();
|
|
327
|
+
this.removeRuntimeEvents();
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
this.updateOptions = options => {
|
|
331
|
+
this.ops = { ...this.ops, options };
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
this.disable = () => {
|
|
335
|
+
this.reset();
|
|
336
|
+
this.disabled = true;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
this.enable = () => {
|
|
340
|
+
this.reset();
|
|
341
|
+
this.disable = false;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
this.destroy = () => {
|
|
345
|
+
this.reset();
|
|
346
|
+
this.removeRuntimeEvents();
|
|
347
|
+
this.removeElementEvents();
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
// this.setTouchActionDescendants = (elements, value) => {
|
|
351
|
+
// let i = elements.length;
|
|
352
|
+
// let children;
|
|
353
|
+
// while (i--) {
|
|
354
|
+
// value
|
|
355
|
+
// ? (elements[i].style.touchAction = value)
|
|
356
|
+
// : elements[i].style.removeProperty('touch-action');
|
|
357
|
+
// children = elements[i].children;
|
|
358
|
+
// children && children.length && this.setTouchActionDescendants(children, value);
|
|
359
|
+
// }
|
|
360
|
+
// };
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export default Drag;
|
package/utils/fit.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export function cover(inner, outer, posX = 0.5, posY = 0.5) {
|
|
2
|
+
var aspectOuter = outer.width / outer.height,
|
|
3
|
+
aspectInner = inner.width / inner.height,
|
|
4
|
+
width,
|
|
5
|
+
height,
|
|
6
|
+
x,
|
|
7
|
+
y,
|
|
8
|
+
scale;
|
|
9
|
+
outer.x = outer.x ? outer.x : 0;
|
|
10
|
+
outer.y = outer.y ? outer.y : 0;
|
|
11
|
+
inner.x = inner.x ? inner.x : 0;
|
|
12
|
+
inner.y = inner.y ? inner.y : 0;
|
|
13
|
+
|
|
14
|
+
if (aspectOuter > aspectInner) {
|
|
15
|
+
width = outer.width;
|
|
16
|
+
height = outer.width * (1 / aspectInner);
|
|
17
|
+
x = outer.x;
|
|
18
|
+
y = outer.y - (height - outer.height) * posY;
|
|
19
|
+
scale = outer.height / height;
|
|
20
|
+
} else {
|
|
21
|
+
height = outer.height;
|
|
22
|
+
width = outer.height * aspectInner;
|
|
23
|
+
y = outer.y;
|
|
24
|
+
x = outer.x - (width - outer.width) * posX;
|
|
25
|
+
scale = outer.width / width;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var rect = {
|
|
29
|
+
width: width,
|
|
30
|
+
height: height,
|
|
31
|
+
x: x,
|
|
32
|
+
y: y,
|
|
33
|
+
scale: scale,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return rect;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function contain(inner, outer, posX = 0.5, posY = 0.5) {
|
|
40
|
+
var aspectOuter = outer.width / outer.height,
|
|
41
|
+
aspectInner = inner.width / inner.height,
|
|
42
|
+
width,
|
|
43
|
+
height,
|
|
44
|
+
x,
|
|
45
|
+
y,
|
|
46
|
+
scale;
|
|
47
|
+
outer.x = outer.x ? outer.x : 0;
|
|
48
|
+
outer.y = outer.y ? outer.y : 0;
|
|
49
|
+
|
|
50
|
+
if (aspectInner > aspectOuter) {
|
|
51
|
+
width = outer.width;
|
|
52
|
+
height = outer.width / aspectInner;
|
|
53
|
+
x = 0;
|
|
54
|
+
y = outer.height * posY - height * posY;
|
|
55
|
+
scale = height / outer.height;
|
|
56
|
+
} else {
|
|
57
|
+
width = outer.height * aspectInner;
|
|
58
|
+
height = outer.height;
|
|
59
|
+
x = outer.width * posX - width * posX;
|
|
60
|
+
y = 0;
|
|
61
|
+
scale = width / outer.width;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var rect = {
|
|
65
|
+
width: width,
|
|
66
|
+
height: height,
|
|
67
|
+
x: x,
|
|
68
|
+
y: y,
|
|
69
|
+
scale: scale,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return rect;
|
|
73
|
+
}
|
package/utils/tween.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Super simple tweening
|
|
2
|
+
// Usage: tween({from: 0, to: 1, dur: 1000, update: (v) => {}, complete: () => {}, ease: 'linear'});
|
|
3
|
+
|
|
4
|
+
// easing functions
|
|
5
|
+
|
|
6
|
+
const easeIn = power => t => Math.pow(t, power);
|
|
7
|
+
|
|
8
|
+
const easeOut = power => t => 1 - Math.abs(Math.pow(t - 1, power));
|
|
9
|
+
|
|
10
|
+
const easeInOut = power => t =>
|
|
11
|
+
t < 0.5 ? easeOut(power)(t * 2) / 2 : easeOut(power)(t * 2 - 1) / 2 + 0.5;
|
|
12
|
+
|
|
13
|
+
const easings = {
|
|
14
|
+
linear: easeInOut(1),
|
|
15
|
+
easeInQuad: easeIn(2),
|
|
16
|
+
easeOutQuad: easeOut(2),
|
|
17
|
+
easeInOutQuad: easeInOut(2),
|
|
18
|
+
easeInCubic: easeIn(3),
|
|
19
|
+
easeOutCubic: easeOut(3),
|
|
20
|
+
easeInOutCubic: easeInOut(3),
|
|
21
|
+
easeInQuart: easeIn(4),
|
|
22
|
+
easeOutQuart: easeOut(4),
|
|
23
|
+
easeInOutQuart: easeInOut(4),
|
|
24
|
+
easeInQuint: easeIn(5),
|
|
25
|
+
easeOutQuint: easeOut(5),
|
|
26
|
+
easeInOutQuint: easeInOut(5),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const isClient = () => {
|
|
30
|
+
return !process.server && typeof window !== 'undefined' && typeof document !== undefined;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const getActiveTweens = () => {
|
|
34
|
+
if (typeof window == 'undefined') {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// create active tweens collection on window
|
|
39
|
+
if (!window.pxTween || !window.pxTween.activeTweens) {
|
|
40
|
+
window.pxTween = window?.pxTween || {};
|
|
41
|
+
window.pxTween.activeTweens = {};
|
|
42
|
+
}
|
|
43
|
+
return window.pxTween.activeTweens;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const getNextTweenId = () => {
|
|
47
|
+
if (typeof window == 'undefined') {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
if (!window.pxTween || !window.pxTween.nextTweenId) {
|
|
51
|
+
window.pxTween = window?.pxTween || {};
|
|
52
|
+
window.pxTween.nextTweenId = 0;
|
|
53
|
+
}
|
|
54
|
+
return window.pxTween.nextTweenId + 1;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const deleteTween = id => {
|
|
58
|
+
let tweens = getActiveTweens();
|
|
59
|
+
delete tweens[id];
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function tweenValue(from, to, cb, { time, done, easeFunc, delay } = {}) {
|
|
63
|
+
if (typeof window == 'undefined') {
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const activeTweens = getActiveTweens();
|
|
68
|
+
const id = getNextTweenId();
|
|
69
|
+
|
|
70
|
+
activeTweens[id] = true;
|
|
71
|
+
|
|
72
|
+
const ease = easeFunc || easings.linear;
|
|
73
|
+
const diff = from - to;
|
|
74
|
+
const targetTime = time;
|
|
75
|
+
delay = delay ? delay : 0;
|
|
76
|
+
let start = null;
|
|
77
|
+
function step(timestamp) {
|
|
78
|
+
if (!start) start = timestamp;
|
|
79
|
+
const elapsed = timestamp - (start + delay);
|
|
80
|
+
if (activeTweens[id]) {
|
|
81
|
+
if (elapsed >= delay) {
|
|
82
|
+
const percentage = Math.min((elapsed - delay) / targetTime, 1);
|
|
83
|
+
cb(from - ease(percentage) * diff);
|
|
84
|
+
}
|
|
85
|
+
if (elapsed < targetTime + delay) {
|
|
86
|
+
window && window.requestAnimationFrame(step);
|
|
87
|
+
} else {
|
|
88
|
+
cb(to);
|
|
89
|
+
done && done();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
window && window.requestAnimationFrame(step);
|
|
94
|
+
return id;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const tween = ({
|
|
98
|
+
from = 0,
|
|
99
|
+
to = 1,
|
|
100
|
+
dur = 1000,
|
|
101
|
+
delay = 0,
|
|
102
|
+
update = null,
|
|
103
|
+
complete = null,
|
|
104
|
+
ease = 'easeOutQuart',
|
|
105
|
+
}) => {
|
|
106
|
+
// this should be the only check we need since nothing gets exported
|
|
107
|
+
if (!isClient()) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (typeof ease === 'string' || ease instanceof String) {
|
|
112
|
+
ease = easings[ease];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const id = tweenValue(from, to, update, {
|
|
116
|
+
time: dur,
|
|
117
|
+
done: complete,
|
|
118
|
+
delay: delay,
|
|
119
|
+
easeFunc: ease,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
cancel: function () {
|
|
124
|
+
deleteTween(id);
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export default tween;
|