cayo 1.5.1 → 1.5.3

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.
@@ -0,0 +1,41 @@
1
+ import { SvelteComponentTyped } from 'svelte';
2
+
3
+ export interface CayoProps {
4
+ /**
5
+ * Component object with __cayoPath property or string path
6
+ */
7
+ component?: object | string;
8
+
9
+ /**
10
+ * HTML attributes to spread on the wrapper div
11
+ */
12
+ attributes?: Record<string, any>;
13
+
14
+ /**
15
+ * Traditional string path to the component file
16
+ * @deprecated Use `component` prop instead for better type safety and preprocessor support
17
+ */
18
+ src?: string;
19
+ }
20
+
21
+ /**
22
+ * Cayo component wrapper that handles hydration and renders components.
23
+ *
24
+ * Accepts a component via the `component` prop and passes additional props
25
+ * to the child component via `$$restProps`.
26
+ *
27
+ * @example
28
+ * ```svelte
29
+ * <script>
30
+ * import { Cayo } from 'cayo';
31
+ * import Counter from './components/counter.cayo.svelte';
32
+ * </script>
33
+ *
34
+ * <Cayo
35
+ * component={Counter}
36
+ * count={0}
37
+ * attributes={{ class: "counter-wrapper" }}
38
+ * />
39
+ * ```
40
+ */
41
+ export default class Cayo extends SvelteComponentTyped<CayoProps & Record<string, any>> {}
@@ -0,0 +1,22 @@
1
+ import { SvelteComponentTyped } from 'svelte';
2
+
3
+ export interface EntryProps {
4
+ /**
5
+ * Path to the entry script file (defaults to "entry.js")
6
+ */
7
+ src?: string;
8
+ }
9
+
10
+ /**
11
+ * Entry component that injects the hydration entry point script.
12
+ *
13
+ * @example
14
+ * ```svelte
15
+ * <script>
16
+ * import { Entry } from 'cayo';
17
+ * </script>
18
+ *
19
+ * <Entry src="custom.js" />
20
+ * ```
21
+ */
22
+ export default class Entry extends SvelteComponentTyped<EntryProps> {}
@@ -0,0 +1,3 @@
1
+ export { default as Cayo } from './cayo.svelte';
2
+ export { default as Entry } from './entry.svelte';
3
+ export { cayoPreprocess } from './preprocessors/index';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { default as Cayo } from './cayo.svelte.js';
2
2
  export { default as Entry } from './entry.svelte.js';
