first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
@@ -0,0 +1,12 @@
import type { ExtendedCSSStyleSheet } from '@fluentui/merge-styles';
import type { MergeStylesShadowRootContextValue } from '../contexts/MergeStylesShadowRootContext';
export type AdoptedStylesheetHook = (stylesheetKey: string) => boolean;
export type AdoptedStylesheetExHook = (stylesheetKey: string, shadowCtx: MergeStylesShadowRootContextValue | undefined, rootMergeStyles: Map<string, ExtendedCSSStyleSheet>, win: Window | undefined) => boolean;
/**
* Use adopted stylesheets in the parent shadow root.
*/
export declare const useAdoptedStylesheet: AdoptedStylesheetHook;
/**
* Optimization for specific cases like nested customizables.
*/
export declare const useAdoptedStylesheetEx: AdoptedStylesheetExHook;
@@ -0,0 +1,109 @@
define(["require", "exports", "tslib", "react", "@fluentui/merge-styles", "@fluentui/react-window-provider", "./useMergeStylesRootStylesheets", "./useMergeStylesShadowRoot"], function (require, exports, tslib_1, React, merge_styles_1, react_window_provider_1, useMergeStylesRootStylesheets_1, useMergeStylesShadowRoot_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useAdoptedStylesheetEx = exports.useAdoptedStylesheet = void 0;
/**
* Use adopted stylesheets in the parent shadow root.
*/
var useAdoptedStylesheet = function (stylesheetKey) {
var shadowCtx = (0, useMergeStylesShadowRoot_1.useMergeStylesShadowRootContext)();
var rootMergeStyles = (0, useMergeStylesRootStylesheets_1.useMergeStylesRootStylesheets)();
var win = (0, react_window_provider_1.useWindow)();
return (0, exports.useAdoptedStylesheetEx)(stylesheetKey, shadowCtx, rootMergeStyles, win);
};
exports.useAdoptedStylesheet = useAdoptedStylesheet;
/**
* Optimization for specific cases like nested customizables.
*/
var useAdoptedStylesheetEx = function (stylesheetKey, shadowCtx, rootMergeStyles, win) {
var polyfillInsertListners = React.useRef({});
React.useEffect(function () {
if (!shadowCtx) {
return;
}
var polyfillListeners = polyfillInsertListners.current;
polyfillInsertListners.current = {};
return function () {
Object.keys(polyfillListeners).forEach(function (key) {
polyfillListeners[key]();
});
};
}, [win, stylesheetKey, shadowCtx]);
if (!shadowCtx) {
return false;
}
if (shadowCtx.shadowRoot && !shadowCtx.stylesheets.has(stylesheetKey)) {
var adoptableStyleSheet = rootMergeStyles.get(stylesheetKey);
if (adoptableStyleSheet && (win === null || win === void 0 ? void 0 : win.document)) {
adoptSheet(shadowCtx, win.document, stylesheetKey, adoptableStyleSheet, polyfillInsertListners.current);
}
}
return true;
};
exports.useAdoptedStylesheetEx = useAdoptedStylesheetEx;
var updatePolyfillSheet = function (shadowCtx, stylesheetKey, rule) {
var shadowRoot = shadowCtx.shadowRoot;
var style = shadowRoot.querySelector("[data-merge-styles-stylesheet-key=\"".concat(stylesheetKey, "\"]"));
if (style === null || style === void 0 ? void 0 : style.sheet) {
style.sheet.insertRule(rule);
}
};
var adoptSheet = function (shadowCtx, doc, stylesheetKey, stylesheet, listenerRef) {
var _a, _b, _c, _d, _e;
var shadowRoot = shadowCtx.shadowRoot;
shadowCtx.stylesheets.set(stylesheetKey, stylesheet);
if (merge_styles_1.SUPPORTS_CONSTRUCTABLE_STYLESHEETS) {
// Maintain the sort order of Fluent style sheets
var prevSheets = shadowRoot.adoptedStyleSheets;
var i = prevSheets.length;
var found = i === 0;
while (i >= 0 && !found) {
i--;
var prevSheet = prevSheets[i];
var prevSortOrder = (_b = (_a = prevSheet.metadata) === null || _a === void 0 ? void 0 : _a.sortOrder) !== null && _b !== void 0 ? _b : 0;
var sheetSortOrder = (_d = (_c = stylesheet.metadata) === null || _c === void 0 ? void 0 : _c.sortOrder) !== null && _d !== void 0 ? _d : 0;
if (prevSheet.bucketName === 'merge-styles' && prevSortOrder < sheetSortOrder) {
found = true;
}
}
if (merge_styles_1.SUPPORTS_MODIFYING_ADOPTED_STYLESHEETS) {
// The current spec allows the `adoptedStyleSheets` array to be modified.
// Previous versions of the spec required a new array to be created.
// For more details see: https://github.com/microsoft/fast/pull/6703
shadowRoot.adoptedStyleSheets.splice(i + 1, 0, stylesheet);
}
else {
shadowRoot.adoptedStyleSheets = tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([], shadowRoot.adoptedStyleSheets.slice(0, i + 1), true), [
stylesheet
], false), shadowRoot.adoptedStyleSheets.slice(i + 1), true);
}
}
else {
var style = doc.createElement('style');
style.setAttribute('data-merge-styles-stylesheet-key', stylesheetKey);
var otherStyles = shadowRoot.querySelectorAll('[data-merge-styles-stylesheet-key]');
if (otherStyles.length > 0) {
shadowRoot.insertBefore(style, otherStyles[otherStyles.length - 1].nextSibling);
}
else {
shadowRoot.insertBefore(style, shadowRoot.firstChild);
}
if (style.sheet) {
(0, merge_styles_1.cloneCSSStyleSheet)(stylesheet, style.sheet);
if (!listenerRef[stylesheetKey]) {
var onInsert = function (_a) {
var key = _a.key, rule = _a.rule;
if (key === stylesheetKey) {
if (shadowCtx && rule) {
updatePolyfillSheet(shadowCtx, key, rule);
}
}
};
var polyfillSheet = merge_styles_1.Stylesheet.getInstance((0, merge_styles_1.makeShadowConfig)(stylesheetKey, true, (_e = doc.defaultView) !== null && _e !== void 0 ? _e : undefined));
listenerRef[stylesheetKey] = polyfillSheet.onInsertRule(onInsert);
}
}
}
};
});
//# sourceMappingURL=useAdoptedStylesheet.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,16 @@
import type { UseWindowHook } from '../contexts/MergeStylesDefaultContext';
import type { AdoptedStylesheetExHook, AdoptedStylesheetHook } from './useAdoptedStylesheet';
import type { ShadowConfigHook } from './useShadowConfig';
import type { HasMergeStylesShadowRootContextHook, MergeStylesShadowRootContextHook } from './useMergeStylesShadowRoot';
import type { MergeStylesRootStylesheetsHook } from './useMergeStylesRootStylesheets';
import type { UseStyledHook } from './useStyled';
export declare const useMergeStylesHooks: () => {
useAdoptedStylesheetEx: AdoptedStylesheetExHook;
useAdoptedStylesheet: AdoptedStylesheetHook;
useShadowConfig: ShadowConfigHook;
useMergeStylesShadowRootContext: MergeStylesShadowRootContextHook;
useHasMergeStylesShadowRootContext: HasMergeStylesShadowRootContextHook;
useMergeStylesRootStylesheets: MergeStylesRootStylesheetsHook;
useWindow: UseWindowHook;
useStyled: UseStyledHook;
};
@@ -0,0 +1,20 @@
define(["require", "exports", "react", "../contexts/MergeStylesDefaultContext"], function (require, exports, React, MergeStylesDefaultContext_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMergeStylesHooks = void 0;
var useMergeStylesHooks = function () {
var ctx = React.useContext(MergeStylesDefaultContext_1.MergeStylesDefaultContext);
return {
useAdoptedStylesheet: ctx.useAdoptedStylesheet,
useAdoptedStylesheetEx: ctx.useAdoptedStylesheetEx,
useShadowConfig: ctx.useShadowConfig,
useMergeStylesShadowRootContext: ctx.useMergeStylesShadowRootContext,
useHasMergeStylesShadowRootContext: ctx.useHasMergeStylesShadowRootContext,
useMergeStylesRootStylesheets: ctx.useMergeStylesRootStylesheets,
useWindow: ctx.useWindow,
useStyled: ctx.useStyled,
};
};
exports.useMergeStylesHooks = useMergeStylesHooks;
});
//# sourceMappingURL=useMergeStylesHooks.js.map
@@ -0,0 +1 @@
{"version":3,"file":"useMergeStylesHooks.js","sourceRoot":"../src/","sources":["shadowDom/hooks/useMergeStylesHooks.ts"],"names":[],"mappings":";;;;IASO,IAAM,mBAAmB,GAAG;QAUjC,IAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC,qDAAyB,CAAC,CAAC;QACxD,OAAO;YACL,oBAAoB,EAAE,GAAG,CAAC,oBAAoB;YAC9C,sBAAsB,EAAE,GAAG,CAAC,sBAAsB;YAClD,eAAe,EAAE,GAAG,CAAC,eAAe;YACpC,+BAA+B,EAAE,GAAG,CAAC,+BAA+B;YACpE,kCAAkC,EAAE,GAAG,CAAC,kCAAkC;YAC1E,6BAA6B,EAAE,GAAG,CAAC,6BAA6B;YAChE,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,SAAS,EAAE,GAAG,CAAC,SAAS;SACzB,CAAC;IACJ,CAAC,CAAC;IArBW,QAAA,mBAAmB,uBAqB9B","sourcesContent":["import * as React from 'react';\nimport { MergeStylesDefaultContext } from '../contexts/MergeStylesDefaultContext';\nimport type { UseWindowHook } from '../contexts/MergeStylesDefaultContext';\nimport type { AdoptedStylesheetExHook, AdoptedStylesheetHook } from './useAdoptedStylesheet';\nimport type { ShadowConfigHook } from './useShadowConfig';\nimport type { HasMergeStylesShadowRootContextHook, MergeStylesShadowRootContextHook } from './useMergeStylesShadowRoot';\nimport type { MergeStylesRootStylesheetsHook } from './useMergeStylesRootStylesheets';\nimport type { UseStyledHook } from './useStyled';\n\nexport const useMergeStylesHooks = (): {\n useAdoptedStylesheetEx: AdoptedStylesheetExHook;\n useAdoptedStylesheet: AdoptedStylesheetHook;\n useShadowConfig: ShadowConfigHook;\n useMergeStylesShadowRootContext: MergeStylesShadowRootContextHook;\n useHasMergeStylesShadowRootContext: HasMergeStylesShadowRootContextHook;\n useMergeStylesRootStylesheets: MergeStylesRootStylesheetsHook;\n useWindow: UseWindowHook;\n useStyled: UseStyledHook;\n} => {\n const ctx = React.useContext(MergeStylesDefaultContext);\n return {\n useAdoptedStylesheet: ctx.useAdoptedStylesheet,\n useAdoptedStylesheetEx: ctx.useAdoptedStylesheetEx,\n useShadowConfig: ctx.useShadowConfig,\n useMergeStylesShadowRootContext: ctx.useMergeStylesShadowRootContext,\n useHasMergeStylesShadowRootContext: ctx.useHasMergeStylesShadowRootContext,\n useMergeStylesRootStylesheets: ctx.useMergeStylesRootStylesheets,\n useWindow: ctx.useWindow,\n useStyled: ctx.useStyled,\n };\n};\n"]}
@@ -0,0 +1,6 @@
import type { ExtendedCSSStyleSheet } from '@fluentui/merge-styles';
export type MergeStylesRootStylesheetsHook = () => Map<string, ExtendedCSSStyleSheet>;
/**
* Get the map of stylesheets available in the context.
*/
export declare const useMergeStylesRootStylesheets: MergeStylesRootStylesheetsHook;
@@ -0,0 +1,13 @@
define(["require", "exports", "react", "../contexts/MergeStylesDefaultContext"], function (require, exports, React, MergeStylesDefaultContext_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMergeStylesRootStylesheets = void 0;
/**
* Get the map of stylesheets available in the context.
*/
var useMergeStylesRootStylesheets = function () {
return React.useContext(MergeStylesDefaultContext_1.MergeStylesDefaultContext).stylesheets;
};
exports.useMergeStylesRootStylesheets = useMergeStylesRootStylesheets;
});
//# sourceMappingURL=useMergeStylesRootStylesheets.js.map
@@ -0,0 +1 @@
{"version":3,"file":"useMergeStylesRootStylesheets.js","sourceRoot":"../src/","sources":["shadowDom/hooks/useMergeStylesRootStylesheets.ts"],"names":[],"mappings":";;;;IAMA;;OAEG;IACI,IAAM,6BAA6B,GAAmC;QAC3E,OAAO,KAAK,CAAC,UAAU,CAAC,qDAAyB,CAAC,CAAC,WAAW,CAAC;IACjE,CAAC,CAAC;IAFW,QAAA,6BAA6B,iCAExC","sourcesContent":["import * as React from 'react';\nimport { MergeStylesDefaultContext } from '../contexts/MergeStylesDefaultContext';\nimport type { ExtendedCSSStyleSheet } from '@fluentui/merge-styles';\n\nexport type MergeStylesRootStylesheetsHook = () => Map<string, ExtendedCSSStyleSheet>;\n\n/**\n * Get the map of stylesheets available in the context.\n */\nexport const useMergeStylesRootStylesheets: MergeStylesRootStylesheetsHook = () => {\n return React.useContext(MergeStylesDefaultContext).stylesheets;\n};\n"]}
@@ -0,0 +1,13 @@
import { MergeStylesShadowRootContextValue } from '../contexts/MergeStylesShadowRootContext';
export type HasMergeStylesShadowRootContextHook = () => boolean;
export type MergeStylesShadowRootContextHook = () => MergeStylesShadowRootContextValue | undefined;
/**
* Test if a context is available.
* @returns true if there is a context.
*/
export declare const useHasMergeStylesShadowRootContext: HasMergeStylesShadowRootContextHook;
/**
* Get a reference to the shadow root context.
* @returns The context for the shadow root.
*/
export declare const useMergeStylesShadowRootContext: MergeStylesShadowRootContextHook;
@@ -0,0 +1,22 @@
define(["require", "exports", "react", "../contexts/MergeStylesShadowRootContext"], function (require, exports, React, MergeStylesShadowRootContext_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMergeStylesShadowRootContext = exports.useHasMergeStylesShadowRootContext = void 0;
/**
* Test if a context is available.
* @returns true if there is a context.
*/
var useHasMergeStylesShadowRootContext = function () {
return !!(0, exports.useMergeStylesShadowRootContext)();
};
exports.useHasMergeStylesShadowRootContext = useHasMergeStylesShadowRootContext;
/**
* Get a reference to the shadow root context.
* @returns The context for the shadow root.
*/
var useMergeStylesShadowRootContext = function () {
return React.useContext(MergeStylesShadowRootContext_1.MergeStylesShadowRootContext);
};
exports.useMergeStylesShadowRootContext = useMergeStylesShadowRootContext;
});
//# sourceMappingURL=useMergeStylesShadowRoot.js.map
@@ -0,0 +1 @@
{"version":3,"file":"useMergeStylesShadowRoot.js","sourceRoot":"../src/","sources":["shadowDom/hooks/useMergeStylesShadowRoot.ts"],"names":[],"mappings":";;;;IASA;;;OAGG;IACI,IAAM,kCAAkC,GAAwC;QACrF,OAAO,CAAC,CAAC,IAAA,uCAA+B,GAAE,CAAC;IAC7C,CAAC,CAAC;IAFW,QAAA,kCAAkC,sCAE7C;IAEF;;;OAGG;IACI,IAAM,+BAA+B,GAAqC;QAC/E,OAAO,KAAK,CAAC,UAAU,CAAC,2DAA4B,CAAC,CAAC;IACxD,CAAC,CAAC;IAFW,QAAA,+BAA+B,mCAE1C","sourcesContent":["import * as React from 'react';\nimport {\n MergeStylesShadowRootContext,\n MergeStylesShadowRootContextValue,\n} from '../contexts/MergeStylesShadowRootContext';\n\nexport type HasMergeStylesShadowRootContextHook = () => boolean;\nexport type MergeStylesShadowRootContextHook = () => MergeStylesShadowRootContextValue | undefined;\n\n/**\n * Test if a context is available.\n * @returns true if there is a context.\n */\nexport const useHasMergeStylesShadowRootContext: HasMergeStylesShadowRootContextHook = () => {\n return !!useMergeStylesShadowRootContext();\n};\n\n/**\n * Get a reference to the shadow root context.\n * @returns The context for the shadow root.\n */\nexport const useMergeStylesShadowRootContext: MergeStylesShadowRootContextHook = () => {\n return React.useContext(MergeStylesShadowRootContext);\n};\n"]}
@@ -0,0 +1,9 @@
import type { ShadowConfig } from '@fluentui/merge-styles';
export type ShadowConfigHook = (stylesheetKey: string, inShadow: boolean, win?: Window) => ShadowConfig;
/**
* Get a shadow config.
* @param stylesheetKey - Globally unique key
* @param win - Reference to the `window` global.
* @returns ShadowConfig
*/
export declare const useShadowConfig: ShadowConfigHook;
@@ -0,0 +1,19 @@
define(["require", "exports", "react", "@fluentui/merge-styles"], function (require, exports, React, merge_styles_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useShadowConfig = void 0;
/**
* Get a shadow config.
* @param stylesheetKey - Globally unique key
* @param win - Reference to the `window` global.
* @returns ShadowConfig
*/
var useShadowConfig = function (stylesheetKey, inShadow, win) {
if (inShadow === void 0) { inShadow = false; }
return React.useMemo(function () {
return (0, merge_styles_1.makeShadowConfig)(stylesheetKey, inShadow, win);
}, [stylesheetKey, inShadow, win]);
};
exports.useShadowConfig = useShadowConfig;
});
//# sourceMappingURL=useShadowConfig.js.map
@@ -0,0 +1 @@
{"version":3,"file":"useShadowConfig.js","sourceRoot":"../src/","sources":["shadowDom/hooks/useShadowConfig.ts"],"names":[],"mappings":";;;;IAMA;;;;;OAKG;IACI,IAAM,eAAe,GAAqB,UAAC,aAAa,EAAE,QAAgB,EAAE,GAAI;QAAtB,yBAAA,EAAA,gBAAgB;QAC/E,OAAO,KAAK,CAAC,OAAO,CAAC;YACnB,OAAO,IAAA,+BAAgB,EAAC,aAAa,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;QACxD,CAAC,EAAE,CAAC,aAAa,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;IACrC,CAAC,CAAC;IAJW,QAAA,eAAe,mBAI1B","sourcesContent":["import * as React from 'react';\nimport { makeShadowConfig } from '@fluentui/merge-styles';\nimport type { ShadowConfig } from '@fluentui/merge-styles';\n\nexport type ShadowConfigHook = (stylesheetKey: string, inShadow: boolean, win?: Window) => ShadowConfig;\n\n/**\n * Get a shadow config.\n * @param stylesheetKey - Globally unique key\n * @param win - Reference to the `window` global.\n * @returns ShadowConfig\n */\nexport const useShadowConfig: ShadowConfigHook = (stylesheetKey, inShadow = false, win?) => {\n return React.useMemo(() => {\n return makeShadowConfig(stylesheetKey, inShadow, win);\n }, [stylesheetKey, inShadow, win]);\n};\n"]}
@@ -0,0 +1,3 @@
import { ShadowConfig } from '@fluentui/merge-styles';
export type UseStyledHook = (scope: string) => ShadowConfig | undefined;
export declare const useStyled: UseStyledHook;
+18
View File
@@ -0,0 +1,18 @@
define(["require", "exports", "../../dom", "./useMergeStylesHooks"], function (require, exports, dom_1, useMergeStylesHooks_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useStyled = void 0;
var useStyled = function (scope) {
if (scope === void 0) { scope = '__global__'; }
var _a = (0, useMergeStylesHooks_1.useMergeStylesHooks)(), useAdoptedStylesheetEx = _a.useAdoptedStylesheetEx, useShadowConfig = _a.useShadowConfig, useMergeStylesShadowRootContext = _a.useMergeStylesShadowRootContext, useMergeStylesRootStylesheets = _a.useMergeStylesRootStylesheets, useWindow = _a.useWindow;
var win = useWindow() || (0, dom_1.getWindow)();
var shadowCtx = useMergeStylesShadowRootContext();
var inShadow = !!shadowCtx;
var rootMergeStyles = useMergeStylesRootStylesheets();
var shadowConfig = useShadowConfig(scope, inShadow, win);
useAdoptedStylesheetEx(scope, shadowCtx, rootMergeStyles, win);
return shadowConfig;
};
exports.useStyled = useStyled;
});
//# sourceMappingURL=useStyled.js.map
@@ -0,0 +1 @@
{"version":3,"file":"useStyled.js","sourceRoot":"../src/","sources":["shadowDom/hooks/useStyled.ts"],"names":[],"mappings":";;;;IAMO,IAAM,SAAS,GAAkB,UAAC,KAAoB;QAApB,sBAAA,EAAA,oBAAoB;QACrD,IAAA,KAMF,IAAA,yCAAmB,GAAE,EALvB,sBAAsB,4BAAA,EACtB,eAAe,qBAAA,EACf,+BAA+B,qCAAA,EAC/B,6BAA6B,mCAAA,EAC7B,SAAS,eACc,CAAC;QAE1B,IAAM,GAAG,GAAG,SAAS,EAAE,IAAI,IAAA,eAAS,GAAE,CAAC;QACvC,IAAM,SAAS,GAAG,+BAA+B,EAAE,CAAC;QACpD,IAAM,QAAQ,GAAG,CAAC,CAAC,SAAS,CAAC;QAC7B,IAAM,eAAe,GAAG,6BAA6B,EAAE,CAAC;QACxD,IAAM,YAAY,GAAG,eAAe,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;QAE3D,sBAAsB,CAAC,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,CAAC,CAAC;QAE/D,OAAO,YAAY,CAAC;IACtB,CAAC,CAAC;IAlBW,QAAA,SAAS,aAkBpB","sourcesContent":["import { ShadowConfig } from '@fluentui/merge-styles';\nimport { getWindow } from '../../dom';\nimport { useMergeStylesHooks } from './useMergeStylesHooks';\n\nexport type UseStyledHook = (scope: string) => ShadowConfig | undefined;\n\nexport const useStyled: UseStyledHook = (scope = '__global__') => {\n const {\n useAdoptedStylesheetEx,\n useShadowConfig,\n useMergeStylesShadowRootContext,\n useMergeStylesRootStylesheets,\n useWindow,\n } = useMergeStylesHooks();\n\n const win = useWindow() || getWindow();\n const shadowCtx = useMergeStylesShadowRootContext();\n const inShadow = !!shadowCtx;\n const rootMergeStyles = useMergeStylesRootStylesheets();\n const shadowConfig = useShadowConfig(scope, inShadow, win);\n\n useAdoptedStylesheetEx(scope, shadowCtx, rootMergeStyles, win);\n\n return shadowConfig;\n};\n"]}