@ai11y/core 0.0.1

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.
Files changed (107) hide show
  1. package/.turbo/turbo-build.log +87 -0
  2. package/CHANGELOG.md +29 -0
  3. package/README.md +37 -0
  4. package/dist/agent/agent-adapter.d.mts +17 -0
  5. package/dist/agent/agent-adapter.d.mts.map +1 -0
  6. package/dist/agent/agent-adapter.mjs +45 -0
  7. package/dist/agent/agent-adapter.mjs.map +1 -0
  8. package/dist/agent/llm-agent.d.mts +13 -0
  9. package/dist/agent/llm-agent.d.mts.map +1 -0
  10. package/dist/agent/llm-agent.mjs +41 -0
  11. package/dist/agent/llm-agent.mjs.map +1 -0
  12. package/dist/agent/plan.d.mts +27 -0
  13. package/dist/agent/plan.d.mts.map +1 -0
  14. package/dist/agent/plan.mjs +28 -0
  15. package/dist/agent/plan.mjs.map +1 -0
  16. package/dist/agent/rule-based-agent.d.mts +13 -0
  17. package/dist/agent/rule-based-agent.d.mts.map +1 -0
  18. package/dist/agent/rule-based-agent.mjs +152 -0
  19. package/dist/agent/rule-based-agent.mjs.map +1 -0
  20. package/dist/agent/tool-contract.d.mts +19 -0
  21. package/dist/agent/tool-contract.d.mts.map +1 -0
  22. package/dist/agent/types.d.mts +77 -0
  23. package/dist/agent/types.d.mts.map +1 -0
  24. package/dist/client-api.d.mts +49 -0
  25. package/dist/client-api.d.mts.map +1 -0
  26. package/dist/client-api.mjs +68 -0
  27. package/dist/client-api.mjs.map +1 -0
  28. package/dist/context.d.mts +29 -0
  29. package/dist/context.d.mts.map +1 -0
  30. package/dist/dom-actions/click.d.mts +15 -0
  31. package/dist/dom-actions/click.d.mts.map +1 -0
  32. package/dist/dom-actions/click.mjs +36 -0
  33. package/dist/dom-actions/click.mjs.map +1 -0
  34. package/dist/dom-actions/fill-input.d.mts +17 -0
  35. package/dist/dom-actions/fill-input.d.mts.map +1 -0
  36. package/dist/dom-actions/fill-input.mjs +69 -0
  37. package/dist/dom-actions/fill-input.mjs.map +1 -0
  38. package/dist/dom-actions/find-element.mjs +17 -0
  39. package/dist/dom-actions/find-element.mjs.map +1 -0
  40. package/dist/dom-actions/highlight.d.mts +34 -0
  41. package/dist/dom-actions/highlight.d.mts.map +1 -0
  42. package/dist/dom-actions/highlight.mjs +60 -0
  43. package/dist/dom-actions/highlight.mjs.map +1 -0
  44. package/dist/dom-actions/navigate.d.mts +16 -0
  45. package/dist/dom-actions/navigate.d.mts.map +1 -0
  46. package/dist/dom-actions/navigate.mjs +22 -0
  47. package/dist/dom-actions/navigate.mjs.map +1 -0
  48. package/dist/dom-actions/scroll.d.mts +16 -0
  49. package/dist/dom-actions/scroll.d.mts.map +1 -0
  50. package/dist/dom-actions/scroll.mjs +32 -0
  51. package/dist/dom-actions/scroll.mjs.map +1 -0
  52. package/dist/dom.d.mts +23 -0
  53. package/dist/dom.d.mts.map +1 -0
  54. package/dist/dom.mjs +60 -0
  55. package/dist/dom.mjs.map +1 -0
  56. package/dist/events.d.mts +35 -0
  57. package/dist/events.d.mts.map +1 -0
  58. package/dist/events.mjs +49 -0
  59. package/dist/events.mjs.map +1 -0
  60. package/dist/index.d.mts +21 -0
  61. package/dist/index.mjs +18 -0
  62. package/dist/instruction.d.mts +21 -0
  63. package/dist/instruction.d.mts.map +1 -0
  64. package/dist/marker.d.mts +35 -0
  65. package/dist/marker.d.mts.map +1 -0
  66. package/dist/marker.mjs +137 -0
  67. package/dist/marker.mjs.map +1 -0
  68. package/dist/store.d.mts +56 -0
  69. package/dist/store.d.mts.map +1 -0
  70. package/dist/store.mjs +114 -0
  71. package/dist/store.mjs.map +1 -0
  72. package/dist/util/attributes.d.mts +57 -0
  73. package/dist/util/attributes.d.mts.map +1 -0
  74. package/dist/util/attributes.mjs +68 -0
  75. package/dist/util/attributes.mjs.map +1 -0
  76. package/dist/util/format.d.mts +18 -0
  77. package/dist/util/format.d.mts.map +1 -0
  78. package/dist/util/format.mjs +21 -0
  79. package/dist/util/format.mjs.map +1 -0
  80. package/package.json +26 -0
  81. package/src/agent/agent-adapter.ts +75 -0
  82. package/src/agent/index.ts +21 -0
  83. package/src/agent/llm-agent.ts +64 -0
  84. package/src/agent/plan.ts +41 -0
  85. package/src/agent/rule-based-agent.ts +269 -0
  86. package/src/agent/tool-contract.ts +22 -0
  87. package/src/agent/types.ts +83 -0
  88. package/src/client-api.ts +107 -0
  89. package/src/context.ts +28 -0
  90. package/src/dom-actions/click.ts +39 -0
  91. package/src/dom-actions/fill-input.ts +113 -0
  92. package/src/dom-actions/find-element.ts +14 -0
  93. package/src/dom-actions/highlight.ts +93 -0
  94. package/src/dom-actions/index.ts +5 -0
  95. package/src/dom-actions/navigate.ts +17 -0
  96. package/src/dom-actions/scroll.ts +29 -0
  97. package/src/dom.ts +89 -0
  98. package/src/events.ts +55 -0
  99. package/src/index.ts +55 -0
  100. package/src/instruction.ts +6 -0
  101. package/src/marker.ts +237 -0
  102. package/src/store.ts +138 -0
  103. package/src/util/attributes.ts +68 -0
  104. package/src/util/format.ts +16 -0
  105. package/src/util/index.ts +2 -0
  106. package/tsconfig.json +18 -0
  107. package/tsdown.config.ts +10 -0
