@umber-style/vue 0.2.0-alpha.0 → 0.3.0-alpha.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/dist/index.cjs CHANGED
@@ -186,6 +186,7 @@ function createThemeKeys() {
186
186
  theme: Symbol("theme"),
187
187
  view: Symbol("view"),
188
188
  scope: Symbol("scope"),
189
+ nested: Symbol("nested"),
189
190
  engine: Symbol("engine")
190
191
  };
191
192
  }
@@ -197,8 +198,9 @@ function createThemeKeys() {
197
198
  * `setup` and again when it changes, which renders no styled component. It gives the engine its base
198
199
  * theme when it has none.
199
200
  * - A nested provider renders its wrapper: the theme class of the theme it was given (with the boundary
200
- * and scheme markers), the theme class of its merged theme (every variable, for where it is not inside
201
- * the wrapper above it), and the scope class, which has `display: contents`.
201
+ * and scheme markers), the theme class of the themes of the nested providers above it and its own,
202
+ * merged (for where it is not inside their wrappers; the outermost theme is left out, as it is on
203
+ * `:root` or on the class of `<html>`), and the scope class, which has `display: contents`.
202
204
  * - With `isRoot` it renders no element and makes no rule: the app puts `themeClass(theme)` on an
203
205
  * ancestor, usually `<html>`.
204
206
  *
