UNPKG

@cran/vue.use

Version:

Cranberry Vue Use Utilities

17 lines (16 loc) 594 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useCssVar = void 0; const runtime_dom_1 = require("@vue/runtime-dom"); const varmap = {}; function useCssVar(key, defaultValue = "") { if (!varmap[key]) { const variable = varmap[key] = (0, runtime_dom_1.ref)(defaultValue); const cssKey = `--${key}`; (0, runtime_dom_1.watch)(variable, function onChange(value) { document.documentElement.style.setProperty(cssKey, value); }, { immediate: true, }); } return varmap[key]; } exports.useCssVar = useCssVar;