@hagicode/hagilight-core 0.11.0 → 0.11.1-dev.133.1.338317a

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.
Files changed (116) hide show
  1. package/PostHog.astro +11 -0
  2. package/README.md +154 -1
  3. package/RootTransit.astro +552 -0
  4. package/data/comparison-articles/de-DE/codebuddy-vs-hagicode.json +10 -10
  5. package/data/comparison-articles/de-DE/codex-vs-hagicode.json +6 -6
  6. package/data/comparison-articles/de-DE/copilot-vs-hagicode.json +2 -2
  7. package/data/comparison-articles/de-DE/gemini-vs-hagicode.json +15 -15
  8. package/data/comparison-articles/de-DE/kimi-vs-hagicode.json +15 -15
  9. package/data/comparison-articles/de-DE/kiro-vs-hagicode.json +12 -12
  10. package/data/comparison-articles/de-DE/pi-vs-hagicode.json +10 -10
  11. package/data/comparison-articles/de-DE/qoder-vs-hagicode.json +13 -13
  12. package/data/comparison-articles/de-DE/reasonix-vs-hagicode.json +10 -10
  13. package/data/comparison-articles/en-US/claude-vs-hagicode.json +1 -1
  14. package/data/comparison-articles/en-US/codebuddy-vs-hagicode.json +1 -1
  15. package/data/comparison-articles/en-US/codex-vs-hagicode.json +18 -18
  16. package/data/comparison-articles/en-US/copilot-vs-hagicode.json +29 -29
  17. package/data/comparison-articles/en-US/deepagents-vs-hagicode.json +4 -4
  18. package/data/comparison-articles/en-US/gemini-vs-hagicode.json +32 -32
  19. package/data/comparison-articles/en-US/junie-vs-hagicode.json +19 -19
  20. package/data/comparison-articles/en-US/kimi-vs-hagicode.json +24 -24
  21. package/data/comparison-articles/en-US/kiro-vs-hagicode.json +25 -25
  22. package/data/comparison-articles/en-US/omp-vs-hagicode.json +1 -1
  23. package/data/comparison-articles/en-US/opencode-vs-hagicode.json +1 -1
  24. package/data/comparison-articles/en-US/pi-vs-hagicode.json +1 -1
  25. package/data/comparison-articles/en-US/qoder-vs-hagicode.json +45 -45
  26. package/data/comparison-articles/en-US/reasonix-vs-hagicode.json +1 -1
  27. package/data/comparison-articles/es-ES/codebuddy-vs-hagicode.json +11 -11
  28. package/data/comparison-articles/es-ES/codex-vs-hagicode.json +6 -6
  29. package/data/comparison-articles/es-ES/copilot-vs-hagicode.json +2 -2
  30. package/data/comparison-articles/es-ES/gemini-vs-hagicode.json +15 -15
  31. package/data/comparison-articles/es-ES/kimi-vs-hagicode.json +15 -15
  32. package/data/comparison-articles/es-ES/kiro-vs-hagicode.json +12 -12
  33. package/data/comparison-articles/es-ES/pi-vs-hagicode.json +10 -10
  34. package/data/comparison-articles/es-ES/qoder-vs-hagicode.json +12 -12
  35. package/data/comparison-articles/es-ES/reasonix-vs-hagicode.json +10 -10
  36. package/data/comparison-articles/fr-FR/codebuddy-vs-hagicode.json +11 -11
  37. package/data/comparison-articles/fr-FR/codex-vs-hagicode.json +6 -6
  38. package/data/comparison-articles/fr-FR/copilot-vs-hagicode.json +2 -2
  39. package/data/comparison-articles/fr-FR/gemini-vs-hagicode.json +15 -15
  40. package/data/comparison-articles/fr-FR/kimi-vs-hagicode.json +15 -15
  41. package/data/comparison-articles/fr-FR/kiro-vs-hagicode.json +12 -12
  42. package/data/comparison-articles/fr-FR/pi-vs-hagicode.json +10 -10
  43. package/data/comparison-articles/fr-FR/qoder-vs-hagicode.json +12 -12
  44. package/data/comparison-articles/fr-FR/reasonix-vs-hagicode.json +10 -10
  45. package/data/comparison-articles/ja-JP/claude-vs-hagicode.json +1 -1
  46. package/data/comparison-articles/ja-JP/codebuddy-vs-hagicode.json +11 -11
  47. package/data/comparison-articles/ja-JP/codex-vs-hagicode.json +7 -7
  48. package/data/comparison-articles/ja-JP/copilot-vs-hagicode.json +2 -2
  49. package/data/comparison-articles/ja-JP/gemini-vs-hagicode.json +16 -16
  50. package/data/comparison-articles/ja-JP/kimi-vs-hagicode.json +16 -16
  51. package/data/comparison-articles/ja-JP/kiro-vs-hagicode.json +13 -13
  52. package/data/comparison-articles/ja-JP/pi-vs-hagicode.json +11 -11
  53. package/data/comparison-articles/ja-JP/qoder-vs-hagicode.json +13 -13
  54. package/data/comparison-articles/ja-JP/reasonix-vs-hagicode.json +11 -11
  55. package/data/comparison-articles/ko-KR/claude-vs-hagicode.json +1 -1
  56. package/data/comparison-articles/ko-KR/codebuddy-vs-hagicode.json +11 -11
  57. package/data/comparison-articles/ko-KR/codex-vs-hagicode.json +7 -7
  58. package/data/comparison-articles/ko-KR/copilot-vs-hagicode.json +2 -2
  59. package/data/comparison-articles/ko-KR/gemini-vs-hagicode.json +15 -15
  60. package/data/comparison-articles/ko-KR/kimi-vs-hagicode.json +15 -15
  61. package/data/comparison-articles/ko-KR/kiro-vs-hagicode.json +12 -12
  62. package/data/comparison-articles/ko-KR/pi-vs-hagicode.json +11 -11
  63. package/data/comparison-articles/ko-KR/qoder-vs-hagicode.json +12 -12
  64. package/data/comparison-articles/ko-KR/reasonix-vs-hagicode.json +11 -11
  65. package/data/comparison-articles/pt-BR/codebuddy-vs-hagicode.json +11 -11
  66. package/data/comparison-articles/pt-BR/codex-vs-hagicode.json +6 -6
  67. package/data/comparison-articles/pt-BR/copilot-vs-hagicode.json +2 -2
  68. package/data/comparison-articles/pt-BR/gemini-vs-hagicode.json +15 -15
  69. package/data/comparison-articles/pt-BR/kimi-vs-hagicode.json +15 -15
  70. package/data/comparison-articles/pt-BR/kiro-vs-hagicode.json +12 -12
  71. package/data/comparison-articles/pt-BR/pi-vs-hagicode.json +10 -10
  72. package/data/comparison-articles/pt-BR/qoder-vs-hagicode.json +12 -12
  73. package/data/comparison-articles/pt-BR/reasonix-vs-hagicode.json +10 -10
  74. package/data/comparison-articles/ru-RU/codebuddy-vs-hagicode.json +11 -11
  75. package/data/comparison-articles/ru-RU/codex-vs-hagicode.json +6 -6
  76. package/data/comparison-articles/ru-RU/copilot-vs-hagicode.json +2 -2
  77. package/data/comparison-articles/ru-RU/gemini-vs-hagicode.json +15 -15
  78. package/data/comparison-articles/ru-RU/kimi-vs-hagicode.json +15 -15
  79. package/data/comparison-articles/ru-RU/kiro-vs-hagicode.json +12 -12
  80. package/data/comparison-articles/ru-RU/pi-vs-hagicode.json +10 -10
  81. package/data/comparison-articles/ru-RU/qoder-vs-hagicode.json +45 -45
  82. package/data/comparison-articles/ru-RU/reasonix-vs-hagicode.json +10 -10
  83. package/data/comparison-articles/zh-CN/claude-vs-hagicode.json +1 -1
  84. package/data/comparison-articles/zh-CN/codebuddy-vs-hagicode.json +1 -1
  85. package/data/comparison-articles/zh-CN/codex-vs-hagicode.json +18 -18
  86. package/data/comparison-articles/zh-CN/copilot-vs-hagicode.json +29 -29
  87. package/data/comparison-articles/zh-CN/deepagents-vs-hagicode.json +4 -4
  88. package/data/comparison-articles/zh-CN/gemini-vs-hagicode.json +32 -32
  89. package/data/comparison-articles/zh-CN/junie-vs-hagicode.json +19 -19
  90. package/data/comparison-articles/zh-CN/kimi-vs-hagicode.json +25 -25
  91. package/data/comparison-articles/zh-CN/kiro-vs-hagicode.json +26 -26
  92. package/data/comparison-articles/zh-CN/omp-vs-hagicode.json +1 -1
  93. package/data/comparison-articles/zh-CN/pi-vs-hagicode.json +1 -1
  94. package/data/comparison-articles/zh-CN/qoder-vs-hagicode.json +45 -45
  95. package/data/comparison-articles/zh-CN/reasonix-vs-hagicode.json +1 -1
  96. package/data/comparison-articles/zh-Hant/claude-vs-hagicode.json +1 -1
  97. package/data/comparison-articles/zh-Hant/codebuddy-vs-hagicode.json +11 -11
  98. package/data/comparison-articles/zh-Hant/codex-vs-hagicode.json +6 -6
  99. package/data/comparison-articles/zh-Hant/copilot-vs-hagicode.json +2 -2
  100. package/data/comparison-articles/zh-Hant/gemini-vs-hagicode.json +16 -16
  101. package/data/comparison-articles/zh-Hant/kimi-vs-hagicode.json +16 -16
  102. package/data/comparison-articles/zh-Hant/kiro-vs-hagicode.json +13 -13
  103. package/data/comparison-articles/zh-Hant/pi-vs-hagicode.json +11 -11
  104. package/data/comparison-articles/zh-Hant/qoder-vs-hagicode.json +12 -12
  105. package/data/comparison-articles/zh-Hant/reasonix-vs-hagicode.json +11 -11
  106. package/dist/posthog.d.ts +6 -0
  107. package/dist/posthog.js +17 -0
  108. package/dist/root-transit.d.ts +12 -0
  109. package/dist/root-transit.js +104 -0
  110. package/dist/site-metadata-ownership.d.ts +40 -0
  111. package/dist/site-metadata-ownership.js +72 -0
  112. package/dist/site-metadata-writer.d.ts +25 -0
  113. package/dist/site-metadata-writer.js +55 -0
  114. package/dist/site-metadata.d.ts +113 -0
  115. package/dist/site-metadata.js +256 -0
  116. package/package.json +23 -1
