@m3e/core 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -112,6 +112,88 @@ class MonitorControllerBase {
112
112
  }
113
113
  _MonitorControllerBase_host = new WeakMap(), _MonitorControllerBase_target = new WeakMap(), _MonitorControllerBase_targets = new WeakMap();
114
114
 
115
+ /**
116
+ * Determines whether forced colors are active.
117
+ * @returns {boolean} Whether forced colors are active.
118
+ */
119
+ function forcedColorsActive() {
120
+ return !isServer && matchMedia("(forced-colors: active)").matches;
121
+ }
122
+
123
+ /**
124
+ * Gets the text content of a given node, including slotted content.
125
+ * @param {Node} node The node for which to get text content.
126
+ * @param {boolean} [trim = false] A value indicating whether to trim content.
127
+ * @returns {string} The text content of `node`.
128
+ */
129
+ function getTextContent(node, trim = false) {
130
+ let textContent = "";
131
+ switch (node.nodeType) {
132
+ case Node.TEXT_NODE:
133
+ textContent = node.nodeValue ?? "";
134
+ break;
135
+ case Node.ELEMENT_NODE:
136
+ if (node instanceof HTMLSlotElement) {
137
+ for (const assignedNode of node.assignedNodes({ flatten: true })) {
138
+ textContent += getTextContent(assignedNode, trim);
139
+ }
140
+ }
141
+ else {
142
+ for (const child of node.childNodes) {
143
+ textContent += getTextContent(child, trim);
144
+ }
145
+ }
146
+ break;
147
+ }
148
+ if (trim) {
149
+ textContent = textContent.trim();
150
+ }
151
+ return textContent;
152
+ }
153
+
154
+ /**
155
+ * Generates a new globally unique identifier (GUID).
156
+ * @returns {string} A new globally unique identifier.
157
+ */
158
+ function guid() {
159
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
160
+ const r = (Math.random() * 16) | 0;
161
+ const v = c === "x" ? r : (r & 0x3) | 0x8;
162
+ return v.toString(16);
163
+ });
164
+ }
165
+
166
+ /**
167
+ * Determines whether a slot has any assigned nodes.
168
+ * @param {HTMLSlotElement} slot The slot to test.
169
+ * @returns {boolean} Whether `slot` has any assigned nodes.
170
+ */
171
+ function hasAssignedNodes(slot) {
172
+ return slot.assignedNodes({ flatten: true }).length > 0;
173
+ }
174
+
175
+ /**
176
+ * Determines whether reduced motion is preferred.
177
+ * @returns {boolean} Whether reduced motion is preferred.
178
+ */
179
+ function prefersReducedMotion() {
180
+ return isServer || matchMedia("(prefers-reduced-motion)").matches;
181
+ }
182
+
183
+ /**
184
+ * If needed, scrolls an element into view within a given scroll container.
185
+ * @param {HTMLElement} element The element to scroll into view.
186
+ * @param {HTMLElement} scrollContainer The scrollable container.
187
+ * @param {ScrollIntoViewOptions} [options=undefined] Options used to scroll into view.
188
+ */
189
+ function scrollIntoViewIfNeeded(element, scrollContainer, options) {
190
+ const containerBounds = scrollContainer.getBoundingClientRect();
191
+ const elementBounds = element.getBoundingClientRect();
192
+ if (elementBounds.top < containerBounds.top || elementBounds.bottom > containerBounds.bottom) {
193
+ element.scrollIntoView(options);
194
+ }
195
+ }
196
+
115
197
  var _FocusController_instances, _FocusController_callback, _FocusController_focusInHandler, _FocusController_focusOutHandler, _FocusController_handleFocusIn, _FocusController_handleFocusOut;
116
198
  /** A `ReactiveController` used to monitor the focused state of one or more elements. */