package/dist/dom.d.mts ADDED
@@ -0,0 +1,23 @@
1
+ import { Ai11yContext } from "./context.mjs";
2
+
3
+ //#region src/dom.d.ts
4
+
5
+ /**
6
+ * Composes a complete Ai11yContext from singleton state and DOM markers
7
+ *
8
+ * @param root - Optional DOM root element to scan for markers (defaults to document.body)
9
+ * @returns A complete Ai11yContext object with markers from DOM and state from singleton
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { setRoute, setState, getContext } from '@ai11y/core';
14
+ *
15
+ * setRoute('/billing');
16
+ * setState({ userId: '123' });
17
+ * const context = getContext();
18
+ * ```
19
+ */
20
+ declare function getContext(root?: Element): Ai11yContext;
21
+ //#endregion
22
+ export { getContext };
23
+ //# sourceMappingURL=dom.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom.d.mts","names":[],"sources":["../src/dom.ts"],"sourcesContent":[],"mappings":";;;;;;AAmEA;;;;;;;;;;;;;iBAAgB,UAAA,QAAkB,UAAU"}
package/dist/dom.mjs ADDED
@@ -0,0 +1,60 @@
1
+ import { getAllMarkersSelector, getMarkerId } from "./util/attributes.mjs";
2
+ import { getMarkers } from "./marker.mjs";
3
+ import { getError, getRoute, getState } from "./store.mjs";
4
+
5
+ //#region src/dom.ts
6
+ /**
7
+ * Detects which markers are currently visible in the viewport
8
+ *
9
+ * @param root - Optional DOM root element to scan for markers (defaults to document.body)
10
+ * @returns Array of marker IDs that are currently in view
11
+ */
12
+ function getInViewMarkerIds(root) {
13
+ if (typeof document === "undefined" || typeof window === "undefined") return [];
14
+ const scanRoot = root ?? document.body;
15
+ if (!scanRoot) return [];
16
+ const elements = scanRoot.querySelectorAll(getAllMarkersSelector());
17
+ const inViewIds = [];
18
+ for (let i = 0; i < elements.length; i++) {
19
+ const element = elements[i];
20
+ const id = getMarkerId(element);
21
+ if (!id) continue;
22
+ const rect = element.getBoundingClientRect();
23
+ const isInView = rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
24
+ const isPartiallyVisible = rect.top < (window.innerHeight || document.documentElement.clientHeight) && rect.bottom > 0 && rect.left < (window.innerWidth || document.documentElement.clientWidth) && rect.right > 0;
25
+ if (isInView || isPartiallyVisible) inViewIds.push(id);
26
+ }
27
+ return inViewIds;
28
+ }
29
+ /**
30
+ * Composes a complete Ai11yContext from singleton state and DOM markers
31
+ *
32
+ * @param root - Optional DOM root element to scan for markers (defaults to document.body)
33
+ * @returns A complete Ai11yContext object with markers from DOM and state from singleton
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { setRoute, setState, getContext } from '@ai11y/core';
38
+ *
39
+ * setRoute('/billing');
40
+ * setState({ userId: '123' });
41
+ * const context = getContext();
42
+ * ```
43
+ */
44
+ function getContext(root) {
45
+ const context = {
46
+ markers: getMarkers(root),
47
+ inViewMarkerIds: getInViewMarkerIds(root)
48
+ };
49
+ const route = getRoute();
50
+ const state = getState();
51
+ const error = getError();
52
+ if (route !== void 0) context.route = route;
53
+ if (state !== void 0) context.state = state;
54
+ if (error !== void 0) context.error = error;
55
+ return context;
56
+ }
57
+
58
+ //#endregion
59
+ export { getContext };
60
+ //# sourceMappingURL=dom.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom.mjs","names":["inViewIds: string[]","context: Ai11yContext"],"sources":["../src/dom.ts"],"sourcesContent":["import type { Ai11yContext } from \"./context.js\";\nimport { getMarkers } from \"./marker.js\";\nimport { getError, getRoute, getState } from \"./store.js\";\nimport { getAllMarkersSelector, getMarkerId } from \"./util/attributes.js\";\n\n/**\n * Detects which markers are currently visible in the viewport\n *\n * @param root - Optional DOM root element to scan for markers (defaults to document.body)\n * @returns Array of marker IDs that are currently in view\n */\nfunction getInViewMarkerIds(root?: Element): string[] {\n\tif (typeof document === \"undefined\" || typeof window === \"undefined\") {\n\t\treturn [];\n\t}\n\n\tconst scanRoot = root ?? document.body;\n\tif (!scanRoot) {\n\t\treturn [];\n\t}\n\n\tconst elements = scanRoot.querySelectorAll(getAllMarkersSelector());\n\tconst inViewIds: string[] = [];\n\n\tfor (let i = 0; i < elements.length; i++) {\n\t\tconst element = elements[i];\n\t\tconst id = getMarkerId(element);\n\t\tif (!id) continue;\n\n\t\tconst rect = element.getBoundingClientRect();\n\t\tconst isInView =\n\t\t\trect.top >= 0 &&\n\t\t\trect.left >= 0 &&\n\t\t\trect.bottom <=\n\t\t\t\t(window.innerHeight || document.documentElement.clientHeight) &&\n\t\t\trect.right <= (window.innerWidth || document.documentElement.clientWidth);\n\n\t\tconst isPartiallyVisible =\n\t\t\trect.top <\n\t\t\t\t(window.innerHeight || document.documentElement.clientHeight) &&\n\t\t\trect.bottom > 0 &&\n\t\t\trect.left < (window.innerWidth || document.documentElement.clientWidth) &&\n\t\t\trect.right > 0;\n\n\t\tif (isInView || isPartiallyVisible) {\n\t\t\tinViewIds.push(id);\n\t\t}\n\t}\n\n\treturn inViewIds;\n}\n\n/**\n * Composes a complete Ai11yContext from singleton state and DOM markers\n *\n * @param root - Optional DOM root element to scan for markers (defaults to document.body)\n * @returns A complete Ai11yContext object with markers from DOM and state from singleton\n *\n * @example\n * ```ts\n * import { setRoute, setState, getContext } from '@ai11y/core';\n *\n * setRoute('/billing');\n * setState({ userId: '123' });\n * const context = getContext();\n * ```\n */\nexport function getContext(root?: Element): Ai11yContext {\n\tconst context: Ai11yContext = {\n\t\tmarkers: getMarkers(root),\n\t\tinViewMarkerIds: getInViewMarkerIds(root),\n\t};\n\n\tconst route = getRoute();\n\tconst state = getState();\n\tconst error = getError();\n\n\tif (route !== undefined) {\n\t\tcontext.route = route;\n\t}\n\tif (state !== undefined) {\n\t\tcontext.state = state;\n\t}\n\tif (error !== undefined) {\n\t\tcontext.error = error;\n\t}\n\n\treturn context;\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAS,mBAAmB,MAA0B;AACrD,KAAI,OAAO,aAAa,eAAe,OAAO,WAAW,YACxD,QAAO,EAAE;CAGV,MAAM,WAAW,QAAQ,SAAS;AAClC,KAAI,CAAC,SACJ,QAAO,EAAE;CAGV,MAAM,WAAW,SAAS,iBAAiB,uBAAuB,CAAC;CACnE,MAAMA,YAAsB,EAAE;AAE9B,MAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;EACzC,MAAM,UAAU,SAAS;EACzB,MAAM,KAAK,YAAY,QAAQ;AAC/B,MAAI,CAAC,GAAI;EAET,MAAM,OAAO,QAAQ,uBAAuB;EAC5C,MAAM,WACL,KAAK,OAAO,KACZ,KAAK,QAAQ,KACb,KAAK,WACH,OAAO,eAAe,SAAS,gBAAgB,iBACjD,KAAK,UAAU,OAAO,cAAc,SAAS,gBAAgB;EAE9D,MAAM,qBACL,KAAK,OACH,OAAO,eAAe,SAAS,gBAAgB,iBACjD,KAAK,SAAS,KACd,KAAK,QAAQ,OAAO,cAAc,SAAS,gBAAgB,gBAC3D,KAAK,QAAQ;AAEd,MAAI,YAAY,mBACf,WAAU,KAAK,GAAG;;AAIpB,QAAO;;;;;;;;;;;;;;;;;AAkBR,SAAgB,WAAW,MAA8B;CACxD,MAAMC,UAAwB;EAC7B,SAAS,WAAW,KAAK;EACzB,iBAAiB,mBAAmB,KAAK;EACzC;CAED,MAAM,QAAQ,UAAU;CACxB,MAAM,QAAQ,UAAU;CACxB,MAAM,QAAQ,UAAU;AAExB,KAAI,UAAU,OACb,SAAQ,QAAQ;AAEjB,KAAI,UAAU,OACb,SAAQ,QAAQ;AAEjB,KAAI,UAAU,OACb,SAAQ,QAAQ;AAGjB,QAAO"}
@@ -0,0 +1,35 @@
1
+ //#region src/events.d.ts
2
+ /**
3
+ * Event listener function type
4
+ */
5
+ type EventListener = () => void;
6
+ /**
7
+ * Subscribe to event notifications
8
+ * Returns an unsubscribe function
9
+ *
10
+ * @param listener - Function to call when events are tracked
11
+ * @returns Unsubscribe function
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const unsubscribe = subscribe(() => {
16
+ * console.log('Event tracked!');
17
+ * });
18
+ * // Later...
19
+ * unsubscribe();
20
+ * ```
21
+ */
22
+ declare function subscribe(listener: EventListener): () => void;
23
+ /**
24
+ * Notify all subscribers that an event has been tracked
25
+ * This is called internally by the store when track() is called
26
+ */
27
+ declare function notify(): void;
28
+ /**
29
+ * Get the number of active subscribers
30
+ * Useful for debugging
31
+ */
32
+ declare function getSubscriberCount(): number;
33
+ //#endregion
34
+ export { getSubscriberCount, notify, subscribe };
35
+ //# sourceMappingURL=events.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.mts","names":[],"sources":["../src/events.ts"],"sourcesContent":[],"mappings":";;;AA0BA;AAWA,KAlCK,aAAA,GAkCiB,GAAA,GAAA,IAAA;AAetB;;;;;;;;;;;;;;;;iBA1BgB,SAAA,WAAoB;;;;;iBAWpB,MAAA,CAAA;;;;;iBAeA,kBAAA,CAAA"}
@@ -0,0 +1,49 @@
1
+ //#region src/events.ts
2
+ /**
3
+ * Set of event listeners
4
+ */
5
+ const listeners = /* @__PURE__ */ new Set();
6
+ /**
7
+ * Subscribe to event notifications
8
+ * Returns an unsubscribe function
9
+ *
10
+ * @param listener - Function to call when events are tracked
11
+ * @returns Unsubscribe function
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const unsubscribe = subscribe(() => {
16
+ * console.log('Event tracked!');
17
+ * });
18
+ * // Later...
19
+ * unsubscribe();
20
+ * ```
21
+ */
22
+ function subscribe(listener) {
23
+ listeners.add(listener);
24
+ return () => {
25
+ listeners.delete(listener);
26
+ };
27
+ }
28
+ /**
29
+ * Notify all subscribers that an event has been tracked
30
+ * This is called internally by the store when track() is called
31
+ */
32
+ function notify() {
33
+ for (const listener of listeners) try {
34
+ listener();
35
+ } catch (error) {
36
+ console.error("Error in event listener:", error);
37
+ }
38
+ }
39
+ /**
40
+ * Get the number of active subscribers
41
+ * Useful for debugging
42
+ */
43
+ function getSubscriberCount() {
44
+ return listeners.size;
45
+ }
46
+
47
+ //#endregion
48
+ export { getSubscriberCount, notify, subscribe };
49
+ //# sourceMappingURL=events.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.mjs","names":[],"sources":["../src/events.ts"],"sourcesContent":["/**\n * Event listener function type\n */\ntype EventListener = () => void;\n\n/**\n * Set of event listeners\n */\nconst listeners = new Set<EventListener>();\n\n/**\n * Subscribe to event notifications\n * Returns an unsubscribe function\n *\n * @param listener - Function to call when events are tracked\n * @returns Unsubscribe function\n *\n * @example\n * ```ts\n * const unsubscribe = subscribe(() => {\n * console.log('Event tracked!');\n * });\n * // Later...\n * unsubscribe();\n * ```\n */\nexport function subscribe(listener: EventListener): () => void {\n\tlisteners.add(listener);\n\treturn () => {\n\t\tlisteners.delete(listener);\n\t};\n}\n\n/**\n * Notify all subscribers that an event has been tracked\n * This is called internally by the store when track() is called\n */\nexport function notify(): void {\n\tfor (const listener of listeners) {\n\t\ttry {\n\t\t\tlistener();\n\t\t} catch (error) {\n\t\t\t// Don't let one listener's error break others\n\t\t\tconsole.error(\"Error in event listener:\", error);\n\t\t}\n\t}\n}\n\n/**\n * Get the number of active subscribers\n * Useful for debugging\n */\nexport function getSubscriberCount(): number {\n\treturn listeners.size;\n}\n"],"mappings":";;;;AAQA,MAAM,4BAAY,IAAI,KAAoB;;;;;;;;;;;;;;;;;AAkB1C,SAAgB,UAAU,UAAqC;AAC9D,WAAU,IAAI,SAAS;AACvB,cAAa;AACZ,YAAU,OAAO,SAAS;;;;;;;AAQ5B,SAAgB,SAAe;AAC9B,MAAK,MAAM,YAAY,UACtB,KAAI;AACH,YAAU;UACF,OAAO;AAEf,UAAQ,MAAM,4BAA4B,MAAM;;;;;;;AASnD,SAAgB,qBAA6B;AAC5C,QAAO,UAAU"}
@@ -0,0 +1,21 @@
1
+ import { Marker, getMarkers } from "./marker.mjs";
2
+ import { Ai11yContext, Ai11yError, Ai11yEvent, Ai11yState } from "./context.mjs";
3
+ import { Instruction } from "./instruction.mjs";
4
+ import { AgentAdapterConfig, AgentConfig, AgentMode, AgentRequest, AgentResponse, ConversationMessage, LLMAgentConfig } from "./agent/types.mjs";
5
+ import { runAgentAdapter } from "./agent/agent-adapter.mjs";
6
+ import { runLLMAgent } from "./agent/llm-agent.mjs";
7
+ import { runRuleBasedAgent } from "./agent/rule-based-agent.mjs";
8
+ import { plan } from "./agent/plan.mjs";
9
+ import { ToolDefinition, ToolExecutor } from "./agent/tool-contract.mjs";
10
+ import { Ai11yClient, createClient } from "./client-api.mjs";
11
+ import { getContext } from "./dom.mjs";
12
+ import { clickMarker } from "./dom-actions/click.mjs";
13
+ import { fillInputMarker } from "./dom-actions/fill-input.mjs";
14
+ import { HighlightOptions, highlightMarker } from "./dom-actions/highlight.mjs";
15
+ import { navigateToRoute } from "./dom-actions/navigate.mjs";
16
+ import { scrollToMarker } from "./dom-actions/scroll.mjs";
17
+ import { getSubscriberCount, notify, subscribe } from "./events.mjs";
18
+ import { clearContext, clearEvents, clearState, getError, getEvents, getRoute, getState, setError, setRoute, setState, subscribeToStore, track } from "./store.mjs";
19
+ import { ATTRIBUTE_ID, ATTRIBUTE_INTENT, ATTRIBUTE_LABEL, ATTRIBUTE_SENSITIVE, getAllMarkersSelector, getMarkerId, getMarkerIntent, getMarkerLabel, getMarkerSelector } from "./util/attributes.mjs";
20
+ import { formatMarkerId } from "./util/format.mjs";
21
+ export { ATTRIBUTE_ID, ATTRIBUTE_INTENT, ATTRIBUTE_LABEL, ATTRIBUTE_SENSITIVE, type AgentAdapterConfig, type AgentConfig, type AgentMode, type AgentRequest, type AgentResponse, type Ai11yClient, type Ai11yContext, type Ai11yError, type Ai11yEvent, type Ai11yState, type ConversationMessage, type HighlightOptions, type Instruction, type LLMAgentConfig, type Marker, type ToolDefinition, type ToolExecutor, clearContext, clearEvents, clearState, clickMarker, createClient, fillInputMarker, formatMarkerId, getAllMarkersSelector, getContext, getError, getEvents, getMarkerId, getMarkerIntent, getMarkerLabel, getMarkerSelector, getMarkers, getRoute, getState, getSubscriberCount, highlightMarker, navigateToRoute, notify, plan, runAgentAdapter, runLLMAgent, runRuleBasedAgent, scrollToMarker, setError, setRoute, setState, subscribe, subscribeToStore, track };
package/dist/index.mjs ADDED
@@ -0,0 +1,18 @@
1
+ import { runLLMAgent } from "./agent/llm-agent.mjs";
2
+ import { runRuleBasedAgent } from "./agent/rule-based-agent.mjs";
3
+ import { runAgentAdapter } from "./agent/agent-adapter.mjs";
4
+ import { plan } from "./agent/plan.mjs";
5
+ import { ATTRIBUTE_ID, ATTRIBUTE_INTENT, ATTRIBUTE_LABEL, ATTRIBUTE_SENSITIVE, getAllMarkersSelector, getMarkerId, getMarkerIntent, getMarkerLabel, getMarkerSelector } from "./util/attributes.mjs";
6
+ import { formatMarkerId } from "./util/format.mjs";
7
+ import { getMarkers } from "./marker.mjs";
8
+ import { getSubscriberCount, notify, subscribe } from "./events.mjs";
9
+ import { clearContext, clearEvents, clearState, getError, getEvents, getRoute, getState, setError, setRoute, setState, subscribeToStore, track } from "./store.mjs";
10
+ import { getContext } from "./dom.mjs";
11
+ import { clickMarker } from "./dom-actions/click.mjs";
12
+ import { fillInputMarker } from "./dom-actions/fill-input.mjs";
13
+ import { highlightMarker } from "./dom-actions/highlight.mjs";
14
+ import { navigateToRoute } from "./dom-actions/navigate.mjs";
15
+ import { scrollToMarker } from "./dom-actions/scroll.mjs";
16
+ import { createClient } from "./client-api.mjs";
17
+
18
+ export { ATTRIBUTE_ID, ATTRIBUTE_INTENT, ATTRIBUTE_LABEL, ATTRIBUTE_SENSITIVE, clearContext, clearEvents, clearState, clickMarker, createClient, fillInputMarker, formatMarkerId, getAllMarkersSelector, getContext, getError, getEvents, getMarkerId, getMarkerIntent, getMarkerLabel, getMarkerSelector, getMarkers, getRoute, getState, getSubscriberCount, highlightMarker, navigateToRoute, notify, plan, runAgentAdapter, runLLMAgent, runRuleBasedAgent, scrollToMarker, setError, setRoute, setState, subscribe, subscribeToStore, track };
@@ -0,0 +1,21 @@
1
+ //#region src/instruction.d.ts
2
+ type Instruction = {
3
+ action: "click";
4
+ id: string;
5
+ } | {
6
+ action: "navigate";
7
+ route: string;
8
+ } | {
9
+ action: "highlight";
10
+ id: string;
11
+ } | {
12
+ action: "scroll";
13
+ id: string;
14
+ } | {
15
+ action: "fillInput";
16
+ id: string;
17
+ value: string;
18
+ };
19
+ //#endregion
20
+ export { Instruction };
21
+ //# sourceMappingURL=instruction.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instruction.d.mts","names":[],"sources":["../src/instruction.ts"],"sourcesContent":[],"mappings":";KAAY,WAAA;EAAA,MAAA,EAAA,OAAW"}
@@ -0,0 +1,35 @@
1
+ //#region src/marker.d.ts
2
+ /**
3
+ * Marker information for UI elements
4
+ */
5
+ interface Marker {
6
+ id: string;
7
+ label: string;
8
+ intent: string;
9
+ elementType: string;
10
+ /** Current value for input/textarea elements */
11
+ value?: string;
12
+ /** Selected value(s) for select elements */
13
+ selectedOptions?: string[];
14
+ /** All available options for select elements */
15
+ options?: Array<{
16
+ value: string;
17
+ label: string;
18
+ }>;
19
+ }
20
+ /**
21
+ * Scans the DOM for elements with data-ai-* attributes and returns markers
22
+ *
23
+ * @param root - Optional DOM root element to scan (defaults to document.body)
24
+ * @returns Array of Marker objects found in the DOM
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const markers = getMarkers();
29
+ * // Scans document.body for data-ai-* attributes
30
+ * ```
31
+ */
32
+ declare function getMarkers(root?: Element): Marker[];
33
+ //#endregion
34
+ export { Marker, getMarkers };
35
+ //# sourceMappingURL=marker.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marker.d.mts","names":[],"sources":["../src/marker.ts"],"sourcesContent":[],"mappings":";;AAYA;AAsLA;UAtLiB,MAAA;;;;;;;;;;YAUN;;;;;;;;;;;;;;;;;iBA4KK,UAAA,QAAkB,UAAU"}
@@ -0,0 +1,137 @@
1
+ import { ATTRIBUTE_SENSITIVE, getAllMarkersSelector, getMarkerId, getMarkerIntent, getMarkerLabel } from "./util/attributes.mjs";
2
+ import { formatMarkerId } from "./util/format.mjs";
3
+
4
+ //#region src/marker.ts
5
+ /**
6
+ * Gets the document body in a type-safe way
7
+ * Returns null if not in a browser environment
8
+ */
9
+ function getDocumentBody() {
10
+ if (typeof document === "undefined") return null;
11
+ return document.body;
12
+ }
13
+ /**
14
+ * Finds an input or textarea element within a marked element
15
+ * Handles both direct input elements and nested inputs (when Mark wraps the input)
16
+ */
17
+ function findInputElement(element) {
18
+ if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement) return element;
19
+ if (element instanceof HTMLElement) {
20
+ const nestedInput = element.querySelector("input, textarea");
21
+ if (nestedInput instanceof HTMLInputElement || nestedInput instanceof HTMLTextAreaElement) return nestedInput;
22
+ }
23
+ return null;
24
+ }
25
+ /**
26
+ * Finds a select element within a marked element
27
+ * Handles both direct select elements and nested selects (when Mark wraps the select)
28
+ */
29
+ function findSelectElement(element) {
30
+ if (element instanceof HTMLSelectElement) return element;
31
+ if (element instanceof HTMLElement) {
32
+ const nestedSelect = element.querySelector("select");
33
+ if (nestedSelect instanceof HTMLSelectElement) return nestedSelect;
34
+ }
35
+ return null;
36
+ }
37
+ /**
38
+ * Checks if an input element contains sensitive data that should be redacted
39
+ * from the UI context (passwords, credit cards, hidden fields, etc.)
40
+ *
41
+ * @param inputElement - The input or textarea element to check
42
+ * @returns True if the input contains sensitive data
43
+ */
44
+ function isSensitiveInput(inputElement) {
45
+ if (inputElement instanceof HTMLInputElement) {
46
+ const type = inputElement.type.toLowerCase();
47
+ if (type === "password" || type === "hidden") return true;
48
+ }
49
+ const autocomplete = inputElement.getAttribute("autocomplete")?.toLowerCase();
50
+ if (autocomplete) {
51
+ if ([
52
+ "current-password",
53
+ "new-password",
54
+ "cc-number",
55
+ "cc-csc",
56
+ "cc-exp",
57
+ "cc-exp-month",
58
+ "cc-exp-year"
59
+ ].some((path) => autocomplete.includes(path))) return true;
60
+ }
61
+ if (inputElement.getAttribute(ATTRIBUTE_SENSITIVE) === "true") return true;
62
+ const parent = inputElement.parentElement;
63
+ if (parent && parent.getAttribute(ATTRIBUTE_SENSITIVE) === "true") return true;
64
+ return false;
65
+ }
66
+ /**
67
+ * Extracts the value from an input or textarea element
68
+ * Redacts sensitive values (passwords, credit cards, etc.) for privacy
69
+ */
70
+ function extractInputValue(element) {
71
+ const inputElement = findInputElement(element);
72
+ if (!inputElement) return;
73
+ if (isSensitiveInput(inputElement)) return "[REDACTED]";
74
+ return inputElement.value;
75
+ }
76
+ /**
77
+ * Extracts options and selected values from a select element
78
+ */
79
+ function extractSelectData(element) {
80
+ const selectElement = findSelectElement(element);
81
+ if (!selectElement) return {};
82
+ const options = [];
83
+ for (let i = 0; i < selectElement.options.length; i++) {
84
+ const option = selectElement.options[i];
85
+ options.push({
86
+ value: option.value,
87
+ label: option.text
88
+ });
89
+ }
90
+ const selectedOptions = [];
91
+ if (selectElement.multiple) for (let i = 0; i < selectElement.selectedOptions.length; i++) selectedOptions.push(selectElement.selectedOptions[i].value);
92
+ else if (selectElement.value) selectedOptions.push(selectElement.value);
93
+ return {
94
+ options: options.length > 0 ? options : void 0,
95
+ selectedOptions: selectedOptions.length > 0 ? selectedOptions : void 0
96
+ };
97
+ }
98
+ /**
99
+ * Scans the DOM for elements with data-ai-* attributes and returns markers
100
+ *
101
+ * @param root - Optional DOM root element to scan (defaults to document.body)
102
+ * @returns Array of Marker objects found in the DOM
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * const markers = getMarkers();
107
+ * // Scans document.body for data-ai-* attributes
108
+ * ```
109
+ */
110
+ function getMarkers(root) {
111
+ const scanRoot = root ?? getDocumentBody();
112
+ if (!scanRoot) return [];
113
+ const elements = scanRoot.querySelectorAll(getAllMarkersSelector());
114
+ const markers = [];
115
+ for (let i = 0; i < elements.length; i++) {
116
+ const element = elements[i];
117
+ const id = getMarkerId(element);
118
+ if (!id) continue;
119
+ const marker = {
120
+ id,
121
+ label: getMarkerLabel(element) || formatMarkerId(id),
122
+ intent: getMarkerIntent(element) || "",
123
+ elementType: element.tagName.toLowerCase()
124
+ };
125
+ const inputValue = extractInputValue(element);
126
+ if (inputValue !== void 0) marker.value = inputValue;
127
+ const selectData = extractSelectData(element);
128
+ if (selectData.options !== void 0) marker.options = selectData.options;
129
+ if (selectData.selectedOptions !== void 0) marker.selectedOptions = selectData.selectedOptions;
130
+ markers.push(marker);
131
+ }
132
+ return markers;
133
+ }
134
+
135
+ //#endregion
136
+ export { getMarkers };
137
+ //# sourceMappingURL=marker.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marker.mjs","names":["options: Array<{ value: string; label: string }>","selectedOptions: string[]","markers: Marker[]","marker: Marker"],"sources":["../src/marker.ts"],"sourcesContent":["import {\n\tATTRIBUTE_SENSITIVE,\n\tgetAllMarkersSelector,\n\tgetMarkerId,\n\tgetMarkerIntent,\n\tgetMarkerLabel,\n} from \"./util/attributes.js\";\nimport { formatMarkerId } from \"./util/format.js\";\n\n/**\n * Marker information for UI elements\n */\nexport interface Marker {\n\tid: string;\n\tlabel: string;\n\tintent: string;\n\telementType: string;\n\t/** Current value for input/textarea elements */\n\tvalue?: string;\n\t/** Selected value(s) for select elements */\n\tselectedOptions?: string[];\n\t/** All available options for select elements */\n\toptions?: Array<{ value: string; label: string }>;\n}\n\n/**\n * Gets the document body in a type-safe way\n * Returns null if not in a browser environment\n */\nfunction getDocumentBody(): Element | null {\n\tif (typeof document === \"undefined\") {\n\t\treturn null;\n\t}\n\treturn document.body;\n}\n\n/**\n * Finds an input or textarea element within a marked element\n * Handles both direct input elements and nested inputs (when Mark wraps the input)\n */\nfunction findInputElement(\n\telement: Element,\n): HTMLInputElement | HTMLTextAreaElement | null {\n\tif (\n\t\telement instanceof HTMLInputElement ||\n\t\telement instanceof HTMLTextAreaElement\n\t) {\n\t\treturn element;\n\t}\n\tif (element instanceof HTMLElement) {\n\t\tconst nestedInput = element.querySelector(\"input, textarea\");\n\t\tif (\n\t\t\tnestedInput instanceof HTMLInputElement ||\n\t\t\tnestedInput instanceof HTMLTextAreaElement\n\t\t) {\n\t\t\treturn nestedInput;\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n * Finds a select element within a marked element\n * Handles both direct select elements and nested selects (when Mark wraps the select)\n */\nfunction findSelectElement(element: Element): HTMLSelectElement | null {\n\tif (element instanceof HTMLSelectElement) {\n\t\treturn element;\n\t}\n\tif (element instanceof HTMLElement) {\n\t\tconst nestedSelect = element.querySelector(\"select\");\n\t\tif (nestedSelect instanceof HTMLSelectElement) {\n\t\t\treturn nestedSelect;\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n * Checks if an input element contains sensitive data that should be redacted\n * from the UI context (passwords, credit cards, hidden fields, etc.)\n *\n * @param inputElement - The input or textarea element to check\n * @returns True if the input contains sensitive data\n */\nfunction isSensitiveInput(\n\tinputElement: HTMLInputElement | HTMLTextAreaElement,\n): boolean {\n\t// Check input type\n\tif (inputElement instanceof HTMLInputElement) {\n\t\tconst type = inputElement.type.toLowerCase();\n\t\tif (type === \"password\" || type === \"hidden\") {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\t// Check autocomplete attribute for sensitive patterns\n\tconst autocomplete = inputElement.getAttribute(\"autocomplete\")?.toLowerCase();\n\tif (autocomplete) {\n\t\tconst sensitiveAutocompletePaths = [\n\t\t\t\"current-password\",\n\t\t\t\"new-password\",\n\t\t\t\"cc-number\",\n\t\t\t\"cc-csc\",\n\t\t\t\"cc-exp\",\n\t\t\t\"cc-exp-month\",\n\t\t\t\"cc-exp-year\",\n\t\t];\n\t\tif (\n\t\t\tsensitiveAutocompletePaths.some((path) => autocomplete.includes(path))\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\t// Check for custom sensitive marker attribute\n\tif (inputElement.getAttribute(ATTRIBUTE_SENSITIVE) === \"true\") {\n\t\treturn true;\n\t}\n\n\t// Check parent element for sensitive marker attribute\n\tconst parent = inputElement.parentElement;\n\tif (parent && parent.getAttribute(ATTRIBUTE_SENSITIVE) === \"true\") {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n/**\n * Extracts the value from an input or textarea element\n * Redacts sensitive values (passwords, credit cards, etc.) for privacy\n */\nfunction extractInputValue(element: Element): string | undefined {\n\tconst inputElement = findInputElement(element);\n\tif (!inputElement) {\n\t\treturn undefined;\n\t}\n\tif (isSensitiveInput(inputElement)) {\n\t\treturn \"[REDACTED]\";\n\t}\n\treturn inputElement.value;\n}\n\n/**\n * Extracts options and selected values from a select element\n */\nfunction extractSelectData(element: Element): {\n\toptions?: Array<{ value: string; label: string }>;\n\tselectedOptions?: string[];\n} {\n\tconst selectElement = findSelectElement(element);\n\tif (!selectElement) {\n\t\treturn {};\n\t}\n\n\tconst options: Array<{ value: string; label: string }> = [];\n\tfor (let i = 0; i < selectElement.options.length; i++) {\n\t\tconst option = selectElement.options[i];\n\t\toptions.push({\n\t\t\tvalue: option.value,\n\t\t\tlabel: option.text,\n\t\t});\n\t}\n\n\tconst selectedOptions: string[] = [];\n\tif (selectElement.multiple) {\n\t\tfor (let i = 0; i < selectElement.selectedOptions.length; i++) {\n\t\t\tselectedOptions.push(selectElement.selectedOptions[i].value);\n\t\t}\n\t} else {\n\t\tif (selectElement.value) {\n\t\t\tselectedOptions.push(selectElement.value);\n\t\t}\n\t}\n\n\treturn {\n\t\toptions: options.length > 0 ? options : undefined,\n\t\tselectedOptions: selectedOptions.length > 0 ? selectedOptions : undefined,\n\t};\n}\n\n/**\n * Scans the DOM for elements with data-ai-* attributes and returns markers\n *\n * @param root - Optional DOM root element to scan (defaults to document.body)\n * @returns Array of Marker objects found in the DOM\n *\n * @example\n * ```ts\n * const markers = getMarkers();\n * // Scans document.body for data-ai-* attributes\n * ```\n */\nexport function getMarkers(root?: Element): Marker[] {\n\tconst scanRoot = root ?? getDocumentBody();\n\n\tif (!scanRoot) {\n\t\treturn [];\n\t}\n\n\tconst elements = scanRoot.querySelectorAll(getAllMarkersSelector());\n\tconst markers: Marker[] = [];\n\tfor (let i = 0; i < elements.length; i++) {\n\t\tconst element = elements[i];\n\t\tconst id = getMarkerId(element);\n\t\tif (!id) continue;\n\n\t\tconst label = getMarkerLabel(element) || formatMarkerId(id);\n\t\tconst intent = getMarkerIntent(element) || \"\";\n\t\tconst elementType = element.tagName.toLowerCase();\n\n\t\tconst marker: Marker = {\n\t\t\tid,\n\t\t\tlabel,\n\t\t\tintent,\n\t\t\telementType,\n\t\t};\n\n\t\tconst inputValue = extractInputValue(element);\n\t\tif (inputValue !== undefined) {\n\t\t\tmarker.value = inputValue;\n\t\t}\n\n\t\tconst selectData = extractSelectData(element);\n\t\tif (selectData.options !== undefined) {\n\t\t\tmarker.options = selectData.options;\n\t\t}\n\t\tif (selectData.selectedOptions !== undefined) {\n\t\t\tmarker.selectedOptions = selectData.selectedOptions;\n\t\t}\n\n\t\tmarkers.push(marker);\n\t}\n\n\treturn markers;\n}\n"],"mappings":"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"}
@@ -0,0 +1,56 @@
1
+ import { Ai11yError, Ai11yEvent, Ai11yState } from "./context.mjs";
2
+
3
+ //#region src/store.d.ts
4
+ type StoreChangeListener = (type: "route" | "state" | "error", value: unknown) => void;
5
+ declare function setRoute(newRoute: string | undefined): void;
6
+ declare function getRoute(): string | undefined;
7
+ /**
8
+ * Merges new state with existing state (similar to React's setState)
9
+ * Pass undefined to clear all state
10
+ *
11
+ * @param newState - Partial state to merge, or undefined to clear
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * setState({ userId: '123' }); // Merges with existing state
16
+ * setState({ theme: 'dark' }); // Adds to state, keeps userId
17
+ * setState(undefined); // Clears all state
18
+ * ```
19
+ */
20
+ declare function setState(newState: Ai11yState | undefined): void;
21
+ /**
22
+ * Clears all application state
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * clearState(); // Resets state to empty
27
+ * ```
28
+ */
29
+ declare function clearState(): void;
30
+ declare function getState(): Ai11yState | undefined;
31
+ declare function setError(newError: Ai11yError | null | undefined): void;
32
+ declare function getError(): Ai11yError | null | undefined;
33
+ declare function track(event: string, payload?: unknown): void;
34
+ declare function getEvents(): Ai11yEvent[];
35
+ declare function clearEvents(): void;
36
+ /**
37
+ * Subscribe to store changes (route, state, error)
38
+ * Returns an unsubscribe function
39
+ *
40
+ * @param listener - Function called when route, state, or error changes
41
+ * @returns Unsubscribe function
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const unsubscribe = subscribeToStore((type, value) => {
46
+ * if (type === 'route') console.log('Route changed:', value);
47
+ * });
48
+ * // Later...
49
+ * unsubscribe();
50
+ * ```
51
+ */
52
+ declare function subscribeToStore(listener: StoreChangeListener): () => void;
53
+ declare function clearContext(): void;
54
+ //#endregion
55
+ export { clearContext, clearEvents, clearState, getError, getEvents, getRoute, getState, setError, setRoute, setState, subscribeToStore, track };
56
+ //# sourceMappingURL=store.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.mts","names":[],"sources":["../src/store.ts"],"sourcesContent":[],"mappings":";;;KAQK,mBAAA;iBAqBW,QAAA;AArBX,iBA0BW,QAAA,CAAA,CA1BQ,EAAA,MAAA,GAAA,SAAA;AAqBxB;AAKA;AAiBA;AAiBA;AAKA;AAIA;AAKA;AAIA;AAYA;AAIA;AAoBA;AAOA;;iBA9EgB,QAAA,WAAmB;;;;;;;;;iBAiBnB,UAAA,CAAA;iBAKA,QAAA,CAAA,GAAY;iBAIZ,QAAA,WAAmB;iBAKnB,QAAA,CAAA,GAAY;iBAIZ,KAAA;iBAYA,SAAA,CAAA,GAAa;iBAIb,WAAA,CAAA;;;;;;;;;;;;;;;;;iBAoBA,gBAAA,WAA2B;iBAO3B,YAAA,CAAA"}
package/dist/store.mjs ADDED
@@ -0,0 +1,114 @@
1
+ import { notify } from "./events.mjs";
2
+
3
+ //#region src/store.ts
4
+ let route;
5
+ let state;
6
+ let error;
7
+ let events = [];
8
+ const storeListeners = /* @__PURE__ */ new Set();
9
+ function notifyStoreChange(type, value) {
10
+ for (const listener of storeListeners) try {
11
+ listener(type, value);
12
+ } catch (err) {
13
+ console.error("Error in store change listener:", err);
14
+ }
15
+ }
16
+ function setRoute(newRoute) {
17
+ route = newRoute;
18
+ notifyStoreChange("route", newRoute);
19
+ }
20
+ function getRoute() {
21
+ return route;
22
+ }
23
+ /**
24
+ * Merges new state with existing state (similar to React's setState)
25
+ * Pass undefined to clear all state
26
+ *
27
+ * @param newState - Partial state to merge, or undefined to clear
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * setState({ userId: '123' }); // Merges with existing state
32
+ * setState({ theme: 'dark' }); // Adds to state, keeps userId
33
+ * setState(undefined); // Clears all state
34
+ * ```
35
+ */
36
+ function setState(newState) {
37
+ if (newState === void 0) state = void 0;
38
+ else state = {
39
+ ...state || {},
40
+ ...newState
41
+ };
42
+ notifyStoreChange("state", state);
43
+ }
44
+ /**
45
+ * Clears all application state
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * clearState(); // Resets state to empty
50
+ * ```
51
+ */
52
+ function clearState() {
53
+ state = void 0;
54
+ notifyStoreChange("state", void 0);
55
+ }
56
+ function getState() {
57
+ return state;
58
+ }
59
+ function setError(newError) {
60
+ error = newError;
61
+ notifyStoreChange("error", newError);
62
+ }
63
+ function getError() {
64
+ return error;
65
+ }
66
+ function track(event, payload) {
67
+ events = [...events.slice(-49), {
68
+ type: event,
69
+ payload,
70
+ timestamp: Date.now()
71
+ }];
72
+ notify();
73
+ }
74
+ function getEvents() {
75
+ return events;
76
+ }
77
+ function clearEvents() {
78
+ events = [];
79
+ }
80
+ /**
81
+ * Subscribe to store changes (route, state, error)
82
+ * Returns an unsubscribe function
83
+ *
84
+ * @param listener - Function called when route, state, or error changes
85
+ * @returns Unsubscribe function
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const unsubscribe = subscribeToStore((type, value) => {
90
+ * if (type === 'route') console.log('Route changed:', value);
91
+ * });
92
+ * // Later...
93
+ * unsubscribe();
94
+ * ```
95
+ */
96
+ function subscribeToStore(listener) {
97
+ storeListeners.add(listener);
98
+ return () => {
99
+ storeListeners.delete(listener);
100
+ };
101
+ }
102
+ function clearContext() {
103
+ route = void 0;
104
+ state = void 0;
105
+ error = void 0;
106
+ events = [];
107
+ notifyStoreChange("route", void 0);
108
+ notifyStoreChange("state", void 0);
109
+ notifyStoreChange("error", void 0);
110
+ }
111
+
112
+ //#endregion
113
+ export { clearContext, clearEvents, clearState, getError, getEvents, getRoute, getState, setError, setRoute, setState, subscribeToStore, track };
114
+ //# sourceMappingURL=store.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.mjs","names":["route: string | undefined","state: Ai11yState | undefined","error: Ai11yError | null | undefined","events: Ai11yEvent[]"],"sources":["../src/store.ts"],"sourcesContent":["import type { Ai11yError, Ai11yEvent, Ai11yState } from \"./context.js\";\nimport { notify } from \"./events.js\";\n\nlet route: string | undefined;\nlet state: Ai11yState | undefined;\nlet error: Ai11yError | null | undefined;\nlet events: Ai11yEvent[] = [];\n\ntype StoreChangeListener = (\n\ttype: \"route\" | \"state\" | \"error\",\n\tvalue: unknown,\n) => void;\n\nconst storeListeners = new Set<StoreChangeListener>();\n\nfunction notifyStoreChange(\n\ttype: \"route\" | \"state\" | \"error\",\n\tvalue: unknown,\n): void {\n\tfor (const listener of storeListeners) {\n\t\ttry {\n\t\t\tlistener(type, value);\n\t\t} catch (err) {\n\t\t\t// Don't let one listener's error break others\n\t\t\tconsole.error(\"Error in store change listener:\", err);\n\t\t}\n\t}\n}\n\nexport function setRoute(newRoute: string | undefined): void {\n\troute = newRoute;\n\tnotifyStoreChange(\"route\", newRoute);\n}\n\nexport function getRoute(): string | undefined {\n\treturn route;\n}\n\n/**\n * Merges new state with existing state (similar to React's setState)\n * Pass undefined to clear all state\n *\n * @param newState - Partial state to merge, or undefined to clear\n *\n * @example\n * ```ts\n * setState({ userId: '123' }); // Merges with existing state\n * setState({ theme: 'dark' }); // Adds to state, keeps userId\n * setState(undefined); // Clears all state\n * ```\n */\nexport function setState(newState: Ai11yState | undefined): void {\n\tif (newState === undefined) {\n\t\tstate = undefined;\n\t} else {\n\t\tstate = { ...(state || {}), ...newState };\n\t}\n\tnotifyStoreChange(\"state\", state);\n}\n\n/**\n * Clears all application state\n *\n * @example\n * ```ts\n * clearState(); // Resets state to empty\n * ```\n */\nexport function clearState(): void {\n\tstate = undefined;\n\tnotifyStoreChange(\"state\", undefined);\n}\n\nexport function getState(): Ai11yState | undefined {\n\treturn state;\n}\n\nexport function setError(newError: Ai11yError | null | undefined): void {\n\terror = newError;\n\tnotifyStoreChange(\"error\", newError);\n}\n\nexport function getError(): Ai11yError | null | undefined {\n\treturn error;\n}\n\nexport function track(event: string, payload?: unknown): void {\n\tevents = [\n\t\t...events.slice(-49), // Keep last 50 events\n\t\t{\n\t\t\ttype: event,\n\t\t\tpayload,\n\t\t\ttimestamp: Date.now(),\n\t\t},\n\t];\n\tnotify();\n}\n\nexport function getEvents(): Ai11yEvent[] {\n\treturn events;\n}\n\nexport function clearEvents(): void {\n\tevents = [];\n}\n\n/**\n * Subscribe to store changes (route, state, error)\n * Returns an unsubscribe function\n *\n * @param listener - Function called when route, state, or error changes\n * @returns Unsubscribe function\n *\n * @example\n * ```ts\n * const unsubscribe = subscribeToStore((type, value) => {\n * if (type === 'route') console.log('Route changed:', value);\n * });\n * // Later...\n * unsubscribe();\n * ```\n */\nexport function subscribeToStore(listener: StoreChangeListener): () => void {\n\tstoreListeners.add(listener);\n\treturn () => {\n\t\tstoreListeners.delete(listener);\n\t};\n}\n\nexport function clearContext(): void {\n\troute = undefined;\n\tstate = undefined;\n\terror = undefined;\n\tevents = [];\n\tnotifyStoreChange(\"route\", undefined);\n\tnotifyStoreChange(\"state\", undefined);\n\tnotifyStoreChange(\"error\", undefined);\n}\n"],"mappings":";;;AAGA,IAAIA;AACJ,IAAIC;AACJ,IAAIC;AACJ,IAAIC,SAAuB,EAAE;AAO7B,MAAM,iCAAiB,IAAI,KAA0B;AAErD,SAAS,kBACR,MACA,OACO;AACP,MAAK,MAAM,YAAY,eACtB,KAAI;AACH,WAAS,MAAM,MAAM;UACb,KAAK;AAEb,UAAQ,MAAM,mCAAmC,IAAI;;;AAKxD,SAAgB,SAAS,UAAoC;AAC5D,SAAQ;AACR,mBAAkB,SAAS,SAAS;;AAGrC,SAAgB,WAA+B;AAC9C,QAAO;;;;;;;;;;;;;;;AAgBR,SAAgB,SAAS,UAAwC;AAChE,KAAI,aAAa,OAChB,SAAQ;KAER,SAAQ;EAAE,GAAI,SAAS,EAAE;EAAG,GAAG;EAAU;AAE1C,mBAAkB,SAAS,MAAM;;;;;;;;;;AAWlC,SAAgB,aAAmB;AAClC,SAAQ;AACR,mBAAkB,SAAS,OAAU;;AAGtC,SAAgB,WAAmC;AAClD,QAAO;;AAGR,SAAgB,SAAS,UAA+C;AACvE,SAAQ;AACR,mBAAkB,SAAS,SAAS;;AAGrC,SAAgB,WAA0C;AACzD,QAAO;;AAGR,SAAgB,MAAM,OAAe,SAAyB;AAC7D,UAAS,CACR,GAAG,OAAO,MAAM,IAAI,EACpB;EACC,MAAM;EACN;EACA,WAAW,KAAK,KAAK;EACrB,CACD;AACD,SAAQ;;AAGT,SAAgB,YAA0B;AACzC,QAAO;;AAGR,SAAgB,cAAoB;AACnC,UAAS,EAAE;;;;;;;;;;;;;;;;;;AAmBZ,SAAgB,iBAAiB,UAA2C;AAC3E,gBAAe,IAAI,SAAS;AAC5B,cAAa;AACZ,iBAAe,OAAO,SAAS;;;AAIjC,SAAgB,eAAqB;AACpC,SAAQ;AACR,SAAQ;AACR,SAAQ;AACR,UAAS,EAAE;AACX,mBAAkB,SAAS,OAAU;AACrC,mBAAkB,SAAS,OAAU;AACrC,mBAAkB,SAAS,OAAU"}