@simpleview/cms-foundation 0.0.23 → 0.0.25

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 (121) hide show
  1. package/dist/components/App/App.js +5 -4
  2. package/dist/components/App/App.js.map +3 -3
  3. package/dist/components/App/index.js +1 -8
  4. package/dist/components/App/index.js.map +3 -3
  5. package/dist/components/Error/Error.js +11 -4
  6. package/dist/components/Error/Error.js.map +3 -3
  7. package/dist/components/Error/Error.types.js +0 -1
  8. package/dist/components/Error/index.js +2 -9
  9. package/dist/components/Error/index.js.map +3 -3
  10. package/dist/components/Layout/Layout.js +25 -4
  11. package/dist/components/Layout/Layout.js.map +3 -3
  12. package/dist/components/Layout/index.js +1 -8
  13. package/dist/components/Layout/index.js.map +3 -3
  14. package/dist/components/Preview/PreviewCivWrapper.js +25 -4
  15. package/dist/components/Preview/PreviewCivWrapper.js.map +3 -3
  16. package/dist/components/Preview/PreviewContent.js +10 -18
  17. package/dist/components/Preview/PreviewContent.js.map +3 -3
  18. package/dist/components/Preview/PreviewPageWrapper.js +85 -4
  19. package/dist/components/Preview/PreviewPageWrapper.js.map +3 -3
  20. package/dist/components/Preview/index.js +3 -29
  21. package/dist/components/Preview/index.js.map +3 -3
  22. package/dist/components/Section/Section.js +8 -18
  23. package/dist/components/Section/Section.js.map +3 -3
  24. package/dist/components/Section/Section.types.js +0 -1
  25. package/dist/components/Section/SectionItem.js +11 -18
  26. package/dist/components/Section/SectionItem.js.map +3 -3
  27. package/dist/components/Section/SectionItemCiv.js +19 -18
  28. package/dist/components/Section/SectionItemCiv.js.map +3 -3
  29. package/dist/components/Section/index.js +4 -25
  30. package/dist/components/Section/index.js.map +3 -3
  31. package/dist/components/Unknown/Unknown.js +28 -6
  32. package/dist/components/Unknown/Unknown.js.map +3 -3
  33. package/dist/components/Unknown/index.js +1 -10
  34. package/dist/components/Unknown/index.js.map +3 -3
  35. package/dist/components/index.js +6 -47
  36. package/dist/components/index.js.map +3 -3
  37. package/dist/contexts/ComponentMapContext.js +9 -19
  38. package/dist/contexts/ComponentMapContext.js.map +3 -3
  39. package/dist/contexts/index.js +1 -23
  40. package/dist/contexts/index.js.map +3 -3
  41. package/dist/routes/index.js +2 -7131
  42. package/dist/routes/index.js.map +4 -4
  43. package/dist/types/cms.js +0 -1
  44. package/dist/types/index.js +1 -2
  45. package/dist/types/index.js.map +3 -3
  46. package/dist/types/src/vite/config.d.ts +1 -0
  47. package/dist/types/src/vite/index.d.ts +1 -0
  48. package/dist/utils/getCmsUrl.js +5 -4
  49. package/dist/utils/getCmsUrl.js.map +3 -3
  50. package/dist/utils/getPageContent.js +50 -5
  51. package/dist/utils/getPageContent.js.map +3 -3
  52. package/dist/utils/index.js +2 -11
  53. package/dist/utils/index.js.map +3 -3
  54. package/dist/vite/config.js +37 -0
  55. package/dist/vite/config.js.map +7 -0
  56. package/dist/vite/index.js +2 -0
  57. package/dist/vite/index.js.map +7 -0
  58. package/package.json +11 -5
  59. package/dist/chunk-2WII7C3O.js +0 -31
  60. package/dist/chunk-2WII7C3O.js.map +0 -7
  61. package/dist/chunk-4GSRDXHP.js +0 -87
  62. package/dist/chunk-4GSRDXHP.js.map +0 -7
  63. package/dist/chunk-4LSFAAZW.js +0 -1
  64. package/dist/chunk-4LSFAAZW.js.map +0 -7
  65. package/dist/chunk-5WRI5ZAA.js +0 -31
  66. package/dist/chunk-5WRI5ZAA.js.map +0 -7
  67. package/dist/chunk-CMALSZV3.js +0 -1
  68. package/dist/chunk-CMALSZV3.js.map +0 -7
  69. package/dist/chunk-DG37VYL5.js +0 -1
  70. package/dist/chunk-DG37VYL5.js.map +0 -7
  71. package/dist/chunk-EEKFLXZI.js +0 -11
  72. package/dist/chunk-EEKFLXZI.js.map +0 -7
  73. package/dist/chunk-EG5F4AP4.js +0 -1
  74. package/dist/chunk-EG5F4AP4.js.map +0 -7
  75. package/dist/chunk-EWRVCIV6.js +0 -1
  76. package/dist/chunk-EWRVCIV6.js.map +0 -7
  77. package/dist/chunk-F5L7DWHD.js +0 -1
  78. package/dist/chunk-F5L7DWHD.js.map +0 -7
  79. package/dist/chunk-FJML4RHB.js +0 -59
  80. package/dist/chunk-FJML4RHB.js.map +0 -7
  81. package/dist/chunk-GPTPACV2.js +0 -33
  82. package/dist/chunk-GPTPACV2.js.map +0 -7
  83. package/dist/chunk-MPAGXIUB.js +0 -11
  84. package/dist/chunk-MPAGXIUB.js.map +0 -7
  85. package/dist/chunk-OEYLOZQK.js +0 -31
  86. package/dist/chunk-OEYLOZQK.js.map +0 -7
  87. package/dist/chunk-P3WX4DFS.js +0 -93
  88. package/dist/chunk-P3WX4DFS.js.map +0 -7
  89. package/dist/chunk-VV3NKXSX.js +0 -17
  90. package/dist/chunk-VV3NKXSX.js.map +0 -7
  91. package/dist/chunk-XG5CMDEI.js +0 -1
  92. package/dist/chunk-XG5CMDEI.js.map +0 -7
  93. package/dist/chunk-ZQUGFKHP.js +0 -1
  94. package/dist/chunk-ZQUGFKHP.js.map +0 -7
  95. /package/dist/types/{components → src/components}/App/App.d.ts +0 -0
  96. /package/dist/types/{components → src/components}/App/index.d.ts +0 -0
  97. /package/dist/types/{components → src/components}/Error/Error.d.ts +0 -0
  98. /package/dist/types/{components → src/components}/Error/Error.types.d.ts +0 -0
  99. /package/dist/types/{components → src/components}/Error/index.d.ts +0 -0
  100. /package/dist/types/{components → src/components}/Layout/Layout.d.ts +0 -0
  101. /package/dist/types/{components → src/components}/Layout/index.d.ts +0 -0
  102. /package/dist/types/{components → src/components}/Preview/PreviewCivWrapper.d.ts +0 -0
  103. /package/dist/types/{components → src/components}/Preview/PreviewContent.d.ts +0 -0
  104. /package/dist/types/{components → src/components}/Preview/PreviewPageWrapper.d.ts +0 -0
  105. /package/dist/types/{components → src/components}/Preview/index.d.ts +0 -0
  106. /package/dist/types/{components → src/components}/Section/Section.d.ts +0 -0
  107. /package/dist/types/{components → src/components}/Section/Section.types.d.ts +0 -0
  108. /package/dist/types/{components → src/components}/Section/SectionItem.d.ts +0 -0
  109. /package/dist/types/{components → src/components}/Section/SectionItemCiv.d.ts +0 -0
  110. /package/dist/types/{components → src/components}/Section/index.d.ts +0 -0
  111. /package/dist/types/{components → src/components}/Unknown/Unknown.d.ts +0 -0
  112. /package/dist/types/{components → src/components}/Unknown/index.d.ts +0 -0
  113. /package/dist/types/{components → src/components}/index.d.ts +0 -0
  114. /package/dist/types/{contexts → src/contexts}/ComponentMapContext.d.ts +0 -0
  115. /package/dist/types/{contexts → src/contexts}/index.d.ts +0 -0
  116. /package/dist/types/{routes → src/routes}/index.d.ts +0 -0
  117. /package/dist/types/{types → src/types}/cms.d.ts +0 -0
  118. /package/dist/types/{types → src/types}/index.d.ts +0 -0
  119. /package/dist/types/{utils → src/utils}/getCmsUrl.d.ts +0 -0
  120. /package/dist/types/{utils → src/utils}/getPageContent.d.ts +0 -0
  121. /package/dist/types/{utils → src/utils}/index.d.ts +0 -0
