astro-consent 1.0.16 → 2.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,38 @@
1
+ # Changelog
2
+
3
+ All notable changes to `astro-consent` will be documented in this file.
4
+
5
+ The format follows a simple Keep a Changelog style, with semantic versioning.
6
+
7
+ ## [2.0.0] - 2026-04-01
8
+
9
+ ### Breaking
10
+
11
+ - Changed the package to a major release after the CLI and integration workflow were expanded.
12
+ - The installer now writes a marked `astro-consent` block into `astro.config.*` so `init` and `remove` can target only the plugin stanza.
13
+
14
+ ### Added
15
+
16
+ - `init`, `remove`, `doctor`, and `status` CLI commands
17
+ - `--dry-run` support for install and remove
18
+ - `--json` output for `doctor` and `status`
19
+ - `banner` and `overlay` presentation modes
20
+ - Configurable display timing with `displayUntilIdle` and `displayIdleDelayMs`
21
+ - Configurable copy with `headline`, `description`, `acceptLabel`, `rejectLabel`, and `manageLabel`
22
+ - Separate `cookiePolicyUrl` and `privacyPolicyUrl` support with backwards-compatible `policyUrl` fallback
23
+ - Overlay accessibility improvements, including focus trapping, `Escape` to close, and focus return
24
+ - Generated editable stylesheet at `src/cookiebanner/styles.css`
25
+
26
+ ### Changed
27
+
28
+ - Updated default copy to be more professional and concise
29
+ - Improved banner and overlay motion and spacing
30
+ - Reworked the README into a full onboarding guide
31
+ - Updated package branding to `Velohost UK Limited`
32
+ - Bumped the package major version to `2.0.0`
33
+
34
+ ### Fixed
35
+
36
+ - Safer install and removal behavior for `astro.config.*`
37
+ - Removed older CSS injection path in favor of a real generated stylesheet
38
+ - Improved CLI diagnostics and install/status reporting
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Velohost
3
+ Copyright (c) 2026 Velohost UK Limited
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,89 +1,52 @@
1
1
  # astro-consent
2
2
 
3
- A **privacy-first, zero-dependency cookie consent banner** for Astro projects built for speed, compliance, and total visual control.
3
+ `astro-consent` is a privacy-first cookie consent integration for Astro. It adds a polished consent banner or overlay, generates an editable stylesheet in your project, and exposes a tiny runtime API for managing stored consent.
4
4
 
5
- Designed and maintained by **Velohost**.
5
+ ## What You Get
6
6
 
7
- ---
7
+ - A banner or overlay consent UI
8
+ - A generated `src/cookiebanner/styles.css` file you can edit directly
9
+ - Idle-based display with a configurable fade-in delay
10
+ - Focus trapping, `Escape` to close, and focus return for the overlay
11
+ - CLI setup, removal, and diagnostics commands
12
+ - TypeScript support
13
+ - Compatibility with Astro 4, 5, and 6
8
14
 
9
- ## Why astro-consent?
15
+ ## Quick Start
10
16
 
11
- Most cookie consent solutions are bloated, opaque, or tied to third-party services.
12
-
13
- **astro-consent** is built differently:
14
-
15
- - No trackers
16
- - No remote calls
17
- - No analytics SDKs
18
- - No vendor lock-in
19
- - No runtime dependencies
20
-
21
- Just a **fast, deterministic, developer-controlled consent layer** that respects user privacy and legal boundaries.
22
-
23
- ---
24
-
25
- ## ✨ Features
26
-
27
- - ✅ GDPR / UK GDPR friendly
28
- - 🍪 Consent categories: Essential, Analytics, Marketing
29
- - 🎛️ Preferences modal with toggle switches
30
- - ⚡ Zero runtime dependencies
31
- - 🎨 Fully themeable via CSS variables
32
- - 🧠 Frontend-controlled script loading
33
- - 🧩 Native Astro integration
34
- - 🛠️ CLI installer & remover
35
- - 🔁 Clean uninstall with no residue
36
- - 🌍 Framework-agnostic frontend API
37
-
38
- ---
39
-
40
- ## 📦 Installation (Required)
41
-
42
- This package uses **both an Astro integration and a CLI installer**.
43
-
44
- ### 1️⃣ Install the package
17
+ ### 1. Install the package
45
18
 
