@sebgroup/green-core 1.88.7 → 1.89.0

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.
@@ -5,7 +5,7 @@ import {
5
5
  __privateMethod,
6
6
  __privateSet
7
7
  } from "../../chunks/chunk.QTSIPXV3.js";
8
- var _timeoutId, _progressIntervalId, _alertRef, _timerController, _startTimer, startTimer_fn, _clearTimers, clearTimers_fn, _dismiss, dismiss_fn, _handleButtonClick, handleButtonClick_fn, _handleKeyDown, handleKeyDown_fn, _config, config_get, _renderIcon, renderIcon_fn, _renderMessage, renderMessage_fn, _renderActionButton, renderActionButton_fn, _renderCloseButton, renderCloseButton_fn, _renderTimerBar, renderTimerBar_fn;
8
+ var _timeoutId, _progressIntervalId, _alertRef, _observer, _isVisible, _remaining, _lastTick, _timerController, _setupObserver, setupObserver_fn, _disconnectObserver, disconnectObserver_fn, _startTicking, startTicking_fn, _resumeTimer, resumeTimer_fn, _pauseTimer, pauseTimer_fn, _clearTimers, clearTimers_fn, _dismiss, dismiss_fn, _handleButtonClick, handleButtonClick_fn, _handleKeyDown, handleKeyDown_fn, _config, config_get, _renderIcon, renderIcon_fn, _renderMessage, renderMessage_fn, _renderActionButton, renderActionButton_fn, _renderCloseButton, renderCloseButton_fn, _renderTimerBar, renderTimerBar_fn;
9
9
  import { localized, msg } from "@lit/localize";
10
10
  import { nothing } from "lit";
11
11
  import { property, state } from "lit/decorators.js";
