@alliance-droid/status-feedback-system 1.3.14 → 1.4.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.
@@ -11,7 +11,7 @@
11
11
  } from '@alliance-droid/svelte-component-library';
12
12
  import DevContextMenu from './dev/DevContextMenu.svelte';
13
13
  import DevOnboardingToast from './dev/DevOnboardingToast.svelte';
14
- import { captureScreenshot } from './dev/screenshot.js';
14
+ import { captureScreenshot, type ScreenshotProvider } from './dev/screenshot.js';
15
15
  import {
16
16
  detectEnvironment,
17
17
  getEnvironmentName,
@@ -33,6 +33,14 @@
33
33
  boardUrl?: string;
34
34
  /** Authenticated user email. Required for submitting feedback. */
35
35
  userEmail?: string;
36
+ /**
37
+ * Custom screenshot provider. When supplied, this is called instead of
38
+ * the default html2canvas client-side capture. Use this to delegate
39
+ * screenshot capture to a server endpoint (e.g. Puppeteer / screenshot-service).
40
+ *
41
+ * See `createServerScreenshotProvider()` for a ready-made helper.
42
+ */
43
+ screenshotProvider?: ScreenshotProvider;
36
44
  }
37
45
 
38
46
  let {
@@ -43,6 +51,7 @@
43
51
  showOnboarding = true,
44
52
  boardUrl,
45
53
  userEmail,
54
+ screenshotProvider,
46
55
  }: Props = $props();
47
56
 
48
57
  // --- Client (lazy, stable) ---
@@ -225,7 +234,7 @@
225
234
  async function doScreenshot() {
226
235
  capturingScreenshot_ = true;
227
236
  screenshotFailed = false;
228
- screenshotData = await captureScreenshot();
237
+ screenshotData = await captureScreenshot(screenshotProvider);
229
238
  if (!screenshotData) screenshotFailed = true;
230
239
  capturingScreenshot_ = false;
231
240
  }