46
19
  ```bash
47
20
  npm install astro-consent
48
21
  ```
49
22
 
50
- This step is **required** so Astro can import the integration at build time.
51
-
52
- ---
23
+ ### 2. Add the integration
53
24
 
54
- ### 2️⃣ Run the installer
25
+ Use the CLI to wire everything into your Astro project:
55
26
 
56
27
  ```bash
57
- npx astro-consent
28
+ npx astro-consent init
58
29
  ```
59
30
 
60
- This will automatically:
31
+ That will:
61
32
 
62
- - Inject the Astro integration into `astro.config.*`
63
- - Create `src/cookiebanner.css` for theme control
64
- - Enable the consent banner across your site
33
+ - add `astro-consent` to `astro.config.*`
34
+ - create `src/cookiebanner/styles.css` if it is missing
35
+ - add a starter configuration block with placeholder values
65
36
 
66
- No manual wiring required.
37
+ ### 3. Edit the generated CSS
67
38
 
68
- ---
39
+ Open `src/cookiebanner/styles.css` in your project and customize the banner or modal visually. The package does not inject CSS through JavaScript, so this file is the single source of truth for styling.
69
40
 
70
- ### Uninstall
41
+ ### 4. Run your Astro app
71
42
 
72
43
  ```bash
73
- npx astro-consent remove
44
+ npm run dev
74
45
  ```
75
46
 
76
- This cleanly removes:
77
-
78
- - The integration entry
79
- - Generated files
80
- - All banner logic
81
-
82
- No orphaned config. No hidden state.
47
+ ## Recommended Setup
83
48
 
84
- ---
85
-
86
- ## 🔧 Astro Integration Usage
49
+ The default install is designed to be easy to understand and safe to customise. A typical configuration looks like this:
87
50
 
88
51
  ```ts
89
52
  import astroConsent from "astro-consent";
@@ -92,96 +55,247 @@ export default {
92
55
  integrations: [
93
56
  astroConsent({
94
57
  siteName: "My Website",
95
- policyUrl: "https://example.com/privacy-policy",
58
+ headline: "Manage cookie preferences for My Website",
59
+ description:
60
+ "We use cookies to improve site performance, measure traffic, and support marketing.",
61
+ acceptLabel: "Accept all",
62
+ rejectLabel: "Reject all",
63
+ manageLabel: "Manage preferences",
64
+ cookiePolicyUrl: "/cookie-policy",
65
+ privacyPolicyUrl: "/privacy",
66
+ displayUntilIdle: true,
67
+ displayIdleDelayMs: 1000,
68
+ presentation: "banner",
96
69
  consent: {
97
70
  days: 30,
98
- storageKey: "astro-cookie-consent"
99
- },
100
- categories: {
101
- analytics: false,
102
- marketing: false
71
+ storageKey: "astro-consent"
103
72
  }
104
73
  })
105
74
  ]
106
75
  };
107
76
  ```
108
77
 
109
- ### Configuration notes
78
+ ## CLI Commands
79
+
80
+ ### `init`
81
+
82
+ ```bash
83
+ npx astro-consent init
84
+ ```
85
+
86
+ Adds the integration import and a marked configuration block to `astro.config.*`, then creates `src/cookiebanner/styles.css` if the file does not already exist.
87
+
88
+ ### `remove`
110
89
 
111
- - **policyUrl**
112
- A full, public URL to your Privacy or Cookie Policy page.
113
- This is linked directly from the consent banner.
90
+ ```bash
91
+ npx astro-consent remove
92
+ ```
114
93
 
115
- - **consent.days**
116
- How long (in days) consent is stored before the user is asked again.
94
+ Removes the marked `astro-consent` block from `astro.config.*`, removes the import, and deletes `src/cookiebanner/styles.css` if it exists.
117
95
 
118
- - **consent.storageKey**
119
- The `localStorage` key used to persist consent.
120
- You may change this freely if you need per-site or per-environment isolation.
96
+ ### `doctor`
121
97
 