package/PostHog.astro ADDED
@@ -0,0 +1,11 @@
1
+ ---
2
+ import { posthogInitScript } from './dist/posthog.js';
3
+
4
+ interface Props {
5
+ apiKey?: string;
6
+ }
7
+
8
+ const script = posthogInitScript(Astro.props.apiKey);
9
+ ---
10
+
11
+ {import.meta.env.PROD && <script is:inline set:html={script}></script>}
package/README.md CHANGED
@@ -29,7 +29,7 @@ attribution by itself. Plain-Astro sites that want the literal
29
29
  `@hagicode/hagilight/Footer`; that component reads the exact build-time version
30
30
  from `@hagicode/hagilight`'s own manifest, not from Astro.
31
31
 
32
- Other entry points include `Copyright`, `PromotoBanner`, `GoogleAnalytics`, and `Analytics51LA` Astro components; `links`, `favicon`, `seo`, `seo-schema`, `rss`, `rss-ownership`, `promotions`, and `analytics-events` utilities; and `logo.png` and `favicon.ico` assets. For example:
32
+ Other entry points include `Copyright`, `PromotoBanner`, `GoogleAnalytics`, `PostHog`, and `Analytics51LA` Astro components; `links`, `favicon`, `seo`, `seo-schema`, `rss`, `rss-ownership`, `promotions`, and `analytics-events` utilities; and `logo.png` and `favicon.ico` assets. For example:
33
33
 
