@edynamix/mf-isolation 0.0.29 → 0.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,7 +37,13 @@ export default {
37
37
  };
38
38
  ```
39
39
 
40
- The host and remote must use the same `scopeId`. Both PostCSS plugins keep ordinary global and vendor selectors under the zero-specificity `:where([data-edyn-mf="<scope-id>"])` boundary. Document-root descendants such as `html body#app button` instead use `[data-edyn-mf="<scope-id>"]` so module overrides retain sufficient cascade strength. When that root carries an id, as `body#app` does, the boundary becomes `:is([data-edyn-mf="<scope-id>"], edyn-mf-root edyn-mf-root#edyn-mf-root:not(*))`: the second argument never matches, but it gives the override the same id and type weight it had on the standalone page, so it still beats Angular Material's own rules.
40
+ The host and remote must use the same `scopeId`. Both PostCSS plugins keep ordinary global and vendor selectors under the zero-specificity `:where([data-edyn-mf="<scope-id>"])` boundary. Document-root descendants such as `html body#app button` or `html body button` keep the weight of the root they start from: it becomes `:where([data-edyn-mf="<scope-id>"]):not(<carrier>)`, where `:where()` weighs nothing and the carrier (for example `edyn-mf-root edyn-mf-root#edyn-mf-root` for `html body#app`) has the same id, class and type counts as the replaced root and never matches the scope element. Module overrides therefore win or lose against Angular Material exactly as on the standalone page.
41
+
42
+ ### Root font size and rem
43
+
44
+ `rem` always resolves against the page's `<html>`, even inside a shadow root. A module page that sized its own root (`html, body { font-size: 12px }`) drew every rem length from that size; hosted, the same lengths would use the host page's root. Both PostCSS plugins therefore record a resolvable `font-size` or `font` size on `html` or `:root` (px, %, em, rem, absolute units and size keywords, against the initial 16px) as `--edyn-mf-rem` on the module boundary, in a rule right after the one that sets it, so `@media` conditions and `!important` carry over. Sizing only `body` (or `html body`) leaves rem alone, as it did on the module's own page. A size that cannot be resolved at build time (`var()`, `calc()` with `var()`, viewport units, system fonts) is reported as a PostCSS warning; rem then keeps the host root size. CSS that never sizes the root is emitted exactly as before.
45
+
46
+ At runtime, `provideMfOverlayRoot()` and `provideMfOverlayRootFromToken()` start `followModuleRootFontSize(shadowRoot)` for the shadow root the overlay root sits in, from an environment initializer (before the first component renders) until the injector is destroyed. Once a stylesheet in that root declares `--edyn-mf-rem`, every rem length in its stylesheets, including the component styles Angular adds later, becomes `calc(<n> * var(--edyn-mf-rem, 1rem))` through the CSSOM: `@media`, `@container` and `@supports` conditions, strings and `url()` keep their text, and the rewrite is idempotent. A module that mounts without those providers can call `followModuleRootFontSize(shadowRoot)` from `@edynamix/mf-isolation` itself and call the function it returns on unmount. Inline `style` attributes and rules added later with `insertRule()` into an already rewritten sheet are not rewritten.
41
47
 
42
48
  ### Angular with Vite
43
49
 
package/dist/angular.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ProviderToken, StaticProvider } from '@angular/core';
1
+ import { type ProviderToken, type StaticProvider } from '@angular/core';
2
2
  export declare const provideMfOverlayRoot: (overlayRoot?: HTMLElement) => StaticProvider[];
3
3
  export declare const provideMfOverlayRootFromToken: (overlayRootToken: ProviderToken<HTMLElement>) => StaticProvider[];
4
4
  export { CaseInsensitiveBasePathLocationStrategy, provideCaseInsensitiveBasePath } from './angular-location.js';
