UNPKG

@wordpress/components

Version:
207 lines (206 loc) • 10.6 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 _wordpress_i18n = require("@wordpress/i18n"); let clsx = require("clsx"); clsx = __toESM(clsx); let ___flex_index_ts = require("../flex/index.cjs"); let ___unit_control_index_tsx = require("../unit-control/index.cjs"); ___unit_control_index_tsx = __toESM(___unit_control_index_tsx); let __utils_ts = require("./utils.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/focal-point-picker/style.module.scss if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("0ed1e26ed0", "._4f91cfcb0c85cc41__root{border:0;box-sizing:border-box;font-family:var(--wpds-typography-font-family-body,-apple-system,system-ui,\"Segoe UI\",\"Roboto\",\"Oxygen-Sans\",\"Ubuntu\",\"Cantarell\",\"Helvetica Neue\",sans-serif);font-size:13px;margin:0;padding:0}._4f91cfcb0c85cc41__root *,._4f91cfcb0c85cc41__root :after,._4f91cfcb0c85cc41__root :before{box-sizing:inherit}._8124adaa57f886a6__media-wrapper{background-color:transparent;contain:layout;display:flex;text-align:center;width:100%}._14038b3fb0a03b00__media-container{align-items:center;border-radius:2px;cursor:pointer;display:inline-flex;height:100%;justify-content:center;margin:auto;position:relative}._14038b3fb0a03b00__media-container:after{border-radius:inherit;box-shadow:inset 0 0 0 1px rgba(0,0,0,.1);content:\"\";inset:0;pointer-events:none;position:absolute}._14038b3fb0a03b00__media-container img,._14038b3fb0a03b00__media-container video{border-radius:inherit;box-sizing:border-box;display:block;height:auto;margin:0;max-height:100%;max-width:100%;pointer-events:none;user-select:none;width:100%}._278f7ba1e9ea0dbd__media-placeholder{background:#f0f0f0;border-radius:inherit;box-sizing:border-box;height:170px;max-width:280px;min-width:200px;width:100%}._0fd08c338d5d1ae3__unit-control{width:100%}._24e8123162458442__controls{max-width:320px;padding-top:1em}._24e8123162458442__controls:where(._18c8dc3c0d7e4db5__has-help-text){padding-bottom:1em}._1c53809aed7335a6__grid{left:50%;opacity:0;overflow:hidden;pointer-events:none;position:absolute;top:50%;transform:translate3d(-50%,-50%,0);z-index:1}@media not (prefers-reduced-motion){._1c53809aed7335a6__grid{transition:opacity .1s linear}}._1c53809aed7335a6__grid:where(._140336f4ad6dd49c__show-overlay){opacity:1}._72bef77b62749ecc__grid-line{backdrop-filter:blur(16px) saturate(180%);background:hsla(0,0%,100%,.4);position:absolute;transform:translateZ(0)}._5e72b27b9deb5c57__grid-line-x{height:1px;inset-inline:1px}.b9c3347d2b89441c__grid-line-y{inset-block:1px;width:1px}.ca89efddd89ad211__pointer{backdrop-filter:blur(16px) saturate(180%);background:hsla(0,0%,100%,.4);border:1px solid hsla(0,0%,100%,.4);border-radius:50%;box-shadow:0 0 8px rgba(0,0,0,.1);cursor:grab;height:40px;margin-left:-20px;margin-top:-20px;position:absolute;user-select:none;width:40px;will-change:transform;z-index:10000}@media not (prefers-reduced-motion){.ca89efddd89ad211__pointer{transition:transform .1s linear}}.ca89efddd89ad211__pointer:where(.be014e404db56b57__is-dragging){box-shadow:0 0 10px rgba(0,0,0,.12);cursor:grabbing;transform:scale(1.1)}"); var style_module_default = { "root": "_4f91cfcb0c85cc41__root", "media-wrapper": "_8124adaa57f886a6__media-wrapper", "media-container": "_14038b3fb0a03b00__media-container", "media-placeholder": "_278f7ba1e9ea0dbd__media-placeholder", "unit-control": "_0fd08c338d5d1ae3__unit-control", "controls": "_24e8123162458442__controls", "has-help-text": "_18c8dc3c0d7e4db5__has-help-text", "grid": "_1c53809aed7335a6__grid", "show-overlay": "_140336f4ad6dd49c__show-overlay", "grid-line": "_72bef77b62749ecc__grid-line", "grid-line-x": "_5e72b27b9deb5c57__grid-line-x", "grid-line-y": "b9c3347d2b89441c__grid-line-y", "pointer": "ca89efddd89ad211__pointer", "is-dragging": "be014e404db56b57__is-dragging" }; // packages/components/src/focal-point-picker/controls.tsx const TEXTCONTROL_MIN = 0; const TEXTCONTROL_MAX = 100; const noop = () => {}; function FocalPointPickerControls({ hasHelpText, onChange = noop, point = { x: .5, y: .5 } }) { const valueX = (0, __utils_ts.fractionToPercentage)(point.x); const valueY = (0, __utils_ts.fractionToPercentage)(point.y); const handleChange = (value, axis) => { if (value === void 0) return; const num = parseInt(value, 10); if (!isNaN(num)) onChange({ ...point, [axis]: num / 100 }); }; return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(___flex_index_ts.Flex, { className: (0, clsx.default)(style_module_default.controls, "focal-point-picker__controls", { [style_module_default["has-help-text"]]: hasHelpText }), gap: 4, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FocalPointUnitControl, { label: (0, _wordpress_i18n.__)("Left"), "aria-label": (0, _wordpress_i18n.__)("Focal point left position"), value: [valueX, "%"].join(""), onChange: ((next) => handleChange(next, "x")), dragDirection: "e" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FocalPointUnitControl, { label: (0, _wordpress_i18n.__)("Top"), "aria-label": (0, _wordpress_i18n.__)("Focal point top position"), value: [valueY, "%"].join(""), onChange: ((next) => handleChange(next, "y")), dragDirection: "s" })] }); } function FocalPointUnitControl(props) { return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___unit_control_index_tsx.default, { className: (0, clsx.default)(style_module_default["unit-control"], "focal-point-picker__controls-position-unit-control"), labelPosition: "top", max: TEXTCONTROL_MAX, min: TEXTCONTROL_MIN, step: 1, units: [{ value: "%", label: "%" }], ...props }); } exports.default = FocalPointPickerControls; //# sourceMappingURL=controls.cjs.map