How add2cal/add-to-calendar-button works
1. This repository is a browser-first JavaScript library that ships a custom element, add-to-calendar-button, plus a full documentation/demo site. The main product lives in src/; the Nuxt-based marketing/docs app lives in demo/; CSS themes and static assets are shared from assets/.
2. The core runtime is structured as a pipeline around the button component lifecycle:
- atcb-init.js and atcb-globals.js handle bootstrapping and shared state.
- atcb-validate.js checks the incoming attributes/configuration.
- atcb-generate.js, atcb-generate-rich-data.js, and atcb-generate-pro.js produce the calendar outputs and metadata.
- atcb-event.js, atcb-control.js, atcb-decorate.js, and atcb-links.js handle interaction, UI behavior, decoration, and outbound calendar targets.
- atcb-util.js, atcb-i18n.js, and atcb-validate.js provide shared helpers, localization, and guardrails.
3. The primary data flow is attribute-driven: consumers place <add-to-calendar-button ... /> in HTML, the component reads those attributes, validates them, normalizes dates/time zones, and then generates either calendar links, iCal/ICS outputs, or rich structured data. The README makes clear that the component is designed to work without any backend service.
4. Calendar generation is the core domain boundary. Supported targets include Google, Apple, Yahoo, Microsoft 365/Outlook/Teams, and generic iCal. The codebase also has explicit support for recurring events, dynamic dates, all-day/timed events, and time zone/DST handling, which is why timezone and recurrence-specific playground/test files exist.
5. UI behavior is separated from event generation. The component supports multiple presentation modes and themes, with CSS variants in assets/css/ such as flat, round, 3D, neumorphism, text, date, and simple styles. That indicates a theming layer distinct from the event logic.
6. Localization is a first-class subsystem. src/atcb-i18n.js plus the demo’s demo/i18n/ folder and locale JSON files show that labels, controls, and guidance are translated, including support for multiple languages and RTL scenarios mentioned in the README.
7. SEO and content metadata are treated as part of the product. atcb-generate-rich-data.js generates schema.org structured data so calendar buttons can also contribute rich snippets. This is an important boundary because it ties UI configuration to search/indexing behavior.
8. There is a clear PRO/free split. atcb-generate-pro.js, no-pro/, no-pro-unstyle/, and index.d.ts/variant type files suggest the package can ship different builds or entry points depending on licensing/features. The README also describes extra PRO capabilities such as hosted ICS generation, RSVPs, and advanced distribution options.
9. Packaging and release are handled as a library artifact, not just an app. package.json, src/package.json, Gruntfile.js, grunt-wrapper/, and the GitHub Actions workflows point to a build/publish pipeline that produces npm-ready bundles and a docs site. The presence of npm-publish.yml and gh-pages.yml shows separate deployment paths for package releases and the public site.
10. The demo/ directory is a complete Nuxt application used as the live documentation, playground, and integration guide site. It contains pages for framework-specific usage, configuration, examples, legal/privacy pages, and UI components such as the playground controls, language switcher, theme switch, and code blocks. That app is the user-facing reference implementation for how the component should be consumed.
11. The demo app also demonstrates the integration boundary with host frameworks. Page files like use-with-react.vue, use-with-vue.vue, use-with-nextjs.vue, use-with-angular.vue, etc. indicate that the library is meant to be framework-agnostic and is showcased through framework-specific guidance rather than framework-specific implementations.
12. Testing is split between server-side initialization and browser/web-component behavior. test/server-side-init.test.js covers SSR/init behavior, while test/wc-tests/ includes load and recurrence/time-zone tests, implying that correct behavior depends on both server-rendered and client-side execution paths.
13. Overall architecture: one reusable client-side component library at the center, surrounded by theme assets, localization, rich-data generation, and packaging variants; a separate Nuxt docs/demo site consuming the library; and CI/CD flows for testing, linting, docs publishing, and npm release.
Main entry points: atcb-generate.js Generate · atcb-init.js Init · tests.yml CI/CD · atcb-validate.js Validate
Components 22
Core library
Browser-first custom element runtime and calendar generation pipeline.
- Init · Entry and lifecycle bootstrapping for the custom element.
src/atcb-init.js - Globals · Shared runtime state and cross-module configuration.
src/atcb-globals.js - Validate · Attribute and configuration validation.
src/atcb-validate.js - Generate · Primary calendar-link and output generation pipeline.
src/atcb-generate.js - Rich data · schema.org structured data generation for search/indexing.
src/atcb-generate-rich-data.js - Pro features · PRO-only generation and distribution capabilities.
src/atcb-generate-pro.js - Events · User interaction and event handling for the button.
src/atcb-event.js - Control UI · Presentation state, controls, and component behavior.
src/atcb-control.js - Decorate · Visual decoration and mode-specific rendering tweaks.
src/atcb-decorate.js - Links · Outbound calendar target handling for vendors and formats.
src/atcb-links.js - Utils · General-purpose helpers used across the runtime.
src/atcb-util.js - I18n · Runtime translations and locale-aware labels.
src/atcb-i18n.js
Demo site
Nuxt-based docs, playground, and integration guides.
- Nuxt app · Complete documentation, playground, and marketing application.
demo/app.vue - Pages · Docs, examples, integration guides, and legal pages.
demo/pages/index.vue - UI components · Reusable site components for navigation, controls, and playground.
demo/components/header.vue - Site i18n · Demo-site locale config and translated strings.
demo/i18n/i18n.config.ts
Build & release
Packaging, wrappers, and CI/CD workflows for publishing.
- Package · Root package definition and library publishing metadata.
package.json - Grunt build · Library build orchestration and wrapper generation.
Gruntfile.js - CI/CD · Workflow automation for tests, docs deployment, and npm release.
.github/workflows/tests.yml
Testing
Server-side and web-component test coverage.
- SSR init test · Server-side initialization behavior coverage.
test/server-side-init.test.js - WC tests · Web-component load, recurrence, and timezone behavior coverage.
test/wc-tests/wc-load.test.js
Themes & shared assets
Shared styles and static assets used by the component and site.
- Themes · Shared CSS themes and presentation variants.
assets/css/atcb.css
Connections 29
- Init → Globals: bootstraps · Initializes shared runtime state.
- Init → Validate: reads attrs · Starts from attribute-driven configuration.
- Validate → Utils: uses · Validation relies on helper routines.
- Validate → I18n: labels · Validation and UI messaging use locale text.
- Validate → Generate: feeds · Validated config flows into generation.
- Generate → Links: builds targets · Produces calendar-specific outbound links and formats.
- Generate → Rich data: adds meta · Generates structured data alongside calendar outputs.
- Generate → Pro features: extends · PRO path adds licensed output variants.
- Generate → Control UI: updates ui · Generation results affect component controls and state.
- Events → Control UI: drives · User interaction changes visible behavior.
- Control UI → Decorate: styles · Control state determines presentation variants.
- Decorate → Themes: uses themes · Theme variants are sourced from shared CSS assets.
- Events → Links: opens · Interactions route users to calendar targets.
- I18n → Themes: supports rtl · Localization pairs with theme and layout handling.
- Nuxt app → Pages: routes · The Nuxt shell serves documentation pages.
- Nuxt app → UI components: composes · Site UI is assembled from shared components.
- Nuxt app → Site i18n: loads · The site uses its own locale layer.
- Pages → Init: demonstrates · Docs pages showcase the custom element API.
- UI components → Init: embeds · Playground and examples mount the component.
- Site i18n → I18n: mirrors · Site translations mirror component language support.
- Package → Grunt build: scripts · Package scripts orchestrate build steps.
- Grunt build → Init: bundles · Build pipeline packages the runtime modules.
- Grunt build → Themes: ships · Build includes distributable theme styles.
- CI/CD → SSR init test: runs · CI executes server-side checks.
- CI/CD → WC tests: runs · CI executes web-component checks.
- CI/CD → Nuxt app: deploys · Separate workflow publishes the docs site.
- CI/CD → Package: releases · Package publishing is handled in CI.
- SSR init test → Init: verifies · Tests SSR-safe initialization.
- WC tests → Generate: verifies · Tests cover generation behavior in the browser.