122
- - **categories.analytics**
123
- Allows analytics scripts to load only after consent.
124
- Typical use: Plausible, self-hosted analytics, Google Analytics.
98
+ ```bash
99
+ npx astro-consent doctor
100
+ ```
125
101
 
126
- - **categories.marketing**
127
- Allows marketing and advertising scripts to load only after consent.
128
- Typical use: ad pixels, remarketing tags, embedded social trackers.
102
+ Checks the following:
129
103
 
130
- Scripts outside the **essential** category must be conditionally loaded.
104
+ - Astro config import wiring
105
+ - `astroConsent(...)` integration wiring
106
+ - `src/cookiebanner/styles.css` existence
107
+ - `src/layouts/BaseLayout.astro` importing the stylesheet
131
108
 
132
- ---
109
+ Use JSON output for automation:
133
110
 
134
- ## 🧠 Frontend API
111
+ ```bash
112
+ npx astro-consent doctor --json
113
+ ```
135
114
 
136
- ```js
137
- window.cookieConsent.get();
138
- window.cookieConsent.set({ essential: true, analytics: true });
139
- window.cookieConsent.reset();
115
+ ### `status`
116
+
117
+ ```bash
118
+ npx astro-consent status
140
119
  ```
141
120
 
142
- ---
121
+ Reports the current install state:
143
122
 
144
- ## 🎨 Theming
123
+ - whether the Astro config is wired
124
+ - whether the stylesheet exists
125
+ - whether the package is linked into `node_modules`
126
+ - which consent storage key is configured
127
+ - a note explaining that actual consent state is browser-side
145
128
 
146
- All visuals are controlled via:
129
+ JSON output is also available:
147
130
 
131
+ ```bash
132
+ npx astro-consent status --json
148
133
  ```
149
- src/cookiebanner.css
134
+
135
+ ### Dry Run
136
+
137
+ Preview changes without writing files:
138
+
139
+ ```bash
140
+ npx astro-consent init --dry-run
141
+ npx astro-consent remove --dry-run
150
142
  ```
151
143
 
152
- You must ensure this file is included globally.
144
+ ## Presentation Modes
145
+
146
+ You can choose how the consent UI appears:
153
147
 
154
- ### Recommended import (Astro)
148
+ - `banner` for a standard bottom-of-page consent banner
149
+ - `overlay` for a centered modal-first experience
155
150
 
156
- Import the stylesheet once in your main layout or entry file:
151
+ Example:
157
152
 
158
153
  ```ts