34
34
  ```ts
35
35
  import { resolveSiteLinks } from '@hagicode/hagilight-core/links';
@@ -37,6 +37,70 @@ import { resolveSiteLinks } from '@hagicode/hagilight-core/links';
37
37
  const links = resolveSiteLinks('en-US');
38
38
  ```
39
39
 
40
+ ## Root transit (explicit opt-in)
41
+
42
+ Use this full-page component in an Astro root route (`src/pages/index.astro`):
43
+
44
+ ```astro
45
+ ---
46
+ import RootTransit from '@hagicode/hagilight-core/RootTransit';
47
+ ---
48
+ <RootTransit destination="/en-US/" siteName="My site" />
49
+ ```
50
+
51
+ Create the destination page first, for example `src/pages/en-US/index.astro`.
52
+ The component includes the official root transit's layout, dark/light colors,
53
+ system font stacks, outline-to-solid route sweep, beam, staggered trace and
54
+ continuation chip. It bundles its logo and favicon locally; no custom CSS,
55
+ animation setup, feature package, third-party resource or analytics is required.
56
+ The trace shows the actual configured destination, base and origin rather than
57
+ performing the official website's locale detection. Installing core alone never
58
+ changes routes. Consumers that do not import this page keep their current root.
59
+
60
+ `destination` and nonblank `siteName` are required. Optional `locale` (default
61
+ `en-US`), `heading`, `message`, and `continueLabel` supply the site's translated
62
+ copy. `links={[{ destination: '/zh-CN/', label: '简体中文', lang: 'zh-CN' }]}`
63
+ adds native alternative-language links without introducing locale selection or
64
+ storage rules. Named `head` and `footer` slots accept site-owned metadata and
65
+ quick links. Hagilight's demo is an adoption example with English at `/en-US/`
66
+ and Chinese at `/zh-CN/`; its separate Starlight demo does not opt in.
67
+
68
+ The deployment base comes from Astro's `BASE_URL`. Local `en-US/` or `/en-US/`
69
+ is relative to that base; an already based `/manual/en-US/` stays unchanged.
70
+ An absolute HTTP(S) URL must match `Astro.site` (or the request origin if absent)
71
+ and already lie within the base. Missing/blank destinations, external origins,
72
+ unsupported schemes, traversal outside the base and root aliases (including
73
+ `index.html`) throw `TypeError` prefixed `Hagilight RootTransit` during rendering
74
+ or static generation. Choose a supported content route, not the transit root.
75
+ The browser-safe `@hagicode/hagilight-core/root-transit` entry point exposes the
76
+ same destination resolver, navigation resolver, mount helper and interval.
77
+
78
+ After mounting, the page replaces the current history entry after **1,570 ms**:
79
+ the reference's 1,250 ms sweep plus 320 ms hold. Motion preferences suppress
80
+ animation without changing forwarding. The clock does not wait for animation
81
+ events, fonts or images. A normal continuation activation replaces immediately;
82
+ modified clicks retain native behavior. Leaving the document or an Astro
83
+ `astro:before-swap` event cancels the timer; `astro:page-load` mounts a newly
84
+ rendered transit page once. Back therefore does not re-enter an automatic loop.
85
+
86
+ With scripting, incoming search and fragment replace their configured counterparts
87
+ when nonempty, and the continuation anchor and timer share the resulting URL.
88
+ For example, `/manual/?utm=a#features` forwards to
89
+ `/manual/en-US/?utm=a#features`. A `?lang=` or `?next=` value is preserved as data
90
+ and never selects the destination. Without JavaScript (or if the script fails),
91
+ initial HTML still contains the heading, message and a working native link to the
92
+ configured landing page. Static HTML cannot carry a browser-only fragment or
93
+ request query into that link; automatic forwarding requires scripting.
94
+
95
+ Run `node --test test/root-transit.test.mjs` after building for URL/timer checks,
96
+ and `node test/root-transit-browser.mjs` for the minimal-consumer, responsive,
97
+ no-script, reduced-motion, base and history checks.
98
+ The latter also runs through `npm run test:viewport`. To compare a locally built
99
+ reference without changing it, set `HAGILIGHT_TRANSIT_REFERENCE_DIR` to the
100
+ official site's `dist` directory. Matching 1440/375 px captures at 625/1,250 ms
101
+ are written to `HAGILIGHT_ARTIFACT_DIR` (default `/tmp/hagilight-root-transit`),
102
+ alongside 320/375/1440 px light/dark, minimal-consumer and base-path captures.
103
+
40
104
  ## Build info
