@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.
Files changed (59) hide show
  1. package/dist/casino-engagement-suite-luckywheel/casino-engagement-suite-luckywheel.esm.js +1 -0
  2. package/dist/casino-engagement-suite-luckywheel/index.esm.js +1 -0
  3. package/dist/casino-engagement-suite-luckywheel/p-31e6965f.js +1 -0
  4. package/dist/casino-engagement-suite-luckywheel/p-c99c6eaf.entry.js +1 -0
  5. package/dist/casino-engagement-suite-luckywheel/p-e1255160.js +1 -0
  6. package/dist/casino-engagement-suite-luckywheel/p-f5a837f6.js +2 -0
  7. package/dist/cjs/app-globals-3a1e7e63.js +5 -0
  8. package/dist/cjs/casino-engagement-suite-luckywheel-d1e393bd.js +739 -0
  9. package/dist/cjs/casino-engagement-suite-luckywheel.cjs.entry.js +10 -0
  10. package/dist/cjs/casino-engagement-suite-luckywheel.cjs.js +25 -0
  11. package/dist/cjs/index-b3b5597c.js +1428 -0
  12. package/dist/cjs/index.cjs.js +10 -0
  13. package/dist/cjs/loader.cjs.js +15 -0
  14. package/dist/collection/collection-manifest.json +12 -0
  15. package/dist/collection/components/casino-engagement-suite-luckywheel/casino-engagement-suite-luckywheel.css +213 -0
  16. package/dist/collection/components/casino-engagement-suite-luckywheel/casino-engagement-suite-luckywheel.js +367 -0
  17. package/dist/collection/components/casino-engagement-suite-luckywheel/index.js +1 -0
  18. package/dist/collection/index.js +1 -0
  19. package/dist/collection/models/luckywheel.js +12 -0
  20. package/dist/collection/utils/class.spinable.js +38 -0
  21. package/dist/collection/utils/class.spinner.js +120 -0
  22. package/dist/collection/utils/class.svgcalc.js +175 -0
  23. package/dist/collection/utils/types.js +42 -0
  24. package/dist/collection/utils/utils.js +204 -0
  25. package/dist/esm/app-globals-0f993ce5.js +3 -0
  26. package/dist/esm/casino-engagement-suite-luckywheel-0aad8871.js +737 -0
  27. package/dist/esm/casino-engagement-suite-luckywheel.entry.js +2 -0
  28. package/dist/esm/casino-engagement-suite-luckywheel.js +20 -0
  29. package/dist/esm/index-27ac0c91.js +1401 -0
  30. package/dist/esm/index.js +2 -0
  31. package/dist/esm/loader.js +11 -0
  32. package/dist/index.cjs.js +1 -0
  33. package/dist/index.js +1 -0
  34. package/dist/stencil.config.dev.js +16 -0
  35. package/dist/stencil.config.js +17 -0
  36. package/dist/storybook/main.js +21 -0
  37. package/dist/storybook/preview.js +9 -0
  38. 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
  39. 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
  40. 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
  41. 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
  42. package/dist/types/components/casino-engagement-suite-luckywheel/casino-engagement-suite-luckywheel.d.ts +59 -0
  43. package/dist/types/components/casino-engagement-suite-luckywheel/index.d.ts +1 -0
  44. package/dist/types/components.d.ts +95 -0
  45. package/dist/types/index.d.ts +1 -0
  46. package/dist/types/models/luckywheel.d.ts +57 -0
  47. package/dist/types/stencil-public-runtime.d.ts +1680 -0
  48. package/dist/types/utils/class.spinable.d.ts +14 -0
  49. package/dist/types/utils/class.spinner.d.ts +26 -0
  50. package/dist/types/utils/class.svgcalc.d.ts +109 -0
  51. package/dist/types/utils/types.d.ts +55 -0
  52. package/dist/types/utils/utils.d.ts +78 -0
  53. package/loader/cdn.js +1 -0
  54. package/loader/index.cjs.js +1 -0
  55. package/loader/index.d.ts +24 -0
  56. package/loader/index.es2017.js +1 -0
  57. package/loader/index.js +2 -0
  58. package/loader/package.json +11 -0
  59. package/package.json +26 -0
