@documental-xyz/core 0.1.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.
Files changed (114) hide show
  1. package/README.md +424 -0
  2. package/integration.ts +113 -0
  3. package/package.json +83 -0
  4. package/src/admin/admin.astro +29 -0
  5. package/src/assets/scripts/App.js +70 -0
  6. package/src/assets/scripts/EnteringAnimations.js +34 -0
  7. package/src/assets/scripts/MapBoxHandler.js +680 -0
  8. package/src/assets/scripts/ScrollProgressionBar.js +24 -0
  9. package/src/assets/scripts/utils/ScrollObserver.js +166 -0
  10. package/src/assets/styles/config/_breakpoints.scss +37 -0
  11. package/src/assets/styles/config/_colors.scss +8 -0
  12. package/src/assets/styles/config/_config.scss +5 -0
  13. package/src/assets/styles/config/_functions.scss +90 -0
  14. package/src/assets/styles/config/_grrr.configs.scss +7 -0
  15. package/src/assets/styles/config/_mixins.scss +207 -0
  16. package/src/assets/styles/config/_type.scss +175 -0
  17. package/src/assets/styles/config/_vars.scss +16 -0
  18. package/src/assets/styles/globals/_content.scss +47 -0
  19. package/src/assets/styles/globals/_grrr.scss +18 -0
  20. package/src/assets/styles/globals/_html.scss +25 -0
  21. package/src/assets/styles/globals/_lists.scss +19 -0
  22. package/src/assets/styles/globals/_map-anchors.scss +32 -0
  23. package/src/assets/styles/globals/_reset.scss +240 -0
  24. package/src/assets/styles/globals/_reveal-animations.scss +104 -0
  25. package/src/assets/styles/globals/_root.scss +6 -0
  26. package/src/assets/styles/globals/_scroll-progression-bar.scss +8 -0
  27. package/src/assets/styles/main.scss +17 -0
  28. package/src/assets/styles/utils/.gitkeep +0 -0
  29. package/src/assets/styles/utils/grrr/_grrr.scss +433 -0
  30. package/src/assets/styles/utils/list-styles/_list-styles.scss +190 -0
  31. package/src/components/AnimationToggle.astro +19 -0
  32. package/src/components/BigNumbers.astro +83 -0
  33. package/src/components/Button.astro +49 -0
  34. package/src/components/Caption.astro +15 -0
  35. package/src/components/Card.astro +68 -0
  36. package/src/components/Cards.astro +66 -0
  37. package/src/components/CardsCall.astro +125 -0
  38. package/src/components/ChartBar.astro +217 -0
  39. package/src/components/ChartPercentage.astro +137 -0
  40. package/src/components/Column.astro +54 -0
  41. package/src/components/ColumnSticky.astro +129 -0
  42. package/src/components/Columns.astro +139 -0
  43. package/src/components/Compare.astro +266 -0
  44. package/src/components/Cta.astro +242 -0
  45. package/src/components/Gallery.astro +594 -0
  46. package/src/components/Group.astro +140 -0
  47. package/src/components/HtmlEmbed.astro +98 -0
  48. package/src/components/ImageBlock.astro +134 -0
  49. package/src/components/InnerColumns.astro +54 -0
  50. package/src/components/LogosGroup.astro +102 -0
  51. package/src/components/Map.astro +321 -0
  52. package/src/components/MapBox.astro +96 -0
  53. package/src/components/MapView.astro +30 -0
  54. package/src/components/Menu.astro +278 -0
  55. package/src/components/Pullquote.astro +46 -0
  56. package/src/components/Slider.astro +223 -0
  57. package/src/components/Spacer.astro +25 -0
  58. package/src/components/Text.astro +173 -0
  59. package/src/components/TextPlaceholder.astro +98 -0
  60. package/src/components/Timeline.astro +73 -0
  61. package/src/components/TimelineBullet.astro +67 -0
  62. package/src/components/VideoEmbed.astro +99 -0
  63. package/src/content/loader.ts +29 -0
  64. package/src/content/pages/alter-ameacada.md +80 -0
  65. package/src/content/pages/expulsions.md +1447 -0
  66. package/src/content/pages/home.md +346 -0
  67. package/src/content/pages/nhanderekoa-studio-autonoma.md +3113 -0
  68. package/src/content/pages/nhanderekoa-terra-ind/303/255gena-jaragu/303/241.md +3806 -0
  69. package/src/content/pages/nova-landing-page.md +546 -0
  70. package/src/content/pages/territ/303/263rios-de-exce/303/247/303/243o.md +2199 -0
  71. package/src/content/pages/teste-alter-do-chao.md +955 -0
  72. package/src/content/pages/teste-layout.md +1484 -0
  73. package/src/content/pages/thiago.md +93 -0
  74. package/src/content/schema/blog.ts +11 -0
  75. package/src/content/schema/geostorys.ts +13 -0
  76. package/src/content/schema/index.ts +3 -0
  77. package/src/content/schema/pages.ts +494 -0
  78. package/src/content.config.ts +49 -0
  79. package/src/env.d.ts +1 -0
  80. package/src/integration/override-aliases.ts +67 -0
  81. package/src/layouts/components/ButtonLayout.astro +8 -0
  82. package/src/layouts/components/CardLayout.astro +8 -0
  83. package/src/layouts/components/CardsCallLayout.astro +26 -0
  84. package/src/layouts/components/CardsLayout.astro +14 -0
  85. package/src/layouts/components/ChartBarLayout.astro +21 -0
  86. package/src/layouts/components/ChartPercentageLayout.astro +17 -0
  87. package/src/layouts/components/ColumnLayout.astro +11 -0
  88. package/src/layouts/components/ColumnStickyLayout.astro +10 -0
  89. package/src/layouts/components/ColumnsLayout.astro +13 -0
  90. package/src/layouts/components/CompareLayout.astro +22 -0
  91. package/src/layouts/components/CtaLayout.astro +91 -0
  92. package/src/layouts/components/GalleryLayout.astro +24 -0
  93. package/src/layouts/components/GroupLayout.astro +53 -0
  94. package/src/layouts/components/HtmlEmbedLayout.astro +18 -0
  95. package/src/layouts/components/ImageBlockLayout.astro +20 -0
  96. package/src/layouts/components/InnerColumnsLayout.astro +14 -0
  97. package/src/layouts/components/LogosGroupLayout.astro +22 -0
  98. package/src/layouts/components/MapLayout.astro +41 -0
  99. package/src/layouts/components/MapViewLayout.astro +8 -0
  100. package/src/layouts/components/MapboxLayout.astro +248 -0
  101. package/src/layouts/components/PullquoteLayout.astro +13 -0
  102. package/src/layouts/components/SliderLayout.astro +18 -0
  103. package/src/layouts/components/SpacerLayout.astro +8 -0
  104. package/src/layouts/components/TextLayout.astro +17 -0
  105. package/src/layouts/components/TextPlaceholderLayout.astro +7 -0
  106. package/src/layouts/components/TimelineBulletLayout.astro +14 -0
  107. package/src/layouts/components/TimelineLayout.astro +10 -0
  108. package/src/layouts/components/VideoEmbedLayout.astro +28 -0
  109. package/src/layouts/pages/Layout.astro +90 -0
  110. package/src/layouts/pages/PageLayout.astro +200 -0
  111. package/src/lib/collections.ts +1 -0
  112. package/src/routes/[slug].astro +17 -0
  113. package/src/routes/index.astro +5 -0
  114. package/src/vite/yaml-merge-plugin.ts +234 -0
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Vite plugin: merges Sveltia CMS YAML config fragments into a single
3
+ * `public/admin/config.yml`, substituting placeholders from integration
4
+ * options.
5
+ *
6
+ * ## Why text-concatenation, not parse-then-merge?
7
+ *
8
+ * The YAML fragments in `public/admin/config/components/*.yml` define anchors
9
+ * (e.g. `&pageSettings`) that are aliased (`*pageSettings`) by the collections
10
+ * fragments in `public/admin/config/collections/*.yml`. Anchors only resolve
11
+ * within a single YAML document. The predecessor `vite.config.mjs` plugin had
12
+ * a bug: it parsed each file independently (`mergedConfig = { ...mergedConfig,
13
+ * ...parsed }`), which (a) shallow-merged and (b) dropped all cross-file
14
+ * anchor resolution.
15
+ *
16
+ * The correct approach — inherited from the now-deleted `build-config.js` —
17
+ * is to concatenate the fragment texts in order into one YAML stream, then
18
+ * let `js-yaml` resolve anchors across the whole stream in a single pass.
19
+ * Because each fragment contributes distinct top-level keys, the resulting
20
+ * document is the deep union of all fragments. Placeholders are substituted
21
+ * on the final concatenated text before parse.
22
+ *
23
+ * @packageDocumentation
24
+ */
25
+
26
+ import { glob } from 'glob';
27
+ import fs from 'node:fs';
28
+ import path from 'node:path';
29
+ import { fileURLToPath } from 'node:url';
30
+ import yaml from 'js-yaml';
31
+
32
+ /**
33
+ * Root of the @documental-xyz/core package, resolved from this module's
34
+ * location. Template YAML files (main.yml.template, components/, collections/)
35
+ * live under `public/admin/config/` relative to this root. The output
36
+ * `config.yml` is written to the consumer's `public/admin/`.
37
+ */
38
+ const CORE_ROOT = path.resolve(
39
+ path.dirname(fileURLToPath(import.meta.url)),
40
+ '../..'
41
+ );
42
+
43
+ /** Options for {@link createYamlMergePlugin}. */
44
+ export interface YamlMergePluginOptions {
45
+ /** GitHub repo in `owner/name` form. Required. Substitutes `${REPO}`. */
46
+ repo: string;
47
+ /** Git branch. Defaults to `'main'`. Substitutes `${BRANCH}`. */
48
+ branch?: string;
49
+ /** Auth base URL for Sveltia auth. Substitutes `${AUTH_BASE_URL}`. */
50
+ authBaseUrl?: string;
51
+ /** CMS media_folder. Defaults to `'public/uploads'`. Substitutes `${MEDIA_FOLDER}`. */
52
+ mediaFolder?: string;
53
+ /** CMS public_folder. Defaults to `'uploads'`. Substitutes `${PUBLIC_FOLDER}`. */
54
+ publicFolder?: string;
55
+ /**
56
+ * Override the core package root for template resolution.
57
+ * Defaults to `CORE_ROOT` (resolved from this module's location).
58
+ * Only needed in tests or unusual consumption scenarios.
59
+ */
60
+ coreRoot?: string;
61
+ }
62
+
63
+ /** Resolved options after defaults applied. */
64
+ interface ResolvedOptions {
65
+ repo: string;
66
+ branch: string;
67
+ authBaseUrl: string;
68
+ mediaFolder: string;
69
+ publicFolder: string;
70
+ coreRoot: string;
71
+ }
72
+
73
+ /** Default option values — kept here so tests can reference them too. */
74
+ export const YAML_MERGE_DEFAULTS = {
75
+ branch: 'main',
76
+ mediaFolder: 'public/uploads',
77
+ publicFolder: 'uploads',
78
+ } as const;
79
+
80
+ function resolveOptions(opts: YamlMergePluginOptions): ResolvedOptions {
81
+ if (!opts || typeof opts.repo !== 'string' || opts.repo.length === 0) {
82
+ throw new Error(
83
+ '[documental-yaml-merge] option `repo` is required (e.g. "owner/name").'
84
+ );
85
+ }
86
+ return {
87
+ repo: opts.repo,
88
+ branch: opts.branch ?? YAML_MERGE_DEFAULTS.branch,
89
+ authBaseUrl: opts.authBaseUrl ?? '',
90
+ mediaFolder: opts.mediaFolder ?? YAML_MERGE_DEFAULTS.mediaFolder,
91
+ publicFolder: opts.publicFolder ?? YAML_MERGE_DEFAULTS.publicFolder,
92
+ coreRoot: opts.coreRoot ?? CORE_ROOT,
93
+ };
94
+ }
95
+
96
+ /**
97
+ * Substitute `${PLACEHOLDER}` tokens in `text` using `values`.
98
+ * Unknown placeholders are left untouched (they may be intended for a later
99
+ * substitution pass, e.g. user-authored content).
100
+ */
101
+ export function substitutePlaceholders(
102
+ text: string,
103
+ values: Record<string, string>
104
+ ): string {
105
+ return text.replace(/\$\{([A-Z_][A-Z0-9_]*)\}/g, (match, name) =>
106
+ Object.prototype.hasOwnProperty.call(values, name) ? values[name] : match
107
+ );
108
+ }
109
+
110
+ /** Read a file, returning empty string if it does not exist. */
111
+ function readIfExists(p: string): string | null {
112
+ try {
113
+ return fs.readFileSync(p, 'utf8');
114
+ } catch {
115
+ return null;
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Build the merged YAML text by concatenating fragments in the canonical
121
+ * order: main (template preferred) → components (per `components.yml`) →
122
+ * collections (alphabetical).
123
+ *
124
+ * Exposed for testability.
125
+ */
126
+ export async function buildMergedYamlText(
127
+ projectRoot: string,
128
+ resolved: ResolvedOptions
129
+ ): Promise<string> {
130
+ const adminDir = path.join(resolved.coreRoot, 'public/admin');
131
+ const configDir = path.join(adminDir, 'config');
132
+
133
+ // 1. Main config — prefer T7's template, fall back to static main.yml.
134
+ const templatePath = path.join(configDir, 'main.yml.template');
135
+ const mainPath = path.join(configDir, 'main.yml');
136
+ const mainRaw =
137
+ readIfExists(templatePath) ?? readIfExists(mainPath) ?? '';
138
+ if (mainRaw === '') {
139
+ throw new Error(
140
+ `[documental-yaml-merge] no main config found: expected ${templatePath} or ${mainPath}.`
141
+ );
142
+ }
143
+
144
+ // 2. Components in the order declared by components.yml.
145
+ const componentsManifestPath = path.join(adminDir, 'components.yml');
146
+ const componentsManifestRaw = readIfExists(componentsManifestPath);
147
+ let componentOrder: string[] = [];
148
+ if (componentsManifestRaw) {
149
+ const manifest = yaml.load(componentsManifestRaw) as {
150
+ components?: string[];
151
+ };
152
+ componentOrder = Array.isArray(manifest?.components)
153
+ ? (manifest!.components as string[])
154
+ : [];
155
+ }
156
+
157
+ // 3. Collections (alphabetical — matches original build-config.js behavior).
158
+ const collectionFiles = await glob(
159
+ path.join(configDir, 'collections/*.yml').replace(/\\/g, '/')
160
+ );
161
+ collectionFiles.sort();
162
+
163
+ // Concatenate everything into one YAML stream. Trailing newline separators
164
+ // keep top-level keys from adjacent fragments on distinct document lines.
165
+ const parts: string[] = [];
166
+ parts.push(mainRaw.replace(/\s+$/, ''));
167
+ for (const rel of componentOrder) {
168
+ const full = path.join(configDir, rel);
169
+ const content = readIfExists(full);
170
+ if (content === null) {
171
+ console.warn(
172
+ `[documental-yaml-merge] component file listed in components.yml not found: ${rel}`
173
+ );
174
+ continue;
175
+ }
176
+ parts.push(content.replace(/\s+$/, ''));
177
+ }
178
+ for (const file of collectionFiles) {
179
+ const content = readIfExists(file);
180
+ if (content === null) continue;
181
+ parts.push(content.replace(/\s+$/, ''));
182
+ }
183
+
184
+ const concatenated = parts.join('\n') + '\n';
185
+
186
+ // Substitute placeholders on the merged text. Substituting AFTER concat
187
+ // (rather than only on main.yml) keeps the door open to placeholders in any
188
+ // fragment — harmless when none are present.
189
+ return substitutePlaceholders(concatenated, {
190
+ REPO: resolved.repo,
191
+ BRANCH: resolved.branch,
192
+ AUTH_BASE_URL: resolved.authBaseUrl,
193
+ MEDIA_FOLDER: resolved.mediaFolder,
194
+ PUBLIC_FOLDER: resolved.publicFolder,
195
+ });
196
+ }
197
+
198
+ /**
199
+ * Create a Vite plugin that merges Sveltia CMS YAML fragments into
200
+ * `public/admin/config.yml` at build-start. Runs in BOTH `dev` and `build`.
201
+ */
202
+ export function createYamlMergePlugin(options: YamlMergePluginOptions): {
203
+ name: string;
204
+ buildStart: () => Promise<void>;
205
+ } {
206
+ const resolved = resolveOptions(options);
207
+
208
+ return {
209
+ name: 'documental-yaml-merge',
210
+ async buildStart() {
211
+ const projectRoot = process.cwd();
212
+ const mergedText = await buildMergedYamlText(projectRoot, resolved);
213
+
214
+ // Sanity: the merged stream must parse cleanly (catches broken anchors).
215
+ // We discard the parsed value — the artifact is the text itself, to
216
+ // preserve comments, anchor definitions, and original formatting.
217
+ try {
218
+ yaml.load(mergedText, { schema: yaml.DEFAULT_FULL_SCHEMA });
219
+ } catch (err) {
220
+ throw new Error(
221
+ `[documental-yaml-merge] merged config failed to parse: ${(err as Error).message}`
222
+ );
223
+ }
224
+
225
+ const outDir = path.join(projectRoot, 'public/admin');
226
+ if (!fs.existsSync(outDir)) {
227
+ fs.mkdirSync(outDir, { recursive: true });
228
+ }
229
+ fs.writeFileSync(path.join(outDir, 'config.yml'), mergedText);
230
+ },
231
+ };
232
+ }
233
+
234
+ export default createYamlMergePlugin;