arcy.js 0.1.3 → 0.1.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.
package/dist/index.cjs CHANGED
@@ -352,6 +352,19 @@ var init_contract = __esm({
352
352
  }
353
353
  });
354
354
 
355
+ // src/picker/message.ts
356
+ var DESIGN_MODE_PROTOCOL, DESIGN_MODE_READY, DESIGN_MODE_PICK, DESIGN_MODE_EXIT, DESIGN_MODE_SCREENSHOT, SCREENSHOT_RENDER_BUDGET_MS;
357
+ var init_message = __esm({
358
+ "src/picker/message.ts"() {
359
+ DESIGN_MODE_PROTOCOL = 2;
360
+ DESIGN_MODE_READY = "arcy:design-mode:ready";
361
+ DESIGN_MODE_PICK = "arcy:design-mode:pick";
362
+ DESIGN_MODE_EXIT = "arcy:design-mode:exit";
363
+ DESIGN_MODE_SCREENSHOT = "arcy:design-mode:screenshot";
364
+ SCREENSHOT_RENDER_BUDGET_MS = 8e3;
365
+ }
366
+ });
367
+
355
368
  // src/shell/host.ts
356
369
  function isMounted(id = HOST_ID) {
357
370
  const shell = shells.get(id);
@@ -3979,9 +3992,6 @@ function mount(context) {
3979
3992
  flowOffers: result.flowsOffered
3980
3993
  });
3981
3994
  context.touchConversation?.();