@@ -1 +1 @@
1
- {"version":3,"file":"angular.d.ts","sourceRoot":"","sources":["../src/angular.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AA2SnE,eAAO,MAAM,oBAAoB,GAAI,cAAc,WAAW,KAAG,cAAc,EAkB9E,CAAC;AAEF,eAAO,MAAM,6BAA6B,GAAI,kBAAkB,aAAa,CAAC,WAAW,CAAC,KAAG,cAAc,EAE1G,CAAC;AAEF,OAAO,EAAE,uCAAuC,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["import {\n FlexibleConnectedPositionStrategy,\n type FlexibleConnectedPositionStrategyOrigin,\n GlobalPositionStrategy,\n OverlayContainer,\n OverlayPositionBuilder,\n} from '@angular/cdk/overlay';\nimport { Platform } from '@angular/cdk/platform';\nimport { ViewportRuler } from '@angular/cdk/scrolling';\nimport { DOCUMENT } from '@angular/common';\nimport type { ProviderToken, StaticProvider } from '@angular/core';\n\n// Mirrors the CDK 19 overlay-prebuilt.css structural rules while intentionally excluding document-level scroll blocking.\nconst CDK_OVERLAY_STRUCTURAL_CSS = `\n.cdk-overlay-container,.cdk-global-overlay-wrapper{pointer-events:none;top:0;left:0;height:100%;width:100%}\n.cdk-overlay-container{position:fixed;z-index:1000}\n.cdk-overlay-container:empty{display:none}\n.cdk-global-overlay-wrapper{display:flex;position:absolute;z-index:1000}\n.cdk-overlay-pane{position:absolute;pointer-events:auto;box-sizing:border-box;display:flex;max-width:100%;max-height:100%;z-index:1000}\n.cdk-overlay-backdrop{position:absolute;top:0;bottom:0;left:0;right:0;pointer-events:auto;-webkit-tap-highlight-color:rgba(0,0,0,0);opacity:0;touch-action:manipulation;z-index:1000;transition:opacity 400ms cubic-bezier(0.25,0.8,0.25,1)}\n@media(prefers-reduced-motion){.cdk-overlay-backdrop{transition-duration:1ms}}\n.cdk-overlay-backdrop-showing{opacity:1}\n@media(forced-colors:active){.cdk-overlay-backdrop-showing{opacity:.6}}\n.cdk-overlay-dark-backdrop{background:rgba(0,0,0,.32)}\n.cdk-overlay-transparent-backdrop{transition:visibility 1ms linear,opacity 1ms linear;visibility:hidden;opacity:1}\n.cdk-overlay-transparent-backdrop.cdk-overlay-backdrop-showing,.cdk-high-contrast-active .cdk-overlay-transparent-backdrop{opacity:0;visibility:visible}\n.cdk-overlay-backdrop-noop-animation{transition:none}\n.cdk-overlay-connected-position-bounding-box{position:absolute;display:flex;flex-direction:column;min-width:1px;min-height:1px;z-index:1000}\n`;\n\ninterface IClientRect {\n bottom: number;\n height: number;\n left: number;\n right: number;\n top: number;\n width: number;\n x?: number;\n y?: number;\n}\n\ninterface IFlexibleConnectedPositionStrategyInternals {\n _getOriginPoint: (originRect: IClientRect, containerRect: IClientRect, position: unknown) => { x: number; y: number };\n _getOriginRect: () => IClientRect;\n}\n\nconst translateRectToBoundary = (rect: IClientRect, boundary: IClientRect): IClientRect => {\n const left = rect.left - boundary.left;\n const top = rect.top - boundary.top;\n\n return {\n bottom: top + rect.height,\n height: rect.height,\n left,\n right: left + rect.width,\n top,\n width: rect.width,\n x: left,\n y: top,\n };\n};\n\nconst getBoundaryRect = (overlayRoot: HTMLElement): IClientRect => {\n const { height, width } = overlayRoot.getBoundingClientRect();\n return {\n bottom: height,\n height,\n left: 0,\n right: width,\n top: 0,\n width,\n x: 0,\n y: 0,\n };\n};\n\nconst createBoundaryDocument = (document: Document, overlayRoot: HTMLElement): Document => {\n const boundaryDocumentElement = new Proxy(document.documentElement, {\n get: (target, property, receiver) => {\n if (property === 'clientHeight') {\n return overlayRoot.getBoundingClientRect().height;\n }\n if (property === 'clientWidth') {\n return overlayRoot.getBoundingClientRect().width;\n }\n return Reflect.get(target, property, receiver);\n },\n });\n\n return new Proxy(document, {\n get: (target, property, receiver) => {\n if (property === 'documentElement') {\n return boundaryDocumentElement;\n }\n return Reflect.get(target, property, receiver);\n },\n });\n};\n\nconst createBoundaryViewportRuler = (viewportRuler: ViewportRuler, overlayRoot: HTMLElement): ViewportRuler => {\n const boundaryViewportRuler = Object.create(viewportRuler) as ViewportRuler;\n boundaryViewportRuler.getViewportRect = () => getBoundaryRect(overlayRoot);\n boundaryViewportRuler.getViewportScrollPosition = () => ({ left: 0, top: 0 });\n boundaryViewportRuler.getViewportSize = () => {\n const { height, width } = getBoundaryRect(overlayRoot);\n return { height, width };\n };\n return boundaryViewportRuler;\n};\n\nconst adaptConnectedPositionStrategy = (\n strategy: FlexibleConnectedPositionStrategy,\n overlayRoot: HTMLElement,\n observeBoundary: (callback: () => void) => () => void,\n): FlexibleConnectedPositionStrategy => {\n const internals = strategy as unknown as IFlexibleConnectedPositionStrategyInternals;\n const getOriginRect = internals._getOriginRect.bind(strategy);\n const getOriginPoint = internals._getOriginPoint.bind(strategy);\n const attach = strategy.attach.bind(strategy);\n const detach = strategy.detach.bind(strategy);\n const dispose = strategy.dispose.bind(strategy);\n let stopObserving = () => {};\n internals._getOriginRect = () => {\n return translateRectToBoundary(getOriginRect(), overlayRoot.getBoundingClientRect());\n };\n internals._getOriginPoint = (originRect, _containerRect, position) => {\n return getOriginPoint(originRect, getBoundaryRect(overlayRoot), position);\n };\n strategy.attach = (overlayRef) => {\n attach(overlayRef);\n stopObserving();\n stopObserving = observeBoundary(() => strategy.apply());\n };\n strategy.detach = () => {\n stopObserving();\n stopObserving = () => {};\n detach();\n };\n strategy.dispose = () => {\n stopObserving();\n stopObserving = () => {};\n dispose();\n };\n\n return strategy;\n};\n\nclass MfOverlayPositionBuilder extends OverlayPositionBuilder {\n readonly #document: Document;\n readonly #overlayContainer: OverlayContainer;\n readonly #overlayRoot: HTMLElement;\n readonly #platform: Platform;\n readonly #viewportRuler: ViewportRuler;\n\n constructor(viewportRuler: ViewportRuler, document: Document, platform: Platform, overlayContainer: OverlayContainer, overlayRoot: HTMLElement) {\n super();\n this.#viewportRuler = viewportRuler;\n this.#document = document;\n this.#platform = platform;\n this.#overlayContainer = overlayContainer;\n this.#overlayRoot = overlayRoot;\n }\n\n override global(): GlobalPositionStrategy {\n return new GlobalPositionStrategy();\n }\n\n override flexibleConnectedTo(origin: FlexibleConnectedPositionStrategyOrigin): FlexibleConnectedPositionStrategy {\n const boundaryDocument = createBoundaryDocument(this.#document, this.#overlayRoot);\n const boundaryViewportRuler = createBoundaryViewportRuler(this.#viewportRuler, this.#overlayRoot);\n const strategy = new FlexibleConnectedPositionStrategy(origin, boundaryViewportRuler, boundaryDocument, this.#platform, this.#overlayContainer);\n\n const overlayContainer = this.#overlayContainer as MfOverlayContainer;\n return adaptConnectedPositionStrategy(strategy, this.#overlayRoot, (callback) => overlayContainer.observeBoundary(callback));\n }\n}\n\nclass MfOverlayContainer extends OverlayContainer {\n readonly #boundaryObservers = new Set<() => void>();\n readonly #overlayRoot: HTMLElement;\n #animationFrame: number | null = null;\n #boundaryRect: IClientRect | null = null;\n #restoreRootPosition: (() => void) | null = null;\n #shadowStyle: HTMLStyleElement | null = null;\n\n constructor(overlayRoot: HTMLElement) {\n super();\n this.#overlayRoot = overlayRoot;\n }\n\n override ngOnDestroy(): void {\n if (this.#animationFrame !== null) {\n this.#overlayRoot.ownerDocument.defaultView?.cancelAnimationFrame(this.#animationFrame);\n }\n this.#animationFrame = null;\n this.#boundaryObservers.clear();\n super.ngOnDestroy();\n this.#shadowStyle?.remove();\n this.#shadowStyle = null;\n this.#restoreRootPosition?.();\n this.#restoreRootPosition = null;\n }\n\n observeBoundary(callback: () => void): () => void {\n this.#boundaryObservers.add(callback);\n if (this.#boundaryObservers.size === 1) {\n this.#boundaryRect = this.#overlayRoot.getBoundingClientRect();\n this.#scheduleBoundaryCheck();\n }\n\n return () => {\n this.#boundaryObservers.delete(callback);\n if (this.#boundaryObservers.size === 0 && this.#animationFrame !== null) {\n this.#overlayRoot.ownerDocument.defaultView?.cancelAnimationFrame(this.#animationFrame);\n this.#animationFrame = null;\n this.#boundaryRect = null;\n }\n };\n }\n\n protected override _createContainer(): void {\n if (this.#overlayRoot.ownerDocument.defaultView?.getComputedStyle(this.#overlayRoot).position === 'static') {\n const previousPosition = this.#overlayRoot.style.position;\n this.#overlayRoot.style.position = 'relative';\n this.#restoreRootPosition = () => {\n this.#overlayRoot.style.position = previousPosition;\n };\n }\n\n const rootNode = this.#overlayRoot.getRootNode();\n const ShadowRootConstructor = this.#overlayRoot.ownerDocument.defaultView?.ShadowRoot;\n if (ShadowRootConstructor && rootNode instanceof ShadowRootConstructor) {\n const style = this._document.createElement('style');\n style.setAttribute('data-edyn-mf-cdk-overlay-styles', '');\n style.textContent = CDK_OVERLAY_STRUCTURAL_CSS;\n rootNode.appendChild(style);\n this.#shadowStyle = style;\n }\n\n const container = this._document.createElement('div');\n container.classList.add('cdk-overlay-container');\n container.style.inset = '0';\n container.style.position = 'absolute';\n this.#overlayRoot.appendChild(container);\n this._containerElement = container;\n }\n\n #scheduleBoundaryCheck(): void {\n const window = this.#overlayRoot.ownerDocument.defaultView;\n if (!window || this.#animationFrame !== null || this.#boundaryObservers.size === 0) {\n return;\n }\n\n this.#animationFrame = window.requestAnimationFrame(() => {\n this.#animationFrame = null;\n const previous = this.#boundaryRect;\n const current = this.#overlayRoot.getBoundingClientRect();\n this.#boundaryRect = current;\n\n if (\n previous &&\n (previous.height !== current.height || previous.left !== current.left || previous.top !== current.top || previous.width !== current.width)\n ) {\n for (const observer of this.#boundaryObservers) {\n observer();\n }\n }\n\n this.#scheduleBoundaryCheck();\n });\n }\n}\n\nconst isDocumentViewportRoot = (overlayRoot: HTMLElement): boolean => {\n return overlayRoot === overlayRoot.ownerDocument.body || overlayRoot === overlayRoot.ownerDocument.documentElement;\n};\n\nconst createOverlayContainer = (overlayRoot: HTMLElement): OverlayContainer => {\n return isDocumentViewportRoot(overlayRoot) ? new OverlayContainer() : new MfOverlayContainer(overlayRoot);\n};\n\nconst createOverlayPositionBuilder = (\n viewportRuler: ViewportRuler,\n document: Document,\n platform: Platform,\n overlayContainer: OverlayContainer,\n overlayRoot: HTMLElement,\n): OverlayPositionBuilder => {\n if (isDocumentViewportRoot(overlayRoot)) {\n return new OverlayPositionBuilder();\n }\n return new MfOverlayPositionBuilder(viewportRuler, document, platform, overlayContainer, overlayRoot);\n};\n\nconst createTokenProviders = (overlayRootToken: ProviderToken<HTMLElement>): StaticProvider[] => {\n return [\n {\n provide: OverlayContainer,\n useFactory: createOverlayContainer,\n deps: [overlayRootToken],\n },\n {\n provide: OverlayPositionBuilder,\n useFactory: createOverlayPositionBuilder,\n deps: [ViewportRuler, DOCUMENT, Platform, OverlayContainer, overlayRootToken],\n },\n ];\n};\n\nexport const provideMfOverlayRoot = (overlayRoot?: HTMLElement): StaticProvider[] => {\n if (!overlayRoot) {\n return [];\n }\n\n return [\n {\n provide: OverlayContainer,\n useFactory: () => createOverlayContainer(overlayRoot),\n },\n {\n provide: OverlayPositionBuilder,\n useFactory: (viewportRuler: ViewportRuler, document: Document, platform: Platform, overlayContainer: OverlayContainer) => {\n return createOverlayPositionBuilder(viewportRuler, document, platform, overlayContainer, overlayRoot);\n },\n deps: [ViewportRuler, DOCUMENT, Platform, OverlayContainer],\n },\n ];\n};\n\nexport const provideMfOverlayRootFromToken = (overlayRootToken: ProviderToken<HTMLElement>): StaticProvider[] => {\n return createTokenProviders(overlayRootToken);\n};\n\nexport { CaseInsensitiveBasePathLocationStrategy, provideCaseInsensitiveBasePath } from './angular-location.js';\n"]}
1
+ {"version":3,"file":"angular.d.ts","sourceRoot":"","sources":["../src/angular.ts"],"names":[],"mappings":"AAUA,OAAO,EAAuC,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AA6T7G,eAAO,MAAM,oBAAoB,GAAI,cAAc,WAAW,KAAG,cAAc,EAwB9E,CAAC;AAEF,eAAO,MAAM,6BAA6B,GAAI,kBAAkB,aAAa,CAAC,WAAW,CAAC,KAAG,cAAc,EAE1G,CAAC;AAEF,OAAO,EAAE,uCAAuC,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["import {\n FlexibleConnectedPositionStrategy,\n type FlexibleConnectedPositionStrategyOrigin,\n GlobalPositionStrategy,\n OverlayContainer,\n OverlayPositionBuilder,\n} from '@angular/cdk/overlay';\nimport { Platform } from '@angular/cdk/platform';\nimport { ViewportRuler } from '@angular/cdk/scrolling';\nimport { DOCUMENT } from '@angular/common';\nimport { DestroyRef, ENVIRONMENT_INITIALIZER, type ProviderToken, type StaticProvider } from '@angular/core';\nimport { followModuleRootFontSize } from './root-font-size.js';\n\n// Mirrors the CDK 19 overlay-prebuilt.css structural rules while intentionally excluding document-level scroll blocking.\nconst CDK_OVERLAY_STRUCTURAL_CSS = `\n.cdk-overlay-container,.cdk-global-overlay-wrapper{pointer-events:none;top:0;left:0;height:100%;width:100%}\n.cdk-overlay-container{position:fixed;z-index:1000}\n.cdk-overlay-container:empty{display:none}\n.cdk-global-overlay-wrapper{display:flex;position:absolute;z-index:1000}\n.cdk-overlay-pane{position:absolute;pointer-events:auto;box-sizing:border-box;display:flex;max-width:100%;max-height:100%;z-index:1000}\n.cdk-overlay-backdrop{position:absolute;top:0;bottom:0;left:0;right:0;pointer-events:auto;-webkit-tap-highlight-color:rgba(0,0,0,0);opacity:0;touch-action:manipulation;z-index:1000;transition:opacity 400ms cubic-bezier(0.25,0.8,0.25,1)}\n@media(prefers-reduced-motion){.cdk-overlay-backdrop{transition-duration:1ms}}\n.cdk-overlay-backdrop-showing{opacity:1}\n@media(forced-colors:active){.cdk-overlay-backdrop-showing{opacity:.6}}\n.cdk-overlay-dark-backdrop{background:rgba(0,0,0,.32)}\n.cdk-overlay-transparent-backdrop{transition:visibility 1ms linear,opacity 1ms linear;visibility:hidden;opacity:1}\n.cdk-overlay-transparent-backdrop.cdk-overlay-backdrop-showing,.cdk-high-contrast-active .cdk-overlay-transparent-backdrop{opacity:0;visibility:visible}\n.cdk-overlay-backdrop-noop-animation{transition:none}\n.cdk-overlay-connected-position-bounding-box{position:absolute;display:flex;flex-direction:column;min-width:1px;min-height:1px;z-index:1000}\n`;\n\ninterface IClientRect {\n bottom: number;\n height: number;\n left: number;\n right: number;\n top: number;\n width: number;\n x?: number;\n y?: number;\n}\n\ninterface IFlexibleConnectedPositionStrategyInternals {\n _getOriginPoint: (originRect: IClientRect, containerRect: IClientRect, position: unknown) => { x: number; y: number };\n _getOriginRect: () => IClientRect;\n}\n\nconst translateRectToBoundary = (rect: IClientRect, boundary: IClientRect): IClientRect => {\n const left = rect.left - boundary.left;\n const top = rect.top - boundary.top;\n\n return {\n bottom: top + rect.height,\n height: rect.height,\n left,\n right: left + rect.width,\n top,\n width: rect.width,\n x: left,\n y: top,\n };\n};\n\nconst getBoundaryRect = (overlayRoot: HTMLElement): IClientRect => {\n const { height, width } = overlayRoot.getBoundingClientRect();\n return {\n bottom: height,\n height,\n left: 0,\n right: width,\n top: 0,\n width,\n x: 0,\n y: 0,\n };\n};\n\nconst createBoundaryDocument = (document: Document, overlayRoot: HTMLElement): Document => {\n const boundaryDocumentElement = new Proxy(document.documentElement, {\n get: (target, property, receiver) => {\n if (property === 'clientHeight') {\n return overlayRoot.getBoundingClientRect().height;\n }\n if (property === 'clientWidth') {\n return overlayRoot.getBoundingClientRect().width;\n }\n return Reflect.get(target, property, receiver);\n },\n });\n\n return new Proxy(document, {\n get: (target, property, receiver) => {\n if (property === 'documentElement') {\n return boundaryDocumentElement;\n }\n return Reflect.get(target, property, receiver);\n },\n });\n};\n\nconst createBoundaryViewportRuler = (viewportRuler: ViewportRuler, overlayRoot: HTMLElement): ViewportRuler => {\n const boundaryViewportRuler = Object.create(viewportRuler) as ViewportRuler;\n boundaryViewportRuler.getViewportRect = () => getBoundaryRect(overlayRoot);\n boundaryViewportRuler.getViewportScrollPosition = () => ({ left: 0, top: 0 });\n boundaryViewportRuler.getViewportSize = () => {\n const { height, width } = getBoundaryRect(overlayRoot);\n return { height, width };\n };\n return boundaryViewportRuler;\n};\n\nconst adaptConnectedPositionStrategy = (\n strategy: FlexibleConnectedPositionStrategy,\n overlayRoot: HTMLElement,\n observeBoundary: (callback: () => void) => () => void,\n): FlexibleConnectedPositionStrategy => {\n const internals = strategy as unknown as IFlexibleConnectedPositionStrategyInternals;\n const getOriginRect = internals._getOriginRect.bind(strategy);\n const getOriginPoint = internals._getOriginPoint.bind(strategy);\n const attach = strategy.attach.bind(strategy);\n const detach = strategy.detach.bind(strategy);\n const dispose = strategy.dispose.bind(strategy);\n let stopObserving = () => {};\n internals._getOriginRect = () => {\n return translateRectToBoundary(getOriginRect(), overlayRoot.getBoundingClientRect());\n };\n internals._getOriginPoint = (originRect, _containerRect, position) => {\n return getOriginPoint(originRect, getBoundaryRect(overlayRoot), position);\n };\n strategy.attach = (overlayRef) => {\n attach(overlayRef);\n stopObserving();\n stopObserving = observeBoundary(() => strategy.apply());\n };\n strategy.detach = () => {\n stopObserving();\n stopObserving = () => {};\n detach();\n };\n strategy.dispose = () => {\n stopObserving();\n stopObserving = () => {};\n dispose();\n };\n\n return strategy;\n};\n\nclass MfOverlayPositionBuilder extends OverlayPositionBuilder {\n readonly #document: Document;\n readonly #overlayContainer: OverlayContainer;\n readonly #overlayRoot: HTMLElement;\n readonly #platform: Platform;\n readonly #viewportRuler: ViewportRuler;\n\n constructor(viewportRuler: ViewportRuler, document: Document, platform: Platform, overlayContainer: OverlayContainer, overlayRoot: HTMLElement) {\n super();\n this.#viewportRuler = viewportRuler;\n this.#document = document;\n this.#platform = platform;\n this.#overlayContainer = overlayContainer;\n this.#overlayRoot = overlayRoot;\n }\n\n override global(): GlobalPositionStrategy {\n return new GlobalPositionStrategy();\n }\n\n override flexibleConnectedTo(origin: FlexibleConnectedPositionStrategyOrigin): FlexibleConnectedPositionStrategy {\n const boundaryDocument = createBoundaryDocument(this.#document, this.#overlayRoot);\n const boundaryViewportRuler = createBoundaryViewportRuler(this.#viewportRuler, this.#overlayRoot);\n const strategy = new FlexibleConnectedPositionStrategy(origin, boundaryViewportRuler, boundaryDocument, this.#platform, this.#overlayContainer);\n\n const overlayContainer = this.#overlayContainer as MfOverlayContainer;\n return adaptConnectedPositionStrategy(strategy, this.#overlayRoot, (callback) => overlayContainer.observeBoundary(callback));\n }\n}\n\nclass MfOverlayContainer extends OverlayContainer {\n readonly #boundaryObservers = new Set<() => void>();\n readonly #overlayRoot: HTMLElement;\n #animationFrame: number | null = null;\n #boundaryRect: IClientRect | null = null;\n #restoreRootPosition: (() => void) | null = null;\n #shadowStyle: HTMLStyleElement | null = null;\n\n constructor(overlayRoot: HTMLElement) {\n super();\n this.#overlayRoot = overlayRoot;\n }\n\n override ngOnDestroy(): void {\n if (this.#animationFrame !== null) {\n this.#overlayRoot.ownerDocument.defaultView?.cancelAnimationFrame(this.#animationFrame);\n }\n this.#animationFrame = null;\n this.#boundaryObservers.clear();\n super.ngOnDestroy();\n this.#shadowStyle?.remove();\n this.#shadowStyle = null;\n this.#restoreRootPosition?.();\n this.#restoreRootPosition = null;\n }\n\n observeBoundary(callback: () => void): () => void {\n this.#boundaryObservers.add(callback);\n if (this.#boundaryObservers.size === 1) {\n this.#boundaryRect = this.#overlayRoot.getBoundingClientRect();\n this.#scheduleBoundaryCheck();\n }\n\n return () => {\n this.#boundaryObservers.delete(callback);\n if (this.#boundaryObservers.size === 0 && this.#animationFrame !== null) {\n this.#overlayRoot.ownerDocument.defaultView?.cancelAnimationFrame(this.#animationFrame);\n this.#animationFrame = null;\n this.#boundaryRect = null;\n }\n };\n }\n\n protected override _createContainer(): void {\n if (this.#overlayRoot.ownerDocument.defaultView?.getComputedStyle(this.#overlayRoot).position === 'static') {\n const previousPosition = this.#overlayRoot.style.position;\n this.#overlayRoot.style.position = 'relative';\n this.#restoreRootPosition = () => {\n this.#overlayRoot.style.position = previousPosition;\n };\n }\n\n const rootNode = this.#overlayRoot.getRootNode();\n const ShadowRootConstructor = this.#overlayRoot.ownerDocument.defaultView?.ShadowRoot;\n if (ShadowRootConstructor && rootNode instanceof ShadowRootConstructor) {\n const style = this._document.createElement('style');\n style.setAttribute('data-edyn-mf-cdk-overlay-styles', '');\n style.textContent = CDK_OVERLAY_STRUCTURAL_CSS;\n rootNode.appendChild(style);\n this.#shadowStyle = style;\n }\n\n const container = this._document.createElement('div');\n container.classList.add('cdk-overlay-container');\n container.style.inset = '0';\n container.style.position = 'absolute';\n this.#overlayRoot.appendChild(container);\n this._containerElement = container;\n }\n\n #scheduleBoundaryCheck(): void {\n const window = this.#overlayRoot.ownerDocument.defaultView;\n if (!window || this.#animationFrame !== null || this.#boundaryObservers.size === 0) {\n return;\n }\n\n this.#animationFrame = window.requestAnimationFrame(() => {\n this.#animationFrame = null;\n const previous = this.#boundaryRect;\n const current = this.#overlayRoot.getBoundingClientRect();\n this.#boundaryRect = current;\n\n if (\n previous &&\n (previous.height !== current.height || previous.left !== current.left || previous.top !== current.top || previous.width !== current.width)\n ) {\n for (const observer of this.#boundaryObservers) {\n observer();\n }\n }\n\n this.#scheduleBoundaryCheck();\n });\n }\n}\n\nconst isDocumentViewportRoot = (overlayRoot: HTMLElement): boolean => {\n return overlayRoot === overlayRoot.ownerDocument.body || overlayRoot === overlayRoot.ownerDocument.documentElement;\n};\n\nconst createOverlayContainer = (overlayRoot: HTMLElement): OverlayContainer => {\n return isDocumentViewportRoot(overlayRoot) ? new OverlayContainer() : new MfOverlayContainer(overlayRoot);\n};\n\nconst createOverlayPositionBuilder = (\n viewportRuler: ViewportRuler,\n document: Document,\n platform: Platform,\n overlayContainer: OverlayContainer,\n overlayRoot: HTMLElement,\n): OverlayPositionBuilder => {\n if (isDocumentViewportRoot(overlayRoot)) {\n return new OverlayPositionBuilder();\n }\n return new MfOverlayPositionBuilder(viewportRuler, document, platform, overlayContainer, overlayRoot);\n};\n\n// Hosted, the overlay root sits in the module's shadow root, so the providers every module already uses for overlays also\n// make rem lengths there follow the module's own root font size. They start with the module's injector, before its\n// first component renders and Angular adds component styles, and stop with it.\nconst followRootFontSizeOf = (overlayRoot: HTMLElement, destroyRef: DestroyRef): void => {\n const rootNode = overlayRoot.getRootNode();\n const ShadowRootConstructor = overlayRoot.ownerDocument.defaultView?.ShadowRoot;\n if (ShadowRootConstructor && rootNode instanceof ShadowRootConstructor) {\n destroyRef.onDestroy(followModuleRootFontSize(rootNode));\n }\n};\n\nconst createTokenProviders = (overlayRootToken: ProviderToken<HTMLElement>): StaticProvider[] => {\n return [\n {\n provide: ENVIRONMENT_INITIALIZER,\n multi: true,\n useFactory: (overlayRoot: HTMLElement, destroyRef: DestroyRef) => () => followRootFontSizeOf(overlayRoot, destroyRef),\n deps: [overlayRootToken, DestroyRef],\n },\n {\n provide: OverlayContainer,\n useFactory: createOverlayContainer,\n deps: [overlayRootToken],\n },\n {\n provide: OverlayPositionBuilder,\n useFactory: createOverlayPositionBuilder,\n deps: [ViewportRuler, DOCUMENT, Platform, OverlayContainer, overlayRootToken],\n },\n ];\n};\n\nexport const provideMfOverlayRoot = (overlayRoot?: HTMLElement): StaticProvider[] => {\n if (!overlayRoot) {\n return [];\n }\n\n return [\n {\n provide: ENVIRONMENT_INITIALIZER,\n multi: true,\n useFactory: (destroyRef: DestroyRef) => () => followRootFontSizeOf(overlayRoot, destroyRef),\n deps: [DestroyRef],\n },\n {\n provide: OverlayContainer,\n useFactory: () => createOverlayContainer(overlayRoot),\n },\n {\n provide: OverlayPositionBuilder,\n useFactory: (viewportRuler: ViewportRuler, document: Document, platform: Platform, overlayContainer: OverlayContainer) => {\n return createOverlayPositionBuilder(viewportRuler, document, platform, overlayContainer, overlayRoot);\n },\n deps: [ViewportRuler, DOCUMENT, Platform, OverlayContainer],\n },\n ];\n};\n\nexport const provideMfOverlayRootFromToken = (overlayRootToken: ProviderToken<HTMLElement>): StaticProvider[] => {\n return createTokenProviders(overlayRootToken);\n};\n\nexport { CaseInsensitiveBasePathLocationStrategy, provideCaseInsensitiveBasePath } from './angular-location.js';\n"]}
package/dist/angular.js CHANGED
@@ -2,6 +2,8 @@ import { FlexibleConnectedPositionStrategy, GlobalPositionStrategy, OverlayConta
2
2
  import { Platform } from '@angular/cdk/platform';
3
3
  import { ViewportRuler } from '@angular/cdk/scrolling';
4
4
  import { DOCUMENT } from '@angular/common';
5
+ import { DestroyRef, ENVIRONMENT_INITIALIZER } from '@angular/core';
6
+ import { followModuleRootFontSize } from './root-font-size.js';
5
7
  // Mirrors the CDK 19 overlay-prebuilt.css structural rules while intentionally excluding document-level scroll blocking.
6
8
  const CDK_OVERLAY_STRUCTURAL_CSS = `
7
9
  .cdk-overlay-container,.cdk-global-overlay-wrapper{pointer-events:none;top:0;left:0;height:100%;width:100%}
@@ -227,8 +229,24 @@ const createOverlayPositionBuilder = (viewportRuler, document, platform, overlay
227
229
  }
228
230
  return new MfOverlayPositionBuilder(viewportRuler, document, platform, overlayContainer, overlayRoot);
229
231
  };
232
+ // Hosted, the overlay root sits in the module's shadow root, so the providers every module already uses for overlays also
233
+ // make rem lengths there follow the module's own root font size. They start with the module's injector, before its
234
+ // first component renders and Angular adds component styles, and stop with it.
235
+ const followRootFontSizeOf = (overlayRoot, destroyRef) => {
236
+ const rootNode = overlayRoot.getRootNode();
237
+ const ShadowRootConstructor = overlayRoot.ownerDocument.defaultView?.ShadowRoot;
238
+ if (ShadowRootConstructor && rootNode instanceof ShadowRootConstructor) {
239
+ destroyRef.onDestroy(followModuleRootFontSize(rootNode));
240
+ }
241
+ };
230
242
  const createTokenProviders = (overlayRootToken) => {
231
243
  return [
244
+ {
245
+ provide: ENVIRONMENT_INITIALIZER,
246
+ multi: true,
247
+ useFactory: (overlayRoot, destroyRef) => () => followRootFontSizeOf(overlayRoot, destroyRef),
248
+ deps: [overlayRootToken, DestroyRef],
249
+ },
232
250
  {
233
251
  provide: OverlayContainer,
234
252
  useFactory: createOverlayContainer,
@@ -246,6 +264,12 @@ export const provideMfOverlayRoot = (overlayRoot) => {
246
264
  return [];
247
265
  }
248
266
  return [
267
+ {
268
+ provide: ENVIRONMENT_INITIALIZER,
269
+ multi: true,
270
+ useFactory: (destroyRef) => () => followRootFontSizeOf(overlayRoot, destroyRef),
271
+ deps: [DestroyRef],
272
+ },
249
273
  {
250
274
  provide: OverlayContainer,
251
275
  useFactory: () => createOverlayContainer(overlayRoot),
@@ -1 +1 @@
1
- {"version":3,"file":"angular.js","sourceRoot":"","sources":["../src/angular.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EAEjC,sBAAsB,EACtB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,yHAAyH;AACzH,MAAM,0BAA0B,GAAG;;;;;;;;;;;;;;;CAelC,CAAC;AAkBF,MAAM,uBAAuB,GAAG,CAAC,IAAiB,EAAE,QAAqB,EAAe,EAAE;IACxF,M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,CAAC,WAAW,CAAC;SACtD;QACD;YACE,OAAO,EAAE,sBAAsB;YAC/B,UAAU,EAAE,CAAC,aAA4B,EAAE,QAAkB,EAAE,QAAkB,EAAE,gBAAkC,EAAE,EAAE;gBACvH,OAAO,4BAA4B,CAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,CAAC;YACxG,CAAC;YACD,IAAI,EAAE,CAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,CAAC;SAC5D;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,gBAA4C,EAAoB,EAAE;IAC9G,OAAO,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;AAChD,CAAC,CAAC;AAEF,OAAO,EAAE,uCAAuC,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["import {\n FlexibleConnectedPositionStrategy,\n type FlexibleConnectedPositionStrategyOrigin,\n GlobalPositionStrategy,\n OverlayContainer,\n OverlayPositionBuilder,\n} from '@angular/cdk/overlay';\nimport { Platform } from '@angular/cdk/platform';\nimport { ViewportRuler } from '@angular/cdk/scrolling';\nimport { DOCUMENT } from '@angular/common';\nimport type { ProviderToken, StaticProvider } from '@angular/core';\n\n// Mirrors the CDK 19 overlay-prebuilt.css structural rules while intentionally excluding document-level scroll blocking.\nconst CDK_OVERLAY_STRUCTURAL_CSS = `\n.cdk-overlay-container,.cdk-global-overlay-wrapper{pointer-events:none;top:0;left:0;height:100%;width:100%}\n.cdk-overlay-container{position:fixed;z-index:1000}\n.cdk-overlay-container:empty{display:none}\n.cdk-global-overlay-wrapper{display:flex;position:absolute;z-index:1000}\n.cdk-overlay-pane{position:absolute;pointer-events:auto;box-sizing:border-box;display:flex;max-width:100%;max-height:100%;z-index:1000}\n.cdk-overlay-backdrop{position:absolute;top:0;bottom:0;left:0;right:0;pointer-events:auto;-webkit-tap-highlight-color:rgba(0,0,0,0);opacity:0;touch-action:manipulation;z-index:1000;transition:opacity 400ms cubic-bezier(0.25,0.8,0.25,1)}\n@media(prefers-reduced-motion){.cdk-overlay-backdrop{transition-duration:1ms}}\n.cdk-overlay-backdrop-showing{opacity:1}\n@media(forced-colors:active){.cdk-overlay-backdrop-showing{opacity:.6}}\n.cdk-overlay-dark-backdrop{background:rgba(0,0,0,.32)}\n.cdk-overlay-transparent-backdrop{transition:visibility 1ms linear,opacity 1ms linear;visibility:hidden;opacity:1}\n.cdk-overlay-transparent-backdrop.cdk-overlay-backdrop-showing,.cdk-high-contrast-active .cdk-overlay-transparent-backdrop{opacity:0;visibility:visible}\n.cdk-overlay-backdrop-noop-animation{transition:none}\n.cdk-overlay-connected-position-bounding-box{position:absolute;display:flex;flex-direction:column;min-width:1px;min-height:1px;z-index:1000}\n`;\n\ninterface IClientRect {\n bottom: number;\n height: number;\n left: number;\n right: number;\n top: number;\n width: number;\n x?: number;\n y?: number;\n}\n\ninterface IFlexibleConnectedPositionStrategyInternals {\n _getOriginPoint: (originRect: IClientRect, containerRect: IClientRect, position: unknown) => { x: number; y: number };\n _getOriginRect: () => IClientRect;\n}\n\nconst translateRectToBoundary = (rect: IClientRect, boundary: IClientRect): IClientRect => {\n const left = rect.left - boundary.left;\n const top = rect.top - boundary.top;\n\n return {\n bottom: top + rect.height,\n height: rect.height,\n left,\n right: left + rect.width,\n top,\n width: rect.width,\n x: left,\n y: top,\n };\n};\n\nconst getBoundaryRect = (overlayRoot: HTMLElement): IClientRect => {\n const { height, width } = overlayRoot.getBoundingClientRect();\n return {\n bottom: height,\n height,\n left: 0,\n right: width,\n top: 0,\n width,\n x: 0,\n y: 0,\n };\n};\n\nconst createBoundaryDocument = (document: Document, overlayRoot: HTMLElement): Document => {\n const boundaryDocumentElement = new Proxy(document.documentElement, {\n get: (target, property, receiver) => {\n if (property === 'clientHeight') {\n return overlayRoot.getBoundingClientRect().height;\n }\n if (property === 'clientWidth') {\n return overlayRoot.getBoundingClientRect().width;\n }\n return Reflect.get(target, property, receiver);\n },\n });\n\n return new Proxy(document, {\n get: (target, property, receiver) => {\n if (property === 'documentElement') {\n return boundaryDocumentElement;\n }\n return Reflect.get(target, property, receiver);\n },\n });\n};\n\nconst createBoundaryViewportRuler = (viewportRuler: ViewportRuler, overlayRoot: HTMLElement): ViewportRuler => {\n const boundaryViewportRuler = Object.create(viewportRuler) as ViewportRuler;\n boundaryViewportRuler.getViewportRect = () => getBoundaryRect(overlayRoot);\n boundaryViewportRuler.getViewportScrollPosition = () => ({ left: 0, top: 0 });\n boundaryViewportRuler.getViewportSize = () => {\n const { height, width } = getBoundaryRect(overlayRoot);\n return { height, width };\n };\n return boundaryViewportRuler;\n};\n\nconst adaptConnectedPositionStrategy = (\n strategy: FlexibleConnectedPositionStrategy,\n overlayRoot: HTMLElement,\n observeBoundary: (callback: () => void) => () => void,\n): FlexibleConnectedPositionStrategy => {\n const internals = strategy as unknown as IFlexibleConnectedPositionStrategyInternals;\n const getOriginRect = internals._getOriginRect.bind(strategy);\n const getOriginPoint = internals._getOriginPoint.bind(strategy);\n const attach = strategy.attach.bind(strategy);\n const detach = strategy.detach.bind(strategy);\n const dispose = strategy.dispose.bind(strategy);\n let stopObserving = () => {};\n internals._getOriginRect = () => {\n return translateRectToBoundary(getOriginRect(), overlayRoot.getBoundingClientRect());\n };\n internals._getOriginPoint = (originRect, _containerRect, position) => {\n return getOriginPoint(originRect, getBoundaryRect(overlayRoot), position);\n };\n strategy.attach = (overlayRef) => {\n attach(overlayRef);\n stopObserving();\n stopObserving = observeBoundary(() => strategy.apply());\n };\n strategy.detach = () => {\n stopObserving();\n stopObserving = () => {};\n detach();\n };\n strategy.dispose = () => {\n stopObserving();\n stopObserving = () => {};\n dispose();\n };\n\n return strategy;\n};\n\nclass MfOverlayPositionBuilder extends OverlayPositionBuilder {\n readonly #document: Document;\n readonly #overlayContainer: OverlayContainer;\n readonly #overlayRoot: HTMLElement;\n readonly #platform: Platform;\n readonly #viewportRuler: ViewportRuler;\n\n constructor(viewportRuler: ViewportRuler, document: Document, platform: Platform, overlayContainer: OverlayContainer, overlayRoot: HTMLElement) {\n super();\n this.#viewportRuler = viewportRuler;\n this.#document = document;\n this.#platform = platform;\n this.#overlayContainer = overlayContainer;\n this.#overlayRoot = overlayRoot;\n }\n\n override global(): GlobalPositionStrategy {\n return new GlobalPositionStrategy();\n }\n\n override flexibleConnectedTo(origin: FlexibleConnectedPositionStrategyOrigin): FlexibleConnectedPositionStrategy {\n const boundaryDocument = createBoundaryDocument(this.#document, this.#overlayRoot);\n const boundaryViewportRuler = createBoundaryViewportRuler(this.#viewportRuler, this.#overlayRoot);\n const strategy = new FlexibleConnectedPositionStrategy(origin, boundaryViewportRuler, boundaryDocument, this.#platform, this.#overlayContainer);\n\n const overlayContainer = this.#overlayContainer as MfOverlayContainer;\n return adaptConnectedPositionStrategy(strategy, this.#overlayRoot, (callback) => overlayContainer.observeBoundary(callback));\n }\n}\n\nclass MfOverlayContainer extends OverlayContainer {\n readonly #boundaryObservers = new Set<() => void>();\n readonly #overlayRoot: HTMLElement;\n #animationFrame: number | null = null;\n #boundaryRect: IClientRect | null = null;\n #restoreRootPosition: (() => void) | null = null;\n #shadowStyle: HTMLStyleElement | null = null;\n\n constructor(overlayRoot: HTMLElement) {\n super();\n this.#overlayRoot = overlayRoot;\n }\n\n override ngOnDestroy(): void {\n if (this.#animationFrame !== null) {\n this.#overlayRoot.ownerDocument.defaultView?.cancelAnimationFrame(this.#animationFrame);\n }\n this.#animationFrame = null;\n this.#boundaryObservers.clear();\n super.ngOnDestroy();\n this.#shadowStyle?.remove();\n this.#shadowStyle = null;\n this.#restoreRootPosition?.();\n this.#restoreRootPosition = null;\n }\n\n observeBoundary(callback: () => void): () => void {\n this.#boundaryObservers.add(callback);\n if (this.#boundaryObservers.size === 1) {\n this.#boundaryRect = this.#overlayRoot.getBoundingClientRect();\n this.#scheduleBoundaryCheck();\n }\n\n return () => {\n this.#boundaryObservers.delete(callback);\n if (this.#boundaryObservers.size === 0 && this.#animationFrame !== null) {\n this.#overlayRoot.ownerDocument.defaultView?.cancelAnimationFrame(this.#animationFrame);\n this.#animationFrame = null;\n this.#boundaryRect = null;\n }\n };\n }\n\n protected override _createContainer(): void {\n if (this.#overlayRoot.ownerDocument.defaultView?.getComputedStyle(this.#overlayRoot).position === 'static') {\n const previousPosition = this.#overlayRoot.style.position;\n this.#overlayRoot.style.position = 'relative';\n this.#restoreRootPosition = () => {\n this.#overlayRoot.style.position = previousPosition;\n };\n }\n\n const rootNode = this.#overlayRoot.getRootNode();\n const ShadowRootConstructor = this.#overlayRoot.ownerDocument.defaultView?.ShadowRoot;\n if (ShadowRootConstructor && rootNode instanceof ShadowRootConstructor) {\n const style = this._document.createElement('style');\n style.setAttribute('data-edyn-mf-cdk-overlay-styles', '');\n style.textContent = CDK_OVERLAY_STRUCTURAL_CSS;\n rootNode.appendChild(style);\n this.#shadowStyle = style;\n }\n\n const container = this._document.createElement('div');\n container.classList.add('cdk-overlay-container');\n container.style.inset = '0';\n container.style.position = 'absolute';\n this.#overlayRoot.appendChild(container);\n this._containerElement = container;\n }\n\n #scheduleBoundaryCheck(): void {\n const window = this.#overlayRoot.ownerDocument.defaultView;\n if (!window || this.#animationFrame !== null || this.#boundaryObservers.size === 0) {\n return;\n }\n\n this.#animationFrame = window.requestAnimationFrame(() => {\n this.#animationFrame = null;\n const previous = this.#boundaryRect;\n const current = this.#overlayRoot.getBoundingClientRect();\n this.#boundaryRect = current;\n\n if (\n previous &&\n (previous.height !== current.height || previous.left !== current.left || previous.top !== current.top || previous.width !== current.width)\n ) {\n for (const observer of this.#boundaryObservers) {\n observer();\n }\n }\n\n this.#scheduleBoundaryCheck();\n });\n }\n}\n\nconst isDocumentViewportRoot = (overlayRoot: HTMLElement): boolean => {\n return overlayRoot === overlayRoot.ownerDocument.body || overlayRoot === overlayRoot.ownerDocument.documentElement;\n};\n\nconst createOverlayContainer = (overlayRoot: HTMLElement): OverlayContainer => {\n return isDocumentViewportRoot(overlayRoot) ? new OverlayContainer() : new MfOverlayContainer(overlayRoot);\n};\n\nconst createOverlayPositionBuilder = (\n viewportRuler: ViewportRuler,\n document: Document,\n platform: Platform,\n overlayContainer: OverlayContainer,\n overlayRoot: HTMLElement,\n): OverlayPositionBuilder => {\n if (isDocumentViewportRoot(overlayRoot)) {\n return new OverlayPositionBuilder();\n }\n return new MfOverlayPositionBuilder(viewportRuler, document, platform, overlayContainer, overlayRoot);\n};\n\nconst createTokenProviders = (overlayRootToken: ProviderToken<HTMLElement>): StaticProvider[] => {\n return [\n {\n provide: OverlayContainer,\n useFactory: createOverlayContainer,\n deps: [overlayRootToken],\n },\n {\n provide: OverlayPositionBuilder,\n useFactory: createOverlayPositionBuilder,\n deps: [ViewportRuler, DOCUMENT, Platform, OverlayContainer, overlayRootToken],\n },\n ];\n};\n\nexport const provideMfOverlayRoot = (overlayRoot?: HTMLElement): StaticProvider[] => {\n if (!overlayRoot) {\n return [];\n }\n\n return [\n {\n provide: OverlayContainer,\n useFactory: () => createOverlayContainer(overlayRoot),\n },\n {\n provide: OverlayPositionBuilder,\n useFactory: (viewportRuler: ViewportRuler, document: Document, platform: Platform, overlayContainer: OverlayContainer) => {\n return createOverlayPositionBuilder(viewportRuler, document, platform, overlayContainer, overlayRoot);\n },\n deps: [ViewportRuler, DOCUMENT, Platform, OverlayContainer],\n },\n ];\n};\n\nexport const provideMfOverlayRootFromToken = (overlayRootToken: ProviderToken<HTMLElement>): StaticProvider[] => {\n return createTokenProviders(overlayRootToken);\n};\n\nexport { CaseInsensitiveBasePathLocationStrategy, provideCaseInsensitiveBasePath } from './angular-location.js';\n"]}
1
+ {"version":3,"file":"angular.js","sourceRoot":"","sources":["../src/angular.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EAEjC,sBAAsB,EACtB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAA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YACE,OAAO,EAAE,sBAAsB;YAC/B,UAAU,EAAE,CAAC,aAA4B,EAAE,QAAkB,EAAE,QAAkB,EAAE,gBAAkC,EAAE,EAAE;gBACvH,OAAO,4BAA4B,CAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,CAAC;YACxG,CAAC;YACD,IAAI,EAAE,CAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,CAAC;SAC5D;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,gBAA4C,EAAoB,EAAE;IAC9G,OAAO,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;AAChD,CAAC,CAAC;AAEF,OAAO,EAAE,uCAAuC,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["import {\n FlexibleConnectedPositionStrategy,\n type FlexibleConnectedPositionStrategyOrigin,\n GlobalPositionStrategy,\n OverlayContainer,\n OverlayPositionBuilder,\n} from '@angular/cdk/overlay';\nimport { Platform } from '@angular/cdk/platform';\nimport { ViewportRuler } from '@angular/cdk/scrolling';\nimport { DOCUMENT } from '@angular/common';\nimport { DestroyRef, ENVIRONMENT_INITIALIZER, type ProviderToken, type StaticProvider } from '@angular/core';\nimport { followModuleRootFontSize } from './root-font-size.js';\n\n// Mirrors the CDK 19 overlay-prebuilt.css structural rules while intentionally excluding document-level scroll blocking.\nconst CDK_OVERLAY_STRUCTURAL_CSS = `\n.cdk-overlay-container,.cdk-global-overlay-wrapper{pointer-events:none;top:0;left:0;height:100%;width:100%}\n.cdk-overlay-container{position:fixed;z-index:1000}\n.cdk-overlay-container:empty{display:none}\n.cdk-global-overlay-wrapper{display:flex;position:absolute;z-index:1000}\n.cdk-overlay-pane{position:absolute;pointer-events:auto;box-sizing:border-box;display:flex;max-width:100%;max-height:100%;z-index:1000}\n.cdk-overlay-backdrop{position:absolute;top:0;bottom:0;left:0;right:0;pointer-events:auto;-webkit-tap-highlight-color:rgba(0,0,0,0);opacity:0;touch-action:manipulation;z-index:1000;transition:opacity 400ms cubic-bezier(0.25,0.8,0.25,1)}\n@media(prefers-reduced-motion){.cdk-overlay-backdrop{transition-duration:1ms}}\n.cdk-overlay-backdrop-showing{opacity:1}\n@media(forced-colors:active){.cdk-overlay-backdrop-showing{opacity:.6}}\n.cdk-overlay-dark-backdrop{background:rgba(0,0,0,.32)}\n.cdk-overlay-transparent-backdrop{transition:visibility 1ms linear,opacity 1ms linear;visibility:hidden;opacity:1}\n.cdk-overlay-transparent-backdrop.cdk-overlay-backdrop-showing,.cdk-high-contrast-active .cdk-overlay-transparent-backdrop{opacity:0;visibility:visible}\n.cdk-overlay-backdrop-noop-animation{transition:none}\n.cdk-overlay-connected-position-bounding-box{position:absolute;display:flex;flex-direction:column;min-width:1px;min-height:1px;z-index:1000}\n`;\n\ninterface IClientRect {\n bottom: number;\n height: number;\n left: number;\n right: number;\n top: number;\n width: number;\n x?: number;\n y?: number;\n}\n\ninterface IFlexibleConnectedPositionStrategyInternals {\n _getOriginPoint: (originRect: IClientRect, containerRect: IClientRect, position: unknown) => { x: number; y: number };\n _getOriginRect: () => IClientRect;\n}\n\nconst translateRectToBoundary = (rect: IClientRect, boundary: IClientRect): IClientRect => {\n const left = rect.left - boundary.left;\n const top = rect.top - boundary.top;\n\n return {\n bottom: top + rect.height,\n height: rect.height,\n left,\n right: left + rect.width,\n top,\n width: rect.width,\n x: left,\n y: top,\n };\n};\n\nconst getBoundaryRect = (overlayRoot: HTMLElement): IClientRect => {\n const { height, width } = overlayRoot.getBoundingClientRect();\n return {\n bottom: height,\n height,\n left: 0,\n right: width,\n top: 0,\n width,\n x: 0,\n y: 0,\n };\n};\n\nconst createBoundaryDocument = (document: Document, overlayRoot: HTMLElement): Document => {\n const boundaryDocumentElement = new Proxy(document.documentElement, {\n get: (target, property, receiver) => {\n if (property === 'clientHeight') {\n return overlayRoot.getBoundingClientRect().height;\n }\n if (property === 'clientWidth') {\n return overlayRoot.getBoundingClientRect().width;\n }\n return Reflect.get(target, property, receiver);\n },\n });\n\n return new Proxy(document, {\n get: (target, property, receiver) => {\n if (property === 'documentElement') {\n return boundaryDocumentElement;\n }\n return Reflect.get(target, property, receiver);\n },\n });\n};\n\nconst createBoundaryViewportRuler = (viewportRuler: ViewportRuler, overlayRoot: HTMLElement): ViewportRuler => {\n const boundaryViewportRuler = Object.create(viewportRuler) as ViewportRuler;\n boundaryViewportRuler.getViewportRect = () => getBoundaryRect(overlayRoot);\n boundaryViewportRuler.getViewportScrollPosition = () => ({ left: 0, top: 0 });\n boundaryViewportRuler.getViewportSize = () => {\n const { height, width } = getBoundaryRect(overlayRoot);\n return { height, width };\n };\n return boundaryViewportRuler;\n};\n\nconst adaptConnectedPositionStrategy = (\n strategy: FlexibleConnectedPositionStrategy,\n overlayRoot: HTMLElement,\n observeBoundary: (callback: () => void) => () => void,\n): FlexibleConnectedPositionStrategy => {\n const internals = strategy as unknown as IFlexibleConnectedPositionStrategyInternals;\n const getOriginRect = internals._getOriginRect.bind(strategy);\n const getOriginPoint = internals._getOriginPoint.bind(strategy);\n const attach = strategy.attach.bind(strategy);\n const detach = strategy.detach.bind(strategy);\n const dispose = strategy.dispose.bind(strategy);\n let stopObserving = () => {};\n internals._getOriginRect = () => {\n return translateRectToBoundary(getOriginRect(), overlayRoot.getBoundingClientRect());\n };\n internals._getOriginPoint = (originRect, _containerRect, position) => {\n return getOriginPoint(originRect, getBoundaryRect(overlayRoot), position);\n };\n strategy.attach = (overlayRef) => {\n attach(overlayRef);\n stopObserving();\n stopObserving = observeBoundary(() => strategy.apply());\n };\n strategy.detach = () => {\n stopObserving();\n stopObserving = () => {};\n detach();\n };\n strategy.dispose = () => {\n stopObserving();\n stopObserving = () => {};\n dispose();\n };\n\n return strategy;\n};\n\nclass MfOverlayPositionBuilder extends OverlayPositionBuilder {\n readonly #document: Document;\n readonly #overlayContainer: OverlayContainer;\n readonly #overlayRoot: HTMLElement;\n readonly #platform: Platform;\n readonly #viewportRuler: ViewportRuler;\n\n constructor(viewportRuler: ViewportRuler, document: Document, platform: Platform, overlayContainer: OverlayContainer, overlayRoot: HTMLElement) {\n super();\n this.#viewportRuler = viewportRuler;\n this.#document = document;\n this.#platform = platform;\n this.#overlayContainer = overlayContainer;\n this.#overlayRoot = overlayRoot;\n }\n\n override global(): GlobalPositionStrategy {\n return new GlobalPositionStrategy();\n }\n\n override flexibleConnectedTo(origin: FlexibleConnectedPositionStrategyOrigin): FlexibleConnectedPositionStrategy {\n const boundaryDocument = createBoundaryDocument(this.#document, this.#overlayRoot);\n const boundaryViewportRuler = createBoundaryViewportRuler(this.#viewportRuler, this.#overlayRoot);\n const strategy = new FlexibleConnectedPositionStrategy(origin, boundaryViewportRuler, boundaryDocument, this.#platform, this.#overlayContainer);\n\n const overlayContainer = this.#overlayContainer as MfOverlayContainer;\n return adaptConnectedPositionStrategy(strategy, this.#overlayRoot, (callback) => overlayContainer.observeBoundary(callback));\n }\n}\n\nclass MfOverlayContainer extends OverlayContainer {\n readonly #boundaryObservers = new Set<() => void>();\n readonly #overlayRoot: HTMLElement;\n #animationFrame: number | null = null;\n #boundaryRect: IClientRect | null = null;\n #restoreRootPosition: (() => void) | null = null;\n #shadowStyle: HTMLStyleElement | null = null;\n\n constructor(overlayRoot: HTMLElement) {\n super();\n this.#overlayRoot = overlayRoot;\n }\n\n override ngOnDestroy(): void {\n if (this.#animationFrame !== null) {\n this.#overlayRoot.ownerDocument.defaultView?.cancelAnimationFrame(this.#animationFrame);\n }\n this.#animationFrame = null;\n this.#boundaryObservers.clear();\n super.ngOnDestroy();\n this.#shadowStyle?.remove();\n this.#shadowStyle = null;\n this.#restoreRootPosition?.();\n this.#restoreRootPosition = null;\n }\n\n observeBoundary(callback: () => void): () => void {\n this.#boundaryObservers.add(callback);\n if (this.#boundaryObservers.size === 1) {\n this.#boundaryRect = this.#overlayRoot.getBoundingClientRect();\n this.#scheduleBoundaryCheck();\n }\n\n return () => {\n this.#boundaryObservers.delete(callback);\n if (this.#boundaryObservers.size === 0 && this.#animationFrame !== null) {\n this.#overlayRoot.ownerDocument.defaultView?.cancelAnimationFrame(this.#animationFrame);\n this.#animationFrame = null;\n this.#boundaryRect = null;\n }\n };\n }\n\n protected override _createContainer(): void {\n if (this.#overlayRoot.ownerDocument.defaultView?.getComputedStyle(this.#overlayRoot).position === 'static') {\n const previousPosition = this.#overlayRoot.style.position;\n this.#overlayRoot.style.position = 'relative';\n this.#restoreRootPosition = () => {\n this.#overlayRoot.style.position = previousPosition;\n };\n }\n\n const rootNode = this.#overlayRoot.getRootNode();\n const ShadowRootConstructor = this.#overlayRoot.ownerDocument.defaultView?.ShadowRoot;\n if (ShadowRootConstructor && rootNode instanceof ShadowRootConstructor) {\n const style = this._document.createElement('style');\n style.setAttribute('data-edyn-mf-cdk-overlay-styles', '');\n style.textContent = CDK_OVERLAY_STRUCTURAL_CSS;\n rootNode.appendChild(style);\n this.#shadowStyle = style;\n }\n\n const container = this._document.createElement('div');\n container.classList.add('cdk-overlay-container');\n container.style.inset = '0';\n container.style.position = 'absolute';\n this.#overlayRoot.appendChild(container);\n this._containerElement = container;\n }\n\n #scheduleBoundaryCheck(): void {\n const window = this.#overlayRoot.ownerDocument.defaultView;\n if (!window || this.#animationFrame !== null || this.#boundaryObservers.size === 0) {\n return;\n }\n\n this.#animationFrame = window.requestAnimationFrame(() => {\n this.#animationFrame = null;\n const previous = this.#boundaryRect;\n const current = this.#overlayRoot.getBoundingClientRect();\n this.#boundaryRect = current;\n\n if (\n previous &&\n (previous.height !== current.height || previous.left !== current.left || previous.top !== current.top || previous.width !== current.width)\n ) {\n for (const observer of this.#boundaryObservers) {\n observer();\n }\n }\n\n this.#scheduleBoundaryCheck();\n });\n }\n}\n\nconst isDocumentViewportRoot = (overlayRoot: HTMLElement): boolean => {\n return overlayRoot === overlayRoot.ownerDocument.body || overlayRoot === overlayRoot.ownerDocument.documentElement;\n};\n\nconst createOverlayContainer = (overlayRoot: HTMLElement): OverlayContainer => {\n return isDocumentViewportRoot(overlayRoot) ? new OverlayContainer() : new MfOverlayContainer(overlayRoot);\n};\n\nconst createOverlayPositionBuilder = (\n viewportRuler: ViewportRuler,\n document: Document,\n platform: Platform,\n overlayContainer: OverlayContainer,\n overlayRoot: HTMLElement,\n): OverlayPositionBuilder => {\n if (isDocumentViewportRoot(overlayRoot)) {\n return new OverlayPositionBuilder();\n }\n return new MfOverlayPositionBuilder(viewportRuler, document, platform, overlayContainer, overlayRoot);\n};\n\n// Hosted, the overlay root sits in the module's shadow root, so the providers every module already uses for overlays also\n// make rem lengths there follow the module's own root font size. They start with the module's injector, before its\n// first component renders and Angular adds component styles, and stop with it.\nconst followRootFontSizeOf = (overlayRoot: HTMLElement, destroyRef: DestroyRef): void => {\n const rootNode = overlayRoot.getRootNode();\n const ShadowRootConstructor = overlayRoot.ownerDocument.defaultView?.ShadowRoot;\n if (ShadowRootConstructor && rootNode instanceof ShadowRootConstructor) {\n destroyRef.onDestroy(followModuleRootFontSize(rootNode));\n }\n};\n\nconst createTokenProviders = (overlayRootToken: ProviderToken<HTMLElement>): StaticProvider[] => {\n return [\n {\n provide: ENVIRONMENT_INITIALIZER,\n multi: true,\n useFactory: (overlayRoot: HTMLElement, destroyRef: DestroyRef) => () => followRootFontSizeOf(overlayRoot, destroyRef),\n deps: [overlayRootToken, DestroyRef],\n },\n {\n provide: OverlayContainer,\n useFactory: createOverlayContainer,\n deps: [overlayRootToken],\n },\n {\n provide: OverlayPositionBuilder,\n useFactory: createOverlayPositionBuilder,\n deps: [ViewportRuler, DOCUMENT, Platform, OverlayContainer, overlayRootToken],\n },\n ];\n};\n\nexport const provideMfOverlayRoot = (overlayRoot?: HTMLElement): StaticProvider[] => {\n if (!overlayRoot) {\n return [];\n }\n\n return [\n {\n provide: ENVIRONMENT_INITIALIZER,\n multi: true,\n useFactory: (destroyRef: DestroyRef) => () => followRootFontSizeOf(overlayRoot, destroyRef),\n deps: [DestroyRef],\n },\n {\n provide: OverlayContainer,\n useFactory: () => createOverlayContainer(overlayRoot),\n },\n {\n provide: OverlayPositionBuilder,\n useFactory: (viewportRuler: ViewportRuler, document: Document, platform: Platform, overlayContainer: OverlayContainer) => {\n return createOverlayPositionBuilder(viewportRuler, document, platform, overlayContainer, overlayRoot);\n },\n deps: [ViewportRuler, DOCUMENT, Platform, OverlayContainer],\n },\n ];\n};\n\nexport const provideMfOverlayRootFromToken = (overlayRootToken: ProviderToken<HTMLElement>): StaticProvider[] => {\n return createTokenProviders(overlayRootToken);\n};\n\nexport { CaseInsensitiveBasePathLocationStrategy, provideCaseInsensitiveBasePath } from './angular-location.js';\n"]}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export declare const MF_SCOPE_ATTRIBUTE = "data-edyn-mf";
2
2
  export declare const MF_ROOT_SELECTOR = ":mf-root";
3
3
  export * from './navigation.js';
4
+ export { followModuleRootFontSize, MF_ROOT_FONT_SIZE_PROPERTY, rewriteRemLengths } from './root-font-size.js';
4
5
  export interface IPrepareMfBoundaryOptions {
5
6
  scopeId: string;
6
7
  theme?: Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AACjD,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C,cAAc,iBAAiB,CAAC;AAIhC,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,KAAG,MAMnD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,MAEpD,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,SAAS,WAAW,EAAE,oBAAyB,yBAAyB,KAAG,CAAC,MAAM,IAAI,CA2CvH,CAAC","sourcesContent":["export const MF_SCOPE_ATTRIBUTE = 'data-edyn-mf';\nexport const MF_ROOT_SELECTOR = ':mf-root';\n\nexport * from './navigation.js';\n\nconst SCOPE_ID_PATTERN = /^[a-z][a-z0-9-]*$/;\n\nexport interface IPrepareMfBoundaryOptions {\n scopeId: string;\n theme?: Record<string, string>;\n}\n\nexport const validateMfScopeId = (scopeId: string): string => {\n if (!SCOPE_ID_PATTERN.test(scopeId)) {\n throw new Error(`Invalid microfrontend scope id: \"${scopeId}\".`);\n }\n\n return scopeId;\n};\n\nexport const getMfScopeSelector = (scopeId: string): string => {\n return `:where([${MF_SCOPE_ATTRIBUTE}=\"${validateMfScopeId(scopeId)}\"])`;\n};\n\nexport const prepareMfBoundary = (element: HTMLElement, { scopeId, theme = {} }: IPrepareMfBoundaryOptions): (() => void) => {\n validateMfScopeId(scopeId);\n\n for (const name of Object.keys(theme)) {\n if (!name.startsWith('--')) {\n throw new Error(`Microfrontend theme token must be a CSS custom property: \"${name}\".`);\n }\n }\n\n const previousScope = element.getAttribute(MF_SCOPE_ATTRIBUTE);\n const hadRootClass = element.classList.contains('edx-root');\n const previousTheme = new Map<string, { priority: string; value: string }>();\n\n element.setAttribute(MF_SCOPE_ATTRIBUTE, scopeId);\n element.classList.add('edx-root');\n\n for (const [name, value] of Object.entries(theme)) {\n previousTheme.set(name, {\n priority: element.style.getPropertyPriority(name),\n value: element.style.getPropertyValue(name),\n });\n element.style.setProperty(name, value);\n }\n\n return () => {\n if (previousScope === null) {\n element.removeAttribute(MF_SCOPE_ATTRIBUTE);\n } else {\n element.setAttribute(MF_SCOPE_ATTRIBUTE, previousScope);\n }\n\n if (!hadRootClass) {\n element.classList.remove('edx-root');\n }\n\n for (const [name, previous] of previousTheme) {\n if (previous.value) {\n element.style.setProperty(name, previous.value, previous.priority);\n } else {\n element.style.removeProperty(name);\n }\n }\n };\n};\n"]}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AACjD,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAI9G,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,KAAG,MAMnD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,MAEpD,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,SAAS,WAAW,EAAE,oBAAyB,yBAAyB,KAAG,CAAC,MAAM,IAAI,CA2CvH,CAAC","sourcesContent":["export const MF_SCOPE_ATTRIBUTE = 'data-edyn-mf';\nexport const MF_ROOT_SELECTOR = ':mf-root';\n\nexport * from './navigation.js';\nexport { followModuleRootFontSize, MF_ROOT_FONT_SIZE_PROPERTY, rewriteRemLengths } from './root-font-size.js';\n\nconst SCOPE_ID_PATTERN = /^[a-z][a-z0-9-]*$/;\n\nexport interface IPrepareMfBoundaryOptions {\n scopeId: string;\n theme?: Record<string, string>;\n}\n\nexport const validateMfScopeId = (scopeId: string): string => {\n if (!SCOPE_ID_PATTERN.test(scopeId)) {\n throw new Error(`Invalid microfrontend scope id: \"${scopeId}\".`);\n }\n\n return scopeId;\n};\n\nexport const getMfScopeSelector = (scopeId: string): string => {\n return `:where([${MF_SCOPE_ATTRIBUTE}=\"${validateMfScopeId(scopeId)}\"])`;\n};\n\nexport const prepareMfBoundary = (element: HTMLElement, { scopeId, theme = {} }: IPrepareMfBoundaryOptions): (() => void) => {\n validateMfScopeId(scopeId);\n\n for (const name of Object.keys(theme)) {\n if (!name.startsWith('--')) {\n throw new Error(`Microfrontend theme token must be a CSS custom property: \"${name}\".`);\n }\n }\n\n const previousScope = element.getAttribute(MF_SCOPE_ATTRIBUTE);\n const hadRootClass = element.classList.contains('edx-root');\n const previousTheme = new Map<string, { priority: string; value: string }>();\n\n element.setAttribute(MF_SCOPE_ATTRIBUTE, scopeId);\n element.classList.add('edx-root');\n\n for (const [name, value] of Object.entries(theme)) {\n previousTheme.set(name, {\n priority: element.style.getPropertyPriority(name),\n value: element.style.getPropertyValue(name),\n });\n element.style.setProperty(name, value);\n }\n\n return () => {\n if (previousScope === null) {\n element.removeAttribute(MF_SCOPE_ATTRIBUTE);\n } else {\n element.setAttribute(MF_SCOPE_ATTRIBUTE, previousScope);\n }\n\n if (!hadRootClass) {\n element.classList.remove('edx-root');\n }\n\n for (const [name, previous] of previousTheme) {\n if (previous.value) {\n element.style.setProperty(name, previous.value, previous.priority);\n } else {\n element.style.removeProperty(name);\n }\n }\n };\n};\n"]}
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export const MF_SCOPE_ATTRIBUTE = 'data-edyn-mf';
2
2
  export const MF_ROOT_SELECTOR = ':mf-root';
3
3
  export * from './navigation.js';
4
+ export { followModuleRootFontSize, MF_ROOT_FONT_SIZE_PROPERTY, rewriteRemLengths } from './root-font-size.js';
4
5
  const SCOPE_ID_PATTERN = /^[a-z][a-z0-9-]*$/;
5
6
  export const validateMfScopeId = (scopeId) => {
6
7
  if (!SCOPE_ID_PATTERN.test(scopeId)) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AACjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAE3C,cAAc,iBAAiB,CAAC;AAEhC,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;AAO7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAU,EAAE;IAC3D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AAmB,CAAC,IAAI,CAAC;YACjD,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC;SAC5C,CAAC,CAAC;QACH,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,GAAG,EAAE;QACV,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;YAC3B,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,YAAY,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC;QAED,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,aAAa,EAAE,CAAC;YAC7C,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;gBACnB,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACrE,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["export const MF_SCOPE_ATTRIBUTE = 'data-edyn-mf';\nexport const MF_ROOT_SELECTOR = ':mf-root';\n\nexport * from './navigation.js';\n\nconst SCOPE_ID_PATTERN = /^[a-z][a-z0-9-]*$/;\n\nexport interface IPrepareMfBoundaryOptions {\n scopeId: string;\n theme?: Record<string, string>;\n}\n\nexport const validateMfScopeId = (scopeId: string): string => {\n if (!SCOPE_ID_PATTERN.test(scopeId)) {\n throw new Error(`Invalid microfrontend scope id: \"${scopeId}\".`);\n }\n\n return scopeId;\n};\n\nexport const getMfScopeSelector = (scopeId: string): string => {\n return `:where([${MF_SCOPE_ATTRIBUTE}=\"${validateMfScopeId(scopeId)}\"])`;\n};\n\nexport const prepareMfBoundary = (element: HTMLElement, { scopeId, theme = {} }: IPrepareMfBoundaryOptions): (() => void) => {\n validateMfScopeId(scopeId);\n\n for (const name of Object.keys(theme)) {\n if (!name.startsWith('--')) {\n throw new Error(`Microfrontend theme token must be a CSS custom property: \"${name}\".`);\n }\n }\n\n const previousScope = element.getAttribute(MF_SCOPE_ATTRIBUTE);\n const hadRootClass = element.classList.contains('edx-root');\n const previousTheme = new Map<string, { priority: string; value: string }>();\n\n element.setAttribute(MF_SCOPE_ATTRIBUTE, scopeId);\n element.classList.add('edx-root');\n\n for (const [name, value] of Object.entries(theme)) {\n previousTheme.set(name, {\n priority: element.style.getPropertyPriority(name),\n value: element.style.getPropertyValue(name),\n });\n element.style.setProperty(name, value);\n }\n\n return () => {\n if (previousScope === null) {\n element.removeAttribute(MF_SCOPE_ATTRIBUTE);\n } else {\n element.setAttribute(MF_SCOPE_ATTRIBUTE, previousScope);\n }\n\n if (!hadRootClass) {\n element.classList.remove('edx-root');\n }\n\n for (const [name, previous] of previousTheme) {\n if (previous.value) {\n element.style.setProperty(name, previous.value, previous.priority);\n } else {\n element.style.removeProperty(name);\n }\n }\n };\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AACjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAE3C,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE9G,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;AAO7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAU,EAAE;IAC3D,IAAI,CAAC,gBAAgB,CAA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ACjD,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC;SAC5C,CAAC,CAAC;QACH,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,GAAG,EAAE;QACV,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;YAC3B,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,YAAY,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC;QAED,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,aAAa,EAAE,CAAC;YAC7C,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;gBACnB,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACrE,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["export const MF_SCOPE_ATTRIBUTE = 'data-edyn-mf';\nexport const MF_ROOT_SELECTOR = ':mf-root';\n\nexport * from './navigation.js';\nexport { followModuleRootFontSize, MF_ROOT_FONT_SIZE_PROPERTY, rewriteRemLengths } from './root-font-size.js';\n\nconst SCOPE_ID_PATTERN = /^[a-z][a-z0-9-]*$/;\n\nexport interface IPrepareMfBoundaryOptions {\n scopeId: string;\n theme?: Record<string, string>;\n}\n\nexport const validateMfScopeId = (scopeId: string): string => {\n if (!SCOPE_ID_PATTERN.test(scopeId)) {\n throw new Error(`Invalid microfrontend scope id: \"${scopeId}\".`);\n }\n\n return scopeId;\n};\n\nexport const getMfScopeSelector = (scopeId: string): string => {\n return `:where([${MF_SCOPE_ATTRIBUTE}=\"${validateMfScopeId(scopeId)}\"])`;\n};\n\nexport const prepareMfBoundary = (element: HTMLElement, { scopeId, theme = {} }: IPrepareMfBoundaryOptions): (() => void) => {\n validateMfScopeId(scopeId);\n\n for (const name of Object.keys(theme)) {\n if (!name.startsWith('--')) {\n throw new Error(`Microfrontend theme token must be a CSS custom property: \"${name}\".`);\n }\n }\n\n const previousScope = element.getAttribute(MF_SCOPE_ATTRIBUTE);\n const hadRootClass = element.classList.contains('edx-root');\n const previousTheme = new Map<string, { priority: string; value: string }>();\n\n element.setAttribute(MF_SCOPE_ATTRIBUTE, scopeId);\n element.classList.add('edx-root');\n\n for (const [name, value] of Object.entries(theme)) {\n previousTheme.set(name, {\n priority: element.style.getPropertyPriority(name),\n value: element.style.getPropertyValue(name),\n });\n element.style.setProperty(name, value);\n }\n\n return () => {\n if (previousScope === null) {\n element.removeAttribute(MF_SCOPE_ATTRIBUTE);\n } else {\n element.setAttribute(MF_SCOPE_ATTRIBUTE, previousScope);\n }\n\n if (!hadRootClass) {\n element.classList.remove('edx-root');\n }\n\n for (const [name, previous] of previousTheme) {\n if (previous.value) {\n element.style.setProperty(name, previous.value, previous.priority);\n } else {\n element.style.removeProperty(name);\n }\n }\n };\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"postcss.d.ts","sourceRoot":"","sources":["../src/postcss.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,MAAM,EAAwB,MAAM,SAAS,CAAC;AAKlE,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;CACjB;AA6ND,eAAO,MAAM,gCAAgC,GAAI,WAAW,MAAM,GAAG,SAAS,KAAG,OAEhF,CAAC;AA0NF,eAAO,MAAM,cAAc,GAAI,aAAa,sBAAsB,KAAG,MAWpE,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,aAAa,sBAAsB,KAAG,MAiB3E,CAAC","sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { list, type Plugin, type Root, type Rule } from 'postcss';\nimport selectorParser from 'postcss-selector-parser';\nimport valueParser from 'postcss-value-parser';\nimport { getMfScopeSelector, MF_ROOT_SELECTOR, MF_SCOPE_ATTRIBUTE, validateMfScopeId } from './index.js';\n\nexport interface IScopeRemoteCssOptions {\n scopeId: string;\n}\n\nconst ANGULAR_COMPONENT_STYLE_PATTERN = /\\.component\\.(?:css|less|sass|scss)$/i;\nconst VIEW_ENCAPSULATION_NONE_PATTERN = /(?:^|[,{])\\s*encapsulation\\s*:\\s*(?:[A-Za-z_$][\\w$]*\\s*\\.\\s*)+None\\b/m;\nconst MF_OVERLAY_ATTRIBUTE = 'data-edyn-mf-overlay';\n\ntype TTypeScriptMaskState = 'block-comment' | 'code' | 'double-quote' | 'line-comment' | 'single-quote' | 'template';\n\nconst maskTypeScriptCommentsAndStrings = (source: string): string => {\n let maskedSource = '';\n let state: TTypeScriptMaskState = 'code';\n let escaped = false;\n\n const maskCharacter = (character: string): string => {\n return character === '\\n' || character === '\\r' ? character : ' ';\n };\n\n for (let index = 0; index < source.length; index += 1) {\n const character = source[index] ?? '';\n const nextCharacter = source[index + 1];\n\n if (state === 'code') {\n if (character === '/' && nextCharacter === '/') {\n maskedSource += ' ';\n index += 1;\n state = 'line-comment';\n } else if (character === '/' && nextCharacter === '*') {\n maskedSource += ' ';\n index += 1;\n state = 'block-comment';\n } else if (character === \"'\") {\n maskedSource += ' ';\n state = 'single-quote';\n } else if (character === '\"') {\n maskedSource += ' ';\n state = 'double-quote';\n } else if (character === '`') {\n maskedSource += ' ';\n state = 'template';\n } else {\n maskedSource += character;\n }\n continue;\n }\n\n if (state === 'line-comment') {\n maskedSource += maskCharacter(character);\n if (character === '\\n' || character === '\\r') {\n state = 'code';\n }\n continue;\n }\n\n if (state === 'block-comment') {\n if (character === '*' && nextCharacter === '/') {\n maskedSource += ' ';\n index += 1;\n state = 'code';\n } else {\n maskedSource += maskCharacter(character);\n }\n continue;\n }\n\n maskedSource += maskCharacter(character);\n if (escaped) {\n escaped = false;\n } else if (character === '\\\\') {\n escaped = true;\n } else if (\n (state === 'single-quote' && character === \"'\") ||\n (state === 'double-quote' && character === '\"') ||\n (state === 'template' && character === '`')\n ) {\n state = 'code';\n }\n }\n\n return maskedSource;\n};\n\nconst isKeyframesRule = (rule: Rule): boolean => {\n const parent = rule.parent;\n return parent?.type === 'atrule' && /keyframes$/i.test(parent.name);\n};\n\nconst isRootNode = (node: selectorParser.Node): boolean => {\n return (\n (node.type === 'tag' && (node.value.toLowerCase() === 'html' || node.value.toLowerCase() === 'body')) ||\n (node.type === 'pseudo' && (node.value === ':root' || node.value === MF_ROOT_SELECTOR))\n );\n};\n\nconst isScopeNode = (node: selectorParser.Node | undefined, scopeId: string): boolean => {\n if (node?.type === 'attribute' && node.attribute === MF_SCOPE_ATTRIBUTE && node.operator === '=' && node.value === scopeId) {\n return true;\n }\n\n // A rooted boundary written by rootedDescendantScope(): :is(<scope>, <specificity carrier>).\n if (node?.type === 'pseudo' && node.value === ':is' && node.nodes[0]?.nodes.length === 1 && isScopeNode(node.nodes[0].first, scopeId)) {\n return true;\n }\n\n const normalized = node?.toString().replaceAll('\"', '').replaceAll(\"'\", '');\n return (\n node?.type === 'pseudo' &&\n (normalized === `:where([${MF_SCOPE_ATTRIBUTE}=${scopeId}])` ||\n normalized === `:where([${MF_SCOPE_ATTRIBUTE}=${scopeId}]:not([${MF_OVERLAY_ATTRIBUTE}]))`)\n );\n};\n\nconst startsWithHostPseudo = (selector: selectorParser.Selector): boolean => {\n return selector.first?.type === 'pseudo' && selector.first.value === ':host';\n};\n\nconst removeRootIdentityIds = (selector: selectorParser.Selector): void => {\n let compound: selectorParser.Node[] = [];\n const removeIdsFromRootCompound = (): void => {\n if (compound.some(isRootNode)) {\n for (const node of compound) {\n if (node.type === 'id') {\n node.remove();\n }\n }\n }\n };\n\n for (const node of [...selector.nodes]) {\n if (node.type === 'combinator') {\n removeIdsFromRootCompound();\n compound = [];\n } else {\n compound.push(node);\n }\n }\n removeIdsFromRootCompound();\n};\n\nconst SPECIFICITY_CARRIER = 'edyn-mf-root';\n\n// Legacy overrides such as `html body#app .mdc-checkbox__background` won over Angular Material's own rules through the\n// id and types of the document root they start from. Replacing that root with the scope attribute alone drops the id,\n// so Material wins again. This carrier has the same id, class and type counts as the root part it replaces; inside\n// :is(<scope>, <carrier>) it never matches (`:not(*)`), and :is() takes its strongest argument's specificity. Only roots\n// with an id need it: without one the scope attribute already outweighs them. Neutral names keep `html`, `body` and\n// `#app` out of the emitted CSS.\nconst rootSpecificityCarrier = (selector: selectorParser.Selector): string | undefined => {\n const compounds: selectorParser.Node[][] = [[]];\n for (const node of selector.nodes) {\n if (node.type === 'combinator') {\n compounds.push([]);\n } else {\n compounds.at(-1)?.push(node);\n }\n }\n\n let ids = 0;\n const carrier: string[] = [];\n for (const compound of compounds) {\n if (!compound.some(isRootNode)) {\n continue;\n }\n const types = compound.filter((node) => node.type === 'tag' && isRootNode(node)).length;\n const pseudoRoots = compound.filter((node) => node.type === 'pseudo' && isRootNode(node)).length;\n const compoundIds = compound.filter((node) => node.type === 'id').length;\n ids += compoundIds;\n carrier.push(\n `${SPECIFICITY_CARRIER.repeat(Math.min(types, 1))}${`.${SPECIFICITY_CARRIER}`.repeat(pseudoRoots)}${`#${SPECIFICITY_CARRIER}`.repeat(compoundIds)}`,\n );\n }\n\n return ids > 0 ? `${carrier.filter(Boolean).join(' ')}:not(*)` : undefined;\n};\n\nconst rootedDescendantScope = (selector: selectorParser.Selector, scopeId: string): string => {\n const scope = `[${MF_SCOPE_ATTRIBUTE}=\"${scopeId}\"]`;\n const carrier = rootSpecificityCarrier(selector);\n return carrier ? `:is(${scope}, ${carrier})` : scope;\n};\n\nconst isRootOnlySelector = (selector: selectorParser.Selector): boolean => {\n const compounds: selectorParser.Node[][] = [[]];\n\n for (const node of selector.nodes) {\n if (node.type === 'combinator') {\n compounds.push([]);\n } else {\n compounds.at(-1)?.push(node);\n }\n }\n\n return compounds.every((compound) => compound.some(isRootNode));\n};\n\nconst hasRootOnlySelector = (selectorList: string): boolean => {\n let result = false;\n selectorParser((root) => {\n result = root.nodes.some(isRootOnlySelector);\n }).processSync(selectorList);\n return result;\n};\n\nconst getAngularComponentSourcePath = (stylePath: string): string | undefined => {\n const cleanStylePath = stylePath.replace(/[?#].*$/, '');\n if (!ANGULAR_COMPONENT_STYLE_PATTERN.test(cleanStylePath)) {\n return undefined;\n }\n\n return cleanStylePath.replace(/\\.(?:css|less|sass|scss)$/i, '.ts');\n};\n\nconst usesViewEncapsulationNone = (stylePath: string): boolean => {\n const componentSourcePath = getAngularComponentSourcePath(stylePath);\n if (!componentSourcePath || !existsSync(componentSourcePath)) {\n return false;\n }\n\n const componentSource = readFileSync(componentSourcePath, 'utf8');\n return VIEW_ENCAPSULATION_NONE_PATTERN.test(maskTypeScriptCommentsAndStrings(componentSource));\n};\n\nexport const shouldUseAngularComponentScoping = (stylePath: string | undefined): boolean => {\n return !!stylePath && !!getAngularComponentSourcePath(stylePath) && !usesViewEncapsulationNone(stylePath);\n};\n\nconst scopeSelectorList = (selectorList: string, scopeId: string, scopeSelector: string, rootScopeSelectors: string[]): string => {\n return selectorParser((root) => {\n const sourceSelectors = [...root.nodes];\n\n for (const selector of sourceSelectors) {\n const rootNodes = selector.nodes.filter(isRootNode);\n\n if (rootNodes.length > 0) {\n const replacementSelectors = isRootOnlySelector(selector) ? rootScopeSelectors : [rootedDescendantScope(selector, scopeId)];\n\n for (const replacementSelector of replacementSelectors) {\n const variant = selector.clone();\n removeRootIdentityIds(variant);\n const [firstRoot, ...duplicateRoots] = variant.nodes.filter(isRootNode);\n const scopeNode = selectorParser().astSync(replacementSelector).first.first.clone();\n firstRoot?.replaceWith(scopeNode);\n\n for (const duplicateRoot of duplicateRoots) {\n const previous = duplicateRoot.prev();\n if (previous?.type === 'combinator') {\n previous.remove();\n }\n duplicateRoot.remove();\n }\n\n root.insertBefore(selector, variant);\n }\n selector.remove();\n continue;\n }\n\n if (startsWithHostPseudo(selector) || isScopeNode(selector.first, scopeId)) {\n continue;\n }\n\n const first = selector.first;\n const needsBoundaryVariant = first?.type === 'universal' || (first?.type === 'pseudo' && first.value.startsWith('::'));\n\n if (needsBoundaryVariant) {\n const hasSiblingCombinator = selector.nodes.some((node) => node.type === 'combinator' && (node.value === '+' || node.value === '~'));\n\n if (!hasSiblingCombinator) {\n const boundaryVariant = selector.clone();\n const boundaryScope = selectorParser().astSync(scopeSelector).first.first.clone();\n boundaryVariant.first.rawSpaceBefore = '';\n if (boundaryVariant.first.type === 'universal') {\n boundaryVariant.first.replaceWith(boundaryScope);\n } else {\n boundaryVariant.prepend(boundaryScope);\n }\n root.insertBefore(selector, boundaryVariant);\n }\n }\n\n const descendantScope = selectorParser().astSync(`${scopeSelector} *`).first;\n const prefixNodes = descendantScope.nodes.slice(0, -1).map((node) => node.clone());\n selector.first.rawSpaceBefore = '';\n for (const prefixNode of prefixNodes.reverse()) {\n selector.prepend(prefixNode);\n }\n }\n\n const seenSelectors = new Set<string>();\n for (const selector of [...root.nodes]) {\n const normalizedSelector = selector.toString().trim();\n if (seenSelectors.has(normalizedSelector)) {\n selector.remove();\n } else {\n seenSelectors.add(normalizedSelector);\n }\n }\n }).processSync(selectorList);\n};\n\nconst findFunctionalPseudoEnd = (selector: string, openParenthesisIndex: number): number => {\n let depth = 0;\n let quote: '\"' | \"'\" | undefined;\n\n for (let index = openParenthesisIndex; index < selector.length; index += 1) {\n const character = selector[index];\n const previousCharacter = selector[index - 1];\n\n if (quote) {\n if (character === quote && previousCharacter !== '\\\\') {\n quote = undefined;\n }\n continue;\n }\n\n if (character === '\"' || character === \"'\") {\n quote = character;\n continue;\n }\n\n if (character === '(') {\n depth += 1;\n } else if (character === ')') {\n depth -= 1;\n if (depth === 0) {\n return index;\n }\n }\n }\n\n return -1;\n};\n\nconst scopeAngularSelector = (selector: string, boundarySelector: string): string => {\n const normalizedSelector = selector.trim();\n const angularBoundary = `:host-context(${boundarySelector})`;\n const normalizedBoundary = normalizedSelector.slice(0, angularBoundary.length).replaceAll(\"'\", '\"');\n\n if (normalizedBoundary === angularBoundary) {\n return normalizedSelector;\n }\n\n if (/^:host-context\\(/i.test(normalizedSelector)) {\n return `${angularBoundary}${normalizedSelector}`;\n }\n\n if (/^:host\\(/i.test(normalizedSelector)) {\n const openParenthesisIndex = normalizedSelector.indexOf('(');\n const closeParenthesisIndex = findFunctionalPseudoEnd(normalizedSelector, openParenthesisIndex);\n if (closeParenthesisIndex !== -1) {\n const hostSelector = normalizedSelector.slice(openParenthesisIndex + 1, closeParenthesisIndex);\n const remainder = normalizedSelector.slice(closeParenthesisIndex + 1);\n return list\n .comma(hostSelector)\n .map((hostSelectorVariant) => `${angularBoundary}${hostSelectorVariant}${remainder}`)\n .join(', ');\n }\n }\n\n if (/^:host\\b/i.test(normalizedSelector)) {\n return normalizedSelector.replace(/^:host\\b/i, angularBoundary);\n }\n\n return `${angularBoundary} ${normalizedSelector}`;\n};\n\nconst scopeAngularSelectorList = (selectorList: string, boundarySelector: string): string => {\n return list\n .comma(selectorList)\n .map((selector) => scopeAngularSelector(selector, boundarySelector))\n .join(', ');\n};\n\nconst namespaceKeyframes = (root: Root, keyframePrefix: string): void => {\n const keyframes = new Map<string, string>();\n\n root.walkAtRules((atRule) => {\n if (!/keyframes$/i.test(atRule.name) || atRule.params.startsWith(keyframePrefix)) {\n return;\n }\n\n const originalName = atRule.params.trim();\n const scopedName = `${keyframePrefix}${originalName}`;\n keyframes.set(originalName, scopedName);\n atRule.params = scopedName;\n });\n\n root.walkDecls((declaration) => {\n if (!/^(?:-webkit-)?animation(?:-name)?$/i.test(declaration.prop) && !declaration.prop.startsWith('--animate-')) {\n return;\n }\n\n const parsed = valueParser(declaration.value);\n parsed.walk((node) => {\n if (node.type === 'word') {\n node.value = keyframes.get(node.value) ?? node.value;\n }\n });\n declaration.value = parsed.toString();\n });\n};\n\nconst scopeGlobalRoot = (root: Root, scopeId: string, scopeSelector: string, keyframePrefix: string): void => {\n namespaceKeyframes(root, keyframePrefix);\n const contentRootSelector = `:where([${MF_SCOPE_ATTRIBUTE}=\"${scopeId}\"]:not([${MF_OVERLAY_ATTRIBUTE}]))`;\n root.walkRules((rule) => {\n if (!isKeyframesRule(rule)) {\n const declarations = rule.nodes.filter((node) => node.type === 'decl');\n const customProperties = declarations.filter((declaration) => declaration.prop.startsWith('--'));\n const standardDeclarations = declarations.filter((declaration) => !declaration.prop.startsWith('--'));\n\n if (customProperties.length > 0 && standardDeclarations.length > 0 && hasRootOnlySelector(rule.selector)) {\n const customPropertyRule = rule.cloneBefore();\n customPropertyRule.walkDecls((declaration) => {\n if (!declaration.prop.startsWith('--')) {\n declaration.remove();\n }\n });\n customPropertyRule.selector = scopeSelectorList(customPropertyRule.selector, scopeId, scopeSelector, [':host', scopeSelector]);\n rule.walkDecls((declaration) => {\n if (declaration.prop.startsWith('--')) {\n declaration.remove();\n }\n });\n }\n\n const containsOnlyCustomProperties = declarations.length > 0 && declarations.every((declaration) => declaration.prop.startsWith('--'));\n const rootScopeSelectors = containsOnlyCustomProperties ? [':host', scopeSelector] : [':host', contentRootSelector];\n rule.selector = scopeSelectorList(rule.selector, scopeId, scopeSelector, rootScopeSelectors);\n }\n });\n};\n\nconst scopeAngularComponentRoot = (root: Root, boundarySelector: string, keyframePrefix: string): void => {\n namespaceKeyframes(root, keyframePrefix);\n root.walkRules((rule) => {\n if (!isKeyframesRule(rule)) {\n rule.selector = scopeAngularSelectorList(rule.selector, boundarySelector);\n }\n });\n};\n\nexport const scopeRemoteCss = ({ scopeId }: IScopeRemoteCssOptions): Plugin => {\n const validScopeId = validateMfScopeId(scopeId);\n const scopeSelector = getMfScopeSelector(validScopeId);\n const keyframePrefix = `edyn-mf-${validScopeId}--`;\n\n return {\n postcssPlugin: `edyn-mf-isolation-${validScopeId}`,\n Once(root) {\n scopeGlobalRoot(root, validScopeId, scopeSelector, keyframePrefix);\n },\n };\n};\n\nexport const scopeAngularRemoteCss = ({ scopeId }: IScopeRemoteCssOptions): Plugin => {\n const validScopeId = validateMfScopeId(scopeId);\n const scopeSelector = getMfScopeSelector(validScopeId);\n const boundarySelector = `[${MF_SCOPE_ATTRIBUTE}=\"${validScopeId}\"]`;\n const keyframePrefix = `edyn-mf-${validScopeId}--`;\n\n return {\n postcssPlugin: `edyn-mf-angular-isolation-${validScopeId}`,\n Once(root) {\n if (shouldUseAngularComponentScoping(root.source?.input.file)) {\n scopeAngularComponentRoot(root, boundarySelector, keyframePrefix);\n return;\n }\n\n scopeGlobalRoot(root, validScopeId, scopeSelector, keyframePrefix);\n },\n };\n};\n"]}
1
+ {"version":3,"file":"postcss.d.ts","sourceRoot":"","sources":["../src/postcss.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,KAAK,MAAM,EAAwB,MAAM,SAAS,CAAC;AAMpF,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;CACjB;AAqND,eAAO,MAAM,gCAAgC,GAAI,WAAW,MAAM,GAAG,SAAS,KAAG,OAEhF,CAAC;AAiYF,eAAO,MAAM,cAAc,GAAI,aAAa,sBAAsB,KAAG,MAWpE,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,aAAa,sBAAsB,KAAG,MAiB3E,CAAC","sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { type Declaration, list, type Plugin, type Root, type Rule } from 'postcss';\nimport selectorParser from 'postcss-selector-parser';\nimport valueParser from 'postcss-value-parser';\nimport { getMfScopeSelector, MF_ROOT_SELECTOR, MF_SCOPE_ATTRIBUTE, validateMfScopeId } from './index.js';\nimport { MF_ROOT_FONT_SIZE_PROPERTY } from './root-font-size.js';\n\nexport interface IScopeRemoteCssOptions {\n scopeId: string;\n}\n\nconst ANGULAR_COMPONENT_STYLE_PATTERN = /\\.component\\.(?:css|less|sass|scss)$/i;\nconst VIEW_ENCAPSULATION_NONE_PATTERN = /(?:^|[,{])\\s*encapsulation\\s*:\\s*(?:[A-Za-z_$][\\w$]*\\s*\\.\\s*)+None\\b/m;\nconst MF_OVERLAY_ATTRIBUTE = 'data-edyn-mf-overlay';\n\ntype TTypeScriptMaskState = 'block-comment' | 'code' | 'double-quote' | 'line-comment' | 'single-quote' | 'template';\n\nconst maskTypeScriptCommentsAndStrings = (source: string): string => {\n let maskedSource = '';\n let state: TTypeScriptMaskState = 'code';\n let escaped = false;\n\n const maskCharacter = (character: string): string => {\n return character === '\\n' || character === '\\r' ? character : ' ';\n };\n\n for (let index = 0; index < source.length; index += 1) {\n const character = source[index] ?? '';\n const nextCharacter = source[index + 1];\n\n if (state === 'code') {\n if (character === '/' && nextCharacter === '/') {\n maskedSource += ' ';\n index += 1;\n state = 'line-comment';\n } else if (character === '/' && nextCharacter === '*') {\n maskedSource += ' ';\n index += 1;\n state = 'block-comment';\n } else if (character === \"'\") {\n maskedSource += ' ';\n state = 'single-quote';\n } else if (character === '\"') {\n maskedSource += ' ';\n state = 'double-quote';\n } else if (character === '`') {\n maskedSource += ' ';\n state = 'template';\n } else {\n maskedSource += character;\n }\n continue;\n }\n\n if (state === 'line-comment') {\n maskedSource += maskCharacter(character);\n if (character === '\\n' || character === '\\r') {\n state = 'code';\n }\n continue;\n }\n\n if (state === 'block-comment') {\n if (character === '*' && nextCharacter === '/') {\n maskedSource += ' ';\n index += 1;\n state = 'code';\n } else {\n maskedSource += maskCharacter(character);\n }\n continue;\n }\n\n maskedSource += maskCharacter(character);\n if (escaped) {\n escaped = false;\n } else if (character === '\\\\') {\n escaped = true;\n } else if (\n (state === 'single-quote' && character === \"'\") ||\n (state === 'double-quote' && character === '\"') ||\n (state === 'template' && character === '`')\n ) {\n state = 'code';\n }\n }\n\n return maskedSource;\n};\n\nconst isKeyframesRule = (rule: Rule): boolean => {\n const parent = rule.parent;\n return parent?.type === 'atrule' && /keyframes$/i.test(parent.name);\n};\n\nconst isRootNode = (node: selectorParser.Node): boolean => {\n return (\n (node.type === 'tag' && (node.value.toLowerCase() === 'html' || node.value.toLowerCase() === 'body')) ||\n (node.type === 'pseudo' && (node.value === ':root' || node.value === MF_ROOT_SELECTOR))\n );\n};\n\nconst isScopeNode = (node: selectorParser.Node | undefined, scopeId: string): boolean => {\n if (node?.type === 'attribute' && node.attribute === MF_SCOPE_ATTRIBUTE && node.operator === '=' && node.value === scopeId) {\n return true;\n }\n\n const normalized = node?.toString().replaceAll('\"', '').replaceAll(\"'\", '');\n return (\n node?.type === 'pseudo' &&\n (normalized === `:where([${MF_SCOPE_ATTRIBUTE}=${scopeId}])` ||\n normalized === `:where([${MF_SCOPE_ATTRIBUTE}=${scopeId}]:not([${MF_OVERLAY_ATTRIBUTE}]))`)\n );\n};\n\nconst startsWithHostPseudo = (selector: selectorParser.Selector): boolean => {\n return selector.first?.type === 'pseudo' && selector.first.value === ':host';\n};\n\nconst removeRootIdentityIds = (selector: selectorParser.Selector): void => {\n let compound: selectorParser.Node[] = [];\n const removeIdsFromRootCompound = (): void => {\n if (compound.some(isRootNode)) {\n for (const node of compound) {\n if (node.type === 'id') {\n node.remove();\n }\n }\n }\n };\n\n for (const node of [...selector.nodes]) {\n if (node.type === 'combinator') {\n removeIdsFromRootCompound();\n compound = [];\n } else {\n compound.push(node);\n }\n }\n removeIdsFromRootCompound();\n};\n\nconst SPECIFICITY_CARRIER = 'edyn-mf-root';\n\n// Legacy rules such as `html body button` or `html body#app .mdc-checkbox__background` are weighed against Angular\n// Material's own rules by the html, body and #app they start from, so the scope that replaces that root must weigh\n// exactly the same. A plain scope attribute (0,1,0) drops the id of `body#app`, letting Material's checked colour win,\n// and outweighs the two types of `html body`, letting an override that lost to `.mat-mdc-button` on the old site win\n// hosted. The root becomes :where(<scope>):not(<carrier>): :where() weighs nothing, and the carrier has the same id,\n// class and type counts as the root part it replaces and never matches the scope element, so :not() always matches and\n// weighs exactly that. Neutral names keep `html`, `body` and `#app` out of the emitted CSS.\nconst rootSpecificityCarrier = (selector: selectorParser.Selector): string => {\n const compounds: selectorParser.Node[][] = [[]];\n for (const node of selector.nodes) {\n if (node.type === 'combinator') {\n compounds.push([]);\n } else {\n compounds.at(-1)?.push(node);\n }\n }\n\n const carrier: string[] = [];\n for (const compound of compounds) {\n if (!compound.some(isRootNode)) {\n continue;\n }\n const types = compound.filter((node) => node.type === 'tag' && isRootNode(node)).length;\n const pseudoRoots = compound.filter((node) => node.type === 'pseudo' && isRootNode(node)).length;\n const ids = compound.filter((node) => node.type === 'id').length;\n carrier.push(\n `${SPECIFICITY_CARRIER.repeat(Math.min(types, 1))}${`.${SPECIFICITY_CARRIER}`.repeat(pseudoRoots)}${`#${SPECIFICITY_CARRIER}`.repeat(ids)}`,\n );\n }\n\n return carrier.filter(Boolean).join(' ');\n};\n\nconst rootedDescendantScope = (selector: selectorParser.Selector, scopeId: string): string => {\n return `:where([${MF_SCOPE_ATTRIBUTE}=\"${scopeId}\"]):not(${rootSpecificityCarrier(selector)})`;\n};\n\nconst isRootOnlySelector = (selector: selectorParser.Selector): boolean => {\n const compounds: selectorParser.Node[][] = [[]];\n\n for (const node of selector.nodes) {\n if (node.type === 'combinator') {\n compounds.push([]);\n } else {\n compounds.at(-1)?.push(node);\n }\n }\n\n return compounds.every((compound) => compound.some(isRootNode));\n};\n\nconst hasRootOnlySelector = (selectorList: string): boolean => {\n let result = false;\n selectorParser((root) => {\n result = root.nodes.some(isRootOnlySelector);\n }).processSync(selectorList);\n return result;\n};\n\nconst getAngularComponentSourcePath = (stylePath: string): string | undefined => {\n const cleanStylePath = stylePath.replace(/[?#].*$/, '');\n if (!ANGULAR_COMPONENT_STYLE_PATTERN.test(cleanStylePath)) {\n return undefined;\n }\n\n return cleanStylePath.replace(/\\.(?:css|less|sass|scss)$/i, '.ts');\n};\n\nconst usesViewEncapsulationNone = (stylePath: string): boolean => {\n const componentSourcePath = getAngularComponentSourcePath(stylePath);\n if (!componentSourcePath || !existsSync(componentSourcePath)) {\n return false;\n }\n\n const componentSource = readFileSync(componentSourcePath, 'utf8');\n return VIEW_ENCAPSULATION_NONE_PATTERN.test(maskTypeScriptCommentsAndStrings(componentSource));\n};\n\nexport const shouldUseAngularComponentScoping = (stylePath: string | undefined): boolean => {\n return !!stylePath && !!getAngularComponentSourcePath(stylePath) && !usesViewEncapsulationNone(stylePath);\n};\n\nconst scopeSelectorList = (selectorList: string, scopeId: string, scopeSelector: string, rootScopeSelectors: string[]): string => {\n return selectorParser((root) => {\n const sourceSelectors = [...root.nodes];\n\n for (const selector of sourceSelectors) {\n const rootNodes = selector.nodes.filter(isRootNode);\n\n if (rootNodes.length > 0) {\n const replacementSelectors = isRootOnlySelector(selector) ? rootScopeSelectors : [rootedDescendantScope(selector, scopeId)];\n\n for (const replacementSelector of replacementSelectors) {\n const variant = selector.clone();\n removeRootIdentityIds(variant);\n const [firstRoot, ...duplicateRoots] = variant.nodes.filter(isRootNode);\n // The replacement can be a compound of several nodes, e.g. :where(<scope>):not(<carrier>).\n const scopeNodes = selectorParser()\n .astSync(replacementSelector)\n .first.nodes.map((node) => node.clone());\n const [scopeNode, ...followingScopeNodes] = scopeNodes;\n if (firstRoot && scopeNode) {\n firstRoot.replaceWith(scopeNode);\n let previous = scopeNode;\n for (const node of followingScopeNodes) {\n variant.insertAfter(previous, node);\n previous = node;\n }\n }\n\n for (const duplicateRoot of duplicateRoots) {\n const previous = duplicateRoot.prev();\n if (previous?.type === 'combinator') {\n previous.remove();\n }\n duplicateRoot.remove();\n }\n\n root.insertBefore(selector, variant);\n }\n selector.remove();\n continue;\n }\n\n if (startsWithHostPseudo(selector) || isScopeNode(selector.first, scopeId)) {\n continue;\n }\n\n const first = selector.first;\n const needsBoundaryVariant = first?.type === 'universal' || (first?.type === 'pseudo' && first.value.startsWith('::'));\n\n if (needsBoundaryVariant) {\n const hasSiblingCombinator = selector.nodes.some((node) => node.type === 'combinator' && (node.value === '+' || node.value === '~'));\n\n if (!hasSiblingCombinator) {\n const boundaryVariant = selector.clone();\n const boundaryScope = selectorParser().astSync(scopeSelector).first.first.clone();\n boundaryVariant.first.rawSpaceBefore = '';\n if (boundaryVariant.first.type === 'universal') {\n boundaryVariant.first.replaceWith(boundaryScope);\n } else {\n boundaryVariant.prepend(boundaryScope);\n }\n root.insertBefore(selector, boundaryVariant);\n }\n }\n\n const descendantScope = selectorParser().astSync(`${scopeSelector} *`).first;\n const prefixNodes = descendantScope.nodes.slice(0, -1).map((node) => node.clone());\n selector.first.rawSpaceBefore = '';\n for (const prefixNode of prefixNodes.reverse()) {\n selector.prepend(prefixNode);\n }\n }\n\n const seenSelectors = new Set<string>();\n for (const selector of [...root.nodes]) {\n const normalizedSelector = selector.toString().trim();\n if (seenSelectors.has(normalizedSelector)) {\n selector.remove();\n } else {\n seenSelectors.add(normalizedSelector);\n }\n }\n }).processSync(selectorList);\n};\n\nconst findFunctionalPseudoEnd = (selector: string, openParenthesisIndex: number): number => {\n let depth = 0;\n let quote: '\"' | \"'\" | undefined;\n\n for (let index = openParenthesisIndex; index < selector.length; index += 1) {\n const character = selector[index];\n const previousCharacter = selector[index - 1];\n\n if (quote) {\n if (character === quote && previousCharacter !== '\\\\') {\n quote = undefined;\n }\n continue;\n }\n\n if (character === '\"' || character === \"'\") {\n quote = character;\n continue;\n }\n\n if (character === '(') {\n depth += 1;\n } else if (character === ')') {\n depth -= 1;\n if (depth === 0) {\n return index;\n }\n }\n }\n\n return -1;\n};\n\nconst scopeAngularSelector = (selector: string, boundarySelector: string): string => {\n const normalizedSelector = selector.trim();\n const angularBoundary = `:host-context(${boundarySelector})`;\n const normalizedBoundary = normalizedSelector.slice(0, angularBoundary.length).replaceAll(\"'\", '\"');\n\n if (normalizedBoundary === angularBoundary) {\n return normalizedSelector;\n }\n\n if (/^:host-context\\(/i.test(normalizedSelector)) {\n return `${angularBoundary}${normalizedSelector}`;\n }\n\n if (/^:host\\(/i.test(normalizedSelector)) {\n const openParenthesisIndex = normalizedSelector.indexOf('(');\n const closeParenthesisIndex = findFunctionalPseudoEnd(normalizedSelector, openParenthesisIndex);\n if (closeParenthesisIndex !== -1) {\n const hostSelector = normalizedSelector.slice(openParenthesisIndex + 1, closeParenthesisIndex);\n const remainder = normalizedSelector.slice(closeParenthesisIndex + 1);\n return list\n .comma(hostSelector)\n .map((hostSelectorVariant) => `${angularBoundary}${hostSelectorVariant}${remainder}`)\n .join(', ');\n }\n }\n\n if (/^:host\\b/i.test(normalizedSelector)) {\n return normalizedSelector.replace(/^:host\\b/i, angularBoundary);\n }\n\n return `${angularBoundary} ${normalizedSelector}`;\n};\n\nconst scopeAngularSelectorList = (selectorList: string, boundarySelector: string): string => {\n return list\n .comma(selectorList)\n .map((selector) => scopeAngularSelector(selector, boundarySelector))\n .join(', ');\n};\n\nconst namespaceKeyframes = (root: Root, keyframePrefix: string): void => {\n const keyframes = new Map<string, string>();\n\n root.walkAtRules((atRule) => {\n if (!/keyframes$/i.test(atRule.name) || atRule.params.startsWith(keyframePrefix)) {\n return;\n }\n\n const originalName = atRule.params.trim();\n const scopedName = `${keyframePrefix}${originalName}`;\n keyframes.set(originalName, scopedName);\n atRule.params = scopedName;\n });\n\n root.walkDecls((declaration) => {\n if (!/^(?:-webkit-)?animation(?:-name)?$/i.test(declaration.prop) && !declaration.prop.startsWith('--animate-')) {\n return;\n }\n\n const parsed = valueParser(declaration.value);\n parsed.walk((node) => {\n if (node.type === 'word') {\n node.value = keyframes.get(node.value) ?? node.value;\n }\n });\n declaration.value = parsed.toString();\n });\n};\n\nconst INITIAL_FONT_SIZE_PX = 16;\n// Absolute-size keywords as browsers compute them, and the relative ones as they resolve on the root, whose parent size\n// is the initial 16px.\nconst FONT_SIZE_KEYWORDS_PX: Readonly<Record<string, number>> = {\n 'xx-small': 9,\n 'x-small': 10,\n small: 13,\n medium: 16,\n large: 18,\n 'x-large': 24,\n 'xx-large': 32,\n 'xxx-large': 48,\n smaller: INITIAL_FONT_SIZE_PX / 1.2,\n larger: INITIAL_FONT_SIZE_PX * 1.2,\n};\n// On the root, every global keyword gives the initial size.\nconst GLOBAL_KEYWORDS = new Set(['inherit', 'initial', 'revert', 'revert-layer', 'unset']);\n// em, rem and % on the root are relative to the initial size.\nconst FONT_SIZE_UNITS_PX: Readonly<Record<string, number>> = {\n '%': INITIAL_FONT_SIZE_PX / 100,\n cm: 96 / 2.54,\n em: INITIAL_FONT_SIZE_PX,\n in: 96,\n mm: 96 / 25.4,\n pc: 16,\n pt: 96 / 72,\n px: 1,\n q: 96 / 101.6,\n rem: INITIAL_FONT_SIZE_PX,\n};\n\nconst fontSizeOfWord = (word: string): number | undefined => {\n const keyword = FONT_SIZE_KEYWORDS_PX[word.toLowerCase()];\n if (keyword !== undefined) {\n return keyword;\n }\n const dimension = valueParser.unit(word);\n const unitPx = dimension ? FONT_SIZE_UNITS_PX[dimension.unit.toLowerCase()] : undefined;\n const amount = Number(dimension ? dimension.number : Number.NaN);\n return unitPx !== undefined && Number.isFinite(amount) && amount >= 0 ? amount * unitPx : undefined;\n};\n\nconst significantValueNodes = (value: string): valueParser.Node[] => {\n return valueParser(value).nodes.filter((node) => node.type !== 'space' && node.type !== 'comment');\n};\n\nconst globalKeywordFontSize = (nodes: valueParser.Node[]): number | undefined => {\n const [only] = nodes;\n return nodes.length === 1 && only?.type === 'word' && GLOBAL_KEYWORDS.has(only.value.toLowerCase()) ? INITIAL_FONT_SIZE_PX : undefined;\n};\n\nconst resolveFontSize = (value: string): number | undefined => {\n const nodes = significantValueNodes(value);\n const [only] = nodes;\n return globalKeywordFontSize(nodes) ?? (nodes.length === 1 && only?.type === 'word' ? fontSizeOfWord(only.value) : undefined);\n};\n\n// `font: [style] [variant] [weight] [stretch] <size>[/<line-height>] <family>`: the size is the word before `/`, or else\n// the first word that is a size. A function (var(), calc()) or a family name reached first means it cannot be read.\nconst resolveFontShorthandSize = (value: string): number | undefined => {\n const nodes = significantValueNodes(value);\n const globalSize = globalKeywordFontSize(nodes);\n if (globalSize !== undefined) {\n return globalSize;\n }\n\n const slashIndex = nodes.findIndex((node) => node.type === 'div' && node.value === '/');\n if (slashIndex > 0) {\n const size = nodes[slashIndex - 1];\n return size?.type === 'word' ? fontSizeOfWord(size.value) : undefined;\n }\n\n for (const node of nodes) {\n if (node.type !== 'word') {\n return undefined;\n }\n const size = fontSizeOfWord(node.value);\n if (size !== undefined) {\n return size;\n }\n }\n return undefined;\n};\n\n// `html` and `:root` size the document root, so rem; `body` and `html body` size only the body.\nconst targetsDocumentRoot = (selector: selectorParser.Selector): boolean => {\n let subject: selectorParser.Node[] = [];\n for (const node of selector.nodes) {\n subject = node.type === 'combinator' ? [] : [...subject, node];\n }\n return subject.some((node) => (node.type === 'tag' && node.value.toLowerCase() === 'html') || (node.type === 'pseudo' && node.value === ':root'));\n};\n\nconst documentRootSelectorsOf = (selectorList: string): string[] => {\n const selectors: string[] = [];\n selectorParser((root) => {\n for (const selector of root.nodes) {\n if (targetsDocumentRoot(selector)) {\n selectors.push(selector.toString().trim());\n }\n }\n }).processSync(selectorList);\n return selectors;\n};\n\ntype TWarn = (node: Declaration, text: string) => void;\n\n// Hosted, rem resolves against the host page's root, not the root size the module's own page set. Each rule that sizes\n// the document root gets a sibling rule right after it that records that size as MF_ROOT_FONT_SIZE_PROPERTY, under the\n// same conditions (@media, importance) and in the same cascade order; scoping then moves it onto the module boundary,\n// where followModuleRootFontSize() makes rem lengths read it. CSS that never sizes the root is left byte-identical.\nconst recordRootFontSize = (root: Root, warn: TWarn): void => {\n root.walkRules((rule) => {\n if (isKeyframesRule(rule)) {\n return;\n }\n\n let sizing: Declaration | undefined;\n for (const node of rule.nodes) {\n if (node.type === 'decl' && /^font(?:-size)?$/i.test(node.prop) && (node.important || !sizing?.important)) {\n sizing = node;\n }\n }\n if (!sizing) {\n return;\n }\n\n const rootSelectors = documentRootSelectorsOf(rule.selector);\n if (rootSelectors.length === 0) {\n return;\n }\n\n const sizePx = sizing.prop.toLowerCase() === 'font' ? resolveFontShorthandSize(sizing.value) : resolveFontSize(sizing.value);\n if (sizePx === undefined) {\n warn(\n sizing,\n `Cannot resolve the document root font size \"${sizing.value}\" at build time; rem lengths in the hosted module will use the host page's root size.`,\n );\n return;\n }\n\n const recorded = rule.clone({ selector: rootSelectors.join(', ') });\n recorded.raws.before = rule.raws.before || '\\n';\n recorded.removeAll();\n // The recorded size points back at the declaration it came from, so source maps keep a source for it.\n recorded.append({\n important: sizing.important,\n prop: MF_ROOT_FONT_SIZE_PROPERTY,\n source: sizing.source,\n value: `${Number(sizePx.toFixed(4))}px`,\n });\n rule.after(recorded);\n });\n};\n\nconst scopeGlobalRoot = (root: Root, scopeId: string, scopeSelector: string, keyframePrefix: string, warn: TWarn): void => {\n recordRootFontSize(root, warn);\n namespaceKeyframes(root, keyframePrefix);\n const contentRootSelector = `:where([${MF_SCOPE_ATTRIBUTE}=\"${scopeId}\"]:not([${MF_OVERLAY_ATTRIBUTE}]))`;\n root.walkRules((rule) => {\n if (!isKeyframesRule(rule)) {\n const declarations = rule.nodes.filter((node) => node.type === 'decl');\n const customProperties = declarations.filter((declaration) => declaration.prop.startsWith('--'));\n const standardDeclarations = declarations.filter((declaration) => !declaration.prop.startsWith('--'));\n\n if (customProperties.length > 0 && standardDeclarations.length > 0 && hasRootOnlySelector(rule.selector)) {\n const customPropertyRule = rule.cloneBefore();\n customPropertyRule.walkDecls((declaration) => {\n if (!declaration.prop.startsWith('--')) {\n declaration.remove();\n }\n });\n customPropertyRule.selector = scopeSelectorList(customPropertyRule.selector, scopeId, scopeSelector, [':host', scopeSelector]);\n rule.walkDecls((declaration) => {\n if (declaration.prop.startsWith('--')) {\n declaration.remove();\n }\n });\n }\n\n const containsOnlyCustomProperties = declarations.length > 0 && declarations.every((declaration) => declaration.prop.startsWith('--'));\n const rootScopeSelectors = containsOnlyCustomProperties ? [':host', scopeSelector] : [':host', contentRootSelector];\n rule.selector = scopeSelectorList(rule.selector, scopeId, scopeSelector, rootScopeSelectors);\n }\n });\n};\n\nconst scopeAngularComponentRoot = (root: Root, boundarySelector: string, keyframePrefix: string): void => {\n namespaceKeyframes(root, keyframePrefix);\n root.walkRules((rule) => {\n if (!isKeyframesRule(rule)) {\n rule.selector = scopeAngularSelectorList(rule.selector, boundarySelector);\n }\n });\n};\n\nexport const scopeRemoteCss = ({ scopeId }: IScopeRemoteCssOptions): Plugin => {\n const validScopeId = validateMfScopeId(scopeId);\n const scopeSelector = getMfScopeSelector(validScopeId);\n const keyframePrefix = `edyn-mf-${validScopeId}--`;\n\n return {\n postcssPlugin: `edyn-mf-isolation-${validScopeId}`,\n Once(root, { result }) {\n scopeGlobalRoot(root, validScopeId, scopeSelector, keyframePrefix, (node, text) => node.warn(result, text));\n },\n };\n};\n\nexport const scopeAngularRemoteCss = ({ scopeId }: IScopeRemoteCssOptions): Plugin => {\n const validScopeId = validateMfScopeId(scopeId);\n const scopeSelector = getMfScopeSelector(validScopeId);\n const boundarySelector = `[${MF_SCOPE_ATTRIBUTE}=\"${validScopeId}\"]`;\n const keyframePrefix = `edyn-mf-${validScopeId}--`;\n\n return {\n postcssPlugin: `edyn-mf-angular-isolation-${validScopeId}`,\n Once(root, { result }) {\n if (shouldUseAngularComponentScoping(root.source?.input.file)) {\n scopeAngularComponentRoot(root, boundarySelector, keyframePrefix);\n return;\n }\n\n scopeGlobalRoot(root, validScopeId, scopeSelector, keyframePrefix, (node, text) => node.warn(result, text));\n },\n };\n};\n"]}
package/dist/postcss.js CHANGED
@@ -3,6 +3,7 @@ import { list } from 'postcss';
3
3
  import selectorParser from 'postcss-selector-parser';
4
4
  import valueParser from 'postcss-value-parser';
5
5
  import { getMfScopeSelector, MF_ROOT_SELECTOR, MF_SCOPE_ATTRIBUTE, validateMfScopeId } from './index.js';
6
+ import { MF_ROOT_FONT_SIZE_PROPERTY } from './root-font-size.js';
6
7
  const ANGULAR_COMPONENT_STYLE_PATTERN = /\.component\.(?:css|less|sass|scss)$/i;
7
8
  const VIEW_ENCAPSULATION_NONE_PATTERN = /(?:^|[,{])\s*encapsulation\s*:\s*(?:[A-Za-z_$][\w$]*\s*\.\s*)+None\b/m;
8
9
  const MF_OVERLAY_ATTRIBUTE = 'data-edyn-mf-overlay';
@@ -89,10 +90,6 @@ const isScopeNode = (node, scopeId) => {
89
90
  if (node?.type === 'attribute' && node.attribute === MF_SCOPE_ATTRIBUTE && node.operator === '=' && node.value === scopeId) {
90
91
  return true;
91
92
  }
92
- // A rooted boundary written by rootedDescendantScope(): :is(<scope>, <specificity carrier>).
93
- if (node?.type === 'pseudo' && node.value === ':is' && node.nodes[0]?.nodes.length === 1 && isScopeNode(node.nodes[0].first, scopeId)) {
94
- return true;
95
- }
96
93
  const normalized = node?.toString().replaceAll('"', '').replaceAll("'", '');
97
94
  return (node?.type === 'pseudo' &&
98
95
  (normalized === `:where([${MF_SCOPE_ATTRIBUTE}=${scopeId}])` ||
@@ -124,12 +121,13 @@ const removeRootIdentityIds = (selector) => {
124
121
  removeIdsFromRootCompound();
125
122
  };
126
123
  const SPECIFICITY_CARRIER = 'edyn-mf-root';
127
- // Legacy overrides such as `html body#app .mdc-checkbox__background` won over Angular Material's own rules through the
128
- // id and types of the document root they start from. Replacing that root with the scope attribute alone drops the id,
129
- // so Material wins again. This carrier has the same id, class and type counts as the root part it replaces; inside
130
- // :is(<scope>, <carrier>) it never matches (`:not(*)`), and :is() takes its strongest argument's specificity. Only roots
131
- // with an id need it: without one the scope attribute already outweighs them. Neutral names keep `html`, `body` and
132
- // `#app` out of the emitted CSS.
124
+ // Legacy rules such as `html body button` or `html body#app .mdc-checkbox__background` are weighed against Angular
125
+ // Material's own rules by the html, body and #app they start from, so the scope that replaces that root must weigh
126
+ // exactly the same. A plain scope attribute (0,1,0) drops the id of `body#app`, letting Material's checked colour win,
127
+ // and outweighs the two types of `html body`, letting an override that lost to `.mat-mdc-button` on the old site win
128
+ // hosted. The root becomes :where(<scope>):not(<carrier>): :where() weighs nothing, and the carrier has the same id,
129
+ // class and type counts as the root part it replaces and never matches the scope element, so :not() always matches and
130
+ // weighs exactly that. Neutral names keep `html`, `body` and `#app` out of the emitted CSS.
133
131
  const rootSpecificityCarrier = (selector) => {
134
132
  const compounds = [[]];
135
133
  for (const node of selector.nodes) {
@@ -140,7 +138,6 @@ const rootSpecificityCarrier = (selector) => {
140
138
  compounds.at(-1)?.push(node);
141
139
  }
142
140
  }
143
- let ids = 0;
144
141
  const carrier = [];
145
142
  for (const compound of compounds) {
146
143
  if (!compound.some(isRootNode)) {
@@ -148,16 +145,13 @@ const rootSpecificityCarrier = (selector) => {
148
145
  }
149
146
  const types = compound.filter((node) => node.type === 'tag' && isRootNode(node)).length;
150
147
  const pseudoRoots = compound.filter((node) => node.type === 'pseudo' && isRootNode(node)).length;
151
- const compoundIds = compound.filter((node) => node.type === 'id').length;
152
- ids += compoundIds;
153
- carrier.push(`${SPECIFICITY_CARRIER.repeat(Math.min(types, 1))}${`.${SPECIFICITY_CARRIER}`.repeat(pseudoRoots)}${`#${SPECIFICITY_CARRIER}`.repeat(compoundIds)}`);
148
+ const ids = compound.filter((node) => node.type === 'id').length;
149
+ carrier.push(`${SPECIFICITY_CARRIER.repeat(Math.min(types, 1))}${`.${SPECIFICITY_CARRIER}`.repeat(pseudoRoots)}${`#${SPECIFICITY_CARRIER}`.repeat(ids)}`);
154
150
  }
155
- return ids > 0 ? `${carrier.filter(Boolean).join(' ')}:not(*)` : undefined;
151
+ return carrier.filter(Boolean).join(' ');
156
152
  };
157
153
  const rootedDescendantScope = (selector, scopeId) => {
158
- const scope = `[${MF_SCOPE_ATTRIBUTE}="${scopeId}"]`;
159
- const carrier = rootSpecificityCarrier(selector);
160
- return carrier ? `:is(${scope}, ${carrier})` : scope;
154
+ return `:where([${MF_SCOPE_ATTRIBUTE}="${scopeId}"]):not(${rootSpecificityCarrier(selector)})`;
161
155
  };
162
156
  const isRootOnlySelector = (selector) => {
163
157
  const compounds = [[]];
@@ -207,8 +201,19 @@ const scopeSelectorList = (selectorList, scopeId, scopeSelector, rootScopeSelect
207
201
  const variant = selector.clone();
208
202
  removeRootIdentityIds(variant);
209
203
  const [firstRoot, ...duplicateRoots] = variant.nodes.filter(isRootNode);
210
- const scopeNode = selectorParser().astSync(replacementSelector).first.first.clone();
211
- firstRoot?.replaceWith(scopeNode);
204
+ // The replacement can be a compound of several nodes, e.g. :where(<scope>):not(<carrier>).
205
+ const scopeNodes = selectorParser()
206
+ .astSync(replacementSelector)
207
+ .first.nodes.map((node) => node.clone());
208
+ const [scopeNode, ...followingScopeNodes] = scopeNodes;
209
+ if (firstRoot && scopeNode) {
210
+ firstRoot.replaceWith(scopeNode);
211
+ let previous = scopeNode;
212
+ for (const node of followingScopeNodes) {
213
+ variant.insertAfter(previous, node);
214
+ previous = node;
215
+ }
216
+ }
212
217
  for (const duplicateRoot of duplicateRoots) {
213
218
  const previous = duplicateRoot.prev();
214
219
  if (previous?.type === 'combinator') {
@@ -345,7 +350,143 @@ const namespaceKeyframes = (root, keyframePrefix) => {
345
350
  declaration.value = parsed.toString();
346
351
  });
347
352
  };
348
- const scopeGlobalRoot = (root, scopeId, scopeSelector, keyframePrefix) => {
353
+ const INITIAL_FONT_SIZE_PX = 16;
354
+ // Absolute-size keywords as browsers compute them, and the relative ones as they resolve on the root, whose parent size
355
+ // is the initial 16px.
356
+ const FONT_SIZE_KEYWORDS_PX = {
357
+ 'xx-small': 9,
358
+ 'x-small': 10,
359
+ small: 13,
360
+ medium: 16,
361
+ large: 18,
362
+ 'x-large': 24,
363
+ 'xx-large': 32,
364
+ 'xxx-large': 48,
365
+ smaller: INITIAL_FONT_SIZE_PX / 1.2,
366
+ larger: INITIAL_FONT_SIZE_PX * 1.2,
367
+ };
368
+ // On the root, every global keyword gives the initial size.
369
+ const GLOBAL_KEYWORDS = new Set(['inherit', 'initial', 'revert', 'revert-layer', 'unset']);
370
+ // em, rem and % on the root are relative to the initial size.
371
+ const FONT_SIZE_UNITS_PX = {
372
+ '%': INITIAL_FONT_SIZE_PX / 100,
373
+ cm: 96 / 2.54,
374
+ em: INITIAL_FONT_SIZE_PX,
375
+ in: 96,
376
+ mm: 96 / 25.4,
377
+ pc: 16,
378
+ pt: 96 / 72,
379
+ px: 1,
380
+ q: 96 / 101.6,
381
+ rem: INITIAL_FONT_SIZE_PX,
382
+ };
383
+ const fontSizeOfWord = (word) => {
384
+ const keyword = FONT_SIZE_KEYWORDS_PX[word.toLowerCase()];
385
+ if (keyword !== undefined) {
386
+ return keyword;
387
+ }
388
+ const dimension = valueParser.unit(word);
389
+ const unitPx = dimension ? FONT_SIZE_UNITS_PX[dimension.unit.toLowerCase()] : undefined;
390
+ const amount = Number(dimension ? dimension.number : Number.NaN);
391
+ return unitPx !== undefined && Number.isFinite(amount) && amount >= 0 ? amount * unitPx : undefined;
392
+ };
393
+ const significantValueNodes = (value) => {
394
+ return valueParser(value).nodes.filter((node) => node.type !== 'space' && node.type !== 'comment');
395
+ };
396
+ const globalKeywordFontSize = (nodes) => {
397
+ const [only] = nodes;
398
+ return nodes.length === 1 && only?.type === 'word' && GLOBAL_KEYWORDS.has(only.value.toLowerCase()) ? INITIAL_FONT_SIZE_PX : undefined;
399
+ };
400
+ const resolveFontSize = (value) => {
401
+ const nodes = significantValueNodes(value);
402
+ const [only] = nodes;
403
+ return globalKeywordFontSize(nodes) ?? (nodes.length === 1 && only?.type === 'word' ? fontSizeOfWord(only.value) : undefined);
404
+ };
405
+ // `font: [style] [variant] [weight] [stretch] <size>[/<line-height>] <family>`: the size is the word before `/`, or else
406
+ // the first word that is a size. A function (var(), calc()) or a family name reached first means it cannot be read.
407
+ const resolveFontShorthandSize = (value) => {
408
+ const nodes = significantValueNodes(value);
409
+ const globalSize = globalKeywordFontSize(nodes);
410
+ if (globalSize !== undefined) {
411
+ return globalSize;
412
+ }
413
+ const slashIndex = nodes.findIndex((node) => node.type === 'div' && node.value === '/');
414
+ if (slashIndex > 0) {
415
+ const size = nodes[slashIndex - 1];
416
+ return size?.type === 'word' ? fontSizeOfWord(size.value) : undefined;
417
+ }
418
+ for (const node of nodes) {
419
+ if (node.type !== 'word') {
420
+ return undefined;
421
+ }
422
+ const size = fontSizeOfWord(node.value);
423
+ if (size !== undefined) {
424
+ return size;
425
+ }
426
+ }
427
+ return undefined;
428
+ };
429
+ // `html` and `:root` size the document root, so rem; `body` and `html body` size only the body.
430
+ const targetsDocumentRoot = (selector) => {
431
+ let subject = [];
432
+ for (const node of selector.nodes) {
433
+ subject = node.type === 'combinator' ? [] : [...subject, node];
434
+ }
435
+ return subject.some((node) => (node.type === 'tag' && node.value.toLowerCase() === 'html') || (node.type === 'pseudo' && node.value === ':root'));
436
+ };
437
+ const documentRootSelectorsOf = (selectorList) => {
438
+ const selectors = [];
439
+ selectorParser((root) => {
440
+ for (const selector of root.nodes) {
441
+ if (targetsDocumentRoot(selector)) {
442
+ selectors.push(selector.toString().trim());
443
+ }
444
+ }
445
+ }).processSync(selectorList);
446
+ return selectors;
447
+ };
448
+ // Hosted, rem resolves against the host page's root, not the root size the module's own page set. Each rule that sizes
449
+ // the document root gets a sibling rule right after it that records that size as MF_ROOT_FONT_SIZE_PROPERTY, under the
450
+ // same conditions (@media, importance) and in the same cascade order; scoping then moves it onto the module boundary,
451
+ // where followModuleRootFontSize() makes rem lengths read it. CSS that never sizes the root is left byte-identical.
452
+ const recordRootFontSize = (root, warn) => {
453
+ root.walkRules((rule) => {
454
+ if (isKeyframesRule(rule)) {
455
+ return;
456
+ }
457
+ let sizing;
458
+ for (const node of rule.nodes) {
459
+ if (node.type === 'decl' && /^font(?:-size)?$/i.test(node.prop) && (node.important || !sizing?.important)) {
460
+ sizing = node;
461
+ }
462
+ }
463
+ if (!sizing) {
464
+ return;
465
+ }
466
+ const rootSelectors = documentRootSelectorsOf(rule.selector);
467
+ if (rootSelectors.length === 0) {
468
+ return;
469
+ }
470
+ const sizePx = sizing.prop.toLowerCase() === 'font' ? resolveFontShorthandSize(sizing.value) : resolveFontSize(sizing.value);
471
+ if (sizePx === undefined) {
472
+ warn(sizing, `Cannot resolve the document root font size "${sizing.value}" at build time; rem lengths in the hosted module will use the host page's root size.`);
473
+ return;
474
+ }
475
+ const recorded = rule.clone({ selector: rootSelectors.join(', ') });
476
+ recorded.raws.before = rule.raws.before || '\n';
477
+ recorded.removeAll();
478
+ // The recorded size points back at the declaration it came from, so source maps keep a source for it.
479
+ recorded.append({
480
+ important: sizing.important,
481
+ prop: MF_ROOT_FONT_SIZE_PROPERTY,
482
+ source: sizing.source,
483
+ value: `${Number(sizePx.toFixed(4))}px`,
484
+ });
485
+ rule.after(recorded);
486
+ });
487
+ };
488
+ const scopeGlobalRoot = (root, scopeId, scopeSelector, keyframePrefix, warn) => {
489
+ recordRootFontSize(root, warn);
349
490
  namespaceKeyframes(root, keyframePrefix);
350
491
  const contentRootSelector = `:where([${MF_SCOPE_ATTRIBUTE}="${scopeId}"]:not([${MF_OVERLAY_ATTRIBUTE}]))`;
351
492
  root.walkRules((rule) => {
@@ -387,8 +528,8 @@ export const scopeRemoteCss = ({ scopeId }) => {
387
528
  const keyframePrefix = `edyn-mf-${validScopeId}--`;
388
529
  return {
389
530
  postcssPlugin: `edyn-mf-isolation-${validScopeId}`,
390
- Once(root) {
391
- scopeGlobalRoot(root, validScopeId, scopeSelector, keyframePrefix);
531
+ Once(root, { result }) {
532
+ scopeGlobalRoot(root, validScopeId, scopeSelector, keyframePrefix, (node, text) => node.warn(result, text));
392
533
  },
393
534
  };
394
535
  };
@@ -399,12 +540,12 @@ export const scopeAngularRemoteCss = ({ scopeId }) => {
399
540
  const keyframePrefix = `edyn-mf-${validScopeId}--`;
400
541
  return {
401
542
  postcssPlugin: `edyn-mf-angular-isolation-${validScopeId}`,
402
- Once(root) {
543
+ Once(root, { result }) {
403
544
  if (shouldUseAngularComponentScoping(root.source?.input.file)) {
404
545
  scopeAngularComponentRoot(root, boundarySelector, keyframePrefix);
405
546
  return;
406
547
  }
407
- scopeGlobalRoot(root, validScopeId, scopeSelector, keyframePrefix);
548
+ scopeGlobalRoot(root, validScopeId, scopeSelector, keyframePrefix, (node, text) => node.warn(result, text));
408
549
  },
409
550
  };
410
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,EAAE,cAAc,CAAC,CAAC;gBAClE,OAAO;YACT,CAAC;YAED,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC;QACrE,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { list, type Plugin, type Root, type Rule } from 'postcss';\nimport selectorParser from 'postcss-selector-parser';\nimport valueParser from 'postcss-value-parser';\nimport { getMfScopeSelector, MF_ROOT_SELECTOR, MF_SCOPE_ATTRIBUTE, validateMfScopeId } from './index.js';\n\nexport interface IScopeRemoteCssOptions {\n scopeId: string;\n}\n\nconst ANGULAR_COMPONENT_STYLE_PATTERN = /\\.component\\.(?:css|less|sass|scss)$/i;\nconst VIEW_ENCAPSULATION_NONE_PATTERN = /(?:^|[,{])\\s*encapsulation\\s*:\\s*(?:[A-Za-z_$][\\w$]*\\s*\\.\\s*)+None\\b/m;\nconst MF_OVERLAY_ATTRIBUTE = 'data-edyn-mf-overlay';\n\ntype TTypeScriptMaskState = 'block-comment' | 'code' | 'double-quote' | 'line-comment' | 'single-quote' | 'template';\n\nconst maskTypeScriptCommentsAndStrings = (source: string): string => {\n let maskedSource = '';\n let state: TTypeScriptMaskState = 'code';\n let escaped = false;\n\n const maskCharacter = (character: string): string => {\n return character === '\\n' || character === '\\r' ? character : ' ';\n };\n\n for (let index = 0; index < source.length; index += 1) {\n const character = source[index] ?? '';\n const nextCharacter = source[index + 1];\n\n if (state === 'code') {\n if (character === '/' && nextCharacter === '/') {\n maskedSource += ' ';\n index += 1;\n state = 'line-comment';\n } else if (character === '/' && nextCharacter === '*') {\n maskedSource += ' ';\n index += 1;\n state = 'block-comment';\n } else if (character === \"'\") {\n maskedSource += ' ';\n state = 'single-quote';\n } else if (character === '\"') {\n maskedSource += ' ';\n state = 'double-quote';\n } else if (character === '`') {\n maskedSource += ' ';\n state = 'template';\n } else {\n maskedSource += character;\n }\n continue;\n }\n\n if (state === 'line-comment') {\n maskedSource += maskCharacter(character);\n if (character === '\\n' || character === '\\r') {\n state = 'code';\n }\n continue;\n }\n\n if (state === 'block-comment') {\n if (character === '*' && nextCharacter === '/') {\n maskedSource += ' ';\n index += 1;\n state = 'code';\n } else {\n maskedSource += maskCharacter(character);\n }\n continue;\n }\n\n maskedSource += maskCharacter(character);\n if (escaped) {\n escaped = false;\n } else if (character === '\\\\') {\n escaped = true;\n } else if (\n (state === 'single-quote' && character === \"'\") ||\n (state === 'double-quote' && character === '\"') ||\n (state === 'template' && character === '`')\n ) {\n state = 'code';\n }\n }\n\n return maskedSource;\n};\n\nconst isKeyframesRule = (rule: Rule): boolean => {\n const parent = rule.parent;\n return parent?.type === 'atrule' && /keyframes$/i.test(parent.name);\n};\n\nconst isRootNode = (node: selectorParser.Node): boolean => {\n return (\n (node.type === 'tag' && (node.value.toLowerCase() === 'html' || node.value.toLowerCase() === 'body')) ||\n (node.type === 'pseudo' && (node.value === ':root' || node.value === MF_ROOT_SELECTOR))\n );\n};\n\nconst isScopeNode = (node: selectorParser.Node | undefined, scopeId: string): boolean => {\n if (node?.type === 'attribute' && node.attribute === MF_SCOPE_ATTRIBUTE && node.operator === '=' && node.value === scopeId) {\n return true;\n }\n\n // A rooted boundary written by rootedDescendantScope(): :is(<scope>, <specificity carrier>).\n if (node?.type === 'pseudo' && node.value === ':is' && node.nodes[0]?.nodes.length === 1 && isScopeNode(node.nodes[0].first, scopeId)) {\n return true;\n }\n\n const normalized = node?.toString().replaceAll('\"', '').replaceAll(\"'\", '');\n return (\n node?.type === 'pseudo' &&\n (normalized === `:where([${MF_SCOPE_ATTRIBUTE}=${scopeId}])` ||\n normalized === `:where([${MF_SCOPE_ATTRIBUTE}=${scopeId}]:not([${MF_OVERLAY_ATTRIBUTE}]))`)\n );\n};\n\nconst startsWithHostPseudo = (selector: selectorParser.Selector): boolean => {\n return selector.first?.type === 'pseudo' && selector.first.value === ':host';\n};\n\nconst removeRootIdentityIds = (selector: selectorParser.Selector): void => {\n let compound: selectorParser.Node[] = [];\n const removeIdsFromRootCompound = (): void => {\n if (compound.some(isRootNode)) {\n for (const node of compound) {\n if (node.type === 'id') {\n node.remove();\n }\n }\n }\n };\n\n for (const node of [...selector.nodes]) {\n if (node.type === 'combinator') {\n removeIdsFromRootCompound();\n compound = [];\n } else {\n compound.push(node);\n }\n }\n removeIdsFromRootCompound();\n};\n\nconst SPECIFICITY_CARRIER = 'edyn-mf-root';\n\n// Legacy overrides such as `html body#app .mdc-checkbox__background` won over Angular Material's own rules through the\n// id and types of the document root they start from. Replacing that root with the scope attribute alone drops the id,\n// so Material wins again. This carrier has the same id, class and type counts as the root part it replaces; inside\n// :is(<scope>, <carrier>) it never matches (`:not(*)`), and :is() takes its strongest argument's specificity. Only roots\n// with an id need it: without one the scope attribute already outweighs them. Neutral names keep `html`, `body` and\n// `#app` out of the emitted CSS.\nconst rootSpecificityCarrier = (selector: selectorParser.Selector): string | undefined => {\n const compounds: selectorParser.Node[][] = [[]];\n for (const node of selector.nodes) {\n if (node.type === 'combinator') {\n compounds.push([]);\n } else {\n compounds.at(-1)?.push(node);\n }\n }\n\n let ids = 0;\n const carrier: string[] = [];\n for (const compound of compounds) {\n if (!compound.some(isRootNode)) {\n continue;\n }\n const types = compound.filter((node) => node.type === 'tag' && isRootNode(node)).length;\n const pseudoRoots = compound.filter((node) => node.type === 'pseudo' && isRootNode(node)).length;\n const compoundIds = compound.filter((node) => node.type === 'id').length;\n ids += compoundIds;\n carrier.push(\n `${SPECIFICITY_CARRIER.repeat(Math.min(types, 1))}${`.${SPECIFICITY_CARRIER}`.repeat(pseudoRoots)}${`#${SPECIFICITY_CARRIER}`.repeat(compoundIds)}`,\n );\n }\n\n return ids > 0 ? `${carrier.filter(Boolean).join(' ')}:not(*)` : undefined;\n};\n\nconst rootedDescendantScope = (selector: selectorParser.Selector, scopeId: string): string => {\n const scope = `[${MF_SCOPE_ATTRIBUTE}=\"${scopeId}\"]`;\n const carrier = rootSpecificityCarrier(selector);\n return carrier ? `:is(${scope}, ${carrier})` : scope;\n};\n\nconst isRootOnlySelector = (selector: selectorParser.Selector): boolean => {\n const compounds: selectorParser.Node[][] = [[]];\n\n for (const node of selector.nodes) {\n if (node.type === 'combinator') {\n compounds.push([]);\n } else {\n compounds.at(-1)?.push(node);\n }\n }\n\n return compounds.every((compound) => compound.some(isRootNode));\n};\n\nconst hasRootOnlySelector = (selectorList: string): boolean => {\n let result = false;\n selectorParser((root) => {\n result = root.nodes.some(isRootOnlySelector);\n }).processSync(selectorList);\n return result;\n};\n\nconst getAngularComponentSourcePath = (stylePath: string): string | undefined => {\n const cleanStylePath = stylePath.replace(/[?#].*$/, '');\n if (!ANGULAR_COMPONENT_STYLE_PATTERN.test(cleanStylePath)) {\n return undefined;\n }\n\n return cleanStylePath.replace(/\\.(?:css|less|sass|scss)$/i, '.ts');\n};\n\nconst usesViewEncapsulationNone = (stylePath: string): boolean => {\n const componentSourcePath = getAngularComponentSourcePath(stylePath);\n if (!componentSourcePath || !existsSync(componentSourcePath)) {\n return false;\n }\n\n const componentSource = readFileSync(componentSourcePath, 'utf8');\n return VIEW_ENCAPSULATION_NONE_PATTERN.test(maskTypeScriptCommentsAndStrings(componentSource));\n};\n\nexport const shouldUseAngularComponentScoping = (stylePath: string | undefined): boolean => {\n return !!stylePath && !!getAngularComponentSourcePath(stylePath) && !usesViewEncapsulationNone(stylePath);\n};\n\nconst scopeSelectorList = (selectorList: string, scopeId: string, scopeSelector: string, rootScopeSelectors: string[]): string => {\n return selectorParser((root) => {\n const sourceSelectors = [...root.nodes];\n\n for (const selector of sourceSelectors) {\n const rootNodes = selector.nodes.filter(isRootNode);\n\n if (rootNodes.length > 0) {\n const replacementSelectors = isRootOnlySelector(selector) ? rootScopeSelectors : [rootedDescendantScope(selector, scopeId)];\n\n for (const replacementSelector of replacementSelectors) {\n const variant = selector.clone();\n removeRootIdentityIds(variant);\n const [firstRoot, ...duplicateRoots] = variant.nodes.filter(isRootNode);\n const scopeNode = selectorParser().astSync(replacementSelector).first.first.clone();\n firstRoot?.replaceWith(scopeNode);\n\n for (const duplicateRoot of duplicateRoots) {\n const previous = duplicateRoot.prev();\n if (previous?.type === 'combinator') {\n previous.remove();\n }\n duplicateRoot.remove();\n }\n\n root.insertBefore(selector, variant);\n }\n selector.remove();\n continue;\n }\n\n if (startsWithHostPseudo(selector) || isScopeNode(selector.first, scopeId)) {\n continue;\n }\n\n const first = selector.first;\n const needsBoundaryVariant = first?.type === 'universal' || (first?.type === 'pseudo' && first.value.startsWith('::'));\n\n if (needsBoundaryVariant) {\n const hasSiblingCombinator = selector.nodes.some((node) => node.type === 'combinator' && (node.value === '+' || node.value === '~'));\n\n if (!hasSiblingCombinator) {\n const boundaryVariant = selector.clone();\n const boundaryScope = selectorParser().astSync(scopeSelector).first.first.clone();\n boundaryVariant.first.rawSpaceBefore = '';\n if (boundaryVariant.first.type === 'universal') {\n boundaryVariant.first.replaceWith(boundaryScope);\n } else {\n boundaryVariant.prepend(boundaryScope);\n }\n root.insertBefore(selector, boundaryVariant);\n }\n }\n\n const descendantScope = selectorParser().astSync(`${scopeSelector} *`).first;\n const prefixNodes = descendantScope.nodes.slice(0, -1).map((node) => node.clone());\n selector.first.rawSpaceBefore = '';\n for (const prefixNode of prefixNodes.reverse()) {\n selector.prepend(prefixNode);\n }\n }\n\n const seenSelectors = new Set<string>();\n for (const selector of [...root.nodes]) {\n const normalizedSelector = selector.toString().trim();\n if (seenSelectors.has(normalizedSelector)) {\n selector.remove();\n } else {\n seenSelectors.add(normalizedSelector);\n }\n }\n }).processSync(selectorList);\n};\n\nconst findFunctionalPseudoEnd = (selector: string, openParenthesisIndex: number): number => {\n let depth = 0;\n let quote: '\"' | \"'\" | undefined;\n\n for (let index = openParenthesisIndex; index < selector.length; index += 1) {\n const character = selector[index];\n const previousCharacter = selector[index - 1];\n\n if (quote) {\n if (character === quote && previousCharacter !== '\\\\') {\n quote = undefined;\n }\n continue;\n }\n\n if (character === '\"' || character === \"'\") {\n quote = character;\n continue;\n }\n\n if (character === '(') {\n depth += 1;\n } else if (character === ')') {\n depth -= 1;\n if (depth === 0) {\n return index;\n }\n }\n }\n\n return -1;\n};\n\nconst scopeAngularSelector = (selector: string, boundarySelector: string): string => {\n const normalizedSelector = selector.trim();\n const angularBoundary = `:host-context(${boundarySelector})`;\n const normalizedBoundary = normalizedSelector.slice(0, angularBoundary.length).replaceAll(\"'\", '\"');\n\n if (normalizedBoundary === angularBoundary) {\n return normalizedSelector;\n }\n\n if (/^:host-context\\(/i.test(normalizedSelector)) {\n return `${angularBoundary}${normalizedSelector}`;\n }\n\n if (/^:host\\(/i.test(normalizedSelector)) {\n const openParenthesisIndex = normalizedSelector.indexOf('(');\n const closeParenthesisIndex = findFunctionalPseudoEnd(normalizedSelector, openParenthesisIndex);\n if (closeParenthesisIndex !== -1) {\n const hostSelector = normalizedSelector.slice(openParenthesisIndex + 1, closeParenthesisIndex);\n const remainder = normalizedSelector.slice(closeParenthesisIndex + 1);\n return list\n .comma(hostSelector)\n .map((hostSelectorVariant) => `${angularBoundary}${hostSelectorVariant}${remainder}`)\n .join(', ');\n }\n }\n\n if (/^:host\\b/i.test(normalizedSelector)) {\n return normalizedSelector.replace(/^:host\\b/i, angularBoundary);\n }\n\n return `${angularBoundary} ${normalizedSelector}`;\n};\n\nconst scopeAngularSelectorList = (selectorList: string, boundarySelector: string): string => {\n return list\n .comma(selectorList)\n .map((selector) => scopeAngularSelector(selector, boundarySelector))\n .join(', ');\n};\n\nconst namespaceKeyframes = (root: Root, keyframePrefix: string): void => {\n const keyframes = new Map<string, string>();\n\n root.walkAtRules((atRule) => {\n if (!/keyframes$/i.test(atRule.name) || atRule.params.startsWith(keyframePrefix)) {\n return;\n }\n\n const originalName = atRule.params.trim();\n const scopedName = `${keyframePrefix}${originalName}`;\n keyframes.set(originalName, scopedName);\n atRule.params = scopedName;\n });\n\n root.walkDecls((declaration) => {\n if (!/^(?:-webkit-)?animation(?:-name)?$/i.test(declaration.prop) && !declaration.prop.startsWith('--animate-')) {\n return;\n }\n\n const parsed = valueParser(declaration.value);\n parsed.walk((node) => {\n if (node.type === 'word') {\n node.value = keyframes.get(node.value) ?? node.value;\n }\n });\n declaration.value = parsed.toString();\n });\n};\n\nconst scopeGlobalRoot = (root: Root, scopeId: string, scopeSelector: string, keyframePrefix: string): void => {\n namespaceKeyframes(root, keyframePrefix);\n const contentRootSelector = `:where([${MF_SCOPE_ATTRIBUTE}=\"${scopeId}\"]:not([${MF_OVERLAY_ATTRIBUTE}]))`;\n root.walkRules((rule) => {\n if (!isKeyframesRule(rule)) {\n const declarations = rule.nodes.filter((node) => node.type === 'decl');\n const customProperties = declarations.filter((declaration) => declaration.prop.startsWith('--'));\n const standardDeclarations = declarations.filter((declaration) => !declaration.prop.startsWith('--'));\n\n if (customProperties.length > 0 && standardDeclarations.length > 0 && hasRootOnlySelector(rule.selector)) {\n const customPropertyRule = rule.cloneBefore();\n customPropertyRule.walkDecls((declaration) => {\n if (!declaration.prop.startsWith('--')) {\n declaration.remove();\n }\n });\n customPropertyRule.selector = scopeSelectorList(customPropertyRule.selector, scopeId, scopeSelector, [':host', scopeSelector]);\n rule.walkDecls((declaration) => {\n if (declaration.prop.startsWith('--')) {\n declaration.remove();\n }\n });\n }\n\n const containsOnlyCustomProperties = declarations.length > 0 && declarations.every((declaration) => declaration.prop.startsWith('--'));\n const rootScopeSelectors = containsOnlyCustomProperties ? [':host', scopeSelector] : [':host', contentRootSelector];\n rule.selector = scopeSelectorList(rule.selector, scopeId, scopeSelector, rootScopeSelectors);\n }\n });\n};\n\nconst scopeAngularComponentRoot = (root: Root, boundarySelector: string, keyframePrefix: string): void => {\n namespaceKeyframes(root, keyframePrefix);\n root.walkRules((rule) => {\n if (!isKeyframesRule(rule)) {\n rule.selector = scopeAngularSelectorList(rule.selector, boundarySelector);\n }\n });\n};\n\nexport const scopeRemoteCss = ({ scopeId }: IScopeRemoteCssOptions): Plugin => {\n const validScopeId = validateMfScopeId(scopeId);\n const scopeSelector = getMfScopeSelector(validScopeId);\n const keyframePrefix = `edyn-mf-${validScopeId}--`;\n\n return {\n postcssPlugin: `edyn-mf-isolation-${validScopeId}`,\n Once(root) {\n scopeGlobalRoot(root, validScopeId, scopeSelector, keyframePrefix);\n },\n };\n};\n\nexport const scopeAngularRemoteCss = ({ scopeId }: IScopeRemoteCssOptions): Plugin => {\n const validScopeId = validateMfScopeId(scopeId);\n const scopeSelector = getMfScopeSelector(validScopeId);\n const boundarySelector = `[${MF_SCOPE_ATTRIBUTE}=\"${validScopeId}\"]`;\n const keyframePrefix = `edyn-mf-${validScopeId}--`;\n\n return {\n postcssPlugin: `edyn-mf-angular-isolation-${validScopeId}`,\n Once(root) {\n if (shouldUseAngularComponentScoping(root.source?.input.file)) {\n scopeAngularComponentRoot(root, boundarySelector, keyframePrefix);\n return;\n }\n\n scopeGlobalRoot(root, validScopeId, scopeSelector, keyframePrefix);\n },\n };\n};\n"]}
1
+ {"version":3,"file":"postcss.js","sourceRoot":"","sources":["../src/postcss.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAoB,IAAI,EAAqC,MAAM,SAAS,CAAC;AACpF,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACzG,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAMjE,MAAM,+BAA+B,GAAG,uCAAuC,CAAC;AAChF,MAAM,+BAA+B,GAAG,uEAAuE,CAAC;AAChH,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAIpD,MAAM,gCAAgC,GAAG,CAAC,MAAc,EAAU,EAAE;IAClE,IAAI,YAAY,GAAG,EAAE,CAAC;IACtB,IAAI,KAAK,GAAyB,MAAM,CAAC;IACzC,I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AAI,EAAE,EAAE,MAAM,EAAE;YACnB,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;QAC9G,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,EAAE,OAAO,EAA0B,EAAU,EAAE;IACnF,MAAM,YAAY,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,aAAa,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;IACvD,MAAM,gBAAgB,GAAG,IAAI,kBAAkB,KAAK,YAAY,IAAI,CAAC;IACrE,MAAM,cAAc,GAAG,WAAW,YAAY,IAAI,CAAC;IAEnD,OAAO;QACL,aAAa,EAAE,6BAA6B,YAAY,EAAE;QAC1D,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE;YACnB,IAAI,gCAAgC,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9D,yBAAyB,CAAC,IAAI,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAC;gBAClE,OAAO;YACT,CAAC;YAED,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;QAC9G,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { type Declaration, list, type Plugin, type Root, type Rule } from 'postcss';\nimport selectorParser from 'postcss-selector-parser';\nimport valueParser from 'postcss-value-parser';\nimport { getMfScopeSelector, MF_ROOT_SELECTOR, MF_SCOPE_ATTRIBUTE, validateMfScopeId } from './index.js';\nimport { MF_ROOT_FONT_SIZE_PROPERTY } from './root-font-size.js';\n\nexport interface IScopeRemoteCssOptions {\n scopeId: string;\n}\n\nconst ANGULAR_COMPONENT_STYLE_PATTERN = /\\.component\\.(?:css|less|sass|scss)$/i;\nconst VIEW_ENCAPSULATION_NONE_PATTERN = /(?:^|[,{])\\s*encapsulation\\s*:\\s*(?:[A-Za-z_$][\\w$]*\\s*\\.\\s*)+None\\b/m;\nconst MF_OVERLAY_ATTRIBUTE = 'data-edyn-mf-overlay';\n\ntype TTypeScriptMaskState = 'block-comment' | 'code' | 'double-quote' | 'line-comment' | 'single-quote' | 'template';\n\nconst maskTypeScriptCommentsAndStrings = (source: string): string => {\n let maskedSource = '';\n let state: TTypeScriptMaskState = 'code';\n let escaped = false;\n\n const maskCharacter = (character: string): string => {\n return character === '\\n' || character === '\\r' ? character : ' ';\n };\n\n for (let index = 0; index < source.length; index += 1) {\n const character = source[index] ?? '';\n const nextCharacter = source[index + 1];\n\n if (state === 'code') {\n if (character === '/' && nextCharacter === '/') {\n maskedSource += ' ';\n index += 1;\n state = 'line-comment';\n } else if (character === '/' && nextCharacter === '*') {\n maskedSource += ' ';\n index += 1;\n state = 'block-comment';\n } else if (character === \"'\") {\n maskedSource += ' ';\n state = 'single-quote';\n } else if (character === '\"') {\n maskedSource += ' ';\n state = 'double-quote';\n } else if (character === '`') {\n maskedSource += ' ';\n state = 'template';\n } else {\n maskedSource += character;\n }\n continue;\n }\n\n if (state === 'line-comment') {\n maskedSource += maskCharacter(character);\n if (character === '\\n' || character === '\\r') {\n state = 'code';\n }\n continue;\n }\n\n if (state === 'block-comment') {\n if (character === '*' && nextCharacter === '/') {\n maskedSource += ' ';\n index += 1;\n state = 'code';\n } else {\n maskedSource += maskCharacter(character);\n }\n continue;\n }\n\n maskedSource += maskCharacter(character);\n if (escaped) {\n escaped = false;\n } else if (character === '\\\\') {\n escaped = true;\n } else if (\n (state === 'single-quote' && character === \"'\") ||\n (state === 'double-quote' && character === '\"') ||\n (state === 'template' && character === '`')\n ) {\n state = 'code';\n }\n }\n\n return maskedSource;\n};\n\nconst isKeyframesRule = (rule: Rule): boolean => {\n const parent = rule.parent;\n return parent?.type === 'atrule' && /keyframes$/i.test(parent.name);\n};\n\nconst isRootNode = (node: selectorParser.Node): boolean => {\n return (\n (node.type === 'tag' && (node.value.toLowerCase() === 'html' || node.value.toLowerCase() === 'body')) ||\n (node.type === 'pseudo' && (node.value === ':root' || node.value === MF_ROOT_SELECTOR))\n );\n};\n\nconst isScopeNode = (node: selectorParser.Node | undefined, scopeId: string): boolean => {\n if (node?.type === 'attribute' && node.attribute === MF_SCOPE_ATTRIBUTE && node.operator === '=' && node.value === scopeId) {\n return true;\n }\n\n const normalized = node?.toString().replaceAll('\"', '').replaceAll(\"'\", '');\n return (\n node?.type === 'pseudo' &&\n (normalized === `:where([${MF_SCOPE_ATTRIBUTE}=${scopeId}])` ||\n normalized === `:where([${MF_SCOPE_ATTRIBUTE}=${scopeId}]:not([${MF_OVERLAY_ATTRIBUTE}]))`)\n );\n};\n\nconst startsWithHostPseudo = (selector: selectorParser.Selector): boolean => {\n return selector.first?.type === 'pseudo' && selector.first.value === ':host';\n};\n\nconst removeRootIdentityIds = (selector: selectorParser.Selector): void => {\n let compound: selectorParser.Node[] = [];\n const removeIdsFromRootCompound = (): void => {\n if (compound.some(isRootNode)) {\n for (const node of compound) {\n if (node.type === 'id') {\n node.remove();\n }\n }\n }\n };\n\n for (const node of [...selector.nodes]) {\n if (node.type === 'combinator') {\n removeIdsFromRootCompound();\n compound = [];\n } else {\n compound.push(node);\n }\n }\n removeIdsFromRootCompound();\n};\n\nconst SPECIFICITY_CARRIER = 'edyn-mf-root';\n\n// Legacy rules such as `html body button` or `html body#app .mdc-checkbox__background` are weighed against Angular\n// Material's own rules by the html, body and #app they start from, so the scope that replaces that root must weigh\n// exactly the same. A plain scope attribute (0,1,0) drops the id of `body#app`, letting Material's checked colour win,\n// and outweighs the two types of `html body`, letting an override that lost to `.mat-mdc-button` on the old site win\n// hosted. The root becomes :where(<scope>):not(<carrier>): :where() weighs nothing, and the carrier has the same id,\n// class and type counts as the root part it replaces and never matches the scope element, so :not() always matches and\n// weighs exactly that. Neutral names keep `html`, `body` and `#app` out of the emitted CSS.\nconst rootSpecificityCarrier = (selector: selectorParser.Selector): string => {\n const compounds: selectorParser.Node[][] = [[]];\n for (const node of selector.nodes) {\n if (node.type === 'combinator') {\n compounds.push([]);\n } else {\n compounds.at(-1)?.push(node);\n }\n }\n\n const carrier: string[] = [];\n for (const compound of compounds) {\n if (!compound.some(isRootNode)) {\n continue;\n }\n const types = compound.filter((node) => node.type === 'tag' && isRootNode(node)).length;\n const pseudoRoots = compound.filter((node) => node.type === 'pseudo' && isRootNode(node)).length;\n const ids = compound.filter((node) => node.type === 'id').length;\n carrier.push(\n `${SPECIFICITY_CARRIER.repeat(Math.min(types, 1))}${`.${SPECIFICITY_CARRIER}`.repeat(pseudoRoots)}${`#${SPECIFICITY_CARRIER}`.repeat(ids)}`,\n );\n }\n\n return carrier.filter(Boolean).join(' ');\n};\n\nconst rootedDescendantScope = (selector: selectorParser.Selector, scopeId: string): string => {\n return `:where([${MF_SCOPE_ATTRIBUTE}=\"${scopeId}\"]):not(${rootSpecificityCarrier(selector)})`;\n};\n\nconst isRootOnlySelector = (selector: selectorParser.Selector): boolean => {\n const compounds: selectorParser.Node[][] = [[]];\n\n for (const node of selector.nodes) {\n if (node.type === 'combinator') {\n compounds.push([]);\n } else {\n compounds.at(-1)?.push(node);\n }\n }\n\n return compounds.every((compound) => compound.some(isRootNode));\n};\n\nconst hasRootOnlySelector = (selectorList: string): boolean => {\n let result = false;\n selectorParser((root) => {\n result = root.nodes.some(isRootOnlySelector);\n }).processSync(selectorList);\n return result;\n};\n\nconst getAngularComponentSourcePath = (stylePath: string): string | undefined => {\n const cleanStylePath = stylePath.replace(/[?#].*$/, '');\n if (!ANGULAR_COMPONENT_STYLE_PATTERN.test(cleanStylePath)) {\n return undefined;\n }\n\n return cleanStylePath.replace(/\\.(?:css|less|sass|scss)$/i, '.ts');\n};\n\nconst usesViewEncapsulationNone = (stylePath: string): boolean => {\n const componentSourcePath = getAngularComponentSourcePath(stylePath);\n if (!componentSourcePath || !existsSync(componentSourcePath)) {\n return false;\n }\n\n const componentSource = readFileSync(componentSourcePath, 'utf8');\n return VIEW_ENCAPSULATION_NONE_PATTERN.test(maskTypeScriptCommentsAndStrings(componentSource));\n};\n\nexport const shouldUseAngularComponentScoping = (stylePath: string | undefined): boolean => {\n return !!stylePath && !!getAngularComponentSourcePath(stylePath) && !usesViewEncapsulationNone(stylePath);\n};\n\nconst scopeSelectorList = (selectorList: string, scopeId: string, scopeSelector: string, rootScopeSelectors: string[]): string => {\n return selectorParser((root) => {\n const sourceSelectors = [...root.nodes];\n\n for (const selector of sourceSelectors) {\n const rootNodes = selector.nodes.filter(isRootNode);\n\n if (rootNodes.length > 0) {\n const replacementSelectors = isRootOnlySelector(selector) ? rootScopeSelectors : [rootedDescendantScope(selector, scopeId)];\n\n for (const replacementSelector of replacementSelectors) {\n const variant = selector.clone();\n removeRootIdentityIds(variant);\n const [firstRoot, ...duplicateRoots] = variant.nodes.filter(isRootNode);\n // The replacement can be a compound of several nodes, e.g. :where(<scope>):not(<carrier>).\n const scopeNodes = selectorParser()\n .astSync(replacementSelector)\n .first.nodes.map((node) => node.clone());\n const [scopeNode, ...followingScopeNodes] = scopeNodes;\n if (firstRoot && scopeNode) {\n firstRoot.replaceWith(scopeNode);\n let previous = scopeNode;\n for (const node of followingScopeNodes) {\n variant.insertAfter(previous, node);\n previous = node;\n }\n }\n\n for (const duplicateRoot of duplicateRoots) {\n const previous = duplicateRoot.prev();\n if (previous?.type === 'combinator') {\n previous.remove();\n }\n duplicateRoot.remove();\n }\n\n root.insertBefore(selector, variant);\n }\n selector.remove();\n continue;\n }\n\n if (startsWithHostPseudo(selector) || isScopeNode(selector.first, scopeId)) {\n continue;\n }\n\n const first = selector.first;\n const needsBoundaryVariant = first?.type === 'universal' || (first?.type === 'pseudo' && first.value.startsWith('::'));\n\n if (needsBoundaryVariant) {\n const hasSiblingCombinator = selector.nodes.some((node) => node.type === 'combinator' && (node.value === '+' || node.value === '~'));\n\n if (!hasSiblingCombinator) {\n const boundaryVariant = selector.clone();\n const boundaryScope = selectorParser().astSync(scopeSelector).first.first.clone();\n boundaryVariant.first.rawSpaceBefore = '';\n if (boundaryVariant.first.type === 'universal') {\n boundaryVariant.first.replaceWith(boundaryScope);\n } else {\n boundaryVariant.prepend(boundaryScope);\n }\n root.insertBefore(selector, boundaryVariant);\n }\n }\n\n const descendantScope = selectorParser().astSync(`${scopeSelector} *`).first;\n const prefixNodes = descendantScope.nodes.slice(0, -1).map((node) => node.clone());\n selector.first.rawSpaceBefore = '';\n for (const prefixNode of prefixNodes.reverse()) {\n selector.prepend(prefixNode);\n }\n }\n\n const seenSelectors = new Set<string>();\n for (const selector of [...root.nodes]) {\n const normalizedSelector = selector.toString().trim();\n if (seenSelectors.has(normalizedSelector)) {\n selector.remove();\n } else {\n seenSelectors.add(normalizedSelector);\n }\n }\n }).processSync(selectorList);\n};\n\nconst findFunctionalPseudoEnd = (selector: string, openParenthesisIndex: number): number => {\n let depth = 0;\n let quote: '\"' | \"'\" | undefined;\n\n for (let index = openParenthesisIndex; index < selector.length; index += 1) {\n const character = selector[index];\n const previousCharacter = selector[index - 1];\n\n if (quote) {\n if (character === quote && previousCharacter !== '\\\\') {\n quote = undefined;\n }\n continue;\n }\n\n if (character === '\"' || character === \"'\") {\n quote = character;\n continue;\n }\n\n if (character === '(') {\n depth += 1;\n } else if (character === ')') {\n depth -= 1;\n if (depth === 0) {\n return index;\n }\n }\n }\n\n return -1;\n};\n\nconst scopeAngularSelector = (selector: string, boundarySelector: string): string => {\n const normalizedSelector = selector.trim();\n const angularBoundary = `:host-context(${boundarySelector})`;\n const normalizedBoundary = normalizedSelector.slice(0, angularBoundary.length).replaceAll(\"'\", '\"');\n\n if (normalizedBoundary === angularBoundary) {\n return normalizedSelector;\n }\n\n if (/^:host-context\\(/i.test(normalizedSelector)) {\n return `${angularBoundary}${normalizedSelector}`;\n }\n\n if (/^:host\\(/i.test(normalizedSelector)) {\n const openParenthesisIndex = normalizedSelector.indexOf('(');\n const closeParenthesisIndex = findFunctionalPseudoEnd(normalizedSelector, openParenthesisIndex);\n if (closeParenthesisIndex !== -1) {\n const hostSelector = normalizedSelector.slice(openParenthesisIndex + 1, closeParenthesisIndex);\n const remainder = normalizedSelector.slice(closeParenthesisIndex + 1);\n return list\n .comma(hostSelector)\n .map((hostSelectorVariant) => `${angularBoundary}${hostSelectorVariant}${remainder}`)\n .join(', ');\n }\n }\n\n if (/^:host\\b/i.test(normalizedSelector)) {\n return normalizedSelector.replace(/^:host\\b/i, angularBoundary);\n }\n\n return `${angularBoundary} ${normalizedSelector}`;\n};\n\nconst scopeAngularSelectorList = (selectorList: string, boundarySelector: string): string => {\n return list\n .comma(selectorList)\n .map((selector) => scopeAngularSelector(selector, boundarySelector))\n .join(', ');\n};\n\nconst namespaceKeyframes = (root: Root, keyframePrefix: string): void => {\n const keyframes = new Map<string, string>();\n\n root.walkAtRules((atRule) => {\n if (!/keyframes$/i.test(atRule.name) || atRule.params.startsWith(keyframePrefix)) {\n return;\n }\n\n const originalName = atRule.params.trim();\n const scopedName = `${keyframePrefix}${originalName}`;\n keyframes.set(originalName, scopedName);\n atRule.params = scopedName;\n });\n\n root.walkDecls((declaration) => {\n if (!/^(?:-webkit-)?animation(?:-name)?$/i.test(declaration.prop) && !declaration.prop.startsWith('--animate-')) {\n return;\n }\n\n const parsed = valueParser(declaration.value);\n parsed.walk((node) => {\n if (node.type === 'word') {\n node.value = keyframes.get(node.value) ?? node.value;\n }\n });\n declaration.value = parsed.toString();\n });\n};\n\nconst INITIAL_FONT_SIZE_PX = 16;\n// Absolute-size keywords as browsers compute them, and the relative ones as they resolve on the root, whose parent size\n// is the initial 16px.\nconst FONT_SIZE_KEYWORDS_PX: Readonly<Record<string, number>> = {\n 'xx-small': 9,\n 'x-small': 10,\n small: 13,\n medium: 16,\n large: 18,\n 'x-large': 24,\n 'xx-large': 32,\n 'xxx-large': 48,\n smaller: INITIAL_FONT_SIZE_PX / 1.2,\n larger: INITIAL_FONT_SIZE_PX * 1.2,\n};\n// On the root, every global keyword gives the initial size.\nconst GLOBAL_KEYWORDS = new Set(['inherit', 'initial', 'revert', 'revert-layer', 'unset']);\n// em, rem and % on the root are relative to the initial size.\nconst FONT_SIZE_UNITS_PX: Readonly<Record<string, number>> = {\n '%': INITIAL_FONT_SIZE_PX / 100,\n cm: 96 / 2.54,\n em: INITIAL_FONT_SIZE_PX,\n in: 96,\n mm: 96 / 25.4,\n pc: 16,\n pt: 96 / 72,\n px: 1,\n q: 96 / 101.6,\n rem: INITIAL_FONT_SIZE_PX,\n};\n\nconst fontSizeOfWord = (word: string): number | undefined => {\n const keyword = FONT_SIZE_KEYWORDS_PX[word.toLowerCase()];\n if (keyword !== undefined) {\n return keyword;\n }\n const dimension = valueParser.unit(word);\n const unitPx = dimension ? FONT_SIZE_UNITS_PX[dimension.unit.toLowerCase()] : undefined;\n const amount = Number(dimension ? dimension.number : Number.NaN);\n return unitPx !== undefined && Number.isFinite(amount) && amount >= 0 ? amount * unitPx : undefined;\n};\n\nconst significantValueNodes = (value: string): valueParser.Node[] => {\n return valueParser(value).nodes.filter((node) => node.type !== 'space' && node.type !== 'comment');\n};\n\nconst globalKeywordFontSize = (nodes: valueParser.Node[]): number | undefined => {\n const [only] = nodes;\n return nodes.length === 1 && only?.type === 'word' && GLOBAL_KEYWORDS.has(only.value.toLowerCase()) ? INITIAL_FONT_SIZE_PX : undefined;\n};\n\nconst resolveFontSize = (value: string): number | undefined => {\n const nodes = significantValueNodes(value);\n const [only] = nodes;\n return globalKeywordFontSize(nodes) ?? (nodes.length === 1 && only?.type === 'word' ? fontSizeOfWord(only.value) : undefined);\n};\n\n// `font: [style] [variant] [weight] [stretch] <size>[/<line-height>] <family>`: the size is the word before `/`, or else\n// the first word that is a size. A function (var(), calc()) or a family name reached first means it cannot be read.\nconst resolveFontShorthandSize = (value: string): number | undefined => {\n const nodes = significantValueNodes(value);\n const globalSize = globalKeywordFontSize(nodes);\n if (globalSize !== undefined) {\n return globalSize;\n }\n\n const slashIndex = nodes.findIndex((node) => node.type === 'div' && node.value === '/');\n if (slashIndex > 0) {\n const size = nodes[slashIndex - 1];\n return size?.type === 'word' ? fontSizeOfWord(size.value) : undefined;\n }\n\n for (const node of nodes) {\n if (node.type !== 'word') {\n return undefined;\n }\n const size = fontSizeOfWord(node.value);\n if (size !== undefined) {\n return size;\n }\n }\n return undefined;\n};\n\n// `html` and `:root` size the document root, so rem; `body` and `html body` size only the body.\nconst targetsDocumentRoot = (selector: selectorParser.Selector): boolean => {\n let subject: selectorParser.Node[] = [];\n for (const node of selector.nodes) {\n subject = node.type === 'combinator' ? [] : [...subject, node];\n }\n return subject.some((node) => (node.type === 'tag' && node.value.toLowerCase() === 'html') || (node.type === 'pseudo' && node.value === ':root'));\n};\n\nconst documentRootSelectorsOf = (selectorList: string): string[] => {\n const selectors: string[] = [];\n selectorParser((root) => {\n for (const selector of root.nodes) {\n if (targetsDocumentRoot(selector)) {\n selectors.push(selector.toString().trim());\n }\n }\n }).processSync(selectorList);\n return selectors;\n};\n\ntype TWarn = (node: Declaration, text: string) => void;\n\n// Hosted, rem resolves against the host page's root, not the root size the module's own page set. Each rule that sizes\n// the document root gets a sibling rule right after it that records that size as MF_ROOT_FONT_SIZE_PROPERTY, under the\n// same conditions (@media, importance) and in the same cascade order; scoping then moves it onto the module boundary,\n// where followModuleRootFontSize() makes rem lengths read it. CSS that never sizes the root is left byte-identical.\nconst recordRootFontSize = (root: Root, warn: TWarn): void => {\n root.walkRules((rule) => {\n if (isKeyframesRule(rule)) {\n return;\n }\n\n let sizing: Declaration | undefined;\n for (const node of rule.nodes) {\n if (node.type === 'decl' && /^font(?:-size)?$/i.test(node.prop) && (node.important || !sizing?.important)) {\n sizing = node;\n }\n }\n if (!sizing) {\n return;\n }\n\n const rootSelectors = documentRootSelectorsOf(rule.selector);\n if (rootSelectors.length === 0) {\n return;\n }\n\n const sizePx = sizing.prop.toLowerCase() === 'font' ? resolveFontShorthandSize(sizing.value) : resolveFontSize(sizing.value);\n if (sizePx === undefined) {\n warn(\n sizing,\n `Cannot resolve the document root font size \"${sizing.value}\" at build time; rem lengths in the hosted module will use the host page's root size.`,\n );\n return;\n }\n\n const recorded = rule.clone({ selector: rootSelectors.join(', ') });\n recorded.raws.before = rule.raws.before || '\\n';\n recorded.removeAll();\n // The recorded size points back at the declaration it came from, so source maps keep a source for it.\n recorded.append({\n important: sizing.important,\n prop: MF_ROOT_FONT_SIZE_PROPERTY,\n source: sizing.source,\n value: `${Number(sizePx.toFixed(4))}px`,\n });\n rule.after(recorded);\n });\n};\n\nconst scopeGlobalRoot = (root: Root, scopeId: string, scopeSelector: string, keyframePrefix: string, warn: TWarn): void => {\n recordRootFontSize(root, warn);\n namespaceKeyframes(root, keyframePrefix);\n const contentRootSelector = `:where([${MF_SCOPE_ATTRIBUTE}=\"${scopeId}\"]:not([${MF_OVERLAY_ATTRIBUTE}]))`;\n root.walkRules((rule) => {\n if (!isKeyframesRule(rule)) {\n const declarations = rule.nodes.filter((node) => node.type === 'decl');\n const customProperties = declarations.filter((declaration) => declaration.prop.startsWith('--'));\n const standardDeclarations = declarations.filter((declaration) => !declaration.prop.startsWith('--'));\n\n if (customProperties.length > 0 && standardDeclarations.length > 0 && hasRootOnlySelector(rule.selector)) {\n const customPropertyRule = rule.cloneBefore();\n customPropertyRule.walkDecls((declaration) => {\n if (!declaration.prop.startsWith('--')) {\n declaration.remove();\n }\n });\n customPropertyRule.selector = scopeSelectorList(customPropertyRule.selector, scopeId, scopeSelector, [':host', scopeSelector]);\n rule.walkDecls((declaration) => {\n if (declaration.prop.startsWith('--')) {\n declaration.remove();\n }\n });\n }\n\n const containsOnlyCustomProperties = declarations.length > 0 && declarations.every((declaration) => declaration.prop.startsWith('--'));\n const rootScopeSelectors = containsOnlyCustomProperties ? [':host', scopeSelector] : [':host', contentRootSelector];\n rule.selector = scopeSelectorList(rule.selector, scopeId, scopeSelector, rootScopeSelectors);\n }\n });\n};\n\nconst scopeAngularComponentRoot = (root: Root, boundarySelector: string, keyframePrefix: string): void => {\n namespaceKeyframes(root, keyframePrefix);\n root.walkRules((rule) => {\n if (!isKeyframesRule(rule)) {\n rule.selector = scopeAngularSelectorList(rule.selector, boundarySelector);\n }\n });\n};\n\nexport const scopeRemoteCss = ({ scopeId }: IScopeRemoteCssOptions): Plugin => {\n const validScopeId = validateMfScopeId(scopeId);\n const scopeSelector = getMfScopeSelector(validScopeId);\n const keyframePrefix = `edyn-mf-${validScopeId}--`;\n\n return {\n postcssPlugin: `edyn-mf-isolation-${validScopeId}`,\n Once(root, { result }) {\n scopeGlobalRoot(root, validScopeId, scopeSelector, keyframePrefix, (node, text) => node.warn(result, text));\n },\n };\n};\n\nexport const scopeAngularRemoteCss = ({ scopeId }: IScopeRemoteCssOptions): Plugin => {\n const validScopeId = validateMfScopeId(scopeId);\n const scopeSelector = getMfScopeSelector(validScopeId);\n const boundarySelector = `[${MF_SCOPE_ATTRIBUTE}=\"${validScopeId}\"]`;\n const keyframePrefix = `edyn-mf-${validScopeId}--`;\n\n return {\n postcssPlugin: `edyn-mf-angular-isolation-${validScopeId}`,\n Once(root, { result }) {\n if (shouldUseAngularComponentScoping(root.source?.input.file)) {\n scopeAngularComponentRoot(root, boundarySelector, keyframePrefix);\n return;\n }\n\n scopeGlobalRoot(root, validScopeId, scopeSelector, keyframePrefix, (node, text) => node.warn(result, text));\n },\n };\n};\n"]}
@@ -0,0 +1,11 @@
1
+ export declare const MF_ROOT_FONT_SIZE_PROPERTY = "--edyn-mf-rem";
2
+ /** Rewrites every rem length in CSS declaration text to follow the module's root font size; running it again changes nothing. */
3
+ export declare const rewriteRemLengths: (declarations: string) => string;
4
+ /**
5
+ * Makes rem lengths in a hosted module's shadow root follow the root font size its own page had, once the module's
6
+ * CSS declares one (see MF_ROOT_FONT_SIZE_PROPERTY). Covers stylesheets already in the root and every one added or
7
+ * changed later, such as the component styles Angular adds as components first render. A module whose CSS never sizes
8
+ * its root is left untouched. Returns a function that stops following; rewritten rules stay rewritten.
9
+ */
10
+ export declare const followModuleRootFontSize: (root: ShadowRoot) => (() => void);
11
+ //# sourceMappingURL=root-font-size.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-font-size.d.ts","sourceRoot":"","sources":["../src/root-font-size.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,0BAA0B,kBAAkB,CAAC;AAc1D,iIAAiI;AACjI,eAAO,MAAM,iBAAiB,GAAI,cAAc,MAAM,KAAG,MAQxD,CAAC;AAuEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GAAI,MAAM,UAAU,KAAG,CAAC,MAAM,IAAI,CA+DtE,CAAC","sourcesContent":["// `rem` always resolves against the page's <html>, even inside a shadow root. A module page that sized its own root\n// (`html, body { font-size: 12px }`) drew every rem length from that size, but hosted, the same lengths use the host\n// page's root (16px): Material's `.mat-mdc-button > .mat-icon { font-size: 1.125rem }` drew 13.5px on the old page and\n// 18px hosted. The build-time PostCSS plugin records the module's root size as this property on the module boundary;\n// followModuleRootFontSize() rewrites every rem length in the module's shadow root to read it.\nexport const MF_ROOT_FONT_SIZE_PROPERTY = '--edyn-mf-rem';\n\nconst ROOT_FONT_SIZE_FALLBACK = `var(${MF_ROOT_FONT_SIZE_PROPERTY}, 1rem)`;\nconst ROOT_FONT_SIZE_DECLARATION_PATTERN = new RegExp(`${MF_ROOT_FONT_SIZE_PROPERTY}\\\\s*:`);\nconst REM_LENGTH_HINT_PATTERN = /\\drem/i;\n// A number with the rem unit that is not part of an identifier (`foo-2rem`) and not the fallback this rewrite writes.\nconst REM_LENGTH_PATTERN = new RegExp(`(?<![\\\\w.-]|var\\\\(${MF_ROOT_FONT_SIZE_PROPERTY},\\\\s*)(-?(?:\\\\d+\\\\.?\\\\d*|\\\\.\\\\d+))rem(?![\\\\w-])`, 'gi');\n// Strings and url() keep their text: `content: \"2rem\"` or `url(2rem.png)` are not lengths.\nconst VERBATIM_PATTERN = /\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'|url\\((?:[^()\"'\\\\]|\\\\.)*\\)/gi;\n\nconst rewriteOutsideVerbatim = (text: string): string => {\n return text.replace(REM_LENGTH_PATTERN, (_match, amount: string) => `calc(${amount} * ${ROOT_FONT_SIZE_FALLBACK})`);\n};\n\n/** Rewrites every rem length in CSS declaration text to follow the module's root font size; running it again changes nothing. */\nexport const rewriteRemLengths = (declarations: string): string => {\n let rewritten = '';\n let start = 0;\n for (const verbatim of declarations.matchAll(VERBATIM_PATTERN)) {\n rewritten += rewriteOutsideVerbatim(declarations.slice(start, verbatim.index)) + verbatim[0];\n start = verbatim.index + verbatim[0].length;\n }\n return rewritten + rewriteOutsideVerbatim(declarations.slice(start));\n};\n\nconst isFontFaceRule = (rule: CSSRule): boolean => {\n return typeof CSSFontFaceRule !== 'undefined' && rule instanceof CSSFontFaceRule;\n};\n\n// Rule kinds are told apart by what they carry, not by class: @import has a sheet, style and keyframe rules have\n// declarations, and grouping rules (@media, @supports, @container, @layer, @keyframes, nesting) have child rules.\nconst importedSheetOf = (rule: CSSRule): CSSStyleSheet | undefined => {\n return 'styleSheet' in rule && rule.styleSheet ? (rule.styleSheet as CSSStyleSheet) : undefined;\n};\n\nconst declarationsOf = (rule: CSSRule): CSSStyleDeclaration | undefined => {\n return 'style' in rule && rule.style && !isFontFaceRule(rule) ? (rule.style as CSSStyleDeclaration) : undefined;\n};\n\nconst childRulesOf = (rule: CSSRule): CSSRuleList | undefined => {\n return 'cssRules' in rule && rule.cssRules ? (rule.cssRules as CSSRuleList) : undefined;\n};\n\n// Only declaration blocks change, through the CSSOM: @media, @container and @supports conditions keep their rem (var()\n// is invalid there, and a media query rem is the browser's initial size anyway), and !important stays with its value.\nconst rewriteRules = (rules: CSSRuleList): void => {\n for (const rule of Array.from(rules)) {\n const importedSheet = importedSheetOf(rule);\n if (importedSheet) {\n rewriteSheet(importedSheet);\n }\n const declarations = declarationsOf(rule);\n if (declarations && REM_LENGTH_HINT_PATTERN.test(declarations.cssText)) {\n const rewritten = rewriteRemLengths(declarations.cssText);\n if (rewritten !== declarations.cssText) {\n declarations.cssText = rewritten;\n }\n }\n const childRules = childRulesOf(rule);\n if (childRules) {\n rewriteRules(childRules);\n }\n }\n};\n\nconst readRules = (sheet: CSSStyleSheet): CSSRuleList | undefined => {\n try {\n return sheet.cssRules;\n } catch {\n // A cross-origin sheet (a font service's @font-face list) cannot be read, and none of its rules are module rules.\n return undefined;\n }\n};\n\nconst rewriteSheet = (sheet: CSSStyleSheet): void => {\n const rules = readRules(sheet);\n if (rules) {\n rewriteRules(rules);\n }\n};\n\nconst declaresRootFontSize = (rules: CSSRuleList): boolean => {\n return Array.from(rules).some((rule) => {\n const childRules = childRulesOf(rule);\n return !!declarationsOf(rule)?.getPropertyValue(MF_ROOT_FONT_SIZE_PROPERTY) || (!!childRules && declaresRootFontSize(childRules));\n });\n};\n\ntype TStyleOwner = HTMLLinkElement | HTMLStyleElement;\n\nconst isStyleOwner = (node: Node): node is TStyleOwner => {\n return node.nodeName === 'STYLE' || (node.nodeName === 'LINK' && (node as HTMLLinkElement).rel.split(/\\s+/).includes('stylesheet'));\n};\n\n/**\n * Makes rem lengths in a hosted module's shadow root follow the root font size its own page had, once the module's\n * CSS declares one (see MF_ROOT_FONT_SIZE_PROPERTY). Covers stylesheets already in the root and every one added or\n * changed later, such as the component styles Angular adds as components first render. A module whose CSS never sizes\n * its root is left untouched. Returns a function that stops following; rewritten rules stay rewritten.\n */\nexport const followModuleRootFontSize = (root: ShadowRoot): (() => void) => {\n let following = false;\n const rewrittenSheets = new WeakSet<CSSStyleSheet>();\n const watchedOwners = new WeakSet<TStyleOwner>();\n\n const owners = (): TStyleOwner[] => Array.from(root.childNodes).filter(isStyleOwner);\n\n const sheetsOf = (styleOwners: TStyleOwner[]): CSSStyleSheet[] => {\n return [...(root.adoptedStyleSheets ?? []), ...styleOwners.map((owner) => owner.sheet).filter((sheet): sheet is CSSStyleSheet => !!sheet)];\n };\n\n // A <style>'s own text is the cheap check; linked and adopted sheets have only their rules.\n const findsRootFontSize = (styleOwners: TStyleOwner[]): boolean => {\n const styles = styleOwners.filter((owner) => owner.nodeName === 'STYLE');\n if (styles.some((style) => ROOT_FONT_SIZE_DECLARATION_PATTERN.test(style.textContent ?? ''))) {\n return true;\n }\n return sheetsOf(styleOwners.filter((owner) => owner.nodeName === 'LINK')).some((sheet) => {\n const rules = readRules(sheet);\n return !!rules && declaresRootFontSize(rules);\n });\n };\n\n const observer = new MutationObserver(() => update());\n\n const update = (): void => {\n const styleOwners = owners();\n for (const owner of styleOwners) {\n if (owner.nodeName === 'STYLE' && !watchedOwners.has(owner)) {\n // Replacing a <style>'s text gives it a new sheet, which must be rewritten again.\n observer.observe(owner, { characterData: true, childList: true, subtree: true });\n watchedOwners.add(owner);\n }\n }\n\n following ||= findsRootFontSize(styleOwners);\n if (!following) {\n return;\n }\n\n for (const sheet of sheetsOf(styleOwners)) {\n if (!rewrittenSheets.has(sheet)) {\n rewriteSheet(sheet);\n rewrittenSheets.add(sheet);\n }\n }\n };\n\n // A <link> sheet has no rules until it loads; load does not bubble, so it is caught on the way down.\n const onLoad = (event: Event): void => {\n if (event.target instanceof Node && isStyleOwner(event.target)) {\n update();\n }\n };\n\n observer.observe(root, { childList: true });\n root.addEventListener('load', onLoad, true);\n update();\n\n return () => {\n observer.disconnect();\n root.removeEventListener('load', onLoad, true);\n };\n};\n"]}
@@ -0,0 +1,146 @@
1
+ // `rem` always resolves against the page's <html>, even inside a shadow root. A module page that sized its own root
2
+ // (`html, body { font-size: 12px }`) drew every rem length from that size, but hosted, the same lengths use the host
3
+ // page's root (16px): Material's `.mat-mdc-button > .mat-icon { font-size: 1.125rem }` drew 13.5px on the old page and
4
+ // 18px hosted. The build-time PostCSS plugin records the module's root size as this property on the module boundary;
5
+ // followModuleRootFontSize() rewrites every rem length in the module's shadow root to read it.
6
+ export const MF_ROOT_FONT_SIZE_PROPERTY = '--edyn-mf-rem';
7
+ const ROOT_FONT_SIZE_FALLBACK = `var(${MF_ROOT_FONT_SIZE_PROPERTY}, 1rem)`;
8
+ const ROOT_FONT_SIZE_DECLARATION_PATTERN = new RegExp(`${MF_ROOT_FONT_SIZE_PROPERTY}\\s*:`);
9
+ const REM_LENGTH_HINT_PATTERN = /\drem/i;
10
+ // A number with the rem unit that is not part of an identifier (`foo-2rem`) and not the fallback this rewrite writes.
11
+ const REM_LENGTH_PATTERN = new RegExp(`(?<![\\w.-]|var\\(${MF_ROOT_FONT_SIZE_PROPERTY},\\s*)(-?(?:\\d+\\.?\\d*|\\.\\d+))rem(?![\\w-])`, 'gi');
12
+ // Strings and url() keep their text: `content: "2rem"` or `url(2rem.png)` are not lengths.
13
+ const VERBATIM_PATTERN = /"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|url\((?:[^()"'\\]|\\.)*\)/gi;
14
+ const rewriteOutsideVerbatim = (text) => {
15
+ return text.replace(REM_LENGTH_PATTERN, (_match, amount) => `calc(${amount} * ${ROOT_FONT_SIZE_FALLBACK})`);
16
+ };
17
+ /** Rewrites every rem length in CSS declaration text to follow the module's root font size; running it again changes nothing. */
18
+ export const rewriteRemLengths = (declarations) => {
19
+ let rewritten = '';
20
+ let start = 0;
21
+ for (const verbatim of declarations.matchAll(VERBATIM_PATTERN)) {
22
+ rewritten += rewriteOutsideVerbatim(declarations.slice(start, verbatim.index)) + verbatim[0];
23
+ start = verbatim.index + verbatim[0].length;
24
+ }
25
+ return rewritten + rewriteOutsideVerbatim(declarations.slice(start));
26
+ };
27
+ const isFontFaceRule = (rule) => {
28
+ return typeof CSSFontFaceRule !== 'undefined' && rule instanceof CSSFontFaceRule;
29
+ };
30
+ // Rule kinds are told apart by what they carry, not by class: @import has a sheet, style and keyframe rules have
31
+ // declarations, and grouping rules (@media, @supports, @container, @layer, @keyframes, nesting) have child rules.
32
+ const importedSheetOf = (rule) => {
33
+ return 'styleSheet' in rule && rule.styleSheet ? rule.styleSheet : undefined;
34
+ };
35
+ const declarationsOf = (rule) => {
36
+ return 'style' in rule && rule.style && !isFontFaceRule(rule) ? rule.style : undefined;
37
+ };
38
+ const childRulesOf = (rule) => {
39
+ return 'cssRules' in rule && rule.cssRules ? rule.cssRules : undefined;
40
+ };
41
+ // Only declaration blocks change, through the CSSOM: @media, @container and @supports conditions keep their rem (var()
42
+ // is invalid there, and a media query rem is the browser's initial size anyway), and !important stays with its value.
43
+ const rewriteRules = (rules) => {
44
+ for (const rule of Array.from(rules)) {
45
+ const importedSheet = importedSheetOf(rule);
46
+ if (importedSheet) {
47
+ rewriteSheet(importedSheet);
48
+ }
49
+ const declarations = declarationsOf(rule);
50
+ if (declarations && REM_LENGTH_HINT_PATTERN.test(declarations.cssText)) {
51
+ const rewritten = rewriteRemLengths(declarations.cssText);
52
+ if (rewritten !== declarations.cssText) {
53
+ declarations.cssText = rewritten;
54
+ }
55
+ }
56
+ const childRules = childRulesOf(rule);
57
+ if (childRules) {
58
+ rewriteRules(childRules);
59
+ }
60
+ }
61
+ };
62
+ const readRules = (sheet) => {
63
+ try {
64
+ return sheet.cssRules;
65
+ }
66
+ catch {
67
+ // A cross-origin sheet (a font service's @font-face list) cannot be read, and none of its rules are module rules.
68
+ return undefined;
69
+ }
70
+ };
71
+ const rewriteSheet = (sheet) => {
72
+ const rules = readRules(sheet);
73
+ if (rules) {
74
+ rewriteRules(rules);
75
+ }
76
+ };
77
+ const declaresRootFontSize = (rules) => {
78
+ return Array.from(rules).some((rule) => {
79
+ const childRules = childRulesOf(rule);
80
+ return !!declarationsOf(rule)?.getPropertyValue(MF_ROOT_FONT_SIZE_PROPERTY) || (!!childRules && declaresRootFontSize(childRules));
81
+ });
82
+ };
83
+ const isStyleOwner = (node) => {
84
+ return node.nodeName === 'STYLE' || (node.nodeName === 'LINK' && node.rel.split(/\s+/).includes('stylesheet'));
85
+ };
86
+ /**
87
+ * Makes rem lengths in a hosted module's shadow root follow the root font size its own page had, once the module's
88
+ * CSS declares one (see MF_ROOT_FONT_SIZE_PROPERTY). Covers stylesheets already in the root and every one added or
89
+ * changed later, such as the component styles Angular adds as components first render. A module whose CSS never sizes
90
+ * its root is left untouched. Returns a function that stops following; rewritten rules stay rewritten.
91
+ */
92
+ export const followModuleRootFontSize = (root) => {
93
+ let following = false;
94
+ const rewrittenSheets = new WeakSet();
95
+ const watchedOwners = new WeakSet();
96
+ const owners = () => Array.from(root.childNodes).filter(isStyleOwner);
97
+ const sheetsOf = (styleOwners) => {
98
+ return [...(root.adoptedStyleSheets ?? []), ...styleOwners.map((owner) => owner.sheet).filter((sheet) => !!sheet)];
99
+ };
100
+ // A <style>'s own text is the cheap check; linked and adopted sheets have only their rules.
101
+ const findsRootFontSize = (styleOwners) => {
102
+ const styles = styleOwners.filter((owner) => owner.nodeName === 'STYLE');
103
+ if (styles.some((style) => ROOT_FONT_SIZE_DECLARATION_PATTERN.test(style.textContent ?? ''))) {
104
+ return true;
105
+ }
106
+ return sheetsOf(styleOwners.filter((owner) => owner.nodeName === 'LINK')).some((sheet) => {
107
+ const rules = readRules(sheet);
108
+ return !!rules && declaresRootFontSize(rules);
109
+ });
110
+ };
111
+ const observer = new MutationObserver(() => update());
112
+ const update = () => {
113
+ const styleOwners = owners();
114
+ for (const owner of styleOwners) {
115
+ if (owner.nodeName === 'STYLE' && !watchedOwners.has(owner)) {
116
+ // Replacing a <style>'s text gives it a new sheet, which must be rewritten again.
117
+ observer.observe(owner, { characterData: true, childList: true, subtree: true });
118
+ watchedOwners.add(owner);
119
+ }
120
+ }
121
+ following ||= findsRootFontSize(styleOwners);
122
+ if (!following) {
123
+ return;
124
+ }
125
+ for (const sheet of sheetsOf(styleOwners)) {
126
+ if (!rewrittenSheets.has(sheet)) {
127
+ rewriteSheet(sheet);
128
+ rewrittenSheets.add(sheet);
129
+ }
130
+ }
131
+ };
132
+ // A <link> sheet has no rules until it loads; load does not bubble, so it is caught on the way down.
133
+ const onLoad = (event) => {
134
+ if (event.target instanceof Node && isStyleOwner(event.target)) {
135
+ update();
136
+ }
137
+ };
138
+ observer.observe(root, { childList: true });
139
+ root.addEventListener('load', onLoad, true);
140
+ update();
141
+ return () => {
142
+ observer.disconnect();
143
+ root.removeEventListener('load', onLoad, true);
144
+ };
145
+ };
146
+ //# sourceMappingURL=root-font-size.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-font-size.js","sourceRoot":"","sources":["../src/root-font-size.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,qHAAqH;AACrH,uHAAuH;AACvH,qHAAqH;AACrH,+FAA+F;AAC/F,MAAM,CAAC,MAAM,0BAA0B,GAAG,eAAe,CAAC;AAE1D,MAAM,uBAAuB,GAAG,OAAO,0BAA0B,SAAS,CAAC;AAC3E,MAAM,kCAAkC,GAAG,IAAI,MAAM,CAAC,GAAG,0BAA0B,OAAO,CAAC,CAAC;AAC5F,MAAM,uBAAuB,GAAG,QAAQ,CAAC;AACzC,sHAAsH;AACtH,MAAM,kBAAkB,GAAG,IAAI,MAAM,CAAC,qBAAqB,0BAA0B,iDAAiD,EAAE,IAAI,CAAC,CAAC;AAC9I,2FAA2F;AAC3F,MAAM,gBAAgB,GAAG,iEAAiE,CAAC;AAE3F,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAU,EAAE;IACtD,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,MAAc,EAAE,EAAE,CAAC,QAAQ,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC;AACtH,CAAC,CAAC;AAEF,iIAAiI;AACjI,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,YAAoB,EAAU,EAAE;IAChE,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,QAAQ,IAAI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C,WAAW,CAAC,CAAC;QAC7C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO;QACT,CAAC;QAED,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC1C,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBAChC,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,qGAAqG;IACrG,MAAM,MAAM,GAAG,CAAC,KAAY,EAAQ,EAAE;QACpC,IAAI,KAAK,CAAC,MAAM,YAAY,IAAI,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;YAC/D,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC,CAAC;IAEF,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAC5C,MAAM,EAAE,CAAC;IAET,OAAO,GAAG,EAAE;QACV,QAAQ,CAAC,UAAU,EAAE,CAAC;QACtB,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACjD,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// `rem` always resolves against the page's <html>, even inside a shadow root. A module page that sized its own root\n// (`html, body { font-size: 12px }`) drew every rem length from that size, but hosted, the same lengths use the host\n// page's root (16px): Material's `.mat-mdc-button > .mat-icon { font-size: 1.125rem }` drew 13.5px on the old page and\n// 18px hosted. The build-time PostCSS plugin records the module's root size as this property on the module boundary;\n// followModuleRootFontSize() rewrites every rem length in the module's shadow root to read it.\nexport const MF_ROOT_FONT_SIZE_PROPERTY = '--edyn-mf-rem';\n\nconst ROOT_FONT_SIZE_FALLBACK = `var(${MF_ROOT_FONT_SIZE_PROPERTY}, 1rem)`;\nconst ROOT_FONT_SIZE_DECLARATION_PATTERN = new RegExp(`${MF_ROOT_FONT_SIZE_PROPERTY}\\\\s*:`);\nconst REM_LENGTH_HINT_PATTERN = /\\drem/i;\n// A number with the rem unit that is not part of an identifier (`foo-2rem`) and not the fallback this rewrite writes.\nconst REM_LENGTH_PATTERN = new RegExp(`(?<![\\\\w.-]|var\\\\(${MF_ROOT_FONT_SIZE_PROPERTY},\\\\s*)(-?(?:\\\\d+\\\\.?\\\\d*|\\\\.\\\\d+))rem(?![\\\\w-])`, 'gi');\n// Strings and url() keep their text: `content: \"2rem\"` or `url(2rem.png)` are not lengths.\nconst VERBATIM_PATTERN = /\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'|url\\((?:[^()\"'\\\\]|\\\\.)*\\)/gi;\n\nconst rewriteOutsideVerbatim = (text: string): string => {\n return text.replace(REM_LENGTH_PATTERN, (_match, amount: string) => `calc(${amount} * ${ROOT_FONT_SIZE_FALLBACK})`);\n};\n\n/** Rewrites every rem length in CSS declaration text to follow the module's root font size; running it again changes nothing. */\nexport const rewriteRemLengths = (declarations: string): string => {\n let rewritten = '';\n let start = 0;\n for (const verbatim of declarations.matchAll(VERBATIM_PATTERN)) {\n rewritten += rewriteOutsideVerbatim(declarations.slice(start, verbatim.index)) + verbatim[0];\n start = verbatim.index + verbatim[0].length;\n }\n return rewritten + rewriteOutsideVerbatim(declarations.slice(start));\n};\n\nconst isFontFaceRule = (rule: CSSRule): boolean => {\n return typeof CSSFontFaceRule !== 'undefined' && rule instanceof CSSFontFaceRule;\n};\n\n// Rule kinds are told apart by what they carry, not by class: @import has a sheet, style and keyframe rules have\n// declarations, and grouping rules (@media, @supports, @container, @layer, @keyframes, nesting) have child rules.\nconst importedSheetOf = (rule: CSSRule): CSSStyleSheet | undefined => {\n return 'styleSheet' in rule && rule.styleSheet ? (rule.styleSheet as CSSStyleSheet) : undefined;\n};\n\nconst declarationsOf = (rule: CSSRule): CSSStyleDeclaration | undefined => {\n return 'style' in rule && rule.style && !isFontFaceRule(rule) ? (rule.style as CSSStyleDeclaration) : undefined;\n};\n\nconst childRulesOf = (rule: CSSRule): CSSRuleList | undefined => {\n return 'cssRules' in rule && rule.cssRules ? (rule.cssRules as CSSRuleList) : undefined;\n};\n\n// Only declaration blocks change, through the CSSOM: @media, @container and @supports conditions keep their rem (var()\n// is invalid there, and a media query rem is the browser's initial size anyway), and !important stays with its value.\nconst rewriteRules = (rules: CSSRuleList): void => {\n for (const rule of Array.from(rules)) {\n const importedSheet = importedSheetOf(rule);\n if (importedSheet) {\n rewriteSheet(importedSheet);\n }\n const declarations = declarationsOf(rule);\n if (declarations && REM_LENGTH_HINT_PATTERN.test(declarations.cssText)) {\n const rewritten = rewriteRemLengths(declarations.cssText);\n if (rewritten !== declarations.cssText) {\n declarations.cssText = rewritten;\n }\n }\n const childRules = childRulesOf(rule);\n if (childRules) {\n rewriteRules(childRules);\n }\n }\n};\n\nconst readRules = (sheet: CSSStyleSheet): CSSRuleList | undefined => {\n try {\n return sheet.cssRules;\n } catch {\n // A cross-origin sheet (a font service's @font-face list) cannot be read, and none of its rules are module rules.\n return undefined;\n }\n};\n\nconst rewriteSheet = (sheet: CSSStyleSheet): void => {\n const rules = readRules(sheet);\n if (rules) {\n rewriteRules(rules);\n }\n};\n\nconst declaresRootFontSize = (rules: CSSRuleList): boolean => {\n return Array.from(rules).some((rule) => {\n const childRules = childRulesOf(rule);\n return !!declarationsOf(rule)?.getPropertyValue(MF_ROOT_FONT_SIZE_PROPERTY) || (!!childRules && declaresRootFontSize(childRules));\n });\n};\n\ntype TStyleOwner = HTMLLinkElement | HTMLStyleElement;\n\nconst isStyleOwner = (node: Node): node is TStyleOwner => {\n return node.nodeName === 'STYLE' || (node.nodeName === 'LINK' && (node as HTMLLinkElement).rel.split(/\\s+/).includes('stylesheet'));\n};\n\n/**\n * Makes rem lengths in a hosted module's shadow root follow the root font size its own page had, once the module's\n * CSS declares one (see MF_ROOT_FONT_SIZE_PROPERTY). Covers stylesheets already in the root and every one added or\n * changed later, such as the component styles Angular adds as components first render. A module whose CSS never sizes\n * its root is left untouched. Returns a function that stops following; rewritten rules stay rewritten.\n */\nexport const followModuleRootFontSize = (root: ShadowRoot): (() => void) => {\n let following = false;\n const rewrittenSheets = new WeakSet<CSSStyleSheet>();\n const watchedOwners = new WeakSet<TStyleOwner>();\n\n const owners = (): TStyleOwner[] => Array.from(root.childNodes).filter(isStyleOwner);\n\n const sheetsOf = (styleOwners: TStyleOwner[]): CSSStyleSheet[] => {\n return [...(root.adoptedStyleSheets ?? []), ...styleOwners.map((owner) => owner.sheet).filter((sheet): sheet is CSSStyleSheet => !!sheet)];\n };\n\n // A <style>'s own text is the cheap check; linked and adopted sheets have only their rules.\n const findsRootFontSize = (styleOwners: TStyleOwner[]): boolean => {\n const styles = styleOwners.filter((owner) => owner.nodeName === 'STYLE');\n if (styles.some((style) => ROOT_FONT_SIZE_DECLARATION_PATTERN.test(style.textContent ?? ''))) {\n return true;\n }\n return sheetsOf(styleOwners.filter((owner) => owner.nodeName === 'LINK')).some((sheet) => {\n const rules = readRules(sheet);\n return !!rules && declaresRootFontSize(rules);\n });\n };\n\n const observer = new MutationObserver(() => update());\n\n const update = (): void => {\n const styleOwners = owners();\n for (const owner of styleOwners) {\n if (owner.nodeName === 'STYLE' && !watchedOwners.has(owner)) {\n // Replacing a <style>'s text gives it a new sheet, which must be rewritten again.\n observer.observe(owner, { characterData: true, childList: true, subtree: true });\n watchedOwners.add(owner);\n }\n }\n\n following ||= findsRootFontSize(styleOwners);\n if (!following) {\n return;\n }\n\n for (const sheet of sheetsOf(styleOwners)) {\n if (!rewrittenSheets.has(sheet)) {\n rewriteSheet(sheet);\n rewrittenSheets.add(sheet);\n }\n }\n };\n\n // A <link> sheet has no rules until it loads; load does not bubble, so it is caught on the way down.\n const onLoad = (event: Event): void => {\n if (event.target instanceof Node && isStyleOwner(event.target)) {\n update();\n }\n };\n\n observer.observe(root, { childList: true });\n root.addEventListener('load', onLoad, true);\n update();\n\n return () => {\n observer.disconnect();\n root.removeEventListener('load', onLoad, true);\n };\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edynamix/mf-isolation",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "description": "CSS and overlay isolation helpers for eDynamix microfrontends.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",