@getsigil/core 0.1.0 → 0.2.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.
package/dist/sigil.cjs CHANGED
@@ -52,6 +52,27 @@ var NO_CHILD_ELEMENTS = [
52
52
  "TRACK",
53
53
  "WBR"
54
54
  ];
55
+ var SIGIL_ATTRS = ["data-sigil-id", "data-testid", "sig"];
56
+ function getSigilId(element) {
57
+ for (const attr of SIGIL_ATTRS) {
58
+ const val = element.getAttribute(attr);
59
+ if (val) return val;
60
+ }
61
+ return null;
62
+ }
63
+ function findElementById(markerId) {
64
+ for (const attr of SIGIL_ATTRS) {
65
+ const el = document.querySelector(`[${attr}="${markerId}"]`);
66
+ if (el) return el;
67
+ }
68
+ return null;
69
+ }
70
+ function getSigilSelector() {
71
+ return SIGIL_ATTRS.map((attr) => `[${attr}]`).join(", ");
72
+ }
73
+ function hasSigilAttr(element) {
74
+ return SIGIL_ATTRS.some((attr) => element.hasAttribute(attr));
75
+ }
55
76
  var SigilCore = class {
56
77
  constructor() {
57
78
  this.config = {
@@ -101,15 +122,15 @@ var SigilCore = class {
101
122
  }
102
123
  }
103
124
  /**
104
- * Scan DOM and add markers to elements with data-sigil-id
125
+ * Scan DOM and add markers to elements with sigil attributes (data-sigil-id, data-testid, sig)
105
126
  */
106
127
  scan(root = document) {
107
128
  if (!this.config.enabled) return;
108
- const elements = root.querySelectorAll("[data-sigil-id]");
129
+ const elements = root.querySelectorAll(getSigilSelector());
109
130
  elements.forEach((el) => this.addMarker(el));
110
131
  }
111
132
  /**
112
- * Auto-discover interactive elements and add data-sigil-id attributes
133
+ * Auto-discover interactive elements and add sig attributes
113
134
  */
114
135
  autoDiscover() {
115
136
  const selectors = [
@@ -131,16 +152,17 @@ var SigilCore = class {
131
152
  } catch {
132
153
  }
133
154
  });
134
- const uniqueElements = [...new Set(allElements)].filter((el) => !el.hasAttribute("data-sigil-id"));
155
+ const uniqueElements = [...new Set(allElements)].filter((el) => !hasSigilAttr(el));
135
156
  const usedIds = /* @__PURE__ */ new Set();
136
- document.querySelectorAll("[data-sigil-id]").forEach((el) => {
137
- usedIds.add(el.getAttribute("data-sigil-id"));
157
+ document.querySelectorAll(getSigilSelector()).forEach((el) => {
158
+ const id = getSigilId(el);
159
+ if (id) usedIds.add(id);
138
160
  });
139
161
  let counter = 0;
140
162
  uniqueElements.forEach((el) => {
141
163
  const id = this.generateElementId(el, counter++, usedIds);
142
164
  if (id) {
143
- el.setAttribute("data-sigil-id", id);
165
+ el.setAttribute("sig", id);
144
166
  usedIds.add(id);
145
167
  }
146
168
  });
@@ -203,7 +225,7 @@ var SigilCore = class {
203
225
  async addMarker(element) {
204
226
  if (this.markedElements.has(element)) return;
205
227
  if (!this.config.enabled) return;
206
- const markerId = element.getAttribute("data-sigil-id");
228
+ const markerId = getSigilId(element);
207
229
  if (!markerId) return;
208
230
  this.markedElements.add(element);
209
231
  const encoding = await this.encode(markerId);
@@ -364,7 +386,7 @@ var SigilCore = class {
364
386
  mutation.addedNodes.forEach((node) => {
365
387
  if (node.nodeType === Node.ELEMENT_NODE) {
366
388
  const el = node;
367
- if (el.hasAttribute?.("data-sigil-id")) {
389
+ if (hasSigilAttr(el)) {
368
390
  this.addMarker(el);
369
391
  }
370
392
  this.scan(el);
@@ -451,7 +473,7 @@ var SigilCore = class {
451
473
  }
452
474
  }
453
475
  searchForMarker(markerId) {
454
- const element = document.querySelector(`[data-sigil-id="${markerId}"]`);
476
+ const element = findElementById(markerId);
455
477
  if (!element) {
456
478
  return { found: false, visible: false, markerId };
457
479
  }
@@ -478,24 +500,24 @@ var SigilCore = class {
478
500
  return dir || "down";
479
501
  }
480
502
  scrollToMarker(markerId) {
481
- const element = document.querySelector(`[data-sigil-id="${markerId}"]`);
503
+ const element = findElementById(markerId);
482
504
  if (element) {
483
505
  element.scrollIntoView({ behavior: "instant", block: "center" });
484
506
  }
485
507
  }
486
508
  readTextContent(markerId) {
487
- const element = document.querySelector(`[data-sigil-id="${markerId}"]`);
509
+ const element = findElementById(markerId);
488
510
  if (!element) return { success: false, value: "", error: "Element not found" };
489
511
  return { success: true, value: element.textContent?.trim() || "" };
490
512
  }
491
513
  readInputValue(markerId) {
492
- const element = document.querySelector(`[data-sigil-id="${markerId}"]`);
514
+ const element = findElementById(markerId);
493
515
  if (!element) return { success: false, value: "", error: "Element not found" };
494
516
  const input = element.querySelector("input, textarea, select") || element;
495
517
  return { success: true, value: input.value || "" };
496
518
  }
497
519
  selectOption(markerId, optionValue) {
498
- const element = document.querySelector(`[data-sigil-id="${markerId}"]`);
520
+ const element = findElementById(markerId);
499
521
  if (!element) return { success: false, error: "Element not found" };
500
522
  const select = element.querySelector("select") || element;
501
523
  if (select.tagName === "SELECT") {
@@ -524,7 +546,7 @@ var SigilCore = class {
524
546
  });
525
547
  }
526
548
  setCheckboxState(markerId, shouldCheck) {
527
- const element = document.querySelector(`[data-sigil-id="${markerId}"]`);
549
+ const element = findElementById(markerId);
528
550
  if (!element) return { success: false, error: "Element not found" };
529
551
  const checkbox = element.querySelector('input[type="checkbox"]') || element;
530
552
  if (checkbox.type === "checkbox" && checkbox.checked !== shouldCheck) {
package/dist/sigil.d.cts CHANGED
@@ -34,11 +34,11 @@ declare class SigilCore {
34
34
  */
35
35
  configure(options: Partial<SigilConfig>): void;
36
36
  /**
37
- * Scan DOM and add markers to elements with data-sigil-id
37
+ * Scan DOM and add markers to elements with sigil attributes (data-sigil-id, data-testid, sig)
38
38
  */
39
39
  scan(root?: Document | Element): void;
40
40
  /**
41
- * Auto-discover interactive elements and add data-sigil-id attributes
41
+ * Auto-discover interactive elements and add sig attributes
42
42
  */
43
43
  autoDiscover(): void;
44
44
  /**
package/dist/sigil.d.ts CHANGED
@@ -34,11 +34,11 @@ declare class SigilCore {
34
34
  */
35
35
  configure(options: Partial<SigilConfig>): void;
36
36
  /**
37
- * Scan DOM and add markers to elements with data-sigil-id
37
+ * Scan DOM and add markers to elements with sigil attributes (data-sigil-id, data-testid, sig)
38
38
  */
39
39
  scan(root?: Document | Element): void;
40
40
  /**
41
- * Auto-discover interactive elements and add data-sigil-id attributes
41
+ * Auto-discover interactive elements and add sig attributes
42
42
  */
43
43
  autoDiscover(): void;
44
44
  /**
package/dist/sigil.js CHANGED
@@ -27,6 +27,27 @@ var NO_CHILD_ELEMENTS = [
27
27
  "TRACK",
28
28
  "WBR"
29
29
  ];
30
+ var SIGIL_ATTRS = ["data-sigil-id", "data-testid", "sig"];
31
+ function getSigilId(element) {
32
+ for (const attr of SIGIL_ATTRS) {
33
+ const val = element.getAttribute(attr);
34
+ if (val) return val;
35
+ }
36
+ return null;
37
+ }
38
+ function findElementById(markerId) {
39
+ for (const attr of SIGIL_ATTRS) {
40
+ const el = document.querySelector(`[${attr}="${markerId}"]`);
41
+ if (el) return el;
42
+ }
43
+ return null;
44
+ }
45
+ function getSigilSelector() {
46
+ return SIGIL_ATTRS.map((attr) => `[${attr}]`).join(", ");
47
+ }
48
+ function hasSigilAttr(element) {
49
+ return SIGIL_ATTRS.some((attr) => element.hasAttribute(attr));
50
+ }
30
51
  var SigilCore = class {
31
52
  constructor() {
32
53
  this.config = {
@@ -76,15 +97,15 @@ var SigilCore = class {
76
97
  }
77
98
  }
78
99
  /**
79
- * Scan DOM and add markers to elements with data-sigil-id
100
+ * Scan DOM and add markers to elements with sigil attributes (data-sigil-id, data-testid, sig)
80
101
  */
81
102
  scan(root = document) {
82
103
  if (!this.config.enabled) return;
83
- const elements = root.querySelectorAll("[data-sigil-id]");
104
+ const elements = root.querySelectorAll(getSigilSelector());
84
105
  elements.forEach((el) => this.addMarker(el));
85
106
  }
86
107
  /**
87
- * Auto-discover interactive elements and add data-sigil-id attributes
108
+ * Auto-discover interactive elements and add sig attributes
88
109
  */
89
110
  autoDiscover() {
90
111
  const selectors = [
@@ -106,16 +127,17 @@ var SigilCore = class {
106
127
  } catch {
107
128
  }
108
129
  });
109
- const uniqueElements = [...new Set(allElements)].filter((el) => !el.hasAttribute("data-sigil-id"));
130
+ const uniqueElements = [...new Set(allElements)].filter((el) => !hasSigilAttr(el));
110
131
  const usedIds = /* @__PURE__ */ new Set();
111
- document.querySelectorAll("[data-sigil-id]").forEach((el) => {
112
- usedIds.add(el.getAttribute("data-sigil-id"));
132
+ document.querySelectorAll(getSigilSelector()).forEach((el) => {
133
+ const id = getSigilId(el);
134
+ if (id) usedIds.add(id);
113
135
  });
114
136
  let counter = 0;
115
137
  uniqueElements.forEach((el) => {
116
138
  const id = this.generateElementId(el, counter++, usedIds);
117
139
  if (id) {
118
- el.setAttribute("data-sigil-id", id);
140
+ el.setAttribute("sig", id);
119
141
  usedIds.add(id);
120
142
  }
121
143
  });
@@ -178,7 +200,7 @@ var SigilCore = class {
178
200
  async addMarker(element) {
179
201
  if (this.markedElements.has(element)) return;
180
202
  if (!this.config.enabled) return;
181
- const markerId = element.getAttribute("data-sigil-id");
203
+ const markerId = getSigilId(element);
182
204
  if (!markerId) return;
183
205
  this.markedElements.add(element);
184
206
  const encoding = await this.encode(markerId);
@@ -339,7 +361,7 @@ var SigilCore = class {
339
361
  mutation.addedNodes.forEach((node) => {
340
362
  if (node.nodeType === Node.ELEMENT_NODE) {
341
363
  const el = node;
342
- if (el.hasAttribute?.("data-sigil-id")) {
364
+ if (hasSigilAttr(el)) {
343
365
  this.addMarker(el);
344
366
  }
345
367
  this.scan(el);
@@ -426,7 +448,7 @@ var SigilCore = class {
426
448
  }
427
449
  }
428
450
  searchForMarker(markerId) {
429
- const element = document.querySelector(`[data-sigil-id="${markerId}"]`);
451
+ const element = findElementById(markerId);
430
452
  if (!element) {
431
453
  return { found: false, visible: false, markerId };
432
454
  }
@@ -453,24 +475,24 @@ var SigilCore = class {
453
475
  return dir || "down";
454
476
  }
455
477
  scrollToMarker(markerId) {
456
- const element = document.querySelector(`[data-sigil-id="${markerId}"]`);
478
+ const element = findElementById(markerId);
457
479
  if (element) {
458
480
  element.scrollIntoView({ behavior: "instant", block: "center" });
459
481
  }
460
482
  }
461
483
  readTextContent(markerId) {
462
- const element = document.querySelector(`[data-sigil-id="${markerId}"]`);
484
+ const element = findElementById(markerId);
463
485
  if (!element) return { success: false, value: "", error: "Element not found" };
464
486
  return { success: true, value: element.textContent?.trim() || "" };
465
487
  }
466
488
  readInputValue(markerId) {
467
- const element = document.querySelector(`[data-sigil-id="${markerId}"]`);
489
+ const element = findElementById(markerId);
468
490
  if (!element) return { success: false, value: "", error: "Element not found" };
469
491
  const input = element.querySelector("input, textarea, select") || element;
470
492
  return { success: true, value: input.value || "" };
471
493
  }
472
494
  selectOption(markerId, optionValue) {
473
- const element = document.querySelector(`[data-sigil-id="${markerId}"]`);
495
+ const element = findElementById(markerId);
474
496
  if (!element) return { success: false, error: "Element not found" };
475
497
  const select = element.querySelector("select") || element;
476
498
  if (select.tagName === "SELECT") {
@@ -499,7 +521,7 @@ var SigilCore = class {
499
521
  });
500
522
  }
501
523
  setCheckboxState(markerId, shouldCheck) {
502
- const element = document.querySelector(`[data-sigil-id="${markerId}"]`);
524
+ const element = findElementById(markerId);
503
525
  if (!element) return { success: false, error: "Element not found" };
504
526
  const checkbox = element.querySelector('input[type="checkbox"]') || element;
505
527
  if (checkbox.type === "checkbox" && checkbox.checked !== shouldCheck) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getsigil/core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Visual markers for automated UI testing - zero-config browser automation",
5
5
  "author": "Iridium Softworks",
6
6
  "license": "MIT",