3982
- if (result.isFallback) {
3983
- context.track?.("fallback_triggered", {}, { question: text });
3984
- }
3985
3995
  for (const offer of result.flowsOffered) {
3986
3996
  context.track?.(
3987
3997
  "flow_suggested",
@@ -4420,7 +4430,7 @@ function mount(context) {
4420
4430
  historyDrawer.close();
4421
4431
  },
4422
4432
  onSelect: (conversationId) => {
4423
- if ((context.getConversationId?.() ?? "") === conversationId) {
4433
+ if ((context.getConversationId?.() ?? "") === conversationId && !transcript.isEmpty()) {
4424
4434
  historyDrawer.close();
4425
4435
  return;
4426
4436
  }
@@ -4644,11 +4654,13 @@ function mount(context) {
4644
4654
  renderWelcome();
4645
4655
  };
4646
4656
  let catalogRequested = false;
4657
+ let catalogAudience = null;
4647
4658
  const requestFlowCatalog = () => {
4648
4659
  if (catalogRequested) return true;
4649
4660
  const sessionToken = context.getSessionToken?.();
4650
4661
  if (!sessionToken) return false;
4651
4662
  catalogRequested = true;
4663
+ catalogAudience = widget()?.audience || null;
4652
4664
  void fetchFlowCatalog({
4653
4665
  apiBase: context.apiBase,
4654
4666
  sessionToken,
@@ -4719,6 +4731,11 @@ function mount(context) {
4719
4731
  fillCard.reposition();
4720
4732
  },
4721
4733
  refreshChrome() {
4734
+ const audience = widget()?.audience || null;
4735
+ if (catalogRequested && audience !== null && catalogAudience !== null && audience !== catalogAudience && transcript.isEmpty()) {
4736
+ catalogRequested = false;
4737
+ starterFlowsPending = true;
4738
+ }
4722
4739
  if (!requestFlowCatalog() && starterFlowsPending) {
4723
4740
  settleStarterFlows([]);
4724
4741
  }
@@ -5071,25 +5088,45 @@ var init_chat = __esm({
5071
5088
  min-height: 34px;
5072
5089
  }
5073
5090
 
5091
+ /* Painted in the operator's brand, not in neutral grey (D1478). These pills
5092
+ are the first thing a visitor is invited to touch, and a grey outline on a
5093
+ welcome screen reads as chrome rather than as an offer. Tinted rather than
5094
+ filled, the same brand-on-brand-wash pair the transcript already uses for a
5095
+ pressed rating: up to five of these sit in one row, and five solid brand
5096
+ buttons would fight both each other and the send button below them. The
5097
+ brand colour therefore lands on the border, on the wash behind the label,
5098
+ and on the label itself, all derived from the one token the operator set. */
5074
5099
  .${STARTER_CLASS} {
5075
5100
  appearance: none;
5076
5101
  text-align: left;
5077
5102
  font: inherit;
5078
5103
  font-size: 12.5px;
5104
+ font-weight: 500;
5079
5105
  cursor: pointer;
5080
5106
  padding: 7px 13px;
5081
5107
  border-radius: 999px;
5082
- border: 1px solid color-mix(in srgb, var(--_arcy-main-text, #101828) 14%, transparent);
5083
- background: transparent;
5084
- color: inherit;
5108
+ border: 1px solid color-mix(in srgb, var(--_arcy-brand-bg, #101828) 28%, transparent);
5109
+ background: color-mix(in srgb, var(--_arcy-brand-bg, #101828) 8%, transparent);
5110
+ color: var(--_arcy-brand-bg, #101828);
5085
5111
  max-width: 100%;
5086
5112
  transition: background 120ms ease, border-color 120ms ease;
5087
5113
  -webkit-tap-highlight-color: transparent;
5088
5114
  }
5089
5115
 
5090
5116
  .${STARTER_CLASS}:hover {
5091
- background: color-mix(in srgb, var(--_arcy-main-text, #101828) 9%, transparent);
5092
- border-color: color-mix(in srgb, var(--_arcy-main-text, #101828) 30%, transparent);
5117
+ background: color-mix(in srgb, var(--_arcy-brand-bg, #101828) 16%, transparent);
5118
+ border-color: color-mix(in srgb, var(--_arcy-brand-bg, #101828) 48%, transparent);
5119
+ }
5120
+
5121
+ .${STARTER_CLASS}:active {
5122
+ background: color-mix(in srgb, var(--_arcy-brand-bg, #101828) 24%, transparent);
5123
+ }
5124
+
5125
+ /* Brand rather than "currentColor", so the ring stays the same colour on a
5126
+ pill whose label the host page has managed to restyle. */
5127
+ .${STARTER_CLASS}:focus-visible {
5128
+ outline: 2px solid var(--_arcy-brand-bg, #101828);
5129
+ outline-offset: 2px;
5093
5130
  }
5094
5131
 
5095
5132
  @media (prefers-reduced-motion: reduce) {
@@ -5987,6 +6024,21 @@ var init_runtime = __esm({
5987
6024
  /** ADR 0166: true while a fill question is awaiting the end user's
5988
6025
  * answer. Suspends trigger evaluation for the duration. */
5989
6026
  this.inputPending = false;
6027
+ /**
6028
+ * True from the moment a step is entered until its own action has
6029
+ * settled. Suspends trigger evaluation for exactly that window, the same
6030
+ * posture `inputPending` takes around a fill question.
6031
+ *
6032
+ * **This is what makes a step's type mean anything.** The builder's
6033
+ * default condition for a new trigger is `always_true` with no wait
6034
+ * (`flow-draft.ts`'s `newTrigger`), so the ordinary way to say "then go to
6035
+ * step 2" is a trigger that is true the instant the step mounts. Without
6036
+ * this flag `startWatch`'s initial pass fired that trigger before the step
6037
+ * had clicked, filled or navigated anything, and the action never ran at
6038
+ * all: a two-step flow counted to step 2 and quietly ended, having done
6039
+ * nothing. A step acts first; its triggers are how it is left.
6040
+ */
6041
+ this.actionPending = false;
5990
6042
  /** Extra capture-phase listeners `startWatch` installs alongside the
5991
6043
  * click listener (D1297): typing, focus moves and checkbox flips change
5992
6044
  * nothing a MutationObserver can see, yet `text_input`, `is_focused`
@@ -6123,6 +6175,7 @@ var init_runtime = __esm({
6123
6175
  }
6124
6176
  this.activityListeners = [];
6125
6177
  this.inputPending = false;
6178
+ this.actionPending = false;
6126
6179
  this.trueSince.clear();
6127
6180
  this.clicked.clear();
6128
6181
  this.initialValues.clear();
@@ -6212,7 +6265,7 @@ var init_runtime = __esm({
6212
6265
  }
6213
6266
  checkTriggers(step, ctx) {
6214
6267
  if (this.stopped) return;
6215
- if (this.inputPending) return;
6268
+ const mayFire = !this.inputPending && !this.actionPending;
6216
6269
  const now = this.now();
6217
6270
  for (const trigger of [...step.triggers].sort((a, b) => a.position - b.position)) {
6218
6271
  const parsed = this.parsedTrigger(trigger);
@@ -6226,7 +6279,7 @@ var init_runtime = __esm({
6226
6279
  const since = this.trueSince.get(key) ?? now;
6227
6280
  if (!this.trueSince.has(key)) this.trueSince.set(key, since);
6228
6281
  const waitMs = (trigger.waitSeconds ?? 0) * 1e3;
6229
- if (now - since >= waitMs) {
6282
+ if (now - since >= waitMs && mayFire) {
6230
6283
  this.fireTrigger(trigger);
6231
6284
  return;
6232
6285
  }
@@ -6312,8 +6365,7 @@ var init_runtime = __esm({
6312
6365
  }
6313
6366
  this.checkTriggers(step, this.conditionContext());
6314
6367
  }
6315
- async runExecutor(step) {
6316
- const startIndex = this.stepIndex;
6368
+ async runExecutor(step, startIndex) {
6317
6369
  try {
6318
6370
  const outcome = await this.executor(step, {
6319
6371
  doc: this.doc,
@@ -6325,6 +6377,7 @@ var init_runtime = __esm({
6325
6377
  }
6326
6378
  });
6327
6379
  if (this.stopped || this.stepIndex !== startIndex) return;
6380
+ this.actionPending = false;
6328
6381
  if (outcome.status === "advance") {
6329
6382
  this.emit("flow_step_completed");
6330
6383
  if (step.isCompletion) {
@@ -6369,11 +6422,14 @@ var init_runtime = __esm({
6369
6422
  );
6370
6423
  return;
6371
6424
  }
6425
+ this.scheduleCheck(step);
6372
6426
  } catch {
6427
+ this.actionPending = false;
6373
6428
  }
6374
6429
  }
6375
6430
  enterStep() {
6376
6431
  const step = this.currentStep();
6432
+ const stepIndex = this.stepIndex;
6377
6433
  if (!step || this.stopped) {
6378
6434
  this.finish(step ? "completed" : "error", step ? void 0 : { reason: "missing_step" });
6379
6435
  return;
@@ -6388,8 +6444,9 @@ var init_runtime = __esm({
6388
6444
  });
6389
6445
  const begin = () => {
6390
6446
  if (this.stopped) return;
6447
+ this.actionPending = true;
6391
6448
  this.startWatch(step);
6392
- void this.runExecutor(step);
6449
+ void this.runExecutor(step, stepIndex);
6393
6450
  };
6394
6451
  this.waitForPageReady(begin);
6395
6452
  }
@@ -8723,6 +8780,7 @@ var init_screenshot = __esm({
8723
8780
  "src/picker/screenshot.ts"() {
8724
8781
  init_dist();
8725
8782
  init_host();
8783
+ init_message();
8726
8784
  CROP_MARGIN_RATIO = 0.25;
8727
8785
  CROP_MARGIN_MAX_PX = 160;
8728
8786
  CROP_MARGIN_MIN_PX = 28;
@@ -8731,7 +8789,7 @@ var init_screenshot = __esm({
8731
8789
  OUTPUT_MAX_DPR = 2;
8732
8790
  OUTPUT_MAX_PIXELS = 26e5;
8733
8791
  DATA_URL_SOFT_MAX = 36e5;
8734
- RENDER_TIMEOUT_MS = 8e3;
8792
+ RENDER_TIMEOUT_MS = SCREENSHOT_RENDER_BUDGET_MS;
8735
8793
  PII_PATTERNS2 = [
8736
8794
  /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,
8737
8795
  /\b\d{3}-\d{2}-\d{4}\b/g,
@@ -9169,13 +9227,7 @@ function normalizeRoute(href, base) {
9169
9227
 
9170
9228
  // src/picker/activate.ts
9171
9229
  init_warn();
9172
-
9173
- // src/picker/message.ts
9174
- var DESIGN_MODE_PROTOCOL = 2;
9175
- var DESIGN_MODE_READY = "arcy:design-mode:ready";
9176
- var DESIGN_MODE_PICK = "arcy:design-mode:pick";
9177
- var DESIGN_MODE_EXIT = "arcy:design-mode:exit";
9178
- var DESIGN_MODE_SCREENSHOT = "arcy:design-mode:screenshot";
9230
+ init_message();
9179
9231
 
9180
9232
  // src/picker/notice.ts
9181
9233
  init_host();
@@ -13114,6 +13166,11 @@ function createArcyInternals(internalOptions = {}) {
13114
13166
  welcomeMessage: text(raw?.welcomeMessage),
13115
13167
  inputPlaceholder: text(raw?.inputPlaceholder),
13116
13168
  welcomeHeadline: text(raw?.welcomeHeadline),
13169
+ // Which copy the three texts above are (ADR 0195). Shape-checked like
13170
+ // everything else read out of the bootstrap (ADR 0050), and anything
13171
+ // that is not one of the two audiences reads as the empty string, which
13172
+ // the panel treats as "not known yet" and never as a change.
13173
+ audience: raw?.audience === "identified" || raw?.audience === "anonymous" ? raw.audience : "",
13117
13174
  // Re-checked here rather than trusted: a rewritten bootstrap must not
13118
13175
  // be able to turn a camera prompt on for an operator who never did
13119
13176
  // (ADR 0050, ADR 0102).
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { DESIGN_MODE_PROTOCOL, DESIGN_MODE_EXIT, DESIGN_MODE_SCREENSHOT, DESIGN_MODE_PICK, DESIGN_MODE_READY } from './chunk-7VVKR3AO.js';
2
1
  import { FALLBACK_CHROME, resolveImageUrl, FONT_KEY_PROPERTY, isRenderableImageUrl, readViewport, POLICY_LINK_CLASS, BAR_TRAY_CLASS, ATTACHABLE_TYPES, TOOLTIP_CSS, surfaceWidth, clampOffsetX, dragTransform, carriesFiles, droppedFiles, MOBILE_MARGIN, CHAT_CONTRACT, CHAT_GLOBAL } from './chunk-DW3GUQ6J.js';
3
2
  import { createShellState, safeStore, browserSessionStorage, writeJson, browserLocalStorage, readJson, hasPendingPreview, createFlowRunState, FLOW_CONTRACT, FLOW_GLOBAL } from './chunk-FR6SJSDU.js';
4
3
  import { PICKER_CONTRACT, PICKER_GLOBAL } from './chunk-DKYMIAYF.js';
4
+ import { DESIGN_MODE_PROTOCOL, DESIGN_MODE_EXIT, DESIGN_MODE_SCREENSHOT, DESIGN_MODE_PICK, DESIGN_MODE_READY } from './chunk-GDGE3HLE.js';
5
5
  import { warn, reportCspViolations, releaseHostFocus, Z_INDEX, createShell, injectStyles } from './chunk-LGWYJSYX.js';
6
6
  import { captureEventFingerprint, containsPii } from './chunk-NY3NXM2V.js';
7
7
 
@@ -3998,6 +3998,11 @@ function createArcyInternals(internalOptions = {}) {
3998
3998
  welcomeMessage: text(raw?.welcomeMessage),
3999
3999
  inputPlaceholder: text(raw?.inputPlaceholder),
4000
4000
  welcomeHeadline: text(raw?.welcomeHeadline),
4001
+ // Which copy the three texts above are (ADR 0195). Shape-checked like
4002
+ // everything else read out of the bootstrap (ADR 0050), and anything
4003
+ // that is not one of the two audiences reads as the empty string, which
4004
+ // the panel treats as "not known yet" and never as a change.
4005
+ audience: raw?.audience === "identified" || raw?.audience === "anonymous" ? raw.audience : "",
4001
4006
  // Re-checked here rather than trusted: a rewritten bootstrap must not
4002
4007
  // be able to turn a camera prompt on for an operator who never did
4003
4008
  // (ADR 0050, ADR 0102).
@@ -4717,7 +4722,7 @@ var bundledChunks = {
4717
4722
  cdnBase: null,
4718
4723
  loadChat: (win, timeoutMs, setTimeoutImpl) => importChunk(
4719
4724
  win,
4720
- () => import('./chat-HNE6525R.js'),
4725
+ () => import('./chat-NCTVDXR5.js'),
4721
4726
  CHAT_GLOBAL,
4722
4727
  CHAT_CONTRACT,
4723
4728
  "chat panel",
@@ -4726,7 +4731,7 @@ var bundledChunks = {
4726
4731
  ),
4727
4732
  loadFlow: (win, timeoutMs, setTimeoutImpl) => importChunk(
4728
4733
  win,
4729
- () => import('./flow-M7W3H3C5.js'),
4734
+ () => import('./flow-GATJGDCR.js'),
4730
4735
  FLOW_GLOBAL,
4731
4736
  FLOW_CONTRACT,
4732
4737
  "flow engine",
@@ -4735,7 +4740,7 @@ var bundledChunks = {
4735
4740
  ),
4736
4741
  loadPicker: (win, timeoutMs, setTimeoutImpl) => importChunk(
4737
4742
  win,
4738
- () => import('./picker-JPESE6JJ.js'),
4743
+ () => import('./picker-GPZ2GHB4.js'),
4739
4744
  PICKER_GLOBAL,
4740
4745
  PICKER_CONTRACT,
4741
4746
  "design-mode picker",
@@ -1,4 +1,5 @@
1
1
  import { PICKER_CONTRACT, PICKER_GLOBAL } from './chunk-DKYMIAYF.js';
2
+ import { SCREENSHOT_RENDER_BUDGET_MS } from './chunk-GDGE3HLE.js';
2
3
  import { createShell, injectStyles, warn, HOST_ATTRIBUTE } from './chunk-LGWYJSYX.js';
3
4
  import { matchTarget } from './chunk-NIHUDSWK.js';
4
5
  import { resolveInteractiveTarget, createTargetFingerprint, captureEventFingerprint, closestAcrossShadow, isStableId, containsPii, SELECTOR_CANDIDATES_MAX, collectElementsDeep, querySelectorAllDeep } from './chunk-NY3NXM2V.js';
@@ -1665,7 +1666,7 @@ var CROP_MAX_HEIGHT = 1200;
1665
1666
  var OUTPUT_MAX_DPR = 2;
1666
1667
  var OUTPUT_MAX_PIXELS = 26e5;
1667
1668
  var DATA_URL_SOFT_MAX = 36e5;
1668
- var RENDER_TIMEOUT_MS = 8e3;
1669
+ var RENDER_TIMEOUT_MS = SCREENSHOT_RENDER_BUDGET_MS;
1669
1670
  var PII_PATTERNS = [
1670
1671
  /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,
1671
1672
  /\b\d{3}-\d{2}-\d{4}\b/g,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arcy.js",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "ARCY — the universal JavaScript utility for embedding an AI agent that talks to, learns from, and acts on behalf of your users.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,3 +0,0 @@
1
- (function(){'use strict';/* arcy.js — https://arcyai.com */
2
- function I(t){if(t.parentElement!==null)return t.parentElement;let e=t.parentNode;return e!==null&&"host"in e?e.host:null}function nt(t,e){let n=e;for(;n!==null;){if(n===t)return true;n=I(n);}return false}var rt=100;function b(t,e=0){let n=[],r=t.querySelectorAll("*");for(let o=0;o<r.length;o+=1){let i=r[o];n.push(i),i.shadowRoot!==null&&e<rt&&n.push(...b(i.shadowRoot,e+1));}return n}function H(t,e,n=0){let r=Array.from(t.querySelectorAll(e)),o=t.querySelectorAll("*");for(let i=0;i<o.length;i+=1){let s=o[i];s.shadowRoot!==null&&n<rt&&r.push(...H(s.shadowRoot,e,n+1));}return r}var ot=[/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,/\b\d{3}-\d{2}-\d{4}\b/g,/\b\d(?:[ -]?\d){12,18}\b/g],x="[masked]";function W(t){return ot.some(e=>(e.lastIndex=0,e.test(t)))}var V=4096,Ct=100,At=64;function k(t){if(!t)return;let e=t.slice(0,V);if(t.length>V){let r=e.search(/\s\S*$/);e=r===-1?e.slice(0,V-Ct):e.slice(0,r);}let n=e.replace(/\s+/g," ").trim();if(n){for(let r of ot)n=n.replace(r,x);return n.slice(0,80)}}function it(t){return !(t.length===0||t.length>64||t.includes(":")||t.startsWith("radix-")||/^\d+$/.test(t)||/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t))}var Lt=new Set(["button","input","select","textarea","label","summary"]),Mt=new Set(["button","link","menuitem","tab","option"]);function R(t){let e=t.tagName.toLowerCase();if(Lt.has(e)||e==="a"&&t.hasAttribute("href"))return true;let n=t.getAttribute("role");if(n!==null&&Mt.has(n))return true;let r=t.getAttribute("contenteditable");return r===""||r==="true"}var Nt=["data-testid","data-test","data-cy","id","name","aria-label"],Ot=["data-testid","data-test","data-cy"],Pt=64;function Dt(t){for(let e of Ot){let n=t.getAttribute(e);if(n===null)continue;let r=n.trim();if(!(r===""||r.length>Pt)&&!W(r))return r}}var Ht=new Set(["navigation","main","banner","contentinfo","search","form","region","dialog"]);function Vt(t){let e=I(t);for(;e!==null;){let n=e.tagName.toLowerCase();if(n==="body"||n==="html")return;for(let o of Nt){let i=e.getAttribute(o);if(i===null||o==="id"&&!it(i))continue;let s=k(i);if(s!==void 0)return {tag:n,attr:o,value:s}}let r=e.getAttribute("role");if(r!==null&&Ht.has(r))return {tag:n,attr:"role",value:r};e=I(e);}}function Wt(t){let e=0,n=t.previousElementSibling;for(;n!==null;)n.tagName===t.tagName&&(e+=1),n=n.previousElementSibling;return e}function C(t){let e={tag:t.tagName.toLowerCase(),siblingIndex:Wt(t)},n=k(t.textContent);n!==void 0&&(e.text=n);let r=k(t.getAttribute("aria-label"));r!==void 0&&(e.ariaLabel=r);let o=k(t.getAttribute("placeholder"));o!==void 0&&(e.placeholder=o);let i=t.getAttribute("id");i!==null&&it(i)&&!W(i)&&(e.id=i);let s=t.getAttribute("role");if(s!==null){let u=s.trim();u!==""&&u.length<=At&&!W(u)&&(e.role=u);}let l=Dt(t);l!==void 0&&(e.testId=l);let a=Vt(t);return a!==void 0&&(e.ancestorTag=a.tag,e.ancestorAttr=a.attr,e.ancestorValue=a.value),e}function Kt(t){return t.getClientRects().length>0}var $t=50,Bt=40,Ut=10,jt=15,Gt=15,Xt=10,Jt=10,Yt=10,zt=5,qt=5,Zt=.6,Qt=.7,te={1:.3,2:.45,3:.6,4:.75,5:.9};function A(t){return t.split(x).join(" ").replace(/\s+/g," ").trim()}function ee(t,e){if(e===void 0)return 0;let n=A(t),r=A(e);return n===""||r===""?0:r===n?1:r.includes(n)||n.includes(r)?Zt:0}function T(t,e){return e===t?1:0}function K(t){return t.includes(x)&&A(t)===""}function ne(t,e,n){let r=0,o=0,i=(s,l)=>{r+=s,o+=s*l;};if(t.testId!==void 0&&i($t,T(t.testId,e.testId)),t.text!==void 0&&A(t.text)!==""&&i(n?Ut:Bt,ee(t.text,e.text)),t.ariaLabel!==void 0&&!K(t.ariaLabel)&&i(jt,T(t.ariaLabel,e.ariaLabel)),t.placeholder!==void 0&&!K(t.placeholder)&&i(Jt,T(t.placeholder,e.placeholder)),t.id!==void 0&&i(Gt,T(t.id,e.id)),t.role!==void 0&&i(zt,T(t.role,e.role)),i(Xt,e.tag===t.tag?1:0),i(qt,e.siblingIndex===t.siblingIndex?1:0),t.ancestorAttr!==void 0&&t.ancestorValue!==void 0&&!K(t.ancestorValue)){let s=0;e.ancestorAttr===t.ancestorAttr&&e.ancestorValue===t.ancestorValue&&(s=e.ancestorTag===t.ancestorTag?1:Qt),i(Yt,s);}return r===0?0:o/r}function re(t,e){if(t.selector===null)return null;try{return H(e,t.selector)}catch{return null}}function oe(t,e){let n=t.core.tag,r=[];for(let o of b(e))(o.tagName.toLowerCase()===n||R(o))&&r.push(o);return r}function st(t,e){if(e.length===0)return {status:"not_found",reason:"no_candidates",matchCount:0};let n=te[t.precision],r=false,o=[];for(let s of e){if(!Kt(s))continue;r=true;let l=ne(t.core,C(s),t.dynamicText);l>=n&&o.push({element:s,score:l});}if(o=o.filter((s,l)=>{let a=o[l+1];return a===void 0?true:!(nt(s.element,a.element)&&s.score<=a.score)}),o.length===0)return {status:"not_found",reason:r?"below_threshold":"not_visible",matchCount:0};let i=t.ordinal>=1?o[t.ordinal-1]:void 0;return i===void 0?{status:"not_found",reason:"ordinal_out_of_range",matchCount:o.length}:{status:"matched",element:i.element,score:i.score,matchCount:o.length}}function g(t,e){try{let n=re(t,e);if(n!==null&&n.length>0){let r=st(t,n);if(r.status==="matched"||r.reason==="ordinal_out_of_range")return r}return st(t,oe(t,e))}catch{return {status:"not_found",reason:"error",matchCount:0}}}var ie=40;function lt(t=document){try{let e=b(t),n=[];for(let r of e){if(n.length>=ie)break;R(r)&&n.push(C(r));}return n}catch{return []}}var $={getItem:()=>null,setItem:()=>{},removeItem:()=>{}};function y(t){return t?{getItem(e){try{return t.getItem(e)}catch{return null}},setItem(e,n){try{t.setItem(e,n);}catch{}},removeItem(e){try{t.removeItem(e);}catch{}}}:$}function at(){try{let t=globalThis.localStorage;return y(t)}catch{return $}}function ut(){try{let t=globalThis.sessionStorage;return y(t)}catch{return $}}function L(t,e){let n=t.getItem(e);if(!n)return null;try{let r=JSON.parse(n);return !r||typeof r!="object"||Array.isArray(r)?null:r}catch{return null}}function M(t,e,n){try{t.setItem(e,JSON.stringify(n));}catch{}}var se=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;function B(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;if(e&&typeof e.randomUUID=="function")try{let o=e.randomUUID();if(se.test(o))return o}catch{}let n=new Uint8Array(16);if(e&&typeof e.getRandomValues=="function")e.getRandomValues(n);else for(let o=0;o<n.length;o++)n[o]=Math.floor(Math.random()*256);n[6]=(n[6]??0)&15|64,n[8]=(n[8]??0)&63|128;let r="";for(let o=0;o<n.length;o++)r+=(n[o]??0).toString(16).padStart(2,"0");return `${r.slice(0,8)}-${r.slice(8,12)}-${r.slice(12,16)}-${r.slice(16,20)}-${r.slice(20)}`}var le=3,ae=["attribute","current_page","element","text_input","user_fills_input","current_time","user_idle","visitor","always_true","group"];function v(t){if(!t||typeof t!="object")return false;let e=t;return e.v===1&&!!e.core&&typeof e.core=="object"&&typeof e.core.tag=="string"&&(e.selector===null||typeof e.selector=="string")&&typeof e.ordinal=="number"&&typeof e.precision=="number"}function pt(t,e){if(e>le||!t||typeof t!="object")return null;let n=t,r=n.type;if(typeof r!="string"||!ae.includes(r))return null;switch(r){case "attribute":return typeof n.codeName!="string"||typeof n.operator!="string"?null:{type:"attribute",codeName:n.codeName,operator:n.operator,value:n.value};case "current_page":return !Array.isArray(n.matches)||!Array.isArray(n.doesNotMatch)?null:{type:"current_page",matches:n.matches.filter(o=>typeof o=="string"),doesNotMatch:n.doesNotMatch.filter(o=>typeof o=="string")};case "element":return !v(n.target)||typeof n.state!="string"?null:{type:"element",target:n.target,state:n.state};case "text_input":return !v(n.target)||typeof n.operator!="string"||typeof n.value!="string"?null:{type:"text_input",target:n.target,operator:n.operator,value:n.value};case "user_fills_input":return v(n.target)?{type:"user_fills_input",target:n.target}:null;case "current_time":{let o=n.from,i=n.to;return o!==null&&typeof o!="string"||i!==null&&typeof i!="string"?null:{type:"current_time",from:o??null,to:i??null}}case "user_idle":{let o=n.seconds;return typeof o!="number"||!Number.isFinite(o)||o<1||o>600?null:{type:"user_idle",seconds:o}}case "visitor":return n.state!=="first_visit"&&n.state!=="returning"?null:{type:"visitor",state:n.state};case "always_true":return {type:"always_true"};case "group":{if(!Array.isArray(n.children)||n.operator!=="and"&&n.operator!=="or")return null;let o=[];for(let i of n.children){let s=pt(i,e+1);s&&o.push(s);}return {type:"group",operator:n.operator,children:o}}default:return null}}function mt(t){if(!t||typeof t!="object")return null;let e=t;if(e.v!==1)return null;let n=pt(e.node,0);return n?{v:1,node:n}:null}function ct(t){let e=/^(\d{2}):(\d{2})$/.exec(t);if(!e)return null;let n=Number(e[1]),r=Number(e[2]);return n>23||r>59?null:n*60+r}function ue(t,e){if(t.from===null&&t.to===null)return true;let n=e.getHours()*60+e.getMinutes(),r=t.from!==null?ct(t.from):null,o=t.to!==null?ct(t.to):null;return t.from!==null&&r===null||t.to!==null&&o===null?false:r!==null&&o===null?n>=r:r===null&&o!==null?n<=o:r!==null&&o!==null?r<=o?n>=r&&n<=o:n>=r||n<=o:true}function U(t,e){let n=t.split("*").map(r=>r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");try{return new RegExp(`^${n}$`).test(e)}catch{return false}}function ce(t,e){return t.doesNotMatch.some(n=>U(n,e))?false:t.matches.length===0?true:t.matches.some(n=>U(n,e))}function ht(t,e,n){if(e===void 0)return false;switch(t){case "is":return e===n;case "is_not":return e!==n;case "contains":return e.includes(n);case "does_not_contain":return !e.includes(n);case "starts_with":return e.startsWith(n);case "ends_with":return e.endsWith(n);case "is_empty":return e==="";case "is_not_empty":return e!=="";case "greater_than":case "less_than":{let r=Number(e),o=Number(n);return e.trim()===""||!Number.isFinite(r)||!Number.isFinite(o)?false:t==="greater_than"?r>o:r<o}case "matches_pattern":return U(n,e);default:return false}}function dt(t,e){try{if(t.getClientRects().length===0)return !1}catch{return false}try{let n=e.defaultView?.getComputedStyle(t);if(n&&n.visibility==="hidden")return !1}catch{}return true}function ft(t,e){try{let n=e.activeElement;for(;n;){if(n===t||t.contains(n))return !0;n=n.shadowRoot?.activeElement??null;}}catch{}return false}function de(t,e){let n=g(t.target,e.doc);switch(t.state){case "is_present":return n.status==="matched";case "is_not_present":return n.status==="not_found";case "is_disabled":case "is_not_disabled":{if(n.status!=="matched")return false;let r="disabled"in n.element&&n.element.disabled===true;return t.state==="is_disabled"?r:!r}case "is_clicked":return e.wasClicked(t.target);case "is_not_clicked":return !e.wasClicked(t.target);case "is_visible":return n.status==="matched"&&dt(n.element,e.doc);case "is_not_visible":return n.status!=="matched"||!dt(n.element,e.doc);case "is_checked":case "is_not_checked":{if(n.status!=="matched")return false;let r="checked"in n.element&&n.element.checked===true;return t.state==="is_checked"?r:!r}case "is_focused":return n.status==="matched"&&ft(n.element,e.doc);case "is_not_focused":return n.status!=="matched"||!ft(n.element,e.doc);default:return false}}function fe(t,e){let n=e.getTrait?.(t.codeName);switch(t.operator){case "has_any_value":return n!=null&&n!=="";case "is_empty":return n==null||n==="";}if(n===void 0)return false;let r=String(n),o=t.value===void 0?"":String(t.value);return ht(t.operator,r,o)}function N(t,e){switch(t.type){case "always_true":return true;case "current_time":return ue(t,e.now());case "current_page":return ce(t,e.href());case "element":return de(t,e);case "attribute":return fe(t,e);case "text_input":{let n=e.readInputValue(t.target);return ht(t.operator,n,t.value)}case "user_fills_input":{let n=e.readInputValue(t.target),r=e.initialInputValue(t.target);return n!==void 0&&n!==""&&n!==r}case "user_idle":{let n=e.idleSeconds?.();return n!==void 0&&n>=t.seconds}case "visitor":{let n=e.isFirstVisit?.();return n===void 0?false:t.state==="first_visit"?n:!n}case "group":return t.children.length===0?false:t.operator==="and"?t.children.every(n=>N(n,e)):t.children.some(n=>N(n,e));default:return false}}function j(t){return t.type==="current_time"||t.type==="user_idle"?true:t.type==="group"?t.children.some(j):false}function G(t){return t.type==="user_idle"?true:t.type==="group"?t.children.some(G):false}var pe="https://api.arcyai.com";var me="/api/v1/sdk/flows";function he(t){return t!==void 0?t:typeof fetch<"u"?fetch.bind(globalThis):null}function ge(t,e,n,r){return new Promise(o=>{let i=false,s=l=>{i||(i=true,o(l));};t.then(s,()=>s(r));try{n(()=>s(r),e);}catch{}})}function we(t){return !t||typeof t!="object"||Array.isArray(t)?null:O(t.flow)}function O(t){if(!t||typeof t!="object"||Array.isArray(t))return null;let e=t;return typeof e.cvid!="string"||!Array.isArray(e.steps)?null:t}function ye(t){return {"Content-Type":"application/json",Authorization:`Bearer ${t}`}}async function gt(t,e){let{apiBase:n=pe,sessionToken:r,sessionId:o,setTimeoutImpl:i=(u,p)=>setTimeout(u,p),timeoutMs:s=8e3}=e,l=he(e.fetchImpl);if(!l)return {ok:false,reason:"unusable"};let a=(async()=>{let u;try{u=await l(`${n}${me}/${encodeURIComponent(t)}/run`,{method:"POST",headers:ye(r),body:JSON.stringify(o?{sessionId:o}:{}),credentials:"omit"});}catch{return {ok:false,reason:"network"}}if(u.status===404)return {ok:false,reason:"not_found"};if(!u.ok)return {ok:false,reason:"rejected"};let p;try{p=await u.json();}catch{return {ok:false,reason:"unusable"}}let f=we(p);return f?{ok:true,flow:f}:{ok:false,reason:"unusable"}})();return ge(a,s,i,{ok:false,reason:"network"})}var ve="arcy.flow.";function Se(t){return typeof t.flowId=="string"&&t.flowId.length>0&&typeof t.currentStepCvid=="string"&&t.currentStepCvid.length>0&&typeof t.flowSessionId=="string"&&t.flowSessionId.length>0&&typeof t.startedAt=="number"}function wt(t,{store:e=at()}={}){let n=y(e),r=ve+t;return {read(){let o=L(n,r);return !o||!Se(o)?null:{flowId:o.flowId,currentStepCvid:o.currentStepCvid,flowSessionId:o.flowSessionId,startedAt:o.startedAt}},save(o){M(n,r,o);},clear(){n.removeItem(r);}}}var be="arcy.preview.";function Te(t){return typeof t.flowId=="string"&&t.flowId.length>0&&typeof t.currentStepCvid=="string"&&t.currentStepCvid.length>0&&typeof t.flowSessionId=="string"&&t.flowSessionId.length>0&&typeof t.startedAt=="number"&&t.flow!==void 0&&t.flow!==null}function X(t,{store:e=ut()}={}){let n=y(e),r=be+t;return {read(){let o=L(n,r);return !o||!Te(o)?null:o},save(o){M(n,r,o);},clear(){n.removeItem(r);}}}var Ee=250,_e=15e3,Fe=1e3,Ie=["pointerdown","pointermove","keydown","wheel","scroll","touchstart"],J=250,ke=3e3,xe=250,Y=()=>{},Re=()=>Promise.resolve({status:"wait"});function z(t,e){return t.steps.findIndex(n=>n.cvid===e)}function vt(t){return t?t.type==="element"?[t.target]:t.type==="group"?t.children.flatMap(e=>vt(e)):[]:[]}var q=class{constructor(e,n,r,o,i,s,l,a,u,p,f,w,h,D,S,d){this.flow=e;this.stepIndex=n;this.startedAt=r;this.flowSessionId=o;this.doc=i;this.win=s;this.runState=l;this.executor=a;this.getTrait=u;this.isFirstVisit=p;this.track=f;this.now=w;this.setTimeoutImpl=h;this.clearTimeoutImpl=D;this.setIntervalImpl=S;this.clearIntervalImpl=d;this.stopped=false;this.dwellTimer=null;this.observer=null;this.intervalHandle=null;this.throttleHandle=null;this.lastCheck=0;this.trueSince=new Map;this.clicked=new Set;this.initialValues=new Map;this.clickListener=null;this.lastActivityAt=0;this.activityListeners=[];this.inputPending=false;this.inputListeners=[];this.parsedTriggers=new Map;this.lastStopReason=null;this.onStatus=null;this.onFailure=null;this.onCancelFill=null;}resolveElement(e,n=0){return g(e,this.doc)}waitForElement(e){let n=()=>{let l=g(e,this.doc),a=l.status==="matched"&&l.element.isConnected;return {result:l,found:a}},r=n(),o=Math.max(0,this.flow.waitSeconds*1e3);if(r.found||o===0)return Promise.resolve(r.result);let i=this.stepIndex,s=this.now()+o;return new Promise(l=>{let a=()=>{let u=n();if(u.found||this.stopped||this.stepIndex!==i||this.now()>=s){l(u.result);return}this.setTimeoutImpl(a,J);};this.setTimeoutImpl(a,J);})}conditionContext(){return {doc:this.doc,now:()=>new Date(this.now()),href:()=>this.win.location?.href??"",getTrait:this.getTrait,idleSeconds:()=>Math.max(0,(this.now()-this.lastActivityAt)/1e3),isFirstVisit:this.isFirstVisit,wasClicked:e=>this.clicked.has(e),readInputValue:e=>{let n=g(e,this.doc);if(n.status!=="matched")return;let r=n.element;return typeof r.value=="string"?r.value:void 0},initialInputValue:e=>{if(!this.initialValues.has(e)){let n=g(e,this.doc),r=n.status==="matched"?n.element:null;this.initialValues.set(e,r&&typeof r.value=="string"?r.value:void 0);}return this.initialValues.get(e)}}}currentStep(){return this.flow.steps[this.stepIndex]}persist(){let e=this.currentStep();e&&this.runState.save({flowId:this.flow.cvid,currentStepCvid:e.cvid,flowSessionId:this.flowSessionId,startedAt:this.startedAt});}teardownWatch(){if(this.observer?.disconnect(),this.observer=null,this.intervalHandle!==null&&(this.clearIntervalImpl(this.intervalHandle),this.intervalHandle=null),this.throttleHandle!==null&&(this.clearTimeoutImpl(this.throttleHandle),this.throttleHandle=null),this.dwellTimer!==null&&(this.clearTimeoutImpl(this.dwellTimer),this.dwellTimer=null),this.clickListener){try{this.doc.removeEventListener("click",this.clickListener,!0);}catch{}this.clickListener=null;}for(let[e,n]of this.inputListeners)try{this.doc.removeEventListener(e,n,!0);}catch{}this.inputListeners=[];for(let[e,n]of this.activityListeners)try{this.doc.removeEventListener(e,n,!0);}catch{}this.activityListeners=[],this.inputPending=false,this.trueSince.clear(),this.clicked.clear(),this.initialValues.clear();}jumpTo(e){let n=z(this.flow,e);if(n===-1){this.finish("error",{reason:"step_not_found"});return}this.stopStep(),this.stepIndex=n,this.persist(),this.enterStep();}emitStatus(e){try{this.onStatus?.(e);}catch{}}dismiss(){this.stopped||this.finish("dismissed");}emit(e,n){try{this.track(e,{flowId:this.flow.cvid,flowSessionId:this.flowSessionId,stepCvid:this.currentStep()?.cvid},n);}catch{}}finish(e,n){this.lastStopReason=e;let r=e==="completed"?"flow_completed":e==="dismissed"?"flow_abandoned":"flow_error";this.emit(r,n);try{this.onCancelFill?.();}catch{}if(this.stopStep(),this.stopped=true,this.runState.clear(),e==="completed"&&this.emitStatus({name:this.flow.publicName??this.flow.name,step:this.flow.steps.length,total:this.flow.steps.length,phase:"done"}),this.emitStatus(null),e==="error")try{this.onFailure?.();}catch{}}stopStep(){this.teardownWatch();}fireTrigger(e){if(e.actionType==="dismiss_flow"){this.finish("dismissed");return}e.actionType==="go_to_step"&&e.targetStepCvid&&this.jumpTo(e.targetStepCvid);}parsedTrigger(e){return this.parsedTriggers.has(e.cvid)||this.parsedTriggers.set(e.cvid,mt(e.condition)),this.parsedTriggers.get(e.cvid)??null}checkTriggers(e,n){if(this.stopped||this.inputPending)return;let r=this.now();for(let o of [...e.triggers].sort((i,s)=>i.position-s.position)){let i=this.parsedTrigger(o);if(!i)continue;let s=N(i.node,n),l=o.cvid;if(!s){this.trueSince.delete(l);continue}let a=this.trueSince.get(l)??r;this.trueSince.has(l)||this.trueSince.set(l,a);let u=(o.waitSeconds??0)*1e3;if(r-a>=u){this.fireTrigger(o);return}}}scheduleCheck(e){if(this.stopped||this.throttleHandle!==null)return;let n=Math.max(0,Ee-(this.now()-this.lastCheck));this.throttleHandle=this.setTimeoutImpl(()=>{this.throttleHandle=null,this.lastCheck=this.now(),this.checkTriggers(e,this.conditionContext());},n);}startWatch(e){let n=e.triggers.some(o=>{let i=this.parsedTrigger(o);return i?j(i.node):false}),r=e.triggers.some(o=>{let i=this.parsedTrigger(o);return i?G(i.node):false});if(this.lastActivityAt=this.now(),typeof MutationObserver=="function")try{this.observer=new MutationObserver(()=>this.scheduleCheck(e)),this.observer.observe(this.doc.documentElement,{childList:!0,subtree:!0,attributes:!0,characterData:!0});}catch{}if(n)try{this.intervalHandle=this.setIntervalImpl(()=>this.scheduleCheck(e),r?Fe:_e);}catch{}if(r)for(let o of Ie){let i=()=>{this.lastActivityAt=this.now();};try{this.doc.addEventListener(o,i,{capture:!0,passive:!0}),this.activityListeners.push([o,i]);}catch{}}this.clickListener=o=>{for(let i of e.triggers){let s=this.parsedTrigger(i),l=vt(s?.node);for(let a of l){let u=g(a,this.doc);u.status==="matched"&&o.target instanceof Node&&(u.element===o.target||u.element.contains(o.target))&&this.clicked.add(a);}}this.scheduleCheck(e);};try{this.doc.addEventListener("click",this.clickListener,!0);}catch{this.clickListener=null;}for(let o of ["input","change","focusin","focusout"]){let i=()=>this.scheduleCheck(e);try{this.doc.addEventListener(o,i,!0),this.inputListeners.push([o,i]);}catch{}}this.checkTriggers(e,this.conditionContext());}async runExecutor(e){let n=this.stepIndex;try{let r=await this.executor(e,{doc:this.doc,win:this.win,resolveElement:(o,i)=>this.resolveElement(o,i),waitForElement:o=>this.waitForElement(o),setInputPending:o=>{this.inputPending=o;}});if(this.stopped||this.stepIndex!==n)return;if(r.status==="advance"){if(this.emit("flow_step_completed"),e.isCompletion){this.finish("completed");return}let o=this.stepIndex+1;if(o>=this.flow.steps.length){this.finish("completed");return}this.stopStep(),this.stepIndex=o,this.persist(),this.enterStep();return}if(r.status==="navigated"){if(this.emit("flow_step_completed"),r.navigateTarget==="new_tab"){this.finish("completed");return}if(this.stopStep(),e.isCompletion){this.finish("completed");return}let o=this.stepIndex+1;if(o>=this.flow.steps.length){this.finish("completed");return}this.stepIndex=o,this.persist();return}if(r.status==="error"){this.finish("error",r.reason==="element_not_found"?{reason:r.reason,liveManifest:lt(this.doc)}:{reason:r.reason});return}}catch{}}enterStep(){let e=this.currentStep();if(!e||this.stopped){this.finish(e?"completed":"error",e?void 0:{reason:"missing_step"});return}this.persist(),this.emit("flow_step_entered"),this.emitStatus({name:this.flow.publicName??this.flow.name,step:this.stepIndex+1,total:this.flow.steps.length,phase:"running"});let n=()=>{this.stopped||(this.startWatch(e),this.runExecutor(e));};this.waitForPageReady(n);}waitForPageReady(e){let n=this.now()+ke,r=()=>{this.dwellTimer=this.setTimeoutImpl(()=>{this.dwellTimer=null,e();},xe);},o=()=>{if(!this.stopped){if(this.doc.readyState!=="loading"||this.now()>=n){r();return}this.dwellTimer=this.setTimeoutImpl(()=>{this.dwellTimer=null,o();},J);}};o();}begin(){this.enterStep();}stop(){if(!this.stopped){try{this.onCancelFill?.();}catch{}this.stopStep(),this.stopped=true;}}};function St(t){let{context:e,executor:n=Re,track:r=e.track??Y,now:o=()=>Date.now(),setTimeoutImpl:i=(d,c)=>setTimeout(d,c),clearTimeoutImpl:s=d=>clearTimeout(d),setIntervalImpl:l=(d,c)=>setInterval(d,c),clearIntervalImpl:a=d=>clearInterval(d)}=t,u=e.doc??document,p=e.win??window,f=wt(e.token),w={apiBase:e.apiBase,sessionToken:e.sessionToken,sessionId:e.sessionId},h=null;async function D(d){let c=await gt(d,w);return c.ok?c.flow:null}function S(d,c,m,F,et={}){h?.stop(),h=new q(d,c,m,F,u,p,et.runState??f,n,e.getTrait,e.isFirstVisit,et.track??r,o,i,s,l,a),h.onStatus=Rt=>e.onStatus?.(Rt),h.onFailure=()=>e.onFailure?.(),h.onCancelFill=()=>e.cancelFill?.(),h.begin();}return {async start(d){let c=await D(d);if(!c||c.steps.length===0)return;let m=B();try{r("flow_started",{flowId:c.cvid,flowSessionId:m});}catch{}S(c,0,o(),m);},async resume(){let d=f.read();if(!d)return false;let c=await D(d.flowId);if(!c||c.steps.length===0)return f.clear(),false;let m=z(c,d.currentStepCvid);return m===-1?(f.clear(),false):(S(c,m,d.startedAt,d.flowSessionId),true)},stop(){h?.dismiss(),h=null;},async startPreview(d){let c=O(d);if(!c||c.steps.length===0)return;let m=X(e.token);S(c,0,o(),B(),{runState:yt(m,d),track:Y});},async resumePreview(){let d=X(e.token),c=d.read();if(!c)return false;let m=O(c.flow);if(!m||m.steps.length===0)return d.clear(),false;let F=z(m,c.currentStepCvid);return F===-1?(d.clear(),false):(S(m,F,c.startedAt,c.flowSessionId,{runState:yt(d,c.flow),track:Y}),true)},destroy(){h?.stop(),h=null;}}}function yt(t,e){return {read:()=>null,save:n=>t.save({...n,flow:e}),clear:()=>t.clear()}}var Ce=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Ae=/^\d{4}-\d{2}-\d{2}$/,Le=/^([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/,Me=/^\d{4}-\d{2}-\d{2}T([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/,Ne=/^\d{4}-\d{2}$/,Oe=/^\d{4}-W\d{2}$/,Pe=/^\+?[\d\s().-]{3,}$/;function De(t){let e=Date.parse(t);return Number.isFinite(e)}function He(t,e){if(e.min!==null){let n=Number(e.min);if(Number.isFinite(n)&&t<n)return "number_too_small"}if(e.max!==null){let n=Number(e.max);if(Number.isFinite(n)&&t>n)return "number_too_large"}return null}function Z(t){return /^\d:/.test(t)?`0${t}`:t}function E(t,e){return e.min!==null&&e.min.length>0&&t<e.min?"date_too_early":e.max!==null&&e.max.length>0&&t>e.max?"date_too_late":null}function bt(t,e){let n=e.kind==="password"?t:t.trim();if(n.length===0)return e.required?"required":null;if(e.maxLength!==null&&n.length>e.maxLength)return "too_long";switch(e.kind){case "number":case "range":{let r=Number(n);return Number.isFinite(r)?He(r,e):"invalid_number"}case "email":return Ce.test(n)?null:"invalid_email";case "url":try{let r=new URL(n);return r.protocol==="http:"||r.protocol==="https:"?null:"invalid_url"}catch{return "invalid_url"}case "tel":return Pe.test(n)?null:"invalid";case "date":return !Ae.test(n)||!De(n)?"invalid_date":E(n,e);case "datetime":return Me.test(n)?E(n,e):"invalid_date";case "month":return Ne.test(n)?E(n,e):"invalid_date";case "week":return Oe.test(n)?E(n,e):"invalid_date";case "time":return Le.test(n)?E(Z(n),{...e,min:e.min!==null?Z(e.min):null,max:e.max!==null?Z(e.max):null}):"invalid_time";case "select":case "radio":return (e.options??[]).some(o=>o.value===n)?null:"invalid_option";case "checkbox":return n==="true"||n==="false"?null:"invalid_option";default:{if(e.pattern)try{if(!new RegExp(`^(?:${e.pattern})$`).test(n))return "invalid"}catch{}return null}}}function Tt(t,e){if(!e||e.length===0)return t;let n=t.trim();if(e.some(i=>i.value===n))return n;let r=n.toLowerCase(),o=e.find(i=>i.label.trim().toLowerCase()===r);return o?o.value:t}var Q=24;function Ve(t,e,n){let r=e-Math.max(0,n);if(!(e>0)||r<=0)return 0;if(t.bottom>r){let o=t.bottom-r+Q,i=Math.max(0,t.top-Q);return Math.min(o,i)}return t.top<0?t.top-Q:0}function Ft(t,e,n){try{let r=n.getBottomOcclusion?.()??0,o=t.getBoundingClientRect(),i=e.doc.documentElement?.clientHeight||e.win.innerHeight||0,s=Ve(o,i,r);if(s===0)return;e.win.scrollBy({top:s,behavior:"smooth"});}catch{}}function tt(t,e){let r=e.defaultView?.PointerEvent,o=(()=>{try{return t.getBoundingClientRect()}catch{return null}})(),i={bubbles:true,cancelable:true,clientX:o?o.left+o.width/2:0,clientY:o?o.top+o.height/2:0},s=a=>{try{typeof r=="function"&&t.dispatchEvent(new r(a,{...i,pointerType:"mouse"}));}catch{}},l=a=>{try{t.dispatchEvent(new MouseEvent(a,i));}catch{}};s("pointerover"),s("pointerenter"),s("pointerdown"),l("mousedown");try{typeof t.focus=="function"&&t.focus();}catch{}s("pointerup"),l("mouseup"),l("click");}function We(t,e){let n=t instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:t instanceof HTMLInputElement?HTMLInputElement.prototype:t instanceof HTMLSelectElement?HTMLSelectElement.prototype:null;if(!n)return false;let o=Object.getOwnPropertyDescriptor(n,"value")?.set;if(!o)return false;try{return o.call(t,e),!0}catch{return false}}function P(t,e){let n=e.defaultView;try{t.dispatchEvent(new(n?.Event??Event)("input",{bubbles:!0}));}catch{}try{t.dispatchEvent(new(n?.Event??Event)("change",{bubbles:!0}));}catch{}}async function Ke(t,e,n){if(!v(t.target))return {status:"error",reason:"invalid_target"};let r=await e.waitForElement(t.target);if(r.status!=="matched"||!r.element.isConnected)return {status:"error",reason:"element_not_found"};Ft(r.element,e,n);try{tt(r.element,e.doc);}catch{return {status:"error",reason:"dispatch_failed"}}return {status:"advance"}}var $e=["text","number","email","date","url","tel"];function Et(t){return $e.includes(t)?t:null}var Be={text:"text",search:"text",number:"number",email:"email",url:"url",tel:"tel",password:"password",date:"date",time:"time","datetime-local":"datetime",month:"month",week:"week",checkbox:"checkbox",radio:"radio",range:"range"};function _(t,e){try{let n=t.getAttribute(e);return n===null||n===""?null:n}catch{return null}}function Ue(t){let e=[];for(let n=0;n<t.options.length;n+=1){let r=t.options[n];if(!r||r.disabled)continue;let o=(r.label||r.textContent||"").trim();r.value!==""&&e.push({value:r.value,label:o||r.value});}return e}function je(t,e){let n=t.getAttribute("name"),r=t.form??e,o=[];if(n)try{let i=`input[type="radio"][name="${CSS.escape(n)}"]`;r.querySelectorAll(i).forEach(s=>{s instanceof HTMLInputElement&&o.push(s);});}catch{}return o.length===0&&o.push(t),o.map(i=>({value:i.value,label:Ge(i)||i.value}))}function It(t){try{let e=t.labels;if(e&&e.length>0)return (e[0]?.textContent??"").trim()}catch{}try{let e=t.closest("label");if(e)return (e.textContent??"").trim()}catch{}return ""}function Ge(t){return It(t)}function _t(t,e,n){let r="custom",o=null,i=false,s=null,l=null,a=null,u=null,p=null;if(t instanceof HTMLSelectElement)r="select",o=Ue(t),i=t.required||!t.querySelector('option[value=""]');else if(t instanceof HTMLTextAreaElement)r="textarea",i=t.required,t.maxLength>0&&(u=t.maxLength);else if(t instanceof HTMLInputElement){let f=(_(t,"type")??"text").toLowerCase();r=Be[f]??"text",i=t.required,s=_(t,"min"),l=_(t,"max"),a=_(t,"step"),p=_(t,"pattern"),t.maxLength>0&&(u=t.maxLength),r==="radio"&&(o=je(t,n)),r==="checkbox"&&(o=[{value:"true",label:It(t)}]);}return e&&e!=="text"&&(r==="text"||r==="custom"||r==="textarea")&&(r=e),{kind:r,required:i,options:o,min:s,max:l,step:a,maxLength:u,pattern:p}}function Xe(t){if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||t instanceof HTMLElement&&t.isContentEditable)return t;try{let e=t.querySelector('input:not([type="hidden"]), textarea, select, [contenteditable="true"], [contenteditable=""]');return e instanceof HTMLElement?e:null}catch{return null}}function Je(t,e){let r=e.defaultView?.KeyboardEvent;if(typeof r=="function")for(let o of ["keydown","keyup"])try{t.dispatchEvent(new r(o,{bubbles:!0,cancelable:!0}));}catch{}}function Ye(t,e,n,r){if(n==="checkbox"&&t instanceof HTMLInputElement){let i=e==="true";return t.checked!==i&&tt(t,r),t.checked!==i&&(t.checked=i,P(t,r)),true}if(n==="radio"&&t instanceof HTMLInputElement){let i=t.form??r,s=t.getAttribute("name"),l=null;if(s)try{let p=`input[type="radio"][name="${CSS.escape(s)}"]`;i.querySelectorAll(p).forEach(f=>{f instanceof HTMLInputElement&&f.value===e&&(l=f);});}catch{}let a=l??(t.value===e?t:null);if(!a)return false;tt(a,r);let u=a;return u.checked||(u.checked=true,P(u,r)),true}let o=Xe(t);if(!o)return false;if(o instanceof HTMLElement&&o.isContentEditable){try{o.focus();}catch{}try{o.textContent=e;}catch{return false}return P(o,r),true}try{o.focus();}catch{}return We(o,e)?(Je(o,r),P(o,r),true):false}async function ze(t,e,n){if(!v(t.target))return {status:"error",reason:"invalid_target"};if(!n.promptFill)return {status:"wait"};let r=await e.waitForElement(t.target);if(r.status!=="matched"||!r.element.isConnected)return {status:"error",reason:"element_not_found"};let o=_t(r.element,Et(t.fillInputType),e.doc),i=(t.fillDescription??"").trim()||t.label||"",s=null,l=null,a;for(;;){let f;e.setInputPending(true);try{f=await n.promptFill({...o,question:i,errorCode:s});}catch{return {status:"error",reason:"prompt_failed"}}finally{e.setInputPending(false);}if(f===null)return {status:"error",reason:"fill_cancelled"};let w=o.kind==="select"||o.kind==="radio"?Tt(f,o.options):o.kind==="password"?f:f.trim();if(s=bt(w,{...o,question:i,errorCode:null}),s===null){a=w;break}if(l!==null&&l===w)return {status:"error",reason:"fill_invalid"};l=w;}let u=await e.waitForElement(t.target);if(u.status!=="matched"||!u.element.isConnected)return {status:"error",reason:"element_not_found"};let p=_t(u.element,Et(t.fillInputType),e.doc);return p.kind!==o.kind?{status:"error",reason:"unfillable_target"}:(Ft(u.element,e,n),Ye(u.element,a,p.kind,e.doc)?{status:"advance"}:{status:"error",reason:"unfillable_target"})}function qe(t){if(t.startsWith("/")&&!t.startsWith("//"))return true;try{let e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return false}}async function Ze(t,e){if(!t.navigateUrl||!t.navigateTarget)return {status:"error",reason:"invalid_navigate_step"};if(!qe(t.navigateUrl))return {status:"error",reason:"invalid_navigate_step"};try{t.navigateTarget==="new_tab"?e.win.open(t.navigateUrl,"_blank","noopener,noreferrer"):e.win.location.assign(t.navigateUrl);}catch{return {status:"error",reason:"navigate_failed"}}return {status:"navigated",navigateTarget:t.navigateTarget}}function kt(t={}){return async(e,n)=>{try{switch(e.type){case "click":return await Ke(e,n,t);case "fill":return await ze(e,n,t);case "navigate":return await Ze(e,n);default:return {status:"error",reason:"unknown_step_type"}}}catch{return {status:"error",reason:"executor_threw"}}}}var xt="__arcyFlow";function tn(t){try{let e=kt({promptFill:t.promptFill,getBottomOcclusion:t.getBottomOcclusion});return St({context:t,executor:e})}catch{return null}}var en={contract:2,mount:tn};if(typeof window<"u")try{window[xt]=en;}catch{}
3
- })();