@pb33f/cowboy-components 0.6.5 → 0.6.7

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.
@@ -1,10 +1,12 @@
1
1
  import { LitElement } from "lit";
2
2
  import { SlDialog } from "@shoelace-style/shoelace";
3
+ import { OAuthLogin } from "./oauth-login";
3
4
  export declare class LoginButton extends LitElement {
4
5
  static styles: import("lit").CSSResult[];
5
6
  authDialog: SlDialog;
6
7
  title: string;
7
8
  buttonLabel: string;
9
+ oauthLogin: OAuthLogin;
8
10
  private controller;
9
11
  constructor();
10
12
  render(): import("lit-html").TemplateResult<1>;
@@ -42,6 +42,8 @@ let LoginButton = class LoginButton extends LitElement {
42
42
  }
43
43
  hide() {
44
44
  this.authDialog.hide();
45
+ this.oauthLogin.animateBox = false;
46
+ this.oauthLogin.requestUpdate();
45
47
  }
46
48
  authenticatedView() {
47
49
  return html `
@@ -68,6 +70,8 @@ let LoginButton = class LoginButton extends LitElement {
68
70
  }));
69
71
  }
70
72
  openAuthModal() {
73
+ this.oauthLogin.animateBox = true;
74
+ this.oauthLogin.requestUpdate();
71
75
  this.authDialog.show();
72
76
  }
73
77
  };
@@ -81,6 +85,9 @@ __decorate([
81
85
  __decorate([
82
86
  property()
83
87
  ], LoginButton.prototype, "buttonLabel", void 0);
88
+ __decorate([
89
+ query('pb33f-oauth-login')
90
+ ], LoginButton.prototype, "oauthLogin", void 0);
84
91
  LoginButton = __decorate([
85
92
  customElement('pb33f-login-button')
86
93
  ], LoginButton);
@@ -1,6 +1,7 @@
1
1
  import { LitElement } from "lit";
2
2
  import '../electric-box/electric-box.js';
3
3
  import { SlAnimation, SlButton } from "@shoelace-style/shoelace";
4
+ import { ElectricBox } from "../electric-box/electric-box";
4
5
  export declare class OAuthLogin extends LitElement {
5
6
  static styles: import("lit").CSSResult[];
6
7
  title: string;
@@ -9,8 +10,10 @@ export declare class OAuthLogin extends LitElement {
9
10
  maxtravel: number;
10
11
  spin: number;
11
12
  orbs: boolean;
13
+ animateBox: boolean;
12
14
  buttonAnimation: SlAnimation;
13
15
  githubButton: SlButton;
16
+ electricBox: ElectricBox;
14
17
  constructor();
15
18
  githubLogin(): void;
16
19
  render(): import("lit-html").TemplateResult<1>;
@@ -19,6 +19,7 @@ let OAuthLogin = class OAuthLogin extends LitElement {
19
19
  this.maxtravel = 6500;
20
20
  this.spin = 20;
21
21
  this.orbs = true;
22
+ this.animateBox = false;
22
23
  }
23
24
  githubLogin() {
24
25
  this.mintravel = 1000;
@@ -38,7 +39,8 @@ let OAuthLogin = class OAuthLogin extends LitElement {
38
39
  render() {
39
40
  return html `
40
41
  <div style="width: 500px; height: 280px; margin: 0 auto;">
41
- <pb33f-electric-box .orbs="${this.orbs}"
42
+ <pb33f-electric-box .orbs="${this.orbs}"
43
+ ?disable=${!this.animateBox}
42
44
  spin spinamount="${this.spin}"
43
45
  mintraveltime="${this.mintravel}"
44
46
  maxtraveltime="${this.maxtravel}"
@@ -81,12 +83,18 @@ __decorate([
81
83
  __decorate([
82
84
  state()
83
85
  ], OAuthLogin.prototype, "orbs", void 0);
86
+ __decorate([
87
+ state()
88
+ ], OAuthLogin.prototype, "animateBox", void 0);
84
89
  __decorate([
85
90
  query('#button-anim')
86
91
  ], OAuthLogin.prototype, "buttonAnimation", void 0);
87
92
  __decorate([
88
93
  query('#github-button')
89
94
  ], OAuthLogin.prototype, "githubButton", void 0);
95
+ __decorate([
96
+ query('pb33f-electric-box')
97
+ ], OAuthLogin.prototype, "electricBox", void 0);
90
98
  OAuthLogin = __decorate([
91
99
  customElement("pb33f-oauth-login")
92
100
  ], OAuthLogin);
@@ -10,6 +10,7 @@ export declare class ElectricBox extends LitElement {
10
10
  maxtraveltime: number;
11
11
  height: number;
12
12
  heroView: boolean;
13
+ disable: boolean;
13
14
  color: string;
14
15
  private container;
15
16
  private orbPath;
@@ -24,6 +25,9 @@ export declare class ElectricBox extends LitElement {
24
25
  constructor();
25
26
  render(): TemplateResult;
26
27
  protected firstUpdated(): void;
28
+ protected updated(): void;
29
+ runAnimation(): void;
30
+ stopAnimation(): void;
27
31
  protected willUpdate(): void;
28
32
  disconnectedCallback(): void;
29
33
  private getRandomBorderPosition;
@@ -23,6 +23,7 @@ let ElectricBox = class ElectricBox extends LitElement {
23
23
  this.maxtraveltime = 4000;
24
24
  this.heroView = false;
25
25
  this.height = 500;
26
+ this.disable = false;
26
27
  }
27
28
  render() {
28
29
  return html `
@@ -91,31 +92,50 @@ let ElectricBox = class ElectricBox extends LitElement {
91
92
  this.orbGroup = this.container.select("#orb-group");
92
93
  this.orb = this.container.select("#orb-circle");
93
94
  this.orb.attr({ display: "none" });
94
- if (this.orbs) {
95
- this.orbTimer = setInterval(() => {
96
- this.spawnOrb();
97
- }, 500);
95
+ }
96
+ updated() {
97
+ if (this.disable) {
98
+ this.stopAnimation();
99
+ }
100
+ else {
101
+ this.runAnimation();
98
102
  }
99
- this.pixelSpawnTimer = setInterval(() => {
100
- if (this.activePixelCount < this.pixelConfig.maxActivePixels) {
101
- this.spawnPixel();
102
- }
103
- }, this.pixelConfig.spawnIntervalMs);
104
103
  }
105
- willUpdate() {
106
- if (this.orbTimer && !this.orbs) {
107
- clearInterval(this.orbTimer);
104
+ runAnimation() {
105
+ // Ensure timers have not already been started.
106
+ if (!this.pixelSpawnTimer && !this.disable) {
107
+ if (this.orbs) {
108
+ this.orbTimer = setInterval(() => {
109
+ this.spawnOrb();
110
+ }, 500);
111
+ }
112
+ this.pixelSpawnTimer = setInterval(() => {
113
+ if (this.activePixelCount < this.pixelConfig.maxActivePixels) {
114
+ this.spawnPixel();
115
+ }
116
+ }, this.pixelConfig.spawnIntervalMs);
108
117
  }
109
118
  }
110
- disconnectedCallback() {
111
- super.disconnectedCallback();
119
+ stopAnimation() {
120
+ // Clear the animation timers if they exist.
112
121
  if (this.pixelSpawnTimer) {
113
122
  clearInterval(this.pixelSpawnTimer);
123
+ this.pixelSpawnTimer = null;
114
124
  }
115
125
  if (this.orbTimer) {
116
126
  clearInterval(this.orbTimer);
127
+ this.orbTimer = null;
128
+ }
129
+ }
130
+ willUpdate() {
131
+ if (this.orbTimer && !this.orbs) {
132
+ clearInterval(this.orbTimer);
117
133
  }
118
134
  }
135
+ disconnectedCallback() {
136
+ super.disconnectedCallback();
137
+ this.stopAnimation();
138
+ }
119
139
  getRandomBorderPosition() {
120
140
  // If heroView is true, only spawn pixels on the top (edge 0) or bottom (edge 1)
121
141
  if (this.heroView) {
@@ -327,6 +347,9 @@ __decorate([
327
347
  __decorate([
328
348
  property({ type: Boolean })
329
349
  ], ElectricBox.prototype, "heroView", void 0);
350
+ __decorate([
351
+ property({ type: Boolean, attribute: 'disable' })
352
+ ], ElectricBox.prototype, "disable", void 0);
330
353
  __decorate([
331
354
  property()
332
355
  ], ElectricBox.prototype, "color", void 0);
@@ -21,7 +21,7 @@ export default css `
21
21
  }
22
22
 
23
23
  .no-values {
24
- //min-height: 550px;
24
+ height: 600px;
25
25
  width: 500px;
26
26
  margin: 0 auto;
27
27
  padding-top: 50px;
@@ -9,6 +9,7 @@ export declare class Paginator extends LitElement {
9
9
  label: string;
10
10
  activeIndex: number;
11
11
  invalid: boolean;
12
+ hideSparks: boolean;
12
13
  private renderValues;
13
14
  private sparks;
14
15
  private paginatorNavigator;
@@ -20,6 +20,7 @@ let Paginator = class Paginator extends LitElement {
20
20
  this.itemsPerPage = 20;
21
21
  this.activeIndex = 0;
22
22
  this.invalid = false;
23
+ this.hideSparks = false;
23
24
  this.paginatorNavigator = new PaginatorNavigation();
24
25
  this.paginatorNavigator.currentPage = this.currentPage;
25
26
  this.paginatorNavigator.totalPages = this.totalPages;
@@ -84,14 +85,29 @@ let Paginator = class Paginator extends LitElement {
84
85
  }
85
86
  render() {
86
87
  this.sparks.isError = this.invalid;
88
+ if (this.sparks.animating) {
89
+ this.sparks.stopAnimation();
90
+ }
87
91
  if (this.renderValues?.length === 0 || !this.renderValues) {
88
- return html `
89
- <div class="no-values ${this.invalid ? 'error' : ''}" style="position: relative">
90
- <div style="position: absolute; width: 100%; top: -50px; left: 0;">${this.sparks}</div>
91
- <sl-icon name="prescription2"></sl-icon><br/>
92
- ${this.invalid ? 'invalid / error' : 'healthy!'}
93
- </div>
94
- `;
92
+ if (!this.sparks.animating) {
93
+ this.sparks.startAnimation();
94
+ }
95
+ if (!this.hideSparks) {
96
+ return html `
97
+ <div class="no-values ${this.invalid ? 'error' : ''}" style="position: relative">
98
+ <div style="position: absolute; width: 100%; top: -50px; left: 0;">${this.sparks}</div>
99
+ <sl-icon name="prescription2"></sl-icon>
100
+ <br/>
101
+ ${this.invalid ? 'invalid / error' : 'healthy!'}
102
+ </div>
103
+ `;
104
+ }
105
+ else {
106
+ return html `
107
+ <div class="no-values" style="position: relative">
108
+ </div>
109
+ `;
110
+ }
95
111
  }
96
112
  return html `
97
113
  ${this.paginatorNavigator}
@@ -126,6 +142,9 @@ __decorate([
126
142
  __decorate([
127
143
  property({ type: Boolean })
128
144
  ], Paginator.prototype, "invalid", void 0);
145
+ __decorate([
146
+ property({ type: Boolean })
147
+ ], Paginator.prototype, "hideSparks", void 0);
129
148
  Paginator = __decorate([
130
149
  customElement("pb33f-paginator-navigation")
131
150
  ], Paginator);
@@ -5,11 +5,14 @@ export declare class PixelSparks extends LitElement {
5
5
  private readonly spawnRate;
6
6
  private ctx;
7
7
  private canvas;
8
+ private animationTimer;
8
9
  isError: boolean;
10
+ animating: boolean;
9
11
  static styles: import("lit").CSSResult;
10
12
  constructor();
11
13
  firstUpdated(): void;
12
14
  startAnimation(): void;
15
+ stopAnimation(): void;
13
16
  getRandomBetween(min: number, max: number): number;
14
17
  spawnSpark(): void;
15
18
  animateSparks(): void;
@@ -13,6 +13,7 @@ let PixelSparks = class PixelSparks extends LitElement {
13
13
  this.gravity = 0.0001;
14
14
  this.spawnRate = 70;
15
15
  this.isError = false;
16
+ this.animating = false;
16
17
  }
17
18
  firstUpdated() {
18
19
  const canvas = this.renderRoot.querySelector('canvas');
@@ -23,11 +24,19 @@ let PixelSparks = class PixelSparks extends LitElement {
23
24
  this.ctx = ctx;
24
25
  }
25
26
  }
26
- this.startAnimation();
27
27
  }
28
28
  startAnimation() {
29
- setInterval(() => this.spawnSpark(), 1000 / this.spawnRate);
30
- this.animateSparks();
29
+ if (!this.animating) {
30
+ this.animationTimer = setInterval(() => this.spawnSpark(), 1000 / this.spawnRate);
31
+ this.animateSparks();
32
+ this.animating = true;
33
+ }
34
+ }
35
+ stopAnimation() {
36
+ if (this.animating) {
37
+ clearInterval(this.animationTimer);
38
+ this.animating = false;
39
+ }
31
40
  }
32
41
  getRandomBetween(min, max) {
33
42
  return Math.random() * (max - min) + min;
@@ -64,8 +73,10 @@ let PixelSparks = class PixelSparks extends LitElement {
64
73
  drawSpark(spark) {
65
74
  this.ctx.globalAlpha = spark.opacity; // Set transparency level
66
75
  this.ctx.fillStyle = spark.color;
67
- this.ctx.shadowColor = spark.color;
68
- this.ctx.shadowBlur = 8;
76
+ if (!/Safari/.test(navigator.userAgent)) {
77
+ this.ctx.shadowColor = spark.color;
78
+ this.ctx.shadowBlur = 8;
79
+ }
69
80
  this.ctx.fillRect(spark.x, spark.y, spark.size, spark.size);
70
81
  this.ctx.globalAlpha = 1; // Reset alpha to default
71
82
  }