3
- export { cayoPreprocess } from '../lib/preprocessors/index.js';
3
+ export { cayoPreprocess } from './preprocessors/index.js';
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Svelte preprocessor that transforms Cayo component imports
3
+ * from object references to string paths
4
+ */
5
+ export function cayoComponentPreprocessor() {
6
+ return {
7
+ script({ content, attributes }) {
8
+ // Only process if the script contains .cayo.svelte imports
9
+ if (!content.includes('.cayo.svelte')) return;
10
+
11
+ // Transform: import Component from '$components/Component.cayo.svelte' or './components/Component.cayo.svelte'
12
+ // Into: import Component from '...'; Component.__cayoPath = 'Component.cayo.svelte';
13
+ const transformedContent = content.replace(
14
+ /import\s+(\w+)\s+from\s+['"]([^'"]*\/)?([^\/'"]+\.cayo\.svelte)['"]\s*;/g,
15
+ (match, varName, pathPrefix, filename) => {
16
+ return `${match}\n if (${varName}) ${varName}.__cayoPath = '${filename}';`;
17
+ }
18
+ );
19
+
20
+ return transformedContent !== content ? { code: transformedContent } : null;
21
+ }
22
+ };
23
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Svelte preprocessor that transforms .cayo.svelte imports
3
+ * Adds __cayoPath property to imported components for runtime path resolution
4
+ *
5
+ * @example
6
+ * ```javascript
7
+ * // svelte.config.js
8
+ * import { cayoPreprocess } from 'cayo';
9
+ *
10
+ * export default {
11
+ * preprocess: cayoPreprocess()
12
+ * };
13
+ * ```
14
+ */
15
+ export function cayoPreprocess(): {
16
+ markup: (options: { content: string; filename: string }) => { code: string };
17
+ };
@@ -0,0 +1,10 @@
1
+ import { cayoComponentPreprocessor } from './cayo-component.js';
2
+
3
+ /**
4
+ * Cayo preprocessor for Svelte
5
+ * Currently includes component import transformation
6
+ * Future preprocessors and config options can be added here
7
+ */
8
+ export function cayoPreprocess(options = {}) {
9
+ return cayoComponentPreprocessor();
10
+ }
@@ -28,6 +28,7 @@ function resolvePluginDefaults(overrides = {}) {
28
28
 
29
29
  function sveltePluginDefaults() {
30
30
  return {
31
+ emitCss: false, // Bundle CSS into JS instead of separate file
31
32
  onwarn: (warning, handler) => {
32
33
  // console.log('Svelte processing:', warning.filename);
33
34
  // console.log('Svelte warning:', warning.message);
@@ -31,7 +31,9 @@ export class Renderer {
31
31
 
32
32
  const title = () => {
33
33
  let title = page.name;
34
- title = title.charAt(0).toUpperCase() + title.substring(1);
34
+ if (page.name !== page.url && page.url !== '/') {
35
+ title += ` • ${page.url}`;
36
+ }
35
37
  return `<title>${title}</title>`
36
38
  }
37
39
 
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "cayo",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "type": "module",
5
+ "types": "./dist/index.d.ts",
5
6
  "scripts": {
6
7
  "start": "node cayo dev --projectRoot test",
7
8
  "build": "node scripts/build"
@@ -15,6 +16,7 @@
15
16
  "svelte": "./dist/index.js",
16
17
  "exports": {
17
18
  ".": {
19
+ "types": "./dist/index.d.ts",
18
20
  "default": "./dist/index.js"
19
21
  },
20
22
  "./package.json": "./package.json"
package/scripts/build.js CHANGED
@@ -23,6 +23,14 @@ async function compileComponents(components, config) {
23
23
  output[component] = { path: `./${component}.svelte.js` }
24
24
  console.log(chalk.green.bold(`Compiled ${component}.svelte → ${component}.svelte.js`));
25
25
  console.log(chalk.dim(`./dist/${component}.svelte.js`));
26
+
27
+ // Copy type definition file
28
+ const typeDefPath = path.resolve(`./src/${component}.svelte.d.ts`);
29
+ const typeDefOutputPath = path.resolve(`./dist/${component}.svelte.d.ts`);
30
+ if (await fs.pathExists(typeDefPath)) {
31
+ await fs.copy(typeDefPath, typeDefOutputPath);
32
+ console.log(chalk.cyan(`Copied ${component}.svelte.d.ts`));
33
+ }
26
34
  } catch (err) {
27
35
  throw new Error(`Cayo Internal Error: Could not compile ./src/${component}.svelte`, { cause: err });
28
36
  }
@@ -37,10 +45,20 @@ function generateIndex(modules) {
37
45
  js += `export { default as ${m[0]} } from '${m[1]}';\n`;
38
46
  }
39
47
  // Add preprocessor exports
40
- js += `export { cayoPreprocess } from '../lib/preprocessors/index.js';\n`;
48
+ js += `export { cayoPreprocess } from './preprocessors/index.js';\n`;
41
49
  return { code: js };
42
50
  }
43
51
 
52
+ function generateIndexTypes(modules) {
53
+ let dts = '';
54
+ for (const m of modules) {
55
+ dts += `export { default as ${m[0]} } from '${m[1]}';\n`;
56
+ }
57
+ // Add preprocessor type exports
58
+ dts += `export { cayoPreprocess } from './preprocessors/index';\n`;
59
+ return { code: dts };
60
+ }
61
+
44
62
  try {
45
63
  const cayoConfig = await validateConfig({});
46
64
  const output = await compileComponents(['cayo', 'entry'], cayoConfig);
@@ -49,11 +67,26 @@ try {
49
67
  ['Cayo', output.cayo.path],
50
68
  ['Entry', output.entry.path],
51
69
  ]);
52
- await fs.outputFile('./dist/index.js', index.code)
53
- .then(() => {
54
- console.log(chalk.green.bold(`✅ Components built.`));
55
- console.log(chalk.dim(`./dist/index.js`));
56
- });
70
+ await fs.outputFile('./dist/index.js', index.code);
71
+
72
+ // Generate TypeScript definitions
73
+ const indexTypes = generateIndexTypes([
74
+ ['Cayo', './cayo.svelte'],
75
+ ['Entry', './entry.svelte'],
76
+ ]);
77
+ await fs.outputFile('./dist/index.d.ts', indexTypes.code);
78
+
79
+ // Copy preprocessors directory
80
+ const preprocessorsPath = path.resolve('./src/preprocessors');
81
+ const preprocessorsOutputPath = path.resolve('./dist/preprocessors');
82
+ if (await fs.pathExists(preprocessorsPath)) {
83
+ await fs.copy(preprocessorsPath, preprocessorsOutputPath);
84
+ console.log(chalk.cyan(`Copied preprocessors/`));
85
+ }
86
+
87
+ console.log(chalk.green.bold(`✅ Components built.`));
88
+ console.log(chalk.dim(`./dist/index.js`));
89
+ console.log(chalk.dim(`./dist/index.d.ts`));
57
90
 
58
91
  } catch (err) {
59
92
  logger.error(err);
@@ -0,0 +1,41 @@
1
+ import { SvelteComponentTyped } from 'svelte';
2
+
3
+ export interface CayoProps {
4
+ /**
5
+ * Component object with __cayoPath property or string path
6
+ */
7
+ component?: object | string;
8
+
9
+ /**
10
+ * HTML attributes to spread on the wrapper div
11
+ */
12
+ attributes?: Record<string, any>;
13
+
14
+ /**
15
+ * Traditional string path to the component file
16
+ * @deprecated Use `component` prop instead for better type safety and preprocessor support
17
+ */
18
+ src?: string;
19
+ }
20
+
21
+ /**
22
+ * Cayo component wrapper that handles hydration and renders components.
23
+ *
24
+ * Accepts a component via the `component` prop and passes additional props
25
+ * to the child component via `$$restProps`.
26
+ *
27
+ * @example
28
+ * ```svelte
29
+ * <script>
30
+ * import { Cayo } from 'cayo';
31
+ * import Counter from './components/counter.cayo.svelte';
32
+ * </script>
33
+ *
34
+ * <Cayo
35
+ * component={Counter}
36
+ * count={0}
37
+ * attributes={{ class: "counter-wrapper" }}
38
+ * />
39
+ * ```
40
+ */
41
+ export default class Cayo extends SvelteComponentTyped<CayoProps & Record<string, any>> {}
@@ -0,0 +1,22 @@
1
+ import { SvelteComponentTyped } from 'svelte';
2
+
3
+ export interface EntryProps {
4
+ /**
5
+ * Path to the entry script file (defaults to "entry.js")
6
+ */
7
+ src?: string;
8
+ }
9
+
10
+ /**
11
+ * Entry component that injects the hydration entry point script.
12
+ *
13
+ * @example
14
+ * ```svelte
15
+ * <script>
16
+ * import { Entry } from 'cayo';
17
+ * </script>
18
+ *
19
+ * <Entry src="custom.js" />
20
+ * ```
21
+ */
22
+ export default class Entry extends SvelteComponentTyped<EntryProps> {}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Svelte preprocessor that transforms Cayo component imports
3
+ * from object references to string paths
4
+ */
5
+ export function cayoComponentPreprocessor() {
6
+ return {
7
+ script({ content, attributes }) {
8
+ // Only process if the script contains .cayo.svelte imports
9
+ if (!content.includes('.cayo.svelte')) return;
10
+
11
+ // Transform: import Component from '$components/Component.cayo.svelte' or './components/Component.cayo.svelte'
12
+ // Into: import Component from '...'; Component.__cayoPath = 'Component.cayo.svelte';
13
+ const transformedContent = content.replace(
14
+ /import\s+(\w+)\s+from\s+['"]([^'"]*\/)?([^\/'"]+\.cayo\.svelte)['"]\s*;/g,
15
+ (match, varName, pathPrefix, filename) => {
16
+ return `${match}\n if (${varName}) ${varName}.__cayoPath = '${filename}';`;
17
+ }
18
+ );
19
+
20
+ return transformedContent !== content ? { code: transformedContent } : null;
21
+ }
22
+ };
23
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Svelte preprocessor that transforms .cayo.svelte imports
3
+ * Adds __cayoPath property to imported components for runtime path resolution
4
+ *
5
+ * @example
6
+ * ```javascript
7
+ * // svelte.config.js
8
+ * import { cayoPreprocess } from 'cayo';
9
+ *
10
+ * export default {
11
+ * preprocess: cayoPreprocess()
12
+ * };
13
+ * ```
14
+ */
15
+ export function cayoPreprocess(): {
16
+ markup: (options: { content: string; filename: string }) => { code: string };
17
+ };
@@ -0,0 +1,10 @@
1
+ import { cayoComponentPreprocessor } from './cayo-component.js';
2
+
3
+ /**
4
+ * Cayo preprocessor for Svelte
5
+ * Currently includes component import transformation
6
+ * Future preprocessors and config options can be added here
7
+ */
8
+ export function cayoPreprocess(options = {}) {
9
+ return cayoComponentPreprocessor();
10
+ }