159
- import "../cookiebanner.css";
154
+ astroConsent({
155
+ presentation: "overlay"
156
+ });
160
157
  ```
161
158
 
162
- This guarantees the banner styles are available on every page.
159
+ ## Display Timing
163
160
 
164
- - This file is never overwritten
165
- - All colours, spacing, radius, and animations are controlled via CSS variables
166
- - Full visual control with zero JavaScript theming
161
+ The consent UI can wait until the browser is idle before appearing, then fade in after a short pause.
167
162
 
168
- ---
163
+ ### `displayUntilIdle`
169
164
 
170
- ## 🔐 Privacy
165
+ When `true`, the banner or overlay waits for browser idle before showing.
171
166
 
172
- - No cookies before consent
173
- - No tracking without permission
174
- - No external requests
175
- - Stored locally with TTL
167
+ ### `displayIdleDelayMs`
168
+
169
+ Adds a delay after idle before the UI becomes visible.
170
+
171
+ Example:
172
+
173
+ ```ts
174
+ astroConsent({
175
+ displayUntilIdle: true,
176
+ displayIdleDelayMs: 1000
177
+ });
178
+ ```
176
179
 
177
- ---
180
+ ## Copy Customisation
181
+
182
+ These options let you tune the wording without editing the runtime:
183
+
184
+ - `siteName` sets the site name used in fallback copy
185
+ - `headline` sets the banner or dialog title
186
+ - `description` sets the explanatory text
187
+ - `acceptLabel` sets the primary action
188
+ - `rejectLabel` sets the reject action
189
+ - `manageLabel` sets the preferences action
190
+
191
+ Example:
192
+
193
+ ```ts
194
+ astroConsent({
195
+ siteName: "Escape Zone",
196
+ headline: "Manage cookie preferences for Escape Zone",
197
+ description:
198
+ "We use cookies to improve site performance, measure traffic, and support marketing.",
199
+ acceptLabel: "Accept all",
200
+ rejectLabel: "Reject all",
201
+ manageLabel: "Manage preferences"
202
+ });
203
+ ```
204
+
205
+ ## Policy Links
206
+
207
+ The consent UI supports separate links for cookie and privacy policy pages.
208
+
209
+ - `cookiePolicyUrl` controls the cookie policy link
210
+ - `privacyPolicyUrl` controls the privacy policy link
211
+
212
+ If you still pass `policyUrl`, it will be used for both links as a backwards-compatible fallback.
213
+
214
+ ## Runtime API
215
+
216
+ The integration exposes a small browser API on `window.astroConsent`:
217
+
218
+ ```js
219
+ window.astroConsent.get();
220
+ window.astroConsent.set({ essential: true, analytics: true, marketing: false });
221
+ window.astroConsent.reset();
222
+ ```
223
+
224
+ - `get()` returns the stored consent object if one exists and is still valid
225
+ - `set(...)` stores a new consent state
226
+ - `reset()` clears consent and reloads the page
227
+
228
+ ## Styling
229
+
230
+ The generated `src/cookiebanner/styles.css` file is meant to be edited directly.
231
+
232
+ It uses `cb-*` custom properties so you can change the visual style without rewriting selectors. The most useful tokens are:
233
+
234
+ - `--cb-bg`
235
+ - `--cb-text`
236
+ - `--cb-muted`
237
+ - `--cb-border`
238
+ - `--cb-accent`
239
+ - `--cb-accent-strong`
240
+ - `--cb-success`
241
+ - `--cb-shadow`
242
+ - `--cb-banner-radius`
243
+ - `--cb-modal-width`
244
+ - `--cb-button-bg`
245
+ - `--cb-button-secondary-bg`
246
+
247
+ ## File Layout
248
+
249
+ The installer creates the stylesheet here:
250
+
251
+ ```txt
252
+ src/cookiebanner/styles.css
253
+ ```
254
+
255
+ That file is intentionally local to your project. It is not injected from the package at runtime, which keeps styling under your control and avoids overwriting custom work.
256
+
257
+ ## Notes
258
+
259
+ - Consent is stored in `localStorage`
260
+ - The stored value expires after the configured TTL
261
+ - Optional categories default to checked in the UI, but users can still reject them
262
+ - The overlay uses accessible dialog behavior, including focus trapping, `Escape` to close, and focus return to the trigger
263
+
264
+ ## Troubleshooting
265
+
266
+ ### The banner does not appear
267
+
268
+ Check the following:
269
+
270
+ 1. `npx astro-consent init` has been run in the Astro project root
271
+ 2. `astro.config.*` includes the `astro-consent` integration
272
+ 3. `src/layouts/BaseLayout.astro` imports `../cookiebanner/styles.css`
273
+ 4. You have not already stored consent in `localStorage`
274
+
275
+ ### The CLI says the stylesheet is missing
276
+
277
+ Run:
278
+
279
+ ```bash
280
+ npx astro-consent init
281
+ ```
282
+
283
+ ### The CLI says the config is not wired
284
+
285
+ Run:
286
+
287
+ ```bash
288
+ npx astro-consent doctor
289
+ ```
178
290
 
179
- ## 📄 License
291
+ and follow the fix instructions it prints.
180
292
 
181
- MIT © Velohost
293
+ ## Why the Package Works This Way
182
294
 
183
- ---
295
+ The design is intentionally simple:
184
296
 
185
- ## 🏢 Velohost
297
+ - the runtime handles consent logic and UI behavior
298
+ - the generated stylesheet handles appearance
299
+ - the CLI wires setup and removal cleanly
186
300
 
187
- https://velohost.co.uk/
301
+ That separation keeps the plugin predictable, easier to debug, and safer to customise.