@elastic/distillate 0.0.0 → 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.
- package/LICENSE.txt +93 -0
- package/NOTICE.txt +30 -0
- package/README.md +142 -0
- package/THIRD_PARTY_LICENSES.md +768 -0
- package/dist/cjs/collector.js +420 -0
- package/dist/cjs/collector.js.map +1 -0
- package/dist/cjs/css_scan.js +186 -0
- package/dist/cjs/css_scan.js.map +1 -0
- package/dist/cjs/dom_sink.js +40 -0
- package/dist/cjs/dom_sink.js.map +1 -0
- package/dist/cjs/emotion.js +189 -0
- package/dist/cjs/emotion.js.map +1 -0
- package/dist/cjs/engine.js +79 -0
- package/dist/cjs/engine.js.map +1 -0
- package/dist/cjs/environment.js +9 -0
- package/dist/cjs/environment.js.map +1 -0
- package/dist/cjs/hash.js +86 -0
- package/dist/cjs/hash.js.map +1 -0
- package/dist/cjs/idents.js +23 -0
- package/dist/cjs/idents.js.map +1 -0
- package/dist/cjs/index.js +42 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/instance.js +34 -0
- package/dist/cjs/instance.js.map +1 -0
- package/dist/cjs/local_vars.js +100 -0
- package/dist/cjs/local_vars.js.map +1 -0
- package/dist/cjs/minify.js +77 -0
- package/dist/cjs/minify.js.map +1 -0
- package/dist/cjs/names.js +77 -0
- package/dist/cjs/names.js.map +1 -0
- package/dist/cjs/nesting.js +406 -0
- package/dist/cjs/nesting.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/runtime.js +257 -0
- package/dist/cjs/runtime.js.map +1 -0
- package/dist/cjs/styles/authoring.js +169 -0
- package/dist/cjs/styles/authoring.js.map +1 -0
- package/dist/cjs/styles/declarations.js +139 -0
- package/dist/cjs/styles/declarations.js.map +1 -0
- package/dist/cjs/styles/index.js +32 -0
- package/dist/cjs/styles/index.js.map +1 -0
- package/dist/cjs/styles/module.js +233 -0
- package/dist/cjs/styles/module.js.map +1 -0
- package/dist/cjs/styles/registry.js +187 -0
- package/dist/cjs/styles/registry.js.map +1 -0
- package/dist/cjs/styles/types.js +9 -0
- package/dist/cjs/styles/types.js.map +1 -0
- package/dist/cjs/testing.js +37 -0
- package/dist/cjs/testing.js.map +1 -0
- package/dist/cjs/theme.js +249 -0
- package/dist/cjs/theme.js.map +1 -0
- package/dist/cjs/tokens/contextual_var.js +39 -0
- package/dist/cjs/tokens/contextual_var.js.map +1 -0
- package/dist/cjs/tokens/index.js +24 -0
- package/dist/cjs/tokens/index.js.map +1 -0
- package/dist/cjs/tokens/kind.js +14 -0
- package/dist/cjs/tokens/kind.js.map +1 -0
- package/dist/cjs/tokens/light_dark.js +42 -0
- package/dist/cjs/tokens/light_dark.js.map +1 -0
- package/dist/cjs/tokens/scale_token.js +28 -0
- package/dist/cjs/tokens/scale_token.js.map +1 -0
- package/dist/cjs/tokens/theme_token.js +28 -0
- package/dist/cjs/tokens/theme_token.js.map +1 -0
- package/dist/cjs/var_invariant.js +115 -0
- package/dist/cjs/var_invariant.js.map +1 -0
- package/dist/collector.d.ts +84 -0
- package/dist/collector.d.ts.map +1 -0
- package/dist/collector.js +416 -0
- package/dist/collector.js.map +1 -0
- package/dist/css_scan.d.ts +57 -0
- package/dist/css_scan.d.ts.map +1 -0
- package/dist/css_scan.js +180 -0
- package/dist/css_scan.js.map +1 -0
- package/dist/dom_sink.d.ts +27 -0
- package/dist/dom_sink.d.ts.map +1 -0
- package/dist/dom_sink.js +36 -0
- package/dist/dom_sink.js.map +1 -0
- package/dist/emotion.d.ts +47 -0
- package/dist/emotion.d.ts.map +1 -0
- package/dist/emotion.js +184 -0
- package/dist/emotion.js.map +1 -0
- package/dist/engine.d.ts +41 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +75 -0
- package/dist/engine.js.map +1 -0
- package/dist/environment.d.ts +43 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +8 -0
- package/dist/environment.js.map +1 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +82 -0
- package/dist/hash.js.map +1 -0
- package/dist/idents.d.ts +9 -0
- package/dist/idents.d.ts.map +1 -0
- package/dist/idents.js +19 -0
- package/dist/idents.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/instance.d.ts +16 -0
- package/dist/instance.d.ts.map +1 -0
- package/dist/instance.js +30 -0
- package/dist/instance.js.map +1 -0
- package/dist/local_vars.d.ts +75 -0
- package/dist/local_vars.d.ts.map +1 -0
- package/dist/local_vars.js +92 -0
- package/dist/local_vars.js.map +1 -0
- package/dist/minify.d.ts +11 -0
- package/dist/minify.d.ts.map +1 -0
- package/dist/minify.js +73 -0
- package/dist/minify.js.map +1 -0
- package/dist/names.d.ts +39 -0
- package/dist/names.d.ts.map +1 -0
- package/dist/names.js +70 -0
- package/dist/names.js.map +1 -0
- package/dist/nesting.d.ts +59 -0
- package/dist/nesting.d.ts.map +1 -0
- package/dist/nesting.js +400 -0
- package/dist/nesting.js.map +1 -0
- package/dist/runtime.d.ts +36 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +252 -0
- package/dist/runtime.js.map +1 -0
- package/dist/styles/authoring.d.ts +59 -0
- package/dist/styles/authoring.d.ts.map +1 -0
- package/dist/styles/authoring.js +155 -0
- package/dist/styles/authoring.js.map +1 -0
- package/dist/styles/declarations.d.ts +10 -0
- package/dist/styles/declarations.d.ts.map +1 -0
- package/dist/styles/declarations.js +132 -0
- package/dist/styles/declarations.js.map +1 -0
- package/dist/styles/index.d.ts +7 -0
- package/dist/styles/index.d.ts.map +1 -0
- package/dist/styles/index.js +12 -0
- package/dist/styles/index.js.map +1 -0
- package/dist/styles/module.d.ts +5 -0
- package/dist/styles/module.d.ts.map +1 -0
- package/dist/styles/module.js +229 -0
- package/dist/styles/module.js.map +1 -0
- package/dist/styles/registry.d.ts +48 -0
- package/dist/styles/registry.d.ts.map +1 -0
- package/dist/styles/registry.js +182 -0
- package/dist/styles/registry.js.map +1 -0
- package/dist/styles/types.d.ts +211 -0
- package/dist/styles/types.d.ts.map +1 -0
- package/dist/styles/types.js +8 -0
- package/dist/styles/types.js.map +1 -0
- package/dist/testing.d.ts +10 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +31 -0
- package/dist/testing.js.map +1 -0
- package/dist/theme.d.ts +85 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +240 -0
- package/dist/theme.js.map +1 -0
- package/dist/tokens/contextual_var.d.ts +35 -0
- package/dist/tokens/contextual_var.d.ts.map +1 -0
- package/dist/tokens/contextual_var.js +33 -0
- package/dist/tokens/contextual_var.js.map +1 -0
- package/dist/tokens/index.d.ts +5 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +11 -0
- package/dist/tokens/index.js.map +1 -0
- package/dist/tokens/kind.d.ts +2 -0
- package/dist/tokens/kind.d.ts.map +1 -0
- package/dist/tokens/kind.js +10 -0
- package/dist/tokens/kind.js.map +1 -0
- package/dist/tokens/light_dark.d.ts +20 -0
- package/dist/tokens/light_dark.d.ts.map +1 -0
- package/dist/tokens/light_dark.js +37 -0
- package/dist/tokens/light_dark.js.map +1 -0
- package/dist/tokens/scale_token.d.ts +20 -0
- package/dist/tokens/scale_token.d.ts.map +1 -0
- package/dist/tokens/scale_token.js +23 -0
- package/dist/tokens/scale_token.js.map +1 -0
- package/dist/tokens/theme_token.d.ts +20 -0
- package/dist/tokens/theme_token.d.ts.map +1 -0
- package/dist/tokens/theme_token.js +23 -0
- package/dist/tokens/theme_token.js.map +1 -0
- package/dist/var_invariant.d.ts +25 -0
- package/dist/var_invariant.d.ts.map +1 -0
- package/dist/var_invariant.js +108 -0
- package/dist/var_invariant.js.map +1 -0
- package/docs/concepts/authoring.md +115 -0
- package/docs/concepts/collection.md +66 -0
- package/docs/concepts/distillery.md +47 -0
- package/docs/concepts/index.md +18 -0
- package/docs/concepts/naming-and-output.md +123 -0
- package/docs/concepts/ordering.md +61 -0
- package/docs/concepts/single-copy.md +103 -0
- package/docs/concepts/tokens.md +99 -0
- package/docs/docset.yml +53 -0
- package/docs/examples/01-stylesheet.ts +20 -0
- package/docs/examples/02-artifact.ts +26 -0
- package/docs/examples/03-variants.ts +40 -0
- package/docs/examples/04-emotion.ts +33 -0
- package/docs/examples/05-var-invariant.ts +31 -0
- package/docs/examples/06-payload.ts +85 -0
- package/docs/examples/fixture.ts +22 -0
- package/docs/getting-started/index.md +14 -0
- package/docs/getting-started/installation.md +30 -0
- package/docs/getting-started/quick-start.md +61 -0
- package/docs/getting-started/your-first-stylesheet.md +57 -0
- package/docs/guides/compact-artifacts.md +87 -0
- package/docs/guides/emotion-migration.md +60 -0
- package/docs/guides/index.md +17 -0
- package/docs/guides/name-collisions.md +37 -0
- package/docs/guides/non-css-surfaces.md +73 -0
- package/docs/guides/react-renderer.md +158 -0
- package/docs/guides/theming.md +107 -0
- package/docs/guides/var-invariant.md +24 -0
- package/docs/guides/vs-emotion.md +61 -0
- package/docs/index.md +73 -0
- package/docs/logo.svg +7 -0
- package/docs/playground/index.html +12 -0
- package/docs/playground/package.json +23 -0
- package/docs/playground/src/app/app.tsx +109 -0
- package/docs/playground/src/app/css_panel.tsx +119 -0
- package/docs/playground/src/app/editor_panel.tsx +87 -0
- package/docs/playground/src/app/index.ts +8 -0
- package/docs/playground/src/app/monaco_css_editor.tsx +84 -0
- package/docs/playground/src/app/monaco_source_editor.tsx +132 -0
- package/docs/playground/src/app/preview_panel.tsx +99 -0
- package/docs/playground/src/app/tokens_panel.tsx +117 -0
- package/docs/playground/src/app/types.ts +10 -0
- package/docs/playground/src/examples/snippets.test.ts +28 -0
- package/docs/playground/src/examples/snippets.ts +418 -0
- package/docs/playground/src/lib/compile.test.ts +157 -0
- package/docs/playground/src/lib/compile.ts +242 -0
- package/docs/playground/src/lib/demo_environment.test.ts +123 -0
- package/docs/playground/src/lib/demo_environment.ts +140 -0
- package/docs/playground/src/lib/editor_lib.test.ts +39 -0
- package/docs/playground/src/lib/editor_lib.ts +142 -0
- package/docs/playground/src/lib/format_css.test.ts +41 -0
- package/docs/playground/src/lib/format_css.ts +71 -0
- package/docs/playground/src/main.tsx +25 -0
- package/docs/playground/src/setup/chrome.test.ts +47 -0
- package/docs/playground/src/setup/chrome.ts +365 -0
- package/docs/playground/src/setup/monaco_env.ts +64 -0
- package/docs/playground/tsconfig.json +22 -0
- package/docs/playground/vite.config.ts +37 -0
- package/docs/playground/vitest.config.ts +35 -0
- package/docs/playground.md +28 -0
- package/docs/reference/api/emotion.md +372 -0
- package/docs/reference/api/index-1.md +2180 -0
- package/docs/reference/api/index.md +9 -0
- package/docs/reference/api/testing.md +92 -0
- package/docs/reference/api.md +12 -0
- package/docs/reference/entry-points.md +125 -0
- package/docs/reference/environment.md +60 -0
- package/docs/reference/index.md +11 -0
- package/docs/reference/okf-map.md +92 -0
- package/package.json +127 -4
- package/src/collector.ts +526 -0
- package/src/css_scan.ts +263 -0
- package/src/dom_sink.ts +65 -0
- package/src/emotion.ts +311 -0
- package/src/engine.ts +191 -0
- package/src/environment.ts +56 -0
- package/src/hash.ts +111 -0
- package/src/idents.ts +21 -0
- package/src/index.ts +93 -0
- package/src/instance.ts +49 -0
- package/src/local_vars.ts +220 -0
- package/src/minify.ts +87 -0
- package/src/names.ts +129 -0
- package/src/nesting.ts +596 -0
- package/src/runtime.ts +428 -0
- package/src/styles/authoring.ts +244 -0
- package/src/styles/declarations.ts +172 -0
- package/src/styles/index.ts +58 -0
- package/src/styles/module.ts +396 -0
- package/src/styles/registry.ts +261 -0
- package/src/styles/types.ts +283 -0
- package/src/testing.ts +48 -0
- package/src/theme.ts +454 -0
- package/src/tokens/contextual_var.ts +72 -0
- package/src/tokens/index.ts +17 -0
- package/src/tokens/kind.ts +13 -0
- package/src/tokens/light_dark.ts +58 -0
- package/src/tokens/scale_token.ts +41 -0
- package/src/tokens/theme_token.ts +42 -0
- package/src/var_invariant.ts +147 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
4
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
|
+
* 2.0.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import 'monaco-editor/languages/definitions/typescript/register.js';
|
|
9
|
+
|
|
10
|
+
import { type ReactNode, useEffect, useRef } from 'react';
|
|
11
|
+
import { editor, Uri } from 'monaco-editor/editor.js';
|
|
12
|
+
import {
|
|
13
|
+
ModuleKind,
|
|
14
|
+
ModuleResolutionKind,
|
|
15
|
+
ScriptTarget,
|
|
16
|
+
typescriptDefaults,
|
|
17
|
+
} from 'monaco-editor/languages/features/typescript/register.js';
|
|
18
|
+
|
|
19
|
+
import type { PlaygroundMode } from '../lib/compile';
|
|
20
|
+
import { extraLibSource, PLAYGROUND_EXTRA_LIB_PATH } from '../lib/editor_lib';
|
|
21
|
+
import { ensureMonaco, SOURCE_THEME } from '../setup/monaco_env';
|
|
22
|
+
|
|
23
|
+
const MODEL_URI = 'file:///playground.ts';
|
|
24
|
+
|
|
25
|
+
let monacoReady = false;
|
|
26
|
+
|
|
27
|
+
const ensureSourceLanguage = (): void => {
|
|
28
|
+
if (monacoReady) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
monacoReady = true;
|
|
32
|
+
ensureMonaco();
|
|
33
|
+
typescriptDefaults.setCompilerOptions({
|
|
34
|
+
target: ScriptTarget.ESNext,
|
|
35
|
+
module: ModuleKind.ESNext,
|
|
36
|
+
moduleResolution: ModuleResolutionKind.NodeJs,
|
|
37
|
+
lib: ['es2022', 'dom'],
|
|
38
|
+
strict: true,
|
|
39
|
+
noEmit: true,
|
|
40
|
+
allowNonTsExtensions: true,
|
|
41
|
+
});
|
|
42
|
+
typescriptDefaults.setDiagnosticsOptions({
|
|
43
|
+
noSemanticValidation: false,
|
|
44
|
+
noSyntaxValidation: false,
|
|
45
|
+
diagnosticCodesToIgnore: [1108],
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const syncExtraLib = (mode: PlaygroundMode): void => {
|
|
50
|
+
typescriptDefaults.setExtraLibs([
|
|
51
|
+
{ content: extraLibSource(mode), filePath: PLAYGROUND_EXTRA_LIB_PATH },
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
interface MonacoSourceEditorProps {
|
|
56
|
+
readonly mode: PlaygroundMode;
|
|
57
|
+
readonly source: string;
|
|
58
|
+
readonly onSourceChange: (source: string) => void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const MonacoSourceEditor = ({
|
|
62
|
+
mode,
|
|
63
|
+
source,
|
|
64
|
+
onSourceChange,
|
|
65
|
+
}: MonacoSourceEditorProps): ReactNode => {
|
|
66
|
+
const hostRef = useRef<HTMLDivElement>(null);
|
|
67
|
+
const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null);
|
|
68
|
+
const onSourceChangeRef = useRef(onSourceChange);
|
|
69
|
+
onSourceChangeRef.current = onSourceChange;
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const host = hostRef.current;
|
|
73
|
+
if (!host) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const initialMode = mode;
|
|
77
|
+
const initialSource = source;
|
|
78
|
+
ensureSourceLanguage();
|
|
79
|
+
syncExtraLib(initialMode);
|
|
80
|
+
const uri = Uri.parse(MODEL_URI);
|
|
81
|
+
const existing = editor.getModel(uri);
|
|
82
|
+
const model =
|
|
83
|
+
existing ?? editor.createModel(initialSource, 'typescript', uri);
|
|
84
|
+
if (existing && existing.getValue() !== initialSource) {
|
|
85
|
+
existing.setValue(initialSource);
|
|
86
|
+
}
|
|
87
|
+
const instance = editor.create(host, {
|
|
88
|
+
model,
|
|
89
|
+
theme: SOURCE_THEME,
|
|
90
|
+
automaticLayout: true,
|
|
91
|
+
minimap: { enabled: false },
|
|
92
|
+
fontSize: 13,
|
|
93
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, monospace',
|
|
94
|
+
lineHeight: 20,
|
|
95
|
+
tabSize: 2,
|
|
96
|
+
insertSpaces: true,
|
|
97
|
+
scrollBeyondLastLine: false,
|
|
98
|
+
wordWrap: 'off',
|
|
99
|
+
padding: { top: 12, bottom: 12 },
|
|
100
|
+
fixedOverflowWidgets: true,
|
|
101
|
+
ariaLabel: 'Playground source',
|
|
102
|
+
renderLineHighlight: 'line',
|
|
103
|
+
overviewRulerLanes: 0,
|
|
104
|
+
hideCursorInOverviewRuler: true,
|
|
105
|
+
scrollbar: { verticalScrollbarSize: 10, horizontalScrollbarSize: 10 },
|
|
106
|
+
});
|
|
107
|
+
editorRef.current = instance;
|
|
108
|
+
const sub = instance.onDidChangeModelContent(() => {
|
|
109
|
+
onSourceChangeRef.current(instance.getValue());
|
|
110
|
+
});
|
|
111
|
+
return () => {
|
|
112
|
+
sub.dispose();
|
|
113
|
+
instance.dispose();
|
|
114
|
+
editorRef.current = null;
|
|
115
|
+
model.dispose();
|
|
116
|
+
};
|
|
117
|
+
}, []);
|
|
118
|
+
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
syncExtraLib(mode);
|
|
121
|
+
}, [mode]);
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
const instance = editorRef.current;
|
|
125
|
+
if (!instance || instance.getValue() === source) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
instance.setValue(source);
|
|
129
|
+
}, [source]);
|
|
130
|
+
|
|
131
|
+
return <div ref={hostRef} data-pg-monaco="" />;
|
|
132
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
4
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
|
+
* 2.0.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { type ReactNode, useEffect, useRef } from 'react';
|
|
9
|
+
|
|
10
|
+
import type { CompileError, CompileSuccess } from '../lib/compile';
|
|
11
|
+
import { cx, ui } from '../setup/chrome';
|
|
12
|
+
|
|
13
|
+
import type { PreviewTheme } from './types';
|
|
14
|
+
|
|
15
|
+
const { handles: h } = ui;
|
|
16
|
+
|
|
17
|
+
const stageLabel: Record<CompileError['stage'], string> = {
|
|
18
|
+
transform: 'Syntax error',
|
|
19
|
+
evaluate: 'Runtime error',
|
|
20
|
+
render: 'Render error',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export interface PreviewPanelProps {
|
|
24
|
+
readonly display: CompileSuccess | null;
|
|
25
|
+
readonly error: CompileError | null;
|
|
26
|
+
readonly theme: PreviewTheme;
|
|
27
|
+
readonly onThemeChange: (theme: PreviewTheme) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const PreviewPanel = ({
|
|
31
|
+
display,
|
|
32
|
+
error,
|
|
33
|
+
theme,
|
|
34
|
+
onThemeChange,
|
|
35
|
+
}: PreviewPanelProps): ReactNode => {
|
|
36
|
+
return (
|
|
37
|
+
<section className={cx(h.panel, h.dockPreview)}>
|
|
38
|
+
{error ? (
|
|
39
|
+
<div className={h.callout.readableName} role="alert">
|
|
40
|
+
<strong>{stageLabel[error.stage]}</strong>
|
|
41
|
+
<pre>{error.message}</pre>
|
|
42
|
+
</div>
|
|
43
|
+
) : null}
|
|
44
|
+
<div className={h.toolbar.readableName}>
|
|
45
|
+
<h2>Preview</h2>
|
|
46
|
+
<div
|
|
47
|
+
className={h.segmented.readableName}
|
|
48
|
+
role="group"
|
|
49
|
+
aria-label="Preview color scheme">
|
|
50
|
+
<button
|
|
51
|
+
type="button"
|
|
52
|
+
aria-pressed={theme === 'light'}
|
|
53
|
+
onClick={() => onThemeChange('light')}>
|
|
54
|
+
Light
|
|
55
|
+
</button>
|
|
56
|
+
<button
|
|
57
|
+
type="button"
|
|
58
|
+
aria-pressed={theme === 'dark'}
|
|
59
|
+
onClick={() => onThemeChange('dark')}>
|
|
60
|
+
Dark
|
|
61
|
+
</button>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
<PreviewHost
|
|
65
|
+
html={display?.previewHtml ?? ''}
|
|
66
|
+
readableCss={display?.readableCss ?? ''}
|
|
67
|
+
{...{ theme }}
|
|
68
|
+
/>
|
|
69
|
+
</section>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
interface PreviewHostProps {
|
|
74
|
+
readonly html: string;
|
|
75
|
+
readonly readableCss: string;
|
|
76
|
+
readonly theme: PreviewTheme;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const PreviewHost = ({
|
|
80
|
+
html,
|
|
81
|
+
readableCss,
|
|
82
|
+
theme,
|
|
83
|
+
}: PreviewHostProps): ReactNode => {
|
|
84
|
+
const hostRef = useRef<HTMLDivElement>(null);
|
|
85
|
+
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
const host = hostRef.current;
|
|
88
|
+
if (!host) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const shadow = host.shadowRoot ?? host.attachShadow({ mode: 'open' });
|
|
92
|
+
shadow.innerHTML =
|
|
93
|
+
`<style>:host{color-scheme:${theme};display:block;height:100%;background:${theme === 'dark' ? '#0B1628' : '#FFFFFF'};box-sizing:border-box}[data-pg-stage]{min-height:100%;display:flex;align-items:center;justify-content:center;padding:24px;box-sizing:border-box}</style>` +
|
|
94
|
+
`<style>${readableCss}</style>` +
|
|
95
|
+
`<div data-pg-stage="">${html}</div>`;
|
|
96
|
+
}, [html, readableCss, theme]);
|
|
97
|
+
|
|
98
|
+
return <div ref={hostRef} className={h.previewHost.readableName} />;
|
|
99
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
4
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
|
+
* 2.0.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ReactNode } from 'react';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
demoTokenCatalog,
|
|
12
|
+
type DemoTokenCatalogEntry,
|
|
13
|
+
} from '../lib/demo_environment';
|
|
14
|
+
import { cx, ui } from '../setup/chrome';
|
|
15
|
+
|
|
16
|
+
import type { PreviewTheme } from './types';
|
|
17
|
+
|
|
18
|
+
const { handles: h } = ui;
|
|
19
|
+
|
|
20
|
+
const looksLikeCssColor = (value: string): boolean =>
|
|
21
|
+
/^#|^rgba?\(|^hsla?\(|^oklch\(|^lab\(/i.test(value.trim());
|
|
22
|
+
|
|
23
|
+
export interface TokensPanelProps {
|
|
24
|
+
readonly theme: PreviewTheme;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const TokensPanel = ({ theme }: TokensPanelProps): ReactNode => (
|
|
28
|
+
<section className={cx(h.panel, h.tokens)}>
|
|
29
|
+
<div className={h.toolbar.readableName}>
|
|
30
|
+
<h2>Tokens</h2>
|
|
31
|
+
</div>
|
|
32
|
+
<div className={h.tokenPanel.readableName}>
|
|
33
|
+
<table className={h.tokenTable.readableName}>
|
|
34
|
+
<thead>
|
|
35
|
+
<tr>
|
|
36
|
+
<th>Token</th>
|
|
37
|
+
<th>Value</th>
|
|
38
|
+
</tr>
|
|
39
|
+
</thead>
|
|
40
|
+
<tbody>
|
|
41
|
+
{demoTokenCatalog.map((entry) => (
|
|
42
|
+
<tr key={entry.access}>
|
|
43
|
+
<td>
|
|
44
|
+
<code>{entry.access}</code>
|
|
45
|
+
</td>
|
|
46
|
+
<td>
|
|
47
|
+
<TokenValue {...{ entry, theme }} />
|
|
48
|
+
</td>
|
|
49
|
+
</tr>
|
|
50
|
+
))}
|
|
51
|
+
</tbody>
|
|
52
|
+
</table>
|
|
53
|
+
</div>
|
|
54
|
+
</section>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
interface TokenValueProps {
|
|
58
|
+
readonly entry: DemoTokenCatalogEntry;
|
|
59
|
+
readonly theme: PreviewTheme;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const TokenValue = ({ entry, theme }: TokenValueProps): ReactNode => {
|
|
63
|
+
if (entry.kind === 'scale') {
|
|
64
|
+
return (
|
|
65
|
+
<span className={h.tokenValue.readableName}>
|
|
66
|
+
{entry.value}
|
|
67
|
+
{entry.cq !== entry.value ? ` · .cq ${entry.cq}` : null}
|
|
68
|
+
</span>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const showSwatches =
|
|
73
|
+
looksLikeCssColor(entry.light) || looksLikeCssColor(entry.dark);
|
|
74
|
+
const same = entry.light === entry.dark;
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<span className={h.tokenValue.readableName}>
|
|
78
|
+
{showSwatches ? (
|
|
79
|
+
<>
|
|
80
|
+
<ColorSwatch
|
|
81
|
+
color={entry.light}
|
|
82
|
+
active={theme === 'light'}
|
|
83
|
+
scheme="light"
|
|
84
|
+
/>
|
|
85
|
+
{same ? null : (
|
|
86
|
+
<ColorSwatch
|
|
87
|
+
color={entry.dark}
|
|
88
|
+
active={theme === 'dark'}
|
|
89
|
+
scheme="dark"
|
|
90
|
+
/>
|
|
91
|
+
)}
|
|
92
|
+
</>
|
|
93
|
+
) : null}
|
|
94
|
+
{same ? entry.light : `${entry.light} / ${entry.dark}`}
|
|
95
|
+
</span>
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
interface ColorSwatchProps {
|
|
100
|
+
readonly color: string;
|
|
101
|
+
readonly active: boolean;
|
|
102
|
+
readonly scheme: PreviewTheme;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const ColorSwatch = ({
|
|
106
|
+
color,
|
|
107
|
+
active,
|
|
108
|
+
scheme,
|
|
109
|
+
}: ColorSwatchProps): ReactNode => (
|
|
110
|
+
<span
|
|
111
|
+
className={h.swatch.readableName}
|
|
112
|
+
data-active={active ? '' : undefined}
|
|
113
|
+
title={`${scheme} ${color}`}
|
|
114
|
+
aria-label={`${scheme} ${color}`}
|
|
115
|
+
style={{ background: color }}
|
|
116
|
+
/>
|
|
117
|
+
);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
4
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
|
+
* 2.0.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type PreviewTheme = 'light' | 'dark';
|
|
9
|
+
|
|
10
|
+
export type CssTab = 'readable' | 'compact' | 'artifact';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
4
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
|
+
* 2.0.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, expect, it } from 'vitest';
|
|
9
|
+
|
|
10
|
+
import { snippetById, snippetCatalog, snippets } from './snippets';
|
|
11
|
+
|
|
12
|
+
describe('snippet catalog', () => {
|
|
13
|
+
it('lists the same ids and labels in both modes', () => {
|
|
14
|
+
const meta = (mode: 'emotion' | 'native') =>
|
|
15
|
+
snippets[mode].map(({ id, label }) => ({ id, label }));
|
|
16
|
+
expect(meta('emotion')).toEqual(meta('native'));
|
|
17
|
+
expect(snippets.emotion.map(({ id }) => id)).toEqual(
|
|
18
|
+
snippetCatalog.map(({ id }) => id)
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('loads both authoring modes from one snippet id', () => {
|
|
23
|
+
const bundle = snippetById('tree-shake');
|
|
24
|
+
expect(bundle?.id).toBe('tree-shake');
|
|
25
|
+
expect(bundle?.source.emotion).toContain('css`');
|
|
26
|
+
expect(bundle?.source.native).toContain('createStyleModule');
|
|
27
|
+
});
|
|
28
|
+
});
|