@crispcode/shimmer 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.esdoc.json +21 -0
- package/.eslintrc +143 -0
- package/LICENSE +21 -0
- package/README.md +35 -0
- package/manual/advanced-usage.md +180 -0
- package/manual/basic-usage.md +38 -0
- package/package.json +64 -0
- package/scripts/button.js +137 -0
- package/scripts/controls.js +95 -0
- package/scripts/element.js +154 -0
- package/scripts/index.js +28 -0
- package/scripts/shimmer.js +195 -0
- package/scripts/tween.js +147 -0
- package/test/app.html +30 -0
- package/test/app.js +4 -0
- package/test/modux.config.js +8 -0
- package/test/public/image1.png +0 -0
- package/test/public/image2.png +0 -0
- package/test/scripts/components/layout/index.js +9 -0
- package/test/scripts/components/layout/template.html +3 -0
- package/test/scripts/components/shimmer/buttonMain.js +27 -0
- package/test/scripts/components/shimmer/debug.js +42 -0
- package/test/scripts/components/shimmer/index.js +88 -0
- package/test/scripts/components/shimmer/moon.js +88 -0
- package/test/scripts/index.js +28 -0
- package/test/styles/index.scss +22 -0
package/.esdoc.json
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
"source": "./scripts",
|
3
|
+
"destination": "./docs",
|
4
|
+
"plugins": [
|
5
|
+
{
|
6
|
+
"name": "esdoc-standard-plugin",
|
7
|
+
"option": {
|
8
|
+
"coverage": { "enable": true },
|
9
|
+
"accessor": { "access": [ "public", "protected", "package" ], "autoPrivate": true },
|
10
|
+
"manual": {
|
11
|
+
"index": "./README.md",
|
12
|
+
"globalIndex": true,
|
13
|
+
"files": [
|
14
|
+
"./manual/basic-usage.md",
|
15
|
+
"./manual/advanced-usage.md"
|
16
|
+
]
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
]
|
21
|
+
}
|
package/.eslintrc
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
{
|
2
|
+
"parserOptions": {
|
3
|
+
"ecmaVersion": 8,
|
4
|
+
"ecmaFeatures": {
|
5
|
+
"experimentalObjectRestSpread": true,
|
6
|
+
"jsx": true
|
7
|
+
},
|
8
|
+
"sourceType": "module"
|
9
|
+
},
|
10
|
+
|
11
|
+
"env": {
|
12
|
+
"es6": true,
|
13
|
+
"node": true
|
14
|
+
},
|
15
|
+
|
16
|
+
"globals": {
|
17
|
+
},
|
18
|
+
|
19
|
+
"rules": {
|
20
|
+
"accessor-pairs": 2,
|
21
|
+
"array-bracket-spacing": [2, "always"],
|
22
|
+
"arrow-spacing": [2, { "before": true, "after": true }],
|
23
|
+
"block-spacing": [2, "always"],
|
24
|
+
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
|
25
|
+
"camelcase": [2, { "properties": "never" }],
|
26
|
+
"comma-dangle": [2, "never"],
|
27
|
+
"comma-spacing": [2, { "before": false, "after": true }],
|
28
|
+
"comma-style": [2, "last"],
|
29
|
+
"constructor-super": 2,
|
30
|
+
"curly": [2, "multi-line"],
|
31
|
+
"dot-location": [2, "property"],
|
32
|
+
"eol-last": 2,
|
33
|
+
"eqeqeq": [2, "allow-null"],
|
34
|
+
"func-call-spacing": [2, "never"],
|
35
|
+
"handle-callback-err": [2, "^(err|error)$" ],
|
36
|
+
"indent": [2, 2, { "SwitchCase": 1 }],
|
37
|
+
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
|
38
|
+
"keyword-spacing": [2, { "before": true, "after": true }],
|
39
|
+
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
|
40
|
+
"new-parens": 2,
|
41
|
+
"no-array-constructor": 2,
|
42
|
+
"no-caller": 2,
|
43
|
+
"no-class-assign": 2,
|
44
|
+
"no-cond-assign": 2,
|
45
|
+
"no-const-assign": 2,
|
46
|
+
"no-constant-condition": [2, { "checkLoops": false }],
|
47
|
+
"no-control-regex": 2,
|
48
|
+
"no-debugger": 2,
|
49
|
+
"no-delete-var": 2,
|
50
|
+
"no-dupe-args": 2,
|
51
|
+
"no-dupe-class-members": 2,
|
52
|
+
"no-dupe-keys": 2,
|
53
|
+
"no-duplicate-case": 2,
|
54
|
+
"no-duplicate-imports": 2,
|
55
|
+
"no-empty-character-class": 2,
|
56
|
+
"no-empty-pattern": 2,
|
57
|
+
"no-eval": 0,
|
58
|
+
"no-ex-assign": 2,
|
59
|
+
"no-extend-native": 2,
|
60
|
+
"no-extra-bind": 2,
|
61
|
+
"no-extra-boolean-cast": 2,
|
62
|
+
"no-extra-parens": [2, "functions"],
|
63
|
+
"no-fallthrough": 2,
|
64
|
+
"no-floating-decimal": 2,
|
65
|
+
"no-func-assign": 2,
|
66
|
+
"no-global-assign": 2,
|
67
|
+
"no-implied-eval": 2,
|
68
|
+
"no-inner-declarations": [2, "functions"],
|
69
|
+
"no-invalid-regexp": 2,
|
70
|
+
"no-irregular-whitespace": 2,
|
71
|
+
"no-iterator": 2,
|
72
|
+
"no-label-var": 2,
|
73
|
+
"no-labels": [2, { "allowLoop": false, "allowSwitch": false }],
|
74
|
+
"no-lone-blocks": 2,
|
75
|
+
"no-mixed-spaces-and-tabs": 2,
|
76
|
+
"no-multi-spaces": 2,
|
77
|
+
"no-multi-str": 0,
|
78
|
+
"no-multiple-empty-lines": [2, { "max": 1 }],
|
79
|
+
"no-native-reassign": 2,
|
80
|
+
"no-negated-in-lhs": 2,
|
81
|
+
"no-new": 2,
|
82
|
+
"no-new-func": 2,
|
83
|
+
"no-new-object": 2,
|
84
|
+
"no-new-require": 2,
|
85
|
+
"no-new-symbol": 2,
|
86
|
+
"no-new-wrappers": 2,
|
87
|
+
"no-obj-calls": 2,
|
88
|
+
"no-octal": 2,
|
89
|
+
"no-octal-escape": 2,
|
90
|
+
"no-proto": 2,
|
91
|
+
"no-redeclare": 2,
|
92
|
+
"no-regex-spaces": 2,
|
93
|
+
"no-return-assign": [2, "except-parens"],
|
94
|
+
"no-self-assign": 2,
|
95
|
+
"no-self-compare": 2,
|
96
|
+
"no-sequences": 2,
|
97
|
+
"no-shadow-restricted-names": 2,
|
98
|
+
"no-sparse-arrays": 2,
|
99
|
+
"no-tabs": 2,
|
100
|
+
"no-template-curly-in-string": 2,
|
101
|
+
"no-this-before-super": 2,
|
102
|
+
"no-throw-literal": 2,
|
103
|
+
"no-trailing-spaces": 2,
|
104
|
+
"no-undef": 2,
|
105
|
+
"no-undef-init": 2,
|
106
|
+
"no-unexpected-multiline": 2,
|
107
|
+
"no-unmodified-loop-condition": 2,
|
108
|
+
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
|
109
|
+
"no-unreachable": 2,
|
110
|
+
"no-unsafe-finally": 2,
|
111
|
+
"no-unsafe-negation": 2,
|
112
|
+
"no-unused-vars": [1, { "vars": "all", "args": "after-used" }],
|
113
|
+
"no-useless-call": 2,
|
114
|
+
"no-useless-computed-key": 2,
|
115
|
+
"no-useless-constructor": 2,
|
116
|
+
"no-useless-escape": 2,
|
117
|
+
"no-useless-rename": 2,
|
118
|
+
"no-whitespace-before-property": 2,
|
119
|
+
"no-with": 2,
|
120
|
+
"object-property-newline": [2, { "allowMultiplePropertiesPerLine": true }],
|
121
|
+
"object-curly-spacing": [2, "always"],
|
122
|
+
"one-var": [2, { "initialized": "never" }],
|
123
|
+
"operator-linebreak": [2, "after", { "overrides": { "?": "before", ":": "before" } }],
|
124
|
+
"padded-blocks": [2, "never"],
|
125
|
+
"quotes": [2, "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
|
126
|
+
"rest-spread-spacing": [2, "never"],
|
127
|
+
"semi": [2, "never"],
|
128
|
+
"semi-spacing": [2, { "before": false, "after": true }],
|
129
|
+
"space-before-blocks": [2, "always"],
|
130
|
+
"space-before-function-paren": [2, "always"],
|
131
|
+
"space-in-parens": [2, "always"],
|
132
|
+
"space-infix-ops": 2,
|
133
|
+
"space-unary-ops": [2, { "words": true, "nonwords": false }],
|
134
|
+
"spaced-comment": [2, "always", { "line": { "markers": ["*package", "!", ","] }, "block": { "balanced": true, "markers": ["*package", "!", ","], "exceptions": ["*"] } }],
|
135
|
+
"template-curly-spacing": [2, "never"],
|
136
|
+
"unicode-bom": [2, "never"],
|
137
|
+
"use-isnan": 2,
|
138
|
+
"valid-typeof": 2,
|
139
|
+
"wrap-iife": [2, "any"],
|
140
|
+
"yield-star-spacing": [2, "both"],
|
141
|
+
"yoda": [2, "never"]
|
142
|
+
}
|
143
|
+
}
|
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 CrispCode
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# shimmer
|
2
|
+
A PIXI.JS wrapper plugin for MODUX
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
```
|
7
|
+
npm install @CrispCode/shimmer
|
8
|
+
```
|
9
|
+
|
10
|
+
## Documentation & Testing
|
11
|
+
|
12
|
+
Clone the shimmer repository to your machine and use the following commands:
|
13
|
+
|
14
|
+
To generate a documentation use `npm run docs`
|
15
|
+
If you want to check functionality you can use `npm run test`
|
16
|
+
|
17
|
+
## Polyfill
|
18
|
+
|
19
|
+
In order to support older versions of browsers, you can use [polyfill.io](https://polyfill.io)
|
20
|
+
|
21
|
+
## Shimmer classes
|
22
|
+
|
23
|
+
|Name|Usage|Description|
|
24
|
+
|:---:|---|---|
|
25
|
+
| Button | `import { Button } from 'shimmer'` | The Button class is an extension of the standard Element class |
|
26
|
+
| Element | `import { Element } from 'shimmer'` | The base class for all Shimmer objects |
|
27
|
+
| Shimmer | `import { Shimmer } from 'shimmer'` | The Shimmer component class, check Modux/Component for more information |
|
28
|
+
| Tween | `import { Tween } from 'shimmer'` | A class used to create animation tweens in Element or Shimmer |
|
29
|
+
| Sprite | `import { Sprite } from 'shimmer'` | PIXI.JS Sprite class |
|
30
|
+
| AnimatedSprite | `import { AnimatedSprite } from 'shimmer'` | PIXI.JS AnimatedSprite class |
|
31
|
+
| Text | `import { Text } from 'shimmer'` | PIXI.JS Text class |
|
32
|
+
| Graphics | `import { Graphics } from 'shimmer'` | PIXI.JS Graphics class |
|
33
|
+
| Texture | `import { Texture } from 'shimmer'` | PIXI.JS Texture class |
|
34
|
+
| BaseTexture | `import { BaseTexture } from 'shimmer'` | PIXI.JS BaseTexture class |
|
35
|
+
|
@@ -0,0 +1,180 @@
|
|
1
|
+
# Advanced usage
|
2
|
+
|
3
|
+
## buttonMain.js
|
4
|
+
```
|
5
|
+
'use strict'
|
6
|
+
|
7
|
+
import { Button } from 'shimmer'
|
8
|
+
import { Sprite } from 'shimmer'
|
9
|
+
|
10
|
+
export class ButtonMain extends Button {
|
11
|
+
constructor () {
|
12
|
+
super()
|
13
|
+
|
14
|
+
let image = Sprite.fromImage( '/image1.png' )
|
15
|
+
|
16
|
+
image.anchor.x = 0.5
|
17
|
+
image.anchor.y = 0.5
|
18
|
+
|
19
|
+
this.addElementChild( 'image', image )
|
20
|
+
|
21
|
+
this.onMouseOver( () => {
|
22
|
+
this.createTween( 10, 12, 1, ( value ) => {
|
23
|
+
image.scale.x = value / 10
|
24
|
+
image.scale.y = value / 10
|
25
|
+
} )
|
26
|
+
} )
|
27
|
+
|
28
|
+
this.onMouseOut( () => {
|
29
|
+
this.createTween( 10, 12, 1, ( value ) => {
|
30
|
+
image.scale.x = ( 22 - value ) / 10
|
31
|
+
image.scale.y = ( 22 - value ) / 10
|
32
|
+
} )
|
33
|
+
} )
|
34
|
+
}
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
### moon.js
|
39
|
+
```
|
40
|
+
'use strict'
|
41
|
+
|
42
|
+
import { radians } from 'modux'
|
43
|
+
|
44
|
+
import { Element } from 'shimmer'
|
45
|
+
import { Sprite } from 'shimmer'
|
46
|
+
|
47
|
+
export class Moon extends Element {
|
48
|
+
constructor () {
|
49
|
+
super()
|
50
|
+
|
51
|
+
let image = Sprite.fromImage( '/image2.png' )
|
52
|
+
|
53
|
+
image.anchor.x = 0.5
|
54
|
+
image.anchor.y = 0.5
|
55
|
+
|
56
|
+
this.alpha = 0
|
57
|
+
|
58
|
+
this.__angle = 0
|
59
|
+
this.__radius = 0
|
60
|
+
this.__speed = 1
|
61
|
+
this.__centerX = 0
|
62
|
+
this.__centerY = 0
|
63
|
+
|
64
|
+
this.__rotating = false
|
65
|
+
|
66
|
+
this.addElementChild( 'image', image )
|
67
|
+
}
|
68
|
+
|
69
|
+
__move () {
|
70
|
+
this.x = this.__centerX + this.__radius * Math.cos( radians( this.__angle ) )
|
71
|
+
this.y = this.__centerY + this.__radius * Math.sin( radians( this.__angle ) )
|
72
|
+
}
|
73
|
+
|
74
|
+
setCenter ( x, y ) {
|
75
|
+
this.__centerX = x
|
76
|
+
this.__centerY = y
|
77
|
+
this.__move()
|
78
|
+
}
|
79
|
+
setAngle ( angle ) {
|
80
|
+
this.__angle = angle
|
81
|
+
this.__move()
|
82
|
+
}
|
83
|
+
setRadius ( radius ) {
|
84
|
+
this.__radius = radius
|
85
|
+
this.__move()
|
86
|
+
}
|
87
|
+
setSpeed ( speed ) {
|
88
|
+
this.__speed = speed
|
89
|
+
}
|
90
|
+
|
91
|
+
start () {
|
92
|
+
this.__rotating = true
|
93
|
+
}
|
94
|
+
|
95
|
+
stop () {
|
96
|
+
this.__rotating = false
|
97
|
+
}
|
98
|
+
|
99
|
+
tick ( delta ) {
|
100
|
+
if ( this.__rotating ) {
|
101
|
+
this.__angle = this.__angle + this.__speed * delta
|
102
|
+
if ( this.__angle === 360 ) {
|
103
|
+
this.__angle = 0
|
104
|
+
}
|
105
|
+
this.__move()
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
```
|
110
|
+
|
111
|
+
## Shimmer Component
|
112
|
+
```
|
113
|
+
'use strict'
|
114
|
+
|
115
|
+
import { rnd, loop } from 'modux'
|
116
|
+
|
117
|
+
import { Shimmer } from 'shimmer'
|
118
|
+
|
119
|
+
import { ButtonMain } from './buttonMain.js'
|
120
|
+
import { Moon } from './moon.js'
|
121
|
+
|
122
|
+
export class ShimmerComponent extends Shimmer {
|
123
|
+
onResize ( width, height ) {
|
124
|
+
super.onResize( width, height )
|
125
|
+
this.__button.x = this.renderer.width / this.renderer.resolution / 2
|
126
|
+
this.__button.y = this.renderer.height / this.renderer.resolution / 2
|
127
|
+
|
128
|
+
loop( this.__moons, ( moon ) => {
|
129
|
+
moon.setCenter( this.__button.x, this.__button.y )
|
130
|
+
moon.show()
|
131
|
+
} )
|
132
|
+
}
|
133
|
+
|
134
|
+
get settings() {
|
135
|
+
return {
|
136
|
+
backgroundAlpha: 1,
|
137
|
+
backgroundColor: 0xFFFF00,
|
138
|
+
forceCanvas: false
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
execute () {
|
143
|
+
this.ticker.start()
|
144
|
+
|
145
|
+
this.__button = new ButtonMain()
|
146
|
+
this.stage.addElementChild( 'button', this.__button )
|
147
|
+
|
148
|
+
this.__moons = {}
|
149
|
+
|
150
|
+
for ( let i = 0; i < 10; i++ ) {
|
151
|
+
let moon = new Moon()
|
152
|
+
moon.setAngle( rnd( 0, 359 ) )
|
153
|
+
moon.setRadius( rnd( 200, 500 ) )
|
154
|
+
moon.setSpeed( rnd( 10, 50 ) / 10 )
|
155
|
+
moon.setCenter( this.__button.x, this.__button.y )
|
156
|
+
|
157
|
+
this.stage.addElementChild( 'moon' + i, moon )
|
158
|
+
|
159
|
+
this.__moons[ i ] = moon
|
160
|
+
}
|
161
|
+
|
162
|
+
this.__button.onMouseDown( () => {
|
163
|
+
loop( this.__moons, ( moon ) => {
|
164
|
+
moon.start()
|
165
|
+
} )
|
166
|
+
} )
|
167
|
+
|
168
|
+
this.__button.onMouseUp( () => {
|
169
|
+
loop( this.__moons, ( moon ) => {
|
170
|
+
moon.stop()
|
171
|
+
} )
|
172
|
+
} )
|
173
|
+
this.__button.onMouseUpOutside( () => {
|
174
|
+
loop( this.__moons, ( moon ) => {
|
175
|
+
moon.stop()
|
176
|
+
} )
|
177
|
+
} )
|
178
|
+
}
|
179
|
+
}
|
180
|
+
```
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Basic Usage
|
2
|
+
|
3
|
+
## Moon library
|
4
|
+
```
|
5
|
+
'use strict'
|
6
|
+
|
7
|
+
import { Element } from 'shimmer'
|
8
|
+
import { Sprite } from 'shimmer'
|
9
|
+
|
10
|
+
export class Moon extends Element {
|
11
|
+
constructor () {
|
12
|
+
super()
|
13
|
+
|
14
|
+
let image = Sprite.fromImage( '/image2.png' )
|
15
|
+
this.addElementChild( 'image', image )
|
16
|
+
}
|
17
|
+
}
|
18
|
+
```
|
19
|
+
|
20
|
+
## Shimmer component
|
21
|
+
```
|
22
|
+
'use strict'
|
23
|
+
|
24
|
+
import { Shimmer } from 'shimmer'
|
25
|
+
|
26
|
+
import { Moon } from './moon.js'
|
27
|
+
|
28
|
+
export class ShimmerComponent extends Shimmer {
|
29
|
+
|
30
|
+
execute () {
|
31
|
+
this.ticker.start()
|
32
|
+
|
33
|
+
let moon = new Moon()
|
34
|
+
this.stage.addElementChild( 'moon', moon )
|
35
|
+
}
|
36
|
+
|
37
|
+
}
|
38
|
+
```
|
package/package.json
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
{
|
2
|
+
"name": "@crispcode/shimmer",
|
3
|
+
"version": "5.0.0",
|
4
|
+
"description": "A PIXI.JS wrapper plugin for MODUX",
|
5
|
+
"author": "Crisp Code ( contact@crispcode.ro )",
|
6
|
+
"access": "public",
|
7
|
+
"engines": {
|
8
|
+
"node": ">=16.15.0",
|
9
|
+
"npm": ">=8.5.5"
|
10
|
+
},
|
11
|
+
"license": "SEE LICENSE IN LICENSE",
|
12
|
+
"repository": {
|
13
|
+
"type": "git",
|
14
|
+
"url": "https://github.com/CrispCode/shimmer.git"
|
15
|
+
},
|
16
|
+
"bugs": {
|
17
|
+
"url": "https://github.com/CrispCode/shimmer/issues"
|
18
|
+
},
|
19
|
+
"dependencies": {
|
20
|
+
"@pixi/canvas-display": "^6.4.0",
|
21
|
+
"@pixi/canvas-extract": "^6.4.0",
|
22
|
+
"@pixi/canvas-graphics": "^6.4.0",
|
23
|
+
"@pixi/canvas-mesh": "^6.4.0",
|
24
|
+
"@pixi/canvas-particle-container": "^6.4.0",
|
25
|
+
"@pixi/canvas-prepare": "^6.4.0",
|
26
|
+
"@pixi/canvas-renderer": "^6.4.0",
|
27
|
+
"@pixi/canvas-sprite": "^6.4.0",
|
28
|
+
"@pixi/canvas-sprite-tiling": "^6.4.0",
|
29
|
+
"@pixi/canvas-text": "^6.4.0",
|
30
|
+
"@pixi/constants": "^6.4.0",
|
31
|
+
"@pixi/core": "^6.4.0",
|
32
|
+
"@pixi/display": "^6.4.0",
|
33
|
+
"@pixi/graphics": "^6.4.0",
|
34
|
+
"@pixi/interaction": "^6.4.0",
|
35
|
+
"@pixi/loaders": "^6.4.0",
|
36
|
+
"@pixi/math": "^6.4.0",
|
37
|
+
"@pixi/mesh": "^6.4.0",
|
38
|
+
"@pixi/mesh-extras": "^6.4.0",
|
39
|
+
"@pixi/particle-container": "^6.4.0",
|
40
|
+
"@pixi/prepare": "^6.4.0",
|
41
|
+
"@pixi/runner": "^6.4.0",
|
42
|
+
"@pixi/settings": "^6.4.0",
|
43
|
+
"@pixi/sprite": "^6.4.0",
|
44
|
+
"@pixi/sprite-animated": "^6.4.0",
|
45
|
+
"@pixi/sprite-tiling": "^6.4.0",
|
46
|
+
"@pixi/text": "^6.4.0",
|
47
|
+
"@pixi/ticker": "^6.4.0",
|
48
|
+
"@pixi/utils": "^6.4.0",
|
49
|
+
"acorn": "^8.7.1"
|
50
|
+
},
|
51
|
+
"peerDependencies": {
|
52
|
+
"@crispcode/modux": "CrispCode/modux#v5.0.4"
|
53
|
+
},
|
54
|
+
"devDependencies": {
|
55
|
+
"esdoc": "^1.1.0",
|
56
|
+
"esdoc-standard-plugin": "^1.0.0"
|
57
|
+
},
|
58
|
+
"main": "./scripts/index.js",
|
59
|
+
"scripts": {
|
60
|
+
"test": "cd test && node ./../node_modules/.bin/modux start ",
|
61
|
+
"nowebgl": "open -a \"Google Chrome\" --args -disable-webgl",
|
62
|
+
"docs": "rm -rf ./docs && ./node_modules/.bin/esdoc && open ./docs/index.html"
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,137 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
import { loop, uid } from '@crispcode/modux'
|
4
|
+
|
5
|
+
import { Element } from './element.js'
|
6
|
+
|
7
|
+
/**
|
8
|
+
* This class is used to create buttons for shimmer
|
9
|
+
*/
|
10
|
+
export class Button extends Element {
|
11
|
+
/**
|
12
|
+
* Creates an instance of Button
|
13
|
+
*/
|
14
|
+
constructor () {
|
15
|
+
super()
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Marks the Button as interactive
|
19
|
+
* @type {Boolean}
|
20
|
+
*/
|
21
|
+
this.interactive = true
|
22
|
+
/**
|
23
|
+
* Marks the Button as a button
|
24
|
+
* @type {Boolean}
|
25
|
+
*/
|
26
|
+
this.buttonMode = true
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Holds all event listeners
|
30
|
+
* @type {Object}
|
31
|
+
* @private
|
32
|
+
*/
|
33
|
+
this.__handlers = {}
|
34
|
+
/**
|
35
|
+
* Enables or disables the button interactivity
|
36
|
+
* @type {Boolean}
|
37
|
+
* @private
|
38
|
+
*/
|
39
|
+
this.__enabled = true
|
40
|
+
|
41
|
+
/**
|
42
|
+
* This function calls all event listeners for a specific eventname
|
43
|
+
* @param {String} eventname The event name
|
44
|
+
* @private
|
45
|
+
*/
|
46
|
+
const __triggerEventHandlers = ( eventname ) => {
|
47
|
+
return ( ev ) => {
|
48
|
+
if ( this.__enabled ) {
|
49
|
+
loop( this.__handlers[ eventname ], ( handler ) => {
|
50
|
+
handler( ev )
|
51
|
+
} )
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
this
|
57
|
+
// Mouse & touch events are normalized into
|
58
|
+
// the pointer* events for handling different
|
59
|
+
// button events.
|
60
|
+
.on( 'pointerdown', __triggerEventHandlers( 'pointerdown' ) )
|
61
|
+
.on( 'pointerup', __triggerEventHandlers( 'pointerup' ) )
|
62
|
+
.on( 'pointerupoutside', __triggerEventHandlers( 'pointerupoutside' ) )
|
63
|
+
.on( 'pointerover', __triggerEventHandlers( 'pointerover' ) )
|
64
|
+
.on( 'pointerout', __triggerEventHandlers( 'pointerout' ) )
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Adds an event listener to the Button
|
69
|
+
* @param {String} eventname The event name
|
70
|
+
* @param {Function} handler The event handler
|
71
|
+
* @return {Function} A function which can be called to unregister the event handler
|
72
|
+
*/
|
73
|
+
__addEventHandler ( eventname, handler ) {
|
74
|
+
this.__handlers[ eventname ] = this.__handlers[ eventname ] || {}
|
75
|
+
let id = uid()
|
76
|
+
this.__handlers[ eventname ][ id ] = handler
|
77
|
+
return () => {
|
78
|
+
delete this.__handlers[ eventname ][ id ]
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Enables or disables the button interactivity
|
84
|
+
* @param {Boolean} enabled If true, button is enabled, otherwise its disabled
|
85
|
+
*/
|
86
|
+
enable ( enabled ) {
|
87
|
+
this.__enabled = !!enabled
|
88
|
+
if ( enabled ) {
|
89
|
+
this.interactive = true
|
90
|
+
this.buttonMode = true
|
91
|
+
} else {
|
92
|
+
this.interactive = false
|
93
|
+
this.buttonMode = false
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Adds an event listener for the Mouse Over event
|
99
|
+
* @param {Function} handler The event listener
|
100
|
+
* @return {Function} A function which can be called to unregister the event handler
|
101
|
+
*/
|
102
|
+
onMouseOver ( handler ) {
|
103
|
+
return this.__addEventHandler( 'pointerover', handler )
|
104
|
+
}
|
105
|
+
/**
|
106
|
+
* Adds an event listener for the Mouse Out event
|
107
|
+
* @param {Function} handler The event listener
|
108
|
+
* @return {Function} A function which can be called to unregister the event handler
|
109
|
+
*/
|
110
|
+
onMouseOut ( handler ) {
|
111
|
+
return this.__addEventHandler( 'pointerout', handler )
|
112
|
+
}
|
113
|
+
/**
|
114
|
+
* Adds an event listener for the Mouse Down event
|
115
|
+
* @param {Function} handler The event listener
|
116
|
+
* @return {Function} A function which can be called to unregister the event handler
|
117
|
+
*/
|
118
|
+
onMouseDown ( handler ) {
|
119
|
+
return this.__addEventHandler( 'pointerdown', handler )
|
120
|
+
}
|
121
|
+
/**
|
122
|
+
* Adds an event listener for the Mouse Up event
|
123
|
+
* @param {Function} handler The event listener
|
124
|
+
* @return {Function} A function which can be called to unregister the event handler
|
125
|
+
*/
|
126
|
+
onMouseUp ( handler ) {
|
127
|
+
return this.__addEventHandler( 'pointerup', handler )
|
128
|
+
}
|
129
|
+
/**
|
130
|
+
* Adds an event listener for the Mouse Up Outside event
|
131
|
+
* @param {Function} handler The event listener
|
132
|
+
* @return {Function} A function which can be called to unregister the event handler
|
133
|
+
*/
|
134
|
+
onMouseUpOutside ( handler ) {
|
135
|
+
return this.__addEventHandler( 'pointerupoutside', handler )
|
136
|
+
}
|
137
|
+
}
|