Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.173/page_editor/app/components/CommonStylesManager",["module","exports","require","liferay!frontend-js-react-web$react","../config/constants/containerWidthTypes","../config/constants/layoutDataItemTypes","../config/constants/viewportSizes","../config/index","../contexts/GlobalContext","../contexts/StoreContext","../utils/checkDeepEqual","../utils/generateStyleSheet","../utils/getResponsiveConfig","../utils/hasInnerCustomStyles"],(function(e,t,s){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function CommonStylesManager(){const e=(0,n.useRef)({}),t=(0,n.useRef)({}),s=(0,c.useSelector)((e=>e.layoutData)),o=(0,c.useSelector)((e=>{var t;return null===(t=e.masterLayout)||void 0===t?void 0:t.masterLayoutData})),i=(0,c.useSelector)((e=>e.selectedViewportSize)),l=(0,c.useSelectorRef)((e=>e.fragmentEntryLinks)),r=(0,a.useGlobalContext)();return(0,n.useEffect)((()=>{const{styleSheet:t,styles:n}=e.current[i]||{},{styleSheet:o,styles:a}=calculateStyles({fragmentEntryLinks:l.current,isMaster:!0,items:Object.values(s.items),previousStyleSheet:t,previousStyles:n,selectedViewportSize:i});e.current[i]={styleSheet:o,styles:a},createOrUpdateStyleTag({globalContext:r,id:"layout-common-styles",styleSheet:o})}),[s.items,i,r,l]),(0,n.useEffect)((()=>{if(!o)return;const{styleSheet:e,styles:s}=t.current[i]||{},{styleSheet:n,styles:a}=calculateStyles({fragmentEntryLinks:l.current,isMaster:!1,items:Object.values(o.items),previousStyleSheet:e,previousStyles:s,selectedViewportSize:i});t.current[i]={styleSheet:n,styles:a},createOrUpdateStyleTag({globalContext:r,id:"layout-master-common-styles",styleSheet:n})}),[o,i,r,l]),null};var n=s("liferay!frontend-js-react-web$react"),o=s("../config/constants/containerWidthTypes"),i=s("../config/constants/layoutDataItemTypes"),l=s("../config/constants/viewportSizes"),r=s("../config/index"),a=s("../contexts/GlobalContext"),c=s("../contexts/StoreContext"),u=s("../utils/checkDeepEqual"),y=_interopRequireDefault(s("../utils/generateStyleSheet")),S=s("../utils/getResponsiveConfig"),f=_interopRequireDefault(s("../utils/hasInnerCustomStyles"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const e=[i.LAYOUT_DATA_ITEM_TYPES.collection,i.LAYOUT_DATA_ITEM_TYPES.container,i.LAYOUT_DATA_ITEM_TYPES.form,i.LAYOUT_DATA_ITEM_TYPES.row,i.LAYOUT_DATA_ITEM_TYPES.fragment];function createOrUpdateStyleTag({globalContext:e,id:t,styleSheet:s}){let n=e.document.getElementById(t);return n||(n=e.document.createElement("style"),n.id=t,n.type="text/css",n.dataset.sennaTrack="temporary",e.document.head.appendChild(n)),n.innerHTML=s,n}function calculateStyles({fragmentEntryLinks:t,isMaster:s,items:n,previousStyleSheet:a,previousStyles:c,selectedViewportSize:d}){const m=new Set,p={};if(n.forEach((n=>{if(function hasCommonStyles(t){return e.includes(t.type)}(n)){var a,c;const e=null===(a=(0,S.getResponsiveConfig)(n.config,d))||void 0===a?void 0:a.customCSS,u=null===(c=(0,S.getResponsiveConfig)(n.config,d))||void 0===c?void 0:c.styles,y=function filterStyles({item:e,selectedViewportSize:t,styles:s}){const n={};return Object.entries(s).forEach((([s,i])=>{var a;const{defaultValue:c}=r.config.commonStylesFields[s],u=(null===(a=e.config)||void 0===a?void 0:a.widthType)===o.CONTAINER_WIDTH_TYPES.fixed;!i||c===i&&t===l.VIEWPORT_SIZES.desktop||u&&("marginRight"===s||"marginLeft"===s)||(n[s]=i)})),n}({item:n,selectedViewportSize:d,styles:u});if(p[n.itemId]={customCSS:e,styles:y},!s)return;const g=t[n.config.fragmentEntryLinkId];n.type===i.LAYOUT_DATA_ITEM_TYPES.fragment&&(0,f.default)(g)||m.add(n.itemId)}})),!c||!a||!(0,u.deepEqual)(c,p)){return{styleSheet:(0,y.default)(p,{itemsWithTopper:m}),styles:p}}return{styleSheet:a,styles:p}}}}));
//# sourceMappingURL=CommonStylesManager.js.map