package/dist/types/cms.js CHANGED
@@ -1,2 +1 @@
1
- import "../chunk-ZQUGFKHP.js";
2
1
  //# sourceMappingURL=cms.js.map
@@ -1,3 +1,2 @@
1
- import "../chunk-4LSFAAZW.js";
2
- import "../chunk-ZQUGFKHP.js";
1
+ export * from "./cms.js";
3
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
3
+ "sources": ["../../src/types/index.ts"],
4
+ "sourcesContent": ["export * from \"./cms.js\";\r\n"],
5
+ "mappings": "AAAA,cAAc;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1 @@
1
+ export declare const config: import("vite").UserConfig;
@@ -0,0 +1 @@
1
+ export * from "./config.js";
@@ -1,7 +1,8 @@
1
- import {
2
- getCmsUrl
3
- } from "../chunk-EEKFLXZI.js";
4
- import "../chunk-5WRI5ZAA.js";
1
+ const { CMS_DOMAIN } = process.env;
2
+ function getCmsUrl(host) {
3
+ const siteClient = host.split(".")[0];
4
+ return new URL(`https://${siteClient}.${CMS_DOMAIN}`);
5
+ }
5
6
  export {
6
7
  getCmsUrl
7
8
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
3
+ "sources": ["../../src/utils/getCmsUrl.ts"],
4
+ "sourcesContent": ["const { CMS_DOMAIN } = process.env;\r\n\r\nexport function getCmsUrl(host: string): URL {\r\n\tconst siteClient = host.split(\".\")[0];\r\n\treturn new URL(`https://${siteClient}.${CMS_DOMAIN}`);\r\n}\r\n"],
5
+ "mappings": "AAAA,MAAM,EAAE,WAAW,IAAI,QAAQ;AAExB,SAAS,UAAU,MAAmB;AAC5C,QAAM,aAAa,KAAK,MAAM,GAAG,EAAE,CAAC;AACpC,SAAO,IAAI,IAAI,WAAW,UAAU,IAAI,UAAU,EAAE;AACrD;",
6
6
  "names": []
7
7
  }
