@umituz/web-seo 1.0.4 → 2.0.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 (47) hide show
  1. package/README.md +433 -0
  2. package/dist/domains/seo/components/JsonLd.d.ts +17 -0
  3. package/dist/domains/seo/components/JsonLd.d.ts.map +1 -0
  4. package/dist/domains/seo/components/JsonLd.js +52 -0
  5. package/dist/domains/seo/components/SEO.d.ts +4 -0
  6. package/dist/domains/seo/components/SEO.d.ts.map +1 -0
  7. package/dist/domains/seo/components/SEO.js +48 -0
  8. package/dist/domains/seo/core/init.d.ts +16 -0
  9. package/dist/domains/seo/core/init.d.ts.map +1 -0
  10. package/dist/domains/seo/core/init.js +34 -0
  11. package/dist/domains/seo/hooks/useJsonLd.d.ts +19 -0
  12. package/dist/domains/seo/hooks/useJsonLd.d.ts.map +1 -0
  13. package/dist/domains/seo/hooks/useJsonLd.js +53 -0
  14. package/dist/domains/seo/hooks/useSEO.d.ts +3 -0
  15. package/dist/domains/seo/hooks/useSEO.d.ts.map +1 -0
  16. package/dist/domains/seo/hooks/useSEO.js +47 -0
  17. package/dist/domains/seo/index.d.ts +15 -0
  18. package/dist/domains/seo/index.d.ts.map +1 -0
  19. package/dist/domains/seo/index.js +21 -0
  20. package/dist/domains/seo/ssr/renderer.d.ts +58 -0
  21. package/dist/domains/seo/ssr/renderer.d.ts.map +1 -0
  22. package/dist/domains/seo/ssr/renderer.js +242 -0
  23. package/dist/domains/seo/ssr/serializer.d.ts +71 -0
  24. package/dist/domains/seo/ssr/serializer.d.ts.map +1 -0
  25. package/dist/domains/seo/ssr/serializer.js +175 -0
  26. package/dist/domains/seo/types/index.d.ts +190 -0
  27. package/dist/domains/seo/types/index.d.ts.map +1 -0
  28. package/dist/domains/seo/types/index.js +1 -0
  29. package/dist/domains/seo/types/schema.d.ts +212 -0
  30. package/dist/domains/seo/types/schema.d.ts.map +1 -0
  31. package/dist/domains/seo/types/schema.js +4 -0
  32. package/dist/domains/seo/utils/dom.d.ts +22 -0
  33. package/dist/domains/seo/utils/dom.d.ts.map +1 -0
  34. package/dist/domains/seo/utils/dom.js +537 -0
  35. package/dist/domains/seo/utils/schema.d.ts +135 -0
  36. package/dist/domains/seo/utils/schema.d.ts.map +1 -0
  37. package/dist/domains/seo/utils/schema.js +321 -0
  38. package/dist/domains/seo/utils/validators.d.ts +39 -0
  39. package/dist/domains/seo/utils/validators.d.ts.map +1 -0
  40. package/dist/domains/seo/utils/validators.js +364 -0
  41. package/dist/domains/seo/vite/plugin.d.ts +61 -0
  42. package/dist/domains/seo/vite/plugin.d.ts.map +1 -0
  43. package/dist/domains/seo/vite/plugin.js +215 -0
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +6 -0
  47. package/package.json +34 -5
