cayo 1.1.2 → 1.2.1
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/dist/cayo.svelte.js +8 -4
- package/lib/core/bundle.js +8 -4
- package/lib/core/codegen.js +2 -1
- package/lib/core/render/prerender.js +45 -24
- package/lib/core/render/renderer.js +3 -3
- package/package.json +3 -2
- package/src/cayo.svelte +5 -4
package/dist/cayo.svelte.js
CHANGED
|
@@ -57,13 +57,16 @@ const Cayo = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
|
57
57
|
|
|
58
58
|
return value;
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
|
|
61
|
+
// const props = toSource({...$$restProps})
|
|
62
|
+
const props = JSON.stringify({ ...$$restProps }, replacer);
|
|
63
|
+
|
|
61
64
|
const warnings = getWarnings(src, badProps);
|
|
62
65
|
|
|
63
66
|
const cayoInstanceData = {
|
|
64
|
-
'data-cayo-id': '',
|
|
65
67
|
'data-cayo-src': !warnings.invalidSrc ? `${src}` : '',
|
|
66
|
-
'data-cayo-
|
|
68
|
+
'data-cayo-id': '', // will get set during prerender process based on the src
|
|
69
|
+
|
|
67
70
|
};
|
|
68
71
|
|
|
69
72
|
if (warnings) {
|
|
@@ -72,7 +75,8 @@ const Cayo = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
|
72
75
|
|
|
73
76
|
if ($$props.src === void 0 && $$bindings.src && src !== void 0) $$bindings.src(src);
|
|
74
77
|
|
|
75
|
-
return `<div${add_attribute("data-cayo-id", cayoInstanceData['data-cayo-id'], 0)}${add_attribute("data-cayo-src", cayoInstanceData['data-cayo-src'], 0)}${add_attribute("data-cayo-
|
|
78
|
+
return `<div${add_attribute("data-cayo-id", cayoInstanceData['data-cayo-id'], 0)}${add_attribute("data-cayo-src", cayoInstanceData['data-cayo-src'], 0)}${add_attribute("data-cayo-warn", cayoInstanceData['data-cayo-warn'], 0)}>
|
|
79
|
+
${`<script data-cayo-props type="application/json">${props}</script>`}
|
|
76
80
|
${slots.default ? slots.default({}) : ``}
|
|
77
81
|
</div>`;
|
|
78
82
|
});
|
package/lib/core/bundle.js
CHANGED
|
@@ -70,10 +70,15 @@ export async function getDeps(input, config) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export async function build(input, config, type = 'page') {
|
|
73
|
-
const
|
|
73
|
+
const template = (type === 'page' || type === 'template');
|
|
74
74
|
const requiredCompilerOptions = {
|
|
75
|
-
generate:
|
|
76
|
-
hydratable:
|
|
75
|
+
generate: template ? 'ssr' : 'dom',
|
|
76
|
+
hydratable: template ? false : true,
|
|
77
|
+
preserveComments: template
|
|
78
|
+
? false
|
|
79
|
+
: config.svelte.compilerOptions.preserveComments
|
|
80
|
+
? config.svelte.compilerOptions.preserveComments
|
|
81
|
+
: true,
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
let bundle;
|
|
@@ -95,7 +100,6 @@ export async function build(input, config, type = 'page') {
|
|
|
95
100
|
...preprocessors,
|
|
96
101
|
],
|
|
97
102
|
compilerOptions: {
|
|
98
|
-
preserveComments: true,
|
|
99
103
|
preserveWhitespace: true,
|
|
100
104
|
...config.svelte.compilerOptions,
|
|
101
105
|
...requiredCompilerOptions,
|
package/lib/core/codegen.js
CHANGED
|
@@ -6,7 +6,8 @@ export function generateGetProps() {
|
|
|
6
6
|
return (
|
|
7
7
|
`
|
|
8
8
|
function getProps(cayoElement) {
|
|
9
|
-
const json = cayoElement.
|
|
9
|
+
const json = cayoElement.querySelector('[data-cayo-props]').innerHTML;
|
|
10
|
+
console.log('json', json);
|
|
10
11
|
return JSON.parse(json);
|
|
11
12
|
}
|
|
12
13
|
`
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { JSDOM } from 'jsdom';
|
|
4
|
+
import chalk from 'chalk';
|
|
4
5
|
import { Renderer } from './renderer.js';
|
|
5
6
|
import { compileCayos } from '../compile/cayos.js';
|
|
6
7
|
import { generateCayoRuntime, generateRuntimeIssuesScript } from '../codegen.js';
|
|
@@ -56,10 +57,11 @@ export async function processPage(content, page, _cayo, logger) {
|
|
|
56
57
|
for (const el of document.querySelectorAll('[data-cayo-src]')) {
|
|
57
58
|
let src = el.dataset.cayoSrc;
|
|
58
59
|
if (src !== '') {
|
|
60
|
+
// Generate an ID for the Cayo
|
|
59
61
|
const { id, name } = generateCayoComponentId(src);
|
|
60
62
|
cayoIds.push(id);
|
|
61
63
|
el.dataset.cayoId = id;
|
|
62
|
-
|
|
64
|
+
|
|
63
65
|
// Get warnings added by the Cayo component during compile time
|
|
64
66
|
if (el.dataset.cayoWarn && el.dataset.cayoWarn !== '{}') {
|
|
65
67
|
warnings.cayos[id] = JSON.parse(el.dataset.cayoWarn);
|
|
@@ -116,7 +118,16 @@ export async function processPage(content, page, _cayo, logger) {
|
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
120
|
const cayoAssetsCssMarker = document.querySelector('link[data-cayo-assets-css]');
|
|
119
|
-
cayoAssetsCssMarker.outerHTML
|
|
121
|
+
if (cayoAssetsCssMarker && cayoAssetsCssMarker.outerHTML) {
|
|
122
|
+
cayoAssetsCssMarker.outerHTML = cayoAssetCssElements;
|
|
123
|
+
} else {
|
|
124
|
+
if (cayoAssetCssElements) {
|
|
125
|
+
logger.log.info(
|
|
126
|
+
chalk.yellow.bold('Warning') + chalk.yellow(': No %cayo.css% found in template, but there is CSS used in source files.'),
|
|
127
|
+
{ timestamp: true, clear: false, }
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
120
131
|
|
|
121
132
|
// Get user-specified entry placeholder
|
|
122
133
|
const entryScriptPlaceholder = document.querySelector('script[data-cayo-entry]');
|
|
@@ -138,7 +149,7 @@ export async function processPage(content, page, _cayo, logger) {
|
|
|
138
149
|
log: `Entry file '${entryScriptSrc}' does not exist.`,
|
|
139
150
|
}
|
|
140
151
|
// Remove the entry file script because the file doesn't exist
|
|
141
|
-
entryScript
|
|
152
|
+
entryScript?.remove();
|
|
142
153
|
} else {
|
|
143
154
|
entry.path = absoluteEntrySrcPath;
|
|
144
155
|
_cayo.stats.dependencies.pages[page.sourcePath].add(absoluteEntrySrcPath);
|
|
@@ -154,7 +165,7 @@ export async function processPage(content, page, _cayo, logger) {
|
|
|
154
165
|
}
|
|
155
166
|
} else {
|
|
156
167
|
// Remove the entry point script tag because the page doesn't need any JS
|
|
157
|
-
entryScript
|
|
168
|
+
entryScript?.remove();
|
|
158
169
|
}
|
|
159
170
|
}
|
|
160
171
|
|
|
@@ -199,22 +210,32 @@ export async function processPage(content, page, _cayo, logger) {
|
|
|
199
210
|
let processedHTML = '';
|
|
200
211
|
if (tags.doctype) {
|
|
201
212
|
processedHTML += tags.doctype;
|
|
202
|
-
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
let html; // html element parts (open/close tag, inner)
|
|
216
|
+
let head;
|
|
203
217
|
if (tags.html) {
|
|
204
|
-
|
|
218
|
+
({groups: html} = document.documentElement.outerHTML
|
|
219
|
+
.match(/(?<open><html[\s\S]*?>)(?<innerHTML>[\s\S]*)(?<close><\/html>)/)
|
|
220
|
+
)
|
|
221
|
+
processedHTML += html.open;
|
|
222
|
+
}
|
|
223
|
+
if (tags.head) {
|
|
224
|
+
({groups: head} = document.head.outerHTML
|
|
225
|
+
.match(/(?<open><head[\s\S]*?>)(?<innerHTML>[\s\S]*)(?<close><\/head>)/)
|
|
226
|
+
)
|
|
227
|
+
processedHTML += document.head.outerHTML;
|
|
205
228
|
} else {
|
|
206
|
-
|
|
207
|
-
processedHTML += document.head.outerHTML;
|
|
208
|
-
} else {
|
|
209
|
-
processedHTML += document.head.innerHTML;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (tags.body) {
|
|
213
|
-
processedHTML += document.body.outerHTML;
|
|
214
|
-
} else {
|
|
215
|
-
processedHTML += document.body.innerHTML;
|
|
216
|
-
}
|
|
229
|
+
processedHTML += document.head.innerHTML;
|
|
217
230
|
}
|
|
231
|
+
if (tags.body) {
|
|
232
|
+
processedHTML += document.body.outerHTML;
|
|
233
|
+
} else {
|
|
234
|
+
processedHTML += document.body.innerHTML;
|
|
235
|
+
}
|
|
236
|
+
if (tags.html) {
|
|
237
|
+
processedHTML += html.close;
|
|
238
|
+
}
|
|
218
239
|
|
|
219
240
|
return {
|
|
220
241
|
html: processedHTML,
|
|
@@ -227,14 +248,14 @@ export async function processPage(content, page, _cayo, logger) {
|
|
|
227
248
|
}
|
|
228
249
|
|
|
229
250
|
function tagsExist(source) {
|
|
230
|
-
const doctype = source.match(
|
|
231
|
-
const head = source.match(
|
|
232
|
-
const body = source.match(
|
|
233
|
-
const html = source.match(
|
|
251
|
+
const doctype = source.match(/<!DOCTYPE[\s\S]*>/);
|
|
252
|
+
const head = source.match(/<head[\s\S]*>(?<innerHTML>[\s\S]*)<\/head>/);
|
|
253
|
+
const body = source.match(/<body[\s\S]*>(?<innerHTML>[\s\S]*)<\/body>/);
|
|
254
|
+
const html = source.match(/<html[\s\S]*>(?<innerHTML>[\s\S]*)<\/html>/);
|
|
234
255
|
return {
|
|
235
256
|
doctype: doctype === null ? false : doctype,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
257
|
+
html: html === null ? false : html.groups,
|
|
258
|
+
head: head === null ? false : head.groups,
|
|
259
|
+
body: body === null ? false : body.groups,
|
|
239
260
|
};
|
|
240
261
|
}
|
|
@@ -37,9 +37,9 @@ export class Renderer {
|
|
|
37
37
|
// https://stackoverflow.com/questions/9423722/string-replace-weird-behavior-when-using-dollar-sign-as-replacement
|
|
38
38
|
return {
|
|
39
39
|
html: this.template.html
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
// Strip placeholders wrapped in HTML comments
|
|
41
|
+
.replace(/<!--[\s\S]?%cayo\.\w+%[\s\S]*?(-->)/g, '')
|
|
42
|
+
// Inject markup in the cayo placeholders
|
|
43
43
|
.replace('%cayo.title%', () => !head.includes('<title>') ? title() : '')
|
|
44
44
|
.replace('%cayo.head%', () => head)
|
|
45
45
|
.replace('%cayo.body%', () => html)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cayo",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "node cayo dev --projectRoot test",
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"rollup-plugin-import-css": "^3.0.3",
|
|
44
44
|
"rollup-plugin-svelte": "^7.1.0",
|
|
45
45
|
"svelte": "^3.49.0",
|
|
46
|
-
"
|
|
46
|
+
"tosource": "^2.0.0-alpha.3",
|
|
47
|
+
"vite": "^4.3.9",
|
|
47
48
|
"yargs-parser": "^20.2.9",
|
|
48
49
|
"zod": "^3.10.3"
|
|
49
50
|
}
|
package/src/cayo.svelte
CHANGED
|
@@ -18,23 +18,24 @@
|
|
|
18
18
|
return value;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
// const props = toSource({...$$restProps})
|
|
22
|
+
const props = JSON.stringify({...$$restProps}, replacer);
|
|
22
23
|
const warnings = getWarnings(src, badProps);
|
|
23
24
|
const cayoInstanceData = {
|
|
24
|
-
'data-cayo-id': '',
|
|
25
25
|
'data-cayo-src': !warnings.invalidSrc ? `${src}` : '',
|
|
26
|
-
'data-cayo-
|
|
26
|
+
'data-cayo-id': '', // will get set during prerender process based on the src
|
|
27
27
|
};
|
|
28
28
|
if (warnings) {
|
|
29
29
|
cayoInstanceData['data-cayo-warn'] = JSON.stringify(warnings);
|
|
30
30
|
}
|
|
31
31
|
</script>
|
|
32
|
+
|
|
32
33
|
<div
|
|
33
34
|
data-cayo-id={cayoInstanceData['data-cayo-id']}
|
|
34
35
|
data-cayo-src={cayoInstanceData['data-cayo-src']}
|
|
35
|
-
data-cayo-props={cayoInstanceData['data-cayo-props']}
|
|
36
36
|
data-cayo-warn={cayoInstanceData['data-cayo-warn']}
|
|
37
37
|
>
|
|
38
|
+
{@html `<script data-cayo-props type="application/json">${props}</script>`}
|
|
38
39
|
<slot/>
|
|
39
40
|
</div>
|
|
40
41
|
|