@supersoniks/concorde 5.0.3 → 5.0.5

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 (151) hide show
  1. package/.agents/skills/concorde-component-docs/SKILL.md +194 -0
  2. package/.agents/skills/concorde-component-docs/template.md +45 -0
  3. package/ai/cursor/rules/concorde-theme.mdc +1 -1
  4. package/ai/cursor/rules/concorde.mdc +1 -1
  5. package/ai/skills/concorde/SKILL.md +1 -1
  6. package/ai/skills/concorde-theme/SKILL.md +21 -10
  7. package/build-infos.json +1 -1
  8. package/concorde-core.bundle.js +515 -521
  9. package/concorde-core.es.js +5151 -5056
  10. package/dist/concorde-core.bundle.js +515 -521
  11. package/dist/concorde-core.es.js +5151 -5056
  12. package/dist/docs-mock-api-sw.js +2 -0
  13. package/dist/docs-mock-api-sw.js.map +2 -2
  14. package/docs/assets/index-CD4WyL6o.css +1 -0
  15. package/docs/assets/{index-BnK6OS7w.js → index-wVZpLVYW.js} +815 -808
  16. package/docs/crawl/core/components/ui/alert/alert.html +76 -5
  17. package/docs/crawl/core/components/ui/alert-messages/alert-messages.html +113 -5
  18. package/docs/crawl/core/components/ui/badge/badge.html +57 -8
  19. package/docs/crawl/core/components/ui/captcha/captcha.html +90 -8
  20. package/docs/crawl/core/components/ui/card/card.html +122 -12
  21. package/docs/crawl/core/components/ui/divider/divider.html +117 -31
  22. package/docs/crawl/core/components/ui/form/fieldset/fieldset.html +232 -101
  23. package/docs/crawl/core/components/ui/form/form-actions/form-actions.html +95 -52
  24. package/docs/crawl/core/components/ui/form/form-layout/form-layout.html +97 -38
  25. package/docs/crawl/core/components/ui/group/group.html +60 -38
  26. package/docs/crawl/core/components/ui/icon/icon.html +136 -47
  27. package/docs/crawl/core/components/ui/image/image.html +118 -6
  28. package/docs/crawl/core/components/ui/link/link.html +65 -7
  29. package/docs/crawl/core/components/ui/loader/loader.html +97 -23
  30. package/docs/crawl/core/components/ui/menu/menu.html +162 -90
  31. package/docs/crawl/core/components/ui/modal/modal.html +275 -50
  32. package/docs/crawl/core/components/ui/pop/pop.html +242 -124
  33. package/docs/crawl/core/components/ui/progress/progress.html +103 -30
  34. package/docs/crawl/core/components/ui/table/table.html +303 -171
  35. package/docs/crawl/core/components/ui/theme/theme.html +131 -0
  36. package/docs/crawl/core/components/ui/toast/toast.html +170 -59
  37. package/docs/crawl/core/components/ui/tooltip/tooltip.html +90 -29
  38. package/docs/crawl/docs/_decorators/ancestor-attribute.html +3 -2
  39. package/docs/crawl/docs/_getting-started/start.html +1 -1
  40. package/docs/crawl/docs/_getting-started/theming.html +311 -63
  41. package/docs/crawl/hubs/form-components.html +71 -49
  42. package/docs/crawl/index.html +7 -6
  43. package/docs/docs-mock-api-sw.js +2 -0
  44. package/docs/docs-mock-api-sw.js.map +2 -2
  45. package/docs/index.html +6 -4
  46. package/docs/llms-full.txt +1468 -405
  47. package/docs/llms.txt +23 -30
  48. package/docs/sitemap.xml +3 -0
  49. package/docs/src/core/components/ui/alert/alert.md +21 -2
  50. package/docs/src/core/components/ui/alert-messages/alert-messages.md +85 -0
  51. package/docs/src/core/components/ui/badge/badge.md +19 -6
  52. package/docs/src/core/components/ui/captcha/captcha.md +65 -6
  53. package/docs/src/core/components/ui/card/card.md +73 -10
  54. package/docs/src/core/components/ui/divider/divider.md +107 -13
  55. package/docs/src/core/components/ui/form/fieldset/fieldset.md +175 -99
  56. package/docs/src/core/components/ui/form/form-actions/form-actions.md +75 -52
  57. package/docs/src/core/components/ui/form/form-layout/form-layout.md +109 -34
  58. package/docs/src/core/components/ui/group/group.md +36 -36
  59. package/docs/src/core/components/ui/icon/icon.md +132 -43
  60. package/docs/src/core/components/ui/image/image.md +35 -3
  61. package/docs/src/core/components/ui/link/link.md +43 -5
  62. package/docs/src/core/components/ui/loader/loader.md +79 -22
  63. package/docs/src/core/components/ui/menu/menu.md +133 -92
  64. package/docs/src/core/components/ui/modal/modal.md +163 -47
  65. package/docs/src/core/components/ui/pop/pop.md +217 -123
  66. package/docs/src/core/components/ui/progress/progress.md +76 -30
  67. package/docs/src/core/components/ui/table/table.md +147 -171
  68. package/docs/src/core/components/ui/theme/theme.md +122 -0
  69. package/docs/src/core/components/ui/toast/toast.md +108 -58
  70. package/docs/src/core/components/ui/tooltip/tooltip.md +68 -26
  71. package/docs/src/docs/_decorators/ancestor-attribute.md +3 -2
  72. package/docs/src/docs/_getting-started/start.md +1 -1
  73. package/docs/src/docs/_getting-started/theming.md +223 -61
  74. package/docs/src/docs/search/docs-search.json +2504 -399
  75. package/docs/src/tsconfig.json +18 -0
  76. package/index.html +4 -2
  77. package/package.json +7 -1
  78. package/public/docs-mock-api-sw.js +2 -0
  79. package/public/docs-mock-api-sw.js.map +2 -2
  80. package/src/core/components/ui/_css/align.ts +1 -0
  81. package/src/core/components/ui/_css/type.ts +86 -8
  82. package/src/core/components/ui/_i18n/ui-aria-labels.ts +8 -0
  83. package/src/core/components/ui/alert/alert.md +21 -2
  84. package/src/core/components/ui/alert-messages/alert-messages.md +85 -0
  85. package/src/core/components/ui/badge/badge.md +19 -6
  86. package/src/core/components/ui/badge/badge.ts +8 -9
  87. package/src/core/components/ui/button/button.ts +5 -15
  88. package/src/core/components/ui/captcha/captcha.md +65 -6
  89. package/src/core/components/ui/card/card.md +73 -10
  90. package/src/core/components/ui/card/card.ts +24 -22
  91. package/src/core/components/ui/divider/divider.md +107 -13
  92. package/src/core/components/ui/divider/divider.ts +40 -33
  93. package/src/core/components/ui/form/fieldset/fieldset.md +175 -99
  94. package/src/core/components/ui/form/fieldset/fieldset.ts +15 -28
  95. package/src/core/components/ui/form/fieldset/legend.ts +13 -13
  96. package/src/core/components/ui/form/form-actions/form-actions.md +75 -52
  97. package/src/core/components/ui/form/form-actions/form-actions.ts +7 -5
  98. package/src/core/components/ui/form/form-layout/form-layout.md +109 -34
  99. package/src/core/components/ui/form/form-layout/form-layout.ts +27 -24
  100. package/src/core/components/ui/form/textarea/textarea.ts +4 -3
  101. package/src/core/components/ui/group/group.md +36 -36
  102. package/src/core/components/ui/group/group.ts +5 -10
  103. package/src/core/components/ui/icon/icon.md +132 -43
  104. package/src/core/components/ui/image/image.md +35 -3
  105. package/src/core/components/ui/link/link.md +43 -5
  106. package/src/core/components/ui/loader/loader.md +79 -22
  107. package/src/core/components/ui/loader/loader.ts +67 -27
  108. package/src/core/components/ui/loader/styles/fixed.ts +6 -11
  109. package/src/core/components/ui/menu/menu.md +133 -92
  110. package/src/core/components/ui/menu/menu.ts +53 -58
  111. package/src/core/components/ui/modal/modal.md +163 -47
  112. package/src/core/components/ui/modal/modal.ts +2 -4
  113. package/src/core/components/ui/pop/pop.md +217 -123
  114. package/src/core/components/ui/pop/pop.ts +0 -1
  115. package/src/core/components/ui/progress/progress.md +76 -30
  116. package/src/core/components/ui/progress/progress.ts +25 -56
  117. package/src/core/components/ui/table/table-caption.ts +2 -2
  118. package/src/core/components/ui/table/table-tbody.ts +3 -3
  119. package/src/core/components/ui/table/table-td.ts +23 -18
  120. package/src/core/components/ui/table/table-th.ts +8 -8
  121. package/src/core/components/ui/table/table-tr.ts +4 -4
  122. package/src/core/components/ui/table/table.md +147 -171
  123. package/src/core/components/ui/table/table.ts +20 -19
  124. package/src/core/components/ui/theme/theme-collection/auto.ts +15 -0
  125. package/src/core/components/ui/theme/theme-collection/core-variables.ts +8 -31
  126. package/src/core/components/ui/theme/theme-collection/dark.ts +1 -7
  127. package/src/core/components/ui/theme/theme-collection/light.ts +30 -26
  128. package/src/core/components/ui/theme/theme.md +122 -0
  129. package/src/core/components/ui/theme/theme.ts +30 -7
  130. package/src/core/components/ui/toast/toast-item.ts +6 -9
  131. package/src/core/components/ui/toast/toast.md +108 -58
  132. package/src/core/components/ui/toast/types.ts +1 -1
  133. package/src/core/components/ui/tooltip/tooltip.md +68 -26
  134. package/src/core/decorators/subscriber/ancestorAttribute.spec.ts +26 -0
  135. package/src/core/decorators/subscriber/ancestorAttribute.ts +3 -4
  136. package/src/core/utils/AncestorAttributeObserver.ts +183 -70
  137. package/src/docs/_decorators/ancestor-attribute.md +3 -2
  138. package/src/docs/_getting-started/start.md +1 -1
  139. package/src/docs/_getting-started/theming.md +223 -61
  140. package/src/docs/code.ts +125 -58
  141. package/src/docs/header/header.ts +62 -54
  142. package/src/docs/mock-api/router.ts +2 -0
  143. package/src/docs/navigation/navigation.ts +6 -3
  144. package/src/docs/search/docs-search.json +2504 -399
  145. package/src/docs/search/markdown-renderer.ts +6 -6
  146. package/src/docs/search/search.ts +4 -4
  147. package/src/docs/tailwind/css/tailwind.css +6 -5
  148. package/src/tsconfig.json +18 -0
  149. package/src/tsconfig.tsbuildinfo +1 -1
  150. package/tailwind.config.js +19 -0
  151. package/docs/assets/index--GpD7R7a.css +0 -1
