@kontourai/survey 0.7.0 → 0.7.1
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.
|
@@ -30,6 +30,72 @@
|
|
|
30
30
|
*/
|
|
31
31
|
import { mountReviewWorkbench, } from "./review-workbench.js";
|
|
32
32
|
import { REVIEW_WORKBENCH_CSS } from "./review-workbench-css.generated.js";
|
|
33
|
+
/** @internal Second adopted stylesheet: host token defaults + inheritance delegation.
|
|
34
|
+
*
|
|
35
|
+
* This sheet is adopted AFTER the main workbench CSS (adoptedStyleSheets[1]).
|
|
36
|
+
* It serves two purposes:
|
|
37
|
+
*
|
|
38
|
+
* 1. :host literal defaults — non-self-referential literal values for all --k-* tokens.
|
|
39
|
+
* These provide a baseline when the host page does not load Console Kit.
|
|
40
|
+
* Because they are literal (not var()), there is no self-reference cycle.
|
|
41
|
+
* Inline styles on the host element always win over :host rules, so setting
|
|
42
|
+
* `--k-brand: hotpink` on the element naturally overrides the #5ce0c6 default.
|
|
43
|
+
*
|
|
44
|
+
* 2. .survey-workbench-embed[class] inherit delegation — using specificity (0,2,0)
|
|
45
|
+
* to match the theme class selectors (e.g. .survey-workbench-embed.theme-survey).
|
|
46
|
+
* Source order (after the workbench sheet) makes these inherit rules win, so the
|
|
47
|
+
* embed's tokens propagate upward to :host, picking up any host overrides.
|
|
48
|
+
*/
|
|
49
|
+
const TOKEN_INHERIT_CSS = `/* 1. Host token defaults — literal values, not var() self-references.
|
|
50
|
+
Inline styles on the host element always win over :host rules so external
|
|
51
|
+
overrides (e.g. style="--k-brand: hotpink") propagate through automatically. */
|
|
52
|
+
:host {
|
|
53
|
+
display: block;
|
|
54
|
+
container-type: inline-size;
|
|
55
|
+
--k-bg: #060a10;
|
|
56
|
+
--k-panel: #101822;
|
|
57
|
+
--k-panel-raised: #161e2b;
|
|
58
|
+
--k-text: #e8eaf0;
|
|
59
|
+
--k-text-muted: #8b93a8;
|
|
60
|
+
--k-text-faint: #4e5870;
|
|
61
|
+
--k-line: rgba(255,255,255,0.08);
|
|
62
|
+
--k-line-strong: rgba(255,255,255,0.14);
|
|
63
|
+
--k-brand: #5ce0c6;
|
|
64
|
+
--k-active: #7aa2ff;
|
|
65
|
+
--k-positive: #34d399;
|
|
66
|
+
--k-caution: #f3b14b;
|
|
67
|
+
--k-negative: #ff6f6f;
|
|
68
|
+
--k-neutral: #8b93a8;
|
|
69
|
+
--k-radius-md: 10px;
|
|
70
|
+
--k-radius-sm: 6px;
|
|
71
|
+
--k-font-ui: "Hanken Grotesk", system-ui, sans-serif;
|
|
72
|
+
}
|
|
73
|
+
/* 2. Token inheritance delegation — re-delegate --k-* tokens on the embed root
|
|
74
|
+
to inherit from :host, so external overrides set on the host element propagate
|
|
75
|
+
through the shadow boundary. The [class] attribute selector raises specificity
|
|
76
|
+
to (0,2,0) — matching the theme class selectors — and this sheet comes AFTER
|
|
77
|
+
the workbench defaults, so source order makes these rules win. */
|
|
78
|
+
.survey-workbench-embed[class] {
|
|
79
|
+
--k-bg: inherit;
|
|
80
|
+
--k-panel: inherit;
|
|
81
|
+
--k-panel-raised: inherit;
|
|
82
|
+
--k-text: inherit;
|
|
83
|
+
--k-text-muted: inherit;
|
|
84
|
+
--k-text-faint: inherit;
|
|
85
|
+
--k-line: inherit;
|
|
86
|
+
--k-line-strong: inherit;
|
|
87
|
+
--k-brand: inherit;
|
|
88
|
+
--k-active: inherit;
|
|
89
|
+
--k-positive: inherit;
|
|
90
|
+
--k-caution: inherit;
|
|
91
|
+
--k-negative: inherit;
|
|
92
|
+
--k-neutral: inherit;
|
|
93
|
+
--k-radius-md: inherit;
|
|
94
|
+
--k-radius-sm: inherit;
|
|
95
|
+
--k-font-ui: inherit;
|
|
96
|
+
--k-font-mono: inherit;
|
|
97
|
+
--k-font-display: inherit;
|
|
98
|
+
}`;
|
|
33
99
|
export class SurveyReviewWorkbenchElement extends HTMLElement {
|
|
34
100
|
static observedAttributes = ["theme", "color-scheme", "src"];
|
|
35
101
|
#session = null;
|
|
@@ -49,33 +115,34 @@ export class SurveyReviewWorkbenchElement extends HTMLElement {
|
|
|
49
115
|
styleEl.textContent = REVIEW_WORKBENCH_CSS;
|
|
50
116
|
this.#root.appendChild(styleEl);
|
|
51
117
|
}
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
118
|
+
// Fallback <style> element for browsers that do not support adoptedStyleSheets.
|
|
119
|
+
// When adoptedStyleSheets are available, TOKEN_INHERIT_CSS (the second adopted
|
|
120
|
+
// sheet) handles :host defaults and embed token delegation — and wins over this
|
|
121
|
+
// <style> element in the cascade. This <style> is only active in the fallback
|
|
122
|
+
// path, so using literal values here is safe: there is no self-reference cycle.
|
|
55
123
|
const hostStyle = document.createElement("style");
|
|
56
124
|
hostStyle.textContent = `
|
|
57
125
|
:host {
|
|
58
126
|
display: block;
|
|
59
127
|
container-type: inline-size;
|
|
60
|
-
/*
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
--k-
|
|
64
|
-
--k-panel:
|
|
65
|
-
--k-
|
|
66
|
-
--k-text:
|
|
67
|
-
--k-text-
|
|
68
|
-
--k-
|
|
69
|
-
--k-line:
|
|
70
|
-
--k-
|
|
71
|
-
--k-
|
|
72
|
-
--k-
|
|
73
|
-
--k-
|
|
74
|
-
--k-
|
|
75
|
-
--k-
|
|
76
|
-
--k-radius-
|
|
77
|
-
--k-
|
|
78
|
-
--k-font-ui: var(--k-font-ui, "Hanken Grotesk", system-ui, sans-serif);
|
|
128
|
+
/* Literal token defaults (no var() self-references) so the values resolve
|
|
129
|
+
correctly even when the adopted inheritance sheet is unavailable. */
|
|
130
|
+
--k-bg: #060a10;
|
|
131
|
+
--k-panel: #101822;
|
|
132
|
+
--k-panel-raised: #161e2b;
|
|
133
|
+
--k-text: #e8eaf0;
|
|
134
|
+
--k-text-muted: #8b93a8;
|
|
135
|
+
--k-text-faint: #4e5870;
|
|
136
|
+
--k-line: rgba(255,255,255,0.08);
|
|
137
|
+
--k-line-strong: rgba(255,255,255,0.14);
|
|
138
|
+
--k-brand: #5ce0c6;
|
|
139
|
+
--k-active: #7aa2ff;
|
|
140
|
+
--k-positive: #34d399;
|
|
141
|
+
--k-caution: #f3b14b;
|
|
142
|
+
--k-negative: #ff6f6f;
|
|
143
|
+
--k-radius-md: 10px;
|
|
144
|
+
--k-radius-sm: 6px;
|
|
145
|
+
--k-font-ui: "Hanken Grotesk", system-ui, sans-serif;
|
|
79
146
|
}
|
|
80
147
|
.workbench-empty, .workbench-error {
|
|
81
148
|
display: flex;
|
|
@@ -92,6 +159,30 @@ export class SurveyReviewWorkbenchElement extends HTMLElement {
|
|
|
92
159
|
.workbench-error {
|
|
93
160
|
color: var(--k-negative, #ff6f6f);
|
|
94
161
|
}
|
|
162
|
+
/* Delegate k-tokens from :host to the embed container so host-element inline
|
|
163
|
+
style overrides propagate through the shadow boundary. This rule has same
|
|
164
|
+
specificity as the workbench CSS token defaults but comes after them in
|
|
165
|
+
document order, so it wins and allows inheritance from :host. */
|
|
166
|
+
.survey-workbench-embed {
|
|
167
|
+
--k-bg: inherit;
|
|
168
|
+
--k-panel: inherit;
|
|
169
|
+
--k-panel-raised: inherit;
|
|
170
|
+
--k-text: inherit;
|
|
171
|
+
--k-text-muted: inherit;
|
|
172
|
+
--k-text-faint: inherit;
|
|
173
|
+
--k-line: inherit;
|
|
174
|
+
--k-line-strong: inherit;
|
|
175
|
+
--k-brand: inherit;
|
|
176
|
+
--k-active: inherit;
|
|
177
|
+
--k-positive: inherit;
|
|
178
|
+
--k-caution: inherit;
|
|
179
|
+
--k-negative: inherit;
|
|
180
|
+
--k-radius-md: inherit;
|
|
181
|
+
--k-radius-sm: inherit;
|
|
182
|
+
--k-font-ui: inherit;
|
|
183
|
+
--k-font-mono: inherit;
|
|
184
|
+
--k-font-display: inherit;
|
|
185
|
+
}
|
|
95
186
|
`;
|
|
96
187
|
this.#root.appendChild(hostStyle);
|
|
97
188
|
this.#mountRoot = document.createElement("div");
|
|
@@ -186,15 +277,27 @@ export class SurveyReviewWorkbenchElement extends HTMLElement {
|
|
|
186
277
|
this.#mountRoot.innerHTML = `<div class="workbench-error">${escapeHtml(message)}</div>`;
|
|
187
278
|
this.#mounted = false;
|
|
188
279
|
}
|
|
189
|
-
/** Attempt to inject the workbench CSS via constructable CSSStyleSheet.
|
|
280
|
+
/** Attempt to inject the workbench CSS via constructable CSSStyleSheet.
|
|
281
|
+
*
|
|
282
|
+
* Two sheets are adopted: the main workbench CSS first, then a
|
|
283
|
+
* token-inheritance sheet that resets all --k-* tokens to `inherit`
|
|
284
|
+
* on .survey-workbench-embed. Because later entries in adoptedStyleSheets
|
|
285
|
+
* win over earlier ones at equal specificity, the inheritance rules
|
|
286
|
+
* override the workbench token defaults. This allows host-element inline
|
|
287
|
+
* style overrides (or any ancestor's CSS custom properties) to propagate
|
|
288
|
+
* through the shadow boundary.
|
|
289
|
+
*/
|
|
190
290
|
#adoptCss() {
|
|
191
291
|
try {
|
|
192
292
|
if (typeof CSSStyleSheet === "undefined" || !this.#root.adoptedStyleSheets) {
|
|
193
293
|
return false;
|
|
194
294
|
}
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
295
|
+
const workbenchSheet = new CSSStyleSheet();
|
|
296
|
+
workbenchSheet.replaceSync(REVIEW_WORKBENCH_CSS);
|
|
297
|
+
// Inheritance delegation sheet — must come AFTER the workbench sheet.
|
|
298
|
+
const inheritanceSheet = new CSSStyleSheet();
|
|
299
|
+
inheritanceSheet.replaceSync(TOKEN_INHERIT_CSS);
|
|
300
|
+
this.#root.adoptedStyleSheets = [workbenchSheet, inheritanceSheet];
|
|
198
301
|
return true;
|
|
199
302
|
}
|
|
200
303
|
catch {
|
package/package.json
CHANGED