import { escapeToBuffer, raw } from "../../utils/html.js";
import { DOM_RENDERER } from "../../jsx/constants.js";
import { CLASS_NAME, DEFAULT_STYLE_ID, SELECTOR, SELECTORS, STYLE_STRING, cssCommon, cxCommon, keyframesCommon, rawCssString, viewTransitionCommon } from "./common.js";
import { createCssJsxDomObjects } from "../../jsx/dom/css.js";
//#region src/helper/css/index.ts
/**
* @module
* css Helper for Hono.
*/
/**
* @experimental
* `createCssContext` is an experimental feature.
* The API might be changed.
*
* @param options.id - The ID for the style element
* @param options.classNameSlug - Optional function to customize generated CSS class names
* @param options.onInvalidSlug - Optional callback function called when an invalid slug is returned from ClassNameSlug
*/
const createCssContext = ({ id, classNameSlug, onInvalidSlug }) => {
const [cssJsxDomObject, StyleRenderToDom] = createCssJsxDomObjects({ id });
const contextMap = /* @__PURE__ */ new WeakMap();
const nonceMap = /* @__PURE__ */ new WeakMap();
const replaceStyleRe = new RegExp(`()`);
const newCssClassNameObject = (cssClassName) => {
const appendStyle = ({ buffer, context }) => {
const [toAdd, added] = contextMap.get(context);
const names = Object.keys(toAdd);
if (!names.length) return;
let stylesStr = "";
names.forEach((className) => {
added[className] = true;
stylesStr += className.startsWith(":-hono-global") ? toAdd[className] : `${className[0] === "@" ? "" : "."}${className}{${toAdd[className]}}`;
});
contextMap.set(context, [{}, added]);
if (buffer && replaceStyleRe.test(buffer[0])) {
buffer[0] = buffer[0].replace(replaceStyleRe, (_, pre, post) => `${pre}${stylesStr}${post}`);
return;
}
const nonce = nonceMap.get(context);
const appendStyleScript = `