@@ -0,0 +1,3 @@
1
+ import type { SEOptions } from "../types/index.js";
2
+ export declare const useSEO: (options: SEOptions) => void;
3
+ //# sourceMappingURL=useSEO.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSEO.d.ts","sourceRoot":"","sources":["../../../../src/domains/seo/hooks/useSEO.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGnD,eAAO,MAAM,MAAM,GAAI,SAAS,SAAS,SA6CxC,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { useEffect, useMemo } from "react";
2
+ import { updateSEO } from "../utils/dom.js";
3
+ export const useSEO = (options) => {
4
+ // Memoize dependencies for better performance
5
+ const dependencies = useMemo(() => [
6
+ options.title,
7
+ options.description,
8
+ options.lang,
9
+ options.canonical,
10
+ options.themeColor,
11
+ options.favicon,
12
+ JSON.stringify(options.meta),
13
+ JSON.stringify(options.link),
14
+ JSON.stringify(options.openGraph),
15
+ JSON.stringify(options.twitter),
16
+ JSON.stringify(options.jsonLd),
17
+ JSON.stringify(options.hreflang),
18
+ JSON.stringify(options.preload),
19
+ JSON.stringify(options.preconnect),
20
+ JSON.stringify(options.dnsPrefetch),
21
+ JSON.stringify(options.robots),
22
+ JSON.stringify(options.breadcrumbs),
23
+ options.viewport,
24
+ ], [
25
+ options.title,
26
+ options.description,
27
+ options.lang,
28
+ options.canonical,
29
+ options.themeColor,
30
+ options.favicon,
31
+ options.meta,
32
+ options.link,
33
+ options.openGraph,
34
+ options.twitter,
35
+ options.jsonLd,
36
+ options.hreflang,
37
+ options.preload,
38
+ options.preconnect,
39
+ options.dnsPrefetch,
40
+ options.robots,
41
+ options.breadcrumbs,
42
+ options.viewport,
43
+ ]);
44
+ useEffect(() => {
45
+ updateSEO(options);
46
+ }, dependencies);
47
+ };
@@ -0,0 +1,15 @@
1
+ export { SEO } from "./components/SEO.js";
2
+ export { JsonLd } from "./components/JsonLd.js";
3
+ export { useSEO } from "./hooks/useSEO.js";
4
+ export { useJsonLd } from "./hooks/useJsonLd.js";
5
+ export { initSEO } from "./core/init.js";
6
+ export { updateSEO, clearSEO, getCurrentSEOState, } from "./utils/dom.js";
7
+ export { generateArticleSchema, generateProductSchema, generateOrganizationSchema, generateLocalBusinessSchema, generateBreadcrumbSchema, generateFAQSchema, generateWebSiteSchema, generatePersonSchema, generateVideoSchema, } from "./utils/schema.js";
8
+ export { validateSEO, auditSEO, isValidUrl, validateUrl, validateTitleLength, validateDescriptionLength, validateOpenGraphImage, validateHreflangEntry, truncateForSEO, generateSlug, } from "./utils/validators.js";
9
+ export { renderSEO, generateHead, extractSEOData, hydrateSEO, renderAsHelmet, } from "./ssr/renderer.js";
10
+ export { serializeSEO, deserializeSEO, serializeSEOToBase64, deserializeSEOFromBase64, compressSEO, serializeSEOToQueryString, deserializeSEOFromQueryString, safeDeserializeSEO, } from "./ssr/serializer.js";
11
+ export { viteSEOPlugin, quickSEOSetup, } from "./vite/plugin.js";
12
+ export type { ViteSEOPluginOptions } from "./vite/plugin.js";
13
+ export type { MetaTag, LinkTag, ScriptTag, SEOptions, SEOConfig, RobotsMeta, RobotsDirective, HreflangEntry, PreloadHint, PreconnectOrigin, DnsPrefetchDomain, ArticleMeta, ProductMeta, BreadcrumbItem, OpenGraphImage, SEOValidationResult, } from "./types/index.js";
14
+ export type { JsonLdTypes, ArticleJsonLd, ProductJsonLd, OrganizationJsonLd, LocalBusinessJsonLd, BreadcrumbJsonLd, FAQJsonLd, WebSiteJsonLd, PersonJsonLd, VideoJsonLd, SchemaType, SchemaGeneratorOptions, } from "./types/schema.js";
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domains/seo/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,OAAO,EACL,SAAS,EACT,QAAQ,EACR,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,2BAA2B,EAC3B,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,QAAQ,EACR,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACd,YAAY,GACb,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,UAAU,EACV,cAAc,GACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,WAAW,EACX,yBAAyB,EACzB,6BAA6B,EAC7B,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,aAAa,EACb,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,YAAY,EAEV,OAAO,EACP,OAAO,EACP,SAAS,EACT,SAAS,EACT,SAAS,EAGT,UAAU,EACV,eAAe,EAGf,aAAa,EAGb,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EAGjB,WAAW,EACX,WAAW,EACX,cAAc,EAGd,cAAc,EAGd,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAEV,WAAW,EACX,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,WAAW,EACX,UAAU,EACV,sBAAsB,GACvB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,21 @@
1
+ // ============================================================================
2
+ // SEO Domain - Main Exports
3
+ // Domain-Driven Design structure for comprehensive SEO functionality
4
+ // ============================================================================
5
+ // Components
6
+ export { SEO } from "./components/SEO.js";
7
+ export { JsonLd } from "./components/JsonLd.js";
8
+ // Hooks
9
+ export { useSEO } from "./hooks/useSEO.js";
10
+ export { useJsonLd } from "./hooks/useJsonLd.js";
11
+ // Core
12
+ export { initSEO } from "./core/init.js";
13
+ // Utils
14
+ export { updateSEO, clearSEO, getCurrentSEOState, } from "./utils/dom.js";
15
+ export { generateArticleSchema, generateProductSchema, generateOrganizationSchema, generateLocalBusinessSchema, generateBreadcrumbSchema, generateFAQSchema, generateWebSiteSchema, generatePersonSchema, generateVideoSchema, } from "./utils/schema.js";
16
+ export { validateSEO, auditSEO, isValidUrl, validateUrl, validateTitleLength, validateDescriptionLength, validateOpenGraphImage, validateHreflangEntry, truncateForSEO, generateSlug, } from "./utils/validators.js";
17
+ // SSR
18
+ export { renderSEO, generateHead, extractSEOData, hydrateSEO, renderAsHelmet, } from "./ssr/renderer.js";
19
+ export { serializeSEO, deserializeSEO, serializeSEOToBase64, deserializeSEOFromBase64, compressSEO, serializeSEOToQueryString, deserializeSEOFromQueryString, safeDeserializeSEO, } from "./ssr/serializer.js";
20
+ // Vite Plugin
21
+ export { viteSEOPlugin, quickSEOSetup, } from "./vite/plugin.js";
@@ -0,0 +1,58 @@
1
+ /**
2
+ * SEO SSR Renderer
3
+ *
4
+ * Server-side rendering utilities for SEO.
5
+ * Generates HTML strings for meta tags and structured data.
6
+ */
7
+ import type { SEOptions } from "../types/index.js";
8
+ export interface RenderedSEO {
9
+ /** Title tag */
10
+ title: string;
11
+ /** All meta tags as HTML */
12
+ meta: string;
13
+ /** All link tags as HTML */
14
+ link: string;
15
+ /** All JSON-LD scripts as HTML */
16
+ jsonLd: string;
17
+ /** Complete HTML head content */
18
+ toHTML(): string;
19
+ /** Convert to string (same as toHTML) */
20
+ toString(): string;
21
+ }
22
+ /**
23
+ * Render SEO options to HTML strings for server-side rendering
24
+ */
25
+ export declare const renderSEO: (options: SEOptions) => RenderedSEO;
26
+ /**
27
+ * Generate complete HTML head with SEO tags
28
+ */
29
+ export declare const generateHead: (options: SEOptions) => string;
30
+ /**
31
+ * Extract SEO data for hydration
32
+ */
33
+ export declare const extractSEOData: (options: SEOptions) => string;
34
+ /**
35
+ * Hydrate SEO on client side
36
+ */
37
+ export declare const hydrateSEO: (serializedData: string) => void;
38
+ export interface RenderedMetaTag {
39
+ toString(): string;
40
+ toComponent(): any;
41
+ }
42
+ export interface HelmetData {
43
+ base: RenderedMetaTag[];
44
+ bodyAttributes: Record<string, string>;
45
+ htmlAttributes: Record<string, string>;
46
+ link: RenderedMetaTag[];
47
+ meta: RenderedMetaTag[];
48
+ noscript: RenderedMetaTag[];
49
+ script: RenderedMetaTag[];
50
+ style: RenderedMetaTag[];
51
+ title: string;
52
+ titleAttributes: Record<string, string>;
53
+ }
54
+ /**
55
+ * Render SEO in Helmet-compatible format
56
+ */
57
+ export declare const renderAsHelmet: (options: SEOptions) => HelmetData;
58
+ //# sourceMappingURL=renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../../../src/domains/seo/ssr/renderer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,mBAAmB,CAAC;AAMhE,MAAM,WAAW,WAAW;IAC1B,gBAAgB;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,MAAM,IAAI,MAAM,CAAC;IACjB,yCAAyC;IACzC,QAAQ,IAAI,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,GAAI,SAAS,SAAS,KAAG,WA4K9C,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,SAAS,KAAG,MAKjD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,KAAG,MAEnD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,gBAAgB,MAAM,KAAG,IASnD,CAAC;AAMF,MAAM,WAAW,eAAe;IAC9B,QAAQ,IAAI,MAAM,CAAC;IACnB,WAAW,IAAI,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,eAAe,EAAE,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,EAAE,eAAe,EAAE,CAAC;IACxB,IAAI,EAAE,eAAe,EAAE,CAAC;IACxB,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,KAAG,UAenD,CAAC"}
@@ -0,0 +1,242 @@
1
+ /**
2
+ * SEO SSR Renderer
3
+ *
4
+ * Server-side rendering utilities for SEO.
5
+ * Generates HTML strings for meta tags and structured data.
6
+ */
7
+ /**
8
+ * Render SEO options to HTML strings for server-side rendering
9
+ */
10
+ export const renderSEO = (options) => {
11
+ const metaTags = [];
12
+ const linkTags = [];
13
+ const jsonLdScripts = [];
14
+ // Title
15
+ const title = options.titleTemplate
16
+ ? options.titleTemplate.replace("%s", options.title || "")
17
+ : options.title || "";
18
+ // Charset
19
+ metaTags.push('<meta charset="utf-8" />');
20
+ metaTags.push('<meta name="viewport" content="width=device-width, initial-scale=1" />');
21
+ // Description
22
+ if (options.description) {
23
+ metaTags.push(`<meta name="description" content="${options.description}" />`);
24
+ }
25
+ // Robots
26
+ if (options.robots !== undefined) {
27
+ let robotsContent = "";
28
+ if (typeof options.robots === "boolean") {
29
+ robotsContent = options.robots ? "index, follow" : "noindex, nofollow";
30
+ }
31
+ else if (Array.isArray(options.robots)) {
32
+ robotsContent = options.robots.join(", ");
33
+ }
34
+ else {
35
+ const directives = [];
36
+ if (options.robots.index !== undefined)
37
+ directives.push(options.robots.index ? "index" : "noindex");
38
+ if (options.robots.follow !== undefined)
39
+ directives.push(options.robots.follow ? "follow" : "nofollow");
40
+ if (options.robots.archive !== undefined)
41
+ directives.push(options.robots.archive ? "all" : "noarchive");
42
+ if (options.robots.snippet !== undefined)
43
+ directives.push(options.robots.snippet ? "all" : "nosnippet");
44
+ robotsContent = directives.join(", ");
45
+ }
46
+ metaTags.push(`<meta name="robots" content="${robotsContent}" />`);
47
+ }
48
+ // Canonical
49
+ if (options.canonical) {
50
+ linkTags.push(`<link rel="canonical" href="${options.canonical}" />`);
51
+ }
52
+ // Theme color
53
+ if (options.themeColor) {
54
+ metaTags.push(`<meta name="theme-color" content="${options.themeColor}" />`);
55
+ }
56
+ // Favicon
57
+ if (options.favicon) {
58
+ linkTags.push(`<link rel="icon" type="image/x-icon" href="${options.favicon}" />`);
59
+ }
60
+ if (options.appleTouchIcon) {
61
+ linkTags.push(`<link rel="apple-touch-icon" sizes="180x180" href="${options.appleTouchIcon}" />`);
62
+ }
63
+ if (options.maskIcon) {
64
+ linkTags.push(`<link rel="mask-icon" href="${options.maskIcon}" />`);
65
+ }
66
+ // Hreflang
67
+ if (options.hreflang && options.hreflang.length > 0) {
68
+ options.hreflang.forEach((entry) => {
69
+ linkTags.push(`<link rel="alternate" hreflang="${entry.lang}" href="${entry.url}" />`);
70
+ });
71
+ }
72
+ // Preload
73
+ if (options.preload && options.preload.length > 0) {
74
+ options.preload.forEach((preload) => {
75
+ const attrs = [`rel="preload"`, `href="${preload.href}"`, `as="${preload.as}"`];
76
+ if (preload.type)
77
+ attrs.push(`type="${preload.type}"`);
78
+ if (preload.crossOrigin)
79
+ attrs.push(`crossorigin="${preload.crossOrigin}"`);
80
+ if (preload.integrity)
81
+ attrs.push(`integrity="${preload.integrity}"`);
82
+ linkTags.push(`<link ${attrs.join(" ")} />`);
83
+ });
84
+ }
85
+ // Preconnect
86
+ if (options.preconnect && options.preconnect.length > 0) {
87
+ options.preconnect.forEach((origin) => {
88
+ const attrs = [`rel="preconnect"`, `href="${origin.href}"`];
89
+ if (origin.crossOrigin)
90
+ attrs.push(`crossorigin="${origin.crossOrigin}"`);
91
+ linkTags.push(`<link ${attrs.join(" ")} />`);
92
+ });
93
+ }
94
+ // DNS Prefetch
95
+ if (options.dnsPrefetch && options.dnsPrefetch.length > 0) {
96
+ options.dnsPrefetch.forEach((domain) => {
97
+ linkTags.push(`<link rel="dns-prefetch" href="${domain.href}" />`);
98
+ });
99
+ }
100
+ // Custom meta tags
101
+ if (options.meta && options.meta.length > 0) {
102
+ options.meta.forEach((m) => {
103
+ if (m.name) {
104
+ metaTags.push(`<meta name="${m.name}" content="${m.content}" />`);
105
+ }
106
+ if (m.property) {
107
+ metaTags.push(`<meta property="${m.property}" content="${m.content}" />`);
108
+ }
109
+ if (m.httpEquiv) {
110
+ metaTags.push(`<meta http-equiv="${m.httpEquiv}" content="${m.content}" />`);
111
+ }
112
+ });
113
+ }
114
+ // Custom link tags
115
+ if (options.link && options.link.length > 0) {
116
+ options.link.forEach((link) => {
117
+ const attrs = [`rel="${link.rel}"`, `href="${link.href}"`];
118
+ if (link.type)
119
+ attrs.push(`type="${link.type}"`);
120
+ if (link.sizes)
121
+ attrs.push(`sizes="${link.sizes}"`);
122
+ if (link.media)
123
+ attrs.push(`media="${link.media}"`);
124
+ if (link.crossOrigin)
125
+ attrs.push(`crossorigin="${link.crossOrigin}"`);
126
+ if (link.as)
127
+ attrs.push(`as="${link.as}"`);
128
+ linkTags.push(`<link ${attrs.join(" ")} />`);
129
+ });
130
+ }
131
+ // Open Graph
132
+ if (options.openGraph) {
133
+ if (options.openGraph.title)
134
+ metaTags.push(`<meta property="og:title" content="${options.openGraph.title}" />`);
135
+ if (options.openGraph.description)
136
+ metaTags.push(`<meta property="og:description" content="${options.openGraph.description}" />`);
137
+ if (options.openGraph.url)
138
+ metaTags.push(`<meta property="og:url" content="${options.openGraph.url}" />`);
139
+ if (options.openGraph.type)
140
+ metaTags.push(`<meta property="og:type" content="${options.openGraph.type}" />`);
141
+ if (options.openGraph.siteName)
142
+ metaTags.push(`<meta property="og:site_name" content="${options.openGraph.siteName}" />`);
143
+ if (options.openGraph.locale)
144
+ metaTags.push(`<meta property="og:locale" content="${options.openGraph.locale}" />`);
145
+ // Images
146
+ if (options.openGraph.image) {
147
+ if (Array.isArray(options.openGraph.image)) {
148
+ options.openGraph.image.forEach((img) => {
149
+ metaTags.push(`<meta property="og:image" content="${img.url}" />`);
150
+ if (img.alt)
151
+ metaTags.push(`<meta property="og:image:alt" content="${img.alt}" />`);
152
+ });
153
+ }
154
+ else {
155
+ metaTags.push(`<meta property="og:image" content="${options.openGraph.image}" />`);
156
+ }
157
+ }
158
+ }
159
+ // Twitter Card
160
+ if (options.twitter) {
161
+ if (options.twitter.cardType)
162
+ metaTags.push(`<meta name="twitter:card" content="${options.twitter.cardType}" />`);
163
+ if (options.twitter.site)
164
+ metaTags.push(`<meta name="twitter:site" content="${options.twitter.site}" />`);
165
+ if (options.twitter.handle)
166
+ metaTags.push(`<meta name="twitter:creator" content="${options.twitter.handle}" />`);
167
+ if (options.twitter.title)
168
+ metaTags.push(`<meta name="twitter:title" content="${options.twitter.title}" />`);
169
+ if (options.twitter.description)
170
+ metaTags.push(`<meta name="twitter:description" content="${options.twitter.description}" />`);
171
+ if (options.twitter.image)
172
+ metaTags.push(`<meta name="twitter:image" content="${options.twitter.image}" />`);
173
+ if (options.twitter.imageAlt)
174
+ metaTags.push(`<meta name="twitter:image:alt" content="${options.twitter.imageAlt}" />`);
175
+ }
176
+ // JSON-LD
177
+ if (options.jsonLd && options.jsonLd.length > 0) {
178
+ options.jsonLd.forEach((data) => {
179
+ jsonLdScripts.push(`<script type="application/ld+json">${JSON.stringify(data)}</script>`);
180
+ });
181
+ }
182
+ return {
183
+ title,
184
+ meta: metaTags.join("\n "),
185
+ link: linkTags.join("\n "),
186
+ jsonLd: jsonLdScripts.join("\n "),
187
+ toHTML() {
188
+ return ` <title>${this.title}</title>\n${this.meta ? ` ${this.meta}\n` : ""}${this.link ? ` ${this.link}\n` : ""}${this.jsonLd ? ` ${this.jsonLd}\n` : ""}`;
189
+ },
190
+ toString() {
191
+ return this.toHTML();
192
+ },
193
+ };
194
+ };
195
+ // ============================================================================
196
+ // SSR SEO Utilities
197
+ // ============================================================================
198
+ /**
199
+ * Generate complete HTML head with SEO tags
200
+ */
201
+ export const generateHead = (options) => {
202
+ const rendered = renderSEO(options);
203
+ return ` <head${options.lang ? ` lang="${options.lang}"` : ""}>
204
+ ${rendered.toHTML().split("\n").map(line => ` ${line}`).join("\n")}
205
+ </head>`;
206
+ };
207
+ /**
208
+ * Extract SEO data for hydration
209
+ */
210
+ export const extractSEOData = (options) => {
211
+ return JSON.stringify(options);
212
+ };
213
+ /**
214
+ * Hydrate SEO on client side
215
+ */
216
+ export const hydrateSEO = (serializedData) => {
217
+ if (typeof window === "undefined")
218
+ return;
219
+ const options = JSON.parse(serializedData);
220
+ // Import updateSEO dynamically to avoid circular dependencies
221
+ import("../utils/dom.js").then(({ updateSEO }) => {
222
+ updateSEO(options);
223
+ });
224
+ };
225
+ /**
226
+ * Render SEO in Helmet-compatible format
227
+ */
228
+ export const renderAsHelmet = (options) => {
229
+ const rendered = renderSEO(options);
230
+ return {
231
+ base: [],
232
+ bodyAttributes: {},
233
+ htmlAttributes: options.lang ? { lang: options.lang } : {},
234
+ link: [],
235
+ meta: [],
236
+ noscript: [],
237
+ script: [],
238
+ style: [],
239
+ title: rendered.title,
240
+ titleAttributes: {},
241
+ };
242
+ };
@@ -0,0 +1,71 @@
1
+ /**
2
+ * SEO Serializer
3
+ *
4
+ * Serialization utilities for SEO data.
5
+ * Used for server-side rendering and hydration.
6
+ */
7
+ import type { SEOptions } from "../types/index.js";
8
+ /**
9
+ * Serialize SEO options to a string for transmission/hydration
10
+ */
11
+ export declare const serializeSEO: (options: SEOptions) => string;
12
+ /**
13
+ * Deserialize SEO options from a string
14
+ */
15
+ export declare const deserializeSEO: (data: string) => SEOptions;
16
+ /**
17
+ * Serialize SEO options to base64 for safe URL transmission
18
+ */
19
+ export declare const serializeSEOToBase64: (options: SEOptions) => string;
20
+ /**
21
+ * Deserialize SEO options from base64
22
+ */
23
+ export declare const deserializeSEOFromBase64: (base64: string) => SEOptions;
24
+ interface SEOState {
25
+ options: SEOptions;
26
+ timestamp: number;
27
+ }
28
+ /**
29
+ * Create SEO state with timestamp
30
+ */
31
+ export declare const createSEOState: (options: SEOptions) => SEOState;
32
+ /**
33
+ * Serialize SEO state
34
+ */
35
+ export declare const serializeSEOState: (state: SEOState) => string;
36
+ /**
37
+ * Deserialize SEO state
38
+ */
39
+ export declare const deserializeSEOState: (data: string) => SEOState;
40
+ /**
41
+ * Check if SEO state is stale (older than specified milliseconds)
42
+ */
43
+ export declare const isSEOStateStale: (state: SEOState, maxAge?: number) => boolean;
44
+ /**
45
+ * Compress SEO options using simple compression
46
+ * Removes undefined values and empty arrays
47
+ */
48
+ export declare const compressSEO: (options: SEOptions) => SEOptions;
49
+ /**
50
+ * Decompress SEO options (identity function, kept for API consistency)
51
+ */
52
+ export declare const decompressSEO: (options: SEOptions) => SEOptions;
53
+ /**
54
+ * Serialize SEO options to URL-safe query string
55
+ * Only includes essential SEO data for social sharing previews
56
+ */
57
+ export declare const serializeSEOToQueryString: (options: SEOptions) => string;
58
+ /**
59
+ * Deserialize SEO options from query string
60
+ */
61
+ export declare const deserializeSEOFromQueryString: (queryString: string) => Partial<SEOptions>;
62
+ /**
63
+ * Validate serialized SEO data before deserialization
64
+ */
65
+ export declare const validateSerializedSEO: (data: string) => boolean;
66
+ /**
67
+ * Safe deserialize with validation
68
+ */
69
+ export declare const safeDeserializeSEO: (data: string) => SEOptions | null;
70
+ export {};
71
+ //# sourceMappingURL=serializer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../../../../src/domains/seo/ssr/serializer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAMnD;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,SAAS,KAAG,MAEjD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,SAE7C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,SAAS,KAAG,MAOzD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,QAAQ,MAAM,KAAG,SASzD,CAAC;AAMF,UAAU,QAAQ;IAChB,OAAO,EAAE,SAAS,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,KAAG,QAKnD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,QAAQ,KAAG,MAEnD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,KAAG,QAElD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,QAAQ,EAAE,SAAQ,MAAgB,KAAG,OAE3E,CAAC;AAMF;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,SAAS,SAAS,KAAG,SAoBhD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,SAAS,KAAG,SAElD,CAAC;AAMF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,GAAI,SAAS,SAAS,KAAG,MAa9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,6BAA6B,GAAI,aAAa,MAAM,KAAG,OAAO,CAAC,SAAS,CAapF,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,MAAM,MAAM,KAAG,OAOpD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,SAAS,GAAG,IAY7D,CAAC"}
@@ -0,0 +1,175 @@
1
+ /**
2
+ * SEO Serializer
3
+ *
4
+ * Serialization utilities for SEO data.
5
+ * Used for server-side rendering and hydration.
6
+ */
7
+ // ============================================================================
8
+ // Serialization
9
+ // ============================================================================
10
+ /**
11
+ * Serialize SEO options to a string for transmission/hydration
12
+ */
13
+ export const serializeSEO = (options) => {
14
+ return JSON.stringify(options);
15
+ };
16
+ /**
17
+ * Deserialize SEO options from a string
18
+ */
19
+ export const deserializeSEO = (data) => {
20
+ return JSON.parse(data);
21
+ };
22
+ /**
23
+ * Serialize SEO options to base64 for safe URL transmission
24
+ */
25
+ export const serializeSEOToBase64 = (options) => {
26
+ const json = serializeSEO(options);
27
+ if (typeof Buffer !== "undefined") {
28
+ return Buffer.from(json).toString("base64");
29
+ }
30
+ // Browser fallback
31
+ return btoa(json);
32
+ };
33
+ /**
34
+ * Deserialize SEO options from base64
35
+ */
36
+ export const deserializeSEOFromBase64 = (base64) => {
37
+ let json;
38
+ if (typeof Buffer !== "undefined") {
39
+ json = Buffer.from(base64, "base64").toString("utf-8");
40
+ }
41
+ else {
42
+ // Browser fallback
43
+ json = atob(base64);
44
+ }
45
+ return deserializeSEO(json);
46
+ };
47
+ /**
48
+ * Create SEO state with timestamp
49
+ */
50
+ export const createSEOState = (options) => {
51
+ return {
52
+ options,
53
+ timestamp: Date.now(),
54
+ };
55
+ };
56
+ /**
57
+ * Serialize SEO state
58
+ */
59
+ export const serializeSEOState = (state) => {
60
+ return JSON.stringify(state);
61
+ };
62
+ /**
63
+ * Deserialize SEO state
64
+ */
65
+ export const deserializeSEOState = (data) => {
66
+ return JSON.parse(data);
67
+ };
68
+ /**
69
+ * Check if SEO state is stale (older than specified milliseconds)
70
+ */
71
+ export const isSEOStateStale = (state, maxAge = 3600000) => {
72
+ return Date.now() - state.timestamp > maxAge;
73
+ };
74
+ // ============================================================================
75
+ // Compression (for large SEO datasets)
76
+ // ============================================================================
77
+ /**
78
+ * Compress SEO options using simple compression
79
+ * Removes undefined values and empty arrays
80
+ */
81
+ export const compressSEO = (options) => {
82
+ const compressed = {};
83
+ Object.entries(options).forEach(([key, value]) => {
84
+ if (value === undefined || (Array.isArray(value) && value.length === 0)) {
85
+ return;
86
+ }
87
+ // Compress nested objects
88
+ if (typeof value === "object" && !Array.isArray(value)) {
89
+ const compressedNested = compressSEO(value);
90
+ if (Object.keys(compressedNested).length > 0) {
91
+ compressed[key] = compressedNested;
92
+ }
93
+ }
94
+ else {
95
+ compressed[key] = value;
96
+ }
97
+ });
98
+ return compressed;
99
+ };
100
+ /**
101
+ * Decompress SEO options (identity function, kept for API consistency)
102
+ */
103
+ export const decompressSEO = (options) => {
104
+ return options;
105
+ };
106
+ // ============================================================================
107
+ // Query String Serialization
108
+ // ============================================================================
109
+ /**
110
+ * Serialize SEO options to URL-safe query string
111
+ * Only includes essential SEO data for social sharing previews
112
+ */
113
+ export const serializeSEOToQueryString = (options) => {
114
+ const params = new URLSearchParams();
115
+ if (options.title)
116
+ params.set("title", options.title);
117
+ if (options.description)
118
+ params.set("description", options.description);
119
+ if (options.openGraph?.image) {
120
+ const image = Array.isArray(options.openGraph.image)
121
+ ? options.openGraph.image[0]?.url
122
+ : options.openGraph.image;
123
+ if (image)
124
+ params.set("image", image);
125
+ }
126
+ return params.toString();
127
+ };
128
+ /**
129
+ * Deserialize SEO options from query string
130
+ */
131
+ export const deserializeSEOFromQueryString = (queryString) => {
132
+ const params = new URLSearchParams(queryString);
133
+ const options = {};
134
+ if (params.has("title"))
135
+ options.title = params.get("title");
136
+ if (params.has("description"))
137
+ options.description = params.get("description");
138
+ if (params.has("image")) {
139
+ options.openGraph = {
140
+ image: params.get("image"),
141
+ };
142
+ }
143
+ return options;
144
+ };
145
+ // ============================================================================
146
+ // Validation
147
+ // ============================================================================
148
+ /**
149
+ * Validate serialized SEO data before deserialization
150
+ */
151
+ export const validateSerializedSEO = (data) => {
152
+ try {
153
+ const parsed = JSON.parse(data);
154
+ return typeof parsed === "object" && parsed !== null;
155
+ }
156
+ catch {
157
+ return false;
158
+ }
159
+ };
160
+ /**
161
+ * Safe deserialize with validation
162
+ */
163
+ export const safeDeserializeSEO = (data) => {
164
+ if (!validateSerializedSEO(data)) {
165
+ console.error("[SEO] Invalid serialized data");
166
+ return null;
167
+ }
168
+ try {
169
+ return deserializeSEO(data);
170
+ }
171
+ catch (error) {
172
+ console.error("[SEO] Error deserializing data:", error);
173
+ return null;
174
+ }
175
+ };