first commit
This commit is contained in:
102
wp-includes/js/dist/script-modules/block-editor/utils/fit-text-frontend.js
vendored
Normal file
102
wp-includes/js/dist/script-modules/block-editor/utils/fit-text-frontend.js
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
import * as __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__ from "@wordpress/interactivity";
|
||||
/******/ // The require scope
|
||||
/******/ var __webpack_require__ = {};
|
||||
/******/
|
||||
/************************************************************************/
|
||||
/******/ /* webpack/runtime/define property getters */
|
||||
/******/ (() => {
|
||||
/******/ // define getter functions for harmony exports
|
||||
/******/ __webpack_require__.d = (exports, definition) => {
|
||||
/******/ for(var key in definition) {
|
||||
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
||||
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
||||
/******/ }
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/ })();
|
||||
/******/
|
||||
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
||||
/******/ (() => {
|
||||
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
||||
/******/ })();
|
||||
/******/
|
||||
/************************************************************************/
|
||||
var __webpack_exports__ = {};
|
||||
|
||||
;// external "@wordpress/interactivity"
|
||||
var x = (y) => {
|
||||
var x = {}; __webpack_require__.d(x, y); return x
|
||||
}
|
||||
var y = (x) => (() => (x))
|
||||
const interactivity_namespaceObject = x({ ["getContext"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getContext), ["getElement"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getElement), ["store"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.store) });
|
||||
;// ./node_modules/@wordpress/block-editor/build-module/utils/fit-text-utils.js
|
||||
function findOptimalFontSize(textElement, applyFontSize) {
|
||||
const alreadyHasScrollableHeight = textElement.scrollHeight > textElement.clientHeight;
|
||||
let minSize = 5;
|
||||
let maxSize = 2400;
|
||||
let bestSize = minSize;
|
||||
const computedStyle = window.getComputedStyle(textElement);
|
||||
const paddingLeft = parseFloat(computedStyle.paddingLeft) || 0;
|
||||
const paddingRight = parseFloat(computedStyle.paddingRight) || 0;
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(textElement);
|
||||
while (minSize <= maxSize) {
|
||||
const midSize = Math.floor((minSize + maxSize) / 2);
|
||||
applyFontSize(midSize);
|
||||
const rect = range.getBoundingClientRect();
|
||||
const textWidth = rect.width;
|
||||
const fitsWidth = textElement.scrollWidth <= textElement.clientWidth && textWidth <= textElement.clientWidth - paddingLeft - paddingRight;
|
||||
const fitsHeight = alreadyHasScrollableHeight || textElement.scrollHeight <= textElement.clientHeight;
|
||||
if (fitsWidth && fitsHeight) {
|
||||
bestSize = midSize;
|
||||
minSize = midSize + 1;
|
||||
} else {
|
||||
maxSize = midSize - 1;
|
||||
}
|
||||
}
|
||||
range.detach();
|
||||
return bestSize;
|
||||
}
|
||||
function optimizeFitText(textElement, applyFontSize) {
|
||||
if (!textElement) {
|
||||
return;
|
||||
}
|
||||
applyFontSize(0);
|
||||
const optimalSize = findOptimalFontSize(textElement, applyFontSize);
|
||||
applyFontSize(optimalSize);
|
||||
return optimalSize;
|
||||
}
|
||||
|
||||
|
||||
;// ./node_modules/@wordpress/block-editor/build-module/utils/fit-text-frontend.js
|
||||
|
||||
|
||||
(0,interactivity_namespaceObject.store)("core/fit-text", {
|
||||
callbacks: {
|
||||
init() {
|
||||
const context = (0,interactivity_namespaceObject.getContext)();
|
||||
const { ref } = (0,interactivity_namespaceObject.getElement)();
|
||||
const applyFontSize = (fontSize) => {
|
||||
if (fontSize === 0) {
|
||||
ref.style.fontSize = "";
|
||||
} else {
|
||||
ref.style.fontSize = `${fontSize}px`;
|
||||
}
|
||||
};
|
||||
context.fontSize = optimizeFitText(ref, applyFontSize);
|
||||
if (window.ResizeObserver && ref.parentElement) {
|
||||
const resizeObserver = new window.ResizeObserver(() => {
|
||||
context.fontSize = optimizeFitText(ref, applyFontSize);
|
||||
});
|
||||
resizeObserver.observe(ref.parentElement);
|
||||
resizeObserver.observe(ref);
|
||||
return () => {
|
||||
if (resizeObserver) {
|
||||
resizeObserver.disconnect();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
1
wp-includes/js/dist/script-modules/block-editor/utils/fit-text-frontend.min.js
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-editor/utils/fit-text-frontend.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import*as e from"@wordpress/interactivity";var t={d:(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const n=(e=>{var n={};return t.d(n,e),n})({getContext:()=>e.getContext,getElement:()=>e.getElement,store:()=>e.store});function o(e,t){if(!e)return;t(0);const n=function(e,t){const n=e.scrollHeight>e.clientHeight;let o=5,r=2400,i=o;const c=window.getComputedStyle(e),s=parseFloat(c.paddingLeft)||0,l=parseFloat(c.paddingRight)||0,a=document.createRange();for(a.selectNodeContents(e);o<=r;){const c=Math.floor((o+r)/2);t(c);const d=a.getBoundingClientRect().width,g=e.scrollWidth<=e.clientWidth&&d<=e.clientWidth-s-l,f=n||e.scrollHeight<=e.clientHeight;g&&f?(i=c,o=c+1):r=c-1}return a.detach(),i}(e,t);return t(n),n}(0,n.store)("core/fit-text",{callbacks:{init(){const e=(0,n.getContext)(),{ref:t}=(0,n.getElement)(),r=e=>{t.style.fontSize=0===e?"":`${e}px`};if(e.fontSize=o(t,r),window.ResizeObserver&&t.parentElement){const n=new window.ResizeObserver((()=>{e.fontSize=o(t,r)}));return n.observe(t.parentElement),n.observe(t),()=>{n&&n.disconnect()}}}}});
|
||||
Reference in New Issue
Block a user