@puzzle-ui/seo 0.0.0-stage → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/README.md +755 -2
  2. package/dist/LICENSE +21 -0
  3. package/dist/context/config.cjs +82 -0
  4. package/dist/context/config.cjs.map +1 -0
  5. package/dist/context/config.d.cts +6 -0
  6. package/dist/context/config.d.ts +6 -0
  7. package/dist/context/config.js +80 -0
  8. package/dist/context/config.js.map +1 -0
  9. package/dist/context/index.cjs +6 -0
  10. package/dist/context/index.d.cts +4 -0
  11. package/dist/context/index.d.ts +4 -0
  12. package/dist/context/index.js +3 -0
  13. package/dist/context/types.d.cts +46 -0
  14. package/dist/context/types.d.ts +46 -0
  15. package/dist/core/graph.cjs +464 -0
  16. package/dist/core/graph.cjs.map +1 -0
  17. package/dist/core/graph.d.cts +62 -0
  18. package/dist/core/graph.d.ts +62 -0
  19. package/dist/core/graph.js +456 -0
  20. package/dist/core/graph.js.map +1 -0
  21. package/dist/core/index.cjs +11 -0
  22. package/dist/core/index.d.cts +3 -0
  23. package/dist/core/index.d.ts +3 -0
  24. package/dist/core/index.js +1 -0
  25. package/dist/core/types.d.cts +92 -0
  26. package/dist/core/types.d.ts +92 -0
  27. package/dist/index.cjs +96 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +48 -0
  30. package/dist/index.d.ts +38 -0
  31. package/dist/index.js +19 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/metadata/index.cjs +4 -0
  34. package/dist/metadata/index.d.cts +3 -0
  35. package/dist/metadata/index.d.ts +3 -0
  36. package/dist/metadata/index.js +1 -0
  37. package/dist/metadata/resolve.cjs +122 -0
  38. package/dist/metadata/resolve.cjs.map +1 -0
  39. package/dist/metadata/resolve.d.cts +4 -0
  40. package/dist/metadata/resolve.d.ts +4 -0
  41. package/dist/metadata/resolve.js +121 -0
  42. package/dist/metadata/resolve.js.map +1 -0
  43. package/dist/metadata/types.d.cts +82 -0
  44. package/dist/metadata/types.d.ts +82 -0
  45. package/dist/next/index.cjs +13 -0
  46. package/dist/next/index.cjs.map +1 -0
  47. package/dist/next/index.d.cts +15 -0
  48. package/dist/next/index.d.ts +14 -0
  49. package/dist/next/index.js +12 -0
  50. package/dist/next/index.js.map +1 -0
  51. package/dist/react/context.cjs +30 -0
  52. package/dist/react/context.cjs.map +1 -0
  53. package/dist/react/context.d.cts +14 -0
  54. package/dist/react/context.d.ts +14 -0
  55. package/dist/react/context.js +27 -0
  56. package/dist/react/context.js.map +1 -0
  57. package/dist/react/index.cjs +48 -0
  58. package/dist/react/index.d.cts +6 -0
  59. package/dist/react/index.d.ts +6 -0
  60. package/dist/react/index.js +5 -0
  61. package/dist/react/metadata.cjs +100 -0
  62. package/dist/react/metadata.cjs.map +1 -0
  63. package/dist/react/metadata.d.cts +18 -0
  64. package/dist/react/metadata.d.ts +18 -0
  65. package/dist/react/metadata.js +99 -0
  66. package/dist/react/metadata.js.map +1 -0
  67. package/dist/react/provider.cjs +42 -0
  68. package/dist/react/provider.cjs.map +1 -0
  69. package/dist/react/provider.d.cts +3 -0
  70. package/dist/react/provider.d.ts +3 -0
  71. package/dist/react/provider.js +42 -0
  72. package/dist/react/provider.js.map +1 -0
  73. package/dist/react/schema-components.cjs +294 -0
  74. package/dist/react/schema-components.cjs.map +1 -0
  75. package/dist/react/schema-components.d.cts +84 -0
  76. package/dist/react/schema-components.d.ts +80 -0
  77. package/dist/react/schema-components.js +254 -0
  78. package/dist/react/schema-components.js.map +1 -0
  79. package/dist/react/types.d.cts +81 -0
  80. package/dist/react/types.d.ts +80 -0
  81. package/dist/react-router/index.cjs +13 -0
  82. package/dist/react-router/index.cjs.map +1 -0
  83. package/dist/react-router/index.d.cts +21 -0
  84. package/dist/react-router/index.d.ts +20 -0
  85. package/dist/react-router/index.js +12 -0
  86. package/dist/react-router/index.js.map +1 -0
  87. package/dist/robots/generate.cjs +88 -0
  88. package/dist/robots/generate.cjs.map +1 -0
  89. package/dist/robots/generate.d.cts +4 -0
  90. package/dist/robots/generate.d.ts +4 -0
  91. package/dist/robots/generate.js +86 -0
  92. package/dist/robots/generate.js.map +1 -0
  93. package/dist/robots/index.cjs +5 -0
  94. package/dist/robots/index.d.cts +3 -0
  95. package/dist/robots/index.d.ts +3 -0
  96. package/dist/robots/index.js +1 -0
  97. package/dist/robots/types.d.cts +27 -0
  98. package/dist/robots/types.d.ts +27 -0
  99. package/dist/schema/create-registry.cjs +12 -0
  100. package/dist/schema/create-registry.cjs.map +1 -0
  101. package/dist/schema/create-registry.d.cts +2 -0
  102. package/dist/schema/create-registry.d.ts +2 -0
  103. package/dist/schema/create-registry.js +12 -0
  104. package/dist/schema/create-registry.js.map +1 -0
  105. package/dist/schema/generated/index.d.cts +2 -0
  106. package/dist/schema/generated/schemaorg.cjs +36386 -0
  107. package/dist/schema/generated/schemaorg.cjs.map +1 -0
  108. package/dist/schema/generated/schemaorg.d.cts +945 -0
  109. package/dist/schema/generated/schemaorg.d.ts +945 -0
  110. package/dist/schema/generated/schemaorg.js +36384 -0
  111. package/dist/schema/generated/schemaorg.js.map +1 -0
  112. package/dist/schema/index.cjs +11 -0
  113. package/dist/schema/index.d.cts +7 -0
  114. package/dist/schema/index.d.ts +6 -0
  115. package/dist/schema/index.js +5 -0
  116. package/dist/schema/registry.cjs +194 -0
  117. package/dist/schema/registry.cjs.map +1 -0
  118. package/dist/schema/registry.d.cts +2 -0
  119. package/dist/schema/registry.d.ts +2 -0
  120. package/dist/schema/registry.js +194 -0
  121. package/dist/schema/registry.js.map +1 -0
  122. package/dist/schema/types.d.cts +79 -0
  123. package/dist/schema/types.d.ts +79 -0
  124. package/dist/schema/validate.cjs +131 -0
  125. package/dist/schema/validate.cjs.map +1 -0
  126. package/dist/schema/validate.d.cts +16 -0
  127. package/dist/schema/validate.d.ts +16 -0
  128. package/dist/schema/validate.js +131 -0
  129. package/dist/schema/validate.js.map +1 -0
  130. package/dist/server/handlers.cjs +96 -0
  131. package/dist/server/handlers.cjs.map +1 -0
  132. package/dist/server/handlers.d.cts +3 -0
  133. package/dist/server/handlers.d.ts +3 -0
  134. package/dist/server/handlers.js +95 -0
  135. package/dist/server/handlers.js.map +1 -0
  136. package/dist/server/index.cjs +6 -0
  137. package/dist/server/index.d.cts +4 -0
  138. package/dist/server/index.d.ts +4 -0
  139. package/dist/server/index.js +3 -0
  140. package/dist/server/routes.cjs +17 -0
  141. package/dist/server/routes.cjs.map +1 -0
  142. package/dist/server/routes.d.cts +2 -0
  143. package/dist/server/routes.d.ts +2 -0
  144. package/dist/server/routes.js +17 -0
  145. package/dist/server/routes.js.map +1 -0
  146. package/dist/server/types.d.cts +61 -0
  147. package/dist/server/types.d.ts +61 -0
  148. package/dist/sitemap/generate.cjs +147 -0
  149. package/dist/sitemap/generate.cjs.map +1 -0
  150. package/dist/sitemap/generate.d.cts +3 -0
  151. package/dist/sitemap/generate.d.ts +3 -0
  152. package/dist/sitemap/generate.js +146 -0
  153. package/dist/sitemap/generate.js.map +1 -0
  154. package/dist/sitemap/index.cjs +11 -0
  155. package/dist/sitemap/index.d.cts +4 -0
  156. package/dist/sitemap/index.d.ts +4 -0
  157. package/dist/sitemap/index.js +3 -0
  158. package/dist/sitemap/types.d.cts +82 -0
  159. package/dist/sitemap/types.d.ts +82 -0
  160. package/dist/sitemap/xml.cjs +215 -0
  161. package/dist/sitemap/xml.cjs.map +1 -0
  162. package/dist/sitemap/xml.d.cts +16 -0
  163. package/dist/sitemap/xml.d.ts +16 -0
  164. package/dist/sitemap/xml.js +210 -0
  165. package/dist/sitemap/xml.js.map +1 -0
  166. package/dist/tanstack/index.cjs +13 -0
  167. package/dist/tanstack/index.cjs.map +1 -0
  168. package/dist/tanstack/index.d.cts +19 -0
  169. package/dist/tanstack/index.d.ts +18 -0
  170. package/dist/tanstack/index.js +12 -0
  171. package/dist/tanstack/index.js.map +1 -0
  172. package/dist/testing/diagnostics.cjs +27 -0
  173. package/dist/testing/diagnostics.cjs.map +1 -0
  174. package/dist/testing/diagnostics.d.cts +3 -0
  175. package/dist/testing/diagnostics.d.ts +3 -0
  176. package/dist/testing/diagnostics.js +27 -0
  177. package/dist/testing/diagnostics.js.map +1 -0
  178. package/dist/testing/fixture.cjs +80 -0
  179. package/dist/testing/fixture.cjs.map +1 -0
  180. package/dist/testing/fixture.d.cts +4 -0
  181. package/dist/testing/fixture.d.ts +4 -0
  182. package/dist/testing/fixture.js +78 -0
  183. package/dist/testing/fixture.js.map +1 -0
  184. package/dist/testing/index.cjs +9 -0
  185. package/dist/testing/index.d.cts +5 -0
  186. package/dist/testing/index.d.ts +5 -0
  187. package/dist/testing/index.js +4 -0
  188. package/dist/testing/inspect.cjs +63 -0
  189. package/dist/testing/inspect.cjs.map +1 -0
  190. package/dist/testing/inspect.d.cts +5 -0
  191. package/dist/testing/inspect.d.ts +5 -0
  192. package/dist/testing/inspect.js +63 -0
  193. package/dist/testing/inspect.js.map +1 -0
  194. package/dist/testing/types.d.cts +40 -0
  195. package/dist/testing/types.d.ts +40 -0
  196. package/dist/urls/index.cjs +8 -0
  197. package/dist/urls/index.d.cts +3 -0
  198. package/dist/urls/index.d.ts +3 -0
  199. package/dist/urls/index.js +1 -0
  200. package/dist/urls/normalize.cjs +65 -0
  201. package/dist/urls/normalize.cjs.map +1 -0
  202. package/dist/urls/normalize.d.cts +14 -0
  203. package/dist/urls/normalize.d.ts +14 -0
  204. package/dist/urls/normalize.js +60 -0
  205. package/dist/urls/normalize.js.map +1 -0
  206. package/dist/urls/types.d.cts +22 -0
  207. package/dist/urls/types.d.ts +22 -0
  208. package/dist/validation/index.cjs +5 -0
  209. package/dist/validation/index.d.cts +3 -0
  210. package/dist/validation/index.d.ts +3 -0
  211. package/dist/validation/index.js +1 -0
  212. package/dist/validation/types.d.cts +75 -0
  213. package/dist/validation/types.d.ts +75 -0
  214. package/dist/validation/validate.cjs +452 -0
  215. package/dist/validation/validate.cjs.map +1 -0
  216. package/dist/validation/validate.d.cts +7 -0
  217. package/dist/validation/validate.d.ts +6 -0
  218. package/dist/validation/validate.js +450 -0
  219. package/dist/validation/validate.js.map +1 -0
  220. package/package.json +203 -4
