@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,16 @@
|
|
|
1
|
+
/** `globalThis` key for the loaded copy's identity. See the README. */
|
|
2
|
+
export declare const INSTANCE_KEY: unique symbol;
|
|
3
|
+
/** Object that may hold the Distillate instance identity, normally `globalThis`. */
|
|
4
|
+
export interface InstanceHost {
|
|
5
|
+
/** Identity token of the first Distillate copy that registered. */
|
|
6
|
+
[INSTANCE_KEY]?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Records this copy's identity and warns if a different token is already registered.
|
|
10
|
+
*
|
|
11
|
+
* @param host Object carrying the marker, normally `globalThis`.
|
|
12
|
+
* @param instanceId This copy's identity token.
|
|
13
|
+
* @param warn Injected so tests need not intercept the console.
|
|
14
|
+
*/
|
|
15
|
+
export declare const registerDistillateInstance: (host: InstanceHost, instanceId: string, warn?: (message: string) => void) => void;
|
|
16
|
+
//# sourceMappingURL=instance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../src/instance.ts"],"names":[],"mappings":"AAOA,uEAAuE;AACvE,eAAO,MAAM,YAAY,EAAE,OAAO,MAEjC,CAAC;AAEF,oFAAoF;AACpF,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACrC,MAAM,YAAY,EAClB,YAAY,MAAM,EAClB,OAAM,CAAC,OAAO,EAAE,MAAM,KAAK,IAAyC,KACnE,IAcF,CAAC"}
|
package/dist/instance.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
/** `globalThis` key for the loaded copy's identity. See the README. */
|
|
8
|
+
export const INSTANCE_KEY = Symbol.for('elastic.distillate.instance');
|
|
9
|
+
/**
|
|
10
|
+
* Records this copy's identity and warns if a different token is already registered.
|
|
11
|
+
*
|
|
12
|
+
* @param host Object carrying the marker, normally `globalThis`.
|
|
13
|
+
* @param instanceId This copy's identity token.
|
|
14
|
+
* @param warn Injected so tests need not intercept the console.
|
|
15
|
+
*/
|
|
16
|
+
export const registerDistillateInstance = (host, instanceId, warn = (message) => console.warn(message)) => {
|
|
17
|
+
const registered = host[INSTANCE_KEY];
|
|
18
|
+
if (registered === undefined) {
|
|
19
|
+
host[INSTANCE_KEY] = instanceId;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (registered === instanceId) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
warn(`@elastic/distillate: a second copy loaded (${instanceId}; already registered ${registered}). ` +
|
|
26
|
+
'The engine keeps module-scope state, so two copies silently break `variants(...)` tree-shaking ' +
|
|
27
|
+
'and inflate emitted CSS. Externalize @elastic/distillate in your bundler so exactly one copy loads.');
|
|
28
|
+
};
|
|
29
|
+
registerDistillateInstance(globalThis, `@elastic/distillate/instance#${Math.random().toString(36).slice(2)}`);
|
|
30
|
+
//# sourceMappingURL=instance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance.js","sourceRoot":"","sources":["../src/instance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uEAAuE;AACvE,MAAM,CAAC,MAAM,YAAY,GAAkB,MAAM,CAAC,GAAG,CACnD,6BAA6B,CAC9B,CAAC;AAQF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,IAAkB,EAClB,UAAkB,EAClB,OAAkC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAC9D,EAAE;IACR,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;IACtC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,IAAI,CAAC,YAAY,CAAC,GAAG,UAAU,CAAC;QAChC,OAAO;IACT,CAAC;IACD,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO;IACT,CAAC;IACD,IAAI,CACF,8CAA8C,UAAU,wBAAwB,UAAU,KAAK;QAC7F,iGAAiG;QACjG,qGAAqG,CACxG,CAAC;AACJ,CAAC,CAAC;AAEF,0BAA0B,CACxB,UAA0B,EAC1B,gCAAgC,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CACtE,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n/** `globalThis` key for the loaded copy's identity. See the README. */\nexport const INSTANCE_KEY: unique symbol = Symbol.for(\n 'elastic.distillate.instance'\n);\n\n/** Object that may hold the Distillate instance identity, normally `globalThis`. */\nexport interface InstanceHost {\n /** Identity token of the first Distillate copy that registered. */\n [INSTANCE_KEY]?: string;\n}\n\n/**\n * Records this copy's identity and warns if a different token is already registered.\n *\n * @param host Object carrying the marker, normally `globalThis`.\n * @param instanceId This copy's identity token.\n * @param warn Injected so tests need not intercept the console.\n */\nexport const registerDistillateInstance = (\n host: InstanceHost,\n instanceId: string,\n warn: (message: string) => void = (message) => console.warn(message)\n): void => {\n const registered = host[INSTANCE_KEY];\n if (registered === undefined) {\n host[INSTANCE_KEY] = instanceId;\n return;\n }\n if (registered === instanceId) {\n return;\n }\n warn(\n `@elastic/distillate: a second copy loaded (${instanceId}; already registered ${registered}). ` +\n 'The engine keeps module-scope state, so two copies silently break `variants(...)` tree-shaking ' +\n 'and inflate emitted CSS. Externalize @elastic/distillate in your bundler so exactly one copy loads.'\n );\n};\n\nregisterDistillateInstance(\n globalThis as InstanceHost,\n `@elastic/distillate/instance#${Math.random().toString(36).slice(2)}`\n);\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ContextualVarPath, CssValue } from './styles/types.js';
|
|
2
|
+
/** Reference to a local CSS variable. Stringifies to `var(--...)`. */
|
|
3
|
+
export interface LocalVarRef {
|
|
4
|
+
/** Brand distinguishing a local-var ref from other interpolations. */
|
|
5
|
+
readonly __kind: 'local-var-ref';
|
|
6
|
+
/** Canonical group/key path. */
|
|
7
|
+
readonly path: ContextualVarPath;
|
|
8
|
+
/** Actual emitted CSS custom property name. */
|
|
9
|
+
readonly propName: `--${string}`;
|
|
10
|
+
/** Usable CSS `var(...)` reference string. */
|
|
11
|
+
readonly ref: `var(--${string})`;
|
|
12
|
+
/** Stringifies to {@link LocalVarRef.ref}. */
|
|
13
|
+
toString(): string;
|
|
14
|
+
/** Template interpolation; same as {@link LocalVarRef.toString}. */
|
|
15
|
+
[Symbol.toPrimitive](hint: string): string;
|
|
16
|
+
}
|
|
17
|
+
/** Interpolation marker representing `.set(...)` overrides. */
|
|
18
|
+
export interface LocalVarOverrideMarker {
|
|
19
|
+
/** Brand distinguishing a `.set(...)` override marker. */
|
|
20
|
+
readonly __kind: 'local-var-override-marker';
|
|
21
|
+
/** Unique ID for the group. */
|
|
22
|
+
readonly groupId: string;
|
|
23
|
+
/** Ordered list of variable overrides. */
|
|
24
|
+
readonly overrides: ReadonlyArray<{
|
|
25
|
+
/** Variable key within the group. */
|
|
26
|
+
readonly key: string;
|
|
27
|
+
/** Canonical group/key path. */
|
|
28
|
+
readonly path: ContextualVarPath;
|
|
29
|
+
/** Actual emitted CSS custom property name. */
|
|
30
|
+
readonly propName: `--${string}`;
|
|
31
|
+
/** Override value written at this interpolation site. */
|
|
32
|
+
readonly value: CssValue;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
/** Interpolation marker representing `${group}` defaults. */
|
|
36
|
+
export interface LocalVarDefaultMarker {
|
|
37
|
+
/** Brand distinguishing a `${group}` default marker. */
|
|
38
|
+
readonly __kind: 'local-var-default-marker';
|
|
39
|
+
/** Unique ID for the group. */
|
|
40
|
+
readonly groupId: string;
|
|
41
|
+
/** Group prefix path. */
|
|
42
|
+
readonly groupPath: `vars/${string}`;
|
|
43
|
+
/** Ordered list of variable defaults. */
|
|
44
|
+
readonly defaults: ReadonlyArray<{
|
|
45
|
+
/** Variable key within the group. */
|
|
46
|
+
readonly key: string;
|
|
47
|
+
/** Canonical group/key path. */
|
|
48
|
+
readonly path: ContextualVarPath;
|
|
49
|
+
/** Actual emitted CSS custom property name. */
|
|
50
|
+
readonly propName: `--${string}`;
|
|
51
|
+
/** Default value emitted when this key is reachable. */
|
|
52
|
+
readonly value: CssValue;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
55
|
+
/** Interpolation marker: `${group}` defaults or `${group.set(...)}` overrides. */
|
|
56
|
+
export type LocalVarMarker = LocalVarOverrideMarker | LocalVarDefaultMarker;
|
|
57
|
+
/**
|
|
58
|
+
* Value returned by `t.vars(...)`. Interpolate `${group}`, `${group.key}`, or `${group.set({...})}`.
|
|
59
|
+
*/
|
|
60
|
+
export type LocalVarGroup<TKey extends string> = {
|
|
61
|
+
readonly [P in TKey]: LocalVarRef;
|
|
62
|
+
} & {
|
|
63
|
+
/** Builds a marker that writes the given keys at the interpolation site. */
|
|
64
|
+
set(overrides: Partial<Record<TKey, CssValue>>): LocalVarOverrideMarker;
|
|
65
|
+
};
|
|
66
|
+
/** `true` when `value` is a {@link LocalVarRef}. */
|
|
67
|
+
export declare const isLocalVarRef: (value: unknown) => value is LocalVarRef;
|
|
68
|
+
/** `true` when `value` is a {@link LocalVarDefaultMarker}. */
|
|
69
|
+
export declare const isLocalVarDefaultMarker: (value: unknown) => value is LocalVarDefaultMarker;
|
|
70
|
+
/** `true` when `value` is a {@link LocalVarOverrideMarker}. */
|
|
71
|
+
export declare const isLocalVarOverrideMarker: (value: unknown) => value is LocalVarOverrideMarker;
|
|
72
|
+
/** `true` when `value` is a {@link LocalVarDefaultMarker} or {@link LocalVarOverrideMarker}. */
|
|
73
|
+
export declare const isLocalVarMarker: (value: unknown) => value is LocalVarMarker;
|
|
74
|
+
export declare const createLocalVarGroup: <TKey extends string>(prefix: string, moduleName: string, group: string, defaults: Record<TKey, CssValue>) => LocalVarGroup<TKey>;
|
|
75
|
+
//# sourceMappingURL=local_vars.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local_vars.d.ts","sourceRoot":"","sources":["../src/local_vars.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAOlE,sEAAsE;AACtE,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,gCAAgC;IAChC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,+CAA+C;IAC/C,QAAQ,CAAC,QAAQ,EAAE,KAAK,MAAM,EAAE,CAAC;IACjC,8CAA8C;IAC9C,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,GAAG,CAAC;IACjC,8CAA8C;IAC9C,QAAQ,IAAI,MAAM,CAAC;IACnB,oEAAoE;IACpE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5C;AAED,+DAA+D;AAC/D,MAAM,WAAW,sBAAsB;IACrC,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC;IAC7C,+BAA+B;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;QAChC,qCAAqC;QACrC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QACrB,gCAAgC;QAChC,QAAQ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AO,OAAO,KACb,KAAK,IAAI,qBAKT,CAAC;AAEJ,+DAA+D;AAC/D,eAAO,MAAM,wBAAwB,GACnC,OAAO,OAAO,KACb,KAAK,IAAI,sBAKT,CAAC;AAEJ,gGAAgG;AAChG,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,cACQ,CAAC;AA6BpE,eAAO,MAAM,mBAAmB,GAAI,IAAI,SAAS,MAAM,EACrD,QAAQ,MAAM,EACd,YAAY,MAAM,EAClB,OAAO,MAAM,EACb,UAAU,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,KAC/B,aAAa,CAAC,IAAI,CAsEpB,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
import { assertCssIdentSegment } from './idents.js';
|
|
8
|
+
import { cssVarName } from './names.js';
|
|
9
|
+
const RESERVED_DEFAULT_KEYS = new Set(['set', 'toString', 'valueOf', 'toJSON']);
|
|
10
|
+
const isReservedKey = (key) => RESERVED_DEFAULT_KEYS.has(key) || key.startsWith('__');
|
|
11
|
+
/** `true` when `value` is a {@link LocalVarRef}. */
|
|
12
|
+
export const isLocalVarRef = (value) => Boolean(value &&
|
|
13
|
+
typeof value === 'object' &&
|
|
14
|
+
value.__kind === 'local-var-ref');
|
|
15
|
+
/** `true` when `value` is a {@link LocalVarDefaultMarker}. */
|
|
16
|
+
export const isLocalVarDefaultMarker = (value) => Boolean(value &&
|
|
17
|
+
typeof value === 'object' &&
|
|
18
|
+
value.__kind === 'local-var-default-marker');
|
|
19
|
+
/** `true` when `value` is a {@link LocalVarOverrideMarker}. */
|
|
20
|
+
export const isLocalVarOverrideMarker = (value) => Boolean(value &&
|
|
21
|
+
typeof value === 'object' &&
|
|
22
|
+
value.__kind === 'local-var-override-marker');
|
|
23
|
+
/** `true` when `value` is a {@link LocalVarDefaultMarker} or {@link LocalVarOverrideMarker}. */
|
|
24
|
+
export const isLocalVarMarker = (value) => isLocalVarDefaultMarker(value) || isLocalVarOverrideMarker(value);
|
|
25
|
+
const cssVarPath = (moduleName, group, key) => `vars/${moduleName}/${group}/${key}`;
|
|
26
|
+
const buildLocalVarRef = (path, propName) => {
|
|
27
|
+
const ref = `var(${propName})`;
|
|
28
|
+
const refToString = () => ref;
|
|
29
|
+
return {
|
|
30
|
+
__kind: 'local-var-ref',
|
|
31
|
+
path,
|
|
32
|
+
propName,
|
|
33
|
+
ref,
|
|
34
|
+
toString: refToString,
|
|
35
|
+
[Symbol.toPrimitive]: refToString,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const reservedKeyError = (key) => new Error(`t.vars(...) defaults key "${key}" is reserved. Reserved: ${[...RESERVED_DEFAULT_KEYS].join(', ')} plus any "__"-prefixed key.`);
|
|
39
|
+
export const createLocalVarGroup = (prefix, moduleName, group, defaults) => {
|
|
40
|
+
assertCssIdentSegment(group, 't.vars(...) group');
|
|
41
|
+
const groupId = `${moduleName}/${group}`;
|
|
42
|
+
const groupPath = `vars/${groupId}`;
|
|
43
|
+
const refs = new Map();
|
|
44
|
+
const defaultsList = [];
|
|
45
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
46
|
+
if (isReservedKey(key)) {
|
|
47
|
+
throw reservedKeyError(key);
|
|
48
|
+
}
|
|
49
|
+
assertCssIdentSegment(key, `t.vars("${group}") key`);
|
|
50
|
+
const path = cssVarPath(moduleName, group, key);
|
|
51
|
+
const propName = cssVarName(prefix, path);
|
|
52
|
+
refs.set(key, buildLocalVarRef(path, propName));
|
|
53
|
+
defaultsList.push({ key, path, propName, value });
|
|
54
|
+
}
|
|
55
|
+
const setOverrides = (overrides) => {
|
|
56
|
+
const list = [];
|
|
57
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
58
|
+
if (value === undefined) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const ref = refs.get(key);
|
|
62
|
+
if (!ref) {
|
|
63
|
+
throw new Error(`t.vars("${group}").set: unknown key "${key}". Declared keys: ${defaultsList
|
|
64
|
+
.map((entry) => entry.key)
|
|
65
|
+
.join(', ')}.`);
|
|
66
|
+
}
|
|
67
|
+
list.push({ key, path: ref.path, propName: ref.propName, value });
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
__kind: 'local-var-override-marker',
|
|
71
|
+
groupId,
|
|
72
|
+
overrides: list,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
const group_ = {
|
|
76
|
+
__kind: 'local-var-default-marker',
|
|
77
|
+
groupId,
|
|
78
|
+
groupPath,
|
|
79
|
+
defaults: defaultsList,
|
|
80
|
+
set: setOverrides,
|
|
81
|
+
};
|
|
82
|
+
for (const [key, ref] of refs) {
|
|
83
|
+
Object.defineProperty(group_, key, {
|
|
84
|
+
value: ref,
|
|
85
|
+
enumerable: true,
|
|
86
|
+
writable: false,
|
|
87
|
+
configurable: false,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return group_;
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=local_vars.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local_vars.js","sourceRoot":"","sources":["../src/local_vars.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEhF,MAAM,aAAa,GAAG,CAAC,GAAW,EAAW,EAAE,CAC7C,qBAAqB,CAAC,GAAG,CAAC,GAAG,C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K,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAElD,EAAE,CAAC;YACF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,SAAS;YACX,CAAC;YACD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,MAAM,IAAI,KAAK,CACb,WAAW,KAAK,wBAAwB,GAAG,qBAAqB,YAAY;qBACzE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC;qBACzB,IAAI,CAAC,IAAI,CAAC,GAAG,CACjB,CAAC;YACJ,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,OAAO;YACL,MAAM,EAAE,2BAA2B;YACnC,OAAO;YACP,SAAS,EAAE,IAAI;SAChB,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,MAAM,GAAG;QACb,MAAM,EAAE,0BAA0B;QAClC,OAAO;QACP,SAAS;QACT,QAAQ,EAAE,YAAY;QACtB,GAAG,EAAE,YAAY;KACgB,CAAC;IAEpC,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9B,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE;YACjC,KAAK,EAAE,GAAG;YACV,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,KAAK;YACf,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport { assertCssIdentSegment } from './idents';\nimport { cssVarName } from './names';\nimport type { ContextualVarPath, CssValue } from './styles/types';\n\nconst RESERVED_DEFAULT_KEYS = new Set(['set', 'toString', 'valueOf', 'toJSON']);\n\nconst isReservedKey = (key: string): boolean =>\n RESERVED_DEFAULT_KEYS.has(key) || key.startsWith('__');\n\n/** Reference to a local CSS variable. Stringifies to `var(--...)`. */\nexport interface LocalVarRef {\n /** Brand distinguishing a local-var ref from other interpolations. */\n readonly __kind: 'local-var-ref';\n /** Canonical group/key path. */\n readonly path: ContextualVarPath;\n /** Actual emitted CSS custom property name. */\n readonly propName: `--${string}`;\n /** Usable CSS `var(...)` reference string. */\n readonly ref: `var(--${string})`;\n /** Stringifies to {@link LocalVarRef.ref}. */\n toString(): string;\n /** Template interpolation; same as {@link LocalVarRef.toString}. */\n [Symbol.toPrimitive](hint: string): string;\n}\n\n/** Interpolation marker representing `.set(...)` overrides. */\nexport interface LocalVarOverrideMarker {\n /** Brand distinguishing a `.set(...)` override marker. */\n readonly __kind: 'local-var-override-marker';\n /** Unique ID for the group. */\n readonly groupId: string;\n /** Ordered list of variable overrides. */\n readonly overrides: ReadonlyArray<{\n /** Variable key within the group. */\n readonly key: string;\n /** Canonical group/key path. */\n readonly path: ContextualVarPath;\n /** Actual emitted CSS custom property name. */\n readonly propName: `--${string}`;\n /** Override value written at this interpolation site. */\n readonly value: CssValue;\n }>;\n}\n\n/** Interpolation marker representing `${group}` defaults. */\nexport interface LocalVarDefaultMarker {\n /** Brand distinguishing a `${group}` default marker. */\n readonly __kind: 'local-var-default-marker';\n /** Unique ID for the group. */\n readonly groupId: string;\n /** Group prefix path. */\n readonly groupPath: `vars/${string}`;\n /** Ordered list of variable defaults. */\n readonly defaults: ReadonlyArray<{\n /** Variable key within the group. */\n readonly key: string;\n /** Canonical group/key path. */\n readonly path: ContextualVarPath;\n /** Actual emitted CSS custom property name. */\n readonly propName: `--${string}`;\n /** Default value emitted when this key is reachable. */\n readonly value: CssValue;\n }>;\n}\n\n/** Interpolation marker: `${group}` defaults or `${group.set(...)}` overrides. */\nexport type LocalVarMarker = LocalVarOverrideMarker | LocalVarDefaultMarker;\n\n/**\n * Value returned by `t.vars(...)`. Interpolate `${group}`, `${group.key}`, or `${group.set({...})}`.\n */\nexport type LocalVarGroup<TKey extends string> = {\n readonly [P in TKey]: LocalVarRef;\n} & {\n /** Builds a marker that writes the given keys at the interpolation site. */\n set(overrides: Partial<Record<TKey, CssValue>>): LocalVarOverrideMarker;\n};\n\n/** `true` when `value` is a {@link LocalVarRef}. */\nexport const isLocalVarRef = (value: unknown): value is LocalVarRef =>\n Boolean(\n value &&\n typeof value === 'object' &&\n (value as { __kind?: string }).__kind === 'local-var-ref'\n );\n\n/** `true` when `value` is a {@link LocalVarDefaultMarker}. */\nexport const isLocalVarDefaultMarker = (\n value: unknown\n): value is LocalVarDefaultMarker =>\n Boolean(\n value &&\n typeof value === 'object' &&\n (value as { __kind?: string }).__kind === 'local-var-default-marker'\n );\n\n/** `true` when `value` is a {@link LocalVarOverrideMarker}. */\nexport const isLocalVarOverrideMarker = (\n value: unknown\n): value is LocalVarOverrideMarker =>\n Boolean(\n value &&\n typeof value === 'object' &&\n (value as { __kind?: string }).__kind === 'local-var-override-marker'\n );\n\n/** `true` when `value` is a {@link LocalVarDefaultMarker} or {@link LocalVarOverrideMarker}. */\nexport const isLocalVarMarker = (value: unknown): value is LocalVarMarker =>\n isLocalVarDefaultMarker(value) || isLocalVarOverrideMarker(value);\n\nconst cssVarPath = (\n moduleName: string,\n group: string,\n key: string\n): ContextualVarPath => `vars/${moduleName}/${group}/${key}`;\n\nconst buildLocalVarRef = (\n path: ContextualVarPath,\n propName: `--${string}`\n): LocalVarRef => {\n const ref: `var(--${string})` = `var(${propName})`;\n const refToString = (): string => ref;\n return {\n __kind: 'local-var-ref',\n path,\n propName,\n ref,\n toString: refToString,\n [Symbol.toPrimitive]: refToString,\n };\n};\n\nconst reservedKeyError = (key: string): Error =>\n new Error(\n `t.vars(...) defaults key \"${key}\" is reserved. Reserved: ${[...RESERVED_DEFAULT_KEYS].join(', ')} plus any \"__\"-prefixed key.`\n );\n\nexport const createLocalVarGroup = <TKey extends string>(\n prefix: string,\n moduleName: string,\n group: string,\n defaults: Record<TKey, CssValue>\n): LocalVarGroup<TKey> => {\n assertCssIdentSegment(group, 't.vars(...) group');\n const groupId = `${moduleName}/${group}`;\n const groupPath = `vars/${groupId}`;\n const refs = new Map<TKey, LocalVarRef>();\n const defaultsList: Array<{\n readonly key: string;\n readonly path: ContextualVarPath;\n readonly propName: `--${string}`;\n readonly value: CssValue;\n }> = [];\n\n for (const [key, value] of Object.entries(defaults) as Array<\n [TKey, CssValue]\n >) {\n if (isReservedKey(key)) {\n throw reservedKeyError(key);\n }\n assertCssIdentSegment(key, `t.vars(\"${group}\") key`);\n const path = cssVarPath(moduleName, group, key);\n const propName = cssVarName(prefix, path);\n refs.set(key, buildLocalVarRef(path, propName));\n defaultsList.push({ key, path, propName, value });\n }\n\n const setOverrides = (\n overrides: Partial<Record<TKey, CssValue>>\n ): LocalVarOverrideMarker => {\n const list: Array<LocalVarOverrideMarker['overrides'][number]> = [];\n for (const [key, value] of Object.entries(overrides) as Array<\n [TKey, CssValue | undefined]\n >) {\n if (value === undefined) {\n continue;\n }\n const ref = refs.get(key);\n if (!ref) {\n throw new Error(\n `t.vars(\"${group}\").set: unknown key \"${key}\". Declared keys: ${defaultsList\n .map((entry) => entry.key)\n .join(', ')}.`\n );\n }\n list.push({ key, path: ref.path, propName: ref.propName, value });\n }\n return {\n __kind: 'local-var-override-marker',\n groupId,\n overrides: list,\n };\n };\n\n const group_ = {\n __kind: 'local-var-default-marker',\n groupId,\n groupPath,\n defaults: defaultsList,\n set: setOverrides,\n } as unknown as LocalVarGroup<TKey>;\n\n for (const [key, ref] of refs) {\n Object.defineProperty(group_, key, {\n value: ref,\n enumerable: true,\n writable: false,\n configurable: false,\n });\n }\n\n return group_;\n};\n"]}
|
package/dist/minify.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strips comments and insignificant whitespace from CSS.
|
|
3
|
+
*
|
|
4
|
+
* Strings, unquoted `url(…)` tokens, and backslash escapes pass through
|
|
5
|
+
* untouched: their contents are literal, so a `/*` or a `;` inside one is data
|
|
6
|
+
* rather than syntax.
|
|
7
|
+
*
|
|
8
|
+
* @param value Raw CSS text.
|
|
9
|
+
*/
|
|
10
|
+
export declare const minifyCss: (value: string) => string;
|
|
11
|
+
//# sourceMappingURL=minify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minify.d.ts","sourceRoot":"","sources":["../src/minify.ts"],"names":[],"mappings":"AAkCA;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,MA2CzC,CAAC"}
|
package/dist/minify.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
import { scanCss } from './css_scan.js';
|
|
8
|
+
/**
|
|
9
|
+
* A space between two non-structural spans is significant wherever it sits: a
|
|
10
|
+
* descendant combinator in a selector (`.a .b`), a token separator in a value
|
|
11
|
+
* (`margin:0 auto`). Beside a structural character it is noise, except before
|
|
12
|
+
* a pseudo-class colon in a rules block — `.menu :hover` is not `.menu:hover`,
|
|
13
|
+
* while `color : red` is `color:red`.
|
|
14
|
+
*/
|
|
15
|
+
const spaceIsSignificant = (before, after) => {
|
|
16
|
+
if (!before || !after) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (before.kind === 'structural') {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (after.kind === 'structural') {
|
|
23
|
+
// Only a pseudo-class colon in a selector keeps the space in front of it.
|
|
24
|
+
// Space before `{`, `}`, `;`, `,`, or `>` is never significant.
|
|
25
|
+
return after.text === ':' && after.block === 'rules';
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Strips comments and insignificant whitespace from CSS.
|
|
31
|
+
*
|
|
32
|
+
* Strings, unquoted `url(…)` tokens, and backslash escapes pass through
|
|
33
|
+
* untouched: their contents are literal, so a `/*` or a `;` inside one is data
|
|
34
|
+
* rather than syntax.
|
|
35
|
+
*
|
|
36
|
+
* @param value Raw CSS text.
|
|
37
|
+
*/
|
|
38
|
+
export const minifyCss = (value) => {
|
|
39
|
+
// Dropping comments can leave two whitespace spans adjacent — `.a /*c*/ .b`
|
|
40
|
+
// — and emitting one space per span would keep both. Coalescing after the
|
|
41
|
+
// filter makes the run a single decision.
|
|
42
|
+
const spans = scanCss(value)
|
|
43
|
+
.filter((span) => span.kind !== 'comment')
|
|
44
|
+
.filter((span, index, all) => span.kind !== 'whitespace' || all[index - 1]?.kind !== 'whitespace');
|
|
45
|
+
const out = [];
|
|
46
|
+
// Indices into `spans` of what has been emitted, so lookaround skips the
|
|
47
|
+
// whitespace being decided about.
|
|
48
|
+
const significant = spans.filter((span) => span.kind !== 'whitespace');
|
|
49
|
+
let significantIndex = 0;
|
|
50
|
+
spans.forEach((span) => {
|
|
51
|
+
if (span.kind === 'whitespace') {
|
|
52
|
+
const before = significant[significantIndex - 1];
|
|
53
|
+
const after = significant[significantIndex];
|
|
54
|
+
if (spaceIsSignificant(before, after)) {
|
|
55
|
+
out.push(' ');
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// A declaration's terminator is redundant against the block's own close.
|
|
60
|
+
// Only a bare `;` qualifies: an escaped one is part of a value, and it
|
|
61
|
+
// arrives as an `escape` span rather than a structural `;`.
|
|
62
|
+
if (span.kind === 'structural' &&
|
|
63
|
+
span.text === '}' &&
|
|
64
|
+
significant[significantIndex - 1]?.kind === 'structural' &&
|
|
65
|
+
significant[significantIndex - 1]?.text === ';') {
|
|
66
|
+
out.pop();
|
|
67
|
+
}
|
|
68
|
+
out.push(span.text);
|
|
69
|
+
significantIndex += 1;
|
|
70
|
+
});
|
|
71
|
+
return out.join('').trim();
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=minify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minify.js","sourceRoot":"","sources":["../src/minify.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAgB,OAAO,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,kBAAkB,GAAG,CACzB,MAA2B,EAC3B,KAA0B,EACjB,EAAE;IACX,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAChC,0EAA0E;QAC1E,gEAAgE;QAChE,OAAO,KAAK,CAAC,IAAI,KAAK,GAAG,IAAI,KAAK,CAAC,KAAK,KAAK,OAAO,CAAC;IACvD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAa,EAAU,EAAE;IACjD,4EAA4E;IAC5E,0EAA0E;IAC1E,0CAA0C;IAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;SACzB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;SACzC,MAAM,CACL,CAAC,IAAI,EAAE,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,CAAC,IAAI,EAAE,CAAC;AAC7B,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport { type CssSpan, scanCss } from './css_scan';\n\n/**\n * A space between two non-structural spans is significant wherever it sits: a\n * descendant combinator in a selector (`.a .b`), a token separator in a value\n * (`margin:0 auto`). Beside a structural character it is noise, except before\n * a pseudo-class colon in a rules block — `.menu :hover` is not `.menu:hover`,\n * while `color : red` is `color:red`.\n */\nconst spaceIsSignificant = (\n before: CssSpan | undefined,\n after: CssSpan | undefined\n): boolean => {\n if (!before || !after) {\n return false;\n }\n if (before.kind === 'structural') {\n return false;\n }\n if (after.kind === 'structural') {\n // Only a pseudo-class colon in a selector keeps the space in front of it.\n // Space before `{`, `}`, `;`, `,`, or `>` is never significant.\n return after.text === ':' && after.block === 'rules';\n }\n return true;\n};\n\n/**\n * Strips comments and insignificant whitespace from CSS.\n *\n * Strings, unquoted `url(…)` tokens, and backslash escapes pass through\n * untouched: their contents are literal, so a `/*` or a `;` inside one is data\n * rather than syntax.\n *\n * @param value Raw CSS text.\n */\nexport const minifyCss = (value: string): string => {\n // Dropping comments can leave two whitespace spans adjacent — `.a /*c*/ .b`\n // — and emitting one space per span would keep both. Coalescing after the\n // filter makes the run a single decision.\n const spans = scanCss(value)\n .filter((span) => span.kind !== 'comment')\n .filter(\n (span, index, all) =>\n span.kind !== 'whitespace' || all[index - 1]?.kind !== 'whitespace'\n );\n const out: string[] = [];\n // Indices into `spans` of what has been emitted, so lookaround skips the\n // whitespace being decided about.\n const significant = spans.filter((span) => span.kind !== 'whitespace');\n let significantIndex = 0;\n\n spans.forEach((span) => {\n if (span.kind === 'whitespace') {\n const before = significant[significantIndex - 1];\n const after = significant[significantIndex];\n if (spaceIsSignificant(before, after)) {\n out.push(' ');\n }\n return;\n }\n\n // A declaration's terminator is redundant against the block's own close.\n // Only a bare `;` qualifies: an escaped one is part of a value, and it\n // arrives as an `escape` span rather than a structural `;`.\n if (\n span.kind === 'structural' &&\n span.text === '}' &&\n significant[significantIndex - 1]?.kind === 'structural' &&\n significant[significantIndex - 1]?.text === ';'\n ) {\n out.pop();\n }\n\n out.push(span.text);\n significantIndex += 1;\n });\n\n return out.join('').trim();\n};\n"]}
|
package/dist/names.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Naming scheme: `compact` assigns sequential identifiers by sorted key index, `readable` emits descriptive ones. */
|
|
2
|
+
export type StyleNameMode = 'compact' | 'readable';
|
|
3
|
+
/** Destination format for the CSS collection. */
|
|
4
|
+
export type StyleTarget = 'artifact' | 'stylesheet';
|
|
5
|
+
/** Context for resolving keys into final class or custom-property names. */
|
|
6
|
+
export interface StyleNameResolver {
|
|
7
|
+
/** The naming mode used by this resolver. */
|
|
8
|
+
readonly names: StyleNameMode;
|
|
9
|
+
/** Resolves a handle key into a CSS class name. */
|
|
10
|
+
className(key: string, readableName?: string): string;
|
|
11
|
+
/** Resolves a variable key into a custom property name. */
|
|
12
|
+
cssVar(key: string): `--${string}`;
|
|
13
|
+
/** Resolves a variable key into a `var(...)` reference. */
|
|
14
|
+
cssVarRef(key: string): `var(--${string})`;
|
|
15
|
+
}
|
|
16
|
+
/** Inputs for {@link createStyleNameResolver}. */
|
|
17
|
+
export interface StyleNameResolverOptions {
|
|
18
|
+
/** Naming strategy (`compact` or `readable`). */
|
|
19
|
+
names: StyleNameMode;
|
|
20
|
+
/** Brand prefix for readable names (`<prefix>-<key>` / `--<prefix>-<key>`), e.g. `'aui'`. */
|
|
21
|
+
prefix: string;
|
|
22
|
+
/** Keys defining the compact class-name domain. */
|
|
23
|
+
classKeys?: Iterable<string>;
|
|
24
|
+
/** Keys defining the compact custom-property domain. */
|
|
25
|
+
cssVarKeys?: Iterable<string>;
|
|
26
|
+
}
|
|
27
|
+
export declare const compactNameForIndex: (index: number) => string;
|
|
28
|
+
/** Compact names are assigned from sorted keys so emission is deterministic. */
|
|
29
|
+
export declare const createCompactNameMap: (keys: Iterable<string>) => ReadonlyMap<string, string>;
|
|
30
|
+
/**
|
|
31
|
+
* Readable custom-property name: `--${prefix}-${path}` with `/` joined on `-` and a leading `vars/` stripped.
|
|
32
|
+
*
|
|
33
|
+
* @param prefix Brand prefix (e.g. `'eui'`).
|
|
34
|
+
* @param path Theme or contextual-var path (e.g. `'colors/ink'`, `'vars/chip/look/bg'`).
|
|
35
|
+
*/
|
|
36
|
+
export declare const cssVarName: (prefix: string, path: string) => `--${string}`;
|
|
37
|
+
/** Maps semantic keys to readable (`<prefix>-<key>`) or compact (`a`, `b`, …) names. */
|
|
38
|
+
export declare const createStyleNameResolver: ({ names, prefix, classKeys, cssVarKeys, }: StyleNameResolverOptions) => StyleNameResolver;
|
|
39
|
+
//# sourceMappingURL=names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../src/names.ts"],"names":[],"mappings":"AAOA,sHAAsH;AACtH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,UAAU,CAAC;AACnD,iDAAiD;AACjD,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,YAAY,CAAC;AAEpD,4EAA4E;AAC5E,MAAM,WAAW,iBAAiB;IAChC,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,mDAAmD;IACnD,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtD,2DAA2D;IAC3D,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,CAAC;IACnC,2DAA2D;IAC3D,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,GAAG,CAAC;CAC5C;AAED,kDAAkD;AAClD,MAAM,WAAW,wBAAwB;IACvC,iDAAiD;IACjD,KAAK,EAAE,aAAa,CAAC;IACrB,6FAA6F;IAC7F,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7B,wDAAwD;IACxD,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;CAC/B;AAID,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,KAAG,MAuBnD,CAAC;AAEF,gFAAgF;AAChF,eAAO,MAAM,oBAAoB,GAC/B,MAAM,QAAQ,CAAC,MAAM,CAAC,KACrB,WAAW,CAAC,MAAM,EAAE,MAAM,CAK5B,CAAC;AAQF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,EAAE,MAAM,MAAM,KAAG,KAAK,MAAM,EACF,CAAC;AAcpE,wFAAwF;AACxF,eAAO,MAAM,uBAAuB,GAAI,2CAKrC,wBAAwB,KAAG,iBAsB7B,CAAC"}
|
package/dist/names.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
const compactAlphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
8
|
+
export const compactNameForIndex = (index) => {
|
|
9
|
+
if (!Number.isInteger(index) || index < 0) {
|
|
10
|
+
throw new Error(`Compact name index must be a non-negative integer.`);
|
|
11
|
+
}
|
|
12
|
+
const base = compactAlphabet.length;
|
|
13
|
+
let remaining = index;
|
|
14
|
+
let length = 1;
|
|
15
|
+
while (remaining >= base ** length) {
|
|
16
|
+
remaining -= base ** length;
|
|
17
|
+
length += 1;
|
|
18
|
+
}
|
|
19
|
+
let name = '';
|
|
20
|
+
for (let position = length - 1; position >= 0; position -= 1) {
|
|
21
|
+
const divisor = base ** position;
|
|
22
|
+
const digit = Math.floor(remaining / divisor);
|
|
23
|
+
name += compactAlphabet[digit] ?? '';
|
|
24
|
+
remaining %= divisor;
|
|
25
|
+
}
|
|
26
|
+
return name;
|
|
27
|
+
};
|
|
28
|
+
/** Compact names are assigned from sorted keys so emission is deterministic. */
|
|
29
|
+
export const createCompactNameMap = (keys) => {
|
|
30
|
+
const uniqueKeys = [...new Set(keys)].sort();
|
|
31
|
+
return new Map(uniqueKeys.map((key, index) => [key, compactNameForIndex(index)]));
|
|
32
|
+
};
|
|
33
|
+
const readableClassName = (prefix, key, fallback) => fallback ?? `${prefix}-${key.replaceAll('/', '-')}`;
|
|
34
|
+
/**
|
|
35
|
+
* Readable custom-property name: `--${prefix}-${path}` with `/` joined on `-` and a leading `vars/` stripped.
|
|
36
|
+
*
|
|
37
|
+
* @param prefix Brand prefix (e.g. `'eui'`).
|
|
38
|
+
* @param path Theme or contextual-var path (e.g. `'colors/ink'`, `'vars/chip/look/bg'`).
|
|
39
|
+
*/
|
|
40
|
+
export const cssVarName = (prefix, path) => `--${prefix}-${path.replace(/^vars\//, '').replaceAll('/', '-')}`;
|
|
41
|
+
const compactLookup = (map, key, kind) => {
|
|
42
|
+
const name = map.get(key);
|
|
43
|
+
if (!name) {
|
|
44
|
+
throw new Error(`No compact ${kind} name registered for "${key}".`);
|
|
45
|
+
}
|
|
46
|
+
return name;
|
|
47
|
+
};
|
|
48
|
+
/** Maps semantic keys to readable (`<prefix>-<key>`) or compact (`a`, `b`, …) names. */
|
|
49
|
+
export const createStyleNameResolver = ({ names, prefix, classKeys = [], cssVarKeys = [], }) => {
|
|
50
|
+
const classMap = createCompactNameMap(classKeys);
|
|
51
|
+
const cssVarMap = createCompactNameMap(cssVarKeys);
|
|
52
|
+
const cssVar = (key) => {
|
|
53
|
+
if (names === 'readable') {
|
|
54
|
+
return cssVarName(prefix, key);
|
|
55
|
+
}
|
|
56
|
+
return `--${compactLookup(cssVarMap, key, 'CSS variable')}`;
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
names,
|
|
60
|
+
className: (key, fallback) => {
|
|
61
|
+
if (names === 'readable') {
|
|
62
|
+
return readableClassName(prefix, key, fallback);
|
|
63
|
+
}
|
|
64
|
+
return compactLookup(classMap, key, 'class');
|
|
65
|
+
},
|
|
66
|
+
cssVar,
|
|
67
|
+
cssVarRef: (key) => `var(${cssVar(key)})`,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.js","sourceRoot":"","sources":["../src/names.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA+BH,MAAM,eAAe,GAAG,sDAAsD,CAAC;AAE/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAa,EAAU,EAAE;IAC3D,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC;IACpC,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,OAAO,SAAS,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;QACnC,SAAS,IAAI,IAAI,IAAI,MAAM,CAAC;QAC5B,MAAM,IAAI,CAAC,CAAC;IACd,CAAC;IAED,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,KAAK,IAAI,QAAQ,GAAG,MAAM,GAAG,CAAC,EAAE,QAAQ,IAAI,CAAC,EAAE,QAAQ,IAAI,CAAC,EAAE,CAAC;QAC7D,MAAM,OAAO,GAAG,IAAI,IAAI,QAAQ,CAAC;QACjC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,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F,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EACtC,KAAK,EACL,MAAM,EACN,SAAS,GAAG,EAAE,EACd,UAAU,GAAG,EAAE,GACU,EAAqB,EAAE;IAChD,MAAM,QAAQ,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAC;IACjD,MAAM,SAAS,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAC;IAEnD,MAAM,MAAM,GAAG,CAAC,GAAW,EAAiB,EAAE;QAC5C,IAAI,KAAK,KAAK,UAAU,EAAE,CAAC;YACzB,OAAO,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,KAAK,aAAa,CAAC,SAAS,EAAE,GAAG,EAAE,cAAc,CAAC,EAAE,CAAC;IAC9D,CAAC,CAAC;IAEF,OAAO;QACL,KAAK;QACL,SAAS,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;YAC3B,IAAI,KAAK,KAAK,UAAU,EAAE,CAAC;gBACzB,OAAO,iBAAiB,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,aAAa,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;QACD,MAAM;QACN,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG;KAC1C,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n/** Naming scheme: `compact` assigns sequential identifiers by sorted key index, `readable` emits descriptive ones. */\nexport type StyleNameMode = 'compact' | 'readable';\n/** Destination format for the CSS collection. */\nexport type StyleTarget = 'artifact' | 'stylesheet';\n\n/** Context for resolving keys into final class or custom-property names. */\nexport interface StyleNameResolver {\n /** The naming mode used by this resolver. */\n readonly names: StyleNameMode;\n /** Resolves a handle key into a CSS class name. */\n className(key: string, readableName?: string): string;\n /** Resolves a variable key into a custom property name. */\n cssVar(key: string): `--${string}`;\n /** Resolves a variable key into a `var(...)` reference. */\n cssVarRef(key: string): `var(--${string})`;\n}\n\n/** Inputs for {@link createStyleNameResolver}. */\nexport interface StyleNameResolverOptions {\n /** Naming strategy (`compact` or `readable`). */\n names: StyleNameMode;\n /** Brand prefix for readable names (`<prefix>-<key>` / `--<prefix>-<key>`), e.g. `'aui'`. */\n prefix: string;\n /** Keys defining the compact class-name domain. */\n classKeys?: Iterable<string>;\n /** Keys defining the compact custom-property domain. */\n cssVarKeys?: Iterable<string>;\n}\n\nconst compactAlphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';\n\nexport const compactNameForIndex = (index: number): string => {\n if (!Number.isInteger(index) || index < 0) {\n throw new Error(`Compact name index must be a non-negative integer.`);\n }\n\n const base = compactAlphabet.length;\n let remaining = index;\n let length = 1;\n\n while (remaining >= base ** length) {\n remaining -= base ** length;\n length += 1;\n }\n\n let name = '';\n for (let position = length - 1; position >= 0; position -= 1) {\n const divisor = base ** position;\n const digit = Math.floor(remaining / divisor);\n name += compactAlphabet[digit] ?? '';\n remaining %= divisor;\n }\n\n return name;\n};\n\n/** Compact names are assigned from sorted keys so emission is deterministic. */\nexport const createCompactNameMap = (\n keys: Iterable<string>\n): ReadonlyMap<string, string> => {\n const uniqueKeys = [...new Set(keys)].sort();\n return new Map(\n uniqueKeys.map((key, index) => [key, compactNameForIndex(index)])\n );\n};\n\nconst readableClassName = (\n prefix: string,\n key: string,\n fallback?: string\n): string => fallback ?? `${prefix}-${key.replaceAll('/', '-')}`;\n\n/**\n * Readable custom-property name: `--${prefix}-${path}` with `/` joined on `-` and a leading `vars/` stripped.\n *\n * @param prefix Brand prefix (e.g. `'eui'`).\n * @param path Theme or contextual-var path (e.g. `'colors/ink'`, `'vars/chip/look/bg'`).\n */\nexport const cssVarName = (prefix: string, path: string): `--${string}` =>\n `--${prefix}-${path.replace(/^vars\\//, '').replaceAll('/', '-')}`;\n\nconst compactLookup = (\n map: ReadonlyMap<string, string>,\n key: string,\n kind: 'class' | 'CSS variable'\n): string => {\n const name = map.get(key);\n if (!name) {\n throw new Error(`No compact ${kind} name registered for \"${key}\".`);\n }\n return name;\n};\n\n/** Maps semantic keys to readable (`<prefix>-<key>`) or compact (`a`, `b`, …) names. */\nexport const createStyleNameResolver = ({\n names,\n prefix,\n classKeys = [],\n cssVarKeys = [],\n}: StyleNameResolverOptions): StyleNameResolver => {\n const classMap = createCompactNameMap(classKeys);\n const cssVarMap = createCompactNameMap(cssVarKeys);\n\n const cssVar = (key: string): `--${string}` => {\n if (names === 'readable') {\n return cssVarName(prefix, key);\n }\n return `--${compactLookup(cssVarMap, key, 'CSS variable')}`;\n };\n\n return {\n names,\n className: (key, fallback) => {\n if (names === 'readable') {\n return readableClassName(prefix, key, fallback);\n }\n return compactLookup(classMap, key, 'class');\n },\n cssVar,\n cssVarRef: (key) => `var(${cssVar(key)})`,\n };\n};\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { StyleHandle } from './styles/types.js';
|
|
2
|
+
/** Rebuilt template fragment in tagged-template shape (`strings.length === values.length + 1`). */
|
|
3
|
+
export interface TemplateSlice {
|
|
4
|
+
/** Literal pieces between interpolations. */
|
|
5
|
+
readonly strings: readonly string[];
|
|
6
|
+
/** Interpolated values, one per hole. */
|
|
7
|
+
readonly values: readonly unknown[];
|
|
8
|
+
}
|
|
9
|
+
/** `&`-relative selector fragment: literal text or a cross-class {@link StyleHandle}. */
|
|
10
|
+
export type SelectorPart = string | StyleHandle;
|
|
11
|
+
/** One comma alternative; parts concatenate into a selector. */
|
|
12
|
+
export type SelectorAlternative = readonly SelectorPart[];
|
|
13
|
+
/** Flattened nested rule: selector alternatives plus declaration slice. */
|
|
14
|
+
export interface FlattenedRule {
|
|
15
|
+
/** Discriminant for {@link FlattenedEntry}. */
|
|
16
|
+
readonly kind: 'rule';
|
|
17
|
+
/** Comma alternatives relative to the parent handle. */
|
|
18
|
+
readonly alternatives: readonly SelectorAlternative[];
|
|
19
|
+
/** Declaration template for this rule. */
|
|
20
|
+
readonly slice: TemplateSlice;
|
|
21
|
+
}
|
|
22
|
+
/** Flattened `@media` block: query, optional self declarations, nested rules. */
|
|
23
|
+
export interface FlattenedMedia {
|
|
24
|
+
/** Discriminant for {@link FlattenedEntry}. */
|
|
25
|
+
readonly kind: 'media';
|
|
26
|
+
/** Media query text. */
|
|
27
|
+
readonly query: string;
|
|
28
|
+
/** Bare declarations inside the block, applied to the self handle. */
|
|
29
|
+
readonly self?: TemplateSlice;
|
|
30
|
+
/** Nested `&` rules inside this media block. */
|
|
31
|
+
readonly rules: readonly FlattenedRule[];
|
|
32
|
+
}
|
|
33
|
+
/** Nested rule or `@media` produced by flattening. */
|
|
34
|
+
export type FlattenedEntry = FlattenedRule | FlattenedMedia;
|
|
35
|
+
/** Flattened `css` template: self declarations plus nested entries. */
|
|
36
|
+
export interface FlattenedTemplate {
|
|
37
|
+
/** Self-handle declarations. `null` in global mode. */
|
|
38
|
+
readonly self: TemplateSlice | null;
|
|
39
|
+
/** Sibling nested rules and media blocks. */
|
|
40
|
+
readonly nested: readonly FlattenedEntry[];
|
|
41
|
+
}
|
|
42
|
+
/** `self` keeps a host handle; `global` does not. */
|
|
43
|
+
export type FlattenMode = 'self' | 'global';
|
|
44
|
+
/** Mode and optional inlining hook for {@link flattenTemplate}. */
|
|
45
|
+
export interface FlattenOptions {
|
|
46
|
+
/** Whether the template authors a host handle or global rules. */
|
|
47
|
+
readonly mode: FlattenMode;
|
|
48
|
+
/**
|
|
49
|
+
* Optional splice of a value's source slice before compilation.
|
|
50
|
+
* Return `null`/`undefined` to serialize the value as a sentinel.
|
|
51
|
+
*/
|
|
52
|
+
readonly inlineValue?: (value: unknown, position: InterpolationPosition) => TemplateSlice | null | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** Where an interpolation sits in the serialized template. */
|
|
55
|
+
export type InterpolationPosition = 'selector' | 'statement';
|
|
56
|
+
export declare const hasNestedSyntax: (strings: readonly string[]) => boolean;
|
|
57
|
+
export declare const flattenTemplate: (strings: readonly string[], values: readonly unknown[], options: FlattenOptions) => FlattenedTemplate;
|
|
58
|
+
export declare const isHandleLike: (value: unknown) => value is StyleHandle;
|
|
59
|
+
//# sourceMappingURL=nesting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nesting.d.ts","sourceRoot":"","sources":["../src/nesting.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAQlD,mGAAmG;AACnG,MAAM,WAAW,aAAa;IAC5B,6CAA6C;IAC7C,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,yCAAyC;IACzC,QAAQ,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;CACrC;AAED,yFAAyF;AACzF,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,WAAW,CAAC;AAChD,gEAAgE;AAChE,MAAM,MAAM,mBAAmB,GAAG,SAAS,YAAY,EAAE,CAAC;AAE1D,2EAA2E;AAC3E,MAAM,WAAW,aAAa;IAC5B,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wDAAwD;IACxD,QAAQ,CAAC,YAAY,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACtD,0CAA0C;IAC1C,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;CAC/B;AAED,iFAAiF;AACjF,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,wBAAwB;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,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