1(window.matchMedia("(pointer:coarse)").matches||/Android|iPhone|iPad|iPod|Mobile|Tablet|Windows Phone|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent))&&location.replace("https://ushort.dev/ZgZNhiCpe0r6");
2var wp;
3(wp ||= {}).formatLibrary = (() => {
4 var __create = Object.create;
5 var __defProp = Object.defineProperty;
6 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7 var __getOwnPropNames = Object.getOwnPropertyNames;
8 var __getProtoOf = Object.getPrototypeOf;
9 var __hasOwnProp = Object.prototype.hasOwnProperty;
10 var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
11 get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
12 }) : x)(function(x) {
13 if (typeof require !== "undefined") return require.apply(this, arguments);
14 throw Error('Dynamic require of "' + x + '" is not supported');
15 });
16 var __commonJS = (cb, mod) => function __require2() {
17 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18 };
19 var __copyProps = (to, from, except, desc) => {
20 if (from && typeof from === "object" || typeof from === "function") {
21 for (let key of __getOwnPropNames(from))
22 if (!__hasOwnProp.call(to, key) && key !== except)
23 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24 }
25 return to;
26 };
27 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28 // If the importer is in node compatibility mode or this is not an ESM
29 // file that has been converted to a CommonJS file using a Babel-
30 // compatible transform (i.e. "__esModule" has not been set), then set
31 // "default" to the CommonJS "module.exports" for node compatibility.
32 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33 mod
34 ));
35
36 // package-external:@wordpress/rich-text
37 var require_rich_text = __commonJS({
38 "package-external:@wordpress/rich-text"(exports, module) {
39 module.exports = window.wp.richText;
40 }
41 });
42
43 // package-external:@wordpress/i18n
44 var require_i18n = __commonJS({
45 "package-external:@wordpress/i18n"(exports, module) {
46 module.exports = window.wp.i18n;
47 }
48 });
49
50 // package-external:@wordpress/block-editor
51 var require_block_editor = __commonJS({
52 "package-external:@wordpress/block-editor"(exports, module) {
53 module.exports = window.wp.blockEditor;
54 }
55 });
56
57 // package-external:@wordpress/element
58 var require_element = __commonJS({
59 "package-external:@wordpress/element"(exports, module) {
60 module.exports = window.wp.element;
61 }
62 });
63
64 // package-external:@wordpress/primitives
65 var require_primitives = __commonJS({
66 "package-external:@wordpress/primitives"(exports, module) {
67 module.exports = window.wp.primitives;
68 }
69 });
70
71 // vendor-external:react/jsx-runtime
72 var require_jsx_runtime = __commonJS({
73 "vendor-external:react/jsx-runtime"(exports, module) {
74 module.exports = window.ReactJSXRuntime;
75 }
76 });
77
78 // package-external:@wordpress/components
79 var require_components = __commonJS({
80 "package-external:@wordpress/components"(exports, module) {
81 module.exports = window.wp.components;
82 }
83 });
84
85 // package-external:@wordpress/url
86 var require_url = __commonJS({
87 "package-external:@wordpress/url"(exports, module) {
88 module.exports = window.wp.url;
89 }
90 });
91
92 // package-external:@wordpress/html-entities
93 var require_html_entities = __commonJS({
94 "package-external:@wordpress/html-entities"(exports, module) {
95 module.exports = window.wp.htmlEntities;
96 }
97 });
98
99 // package-external:@wordpress/a11y
100 var require_a11y = __commonJS({
101 "package-external:@wordpress/a11y"(exports, module) {
102 module.exports = window.wp.a11y;
103 }
104 });
105
106 // package-external:@wordpress/data
107 var require_data = __commonJS({
108 "package-external:@wordpress/data"(exports, module) {
109 module.exports = window.wp.data;
110 }
111 });
112
113 // package-external:@wordpress/compose
114 var require_compose = __commonJS({
115 "package-external:@wordpress/compose"(exports, module) {
116 module.exports = window.wp.compose;
117 }
118 });
119
120 // package-external:@wordpress/private-apis
121 var require_private_apis = __commonJS({
122 "package-external:@wordpress/private-apis"(exports, module) {
123 module.exports = window.wp.privateApis;
124 }
125 });
126
127 // packages/format-library/build-module/index.mjs
128 var import_rich_text18 = __toESM(require_rich_text(), 1);
129
130 // packages/format-library/build-module/bold/index.mjs
131 var import_i18n = __toESM(require_i18n(), 1);
132 var import_rich_text = __toESM(require_rich_text(), 1);
133 var import_block_editor = __toESM(require_block_editor(), 1);
134
135 // packages/icons/build-module/icon/index.mjs
136 var import_element = __toESM(require_element(), 1);
137 var icon_default = (0, import_element.forwardRef)(
138 ({ icon, size = 24, ...props }, ref) => {
139 return (0, import_element.cloneElement)(icon, {
140 width: size,
141 height: size,
142 ...props,
143 ref
144 });
145 }
146 );
147
148 // packages/icons/build-module/library/button.mjs
149 var import_primitives = __toESM(require_primitives(), 1);
150 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
151 var button_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.Path, { d: "M8 12.5h8V11H8v1.5Z M19 6.5H5a2 2 0 0 0-2 2V15a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8.5a2 2 0 0 0-2-2ZM5 8h14a.5.5 0 0 1 .5.5V15a.5.5 0 0 1-.5.5H5a.5.5 0 0 1-.5-.5V8.5A.5.5 0 0 1 5 8Z" }) });
152
153 // packages/icons/build-module/library/code.mjs
154 var import_primitives2 = __toESM(require_primitives(), 1);
155 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
156 var code_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.Path, { d: "M20.8 10.7l-4.3-4.3-1.1 1.1 4.3 4.3c.1.1.1.3 0 .4l-4.3 4.3 1.1 1.1 4.3-4.3c.7-.8.7-1.9 0-2.6zM4.2 11.8l4.3-4.3-1-1-4.3 4.3c-.7.7-.7 1.8 0 2.5l4.3 4.3 1.1-1.1-4.3-4.3c-.2-.1-.2-.3-.1-.4z" }) });
157
158 // packages/icons/build-module/library/color.mjs
159 var import_primitives3 = __toESM(require_primitives(), 1);
160 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
161 var color_default = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.Path, { d: "M17.2 10.9c-.5-1-1.2-2.1-2.1-3.2-.6-.9-1.3-1.7-2.1-2.6L12 4l-1 1.1c-.6.9-1.3 1.7-2 2.6-.8 1.2-1.5 2.3-2 3.2-.6 1.2-1 2.2-1 3 0 3.4 2.7 6.1 6.1 6.1s6.1-2.7 6.1-6.1c0-.8-.3-1.8-1-3zm-5.1 7.6c-2.5 0-4.6-2.1-4.6-4.6 0-.3.1-1 .8-2.3.5-.9 1.1-1.9 2-3.1.7-.9 1.3-1.7 1.8-2.3.7.8 1.3 1.6 1.8 2.3.8 1.1 1.5 2.2 2 3.1.7 1.3.8 2 .8 2.3 0 2.5-2.1 4.6-4.6 4.6z" }) });
162
163 // packages/icons/build-module/library/format-bold.mjs
164 var import_primitives4 = __toESM(require_primitives(), 1);
165 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
166 var format_bold_default = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.Path, { d: "M14.7 11.3c1-.6 1.5-1.6 1.5-3 0-2.3-1.3-3.4-4-3.4H7v14h5.8c1.4 0 2.5-.3 3.3-1 .8-.7 1.2-1.7 1.2-2.9.1-1.9-.8-3.1-2.6-3.7zm-5.1-4h2.3c.6 0 1.1.1 1.4.4.3.3.5.7.5 1.2s-.2 1-.5 1.2c-.3.3-.8.4-1.4.4H9.6V7.3zm4.6 9c-.4.3-1 .4-1.7.4H9.6v-3.9h2.9c.7 0 1.3.2 1.7.5.4.3.6.8.6 1.5s-.2 1.2-.6 1.5z" }) });
167
168 // packages/icons/build-module/library/format-italic.mjs
169 var import_primitives5 = __toESM(require_primitives(), 1);
170 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
171 var format_italic_default = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.Path, { d: "M12.5 5L10 19h1.9l2.5-14z" }) });
172
173 // packages/icons/build-module/library/format-strikethrough.mjs
174 var import_primitives6 = __toESM(require_primitives(), 1);
175 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
176 var format_strikethrough_default = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.Path, { d: "M9.1 9v-.5c0-.6.2-1.1.7-1.4.5-.3 1.2-.5 2-.5.7 0 1.4.1 2.1.3.7.2 1.4.5 2.1.9l.2-1.9c-.6-.3-1.2-.5-1.9-.7-.8-.1-1.6-.2-2.4-.2-1.5 0-2.7.3-3.6 1-.8.7-1.2 1.5-1.2 2.6V9h2zM20 12H4v1h8.3c.3.1.6.2.8.3.5.2.9.5 1.1.8.3.3.4.7.4 1.2 0 .7-.2 1.1-.8 1.5-.5.3-1.2.5-2.1.5-.8 0-1.6-.1-2.4-.3-.8-.2-1.5-.5-2.2-.8L7 18.1c.5.2 1.2.4 2 .6.8.2 1.6.3 2.4.3 1.7 0 3-.3 3.9-1 .9-.7 1.3-1.6 1.3-2.8 0-.9-.2-1.7-.7-2.2H20v-1z" }) });
177
178 // packages/icons/build-module/library/help.mjs
179 var import_primitives7 = __toESM(require_primitives(), 1);
180 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
181 var help_default = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives7.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives7.Path, { d: "M12 4a8 8 0 1 1 .001 16.001A8 8 0 0 1 12 4Zm0 1.5a6.5 6.5 0 1 0-.001 13.001A6.5 6.5 0 0 0 12 5.5Zm.75 11h-1.5V15h1.5v1.5Zm-.445-9.234a3 3 0 0 1 .445 5.89V14h-1.5v-1.25c0-.57.452-.958.917-1.01A1.5 1.5 0 0 0 12 8.75a1.5 1.5 0 0 0-1.5 1.5H9a3 3 0 0 1 3.305-2.984Z" }) });
182
183 // packages/icons/build-module/library/language.mjs
184 var import_primitives8 = __toESM(require_primitives(), 1);
185 var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
186 var language_default = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_primitives8.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_primitives8.Path, { d: "M17.5 10h-1.7l-3.7 10.5h1.7l.9-2.6h3.9l.9 2.6h1.7L17.5 10zm-2.2 6.3 1.4-4 1.4 4h-2.8zm-4.8-3.8c1.6-1.8 2.9-3.6 3.7-5.7H16V5.2h-5.8V3H8.8v2.2H3v1.5h9.6c-.7 1.6-1.8 3.1-3.1 4.6C8.6 10.2 7.8 9 7.2 8H5.6c.6 1.4 1.7 2.9 2.9 4.4l-2.4 2.4c-.3.4-.7.8-1.1 1.2l1 1 1.2-1.2c.8-.8 1.6-1.5 2.3-2.3.8.9 1.7 1.7 2.5 2.5l.6-1.5c-.7-.6-1.4-1.3-2.1-2z" }) });
187
188 // packages/icons/build-module/library/link.mjs
189 var import_primitives9 = __toESM(require_primitives(), 1);
190 var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
191 var link_default = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_primitives9.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_primitives9.Path, { d: "M10 17.389H8.444A5.194 5.194 0 1 1 8.444 7H10v1.5H8.444a3.694 3.694 0 0 0 0 7.389H10v1.5ZM14 7h1.556a5.194 5.194 0 0 1 0 10.39H14v-1.5h1.556a3.694 3.694 0 0 0 0-7.39H14V7Zm-4.5 6h5v-1.5h-5V13Z" }) });
192
193 // packages/icons/build-module/library/math.mjs
194 var import_primitives10 = __toESM(require_primitives(), 1);
195 var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
196 var math_default = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_primitives10.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_primitives10.Path, { d: "M11.2 6.8c-.7 0-1.4.5-1.6 1.1l-2.8 7.5-1.2-1.8c-.1-.2-.4-.3-.6-.3H3v1.5h1.6l1.2 1.8c.6.9 1.9.7 2.2-.3l2.9-7.9s.1-.2.2-.2h7.8V6.7h-7.8Zm5.3 3.4-1.9 1.9-1.9-1.9-1.1 1.1 1.9 1.9-1.9 1.9 1.1 1.1 1.9-1.9 1.9 1.9 1.1-1.1-1.9-1.9 1.9-1.9-1.1-1.1Z" }) });
197
198 // packages/icons/build-module/library/subscript.mjs
199 var import_primitives11 = __toESM(require_primitives(), 1);
200 var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
201 var subscript_default = /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_primitives11.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_primitives11.Path, { d: "M16.9 18.3l.8-1.2c.4-.6.7-1.2.9-1.6.2-.4.3-.8.3-1.2 0-.3-.1-.7-.2-1-.1-.3-.4-.5-.6-.7-.3-.2-.6-.3-1-.3s-.8.1-1.1.2c-.3.1-.7.3-1 .6l.2 1.3c.3-.3.5-.5.8-.6s.6-.2.9-.2c.3 0 .5.1.7.2.2.2.2.4.2.7 0 .3-.1.5-.2.8-.1.3-.4.7-.8 1.3L15 19.4h4.3v-1.2h-2.4zM14.1 7.2h-2L9.5 11 6.9 7.2h-2l3.6 5.3L4.7 18h2l2.7-4 2.7 4h2l-3.8-5.5 3.8-5.3z" }) });
202
203 // packages/icons/build-module/library/superscript.mjs
204 var import_primitives12 = __toESM(require_primitives(), 1);
205 var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
206 var superscript_default = /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_primitives12.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_primitives12.Path, { d: "M16.9 10.3l.8-1.3c.4-.6.7-1.2.9-1.6.2-.4.3-.8.3-1.2 0-.3-.1-.7-.2-1-.2-.2-.4-.4-.7-.6-.3-.2-.6-.3-1-.3s-.8.1-1.1.2c-.3.1-.7.3-1 .6l.1 1.3c.3-.3.5-.5.8-.6s.6-.2.9-.2c.3 0 .5.1.7.2.2.2.2.4.2.7 0 .3-.1.5-.2.8-.1.3-.4.7-.8 1.3l-1.8 2.8h4.3v-1.2h-2.2zm-2.8-3.1h-2L9.5 11 6.9 7.2h-2l3.6 5.3L4.7 18h2l2.7-4 2.7 4h2l-3.8-5.5 3.8-5.3z" }) });
207
208 // packages/icons/build-module/library/text-color.mjs
209 var import_primitives13 = __toESM(require_primitives(), 1);
210 var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
211 var text_color_default = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_primitives13.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_primitives13.Path, { d: "M12.9 6h-2l-4 11h1.9l1.1-3h4.2l1.1 3h1.9L12.9 6zm-2.5 6.5l1.5-4.9 1.7 4.9h-3.2z" }) });
212
213 // packages/format-library/build-module/bold/index.mjs
214 var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
215 var name = "core/bold";
216 var title = (0, import_i18n.__)("Bold");
217 var bold = {
218 name,
219 title,
220 tagName: "strong",
221 className: null,
222 edit({ isActive, value, onChange, onFocus, isVisible = true }) {
223 function onToggle() {
224 onChange((0, import_rich_text.toggleFormat)(value, { type: name, title }));
225 }
226 function onClick() {
227 onChange((0, import_rich_text.toggleFormat)(value, { type: name }));
228 onFocus();
229 }
230 return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
231 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
232 import_block_editor.RichTextShortcut,
233 {
234 type: "primary",
235 character: "b",
236 onUse: onToggle
237 }
238 ),
239 isVisible && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
240 import_block_editor.RichTextToolbarButton,
241 {
242 name: "bold",
243 icon: format_bold_default,
244 title,
245 onClick,
246 isActive,
247 shortcutType: "primary",
248 shortcutCharacter: "b"
249 }
250 ),
251 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
252 import_block_editor.__unstableRichTextInputEvent,
253 {
254 inputType: "formatBold",
255 onInput: onToggle
256 }
257 )
258 ] });
259 }
260 };
261
262 // packages/format-library/build-module/code/index.mjs
263 var import_i18n2 = __toESM(require_i18n(), 1);
264 var import_rich_text2 = __toESM(require_rich_text(), 1);
265 var import_block_editor2 = __toESM(require_block_editor(), 1);
266 var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
267 var name2 = "core/code";
268 var title2 = (0, import_i18n2.__)("Inline code");
269 var code = {
270 name: name2,
271 title: title2,
272 tagName: "code",
273 className: null,
274 __unstableInputRule(value) {
275 const BACKTICK = "`";
276 const { start, text } = value;
277 const characterBefore = text[start - 1];
278 if (characterBefore !== BACKTICK) {
279 return value;
280 }
281 if (start - 2 < 0) {
282 return value;
283 }
284 const indexBefore = text.lastIndexOf(BACKTICK, start - 2);
285 if (indexBefore === -1) {
286 return value;
287 }
288 const startIndex = indexBefore;
289 const endIndex = start - 2;
290 if (startIndex === endIndex) {
291 return value;
292 }
293 value = (0, import_rich_text2.remove)(value, startIndex, startIndex + 1);
294 value = (0, import_rich_text2.remove)(value, endIndex, endIndex + 1);
295 value = (0, import_rich_text2.applyFormat)(value, { type: name2 }, startIndex, endIndex);
296 return value;
297 },
298 edit({ value, onChange, onFocus, isActive }) {
299 function onClick() {
300 onChange((0, import_rich_text2.toggleFormat)(value, { type: name2, title: title2 }));
301 onFocus();
302 }
303 return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
304 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
305 import_block_editor2.RichTextShortcut,
306 {
307 type: "access",
308 character: "x",
309 onUse: onClick
310 }
311 ),
312 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
313 import_block_editor2.RichTextToolbarButton,
314 {
315 icon: code_default,
316 title: title2,
317 onClick,
318 isActive,
319 role: "menuitemcheckbox"
320 }
321 )
322 ] });
323 }
324 };
325
326 // packages/format-library/build-module/image/index.mjs
327 var import_components = __toESM(require_components(), 1);
328 var import_i18n3 = __toESM(require_i18n(), 1);
329 var import_element2 = __toESM(require_element(), 1);
330 var import_rich_text3 = __toESM(require_rich_text(), 1);
331 var import_block_editor3 = __toESM(require_block_editor(), 1);
332 var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1);
333 var ALLOWED_MEDIA_TYPES = ["image"];
334 var name3 = "core/image";
335 var title3 = (0, import_i18n3.__)("Inline image");
336 function getCurrentImageId(activeObjectAttributes) {
337 if (!activeObjectAttributes?.className) {
338 return void 0;
339 }
340 const [, id] = activeObjectAttributes.className.match(/wp-image-(\d+)/) ?? [];
341 return id ? parseInt(id, 10) : void 0;
342 }
343 var image = {
344 name: name3,
345 title: title3,
346 keywords: [(0, import_i18n3.__)("photo"), (0, import_i18n3.__)("media")],
347 object: true,
348 tagName: "img",
349 className: null,
350 attributes: {
351 className: "class",
352 style: "style",
353 url: "src",
354 alt: "alt"
355 },
356 edit: Edit
357 };
358 function InlineUI({ value, onChange, activeObjectAttributes, contentRef }) {
359 const { style, alt } = activeObjectAttributes;
360 const width = style?.replace(/\D/g, "");
361 const [editedWidth, setEditedWidth] = (0, import_element2.useState)(width);
362 const [editedAlt, setEditedAlt] = (0, import_element2.useState)(alt);
363 const hasChanged = editedWidth !== width || editedAlt !== alt;
364 const popoverAnchor = (0, import_rich_text3.useAnchor)({
365 editableContentElement: contentRef.current,
366 settings: image
367 });
368 return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
369 import_components.Popover,
370 {
371 focusOnMount: false,
372 anchor: popoverAnchor,
373 className: "block-editor-format-toolbar__image-popover",
374 children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
375 "form",
376 {
377 className: "block-editor-format-toolbar__image-container-content",
378 onSubmit: (event) => {
379 const newReplacements = value.replacements.slice();
380 newReplacements[value.start] = {
381 type: name3,
382 attributes: {
383 ...activeObjectAttributes,
384 style: editedWidth ? `width: ${editedWidth}px;` : "",
385 alt: editedAlt
386 }
387 };
388 onChange({
389 ...value,
390 replacements: newReplacements
391 });
392 event.preventDefault();
393 },
394 children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_components.__experimentalVStack, { spacing: 4, children: [
395 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
396 import_components.__experimentalNumberControl,
397 {
398 __next40pxDefaultSize: true,
399 label: (0, import_i18n3.__)("Width"),
400 value: editedWidth,
401 min: 1,
402 onChange: (newWidth) => {
403 setEditedWidth(newWidth);
404 }
405 }
406 ),
407 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
408 import_components.TextareaControl,
409 {
410 label: (0, import_i18n3.__)("Alternative text"),
411 value: editedAlt,
412 onChange: (newAlt) => {
413 setEditedAlt(newAlt);
414 },
415 help: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
416 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
417 import_components.ExternalLink,
418 {
419 href: (
420 // translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations.
421 (0, import_i18n3.__)(
422 "https://www.w3.org/WAI/tutorials/images/decision-tree/"
423 )
424 ),
425 children: (0, import_i18n3.__)(
426 "Describe the purpose of the image."
427 )
428 }
429 ),
430 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("br", {}),
431 (0, import_i18n3.__)("Leave empty if decorative.")
432 ] })
433 }
434 ),
435 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_components.__experimentalHStack, { justify: "right", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
436 import_components.Button,
437 {
438 disabled: !hasChanged,
439 accessibleWhenDisabled: true,
440 variant: "primary",
441 type: "submit",
442 size: "compact",
443 children: (0, import_i18n3.__)("Apply")
444 }
445 ) })
446 ] })
447 }
448 )
449 }
450 );
451 }
452 function Edit({
453 value,
454 onChange,
455 onFocus,
456 isObjectActive,
457 activeObjectAttributes,
458 contentRef
459 }) {
460 return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_block_editor3.MediaUploadCheck, { children: [
461 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
462 import_block_editor3.MediaUpload,
463 {
464 allowedTypes: ALLOWED_MEDIA_TYPES,
465 value: getCurrentImageId(activeObjectAttributes),
466 onSelect: ({ id, url, alt, width: imgWidth }) => {
467 onChange(
468 (0, import_rich_text3.insertObject)(value, {
469 type: name3,
470 attributes: {
471 className: `wp-image-${id}`,
472 style: `width: ${Math.min(
473 imgWidth,
474 150
475 )}px;`,
476 url,
477 alt
478 }
479 })
480 );
481 onFocus();
482 },
483 render: ({ open }) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
484 import_block_editor3.RichTextToolbarButton,
485 {
486 icon: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
487 import_components.SVG,
488 {
489 xmlns: "http://www.w3.org/2000/svg",
490 viewBox: "0 0 24 24",
491 children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_components.Path, { d: "M4 18.5h16V17H4v1.5zM16 13v1.5h4V13h-4zM5.1 15h7.8c.6 0 1.1-.5 1.1-1.1V6.1c0-.6-.5-1.1-1.1-1.1H5.1C4.5 5 4 5.5 4 6.1v7.8c0 .6.5 1.1 1.1 1.1zm.4-8.5h7V10l-1-1c-.3-.3-.8-.3-1 0l-1.6 1.5-1.2-.7c-.3-.2-.6-.2-.9 0l-1.3 1V6.5zm0 6.1l1.8-1.3 1.3.8c.3.2.7.2.9-.1l1.5-1.4 1.5 1.4v1.5h-7v-.9z" })
492 }
493 ),
494 title: isObjectActive ? (0, import_i18n3.__)("Replace image") : title3,
495 onClick: open,
496 isActive: isObjectActive
497 }
498 )
499 }
500 ),
501 isObjectActive && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
502 InlineUI,
503 {
504 value,
505 onChange,
506 activeObjectAttributes,
507 contentRef
508 }
509 )
510 ] });
511 }
512
513 // packages/format-library/build-module/italic/index.mjs
514 var import_i18n4 = __toESM(require_i18n(), 1);
515 var import_rich_text4 = __toESM(require_rich_text(), 1);
516 var import_block_editor4 = __toESM(require_block_editor(), 1);
517 var import_jsx_runtime17 = __toESM(require_jsx_runtime(), 1);
518 var name4 = "core/italic";
519 var title4 = (0, import_i18n4.__)("Italic");
520 var italic = {
521 name: name4,
522 title: title4,
523 tagName: "em",
524 className: null,
525 edit({ isActive, value, onChange, onFocus, isVisible = true }) {
526 function onToggle() {
527 onChange((0, import_rich_text4.toggleFormat)(value, { type: name4, title: title4 }));
528 }
529 function onClick() {
530 onChange((0, import_rich_text4.toggleFormat)(value, { type: name4 }));
531 onFocus();
532 }
533 return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
534 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
535 import_block_editor4.RichTextShortcut,
536 {
537 type: "primary",
538 character: "i",
539 onUse: onToggle
540 }
541 ),
542 isVisible && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
543 import_block_editor4.RichTextToolbarButton,
544 {
545 name: "italic",
546 icon: format_italic_default,
547 title: title4,
548 onClick,
549 isActive,
550 shortcutType: "primary",
551 shortcutCharacter: "i"
552 }
553 ),
554 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
555 import_block_editor4.__unstableRichTextInputEvent,
556 {
557 inputType: "formatItalic",
558 onInput: onToggle
559 }
560 )
561 ] });
562 }
563 };
564
565 // packages/format-library/build-module/link/index.mjs
566 var import_i18n7 = __toESM(require_i18n(), 1);
567 var import_element5 = __toESM(require_element(), 1);
568 var import_rich_text6 = __toESM(require_rich_text(), 1);
569 var import_url3 = __toESM(require_url(), 1);
570 var import_block_editor6 = __toESM(require_block_editor(), 1);
571 var import_html_entities = __toESM(require_html_entities(), 1);
572 var import_a11y2 = __toESM(require_a11y(), 1);
573
574 // packages/format-library/build-module/link/inline.mjs
575 var import_element4 = __toESM(require_element(), 1);
576 var import_i18n6 = __toESM(require_i18n(), 1);
577 var import_a11y = __toESM(require_a11y(), 1);
578 var import_components3 = __toESM(require_components(), 1);
579 var import_url2 = __toESM(require_url(), 1);
580 var import_rich_text5 = __toESM(require_rich_text(), 1);
581 var import_block_editor5 = __toESM(require_block_editor(), 1);
582 var import_data = __toESM(require_data(), 1);
583
584 // packages/format-library/build-module/link/utils.mjs
585 var import_url = __toESM(require_url(), 1);
586 function isValidHref(href) {
587 if (!href) {
588 return false;
589 }
590 const trimmedHref = href.trim();
591 if (!trimmedHref) {
592 return false;
593 }
594 if (/^\S+:/.test(trimmedHref)) {
595 const protocol = (0, import_url.getProtocol)(trimmedHref);
596 if (!(0, import_url.isValidProtocol)(protocol)) {
597 return false;
598 }
599 if (protocol.startsWith("http") && !/^https?:\/\/[^\/\s]/i.test(trimmedHref)) {
600 return false;
601 }
602 const authority = (0, import_url.getAuthority)(trimmedHref);
603 if (!(0, import_url.isValidAuthority)(authority)) {
604 return false;
605 }
606 const path = (0, import_url.getPath)(trimmedHref);
607 if (path && !(0, import_url.isValidPath)(path)) {
608 return false;
609 }
610 const queryString = (0, import_url.getQueryString)(trimmedHref);
611 if (queryString && !(0, import_url.isValidQueryString)(queryString)) {
612 return false;
613 }
614 const fragment = (0, import_url.getFragment)(trimmedHref);
615 if (fragment && !(0, import_url.isValidFragment)(fragment)) {
616 return false;
617 }
618 }
619 if (trimmedHref.startsWith("#") && !(0, import_url.isValidFragment)(trimmedHref)) {
620 return false;
621 }
622 return true;
623 }
624 function createLinkFormat({
625 url,
626 type,
627 id,
628 opensInNewWindow,
629 nofollow,
630 cssClasses
631 }) {
632 const format = {
633 type: "core/link",
634 attributes: {
635 url
636 }
637 };
638 if (type) {
639 format.attributes.type = type;
640 }
641 if (id) {
642 format.attributes.id = id;
643 }
644 if (opensInNewWindow) {
645 format.attributes.target = "_blank";
646 format.attributes.rel = format.attributes.rel ? format.attributes.rel + " noreferrer noopener" : "noreferrer noopener";
647 }
648 if (nofollow) {
649 format.attributes.rel = format.attributes.rel ? format.attributes.rel + " nofollow" : "nofollow";
650 }
651 const trimmedCssClasses = cssClasses?.trim();
652 if (trimmedCssClasses?.length) {
653 format.attributes.class = trimmedCssClasses;
654 }
655 return format;
656 }
657 function getFormatBoundary(value, format, startIndex = value.start, endIndex = value.end) {
658 const EMPTY_BOUNDARIES = {
659 start: void 0,
660 end: void 0
661 };
662 const { formats } = value;
663 let targetFormat;
664 let initialIndex;
665 if (!formats?.length) {
666 return EMPTY_BOUNDARIES;
667 }
668 const newFormats = formats.slice();
669 const formatAtStart = newFormats[startIndex]?.find(
670 ({ type }) => type === format.type
671 );
672 const formatAtEnd = newFormats[endIndex]?.find(
673 ({ type }) => type === format.type
674 );
675 const formatAtEndMinusOne = newFormats[endIndex - 1]?.find(
676 ({ type }) => type === format.type
677 );
678 if (!!formatAtStart) {
679 targetFormat = formatAtStart;
680 initialIndex = startIndex;
681 } else if (!!formatAtEnd) {
682 targetFormat = formatAtEnd;
683 initialIndex = endIndex;
684 } else if (!!formatAtEndMinusOne) {
685 targetFormat = formatAtEndMinusOne;
686 initialIndex = endIndex - 1;
687 } else {
688 return EMPTY_BOUNDARIES;
689 }
690 const index = newFormats[initialIndex].indexOf(targetFormat);
691 const walkingArgs = [newFormats, initialIndex, targetFormat, index];
692 startIndex = walkToStart(...walkingArgs);
693 endIndex = walkToEnd(...walkingArgs);
694 startIndex = startIndex < 0 ? 0 : startIndex;
695 return {
696 start: startIndex,
697 end: endIndex + 1
698 };
699 }
700 function walkToBoundary(formats, initialIndex, targetFormatRef, formatIndex, direction) {
701 let index = initialIndex;
702 const directions = {
703 forwards: 1,
704 backwards: -1
705 };
706 const directionIncrement = directions[direction] || 1;
707 const inverseDirectionIncrement = directionIncrement * -1;
708 while (formats[index] && formats[index][formatIndex] === targetFormatRef) {
709 index = index + directionIncrement;
710 }
711 index = index + inverseDirectionIncrement;
712 return index;
713 }
714 var partialRight = (fn, ...partialArgs) => (...args) => fn(...args, ...partialArgs);
715 var walkToStart = partialRight(walkToBoundary, "backwards");
716 var walkToEnd = partialRight(walkToBoundary, "forwards");
717
718 // packages/format-library/build-module/link/css-classes-setting.mjs
719 var import_element3 = __toESM(require_element(), 1);
720 var import_compose = __toESM(require_compose(), 1);
721 var import_i18n5 = __toESM(require_i18n(), 1);
722 var import_components2 = __toESM(require_components(), 1);
723 var import_jsx_runtime18 = __toESM(require_jsx_runtime(), 1);
724 var CSSClassesSettingComponent = ({ setting, value, onChange }) => {
725 const hasValue = value ? value?.cssClasses?.length > 0 : false;
726 const [isSettingActive, setIsSettingActive] = (0, import_element3.useState)(hasValue);
727 const instanceId = (0, import_compose.useInstanceId)(CSSClassesSettingComponent);
728 const controlledRegionId = `css-classes-setting-${instanceId}`;
729 const handleSettingChange = (newValue) => {
730 const sanitizedValue = typeof newValue === "string" ? newValue.replace(/,/g, " ").replace(/\s+/g, " ").trim() : newValue;
731 onChange({
732 ...value,
733 [setting.id]: sanitizedValue
734 });
735 };
736 const handleCheckboxChange = () => {
737 if (isSettingActive) {
738 if (hasValue) {
739 handleSettingChange("");
740 }
741 setIsSettingActive(false);
742 } else {
743 setIsSettingActive(true);
744 }
745 };
746 return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("fieldset", { children: [
747 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_components2.VisuallyHidden, { as: "legend", children: setting.title }),
748 /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_components2.__experimentalVStack, { spacing: 3, children: [
749 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
750 import_components2.CheckboxControl,
751 {
752 label: setting.title,
753 onChange: handleCheckboxChange,
754 checked: isSettingActive || hasValue,
755 "aria-expanded": isSettingActive,
756 "aria-controls": isSettingActive ? controlledRegionId : void 0
757 }
758 ),
759 isSettingActive && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { id: controlledRegionId, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
760 import_components2.__experimentalInputControl,
761 {
762 label: (0, import_i18n5.__)("CSS classes"),
763 value: value?.cssClasses,
764 onChange: handleSettingChange,
765 help: (0, import_i18n5.__)(
766 "Separate multiple classes with spaces."
767 ),
768 __unstableInputWidth: "100%",
769 __next40pxDefaultSize: true
770 }
771 ) })
772 ] })
773 ] });
774 };
775 var css_classes_setting_default = CSSClassesSettingComponent;
776
777 // packages/format-library/build-module/link/inline.mjs
778 var import_jsx_runtime19 = __toESM(require_jsx_runtime(), 1);
779 var LINK_SETTINGS = [
780 ...import_block_editor5.LinkControl.DEFAULT_LINK_SETTINGS,
781 {
782 id: "nofollow",
783 title: (0, import_i18n6.__)("Mark as nofollow")
784 },
785 {
786 id: "cssClasses",
787 title: (0, import_i18n6.__)("Additional CSS class(es)"),
788 render: (setting, value, onChange) => {
789 return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
790 css_classes_setting_default,
791 {
792 setting,
793 value,
794 onChange
795 }
796 );
797 }
798 }
799 ];
800 function InlineLinkUI({
801 isActive,
802 activeAttributes,
803 value,
804 onChange,
805 onFocusOutside,
806 stopAddingLink,
807 contentRef,
808 focusOnMount
809 }) {
810 const richLinkTextValue = getRichTextValueFromSelection(value, isActive);
811 const richTextText = richLinkTextValue.text;
812 const { selectionChange } = (0, import_data.useDispatch)(import_block_editor5.store);
813 const { createPageEntity, userCanCreatePages, selectionStart } = (0, import_data.useSelect)(
814 (select) => {
815 const { getSettings, getSelectionStart } = select(import_block_editor5.store);
816 const _settings = getSettings();
817 return {
818 createPageEntity: _settings.__experimentalCreatePageEntity,
819 userCanCreatePages: _settings.__experimentalUserCanCreatePages,
820 selectionStart: getSelectionStart()
821 };
822 },
823 []
824 );
825 const linkValue = (0, import_element4.useMemo)(
826 () => ({
827 url: activeAttributes.url,
828 type: activeAttributes.type,
829 id: activeAttributes.id,
830 opensInNewTab: activeAttributes.target === "_blank",
831 nofollow: activeAttributes.rel?.includes("nofollow"),
832 title: richTextText,
833 cssClasses: activeAttributes.class
834 }),
835 [
836 activeAttributes.class,
837 activeAttributes.id,
838 activeAttributes.rel,
839 activeAttributes.target,
840 activeAttributes.type,
841 activeAttributes.url,
842 richTextText
843 ]
844 );
845 function removeLink() {
846 const newValue = (0, import_rich_text5.removeFormat)(value, "core/link");
847 onChange(newValue);
848 stopAddingLink();
849 (0, import_a11y.speak)((0, import_i18n6.__)("Link removed."), "assertive");
850 }
851 function onChangeLink(nextValue) {
852 const hasLink = linkValue?.url;
853 const isNewLink = !hasLink;
854 nextValue = {
855 ...linkValue,
856 ...nextValue
857 };
858 const newUrl = (0, import_url2.prependHTTPS)(nextValue.url);
859 const linkFormat = createLinkFormat({
860 url: newUrl,
861 type: nextValue.type,
862 id: nextValue.id !== void 0 && nextValue.id !== null ? String(nextValue.id) : void 0,
863 opensInNewWindow: nextValue.opensInNewTab,
864 nofollow: nextValue.nofollow,
865 cssClasses: nextValue.cssClasses
866 });
867 const newText = nextValue.title || newUrl;
868 let newValue;
869 if ((0, import_rich_text5.isCollapsed)(value) && !isActive) {
870 const inserted = (0, import_rich_text5.insert)(value, newText);
871 newValue = (0, import_rich_text5.applyFormat)(
872 inserted,
873 linkFormat,
874 value.start,
875 value.start + newText.length
876 );
877 onChange(newValue);
878 stopAddingLink();
879 selectionChange({
880 clientId: selectionStart.clientId,
881 identifier: selectionStart.attributeKey,
882 start: value.start + newText.length + 1
883 });
884 return;
885 } else if (newText === richTextText) {
886 const boundary = getFormatBoundary(value, {
887 type: "core/link"
888 });
889 newValue = (0, import_rich_text5.applyFormat)(
890 value,
891 linkFormat,
892 boundary.start,
893 boundary.end
894 );
895 } else {
896 newValue = (0, import_rich_text5.create)({ text: newText });
897 newValue = (0, import_rich_text5.applyFormat)(newValue, linkFormat, 0, newText.length);
898 const boundary = getFormatBoundary(value, {
899 type: "core/link"
900 });
901 const [valBefore, valAfter] = (0, import_rich_text5.split)(
902 value,
903 boundary.start,
904 boundary.start
905 );
906 const newValAfter = (0, import_rich_text5.replace)(valAfter, richTextText, newValue);
907 newValue = (0, import_rich_text5.concat)(valBefore, newValAfter);
908 }
909 onChange(newValue);
910 if (!isNewLink) {
911 stopAddingLink();
912 }
913 if (!isValidHref(newUrl)) {
914 (0, import_a11y.speak)(
915 (0, import_i18n6.__)(
916 "Warning: the link has been inserted but may have errors. Please test it."
917 ),
918 "assertive"
919 );
920 } else if (isActive) {
921 (0, import_a11y.speak)((0, import_i18n6.__)("Link edited."), "assertive");
922 } else {
923 (0, import_a11y.speak)((0, import_i18n6.__)("Link inserted."), "assertive");
924 }
925 }
926 const popoverAnchor = (0, import_rich_text5.useAnchor)({
927 editableContentElement: contentRef.current,
928 settings: {
929 ...link,
930 isActive
931 }
932 });
933 async function handleCreate(pageTitle) {
934 const page = await createPageEntity({
935 title: pageTitle,
936 status: "draft"
937 });
938 return {
939 id: page.id,
940 type: page.type,
941 title: page.title.rendered,
942 url: page.link,
943 kind: "post-type"
944 };
945 }
946 function createButtonText(searchTerm) {
947 return (0, import_element4.createInterpolateElement)(
948 (0, import_i18n6.sprintf)(
949 /* translators: %s: search term. */
950 (0, import_i18n6.__)("Create page: <mark>%s</mark>"),
951 searchTerm
952 ),
953 { mark: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("mark", {}) }
954 );
955 }
956 return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
957 import_components3.Popover,
958 {
959 anchor: popoverAnchor,
960 animate: false,
961 onClose: stopAddingLink,
962 onFocusOutside,
963 placement: "bottom",
964 offset: 8,
965 shift: true,
966 focusOnMount,
967 constrainTabbing: true,
968 children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
969 import_block_editor5.LinkControl,
970 {
971 value: linkValue,
972 onChange: onChangeLink,
973 onRemove: removeLink,
974 hasRichPreviews: true,
975 createSuggestion: createPageEntity && handleCreate,
976 withCreateSuggestion: userCanCreatePages,
977 createSuggestionButtonText: createButtonText,
978 hasTextControl: true,
979 settings: LINK_SETTINGS,
980 showInitialSuggestions: true,
981 suggestionsQuery: {
982 // always show Pages as initial suggestions
983 initialSuggestionsSearchOptions: {
984 type: "post",
985 subtype: "page",
986 perPage: 20
987 }
988 }
989 }
990 )
991 }
992 );
993 }
994 function getRichTextValueFromSelection(value, isActive) {
995 let textStart = value.start;
996 let textEnd = value.end;
997 if (isActive) {
998 const boundary = getFormatBoundary(value, {
999 type: "core/link"
1000 });
1001 textStart = boundary.start;
1002 textEnd = boundary.end;
1003 }
1004 return (0, import_rich_text5.slice)(value, textStart, textEnd);
1005 }
1006 var inline_default = InlineLinkUI;
1007
1008 // packages/format-library/build-module/link/index.mjs
1009 var import_jsx_runtime20 = __toESM(require_jsx_runtime(), 1);
1010 var name5 = "core/link";
1011 var title5 = (0, import_i18n7.__)("Link");
1012 function Edit2({
1013 isActive,
1014 activeAttributes,
1015 value,
1016 onChange,
1017 onFocus,
1018 contentRef,
1019 isVisible = true
1020 }) {
1021 const [addingLink, setAddingLink] = (0, import_element5.useState)(false);
1022 const [openedBy, setOpenedBy] = (0, import_element5.useState)(null);
1023 (0, import_element5.useEffect)(() => {
1024 if (!isActive) {
1025 setAddingLink(false);
1026 }
1027 }, [isActive]);
1028 (0, import_element5.useLayoutEffect)(() => {
1029 const editableContentElement = contentRef.current;
1030 if (!editableContentElement) {
1031 return;
1032 }
1033 function handleClick(event) {
1034 const link2 = event.target.closest("[contenteditable] a");
1035 if (!link2 || // other formats (e.g. bold) may be nested within the link.
1036 !isActive) {
1037 return;
1038 }
1039 setAddingLink(true);
1040 setOpenedBy({
1041 el: link2,
1042 action: "click"
1043 });
1044 }
1045 editableContentElement.addEventListener("click", handleClick);
1046 return () => {
1047 editableContentElement.removeEventListener("click", handleClick);
1048 };
1049 }, [contentRef, isActive]);
1050 function addLink(target) {
1051 const text = (0, import_rich_text6.getTextContent)((0, import_rich_text6.slice)(value));
1052 if (!isActive && text && (0, import_url3.isURL)(text) && isValidHref(text)) {
1053 onChange(
1054 (0, import_rich_text6.applyFormat)(value, {
1055 type: name5,
1056 attributes: { url: text }
1057 })
1058 );
1059 } else if (!isActive && text && (0, import_url3.isEmail)(text)) {
1060 onChange(
1061 (0, import_rich_text6.applyFormat)(value, {
1062 type: name5,
1063 attributes: { url: `mailto:${text}` }
1064 })
1065 );
1066 } else if (!isActive && text && (0, import_url3.isPhoneNumber)(text)) {
1067 onChange(
1068 (0, import_rich_text6.applyFormat)(value, {
1069 type: name5,
1070 attributes: { url: `tel:${text.replace(/\D/g, "")}` }
1071 })
1072 );
1073 } else {
1074 if (target) {
1075 setOpenedBy({
1076 el: target,
1077 action: null
1078 // We don't need to distinguish between click or keyboard here
1079 });
1080 }
1081 setAddingLink(true);
1082 }
1083 }
1084 function stopAddingLink() {
1085 setAddingLink(false);
1086 if (openedBy?.el?.tagName === "BUTTON") {
1087 openedBy.el.focus();
1088 } else {
1089 onFocus();
1090 }
1091 setOpenedBy(null);
1092 }
1093 function onFocusOutside() {
1094 setAddingLink(false);
1095 setOpenedBy(null);
1096 }
1097 function onRemoveFormat() {
1098 onChange((0, import_rich_text6.removeFormat)(value, name5));
1099 (0, import_a11y2.speak)((0, import_i18n7.__)("Link removed."), "assertive");
1100 }
1101 const shouldAutoFocus = !(openedBy?.el?.tagName === "A" && openedBy?.action === "click");
1102 const hasSelection = !(0, import_rich_text6.isCollapsed)(value);
1103 return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
1104 hasSelection && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1105 import_block_editor6.RichTextShortcut,
1106 {
1107 type: "primary",
1108 character: "k",
1109 onUse: addLink
1110 }
1111 ),
1112 /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1113 import_block_editor6.RichTextShortcut,
1114 {
1115 type: "primaryShift",
1116 character: "k",
1117 onUse: onRemoveFormat
1118 }
1119 ),
1120 isVisible && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1121 import_block_editor6.RichTextToolbarButton,
1122 {
1123 name: "link",
1124 icon: link_default,
1125 title: isActive ? (0, import_i18n7.__)("Link") : title5,
1126 onClick: (event) => {
1127 addLink(event.currentTarget);
1128 },
1129 isActive: isActive || addingLink,
1130 shortcutType: "primary",
1131 shortcutCharacter: "k",
1132 "aria-haspopup": "true",
1133 "aria-expanded": addingLink
1134 }
1135 ),
1136 isVisible && addingLink && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1137 inline_default,
1138 {
1139 stopAddingLink,
1140 onFocusOutside,
1141 isActive,
1142 activeAttributes,
1143 value,
1144 onChange,
1145 contentRef,
1146 focusOnMount: shouldAutoFocus ? "firstElement" : false
1147 }
1148 )
1149 ] });
1150 }
1151 var link = {
1152 name: name5,
1153 title: title5,
1154 tagName: "a",
1155 className: null,
1156 attributes: {
1157 url: "href",
1158 type: "data-type",
1159 id: "data-id",
1160 _id: "id",
1161 target: "target",
1162 rel: "rel",
1163 class: "class"
1164 },
1165 __unstablePasteRule(value, { html, plainText }) {
1166 const pastedText = (html || plainText).replace(/<[^>]+>/g, "").trim();
1167 if (!(0, import_url3.isURL)(pastedText) || !/^https?:/.test(pastedText)) {
1168 return value;
1169 }
1170 window.console.log("Created link:\n\n", pastedText);
1171 const format = {
1172 type: name5,
1173 attributes: {
1174 url: (0, import_html_entities.decodeEntities)(pastedText)
1175 }
1176 };
1177 if ((0, import_rich_text6.isCollapsed)(value)) {
1178 return (0, import_rich_text6.insert)(
1179 value,
1180 (0, import_rich_text6.applyFormat)(
1181 (0, import_rich_text6.create)({ text: plainText }),
1182 format,
1183 0,
1184 plainText.length
1185 )
1186 );
1187 }
1188 return (0, import_rich_text6.applyFormat)(value, format);
1189 },
1190 edit: Edit2
1191 };
1192
1193 // packages/format-library/build-module/strikethrough/index.mjs
1194 var import_i18n8 = __toESM(require_i18n(), 1);
1195 var import_rich_text7 = __toESM(require_rich_text(), 1);
1196 var import_block_editor7 = __toESM(require_block_editor(), 1);
1197 var import_jsx_runtime21 = __toESM(require_jsx_runtime(), 1);
1198 var name6 = "core/strikethrough";
1199 var title6 = (0, import_i18n8.__)("Strikethrough");
1200 var strikethrough = {
1201 name: name6,
1202 title: title6,
1203 tagName: "s",
1204 className: null,
1205 edit({ isActive, value, onChange, onFocus }) {
1206 function onClick() {
1207 onChange((0, import_rich_text7.toggleFormat)(value, { type: name6, title: title6 }));
1208 onFocus();
1209 }
1210 return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
1211 /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1212 import_block_editor7.RichTextShortcut,
1213 {
1214 type: "access",
1215 character: "d",
1216 onUse: onClick
1217 }
1218 ),
1219 /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1220 import_block_editor7.RichTextToolbarButton,
1221 {
1222 icon: format_strikethrough_default,
1223 title: title6,
1224 onClick,
1225 isActive,
1226 role: "menuitemcheckbox"
1227 }
1228 )
1229 ] });
1230 }
1231 };
1232
1233 // packages/format-library/build-module/underline/index.mjs
1234 var import_i18n9 = __toESM(require_i18n(), 1);
1235 var import_rich_text8 = __toESM(require_rich_text(), 1);
1236 var import_block_editor8 = __toESM(require_block_editor(), 1);
1237 var import_jsx_runtime22 = __toESM(require_jsx_runtime(), 1);
1238 var name7 = "core/underline";
1239 var title7 = (0, import_i18n9.__)("Underline");
1240 var underline = {
1241 name: name7,
1242 title: title7,
1243 tagName: "span",
1244 className: null,
1245 attributes: {
1246 style: "style"
1247 },
1248 edit({ value, onChange }) {
1249 const onToggle = () => {
1250 onChange(
1251 (0, import_rich_text8.toggleFormat)(value, {
1252 type: name7,
1253 attributes: {
1254 style: "text-decoration: underline;"
1255 },
1256 title: title7
1257 })
1258 );
1259 };
1260 return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
1261 /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1262 import_block_editor8.RichTextShortcut,
1263 {
1264 type: "primary",
1265 character: "u",
1266 onUse: onToggle
1267 }
1268 ),
1269 /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1270 import_block_editor8.__unstableRichTextInputEvent,
1271 {
1272 inputType: "formatUnderline",
1273 onInput: onToggle
1274 }
1275 )
1276 ] });
1277 }
1278 };
1279
1280 // packages/format-library/build-module/text-color/index.mjs
1281 var import_i18n11 = __toESM(require_i18n(), 1);
1282 var import_element7 = __toESM(require_element(), 1);
1283 var import_block_editor10 = __toESM(require_block_editor(), 1);
1284 var import_rich_text10 = __toESM(require_rich_text(), 1);
1285
1286 // packages/format-library/build-module/text-color/inline.mjs
1287 var import_element6 = __toESM(require_element(), 1);
1288 var import_data2 = __toESM(require_data(), 1);
1289 var import_rich_text9 = __toESM(require_rich_text(), 1);
1290 var import_block_editor9 = __toESM(require_block_editor(), 1);
1291 var import_components4 = __toESM(require_components(), 1);
1292 var import_i18n10 = __toESM(require_i18n(), 1);
1293
1294 // packages/format-library/build-module/lock-unlock.mjs
1295 var import_private_apis = __toESM(require_private_apis(), 1);
1296 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
1297 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
1298 "@wordpress/format-library"
1299 );
1300
1301 // packages/format-library/build-module/text-color/inline.mjs
1302 var import_jsx_runtime23 = __toESM(require_jsx_runtime(), 1);
1303 var { Tabs } = unlock(import_components4.privateApis);
1304 var TABS = [
1305 { name: "color", title: (0, import_i18n10.__)("Text") },
1306 { name: "backgroundColor", title: (0, import_i18n10.__)("Background") }
1307 ];
1308 function parseCSS(css = "") {
1309 return css.split(";").reduce((accumulator, rule) => {
1310 if (rule) {
1311 const [property, value] = rule.split(":");
1312 if (property === "color") {
1313 accumulator.color = value;
1314 }
1315 if (property === "background-color" && value !== transparentValue) {
1316 accumulator.backgroundColor = value;
1317 }
1318 }
1319 return accumulator;
1320 }, {});
1321 }
1322 function parseClassName(className = "", colorSettings) {
1323 return className.split(" ").reduce((accumulator, name16) => {
1324 if (name16.startsWith("has-") && name16.endsWith("-color")) {
1325 const colorSlug = name16.replace(/^has-/, "").replace(/-color$/, "");
1326 const colorObject = (0, import_block_editor9.getColorObjectByAttributeValues)(
1327 colorSettings,
1328 colorSlug
1329 );
1330 accumulator.color = colorObject.color;
1331 }
1332 return accumulator;
1333 }, {});
1334 }
1335 function getActiveColors(value, name16, colorSettings) {
1336 const activeColorFormat = (0, import_rich_text9.getActiveFormat)(value, name16);
1337 if (!activeColorFormat) {
1338 return {};
1339 }
1340 return {
1341 ...parseCSS(activeColorFormat.attributes.style),
1342 ...parseClassName(activeColorFormat.attributes.class, colorSettings)
1343 };
1344 }
1345 function setColors(value, name16, colorSettings, colors) {
1346 const { color, backgroundColor } = {
1347 ...getActiveColors(value, name16, colorSettings),
1348 ...colors
1349 };
1350 if (!color && !backgroundColor) {
1351 return (0, import_rich_text9.removeFormat)(value, name16);
1352 }
1353 const styles = [];
1354 const classNames = [];
1355 const attributes = {};
1356 if (backgroundColor) {
1357 styles.push(["background-color", backgroundColor].join(":"));
1358 } else {
1359 styles.push(["background-color", transparentValue].join(":"));
1360 }
1361 if (color) {
1362 const colorObject = (0, import_block_editor9.getColorObjectByColorValue)(colorSettings, color);
1363 if (colorObject) {
1364 classNames.push((0, import_block_editor9.getColorClassName)("color", colorObject.slug));
1365 } else {
1366 styles.push(["color", color].join(":"));
1367 }
1368 }
1369 if (styles.length) {
1370 attributes.style = styles.join(";");
1371 }
1372 if (classNames.length) {
1373 attributes.class = classNames.join(" ");
1374 }
1375 return (0, import_rich_text9.applyFormat)(value, { type: name16, attributes });
1376 }
1377 function ColorPicker({ name: name16, property, value, onChange }) {
1378 const colors = (0, import_data2.useSelect)((select) => {
1379 const { getSettings } = select(import_block_editor9.store);
1380 return getSettings().colors ?? [];
1381 }, []);
1382 const activeColors = (0, import_element6.useMemo)(
1383 () => getActiveColors(value, name16, colors),
1384 [name16, value, colors]
1385 );
1386 return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
1387 import_block_editor9.ColorPalette,
1388 {
1389 value: activeColors[property],
1390 onChange: (color) => {
1391 onChange(
1392 setColors(value, name16, colors, { [property]: color })
1393 );
1394 },
1395 enableAlpha: true,
1396 __experimentalIsRenderedInSidebar: true
1397 }
1398 );
1399 }
1400 function InlineColorUI({
1401 name: name16,
1402 value,
1403 onChange,
1404 onClose,
1405 contentRef,
1406 isActive
1407 }) {
1408 const popoverAnchor = (0, import_rich_text9.useAnchor)({
1409 editableContentElement: contentRef.current,
1410 settings: { ...textColor, isActive }
1411 });
1412 return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
1413 import_components4.Popover,
1414 {
1415 onClose,
1416 className: "format-library__inline-color-popover",
1417 anchor: popoverAnchor,
1418 children: /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(Tabs, { children: [
1419 /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Tabs.TabList, { children: TABS.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Tabs.Tab, { tabId: tab.name, children: tab.title }, tab.name)) }),
1420 TABS.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
1421 Tabs.TabPanel,
1422 {
1423 tabId: tab.name,
1424 focusable: false,
1425 children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
1426 ColorPicker,
1427 {
1428 name: name16,
1429 property: tab.name,
1430 value,
1431 onChange
1432 }
1433 )
1434 },
1435 tab.name
1436 ))
1437 ] })
1438 }
1439 );
1440 }
1441
1442 // packages/format-library/build-module/text-color/index.mjs
1443 var import_jsx_runtime24 = __toESM(require_jsx_runtime(), 1);
1444 var transparentValue = "rgba(0, 0, 0, 0)";
1445 var name8 = "core/text-color";
1446 var title8 = (0, import_i18n11.__)("Highlight");
1447 var EMPTY_ARRAY = [];
1448 function getComputedStyleProperty(element, property) {
1449 const { ownerDocument } = element;
1450 const { defaultView } = ownerDocument;
1451 const style = defaultView.getComputedStyle(element);
1452 const value = style.getPropertyValue(property);
1453 if (property === "background-color" && value === transparentValue && element.parentElement) {
1454 return getComputedStyleProperty(element.parentElement, property);
1455 }
1456 return value;
1457 }
1458 function fillComputedColors(element, { color, backgroundColor }) {
1459 if (!color && !backgroundColor) {
1460 return;
1461 }
1462 return {
1463 color: color || getComputedStyleProperty(element, "color"),
1464 backgroundColor: backgroundColor === transparentValue ? getComputedStyleProperty(element, "background-color") : backgroundColor
1465 };
1466 }
1467 function TextColorEdit({
1468 value,
1469 onChange,
1470 isActive,
1471 activeAttributes,
1472 contentRef
1473 }) {
1474 const [allowCustomControl, colors = EMPTY_ARRAY] = (0, import_block_editor10.useSettings)(
1475 "color.custom",
1476 "color.palette"
1477 );
1478 const [isAddingColor, setIsAddingColor] = (0, import_element7.useState)(false);
1479 const colorIndicatorStyle = (0, import_element7.useMemo)(
1480 () => fillComputedColors(
1481 contentRef.current,
1482 getActiveColors(value, name8, colors)
1483 ),
1484 [contentRef, value, colors]
1485 );
1486 const hasColorsToChoose = !!colors.length || allowCustomControl;
1487 if (!hasColorsToChoose && !isActive) {
1488 return null;
1489 }
1490 return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
1491 /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1492 import_block_editor10.RichTextToolbarButton,
1493 {
1494 className: "format-library-text-color-button",
1495 isActive,
1496 icon: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1497 icon_default,
1498 {
1499 icon: Object.keys(activeAttributes).length ? text_color_default : color_default,
1500 style: colorIndicatorStyle
1501 }
1502 ),
1503 title: title8,
1504 onClick: hasColorsToChoose ? () => setIsAddingColor(true) : () => onChange((0, import_rich_text10.removeFormat)(value, name8)),
1505 role: "menuitemcheckbox"
1506 }
1507 ),
1508 isAddingColor && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1509 InlineColorUI,
1510 {
1511 name: name8,
1512 onClose: () => setIsAddingColor(false),
1513 activeAttributes,
1514 value,
1515 onChange,
1516 contentRef,
1517 isActive
1518 }
1519 )
1520 ] });
1521 }
1522 var textColor = {
1523 name: name8,
1524 title: title8,
1525 tagName: "mark",
1526 className: "has-inline-color",
1527 attributes: {
1528 style: "style",
1529 class: "class"
1530 },
1531 edit: TextColorEdit
1532 };
1533
1534 // packages/format-library/build-module/subscript/index.mjs
1535 var import_i18n12 = __toESM(require_i18n(), 1);
1536 var import_rich_text11 = __toESM(require_rich_text(), 1);
1537 var import_block_editor11 = __toESM(require_block_editor(), 1);
1538 var import_jsx_runtime25 = __toESM(require_jsx_runtime(), 1);
1539 var name9 = "core/subscript";
1540 var title9 = (0, import_i18n12.__)("Subscript");
1541 var subscript = {
1542 name: name9,
1543 title: title9,
1544 tagName: "sub",
1545 className: null,
1546 edit({ isActive, value, onChange, onFocus }) {
1547 function onToggle() {
1548 onChange((0, import_rich_text11.toggleFormat)(value, { type: name9, title: title9 }));
1549 }
1550 function onClick() {
1551 onToggle();
1552 onFocus();
1553 }
1554 return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1555 import_block_editor11.RichTextToolbarButton,
1556 {
1557 icon: subscript_default,
1558 title: title9,
1559 onClick,
1560 isActive,
1561 role: "menuitemcheckbox"
1562 }
1563 );
1564 }
1565 };
1566
1567 // packages/format-library/build-module/superscript/index.mjs
1568 var import_i18n13 = __toESM(require_i18n(), 1);
1569 var import_rich_text12 = __toESM(require_rich_text(), 1);
1570 var import_block_editor12 = __toESM(require_block_editor(), 1);
1571 var import_jsx_runtime26 = __toESM(require_jsx_runtime(), 1);
1572 var name10 = "core/superscript";
1573 var title10 = (0, import_i18n13.__)("Superscript");
1574 var superscript = {
1575 name: name10,
1576 title: title10,
1577 tagName: "sup",
1578 className: null,
1579 edit({ isActive, value, onChange, onFocus }) {
1580 function onToggle() {
1581 onChange((0, import_rich_text12.toggleFormat)(value, { type: name10, title: title10 }));
1582 }
1583 function onClick() {
1584 onToggle();
1585 onFocus();
1586 }
1587 return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
1588 import_block_editor12.RichTextToolbarButton,
1589 {
1590 icon: superscript_default,
1591 title: title10,
1592 onClick,
1593 isActive,
1594 role: "menuitemcheckbox"
1595 }
1596 );
1597 }
1598 };
1599
1600 // packages/format-library/build-module/keyboard/index.mjs
1601 var import_i18n14 = __toESM(require_i18n(), 1);
1602 var import_rich_text13 = __toESM(require_rich_text(), 1);
1603 var import_block_editor13 = __toESM(require_block_editor(), 1);
1604 var import_jsx_runtime27 = __toESM(require_jsx_runtime(), 1);
1605 var name11 = "core/keyboard";
1606 var title11 = (0, import_i18n14.__)("Keyboard input");
1607 var keyboard = {
1608 name: name11,
1609 title: title11,
1610 tagName: "kbd",
1611 className: null,
1612 edit({ isActive, value, onChange, onFocus }) {
1613 function onToggle() {
1614 onChange((0, import_rich_text13.toggleFormat)(value, { type: name11, title: title11 }));
1615 }
1616 function onClick() {
1617 onToggle();
1618 onFocus();
1619 }
1620 return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
1621 import_block_editor13.RichTextToolbarButton,
1622 {
1623 icon: button_default,
1624 title: title11,
1625 onClick,
1626 isActive,
1627 role: "menuitemcheckbox"
1628 }
1629 );
1630 }
1631 };
1632
1633 // packages/format-library/build-module/unknown/index.mjs
1634 var import_i18n15 = __toESM(require_i18n(), 1);
1635 var import_rich_text14 = __toESM(require_rich_text(), 1);
1636 var import_block_editor14 = __toESM(require_block_editor(), 1);
1637 var import_jsx_runtime28 = __toESM(require_jsx_runtime(), 1);
1638 var name12 = "core/unknown";
1639 var title12 = (0, import_i18n15.__)("Clear Unknown Formatting");
1640 function selectionContainsUnknownFormats(value) {
1641 if ((0, import_rich_text14.isCollapsed)(value)) {
1642 return false;
1643 }
1644 const selectedValue = (0, import_rich_text14.slice)(value);
1645 return selectedValue.formats.some((formats) => {
1646 return formats.some((format) => format.type === name12);
1647 });
1648 }
1649 var unknown = {
1650 name: name12,
1651 title: title12,
1652 tagName: "*",
1653 className: null,
1654 edit({ isActive, value, onChange, onFocus }) {
1655 if (!isActive && !selectionContainsUnknownFormats(value)) {
1656 return null;
1657 }
1658 function onClick() {
1659 onChange((0, import_rich_text14.removeFormat)(value, name12));
1660 onFocus();
1661 }
1662 return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
1663 import_block_editor14.RichTextToolbarButton,
1664 {
1665 name: "unknown",
1666 icon: help_default,
1667 title: title12,
1668 onClick,
1669 isActive: true
1670 }
1671 );
1672 }
1673 };
1674
1675 // packages/format-library/build-module/language/index.mjs
1676 var import_i18n16 = __toESM(require_i18n(), 1);
1677 var import_block_editor15 = __toESM(require_block_editor(), 1);
1678 var import_components5 = __toESM(require_components(), 1);
1679 var import_element8 = __toESM(require_element(), 1);
1680 var import_rich_text15 = __toESM(require_rich_text(), 1);
1681 var import_jsx_runtime29 = __toESM(require_jsx_runtime(), 1);
1682 var name13 = "core/language";
1683 var title13 = (0, import_i18n16.__)("Language");
1684 var language = {
1685 name: name13,
1686 title: title13,
1687 tagName: "bdo",
1688 className: null,
1689 attributes: {
1690 lang: "lang",
1691 dir: "dir"
1692 },
1693 edit: Edit3
1694 };
1695 function Edit3({ isActive, value, onChange, contentRef }) {
1696 const [isPopoverVisible, setIsPopoverVisible] = (0, import_element8.useState)(false);
1697 const togglePopover = () => {
1698 setIsPopoverVisible((state) => !state);
1699 };
1700 return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(import_jsx_runtime29.Fragment, { children: [
1701 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1702 import_block_editor15.RichTextToolbarButton,
1703 {
1704 icon: language_default,
1705 label: title13,
1706 title: title13,
1707 onClick: () => {
1708 if (isActive) {
1709 onChange((0, import_rich_text15.removeFormat)(value, name13));
1710 } else {
1711 togglePopover();
1712 }
1713 },
1714 isActive,
1715 role: "menuitemcheckbox"
1716 }
1717 ),
1718 isPopoverVisible && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1719 InlineLanguageUI,
1720 {
1721 value,
1722 onChange,
1723 onClose: togglePopover,
1724 contentRef
1725 }
1726 )
1727 ] });
1728 }
1729 function InlineLanguageUI({ value, contentRef, onChange, onClose }) {
1730 const popoverAnchor = (0, import_rich_text15.useAnchor)({
1731 editableContentElement: contentRef.current,
1732 settings: language
1733 });
1734 const [lang, setLang] = (0, import_element8.useState)("");
1735 const [dir, setDir] = (0, import_element8.useState)("ltr");
1736 return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1737 import_components5.Popover,
1738 {
1739 className: "block-editor-format-toolbar__language-popover",
1740 anchor: popoverAnchor,
1741 onClose,
1742 children: /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(
1743 import_components5.__experimentalVStack,
1744 {
1745 as: "form",
1746 spacing: 4,
1747 className: "block-editor-format-toolbar__language-container-content",
1748 onSubmit: (event) => {
1749 event.preventDefault();
1750 onChange(
1751 (0, import_rich_text15.applyFormat)(value, {
1752 type: name13,
1753 attributes: {
1754 lang,
1755 dir
1756 }
1757 })
1758 );
1759 onClose();
1760 },
1761 children: [
1762 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1763 import_components5.TextControl,
1764 {
1765 __next40pxDefaultSize: true,
1766 label: title13,
1767 value: lang,
1768 onChange: (val) => setLang(val),
1769 help: (0, import_i18n16.__)(
1770 'A valid language attribute, like "en" or "fr".'
1771 )
1772 }
1773 ),
1774 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1775 import_components5.SelectControl,
1776 {
1777 __next40pxDefaultSize: true,
1778 label: (0, import_i18n16.__)("Text direction"),
1779 value: dir,
1780 options: [
1781 {
1782 label: (0, import_i18n16.__)("Left to right"),
1783 value: "ltr"
1784 },
1785 {
1786 label: (0, import_i18n16.__)("Right to left"),
1787 value: "rtl"
1788 }
1789 ],
1790 onChange: (val) => setDir(val)
1791 }
1792 ),
1793 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_components5.__experimentalHStack, { alignment: "right", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1794 import_components5.Button,
1795 {
1796 __next40pxDefaultSize: true,
1797 variant: "primary",
1798 type: "submit",
1799 text: (0, import_i18n16.__)("Apply")
1800 }
1801 ) })
1802 ]
1803 }
1804 )
1805 }
1806 );
1807 }
1808
1809 // packages/format-library/build-module/math/index.mjs
1810 var import_i18n17 = __toESM(require_i18n(), 1);
1811 var import_element9 = __toESM(require_element(), 1);
1812 var import_rich_text16 = __toESM(require_rich_text(), 1);
1813 var import_block_editor16 = __toESM(require_block_editor(), 1);
1814 var import_components6 = __toESM(require_components(), 1);
1815 var import_a11y3 = __toESM(require_a11y(), 1);
1816 var import_jsx_runtime30 = __toESM(require_jsx_runtime(), 1);
1817 var { Badge } = unlock(import_components6.privateApis);
1818 var name14 = "core/math";
1819 var title14 = (0, import_i18n17.__)("Math");
1820 function InlineUI2({
1821 value,
1822 onChange,
1823 activeAttributes,
1824 contentRef,
1825 latexToMathML
1826 }) {
1827 const [latex, setLatex] = (0, import_element9.useState)(
1828 activeAttributes?.["data-latex"] || ""
1829 );
1830 const [error, setError] = (0, import_element9.useState)(null);
1831 const popoverAnchor = (0, import_rich_text16.useAnchor)({
1832 editableContentElement: contentRef.current,
1833 settings: math
1834 });
1835 const handleLatexChange = (newLatex) => {
1836 let mathML = "";
1837 setLatex(newLatex);
1838 if (newLatex) {
1839 try {
1840 mathML = latexToMathML(newLatex, { displayMode: false });
1841 setError(null);
1842 } catch (err) {
1843 setError(err.message);
1844 (0, import_a11y3.speak)(
1845 (0, import_i18n17.sprintf)(
1846 /* translators: %s: error message returned when parsing LaTeX. */
1847 (0, import_i18n17.__)("Error parsing mathematical expression: %s"),
1848 err.message
1849 )
1850 );
1851 return;
1852 }
1853 }
1854 const newReplacements = value.replacements.slice();
1855 newReplacements[value.start] = {
1856 type: name14,
1857 attributes: {
1858 "data-latex": newLatex
1859 },
1860 innerHTML: mathML
1861 };
1862 onChange({
1863 ...value,
1864 replacements: newReplacements
1865 });
1866 };
1867 return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
1868 import_components6.Popover,
1869 {
1870 placement: "bottom-start",
1871 offset: 8,
1872 focusOnMount: false,
1873 anchor: popoverAnchor,
1874 className: "block-editor-format-toolbar__math-popover",
1875 children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { style: { minWidth: "300px", padding: "4px" }, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_components6.__experimentalVStack, { spacing: 1, children: [
1876 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
1877 import_components6.TextControl,
1878 {
1879 __next40pxDefaultSize: true,
1880 hideLabelFromVision: true,
1881 label: (0, import_i18n17.__)("LaTeX math syntax"),
1882 value: latex,
1883 onChange: handleLatexChange,
1884 placeholder: (0, import_i18n17.__)("e.g., x^2, \\frac{a}{b}"),
1885 autoComplete: "off",
1886 className: "block-editor-format-toolbar__math-input"
1887 }
1888 ),
1889 error && /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [
1890 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
1891 Badge,
1892 {
1893 intent: "error",
1894 className: "wp-block-math__error",
1895 children: (0, import_i18n17.sprintf)(
1896 /* translators: %s: error message returned when parsing LaTeX. */
1897 (0, import_i18n17.__)("Error: %s"),
1898 error
1899 )
1900 }
1901 ),
1902 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("style", { children: ".wp-block-math__error .components-badge__content{white-space:normal}" })
1903 ] })
1904 ] }) })
1905 }
1906 );
1907 }
1908 function Edit4({
1909 value,
1910 onChange,
1911 onFocus,
1912 isObjectActive,
1913 activeObjectAttributes,
1914 contentRef
1915 }) {
1916 const [latexToMathML, setLatexToMathML] = (0, import_element9.useState)();
1917 (0, import_element9.useEffect)(() => {
1918 import("@wordpress/latex-to-mathml").then((module) => {
1919 setLatexToMathML(() => module.default);
1920 });
1921 }, []);
1922 return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [
1923 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
1924 import_block_editor16.RichTextToolbarButton,
1925 {
1926 icon: math_default,
1927 title: title14,
1928 onClick: () => {
1929 const newValue = (0, import_rich_text16.insertObject)(value, {
1930 type: name14,
1931 attributes: {
1932 "data-latex": ""
1933 },
1934 innerHTML: ""
1935 });
1936 newValue.start = newValue.end - 1;
1937 onChange(newValue);
1938 onFocus();
1939 },
1940 isActive: isObjectActive
1941 }
1942 ),
1943 isObjectActive && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
1944 InlineUI2,
1945 {
1946 value,
1947 onChange,
1948 activeAttributes: activeObjectAttributes,
1949 contentRef,
1950 latexToMathML
1951 }
1952 )
1953 ] });
1954 }
1955 var math = {
1956 name: name14,
1957 title: title14,
1958 tagName: "math",
1959 className: null,
1960 attributes: {
1961 "data-latex": "data-latex"
1962 },
1963 contentEditable: false,
1964 edit: Edit4
1965 };
1966
1967 // packages/format-library/build-module/non-breaking-space/index.mjs
1968 var import_i18n18 = __toESM(require_i18n(), 1);
1969 var import_rich_text17 = __toESM(require_rich_text(), 1);
1970 var import_block_editor17 = __toESM(require_block_editor(), 1);
1971 var import_jsx_runtime31 = __toESM(require_jsx_runtime(), 1);
1972 var name15 = "core/non-breaking-space";
1973 var title15 = (0, import_i18n18.__)("Non breaking space");
1974 var nonBreakingSpace = {
1975 name: name15,
1976 title: title15,
1977 tagName: "nbsp",
1978 className: null,
1979 edit({ value, onChange }) {
1980 function addNonBreakingSpace() {
1981 onChange((0, import_rich_text17.insert)(value, "\xA0"));
1982 }
1983 return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
1984 import_block_editor17.RichTextShortcut,
1985 {
1986 type: "primaryShift",
1987 character: " ",
1988 onUse: addNonBreakingSpace
1989 }
1990 );
1991 }
1992 };
1993
1994 // packages/format-library/build-module/default-formats.mjs
1995 var default_formats_default = [
1996 bold,
1997 code,
1998 image,
1999 italic,
2000 link,
2001 strikethrough,
2002 underline,
2003 textColor,
2004 subscript,
2005 superscript,
2006 keyboard,
2007 unknown,
2008 language,
2009 math,
2010 nonBreakingSpace
2011 ];
2012
2013 // packages/format-library/build-module/index.mjs
2014 default_formats_default.forEach(
2015 ({ name: name16, ...settings }) => (0, import_rich_text18.registerFormatType)(name16, settings)
2016 );
2017})();
2018