@everymatrix/casino-engagement-suite-luckywheel 0.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/dist/casino-engagement-suite-luckywheel/casino-engagement-suite-luckywheel.esm.js +1 -0
- package/dist/casino-engagement-suite-luckywheel/index.esm.js +1 -0
- package/dist/casino-engagement-suite-luckywheel/p-31e6965f.js +1 -0
- package/dist/casino-engagement-suite-luckywheel/p-c99c6eaf.entry.js +1 -0
- package/dist/casino-engagement-suite-luckywheel/p-e1255160.js +1 -0
- package/dist/casino-engagement-suite-luckywheel/p-f5a837f6.js +2 -0
- package/dist/cjs/app-globals-3a1e7e63.js +5 -0
- package/dist/cjs/casino-engagement-suite-luckywheel-d1e393bd.js +739 -0
- package/dist/cjs/casino-engagement-suite-luckywheel.cjs.entry.js +10 -0
- package/dist/cjs/casino-engagement-suite-luckywheel.cjs.js +25 -0
- package/dist/cjs/index-b3b5597c.js +1428 -0
- package/dist/cjs/index.cjs.js +10 -0
- package/dist/cjs/loader.cjs.js +15 -0
- package/dist/collection/collection-manifest.json +12 -0
- package/dist/collection/components/casino-engagement-suite-luckywheel/casino-engagement-suite-luckywheel.css +213 -0
- package/dist/collection/components/casino-engagement-suite-luckywheel/casino-engagement-suite-luckywheel.js +367 -0
- package/dist/collection/components/casino-engagement-suite-luckywheel/index.js +1 -0
- package/dist/collection/index.js +1 -0
- package/dist/collection/models/luckywheel.js +12 -0
- package/dist/collection/utils/class.spinable.js +38 -0
- package/dist/collection/utils/class.spinner.js +120 -0
- package/dist/collection/utils/class.svgcalc.js +175 -0
- package/dist/collection/utils/types.js +42 -0
- package/dist/collection/utils/utils.js +204 -0
- package/dist/esm/app-globals-0f993ce5.js +3 -0
- package/dist/esm/casino-engagement-suite-luckywheel-0aad8871.js +737 -0
- package/dist/esm/casino-engagement-suite-luckywheel.entry.js +2 -0
- package/dist/esm/casino-engagement-suite-luckywheel.js +20 -0
- package/dist/esm/index-27ac0c91.js +1401 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/loader.js +11 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/stencil.config.dev.js +16 -0
- package/dist/stencil.config.js +17 -0
- package/dist/storybook/main.js +21 -0
- package/dist/storybook/preview.js +9 -0
- package/dist/types/Users/adrian.pripon/Documents/Work/widgets-monorepo/packages/stencil/casino-engagement-suite-luckywheel/.stencil/packages/stencil/casino-engagement-suite-luckywheel/stencil.config.d.ts +2 -0
- package/dist/types/Users/adrian.pripon/Documents/Work/widgets-monorepo/packages/stencil/casino-engagement-suite-luckywheel/.stencil/packages/stencil/casino-engagement-suite-luckywheel/stencil.config.dev.d.ts +2 -0
- package/dist/types/Users/adrian.pripon/Documents/Work/widgets-monorepo/packages/stencil/casino-engagement-suite-luckywheel/.stencil/packages/stencil/casino-engagement-suite-luckywheel/storybook/main.d.ts +3 -0
- package/dist/types/Users/adrian.pripon/Documents/Work/widgets-monorepo/packages/stencil/casino-engagement-suite-luckywheel/.stencil/packages/stencil/casino-engagement-suite-luckywheel/storybook/preview.d.ts +70 -0
- package/dist/types/components/casino-engagement-suite-luckywheel/casino-engagement-suite-luckywheel.d.ts +59 -0
- package/dist/types/components/casino-engagement-suite-luckywheel/index.d.ts +1 -0
- package/dist/types/components.d.ts +95 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/models/luckywheel.d.ts +57 -0
- package/dist/types/stencil-public-runtime.d.ts +1680 -0
- package/dist/types/utils/class.spinable.d.ts +14 -0
- package/dist/types/utils/class.spinner.d.ts +26 -0
- package/dist/types/utils/class.svgcalc.d.ts +109 -0
- package/dist/types/utils/types.d.ts +55 -0
- package/dist/types/utils/utils.d.ts +78 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/loader/package.json +11 -0
- package/package.json +26 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Easing, SpinStep } from "./types";
|
|
2
|
+
import { easing, easingGrad, easingGradX, params } from "./utils";
|
|
3
|
+
export class Spinner {
|
|
4
|
+
constructor(inits) {
|
|
5
|
+
this.deg = 0;
|
|
6
|
+
this.degTarget = undefined;
|
|
7
|
+
this.step = undefined;
|
|
8
|
+
this.easingType = Easing.cubic;
|
|
9
|
+
this.param = params[2];
|
|
10
|
+
this.halt = (deg, cb = () => { }) => {
|
|
11
|
+
this.shouldHalt = () => {
|
|
12
|
+
this.step = SpinStep.halt;
|
|
13
|
+
this.cb = () => {
|
|
14
|
+
cb();
|
|
15
|
+
this.setDeg(deg, 0);
|
|
16
|
+
};
|
|
17
|
+
this.degTarget = deg + 360 * this.param.haltTurns;
|
|
18
|
+
this.continueRepeat();
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
this.continueRepeat = () => setTimeout(() => this.ticker(), 30);
|
|
22
|
+
this.ticker = () => {
|
|
23
|
+
const linkSpeed = this.param.loopSpeed;
|
|
24
|
+
const easingDuration = (deg) => 33 * easingGrad[this.easingType] * deg / this.param.loopSpeed;
|
|
25
|
+
const animations = {
|
|
26
|
+
launch: () => {
|
|
27
|
+
const degTar = 360 * this.param.launchTurns - this.deg;
|
|
28
|
+
const t = easingDuration(degTar);
|
|
29
|
+
this.animateF(t, this.deg, degTar, easing.in[this.easingType], easingGradX.in[this.easingType]);
|
|
30
|
+
},
|
|
31
|
+
halt: () => {
|
|
32
|
+
const t = easingDuration(this.degTarget);
|
|
33
|
+
this.animateF(t, 0, this.degTarget, easing.out[this.easingType], easingGradX.out[this.easingType]);
|
|
34
|
+
},
|
|
35
|
+
loop: () => {
|
|
36
|
+
this.setDeg((this.deg + linkSpeed) % 360, easingGrad[this.easingType]);
|
|
37
|
+
this.continueRepeat();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const stepSwitcher = {
|
|
41
|
+
[SpinStep.launch]: () => {
|
|
42
|
+
this.cb = () => {
|
|
43
|
+
this.step = SpinStep.loop;
|
|
44
|
+
this.setDeg(linkSpeed, easingGrad[this.easingType]);
|
|
45
|
+
this.continueRepeat();
|
|
46
|
+
};
|
|
47
|
+
animations.launch();
|
|
48
|
+
},
|
|
49
|
+
[SpinStep.loop]: () => {
|
|
50
|
+
if (this.shouldHalt && this.deg === 0) {
|
|
51
|
+
this.shouldHalt();
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
animations.loop();
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[SpinStep.halt]: () => {
|
|
58
|
+
if (this.deg === 360 - linkSpeed) {
|
|
59
|
+
animations.halt();
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
animations.loop();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
stepSwitcher[this.step]();
|
|
67
|
+
};
|
|
68
|
+
this.setDeg = (deg, speed) => {
|
|
69
|
+
this.deg = deg;
|
|
70
|
+
this.tick(deg, speed);
|
|
71
|
+
};
|
|
72
|
+
this.animateF = (duration, startAngle, target, easing, _easingGrad) => {
|
|
73
|
+
let start = null;
|
|
74
|
+
const step = () => {
|
|
75
|
+
let timestamp = new Date().getTime();
|
|
76
|
+
if (!start) {
|
|
77
|
+
start = timestamp;
|
|
78
|
+
}
|
|
79
|
+
const progress = timestamp - start;
|
|
80
|
+
const translation = target * easing(progress / duration) + startAngle;
|
|
81
|
+
const speedCur = Math.abs(_easingGrad(progress / duration));
|
|
82
|
+
this.setDeg(translation, speedCur);
|
|
83
|
+
if (progress < duration) {
|
|
84
|
+
setTimeout(() => step(), 30);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.cb();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
step();
|
|
91
|
+
};
|
|
92
|
+
this.animate = (duration, startAngle, target, easing, _easingGrad) => {
|
|
93
|
+
let animationId = null;
|
|
94
|
+
window.cancelAnimationFrame(animationId);
|
|
95
|
+
let start = null;
|
|
96
|
+
const step = (timestamp) => {
|
|
97
|
+
if (!start) {
|
|
98
|
+
start = timestamp;
|
|
99
|
+
}
|
|
100
|
+
const progress = timestamp - start;
|
|
101
|
+
const translation = target * easing(progress / duration) + startAngle;
|
|
102
|
+
const speedCur = Math.abs(_easingGrad(progress / duration));
|
|
103
|
+
this.setDeg(translation, speedCur);
|
|
104
|
+
if (progress < duration) {
|
|
105
|
+
animationId = window.requestAnimationFrame(step);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.cb();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
animationId = window.requestAnimationFrame(step);
|
|
112
|
+
};
|
|
113
|
+
this.tick = inits.tick;
|
|
114
|
+
}
|
|
115
|
+
launch() {
|
|
116
|
+
this.shouldHalt = undefined;
|
|
117
|
+
this.step = SpinStep.launch;
|
|
118
|
+
this.ticker();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { ArrowMode, ContentDirection } from "./types.js";
|
|
2
|
+
import { getPointOnCircle, pointPlus, getSymmetricalPointFromScalar, getPointWithNext } from "./utils.js";
|
|
3
|
+
export const mapObjectValueToTuple = (object) => Object.keys(object).map(key => object[key]);
|
|
4
|
+
var RotateDirection;
|
|
5
|
+
(function (RotateDirection) {
|
|
6
|
+
RotateDirection[RotateDirection["clockwise"] = 1] = "clockwise";
|
|
7
|
+
RotateDirection[RotateDirection["anticlockwise"] = -1] = "anticlockwise";
|
|
8
|
+
})(RotateDirection || (RotateDirection = {}));
|
|
9
|
+
export class SvgCalc {
|
|
10
|
+
constructor({ size, radius, options, themeIndex, contentdirection }) {
|
|
11
|
+
this.arrowmode = ArrowMode.DownFromTop;
|
|
12
|
+
this.convertDegToArc = (deg) => deg * Math.PI / 180;
|
|
13
|
+
this.convertArcToDeg = (arc) => arc * 180 / Math.PI % 360;
|
|
14
|
+
this.getArcDelta = (n) => 2 * Math.PI / n;
|
|
15
|
+
this.findDeg = (index, n) => {
|
|
16
|
+
const degDelta = this.convertArcToDeg(this.getArcDelta(n));
|
|
17
|
+
return (index) * degDelta;
|
|
18
|
+
};
|
|
19
|
+
this.angleTransform = (arrowmode) => {
|
|
20
|
+
switch (arrowmode) {
|
|
21
|
+
case ArrowMode.DownFromTop:
|
|
22
|
+
case ArrowMode.UpFromCenter:
|
|
23
|
+
return -Math.PI / 2;
|
|
24
|
+
case ArrowMode.DownFromCenter:
|
|
25
|
+
case ArrowMode.UpFromBottom:
|
|
26
|
+
return Math.PI / 2;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
this.contentdirection = contentdirection || 'anticlockwise';
|
|
30
|
+
// size
|
|
31
|
+
this.center = size / 2;
|
|
32
|
+
this.ratio = size / 375;
|
|
33
|
+
// options
|
|
34
|
+
this.options = options;
|
|
35
|
+
this.length = options.length;
|
|
36
|
+
// theme
|
|
37
|
+
this.themeIndex = themeIndex;
|
|
38
|
+
//
|
|
39
|
+
this.radius = radius;
|
|
40
|
+
}
|
|
41
|
+
get sizeImage() {
|
|
42
|
+
const getSize = (length) => this.ratio * 48 * 5 / length;
|
|
43
|
+
if (this.length <= 3)
|
|
44
|
+
return getSize(4);
|
|
45
|
+
switch (this.length) {
|
|
46
|
+
case 8:
|
|
47
|
+
case 7: return this.ratio * 24;
|
|
48
|
+
case 6: return this.ratio * 36;
|
|
49
|
+
case 5: return this.ratio * 48;
|
|
50
|
+
case 4: return this.ratio * 56;
|
|
51
|
+
default: return getSize(this.length);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
getSizeImageByPartition(index) {
|
|
55
|
+
if (this.options[index].name) {
|
|
56
|
+
return this.sizeImage / 2;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return this.sizeImage;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
getSvgImageProps(index, partitionDivisor = 1.25) {
|
|
63
|
+
const sizeImage = this.getSizeImageByPartition(index);
|
|
64
|
+
let baseRadius;
|
|
65
|
+
if (this.options[index].name) {
|
|
66
|
+
baseRadius = this.radius - sizeImage / 2 - 3 * this.ratio;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
baseRadius = (this.radius - sizeImage / 2) / Number(partitionDivisor) - 3 * this.ratio;
|
|
70
|
+
}
|
|
71
|
+
return Object.assign(Object.assign({}, this.getPropsForPartitionInfo(index, this.getOffsetImage(sizeImage), baseRadius, ContentDirection.outward)), { width: sizeImage, height: sizeImage });
|
|
72
|
+
}
|
|
73
|
+
getSvgTextProps(index) {
|
|
74
|
+
const sizeImage = this.getSizeImageByPartition(index);
|
|
75
|
+
let baseRadius;
|
|
76
|
+
if (this.options[index].image) {
|
|
77
|
+
baseRadius = this.radius - sizeImage - 6 * this.ratio;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
baseRadius = this.radius - 6 * this.ratio;
|
|
81
|
+
}
|
|
82
|
+
return Object.assign({}, this.getPropsForPartitionInfo(index, this.offsetText, baseRadius));
|
|
83
|
+
}
|
|
84
|
+
getSvgTextPropsAdjustedByImage(index) {
|
|
85
|
+
const props = this.getSvgTextProps(index);
|
|
86
|
+
const size = this.options[index].image ? 80 : 100;
|
|
87
|
+
const objectSize = {
|
|
88
|
+
width: size,
|
|
89
|
+
height: size
|
|
90
|
+
};
|
|
91
|
+
return Object.assign(Object.assign(Object.assign({}, props), objectSize), { x: this.contentdirection === 'clockwise' ? props.x : props.x - objectSize.width, y: props.y - objectSize.height / 2 });
|
|
92
|
+
}
|
|
93
|
+
get offsetText() {
|
|
94
|
+
return {
|
|
95
|
+
center: 0,
|
|
96
|
+
position: {
|
|
97
|
+
x: 0,
|
|
98
|
+
y: 0
|
|
99
|
+
},
|
|
100
|
+
transform: {
|
|
101
|
+
x: 0,
|
|
102
|
+
y: 0
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
getOffsetImage(sizeImage) {
|
|
107
|
+
return {
|
|
108
|
+
center: 0,
|
|
109
|
+
position: {
|
|
110
|
+
x: -1 * sizeImage / 2,
|
|
111
|
+
y: -1 * sizeImage / 2
|
|
112
|
+
},
|
|
113
|
+
transform: {
|
|
114
|
+
x: 0,
|
|
115
|
+
y: 0
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
get direction() {
|
|
120
|
+
return RotateDirection.clockwise;
|
|
121
|
+
}
|
|
122
|
+
getAngleSelf(index, contentDirection) {
|
|
123
|
+
const baseAngle = 360 * index / this.length * this.direction;
|
|
124
|
+
const fixerAngle = 90 * (contentDirection !== undefined ? contentDirection : ContentDirection[this.contentdirection]);
|
|
125
|
+
const resultAngle = baseAngle + fixerAngle;
|
|
126
|
+
return resultAngle;
|
|
127
|
+
}
|
|
128
|
+
getPartitionPositions(index, baseRadius, offset) {
|
|
129
|
+
const angle = this.angleTransform(this.arrowmode) +
|
|
130
|
+
this.direction * index * 2 * Math.PI / this.length;
|
|
131
|
+
const point = getPointOnCircle(baseRadius || this.radius - 9 * this.ratio, angle, this.center + offset.center);
|
|
132
|
+
const transformOrigin = pointPlus(point, offset.transform);
|
|
133
|
+
const pointResult = pointPlus(point, offset.position);
|
|
134
|
+
return {
|
|
135
|
+
transformOrigin,
|
|
136
|
+
point: pointResult
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
getPropsForPartitionInfo(index, offset, baseRadius, contentDirection) {
|
|
140
|
+
const { point, transformOrigin } = this.getPartitionPositions(index, baseRadius, offset);
|
|
141
|
+
const getTransformOriginString = (vector) => Object.keys(vector).map(axis => `${vector[axis]}px`).join(' ');
|
|
142
|
+
return Object.assign(Object.assign({}, point), { style: {
|
|
143
|
+
'font-size': `${13 * this.ratio}px`,
|
|
144
|
+
'transform': `rotate(${this.getAngleSelf(index, contentDirection)}deg)`,
|
|
145
|
+
'transform-origin': `${getTransformOriginString(transformOrigin)}`
|
|
146
|
+
} });
|
|
147
|
+
}
|
|
148
|
+
getPartitionDraw(index) {
|
|
149
|
+
const rPoint = getSymmetricalPointFromScalar(this.center);
|
|
150
|
+
const rRingInnerPoint = getSymmetricalPointFromScalar(this.radius);
|
|
151
|
+
const { point, pointNext } = getPointWithNext(index, this.length, this.radius, this.center);
|
|
152
|
+
const ds = [
|
|
153
|
+
'M', ...mapObjectValueToTuple(rPoint),
|
|
154
|
+
'L', ...mapObjectValueToTuple(point),
|
|
155
|
+
'A',
|
|
156
|
+
...mapObjectValueToTuple(rRingInnerPoint),
|
|
157
|
+
'0 0 1',
|
|
158
|
+
...mapObjectValueToTuple(pointNext),
|
|
159
|
+
'Z'
|
|
160
|
+
];
|
|
161
|
+
return {
|
|
162
|
+
d: ds.join(' ')
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
getDeg(index) {
|
|
166
|
+
const i = index || this.length - 1;
|
|
167
|
+
return this.findDeg(length - i, length);
|
|
168
|
+
}
|
|
169
|
+
getSpinnerProps() {
|
|
170
|
+
const centerPoint = getSymmetricalPointFromScalar(this.center);
|
|
171
|
+
return {
|
|
172
|
+
'transform-origin': `${centerPoint.x} ${centerPoint.y}`
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export var PointerMode;
|
|
2
|
+
(function (PointerMode) {
|
|
3
|
+
PointerMode["Arrow"] = "Arrow";
|
|
4
|
+
PointerMode["Partition"] = "Partition";
|
|
5
|
+
})(PointerMode || (PointerMode = {}));
|
|
6
|
+
export var ArrowMode;
|
|
7
|
+
(function (ArrowMode) {
|
|
8
|
+
ArrowMode["DownFromTop"] = "DownFromTop";
|
|
9
|
+
ArrowMode["UpFromCenter"] = "UpFromCenter";
|
|
10
|
+
ArrowMode["DownFromCenter"] = "DownFromCenter";
|
|
11
|
+
ArrowMode["UpFromBottom"] = "UpFromBottom";
|
|
12
|
+
})(ArrowMode || (ArrowMode = {}));
|
|
13
|
+
export var Lang;
|
|
14
|
+
(function (Lang) {
|
|
15
|
+
Lang["en"] = "en";
|
|
16
|
+
Lang["fr"] = "fr";
|
|
17
|
+
Lang["de"] = "de";
|
|
18
|
+
Lang["tr"] = "tr";
|
|
19
|
+
})(Lang || (Lang = {}));
|
|
20
|
+
export var ContentDirection;
|
|
21
|
+
(function (ContentDirection) {
|
|
22
|
+
ContentDirection[ContentDirection["clockwise"] = 1] = "clockwise";
|
|
23
|
+
ContentDirection[ContentDirection["anticlockwise"] = -1] = "anticlockwise";
|
|
24
|
+
ContentDirection[ContentDirection["outward"] = 0] = "outward";
|
|
25
|
+
})(ContentDirection || (ContentDirection = {}));
|
|
26
|
+
export var SpinStep;
|
|
27
|
+
(function (SpinStep) {
|
|
28
|
+
SpinStep["launch"] = "launch";
|
|
29
|
+
SpinStep["loop"] = "loop";
|
|
30
|
+
SpinStep["halt"] = "halt";
|
|
31
|
+
})(SpinStep || (SpinStep = {}));
|
|
32
|
+
export var Easing;
|
|
33
|
+
(function (Easing) {
|
|
34
|
+
Easing["quad"] = "quad";
|
|
35
|
+
Easing["cubic"] = "cubic";
|
|
36
|
+
Easing["quart"] = "quart";
|
|
37
|
+
Easing["quint"] = "quint";
|
|
38
|
+
//
|
|
39
|
+
Easing["expo"] = "expo";
|
|
40
|
+
Easing["sine"] = "sine";
|
|
41
|
+
Easing["circ"] = "circ";
|
|
42
|
+
})(Easing || (Easing = {}));
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
export function format(first, middle, last) {
|
|
2
|
+
return (first || '') + (middle ? ` ${middle}` : '') + (last ? ` ${last}` : '');
|
|
3
|
+
}
|
|
4
|
+
export const isSafari = () => {
|
|
5
|
+
var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
6
|
+
return isSafari;
|
|
7
|
+
};
|
|
8
|
+
const cvtCaseFromCamelToKebab = (text) => text
|
|
9
|
+
.split(/(?=[A-Z])/)
|
|
10
|
+
.map(s => s.toLocaleLowerCase())
|
|
11
|
+
.join('-');
|
|
12
|
+
export const setProps = (element, props) => {
|
|
13
|
+
Object.keys(props).map(_key => {
|
|
14
|
+
element.setAttribute(cvtCaseFromCamelToKebab(_key), props[_key]);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
export const imageLoaderSvg = (src) => {
|
|
18
|
+
return new Promise((resolve, _reject) => {
|
|
19
|
+
let img = document.createElementNS("http://www.w3.org/2000/svg", "image");
|
|
20
|
+
img.onload = () => resolve(img);
|
|
21
|
+
img.onerror = () => resolve(img); //reject
|
|
22
|
+
img.href.baseVal = src;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
export const getSymmetricalPointFromScalar = (length) => ({
|
|
26
|
+
x: length,
|
|
27
|
+
y: length
|
|
28
|
+
});
|
|
29
|
+
export const getPointOnCircle = (radius, angle, center) => {
|
|
30
|
+
const centerPoint = getSymmetricalPointFromScalar(center);
|
|
31
|
+
return {
|
|
32
|
+
x: centerPoint.x + radius * Math.cos(angle),
|
|
33
|
+
y: centerPoint.y + radius * Math.sin(angle)
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export const getPoint = (num, length, r, rCenter) => {
|
|
37
|
+
const arc = 360 / length;
|
|
38
|
+
const psai = Math.PI / 180 * (-90 + arc * (num - 1 / 2));
|
|
39
|
+
const rCenterPoint = getSymmetricalPointFromScalar(rCenter);
|
|
40
|
+
const rPoint = getSymmetricalPointFromScalar(r);
|
|
41
|
+
return {
|
|
42
|
+
x: rCenterPoint.x + rPoint.x * Math.cos(psai),
|
|
43
|
+
y: rCenterPoint.y + rPoint.y * Math.sin(psai)
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export const getPointWithNext = (num, length, r1, r2) => {
|
|
47
|
+
const getPointx = (num) => getPoint(num, length, r1, r2);
|
|
48
|
+
return {
|
|
49
|
+
point: getPointx(num),
|
|
50
|
+
pointNext: getPointx(num + 1)
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export const getTrianglePointsY = (height, isPointUp, yBase) => {
|
|
54
|
+
return {
|
|
55
|
+
y1: yBase,
|
|
56
|
+
y2: isPointUp ? yBase - height : yBase + height,
|
|
57
|
+
y3: yBase
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export const getTwoPointsOfLineGradient = (radius, index, length, angle) => ({
|
|
61
|
+
x1: radius,
|
|
62
|
+
y1: radius,
|
|
63
|
+
x2: radius * (1 + Math.cos(2 * Math.PI / length * index + angle)),
|
|
64
|
+
y2: radius * (1 + Math.sin(2 * Math.PI / length * index + angle)),
|
|
65
|
+
});
|
|
66
|
+
export const pointPlus = (point1, point2) => ({
|
|
67
|
+
x: point1.x + point2.x,
|
|
68
|
+
y: point1.y + point2.y
|
|
69
|
+
});
|
|
70
|
+
const optionCompliment = {
|
|
71
|
+
image: '',
|
|
72
|
+
name: 'Thank you',
|
|
73
|
+
prizeText: '',
|
|
74
|
+
prizeImage: ''
|
|
75
|
+
};
|
|
76
|
+
const getSumProbability = (partitions) => {
|
|
77
|
+
let probabilityAll = 0;
|
|
78
|
+
partitions.map(partition => {
|
|
79
|
+
probabilityAll += Number(partition.probability);
|
|
80
|
+
});
|
|
81
|
+
return probabilityAll;
|
|
82
|
+
};
|
|
83
|
+
const getOptionsFromPartitions = (partitions, lang) => {
|
|
84
|
+
const options = partitions.map(_partition => {
|
|
85
|
+
const option = {};
|
|
86
|
+
Object.keys(_partition).map((_key) => {
|
|
87
|
+
if (typeof _partition[_key] === 'object' &&
|
|
88
|
+
_partition[_key].hasOwnProperty('*')) {
|
|
89
|
+
const targetKey = _key === 'image1' ? 'image' : _key;
|
|
90
|
+
option[targetKey] = _partition[_key][lang] || _partition[_key]['*'];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return option;
|
|
94
|
+
});
|
|
95
|
+
if (getSumProbability(partitions) < 1) {
|
|
96
|
+
options.push(optionCompliment);
|
|
97
|
+
}
|
|
98
|
+
return options;
|
|
99
|
+
};
|
|
100
|
+
const preloadImage = async (src) => {
|
|
101
|
+
if (!src)
|
|
102
|
+
return {};
|
|
103
|
+
return {
|
|
104
|
+
image: await imageLoaderSvg(src)
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
export const getOptions = async (bonus, lang) => {
|
|
108
|
+
const { partitions } = bonus.program.wheelOfFortune;
|
|
109
|
+
let options = getOptionsFromPartitions(partitions, lang);
|
|
110
|
+
if (isSafari()) {
|
|
111
|
+
options = options.map(option => {
|
|
112
|
+
if (option.image) {
|
|
113
|
+
const img = document.createElementNS('http://www.w3.org/2000/svg', 'image');
|
|
114
|
+
img.href.baseVal = option.image;
|
|
115
|
+
return Object.assign(Object.assign({}, option), { image: img });
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return option;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
options = await Promise.all(options.map(async (o) => (Object.assign(Object.assign({}, o), (await preloadImage(o.image))))));
|
|
124
|
+
}
|
|
125
|
+
return options;
|
|
126
|
+
};
|
|
127
|
+
export const convertDegToArc = (deg) => deg * Math.PI / 180;
|
|
128
|
+
export const easeOut = (time, b, angleStart, timeTotal) => {
|
|
129
|
+
var ts = (time /= timeTotal) * time;
|
|
130
|
+
var tc = ts * time;
|
|
131
|
+
const res = b + angleStart * (tc + -3 * ts + 3 * time);
|
|
132
|
+
return res;
|
|
133
|
+
};
|
|
134
|
+
export const easing = {
|
|
135
|
+
in: {
|
|
136
|
+
quad: (x) => Math.pow(x, 2),
|
|
137
|
+
cubic: (x) => Math.pow(x, 3),
|
|
138
|
+
quart: (x) => Math.pow(x, 4),
|
|
139
|
+
quint: (x) => Math.pow(x, 5),
|
|
140
|
+
//
|
|
141
|
+
sine: (x) => 1 - Math.cos((x * Math.PI) / 2),
|
|
142
|
+
expo: (x) => x === 0 ? 0 : Math.pow(2, 10 * x - 10),
|
|
143
|
+
circ: (x) => 1 - Math.sqrt(1 - Math.pow(x, 2)),
|
|
144
|
+
},
|
|
145
|
+
out: {
|
|
146
|
+
quad: (x) => 1 - Math.pow(1 - x, 2),
|
|
147
|
+
cubic: (x) => 1 - Math.pow(1 - x, 3),
|
|
148
|
+
quart: (x) => 1 - Math.pow(1 - x, 4),
|
|
149
|
+
quint: (x) => 1 - Math.pow(1 - x, 5),
|
|
150
|
+
//
|
|
151
|
+
sine: (x) => Math.sin((x * Math.PI) / 2),
|
|
152
|
+
expo: (x) => x === 1 ? 1 : 1 - Math.pow(2, -10 * x),
|
|
153
|
+
circ: (x) => Math.sqrt(1 - Math.pow(x - 1, 2)),
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
export const easingGrad = {
|
|
157
|
+
quad: 2,
|
|
158
|
+
cubic: 3,
|
|
159
|
+
quart: 4,
|
|
160
|
+
quint: 5,
|
|
161
|
+
sine: Math.PI / 2,
|
|
162
|
+
expo: Math.LN2,
|
|
163
|
+
circ: Infinity,
|
|
164
|
+
};
|
|
165
|
+
export const easingGradX = {
|
|
166
|
+
in: {
|
|
167
|
+
quad: (x) => 2 * x,
|
|
168
|
+
cubic: (x) => 3 * x ** 2,
|
|
169
|
+
quart: (x) => 4 * x ** 3,
|
|
170
|
+
quint: (x) => 5 * x ** 4,
|
|
171
|
+
sine: (x) => Math.PI / 2 * Math.sin(Math.PI / 2 * x),
|
|
172
|
+
expo: (x) => Math.LN2 * 10 * 2 ** (10 * x - 10),
|
|
173
|
+
circ: (x) => -1 / 2 * (1 - x ** 2) ** (-1 / 2),
|
|
174
|
+
},
|
|
175
|
+
out: {
|
|
176
|
+
cubic: (x) => 3 * x ** 2 - 6 * x + 3,
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
export const params = [
|
|
180
|
+
// basic
|
|
181
|
+
{
|
|
182
|
+
launchTurns: 5,
|
|
183
|
+
launchSpeed: 0.2,
|
|
184
|
+
loopSpeed: 15,
|
|
185
|
+
haltTurns: 2,
|
|
186
|
+
haltSpeed: 0.16,
|
|
187
|
+
},
|
|
188
|
+
// faster
|
|
189
|
+
{
|
|
190
|
+
launchTurns: 2,
|
|
191
|
+
launchSpeed: 0.5,
|
|
192
|
+
loopSpeed: 20,
|
|
193
|
+
haltTurns: 2,
|
|
194
|
+
haltSpeed: 0.22,
|
|
195
|
+
},
|
|
196
|
+
// faster with more turns
|
|
197
|
+
{
|
|
198
|
+
launchTurns: 6,
|
|
199
|
+
launchSpeed: 1.38,
|
|
200
|
+
loopSpeed: 45,
|
|
201
|
+
haltTurns: 6,
|
|
202
|
+
haltSpeed: 0.50,
|
|
203
|
+
},
|
|
204
|
+
];
|