@syntrologie/runtime-sdk 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/README.md +185 -0
  2. package/dist/SmartCanvasApp.d.ts +29 -0
  3. package/dist/SmartCanvasApp.js +68 -0
  4. package/dist/SmartCanvasApp.js.map +1 -0
  5. package/dist/SmartCanvasElement.d.ts +29 -0
  6. package/dist/SmartCanvasElement.js +133 -0
  7. package/dist/SmartCanvasElement.js.map +1 -0
  8. package/dist/SmartCanvasPortal.d.ts +7 -0
  9. package/dist/SmartCanvasPortal.js +17 -0
  10. package/dist/SmartCanvasPortal.js.map +1 -0
  11. package/dist/antiFlicker.d.ts +10 -0
  12. package/dist/antiFlicker.js +39 -0
  13. package/dist/antiFlicker.js.map +1 -0
  14. package/dist/api.d.ts +60 -0
  15. package/dist/api.js +159 -0
  16. package/dist/api.js.map +1 -0
  17. package/dist/bootstrap.d.ts +62 -0
  18. package/dist/bootstrap.js +83 -0
  19. package/dist/bootstrap.js.map +1 -0
  20. package/dist/bundle-entry.d.ts +4 -0
  21. package/dist/bundle-entry.js +9 -0
  22. package/dist/bundle-entry.js.map +1 -0
  23. package/dist/components/RectangleCard.d.ts +15 -0
  24. package/dist/components/RectangleCard.js +226 -0
  25. package/dist/components/RectangleCard.js.map +1 -0
  26. package/dist/components/RectangleWheel.d.ts +8 -0
  27. package/dist/components/RectangleWheel.js +30 -0
  28. package/dist/components/RectangleWheel.js.map +1 -0
  29. package/dist/components/ShadowCanvasOverlay.d.ts +26 -0
  30. package/dist/components/ShadowCanvasOverlay.js +163 -0
  31. package/dist/components/ShadowCanvasOverlay.js.map +1 -0
  32. package/dist/configFetcher.d.ts +15 -0
  33. package/dist/configFetcher.js +90 -0
  34. package/dist/configFetcher.js.map +1 -0
  35. package/dist/controller.d.ts +15 -0
  36. package/dist/controller.js +34 -0
  37. package/dist/controller.js.map +1 -0
  38. package/dist/earlyPatcher.d.ts +23 -0
  39. package/dist/earlyPatcher.js +70 -0
  40. package/dist/earlyPatcher.js.map +1 -0
  41. package/dist/editorLoader.d.ts +17 -0
  42. package/dist/editorLoader.js +95 -0
  43. package/dist/editorLoader.js.map +1 -0
  44. package/dist/experiments/adapters/growthbook.d.ts +45 -0
  45. package/dist/experiments/adapters/growthbook.js +79 -0
  46. package/dist/experiments/adapters/growthbook.js.map +1 -0
  47. package/dist/experiments/index.d.ts +3 -0
  48. package/dist/experiments/index.js +4 -0
  49. package/dist/experiments/index.js.map +1 -0
  50. package/dist/experiments/registry.d.ts +13 -0
  51. package/dist/experiments/registry.js +30 -0
  52. package/dist/experiments/registry.js.map +1 -0
  53. package/dist/experiments/types.d.ts +25 -0
  54. package/dist/experiments/types.js +2 -0
  55. package/dist/experiments/types.js.map +1 -0
  56. package/dist/fetchers/cdnFetcher.d.ts +35 -0
  57. package/dist/fetchers/cdnFetcher.js +100 -0
  58. package/dist/fetchers/cdnFetcher.js.map +1 -0
  59. package/dist/fetchers/experimentsFetcher.d.ts +33 -0
  60. package/dist/fetchers/experimentsFetcher.js +42 -0
  61. package/dist/fetchers/experimentsFetcher.js.map +1 -0
  62. package/dist/fetchers/index.d.ts +3 -0
  63. package/dist/fetchers/index.js +5 -0
  64. package/dist/fetchers/index.js.map +1 -0
  65. package/dist/fetchers/registry.d.ts +14 -0
  66. package/dist/fetchers/registry.js +58 -0
  67. package/dist/fetchers/registry.js.map +1 -0
  68. package/dist/fetchers/types.d.ts +26 -0
  69. package/dist/fetchers/types.js +2 -0
  70. package/dist/fetchers/types.js.map +1 -0
  71. package/dist/hooks/useCanvasOverlays.d.ts +13 -0
  72. package/dist/hooks/useCanvasOverlays.js +59 -0
  73. package/dist/hooks/useCanvasOverlays.js.map +1 -0
  74. package/dist/hooks/useHostPatches.d.ts +9 -0
  75. package/dist/hooks/useHostPatches.js +40 -0
  76. package/dist/hooks/useHostPatches.js.map +1 -0
  77. package/dist/hooks/useShadowCanvasConfig.d.ts +20 -0
  78. package/dist/hooks/useShadowCanvasConfig.js +46 -0
  79. package/dist/hooks/useShadowCanvasConfig.js.map +1 -0
  80. package/dist/hostPatcher/core/patcher.d.ts +3 -0
  81. package/dist/hostPatcher/core/patcher.js +173 -0
  82. package/dist/hostPatcher/core/patcher.js.map +1 -0
  83. package/dist/hostPatcher/core/sanitizer.d.ts +1 -0
  84. package/dist/hostPatcher/core/sanitizer.js +45 -0
  85. package/dist/hostPatcher/core/sanitizer.js.map +1 -0
  86. package/dist/hostPatcher/core/types.d.ts +94 -0
  87. package/dist/hostPatcher/core/types.js +2 -0
  88. package/dist/hostPatcher/core/types.js.map +1 -0
  89. package/dist/hostPatcher/index.d.ts +6 -0
  90. package/dist/hostPatcher/index.js +7 -0
  91. package/dist/hostPatcher/index.js.map +1 -0
  92. package/dist/hostPatcher/policy/defaultPolicy.d.ts +2 -0
  93. package/dist/hostPatcher/policy/defaultPolicy.js +41 -0
  94. package/dist/hostPatcher/policy/defaultPolicy.js.map +1 -0
  95. package/dist/hostPatcher/utils/anchors.d.ts +13 -0
  96. package/dist/hostPatcher/utils/anchors.js +107 -0
  97. package/dist/hostPatcher/utils/anchors.js.map +1 -0
  98. package/dist/hostPatcher/utils/observer.d.ts +3 -0
  99. package/dist/hostPatcher/utils/observer.js +11 -0
  100. package/dist/hostPatcher/utils/observer.js.map +1 -0
  101. package/dist/index.d.ts +20 -0
  102. package/dist/index.js +20 -0
  103. package/dist/index.js.map +1 -0
  104. package/dist/overlays/fetcher.d.ts +4 -0
  105. package/dist/overlays/fetcher.js +17 -0
  106. package/dist/overlays/fetcher.js.map +1 -0
  107. package/dist/overlays/runtime/anchor/resolve.d.ts +4 -0
  108. package/dist/overlays/runtime/anchor/resolve.js +87 -0
  109. package/dist/overlays/runtime/anchor/resolve.js.map +1 -0
  110. package/dist/overlays/runtime/index.d.ts +6 -0
  111. package/dist/overlays/runtime/index.js +7 -0
  112. package/dist/overlays/runtime/index.js.map +1 -0
  113. package/dist/overlays/runtime/overlay/highlight.d.ts +10 -0
  114. package/dist/overlays/runtime/overlay/highlight.js +152 -0
  115. package/dist/overlays/runtime/overlay/highlight.js.map +1 -0
  116. package/dist/overlays/runtime/overlay/root.d.ts +4 -0
  117. package/dist/overlays/runtime/overlay/root.js +165 -0
  118. package/dist/overlays/runtime/overlay/root.js.map +1 -0
  119. package/dist/overlays/runtime/overlay/runner.d.ts +2 -0
  120. package/dist/overlays/runtime/overlay/runner.js +101 -0
  121. package/dist/overlays/runtime/overlay/runner.js.map +1 -0
  122. package/dist/overlays/runtime/overlay/tooltip.d.ts +14 -0
  123. package/dist/overlays/runtime/overlay/tooltip.js +174 -0
  124. package/dist/overlays/runtime/overlay/tooltip.js.map +1 -0
  125. package/dist/overlays/runtime/utils/dom.d.ts +2 -0
  126. package/dist/overlays/runtime/utils/dom.js +9 -0
  127. package/dist/overlays/runtime/utils/dom.js.map +1 -0
  128. package/dist/overlays/schema.d.ts +907 -0
  129. package/dist/overlays/schema.js +48 -0
  130. package/dist/overlays/schema.js.map +1 -0
  131. package/dist/overlays/types.d.ts +68 -0
  132. package/dist/overlays/types.js +2 -0
  133. package/dist/overlays/types.js.map +1 -0
  134. package/dist/react.d.ts +99 -0
  135. package/dist/react.js +119 -0
  136. package/dist/react.js.map +1 -0
  137. package/dist/smart-canvas.esm.js +202 -0
  138. package/dist/smart-canvas.esm.js.map +7 -0
  139. package/dist/smart-canvas.js +40406 -0
  140. package/dist/smart-canvas.js.map +7 -0
  141. package/dist/smart-canvas.min.js +202 -0
  142. package/dist/smart-canvas.min.js.map +7 -0
  143. package/dist/telemetry/adapters/posthog.d.ts +67 -0
  144. package/dist/telemetry/adapters/posthog.js +61 -0
  145. package/dist/telemetry/adapters/posthog.js.map +1 -0
  146. package/dist/telemetry/index.d.ts +3 -0
  147. package/dist/telemetry/index.js +3 -0
  148. package/dist/telemetry/index.js.map +1 -0
  149. package/dist/telemetry/registry.d.ts +13 -0
  150. package/dist/telemetry/registry.js +27 -0
  151. package/dist/telemetry/registry.js.map +1 -0
  152. package/dist/telemetry/types.d.ts +28 -0
  153. package/dist/telemetry/types.js +2 -0
  154. package/dist/telemetry/types.js.map +1 -0
  155. package/dist/token.d.ts +36 -0
  156. package/dist/token.js +47 -0
  157. package/dist/token.js.map +1 -0
  158. package/dist/types.d.ts +147 -0
  159. package/dist/types.js +5 -0
  160. package/dist/types.js.map +1 -0
  161. package/package.json +64 -0
  162. package/schema/canvas-config.schema.json +329 -0
  163. package/scripts/validate-config.mjs +80 -0
