@studiometa/ui 0.2.9 → 0.2.12
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/atoms/Figure/Figure.cjs +19 -5
- package/atoms/Figure/Figure.d.ts +40 -17
- package/atoms/Figure/Figure.js +1 -1
- package/atoms/Figure/FigureTwicPics.cjs +1 -1
- package/atoms/Figure/FigureTwicPics.d.ts +5 -0
- package/atoms/Figure/FigureTwicPics.js +1 -1
- package/atoms/ScrollReveal/ScrollReveal.cjs +72 -0
- package/atoms/ScrollReveal/ScrollReveal.d.ts +77 -0
- package/atoms/ScrollReveal/ScrollReveal.js +1 -0
- package/atoms/ScrollReveal/index.cjs +29 -0
- package/atoms/ScrollReveal/index.d.ts +1 -0
- package/atoms/ScrollReveal/index.js +1 -0
- package/atoms/index.cjs +1 -0
- package/atoms/index.d.ts +1 -0
- package/atoms/index.js +1 -1
- package/decorators/index.cjs +29 -0
- package/decorators/index.d.ts +1 -0
- package/decorators/index.js +1 -0
- package/decorators/withTransition.cjs +66 -0
- package/decorators/withTransition.d.ts +43 -0
- package/decorators/withTransition.js +1 -0
- package/index.cjs +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -1
- package/molecules/Menu/MenuList.cjs +0 -1
- package/molecules/Menu/MenuList.d.ts +11 -12
- package/molecules/Menu/MenuList.js +1 -1
- package/molecules/Slider/Slider.cjs +70 -24
- package/molecules/Slider/Slider.d.ts +29 -3
- package/molecules/Slider/Slider.js +1 -1
- package/molecules/Slider/SliderDots.cjs +9 -4
- package/molecules/Slider/SliderDots.d.ts +18 -1
- package/molecules/Slider/SliderDots.js +1 -1
- package/molecules/Slider/SliderDrag.cjs +14 -3
- package/molecules/Slider/SliderDrag.d.ts +31 -3
- package/molecules/Slider/SliderDrag.js +1 -1
- package/molecules/Slider/SliderItem.cjs +1 -1
- package/molecules/Slider/SliderItem.js +1 -1
- package/molecules/Slider/SliderProgress.cjs +3 -4
- package/molecules/Slider/SliderProgress.js +1 -1
- package/organisms/Frame/Frame.cjs +4 -5
- package/organisms/Frame/Frame.d.ts +4 -5
- package/organisms/Frame/Frame.js +1 -1
- package/organisms/Frame/FrameTarget.d.ts +16 -10
- package/package.json +1 -1
- package/primitives/Transition/Transition.cjs +3 -41
- package/primitives/Transition/Transition.d.ts +6 -66
- package/primitives/Transition/Transition.js +1 -1
|
@@ -53,6 +53,7 @@ var Slider = class extends import_js_toolkit.Base {
|
|
|
53
53
|
center: 0,
|
|
54
54
|
right: 0
|
|
55
55
|
};
|
|
56
|
+
hasFocus = false;
|
|
56
57
|
get currentState() {
|
|
57
58
|
return this.states[this.currentIndex];
|
|
58
59
|
}
|
|
@@ -82,15 +83,46 @@ var Slider = class extends import_js_toolkit.Base {
|
|
|
82
83
|
center: originRect.x + originRect.width / 2,
|
|
83
84
|
right: originRect.x + originRect.width
|
|
84
85
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
const states = this.$children.SliderItem.map((item) => ({
|
|
87
|
+
x: {
|
|
88
|
+
left: (item.rect.x - this.origins.left) * -1,
|
|
89
|
+
center: (item.rect.x + item.rect.width / 2 - this.origins.center) * -1,
|
|
90
|
+
right: (item.rect.x + item.rect.width - this.origins.right) * -1
|
|
91
|
+
}
|
|
92
|
+
}));
|
|
93
|
+
if (this.$options.contain) {
|
|
94
|
+
const { mode } = this.$options;
|
|
95
|
+
if (mode === "left") {
|
|
96
|
+
const lastChild = this.$children.SliderItem.at(-1);
|
|
97
|
+
const maxState = states.find((state) => {
|
|
98
|
+
const lastChildPosition = lastChild.rect.x - this.origins.left + lastChild.rect.width + state.x.left;
|
|
99
|
+
const diffWithWrapperBound = originRect.width - lastChildPosition;
|
|
100
|
+
if (diffWithWrapperBound > 0) {
|
|
101
|
+
state.x.left = Math.min(state.x.left + diffWithWrapperBound, 0);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
});
|
|
106
|
+
if (maxState) {
|
|
107
|
+
return states.map((state) => {
|
|
108
|
+
state.x.left = Math.max(state.x.left, maxState.x.left);
|
|
109
|
+
return state;
|
|
110
|
+
});
|
|
91
111
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
112
|
+
}
|
|
113
|
+
if (mode === "right") {
|
|
114
|
+
const maxStateIndex = states.findIndex((state) => state.x.right <= 0);
|
|
115
|
+
const maxState = maxStateIndex < 0 ? states.at(-1) : states[maxStateIndex - 1];
|
|
116
|
+
return states.map((state) => {
|
|
117
|
+
state.x.right = maxStateIndex < 0 ? maxState.x.right : Math.min(state.x.right, 0);
|
|
118
|
+
return state;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (mode === "center" && import_utils.isDev) {
|
|
122
|
+
console.warn(`[${this.$id}]`, "The `center` mode is not yet compatible with the `contain` mode.");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return states;
|
|
94
126
|
}
|
|
95
127
|
getOriginByMode(mode) {
|
|
96
128
|
return this.origins[mode ?? this.$options.mode];
|
|
@@ -124,25 +156,23 @@ var Slider = class extends import_js_toolkit.Base {
|
|
|
124
156
|
}
|
|
125
157
|
this.goTo(this.currentIndex - 1);
|
|
126
158
|
}
|
|
127
|
-
goTo(index) {
|
|
159
|
+
goTo(index, { withInstantMove = true } = {}) {
|
|
128
160
|
if (index < 0 || index > this.indexMax) {
|
|
129
161
|
throw new Error("Index out of bound.");
|
|
130
162
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (this.$children.SliderItem[this.indexMax].willBeFullyVisible(state)) {
|
|
134
|
-
state = this.getStateValueByMode(this.lastState.x, "right");
|
|
135
|
-
} else if (this.$children.SliderItem[0].willBeFullyVisible(state)) {
|
|
136
|
-
state = this.getStateValueByMode(this.firstState.x, "left");
|
|
137
|
-
}
|
|
138
|
-
}
|
|
163
|
+
const currentState = this.getStateValueByMode(this.currentState.x);
|
|
164
|
+
const state = this.getStateValueByMode(this.states[index].x);
|
|
139
165
|
const itemsToMove = this.getVisibleItems(state);
|
|
140
|
-
|
|
141
|
-
itemsToMove.reverse();
|
|
142
|
-
}
|
|
166
|
+
const invisibleItemsToMoveInstantly = this.getInvisibleItems(state);
|
|
143
167
|
itemsToMove.forEach((item) => {
|
|
168
|
+
if (currentState !== state && withInstantMove) {
|
|
169
|
+
item.moveInstantly(currentState);
|
|
170
|
+
}
|
|
144
171
|
(0, import_utils.nextFrame)(() => item.move(state));
|
|
145
172
|
});
|
|
173
|
+
invisibleItemsToMoveInstantly.forEach((item) => {
|
|
174
|
+
item.moveInstantly(state);
|
|
175
|
+
});
|
|
146
176
|
this.currentIndex = index;
|
|
147
177
|
this.$emit("goto", index);
|
|
148
178
|
}
|
|
@@ -162,12 +192,12 @@ var Slider = class extends import_js_toolkit.Base {
|
|
|
162
192
|
if (Math.abs(props.delta.y) > Math.abs(props.delta.x)) {
|
|
163
193
|
return;
|
|
164
194
|
}
|
|
165
|
-
let finalX = (0, import_utils.clamp)((0, import_utils.inertiaFinalValue)(this.__distanceX, props.delta.x * this.$options.
|
|
195
|
+
let finalX = (0, import_utils.clamp)((0, import_utils.inertiaFinalValue)(this.__distanceX, props.delta.x * this.$options.dropSensitivity), 0, this.getStateValueByMode(this.lastState.x));
|
|
166
196
|
const absoluteDifferencesBetweenDistanceAndState = this.states.map((state) => Math.abs(finalX - this.getStateValueByMode(state.x)));
|
|
167
197
|
const minimumDifference = Math.min(...absoluteDifferencesBetweenDistanceAndState);
|
|
168
198
|
const closestIndex = absoluteDifferencesBetweenDistanceAndState.findIndex((number) => number === minimumDifference);
|
|
169
199
|
if (this.$options.fitBounds) {
|
|
170
|
-
this.goTo(closestIndex);
|
|
200
|
+
this.goTo(closestIndex, { withInstantMove: false });
|
|
171
201
|
} else {
|
|
172
202
|
if (this.$options.contain) {
|
|
173
203
|
finalX = Math.min(this.containMinState, finalX);
|
|
@@ -179,6 +209,21 @@ var Slider = class extends import_js_toolkit.Base {
|
|
|
179
209
|
this.currentIndex = closestIndex;
|
|
180
210
|
}
|
|
181
211
|
}
|
|
212
|
+
onWrapperFocus() {
|
|
213
|
+
this.hasFocus = true;
|
|
214
|
+
}
|
|
215
|
+
onWrapperBlur() {
|
|
216
|
+
this.hasFocus = false;
|
|
217
|
+
}
|
|
218
|
+
keyed({ LEFT, RIGHT, isDown }) {
|
|
219
|
+
if (this.hasFocus && isDown) {
|
|
220
|
+
if (LEFT) {
|
|
221
|
+
this.goPrev();
|
|
222
|
+
} else if (RIGHT) {
|
|
223
|
+
this.goNext();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
182
227
|
prepareInvisibleItems() {
|
|
183
228
|
const state = this.states[this.currentIndex];
|
|
184
229
|
const nextItemsToPrepare = [];
|
|
@@ -222,7 +267,7 @@ var Slider = class extends import_js_toolkit.Base {
|
|
|
222
267
|
};
|
|
223
268
|
__publicField(Slider, "config", {
|
|
224
269
|
name: "Slider",
|
|
225
|
-
refs: ["wrapper"],
|
|
270
|
+
refs: ["wrapper", "debug"],
|
|
226
271
|
emits: ["goto", "index"],
|
|
227
272
|
components: {
|
|
228
273
|
SliderItem: import_SliderItem.default,
|
|
@@ -232,7 +277,8 @@ __publicField(Slider, "config", {
|
|
|
232
277
|
mode: { type: String, default: "left" },
|
|
233
278
|
fitBounds: Boolean,
|
|
234
279
|
contain: Boolean,
|
|
235
|
-
sensitivity: { type: Number, default: 1 }
|
|
280
|
+
sensitivity: { type: Number, default: 1 },
|
|
281
|
+
dropSensitivity: { type: Number, default: 2 }
|
|
236
282
|
}
|
|
237
283
|
});
|
|
238
284
|
if (module.exports.default) module.exports = module.exports.default;
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
/**
|
|
26
26
|
* Orchestrate the slider items state transition.
|
|
27
27
|
* @todo a11y
|
|
28
|
-
* @todo better state management with `mode` option
|
|
29
28
|
*/
|
|
30
29
|
export default class Slider extends Base {
|
|
31
30
|
/**
|
|
@@ -50,6 +49,10 @@ export default class Slider extends Base {
|
|
|
50
49
|
type: NumberConstructor;
|
|
51
50
|
default: number;
|
|
52
51
|
};
|
|
52
|
+
dropSensitivity: {
|
|
53
|
+
type: NumberConstructor;
|
|
54
|
+
default: number;
|
|
55
|
+
};
|
|
53
56
|
};
|
|
54
57
|
};
|
|
55
58
|
__distanceX: number;
|
|
@@ -80,6 +83,11 @@ export default class Slider extends Base {
|
|
|
80
83
|
* @type {Record<SliderModes, number>}
|
|
81
84
|
*/
|
|
82
85
|
origins: Record<SliderModes, number>;
|
|
86
|
+
/**
|
|
87
|
+
* Wether or not the wrapper is focused.
|
|
88
|
+
* @type {boolean}
|
|
89
|
+
*/
|
|
90
|
+
hasFocus: boolean;
|
|
83
91
|
/**
|
|
84
92
|
* Get the current state.
|
|
85
93
|
* @returns {SliderState}
|
|
@@ -122,7 +130,6 @@ export default class Slider extends Base {
|
|
|
122
130
|
/**
|
|
123
131
|
* Get the states for each SliderItem.
|
|
124
132
|
*
|
|
125
|
-
* @todo save value for every available modes to avoid recalculation when switching
|
|
126
133
|
* @this {SliderInterface}
|
|
127
134
|
*/
|
|
128
135
|
getStates(this: SliderInterface): {
|
|
@@ -175,9 +182,12 @@ export default class Slider extends Base {
|
|
|
175
182
|
*
|
|
176
183
|
* @this {SliderInterface}
|
|
177
184
|
* @param {number} index
|
|
185
|
+
* @param {{ withInstantMove?: boolean }} [options]
|
|
178
186
|
* @returns {void}
|
|
179
187
|
*/
|
|
180
|
-
goTo(this: SliderInterface, index: number
|
|
188
|
+
goTo(this: SliderInterface, index: number, { withInstantMove }?: {
|
|
189
|
+
withInstantMove?: boolean;
|
|
190
|
+
}): void;
|
|
181
191
|
/**
|
|
182
192
|
* Listen to the Draggable `start` event.
|
|
183
193
|
*
|
|
@@ -199,6 +209,22 @@ export default class Slider extends Base {
|
|
|
199
209
|
* @returns {void}
|
|
200
210
|
*/
|
|
201
211
|
onSliderDragDrop(this: SliderInterface, props: import('@studiometa/js-toolkit/services/drag').DragServiceProps): void;
|
|
212
|
+
/**
|
|
213
|
+
* Enable focus.
|
|
214
|
+
* @returns {void}
|
|
215
|
+
*/
|
|
216
|
+
onWrapperFocus(): void;
|
|
217
|
+
/**
|
|
218
|
+
* Disable focus.
|
|
219
|
+
* @returns {void}
|
|
220
|
+
*/
|
|
221
|
+
onWrapperBlur(): void;
|
|
222
|
+
/**
|
|
223
|
+
* Go prev or next when focus is on the wrapper and pressing arrow keys.
|
|
224
|
+
* @param {import('@studiometa/js-toolkit/services/key').KeyServiceProps} props
|
|
225
|
+
* @returns {void}
|
|
226
|
+
*/
|
|
227
|
+
keyed({ LEFT, RIGHT, isDown }: import('@studiometa/js-toolkit/services/key').KeyServiceProps): void;
|
|
202
228
|
/**
|
|
203
229
|
* Prepare invisible items.
|
|
204
230
|
* @returns {void}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Base as
|
|
1
|
+
import{Base as d}from"@studiometa/js-toolkit";import{clamp as c,inertiaFinalValue as u,nextFrame as h,isDev as f}from"@studiometa/js-toolkit/utils";import x from"./SliderDrag.js";import g from"./SliderItem.js";class I extends d{static config={name:"Slider",refs:["wrapper","debug"],emits:["goto","index"],components:{SliderItem:g,SliderDrag:x},options:{mode:{type:String,default:"left"},fitBounds:Boolean,contain:Boolean,sensitivity:{type:Number,default:1},dropSensitivity:{type:Number,default:2}}};__distanceX=0;__initialX=0;__currentIndex=0;get currentIndex(){return this.__currentIndex}set currentIndex(t){this.currentSliderItem.disactivate(),this.$emit("index",t),this.__currentIndex=t,this.currentSliderItem.activate()}states=[];origins={left:0,center:0,right:0};hasFocus=!1;get currentState(){return this.states[this.currentIndex]}get firstState(){return this.states[0]}get lastState(){return this.states[this.states.length-1]}get containMinState(){return this.getStateValueByMode(this.firstState.x,"left")}get containMaxState(){return this.getStateValueByMode(this.lastState.x,"right")}get indexMax(){return this.$children.SliderItem.length-1}get currentSliderItem(){return this.$children.SliderItem[this.currentIndex]}getStates(){const{wrapper:t}=this.$refs,e=t.getBoundingClientRect();this.origins={left:e.left,center:e.x+e.width/2,right:e.x+e.width};const s=this.$children.SliderItem.map(i=>({x:{left:(i.rect.x-this.origins.left)*-1,center:(i.rect.x+i.rect.width/2-this.origins.center)*-1,right:(i.rect.x+i.rect.width-this.origins.right)*-1}}));if(this.$options.contain){const{mode:i}=this.$options;if(i==="left"){const n=this.$children.SliderItem.at(-1),a=s.find(r=>{const o=n.rect.x-this.origins.left+n.rect.width+r.x.left,l=e.width-o;return l>0?(r.x.left=Math.min(r.x.left+l,0),!0):!1});if(a)return s.map(r=>(r.x.left=Math.max(r.x.left,a.x.left),r))}if(i==="right"){const n=s.findIndex(r=>r.x.right<=0),a=n<0?s.at(-1):s[n-1];return s.map(r=>(r.x.right=n<0?a.x.right:Math.min(r.x.right,0),r))}i==="center"&&f&&console.warn(`[${this.$id}]`,"The `center` mode is not yet compatible with the `contain` mode.")}return s}getOriginByMode(t){return this.origins[t??this.$options.mode]}getStateValueByMode(t,e){return t[e??this.$options.mode]}mounted(){this.states=this.getStates(),this.prepareInvisibleItems(),this.goTo(this.currentIndex)}resized(){h(()=>{this.states=this.getStates(),h(()=>{this.prepareInvisibleItems(),this.goTo(this.currentIndex)})})}goNext(){this.currentIndex+1>this.indexMax||this.goTo(this.currentIndex+1)}goPrev(){this.currentIndex-1<0||this.goTo(this.currentIndex-1)}goTo(t,{withInstantMove:e=!0}={}){if(t<0||t>this.indexMax)throw new Error("Index out of bound.");const s=this.getStateValueByMode(this.currentState.x),i=this.getStateValueByMode(this.states[t].x),n=this.getVisibleItems(i),a=this.getInvisibleItems(i);n.forEach(r=>{s!==i&&e&&r.moveInstantly(s),h(()=>r.move(i))}),a.forEach(r=>{r.moveInstantly(i)}),this.currentIndex=t,this.$emit("goto",t)}onSliderDragStart(){this.__initialX=this.currentSliderItem?this.currentSliderItem.x:0}onSliderDragDrag(t){Math.abs(t.delta.y)>Math.abs(t.delta.x)||(this.__distanceX=this.__initialX+t.distance.x*this.$options.sensitivity,this.getVisibleItems(this.__distanceX).forEach(e=>{e.moveInstantly(this.__distanceX)}))}onSliderDragDrop(t){if(Math.abs(t.delta.y)>Math.abs(t.delta.x))return;let e=c(u(this.__distanceX,t.delta.x*this.$options.dropSensitivity),0,this.getStateValueByMode(this.lastState.x));const s=this.states.map(a=>Math.abs(e-this.getStateValueByMode(a.x))),i=Math.min(...s),n=s.findIndex(a=>a===i);this.$options.fitBounds?this.goTo(n,{withInstantMove:!1}):(this.$options.contain&&(e=Math.min(this.containMinState,e),e=Math.max(this.containMaxState,e)),this.$children.SliderItem.forEach(a=>{a.move(e)}),this.currentIndex=n)}onWrapperFocus(){this.hasFocus=!0}onWrapperBlur(){this.hasFocus=!1}keyed({LEFT:t,RIGHT:e,isDown:s}){this.hasFocus&&s&&(t?this.goPrev():e&&this.goNext())}prepareInvisibleItems(){const t=this.states[this.currentIndex],e=[],s=[];this.getInvisibleItems(this.getStateValueByMode(t.x)).forEach((i,n)=>{if(n>this.currentIndex){e.push(i);return}n<this.currentIndex&&s.push(i)}),e.forEach(i=>{const n=this.getStateWhereItemWillBeInvisible(i);n&&i.moveInstantly(this.getStateValueByMode(n.x))}),s.forEach(i=>{const n=this.getStateWhereItemWillBeInvisible(i,{reversed:!0});n&&i.moveInstantly(this.getStateValueByMode(n.x))})}getStateWhereItemWillBeInvisible(t,{reversed:e=!1}={}){const s=this.states.filter(o=>t.willBeVisible(this.getStateValueByMode(o.x))),i=s[0],n=s[s.length-1],a=this.states.findIndex(o=>this.getStateValueByMode(o.x)===this.getStateValueByMode(i.x)),r=this.states.findIndex(o=>o.x===n.x);return e?this.states[r+1]:this.states[a-1]}getVisibleItems(t){return this.$children.SliderItem.filter(e=>e.isVisible||e.willBeVisible(t))}getInvisibleItems(t){return this.$children.SliderItem.filter(e=>!e.isVisible&&!e.willBeVisible(t))}}export{I as default};
|
|
@@ -30,12 +30,17 @@ __export(SliderDots_exports, {
|
|
|
30
30
|
default: () => SliderDots
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(SliderDots_exports);
|
|
33
|
+
var import_decorators = require("../../decorators/index.cjs");
|
|
33
34
|
var import_AbstractSliderChild = __toESM(require("./AbstractSliderChild.cjs"), 1);
|
|
34
|
-
var SliderDots = class extends import_AbstractSliderChild.default {
|
|
35
|
+
var SliderDots = class extends (0, import_decorators.withTransition)(import_AbstractSliderChild.default) {
|
|
36
|
+
get target() {
|
|
37
|
+
return this.$refs.dots;
|
|
38
|
+
}
|
|
39
|
+
currentIndex = 0;
|
|
35
40
|
update(index) {
|
|
36
|
-
this.$refs.dots.
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
this.leave(this.$refs.dots[this.currentIndex]);
|
|
42
|
+
this.enter(this.$refs.dots[index]);
|
|
43
|
+
this.currentIndex = index;
|
|
39
44
|
}
|
|
40
45
|
onDotsClick(event, index) {
|
|
41
46
|
this.$parent.goTo(index);
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
declare const SliderDots_base: typeof AbstractSliderChild & (new (...a: any[]) => {
|
|
2
|
+
readonly target: HTMLElement | HTMLElement[];
|
|
3
|
+
enter(target?: HTMLElement | HTMLElement[]): Promise<void | void[]>;
|
|
4
|
+
leave(target?: HTMLElement | HTMLElement[]): Promise<void | void[]>;
|
|
5
|
+
});
|
|
1
6
|
/**
|
|
2
7
|
* @typedef {SliderDots & {
|
|
3
8
|
* $refs: {
|
|
@@ -8,7 +13,7 @@
|
|
|
8
13
|
/**
|
|
9
14
|
* SliderDots class.
|
|
10
15
|
*/
|
|
11
|
-
export default class SliderDots extends
|
|
16
|
+
export default class SliderDots extends SliderDots_base {
|
|
12
17
|
/**
|
|
13
18
|
* Config.
|
|
14
19
|
*/
|
|
@@ -16,6 +21,17 @@ export default class SliderDots extends AbstractSliderChild {
|
|
|
16
21
|
name: string;
|
|
17
22
|
refs: string[];
|
|
18
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Get target.
|
|
26
|
+
* @this {SliderDotsInterface}
|
|
27
|
+
* @returns {HTMLButtonElement[]}
|
|
28
|
+
*/
|
|
29
|
+
get target(): HTMLButtonElement[];
|
|
30
|
+
/**
|
|
31
|
+
* The current active index.
|
|
32
|
+
* @type {number}
|
|
33
|
+
*/
|
|
34
|
+
currentIndex: number;
|
|
19
35
|
/**
|
|
20
36
|
* Update dots classes according to the new index.
|
|
21
37
|
*
|
|
@@ -39,3 +55,4 @@ export type SliderDotsInterface = SliderDots & {
|
|
|
39
55
|
};
|
|
40
56
|
};
|
|
41
57
|
import AbstractSliderChild from "./AbstractSliderChild.js";
|
|
58
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{withTransition as r}from"../../decorators/index.js";import s from"./AbstractSliderChild.js";class i extends r(s){static config={name:"SliderDots",refs:["dots[]"]};get target(){return this.$refs.dots}currentIndex=0;update(t){this.leave(this.$refs.dots[this.currentIndex]),this.enter(this.$refs.dots[t]),this.currentIndex=t}onDotsClick(t,e){this.$parent.goTo(e)}}export{i as default};
|
|
@@ -29,6 +29,15 @@ __export(SliderDrag_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(SliderDrag_exports);
|
|
30
30
|
var import_js_toolkit = require("@studiometa/js-toolkit");
|
|
31
31
|
var SliderDrag = class extends (0, import_js_toolkit.withDrag)(import_js_toolkit.Base) {
|
|
32
|
+
get shouldPreventScroll() {
|
|
33
|
+
const { distance } = this.$services.get("dragged");
|
|
34
|
+
return Math.abs(distance.x) > this.$options.scrollLockThreshold && Math.abs(distance.x) > Math.abs(distance.y);
|
|
35
|
+
}
|
|
36
|
+
onTouchmove(event) {
|
|
37
|
+
if (this.shouldPreventScroll) {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
32
41
|
dragged(props) {
|
|
33
42
|
this.$emit(props.mode, props);
|
|
34
43
|
}
|
|
@@ -36,9 +45,11 @@ var SliderDrag = class extends (0, import_js_toolkit.withDrag)(import_js_toolkit
|
|
|
36
45
|
__publicField(SliderDrag, "config", {
|
|
37
46
|
name: "SliderDrag",
|
|
38
47
|
emits: ["start", "drag", "drop", "inertia", "stop"],
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
options: {
|
|
49
|
+
scrollLockThreshold: {
|
|
50
|
+
type: Number,
|
|
51
|
+
default: 10
|
|
52
|
+
}
|
|
42
53
|
}
|
|
43
54
|
});
|
|
44
55
|
if (module.exports.default) module.exports = module.exports.default;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {SliderDrag & {
|
|
3
|
+
* $options: {
|
|
4
|
+
* scrollLockThreshold: number;
|
|
5
|
+
* }
|
|
6
|
+
* }} SliderDragInterface
|
|
7
|
+
*/
|
|
1
8
|
/**
|
|
2
9
|
* SliderDrag class.
|
|
3
10
|
*/
|
|
@@ -8,11 +15,27 @@ export default class SliderDrag extends Base {
|
|
|
8
15
|
static config: {
|
|
9
16
|
name: string;
|
|
10
17
|
emits: string[];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
options: {
|
|
19
|
+
scrollLockThreshold: {
|
|
20
|
+
type: NumberConstructor;
|
|
21
|
+
default: number;
|
|
22
|
+
};
|
|
14
23
|
};
|
|
15
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Test if the scroll should be blocked. Used with the touchmove event to prevent
|
|
27
|
+
* scrolling vertically when trying to drag the slider.
|
|
28
|
+
*
|
|
29
|
+
* @this {SliderDragInterface}
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
32
|
+
get shouldPreventScroll(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Touchmove handler.
|
|
35
|
+
* @param {TouchEvent} event
|
|
36
|
+
* @returns {void}
|
|
37
|
+
*/
|
|
38
|
+
onTouchmove(event: TouchEvent): void;
|
|
16
39
|
/**
|
|
17
40
|
* Emit drag events.
|
|
18
41
|
* @param {import('@studiometa/js-toolkit/services/drag').DragServiceProps} props
|
|
@@ -20,4 +43,9 @@ export default class SliderDrag extends Base {
|
|
|
20
43
|
*/
|
|
21
44
|
dragged(props: import('@studiometa/js-toolkit/services/drag').DragServiceProps): void;
|
|
22
45
|
}
|
|
46
|
+
export type SliderDragInterface = SliderDrag & {
|
|
47
|
+
$options: {
|
|
48
|
+
scrollLockThreshold: number;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
23
51
|
import { Base } from "@studiometa/js-toolkit";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Base as
|
|
1
|
+
import{Base as t,withDrag as r}from"@studiometa/js-toolkit";class s extends r(t){static config={name:"SliderDrag",emits:["start","drag","drop","inertia","stop"],options:{scrollLockThreshold:{type:Number,default:10}}};get shouldPreventScroll(){const{distance:e}=this.$services.get("dragged");return Math.abs(e.x)>this.$options.scrollLockThreshold&&Math.abs(e.x)>Math.abs(e.y)}onTouchmove(e){this.shouldPreventScroll&&e.preventDefault()}dragged(e){this.$emit(e.mode,e)}}export{s as default};
|
|
@@ -56,7 +56,7 @@ var SliderItem = class extends (0, import_js_toolkit.withIntersectionObserver)(i
|
|
|
56
56
|
this.isVisible = isIntersecting;
|
|
57
57
|
}
|
|
58
58
|
ticked() {
|
|
59
|
-
this.dampedX = (0, import_utils.damp)(this.x, this.dampedX, 0.
|
|
59
|
+
this.dampedX = (0, import_utils.damp)(this.x, this.dampedX, 0.1, 1e-5);
|
|
60
60
|
this.render();
|
|
61
61
|
if (this.dampedX === this.x) {
|
|
62
62
|
this.$services.disable("ticked");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Base as t,withIntersectionObserver as s}from"@studiometa/js-toolkit";import{damp as d,domScheduler as h,transform as r}from"@studiometa/js-toolkit/utils";class l extends s(t,{threshold:[0,1]}){static config={name:"SliderItem",emits:["is-fully-visible","is-partially-visible","is-hidden"]};isVisible=!1;x=0;dampedX=0;mounted(){this.updateRectAdjustedWithX()}resized(){this.updateRectAdjustedWithX()}destroyed(){this.moveInstantly(0)}intersected([{intersectionRatio:e,isIntersecting:i}]){e>=1?(this.$emit("is-fully-visible"),this.$el.setAttribute("aria-hidden","false")):e>0?(this.$emit("is-partially-visible"),this.$el.setAttribute("aria-hidden","true")):(this.$emit("is-hidden"),this.$el.setAttribute("aria-hidden","true")),this.isVisible=i}ticked(){this.dampedX=d(this.x,this.dampedX,.
|
|
1
|
+
import{Base as t,withIntersectionObserver as s}from"@studiometa/js-toolkit";import{damp as d,domScheduler as h,transform as r}from"@studiometa/js-toolkit/utils";class l extends s(t,{threshold:[0,1]}){static config={name:"SliderItem",emits:["is-fully-visible","is-partially-visible","is-hidden"]};isVisible=!1;x=0;dampedX=0;mounted(){this.updateRectAdjustedWithX()}resized(){this.updateRectAdjustedWithX()}destroyed(){this.moveInstantly(0)}intersected([{intersectionRatio:e,isIntersecting:i}]){e>=1?(this.$emit("is-fully-visible"),this.$el.setAttribute("aria-hidden","false")):e>0?(this.$emit("is-partially-visible"),this.$el.setAttribute("aria-hidden","true")):(this.$emit("is-hidden"),this.$el.setAttribute("aria-hidden","true")),this.isVisible=i}ticked(){this.dampedX=d(this.x,this.dampedX,.1,1e-5),this.render(),this.dampedX===this.x&&this.$services.disable("ticked")}activate(){this.$el.classList.add("is-active")}disactivate(){this.$el.classList.remove("is-active")}move(e){this.x=e,this.$services.has("ticked")||this.$services.enable("ticked")}moveInstantly(e){this.x=e,this.dampedX=e,this.render()}render(){h.write(()=>{r(this.$el,{x:this.dampedX})})}willBeVisible(e){return this.rect.x+e<window.innerWidth*1.5&&this.rect.x+e+this.rect.width>window.innerWidth*-.5}willBeFullyVisible(e){return this.rect.x+e<window.innerWidth&&this.rect.x+e>0&&this.rect.x+e+this.rect.width<window.innerWidth&&this.rect.x+e+this.rect.width>0}updateRectAdjustedWithX(){const e=this.x*-1,i=this.$el.getBoundingClientRect().toJSON();this.rect={...i,left:i.left+e,right:i.left+e+i.width,x:i.left+e}}}export{l as default};
|
|
@@ -35,11 +35,10 @@ var import_AbstractSliderChild = __toESM(require("./AbstractSliderChild.cjs"), 1
|
|
|
35
35
|
var SliderProgress = class extends import_AbstractSliderChild.default {
|
|
36
36
|
update(index) {
|
|
37
37
|
import_utils.domScheduler.read(() => {
|
|
38
|
-
const
|
|
38
|
+
const { progress } = this.$refs;
|
|
39
|
+
const x = (0, import_utils.map)(index, 0, this.$parent.indexMax, progress.clientWidth * -1, 0);
|
|
39
40
|
import_utils.domScheduler.write(() => {
|
|
40
|
-
|
|
41
|
-
translateX: (0, import_utils.map)(index, 0, this.$parent.indexMax, (this.$refs.progress.clientWidth - unit) * -1, 0)
|
|
42
|
-
});
|
|
41
|
+
(0, import_utils.transform)(progress, { x });
|
|
43
42
|
});
|
|
44
43
|
});
|
|
45
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{transform as i,map as o,domScheduler as e}from"@studiometa/js-toolkit/utils";import d from"./AbstractSliderChild.js";class a extends d{static config={name:"SliderProgress",refs:["progress"]};update(s){e.read(()=>{const{progress:r}=this.$refs,t=o(s,0,this.$parent.indexMax,r.clientWidth*-1,0);e.write(()=>{i(r,{x:t})})})}}export{a as default};
|
|
@@ -87,11 +87,11 @@ var _Frame = class extends import_js_toolkit.Base {
|
|
|
87
87
|
onWindowPopstate(event) {
|
|
88
88
|
this.goTo(window.location.href, event.state);
|
|
89
89
|
}
|
|
90
|
-
onFrameAnchorClick(
|
|
90
|
+
onFrameAnchorClick(index, event) {
|
|
91
91
|
if (!(0, import_js_toolkit.isDirectChild)(this, "Frame", "FrameAnchor", this.$children.FrameAnchor[index])) {
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
|
-
this.$log("onAFrameClick",
|
|
94
|
+
this.$log("onAFrameClick", index, event);
|
|
95
95
|
event.preventDefault();
|
|
96
96
|
const anchor = this.$children.FrameAnchor[index];
|
|
97
97
|
if (anchor.href === window.location.href) {
|
|
@@ -99,11 +99,11 @@ var _Frame = class extends import_js_toolkit.Base {
|
|
|
99
99
|
}
|
|
100
100
|
this.goTo(anchor.href);
|
|
101
101
|
}
|
|
102
|
-
onFrameFormSubmit(
|
|
102
|
+
onFrameFormSubmit(index, event) {
|
|
103
103
|
if (!(0, import_js_toolkit.isDirectChild)(this, "Frame", "FrameForm", this.$children.FrameForm[index])) {
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
-
this.$log("onFrameFormFrameSubmit", event);
|
|
106
|
+
this.$log("onFrameFormFrameSubmit", index, event);
|
|
107
107
|
event.preventDefault();
|
|
108
108
|
const form = this.$children.FrameForm[index];
|
|
109
109
|
const url = new URL(form.action);
|
|
@@ -192,7 +192,6 @@ __publicField(Frame, "config", {
|
|
|
192
192
|
"before-enter",
|
|
193
193
|
"after-enter"
|
|
194
194
|
],
|
|
195
|
-
log: true,
|
|
196
195
|
components: {
|
|
197
196
|
FrameAnchor: import_FrameAnchor.default,
|
|
198
197
|
FrameForm: import_FrameForm.default,
|
|
@@ -24,7 +24,6 @@ export default class Frame extends Base {
|
|
|
24
24
|
static config: {
|
|
25
25
|
name: string;
|
|
26
26
|
emits: string[];
|
|
27
|
-
log: boolean;
|
|
28
27
|
components: {
|
|
29
28
|
FrameAnchor: typeof FrameAnchor;
|
|
30
29
|
FrameForm: typeof FrameForm;
|
|
@@ -86,20 +85,20 @@ export default class Frame extends Base {
|
|
|
86
85
|
* Prevent click on `FrameAnchor`.
|
|
87
86
|
*
|
|
88
87
|
* @this {FrameInterface}
|
|
89
|
-
* @param {MouseEvent} event
|
|
90
88
|
* @param {number} index
|
|
89
|
+
* @param {MouseEvent} event
|
|
91
90
|
* @returns {void}
|
|
92
91
|
*/
|
|
93
|
-
onFrameAnchorClick(this: FrameInterface,
|
|
92
|
+
onFrameAnchorClick(this: FrameInterface, index: number, event: MouseEvent): void;
|
|
94
93
|
/**
|
|
95
94
|
* Prevent submit on forms.
|
|
96
95
|
*
|
|
97
96
|
* @this {FrameInterface}
|
|
98
|
-
* @param {SubmitEvent} event
|
|
99
97
|
* @param {number} index
|
|
98
|
+
* @param {SubmitEvent} event
|
|
100
99
|
* @returns {void}
|
|
101
100
|
*/
|
|
102
|
-
onFrameFormSubmit(this: FrameInterface,
|
|
101
|
+
onFrameFormSubmit(this: FrameInterface, index: number, event: SubmitEvent): void;
|
|
103
102
|
/**
|
|
104
103
|
* Parge an HTML string into a DOM object.
|
|
105
104
|
* @param {string} string
|
package/organisms/Frame/Frame.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Base as f,isDirectChild as c,getDirectChildren as p}from"@studiometa/js-toolkit";import{nextFrame as m,historyPush as w}from"@studiometa/js-toolkit/utils";import g from"./FrameAnchor.js";import F from"./FrameForm.js";import u from"./FrameTarget.js";function $(){return{left:window.pageXOffset,top:window.pageYOffset}}const a=new Map;class s extends f{static config={name:"Frame",emits:["before-fetch","after-fetch","before-leave","after-leave","before-content","after-content","before-enter","after-enter"],
|
|
1
|
+
import{Base as f,isDirectChild as c,getDirectChildren as p}from"@studiometa/js-toolkit";import{nextFrame as m,historyPush as w}from"@studiometa/js-toolkit/utils";import g from"./FrameAnchor.js";import F from"./FrameForm.js";import u from"./FrameTarget.js";function $(){return{left:window.pageXOffset,top:window.pageYOffset}}const a=new Map;class s extends f{static config={name:"Frame",emits:["before-fetch","after-fetch","before-leave","after-leave","before-content","after-content","before-enter","after-enter"],components:{FrameAnchor:g,FrameForm:F,FrameTarget:u,Frame:s},options:{history:Boolean}};get id(){return this.$el.id}getDirectChild(e){return this.$children[e]?this.$children.Frame?this.$children[e].filter(r=>this.$children.Frame.every(t=>t.$children[e]?!t.$children[e].includes(r):!0)):this.$children[e]:[]}get directChildrenFrameTarget(){return p(this,"Frame","FrameTarget")}mounted(){this.$options.history&&window.addEventListener("popstate",this)}destroyed(){window.removeEventListener("popstate",this)}handleEvent(e){e.type==="popstate"&&this.onWindowPopstate(e),e.type==="beforeunload"&&this.onWindowUnload()}onWindowUnload(){const{history:e}=window;!e.state||e.replaceState({...e.state,scroll:$()},"")}onWindowPopstate(e){this.goTo(window.location.href,e.state)}onFrameAnchorClick(e,r){if(!c(this,"Frame","FrameAnchor",this.$children.FrameAnchor[e]))return;this.$log("onAFrameClick",e,r),r.preventDefault();const t=this.$children.FrameAnchor[e];t.href!==window.location.href&&this.goTo(t.href)}onFrameFormSubmit(e,r){if(!c(this,"Frame","FrameForm",this.$children.FrameForm[e]))return;this.$log("onFrameFormFrameSubmit",e,r),r.preventDefault();const t=this.$children.FrameForm[e],i=new URL(t.action);i.search=new URLSearchParams(new FormData(t.$el)).toString(),this.goTo(i.toString())}parseHTML(e=""){return new DOMParser().parseFromString(e,"text/html")}async goTo(e,r=null){this.$log("goTo",e);const t=new URL(e);if(t.origin!==window.location.origin)throw new Error("Cross origin request are not allowed.");this.$emit("before-fetch",e);const i=await this.fetch(e),n=this.parseHTML(i),l=n.querySelector(`#${this.id}`),h=new s(l);h.$children.registerAll(),this.$emit("after-fetch",e,i),this.$emit("before-leave"),await Promise.all(this.directChildrenFrameTarget.map(o=>o.leave())),this.$emit("after-leave"),this.$emit("before-content"),this.directChildrenFrameTarget.map((o,d)=>o.updateContent(h.directChildrenFrameTarget[d])),this.$options.history&&(document.title=n.title,w({path:t.pathname,search:t.searchParams})),r&&(document.scrollingElement.scrollTop=r.top,document.scrollingElement.scrollLeft=r.left),await m(),this.$root.$update(),await m(),this.$emit("after-content"),this.$emit("before-enter"),await Promise.all(this.directChildrenFrameTarget.map(o=>o.enter())),this.$emit("after-enter")}async fetch(e){const r=a.get(e);if(r)return r.status==="pending"?r.promise:r.content;const t=fetch(e);try{a.set(e,{promise:t,status:"pending",content:void 0});const i=await t.then(n=>n.text());return a.set(e,{promise:t,status:"resolved",content:i}),i}catch(i){return a.set(e,{promise:t,status:"error",content:i}),i}}}export{s as default};
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
declare const FrameTarget_base: typeof import("@studiometa/js-toolkit").Base & (new (...a: any[]) => {
|
|
2
|
+
readonly target: HTMLElement | HTMLElement[];
|
|
3
|
+
enter(target?: HTMLElement | HTMLElement[]): Promise<void | void[]>;
|
|
4
|
+
leave(target?: HTMLElement | HTMLElement[]): Promise<void | void[]>;
|
|
5
|
+
});
|
|
1
6
|
/**
|
|
2
7
|
* FrameTarget class.
|
|
3
8
|
*/
|
|
4
|
-
export default class FrameTarget extends
|
|
9
|
+
export default class FrameTarget extends FrameTarget_base {
|
|
5
10
|
/**
|
|
6
11
|
* Config.
|
|
7
12
|
*/
|
|
@@ -14,15 +19,11 @@ export default class FrameTarget extends Transition {
|
|
|
14
19
|
default: string;
|
|
15
20
|
};
|
|
16
21
|
id: StringConstructor;
|
|
17
|
-
enterFrom: StringConstructor;
|
|
18
|
-
enterActive: StringConstructor;
|
|
19
|
-
enterTo: StringConstructor;
|
|
20
|
-
enterKeep: BooleanConstructor;
|
|
21
|
-
leaveFrom: StringConstructor;
|
|
22
|
-
leaveActive: StringConstructor;
|
|
23
|
-
leaveTo: StringConstructor;
|
|
24
|
-
leaveKeep: BooleanConstructor;
|
|
25
22
|
};
|
|
23
|
+
debug?: boolean;
|
|
24
|
+
refs?: string[];
|
|
25
|
+
emits?: string[];
|
|
26
|
+
components?: import("@studiometa/js-toolkit/Base/index.js").BaseConfigComponents;
|
|
26
27
|
};
|
|
27
28
|
/**
|
|
28
29
|
* Insert modes.
|
|
@@ -36,6 +37,11 @@ export default class FrameTarget extends Transition {
|
|
|
36
37
|
* @returns {string}
|
|
37
38
|
*/
|
|
38
39
|
get id(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Enter transition.
|
|
42
|
+
* @returns {Promise<void>}
|
|
43
|
+
*/
|
|
44
|
+
enter(): Promise<void>;
|
|
39
45
|
/**
|
|
40
46
|
* Update the content from the new target.
|
|
41
47
|
*
|
|
@@ -44,4 +50,4 @@ export default class FrameTarget extends Transition {
|
|
|
44
50
|
*/
|
|
45
51
|
updateContent(newTarget: FrameTarget): void;
|
|
46
52
|
}
|
|
47
|
-
|
|
53
|
+
export {};
|