package/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sjoerd van Den Berg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,82 @@
1
+ const require_normalize = require("../urls/normalize.cjs");
2
+ // src/context/config.ts
3
+ const DEFAULT_LOCALE = "en";
4
+ const DEFAULT_TRAILING_SLASH = "never";
5
+ const normalizeLocale = (locale) => {
6
+ if (!locale.trim()) throw new Error("SEO locale must not be empty.");
7
+ try {
8
+ const normalized = Intl.getCanonicalLocales(locale)[0];
9
+ if (!normalized) throw new Error(`Invalid SEO locale: "${locale}".`);
10
+ return normalized;
11
+ } catch {
12
+ throw new Error(`Invalid SEO locale: "${locale}".`);
13
+ }
14
+ };
15
+ const normalizeSiteUrl = (value) => {
16
+ let url;
17
+ try {
18
+ url = new URL(value);
19
+ } catch {
20
+ throw new Error(`Invalid SEO siteUrl: "${value}". Expected an absolute HTTP(S) URL.`);
21
+ }
22
+ if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error("SEO siteUrl must use HTTP or HTTPS.");
23
+ if (url.username || url.password) throw new Error("SEO siteUrl must not contain credentials.");
24
+ return url.origin;
25
+ };
26
+ const normalizeLocales = (defaultLocale, supportedLocales) => {
27
+ const normalizedDefault = normalizeLocale(defaultLocale);
28
+ const locales = (supportedLocales?.length ? supportedLocales : [defaultLocale]).map(normalizeLocale);
29
+ if (!locales.includes(normalizedDefault)) locales.unshift(normalizedDefault);
30
+ return {
31
+ defaultLocale: normalizedDefault,
32
+ supportedLocales: [...new Set(locales)]
33
+ };
34
+ };
35
+ const normalizeSeoConfig = (config) => {
36
+ if (!config || typeof config !== "object") throw new Error("SeoProvider requires a valid configuration object.");
37
+ if (typeof config.siteUrl !== "string" || !config.siteUrl.trim()) throw new Error("SEO siteUrl is required.");
38
+ const siteUrl = normalizeSiteUrl(config.siteUrl);
39
+ const locales = normalizeLocales(config.defaultLocale ?? DEFAULT_LOCALE, config.supportedLocales);
40
+ const trailingSlash = config.trailingSlash ?? DEFAULT_TRAILING_SLASH;
41
+ if (![
42
+ "always",
43
+ "never",
44
+ "preserve"
45
+ ].includes(trailingSlash)) throw new Error(`Invalid SEO trailingSlash value: "${trailingSlash}".`);
46
+ if (config.title?.template && !config.title.template.includes("%s")) throw new Error("SEO title.template must contain \"%s\" as the page-title placeholder.");
47
+ const identityUrl = config.identity?.url ? normalizeSiteUrl(config.identity.url) : siteUrl;
48
+ return {
49
+ ...config,
50
+ siteUrl,
51
+ ...locales,
52
+ trailingSlash,
53
+ title: {
54
+ separator: " | ",
55
+ ...config.title
56
+ },
57
+ defaults: { ...config.defaults },
58
+ metadata: { ...config.metadata },
59
+ identity: config.identity ? {
60
+ ...config.identity,
61
+ url: identityUrl,
62
+ sameAs: config.identity.sameAs ? [...config.identity.sameAs] : void 0
63
+ } : void 0
64
+ };
65
+ };
66
+ const resolveSeoUrl = (value, config) => {
67
+ let url;
68
+ try {
69
+ url = new URL(value, config.siteUrl);
70
+ } catch {
71
+ throw new Error(`Invalid SEO URL: "${value}".`);
72
+ }
73
+ if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error(`SEO URL must use HTTP or HTTPS: "${value}".`);
74
+ const siteOrigin = new URL(config.siteUrl).origin;
75
+ if (url.origin === siteOrigin) url.pathname = require_normalize.normalizeSeoPath(url.pathname, config.trailingSlash);
76
+ return url.toString();
77
+ };
78
+ exports.normalizeSeoConfig = normalizeSeoConfig;
79
+ exports.normalizeSeoPath = require_normalize.normalizeSeoPath;
80
+ exports.resolveSeoUrl = resolveSeoUrl;
81
+
82
+ //# sourceMappingURL=config.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.cjs","names":["normalizeSeoPath"],"sources":["../../src/context/config.ts"],"sourcesContent":["import type { SeoLocale, SeoUrl } from \"../core/types\";\nimport { normalizeSeoPath } from \"../urls/normalize\";\nimport type { SeoConfig, SeoResolvedConfig } from \"./types\";\n\nexport { normalizeSeoPath };\n\nconst DEFAULT_LOCALE = \"en\";\nconst DEFAULT_TRAILING_SLASH = \"never\";\n\nconst normalizeLocale = (locale: string): SeoLocale => {\n if (!locale.trim()) {\n throw new Error(\"SEO locale must not be empty.\");\n }\n\n try {\n const normalized = Intl.getCanonicalLocales(locale)[0];\n\n if (!normalized) {\n throw new Error(`Invalid SEO locale: \"${locale}\".`);\n }\n\n return normalized as SeoLocale;\n } catch {\n throw new Error(`Invalid SEO locale: \"${locale}\".`);\n }\n};\n\nconst normalizeSiteUrl = (value: string): SeoUrl => {\n let url: URL;\n\n try {\n url = new URL(value);\n } catch {\n throw new Error(\n `Invalid SEO siteUrl: \"${value}\". Expected an absolute HTTP(S) URL.`,\n );\n }\n\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n throw new Error(\"SEO siteUrl must use HTTP or HTTPS.\");\n }\n\n if (url.username || url.password) {\n throw new Error(\"SEO siteUrl must not contain credentials.\");\n }\n\n // Paths, queries and fragments are dropped: page URLs resolve against the origin.\n return url.origin as SeoUrl;\n};\n\nconst normalizeLocales = (\n defaultLocale: string,\n supportedLocales: readonly string[] | undefined,\n): {\n defaultLocale: SeoLocale;\n supportedLocales: SeoLocale[];\n} => {\n const normalizedDefault = normalizeLocale(defaultLocale);\n\n const locales = (\n supportedLocales?.length ? supportedLocales : [defaultLocale]\n ).map(normalizeLocale);\n\n if (!locales.includes(normalizedDefault)) {\n locales.unshift(normalizedDefault);\n }\n\n return {\n defaultLocale: normalizedDefault,\n supportedLocales: [...new Set(locales)],\n };\n};\n\nexport const normalizeSeoConfig = (config: SeoConfig): SeoResolvedConfig => {\n if (!config || typeof config !== \"object\") {\n throw new Error(\"SeoProvider requires a valid configuration object.\");\n }\n\n if (typeof config.siteUrl !== \"string\" || !config.siteUrl.trim()) {\n throw new Error(\"SEO siteUrl is required.\");\n }\n\n const siteUrl = normalizeSiteUrl(config.siteUrl);\n\n const locales = normalizeLocales(\n config.defaultLocale ?? DEFAULT_LOCALE,\n config.supportedLocales,\n );\n\n const trailingSlash = config.trailingSlash ?? DEFAULT_TRAILING_SLASH;\n\n if (![\"always\", \"never\", \"preserve\"].includes(trailingSlash)) {\n throw new Error(`Invalid SEO trailingSlash value: \"${trailingSlash}\".`);\n }\n\n if (config.title?.template && !config.title.template.includes(\"%s\")) {\n throw new Error(\n 'SEO title.template must contain \"%s\" as the page-title placeholder.',\n );\n }\n\n const identityUrl = config.identity?.url\n ? normalizeSiteUrl(config.identity.url)\n : siteUrl;\n\n return {\n ...config,\n siteUrl,\n ...locales,\n trailingSlash,\n title: {\n separator: \" | \",\n ...config.title,\n },\n defaults: {\n ...config.defaults,\n },\n metadata: {\n ...config.metadata,\n },\n identity: config.identity\n ? {\n ...config.identity,\n url: identityUrl,\n sameAs: config.identity.sameAs\n ? [...config.identity.sameAs]\n : undefined,\n }\n : undefined,\n };\n};\n\nexport const resolveSeoUrl = (\n value: string,\n config: SeoResolvedConfig,\n): SeoUrl => {\n let url: URL;\n\n try {\n url = new URL(value, config.siteUrl);\n } catch {\n throw new Error(`Invalid SEO URL: \"${value}\".`);\n }\n\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n throw new Error(`SEO URL must use HTTP or HTTPS: \"${value}\".`);\n }\n\n const siteOrigin = new URL(config.siteUrl).origin;\n\n if (url.origin === siteOrigin) {\n url.pathname = normalizeSeoPath(url.pathname, config.trailingSlash);\n }\n\n return url.toString() as SeoUrl;\n};\n"],"mappings":";;AAMA,MAAM,iBAAiB;AACvB,MAAM,yBAAyB;AAE/B,MAAM,mBAAmB,WAA8B;CACrD,IAAI,CAAC,OAAO,KAAK,GACf,MAAM,IAAI,MAAM,+BAA+B;CAGjD,IAAI;EACF,MAAM,aAAa,KAAK,oBAAoB,MAAM,CAAC,CAAC;EAEpD,IAAI,CAAC,YACH,MAAM,IAAI,MAAM,wBAAwB,OAAO,GAAG;EAGpD,OAAO;CACT,QAAQ;EACN,MAAM,IAAI,MAAM,wBAAwB,OAAO,GAAG;CACpD;AACF;AAEA,MAAM,oBAAoB,UAA0B;CAClD,IAAI;CAEJ,IAAI;EACF,MAAM,IAAI,IAAI,KAAK;CACrB,QAAQ;EACN,MAAM,IAAI,MACR,yBAAyB,MAAM,qCACjC;CACF;CAEA,IAAI,IAAI,aAAa,WAAW,IAAI,aAAa,UAC/C,MAAM,IAAI,MAAM,qCAAqC;CAGvD,IAAI,IAAI,YAAY,IAAI,UACtB,MAAM,IAAI,MAAM,2CAA2C;CAI7D,OAAO,IAAI;AACb;AAEA,MAAM,oBACJ,eACA,qBAIG;CACH,MAAM,oBAAoB,gBAAgB,aAAa;CAEvD,MAAM,WACJ,kBAAkB,SAAS,mBAAmB,CAAC,aAAa,EAAA,CAC5D,IAAI,eAAe;CAErB,IAAI,CAAC,QAAQ,SAAS,iBAAiB,GACrC,QAAQ,Q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CAAoC,MAAM,GAAG;CAG/D,MAAM,aAAa,IAAI,IAAI,OAAO,OAAO,CAAC,CAAC;CAE3C,IAAI,IAAI,WAAW,YACjB,IAAI,WAAWA,kBAAAA,iBAAiB,IAAI,UAAU,OAAO,aAAa;CAGpE,OAAO,IAAI,SAAS;AACtB"}
@@ -0,0 +1,6 @@
1
+ import { SeoUrl } from "../core/types.cjs";
2
+ import { normalizeSeoPath } from "../urls/normalize.cjs";
3
+ import { SeoConfig, SeoResolvedConfig } from "./types.cjs";
4
+ export declare const normalizeSeoConfig: (config: SeoConfig) => SeoResolvedConfig;
5
+ export declare const resolveSeoUrl: (value: string, config: SeoResolvedConfig) => SeoUrl;
6
+ export { normalizeSeoPath };
@@ -0,0 +1,6 @@
1
+ import { SeoUrl } from "../core/types.js";
2
+ import { SeoConfig, SeoResolvedConfig } from "./types.js";
3
+ import { normalizeSeoPath } from "../urls/normalize.js";
4
+ export declare const normalizeSeoConfig: (config: SeoConfig) => SeoResolvedConfig;
5
+ export declare const resolveSeoUrl: (value: string, config: SeoResolvedConfig) => SeoUrl;
6
+ export { normalizeSeoPath };
@@ -0,0 +1,80 @@
1
+ import { normalizeSeoPath } from "../urls/normalize.js";
2
+ // src/context/config.ts
3
+ const DEFAULT_LOCALE = "en";
4
+ const DEFAULT_TRAILING_SLASH = "never";
5
+ const normalizeLocale = (locale) => {
6
+ if (!locale.trim()) throw new Error("SEO locale must not be empty.");
7
+ try {
8
+ const normalized = Intl.getCanonicalLocales(locale)[0];
9
+ if (!normalized) throw new Error(`Invalid SEO locale: "${locale}".`);
10
+ return normalized;
11
+ } catch {
12
+ throw new Error(`Invalid SEO locale: "${locale}".`);
13
+ }
14
+ };
15
+ const normalizeSiteUrl = (value) => {
16
+ let url;
17
+ try {
18
+ url = new URL(value);
19
+ } catch {
20
+ throw new Error(`Invalid SEO siteUrl: "${value}". Expected an absolute HTTP(S) URL.`);
21
+ }
22
+ if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error("SEO siteUrl must use HTTP or HTTPS.");
23
+ if (url.username || url.password) throw new Error("SEO siteUrl must not contain credentials.");
24
+ return url.origin;
25
+ };
26
+ const normalizeLocales = (defaultLocale, supportedLocales) => {
27
+ const normalizedDefault = normalizeLocale(defaultLocale);
28
+ const locales = (supportedLocales?.length ? supportedLocales : [defaultLocale]).map(normalizeLocale);
29
+ if (!locales.includes(normalizedDefault)) locales.unshift(normalizedDefault);
30
+ return {
31
+ defaultLocale: normalizedDefault,
32
+ supportedLocales: [...new Set(locales)]
33
+ };
34
+ };
35
+ const normalizeSeoConfig = (config) => {
36
+ if (!config || typeof config !== "object") throw new Error("SeoProvider requires a valid configuration object.");
37
+ if (typeof config.siteUrl !== "string" || !config.siteUrl.trim()) throw new Error("SEO siteUrl is required.");
38
+ const siteUrl = normalizeSiteUrl(config.siteUrl);
39
+ const locales = normalizeLocales(config.defaultLocale ?? DEFAULT_LOCALE, config.supportedLocales);
40
+ const trailingSlash = config.trailingSlash ?? DEFAULT_TRAILING_SLASH;
41
+ if (![
42
+ "always",
43
+ "never",
44
+ "preserve"
45
+ ].includes(trailingSlash)) throw new Error(`Invalid SEO trailingSlash value: "${trailingSlash}".`);
46
+ if (config.title?.template && !config.title.template.includes("%s")) throw new Error("SEO title.template must contain \"%s\" as the page-title placeholder.");
47
+ const identityUrl = config.identity?.url ? normalizeSiteUrl(config.identity.url) : siteUrl;
48
+ return {
49
+ ...config,
50
+ siteUrl,
51
+ ...locales,
52
+ trailingSlash,
53
+ title: {
54
+ separator: " | ",
55
+ ...config.title
56
+ },
57
+ defaults: { ...config.defaults },
58
+ metadata: { ...config.metadata },
59
+ identity: config.identity ? {
60
+ ...config.identity,
61
+ url: identityUrl,
62
+ sameAs: config.identity.sameAs ? [...config.identity.sameAs] : void 0
63
+ } : void 0
64
+ };
65
+ };
66
+ const resolveSeoUrl = (value, config) => {
67
+ let url;
68
+ try {
69
+ url = new URL(value, config.siteUrl);
70
+ } catch {
71
+ throw new Error(`Invalid SEO URL: "${value}".`);
72
+ }
73
+ if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error(`SEO URL must use HTTP or HTTPS: "${value}".`);
74
+ const siteOrigin = new URL(config.siteUrl).origin;
75
+ if (url.origin === siteOrigin) url.pathname = normalizeSeoPath(url.pathname, config.trailingSlash);
76
+ return url.toString();
77
+ };
78
+ export { normalizeSeoConfig, normalizeSeoPath, resolveSeoUrl };
79
+
80
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","names":[],"sources":["../../src/context/config.ts"],"sourcesContent":["import type { SeoLocale, SeoUrl } from \"../core/types\";\nimport { normalizeSeoPath } from \"../urls/normalize\";\nimport type { SeoConfig, SeoResolvedConfig } from \"./types\";\n\nexport { normalizeSeoPath };\n\nconst DEFAULT_LOCALE = \"en\";\nconst DEFAULT_TRAILING_SLASH = \"never\";\n\nconst normalizeLocale = (locale: string): SeoLocale => {\n if (!locale.trim()) {\n throw new Error(\"SEO locale must not be empty.\");\n }\n\n try {\n const normalized = Intl.getCanonicalLocales(locale)[0];\n\n if (!normalized) {\n throw new Error(`Invalid SEO locale: \"${locale}\".`);\n }\n\n return normalized as SeoLocale;\n } catch {\n throw new Error(`Invalid SEO locale: \"${locale}\".`);\n }\n};\n\nconst normalizeSiteUrl = (value: string): SeoUrl => {\n let url: URL;\n\n try {\n url = new URL(value);\n } catch {\n throw new Error(\n `Invalid SEO siteUrl: \"${value}\". Expected an absolute HTTP(S) URL.`,\n );\n }\n\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n throw new Error(\"SEO siteUrl must use HTTP or HTTPS.\");\n }\n\n if (url.username || url.password) {\n throw new Error(\"SEO siteUrl must not contain credentials.\");\n }\n\n // Paths, queries and fragments are dropped: page URLs resolve against the origin.\n return url.origin as SeoUrl;\n};\n\nconst normalizeLocales = (\n defaultLocale: string,\n supportedLocales: readonly string[] | undefined,\n): {\n defaultLocale: SeoLocale;\n supportedLocales: SeoLocale[];\n} => {\n const normalizedDefault = normalizeLocale(defaultLocale);\n\n const locales = (\n supportedLocales?.length ? supportedLocales : [defaultLocale]\n ).map(normalizeLocale);\n\n if (!locales.includes(normalizedDefault)) {\n locales.unshift(normalizedDefault);\n }\n\n return {\n defaultLocale: normalizedDefault,\n supportedLocales: [...new Set(locales)],\n };\n};\n\nexport const normalizeSeoConfig = (config: SeoConfig): SeoResolvedConfig => {\n if (!config || typeof config !== \"object\") {\n throw new Error(\"SeoProvider requires a valid configuration object.\");\n }\n\n if (typeof config.siteUrl !== \"string\" || !config.siteUrl.trim()) {\n throw new Error(\"SEO siteUrl is required.\");\n }\n\n const siteUrl = normalizeSiteUrl(config.siteUrl);\n\n const locales = normalizeLocales(\n config.defaultLocale ?? DEFAULT_LOCALE,\n config.supportedLocales,\n );\n\n const trailingSlash = config.trailingSlash ?? DEFAULT_TRAILING_SLASH;\n\n if (![\"always\", \"never\", \"preserve\"].includes(trailingSlash)) {\n throw new Error(`Invalid SEO trailingSlash value: \"${trailingSlash}\".`);\n }\n\n if (config.title?.template && !config.title.template.includes(\"%s\")) {\n throw new Error(\n 'SEO title.template must contain \"%s\" as the page-title placeholder.',\n );\n }\n\n const identityUrl = config.identity?.url\n ? normalizeSiteUrl(config.identity.url)\n : siteUrl;\n\n return {\n ...config,\n siteUrl,\n ...locales,\n trailingSlash,\n title: {\n separator: \" | \",\n ...config.title,\n },\n defaults: {\n ...config.defaults,\n },\n metadata: {\n ...config.metadata,\n },\n identity: config.identity\n ? {\n ...config.identity,\n url: identityUrl,\n sameAs: config.identity.sameAs\n ? [...config.identity.sameAs]\n : undefined,\n }\n : undefined,\n };\n};\n\nexport const resolveSeoUrl = (\n value: string,\n config: SeoResolvedConfig,\n): SeoUrl => {\n let url: URL;\n\n try {\n url = new URL(value, config.siteUrl);\n } catch {\n throw new Error(`Invalid SEO URL: \"${value}\".`);\n }\n\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n throw new Error(`SEO URL must use HTTP or HTTPS: \"${value}\".`);\n }\n\n const siteOrigin = new URL(config.siteUrl).origin;\n\n if (url.origin === siteOrigin) {\n url.pathname = normalizeSeoPath(url.pathname, config.trailingSlash);\n }\n\n return url.toString() as SeoUrl;\n};\n"],"mappings":";;AAMA,MAAM,iBAAiB;AACvB,MAAM,yBAAyB;AAE/B,MAAM,mBAAmB,WAA8B;CACrD,IAAI,CAAC,OAAO,KAAK,GACf,MAAM,IAAI,MAAM,+BAA+B;CAGjD,IAAI;EACF,MAAM,aAAa,KAAK,oBAAoB,MAAM,CAAC,CAAC;EAEpD,IAAI,CAAC,YACH,MAAM,IAAI,MAAM,wBAAwB,OAAO,GAAG;EAGpD,OAAO;CACT,QAAQ;EACN,MAAM,IAAI,MAAM,wBAAwB,OAAO,GAAG;CACpD;AACF;AAEA,MAAM,oBAAoB,UAA0B;CAClD,IAAI;CAEJ,IAAI;EACF,MAAM,IAAI,IAAI,KAAK;CACrB,QAAQ;EACN,MAAM,IAAI,MACR,yBAAyB,MAAM,qCACjC;CACF;CAEA,IAAI,IAAI,aAAa,WAAW,IAAI,aAAa,UAC/C,MAAM,IAAI,MAAM,qCAAqC;CAGvD,IAAI,IAAI,YAAY,IAAI,UACtB,MAAM,IAAI,MAAM,2CAA2C;CAI7D,OAAO,IAAI;AACb;AAEA,MAAM,oBACJ,eACA,qBAIG;CACH,MAAM,oBAAoB,gBAAgB,aAAa;CAEvD,MAAM,WACJ,kBAAkB,SAAS,mBAAmB,CAAC,aAAa,EAAA,CAC5D,IAAI,eAAe;CAErB,IAAI,CAAC,QAAQ,SAAS,iBAAiB,GACrC,QAAQ,QAAQ,iBAAiB;CAGnC,OAAO;EACL,eAAe;EACf,kBAAkB,CAAC,GAAG,IAAI,IAAI,OAAO,CAAC;CACxC;AACF;AAEA,MAAa,sBAAsB,WAAyC;CAC1E,IAAI,CAAC,UAAU,OAAO,WAAW,UAC/B,MAAM,IAAI,MAAM,oDAAoD;CAGtE,IAAI,OAAO,OAAO,YAAY,YAAY,CAAC,OAAO,QAAQ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const require_normalize = require("../urls/normalize.cjs");
3
+ const require_config = require("./config.cjs");
4
+ exports.normalizeSeoConfig = require_config.normalizeSeoConfig;
5
+ exports.normalizeSeoPath = require_normalize.normalizeSeoPath;
6
+ exports.resolveSeoUrl = require_config.resolveSeoUrl;
@@ -0,0 +1,4 @@
1
+ import { SeoConfig, SeoConfigContext, SeoConfigOverride, SeoDefaultMetadata, SeoResolvedConfig, SeoSiteIdentity, SeoTitleConfig, SeoTrailingSlash } from "./types.cjs";
2
+ import { normalizeSeoPath } from "../urls/normalize.cjs";
3
+ import { normalizeSeoConfig, resolveSeoUrl } from "./config.cjs";
4
+ export { type SeoConfig, type SeoConfigContext, type SeoConfigOverride, type SeoDefaultMetadata, type SeoResolvedConfig, type SeoSiteIdentity, type SeoTitleConfig, type SeoTrailingSlash, normalizeSeoConfig, normalizeSeoPath, resolveSeoUrl };
@@ -0,0 +1,4 @@
1
+ import { SeoConfig, SeoConfigContext, SeoConfigOverride, SeoDefaultMetadata, SeoResolvedConfig, SeoSiteIdentity, SeoTitleConfig, SeoTrailingSlash } from "./types.js";
2
+ import { normalizeSeoPath } from "../urls/normalize.js";
3
+ import { normalizeSeoConfig, resolveSeoUrl } from "./config.js";
4
+ export { type SeoConfig, type SeoConfigContext, type SeoConfigOverride, type SeoDefaultMetadata, type SeoResolvedConfig, type SeoSiteIdentity, type SeoTitleConfig, type SeoTrailingSlash, normalizeSeoConfig, normalizeSeoPath, resolveSeoUrl };
@@ -0,0 +1,3 @@
1
+ import { normalizeSeoPath } from "../urls/normalize.js";
2
+ import { normalizeSeoConfig, resolveSeoUrl } from "./config.js";
3
+ export { normalizeSeoConfig, normalizeSeoPath, resolveSeoUrl };
@@ -0,0 +1,46 @@
1
+ import { SeoLocale, SeoMetadata, SeoUrl } from "../core/types.cjs";
2
+ export type SeoTrailingSlash = "always" | "never" | "preserve";
3
+ export interface SeoTitleConfig {
4
+ default?: string;
5
+ template?: string;
6
+ separator?: string;
7
+ }
8
+ export interface SeoDefaultMetadata {
9
+ title?: string;
10
+ description?: string;
11
+ canonical?: string;
12
+ robots?: string;
13
+ }
14
+ export interface SeoSiteIdentity {
15
+ name: string;
16
+ url?: string;
17
+ logo?: string;
18
+ description?: string;
19
+ sameAs?: string[];
20
+ }
21
+ export interface SeoConfig {
22
+ siteUrl: SeoUrl | string;
23
+ defaultLocale?: SeoLocale | string;
24
+ supportedLocales?: Array<SeoLocale | string>;
25
+ trailingSlash?: SeoTrailingSlash;
26
+ title?: SeoTitleConfig;
27
+ defaults?: SeoDefaultMetadata;
28
+ identity?: SeoSiteIdentity;
29
+ metadata?: SeoMetadata;
30
+ debug?: boolean;
31
+ }
32
+ export interface SeoResolvedConfig extends Omit<SeoConfig, "siteUrl"> {
33
+ siteUrl: SeoUrl;
34
+ defaultLocale: SeoLocale;
35
+ supportedLocales: SeoLocale[];
36
+ trailingSlash: SeoTrailingSlash;
37
+ }
38
+ export interface SeoConfigOverride {
39
+ title?: SeoTitleConfig;
40
+ defaults?: SeoDefaultMetadata;
41
+ metadata?: SeoMetadata;
42
+ }
43
+ export interface SeoConfigContext {
44
+ config: SeoResolvedConfig;
45
+ overrides?: SeoConfigOverride;
46
+ }
@@ -0,0 +1,46 @@
1
+ import { SeoLocale, SeoMetadata, SeoUrl } from "../core/types.js";
2
+ export type SeoTrailingSlash = "always" | "never" | "preserve";
3
+ export interface SeoTitleConfig {
4
+ default?: string;
5
+ template?: string;
6
+ separator?: string;
7
+ }
8
+ export interface SeoDefaultMetadata {
9
+ title?: string;
10
+ description?: string;
11
+ canonical?: string;
12
+ robots?: string;
13
+ }
14
+ export interface SeoSiteIdentity {
15
+ name: string;
16
+ url?: string;
17
+ logo?: string;
18
+ description?: string;
19
+ sameAs?: string[];
20
+ }
21
+ export interface SeoConfig {
22
+ siteUrl: SeoUrl | string;
23
+ defaultLocale?: SeoLocale | string;
24
+ supportedLocales?: Array<SeoLocale | string>;
25
+ trailingSlash?: SeoTrailingSlash;
26
+ title?: SeoTitleConfig;
27
+ defaults?: SeoDefaultMetadata;
28
+ identity?: SeoSiteIdentity;
29
+ metadata?: SeoMetadata;
30
+ debug?: boolean;
31
+ }
32
+ export interface SeoResolvedConfig extends Omit<SeoConfig, "siteUrl"> {
33
+ siteUrl: SeoUrl;
34
+ defaultLocale: SeoLocale;
35
+ supportedLocales: SeoLocale[];
36
+ trailingSlash: SeoTrailingSlash;
37
+ }
38
+ export interface SeoConfigOverride {
39
+ title?: SeoTitleConfig;
40
+ defaults?: SeoDefaultMetadata;
41
+ metadata?: SeoMetadata;
42
+ }
43
+ export interface SeoConfigContext {
44
+ config: SeoResolvedConfig;
45
+ overrides?: SeoConfigOverride;
46
+ }