41
105
 
42
106
  `@hagicode/hagilight-core/build-info` is browser-safe. It exports the `BuildInfo` type, `normalizeBuildInfo`, `shortCommit`, and `buildInfoItems`, which turn a resolved value into the footer's Branch, Commit, and Built items. `@hagicode/hagilight-core/build-info-resolver` is Node-only: `resolveBuildInfo({ root, env, now })` reads the value for one project. Keep Node-only code out of any module that a browser bundle imports.
@@ -53,6 +117,57 @@ After trimming, `HAGILIGHT_BUILD_BRANCH` must be nonblank and free of control ch
53
117
 
54
118
  The footer shows the commit as its first seven characters, with the full hash in the `title` attribute. The core `Footer` renders this line only when it receives a `buildInfo` prop or the `hagilight()` integration from `@hagicode/hagilight/integration` is registered; otherwise it renders no build text.
55
119
 
120
+ ## Site metadata file
121
+
122
+ The integrations write `.well-known/hagilight.metadata.json` into the build output. This module owns the contract, so the three packages cannot drift apart.
123
+
124
+ - `@hagicode/hagilight-core/site-metadata` is browser-safe. It exports `SITE_METADATA_PATH` (`.well-known/hagilight.metadata.json`, the only place the path is spelled), `buildSiteMetadata`, `validateSiteMetadata` (returns a list of problems; empty means valid), `serializeSiteMetadata` (minified, fixed key order, trailing newline), `detectAnalyticsLoaders` (checks built HTML for each provider's loader markers), `ANALYTICS_LOADER_MARKERS`, and `resolveSiteMetadataOption` (the shared `metadata` option resolver).
125
+ - `@hagicode/hagilight-core/site-metadata-writer` is Node-only. `findDiscoveryOutputs(outDir)` reports which discovery files the build produced, and `writeSiteMetadata({ outDir, metadata, siteOwnedFiles, logger })` writes the file through a temporary file and a rename. An existing file, in the output or in `siteOwnedFiles`, is kept and reported.
126
+ - `@hagicode/hagilight-core/site-metadata-ownership` decides which integration writes the file when plain Astro and Starlight are both registered. Starlight claims at plugin creation, plain Astro defers, and the owner's write runs after every deferring peer has reported its build step.
127
+
128
+ The file follows `schemaVersion: 1`. Fields may be added within version 1. Renaming, removing, or re-typing a field requires a new version.
129
+
130
+ ```json
131
+ {
132
+ "schemaVersion": 1,
133
+ "generator": { "name": "@hagicode/hagilight-starlight", "version": "0.1.0" },
134
+ "site": {
135
+ "name": "HagiCode Docs",
136
+ "url": "https://docs.hagicode.com/",
137
+ "base": "/",
138
+ "description": "Documentation for HagiCode."
139
+ },
140
+ "languages": {
141
+ "default": "en-US",
142
+ "locales": [
143
+ { "code": "en-US", "lang": "en-US", "path": "/" },
144
+ { "code": "zh-CN", "lang": "zh-CN", "path": "/zh-CN/" }
145
+ ]
146
+ },
147
+ "build": {
148
+ "branch": "main",
149
+ "commit": "a1b2c3d4e5f60718293a4b5c6d7e8f9012345678",
150
+ "builtAt": "2026-10-17T08:12:34Z"
151
+ },
152
+ "discovery": {
153
+ "sitemap": "/sitemap-index.xml",
154
+ "robots": "/robots.txt",
155
+ "rss": "/rss.xml",
156
+ "llms": "/llms.txt"
157
+ },
158
+ "analytics": { "googleAnalytics": true, "fiftyOneLa": false, "posthog": true },
159
+ "features": { "seo": true, "promoto": true }
160
+ }
161
+ ```
162
+
163
+ Rules that every writer applies:
164
+
165
+ - `site.name` comes from the `name` option, then the site's own title, then the home page name, then the URL hostname. `site.description` is omitted when no description exists.
166
+ - `build` holds the same branch, commit, and build time as the footer, with `unknown` for any value that cannot be resolved.
167
+ - `discovery` holds site-relative paths, relative to `site.base`, for the artifacts that exist in this build. A key is absent when its file is absent.
168
+ - `analytics` holds three booleans that say whether each provider's loader is in this build. Measurement IDs, 51LA site IDs, and PostHog keys are never written, and neither are environment values, absolute paths, or Git remotes.
169
+ - Only the schema fields are copied from typed inputs, so an extra input field cannot leak into the output.
170
+
56
171
  ## Comparison articles
57
172
 
58
173
  Core ships the 136 `*-vs-hagicode` comparison articles (10 locales) as JSON under `data/comparison-articles/<locale>/<slug>.json`. The files are the `1.0.0` structured-article schema, unchanged from the source they moved from. Two entry points split the API by runtime, following the build-info split:
@@ -168,6 +283,44 @@ Decision, recorded 2026-10-15 under the `first-party-link-policy-and-attribution
168
283
  - Constraints that any future linker must respect: one `gtag('config', id)` call per page, so a `linker` setting is added to that single call in `GoogleAnalytics.astro`; the sites with their own inline `gtag` copies would each need the same change; and `_gl` must never reach canonical or sitemap URLs.
169
284
  - Revisit this decision when a HagiCode-owned site runs the shared `gtag` on a registrable domain other than `hagicode.com`, or when a first-party destination on another domain also runs HagiCode's `gtag` and needs session continuity. Then list the host, add it to the linker in the single `config` call, and update the GA reference document, which lives in the monorepo root and needs its owner's follow-up edit.
170
285
 
286
+ ## PostHog
287
+
288
+ Render the component once in the global layout's `<head>`, alongside Google Analytics when configured:
289
+
290
+ ```astro
291
+ ---
292
+ import PostHog from '@hagicode/hagilight-core/PostHog';
293
+ import GoogleAnalytics from '@hagicode/hagilight-core/GoogleAnalytics';
294
+ ---
295
+ <html>
296
+ <head>
297
+ <PostHog />
298
+ <GoogleAnalytics measurementId="G-EN03FMT2Q4" />
299
+ </head>
300
+ <body><slot /></body>
301
+ </html>
302
+ ```
303
+
304
+ `<PostHog />` needs no enabled flag or project key. It uses `phc_qiVVihsL925ovhPYNdLJWz4k7aoKVMwYCevgZPE6PER5`, API host `https://us.i.posthog.com`, and SDK defaults `2026-05-30`. It emits no loader or initialization outside production. The SDK is loaded asynchronously with anonymous cross-origin mode from `https://us-assets.i.posthog.com/static/array.js`.
305
+
306
+ For a different project, pass `<PostHog apiKey="phc_Custom123" />`. Keys must match `^phc_[A-Za-z0-9]+$`; invalid values fail rendering before a script is emitted. The host and defaults version stay fixed.
307
+
308
+ Non-Astro integrations can import the browser-safe ESM generator and its declarations without installing Astro:
309
+
310
+ ```ts
311
+ import {
312
+ posthogInitScript,
313
+ DEFAULT_POSTHOG_API_KEY,
314
+ POSTHOG_API_HOST,
315
+ POSTHOG_DEFAULTS,
316
+ POSTHOG_API_KEY_PATTERN,
317
+ } from '@hagicode/hagilight-core/posthog';
318
+
319
+ const script = posthogInitScript(); // optional custom key as the only argument
320
+ ```
321
+
322
+ Initialization runs once per document, including when the script is re-executed before or after the SDK loads. Fresh documents initialize independently. SDK defaults own navigation tracking; Hagilight adds no PostHog capture calls or route listeners. Choose one initialization owner: omit this component when another integration initializes PostHog, or disable the plugin provider when composing it yourself. The plain Astro integration does not inject analytics automatically; the demo composes this component in its shared head (and in its transit page's head slot).
323
+
171
324
  ## Google Analytics click events
172
325
 
173
326
  `GoogleAnalytics` also reports clicks on the key links and download buttons that the shared components render. There is nothing to configure: events follow the same rules as page views, so they are sent only on production pages where Google Analytics is enabled, never on the Starlight 404 page, and silently skipped when `gtag` is missing (development builds, blocked scripts).