start UI implementing

This commit is contained in:
2026-08-18 21:38:57 +02:00
parent f040982b9c
commit d639cf3234
57692 changed files with 2619272 additions and 417 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,29 @@
export type EventListener = (...args: any[]) => void;
export interface EventListenerOptions {
isFirst?: boolean;
}
interface EventListenerCollection {
/**
* List of listeners to run before the others
* They are run in the opposite order of the registration order
*/
highPriority: Map<EventListener, true>;
/**
* List of events to run after the high priority listeners
* They are run in the registration order
*/
regular: Map<EventListener, true>;
}
export declare class EventManager {
maxListeners: number;
warnOnce: boolean;
events: {
[eventName: string]: EventListenerCollection;
};
on(eventName: string, listener: EventListener, options?: EventListenerOptions): void;
removeListener(eventName: string, listener: EventListener): void;
removeAllListeners(): void;
emit(eventName: string, ...args: any[]): void;
once(eventName: string, listener: EventListener): void;
}
export {};
@@ -0,0 +1,29 @@
export type EventListener = (...args: any[]) => void;
export interface EventListenerOptions {
isFirst?: boolean;
}
interface EventListenerCollection {
/**
* List of listeners to run before the others
* They are run in the opposite order of the registration order
*/
highPriority: Map<EventListener, true>;
/**
* List of events to run after the high priority listeners
* They are run in the registration order
*/
regular: Map<EventListener, true>;
}
export declare class EventManager {
maxListeners: number;
warnOnce: boolean;
events: {
[eventName: string]: EventListenerCollection;
};
on(eventName: string, listener: EventListener, options?: EventListenerOptions): void;
removeListener(eventName: string, listener: EventListener): void;
removeAllListeners(): void;
emit(eventName: string, ...args: any[]): void;
once(eventName: string, listener: EventListener): void;
}
export {};
@@ -0,0 +1,74 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EventManager = void 0;
// Used https://gist.github.com/mudge/5830382 as a starting point.
// See https://github.com/browserify/events/blob/master/events.js for
// the Node.js (https://nodejs.org/api/events.html) polyfill used by webpack.
class EventManager {
maxListeners = 20;
warnOnce = false;
events = {};
on(eventName, listener, options = {}) {
let collection = this.events[eventName];
if (!collection) {
collection = {
highPriority: new Map(),
regular: new Map()
};
this.events[eventName] = collection;
}
if (options.isFirst) {
collection.highPriority.set(listener, true);
} else {
collection.regular.set(listener, true);
}
if (process.env.NODE_ENV !== 'production') {
const collectionSize = collection.highPriority.size + collection.regular.size;
if (collectionSize > this.maxListeners && !this.warnOnce) {
this.warnOnce = true;
console.warn([`Possible EventEmitter memory leak detected. ${collectionSize} ${eventName} listeners added.`].join('\n'));
}
}
}
removeListener(eventName, listener) {
if (this.events[eventName]) {
this.events[eventName].regular.delete(listener);
this.events[eventName].highPriority.delete(listener);
}
}
removeAllListeners() {
this.events = {};
}
emit(eventName, ...args) {
const collection = this.events[eventName];
if (!collection) {
return;
}
const highPriorityListeners = Array.from(collection.highPriority.keys());
const regularListeners = Array.from(collection.regular.keys());
for (let i = highPriorityListeners.length - 1; i >= 0; i -= 1) {
const listener = highPriorityListeners[i];
if (collection.highPriority.has(listener)) {
listener.apply(this, args);
}
}
for (let i = 0; i < regularListeners.length; i += 1) {
const listener = regularListeners[i];
if (collection.regular.has(listener)) {
listener.apply(this, args);
}
}
}
once(eventName, listener) {
// eslint-disable-next-line consistent-this
const that = this;
this.on(eventName, function oneTimeListener(...args) {
that.removeListener(eventName, oneTimeListener);
listener.apply(that, args);
});
}
}
exports.EventManager = EventManager;
@@ -0,0 +1,67 @@
// Used https://gist.github.com/mudge/5830382 as a starting point.
// See https://github.com/browserify/events/blob/master/events.js for
// the Node.js (https://nodejs.org/api/events.html) polyfill used by webpack.
export class EventManager {
maxListeners = 20;
warnOnce = false;
events = {};
on(eventName, listener, options = {}) {
let collection = this.events[eventName];
if (!collection) {
collection = {
highPriority: new Map(),
regular: new Map()
};
this.events[eventName] = collection;
}
if (options.isFirst) {
collection.highPriority.set(listener, true);
} else {
collection.regular.set(listener, true);
}
if (process.env.NODE_ENV !== 'production') {
const collectionSize = collection.highPriority.size + collection.regular.size;
if (collectionSize > this.maxListeners && !this.warnOnce) {
this.warnOnce = true;
console.warn([`Possible EventEmitter memory leak detected. ${collectionSize} ${eventName} listeners added.`].join('\n'));
}
}
}
removeListener(eventName, listener) {
if (this.events[eventName]) {
this.events[eventName].regular.delete(listener);
this.events[eventName].highPriority.delete(listener);
}
}
removeAllListeners() {
this.events = {};
}
emit(eventName, ...args) {
const collection = this.events[eventName];
if (!collection) {
return;
}
const highPriorityListeners = Array.from(collection.highPriority.keys());
const regularListeners = Array.from(collection.regular.keys());
for (let i = highPriorityListeners.length - 1; i >= 0; i -= 1) {
const listener = highPriorityListeners[i];
if (collection.highPriority.has(listener)) {
listener.apply(this, args);
}
}
for (let i = 0; i < regularListeners.length; i += 1) {
const listener = regularListeners[i];
if (collection.regular.has(listener)) {
listener.apply(this, args);
}
}
}
once(eventName, listener) {
// eslint-disable-next-line consistent-this
const that = this;
this.on(eventName, function oneTimeListener(...args) {
that.removeListener(eventName, oneTimeListener);
listener.apply(that, args);
});
}
}
@@ -0,0 +1,2 @@
export { EventManager } from "./EventManager.mjs";
export type { EventListenerOptions } from "./EventManager.mjs";
@@ -0,0 +1,2 @@
export { EventManager } from "./EventManager.js";
export type { EventListenerOptions } from "./EventManager.js";
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "EventManager", {
enumerable: true,
get: function () {
return _EventManager.EventManager;
}
});
var _EventManager = require("./EventManager");
@@ -0,0 +1 @@
export { EventManager } from "./EventManager.mjs";
+23
View File
@@ -0,0 +1,23 @@
# License
MIT License
Copyright (c) 2020 Material-UI SAS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,4 @@
# @mui/x-internals
Shared utilities used by MUI X packages.
This package should never be installed or used directly.
@@ -0,0 +1,15 @@
import * as React from 'react';
export interface ToolbarContextValue {
focusableItemId: string | null;
registerItem: (id: string, ref: React.RefObject<HTMLButtonElement | null>) => void;
unregisterItem: (id: string) => void;
onItemKeyDown: (event: React.KeyboardEvent<HTMLButtonElement>) => void;
onItemFocus: (id: string) => void;
onItemBlur: (id: string, event: React.FocusEvent<HTMLButtonElement>) => void;
onItemDisabled: (id: string) => void;
}
export declare const ToolbarContext: React.Context<ToolbarContextValue | undefined>;
export declare function useToolbarContext(): ToolbarContextValue;
export declare function ToolbarContextProvider({
children
}: React.PropsWithChildren): React.JSX.Element;
@@ -0,0 +1,15 @@
import * as React from 'react';
export interface ToolbarContextValue {
focusableItemId: string | null;
registerItem: (id: string, ref: React.RefObject<HTMLButtonElement | null>) => void;
unregisterItem: (id: string) => void;
onItemKeyDown: (event: React.KeyboardEvent<HTMLButtonElement>) => void;
onItemFocus: (id: string) => void;
onItemBlur: (id: string, event: React.FocusEvent<HTMLButtonElement>) => void;
onItemDisabled: (id: string) => void;
}
export declare const ToolbarContext: React.Context<ToolbarContextValue | undefined>;
export declare function useToolbarContext(): ToolbarContextValue;
export declare function ToolbarContextProvider({
children
}: React.PropsWithChildren): React.JSX.Element;
@@ -0,0 +1,209 @@
"use strict";
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ToolbarContext = void 0;
exports.ToolbarContextProvider = ToolbarContextProvider;
exports.useToolbarContext = useToolbarContext;
var _index = _interopRequireDefault(require("../formatErrorMessage/index.js"));
var React = _interopRequireWildcard(require("react"));
var _jsxRuntime = require("react/jsx-runtime");
const ToolbarContext = exports.ToolbarContext = /*#__PURE__*/React.createContext(undefined);
if (process.env.NODE_ENV !== "production") ToolbarContext.displayName = "ToolbarContext";
function useToolbarContext() {
const context = React.useContext(ToolbarContext);
if (context === undefined) {
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X: Missing context. Toolbar subcomponents must be placed within a <Toolbar /> component.' : (0, _index.default)(63));
}
return context;
}
function ToolbarContextProvider({
children
}) {
const [focusableItemId, setFocusableItemId] = React.useState(null);
const focusableItemIdRef = React.useRef(focusableItemId);
// The item that currently has real DOM focus, `null` when focus is outside the toolbar.
const focusedItemIdRef = React.useRef(null);
const [items, setItems] = React.useState([]);
const updateFocusableItemId = React.useCallback(id => {
focusableItemIdRef.current = id;
setFocusableItemId(id);
}, []);
const getSortedItems = React.useCallback(() => items.sort(sortByDocumentPosition), [items]);
const findEnabledItem = React.useCallback((startIndex, step, wrap = true) => {
let index = startIndex;
const sortedItems = getSortedItems();
const itemCount = sortedItems.length;
// Look for enabled items in the specified direction
for (let i = 0; i < itemCount; i += 1) {
index += step;
// Handle wrapping around the ends
if (index >= itemCount) {
if (!wrap) {
return -1;
}
index = 0;
} else if (index < 0) {
if (!wrap) {
return -1;
}
index = itemCount - 1;
}
// Return if we found an enabled item
if (!sortedItems[index].ref.current?.disabled && sortedItems[index].ref.current?.ariaDisabled !== 'true') {
return index;
}
}
// If we've checked all items and found none enabled
return -1;
}, [getSortedItems]);
const registerItem = React.useCallback((id, itemRef) => {
setItems(prevItems => [...prevItems, {
id,
ref: itemRef
}]);
}, []);
const unregisterItem = React.useCallback(id => {
setItems(prevItems => prevItems.filter(i => i.id !== id));
}, []);
const onItemKeyDown = React.useCallback(event => {
if (!focusableItemId) {
return;
}
const sortedItems = getSortedItems();
const focusableItemIndex = sortedItems.findIndex(item => item.id === focusableItemId);
let newIndex = -1;
if (event.key === 'ArrowRight') {
event.preventDefault();
newIndex = findEnabledItem(focusableItemIndex, 1);
} else if (event.key === 'ArrowLeft') {
event.preventDefault();
newIndex = findEnabledItem(focusableItemIndex, -1);
} else if (event.key === 'Home') {
event.preventDefault();
newIndex = findEnabledItem(-1, 1, false);
} else if (event.key === 'End') {
event.preventDefault();
newIndex = findEnabledItem(sortedItems.length, -1, false);
}
if (newIndex >= 0 && newIndex < sortedItems.length) {
const item = sortedItems[newIndex];
updateFocusableItemId(item.id);
item.ref.current?.focus();
}
}, [getSortedItems, focusableItemId, findEnabledItem, updateFocusableItemId]);
const onItemFocus = React.useCallback(id => {
focusedItemIdRef.current = id;
if (focusableItemId !== id) {
updateFocusableItemId(id);
}
}, [focusableItemId, updateFocusableItemId]);
const onItemBlur = React.useCallback((id, event) => {
// When a focused item becomes disabled, the browser blurs it before the
// `onItemDisabled` effect runs. Keep tracking it as the focused item in that
// case so `onItemDisabled` can move focus to the next enabled item.
if (event.currentTarget.disabled) {
return;
}
if (focusedItemIdRef.current === id) {
focusedItemIdRef.current = null;
}
}, []);
const onItemDisabled = React.useCallback(id => {
const itemHadFocus = focusedItemIdRef.current === id;
const itemWasTabStop = focusableItemIdRef.current === id;
// Disabling an item the user is not interacting with must not move focus,
// and only requires a new tab stop if the disabled item was the tab stop.
if (!itemHadFocus && !itemWasTabStop) {
return;
}
const sortedItems = getSortedItems();
const currentIndex = sortedItems.findIndex(item => item.id === id);
if (currentIndex === -1) {
return;
}
// An `aria-disabled` item is still focusable, so real focus can stay where
// it is. Only a `disabled` item drops focus and needs it restored.
const focusLost = itemHadFocus && Boolean(sortedItems[currentIndex].ref.current?.disabled);
const newIndex = findEnabledItem(currentIndex, 1);
if (newIndex >= 0 && newIndex < sortedItems.length) {
const item = sortedItems[newIndex];
updateFocusableItemId(item.id);
if (focusLost) {
focusedItemIdRef.current = item.id;
item.ref.current?.focus();
}
} else if (focusLost) {
// No enabled item to move focus to
focusedItemIdRef.current = null;
}
}, [getSortedItems, findEnabledItem, updateFocusableItemId]);
React.useEffect(() => {
const sortedItems = getSortedItems();
if (sortedItems.length === 0) {
return;
}
// Set initial focusable item. A disabled item can't receive focus, so the
// toolbar would be unreachable with `Tab` if it became the tab stop.
// Fall back to the first item when every item is disabled.
if (!focusableItemIdRef.current) {
const firstEnabledIndex = findEnabledItem(-1, 1, false);
updateFocusableItemId(sortedItems[firstEnabledIndex === -1 ? 0 : firstEnabledIndex].id);
return;
}
const focusableItemExists = sortedItems.some(item => item.id === focusableItemIdRef.current);
if (!focusableItemExists) {
// The tab stop has been removed from the items array, assign it to the last item
const fallbackItem = sortedItems[sortedItems.length - 1];
updateFocusableItemId(fallbackItem.id);
// Move real focus only if the removed item had focus
if (focusedItemIdRef.current !== null && !sortedItems.some(item => item.id === focusedItemIdRef.current)) {
focusedItemIdRef.current = fallbackItem.id;
fallbackItem.ref.current?.focus();
}
}
}, [getSortedItems, findEnabledItem, updateFocusableItemId]);
const contextValue = React.useMemo(() => ({
focusableItemId,
registerItem,
unregisterItem,
onItemKeyDown,
onItemFocus,
onItemBlur,
onItemDisabled
}), [focusableItemId, registerItem, unregisterItem, onItemKeyDown, onItemFocus, onItemBlur, onItemDisabled]);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ToolbarContext.Provider, {
value: contextValue,
children: children
});
}
/* eslint-disable no-bitwise */
function sortByDocumentPosition(a, b) {
if (!a.ref.current || !b.ref.current) {
return 0;
}
const position = a.ref.current.compareDocumentPosition(b.ref.current);
if (!position) {
return 0;
}
if (position & Node.DOCUMENT_POSITION_FOLLOWING || position & Node.DOCUMENT_POSITION_CONTAINED_BY) {
return -1;
}
if (position & Node.DOCUMENT_POSITION_PRECEDING || position & Node.DOCUMENT_POSITION_CONTAINS) {
return 1;
}
return 0;
}
@@ -0,0 +1,200 @@
'use client';
import _formatErrorMessage from "../formatErrorMessage/index.mjs";
import * as React from 'react';
import { jsx as _jsx } from "react/jsx-runtime";
export const ToolbarContext = /*#__PURE__*/React.createContext(undefined);
if (process.env.NODE_ENV !== "production") ToolbarContext.displayName = "ToolbarContext";
export function useToolbarContext() {
const context = React.useContext(ToolbarContext);
if (context === undefined) {
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X: Missing context. Toolbar subcomponents must be placed within a <Toolbar /> component.' : _formatErrorMessage(63));
}
return context;
}
export function ToolbarContextProvider({
children
}) {
const [focusableItemId, setFocusableItemId] = React.useState(null);
const focusableItemIdRef = React.useRef(focusableItemId);
// The item that currently has real DOM focus, `null` when focus is outside the toolbar.
const focusedItemIdRef = React.useRef(null);
const [items, setItems] = React.useState([]);
const updateFocusableItemId = React.useCallback(id => {
focusableItemIdRef.current = id;
setFocusableItemId(id);
}, []);
const getSortedItems = React.useCallback(() => items.sort(sortByDocumentPosition), [items]);
const findEnabledItem = React.useCallback((startIndex, step, wrap = true) => {
let index = startIndex;
const sortedItems = getSortedItems();
const itemCount = sortedItems.length;
// Look for enabled items in the specified direction
for (let i = 0; i < itemCount; i += 1) {
index += step;
// Handle wrapping around the ends
if (index >= itemCount) {
if (!wrap) {
return -1;
}
index = 0;
} else if (index < 0) {
if (!wrap) {
return -1;
}
index = itemCount - 1;
}
// Return if we found an enabled item
if (!sortedItems[index].ref.current?.disabled && sortedItems[index].ref.current?.ariaDisabled !== 'true') {
return index;
}
}
// If we've checked all items and found none enabled
return -1;
}, [getSortedItems]);
const registerItem = React.useCallback((id, itemRef) => {
setItems(prevItems => [...prevItems, {
id,
ref: itemRef
}]);
}, []);
const unregisterItem = React.useCallback(id => {
setItems(prevItems => prevItems.filter(i => i.id !== id));
}, []);
const onItemKeyDown = React.useCallback(event => {
if (!focusableItemId) {
return;
}
const sortedItems = getSortedItems();
const focusableItemIndex = sortedItems.findIndex(item => item.id === focusableItemId);
let newIndex = -1;
if (event.key === 'ArrowRight') {
event.preventDefault();
newIndex = findEnabledItem(focusableItemIndex, 1);
} else if (event.key === 'ArrowLeft') {
event.preventDefault();
newIndex = findEnabledItem(focusableItemIndex, -1);
} else if (event.key === 'Home') {
event.preventDefault();
newIndex = findEnabledItem(-1, 1, false);
} else if (event.key === 'End') {
event.preventDefault();
newIndex = findEnabledItem(sortedItems.length, -1, false);
}
if (newIndex >= 0 && newIndex < sortedItems.length) {
const item = sortedItems[newIndex];
updateFocusableItemId(item.id);
item.ref.current?.focus();
}
}, [getSortedItems, focusableItemId, findEnabledItem, updateFocusableItemId]);
const onItemFocus = React.useCallback(id => {
focusedItemIdRef.current = id;
if (focusableItemId !== id) {
updateFocusableItemId(id);
}
}, [focusableItemId, updateFocusableItemId]);
const onItemBlur = React.useCallback((id, event) => {
// When a focused item becomes disabled, the browser blurs it before the
// `onItemDisabled` effect runs. Keep tracking it as the focused item in that
// case so `onItemDisabled` can move focus to the next enabled item.
if (event.currentTarget.disabled) {
return;
}
if (focusedItemIdRef.current === id) {
focusedItemIdRef.current = null;
}
}, []);
const onItemDisabled = React.useCallback(id => {
const itemHadFocus = focusedItemIdRef.current === id;
const itemWasTabStop = focusableItemIdRef.current === id;
// Disabling an item the user is not interacting with must not move focus,
// and only requires a new tab stop if the disabled item was the tab stop.
if (!itemHadFocus && !itemWasTabStop) {
return;
}
const sortedItems = getSortedItems();
const currentIndex = sortedItems.findIndex(item => item.id === id);
if (currentIndex === -1) {
return;
}
// An `aria-disabled` item is still focusable, so real focus can stay where
// it is. Only a `disabled` item drops focus and needs it restored.
const focusLost = itemHadFocus && Boolean(sortedItems[currentIndex].ref.current?.disabled);
const newIndex = findEnabledItem(currentIndex, 1);
if (newIndex >= 0 && newIndex < sortedItems.length) {
const item = sortedItems[newIndex];
updateFocusableItemId(item.id);
if (focusLost) {
focusedItemIdRef.current = item.id;
item.ref.current?.focus();
}
} else if (focusLost) {
// No enabled item to move focus to
focusedItemIdRef.current = null;
}
}, [getSortedItems, findEnabledItem, updateFocusableItemId]);
React.useEffect(() => {
const sortedItems = getSortedItems();
if (sortedItems.length === 0) {
return;
}
// Set initial focusable item. A disabled item can't receive focus, so the
// toolbar would be unreachable with `Tab` if it became the tab stop.
// Fall back to the first item when every item is disabled.
if (!focusableItemIdRef.current) {
const firstEnabledIndex = findEnabledItem(-1, 1, false);
updateFocusableItemId(sortedItems[firstEnabledIndex === -1 ? 0 : firstEnabledIndex].id);
return;
}
const focusableItemExists = sortedItems.some(item => item.id === focusableItemIdRef.current);
if (!focusableItemExists) {
// The tab stop has been removed from the items array, assign it to the last item
const fallbackItem = sortedItems[sortedItems.length - 1];
updateFocusableItemId(fallbackItem.id);
// Move real focus only if the removed item had focus
if (focusedItemIdRef.current !== null && !sortedItems.some(item => item.id === focusedItemIdRef.current)) {
focusedItemIdRef.current = fallbackItem.id;
fallbackItem.ref.current?.focus();
}
}
}, [getSortedItems, findEnabledItem, updateFocusableItemId]);
const contextValue = React.useMemo(() => ({
focusableItemId,
registerItem,
unregisterItem,
onItemKeyDown,
onItemFocus,
onItemBlur,
onItemDisabled
}), [focusableItemId, registerItem, unregisterItem, onItemKeyDown, onItemFocus, onItemBlur, onItemDisabled]);
return /*#__PURE__*/_jsx(ToolbarContext.Provider, {
value: contextValue,
children: children
});
}
/* eslint-disable no-bitwise */
function sortByDocumentPosition(a, b) {
if (!a.ref.current || !b.ref.current) {
return 0;
}
const position = a.ref.current.compareDocumentPosition(b.ref.current);
if (!position) {
return 0;
}
if (position & Node.DOCUMENT_POSITION_FOLLOWING || position & Node.DOCUMENT_POSITION_CONTAINED_BY) {
return -1;
}
if (position & Node.DOCUMENT_POSITION_PRECEDING || position & Node.DOCUMENT_POSITION_CONTAINS) {
return 1;
}
return 0;
}
@@ -0,0 +1,2 @@
export * from "./ToolbarContext.mjs";
export * from "./useRegisterToolbarButton.mjs";
@@ -0,0 +1,2 @@
export * from "./ToolbarContext.js";
export * from "./useRegisterToolbarButton.js";
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _ToolbarContext = require("./ToolbarContext");
Object.keys(_ToolbarContext).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _ToolbarContext[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _ToolbarContext[key];
}
});
});
var _useRegisterToolbarButton = require("./useRegisterToolbarButton");
Object.keys(_useRegisterToolbarButton).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _useRegisterToolbarButton[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _useRegisterToolbarButton[key];
}
});
});
@@ -0,0 +1,2 @@
export * from "./ToolbarContext.mjs";
export * from "./useRegisterToolbarButton.mjs";
@@ -0,0 +1,11 @@
import * as React from 'react';
interface ToolbarItemProps extends Pick<React.ComponentProps<'button'>, 'onKeyDown' | 'onFocus' | 'onBlur' | 'aria-disabled' | 'disabled'> {}
export declare function useRegisterToolbarButton(props: ToolbarItemProps, ref: React.RefObject<HTMLButtonElement | null>): {
tabIndex: number;
disabled: boolean | undefined;
'aria-disabled': ("false" | "true" | boolean) | undefined;
onKeyDown: (event: React.KeyboardEvent<HTMLButtonElement>) => void;
onFocus: (event: React.FocusEvent<HTMLButtonElement>) => void;
onBlur: (event: React.FocusEvent<HTMLButtonElement>) => void;
};
export {};
@@ -0,0 +1,11 @@
import * as React from 'react';
interface ToolbarItemProps extends Pick<React.ComponentProps<'button'>, 'onKeyDown' | 'onFocus' | 'onBlur' | 'aria-disabled' | 'disabled'> {}
export declare function useRegisterToolbarButton(props: ToolbarItemProps, ref: React.RefObject<HTMLButtonElement | null>): {
tabIndex: number;
disabled: boolean | undefined;
'aria-disabled': ("false" | "true" | boolean) | undefined;
onKeyDown: (event: React.KeyboardEvent<HTMLButtonElement>) => void;
onFocus: (event: React.FocusEvent<HTMLButtonElement>) => void;
onBlur: (event: React.FocusEvent<HTMLButtonElement>) => void;
};
export {};
@@ -0,0 +1,69 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useRegisterToolbarButton = useRegisterToolbarButton;
var React = _interopRequireWildcard(require("react"));
var _useId = _interopRequireDefault(require("@mui/utils/useId"));
var _ToolbarContext = require("./ToolbarContext");
function useRegisterToolbarButton(props, ref) {
const {
onKeyDown,
onFocus,
onBlur,
disabled,
'aria-disabled': ariaDisabled
} = props;
const id = (0, _useId.default)();
const {
focusableItemId,
registerItem,
unregisterItem,
onItemKeyDown,
onItemFocus,
onItemBlur,
onItemDisabled
} = (0, _ToolbarContext.useToolbarContext)();
const handleKeyDown = event => {
onItemKeyDown(event);
onKeyDown?.(event);
};
const handleFocus = event => {
onItemFocus(id);
onFocus?.(event);
};
const handleBlur = event => {
onItemBlur(id, event);
onBlur?.(event);
};
React.useEffect(() => {
registerItem(id, ref);
return () => unregisterItem(id);
}, [id, ref, registerItem, unregisterItem]);
const previousDisabled = React.useRef(disabled);
React.useEffect(() => {
if (previousDisabled.current !== disabled && disabled === true) {
onItemDisabled(id);
}
previousDisabled.current = disabled;
}, [disabled, id, onItemDisabled]);
const previousAriaDisabled = React.useRef(ariaDisabled);
React.useEffect(() => {
if (previousAriaDisabled.current !== ariaDisabled && ariaDisabled === true) {
onItemDisabled(id);
}
previousAriaDisabled.current = ariaDisabled;
}, [ariaDisabled, id, onItemDisabled]);
return {
tabIndex: focusableItemId === id ? 0 : -1,
disabled,
'aria-disabled': ariaDisabled,
onKeyDown: handleKeyDown,
onFocus: handleFocus,
onBlur: handleBlur
};
}
@@ -0,0 +1,62 @@
'use client';
import * as React from 'react';
import useId from '@mui/utils/useId';
import { useToolbarContext } from "./ToolbarContext.mjs";
export function useRegisterToolbarButton(props, ref) {
const {
onKeyDown,
onFocus,
onBlur,
disabled,
'aria-disabled': ariaDisabled
} = props;
const id = useId();
const {
focusableItemId,
registerItem,
unregisterItem,
onItemKeyDown,
onItemFocus,
onItemBlur,
onItemDisabled
} = useToolbarContext();
const handleKeyDown = event => {
onItemKeyDown(event);
onKeyDown?.(event);
};
const handleFocus = event => {
onItemFocus(id);
onFocus?.(event);
};
const handleBlur = event => {
onItemBlur(id, event);
onBlur?.(event);
};
React.useEffect(() => {
registerItem(id, ref);
return () => unregisterItem(id);
}, [id, ref, registerItem, unregisterItem]);
const previousDisabled = React.useRef(disabled);
React.useEffect(() => {
if (previousDisabled.current !== disabled && disabled === true) {
onItemDisabled(id);
}
previousDisabled.current = disabled;
}, [disabled, id, onItemDisabled]);
const previousAriaDisabled = React.useRef(ariaDisabled);
React.useEffect(() => {
if (previousAriaDisabled.current !== ariaDisabled && ariaDisabled === true) {
onItemDisabled(id);
}
previousAriaDisabled.current = ariaDisabled;
}, [ariaDisabled, id, onItemDisabled]);
return {
tabIndex: focusableItemId === id ? 0 : -1,
disabled,
'aria-disabled': ariaDisabled,
onKeyDown: handleKeyDown,
onFocus: handleFocus,
onBlur: handleBlur
};
}
@@ -0,0 +1,74 @@
/**
* Well-known `Symbol.dispose`. Resolves to the native well-known symbol when
* the runtime ships the explicit resource management proposal; otherwise falls
* back to `Symbol.for('Symbol.dispose')`, the same registry symbol used by the
* fallback stacks below, so `DisposableStack#use` finds the method.
*
* Consumers should key dispose methods on this constant —
* `class Foo { [disposeSymbol]() {} }` — rather than `Symbol.dispose`, so the
* class works on runtimes without the proposal.
*/
export declare const disposeSymbol: unique symbol;
/**
* Well-known `Symbol.asyncDispose`. See {@link disposeSymbol} for the
* native/fallback resolution rules.
*/
export declare const asyncDisposeSymbol: unique symbol;
/** Object disposable via {@link disposeSymbol}. Mirrors `Disposable` from `esnext.disposable`. */
export interface Disposable {
[disposeSymbol](): void;
}
/** Object disposable via {@link asyncDisposeSymbol}. Mirrors `AsyncDisposable` from `esnext.disposable`. */
export interface AsyncDisposable {
[asyncDisposeSymbol](): PromiseLike<void>;
}
/**
* Mirrors the `DisposableStack` interface from `esnext.disposable`, declared
* locally so consumers don't need that lib in their TypeScript config.
*/
export interface DisposableStack {
readonly disposed: boolean;
dispose(): void;
use<T extends Disposable | null | undefined>(value: T): T;
adopt<T>(value: T, onDispose: (value: T) => void): T;
defer(onDispose: () => void): void;
move(): DisposableStack;
[disposeSymbol](): void;
}
export interface DisposableStackConstructor {
new (): DisposableStack;
readonly prototype: DisposableStack;
}
/**
* Mirrors the `AsyncDisposableStack` interface from `esnext.disposable`, declared
* locally so consumers don't need that lib in their TypeScript config.
*/
export interface AsyncDisposableStack {
readonly disposed: boolean;
disposeAsync(): Promise<void>;
use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T;
adopt<T>(value: T, onDisposeAsync: (value: T) => PromiseLike<void> | void): T;
defer(onDisposeAsync: () => PromiseLike<void> | void): void;
move(): AsyncDisposableStack;
[asyncDisposeSymbol](): Promise<void>;
}
export interface AsyncDisposableStackConstructor {
new (): AsyncDisposableStack;
readonly prototype: AsyncDisposableStack;
}
/**
* Spec-compliant `DisposableStack`. Prefers the platform's native class when
* present; falls back to a minimal built-in implementation otherwise.
*/
export declare const DisposableStack: DisposableStackConstructor;
/**
* Spec-compliant `AsyncDisposableStack`. Prefers the platform's native class
* when present; falls back to a minimal built-in implementation otherwise.
*/
export declare const AsyncDisposableStack: AsyncDisposableStackConstructor;
/**
* Unwraps a `SuppressedError` chain (as produced by `DisposableStack.dispose()`
* when multiple disposers throw) into a flat list, outermost failure first.
* Returns `[error]` unchanged if it isn't a `SuppressedError`.
*/
export declare function unwrapSuppressedErrors(error: unknown): unknown[];
@@ -0,0 +1,74 @@
/**
* Well-known `Symbol.dispose`. Resolves to the native well-known symbol when
* the runtime ships the explicit resource management proposal; otherwise falls
* back to `Symbol.for('Symbol.dispose')`, the same registry symbol used by the
* fallback stacks below, so `DisposableStack#use` finds the method.
*
* Consumers should key dispose methods on this constant —
* `class Foo { [disposeSymbol]() {} }` — rather than `Symbol.dispose`, so the
* class works on runtimes without the proposal.
*/
export declare const disposeSymbol: unique symbol;
/**
* Well-known `Symbol.asyncDispose`. See {@link disposeSymbol} for the
* native/fallback resolution rules.
*/
export declare const asyncDisposeSymbol: unique symbol;
/** Object disposable via {@link disposeSymbol}. Mirrors `Disposable` from `esnext.disposable`. */
export interface Disposable {
[disposeSymbol](): void;
}
/** Object disposable via {@link asyncDisposeSymbol}. Mirrors `AsyncDisposable` from `esnext.disposable`. */
export interface AsyncDisposable {
[asyncDisposeSymbol](): PromiseLike<void>;
}
/**
* Mirrors the `DisposableStack` interface from `esnext.disposable`, declared
* locally so consumers don't need that lib in their TypeScript config.
*/
export interface DisposableStack {
readonly disposed: boolean;
dispose(): void;
use<T extends Disposable | null | undefined>(value: T): T;
adopt<T>(value: T, onDispose: (value: T) => void): T;
defer(onDispose: () => void): void;
move(): DisposableStack;
[disposeSymbol](): void;
}
export interface DisposableStackConstructor {
new (): DisposableStack;
readonly prototype: DisposableStack;
}
/**
* Mirrors the `AsyncDisposableStack` interface from `esnext.disposable`, declared
* locally so consumers don't need that lib in their TypeScript config.
*/
export interface AsyncDisposableStack {
readonly disposed: boolean;
disposeAsync(): Promise<void>;
use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T;
adopt<T>(value: T, onDisposeAsync: (value: T) => PromiseLike<void> | void): T;
defer(onDisposeAsync: () => PromiseLike<void> | void): void;
move(): AsyncDisposableStack;
[asyncDisposeSymbol](): Promise<void>;
}
export interface AsyncDisposableStackConstructor {
new (): AsyncDisposableStack;
readonly prototype: AsyncDisposableStack;
}
/**
* Spec-compliant `DisposableStack`. Prefers the platform's native class when
* present; falls back to a minimal built-in implementation otherwise.
*/
export declare const DisposableStack: DisposableStackConstructor;
/**
* Spec-compliant `AsyncDisposableStack`. Prefers the platform's native class
* when present; falls back to a minimal built-in implementation otherwise.
*/
export declare const AsyncDisposableStack: AsyncDisposableStackConstructor;
/**
* Unwraps a `SuppressedError` chain (as produced by `DisposableStack.dispose()`
* when multiple disposers throw) into a flat list, outermost failure first.
* Returns `[error]` unchanged if it isn't a `SuppressedError`.
*/
export declare function unwrapSuppressedErrors(error: unknown): unknown[];
@@ -0,0 +1,223 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.disposeSymbol = exports.asyncDisposeSymbol = exports.DisposableStack = exports.AsyncDisposableStack = void 0;
exports.unwrapSuppressedErrors = unwrapSuppressedErrors;
/**
* Well-known `Symbol.dispose`. Resolves to the native well-known symbol when
* the runtime ships the explicit resource management proposal; otherwise falls
* back to `Symbol.for('Symbol.dispose')`, the same registry symbol used by the
* fallback stacks below, so `DisposableStack#use` finds the method.
*
* Consumers should key dispose methods on this constant —
* `class Foo { [disposeSymbol]() {} }` — rather than `Symbol.dispose`, so the
* class works on runtimes without the proposal.
*/
const disposeSymbol = exports.disposeSymbol = typeof Symbol.dispose === 'symbol' ? Symbol.dispose : Symbol.for('Symbol.dispose');
/**
* Well-known `Symbol.asyncDispose`. See {@link disposeSymbol} for the
* native/fallback resolution rules.
*/
const asyncDisposeSymbol = exports.asyncDisposeSymbol = typeof Symbol.asyncDispose === 'symbol' ? Symbol.asyncDispose : Symbol.for('Symbol.asyncDispose');
/** Object disposable via {@link disposeSymbol}. Mirrors `Disposable` from `esnext.disposable`. */
/** Object disposable via {@link asyncDisposeSymbol}. Mirrors `AsyncDisposable` from `esnext.disposable`. */
/**
* Mirrors the `DisposableStack` interface from `esnext.disposable`, declared
* locally so consumers don't need that lib in their TypeScript config.
*/
/**
* Mirrors the `AsyncDisposableStack` interface from `esnext.disposable`, declared
* locally so consumers don't need that lib in their TypeScript config.
*/
const NativeSuppressedError = typeof SuppressedError === 'function' ? SuppressedError : undefined;
/**
* Builds a `SuppressedError` (native when available, otherwise a compatible
* `{ error, suppressed }` Error) so {@link unwrapSuppressedErrors} can flatten
* the chain produced when several disposers throw.
*/
function createSuppressedError(error, suppressed) {
if (NativeSuppressedError) {
return new NativeSuppressedError(error, suppressed);
}
const wrapper = /* minify-error-disabled */new Error('An error was suppressed during disposal.');
return Object.assign(wrapper, {
name: 'SuppressedError',
error,
suppressed
});
}
function assertNotDisposed(disposed) {
if (disposed) {
throw /* minify-error-disabled */new ReferenceError('MUI X: The disposable stack is disposed.');
}
}
/**
* Minimal fallback for `DisposableStack`, used on runtimes that do not ship the
* explicit resource management proposal. Implements the subset of the proposal
* MUI X uses — `use`, `adopt`, `defer`, `move`, `dispose`, `disposed` and
* `[Symbol.dispose]` — so the `core-js-pure` ponyfill no longer has to be bundled.
*/
class FallbackDisposableStack {
stack = [];
isDisposed = false;
get disposed() {
return this.isDisposed;
}
use(value) {
assertNotDisposed(this.isDisposed);
if (value != null) {
const method = value[disposeSymbol];
if (typeof method !== 'function') {
throw /* minify-error-disabled */new TypeError('MUI X: The value is not disposable.');
}
this.stack.push(() => method.call(value));
}
return value;
}
adopt(value, onDispose) {
assertNotDisposed(this.isDisposed);
this.stack.push(() => onDispose(value));
return value;
}
defer(onDispose) {
assertNotDisposed(this.isDisposed);
this.stack.push(onDispose);
}
move() {
assertNotDisposed(this.isDisposed);
const next = new FallbackDisposableStack();
next.stack = this.stack;
this.stack = [];
this.isDisposed = true;
return next;
}
dispose() {
if (this.isDisposed) {
return;
}
this.isDisposed = true;
let hasError = false;
let error;
// Dispose in reverse (LIFO) order, aggregating failures into a SuppressedError chain.
for (let i = this.stack.length - 1; i >= 0; i -= 1) {
try {
this.stack[i]();
} catch (caught) {
error = hasError ? createSuppressedError(caught, error) : caught;
hasError = true;
}
}
this.stack = [];
if (hasError) {
throw error;
}
}
[disposeSymbol]() {
this.dispose();
}
}
/**
* Minimal fallback for `AsyncDisposableStack`. See {@link FallbackDisposableStack};
* disposers may return promises and are awaited sequentially in LIFO order.
*/
class FallbackAsyncDisposableStack {
stack = [];
isDisposed = false;
get disposed() {
return this.isDisposed;
}
use(value) {
assertNotDisposed(this.isDisposed);
if (value != null) {
const record = value;
const method = record[asyncDisposeSymbol] ?? record[disposeSymbol];
if (typeof method !== 'function') {
throw /* minify-error-disabled */new TypeError('MUI X: The value is not async disposable.');
}
this.stack.push(() => method.call(value));
}
return value;
}
adopt(value, onDisposeAsync) {
assertNotDisposed(this.isDisposed);
this.stack.push(() => onDisposeAsync(value));
return value;
}
defer(onDisposeAsync) {
assertNotDisposed(this.isDisposed);
this.stack.push(onDisposeAsync);
}
move() {
assertNotDisposed(this.isDisposed);
const next = new FallbackAsyncDisposableStack();
next.stack = this.stack;
this.stack = [];
this.isDisposed = true;
return next;
}
async disposeAsync() {
if (this.isDisposed) {
return;
}
this.isDisposed = true;
let hasError = false;
let error;
for (let i = this.stack.length - 1; i >= 0; i -= 1) {
try {
// eslint-disable-next-line no-await-in-loop
await this.stack[i]();
} catch (caught) {
error = hasError ? createSuppressedError(caught, error) : caught;
hasError = true;
}
}
this.stack = [];
if (hasError) {
throw error;
}
}
[asyncDisposeSymbol]() {
return this.disposeAsync();
}
}
/**
* Spec-compliant `DisposableStack`. Prefers the platform's native class when
* present; falls back to a minimal built-in implementation otherwise.
*/
// eslint-disable-next-line @typescript-eslint/no-redeclare
const DisposableStack = exports.DisposableStack = globalThis.DisposableStack ?? FallbackDisposableStack;
/**
* Spec-compliant `AsyncDisposableStack`. Prefers the platform's native class
* when present; falls back to a minimal built-in implementation otherwise.
*/
// eslint-disable-next-line @typescript-eslint/no-redeclare
const AsyncDisposableStack = exports.AsyncDisposableStack = globalThis.AsyncDisposableStack ?? FallbackAsyncDisposableStack;
/**
* Unwraps a `SuppressedError` chain (as produced by `DisposableStack.dispose()`
* when multiple disposers throw) into a flat list, outermost failure first.
* Returns `[error]` unchanged if it isn't a `SuppressedError`.
*/
function unwrapSuppressedErrors(error) {
const failures = [];
let current = error;
while (typeof current === 'object' && current !== null && 'error' in current && 'suppressed' in current) {
failures.push(current.error);
current = current.suppressed;
}
failures.push(current);
return failures;
}
@@ -0,0 +1,216 @@
/**
* Well-known `Symbol.dispose`. Resolves to the native well-known symbol when
* the runtime ships the explicit resource management proposal; otherwise falls
* back to `Symbol.for('Symbol.dispose')`, the same registry symbol used by the
* fallback stacks below, so `DisposableStack#use` finds the method.
*
* Consumers should key dispose methods on this constant —
* `class Foo { [disposeSymbol]() {} }` — rather than `Symbol.dispose`, so the
* class works on runtimes without the proposal.
*/
export const disposeSymbol = typeof Symbol.dispose === 'symbol' ? Symbol.dispose : Symbol.for('Symbol.dispose');
/**
* Well-known `Symbol.asyncDispose`. See {@link disposeSymbol} for the
* native/fallback resolution rules.
*/
export const asyncDisposeSymbol = typeof Symbol.asyncDispose === 'symbol' ? Symbol.asyncDispose : Symbol.for('Symbol.asyncDispose');
/** Object disposable via {@link disposeSymbol}. Mirrors `Disposable` from `esnext.disposable`. */
/** Object disposable via {@link asyncDisposeSymbol}. Mirrors `AsyncDisposable` from `esnext.disposable`. */
/**
* Mirrors the `DisposableStack` interface from `esnext.disposable`, declared
* locally so consumers don't need that lib in their TypeScript config.
*/
/**
* Mirrors the `AsyncDisposableStack` interface from `esnext.disposable`, declared
* locally so consumers don't need that lib in their TypeScript config.
*/
const NativeSuppressedError = typeof SuppressedError === 'function' ? SuppressedError : undefined;
/**
* Builds a `SuppressedError` (native when available, otherwise a compatible
* `{ error, suppressed }` Error) so {@link unwrapSuppressedErrors} can flatten
* the chain produced when several disposers throw.
*/
function createSuppressedError(error, suppressed) {
if (NativeSuppressedError) {
return new NativeSuppressedError(error, suppressed);
}
const wrapper = /* minify-error-disabled */new Error('An error was suppressed during disposal.');
return Object.assign(wrapper, {
name: 'SuppressedError',
error,
suppressed
});
}
function assertNotDisposed(disposed) {
if (disposed) {
throw /* minify-error-disabled */new ReferenceError('MUI X: The disposable stack is disposed.');
}
}
/**
* Minimal fallback for `DisposableStack`, used on runtimes that do not ship the
* explicit resource management proposal. Implements the subset of the proposal
* MUI X uses — `use`, `adopt`, `defer`, `move`, `dispose`, `disposed` and
* `[Symbol.dispose]` — so the `core-js-pure` ponyfill no longer has to be bundled.
*/
class FallbackDisposableStack {
stack = [];
isDisposed = false;
get disposed() {
return this.isDisposed;
}
use(value) {
assertNotDisposed(this.isDisposed);
if (value != null) {
const method = value[disposeSymbol];
if (typeof method !== 'function') {
throw /* minify-error-disabled */new TypeError('MUI X: The value is not disposable.');
}
this.stack.push(() => method.call(value));
}
return value;
}
adopt(value, onDispose) {
assertNotDisposed(this.isDisposed);
this.stack.push(() => onDispose(value));
return value;
}
defer(onDispose) {
assertNotDisposed(this.isDisposed);
this.stack.push(onDispose);
}
move() {
assertNotDisposed(this.isDisposed);
const next = new FallbackDisposableStack();
next.stack = this.stack;
this.stack = [];
this.isDisposed = true;
return next;
}
dispose() {
if (this.isDisposed) {
return;
}
this.isDisposed = true;
let hasError = false;
let error;
// Dispose in reverse (LIFO) order, aggregating failures into a SuppressedError chain.
for (let i = this.stack.length - 1; i >= 0; i -= 1) {
try {
this.stack[i]();
} catch (caught) {
error = hasError ? createSuppressedError(caught, error) : caught;
hasError = true;
}
}
this.stack = [];
if (hasError) {
throw error;
}
}
[disposeSymbol]() {
this.dispose();
}
}
/**
* Minimal fallback for `AsyncDisposableStack`. See {@link FallbackDisposableStack};
* disposers may return promises and are awaited sequentially in LIFO order.
*/
class FallbackAsyncDisposableStack {
stack = [];
isDisposed = false;
get disposed() {
return this.isDisposed;
}
use(value) {
assertNotDisposed(this.isDisposed);
if (value != null) {
const record = value;
const method = record[asyncDisposeSymbol] ?? record[disposeSymbol];
if (typeof method !== 'function') {
throw /* minify-error-disabled */new TypeError('MUI X: The value is not async disposable.');
}
this.stack.push(() => method.call(value));
}
return value;
}
adopt(value, onDisposeAsync) {
assertNotDisposed(this.isDisposed);
this.stack.push(() => onDisposeAsync(value));
return value;
}
defer(onDisposeAsync) {
assertNotDisposed(this.isDisposed);
this.stack.push(onDisposeAsync);
}
move() {
assertNotDisposed(this.isDisposed);
const next = new FallbackAsyncDisposableStack();
next.stack = this.stack;
this.stack = [];
this.isDisposed = true;
return next;
}
async disposeAsync() {
if (this.isDisposed) {
return;
}
this.isDisposed = true;
let hasError = false;
let error;
for (let i = this.stack.length - 1; i >= 0; i -= 1) {
try {
// eslint-disable-next-line no-await-in-loop
await this.stack[i]();
} catch (caught) {
error = hasError ? createSuppressedError(caught, error) : caught;
hasError = true;
}
}
this.stack = [];
if (hasError) {
throw error;
}
}
[asyncDisposeSymbol]() {
return this.disposeAsync();
}
}
/**
* Spec-compliant `DisposableStack`. Prefers the platform's native class when
* present; falls back to a minimal built-in implementation otherwise.
*/
// eslint-disable-next-line @typescript-eslint/no-redeclare
export const DisposableStack = globalThis.DisposableStack ?? FallbackDisposableStack;
/**
* Spec-compliant `AsyncDisposableStack`. Prefers the platform's native class
* when present; falls back to a minimal built-in implementation otherwise.
*/
// eslint-disable-next-line @typescript-eslint/no-redeclare
export const AsyncDisposableStack = globalThis.AsyncDisposableStack ?? FallbackAsyncDisposableStack;
/**
* Unwraps a `SuppressedError` chain (as produced by `DisposableStack.dispose()`
* when multiple disposers throw) into a flat list, outermost failure first.
* Returns `[error]` unchanged if it isn't a `SuppressedError`.
*/
export function unwrapSuppressedErrors(error) {
const failures = [];
let current = error;
while (typeof current === 'object' && current !== null && 'error' in current && 'suppressed' in current) {
failures.push(current.error);
current = current.suppressed;
}
failures.push(current);
return failures;
}
@@ -0,0 +1,6 @@
/**
* Returns the target element of an event, accounting for shadow DOM.
* @param event The event object.
* @returns The target element of the event.
*/
export declare function getTarget(event: Event): EventTarget | null;
@@ -0,0 +1,6 @@
/**
* Returns the target element of an event, accounting for shadow DOM.
* @param event The event object.
* @returns The target element of the event.
*/
export declare function getTarget(event: Event): EventTarget | null;
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getTarget = getTarget;
/**
* Returns the target element of an event, accounting for shadow DOM.
* @param event The event object.
* @returns The target element of the event.
*/
function getTarget(event) {
if ('composedPath' in event) {
return event.composedPath()[0] ?? event.target;
}
// Fallback for environments where `composedPath` is not available.
// TS narrows `event` to `never` here because it assumes `composedPath` always exists.
return event.target;
}
@@ -0,0 +1,14 @@
/**
* Returns the target element of an event, accounting for shadow DOM.
* @param event The event object.
* @returns The target element of the event.
*/
export function getTarget(event) {
if ('composedPath' in event) {
return event.composedPath()[0] ?? event.target;
}
// Fallback for environments where `composedPath` is not available.
// TS narrows `event` to `never` here because it assumes `composedPath` always exists.
return event.target;
}
@@ -0,0 +1,2 @@
export * from "./getTarget.mjs";
export * from "./isHTMLElement.mjs";
@@ -0,0 +1,2 @@
export * from "./getTarget.js";
export * from "./isHTMLElement.js";
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _getTarget = require("./getTarget");
Object.keys(_getTarget).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _getTarget[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _getTarget[key];
}
});
});
var _isHTMLElement = require("./isHTMLElement");
Object.keys(_isHTMLElement).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _isHTMLElement[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _isHTMLElement[key];
}
});
});
@@ -0,0 +1,2 @@
export * from "./getTarget.mjs";
export * from "./isHTMLElement.mjs";
@@ -0,0 +1,4 @@
/**
* Checks if a value is an HTMLElement, including elements from other iframes/realms.
*/
export declare function isHTMLElement(value: unknown): value is HTMLElement;
@@ -0,0 +1,4 @@
/**
* Checks if a value is an HTMLElement, including elements from other iframes/realms.
*/
export declare function isHTMLElement(value: unknown): value is HTMLElement;
@@ -0,0 +1,27 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isHTMLElement = isHTMLElement;
var _ownerWindow = _interopRequireDefault(require("@mui/utils/ownerWindow"));
/**
* Checks if a value is an HTMLElement, including elements from other iframes/realms.
*/
function isHTMLElement(value) {
if (typeof window === 'undefined' || value == null) {
return false;
}
if (value instanceof HTMLElement) {
return true;
}
// Cross-realm: must be an element node (nodeType 1) from another window.
// The try/catch guards against detached/destroyed windows where accessing
// `.HTMLElement` on the owner window may throw.
try {
return value.nodeType === 1 && value instanceof (0, _ownerWindow.default)(value).HTMLElement;
} catch {
return false;
}
}
@@ -0,0 +1,21 @@
import ownerWindow from '@mui/utils/ownerWindow';
/**
* Checks if a value is an HTMLElement, including elements from other iframes/realms.
*/
export function isHTMLElement(value) {
if (typeof window === 'undefined' || value == null) {
return false;
}
if (value instanceof HTMLElement) {
return true;
}
// Cross-realm: must be an element node (nodeType 1) from another window.
// The try/catch guards against detached/destroyed windows where accessing
// `.HTMLElement` on the owner window may throw.
try {
return value.nodeType === 1 && value instanceof ownerWindow(value).HTMLElement;
} catch {
return false;
}
}
@@ -0,0 +1 @@
export { loadStyleSheets } from "./loadStyleSheets.mjs";
@@ -0,0 +1 @@
export { loadStyleSheets } from "./loadStyleSheets.js";
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "loadStyleSheets", {
enumerable: true,
get: function () {
return _loadStyleSheets.loadStyleSheets;
}
});
var _loadStyleSheets = require("./loadStyleSheets");
@@ -0,0 +1 @@
export { loadStyleSheets } from "./loadStyleSheets.mjs";
@@ -0,0 +1,8 @@
/**
* Loads all stylesheets from the given root element into the document.
* @returns an array of promises that resolve when each stylesheet is loaded
* @param document Document to load stylesheets into
* @param root Document or ShadowRoot to load stylesheets from
* @param nonce Optional nonce to set on style elements for CSP compliance
*/
export declare function loadStyleSheets(document: Document, root: Document | ShadowRoot, nonce?: string): Promise<void>[];
@@ -0,0 +1,8 @@
/**
* Loads all stylesheets from the given root element into the document.
* @returns an array of promises that resolve when each stylesheet is loaded
* @param document Document to load stylesheets into
* @param root Document or ShadowRoot to load stylesheets from
* @param nonce Optional nonce to set on style elements for CSP compliance
*/
export declare function loadStyleSheets(document: Document, root: Document | ShadowRoot, nonce?: string): Promise<void>[];
@@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.loadStyleSheets = loadStyleSheets;
/**
* Loads all stylesheets from the given root element into the document.
* @returns an array of promises that resolve when each stylesheet is loaded
* @param document Document to load stylesheets into
* @param root Document or ShadowRoot to load stylesheets from
* @param nonce Optional nonce to set on style elements for CSP compliance
*/
function loadStyleSheets(document, root, nonce) {
const stylesheetLoadPromises = [];
const headStyleElements = root.querySelectorAll("style, link[rel='stylesheet']");
for (let i = 0; i < headStyleElements.length; i += 1) {
const node = headStyleElements[i];
const newHeadStyleElement = document.createElement(node.tagName);
if (node.tagName === 'STYLE') {
const sheet = node.sheet;
if (sheet) {
let styleCSS = '';
for (let j = 0; j < sheet.cssRules.length; j += 1) {
if (typeof sheet.cssRules[j].cssText === 'string') {
styleCSS += `${sheet.cssRules[j].cssText}\r\n`;
}
}
newHeadStyleElement.appendChild(document.createTextNode(styleCSS));
}
} else if (node.getAttribute('href')) {
for (let j = 0; j < node.attributes.length; j += 1) {
const attr = node.attributes[j];
if (attr) {
newHeadStyleElement.setAttribute(attr.nodeName, attr.nodeValue || '');
}
}
stylesheetLoadPromises.push(new Promise(resolve => {
newHeadStyleElement.addEventListener('load', () => resolve());
}));
}
if (nonce) {
newHeadStyleElement.setAttribute('nonce', nonce);
}
document.head.appendChild(newHeadStyleElement);
if (nonce) {
// I don't understand why we need to set the nonce again after appending the element, but I've tested it, and it's
// the only way I could find to fix Chrome's warning about a CSP violation.
newHeadStyleElement.setAttribute('nonce', nonce);
}
}
return stylesheetLoadPromises;
}
@@ -0,0 +1,47 @@
/**
* Loads all stylesheets from the given root element into the document.
* @returns an array of promises that resolve when each stylesheet is loaded
* @param document Document to load stylesheets into
* @param root Document or ShadowRoot to load stylesheets from
* @param nonce Optional nonce to set on style elements for CSP compliance
*/
export function loadStyleSheets(document, root, nonce) {
const stylesheetLoadPromises = [];
const headStyleElements = root.querySelectorAll("style, link[rel='stylesheet']");
for (let i = 0; i < headStyleElements.length; i += 1) {
const node = headStyleElements[i];
const newHeadStyleElement = document.createElement(node.tagName);
if (node.tagName === 'STYLE') {
const sheet = node.sheet;
if (sheet) {
let styleCSS = '';
for (let j = 0; j < sheet.cssRules.length; j += 1) {
if (typeof sheet.cssRules[j].cssText === 'string') {
styleCSS += `${sheet.cssRules[j].cssText}\r\n`;
}
}
newHeadStyleElement.appendChild(document.createTextNode(styleCSS));
}
} else if (node.getAttribute('href')) {
for (let j = 0; j < node.attributes.length; j += 1) {
const attr = node.attributes[j];
if (attr) {
newHeadStyleElement.setAttribute(attr.nodeName, attr.nodeValue || '');
}
}
stylesheetLoadPromises.push(new Promise(resolve => {
newHeadStyleElement.addEventListener('load', () => resolve());
}));
}
if (nonce) {
newHeadStyleElement.setAttribute('nonce', nonce);
}
document.head.appendChild(newHeadStyleElement);
if (nonce) {
// I don't understand why we need to set the nonce again after appending the element, but I've tested it, and it's
// the only way I could find to fix Chrome's warning about a CSP violation.
newHeadStyleElement.setAttribute('nonce', nonce);
}
}
return stylesheetLoadPromises;
}
@@ -0,0 +1,12 @@
/**
* A fast array comparison function that compares two arrays for equality.
*
* Assumes that the arrays are ordered and contain only primitive values.
*
* It is faster than `fastObjectShallowCompare` for arrays.
*
* Returns true for instance equality, even if inputs are not arrays.
*
* @returns true if arrays contain the same elements in the same order, false otherwise.
*/
export declare function fastArrayCompare<T>(a: T, b: T): boolean;
@@ -0,0 +1,12 @@
/**
* A fast array comparison function that compares two arrays for equality.
*
* Assumes that the arrays are ordered and contain only primitive values.
*
* It is faster than `fastObjectShallowCompare` for arrays.
*
* Returns true for instance equality, even if inputs are not arrays.
*
* @returns true if arrays contain the same elements in the same order, false otherwise.
*/
export declare function fastArrayCompare<T>(a: T, b: T): boolean;
@@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fastArrayCompare = fastArrayCompare;
/**
* A fast array comparison function that compares two arrays for equality.
*
* Assumes that the arrays are ordered and contain only primitive values.
*
* It is faster than `fastObjectShallowCompare` for arrays.
*
* Returns true for instance equality, even if inputs are not arrays.
*
* @returns true if arrays contain the same elements in the same order, false otherwise.
*/
function fastArrayCompare(a, b) {
if (a === b) {
return true;
}
if (!Array.isArray(a) || !Array.isArray(b)) {
return false;
}
let i = a.length;
if (i !== b.length) {
return false;
}
// eslint-disable-next-line no-plusplus
while (i--) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
}
@@ -0,0 +1,31 @@
/**
* A fast array comparison function that compares two arrays for equality.
*
* Assumes that the arrays are ordered and contain only primitive values.
*
* It is faster than `fastObjectShallowCompare` for arrays.
*
* Returns true for instance equality, even if inputs are not arrays.
*
* @returns true if arrays contain the same elements in the same order, false otherwise.
*/
export function fastArrayCompare(a, b) {
if (a === b) {
return true;
}
if (!Array.isArray(a) || !Array.isArray(b)) {
return false;
}
let i = a.length;
if (i !== b.length) {
return false;
}
// eslint-disable-next-line no-plusplus
while (i--) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
}
@@ -0,0 +1 @@
export { fastArrayCompare } from "./fastArrayCompare.mjs";
@@ -0,0 +1 @@
export { fastArrayCompare } from "./fastArrayCompare.js";
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "fastArrayCompare", {
enumerable: true,
get: function () {
return _fastArrayCompare.fastArrayCompare;
}
});
var _fastArrayCompare = require("./fastArrayCompare");
@@ -0,0 +1 @@
export { fastArrayCompare } from "./fastArrayCompare.mjs";
@@ -0,0 +1 @@
export declare function fastMemo<T>(component: T): T;
@@ -0,0 +1 @@
export declare function fastMemo<T>(component: T): T;
@@ -0,0 +1,12 @@
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fastMemo = fastMemo;
var React = _interopRequireWildcard(require("react"));
var _fastObjectShallowCompare = require("../fastObjectShallowCompare");
function fastMemo(component) {
return /*#__PURE__*/React.memo(component, _fastObjectShallowCompare.fastObjectShallowCompare);
}
@@ -0,0 +1,5 @@
import * as React from 'react';
import { fastObjectShallowCompare } from "../fastObjectShallowCompare/index.mjs";
export function fastMemo(component) {
return /*#__PURE__*/React.memo(component, fastObjectShallowCompare);
}
@@ -0,0 +1 @@
export { fastMemo } from "./fastMemo.mjs";
@@ -0,0 +1 @@
export { fastMemo } from "./fastMemo.js";
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "fastMemo", {
enumerable: true,
get: function () {
return _fastMemo.fastMemo;
}
});
var _fastMemo = require("./fastMemo");
@@ -0,0 +1 @@
export { fastMemo } from "./fastMemo.mjs";
@@ -0,0 +1,5 @@
/**
* Fast shallow compare for objects.
* @returns true if objects are equal.
*/
export declare function fastObjectShallowCompare<T extends Record<string, any> | null>(a: T, b: T): boolean;
@@ -0,0 +1,5 @@
/**
* Fast shallow compare for objects.
* @returns true if objects are equal.
*/
export declare function fastObjectShallowCompare<T extends Record<string, any> | null>(a: T, b: T): boolean;
@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fastObjectShallowCompare = fastObjectShallowCompare;
const is = Object.is;
/**
* Fast shallow compare for objects.
* @returns true if objects are equal.
*/
function fastObjectShallowCompare(a, b) {
if (a === b) {
return true;
}
if (!(a instanceof Object) || !(b instanceof Object)) {
return false;
}
let aLength = 0;
let bLength = 0;
/* eslint-disable guard-for-in */
for (const key in a) {
aLength += 1;
if (!is(a[key], b[key])) {
return false;
}
if (!(key in b)) {
return false;
}
}
/* eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-unused-vars */
for (const _ in b) {
bLength += 1;
}
return aLength === bLength;
}
@@ -0,0 +1,33 @@
const is = Object.is;
/**
* Fast shallow compare for objects.
* @returns true if objects are equal.
*/
export function fastObjectShallowCompare(a, b) {
if (a === b) {
return true;
}
if (!(a instanceof Object) || !(b instanceof Object)) {
return false;
}
let aLength = 0;
let bLength = 0;
/* eslint-disable guard-for-in */
for (const key in a) {
aLength += 1;
if (!is(a[key], b[key])) {
return false;
}
if (!(key in b)) {
return false;
}
}
/* eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-unused-vars */
for (const _ in b) {
bLength += 1;
}
return aLength === bLength;
}
@@ -0,0 +1 @@
export { fastObjectShallowCompare } from "./fastObjectShallowCompare.mjs";
@@ -0,0 +1 @@
export { fastObjectShallowCompare } from "./fastObjectShallowCompare.js";
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "fastObjectShallowCompare", {
enumerable: true,
get: function () {
return _fastObjectShallowCompare.fastObjectShallowCompare;
}
});
var _fastObjectShallowCompare = require("./fastObjectShallowCompare");
@@ -0,0 +1 @@
export { fastObjectShallowCompare } from "./fastObjectShallowCompare.mjs";
@@ -0,0 +1,10 @@
/**
* WARNING: Don't import this directly. It's imported by the code generated by
* `@mui/internal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
* constructors to ensure the plugin works as expected. Supported patterns include:
* throw new Error('My message');
* throw new Error(`My message: ${foo}`);
* throw new Error(`My message: ${foo}` + 'another string');
* ...
*/
export declare function formatErrorMessage(code: number, ...args: string[]): string;
@@ -0,0 +1,10 @@
/**
* WARNING: Don't import this directly. It's imported by the code generated by
* `@mui/internal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
* constructors to ensure the plugin works as expected. Supported patterns include:
* throw new Error('My message');
* throw new Error(`My message: ${foo}`);
* throw new Error(`My message: ${foo}` + 'another string');
* ...
*/
export declare function formatErrorMessage(code: number, ...args: string[]): string;
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.formatErrorMessage = formatErrorMessage;
/**
* WARNING: Don't import this directly. It's imported by the code generated by
* `@mui/internal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
* constructors to ensure the plugin works as expected. Supported patterns include:
* throw new Error('My message');
* throw new Error(`My message: ${foo}`);
* throw new Error(`My message: ${foo}` + 'another string');
* ...
*/
function formatErrorMessage(code, ...args) {
const url = new URL('https://mui.com/x/production-error');
url.searchParams.set('code', code.toString());
args.forEach(arg => url.searchParams.append('args[]', arg));
return `MUI X error #${code}; visit ${url} for the full message.`;
}
@@ -0,0 +1,15 @@
/**
* WARNING: Don't import this directly. It's imported by the code generated by
* `@mui/internal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
* constructors to ensure the plugin works as expected. Supported patterns include:
* throw new Error('My message');
* throw new Error(`My message: ${foo}`);
* throw new Error(`My message: ${foo}` + 'another string');
* ...
*/
export function formatErrorMessage(code, ...args) {
const url = new URL('https://mui.com/x/production-error');
url.searchParams.set('code', code.toString());
args.forEach(arg => url.searchParams.append('args[]', arg));
return `MUI X error #${code}; visit ${url} for the full message.`;
}
@@ -0,0 +1 @@
export { formatErrorMessage as default } from "./formatErrorMessage.mjs";
@@ -0,0 +1 @@
export { formatErrorMessage as default } from "./formatErrorMessage.js";
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function () {
return _formatErrorMessage.formatErrorMessage;
}
});
var _formatErrorMessage = require("./formatErrorMessage");
@@ -0,0 +1 @@
export { formatErrorMessage as default } from "./formatErrorMessage.mjs";
@@ -0,0 +1,4 @@
import * as React from 'react';
export declare const forwardRef: <T, P = {}>(render: React.ForwardRefRenderFunction<T, P & {
ref: React.Ref<T>;
}>) => React.ForwardRefExoticComponent<P> | React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>;
@@ -0,0 +1,4 @@
import * as React from 'react';
export declare const forwardRef: <T, P = {}>(render: React.ForwardRefRenderFunction<T, P & {
ref: React.Ref<T>;
}>) => React.ForwardRefExoticComponent<P> | React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>;
@@ -0,0 +1,24 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.forwardRef = void 0;
var React = _interopRequireWildcard(require("react"));
var _reactMajor = _interopRequireDefault(require("../reactMajor"));
// Compatibility shim that ensures stable props object for forwardRef components
// Fixes https://github.com/react/react/issues/31613
// We ensure that the ref is always present in the props object (even if that's not the case for older versions of React) to avoid the footgun of spreading props over the ref in the newer versions of React.
// Footgun: <Component ref={ref} {...props} /> will break past React 19, but the types will now warn us that we should use <Component {...props} ref={ref} /> instead.
const forwardRef = render => {
if (_reactMajor.default >= 19) {
const Component = props => render(props, props.ref ?? null);
Component.displayName = render.displayName ?? render.name;
return Component;
}
return /*#__PURE__*/React.forwardRef(render);
};
exports.forwardRef = forwardRef;
if (process.env.NODE_ENV !== "production") forwardRef.displayName = "forwardRef";
@@ -0,0 +1,16 @@
import * as React from 'react';
import reactMajor from "../reactMajor/index.mjs";
// Compatibility shim that ensures stable props object for forwardRef components
// Fixes https://github.com/react/react/issues/31613
// We ensure that the ref is always present in the props object (even if that's not the case for older versions of React) to avoid the footgun of spreading props over the ref in the newer versions of React.
// Footgun: <Component ref={ref} {...props} /> will break past React 19, but the types will now warn us that we should use <Component {...props} ref={ref} /> instead.
export const forwardRef = render => {
if (reactMajor >= 19) {
const Component = props => render(props, props.ref ?? null);
Component.displayName = render.displayName ?? render.name;
return Component;
}
return /*#__PURE__*/React.forwardRef(render);
};
if (process.env.NODE_ENV !== "production") forwardRef.displayName = "forwardRef";
@@ -0,0 +1 @@
export * from "./forwardRef.mjs";
@@ -0,0 +1 @@
export * from "./forwardRef.js";
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _forwardRef = require("./forwardRef");
Object.keys(_forwardRef).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _forwardRef[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _forwardRef[key];
}
});
});
@@ -0,0 +1 @@
export * from "./forwardRef.mjs";
@@ -0,0 +1,6 @@
export declare const hash: typeof xxh;
/**
* Returns an xxh hash of `input` formatted as a decimal string.
*/
declare function xxh(input: string): string;
export {};
@@ -0,0 +1,6 @@
export declare const hash: typeof xxh;
/**
* Returns an xxh hash of `input` formatted as a decimal string.
*/
declare function xxh(input: string): string;
export {};
@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hash = void 0;
const encoder = new TextEncoder();
// bufferLength must be a multiple of 4 to satisfy Int32Array constraints
let bufferLength = 2 * 1024;
let buffer = new ArrayBuffer(bufferLength);
let uint8View = new Uint8Array(buffer);
let int32View = new Int32Array(buffer);
const hash = exports.hash = xxh;
/**
* Returns an xxh hash of `input` formatted as a decimal string.
*/
// prettier-ignore
function xxh(input) {
/* eslint-disable no-bitwise */
// Worst-case scenario: full string of 2-byte characters
const requiredLength = input.length * 2;
if (requiredLength > bufferLength) {
// buffer.resize() is only available in recent browsers, so we re-allocate
// a new and views
bufferLength = requiredLength + (4 - requiredLength % 4);
buffer = new ArrayBuffer(bufferLength);
uint8View = new Uint8Array(buffer);
int32View = new Int32Array(buffer);
}
const length8 = encoder.encodeInto(input, uint8View).written;
const seed = 0;
const len = length8 | 0;
let i = 0;
let h = (seed + len | 0) + 0x165667B1 | 0;
if (len < 16) {
for (; (i + 3 | 0) < len; i = i + 4 | 0) {
h = Math.imul(rotl32(h + Math.imul(int32View[i] | 0, 0xC2B2AE3D) | 0, 17) | 0, 0x27D4EB2F);
}
} else {
let v0 = seed + 0x24234428 | 0;
let v1 = seed + 0x85EBCA77 | 0;
let v2 = seed;
let v3 = seed - 0x9E3779B1 | 0;
for (; (i + 15 | 0) < len; i = i + 16 | 0) {
v0 = Math.imul(rotl32(v0 + Math.imul(int32View[i + 0 | 0] | 0, 0x85EBCA77) | 0, 13) | 0, 0x9E3779B1);
v1 = Math.imul(rotl32(v1 + Math.imul(int32View[i + 4 | 0] | 0, 0x85EBCA77) | 0, 13) | 0, 0x9E3779B1);
v2 = Math.imul(rotl32(v2 + Math.imul(int32View[i + 8 | 0] | 0, 0x85EBCA77) | 0, 13) | 0, 0x9E3779B1);
v3 = Math.imul(rotl32(v3 + Math.imul(int32View[i + 12 | 0] | 0, 0x85EBCA77) | 0, 13) | 0, 0x9E3779B1);
}
h = (((rotl32(v0, 1) | 0 + rotl32(v1, 7) | 0) + rotl32(v2, 12) | 0) + rotl32(v3, 18) | 0) + len | 0;
for (; (i + 3 | 0) < len; i = i + 4 | 0) {
h = Math.imul(rotl32(h + Math.imul(int32View[i] | 0, 0xC2B2AE3D) | 0, 17) | 0, 0x27D4EB2F);
}
}
for (; i < len; i = i + 1 | 0) {
h = Math.imul(rotl32(h + Math.imul(uint8View[i] | 0, 0x165667B1) | 0, 11) | 0, 0x9E3779B1);
}
h = Math.imul(h ^ h >>> 15, 0x85EBCA77);
h = Math.imul(h ^ h >>> 13, 0xC2B2AE3D);
return ((h ^ h >>> 16) >>> 0).toString();
}
function rotl32(x, r) {
return x << r | x >>> 32 - r;
}
@@ -0,0 +1,61 @@
const encoder = new TextEncoder();
// bufferLength must be a multiple of 4 to satisfy Int32Array constraints
let bufferLength = 2 * 1024;
let buffer = new ArrayBuffer(bufferLength);
let uint8View = new Uint8Array(buffer);
let int32View = new Int32Array(buffer);
export const hash = xxh;
/**
* Returns an xxh hash of `input` formatted as a decimal string.
*/
// prettier-ignore
function xxh(input) {
/* eslint-disable no-bitwise */
// Worst-case scenario: full string of 2-byte characters
const requiredLength = input.length * 2;
if (requiredLength > bufferLength) {
// buffer.resize() is only available in recent browsers, so we re-allocate
// a new and views
bufferLength = requiredLength + (4 - requiredLength % 4);
buffer = new ArrayBuffer(bufferLength);
uint8View = new Uint8Array(buffer);
int32View = new Int32Array(buffer);
}
const length8 = encoder.encodeInto(input, uint8View).written;
const seed = 0;
const len = length8 | 0;
let i = 0;
let h = (seed + len | 0) + 0x165667B1 | 0;
if (len < 16) {
for (; (i + 3 | 0) < len; i = i + 4 | 0) {
h = Math.imul(rotl32(h + Math.imul(int32View[i] | 0, 0xC2B2AE3D) | 0, 17) | 0, 0x27D4EB2F);
}
} else {
let v0 = seed + 0x24234428 | 0;
let v1 = seed + 0x85EBCA77 | 0;
let v2 = seed;
let v3 = seed - 0x9E3779B1 | 0;
for (; (i + 15 | 0) < len; i = i + 16 | 0) {
v0 = Math.imul(rotl32(v0 + Math.imul(int32View[i + 0 | 0] | 0, 0x85EBCA77) | 0, 13) | 0, 0x9E3779B1);
v1 = Math.imul(rotl32(v1 + Math.imul(int32View[i + 4 | 0] | 0, 0x85EBCA77) | 0, 13) | 0, 0x9E3779B1);
v2 = Math.imul(rotl32(v2 + Math.imul(int32View[i + 8 | 0] | 0, 0x85EBCA77) | 0, 13) | 0, 0x9E3779B1);
v3 = Math.imul(rotl32(v3 + Math.imul(int32View[i + 12 | 0] | 0, 0x85EBCA77) | 0, 13) | 0, 0x9E3779B1);
}
h = (((rotl32(v0, 1) | 0 + rotl32(v1, 7) | 0) + rotl32(v2, 12) | 0) + rotl32(v3, 18) | 0) + len | 0;
for (; (i + 3 | 0) < len; i = i + 4 | 0) {
h = Math.imul(rotl32(h + Math.imul(int32View[i] | 0, 0xC2B2AE3D) | 0, 17) | 0, 0x27D4EB2F);
}
}
for (; i < len; i = i + 1 | 0) {
h = Math.imul(rotl32(h + Math.imul(uint8View[i] | 0, 0x165667B1) | 0, 11) | 0, 0x9E3779B1);
}
h = Math.imul(h ^ h >>> 15, 0x85EBCA77);
h = Math.imul(h ^ h >>> 13, 0xC2B2AE3D);
return ((h ^ h >>> 16) >>> 0).toString();
}
function rotl32(x, r) {
return x << r | x >>> 32 - r;
}
@@ -0,0 +1 @@
export * from "./hash.mjs";
@@ -0,0 +1 @@
export * from "./hash.js";
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _hash = require("./hash");
Object.keys(_hash).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _hash[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _hash[key];
}
});
});
@@ -0,0 +1 @@
export * from "./hash.mjs";
@@ -0,0 +1 @@
export * from "./isDeepEqual.mjs";
@@ -0,0 +1 @@
export * from "./isDeepEqual.js";
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _isDeepEqual = require("./isDeepEqual");
Object.keys(_isDeepEqual).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _isDeepEqual[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _isDeepEqual[key];
}
});
});
@@ -0,0 +1 @@
export * from "./isDeepEqual.mjs";
@@ -0,0 +1,29 @@
/**
* Based on `fast-deep-equal`
*
* MIT License
*
* Copyright (c) 2017 Evgeny Poberezkin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* Check if two values are deeply equal.
*/
export declare function isDeepEqual<T>(actual: any, expected: T): actual is T;

Some files were not shown because too many files have changed in this diff Show More