@@ -235,15 +237,18 @@ function createThemeProvider(baseEngine, keys) {
235
237
  const cache = injectCache();
236
238
  const engine = cache === void 0 ? baseEngine : baseEngine.withCache(cache);
237
239
  const outer = (0, vue.inject)(keys.theme, null);
238
- const scope = (0, vue.inject)(keys.engine, null) === engine ? (0, vue.inject)(keys.scope, null) : null;
240
+ const isSameEngine = (0, vue.inject)(keys.engine, null) === engine;
241
+ const scope = isSameEngine ? (0, vue.inject)(keys.scope, null) : null;
242
+ const above = isSameEngine ? (0, vue.inject)(keys.nested, null) : null;
239
243
  const isNested = scope !== null && !props.isRoot;
240
244
  const readOuter = () => outer?.value ?? engine.givenTheme;
241
245
  const given = (0, vue.computed)(() => (0, _umber_style_core.resolveThemeInput)(props.theme, readOuter() ?? _umber_style_core.EMPTY_THEME));
242
246
  engine.adoptTheme(given.value);
243
247
  const merged = (0, vue.computed)(() => (0, _umber_style_core.mergeTheme)(readOuter(), given.value));
248
+ const nested = (0, vue.computed)(() => isNested ? (0, _umber_style_core.mergeTheme)(above?.value, given.value) : above?.value);
244
249
  const classes = (0, vue.computed)(() => {
245
250
  const own = engine.themeClass(given.value, props.colorScheme);
246
- const full = engine.themeId(merged.value, props.colorScheme);
251
+ const full = engine.themeId(nested.value, props.colorScheme);
247
252
  return [
248
253
  own,
249
254
  own.startsWith(`${full} `) ? "" : full,
@@ -252,6 +257,7 @@ function createThemeProvider(baseEngine, keys) {
252
257
  });
253
258
  (0, vue.provide)(keys.engine, engine);
254
259
  (0, vue.provide)(keys.theme, merged);
260
+ (0, vue.provide)(keys.nested, nested);
255
261
  (0, vue.provide)(keys.view, (0, vue.computed)(() => engine.createThemeView(merged.value)));
256
262
  (0, vue.provide)(keys.scope, isNested ? (0, vue.computed)(() => ({
257
263
  as: props.as,
@@ -287,6 +293,35 @@ function createThemeScope(keys) {
287
293
  })
288
294
  };
289
295
  }
296
+ // src/useStyleValue.ts
297
+ /**
298
+ * Makes `useStyleValue` for the cache `readCache` gives (the engine's), or the one of a `CacheProvider`
299
+ * above. It is called in `setup`: the value is made with a variable named from Vue's `useId`, so the
300
+ * server and the browser name it alike, its rule is declared when the component is mounted, with the
301
+ * number it holds then, and removed before it unmounts. Setting `value` changes the declaration in
302
+ * place, and renders nothing: the value is not reactive.
303
+ */
304
+ function createUseStyleValue(readCache) {
305
+ return function useStyleValue(initial, unit) {
306
+ const cache = injectCache() ?? readCache();
307
+ const value = (0, _umber_style_core.createLiveValue)(`--${cache.prefix}-value-${(0, _umber_style_core.hashString)((0, vue.useId)())}`, initial, unit);
308
+ let rule;
309
+ (0, vue.onMounted)(() => {
310
+ rule = (0, _umber_style_core.declareLiveValue)(cache, value);
311
+ });
312
+ (0, vue.onBeforeUnmount)(() => {
313
+ rule.remove();
314
+ rule = void 0;
315
+ });
316
+ return Object.defineProperty(value, "value", {
317
+ get: () => value.get(),
318
+ set: (next) => {
319
+ const text = (0, _umber_style_core.writeLiveValue)(value, next);
320
+ rule?.set(text);
321
+ }
322
+ });
323
+ };
324
+ }
290
325
  // src/createStyle.ts
291
326
  /** Makes the Vue styling over an engine: `styled`, sheets, the theme provider and `useTheme`. */
292
327
  function bindEngine(engine) {
@@ -313,6 +348,7 @@ function bindEngine(engine) {
313
348
  const entries = (0, _umber_style_core.isThemedSheet)(sheet) ? sheet.resolve(useThemeView(cache)) : sheet;
314
349
  return cache === void 0 ? entries : engine.withCache(cache).adoptSheet(entries);
315
350
  }),
351
+ useStyleValue: createUseStyleValue(() => engine.cache),
316
352
  apply: (...entries) => ({ class: ((0, _umber_style_core.findEntryCache)(entries) ?? engine.cache).css(...entries) || void 0 }),
317
353
  css: ((...args) => (0, _umber_style_core.createCssEntry)(engine.cache, args)),
318
354
  ThemeProvider: createThemeProvider(engine, keys),
@@ -354,6 +390,7 @@ function createDefaultStyle() {
354
390
  const styled = (0, _umber_style_core.withTagShorthands)(((tag, options) => (...args) => getStyle().styled(tag, options)(...args)));
355
391
  const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : (0, _umber_style_core.createDeferredRecord)(styles, () => getStyle().StyleSheet.create(styles))) };
356
392
  const useStyle = ((sheet) => getStyle().useStyle(sheet));
393
+ const useStyleValue = (initial, unit) => getStyle().useStyleValue(initial, unit);
357
394
  function useTheme() {
358
395
  return getStyle().useTheme();
359
396
  }
@@ -389,6 +426,7 @@ function createDefaultStyle() {
389
426
  styled,
390
427
  StyleSheet,
391
428
  useStyle,
429
+ useStyleValue,
392
430
  useTheme,
393
431
  ThemeProvider,
394
432
  ThemeScope,
@@ -403,7 +441,7 @@ function createDefaultStyle() {
403
441
  Global
404
442
  };
405
443
  }
406
- const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, ThemeProvider, ThemeScope, useThemeClass, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = (0, _umber_style_core.readSharedState)("vue.default-style@1", createDefaultStyle);
444
+ const { configure, getEngine, styled, StyleSheet, useStyle, useStyleValue, useTheme, ThemeProvider, ThemeScope, useThemeClass, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = (0, _umber_style_core.readSharedState)("vue.default-style@1", createDefaultStyle);
407
445
  exports.CacheProvider = CacheProvider;
408
446
  exports.Global = Global;
409
447
  exports.StyleSheet = StyleSheet;
@@ -463,6 +501,7 @@ Object.defineProperty(exports, "subtract", {
463
501
  });
464
502
  exports.themeClass = themeClass;
465
503
  exports.useStyle = useStyle;
504
+ exports.useStyleValue = useStyleValue;
466
505
  exports.useTheme = useTheme;
467
506
  exports.useThemeClass = useThemeClass;
468
507
  exports.when = when;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Component, ComputedRef, FunctionalComponent, IntrinsicElementAttributes, PropType } from "vue";
2
- import { AlphaColor, BindingOptions, CSSObject, Cache, ColorScheme, ComponentSelector, CssArgument, CssArgument as CssArgument$1, Engine, GlobalInput, GlobalInput as GlobalInput$1, GlobalStyleObject, GlobalStyleObject as GlobalStyleObject$1, GlobalStyles, GlobalStyles as GlobalStyles$1, GlobalStylesInput, Interpolation as Interpolation$1, InterpolationResult, InterpolationResult as InterpolationResult$1, Keyframes, Keyframes as Keyframes$1, KeyframesInput, KeyframesOptions, KeyframesSteps, KeyframesSteps as KeyframesSteps$1, NestedKey, ObjectSheet, SchemeKey, SchemeName, SerializedStyles, SerializedStyles as SerializedStyles$1, SheetEntry, SheetEntry as SheetEntry$1, SheetStyles, StaticTemplateValue, StaticTemplateValue as StaticTemplateValue$1, StyleInput, StyleObject, StyleTypeOptions, StylerOptions, TemplateValue, TemplateValue as TemplateValue$1, Theme as Theme$1, ThemeInput, ThemeInput as ThemeInput$1, ThemeKey, UmberCache, WebNested, WebProperties, WebStyleObject, WebStyleObject as WebStyleObject$1, add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
2
+ import { AlphaColor, BindingOptions, CSSObject, Cache, ColorScheme, ComponentSelector, CssArgument, CssArgument as CssArgument$1, Engine, GlobalInput, GlobalInput as GlobalInput$1, GlobalStyleObject, GlobalStyleObject as GlobalStyleObject$1, GlobalStyles, GlobalStyles as GlobalStyles$1, GlobalStylesInput, Interpolation as Interpolation$1, InterpolationResult, InterpolationResult as InterpolationResult$1, Keyframes, Keyframes as Keyframes$1, KeyframesInput, KeyframesOptions, KeyframesSteps, KeyframesSteps as KeyframesSteps$1, LiveValue, LiveValue as LiveValue$1, NestedKey, ObjectSheet, SchemeKey, SchemeName, SerializedStyles, SerializedStyles as SerializedStyles$1, SheetEntry, SheetEntry as SheetEntry$1, SheetStyles, StaticTemplateValue, StaticTemplateValue as StaticTemplateValue$1, StyleInput, StyleObject, StyleTypeOptions, StylerOptions, TemplateValue, TemplateValue as TemplateValue$1, Theme as Theme$1, ThemeInput, ThemeInput as ThemeInput$1, ThemeKey, UmberCache, WebNested, WebProperties, WebStyleObject, WebStyleObject as WebStyleObject$1, add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
3
3
  /**
4
4
  * The theme of the default style of this binding: what `styled`, `useTheme`, `StyleSheet` and
5
5
  * `ThemeProvider` of the default style read. It extends the core's `Theme`, so an app gives it members
@@ -108,8 +108,25 @@ export interface GlobalProps<T> {
108
108
  */
109
109
  styles: GlobalInput$1<T>;
110
110
  }
111
+ /**
112
+ * A value of `useStyleValue` in Vue: the reference to its variable in a style (`${left}`, or an
113
+ * operand of the helpers of tokens), with `value` in the shape of a ref: reading it gives the number,
114
+ * setting it changes the declaration of the variable in place, with no render. `get()` reads it too.
115
+ */
116
+ export interface StyleValueRef extends LiveValue$1 {
117
+ /** The number now; setting it changes what the variable declares. */
118
+ value: number;
119
+ }
111
120
  /** What `createStyle` and `bindEngine` return: the Vue styling of one engine. */
112
121
  export interface Style<T> {
122
+ /**
123
+ * A number that a style reads through a CSS variable of its own, for a value that changes often (a
124
+ * slider): `const left = useStyleValue(0, '%')` in `setup`, `${left}` in a style, `left.value = 40` to
125
+ * change it with no render. The number is written with `unit` after it, or as it is without one. Its
126
+ * rule is on `:root`, in the theme layer, while the component is mounted; the reference falls back to
127
+ * the first number, which a server render shows with no rule.
128
+ */
129
+ useStyleValue(initial: number, unit?: string): StyleValueRef;
113
130
  /** The engine every member writes through. */
114
131
  engine: Engine<T>;
115
132
  /** The cache of the engine: its rules and sheet. */
@@ -198,6 +215,7 @@ export declare function createDefaultStyle(): {
198
215
  <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
199
216
  <S extends import("@umber-style/core").SheetStyles>(sheet: Sheet<S>): { [K in keyof S]: import("@umber-style/core").SheetEntry; };
200
217
  };
218
+ useStyleValue: (initial: number, unit?: string) => StyleValueRef;
201
219
  useTheme: () => ComputedRef<Theme>;
202
220
  ThemeProvider: Component<ThemeProviderProps<Theme>>;
203
221
  ThemeScope: Component;
@@ -243,7 +261,7 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
243
261
  }, useStyle: {
244
262
  <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
245
263
  <S extends import("@umber-style/core").SheetStyles>(sheet: Sheet<S>): { [K in keyof S]: import("@umber-style/core").SheetEntry; };
246
- }, useTheme: () => import("vue").ComputedRef<Theme>, ThemeProvider: import("vue").Component<ThemeProviderProps<Theme>>, ThemeScope: import("vue").Component, useThemeClass: () => import("vue").ComputedRef<string | undefined>, apply: (...entries: (import("@umber-style/core").SheetEntry | string | null | undefined | false)[]) => {
264
+ }, useStyleValue: (initial: number, unit?: string) => StyleValueRef, useTheme: () => import("vue").ComputedRef<Theme>, ThemeProvider: import("vue").Component<ThemeProviderProps<Theme>>, ThemeScope: import("vue").Component, useThemeClass: () => import("vue").ComputedRef<string | undefined>, apply: (...entries: (import("@umber-style/core").SheetEntry | string | null | undefined | false)[]) => {
247
265
  class?: string;
248
266
  }, css: CssFunction, themeClass: (theme: {
249
267
  readonly _theme?: never;
@@ -258,4 +276,4 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
258
276
  (template: TemplateStringsArray, ...values: import("@umber-style/core").TemplateValue<unknown, Theme>[]): import("@umber-style/core").GlobalStyles<Theme>;
259
277
  (styles: import("@umber-style/core").GlobalStylesInput<Theme>): import("@umber-style/core").GlobalStyles<Theme>;
260
278
  }, Global: import("vue").Component<GlobalProps<Theme>>;
261
- export { type AlphaColor, type CSSObject, type ComponentSelector, type CssArgument, type GlobalInput, type GlobalStyleObject, type GlobalStyles, type InterpolationResult, type Keyframes, type KeyframesSteps, type NestedKey, type SchemeKey, type SchemeName, type SerializedStyles, type SheetEntry, type StaticTemplateValue, type StyleObject, type StyleTypeOptions, type TemplateValue, type ThemeInput, type ThemeKey, type UmberCache, type WebNested, type WebProperties, type WebStyleObject, add, alpha, at, divide, multiply, negate, subtract };
279
+ export { type AlphaColor, type CSSObject, type ComponentSelector, type CssArgument, type GlobalInput, type GlobalStyleObject, type GlobalStyles, type InterpolationResult, type Keyframes, type KeyframesSteps, type LiveValue, type NestedKey, type SchemeKey, type SchemeName, type SerializedStyles, type SheetEntry, type StaticTemplateValue, type StyleObject, type StyleTypeOptions, type TemplateValue, type ThemeInput, type ThemeKey, type UmberCache, type WebNested, type WebProperties, type WebStyleObject, add, alpha, at, divide, multiply, negate, subtract };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Component, ComputedRef, FunctionalComponent, IntrinsicElementAttributes, PropType } from "vue";
2
- import { AlphaColor, BindingOptions, CSSObject, Cache, ColorScheme, ComponentSelector, CssArgument, CssArgument as CssArgument$1, Engine, GlobalInput, GlobalInput as GlobalInput$1, GlobalStyleObject, GlobalStyleObject as GlobalStyleObject$1, GlobalStyles, GlobalStyles as GlobalStyles$1, GlobalStylesInput, Interpolation as Interpolation$1, InterpolationResult, InterpolationResult as InterpolationResult$1, Keyframes, Keyframes as Keyframes$1, KeyframesInput, KeyframesOptions, KeyframesSteps, KeyframesSteps as KeyframesSteps$1, NestedKey, ObjectSheet, SchemeKey, SchemeName, SerializedStyles, SerializedStyles as SerializedStyles$1, SheetEntry, SheetEntry as SheetEntry$1, SheetStyles, StaticTemplateValue, StaticTemplateValue as StaticTemplateValue$1, StyleInput, StyleObject, StyleTypeOptions, StylerOptions, TemplateValue, TemplateValue as TemplateValue$1, Theme as Theme$1, ThemeInput, ThemeInput as ThemeInput$1, ThemeKey, UmberCache, WebNested, WebProperties, WebStyleObject, WebStyleObject as WebStyleObject$1, add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
2
+ import { AlphaColor, BindingOptions, CSSObject, Cache, ColorScheme, ComponentSelector, CssArgument, CssArgument as CssArgument$1, Engine, GlobalInput, GlobalInput as GlobalInput$1, GlobalStyleObject, GlobalStyleObject as GlobalStyleObject$1, GlobalStyles, GlobalStyles as GlobalStyles$1, GlobalStylesInput, Interpolation as Interpolation$1, InterpolationResult, InterpolationResult as InterpolationResult$1, Keyframes, Keyframes as Keyframes$1, KeyframesInput, KeyframesOptions, KeyframesSteps, KeyframesSteps as KeyframesSteps$1, LiveValue, LiveValue as LiveValue$1, NestedKey, ObjectSheet, SchemeKey, SchemeName, SerializedStyles, SerializedStyles as SerializedStyles$1, SheetEntry, SheetEntry as SheetEntry$1, SheetStyles, StaticTemplateValue, StaticTemplateValue as StaticTemplateValue$1, StyleInput, StyleObject, StyleTypeOptions, StylerOptions, TemplateValue, TemplateValue as TemplateValue$1, Theme as Theme$1, ThemeInput, ThemeInput as ThemeInput$1, ThemeKey, UmberCache, WebNested, WebProperties, WebStyleObject, WebStyleObject as WebStyleObject$1, add, alpha, at, divide, multiply, negate, subtract } from "@umber-style/core";
3
3
  /**
4
4
  * The theme of the default style of this binding: what `styled`, `useTheme`, `StyleSheet` and
5
5
  * `ThemeProvider` of the default style read. It extends the core's `Theme`, so an app gives it members
@@ -108,8 +108,25 @@ export interface GlobalProps<T> {
108
108
  */
109
109
  styles: GlobalInput$1<T>;
110
110
  }
111
+ /**
112
+ * A value of `useStyleValue` in Vue: the reference to its variable in a style (`${left}`, or an
113
+ * operand of the helpers of tokens), with `value` in the shape of a ref: reading it gives the number,
114
+ * setting it changes the declaration of the variable in place, with no render. `get()` reads it too.
115
+ */
116
+ export interface StyleValueRef extends LiveValue$1 {
117
+ /** The number now; setting it changes what the variable declares. */
118
+ value: number;
119
+ }
111
120
  /** What `createStyle` and `bindEngine` return: the Vue styling of one engine. */
112
121
  export interface Style<T> {
122
+ /**
123
+ * A number that a style reads through a CSS variable of its own, for a value that changes often (a
124
+ * slider): `const left = useStyleValue(0, '%')` in `setup`, `${left}` in a style, `left.value = 40` to
125
+ * change it with no render. The number is written with `unit` after it, or as it is without one. Its
126
+ * rule is on `:root`, in the theme layer, while the component is mounted; the reference falls back to
127
+ * the first number, which a server render shows with no rule.
128
+ */
129
+ useStyleValue(initial: number, unit?: string): StyleValueRef;
113
130
  /** The engine every member writes through. */
114
131
  engine: Engine<T>;
115
132
  /** The cache of the engine: its rules and sheet. */
@@ -198,6 +215,7 @@ export declare function createDefaultStyle(): {
198
215
  <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
199
216
  <S extends import("@umber-style/core").SheetStyles>(sheet: Sheet<S>): { [K in keyof S]: import("@umber-style/core").SheetEntry; };
200
217
  };
218
+ useStyleValue: (initial: number, unit?: string) => StyleValueRef;
201
219
  useTheme: () => ComputedRef<Theme>;
202
220
  ThemeProvider: Component<ThemeProviderProps<Theme>>;
203
221
  ThemeScope: Component;
@@ -243,7 +261,7 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
243
261
  }, useStyle: {
244
262
  <K extends string>(sheet: { readonly [P in K]: import("@umber-style/core").SheetEntry; }): { readonly [P in K]: import("@umber-style/core").SheetEntry; };
245
263
  <S extends import("@umber-style/core").SheetStyles>(sheet: Sheet<S>): { [K in keyof S]: import("@umber-style/core").SheetEntry; };
246
- }, useTheme: () => import("vue").ComputedRef<Theme>, ThemeProvider: import("vue").Component<ThemeProviderProps<Theme>>, ThemeScope: import("vue").Component, useThemeClass: () => import("vue").ComputedRef<string | undefined>, apply: (...entries: (import("@umber-style/core").SheetEntry | string | null | undefined | false)[]) => {
264
+ }, useStyleValue: (initial: number, unit?: string) => StyleValueRef, useTheme: () => import("vue").ComputedRef<Theme>, ThemeProvider: import("vue").Component<ThemeProviderProps<Theme>>, ThemeScope: import("vue").Component, useThemeClass: () => import("vue").ComputedRef<string | undefined>, apply: (...entries: (import("@umber-style/core").SheetEntry | string | null | undefined | false)[]) => {
247
265
  class?: string;
248
266
  }, css: CssFunction, themeClass: (theme: {
249
267
  readonly _theme?: never;
@@ -258,4 +276,4 @@ export declare const configure: (options: DefaultStyleOptions) => void, getEngin
258
276
  (template: TemplateStringsArray, ...values: import("@umber-style/core").TemplateValue<unknown, Theme>[]): import("@umber-style/core").GlobalStyles<Theme>;
259
277
  (styles: import("@umber-style/core").GlobalStylesInput<Theme>): import("@umber-style/core").GlobalStyles<Theme>;
260
278
  }, Global: import("vue").Component<GlobalProps<Theme>>;
261
- export { type AlphaColor, type CSSObject, type ComponentSelector, type CssArgument, type GlobalInput, type GlobalStyleObject, type GlobalStyles, type InterpolationResult, type Keyframes, type KeyframesSteps, type NestedKey, type SchemeKey, type SchemeName, type SerializedStyles, type SheetEntry, type StaticTemplateValue, type StyleObject, type StyleTypeOptions, type TemplateValue, type ThemeInput, type ThemeKey, type UmberCache, type WebNested, type WebProperties, type WebStyleObject, add, alpha, at, divide, multiply, negate, subtract };
279
+ export { type AlphaColor, type CSSObject, type ComponentSelector, type CssArgument, type GlobalInput, type GlobalStyleObject, type GlobalStyles, type InterpolationResult, type Keyframes, type KeyframesSteps, type LiveValue, type NestedKey, type SchemeKey, type SchemeName, type SerializedStyles, type SheetEntry, type StaticTemplateValue, type StyleObject, type StyleTypeOptions, type TemplateValue, type ThemeInput, type ThemeKey, type UmberCache, type WebNested, type WebProperties, type WebStyleObject, add, alpha, at, divide, multiply, negate, subtract };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { EMPTY_THEME, add, alpha, at, createComponentSelector, createCssEntry, createDeferredObject, createDeferredRecord, createEngine, createGlobalMarker, createLazyEngine, divide, findEntryCache, flattenStyle, globalStyles as globalStyles$1, isThemedSheet, keyframes as keyframes$1, mergeTheme, multiply, negate, readSharedState, readStyleArguments, resolveThemeInput, subtract, withTagShorthands } from "@umber-style/core";
2
- import { Comment, computed, defineComponent, h, inject, mergeProps, normalizeClass, onUnmounted, provide, watch } from "vue";
1
+ import { EMPTY_THEME, add, alpha, at, createComponentSelector, createCssEntry, createDeferredObject, createDeferredRecord, createEngine, createGlobalMarker, createLazyEngine, createLiveValue, declareLiveValue, divide, findEntryCache, flattenStyle, globalStyles as globalStyles$1, hashString, isThemedSheet, keyframes as keyframes$1, mergeTheme, multiply, negate, readSharedState, readStyleArguments, resolveThemeInput, subtract, withTagShorthands, writeLiveValue } from "@umber-style/core";
2
+ import { Comment, computed, defineComponent, h, inject, mergeProps, normalizeClass, onBeforeUnmount, onMounted, onUnmounted, provide, useId, watch } from "vue";
3
3
  // src/CacheProvider.ts
4
4
  const provided = readSharedState("vue.cache-provider@1", () => ({
5
5
  key: Symbol("cache"),
@@ -185,6 +185,7 @@ function createThemeKeys() {
185
185
  theme: Symbol("theme"),
186
186
  view: Symbol("view"),
187
187
  scope: Symbol("scope"),
188
+ nested: Symbol("nested"),
188
189
  engine: Symbol("engine")
189
190
  };
190
191
  }
@@ -196,8 +197,9 @@ function createThemeKeys() {
196
197
  * `setup` and again when it changes, which renders no styled component. It gives the engine its base
197
198
  * theme when it has none.
198
199
  * - A nested provider renders its wrapper: the theme class of the theme it was given (with the boundary
199
- * and scheme markers), the theme class of its merged theme (every variable, for where it is not inside
200
- * the wrapper above it), and the scope class, which has `display: contents`.
200
+ * and scheme markers), the theme class of the themes of the nested providers above it and its own,
201
+ * merged (for where it is not inside their wrappers; the outermost theme is left out, as it is on
202
+ * `:root` or on the class of `<html>`), and the scope class, which has `display: contents`.
201
203
  * - With `isRoot` it renders no element and makes no rule: the app puts `themeClass(theme)` on an
202
204
  * ancestor, usually `<html>`.
203
205
  *
@@ -234,15 +236,18 @@ function createThemeProvider(baseEngine, keys) {
234
236
  const cache = injectCache();
235
237
  const engine = cache === void 0 ? baseEngine : baseEngine.withCache(cache);
236
238
  const outer = inject(keys.theme, null);
237
- const scope = inject(keys.engine, null) === engine ? inject(keys.scope, null) : null;
239
+ const isSameEngine = inject(keys.engine, null) === engine;
240
+ const scope = isSameEngine ? inject(keys.scope, null) : null;
241
+ const above = isSameEngine ? inject(keys.nested, null) : null;
238
242
  const isNested = scope !== null && !props.isRoot;
239
243
  const readOuter = () => outer?.value ?? engine.givenTheme;
240
244
  const given = computed(() => resolveThemeInput(props.theme, readOuter() ?? EMPTY_THEME));
241
245
  engine.adoptTheme(given.value);
242
246
  const merged = computed(() => mergeTheme(readOuter(), given.value));
247
+ const nested = computed(() => isNested ? mergeTheme(above?.value, given.value) : above?.value);
243
248
  const classes = computed(() => {
244
249
  const own = engine.themeClass(given.value, props.colorScheme);
245
- const full = engine.themeId(merged.value, props.colorScheme);
250
+ const full = engine.themeId(nested.value, props.colorScheme);
246
251
  return [
247
252
  own,
248
253
  own.startsWith(`${full} `) ? "" : full,
@@ -251,6 +256,7 @@ function createThemeProvider(baseEngine, keys) {
251
256
  });
252
257
  provide(keys.engine, engine);
253
258
  provide(keys.theme, merged);
259
+ provide(keys.nested, nested);
254
260
  provide(keys.view, computed(() => engine.createThemeView(merged.value)));
255
261
  provide(keys.scope, isNested ? computed(() => ({
256
262
  as: props.as,
@@ -286,6 +292,35 @@ function createThemeScope(keys) {
286
292
  })
287
293
  };
288
294
  }
295
+ // src/useStyleValue.ts
296
+ /**
297
+ * Makes `useStyleValue` for the cache `readCache` gives (the engine's), or the one of a `CacheProvider`
298
+ * above. It is called in `setup`: the value is made with a variable named from Vue's `useId`, so the
299
+ * server and the browser name it alike, its rule is declared when the component is mounted, with the
300
+ * number it holds then, and removed before it unmounts. Setting `value` changes the declaration in
301
+ * place, and renders nothing: the value is not reactive.
302
+ */
303
+ function createUseStyleValue(readCache) {
304
+ return function useStyleValue(initial, unit) {
305
+ const cache = injectCache() ?? readCache();
306
+ const value = createLiveValue(`--${cache.prefix}-value-${hashString(useId())}`, initial, unit);
307
+ let rule;
308
+ onMounted(() => {
309
+ rule = declareLiveValue(cache, value);
310
+ });
311
+ onBeforeUnmount(() => {
312
+ rule.remove();
313
+ rule = void 0;
314
+ });
315
+ return Object.defineProperty(value, "value", {
316
+ get: () => value.get(),
317
+ set: (next) => {
318
+ const text = writeLiveValue(value, next);
319
+ rule?.set(text);
320
+ }
321
+ });
322
+ };
323
+ }
289
324
  // src/createStyle.ts
290
325
  /** Makes the Vue styling over an engine: `styled`, sheets, the theme provider and `useTheme`. */
291
326
  function bindEngine(engine) {
@@ -312,6 +347,7 @@ function bindEngine(engine) {
312
347
  const entries = isThemedSheet(sheet) ? sheet.resolve(useThemeView(cache)) : sheet;
313
348
  return cache === void 0 ? entries : engine.withCache(cache).adoptSheet(entries);
314
349
  }),
350
+ useStyleValue: createUseStyleValue(() => engine.cache),
315
351
  apply: (...entries) => ({ class: (findEntryCache(entries) ?? engine.cache).css(...entries) || void 0 }),
316
352
  css: ((...args) => createCssEntry(engine.cache, args)),
317
353
  ThemeProvider: createThemeProvider(engine, keys),
@@ -353,6 +389,7 @@ function createDefaultStyle() {
353
389
  const styled = withTagShorthands(((tag, options) => (...args) => getStyle().styled(tag, options)(...args)));
354
390
  const StyleSheet = { create: ((styles) => typeof styles === "function" ? getStyle().StyleSheet.create(styles) : createDeferredRecord(styles, () => getStyle().StyleSheet.create(styles))) };
355
391
  const useStyle = ((sheet) => getStyle().useStyle(sheet));
392
+ const useStyleValue = (initial, unit) => getStyle().useStyleValue(initial, unit);
356
393
  function useTheme() {
357
394
  return getStyle().useTheme();
358
395
  }
@@ -388,6 +425,7 @@ function createDefaultStyle() {
388
425
  styled,
389
426
  StyleSheet,
390
427
  useStyle,
428
+ useStyleValue,
391
429
  useTheme,
392
430
  ThemeProvider,
393
431
  ThemeScope,
@@ -402,5 +440,5 @@ function createDefaultStyle() {
402
440
  Global
403
441
  };
404
442
  }
405
- const { configure, getEngine, styled, StyleSheet, useStyle, useTheme, ThemeProvider, ThemeScope, useThemeClass, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = readSharedState("vue.default-style@1", createDefaultStyle);
406
- export { CacheProvider, Global, StyleSheet, ThemeProvider, ThemeScope, add, alpha, apply, at, bindEngine, configure, createDefaultStyle, createStyle, css, divide, getEngine, globalStyles, keyframes, multiply, negate, styled, subtract, themeClass, useStyle, useTheme, useThemeClass, when, whenScheme };
443
+ const { configure, getEngine, styled, StyleSheet, useStyle, useStyleValue, useTheme, ThemeProvider, ThemeScope, useThemeClass, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = readSharedState("vue.default-style@1", createDefaultStyle);
444
+ export { CacheProvider, Global, StyleSheet, ThemeProvider, ThemeScope, add, alpha, apply, at, bindEngine, configure, createDefaultStyle, createStyle, css, divide, getEngine, globalStyles, keyframes, multiply, negate, styled, subtract, themeClass, useStyle, useStyleValue, useTheme, useThemeClass, when, whenScheme };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umber-style/vue",
3
- "version": "0.2.0-alpha.0",
3
+ "version": "0.3.0-alpha.0",
4
4
  "description": "UmberStyle for Vue: the same names as the React binding, with a reactive useTheme.",
5
5
  "keywords": [
6
6
  "styling",
@@ -43,7 +43,7 @@
43
43
  "access": "public"
44
44
  },
45
45
  "dependencies": {
46
- "@umber-style/core": "^0.2.0-alpha.1"
46
+ "@umber-style/core": "^0.3.0-alpha.0"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "vue": "^3.5.0"
@@ -59,7 +59,7 @@
59
59
  "vitest": "^5.1.0",
60
60
  "vue": "^3.5.45",
61
61
  "@umber-style/eslint-config": "0.0.0",
62
- "@umber-style/is-prop-valid": "0.2.0-alpha.0"
62
+ "@umber-style/is-prop-valid": "0.3.0-alpha.0"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "tsdown",