@cloudhal/astro-renderer 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +36 -2
- package/dist/src/ambient-client.d.ts +17 -0
- package/dist/src/ambient-client.js +55 -0
- package/dist/src/analytics-client.d.ts +17 -0
- package/dist/src/analytics-client.js +96 -0
- package/dist/src/analytics-middleware.d.ts +6 -0
- package/dist/src/analytics-middleware.js +43 -0
- package/dist/src/analytics-node.d.ts +46 -0
- package/dist/src/analytics-node.js +134 -0
- package/dist/src/analytics.d.ts +117 -0
- package/dist/src/analytics.js +372 -0
- package/dist/src/archive.d.ts +106 -0
- package/dist/src/archive.js +207 -0
- package/dist/src/astro-env.d.ts +21 -0
- package/dist/src/block-html.d.ts +14 -0
- package/dist/src/block-html.js +103 -0
- package/dist/src/blocks.d.ts +24 -0
- package/dist/src/blocks.js +66 -0
- package/dist/src/cache-tags.d.ts +25 -0
- package/dist/src/cache-tags.js +59 -0
- package/dist/src/carousel-client.d.ts +28 -0
- package/dist/src/carousel-client.js +67 -0
- package/dist/src/chart.d.ts +34 -0
- package/dist/src/chart.js +182 -0
- package/dist/src/chrome-client.d.ts +27 -0
- package/dist/src/chrome-client.js +64 -0
- package/dist/src/cloudflare-entry.d.ts +87 -0
- package/dist/src/cloudflare-entry.js +548 -0
- package/dist/src/comments-client.d.ts +11 -0
- package/dist/src/comments-client.js +58 -0
- package/dist/src/comments-html.d.ts +42 -0
- package/dist/src/comments-html.js +303 -0
- package/dist/src/comments-middleware.d.ts +6 -0
- package/dist/src/comments-middleware.js +38 -0
- package/dist/src/comments-node.d.ts +42 -0
- package/dist/src/comments-node.js +112 -0
- package/dist/src/comments-view.d.ts +68 -0
- package/dist/src/comments-view.js +174 -0
- package/dist/src/comments.d.ts +66 -0
- package/dist/src/comments.js +258 -0
- package/dist/src/components/Block.astro +39 -0
- package/dist/src/components/Body.astro +43 -0
- package/dist/src/components/Comments.astro +19 -0
- package/dist/src/components/ContentList.astro +31 -0
- package/dist/src/components/EntryArticle.astro +31 -0
- package/dist/src/components/Hero.astro +36 -0
- package/dist/src/components/Image.astro +36 -0
- package/dist/src/components/RichText.astro +19 -0
- package/dist/src/components/Sections.astro +66 -0
- package/dist/src/components/SeoHead.astro +22 -0
- package/dist/src/components/Surface.astro +36 -0
- package/dist/src/components/SurfaceNode.astro +82 -0
- package/dist/src/components/index.d.ts +12 -0
- package/dist/src/components/index.js +12 -0
- package/dist/src/csp.d.ts +20 -0
- package/dist/src/csp.js +28 -0
- package/dist/src/embed-client.d.ts +38 -0
- package/dist/src/embed-client.js +98 -0
- package/dist/src/embed-middleware.d.ts +9 -0
- package/dist/src/embed-middleware.js +49 -0
- package/dist/src/feeds.d.ts +72 -0
- package/dist/src/feeds.js +246 -0
- package/dist/src/gates.d.ts +25 -0
- package/dist/src/gates.js +63 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.js +17 -0
- package/dist/src/integration.d.ts +55 -0
- package/dist/src/integration.js +244 -0
- package/dist/src/kit.d.ts +48 -0
- package/dist/src/kit.js +83 -0
- package/dist/src/locale-feeds.d.ts +29 -0
- package/dist/src/locale-feeds.js +152 -0
- package/dist/src/locale-middleware.d.ts +5 -0
- package/dist/src/locale-middleware.js +26 -0
- package/dist/src/locales.d.ts +87 -0
- package/dist/src/locales.js +336 -0
- package/dist/src/markdown.d.ts +83 -0
- package/dist/src/markdown.js +533 -0
- package/dist/src/media-middleware.d.ts +5 -0
- package/dist/src/media-middleware.js +18 -0
- package/dist/src/media-route.d.ts +47 -0
- package/dist/src/media-route.js +238 -0
- package/dist/src/media.d.ts +109 -0
- package/dist/src/media.js +298 -0
- package/dist/src/motion-client.d.ts +39 -0
- package/dist/src/motion-client.js +115 -0
- package/dist/src/navigation.d.ts +127 -0
- package/dist/src/navigation.js +382 -0
- package/dist/src/not-found.d.ts +16 -0
- package/dist/src/not-found.js +41 -0
- package/dist/src/overlay-client.d.ts +20 -0
- package/dist/src/overlay-client.js +49 -0
- package/dist/src/prefs-client.d.ts +14 -0
- package/dist/src/prefs-client.js +18 -0
- package/dist/src/preview.d.ts +70 -0
- package/dist/src/preview.js +551 -0
- package/dist/src/resolver.d.ts +71 -0
- package/dist/src/resolver.js +206 -0
- package/dist/src/routing.d.ts +108 -0
- package/dist/src/routing.js +285 -0
- package/dist/src/runtime-workerd.d.ts +87 -0
- package/dist/src/runtime-workerd.js +275 -0
- package/dist/src/runtime.d.ts +59 -0
- package/dist/src/runtime.js +153 -0
- package/dist/src/safe-urls.d.ts +13 -0
- package/dist/src/safe-urls.js +35 -0
- package/dist/src/sanitize.d.ts +7 -0
- package/dist/src/sanitize.js +217 -0
- package/dist/src/search-client.d.ts +29 -0
- package/dist/src/search-client.js +92 -0
- package/dist/src/search-limit.d.ts +36 -0
- package/dist/src/search-limit.js +66 -0
- package/dist/src/search.d.ts +64 -0
- package/dist/src/search.js +155 -0
- package/dist/src/seo.d.ts +85 -0
- package/dist/src/seo.js +468 -0
- package/dist/src/site-dispatch.d.ts +37 -0
- package/dist/src/site-dispatch.js +86 -0
- package/dist/src/site-hosts.d.ts +35 -0
- package/dist/src/site-hosts.js +110 -0
- package/dist/src/source.d.ts +227 -0
- package/dist/src/source.js +794 -0
- package/dist/src/static-gates.d.ts +3 -0
- package/dist/src/static-gates.js +28 -0
- package/dist/src/static-headers.d.ts +30 -0
- package/dist/src/static-headers.js +140 -0
- package/dist/src/static-media.d.ts +4 -0
- package/dist/src/static-media.js +65 -0
- package/dist/src/static-redirects.d.ts +4 -0
- package/dist/src/static-redirects.js +40 -0
- package/dist/src/surface-client.d.ts +34 -0
- package/dist/src/surface-client.js +146 -0
- package/dist/src/surfaces/html.d.ts +35 -0
- package/dist/src/surfaces/html.js +184 -0
- package/dist/src/surfaces/markup.d.ts +57 -0
- package/dist/src/surfaces/markup.js +135 -0
- package/dist/src/surfaces/motion.d.ts +33 -0
- package/dist/src/surfaces/motion.js +132 -0
- package/dist/src/surfaces/primitives/carousel.d.ts +2 -0
- package/dist/src/surfaces/primitives/carousel.js +95 -0
- package/dist/src/surfaces/primitives/content.d.ts +13 -0
- package/dist/src/surfaces/primitives/content.js +159 -0
- package/dist/src/surfaces/primitives/data.d.ts +5 -0
- package/dist/src/surfaces/primitives/data.js +80 -0
- package/dist/src/surfaces/primitives/index.d.ts +54 -0
- package/dist/src/surfaces/primitives/index.js +106 -0
- package/dist/src/surfaces/primitives/inputs.d.ts +8 -0
- package/dist/src/surfaces/primitives/inputs.js +68 -0
- package/dist/src/surfaces/primitives/layout.d.ts +14 -0
- package/dist/src/surfaces/primitives/layout.js +61 -0
- package/dist/src/surfaces/primitives/motion.d.ts +9 -0
- package/dist/src/surfaces/primitives/motion.js +45 -0
- package/dist/src/surfaces/primitives/overlays.d.ts +6 -0
- package/dist/src/surfaces/primitives/overlays.js +79 -0
- package/dist/src/surfaces/tree.d.ts +107 -0
- package/dist/src/surfaces/tree.js +321 -0
- package/dist/src/surfaces.d.ts +14 -0
- package/dist/src/surfaces.js +33 -0
- package/dist/src/taxonomy.d.ts +86 -0
- package/dist/src/taxonomy.js +268 -0
- package/dist/src/theme-settings.d.ts +24 -0
- package/dist/src/theme-settings.js +111 -0
- package/package.json +219 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cloudhal/astro-renderer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Renders a Cloudhal Site Graph with Astro 7. Three pieces:
|
|
4
|
+
|
|
5
|
+
| Export | What |
|
|
6
|
+
|---|---|
|
|
7
|
+
| `@cloudhal/astro-renderer/integration` | `cloudhal({ dataDir, siteId })` — exposes the project config as `virtual:cloudhal/config`, externalises the native SQLite module, and in dev watches the data directory to clear Astro's route cache when pages are added (Astro ≥6.3 caches `getStaticPaths()` across requests). |
|
|
8
|
+
| `@cloudhal/astro-renderer/runtime` | `getSource(config)` — a `GraphSource`: **live** nodes in dev (drafts visible), a **snapshot** in builds (`CLOUDHAL_SOURCE=snapshot:<id>`). |
|
|
9
|
+
| `@cloudhal/astro-renderer/components` | `Sections` dispatcher + `Hero`, `RichText`, `Image`, `ContentList` `.astro` components. Themes override any of them through the `components` prop. |
|
|
10
|
+
|
|
11
|
+
A page route in a starter looks like this:
|
|
12
|
+
|
|
13
|
+
```astro
|
|
14
|
+
---
|
|
15
|
+
import { Sections } from "@cloudhal/astro-renderer/components";
|
|
16
|
+
import { getSource } from "@cloudhal/astro-renderer/runtime";
|
|
17
|
+
import config from "virtual:cloudhal/config";
|
|
18
|
+
export async function getStaticPaths() {
|
|
19
|
+
const source = await getSource(config);
|
|
20
|
+
return (await source.pages()).map((p) => ({ params: { path: p.path === "/" ? undefined : p.path.slice(1) } }));
|
|
21
|
+
}
|
|
22
|
+
const source = await getSource(config);
|
|
23
|
+
const page = await source.pageByPath(Astro.params.path ? `/${Astro.params.path}` : "/");
|
|
24
|
+
---
|
|
25
|
+
<Sections sections={page.sections} />
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`.astro` files ship as source (no build step); the consumer's Astro compiles them. `astro` is a peer dependency.
|
|
29
|
+
|
|
30
|
+
## Site analytics (RFC-0006)
|
|
31
|
+
|
|
32
|
+
The renderer carries the site side of Cloudhal's cookie-less analytics (`@cloudhal/analytics`):
|
|
33
|
+
|
|
34
|
+
- **Scripts.** On a Site Worker build (`target: "cloudflare"`) the `cloudhal()` integration bundles `@cloudhal/analytics/client` with Astro's Vite into two hashed static assets, `/_cloudhal/p.<hash>.js` (the page-view script, ≤ 1 KB gzipped, held there by a test) and `/_cloudhal/v.<hash>.js` (vitals, `web-vitals`, loaded by one page view in N). No cookies, no storage, no identifiers, nothing third-party; the CSP stays `script-src 'self'; connect-src 'self'`.
|
|
35
|
+
- **Site Worker** (`cloudflare-entry.ts`, `analytics.ts`). `POST /__cloudhal/e` answers `204` for every outcome (`405` for other methods) and writes one event through `WaeWriter(env.ANALYTICS)`; published HTML `200`s get `<script type="module" src="/_cloudhal/p.<hash>.js" data-v="N">` in `<head>` while the site's setting is on (never previews, errors or feeds); responses the Worker renders become `render` events (published HTML `200`s, redirects, `404`, `410`, `451`, `5xx`). A purge re-reads the settings.
|
|
36
|
+
- **What the Site Worker expects** (written by `cloudhal deploy` in rollout step 9): the Analytics Engine binding `ANALYTICS` (dataset `<deployment>_events`), `CLOUDHAL_ANALYTICS = "on"`, `CLOUDHAL_ANALYTICS_DEFAULTS` (`cloudhal.json`'s `analytics` block as JSON; `enabled` defaults to `true`), migration `0014_analytics` in D1 (until it has run, analytics count as off), and optionally `CLOUDHAL_SITE_HOSTS` (extra hostnames; `Site.domains` and `*.workers.dev` request hosts are accepted already). Without the switch or the binding nothing is collected and no tag is added.
|
|
37
|
+
- **`cloudhal dev`** (`analytics-middleware.ts`, `analytics-node.ts`). The same endpoint; it records into the local SQLite store (`analytics_events`) only with `analytics.dev: true` (the integration's `analytics` option, which the blog starter passes from `cloudhal.json`, or `CLOUDHAL_ANALYTICS`, `CLOUDHAL_ANALYTICS_DEFAULTS` and `CLOUDHAL_ANALYTICS_DEV=1` in the environment), and then serves the scripts and injects the tag. Static builds carry no analytics.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudhal's ambient module (RFC-0024 §4): particle backgrounds for bands, drawn on a canvas under
|
|
3
|
+
* the content. A self-contained, versioned file under `/_cloudhal/` (CSP `script-src 'self'`) the
|
|
4
|
+
* motion module imports only when a page has a particle band, motion plays at `standard` or
|
|
5
|
+
* above, and the device can afford it (no Save-Data, more than 2 GB of memory).
|
|
6
|
+
*
|
|
7
|
+
* Guards: device-pixel ratio capped at 2; particles scaled by the band's area and capped (120
|
|
8
|
+
* with links, 400 without); 30 frames a second; no drawing while the band is off screen, the tab
|
|
9
|
+
* is hidden or the reader has paused motion; colors read from the band's role variables
|
|
10
|
+
* (`--ch-amb-1`, `--ch-amb-2`); twinkles and glows change slowly (never more than once a second),
|
|
11
|
+
* so nothing flashes. The canvas is `aria-hidden` and ignores the pointer; `interactive` bands
|
|
12
|
+
* push particles away from a fine pointer.
|
|
13
|
+
*/
|
|
14
|
+
export declare const AMBIENT_SCRIPT: {
|
|
15
|
+
readonly path: "/_cloudhal/ambient.1.js";
|
|
16
|
+
readonly code: string;
|
|
17
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudhal's ambient module (RFC-0024 §4): particle backgrounds for bands, drawn on a canvas under
|
|
3
|
+
* the content. A self-contained, versioned file under `/_cloudhal/` (CSP `script-src 'self'`) the
|
|
4
|
+
* motion module imports only when a page has a particle band, motion plays at `standard` or
|
|
5
|
+
* above, and the device can afford it (no Save-Data, more than 2 GB of memory).
|
|
6
|
+
*
|
|
7
|
+
* Guards: device-pixel ratio capped at 2; particles scaled by the band's area and capped (120
|
|
8
|
+
* with links, 400 without); 30 frames a second; no drawing while the band is off screen, the tab
|
|
9
|
+
* is hidden or the reader has paused motion; colors read from the band's role variables
|
|
10
|
+
* (`--ch-amb-1`, `--ch-amb-2`); twinkles and glows change slowly (never more than once a second),
|
|
11
|
+
* so nothing flashes. The canvas is `aria-hidden` and ignores the pointer; `interactive` bands
|
|
12
|
+
* push particles away from a fine pointer.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const code = String.raw`const d=document,h=d.documentElement;
|
|
16
|
+
const fine=matchMedia("(hover: hover) and (pointer: fine)").matches;
|
|
17
|
+
const expressive=h.getAttribute("data-ch-motion")==="expressive";
|
|
18
|
+
const rnd=(a,b)=>a+Math.random()*(b-a);
|
|
19
|
+
const hex=(c,a)=>{const m=/^#([0-9a-f]{6})$/i.exec((c||"").trim());if(!m)return"rgba(128,128,128,"+a+")";const n=parseInt(m[1],16);return"rgba("+(n>>16)+","+((n>>8)&255)+","+(n&255)+","+a+")";};
|
|
20
|
+
const start=(cv)=>{const band=cv.parentElement;if(!band)return;const ctx=cv.getContext("2d");if(!ctx)return;
|
|
21
|
+
const preset=band.getAttribute("data-ch-preset")||"dots";const dens=band.getAttribute("data-ch-density")||"medium";
|
|
22
|
+
const cs=getComputedStyle(band);const c1=cs.getPropertyValue("--ch-amb-1"),c2=cs.getPropertyValue("--ch-amb-2");
|
|
23
|
+
const interactive=fine&&band.hasAttribute("data-ch-interactive");
|
|
24
|
+
let w=0,ht=0,dpr=1,ps=[],on=false,raf=0,last=0,mx=-1e4,my=-1e4;
|
|
25
|
+
const make=(fresh)=>{const n=Math.round(Math.min(preset==="links"?120:400,(w*ht/10000)*(dens==="low"?0.5:dens==="high"?1.6:1)*(expressive?1:0.6)));
|
|
26
|
+
ps=Array.from({length:n},(_,i)=>{const big=preset==="bubbles";return{x:rnd(0,w),y:fresh?rnd(0,ht):rnd(0,ht),r:big?rnd(4,14):preset==="fireflies"?rnd(1.5,3):rnd(0.8,2.4),
|
|
27
|
+
vx:preset==="snow"?rnd(-0.15,0.15):preset==="bubbles"?rnd(-0.1,0.1):rnd(-0.25,0.25),vy:preset==="snow"?rnd(0.3,0.9):preset==="bubbles"?rnd(-0.6,-0.2):rnd(-0.25,0.25),
|
|
28
|
+
c:i%2?c2:c1,p:rnd(0,Math.PI*2),s:rnd(0.6,1.4)};});};
|
|
29
|
+
const size=()=>{const r=band.getBoundingClientRect();dpr=Math.min(2,devicePixelRatio||1);w=Math.max(1,r.width);ht=Math.max(1,r.height);
|
|
30
|
+
cv.width=Math.round(w*dpr);cv.height=Math.round(ht*dpr);ctx.setTransform(dpr,0,0,dpr,0,0);make(true);};
|
|
31
|
+
const frame=(t)=>{raf=0;if(!on)return;raf=requestAnimationFrame(frame);if(t-last<33)return;const dt=Math.min(3,(t-last)/16.7||1);last=t;
|
|
32
|
+
ctx.clearRect(0,0,w,ht);const sec=t/1000;
|
|
33
|
+
for(const q of ps){q.x+=q.vx*dt;q.y+=q.vy*dt;
|
|
34
|
+
if(preset==="snow")q.x+=Math.sin(sec*0.6+q.p)*0.2*dt;
|
|
35
|
+
if(interactive){const dx=q.x-mx,dy=q.y-my,dd=dx*dx+dy*dy;if(dd<8100&&dd>0.01){const f=(1-Math.sqrt(dd)/90)*1.6;q.x+=dx/Math.sqrt(dd)*f;q.y+=dy/Math.sqrt(dd)*f;}}
|
|
36
|
+
if(q.x<-20)q.x=w+20;else if(q.x>w+20)q.x=-20;if(q.y<-20)q.y=ht+20;else if(q.y>ht+20)q.y=-20;
|
|
37
|
+
let a=0.5;if(preset==="stars")a=0.25+0.45*(0.5+0.5*Math.sin(sec*q.s+q.p));else if(preset==="fireflies")a=0.3+0.5*(0.5+0.5*Math.sin(sec*0.8*q.s+q.p));else if(preset==="bubbles")a=0.35;
|
|
38
|
+
if(preset==="fireflies"){const g=ctx.createRadialGradient(q.x,q.y,0,q.x,q.y,q.r*5);g.addColorStop(0,hex(q.c,a));g.addColorStop(1,hex(q.c,0));ctx.fillStyle=g;ctx.beginPath();ctx.arc(q.x,q.y,q.r*5,0,6.2832);ctx.fill();continue;}
|
|
39
|
+
ctx.beginPath();ctx.arc(q.x,q.y,q.r,0,6.2832);
|
|
40
|
+
if(preset==="bubbles"){ctx.strokeStyle=hex(q.c,a);ctx.lineWidth=1;ctx.stroke();}else{ctx.fillStyle=hex(q.c,a);ctx.fill();}}
|
|
41
|
+
if(preset==="links"){ctx.lineWidth=1;for(let i=0;i<ps.length;i++){const a=ps[i];for(let j=i+1;j<ps.length;j++){const b=ps[j];const dx=a.x-b.x,dy=a.y-b.y,dd=dx*dx+dy*dy;
|
|
42
|
+
if(dd<12100){ctx.strokeStyle=hex(a.c,0.22*(1-Math.sqrt(dd)/110));ctx.beginPath();ctx.moveTo(a.x,a.y);ctx.lineTo(b.x,b.y);ctx.stroke();}}}}};
|
|
43
|
+
let visible=false;
|
|
44
|
+
const sync=()=>{const run=visible&&!d.hidden&&!h.hasAttribute("data-ch-motion-paused");if(run&&!on){on=true;last=0;if(!raf)raf=requestAnimationFrame(frame);}else if(!run&&on){on=false;}};
|
|
45
|
+
new IntersectionObserver((es)=>{for(const e of es)visible=e.isIntersecting;sync();}).observe(band);
|
|
46
|
+
d.addEventListener("visibilitychange",sync);
|
|
47
|
+
new MutationObserver(sync).observe(h,{attributes:true,attributeFilter:["data-ch-motion-paused"]});
|
|
48
|
+
if("ResizeObserver"in window)new ResizeObserver(()=>size()).observe(band);
|
|
49
|
+
if(interactive){band.addEventListener("pointermove",(e)=>{const r=band.getBoundingClientRect();mx=e.clientX-r.left;my=e.clientY-r.top;},{passive:true});
|
|
50
|
+
band.addEventListener("pointerleave",()=>{mx=-1e4;my=-1e4;},{passive:true});}
|
|
51
|
+
size();band.setAttribute("data-ch-ambient-live","");sync();};
|
|
52
|
+
for(const cv of d.querySelectorAll("canvas.ch-ambient"))start(cv);
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
export const AMBIENT_SCRIPT = { path: "/_cloudhal/ambient.1.js", code } ;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface AnalyticsClientFile {
|
|
2
|
+
/** URL path, e.g. `/_cloudhal/p.4f9a1c2e.js`. */
|
|
3
|
+
readonly path: string;
|
|
4
|
+
readonly code: string;
|
|
5
|
+
}
|
|
6
|
+
export interface AnalyticsClient {
|
|
7
|
+
/** The page-view script (the one the tag loads). */
|
|
8
|
+
readonly script: AnalyticsClientFile;
|
|
9
|
+
/** The sampled vitals module the script imports. */
|
|
10
|
+
readonly vitals: AnalyticsClientFile;
|
|
11
|
+
}
|
|
12
|
+
/** Bundles one browser entry into a single minified ES module (also the comments client's). */
|
|
13
|
+
export declare function bundle(entry: string, define?: Record<string, string>): Promise<string>;
|
|
14
|
+
/** Writes both scripts under `dir` (a URL or path of the site's static-assets directory). */
|
|
15
|
+
export declare function writeAnalyticsClient(client: AnalyticsClient, dir: URL | string): Promise<void>;
|
|
16
|
+
/** Builds both scripts once per process (they depend only on the package sources). */
|
|
17
|
+
export declare function buildAnalyticsClient(): Promise<AnalyticsClient>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the two analytics scripts (RFC-0006 §5.1) from `@cloudhal/analytics/client` with Vite
|
|
3
|
+
* (Astro's own bundler), at integration time: the vitals module first, so its hashed URL can be
|
|
4
|
+
* baked into the page-view script, then the page-view script. Both are minified ES modules named
|
|
5
|
+
* by the first 8 hex characters of their SHA-256 (`/_cloudhal/p.<hash>.js`, `/_cloudhal/v.<hash>.js`),
|
|
6
|
+
* so the static-assets layer can serve them as immutable. Node only (build time).
|
|
7
|
+
*/
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
import { CLIENT_DIR, CLIENT_SOURCES, VITALS_URL_DEFINE } from "@cloudhal/analytics/client";
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
function hashed(prefix , code ) {
|
|
28
|
+
const hash = createHash("sha256").update(code).digest("hex").slice(0, 8);
|
|
29
|
+
return { path: `${CLIENT_DIR}${prefix}.${hash}.js`, code };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Bundles one browser entry into a single minified ES module (also the comments client's). */
|
|
33
|
+
export async function bundle(entry , define = {}) {
|
|
34
|
+
const { build, minify } = await import("vite");
|
|
35
|
+
const result = await build({
|
|
36
|
+
configFile: false,
|
|
37
|
+
envFile: false,
|
|
38
|
+
logLevel: "silent",
|
|
39
|
+
root: path.dirname(entry),
|
|
40
|
+
publicDir: false,
|
|
41
|
+
define,
|
|
42
|
+
build: {
|
|
43
|
+
write: false,
|
|
44
|
+
minify: true,
|
|
45
|
+
target: "es2020",
|
|
46
|
+
copyPublicDir: false,
|
|
47
|
+
reportCompressedSize: false,
|
|
48
|
+
// Library mode: no module-preload helper around the dynamic import, exports kept.
|
|
49
|
+
lib: { entry, formats: ["es"], fileName: "entry" },
|
|
50
|
+
rolldownOptions: {
|
|
51
|
+
// the vitals module is loaded by URL at run time, never bundled into the page-view script
|
|
52
|
+
external: [/^\/_cloudhal\//],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const outputs = (Array.isArray(result) ? result : [result])
|
|
57
|
+
|
|
58
|
+
;
|
|
59
|
+
const chunks = outputs.flatMap((o) => o.output ?? []).filter((c) => c.type === "chunk");
|
|
60
|
+
if (chunks.length !== 1 || typeof chunks[0]?.code !== "string")
|
|
61
|
+
throw new Error(`browser script ${path.basename(entry)} must build to exactly one chunk`);
|
|
62
|
+
// Library mode keeps whitespace in ES output (to keep pure annotations); the scripts are final
|
|
63
|
+
// and tiny, so they are minified once more as whole modules.
|
|
64
|
+
return (await minify("entry.mjs", chunks[0].code)).code;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Writes both scripts under `dir` (a URL or path of the site's static-assets directory). */
|
|
68
|
+
export async function writeAnalyticsClient(
|
|
69
|
+
client ,
|
|
70
|
+
dir ,
|
|
71
|
+
) {
|
|
72
|
+
const root = typeof dir === "string" ? dir : fileURLToPath(dir.href);
|
|
73
|
+
for (const file of [client.script, client.vitals]) {
|
|
74
|
+
const target = path.join(root, file.path);
|
|
75
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
76
|
+
await writeFile(target, file.code);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let built ;
|
|
81
|
+
|
|
82
|
+
/** Builds both scripts once per process (they depend only on the package sources). */
|
|
83
|
+
export function buildAnalyticsClient() {
|
|
84
|
+
built ??= (async () => {
|
|
85
|
+
const vitals = hashed("v", await bundle(CLIENT_SOURCES.vitals));
|
|
86
|
+
const script = hashed(
|
|
87
|
+
"p",
|
|
88
|
+
await bundle(CLIENT_SOURCES.pageview, { [VITALS_URL_DEFINE]: JSON.stringify(vitals.path) }),
|
|
89
|
+
);
|
|
90
|
+
return { script, vitals };
|
|
91
|
+
})();
|
|
92
|
+
built.catch(() => {
|
|
93
|
+
built = undefined;
|
|
94
|
+
});
|
|
95
|
+
return built;
|
|
96
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics middleware (added by the `cloudhal()` integration in `cloudhal dev`; RFC-0006 §11):
|
|
3
|
+
* answers `POST /__cloudhal/e`, serves the built scripts and injects the tag while recording, and
|
|
4
|
+
* writes into the local SQLite store (`analytics-node.ts`). The Cloudflare Site Worker does the
|
|
5
|
+
* same in its entry (`cloudflare-entry.ts`).
|
|
6
|
+
*/
|
|
7
|
+
import client from "virtual:cloudhal/analytics-client";
|
|
8
|
+
import config from "virtual:cloudhal/config";
|
|
9
|
+
import { analyticsBackend } from "@cloudhal/astro-renderer/runtime";
|
|
10
|
+
import {
|
|
11
|
+
createNodeAnalytics,
|
|
12
|
+
|
|
13
|
+
nodeAnalyticsSettings,
|
|
14
|
+
} from "./analytics-node.js";
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const { defaults, record } = nodeAnalyticsSettings(config);
|
|
22
|
+
const handler = createNodeAnalytics({
|
|
23
|
+
siteId: config.siteId,
|
|
24
|
+
backend: analyticsBackend(config.siteId, config) ,
|
|
25
|
+
client,
|
|
26
|
+
defaults,
|
|
27
|
+
record,
|
|
28
|
+
onError: (m, e) => console.warn(`cloudhal: ${m}`, e),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export async function onRequest(
|
|
32
|
+
context ,
|
|
33
|
+
next ,
|
|
34
|
+
) {
|
|
35
|
+
// Added in `cloudhal dev` only, where every route renders per request (static routes too).
|
|
36
|
+
let ip ;
|
|
37
|
+
try {
|
|
38
|
+
ip = context.clientAddress;
|
|
39
|
+
} catch {
|
|
40
|
+
ip = undefined;
|
|
41
|
+
}
|
|
42
|
+
return handler(context.request, next, ip);
|
|
43
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Site analytics on Node (RFC-0006 §7.1 L3, §11): what the `cloudhal()` integration's analytics
|
|
3
|
+
* middleware does for `cloudhal dev` (and, later, a Node self-host server). The same
|
|
4
|
+
* `SiteAnalytics` as the Site Worker, writing raw events to the local SQLite store through
|
|
5
|
+
* `SqlAnalytics`:
|
|
6
|
+
*
|
|
7
|
+
* - `POST /__cloudhal/e` answers `204` always; it records only when recording is on (`cloudhal dev`
|
|
8
|
+
* records nothing unless `analytics.dev` is set: it is the author's own traffic);
|
|
9
|
+
* - while recording, HTML `200`s get the script tag and `/_cloudhal/*.js` is served from memory
|
|
10
|
+
* (the Site Worker build ships them as static assets instead);
|
|
11
|
+
* - `render` events for redirects, 404, 410 and 5xx, as on the Worker.
|
|
12
|
+
*
|
|
13
|
+
* Beacons resolve against the **published** snapshot of the local store, so a page that is only a
|
|
14
|
+
* draft in `cloudhal dev` is never counted.
|
|
15
|
+
*/
|
|
16
|
+
import { type AnalyticsDefaults } from "@cloudhal/analytics";
|
|
17
|
+
import type { Site } from "@cloudhal/core-contracts";
|
|
18
|
+
import type { SqlDriver } from "@cloudhal/storage";
|
|
19
|
+
import type { AnalyticsClient } from "./analytics-client.js";
|
|
20
|
+
import type { CloudhalRendererConfig } from "./integration.js";
|
|
21
|
+
import type { GraphSource } from "./source.js";
|
|
22
|
+
export interface NodeAnalyticsBackend {
|
|
23
|
+
readonly open: () => Promise<SqlDriver>;
|
|
24
|
+
readonly sql: () => SqlDriver;
|
|
25
|
+
readonly site: () => Promise<Site | undefined>;
|
|
26
|
+
readonly snapshot: (id: string) => Promise<GraphSource>;
|
|
27
|
+
}
|
|
28
|
+
export interface NodeAnalyticsOptions {
|
|
29
|
+
readonly siteId: string;
|
|
30
|
+
readonly backend: NodeAnalyticsBackend;
|
|
31
|
+
/** The built scripts (dev serves them from memory); `null` = none. */
|
|
32
|
+
readonly client: Pick<AnalyticsClient, "script" | "vitals"> | null;
|
|
33
|
+
/** Deployment defaults; `undefined` = off. */
|
|
34
|
+
readonly defaults: AnalyticsDefaults | undefined;
|
|
35
|
+
/** Write events (`analytics.dev` in `cloudhal dev`). */
|
|
36
|
+
readonly record: boolean;
|
|
37
|
+
readonly now?: () => number;
|
|
38
|
+
readonly onError?: (message: string, error?: unknown) => void;
|
|
39
|
+
}
|
|
40
|
+
/** Defaults and recording for `cloudhal dev`: the integration's options, else the environment. */
|
|
41
|
+
export declare function nodeAnalyticsSettings(config: Pick<CloudhalRendererConfig, "analytics">, env?: Record<string, string | undefined>): {
|
|
42
|
+
defaults: AnalyticsDefaults | undefined;
|
|
43
|
+
record: boolean;
|
|
44
|
+
};
|
|
45
|
+
/** A request handler around the page pipeline (`next`). */
|
|
46
|
+
export declare function createNodeAnalytics(options: NodeAnalyticsOptions): (request: Request, next: () => Promise<Response>, clientIp?: string) => Promise<Response>;
|