@useorgx/openclaw-plugin 0.4.1 → 0.4.4

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.js CHANGED
@@ -21,6 +21,8 @@ import { clearPersistedApiKey, loadAuthStore, resolveInstallationId, saveAuthSto
21
21
  import { clearPersistedSnapshot, readPersistedSnapshot, writePersistedSnapshot, } from "./snapshot-store.js";
22
22
  import { appendToOutbox, readOutbox, readOutboxSummary, replaceOutbox, } from "./outbox.js";
23
23
  import { extractProgressOutboxMessage } from "./reporting/outbox-replay.js";
24
+ import { ensureGatewayWatchdog } from "./gateway-watchdog.js";
25
+ import { posthogCapture } from "./telemetry/posthog.js";
24
26
  export { OrgXClient } from "./api.js";
25
27
  const DEFAULT_BASE_URL = "https://www.useorgx.com";
26
28
  const DEFAULT_DOCS_URL = "https://orgx.mintlify.site/guides/openclaw-plugin-setup";
@@ -324,6 +326,19 @@ export default function register(api) {
324
326
  api.log?.info?.("[orgx] Plugin disabled");
325
327
  return;
326
328
  }
329
+ void posthogCapture({
330
+ event: "openclaw_plugin_loaded",
331
+ distinctId: config.installationId,
332
+ properties: {
333
+ plugin_version: config.pluginVersion,
334
+ dashboard_enabled: config.dashboardEnabled,
335
+ has_api_key: Boolean(config.apiKey),
336
+ api_key_source: config.apiKeySource,
337
+ base_url: config.baseUrl,
338
+ },
339
+ }).catch(() => {
340
+ // best effort
341
+ });
327
342
  if (!config.apiKey) {
328
343
  api.log?.warn?.("[orgx] No API key. Set plugins.entries.orgx.config.apiKey, ORGX_API_KEY env, or ~/Code/orgx/orgx/.env.local");
329
344
  }
@@ -390,6 +405,140 @@ export default function register(api) {
390
405
  return err.message;
391
406
  return typeof err === "string" ? err : "Unexpected error";
392
407
  }
408
+ const registerTool = api.registerTool.bind(api);
409
+ api.registerTool = (tool, options) => {
410
+ const toolName = tool.name;
411
+ const optional = Boolean(options?.optional);
412
+ registerTool({
413
+ ...tool,
414
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
415
+ execute: async (callId, params) => {
416
+ const startedAt = Date.now();
417
+ void posthogCapture({
418
+ event: "openclaw_tool_called",
419
+ distinctId: config.installationId,
420
+ properties: {
421
+ tool_name: toolName,
422
+ tool_optional: optional,
423
+ call_id: callId,
424
+ plugin_version: config.pluginVersion,
425
+ },
426
+ }).catch(() => {
427
+ // best effort
428
+ });
429
+ try {
430
+ const result = await tool.execute(callId, params);
431
+ const durationMs = Date.now() - startedAt;
432
+ void posthogCapture({
433
+ event: "openclaw_tool_succeeded",
434
+ distinctId: config.installationId,
435
+ properties: {
436
+ tool_name: toolName,
437
+ tool_optional: optional,
438
+ call_id: callId,
439
+ duration_ms: durationMs,
440
+ plugin_version: config.pluginVersion,
441
+ },
442
+ }).catch(() => {
443
+ // best effort
444
+ });
445
+ return result;
446
+ }
447
+ catch (err) {
448
+ const durationMs = Date.now() - startedAt;
449
+ void posthogCapture({
450
+ event: "openclaw_tool_failed",
451
+ distinctId: config.installationId,
452
+ properties: {
453
+ tool_name: toolName,
454
+ tool_optional: optional,
455
+ call_id: callId,
456
+ duration_ms: durationMs,
457
+ plugin_version: config.pluginVersion,
458
+ error: toErrorMessage(err),
459
+ },
460
+ }).catch(() => {
461
+ // best effort
462
+ });
463
+ throw err;
464
+ }
465
+ },
466
+ }, options);
467
+ };
468
+ const registerService = api.registerService.bind(api);
469
+ api.registerService = (service) => {
470
+ registerService({
471
+ ...service,
472
+ start: async () => {
473
+ const startedAt = Date.now();
474
+ try {
475
+ await service.start();
476
+ const durationMs = Date.now() - startedAt;
477
+ void posthogCapture({
478
+ event: "openclaw_service_started",
479
+ distinctId: config.installationId,
480
+ properties: {
481
+ service_id: service.id,
482
+ duration_ms: durationMs,
483
+ plugin_version: config.pluginVersion,
484
+ },
485
+ }).catch(() => {
486
+ // best effort
487
+ });
488
+ }
489
+ catch (err) {
490
+ const durationMs = Date.now() - startedAt;
491
+ void posthogCapture({
492
+ event: "openclaw_service_start_failed",
493
+ distinctId: config.installationId,
494
+ properties: {
495
+ service_id: service.id,
496
+ duration_ms: durationMs,
497
+ plugin_version: config.pluginVersion,
498
+ error: toErrorMessage(err),
499
+ },
500
+ }).catch(() => {
501
+ // best effort
502
+ });
503
+ throw err;
504
+ }
505
+ },
506
+ stop: async () => {
507
+ const startedAt = Date.now();
508
+ try {
509
+ await service.stop();
510
+ const durationMs = Date.now() - startedAt;
511
+ void posthogCapture({
512
+ event: "openclaw_service_stopped",
513
+ distinctId: config.installationId,
514
+ properties: {
515
+ service_id: service.id,
516
+ duration_ms: durationMs,
517
+ plugin_version: config.pluginVersion,
518
+ },
519
+ }).catch(() => {
520
+ // best effort
521
+ });
522
+ }
523
+ catch (err) {
524
+ const durationMs = Date.now() - startedAt;
525
+ void posthogCapture({
526
+ event: "openclaw_service_stop_failed",
527
+ distinctId: config.installationId,
528
+ properties: {
529
+ service_id: service.id,
530
+ duration_ms: durationMs,
531
+ plugin_version: config.pluginVersion,
532
+ error: toErrorMessage(err),
533
+ },
534
+ }).catch(() => {
535
+ // best effort
536
+ });
537
+ throw err;
538
+ }
539
+ },
540
+ });
541
+ };
393
542
  function clearPairingState() {
394
543
  activePairing = null;
395
544
  updateOnboardingState({
@@ -1077,6 +1226,12 @@ export default function register(api) {
1077
1226
  id: "orgx-sync",
1078
1227
  start: async () => {
1079
1228
  syncServiceRunning = true;
1229
+ const watchdog = ensureGatewayWatchdog(api.log ?? {});
1230
+ if (watchdog.started) {
1231
+ api.log?.info?.("[orgx] Gateway watchdog started", {
1232
+ pid: watchdog.pid,
1233
+ });
1234
+ }
1080
1235
  api.log?.info?.("[orgx] Starting sync service", {
1081
1236
  interval: config.syncIntervalMs,
1082
1237
  });
@@ -0,0 +1,17 @@
1
+ export type OpenClawProvider = "anthropic" | "openrouter" | "openai";
2
+ export interface OpenClawSettingsSnapshot {
3
+ path: string;
4
+ raw: Record<string, unknown> | null;
5
+ }
6
+ export interface OpenClawProviderModelStats {
7
+ provider: OpenClawProvider;
8
+ total: number;
9
+ sonnetCount: number;
10
+ }
11
+ export declare function readOpenClawSettingsSnapshot(): OpenClawSettingsSnapshot;
12
+ export declare function listOpenClawConfiguredModelKeys(raw: Record<string, unknown> | null): string[];
13
+ export declare function classifyProviderFromModelKey(modelKey: string): OpenClawProvider | null;
14
+ export declare function summarizeOpenClawProviderModels(raw: Record<string, unknown> | null): Record<OpenClawProvider, OpenClawProviderModelStats>;
15
+ export declare function resolvePreferredOpenClawProvider(raw: Record<string, unknown> | null): OpenClawProvider | null;
16
+ export declare function readOpenClawPrimaryModel(raw: Record<string, unknown> | null): string | null;
17
+ export declare function readOpenClawGatewayPort(raw: Record<string, unknown> | null): number;
@@ -0,0 +1,118 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { getOpenClawDir } from "./paths.js";
4
+ function readObject(value) {
5
+ return value && typeof value === "object" && !Array.isArray(value)
6
+ ? value
7
+ : {};
8
+ }
9
+ function parseJsonObject(value) {
10
+ try {
11
+ const parsed = JSON.parse(value);
12
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed)
13
+ ? parsed
14
+ : null;
15
+ }
16
+ catch {
17
+ return null;
18
+ }
19
+ }
20
+ export function readOpenClawSettingsSnapshot() {
21
+ const path = join(getOpenClawDir(), "openclaw.json");
22
+ if (!existsSync(path)) {
23
+ return { path, raw: null };
24
+ }
25
+ try {
26
+ const rawText = readFileSync(path, "utf8");
27
+ return { path, raw: parseJsonObject(rawText) };
28
+ }
29
+ catch {
30
+ return { path, raw: null };
31
+ }
32
+ }
33
+ export function listOpenClawConfiguredModelKeys(raw) {
34
+ if (!raw)
35
+ return [];
36
+ const agents = readObject(raw.agents);
37
+ const defaults = readObject(agents.defaults);
38
+ const models = readObject(defaults.models);
39
+ const keys = Object.keys(models)
40
+ .map((key) => key.trim())
41
+ .filter((key) => key.length > 0);
42
+ keys.sort((a, b) => a.localeCompare(b));
43
+ return keys;
44
+ }
45
+ export function classifyProviderFromModelKey(modelKey) {
46
+ const normalized = modelKey.trim().toLowerCase();
47
+ if (!normalized)
48
+ return null;
49
+ if (normalized.startsWith("openrouter/"))
50
+ return "openrouter";
51
+ if (normalized.startsWith("anthropic/") || normalized.startsWith("claude/")) {
52
+ return "anthropic";
53
+ }
54
+ if (normalized.startsWith("openai/") ||
55
+ normalized.startsWith("openai-") ||
56
+ normalized.startsWith("gpt")) {
57
+ return "openai";
58
+ }
59
+ return null;
60
+ }
61
+ export function summarizeOpenClawProviderModels(raw) {
62
+ const summary = {
63
+ anthropic: { provider: "anthropic", total: 0, sonnetCount: 0 },
64
+ openrouter: { provider: "openrouter", total: 0, sonnetCount: 0 },
65
+ openai: { provider: "openai", total: 0, sonnetCount: 0 },
66
+ };
67
+ for (const key of listOpenClawConfiguredModelKeys(raw)) {
68
+ const provider = classifyProviderFromModelKey(key);
69
+ if (!provider)
70
+ continue;
71
+ const bucket = summary[provider];
72
+ bucket.total += 1;
73
+ if (key.toLowerCase().includes("sonnet")) {
74
+ bucket.sonnetCount += 1;
75
+ }
76
+ }
77
+ return summary;
78
+ }
79
+ export function resolvePreferredOpenClawProvider(raw) {
80
+ const summary = summarizeOpenClawProviderModels(raw);
81
+ const order = ["openrouter", "anthropic", "openai"];
82
+ for (const provider of order) {
83
+ if (summary[provider].sonnetCount > 0) {
84
+ return provider;
85
+ }
86
+ }
87
+ for (const provider of order) {
88
+ if (summary[provider].total > 0) {
89
+ return provider;
90
+ }
91
+ }
92
+ return null;
93
+ }
94
+ export function readOpenClawPrimaryModel(raw) {
95
+ if (!raw)
96
+ return null;
97
+ const agents = readObject(raw.agents);
98
+ const defaults = readObject(agents.defaults);
99
+ const model = readObject(defaults.model);
100
+ const primary = typeof model.primary === "string" ? model.primary.trim() : "";
101
+ return primary || null;
102
+ }
103
+ export function readOpenClawGatewayPort(raw) {
104
+ if (!raw)
105
+ return 18789;
106
+ const gateway = readObject(raw.gateway);
107
+ const port = gateway.port;
108
+ if (typeof port === "number" && Number.isFinite(port) && port > 0) {
109
+ return Math.floor(port);
110
+ }
111
+ if (typeof port === "string") {
112
+ const parsed = Number.parseInt(port, 10);
113
+ if (Number.isFinite(parsed) && parsed > 0) {
114
+ return parsed;
115
+ }
116
+ }
117
+ return 18789;
118
+ }
@@ -0,0 +1,8 @@
1
+ export declare function isOrgxTelemetryDisabled(): boolean;
2
+ export declare function resolvePosthogApiKey(): string | null;
3
+ export declare function resolvePosthogHost(): string;
4
+ export declare function posthogCapture(input: {
5
+ event: string;
6
+ distinctId: string;
7
+ properties?: Record<string, unknown>;
8
+ }): Promise<void>;
@@ -0,0 +1,81 @@
1
+ const POSTHOG_DEFAULT_API_KEY = "phc_s4KPgkYEFZgvkMYw4zXG41H5FN6haVwbEWPYHfNjxOc";
2
+ const POSTHOG_DEFAULT_HOST = "https://us.i.posthog.com";
3
+ function isTruthyEnv(value) {
4
+ if (!value)
5
+ return false;
6
+ switch (value.trim().toLowerCase()) {
7
+ case "1":
8
+ case "true":
9
+ case "yes":
10
+ case "y":
11
+ case "on":
12
+ return true;
13
+ default:
14
+ return false;
15
+ }
16
+ }
17
+ export function isOrgxTelemetryDisabled() {
18
+ return (isTruthyEnv(process.env.ORGX_TELEMETRY_DISABLED) ||
19
+ isTruthyEnv(process.env.OPENCLAW_TELEMETRY_DISABLED) ||
20
+ isTruthyEnv(process.env.POSTHOG_DISABLED));
21
+ }
22
+ export function resolvePosthogApiKey() {
23
+ const fromEnv = process.env.ORGX_POSTHOG_API_KEY ??
24
+ process.env.POSTHOG_API_KEY ??
25
+ process.env.ORGX_POSTHOG_KEY ??
26
+ process.env.POSTHOG_KEY ??
27
+ "";
28
+ const trimmed = fromEnv.trim();
29
+ if (trimmed)
30
+ return trimmed;
31
+ return POSTHOG_DEFAULT_API_KEY;
32
+ }
33
+ export function resolvePosthogHost() {
34
+ const fromEnv = process.env.ORGX_POSTHOG_HOST ??
35
+ process.env.POSTHOG_HOST ??
36
+ process.env.ORGX_POSTHOG_API_HOST ??
37
+ process.env.POSTHOG_API_HOST ??
38
+ "";
39
+ const trimmed = fromEnv.trim();
40
+ return trimmed || POSTHOG_DEFAULT_HOST;
41
+ }
42
+ function toPosthogBatchUrl(host) {
43
+ try {
44
+ return new URL("/batch/", host).toString();
45
+ }
46
+ catch {
47
+ return `${POSTHOG_DEFAULT_HOST}/batch/`;
48
+ }
49
+ }
50
+ export async function posthogCapture(input) {
51
+ if (isOrgxTelemetryDisabled())
52
+ return;
53
+ const apiKey = resolvePosthogApiKey();
54
+ if (!apiKey)
55
+ return;
56
+ const url = toPosthogBatchUrl(resolvePosthogHost());
57
+ const now = new Date().toISOString();
58
+ const body = {
59
+ api_key: apiKey,
60
+ batch: [
61
+ {
62
+ type: "capture",
63
+ event: input.event,
64
+ distinct_id: input.distinctId,
65
+ properties: {
66
+ $lib: "orgx-openclaw-plugin",
67
+ ...(input.properties ?? {}),
68
+ },
69
+ timestamp: now,
70
+ },
71
+ ],
72
+ sent_at: now,
73
+ };
74
+ await fetch(url, {
75
+ method: "POST",
76
+ headers: {
77
+ "Content-Type": "application/json",
78
+ },
79
+ body: JSON.stringify(body),
80
+ }).then(() => undefined);
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useorgx/openclaw-plugin",
3
- "version": "0.4.1",
3
+ "version": "0.4.4",
4
4
  "description": "OrgX plugin for OpenClaw — agent orchestration, quality gates, model routing, and live dashboard",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1 +0,0 @@
1
- var z={exports:{}},K={};var Y;function le(){return Y||(Y=1,(function(e){function n(t,i){var a=t.length;t.push(i);e:for(;0<a;){var l=a-1>>>1,f=t[l];if(0<o(f,i))t[l]=i,t[a]=f,a=l;else break e}}function r(t){return t.length===0?null:t[0]}function s(t){if(t.length===0)return null;var i=t[0],a=t.pop();if(a!==i){t[0]=a;e:for(var l=0,f=t.length,S=f>>>1;l<S;){var E=2*(l+1)-1,R=t[E],w=E+1,G=t[w];if(0>o(R,a))w<f&&0>o(G,R)?(t[l]=G,t[w]=a,l=w):(t[l]=R,t[E]=a,l=E);else if(w<f&&0>o(G,a))t[l]=G,t[w]=a,l=w;else break e}}return i}function o(t,i){var a=t.sortIndex-i.sortIndex;return a!==0?a:t.id-i.id}if(typeof performance=="object"&&typeof performance.now=="function"){var d=performance;e.unstable_now=function(){return d.now()}}else{var T=Date,h=T.now();e.unstable_now=function(){return T.now()-h}}var u=[],m=[],g=1,p=null,c=3,y=!1,b=!1,P=!1,j=typeof setTimeout=="function"?setTimeout:null,x=typeof clearTimeout=="function"?clearTimeout:null,H=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function B(t){for(var i=r(m);i!==null;){if(i.callback===null)s(m);else if(i.startTime<=t)s(m),i.sortIndex=i.expirationTime,n(u,i);else break;i=r(m)}}function D(t){if(P=!1,B(t),!b)if(r(u)!==null)b=!0,q(M);else{var i=r(m);i!==null&&F(D,i.startTime-t)}}function M(t,i){b=!1,P&&(P=!1,x(A),A=-1),y=!0;var a=c;try{for(B(i),p=r(u);p!==null&&(!(p.expirationTime>i)||t&&!Q());){var l=p.callback;if(typeof l=="function"){p.callback=null,c=p.priorityLevel;var f=l(p.expirationTime<=i);i=e.unstable_now(),typeof f=="function"?p.callback=f:p===r(u)&&s(u),B(i)}else s(u);p=r(u)}if(p!==null)var S=!0;else{var E=r(m);E!==null&&F(D,E.startTime-i),S=!1}return S}finally{p=null,c=a,y=!1}}var I=!1,C=null,A=-1,V=5,J=-1;function Q(){return!(e.unstable_now()-J<V)}function N(){if(C!==null){var t=e.unstable_now();J=t;var i=!0;try{i=C(!0,t)}finally{i?_():(I=!1,C=null)}}else I=!1}var _;if(typeof H=="function")_=function(){H(N)};else if(typeof MessageChannel<"u"){var X=new MessageChannel,ue=X.port2;X.port1.onmessage=N,_=function(){ue.postMessage(null)}}else _=function(){j(N,0)};function q(t){C=t,I||(I=!0,_())}function F(t,i){A=j(function(){t(e.unstable_now())},i)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(t){t.callback=null},e.unstable_continueExecution=function(){b||y||(b=!0,q(M))},e.unstable_forceFrameRate=function(t){0>t||125<t||(V=0<t?Math.floor(1e3/t):5)},e.unstable_getCurrentPriorityLevel=function(){return c},e.unstable_getFirstCallbackNode=function(){return r(u)},e.unstable_next=function(t){switch(c){case 1:case 2:case 3:var i=3;break;default:i=c}var a=c;c=i;try{return t()}finally{c=a}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(t,i){switch(t){case 1:case 2:case 3:case 4:case 5:break;default:t=3}var a=c;c=t;try{return i()}finally{c=a}},e.unstable_scheduleCallback=function(t,i,a){var l=e.unstable_now();switch(typeof a=="object"&&a!==null?(a=a.delay,a=typeof a=="number"&&0<a?l+a:l):a=l,t){case 1:var f=-1;break;case 2:f=250;break;case 5:f=1073741823;break;case 4:f=1e4;break;default:f=5e3}return f=a+f,t={id:g++,callback:i,priorityLevel:t,startTime:a,expirationTime:f,sortIndex:-1},a>l?(t.sortIndex=a,n(m,t),r(u)===null&&t===r(m)&&(P?(x(A),A=-1):P=!0,F(D,a-l))):(t.sortIndex=f,n(u,t),b||y||(b=!0,q(M))),t},e.unstable_shouldYield=Q,e.unstable_wrapCallback=function(t){var i=c;return function(){var a=c;c=i;try{return t.apply(this,arguments)}finally{c=a}}}})(K)),K}var Z;function Ae(){return Z||(Z=1,z.exports=le()),z.exports}const ce=e=>e;let _e=ce;function re(e){let n;return()=>(n===void 0&&(n=e()),n)}const fe=(e,n,r)=>{const s=n-e;return s===0?1:(r-e)/s},ke=e=>e*1e3,Le=e=>e/1e3,de=re(()=>window.ScrollTimeline!==void 0);class pe{constructor(n){this.stop=()=>this.runAll("stop"),this.animations=n.filter(Boolean)}get finished(){return Promise.all(this.animations.map(n=>"finished"in n?n.finished:n))}getAll(n){return this.animations[0][n]}setAll(n,r){for(let s=0;s<this.animations.length;s++)this.animations[s][n]=r}attachTimeline(n,r){const s=this.animations.map(o=>{if(de()&&o.attachTimeline)return o.attachTimeline(n);if(typeof r=="function")return r(o)});return()=>{s.forEach((o,d)=>{o&&o(),this.animations[d].stop()})}}get time(){return this.getAll("time")}set time(n){this.setAll("time",n)}get speed(){return this.getAll("speed")}set speed(n){this.setAll("speed",n)}get startTime(){return this.getAll("startTime")}get duration(){let n=0;for(let r=0;r<this.animations.length;r++)n=Math.max(n,this.animations[r].duration);return n}runAll(n){this.animations.forEach(r=>r[n]())}flatten(){this.runAll("flatten")}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}class Ie extends pe{then(n,r){return Promise.all(this.animations).then(n).catch(r)}}function Ce(e,n){return e?e[n]||e.default||e:void 0}const $=2e4;function Se(e){let n=0;const r=50;let s=e.next(n);for(;!s.done&&n<$;)n+=r,s=e.next(n);return n>=$?1/0:n}function Ge(e){return typeof e=="function"}function Be(e,n){e.timeline=n,e.onfinish=null}const ie=e=>Array.isArray(e)&&typeof e[0]=="number",he={linearEasing:void 0};function me(e,n){const r=re(e);return()=>{var s;return(s=he[n])!==null&&s!==void 0?s:r()}}const U=me(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch{return!1}return!0},"linearEasing"),ye=(e,n,r=10)=>{let s="";const o=Math.max(Math.round(n/r),2);for(let d=0;d<o;d++)s+=e(fe(0,o-1,d))+", ";return`linear(${s.substring(0,s.length-2)})`};function ve(e){return!!(typeof e=="function"&&U()||!e||typeof e=="string"&&(e in W||U())||ie(e)||Array.isArray(e)&&e.every(ve))}const k=([e,n,r,s])=>`cubic-bezier(${e}, ${n}, ${r}, ${s})`,W={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:k([0,.65,.55,1]),circOut:k([.55,0,1,.45]),backIn:k([.31,.01,.66,-.59]),backOut:k([.33,1.53,.69,.99])};function be(e,n){if(e)return typeof e=="function"&&U()?ye(e,n):ie(e)?k(e):Array.isArray(e)?e.map(r=>be(r,n)||W.easeOut):W[e]}const v={x:!1,y:!1};function se(){return v.x||v.y}function ge(e,n,r){var s;if(e instanceof Element)return[e];if(typeof e=="string"){let o=document;const d=(s=void 0)!==null&&s!==void 0?s:o.querySelectorAll(e);return d?Array.from(d):[]}return Array.from(e)}function ae(e,n){const r=ge(e),s=new AbortController,o={passive:!0,...n,signal:s.signal};return[r,o,()=>s.abort()]}function ee(e){return n=>{n.pointerType==="touch"||se()||e(n)}}function De(e,n,r={}){const[s,o,d]=ae(e,r),T=ee(h=>{const{target:u}=h,m=n(h);if(typeof m!="function"||!u)return;const g=ee(p=>{m(p),u.removeEventListener("pointerleave",g)});u.addEventListener("pointerleave",g,o)});return s.forEach(h=>{h.addEventListener("pointerenter",T,o)}),d}const oe=(e,n)=>n?e===n?!0:oe(e,n.parentElement):!1,Ee=e=>e.pointerType==="mouse"?typeof e.button!="number"||e.button<=0:e.isPrimary!==!1,we=new Set(["BUTTON","INPUT","SELECT","TEXTAREA","A"]);function Te(e){return we.has(e.tagName)||e.tabIndex!==-1}const L=new WeakSet;function ne(e){return n=>{n.key==="Enter"&&e(n)}}function O(e,n){e.dispatchEvent(new PointerEvent("pointer"+n,{isPrimary:!0,bubbles:!0}))}const Pe=(e,n)=>{const r=e.currentTarget;if(!r)return;const s=ne(()=>{if(L.has(r))return;O(r,"down");const o=ne(()=>{O(r,"up")}),d=()=>O(r,"cancel");r.addEventListener("keyup",o,n),r.addEventListener("blur",d,n)});r.addEventListener("keydown",s,n),r.addEventListener("blur",()=>r.removeEventListener("keydown",s),n)};function te(e){return Ee(e)&&!se()}function Me(e,n,r={}){const[s,o,d]=ae(e,r),T=h=>{const u=h.currentTarget;if(!te(h)||L.has(u))return;L.add(u);const m=n(h),g=(y,b)=>{window.removeEventListener("pointerup",p),window.removeEventListener("pointercancel",c),!(!te(y)||!L.has(u))&&(L.delete(u),typeof m=="function"&&m(y,{success:b}))},p=y=>{g(y,r.useGlobalTarget||oe(u,y.target))},c=y=>{g(y,!1)};window.addEventListener("pointerup",p,o),window.addEventListener("pointercancel",c,o)};return s.forEach(h=>{!Te(h)&&h.getAttribute("tabindex")===null&&(h.tabIndex=0),(r.useGlobalTarget?window:h).addEventListener("pointerdown",T,o),h.addEventListener("focus",m=>Pe(m,o),o)}),d}function Ne(e){return e==="x"||e==="y"?v[e]?null:(v[e]=!0,()=>{v[e]=!1}):v.x||v.y?null:(v.x=v.y=!0,()=>{v.x=v.y=!1})}export{Ie as G,$ as a,ie as b,Se as c,_e as d,be as e,re as f,ye as g,U as h,Ge as i,Be as j,ve as k,Ce as l,Le as m,ce as n,Ee as o,fe as p,Ne as q,Ae as r,ke as s,De as t,Me as u};