@@ -1,3 +1,4 @@
1
+ import { type ScreenshotProvider } from './dev/screenshot.js';
1
2
  interface Props {
2
3
  apiUrl: string;
3
4
  apiKey: string;
@@ -11,6 +12,14 @@ interface Props {
11
12
  boardUrl?: string;
12
13
  /** Authenticated user email. Required for submitting feedback. */
13
14
  userEmail?: string;
15
+ /**
16
+ * Custom screenshot provider. When supplied, this is called instead of
17
+ * the default html2canvas client-side capture. Use this to delegate
18
+ * screenshot capture to a server endpoint (e.g. Puppeteer / screenshot-service).
19
+ *
20
+ * See `createServerScreenshotProvider()` for a ready-made helper.
21
+ */
22
+ screenshotProvider?: ScreenshotProvider;
14
23
  }
15
24
  declare const DevFeedback: import("svelte").Component<Props, {}, "">;
16
25
  type DevFeedback = ReturnType<typeof DevFeedback>;
@@ -1,6 +1,36 @@
1
1
  /**
2
2
  * Screenshot capture utility for DevFeedback.
3
- * Dynamically imports html2canvas — gracefully degrades if not installed
4
- * (html2canvas is an optional peer dependency).
3
+ *
4
+ * Supports two modes:
5
+ * 1. Custom provider — consumer supplies a `ScreenshotProvider` callback
6
+ * (e.g. server-side capture via Puppeteer / screenshot-service).
7
+ * 2. html2canvas fallback — dynamically imports html2canvas if no provider
8
+ * is given (html2canvas is an optional peer dependency).
5
9
  */
6
- export declare function captureScreenshot(): Promise<string | null>;
10
+ /**
11
+ * A function that captures a screenshot and returns a data URL (or null on failure).
12
+ * Consumers can implement this however they like — server endpoint, different
13
+ * client library, canvas API, etc.
14
+ */
15
+ export type ScreenshotProvider = () => Promise<string | null>;
16
+ /**
17
+ * Capture a screenshot using the given provider, or fall back to html2canvas.
18
+ */
19
+ export declare function captureScreenshot(provider?: ScreenshotProvider): Promise<string | null>;
20
+ /**
21
+ * Create a screenshot provider that POSTs to a server endpoint.
22
+ *
23
+ * The endpoint receives `{ url, viewport }` and should return
24
+ * `{ screenshot: "data:image/..." }` (or any JSON with a `screenshot` string field).
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * <DevFeedback
29
+ * screenshotProvider={createServerScreenshotProvider('/api/screenshot')}
30
+ * ...
31
+ * />
32
+ * ```
33
+ */
34
+ export declare function createServerScreenshotProvider(endpoint: string, options?: {
35
+ headers?: Record<string, string>;
36
+ }): ScreenshotProvider;
@@ -1,9 +1,65 @@
1
1
  /**
2
2
  * Screenshot capture utility for DevFeedback.
3
- * Dynamically imports html2canvas — gracefully degrades if not installed
4
- * (html2canvas is an optional peer dependency).
3
+ *
4
+ * Supports two modes:
5
+ * 1. Custom provider — consumer supplies a `ScreenshotProvider` callback
6
+ * (e.g. server-side capture via Puppeteer / screenshot-service).
7
+ * 2. html2canvas fallback — dynamically imports html2canvas if no provider
8
+ * is given (html2canvas is an optional peer dependency).
5
9
  */
6
- export async function captureScreenshot() {
10
+ /**
11
+ * Capture a screenshot using the given provider, or fall back to html2canvas.
12
+ */
13
+ export async function captureScreenshot(provider) {
14
+ if (provider) {
15
+ try {
16
+ return await provider();
17
+ }
18
+ catch (err) {
19
+ console.error('[DevFeedback] Screenshot provider failed:', err);
20
+ return null;
21
+ }
22
+ }
23
+ return captureWithHtml2Canvas();
24
+ }
25
+ /**
26
+ * Create a screenshot provider that POSTs to a server endpoint.
27
+ *
28
+ * The endpoint receives `{ url, viewport }` and should return
29
+ * `{ screenshot: "data:image/..." }` (or any JSON with a `screenshot` string field).
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * <DevFeedback
34
+ * screenshotProvider={createServerScreenshotProvider('/api/screenshot')}
35
+ * ...
36
+ * />
37
+ * ```
38
+ */
39
+ export function createServerScreenshotProvider(endpoint, options) {
40
+ return async () => {
41
+ const res = await fetch(endpoint, {
42
+ method: 'POST',
43
+ headers: {
44
+ 'Content-Type': 'application/json',
45
+ ...options?.headers,
46
+ },
47
+ body: JSON.stringify({
48
+ url: window.location.href,
49
+ viewport: {
50
+ width: window.innerWidth,
51
+ height: window.innerHeight,
52
+ },
53
+ }),
54
+ });
55
+ if (!res.ok)
56
+ return null;
57
+ const data = await res.json();
58
+ return data.screenshot ?? null;
59
+ };
60
+ }
61
+ /** html2canvas fallback — gracefully degrades if not installed. */
62
+ async function captureWithHtml2Canvas() {
7
63
  try {
8
64
  const html2canvas = (await import('html2canvas')).default;
9
65
  const canvas = await html2canvas(document.body, {
@@ -25,7 +81,7 @@ export async function captureScreenshot() {
25
81
  return hasUnsupportedColor;
26
82
  },
27
83
  });
28
- return canvas.toDataURL('image/png');
84
+ return canvas.toDataURL('image/jpeg', 0.7);
29
85
  }
30
86
  catch (err) {
31
87
  console.error('[DevFeedback] Screenshot capture failed:', err);
package/dist/index.d.ts CHANGED
@@ -9,6 +9,8 @@
9
9
  */
10
10
  export type { Project, System, Incident, IncidentUpdate, Feedback, FeedbackResponse, FeedbackVisibility, StatusHistoryEntry, SystemStatus, IncidentStatus, IncidentSeverity, FeedbackStatus, ApiResponse, } from './types.js';
11
11
  export { deriveOverallStatus } from './utils.js';
12
+ export { createServerScreenshotProvider } from './components/dev/screenshot.js';
13
+ export type { ScreenshotProvider } from './components/dev/screenshot.js';
12
14
  export { createStatusClient } from './api.js';
13
15
  export type { StatusClient, StatusClientConfig, StatusData, IncidentData, UptimeData, BoardData, BoardItem, BoardCategory } from './api.js';
14
16
  export { default as StatusPage } from './components/StatusPage.svelte';
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@
9
9
  */
10
10
  // ── Utilities ──
11
11
  export { deriveOverallStatus } from './utils.js';
12
+ export { createServerScreenshotProvider } from './components/dev/screenshot.js';
12
13
  // ── API Client ──
13
14
  export { createStatusClient } from './api.js';
14
15
  // ── Client Components ──
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alliance-droid/status-feedback-system",
3
- "version": "1.3.14",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "description": "Drop-in system status pages and user feedback forms for SvelteKit apps",
6
6
  "svelte": "./dist/index.js",