@everymatrix/lottery-program-wof 1.44.0 → 1.45.3
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/es2015/lottery-program-wof.cjs +1 -0
- package/es2015/lottery-program-wof.js +16 -0
- package/package.json +14 -37
- package/CHANGELOG.md +0 -12
- package/README.md +0 -30
- package/babel.config.js +0 -6
- package/dist/lottery-program-wof.js +0 -11886
- package/dist/lottery-program-wof.js.map +0 -1
- package/index.html +0 -42
- package/index.js +0 -1
- package/public/favicon.png +0 -0
- package/public/reset.css +0 -48
- package/rollup.config.js +0 -61
- package/src/LotteryProgramWof.svelte +0 -214
- package/src/api/api.ts +0 -2016
- package/src/api/configuration.ts +0 -65
- package/src/api/custom.d.ts +0 -2
- package/src/api/index.ts +0 -15
- package/src/business.partition.ts +0 -98
- package/src/business.ts +0 -186
- package/src/calc.point.ts +0 -67
- package/src/calc.temp.ts +0 -29
- package/src/calc.ts +0 -28
- package/src/class.process.ts +0 -130
- package/src/class.spinable.ts +0 -60
- package/src/class.spinable.util.ts +0 -10
- package/src/class.spinner.ts +0 -176
- package/src/class.spinner.util.ts +0 -92
- package/src/class.svgcalc.ts +0 -249
- package/src/i18n.ts +0 -38
- package/src/images/Thankyou_1.svg +0 -100
- package/src/images/Thankyou_2.svg +0 -112
- package/src/images/Thankyou_3.svg +0 -87
- package/src/images/Thankyou_4.svg +0 -114
- package/src/images/gift.svg +0 -964
- package/src/images/theme.bg.blackring.svg +0 -10
- package/src/images/theme.bg.halo.svg +0 -27
- package/src/images/theme1Bg3.svg +0 -15
- package/src/images/theme2Arrow.svg +0 -24
- package/src/images/theme2Bg3.svg +0 -11
- package/src/images/theme2Center.svg +0 -36
- package/src/images/theme3Arrow.svg +0 -25
- package/src/images/theme3Bg1.svg +0 -29
- package/src/images/theme3Bg2.svg +0 -19
- package/src/images/theme3Center.svg +0 -77
- package/src/images/theme7Arrow.svg +0 -67
- package/src/images/theme7Bg1.svg +0 -786
- package/src/images/theme7Bg2.svg +0 -40
- package/src/images/theme7Bg3.svg +0 -26
- package/src/images/theme7Center.svg +0 -72
- package/src/images/theme7Light.svg +0 -17
- package/src/images/themeCenter1.svg +0 -76
- package/src/images/themeCenter2.svg +0 -58
- package/src/images/themePartitionLight.svg +0 -19
- package/src/images/themePointerArea.svg +0 -44
- package/src/images/themeShadow.svg +0 -27
- package/src/index.ts +0 -4
- package/src/message.ts +0 -28
- package/src/private.item.svelte +0 -172
- package/src/private.item.svg.scss +0 -302
- package/src/private.item.svg.svelte +0 -356
- package/src/private.loader.svelte +0 -61
- package/src/private.message.svelte +0 -236
- package/src/private.outcomes.svelte +0 -203
- package/src/private.tabs.svelte +0 -106
- package/src/themes.image.center.ts +0 -68
- package/src/themes.ts +0 -52
- package/src/translations.js +0 -218
- package/src/types.business.ts +0 -20
- package/src/types.ts +0 -79
- package/src/util.ts +0 -90
- package/src/widget.ts +0 -27
- package/stories/LotteryProgramWof.stories.js +0 -13
- package/svelte.config.js +0 -7
- package/tsconfig.json +0 -11
package/src/api/configuration.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// tslint:disable
|
|
2
|
-
/**
|
|
3
|
-
* BE.Server
|
|
4
|
-
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
|
5
|
-
*
|
|
6
|
-
* OpenAPI spec version: 1.0
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* NOTE: This file is auto generated by the swagger code generator program.
|
|
10
|
-
* https://github.com/swagger-api/swagger-codegen.git
|
|
11
|
-
* Do not edit the file manually.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
export interface ConfigurationParameters {
|
|
15
|
-
apiKey?: string | ((name: string) => string);
|
|
16
|
-
username?: string;
|
|
17
|
-
password?: string;
|
|
18
|
-
accessToken?: string | ((name: string, scopes?: string[]) => string);
|
|
19
|
-
basePath?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class Configuration {
|
|
23
|
-
/**
|
|
24
|
-
* parameter for apiKey security
|
|
25
|
-
* @param name security name
|
|
26
|
-
* @memberof Configuration
|
|
27
|
-
*/
|
|
28
|
-
apiKey?: string | ((name: string) => string);
|
|
29
|
-
/**
|
|
30
|
-
* parameter for basic security
|
|
31
|
-
*
|
|
32
|
-
* @type {string}
|
|
33
|
-
* @memberof Configuration
|
|
34
|
-
*/
|
|
35
|
-
username?: string;
|
|
36
|
-
/**
|
|
37
|
-
* parameter for basic security
|
|
38
|
-
*
|
|
39
|
-
* @type {string}
|
|
40
|
-
* @memberof Configuration
|
|
41
|
-
*/
|
|
42
|
-
password?: string;
|
|
43
|
-
/**
|
|
44
|
-
* parameter for oauth2 security
|
|
45
|
-
* @param name security name
|
|
46
|
-
* @param scopes oauth2 scope
|
|
47
|
-
* @memberof Configuration
|
|
48
|
-
*/
|
|
49
|
-
accessToken?: string | ((name: string, scopes?: string[]) => string);
|
|
50
|
-
/**
|
|
51
|
-
* override base path
|
|
52
|
-
*
|
|
53
|
-
* @type {string}
|
|
54
|
-
* @memberof Configuration
|
|
55
|
-
*/
|
|
56
|
-
basePath?: string;
|
|
57
|
-
|
|
58
|
-
constructor(param: ConfigurationParameters = {}) {
|
|
59
|
-
this.apiKey = param.apiKey;
|
|
60
|
-
this.username = param.username;
|
|
61
|
-
this.password = param.password;
|
|
62
|
-
this.accessToken = param.accessToken;
|
|
63
|
-
this.basePath = param.basePath;
|
|
64
|
-
}
|
|
65
|
-
}
|
package/src/api/custom.d.ts
DELETED
package/src/api/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// tslint:disable
|
|
2
|
-
/**
|
|
3
|
-
* BE.Server
|
|
4
|
-
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
|
5
|
-
*
|
|
6
|
-
* OpenAPI spec version: 1.0
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* NOTE: This file is auto generated by the swagger code generator program.
|
|
10
|
-
* https://github.com/swagger-api/swagger-codegen.git
|
|
11
|
-
* Do not edit the file manually.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
export * from "./api";
|
|
15
|
-
export * from "./configuration";
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import type { WheelOfFortunePartition } from './api'
|
|
2
|
-
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import Thankyou1Svg from './images/Thankyou_1.svg'
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import Thankyou2Svg from './images/Thankyou_2.svg'
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
import Thankyou3Svg from './images/Thankyou_3.svg'
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
import Thankyou4Svg from './images/Thankyou_4.svg'
|
|
11
|
-
import type { Lang } from './types'
|
|
12
|
-
import type { LotteryProgramForPlayer } from './types.business'
|
|
13
|
-
import { imageLoaderSvg, isSafari } from './util'
|
|
14
|
-
|
|
15
|
-
export interface Option {
|
|
16
|
-
image: SVGElement | string,
|
|
17
|
-
name: string,
|
|
18
|
-
prizeText: string,
|
|
19
|
-
prizeImage: string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const optionCompliment = {
|
|
23
|
-
image: Thankyou1Svg,
|
|
24
|
-
name: 'Thank you',
|
|
25
|
-
prizeText: '',
|
|
26
|
-
prizeImage: '',
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const getSumProbability = (partitions) => {
|
|
30
|
-
let probabilityAll = 0
|
|
31
|
-
partitions.map(partition => {
|
|
32
|
-
probabilityAll += Number(partition.probability)
|
|
33
|
-
})
|
|
34
|
-
return probabilityAll
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const getOptionsFromPartitions = (partitions: WheelOfFortunePartition[], lang: Lang): Option[] => {
|
|
38
|
-
const options = partitions.map(_partition => {
|
|
39
|
-
const option = {}
|
|
40
|
-
Object.keys(_partition).map((_key) => {
|
|
41
|
-
if(
|
|
42
|
-
typeof _partition[_key] === 'object' &&
|
|
43
|
-
(_partition[_key] as Object).hasOwnProperty('*')
|
|
44
|
-
){
|
|
45
|
-
const targetKey = _key === 'image1' ? 'image' : _key
|
|
46
|
-
option[targetKey] = _partition[_key][lang] || _partition[_key]['*']
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
return option as Option
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
if(getSumProbability(partitions) < 1){
|
|
54
|
-
options.push(optionCompliment)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return options
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const preloadImage = async (src: string) => {
|
|
61
|
-
if(!src) return {}
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
image: await imageLoaderSvg(src) as SVGImageElement
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const getOptions = async (bonus: LotteryProgramForPlayer, lang: Lang) => {
|
|
69
|
-
|
|
70
|
-
const { partitions } = bonus.program.wheelOfFortune
|
|
71
|
-
|
|
72
|
-
let options: Option[] = getOptionsFromPartitions(partitions, lang)
|
|
73
|
-
|
|
74
|
-
if(isSafari()){
|
|
75
|
-
options = options.map(option => {
|
|
76
|
-
if(option.image){
|
|
77
|
-
let img = document.createElementNS("http://www.w3.org/2000/svg", "image")
|
|
78
|
-
img.href.baseVal = option.image as string
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
...option,
|
|
82
|
-
image: img
|
|
83
|
-
}
|
|
84
|
-
}else{
|
|
85
|
-
return option
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
}else{
|
|
89
|
-
options = await Promise.all(
|
|
90
|
-
options.map(async o => ({
|
|
91
|
-
...o,
|
|
92
|
-
...(await preloadImage(o.image as string))
|
|
93
|
-
}))
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return options
|
|
98
|
-
}
|
package/src/business.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { findDeg } from './calc';
|
|
2
|
-
import { _postMessage } from './message';
|
|
3
|
-
import { Api, ApiConfigs, PointerMode } from './types';
|
|
4
|
-
import type { LotteryProgramForPlayer, ApiDrawResult, ApiLotteriesResult } from './types.business';
|
|
5
|
-
import { CurrentInfo } from './types.business';
|
|
6
|
-
import { fetcher } from './util';
|
|
7
|
-
import { _ } from './i18n';
|
|
8
|
-
|
|
9
|
-
export * from './business.partition'
|
|
10
|
-
import type { Option } from './business.partition'
|
|
11
|
-
|
|
12
|
-
const fetcherApi = async <T extends Api>(api: Api, endpoint: string, config: ApiConfigs[T]) => {
|
|
13
|
-
|
|
14
|
-
const { session } = config
|
|
15
|
-
|
|
16
|
-
const options = {
|
|
17
|
-
headers: {
|
|
18
|
-
'Content-Type': 'application/json',
|
|
19
|
-
'accept': 'text/plain',
|
|
20
|
-
|
|
21
|
-
...(session ? {'x-SessionId': session} : {})
|
|
22
|
-
},
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const getArgs = {
|
|
26
|
-
[Api.lotteries]: () => {
|
|
27
|
-
|
|
28
|
-
const { } = config || {} as ApiConfigs[Api.lotteries]
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
path: '/wof/lotteries',
|
|
32
|
-
params: {
|
|
33
|
-
},
|
|
34
|
-
options,
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
[Api.outcome]: () => {
|
|
38
|
-
|
|
39
|
-
const { id } = config as ApiConfigs[Api.outcome]
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
path: `/wof/outcome/${id}`,
|
|
43
|
-
params: {
|
|
44
|
-
},
|
|
45
|
-
options,
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
[Api.draw]: () => {
|
|
49
|
-
|
|
50
|
-
const { id, guid } = config as ApiConfigs[Api.draw]
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
path: `/wof/draw/${id}`,
|
|
54
|
-
params: {
|
|
55
|
-
},
|
|
56
|
-
options: {
|
|
57
|
-
...options,
|
|
58
|
-
method: 'PUT',
|
|
59
|
-
body: JSON.stringify({
|
|
60
|
-
guid
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const args = getArgs[api]()
|
|
68
|
-
|
|
69
|
-
args.path = endpoint + `/v1` + args.path
|
|
70
|
-
|
|
71
|
-
return await fetcher(args)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export const setMessage = (id: string, entry: string | object) => {
|
|
75
|
-
const _postMessageScoped = (props) => _postMessage({ ...props, id })
|
|
76
|
-
switch(typeof entry) {
|
|
77
|
-
case 'string':
|
|
78
|
-
_postMessageScoped({ type: 'wof-private-message-open', mode: 'normal', modeValue: entry })
|
|
79
|
-
break;
|
|
80
|
-
case 'object':
|
|
81
|
-
_postMessageScoped({ type: 'wof-private-message-open', ...(entry as object) })
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export const getCurrentInfo = (
|
|
87
|
-
lotteryProgramForPlayer: LotteryProgramForPlayer,
|
|
88
|
-
key: CurrentInfo
|
|
89
|
-
) => {
|
|
90
|
-
|
|
91
|
-
const { current } = lotteryProgramForPlayer
|
|
92
|
-
|
|
93
|
-
switch (key) {
|
|
94
|
-
case CurrentInfo.ActiveTickets:
|
|
95
|
-
return current.activeTickets
|
|
96
|
-
|
|
97
|
-
case CurrentInfo.ImplicitTickets:
|
|
98
|
-
const {
|
|
99
|
-
maxImplicitTickets: max,
|
|
100
|
-
usedImplicitTickets: used,
|
|
101
|
-
} = current
|
|
102
|
-
|
|
103
|
-
return `${max - used}/${max}`
|
|
104
|
-
|
|
105
|
-
case CurrentInfo.RemainingTimes:
|
|
106
|
-
return current.remainingTimes
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export const api = {
|
|
111
|
-
lotteries:
|
|
112
|
-
async (endpoint: string, session: string) => {
|
|
113
|
-
|
|
114
|
-
const data = await fetcherApi(Api.lotteries, endpoint, { session }) as ApiLotteriesResult
|
|
115
|
-
|
|
116
|
-
const lotteryProgramForPlayers = data.items as LotteryProgramForPlayer[] || []
|
|
117
|
-
|
|
118
|
-
return lotteryProgramForPlayers
|
|
119
|
-
},
|
|
120
|
-
draw:
|
|
121
|
-
async (endpoint: string, session: string, id: string, guid, options: Option[]) => {
|
|
122
|
-
|
|
123
|
-
let data = await fetcherApi(Api.draw, endpoint, { id, session, guid }) as ApiDrawResult
|
|
124
|
-
|
|
125
|
-
let index = data.item?.result?.wheelOfFortunePartitionIndex
|
|
126
|
-
|
|
127
|
-
const getOptionAndImageSrc = (_index: number) => {
|
|
128
|
-
const option = options[_index]
|
|
129
|
-
return {
|
|
130
|
-
option,
|
|
131
|
-
imageSrc: (option?.image as SVGAElement)?.href?.baseVal
|
|
132
|
-
} as const
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
let message: any
|
|
136
|
-
if(!index){
|
|
137
|
-
index = options.length - 1
|
|
138
|
-
|
|
139
|
-
const { imageSrc } = getOptionAndImageSrc(index)
|
|
140
|
-
message = {
|
|
141
|
-
mode: 'nogift',
|
|
142
|
-
modeValue: {
|
|
143
|
-
image: imageSrc
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}else{
|
|
147
|
-
const { imageSrc, option } = getOptionAndImageSrc(index)
|
|
148
|
-
message = {
|
|
149
|
-
mode: 'gift',
|
|
150
|
-
modeValue: {
|
|
151
|
-
prize: option.name || 'prize',
|
|
152
|
-
prizeText: option.prizeText,
|
|
153
|
-
prizeSrc: option.prizeImage || imageSrc
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return {
|
|
159
|
-
data,
|
|
160
|
-
message, index
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
|
|
164
|
-
outcome:
|
|
165
|
-
async (endpoint: string, session: string, id: string) => {
|
|
166
|
-
return await fetcherApi(Api.outcome, endpoint, { session, id })
|
|
167
|
-
},
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export const getSpinContainerSelector = (pointerMode: PointerMode) => {
|
|
171
|
-
switch(pointerMode){
|
|
172
|
-
case PointerMode.Arrow: return 'g.PartitionsContainer'
|
|
173
|
-
case PointerMode.Partition: return '.PointerArea > div'
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export const findDegWithPointerMode = (index: number, length: number, pointerMode: PointerMode) => {
|
|
178
|
-
switch(pointerMode){
|
|
179
|
-
case PointerMode.Arrow:
|
|
180
|
-
return findDeg(length - index, length) // + randomInSection(length)
|
|
181
|
-
case PointerMode.Partition:
|
|
182
|
-
return findDeg(index, length)
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export const isBonusInvalid = (bonus) => bonus?.current.remainingTimes == 0 && !bonus?.next
|
package/src/calc.point.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { Point } from "./types"
|
|
2
|
-
|
|
3
|
-
export const getSymmetricalPointFromScalar =
|
|
4
|
-
(length: number): Point => ({
|
|
5
|
-
x: length,
|
|
6
|
-
y: length
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
export const getPointOnCircle =
|
|
10
|
-
(radius: number, angle: number, center: number): Point => {
|
|
11
|
-
|
|
12
|
-
const centerPoint: Point = getSymmetricalPointFromScalar(center)
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
x: centerPoint.x + radius * Math.cos(angle),
|
|
16
|
-
y: centerPoint.y + radius * Math.sin(angle)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const getPoint =
|
|
21
|
-
(num: number, length: number, r: number, rCenter: number): Point => {
|
|
22
|
-
|
|
23
|
-
const arc = 360 / length;
|
|
24
|
-
const psai = Math.PI / 180 * (-90 + arc * (num - 1/2))
|
|
25
|
-
|
|
26
|
-
const rCenterPoint = getSymmetricalPointFromScalar(rCenter)
|
|
27
|
-
const rPoint = getSymmetricalPointFromScalar(r)
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
x: rCenterPoint.x + rPoint.x * Math.cos(psai),
|
|
31
|
-
y: rCenterPoint.y + rPoint.y * Math.sin(psai)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const getPointWithNext =
|
|
36
|
-
(num: number, length: number, r1: number, r2: number) => {
|
|
37
|
-
|
|
38
|
-
const getPointx = (num: number) => getPoint(num, length, r1, r2)
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
point: getPointx(num),
|
|
42
|
-
pointNext: getPointx(num + 1)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const getTrianglePointsY =
|
|
47
|
-
(height: number, isPointUp: boolean, yBase: number) => {
|
|
48
|
-
return {
|
|
49
|
-
y1: yBase,
|
|
50
|
-
y2: isPointUp ? yBase - height : yBase + height,
|
|
51
|
-
y3: yBase
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const getTwoPointsOfLineGradient = (radius, index, length, angle) => ({
|
|
56
|
-
x1: radius,
|
|
57
|
-
y1: radius,
|
|
58
|
-
x2: radius * (1 + Math.cos(2 * Math.PI / length * index + angle)),
|
|
59
|
-
y2: radius * (1 + Math.sin(2 * Math.PI / length * index + angle)),
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
export const pointPlus = (point1: Point, point2: Point): Point => ({
|
|
64
|
-
x: point1.x + point2.x,
|
|
65
|
-
y: point1.y + point2.y
|
|
66
|
-
})
|
|
67
|
-
|
package/src/calc.temp.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const byte2Hex = (n: number) => {
|
|
2
|
-
var nybHexString = "0123456789ABCDEF";
|
|
3
|
-
const query = (m: number) => nybHexString.substr(m & 0x0F, 1)
|
|
4
|
-
|
|
5
|
-
return String(query(n >> 4)) + query(n)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function getColor(item: number, maxitem: number) {
|
|
9
|
-
|
|
10
|
-
const colorCalc = (x: number) => {
|
|
11
|
-
|
|
12
|
-
const phase = 0;
|
|
13
|
-
const center = 128;
|
|
14
|
-
const width = 127;
|
|
15
|
-
|
|
16
|
-
const frequency = 2 * Math.PI / maxitem;
|
|
17
|
-
|
|
18
|
-
return Math.sin(frequency * item + x + phase) * width + center
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const hex = (x: number) => byte2Hex(colorCalc(x))
|
|
22
|
-
|
|
23
|
-
return [
|
|
24
|
-
'#',
|
|
25
|
-
hex(2),
|
|
26
|
-
hex(0),
|
|
27
|
-
hex(4),
|
|
28
|
-
].join('')
|
|
29
|
-
}
|
package/src/calc.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const convertDegToArc = (deg: number) => deg * Math.PI / 180
|
|
2
|
-
export const convertArcToDeg = (arc: number) => arc * 180 / Math.PI % 360
|
|
3
|
-
|
|
4
|
-
export const getArcDelta = (n: number) => 2 * Math.PI / n
|
|
5
|
-
|
|
6
|
-
export const findIndex = (deg: number, n: number) =>
|
|
7
|
-
Math.floor(
|
|
8
|
-
(360 - deg % 360) / convertArcToDeg(getArcDelta(n))
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
export const findDeg = (index: number, n: number) => {
|
|
12
|
-
const degDelta = convertArcToDeg(getArcDelta(n))
|
|
13
|
-
return (index) * degDelta
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const createSVGElement = (tag: string) => {
|
|
17
|
-
const xmlns = "http://www.w3.org/2000/svg";
|
|
18
|
-
return document.createElementNS(xmlns, tag);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const ratioGoldenMean = (times: number) => Math.pow(0.618, times)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const randomDirection = () => Math.random() > 0.5 ? 1 : -1
|
|
25
|
-
|
|
26
|
-
export const randomInSection = (number: number) => {
|
|
27
|
-
return 360 / number / 2 * (1 - 0.2) * Math.random() * randomDirection()
|
|
28
|
-
}
|
package/src/class.process.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { _postMessage } from "./message"
|
|
2
|
-
import { setMessage } from './business';
|
|
3
|
-
|
|
4
|
-
export class Process {
|
|
5
|
-
|
|
6
|
-
id: string
|
|
7
|
-
halter: Function
|
|
8
|
-
afterSuccess: Function
|
|
9
|
-
afterSetMessage: Function
|
|
10
|
-
fetcher: Function
|
|
11
|
-
|
|
12
|
-
private guid: string
|
|
13
|
-
private isDrawn: boolean = false
|
|
14
|
-
private drawnIndex: number;
|
|
15
|
-
private retryingTimes: number = 0
|
|
16
|
-
private retryingMaxTimes: number = 4
|
|
17
|
-
|
|
18
|
-
constructor(params){
|
|
19
|
-
this.id = params.id
|
|
20
|
-
this.afterSetMessage = params.afterSetMessage
|
|
21
|
-
this.halter = params.halter
|
|
22
|
-
this.afterSuccess = params.afterSuccess
|
|
23
|
-
this.fetcher = params.fetcher
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
handleHaltProcess(index, message, fn: Function = () => {}){
|
|
27
|
-
_postMessage({ id: this.id, type: 'wof-private-message-spin-before' })
|
|
28
|
-
|
|
29
|
-
const cb = () => {
|
|
30
|
-
setTimeout(() => {
|
|
31
|
-
_postMessage({ id: this.id, type: 'wof-private-message-spin-after' })
|
|
32
|
-
fn()
|
|
33
|
-
this.setMessage(message)
|
|
34
|
-
}, 1000)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// spinner.halt(calc.getDeg(index), cb)
|
|
38
|
-
this.halter(index, cb)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getRetryingPeriod() {
|
|
42
|
-
if(this.retryingTimes === 1){
|
|
43
|
-
return 5 * 1000
|
|
44
|
-
}else{
|
|
45
|
-
return 10 * 1000
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
drawInit() {
|
|
50
|
-
this.retryingTimes = 0
|
|
51
|
-
this.guid = undefined
|
|
52
|
-
this.isDrawn = false
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async drawer (guid?: string){
|
|
56
|
-
if(guid) this.guid = guid
|
|
57
|
-
if(!this.guid) throw new Error('GUID NOT FOUND')
|
|
58
|
-
|
|
59
|
-
if(this.retryingTimes >= this.retryingMaxTimes){
|
|
60
|
-
|
|
61
|
-
if(this.isDrawn){
|
|
62
|
-
this.handleHaltProcess(this.drawnIndex, 'DrawFailed')
|
|
63
|
-
}else{
|
|
64
|
-
this.handleHaltProcess(undefined, 'Timeout')
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
this.drawInit()
|
|
68
|
-
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
this.retryingTimes += 1
|
|
72
|
-
|
|
73
|
-
let isFetchCompleted = false
|
|
74
|
-
let isTimeouted = false
|
|
75
|
-
|
|
76
|
-
setTimeout(() => {
|
|
77
|
-
if(!isFetchCompleted){
|
|
78
|
-
isTimeouted = true
|
|
79
|
-
this.setMessage({
|
|
80
|
-
mode: 'timeout',
|
|
81
|
-
modeValue: 'Retry'
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
}, this.getRetryingPeriod())
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
|
|
88
|
-
const { data, message, index: _index } = await this.fetcher(this.guid)
|
|
89
|
-
this.drawnIndex = _index
|
|
90
|
-
|
|
91
|
-
isFetchCompleted = true
|
|
92
|
-
|
|
93
|
-
if(!data.success) throw new Error()
|
|
94
|
-
switch(data.item.state) {
|
|
95
|
-
case 'fulfilled':
|
|
96
|
-
this.isDrawn = true
|
|
97
|
-
break
|
|
98
|
-
case 'drawn':
|
|
99
|
-
this.isDrawn = true
|
|
100
|
-
throw new Error()
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if(isTimeouted) return;
|
|
104
|
-
|
|
105
|
-
this.handleHaltProcess(this.drawnIndex, message, this.afterSuccess)
|
|
106
|
-
this.drawInit()
|
|
107
|
-
|
|
108
|
-
} catch (e) {
|
|
109
|
-
if(e.message === "Failed to fetch"){
|
|
110
|
-
isFetchCompleted = true
|
|
111
|
-
this.handleHaltProcess(undefined, 'ErrorNetwork')
|
|
112
|
-
return
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if(e.message.includes("is not valid JSON")){
|
|
116
|
-
isFetchCompleted = true
|
|
117
|
-
this.handleHaltProcess(undefined, 'ErrorJSON')
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if(isTimeouted) return;
|
|
122
|
-
this.drawer()
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
setMessage(entry: string | object) {
|
|
127
|
-
setMessage(this.id, entry)
|
|
128
|
-
this.afterSetMessage()
|
|
129
|
-
}
|
|
130
|
-
}
|
package/src/class.spinable.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { convertDegToArc, easeOut } from "./class.spinable.util"
|
|
2
|
-
|
|
3
|
-
export abstract class Spinnable {
|
|
4
|
-
arcStart: number = 0
|
|
5
|
-
|
|
6
|
-
spinTime = 0
|
|
7
|
-
spinTimeTotal = Math.random() * 3 + 8 * 1000
|
|
8
|
-
spinAngleStart = 0
|
|
9
|
-
spinTimeout
|
|
10
|
-
public spinable: boolean = true
|
|
11
|
-
|
|
12
|
-
abstract tick(): void;
|
|
13
|
-
abstract beforeStart(deg: number): void;
|
|
14
|
-
abstract afterStop(): void;
|
|
15
|
-
|
|
16
|
-
public spin(deg, fn?){
|
|
17
|
-
this.spinAngleStart = deg
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if(!this.spinable) return;
|
|
21
|
-
|
|
22
|
-
this.spinable = false
|
|
23
|
-
this.spinTimeTotal = 1000
|
|
24
|
-
this.spinTime = 0;
|
|
25
|
-
this.spinTick(fn)
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private spinTick(fn) {
|
|
30
|
-
this.spinTime += 30
|
|
31
|
-
|
|
32
|
-
if(this.spinTime >= this.spinTimeTotal) {
|
|
33
|
-
this.stop(fn);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var spinAngle =
|
|
38
|
-
this.spinAngleStart -
|
|
39
|
-
easeOut(
|
|
40
|
-
this.spinTime,
|
|
41
|
-
0,
|
|
42
|
-
this.spinAngleStart,
|
|
43
|
-
this.spinTimeTotal
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this.arcStart += convertDegToArc(spinAngle);
|
|
48
|
-
|
|
49
|
-
this.tick()
|
|
50
|
-
this.spinTimeout = setTimeout(this.spinTick.bind(this, fn), 10);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
private stop (fn){
|
|
54
|
-
clearTimeout(this.spinTimeout);
|
|
55
|
-
|
|
56
|
-
this.afterStop()
|
|
57
|
-
this.spinable = true
|
|
58
|
-
if(fn) fn()
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export const convertDegToArc = (deg: number) => deg * Math.PI / 180
|
|
3
|
-
export const easeOut =
|
|
4
|
-
(time: number, b: number, angleStart: number, timeTotal: number) => {
|
|
5
|
-
var ts = (time /= timeTotal) * time;
|
|
6
|
-
var tc = ts * time;
|
|
7
|
-
const res = b + angleStart * (tc + -3 * ts + 3 * time);
|
|
8
|
-
|
|
9
|
-
return res
|
|
10
|
-
}
|