@@ -1,8 +1,53 @@
1
- import {
2
- getPageContent
3
- } from "../chunk-FJML4RHB.js";
4
- import "../chunk-EEKFLXZI.js";
5
- import "../chunk-5WRI5ZAA.js";
1
+ import { getCmsUrl } from "./getCmsUrl.js";
2
+ const previewPath = "/includes/plugins/nav/preview_civs/";
3
+ async function getPageContent(req) {
4
+ const incomingUrl = new URL(req.url, "http://placeholder.com");
5
+ const cmsUrl = getCmsUrl(incomingUrl.host);
6
+ if (!incomingUrl.pathname.endsWith("/") || /\.[^/]+$/.test(incomingUrl.pathname)) {
7
+ cmsUrl.pathname = incomingUrl.pathname + "/content.json";
8
+ } else {
9
+ cmsUrl.pathname = incomingUrl.pathname + "content.json";
10
+ }
11
+ const headers = {
12
+ "Accept-Encoding": "gzip",
13
+ "X-Forwarded-For": req.headers.get("x-real-ip") || req.headers.get("x-forwarded-host") || "",
14
+ "User-Agent": req.headers.get("user-agent") || ""
15
+ };
16
+ try {
17
+ let body = void 0;
18
+ if (req.method === "POST" && incomingUrl.pathname === previewPath) {
19
+ incomingUrl.searchParams.forEach((val, key) => {
20
+ cmsUrl.searchParams.set(key, val);
21
+ });
22
+ const formData = await req.formData();
23
+ const civs = formData.get("headless_civs");
24
+ if (typeof civs !== "string") {
25
+ throw new Error(
26
+ "Posted CIVs were not a base64 encoded string."
27
+ );
28
+ }
29
+ const data = JSON.parse(atob(civs));
30
+ return data;
31
+ }
32
+ const url = cmsUrl.toString();
33
+ const { method } = req;
34
+ const fetchParams = {
35
+ method,
36
+ headers,
37
+ body
38
+ };
39
+ console.log("Making page content request:", {
40
+ url,
41
+ ...fetchParams
42
+ });
43
+ const result = await fetch(url, fetchParams).then((res) => res.json());
44
+ return result;
45
+ } catch (err) {
46
+ const status = err?.response?.status || 500;
47
+ const message = err?.response?.statusText || "Server Error";
48
+ throw new Error(`Status ${status}: ${message}`);
49
+ }
50
+ }
6
51
  export {
7
52
  getPageContent
8
53
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
3
+ "sources": ["../../src/utils/getPageContent.ts"],
4
+ "sourcesContent": ["import type { CivProps, PageData } from \"../types/index.js\";\r\nimport { getCmsUrl } from \"./getCmsUrl.js\";\r\n\r\nexport type { PageData };\r\n\r\nconst previewPath = \"/includes/plugins/nav/preview_civs/\";\r\n\r\nexport async function getPageContent(\r\n\treq: Request\r\n): Promise<PageData<CivProps>> {\r\n\tconst incomingUrl = new URL(req.url, \"http://placeholder.com\");\r\n\tconst cmsUrl = getCmsUrl(incomingUrl.host);\r\n\r\n\tif (\r\n\t\t!incomingUrl.pathname.endsWith(\"/\") ||\r\n\t\t/\\.[^/]+$/.test(incomingUrl.pathname)\r\n\t) {\r\n\t\t// If it's a file request, we append /content.json\r\n\t\tcmsUrl.pathname = incomingUrl.pathname + \"/content.json\";\r\n\t} else {\r\n\t\t// If it's not a file request, we just append content.json since it already ends with a \"/\"\r\n\t\tcmsUrl.pathname = incomingUrl.pathname + \"content.json\";\r\n\t}\r\n\r\n\tconst headers: Record<string, string> = {\r\n\t\t\"Accept-Encoding\": \"gzip\",\r\n\t\t\"X-Forwarded-For\":\r\n\t\t\treq.headers.get(\"x-real-ip\") ||\r\n\t\t\treq.headers.get(\"x-forwarded-host\") ||\r\n\t\t\t\"\",\r\n\t\t\"User-Agent\": req.headers.get(\"user-agent\") || \"\",\r\n\t};\r\n\r\n\ttry {\r\n\t\tlet body: URLSearchParams | undefined = undefined;\r\n\r\n\t\t/**\r\n\t\t * If this is the live preview page, we need to append the search params from the incoming URL\r\n\t\t * and send the CIVs along with the request.\r\n\t\t */\r\n\t\tif (req.method === \"POST\" && incomingUrl.pathname === previewPath) {\r\n\t\t\tincomingUrl.searchParams.forEach((val, key) => {\r\n\t\t\t\tcmsUrl.searchParams.set(key, val);\r\n\t\t\t});\r\n\r\n\t\t\tconst formData = await req.formData();\r\n\t\t\tconst civs = formData.get(\"headless_civs\");\r\n\r\n\t\t\tif (typeof civs !== \"string\") {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t\"Posted CIVs were not a base64 encoded string.\"\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tconst data = JSON.parse(atob(civs));\r\n\r\n\t\t\treturn data;\r\n\t\t}\r\n\r\n\t\tconst url = cmsUrl.toString();\r\n\t\tconst { method } = req;\r\n\t\tconst fetchParams: RequestInit = {\r\n\t\t\tmethod,\r\n\t\t\theaders,\r\n\t\t\tbody,\r\n\t\t};\r\n\r\n\t\tconsole.log(\"Making page content request:\", {\r\n\t\t\turl,\r\n\t\t\t...fetchParams,\r\n\t\t});\r\n\r\n\t\tconst result = await fetch(url, fetchParams).then((res) => res.json());\r\n\t\treturn result;\r\n\t} catch (err: unknown) {\r\n\t\tconst status =\r\n\t\t\t(err as { response?: { status?: number } })?.response?.status ||\r\n\t\t\t500;\r\n\t\tconst message =\r\n\t\t\t(err as { response?: { statusText?: string } })?.response\r\n\t\t\t\t?.statusText || \"Server Error\";\r\n\t\tthrow new Error(`Status ${status}: ${message}`);\r\n\t}\r\n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O;AAAA,EACR,SAAS,KAAc;AACtB,UAAM,SACJ,KAA4C,UAAU,UACvD;AACD,UAAM,UACJ,KAAgD,UAC9C,cAAc;AAClB,UAAM,IAAI,MAAM,UAAU,MAAM,KAAK,OAAO,EAAE;AAAA,EAC/C;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,12 +1,3 @@
1
- import {
2
- getPageContent
3
- } from "../chunk-FJML4RHB.js";
4
- import {
5
- getCmsUrl
6
- } from "../chunk-EEKFLXZI.js";
7
- import "../chunk-5WRI5ZAA.js";
8
- export {
9
- getCmsUrl,
10
- getPageContent
11
- };
1
+ export * from "./getCmsUrl.js";
2
+ export * from "./getPageContent.js";
12
3
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
3
+ "sources": ["../../src/utils/index.ts"],
4
+ "sourcesContent": ["export * from \"./getCmsUrl.js\";\r\nexport * from \"./getPageContent.js\";\r\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,37 @@
1
+ import { defineConfig } from "vite";
2
+ import tsconfigPaths from "vite-tsconfig-paths";
3
+ const config = defineConfig({
4
+ define: {
5
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
6
+ },
7
+ build: {
8
+ target: "es2022",
9
+ cssMinify: process.env.NODE_ENV === "production",
10
+ rollupOptions: {
11
+ external: [/node:.*/, "fsevents"]
12
+ },
13
+ assetsInlineLimit: (source) => {
14
+ if (source.endsWith("sprite.svg") || source.endsWith("favicon.svg") || source.endsWith("apple-touch-icon.png")) {
15
+ return false;
16
+ }
17
+ },
18
+ sourcemap: process.env.NODE_ENV === "development" ? true : false
19
+ },
20
+ plugins: [tsconfigPaths()],
21
+ server: {
22
+ allowedHosts: [".local.simpleviewcms.app"],
23
+ watch: {
24
+ usePolling: true
25
+ },
26
+ hmr: {
27
+ path: "/__cms_hmr_ws",
28
+ port: 24678,
29
+ clientPort: 443,
30
+ protocol: "wss"
31
+ }
32
+ }
33
+ });
34
+ export {
35
+ config
36
+ };
37
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/vite/config.ts"],
4
+ "sourcesContent": ["import { defineConfig } from \"vite\";\r\nimport tsconfigPaths from \"vite-tsconfig-paths\";\r\n\r\nexport const config = defineConfig({\r\n\tdefine: {\r\n\t\t\"process.env.NODE_ENV\": JSON.stringify(process.env.NODE_ENV),\r\n\t},\r\n\tbuild: {\r\n\t\ttarget: \"es2022\",\r\n\t\tcssMinify: process.env.NODE_ENV === \"production\",\r\n\t\trollupOptions: {\r\n\t\t\texternal: [/node:.*/, \"fsevents\"],\r\n\t\t},\r\n\t\tassetsInlineLimit: (source) => {\r\n\t\t\tif (\r\n\t\t\t\tsource.endsWith(\"sprite.svg\") ||\r\n\t\t\t\tsource.endsWith(\"favicon.svg\") ||\r\n\t\t\t\tsource.endsWith(\"apple-touch-icon.png\")\r\n\t\t\t) {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t},\r\n\t\tsourcemap: process.env.NODE_ENV === \"development\" ? true : false,\r\n\t},\r\n\tplugins: [tsconfigPaths()],\r\n\tserver: {\r\n\t\tallowedHosts: [\".local.simpleviewcms.app\"],\r\n\t\twatch: {\r\n\t\t\tusePolling: true,\r\n\t\t},\r\n\t\thmr: {\r\n\t\t\tpath: \"/__cms_hmr_ws\",\r\n\t\t\tport: 24678,\r\n\t\t\tclientPort: 443,\r\n\t\t\tprotocol: \"wss\",\r\n\t\t},\r\n\t},\r\n});\r\n"],
5
+ "mappings": "AAAA,SAAS,oBAAoB;AAC7B,OAAO,mBAAmB;AAEnB,MAAM,SAAS,aAAa;AAAA,EAClC,QAAQ;AAAA,IACP,wBAAwB,KAAK,UAAU,QAAQ,IAAI,QAAQ;AAAA,EAC5D;AAAA,EACA,OAAO;AAAA,IACN,QAAQ;AAAA,IACR,WAAW,QAAQ,IAAI,aAAa;AAAA,IACpC,eAAe;AAAA,MACd,UAAU,CAAC,WAAW,UAAU;AAAA,IACjC;AAAA,IACA,mBAAmB,CAAC,WAAW;AAC9B,UACC,OAAO,SAAS,YAAY,KAC5B,OAAO,SAAS,aAAa,KAC7B,OAAO,SAAS,sBAAsB,GACrC;AACD,eAAO;AAAA,MACR;AAAA,IACD;AAAA,IACA,WAAW,QAAQ,IAAI,aAAa,gBAAgB,OAAO;AAAA,EAC5D;AAAA,EACA,SAAS,CAAC,cAAc,CAAC;AAAA,EACzB,QAAQ;AAAA,IACP,cAAc,CAAC,0BAA0B;AAAA,IACzC,OAAO;AAAA,MACN,YAAY;AAAA,IACb;AAAA,IACA,KAAK;AAAA,MACJ,MAAM;AAAA,MACN,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,UAAU;AAAA,IACX;AAAA,EACD;AACD,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./config.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/vite/index.ts"],
4
+ "sourcesContent": ["export * from \"./config.js\";\r\n"],
5
+ "mappings": "AAAA,cAAc;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simpleview/cms-foundation",
3
3
  "type": "module",
4
- "version": "0.0.23",
4
+ "version": "0.0.25",
5
5
  "description": "Provides helper types and components to assist when working with Granicus CMS Reactor.",
6
6
  "packageManager": "yarn@4.6.0+sha224.acd0786f07ffc6c933940eb65fc1d627131ddf5455bddcc295dc90fd",
7
7
  "scripts": {
@@ -29,19 +29,25 @@
29
29
  "./routes": {
30
30
  "import": "./dist/routes/index.js",
31
31
  "types": "./dist/types/routes/index.d.ts"
32
+ },
33
+ "./vite": {
34
+ "import": "./dist/vite/index.js",
35
+ "types": "./dist/types/vite/index.d.ts"
32
36
  }
33
37
  },
34
38
  "devDependencies": {
35
39
  "@react-router/dev": "7.7.0",
36
40
  "@types/node": "^24.1.0",
37
- "@types/react": "^19",
41
+ "@types/react": "19.2.7",
42
+ "@types/react-dom": "19.2.3",
38
43
  "esbuild": "^0.25.8",
39
44
  "tsx": "^4.20.3",
40
- "typescript": "^5.8.3"
45
+ "typescript": "^5.8.3",
46
+ "vite-tsconfig-paths": "5.1.4"
41
47
  },
42
48
  "peerDependencies": {
43
- "react": "19.2.0",
44
- "react-dom": "19.2.0",
49
+ "react": "19.2.3",
50
+ "react-dom": "19.2.3",
45
51
  "react-router": "7.7.0",
46
52
  "vite": "6.2.2"
47
53
  },
@@ -1,31 +0,0 @@
1
- // src/components/Layout/Layout.tsx
2
- import { Links, Meta, Scripts, ScrollRestoration } from "react-router";
3
- import { jsx, jsxs } from "react/jsx-runtime";
4
- var allowIndexing = process.env.NODE_ENV === "production";
5
- function Layout({ children }) {
6
- return /* @__PURE__ */ jsxs("html", { lang: "en", children: [
7
- /* @__PURE__ */ jsxs("head", { children: [
8
- /* @__PURE__ */ jsx(Meta, {}),
9
- /* @__PURE__ */ jsx("meta", { charSet: "utf-8" }),
10
- /* @__PURE__ */ jsx(
11
- "meta",
12
- {
13
- name: "viewport",
14
- content: "width=device-width,initial-scale=1"
15
- }
16
- ),
17
- allowIndexing && /* @__PURE__ */ jsx("meta", { name: "robots", content: "noindex, nofollow" }),
18
- /* @__PURE__ */ jsx(Links, {})
19
- ] }),
20
- /* @__PURE__ */ jsxs("body", { children: [
21
- children,
22
- /* @__PURE__ */ jsx(ScrollRestoration, {}),
23
- /* @__PURE__ */ jsx(Scripts, {})
24
- ] })
25
- ] });
26
- }
27
-
28
- export {
29
- Layout
30
- };
31
- //# sourceMappingURL=chunk-2WII7C3O.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/components/Layout/Layout.tsx"],
4
- "sourcesContent": ["import { Links, Meta, Scripts, ScrollRestoration } from \"react-router\";\n\n// FIXME: This is not ideal as its client-level and we really need site-level\nconst allowIndexing = process.env.NODE_ENV === \"production\";\n\ninterface LayoutProps {\n\tchildren: React.ReactNode;\n}\n\nexport function Layout({ children }: LayoutProps) {\n\treturn (\n\t\t<html lang=\"en\">\n\t\t\t<head>\n\t\t\t\t<Meta />\n\t\t\t\t<meta charSet=\"utf-8\" />\n\t\t\t\t<meta\n\t\t\t\t\tname=\"viewport\"\n\t\t\t\t\tcontent=\"width=device-width,initial-scale=1\"\n\t\t\t\t/>\n\t\t\t\t{allowIndexing && (\n\t\t\t\t\t<meta name=\"robots\" content=\"noindex, nofollow\" />\n\t\t\t\t)}\n\t\t\t\t<Links />\n\t\t\t</head>\n\t\t\t<body>\n\t\t\t\t{children}\n\t\t\t\t<ScrollRestoration />\n\t\t\t\t<Scripts />\n\t\t\t</body>\n\t\t</html>\n\t);\n}\n"],
5
- "mappings": ";AAAA,SAAS,OAAO,MAAM,SAAS,yBAAyB;AAYrD,SACC,KADD;AATH,IAAM,gBAAgB,QAAQ,IAAI,aAAa;AAMxC,SAAS,OAAO,EAAE,SAAS,GAAgB;AACjD,SACC,qBAAC,UAAK,MAAK,MACV;AAAA,yBAAC,UACA;AAAA,0BAAC,QAAK;AAAA,MACN,oBAAC,UAAK,SAAQ,SAAQ;AAAA,MACtB;AAAA,QAAC;AAAA;AAAA,UACA,MAAK;AAAA,UACL,SAAQ;AAAA;AAAA,MACT;AAAA,MACC,iBACA,oBAAC,UAAK,MAAK,UAAS,SAAQ,qBAAoB;AAAA,MAEjD,oBAAC,SAAM;AAAA,OACR;AAAA,IACA,qBAAC,UACC;AAAA;AAAA,MACD,oBAAC,qBAAkB;AAAA,MACnB,oBAAC,WAAQ;AAAA,OACV;AAAA,KACD;AAEF;",
6
- "names": []
7
- }
@@ -1,87 +0,0 @@
1
- import {
2
- PreviewCivWrapper
3
- } from "./chunk-OEYLOZQK.js";
4
- import {
5
- usePreview
6
- } from "./chunk-P3WX4DFS.js";
7
- import {
8
- Error
9
- } from "./chunk-VV3NKXSX.js";
10
- import {
11
- Unknown
12
- } from "./chunk-GPTPACV2.js";
13
-
14
- // src/components/Preview/PreviewContent.tsx
15
- import { jsx } from "react/jsx-runtime";
16
- function PreviewContent() {
17
- const preview = usePreview();
18
- if (!preview || !preview.pageData) {
19
- return null;
20
- }
21
- return /* @__PURE__ */ jsx(Section, { section: [preview.pageData.body] });
22
- }
23
-
24
- // src/contexts/ComponentMapContext.tsx
25
- import { createContext, useContext } from "react";
26
- var ComponentMapContext = createContext({
27
- civs: {
28
- foo: () => null
29
- },
30
- Error,
31
- Unknown
32
- });
33
- var ComponentMapProvider = ComponentMapContext.Provider;
34
- var useComponentMap = () => useContext(ComponentMapContext);
35
-
36
- // src/components/Section/SectionItemCiv.tsx
37
- import { useMatches } from "react-router";
38
- import { jsx as jsx2 } from "react/jsx-runtime";
39
- function SectionItemCiv(civ) {
40
- const map = useComponentMap();
41
- const matches = useMatches();
42
- const [root] = matches;
43
- console.log("Component Map", root.data.clientComponentMap);
44
- if (civ === void 0) {
45
- return /* @__PURE__ */ jsx2(
46
- map.Error,
47
- {
48
- status: 500,
49
- message: "Is the CMS API running? I bet it isn't \u{1F609}"
50
- }
51
- );
52
- }
53
- const Component = map.civs[civ.component];
54
- if (Component === void 0) {
55
- return /* @__PURE__ */ jsx2(map.Unknown, { ...civ });
56
- }
57
- return /* @__PURE__ */ jsx2(Component, { ...civ });
58
- }
59
-
60
- // src/components/Section/SectionItem.tsx
61
- import { jsx as jsx3 } from "react/jsx-runtime";
62
- function SectionItem(civ) {
63
- const preview = usePreview();
64
- if (!preview) {
65
- return /* @__PURE__ */ jsx3(SectionItemCiv, { ...civ });
66
- }
67
- return /* @__PURE__ */ jsx3(PreviewCivWrapper, { civid: civ.civid, ...preview, children: /* @__PURE__ */ jsx3(SectionItemCiv, { ...civ }) });
68
- }
69
-
70
- // src/components/Section/Section.tsx
71
- import { Fragment, jsx as jsx4 } from "react/jsx-runtime";
72
- function Section({ section }) {
73
- if (!Array.isArray(section) || !section.length) {
74
- return null;
75
- }
76
- return /* @__PURE__ */ jsx4(Fragment, { children: section.map((civ) => /* @__PURE__ */ jsx4(SectionItem, { ...civ }, civ.civid)) });
77
- }
78
-
79
- export {
80
- ComponentMapProvider,
81
- useComponentMap,
82
- SectionItemCiv,
83
- SectionItem,
84
- Section,
85
- PreviewContent
86
- };
87
- //# sourceMappingURL=chunk-4GSRDXHP.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/components/Preview/PreviewContent.tsx", "../src/contexts/ComponentMapContext.tsx", "../src/components/Section/SectionItemCiv.tsx", "../src/components/Section/SectionItem.tsx", "../src/components/Section/Section.tsx"],
4
- "sourcesContent": ["import { Section } from \"../Section/Section.js\";\r\nimport { usePreview } from \"./PreviewPageWrapper.js\";\r\n\r\nexport function PreviewContent() {\r\n\tconst preview = usePreview();\r\n\r\n\tif (!preview || !preview.pageData) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\treturn <Section section={[preview.pageData.body]} />;\r\n}\r\n", "import { Unknown, Error, type ErrorProps } from \"../components/index.js\";\r\nimport type { CivProps, ComponentMap } from \"../types/index.js\";\r\nimport { createContext, useContext, type FC } from \"react\";\r\n\r\nconst ComponentMapContext = createContext<{\r\n\tcivs: ComponentMap;\r\n\tError: FC<ErrorProps>;\r\n\tUnknown: FC<CivProps>;\r\n}>({\r\n\tcivs: {\r\n\t\tfoo: () => null,\r\n\t},\r\n\tError,\r\n\tUnknown,\r\n});\r\n\r\nexport const ComponentMapProvider = ComponentMapContext.Provider;\r\n\r\nexport const useComponentMap = () => useContext(ComponentMapContext);\r\n", "import { useComponentMap } from \"../../contexts/index.js\";\r\nimport type { CivProps } from \"../../types/index.js\";\r\nimport { useMatches } from \"react-router\";\r\n\r\nexport function SectionItemCiv(civ: CivProps) {\r\n\tconst map = useComponentMap();\r\n\tconst matches = useMatches();\r\n\r\n\tconst [root] = matches;\r\n\r\n\tconsole.log(\"Component Map\", (root.data as any).clientComponentMap);\r\n\r\n\tif (civ === undefined) {\r\n\t\treturn (\r\n\t\t\t<map.Error\r\n\t\t\t\tstatus={500}\r\n\t\t\t\tmessage=\"Is the CMS API running? I bet it isn't \uD83D\uDE09\"\r\n\t\t\t/>\r\n\t\t);\r\n\t}\r\n\r\n\tconst Component = map.civs[civ.component];\r\n\r\n\tif (Component === undefined) {\r\n\t\treturn <map.Unknown {...civ} />;\r\n\t}\r\n\r\n\treturn <Component {...civ} />;\r\n}\r\n", "import type { CivProps } from \"../../types/index.js\";\r\nimport { PreviewCivWrapper } from \"../Preview/index.js\";\r\nimport { usePreview } from \"../Preview/PreviewPageWrapper.js\";\r\nimport { SectionItemCiv } from \"./SectionItemCiv.js\";\r\n\r\nexport function SectionItem(civ: CivProps) {\r\n\tconst preview = usePreview();\r\n\r\n\tif (!preview) {\r\n\t\treturn <SectionItemCiv {...civ} />;\r\n\t}\r\n\r\n\treturn (\r\n\t\t<PreviewCivWrapper civid={civ.civid} {...preview}>\r\n\t\t\t<SectionItemCiv {...civ} />\r\n\t\t</PreviewCivWrapper>\r\n\t);\r\n}\r\n", "import type { SectionProps } from \"./Section.types.js\";\r\nimport { SectionItem } from \"./SectionItem.js\";\r\n\r\nexport function Section({ section }: SectionProps) {\r\n\tif (!Array.isArray(section) || !section.length) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\treturn (\r\n\t\t<>\r\n\t\t\t{section.map((civ) => (\r\n\t\t\t\t<SectionItem key={civ.civid} {...civ} />\r\n\t\t\t))}\r\n\t\t</>\r\n\t);\r\n}\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAUQ;AAPD,SAAS,iBAAiB;AAChC,QAAM,UAAU,WAAW;AAE3B,MAAI,CAAC,WAAW,CAAC,QAAQ,UAAU;AAClC,WAAO;AAAA,EACR;AAEA,SAAO,oBAAC,WAAQ,SAAS,CAAC,QAAQ,SAAS,IAAI,GAAG;AACnD;;;ACTA,SAAS,eAAe,kBAA2B;AAEnD,IAAM,sBA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,GACF;AAEF;",
6
- "names": ["jsx", "jsx", "jsx"]
7
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-4LSFAAZW.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,31 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
- // If the importer is in node compatibility mode or this is not an ESM
20
- // file that has been converted to a CommonJS file using a Babel-
21
- // compatible transform (i.e. "__esModule" has not been set), then set
22
- // "default" to the CommonJS "module.exports" for node compatibility.
23
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
- mod
25
- ));
26
-
27
- export {
28
- __commonJS,
29
- __toESM
30
- };
31
- //# sourceMappingURL=chunk-5WRI5ZAA.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-CMALSZV3.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-DG37VYL5.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,11 +0,0 @@
1
- // src/utils/getCmsUrl.ts
2
- var { CMS_DOMAIN } = process.env;
3
- function getCmsUrl(host) {
4
- const siteClient = host.split(".")[0];
5
- return new URL(`https://${siteClient}.${CMS_DOMAIN}`);
6
- }
7
-
8
- export {
9
- getCmsUrl
10
- };
11
- //# sourceMappingURL=chunk-EEKFLXZI.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/utils/getCmsUrl.ts"],
4
- "sourcesContent": ["const { CMS_DOMAIN } = process.env;\r\n\r\nexport function getCmsUrl(host: string): URL {\r\n\tconst siteClient = host.split(\".\")[0];\r\n\treturn new URL(`https://${siteClient}.${CMS_DOMAIN}`);\r\n}\r\n"],
5
- "mappings": ";AAAA,IAAM,EAAE,WAAW,IAAI,QAAQ;AAExB,SAAS,UAAU,MAAmB;AAC5C,QAAM,aAAa,KAAK,MAAM,GAAG,EAAE,CAAC;AACpC,SAAO,IAAI,IAAI,WAAW,UAAU,IAAI,UAAU,EAAE;AACrD;",
6
- "names": []
7
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-EG5F4AP4.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-EWRVCIV6.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-F5L7DWHD.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,59 +0,0 @@
1
- import {
2
- getCmsUrl
3
- } from "./chunk-EEKFLXZI.js";
4
-
5
- // src/utils/getPageContent.ts
6
- var previewPath = "/includes/plugins/nav/preview_civs/";
7
- async function getPageContent(req) {
8
- const incomingUrl = new URL(req.url, "http://placeholder.com");
9
- const cmsUrl = getCmsUrl(incomingUrl.host);
10
- if (!incomingUrl.pathname.endsWith("/") || /\.[^/]+$/.test(incomingUrl.pathname)) {
11
- cmsUrl.pathname = incomingUrl.pathname + "/content.json";
12
- } else {
13
- cmsUrl.pathname = incomingUrl.pathname + "content.json";
14
- }
15
- const headers = {
16
- "Accept-Encoding": "gzip",
17
- "X-Forwarded-For": req.headers.get("x-real-ip") || req.headers.get("x-forwarded-host") || "",
18
- "User-Agent": req.headers.get("user-agent") || ""
19
- };
20
- try {
21
- let body = void 0;
22
- if (req.method === "POST" && incomingUrl.pathname === previewPath) {
23
- incomingUrl.searchParams.forEach((val, key) => {
24
- cmsUrl.searchParams.set(key, val);
25
- });
26
- const formData = await req.formData();
27
- const civs = formData.get("headless_civs");
28
- if (typeof civs !== "string") {
29
- throw new Error(
30
- "Posted CIVs were not a base64 encoded string."
31
- );
32
- }
33
- const data = JSON.parse(atob(civs));
34
- return data;
35
- }
36
- const url = cmsUrl.toString();
37
- const { method } = req;
38
- const fetchParams = {
39
- method,
40
- headers,
41
- body
42
- };
43
- console.log("Making page content request:", {
44
- url,
45
- ...fetchParams
46
- });
47
- const result = await fetch(url, fetchParams).then((res) => res.json());
48
- return result;
49
- } catch (err) {
50
- const status = err?.response?.status || 500;
51
- const message = err?.response?.statusText || "Server Error";
52
- throw new Error(`Status ${status}: ${message}`);
53
- }
54
- }
55
-
56
- export {
57
- getPageContent
58
- };
59
- //# sourceMappingURL=chunk-FJML4RHB.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/utils/getPageContent.ts"],
4
- "sourcesContent": ["import type { CivProps, PageData } from \"../types/index.js\";\r\nimport { getCmsUrl } from \"./getCmsUrl.js\";\r\n\r\nexport type { PageData };\r\n\r\nconst previewPath = \"/includes/plugins/nav/preview_civs/\";\r\n\r\nexport async function getPageContent(\r\n\treq: Request\r\n): Promise<PageData<CivProps>> {\r\n\tconst incomingUrl = new URL(req.url, \"http://placeholder.com\");\r\n\tconst cmsUrl = getCmsUrl(incomingUrl.host);\r\n\r\n\tif (\r\n\t\t!incomingUrl.pathname.endsWith(\"/\") ||\r\n\t\t/\\.[^/]+$/.test(incomingUrl.pathname)\r\n\t) {\r\n\t\t// If it's a file request, we append /content.json\r\n\t\tcmsUrl.pathname = incomingUrl.pathname + \"/content.json\";\r\n\t} else {\r\n\t\t// If it's not a file request, we just append content.json since it already ends with a \"/\"\r\n\t\tcmsUrl.pathname = incomingUrl.pathname + \"content.json\";\r\n\t}\r\n\r\n\tconst headers: Record<string, string> = {\r\n\t\t\"Accept-Encoding\": \"gzip\",\r\n\t\t\"X-Forwarded-For\":\r\n\t\t\treq.headers.get(\"x-real-ip\") ||\r\n\t\t\treq.headers.get(\"x-forwarded-host\") ||\r\n\t\t\t\"\",\r\n\t\t\"User-Agent\": req.headers.get(\"user-agent\") || \"\",\r\n\t};\r\n\r\n\ttry {\r\n\t\tlet body: URLSearchParams | undefined = undefined;\r\n\r\n\t\t/**\r\n\t\t * If this is the live preview page, we need to append the search params from the incoming URL\r\n\t\t * and send the CIVs along with the request.\r\n\t\t */\r\n\t\tif (req.method === \"POST\" && incomingUrl.pathname === previewPath) {\r\n\t\t\tincomingUrl.searchParams.forEach((val, key) => {\r\n\t\t\t\tcmsUrl.searchParams.set(key, val);\r\n\t\t\t});\r\n\r\n\t\t\tconst formData = await req.formData();\r\n\t\t\tconst civs = formData.get(\"headless_civs\");\r\n\r\n\t\t\tif (typeof civs !== \"string\") {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t\"Posted CIVs were not a base64 encoded string.\"\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tconst data = JSON.parse(atob(civs));\r\n\r\n\t\t\treturn data;\r\n\t\t}\r\n\r\n\t\tconst url = cmsUrl.toString();\r\n\t\tconst { method } = req;\r\n\t\tconst fetchParams: RequestInit = {\r\n\t\t\tmethod,\r\n\t\t\theaders,\r\n\t\t\tbody,\r\n\t\t};\r\n\r\n\t\tconsole.log(\"Making page content request:\", {\r\n\t\t\turl,\r\n\t\t\t...fetchParams,\r\n\t\t});\r\n\r\n\t\tconst result = await fetch(url, fetchParams).then((res) => res.json());\r\n\t\treturn result;\r\n\t} catch (err: unknown) {\r\n\t\tconst status =\r\n\t\t\t(err as { response?: { status?: number } })?.response?.status ||\r\n\t\t\t500;\r\n\t\tconst message =\r\n\t\t\t(err as { response?: { statusText?: string } })?.response\r\n\t\t\t\t?.statusText || \"Server Error\";\r\n\t\tthrow new Error(`Status ${status}: ${message}`);\r\n\t}\r\n}\r\n"],
5
- "mappings": ";;;;;AAKA,IAAM,cAAc;AAEpB,eAAsB,eACrB,KAC8B;AAC9B,QAAM,cAAc,IAAI,IAAI,IAAI,KAAK,wBAAwB;AAC7D,QAAM,SAAS,UAAU,YAAY,IAAI;AAEzC,MACC,CAAC,YAAY,SAAS,SAAS,GAAG,KAClC,WAAW,KAAK,YAAY,QAAQ,GACnC;AAED,WAAO,WAAW,YAAY,WAAW;AAAA,EAC1C,OAAO;AAEN,WAAO,WAAW,YAAY,WAAW;AAAA,EAC1C;AAEA,QAAM,UAAkC;AAAA,IACvC,mBAAmB;AAAA,IACnB,mBACC,IAAI,QAAQ,IAAI,WAAW,KAC3B,IAAI,QAAQ,IAAI,kBAAkB,KAClC;AAAA,IACD,cAAc,IAAI,QAAQ,IAAI,YAAY,KAAK;AAAA,EAChD;AAEA,MAAI;AACH,QAAI,OAAoC;AAMxC,QAAI,IAAI,WAAW,UAAU,YAAY,aAAa,aAAa;AAClE,kBAAY,a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