Best JavaScript code snippet using wpt
Command.ts
Source:Command.ts
...428 // æ¯å¦æ¯ä¸¤ä¸ªç¸åçåé429 // 两个éé½æ¯å½ä»¤ççæå¼ï¼å¦æ两个å为空430 // æè
é½æ¯å符串并ä¸ç¸çï¼å¹¶ä¸å½ä»¤æ²¡æå®ä¹ä»»ä½ equivalentValuesï¼431 // æè
两个é½æ¯å符串ï¼å¹¶ä¸å½ä»¤å®ä¹äº equivalentValues 并ä¸å®ä»¬ä¸å®ä¹å¹é
ã432 function areEquivalentValues(command, val1, val2) {433 if (val1 === null && val2 === null) {434 return true;435 }436 if (typeof val1 == "string"437 && typeof val2 == "string"438 && val1 == val2439 && !("equivalentValues" in commands.get(command))) {440 return true;441 }442 if (typeof val1 == "string"443 && typeof val2 == "string"444 && "equivalentValues" in commands.get(command)445 && commands.get(command).equivalentValues(val1, val2)) {446 return true;447 }448 return false;449 }450 // æ¾æ£æ¯è¾ä¸¤ä¸ªå¼451 function areLooselyEquivalentValues(command, val1, val2) {452 const sizeMap = new Map();453 if (areEquivalentValues(command, val1, val2)) {454 return true;455 }456 if (command != "fontsize"457 || typeof val1 != "string"458 || typeof val2 != "string") {459 return false;460 }461 let font = document.createElement("font");462 document.body.appendChild(font);463 ["x-small", "small", "medium", "large", "x-large", "xx-large", "xxx-large"].forEach(function(keyword) {464 font.size = utils.cssSizeToLegacy(keyword);465 sizeMap.set(keyword, getComputedStyle(font).fontSize)466 });467 document.body.removeChild(font);468 return val1 === sizeMap.get(val2)469 || val2 === sizeMap.get(val1);470 }471 // 强å¶è®¾ç½®å¼472 function forceValue(node, command, newValue) {473 // "If node's parent is null, abort this algorithm."474 // å¦æèç¹çç¶çº§ä¸æ¯å
ç´ ï¼åä¸æ¢è¯¥ç®æ³ã475 if (!node.parentNode) {476 return;477 }478 // "If new value is null, abort this algorithm."479 if (newValue === null) {480 return;481 }482 // "If node is an allowed child of "span":"483 if (utils.isAllowedChild(node, "span")) {484 // "Reorder modifiable descendants of node's previousSibling."485 reorderModifiableDescendants(node.previousSibling, command, newValue);486 // "Reorder modifiable descendants of node's nextSibling."487 reorderModifiableDescendants(node.nextSibling, command, newValue);488 // "Wrap the one-node list consisting of node, with sibling criteria489 // returning true for a simple modifiable element whose specified490 // command value is equivalent to new value and whose effective command491 // value is loosely equivalent to new value and false otherwise, and492 // with new parent instructions returning null."493 wrap([node],494 function(node) {495 return utils.isSimpleModifiableElement(node)496 && areEquivalentValues(command, getSpecifiedCommandValue(node, command), newValue)497 && areLooselyEquivalentValues(command, getEffectiveCommandValue(node, command), newValue);498 },499 function() { return null }500 );501 }502 // "If node is invisible, abort this algorithm."503 if (utils.isInvisible(node)) {504 return;505 }506 // "If the effective command value of command is loosely equivalent to new507 // value on node, abort this algorithm."508 if (areLooselyEquivalentValues(command, getEffectiveCommandValue(node, command), newValue)) {509 return;510 }511 // "If node is not an allowed child of "span":"512 if (!utils.isAllowedChild(node, "span")) {513 // "Let children be all children of node, omitting any that are514 // Elements whose specified command value for command is neither null515 // nor equivalent to new value."516 let children = [];517 for (let i = 0; i < node.childNodes.length; i++) {518 if (node.childNodes[i].nodeType == Node.ELEMENT_NODE) {519 let specifiedValue = getSpecifiedCommandValue(node.childNodes[i], command);520 if (specifiedValue !== null521 && !areEquivalentValues(command, newValue, specifiedValue)) {522 continue;523 }524 }525 children.push(node.childNodes[i]);526 }527 // "Force the value of each Node in children, with command and new528 // value as in this invocation of the algorithm."529 for (let i = 0; i < children.length; i++) {530 forceValue(children[i], command, newValue);531 }532 // "Abort this algorithm."533 return;534 }535 // "If the effective command value of command is loosely equivalent to new536 // value on node, abort this algorithm."537 if (areLooselyEquivalentValues(command, getEffectiveCommandValue(node, command), newValue)) {538 return;539 }540 // "Let new parent be null."541 let newParent = null;542 // "If the CSS styling flag is false:"543 if (!cssStylingFlag) {544 // "If command is "bold" and new value is "bold", let new parent be the545 // result of calling createElement("b") on the ownerDocument of node."546 if (command == "bold" && (newValue == "bold" || newValue == "700")) {547 newParent = node.ownerDocument.createElement("b");548 }549 // "If command is "italic" and new value is "italic", let new parent be550 // the result of calling createElement("i") on the ownerDocument of551 // node."552 if (command == "italic" && newValue == "italic") {553 newParent = node.ownerDocument.createElement("i");554 }555 // "If command is "strikethrough" and new value is "line-through", let556 // new parent be the result of calling createElement("s") on the557 // ownerDocument of node."558 if (command == "strikethrough" && newValue == "line-through") {559 newParent = node.ownerDocument.createElement("s");560 }561 // "If command is "underline" and new value is "underline", let new562 // parent be the result of calling createElement("u") on the563 // ownerDocument of node."564 if (command == "underline" && newValue == "underline") {565 newParent = node.ownerDocument.createElement("u");566 }567 // "If command is "foreColor", and new value is fully opaque with red,568 // green, and blue components in the range 0 to 255:"569 if (command == "forecolor" && utils.parseSimpleColor(newValue)) {570 // "Let new parent be the result of calling createElement("font")571 // on the ownerDocument of node."572 newParent = node.ownerDocument.createElement("font");573 // "Set the color attribute of new parent to the result of applying574 // the rules for serializing simple color values to new value575 // (interpreted as a simple color)."576 newParent.setAttribute("color", utils.parseSimpleColor(newValue));577 }578 // "If command is "fontName", let new parent be the result of calling579 // createElement("font") on the ownerDocument of node, then set the580 // face attribute of new parent to new value."581 if (command == "fontname") {582 newParent = node.ownerDocument.createElement("font");583 newParent.face = newValue;584 }585 }586 // "If command is "createLink" or "unlink":"587 if (command == "createlink" || command == "unlink") {588 // "Let new parent be the result of calling createElement("a") on the589 // ownerDocument of node."590 newParent = node.ownerDocument.createElement("a");591 // "Set the href attribute of new parent to new value."592 newParent.setAttribute("href", newValue);593 // "Let ancestor be node's parent."594 let ancestor = node.parentNode;595 // "While ancestor is not null:"596 while (ancestor) {597 // "If ancestor is an a, set the tag name of ancestor to "span",598 // and let ancestor be the result."599 if (utils.isHtmlElement(ancestor, "A")) {600 ancestor = selection.setTagName(ancestor, "span");601 }602 // "Set ancestor to its parent."603 ancestor = ancestor.parentNode;604 }605 }606 // "If command is "fontSize"; and new value is one of "x-small", "small",607 // "medium", "large", "x-large", "xx-large", or "xxx-large"; and either the608 // CSS styling flag is false, or new value is "xxx-large": let new parent609 // be the result of calling createElement("font") on the ownerDocument of610 // node, then set the size attribute of new parent to the number from the611 // following table based on new value: [table omitted]"612 if (command == "fontsize"613 && ["x-small", "small", "medium", "large", "x-large", "xx-large", "xxx-large"].indexOf(newValue) != -1614 && (!cssStylingFlag || newValue == "xxx-large")) {615 newParent = node.ownerDocument.createElement("font");616 newParent.size = utils.cssSizeToLegacy(newValue);617 }618 // "If command is "subscript" or "superscript" and new value is619 // "subscript", let new parent be the result of calling620 // createElement("sub") on the ownerDocument of node."621 if ((command == "subscript" || command == "superscript")622 && newValue == "subscript") {623 newParent = node.ownerDocument.createElement("sub");624 }625 // "If command is "subscript" or "superscript" and new value is626 // "superscript", let new parent be the result of calling627 // createElement("sup") on the ownerDocument of node."628 if ((command == "subscript" || command == "superscript")629 && newValue == "superscript") {630 newParent = node.ownerDocument.createElement("sup");631 }632 // "If new parent is null, let new parent be the result of calling633 // createElement("span") on the ownerDocument of node."634 if (!newParent) {635 newParent = node.ownerDocument.createElement("span");636 }637 // "Insert new parent in node's parent before node."638 node.parentNode.insertBefore(newParent, node);639 // "If the effective command value of command for new parent is not loosely640 // equivalent to new value, and the relevant CSS property for command is641 // not null, set that CSS property of new parent to new value (if the new642 // value would be valid)."643 let property = commands.get(command).relevantCssProperty;644 if (property !== null645 && !areLooselyEquivalentValues(command, getEffectiveCommandValue(newParent, command), newValue)) {646 newParent.style[property] = newValue;647 }648 // "If command is "strikethrough", and new value is "line-through", and the649 // effective command value of "strikethrough" for new parent is not650 // "line-through", set the "text-decoration" property of new parent to651 // "line-through"."652 if (command == "strikethrough"653 && newValue == "line-through"654 && getEffectiveCommandValue(newParent, "strikethrough") != "line-through") {655 newParent.style.textDecoration = "line-through";656 }657 // "If command is "underline", and new value is "underline", and the658 // effective command value of "underline" for new parent is not659 // "underline", set the "text-decoration" property of new parent to660 // "underline"."661 if (command == "underline"662 && newValue == "underline"663 && getEffectiveCommandValue(newParent, "underline") != "underline") {664 newParent.style.textDecoration = "underline";665 }666 // "Append node to new parent as its last child, preserving ranges."667 selection.movePreservingRanges(node, newParent, newParent.childNodes.length);668 // "If node is an Element and the effective command value of command for669 // node is not loosely equivalent to new value:"670 if (node.nodeType == Node.ELEMENT_NODE671 && !areEquivalentValues(command, getEffectiveCommandValue(node, command), newValue)) {672 // "Insert node into the parent of new parent before new parent,673 // preserving ranges."674 selection.movePreservingRanges(node, newParent.parentNode, utils.getNodeIndex(newParent));675 // "Remove new parent from its parent."676 newParent.parentNode.removeChild(newParent);677 // "Let children be all children of node, omitting any that are678 // Elements whose specified command value for command is neither null679 // nor equivalent to new value."680 let children = [];681 for (let i = 0; i < node.childNodes.length; i++) {682 if (node.childNodes[i].nodeType == Node.ELEMENT_NODE) {683 let specifiedValue = getSpecifiedCommandValue(node.childNodes[i], command);684 if (specifiedValue !== null685 && !areEquivalentValues(command, newValue, specifiedValue)) {686 continue;687 }688 }689 children.push(node.childNodes[i]);690 }691 // "Force the value of each Node in children, with command and new692 // value as in this invocation of the algorithm."693 for (let i = 0; i < children.length; i++) {694 forceValue(children[i], command, newValue);695 }696 }697 }698 // éæ°æåå¯ä¿®æ¹çå代699 function reorderModifiableDescendants(node, command, newValue) {700 // "Let candidate equal node."701 let candidate = node;702 // "While candidate is a modifiable element, and candidate has exactly one703 // child, and that child is also a modifiable element, and candidate is not704 // a simple modifiable element or candidate's specified command value for705 // command is not equivalent to new value, set candidate to its child."706 while (utils.isModifiableElement(candidate)707 && candidate.childNodes.length == 1708 && utils.isModifiableElement(candidate.firstChild)709 && (!utils.isSimpleModifiableElement(candidate)710 || !areEquivalentValues(command, getSpecifiedCommandValue(candidate, command), newValue))) {711 candidate = candidate.firstChild;712 }713 // "If candidate is node, or is not a simple modifiable element, or its714 // specified command value is not equivalent to new value, or its effective715 // command value is not loosely equivalent to new value, abort these716 // steps."717 if (candidate == node718 || !utils.isSimpleModifiableElement(candidate)719 || !areEquivalentValues(command, getSpecifiedCommandValue(candidate, command), newValue)720 || !areLooselyEquivalentValues(command, getEffectiveCommandValue(candidate, command), newValue)) {721 return;722 }723 // "While candidate has children, insert the first child of candidate into724 // candidate's parent immediately before candidate, preserving ranges."725 while (candidate.hasChildNodes()) {726 selection.movePreservingRanges(candidate.firstChild, candidate.parentNode, utils.getNodeIndex(candidate));727 }728 // "Insert candidate into node's parent immediately after node."729 node.parentNode.insertBefore(candidate, node.nextSibling);730 // "Append the node as the last child of candidate, preserving ranges."731 selection.movePreservingRanges(node, candidate, -1);732 }733 function wrap(nodeList, siblingCriteria, newParentInstructions) {734 // "If not provided, sibling criteria returns false and new parent735 // instructions returns null."736 //âå¦ææªæä¾ï¼åå级æ¡ä»¶è¿åfalseåæ°çç¶çº§737 //æä»¤ä¼ ånullãâ738 if (typeof siblingCriteria == "undefined") {739 siblingCriteria = function() { return false };740 }741 if (typeof newParentInstructions == "undefined") {742 newParentInstructions = function() { return null };743 }744 // "If every member of node list is invisible, and none is a br, return745 // null and abort these steps."746 if (nodeList.every(utils.isInvisible)747 && !nodeList.some(function(node) { return utils.isHtmlElement(node, "br") })) {748 return null;749 }750 // "If node list's first member's parent is null, return null and abort751 // these steps."752 if (!nodeList[0].parentNode) {753 return null;754 }755 // "If node list's last member is an inline node that's not a br, and node756 // list's last member's nextSibling is a br, append that br to node list."757 if (utils.isInlineNode(nodeList[nodeList.length - 1])758 && !utils.isHtmlElement(nodeList[nodeList.length - 1], "br")759 && utils.isHtmlElement(nodeList[nodeList.length - 1].nextSibling, "br")) {760 nodeList.push(nodeList[nodeList.length - 1].nextSibling);761 }762 // "While node list's first member's previousSibling is invisible, prepend763 // it to node list."764 while (utils.isInvisible(nodeList[0].previousSibling)) {765 nodeList.unshift(nodeList[0].previousSibling);766 }767 // "While node list's last member's nextSibling is invisible, append it to768 // node list."769 while (utils.isInvisible(nodeList[nodeList.length - 1].nextSibling)) {770 nodeList.push(nodeList[nodeList.length - 1].nextSibling);771 }772 // "If the previousSibling of the first member of node list is editable and773 // running sibling criteria on it returns true, let new parent be the774 // previousSibling of the first member of node list."775 let newParent;776 if (utils.isEditable(nodeList[0].previousSibling)777 && siblingCriteria(nodeList[0].previousSibling)) {778 newParent = nodeList[0].previousSibling;779 // "Otherwise, if the nextSibling of the last member of node list is780 // editable and running sibling criteria on it returns true, let new parent781 // be the nextSibling of the last member of node list."782 } else if (utils.isEditable(nodeList[nodeList.length - 1].nextSibling)783 && siblingCriteria(nodeList[nodeList.length - 1].nextSibling)) {784 newParent = nodeList[nodeList.length - 1].nextSibling;785 // "Otherwise, run new parent instructions, and let new parent be the786 // result."787 } else {788 newParent = newParentInstructions();789 }790 // "If new parent is null, abort these steps and return null."791 if (!newParent) {792 return null;793 }794 // "If new parent's parent is null:"795 if (!newParent.parentNode) {796 // "Insert new parent into the parent of the first member of node list797 // immediately before the first member of node list."798 nodeList[0].parentNode.insertBefore(newParent, nodeList[0]);799 // "If any range has a boundary point with node equal to the parent of800 // new parent and offset equal to the index of new parent, add one to801 // that boundary point's offset."802 //803 // Only try to fix the global range.804 if (selection.range.startContainer == newParent.parentNode805 && selection.range.startOffset == utils.getNodeIndex(newParent)) {806 selection.range.setStart(selection.range.startContainer, selection.range.startOffset + 1);807 }808 if (selection.range.endContainer == newParent.parentNode809 && selection.range.endOffset == utils.getNodeIndex(newParent)) {810 selection.range.setEnd(selection.range.endContainer, selection.range.endOffset + 1);811 }812 }813 // "Let original parent be the parent of the first member of node list."814 let originalParent = nodeList[0].parentNode;815 // "If new parent is before the first member of node list in tree order:"816 if (utils.isBefore(newParent, nodeList[0])) {817 // "If new parent is not an inline node, but the last visible child of818 // new parent and the first visible member of node list are both inline819 // nodes, and the last child of new parent is not a br, call820 // createElement("br") on the ownerDocument of new parent and append821 // the result as the last child of new parent."822 if (!utils.isInlineNode(newParent)823 && utils.isInlineNode([].filter.call(newParent.childNodes, utils.isVisible).slice(-1)[0])824 && utils.isInlineNode(nodeList.filter(utils.isVisible)[0])825 && !utils.isHtmlElement(newParent.lastChild, "BR")) {826 newParent.appendChild(newParent.ownerDocument.createElement("br"));827 }828 // "For each node in node list, append node as the last child of new829 // parent, preserving ranges."830 for (let i = 0; i < nodeList.length; i++) {831 selection.movePreservingRanges(nodeList[i], newParent, -1);832 }833 // "Otherwise:"834 } else {835 // "If new parent is not an inline node, but the first visible child of836 // new parent and the last visible member of node list are both inline837 // nodes, and the last member of node list is not a br, call838 // createElement("br") on the ownerDocument of new parent and insert839 // the result as the first child of new parent."840 if (!utils.isInlineNode(newParent)841 && utils.isInlineNode([].filter.call(newParent.childNodes, utils.isVisible)[0])842 && utils.isInlineNode(nodeList.filter(utils.isVisible).slice(-1)[0])843 && !utils.isHtmlElement(nodeList[nodeList.length - 1], "BR")) {844 newParent.insertBefore(newParent.ownerDocument.createElement("br"), newParent.firstChild);845 }846 // "For each node in node list, in reverse order, insert node as the847 // first child of new parent, preserving ranges."848 for (let i = nodeList.length - 1; i >= 0; i--) {849 selection.movePreservingRanges(nodeList[i], newParent, 0);850 }851 }852 // "If original parent is editable and has no children, remove it from its853 // parent."854 if (utils.isEditable(originalParent) && !originalParent.hasChildNodes()) {855 originalParent.parentNode.removeChild(originalParent);856 }857 // "If new parent's nextSibling is editable and running sibling criteria on858 // it returns true:"859 if (utils.isEditable(newParent.nextSibling)860 && siblingCriteria(newParent.nextSibling)) {861 // "If new parent is not an inline node, but new parent's last child862 // and new parent's nextSibling's first child are both inline nodes,863 // and new parent's last child is not a br, call createElement("br") on864 // the ownerDocument of new parent and append the result as the last865 // child of new parent."866 if (!utils.isInlineNode(newParent)867 && utils.isInlineNode(newParent.lastChild)868 && utils.isInlineNode(newParent.nextSibling.firstChild)869 && !utils.isHtmlElement(newParent.lastChild, "BR")) {870 newParent.appendChild(newParent.ownerDocument.createElement("br"));871 }872 // "While new parent's nextSibling has children, append its first child873 // as the last child of new parent, preserving ranges."874 while (newParent.nextSibling.hasChildNodes()) {875 selection.movePreservingRanges(newParent.nextSibling.firstChild, newParent, -1);876 }877 // "Remove new parent's nextSibling from its parent."878 newParent.parentNode.removeChild(newParent.nextSibling);879 }880 // "Remove extraneous line breaks from new parent."881 utils.removeExtraneousLineBreaksFrom(newParent);882 // "Return new parent."883 return newParent;884 }885 // åºç¨å½åç»æ886 function pushDownValues(node, command, newValue) {887 // å¦æèç¹çç¶çº§ä¸æ¯å
ç´ ï¼åä¸æ¢è¯¥ç®æ³ã888 if (!node.parentNode889 || node.parentNode.nodeType != Node.ELEMENT_NODE) {890 return;891 }892 // å¦æå½åå½ä»¤ææï¼å¹¶ä¸åæ§çå
ç´ ä¸çå¼éè¿æ¾æ£å¹é
ç¸çï¼å°±ä¸è®¾ç½®893 if (areLooselyEquivalentValues(command, getEffectiveCommandValue(node, command), newValue)) {894 return;895 }896 // è·å¾å
Œ
񇝆
897 let currentAncestor = node.parentNode;898 // åå§å ancestor list 为空899 let ancestorList = [];900 // éå½æ¾å°æè¿çç¶èç¹ï¼å¦æå½åæ°ç command ä¸çäºæ§å¼ï¼åå°ç¶èç¹å å
¥å° ancestorList901 while (utils.isEditable(currentAncestor)902 && currentAncestor.nodeType == Node.ELEMENT_NODE903 && !areLooselyEquivalentValues(command, getEffectiveCommandValue(currentAncestor, command), newValue)) {904 ancestorList.push(currentAncestor);905 currentAncestor = currentAncestor.parentNode;906 }907 // å¦æ没æå¾
æ´æ°è³ï¼è¿å908 if (!ancestorList.length) {909 return;910 }911 // å 为 dom èç¹æ ·å¼é½æ¯ç»§æ¿çãæ以è¿å ancestorList æåä¸ä¸ªå
ç´ å³æè¿çç¥å
èç¹912 let propagatedValue = getSpecifiedCommandValue(ancestorList[ancestorList.length - 1], command);913 // å¦æ propagatedValue æ¯ null 并ä¸ä¸çäºæ°çå¼ï¼å°±ç»æ¢914 if (propagatedValue === null && propagatedValue != newValue) {915 return;916 }917 // å¦æå½ä»¤çå¼ææï¼å¹¶ä¸å
Œ
±çç¥å
èç¹æ¾æ£å¹é
ä¸çäºæ°çç»æï¼è¿æ¶æ°çç»æä¹ä¸æ¯ç©ºå¼ï¼å°±ç»æ¢918 if (newValue !== null919 && !areLooselyEquivalentValues(command, getEffectiveCommandValue(ancestorList[ancestorList.length - 1].parentNode, command), newValue)) {920 return;921 }922 // æ¸
空 ancestorList æ 923 while (ancestorList.length) {924 let currentAncestor = ancestorList.pop();925 // åºæ è¿ç¨ä¸ï¼å¦ææ个èç¹å«ææå®çæ ·å¼ï¼å°±è®¾ç½®æå®çä¼ æå¼926 if (getSpecifiedCommandValue(currentAncestor, command) !== null) {927 propagatedValue = getSpecifiedCommandValue(currentAncestor, command);928 }929 let children = Array.prototype.slice.call(currentAncestor.childNodes);930 // å¦æcommandçå½åç¥å
çæå®å½ä»¤å¼ä¸ä¸ºç©ºï¼åæ¸
é¤å½åç¥å
çå¼ã931 if (getSpecifiedCommandValue(currentAncestor, command) !== null) {932 clearValue(currentAncestor, command);933 }934 // å¤çæ¯ä¸ª children935 for (let i = 0; i < children.length; i++) {936 let child = children[i];937 // å¦æ chide == node, è·³è¿å½åå¤ç938 if (child == node) {939 continue;940 }941 // å¦æ child æ¯ä¸ä¸ª Elementï¼å
¶ command çæå®å½ä»¤å¼æ¢ä¸ä¸ºç©ºä¹ä¸çåäº propagatedValeï¼å继ç»ä¸ä¸ä¸ª childã942 if (child.nodeType == Node.ELEMENT_NODE943 && getSpecifiedCommandValue(child, command) !== null944 && !areEquivalentValues(command, propagatedValue, getSpecifiedCommandValue(child, command))) {945 continue;946 }947 // å¦æ child == ancestorList[ancestorList.length - 1]ï¼è·³è¿948 if (child == ancestorList[ancestorList.length - 1]) {949 continue;950 }951 // 强å¶ä½¿ç¨ child çå¼ï¼å¹¶ä¸æ´æ° æ°å¼çäºä¼ æçå¼ã952 forceValue(child, command, propagatedValue);953 }954 }955 }956 function recordCurrentOverrides() {957 // åå§åoverrides958 let overrides = [];959 // ä¼å
å¤çè¶
é¾æ¥960 if (internalOverride.getValueOverride("createlink") !== undefined) {961 overrides.push(["createlink", internalOverride.getValueOverride("createlink")]);962 }963 // è¿äºå¼åªæ true å false964 const verifyState = ["bold", "italic", "strikethrough", "subscript", "superscript", "underline"]965 verifyState.forEach(function(command) {966 if (internalOverride.getStateOverride(command) !== undefined) {967 overrides.push([command, internalOverride.getStateOverride(command)]);968 }969 });970 // è¿äºæ¯æå¼ç971 const verifyValue = ["fontname", "fontsize", "forecolor", "hilitecolor"]972 verifyValue.forEach(function(command) {973 if (internalOverride.getValueOverride(command) !== undefined) {974 overrides.push([command, internalOverride.getValueOverride(command)]);975 }976 });977 return overrides;978 }979 function restoreStatesAndValues(overrides) {980 // "Let node be the first formattable node effectively contained in the981 // active range, or null if there is none."982 let node = utils.getAllEffectivelyContainedNodes(selection.getActiveRange())983 .filter(utils.isFormattableNode)[0];984 // "If node is not null, then for each (command, override) pair in985 // overrides, in order:"986 if (node) {987 for (let i = 0; i < overrides.length; i++) {988 let command = overrides[i][0];989 let override = overrides[i][1];990 // "If override is a boolean, and queryCommandState(command)991 // returns something different from override, take the action for992 // command, with value equal to the empty string."993 if (typeof override == "boolean"994 && queryCommandState(command) != override) {995 commands.get(command).action("");996 // "Otherwise, if override is a string, and command is neither997 // "createLink" nor "fontSize", and queryCommandValue(command)998 // returns something not equivalent to override, take the action999 // for command, with value equal to override."1000 } else if (typeof override == "string"1001 && command != "createlink"1002 && command != "fontsize"1003 && !areEquivalentValues(command, queryCommandValue(command), override)) {1004 commands.get(command).action(override);1005 // "Otherwise, if override is a string; and command is1006 // "createLink"; and either there is a value override for1007 // "createLink" that is not equal to override, or there is no value1008 // override for "createLink" and node's effective command value for1009 // "createLink" is not equal to override: take the action for1010 // "createLink", with value equal to override."1011 } else if (typeof override == "string"1012 && command == "createlink"1013 && (1014 (1015 internalOverride.getValueOverride("createlink") !== undefined1016 && internalOverride.getValueOverride("createlink") !== override1017 ) || (...
d549ba877ef2abdd028ad56f175ed0eccb0425c1_1_25.js
Source:d549ba877ef2abdd028ad56f175ed0eccb0425c1_1_25.js
...20 // with new parent instructions returning null."21 wrap([node],22 function(node) {23 return isSimpleModifiableElement(node)24 && areEquivalentValues(command, getSpecifiedCommandValue(node, command), newValue)25 && areLooselyEquivalentValues(command, getEffectiveCommandValue(node, command), newValue);26 },27 function() { return null },28 range29 );30 }31 // "If the effective command value of command is loosely equivalent to new32 // value on node, abort this algorithm."33 if (areLooselyEquivalentValues(command, getEffectiveCommandValue(node, command), newValue)) {34 return;35 }36 // "If node is not an allowed child of "span":"37 if (!isAllowedChild(node, "span")) {38 // "Let children be all children of node, omitting any that are39 // Elements whose specified command value for command is neither null40 // nor equivalent to new value."41 var children = [];42 for (var i = 0; i < node.childNodes.length; i++) {43 if (node.childNodes[i].nodeType == Node.ELEMENT_NODE) {44 var specifiedValue = getSpecifiedCommandValue(node.childNodes[i], command);45 if (specifiedValue !== null46 && !areEquivalentValues(command, newValue, specifiedValue)) {47 continue;48 }49 }50 children.push(node.childNodes[i]);51 }52 // "Force the value of each Node in children, with command and new53 // value as in this invocation of the algorithm."54 for (var i = 0; i < children.length; i++) {55 forceValue(children[i], command, newValue, range);56 }57 // "Abort this algorithm."58 return;59 }60 // "If the effective command value of command is loosely equivalent to new61 // value on node, abort this algorithm."62 if (areLooselyEquivalentValues(command, getEffectiveCommandValue(node, command), newValue)) {63 return;64 }65 // "Let new parent be null."66 var newParent = null;67 // "If the CSS styling flag is false:"68 if (!cssStylingFlag) {69 // "If command is "bold" and new value is "bold", let new parent be the70 // result of calling createElement("b") on the ownerDocument of node."71 if (command == "bold" && (newValue == "bold" || newValue == "700")) {72 newParent = node.ownerDocument.createElement("b");73 }74 // "If command is "italic" and new value is "italic", let new parent be75 // the result of calling createElement("i") on the ownerDocument of76 // node."77 if (command == "italic" && newValue == "italic") {78 newParent = node.ownerDocument.createElement("i");79 }80 // "If command is "strikethrough" and new value is "line-through", let81 // new parent be the result of calling createElement("s") on the82 // ownerDocument of node."83 if (command == "strikethrough" && newValue == "line-through") {84 newParent = node.ownerDocument.createElement("s");85 }86 // "If command is "underline" and new value is "underline", let new87 // parent be the result of calling createElement("u") on the88 // ownerDocument of node."89 if (command == "underline" && newValue == "underline") {90 newParent = node.ownerDocument.createElement("u");91 }92 // "If command is "foreColor", and new value is fully opaque with red,93 // green, and blue components in the range 0 to 255:"94 if (command == "forecolor" && parseSimpleColor(newValue)) {95 // "Let new parent be the result of calling createElement("span")96 // on the ownerDocument of node."97 // NOTE: modified this process to create span elements with style attributes98 // instead of oldschool font tags with color attributes99 newParent = node.ownerDocument.createElement("span");100 // "If new value is an extended color keyword, set the color101 // attribute of new parent to new value."102 //103 // "Otherwise, set the color attribute of new parent to the result104 // of applying the rules for serializing simple color values to new105 // value (interpreted as a simple color)."106 jQuery(newParent).css('color', parseSimpleColor(newValue));107 }108 // "If command is "fontName", let new parent be the result of calling109 // createElement("font") on the ownerDocument of node, then set the110 // face attribute of new parent to new value."111 if (command == "fontname") {112 newParent = node.ownerDocument.createElement("font");113 newParent.face = newValue;114 }115 }116 // "If command is "createLink" or "unlink":"117 if (command == "createlink" || command == "unlink") {118 // "Let new parent be the result of calling createElement("a") on the119 // ownerDocument of node."120 newParent = node.ownerDocument.createElement("a");121 // "Set the href attribute of new parent to new value."122 newParent.setAttribute("href", newValue);123 // "Let ancestor be node's parent."124 var ancestor = node.parentNode;125 // "While ancestor is not null:"126 while (ancestor) {127 // "If ancestor is an a, set the tag name of ancestor to "span",128 // and let ancestor be the result."129 if (isHtmlElement(ancestor, "A")) {130 ancestor = setTagName(ancestor, "span", range);131 }132 // "Set ancestor to its parent."133 ancestor = ancestor.parentNode;134 }135 }136 // "If command is "fontSize"; and new value is one of "xx-small", "small",137 // "medium", "large", "x-large", "xx-large", or "xxx-large"; and either the138 // CSS styling flag is false, or new value is "xxx-large": let new parent139 // be the result of calling createElement("font") on the ownerDocument of140 // node, then set the size attribute of new parent to the number from the141 // following table based on new value: [table omitted]"142 if (command == "fontsize"143 && ["xx-small", "small", "medium", "large", "x-large", "xx-large", "xxx-large"].indexOf(newValue) != -1144 && (!cssStylingFlag || newValue == "xxx-large")) {145 newParent = node.ownerDocument.createElement("font");146 newParent.size = cssSizeToLegacy(newValue);147 }148 // "If command is "subscript" or "superscript" and new value is149 // "subscript", let new parent be the result of calling150 // createElement("sub") on the ownerDocument of node."151 if ((command == "subscript" || command == "superscript")152 && newValue == "subscript") {153 newParent = node.ownerDocument.createElement("sub");154 }155 // "If command is "subscript" or "superscript" and new value is156 // "superscript", let new parent be the result of calling157 // createElement("sup") on the ownerDocument of node."158 if ((command == "subscript" || command == "superscript")159 && newValue == "superscript") {160 newParent = node.ownerDocument.createElement("sup");161 }162 // "If new parent is null, let new parent be the result of calling163 // createElement("span") on the ownerDocument of node."164 if (!newParent) {165 newParent = node.ownerDocument.createElement("span");166 }167 // "Insert new parent in node's parent before node."168 node.parentNode.insertBefore(newParent, node);169 // "If the effective command value of command for new parent is not loosely170 // equivalent to new value, and the relevant CSS property for command is171 // not null, set that CSS property of new parent to new value (if the new172 // value would be valid)."173 var property = commands[command].relevantCssProperty;174 if (property !== null175 && !areLooselyEquivalentValues(command, getEffectiveCommandValue(newParent, command), newValue)) {176 newParent.style[property] = newValue;177 }178 // "If command is "strikethrough", and new value is "line-through", and the179 // effective command value of "strikethrough" for new parent is not180 // "line-through", set the "text-decoration" property of new parent to181 // "line-through"."182 if (command == "strikethrough"183 && newValue == "line-through"184 && getEffectiveCommandValue(newParent, "strikethrough") != "line-through") {185 newParent.style.textDecoration = "line-through";186 }187 // "If command is "underline", and new value is "underline", and the188 // effective command value of "underline" for new parent is not189 // "underline", set the "text-decoration" property of new parent to190 // "underline"."191 if (command == "underline"192 && newValue == "underline"193 && getEffectiveCommandValue(newParent, "underline") != "underline") {194 newParent.style.textDecoration = "underline";195 }196 // "Append node to new parent as its last child, preserving ranges."197 movePreservingRanges(node, newParent, newParent.childNodes.length, range);198 // "If node is an Element and the effective command value of command for199 // node is not loosely equivalent to new value:"200 if (node.nodeType == Node.ELEMENT_NODE201 && !areEquivalentValues(command, getEffectiveCommandValue(node, command), newValue)) {202 // "Insert node into the parent of new parent before new parent,203 // preserving ranges."204 movePreservingRanges(node, newParent.parentNode, getNodeIndex(newParent), range);205 // "Remove new parent from its parent."206 newParent.parentNode.removeChild(newParent);207 // "Let children be all children of node, omitting any that are208 // Elements whose specified command value for command is neither null209 // nor equivalent to new value."210 var children = [];211 for (var i = 0; i < node.childNodes.length; i++) {212 if (node.childNodes[i].nodeType == Node.ELEMENT_NODE) {213 var specifiedValue = getSpecifiedCommandValue(node.childNodes[i], command);214 if (specifiedValue !== null215 && !areEquivalentValues(command, newValue, specifiedValue)) {216 continue;217 }218 }219 children.push(node.childNodes[i]);220 }221 // "Force the value of each Node in children, with command and new222 // value as in this invocation of the algorithm."223 for (var i = 0; i < children.length; i++) {224 forceValue(children[i], command, newValue, range);225 }226 }...
Using AI Code Generation
1var wptools = require('wptools');2var areEquivalentValues = wptools.areEquivalentValues;3console.log(areEquivalentValues('en', 'en', 'en'));4console.log(areEquivalentValues('en', 'en', 'fr'));5console.log(areEquivalentValues('en', 'fr', 'en'));6console.log(areEquivalentValues('en', 'fr', 'fr'));7console.log(areEquivalentValues('fr', 'en', 'en'));8console.log(areEquivalentValues('fr', 'en', 'fr'));9console.log(areEquivalentValues('fr', 'fr', 'en'));10console.log(areEquivalentValues('fr', 'fr', 'fr'));
Using AI Code Generation
1var wpt = require('./wpt.js');2var areEquivalentValues = wpt.areEquivalentValues;3var a = 1;4var b = 1;5var c = 2;6var d = '1';7function areEquivalentValues(a, b) {8 return a == b;9}10module.exports = {11};12> at Object. (C:\Users\user\test.js:5:15)13> at Module._compile (module.js:652:30)14> at Object.Module._extensions..js (module.js:663:10)15> at Module.load (module.js:565:32)16> at tryModuleLoad (module.js:505:12)17> at Function.Module._load (module.js:497:3)18> at Function.Module.runMain (module.js:693:10)19> at startup (bootstrap_node.js:188:16)20var wpt = require('./wpt.js');
Using AI Code Generation
1var wpt = require('wpt'); 2var areEquivalentValues = wpt.areEquivalentValues;3var actual = 1;4var expected = 1;5console.log(areEquivalentValues(actual, expected));6var wpt = require('wpt'); 7var areEquivalentValues = wpt.areEquivalentValues;8var actual = 1;9var expected = 2;10console.log(areEquivalentValues(actual, expected));11var wpt = require('wpt'); 12var areEquivalentValues = wpt.areEquivalentValues;13var actual = 1;14var expected = "1";15console.log(areEquivalentValues(actual, expected));16var wpt = require('wpt'); 17var areEquivalentValues = wpt.areEquivalentValues;18var actual = 1;19var expected = true;20console.log(areEquivalentValues(actual, expected));21var wpt = require('wpt'); 22var areEquivalentValues = wpt.areEquivalentValues;23var actual = true;24var expected = true;25console.log(areEquivalentValues(actual, expected));26var wpt = require('wpt'); 27var areEquivalentValues = wpt.areEquivalentValues;28var actual = true;29var expected = false;30console.log(areEquivalentValues(actual, expected));31var wpt = require('wpt'); 32var areEquivalentValues = wpt.areEquivalentValues;33var actual = true;34var expected = "true";35console.log(areEquivalentValues(actual, expected));36var wpt = require('wpt'); 37var areEquivalentValues = wpt.areEquivalentValues;38var actual = true;39var expected = 1;40console.log(areEquivalentValues(actual, expected));
Using AI Code Generation
1var wpt = require('wpt');2var assert = require('assert');3var test = require('selenium-webdriver/testing');4test.describe('WPT', function() {5 test.it('should return true', function() {6 assert.equal(true, wpt.areEquivalentValues(1, 1));7 });8});9var wpt = function() {10 return {11 areEquivalentValues: function(val1, val2) {12 return val1 === val2;13 }14 };15};16module.exports = wpt();17module.exports = {18 areEquivalentValues: function(val1, val2) {19 return val1 === val2;20 }21};22var wpt = require('wpt');23var assert = require('assert');24var test = require('selenium-webdriver/testing');25test.describe('WPT', function() {26 test.it('should return true', function() {27 assert.equal(true, wpt.areEquivalentValues(1, 1));28 });29});30module.exports = function(grunt) {31 grunt.initConfig({32 });33 grunt.loadNpmTasks('grunt-contrib-jasmine');34 grunt.registerTask('default', ['jasmine']);35};36var wpt = require('../wpt');37var assert = require('assert');38var test = require('selenium-webdriver/testing');39test.describe('WPT', function() {40 test.it('should return true', function() {41 assert.equal(true, wpt.areEquivalentValues(1, 1));42 });43});
Using AI Code Generation
1var areEquivalentValues = require('wpt-runner').areEquivalentValues;2var assert = require('assert');3describe('areEquivalentValues', function() {4 it('should return true when values are equivalent', function() {5 assert(areEquivalentValues(1,1));6 assert(areEquivalentValues('1',1));7 assert(areEquivalentValues('abc','abc'));8 assert(areEquivalentValues([1,2,3],[1,2,3]));9 assert(areEquivalentValues({a:1,b:2},{a:1,b:2}));10 });11 it('should return false when values are not equivalent', function() {12 assert(!areEquivalentValues(1,2));13 assert(!areEquivalentValues('1',2));14 assert(!areEquivalentValues('abc','cba'));15 assert(!areEquivalentValues([1,2,3],[1,2,4]));16 assert(!areEquivalentValues({a:1,b:2},{a:1,b:3}));17 });18});
Using AI Code Generation
1var wpt = require('wpt');2var assert = require('assert');3var actual1 = "Hello";4var expected1 = "Hello";5assert(wpt.areEquivalentValues(actual1, expected1));6var actual2 = "Hello";7var expected2 = "hello";8assert(wpt.areEquivalentValues(actual2, expected2));9var actual3 = "Hello";10var expected3 = "Hello1";11assert(!wpt.areEquivalentValues(actual3, expected3));12var actual4 = "Hello";13var expected4 = "Hello1";14assert(wpt.areEquivalentValues(actual4, expected4, true));15var actual5 = "Hello";16var expected5 = "Hello1";17assert(!wpt.areEquivalentValues(actual5, expected5, false));18var actual6 = "Hello";19var expected6 = "Hello1";20assert(wpt.areEquivalentValues(actual6, expected6, true));21var actual7 = "Hello";22var expected7 = "Hello1";23assert(wpt.areEquivalentValues(actual7, expected7, false));24var actual8 = "Hello";25var expected8 = "Hello1";26assert(wpt.areEquivalentValues(actual8, expected8, true));27var actual9 = "Hello";28var expected9 = "Hello1";29assert(!wpt.areEquivalentValues(actual9, expected9, false));30var actual10 = "Hello";31var expected10 = "Hello1";32assert(wpt.areEquivalentValues(actual10, expected10, true));33var actual11 = "Hello";34var expected11 = "Hello1";35assert(!wpt.areEquivalentValues(actual11, expected11, false));36var actual12 = "Hello";37var expected12 = "Hello1";38assert(wpt.areEquivalentValues(actual12, expected12, true));39var actual13 = "Hello";40var expected13 = "Hello1";41assert(!wpt.areEquivalentValues(actual13, expected13, false));42var actual14 = "Hello";43var expected14 = "Hello1";44assert(wpt.areEquivalentValues(actual14
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var value1 = 'abc';3var value2 = 'abc';4var areValuesEqual = wptoolkit.areEquivalentValues(value1, value2);5console.log('Are the two values equal: ' + areValuesEqual);6var wptoolkit = require('wptoolkit');7var value1 = 'abc';8var value2 = 'xyz';9var areValuesEqual = wptoolkit.areEquivalentValues(value1, value2);10console.log('Are the two values equal: ' + areValuesEqual);11var wptoolkit = require('wptoolkit');12var value1 = 123;13var value2 = 123;14var areValuesEqual = wptoolkit.areEquivalentValues(value1, value2);15console.log('Are the two values equal: ' + areValuesEqual);16var wptoolkit = require('wptoolkit');17var value1 = 123;18var value2 = 456;19var areValuesEqual = wptoolkit.areEquivalentValues(value1, value2);20console.log('Are the two values equal: ' + areValuesEqual);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!