@reticular/speakable 1.6.0 → 1.7.0

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/mcp.js CHANGED
@@ -849,17 +849,54 @@ function processChildNode(node, children, warnings) {
849
849
  }
850
850
  }
851
851
  function collectChildrenFromRolelessElement(element, warnings) {
852
+ return collectAccessibleChildren(element, warnings);
853
+ }
854
+ function collectAccessibleChildren(element, warnings) {
852
855
  const children = [];
853
856
  if (element.shadowRoot) {
854
857
  for (const child of Array.from(element.shadowRoot.childNodes)) {
855
- processChildNode(child, children, warnings);
858
+ processShadowNode(child, children, warnings);
856
859
  }
860
+ return children;
861
+ }
862
+ if (element.localName && element.localName.includes("-") && element.childNodes.length === 0) {
863
+ warnings.push({
864
+ message: `Custom element <${element.localName}> has no accessible children and may have a closed shadow root; its content could not be analyzed.`,
865
+ element
866
+ });
857
867
  }
858
868
  for (const child of Array.from(element.childNodes)) {
859
869
  processChildNode(child, children, warnings);
860
870
  }
861
871
  return children;
862
872
  }
873
+ function processShadowNode(node, children, warnings) {
874
+ if (node.nodeType === 1) {
875
+ const element = node;
876
+ if (element.localName === "slot") {
877
+ const slot = element;
878
+ let assigned = [];
879
+ if (typeof slot.assignedNodes === "function") {
880
+ try {
881
+ assigned = Array.from(slot.assignedNodes({ flatten: true }));
882
+ } catch {
883
+ assigned = [];
884
+ }
885
+ }
886
+ if (assigned.length > 0) {
887
+ for (const assignedNode of assigned) {
888
+ processChildNode(assignedNode, children, warnings);
889
+ }
890
+ } else {
891
+ for (const child of Array.from(slot.childNodes)) {
892
+ processShadowNode(child, children, warnings);
893
+ }
894
+ }
895
+ return;
896
+ }
897
+ }
898
+ processChildNode(node, children, warnings);
899
+ }
863
900
  function buildAccessibilityTree(rootElement, sourceHash) {
864
901
  const warnings = [];
865
902
  if (isHidden(rootElement)) {
@@ -952,15 +989,7 @@ function buildNodeRecursive(element, warnings) {
952
989
  element: w.element
953
990
  })));
954
991
  const focusInfo = extractFocusInfo(element);
955
- const children = [];
956
- if (element.shadowRoot) {
957
- for (const child of Array.from(element.shadowRoot.childNodes)) {
958
- processChildNode(child, children, warnings);
959
- }
960
- }
961
- for (const child of Array.from(element.childNodes)) {
962
- processChildNode(child, children, warnings);
963
- }
992
+ const children = collectAccessibleChildren(element, warnings);
964
993
  const node = {
965
994
  role: roleResult.role,
966
995
  name: nameResult.name,
@@ -973,15 +1002,7 @@ function buildNodeRecursive(element, warnings) {
973
1002
  return node;
974
1003
  }
975
1004
  function createGenericContainer(rootElement, warnings) {
976
- const children = [];
977
- if (rootElement.shadowRoot) {
978
- for (const child of Array.from(rootElement.shadowRoot.childNodes)) {
979
- processChildNode(child, children, warnings);
980
- }
981
- }
982
- for (const child of Array.from(rootElement.childNodes)) {
983
- processChildNode(child, children, warnings);
984
- }
1005
+ const children = collectAccessibleChildren(rootElement, warnings);
985
1006
  return {
986
1007
  role: "generic",
987
1008
  name: "",