@@ -0,0 +1,48 @@
1
+ import { z } from 'zod';
2
+ export const SelectorZ = z.union([
3
+ z.object({ type: z.literal('data'), key: z.string(), value: z.string().optional() }),
4
+ z.object({ type: z.literal('css'), value: z.string() }),
5
+ z.object({ type: z.literal('aria'), role: z.string().optional(), label: z.string().optional() }),
6
+ z.object({ type: z.literal('shadow-css'), value: z.string() }),
7
+ z.object({ type: z.literal('ref'), el: z.any() }) // runtime-only
8
+ ]);
9
+ export const TooltipStepZ = z.object({
10
+ kind: z.literal('tooltip'),
11
+ id: z.string(),
12
+ anchor: SelectorZ,
13
+ content: z.object({ title: z.string().optional(), body: z.string() }),
14
+ placement: z.enum(['top', 'bottom', 'left', 'right', 'auto']).optional(),
15
+ offsetPx: z.number().optional(),
16
+ blocking: z.boolean().optional(),
17
+ trigger: z.enum(['immediate', 'hover', 'click']).optional(),
18
+ dismiss: z.object({
19
+ onEsc: z.boolean().optional(),
20
+ closeButton: z.boolean().optional(),
21
+ timeoutMs: z.number().optional()
22
+ }).optional()
23
+ });
24
+ export const HighlightStepZ = z.object({
25
+ kind: z.literal('highlight'),
26
+ id: z.string(),
27
+ anchor: SelectorZ,
28
+ copy: z.string().optional(),
29
+ ring: z.object({ paddingPx: z.number().optional(), radiusPx: z.number().optional() }).optional(),
30
+ scrim: z.object({ opacity: z.number().optional() }).optional(),
31
+ ringColor: z.string().optional(),
32
+ blocking: z.boolean().optional(),
33
+ dismiss: z.object({
34
+ onClickOutside: z.boolean().optional(),
35
+ onEsc: z.boolean().optional(),
36
+ timeoutMs: z.number().optional()
37
+ }).optional()
38
+ });
39
+ export const CanvasRecipeZ = z.object({
40
+ id: z.string(),
41
+ version: z.number(),
42
+ routes: z.array(z.string()).optional(),
43
+ steps: z.array(z.union([TooltipStepZ, HighlightStepZ]))
44
+ });
45
+ export function validateRecipe(json) {
46
+ return CanvasRecipeZ.parse(json);
47
+ }
48
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/overlays/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC;IAC/B,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC;IACpF,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IACvD,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC;IAChG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IAC9D,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,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O,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,68 @@
1
+ export type Selector = {
2
+ type: 'data';
3
+ key: string;
4
+ value?: string;
5
+ } | {
6
+ type: 'css';
7
+ value: string;
8
+ } | {
9
+ type: 'aria';
10
+ role?: string;
11
+ label?: string;
12
+ } | {
13
+ type: 'shadow-css';
14
+ value: string;
15
+ } | {
16
+ type: 'ref';
17
+ el?: HTMLElement;
18
+ };
19
+ export type TooltipStep = {
20
+ kind: 'tooltip';
21
+ id: string;
22
+ anchor: Selector;
23
+ content: {
24
+ title?: string;
25
+ body: string;
26
+ };
27
+ placement?: 'top' | 'bottom' | 'left' | 'right' | 'auto';
28
+ offsetPx?: number;
29
+ blocking?: boolean;
30
+ trigger?: 'immediate' | 'hover' | 'click';
31
+ dismiss?: {
32
+ onEsc?: boolean;
33
+ closeButton?: boolean;
34
+ timeoutMs?: number;
35
+ };
36
+ };
37
+ export type HighlightStep = {
38
+ kind: 'highlight';
39
+ id: string;
40
+ anchor: Selector;
41
+ copy?: string;
42
+ ring?: {
43
+ paddingPx?: number;
44
+ radiusPx?: number;
45
+ };
46
+ scrim?: {
47
+ opacity?: number;
48
+ };
49
+ ringColor?: string;
50
+ blocking?: boolean;
51
+ dismiss?: {
52
+ onClickOutside?: boolean;
53
+ onEsc?: boolean;
54
+ timeoutMs?: number;
55
+ };
56
+ };
57
+ export type CanvasRecipe = {
58
+ id: string;
59
+ version: number;
60
+ routes?: string[];
61
+ steps: Array<TooltipStep | HighlightStep>;
62
+ };
63
+ export type OverlayContext = {
64
+ overlayRoot: HTMLElement;
65
+ resolve: (sel: Selector) => Promise<HTMLElement | null>;
66
+ onEvent: (name: string, payload?: any) => void;
67
+ canvasHost?: HTMLElement | null;
68
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/overlays/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * React bindings for the Syntro SDK.
3
+ *
4
+ * Usage:
5
+ * ```tsx
6
+ * import { SyntroProvider, useSyntro } from '@syntrologie/runtime-sdk/react';
7
+ *
8
+ * function App() {
9
+ * return (
10
+ * <SyntroProvider token="syn_xxx">
11
+ * <MyApp />
12
+ * </SyntroProvider>
13
+ * );
14
+ * }
15
+ *
16
+ * function MyComponent() {
17
+ * const { canvas, experiments, telemetry, isReady } = useSyntro();
18
+ * // ...
19
+ * }
20
+ * ```
21
+ */
22
+ import { type ReactNode } from "react";
23
+ import { type SyntroInitOptions, type SyntroInitResult } from "./bootstrap";
24
+ import type { SmartCanvasHandle } from "./api";
25
+ import type { ExperimentClient } from "./experiments/types";
26
+ import type { TelemetryClient } from "./telemetry/types";
27
+ export interface SyntroContextValue {
28
+ /** The SmartCanvas handle */
29
+ canvas: SmartCanvasHandle | null;
30
+ /** The experiment client */
31
+ experiments: ExperimentClient | null;
32
+ /** The telemetry client */
33
+ telemetry: TelemetryClient | null;
34
+ /** Whether the SDK has finished initializing */
35
+ isReady: boolean;
36
+ /** Any error that occurred during initialization */
37
+ error: Error | null;
38
+ }
39
+ export interface SyntroProviderProps {
40
+ /**
41
+ * The Syntro token containing all credentials.
42
+ */
43
+ token: string;
44
+ /**
45
+ * Optional canvas configuration overrides.
46
+ */
47
+ canvasOptions?: SyntroInitOptions["canvas"];
48
+ /**
49
+ * Children to render.
50
+ */
51
+ children: ReactNode;
52
+ /**
53
+ * Called when initialization completes.
54
+ */
55
+ onReady?: (result: SyntroInitResult) => void;
56
+ /**
57
+ * Called when initialization fails.
58
+ */
59
+ onError?: (error: Error) => void;
60
+ }
61
+ /**
62
+ * Provider component that initializes the Syntro SDK.
63
+ *
64
+ * Place this at the root of your app or at the top of any subtree
65
+ * that needs access to the SDK.
66
+ */
67
+ export declare function SyntroProvider({ token, canvasOptions, children, onReady, onError, }: SyntroProviderProps): import("react/jsx-runtime").JSX.Element;
68
+ /**
69
+ * Hook to access the Syntro SDK.
70
+ *
71
+ * Must be used within a SyntroProvider.
72
+ *
73
+ * @returns The SDK context containing canvas, experiments, telemetry, and status
74
+ */
75
+ export declare function useSyntro(): SyntroContextValue;
76
+ /**
77
+ * Hook to check if the SDK is ready.
78
+ *
79
+ * Shorthand for `useSyntro().isReady`.
80
+ */
81
+ export declare function useSyntroReady(): boolean;
82
+ /**
83
+ * Hook to access the experiment client.
84
+ *
85
+ * @returns The experiment client, or null if not configured
86
+ */
87
+ export declare function useSyntroExperiments(): ExperimentClient | null;
88
+ /**
89
+ * Hook to access the telemetry client.
90
+ *
91
+ * @returns The telemetry client, or null if not configured
92
+ */
93
+ export declare function useSyntroTelemetry(): TelemetryClient | null;
94
+ /**
95
+ * Hook to access the canvas handle.
96
+ *
97
+ * @returns The canvas handle, or null if not ready
98
+ */
99
+ export declare function useSyntroCanvas(): SmartCanvasHandle | null;
package/dist/react.js ADDED
@@ -0,0 +1,119 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * React bindings for the Syntro SDK.
4
+ *
5
+ * Usage:
6
+ * ```tsx
7
+ * import { SyntroProvider, useSyntro } from '@syntrologie/runtime-sdk/react';
8
+ *
9
+ * function App() {
10
+ * return (
11
+ * <SyntroProvider token="syn_xxx">
12
+ * <MyApp />
13
+ * </SyntroProvider>
14
+ * );
15
+ * }
16
+ *
17
+ * function MyComponent() {
18
+ * const { canvas, experiments, telemetry, isReady } = useSyntro();
19
+ * // ...
20
+ * }
21
+ * ```
22
+ */
23
+ import { createContext, useContext, useEffect, useState, useRef, } from "react";
24
+ import { Syntro } from "./bootstrap";
25
+ const SyntroContext = createContext(null);
26
+ /**
27
+ * Provider component that initializes the Syntro SDK.
28
+ *
29
+ * Place this at the root of your app or at the top of any subtree
30
+ * that needs access to the SDK.
31
+ */
32
+ export function SyntroProvider({ token, canvasOptions, children, onReady, onError, }) {
33
+ const [state, setState] = useState({
34
+ canvas: null,
35
+ experiments: null,
36
+ telemetry: null,
37
+ isReady: false,
38
+ error: null,
39
+ });
40
+ const initRef = useRef(false);
41
+ const handleRef = useRef(null);
42
+ useEffect(() => {
43
+ if (!token || initRef.current)
44
+ return;
45
+ initRef.current = true;
46
+ Syntro.init({ token, canvas: canvasOptions })
47
+ .then((result) => {
48
+ var _a, _b;
49
+ handleRef.current = result.canvas;
50
+ setState({
51
+ canvas: result.canvas,
52
+ experiments: (_a = result.experiments) !== null && _a !== void 0 ? _a : null,
53
+ telemetry: (_b = result.telemetry) !== null && _b !== void 0 ? _b : null,
54
+ isReady: true,
55
+ error: null,
56
+ });
57
+ onReady === null || onReady === void 0 ? void 0 : onReady(result);
58
+ })
59
+ .catch((err) => {
60
+ const error = err instanceof Error ? err : new Error(String(err));
61
+ setState((prev) => ({ ...prev, error, isReady: true }));
62
+ onError === null || onError === void 0 ? void 0 : onError(error);
63
+ });
64
+ return () => {
65
+ if (handleRef.current) {
66
+ handleRef.current.destroy();
67
+ handleRef.current = null;
68
+ }
69
+ };
70
+ }, [token]);
71
+ return (_jsx(SyntroContext.Provider, { value: state, children: children }));
72
+ }
73
+ /**
74
+ * Hook to access the Syntro SDK.
75
+ *
76
+ * Must be used within a SyntroProvider.
77
+ *
78
+ * @returns The SDK context containing canvas, experiments, telemetry, and status
79
+ */
80
+ export function useSyntro() {
81
+ const context = useContext(SyntroContext);
82
+ if (!context) {
83
+ throw new Error("useSyntro must be used within a SyntroProvider");
84
+ }
85
+ return context;
86
+ }
87
+ /**
88
+ * Hook to check if the SDK is ready.
89
+ *
90
+ * Shorthand for `useSyntro().isReady`.
91
+ */
92
+ export function useSyntroReady() {
93
+ return useSyntro().isReady;
94
+ }
95
+ /**
96
+ * Hook to access the experiment client.
97
+ *
98
+ * @returns The experiment client, or null if not configured
99
+ */
100
+ export function useSyntroExperiments() {
101
+ return useSyntro().experiments;
102
+ }
103
+ /**
104
+ * Hook to access the telemetry client.
105
+ *
106
+ * @returns The telemetry client, or null if not configured
107
+ */
108
+ export function useSyntroTelemetry() {
109
+ return useSyntro().telemetry;
110
+ }
111
+ /**
112
+ * Hook to access the canvas handle.
113
+ *
114
+ * @returns The canvas handle, or null if not ready
115
+ */
116
+ export function useSyntroCanvas() {
117
+ return useSyntro().canvas;
118
+ }
119
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAc,EACZ,aAAa,EACb,UAAU,EACV,SAAS,EACT,QAAQ,EACR,MAAM,GAEP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,MAAM,EAAiD,MAAM,aAAa,CAAC;AAkBpF,MAAM,aAAa,GAAG,aAAa,CAA4B,IAAI,CAAC,CAAC;AA6BrE;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,KAAK,EACL,aAAa,EACb,QAAQ,EACR,OAAO,EACP,OAAO,GACa;IACpB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAqB;QACrD,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,IAAI;QACjB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,MAAM,SAAS,GAAG,MAAM,CAA2B,IAAI,CAAC,CAAC;IAEzD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC,OAAO;YAAE,OAAO;QACtC,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;QAEvB,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;aAC1C,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;;YACf,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC,MA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