@creator-notes/cnotes 0.103.3 → 0.103.5

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.
@@ -6,6 +6,11 @@
6
6
  * __cnHowto.highlight(el, { label: 'CLICK' | 'TYPE' | 'DONE' })
7
7
  * __cnHowto.clear()
8
8
  * __cnHowto.findExact('Contact', { minW: 100, minH: 36, preferX: 1100 })
9
+ * __cnHowto.redact(['.client-name', '[data-field="email"]']) // blur until unredact()
10
+ * __cnHowto.unredact()
11
+ *
12
+ * highlight() returns { text, kind, stepDraft, box, center, label }; stepDraft
13
+ * is a first-draft caption ("Click **Save**", "Type in **Email**").
9
14
  *
10
15
  * Uses a fixed full-viewport radial overlay so the spotlight is not clipped by
11
16
  * parent overflow (unlike element box-shadow: 0 0 0 9999px).
@@ -22,6 +27,7 @@
22
27
  const OVERLAY_ID = "cn-howto-filmstrip-overlay";
23
28
  const LABEL_ID = "cn-howto-filmstrip-label";
24
29
  const HL_CLASS = "cn-howto-filmstrip-hl";
30
+ const REDACT_CLASS = "cn-howto-filmstrip-redact";
25
31
 
26
32
  function ensureStyle() {
27
33
  if (document.getElementById(STYLE_ID)) return;
@@ -37,6 +43,9 @@
37
43
  position: relative !important;
38
44
  z-index: 2147483646 !important;
39
45
  }
46
+ .${REDACT_CLASS} {
47
+ filter: blur(8px) !important;
48
+ }
40
49
  #${OVERLAY_ID} {
41
50
  position: fixed;
42
51
  inset: 0;
@@ -124,19 +133,84 @@
124
133
  placeSpotlight(cx, cy, { maxOpacity, holeR, fadeMult: opts.fadeMult ?? 5.5 });
125
134
  placeLabel(r, label, accent);
126
135
 
136
+ const target = describe(el);
127
137
  return {
128
138
  ok: true,
129
139
  tag: el.tagName,
130
- text: (el.getAttribute("aria-label") || el.textContent || "")
131
- .replace(/\s+/g, " ")
132
- .trim()
133
- .slice(0, 80),
140
+ text: target.name,
141
+ kind: target.kind,
142
+ stepDraft: draftStep(label, target),
134
143
  box: { x: r.x, y: r.y, w: r.width, h: r.height },
135
144
  center: { x: cx, y: cy },
136
145
  label,
137
146
  };
138
147
  }
139
148
 
149
+ function squash(s) {
150
+ return (s || "").replace(/\s+/g, " ").trim().slice(0, 80);
151
+ }
152
+
153
+ // What the user would call this control: the visible label for a field,
154
+ // the text for a button or link.
155
+ function describe(el) {
156
+ const tag = el.tagName.toLowerCase();
157
+ const role = el.getAttribute("role") || "";
158
+ const isField =
159
+ tag === "input" || tag === "textarea" || tag === "select" || role === "textbox" || role === "combobox";
160
+ let name = "";
161
+ if (isField) {
162
+ const labelledBy = el.getAttribute("aria-labelledby");
163
+ name =
164
+ el.getAttribute("aria-label") ||
165
+ (labelledBy && document.getElementById(labelledBy)?.textContent) ||
166
+ (el.labels && el.labels[0]?.textContent) ||
167
+ el.getAttribute("placeholder") ||
168
+ el.getAttribute("name") ||
169
+ "";
170
+ } else {
171
+ name = el.getAttribute("aria-label") || el.textContent || el.getAttribute("title") || "";
172
+ }
173
+ let kind = "control";
174
+ if (isField) kind = tag === "select" || role === "combobox" ? "picker" : "field";
175
+ else if (tag === "a" || role === "link") kind = "link";
176
+ else if (role === "tab") kind = "tab";
177
+ else if (role === "menuitem" || role === "option") kind = "menu item";
178
+ else if (tag === "button" || role === "button") kind = "button";
179
+ else if (role === "radio" || role === "checkbox" || el.type === "checkbox" || el.type === "radio") kind = "option";
180
+ return { name: squash(name), kind };
181
+ }
182
+
183
+ // A first-draft caption from the target alone. The agent finishes it with
184
+ // what changed on screen after the action.
185
+ function draftStep(label, target) {
186
+ const name = target.name ? `**${target.name}**` : `the ${target.kind}`;
187
+ if (label === "TYPE") return `Type in ${name}`;
188
+ if (label === "DONE") return `Done · ${target.name || "the result"} appears`;
189
+ if (target.kind === "picker") return `Choose from ${name}`;
190
+ return `Click ${name}`;
191
+ }
192
+
193
+ // Blur sensitive regions before a screenshot. Redactions survive clear()
194
+ // so they hold for every frame until unredact() is called.
195
+ function redact(targets) {
196
+ ensureStyle();
197
+ const list = typeof targets === "string" ? [targets] : [...(targets || [])];
198
+ let count = 0;
199
+ for (const t of list) {
200
+ const els = typeof t === "string" ? document.querySelectorAll(t) : [t];
201
+ els.forEach((el) => {
202
+ if (!el || !el.classList) return;
203
+ el.classList.add(REDACT_CLASS);
204
+ count += 1;
205
+ });
206
+ }
207
+ return { ok: true, redacted: count };
208
+ }
209
+
210
+ function unredact() {
211
+ document.querySelectorAll("." + REDACT_CLASS).forEach((el) => el.classList.remove(REDACT_CLASS));
212
+ }
213
+
140
214
  function findExact(exact, opts = {}) {
141
215
  const minW = opts.minW ?? 20;
142
216
  const minH = opts.minH ?? 20;
@@ -189,10 +263,10 @@
189
263
  return candidates[0].el;
190
264
  }
191
265
 
192
- window.__cnHowto = { highlight, clear, findExact, ensureStyle };
266
+ window.__cnHowto = { highlight, clear, findExact, describe, redact, unredact, ensureStyle };
193
267
  window.__cnHighlight = (el, opts) => highlight(el, opts);
194
268
  window.__cnClearHighlight = clear;
195
269
  window.__cnFindExact = findExact;
196
270
 
197
- return { ok: true, api: ["highlight", "clear", "findExact"] };
271
+ return { ok: true, api: ["highlight", "clear", "findExact", "describe", "redact", "unredact"] };
198
272
  })();