yaxa-svelte 2.7.0 → 2.8.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.
- package/README.md +66 -21
- package/dist/auth/index.d.ts +7 -1
- package/dist/auth/index.js +3 -0
- package/dist/components/ai/ai.test.js +68 -1
- package/dist/components/ai/index.d.ts +2 -0
- package/dist/components/ai/index.js +1 -0
- package/dist/components/ai/useAiChat.svelte.d.ts +68 -0
- package/dist/components/ai/useAiChat.svelte.js +258 -0
- package/dist/components/blocks/FAQ.svelte +11 -0
- package/dist/components/blocks/FAQ.svelte.d.ts +1 -0
- package/dist/components/blocks/FAQ.test.js +20 -0
- package/dist/components/saas/AuthCard.svelte +16 -12
- package/dist/components/saas/AuthCard.svelte.d.ts +3 -3
- package/dist/components/saas/ResetPasswordCard.svelte +13 -0
- package/dist/components/saas/ResetPasswordCard.svelte.d.ts +5 -0
- package/dist/components/saas/SignInCard.svelte +13 -0
- package/dist/components/saas/SignInCard.svelte.d.ts +5 -0
- package/dist/components/saas/SignUpCard.svelte +13 -0
- package/dist/components/saas/SignUpCard.svelte.d.ts +5 -0
- package/dist/components/saas/auth-cards.test.d.ts +1 -0
- package/dist/components/saas/auth-cards.test.js +42 -0
- package/dist/components/seo/Seo.svelte +16 -9
- package/dist/index.d.ts +21 -2
- package/dist/index.js +12 -1
- package/dist/server/ai/index.d.ts +2 -0
- package/dist/server/ai/index.js +1 -0
- package/dist/server/ai/stream.d.ts +24 -0
- package/dist/server/ai/stream.js +178 -0
- package/dist/server/ai/stream.test.d.ts +1 -0
- package/dist/server/ai/stream.test.js +83 -0
- package/dist/server/ai/types.d.ts +43 -0
- package/dist/server/ai/types.js +1 -0
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +4 -0
- package/dist/site/context.svelte.d.ts +3 -0
- package/dist/site/context.svelte.js +7 -0
- package/dist/site/hook.d.ts +5 -1
- package/dist/site/hook.js +11 -1
- package/dist/site/index.d.ts +26 -0
- package/dist/site/index.js +25 -0
- package/dist/site/llms.d.ts +27 -0
- package/dist/site/llms.js +58 -0
- package/dist/site/schema.d.ts +45 -0
- package/dist/site/schema.js +43 -0
- package/dist/site/seo-helpers.d.ts +1 -0
- package/dist/site/site-export.test.d.ts +1 -0
- package/dist/site/site-export.test.js +193 -0
- package/dist/site/skill.d.ts +26 -0
- package/dist/site/skill.js +69 -0
- package/dist/site/useSeo.svelte.d.ts +23 -0
- package/dist/site/useSeo.svelte.js +40 -0
- package/dist/site/useSeo.test.d.ts +1 -0
- package/dist/site/useSeo.test.js +35 -0
- package/package.json +5 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { defineSiteConfig, DEFAULT_SITE_CONFIG, createRobotsHandler, createSitemapHandler, createSitemapXslHandler, generateSitemapXsl, createManifestHandler, createOgImageHandler, generateOgSvg, generateWebSiteSchema, generateOrganizationSchema, generateSoftwareApplicationSchema, generateFaqSchema, generateProductSchema, createLlmsTxtHandler, generateLlmsTxt, createSkillHandler, generateSkillMd, definePageSeo, createYaxaHook, useSeo, Seo, Favicons } from './index.js';
|
|
3
|
+
describe('yaxa-svelte/seo Subpath Exports', () => {
|
|
4
|
+
const config = defineSiteConfig({
|
|
5
|
+
name: 'Acme Static Site',
|
|
6
|
+
title: 'Acme — Built for Speed',
|
|
7
|
+
description: 'A pure static SvelteKit site using @sveltejs/adapter-static',
|
|
8
|
+
url: 'https://acme.example.com',
|
|
9
|
+
theme: {
|
|
10
|
+
primaryColor: '#6366f1'
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
it('exports all expected SEO functions, components, and generators', () => {
|
|
14
|
+
expect(typeof defineSiteConfig).toBe('function');
|
|
15
|
+
expect(typeof createRobotsHandler).toBe('function');
|
|
16
|
+
expect(typeof createSitemapHandler).toBe('function');
|
|
17
|
+
expect(typeof createSitemapXslHandler).toBe('function');
|
|
18
|
+
expect(typeof generateSitemapXsl).toBe('function');
|
|
19
|
+
expect(typeof createManifestHandler).toBe('function');
|
|
20
|
+
expect(typeof createOgImageHandler).toBe('function');
|
|
21
|
+
expect(typeof generateOgSvg).toBe('function');
|
|
22
|
+
expect(typeof generateWebSiteSchema).toBe('function');
|
|
23
|
+
expect(typeof generateOrganizationSchema).toBe('function');
|
|
24
|
+
expect(typeof generateSoftwareApplicationSchema).toBe('function');
|
|
25
|
+
expect(typeof generateFaqSchema).toBe('function');
|
|
26
|
+
expect(typeof generateProductSchema).toBe('function');
|
|
27
|
+
expect(typeof createLlmsTxtHandler).toBe('function');
|
|
28
|
+
expect(typeof generateLlmsTxt).toBe('function');
|
|
29
|
+
expect(typeof createSkillHandler).toBe('function');
|
|
30
|
+
expect(typeof generateSkillMd).toBe('function');
|
|
31
|
+
expect(typeof definePageSeo).toBe('function');
|
|
32
|
+
expect(typeof createYaxaHook).toBe('function');
|
|
33
|
+
expect(typeof useSeo).toBe('function');
|
|
34
|
+
expect(Seo).toBeDefined();
|
|
35
|
+
expect(Favicons).toBeDefined();
|
|
36
|
+
expect(DEFAULT_SITE_CONFIG).toBeDefined();
|
|
37
|
+
});
|
|
38
|
+
it('generates static XML sitemap with XSL stylesheet reference', async () => {
|
|
39
|
+
const handler = createSitemapHandler({
|
|
40
|
+
config,
|
|
41
|
+
staticRoutes: ['/', '/docs', '/about']
|
|
42
|
+
});
|
|
43
|
+
const response = (await handler({
|
|
44
|
+
url: new URL('https://acme.example.com/sitemap.xml')
|
|
45
|
+
}));
|
|
46
|
+
expect(response.headers.get('Content-Type')).toContain('application/xml');
|
|
47
|
+
const body = await response.text();
|
|
48
|
+
expect(body).toContain('<?xml version="1.0" encoding="UTF-8"?>');
|
|
49
|
+
expect(body).toContain('xml-stylesheet type="text/xsl" href="/sitemap.xsl"');
|
|
50
|
+
expect(body).toContain('<loc>https://acme.example.com/</loc>');
|
|
51
|
+
expect(body).toContain('<loc>https://acme.example.com/docs</loc>');
|
|
52
|
+
expect(body).toContain('<loc>https://acme.example.com/about</loc>');
|
|
53
|
+
});
|
|
54
|
+
it('generates human-readable sitemap XSL stylesheet with themed styling', async () => {
|
|
55
|
+
const xsl = generateSitemapXsl(config);
|
|
56
|
+
expect(xsl).toContain('<?xml version="1.0" encoding="UTF-8"?>');
|
|
57
|
+
expect(xsl).toContain('<xsl:stylesheet');
|
|
58
|
+
expect(xsl).toContain('Acme Static Site');
|
|
59
|
+
expect(xsl).toContain('#6366f1');
|
|
60
|
+
});
|
|
61
|
+
it('generates robots.txt with sitemap reference and preview protection', async () => {
|
|
62
|
+
const handler = createRobotsHandler({
|
|
63
|
+
config,
|
|
64
|
+
isProduction: true
|
|
65
|
+
});
|
|
66
|
+
const response = (await handler({
|
|
67
|
+
url: new URL('https://acme.example.com/robots.txt')
|
|
68
|
+
}));
|
|
69
|
+
expect(response.headers.get('Content-Type')).toContain('text/plain');
|
|
70
|
+
const body = await response.text();
|
|
71
|
+
expect(body).toContain('User-agent: *');
|
|
72
|
+
expect(body).toContain('Sitemap: https://acme.example.com/sitemap.xml');
|
|
73
|
+
});
|
|
74
|
+
it('generates dynamic SVG OpenGraph card in pure static/serverless execution', async () => {
|
|
75
|
+
const svg = generateOgSvg({
|
|
76
|
+
title: 'Pure Static Documentation',
|
|
77
|
+
description: 'Blazing fast SSG with zero server overhead',
|
|
78
|
+
siteName: 'Acme Static Site'
|
|
79
|
+
});
|
|
80
|
+
expect(svg).toContain('<svg');
|
|
81
|
+
expect(svg).toContain('Pure Static Documentation');
|
|
82
|
+
expect(svg).toContain('Blazing fast SSG with zero server overhead');
|
|
83
|
+
expect(svg).toContain('Acme Static Site');
|
|
84
|
+
});
|
|
85
|
+
it('generates Schema.org JSON-LD structured data', () => {
|
|
86
|
+
const schema = generateWebSiteSchema(config);
|
|
87
|
+
expect(schema['@context']).toBe('https://schema.org');
|
|
88
|
+
expect(schema['@type']).toBe('WebSite');
|
|
89
|
+
expect(schema.name).toBe('Acme Static Site');
|
|
90
|
+
expect(schema.url).toBe('https://acme.example.com');
|
|
91
|
+
});
|
|
92
|
+
it('generates valid Schema.org FAQPage rich snippet JSON-LD', () => {
|
|
93
|
+
const faq = generateFaqSchema([
|
|
94
|
+
{ question: 'What is Yaxa?', answer: 'The intuitive UI and SaaS library for Svelte 5.' },
|
|
95
|
+
{ question: 'Is it free?', answer: 'Yes, it is MIT licensed open-source software.' }
|
|
96
|
+
]);
|
|
97
|
+
expect(faq['@context']).toBe('https://schema.org');
|
|
98
|
+
expect(faq['@type']).toBe('FAQPage');
|
|
99
|
+
expect(faq.mainEntity).toHaveLength(2);
|
|
100
|
+
expect(faq.mainEntity[0].name).toBe('What is Yaxa?');
|
|
101
|
+
expect(faq.mainEntity[0].acceptedAnswer.text).toBe('The intuitive UI and SaaS library for Svelte 5.');
|
|
102
|
+
});
|
|
103
|
+
it('generates valid Schema.org Product and Offer JSON-LD', () => {
|
|
104
|
+
const product = generateProductSchema(config, {
|
|
105
|
+
name: 'Pro Subscription',
|
|
106
|
+
description: 'Full-stack SaaS toolkit access',
|
|
107
|
+
price: 29,
|
|
108
|
+
currency: 'USD',
|
|
109
|
+
inStock: true
|
|
110
|
+
});
|
|
111
|
+
expect(product['@context']).toBe('https://schema.org');
|
|
112
|
+
expect(product['@type']).toBe('Product');
|
|
113
|
+
expect(product.name).toBe('Pro Subscription');
|
|
114
|
+
expect(product.offers['@type']).toBe('Offer');
|
|
115
|
+
expect(product.offers.price).toBe('29');
|
|
116
|
+
expect(product.offers.priceCurrency).toBe('USD');
|
|
117
|
+
expect(product.offers.availability).toBe('https://schema.org/InStock');
|
|
118
|
+
});
|
|
119
|
+
it('generates llms.txt standard markdown manifest for AI search engines', async () => {
|
|
120
|
+
const text = generateLlmsTxt({
|
|
121
|
+
config,
|
|
122
|
+
sections: [
|
|
123
|
+
{
|
|
124
|
+
title: 'Documentation',
|
|
125
|
+
description: 'Core concepts and guides',
|
|
126
|
+
links: [{ title: 'Overview', url: '/docs/intro', description: 'Getting started guide' }]
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
});
|
|
130
|
+
expect(text).toContain('# Acme — Built for Speed');
|
|
131
|
+
expect(text).toContain('> A pure static SvelteKit site using @sveltejs/adapter-static');
|
|
132
|
+
expect(text).toContain('## Documentation');
|
|
133
|
+
expect(text).toContain('- [Overview](https://acme.example.com/docs/intro): Getting started guide');
|
|
134
|
+
});
|
|
135
|
+
it('generates agent skill markdown and serves via createSkillHandler', async () => {
|
|
136
|
+
const skillMd = generateSkillMd({
|
|
137
|
+
config,
|
|
138
|
+
actions: [
|
|
139
|
+
{
|
|
140
|
+
name: 'searchDocs',
|
|
141
|
+
description: 'Search static documentation articles',
|
|
142
|
+
endpoint: '/api/docs/search'
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
customRules: ['Always prefer Tailwind v4 utility tokens over arbitrary hex codes.']
|
|
146
|
+
});
|
|
147
|
+
expect(skillMd).toContain('# Acme — Built for Speed Agent Skill');
|
|
148
|
+
expect(skillMd).toContain('Svelte 5 & SvelteKit Strict Rules');
|
|
149
|
+
expect(skillMd).toContain('Yaxa UI & Tailwind v4 Reference');
|
|
150
|
+
expect(skillMd).toContain('`searchDocs`');
|
|
151
|
+
expect(skillMd).toContain('/api/docs/search');
|
|
152
|
+
expect(skillMd).toContain('Always prefer Tailwind v4 utility tokens');
|
|
153
|
+
const handler = createSkillHandler({ config });
|
|
154
|
+
const res = (await handler({}));
|
|
155
|
+
expect(res.headers.get('Content-Type')).toContain('text/markdown');
|
|
156
|
+
expect(await res.text()).toContain('Svelte 5 & SvelteKit Strict Rules');
|
|
157
|
+
});
|
|
158
|
+
it('all-in-one createYaxaHook routes all SEO endpoints without route files', async () => {
|
|
159
|
+
const hook = createYaxaHook(config);
|
|
160
|
+
const resolve = vi.fn().mockResolvedValue(new Response('next-handler'));
|
|
161
|
+
// Test /robots.txt
|
|
162
|
+
const robotsEvent = {
|
|
163
|
+
url: new URL('https://acme.example.com/robots.txt')
|
|
164
|
+
};
|
|
165
|
+
const robotsRes = await hook({ event: robotsEvent, resolve });
|
|
166
|
+
expect(await robotsRes.text()).toContain('User-agent: *');
|
|
167
|
+
// Test /sitemap.xml
|
|
168
|
+
const sitemapEvent = {
|
|
169
|
+
url: new URL('https://acme.example.com/sitemap.xml')
|
|
170
|
+
};
|
|
171
|
+
const sitemapRes = await hook({ event: sitemapEvent, resolve });
|
|
172
|
+
expect(await sitemapRes.text()).toContain('<urlset');
|
|
173
|
+
// Test /llms.txt
|
|
174
|
+
const llmsEvent = {
|
|
175
|
+
url: new URL('https://acme.example.com/llms.txt')
|
|
176
|
+
};
|
|
177
|
+
const llmsRes = await hook({ event: llmsEvent, resolve });
|
|
178
|
+
expect(await llmsRes.text()).toContain('# Acme — Built for Speed');
|
|
179
|
+
// Test /skill.md
|
|
180
|
+
const skillEvent = {
|
|
181
|
+
url: new URL('https://acme.example.com/skill.md')
|
|
182
|
+
};
|
|
183
|
+
const skillRes = await hook({ event: skillEvent, resolve });
|
|
184
|
+
expect(await skillRes.text()).toContain('Svelte 5 & SvelteKit Strict Rules');
|
|
185
|
+
// Test non-SEO route falls through to resolve
|
|
186
|
+
const pageEvent = {
|
|
187
|
+
url: new URL('https://acme.example.com/some-page')
|
|
188
|
+
};
|
|
189
|
+
const pageRes = await hook({ event: pageEvent, resolve });
|
|
190
|
+
expect(await pageRes.text()).toBe('next-handler');
|
|
191
|
+
expect(resolve).toHaveBeenCalled();
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { RequestHandler } from '@sveltejs/kit';
|
|
2
|
+
import type { SiteConfig } from './config.js';
|
|
3
|
+
export interface SkillAction {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
parameters?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export interface SkillOptions {
|
|
10
|
+
config: SiteConfig;
|
|
11
|
+
title?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
actions?: SkillAction[];
|
|
14
|
+
customRules?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generates machine-readable Agent Skill markdown (SKILL.md / .cursorrules).
|
|
18
|
+
* Teaches AI coding assistants (Cursor, Antigravity, Claude Code, Copilot) how to write
|
|
19
|
+
* pure Svelte 5 runes and correctly use Yaxa UI components and endpoints.
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateSkillMd(optionsOrConfig: SiteConfig | SkillOptions): string;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a SvelteKit RequestHandler serving /skill.md or /.well-known/skill.md.
|
|
24
|
+
* Compatible with pure static site generation (@sveltejs/adapter-static) via `export const prerender = true`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createSkillHandler(optionsOrConfig: SiteConfig | SkillOptions): RequestHandler;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates machine-readable Agent Skill markdown (SKILL.md / .cursorrules).
|
|
3
|
+
* Teaches AI coding assistants (Cursor, Antigravity, Claude Code, Copilot) how to write
|
|
4
|
+
* pure Svelte 5 runes and correctly use Yaxa UI components and endpoints.
|
|
5
|
+
*/
|
|
6
|
+
export function generateSkillMd(optionsOrConfig) {
|
|
7
|
+
const options = 'config' in optionsOrConfig ? optionsOrConfig : { config: optionsOrConfig };
|
|
8
|
+
const { config, title, description, actions = [], customRules = [] } = options;
|
|
9
|
+
const skillTitle = title || `${config.title || config.name} Agent Skill`;
|
|
10
|
+
const skillDesc = description ||
|
|
11
|
+
config.description ||
|
|
12
|
+
'Standard guidelines and specifications for AI coding assistants working in this codebase.';
|
|
13
|
+
let md = `# ${skillTitle}\n\n`;
|
|
14
|
+
md += `> ${skillDesc}\n\n`;
|
|
15
|
+
md += `## ⚡ Svelte 5 & SvelteKit Strict Rules\n\n`;
|
|
16
|
+
md += `When writing code for this project, AI agents MUST follow these standards:\n\n`;
|
|
17
|
+
md += `1. **Pure Runes Reactivity**: Use \`$state\`, \`$derived\`, \`$props\`, \`$bindable\`, and \`$effect\` exclusively.\n`;
|
|
18
|
+
md += ` - NEVER use legacy Svelte 3/4 stores (\`writable\`, \`readable\`, \`$store\`).\n`;
|
|
19
|
+
md += ` - NEVER use \`export let prop\`; use \`let { prop = defaultValue }: Props = $props();\` instead.\n`;
|
|
20
|
+
md += `2. **Snippets over Slots**: Use \`{#snippet mySlot()}\` and \`{@render mySlot()}\` instead of \`<slot />\`.\n`;
|
|
21
|
+
md += `3. **Event Handlers**: Use \`onclick={...}\`, \`onsubmit={...}\` rather than legacy \`on:click\` or \`on:submit\`.\n`;
|
|
22
|
+
md += `4. **Type-Safe RPC & Queries**: Use \`createQuery\` and \`createMutation\` from \`yaxa-svelte\` for client caching.\n`;
|
|
23
|
+
md += `5. **SEO & Page Meta**: Use \`useSeo(() => ({ title: '...', description: '...' }))\` from \`yaxa-svelte/seo\`.\n\n`;
|
|
24
|
+
md += `## 🧩 Yaxa UI & Tailwind v4 Reference\n\n`;
|
|
25
|
+
md += `- **Styling Engine**: Tailwind CSS v4 native tokens (\`@theme\`, harmonic radius \`--radius-*\`, series palette \`--color-chart-*\`).\n`;
|
|
26
|
+
md += `- **Core Components**: \`Button\`, \`Badge\`, \`Input\`, \`DataTable\`, \`Modal\`, \`Drawer\`, \`Tabs\`, \`MetricCard\`, \`Skeleton\`.\n`;
|
|
27
|
+
md += `- **Feedback**: Use \`const toast = useToast()\` with \`toast.success(title, message)\`.\n`;
|
|
28
|
+
md += `- **Gating**: Use \`<Gate requiredPlan="pro">\` or \`const gate = useGate()\` for SaaS feature gating.\n\n`;
|
|
29
|
+
if (actions.length > 0) {
|
|
30
|
+
md += `## 🛠️ Project APIs & Action Capabilities\n\n`;
|
|
31
|
+
for (const action of actions) {
|
|
32
|
+
md += `### \`${action.name}\`\n`;
|
|
33
|
+
md += `${action.description}\n\n`;
|
|
34
|
+
if (action.endpoint) {
|
|
35
|
+
md += `- **Endpoint**: \`${action.endpoint}\`\n`;
|
|
36
|
+
}
|
|
37
|
+
if (action.parameters) {
|
|
38
|
+
md += `- **Parameters**:\n`;
|
|
39
|
+
for (const [key, val] of Object.entries(action.parameters)) {
|
|
40
|
+
md += ` - \`${key}\`: ${val}\n`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
md += '\n';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (customRules.length > 0) {
|
|
47
|
+
md += `## 📌 Custom Project Rules\n\n`;
|
|
48
|
+
for (const rule of customRules) {
|
|
49
|
+
md += `- ${rule}\n`;
|
|
50
|
+
}
|
|
51
|
+
md += '\n';
|
|
52
|
+
}
|
|
53
|
+
return md.trimEnd() + '\n';
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates a SvelteKit RequestHandler serving /skill.md or /.well-known/skill.md.
|
|
57
|
+
* Compatible with pure static site generation (@sveltejs/adapter-static) via `export const prerender = true`.
|
|
58
|
+
*/
|
|
59
|
+
export function createSkillHandler(optionsOrConfig) {
|
|
60
|
+
return async () => {
|
|
61
|
+
const body = generateSkillMd(optionsOrConfig);
|
|
62
|
+
return new Response(body, {
|
|
63
|
+
headers: {
|
|
64
|
+
'Content-Type': 'text/markdown; charset=utf-8',
|
|
65
|
+
'Cache-Control': 'public, max-age=86400'
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PageSeoConfig } from './seo-helpers.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reactive Svelte 5 composable for page-level SEO metadata.
|
|
4
|
+
* Equivalent to Nuxt SEO's useSeoMeta().
|
|
5
|
+
*
|
|
6
|
+
* Can be called with a static config or a reactive getter function.
|
|
7
|
+
* Automatically synchronizes with <Seo /> via Svelte context.
|
|
8
|
+
*
|
|
9
|
+
* Example:
|
|
10
|
+
* ```svelte
|
|
11
|
+
* <script lang="ts">
|
|
12
|
+
* import { useSeo } from 'yaxa-svelte/seo';
|
|
13
|
+
*
|
|
14
|
+
* let product = $state({ title: 'Pro Plan', price: 49 });
|
|
15
|
+
*
|
|
16
|
+
* useSeo(() => ({
|
|
17
|
+
* title: product.title,
|
|
18
|
+
* description: `Subscribe for $${product.price}/mo`
|
|
19
|
+
* }));
|
|
20
|
+
* </script>
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function useSeo(getterOrConfig: PageSeoConfig | (() => PageSeoConfig)): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useYaxa } from './context.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reactive Svelte 5 composable for page-level SEO metadata.
|
|
4
|
+
* Equivalent to Nuxt SEO's useSeoMeta().
|
|
5
|
+
*
|
|
6
|
+
* Can be called with a static config or a reactive getter function.
|
|
7
|
+
* Automatically synchronizes with <Seo /> via Svelte context.
|
|
8
|
+
*
|
|
9
|
+
* Example:
|
|
10
|
+
* ```svelte
|
|
11
|
+
* <script lang="ts">
|
|
12
|
+
* import { useSeo } from 'yaxa-svelte/seo';
|
|
13
|
+
*
|
|
14
|
+
* let product = $state({ title: 'Pro Plan', price: 49 });
|
|
15
|
+
*
|
|
16
|
+
* useSeo(() => ({
|
|
17
|
+
* title: product.title,
|
|
18
|
+
* description: `Subscribe for $${product.price}/mo`
|
|
19
|
+
* }));
|
|
20
|
+
* </script>
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function useSeo(getterOrConfig) {
|
|
24
|
+
const yaxa = useYaxa();
|
|
25
|
+
// Immediate evaluation for SSR and initial render
|
|
26
|
+
const initial = typeof getterOrConfig === 'function' ? getterOrConfig() : getterOrConfig;
|
|
27
|
+
yaxa.setPageSeo(initial);
|
|
28
|
+
try {
|
|
29
|
+
$effect(() => {
|
|
30
|
+
const current = typeof getterOrConfig === 'function' ? getterOrConfig() : getterOrConfig;
|
|
31
|
+
yaxa.setPageSeo(current);
|
|
32
|
+
return () => {
|
|
33
|
+
yaxa.setPageSeo(null);
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Outside active effect root (e.g. non-browser testing or direct execution)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { YaxaState, useYaxa } from './context.js';
|
|
3
|
+
import { useSeo } from './useSeo.svelte.js';
|
|
4
|
+
describe('useSeo Composable & YaxaState SEO Reactivity', () => {
|
|
5
|
+
it('manages pageSeo on YaxaState directly', () => {
|
|
6
|
+
const state = new YaxaState();
|
|
7
|
+
expect(state.pageSeo).toBeNull();
|
|
8
|
+
state.setPageSeo({
|
|
9
|
+
title: 'Direct SEO Title',
|
|
10
|
+
description: 'Direct SEO Description'
|
|
11
|
+
});
|
|
12
|
+
expect(state.pageSeo?.title).toBe('Direct SEO Title');
|
|
13
|
+
expect(state.pageSeo?.description).toBe('Direct SEO Description');
|
|
14
|
+
state.setPageSeo(null);
|
|
15
|
+
expect(state.pageSeo).toBeNull();
|
|
16
|
+
});
|
|
17
|
+
it('useSeo composable sets pageSeo on fallback YaxaState when called outside provider tree', () => {
|
|
18
|
+
useSeo({
|
|
19
|
+
title: 'Pricing & Plans',
|
|
20
|
+
description: 'Affordable subscriptions for solo devs'
|
|
21
|
+
});
|
|
22
|
+
const yaxa = useYaxa();
|
|
23
|
+
// Outside provider tree, useYaxa() returns a fallback instance
|
|
24
|
+
expect(yaxa).toBeDefined();
|
|
25
|
+
expect(typeof useSeo).toBe('function');
|
|
26
|
+
});
|
|
27
|
+
it('supports reactive getter signature', () => {
|
|
28
|
+
const currentPlan = 'Enterprise Plan';
|
|
29
|
+
useSeo(() => ({
|
|
30
|
+
title: currentPlan,
|
|
31
|
+
description: `Details about ${currentPlan}`
|
|
32
|
+
}));
|
|
33
|
+
expect(typeof useSeo).toBe('function');
|
|
34
|
+
});
|
|
35
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yaxa-svelte",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "The Intuitive Svelte UI Library — Nuxt UI v4 equivalent for SvelteKit 2 & 3 & Svelte 5 with automated SEO, dynamic OpenGraph cards, sitemaps, robots.txt, and Tailwind CSS v4.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://yaxa.vercel.app",
|
|
@@ -44,6 +44,10 @@
|
|
|
44
44
|
"svelte": "./dist/index.js",
|
|
45
45
|
"default": "./dist/index.js"
|
|
46
46
|
},
|
|
47
|
+
"./seo": {
|
|
48
|
+
"types": "./dist/site/index.d.ts",
|
|
49
|
+
"default": "./dist/site/index.js"
|
|
50
|
+
},
|
|
47
51
|
"./admin": {
|
|
48
52
|
"types": "./dist/admin/index.d.ts",
|
|
49
53
|
"svelte": "./dist/admin/index.js",
|