@@ -1,91 +1,253 @@
1
- # Adding styles
1
+ # Customization
2
2
 
3
- ## Normal Behavior
3
+ ## Theme-first customization
4
4
 
5
- No style crosses the shadow root of a component, except for inheritable properties (which have the "inherit" property possible) and CSS variables.
6
- Properties integrated via a "[slot](https://developer.mozilla.org/en/docs/Web/HTML/Element/slot)" remain stylizable in a conventional way.
5
+ Concorde components ship with **default styles** (fallback values in each component and in `<sonic-theme>`).
6
+ You do not need to define any CSS variables to get a usable UI.
7
7
 
8
- - **During creation / from the inside:**
9
- - We edit the [static "styles" property of the lit component](https://lit.dev/docs/components/styles/), which can also reference shared and dynamic styles.
10
- These styles are scoped and do not impact the outside.
11
- - We use CSS variables as the value of properties intended to be customized from the outside.
12
- For each variable, we define a default value to have a simple but consistent base style.
13
- - We only rewrite inheritable properties with hard values if they are truly specific to the component.
14
- - The `<style>` tag as a direct child can be used as a last resort, especially if there is a need for particularly dynamic customization. Performance is reduced.
15
- - **During use / from the outside:**
16
- We define values for **inheritable CSS properties** (e.g., font-\_, color...) using tools like Tailwind.
17
- We modify the value of **CSS variables** used by the component.
8
+ To align the kit with your brand, override **only the essential theme tokens** on `<sonic-theme>`, on `:root`, or in a project stylesheet.
9
+ Concorde derives radius steps, button/input rounding, shadows, and most per-component layout from these primitives—**do not copy long lists of derived variables** unless you have a specific need.
18
10
 
19
- ## Choosing Style Presets via Reactive Properties:
11
+ <sonic-code language="html">
12
+ <template>
13
+ <sonic-theme color font class="block bg-base min-h-screen">
14
+ <!-- your app -->
15
+ </sonic-theme>
16
+ </template>
17
+ </sonic-code>
20
18
 
21
- The declaration of reactive properties is useful for selecting a particular configuration that mostly affects a set of properties.
19
+ <sonic-code language="javascript">
20
+ <template>
21
+ import "@supersoniks/concorde/theme";
22
+ </template>
23
+ </sonic-code>
22
24
 
23
- For example, a `size` property (xs, sm, md, xl) will affect margins, font, line heights to align them with the corresponding CSS vars, which can be customized using the methods mentioned earlier if necessary.
25
+ | Attribute | Effect |
26
+ |-----------|--------|
27
+ | *(omit)* \| `theme="custom"` | Default: core tokens + your `--sc-*`; no built-in light/dark palette |
28
+ | `theme="light"` \| `"dark"` \| `"auto"` | Opt-in presets; `auto` follows `prefers-color-scheme` |
29
+ | `class="bg-base block"` (Tailwind) | Page/surface background (`--sc-base`) |
30
+ | `color` | Text color (`--sc-base-content`) |
31
+ | `font` | Base font family/weight (`--sc-font-family-base`, etc.) |
24
32
 
25
- It is recommended to use the `{reflect: true}` property for reactive properties that have an associated style on the `:host()`. For example: `:host([type='primary']){...}`
33
+ Popovers, modals, and toasts mount under the nearest `<sonic-theme>`.
26
34
 
27
- ☢️ **Caution:** Passing class names via reactive properties / HTML attributes of the component should be avoided as it can quickly lead to difficult-to-manage situations.
35
+ ## Customization example
28
36
 
29
- #### CSS "display" Property
37
+ Example (full brand override on `<sonic-theme>` or `:root`). Set every essential token below; derived radii and shadows still come from the theme engine—only `--sc-rounded` is listed here.
30
38
 
31
- By default, the display property is `inline`.
32
- Therefore, be careful to define it according to the needs, as one might mistakenly expect it to be `block` as with a regular `<div>`.
39
+ <sonic-code language="css">
40
+ <template>
41
+ sonic-theme {
42
+ /* Semantic fills */
43
+ --sc-primary: #353429;
44
+ --sc-secondary: #f43f5e;
45
+ --sc-info: #7c3aed;
46
+ --sc-danger: #d71839;
47
+ --sc-warning: #f97316;
48
+ --sc-success: #10b981;
49
+ --sc-contrast: #111;
50
+
51
+ /* Text/icons on semantic fills */
52
+ --sc-primary-content: #fff;
53
+ --sc-secondary-content: #fff;
54
+ --sc-info-content: #fff;
55
+ --sc-danger-content: #fff;
56
+ --sc-warning-content: #fff;
57
+ --sc-success-content: #fff;
58
+ --sc-contrast-content: #fff;
59
+
60
+ /* Neutral fills */
61
+ --sc-base: #fff;
62
+ --sc-base-50: #f6f6f5;
63
+ --sc-base-100: #ededec;
64
+ --sc-base-200: #d7d7d4;
65
+ --sc-base-300: #c8c7c4;
66
+ --sc-base-400: #a8a7a2;
67
+ --sc-base-500: #94938c;
68
+ --sc-base-600: #76756c;
69
+ --sc-base-700: #59584e;
70
+ --sc-base-800: #47463b;
71
+ --sc-base-900: #353429;
72
+
73
+ /* Text/icons on neutral surfaces */
74
+ --sc-base-content: var(--sc-base-900);
75
+
76
+ /* Typography */
77
+ --sc-font-family-base: "Oswald", system-ui, -apple-system, "Segoe UI", Roboto,
78
+ "Helvetica Neue", Arial, sans-serif;
79
+ --sc-headings-font-family: "alternate-gothic-compressed", system-ui, sans-serif;
80
+ --sc-headings-line-height: 1.1;
81
+ --sc-headings-font-weight: bold;
82
+ --sc-headings-text-transform: none;
83
+
84
+ /* Shape (primitive only) */
85
+ --sc-rounded: 0;
86
+
87
+ /* Forms */
88
+ --sc-border-width: 0.2rem;
89
+ --sc-form-height: 2em;
90
+ --sc-input-bg: var(--sc-base);
91
+ --sc-input-color: var(--sc-base-content);
92
+ --sc-input-border-color: var(--sc-input-color);
93
+ --sc-input-active-bg: var(--sc-primary);
94
+ --sc-input-active-color: var(--sc-primary-content);
95
+ --sc-input-active-border-color: var(--sc-primary);
96
+ }
97
+ </template>
98
+ </sonic-code>
33
99
 
34
- ☢️ **Caution:** Defining the `display` property as `contents` may seem attractive at first, but:
100
+ <sonic-button href="https://delanfranchi.github.io/concordecolors/"> Palette generator: concordecolors</sonic-button>
35
101
 
36
- - It almost always leads to the creation of wrappers to style the content (instead of using `:host`).
37
- - It is no longer possible to directly add classes to the component or style it from the outside.
38
- Ultimately, the amount of code to write increases significantly.
39
102
 
40
- ## TAILWIND Functional Classes
103
+ **Without these overrides**, components keep Concorde’s per-component fallbacks. Built-in light/dark palettes apply only when you set `theme="light"`, `theme="dark"`, or `theme="auto"`.
41
104
 
42
- [tailwind](https://tailwindcss.com/) has been integrated into Concorde and is available in scoped components (with Shadow DOM).
43
- To use it, you need to import the following:
105
+ **What we intentionally avoid:** large public `--sc-alert-*` / `--sc-badge-*` APIs or `::part()` styling hooks on most components. Prefer attributes (`type`, `status`, `size`, …) and the theme tokens above.
44
106
 
45
- <sonic-code language="javascript">
46
- <template>
47
- import { tailwind } from "@supersoniks/concorde/la-billetterie/ui/theme/theme";
48
- </template>
49
- </sonic-code>
50
107
 
51
- Then include the `tailwind` style in the static `styles` property of the component:
108
+ ## Only essential CSS variables (public theme API)
52
109
 
53
- <sonic-code language="javascript">
54
- <template>
55
- static styles = [tailwind];
56
- </template>
57
- </sonic-code>
110
+ These are the **smallest set** we recommend customizing. Everything else should stay internal to the theme or to components (`--sc_*` private variables, attributes like `type`, `size`, `variant`).
58
111
 
59
- Finally, use it in the HTML within the render function:
112
+ ### Surfaces and foreground
60
113
 
61
- <sonic-code language="html">
62
- <template>
63
- <p class="m-2">A paragraph with margin</p>
64
- </template>
65
- </sonic-code>
114
+ Tokens **without** a `-content` suffix are **fill / background** colors.
115
+ Tokens **with** `-content` are **text and icons** on top of the matching fill (solid buttons, badges, alerts, etc.).
116
+
117
+ #### Neutral fills
118
+
119
+ | Variable | Role |
120
+ |----------|------|
121
+ | `--sc-base` | Main surface / page background |
122
+ | `--sc-base-50` … `--sc-base-900` | Neutral scale (borders, subtle backgrounds, muted UI) |
123
+
124
+ #### Neutral foreground
125
+
126
+ | Variable | Role |
127
+ |----------|------|
128
+ | `--sc-base-content` | Default body text and icons on neutral surfaces |
66
129
 
67
- The colors from Concorde's theme are referenced in Tailwind's theme.
130
+ #### Semantic fills
68
131
 
69
- ## Operation without Shadow DOM
132
+ | Variable | Role |
133
+ |----------|------|
134
+ | `--sc-primary` | Primary actions, links, emphasis |
135
+ | `--sc-secondary` | Secondary brand accent (when used) |
136
+ | `--sc-info`, `--sc-success`, `--sc-warning`, `--sc-danger` | Status and feedback |
137
+ | `--sc-contrast` | High-contrast fills (e.g. on media) |
70
138
 
71
- ### Usefulness
139
+ #### Semantic foreground
72
140
 
73
- This operation is particularly useful when it comes to **adding behavior to a simple existing element**.
74
- It may also become necessary to establish **compatibility with a traditional JS library**.
141
+ | Variable | Role |
142
+ |----------|------|
143
+ | `--sc-primary-content`, `--sc-secondary-content`, … | Text/icons on the matching semantic **fill** (`--sc-primary`, etc.) |
75
144
 
76
- For example, with a text input:
145
+ ### Shape
77
146
 
78
- - Trigger automatic data or filter update when typing text.
79
- - Automatic formatting.
80
- - Constraints that cannot be handled by native methods.
147
+ | Variable | Role |
148
+ |----------|------|
149
+ | `--sc-rounded` | **Single primitive** corner radius; the theme computes `--sc-rounded-sm`, `--sc-btn-rounded`, `--sc-input-rounded`, etc. |
81
150
 
82
- ### Consequences
151
+ ### Typography
83
152
 
84
- If there is no shadow DOM (see the **noShadowDom** property of **Subscriber**):
153
+ | Variable | Role |
154
+ |----------|------|
155
+ | `--sc-font-family-base` | Body UI text |
156
+ | `--sc-font-weight-base`, `--sc-font-style-base` | Optional |
157
+ | `--sc-headings-font-family`, `--sc-headings-line-height`, `--sc-headings-font-weight`, `--sc-headings-text-transform` | Headings (modal titles, etc.) |
85
158
 
86
- - Styling using the static "styles" property of the lit component will not be applied.
87
- - The element and its content can be styled in a traditional manner.
159
+ ### Forms (only if you customize inputs globally)
88
160
 
89
- For example, the components `queue`, `list`, and `fetch` do not have a shadow DOM.
161
+ Interactive controls expose a few extra **theme-level** tokens; prefer these over styling individual inputs from outside.
162
+
163
+ | Variable | Role |
164
+ |----------|------|
165
+ | `--sc-border-width` | Default border thickness |
166
+ | `--sc-form-height` | Control height |
167
+ | `--sc-input-bg`, `--sc-input-color`, `--sc-input-border-color` | Default field chrome |
168
+ | `--sc-input-active-bg`, `--sc-input-active-color`, `--sc-input-active-border-color` | Focus/active state |
169
+
170
+ ---
171
+
172
+ ## Tailwind in new components ?
173
+
174
+ Set <code>tailwind.config.js</code> to match concorde style token in your custom component.
175
+
176
+ <sonic-code language="js">
177
+ <template>
178
+ ...
179
+ theme: {
180
+ borderRadius: {
181
+ DEFAULT: "var(--sc-rounded)",
182
+ none: "0",
183
+ sm: "var(--sc-rounded-sm)",
184
+ md: "var(--sc-rounded-md)",
185
+ lg: "var(--sc-rounded-lg)",
186
+ xl: "var(--sc-rounded-xl)",
187
+ full: "9999px",
188
+ },
189
+ boxShadow: {
190
+ DEFAULT: "var(--sc-shadow)",
191
+ none: "none",
192
+ sm: "var(--sc-shadow-sm)",
193
+ md: "var(--sc-shadow-md)",
194
+ lg: "var(--sc-shadow-lg)",
195
+ xl: "var(--sc-shadow-xl)",
196
+ },
197
+ colors: {
198
+ transparent: "transparent",
199
+ current: "currentColor",
200
+ content: "var(--sc-base-content)",
201
+ base: "var(--sc-base)",
202
+ neutral: {
203
+ 0: "var(--sc-base)",
204
+ 50: "var(--sc-base-50)",
205
+ 100: "var(--sc-base-100)",
206
+ 200: "var(--sc-base-200)",
207
+ 300: "var(--sc-base-300)",
208
+ 400: "var(--sc-base-400)",
209
+ 500: "var(--sc-base-500)",
210
+ 600: "var(--sc-base-600)",
211
+ 700: "var(--sc-base-700)",
212
+ 800: "var(--sc-base-800)",
213
+ 900: "var(--sc-base-900)",
214
+ content: "var(--sc-base)",
215
+ },
216
+ primary: {
217
+ DEFAULT: "var(--sc-primary)",
218
+ content: "var(--sc-primary-content)",
219
+ },
220
+ success: {
221
+ DEFAULT: "var(--sc-success)",
222
+ content: "var(--sc-success-content)",
223
+ },
224
+ danger: {
225
+ DEFAULT: "var(--sc-danger)",
226
+ content: "var(--sc-danger-content)",
227
+ },
228
+ warning: {
229
+ DEFAULT: "var(--sc-warning)",
230
+ content: "var(--sc-warning-content)",
231
+ },
232
+ info: {
233
+ DEFAULT: "var(--sc-info)",
234
+ content: "var(--sc-info-content)",
235
+ },
236
+ contrast: {
237
+ DEFAULT: "var(--sc-contrast)",
238
+ content: "var(--sc-contrast-content)",
239
+ },
240
+ },
241
+ extend: {
242
+ borderWidth: {
243
+ DEFAULT: "var(--sc-border-width)",
244
+ },
245
+ fontFamily: {
246
+ headings: ["var(--sc-headings-font-family, var(--sc-font-family-base, sans-serif))"],
247
+ body: ["var(--sc-font-family-base)"],
248
+ monospace: ["var(--sc-font-family-monospace, monospace)"],
249
+ }
250
+ }
251
+ </template>
252
+ </sonic-code>
90
253
 
91
- ℹ️ **Note:** Specifically in this case, it may be useful to set the `display` property to `contents`.
package/src/docs/code.ts CHANGED
@@ -18,6 +18,25 @@ import "prismjs/components/prism-bash"; // Language
18
18
  // import "prismjs/components/prism-css"; // Language
19
19
  import "prismjs/components/prism-markup"; // Language
20
20
 
21
+ let normalizeWhitespaceDefaultsApplied = false;
22
+
23
+ function normalizeDocsCodeLanguage(language: string): string {
24
+ return language === "html" ? "markup" : language;
25
+ }
26
+
27
+ function applyNormalizeWhitespaceDefaults(): void {
28
+ if (normalizeWhitespaceDefaultsApplied) return;
29
+ normalizeWhitespaceDefaultsApplied = true;
30
+ Prism.plugins.NormalizeWhitespace.setDefaults({
31
+ "remove-trailing": true,
32
+ "remove-indent": true,
33
+ "left-trim": true,
34
+ "right-trim": true,
35
+ "remove-initial-line-feed": true,
36
+ "tabs-to-tabs": 2,
37
+ });
38
+ }
39
+
21
40
  const tagName = "sonic-code";
22
41
  @customElement(tagName)
23
42
  export class DocsCode extends LitElement {
@@ -38,6 +57,7 @@ export class DocsCode extends LitElement {
38
57
  padding-right: 5rem !important;
39
58
  border: 1px solid var(--sc-base-200);
40
59
  border-radius: var(--sc-rounded);
60
+ margin: 0 !important;
41
61
  }
42
62
  .custom-scroll {
43
63
  overflow: auto !important;
@@ -70,62 +90,95 @@ export class DocsCode extends LitElement {
70
90
  @property({ type: Boolean, reflect: true }) showCode = false;
71
91
  @property({ type: Boolean, reflect: true }) toggleCode = false;
72
92
  @property({ type: Boolean, reflect: true }) noEdit = false;
73
- @property({ type: Boolean, reflect: true }) noOutput = false;
74
93
 
75
94
  @property() language = "markup";
76
- @property() defaultCode?: string;
77
- @property() currentCode?: string;
95
+ @property({ attribute: false }) defaultCode?: string;
96
+ @property({ attribute: false }) currentCode?: string;
97
+ @property({ attribute: false }) codeOutput?: string;
78
98
 
79
- @property() codeOutput?: string;
99
+ @query("#codePreview") codePreview!: HTMLPreElement;
80
100
 
81
- //ELEMENTS
82
- @property() templateEl: HTMLTemplateElement | null;
83
- @query("#codePreview") codePreview;
84
- @query("#codeRender") codeRender;
101
+ private templateEl: HTMLTemplateElement | null = null;
85
102
 
86
- //States
87
103
  @state() codeEdited = false;
88
104
 
89
- /** Aperçu live uniquement pour les blocs markup (évite d’injecter du HTML depuis des exemples JS). */
90
- private get rendersLiveOutput(): boolean {
91
- return this.language === "markup" && !this.noOutput;
105
+ /** Live preview only for markup (avoid injecting HTML from JS/TS examples). */
106
+ private get prismLanguage(): string {
107
+ return normalizeDocsCodeLanguage(this.language);
92
108
  }
93
109
 
94
- // createRenderRoot() {
95
- // return this;
96
- // }
110
+ private get rendersLiveOutput(): boolean {
111
+ return this.prismLanguage === "markup";
112
+ }
97
113
 
98
114
  connectedCallback() {
99
115
  super.connectedCallback();
100
116
  if (!this.toggleCode) {
101
117
  this.showCode = true;
102
118
  }
119
+ this.syncFromTemplate();
120
+ }
121
+
122
+ willUpdate(changedProperties: PropertyValues) {
123
+ if (
124
+ changedProperties.has("language") &&
125
+ changedProperties.get("language") !== undefined
126
+ ) {
127
+ this.applyLanguageChange();
128
+ }
129
+ }
103
130
 
131
+ private normalizeSourceForHighlight(source: string): string {
132
+ applyNormalizeWhitespaceDefaults();
133
+ const nw = Prism.plugins.NormalizeWhitespace;
134
+ return nw
135
+ .normalize(source)
136
+ .replaceAll('=""', "")
137
+ .replaceAll("&quot;", '"')
138
+ .replaceAll('"{', "'{")
139
+ .replaceAll('}"', "}'")
140
+ .replaceAll("&amp;", "&");
141
+ }
142
+
143
+ private highlightSource(source: string): string {
144
+ const lang = this.prismLanguage;
145
+ const grammar = Prism.languages[lang];
146
+ if (!grammar) {
147
+ return source;
148
+ }
149
+ return Prism.highlight(
150
+ this.normalizeSourceForHighlight(source),
151
+ grammar,
152
+ lang,
153
+ );
154
+ }
155
+
156
+ private syncFromTemplate() {
104
157
  this.templateEl = this.querySelector("template");
105
158
  this.defaultCode = this.readTemplateSourceCode();
159
+ this.codeEdited = false;
106
160
 
107
161
  if (this.defaultCode) {
108
- Prism.plugins.NormalizeWhitespace.setDefaults({
109
- "remove-trailing": true,
110
- "remove-indent": true,
111
- "left-trim": true,
112
- "right-trim": true,
113
- "remove-initial-line-feed": true,
114
- "tabs-to-tabs": 2,
115
- });
116
- const nw = Prism.plugins.NormalizeWhitespace;
117
- const normalizedCode = nw
118
- .normalize(this.defaultCode)
119
- .replaceAll('=""', "")
120
- .replaceAll("&quot;", '"')
121
- .replaceAll('"{', "'{")
122
- .replaceAll('}"', "}'")
123
- .replaceAll("&amp;", "&");
124
- this.currentCode = Prism.highlight(
125
- normalizedCode,
126
- Prism.languages[this.language],
127
- this.language,
128
- );
162
+ this.currentCode = this.highlightSource(this.defaultCode);
163
+ } else {
164
+ this.currentCode = undefined;
165
+ }
166
+
167
+ if (this.rendersLiveOutput) {
168
+ this.codeOutput = this.defaultCode;
169
+ } else {
170
+ this.removeOutputSlot();
171
+ }
172
+ }
173
+
174
+ private applyLanguageChange() {
175
+ this.defaultCode = this.readTemplateSourceCode();
176
+ this.codeEdited = false;
177
+
178
+ if (this.defaultCode) {
179
+ this.currentCode = this.highlightSource(this.defaultCode);
180
+ } else {
181
+ this.currentCode = undefined;
129
182
  }
130
183
 
131
184
  if (this.rendersLiveOutput) {
@@ -148,10 +201,10 @@ export class DocsCode extends LitElement {
148
201
  * when the fragment has elements; otherwise textContent (imports, types, etc.).
149
202
  */
150
203
  private readTemplateSourceCode(): string {
151
- const template = this.templateEl;
204
+ const template = this.templateEl ?? this.querySelector("template");
152
205
  if (!template) return "";
153
206
 
154
- if (this.language === "markup") {
207
+ if (this.prismLanguage === "markup") {
155
208
  return this.decodeTemplateEntities(template.innerHTML);
156
209
  }
157
210
 
@@ -160,11 +213,16 @@ export class DocsCode extends LitElement {
160
213
  return template.content.textContent ?? "";
161
214
  }
162
215
 
216
+ private getPreviewPlainText(): string {
217
+ return this.codePreview?.innerText ?? "";
218
+ }
219
+
163
220
  updateCodeRender() {
164
- if (this.defaultCode !== this.currentCode) {
165
- this.codeEdited = true;
221
+ const plain = this.getPreviewPlainText();
222
+ this.codeEdited = plain !== (this.defaultCode ?? "");
223
+ if (this.rendersLiveOutput) {
224
+ this.codeOutput = plain;
166
225
  }
167
- this.codeOutput = this.codePreview?.innerText;
168
226
  }
169
227
 
170
228
  resetCode() {
@@ -173,11 +231,7 @@ export class DocsCode extends LitElement {
173
231
  if (this.defaultCode) {
174
232
  this.currentCode = "";
175
233
  window.requestAnimationFrame(() => {
176
- this.currentCode = Prism.highlight(
177
- this.defaultCode || "",
178
- Prism.languages[this.language],
179
- this.language,
180
- );
234
+ this.currentCode = this.highlightSource(this.defaultCode || "");
181
235
  });
182
236
  }
183
237
  if (this.rendersLiveOutput) {
@@ -189,15 +243,27 @@ export class DocsCode extends LitElement {
189
243
  this.showCode = !this.showCode;
190
244
  }
191
245
 
192
- handleCopyCode(e: Event) {
193
- const text = this.codeOutput ?? this.defaultCode;
194
- if (text) {
195
- navigator.clipboard.writeText(text);
196
- const button = e.currentTarget as HTMLButtonElement;
246
+ private getCopyText(): string {
247
+ if (!this.noEdit) {
248
+ const fromPreview = this.getPreviewPlainText();
249
+ if (fromPreview) return fromPreview;
250
+ }
251
+ return this.codeOutput ?? this.defaultCode ?? "";
252
+ }
253
+
254
+ async handleCopyCode(e: Event) {
255
+ const text = this.getCopyText();
256
+ if (!text) return;
257
+
258
+ const button = e.currentTarget as HTMLButtonElement;
259
+ try {
260
+ await navigator.clipboard.writeText(text);
197
261
  button?.setAttribute("active", "");
198
262
  setTimeout(() => {
199
263
  button?.removeAttribute("active");
200
264
  }, 500);
265
+ } catch {
266
+ // Clipboard unavailable or permission denied.
201
267
  }
202
268
  }
203
269
 
@@ -205,8 +271,7 @@ export class DocsCode extends LitElement {
205
271
  super.updated(changedProperties);
206
272
  if (
207
273
  changedProperties.has("codeOutput") ||
208
- changedProperties.has("language") ||
209
- changedProperties.has("noOutput")
274
+ changedProperties.has("language")
210
275
  ) {
211
276
  this.appendOutput();
212
277
  }
@@ -216,6 +281,7 @@ export class DocsCode extends LitElement {
216
281
  this.querySelector("[slot=output]")?.remove();
217
282
  }
218
283
 
284
+ /** Trusted doc demo markup only — same source as the live preview slot. */
219
285
  appendOutput() {
220
286
  if (!this.rendersLiveOutput) {
221
287
  this.removeOutputSlot();
@@ -231,20 +297,21 @@ export class DocsCode extends LitElement {
231
297
  output.innerHTML = this.codeOutput || "";
232
298
  }
233
299
  }
300
+
234
301
  handleGetSDUI() {
235
302
  SDUIUtils.toJson(this.templateEl?.content.children);
236
303
  }
237
304
 
238
305
  render() {
239
- // ${this.language === "markup" ? html`<div class="py-3">${unsafeHTML(this.codeOutput || "")}</div>` : nothing} //
306
+ const isMarkup = this.prismLanguage === "markup";
240
307
 
241
308
  return html`
242
309
  <div
243
- class="relative ${this.language === "markup"
310
+ class="relative ${isMarkup
244
311
  ? "rounded-md border border-neutral-200 bg-neutral-50/80 dark:border-neutral-700/80 dark:bg-neutral-900/40 p-4"
245
312
  : ""}"
246
313
  >
247
- ${this.language === "markup" && !this.noOutput
314
+ ${isMarkup
248
315
  ? html`<slot name="output" class="block py-3"></slot>`
249
316
  : nothing}
250
317
 
@@ -282,7 +349,7 @@ export class DocsCode extends LitElement {
282
349
  name="check"
283
350
  ></sonic-icon>
284
351
  </sonic-button>
285
- ${this.language == "markup"
352
+ ${isMarkup
286
353
  ? html`<sonic-button
287
354
  size="2xs"
288
355
  shape
@@ -316,7 +383,7 @@ export class DocsCode extends LitElement {
316
383
  <div>
317
384
  <pre
318
385
  id="codePreview"
319
- class="rounded-md custom-scroll language-${this.language} ${!this
386
+ class="rounded-md custom-scroll language-${this.prismLanguage} ${!this
320
387
  .showCode || !this.currentCode
321
388
  ? "hidden"
322
389
  : ""}"