abledom 0.6.1 → 0.6.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/dist/index.d.cts CHANGED
@@ -72,6 +72,7 @@ interface AbleDOMProps {
72
72
  onIssueUpdated?(element: HTMLElement, rule: ValidationRule, issue: ValidationIssue): void;
73
73
  onIssueRemoved?(element: HTMLElement, rule: ValidationRule): void;
74
74
  };
75
+ exposeInstanceForTesting?: boolean;
75
76
  }
76
77
  declare class AbleDOM {
77
78
  private _win;
@@ -93,6 +94,7 @@ declare class AbleDOM {
93
94
  private _idleResolve;
94
95
  private _currentAnchoredIssues;
95
96
  private _currentNotAnchoredIssues;
97
+ private _readIssues;
96
98
  constructor(win: Window, props?: AbleDOMProps);
97
99
  private _onElementId;
98
100
  private _getHighlighter;
@@ -109,7 +111,7 @@ declare class AbleDOM {
109
111
  private _onFocusOut;
110
112
  private _notifyAsync;
111
113
  private _getCurrentIssues;
112
- idle(): Promise<ValidationIssue[]>;
114
+ idle(markAsRead?: boolean, timeout?: number): Promise<ValidationIssue[] | null>;
113
115
  clearCurrentIssues(anchored?: boolean, notAnchored?: boolean): void;
114
116
  highlightElement(element: HTMLElement | null, scrollIntoView?: boolean, autoHideTime?: number): void;
115
117
  log: typeof console.error;
package/dist/index.d.ts CHANGED
@@ -72,6 +72,7 @@ interface AbleDOMProps {
72
72
  onIssueUpdated?(element: HTMLElement, rule: ValidationRule, issue: ValidationIssue): void;
73
73
  onIssueRemoved?(element: HTMLElement, rule: ValidationRule): void;
74
74
  };
75
+ exposeInstanceForTesting?: boolean;
75
76
  }
76
77
  declare class AbleDOM {
77
78
  private _win;
@@ -93,6 +94,7 @@ declare class AbleDOM {
93
94
  private _idleResolve;
94
95
  private _currentAnchoredIssues;
95
96
  private _currentNotAnchoredIssues;
97
+ private _readIssues;
96
98
  constructor(win: Window, props?: AbleDOMProps);
97
99
  private _onElementId;
98
100
  private _getHighlighter;
@@ -109,7 +111,7 @@ declare class AbleDOM {
109
111
  private _onFocusOut;
110
112
  private _notifyAsync;
111
113
  private _getCurrentIssues;
112
- idle(): Promise<ValidationIssue[]>;
114
+ idle(markAsRead?: boolean, timeout?: number): Promise<ValidationIssue[] | null>;
113
115
  clearCurrentIssues(anchored?: boolean, notAnchored?: boolean): void;
114
116
  highlightElement(element: HTMLElement | null, scrollIntoView?: boolean, autoHideTime?: number): void;
115
117
  log: typeof console.error;
package/dist/index.js CHANGED
@@ -99,10 +99,10 @@ var ValidationRule = class {
99
99
  }
100
100
  };
101
101
 
102
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/ui.css
102
+ // inline-file:/Users/marata/tmp/abledom/src/ui/ui.css
103
103
  var ui_default = "#abledom-report {\n bottom: 20px;\n display: flex;\n flex-direction: column;\n left: 10px;\n max-height: 80%;\n max-width: 60%;\n padding: 4px 8px;\n position: fixed;\n z-index: 100500;\n}\n\n#abledom-report :focus-visible {\n outline: 3px solid red;\n mix-blend-mode: difference;\n}\n\n#abledom-report.abledom-align-left {\n left: 10px;\n right: auto;\n}\n\n#abledom-report.abledom-align-right {\n left: auto;\n right: 10px;\n}\n\n#abledom-report.abledom-align-bottom {\n bottom: 20px;\n top: auto;\n}\n\n#abledom-report.abledom-align-top {\n /* flex-direction: column-reverse; */\n bottom: auto;\n top: 10px;\n}\n\n.abledom-menu-container {\n backdrop-filter: blur(3px);\n border-radius: 8px;\n box-shadow: 0px 0px 4px rgba(127, 127, 127, 0.5);\n display: inline-block;\n margin: 2px auto 2px 0;\n}\n\n#abledom-report.abledom-align-right .abledom-menu-container {\n margin: 2px 0 2px auto;\n}\n\n.abledom-menu {\n background-color: rgba(140, 10, 121, 0.7);\n border-radius: 8px;\n color: white;\n display: inline flex;\n font-family: Arial, Helvetica, sans-serif;\n font-size: 16px;\n line-height: 26px;\n padding: 4px;\n}\n\n.abledom-menu .issues-count {\n margin: 0 8px;\n display: inline-block;\n}\n\n.abledom-menu .button {\n all: unset;\n color: #000;\n cursor: pointer;\n background: linear-gradient(\n 180deg,\n rgba(255, 255, 255, 1) 0%,\n rgba(200, 200, 200, 1) 100%\n );\n border-radius: 6px;\n border: 1px solid rgba(255, 255, 255, 0.4);\n box-sizing: border-box;\n line-height: 0px;\n margin-right: 4px;\n max-height: 26px;\n padding: 2px;\n text-decoration: none;\n}\n\n.abledom-menu .align-button {\n border-right-color: rgba(0, 0, 0, 0.4);\n border-radius: 0;\n margin: 0;\n}\n\n.abledom-menu .align-button:active,\n#abledom-report .pressed {\n background: linear-gradient(\n 180deg,\n rgba(130, 130, 130, 1) 0%,\n rgba(180, 180, 180, 1) 100%\n );\n}\n\n.abledom-menu .align-button-first {\n border-top-left-radius: 6px;\n border-bottom-left-radius: 6px;\n margin-left: 8px;\n}\n.abledom-menu .align-button-last {\n border-top-right-radius: 6px;\n border-bottom-right-radius: 6px;\n border-right-color: rgba(255, 255, 255, 0.4);\n}\n\n.abledom-issues-container {\n overflow: auto;\n max-height: calc(100vh - 100px);\n}\n\n#abledom-report.abledom-align-right .abledom-issues-container {\n text-align: right;\n}\n\n.abledom-issue-container {\n backdrop-filter: blur(3px);\n border-radius: 8px;\n box-shadow: 0px 0px 4px rgba(127, 127, 127, 0.5);\n display: inline-flex;\n margin: 2px 0;\n}\n\n.abledom-issue {\n background-color: rgba(164, 2, 2, 0.7);\n border-radius: 8px;\n color: white;\n display: inline flex;\n font-family: Arial, Helvetica, sans-serif;\n font-size: 16px;\n line-height: 26px;\n padding: 4px;\n}\n.abledom-issue_warning {\n background-color: rgba(163, 82, 1, 0.7);\n}\n.abledom-issue_info {\n background-color: rgba(0, 0, 255, 0.7);\n}\n\n.abledom-issue .button {\n all: unset;\n color: #000;\n cursor: pointer;\n background: linear-gradient(\n 180deg,\n rgba(255, 255, 255, 1) 0%,\n rgba(200, 200, 200, 1) 100%\n );\n border-radius: 6px;\n border: 1px solid rgba(255, 255, 255, 0.4);\n box-sizing: border-box;\n line-height: 0px;\n margin-right: 4px;\n max-height: 26px;\n padding: 2px;\n text-decoration: none;\n}\n\n.abledom-issue .button:hover {\n opacity: 0.7;\n}\n\n.abledom-issue .button.close {\n background: none;\n border-color: transparent;\n color: #fff;\n margin: 0;\n}\n";
104
104
 
105
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/highlighter.css
105
+ // inline-file:/Users/marata/tmp/abledom/src/ui/highlighter.css
106
106
  var highlighter_default = ".abledom-highlight {\n background-color: yellow;\n box-sizing: border-box;\n display: none;\n opacity: 0.6;\n position: fixed;\n z-index: 100499;\n}\n\n.abledom-highlight-border1 {\n border-top: 2px solid red;\n border-bottom: 2px solid red;\n box-sizing: border-box;\n position: absolute;\n top: -2px;\n width: calc(100% + 20px);\n height: calc(100% + 4px);\n margin: 0 -10px;\n}\n\n.abledom-highlight-border2 {\n border-left: 2px solid red;\n border-right: 2px solid red;\n box-sizing: border-box;\n position: absolute;\n width: calc(100% + 4px);\n left: -2px;\n height: calc(100% + 20px);\n margin: -10px 0;\n}\n";
107
107
 
108
108
  // src/ui/domBuilder.ts
@@ -160,7 +160,7 @@ var DOMBuilder = class {
160
160
  }
161
161
  };
162
162
 
163
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/close.svg
163
+ // inline-file:/Users/marata/tmp/abledom/src/ui/close.svg
164
164
  var close_default = (function buildSVG(parent) {
165
165
  const builder = new DOMBuilder(parent);
166
166
  builder.openTag("svg", { "width": "20", "height": "20", "viewBox": "0 0 24 24", "fill": "none", "stroke": "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "xmlns": "http://www.w3.org/2000/svg" }, void 0, "http://www.w3.org/2000/svg");
@@ -174,7 +174,7 @@ var close_default = (function buildSVG(parent) {
174
174
  return parent.firstElementChild;
175
175
  });
176
176
 
177
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/help.svg
177
+ // inline-file:/Users/marata/tmp/abledom/src/ui/help.svg
178
178
  var help_default = (function buildSVG2(parent) {
179
179
  const builder = new DOMBuilder(parent);
180
180
  builder.openTag("svg", { "width": "20", "height": "20", "viewBox": "0 0 24 24", "fill": "none", "stroke": "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "xmlns": "http://www.w3.org/2000/svg" }, void 0, "http://www.w3.org/2000/svg");
@@ -188,7 +188,7 @@ var help_default = (function buildSVG2(parent) {
188
188
  return parent.firstElementChild;
189
189
  });
190
190
 
191
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/log.svg
191
+ // inline-file:/Users/marata/tmp/abledom/src/ui/log.svg
192
192
  var log_default = (function buildSVG3(parent) {
193
193
  const builder = new DOMBuilder(parent);
194
194
  builder.openTag("svg", { "width": "20", "height": "20", "viewBox": "0 0 24 24", "fill": "none", "stroke": "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "xmlns": "http://www.w3.org/2000/svg" }, void 0, "http://www.w3.org/2000/svg");
@@ -200,7 +200,7 @@ var log_default = (function buildSVG3(parent) {
200
200
  return parent.firstElementChild;
201
201
  });
202
202
 
203
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/reveal.svg
203
+ // inline-file:/Users/marata/tmp/abledom/src/ui/reveal.svg
204
204
  var reveal_default = (function buildSVG4(parent) {
205
205
  const builder = new DOMBuilder(parent);
206
206
  builder.openTag("svg", { "width": "20", "height": "20", "viewBox": "0 0 24 24", "fill": "none", "stroke": "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "xmlns": "http://www.w3.org/2000/svg" }, void 0, "http://www.w3.org/2000/svg");
@@ -218,7 +218,7 @@ var reveal_default = (function buildSVG4(parent) {
218
218
  return parent.firstElementChild;
219
219
  });
220
220
 
221
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/bug.svg
221
+ // inline-file:/Users/marata/tmp/abledom/src/ui/bug.svg
222
222
  var bug_default = (function buildSVG5(parent) {
223
223
  const builder = new DOMBuilder(parent);
224
224
  builder.openTag("svg", { "width": "20", "height": "20", "viewBox": "0 0 20 20", "fill": "none", "stroke": "currentColor" }, void 0, "http://www.w3.org/2000/svg");
@@ -246,7 +246,7 @@ var bug_default = (function buildSVG5(parent) {
246
246
  return parent.firstElementChild;
247
247
  });
248
248
 
249
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/hideall.svg
249
+ // inline-file:/Users/marata/tmp/abledom/src/ui/hideall.svg
250
250
  var hideall_default = (function buildSVG6(parent) {
251
251
  const builder = new DOMBuilder(parent);
252
252
  builder.openTag("svg", { "width": "20", "height": "20", "viewBox": "0 0 20 20", "fill": "none", "stroke": "currentColor" }, void 0, "http://www.w3.org/2000/svg");
@@ -260,7 +260,7 @@ var hideall_default = (function buildSVG6(parent) {
260
260
  return parent.firstElementChild;
261
261
  });
262
262
 
263
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/muteall.svg
263
+ // inline-file:/Users/marata/tmp/abledom/src/ui/muteall.svg
264
264
  var muteall_default = (function buildSVG7(parent) {
265
265
  const builder = new DOMBuilder(parent);
266
266
  builder.openTag("svg", { "width": "20", "height": "20", "viewBox": "0 0 20 20", "fill": "none", "stroke": "currentColor" }, void 0, "http://www.w3.org/2000/svg");
@@ -276,7 +276,7 @@ var muteall_default = (function buildSVG7(parent) {
276
276
  return parent.firstElementChild;
277
277
  });
278
278
 
279
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/showall.svg
279
+ // inline-file:/Users/marata/tmp/abledom/src/ui/showall.svg
280
280
  var showall_default = (function buildSVG8(parent) {
281
281
  const builder = new DOMBuilder(parent);
282
282
  builder.openTag("svg", { "width": "20", "height": "20", "viewBox": "0 0 20 20", "fill": "none", "stroke": "currentColor" }, void 0, "http://www.w3.org/2000/svg");
@@ -288,7 +288,7 @@ var showall_default = (function buildSVG8(parent) {
288
288
  return parent.firstElementChild;
289
289
  });
290
290
 
291
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/aligntopleft.svg
291
+ // inline-file:/Users/marata/tmp/abledom/src/ui/aligntopleft.svg
292
292
  var aligntopleft_default = (function buildSVG9(parent) {
293
293
  const builder = new DOMBuilder(parent);
294
294
  builder.openTag("svg", { "width": "20", "height": "20", "viewBox": "0 0 20 20", "fill": "none", "stroke": "currentColor" }, void 0, "http://www.w3.org/2000/svg");
@@ -298,7 +298,7 @@ var aligntopleft_default = (function buildSVG9(parent) {
298
298
  return parent.firstElementChild;
299
299
  });
300
300
 
301
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/aligntopright.svg
301
+ // inline-file:/Users/marata/tmp/abledom/src/ui/aligntopright.svg
302
302
  var aligntopright_default = (function buildSVG10(parent) {
303
303
  const builder = new DOMBuilder(parent);
304
304
  builder.openTag("svg", { "width": "20", "height": "20", "viewBox": "0 0 20 20", "fill": "none", "stroke": "currentColor" }, void 0, "http://www.w3.org/2000/svg");
@@ -308,7 +308,7 @@ var aligntopright_default = (function buildSVG10(parent) {
308
308
  return parent.firstElementChild;
309
309
  });
310
310
 
311
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/alignbottomright.svg
311
+ // inline-file:/Users/marata/tmp/abledom/src/ui/alignbottomright.svg
312
312
  var alignbottomright_default = (function buildSVG11(parent) {
313
313
  const builder = new DOMBuilder(parent);
314
314
  builder.openTag("svg", { "width": "20", "height": "20", "viewBox": "0 0 20 20", "fill": "none", "stroke": "currentColor" }, void 0, "http://www.w3.org/2000/svg");
@@ -318,7 +318,7 @@ var alignbottomright_default = (function buildSVG11(parent) {
318
318
  return parent.firstElementChild;
319
319
  });
320
320
 
321
- // inline-file:/Users/marata/Documents/Work/abledom/src/ui/alignbottomleft.svg
321
+ // inline-file:/Users/marata/tmp/abledom/src/ui/alignbottomleft.svg
322
322
  var alignbottomleft_default = (function buildSVG12(parent) {
323
323
  const builder = new DOMBuilder(parent);
324
324
  builder.openTag("svg", { "width": "20", "height": "20", "viewBox": "0 0 20 20", "fill": "none", "stroke": "currentColor" }, void 0, "http://www.w3.org/2000/svg");
@@ -1100,6 +1100,7 @@ var AbleDOM = class {
1100
1100
  __publicField(this, "_idleResolve");
1101
1101
  __publicField(this, "_currentAnchoredIssues", /* @__PURE__ */ new Map());
1102
1102
  __publicField(this, "_currentNotAnchoredIssues", []);
1103
+ __publicField(this, "_readIssues", /* @__PURE__ */ new Set());
1103
1104
  __publicField(this, "_getHighlighter", () => {
1104
1105
  if (!this._elementHighlighter && !this._isDisposed) {
1105
1106
  this._elementHighlighter = new ElementHighlighter(this._win);
@@ -1141,6 +1142,9 @@ var AbleDOM = class {
1141
1142
  ((_c = (_b = this._win) == null ? void 0 : _b.console) == null ? void 0 : _c.error)) == null ? void 0 : _d.apply(null, args);
1142
1143
  });
1143
1144
  this._win = win;
1145
+ if (props.exposeInstanceForTesting) {
1146
+ this._win.ableDOMInstanceForTesting = this;
1147
+ }
1144
1148
  this._props = props;
1145
1149
  const _elementsToValidate = /* @__PURE__ */ new Set();
1146
1150
  const _elementsToRemove = /* @__PURE__ */ new Set();
@@ -1456,29 +1460,60 @@ var AbleDOM = class {
1456
1460
  rules.forEach((rule) => this._removeIssue(element, rule));
1457
1461
  });
1458
1462
  }
1459
- _getCurrentIssues() {
1460
- const issues = this._currentNotAnchoredIssues.slice(0);
1463
+ _getCurrentIssues(markAsRead) {
1464
+ const issues = [];
1465
+ this._currentNotAnchoredIssues.forEach((issue) => {
1466
+ if (!this._readIssues.has(issue)) {
1467
+ issues.push(issue);
1468
+ }
1469
+ if (markAsRead) {
1470
+ this._readIssues.add(issue);
1471
+ }
1472
+ });
1461
1473
  this._currentAnchoredIssues.forEach((issueByRule) => {
1462
1474
  issueByRule.forEach((issue) => {
1463
- issues.push(issue);
1475
+ if (!this._readIssues.has(issue)) {
1476
+ issues.push(issue);
1477
+ }
1478
+ if (markAsRead) {
1479
+ this._readIssues.add(issue);
1480
+ }
1464
1481
  });
1465
1482
  });
1466
1483
  return issues;
1467
1484
  }
1468
- idle() {
1485
+ idle(markAsRead, timeout) {
1469
1486
  if (!this._clearValidationTimeout) {
1470
- return Promise.resolve(this._getCurrentIssues());
1471
- }
1487
+ return Promise.resolve(this._getCurrentIssues(!!markAsRead));
1488
+ }
1489
+ let timeoutClear;
1490
+ let timeoutResolve;
1491
+ let timeoutPromise = timeout ? new Promise((resolve) => {
1492
+ timeoutResolve = () => {
1493
+ timeoutClear == null ? void 0 : timeoutClear();
1494
+ timeoutResolve = void 0;
1495
+ resolve(null);
1496
+ };
1497
+ let timeoutTimer = this._win.setTimeout(() => {
1498
+ timeoutClear = void 0;
1499
+ timeoutResolve == null ? void 0 : timeoutResolve();
1500
+ }, timeout);
1501
+ timeoutClear = () => {
1502
+ this._win.clearTimeout(timeoutTimer);
1503
+ timeoutClear = void 0;
1504
+ };
1505
+ }) : void 0;
1472
1506
  if (!this._idlePromise) {
1473
1507
  this._idlePromise = new Promise((resolve) => {
1474
1508
  this._idleResolve = () => {
1475
1509
  delete this._idlePromise;
1476
1510
  delete this._idleResolve;
1477
- resolve(this._getCurrentIssues());
1511
+ resolve(this._getCurrentIssues(!!markAsRead));
1512
+ timeoutResolve == null ? void 0 : timeoutResolve();
1478
1513
  };
1479
1514
  });
1480
1515
  }
1481
- return this._idlePromise;
1516
+ return timeoutPromise ? Promise.race([this._idlePromise, timeoutPromise]) : this._idlePromise;
1482
1517
  }
1483
1518
  clearCurrentIssues(anchored = true, notAnchored = true) {
1484
1519
  if (anchored) {