UNPKG

@wordpress/components

Version:
182 lines (181 loc) • 9.01 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); // \0rolldown/runtime.js var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); let clsx = require("clsx"); clsx = __toESM(clsx); let ___utils_polymorphic_element_tsx = require("../utils/polymorphic-element.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/style-runtime/src/index.ts const STYLE_HASH_ATTRIBUTE = "data-wp-hash"; /** * Returns the shared style runtime registry. * * The registry is stored on `globalThis` so separately bundled copies of this * package can coordinate through the same document and style maps. * * @return The shared runtime registry. */ function getRuntime() { const globalScope = globalThis; if (globalScope.__wpStyleRuntime) return globalScope.__wpStyleRuntime; globalScope.__wpStyleRuntime = { documents: /* @__PURE__ */ new Map(), styles: /* @__PURE__ */ new Map(), injectedStyles: /* @__PURE__ */ new WeakMap() }; if (typeof document !== "undefined") registerDocument(document); return globalScope.__wpStyleRuntime; } /** * Checks whether a document already contains a style tag for a hash. * * @param targetDocument Document to inspect. * @param hash Stable hash for the transformed CSS. * * @return Whether the style hash already exists in the document. */ function documentContainsStyleHash(targetDocument, hash) { if (!targetDocument.head) return false; for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) return true; return false; } /** * Injects a registered style into a document, unless that document already * contains a style tag for the same hash. * * @param targetDocument Document to inject the style into. * @param hash Stable hash for the transformed CSS. * @param css CSS text to inject. */ function injectStyle(targetDocument, hash, css) { if (!targetDocument.head) return; const runtime = getRuntime(); let injectedStyles = runtime.injectedStyles.get(targetDocument); if (!injectedStyles) { injectedStyles = /* @__PURE__ */ new Set(); runtime.injectedStyles.set(targetDocument, injectedStyles); } if (injectedStyles.has(hash)) return; if (documentContainsStyleHash(targetDocument, hash)) { injectedStyles.add(hash); return; } const style = targetDocument.createElement("style"); style.setAttribute(STYLE_HASH_ATTRIBUTE, hash); style.appendChild(targetDocument.createTextNode(css)); targetDocument.head.appendChild(style); injectedStyles.add(hash); } /** * Registers a document as a style injection target. * * Existing registered styles are replayed into the document immediately. * Documents are reference-counted so multiple providers can safely register the * same document without one cleanup removing it while another registration is * still active. * * @param targetDocument Document to receive registered styles. * @return Cleanup function that unregisters this document registration. */ function registerDocument(targetDocument) { const runtime = getRuntime(); runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1); for (const [hash, css] of runtime.styles) injectStyle(targetDocument, hash, css); return () => { const count = runtime.documents.get(targetDocument); if (count === void 0) return; if (count <= 1) { runtime.documents.delete(targetDocument); return; } runtime.documents.set(targetDocument, count - 1); }; } /** * Registers a style and injects it into all registered documents. * * The hash is used as the deduplication key, so calling this repeatedly with * the same hash will not add duplicate style tags to a document. * Registered styles are retained for the lifetime of the page so they can be * replayed into documents that are registered later. * * @param hash Stable hash for the transformed CSS. * @param css CSS text to inject. */ function registerStyle(hash, css) { const runtime = getRuntime(); runtime.styles.set(hash, css); for (const targetDocument of runtime.documents.keys()) injectStyle(targetDocument, hash, css); } // packages/components/src/box-control/style.module.scss if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("688a11782c", ".a691e367f1b55f62__unit-control{max-width:90px}._0e04b2962bc33dbb__input-wrapper{grid-column:1/span 3}._2e0e779ca7284bc5__reset-button{grid-area:1/2;justify-self:end}._2feb1869b0c8a32c__linked-button-wrapper{grid-area:1/3;justify-self:end}._3952789640f98f27__icon{flex:0 0 auto}._1155863d57b9789a__range-control{margin-inline-end:8px;width:100%}._2a7a06bc9e98a8bf__icon-root{box-sizing:border-box;display:block;height:24px;padding:4px;position:relative;width:24px}._78a67da593233b1d__icon-viewbox{box-sizing:border-box;display:block;height:100%;position:relative;width:100%}._80edddeeefc17880__icon-stroke{background-color:currentColor;box-sizing:border-box;display:block;opacity:.3;pointer-events:none;position:absolute}.d3e186923be6807c__is-highlighted{opacity:1}._5126d15f8bb86c74__icon-left,.cbbba3ba3bed8033__icon-right{bottom:3px;top:3px;width:2px}._43ffaa6905d27840__icon-bottom,._9543c21b4cb17eaa__icon-top{height:2px;left:3px;right:3px}._9543c21b4cb17eaa__icon-top{top:0}.cbbba3ba3bed8033__icon-right{right:0}._43ffaa6905d27840__icon-bottom{bottom:0}._5126d15f8bb86c74__icon-left{left:0}"); var style_module_default = { "unit-control": "a691e367f1b55f62__unit-control", "input-wrapper": "_0e04b2962bc33dbb__input-wrapper", "reset-button": "_2e0e779ca7284bc5__reset-button", "linked-button-wrapper": "_2feb1869b0c8a32c__linked-button-wrapper", "icon": "_3952789640f98f27__icon", "range-control": "_1155863d57b9789a__range-control", "icon-root": "_2a7a06bc9e98a8bf__icon-root", "icon-viewbox": "_78a67da593233b1d__icon-viewbox", "icon-stroke": "_80edddeeefc17880__icon-stroke", "is-highlighted": "d3e186923be6807c__is-highlighted", "icon-left": "_5126d15f8bb86c74__icon-left", "icon-right": "cbbba3ba3bed8033__icon-right", "icon-top": "_9543c21b4cb17eaa__icon-top", "icon-bottom": "_43ffaa6905d27840__icon-bottom" }; // packages/components/src/box-control/icon.tsx const BASE_ICON_SIZE = 24; function BoxControlIcon({ as = "span", size = 24, side = "all", sides, className, ...props }) { const isSideDisabled = (value) => sides?.length && !sides.includes(value); const hasSide = (value) => { if (isSideDisabled(value)) return false; return side === "all" || side === value; }; const top = hasSide("top") || hasSide("vertical"); const right = hasSide("right") || hasSide("horizontal"); const bottom = hasSide("bottom") || hasSide("vertical"); const left = hasSide("left") || hasSide("horizontal"); const scale = size / BASE_ICON_SIZE; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___utils_polymorphic_element_tsx.PolymorphicElement, { as, style: { transform: `scale(${scale})` }, ...props, className: (0, clsx.default)(style_module_default["icon-root"], className), children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { className: style_module_default["icon-viewbox"], children: [ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: (0, clsx.default)(style_module_default["icon-stroke"], style_module_default["icon-top"], { [style_module_default["is-highlighted"]]: top }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: (0, clsx.default)(style_module_default["icon-stroke"], style_module_default["icon-right"], { [style_module_default["is-highlighted"]]: right }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: (0, clsx.default)(style_module_default["icon-stroke"], style_module_default["icon-bottom"], { [style_module_default["is-highlighted"]]: bottom }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: (0, clsx.default)(style_module_default["icon-stroke"], style_module_default["icon-left"], { [style_module_default["is-highlighted"]]: left }) }) ] }) }); } exports.default = BoxControlIcon; //# sourceMappingURL=icon.cjs.map