@preprio/prepr-nextjs 1.3.2 → 2.0.0-alpha.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.
Files changed (54) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +55 -144
  3. package/dist/chunk-E7ATRJ2F.js +2 -0
  4. package/dist/chunk-E7ATRJ2F.js.map +1 -0
  5. package/dist/index.css +1 -0
  6. package/dist/metafile-cjs.json +1 -0
  7. package/dist/metafile-esm.json +1 -0
  8. package/dist/middleware/index.cjs +2 -0
  9. package/dist/middleware/index.cjs.map +1 -0
  10. package/dist/middleware/index.d.cts +10 -0
  11. package/dist/middleware/index.d.ts +10 -0
  12. package/dist/middleware/index.js +2 -0
  13. package/dist/middleware/index.js.map +1 -0
  14. package/dist/react/index.cjs +3 -0
  15. package/dist/react/index.cjs.map +1 -0
  16. package/dist/react/index.d.cts +226 -0
  17. package/dist/react/index.d.ts +226 -0
  18. package/dist/react/index.js +3 -0
  19. package/dist/react/index.js.map +1 -0
  20. package/dist/server/index.cjs +7 -0
  21. package/dist/server/index.cjs.map +1 -0
  22. package/dist/{index.d.mts → server/index.d.cts} +6 -17
  23. package/dist/{index.d.ts → server/index.d.ts} +6 -17
  24. package/dist/server/index.js +7 -0
  25. package/dist/server/index.js.map +1 -0
  26. package/dist/types/index.cjs +2 -0
  27. package/dist/types/index.cjs.map +1 -0
  28. package/dist/types/index.d.cts +14 -0
  29. package/dist/types/index.d.ts +14 -0
  30. package/dist/types/index.js +2 -0
  31. package/dist/types/index.js.map +1 -0
  32. package/dist/utils/index.cjs +2 -0
  33. package/dist/utils/index.cjs.map +1 -0
  34. package/dist/utils/index.d.cts +138 -0
  35. package/dist/utils/index.d.ts +138 -0
  36. package/dist/utils/index.js +2 -0
  37. package/dist/utils/index.js.map +1 -0
  38. package/package.json +104 -59
  39. package/dist/chunk-IQXHJV5O.mjs +0 -25
  40. package/dist/chunk-IQXHJV5O.mjs.map +0 -1
  41. package/dist/components.css +0 -430
  42. package/dist/components.css.map +0 -1
  43. package/dist/components.d.mts +0 -10
  44. package/dist/components.d.ts +0 -10
  45. package/dist/components.js +0 -415
  46. package/dist/components.js.map +0 -1
  47. package/dist/components.mjs +0 -388
  48. package/dist/components.mjs.map +0 -1
  49. package/dist/index.js +0 -325
  50. package/dist/index.js.map +0 -1
  51. package/dist/index.mjs +0 -279
  52. package/dist/index.mjs.map +0 -1
  53. package/dist/types-DmITW6Tn.d.mts +0 -6
  54. package/dist/types-DmITW6Tn.d.ts +0 -6
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/server/index.ts","../../package.json"],"names":["package_default","getPreprUUID","__async","headers","getActiveSegment","getActiveVariant","getPreprHeaders","newHeaders","value","key","getPreprEnvironmentSegments","token","_a","response","getPackageVersion","json","e","error","getPreviewBarProps","data","activeSegment","activeVariant"],"mappings":"iDAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,IAAA,OAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,IAAA,CAAA,CAAA,CAAA,EAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,KAAA,CAAA,CAAA,OAAA,CAAA,OAAA,CAAA,CAAA,CAAA,KAAA,CAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA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from 'next/headers';\nimport { PreprPreviewBarProps, PreprSegment } from '../types';\nimport pjson from '../../package.json';\n\n/**\n * Returns the Prepr Customer ID from the headers\n */\nexport async function getPreprUUID() {\n const headersList = await headers();\n return headersList.get('prepr-customer-id');\n}\n\n/**\n * Retuns the active segment from the headers\n */\nexport async function getActiveSegment() {\n const headersList = await headers();\n return headersList.get('Prepr-Segments');\n}\n\n/**\n * Returns the active variant from the headers\n */\nexport async function getActiveVariant() {\n const headersList = await headers();\n return headersList.get('Prepr-ABtesting');\n}\n\n/**\n * Helper function to retrieve Prepr headers (will filter out customer ID if in preview mode)\n */\nexport async function getPreprHeaders() {\n const newHeaders: {\n [key: string]: string;\n } = {};\n\n const headersList = await headers();\n\n headersList.forEach((value, key) => {\n if (key.startsWith('prepr')) {\n newHeaders[key] = value;\n }\n });\n\n return newHeaders;\n}\n\n/**\n * Fetches the segments from the Prepr API\n * @param token Prepr access token with scope 'segments'\n * @returns Array of PreprSegmentResponse\n */\nexport async function getPreprEnvironmentSegments(\n token: string\n): Promise<PreprSegment[]> {\n if (!token) {\n console.error(\n 'No token provided, make sure you are using your Prepr GraphQL URL'\n );\n return [];\n }\n\n if (!token.startsWith('https://')) {\n console.error(\n 'Invalid token provided, make sure you are using your Prepr GraphQL URL'\n );\n return [];\n }\n\n try {\n const response = await fetch(token, {\n headers: {\n 'User-Agent': `Prepr-Preview-Bar/${getPackageVersion()}`,\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n body: JSON.stringify({\n query: `{\n _Segments {\n _id\n name\n }\n }`,\n }),\n });\n try {\n const json = await response.json();\n\n if (!json || !json.data || !json.data._Segments) {\n return [];\n }\n\n return json.data?._Segments as PreprSegment[];\n } catch {\n console.error('Error parsing JSON, please contact Prepr support');\n return [];\n }\n } catch (error) {\n console.error('Error fetching segments:', error);\n return [];\n }\n}\n\n/**\n * Fetches all the necessary previewbar props\n * @param token Prepr access token with scope 'segments'\n * @returns Object with activeSegment, activeVariant and data\n */\nexport async function getPreviewBarProps(\n token: string\n): Promise<PreprPreviewBarProps> {\n let data: PreprSegment[] = [];\n let activeSegment: string | null = null;\n let activeVariant: string | null = null;\n\n // Prevent unnecessary function calling in production\n if (process.env.PREPR_ENV === 'preview') {\n data = await getPreprEnvironmentSegments(token);\n activeSegment = await getActiveSegment();\n activeVariant = await getActiveVariant();\n }\n\n return {\n activeSegment,\n activeVariant,\n data,\n };\n}\n\nfunction getPackageVersion() {\n return pjson.version;\n}\n","{\n \"name\": \"@preprio/prepr-nextjs\",\n \"version\": \"2.0.0-alpha.4\",\n \"description\": \"Next.js package for Prepr CMS preview functionality with advanced debugging and visual editing capabilities\",\n \"main\": \"dist/react/index.cjs\",\n \"types\": \"./dist/react/index.d.ts\",\n \"module\": \"./dist/react/index.js\",\n \"type\": \"module\",\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"dev:css\": \"postcss ./src/globals.css -o ./src/output.css --watch\",\n \"build:css\": \"NODE_ENV=production postcss ./src/globals.css -o ./dist/index.css\",\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\",\n \"clean\": \"rm -rf dist\",\n \"format\": \"prettier --write \\\"src/**/*.{ts,tsx,js,jsx,json,md}\\\"\",\n \"format:check\": \"prettier --check \\\"src/**/*.{ts,tsx,js,jsx,json,md}\\\"\",\n \"release\": \"node scripts/release.js\",\n \"check\": \"npm run type-check && npm run lint:check && npm run format:check\",\n \"type-check\": \"tsc --noEmit\",\n \"lint\": \"eslint src --ext .ts,.tsx --fix\",\n \"lint:check\": \"eslint src --ext .ts,.tsx\",\n \"prepublishOnly\": \"npm run check && npm run build\"\n },\n \"exports\": {\n \"./middleware\": {\n \"import\": \"./dist/middleware/index.js\",\n \"types\": \"./dist/middleware/index.d.ts\",\n \"require\": \"./dist/middleware/index.cjs\"\n },\n \"./server\": {\n \"import\": \"./dist/server/index.js\",\n \"types\": \"./dist/server/index.d.ts\",\n \"require\": \"./dist/server/index.cjs\"\n },\n \"./react\": {\n \"import\": \"./dist/react/index.js\",\n \"types\": \"./dist/react/index.d.ts\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./contexts\": {\n \"import\": \"./dist/contexts/index.js\",\n \"types\": \"./dist/contexts/index.d.ts\",\n \"require\": \"./dist/contexts/index.cjs\"\n },\n \"./utils\": {\n \"import\": \"./dist/utils/index.js\",\n \"types\": \"./dist/utils/index.d.ts\",\n \"require\": \"./dist/utils/index.cjs\"\n },\n \"./types\": {\n \"import\": \"./dist/types/index.js\",\n \"types\": \"./dist/types/index.d.ts\",\n \"require\": \"./dist/types/index.cjs\"\n },\n \"./index.css\": {\n \"import\": \"./dist/index.css\",\n \"require\": \"./dist/index.css\"\n }\n },\n \"files\": [\n \"dist\",\n \"package.json\"\n ],\n \"keywords\": [\n \"prepr\",\n \"cms\",\n \"nextjs\",\n \"preview\",\n \"visual-editing\",\n \"headless-cms\",\n \"react\",\n \"typescript\",\n \"debug\",\n \"stega\"\n ],\n \"author\": \"Preprio\",\n \"license\": \"MIT\",\n \"packageManager\": \"pnpm@10.5.2\",\n \"devDependencies\": {\n \"@eslint/js\": \"^9.25.1\",\n \"@types/node\": \"^20.11.5\",\n \"@types/react\": \"19.1.0\",\n \"@types/react-dom\": \"19.1.2\",\n \"@typescript-eslint/eslint-plugin\": \"^8.31.1\",\n \"@typescript-eslint/parser\": \"^8.31.1\",\n \"autoprefixer\": \"^10.4.21\",\n \"cssnano\": \"^7.0.7\",\n \"eslint\": \"^9.25.1\",\n \"eslint-config-prettier\": \"^10.1.2\",\n \"eslint-plugin-prettier\": \"^5.2.6\",\n \"eslint-plugin-react\": \"^7.37.2\",\n \"eslint-plugin-react-hooks\": \"^5.0.0\",\n \"next\": \"15.3.1\",\n \"postcss\": \"^8\",\n \"prettier\": \"^3.5.3\",\n \"prettier-plugin-tailwindcss\": \"^0.5.12\",\n \"react\": \"^19.1.0\",\n \"react-dom\": \"^19.1.0\",\n \"tailwindcss\": \"^3.4.17\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^5.8.3\"\n },\n \"peerDependencies\": {\n \"next\": \"^15.0.0 || ^14.0.0 || ^13.0.0\",\n \"react\": \"^19.0.0 || ^18.0.0 || ^17.0.0 \",\n \"react-dom\": \"^19.0.0 || ^18.0.0 || ^17.0.0\"\n },\n \"dependencies\": {\n \"@headlessui/react\": \"^2.2.0\",\n \"@vercel/functions\": \"^2.0.0\",\n \"@vercel/stega\": \"^0.1.2\",\n \"clsx\": \"^2.1.1\",\n \"postcss-cli\": \"^11.0.1\",\n \"tailwind-merge\": \"^3.0.1\"\n }\n}\n"]}
@@ -1,24 +1,17 @@
1
- import { NextResponse } from 'next/server';
2
- import { P as PreprSegment } from './types-DmITW6Tn.mjs';
1
+ import { PreprSegment, PreprPreviewBarProps } from '../types/index.cjs';
3
2
 
4
- /**
5
- *
6
- * @param request NextRequest object
7
- * @param response optional NextResponse object
8
- */
9
- declare function PreprMiddleware(request: any): NextResponse<unknown>;
10
3
  /**
11
4
  * Returns the Prepr Customer ID from the headers
12
5
  */
13
- declare function getPreprUUID(): Promise<string>;
6
+ declare function getPreprUUID(): Promise<string | null>;
14
7
  /**
15
8
  * Retuns the active segment from the headers
16
9
  */
17
- declare function getActiveSegment(): Promise<string>;
10
+ declare function getActiveSegment(): Promise<string | null>;
18
11
  /**
19
12
  * Returns the active variant from the headers
20
13
  */
21
- declare function getActiveVariant(): Promise<string>;
14
+ declare function getActiveVariant(): Promise<string | null>;
22
15
  /**
23
16
  * Helper function to retrieve Prepr headers (will filter out customer ID if in preview mode)
24
17
  */
@@ -36,10 +29,6 @@ declare function getPreprEnvironmentSegments(token: string): Promise<PreprSegmen
36
29
  * @param token Prepr access token with scope 'segments'
37
30
  * @returns Object with activeSegment, activeVariant and data
38
31
  */
39
- declare function getPreviewBarProps(token: string): Promise<{
40
- activeSegment: string | null;
41
- activeVariant: string | null;
42
- data: PreprSegment[];
43
- }>;
32
+ declare function getPreviewBarProps(token: string): Promise<PreprPreviewBarProps>;
44
33
 
45
- export { PreprMiddleware, getActiveSegment, getActiveVariant, getPreprEnvironmentSegments, getPreprHeaders, getPreprUUID, getPreviewBarProps };
34
+ export { getActiveSegment, getActiveVariant, getPreprEnvironmentSegments, getPreprHeaders, getPreprUUID, getPreviewBarProps };
@@ -1,24 +1,17 @@
1
- import { NextResponse } from 'next/server';
2
- import { P as PreprSegment } from './types-DmITW6Tn.js';
1
+ import { PreprSegment, PreprPreviewBarProps } from '../types/index.js';
3
2
 
4
- /**
5
- *
6
- * @param request NextRequest object
7
- * @param response optional NextResponse object
8
- */
9
- declare function PreprMiddleware(request: any): NextResponse<unknown>;
10
3
  /**
11
4
  * Returns the Prepr Customer ID from the headers
12
5
  */
13
- declare function getPreprUUID(): Promise<string>;
6
+ declare function getPreprUUID(): Promise<string | null>;
14
7
  /**
15
8
  * Retuns the active segment from the headers
16
9
  */
17
- declare function getActiveSegment(): Promise<string>;
10
+ declare function getActiveSegment(): Promise<string | null>;
18
11
  /**
19
12
  * Returns the active variant from the headers
20
13
  */
21
- declare function getActiveVariant(): Promise<string>;
14
+ declare function getActiveVariant(): Promise<string | null>;
22
15
  /**
23
16
  * Helper function to retrieve Prepr headers (will filter out customer ID if in preview mode)
24
17
  */
@@ -36,10 +29,6 @@ declare function getPreprEnvironmentSegments(token: string): Promise<PreprSegmen
36
29
  * @param token Prepr access token with scope 'segments'
37
30
  * @returns Object with activeSegment, activeVariant and data
38
31
  */
39
- declare function getPreviewBarProps(token: string): Promise<{
40
- activeSegment: string | null;
41
- activeVariant: string | null;
42
- data: PreprSegment[];
43
- }>;
32
+ declare function getPreviewBarProps(token: string): Promise<PreprPreviewBarProps>;
44
33
 
45
- export { PreprMiddleware, getActiveSegment, getActiveVariant, getPreprEnvironmentSegments, getPreprHeaders, getPreprUUID, getPreviewBarProps };
34
+ export { getActiveSegment, getActiveVariant, getPreprEnvironmentSegments, getPreprHeaders, getPreprUUID, getPreviewBarProps };
@@ -0,0 +1,7 @@
1
+ import {c as c$1}from'../chunk-E7ATRJ2F.js';import {headers}from'next/headers';var c={version:"2.0.0-alpha.4"};function x(){return c$1(this,null,function*(){return (yield headers()).get("prepr-customer-id")})}function p(){return c$1(this,null,function*(){return (yield headers()).get("Prepr-Segments")})}function d(){return c$1(this,null,function*(){return (yield headers()).get("Prepr-ABtesting")})}function h(){return c$1(this,null,function*(){let e={};return (yield headers()).forEach((s,t)=>{t.startsWith("prepr")&&(e[t]=s);}),e})}function o(e){return c$1(this,null,function*(){var i;if(!e)return console.error("No token provided, make sure you are using your Prepr GraphQL URL"),[];if(!e.startsWith("https://"))return console.error("Invalid token provided, make sure you are using your Prepr GraphQL URL"),[];try{let s=yield fetch(e,{headers:{"User-Agent":`Prepr-Preview-Bar/${u()}`,"Content-Type":"application/json"},method:"POST",body:JSON.stringify({query:`{
2
+ _Segments {
3
+ _id
4
+ name
5
+ }
6
+ }`})});try{let t=yield s.json();return !t||!t.data||!t.data._Segments?[]:(i=t.data)==null?void 0:i._Segments}catch(t){return console.error("Error parsing JSON, please contact Prepr support"),[]}}catch(s){return console.error("Error fetching segments:",s),[]}})}function y(e){return c$1(this,null,function*(){let i=[],s=null,t=null;return process.env.PREPR_ENV==="preview"&&(i=yield o(e),s=yield p(),t=yield d()),{activeSegment:s,activeVariant:t,data:i}})}function u(){return c.version}export{p as getActiveSegment,d as getActiveVariant,o as getPreprEnvironmentSegments,h as getPreprHeaders,x as getPreprUUID,y as getPreviewBarProps};//# sourceMappingURL=index.js.map
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../package.json","../../src/server/index.ts"],"names":["package_default","getPreprUUID","__async","headers","getActiveSegment","getActiveVariant","getPreprHeaders","newHeaders","value","key","getPreprEnvironmentSegments","token","_a","response","getPackageVersion","json","e","error","getPreviewBarProps","data","activeSegment","activeVariant"],"mappings":"+EAAA,IAAAA,CAAAA,CAAA,CAEE,OAAA,CAAW,eAkHb,EC7GA,SAAsBC,CAAAA,EAAe,CAAA,OAAAC,GAAAA,CA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AA;AAAA;AAAA,aAAA,CAMT,CAAC,CACH,CAAC,CAAA,CACD,GAAI,CACF,IAAMC,EAAO,MAAMF,CAAAA,CAAS,MAAK,CAEjC,OAAI,CAACE,CAAAA,EAAQ,CAACA,EAAK,IAAA,EAAQ,CAACA,CAAAA,CAAK,IAAA,CAAK,SAAA,CAC7B,IAGFH,CAAAA,CAAAG,CAAAA,CAAK,OAAL,IAAA,CAAA,KAAA,CAAA,CAAAH,CAAAA,CAAW,SACpB,CAAA,MAAQI,CAAAA,CAAA,CACN,OAAA,OAAA,CAAQ,KAAA,CAAM,kDAAkD,EACzD,EACT,CACF,CAAA,MAASC,CAAAA,CAAO,CACd,OAAA,OAAA,CAAQ,KAAA,CAAM,0BAAA,CAA4BA,CAAK,CAAA,CACxC,EACT,CACF,CAAA,CAAA,CAOA,SAAsBC,CAAAA,CACpBP,CAAAA,CAC+B,QAAAT,GAAAA,CAAA,IAAA,CAAA,IAAA,CAAA,WAAA,CAC/B,IAAIiB,CAAAA,CAAuB,GACvBC,CAAAA,CAA+B,IAAA,CAC/BC,EAA+B,IAAA,CAGnC,OAAI,QAAQ,GAAA,CAAI,SAAA,GAAc,SAAA,GAC5BF,CAAAA,CAAO,MAAMT,CAAAA,CAA4BC,CAAK,CAAA,CAC9CS,CAAAA,CAAgB,MAAMhB,CAAAA,EAAiB,CACvCiB,EAAgB,MAAMhB,CAAAA,EAAiB,CAAA,CAGlC,CACL,aAAA,CAAAe,CAAAA,CACA,cAAAC,CAAAA,CACA,IAAA,CAAAF,CACF,CACF,CAAA,CAAA,CAEA,SAASL,CAAAA,EAAoB,CAC3B,OAAOd,CAAAA,CAAM,OACf","file":"index.js","sourcesContent":["{\n \"name\": \"@preprio/prepr-nextjs\",\n \"version\": \"2.0.0-alpha.4\",\n \"description\": \"Next.js package for Prepr CMS preview functionality with advanced debugging and visual editing capabilities\",\n \"main\": \"dist/react/index.cjs\",\n \"types\": \"./dist/react/index.d.ts\",\n \"module\": \"./dist/react/index.js\",\n \"type\": \"module\",\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"dev:css\": \"postcss ./src/globals.css -o ./src/output.css --watch\",\n \"build:css\": \"NODE_ENV=production postcss ./src/globals.css -o ./dist/index.css\",\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\",\n \"clean\": \"rm -rf dist\",\n \"format\": \"prettier --write \\\"src/**/*.{ts,tsx,js,jsx,json,md}\\\"\",\n \"format:check\": \"prettier --check \\\"src/**/*.{ts,tsx,js,jsx,json,md}\\\"\",\n \"release\": \"node scripts/release.js\",\n \"check\": \"npm run type-check && npm run lint:check && npm run format:check\",\n \"type-check\": \"tsc --noEmit\",\n \"lint\": \"eslint src --ext .ts,.tsx --fix\",\n \"lint:check\": \"eslint src --ext .ts,.tsx\",\n \"prepublishOnly\": \"npm run check && npm run build\"\n },\n \"exports\": {\n \"./middleware\": {\n \"import\": \"./dist/middleware/index.js\",\n \"types\": \"./dist/middleware/index.d.ts\",\n \"require\": \"./dist/middleware/index.cjs\"\n },\n \"./server\": {\n \"import\": \"./dist/server/index.js\",\n \"types\": \"./dist/server/index.d.ts\",\n \"require\": \"./dist/server/index.cjs\"\n },\n \"./react\": {\n \"import\": \"./dist/react/index.js\",\n \"types\": \"./dist/react/index.d.ts\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./contexts\": {\n \"import\": \"./dist/contexts/index.js\",\n \"types\": \"./dist/contexts/index.d.ts\",\n \"require\": \"./dist/contexts/index.cjs\"\n },\n \"./utils\": {\n \"import\": \"./dist/utils/index.js\",\n \"types\": \"./dist/utils/index.d.ts\",\n \"require\": \"./dist/utils/index.cjs\"\n },\n \"./types\": {\n \"import\": \"./dist/types/index.js\",\n \"types\": \"./dist/types/index.d.ts\",\n \"require\": \"./dist/types/index.cjs\"\n },\n \"./index.css\": {\n \"import\": \"./dist/index.css\",\n \"require\": \"./dist/index.css\"\n }\n },\n \"files\": [\n \"dist\",\n \"package.json\"\n ],\n \"keywords\": [\n \"prepr\",\n \"cms\",\n \"nextjs\",\n \"preview\",\n \"visual-editing\",\n \"headless-cms\",\n \"react\",\n \"typescript\",\n \"debug\",\n \"stega\"\n ],\n \"author\": \"Preprio\",\n \"license\": \"MIT\",\n \"packageManager\": \"pnpm@10.5.2\",\n \"devDependencies\": {\n \"@eslint/js\": \"^9.25.1\",\n \"@types/node\": \"^20.11.5\",\n \"@types/react\": \"19.1.0\",\n \"@types/react-dom\": \"19.1.2\",\n \"@typescript-eslint/eslint-plugin\": \"^8.31.1\",\n \"@typescript-eslint/parser\": \"^8.31.1\",\n \"autoprefixer\": \"^10.4.21\",\n \"cssnano\": \"^7.0.7\",\n \"eslint\": \"^9.25.1\",\n \"eslint-config-prettier\": \"^10.1.2\",\n \"eslint-plugin-prettier\": \"^5.2.6\",\n \"eslint-plugin-react\": \"^7.37.2\",\n \"eslint-plugin-react-hooks\": \"^5.0.0\",\n \"next\": \"15.3.1\",\n \"postcss\": \"^8\",\n \"prettier\": \"^3.5.3\",\n \"prettier-plugin-tailwindcss\": \"^0.5.12\",\n \"react\": \"^19.1.0\",\n \"react-dom\": \"^19.1.0\",\n \"tailwindcss\": \"^3.4.17\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^5.8.3\"\n },\n \"peerDependencies\": {\n \"next\": \"^15.0.0 || ^14.0.0 || ^13.0.0\",\n \"react\": \"^19.0.0 || ^18.0.0 || ^17.0.0 \",\n \"react-dom\": \"^19.0.0 || ^18.0.0 || ^17.0.0\"\n },\n \"dependencies\": {\n \"@headlessui/react\": \"^2.2.0\",\n \"@vercel/functions\": \"^2.0.0\",\n \"@vercel/stega\": \"^0.1.2\",\n \"clsx\": \"^2.1.1\",\n \"postcss-cli\": \"^11.0.1\",\n \"tailwind-merge\": \"^3.0.1\"\n }\n}\n","import { headers } from 'next/headers';\nimport { PreprPreviewBarProps, PreprSegment } from '../types';\nimport pjson from '../../package.json';\n\n/**\n * Returns the Prepr Customer ID from the headers\n */\nexport async function getPreprUUID() {\n const headersList = await headers();\n return headersList.get('prepr-customer-id');\n}\n\n/**\n * Retuns the active segment from the headers\n */\nexport async function getActiveSegment() {\n const headersList = await headers();\n return headersList.get('Prepr-Segments');\n}\n\n/**\n * Returns the active variant from the headers\n */\nexport async function getActiveVariant() {\n const headersList = await headers();\n return headersList.get('Prepr-ABtesting');\n}\n\n/**\n * Helper function to retrieve Prepr headers (will filter out customer ID if in preview mode)\n */\nexport async function getPreprHeaders() {\n const newHeaders: {\n [key: string]: string;\n } = {};\n\n const headersList = await headers();\n\n headersList.forEach((value, key) => {\n if (key.startsWith('prepr')) {\n newHeaders[key] = value;\n }\n });\n\n return newHeaders;\n}\n\n/**\n * Fetches the segments from the Prepr API\n * @param token Prepr access token with scope 'segments'\n * @returns Array of PreprSegmentResponse\n */\nexport async function getPreprEnvironmentSegments(\n token: string\n): Promise<PreprSegment[]> {\n if (!token) {\n console.error(\n 'No token provided, make sure you are using your Prepr GraphQL URL'\n );\n return [];\n }\n\n if (!token.startsWith('https://')) {\n console.error(\n 'Invalid token provided, make sure you are using your Prepr GraphQL URL'\n );\n return [];\n }\n\n try {\n const response = await fetch(token, {\n headers: {\n 'User-Agent': `Prepr-Preview-Bar/${getPackageVersion()}`,\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n body: JSON.stringify({\n query: `{\n _Segments {\n _id\n name\n }\n }`,\n }),\n });\n try {\n const json = await response.json();\n\n if (!json || !json.data || !json.data._Segments) {\n return [];\n }\n\n return json.data?._Segments as PreprSegment[];\n } catch {\n console.error('Error parsing JSON, please contact Prepr support');\n return [];\n }\n } catch (error) {\n console.error('Error fetching segments:', error);\n return [];\n }\n}\n\n/**\n * Fetches all the necessary previewbar props\n * @param token Prepr access token with scope 'segments'\n * @returns Object with activeSegment, activeVariant and data\n */\nexport async function getPreviewBarProps(\n token: string\n): Promise<PreprPreviewBarProps> {\n let data: PreprSegment[] = [];\n let activeSegment: string | null = null;\n let activeVariant: string | null = null;\n\n // Prevent unnecessary function calling in production\n if (process.env.PREPR_ENV === 'preview') {\n data = await getPreprEnvironmentSegments(token);\n activeSegment = await getActiveSegment();\n activeVariant = await getActiveVariant();\n }\n\n return {\n activeSegment,\n activeVariant,\n data,\n };\n}\n\nfunction getPackageVersion() {\n return pjson.version;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ 'use strict';//# sourceMappingURL=index.cjs.map
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
@@ -0,0 +1,14 @@
1
+ type PreprSegment = {
2
+ _id: string;
3
+ name: string;
4
+ };
5
+ type PreprPreviewBarOptions = {
6
+ debug?: boolean;
7
+ };
8
+ type PreprPreviewBarProps = {
9
+ activeSegment: string | null;
10
+ activeVariant: string | null;
11
+ data: PreprSegment[];
12
+ };
13
+
14
+ export type { PreprPreviewBarOptions, PreprPreviewBarProps, PreprSegment };
@@ -0,0 +1,14 @@
1
+ type PreprSegment = {
2
+ _id: string;
3
+ name: string;
4
+ };
5
+ type PreprPreviewBarOptions = {
6
+ debug?: boolean;
7
+ };
8
+ type PreprPreviewBarProps = {
9
+ activeSegment: string | null;
10
+ activeVariant: string | null;
11
+ data: PreprSegment[];
12
+ };
13
+
14
+ export type { PreprPreviewBarOptions, PreprPreviewBarProps, PreprSegment };
@@ -0,0 +1,2 @@
1
+ //# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,2 @@
1
+ 'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge');var b=Object.defineProperty,L=Object.defineProperties;var x=Object.getOwnPropertyDescriptors;var f=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;var D=(r,e,t)=>e in r?b(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t,a=(r,e)=>{for(var t in e||(e={}))v.call(e,t)&&D(r,t,e[t]);if(f)for(var t of f(e))w.call(e,t)&&D(r,t,e[t]);return r},h=(r,e)=>L(r,x(e));var u={DECODE_FAILED:"STEGA_DECODE_FAILED",INVALID_FORMAT:"STEGA_INVALID_FORMAT",DOM_MANIPULATION_FAILED:"DOM_MANIPULATION_FAILED",CONTEXT_NOT_FOUND:"CONTEXT_NOT_FOUND"};function p(r,e,t,n){return {type:r,context:e,message:t.message,timestamp:new Date().toISOString(),stack:t.stack,additionalData:n}}function M(r,e,t){let n=p(u.DECODE_FAILED,e,r,t);return console.error("Stega Error:",n),process.env.NODE_ENV,n}function s(r,e){let t=p(u.DOM_MANIPULATION_FAILED,e,r);return console.error("DOM Error:",t),t}function I(r){let e=new Error(`${r} must be used within its provider`),t=p(u.CONTEXT_NOT_FOUND,r,e);throw console.error("Context Error:",t),e}var T=class{static createElement(e,t){try{let n=document.createElement(e);return n.className=t,n}catch(n){throw s(n,"createElement"),n}}static appendToBody(e){try{document.body.appendChild(e);}catch(t){throw s(t,"appendToBody"),t}}static removeFromBody(e){try{e.parentNode&&e.parentNode.removeChild(e);}catch(t){throw s(t,"removeFromBody"),t}}static setElementStyles(e,t){try{Object.entries(t).forEach(([n,o])=>{e.style.setProperty(n,o);});}catch(n){throw s(n,"setElementStyles"),n}}static getElementRect(e){try{return e.getBoundingClientRect()}catch(t){throw s(t,"getElementRect"),t}}static isElementInViewport(e){try{let t=this.getElementRect(e);return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)}catch(t){return s(t,"isElementInViewport"),false}}static calculateDistance(e,t,n,o){return Math.sqrt(Math.pow(n-e,2)+Math.pow(o-t,2))}static findClosestElement(e,t,n){try{let o=null,i=1/0;return n.forEach(d=>{let c=this.getElementRect(d),m=this.calculateDistance(e,t,c.left+c.width/2,c.top+c.height/2);m<i&&(i=m,o=d);}),o}catch(o){return s(o,"findClosestElement"),null}}static addEventListener(e,t,n,o){try{e.addEventListener(t,n,o);}catch(i){throw s(i,"addEventListener"),i}}static removeEventListener(e,t,n,o){try{e.removeEventListener(t,n,o);}catch(i){throw s(i,"removeEventListener"),i}}};var g=class r{constructor(e){this.options=a({prefix:"[Prepr]"},e);}log(e,...t){if(!this.options.enabled)return;let n=this.options.prefix;console.log(`${n} ${e}`,...t);}warn(e,...t){if(!this.options.enabled)return;let n=this.options.prefix;console.warn(`${n} ${e}`,...t);}error(e,...t){if(!this.options.enabled)return;let n=this.options.prefix;console.error(`${n} ${e}`,...t);}scope(e){return new r(h(a({},this.options),{prefix:`${this.options.prefix}[${e}]`}))}},l=null;function S(r=false){l=new g({enabled:r});}function E(){return l||(l=new g({enabled:false})),l}function H(r,...e){E().log(r,...e);}function F(r,...e){E().warn(r,...e);}function P(r,...e){E().error(r,...e);}function R(r){return E().scope(r)}function V(r,e){let t=null,n=0;return (...o)=>{let i=Date.now();i-n>e?(r(...o),n=i):(t&&clearTimeout(t),t=setTimeout(()=>{r(...o),n=Date.now();},e-(i-n)));}}function U(r,e=1e3){let t=null,n=0;return ()=>{let o=Date.now();return (!t||o-n>e)&&(t=document.querySelectorAll(r),n=o),t}}function q(...r){return tailwindMerge.twMerge(clsx.clsx(r))}function G(r,e){window.parent.postMessage(a({name:"prepr_preview_bar",event:r},e));}exports.DOMService=T;exports.StegaError=u;exports.cn=q;exports.createElementCache=U;exports.createErrorInfo=p;exports.createScopedLogger=R;exports.debugError=P;exports.debugLog=H;exports.debugWarn=F;exports.getDebugLogger=E;exports.handleContextError=I;exports.handleDOMError=s;exports.handleStegaError=M;exports.initDebugLogger=S;exports.sendPreprEvent=G;exports.throttle=V;//# sourceMappingURL=index.cjs.map
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/index.ts","../../src/utils/errors.ts","../../src/utils/dom.ts","../../src/utils/debug.ts","../../src/utils/performance.ts"],"names":["StegaError","createErrorInfo","type","context","error","additionalData","handleStegaError","errorInfo","handleDOMError","handleContextError","contextName","DOMService","tag","className","element","styles","property","value","rect","x1","y1","x2","y2","pointX","pointY","elements","closestElement","minDistance","distance","event","handler","options","DebugLogger","_DebugLogger","__spreadValues","message","args","prefix","scopeName","__spreadProps","globalDebugLogger","initDebugLogger","enabled","getDebugLogger","debugLog","debugWarn","debugError","createScopedLogger","throttle","func","delay","timeoutId","lastExecTime","currentTime","createElementCache","query","ttl","cache","lastCacheTime","now","cn","inputs","twMerge","clsx","sendPreprEvent","data"],"mappings":"8EAAA,IAAA,CAAA,CAAA,MAAA,CAAA,cAAA,CAAA,CAAA,CAAA,MAAA,CAAA,gBAAA,CAAA,IAAA,CAAA,CAAA,MAAA,CAAA,yBAAA,CAAA,IAAA,CAAA,CAAA,MAAA,CAAA,qBAAA,CAAA,IAAA,CAAA,CAAA,MAAA,CAAA,SAAA,CAAA,cAAA,CAAA,CAAA,CAAA,MAAA,CAAA,SAAA,CAAA,oBAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,UAAA,CAAA,IAAA,CAAA,YAAA,CAAA,IAAA,CAAA,QAAA,CAAA,IAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,IAAA,IAAA,CAAA,IAAA,CAAA,GAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,IAAA,IAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAAA,CAAA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,CAAAA,CAAc,IAAA,CAAK,KAAI,CACzBA,CAAAA,CAAcD,CAAAA,CAAeF,CAAAA,EAC/BD,EAAK,GAAIb,CAAsB,EAC/BgB,CAAAA,CAAeC,CAAAA,GAEXF,GAAW,YAAA,CAAaA,CAAS,EACrCA,CAAAA,CAAY,UAAA,CACV,IAAM,CACJF,CAAAA,CAAK,GAAIb,CAAsB,CAAA,CAC/BgB,EAAe,IAAA,CAAK,GAAA,GACtB,CAAA,CACAF,CAAAA,EAASG,EAAcD,CAAAA,CACzB,CAAA,EAEJ,CACF,CAGO,SAASE,EACdC,CAAAA,CACAC,CAAAA,CAAc,IACd,CACA,IAAIC,EAA8B,IAAA,CAC9BC,CAAAA,CAAgB,EACpB,OAAO,IAAM,CACX,IAAMC,CAAAA,CAAM,IAAA,CAAK,GAAA,GACjB,OAAA,CAAI,CAACF,GAASE,CAAAA,CAAMD,CAAAA,CAAgBF,KAClCC,CAAAA,CAAQ,QAAA,CAAS,iBAAoBF,CAAK,CAAA,CAC1CG,EAAgBC,CAAAA,CAAAA,CAEXF,CACT,CACF,CJxCO,SAASG,KAAMC,CAAAA,CAAsB,CAC1C,OAAOC,qBAAAA,CAAQC,SAAAA,CAAKF,CAAM,CAAC,CAC7B,CAUO,SAASG,CAAAA,CAAenC,EAAeoC,CAAAA,CAAuB,CACnE,OAAO,MAAA,CAAO,WAAA,CAAY/B,EAAA,CACxB,IAAA,CAAM,oBACN,KAAA,CAAAL,CAAAA,CAAAA,CACGoC,EACJ,EACH","file":"index.cjs","sourcesContent":["import { ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\n// Define specific types for Prepr events\nexport interface PreprEventData {\n segment?: string;\n variant?: string;\n editMode?: boolean;\n [key: string]: string | boolean | number | undefined;\n}\n\nexport function sendPreprEvent(event: string, data?: PreprEventData) {\n window.parent.postMessage({\n name: 'prepr_preview_bar',\n event,\n ...data,\n });\n}\n\n// Export error handling utilities\nexport * from './errors';\n\n// Export DOM service\nexport * from './dom';\n\n// Export debug utilities\nexport * from './debug';\n\n// Export performance utilities\nexport * from './performance';\n","export const StegaError = {\n DECODE_FAILED: 'STEGA_DECODE_FAILED',\n INVALID_FORMAT: 'STEGA_INVALID_FORMAT',\n DOM_MANIPULATION_FAILED: 'DOM_MANIPULATION_FAILED',\n CONTEXT_NOT_FOUND: 'CONTEXT_NOT_FOUND',\n} as const;\n\nexport type StegaErrorType = (typeof StegaError)[keyof typeof StegaError];\n\n// Define specific types for error additional data\nexport interface ErrorAdditionalData {\n input?: string;\n element?: HTMLElement;\n context?: string;\n [key: string]: string | HTMLElement | undefined;\n}\n\nexport interface ErrorInfo {\n type: StegaErrorType;\n context: string;\n message: string;\n timestamp: string;\n stack?: string;\n additionalData?: ErrorAdditionalData;\n}\n\nexport function createErrorInfo(\n type: StegaErrorType,\n context: string,\n error: Error,\n additionalData?: ErrorAdditionalData\n): ErrorInfo {\n return {\n type,\n context,\n message: error.message,\n timestamp: new Date().toISOString(),\n stack: error.stack,\n additionalData,\n };\n}\n\nexport function handleStegaError(\n error: Error,\n context: string,\n additionalData?: ErrorAdditionalData\n) {\n const errorInfo = createErrorInfo(\n StegaError.DECODE_FAILED,\n context,\n error,\n additionalData\n );\n\n console.error('Stega Error:', errorInfo);\n\n // In production, you might want to send this to an error tracking service\n if (process.env.NODE_ENV === 'production') {\n // sendToErrorTrackingService(errorInfo);\n }\n\n return errorInfo;\n}\n\nexport function handleDOMError(error: Error, context: string) {\n const errorInfo = createErrorInfo(\n StegaError.DOM_MANIPULATION_FAILED,\n context,\n error\n );\n\n console.error('DOM Error:', errorInfo);\n return errorInfo;\n}\n\nexport function handleContextError(contextName: string) {\n const error = new Error(`${contextName} must be used within its provider`);\n const errorInfo = createErrorInfo(\n StegaError.CONTEXT_NOT_FOUND,\n contextName,\n error\n );\n\n console.error('Context Error:', errorInfo);\n throw error;\n}\n","import { handleDOMError } from './errors';\n\nexport class DOMService {\n /**\n * Creates an HTML element with specified tag and class name\n */\n static createElement(tag: string, className: string): HTMLElement {\n try {\n const element = document.createElement(tag);\n element.className = className;\n return element;\n } catch (error) {\n handleDOMError(error as Error, 'createElement');\n throw error;\n }\n }\n\n /**\n * Appends an element to the document body\n */\n static appendToBody(element: HTMLElement): void {\n try {\n document.body.appendChild(element);\n } catch (error) {\n handleDOMError(error as Error, 'appendToBody');\n throw error;\n }\n }\n\n /**\n * Removes an element from the document body\n */\n static removeFromBody(element: HTMLElement): void {\n try {\n if (element.parentNode) {\n element.parentNode.removeChild(element);\n }\n } catch (error) {\n handleDOMError(error as Error, 'removeFromBody');\n throw error;\n }\n }\n\n /**\n * Sets multiple CSS properties on an element\n */\n static setElementStyles(\n element: HTMLElement,\n styles: Record<string, string>\n ): void {\n try {\n Object.entries(styles).forEach(([property, value]) => {\n element.style.setProperty(property, value);\n });\n } catch (error) {\n handleDOMError(error as Error, 'setElementStyles');\n throw error;\n }\n }\n\n /**\n * Gets the bounding rectangle of an element\n */\n static getElementRect(element: HTMLElement): DOMRect {\n try {\n return element.getBoundingClientRect();\n } catch (error) {\n handleDOMError(error as Error, 'getElementRect');\n throw error;\n }\n }\n\n /**\n * Checks if an element is in the viewport\n */\n static isElementInViewport(element: HTMLElement): boolean {\n try {\n const rect = this.getElementRect(element);\n return (\n rect.top >= 0 &&\n rect.left >= 0 &&\n rect.bottom <=\n (window.innerHeight || document.documentElement.clientHeight) &&\n rect.right <=\n (window.innerWidth || document.documentElement.clientWidth)\n );\n } catch (error) {\n handleDOMError(error as Error, 'isElementInViewport');\n return false;\n }\n }\n\n /**\n * Calculates distance between two points\n */\n static calculateDistance(\n x1: number,\n y1: number,\n x2: number,\n y2: number\n ): number {\n return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));\n }\n\n /**\n * Finds the closest element to a point from a list of elements\n */\n static findClosestElement(\n pointX: number,\n pointY: number,\n elements: NodeListOf<Element>\n ): HTMLElement | null {\n try {\n let closestElement: HTMLElement | null = null;\n let minDistance = Infinity;\n\n elements.forEach(element => {\n const rect = this.getElementRect(element as HTMLElement);\n const distance = this.calculateDistance(\n pointX,\n pointY,\n rect.left + rect.width / 2,\n rect.top + rect.height / 2\n );\n\n if (distance < minDistance) {\n minDistance = distance;\n closestElement = element as HTMLElement;\n }\n });\n\n return closestElement;\n } catch (error) {\n handleDOMError(error as Error, 'findClosestElement');\n return null;\n }\n }\n\n /**\n * Safely adds event listeners\n */\n static addEventListener(\n element: EventTarget,\n event: string,\n handler: EventListener,\n options?: AddEventListenerOptions\n ): void {\n try {\n element.addEventListener(event, handler, options);\n } catch (error) {\n handleDOMError(error as Error, 'addEventListener');\n throw error;\n }\n }\n\n /**\n * Safely removes event listeners\n */\n static removeEventListener(\n element: EventTarget,\n event: string,\n handler: EventListener,\n options?: EventListenerOptions\n ): void {\n try {\n element.removeEventListener(event, handler, options);\n } catch (error) {\n handleDOMError(error as Error, 'removeEventListener');\n throw error;\n }\n }\n}\n","/**\n * Debug utility for Prepr Next.js package\n * Provides centralized debug logging with performance optimizations\n */\n\n// Define specific types for debug arguments\nexport type DebugArg = string | number | boolean | null | undefined | object;\n\ninterface DebugOptions {\n enabled: boolean;\n prefix?: string;\n}\n\nclass DebugLogger {\n private options: DebugOptions;\n\n constructor(options: DebugOptions) {\n this.options = {\n prefix: '[Prepr]',\n ...options,\n };\n }\n\n /**\n * Log a debug message if debug is enabled\n */\n log(message: string, ...args: DebugArg[]): void {\n if (!this.options.enabled) return;\n\n const prefix = this.options.prefix;\n console.log(`${prefix} ${message}`, ...args);\n }\n\n /**\n * Log a debug warning if debug is enabled\n */\n warn(message: string, ...args: DebugArg[]): void {\n if (!this.options.enabled) return;\n\n const prefix = this.options.prefix;\n console.warn(`${prefix} ${message}`, ...args);\n }\n\n /**\n * Log a debug error if debug is enabled\n */\n error(message: string, ...args: DebugArg[]): void {\n if (!this.options.enabled) return;\n\n const prefix = this.options.prefix;\n console.error(`${prefix} ${message}`, ...args);\n }\n\n /**\n * Create a scoped logger with additional context\n */\n scope(scopeName: string): DebugLogger {\n return new DebugLogger({\n ...this.options,\n prefix: `${this.options.prefix}[${scopeName}]`,\n });\n }\n}\n\n// Global debug instance\nlet globalDebugLogger: DebugLogger | null = null;\n\n/**\n * Initialize the debug logger\n */\nexport function initDebugLogger(enabled: boolean = false): void {\n globalDebugLogger = new DebugLogger({ enabled });\n}\n\n/**\n * Get the debug logger instance\n */\nexport function getDebugLogger(): DebugLogger {\n if (!globalDebugLogger) {\n // Fallback to disabled logger if not initialized\n globalDebugLogger = new DebugLogger({ enabled: false });\n }\n return globalDebugLogger;\n}\n\n/**\n * Convenience function for logging\n */\nexport function debugLog(message: string, ...args: DebugArg[]): void {\n getDebugLogger().log(message, ...args);\n}\n\n/**\n * Convenience function for warning\n */\nexport function debugWarn(message: string, ...args: DebugArg[]): void {\n getDebugLogger().warn(message, ...args);\n}\n\n/**\n * Convenience function for errors\n */\nexport function debugError(message: string, ...args: DebugArg[]): void {\n getDebugLogger().error(message, ...args);\n}\n\n/**\n * Create a scoped debug logger\n */\nexport function createScopedLogger(scopeName: string): DebugLogger {\n return getDebugLogger().scope(scopeName);\n}\n","// Performance utilities\n\n// TODO: Refine the type for args and return value if possible\nexport function throttle<T extends (...args: any[]) => any>(\n func: T,\n delay: number\n): T {\n let timeoutId: NodeJS.Timeout | null = null;\n let lastExecTime = 0;\n\n return ((...args: unknown[]) => {\n const currentTime = Date.now();\n if (currentTime - lastExecTime > delay) {\n func(...(args as Parameters<T>));\n lastExecTime = currentTime;\n } else {\n if (timeoutId) clearTimeout(timeoutId);\n timeoutId = setTimeout(\n () => {\n func(...(args as Parameters<T>));\n lastExecTime = Date.now();\n },\n delay - (currentTime - lastExecTime)\n );\n }\n }) as T;\n}\n\n// Simple DOM element cache for querySelectorAll\nexport function createElementCache<T extends Element = Element>(\n query: string,\n ttl: number = 1000\n) {\n let cache: NodeListOf<T> | null = null;\n let lastCacheTime = 0;\n return () => {\n const now = Date.now();\n if (!cache || now - lastCacheTime > ttl) {\n cache = document.querySelectorAll<T>(query);\n lastCacheTime = now;\n }\n return cache;\n };\n}\n"]}
@@ -0,0 +1,138 @@
1
+ import { ClassValue } from 'clsx';
2
+
3
+ declare const StegaError: {
4
+ readonly DECODE_FAILED: "STEGA_DECODE_FAILED";
5
+ readonly INVALID_FORMAT: "STEGA_INVALID_FORMAT";
6
+ readonly DOM_MANIPULATION_FAILED: "DOM_MANIPULATION_FAILED";
7
+ readonly CONTEXT_NOT_FOUND: "CONTEXT_NOT_FOUND";
8
+ };
9
+ type StegaErrorType = (typeof StegaError)[keyof typeof StegaError];
10
+ interface ErrorAdditionalData {
11
+ input?: string;
12
+ element?: HTMLElement;
13
+ context?: string;
14
+ [key: string]: string | HTMLElement | undefined;
15
+ }
16
+ interface ErrorInfo {
17
+ type: StegaErrorType;
18
+ context: string;
19
+ message: string;
20
+ timestamp: string;
21
+ stack?: string;
22
+ additionalData?: ErrorAdditionalData;
23
+ }
24
+ declare function createErrorInfo(type: StegaErrorType, context: string, error: Error, additionalData?: ErrorAdditionalData): ErrorInfo;
25
+ declare function handleStegaError(error: Error, context: string, additionalData?: ErrorAdditionalData): ErrorInfo;
26
+ declare function handleDOMError(error: Error, context: string): ErrorInfo;
27
+ declare function handleContextError(contextName: string): void;
28
+
29
+ declare class DOMService {
30
+ /**
31
+ * Creates an HTML element with specified tag and class name
32
+ */
33
+ static createElement(tag: string, className: string): HTMLElement;
34
+ /**
35
+ * Appends an element to the document body
36
+ */
37
+ static appendToBody(element: HTMLElement): void;
38
+ /**
39
+ * Removes an element from the document body
40
+ */
41
+ static removeFromBody(element: HTMLElement): void;
42
+ /**
43
+ * Sets multiple CSS properties on an element
44
+ */
45
+ static setElementStyles(element: HTMLElement, styles: Record<string, string>): void;
46
+ /**
47
+ * Gets the bounding rectangle of an element
48
+ */
49
+ static getElementRect(element: HTMLElement): DOMRect;
50
+ /**
51
+ * Checks if an element is in the viewport
52
+ */
53
+ static isElementInViewport(element: HTMLElement): boolean;
54
+ /**
55
+ * Calculates distance between two points
56
+ */
57
+ static calculateDistance(x1: number, y1: number, x2: number, y2: number): number;
58
+ /**
59
+ * Finds the closest element to a point from a list of elements
60
+ */
61
+ static findClosestElement(pointX: number, pointY: number, elements: NodeListOf<Element>): HTMLElement | null;
62
+ /**
63
+ * Safely adds event listeners
64
+ */
65
+ static addEventListener(element: EventTarget, event: string, handler: EventListener, options?: AddEventListenerOptions): void;
66
+ /**
67
+ * Safely removes event listeners
68
+ */
69
+ static removeEventListener(element: EventTarget, event: string, handler: EventListener, options?: EventListenerOptions): void;
70
+ }
71
+
72
+ /**
73
+ * Debug utility for Prepr Next.js package
74
+ * Provides centralized debug logging with performance optimizations
75
+ */
76
+ type DebugArg = string | number | boolean | null | undefined | object;
77
+ interface DebugOptions {
78
+ enabled: boolean;
79
+ prefix?: string;
80
+ }
81
+ declare class DebugLogger {
82
+ private options;
83
+ constructor(options: DebugOptions);
84
+ /**
85
+ * Log a debug message if debug is enabled
86
+ */
87
+ log(message: string, ...args: DebugArg[]): void;
88
+ /**
89
+ * Log a debug warning if debug is enabled
90
+ */
91
+ warn(message: string, ...args: DebugArg[]): void;
92
+ /**
93
+ * Log a debug error if debug is enabled
94
+ */
95
+ error(message: string, ...args: DebugArg[]): void;
96
+ /**
97
+ * Create a scoped logger with additional context
98
+ */
99
+ scope(scopeName: string): DebugLogger;
100
+ }
101
+ /**
102
+ * Initialize the debug logger
103
+ */
104
+ declare function initDebugLogger(enabled?: boolean): void;
105
+ /**
106
+ * Get the debug logger instance
107
+ */
108
+ declare function getDebugLogger(): DebugLogger;
109
+ /**
110
+ * Convenience function for logging
111
+ */
112
+ declare function debugLog(message: string, ...args: DebugArg[]): void;
113
+ /**
114
+ * Convenience function for warning
115
+ */
116
+ declare function debugWarn(message: string, ...args: DebugArg[]): void;
117
+ /**
118
+ * Convenience function for errors
119
+ */
120
+ declare function debugError(message: string, ...args: DebugArg[]): void;
121
+ /**
122
+ * Create a scoped debug logger
123
+ */
124
+ declare function createScopedLogger(scopeName: string): DebugLogger;
125
+
126
+ declare function throttle<T extends (...args: any[]) => any>(func: T, delay: number): T;
127
+ declare function createElementCache<T extends Element = Element>(query: string, ttl?: number): () => NodeListOf<T>;
128
+
129
+ declare function cn(...inputs: ClassValue[]): string;
130
+ interface PreprEventData {
131
+ segment?: string;
132
+ variant?: string;
133
+ editMode?: boolean;
134
+ [key: string]: string | boolean | number | undefined;
135
+ }
136
+ declare function sendPreprEvent(event: string, data?: PreprEventData): void;
137
+
138
+ export { DOMService, type DebugArg, type ErrorAdditionalData, type ErrorInfo, type PreprEventData, StegaError, type StegaErrorType, cn, createElementCache, createErrorInfo, createScopedLogger, debugError, debugLog, debugWarn, getDebugLogger, handleContextError, handleDOMError, handleStegaError, initDebugLogger, sendPreprEvent, throttle };
@@ -0,0 +1,138 @@
1
+ import { ClassValue } from 'clsx';
2
+
3
+ declare const StegaError: {
4
+ readonly DECODE_FAILED: "STEGA_DECODE_FAILED";
5
+ readonly INVALID_FORMAT: "STEGA_INVALID_FORMAT";
6
+ readonly DOM_MANIPULATION_FAILED: "DOM_MANIPULATION_FAILED";
7
+ readonly CONTEXT_NOT_FOUND: "CONTEXT_NOT_FOUND";
8
+ };
9
+ type StegaErrorType = (typeof StegaError)[keyof typeof StegaError];
10
+ interface ErrorAdditionalData {
11
+ input?: string;
12
+ element?: HTMLElement;
13
+ context?: string;
14
+ [key: string]: string | HTMLElement | undefined;
15
+ }
16
+ interface ErrorInfo {
17
+ type: StegaErrorType;
18
+ context: string;
19
+ message: string;
20
+ timestamp: string;
21
+ stack?: string;
22
+ additionalData?: ErrorAdditionalData;
23
+ }
24
+ declare function createErrorInfo(type: StegaErrorType, context: string, error: Error, additionalData?: ErrorAdditionalData): ErrorInfo;
25
+ declare function handleStegaError(error: Error, context: string, additionalData?: ErrorAdditionalData): ErrorInfo;
26
+ declare function handleDOMError(error: Error, context: string): ErrorInfo;
27
+ declare function handleContextError(contextName: string): void;
28
+
29
+ declare class DOMService {
30
+ /**
31
+ * Creates an HTML element with specified tag and class name
32
+ */
33
+ static createElement(tag: string, className: string): HTMLElement;
34
+ /**
35
+ * Appends an element to the document body
36
+ */
37
+ static appendToBody(element: HTMLElement): void;
38
+ /**
39
+ * Removes an element from the document body
40
+ */
41
+ static removeFromBody(element: HTMLElement): void;
42
+ /**
43
+ * Sets multiple CSS properties on an element
44
+ */
45
+ static setElementStyles(element: HTMLElement, styles: Record<string, string>): void;
46
+ /**
47
+ * Gets the bounding rectangle of an element
48
+ */
49
+ static getElementRect(element: HTMLElement): DOMRect;
50
+ /**
51
+ * Checks if an element is in the viewport
52
+ */
53
+ static isElementInViewport(element: HTMLElement): boolean;
54
+ /**
55
+ * Calculates distance between two points
56
+ */
57
+ static calculateDistance(x1: number, y1: number, x2: number, y2: number): number;
58
+ /**
59
+ * Finds the closest element to a point from a list of elements
60
+ */
61
+ static findClosestElement(pointX: number, pointY: number, elements: NodeListOf<Element>): HTMLElement | null;
62
+ /**
63
+ * Safely adds event listeners
64
+ */
65
+ static addEventListener(element: EventTarget, event: string, handler: EventListener, options?: AddEventListenerOptions): void;
66
+ /**
67
+ * Safely removes event listeners
68
+ */
69
+ static removeEventListener(element: EventTarget, event: string, handler: EventListener, options?: EventListenerOptions): void;
70
+ }
71
+
72
+ /**
73
+ * Debug utility for Prepr Next.js package
74
+ * Provides centralized debug logging with performance optimizations
75
+ */
76
+ type DebugArg = string | number | boolean | null | undefined | object;
77
+ interface DebugOptions {
78
+ enabled: boolean;
79
+ prefix?: string;
80
+ }
81
+ declare class DebugLogger {
82
+ private options;
83
+ constructor(options: DebugOptions);
84
+ /**
85
+ * Log a debug message if debug is enabled
86
+ */
87
+ log(message: string, ...args: DebugArg[]): void;
88
+ /**
89
+ * Log a debug warning if debug is enabled
90
+ */
91
+ warn(message: string, ...args: DebugArg[]): void;
92
+ /**
93
+ * Log a debug error if debug is enabled
94
+ */
95
+ error(message: string, ...args: DebugArg[]): void;
96
+ /**
97
+ * Create a scoped logger with additional context
98
+ */
99
+ scope(scopeName: string): DebugLogger;
100
+ }
101
+ /**
102
+ * Initialize the debug logger
103
+ */
104
+ declare function initDebugLogger(enabled?: boolean): void;
105
+ /**
106
+ * Get the debug logger instance
107
+ */
108
+ declare function getDebugLogger(): DebugLogger;
109
+ /**
110
+ * Convenience function for logging
111
+ */
112
+ declare function debugLog(message: string, ...args: DebugArg[]): void;
113
+ /**
114
+ * Convenience function for warning
115
+ */
116
+ declare function debugWarn(message: string, ...args: DebugArg[]): void;
117
+ /**
118
+ * Convenience function for errors
119
+ */
120
+ declare function debugError(message: string, ...args: DebugArg[]): void;
121
+ /**
122
+ * Create a scoped debug logger
123
+ */
124
+ declare function createScopedLogger(scopeName: string): DebugLogger;
125
+
126
+ declare function throttle<T extends (...args: any[]) => any>(func: T, delay: number): T;
127
+ declare function createElementCache<T extends Element = Element>(query: string, ttl?: number): () => NodeListOf<T>;
128
+
129
+ declare function cn(...inputs: ClassValue[]): string;
130
+ interface PreprEventData {
131
+ segment?: string;
132
+ variant?: string;
133
+ editMode?: boolean;
134
+ [key: string]: string | boolean | number | undefined;
135
+ }
136
+ declare function sendPreprEvent(event: string, data?: PreprEventData): void;
137
+
138
+ export { DOMService, type DebugArg, type ErrorAdditionalData, type ErrorInfo, type PreprEventData, StegaError, type StegaErrorType, cn, createElementCache, createErrorInfo, createScopedLogger, debugError, debugLog, debugWarn, getDebugLogger, handleContextError, handleDOMError, handleStegaError, initDebugLogger, sendPreprEvent, throttle };
@@ -0,0 +1,2 @@
1
+ import {a,b as b$1}from'../chunk-E7ATRJ2F.js';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';var u={DECODE_FAILED:"STEGA_DECODE_FAILED",INVALID_FORMAT:"STEGA_INVALID_FORMAT",DOM_MANIPULATION_FAILED:"DOM_MANIPULATION_FAILED",CONTEXT_NOT_FOUND:"CONTEXT_NOT_FOUND"};function p(n,e,t,r){return {type:n,context:e,message:t.message,timestamp:new Date().toISOString(),stack:t.stack,additionalData:r}}function b(n,e,t){let r=p(u.DECODE_FAILED,e,n,t);return console.error("Stega Error:",r),process.env.NODE_ENV,r}function s(n,e){let t=p(u.DOM_MANIPULATION_FAILED,e,n);return console.error("DOM Error:",t),t}function L(n){let e=new Error(`${n} must be used within its provider`),t=p(u.CONTEXT_NOT_FOUND,n,e);throw console.error("Context Error:",t),e}var D=class{static createElement(e,t){try{let r=document.createElement(e);return r.className=t,r}catch(r){throw s(r,"createElement"),r}}static appendToBody(e){try{document.body.appendChild(e);}catch(t){throw s(t,"appendToBody"),t}}static removeFromBody(e){try{e.parentNode&&e.parentNode.removeChild(e);}catch(t){throw s(t,"removeFromBody"),t}}static setElementStyles(e,t){try{Object.entries(t).forEach(([r,o])=>{e.style.setProperty(r,o);});}catch(r){throw s(r,"setElementStyles"),r}}static getElementRect(e){try{return e.getBoundingClientRect()}catch(t){throw s(t,"getElementRect"),t}}static isElementInViewport(e){try{let t=this.getElementRect(e);return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)}catch(t){return s(t,"isElementInViewport"),false}}static calculateDistance(e,t,r,o){return Math.sqrt(Math.pow(r-e,2)+Math.pow(o-t,2))}static findClosestElement(e,t,r){try{let o=null,i=1/0;return r.forEach(d=>{let c=this.getElementRect(d),m=this.calculateDistance(e,t,c.left+c.width/2,c.top+c.height/2);m<i&&(i=m,o=d);}),o}catch(o){return s(o,"findClosestElement"),null}}static addEventListener(e,t,r,o){try{e.addEventListener(t,r,o);}catch(i){throw s(i,"addEventListener"),i}}static removeEventListener(e,t,r,o){try{e.removeEventListener(t,r,o);}catch(i){throw s(i,"removeEventListener"),i}}};var g=class n{constructor(e){this.options=a({prefix:"[Prepr]"},e);}log(e,...t){if(!this.options.enabled)return;let r=this.options.prefix;console.log(`${r} ${e}`,...t);}warn(e,...t){if(!this.options.enabled)return;let r=this.options.prefix;console.warn(`${r} ${e}`,...t);}error(e,...t){if(!this.options.enabled)return;let r=this.options.prefix;console.error(`${r} ${e}`,...t);}scope(e){return new n(b$1(a({},this.options),{prefix:`${this.options.prefix}[${e}]`}))}},l=null;function O(n=false){l=new g({enabled:n});}function E(){return l||(l=new g({enabled:false})),l}function y(n,...e){E().log(n,...e);}function A(n,...e){E().warn(n,...e);}function M(n,...e){E().error(n,...e);}function I(n){return E().scope(n)}function C(n,e){let t=null,r=0;return (...o)=>{let i=Date.now();i-r>e?(n(...o),r=i):(t&&clearTimeout(t),t=setTimeout(()=>{n(...o),r=Date.now();},e-(i-r)));}}function S(n,e=1e3){let t=null,r=0;return ()=>{let o=Date.now();return (!t||o-r>e)&&(t=document.querySelectorAll(n),r=o),t}}function $(...n){return twMerge(clsx(n))}function k(n,e){window.parent.postMessage(a({name:"prepr_preview_bar",event:n},e));}export{D as DOMService,u as StegaError,$ as cn,S as createElementCache,p as createErrorInfo,I as createScopedLogger,M as debugError,y as debugLog,A as debugWarn,E as getDebugLogger,L as handleContextError,s as handleDOMError,b as handleStegaError,O as initDebugLogger,k as sendPreprEvent,C as throttle};//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/errors.ts","../../src/utils/dom.ts","../../src/utils/debug.ts","../../src/utils/performance.ts","../../src/utils/index.ts"],"names":["StegaError","createErrorInfo","type","context","error","additionalData","handleStegaError","errorInfo","handleDOMError","handleContextError","contextName","DOMService","tag","className","element","styles","property","value","rect","x1","y1","x2","y2","pointX","pointY","elements","closestElement","minDistance","distance","event","handler","options","DebugLogger","_DebugLogger","__spreadValues","message","args","prefix","scopeName","__spreadProps","globalDebugLogger","initDebugLogger","enabled","getDebugLogger","debugLog","debugWarn","debugError","createScopedLogger","throttle","func","delay","timeoutId","lastExecTime","currentTime","createElementCache","query","ttl","cache","lastCacheTime","now","cn","inputs","twMerge","clsx","sendPreprEvent","data"],"mappings":"2GAAO,IAAMA,CAAAA,CAAa,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,CAAA,CAC/BgB,EAAe,IAAA,CAAK,GAAA,GACtB,CAAA,CACAF,CAAAA,EAASG,EAAcD,CAAAA,CACzB,CAAA,EAEJ,CACF,CAGO,SAASE,EACdC,CAAAA,CACAC,CAAAA,CAAc,IACd,CACA,IAAIC,EAA8B,IAAA,CAC9BC,CAAAA,CAAgB,EACpB,OAAO,IAAM,CACX,IAAMC,CAAAA,CAAM,IAAA,CAAK,GAAA,GACjB,OAAA,CAAI,CAACF,GAASE,CAAAA,CAAMD,CAAAA,CAAgBF,KAClCC,CAAAA,CAAQ,QAAA,CAAS,iBAAoBF,CAAK,CAAA,CAC1CG,EAAgBC,CAAAA,CAAAA,CAEXF,CACT,CACF,CCxCO,SAASG,KAAMC,CAAAA,CAAsB,CAC1C,OAAOC,OAAAA,CAAQC,IAAAA,CAAKF,CAAM,CAAC,CAC7B,CAUO,SAASG,CAAAA,CAAenC,EAAeoC,CAAAA,CAAuB,CACnE,OAAO,MAAA,CAAO,WAAA,CAAY/B,EAAA,CACxB,IAAA,CAAM,oBACN,KAAA,CAAAL,CAAAA,CAAAA,CACGoC,EACJ,EACH","file":"index.js","sourcesContent":["export const StegaError = {\n DECODE_FAILED: 'STEGA_DECODE_FAILED',\n INVALID_FORMAT: 'STEGA_INVALID_FORMAT',\n DOM_MANIPULATION_FAILED: 'DOM_MANIPULATION_FAILED',\n CONTEXT_NOT_FOUND: 'CONTEXT_NOT_FOUND',\n} as const;\n\nexport type StegaErrorType = (typeof StegaError)[keyof typeof StegaError];\n\n// Define specific types for error additional data\nexport interface ErrorAdditionalData {\n input?: string;\n element?: HTMLElement;\n context?: string;\n [key: string]: string | HTMLElement | undefined;\n}\n\nexport interface ErrorInfo {\n type: StegaErrorType;\n context: string;\n message: string;\n timestamp: string;\n stack?: string;\n additionalData?: ErrorAdditionalData;\n}\n\nexport function createErrorInfo(\n type: StegaErrorType,\n context: string,\n error: Error,\n additionalData?: ErrorAdditionalData\n): ErrorInfo {\n return {\n type,\n context,\n message: error.message,\n timestamp: new Date().toISOString(),\n stack: error.stack,\n additionalData,\n };\n}\n\nexport function handleStegaError(\n error: Error,\n context: string,\n additionalData?: ErrorAdditionalData\n) {\n const errorInfo = createErrorInfo(\n StegaError.DECODE_FAILED,\n context,\n error,\n additionalData\n );\n\n console.error('Stega Error:', errorInfo);\n\n // In production, you might want to send this to an error tracking service\n if (process.env.NODE_ENV === 'production') {\n // sendToErrorTrackingService(errorInfo);\n }\n\n return errorInfo;\n}\n\nexport function handleDOMError(error: Error, context: string) {\n const errorInfo = createErrorInfo(\n StegaError.DOM_MANIPULATION_FAILED,\n context,\n error\n );\n\n console.error('DOM Error:', errorInfo);\n return errorInfo;\n}\n\nexport function handleContextError(contextName: string) {\n const error = new Error(`${contextName} must be used within its provider`);\n const errorInfo = createErrorInfo(\n StegaError.CONTEXT_NOT_FOUND,\n contextName,\n error\n );\n\n console.error('Context Error:', errorInfo);\n throw error;\n}\n","import { handleDOMError } from './errors';\n\nexport class DOMService {\n /**\n * Creates an HTML element with specified tag and class name\n */\n static createElement(tag: string, className: string): HTMLElement {\n try {\n const element = document.createElement(tag);\n element.className = className;\n return element;\n } catch (error) {\n handleDOMError(error as Error, 'createElement');\n throw error;\n }\n }\n\n /**\n * Appends an element to the document body\n */\n static appendToBody(element: HTMLElement): void {\n try {\n document.body.appendChild(element);\n } catch (error) {\n handleDOMError(error as Error, 'appendToBody');\n throw error;\n }\n }\n\n /**\n * Removes an element from the document body\n */\n static removeFromBody(element: HTMLElement): void {\n try {\n if (element.parentNode) {\n element.parentNode.removeChild(element);\n }\n } catch (error) {\n handleDOMError(error as Error, 'removeFromBody');\n throw error;\n }\n }\n\n /**\n * Sets multiple CSS properties on an element\n */\n static setElementStyles(\n element: HTMLElement,\n styles: Record<string, string>\n ): void {\n try {\n Object.entries(styles).forEach(([property, value]) => {\n element.style.setProperty(property, value);\n });\n } catch (error) {\n handleDOMError(error as Error, 'setElementStyles');\n throw error;\n }\n }\n\n /**\n * Gets the bounding rectangle of an element\n */\n static getElementRect(element: HTMLElement): DOMRect {\n try {\n return element.getBoundingClientRect();\n } catch (error) {\n handleDOMError(error as Error, 'getElementRect');\n throw error;\n }\n }\n\n /**\n * Checks if an element is in the viewport\n */\n static isElementInViewport(element: HTMLElement): boolean {\n try {\n const rect = this.getElementRect(element);\n return (\n rect.top >= 0 &&\n rect.left >= 0 &&\n rect.bottom <=\n (window.innerHeight || document.documentElement.clientHeight) &&\n rect.right <=\n (window.innerWidth || document.documentElement.clientWidth)\n );\n } catch (error) {\n handleDOMError(error as Error, 'isElementInViewport');\n return false;\n }\n }\n\n /**\n * Calculates distance between two points\n */\n static calculateDistance(\n x1: number,\n y1: number,\n x2: number,\n y2: number\n ): number {\n return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));\n }\n\n /**\n * Finds the closest element to a point from a list of elements\n */\n static findClosestElement(\n pointX: number,\n pointY: number,\n elements: NodeListOf<Element>\n ): HTMLElement | null {\n try {\n let closestElement: HTMLElement | null = null;\n let minDistance = Infinity;\n\n elements.forEach(element => {\n const rect = this.getElementRect(element as HTMLElement);\n const distance = this.calculateDistance(\n pointX,\n pointY,\n rect.left + rect.width / 2,\n rect.top + rect.height / 2\n );\n\n if (distance < minDistance) {\n minDistance = distance;\n closestElement = element as HTMLElement;\n }\n });\n\n return closestElement;\n } catch (error) {\n handleDOMError(error as Error, 'findClosestElement');\n return null;\n }\n }\n\n /**\n * Safely adds event listeners\n */\n static addEventListener(\n element: EventTarget,\n event: string,\n handler: EventListener,\n options?: AddEventListenerOptions\n ): void {\n try {\n element.addEventListener(event, handler, options);\n } catch (error) {\n handleDOMError(error as Error, 'addEventListener');\n throw error;\n }\n }\n\n /**\n * Safely removes event listeners\n */\n static removeEventListener(\n element: EventTarget,\n event: string,\n handler: EventListener,\n options?: EventListenerOptions\n ): void {\n try {\n element.removeEventListener(event, handler, options);\n } catch (error) {\n handleDOMError(error as Error, 'removeEventListener');\n throw error;\n }\n }\n}\n","/**\n * Debug utility for Prepr Next.js package\n * Provides centralized debug logging with performance optimizations\n */\n\n// Define specific types for debug arguments\nexport type DebugArg = string | number | boolean | null | undefined | object;\n\ninterface DebugOptions {\n enabled: boolean;\n prefix?: string;\n}\n\nclass DebugLogger {\n private options: DebugOptions;\n\n constructor(options: DebugOptions) {\n this.options = {\n prefix: '[Prepr]',\n ...options,\n };\n }\n\n /**\n * Log a debug message if debug is enabled\n */\n log(message: string, ...args: DebugArg[]): void {\n if (!this.options.enabled) return;\n\n const prefix = this.options.prefix;\n console.log(`${prefix} ${message}`, ...args);\n }\n\n /**\n * Log a debug warning if debug is enabled\n */\n warn(message: string, ...args: DebugArg[]): void {\n if (!this.options.enabled) return;\n\n const prefix = this.options.prefix;\n console.warn(`${prefix} ${message}`, ...args);\n }\n\n /**\n * Log a debug error if debug is enabled\n */\n error(message: string, ...args: DebugArg[]): void {\n if (!this.options.enabled) return;\n\n const prefix = this.options.prefix;\n console.error(`${prefix} ${message}`, ...args);\n }\n\n /**\n * Create a scoped logger with additional context\n */\n scope(scopeName: string): DebugLogger {\n return new DebugLogger({\n ...this.options,\n prefix: `${this.options.prefix}[${scopeName}]`,\n });\n }\n}\n\n// Global debug instance\nlet globalDebugLogger: DebugLogger | null = null;\n\n/**\n * Initialize the debug logger\n */\nexport function initDebugLogger(enabled: boolean = false): void {\n globalDebugLogger = new DebugLogger({ enabled });\n}\n\n/**\n * Get the debug logger instance\n */\nexport function getDebugLogger(): DebugLogger {\n if (!globalDebugLogger) {\n // Fallback to disabled logger if not initialized\n globalDebugLogger = new DebugLogger({ enabled: false });\n }\n return globalDebugLogger;\n}\n\n/**\n * Convenience function for logging\n */\nexport function debugLog(message: string, ...args: DebugArg[]): void {\n getDebugLogger().log(message, ...args);\n}\n\n/**\n * Convenience function for warning\n */\nexport function debugWarn(message: string, ...args: DebugArg[]): void {\n getDebugLogger().warn(message, ...args);\n}\n\n/**\n * Convenience function for errors\n */\nexport function debugError(message: string, ...args: DebugArg[]): void {\n getDebugLogger().error(message, ...args);\n}\n\n/**\n * Create a scoped debug logger\n */\nexport function createScopedLogger(scopeName: string): DebugLogger {\n return getDebugLogger().scope(scopeName);\n}\n","// Performance utilities\n\n// TODO: Refine the type for args and return value if possible\nexport function throttle<T extends (...args: any[]) => any>(\n func: T,\n delay: number\n): T {\n let timeoutId: NodeJS.Timeout | null = null;\n let lastExecTime = 0;\n\n return ((...args: unknown[]) => {\n const currentTime = Date.now();\n if (currentTime - lastExecTime > delay) {\n func(...(args as Parameters<T>));\n lastExecTime = currentTime;\n } else {\n if (timeoutId) clearTimeout(timeoutId);\n timeoutId = setTimeout(\n () => {\n func(...(args as Parameters<T>));\n lastExecTime = Date.now();\n },\n delay - (currentTime - lastExecTime)\n );\n }\n }) as T;\n}\n\n// Simple DOM element cache for querySelectorAll\nexport function createElementCache<T extends Element = Element>(\n query: string,\n ttl: number = 1000\n) {\n let cache: NodeListOf<T> | null = null;\n let lastCacheTime = 0;\n return () => {\n const now = Date.now();\n if (!cache || now - lastCacheTime > ttl) {\n cache = document.querySelectorAll<T>(query);\n lastCacheTime = now;\n }\n return cache;\n };\n}\n","import { ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\n// Define specific types for Prepr events\nexport interface PreprEventData {\n segment?: string;\n variant?: string;\n editMode?: boolean;\n [key: string]: string | boolean | number | undefined;\n}\n\nexport function sendPreprEvent(event: string, data?: PreprEventData) {\n window.parent.postMessage({\n name: 'prepr_preview_bar',\n event,\n ...data,\n });\n}\n\n// Export error handling utilities\nexport * from './errors';\n\n// Export DOM service\nexport * from './dom';\n\n// Export debug utilities\nexport * from './debug';\n\n// Export performance utilities\nexport * from './performance';\n"]}