117
199
  class FocusController extends MonitorControllerBase {
@@ -149,7 +231,7 @@ class FocusController extends MonitorControllerBase {
149
231
  }
150
232
  _FocusController_callback = new WeakMap(), _FocusController_focusInHandler = new WeakMap(), _FocusController_focusOutHandler = new WeakMap(), _FocusController_instances = new WeakSet(), _FocusController_handleFocusIn = function _FocusController_handleFocusIn(e) {
151
233
  const target = e.target;
152
- __classPrivateFieldGet(this, _FocusController_callback, "f").call(this, true, target.matches(":focus-visible") || matchMedia("(forced-colors: active)").matches, target);
234
+ __classPrivateFieldGet(this, _FocusController_callback, "f").call(this, true, target.matches(":focus-visible") || forcedColorsActive(), target);
153
235
  }, _FocusController_handleFocusOut = function _FocusController_handleFocusOut(e) {
154
236
  __classPrivateFieldGet(this, _FocusController_callback, "f").call(this, false, false, e.target);
155
237
  };
@@ -2896,80 +2978,6 @@ function Vertical(base) {
2896
2978
  return _VerticalMixin;
2897
2979
  }
2898
2980
 
2899
- /**
2900
- * Gets the text content of a given node, including slotted content.
2901
- * @param {Node} node The node for which to get text content.
2902
- * @param {boolean} [trim = false] A value indicating whether to trim content.
2903
- * @returns {string} The text content of `node`.
2904
- */
2905
- function getTextContent(node, trim = false) {
2906
- let textContent = "";
2907
- switch (node.nodeType) {
2908
- case Node.TEXT_NODE:
2909
- textContent = node.nodeValue ?? "";
2910
- break;
2911
- case Node.ELEMENT_NODE:
2912
- if (node instanceof HTMLSlotElement) {
2913
- for (const assignedNode of node.assignedNodes({ flatten: true })) {
2914
- textContent += getTextContent(assignedNode, trim);
2915
- }
2916
- }
2917
- else {
2918
- for (const child of node.childNodes) {
2919
- textContent += getTextContent(child, trim);
2920
- }
2921
- }
2922
- break;
2923
- }
2924
- if (trim) {
2925
- textContent = textContent.trim();
2926
- }
2927
- return textContent;
2928
- }
2929
-
2930
- /**
2931
- * Generates a new globally unique identifier (GUID).
2932
- * @returns {string} A new globally unique identifier.
2933
- */
2934
- function guid() {
2935
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
2936
- const r = (Math.random() * 16) | 0;
2937
- const v = c === "x" ? r : (r & 0x3) | 0x8;
2938
- return v.toString(16);
2939
- });
2940
- }
2941
-
2942
- /**
2943
- * Determines whether a slot has any assigned nodes.
2944
- * @param {HTMLSlotElement} slot The slot to test.
2945
- * @returns {boolean} Whether `slot` has any assigned nodes.
2946
- */
2947
- function hasAssignedNodes(slot) {
2948
- return slot.assignedNodes({ flatten: true }).length > 0;
2949
- }
2950
-
2951
- /**
2952
- * Determines whether reduced motion is preferred.
2953
- * @returns {boolean} Whether reduced motion is preferred.
2954
- */
2955
- function prefersReducedMotion() {
2956
- return isServer || matchMedia("(prefers-reduced-motion)").matches;
2957
- }
2958
-
2959
- /**
2960
- * If needed, scrolls an element into view within a given scroll container.
2961
- * @param {HTMLElement} element The element to scroll into view.
2962
- * @param {HTMLElement} scrollContainer The scrollable container.
2963
- * @param {ScrollIntoViewOptions} [options=undefined] Options used to scroll into view.
2964
- */
2965
- function scrollIntoViewIfNeeded(element, scrollContainer, options) {
2966
- const containerBounds = scrollContainer.getBoundingClientRect();
2967
- const elementBounds = element.getBoundingClientRect();
2968
- if (elementBounds.top < containerBounds.top || elementBounds.bottom > containerBounds.bottom) {
2969
- element.scrollIntoView(options);
2970
- }
2971
- }
2972
-
2973
2981
  /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