@@ -0,0 +1,737 @@
1
+ import { r as registerInstance, h, g as getElement } from './index-27ac0c91.js';
2
+
3
+ /******************************************************************************
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission to use, copy, modify, and/or distribute this software for any
7
+ purpose with or without fee is hereby granted.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
16
+ ***************************************************************************** */
17
+
18
+ function __rest(s, e) {
19
+ var t = {};
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
21
+ t[p] = s[p];
22
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
23
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
24
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
25
+ t[p[i]] = s[p[i]];
26
+ }
27
+ return t;
28
+ }
29
+
30
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
31
+ var e = new Error(message);
32
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
33
+ };
34
+
35
+ var PointerMode;
36
+ (function (PointerMode) {
37
+ PointerMode["Arrow"] = "Arrow";
38
+ PointerMode["Partition"] = "Partition";
39
+ })(PointerMode || (PointerMode = {}));
40
+ var ArrowMode;
41
+ (function (ArrowMode) {
42
+ ArrowMode["DownFromTop"] = "DownFromTop";
43
+ ArrowMode["UpFromCenter"] = "UpFromCenter";
44
+ ArrowMode["DownFromCenter"] = "DownFromCenter";
45
+ ArrowMode["UpFromBottom"] = "UpFromBottom";
46
+ })(ArrowMode || (ArrowMode = {}));
47
+ var Lang;
48
+ (function (Lang) {
49
+ Lang["en"] = "en";
50
+ Lang["fr"] = "fr";
51
+ Lang["de"] = "de";
52
+ Lang["tr"] = "tr";
53
+ })(Lang || (Lang = {}));
54
+ var ContentDirection;
55
+ (function (ContentDirection) {
56
+ ContentDirection[ContentDirection["clockwise"] = 1] = "clockwise";
57
+ ContentDirection[ContentDirection["anticlockwise"] = -1] = "anticlockwise";
58
+ ContentDirection[ContentDirection["outward"] = 0] = "outward";
59
+ })(ContentDirection || (ContentDirection = {}));
60
+ var SpinStep;
61
+ (function (SpinStep) {
62
+ SpinStep["launch"] = "launch";
63
+ SpinStep["loop"] = "loop";
64
+ SpinStep["halt"] = "halt";
65
+ })(SpinStep || (SpinStep = {}));
66
+ var Easing;
67
+ (function (Easing) {
68
+ Easing["quad"] = "quad";
69
+ Easing["cubic"] = "cubic";
70
+ Easing["quart"] = "quart";
71
+ Easing["quint"] = "quint";
72
+ //
73
+ Easing["expo"] = "expo";
74
+ Easing["sine"] = "sine";
75
+ Easing["circ"] = "circ";
76
+ })(Easing || (Easing = {}));
77
+
78
+ const isSafari = () => {
79
+ var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
80
+ return isSafari;
81
+ };
82
+ const cvtCaseFromCamelToKebab = (text) => text
83
+ .split(/(?=[A-Z])/)
84
+ .map(s => s.toLocaleLowerCase())
85
+ .join('-');
86
+ const setProps = (element, props) => {
87
+ Object.keys(props).map(_key => {
88
+ element.setAttribute(cvtCaseFromCamelToKebab(_key), props[_key]);
89
+ });
90
+ };
91
+ const imageLoaderSvg = (src) => {
92
+ return new Promise((resolve, _reject) => {
93
+ let img = document.createElementNS("http://www.w3.org/2000/svg", "image");
94
+ img.onload = () => resolve(img);
95
+ img.onerror = () => resolve(img); //reject
96
+ img.href.baseVal = src;
97
+ });
98
+ };
99
+ const getSymmetricalPointFromScalar = (length) => ({
100
+ x: length,
101
+ y: length
102
+ });
103
+ const getPointOnCircle = (radius, angle, center) => {
104
+ const centerPoint = getSymmetricalPointFromScalar(center);
105
+ return {
106
+ x: centerPoint.x + radius * Math.cos(angle),
107
+ y: centerPoint.y + radius * Math.sin(angle)
108
+ };
109
+ };
110
+ const getPoint = (num, length, r, rCenter) => {
111
+ const arc = 360 / length;
112
+ const psai = Math.PI / 180 * (-90 + arc * (num - 1 / 2));
113
+ const rCenterPoint = getSymmetricalPointFromScalar(rCenter);
114
+ const rPoint = getSymmetricalPointFromScalar(r);
115
+ return {
116
+ x: rCenterPoint.x + rPoint.x * Math.cos(psai),
117
+ y: rCenterPoint.y + rPoint.y * Math.sin(psai)
118
+ };
119
+ };
120
+ const getPointWithNext = (num, length, r1, r2) => {
121
+ const getPointx = (num) => getPoint(num, length, r1, r2);
122
+ return {
123
+ point: getPointx(num),
124
+ pointNext: getPointx(num + 1)
125
+ };
126
+ };
127
+ const pointPlus = (point1, point2) => ({
128
+ x: point1.x + point2.x,
129
+ y: point1.y + point2.y
130
+ });
131
+ const optionCompliment = {
132
+ image: '',
133
+ name: 'Thank you',
134
+ prizeText: '',
135
+ prizeImage: ''
136
+ };
137
+ const getSumProbability = (partitions) => {
138
+ let probabilityAll = 0;
139
+ partitions.map(partition => {
140
+ probabilityAll += Number(partition.probability);
141
+ });
142
+ return probabilityAll;
143
+ };
144
+ const getOptionsFromPartitions = (partitions, lang) => {
145
+ const options = partitions.map(_partition => {
146
+ const option = {};
147
+ Object.keys(_partition).map((_key) => {
148
+ if (typeof _partition[_key] === 'object' &&
149
+ _partition[_key].hasOwnProperty('*')) {
150
+ const targetKey = _key === 'image1' ? 'image' : _key;
151
+ option[targetKey] = _partition[_key][lang] || _partition[_key]['*'];
152
+ }
153
+ });
154
+ return option;
155
+ });
156
+ if (getSumProbability(partitions) < 1) {
157
+ options.push(optionCompliment);
158
+ }
159
+ return options;
160
+ };
161
+ const preloadImage = async (src) => {
162
+ if (!src)
163
+ return {};
164
+ return {
165
+ image: await imageLoaderSvg(src)
166
+ };
167
+ };
168
+ const getOptions = async (bonus, lang) => {
169
+ const { partitions } = bonus.program.wheelOfFortune;
170
+ let options = getOptionsFromPartitions(partitions, lang);
171
+ if (isSafari()) {
172
+ options = options.map(option => {
173
+ if (option.image) {
174
+ const img = document.createElementNS('http://www.w3.org/2000/svg', 'image');
175
+ img.href.baseVal = option.image;
176
+ return Object.assign(Object.assign({}, option), { image: img });
177
+ }
178
+ else {
179
+ return option;
180
+ }
181
+ });
182
+ }
183
+ else {
184
+ options = await Promise.all(options.map(async (o) => (Object.assign(Object.assign({}, o), (await preloadImage(o.image))))));
185
+ }
186
+ return options;
187
+ };
188
+ const easing = {
189
+ in: {
190
+ quad: (x) => Math.pow(x, 2),
191
+ cubic: (x) => Math.pow(x, 3),
192
+ quart: (x) => Math.pow(x, 4),
193
+ quint: (x) => Math.pow(x, 5),
194
+ //
195
+ sine: (x) => 1 - Math.cos((x * Math.PI) / 2),
196
+ expo: (x) => x === 0 ? 0 : Math.pow(2, 10 * x - 10),
197
+ circ: (x) => 1 - Math.sqrt(1 - Math.pow(x, 2)),
198
+ },
199
+ out: {
200
+ quad: (x) => 1 - Math.pow(1 - x, 2),
201
+ cubic: (x) => 1 - Math.pow(1 - x, 3),
202
+ quart: (x) => 1 - Math.pow(1 - x, 4),
203
+ quint: (x) => 1 - Math.pow(1 - x, 5),
204
+ //
205
+ sine: (x) => Math.sin((x * Math.PI) / 2),
206
+ expo: (x) => x === 1 ? 1 : 1 - Math.pow(2, -10 * x),
207
+ circ: (x) => Math.sqrt(1 - Math.pow(x - 1, 2)),
208
+ }
209
+ };
210
+ const easingGrad = {
211
+ quad: 2,
212
+ cubic: 3,
213
+ quart: 4,
214
+ quint: 5,
215
+ sine: Math.PI / 2,
216
+ expo: Math.LN2,
217
+ circ: Infinity,
218
+ };
219
+ const easingGradX = {
220
+ in: {
221
+ quad: (x) => 2 * x,
222
+ cubic: (x) => 3 * x ** 2,
223
+ quart: (x) => 4 * x ** 3,
224
+ quint: (x) => 5 * x ** 4,
225
+ sine: (x) => Math.PI / 2 * Math.sin(Math.PI / 2 * x),
226
+ expo: (x) => Math.LN2 * 10 * 2 ** (10 * x - 10),
227
+ circ: (x) => -1 / 2 * (1 - x ** 2) ** (-1 / 2),
228
+ },
229
+ out: {
230
+ cubic: (x) => 3 * x ** 2 - 6 * x + 3,
231
+ }
232
+ };
233
+ const params = [
234
+ // basic
235
+ {
236
+ launchTurns: 5,
237
+ launchSpeed: 0.2,
238
+ loopSpeed: 15,
239
+ haltTurns: 2,
240
+ haltSpeed: 0.16,
241
+ },
242
+ // faster
243
+ {
244
+ launchTurns: 2,
245
+ launchSpeed: 0.5,
246
+ loopSpeed: 20,
247
+ haltTurns: 2,
248
+ haltSpeed: 0.22,
249
+ },
250
+ // faster with more turns
251
+ {
252
+ launchTurns: 6,
253
+ launchSpeed: 1.38,
254
+ loopSpeed: 45,
255
+ haltTurns: 6,
256
+ haltSpeed: 0.50,
257
+ },
258
+ ];
259
+
260
+ const mapObjectValueToTuple = (object) => Object.keys(object).map(key => object[key]);
261
+ var RotateDirection;
262
+ (function (RotateDirection) {
263
+ RotateDirection[RotateDirection["clockwise"] = 1] = "clockwise";
264
+ RotateDirection[RotateDirection["anticlockwise"] = -1] = "anticlockwise";
265
+ })(RotateDirection || (RotateDirection = {}));
266
+ class SvgCalc {
267
+ constructor({ size, radius, options, themeIndex, contentdirection }) {
268
+ this.arrowmode = ArrowMode.DownFromTop;
269
+ this.convertDegToArc = (deg) => deg * Math.PI / 180;
270
+ this.convertArcToDeg = (arc) => arc * 180 / Math.PI % 360;
271
+ this.getArcDelta = (n) => 2 * Math.PI / n;
272
+ this.findDeg = (index, n) => {
273
+ const degDelta = this.convertArcToDeg(this.getArcDelta(n));
274
+ return (index) * degDelta;
275
+ };
276
+ this.angleTransform = (arrowmode) => {
277
+ switch (arrowmode) {
278
+ case ArrowMode.DownFromTop:
279
+ case ArrowMode.UpFromCenter:
280
+ return -Math.PI / 2;
281
+ case ArrowMode.DownFromCenter:
282
+ case ArrowMode.UpFromBottom:
283
+ return Math.PI / 2;
284
+ }
285
+ };
286
+ this.contentdirection = contentdirection || 'anticlockwise';
287
+ // size
288
+ this.center = size / 2;
289
+ this.ratio = size / 375;
290
+ // options
291
+ this.options = options;
292
+ this.length = options.length;
293
+ // theme
294
+ this.themeIndex = themeIndex;
295
+ //
296
+ this.radius = radius;
297
+ }
298
+ get sizeImage() {
299
+ const getSize = (length) => this.ratio * 48 * 5 / length;
300
+ if (this.length <= 3)
301
+ return getSize(4);
302
+ switch (this.length) {
303
+ case 8:
304
+ case 7: return this.ratio * 24;
305
+ case 6: return this.ratio * 36;
306
+ case 5: return this.ratio * 48;
307
+ case 4: return this.ratio * 56;
308
+ default: return getSize(this.length);
309
+ }
310
+ }
311
+ getSizeImageByPartition(index) {
312
+ if (this.options[index].name) {
313
+ return this.sizeImage / 2;
314
+ }
315
+ else {
316
+ return this.sizeImage;
317
+ }
318
+ }
319
+ getSvgImageProps(index, partitionDivisor = 1.25) {
320
+ const sizeImage = this.getSizeImageByPartition(index);
321
+ let baseRadius;
322
+ if (this.options[index].name) {
323
+ baseRadius = this.radius - sizeImage / 2 - 3 * this.ratio;
324
+ }
325
+ else {
326
+ baseRadius = (this.radius - sizeImage / 2) / Number(partitionDivisor) - 3 * this.ratio;
327
+ }
328
+ return Object.assign(Object.assign({}, this.getPropsForPartitionInfo(index, this.getOffsetImage(sizeImage), baseRadius, ContentDirection.outward)), { width: sizeImage, height: sizeImage });
329
+ }
330
+ getSvgTextProps(index) {
331
+ const sizeImage = this.getSizeImageByPartition(index);
332
+ let baseRadius;
333
+ if (this.options[index].image) {
334
+ baseRadius = this.radius - sizeImage - 6 * this.ratio;
335
+ }
336
+ else {
337
+ baseRadius = this.radius - 6 * this.ratio;
338
+ }
339
+ return Object.assign({}, this.getPropsForPartitionInfo(index, this.offsetText, baseRadius));
340
+ }
341
+ getSvgTextPropsAdjustedByImage(index) {
342
+ const props = this.getSvgTextProps(index);
343
+ const size = this.options[index].image ? 80 : 100;
344
+ const objectSize = {
345
+ width: size,
346
+ height: size
347
+ };
348
+ 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 });
349
+ }
350
+ get offsetText() {
351
+ return {
352
+ center: 0,
353
+ position: {
354
+ x: 0,
355
+ y: 0
356
+ },
357
+ transform: {
358
+ x: 0,
359
+ y: 0
360
+ }
361
+ };
362
+ }
363
+ getOffsetImage(sizeImage) {
364
+ return {
365
+ center: 0,
366
+ position: {
367
+ x: -1 * sizeImage / 2,
368
+ y: -1 * sizeImage / 2
369
+ },
370
+ transform: {
371
+ x: 0,
372
+ y: 0
373
+ }
374
+ };
375
+ }
376
+ get direction() {
377
+ return RotateDirection.clockwise;
378
+ }
379
+ getAngleSelf(index, contentDirection) {
380
+ const baseAngle = 360 * index / this.length * this.direction;
381
+ const fixerAngle = 90 * (contentDirection !== undefined ? contentDirection : ContentDirection[this.contentdirection]);
382
+ const resultAngle = baseAngle + fixerAngle;
383
+ return resultAngle;
384
+ }
385
+ getPartitionPositions(index, baseRadius, offset) {
386
+ const angle = this.angleTransform(this.arrowmode) +
387
+ this.direction * index * 2 * Math.PI / this.length;
388
+ const point = getPointOnCircle(baseRadius || this.radius - 9 * this.ratio, angle, this.center + offset.center);
389
+ const transformOrigin = pointPlus(point, offset.transform);
390
+ const pointResult = pointPlus(point, offset.position);
391
+ return {
392
+ transformOrigin,
393
+ point: pointResult
394
+ };
395
+ }
396
+ getPropsForPartitionInfo(index, offset, baseRadius, contentDirection) {
397
+ const { point, transformOrigin } = this.getPartitionPositions(index, baseRadius, offset);
398
+ const getTransformOriginString = (vector) => Object.keys(vector).map(axis => `${vector[axis]}px`).join(' ');
399
+ return Object.assign(Object.assign({}, point), { style: {
400
+ 'font-size': `${13 * this.ratio}px`,
401
+ 'transform': `rotate(${this.getAngleSelf(index, contentDirection)}deg)`,
402
+ 'transform-origin': `${getTransformOriginString(transformOrigin)}`
403
+ } });
404
+ }
405
+ getPartitionDraw(index) {
406
+ const rPoint = getSymmetricalPointFromScalar(this.center);
407
+ const rRingInnerPoint = getSymmetricalPointFromScalar(this.radius);
408
+ const { point, pointNext } = getPointWithNext(index, this.length, this.radius, this.center);
409
+ const ds = [
410
+ 'M', ...mapObjectValueToTuple(rPoint),
411
+ 'L', ...mapObjectValueToTuple(point),
412
+ 'A',
413
+ ...mapObjectValueToTuple(rRingInnerPoint),
414
+ '0 0 1',
415
+ ...mapObjectValueToTuple(pointNext),
416
+ 'Z'
417
+ ];
418
+ return {
419
+ d: ds.join(' ')
420
+ };
421
+ }
422
+ getDeg(index) {
423
+ const i = index || this.length - 1;
424
+ return this.findDeg(length - i, length);
425
+ }
426
+ getSpinnerProps() {
427
+ const centerPoint = getSymmetricalPointFromScalar(this.center);
428
+ return {
429
+ 'transform-origin': `${centerPoint.x} ${centerPoint.y}`
430
+ };
431
+ }
432
+ }
433
+
434
+ class Spinner {
435
+ constructor(inits) {
436
+ this.deg = 0;
437
+ this.degTarget = undefined;
438
+ this.step = undefined;
439
+ this.easingType = Easing.cubic;
440
+ this.param = params[2];
441
+ this.halt = (deg, cb = () => { }) => {
442
+ this.shouldHalt = () => {
443
+ this.step = SpinStep.halt;
444
+ this.cb = () => {
445
+ cb();
446
+ this.setDeg(deg, 0);
447
+ };
448
+ this.degTarget = deg + 360 * this.param.haltTurns;
449
+ this.continueRepeat();
450
+ };
451
+ };
452
+ this.continueRepeat = () => setTimeout(() => this.ticker(), 30);
453
+ this.ticker = () => {
454
+ const linkSpeed = this.param.loopSpeed;
455
+ const easingDuration = (deg) => 33 * easingGrad[this.easingType] * deg / this.param.loopSpeed;
456
+ const animations = {
457
+ launch: () => {
458
+ const degTar = 360 * this.param.launchTurns - this.deg;
459
+ const t = easingDuration(degTar);
460
+ this.animateF(t, this.deg, degTar, easing.in[this.easingType], easingGradX.in[this.easingType]);
461
+ },
462
+ halt: () => {
463
+ const t = easingDuration(this.degTarget);
464
+ this.animateF(t, 0, this.degTarget, easing.out[this.easingType], easingGradX.out[this.easingType]);
465
+ },
466
+ loop: () => {
467
+ this.setDeg((this.deg + linkSpeed) % 360, easingGrad[this.easingType]);
468
+ this.continueRepeat();
469
+ }
470
+ };
471
+ const stepSwitcher = {
472
+ [SpinStep.launch]: () => {
473
+ this.cb = () => {
474
+ this.step = SpinStep.loop;
475
+ this.setDeg(linkSpeed, easingGrad[this.easingType]);
476
+ this.continueRepeat();
477
+ };
478
+ animations.launch();
479
+ },
480
+ [SpinStep.loop]: () => {
481
+ if (this.shouldHalt && this.deg === 0) {
482
+ this.shouldHalt();
483
+ }
484
+ else {
485
+ animations.loop();
486
+ }
487
+ },
488
+ [SpinStep.halt]: () => {
489
+ if (this.deg === 360 - linkSpeed) {
490
+ animations.halt();
491
+ }
492
+ else {
493
+ animations.loop();
494
+ }
495
+ }
496
+ };
497
+ stepSwitcher[this.step]();
498
+ };
499
+ this.setDeg = (deg, speed) => {
500
+ this.deg = deg;
501
+ this.tick(deg, speed);
502
+ };
503
+ this.animateF = (duration, startAngle, target, easing, _easingGrad) => {
504
+ let start = null;
505
+ const step = () => {
506
+ let timestamp = new Date().getTime();
507
+ if (!start) {
508
+ start = timestamp;
509
+ }
510
+ const progress = timestamp - start;
511
+ const translation = target * easing(progress / duration) + startAngle;
512
+ const speedCur = Math.abs(_easingGrad(progress / duration));
513
+ this.setDeg(translation, speedCur);
514
+ if (progress < duration) {
515
+ setTimeout(() => step(), 30);
516
+ }
517
+ else {
518
+ this.cb();
519
+ }
520
+ };
521
+ step();
522
+ };
523
+ this.animate = (duration, startAngle, target, easing, _easingGrad) => {
524
+ let animationId = null;
525
+ window.cancelAnimationFrame(animationId);
526
+ let start = null;
527
+ const step = (timestamp) => {
528
+ if (!start) {
529
+ start = timestamp;
530
+ }
531
+ const progress = timestamp - start;
532
+ const translation = target * easing(progress / duration) + startAngle;
533
+ const speedCur = Math.abs(_easingGrad(progress / duration));
534
+ this.setDeg(translation, speedCur);
535
+ if (progress < duration) {
536
+ animationId = window.requestAnimationFrame(step);
537
+ }
538
+ else {
539
+ this.cb();
540
+ }
541
+ };
542
+ animationId = window.requestAnimationFrame(step);
543
+ };
544
+ this.tick = inits.tick;
545
+ }
546
+ launch() {
547
+ this.shouldHalt = undefined;
548
+ this.step = SpinStep.launch;
549
+ this.ticker();
550
+ }
551
+ }
552
+
553
+ const casinoEngagementSuiteLuckywheelCss = ":host{font-family:system-ui, -apple-system, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\"}*,*::before,*::after{margin:0;padding:0;list-style:none;text-decoration:none;outline:none;box-sizing:border-box}.LotteryProgramWof{background:var(--emw--color-contrast, #07072A);display:flex;align-items:center;flex-direction:column;padding:20px 0}main{max-width:600px;width:100%;display:flex;justify-content:space-around;min-height:200px}svg{transition:opacity 0.3s}.WheelContainer{text-align:center}.FortuneContainer{width:100%;display:flex;align-items:center;flex-direction:column}.Center{cursor:pointer;transition:filter;transition-duration:1s}.Center.disabled{filter:grayscale(80%)}.Center .CenterCircle{fill:#3CE4BB;stroke:rgb(150, 54, 88);stroke-width:2px;cursor:pointer;transition:fill;transition-duration:1s}.Center .CenterText{fill:#FFFFFF}.PointerPartition{opacity:0.3;fill:lightgoldenrodyellow;stroke:red;stroke-width:6px;stroke-dasharray:12}.Current{color:#FFFFFF}.PartitionText{color:#FFFFFF;font-style:normal;font-weight:700;text-anchor:end;text-shadow:0px 3px #000;dominant-baseline:central}.PartitionsShadow{background-blend-mode:multiply;mix-blend-mode:multiply}.PartitionTextEntityContainer{height:100%;display:flex;align-items:center}.PartitionTextEntity{width:100%}.PartitionTextEntity.Anticlockwise{text-align:end}foreignObject.Bottom div{background-image:url(\"https://static.everymatrix.com/gic/img/engagement-suite/bar/luckywheel/luckywheel-bg.svg\");background-size:calc(var(--radius) * 2px + var(--ratio) * 20px);background-position:center}foreignObject.Middle div{background-image:url(\"https://static.everymatrix.com/gic/img/engagement-suite/bar/luckywheel/luckywheel-spin.svg\"), url(\"https://static.everymatrix.com/gic/img/engagement-suite/bar/luckywheel/luckywheel-pointer.svg\");background-position:center, center 5px}foreignObject.Top{mix-blend-mode:multiply}foreignObject.Top div{background-image:var(--img-theme-shadow);background-position:center;background-size:calc(var(--radius) * 2px)}foreignObject.Partition1 div{background-image:var(--img-theme-partition-light);background-position:center calc((var(--size) / 2 - var(--radius)) * 1px - var(--ratio) * 22px);transform:rotate(calc(var(--index) * 360deg / var(--length)))}foreignObject.Partition2 div{background-image:var(--img-theme-partition-light);background-position:center calc((var(--size) / 2 - var(--radius)) * 1px - var(--ratio) * 22px);transform:rotate(calc((var(--index) + 0.5) * 360deg / var(--length)))}foreignObject.PointerArea{mix-blend-mode:screen}foreignObject.PointerArea div{background-image:var(--img-theme-pointer-area);background-position:center -3px;background-size:51%}foreignObject.Partition1 div,foreignObject.Partition2 div{transform-origin:center}.PartitionsCustomable1 div,.PartitionsCustomable2 div{visibility:hidden}.PartitionsCustomable1 div.active,.PartitionsCustomable2 div.active{visibility:visible}foreignObject.Customable{overflow:visible}foreignObject.Customable div{background-repeat:no-repeat}.PartitionBackground div{background-size:calc(var(--radius) * 2 / var(--size) * 100%) calc(var(--radius) * 2 / var(--size) * 100%);background-position:center}.PartitionBackground:nth-child(2n) div{background:var(--emw--color-primary, #3F2E75)}.PartitionBackground:nth-child(2n+1) div{background:var(--emw--color-secondary, #9482CE)}.PartitionBackground div{transform-origin:center}.PartitionBackgroundStroke{fill:transparent;stroke:var(--emw--color-background-secondary, #251D3E);stroke-width:3px;stroke-dasharray:none}.PointerPartitionFrame{stroke:#FFDD64;fill:transparent;stroke-dasharray:var(--radius) calc(6.2831853072 / var(--length) * var(--radius));stroke-width:0px}.PointerPartitionFrame.active{stroke-width:3px}.WheelContainer.Mobile foreignObject.Middle div{background-size:95px, 38px}.PartitionText .PartitionTextEntityContainer .PartitionTextEntity{text-align:center;text-transform:uppercase;text-shadow:none;font-size:var(--emw--font-size-small, 14px);font-weight:900}";
554
+ const CasinoEngagementSuiteLuckywheelStyle0 = casinoEngagementSuiteLuckywheelCss;
555
+
556
+ const CasinoEngagementSuiteLuckywheel = class {
557
+ constructor(hostRef) {
558
+ registerInstance(this, hostRef);
559
+ /**
560
+ * Client custom styling via string
561
+ */
562
+ this.clientStyling = '';
563
+ /**
564
+ * Client custom styling via url
565
+ */
566
+ this.clientStylingUrl = '';
567
+ /**
568
+ * Language of the widget
569
+ */
570
+ this.language = 'en';
571
+ /**
572
+ * User's device type
573
+ */
574
+ this.device = 'Mobile';
575
+ /**
576
+ * Wheel size
577
+ */
578
+ this.size = '440';
579
+ /**
580
+ * Content Direction
581
+ */
582
+ this.contentdirection = 'anticlockwise';
583
+ this.limitStylingAppends = false;
584
+ this.isPartitionsCustomableReady = false;
585
+ this.isSpinning = false;
586
+ this.radius = 0.85 * Number(this.size) / 2;
587
+ this.speed = 0;
588
+ this.setClientStyling = () => {
589
+ let sheet = document.createElement('style');
590
+ sheet.innerHTML = this.clientStyling;
591
+ this.host.prepend(sheet);
592
+ };
593
+ this.setClientStylingURL = () => {
594
+ let url = new URL(this.clientStylingUrl);
595
+ let cssFile = document.createElement('style');
596
+ fetch(url.href)
597
+ .then((res) => res.text())
598
+ .then((data) => {
599
+ cssFile.innerHTML = data;
600
+ setTimeout(() => { this.host.prepend(cssFile); }, 1);
601
+ })
602
+ .catch((err) => {
603
+ console.log('Error ', err);
604
+ });
605
+ };
606
+ this.renderImage = (node, index) => {
607
+ const image = this.options[index].image;
608
+ setProps(image, this.settings.getSvgImageProps(index));
609
+ node.innerHTML = null;
610
+ node.appendChild(image);
611
+ };
612
+ this.updateSpinable = () => {
613
+ if (!!this.luckywheel.current) {
614
+ if (Number(this.luckywheel.current.remainingTimes) > 0) {
615
+ this.spinable = true;
616
+ return;
617
+ }
618
+ else {
619
+ window.postMessage({ type: 'ShowNoSpinLeftModal' });
620
+ }
621
+ }
622
+ this.spinable = false;
623
+ };
624
+ this.eventSpin = () => {
625
+ this.updateSpinable();
626
+ if (!this.spinable || this.isSpinning) {
627
+ return;
628
+ }
629
+ this.isSpinning = true;
630
+ this.spinContainer = this.svg.querySelector('g.PartitionsContainer');
631
+ this.spinner.launch();
632
+ window.postMessage({
633
+ type: 'SpinLuckyWheel',
634
+ lotteryProgramID: this.luckywheel.program.id,
635
+ });
636
+ // todo: this code below simulates the server response,
637
+ // delete after implementation with GLС
638
+ setTimeout(() => {
639
+ window.postMessage({
640
+ type: 'SpinLuckyWheelRes',
641
+ data: {
642
+ item: { result: { wheelOfFortunePartitionIndex: 1 } },
643
+ success: false
644
+ }
645
+ });
646
+ }, 2500);
647
+ };
648
+ this.handleSpinClick = () => {
649
+ if (isSafari()) {
650
+ return;
651
+ }
652
+ this.eventSpin();
653
+ };
654
+ }
655
+ handleEvent(e) {
656
+ const _a = e === null || e === void 0 ? void 0 : e.data, { type } = _a, rest = __rest(_a, ["type"]);
657
+ switch (type) {
658
+ case 'SpinLuckyWheelRes':
659
+ this.spinner.halt(this.settings.getDeg(rest.data.item.result.wheelOfFortunePartitionIndex), () => {
660
+ this.isSpinning = false;
661
+ this.updateSpinable();
662
+ const prizeText = this.luckywheel.program.wheelOfFortune.partitions[rest.data.item.result.wheelOfFortunePartitionIndex].prizeText;
663
+ window.postMessage({
664
+ type: 'ShowLuckywheelRewardModal',
665
+ data: {
666
+ PrizeMessage: prizeText['en'] || prizeText['*'],
667
+ HasError: rest.data.success,
668
+ }
669
+ });
670
+ });
671
+ break;
672
+ }
673
+ }
674
+ componentDidRender() {
675
+ if (!this.limitStylingAppends && this.host) {
676
+ if (this.clientStyling)
677
+ this.setClientStyling();
678
+ if (this.clientStylingUrl)
679
+ this.setClientStylingURL();
680
+ this.limitStylingAppends = true;
681
+ }
682
+ }
683
+ async componentWillLoad() {
684
+ this.options = await getOptions(this.luckywheel, Lang.en);
685
+ this.settings = new SvgCalc({
686
+ size: this.size,
687
+ radius: this.radius,
688
+ options: this.options,
689
+ themeIndex: 1,
690
+ contentdirection: this.contentdirection
691
+ });
692
+ this.spinner = new Spinner({
693
+ tick: (deg, speed) => {
694
+ setProps(this.spinContainer, {
695
+ style: [
696
+ `transform: rotate(${deg}deg)`,
697
+ `height: ${this.size}px`,
698
+ `width: ${this.size}px`,
699
+ ].join(';'),
700
+ });
701
+ this.speed = speed * 0.5;
702
+ }
703
+ });
704
+ }
705
+ defineGeneralVariables() {
706
+ return {
707
+ '--length': `${this.options.length}`,
708
+ '--radius': `${this.radius}`,
709
+ '--ratio': `${Number(this.size) / 480}`,
710
+ '--size': `${this.size}`,
711
+ };
712
+ }
713
+ render() {
714
+ const sizeProps = { height: this.size, width: this.size };
715
+ const foreignObjectAgentProps = { 'height': `${this.size}px`, 'width': `${this.size}px` };
716
+ return (h("div", { key: '8d964d9a81690d2a22240cb1355abb3c7cf6f665', class: `WheelContainer ${this.device}`, style: this.defineGeneralVariables() }, h("svg", { key: '92f44f4659874e1fedaffa32813c57d1c9c04440', width: this.size, height: this.size, ref: (el) => { this.svg = el; } }, h("foreignObject", Object.assign({ key: 'f042214f1516c688035f650a92ff1437c5d06a36' }, sizeProps, { class: "Bottom Customable" }), h("div", { key: '6c80c40dfdb80159d75af8f70a75604257039c53', style: foreignObjectAgentProps })), h("g", Object.assign({ key: '46c01589f440c19727c8364d5e1bdb3a90082cac', class: "PartitionsContainer" }, this.settings.getSpinnerProps()), h("g", { key: 'fd0e9a65b7ba25db742ff12bb26e389b8d72e4c7', class: "PartitionsBackgrounds" }, this.options.map((_el, index) => {
717
+ return (h("foreignObject", { "clip-path": `url(#clip${index})`, class: "PartitionBackground Customable", style: { '--index': index.toString() }, width: this.size, height: this.size }, h("div", { style: foreignObjectAgentProps })));
718
+ })), h("g", { key: '8c116aa611b92b87b98f23aa344025953a27e90d', class: "PartitionsBackgroundStrokes" }, this.options.map((_el, index) => {
719
+ return (h("path", Object.assign({ class: "PartitionBackgroundStroke" }, this.settings.getPartitionDraw(index), { width: this.size, height: this.size })));
720
+ })), h("g", { key: '8907e6529e660e6452328aaa684995719b528ec6', class: "Partitions", style: { filter: this.speed > 0.3 ? `blur(${this.speed}px)` : '' } }, this.options.map((el, index) => {
721
+ return ([
722
+ el.image && (h("g", { class: `PartitionImage PartitionImage${index}`, ref: (el) => this.renderImage(el, index) })),
723
+ el.name && (h("foreignObject", Object.assign({ class: "PartitionText" }, this.settings.getSvgTextPropsAdjustedByImage(index)), h("div", { class: "PartitionTextEntityContainer" }, h("p", { class: `PartitionTextEntity${this.settings.contentdirection === 'clockwise' ? '' : ' Anticlockwise'}`, innerHTML: el.name }))))
724
+ ]);
725
+ }))), h("g", { key: '62cf4e41e77374dd8f8c1af0833a4143e5d45403', class: { 'active': this.isPartitionsCustomableReady, 'PartitionsCustomable1': true } }, this.options.map((_el, index) => {
726
+ return (h("foreignObject", Object.assign({ class: "Partition1 Customable", style: { '--index': index.toString() } }, sizeProps), h("div", { style: foreignObjectAgentProps })));
727
+ })), h("g", { key: '6b0538da5d4f52e4b543205fb64dedda084f81b2', class: { 'active': this.isPartitionsCustomableReady, 'PartitionsCustomable2': true } }, this.options.map((_el, index) => {
728
+ return (h("foreignObject", Object.assign({ class: "Partition2 Customable", style: { '--index': index.toString() } }, sizeProps), h("div", { style: foreignObjectAgentProps })));
729
+ })), h("foreignObject", Object.assign({ key: '907db579094a7a192999510ade3150fdadbb94b6', class: "Middle Customable" }, sizeProps), h("div", { key: 'fa66cb96da2f285015fb8afeea5db05313ed832c', style: foreignObjectAgentProps })), h("foreignObject", Object.assign({ key: '688c0d33ad480ea331847286335a88fd74dbbb26', class: "Top Customable" }, sizeProps), h("div", { key: '292f6ea3549322a605fc8c3c61a93addcba00890', style: foreignObjectAgentProps })), h("g", { key: '22368be98007a7fa820cee96c666c363f85cd32a', class: { 'spinning': this.isSpinning, 'Center': true }, onClick: this.handleSpinClick }, h("foreignObject", { key: 'efffd7edb9ed21d5bd93896a4bead8931d91ff1f', x: Number(this.size) / 2 - 100 / 2, y: Number(this.size) / 2 - 100 / 2, width: 100, height: 100 })), h("g", { key: '7d8b741cc21d6d07f5736336f147cef2bfdf90ca' }, this.options.map((_el, index) => {
730
+ return (h("clipPath", { id: `clip${index}` }, h("path", Object.assign({}, this.settings.getPartitionDraw(index)))));
731
+ })))));
732
+ }
733
+ get host() { return getElement(this); }
734
+ };
735
+ CasinoEngagementSuiteLuckywheel.style = CasinoEngagementSuiteLuckywheelStyle0;
736
+
737
+ export { CasinoEngagementSuiteLuckywheel as C };