@@ -43,8 +43,12 @@ const PROGRESS_INTERVAL = 100;
43
43
  let GdsAlert = class extends GdsElement {
44
44
  constructor() {
45
45
  super();
46
- // Timer management
47
- __privateAdd(this, _startTimer);
46
+ __privateAdd(this, _setupObserver);
47
+ __privateAdd(this, _disconnectObserver);
48
+ // Timer management (pausable)
49
+ __privateAdd(this, _startTicking);
50
+ __privateAdd(this, _resumeTimer);
51
+ __privateAdd(this, _pauseTimer);
48
52
  __privateAdd(this, _clearTimers);
49
53
  __privateAdd(this, _dismiss);
50
54
  // Event handlers
@@ -70,20 +74,31 @@ let GdsAlert = class extends GdsElement {
70
74
  __privateAdd(this, _timeoutId, void 0);
71
75
  __privateAdd(this, _progressIntervalId, void 0);
72
76
  __privateAdd(this, _alertRef, createRef());
77
+ __privateAdd(this, _observer, void 0);
78
+ __privateAdd(this, _isVisible, false);
79
+ __privateAdd(this, _remaining, 0);
80
+ __privateAdd(this, _lastTick, 0);
73
81
  __privateAdd(this, _timerController, {
74
82
  hostConnected: () => {
75
- if (this.timeout > 0)
76
- __privateMethod(this, _startTimer, startTimer_fn).call(this);
83
+ if (this.timeout > 0) {
84
+ __privateMethod(this, _setupObserver, setupObserver_fn).call(this);
85
+ }
77
86
  },
78
- hostDisconnected: () => __privateMethod(this, _clearTimers, clearTimers_fn).call(this)
87
+ hostDisconnected: () => {
88
+ __privateMethod(this, _disconnectObserver, disconnectObserver_fn).call(this);
89
+ __privateMethod(this, _clearTimers, clearTimers_fn).call(this);
90
+ }
79
91
  });
80
92
  this.addController(__privateGet(this, _timerController));
81
93
  }
82
94
  updated(changed) {
83
95
  if (changed.has("timeout")) {
96
+ __privateMethod(this, _disconnectObserver, disconnectObserver_fn).call(this);
84
97
  __privateMethod(this, _clearTimers, clearTimers_fn).call(this);
98
+ __privateSet(this, _remaining, Math.max(0, this.timeout));
99
+ this._progress = 100;
85
100
  if (this.timeout > 0)
86
- __privateMethod(this, _startTimer, startTimer_fn).call(this);
101
+ __privateMethod(this, _setupObserver, setupObserver_fn).call(this);
87
102
  }
88
103
  }
89
104
  render() {
@@ -114,22 +129,68 @@ let GdsAlert = class extends GdsElement {
114
129
  _timeoutId = new WeakMap();
115
130
  _progressIntervalId = new WeakMap();
116
131
  _alertRef = new WeakMap();
132
+ _observer = new WeakMap();
133
+ _isVisible = new WeakMap();
134
+ _remaining = new WeakMap();
135
+ _lastTick = new WeakMap();
117
136
  _timerController = new WeakMap();
118
- _startTimer = new WeakSet();
119
- startTimer_fn = function() {
120
- const start = Date.now();
121
- this._progress = 100;
137
+ _setupObserver = new WeakSet();
138
+ setupObserver_fn = function() {
139
+ if (__privateGet(this, _observer))
140
+ return;
141
+ if (!__privateGet(this, _remaining))
142
+ __privateSet(this, _remaining, Math.max(0, this.timeout));
143
+ __privateSet(this, _observer, new IntersectionObserver(
144
+ (entries) => {
145
+ const entry = entries[0];
146
+ const ratio = entry?.intersectionRatio ?? 0;
147
+ const nowVisible = ratio >= 0.1;
148
+ if (nowVisible && !__privateGet(this, _isVisible)) {
149
+ __privateSet(this, _isVisible, true);
150
+ __privateMethod(this, _resumeTimer, resumeTimer_fn).call(this);
151
+ } else if (!nowVisible && __privateGet(this, _isVisible)) {
152
+ __privateSet(this, _isVisible, false);
153
+ __privateMethod(this, _pauseTimer, pauseTimer_fn).call(this);
154
+ }
155
+ },
156
+ {
157
+ root: null,
158
+ threshold: [0, 0.1, 1]
159
+ }
160
+ ));
161
+ __privateGet(this, _observer).observe(this);
162
+ };
163
+ _disconnectObserver = new WeakSet();
164
+ disconnectObserver_fn = function() {
165
+ if (__privateGet(this, _observer)) {
166
+ __privateGet(this, _observer).disconnect();
167
+ __privateSet(this, _observer, void 0);
168
+ }
169
+ __privateSet(this, _isVisible, false);
170
+ };
171
+ _startTicking = new WeakSet();
172
+ startTicking_fn = function() {
173
+ __privateSet(this, _lastTick, Date.now());
122
174
  __privateSet(this, _progressIntervalId, window.setInterval(() => {
123
- const elapsed = Date.now() - start;
124
- this._progress = Math.max(
125
- 0,
126
- (this.timeout - elapsed) / this.timeout * 100
127
- );
175
+ const now = Date.now();
176
+ const dt = now - __privateGet(this, _lastTick);
177
+ __privateSet(this, _lastTick, now);
178
+ __privateSet(this, _remaining, Math.max(0, __privateGet(this, _remaining) - dt));
179
+ this._progress = this.timeout > 0 ? Math.max(0, __privateGet(this, _remaining) / this.timeout * 100) : 0;
180
+ if (__privateGet(this, _remaining) <= 0) {
181
+ __privateMethod(this, _dismiss, dismiss_fn).call(this, "timeout");
182
+ }
128
183
  }, PROGRESS_INTERVAL));
129
- __privateSet(this, _timeoutId, window.setTimeout(
130
- () => __privateMethod(this, _dismiss, dismiss_fn).call(this, "timeout"),
131
- this.timeout
132
- ));
184
+ };
185
+ _resumeTimer = new WeakSet();
186
+ resumeTimer_fn = function() {
187
+ if (__privateGet(this, _remaining) <= 0 || __privateGet(this, _timeoutId) || __privateGet(this, _progressIntervalId))
188
+ return;
189
+ __privateMethod(this, _startTicking, startTicking_fn).call(this);
190
+ };
191
+ _pauseTimer = new WeakSet();
192
+ pauseTimer_fn = function() {
193
+ __privateMethod(this, _clearTimers, clearTimers_fn).call(this);
133
194
  };
134
195
  _clearTimers = new WeakSet();
135
196
  clearTimers_fn = function() {
@@ -140,6 +201,7 @@ clearTimers_fn = function() {
140
201
  _dismiss = new WeakSet();
141
202
  dismiss_fn = async function(source) {
142
203
  this._isClosing = true;
204
+ __privateMethod(this, _disconnectObserver, disconnectObserver_fn).call(this);
143
205
  __privateMethod(this, _clearTimers, clearTimers_fn).call(this);
144
206
  await this.updateComplete;
145
207
  this.dispatchCustomEvent("gds-close", {
@@ -23,10 +23,10 @@ export * from './grid/index.js';
23
23
  export * from './grouped-list/index.js';
24
24
  export * from './list-item/index.js';
25
25
  export * from './icons/icon/index.js';
26
+ export * from './img/index.js';
26
27
  export * from './input/index.js';
27
28
  export * from './link/index.js';
28
29
  export * from './mask/index.js';
29
- export * from './img/index.js';
30
30
  export * from './menu-button/index.js';
31
31
  export * from './backdrop/index.js';
32
32
  export * from './popover/index.js';
@@ -23,10 +23,10 @@ export * from "./grid/index.js";
23
23
  export * from "./grouped-list/index.js";
24
24
  export * from "./list-item/index.js";
25
25
  export * from "./icons/icon/index.js";
26
+ export * from "./img/index.js";
26
27
  export * from "./input/index.js";
27
28
  export * from "./link/index.js";
28
29
  export * from "./mask/index.js";
29
- export * from "./img/index.js";
30
30
  export * from "./menu-button/index.js";
31
31
  export * from "./backdrop/index.js";
32
32
  export * from "./popover/index.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sebgroup/green-core",
3
3
  "description": "A carefully crafted set of Web Components, laying the foundation of the Green Design System.",
4
- "version": "1.88.7",
4
+ "version": "1.89.0",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
7
7
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  import "../../chunks/chunk.QTSIPXV3.js";
2
2
  import { html as litHtml } from "lit";
3
- const VER_SUFFIX = "-f2b062";
3
+ const VER_SUFFIX = "-dc748c";
4
4
  class ScopedElementRegistry {
5
5
  static get instance() {
6
6
  if (!globalThis.__gdsElementLookupTable?.[VER_SUFFIX])