2974
2982
  var _M3eCollapsibleElement_instances, _M3eCollapsibleElement_slotChanged, _M3eCollapsibleElement_hasOpened, _M3eCollapsibleElement_handleSlotChange, _M3eCollapsibleElement_autoSize, _M3eCollapsibleElement_clearSize, _M3eCollapsibleElement_actualSize;
2975
2983
  /**
@@ -4756,5 +4764,5 @@ M3eTextHighlightElement = M3eTextHighlightElement_1 = __decorate([
4756
4764
  t$2("m3e-text-highlight")
4757
4765
  ], M3eTextHighlightElement);
4758
4766
 
4759
- export { AttachInternals, Checked, CheckedIndeterminate, ConstraintValidation, DesignToken, Dirty, Disabled, DisabledInteractive, EventAttribute, FocusController, Focusable, FormAssociated, FormSubmitter, HoverController, HtmlFor, IntersectionController, KeyboardClick, Labelled, LinkButton, LongPressController, M3eCollapsibleElement, M3eElevationElement, M3eFocusRingElement, M3ePseudoCheckboxElement, M3ePseudoRadioElement, M3eRippleElement, M3eScrollContainerElement, M3eSlideElement, M3eStateLayerElement, M3eTextHighlightElement, M3eTextOverflowElement, MutationController, PressedController, ReadOnly, Required, RequiredConstraintValidation, ResizeController, Role, ScrollController, Selected, Touched, Vertical, checkOrSelect, debounce, defaultValue, formValue, getTextContent, guid, hasAssignedNodes, hasKeys, internals, isAttachInternalsMixin, isCheckedIndeterminateMixin, isCheckedMixin, isCheckedOrSelected, isCheckedOrSelectedMixin, isConstraintValidationMixin, isDirtyMixin, isDisabledInteractiveMixin, isDisabledMixin, isFormAssociatedMixin, isFormSubmitterMixin, isHtmlForMixin, isLabelledMixin, isLinkButtonMixin, isReadOnlyMixin, isRequiredConstraintValidationMixin, isRequiredMixin, isSelectedMixin, isTouchedMixin, isVerticalMixin, prefersReducedMotion, renderPseudoLink, safeStyleMap, scrollIntoViewIfNeeded, updateLabels, validate };
4767
+ export { AttachInternals, Checked, CheckedIndeterminate, ConstraintValidation, DesignToken, Dirty, Disabled, DisabledInteractive, EventAttribute, FocusController, Focusable, FormAssociated, FormSubmitter, HoverController, HtmlFor, IntersectionController, KeyboardClick, Labelled, LinkButton, LongPressController, M3eCollapsibleElement, M3eElevationElement, M3eFocusRingElement, M3ePseudoCheckboxElement, M3ePseudoRadioElement, M3eRippleElement, M3eScrollContainerElement, M3eSlideElement, M3eStateLayerElement, M3eTextHighlightElement, M3eTextOverflowElement, MutationController, PressedController, ReadOnly, Required, RequiredConstraintValidation, ResizeController, Role, ScrollController, Selected, Touched, Vertical, checkOrSelect, debounce, defaultValue, forcedColorsActive, formValue, getTextContent, guid, hasAssignedNodes, hasKeys, internals, isAttachInternalsMixin, isCheckedIndeterminateMixin, isCheckedMixin, isCheckedOrSelected, isCheckedOrSelectedMixin, isConstraintValidationMixin, isDirtyMixin, isDisabledInteractiveMixin, isDisabledMixin, isFormAssociatedMixin, isFormSubmitterMixin, isHtmlForMixin, isLabelledMixin, isLinkButtonMixin, isReadOnlyMixin, isRequiredConstraintValidationMixin, isRequiredMixin, isSelectedMixin, isTouchedMixin, isVerticalMixin, prefersReducedMotion, renderPseudoLink, safeStyleMap, scrollIntoViewIfNeeded, updateLabels, validate };
4760
4768
  //# sourceMappingURL=index.js.map