diff --git a/dist/igv.esm.js b/dist/igv.esm.js deleted file mode 100644 index d3fed0168..000000000 --- a/dist/igv.esm.js +++ /dev/null @@ -1,51699 +0,0 @@ -let igv; - -(function (root, factory) { - - - igv = factory(); - -}(this, function () { - - - -(function () { - - var css = '.igv-user-feedback {\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 512px;\n height: 360px;\n z-index: 2048;\n background-color: white;\n border-color: #a2a2a2;\n border-style: solid;\n border-width: thin;\n font-family: \"Open Sans\", sans-serif;\n font-size: medium;\n font-weight: 400;\n color: #444;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-user-feedback div:first-child {\n position: relative;\n height: 24px;\n width: 100%;\n background-color: white;\n border-bottom-color: #a2a2a2;\n border-bottom-style: solid;\n border-bottom-width: thin; }\n .igv-user-feedback div:first-child div {\n position: absolute;\n top: 2px;\n width: 16px;\n height: 16px;\n background-color: transparent; }\n .igv-user-feedback div:first-child div:first-child {\n left: 8px; }\n .igv-user-feedback div:first-child div:last-child {\n cursor: pointer;\n right: 8px; }\n .igv-user-feedback div:last-child {\n width: 100%;\n height: calc(100% - 24px);\n border-width: 0; }\n .igv-user-feedback div:last-child div {\n width: auto;\n height: auto;\n margin: 8px; }\n\n.igv-color-swatch {\n display: flex;\n flex-flow: row;\n flex-wrap: wrap;\n justify-content: center;\n align-items: center;\n width: 32px;\n height: 32px;\n border-style: solid;\n border-width: 2px;\n border-color: white;\n border-radius: 4px; }\n\n.igv-colorpicker-menu-close-button {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center;\n width: 100%;\n height: 32px;\n margin-top: 4px;\n margin-bottom: 4px;\n padding-right: 8px; }\n .igv-colorpicker-menu-close-button i.fa {\n display: block;\n margin-left: 4px;\n margin-right: 4px;\n color: #5f5f5f; }\n .igv-colorpicker-menu-close-button i.fa:hover,\n .igv-colorpicker-menu-close-button i.fa:focus,\n .igv-colorpicker-menu-close-button i.fa:active {\n cursor: pointer;\n color: #0f0f0f; }\n\n.igv-alert-dialog-container {\n position: absolute;\n top: 0;\n left: 0;\n width: 300px;\n height: 256px;\n border-color: #7F7F7F;\n border-radius: 4px;\n border-style: solid;\n border-width: thin;\n font-family: \"Open Sans\", sans-serif;\n font-size: 15px;\n font-weight: 400;\n z-index: 2048;\n background-color: white;\n display: flex;\n flex-flow: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-alert-dialog-container div:first-child {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center;\n width: 100%;\n height: 24px;\n cursor: move;\n border-top-left-radius: 4px;\n border-top-right-radius: 4px;\n border-bottom-color: #7F7F7F;\n border-bottom-style: solid;\n border-bottom-width: thin;\n background-color: #eee; }\n .igv-alert-dialog-container div:first-child div {\n margin-right: 4px;\n margin-bottom: 2px;\n height: 12px;\n width: 12px;\n color: #7F7F7F; }\n .igv-alert-dialog-container div:first-child div:hover {\n cursor: pointer;\n color: #444; }\n .igv-alert-dialog-container #igv-alert-dialog-body {\n color: #373737;\n width: 100%;\n height: calc(100% - 24px - 64px);\n overflow-y: scroll; }\n .igv-alert-dialog-container #igv-alert-dialog-body #igv-alert-dialog-body-copy {\n cursor: pointer;\n margin: 16px;\n width: auto;\n height: auto;\n overflow-wrap: break-word;\n word-break: break-word;\n background-color: white;\n border: unset; }\n .igv-alert-dialog-container div:last-child {\n width: 100%;\n height: 64px;\n background-color: white;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: center;\n align-items: center; }\n .igv-alert-dialog-container div:last-child div {\n width: 98px;\n height: 36px;\n line-height: 36px;\n text-align: center;\n color: white;\n font-family: \"Open Sans\", sans-serif;\n font-size: medium;\n font-weight: 400;\n border-color: #2B81AF;\n border-style: solid;\n border-width: thin;\n border-radius: 4px;\n background-color: #2B81AF; }\n .igv-alert-dialog-container div:last-child div:hover {\n cursor: pointer;\n border-color: #25597f;\n background-color: #25597f; }\n\n.igv-generic-container {\n position: absolute;\n top: 0;\n left: 0;\n z-index: 2048;\n background-color: white;\n cursor: pointer;\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-generic-container div:first-child {\n cursor: move;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center;\n height: 24px;\n width: 100%;\n background-color: #dddddd; }\n .igv-generic-container div:first-child i {\n display: block;\n color: #5f5f5f;\n cursor: pointer;\n width: 14px;\n height: 14px;\n margin-right: 8px;\n margin-bottom: 4px; }\n\n.igv-generic-dialog-container {\n position: absolute;\n top: 0;\n left: 0;\n width: 300px;\n height: 200px;\n border-color: #7F7F7F;\n border-radius: 4px;\n border-style: solid;\n border-width: thin;\n font-family: \"Open Sans\", sans-serif;\n font-size: medium;\n font-weight: 400;\n z-index: 2048;\n background-color: white;\n display: flex;\n flex-flow: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-header {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center;\n width: 100%;\n height: 24px;\n cursor: move;\n border-top-left-radius: 4px;\n border-top-right-radius: 4px;\n border-bottom-color: #7F7F7F;\n border-bottom-style: solid;\n border-bottom-width: thin;\n background-color: #eee; }\n .igv-generic-dialog-container .igv-generic-dialog-header div {\n margin-right: 4px;\n margin-bottom: 2px;\n height: 12px;\n width: 12px;\n color: #7F7F7F; }\n .igv-generic-dialog-container .igv-generic-dialog-header div:hover {\n cursor: pointer;\n color: #444; }\n .igv-generic-dialog-container .igv-generic-dialog-one-liner {\n color: #373737;\n width: 95%;\n height: 24px;\n line-height: 24px;\n text-align: left;\n margin-top: 8px;\n padding-left: 8px;\n overflow-wrap: break-word;\n background-color: white; }\n .igv-generic-dialog-container .igv-generic-dialog-label-input {\n margin-top: 8px;\n width: 95%;\n height: 24px;\n color: #373737;\n line-height: 24px;\n padding-left: 8px;\n background-color: white;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-label-input div {\n width: 30%;\n height: 100%;\n font-size: 16px;\n text-align: right;\n padding-right: 8px;\n background-color: white; }\n .igv-generic-dialog-container .igv-generic-dialog-label-input input {\n display: block;\n height: 100%;\n width: 100%;\n padding-left: 4px;\n font-family: \"Open Sans\", sans-serif;\n font-weight: 400;\n color: #373737;\n text-align: left;\n outline: none;\n border-style: solid;\n border-width: thin;\n border-color: #7F7F7F;\n background-color: white; }\n .igv-generic-dialog-container .igv-generic-dialog-label-input input {\n width: 50%;\n font-size: 16px; }\n .igv-generic-dialog-container .igv-generic-dialog-input {\n margin-top: 8px;\n width: calc(100% - 16px);\n height: 24px;\n color: #373737;\n line-height: 24px;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-around;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-input input {\n display: block;\n height: 100%;\n width: 100%;\n padding-left: 4px;\n font-family: \"Open Sans\", sans-serif;\n font-weight: 400;\n color: #373737;\n text-align: left;\n outline: none;\n border-style: solid;\n border-width: thin;\n border-color: #7F7F7F;\n background-color: white; }\n .igv-generic-dialog-container .igv-generic-dialog-input input {\n font-size: 16px; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel {\n width: 100%;\n height: 28px;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-around;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div {\n margin-top: 32px;\n color: white;\n font-family: \"Open Sans\", sans-serif;\n font-size: 14px;\n font-weight: 400;\n width: 75px;\n height: 28px;\n line-height: 28px;\n text-align: center;\n border-color: transparent;\n border-style: solid;\n border-width: thin;\n border-radius: 2px; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div:first-child {\n margin-left: 32px;\n margin-right: 0;\n background-color: #5ea4e0; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div:last-child {\n margin-left: 0;\n margin-right: 32px;\n background-color: #c4c4c4; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div:first-child:hover {\n cursor: pointer;\n background-color: #3b5c7f; }\n .igv-generic-dialog-container .igv-generic-dialog-ok-cancel div:last-child:hover {\n cursor: pointer;\n background-color: #7f7f7f; }\n .igv-generic-dialog-container .igv-generic-dialog-ok {\n width: 100%;\n height: 36px;\n margin-top: 32px;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-around;\n align-items: center; }\n .igv-generic-dialog-container .igv-generic-dialog-ok div {\n width: 98px;\n height: 36px;\n line-height: 36px;\n text-align: center;\n color: white;\n font-family: \"Open Sans\", sans-serif;\n font-size: medium;\n font-weight: 400;\n border-color: white;\n border-style: solid;\n border-width: thin;\n border-radius: 4px;\n background-color: #2B81AF; }\n .igv-generic-dialog-container .igv-generic-dialog-ok div:hover {\n cursor: pointer;\n background-color: #25597f; }\n\n.igv-popover {\n position: absolute;\n top: 0;\n left: 0;\n min-width: 128px;\n z-index: 4096;\n font-family: \"Open Sans\", sans-serif;\n font-size: small;\n font-weight: 400;\n color: #4b4b4b;\n background-color: white;\n border-radius: 4px;\n border-color: #7F7F7F;\n border-style: solid;\n border-width: thin;\n display: none; }\n\n.igv-popover-header {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n justify-content: flex-end;\n align-items: center;\n width: 100%;\n height: 24px;\n cursor: move;\n border-top-left-radius: 4px;\n border-top-right-radius: 4px;\n border-bottom-color: #7F7F7F;\n border-bottom-style: solid;\n border-bottom-width: thin;\n background-color: #eee; }\n .igv-popover-header div {\n margin-right: 4px;\n height: 12px;\n width: 12px;\n color: #7F7F7F; }\n .igv-popover-header div:hover {\n cursor: pointer;\n color: #444; }\n\n.igv-popover-track-popup-content {\n position: relative;\n top: 0;\n left: 0;\n max-height: 384px;\n overflow-x: hidden;\n overflow-y: auto;\n background-color: white; }\n .igv-popover-track-popup-content div {\n margin-left: 4px;\n background-color: white; }\n .igv-popover-track-popup-content div:hover {\n cursor: pointer;\n background-color: #efefef; }\n\n.igv-popover-name-value {\n cursor: default;\n text-wrap: none;\n white-space: nowrap;\n max-width: 384px; }\n\n.igv-popover-name {\n font-weight: bold;\n padding-right: 4px;\n float: left; }\n\n.igv-popover-value {\n padding-left: 4px;\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n max-width: 256px;\n display: inline-block; }\n\n.igv-trackgear-container {\n position: relative;\n width: 20px;\n height: 20px;\n margin-left: 4px;\n color: #7F7F7F; }\n\n.igv-trackgear-container:hover {\n cursor: pointer;\n color: #444; }\n\n.igv-trackgear-popover {\n position: absolute;\n top: 0;\n left: 0;\n min-width: 132px;\n z-index: 4096;\n cursor: pointer;\n font-family: \"Open Sans\", sans-serif;\n font-size: small;\n font-weight: 400;\n color: #4b4b4b;\n background: white;\n border-radius: 4px;\n border-color: #7F7F7F;\n border-style: solid;\n border-width: thin;\n display: flex;\n flex-flow: column;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: flex-end;\n text-align: left; }\n .igv-trackgear-popover > div:not(:first-child) {\n width: 100%; }\n .igv-trackgear-popover > div:not(:first-child) > div {\n background: white; }\n .igv-trackgear-popover > div:not(:first-child) > div:last-child {\n border-bottom-left-radius: 4px;\n border-bottom-right-radius: 4px;\n border-bottom-color: transparent;\n border-bottom-style: solid;\n border-bottom-width: thin; }\n .igv-trackgear-popover > div:not(:first-child) > div:hover {\n background: #efefef; }\n\n.igv-trackgear-popover-shim {\n padding-left: 8px;\n padding-right: 8px; }\n\n.igv-trackgear-popover-header {\n position: relative;\n width: 100%;\n height: 24px;\n cursor: move;\n border-top-color: transparent;\n border-top-left-radius: 4px;\n border-top-right-radius: 4px;\n border-bottom-color: #7F7F7F;\n border-bottom-style: solid;\n border-bottom-width: thin;\n background-color: #eee;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center; }\n .igv-trackgear-popover-header div {\n margin-right: 4px;\n height: 12px;\n width: 12px;\n color: #7F7F7F; }\n .igv-trackgear-popover-header div:hover {\n cursor: pointer;\n color: #444; }\n\n.igv-trackgear-popover-check-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center;\n width: 100%;\n height: 20px;\n background-color: transparent; }\n .igv-trackgear-popover-check-container div {\n padding-top: 2px;\n padding-left: 8px; }\n .igv-trackgear-popover-check-container div:first-child {\n position: relative;\n width: 12px;\n height: 12px; }\n .igv-trackgear-popover-check-container div:first-child svg {\n position: absolute;\n width: 12px;\n height: 12px; }\n\n.igvControlDiv {\n position: relative; }\n\n.igv-content-header {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center;\n margin-top: 10px;\n height: 16px;\n width: 100%; }\n .igv-content-header .igv-ideogram-shim {\n height: 100%;\n width: 50px;\n background-color: white; }\n .igv-content-header .igv-ideogram-content {\n height: 100%;\n background-color: white; }\n .igv-content-header .igv-ideogram-content-border-right {\n border-right-color: #292929;\n border-right-style: solid;\n border-right-width: 1px; }\n\n.igv-multi-locus-panel-border {\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 1px;\n background-color: green;\n border-right-color: #ff0000;\n border-right-style: solid;\n border-right-width: 1px; }\n\n.igv-navbar {\n position: relative;\n padding-left: 8px;\n padding-right: 8px;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n color: #444;\n font-size: 12px;\n font-family: \"Open Sans\", sans-serif;\n font-weight: 400;\n line-height: 32px;\n margin-top: 2px;\n margin-bottom: 4px;\n height: 32px;\n border-style: solid;\n border-radius: 3px;\n border-width: thin;\n border-color: #bfbfbf;\n background-color: #f3f3f3; }\n\n.igv-nav-bar-left-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n height: 32px;\n line-height: 32px; }\n .igv-nav-bar-left-container .igv-logo {\n width: 34px;\n height: 32px;\n margin-top: 6px;\n margin-right: 8px; }\n .igv-nav-bar-left-container .igv-current-genome {\n height: 32px;\n width: 40px;\n margin-left: 4px;\n margin-right: 4px;\n user-select: none;\n line-height: 32px;\n vertical-align: middle;\n text-align: center; }\n\n.igv-nav-bar-genomic-location {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n height: 100%; }\n\n.igv-chromosome-select-widget-container {\n height: 100%;\n width: 125px;\n margin-right: 4px;\n display: flex;\n flex-flow: column;\n flex-wrap: nowrap;\n justify-content: space-around;\n align-items: center; }\n .igv-chromosome-select-widget-container select {\n display: block;\n cursor: pointer;\n width: 100px;\n height: 75%;\n outline: none;\n font-size: 12px;\n font-family: \"Open Sans\", sans-serif;\n font-weight: 400; }\n\n.igv-locus-size-group {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n margin-left: 8px;\n height: calc(32px - 10px); }\n .igv-locus-size-group .igv-search-container {\n width: 200px;\n height: calc(32px - 10px);\n line-height: calc(32px - 10px);\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-start;\n align-items: center; }\n .igv-locus-size-group .igv-search-container input {\n cursor: text;\n width: 85%;\n height: calc(32px - 10px);\n line-height: calc(32px - 10px);\n font-size: 12px;\n font-family: \"Open Sans\", sans-serif;\n font-weight: 400;\n text-align: left;\n padding-left: 8px;\n margin-right: 8px;\n outline: none;\n border-style: solid;\n border-radius: 3px;\n border-width: thin;\n border-color: #bfbfbf;\n background-color: white; }\n .igv-locus-size-group .igv-search-container div {\n cursor: pointer;\n height: 16px;\n width: 16px; }\n .igv-locus-size-group .igv-windowsizepanel-content-div {\n margin-left: 4px;\n user-select: none; }\n\n.igv-nav-bar-right-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n height: 32px;\n line-height: 32px; }\n .igv-nav-bar-right-container .igv-nav-bar-toggle-button-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n align-items: center;\n height: 100%; }\n .igv-nav-bar-right-container .igv-nav-bar-toggle-button-container div {\n margin-left: 0;\n margin-right: 4px; }\n .igv-nav-bar-right-container .igv-nav-bar-toggle-button-container div:last-child {\n margin-left: 0;\n margin-right: 0; }\n .igv-nav-bar-right-container .igv-nav-bar-toggle-button-container-750 {\n display: none; }\n .igv-nav-bar-right-container .igv-zoom-widget {\n color: #737373;\n font-size: 18px;\n height: 32px;\n line-height: 32px;\n margin-left: 8px;\n user-select: none;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center; }\n .igv-nav-bar-right-container .igv-zoom-widget div {\n cursor: pointer;\n margin-left: unset;\n margin-right: unset; }\n .igv-nav-bar-right-container .igv-zoom-widget div:first-child {\n height: 24px;\n width: 24px;\n margin-left: unset;\n margin-right: 8px; }\n .igv-nav-bar-right-container .igv-zoom-widget div:last-child {\n height: 24px;\n width: 24px;\n margin-left: 8px;\n margin-right: unset; }\n .igv-nav-bar-right-container .igv-zoom-widget div:nth-child(even) {\n display: block;\n height: fit-content; }\n .igv-nav-bar-right-container .igv-zoom-widget input {\n display: block;\n width: 125px; }\n .igv-nav-bar-right-container .igv-zoom-widget svg {\n display: block; }\n .igv-nav-bar-right-container .igv-zoom-widget-900 {\n color: #737373;\n font-size: 18px;\n height: 32px;\n line-height: 32px;\n margin-left: 8px;\n user-select: none;\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: flex-end;\n align-items: center; }\n .igv-nav-bar-right-container .igv-zoom-widget-900 div {\n cursor: pointer;\n margin-left: unset;\n margin-right: unset; }\n .igv-nav-bar-right-container .igv-zoom-widget-900 div:first-child {\n height: 24px;\n width: 24px;\n margin-left: unset;\n margin-right: 8px; }\n .igv-nav-bar-right-container .igv-zoom-widget-900 div:last-child {\n height: 24px;\n width: 24px;\n margin-left: 8px;\n margin-right: unset; }\n .igv-nav-bar-right-container .igv-zoom-widget-900 div:nth-child(even) {\n width: 0;\n height: 0;\n display: none; }\n .igv-nav-bar-right-container .igv-zoom-widget-900 input {\n width: 0;\n height: 0;\n display: none; }\n .igv-nav-bar-right-container .igv-zoom-widget-900 svg {\n display: block; }\n .igv-nav-bar-right-container .igv-zoom-widget-hidden {\n display: none; }\n\n.igv-nav-bar-button {\n box-sizing: unset;\n padding-left: 6px;\n padding-right: 6px;\n height: 18px;\n text-transform: capitalize;\n user-select: none;\n line-height: 18px;\n text-align: center;\n vertical-align: middle;\n font-family: \"Open Sans\", sans-serif;\n font-size: 11px;\n font-weight: 200;\n color: #737373;\n background-color: #f3f3f3;\n border-color: #737373;\n border-style: solid;\n border-width: thin;\n border-radius: 6px; }\n\n.igv-nav-bar-button-clicked {\n color: white;\n background-color: #737373; }\n\n.igv-nav-bar-button:hover {\n cursor: pointer; }\n\n.igv-logo-nonav {\n margin-left: 4px;\n margin-top: 12px;\n position: absolute;\n top: 0;\n left: 0;\n width: 34px;\n height: 16px; }\n\n.igv-search-results {\n position: absolute;\n top: 32px;\n left: 2px;\n height: 320px;\n width: 213px;\n background-color: white;\n border-color: #7F7F7F;\n border-style: solid;\n border-width: thin;\n overflow-x: hidden;\n overflow-y: auto;\n z-index: 9999; }\n .igv-search-results tr {\n font-family: \"Open Sans\", sans-serif;\n font-size: small;\n font-weight: 400;\n color: #444; }\n .igv-search-results tr:hover,\n .igv-search-results tr:focus,\n .igv-search-results tr:active {\n cursor: pointer;\n font-weight: 700;\n color: #141414; }\n\n.igv-root-div {\n position: relative;\n left: 0;\n right: 0;\n height: auto;\n margin-left: 10px;\n margin-right: 10px;\n padding-top: 4px; }\n\n.igv-content-div {\n position: relative;\n width: 100%;\n height: 100%; }\n\n.igv-track-container-div {\n user-select: none;\n position: relative;\n clear: both; }\n\n.igv-track-div {\n position: relative;\n width: 100%;\n margin-top: 5px;\n margin-bottom: 5px; }\n\n.igv-viewport-container {\n position: absolute;\n left: 50px;\n right: 50px;\n height: 100%;\n white-space: nowrap;\n overflow-x: hidden;\n overflow-y: hidden; }\n\n.igv-viewport-div {\n position: relative;\n display: inline-block;\n height: 100%;\n overflow-x: hidden;\n overflow-y: hidden; }\n\n.igv-viewport-content-div {\n position: absolute;\n width: 100%; }\n\n.igv-viewport-message {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n color: rgba(0, 0, 0, 0.15);\n font-family: \"Open Sans\", sans-serif;\n font-size: 25px;\n font-weight: bold;\n user-select: none; }\n\n.igv-whole-genome-container {\n display: flex;\n flex-flow: row;\n flex-wrap: nowrap;\n justify-content: space-between;\n width: 100%;\n height: 100%;\n background-color: white; }\n .igv-whole-genome-container div {\n font-family: \"Open Sans\", sans-serif;\n font-size: 10px;\n font-weight: 400;\n color: #444;\n height: 100%;\n text-align: center;\n border-right-color: #bfbfbf;\n border-right-style: solid;\n border-right-width: thin; }\n .igv-whole-genome-container div span {\n display: block;\n padding-top: 6px;\n text-overflow: ellipsis; }\n .igv-whole-genome-container div:last-child {\n border-right-color: transparent; }\n .igv-whole-genome-container div:hover,\n .igv-whole-genome-container div:focus,\n .igv-whole-genome-container div:active {\n cursor: pointer;\n background-color: #efefef; }\n\n.igv-viewport-div-border-right {\n border-right-color: #292929;\n border-right-style: solid;\n border-right-width: 1px; }\n\n.igv-multi-locus-panel-close-container {\n position: absolute;\n top: 4px;\n right: 4px;\n width: 16px;\n height: 16px;\n color: #666666;\n z-index: 1000; }\n\n.igv-multi-locus-panel-close-container:hover {\n cursor: pointer;\n color: #434343; }\n\n.igv-multi-locus-panel-label-div {\n position: absolute;\n left: 50%;\n top: 25%;\n transform: translate(-50%, -25%);\n font-family: \"Open Sans\", sans-serif;\n font-size: 12px;\n font-weight: 400;\n text-align: center;\n min-width: 16px;\n z-index: 64;\n color: #373737;\n background-color: white;\n padding: 1px; }\n\n.igv-multi-locus-panel-label-div:hover {\n cursor: pointer; }\n\n.igv-viewport-ruler {\n cursor: pointer;\n font-family: \"Open Sans\", sans-serif;\n font-size: 10px;\n font-weight: 200;\n text-align: center; }\n .igv-viewport-ruler > div {\n height: 100%; }\n\n.igv-viewport-sequence {\n font-family: \"Open Sans\", sans-serif;\n font-size: 8px;\n font-weight: 200;\n text-align: center; }\n\n.igv-viewport-spinner {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n z-index: 1024;\n width: 24px;\n height: 24px;\n pointer-events: none;\n color: #737373; }\n\n.igv-ruler-sweeper-div {\n display: none;\n pointer-events: none;\n position: absolute;\n top: 0;\n left: 0;\n width: 0;\n height: 100%;\n z-index: 99999;\n background-color: rgba(68, 134, 247, 0.25); }\n\n.igv-right-hand-gutter {\n position: absolute;\n right: 0;\n width: 36px;\n height: 100%;\n background: white; }\n\n.igv-left-hand-gutter {\n position: absolute;\n left: 0;\n width: 50px;\n height: 100%; }\n .igv-left-hand-gutter canvas {\n position: absolute; }\n\n.igv-track-menu-border-top {\n border-top-color: #a2a2a2;\n border-top-style: solid;\n border-top-width: thin; }\n\n.igv-track-menu-category {\n padding-left: 4px;\n font-weight: 400; }\n\n.igv-track-drag-scrim {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 256;\n background-color: rgba(68, 134, 247, 0.25); }\n\n.igv-track-manipulation-handle {\n cursor: pointer;\n position: absolute;\n right: 36px;\n width: 12px;\n margin-left: 2px;\n height: 100%;\n box-sizing: border-box;\n font-size: medium;\n border-color: #c4c4c4;\n border-style: solid;\n border-width: thin;\n border-top-right-radius: 6px;\n border-bottom-right-radius: 6px;\n z-index: 512;\n background-color: #c4c4c4; }\n\n.igv-track-manipulation-handle:hover,\n.igv-track-manipulation-handle:focus,\n.igv-track-manipulation-handle:active {\n border-color: #7e7e7e;\n background-color: #7e7e7e; }\n\n.igv-track-label {\n position: absolute;\n left: 8px;\n top: 4px;\n width: auto;\n height: auto;\n max-width: 200px;\n padding-left: 4px;\n padding-right: 4px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n font-family: \"Open Sans\", sans-serif;\n font-size: small;\n font-weight: 400;\n text-align: center;\n user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n border-color: #444;\n border-radius: 2px;\n border-style: solid;\n border-width: thin;\n background-color: white;\n z-index: 128;\n cursor: pointer; }\n\n.igv-track-label:hover,\n.igv-track-label:focus,\n.igv-track-label:active {\n background-color: rgba(0, 0, 0, 0.05); }\n\n.igv-scrollbar-outer-div {\n position: absolute;\n top: 0;\n right: 0;\n width: 14px;\n height: 100%;\n background-color: white; }\n .igv-scrollbar-outer-div div {\n position: absolute;\n top: 0;\n left: 3px;\n width: 8px;\n border-style: solid;\n border-width: thin;\n border-color: #c4c4c4;\n border-top-left-radius: 4px;\n border-top-right-radius: 4px;\n border-bottom-left-radius: 4px;\n border-bottom-right-radius: 4px;\n background-color: white; }\n .igv-scrollbar-outer-div div:hover,\n .igv-scrollbar-outer-div div:focus,\n .igv-scrollbar-outer-div div:active {\n cursor: pointer;\n background-color: #c4c4c4; }\n\n.zoom-in-notice-container {\n position: absolute;\n top: 10px;\n left: 50%; }\n .zoom-in-notice-container div {\n position: relative;\n left: -50%;\n font-family: \"Open Sans\", sans-serif;\n font-size: medium;\n font-weight: 400;\n color: #3f3f3f;\n background-color: rgba(255, 255, 255, 0.51);\n z-index: 64; }\n\n.igv-center-guide {\n pointer-events: none;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 50%;\n width: 8px;\n z-index: 8;\n display: none;\n user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n border-left-style: dashed;\n border-left-width: thin;\n border-right-style: dashed;\n border-right-width: thin; }\n\n.igv-center-guide-wide {\n background-color: rgba(0, 0, 0, 0);\n border-left-color: rgba(127, 127, 127, 0.51);\n border-right-color: rgba(127, 127, 127, 0.51); }\n\n.igv-center-guide-thin {\n left: 50%;\n width: 1px;\n background-color: rgba(0, 0, 0, 0);\n border-left-color: rgba(127, 127, 127, 0.51);\n border-right-color: rgba(0, 0, 0, 0);\n /*background-color: rgba(127, 127, 127, 0.51);*/\n /*border-left-color: rgba(0,0,0,0);*/\n /*border-right-color: rgba(0,0,0,0);*/ }\n\n.igv-cursor-tracking-guide {\n pointer-events: none;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 50%;\n width: 1px;\n z-index: 1;\n border-left-style: dotted;\n border-left-width: thin;\n border-left-color: rgba(127, 127, 127, 0.76);\n display: none;\n user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none; }\n\n.igv-clickable {\n cursor: pointer;\n background-color: white; }\n\n#color-by-tag {\n color: #444; }\n\n#color-by-tag:hover,\n#color-by-tag:focus,\n#color-by-tag:active {\n cursor: pointer;\n padding-left: 2px;\n padding-right: 2px;\n color: white;\n border-color: #444;\n border-radius: 2px;\n border-style: solid;\n border-width: thin;\n background-color: #7f7f7f; }\n\n.igv-ellipsis {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis; }\n\n.igv-spinner-container {\n color: #3f3f3f;\n width: 100%;\n height: 100%;\n text-align: center;\n padding-top: 8px;\n font-size: 24px;\n z-index: 512; }\n\n.igv-fa-check-visible {\n color: inherit;\n padding-right: 2px; }\n\n.igv-fa-check-hidden {\n color: transparent;\n padding-right: 2px; }\n\n.validateTips {\n border: 1px solid transparent;\n padding: 0.3em; }\n .validateTips fieldset {\n border: 0; }\n\n.igv-spacer-10 {\n height: 10px;\n width: 100%;\n font-size: 0;\n margin: 0;\n padding: 0;\n border: 0;\n display: block; }\n\n/*# sourceMappingURL=igv.css.map */\n\n/*!\n * Font Awesome Free 5.0.8 by @fontawesome - https://fontawesome.com\n * License - https://fontawesome.com/license (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)\n */\nsvg:not(:root).svg-inline--fa5 {\n overflow: visible;\n }\n\n.svg-inline--fa5 {\n display: inline-block;\n font-size: inherit;\n height: 1em;\n overflow: visible;\n vertical-align: -.125em; }\n .svg-inline--fa5.fa5-lg {\n vertical-align: -.225em; }\n .svg-inline--fa5.fa5-w-1 {\n width: 0.0625em; }\n .svg-inline--fa5.fa5-w-2 {\n width: 0.125em; }\n .svg-inline--fa5.fa5-w-3 {\n width: 0.1875em; }\n .svg-inline--fa5.fa5-w-4 {\n width: 0.25em; }\n .svg-inline--fa5.fa5-w-5 {\n width: 0.3125em; }\n .svg-inline--fa5.fa5-w-6 {\n width: 0.375em; }\n .svg-inline--fa5.fa5-w-7 {\n width: 0.4375em; }\n .svg-inline--fa5.fa5-w-8 {\n width: 0.5em; }\n .svg-inline--fa5.fa5-w-9 {\n width: 0.5625em; }\n .svg-inline--fa5.fa5-w-10 {\n width: 0.625em; }\n .svg-inline--fa5.fa5-w-11 {\n width: 0.6875em; }\n .svg-inline--fa5.fa5-w-12 {\n width: 0.75em; }\n .svg-inline--fa5.fa5-w-13 {\n width: 0.8125em; }\n .svg-inline--fa5.fa5-w-14 {\n width: 0.875em; }\n .svg-inline--fa5.fa5-w-15 {\n width: 0.9375em; }\n .svg-inline--fa5.fa5-w-16 {\n /* width: 1em; */\n }\n .svg-inline--fa5.fa5-w-17 {\n width: 1.0625em; }\n .svg-inline--fa5.fa5-w-18 {\n width: 1.125em; }\n .svg-inline--fa5.fa5-w-19 {\n width: 1.1875em; }\n .svg-inline--fa5.fa5-w-20 {\n width: 1.25em; }\n .svg-inline--fa5.fa5-pull-left {\n margin-right: .3em;\n width: auto; }\n .svg-inline--fa5.fa5-pull-right {\n margin-left: .3em;\n width: auto; }\n .svg-inline--fa5.fa5-border {\n height: 1.5em; }\n .svg-inline--fa5.fa5-li {\n width: 2em; }\n .svg-inline--fa5.fa5-fw {\n width: 1.25em; }\n\n.fa5-layers svg.svg-inline--fa5 {\n bottom: 0;\n left: 0;\n margin: auto;\n position: absolute;\n right: 0;\n top: 0; }\n\n.fa5-layers {\n display: inline-block;\n height: 1em;\n position: relative;\n text-align: center;\n vertical-align: -.125em;\n width: 1em; }\n .fa5-layers svg.svg-inline--fa5 {\n -webkit-transform-origin: center center;\n transform-origin: center center; }\n\n.fa5-layers-text, .fa5-layers-counter {\n display: inline-block;\n position: absolute;\n text-align: center; }\n\n.fa5-layers-text {\n left: 50%;\n top: 50%;\n -webkit-transform: translate(-50%, -50%);\n transform: translate(-50%, -50%);\n -webkit-transform-origin: center center;\n transform-origin: center center; }\n\n.fa5-layers-counter {\n background-color: #ff253a;\n border-radius: 1em;\n color: #fff;\n height: 1.5em;\n line-height: 1;\n max-width: 5em;\n min-width: 1.5em;\n overflow: hidden;\n padding: .25em;\n right: 0;\n text-overflow: ellipsis;\n top: 0;\n -webkit-transform: scale(0.25);\n transform: scale(0.25);\n -webkit-transform-origin: top right;\n transform-origin: top right; }\n\n.fa5-layers-bottom-right {\n bottom: 0;\n right: 0;\n top: auto;\n -webkit-transform: scale(0.25);\n transform: scale(0.25);\n -webkit-transform-origin: bottom right;\n transform-origin: bottom right; }\n\n.fa5-layers-bottom-left {\n bottom: 0;\n left: 0;\n right: auto;\n top: auto;\n -webkit-transform: scale(0.25);\n transform: scale(0.25);\n -webkit-transform-origin: bottom left;\n transform-origin: bottom left; }\n\n.fa5-layers-top-right {\n right: 0;\n top: 0;\n -webkit-transform: scale(0.25);\n transform: scale(0.25);\n -webkit-transform-origin: top right;\n transform-origin: top right; }\n\n.fa5-layers-top-left {\n left: 0;\n right: auto;\n top: 0;\n -webkit-transform: scale(0.25);\n transform: scale(0.25);\n -webkit-transform-origin: top left;\n transform-origin: top left; }\n\n.fa5-lg {\n font-size: 1.33333em;\n line-height: 0.75em;\n vertical-align: -.0667em; }\n\n.fa5-xs {\n font-size: .75em; }\n\n.fa5-sm {\n font-size: .875em; }\n\n.fa5-1x {\n font-size: 1em; }\n\n.fa5-2x {\n font-size: 2em; }\n\n.fa5-3x {\n font-size: 3em; }\n\n.fa5-4x {\n font-size: 4em; }\n\n.fa5-5x {\n font-size: 5em; }\n\n.fa5-6x {\n font-size: 6em; }\n\n.fa5-7x {\n font-size: 7em; }\n\n.fa5-8x {\n font-size: 8em; }\n\n.fa5-9x {\n font-size: 9em; }\n\n.fa5-10x {\n font-size: 10em; }\n\n.fa5-fw {\n text-align: center;\n width: 1.25em; }\n\n.fa5-ul {\n list-style-type: none;\n margin-left: 2.5em;\n padding-left: 0; }\n .fa5-ul > li {\n position: relative; }\n\n.fa5-li {\n left: -2em;\n position: absolute;\n text-align: center;\n width: 2em;\n line-height: inherit; }\n\n.fa5-border {\n border: solid 0.08em #eee;\n border-radius: .1em;\n padding: .2em .25em .15em; }\n\n.fa5-pull-left {\n float: left; }\n\n.fa5-pull-right {\n float: right; }\n\n.fa5.fa5-pull-left,\n.fas.fa5-pull-left,\n.far.fa5-pull-left,\n.fal.fa5-pull-left,\n.fab.fa5-pull-left {\n margin-right: .3em; }\n\n.fa5.fa5-pull-right,\n.fas.fa5-pull-right,\n.far.fa5-pull-right,\n.fal.fa5-pull-right,\n.fab.fa5-pull-right {\n margin-left: .3em; }\n\n.fa5-spin {\n -webkit-animation: fa5-spin 2s infinite linear;\n animation: fa5-spin 2s infinite linear; }\n\n.fa5-pulse {\n -webkit-animation: fa5-spin 1s infinite steps(8);\n animation: fa5-spin 1s infinite steps(8); }\n\n@-webkit-keyframes fa5-spin {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg); }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg); } }\n\n@keyframes fa5-spin {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg); }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg); } }\n\n.fa5-rotate-90 {\n -ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=1)\";\n -webkit-transform: rotate(90deg);\n transform: rotate(90deg); }\n\n.fa5-rotate-180 {\n -ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=2)\";\n -webkit-transform: rotate(180deg);\n transform: rotate(180deg); }\n\n.fa5-rotate-270 {\n -ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=3)\";\n -webkit-transform: rotate(270deg);\n transform: rotate(270deg); }\n\n.fa5-flip-horizontal {\n -ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1)\";\n -webkit-transform: scale(-1, 1);\n transform: scale(-1, 1); }\n\n.fa5-flip-vertical {\n -ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1)\";\n -webkit-transform: scale(1, -1);\n transform: scale(1, -1); }\n\n.fa5-flip-horizontal.fa5-flip-vertical {\n -ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1)\";\n -webkit-transform: scale(-1, -1);\n transform: scale(-1, -1); }\n\n:root .fa5-rotate-90,\n:root .fa5-rotate-180,\n:root .fa5-rotate-270,\n:root .fa5-flip-horizontal,\n:root .fa5-flip-vertical {\n -webkit-filter: none;\n filter: none; }\n\n.fa5-stack {\n display: inline-block;\n height: 2em;\n position: relative;\n width: 2em; }\n\n.fa5-stack-1x,\n.fa5-stack-2x {\n bottom: 0;\n left: 0;\n margin: auto;\n position: absolute;\n right: 0;\n top: 0; }\n\n.svg-inline--fa5.fa5-stack-1x {\n height: 1em;\n width: 1em; }\n\n.svg-inline--fa5.fa5-stack-2x {\n height: 2em;\n width: 2em; }\n\n.fa5-inverse {\n color: #fff; }\n\n.sr-only {\n border: 0;\n clip: rect(0, 0, 0, 0);\n height: 1px;\n margin: -1px;\n overflow: hidden;\n padding: 0;\n position: absolute;\n width: 1px; }\n\n.sr-only-focusable:active, .sr-only-focusable:focus {\n clip: auto;\n height: auto;\n margin: 0;\n overflow: visible;\n position: static;\n width: auto; }\n'; - - var style = document.createElement('style'); - style.setAttribute('type', 'text/css'); - style.innerHTML = css; - - document.head.insertBefore(style, document.head.childNodes[ document.head.childNodes.length - 1 ]); - -})(); - -/*! - * jQuery JavaScript Library v3.3.1 -ajax,-ajax/jsonp,-ajax/load,-ajax/parseXML,-ajax/script,-ajax/var/location,-ajax/var/nonce,-ajax/var/rquery,-ajax/xhr,-manipulation/_evalUrl,-event/ajax,-effects,-effects/Tween,-effects/animatedSelector - * https://jquery.com/ - * - * Includes Sizzle.js - * https://sizzlejs.com/ - * - * Copyright JS Foundation and other contributors - * Released under the MIT license - * https://jquery.org/license - * - * Date: 2018-01-20T17:24Z - */ -// Modified for encapsulation in igv module -// * no exports -// * no global definition -// * noConflict not supported (as _ is encapsulated its not needed) - -var $, jQuery; - -(function (global, factory) { - - - $ = factory(global); - jQuery = $; - - -// Pass this if window is not defined yet -}(typeof window !== "undefined" ? window : this, function (window) { - -// Edge <= 12 - 13+, Firefox <=18 - 45+, IE 10 - 11, Safari 5.1 - 9+, iOS 6 - 9.1 -// throw exceptions when non-strict code (e.g., ASP.NET 4.5) accesses strict mode -// arguments.callee.caller (trac-13335). But as of jQuery 3.0 (2016), strict mode should be common -// enough that all such attempts are guarded in a try block. -"use strict"; - -var arr = []; - -var document = window.document; - -var getProto = Object.getPrototypeOf; - -var slice = arr.slice; - -var concat = arr.concat; - -var push = arr.push; - -var indexOf = arr.indexOf; - -var class2type = {}; - -var toString = class2type.toString; - -var hasOwn = class2type.hasOwnProperty; - -var fnToString = hasOwn.toString; - -var ObjectFunctionString = fnToString.call( Object ); - -var support = {}; - -var isFunction = function isFunction( obj ) { - - // Support: Chrome <=57, Firefox <=52 - // In some browsers, typeof returns "function" for HTML elements - // (i.e., `typeof document.createElement( "object" ) === "function"`). - // We don't want to classify *any* DOM node as a function. - return typeof obj === "function" && typeof obj.nodeType !== "number"; - }; - - -var isWindow = function isWindow( obj ) { - return obj != null && obj === obj.window; - }; - - - - - var preservedScriptAttributes = { - type: true, - src: true, - noModule: true - }; - - function DOMEval( code, doc, node ) { - doc = doc || document; - - var i, - script = doc.createElement( "script" ); - - script.text = code; - if ( node ) { - for ( i in preservedScriptAttributes ) { - if ( node[ i ] ) { - script[ i ] = node[ i ]; - } - } - } - doc.head.appendChild( script ).parentNode.removeChild( script ); - } - - -function toType( obj ) { - if ( obj == null ) { - return obj + ""; - } - - // Support: Android <=2.3 only (functionish RegExp) - return typeof obj === "object" || typeof obj === "function" ? - class2type[ toString.call( obj ) ] || "object" : - typeof obj; -} -/* global Symbol */ -// Defining this global in .eslintrc.json would create a danger of using the global -// unguarded in another place, it seems safer to define global only for this module - - - -var - version = "3.3.1 -ajax,-ajax/jsonp,-ajax/load,-ajax/parseXML,-ajax/script,-ajax/var/location,-ajax/var/nonce,-ajax/var/rquery,-ajax/xhr,-manipulation/_evalUrl,-event/ajax,-effects,-effects/Tween,-effects/animatedSelector", - - // Define a local copy of jQuery - jQuery = function( selector, context ) { - - // The jQuery object is actually just the init constructor 'enhanced' - // Need init if jQuery is called (just allow error to be thrown if not included) - return new jQuery.fn.init( selector, context ); - }, - - // Support: Android <=4.0 only - // Make sure we trim BOM and NBSP - rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g; - -jQuery.fn = jQuery.prototype = { - - // The current version of jQuery being used - jquery: version, - - constructor: jQuery, - - // The default length of a jQuery object is 0 - length: 0, - - toArray: function() { - return slice.call( this ); - }, - - // Get the Nth element in the matched element set OR - // Get the whole matched element set as a clean array - get: function( num ) { - - // Return all the elements in a clean array - if ( num == null ) { - return slice.call( this ); - } - - // Return just the one element from the set - return num < 0 ? this[ num + this.length ] : this[ num ]; - }, - - // Take an array of elements and push it onto the stack - // (returning the new matched element set) - pushStack: function( elems ) { - - // Build a new jQuery matched element set - var ret = jQuery.merge( this.constructor(), elems ); - - // Add the old object onto the stack (as a reference) - ret.prevObject = this; - - // Return the newly-formed element set - return ret; - }, - - // Execute a callback for every element in the matched set. - each: function( callback ) { - return jQuery.each( this, callback ); - }, - - map: function( callback ) { - return this.pushStack( jQuery.map( this, function( elem, i ) { - return callback.call( elem, i, elem ); - } ) ); - }, - - slice: function() { - return this.pushStack( slice.apply( this, arguments ) ); - }, - - first: function() { - return this.eq( 0 ); - }, - - last: function() { - return this.eq( -1 ); - }, - - eq: function( i ) { - var len = this.length, - j = +i + ( i < 0 ? len : 0 ); - return this.pushStack( j >= 0 && j < len ? [ this[ j ] ] : [] ); - }, - - end: function() { - return this.prevObject || this.constructor(); - }, - - // For internal use only. - // Behaves like an Array's method, not like a jQuery method. - push: push, - sort: arr.sort, - splice: arr.splice -}; - -jQuery.extend = jQuery.fn.extend = function() { - var options, name, src, copy, copyIsArray, clone, - target = arguments[ 0 ] || {}, - i = 1, - length = arguments.length, - deep = false; - - // Handle a deep copy situation - if ( typeof target === "boolean" ) { - deep = target; - - // Skip the boolean and the target - target = arguments[ i ] || {}; - i++; - } - - // Handle case when target is a string or something (possible in deep copy) - if ( typeof target !== "object" && !isFunction( target ) ) { - target = {}; - } - - // Extend jQuery itself if only one argument is passed - if ( i === length ) { - target = this; - i--; - } - - for ( ; i < length; i++ ) { - - // Only deal with non-null/undefined values - if ( ( options = arguments[ i ] ) != null ) { - - // Extend the base object - for ( name in options ) { - src = target[ name ]; - copy = options[ name ]; - - // Prevent never-ending loop - if ( target === copy ) { - continue; - } - - // Recurse if we're merging plain objects or arrays - if ( deep && copy && ( jQuery.isPlainObject( copy ) || - ( copyIsArray = Array.isArray( copy ) ) ) ) { - - if ( copyIsArray ) { - copyIsArray = false; - clone = src && Array.isArray( src ) ? src : []; - - } else { - clone = src && jQuery.isPlainObject( src ) ? src : {}; - } - - // Never move original objects, clone them - target[ name ] = jQuery.extend( deep, clone, copy ); - - // Don't bring in undefined values - } else if ( copy !== undefined ) { - target[ name ] = copy; - } - } - } - } - - // Return the modified object - return target; -}; - -jQuery.extend( { - - // Unique for each copy of jQuery on the page - expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ), - - // Assume jQuery is ready without the ready module - isReady: true, - - error: function( msg ) { - throw new Error( msg ); - }, - - noop: function() {}, - - isPlainObject: function( obj ) { - var proto, Ctor; - - // Detect obvious negatives - // Use toString instead of jQuery.type to catch host objects - if ( !obj || toString.call( obj ) !== "[object Object]" ) { - return false; - } - - proto = getProto( obj ); - - // Objects with no prototype (e.g., `Object.create( null )`) are plain - if ( !proto ) { - return true; - } - - // Objects with prototype are plain iff they were constructed by a global Object function - Ctor = hasOwn.call( proto, "constructor" ) && proto.constructor; - return typeof Ctor === "function" && fnToString.call( Ctor ) === ObjectFunctionString; - }, - - isEmptyObject: function( obj ) { - - /* eslint-disable no-unused-vars */ - // See https://github.com/eslint/eslint/issues/6125 - var name; - - for ( name in obj ) { - return false; - } - return true; - }, - - // Evaluates a script in a global context - globalEval: function( code ) { - DOMEval( code ); - }, - - each: function( obj, callback ) { - var length, i = 0; - - if ( isArrayLike( obj ) ) { - length = obj.length; - for ( ; i < length; i++ ) { - if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) { - break; - } - } - } else { - for ( i in obj ) { - if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) { - break; - } - } - } - - return obj; - }, - - // Support: Android <=4.0 only - trim: function( text ) { - return text == null ? - "" : - ( text + "" ).replace( rtrim, "" ); - }, - - // results is for internal usage only - makeArray: function( arr, results ) { - var ret = results || []; - - if ( arr != null ) { - if ( isArrayLike( Object( arr ) ) ) { - jQuery.merge( ret, - typeof arr === "string" ? - [ arr ] : arr - ); - } else { - push.call( ret, arr ); - } - } - - return ret; - }, - - inArray: function( elem, arr, i ) { - return arr == null ? -1 : indexOf.call( arr, elem, i ); - }, - - // Support: Android <=4.0 only, PhantomJS 1 only - // push.apply(_, arraylike) throws on ancient WebKit - merge: function( first, second ) { - var len = +second.length, - j = 0, - i = first.length; - - for ( ; j < len; j++ ) { - first[ i++ ] = second[ j ]; - } - - first.length = i; - - return first; - }, - - grep: function( elems, callback, invert ) { - var callbackInverse, - matches = [], - i = 0, - length = elems.length, - callbackExpect = !invert; - - // Go through the array, only saving the items - // that pass the validator function - for ( ; i < length; i++ ) { - callbackInverse = !callback( elems[ i ], i ); - if ( callbackInverse !== callbackExpect ) { - matches.push( elems[ i ] ); - } - } - - return matches; - }, - - // arg is for internal usage only - map: function( elems, callback, arg ) { - var length, value, - i = 0, - ret = []; - - // Go through the array, translating each of the items to their new values - if ( isArrayLike( elems ) ) { - length = elems.length; - for ( ; i < length; i++ ) { - value = callback( elems[ i ], i, arg ); - - if ( value != null ) { - ret.push( value ); - } - } - - // Go through every key on the object, - } else { - for ( i in elems ) { - value = callback( elems[ i ], i, arg ); - - if ( value != null ) { - ret.push( value ); - } - } - } - - // Flatten any nested arrays - return concat.apply( [], ret ); - }, - - // A global GUID counter for objects - guid: 1, - - // jQuery.support is not used in Core but other projects attach their - // properties to it so it needs to exist. - support: support -} ); - -if ( typeof Symbol === "function" ) { - jQuery.fn[ Symbol.iterator ] = arr[ Symbol.iterator ]; -} - -// Populate the class2type map -jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ), -function( i, name ) { - class2type[ "[object " + name + "]" ] = name.toLowerCase(); -} ); - -function isArrayLike( obj ) { - - // Support: real iOS 8.2 only (not reproducible in simulator) - // `in` check used to prevent JIT error (gh-2145) - // hasOwn isn't used here due to false negatives - // regarding Nodelist length in IE - var length = !!obj && "length" in obj && obj.length, - type = toType( obj ); - - if ( isFunction( obj ) || isWindow( obj ) ) { - return false; - } - - return type === "array" || length === 0 || - typeof length === "number" && length > 0 && ( length - 1 ) in obj; -} -var Sizzle = -/*! - * Sizzle CSS Selector Engine v2.3.3 - * https://sizzlejs.com/ - * - * Copyright jQuery Foundation and other contributors - * Released under the MIT license - * http://jquery.org/license - * - * Date: 2016-08-08 - */ -(function( window ) { - -var i, - support, - Expr, - getText, - isXML, - tokenize, - compile, - select, - outermostContext, - sortInput, - hasDuplicate, - - // Local document vars - setDocument, - document, - docElem, - documentIsHTML, - rbuggyQSA, - rbuggyMatches, - matches, - contains, - - // Instance-specific data - expando = "sizzle" + 1 * new Date(), - preferredDoc = window.document, - dirruns = 0, - done = 0, - classCache = createCache(), - tokenCache = createCache(), - compilerCache = createCache(), - sortOrder = function( a, b ) { - if ( a === b ) { - hasDuplicate = true; - } - return 0; - }, - - // Instance methods - hasOwn = ({}).hasOwnProperty, - arr = [], - pop = arr.pop, - push_native = arr.push, - push = arr.push, - slice = arr.slice, - // Use a stripped-down indexOf as it's faster than native - // https://jsperf.com/thor-indexof-vs-for/5 - indexOf = function( list, elem ) { - var i = 0, - len = list.length; - for ( ; i < len; i++ ) { - if ( list[i] === elem ) { - return i; - } - } - return -1; - }, - - booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped", - - // Regular expressions - - // http://www.w3.org/TR/css3-selectors/#whitespace - whitespace = "[\\x20\\t\\r\\n\\f]", - - // http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier - identifier = "(?:\\\\.|[\\w-]|[^\0-\\xa0])+", - - // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors - attributes = "\\[" + whitespace + "*(" + identifier + ")(?:" + whitespace + - // Operator (capture 2) - "*([*^$|!~]?=)" + whitespace + - // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]" - "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace + - "*\\]", - - pseudos = ":(" + identifier + ")(?:\\((" + - // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments: - // 1. quoted (capture 3; capture 4 or capture 5) - "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" + - // 2. simple (capture 6) - "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" + - // 3. anything else (capture 2) - ".*" + - ")\\)|)", - - // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter - rwhitespace = new RegExp( whitespace + "+", "g" ), - rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ), - - rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ), - rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ), - - rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ), - - rpseudo = new RegExp( pseudos ), - ridentifier = new RegExp( "^" + identifier + "$" ), - - matchExpr = { - "ID": new RegExp( "^#(" + identifier + ")" ), - "CLASS": new RegExp( "^\\.(" + identifier + ")" ), - "TAG": new RegExp( "^(" + identifier + "|[*])" ), - "ATTR": new RegExp( "^" + attributes ), - "PSEUDO": new RegExp( "^" + pseudos ), - "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace + - "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace + - "*(\\d+)|))" + whitespace + "*\\)|)", "i" ), - "bool": new RegExp( "^(?:" + booleans + ")$", "i" ), - // For use in libraries implementing .is() - // We use this for POS matching in `select` - "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" + - whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" ) - }, - - rinputs = /^(?:input|select|textarea|button)$/i, - rheader = /^h\d$/i, - - rnative = /^[^{]+\{\s*\[native \w/, - - // Easily-parseable/retrievable ID or TAG or CLASS selectors - rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/, - - rsibling = /[+~]/, - - // CSS escapes - // http://www.w3.org/TR/CSS21/syndata.html#escaped-characters - runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ), - funescape = function( _, escaped, escapedWhitespace ) { - var high = "0x" + escaped - 0x10000; - // NaN means non-codepoint - // Support: Firefox<24 - // Workaround erroneous numeric interpretation of +"0x" - return high !== high || escapedWhitespace ? - escaped : - high < 0 ? - // BMP codepoint - String.fromCharCode( high + 0x10000 ) : - // Supplemental Plane codepoint (surrogate pair) - String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 ); - }, - - // CSS string/identifier serialization - // https://drafts.csswg.org/cssom/#common-serializing-idioms - rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g, - fcssescape = function( ch, asCodePoint ) { - if ( asCodePoint ) { - - // U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER - if ( ch === "\0" ) { - return "\uFFFD"; - } - - // Control characters and (dependent upon position) numbers get escaped as code points - return ch.slice( 0, -1 ) + "\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + " "; - } - - // Other potentially-special ASCII characters get backslash-escaped - return "\\" + ch; - }, - - // Used for iframes - // See setDocument() - // Removing the function wrapper causes a "Permission Denied" - // error in IE - unloadHandler = function() { - setDocument(); - }, - - disabledAncestor = addCombinator( - function( elem ) { - return elem.disabled === true && ("form" in elem || "label" in elem); - }, - { dir: "parentNode", next: "legend" } - ); - -// Optimize for push.apply( _, NodeList ) -try { - push.apply( - (arr = slice.call( preferredDoc.childNodes )), - preferredDoc.childNodes - ); - // Support: Android<4.0 - // Detect silently failing push.apply - arr[ preferredDoc.childNodes.length ].nodeType; -} catch ( e ) { - push = { apply: arr.length ? - - // Leverage slice if possible - function( target, els ) { - push_native.apply( target, slice.call(els) ); - } : - - // Support: IE<9 - // Otherwise append directly - function( target, els ) { - var j = target.length, - i = 0; - // Can't trust NodeList.length - while ( (target[j++] = els[i++]) ) {} - target.length = j - 1; - } - }; -} - -function Sizzle( selector, context, results, seed ) { - var m, i, elem, nid, match, groups, newSelector, - newContext = context && context.ownerDocument, - - // nodeType defaults to 9, since context defaults to document - nodeType = context ? context.nodeType : 9; - - results = results || []; - - // Return early from calls with invalid selector or context - if ( typeof selector !== "string" || !selector || - nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) { - - return results; - } - - // Try to shortcut find operations (as opposed to filters) in HTML documents - if ( !seed ) { - - if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) { - setDocument( context ); - } - context = context || document; - - if ( documentIsHTML ) { - - // If the selector is sufficiently simple, try using a "get*By*" DOM method - // (excepting DocumentFragment context, where the methods don't exist) - if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) { - - // ID selector - if ( (m = match[1]) ) { - - // Document context - if ( nodeType === 9 ) { - if ( (elem = context.getElementById( m )) ) { - - // Support: IE, Opera, Webkit - // TODO: identify versions - // getElementById can match elements by name instead of ID - if ( elem.id === m ) { - results.push( elem ); - return results; - } - } else { - return results; - } - - // Element context - } else { - - // Support: IE, Opera, Webkit - // TODO: identify versions - // getElementById can match elements by name instead of ID - if ( newContext && (elem = newContext.getElementById( m )) && - contains( context, elem ) && - elem.id === m ) { - - results.push( elem ); - return results; - } - } - - // Type selector - } else if ( match[2] ) { - push.apply( results, context.getElementsByTagName( selector ) ); - return results; - - // Class selector - } else if ( (m = match[3]) && support.getElementsByClassName && - context.getElementsByClassName ) { - - push.apply( results, context.getElementsByClassName( m ) ); - return results; - } - } - - // Take advantage of querySelectorAll - if ( support.qsa && - !compilerCache[ selector + " " ] && - (!rbuggyQSA || !rbuggyQSA.test( selector )) ) { - - if ( nodeType !== 1 ) { - newContext = context; - newSelector = selector; - - // qSA looks outside Element context, which is not what we want - // Thanks to Andrew Dupont for this workaround technique - // Support: IE <=8 - // Exclude object elements - } else if ( context.nodeName.toLowerCase() !== "object" ) { - - // Capture the context ID, setting it first if necessary - if ( (nid = context.getAttribute( "id" )) ) { - nid = nid.replace( rcssescape, fcssescape ); - } else { - context.setAttribute( "id", (nid = expando) ); - } - - // Prefix every selector in the list - groups = tokenize( selector ); - i = groups.length; - while ( i-- ) { - groups[i] = "#" + nid + " " + toSelector( groups[i] ); - } - newSelector = groups.join( "," ); - - // Expand context for sibling selectors - newContext = rsibling.test( selector ) && testContext( context.parentNode ) || - context; - } - - if ( newSelector ) { - try { - push.apply( results, - newContext.querySelectorAll( newSelector ) - ); - return results; - } catch ( qsaError ) { - } finally { - if ( nid === expando ) { - context.removeAttribute( "id" ); - } - } - } - } - } - } - - // All others - return select( selector.replace( rtrim, "$1" ), context, results, seed ); -} - -/** - * Create key-value caches of limited size - * @returns {function(string, object)} Returns the Object data after storing it on itself with - * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength) - * deleting the oldest entry - */ -function createCache() { - var keys = []; - - function cache( key, value ) { - // Use (key + " ") to avoid collision with native prototype properties (see Issue #157) - if ( keys.push( key + " " ) > Expr.cacheLength ) { - // Only keep the most recent entries - delete cache[ keys.shift() ]; - } - return (cache[ key + " " ] = value); - } - return cache; -} - -/** - * Mark a function for special use by Sizzle - * @param {Function} fn The function to mark - */ -function markFunction( fn ) { - fn[ expando ] = true; - return fn; -} - -/** - * Support testing using an element - * @param {Function} fn Passed the created element and returns a boolean result - */ -function assert( fn ) { - var el = document.createElement("fieldset"); - - try { - return !!fn( el ); - } catch (e) { - return false; - } finally { - // Remove from its parent by default - if ( el.parentNode ) { - el.parentNode.removeChild( el ); - } - // release memory in IE - el = null; - } -} - -/** - * Adds the same handler for all of the specified attrs - * @param {String} attrs Pipe-separated list of attributes - * @param {Function} handler The method that will be applied - */ -function addHandle( attrs, handler ) { - var arr = attrs.split("|"), - i = arr.length; - - while ( i-- ) { - Expr.attrHandle[ arr[i] ] = handler; - } -} - -/** - * Checks document order of two siblings - * @param {Element} a - * @param {Element} b - * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b - */ -function siblingCheck( a, b ) { - var cur = b && a, - diff = cur && a.nodeType === 1 && b.nodeType === 1 && - a.sourceIndex - b.sourceIndex; - - // Use IE sourceIndex if available on both nodes - if ( diff ) { - return diff; - } - - // Check if b follows a - if ( cur ) { - while ( (cur = cur.nextSibling) ) { - if ( cur === b ) { - return -1; - } - } - } - - return a ? 1 : -1; -} - -/** - * Returns a function to use in pseudos for input types - * @param {String} type - */ -function createInputPseudo( type ) { - return function( elem ) { - var name = elem.nodeName.toLowerCase(); - return name === "input" && elem.type === type; - }; -} - -/** - * Returns a function to use in pseudos for buttons - * @param {String} type - */ -function createButtonPseudo( type ) { - return function( elem ) { - var name = elem.nodeName.toLowerCase(); - return (name === "input" || name === "button") && elem.type === type; - }; -} - -/** - * Returns a function to use in pseudos for :enabled/:disabled - * @param {Boolean} disabled true for :disabled; false for :enabled - */ -function createDisabledPseudo( disabled ) { - - // Known :disabled false positives: fieldset[disabled] > legend:nth-of-type(n+2) :can-disable - return function( elem ) { - - // Only certain elements can match :enabled or :disabled - // https://html.spec.whatwg.org/multipage/scripting.html#selector-enabled - // https://html.spec.whatwg.org/multipage/scripting.html#selector-disabled - if ( "form" in elem ) { - - // Check for inherited disabledness on relevant non-disabled elements: - // * listed form-associated elements in a disabled fieldset - // https://html.spec.whatwg.org/multipage/forms.html#category-listed - // https://html.spec.whatwg.org/multipage/forms.html#concept-fe-disabled - // * option elements in a disabled optgroup - // https://html.spec.whatwg.org/multipage/forms.html#concept-option-disabled - // All such elements have a "form" property. - if ( elem.parentNode && elem.disabled === false ) { - - // Option elements defer to a parent optgroup if present - if ( "label" in elem ) { - if ( "label" in elem.parentNode ) { - return elem.parentNode.disabled === disabled; - } else { - return elem.disabled === disabled; - } - } - - // Support: IE 6 - 11 - // Use the isDisabled shortcut property to check for disabled fieldset ancestors - return elem.isDisabled === disabled || - - // Where there is no isDisabled, check manually - /* jshint -W018 */ - elem.isDisabled !== !disabled && - disabledAncestor( elem ) === disabled; - } - - return elem.disabled === disabled; - - // Try to winnow out elements that can't be disabled before trusting the disabled property. - // Some victims get caught in our net (label, legend, menu, track), but it shouldn't - // even exist on them, let alone have a boolean value. - } else if ( "label" in elem ) { - return elem.disabled === disabled; - } - - // Remaining elements are neither :enabled nor :disabled - return false; - }; -} - -/** - * Returns a function to use in pseudos for positionals - * @param {Function} fn - */ -function createPositionalPseudo( fn ) { - return markFunction(function( argument ) { - argument = +argument; - return markFunction(function( seed, matches ) { - var j, - matchIndexes = fn( [], seed.length, argument ), - i = matchIndexes.length; - - // Match elements found at the specified indexes - while ( i-- ) { - if ( seed[ (j = matchIndexes[i]) ] ) { - seed[j] = !(matches[j] = seed[j]); - } - } - }); - }); -} - -/** - * Checks a node for validity as a Sizzle context - * @param {Element|Object=} context - * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value - */ -function testContext( context ) { - return context && typeof context.getElementsByTagName !== "undefined" && context; -} - -// Expose support vars for convenience -support = Sizzle.support = {}; - -/** - * Detects XML nodes - * @param {Element|Object} elem An element or a document - * @returns {Boolean} True iff elem is a non-HTML XML node - */ -isXML = Sizzle.isXML = function( elem ) { - // documentElement is verified for cases where it doesn't yet exist - // (such as loading iframes in IE - #4833) - var documentElement = elem && (elem.ownerDocument || elem).documentElement; - return documentElement ? documentElement.nodeName !== "HTML" : false; -}; - -/** - * Sets document-related variables once based on the current document - * @param {Element|Object} [doc] An element or document object to use to set the document - * @returns {Object} Returns the current document - */ -setDocument = Sizzle.setDocument = function( node ) { - var hasCompare, subWindow, - doc = node ? node.ownerDocument || node : preferredDoc; - - // Return early if doc is invalid or already selected - if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) { - return document; - } - - // Update global variables - document = doc; - docElem = document.documentElement; - documentIsHTML = !isXML( document ); - - // Support: IE 9-11, Edge - // Accessing iframe documents after unload throws "permission denied" errors (jQuery #13936) - if ( preferredDoc !== document && - (subWindow = document.defaultView) && subWindow.top !== subWindow ) { - - // Support: IE 11, Edge - if ( subWindow.addEventListener ) { - subWindow.addEventListener( "unload", unloadHandler, false ); - - // Support: IE 9 - 10 only - } else if ( subWindow.attachEvent ) { - subWindow.attachEvent( "onunload", unloadHandler ); - } - } - - /* Attributes - ---------------------------------------------------------------------- */ - - // Support: IE<8 - // Verify that getAttribute really returns attributes and not properties - // (excepting IE8 booleans) - support.attributes = assert(function( el ) { - el.className = "i"; - return !el.getAttribute("className"); - }); - - /* getElement(s)By* - ---------------------------------------------------------------------- */ - - // Check if getElementsByTagName("*") returns only elements - support.getElementsByTagName = assert(function( el ) { - el.appendChild( document.createComment("") ); - return !el.getElementsByTagName("*").length; - }); - - // Support: IE<9 - support.getElementsByClassName = rnative.test( document.getElementsByClassName ); - - // Support: IE<10 - // Check if getElementById returns elements by name - // The broken getElementById methods don't pick up programmatically-set names, - // so use a roundabout getElementsByName test - support.getById = assert(function( el ) { - docElem.appendChild( el ).id = expando; - return !document.getElementsByName || !document.getElementsByName( expando ).length; - }); - - // ID filter and find - if ( support.getById ) { - Expr.filter["ID"] = function( id ) { - var attrId = id.replace( runescape, funescape ); - return function( elem ) { - return elem.getAttribute("id") === attrId; - }; - }; - Expr.find["ID"] = function( id, context ) { - if ( typeof context.getElementById !== "undefined" && documentIsHTML ) { - var elem = context.getElementById( id ); - return elem ? [ elem ] : []; - } - }; - } else { - Expr.filter["ID"] = function( id ) { - var attrId = id.replace( runescape, funescape ); - return function( elem ) { - var node = typeof elem.getAttributeNode !== "undefined" && - elem.getAttributeNode("id"); - return node && node.value === attrId; - }; - }; - - // Support: IE 6 - 7 only - // getElementById is not reliable as a find shortcut - Expr.find["ID"] = function( id, context ) { - if ( typeof context.getElementById !== "undefined" && documentIsHTML ) { - var node, i, elems, - elem = context.getElementById( id ); - - if ( elem ) { - - // Verify the id attribute - node = elem.getAttributeNode("id"); - if ( node && node.value === id ) { - return [ elem ]; - } - - // Fall back on getElementsByName - elems = context.getElementsByName( id ); - i = 0; - while ( (elem = elems[i++]) ) { - node = elem.getAttributeNode("id"); - if ( node && node.value === id ) { - return [ elem ]; - } - } - } - - return []; - } - }; - } - - // Tag - Expr.find["TAG"] = support.getElementsByTagName ? - function( tag, context ) { - if ( typeof context.getElementsByTagName !== "undefined" ) { - return context.getElementsByTagName( tag ); - - // DocumentFragment nodes don't have gEBTN - } else if ( support.qsa ) { - return context.querySelectorAll( tag ); - } - } : - - function( tag, context ) { - var elem, - tmp = [], - i = 0, - // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too - results = context.getElementsByTagName( tag ); - - // Filter out possible comments - if ( tag === "*" ) { - while ( (elem = results[i++]) ) { - if ( elem.nodeType === 1 ) { - tmp.push( elem ); - } - } - - return tmp; - } - return results; - }; - - // Class - Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) { - if ( typeof context.getElementsByClassName !== "undefined" && documentIsHTML ) { - return context.getElementsByClassName( className ); - } - }; - - /* QSA/matchesSelector - ---------------------------------------------------------------------- */ - - // QSA and matchesSelector support - - // matchesSelector(:active) reports false when true (IE9/Opera 11.5) - rbuggyMatches = []; - - // qSa(:focus) reports false when true (Chrome 21) - // We allow this because of a bug in IE8/9 that throws an error - // whenever `document.activeElement` is accessed on an iframe - // So, we allow :focus to pass through QSA all the time to avoid the IE error - // See https://bugs.jquery.com/ticket/13378 - rbuggyQSA = []; - - if ( (support.qsa = rnative.test( document.querySelectorAll )) ) { - // Build QSA regex - // Regex strategy adopted from Diego Perini - assert(function( el ) { - // Select is set to empty string on purpose - // This is to test IE's treatment of not explicitly - // setting a boolean content attribute, - // since its presence should be enough - // https://bugs.jquery.com/ticket/12359 - docElem.appendChild( el ).innerHTML = "" + - ""; - - // Support: IE8, Opera 11-12.16 - // Nothing should be selected when empty strings follow ^= or $= or *= - // The test attribute must be unknown in Opera but "safe" for WinRT - // https://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section - if ( el.querySelectorAll("[msallowcapture^='']").length ) { - rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" ); - } - - // Support: IE8 - // Boolean attributes and "value" are not treated correctly - if ( !el.querySelectorAll("[selected]").length ) { - rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" ); - } - - // Support: Chrome<29, Android<4.4, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.8+ - if ( !el.querySelectorAll( "[id~=" + expando + "-]" ).length ) { - rbuggyQSA.push("~="); - } - - // Webkit/Opera - :checked should return selected option elements - // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked - // IE8 throws error here and will not see later tests - if ( !el.querySelectorAll(":checked").length ) { - rbuggyQSA.push(":checked"); - } - - // Support: Safari 8+, iOS 8+ - // https://bugs.webkit.org/show_bug.cgi?id=136851 - // In-page `selector#id sibling-combinator selector` fails - if ( !el.querySelectorAll( "a#" + expando + "+*" ).length ) { - rbuggyQSA.push(".#.+[+~]"); - } - }); - - assert(function( el ) { - el.innerHTML = "" + - ""; - - // Support: Windows 8 Native Apps - // The type and name attributes are restricted during .innerHTML assignment - var input = document.createElement("input"); - input.setAttribute( "type", "hidden" ); - el.appendChild( input ).setAttribute( "name", "D" ); - - // Support: IE8 - // Enforce case-sensitivity of name attribute - if ( el.querySelectorAll("[name=d]").length ) { - rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" ); - } - - // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled) - // IE8 throws error here and will not see later tests - if ( el.querySelectorAll(":enabled").length !== 2 ) { - rbuggyQSA.push( ":enabled", ":disabled" ); - } - - // Support: IE9-11+ - // IE's :disabled selector does not pick up the children of disabled fieldsets - docElem.appendChild( el ).disabled = true; - if ( el.querySelectorAll(":disabled").length !== 2 ) { - rbuggyQSA.push( ":enabled", ":disabled" ); - } - - // Opera 10-11 does not throw on post-comma invalid pseudos - el.querySelectorAll("*,:x"); - rbuggyQSA.push(",.*:"); - }); - } - - if ( (support.matchesSelector = rnative.test( (matches = docElem.matches || - docElem.webkitMatchesSelector || - docElem.mozMatchesSelector || - docElem.oMatchesSelector || - docElem.msMatchesSelector) )) ) { - - assert(function( el ) { - // Check to see if it's possible to do matchesSelector - // on a disconnected node (IE 9) - support.disconnectedMatch = matches.call( el, "*" ); - - // This should fail with an exception - // Gecko does not error, returns false instead - matches.call( el, "[s!='']:x" ); - rbuggyMatches.push( "!=", pseudos ); - }); - } - - rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") ); - rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") ); - - /* Contains - ---------------------------------------------------------------------- */ - hasCompare = rnative.test( docElem.compareDocumentPosition ); - - // Element contains another - // Purposefully self-exclusive - // As in, an element does not contain itself - contains = hasCompare || rnative.test( docElem.contains ) ? - function( a, b ) { - var adown = a.nodeType === 9 ? a.documentElement : a, - bup = b && b.parentNode; - return a === bup || !!( bup && bup.nodeType === 1 && ( - adown.contains ? - adown.contains( bup ) : - a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16 - )); - } : - function( a, b ) { - if ( b ) { - while ( (b = b.parentNode) ) { - if ( b === a ) { - return true; - } - } - } - return false; - }; - - /* Sorting - ---------------------------------------------------------------------- */ - - // Document order sorting - sortOrder = hasCompare ? - function( a, b ) { - - // Flag for duplicate removal - if ( a === b ) { - hasDuplicate = true; - return 0; - } - - // Sort on method existence if only one input has compareDocumentPosition - var compare = !a.compareDocumentPosition - !b.compareDocumentPosition; - if ( compare ) { - return compare; - } - - // Calculate position if both inputs belong to the same document - compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ? - a.compareDocumentPosition( b ) : - - // Otherwise we know they are disconnected - 1; - - // Disconnected nodes - if ( compare & 1 || - (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) { - - // Choose the first element that is related to our preferred document - if ( a === document || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) { - return -1; - } - if ( b === document || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) { - return 1; - } - - // Maintain original order - return sortInput ? - ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) : - 0; - } - - return compare & 4 ? -1 : 1; - } : - function( a, b ) { - // Exit early if the nodes are identical - if ( a === b ) { - hasDuplicate = true; - return 0; - } - - var cur, - i = 0, - aup = a.parentNode, - bup = b.parentNode, - ap = [ a ], - bp = [ b ]; - - // Parentless nodes are either documents or disconnected - if ( !aup || !bup ) { - return a === document ? -1 : - b === document ? 1 : - aup ? -1 : - bup ? 1 : - sortInput ? - ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) : - 0; - - // If the nodes are siblings, we can do a quick check - } else if ( aup === bup ) { - return siblingCheck( a, b ); - } - - // Otherwise we need full lists of their ancestors for comparison - cur = a; - while ( (cur = cur.parentNode) ) { - ap.unshift( cur ); - } - cur = b; - while ( (cur = cur.parentNode) ) { - bp.unshift( cur ); - } - - // Walk down the tree looking for a discrepancy - while ( ap[i] === bp[i] ) { - i++; - } - - return i ? - // Do a sibling check if the nodes have a common ancestor - siblingCheck( ap[i], bp[i] ) : - - // Otherwise nodes in our document sort first - ap[i] === preferredDoc ? -1 : - bp[i] === preferredDoc ? 1 : - 0; - }; - - return document; -}; - -Sizzle.matches = function( expr, elements ) { - return Sizzle( expr, null, null, elements ); -}; - -Sizzle.matchesSelector = function( elem, expr ) { - // Set document vars if needed - if ( ( elem.ownerDocument || elem ) !== document ) { - setDocument( elem ); - } - - // Make sure that attribute selectors are quoted - expr = expr.replace( rattributeQuotes, "='$1']" ); - - if ( support.matchesSelector && documentIsHTML && - !compilerCache[ expr + " " ] && - ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) && - ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) { - - try { - var ret = matches.call( elem, expr ); - - // IE 9's matchesSelector returns false on disconnected nodes - if ( ret || support.disconnectedMatch || - // As well, disconnected nodes are said to be in a document - // fragment in IE 9 - elem.document && elem.document.nodeType !== 11 ) { - return ret; - } - } catch (e) {} - } - - return Sizzle( expr, document, null, [ elem ] ).length > 0; -}; - -Sizzle.contains = function( context, elem ) { - // Set document vars if needed - if ( ( context.ownerDocument || context ) !== document ) { - setDocument( context ); - } - return contains( context, elem ); -}; - -Sizzle.attr = function( elem, name ) { - // Set document vars if needed - if ( ( elem.ownerDocument || elem ) !== document ) { - setDocument( elem ); - } - - var fn = Expr.attrHandle[ name.toLowerCase() ], - // Don't get fooled by Object.prototype properties (jQuery #13807) - val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ? - fn( elem, name, !documentIsHTML ) : - undefined; - - return val !== undefined ? - val : - support.attributes || !documentIsHTML ? - elem.getAttribute( name ) : - (val = elem.getAttributeNode(name)) && val.specified ? - val.value : - null; -}; - -Sizzle.escape = function( sel ) { - return (sel + "").replace( rcssescape, fcssescape ); -}; - -Sizzle.error = function( msg ) { - throw new Error( "Syntax error, unrecognized expression: " + msg ); -}; - -/** - * Document sorting and removing duplicates - * @param {ArrayLike} results - */ -Sizzle.uniqueSort = function( results ) { - var elem, - duplicates = [], - j = 0, - i = 0; - - // Unless we *know* we can detect duplicates, assume their presence - hasDuplicate = !support.detectDuplicates; - sortInput = !support.sortStable && results.slice( 0 ); - results.sort( sortOrder ); - - if ( hasDuplicate ) { - while ( (elem = results[i++]) ) { - if ( elem === results[ i ] ) { - j = duplicates.push( i ); - } - } - while ( j-- ) { - results.splice( duplicates[ j ], 1 ); - } - } - - // Clear input after sorting to release objects - // See https://github.com/jquery/sizzle/pull/225 - sortInput = null; - - return results; -}; - -/** - * Utility function for retrieving the text value of an array of DOM nodes - * @param {Array|Element} elem - */ -getText = Sizzle.getText = function( elem ) { - var node, - ret = "", - i = 0, - nodeType = elem.nodeType; - - if ( !nodeType ) { - // If no nodeType, this is expected to be an array - while ( (node = elem[i++]) ) { - // Do not traverse comment nodes - ret += getText( node ); - } - } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) { - // Use textContent for elements - // innerText usage removed for consistency of new lines (jQuery #11153) - if ( typeof elem.textContent === "string" ) { - return elem.textContent; - } else { - // Traverse its children - for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) { - ret += getText( elem ); - } - } - } else if ( nodeType === 3 || nodeType === 4 ) { - return elem.nodeValue; - } - // Do not include comment or processing instruction nodes - - return ret; -}; - -Expr = Sizzle.selectors = { - - // Can be adjusted by the user - cacheLength: 50, - - createPseudo: markFunction, - - match: matchExpr, - - attrHandle: {}, - - find: {}, - - relative: { - ">": { dir: "parentNode", first: true }, - " ": { dir: "parentNode" }, - "+": { dir: "previousSibling", first: true }, - "~": { dir: "previousSibling" } - }, - - preFilter: { - "ATTR": function( match ) { - match[1] = match[1].replace( runescape, funescape ); - - // Move the given value to match[3] whether quoted or unquoted - match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape ); - - if ( match[2] === "~=" ) { - match[3] = " " + match[3] + " "; - } - - return match.slice( 0, 4 ); - }, - - "CHILD": function( match ) { - /* matches from matchExpr["CHILD"] - 1 type (only|nth|...) - 2 what (child|of-type) - 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...) - 4 xn-component of xn+y argument ([+-]?\d*n|) - 5 sign of xn-component - 6 x of xn-component - 7 sign of y-component - 8 y of y-component - */ - match[1] = match[1].toLowerCase(); - - if ( match[1].slice( 0, 3 ) === "nth" ) { - // nth-* requires argument - if ( !match[3] ) { - Sizzle.error( match[0] ); - } - - // numeric x and y parameters for Expr.filter.CHILD - // remember that false/true cast respectively to 0/1 - match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) ); - match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" ); - - // other types prohibit arguments - } else if ( match[3] ) { - Sizzle.error( match[0] ); - } - - return match; - }, - - "PSEUDO": function( match ) { - var excess, - unquoted = !match[6] && match[2]; - - if ( matchExpr["CHILD"].test( match[0] ) ) { - return null; - } - - // Accept quoted arguments as-is - if ( match[3] ) { - match[2] = match[4] || match[5] || ""; - - // Strip excess characters from unquoted arguments - } else if ( unquoted && rpseudo.test( unquoted ) && - // Get excess from tokenize (recursively) - (excess = tokenize( unquoted, true )) && - // advance to the next closing parenthesis - (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) { - - // excess is a negative index - match[0] = match[0].slice( 0, excess ); - match[2] = unquoted.slice( 0, excess ); - } - - // Return only captures needed by the pseudo filter method (type and argument) - return match.slice( 0, 3 ); - } - }, - - filter: { - - "TAG": function( nodeNameSelector ) { - var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase(); - return nodeNameSelector === "*" ? - function() { return true; } : - function( elem ) { - return elem.nodeName && elem.nodeName.toLowerCase() === nodeName; - }; - }, - - "CLASS": function( className ) { - var pattern = classCache[ className + " " ]; - - return pattern || - (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) && - classCache( className, function( elem ) { - return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" ); - }); - }, - - "ATTR": function( name, operator, check ) { - return function( elem ) { - var result = Sizzle.attr( elem, name ); - - if ( result == null ) { - return operator === "!="; - } - if ( !operator ) { - return true; - } - - result += ""; - - return operator === "=" ? result === check : - operator === "!=" ? result !== check : - operator === "^=" ? check && result.indexOf( check ) === 0 : - operator === "*=" ? check && result.indexOf( check ) > -1 : - operator === "$=" ? check && result.slice( -check.length ) === check : - operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 : - operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" : - false; - }; - }, - - "CHILD": function( type, what, argument, first, last ) { - var simple = type.slice( 0, 3 ) !== "nth", - forward = type.slice( -4 ) !== "last", - ofType = what === "of-type"; - - return first === 1 && last === 0 ? - - // Shortcut for :nth-*(n) - function( elem ) { - return !!elem.parentNode; - } : - - function( elem, context, xml ) { - var cache, uniqueCache, outerCache, node, nodeIndex, start, - dir = simple !== forward ? "nextSibling" : "previousSibling", - parent = elem.parentNode, - name = ofType && elem.nodeName.toLowerCase(), - useCache = !xml && !ofType, - diff = false; - - if ( parent ) { - - // :(first|last|only)-(child|of-type) - if ( simple ) { - while ( dir ) { - node = elem; - while ( (node = node[ dir ]) ) { - if ( ofType ? - node.nodeName.toLowerCase() === name : - node.nodeType === 1 ) { - - return false; - } - } - // Reverse direction for :only-* (if we haven't yet done so) - start = dir = type === "only" && !start && "nextSibling"; - } - return true; - } - - start = [ forward ? parent.firstChild : parent.lastChild ]; - - // non-xml :nth-child(...) stores cache data on `parent` - if ( forward && useCache ) { - - // Seek `elem` from a previously-cached index - - // ...in a gzip-friendly way - node = parent; - outerCache = node[ expando ] || (node[ expando ] = {}); - - // Support: IE <9 only - // Defend against cloned attroperties (jQuery gh-1709) - uniqueCache = outerCache[ node.uniqueID ] || - (outerCache[ node.uniqueID ] = {}); - - cache = uniqueCache[ type ] || []; - nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ]; - diff = nodeIndex && cache[ 2 ]; - node = nodeIndex && parent.childNodes[ nodeIndex ]; - - while ( (node = ++nodeIndex && node && node[ dir ] || - - // Fallback to seeking `elem` from the start - (diff = nodeIndex = 0) || start.pop()) ) { - - // When found, cache indexes on `parent` and break - if ( node.nodeType === 1 && ++diff && node === elem ) { - uniqueCache[ type ] = [ dirruns, nodeIndex, diff ]; - break; - } - } - - } else { - // Use previously-cached element index if available - if ( useCache ) { - // ...in a gzip-friendly way - node = elem; - outerCache = node[ expando ] || (node[ expando ] = {}); - - // Support: IE <9 only - // Defend against cloned attroperties (jQuery gh-1709) - uniqueCache = outerCache[ node.uniqueID ] || - (outerCache[ node.uniqueID ] = {}); - - cache = uniqueCache[ type ] || []; - nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ]; - diff = nodeIndex; - } - - // xml :nth-child(...) - // or :nth-last-child(...) or :nth(-last)?-of-type(...) - if ( diff === false ) { - // Use the same loop as above to seek `elem` from the start - while ( (node = ++nodeIndex && node && node[ dir ] || - (diff = nodeIndex = 0) || start.pop()) ) { - - if ( ( ofType ? - node.nodeName.toLowerCase() === name : - node.nodeType === 1 ) && - ++diff ) { - - // Cache the index of each encountered element - if ( useCache ) { - outerCache = node[ expando ] || (node[ expando ] = {}); - - // Support: IE <9 only - // Defend against cloned attroperties (jQuery gh-1709) - uniqueCache = outerCache[ node.uniqueID ] || - (outerCache[ node.uniqueID ] = {}); - - uniqueCache[ type ] = [ dirruns, diff ]; - } - - if ( node === elem ) { - break; - } - } - } - } - } - - // Incorporate the offset, then check against cycle size - diff -= last; - return diff === first || ( diff % first === 0 && diff / first >= 0 ); - } - }; - }, - - "PSEUDO": function( pseudo, argument ) { - // pseudo-class names are case-insensitive - // http://www.w3.org/TR/selectors/#pseudo-classes - // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters - // Remember that setFilters inherits from pseudos - var args, - fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] || - Sizzle.error( "unsupported pseudo: " + pseudo ); - - // The user may use createPseudo to indicate that - // arguments are needed to create the filter function - // just as Sizzle does - if ( fn[ expando ] ) { - return fn( argument ); - } - - // But maintain support for old signatures - if ( fn.length > 1 ) { - args = [ pseudo, pseudo, "", argument ]; - return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ? - markFunction(function( seed, matches ) { - var idx, - matched = fn( seed, argument ), - i = matched.length; - while ( i-- ) { - idx = indexOf( seed, matched[i] ); - seed[ idx ] = !( matches[ idx ] = matched[i] ); - } - }) : - function( elem ) { - return fn( elem, 0, args ); - }; - } - - return fn; - } - }, - - pseudos: { - // Potentially complex pseudos - "not": markFunction(function( selector ) { - // Trim the selector passed to compile - // to avoid treating leading and trailing - // spaces as combinators - var input = [], - results = [], - matcher = compile( selector.replace( rtrim, "$1" ) ); - - return matcher[ expando ] ? - markFunction(function( seed, matches, context, xml ) { - var elem, - unmatched = matcher( seed, null, xml, [] ), - i = seed.length; - - // Match elements unmatched by `matcher` - while ( i-- ) { - if ( (elem = unmatched[i]) ) { - seed[i] = !(matches[i] = elem); - } - } - }) : - function( elem, context, xml ) { - input[0] = elem; - matcher( input, null, xml, results ); - // Don't keep the element (issue #299) - input[0] = null; - return !results.pop(); - }; - }), - - "has": markFunction(function( selector ) { - return function( elem ) { - return Sizzle( selector, elem ).length > 0; - }; - }), - - "contains": markFunction(function( text ) { - text = text.replace( runescape, funescape ); - return function( elem ) { - return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1; - }; - }), - - // "Whether an element is represented by a :lang() selector - // is based solely on the element's language value - // being equal to the identifier C, - // or beginning with the identifier C immediately followed by "-". - // The matching of C against the element's language value is performed case-insensitively. - // The identifier C does not have to be a valid language name." - // http://www.w3.org/TR/selectors/#lang-pseudo - "lang": markFunction( function( lang ) { - // lang value must be a valid identifier - if ( !ridentifier.test(lang || "") ) { - Sizzle.error( "unsupported lang: " + lang ); - } - lang = lang.replace( runescape, funescape ).toLowerCase(); - return function( elem ) { - var elemLang; - do { - if ( (elemLang = documentIsHTML ? - elem.lang : - elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) { - - elemLang = elemLang.toLowerCase(); - return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0; - } - } while ( (elem = elem.parentNode) && elem.nodeType === 1 ); - return false; - }; - }), - - // Miscellaneous - "target": function( elem ) { - var hash = window.location && window.location.hash; - return hash && hash.slice( 1 ) === elem.id; - }, - - "root": function( elem ) { - return elem === docElem; - }, - - "focus": function( elem ) { - return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex); - }, - - // Boolean properties - "enabled": createDisabledPseudo( false ), - "disabled": createDisabledPseudo( true ), - - "checked": function( elem ) { - // In CSS3, :checked should return both checked and selected elements - // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked - var nodeName = elem.nodeName.toLowerCase(); - return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected); - }, - - "selected": function( elem ) { - // Accessing this property makes selected-by-default - // options in Safari work properly - if ( elem.parentNode ) { - elem.parentNode.selectedIndex; - } - - return elem.selected === true; - }, - - // Contents - "empty": function( elem ) { - // http://www.w3.org/TR/selectors/#empty-pseudo - // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5), - // but not by others (comment: 8; processing instruction: 7; etc.) - // nodeType < 6 works because attributes (2) do not appear as children - for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) { - if ( elem.nodeType < 6 ) { - return false; - } - } - return true; - }, - - "parent": function( elem ) { - return !Expr.pseudos["empty"]( elem ); - }, - - // Element/input types - "header": function( elem ) { - return rheader.test( elem.nodeName ); - }, - - "input": function( elem ) { - return rinputs.test( elem.nodeName ); - }, - - "button": function( elem ) { - var name = elem.nodeName.toLowerCase(); - return name === "input" && elem.type === "button" || name === "button"; - }, - - "text": function( elem ) { - var attr; - return elem.nodeName.toLowerCase() === "input" && - elem.type === "text" && - - // Support: IE<8 - // New HTML5 attribute values (e.g., "search") appear with elem.type === "text" - ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" ); - }, - - // Position-in-collection - "first": createPositionalPseudo(function() { - return [ 0 ]; - }), - - "last": createPositionalPseudo(function( matchIndexes, length ) { - return [ length - 1 ]; - }), - - "eq": createPositionalPseudo(function( matchIndexes, length, argument ) { - return [ argument < 0 ? argument + length : argument ]; - }), - - "even": createPositionalPseudo(function( matchIndexes, length ) { - var i = 0; - for ( ; i < length; i += 2 ) { - matchIndexes.push( i ); - } - return matchIndexes; - }), - - "odd": createPositionalPseudo(function( matchIndexes, length ) { - var i = 1; - for ( ; i < length; i += 2 ) { - matchIndexes.push( i ); - } - return matchIndexes; - }), - - "lt": createPositionalPseudo(function( matchIndexes, length, argument ) { - var i = argument < 0 ? argument + length : argument; - for ( ; --i >= 0; ) { - matchIndexes.push( i ); - } - return matchIndexes; - }), - - "gt": createPositionalPseudo(function( matchIndexes, length, argument ) { - var i = argument < 0 ? argument + length : argument; - for ( ; ++i < length; ) { - matchIndexes.push( i ); - } - return matchIndexes; - }) - } -}; - -Expr.pseudos["nth"] = Expr.pseudos["eq"]; - -// Add button/input type pseudos -for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) { - Expr.pseudos[ i ] = createInputPseudo( i ); -} -for ( i in { submit: true, reset: true } ) { - Expr.pseudos[ i ] = createButtonPseudo( i ); -} - -// Easy API for creating new setFilters -function setFilters() {} -setFilters.prototype = Expr.filters = Expr.pseudos; -Expr.setFilters = new setFilters(); - -tokenize = Sizzle.tokenize = function( selector, parseOnly ) { - var matched, match, tokens, type, - soFar, groups, preFilters, - cached = tokenCache[ selector + " " ]; - - if ( cached ) { - return parseOnly ? 0 : cached.slice( 0 ); - } - - soFar = selector; - groups = []; - preFilters = Expr.preFilter; - - while ( soFar ) { - - // Comma and first run - if ( !matched || (match = rcomma.exec( soFar )) ) { - if ( match ) { - // Don't consume trailing commas as valid - soFar = soFar.slice( match[0].length ) || soFar; - } - groups.push( (tokens = []) ); - } - - matched = false; - - // Combinators - if ( (match = rcombinators.exec( soFar )) ) { - matched = match.shift(); - tokens.push({ - value: matched, - // Cast descendant combinators to space - type: match[0].replace( rtrim, " " ) - }); - soFar = soFar.slice( matched.length ); - } - - // Filters - for ( type in Expr.filter ) { - if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] || - (match = preFilters[ type ]( match ))) ) { - matched = match.shift(); - tokens.push({ - value: matched, - type: type, - matches: match - }); - soFar = soFar.slice( matched.length ); - } - } - - if ( !matched ) { - break; - } - } - - // Return the length of the invalid excess - // if we're just parsing - // Otherwise, throw an error or return tokens - return parseOnly ? - soFar.length : - soFar ? - Sizzle.error( selector ) : - // Cache the tokens - tokenCache( selector, groups ).slice( 0 ); -}; - -function toSelector( tokens ) { - var i = 0, - len = tokens.length, - selector = ""; - for ( ; i < len; i++ ) { - selector += tokens[i].value; - } - return selector; -} - -function addCombinator( matcher, combinator, base ) { - var dir = combinator.dir, - skip = combinator.next, - key = skip || dir, - checkNonElements = base && key === "parentNode", - doneName = done++; - - return combinator.first ? - // Check against closest ancestor/preceding element - function( elem, context, xml ) { - while ( (elem = elem[ dir ]) ) { - if ( elem.nodeType === 1 || checkNonElements ) { - return matcher( elem, context, xml ); - } - } - return false; - } : - - // Check against all ancestor/preceding elements - function( elem, context, xml ) { - var oldCache, uniqueCache, outerCache, - newCache = [ dirruns, doneName ]; - - // We can't set arbitrary data on XML nodes, so they don't benefit from combinator caching - if ( xml ) { - while ( (elem = elem[ dir ]) ) { - if ( elem.nodeType === 1 || checkNonElements ) { - if ( matcher( elem, context, xml ) ) { - return true; - } - } - } - } else { - while ( (elem = elem[ dir ]) ) { - if ( elem.nodeType === 1 || checkNonElements ) { - outerCache = elem[ expando ] || (elem[ expando ] = {}); - - // Support: IE <9 only - // Defend against cloned attroperties (jQuery gh-1709) - uniqueCache = outerCache[ elem.uniqueID ] || (outerCache[ elem.uniqueID ] = {}); - - if ( skip && skip === elem.nodeName.toLowerCase() ) { - elem = elem[ dir ] || elem; - } else if ( (oldCache = uniqueCache[ key ]) && - oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) { - - // Assign to newCache so results back-propagate to previous elements - return (newCache[ 2 ] = oldCache[ 2 ]); - } else { - // Reuse newcache so results back-propagate to previous elements - uniqueCache[ key ] = newCache; - - // A match means we're done; a fail means we have to keep checking - if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) { - return true; - } - } - } - } - } - return false; - }; -} - -function elementMatcher( matchers ) { - return matchers.length > 1 ? - function( elem, context, xml ) { - var i = matchers.length; - while ( i-- ) { - if ( !matchers[i]( elem, context, xml ) ) { - return false; - } - } - return true; - } : - matchers[0]; -} - -function multipleContexts( selector, contexts, results ) { - var i = 0, - len = contexts.length; - for ( ; i < len; i++ ) { - Sizzle( selector, contexts[i], results ); - } - return results; -} - -function condense( unmatched, map, filter, context, xml ) { - var elem, - newUnmatched = [], - i = 0, - len = unmatched.length, - mapped = map != null; - - for ( ; i < len; i++ ) { - if ( (elem = unmatched[i]) ) { - if ( !filter || filter( elem, context, xml ) ) { - newUnmatched.push( elem ); - if ( mapped ) { - map.push( i ); - } - } - } - } - - return newUnmatched; -} - -function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) { - if ( postFilter && !postFilter[ expando ] ) { - postFilter = setMatcher( postFilter ); - } - if ( postFinder && !postFinder[ expando ] ) { - postFinder = setMatcher( postFinder, postSelector ); - } - return markFunction(function( seed, results, context, xml ) { - var temp, i, elem, - preMap = [], - postMap = [], - preexisting = results.length, - - // Get initial elements from seed or context - elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ), - - // Prefilter to get matcher input, preserving a map for seed-results synchronization - matcherIn = preFilter && ( seed || !selector ) ? - condense( elems, preMap, preFilter, context, xml ) : - elems, - - matcherOut = matcher ? - // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results, - postFinder || ( seed ? preFilter : preexisting || postFilter ) ? - - // ...intermediate processing is necessary - [] : - - // ...otherwise use results directly - results : - matcherIn; - - // Find primary matches - if ( matcher ) { - matcher( matcherIn, matcherOut, context, xml ); - } - - // Apply postFilter - if ( postFilter ) { - temp = condense( matcherOut, postMap ); - postFilter( temp, [], context, xml ); - - // Un-match failing elements by moving them back to matcherIn - i = temp.length; - while ( i-- ) { - if ( (elem = temp[i]) ) { - matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem); - } - } - } - - if ( seed ) { - if ( postFinder || preFilter ) { - if ( postFinder ) { - // Get the final matcherOut by condensing this intermediate into postFinder contexts - temp = []; - i = matcherOut.length; - while ( i-- ) { - if ( (elem = matcherOut[i]) ) { - // Restore matcherIn since elem is not yet a final match - temp.push( (matcherIn[i] = elem) ); - } - } - postFinder( null, (matcherOut = []), temp, xml ); - } - - // Move matched elements from seed to results to keep them synchronized - i = matcherOut.length; - while ( i-- ) { - if ( (elem = matcherOut[i]) && - (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) { - - seed[temp] = !(results[temp] = elem); - } - } - } - - // Add elements to results, through postFinder if defined - } else { - matcherOut = condense( - matcherOut === results ? - matcherOut.splice( preexisting, matcherOut.length ) : - matcherOut - ); - if ( postFinder ) { - postFinder( null, results, matcherOut, xml ); - } else { - push.apply( results, matcherOut ); - } - } - }); -} - -function matcherFromTokens( tokens ) { - var checkContext, matcher, j, - len = tokens.length, - leadingRelative = Expr.relative[ tokens[0].type ], - implicitRelative = leadingRelative || Expr.relative[" "], - i = leadingRelative ? 1 : 0, - - // The foundational matcher ensures that elements are reachable from top-level context(s) - matchContext = addCombinator( function( elem ) { - return elem === checkContext; - }, implicitRelative, true ), - matchAnyContext = addCombinator( function( elem ) { - return indexOf( checkContext, elem ) > -1; - }, implicitRelative, true ), - matchers = [ function( elem, context, xml ) { - var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || ( - (checkContext = context).nodeType ? - matchContext( elem, context, xml ) : - matchAnyContext( elem, context, xml ) ); - // Avoid hanging onto element (issue #299) - checkContext = null; - return ret; - } ]; - - for ( ; i < len; i++ ) { - if ( (matcher = Expr.relative[ tokens[i].type ]) ) { - matchers = [ addCombinator(elementMatcher( matchers ), matcher) ]; - } else { - matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches ); - - // Return special upon seeing a positional matcher - if ( matcher[ expando ] ) { - // Find the next relative operator (if any) for proper handling - j = ++i; - for ( ; j < len; j++ ) { - if ( Expr.relative[ tokens[j].type ] ) { - break; - } - } - return setMatcher( - i > 1 && elementMatcher( matchers ), - i > 1 && toSelector( - // If the preceding token was a descendant combinator, insert an implicit any-element `*` - tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" }) - ).replace( rtrim, "$1" ), - matcher, - i < j && matcherFromTokens( tokens.slice( i, j ) ), - j < len && matcherFromTokens( (tokens = tokens.slice( j )) ), - j < len && toSelector( tokens ) - ); - } - matchers.push( matcher ); - } - } - - return elementMatcher( matchers ); -} - -function matcherFromGroupMatchers( elementMatchers, setMatchers ) { - var bySet = setMatchers.length > 0, - byElement = elementMatchers.length > 0, - superMatcher = function( seed, context, xml, results, outermost ) { - var elem, j, matcher, - matchedCount = 0, - i = "0", - unmatched = seed && [], - setMatched = [], - contextBackup = outermostContext, - // We must always have either seed elements or outermost context - elems = seed || byElement && Expr.find["TAG"]( "*", outermost ), - // Use integer dirruns iff this is the outermost matcher - dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1), - len = elems.length; - - if ( outermost ) { - outermostContext = context === document || context || outermost; - } - - // Add elements passing elementMatchers directly to results - // Support: IE<9, Safari - // Tolerate NodeList properties (IE: "length"; Safari: ) matching elements by id - for ( ; i !== len && (elem = elems[i]) != null; i++ ) { - if ( byElement && elem ) { - j = 0; - if ( !context && elem.ownerDocument !== document ) { - setDocument( elem ); - xml = !documentIsHTML; - } - while ( (matcher = elementMatchers[j++]) ) { - if ( matcher( elem, context || document, xml) ) { - results.push( elem ); - break; - } - } - if ( outermost ) { - dirruns = dirrunsUnique; - } - } - - // Track unmatched elements for set filters - if ( bySet ) { - // They will have gone through all possible matchers - if ( (elem = !matcher && elem) ) { - matchedCount--; - } - - // Lengthen the array for every element, matched or not - if ( seed ) { - unmatched.push( elem ); - } - } - } - - // `i` is now the count of elements visited above, and adding it to `matchedCount` - // makes the latter nonnegative. - matchedCount += i; - - // Apply set filters to unmatched elements - // NOTE: This can be skipped if there are no unmatched elements (i.e., `matchedCount` - // equals `i`), unless we didn't visit _any_ elements in the above loop because we have - // no element matchers and no seed. - // Incrementing an initially-string "0" `i` allows `i` to remain a string only in that - // case, which will result in a "00" `matchedCount` that differs from `i` but is also - // numerically zero. - if ( bySet && i !== matchedCount ) { - j = 0; - while ( (matcher = setMatchers[j++]) ) { - matcher( unmatched, setMatched, context, xml ); - } - - if ( seed ) { - // Reintegrate element matches to eliminate the need for sorting - if ( matchedCount > 0 ) { - while ( i-- ) { - if ( !(unmatched[i] || setMatched[i]) ) { - setMatched[i] = pop.call( results ); - } - } - } - - // Discard index placeholder values to get only actual matches - setMatched = condense( setMatched ); - } - - // Add matches to results - push.apply( results, setMatched ); - - // Seedless set matches succeeding multiple successful matchers stipulate sorting - if ( outermost && !seed && setMatched.length > 0 && - ( matchedCount + setMatchers.length ) > 1 ) { - - Sizzle.uniqueSort( results ); - } - } - - // Override manipulation of globals by nested matchers - if ( outermost ) { - dirruns = dirrunsUnique; - outermostContext = contextBackup; - } - - return unmatched; - }; - - return bySet ? - markFunction( superMatcher ) : - superMatcher; -} - -compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) { - var i, - setMatchers = [], - elementMatchers = [], - cached = compilerCache[ selector + " " ]; - - if ( !cached ) { - // Generate a function of recursive functions that can be used to check each element - if ( !match ) { - match = tokenize( selector ); - } - i = match.length; - while ( i-- ) { - cached = matcherFromTokens( match[i] ); - if ( cached[ expando ] ) { - setMatchers.push( cached ); - } else { - elementMatchers.push( cached ); - } - } - - // Cache the compiled function - cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) ); - - // Save selector and tokenization - cached.selector = selector; - } - return cached; -}; - -/** - * A low-level selection function that works with Sizzle's compiled - * selector functions - * @param {String|Function} selector A selector or a pre-compiled - * selector function built with Sizzle.compile - * @param {Element} context - * @param {Array} [results] - * @param {Array} [seed] A set of elements to match against - */ -select = Sizzle.select = function( selector, context, results, seed ) { - var i, tokens, token, type, find, - compiled = typeof selector === "function" && selector, - match = !seed && tokenize( (selector = compiled.selector || selector) ); - - results = results || []; - - // Try to minimize operations if there is only one selector in the list and no seed - // (the latter of which guarantees us context) - if ( match.length === 1 ) { - - // Reduce context if the leading compound selector is an ID - tokens = match[0] = match[0].slice( 0 ); - if ( tokens.length > 2 && (token = tokens[0]).type === "ID" && - context.nodeType === 9 && documentIsHTML && Expr.relative[ tokens[1].type ] ) { - - context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0]; - if ( !context ) { - return results; - - // Precompiled matchers will still verify ancestry, so step up a level - } else if ( compiled ) { - context = context.parentNode; - } - - selector = selector.slice( tokens.shift().value.length ); - } - - // Fetch a seed set for right-to-left matching - i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length; - while ( i-- ) { - token = tokens[i]; - - // Abort if we hit a combinator - if ( Expr.relative[ (type = token.type) ] ) { - break; - } - if ( (find = Expr.find[ type ]) ) { - // Search, expanding context for leading sibling combinators - if ( (seed = find( - token.matches[0].replace( runescape, funescape ), - rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context - )) ) { - - // If seed is empty or no tokens remain, we can return early - tokens.splice( i, 1 ); - selector = seed.length && toSelector( tokens ); - if ( !selector ) { - push.apply( results, seed ); - return results; - } - - break; - } - } - } - } - - // Compile and execute a filtering function if one is not provided - // Provide `match` to avoid retokenization if we modified the selector above - ( compiled || compile( selector, match ) )( - seed, - context, - !documentIsHTML, - results, - !context || rsibling.test( selector ) && testContext( context.parentNode ) || context - ); - return results; -}; - -// One-time assignments - -// Sort stability -support.sortStable = expando.split("").sort( sortOrder ).join("") === expando; - -// Support: Chrome 14-35+ -// Always assume duplicates if they aren't passed to the comparison function -support.detectDuplicates = !!hasDuplicate; - -// Initialize against the default document -setDocument(); - -// Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27) -// Detached nodes confoundingly follow *each other* -support.sortDetached = assert(function( el ) { - // Should return 1, but returns 4 (following) - return el.compareDocumentPosition( document.createElement("fieldset") ) & 1; -}); - -// Support: IE<8 -// Prevent attribute/property "interpolation" -// https://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx -if ( !assert(function( el ) { - el.innerHTML = ""; - return el.firstChild.getAttribute("href") === "#" ; -}) ) { - addHandle( "type|href|height|width", function( elem, name, isXML ) { - if ( !isXML ) { - return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 ); - } - }); -} - -// Support: IE<9 -// Use defaultValue in place of getAttribute("value") -if ( !support.attributes || !assert(function( el ) { - el.innerHTML = ""; - el.firstChild.setAttribute( "value", "" ); - return el.firstChild.getAttribute( "value" ) === ""; -}) ) { - addHandle( "value", function( elem, name, isXML ) { - if ( !isXML && elem.nodeName.toLowerCase() === "input" ) { - return elem.defaultValue; - } - }); -} - -// Support: IE<9 -// Use getAttributeNode to fetch booleans when getAttribute lies -if ( !assert(function( el ) { - return el.getAttribute("disabled") == null; -}) ) { - addHandle( booleans, function( elem, name, isXML ) { - var val; - if ( !isXML ) { - return elem[ name ] === true ? name.toLowerCase() : - (val = elem.getAttributeNode( name )) && val.specified ? - val.value : - null; - } - }); -} - -return Sizzle; - -})( window ); - - - -jQuery.find = Sizzle; -jQuery.expr = Sizzle.selectors; - -// Deprecated -jQuery.expr[ ":" ] = jQuery.expr.pseudos; -jQuery.uniqueSort = jQuery.unique = Sizzle.uniqueSort; -jQuery.text = Sizzle.getText; -jQuery.isXMLDoc = Sizzle.isXML; -jQuery.contains = Sizzle.contains; -jQuery.escapeSelector = Sizzle.escape; - - - - -var dir = function( elem, dir, until ) { - var matched = [], - truncate = until !== undefined; - - while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) { - if ( elem.nodeType === 1 ) { - if ( truncate && jQuery( elem ).is( until ) ) { - break; - } - matched.push( elem ); - } - } - return matched; -}; - - -var siblings = function( n, elem ) { - var matched = []; - - for ( ; n; n = n.nextSibling ) { - if ( n.nodeType === 1 && n !== elem ) { - matched.push( n ); - } - } - - return matched; -}; - - -var rneedsContext = jQuery.expr.match.needsContext; - - - -function nodeName( elem, name ) { - - return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase(); - -}; -var rsingleTag = ( /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i ); - - - -// Implement the identical functionality for filter and not -function winnow( elements, qualifier, not ) { - if ( isFunction( qualifier ) ) { - return jQuery.grep( elements, function( elem, i ) { - return !!qualifier.call( elem, i, elem ) !== not; - } ); - } - - // Single element - if ( qualifier.nodeType ) { - return jQuery.grep( elements, function( elem ) { - return ( elem === qualifier ) !== not; - } ); - } - - // Arraylike of elements (jQuery, arguments, Array) - if ( typeof qualifier !== "string" ) { - return jQuery.grep( elements, function( elem ) { - return ( indexOf.call( qualifier, elem ) > -1 ) !== not; - } ); - } - - // Filtered directly for both simple and complex selectors - return jQuery.filter( qualifier, elements, not ); -} - -jQuery.filter = function( expr, elems, not ) { - var elem = elems[ 0 ]; - - if ( not ) { - expr = ":not(" + expr + ")"; - } - - if ( elems.length === 1 && elem.nodeType === 1 ) { - return jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : []; - } - - return jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) { - return elem.nodeType === 1; - } ) ); -}; - -jQuery.fn.extend( { - find: function( selector ) { - var i, ret, - len = this.length, - self = this; - - if ( typeof selector !== "string" ) { - return this.pushStack( jQuery( selector ).filter( function() { - for ( i = 0; i < len; i++ ) { - if ( jQuery.contains( self[ i ], this ) ) { - return true; - } - } - } ) ); - } - - ret = this.pushStack( [] ); - - for ( i = 0; i < len; i++ ) { - jQuery.find( selector, self[ i ], ret ); - } - - return len > 1 ? jQuery.uniqueSort( ret ) : ret; - }, - filter: function( selector ) { - return this.pushStack( winnow( this, selector || [], false ) ); - }, - not: function( selector ) { - return this.pushStack( winnow( this, selector || [], true ) ); - }, - is: function( selector ) { - return !!winnow( - this, - - // If this is a positional/relative selector, check membership in the returned set - // so $("p:first").is("p:last") won't return true for a doc with two "p". - typeof selector === "string" && rneedsContext.test( selector ) ? - jQuery( selector ) : - selector || [], - false - ).length; - } -} ); - - -// Initialize a jQuery object - - -// A central reference to the root jQuery(document) -var rootjQuery, - - // A simple way to check for HTML strings - // Prioritize #id over to avoid XSS via location.hash (#9521) - // Strict HTML recognition (#11290: must start with <) - // Shortcut simple #id case for speed - rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/, - - init = jQuery.fn.init = function( selector, context, root ) { - var match, elem; - - // HANDLE: $(""), $(null), $(undefined), $(false) - if ( !selector ) { - return this; - } - - // Method init() accepts an alternate rootjQuery - // so migrate can support jQuery.sub (gh-2101) - root = root || rootjQuery; - - // Handle HTML strings - if ( typeof selector === "string" ) { - if ( selector[ 0 ] === "<" && - selector[ selector.length - 1 ] === ">" && - selector.length >= 3 ) { - - // Assume that strings that start and end with <> are HTML and skip the regex check - match = [ null, selector, null ]; - - } else { - match = rquickExpr.exec( selector ); - } - - // Match html or make sure no context is specified for #id - if ( match && ( match[ 1 ] || !context ) ) { - - // HANDLE: $(html) -> $(array) - if ( match[ 1 ] ) { - context = context instanceof jQuery ? context[ 0 ] : context; - - // Option to run scripts is true for back-compat - // Intentionally let the error be thrown if parseHTML is not present - jQuery.merge( this, jQuery.parseHTML( - match[ 1 ], - context && context.nodeType ? context.ownerDocument || context : document, - true - ) ); - - // HANDLE: $(html, props) - if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) { - for ( match in context ) { - - // Properties of context are called as methods if possible - if ( isFunction( this[ match ] ) ) { - this[ match ]( context[ match ] ); - - // ...and otherwise set as attributes - } else { - this.attr( match, context[ match ] ); - } - } - } - - return this; - - // HANDLE: $(#id) - } else { - elem = document.getElementById( match[ 2 ] ); - - if ( elem ) { - - // Inject the element directly into the jQuery object - this[ 0 ] = elem; - this.length = 1; - } - return this; - } - - // HANDLE: $(expr, $(...)) - } else if ( !context || context.jquery ) { - return ( context || root ).find( selector ); - - // HANDLE: $(expr, context) - // (which is just equivalent to: $(context).find(expr) - } else { - return this.constructor( context ).find( selector ); - } - - // HANDLE: $(DOMElement) - } else if ( selector.nodeType ) { - this[ 0 ] = selector; - this.length = 1; - return this; - - // HANDLE: $(function) - // Shortcut for document ready - } else if ( isFunction( selector ) ) { - return root.ready !== undefined ? - root.ready( selector ) : - - // Execute immediately if ready is not present - selector( jQuery ); - } - - return jQuery.makeArray( selector, this ); - }; - -// Give the init function the jQuery prototype for later instantiation -init.prototype = jQuery.fn; - -// Initialize central reference -rootjQuery = jQuery( document ); - - -var rparentsprev = /^(?:parents|prev(?:Until|All))/, - - // Methods guaranteed to produce a unique set when starting from a unique set - guaranteedUnique = { - children: true, - contents: true, - next: true, - prev: true - }; - -jQuery.fn.extend( { - has: function( target ) { - var targets = jQuery( target, this ), - l = targets.length; - - return this.filter( function() { - var i = 0; - for ( ; i < l; i++ ) { - if ( jQuery.contains( this, targets[ i ] ) ) { - return true; - } - } - } ); - }, - - closest: function( selectors, context ) { - var cur, - i = 0, - l = this.length, - matched = [], - targets = typeof selectors !== "string" && jQuery( selectors ); - - // Positional selectors never match, since there's no _selection_ context - if ( !rneedsContext.test( selectors ) ) { - for ( ; i < l; i++ ) { - for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) { - - // Always skip document fragments - if ( cur.nodeType < 11 && ( targets ? - targets.index( cur ) > -1 : - - // Don't pass non-elements to Sizzle - cur.nodeType === 1 && - jQuery.find.matchesSelector( cur, selectors ) ) ) { - - matched.push( cur ); - break; - } - } - } - } - - return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched ); - }, - - // Determine the position of an element within the set - index: function( elem ) { - - // No argument, return index in parent - if ( !elem ) { - return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1; - } - - // Index in selector - if ( typeof elem === "string" ) { - return indexOf.call( jQuery( elem ), this[ 0 ] ); - } - - // Locate the position of the desired element - return indexOf.call( this, - - // If it receives a jQuery object, the first element is used - elem.jquery ? elem[ 0 ] : elem - ); - }, - - add: function( selector, context ) { - return this.pushStack( - jQuery.uniqueSort( - jQuery.merge( this.get(), jQuery( selector, context ) ) - ) - ); - }, - - addBack: function( selector ) { - return this.add( selector == null ? - this.prevObject : this.prevObject.filter( selector ) - ); - } -} ); - -function sibling( cur, dir ) { - while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {} - return cur; -} - -jQuery.each( { - parent: function( elem ) { - var parent = elem.parentNode; - return parent && parent.nodeType !== 11 ? parent : null; - }, - parents: function( elem ) { - return dir( elem, "parentNode" ); - }, - parentsUntil: function( elem, i, until ) { - return dir( elem, "parentNode", until ); - }, - next: function( elem ) { - return sibling( elem, "nextSibling" ); - }, - prev: function( elem ) { - return sibling( elem, "previousSibling" ); - }, - nextAll: function( elem ) { - return dir( elem, "nextSibling" ); - }, - prevAll: function( elem ) { - return dir( elem, "previousSibling" ); - }, - nextUntil: function( elem, i, until ) { - return dir( elem, "nextSibling", until ); - }, - prevUntil: function( elem, i, until ) { - return dir( elem, "previousSibling", until ); - }, - siblings: function( elem ) { - return siblings( ( elem.parentNode || {} ).firstChild, elem ); - }, - children: function( elem ) { - return siblings( elem.firstChild ); - }, - contents: function( elem ) { - if ( nodeName( elem, "iframe" ) ) { - return elem.contentDocument; - } - - // Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only - // Treat the template element as a regular one in browsers that - // don't support it. - if ( nodeName( elem, "template" ) ) { - elem = elem.content || elem; - } - - return jQuery.merge( [], elem.childNodes ); - } -}, function( name, fn ) { - jQuery.fn[ name ] = function( until, selector ) { - var matched = jQuery.map( this, fn, until ); - - if ( name.slice( -5 ) !== "Until" ) { - selector = until; - } - - if ( selector && typeof selector === "string" ) { - matched = jQuery.filter( selector, matched ); - } - - if ( this.length > 1 ) { - - // Remove duplicates - if ( !guaranteedUnique[ name ] ) { - jQuery.uniqueSort( matched ); - } - - // Reverse order for parents* and prev-derivatives - if ( rparentsprev.test( name ) ) { - matched.reverse(); - } - } - - return this.pushStack( matched ); - }; -} ); -var rnothtmlwhite = ( /[^\x20\t\r\n\f]+/g ); - - - -// Convert String-formatted options into Object-formatted ones -function createOptions( options ) { - var object = {}; - jQuery.each( options.match( rnothtmlwhite ) || [], function( _, flag ) { - object[ flag ] = true; - } ); - return object; -} - -/* - * Create a callback list using the following parameters: - * - * options: an optional list of space-separated options that will change how - * the callback list behaves or a more traditional option object - * - * By default a callback list will act like an event callback list and can be - * "fired" multiple times. - * - * Possible options: - * - * once: will ensure the callback list can only be fired once (like a Deferred) - * - * memory: will keep track of previous values and will call any callback added - * after the list has been fired right away with the latest "memorized" - * values (like a Deferred) - * - * unique: will ensure a callback can only be added once (no duplicate in the list) - * - * stopOnFalse: interrupt callings when a callback returns false - * - */ -jQuery.Callbacks = function( options ) { - - // Convert options from String-formatted to Object-formatted if needed - // (we check in cache first) - options = typeof options === "string" ? - createOptions( options ) : - jQuery.extend( {}, options ); - - var // Flag to know if list is currently firing - firing, - - // Last fire value for non-forgettable lists - memory, - - // Flag to know if list was already fired - fired, - - // Flag to prevent firing - locked, - - // Actual callback list - list = [], - - // Queue of execution data for repeatable lists - queue = [], - - // Index of currently firing callback (modified by add/remove as needed) - firingIndex = -1, - - // Fire callbacks - fire = function() { - - // Enforce single-firing - locked = locked || options.once; - - // Execute callbacks for all pending executions, - // respecting firingIndex overrides and runtime changes - fired = firing = true; - for ( ; queue.length; firingIndex = -1 ) { - memory = queue.shift(); - while ( ++firingIndex < list.length ) { - - // Run callback and check for early termination - if ( list[ firingIndex ].apply( memory[ 0 ], memory[ 1 ] ) === false && - options.stopOnFalse ) { - - // Jump to end and forget the data so .add doesn't re-fire - firingIndex = list.length; - memory = false; - } - } - } - - // Forget the data if we're done with it - if ( !options.memory ) { - memory = false; - } - - firing = false; - - // Clean up if we're done firing for good - if ( locked ) { - - // Keep an empty list if we have data for future add calls - if ( memory ) { - list = []; - - // Otherwise, this object is spent - } else { - list = ""; - } - } - }, - - // Actual Callbacks object - self = { - - // Add a callback or a collection of callbacks to the list - add: function() { - if ( list ) { - - // If we have memory from a past run, we should fire after adding - if ( memory && !firing ) { - firingIndex = list.length - 1; - queue.push( memory ); - } - - ( function add( args ) { - jQuery.each( args, function( _, arg ) { - if ( isFunction( arg ) ) { - if ( !options.unique || !self.has( arg ) ) { - list.push( arg ); - } - } else if ( arg && arg.length && toType( arg ) !== "string" ) { - - // Inspect recursively - add( arg ); - } - } ); - } )( arguments ); - - if ( memory && !firing ) { - fire(); - } - } - return this; - }, - - // Remove a callback from the list - remove: function() { - jQuery.each( arguments, function( _, arg ) { - var index; - while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) { - list.splice( index, 1 ); - - // Handle firing indexes - if ( index <= firingIndex ) { - firingIndex--; - } - } - } ); - return this; - }, - - // Check if a given callback is in the list. - // If no argument is given, return whether or not list has callbacks attached. - has: function( fn ) { - return fn ? - jQuery.inArray( fn, list ) > -1 : - list.length > 0; - }, - - // Remove all callbacks from the list - empty: function() { - if ( list ) { - list = []; - } - return this; - }, - - // Disable .fire and .add - // Abort any current/pending executions - // Clear all callbacks and values - disable: function() { - locked = queue = []; - list = memory = ""; - return this; - }, - disabled: function() { - return !list; - }, - - // Disable .fire - // Also disable .add unless we have memory (since it would have no effect) - // Abort any pending executions - lock: function() { - locked = queue = []; - if ( !memory && !firing ) { - list = memory = ""; - } - return this; - }, - locked: function() { - return !!locked; - }, - - // Call all callbacks with the given context and arguments - fireWith: function( context, args ) { - if ( !locked ) { - args = args || []; - args = [ context, args.slice ? args.slice() : args ]; - queue.push( args ); - if ( !firing ) { - fire(); - } - } - return this; - }, - - // Call all the callbacks with the given arguments - fire: function() { - self.fireWith( this, arguments ); - return this; - }, - - // To know if the callbacks have already been called at least once - fired: function() { - return !!fired; - } - }; - - return self; -}; - - -function Identity( v ) { - return v; -} -function Thrower( ex ) { - throw ex; -} - -function adoptValue( value, resolve, reject, noValue ) { - var method; - - try { - - // Check for promise aspect first to privilege synchronous behavior - if ( value && isFunction( ( method = value.promise ) ) ) { - method.call( value ).done( resolve ).fail( reject ); - - // Other thenables - } else if ( value && isFunction( ( method = value.then ) ) ) { - method.call( value, resolve, reject ); - - // Other non-thenables - } else { - - // Control `resolve` arguments by letting Array#slice cast boolean `noValue` to integer: - // * false: [ value ].slice( 0 ) => resolve( value ) - // * true: [ value ].slice( 1 ) => resolve() - resolve.apply( undefined, [ value ].slice( noValue ) ); - } - - // For Promises/A+, convert exceptions into rejections - // Since jQuery.when doesn't unwrap thenables, we can skip the extra checks appearing in - // Deferred#then to conditionally suppress rejection. - } catch ( value ) { - - // Support: Android 4.0 only - // Strict mode functions invoked without .call/.apply get global-object context - reject.apply( undefined, [ value ] ); - } -} - -jQuery.extend( { - - Deferred: function( func ) { - var tuples = [ - - // action, add listener, callbacks, - // ... .then handlers, argument index, [final state] - [ "notify", "progress", jQuery.Callbacks( "memory" ), - jQuery.Callbacks( "memory" ), 2 ], - [ "resolve", "done", jQuery.Callbacks( "once memory" ), - jQuery.Callbacks( "once memory" ), 0, "resolved" ], - [ "reject", "fail", jQuery.Callbacks( "once memory" ), - jQuery.Callbacks( "once memory" ), 1, "rejected" ] - ], - state = "pending", - promise = { - state: function() { - return state; - }, - always: function() { - deferred.done( arguments ).fail( arguments ); - return this; - }, - "catch": function( fn ) { - return promise.then( null, fn ); - }, - - // Keep pipe for back-compat - pipe: function( /* fnDone, fnFail, fnProgress */ ) { - var fns = arguments; - - return jQuery.Deferred( function( newDefer ) { - jQuery.each( tuples, function( i, tuple ) { - - // Map tuples (progress, done, fail) to arguments (done, fail, progress) - var fn = isFunction( fns[ tuple[ 4 ] ] ) && fns[ tuple[ 4 ] ]; - - // deferred.progress(function() { bind to newDefer or newDefer.notify }) - // deferred.done(function() { bind to newDefer or newDefer.resolve }) - // deferred.fail(function() { bind to newDefer or newDefer.reject }) - deferred[ tuple[ 1 ] ]( function() { - var returned = fn && fn.apply( this, arguments ); - if ( returned && isFunction( returned.promise ) ) { - returned.promise() - .progress( newDefer.notify ) - .done( newDefer.resolve ) - .fail( newDefer.reject ); - } else { - newDefer[ tuple[ 0 ] + "With" ]( - this, - fn ? [ returned ] : arguments - ); - } - } ); - } ); - fns = null; - } ).promise(); - }, - then: function( onFulfilled, onRejected, onProgress ) { - var maxDepth = 0; - function resolve( depth, deferred, handler, special ) { - return function() { - var that = this, - args = arguments, - mightThrow = function() { - var returned, then; - - // Support: Promises/A+ section 2.3.3.3.3 - // https://promisesaplus.com/#point-59 - // Ignore double-resolution attempts - if ( depth < maxDepth ) { - return; - } - - returned = handler.apply( that, args ); - - // Support: Promises/A+ section 2.3.1 - // https://promisesaplus.com/#point-48 - if ( returned === deferred.promise() ) { - throw new TypeError( "Thenable self-resolution" ); - } - - // Support: Promises/A+ sections 2.3.3.1, 3.5 - // https://promisesaplus.com/#point-54 - // https://promisesaplus.com/#point-75 - // Retrieve `then` only once - then = returned && - - // Support: Promises/A+ section 2.3.4 - // https://promisesaplus.com/#point-64 - // Only check objects and functions for thenability - ( typeof returned === "object" || - typeof returned === "function" ) && - returned.then; - - // Handle a returned thenable - if ( isFunction( then ) ) { - - // Special processors (notify) just wait for resolution - if ( special ) { - then.call( - returned, - resolve( maxDepth, deferred, Identity, special ), - resolve( maxDepth, deferred, Thrower, special ) - ); - - // Normal processors (resolve) also hook into progress - } else { - - // ...and disregard older resolution values - maxDepth++; - - then.call( - returned, - resolve( maxDepth, deferred, Identity, special ), - resolve( maxDepth, deferred, Thrower, special ), - resolve( maxDepth, deferred, Identity, - deferred.notifyWith ) - ); - } - - // Handle all other returned values - } else { - - // Only substitute handlers pass on context - // and multiple values (non-spec behavior) - if ( handler !== Identity ) { - that = undefined; - args = [ returned ]; - } - - // Process the value(s) - // Default process is resolve - ( special || deferred.resolveWith )( that, args ); - } - }, - - // Only normal processors (resolve) catch and reject exceptions - process = special ? - mightThrow : - function() { - try { - mightThrow(); - } catch ( e ) { - - if ( jQuery.Deferred.exceptionHook ) { - jQuery.Deferred.exceptionHook( e, - process.stackTrace ); - } - - // Support: Promises/A+ section 2.3.3.3.4.1 - // https://promisesaplus.com/#point-61 - // Ignore post-resolution exceptions - if ( depth + 1 >= maxDepth ) { - - // Only substitute handlers pass on context - // and multiple values (non-spec behavior) - if ( handler !== Thrower ) { - that = undefined; - args = [ e ]; - } - - deferred.rejectWith( that, args ); - } - } - }; - - // Support: Promises/A+ section 2.3.3.3.1 - // https://promisesaplus.com/#point-57 - // Re-resolve promises immediately to dodge false rejection from - // subsequent errors - if ( depth ) { - process(); - } else { - - // Call an optional hook to record the stack, in case of exception - // since it's otherwise lost when execution goes async - if ( jQuery.Deferred.getStackHook ) { - process.stackTrace = jQuery.Deferred.getStackHook(); - } - window.setTimeout( process ); - } - }; - } - - return jQuery.Deferred( function( newDefer ) { - - // progress_handlers.add( ... ) - tuples[ 0 ][ 3 ].add( - resolve( - 0, - newDefer, - isFunction( onProgress ) ? - onProgress : - Identity, - newDefer.notifyWith - ) - ); - - // fulfilled_handlers.add( ... ) - tuples[ 1 ][ 3 ].add( - resolve( - 0, - newDefer, - isFunction( onFulfilled ) ? - onFulfilled : - Identity - ) - ); - - // rejected_handlers.add( ... ) - tuples[ 2 ][ 3 ].add( - resolve( - 0, - newDefer, - isFunction( onRejected ) ? - onRejected : - Thrower - ) - ); - } ).promise(); - }, - - // Get a promise for this deferred - // If obj is provided, the promise aspect is added to the object - promise: function( obj ) { - return obj != null ? jQuery.extend( obj, promise ) : promise; - } - }, - deferred = {}; - - // Add list-specific methods - jQuery.each( tuples, function( i, tuple ) { - var list = tuple[ 2 ], - stateString = tuple[ 5 ]; - - // promise.progress = list.add - // promise.done = list.add - // promise.fail = list.add - promise[ tuple[ 1 ] ] = list.add; - - // Handle state - if ( stateString ) { - list.add( - function() { - - // state = "resolved" (i.e., fulfilled) - // state = "rejected" - state = stateString; - }, - - // rejected_callbacks.disable - // fulfilled_callbacks.disable - tuples[ 3 - i ][ 2 ].disable, - - // rejected_handlers.disable - // fulfilled_handlers.disable - tuples[ 3 - i ][ 3 ].disable, - - // progress_callbacks.lock - tuples[ 0 ][ 2 ].lock, - - // progress_handlers.lock - tuples[ 0 ][ 3 ].lock - ); - } - - // progress_handlers.fire - // fulfilled_handlers.fire - // rejected_handlers.fire - list.add( tuple[ 3 ].fire ); - - // deferred.notify = function() { deferred.notifyWith(...) } - // deferred.resolve = function() { deferred.resolveWith(...) } - // deferred.reject = function() { deferred.rejectWith(...) } - deferred[ tuple[ 0 ] ] = function() { - deferred[ tuple[ 0 ] + "With" ]( this === deferred ? undefined : this, arguments ); - return this; - }; - - // deferred.notifyWith = list.fireWith - // deferred.resolveWith = list.fireWith - // deferred.rejectWith = list.fireWith - deferred[ tuple[ 0 ] + "With" ] = list.fireWith; - } ); - - // Make the deferred a promise - promise.promise( deferred ); - - // Call given func if any - if ( func ) { - func.call( deferred, deferred ); - } - - // All done! - return deferred; - }, - - // Deferred helper - when: function( singleValue ) { - var - - // count of uncompleted subordinates - remaining = arguments.length, - - // count of unprocessed arguments - i = remaining, - - // subordinate fulfillment data - resolveContexts = Array( i ), - resolveValues = slice.call( arguments ), - - // the master Deferred - master = jQuery.Deferred(), - - // subordinate callback factory - updateFunc = function( i ) { - return function( value ) { - resolveContexts[ i ] = this; - resolveValues[ i ] = arguments.length > 1 ? slice.call( arguments ) : value; - if ( !( --remaining ) ) { - master.resolveWith( resolveContexts, resolveValues ); - } - }; - }; - - // Single- and empty arguments are adopted like Promise.resolve - if ( remaining <= 1 ) { - adoptValue( singleValue, master.done( updateFunc( i ) ).resolve, master.reject, - !remaining ); - - // Use .then() to unwrap secondary thenables (cf. gh-3000) - if ( master.state() === "pending" || - isFunction( resolveValues[ i ] && resolveValues[ i ].then ) ) { - - return master.then(); - } - } - - // Multiple arguments are aggregated like Promise.all array elements - while ( i-- ) { - adoptValue( resolveValues[ i ], updateFunc( i ), master.reject ); - } - - return master.promise(); - } -} ); - - -// These usually indicate a programmer mistake during development, -// warn about them ASAP rather than swallowing them by default. -var rerrorNames = /^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/; - -jQuery.Deferred.exceptionHook = function( error, stack ) { - - // Support: IE 8 - 9 only - // Console exists when dev tools are open, which can happen at any time - if ( window.console && window.console.warn && error && rerrorNames.test( error.name ) ) { - window.console.warn( "jQuery.Deferred exception: " + error.message, error.stack, stack ); - } -}; - - - - -jQuery.readyException = function( error ) { - window.setTimeout( function() { - throw error; - } ); -}; - - - - -// The deferred used on DOM ready -var readyList = jQuery.Deferred(); - -jQuery.fn.ready = function( fn ) { - - readyList - .then( fn ) - - // Wrap jQuery.readyException in a function so that the lookup - // happens at the time of error handling instead of callback - // registration. - .catch( function( error ) { - jQuery.readyException( error ); - } ); - - return this; -}; - -jQuery.extend( { - - // Is the DOM ready to be used? Set to true once it occurs. - isReady: false, - - // A counter to track how many items to wait for before - // the ready event fires. See #6781 - readyWait: 1, - - // Handle when the DOM is ready - ready: function( wait ) { - - // Abort if there are pending holds or we're already ready - if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) { - return; - } - - // Remember that the DOM is ready - jQuery.isReady = true; - - // If a normal DOM Ready event fired, decrement, and wait if need be - if ( wait !== true && --jQuery.readyWait > 0 ) { - return; - } - - // If there are functions bound, to execute - readyList.resolveWith( document, [ jQuery ] ); - } -} ); - -jQuery.ready.then = readyList.then; - -// The ready event handler and self cleanup method -function completed() { - document.removeEventListener( "DOMContentLoaded", completed ); - window.removeEventListener( "load", completed ); - jQuery.ready(); -} - -// Catch cases where $(document).ready() is called -// after the browser event has already occurred. -// Support: IE <=9 - 10 only -// Older IE sometimes signals "interactive" too soon -if ( document.readyState === "complete" || - ( document.readyState !== "loading" && !document.documentElement.doScroll ) ) { - - // Handle it asynchronously to allow scripts the opportunity to delay ready - window.setTimeout( jQuery.ready ); - -} else { - - // Use the handy event callback - document.addEventListener( "DOMContentLoaded", completed ); - - // A fallback to window.onload, that will always work - window.addEventListener( "load", completed ); -} - - - - -// Multifunctional method to get and set values of a collection -// The value/s can optionally be executed if it's a function -var access = function( elems, fn, key, value, chainable, emptyGet, raw ) { - var i = 0, - len = elems.length, - bulk = key == null; - - // Sets many values - if ( toType( key ) === "object" ) { - chainable = true; - for ( i in key ) { - access( elems, fn, i, key[ i ], true, emptyGet, raw ); - } - - // Sets one value - } else if ( value !== undefined ) { - chainable = true; - - if ( !isFunction( value ) ) { - raw = true; - } - - if ( bulk ) { - - // Bulk operations run against the entire set - if ( raw ) { - fn.call( elems, value ); - fn = null; - - // ...except when executing function values - } else { - bulk = fn; - fn = function( elem, key, value ) { - return bulk.call( jQuery( elem ), value ); - }; - } - } - - if ( fn ) { - for ( ; i < len; i++ ) { - fn( - elems[ i ], key, raw ? - value : - value.call( elems[ i ], i, fn( elems[ i ], key ) ) - ); - } - } - } - - if ( chainable ) { - return elems; - } - - // Gets - if ( bulk ) { - return fn.call( elems ); - } - - return len ? fn( elems[ 0 ], key ) : emptyGet; -}; - - -// Matches dashed string for camelizing -var rmsPrefix = /^-ms-/, - rdashAlpha = /-([a-z])/g; - -// Used by camelCase as callback to replace() -function fcamelCase( all, letter ) { - return letter.toUpperCase(); -} - -// Convert dashed to camelCase; used by the css and data modules -// Support: IE <=9 - 11, Edge 12 - 15 -// Microsoft forgot to hump their vendor prefix (#9572) -function camelCase( string ) { - return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase ); -} -var acceptData = function( owner ) { - - // Accepts only: - // - Node - // - Node.ELEMENT_NODE - // - Node.DOCUMENT_NODE - // - Object - // - Any - return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType ); -}; - - - - -function Data() { - this.expando = jQuery.expando + Data.uid++; -} - -Data.uid = 1; - -Data.prototype = { - - cache: function( owner ) { - - // Check if the owner object already has a cache - var value = owner[ this.expando ]; - - // If not, create one - if ( !value ) { - value = {}; - - // We can accept data for non-element nodes in modern browsers, - // but we should not, see #8335. - // Always return an empty object. - if ( acceptData( owner ) ) { - - // If it is a node unlikely to be stringify-ed or looped over - // use plain assignment - if ( owner.nodeType ) { - owner[ this.expando ] = value; - - // Otherwise secure it in a non-enumerable property - // configurable must be true to allow the property to be - // deleted when data is removed - } else { - Object.defineProperty( owner, this.expando, { - value: value, - configurable: true - } ); - } - } - } - - return value; - }, - set: function( owner, data, value ) { - var prop, - cache = this.cache( owner ); - - // Handle: [ owner, key, value ] args - // Always use camelCase key (gh-2257) - if ( typeof data === "string" ) { - cache[ camelCase( data ) ] = value; - - // Handle: [ owner, { properties } ] args - } else { - - // Copy the properties one-by-one to the cache object - for ( prop in data ) { - cache[ camelCase( prop ) ] = data[ prop ]; - } - } - return cache; - }, - get: function( owner, key ) { - return key === undefined ? - this.cache( owner ) : - - // Always use camelCase key (gh-2257) - owner[ this.expando ] && owner[ this.expando ][ camelCase( key ) ]; - }, - access: function( owner, key, value ) { - - // In cases where either: - // - // 1. No key was specified - // 2. A string key was specified, but no value provided - // - // Take the "read" path and allow the get method to determine - // which value to return, respectively either: - // - // 1. The entire cache object - // 2. The data stored at the key - // - if ( key === undefined || - ( ( key && typeof key === "string" ) && value === undefined ) ) { - - return this.get( owner, key ); - } - - // When the key is not a string, or both a key and value - // are specified, set or extend (existing objects) with either: - // - // 1. An object of properties - // 2. A key and value - // - this.set( owner, key, value ); - - // Since the "set" path can have two possible entry points - // return the expected data based on which path was taken[*] - return value !== undefined ? value : key; - }, - remove: function( owner, key ) { - var i, - cache = owner[ this.expando ]; - - if ( cache === undefined ) { - return; - } - - if ( key !== undefined ) { - - // Support array or space separated string of keys - if ( Array.isArray( key ) ) { - - // If key is an array of keys... - // We always set camelCase keys, so remove that. - key = key.map( camelCase ); - } else { - key = camelCase( key ); - - // If a key with the spaces exists, use it. - // Otherwise, create an array by matching non-whitespace - key = key in cache ? - [ key ] : - ( key.match( rnothtmlwhite ) || [] ); - } - - i = key.length; - - while ( i-- ) { - delete cache[ key[ i ] ]; - } - } - - // Remove the expando if there's no more data - if ( key === undefined || jQuery.isEmptyObject( cache ) ) { - - // Support: Chrome <=35 - 45 - // Webkit & Blink performance suffers when deleting properties - // from DOM nodes, so set to undefined instead - // https://bugs.chromium.org/p/chromium/issues/detail?id=378607 (bug restricted) - if ( owner.nodeType ) { - owner[ this.expando ] = undefined; - } else { - delete owner[ this.expando ]; - } - } - }, - hasData: function( owner ) { - var cache = owner[ this.expando ]; - return cache !== undefined && !jQuery.isEmptyObject( cache ); - } -}; -var dataPriv = new Data(); - -var dataUser = new Data(); - - - -// Implementation Summary -// -// 1. Enforce API surface and semantic compatibility with 1.9.x branch -// 2. Improve the module's maintainability by reducing the storage -// paths to a single mechanism. -// 3. Use the same single mechanism to support "private" and "user" data. -// 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData) -// 5. Avoid exposing implementation details on user objects (eg. expando properties) -// 6. Provide a clear path for implementation upgrade to WeakMap in 2014 - -var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/, - rmultiDash = /[A-Z]/g; - -function getData( data ) { - if ( data === "true" ) { - return true; - } - - if ( data === "false" ) { - return false; - } - - if ( data === "null" ) { - return null; - } - - // Only convert to a number if it doesn't change the string - if ( data === +data + "" ) { - return +data; - } - - if ( rbrace.test( data ) ) { - return JSON.parse( data ); - } - - return data; -} - -function dataAttr( elem, key, data ) { - var name; - - // If nothing was found internally, try to fetch any - // data from the HTML5 data-* attribute - if ( data === undefined && elem.nodeType === 1 ) { - name = "data-" + key.replace( rmultiDash, "-$&" ).toLowerCase(); - data = elem.getAttribute( name ); - - if ( typeof data === "string" ) { - try { - data = getData( data ); - } catch ( e ) {} - - // Make sure we set the data so it isn't changed later - dataUser.set( elem, key, data ); - } else { - data = undefined; - } - } - return data; -} - -jQuery.extend( { - hasData: function( elem ) { - return dataUser.hasData( elem ) || dataPriv.hasData( elem ); - }, - - data: function( elem, name, data ) { - return dataUser.access( elem, name, data ); - }, - - removeData: function( elem, name ) { - dataUser.remove( elem, name ); - }, - - // TODO: Now that all calls to _data and _removeData have been replaced - // with direct calls to dataPriv methods, these can be deprecated. - _data: function( elem, name, data ) { - return dataPriv.access( elem, name, data ); - }, - - _removeData: function( elem, name ) { - dataPriv.remove( elem, name ); - } -} ); - -jQuery.fn.extend( { - data: function( key, value ) { - var i, name, data, - elem = this[ 0 ], - attrs = elem && elem.attributes; - - // Gets all values - if ( key === undefined ) { - if ( this.length ) { - data = dataUser.get( elem ); - - if ( elem.nodeType === 1 && !dataPriv.get( elem, "hasDataAttrs" ) ) { - i = attrs.length; - while ( i-- ) { - - // Support: IE 11 only - // The attrs elements can be null (#14894) - if ( attrs[ i ] ) { - name = attrs[ i ].name; - if ( name.indexOf( "data-" ) === 0 ) { - name = camelCase( name.slice( 5 ) ); - dataAttr( elem, name, data[ name ] ); - } - } - } - dataPriv.set( elem, "hasDataAttrs", true ); - } - } - - return data; - } - - // Sets multiple values - if ( typeof key === "object" ) { - return this.each( function() { - dataUser.set( this, key ); - } ); - } - - return access( this, function( value ) { - var data; - - // The calling jQuery object (element matches) is not empty - // (and therefore has an element appears at this[ 0 ]) and the - // `value` parameter was not undefined. An empty jQuery object - // will result in `undefined` for elem = this[ 0 ] which will - // throw an exception if an attempt to read a data cache is made. - if ( elem && value === undefined ) { - - // Attempt to get data from the cache - // The key will always be camelCased in Data - data = dataUser.get( elem, key ); - if ( data !== undefined ) { - return data; - } - - // Attempt to "discover" the data in - // HTML5 custom data-* attrs - data = dataAttr( elem, key ); - if ( data !== undefined ) { - return data; - } - - // We tried really hard, but the data doesn't exist. - return; - } - - // Set the data... - this.each( function() { - - // We always store the camelCased key - dataUser.set( this, key, value ); - } ); - }, null, value, arguments.length > 1, null, true ); - }, - - removeData: function( key ) { - return this.each( function() { - dataUser.remove( this, key ); - } ); - } -} ); - - -jQuery.extend( { - queue: function( elem, type, data ) { - var queue; - - if ( elem ) { - type = ( type || "fx" ) + "queue"; - queue = dataPriv.get( elem, type ); - - // Speed up dequeue by getting out quickly if this is just a lookup - if ( data ) { - if ( !queue || Array.isArray( data ) ) { - queue = dataPriv.access( elem, type, jQuery.makeArray( data ) ); - } else { - queue.push( data ); - } - } - return queue || []; - } - }, - - dequeue: function( elem, type ) { - type = type || "fx"; - - var queue = jQuery.queue( elem, type ), - startLength = queue.length, - fn = queue.shift(), - hooks = jQuery._queueHooks( elem, type ), - next = function() { - jQuery.dequeue( elem, type ); - }; - - // If the fx queue is dequeued, always remove the progress sentinel - if ( fn === "inprogress" ) { - fn = queue.shift(); - startLength--; - } - - if ( fn ) { - - // Add a progress sentinel to prevent the fx queue from being - // automatically dequeued - if ( type === "fx" ) { - queue.unshift( "inprogress" ); - } - - // Clear up the last queue stop function - delete hooks.stop; - fn.call( elem, next, hooks ); - } - - if ( !startLength && hooks ) { - hooks.empty.fire(); - } - }, - - // Not public - generate a queueHooks object, or return the current one - _queueHooks: function( elem, type ) { - var key = type + "queueHooks"; - return dataPriv.get( elem, key ) || dataPriv.access( elem, key, { - empty: jQuery.Callbacks( "once memory" ).add( function() { - dataPriv.remove( elem, [ type + "queue", key ] ); - } ) - } ); - } -} ); - -jQuery.fn.extend( { - queue: function( type, data ) { - var setter = 2; - - if ( typeof type !== "string" ) { - data = type; - type = "fx"; - setter--; - } - - if ( arguments.length < setter ) { - return jQuery.queue( this[ 0 ], type ); - } - - return data === undefined ? - this : - this.each( function() { - var queue = jQuery.queue( this, type, data ); - - // Ensure a hooks for this queue - jQuery._queueHooks( this, type ); - - if ( type === "fx" && queue[ 0 ] !== "inprogress" ) { - jQuery.dequeue( this, type ); - } - } ); - }, - dequeue: function( type ) { - return this.each( function() { - jQuery.dequeue( this, type ); - } ); - }, - clearQueue: function( type ) { - return this.queue( type || "fx", [] ); - }, - - // Get a promise resolved when queues of a certain type - // are emptied (fx is the type by default) - promise: function( type, obj ) { - var tmp, - count = 1, - defer = jQuery.Deferred(), - elements = this, - i = this.length, - resolve = function() { - if ( !( --count ) ) { - defer.resolveWith( elements, [ elements ] ); - } - }; - - if ( typeof type !== "string" ) { - obj = type; - type = undefined; - } - type = type || "fx"; - - while ( i-- ) { - tmp = dataPriv.get( elements[ i ], type + "queueHooks" ); - if ( tmp && tmp.empty ) { - count++; - tmp.empty.add( resolve ); - } - } - resolve(); - return defer.promise( obj ); - } -} ); -var pnum = ( /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/ ).source; - -var rcssNum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ); - - -var cssExpand = [ "Top", "Right", "Bottom", "Left" ]; - -var isHiddenWithinTree = function( elem, el ) { - - // isHiddenWithinTree might be called from jQuery#filter function; - // in that case, element will be second argument - elem = el || elem; - - // Inline style trumps all - return elem.style.display === "none" || - elem.style.display === "" && - - // Otherwise, check computed style - // Support: Firefox <=43 - 45 - // Disconnected elements can have computed display: none, so first confirm that elem is - // in the document. - jQuery.contains( elem.ownerDocument, elem ) && - - jQuery.css( elem, "display" ) === "none"; - }; - -var swap = function( elem, options, callback, args ) { - var ret, name, - old = {}; - - // Remember the old values, and insert the new ones - for ( name in options ) { - old[ name ] = elem.style[ name ]; - elem.style[ name ] = options[ name ]; - } - - ret = callback.apply( elem, args || [] ); - - // Revert the old values - for ( name in options ) { - elem.style[ name ] = old[ name ]; - } - - return ret; -}; - - - - -function adjustCSS( elem, prop, valueParts, tween ) { - var adjusted, scale, - maxIterations = 20, - currentValue = tween ? - function() { - return tween.cur(); - } : - function() { - return jQuery.css( elem, prop, "" ); - }, - initial = currentValue(), - unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ), - - // Starting value computation is required for potential unit mismatches - initialInUnit = ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) && - rcssNum.exec( jQuery.css( elem, prop ) ); - - if ( initialInUnit && initialInUnit[ 3 ] !== unit ) { - - // Support: Firefox <=54 - // Halve the iteration target value to prevent interference from CSS upper bounds (gh-2144) - initial = initial / 2; - - // Trust units reported by jQuery.css - unit = unit || initialInUnit[ 3 ]; - - // Iteratively approximate from a nonzero starting point - initialInUnit = +initial || 1; - - while ( maxIterations-- ) { - - // Evaluate and update our best guess (doubling guesses that zero out). - // Finish if the scale equals or crosses 1 (making the old*new product non-positive). - jQuery.style( elem, prop, initialInUnit + unit ); - if ( ( 1 - scale ) * ( 1 - ( scale = currentValue() / initial || 0.5 ) ) <= 0 ) { - maxIterations = 0; - } - initialInUnit = initialInUnit / scale; - - } - - initialInUnit = initialInUnit * 2; - jQuery.style( elem, prop, initialInUnit + unit ); - - // Make sure we update the tween properties later on - valueParts = valueParts || []; - } - - if ( valueParts ) { - initialInUnit = +initialInUnit || +initial || 0; - - // Apply relative offset (+=/-=) if specified - adjusted = valueParts[ 1 ] ? - initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] : - +valueParts[ 2 ]; - if ( tween ) { - tween.unit = unit; - tween.start = initialInUnit; - tween.end = adjusted; - } - } - return adjusted; -} - - -var defaultDisplayMap = {}; - -function getDefaultDisplay( elem ) { - var temp, - doc = elem.ownerDocument, - nodeName = elem.nodeName, - display = defaultDisplayMap[ nodeName ]; - - if ( display ) { - return display; - } - - temp = doc.body.appendChild( doc.createElement( nodeName ) ); - display = jQuery.css( temp, "display" ); - - temp.parentNode.removeChild( temp ); - - if ( display === "none" ) { - display = "block"; - } - defaultDisplayMap[ nodeName ] = display; - - return display; -} - -function showHide( elements, show ) { - var display, elem, - values = [], - index = 0, - length = elements.length; - - // Determine new display value for elements that need to change - for ( ; index < length; index++ ) { - elem = elements[ index ]; - if ( !elem.style ) { - continue; - } - - display = elem.style.display; - if ( show ) { - - // Since we force visibility upon cascade-hidden elements, an immediate (and slow) - // check is required in this first loop unless we have a nonempty display value (either - // inline or about-to-be-restored) - if ( display === "none" ) { - values[ index ] = dataPriv.get( elem, "display" ) || null; - if ( !values[ index ] ) { - elem.style.display = ""; - } - } - if ( elem.style.display === "" && isHiddenWithinTree( elem ) ) { - values[ index ] = getDefaultDisplay( elem ); - } - } else { - if ( display !== "none" ) { - values[ index ] = "none"; - - // Remember what we're overwriting - dataPriv.set( elem, "display", display ); - } - } - } - - // Set the display of the elements in a second loop to avoid constant reflow - for ( index = 0; index < length; index++ ) { - if ( values[ index ] != null ) { - elements[ index ].style.display = values[ index ]; - } - } - - return elements; -} - -jQuery.fn.extend( { - show: function() { - return showHide( this, true ); - }, - hide: function() { - return showHide( this ); - }, - toggle: function( state ) { - if ( typeof state === "boolean" ) { - return state ? this.show() : this.hide(); - } - - return this.each( function() { - if ( isHiddenWithinTree( this ) ) { - jQuery( this ).show(); - } else { - jQuery( this ).hide(); - } - } ); - } -} ); -var rcheckableType = ( /^(?:checkbox|radio)$/i ); - -var rtagName = ( /<([a-z][^\/\0>\x20\t\r\n\f]+)/i ); - -var rscriptType = ( /^$|^module$|\/(?:java|ecma)script/i ); - - - -// We have to close these tags to support XHTML (#13200) -var wrapMap = { - - // Support: IE <=9 only - option: [ 1, "" ], - - // XHTML parsers do not magically insert elements in the - // same way that tag soup parsers do. So we cannot shorten - // this by omitting or other required elements. - thead: [ 1, "", "
" ], - col: [ 2, "", "
" ], - tr: [ 2, "", "
" ], - td: [ 3, "", "
" ], - - _default: [ 0, "", "" ] -}; - -// Support: IE <=9 only -wrapMap.optgroup = wrapMap.option; - -wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; -wrapMap.th = wrapMap.td; - - -function getAll( context, tag ) { - - // Support: IE <=9 - 11 only - // Use typeof to avoid zero-argument method invocation on host objects (#15151) - var ret; - - if ( typeof context.getElementsByTagName !== "undefined" ) { - ret = context.getElementsByTagName( tag || "*" ); - - } else if ( typeof context.querySelectorAll !== "undefined" ) { - ret = context.querySelectorAll( tag || "*" ); - - } else { - ret = []; - } - - if ( tag === undefined || tag && nodeName( context, tag ) ) { - return jQuery.merge( [ context ], ret ); - } - - return ret; -} - - -// Mark scripts as having already been evaluated -function setGlobalEval( elems, refElements ) { - var i = 0, - l = elems.length; - - for ( ; i < l; i++ ) { - dataPriv.set( - elems[ i ], - "globalEval", - !refElements || dataPriv.get( refElements[ i ], "globalEval" ) - ); - } -} - - -var rhtml = /<|&#?\w+;/; - -function buildFragment( elems, context, scripts, selection, ignored ) { - var elem, tmp, tag, wrap, contains, j, - fragment = context.createDocumentFragment(), - nodes = [], - i = 0, - l = elems.length; - - for ( ; i < l; i++ ) { - elem = elems[ i ]; - - if ( elem || elem === 0 ) { - - // Add nodes directly - if ( toType( elem ) === "object" ) { - - // Support: Android <=4.0 only, PhantomJS 1 only - // push.apply(_, arraylike) throws on ancient WebKit - jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem ); - - // Convert non-html into a text node - } else if ( !rhtml.test( elem ) ) { - nodes.push( context.createTextNode( elem ) ); - - // Convert html into DOM nodes - } else { - tmp = tmp || fragment.appendChild( context.createElement( "div" ) ); - - // Deserialize a standard representation - tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase(); - wrap = wrapMap[ tag ] || wrapMap._default; - tmp.innerHTML = wrap[ 1 ] + jQuery.htmlPrefilter( elem ) + wrap[ 2 ]; - - // Descend through wrappers to the right content - j = wrap[ 0 ]; - while ( j-- ) { - tmp = tmp.lastChild; - } - - // Support: Android <=4.0 only, PhantomJS 1 only - // push.apply(_, arraylike) throws on ancient WebKit - jQuery.merge( nodes, tmp.childNodes ); - - // Remember the top-level container - tmp = fragment.firstChild; - - // Ensure the created nodes are orphaned (#12392) - tmp.textContent = ""; - } - } - } - - // Remove wrapper from fragment - fragment.textContent = ""; - - i = 0; - while ( ( elem = nodes[ i++ ] ) ) { - - // Skip elements already in the context collection (trac-4087) - if ( selection && jQuery.inArray( elem, selection ) > -1 ) { - if ( ignored ) { - ignored.push( elem ); - } - continue; - } - - contains = jQuery.contains( elem.ownerDocument, elem ); - - // Append to fragment - tmp = getAll( fragment.appendChild( elem ), "script" ); - - // Preserve script evaluation history - if ( contains ) { - setGlobalEval( tmp ); - } - - // Capture executables - if ( scripts ) { - j = 0; - while ( ( elem = tmp[ j++ ] ) ) { - if ( rscriptType.test( elem.type || "" ) ) { - scripts.push( elem ); - } - } - } - } - - return fragment; -} - - -( function() { - var fragment = document.createDocumentFragment(), - div = fragment.appendChild( document.createElement( "div" ) ), - input = document.createElement( "input" ); - - // Support: Android 4.0 - 4.3 only - // Check state lost if the name is set (#11217) - // Support: Windows Web Apps (WWA) - // `name` and `type` must use .setAttribute for WWA (#14901) - input.setAttribute( "type", "radio" ); - input.setAttribute( "checked", "checked" ); - input.setAttribute( "name", "t" ); - - div.appendChild( input ); - - // Support: Android <=4.1 only - // Older WebKit doesn't clone checked state correctly in fragments - support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked; - - // Support: IE <=11 only - // Make sure textarea (and checkbox) defaultValue is properly cloned - div.innerHTML = ""; - support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue; -} )(); -var documentElement = document.documentElement; - - - -var - rkeyEvent = /^key/, - rmouseEvent = /^(?:mouse|pointer|contextmenu|drag|drop)|click/, - rtypenamespace = /^([^.]*)(?:\.(.+)|)/; - -function returnTrue() { - return true; -} - -function returnFalse() { - return false; -} - -// Support: IE <=9 only -// See #13393 for more info -function safeActiveElement() { - try { - return document.activeElement; - } catch ( err ) { } -} - -function on( elem, types, selector, data, fn, one ) { - var origFn, type; - - // Types can be a map of types/handlers - if ( typeof types === "object" ) { - - // ( types-Object, selector, data ) - if ( typeof selector !== "string" ) { - - // ( types-Object, data ) - data = data || selector; - selector = undefined; - } - for ( type in types ) { - on( elem, type, selector, data, types[ type ], one ); - } - return elem; - } - - if ( data == null && fn == null ) { - - // ( types, fn ) - fn = selector; - data = selector = undefined; - } else if ( fn == null ) { - if ( typeof selector === "string" ) { - - // ( types, selector, fn ) - fn = data; - data = undefined; - } else { - - // ( types, data, fn ) - fn = data; - data = selector; - selector = undefined; - } - } - if ( fn === false ) { - fn = returnFalse; - } else if ( !fn ) { - return elem; - } - - if ( one === 1 ) { - origFn = fn; - fn = function( event ) { - - // Can use an empty set, since event contains the info - jQuery().off( event ); - return origFn.apply( this, arguments ); - }; - - // Use same guid so caller can remove using origFn - fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ ); - } - return elem.each( function() { - jQuery.event.add( this, types, fn, data, selector ); - } ); -} - -/* - * Helper functions for managing events -- not part of the public interface. - * Props to Dean Edwards' addEvent library for many of the ideas. - */ -jQuery.event = { - - global: {}, - - add: function( elem, types, handler, data, selector ) { - - var handleObjIn, eventHandle, tmp, - events, t, handleObj, - special, handlers, type, namespaces, origType, - elemData = dataPriv.get( elem ); - - // Don't attach events to noData or text/comment nodes (but allow plain objects) - if ( !elemData ) { - return; - } - - // Caller can pass in an object of custom data in lieu of the handler - if ( handler.handler ) { - handleObjIn = handler; - handler = handleObjIn.handler; - selector = handleObjIn.selector; - } - - // Ensure that invalid selectors throw exceptions at attach time - // Evaluate against documentElement in case elem is a non-element node (e.g., document) - if ( selector ) { - jQuery.find.matchesSelector( documentElement, selector ); - } - - // Make sure that the handler has a unique ID, used to find/remove it later - if ( !handler.guid ) { - handler.guid = jQuery.guid++; - } - - // Init the element's event structure and main handler, if this is the first - if ( !( events = elemData.events ) ) { - events = elemData.events = {}; - } - if ( !( eventHandle = elemData.handle ) ) { - eventHandle = elemData.handle = function( e ) { - - // Discard the second event of a jQuery.event.trigger() and - // when an event is called after a page has unloaded - return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ? - jQuery.event.dispatch.apply( elem, arguments ) : undefined; - }; - } - - // Handle multiple events separated by a space - types = ( types || "" ).match( rnothtmlwhite ) || [ "" ]; - t = types.length; - while ( t-- ) { - tmp = rtypenamespace.exec( types[ t ] ) || []; - type = origType = tmp[ 1 ]; - namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort(); - - // There *must* be a type, no attaching namespace-only handlers - if ( !type ) { - continue; - } - - // If event changes its type, use the special event handlers for the changed type - special = jQuery.event.special[ type ] || {}; - - // If selector defined, determine special event api type, otherwise given type - type = ( selector ? special.delegateType : special.bindType ) || type; - - // Update special based on newly reset type - special = jQuery.event.special[ type ] || {}; - - // handleObj is passed to all event handlers - handleObj = jQuery.extend( { - type: type, - origType: origType, - data: data, - handler: handler, - guid: handler.guid, - selector: selector, - needsContext: selector && jQuery.expr.match.needsContext.test( selector ), - namespace: namespaces.join( "." ) - }, handleObjIn ); - - // Init the event handler queue if we're the first - if ( !( handlers = events[ type ] ) ) { - handlers = events[ type ] = []; - handlers.delegateCount = 0; - - // Only use addEventListener if the special events handler returns false - if ( !special.setup || - special.setup.call( elem, data, namespaces, eventHandle ) === false ) { - - if ( elem.addEventListener ) { - elem.addEventListener( type, eventHandle ); - } - } - } - - if ( special.add ) { - special.add.call( elem, handleObj ); - - if ( !handleObj.handler.guid ) { - handleObj.handler.guid = handler.guid; - } - } - - // Add to the element's handler list, delegates in front - if ( selector ) { - handlers.splice( handlers.delegateCount++, 0, handleObj ); - } else { - handlers.push( handleObj ); - } - - // Keep track of which events have ever been used, for event optimization - jQuery.event.global[ type ] = true; - } - - }, - - // Detach an event or set of events from an element - remove: function( elem, types, handler, selector, mappedTypes ) { - - var j, origCount, tmp, - events, t, handleObj, - special, handlers, type, namespaces, origType, - elemData = dataPriv.hasData( elem ) && dataPriv.get( elem ); - - if ( !elemData || !( events = elemData.events ) ) { - return; - } - - // Once for each type.namespace in types; type may be omitted - types = ( types || "" ).match( rnothtmlwhite ) || [ "" ]; - t = types.length; - while ( t-- ) { - tmp = rtypenamespace.exec( types[ t ] ) || []; - type = origType = tmp[ 1 ]; - namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort(); - - // Unbind all events (on this namespace, if provided) for the element - if ( !type ) { - for ( type in events ) { - jQuery.event.remove( elem, type + types[ t ], handler, selector, true ); - } - continue; - } - - special = jQuery.event.special[ type ] || {}; - type = ( selector ? special.delegateType : special.bindType ) || type; - handlers = events[ type ] || []; - tmp = tmp[ 2 ] && - new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" ); - - // Remove matching events - origCount = j = handlers.length; - while ( j-- ) { - handleObj = handlers[ j ]; - - if ( ( mappedTypes || origType === handleObj.origType ) && - ( !handler || handler.guid === handleObj.guid ) && - ( !tmp || tmp.test( handleObj.namespace ) ) && - ( !selector || selector === handleObj.selector || - selector === "**" && handleObj.selector ) ) { - handlers.splice( j, 1 ); - - if ( handleObj.selector ) { - handlers.delegateCount--; - } - if ( special.remove ) { - special.remove.call( elem, handleObj ); - } - } - } - - // Remove generic event handler if we removed something and no more handlers exist - // (avoids potential for endless recursion during removal of special event handlers) - if ( origCount && !handlers.length ) { - if ( !special.teardown || - special.teardown.call( elem, namespaces, elemData.handle ) === false ) { - - jQuery.removeEvent( elem, type, elemData.handle ); - } - - delete events[ type ]; - } - } - - // Remove data and the expando if it's no longer used - if ( jQuery.isEmptyObject( events ) ) { - dataPriv.remove( elem, "handle events" ); - } - }, - - dispatch: function( nativeEvent ) { - - // Make a writable jQuery.Event from the native event object - var event = jQuery.event.fix( nativeEvent ); - - var i, j, ret, matched, handleObj, handlerQueue, - args = new Array( arguments.length ), - handlers = ( dataPriv.get( this, "events" ) || {} )[ event.type ] || [], - special = jQuery.event.special[ event.type ] || {}; - - // Use the fix-ed jQuery.Event rather than the (read-only) native event - args[ 0 ] = event; - - for ( i = 1; i < arguments.length; i++ ) { - args[ i ] = arguments[ i ]; - } - - event.delegateTarget = this; - - // Call the preDispatch hook for the mapped type, and let it bail if desired - if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) { - return; - } - - // Determine handlers - handlerQueue = jQuery.event.handlers.call( this, event, handlers ); - - // Run delegates first; they may want to stop propagation beneath us - i = 0; - while ( ( matched = handlerQueue[ i++ ] ) && !event.isPropagationStopped() ) { - event.currentTarget = matched.elem; - - j = 0; - while ( ( handleObj = matched.handlers[ j++ ] ) && - !event.isImmediatePropagationStopped() ) { - - // Triggered event must either 1) have no namespace, or 2) have namespace(s) - // a subset or equal to those in the bound event (both can have no namespace). - if ( !event.rnamespace || event.rnamespace.test( handleObj.namespace ) ) { - - event.handleObj = handleObj; - event.data = handleObj.data; - - ret = ( ( jQuery.event.special[ handleObj.origType ] || {} ).handle || - handleObj.handler ).apply( matched.elem, args ); - - if ( ret !== undefined ) { - if ( ( event.result = ret ) === false ) { - event.preventDefault(); - event.stopPropagation(); - } - } - } - } - } - - // Call the postDispatch hook for the mapped type - if ( special.postDispatch ) { - special.postDispatch.call( this, event ); - } - - return event.result; - }, - - handlers: function( event, handlers ) { - var i, handleObj, sel, matchedHandlers, matchedSelectors, - handlerQueue = [], - delegateCount = handlers.delegateCount, - cur = event.target; - - // Find delegate handlers - if ( delegateCount && - - // Support: IE <=9 - // Black-hole SVG instance trees (trac-13180) - cur.nodeType && - - // Support: Firefox <=42 - // Suppress spec-violating clicks indicating a non-primary pointer button (trac-3861) - // https://www.w3.org/TR/DOM-Level-3-Events/#event-type-click - // Support: IE 11 only - // ...but not arrow key "clicks" of radio inputs, which can have `button` -1 (gh-2343) - !( event.type === "click" && event.button >= 1 ) ) { - - for ( ; cur !== this; cur = cur.parentNode || this ) { - - // Don't check non-elements (#13208) - // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764) - if ( cur.nodeType === 1 && !( event.type === "click" && cur.disabled === true ) ) { - matchedHandlers = []; - matchedSelectors = {}; - for ( i = 0; i < delegateCount; i++ ) { - handleObj = handlers[ i ]; - - // Don't conflict with Object.prototype properties (#13203) - sel = handleObj.selector + " "; - - if ( matchedSelectors[ sel ] === undefined ) { - matchedSelectors[ sel ] = handleObj.needsContext ? - jQuery( sel, this ).index( cur ) > -1 : - jQuery.find( sel, this, null, [ cur ] ).length; - } - if ( matchedSelectors[ sel ] ) { - matchedHandlers.push( handleObj ); - } - } - if ( matchedHandlers.length ) { - handlerQueue.push( { elem: cur, handlers: matchedHandlers } ); - } - } - } - } - - // Add the remaining (directly-bound) handlers - cur = this; - if ( delegateCount < handlers.length ) { - handlerQueue.push( { elem: cur, handlers: handlers.slice( delegateCount ) } ); - } - - return handlerQueue; - }, - - addProp: function( name, hook ) { - Object.defineProperty( jQuery.Event.prototype, name, { - enumerable: true, - configurable: true, - - get: isFunction( hook ) ? - function() { - if ( this.originalEvent ) { - return hook( this.originalEvent ); - } - } : - function() { - if ( this.originalEvent ) { - return this.originalEvent[ name ]; - } - }, - - set: function( value ) { - Object.defineProperty( this, name, { - enumerable: true, - configurable: true, - writable: true, - value: value - } ); - } - } ); - }, - - fix: function( originalEvent ) { - return originalEvent[ jQuery.expando ] ? - originalEvent : - new jQuery.Event( originalEvent ); - }, - - special: { - load: { - - // Prevent triggered image.load events from bubbling to window.load - noBubble: true - }, - focus: { - - // Fire native event if possible so blur/focus sequence is correct - trigger: function() { - if ( this !== safeActiveElement() && this.focus ) { - this.focus(); - return false; - } - }, - delegateType: "focusin" - }, - blur: { - trigger: function() { - if ( this === safeActiveElement() && this.blur ) { - this.blur(); - return false; - } - }, - delegateType: "focusout" - }, - click: { - - // For checkbox, fire native event so checked state will be right - trigger: function() { - if ( this.type === "checkbox" && this.click && nodeName( this, "input" ) ) { - this.click(); - return false; - } - }, - - // For cross-browser consistency, don't fire native .click() on links - _default: function( event ) { - return nodeName( event.target, "a" ); - } - }, - - beforeunload: { - postDispatch: function( event ) { - - // Support: Firefox 20+ - // Firefox doesn't alert if the returnValue field is not set. - if ( event.result !== undefined && event.originalEvent ) { - event.originalEvent.returnValue = event.result; - } - } - } - } -}; - -jQuery.removeEvent = function( elem, type, handle ) { - - // This "if" is needed for plain objects - if ( elem.removeEventListener ) { - elem.removeEventListener( type, handle ); - } -}; - -jQuery.Event = function( src, props ) { - - // Allow instantiation without the 'new' keyword - if ( !( this instanceof jQuery.Event ) ) { - return new jQuery.Event( src, props ); - } - - // Event object - if ( src && src.type ) { - this.originalEvent = src; - this.type = src.type; - - // Events bubbling up the document may have been marked as prevented - // by a handler lower down the tree; reflect the correct value. - this.isDefaultPrevented = src.defaultPrevented || - src.defaultPrevented === undefined && - - // Support: Android <=2.3 only - src.returnValue === false ? - returnTrue : - returnFalse; - - // Create target properties - // Support: Safari <=6 - 7 only - // Target should not be a text node (#504, #13143) - this.target = ( src.target && src.target.nodeType === 3 ) ? - src.target.parentNode : - src.target; - - this.currentTarget = src.currentTarget; - this.relatedTarget = src.relatedTarget; - - // Event type - } else { - this.type = src; - } - - // Put explicitly provided properties onto the event object - if ( props ) { - jQuery.extend( this, props ); - } - - // Create a timestamp if incoming event doesn't have one - this.timeStamp = src && src.timeStamp || Date.now(); - - // Mark it as fixed - this[ jQuery.expando ] = true; -}; - -// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding -// https://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html -jQuery.Event.prototype = { - constructor: jQuery.Event, - isDefaultPrevented: returnFalse, - isPropagationStopped: returnFalse, - isImmediatePropagationStopped: returnFalse, - isSimulated: false, - - preventDefault: function() { - var e = this.originalEvent; - - this.isDefaultPrevented = returnTrue; - - if ( e && !this.isSimulated ) { - e.preventDefault(); - } - }, - stopPropagation: function() { - var e = this.originalEvent; - - this.isPropagationStopped = returnTrue; - - if ( e && !this.isSimulated ) { - e.stopPropagation(); - } - }, - stopImmediatePropagation: function() { - var e = this.originalEvent; - - this.isImmediatePropagationStopped = returnTrue; - - if ( e && !this.isSimulated ) { - e.stopImmediatePropagation(); - } - - this.stopPropagation(); - } -}; - -// Includes all common event props including KeyEvent and MouseEvent specific props -jQuery.each( { - altKey: true, - bubbles: true, - cancelable: true, - changedTouches: true, - ctrlKey: true, - detail: true, - eventPhase: true, - metaKey: true, - pageX: true, - pageY: true, - shiftKey: true, - view: true, - "char": true, - charCode: true, - key: true, - keyCode: true, - button: true, - buttons: true, - clientX: true, - clientY: true, - offsetX: true, - offsetY: true, - pointerId: true, - pointerType: true, - screenX: true, - screenY: true, - targetTouches: true, - toElement: true, - touches: true, - - which: function( event ) { - var button = event.button; - - // Add which for key events - if ( event.which == null && rkeyEvent.test( event.type ) ) { - return event.charCode != null ? event.charCode : event.keyCode; - } - - // Add which for click: 1 === left; 2 === middle; 3 === right - if ( !event.which && button !== undefined && rmouseEvent.test( event.type ) ) { - if ( button & 1 ) { - return 1; - } - - if ( button & 2 ) { - return 3; - } - - if ( button & 4 ) { - return 2; - } - - return 0; - } - - return event.which; - } -}, jQuery.event.addProp ); - -// Create mouseenter/leave events using mouseover/out and event-time checks -// so that event delegation works in jQuery. -// Do the same for pointerenter/pointerleave and pointerover/pointerout -// -// Support: Safari 7 only -// Safari sends mouseenter too often; see: -// https://bugs.chromium.org/p/chromium/issues/detail?id=470258 -// for the description of the bug (it existed in older Chrome versions as well). -jQuery.each( { - mouseenter: "mouseover", - mouseleave: "mouseout", - pointerenter: "pointerover", - pointerleave: "pointerout" -}, function( orig, fix ) { - jQuery.event.special[ orig ] = { - delegateType: fix, - bindType: fix, - - handle: function( event ) { - var ret, - target = this, - related = event.relatedTarget, - handleObj = event.handleObj; - - // For mouseenter/leave call the handler if related is outside the target. - // NB: No relatedTarget if the mouse left/entered the browser window - if ( !related || ( related !== target && !jQuery.contains( target, related ) ) ) { - event.type = handleObj.origType; - ret = handleObj.handler.apply( this, arguments ); - event.type = fix; - } - return ret; - } - }; -} ); - -jQuery.fn.extend( { - - on: function( types, selector, data, fn ) { - return on( this, types, selector, data, fn ); - }, - one: function( types, selector, data, fn ) { - return on( this, types, selector, data, fn, 1 ); - }, - off: function( types, selector, fn ) { - var handleObj, type; - if ( types && types.preventDefault && types.handleObj ) { - - // ( event ) dispatched jQuery.Event - handleObj = types.handleObj; - jQuery( types.delegateTarget ).off( - handleObj.namespace ? - handleObj.origType + "." + handleObj.namespace : - handleObj.origType, - handleObj.selector, - handleObj.handler - ); - return this; - } - if ( typeof types === "object" ) { - - // ( types-object [, selector] ) - for ( type in types ) { - this.off( type, selector, types[ type ] ); - } - return this; - } - if ( selector === false || typeof selector === "function" ) { - - // ( types [, fn] ) - fn = selector; - selector = undefined; - } - if ( fn === false ) { - fn = returnFalse; - } - return this.each( function() { - jQuery.event.remove( this, types, fn, selector ); - } ); - } -} ); - - -var - - /* eslint-disable max-len */ - - // See https://github.com/eslint/eslint/issues/3229 - rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi, - - /* eslint-enable */ - - // Support: IE <=10 - 11, Edge 12 - 13 only - // In IE/Edge using regex groups here causes severe slowdowns. - // See https://connect.microsoft.com/IE/feedback/details/1736512/ - rnoInnerhtml = /\s*$/g; - -// Prefer a tbody over its parent table for containing new rows -function manipulationTarget( elem, content ) { - if ( nodeName( elem, "table" ) && - nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ) { - - return jQuery( elem ).children( "tbody" )[ 0 ] || elem; - } - - return elem; -} - -// Replace/restore the type attribute of script elements for safe DOM manipulation -function disableScript( elem ) { - elem.type = ( elem.getAttribute( "type" ) !== null ) + "/" + elem.type; - return elem; -} -function restoreScript( elem ) { - if ( ( elem.type || "" ).slice( 0, 5 ) === "true/" ) { - elem.type = elem.type.slice( 5 ); - } else { - elem.removeAttribute( "type" ); - } - - return elem; -} - -function cloneCopyEvent( src, dest ) { - var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events; - - if ( dest.nodeType !== 1 ) { - return; - } - - // 1. Copy private data: events, handlers, etc. - if ( dataPriv.hasData( src ) ) { - pdataOld = dataPriv.access( src ); - pdataCur = dataPriv.set( dest, pdataOld ); - events = pdataOld.events; - - if ( events ) { - delete pdataCur.handle; - pdataCur.events = {}; - - for ( type in events ) { - for ( i = 0, l = events[ type ].length; i < l; i++ ) { - jQuery.event.add( dest, type, events[ type ][ i ] ); - } - } - } - } - - // 2. Copy user data - if ( dataUser.hasData( src ) ) { - udataOld = dataUser.access( src ); - udataCur = jQuery.extend( {}, udataOld ); - - dataUser.set( dest, udataCur ); - } -} - -// Fix IE bugs, see support tests -function fixInput( src, dest ) { - var nodeName = dest.nodeName.toLowerCase(); - - // Fails to persist the checked state of a cloned checkbox or radio button. - if ( nodeName === "input" && rcheckableType.test( src.type ) ) { - dest.checked = src.checked; - - // Fails to return the selected option to the default selected state when cloning options - } else if ( nodeName === "input" || nodeName === "textarea" ) { - dest.defaultValue = src.defaultValue; - } -} - -function domManip( collection, args, callback, ignored ) { - - // Flatten any nested arrays - args = concat.apply( [], args ); - - var fragment, first, scripts, hasScripts, node, doc, - i = 0, - l = collection.length, - iNoClone = l - 1, - value = args[ 0 ], - valueIsFunction = isFunction( value ); - - // We can't cloneNode fragments that contain checked, in WebKit - if ( valueIsFunction || - ( l > 1 && typeof value === "string" && - !support.checkClone && rchecked.test( value ) ) ) { - return collection.each( function( index ) { - var self = collection.eq( index ); - if ( valueIsFunction ) { - args[ 0 ] = value.call( this, index, self.html() ); - } - domManip( self, args, callback, ignored ); - } ); - } - - if ( l ) { - fragment = buildFragment( args, collection[ 0 ].ownerDocument, false, collection, ignored ); - first = fragment.firstChild; - - if ( fragment.childNodes.length === 1 ) { - fragment = first; - } - - // Require either new content or an interest in ignored elements to invoke the callback - if ( first || ignored ) { - scripts = jQuery.map( getAll( fragment, "script" ), disableScript ); - hasScripts = scripts.length; - - // Use the original fragment for the last item - // instead of the first because it can end up - // being emptied incorrectly in certain situations (#8070). - for ( ; i < l; i++ ) { - node = fragment; - - if ( i !== iNoClone ) { - node = jQuery.clone( node, true, true ); - - // Keep references to cloned scripts for later restoration - if ( hasScripts ) { - - // Support: Android <=4.0 only, PhantomJS 1 only - // push.apply(_, arraylike) throws on ancient WebKit - jQuery.merge( scripts, getAll( node, "script" ) ); - } - } - - callback.call( collection[ i ], node, i ); - } - - if ( hasScripts ) { - doc = scripts[ scripts.length - 1 ].ownerDocument; - - // Reenable scripts - jQuery.map( scripts, restoreScript ); - - // Evaluate executable scripts on first document insertion - for ( i = 0; i < hasScripts; i++ ) { - node = scripts[ i ]; - if ( rscriptType.test( node.type || "" ) && - !dataPriv.access( node, "globalEval" ) && - jQuery.contains( doc, node ) ) { - - if ( node.src && ( node.type || "" ).toLowerCase() !== "module" ) { - - // Optional AJAX dependency, but won't run scripts if not present - if ( jQuery._evalUrl ) { - jQuery._evalUrl( node.src ); - } - } else { - DOMEval( node.textContent.replace( rcleanScript, "" ), doc, node ); - } - } - } - } - } - } - - return collection; -} - -function remove( elem, selector, keepData ) { - var node, - nodes = selector ? jQuery.filter( selector, elem ) : elem, - i = 0; - - for ( ; ( node = nodes[ i ] ) != null; i++ ) { - if ( !keepData && node.nodeType === 1 ) { - jQuery.cleanData( getAll( node ) ); - } - - if ( node.parentNode ) { - if ( keepData && jQuery.contains( node.ownerDocument, node ) ) { - setGlobalEval( getAll( node, "script" ) ); - } - node.parentNode.removeChild( node ); - } - } - - return elem; -} - -jQuery.extend( { - htmlPrefilter: function( html ) { - return html.replace( rxhtmlTag, "<$1>" ); - }, - - clone: function( elem, dataAndEvents, deepDataAndEvents ) { - var i, l, srcElements, destElements, - clone = elem.cloneNode( true ), - inPage = jQuery.contains( elem.ownerDocument, elem ); - - // Fix IE cloning issues - if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) && - !jQuery.isXMLDoc( elem ) ) { - - // We eschew Sizzle here for performance reasons: https://jsperf.com/getall-vs-sizzle/2 - destElements = getAll( clone ); - srcElements = getAll( elem ); - - for ( i = 0, l = srcElements.length; i < l; i++ ) { - fixInput( srcElements[ i ], destElements[ i ] ); - } - } - - // Copy the events from the original to the clone - if ( dataAndEvents ) { - if ( deepDataAndEvents ) { - srcElements = srcElements || getAll( elem ); - destElements = destElements || getAll( clone ); - - for ( i = 0, l = srcElements.length; i < l; i++ ) { - cloneCopyEvent( srcElements[ i ], destElements[ i ] ); - } - } else { - cloneCopyEvent( elem, clone ); - } - } - - // Preserve script evaluation history - destElements = getAll( clone, "script" ); - if ( destElements.length > 0 ) { - setGlobalEval( destElements, !inPage && getAll( elem, "script" ) ); - } - - // Return the cloned set - return clone; - }, - - cleanData: function( elems ) { - var data, elem, type, - special = jQuery.event.special, - i = 0; - - for ( ; ( elem = elems[ i ] ) !== undefined; i++ ) { - if ( acceptData( elem ) ) { - if ( ( data = elem[ dataPriv.expando ] ) ) { - if ( data.events ) { - for ( type in data.events ) { - if ( special[ type ] ) { - jQuery.event.remove( elem, type ); - - // This is a shortcut to avoid jQuery.event.remove's overhead - } else { - jQuery.removeEvent( elem, type, data.handle ); - } - } - } - - // Support: Chrome <=35 - 45+ - // Assign undefined instead of using delete, see Data#remove - elem[ dataPriv.expando ] = undefined; - } - if ( elem[ dataUser.expando ] ) { - - // Support: Chrome <=35 - 45+ - // Assign undefined instead of using delete, see Data#remove - elem[ dataUser.expando ] = undefined; - } - } - } - } -} ); - -jQuery.fn.extend( { - detach: function( selector ) { - return remove( this, selector, true ); - }, - - remove: function( selector ) { - return remove( this, selector ); - }, - - text: function( value ) { - return access( this, function( value ) { - return value === undefined ? - jQuery.text( this ) : - this.empty().each( function() { - if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { - this.textContent = value; - } - } ); - }, null, value, arguments.length ); - }, - - append: function() { - return domManip( this, arguments, function( elem ) { - if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { - var target = manipulationTarget( this, elem ); - target.appendChild( elem ); - } - } ); - }, - - prepend: function() { - return domManip( this, arguments, function( elem ) { - if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { - var target = manipulationTarget( this, elem ); - target.insertBefore( elem, target.firstChild ); - } - } ); - }, - - before: function() { - return domManip( this, arguments, function( elem ) { - if ( this.parentNode ) { - this.parentNode.insertBefore( elem, this ); - } - } ); - }, - - after: function() { - return domManip( this, arguments, function( elem ) { - if ( this.parentNode ) { - this.parentNode.insertBefore( elem, this.nextSibling ); - } - } ); - }, - - empty: function() { - var elem, - i = 0; - - for ( ; ( elem = this[ i ] ) != null; i++ ) { - if ( elem.nodeType === 1 ) { - - // Prevent memory leaks - jQuery.cleanData( getAll( elem, false ) ); - - // Remove any remaining nodes - elem.textContent = ""; - } - } - - return this; - }, - - clone: function( dataAndEvents, deepDataAndEvents ) { - dataAndEvents = dataAndEvents == null ? false : dataAndEvents; - deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents; - - return this.map( function() { - return jQuery.clone( this, dataAndEvents, deepDataAndEvents ); - } ); - }, - - html: function( value ) { - return access( this, function( value ) { - var elem = this[ 0 ] || {}, - i = 0, - l = this.length; - - if ( value === undefined && elem.nodeType === 1 ) { - return elem.innerHTML; - } - - // See if we can take a shortcut and just use innerHTML - if ( typeof value === "string" && !rnoInnerhtml.test( value ) && - !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) { - - value = jQuery.htmlPrefilter( value ); - - try { - for ( ; i < l; i++ ) { - elem = this[ i ] || {}; - - // Remove element nodes and prevent memory leaks - if ( elem.nodeType === 1 ) { - jQuery.cleanData( getAll( elem, false ) ); - elem.innerHTML = value; - } - } - - elem = 0; - - // If using innerHTML throws an exception, use the fallback method - } catch ( e ) {} - } - - if ( elem ) { - this.empty().append( value ); - } - }, null, value, arguments.length ); - }, - - replaceWith: function() { - var ignored = []; - - // Make the changes, replacing each non-ignored context element with the new content - return domManip( this, arguments, function( elem ) { - var parent = this.parentNode; - - if ( jQuery.inArray( this, ignored ) < 0 ) { - jQuery.cleanData( getAll( this ) ); - if ( parent ) { - parent.replaceChild( elem, this ); - } - } - - // Force callback invocation - }, ignored ); - } -} ); - -jQuery.each( { - appendTo: "append", - prependTo: "prepend", - insertBefore: "before", - insertAfter: "after", - replaceAll: "replaceWith" -}, function( name, original ) { - jQuery.fn[ name ] = function( selector ) { - var elems, - ret = [], - insert = jQuery( selector ), - last = insert.length - 1, - i = 0; - - for ( ; i <= last; i++ ) { - elems = i === last ? this : this.clone( true ); - jQuery( insert[ i ] )[ original ]( elems ); - - // Support: Android <=4.0 only, PhantomJS 1 only - // .get() because push.apply(_, arraylike) throws on ancient WebKit - push.apply( ret, elems.get() ); - } - - return this.pushStack( ret ); - }; -} ); -var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" ); - -var getStyles = function( elem ) { - - // Support: IE <=11 only, Firefox <=30 (#15098, #14150) - // IE throws on elements created in popups - // FF meanwhile throws on frame elements through "defaultView.getComputedStyle" - var view = elem.ownerDocument.defaultView; - - if ( !view || !view.opener ) { - view = window; - } - - return view.getComputedStyle( elem ); - }; - -var rboxStyle = new RegExp( cssExpand.join( "|" ), "i" ); - - - -( function() { - - // Executing both pixelPosition & boxSizingReliable tests require only one layout - // so they're executed at the same time to save the second computation. - function computeStyleTests() { - - // This is a singleton, we need to execute it only once - if ( !div ) { - return; - } - - container.style.cssText = "position:absolute;left:-11111px;width:60px;" + - "margin-top:1px;padding:0;border:0"; - div.style.cssText = - "position:relative;display:block;box-sizing:border-box;overflow:scroll;" + - "margin:auto;border:1px;padding:1px;" + - "width:60%;top:1%"; - documentElement.appendChild( container ).appendChild( div ); - - var divStyle = window.getComputedStyle( div ); - pixelPositionVal = divStyle.top !== "1%"; - - // Support: Android 4.0 - 4.3 only, Firefox <=3 - 44 - reliableMarginLeftVal = roundPixelMeasures( divStyle.marginLeft ) === 12; - - // Support: Android 4.0 - 4.3 only, Safari <=9.1 - 10.1, iOS <=7.0 - 9.3 - // Some styles come back with percentage values, even though they shouldn't - div.style.right = "60%"; - pixelBoxStylesVal = roundPixelMeasures( divStyle.right ) === 36; - - // Support: IE 9 - 11 only - // Detect misreporting of content dimensions for box-sizing:border-box elements - boxSizingReliableVal = roundPixelMeasures( divStyle.width ) === 36; - - // Support: IE 9 only - // Detect overflow:scroll screwiness (gh-3699) - div.style.position = "absolute"; - scrollboxSizeVal = div.offsetWidth === 36 || "absolute"; - - documentElement.removeChild( container ); - - // Nullify the div so it wouldn't be stored in the memory and - // it will also be a sign that checks already performed - div = null; - } - - function roundPixelMeasures( measure ) { - return Math.round( parseFloat( measure ) ); - } - - var pixelPositionVal, boxSizingReliableVal, scrollboxSizeVal, pixelBoxStylesVal, - reliableMarginLeftVal, - container = document.createElement( "div" ), - div = document.createElement( "div" ); - - // Finish early in limited (non-browser) environments - if ( !div.style ) { - return; - } - - // Support: IE <=9 - 11 only - // Style of cloned element affects source element cloned (#8908) - div.style.backgroundClip = "content-box"; - div.cloneNode( true ).style.backgroundClip = ""; - support.clearCloneStyle = div.style.backgroundClip === "content-box"; - - jQuery.extend( support, { - boxSizingReliable: function() { - computeStyleTests(); - return boxSizingReliableVal; - }, - pixelBoxStyles: function() { - computeStyleTests(); - return pixelBoxStylesVal; - }, - pixelPosition: function() { - computeStyleTests(); - return pixelPositionVal; - }, - reliableMarginLeft: function() { - computeStyleTests(); - return reliableMarginLeftVal; - }, - scrollboxSize: function() { - computeStyleTests(); - return scrollboxSizeVal; - } - } ); -} )(); - - -function curCSS( elem, name, computed ) { - var width, minWidth, maxWidth, ret, - - // Support: Firefox 51+ - // Retrieving style before computed somehow - // fixes an issue with getting wrong values - // on detached elements - style = elem.style; - - computed = computed || getStyles( elem ); - - // getPropertyValue is needed for: - // .css('filter') (IE 9 only, #12537) - // .css('--customProperty) (#3144) - if ( computed ) { - ret = computed.getPropertyValue( name ) || computed[ name ]; - - if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) { - ret = jQuery.style( elem, name ); - } - - // A tribute to the "awesome hack by Dean Edwards" - // Android Browser returns percentage for some values, - // but width seems to be reliably pixels. - // This is against the CSSOM draft spec: - // https://drafts.csswg.org/cssom/#resolved-values - if ( !support.pixelBoxStyles() && rnumnonpx.test( ret ) && rboxStyle.test( name ) ) { - - // Remember the original values - width = style.width; - minWidth = style.minWidth; - maxWidth = style.maxWidth; - - // Put in the new values to get a computed value out - style.minWidth = style.maxWidth = style.width = ret; - ret = computed.width; - - // Revert the changed values - style.width = width; - style.minWidth = minWidth; - style.maxWidth = maxWidth; - } - } - - return ret !== undefined ? - - // Support: IE <=9 - 11 only - // IE returns zIndex value as an integer. - ret + "" : - ret; -} - - -function addGetHookIf( conditionFn, hookFn ) { - - // Define the hook, we'll check on the first run if it's really needed. - return { - get: function() { - if ( conditionFn() ) { - - // Hook not needed (or it's not possible to use it due - // to missing dependency), remove it. - delete this.get; - return; - } - - // Hook needed; redefine it so that the support test is not executed again. - return ( this.get = hookFn ).apply( this, arguments ); - } - }; -} - - -var - - // Swappable if display is none or starts with table - // except "table", "table-cell", or "table-caption" - // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display - rdisplayswap = /^(none|table(?!-c[ea]).+)/, - rcustomProp = /^--/, - cssShow = { position: "absolute", visibility: "hidden", display: "block" }, - cssNormalTransform = { - letterSpacing: "0", - fontWeight: "400" - }, - - cssPrefixes = [ "Webkit", "Moz", "ms" ], - emptyStyle = document.createElement( "div" ).style; - -// Return a css property mapped to a potentially vendor prefixed property -function vendorPropName( name ) { - - // Shortcut for names that are not vendor prefixed - if ( name in emptyStyle ) { - return name; - } - - // Check for vendor prefixed names - var capName = name[ 0 ].toUpperCase() + name.slice( 1 ), - i = cssPrefixes.length; - - while ( i-- ) { - name = cssPrefixes[ i ] + capName; - if ( name in emptyStyle ) { - return name; - } - } -} - -// Return a property mapped along what jQuery.cssProps suggests or to -// a vendor prefixed property. -function finalPropName( name ) { - var ret = jQuery.cssProps[ name ]; - if ( !ret ) { - ret = jQuery.cssProps[ name ] = vendorPropName( name ) || name; - } - return ret; -} - -function setPositiveNumber( elem, value, subtract ) { - - // Any relative (+/-) values have already been - // normalized at this point - var matches = rcssNum.exec( value ); - return matches ? - - // Guard against undefined "subtract", e.g., when used as in cssHooks - Math.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || "px" ) : - value; -} - -function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computedVal ) { - var i = dimension === "width" ? 1 : 0, - extra = 0, - delta = 0; - - // Adjustment may not be necessary - if ( box === ( isBorderBox ? "border" : "content" ) ) { - return 0; - } - - for ( ; i < 4; i += 2 ) { - - // Both box models exclude margin - if ( box === "margin" ) { - delta += jQuery.css( elem, box + cssExpand[ i ], true, styles ); - } - - // If we get here with a content-box, we're seeking "padding" or "border" or "margin" - if ( !isBorderBox ) { - - // Add padding - delta += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles ); - - // For "border" or "margin", add border - if ( box !== "padding" ) { - delta += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles ); - - // But still keep track of it otherwise - } else { - extra += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles ); - } - - // If we get here with a border-box (content + padding + border), we're seeking "content" or - // "padding" or "margin" - } else { - - // For "content", subtract padding - if ( box === "content" ) { - delta -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles ); - } - - // For "content" or "padding", subtract border - if ( box !== "margin" ) { - delta -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles ); - } - } - } - - // Account for positive content-box scroll gutter when requested by providing computedVal - if ( !isBorderBox && computedVal >= 0 ) { - - // offsetWidth/offsetHeight is a rounded sum of content, padding, scroll gutter, and border - // Assuming integer scroll gutter, subtract the rest and round down - delta += Math.max( 0, Math.ceil( - elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] - - computedVal - - delta - - extra - - 0.5 - ) ); - } - - return delta; -} - -function getWidthOrHeight( elem, dimension, extra ) { - - // Start with computed style - var styles = getStyles( elem ), - val = curCSS( elem, dimension, styles ), - isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box", - valueIsBorderBox = isBorderBox; - - // Support: Firefox <=54 - // Return a confounding non-pixel value or feign ignorance, as appropriate. - if ( rnumnonpx.test( val ) ) { - if ( !extra ) { - return val; - } - val = "auto"; - } - - // Check for style in case a browser which returns unreliable values - // for getComputedStyle silently falls back to the reliable elem.style - valueIsBorderBox = valueIsBorderBox && - ( support.boxSizingReliable() || val === elem.style[ dimension ] ); - - // Fall back to offsetWidth/offsetHeight when value is "auto" - // This happens for inline elements with no explicit setting (gh-3571) - // Support: Android <=4.1 - 4.3 only - // Also use offsetWidth/offsetHeight for misreported inline dimensions (gh-3602) - if ( val === "auto" || - !parseFloat( val ) && jQuery.css( elem, "display", false, styles ) === "inline" ) { - - val = elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ]; - - // offsetWidth/offsetHeight provide border-box values - valueIsBorderBox = true; - } - - // Normalize "" and auto - val = parseFloat( val ) || 0; - - // Adjust for the element's box model - return ( val + - boxModelAdjustment( - elem, - dimension, - extra || ( isBorderBox ? "border" : "content" ), - valueIsBorderBox, - styles, - - // Provide the current computed size to request scroll gutter calculation (gh-3589) - val - ) - ) + "px"; -} - -jQuery.extend( { - - // Add in style property hooks for overriding the default - // behavior of getting and setting a style property - cssHooks: { - opacity: { - get: function( elem, computed ) { - if ( computed ) { - - // We should always get a number back from opacity - var ret = curCSS( elem, "opacity" ); - return ret === "" ? "1" : ret; - } - } - } - }, - - // Don't automatically add "px" to these possibly-unitless properties - cssNumber: { - "animationIterationCount": true, - "columnCount": true, - "fillOpacity": true, - "flexGrow": true, - "flexShrink": true, - "fontWeight": true, - "lineHeight": true, - "opacity": true, - "order": true, - "orphans": true, - "widows": true, - "zIndex": true, - "zoom": true - }, - - // Add in properties whose names you wish to fix before - // setting or getting the value - cssProps: {}, - - // Get and set the style property on a DOM Node - style: function( elem, name, value, extra ) { - - // Don't set styles on text and comment nodes - if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) { - return; - } - - // Make sure that we're working with the right name - var ret, type, hooks, - origName = camelCase( name ), - isCustomProp = rcustomProp.test( name ), - style = elem.style; - - // Make sure that we're working with the right name. We don't - // want to query the value if it is a CSS custom property - // since they are user-defined. - if ( !isCustomProp ) { - name = finalPropName( origName ); - } - - // Gets hook for the prefixed version, then unprefixed version - hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ]; - - // Check if we're setting a value - if ( value !== undefined ) { - type = typeof value; - - // Convert "+=" or "-=" to relative numbers (#7345) - if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) { - value = adjustCSS( elem, name, ret ); - - // Fixes bug #9237 - type = "number"; - } - - // Make sure that null and NaN values aren't set (#7116) - if ( value == null || value !== value ) { - return; - } - - // If a number was passed in, add the unit (except for certain CSS properties) - if ( type === "number" ) { - value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" ); - } - - // background-* props affect original clone's values - if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) { - style[ name ] = "inherit"; - } - - // If a hook was provided, use that value, otherwise just set the specified value - if ( !hooks || !( "set" in hooks ) || - ( value = hooks.set( elem, value, extra ) ) !== undefined ) { - - if ( isCustomProp ) { - style.setProperty( name, value ); - } else { - style[ name ] = value; - } - } - - } else { - - // If a hook was provided get the non-computed value from there - if ( hooks && "get" in hooks && - ( ret = hooks.get( elem, false, extra ) ) !== undefined ) { - - return ret; - } - - // Otherwise just get the value from the style object - return style[ name ]; - } - }, - - css: function( elem, name, extra, styles ) { - var val, num, hooks, - origName = camelCase( name ), - isCustomProp = rcustomProp.test( name ); - - // Make sure that we're working with the right name. We don't - // want to modify the value if it is a CSS custom property - // since they are user-defined. - if ( !isCustomProp ) { - name = finalPropName( origName ); - } - - // Try prefixed name followed by the unprefixed name - hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ]; - - // If a hook was provided get the computed value from there - if ( hooks && "get" in hooks ) { - val = hooks.get( elem, true, extra ); - } - - // Otherwise, if a way to get the computed value exists, use that - if ( val === undefined ) { - val = curCSS( elem, name, styles ); - } - - // Convert "normal" to computed value - if ( val === "normal" && name in cssNormalTransform ) { - val = cssNormalTransform[ name ]; - } - - // Make numeric if forced or a qualifier was provided and val looks numeric - if ( extra === "" || extra ) { - num = parseFloat( val ); - return extra === true || isFinite( num ) ? num || 0 : val; - } - - return val; - } -} ); - -jQuery.each( [ "height", "width" ], function( i, dimension ) { - jQuery.cssHooks[ dimension ] = { - get: function( elem, computed, extra ) { - if ( computed ) { - - // Certain elements can have dimension info if we invisibly show them - // but it must have a current display style that would benefit - return rdisplayswap.test( jQuery.css( elem, "display" ) ) && - - // Support: Safari 8+ - // Table columns in Safari have non-zero offsetWidth & zero - // getBoundingClientRect().width unless display is changed. - // Support: IE <=11 only - // Running getBoundingClientRect on a disconnected node - // in IE throws an error. - ( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ? - swap( elem, cssShow, function() { - return getWidthOrHeight( elem, dimension, extra ); - } ) : - getWidthOrHeight( elem, dimension, extra ); - } - }, - - set: function( elem, value, extra ) { - var matches, - styles = getStyles( elem ), - isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box", - subtract = extra && boxModelAdjustment( - elem, - dimension, - extra, - isBorderBox, - styles - ); - - // Account for unreliable border-box dimensions by comparing offset* to computed and - // faking a content-box to get border and padding (gh-3699) - if ( isBorderBox && support.scrollboxSize() === styles.position ) { - subtract -= Math.ceil( - elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] - - parseFloat( styles[ dimension ] ) - - boxModelAdjustment( elem, dimension, "border", false, styles ) - - 0.5 - ); - } - - // Convert to pixels if value adjustment is needed - if ( subtract && ( matches = rcssNum.exec( value ) ) && - ( matches[ 3 ] || "px" ) !== "px" ) { - - elem.style[ dimension ] = value; - value = jQuery.css( elem, dimension ); - } - - return setPositiveNumber( elem, value, subtract ); - } - }; -} ); - -jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft, - function( elem, computed ) { - if ( computed ) { - return ( parseFloat( curCSS( elem, "marginLeft" ) ) || - elem.getBoundingClientRect().left - - swap( elem, { marginLeft: 0 }, function() { - return elem.getBoundingClientRect().left; - } ) - ) + "px"; - } - } -); - -// These hooks are used by animate to expand properties -jQuery.each( { - margin: "", - padding: "", - border: "Width" -}, function( prefix, suffix ) { - jQuery.cssHooks[ prefix + suffix ] = { - expand: function( value ) { - var i = 0, - expanded = {}, - - // Assumes a single number if not a string - parts = typeof value === "string" ? value.split( " " ) : [ value ]; - - for ( ; i < 4; i++ ) { - expanded[ prefix + cssExpand[ i ] + suffix ] = - parts[ i ] || parts[ i - 2 ] || parts[ 0 ]; - } - - return expanded; - } - }; - - if ( prefix !== "margin" ) { - jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber; - } -} ); - -jQuery.fn.extend( { - css: function( name, value ) { - return access( this, function( elem, name, value ) { - var styles, len, - map = {}, - i = 0; - - if ( Array.isArray( name ) ) { - styles = getStyles( elem ); - len = name.length; - - for ( ; i < len; i++ ) { - map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles ); - } - - return map; - } - - return value !== undefined ? - jQuery.style( elem, name, value ) : - jQuery.css( elem, name ); - }, name, value, arguments.length > 1 ); - } -} ); - - -// Based off of the plugin by Clint Helfers, with permission. -// https://web.archive.org/web/20100324014747/http://blindsignals.com/index.php/2009/07/jquery-delay/ -jQuery.fn.delay = function( time, type ) { - time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time; - type = type || "fx"; - - return this.queue( type, function( next, hooks ) { - var timeout = window.setTimeout( next, time ); - hooks.stop = function() { - window.clearTimeout( timeout ); - }; - } ); -}; - - -( function() { - var input = document.createElement( "input" ), - select = document.createElement( "select" ), - opt = select.appendChild( document.createElement( "option" ) ); - - input.type = "checkbox"; - - // Support: Android <=4.3 only - // Default value for a checkbox should be "on" - support.checkOn = input.value !== ""; - - // Support: IE <=11 only - // Must access selectedIndex to make default options select - support.optSelected = opt.selected; - - // Support: IE <=11 only - // An input loses its value after becoming a radio - input = document.createElement( "input" ); - input.value = "t"; - input.type = "radio"; - support.radioValue = input.value === "t"; -} )(); - - -var boolHook, - attrHandle = jQuery.expr.attrHandle; - -jQuery.fn.extend( { - attr: function( name, value ) { - return access( this, jQuery.attr, name, value, arguments.length > 1 ); - }, - - removeAttr: function( name ) { - return this.each( function() { - jQuery.removeAttr( this, name ); - } ); - } -} ); - -jQuery.extend( { - attr: function( elem, name, value ) { - var ret, hooks, - nType = elem.nodeType; - - // Don't get/set attributes on text, comment and attribute nodes - if ( nType === 3 || nType === 8 || nType === 2 ) { - return; - } - - // Fallback to prop when attributes are not supported - if ( typeof elem.getAttribute === "undefined" ) { - return jQuery.prop( elem, name, value ); - } - - // Attribute hooks are determined by the lowercase version - // Grab necessary hook if one is defined - if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) { - hooks = jQuery.attrHooks[ name.toLowerCase() ] || - ( jQuery.expr.match.bool.test( name ) ? boolHook : undefined ); - } - - if ( value !== undefined ) { - if ( value === null ) { - jQuery.removeAttr( elem, name ); - return; - } - - if ( hooks && "set" in hooks && - ( ret = hooks.set( elem, value, name ) ) !== undefined ) { - return ret; - } - - elem.setAttribute( name, value + "" ); - return value; - } - - if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) { - return ret; - } - - ret = jQuery.find.attr( elem, name ); - - // Non-existent attributes return null, we normalize to undefined - return ret == null ? undefined : ret; - }, - - attrHooks: { - type: { - set: function( elem, value ) { - if ( !support.radioValue && value === "radio" && - nodeName( elem, "input" ) ) { - var val = elem.value; - elem.setAttribute( "type", value ); - if ( val ) { - elem.value = val; - } - return value; - } - } - } - }, - - removeAttr: function( elem, value ) { - var name, - i = 0, - - // Attribute names can contain non-HTML whitespace characters - // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 - attrNames = value && value.match( rnothtmlwhite ); - - if ( attrNames && elem.nodeType === 1 ) { - while ( ( name = attrNames[ i++ ] ) ) { - elem.removeAttribute( name ); - } - } - } -} ); - -// Hooks for boolean attributes -boolHook = { - set: function( elem, value, name ) { - if ( value === false ) { - - // Remove boolean attributes when set to false - jQuery.removeAttr( elem, name ); - } else { - elem.setAttribute( name, name ); - } - return name; - } -}; - -jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) { - var getter = attrHandle[ name ] || jQuery.find.attr; - - attrHandle[ name ] = function( elem, name, isXML ) { - var ret, handle, - lowercaseName = name.toLowerCase(); - - if ( !isXML ) { - - // Avoid an infinite loop by temporarily removing this function from the getter - handle = attrHandle[ lowercaseName ]; - attrHandle[ lowercaseName ] = ret; - ret = getter( elem, name, isXML ) != null ? - lowercaseName : - null; - attrHandle[ lowercaseName ] = handle; - } - return ret; - }; -} ); - - - - -var rfocusable = /^(?:input|select|textarea|button)$/i, - rclickable = /^(?:a|area)$/i; - -jQuery.fn.extend( { - prop: function( name, value ) { - return access( this, jQuery.prop, name, value, arguments.length > 1 ); - }, - - removeProp: function( name ) { - return this.each( function() { - delete this[ jQuery.propFix[ name ] || name ]; - } ); - } -} ); - -jQuery.extend( { - prop: function( elem, name, value ) { - var ret, hooks, - nType = elem.nodeType; - - // Don't get/set properties on text, comment and attribute nodes - if ( nType === 3 || nType === 8 || nType === 2 ) { - return; - } - - if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) { - - // Fix name and attach hooks - name = jQuery.propFix[ name ] || name; - hooks = jQuery.propHooks[ name ]; - } - - if ( value !== undefined ) { - if ( hooks && "set" in hooks && - ( ret = hooks.set( elem, value, name ) ) !== undefined ) { - return ret; - } - - return ( elem[ name ] = value ); - } - - if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) { - return ret; - } - - return elem[ name ]; - }, - - propHooks: { - tabIndex: { - get: function( elem ) { - - // Support: IE <=9 - 11 only - // elem.tabIndex doesn't always return the - // correct value when it hasn't been explicitly set - // https://web.archive.org/web/20141116233347/http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ - // Use proper attribute retrieval(#12072) - var tabindex = jQuery.find.attr( elem, "tabindex" ); - - if ( tabindex ) { - return parseInt( tabindex, 10 ); - } - - if ( - rfocusable.test( elem.nodeName ) || - rclickable.test( elem.nodeName ) && - elem.href - ) { - return 0; - } - - return -1; - } - } - }, - - propFix: { - "for": "htmlFor", - "class": "className" - } -} ); - -// Support: IE <=11 only -// Accessing the selectedIndex property -// forces the browser to respect setting selected -// on the option -// The getter ensures a default option is selected -// when in an optgroup -// eslint rule "no-unused-expressions" is disabled for this code -// since it considers such accessions noop -if ( !support.optSelected ) { - jQuery.propHooks.selected = { - get: function( elem ) { - - /* eslint no-unused-expressions: "off" */ - - var parent = elem.parentNode; - if ( parent && parent.parentNode ) { - parent.parentNode.selectedIndex; - } - return null; - }, - set: function( elem ) { - - /* eslint no-unused-expressions: "off" */ - - var parent = elem.parentNode; - if ( parent ) { - parent.selectedIndex; - - if ( parent.parentNode ) { - parent.parentNode.selectedIndex; - } - } - } - }; -} - -jQuery.each( [ - "tabIndex", - "readOnly", - "maxLength", - "cellSpacing", - "cellPadding", - "rowSpan", - "colSpan", - "useMap", - "frameBorder", - "contentEditable" -], function() { - jQuery.propFix[ this.toLowerCase() ] = this; -} ); - - - - - // Strip and collapse whitespace according to HTML spec - // https://infra.spec.whatwg.org/#strip-and-collapse-ascii-whitespace - function stripAndCollapse( value ) { - var tokens = value.match( rnothtmlwhite ) || []; - return tokens.join( " " ); - } - - -function getClass( elem ) { - return elem.getAttribute && elem.getAttribute( "class" ) || ""; -} - -function classesToArray( value ) { - if ( Array.isArray( value ) ) { - return value; - } - if ( typeof value === "string" ) { - return value.match( rnothtmlwhite ) || []; - } - return []; -} - -jQuery.fn.extend( { - addClass: function( value ) { - var classes, elem, cur, curValue, clazz, j, finalValue, - i = 0; - - if ( isFunction( value ) ) { - return this.each( function( j ) { - jQuery( this ).addClass( value.call( this, j, getClass( this ) ) ); - } ); - } - - classes = classesToArray( value ); - - if ( classes.length ) { - while ( ( elem = this[ i++ ] ) ) { - curValue = getClass( elem ); - cur = elem.nodeType === 1 && ( " " + stripAndCollapse( curValue ) + " " ); - - if ( cur ) { - j = 0; - while ( ( clazz = classes[ j++ ] ) ) { - if ( cur.indexOf( " " + clazz + " " ) < 0 ) { - cur += clazz + " "; - } - } - - // Only assign if different to avoid unneeded rendering. - finalValue = stripAndCollapse( cur ); - if ( curValue !== finalValue ) { - elem.setAttribute( "class", finalValue ); - } - } - } - } - - return this; - }, - - removeClass: function( value ) { - var classes, elem, cur, curValue, clazz, j, finalValue, - i = 0; - - if ( isFunction( value ) ) { - return this.each( function( j ) { - jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) ); - } ); - } - - if ( !arguments.length ) { - return this.attr( "class", "" ); - } - - classes = classesToArray( value ); - - if ( classes.length ) { - while ( ( elem = this[ i++ ] ) ) { - curValue = getClass( elem ); - - // This expression is here for better compressibility (see addClass) - cur = elem.nodeType === 1 && ( " " + stripAndCollapse( curValue ) + " " ); - - if ( cur ) { - j = 0; - while ( ( clazz = classes[ j++ ] ) ) { - - // Remove *all* instances - while ( cur.indexOf( " " + clazz + " " ) > -1 ) { - cur = cur.replace( " " + clazz + " ", " " ); - } - } - - // Only assign if different to avoid unneeded rendering. - finalValue = stripAndCollapse( cur ); - if ( curValue !== finalValue ) { - elem.setAttribute( "class", finalValue ); - } - } - } - } - - return this; - }, - - toggleClass: function( value, stateVal ) { - var type = typeof value, - isValidValue = type === "string" || Array.isArray( value ); - - if ( typeof stateVal === "boolean" && isValidValue ) { - return stateVal ? this.addClass( value ) : this.removeClass( value ); - } - - if ( isFunction( value ) ) { - return this.each( function( i ) { - jQuery( this ).toggleClass( - value.call( this, i, getClass( this ), stateVal ), - stateVal - ); - } ); - } - - return this.each( function() { - var className, i, self, classNames; - - if ( isValidValue ) { - - // Toggle individual class names - i = 0; - self = jQuery( this ); - classNames = classesToArray( value ); - - while ( ( className = classNames[ i++ ] ) ) { - - // Check each className given, space separated list - if ( self.hasClass( className ) ) { - self.removeClass( className ); - } else { - self.addClass( className ); - } - } - - // Toggle whole class name - } else if ( value === undefined || type === "boolean" ) { - className = getClass( this ); - if ( className ) { - - // Store className if set - dataPriv.set( this, "__className__", className ); - } - - // If the element has a class name or if we're passed `false`, - // then remove the whole classname (if there was one, the above saved it). - // Otherwise bring back whatever was previously saved (if anything), - // falling back to the empty string if nothing was stored. - if ( this.setAttribute ) { - this.setAttribute( "class", - className || value === false ? - "" : - dataPriv.get( this, "__className__" ) || "" - ); - } - } - } ); - }, - - hasClass: function( selector ) { - var className, elem, - i = 0; - - className = " " + selector + " "; - while ( ( elem = this[ i++ ] ) ) { - if ( elem.nodeType === 1 && - ( " " + stripAndCollapse( getClass( elem ) ) + " " ).indexOf( className ) > -1 ) { - return true; - } - } - - return false; - } -} ); - - - - -var rreturn = /\r/g; - -jQuery.fn.extend( { - val: function( value ) { - var hooks, ret, valueIsFunction, - elem = this[ 0 ]; - - if ( !arguments.length ) { - if ( elem ) { - hooks = jQuery.valHooks[ elem.type ] || - jQuery.valHooks[ elem.nodeName.toLowerCase() ]; - - if ( hooks && - "get" in hooks && - ( ret = hooks.get( elem, "value" ) ) !== undefined - ) { - return ret; - } - - ret = elem.value; - - // Handle most common string cases - if ( typeof ret === "string" ) { - return ret.replace( rreturn, "" ); - } - - // Handle cases where value is null/undef or number - return ret == null ? "" : ret; - } - - return; - } - - valueIsFunction = isFunction( value ); - - return this.each( function( i ) { - var val; - - if ( this.nodeType !== 1 ) { - return; - } - - if ( valueIsFunction ) { - val = value.call( this, i, jQuery( this ).val() ); - } else { - val = value; - } - - // Treat null/undefined as ""; convert numbers to string - if ( val == null ) { - val = ""; - - } else if ( typeof val === "number" ) { - val += ""; - - } else if ( Array.isArray( val ) ) { - val = jQuery.map( val, function( value ) { - return value == null ? "" : value + ""; - } ); - } - - hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ]; - - // If set returns undefined, fall back to normal setting - if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) { - this.value = val; - } - } ); - } -} ); - -jQuery.extend( { - valHooks: { - option: { - get: function( elem ) { - - var val = jQuery.find.attr( elem, "value" ); - return val != null ? - val : - - // Support: IE <=10 - 11 only - // option.text throws exceptions (#14686, #14858) - // Strip and collapse whitespace - // https://html.spec.whatwg.org/#strip-and-collapse-whitespace - stripAndCollapse( jQuery.text( elem ) ); - } - }, - select: { - get: function( elem ) { - var value, option, i, - options = elem.options, - index = elem.selectedIndex, - one = elem.type === "select-one", - values = one ? null : [], - max = one ? index + 1 : options.length; - - if ( index < 0 ) { - i = max; - - } else { - i = one ? index : 0; - } - - // Loop through all the selected options - for ( ; i < max; i++ ) { - option = options[ i ]; - - // Support: IE <=9 only - // IE8-9 doesn't update selected after form reset (#2551) - if ( ( option.selected || i === index ) && - - // Don't return options that are disabled or in a disabled optgroup - !option.disabled && - ( !option.parentNode.disabled || - !nodeName( option.parentNode, "optgroup" ) ) ) { - - // Get the specific value for the option - value = jQuery( option ).val(); - - // We don't need an array for one selects - if ( one ) { - return value; - } - - // Multi-Selects return an array - values.push( value ); - } - } - - return values; - }, - - set: function( elem, value ) { - var optionSet, option, - options = elem.options, - values = jQuery.makeArray( value ), - i = options.length; - - while ( i-- ) { - option = options[ i ]; - - /* eslint-disable no-cond-assign */ - - if ( option.selected = - jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1 - ) { - optionSet = true; - } - - /* eslint-enable no-cond-assign */ - } - - // Force browsers to behave consistently when non-matching value is set - if ( !optionSet ) { - elem.selectedIndex = -1; - } - return values; - } - } - } -} ); - -// Radios and checkboxes getter/setter -jQuery.each( [ "radio", "checkbox" ], function() { - jQuery.valHooks[ this ] = { - set: function( elem, value ) { - if ( Array.isArray( value ) ) { - return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 ); - } - } - }; - if ( !support.checkOn ) { - jQuery.valHooks[ this ].get = function( elem ) { - return elem.getAttribute( "value" ) === null ? "on" : elem.value; - }; - } -} ); - - - - -// Return jQuery for attributes-only inclusion - - -support.focusin = "onfocusin" in window; - - -var rfocusMorph = /^(?:focusinfocus|focusoutblur)$/, - stopPropagationCallback = function( e ) { - e.stopPropagation(); - }; - -jQuery.extend( jQuery.event, { - - trigger: function( event, data, elem, onlyHandlers ) { - - var i, cur, tmp, bubbleType, ontype, handle, special, lastElement, - eventPath = [ elem || document ], - type = hasOwn.call( event, "type" ) ? event.type : event, - namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split( "." ) : []; - - cur = lastElement = tmp = elem = elem || document; - - // Don't do events on text and comment nodes - if ( elem.nodeType === 3 || elem.nodeType === 8 ) { - return; - } - - // focus/blur morphs to focusin/out; ensure we're not firing them right now - if ( rfocusMorph.test( type + jQuery.event.triggered ) ) { - return; - } - - if ( type.indexOf( "." ) > -1 ) { - - // Namespaced trigger; create a regexp to match event type in handle() - namespaces = type.split( "." ); - type = namespaces.shift(); - namespaces.sort(); - } - ontype = type.indexOf( ":" ) < 0 && "on" + type; - - // Caller can pass in a jQuery.Event object, Object, or just an event type string - event = event[ jQuery.expando ] ? - event : - new jQuery.Event( type, typeof event === "object" && event ); - - // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true) - event.isTrigger = onlyHandlers ? 2 : 3; - event.namespace = namespaces.join( "." ); - event.rnamespace = event.namespace ? - new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" ) : - null; - - // Clean up the event in case it is being reused - event.result = undefined; - if ( !event.target ) { - event.target = elem; - } - - // Clone any incoming data and prepend the event, creating the handler arg list - data = data == null ? - [ event ] : - jQuery.makeArray( data, [ event ] ); - - // Allow special events to draw outside the lines - special = jQuery.event.special[ type ] || {}; - if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) { - return; - } - - // Determine event propagation path in advance, per W3C events spec (#9951) - // Bubble up to document, then to window; watch for a global ownerDocument var (#9724) - if ( !onlyHandlers && !special.noBubble && !isWindow( elem ) ) { - - bubbleType = special.delegateType || type; - if ( !rfocusMorph.test( bubbleType + type ) ) { - cur = cur.parentNode; - } - for ( ; cur; cur = cur.parentNode ) { - eventPath.push( cur ); - tmp = cur; - } - - // Only add window if we got to document (e.g., not plain obj or detached DOM) - if ( tmp === ( elem.ownerDocument || document ) ) { - eventPath.push( tmp.defaultView || tmp.parentWindow || window ); - } - } - - // Fire handlers on the event path - i = 0; - while ( ( cur = eventPath[ i++ ] ) && !event.isPropagationStopped() ) { - lastElement = cur; - event.type = i > 1 ? - bubbleType : - special.bindType || type; - - // jQuery handler - handle = ( dataPriv.get( cur, "events" ) || {} )[ event.type ] && - dataPriv.get( cur, "handle" ); - if ( handle ) { - handle.apply( cur, data ); - } - - // Native handler - handle = ontype && cur[ ontype ]; - if ( handle && handle.apply && acceptData( cur ) ) { - event.result = handle.apply( cur, data ); - if ( event.result === false ) { - event.preventDefault(); - } - } - } - event.type = type; - - // If nobody prevented the default action, do it now - if ( !onlyHandlers && !event.isDefaultPrevented() ) { - - if ( ( !special._default || - special._default.apply( eventPath.pop(), data ) === false ) && - acceptData( elem ) ) { - - // Call a native DOM method on the target with the same name as the event. - // Don't do default actions on window, that's where global variables be (#6170) - if ( ontype && isFunction( elem[ type ] ) && !isWindow( elem ) ) { - - // Don't re-trigger an onFOO event when we call its FOO() method - tmp = elem[ ontype ]; - - if ( tmp ) { - elem[ ontype ] = null; - } - - // Prevent re-triggering of the same event, since we already bubbled it above - jQuery.event.triggered = type; - - if ( event.isPropagationStopped() ) { - lastElement.addEventListener( type, stopPropagationCallback ); - } - - elem[ type ](); - - if ( event.isPropagationStopped() ) { - lastElement.removeEventListener( type, stopPropagationCallback ); - } - - jQuery.event.triggered = undefined; - - if ( tmp ) { - elem[ ontype ] = tmp; - } - } - } - } - - return event.result; - }, - - // Piggyback on a donor event to simulate a different one - // Used only for `focus(in | out)` events - simulate: function( type, elem, event ) { - var e = jQuery.extend( - new jQuery.Event(), - event, - { - type: type, - isSimulated: true - } - ); - - jQuery.event.trigger( e, null, elem ); - } - -} ); - -jQuery.fn.extend( { - - trigger: function( type, data ) { - return this.each( function() { - jQuery.event.trigger( type, data, this ); - } ); - }, - triggerHandler: function( type, data ) { - var elem = this[ 0 ]; - if ( elem ) { - return jQuery.event.trigger( type, data, elem, true ); - } - } -} ); - - -// Support: Firefox <=44 -// Firefox doesn't have focus(in | out) events -// Related ticket - https://bugzilla.mozilla.org/show_bug.cgi?id=687787 -// -// Support: Chrome <=48 - 49, Safari <=9.0 - 9.1 -// focus(in | out) events fire after focus & blur events, -// which is spec violation - http://www.w3.org/TR/DOM-Level-3-Events/#events-focusevent-event-order -// Related ticket - https://bugs.chromium.org/p/chromium/issues/detail?id=449857 -if ( !support.focusin ) { - jQuery.each( { focus: "focusin", blur: "focusout" }, function( orig, fix ) { - - // Attach a single capturing handler on the document while someone wants focusin/focusout - var handler = function( event ) { - jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ) ); - }; - - jQuery.event.special[ fix ] = { - setup: function() { - var doc = this.ownerDocument || this, - attaches = dataPriv.access( doc, fix ); - - if ( !attaches ) { - doc.addEventListener( orig, handler, true ); - } - dataPriv.access( doc, fix, ( attaches || 0 ) + 1 ); - }, - teardown: function() { - var doc = this.ownerDocument || this, - attaches = dataPriv.access( doc, fix ) - 1; - - if ( !attaches ) { - doc.removeEventListener( orig, handler, true ); - dataPriv.remove( doc, fix ); - - } else { - dataPriv.access( doc, fix, attaches ); - } - } - }; - } ); -} - - -var - rbracket = /\[\]$/, - rCRLF = /\r?\n/g, - rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i, - rsubmittable = /^(?:input|select|textarea|keygen)/i; - -function buildParams( prefix, obj, traditional, add ) { - var name; - - if ( Array.isArray( obj ) ) { - - // Serialize array item. - jQuery.each( obj, function( i, v ) { - if ( traditional || rbracket.test( prefix ) ) { - - // Treat each array item as a scalar. - add( prefix, v ); - - } else { - - // Item is non-scalar (array or object), encode its numeric index. - buildParams( - prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]", - v, - traditional, - add - ); - } - } ); - - } else if ( !traditional && toType( obj ) === "object" ) { - - // Serialize object item. - for ( name in obj ) { - buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add ); - } - - } else { - - // Serialize scalar item. - add( prefix, obj ); - } -} - -// Serialize an array of form elements or a set of -// key/values into a query string -jQuery.param = function( a, traditional ) { - var prefix, - s = [], - add = function( key, valueOrFunction ) { - - // If value is a function, invoke it and use its return value - var value = isFunction( valueOrFunction ) ? - valueOrFunction() : - valueOrFunction; - - s[ s.length ] = encodeURIComponent( key ) + "=" + - encodeURIComponent( value == null ? "" : value ); - }; - - // If an array was passed in, assume that it is an array of form elements. - if ( Array.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) { - - // Serialize the form elements - jQuery.each( a, function() { - add( this.name, this.value ); - } ); - - } else { - - // If traditional, encode the "old" way (the way 1.3.2 or older - // did it), otherwise encode params recursively. - for ( prefix in a ) { - buildParams( prefix, a[ prefix ], traditional, add ); - } - } - - // Return the resulting serialization - return s.join( "&" ); -}; - -jQuery.fn.extend( { - serialize: function() { - return jQuery.param( this.serializeArray() ); - }, - serializeArray: function() { - return this.map( function() { - - // Can add propHook for "elements" to filter or add form elements - var elements = jQuery.prop( this, "elements" ); - return elements ? jQuery.makeArray( elements ) : this; - } ) - .filter( function() { - var type = this.type; - - // Use .is( ":disabled" ) so that fieldset[disabled] works - return this.name && !jQuery( this ).is( ":disabled" ) && - rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) && - ( this.checked || !rcheckableType.test( type ) ); - } ) - .map( function( i, elem ) { - var val = jQuery( this ).val(); - - if ( val == null ) { - return null; - } - - if ( Array.isArray( val ) ) { - return jQuery.map( val, function( val ) { - return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; - } ); - } - - return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; - } ).get(); - } -} ); - - -jQuery.fn.extend( { - wrapAll: function( html ) { - var wrap; - - if ( this[ 0 ] ) { - if ( isFunction( html ) ) { - html = html.call( this[ 0 ] ); - } - - // The elements to wrap the target around - wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true ); - - if ( this[ 0 ].parentNode ) { - wrap.insertBefore( this[ 0 ] ); - } - - wrap.map( function() { - var elem = this; - - while ( elem.firstElementChild ) { - elem = elem.firstElementChild; - } - - return elem; - } ).append( this ); - } - - return this; - }, - - wrapInner: function( html ) { - if ( isFunction( html ) ) { - return this.each( function( i ) { - jQuery( this ).wrapInner( html.call( this, i ) ); - } ); - } - - return this.each( function() { - var self = jQuery( this ), - contents = self.contents(); - - if ( contents.length ) { - contents.wrapAll( html ); - - } else { - self.append( html ); - } - } ); - }, - - wrap: function( html ) { - var htmlIsFunction = isFunction( html ); - - return this.each( function( i ) { - jQuery( this ).wrapAll( htmlIsFunction ? html.call( this, i ) : html ); - } ); - }, - - unwrap: function( selector ) { - this.parent( selector ).not( "body" ).each( function() { - jQuery( this ).replaceWith( this.childNodes ); - } ); - return this; - } -} ); - - -jQuery.expr.pseudos.hidden = function( elem ) { - return !jQuery.expr.pseudos.visible( elem ); -}; -jQuery.expr.pseudos.visible = function( elem ) { - return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length ); -}; - - - - -// Support: Safari 8 only -// In Safari 8 documents created via document.implementation.createHTMLDocument -// collapse sibling forms: the second one becomes a child of the first one. -// Because of that, this security measure has to be disabled in Safari 8. -// https://bugs.webkit.org/show_bug.cgi?id=137337 -support.createHTMLDocument = ( function() { - var body = document.implementation.createHTMLDocument( "" ).body; - body.innerHTML = "
"; - return body.childNodes.length === 2; -} )(); - - -// Argument "data" should be string of html -// context (optional): If specified, the fragment will be created in this context, -// defaults to document -// keepScripts (optional): If true, will include scripts passed in the html string -jQuery.parseHTML = function( data, context, keepScripts ) { - if ( typeof data !== "string" ) { - return []; - } - if ( typeof context === "boolean" ) { - keepScripts = context; - context = false; - } - - var base, parsed, scripts; - - if ( !context ) { - - // Stop scripts or inline event handlers from being executed immediately - // by using document.implementation - if ( support.createHTMLDocument ) { - context = document.implementation.createHTMLDocument( "" ); - - // Set the base href for the created document - // so any parsed elements with URLs - // are based on the document's URL (gh-2965) - base = context.createElement( "base" ); - base.href = document.location.href; - context.head.appendChild( base ); - } else { - context = document; - } - } - - parsed = rsingleTag.exec( data ); - scripts = !keepScripts && []; - - // Single tag - if ( parsed ) { - return [ context.createElement( parsed[ 1 ] ) ]; - } - - parsed = buildFragment( [ data ], context, scripts ); - - if ( scripts && scripts.length ) { - jQuery( scripts ).remove(); - } - - return jQuery.merge( [], parsed.childNodes ); -}; - - -jQuery.offset = { - setOffset: function( elem, options, i ) { - var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition, - position = jQuery.css( elem, "position" ), - curElem = jQuery( elem ), - props = {}; - - // Set position first, in-case top/left are set even on static elem - if ( position === "static" ) { - elem.style.position = "relative"; - } - - curOffset = curElem.offset(); - curCSSTop = jQuery.css( elem, "top" ); - curCSSLeft = jQuery.css( elem, "left" ); - calculatePosition = ( position === "absolute" || position === "fixed" ) && - ( curCSSTop + curCSSLeft ).indexOf( "auto" ) > -1; - - // Need to be able to calculate position if either - // top or left is auto and position is either absolute or fixed - if ( calculatePosition ) { - curPosition = curElem.position(); - curTop = curPosition.top; - curLeft = curPosition.left; - - } else { - curTop = parseFloat( curCSSTop ) || 0; - curLeft = parseFloat( curCSSLeft ) || 0; - } - - if ( isFunction( options ) ) { - - // Use jQuery.extend here to allow modification of coordinates argument (gh-1848) - options = options.call( elem, i, jQuery.extend( {}, curOffset ) ); - } - - if ( options.top != null ) { - props.top = ( options.top - curOffset.top ) + curTop; - } - if ( options.left != null ) { - props.left = ( options.left - curOffset.left ) + curLeft; - } - - if ( "using" in options ) { - options.using.call( elem, props ); - - } else { - curElem.css( props ); - } - } -}; - -jQuery.fn.extend( { - - // offset() relates an element's border box to the document origin - offset: function( options ) { - - // Preserve chaining for setter - if ( arguments.length ) { - return options === undefined ? - this : - this.each( function( i ) { - jQuery.offset.setOffset( this, options, i ); - } ); - } - - var rect, win, - elem = this[ 0 ]; - - if ( !elem ) { - return; - } - - // Return zeros for disconnected and hidden (display: none) elements (gh-2310) - // Support: IE <=11 only - // Running getBoundingClientRect on a - // disconnected node in IE throws an error - if ( !elem.getClientRects().length ) { - return { top: 0, left: 0 }; - } - - // Get document-relative position by adding viewport scroll to viewport-relative gBCR - rect = elem.getBoundingClientRect(); - win = elem.ownerDocument.defaultView; - return { - top: rect.top + win.pageYOffset, - left: rect.left + win.pageXOffset - }; - }, - - // position() relates an element's margin box to its offset parent's padding box - // This corresponds to the behavior of CSS absolute positioning - position: function() { - if ( !this[ 0 ] ) { - return; - } - - var offsetParent, offset, doc, - elem = this[ 0 ], - parentOffset = { top: 0, left: 0 }; - - // position:fixed elements are offset from the viewport, which itself always has zero offset - if ( jQuery.css( elem, "position" ) === "fixed" ) { - - // Assume position:fixed implies availability of getBoundingClientRect - offset = elem.getBoundingClientRect(); - - } else { - offset = this.offset(); - - // Account for the *real* offset parent, which can be the document or its root element - // when a statically positioned element is identified - doc = elem.ownerDocument; - offsetParent = elem.offsetParent || doc.documentElement; - while ( offsetParent && - ( offsetParent === doc.body || offsetParent === doc.documentElement ) && - jQuery.css( offsetParent, "position" ) === "static" ) { - - offsetParent = offsetParent.parentNode; - } - if ( offsetParent && offsetParent !== elem && offsetParent.nodeType === 1 ) { - - // Incorporate borders into its offset, since they are outside its content origin - parentOffset = jQuery( offsetParent ).offset(); - parentOffset.top += jQuery.css( offsetParent, "borderTopWidth", true ); - parentOffset.left += jQuery.css( offsetParent, "borderLeftWidth", true ); - } - } - - // Subtract parent offsets and element margins - return { - top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ), - left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true ) - }; - }, - - // This method will return documentElement in the following cases: - // 1) For the element inside the iframe without offsetParent, this method will return - // documentElement of the parent window - // 2) For the hidden or detached element - // 3) For body or html element, i.e. in case of the html node - it will return itself - // - // but those exceptions were never presented as a real life use-cases - // and might be considered as more preferable results. - // - // This logic, however, is not guaranteed and can change at any point in the future - offsetParent: function() { - return this.map( function() { - var offsetParent = this.offsetParent; - - while ( offsetParent && jQuery.css( offsetParent, "position" ) === "static" ) { - offsetParent = offsetParent.offsetParent; - } - - return offsetParent || documentElement; - } ); - } -} ); - -// Create scrollLeft and scrollTop methods -jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) { - var top = "pageYOffset" === prop; - - jQuery.fn[ method ] = function( val ) { - return access( this, function( elem, method, val ) { - - // Coalesce documents and windows - var win; - if ( isWindow( elem ) ) { - win = elem; - } else if ( elem.nodeType === 9 ) { - win = elem.defaultView; - } - - if ( val === undefined ) { - return win ? win[ prop ] : elem[ method ]; - } - - if ( win ) { - win.scrollTo( - !top ? val : win.pageXOffset, - top ? val : win.pageYOffset - ); - - } else { - elem[ method ] = val; - } - }, method, val, arguments.length ); - }; -} ); - -// Support: Safari <=7 - 9.1, Chrome <=37 - 49 -// Add the top/left cssHooks using jQuery.fn.position -// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084 -// Blink bug: https://bugs.chromium.org/p/chromium/issues/detail?id=589347 -// getComputedStyle returns percent when specified for top/left/bottom/right; -// rather than make the css module depend on the offset module, just check for it here -jQuery.each( [ "top", "left" ], function( i, prop ) { - jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition, - function( elem, computed ) { - if ( computed ) { - computed = curCSS( elem, prop ); - - // If curCSS returns percentage, fallback to offset - return rnumnonpx.test( computed ) ? - jQuery( elem ).position()[ prop ] + "px" : - computed; - } - } - ); -} ); - - -// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods -jQuery.each( { Height: "height", Width: "width" }, function( name, type ) { - jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, - function( defaultExtra, funcName ) { - - // Margin is only for outerHeight, outerWidth - jQuery.fn[ funcName ] = function( margin, value ) { - var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ), - extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" ); - - return access( this, function( elem, type, value ) { - var doc; - - if ( isWindow( elem ) ) { - - // $( window ).outerWidth/Height return w/h including scrollbars (gh-1729) - return funcName.indexOf( "outer" ) === 0 ? - elem[ "inner" + name ] : - elem.document.documentElement[ "client" + name ]; - } - - // Get document width or height - if ( elem.nodeType === 9 ) { - doc = elem.documentElement; - - // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height], - // whichever is greatest - return Math.max( - elem.body[ "scroll" + name ], doc[ "scroll" + name ], - elem.body[ "offset" + name ], doc[ "offset" + name ], - doc[ "client" + name ] - ); - } - - return value === undefined ? - - // Get width or height on the element, requesting but not forcing parseFloat - jQuery.css( elem, type, extra ) : - - // Set width or height on the element - jQuery.style( elem, type, value, extra ); - }, type, chainable ? margin : undefined, chainable ); - }; - } ); -} ); - - -jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " + - "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + - "change select submit keydown keypress keyup contextmenu" ).split( " " ), - function( i, name ) { - - // Handle event binding - jQuery.fn[ name ] = function( data, fn ) { - return arguments.length > 0 ? - this.on( name, null, data, fn ) : - this.trigger( name ); - }; -} ); - -jQuery.fn.extend( { - hover: function( fnOver, fnOut ) { - return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); - } -} ); - - - - -jQuery.fn.extend( { - - bind: function( types, data, fn ) { - return this.on( types, null, data, fn ); - }, - unbind: function( types, fn ) { - return this.off( types, null, fn ); - }, - - delegate: function( selector, types, data, fn ) { - return this.on( types, selector, data, fn ); - }, - undelegate: function( selector, types, fn ) { - - // ( namespace ) or ( selector, types [, fn] ) - return arguments.length === 1 ? - this.off( selector, "**" ) : - this.off( types, selector || "**", fn ); - } -} ); - -// Bind a function to a context, optionally partially applying any -// arguments. -// jQuery.proxy is deprecated to promote standards (specifically Function#bind) -// However, it is not slated for removal any time soon -jQuery.proxy = function( fn, context ) { - var tmp, args, proxy; - - if ( typeof context === "string" ) { - tmp = fn[ context ]; - context = fn; - fn = tmp; - } - - // Quick check to determine if target is callable, in the spec - // this throws a TypeError, but we will just return undefined. - if ( !isFunction( fn ) ) { - return undefined; - } - - // Simulated bind - args = slice.call( arguments, 2 ); - proxy = function() { - return fn.apply( context || this, args.concat( slice.call( arguments ) ) ); - }; - - // Set the guid of unique handler to the same of original handler, so it can be removed - proxy.guid = fn.guid = fn.guid || jQuery.guid++; - - return proxy; -}; - -jQuery.holdReady = function( hold ) { - if ( hold ) { - jQuery.readyWait++; - } else { - jQuery.ready( true ); - } -}; -jQuery.isArray = Array.isArray; -jQuery.parseJSON = JSON.parse; -jQuery.nodeName = nodeName; -jQuery.isFunction = isFunction; -jQuery.isWindow = isWindow; -jQuery.camelCase = camelCase; -jQuery.type = toType; - -jQuery.now = Date.now; - -jQuery.isNumeric = function( obj ) { - - // As of jQuery 3.0, isNumeric is limited to - // strings and numbers (primitives or objects) - // that can be coerced to finite numbers (gh-2662) - var type = jQuery.type( obj ); - return ( type === "number" || type === "string" ) && - - // parseFloat NaNs numeric-cast false positives ("") - // ...but misinterprets leading-number strings, particularly hex literals ("0x...") - // subtraction forces infinities to NaN - !isNaN( obj - parseFloat( obj ) ); -}; - - - - - /* - // Register as a named AMD module, since jQuery can be concatenated with other - // files that may use define, but not via a proper concatenation script that - // understands anonymous AMD modules. A named AMD is safest and most robust - // way to register. Lowercase jquery is used because AMD module names are - // derived from file names, and jQuery is normally delivered in a lowercase - // file name. Do this after creating the global so that if an AMD module wants - // to call noConflict to hide this version of jQuery, it will work. - - // Note that for maximum portability, libraries that are not jQuery should - // declare themselves as anonymous modules, and avoid setting a global if an - // AMD loader is present. jQuery is a special case. For more information, see - // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon - - if (typeof define === "function" && define.amd) { - define("jquery", [], function () { - return jQuery; - }); - } - - - var - - // Map over jQuery in case of overwrite - _jQuery = window.jQuery, - - // Map over the $ in case of overwrite - _$ = window.$; - - jQuery.noConflict = function (deep) { - if (window.$ === jQuery) { - window.$ = _$; - } - - if (deep && window.jQuery === jQuery) { - window.jQuery = _jQuery; - } - - return jQuery; - }; - - // Expose jQuery and $ identifiers, even in - // AMD (#7102#comment:10, https://github.com/jquery/jquery/pull/557) - // and CommonJS for browser emulators (#13566) - if (!noGlobal) { - window.jQuery = window.$ = jQuery; - } - */ - - return jQuery; -})); -// Underscore.js 1.8.3 -// http://underscorejs.org -// (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors -// Underscore may be freely distributed under the MIT license. - -// Modified for encapsulation in igv module -// * no exports -// * no global definition -// * noConflict not supported (as _ is encapsulated its not needed) - - -// Create a safe reference to the Underscore object for use below. -var _ = function (obj) { - if (obj instanceof _) return obj; - if (!(this instanceof _)) return new _(obj); - this._wrapped = obj; -}; - -(function () { - - // Baseline setup - // -------------- - - - // Save bytes in the minified (but not gzipped) version: - var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype; - - // Create quick reference variables for speed access to core prototypes. - var - push = ArrayProto.push, - slice = ArrayProto.slice, - toString = ObjProto.toString, - hasOwnProperty = ObjProto.hasOwnProperty; - - // All **ECMAScript 5** native function implementations that we hope to use - // are declared here. - var - nativeIsArray = Array.isArray, - nativeKeys = Object.keys, - nativeBind = FuncProto.bind, - nativeCreate = Object.create; - - // Naked function reference for surrogate-prototype-swapping. - var Ctor = function () { - }; - - - // Current version. - _.VERSION = '1.8.3'; - - // Internal function that returns an efficient (for current engines) version - // of the passed-in callback, to be repeatedly applied in other Underscore - // functions. - var optimizeCb = function (func, context, argCount) { - if (context === void 0) return func; - switch (argCount == null ? 3 : argCount) { - case 1: - return function (value) { - return func.call(context, value); - }; - case 2: - return function (value, other) { - return func.call(context, value, other); - }; - case 3: - return function (value, index, collection) { - return func.call(context, value, index, collection); - }; - case 4: - return function (accumulator, value, index, collection) { - return func.call(context, accumulator, value, index, collection); - }; - } - return function () { - return func.apply(context, arguments); - }; - }; - - // A mostly-internal function to generate callbacks that can be applied - // to each element in a collection, returning the desired result — either - // identity, an arbitrary callback, a property matcher, or a property accessor. - var cb = function (value, context, argCount) { - if (value == null) return _.identity; - if (_.isFunction(value)) return optimizeCb(value, context, argCount); - if (_.isObject(value)) return _.matcher(value); - return _.property(value); - }; - _.iteratee = function (value, context) { - return cb(value, context, Infinity); - }; - - // An internal function for creating assigner functions. - var createAssigner = function (keysFunc, undefinedOnly) { - return function (obj) { - var length = arguments.length; - if (length < 2 || obj == null) return obj; - for (var index = 1; index < length; index++) { - var source = arguments[index], - keys = keysFunc(source), - l = keys.length; - for (var i = 0; i < l; i++) { - var key = keys[i]; - if (!undefinedOnly || obj[key] === void 0) obj[key] = source[key]; - } - } - return obj; - }; - }; - - // An internal function for creating a new object that inherits from another. - var baseCreate = function (prototype) { - if (!_.isObject(prototype)) return {}; - if (nativeCreate) return nativeCreate(prototype); - Ctor.prototype = prototype; - var result = new Ctor; - Ctor.prototype = null; - return result; - }; - - var property = function (key) { - return function (obj) { - return obj == null ? void 0 : obj[key]; - }; - }; - - // Helper for collection methods to determine whether a collection - // should be iterated as an array or as an object - // Related: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength - // Avoids a very nasty iOS 8 JIT bug on ARM-64. #2094 - var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1; - var getLength = property('length'); - var isArrayLike = function (collection) { - var length = getLength(collection); - return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX; - }; - - // Collection Functions - // -------------------- - - // The cornerstone, an `each` implementation, aka `forEach`. - // Handles raw objects in addition to array-likes. Treats all - // sparse array-likes as if they were dense. - _.each = _.forEach = function (obj, iteratee, context) { - iteratee = optimizeCb(iteratee, context); - var i, length; - if (isArrayLike(obj)) { - for (i = 0, length = obj.length; i < length; i++) { - iteratee(obj[i], i, obj); - } - } else { - var keys = _.keys(obj); - for (i = 0, length = keys.length; i < length; i++) { - iteratee(obj[keys[i]], keys[i], obj); - } - } - return obj; - }; - - // Return the results of applying the iteratee to each element. - _.map = _.collect = function (obj, iteratee, context) { - iteratee = cb(iteratee, context); - var keys = !isArrayLike(obj) && _.keys(obj), - length = (keys || obj).length, - results = Array(length); - for (var index = 0; index < length; index++) { - var currentKey = keys ? keys[index] : index; - results[index] = iteratee(obj[currentKey], currentKey, obj); - } - return results; - }; - - // Create a reducing function iterating left or right. - function createReduce(dir) { - // Optimized iterator function as using arguments.length - // in the main function will deoptimize the, see #1991. - function iterator(obj, iteratee, memo, keys, index, length) { - for (; index >= 0 && index < length; index += dir) { - var currentKey = keys ? keys[index] : index; - memo = iteratee(memo, obj[currentKey], currentKey, obj); - } - return memo; - } - - return function (obj, iteratee, memo, context) { - iteratee = optimizeCb(iteratee, context, 4); - var keys = !isArrayLike(obj) && _.keys(obj), - length = (keys || obj).length, - index = dir > 0 ? 0 : length - 1; - // Determine the initial value if none is provided. - if (arguments.length < 3) { - memo = obj[keys ? keys[index] : index]; - index += dir; - } - return iterator(obj, iteratee, memo, keys, index, length); - }; - } - - // **Reduce** builds up a single result from a list of values, aka `inject`, - // or `foldl`. - _.reduce = _.foldl = _.inject = createReduce(1); - - // The right-associative version of reduce, also known as `foldr`. - _.reduceRight = _.foldr = createReduce(-1); - - // Return the first value which passes a truth test. Aliased as `detect`. - _.find = _.detect = function (obj, predicate, context) { - var key; - if (isArrayLike(obj)) { - key = _.findIndex(obj, predicate, context); - } else { - key = _.findKey(obj, predicate, context); - } - if (key !== void 0 && key !== -1) return obj[key]; - }; - - // Return all the elements that pass a truth test. - // Aliased as `select`. - _.filter = _.select = function (obj, predicate, context) { - var results = []; - predicate = cb(predicate, context); - _.each(obj, function (value, index, list) { - if (predicate(value, index, list)) results.push(value); - }); - return results; - }; - - // Return all the elements for which a truth test fails. - _.reject = function (obj, predicate, context) { - return _.filter(obj, _.negate(cb(predicate)), context); - }; - - // Determine whether all of the elements match a truth test. - // Aliased as `all`. - _.every = _.all = function (obj, predicate, context) { - predicate = cb(predicate, context); - var keys = !isArrayLike(obj) && _.keys(obj), - length = (keys || obj).length; - for (var index = 0; index < length; index++) { - var currentKey = keys ? keys[index] : index; - if (!predicate(obj[currentKey], currentKey, obj)) return false; - } - return true; - }; - - // Determine if at least one element in the object matches a truth test. - // Aliased as `any`. - _.some = _.any = function (obj, predicate, context) { - predicate = cb(predicate, context); - var keys = !isArrayLike(obj) && _.keys(obj), - length = (keys || obj).length; - for (var index = 0; index < length; index++) { - var currentKey = keys ? keys[index] : index; - if (predicate(obj[currentKey], currentKey, obj)) return true; - } - return false; - }; - - // Determine if the array or object contains a given item (using `===`). - // Aliased as `includes` and `include`. - _.contains = _.includes = _.include = function (obj, item, fromIndex, guard) { - if (!isArrayLike(obj)) obj = _.values(obj); - if (typeof fromIndex != 'number' || guard) fromIndex = 0; - return _.indexOf(obj, item, fromIndex) >= 0; - }; - - // Invoke a method (with arguments) on every item in a collection. - _.invoke = function (obj, method) { - var args = slice.call(arguments, 2); - var isFunc = _.isFunction(method); - return _.map(obj, function (value) { - var func = isFunc ? method : value[method]; - return func == null ? func : func.apply(value, args); - }); - }; - - // Convenience version of a common use case of `map`: fetching a property. - _.pluck = function (obj, key) { - return _.map(obj, _.property(key)); - }; - - // Convenience version of a common use case of `filter`: selecting only objects - // containing specific `key:value` pairs. - _.where = function (obj, attrs) { - return _.filter(obj, _.matcher(attrs)); - }; - - // Convenience version of a common use case of `find`: getting the first object - // containing specific `key:value` pairs. - _.findWhere = function (obj, attrs) { - return _.find(obj, _.matcher(attrs)); - }; - - // Return the maximum element (or element-based computation). - _.max = function (obj, iteratee, context) { - var result = -Infinity, lastComputed = -Infinity, - value, computed; - if (iteratee == null && obj != null) { - obj = isArrayLike(obj) ? obj : _.values(obj); - for (var i = 0, length = obj.length; i < length; i++) { - value = obj[i]; - if (value > result) { - result = value; - } - } - } else { - iteratee = cb(iteratee, context); - _.each(obj, function (value, index, list) { - computed = iteratee(value, index, list); - if (computed > lastComputed || computed === -Infinity && result === -Infinity) { - result = value; - lastComputed = computed; - } - }); - } - return result; - }; - - // Return the minimum element (or element-based computation). - _.min = function (obj, iteratee, context) { - var result = Infinity, lastComputed = Infinity, - value, computed; - if (iteratee == null && obj != null) { - obj = isArrayLike(obj) ? obj : _.values(obj); - for (var i = 0, length = obj.length; i < length; i++) { - value = obj[i]; - if (value < result) { - result = value; - } - } - } else { - iteratee = cb(iteratee, context); - _.each(obj, function (value, index, list) { - computed = iteratee(value, index, list); - if (computed < lastComputed || computed === Infinity && result === Infinity) { - result = value; - lastComputed = computed; - } - }); - } - return result; - }; - - // Shuffle a collection, using the modern version of the - // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle). - _.shuffle = function (obj) { - var set = isArrayLike(obj) ? obj : _.values(obj); - var length = set.length; - var shuffled = Array(length); - for (var index = 0, rand; index < length; index++) { - rand = _.random(0, index); - if (rand !== index) shuffled[index] = shuffled[rand]; - shuffled[rand] = set[index]; - } - return shuffled; - }; - - // Sample **n** random values from a collection. - // If **n** is not specified, returns a single random element. - // The internal `guard` argument allows it to work with `map`. - _.sample = function (obj, n, guard) { - if (n == null || guard) { - if (!isArrayLike(obj)) obj = _.values(obj); - return obj[_.random(obj.length - 1)]; - } - return _.shuffle(obj).slice(0, Math.max(0, n)); - }; - - // Sort the object's values by a criterion produced by an iteratee. - _.sortBy = function (obj, iteratee, context) { - iteratee = cb(iteratee, context); - return _.pluck(_.map(obj, function (value, index, list) { - return { - value: value, - index: index, - criteria: iteratee(value, index, list) - }; - }).sort(function (left, right) { - var a = left.criteria; - var b = right.criteria; - if (a !== b) { - if (a > b || a === void 0) return 1; - if (a < b || b === void 0) return -1; - } - return left.index - right.index; - }), 'value'); - }; - - // An internal function used for aggregate "group by" operations. - var group = function (behavior) { - return function (obj, iteratee, context) { - var result = {}; - iteratee = cb(iteratee, context); - _.each(obj, function (value, index) { - var key = iteratee(value, index, obj); - behavior(result, value, key); - }); - return result; - }; - }; - - // Groups the object's values by a criterion. Pass either a string attribute - // to group by, or a function that returns the criterion. - _.groupBy = group(function (result, value, key) { - if (_.has(result, key)) result[key].push(value); else result[key] = [value]; - }); - - // Indexes the object's values by a criterion, similar to `groupBy`, but for - // when you know that your index values will be unique. - _.indexBy = group(function (result, value, key) { - result[key] = value; - }); - - // Counts instances of an object that group by a certain criterion. Pass - // either a string attribute to count by, or a function that returns the - // criterion. - _.countBy = group(function (result, value, key) { - if (_.has(result, key)) result[key]++; else result[key] = 1; - }); - - // Safely create a real, live array from anything iterable. - _.toArray = function (obj) { - if (!obj) return []; - if (_.isArray(obj)) return slice.call(obj); - if (isArrayLike(obj)) return _.map(obj, _.identity); - return _.values(obj); - }; - - // Return the number of elements in an object. - _.size = function (obj) { - if (obj == null) return 0; - return isArrayLike(obj) ? obj.length : _.keys(obj).length; - }; - - // Split a collection into two arrays: one whose elements all satisfy the given - // predicate, and one whose elements all do not satisfy the predicate. - _.partition = function (obj, predicate, context) { - predicate = cb(predicate, context); - var pass = [], fail = []; - _.each(obj, function (value, key, obj) { - (predicate(value, key, obj) ? pass : fail).push(value); - }); - return [pass, fail]; - }; - - // Array Functions - // --------------- - - // Get the first element of an array. Passing **n** will return the first N - // values in the array. Aliased as `head` and `take`. The **guard** check - // allows it to work with `_.map`. - _.first = _.head = _.take = function (array, n, guard) { - if (array == null) return void 0; - if (n == null || guard) return array[0]; - return _.initial(array, array.length - n); - }; - - // Returns everything but the last entry of the array. Especially useful on - // the arguments object. Passing **n** will return all the values in - // the array, excluding the last N. - _.initial = function (array, n, guard) { - return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n))); - }; - - // Get the last element of an array. Passing **n** will return the last N - // values in the array. - _.last = function (array, n, guard) { - if (array == null) return void 0; - if (n == null || guard) return array[array.length - 1]; - return _.rest(array, Math.max(0, array.length - n)); - }; - - // Returns everything but the first entry of the array. Aliased as `tail` and `drop`. - // Especially useful on the arguments object. Passing an **n** will return - // the rest N values in the array. - _.rest = _.tail = _.drop = function (array, n, guard) { - return slice.call(array, n == null || guard ? 1 : n); - }; - - // Trim out all falsy values from an array. - _.compact = function (array) { - return _.filter(array, _.identity); - }; - - // Internal implementation of a recursive `flatten` function. - var flatten = function (input, shallow, strict, startIndex) { - var output = [], idx = 0; - for (var i = startIndex || 0, length = getLength(input); i < length; i++) { - var value = input[i]; - if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) { - //flatten current level of array or arguments object - if (!shallow) value = flatten(value, shallow, strict); - var j = 0, len = value.length; - output.length += len; - while (j < len) { - output[idx++] = value[j++]; - } - } else if (!strict) { - output[idx++] = value; - } - } - return output; - }; - - // Flatten out an array, either recursively (by default), or just one level. - _.flatten = function (array, shallow) { - return flatten(array, shallow, false); - }; - - // Return a version of the array that does not contain the specified value(s). - _.without = function (array) { - return _.difference(array, slice.call(arguments, 1)); - }; - - // Produce a duplicate-free version of the array. If the array has already - // been sorted, you have the option of using a faster algorithm. - // Aliased as `unique`. - _.uniq = _.unique = function (array, isSorted, iteratee, context) { - if (!_.isBoolean(isSorted)) { - context = iteratee; - iteratee = isSorted; - isSorted = false; - } - if (iteratee != null) iteratee = cb(iteratee, context); - var result = []; - var seen = []; - for (var i = 0, length = getLength(array); i < length; i++) { - var value = array[i], - computed = iteratee ? iteratee(value, i, array) : value; - if (isSorted) { - if (!i || seen !== computed) result.push(value); - seen = computed; - } else if (iteratee) { - if (!_.contains(seen, computed)) { - seen.push(computed); - result.push(value); - } - } else if (!_.contains(result, value)) { - result.push(value); - } - } - return result; - }; - - // Produce an array that contains the union: each distinct element from all of - // the passed-in arrays. - _.union = function () { - return _.uniq(flatten(arguments, true, true)); - }; - - // Produce an array that contains every item shared between all the - // passed-in arrays. - _.intersection = function (array) { - var result = []; - var argsLength = arguments.length; - for (var i = 0, length = getLength(array); i < length; i++) { - var item = array[i]; - if (_.contains(result, item)) continue; - for (var j = 1; j < argsLength; j++) { - if (!_.contains(arguments[j], item)) break; - } - if (j === argsLength) result.push(item); - } - return result; - }; - - // Take the difference between one array and a number of other arrays. - // Only the elements present in just the first array will remain. - _.difference = function (array) { - var rest = flatten(arguments, true, true, 1); - return _.filter(array, function (value) { - return !_.contains(rest, value); - }); - }; - - // Zip together multiple lists into a single array -- elements that share - // an index go together. - _.zip = function () { - return _.unzip(arguments); - }; - - // Complement of _.zip. Unzip accepts an array of arrays and groups - // each array's elements on shared indices - _.unzip = function (array) { - var length = array && _.max(array, getLength).length || 0; - var result = Array(length); - - for (var index = 0; index < length; index++) { - result[index] = _.pluck(array, index); - } - return result; - }; - - // Converts lists into objects. Pass either a single array of `[key, value]` - // pairs, or two parallel arrays of the same length -- one of keys, and one of - // the corresponding values. - _.object = function (list, values) { - var result = {}; - for (var i = 0, length = getLength(list); i < length; i++) { - if (values) { - result[list[i]] = values[i]; - } else { - result[list[i][0]] = list[i][1]; - } - } - return result; - }; - - // Generator function to create the findIndex and findLastIndex functions - function createPredicateIndexFinder(dir) { - return function (array, predicate, context) { - predicate = cb(predicate, context); - var length = getLength(array); - var index = dir > 0 ? 0 : length - 1; - for (; index >= 0 && index < length; index += dir) { - if (predicate(array[index], index, array)) return index; - } - return -1; - }; - } - - // Returns the first index on an array-like that passes a predicate test - _.findIndex = createPredicateIndexFinder(1); - _.findLastIndex = createPredicateIndexFinder(-1); - - // Use a comparator function to figure out the smallest index at which - // an object should be inserted so as to maintain order. Uses binary search. - _.sortedIndex = function (array, obj, iteratee, context) { - iteratee = cb(iteratee, context, 1); - var value = iteratee(obj); - var low = 0, high = getLength(array); - while (low < high) { - var mid = Math.floor((low + high) / 2); - if (iteratee(array[mid]) < value) low = mid + 1; else high = mid; - } - return low; - }; - - // Generator function to create the indexOf and lastIndexOf functions - function createIndexFinder(dir, predicateFind, sortedIndex) { - return function (array, item, idx) { - var i = 0, length = getLength(array); - if (typeof idx == 'number') { - if (dir > 0) { - i = idx >= 0 ? idx : Math.max(idx + length, i); - } else { - length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1; - } - } else if (sortedIndex && idx && length) { - idx = sortedIndex(array, item); - return array[idx] === item ? idx : -1; - } - if (item !== item) { - idx = predicateFind(slice.call(array, i, length), _.isNaN); - return idx >= 0 ? idx + i : -1; - } - for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) { - if (array[idx] === item) return idx; - } - return -1; - }; - } - - // Return the position of the first occurrence of an item in an array, - // or -1 if the item is not included in the array. - // If the array is large and already in sort order, pass `true` - // for **isSorted** to use binary search. - _.indexOf = createIndexFinder(1, _.findIndex, _.sortedIndex); - _.lastIndexOf = createIndexFinder(-1, _.findLastIndex); - - // Generate an integer Array containing an arithmetic progression. A port of - // the native Python `range()` function. See - // [the Python documentation](http://docs.python.org/library/functions.html#range). - _.range = function (start, stop, step) { - if (stop == null) { - stop = start || 0; - start = 0; - } - step = step || 1; - - var length = Math.max(Math.ceil((stop - start) / step), 0); - var range = Array(length); - - for (var idx = 0; idx < length; idx++, start += step) { - range[idx] = start; - } - - return range; - }; - - // Function (ahem) Functions - // ------------------ - - // Determines whether to execute a function as a constructor - // or a normal function with the provided arguments - var executeBound = function (sourceFunc, boundFunc, context, callingContext, args) { - if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args); - var self = baseCreate(sourceFunc.prototype); - var result = sourceFunc.apply(self, args); - if (_.isObject(result)) return result; - return self; - }; - - // Create a function bound to a given object (assigning `this`, and arguments, - // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if - // available. - _.bind = function (func, context) { - if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); - if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function'); - var args = slice.call(arguments, 2); - var bound = function () { - return executeBound(func, bound, context, this, args.concat(slice.call(arguments))); - }; - return bound; - }; - - // Partially apply a function by creating a version that has had some of its - // arguments pre-filled, without changing its dynamic `this` context. _ acts - // as a placeholder, allowing any combination of arguments to be pre-filled. - _.partial = function (func) { - var boundArgs = slice.call(arguments, 1); - var bound = function () { - var position = 0, length = boundArgs.length; - var args = Array(length); - for (var i = 0; i < length; i++) { - args[i] = boundArgs[i] === _ ? arguments[position++] : boundArgs[i]; - } - while (position < arguments.length) args.push(arguments[position++]); - return executeBound(func, bound, this, this, args); - }; - return bound; - }; - - // Bind a number of an object's methods to that object. Remaining arguments - // are the method names to be bound. Useful for ensuring that all callbacks - // defined on an object belong to it. - _.bindAll = function (obj) { - var i, length = arguments.length, key; - if (length <= 1) throw new Error('bindAll must be passed function names'); - for (i = 1; i < length; i++) { - key = arguments[i]; - obj[key] = _.bind(obj[key], obj); - } - return obj; - }; - - // Memoize an expensive function by storing its results. - _.memoize = function (func, hasher) { - var memoize = function (key) { - var cache = memoize.cache; - var address = '' + (hasher ? hasher.apply(this, arguments) : key); - if (!_.has(cache, address)) cache[address] = func.apply(this, arguments); - return cache[address]; - }; - memoize.cache = {}; - return memoize; - }; - - // Delays a function for the given number of milliseconds, and then calls - // it with the arguments supplied. - _.delay = function (func, wait) { - var args = slice.call(arguments, 2); - return setTimeout(function () { - return func.apply(null, args); - }, wait); - }; - - // Defers a function, scheduling it to run after the current call stack has - // cleared. - _.defer = _.partial(_.delay, _, 1); - - // Returns a function, that, when invoked, will only be triggered at most once - // during a given window of time. Normally, the throttled function will run - // as much as it can, without ever going more than once per `wait` duration; - // but if you'd like to disable the execution on the leading edge, pass - // `{leading: false}`. To disable execution on the trailing edge, ditto. - _.throttle = function (func, wait, options) { - var context, args, result; - var timeout = null; - var previous = 0; - if (!options) options = {}; - var later = function () { - previous = options.leading === false ? 0 : _.now(); - timeout = null; - result = func.apply(context, args); - if (!timeout) context = args = null; - }; - return function () { - var now = _.now(); - if (!previous && options.leading === false) previous = now; - var remaining = wait - (now - previous); - context = this; - args = arguments; - if (remaining <= 0 || remaining > wait) { - if (timeout) { - clearTimeout(timeout); - timeout = null; - } - previous = now; - result = func.apply(context, args); - if (!timeout) context = args = null; - } else if (!timeout && options.trailing !== false) { - timeout = setTimeout(later, remaining); - } - return result; - }; - }; - - // Returns a function, that, as long as it continues to be invoked, will not - // be triggered. The function will be called after it stops being called for - // N milliseconds. If `immediate` is passed, trigger the function on the - // leading edge, instead of the trailing. - _.debounce = function (func, wait, immediate) { - var timeout, args, context, timestamp, result; - - var later = function () { - var last = _.now() - timestamp; - - if (last < wait && last >= 0) { - timeout = setTimeout(later, wait - last); - } else { - timeout = null; - if (!immediate) { - result = func.apply(context, args); - if (!timeout) context = args = null; - } - } - }; - - return function () { - context = this; - args = arguments; - timestamp = _.now(); - var callNow = immediate && !timeout; - if (!timeout) timeout = setTimeout(later, wait); - if (callNow) { - result = func.apply(context, args); - context = args = null; - } - - return result; - }; - }; - - // Returns the first function passed as an argument to the second, - // allowing you to adjust arguments, run code before and after, and - // conditionally execute the original function. - _.wrap = function (func, wrapper) { - return _.partial(wrapper, func); - }; - - // Returns a negated version of the passed-in predicate. - _.negate = function (predicate) { - return function () { - return !predicate.apply(this, arguments); - }; - }; - - // Returns a function that is the composition of a list of functions, each - // consuming the return value of the function that follows. - _.compose = function () { - var args = arguments; - var start = args.length - 1; - return function () { - var i = start; - var result = args[start].apply(this, arguments); - while (i--) result = args[i].call(this, result); - return result; - }; - }; - - // Returns a function that will only be executed on and after the Nth call. - _.after = function (times, func) { - return function () { - if (--times < 1) { - return func.apply(this, arguments); - } - }; - }; - - // Returns a function that will only be executed up to (but not including) the Nth call. - _.before = function (times, func) { - var memo; - return function () { - if (--times > 0) { - memo = func.apply(this, arguments); - } - if (times <= 1) func = null; - return memo; - }; - }; - - // Returns a function that will be executed at most one time, no matter how - // often you call it. Useful for lazy initialization. - _.once = _.partial(_.before, 2); - - // Object Functions - // ---------------- - - // Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed. - var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString'); - var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString', - 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; - - function collectNonEnumProps(obj, keys) { - var nonEnumIdx = nonEnumerableProps.length; - var constructor = obj.constructor; - var proto = (_.isFunction(constructor) && constructor.prototype) || ObjProto; - - // Constructor is a special case. - var prop = 'constructor'; - if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop); - - while (nonEnumIdx--) { - prop = nonEnumerableProps[nonEnumIdx]; - if (prop in obj && obj[prop] !== proto[prop] && !_.contains(keys, prop)) { - keys.push(prop); - } - } - } - - // Retrieve the names of an object's own properties. - // Delegates to **ECMAScript 5**'s native `Object.keys` - _.keys = function (obj) { - if (!_.isObject(obj)) return []; - if (nativeKeys) return nativeKeys(obj); - var keys = []; - for (var key in obj) if (_.has(obj, key)) keys.push(key); - // Ahem, IE < 9. - if (hasEnumBug) collectNonEnumProps(obj, keys); - return keys; - }; - - // Retrieve all the property names of an object. - _.allKeys = function (obj) { - if (!_.isObject(obj)) return []; - var keys = []; - for (var key in obj) keys.push(key); - // Ahem, IE < 9. - if (hasEnumBug) collectNonEnumProps(obj, keys); - return keys; - }; - - // Retrieve the values of an object's properties. - _.values = function (obj) { - var keys = _.keys(obj); - var length = keys.length; - var values = Array(length); - for (var i = 0; i < length; i++) { - values[i] = obj[keys[i]]; - } - return values; - }; - - // Returns the results of applying the iteratee to each element of the object - // In contrast to _.map it returns an object - _.mapObject = function (obj, iteratee, context) { - iteratee = cb(iteratee, context); - var keys = _.keys(obj), - length = keys.length, - results = {}, - currentKey; - for (var index = 0; index < length; index++) { - currentKey = keys[index]; - results[currentKey] = iteratee(obj[currentKey], currentKey, obj); - } - return results; - }; - - // Convert an object into a list of `[key, value]` pairs. - _.pairs = function (obj) { - var keys = _.keys(obj); - var length = keys.length; - var pairs = Array(length); - for (var i = 0; i < length; i++) { - pairs[i] = [keys[i], obj[keys[i]]]; - } - return pairs; - }; - - // Invert the keys and values of an object. The values must be serializable. - _.invert = function (obj) { - var result = {}; - var keys = _.keys(obj); - for (var i = 0, length = keys.length; i < length; i++) { - result[obj[keys[i]]] = keys[i]; - } - return result; - }; - - // Return a sorted list of the function names available on the object. - // Aliased as `methods` - _.functions = _.methods = function (obj) { - var names = []; - for (var key in obj) { - if (_.isFunction(obj[key])) names.push(key); - } - return names.sort(); - }; - - // Extend a given object with all the properties in passed-in object(s). - _.extend = createAssigner(_.allKeys); - - // Assigns a given object with all the own properties in the passed-in object(s) - // (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) - _.extendOwn = _.assign = createAssigner(_.keys); - - // Returns the first key on an object that passes a predicate test - _.findKey = function (obj, predicate, context) { - predicate = cb(predicate, context); - var keys = _.keys(obj), key; - for (var i = 0, length = keys.length; i < length; i++) { - key = keys[i]; - if (predicate(obj[key], key, obj)) return key; - } - }; - - // Return a copy of the object only containing the whitelisted properties. - _.pick = function (object, oiteratee, context) { - var result = {}, obj = object, iteratee, keys; - if (obj == null) return result; - if (_.isFunction(oiteratee)) { - keys = _.allKeys(obj); - iteratee = optimizeCb(oiteratee, context); - } else { - keys = flatten(arguments, false, false, 1); - iteratee = function (value, key, obj) { - return key in obj; - }; - obj = Object(obj); - } - for (var i = 0, length = keys.length; i < length; i++) { - var key = keys[i]; - var value = obj[key]; - if (iteratee(value, key, obj)) result[key] = value; - } - return result; - }; - - // Return a copy of the object without the blacklisted properties. - _.omit = function (obj, iteratee, context) { - if (_.isFunction(iteratee)) { - iteratee = _.negate(iteratee); - } else { - var keys = _.map(flatten(arguments, false, false, 1), String); - iteratee = function (value, key) { - return !_.contains(keys, key); - }; - } - return _.pick(obj, iteratee, context); - }; - - // Fill in a given object with default properties. - _.defaults = createAssigner(_.allKeys, true); - - // Creates an object that inherits from the given prototype object. - // If additional properties are provided then they will be added to the - // created object. - _.create = function (prototype, props) { - var result = baseCreate(prototype); - if (props) _.extendOwn(result, props); - return result; - }; - - // Create a (shallow-cloned) duplicate of an object. - _.clone = function (obj) { - if (!_.isObject(obj)) return obj; - return _.isArray(obj) ? obj.slice() : _.extend({}, obj); - }; - - // Invokes interceptor with the obj, and then returns obj. - // The primary purpose of this method is to "tap into" a method chain, in - // order to perform operations on intermediate results within the chain. - _.tap = function (obj, interceptor) { - interceptor(obj); - return obj; - }; - - // Returns whether an object has a given set of `key:value` pairs. - _.isMatch = function (object, attrs) { - var keys = _.keys(attrs), length = keys.length; - if (object == null) return !length; - var obj = Object(object); - for (var i = 0; i < length; i++) { - var key = keys[i]; - if (attrs[key] !== obj[key] || !(key in obj)) return false; - } - return true; - }; - - - // Internal recursive comparison function for `isEqual`. - var eq = function (a, b, aStack, bStack) { - // Identical objects are equal. `0 === -0`, but they aren't identical. - // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal). - if (a === b) return a !== 0 || 1 / a === 1 / b; - // A strict comparison is necessary because `null == undefined`. - if (a == null || b == null) return a === b; - // Unwrap any wrapped objects. - if (a instanceof _) a = a._wrapped; - if (b instanceof _) b = b._wrapped; - // Compare `[[Class]]` names. - var className = toString.call(a); - if (className !== toString.call(b)) return false; - switch (className) { - // Strings, numbers, regular expressions, dates, and booleans are compared by value. - case '[object RegExp]': - // RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i') - case '[object String]': - // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is - // equivalent to `new String("5")`. - return '' + a === '' + b; - case '[object Number]': - // `NaN`s are equivalent, but non-reflexive. - // Object(NaN) is equivalent to NaN - if (+a !== +a) return +b !== +b; - // An `egal` comparison is performed for other numeric values. - return +a === 0 ? 1 / +a === 1 / b : +a === +b; - case '[object Date]': - case '[object Boolean]': - // Coerce dates and booleans to numeric primitive values. Dates are compared by their - // millisecond representations. Note that invalid dates with millisecond representations - // of `NaN` are not equivalent. - return +a === +b; - } - - var areArrays = className === '[object Array]'; - if (!areArrays) { - if (typeof a != 'object' || typeof b != 'object') return false; - - // Objects with different constructors are not equivalent, but `Object`s or `Array`s - // from different frames are. - var aCtor = a.constructor, bCtor = b.constructor; - if (aCtor !== bCtor && !(_.isFunction(aCtor) && aCtor instanceof aCtor && - _.isFunction(bCtor) && bCtor instanceof bCtor) - && ('constructor' in a && 'constructor' in b)) { - return false; - } - } - // Assume equality for cyclic structures. The algorithm for detecting cyclic - // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. - - // Initializing stack of traversed objects. - // It's done here since we only need them for objects and arrays comparison. - aStack = aStack || []; - bStack = bStack || []; - var length = aStack.length; - while (length--) { - // Linear search. Performance is inversely proportional to the number of - // unique nested structures. - if (aStack[length] === a) return bStack[length] === b; - } - - // Add the first object to the stack of traversed objects. - aStack.push(a); - bStack.push(b); - - // Recursively compare objects and arrays. - if (areArrays) { - // Compare array lengths to determine if a deep comparison is necessary. - length = a.length; - if (length !== b.length) return false; - // Deep compare the contents, ignoring non-numeric properties. - while (length--) { - if (!eq(a[length], b[length], aStack, bStack)) return false; - } - } else { - // Deep compare objects. - var keys = _.keys(a), key; - length = keys.length; - // Ensure that both objects contain the same number of properties before comparing deep equality. - if (_.keys(b).length !== length) return false; - while (length--) { - // Deep compare each member - key = keys[length]; - if (!(_.has(b, key) && eq(a[key], b[key], aStack, bStack))) return false; - } - } - // Remove the first object from the stack of traversed objects. - aStack.pop(); - bStack.pop(); - return true; - }; - - // Perform a deep comparison to check if two objects are equal. - _.isEqual = function (a, b) { - return eq(a, b); - }; - - // Is a given array, string, or object empty? - // An "empty" object has no enumerable own-properties. - _.isEmpty = function (obj) { - if (obj == null) return true; - if (isArrayLike(obj) && (_.isArray(obj) || _.isString(obj) || _.isArguments(obj))) return obj.length === 0; - return _.keys(obj).length === 0; - }; - - // Is a given value a DOM element? - _.isElement = function (obj) { - return !!(obj && obj.nodeType === 1); - }; - - // Is a given value an array? - // Delegates to ECMA5's native Array.isArray - _.isArray = nativeIsArray || function (obj) { - return toString.call(obj) === '[object Array]'; - }; - - // Is a given variable an object? - _.isObject = function (obj) { - var type = typeof obj; - return type === 'function' || type === 'object' && !!obj; - }; - - // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError. - _.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'], function (name) { - _['is' + name] = function (obj) { - return toString.call(obj) === '[object ' + name + ']'; - }; - }); - - // Define a fallback version of the method in browsers (ahem, IE < 9), where - // there isn't any inspectable "Arguments" type. - if (!_.isArguments(arguments)) { - _.isArguments = function (obj) { - return _.has(obj, 'callee'); - }; - } - - // Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8, - // IE 11 (#1621), and in Safari 8 (#1929). - if (typeof /./ != 'function' && typeof Int8Array != 'object') { - _.isFunction = function (obj) { - return typeof obj == 'function' || false; - }; - } - - // Is a given object a finite number? - _.isFinite = function (obj) { - return isFinite(obj) && !isNaN(parseFloat(obj)); - }; - - // Is the given value `NaN`? (NaN is the only number which does not equal itself). - _.isNaN = function (obj) { - return _.isNumber(obj) && obj !== +obj; - }; - - // Is a given value a boolean? - _.isBoolean = function (obj) { - return obj === true || obj === false || toString.call(obj) === '[object Boolean]'; - }; - - // Is a given value equal to null? - _.isNull = function (obj) { - return obj === null; - }; - - // Is a given variable undefined? - _.isUndefined = function (obj) { - return obj === void 0; - }; - - // Shortcut function for checking if an object has a given property directly - // on itself (in other words, not on a prototype). - _.has = function (obj, key) { - return obj != null && hasOwnProperty.call(obj, key); - }; - - // Utility Functions - // ----------------- - - // Keep the identity function around for default iteratees. - _.identity = function (value) { - return value; - }; - - // Predicate-generating functions. Often useful outside of Underscore. - _.constant = function (value) { - return function () { - return value; - }; - }; - - _.noop = function () { - }; - - _.property = property; - - // Generates a function for a given object that returns a given property. - _.propertyOf = function (obj) { - return obj == null ? function () { - } : function (key) { - return obj[key]; - }; - }; - - // Returns a predicate for checking whether an object has a given set of - // `key:value` pairs. - _.matcher = _.matches = function (attrs) { - attrs = _.extendOwn({}, attrs); - return function (obj) { - return _.isMatch(obj, attrs); - }; - }; - - // Run a function **n** times. - _.times = function (n, iteratee, context) { - var accum = Array(Math.max(0, n)); - iteratee = optimizeCb(iteratee, context, 1); - for (var i = 0; i < n; i++) accum[i] = iteratee(i); - return accum; - }; - - // Return a random integer between min and max (inclusive). - _.random = function (min, max) { - if (max == null) { - max = min; - min = 0; - } - return min + Math.floor(Math.random() * (max - min + 1)); - }; - - // A (possibly faster) way to get the current timestamp as an integer. - _.now = Date.now || function () { - return new Date().getTime(); - }; - - // List of HTML entities for escaping. - var escapeMap = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''', - '`': '`' - }; - var unescapeMap = _.invert(escapeMap); - - // Functions for escaping and unescaping strings to/from HTML interpolation. - var createEscaper = function (map) { - var escaper = function (match) { - return map[match]; - }; - // Regexes for identifying a key that needs to be escaped - var source = '(?:' + _.keys(map).join('|') + ')'; - var testRegexp = RegExp(source); - var replaceRegexp = RegExp(source, 'g'); - return function (string) { - string = string == null ? '' : '' + string; - return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string; - }; - }; - _.escape = createEscaper(escapeMap); - _.unescape = createEscaper(unescapeMap); - - // If the value of the named `property` is a function then invoke it with the - // `object` as context; otherwise, return it. - _.result = function (object, property, fallback) { - var value = object == null ? void 0 : object[property]; - if (value === void 0) { - value = fallback; - } - return _.isFunction(value) ? value.call(object) : value; - }; - - // Generate a unique integer id (unique within the entire client session). - // Useful for temporary DOM ids. - var idCounter = 0; - _.uniqueId = function (prefix) { - var id = ++idCounter + ''; - return prefix ? prefix + id : id; - }; - - // By default, Underscore uses ERB-style template delimiters, change the - // following template settings to use alternative delimiters. - _.templateSettings = { - evaluate: /<%([\s\S]+?)%>/g, - interpolate: /<%=([\s\S]+?)%>/g, - escape: /<%-([\s\S]+?)%>/g - }; - - // When customizing `templateSettings`, if you don't want to define an - // interpolation, evaluation or escaping regex, we need one that is - // guaranteed not to match. - var noMatch = /(.)^/; - - // Certain characters need to be escaped so that they can be put into a - // string literal. - var escapes = { - "'": "'", - '\\': '\\', - '\r': 'r', - '\n': 'n', - '\u2028': 'u2028', - '\u2029': 'u2029' - }; - - var escaper = /\\|'|\r|\n|\u2028|\u2029/g; - - var escapeChar = function (match) { - return '\\' + escapes[match]; - }; - - // JavaScript micro-templating, similar to John Resig's implementation. - // Underscore templating handles arbitrary delimiters, preserves whitespace, - // and correctly escapes quotes within interpolated code. - // NB: `oldSettings` only exists for backwards compatibility. - _.template = function (text, settings, oldSettings) { - if (!settings && oldSettings) settings = oldSettings; - settings = _.defaults({}, settings, _.templateSettings); - - // Combine delimiters into one regular expression via alternation. - var matcher = RegExp([ - (settings.escape || noMatch).source, - (settings.interpolate || noMatch).source, - (settings.evaluate || noMatch).source - ].join('|') + '|$', 'g'); - - // Compile the template source, escaping string literals appropriately. - var index = 0; - var source = "__p+='"; - text.replace(matcher, function (match, escape, interpolate, evaluate, offset) { - source += text.slice(index, offset).replace(escaper, escapeChar); - index = offset + match.length; - - if (escape) { - source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; - } else if (interpolate) { - source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; - } else if (evaluate) { - source += "';\n" + evaluate + "\n__p+='"; - } - - // Adobe VMs need the match returned to produce the correct offest. - return match; - }); - source += "';\n"; - - // If a variable is not specified, place data values in local scope. - if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; - - source = "var __t,__p='',__j=Array.prototype.join," + - "print=function(){__p+=__j.call(arguments,'');};\n" + - source + 'return __p;\n'; - - try { - var render = new Function(settings.variable || 'obj', '_', source); - } catch (e) { - e.source = source; - throw e; - } - - var template = function (data) { - return render.call(this, data, _); - }; - - // Provide the compiled source as a convenience for precompilation. - var argument = settings.variable || 'obj'; - template.source = 'function(' + argument + '){\n' + source + '}'; - - return template; - }; - - // Add a "chain" function. Start chaining a wrapped Underscore object. - _.chain = function (obj) { - var instance = _(obj); - instance._chain = true; - return instance; - }; - - // OOP - // --------------- - // If Underscore is called as a function, it returns a wrapped object that - // can be used OO-style. This wrapper holds altered versions of all the - // underscore functions. Wrapped objects may be chained. - - // Helper function to continue chaining intermediate results. - var result = function (instance, obj) { - return instance._chain ? _(obj).chain() : obj; - }; - - // Add your own custom functions to the Underscore object. - _.mixin = function (obj) { - _.each(_.functions(obj), function (name) { - var func = _[name] = obj[name]; - _.prototype[name] = function () { - var args = [this._wrapped]; - push.apply(args, arguments); - return result(this, func.apply(_, args)); - }; - }); - }; - - // Add all of the Underscore functions to the wrapper object. - _.mixin(_); - - // Add all mutator Array functions to the wrapper. - _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function (name) { - var method = ArrayProto[name]; - _.prototype[name] = function () { - var obj = this._wrapped; - method.apply(obj, arguments); - if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0]; - return result(this, obj); - }; - }); - - // Add all accessor Array functions to the wrapper. - _.each(['concat', 'join', 'slice'], function (name) { - var method = ArrayProto[name]; - _.prototype[name] = function () { - return result(this, method.apply(this._wrapped, arguments)); - }; - }); - - // Extracts the result from a wrapped and chained object. - _.prototype.value = function () { - return this._wrapped; - }; - - // Provide unwrapping proxy for some methods used in engine operations - // such as arithmetic and JSON stringification. - _.prototype.valueOf = _.prototype.toJSON = _.prototype.value; - - _.prototype.toString = function () { - return '' + this._wrapped; - }; - - -}()); - -/** - * @fileoverview Zlib namespace. Zlib の仕様に準拠した圧縮は Zlib.Deflate で実装 - * されている. これは Inflate との共存を考慮している為. - */ - -var USE_TYPEDARRAY = true; - -var Zlib = { - Huffman: {}, - Util: {}, - CRC32: {} -}; - - -/** - * Compression Method - * @enum {number} - */ -Zlib.CompressionMethod = { - DEFLATE: 8, - RESERVED: 15 -}; - - - - -/** - * @param {Object=} opt_params options. - * @constructor - */ -Zlib.Zip = function(opt_params) { - opt_params = opt_params || {}; - /** @type {Array.<{ - * buffer: !(Array.|Uint8Array), - * option: Object, - * compressed: boolean, - * encrypted: boolean, - * size: number, - * crc32: number - * }>} */ - this.files = []; - /** @type {(Array.|Uint8Array)} */ - this.comment = opt_params['comment']; - /** @type {(Array.|Uint8Array)} */ - this.password; -}; - - -/** - * @enum {number} - */ -Zlib.Zip.CompressionMethod = { - STORE: 0, - DEFLATE: 8 -}; - -/** - * @enum {number} - */ -Zlib.Zip.OperatingSystem = { - MSDOS: 0, - UNIX: 3, - MACINTOSH: 7 -}; - -/** - * @enum {number} - */ -Zlib.Zip.Flags = { - ENCRYPT: 0x0001, - DESCRIPTOR: 0x0008, - UTF8: 0x0800 -}; - -/** - * @type {Array.} - * @const - */ -Zlib.Zip.FileHeaderSignature = [0x50, 0x4b, 0x01, 0x02]; - -/** - * @type {Array.} - * @const - */ -Zlib.Zip.LocalFileHeaderSignature = [0x50, 0x4b, 0x03, 0x04]; - -/** - * @type {Array.} - * @const - */ -Zlib.Zip.CentralDirectorySignature = [0x50, 0x4b, 0x05, 0x06]; - -/** - * @param {Array.|Uint8Array} input - * @param {Object=} opt_params options. - */ -Zlib.Zip.prototype.addFile = function(input, opt_params) { - opt_params = opt_params || {}; - /** @type {string} */ - var filename = '' || opt_params['filename']; - /** @type {boolean} */ - var compressed; - /** @type {number} */ - var size = input.length; - /** @type {number} */ - var crc32 = 0; - - if (USE_TYPEDARRAY && input instanceof Array) { - input = new Uint8Array(input); - } - - // default - if (typeof opt_params['compressionMethod'] !== 'number') { - opt_params['compressionMethod'] = Zlib.Zip.CompressionMethod.DEFLATE; - } - - // その場で圧縮する場合 - if (opt_params['compress']) { - switch (opt_params['compressionMethod']) { - case Zlib.Zip.CompressionMethod.STORE: - break; - case Zlib.Zip.CompressionMethod.DEFLATE: - crc32 = Zlib.CRC32.calc(input); - input = this.deflateWithOption(input, opt_params); - compressed = true; - break; - default: - throw new Error('unknown compression method:' + opt_params['compressionMethod']); - } - } - - this.files.push({ - buffer: input, - option: opt_params, - compressed: compressed, - encrypted: false, - size: size, - crc32: crc32 - }); -}; - -/** - * @param {(Array.|Uint8Array)} password - */ -Zlib.Zip.prototype.setPassword = function(password) { - this.password = password; -}; - -Zlib.Zip.prototype.compress = function() { - /** @type {Array.<{ - * buffer: !(Array.|Uint8Array), - * option: Object, - * compressed: boolean, - * encrypted: boolean, - * size: number, - * crc32: number - * }>} */ - var files = this.files; - /** @type {{ - * buffer: !(Array.|Uint8Array), - * option: Object, - * compressed: boolean, - * encrypted: boolean, - * size: number, - * crc32: number - * }} */ - var file; - /** @type {!(Array.|Uint8Array)} */ - var output; - /** @type {number} */ - var op1; - /** @type {number} */ - var op2; - /** @type {number} */ - var op3; - /** @type {number} */ - var localFileSize = 0; - /** @type {number} */ - var centralDirectorySize = 0; - /** @type {number} */ - var endOfCentralDirectorySize; - /** @type {number} */ - var offset; - /** @type {number} */ - var needVersion; - /** @type {number} */ - var flags; - /** @type {Zlib.Zip.CompressionMethod} */ - var compressionMethod; - /** @type {Date} */ - var date; - /** @type {number} */ - var crc32; - /** @type {number} */ - var size; - /** @type {number} */ - var plainSize; - /** @type {number} */ - var filenameLength; - /** @type {number} */ - var extraFieldLength; - /** @type {number} */ - var commentLength; - /** @type {(Array.|Uint8Array)} */ - var filename; - /** @type {(Array.|Uint8Array)} */ - var extraField; - /** @type {(Array.|Uint8Array)} */ - var comment; - /** @type {(Array.|Uint8Array)} */ - var buffer; - /** @type {*} */ - var tmp; - /** @type {Array.|Uint32Array|Object} */ - var key; - /** @type {number} */ - var i; - /** @type {number} */ - var il; - /** @type {number} */ - var j; - /** @type {number} */ - var jl; - - // ファイルの圧縮 - for (i = 0, il = files.length; i < il; ++i) { - file = files[i]; - filenameLength = - (file.option['filename']) ? file.option['filename'].length : 0; - extraFieldLength = - (file.option['extraField']) ? file.option['extraField'].length : 0; - commentLength = - (file.option['comment']) ? file.option['comment'].length : 0; - - // 圧縮されていなかったら圧縮 - if (!file.compressed) { - // 圧縮前に CRC32 の計算をしておく - file.crc32 = Zlib.CRC32.calc(file.buffer); - - switch (file.option['compressionMethod']) { - case Zlib.Zip.CompressionMethod.STORE: - break; - case Zlib.Zip.CompressionMethod.DEFLATE: - file.buffer = this.deflateWithOption(file.buffer, file.option); - file.compressed = true; - break; - default: - throw new Error('unknown compression method:' + file.option['compressionMethod']); - } - } - - // encryption - if (file.option['password'] !== void 0|| this.password !== void 0) { - // init encryption - key = this.createEncryptionKey(file.option['password'] || this.password); - - // add header - buffer = file.buffer; - if (USE_TYPEDARRAY) { - tmp = new Uint8Array(buffer.length + 12); - tmp.set(buffer, 12); - buffer = tmp; - } else { - buffer.unshift(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - } - - for (j = 0; j < 12; ++j) { - buffer[j] = this.encode( - key, - i === 11 ? (file.crc32 & 0xff) : (Math.random() * 256 | 0) - ); - } - - // data encryption - for (jl = buffer.length; j < jl; ++j) { - buffer[j] = this.encode(key, buffer[j]); - } - file.buffer = buffer; - } - - // 必要バッファサイズの計算 - localFileSize += - // local file header - 30 + filenameLength + - // file data - file.buffer.length; - - centralDirectorySize += - // file header - 46 + filenameLength + commentLength; - } - - // end of central directory - endOfCentralDirectorySize = 22 + (this.comment ? this.comment.length : 0); - output = new (USE_TYPEDARRAY ? Uint8Array : Array)( - localFileSize + centralDirectorySize + endOfCentralDirectorySize - ); - op1 = 0; - op2 = localFileSize; - op3 = op2 + centralDirectorySize; - - // ファイルの圧縮 - for (i = 0, il = files.length; i < il; ++i) { - file = files[i]; - filenameLength = - file.option['filename'] ? file.option['filename'].length : 0; - extraFieldLength = 0; // TODO - commentLength = - file.option['comment'] ? file.option['comment'].length : 0; - - //------------------------------------------------------------------------- - // local file header & file header - //------------------------------------------------------------------------- - - offset = op1; - - // signature - // local file header - output[op1++] = Zlib.Zip.LocalFileHeaderSignature[0]; - output[op1++] = Zlib.Zip.LocalFileHeaderSignature[1]; - output[op1++] = Zlib.Zip.LocalFileHeaderSignature[2]; - output[op1++] = Zlib.Zip.LocalFileHeaderSignature[3]; - // file header - output[op2++] = Zlib.Zip.FileHeaderSignature[0]; - output[op2++] = Zlib.Zip.FileHeaderSignature[1]; - output[op2++] = Zlib.Zip.FileHeaderSignature[2]; - output[op2++] = Zlib.Zip.FileHeaderSignature[3]; - - // compressor info - needVersion = 20; - output[op2++] = needVersion & 0xff; - output[op2++] = - /** @type {Zlib.Zip.OperatingSystem} */ - (file.option['os']) || - Zlib.Zip.OperatingSystem.MSDOS; - - // need version - output[op1++] = output[op2++] = needVersion & 0xff; - output[op1++] = output[op2++] = (needVersion >> 8) & 0xff; - - // general purpose bit flag - flags = 0; - if (file.option['password'] || this.password) { - flags |= Zlib.Zip.Flags.ENCRYPT; - } - output[op1++] = output[op2++] = flags & 0xff; - output[op1++] = output[op2++] = (flags >> 8) & 0xff; - - // compression method - compressionMethod = - /** @type {Zlib.Zip.CompressionMethod} */ - (file.option['compressionMethod']); - output[op1++] = output[op2++] = compressionMethod & 0xff; - output[op1++] = output[op2++] = (compressionMethod >> 8) & 0xff; - - // date - date = /** @type {(Date|undefined)} */(file.option['date']) || new Date(); - output[op1++] = output[op2++] = - ((date.getMinutes() & 0x7) << 5) | - (date.getSeconds() / 2 | 0); - output[op1++] = output[op2++] = - (date.getHours() << 3) | - (date.getMinutes() >> 3); - // - output[op1++] = output[op2++] = - ((date.getMonth() + 1 & 0x7) << 5) | - (date.getDate()); - output[op1++] = output[op2++] = - ((date.getFullYear() - 1980 & 0x7f) << 1) | - (date.getMonth() + 1 >> 3); - - // CRC-32 - crc32 = file.crc32; - output[op1++] = output[op2++] = crc32 & 0xff; - output[op1++] = output[op2++] = (crc32 >> 8) & 0xff; - output[op1++] = output[op2++] = (crc32 >> 16) & 0xff; - output[op1++] = output[op2++] = (crc32 >> 24) & 0xff; - - // compressed size - size = file.buffer.length; - output[op1++] = output[op2++] = size & 0xff; - output[op1++] = output[op2++] = (size >> 8) & 0xff; - output[op1++] = output[op2++] = (size >> 16) & 0xff; - output[op1++] = output[op2++] = (size >> 24) & 0xff; - - // uncompressed size - plainSize = file.size; - output[op1++] = output[op2++] = plainSize & 0xff; - output[op1++] = output[op2++] = (plainSize >> 8) & 0xff; - output[op1++] = output[op2++] = (plainSize >> 16) & 0xff; - output[op1++] = output[op2++] = (plainSize >> 24) & 0xff; - - // filename length - output[op1++] = output[op2++] = filenameLength & 0xff; - output[op1++] = output[op2++] = (filenameLength >> 8) & 0xff; - - // extra field length - output[op1++] = output[op2++] = extraFieldLength & 0xff; - output[op1++] = output[op2++] = (extraFieldLength >> 8) & 0xff; - - // file comment length - output[op2++] = commentLength & 0xff; - output[op2++] = (commentLength >> 8) & 0xff; - - // disk number start - output[op2++] = 0; - output[op2++] = 0; - - // internal file attributes - output[op2++] = 0; - output[op2++] = 0; - - // external file attributes - output[op2++] = 0; - output[op2++] = 0; - output[op2++] = 0; - output[op2++] = 0; - - // relative offset of local header - output[op2++] = offset & 0xff; - output[op2++] = (offset >> 8) & 0xff; - output[op2++] = (offset >> 16) & 0xff; - output[op2++] = (offset >> 24) & 0xff; - - // filename - filename = file.option['filename']; - if (filename) { - if (USE_TYPEDARRAY) { - output.set(filename, op1); - output.set(filename, op2); - op1 += filenameLength; - op2 += filenameLength; - } else { - for (j = 0; j < filenameLength; ++j) { - output[op1++] = output[op2++] = filename[j]; - } - } - } - - // extra field - extraField = file.option['extraField']; - if (extraField) { - if (USE_TYPEDARRAY) { - output.set(extraField, op1); - output.set(extraField, op2); - op1 += extraFieldLength; - op2 += extraFieldLength; - } else { - for (j = 0; j < commentLength; ++j) { - output[op1++] = output[op2++] = extraField[j]; - } - } - } - - // comment - comment = file.option['comment']; - if (comment) { - if (USE_TYPEDARRAY) { - output.set(comment, op2); - op2 += commentLength; - } else { - for (j = 0; j < commentLength; ++j) { - output[op2++] = comment[j]; - } - } - } - - //------------------------------------------------------------------------- - // file data - //------------------------------------------------------------------------- - - if (USE_TYPEDARRAY) { - output.set(file.buffer, op1); - op1 += file.buffer.length; - } else { - for (j = 0, jl = file.buffer.length; j < jl; ++j) { - output[op1++] = file.buffer[j]; - } - } - } - - //------------------------------------------------------------------------- - // end of central directory - //------------------------------------------------------------------------- - - // signature - output[op3++] = Zlib.Zip.CentralDirectorySignature[0]; - output[op3++] = Zlib.Zip.CentralDirectorySignature[1]; - output[op3++] = Zlib.Zip.CentralDirectorySignature[2]; - output[op3++] = Zlib.Zip.CentralDirectorySignature[3]; - - // number of this disk - output[op3++] = 0; - output[op3++] = 0; - - // number of the disk with the start of the central directory - output[op3++] = 0; - output[op3++] = 0; - - // total number of entries in the central directory on this disk - output[op3++] = il & 0xff; - output[op3++] = (il >> 8) & 0xff; - - // total number of entries in the central directory - output[op3++] = il & 0xff; - output[op3++] = (il >> 8) & 0xff; - - // size of the central directory - output[op3++] = centralDirectorySize & 0xff; - output[op3++] = (centralDirectorySize >> 8) & 0xff; - output[op3++] = (centralDirectorySize >> 16) & 0xff; - output[op3++] = (centralDirectorySize >> 24) & 0xff; - - // offset of start of central directory with respect to the starting disk number - output[op3++] = localFileSize & 0xff; - output[op3++] = (localFileSize >> 8) & 0xff; - output[op3++] = (localFileSize >> 16) & 0xff; - output[op3++] = (localFileSize >> 24) & 0xff; - - // .ZIP file comment length - commentLength = this.comment ? this.comment.length : 0; - output[op3++] = commentLength & 0xff; - output[op3++] = (commentLength >> 8) & 0xff; - - // .ZIP file comment - if (this.comment) { - if (USE_TYPEDARRAY) { - output.set(this.comment, op3); - op3 += commentLength; - } else { - for (j = 0, jl = commentLength; j < jl; ++j) { - output[op3++] = this.comment[j]; - } - } - } - - return output; -}; - -/** - * @param {!(Array.|Uint8Array)} input - * @param {Object=} opt_params options. - * @return {!(Array.|Uint8Array)} - */ -Zlib.Zip.prototype.deflateWithOption = function(input, opt_params) { - /** @type {Zlib.RawDeflate} */ - var deflator = new Zlib.RawDeflate(input, opt_params['deflateOption']); - - return deflator.compress(); -}; - -/** - * @param {(Array.|Uint32Array)} key - * @return {number} - */ -Zlib.Zip.prototype.getByte = function(key) { - /** @type {number} */ - var tmp = ((key[2] & 0xffff) | 2); - - return ((tmp * (tmp ^ 1)) >> 8) & 0xff; -}; - -/** - * @param {(Array.|Uint32Array|Object)} key - * @param {number} n - * @return {number} - */ -Zlib.Zip.prototype.encode = function(key, n) { - /** @type {number} */ - var tmp = this.getByte(/** @type {(Array.|Uint32Array)} */(key)); - - this.updateKeys(/** @type {(Array.|Uint32Array)} */(key), n); - - return tmp ^ n; -}; - -/** - * @param {(Array.|Uint32Array)} key - * @param {number} n - */ -Zlib.Zip.prototype.updateKeys = function(key, n) { - key[0] = Zlib.CRC32.single(key[0], n); - key[1] = - (((((key[1] + (key[0] & 0xff)) * 20173 >>> 0) * 6681) >>> 0) + 1) >>> 0; - key[2] = Zlib.CRC32.single(key[2], key[1] >>> 24); -}; - -/** - * @param {(Array.|Uint8Array)} password - * @return {!(Array.|Uint32Array|Object)} - */ -Zlib.Zip.prototype.createEncryptionKey = function(password) { - /** @type {!(Array.|Uint32Array)} */ - var key = [305419896, 591751049, 878082192]; - /** @type {number} */ - var i; - /** @type {number} */ - var il; - - if (USE_TYPEDARRAY) { - key = new Uint32Array(key); - } - - for (i = 0, il = password.length; i < il; ++i) { - this.updateKeys(key, password[i] & 0xff); - } - - return key; -}; - - - -/** - * build huffman table from length list. - * @param {!(Array.|Uint8Array)} lengths length list. - * @return {!Array} huffman table. - */ -Zlib.Huffman.buildHuffmanTable = function(lengths) { - /** @type {number} length list size. */ - var listSize = lengths.length; - /** @type {number} max code length for table size. */ - var maxCodeLength = 0; - /** @type {number} min code length for table size. */ - var minCodeLength = Number.POSITIVE_INFINITY; - /** @type {number} table size. */ - var size; - /** @type {!(Array|Uint8Array)} huffman code table. */ - var table; - /** @type {number} bit length. */ - var bitLength; - /** @type {number} huffman code. */ - var code; - /** - * サイズが 2^maxlength 個のテーブルを埋めるためのスキップ長. - * @type {number} skip length for table filling. - */ - var skip; - /** @type {number} reversed code. */ - var reversed; - /** @type {number} reverse temp. */ - var rtemp; - /** @type {number} loop counter. */ - var i; - /** @type {number} loop limit. */ - var il; - /** @type {number} loop counter. */ - var j; - /** @type {number} table value. */ - var value; - - // Math.max は遅いので最長の値は for-loop で取得する - for (i = 0, il = listSize; i < il; ++i) { - if (lengths[i] > maxCodeLength) { - maxCodeLength = lengths[i]; - } - if (lengths[i] < minCodeLength) { - minCodeLength = lengths[i]; - } - } - - size = 1 << maxCodeLength; - table = new (USE_TYPEDARRAY ? Uint32Array : Array)(size); - - // ビット長の短い順からハフマン符号を割り当てる - for (bitLength = 1, code = 0, skip = 2; bitLength <= maxCodeLength;) { - for (i = 0; i < listSize; ++i) { - if (lengths[i] === bitLength) { - // ビットオーダーが逆になるためビット長分並びを反転する - for (reversed = 0, rtemp = code, j = 0; j < bitLength; ++j) { - reversed = (reversed << 1) | (rtemp & 1); - rtemp >>= 1; - } - - // 最大ビット長をもとにテーブルを作るため、 - // 最大ビット長以外では 0 / 1 どちらでも良い箇所ができる - // そのどちらでも良い場所は同じ値で埋めることで - // 本来のビット長以上のビット数取得しても問題が起こらないようにする - value = (bitLength << 16) | i; - for (j = reversed; j < size; j += skip) { - table[j] = value; - } - - ++code; - } - } - - // 次のビット長へ - ++bitLength; - code <<= 1; - skip <<= 1; - } - - return [table, maxCodeLength, minCodeLength]; -}; - - - - -//----------------------------------------------------------------------------- - -/** @define {number} buffer block size. */ -var ZLIB_RAW_INFLATE_BUFFER_SIZE = 0x8000; // [ 0x8000 >= ZLIB_BUFFER_BLOCK_SIZE ] - -//----------------------------------------------------------------------------- - - -var buildHuffmanTable = Zlib.Huffman.buildHuffmanTable; - -/** - * @constructor - * @param {!(Uint8Array|Array.)} input input buffer. - * @param {Object} opt_params option parameter. - * - * opt_params は以下のプロパティを指定する事ができます。 - * - index: input buffer の deflate コンテナの開始位置. - * - blockSize: バッファのブロックサイズ. - * - bufferType: Zlib.RawInflate.BufferType の値によってバッファの管理方法を指定する. - * - resize: 確保したバッファが実際の大きさより大きかった場合に切り詰める. - */ -Zlib.RawInflate = function(input, opt_params) { - /** @type {!(Array.|Uint8Array)} inflated buffer */ - this.buffer; - /** @type {!Array.<(Array.|Uint8Array)>} */ - this.blocks = []; - /** @type {number} block size. */ - this.bufferSize = ZLIB_RAW_INFLATE_BUFFER_SIZE; - /** @type {!number} total output buffer pointer. */ - this.totalpos = 0; - /** @type {!number} input buffer pointer. */ - this.ip = 0; - /** @type {!number} bit stream reader buffer. */ - this.bitsbuf = 0; - /** @type {!number} bit stream reader buffer size. */ - this.bitsbuflen = 0; - /** @type {!(Array.|Uint8Array)} input buffer. */ - this.input = USE_TYPEDARRAY ? new Uint8Array(input) : input; - /** @type {!(Uint8Array|Array.)} output buffer. */ - this.output; - /** @type {!number} output buffer pointer. */ - this.op; - /** @type {boolean} is final block flag. */ - this.bfinal = false; - /** @type {Zlib.RawInflate.BufferType} buffer management. */ - this.bufferType = Zlib.RawInflate.BufferType.ADAPTIVE; - /** @type {boolean} resize flag for memory size optimization. */ - this.resize = false; - - // option parameters - if (opt_params || !(opt_params = {})) { - if (opt_params['index']) { - this.ip = opt_params['index']; - } - if (opt_params['bufferSize']) { - this.bufferSize = opt_params['bufferSize']; - } - if (opt_params['bufferType']) { - this.bufferType = opt_params['bufferType']; - } - if (opt_params['resize']) { - this.resize = opt_params['resize']; - } - } - - // initialize - switch (this.bufferType) { - case Zlib.RawInflate.BufferType.BLOCK: - this.op = Zlib.RawInflate.MaxBackwardLength; - this.output = - new (USE_TYPEDARRAY ? Uint8Array : Array)( - Zlib.RawInflate.MaxBackwardLength + - this.bufferSize + - Zlib.RawInflate.MaxCopyLength - ); - break; - case Zlib.RawInflate.BufferType.ADAPTIVE: - this.op = 0; - this.output = new (USE_TYPEDARRAY ? Uint8Array : Array)(this.bufferSize); - break; - default: - throw new Error('invalid inflate mode'); - } -}; - -/** - * @enum {number} - */ -Zlib.RawInflate.BufferType = { - BLOCK: 0, - ADAPTIVE: 1 -}; - -/** - * decompress. - * @return {!(Uint8Array|Array.)} inflated buffer. - */ -Zlib.RawInflate.prototype.decompress = function() { - while (!this.bfinal) { - this.parseBlock(); - } - - switch (this.bufferType) { - case Zlib.RawInflate.BufferType.BLOCK: - return this.concatBufferBlock(); - case Zlib.RawInflate.BufferType.ADAPTIVE: - return this.concatBufferDynamic(); - default: - throw new Error('invalid inflate mode'); - } -}; - -/** - * @const - * @type {number} max backward length for LZ77. - */ -Zlib.RawInflate.MaxBackwardLength = 32768; - -/** - * @const - * @type {number} max copy length for LZ77. - */ -Zlib.RawInflate.MaxCopyLength = 258; - -/** - * huffman order - * @const - * @type {!(Array.|Uint8Array)} - */ -Zlib.RawInflate.Order = (function(table) { - return USE_TYPEDARRAY ? new Uint16Array(table) : table; -})([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); - -/** - * huffman length code table. - * @const - * @type {!(Array.|Uint16Array)} - */ -Zlib.RawInflate.LengthCodeTable = (function(table) { - return USE_TYPEDARRAY ? new Uint16Array(table) : table; -})([ - 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, - 0x000d, 0x000f, 0x0011, 0x0013, 0x0017, 0x001b, 0x001f, 0x0023, 0x002b, - 0x0033, 0x003b, 0x0043, 0x0053, 0x0063, 0x0073, 0x0083, 0x00a3, 0x00c3, - 0x00e3, 0x0102, 0x0102, 0x0102 -]); - -/** - * huffman length extra-bits table. - * @const - * @type {!(Array.|Uint8Array)} - */ -Zlib.RawInflate.LengthExtraTable = (function(table) { - return USE_TYPEDARRAY ? new Uint8Array(table) : table; -})([ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, - 5, 5, 0, 0, 0 -]); - -/** - * huffman dist code table. - * @const - * @type {!(Array.|Uint16Array)} - */ -Zlib.RawInflate.DistCodeTable = (function(table) { - return USE_TYPEDARRAY ? new Uint16Array(table) : table; -})([ - 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d, 0x0011, - 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1, 0x0101, 0x0181, - 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01, 0x1001, 0x1801, 0x2001, - 0x3001, 0x4001, 0x6001 -]); - -/** - * huffman dist extra-bits table. - * @const - * @type {!(Array.|Uint8Array)} - */ -Zlib.RawInflate.DistExtraTable = (function(table) { - return USE_TYPEDARRAY ? new Uint8Array(table) : table; -})([ - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, - 11, 12, 12, 13, 13 -]); - -/** - * fixed huffman length code table - * @const - * @type {!Array} - */ -Zlib.RawInflate.FixedLiteralLengthTable = (function(table) { - return table; -})((function() { - var lengths = new (USE_TYPEDARRAY ? Uint8Array : Array)(288); - var i, il; - - for (i = 0, il = lengths.length; i < il; ++i) { - lengths[i] = - (i <= 143) ? 8 : - (i <= 255) ? 9 : - (i <= 279) ? 7 : - 8; - } - - return buildHuffmanTable(lengths); -})()); - -/** - * fixed huffman distance code table - * @const - * @type {!Array} - */ -Zlib.RawInflate.FixedDistanceTable = (function(table) { - return table; -})((function() { - var lengths = new (USE_TYPEDARRAY ? Uint8Array : Array)(30); - var i, il; - - for (i = 0, il = lengths.length; i < il; ++i) { - lengths[i] = 5; - } - - return buildHuffmanTable(lengths); -})()); - -/** - * parse deflated block. - */ -Zlib.RawInflate.prototype.parseBlock = function() { - /** @type {number} header */ - var hdr = this.readBits(3); - - // BFINAL - if (hdr & 0x1) { - this.bfinal = true; - } - - // BTYPE - hdr >>>= 1; - switch (hdr) { - // uncompressed - case 0: - this.parseUncompressedBlock(); - break; - // fixed huffman - case 1: - this.parseFixedHuffmanBlock(); - break; - // dynamic huffman - case 2: - this.parseDynamicHuffmanBlock(); - break; - // reserved or other - default: - throw new Error('unknown BTYPE: ' + hdr); - } -}; - -/** - * read inflate bits - * @param {number} length bits length. - * @return {number} read bits. - */ -Zlib.RawInflate.prototype.readBits = function(length) { - var bitsbuf = this.bitsbuf; - var bitsbuflen = this.bitsbuflen; - var input = this.input; - var ip = this.ip; - - /** @type {number} */ - var inputLength = input.length; - /** @type {number} input and output byte. */ - var octet; - - // input byte - if (ip + ((length - bitsbuflen + 7) >> 3) >= inputLength) { - throw new Error('input buffer is broken'); - } - - // not enough buffer - while (bitsbuflen < length) { - bitsbuf |= input[ip++] << bitsbuflen; - bitsbuflen += 8; - } - - // output byte - octet = bitsbuf & /* MASK */ ((1 << length) - 1); - bitsbuf >>>= length; - bitsbuflen -= length; - - this.bitsbuf = bitsbuf; - this.bitsbuflen = bitsbuflen; - this.ip = ip; - - return octet; -}; - -/** - * read huffman code using table - * @param {!(Array.|Uint8Array|Uint16Array)} table huffman code table. - * @return {number} huffman code. - */ -Zlib.RawInflate.prototype.readCodeByTable = function(table) { - var bitsbuf = this.bitsbuf; - var bitsbuflen = this.bitsbuflen; - var input = this.input; - var ip = this.ip; - - /** @type {number} */ - var inputLength = input.length; - /** @type {!(Array.|Uint8Array)} huffman code table */ - var codeTable = table[0]; - /** @type {number} */ - var maxCodeLength = table[1]; - /** @type {number} code length & code (16bit, 16bit) */ - var codeWithLength; - /** @type {number} code bits length */ - var codeLength; - - // not enough buffer - while (bitsbuflen < maxCodeLength) { - if (ip >= inputLength) { - break; - } - bitsbuf |= input[ip++] << bitsbuflen; - bitsbuflen += 8; - } - - // read max length - codeWithLength = codeTable[bitsbuf & ((1 << maxCodeLength) - 1)]; - codeLength = codeWithLength >>> 16; - - if (codeLength > bitsbuflen) { - throw new Error('invalid code length: ' + codeLength); - } - - this.bitsbuf = bitsbuf >> codeLength; - this.bitsbuflen = bitsbuflen - codeLength; - this.ip = ip; - - return codeWithLength & 0xffff; -}; - -/** - * parse uncompressed block. - */ -Zlib.RawInflate.prototype.parseUncompressedBlock = function() { - var input = this.input; - var ip = this.ip; - var output = this.output; - var op = this.op; - - /** @type {number} */ - var inputLength = input.length; - /** @type {number} block length */ - var len; - /** @type {number} number for check block length */ - var nlen; - /** @type {number} output buffer length */ - var olength = output.length; - /** @type {number} copy counter */ - var preCopy; - - // skip buffered header bits - this.bitsbuf = 0; - this.bitsbuflen = 0; - - // len - if (ip + 1 >= inputLength) { - throw new Error('invalid uncompressed block header: LEN'); - } - len = input[ip++] | (input[ip++] << 8); - - // nlen - if (ip + 1 >= inputLength) { - throw new Error('invalid uncompressed block header: NLEN'); - } - nlen = input[ip++] | (input[ip++] << 8); - - // check len & nlen - if (len === ~nlen) { - throw new Error('invalid uncompressed block header: length verify'); - } - - // check size - if (ip + len > input.length) { throw new Error('input buffer is broken'); } - - // expand buffer - switch (this.bufferType) { - case Zlib.RawInflate.BufferType.BLOCK: - // pre copy - while (op + len > output.length) { - preCopy = olength - op; - len -= preCopy; - if (USE_TYPEDARRAY) { - output.set(input.subarray(ip, ip + preCopy), op); - op += preCopy; - ip += preCopy; - } else { - while (preCopy--) { - output[op++] = input[ip++]; - } - } - this.op = op; - output = this.expandBufferBlock(); - op = this.op; - } - break; - case Zlib.RawInflate.BufferType.ADAPTIVE: - while (op + len > output.length) { - output = this.expandBufferAdaptive({fixRatio: 2}); - } - break; - default: - throw new Error('invalid inflate mode'); - } - - // copy - if (USE_TYPEDARRAY) { - output.set(input.subarray(ip, ip + len), op); - op += len; - ip += len; - } else { - while (len--) { - output[op++] = input[ip++]; - } - } - - this.ip = ip; - this.op = op; - this.output = output; -}; - -/** - * parse fixed huffman block. - */ -Zlib.RawInflate.prototype.parseFixedHuffmanBlock = function() { - switch (this.bufferType) { - case Zlib.RawInflate.BufferType.ADAPTIVE: - this.decodeHuffmanAdaptive( - Zlib.RawInflate.FixedLiteralLengthTable, - Zlib.RawInflate.FixedDistanceTable - ); - break; - case Zlib.RawInflate.BufferType.BLOCK: - this.decodeHuffmanBlock( - Zlib.RawInflate.FixedLiteralLengthTable, - Zlib.RawInflate.FixedDistanceTable - ); - break; - default: - throw new Error('invalid inflate mode'); - } -}; - -/** - * parse dynamic huffman block. - */ -Zlib.RawInflate.prototype.parseDynamicHuffmanBlock = function() { - /** @type {number} number of literal and length codes. */ - var hlit = this.readBits(5) + 257; - /** @type {number} number of distance codes. */ - var hdist = this.readBits(5) + 1; - /** @type {number} number of code lengths. */ - var hclen = this.readBits(4) + 4; - /** @type {!(Uint8Array|Array.)} code lengths. */ - var codeLengths = - new (USE_TYPEDARRAY ? Uint8Array : Array)(Zlib.RawInflate.Order.length); - /** @type {!Array} code lengths table. */ - var codeLengthsTable; - /** @type {!(Uint8Array|Array.)} literal and length code table. */ - var litlenTable; - /** @type {!(Uint8Array|Array.)} distance code table. */ - var distTable; - /** @type {!(Uint8Array|Array.)} code length table. */ - var lengthTable; - /** @type {number} */ - var code; - /** @type {number} */ - var prev; - /** @type {number} */ - var repeat; - /** @type {number} loop counter. */ - var i; - /** @type {number} loop limit. */ - var il; - - // decode code lengths - for (i = 0; i < hclen; ++i) { - codeLengths[Zlib.RawInflate.Order[i]] = this.readBits(3); - } - if (!USE_TYPEDARRAY) { - for (i = hclen, hclen = codeLengths.length; i < hclen; ++i) { - codeLengths[Zlib.RawInflate.Order[i]] = 0; - } - } - - // decode length table - codeLengthsTable = buildHuffmanTable(codeLengths); - lengthTable = new (USE_TYPEDARRAY ? Uint8Array : Array)(hlit + hdist); - for (i = 0, il = hlit + hdist; i < il;) { - code = this.readCodeByTable(codeLengthsTable); - switch (code) { - case 16: - repeat = 3 + this.readBits(2); - while (repeat--) { lengthTable[i++] = prev; } - break; - case 17: - repeat = 3 + this.readBits(3); - while (repeat--) { lengthTable[i++] = 0; } - prev = 0; - break; - case 18: - repeat = 11 + this.readBits(7); - while (repeat--) { lengthTable[i++] = 0; } - prev = 0; - break; - default: - lengthTable[i++] = code; - prev = code; - break; - } - } - - litlenTable = USE_TYPEDARRAY - ? buildHuffmanTable(lengthTable.subarray(0, hlit)) - : buildHuffmanTable(lengthTable.slice(0, hlit)); - distTable = USE_TYPEDARRAY - ? buildHuffmanTable(lengthTable.subarray(hlit)) - : buildHuffmanTable(lengthTable.slice(hlit)); - - switch (this.bufferType) { - case Zlib.RawInflate.BufferType.ADAPTIVE: - this.decodeHuffmanAdaptive(litlenTable, distTable); - break; - case Zlib.RawInflate.BufferType.BLOCK: - this.decodeHuffmanBlock(litlenTable, distTable); - break; - default: - throw new Error('invalid inflate mode'); - } -}; - -/** - * decode huffman code - * @param {!(Array.|Uint16Array)} litlen literal and length code table. - * @param {!(Array.|Uint8Array)} dist distination code table. - */ -Zlib.RawInflate.prototype.decodeHuffmanBlock = function(litlen, dist) { - var output = this.output; - var op = this.op; - - this.currentLitlenTable = litlen; - - /** @type {number} output position limit. */ - var olength = output.length - Zlib.RawInflate.MaxCopyLength; - /** @type {number} huffman code. */ - var code; - /** @type {number} table index. */ - var ti; - /** @type {number} huffman code distination. */ - var codeDist; - /** @type {number} huffman code length. */ - var codeLength; - - var lengthCodeTable = Zlib.RawInflate.LengthCodeTable; - var lengthExtraTable = Zlib.RawInflate.LengthExtraTable; - var distCodeTable = Zlib.RawInflate.DistCodeTable; - var distExtraTable = Zlib.RawInflate.DistExtraTable; - - while ((code = this.readCodeByTable(litlen)) !== 256) { - // literal - if (code < 256) { - if (op >= olength) { - this.op = op; - output = this.expandBufferBlock(); - op = this.op; - } - output[op++] = code; - - continue; - } - - // length code - ti = code - 257; - codeLength = lengthCodeTable[ti]; - if (lengthExtraTable[ti] > 0) { - codeLength += this.readBits(lengthExtraTable[ti]); - } - - // dist code - code = this.readCodeByTable(dist); - codeDist = distCodeTable[code]; - if (distExtraTable[code] > 0) { - codeDist += this.readBits(distExtraTable[code]); - } - - // lz77 decode - if (op >= olength) { - this.op = op; - output = this.expandBufferBlock(); - op = this.op; - } - while (codeLength--) { - output[op] = output[(op++) - codeDist]; - } - } - - while (this.bitsbuflen >= 8) { - this.bitsbuflen -= 8; - this.ip--; - } - this.op = op; -}; - -/** - * decode huffman code (adaptive) - * @param {!(Array.|Uint16Array)} litlen literal and length code table. - * @param {!(Array.|Uint8Array)} dist distination code table. - */ -Zlib.RawInflate.prototype.decodeHuffmanAdaptive = function(litlen, dist) { - var output = this.output; - var op = this.op; - - this.currentLitlenTable = litlen; - - /** @type {number} output position limit. */ - var olength = output.length; - /** @type {number} huffman code. */ - var code; - /** @type {number} table index. */ - var ti; - /** @type {number} huffman code distination. */ - var codeDist; - /** @type {number} huffman code length. */ - var codeLength; - - var lengthCodeTable = Zlib.RawInflate.LengthCodeTable; - var lengthExtraTable = Zlib.RawInflate.LengthExtraTable; - var distCodeTable = Zlib.RawInflate.DistCodeTable; - var distExtraTable = Zlib.RawInflate.DistExtraTable; - - while ((code = this.readCodeByTable(litlen)) !== 256) { - // literal - if (code < 256) { - if (op >= olength) { - output = this.expandBufferAdaptive(); - olength = output.length; - } - output[op++] = code; - - continue; - } - - // length code - ti = code - 257; - codeLength = lengthCodeTable[ti]; - if (lengthExtraTable[ti] > 0) { - codeLength += this.readBits(lengthExtraTable[ti]); - } - - // dist code - code = this.readCodeByTable(dist); - codeDist = distCodeTable[code]; - if (distExtraTable[code] > 0) { - codeDist += this.readBits(distExtraTable[code]); - } - - // lz77 decode - if (op + codeLength > olength) { - output = this.expandBufferAdaptive(); - olength = output.length; - } - while (codeLength--) { - output[op] = output[(op++) - codeDist]; - } - } - - while (this.bitsbuflen >= 8) { - this.bitsbuflen -= 8; - this.ip--; - } - this.op = op; -}; - -/** - * expand output buffer. - * @param {Object=} opt_param option parameters. - * @return {!(Array.|Uint8Array)} output buffer. - */ -Zlib.RawInflate.prototype.expandBufferBlock = function(opt_param) { - /** @type {!(Array.|Uint8Array)} store buffer. */ - var buffer = - new (USE_TYPEDARRAY ? Uint8Array : Array)( - this.op - Zlib.RawInflate.MaxBackwardLength - ); - /** @type {number} backward base point */ - var backward = this.op - Zlib.RawInflate.MaxBackwardLength; - /** @type {number} copy index. */ - var i; - /** @type {number} copy limit */ - var il; - - var output = this.output; - - // copy to output buffer - if (USE_TYPEDARRAY) { - buffer.set(output.subarray(Zlib.RawInflate.MaxBackwardLength, buffer.length)); - } else { - for (i = 0, il = buffer.length; i < il; ++i) { - buffer[i] = output[i + Zlib.RawInflate.MaxBackwardLength]; - } - } - - this.blocks.push(buffer); - this.totalpos += buffer.length; - - // copy to backward buffer - if (USE_TYPEDARRAY) { - output.set( - output.subarray(backward, backward + Zlib.RawInflate.MaxBackwardLength) - ); - } else { - for (i = 0; i < Zlib.RawInflate.MaxBackwardLength; ++i) { - output[i] = output[backward + i]; - } - } - - this.op = Zlib.RawInflate.MaxBackwardLength; - - return output; -}; - -/** - * expand output buffer. (adaptive) - * @param {Object=} opt_param option parameters. - * @return {!(Array.|Uint8Array)} output buffer pointer. - */ -Zlib.RawInflate.prototype.expandBufferAdaptive = function(opt_param) { - /** @type {!(Array.|Uint8Array)} store buffer. */ - var buffer; - /** @type {number} expantion ratio. */ - var ratio = (this.input.length / this.ip + 1) | 0; - /** @type {number} maximum number of huffman code. */ - var maxHuffCode; - /** @type {number} new output buffer size. */ - var newSize; - /** @type {number} max inflate size. */ - var maxInflateSize; - - var input = this.input; - var output = this.output; - - if (opt_param) { - if (typeof opt_param.fixRatio === 'number') { - ratio = opt_param.fixRatio; - } - if (typeof opt_param.addRatio === 'number') { - ratio += opt_param.addRatio; - } - } - - // calculate new buffer size - if (ratio < 2) { - maxHuffCode = - (input.length - this.ip) / this.currentLitlenTable[2]; - maxInflateSize = (maxHuffCode / 2 * 258) | 0; - newSize = maxInflateSize < output.length ? - output.length + maxInflateSize : - output.length << 1; - } else { - newSize = output.length * ratio; - } - - // buffer expantion - if (USE_TYPEDARRAY) { - buffer = new Uint8Array(newSize); - buffer.set(output); - } else { - buffer = output; - } - - this.output = buffer; - - return this.output; -}; - -/** - * concat output buffer. - * @return {!(Array.|Uint8Array)} output buffer. - */ -Zlib.RawInflate.prototype.concatBufferBlock = function() { - /** @type {number} buffer pointer. */ - var pos = 0; - /** @type {number} buffer pointer. */ - var limit = this.totalpos + (this.op - Zlib.RawInflate.MaxBackwardLength); - /** @type {!(Array.|Uint8Array)} output block array. */ - var output = this.output; - /** @type {!Array} blocks array. */ - var blocks = this.blocks; - /** @type {!(Array.|Uint8Array)} output block array. */ - var block; - /** @type {!(Array.|Uint8Array)} output buffer. */ - var buffer = new (USE_TYPEDARRAY ? Uint8Array : Array)(limit); - /** @type {number} loop counter. */ - var i; - /** @type {number} loop limiter. */ - var il; - /** @type {number} loop counter. */ - var j; - /** @type {number} loop limiter. */ - var jl; - - // single buffer - if (blocks.length === 0) { - return USE_TYPEDARRAY ? - this.output.subarray(Zlib.RawInflate.MaxBackwardLength, this.op) : - this.output.slice(Zlib.RawInflate.MaxBackwardLength, this.op); - } - - // copy to buffer - for (i = 0, il = blocks.length; i < il; ++i) { - block = blocks[i]; - for (j = 0, jl = block.length; j < jl; ++j) { - buffer[pos++] = block[j]; - } - } - - // current buffer - for (i = Zlib.RawInflate.MaxBackwardLength, il = this.op; i < il; ++i) { - buffer[pos++] = output[i]; - } - - this.blocks = []; - this.buffer = buffer; - - return this.buffer; -}; - -/** - * concat output buffer. (dynamic) - * @return {!(Array.|Uint8Array)} output buffer. - */ -Zlib.RawInflate.prototype.concatBufferDynamic = function() { - /** @type {Array.|Uint8Array} output buffer. */ - var buffer; - var op = this.op; - - if (USE_TYPEDARRAY) { - if (this.resize) { - buffer = new Uint8Array(op); - buffer.set(this.output.subarray(0, op)); - } else { - buffer = this.output.subarray(0, op); - } - } else { - if (this.output.length > op) { - this.output.length = op; - } - buffer = this.output; - } - - this.buffer = buffer; - - return this.buffer; -}; - - - - -var buildHuffmanTable = Zlib.Huffman.buildHuffmanTable; - -/** - * @param {!(Uint8Array|Array.)} input input buffer. - * @param {number} ip input buffer pointer. - * @param {number=} opt_buffersize buffer block size. - * @constructor - */ -Zlib.RawInflateStream = function(input, ip, opt_buffersize) { - /** @type {!Array.<(Array|Uint8Array)>} */ - this.blocks = []; - /** @type {number} block size. */ - this.bufferSize = - opt_buffersize ? opt_buffersize : ZLIB_STREAM_RAW_INFLATE_BUFFER_SIZE; - /** @type {!number} total output buffer pointer. */ - this.totalpos = 0; - /** @type {!number} input buffer pointer. */ - this.ip = ip === void 0 ? 0 : ip; - /** @type {!number} bit stream reader buffer. */ - this.bitsbuf = 0; - /** @type {!number} bit stream reader buffer size. */ - this.bitsbuflen = 0; - /** @type {!(Array|Uint8Array)} input buffer. */ - this.input = USE_TYPEDARRAY ? new Uint8Array(input) : input; - /** @type {!(Uint8Array|Array)} output buffer. */ - this.output = new (USE_TYPEDARRAY ? Uint8Array : Array)(this.bufferSize); - /** @type {!number} output buffer pointer. */ - this.op = 0; - /** @type {boolean} is final block flag. */ - this.bfinal = false; - /** @type {number} uncompressed block length. */ - this.blockLength; - /** @type {boolean} resize flag for memory size optimization. */ - this.resize = false; - /** @type {Array} */ - this.litlenTable; - /** @type {Array} */ - this.distTable; - /** @type {number} */ - this.sp = 0; // stream pointer - /** @type {Zlib.RawInflateStream.Status} */ - this.status = Zlib.RawInflateStream.Status.INITIALIZED; - - // - // backup - // - /** @type {!number} */ - this.ip_; - /** @type {!number} */ - this.bitsbuflen_; - /** @type {!number} */ - this.bitsbuf_; -}; - -/** - * @enum {number} - */ -Zlib.RawInflateStream.BlockType = { - UNCOMPRESSED: 0, - FIXED: 1, - DYNAMIC: 2 -}; - -/** - * @enum {number} - */ -Zlib.RawInflateStream.Status = { - INITIALIZED: 0, - BLOCK_HEADER_START: 1, - BLOCK_HEADER_END: 2, - BLOCK_BODY_START: 3, - BLOCK_BODY_END: 4, - DECODE_BLOCK_START: 5, - DECODE_BLOCK_END: 6 -}; - -/** - * decompress. - * @return {!(Uint8Array|Array)} inflated buffer. - */ -Zlib.RawInflateStream.prototype.decompress = function(newInput, ip) { - /** @type {boolean} */ - var stop = false; - - if (newInput !== void 0) { - this.input = newInput; - } - - if (ip !== void 0) { - this.ip = ip; - } - - // decompress - while (!stop) { - switch (this.status) { - // block header - case Zlib.RawInflateStream.Status.INITIALIZED: - case Zlib.RawInflateStream.Status.BLOCK_HEADER_START: - if (this.readBlockHeader() < 0) { - stop = true; - } - break; - // block body - case Zlib.RawInflateStream.Status.BLOCK_HEADER_END: /* FALLTHROUGH */ - case Zlib.RawInflateStream.Status.BLOCK_BODY_START: - switch(this.currentBlockType) { - case Zlib.RawInflateStream.BlockType.UNCOMPRESSED: - if (this.readUncompressedBlockHeader() < 0) { - stop = true; - } - break; - case Zlib.RawInflateStream.BlockType.FIXED: - if (this.parseFixedHuffmanBlock() < 0) { - stop = true; - } - break; - case Zlib.RawInflateStream.BlockType.DYNAMIC: - if (this.parseDynamicHuffmanBlock() < 0) { - stop = true; - } - break; - } - break; - // decode data - case Zlib.RawInflateStream.Status.BLOCK_BODY_END: - case Zlib.RawInflateStream.Status.DECODE_BLOCK_START: - switch(this.currentBlockType) { - case Zlib.RawInflateStream.BlockType.UNCOMPRESSED: - if (this.parseUncompressedBlock() < 0) { - stop = true; - } - break; - case Zlib.RawInflateStream.BlockType.FIXED: /* FALLTHROUGH */ - case Zlib.RawInflateStream.BlockType.DYNAMIC: - if (this.decodeHuffman() < 0) { - stop = true; - } - break; - } - break; - case Zlib.RawInflateStream.Status.DECODE_BLOCK_END: - if (this.bfinal) { - stop = true; - } else { - this.status = Zlib.RawInflateStream.Status.INITIALIZED; - } - break; - } - } - - return this.concatBuffer(); -}; - -/** - * @const - * @type {number} max backward length for LZ77. - */ -Zlib.RawInflateStream.MaxBackwardLength = 32768; - -/** - * @const - * @type {number} max copy length for LZ77. - */ -Zlib.RawInflateStream.MaxCopyLength = 258; - -/** - * huffman order - * @const - * @type {!(Array.|Uint8Array)} - */ -Zlib.RawInflateStream.Order = (function(table) { - return USE_TYPEDARRAY ? new Uint16Array(table) : table; -})([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); - -/** - * huffman length code table. - * @const - * @type {!(Array.|Uint16Array)} - */ -Zlib.RawInflateStream.LengthCodeTable = (function(table) { - return USE_TYPEDARRAY ? new Uint16Array(table) : table; -})([ - 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, - 0x000d, 0x000f, 0x0011, 0x0013, 0x0017, 0x001b, 0x001f, 0x0023, 0x002b, - 0x0033, 0x003b, 0x0043, 0x0053, 0x0063, 0x0073, 0x0083, 0x00a3, 0x00c3, - 0x00e3, 0x0102, 0x0102, 0x0102 -]); - -/** - * huffman length extra-bits table. - * @const - * @type {!(Array.|Uint8Array)} - */ -Zlib.RawInflateStream.LengthExtraTable = (function(table) { - return USE_TYPEDARRAY ? new Uint8Array(table) : table; -})([ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, - 5, 5, 0, 0, 0 -]); - -/** - * huffman dist code table. - * @const - * @type {!(Array.|Uint16Array)} - */ -Zlib.RawInflateStream.DistCodeTable = (function(table) { - return USE_TYPEDARRAY ? new Uint16Array(table) : table; -})([ - 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d, 0x0011, - 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1, 0x0101, 0x0181, - 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01, 0x1001, 0x1801, 0x2001, - 0x3001, 0x4001, 0x6001 -]); - -/** - * huffman dist extra-bits table. - * @const - * @type {!(Array.|Uint8Array)} - */ -Zlib.RawInflateStream.DistExtraTable = (function(table) { - return USE_TYPEDARRAY ? new Uint8Array(table) : table; -})([ - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, - 11, 12, 12, 13, 13 -]); - -/** - * fixed huffman length code table - * @const - * @type {!Array} - */ -Zlib.RawInflateStream.FixedLiteralLengthTable = (function(table) { - return table; -})((function() { - var lengths = new (USE_TYPEDARRAY ? Uint8Array : Array)(288); - var i, il; - - for (i = 0, il = lengths.length; i < il; ++i) { - lengths[i] = - (i <= 143) ? 8 : - (i <= 255) ? 9 : - (i <= 279) ? 7 : - 8; - } - - return buildHuffmanTable(lengths); -})()); - -/** - * fixed huffman distance code table - * @const - * @type {!Array} - */ -Zlib.RawInflateStream.FixedDistanceTable = (function(table) { - return table; -})((function() { - var lengths = new (USE_TYPEDARRAY ? Uint8Array : Array)(30); - var i, il; - - for (i = 0, il = lengths.length; i < il; ++i) { - lengths[i] = 5; - } - - return buildHuffmanTable(lengths); -})()); - -/** - * parse deflated block. - */ -Zlib.RawInflateStream.prototype.readBlockHeader = function() { - /** @type {number} header */ - var hdr; - - this.status = Zlib.RawInflateStream.Status.BLOCK_HEADER_START; - - this.save_(); - if ((hdr = this.readBits(3)) < 0) { - this.restore_(); - return -1; - } - - // BFINAL - if (hdr & 0x1) { - this.bfinal = true; - } - - // BTYPE - hdr >>>= 1; - switch (hdr) { - case 0: // uncompressed - this.currentBlockType = Zlib.RawInflateStream.BlockType.UNCOMPRESSED; - break; - case 1: // fixed huffman - this.currentBlockType = Zlib.RawInflateStream.BlockType.FIXED; - break; - case 2: // dynamic huffman - this.currentBlockType = Zlib.RawInflateStream.BlockType.DYNAMIC; - break; - default: // reserved or other - throw new Error('unknown BTYPE: ' + hdr); - } - - this.status = Zlib.RawInflateStream.Status.BLOCK_HEADER_END; -}; - -/** - * read inflate bits - * @param {number} length bits length. - * @return {number} read bits. - */ -Zlib.RawInflateStream.prototype.readBits = function(length) { - var bitsbuf = this.bitsbuf; - var bitsbuflen = this.bitsbuflen; - var input = this.input; - var ip = this.ip; - - /** @type {number} input and output byte. */ - var octet; - - // not enough buffer - while (bitsbuflen < length) { - // input byte - if (input.length <= ip) { - return -1; - } - octet = input[ip++]; - - // concat octet - bitsbuf |= octet << bitsbuflen; - bitsbuflen += 8; - } - - // output byte - octet = bitsbuf & /* MASK */ ((1 << length) - 1); - bitsbuf >>>= length; - bitsbuflen -= length; - - this.bitsbuf = bitsbuf; - this.bitsbuflen = bitsbuflen; - this.ip = ip; - - return octet; -}; - -/** - * read huffman code using table - * @param {Array} table huffman code table. - * @return {number} huffman code. - */ -Zlib.RawInflateStream.prototype.readCodeByTable = function(table) { - var bitsbuf = this.bitsbuf; - var bitsbuflen = this.bitsbuflen; - var input = this.input; - var ip = this.ip; - - /** @type {!(Array|Uint8Array)} huffman code table */ - var codeTable = table[0]; - /** @type {number} */ - var maxCodeLength = table[1]; - /** @type {number} input byte */ - var octet; - /** @type {number} code length & code (16bit, 16bit) */ - var codeWithLength; - /** @type {number} code bits length */ - var codeLength; - - // not enough buffer - while (bitsbuflen < maxCodeLength) { - if (input.length <= ip) { - return -1; - } - octet = input[ip++]; - bitsbuf |= octet << bitsbuflen; - bitsbuflen += 8; - } - - // read max length - codeWithLength = codeTable[bitsbuf & ((1 << maxCodeLength) - 1)]; - codeLength = codeWithLength >>> 16; - - if (codeLength > bitsbuflen) { - throw new Error('invalid code length: ' + codeLength); - } - - this.bitsbuf = bitsbuf >> codeLength; - this.bitsbuflen = bitsbuflen - codeLength; - this.ip = ip; - - return codeWithLength & 0xffff; -}; - -/** - * read uncompressed block header - */ -Zlib.RawInflateStream.prototype.readUncompressedBlockHeader = function() { - /** @type {number} block length */ - var len; - /** @type {number} number for check block length */ - var nlen; - - var input = this.input; - var ip = this.ip; - - this.status = Zlib.RawInflateStream.Status.BLOCK_BODY_START; - - if (ip + 4 >= input.length) { - return -1; - } - - len = input[ip++] | (input[ip++] << 8); - nlen = input[ip++] | (input[ip++] << 8); - - // check len & nlen - if (len === ~nlen) { - throw new Error('invalid uncompressed block header: length verify'); - } - - // skip buffered header bits - this.bitsbuf = 0; - this.bitsbuflen = 0; - - this.ip = ip; - this.blockLength = len; - this.status = Zlib.RawInflateStream.Status.BLOCK_BODY_END; -}; - -/** - * parse uncompressed block. - */ -Zlib.RawInflateStream.prototype.parseUncompressedBlock = function() { - var input = this.input; - var ip = this.ip; - var output = this.output; - var op = this.op; - var len = this.blockLength; - - this.status = Zlib.RawInflateStream.Status.DECODE_BLOCK_START; - - // copy - // XXX: とりあえず素直にコピー - while (len--) { - if (op === output.length) { - output = this.expandBuffer({fixRatio: 2}); - } - - // not enough input buffer - if (ip >= input.length) { - this.ip = ip; - this.op = op; - this.blockLength = len + 1; // コピーしてないので戻す - return -1; - } - - output[op++] = input[ip++]; - } - - if (len < 0) { - this.status = Zlib.RawInflateStream.Status.DECODE_BLOCK_END; - } - - this.ip = ip; - this.op = op; - - return 0; -}; - -/** - * parse fixed huffman block. - */ -Zlib.RawInflateStream.prototype.parseFixedHuffmanBlock = function() { - this.status = Zlib.RawInflateStream.Status.BLOCK_BODY_START; - - this.litlenTable = Zlib.RawInflateStream.FixedLiteralLengthTable; - this.distTable = Zlib.RawInflateStream.FixedDistanceTable; - - this.status = Zlib.RawInflateStream.Status.BLOCK_BODY_END; - - return 0; -}; - -/** - * オブジェクトのコンテキストを別のプロパティに退避する. - * @private - */ -Zlib.RawInflateStream.prototype.save_ = function() { - this.ip_ = this.ip; - this.bitsbuflen_ = this.bitsbuflen; - this.bitsbuf_ = this.bitsbuf; -}; - -/** - * 別のプロパティに退避したコンテキストを復元する. - * @private - */ -Zlib.RawInflateStream.prototype.restore_ = function() { - this.ip = this.ip_; - this.bitsbuflen = this.bitsbuflen_; - this.bitsbuf = this.bitsbuf_; -}; - -/** - * parse dynamic huffman block. - */ -Zlib.RawInflateStream.prototype.parseDynamicHuffmanBlock = function() { - /** @type {number} number of literal and length codes. */ - var hlit; - /** @type {number} number of distance codes. */ - var hdist; - /** @type {number} number of code lengths. */ - var hclen; - /** @type {!(Uint8Array|Array)} code lengths. */ - var codeLengths = - new (USE_TYPEDARRAY ? Uint8Array : Array)(Zlib.RawInflateStream.Order.length); - /** @type {!Array} code lengths table. */ - var codeLengthsTable; - /** @type {!(Uint32Array|Array)} literal and length code lengths. */ - var litlenLengths; - /** @type {!(Uint32Array|Array)} distance code lengths. */ - var distLengths; - - this.status = Zlib.RawInflateStream.Status.BLOCK_BODY_START; - - this.save_(); - hlit = this.readBits(5) + 257; - hdist = this.readBits(5) + 1; - hclen = this.readBits(4) + 4; - if (hlit < 0 || hdist < 0 || hclen < 0) { - this.restore_(); - return -1; - } - - try { - parseDynamicHuffmanBlockImpl.call(this); - } catch(e) { - this.restore_(); - return -1; - } - - function parseDynamicHuffmanBlockImpl() { - /** @type {number} */ - var bits; - var code; - var prev = 0; - var repeat; - /** @type {!(Uint8Array|Array.)} code length table. */ - var lengthTable; - /** @type {number} loop counter. */ - var i; - /** @type {number} loop limit. */ - var il; - - // decode code lengths - for (i = 0; i < hclen; ++i) { - if ((bits = this.readBits(3)) < 0) { - throw new Error('not enough input'); - } - codeLengths[Zlib.RawInflateStream.Order[i]] = bits; - } - - // decode length table - codeLengthsTable = buildHuffmanTable(codeLengths); - lengthTable = new (USE_TYPEDARRAY ? Uint8Array : Array)(hlit + hdist); - for (i = 0, il = hlit + hdist; i < il;) { - code = this.readCodeByTable(codeLengthsTable); - if (code < 0) { - throw new Error('not enough input'); - } - switch (code) { - case 16: - if ((bits = this.readBits(2)) < 0) { - throw new Error('not enough input'); - } - repeat = 3 + bits; - while (repeat--) { lengthTable[i++] = prev; } - break; - case 17: - if ((bits = this.readBits(3)) < 0) { - throw new Error('not enough input'); - } - repeat = 3 + bits; - while (repeat--) { lengthTable[i++] = 0; } - prev = 0; - break; - case 18: - if ((bits = this.readBits(7)) < 0) { - throw new Error('not enough input'); - } - repeat = 11 + bits; - while (repeat--) { lengthTable[i++] = 0; } - prev = 0; - break; - default: - lengthTable[i++] = code; - prev = code; - break; - } - } - - // literal and length code - litlenLengths = new (USE_TYPEDARRAY ? Uint8Array : Array)(hlit); - - // distance code - distLengths = new (USE_TYPEDARRAY ? Uint8Array : Array)(hdist); - - this.litlenTable = USE_TYPEDARRAY - ? buildHuffmanTable(lengthTable.subarray(0, hlit)) - : buildHuffmanTable(lengthTable.slice(0, hlit)); - this.distTable = USE_TYPEDARRAY - ? buildHuffmanTable(lengthTable.subarray(hlit)) - : buildHuffmanTable(lengthTable.slice(hlit)); - } - - this.status = Zlib.RawInflateStream.Status.BLOCK_BODY_END; - - return 0; -}; - -/** - * decode huffman code (dynamic) - * @return {(number|undefined)} -1 is error. - */ -Zlib.RawInflateStream.prototype.decodeHuffman = function() { - var output = this.output; - var op = this.op; - - /** @type {number} huffman code. */ - var code; - /** @type {number} table index. */ - var ti; - /** @type {number} huffman code distination. */ - var codeDist; - /** @type {number} huffman code length. */ - var codeLength; - - var litlen = this.litlenTable; - var dist = this.distTable; - - var olength = output.length; - var bits; - - this.status = Zlib.RawInflateStream.Status.DECODE_BLOCK_START; - - while (true) { - this.save_(); - - code = this.readCodeByTable(litlen); - if (code < 0) { - this.op = op; - this.restore_(); - return -1; - } - - if (code === 256) { - break; - } - - // literal - if (code < 256) { - if (op === olength) { - output = this.expandBuffer(); - olength = output.length; - } - output[op++] = code; - - continue; - } - - // length code - ti = code - 257; - codeLength = Zlib.RawInflateStream.LengthCodeTable[ti]; - if (Zlib.RawInflateStream.LengthExtraTable[ti] > 0) { - bits = this.readBits(Zlib.RawInflateStream.LengthExtraTable[ti]); - if (bits < 0) { - this.op = op; - this.restore_(); - return -1; - } - codeLength += bits; - } - - // dist code - code = this.readCodeByTable(dist); - if (code < 0) { - this.op = op; - this.restore_(); - return -1; - } - codeDist = Zlib.RawInflateStream.DistCodeTable[code]; - if (Zlib.RawInflateStream.DistExtraTable[code] > 0) { - bits = this.readBits(Zlib.RawInflateStream.DistExtraTable[code]); - if (bits < 0) { - this.op = op; - this.restore_(); - return -1; - } - codeDist += bits; - } - - // lz77 decode - if (op + codeLength >= olength) { - output = this.expandBuffer(); - olength = output.length; - } - - while (codeLength--) { - output[op] = output[(op++) - codeDist]; - } - - // break - if (this.ip === this.input.length) { - this.op = op; - return -1; - } - } - - while (this.bitsbuflen >= 8) { - this.bitsbuflen -= 8; - this.ip--; - } - - this.op = op; - this.status = Zlib.RawInflateStream.Status.DECODE_BLOCK_END; -}; - -/** - * expand output buffer. (dynamic) - * @param {Object=} opt_param option parameters. - * @return {!(Array|Uint8Array)} output buffer pointer. - */ -Zlib.RawInflateStream.prototype.expandBuffer = function(opt_param) { - /** @type {!(Array|Uint8Array)} store buffer. */ - var buffer; - /** @type {number} expantion ratio. */ - var ratio = (this.input.length / this.ip + 1) | 0; - /** @type {number} maximum number of huffman code. */ - var maxHuffCode; - /** @type {number} new output buffer size. */ - var newSize; - /** @type {number} max inflate size. */ - var maxInflateSize; - - var input = this.input; - var output = this.output; - - if (opt_param) { - if (typeof opt_param.fixRatio === 'number') { - ratio = opt_param.fixRatio; - } - if (typeof opt_param.addRatio === 'number') { - ratio += opt_param.addRatio; - } - } - - // calculate new buffer size - if (ratio < 2) { - maxHuffCode = - (input.length - this.ip) / this.litlenTable[2]; - maxInflateSize = (maxHuffCode / 2 * 258) | 0; - newSize = maxInflateSize < output.length ? - output.length + maxInflateSize : - output.length << 1; - } else { - newSize = output.length * ratio; - } - - // buffer expantion - if (USE_TYPEDARRAY) { - buffer = new Uint8Array(newSize); - buffer.set(output); - } else { - buffer = output; - } - - this.output = buffer; - - return this.output; -}; - -/** - * concat output buffer. (dynamic) - * @return {!(Array|Uint8Array)} output buffer. - */ -Zlib.RawInflateStream.prototype.concatBuffer = function() { - /** @type {!(Array|Uint8Array)} output buffer. */ - var buffer; - /** @type {number} */ - var op = this.op; - /** @type {Uint8Array} */ - var tmp; - - if (this.resize) { - if (USE_TYPEDARRAY) { - buffer = new Uint8Array(this.output.subarray(this.sp, op)); - } else { - buffer = this.output.slice(this.sp, op); - } - } else { - buffer = - USE_TYPEDARRAY ? this.output.subarray(this.sp, op) : this.output.slice(this.sp, op); - } - - this.sp = op; - - // compaction - if (op > Zlib.RawInflateStream.MaxBackwardLength + this.bufferSize) { - this.op = this.sp = Zlib.RawInflateStream.MaxBackwardLength; - if (USE_TYPEDARRAY) { - tmp = /** @type {Uint8Array} */(this.output); - this.output = new Uint8Array(this.bufferSize + Zlib.RawInflateStream.MaxBackwardLength); - this.output.set(tmp.subarray(op - Zlib.RawInflateStream.MaxBackwardLength, op)); - } else { - this.output = this.output.slice(op - Zlib.RawInflateStream.MaxBackwardLength); - } - } - - return buffer; -}; - - -/** - * @constructor - * @param {!(Uint8Array|Array)} input deflated buffer. - * @param {Object=} opt_params option parameters. - * - * opt_params は以下のプロパティを指定する事ができます。 - * - index: input buffer の deflate コンテナの開始位置. - * - blockSize: バッファのブロックサイズ. - * - verify: 伸張が終わった後 adler-32 checksum の検証を行うか. - * - bufferType: Zlib.Inflate.BufferType の値によってバッファの管理方法を指定する. - * Zlib.Inflate.BufferType は Zlib.RawInflate.BufferType のエイリアス. - */ -Zlib.Inflate = function(input, opt_params) { - /** @type {number} */ - var bufferSize; - /** @type {Zlib.Inflate.BufferType} */ - var bufferType; - /** @type {number} */ - var cmf; - /** @type {number} */ - var flg; - - /** @type {!(Uint8Array|Array)} */ - this.input = input; - /** @type {number} */ - this.ip = 0; - /** @type {Zlib.RawInflate} */ - this.rawinflate; - /** @type {(boolean|undefined)} verify flag. */ - this.verify; - - // option parameters - if (opt_params || !(opt_params = {})) { - if (opt_params['index']) { - this.ip = opt_params['index']; - } - if (opt_params['verify']) { - this.verify = opt_params['verify']; - } - } - - // Compression Method and Flags - cmf = input[this.ip++]; - flg = input[this.ip++]; - - // compression method - switch (cmf & 0x0f) { - case Zlib.CompressionMethod.DEFLATE: - this.method = Zlib.CompressionMethod.DEFLATE; - break; - default: - throw new Error('unsupported compression method'); - } - - // fcheck - if (((cmf << 8) + flg) % 31 !== 0) { - throw new Error('invalid fcheck flag:' + ((cmf << 8) + flg) % 31); - } - - // fdict (not supported) - if (flg & 0x20) { - throw new Error('fdict flag is not supported'); - } - - // RawInflate - this.rawinflate = new Zlib.RawInflate(input, { - 'index': this.ip, - 'bufferSize': opt_params['bufferSize'], - 'bufferType': opt_params['bufferType'], - 'resize': opt_params['resize'] - }); -} - -/** - * @enum {number} - */ -Zlib.Inflate.BufferType = Zlib.RawInflate.BufferType; - -/** - * decompress. - * @return {!(Uint8Array|Array)} inflated buffer. - */ -Zlib.Inflate.prototype.decompress = function() { - /** @type {!(Array|Uint8Array)} input buffer. */ - var input = this.input; - /** @type {!(Uint8Array|Array)} inflated buffer. */ - var buffer; - /** @type {number} adler-32 checksum */ - var adler32; - - buffer = this.rawinflate.decompress(); - this.ip = this.rawinflate.ip; - - // verify adler-32 - if (this.verify) { - adler32 = ( - input[this.ip++] << 24 | input[this.ip++] << 16 | - input[this.ip++] << 8 | input[this.ip++] - ) >>> 0; - - if (adler32 !== Zlib.Adler32(buffer)) { - throw new Error('invalid adler-32 checksum'); - } - } - - return buffer; -}; - - -/* vim:set expandtab ts=2 sw=2 tw=80: */ - - -/** - * @param {!(Uint8Array|Array)} input deflated buffer. - * @constructor - */ -Zlib.InflateStream = function(input) { - /** @type {!(Uint8Array|Array)} */ - this.input = input === void 0 ? new (USE_TYPEDARRAY ? Uint8Array : Array)() : input; - /** @type {number} */ - this.ip = 0; - /** @type {Zlib.RawInflateStream} */ - this.rawinflate = new Zlib.RawInflateStream(this.input, this.ip); - /** @type {Zlib.CompressionMethod} */ - this.method; - /** @type {!(Array|Uint8Array)} */ - this.output = this.rawinflate.output; -}; - -/** - * decompress. - * @return {!(Uint8Array|Array)} inflated buffer. - */ -Zlib.InflateStream.prototype.decompress = function(input) { - /** @type {!(Uint8Array|Array)} inflated buffer. */ - var buffer; - /** @type {number} adler-32 checksum */ - var adler32; - - // 新しい入力を入力バッファに結合する - // XXX Array, Uint8Array のチェックを行うか確認する - if (input !== void 0) { - if (USE_TYPEDARRAY) { - var tmp = new Uint8Array(this.input.length + input.length); - tmp.set(this.input, 0); - tmp.set(input, this.input.length); - this.input = tmp; - } else { - this.input = this.input.concat(input); - } - } - - if (this.method === void 0) { - if(this.readHeader() < 0) { - return new (USE_TYPEDARRAY ? Uint8Array : Array)(); - } - } - - buffer = this.rawinflate.decompress(this.input, this.ip); - if (this.rawinflate.ip !== 0) { - this.input = USE_TYPEDARRAY ? - this.input.subarray(this.rawinflate.ip) : - this.input.slice(this.rawinflate.ip); - this.ip = 0; - } - - // verify adler-32 - /* - if (this.verify) { - adler32 = - input[this.ip++] << 24 | input[this.ip++] << 16 | - input[this.ip++] << 8 | input[this.ip++]; - - if (adler32 !== Zlib.Adler32(buffer)) { - throw new Error('invalid adler-32 checksum'); - } - } - */ - - return buffer; -}; - -Zlib.InflateStream.prototype.readHeader = function() { - var ip = this.ip; - var input = this.input; - - // Compression Method and Flags - var cmf = input[ip++]; - var flg = input[ip++]; - - if (cmf === void 0 || flg === void 0) { - return -1; - } - - // compression method - switch (cmf & 0x0f) { - case Zlib.CompressionMethod.DEFLATE: - this.method = Zlib.CompressionMethod.DEFLATE; - break; - default: - throw new Error('unsupported compression method'); - } - - // fcheck - if (((cmf << 8) + flg) % 31 !== 0) { - throw new Error('invalid fcheck flag:' + ((cmf << 8) + flg) % 31); - } - - // fdict (not supported) - if (flg & 0x20) { - throw new Error('fdict flag is not supported'); - } - - this.ip = ip; -}; - - -/** - * @fileoverview GZIP (RFC1952) 展開コンテナ実装. - */ - -/** - * @constructor - * @param {!(Array|Uint8Array)} input input buffer. - * @param {Object=} opt_params option parameters. - */ -Zlib.Gunzip = function(input, opt_params) { - /** @type {!(Array.|Uint8Array)} input buffer. */ - this.input = input; - /** @type {number} input buffer pointer. */ - this.ip = 0; - /** @type {Array.} */ - this.member = []; - /** @type {boolean} */ - this.decompressed = false; -}; - -/** - * @return {Array.} - */ -Zlib.Gunzip.prototype.getMembers = function() { - if (!this.decompressed) { - this.decompress(); - } - - return this.member.slice(); -}; - -/** - * inflate gzip data. - * @return {!(Array.|Uint8Array)} inflated buffer. - */ -Zlib.Gunzip.prototype.decompress = function() { - /** @type {number} input length. */ - var il = this.input.length; - - while (this.ip < il) { - this.decodeMember(); - } - - this.decompressed = true; - - return this.concatMember(); -}; - -/** - * decode gzip member. - */ -Zlib.Gunzip.prototype.decodeMember = function() { - /** @type {Zlib.GunzipMember} */ - var member = new Zlib.GunzipMember(); - /** @type {number} */ - var isize; - /** @type {Zlib.RawInflate} RawInflate implementation. */ - var rawinflate; - /** @type {!(Array.|Uint8Array)} inflated data. */ - var inflated; - /** @type {number} inflate size */ - var inflen; - /** @type {number} character code */ - var c; - /** @type {number} character index in string. */ - var ci; - /** @type {Array.} character array. */ - var str; - /** @type {number} modification time. */ - var mtime; - /** @type {number} */ - var crc32; - - var input = this.input; - var ip = this.ip; - - member.id1 = input[ip++]; - member.id2 = input[ip++]; - - // check signature - if (member.id1 !== 0x1f || member.id2 !== 0x8b) { - throw new Error('invalid file signature:' + member.id1 + ',' + member.id2); - } - - // check compression method - member.cm = input[ip++]; - switch (member.cm) { - case 8: /* XXX: use Zlib const */ - break; - default: - throw new Error('unknown compression method: ' + member.cm); - } - - // flags - member.flg = input[ip++]; - - // modification time - mtime = (input[ip++]) | - (input[ip++] << 8) | - (input[ip++] << 16) | - (input[ip++] << 24); - member.mtime = new Date(mtime * 1000); - - // extra flags - member.xfl = input[ip++]; - - // operating system - member.os = input[ip++]; - - // extra - if ((member.flg & Zlib.Gzip.FlagsMask.FEXTRA) > 0) { - member.xlen = input[ip++] | (input[ip++] << 8); - ip = this.decodeSubField(ip, member.xlen); - } - - // fname - if ((member.flg & Zlib.Gzip.FlagsMask.FNAME) > 0) { - for(str = [], ci = 0; (c = input[ip++]) > 0;) { - str[ci++] = String.fromCharCode(c); - } - member.name = str.join(''); - } - - // fcomment - if ((member.flg & Zlib.Gzip.FlagsMask.FCOMMENT) > 0) { - for(str = [], ci = 0; (c = input[ip++]) > 0;) { - str[ci++] = String.fromCharCode(c); - } - member.comment = str.join(''); - } - - // fhcrc - if ((member.flg & Zlib.Gzip.FlagsMask.FHCRC) > 0) { - member.crc16 = Zlib.CRC32.calc(input, 0, ip) & 0xffff; - if (member.crc16 !== (input[ip++] | (input[ip++] << 8))) { - throw new Error('invalid header crc16'); - } - } - - // isize を事前に取得すると展開後のサイズが分かるため、 - // inflate処理のバッファサイズが事前に分かり、高速になる - isize = (input[input.length - 4]) | (input[input.length - 3] << 8) | - (input[input.length - 2] << 16) | (input[input.length - 1] << 24); - - // isize の妥当性チェック - // ハフマン符号では最小 2-bit のため、最大で 1/4 になる - // LZ77 符号では 長さと距離 2-Byte で最大 258-Byte を表現できるため、 - // 1/128 になるとする - // ここから入力バッファの残りが isize の 512 倍以上だったら - // サイズ指定のバッファ確保は行わない事とする - if (input.length - ip - /* CRC-32 */4 - /* ISIZE */4 < isize * 512) { - inflen = isize; - } - - // compressed block - rawinflate = new Zlib.RawInflate(input, {'index': ip, 'bufferSize': inflen}); - member.data = inflated = rawinflate.decompress(); - ip = rawinflate.ip; - - // crc32 - member.crc32 = crc32 = - ((input[ip++]) | (input[ip++] << 8) | - (input[ip++] << 16) | (input[ip++] << 24)) >>> 0; - if (Zlib.CRC32.calc(inflated) !== crc32) { - throw new Error('invalid CRC-32 checksum: 0x' + - Zlib.CRC32.calc(inflated).toString(16) + ' / 0x' + crc32.toString(16)); - } - - // input size - member.isize = isize = - ((input[ip++]) | (input[ip++] << 8) | - (input[ip++] << 16) | (input[ip++] << 24)) >>> 0; - if ((inflated.length & 0xffffffff) !== isize) { - throw new Error('invalid input size: ' + - (inflated.length & 0xffffffff) + ' / ' + isize); - } - - this.member.push(member); - this.ip = ip; -}; - -/** - * サブフィールドのデコード - * XXX: 現在は何もせずスキップする - */ -Zlib.Gunzip.prototype.decodeSubField = function(ip, length) { - return ip + length; -}; - -/** - * @return {!(Array.|Uint8Array)} - */ -Zlib.Gunzip.prototype.concatMember = function() { - /** @type {Array.} */ - var member = this.member; - /** @type {number} */ - var i; - /** @type {number} */ - var il; - /** @type {number} */ - var p = 0; - /** @type {number} */ - var size = 0; - /** @type {!(Array.|Uint8Array)} */ - var buffer; - - for (i = 0, il = member.length; i < il; ++i) { - size += member[i].data.length; - } - - if (USE_TYPEDARRAY) { - buffer = new Uint8Array(size); - for (i = 0; i < il; ++i) { - buffer.set(member[i].data, p); - p += member[i].data.length; - } - } else { - buffer = []; - for (i = 0; i < il; ++i) { - buffer[i] = member[i].data; - } - buffer = Array.prototype.concat.apply([], buffer); - } - - return buffer; -}; - - - -/** - * @constructor - */ -Zlib.GunzipMember = function() { - /** @type {number} signature first byte. */ - this.id1; - /** @type {number} signature second byte. */ - this.id2; - /** @type {number} compression method. */ - this.cm; - /** @type {number} flags. */ - this.flg; - /** @type {Date} modification time. */ - this.mtime; - /** @type {number} extra flags. */ - this.xfl; - /** @type {number} operating system number. */ - this.os; - /** @type {number} CRC-16 value for FHCRC flag. */ - this.crc16; - /** @type {number} extra length. */ - this.xlen; - /** @type {number} CRC-32 value for verification. */ - this.crc32; - /** @type {number} input size modulo 32 value. */ - this.isize; - /** @type {string} filename. */ - this.name; - /** @type {string} comment. */ - this.comment; - /** @type {!(Uint8Array|Array.)} */ - this.data; -}; - -Zlib.GunzipMember.prototype.getName = function() { - return this.name; -}; - -Zlib.GunzipMember.prototype.getData = function() { - return this.data; -}; - -Zlib.GunzipMember.prototype.getMtime = function() { - return this.mtime; -} - -/** - * @fileoverview GZIP (RFC1952) 実装. - */ - -/** - * @constructor - * @param {!(Array|Uint8Array)} input input buffer. - * @param {Object=} opt_params option parameters. - */ -Zlib.Gzip = function(input, opt_params) { - /** @type {!(Array.|Uint8Array)} input buffer. */ - this.input = input; - /** @type {number} input buffer pointer. */ - this.ip = 0; - /** @type {!(Array.|Uint8Array)} output buffer. */ - this.output; - /** @type {number} output buffer. */ - this.op = 0; - /** @type {!Object} flags option flags. */ - this.flags = {}; - /** @type {!string} filename. */ - this.filename; - /** @type {!string} comment. */ - this.comment; - /** @type {!Object} deflate options. */ - this.deflateOptions; - - // option parameters - if (opt_params) { - if (opt_params['flags']) { - this.flags = opt_params['flags']; - } - if (typeof opt_params['filename'] === 'string') { - this.filename = opt_params['filename']; - } - if (typeof opt_params['comment'] === 'string') { - this.comment = opt_params['comment']; - } - if (opt_params['deflateOptions']) { - this.deflateOptions = opt_params['deflateOptions']; - } - } - - if (!this.deflateOptions) { - this.deflateOptions = {}; - } -}; - -/** - * @type {number} - * @const - */ -Zlib.Gzip.DefaultBufferSize = 0x8000; - -/** - * encode gzip members. - * @return {!(Array|Uint8Array)} gzip binary array. - */ -Zlib.Gzip.prototype.compress = function() { - /** @type {number} flags. */ - var flg; - /** @type {number} modification time. */ - var mtime; - /** @type {number} CRC-16 value for FHCRC flag. */ - var crc16; - /** @type {number} CRC-32 value for verification. */ - var crc32; - /** @type {!Zlib.RawDeflate} raw deflate object. */ - var rawdeflate; - /** @type {number} character code */ - var c; - /** @type {number} loop counter. */ - var i; - /** @type {number} loop limiter. */ - var il; - /** @type {!(Array|Uint8Array)} output buffer. */ - var output = - new (USE_TYPEDARRAY ? Uint8Array : Array)(Zlib.Gzip.DefaultBufferSize); - /** @type {number} output buffer pointer. */ - var op = 0; - - var input = this.input; - var ip = this.ip; - var filename = this.filename; - var comment = this.comment; - - // check signature - output[op++] = 0x1f; - output[op++] = 0x8b; - - // check compression method - output[op++] = 8; /* XXX: use Zlib const */ - - // flags - flg = 0; - if (this.flags['fname']) flg |= Zlib.Gzip.FlagsMask.FNAME; - if (this.flags['fcomment']) flg |= Zlib.Gzip.FlagsMask.FCOMMENT; - if (this.flags['fhcrc']) flg |= Zlib.Gzip.FlagsMask.FHCRC; - // XXX: FTEXT - // XXX: FEXTRA - output[op++] = flg; - - // modification time - mtime = (Date.now ? Date.now() : +new Date()) / 1000 | 0; - output[op++] = mtime & 0xff; - output[op++] = mtime >>> 8 & 0xff; - output[op++] = mtime >>> 16 & 0xff; - output[op++] = mtime >>> 24 & 0xff; - - // extra flags - output[op++] = 0; - - // operating system - output[op++] = Zlib.Gzip.OperatingSystem.UNKNOWN; - - // extra - /* NOP */ - - // fname - if (this.flags['fname'] !== void 0) { - for (i = 0, il = filename.length; i < il; ++i) { - c = filename.charCodeAt(i); - if (c > 0xff) { output[op++] = (c >>> 8) & 0xff; } - output[op++] = c & 0xff; - } - output[op++] = 0; // null termination - } - - // fcomment - if (this.flags['comment']) { - for (i = 0, il = comment.length; i < il; ++i) { - c = comment.charCodeAt(i); - if (c > 0xff) { output[op++] = (c >>> 8) & 0xff; } - output[op++] = c & 0xff; - } - output[op++] = 0; // null termination - } - - // fhcrc - if (this.flags['fhcrc']) { - crc16 = Zlib.CRC32.calc(output, 0, op) & 0xffff; - output[op++] = (crc16 ) & 0xff; - output[op++] = (crc16 >>> 8) & 0xff; - } - - // add compress option - this.deflateOptions['outputBuffer'] = output; - this.deflateOptions['outputIndex'] = op; - - // compress - rawdeflate = new Zlib.RawDeflate(input, this.deflateOptions); - output = rawdeflate.compress(); - op = rawdeflate.op; - - // expand buffer - if (USE_TYPEDARRAY) { - if (op + 8 > output.buffer.byteLength) { - this.output = new Uint8Array(op + 8); - this.output.set(new Uint8Array(output.buffer)); - output = this.output; - } else { - output = new Uint8Array(output.buffer); - } - } - - // crc32 - crc32 = Zlib.CRC32.calc(input); - output[op++] = (crc32 ) & 0xff; - output[op++] = (crc32 >>> 8) & 0xff; - output[op++] = (crc32 >>> 16) & 0xff; - output[op++] = (crc32 >>> 24) & 0xff; - - // input size - il = input.length; - output[op++] = (il ) & 0xff; - output[op++] = (il >>> 8) & 0xff; - output[op++] = (il >>> 16) & 0xff; - output[op++] = (il >>> 24) & 0xff; - - this.ip = ip; - - if (USE_TYPEDARRAY && op < output.length) { - this.output = output = output.subarray(0, op); - } - - return output; -}; - -/** @enum {number} */ -Zlib.Gzip.OperatingSystem = { - FAT: 0, - AMIGA: 1, - VMS: 2, - UNIX: 3, - VM_CMS: 4, - ATARI_TOS: 5, - HPFS: 6, - MACINTOSH: 7, - Z_SYSTEM: 8, - CP_M: 9, - TOPS_20: 10, - NTFS: 11, - QDOS: 12, - ACORN_RISCOS: 13, - UNKNOWN: 255 -}; - -/** @enum {number} */ -Zlib.Gzip.FlagsMask = { - FTEXT: 0x01, - FHCRC: 0x02, - FEXTRA: 0x04, - FNAME: 0x08, - FCOMMENT: 0x10 -}; - - -/** - * @fileoverview Heap Sort 実装. ハフマン符号化で使用する. - */ - -/** - * カスタムハフマン符号で使用するヒープ実装 - * @param {number} length ヒープサイズ. - * @constructor - */ -Zlib.Heap = function(length) { - this.buffer = new (USE_TYPEDARRAY ? Uint16Array : Array)(length * 2); - this.length = 0; -}; - -/** - * 親ノードの index 取得 - * @param {number} index 子ノードの index. - * @return {number} 親ノードの index. - * - */ -Zlib.Heap.prototype.getParent = function(index) { - return ((index - 2) / 4 | 0) * 2; -}; - -/** - * 子ノードの index 取得 - * @param {number} index 親ノードの index. - * @return {number} 子ノードの index. - */ -Zlib.Heap.prototype.getChild = function(index) { - return 2 * index + 2; -}; - -/** - * Heap に値を追加する - * @param {number} index キー index. - * @param {number} value 値. - * @return {number} 現在のヒープ長. - */ -Zlib.Heap.prototype.push = function(index, value) { - var current, parent, - heap = this.buffer, - swap; - - current = this.length; - heap[this.length++] = value; - heap[this.length++] = index; - - // ルートノードにたどり着くまで入れ替えを試みる - while (current > 0) { - parent = this.getParent(current); - - // 親ノードと比較して親の方が小さければ入れ替える - if (heap[current] > heap[parent]) { - swap = heap[current]; - heap[current] = heap[parent]; - heap[parent] = swap; - - swap = heap[current + 1]; - heap[current + 1] = heap[parent + 1]; - heap[parent + 1] = swap; - - current = parent; - // 入れ替えが必要なくなったらそこで抜ける - } else { - break; - } - } - - return this.length; -}; - -/** - * Heapから一番大きい値を返す - * @return {{index: number, value: number, length: number}} {index: キーindex, - * value: 値, length: ヒープ長} の Object. - */ -Zlib.Heap.prototype.pop = function() { - var index, value, - heap = this.buffer, swap, - current, parent; - - value = heap[0]; - index = heap[1]; - - // 後ろから値を取る - this.length -= 2; - heap[0] = heap[this.length]; - heap[1] = heap[this.length + 1]; - - parent = 0; - // ルートノードから下がっていく - while (true) { - current = this.getChild(parent); - - // 範囲チェック - if (current >= this.length) { - break; - } - - // 隣のノードと比較して、隣の方が値が大きければ隣を現在ノードとして選択 - if (current + 2 < this.length && heap[current + 2] > heap[current]) { - current += 2; - } - - // 親ノードと比較して親の方が小さい場合は入れ替える - if (heap[current] > heap[parent]) { - swap = heap[parent]; - heap[parent] = heap[current]; - heap[current] = swap; - - swap = heap[parent + 1]; - heap[parent + 1] = heap[current + 1]; - heap[current + 1] = swap; - } else { - break; - } - - parent = current; - } - - return {index: index, value: value, length: this.length}; -}; - - -/* vim:set expandtab ts=2 sw=2 tw=80: */ - -/** - * @fileoverview Deflate (RFC1951) 符号化アルゴリズム実装. - */ - - -/** - * Raw Deflate 実装 - * - * @constructor - * @param {!(Array.|Uint8Array)} input 符号化する対象のバッファ. - * @param {Object=} opt_params option parameters. - * - * typed array が使用可能なとき、outputBuffer が Array は自動的に Uint8Array に - * 変換されます. - * 別のオブジェクトになるため出力バッファを参照している変数などは - * 更新する必要があります. - */ -Zlib.RawDeflate = function(input, opt_params) { - /** @type {Zlib.RawDeflate.CompressionType} */ - this.compressionType = Zlib.RawDeflate.CompressionType.DYNAMIC; - /** @type {number} */ - this.lazy = 0; - /** @type {!(Array.|Uint32Array)} */ - this.freqsLitLen; - /** @type {!(Array.|Uint32Array)} */ - this.freqsDist; - /** @type {!(Array.|Uint8Array)} */ - this.input = - (USE_TYPEDARRAY && input instanceof Array) ? new Uint8Array(input) : input; - /** @type {!(Array.|Uint8Array)} output output buffer. */ - this.output; - /** @type {number} pos output buffer position. */ - this.op = 0; - - // option parameters - if (opt_params) { - if (opt_params['lazy']) { - this.lazy = opt_params['lazy']; - } - if (typeof opt_params['compressionType'] === 'number') { - this.compressionType = opt_params['compressionType']; - } - if (opt_params['outputBuffer']) { - this.output = - (USE_TYPEDARRAY && opt_params['outputBuffer'] instanceof Array) ? - new Uint8Array(opt_params['outputBuffer']) : opt_params['outputBuffer']; - } - if (typeof opt_params['outputIndex'] === 'number') { - this.op = opt_params['outputIndex']; - } - } - - if (!this.output) { - this.output = new (USE_TYPEDARRAY ? Uint8Array : Array)(0x8000); - } -}; - -/** - * @enum {number} - */ -Zlib.RawDeflate.CompressionType = { - NONE: 0, - FIXED: 1, - DYNAMIC: 2, - RESERVED: 3 -}; - - -/** - * LZ77 の最小マッチ長 - * @const - * @type {number} - */ -Zlib.RawDeflate.Lz77MinLength = 3; - -/** - * LZ77 の最大マッチ長 - * @const - * @type {number} - */ -Zlib.RawDeflate.Lz77MaxLength = 258; - -/** - * LZ77 のウィンドウサイズ - * @const - * @type {number} - */ -Zlib.RawDeflate.WindowSize = 0x8000; - -/** - * 最長の符号長 - * @const - * @type {number} - */ -Zlib.RawDeflate.MaxCodeLength = 16; - -/** - * ハフマン符号の最大数値 - * @const - * @type {number} - */ -Zlib.RawDeflate.HUFMAX = 286; - -/** - * 固定ハフマン符号の符号化テーブル - * @const - * @type {Array.>} - */ -Zlib.RawDeflate.FixedHuffmanTable = (function() { - var table = [], i; - - for (i = 0; i < 288; i++) { - switch (true) { - case (i <= 143): table.push([i + 0x030, 8]); break; - case (i <= 255): table.push([i - 144 + 0x190, 9]); break; - case (i <= 279): table.push([i - 256 + 0x000, 7]); break; - case (i <= 287): table.push([i - 280 + 0x0C0, 8]); break; - default: - throw 'invalid literal: ' + i; - } - } - - return table; -})(); - -/** - * DEFLATE ブロックの作成 - * @return {!(Array.|Uint8Array)} 圧縮済み byte array. - */ -Zlib.RawDeflate.prototype.compress = function() { - /** @type {!(Array.|Uint8Array)} */ - var blockArray; - /** @type {number} */ - var position; - /** @type {number} */ - var length; - - var input = this.input; - - // compression - switch (this.compressionType) { - case Zlib.RawDeflate.CompressionType.NONE: - // each 65535-Byte (length header: 16-bit) - for (position = 0, length = input.length; position < length;) { - blockArray = USE_TYPEDARRAY ? - input.subarray(position, position + 0xffff) : - input.slice(position, position + 0xffff); - position += blockArray.length; - this.makeNocompressBlock(blockArray, (position === length)); - } - break; - case Zlib.RawDeflate.CompressionType.FIXED: - this.output = this.makeFixedHuffmanBlock(input, true); - this.op = this.output.length; - break; - case Zlib.RawDeflate.CompressionType.DYNAMIC: - this.output = this.makeDynamicHuffmanBlock(input, true); - this.op = this.output.length; - break; - default: - throw 'invalid compression type'; - } - - return this.output; -}; - -/** - * 非圧縮ブロックの作成 - * @param {!(Array.|Uint8Array)} blockArray ブロックデータ byte array. - * @param {!boolean} isFinalBlock 最後のブロックならばtrue. - * @return {!(Array.|Uint8Array)} 非圧縮ブロック byte array. - */ -Zlib.RawDeflate.prototype.makeNocompressBlock = -function(blockArray, isFinalBlock) { - /** @type {number} */ - var bfinal; - /** @type {Zlib.RawDeflate.CompressionType} */ - var btype; - /** @type {number} */ - var len; - /** @type {number} */ - var nlen; - /** @type {number} */ - var i; - /** @type {number} */ - var il; - - var output = this.output; - var op = this.op; - - // expand buffer - if (USE_TYPEDARRAY) { - output = new Uint8Array(this.output.buffer); - while (output.length <= op + blockArray.length + 5) { - output = new Uint8Array(output.length << 1); - } - output.set(this.output); - } - - // header - bfinal = isFinalBlock ? 1 : 0; - btype = Zlib.RawDeflate.CompressionType.NONE; - output[op++] = (bfinal) | (btype << 1); - - // length - len = blockArray.length; - nlen = (~len + 0x10000) & 0xffff; - output[op++] = len & 0xff; - output[op++] = (len >>> 8) & 0xff; - output[op++] = nlen & 0xff; - output[op++] = (nlen >>> 8) & 0xff; - - // copy buffer - if (USE_TYPEDARRAY) { - output.set(blockArray, op); - op += blockArray.length; - output = output.subarray(0, op); - } else { - for (i = 0, il = blockArray.length; i < il; ++i) { - output[op++] = blockArray[i]; - } - output.length = op; - } - - this.op = op; - this.output = output; - - return output; -}; - -/** - * 固定ハフマンブロックの作成 - * @param {!(Array.|Uint8Array)} blockArray ブロックデータ byte array. - * @param {!boolean} isFinalBlock 最後のブロックならばtrue. - * @return {!(Array.|Uint8Array)} 固定ハフマン符号化ブロック byte array. - */ -Zlib.RawDeflate.prototype.makeFixedHuffmanBlock = -function(blockArray, isFinalBlock) { - /** @type {Zlib.BitStream} */ - var stream = new Zlib.BitStream(USE_TYPEDARRAY ? - new Uint8Array(this.output.buffer) : this.output, this.op); - /** @type {number} */ - var bfinal; - /** @type {Zlib.RawDeflate.CompressionType} */ - var btype; - /** @type {!(Array.|Uint16Array)} */ - var data; - - // header - bfinal = isFinalBlock ? 1 : 0; - btype = Zlib.RawDeflate.CompressionType.FIXED; - - stream.writeBits(bfinal, 1, true); - stream.writeBits(btype, 2, true); - - data = this.lz77(blockArray); - this.fixedHuffman(data, stream); - - return stream.finish(); -}; - -/** - * 動的ハフマンブロックの作成 - * @param {!(Array.|Uint8Array)} blockArray ブロックデータ byte array. - * @param {!boolean} isFinalBlock 最後のブロックならばtrue. - * @return {!(Array.|Uint8Array)} 動的ハフマン符号ブロック byte array. - */ -Zlib.RawDeflate.prototype.makeDynamicHuffmanBlock = -function(blockArray, isFinalBlock) { - /** @type {Zlib.BitStream} */ - var stream = new Zlib.BitStream(USE_TYPEDARRAY ? - new Uint8Array(this.output.buffer) : this.output, this.op); - /** @type {number} */ - var bfinal; - /** @type {Zlib.RawDeflate.CompressionType} */ - var btype; - /** @type {!(Array.|Uint16Array)} */ - var data; - /** @type {number} */ - var hlit; - /** @type {number} */ - var hdist; - /** @type {number} */ - var hclen; - /** @const @type {Array.} */ - var hclenOrder = - [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; - /** @type {!(Array.|Uint8Array)} */ - var litLenLengths; - /** @type {!(Array.|Uint16Array)} */ - var litLenCodes; - /** @type {!(Array.|Uint8Array)} */ - var distLengths; - /** @type {!(Array.|Uint16Array)} */ - var distCodes; - /** @type {{ - * codes: !(Array.|Uint32Array), - * freqs: !(Array.|Uint8Array) - * }} */ - var treeSymbols; - /** @type {!(Array.|Uint8Array)} */ - var treeLengths; - /** @type {Array} */ - var transLengths = new Array(19); - /** @type {!(Array.|Uint16Array)} */ - var treeCodes; - /** @type {number} */ - var code; - /** @type {number} */ - var bitlen; - /** @type {number} */ - var i; - /** @type {number} */ - var il; - - // header - bfinal = isFinalBlock ? 1 : 0; - btype = Zlib.RawDeflate.CompressionType.DYNAMIC; - - stream.writeBits(bfinal, 1, true); - stream.writeBits(btype, 2, true); - - data = this.lz77(blockArray); - - // リテラル・長さ, 距離のハフマン符号と符号長の算出 - litLenLengths = this.getLengths_(this.freqsLitLen, 15); - litLenCodes = this.getCodesFromLengths_(litLenLengths); - distLengths = this.getLengths_(this.freqsDist, 7); - distCodes = this.getCodesFromLengths_(distLengths); - - // HLIT, HDIST の決定 - for (hlit = 286; hlit > 257 && litLenLengths[hlit - 1] === 0; hlit--) {} - for (hdist = 30; hdist > 1 && distLengths[hdist - 1] === 0; hdist--) {} - - // HCLEN - treeSymbols = - this.getTreeSymbols_(hlit, litLenLengths, hdist, distLengths); - treeLengths = this.getLengths_(treeSymbols.freqs, 7); - for (i = 0; i < 19; i++) { - transLengths[i] = treeLengths[hclenOrder[i]]; - } - for (hclen = 19; hclen > 4 && transLengths[hclen - 1] === 0; hclen--) {} - - treeCodes = this.getCodesFromLengths_(treeLengths); - - // 出力 - stream.writeBits(hlit - 257, 5, true); - stream.writeBits(hdist - 1, 5, true); - stream.writeBits(hclen - 4, 4, true); - for (i = 0; i < hclen; i++) { - stream.writeBits(transLengths[i], 3, true); - } - - // ツリーの出力 - for (i = 0, il = treeSymbols.codes.length; i < il; i++) { - code = treeSymbols.codes[i]; - - stream.writeBits(treeCodes[code], treeLengths[code], true); - - // extra bits - if (code >= 16) { - i++; - switch (code) { - case 16: bitlen = 2; break; - case 17: bitlen = 3; break; - case 18: bitlen = 7; break; - default: - throw 'invalid code: ' + code; - } - - stream.writeBits(treeSymbols.codes[i], bitlen, true); - } - } - - this.dynamicHuffman( - data, - [litLenCodes, litLenLengths], - [distCodes, distLengths], - stream - ); - - return stream.finish(); -}; - - -/** - * 動的ハフマン符号化(カスタムハフマンテーブル) - * @param {!(Array.|Uint16Array)} dataArray LZ77 符号化済み byte array. - * @param {!Zlib.BitStream} stream 書き込み用ビットストリーム. - * @return {!Zlib.BitStream} ハフマン符号化済みビットストリームオブジェクト. - */ -Zlib.RawDeflate.prototype.dynamicHuffman = -function(dataArray, litLen, dist, stream) { - /** @type {number} */ - var index; - /** @type {number} */ - var length; - /** @type {number} */ - var literal; - /** @type {number} */ - var code; - /** @type {number} */ - var litLenCodes; - /** @type {number} */ - var litLenLengths; - /** @type {number} */ - var distCodes; - /** @type {number} */ - var distLengths; - - litLenCodes = litLen[0]; - litLenLengths = litLen[1]; - distCodes = dist[0]; - distLengths = dist[1]; - - // 符号を BitStream に書き込んでいく - for (index = 0, length = dataArray.length; index < length; ++index) { - literal = dataArray[index]; - - // literal or length - stream.writeBits(litLenCodes[literal], litLenLengths[literal], true); - - // 長さ・距離符号 - if (literal > 256) { - // length extra - stream.writeBits(dataArray[++index], dataArray[++index], true); - // distance - code = dataArray[++index]; - stream.writeBits(distCodes[code], distLengths[code], true); - // distance extra - stream.writeBits(dataArray[++index], dataArray[++index], true); - // 終端 - } else if (literal === 256) { - break; - } - } - - return stream; -}; - -/** - * 固定ハフマン符号化 - * @param {!(Array.|Uint16Array)} dataArray LZ77 符号化済み byte array. - * @param {!Zlib.BitStream} stream 書き込み用ビットストリーム. - * @return {!Zlib.BitStream} ハフマン符号化済みビットストリームオブジェクト. - */ -Zlib.RawDeflate.prototype.fixedHuffman = function(dataArray, stream) { - /** @type {number} */ - var index; - /** @type {number} */ - var length; - /** @type {number} */ - var literal; - - // 符号を BitStream に書き込んでいく - for (index = 0, length = dataArray.length; index < length; index++) { - literal = dataArray[index]; - - // 符号の書き込み - Zlib.BitStream.prototype.writeBits.apply( - stream, - Zlib.RawDeflate.FixedHuffmanTable[literal] - ); - - // 長さ・距離符号 - if (literal > 0x100) { - // length extra - stream.writeBits(dataArray[++index], dataArray[++index], true); - // distance - stream.writeBits(dataArray[++index], 5); - // distance extra - stream.writeBits(dataArray[++index], dataArray[++index], true); - // 終端 - } else if (literal === 0x100) { - break; - } - } - - return stream; -}; - -/** - * マッチ情報 - * @param {!number} length マッチした長さ. - * @param {!number} backwardDistance マッチ位置との距離. - * @constructor - */ -Zlib.RawDeflate.Lz77Match = function(length, backwardDistance) { - /** @type {number} match length. */ - this.length = length; - /** @type {number} backward distance. */ - this.backwardDistance = backwardDistance; -}; - -/** - * 長さ符号テーブル. - * [コード, 拡張ビット, 拡張ビット長] の配列となっている. - * @const - * @type {!(Array.|Uint32Array)} - */ -Zlib.RawDeflate.Lz77Match.LengthCodeTable = (function(table) { - return USE_TYPEDARRAY ? new Uint32Array(table) : table; -})((function() { - /** @type {!Array} */ - var table = []; - /** @type {number} */ - var i; - /** @type {!Array.} */ - var c; - - for (i = 3; i <= 258; i++) { - c = code(i); - table[i] = (c[2] << 24) | (c[1] << 16) | c[0]; - } - - /** - * @param {number} length lz77 length. - * @return {!Array.} lz77 codes. - */ - function code(length) { - switch (true) { - case (length === 3): return [257, length - 3, 0]; break; - case (length === 4): return [258, length - 4, 0]; break; - case (length === 5): return [259, length - 5, 0]; break; - case (length === 6): return [260, length - 6, 0]; break; - case (length === 7): return [261, length - 7, 0]; break; - case (length === 8): return [262, length - 8, 0]; break; - case (length === 9): return [263, length - 9, 0]; break; - case (length === 10): return [264, length - 10, 0]; break; - case (length <= 12): return [265, length - 11, 1]; break; - case (length <= 14): return [266, length - 13, 1]; break; - case (length <= 16): return [267, length - 15, 1]; break; - case (length <= 18): return [268, length - 17, 1]; break; - case (length <= 22): return [269, length - 19, 2]; break; - case (length <= 26): return [270, length - 23, 2]; break; - case (length <= 30): return [271, length - 27, 2]; break; - case (length <= 34): return [272, length - 31, 2]; break; - case (length <= 42): return [273, length - 35, 3]; break; - case (length <= 50): return [274, length - 43, 3]; break; - case (length <= 58): return [275, length - 51, 3]; break; - case (length <= 66): return [276, length - 59, 3]; break; - case (length <= 82): return [277, length - 67, 4]; break; - case (length <= 98): return [278, length - 83, 4]; break; - case (length <= 114): return [279, length - 99, 4]; break; - case (length <= 130): return [280, length - 115, 4]; break; - case (length <= 162): return [281, length - 131, 5]; break; - case (length <= 194): return [282, length - 163, 5]; break; - case (length <= 226): return [283, length - 195, 5]; break; - case (length <= 257): return [284, length - 227, 5]; break; - case (length === 258): return [285, length - 258, 0]; break; - default: throw 'invalid length: ' + length; - } - } - - return table; -})()); - -/** - * 距離符号テーブル - * @param {!number} dist 距離. - * @return {!Array.} コード、拡張ビット、拡張ビット長の配列. - * @private - */ -Zlib.RawDeflate.Lz77Match.prototype.getDistanceCode_ = function(dist) { - /** @type {!Array.} distance code table. */ - var r; - - switch (true) { - case (dist === 1): r = [0, dist - 1, 0]; break; - case (dist === 2): r = [1, dist - 2, 0]; break; - case (dist === 3): r = [2, dist - 3, 0]; break; - case (dist === 4): r = [3, dist - 4, 0]; break; - case (dist <= 6): r = [4, dist - 5, 1]; break; - case (dist <= 8): r = [5, dist - 7, 1]; break; - case (dist <= 12): r = [6, dist - 9, 2]; break; - case (dist <= 16): r = [7, dist - 13, 2]; break; - case (dist <= 24): r = [8, dist - 17, 3]; break; - case (dist <= 32): r = [9, dist - 25, 3]; break; - case (dist <= 48): r = [10, dist - 33, 4]; break; - case (dist <= 64): r = [11, dist - 49, 4]; break; - case (dist <= 96): r = [12, dist - 65, 5]; break; - case (dist <= 128): r = [13, dist - 97, 5]; break; - case (dist <= 192): r = [14, dist - 129, 6]; break; - case (dist <= 256): r = [15, dist - 193, 6]; break; - case (dist <= 384): r = [16, dist - 257, 7]; break; - case (dist <= 512): r = [17, dist - 385, 7]; break; - case (dist <= 768): r = [18, dist - 513, 8]; break; - case (dist <= 1024): r = [19, dist - 769, 8]; break; - case (dist <= 1536): r = [20, dist - 1025, 9]; break; - case (dist <= 2048): r = [21, dist - 1537, 9]; break; - case (dist <= 3072): r = [22, dist - 2049, 10]; break; - case (dist <= 4096): r = [23, dist - 3073, 10]; break; - case (dist <= 6144): r = [24, dist - 4097, 11]; break; - case (dist <= 8192): r = [25, dist - 6145, 11]; break; - case (dist <= 12288): r = [26, dist - 8193, 12]; break; - case (dist <= 16384): r = [27, dist - 12289, 12]; break; - case (dist <= 24576): r = [28, dist - 16385, 13]; break; - case (dist <= 32768): r = [29, dist - 24577, 13]; break; - default: throw 'invalid distance'; - } - - return r; -}; - -/** - * マッチ情報を LZ77 符号化配列で返す. - * なお、ここでは以下の内部仕様で符号化している - * [ CODE, EXTRA-BIT-LEN, EXTRA, CODE, EXTRA-BIT-LEN, EXTRA ] - * @return {!Array.} LZ77 符号化 byte array. - */ -Zlib.RawDeflate.Lz77Match.prototype.toLz77Array = function() { - /** @type {number} */ - var length = this.length; - /** @type {number} */ - var dist = this.backwardDistance; - /** @type {Array} */ - var codeArray = []; - /** @type {number} */ - var pos = 0; - /** @type {!Array.} */ - var code; - - // length - code = Zlib.RawDeflate.Lz77Match.LengthCodeTable[length]; - codeArray[pos++] = code & 0xffff; - codeArray[pos++] = (code >> 16) & 0xff; - codeArray[pos++] = code >> 24; - - // distance - code = this.getDistanceCode_(dist); - codeArray[pos++] = code[0]; - codeArray[pos++] = code[1]; - codeArray[pos++] = code[2]; - - return codeArray; -}; - -/** - * LZ77 実装 - * @param {!(Array.|Uint8Array)} dataArray LZ77 符号化するバイト配列. - * @return {!(Array.|Uint16Array)} LZ77 符号化した配列. - */ -Zlib.RawDeflate.prototype.lz77 = function(dataArray) { - /** @type {number} input position */ - var position; - /** @type {number} input length */ - var length; - /** @type {number} loop counter */ - var i; - /** @type {number} loop limiter */ - var il; - /** @type {number} chained-hash-table key */ - var matchKey; - /** @type {Object.>} chained-hash-table */ - var table = {}; - /** @const @type {number} */ - var windowSize = Zlib.RawDeflate.WindowSize; - /** @type {Array.} match list */ - var matchList; - /** @type {Zlib.RawDeflate.Lz77Match} longest match */ - var longestMatch; - /** @type {Zlib.RawDeflate.Lz77Match} previous longest match */ - var prevMatch; - /** @type {!(Array.|Uint16Array)} lz77 buffer */ - var lz77buf = USE_TYPEDARRAY ? - new Uint16Array(dataArray.length * 2) : []; - /** @type {number} lz77 output buffer pointer */ - var pos = 0; - /** @type {number} lz77 skip length */ - var skipLength = 0; - /** @type {!(Array.|Uint32Array)} */ - var freqsLitLen = new (USE_TYPEDARRAY ? Uint32Array : Array)(286); - /** @type {!(Array.|Uint32Array)} */ - var freqsDist = new (USE_TYPEDARRAY ? Uint32Array : Array)(30); - /** @type {number} */ - var lazy = this.lazy; - /** @type {*} temporary variable */ - var tmp; - - // 初期化 - if (!USE_TYPEDARRAY) { - for (i = 0; i <= 285;) { freqsLitLen[i++] = 0; } - for (i = 0; i <= 29;) { freqsDist[i++] = 0; } - } - freqsLitLen[256] = 1; // EOB の最低出現回数は 1 - - /** - * マッチデータの書き込み - * @param {Zlib.RawDeflate.Lz77Match} match LZ77 Match data. - * @param {!number} offset スキップ開始位置(相対指定). - * @private - */ - function writeMatch(match, offset) { - /** @type {Array.} */ - var lz77Array = match.toLz77Array(); - /** @type {number} */ - var i; - /** @type {number} */ - var il; - - for (i = 0, il = lz77Array.length; i < il; ++i) { - lz77buf[pos++] = lz77Array[i]; - } - freqsLitLen[lz77Array[0]]++; - freqsDist[lz77Array[3]]++; - skipLength = match.length + offset - 1; - prevMatch = null; - } - - // LZ77 符号化 - for (position = 0, length = dataArray.length; position < length; ++position) { - // ハッシュキーの作成 - for (matchKey = 0, i = 0, il = Zlib.RawDeflate.Lz77MinLength; i < il; ++i) { - if (position + i === length) { - break; - } - matchKey = (matchKey << 8) | dataArray[position + i]; - } - - // テーブルが未定義だったら作成する - if (table[matchKey] === void 0) { table[matchKey] = []; } - matchList = table[matchKey]; - - // skip - if (skipLength-- > 0) { - matchList.push(position); - continue; - } - - // マッチテーブルの更新 (最大戻り距離を超えているものを削除する) - while (matchList.length > 0 && position - matchList[0] > windowSize) { - matchList.shift(); - } - - // データ末尾でマッチしようがない場合はそのまま流しこむ - if (position + Zlib.RawDeflate.Lz77MinLength >= length) { - if (prevMatch) { - writeMatch(prevMatch, -1); - } - - for (i = 0, il = length - position; i < il; ++i) { - tmp = dataArray[position + i]; - lz77buf[pos++] = tmp; - ++freqsLitLen[tmp]; - } - break; - } - - // マッチ候補から最長のものを探す - if (matchList.length > 0) { - longestMatch = this.searchLongestMatch_(dataArray, position, matchList); - - if (prevMatch) { - // 現在のマッチの方が前回のマッチよりも長い - if (prevMatch.length < longestMatch.length) { - // write previous literal - tmp = dataArray[position - 1]; - lz77buf[pos++] = tmp; - ++freqsLitLen[tmp]; - - // write current match - writeMatch(longestMatch, 0); - } else { - // write previous match - writeMatch(prevMatch, -1); - } - } else if (longestMatch.length < lazy) { - prevMatch = longestMatch; - } else { - writeMatch(longestMatch, 0); - } - // 前回マッチしていて今回マッチがなかったら前回のを採用 - } else if (prevMatch) { - writeMatch(prevMatch, -1); - } else { - tmp = dataArray[position]; - lz77buf[pos++] = tmp; - ++freqsLitLen[tmp]; - } - - matchList.push(position); // マッチテーブルに現在の位置を保存 - } - - // 終端処理 - lz77buf[pos++] = 256; - freqsLitLen[256]++; - this.freqsLitLen = freqsLitLen; - this.freqsDist = freqsDist; - - return /** @type {!(Uint16Array|Array.)} */ ( - USE_TYPEDARRAY ? lz77buf.subarray(0, pos) : lz77buf - ); -}; - -/** - * マッチした候補の中から最長一致を探す - * @param {!Object} data plain data byte array. - * @param {!number} position plain data byte array position. - * @param {!Array.} matchList 候補となる位置の配列. - * @return {!Zlib.RawDeflate.Lz77Match} 最長かつ最短距離のマッチオブジェクト. - * @private - */ -Zlib.RawDeflate.prototype.searchLongestMatch_ = -function(data, position, matchList) { - var match, - currentMatch, - matchMax = 0, matchLength, - i, j, l, dl = data.length; - - // 候補を後ろから 1 つずつ絞り込んでゆく - permatch: - for (i = 0, l = matchList.length; i < l; i++) { - match = matchList[l - i - 1]; - matchLength = Zlib.RawDeflate.Lz77MinLength; - - // 前回までの最長一致を末尾から一致検索する - if (matchMax > Zlib.RawDeflate.Lz77MinLength) { - for (j = matchMax; j > Zlib.RawDeflate.Lz77MinLength; j--) { - if (data[match + j - 1] !== data[position + j - 1]) { - continue permatch; - } - } - matchLength = matchMax; - } - - // 最長一致探索 - while (matchLength < Zlib.RawDeflate.Lz77MaxLength && - position + matchLength < dl && - data[match + matchLength] === data[position + matchLength]) { - ++matchLength; - } - - // マッチ長が同じ場合は後方を優先 - if (matchLength > matchMax) { - currentMatch = match; - matchMax = matchLength; - } - - // 最長が確定したら後の処理は省略 - if (matchLength === Zlib.RawDeflate.Lz77MaxLength) { - break; - } - } - - return new Zlib.RawDeflate.Lz77Match(matchMax, position - currentMatch); -}; - -/** - * Tree-Transmit Symbols の算出 - * reference: PuTTY Deflate implementation - * @param {number} hlit HLIT. - * @param {!(Array.|Uint8Array)} litlenLengths リテラルと長さ符号の符号長配列. - * @param {number} hdist HDIST. - * @param {!(Array.|Uint8Array)} distLengths 距離符号の符号長配列. - * @return {{ - * codes: !(Array.|Uint32Array), - * freqs: !(Array.|Uint8Array) - * }} Tree-Transmit Symbols. - */ -Zlib.RawDeflate.prototype.getTreeSymbols_ = -function(hlit, litlenLengths, hdist, distLengths) { - var src = new (USE_TYPEDARRAY ? Uint32Array : Array)(hlit + hdist), - i, j, runLength, l, - result = new (USE_TYPEDARRAY ? Uint32Array : Array)(286 + 30), - nResult, - rpt, - freqs = new (USE_TYPEDARRAY ? Uint8Array : Array)(19); - - j = 0; - for (i = 0; i < hlit; i++) { - src[j++] = litlenLengths[i]; - } - for (i = 0; i < hdist; i++) { - src[j++] = distLengths[i]; - } - - // 初期化 - if (!USE_TYPEDARRAY) { - for (i = 0, l = freqs.length; i < l; ++i) { - freqs[i] = 0; - } - } - - // 符号化 - nResult = 0; - for (i = 0, l = src.length; i < l; i += j) { - // Run Length Encoding - for (j = 1; i + j < l && src[i + j] === src[i]; ++j) {} - - runLength = j; - - if (src[i] === 0) { - // 0 の繰り返しが 3 回未満ならばそのまま - if (runLength < 3) { - while (runLength-- > 0) { - result[nResult++] = 0; - freqs[0]++; - } - } else { - while (runLength > 0) { - // 繰り返しは最大 138 までなので切り詰める - rpt = (runLength < 138 ? runLength : 138); - - if (rpt > runLength - 3 && rpt < runLength) { - rpt = runLength - 3; - } - - // 3-10 回 -> 17 - if (rpt <= 10) { - result[nResult++] = 17; - result[nResult++] = rpt - 3; - freqs[17]++; - // 11-138 回 -> 18 - } else { - result[nResult++] = 18; - result[nResult++] = rpt - 11; - freqs[18]++; - } - - runLength -= rpt; - } - } - } else { - result[nResult++] = src[i]; - freqs[src[i]]++; - runLength--; - - // 繰り返し回数が3回未満ならばランレングス符号は要らない - if (runLength < 3) { - while (runLength-- > 0) { - result[nResult++] = src[i]; - freqs[src[i]]++; - } - // 3 回以上ならばランレングス符号化 - } else { - while (runLength > 0) { - // runLengthを 3-6 で分割 - rpt = (runLength < 6 ? runLength : 6); - - if (rpt > runLength - 3 && rpt < runLength) { - rpt = runLength - 3; - } - - result[nResult++] = 16; - result[nResult++] = rpt - 3; - freqs[16]++; - - runLength -= rpt; - } - } - } - } - - return { - codes: - USE_TYPEDARRAY ? result.subarray(0, nResult) : result.slice(0, nResult), - freqs: freqs - }; -}; - -/** - * ハフマン符号の長さを取得する - * @param {!(Array.|Uint8Array|Uint32Array)} freqs 出現カウント. - * @param {number} limit 符号長の制限. - * @return {!(Array.|Uint8Array)} 符号長配列. - * @private - */ -Zlib.RawDeflate.prototype.getLengths_ = function(freqs, limit) { - /** @type {number} */ - var nSymbols = freqs.length; - /** @type {Zlib.Heap} */ - var heap = new Zlib.Heap(2 * Zlib.RawDeflate.HUFMAX); - /** @type {!(Array.|Uint8Array)} */ - var length = new (USE_TYPEDARRAY ? Uint8Array : Array)(nSymbols); - /** @type {Array} */ - var nodes; - /** @type {!(Array.|Uint32Array)} */ - var values; - /** @type {!(Array.|Uint8Array)} */ - var codeLength; - /** @type {number} */ - var i; - /** @type {number} */ - var il; - - // 配列の初期化 - if (!USE_TYPEDARRAY) { - for (i = 0; i < nSymbols; i++) { - length[i] = 0; - } - } - - // ヒープの構築 - for (i = 0; i < nSymbols; ++i) { - if (freqs[i] > 0) { - heap.push(i, freqs[i]); - } - } - nodes = new Array(heap.length / 2); - values = new (USE_TYPEDARRAY ? Uint32Array : Array)(heap.length / 2); - - // 非 0 の要素が一つだけだった場合は、そのシンボルに符号長 1 を割り当てて終了 - if (nodes.length === 1) { - length[heap.pop().index] = 1; - return length; - } - - // Reverse Package Merge Algorithm による Canonical Huffman Code の符号長決定 - for (i = 0, il = heap.length / 2; i < il; ++i) { - nodes[i] = heap.pop(); - values[i] = nodes[i].value; - } - codeLength = this.reversePackageMerge_(values, values.length, limit); - - for (i = 0, il = nodes.length; i < il; ++i) { - length[nodes[i].index] = codeLength[i]; - } - - return length; -}; - -/** - * Reverse Package Merge Algorithm. - * @param {!(Array.|Uint32Array)} freqs sorted probability. - * @param {number} symbols number of symbols. - * @param {number} limit code length limit. - * @return {!(Array.|Uint8Array)} code lengths. - */ -Zlib.RawDeflate.prototype.reversePackageMerge_ = function(freqs, symbols, limit) { - /** @type {!(Array.|Uint16Array)} */ - var minimumCost = new (USE_TYPEDARRAY ? Uint16Array : Array)(limit); - /** @type {!(Array.|Uint8Array)} */ - var flag = new (USE_TYPEDARRAY ? Uint8Array : Array)(limit); - /** @type {!(Array.|Uint8Array)} */ - var codeLength = new (USE_TYPEDARRAY ? Uint8Array : Array)(symbols); - /** @type {Array} */ - var value = new Array(limit); - /** @type {Array} */ - var type = new Array(limit); - /** @type {Array.} */ - var currentPosition = new Array(limit); - /** @type {number} */ - var excess = (1 << limit) - symbols; - /** @type {number} */ - var half = (1 << (limit - 1)); - /** @type {number} */ - var i; - /** @type {number} */ - var j; - /** @type {number} */ - var t; - /** @type {number} */ - var weight; - /** @type {number} */ - var next; - - /** - * @param {number} j - */ - function takePackage(j) { - /** @type {number} */ - var x = type[j][currentPosition[j]]; - - if (x === symbols) { - takePackage(j+1); - takePackage(j+1); - } else { - --codeLength[x]; - } - - ++currentPosition[j]; - } - - minimumCost[limit-1] = symbols; - - for (j = 0; j < limit; ++j) { - if (excess < half) { - flag[j] = 0; - } else { - flag[j] = 1; - excess -= half; - } - excess <<= 1; - minimumCost[limit-2-j] = (minimumCost[limit-1-j] / 2 | 0) + symbols; - } - minimumCost[0] = flag[0]; - - value[0] = new Array(minimumCost[0]); - type[0] = new Array(minimumCost[0]); - for (j = 1; j < limit; ++j) { - if (minimumCost[j] > 2 * minimumCost[j-1] + flag[j]) { - minimumCost[j] = 2 * minimumCost[j-1] + flag[j]; - } - value[j] = new Array(minimumCost[j]); - type[j] = new Array(minimumCost[j]); - } - - for (i = 0; i < symbols; ++i) { - codeLength[i] = limit; - } - - for (t = 0; t < minimumCost[limit-1]; ++t) { - value[limit-1][t] = freqs[t]; - type[limit-1][t] = t; - } - - for (i = 0; i < limit; ++i) { - currentPosition[i] = 0; - } - if (flag[limit-1] === 1) { - --codeLength[0]; - ++currentPosition[limit-1]; - } - - for (j = limit-2; j >= 0; --j) { - i = 0; - weight = 0; - next = currentPosition[j+1]; - - for (t = 0; t < minimumCost[j]; t++) { - weight = value[j+1][next] + value[j+1][next+1]; - - if (weight > freqs[i]) { - value[j][t] = weight; - type[j][t] = symbols; - next += 2; - } else { - value[j][t] = freqs[i]; - type[j][t] = i; - ++i; - } - } - - currentPosition[j] = 0; - if (flag[j] === 1) { - takePackage(j); - } - } - - return codeLength; -}; - -/** - * 符号長配列からハフマン符号を取得する - * reference: PuTTY Deflate implementation - * @param {!(Array.|Uint8Array)} lengths 符号長配列. - * @return {!(Array.|Uint16Array)} ハフマン符号配列. - * @private - */ -Zlib.RawDeflate.prototype.getCodesFromLengths_ = function(lengths) { - var codes = new (USE_TYPEDARRAY ? Uint16Array : Array)(lengths.length), - count = [], - startCode = [], - code = 0, i, il, j, m; - - // Count the codes of each length. - for (i = 0, il = lengths.length; i < il; i++) { - count[lengths[i]] = (count[lengths[i]] | 0) + 1; - } - - // Determine the starting code for each length block. - for (i = 1, il = Zlib.RawDeflate.MaxCodeLength; i <= il; i++) { - startCode[i] = code; - code += count[i] | 0; - code <<= 1; - } - - // Determine the code for each symbol. Mirrored, of course. - for (i = 0, il = lengths.length; i < il; i++) { - code = startCode[lengths[i]]; - startCode[lengths[i]] += 1; - codes[i] = 0; - - for (j = 0, m = lengths[i]; j < m; j++) { - codes[i] = (codes[i] << 1) | (code & 1); - code >>>= 1; - } - } - - return codes; -}; - - -/** - * @param {!(Array.|Uint8Array)} input input buffer. - * @param {Object=} opt_params options. - * @constructor - */ -Zlib.Unzip = function(input, opt_params) { - opt_params = opt_params || {}; - /** @type {!(Array.|Uint8Array)} */ - this.input = - (USE_TYPEDARRAY && (input instanceof Array)) ? - new Uint8Array(input) : input; - /** @type {number} */ - this.ip = 0; - /** @type {number} */ - this.eocdrOffset; - /** @type {number} */ - this.numberOfThisDisk; - /** @type {number} */ - this.startDisk; - /** @type {number} */ - this.totalEntriesThisDisk; - /** @type {number} */ - this.totalEntries; - /** @type {number} */ - this.centralDirectorySize; - /** @type {number} */ - this.centralDirectoryOffset; - /** @type {number} */ - this.commentLength; - /** @type {(Array.|Uint8Array)} */ - this.comment; - /** @type {Array.} */ - this.fileHeaderList; - /** @type {Object.} */ - this.filenameToIndex; - /** @type {boolean} */ - this.verify = opt_params['verify'] || false; - /** @type {(Array.|Uint8Array)} */ - this.password = opt_params['password']; -}; - -Zlib.Unzip.CompressionMethod = Zlib.Zip.CompressionMethod; - -/** - * @type {Array.} - * @const - */ -Zlib.Unzip.FileHeaderSignature = Zlib.Zip.FileHeaderSignature; - -/** - * @type {Array.} - * @const - */ -Zlib.Unzip.LocalFileHeaderSignature = Zlib.Zip.LocalFileHeaderSignature; - -/** - * @type {Array.} - * @const - */ -Zlib.Unzip.CentralDirectorySignature = Zlib.Zip.CentralDirectorySignature; - -/** - * @param {!(Array.|Uint8Array)} input input buffer. - * @param {number} ip input position. - * @constructor - */ -Zlib.Unzip.FileHeader = function(input, ip) { - /** @type {!(Array.|Uint8Array)} */ - this.input = input; - /** @type {number} */ - this.offset = ip; - /** @type {number} */ - this.length; - /** @type {number} */ - this.version; - /** @type {number} */ - this.os; - /** @type {number} */ - this.needVersion; - /** @type {number} */ - this.flags; - /** @type {number} */ - this.compression; - /** @type {number} */ - this.time; - /** @type {number} */ - this.date; - /** @type {number} */ - this.crc32; - /** @type {number} */ - this.compressedSize; - /** @type {number} */ - this.plainSize; - /** @type {number} */ - this.fileNameLength; - /** @type {number} */ - this.extraFieldLength; - /** @type {number} */ - this.fileCommentLength; - /** @type {number} */ - this.diskNumberStart; - /** @type {number} */ - this.internalFileAttributes; - /** @type {number} */ - this.externalFileAttributes; - /** @type {number} */ - this.relativeOffset; - /** @type {string} */ - this.filename; - /** @type {!(Array.|Uint8Array)} */ - this.extraField; - /** @type {!(Array.|Uint8Array)} */ - this.comment; -}; - -Zlib.Unzip.FileHeader.prototype.parse = function() { - /** @type {!(Array.|Uint8Array)} */ - var input = this.input; - /** @type {number} */ - var ip = this.offset; - - // central file header signature - if (input[ip++] !== Zlib.Unzip.FileHeaderSignature[0] || - input[ip++] !== Zlib.Unzip.FileHeaderSignature[1] || - input[ip++] !== Zlib.Unzip.FileHeaderSignature[2] || - input[ip++] !== Zlib.Unzip.FileHeaderSignature[3]) { - throw new Error('invalid file header signature'); - } - - // version made by - this.version = input[ip++]; - this.os = input[ip++]; - - // version needed to extract - this.needVersion = input[ip++] | (input[ip++] << 8); - - // general purpose bit flag - this.flags = input[ip++] | (input[ip++] << 8); - - // compression method - this.compression = input[ip++] | (input[ip++] << 8); - - // last mod file time - this.time = input[ip++] | (input[ip++] << 8); - - //last mod file date - this.date = input[ip++] | (input[ip++] << 8); - - // crc-32 - this.crc32 = ( - (input[ip++] ) | (input[ip++] << 8) | - (input[ip++] << 16) | (input[ip++] << 24) - ) >>> 0; - - // compressed size - this.compressedSize = ( - (input[ip++] ) | (input[ip++] << 8) | - (input[ip++] << 16) | (input[ip++] << 24) - ) >>> 0; - - // uncompressed size - this.plainSize = ( - (input[ip++] ) | (input[ip++] << 8) | - (input[ip++] << 16) | (input[ip++] << 24) - ) >>> 0; - - // file name length - this.fileNameLength = input[ip++] | (input[ip++] << 8); - - // extra field length - this.extraFieldLength = input[ip++] | (input[ip++] << 8); - - // file comment length - this.fileCommentLength = input[ip++] | (input[ip++] << 8); - - // disk number start - this.diskNumberStart = input[ip++] | (input[ip++] << 8); - - // internal file attributes - this.internalFileAttributes = input[ip++] | (input[ip++] << 8); - - // external file attributes - this.externalFileAttributes = - (input[ip++] ) | (input[ip++] << 8) | - (input[ip++] << 16) | (input[ip++] << 24); - - // relative offset of local header - this.relativeOffset = ( - (input[ip++] ) | (input[ip++] << 8) | - (input[ip++] << 16) | (input[ip++] << 24) - ) >>> 0; - - // file name - this.filename = String.fromCharCode.apply(null, USE_TYPEDARRAY ? - input.subarray(ip, ip += this.fileNameLength) : - input.slice(ip, ip += this.fileNameLength) - ); - - // extra field - this.extraField = USE_TYPEDARRAY ? - input.subarray(ip, ip += this.extraFieldLength) : - input.slice(ip, ip += this.extraFieldLength); - - // file comment - this.comment = USE_TYPEDARRAY ? - input.subarray(ip, ip + this.fileCommentLength) : - input.slice(ip, ip + this.fileCommentLength); - - this.length = ip - this.offset; -}; - -/** - * @param {!(Array.|Uint8Array)} input input buffer. - * @param {number} ip input position. - * @constructor - */ -Zlib.Unzip.LocalFileHeader = function(input, ip) { - /** @type {!(Array.|Uint8Array)} */ - this.input = input; - /** @type {number} */ - this.offset = ip; - /** @type {number} */ - this.length; - /** @type {number} */ - this.needVersion; - /** @type {number} */ - this.flags; - /** @type {number} */ - this.compression; - /** @type {number} */ - this.time; - /** @type {number} */ - this.date; - /** @type {number} */ - this.crc32; - /** @type {number} */ - this.compressedSize; - /** @type {number} */ - this.plainSize; - /** @type {number} */ - this.fileNameLength; - /** @type {number} */ - this.extraFieldLength; - /** @type {string} */ - this.filename; - /** @type {!(Array.|Uint8Array)} */ - this.extraField; -}; - -Zlib.Unzip.LocalFileHeader.Flags = Zlib.Zip.Flags; - -Zlib.Unzip.LocalFileHeader.prototype.parse = function() { - /** @type {!(Array.|Uint8Array)} */ - var input = this.input; - /** @type {number} */ - var ip = this.offset; - - // local file header signature - if (input[ip++] !== Zlib.Unzip.LocalFileHeaderSignature[0] || - input[ip++] !== Zlib.Unzip.LocalFileHeaderSignature[1] || - input[ip++] !== Zlib.Unzip.LocalFileHeaderSignature[2] || - input[ip++] !== Zlib.Unzip.LocalFileHeaderSignature[3]) { - throw new Error('invalid local file header signature'); - } - - // version needed to extract - this.needVersion = input[ip++] | (input[ip++] << 8); - - // general purpose bit flag - this.flags = input[ip++] | (input[ip++] << 8); - - // compression method - this.compression = input[ip++] | (input[ip++] << 8); - - // last mod file time - this.time = input[ip++] | (input[ip++] << 8); - - //last mod file date - this.date = input[ip++] | (input[ip++] << 8); - - // crc-32 - this.crc32 = ( - (input[ip++] ) | (input[ip++] << 8) | - (input[ip++] << 16) | (input[ip++] << 24) - ) >>> 0; - - // compressed size - this.compressedSize = ( - (input[ip++] ) | (input[ip++] << 8) | - (input[ip++] << 16) | (input[ip++] << 24) - ) >>> 0; - - // uncompressed size - this.plainSize = ( - (input[ip++] ) | (input[ip++] << 8) | - (input[ip++] << 16) | (input[ip++] << 24) - ) >>> 0; - - // file name length - this.fileNameLength = input[ip++] | (input[ip++] << 8); - - // extra field length - this.extraFieldLength = input[ip++] | (input[ip++] << 8); - - // file name - this.filename = String.fromCharCode.apply(null, USE_TYPEDARRAY ? - input.subarray(ip, ip += this.fileNameLength) : - input.slice(ip, ip += this.fileNameLength) - ); - - // extra field - this.extraField = USE_TYPEDARRAY ? - input.subarray(ip, ip += this.extraFieldLength) : - input.slice(ip, ip += this.extraFieldLength); - - this.length = ip - this.offset; -}; - - -Zlib.Unzip.prototype.searchEndOfCentralDirectoryRecord = function() { - /** @type {!(Array.|Uint8Array)} */ - var input = this.input; - /** @type {number} */ - var ip; - - for (ip = input.length - 12; ip > 0; --ip) { - if (input[ip ] === Zlib.Unzip.CentralDirectorySignature[0] && - input[ip+1] === Zlib.Unzip.CentralDirectorySignature[1] && - input[ip+2] === Zlib.Unzip.CentralDirectorySignature[2] && - input[ip+3] === Zlib.Unzip.CentralDirectorySignature[3]) { - this.eocdrOffset = ip; - return; - } - } - - throw new Error('End of Central Directory Record not found'); -}; - -Zlib.Unzip.prototype.parseEndOfCentralDirectoryRecord = function() { - /** @type {!(Array.|Uint8Array)} */ - var input = this.input; - /** @type {number} */ - var ip; - - if (!this.eocdrOffset) { - this.searchEndOfCentralDirectoryRecord(); - } - ip = this.eocdrOffset; - - // signature - if (input[ip++] !== Zlib.Unzip.CentralDirectorySignature[0] || - input[ip++] !== Zlib.Unzip.CentralDirectorySignature[1] || - input[ip++] !== Zlib.Unzip.CentralDirectorySignature[2] || - input[ip++] !== Zlib.Unzip.CentralDirectorySignature[3]) { - throw new Error('invalid signature'); - } - - // number of this disk - this.numberOfThisDisk = input[ip++] | (input[ip++] << 8); - - // number of the disk with the start of the central directory - this.startDisk = input[ip++] | (input[ip++] << 8); - - // total number of entries in the central directory on this disk - this.totalEntriesThisDisk = input[ip++] | (input[ip++] << 8); - - // total number of entries in the central directory - this.totalEntries = input[ip++] | (input[ip++] << 8); - - // size of the central directory - this.centralDirectorySize = ( - (input[ip++] ) | (input[ip++] << 8) | - (input[ip++] << 16) | (input[ip++] << 24) - ) >>> 0; - - // offset of start of central directory with respect to the starting disk number - this.centralDirectoryOffset = ( - (input[ip++] ) | (input[ip++] << 8) | - (input[ip++] << 16) | (input[ip++] << 24) - ) >>> 0; - - // .ZIP file comment length - this.commentLength = input[ip++] | (input[ip++] << 8); - - // .ZIP file comment - this.comment = USE_TYPEDARRAY ? - input.subarray(ip, ip + this.commentLength) : - input.slice(ip, ip + this.commentLength); -}; - -Zlib.Unzip.prototype.parseFileHeader = function() { - /** @type {Array.} */ - var filelist = []; - /** @type {Object.} */ - var filetable = {}; - /** @type {number} */ - var ip; - /** @type {Zlib.Unzip.FileHeader} */ - var fileHeader; - /*: @type {number} */ - var i; - /*: @type {number} */ - var il; - - if (this.fileHeaderList) { - return; - } - - if (this.centralDirectoryOffset === void 0) { - this.parseEndOfCentralDirectoryRecord(); - } - ip = this.centralDirectoryOffset; - - for (i = 0, il = this.totalEntries; i < il; ++i) { - fileHeader = new Zlib.Unzip.FileHeader(this.input, ip); - fileHeader.parse(); - ip += fileHeader.length; - filelist[i] = fileHeader; - filetable[fileHeader.filename] = i; - } - - if (this.centralDirectorySize < ip - this.centralDirectoryOffset) { - throw new Error('invalid file header size'); - } - - this.fileHeaderList = filelist; - this.filenameToIndex = filetable; -}; - -/** - * @param {number} index file header index. - * @param {Object=} opt_params - * @return {!(Array.|Uint8Array)} file data. - */ -Zlib.Unzip.prototype.getFileData = function(index, opt_params) { - opt_params = opt_params || {}; - /** @type {!(Array.|Uint8Array)} */ - var input = this.input; - /** @type {Array.} */ - var fileHeaderList = this.fileHeaderList; - /** @type {Zlib.Unzip.LocalFileHeader} */ - var localFileHeader; - /** @type {number} */ - var offset; - /** @type {number} */ - var length; - /** @type {!(Array.|Uint8Array)} */ - var buffer; - /** @type {number} */ - var crc32; - /** @type {Array.|Uint32Array|Object} */ - var key; - /** @type {number} */ - var i; - /** @type {number} */ - var il; - - if (!fileHeaderList) { - this.parseFileHeader(); - } - - if (fileHeaderList[index] === void 0) { - throw new Error('wrong index'); - } - - offset = fileHeaderList[index].relativeOffset; - localFileHeader = new Zlib.Unzip.LocalFileHeader(this.input, offset); - localFileHeader.parse(); - offset += localFileHeader.length; - length = localFileHeader.compressedSize; - - // decryption - if ((localFileHeader.flags & Zlib.Unzip.LocalFileHeader.Flags.ENCRYPT) !== 0) { - if (!(opt_params['password'] || this.password)) { - throw new Error('please set password'); - } - key = this.createDecryptionKey(opt_params['password'] || this.password); - - // encryption header - for(i = offset, il = offset + 12; i < il; ++i) { - this.decode(key, input[i]); - } - offset += 12; - length -= 12; - - // decryption - for (i = offset, il = offset + length; i < il; ++i) { - input[i] = this.decode(key, input[i]); - } - } - - switch (localFileHeader.compression) { - case Zlib.Unzip.CompressionMethod.STORE: - buffer = USE_TYPEDARRAY ? - this.input.subarray(offset, offset + length) : - this.input.slice(offset, offset + length); - break; - case Zlib.Unzip.CompressionMethod.DEFLATE: - buffer = new Zlib.RawInflate(this.input, { - 'index': offset, - 'bufferSize': localFileHeader.plainSize - }).decompress(); - break; - default: - throw new Error('unknown compression type'); - } - - if (this.verify) { - crc32 = Zlib.CRC32.calc(buffer); - if (localFileHeader.crc32 !== crc32) { - throw new Error( - 'wrong crc: file=0x' + localFileHeader.crc32.toString(16) + - ', data=0x' + crc32.toString(16) - ); - } - } - - return buffer; -}; - -/** - * @return {Array.} - */ -Zlib.Unzip.prototype.getFilenames = function() { - /** @type {Array.} */ - var filenameList = []; - /** @type {number} */ - var i; - /** @type {number} */ - var il; - /** @type {Array.} */ - var fileHeaderList; - - if (!this.fileHeaderList) { - this.parseFileHeader(); - } - fileHeaderList = this.fileHeaderList; - - for (i = 0, il = fileHeaderList.length; i < il; ++i) { - filenameList[i] = fileHeaderList[i].filename; - } - - return filenameList; -}; - -/** - * @param {string} filename extract filename. - * @param {Object=} opt_params - * @return {!(Array.|Uint8Array)} decompressed data. - */ -Zlib.Unzip.prototype.decompress = function(filename, opt_params) { - /** @type {number} */ - var index; - - if (!this.filenameToIndex) { - this.parseFileHeader(); - } - index = this.filenameToIndex[filename]; - - if (index === void 0) { - throw new Error(filename + ' not found'); - } - - return this.getFileData(index, opt_params); -}; - -/** - * @param {(Array.|Uint8Array)} password - */ -Zlib.Unzip.prototype.setPassword = function(password) { - this.password = password; -}; - -/** - * @param {(Array.|Uint32Array|Object)} key - * @param {number} n - * @return {number} - */ -Zlib.Unzip.prototype.decode = function(key, n) { - n ^= this.getByte(/** @type {(Array.|Uint32Array)} */(key)); - this.updateKeys(/** @type {(Array.|Uint32Array)} */(key), n); - - return n; -}; - -// common method -Zlib.Unzip.prototype.updateKeys = Zlib.Zip.prototype.updateKeys; -Zlib.Unzip.prototype.createDecryptionKey = Zlib.Zip.prototype.createEncryptionKey; -Zlib.Unzip.prototype.getByte = Zlib.Zip.prototype.getByte; - -/** - * @fileoverview 雑多な関数群をまとめたモジュール実装. - */ - - -/** - * Byte String から Byte Array に変換. - * @param {!string} str byte string. - * @return {!Array.} byte array. - */ -Zlib.Util.stringToByteArray = function(str) { - /** @type {!Array.<(string|number)>} */ - var tmp = str.split(''); - /** @type {number} */ - var i; - /** @type {number} */ - var il; - - for (i = 0, il = tmp.length; i < il; i++) { - tmp[i] = (tmp[i].charCodeAt(0) & 0xff) >>> 0; - } - - return tmp; -}; - - -/** - * @fileoverview Adler32 checksum 実装. - */ - - -/** - * Adler32 ハッシュ値の作成 - * @param {!(Array|Uint8Array|string)} array 算出に使用する byte array. - * @return {number} Adler32 ハッシュ値. - */ -Zlib.Adler32 = function(array) { - if (typeof(array) === 'string') { - array = Zlib.Util.stringToByteArray(array); - } - return Zlib.Adler32.update(1, array); -}; - -/** - * Adler32 ハッシュ値の更新 - * @param {number} adler 現在のハッシュ値. - * @param {!(Array|Uint8Array)} array 更新に使用する byte array. - * @return {number} Adler32 ハッシュ値. - */ -Zlib.Adler32.update = function(adler, array) { - /** @type {number} */ - var s1 = adler & 0xffff; - /** @type {number} */ - var s2 = (adler >>> 16) & 0xffff; - /** @type {number} array length */ - var len = array.length; - /** @type {number} loop length (don't overflow) */ - var tlen; - /** @type {number} array index */ - var i = 0; - - while (len > 0) { - tlen = len > Zlib.Adler32.OptimizationParameter ? - Zlib.Adler32.OptimizationParameter : len; - len -= tlen; - do { - s1 += array[i++]; - s2 += s1; - } while (--tlen); - - s1 %= 65521; - s2 %= 65521; - } - - return ((s2 << 16) | s1) >>> 0; -}; - -/** - * Adler32 最適化パラメータ - * 現状では 1024 程度が最適. - * @see http://jsperf.com/adler-32-simple-vs-optimized/3 - * @define {number} - */ -Zlib.Adler32.OptimizationParameter = 1024; - - - - -/** - * ビットストリーム - * @constructor - * @param {!(Array|Uint8Array)=} buffer output buffer. - * @param {number=} bufferPosition start buffer pointer. - */ -Zlib.BitStream = function(buffer, bufferPosition) { - /** @type {number} buffer index. */ - this.index = typeof bufferPosition === 'number' ? bufferPosition : 0; - /** @type {number} bit index. */ - this.bitindex = 0; - /** @type {!(Array|Uint8Array)} bit-stream output buffer. */ - this.buffer = buffer instanceof (USE_TYPEDARRAY ? Uint8Array : Array) ? - buffer : - new (USE_TYPEDARRAY ? Uint8Array : Array)(Zlib.BitStream.DefaultBlockSize); - - // 入力された index が足りなかったら拡張するが、倍にしてもダメなら不正とする - if (this.buffer.length * 2 <= this.index) { - throw new Error("invalid index"); - } else if (this.buffer.length <= this.index) { - this.expandBuffer(); - } -}; - -/** - * デフォルトブロックサイズ. - * @const - * @type {number} - */ -Zlib.BitStream.DefaultBlockSize = 0x8000; - -/** - * expand buffer. - * @return {!(Array|Uint8Array)} new buffer. - */ -Zlib.BitStream.prototype.expandBuffer = function() { - /** @type {!(Array|Uint8Array)} old buffer. */ - var oldbuf = this.buffer; - /** @type {number} loop counter. */ - var i; - /** @type {number} loop limiter. */ - var il = oldbuf.length; - /** @type {!(Array|Uint8Array)} new buffer. */ - var buffer = - new (USE_TYPEDARRAY ? Uint8Array : Array)(il << 1); - - // copy buffer - if (USE_TYPEDARRAY) { - buffer.set(oldbuf); - } else { - // XXX: loop unrolling - for (i = 0; i < il; ++i) { - buffer[i] = oldbuf[i]; - } - } - - return (this.buffer = buffer); -}; - - -/** - * 数値をビットで指定した数だけ書き込む. - * @param {number} number 書き込む数値. - * @param {number} n 書き込むビット数. - * @param {boolean=} reverse 逆順に書き込むならば true. - */ -Zlib.BitStream.prototype.writeBits = function(number, n, reverse) { - var buffer = this.buffer; - var index = this.index; - var bitindex = this.bitindex; - - /** @type {number} current octet. */ - var current = buffer[index]; - /** @type {number} loop counter. */ - var i; - - /** - * 32-bit 整数のビット順を逆にする - * @param {number} n 32-bit integer. - * @return {number} reversed 32-bit integer. - * @private - */ - function rev32_(n) { - return (Zlib.BitStream.ReverseTable[n & 0xFF] << 24) | - (Zlib.BitStream.ReverseTable[n >>> 8 & 0xFF] << 16) | - (Zlib.BitStream.ReverseTable[n >>> 16 & 0xFF] << 8) | - Zlib.BitStream.ReverseTable[n >>> 24 & 0xFF]; - } - - if (reverse && n > 1) { - number = n > 8 ? - rev32_(number) >> (32 - n) : - Zlib.BitStream.ReverseTable[number] >> (8 - n); - } - - // Byte 境界を超えないとき - if (n + bitindex < 8) { - current = (current << n) | number; - bitindex += n; - // Byte 境界を超えるとき - } else { - for (i = 0; i < n; ++i) { - current = (current << 1) | ((number >> n - i - 1) & 1); - - // next byte - if (++bitindex === 8) { - bitindex = 0; - buffer[index++] = Zlib.BitStream.ReverseTable[current]; - current = 0; - - // expand - if (index === buffer.length) { - buffer = this.expandBuffer(); - } - } - } - } - buffer[index] = current; - - this.buffer = buffer; - this.bitindex = bitindex; - this.index = index; -}; - - -/** - * ストリームの終端処理を行う - * @return {!(Array|Uint8Array)} 終端処理後のバッファを byte array で返す. - */ -Zlib.BitStream.prototype.finish = function() { - var buffer = this.buffer; - var index = this.index; - - /** @type {!(Array|Uint8Array)} output buffer. */ - var output; - - // bitindex が 0 の時は余分に index が進んでいる状態 - if (this.bitindex > 0) { - buffer[index] <<= 8 - this.bitindex; - buffer[index] = Zlib.BitStream.ReverseTable[buffer[index]]; - index++; - } - - // array truncation - if (USE_TYPEDARRAY) { - output = buffer.subarray(0, index); - } else { - buffer.length = index; - output = buffer; - } - - return output; -}; - -/** - * 0-255 のビット順を反転したテーブル - * @const - * @type {!(Uint8Array|Array.)} - */ -Zlib.BitStream.ReverseTable = (function(table) { - return table; -})((function() { - /** @type {!(Array|Uint8Array)} reverse table. */ - var table = new (USE_TYPEDARRAY ? Uint8Array : Array)(256); - /** @type {number} loop counter. */ - var i; - - // generate - for (i = 0; i < 256; ++i) { - table[i] = (function(n) { - var r = n; - var s = 7; - - for (n >>>= 1; n; n >>>= 1) { - r <<= 1; - r |= n & 1; - --s; - } - - return (r << s & 0xff) >>> 0; - })(i); - } - - return table; -})()); - - -/** - * @fileoverview CRC32 実装. - */ - - -/** @define {boolean} */ -var ZLIB_CRC32_COMPACT = false; - -/** - * CRC32 ハッシュ値を取得 - * @param {!(Array.|Uint8Array)} data data byte array. - * @param {number=} pos data position. - * @param {number=} length data length. - * @return {number} CRC32. - */ -Zlib.CRC32.calc = function(data, pos, length) { - return Zlib.CRC32.update(data, 0, pos, length); -}; - -/** - * CRC32ハッシュ値を更新 - * @param {!(Array.|Uint8Array)} data data byte array. - * @param {number} crc CRC32. - * @param {number=} pos data position. - * @param {number=} length data length. - * @return {number} CRC32. - */ -Zlib.CRC32.update = function(data, crc, pos, length) { - var table = Zlib.CRC32.Table; - var i = (typeof pos === 'number') ? pos : (pos = 0); - var il = (typeof length === 'number') ? length : data.length; - - crc ^= 0xffffffff; - - // loop unrolling for performance - for (i = il & 7; i--; ++pos) { - crc = (crc >>> 8) ^ table[(crc ^ data[pos]) & 0xff]; - } - for (i = il >> 3; i--; pos += 8) { - crc = (crc >>> 8) ^ table[(crc ^ data[pos ]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 1]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 2]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 3]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 4]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 5]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 6]) & 0xff]; - crc = (crc >>> 8) ^ table[(crc ^ data[pos + 7]) & 0xff]; - } - - return (crc ^ 0xffffffff) >>> 0; -}; - -/** - * @param {number} num - * @param {number} crc - * @returns {number} - */ -Zlib.CRC32.single = function(num, crc) { - return (Zlib.CRC32.Table[(num ^ crc) & 0xff] ^ (num >>> 8)) >>> 0; -}; - -/** - * @type {Array.} - * @const - * @private - */ -Zlib.CRC32.Table_ = [ - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d -]; - -/** - * @type {!(Array.|Uint32Array)} CRC-32 Table. - * @const - */ -Zlib.CRC32.Table = ZLIB_CRC32_COMPACT ? (function() { - /** @type {!(Array.|Uint32Array)} */ - var table = new (USE_TYPEDARRAY ? Uint32Array : Array)(256); - /** @type {number} */ - var c; - /** @type {number} */ - var i; - /** @type {number} */ - var j; - - for (i = 0; i < 256; ++i) { - c = i; - for (j = 0; j < 8; ++j) { - c = (c & 1) ? (0xedB88320 ^ (c >>> 1)) : (c >>> 1); - } - table[i] = c >>> 0; - } - - return table; -})() : USE_TYPEDARRAY ? new Uint32Array(Zlib.CRC32.Table_) : Zlib.CRC32.Table_; - -/** - * @fileoverview Deflate (RFC1951) 実装. - * Deflateアルゴリズム本体は Zlib.RawDeflate で実装されている. - */ - -/** - * Zlib Deflate - * @constructor - * @param {!(Array|Uint8Array)} input 符号化する対象の byte array. - * @param {Object=} opt_params option parameters. - */ -Zlib.Deflate = function(input, opt_params) { - /** @type {!(Array|Uint8Array)} */ - this.input = input; - /** @type {!(Array|Uint8Array)} */ - this.output = - new (USE_TYPEDARRAY ? Uint8Array : Array)(Zlib.Deflate.DefaultBufferSize); - /** @type {Zlib.Deflate.CompressionType} */ - this.compressionType = Zlib.Deflate.CompressionType.DYNAMIC; - /** @type {Zlib.RawDeflate} */ - this.rawDeflate; - /** @type {Object} */ - var rawDeflateOption = {}; - /** @type {string} */ - var prop; - - // option parameters - if (opt_params || !(opt_params = {})) { - if (typeof opt_params['compressionType'] === 'number') { - this.compressionType = opt_params['compressionType']; - } - } - - // copy options - for (prop in opt_params) { - rawDeflateOption[prop] = opt_params[prop]; - } - - // set raw-deflate output buffer - rawDeflateOption['outputBuffer'] = this.output; - - this.rawDeflate = new Zlib.RawDeflate(this.input, rawDeflateOption); -}; - -/** - * @const - * @type {number} デフォルトバッファサイズ. - */ -Zlib.Deflate.DefaultBufferSize = 0x8000; - -/** - * @enum {number} - */ -Zlib.Deflate.CompressionType = Zlib.RawDeflate.CompressionType; - -/** - * 直接圧縮に掛ける. - * @param {!(Array|Uint8Array)} input target buffer. - * @param {Object=} opt_params option parameters. - * @return {!(Array|Uint8Array)} compressed data byte array. - */ -Zlib.Deflate.compress = function(input, opt_params) { - return (new Zlib.Deflate(input, opt_params)).compress(); -}; - -/** - * Deflate Compression. - * @return {!(Array|Uint8Array)} compressed data byte array. - */ -Zlib.Deflate.prototype.compress = function() { - /** @type {Zlib.CompressionMethod} */ - var cm; - /** @type {number} */ - var cinfo; - /** @type {number} */ - var cmf; - /** @type {number} */ - var flg; - /** @type {number} */ - var fcheck; - /** @type {number} */ - var fdict; - /** @type {number} */ - var flevel; - /** @type {number} */ - var clevel; - /** @type {number} */ - var adler; - /** @type {boolean} */ - var error = false; - /** @type {!(Array|Uint8Array)} */ - var output; - /** @type {number} */ - var pos = 0; - - output = this.output; - - // Compression Method and Flags - cm = Zlib.CompressionMethod.DEFLATE; - switch (cm) { - case Zlib.CompressionMethod.DEFLATE: - cinfo = Math.LOG2E * Math.log(Zlib.RawDeflate.WindowSize) - 8; - break; - default: - throw new Error('invalid compression method'); - } - cmf = (cinfo << 4) | cm; - output[pos++] = cmf; - - // Flags - fdict = 0; - switch (cm) { - case Zlib.CompressionMethod.DEFLATE: - switch (this.compressionType) { - case Zlib.Deflate.CompressionType.NONE: flevel = 0; break; - case Zlib.Deflate.CompressionType.FIXED: flevel = 1; break; - case Zlib.Deflate.CompressionType.DYNAMIC: flevel = 2; break; - default: throw new Error('unsupported compression type'); - } - break; - default: - throw new Error('invalid compression method'); - } - flg = (flevel << 6) | (fdict << 5); - fcheck = 31 - (cmf * 256 + flg) % 31; - flg |= fcheck; - output[pos++] = flg; - - // Adler-32 checksum - adler = Zlib.Adler32(this.input); - - this.rawDeflate.op = pos; - output = this.rawDeflate.compress(); - pos = output.length; - - if (USE_TYPEDARRAY) { - // subarray 分を元にもどす - output = new Uint8Array(output.buffer); - // expand buffer - if (output.length <= pos + 4) { - this.output = new Uint8Array(output.length + 4); - this.output.set(output); - output = this.output; - } - output = output.subarray(0, pos + 4); - } - - // adler32 - output[pos++] = (adler >> 24) & 0xff; - output[pos++] = (adler >> 16) & 0xff; - output[pos++] = (adler >> 8) & 0xff; - output[pos++] = (adler ) & 0xff; - - return output; -}; - - -/* -*- mode: javascript; c-basic-offset: 4; indent-tabs-mode: nil -*- */ - -// -// Javascript ZLib -// By Thomas Down 2010-2011 -// -// Based very heavily on portions of jzlib (by ymnk@jcraft.com), who in -// turn credits Jean-loup Gailly and Mark Adler for the original zlib code. -// -// inflate.js: ZLib inflate code -// - -// -// Shared constants -// - -var MAX_WBITS=15; // 32K LZ77 window -var DEF_WBITS=MAX_WBITS; -var MAX_MEM_LEVEL=9; -var MANY=1440; -var BMAX = 15; - -// preset dictionary flag in zlib header -var PRESET_DICT=0x20; - -var Z_NO_FLUSH=0; -var Z_PARTIAL_FLUSH=1; -var Z_SYNC_FLUSH=2; -var Z_FULL_FLUSH=3; -var Z_FINISH=4; - -var Z_DEFLATED=8; - -var Z_OK=0; -var Z_STREAM_END=1; -var Z_NEED_DICT=2; -var Z_ERRNO=-1; -var Z_STREAM_ERROR=-2; -var Z_DATA_ERROR=-3; -var Z_MEM_ERROR=-4; -var Z_BUF_ERROR=-5; -var Z_VERSION_ERROR=-6; - -var METHOD=0; // waiting for method byte -var FLAG=1; // waiting for flag byte -var DICT4=2; // four dictionary check bytes to go -var DICT3=3; // three dictionary check bytes to go -var DICT2=4; // two dictionary check bytes to go -var DICT1=5; // one dictionary check byte to go -var DICT0=6; // waiting for inflateSetDictionary -var BLOCKS=7; // decompressing blocks -var CHECK4=8; // four check bytes to go -var CHECK3=9; // three check bytes to go -var CHECK2=10; // two check bytes to go -var CHECK1=11; // one check byte to go -var DONE=12; // finished check, done -var BAD=13; // got an error--stay here - -var inflate_mask = [0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff]; - -var IB_TYPE=0; // get type bits (3, including end bit) -var IB_LENS=1; // get lengths for stored -var IB_STORED=2;// processing stored block -var IB_TABLE=3; // get table lengths -var IB_BTREE=4; // get bit lengths tree for a dynamic block -var IB_DTREE=5; // get length, distance trees for a dynamic block -var IB_CODES=6; // processing fixed or dynamic block -var IB_DRY=7; // output remaining window bytes -var IB_DONE=8; // finished last block, done -var IB_BAD=9; // ot a data error--stuck here - -var fixed_bl = 9; -var fixed_bd = 5; - -var fixed_tl = [ - 96,7,256, 0,8,80, 0,8,16, 84,8,115, - 82,7,31, 0,8,112, 0,8,48, 0,9,192, - 80,7,10, 0,8,96, 0,8,32, 0,9,160, - 0,8,0, 0,8,128, 0,8,64, 0,9,224, - 80,7,6, 0,8,88, 0,8,24, 0,9,144, - 83,7,59, 0,8,120, 0,8,56, 0,9,208, - 81,7,17, 0,8,104, 0,8,40, 0,9,176, - 0,8,8, 0,8,136, 0,8,72, 0,9,240, - 80,7,4, 0,8,84, 0,8,20, 85,8,227, - 83,7,43, 0,8,116, 0,8,52, 0,9,200, - 81,7,13, 0,8,100, 0,8,36, 0,9,168, - 0,8,4, 0,8,132, 0,8,68, 0,9,232, - 80,7,8, 0,8,92, 0,8,28, 0,9,152, - 84,7,83, 0,8,124, 0,8,60, 0,9,216, - 82,7,23, 0,8,108, 0,8,44, 0,9,184, - 0,8,12, 0,8,140, 0,8,76, 0,9,248, - 80,7,3, 0,8,82, 0,8,18, 85,8,163, - 83,7,35, 0,8,114, 0,8,50, 0,9,196, - 81,7,11, 0,8,98, 0,8,34, 0,9,164, - 0,8,2, 0,8,130, 0,8,66, 0,9,228, - 80,7,7, 0,8,90, 0,8,26, 0,9,148, - 84,7,67, 0,8,122, 0,8,58, 0,9,212, - 82,7,19, 0,8,106, 0,8,42, 0,9,180, - 0,8,10, 0,8,138, 0,8,74, 0,9,244, - 80,7,5, 0,8,86, 0,8,22, 192,8,0, - 83,7,51, 0,8,118, 0,8,54, 0,9,204, - 81,7,15, 0,8,102, 0,8,38, 0,9,172, - 0,8,6, 0,8,134, 0,8,70, 0,9,236, - 80,7,9, 0,8,94, 0,8,30, 0,9,156, - 84,7,99, 0,8,126, 0,8,62, 0,9,220, - 82,7,27, 0,8,110, 0,8,46, 0,9,188, - 0,8,14, 0,8,142, 0,8,78, 0,9,252, - 96,7,256, 0,8,81, 0,8,17, 85,8,131, - 82,7,31, 0,8,113, 0,8,49, 0,9,194, - 80,7,10, 0,8,97, 0,8,33, 0,9,162, - 0,8,1, 0,8,129, 0,8,65, 0,9,226, - 80,7,6, 0,8,89, 0,8,25, 0,9,146, - 83,7,59, 0,8,121, 0,8,57, 0,9,210, - 81,7,17, 0,8,105, 0,8,41, 0,9,178, - 0,8,9, 0,8,137, 0,8,73, 0,9,242, - 80,7,4, 0,8,85, 0,8,21, 80,8,258, - 83,7,43, 0,8,117, 0,8,53, 0,9,202, - 81,7,13, 0,8,101, 0,8,37, 0,9,170, - 0,8,5, 0,8,133, 0,8,69, 0,9,234, - 80,7,8, 0,8,93, 0,8,29, 0,9,154, - 84,7,83, 0,8,125, 0,8,61, 0,9,218, - 82,7,23, 0,8,109, 0,8,45, 0,9,186, - 0,8,13, 0,8,141, 0,8,77, 0,9,250, - 80,7,3, 0,8,83, 0,8,19, 85,8,195, - 83,7,35, 0,8,115, 0,8,51, 0,9,198, - 81,7,11, 0,8,99, 0,8,35, 0,9,166, - 0,8,3, 0,8,131, 0,8,67, 0,9,230, - 80,7,7, 0,8,91, 0,8,27, 0,9,150, - 84,7,67, 0,8,123, 0,8,59, 0,9,214, - 82,7,19, 0,8,107, 0,8,43, 0,9,182, - 0,8,11, 0,8,139, 0,8,75, 0,9,246, - 80,7,5, 0,8,87, 0,8,23, 192,8,0, - 83,7,51, 0,8,119, 0,8,55, 0,9,206, - 81,7,15, 0,8,103, 0,8,39, 0,9,174, - 0,8,7, 0,8,135, 0,8,71, 0,9,238, - 80,7,9, 0,8,95, 0,8,31, 0,9,158, - 84,7,99, 0,8,127, 0,8,63, 0,9,222, - 82,7,27, 0,8,111, 0,8,47, 0,9,190, - 0,8,15, 0,8,143, 0,8,79, 0,9,254, - 96,7,256, 0,8,80, 0,8,16, 84,8,115, - 82,7,31, 0,8,112, 0,8,48, 0,9,193, - - 80,7,10, 0,8,96, 0,8,32, 0,9,161, - 0,8,0, 0,8,128, 0,8,64, 0,9,225, - 80,7,6, 0,8,88, 0,8,24, 0,9,145, - 83,7,59, 0,8,120, 0,8,56, 0,9,209, - 81,7,17, 0,8,104, 0,8,40, 0,9,177, - 0,8,8, 0,8,136, 0,8,72, 0,9,241, - 80,7,4, 0,8,84, 0,8,20, 85,8,227, - 83,7,43, 0,8,116, 0,8,52, 0,9,201, - 81,7,13, 0,8,100, 0,8,36, 0,9,169, - 0,8,4, 0,8,132, 0,8,68, 0,9,233, - 80,7,8, 0,8,92, 0,8,28, 0,9,153, - 84,7,83, 0,8,124, 0,8,60, 0,9,217, - 82,7,23, 0,8,108, 0,8,44, 0,9,185, - 0,8,12, 0,8,140, 0,8,76, 0,9,249, - 80,7,3, 0,8,82, 0,8,18, 85,8,163, - 83,7,35, 0,8,114, 0,8,50, 0,9,197, - 81,7,11, 0,8,98, 0,8,34, 0,9,165, - 0,8,2, 0,8,130, 0,8,66, 0,9,229, - 80,7,7, 0,8,90, 0,8,26, 0,9,149, - 84,7,67, 0,8,122, 0,8,58, 0,9,213, - 82,7,19, 0,8,106, 0,8,42, 0,9,181, - 0,8,10, 0,8,138, 0,8,74, 0,9,245, - 80,7,5, 0,8,86, 0,8,22, 192,8,0, - 83,7,51, 0,8,118, 0,8,54, 0,9,205, - 81,7,15, 0,8,102, 0,8,38, 0,9,173, - 0,8,6, 0,8,134, 0,8,70, 0,9,237, - 80,7,9, 0,8,94, 0,8,30, 0,9,157, - 84,7,99, 0,8,126, 0,8,62, 0,9,221, - 82,7,27, 0,8,110, 0,8,46, 0,9,189, - 0,8,14, 0,8,142, 0,8,78, 0,9,253, - 96,7,256, 0,8,81, 0,8,17, 85,8,131, - 82,7,31, 0,8,113, 0,8,49, 0,9,195, - 80,7,10, 0,8,97, 0,8,33, 0,9,163, - 0,8,1, 0,8,129, 0,8,65, 0,9,227, - 80,7,6, 0,8,89, 0,8,25, 0,9,147, - 83,7,59, 0,8,121, 0,8,57, 0,9,211, - 81,7,17, 0,8,105, 0,8,41, 0,9,179, - 0,8,9, 0,8,137, 0,8,73, 0,9,243, - 80,7,4, 0,8,85, 0,8,21, 80,8,258, - 83,7,43, 0,8,117, 0,8,53, 0,9,203, - 81,7,13, 0,8,101, 0,8,37, 0,9,171, - 0,8,5, 0,8,133, 0,8,69, 0,9,235, - 80,7,8, 0,8,93, 0,8,29, 0,9,155, - 84,7,83, 0,8,125, 0,8,61, 0,9,219, - 82,7,23, 0,8,109, 0,8,45, 0,9,187, - 0,8,13, 0,8,141, 0,8,77, 0,9,251, - 80,7,3, 0,8,83, 0,8,19, 85,8,195, - 83,7,35, 0,8,115, 0,8,51, 0,9,199, - 81,7,11, 0,8,99, 0,8,35, 0,9,167, - 0,8,3, 0,8,131, 0,8,67, 0,9,231, - 80,7,7, 0,8,91, 0,8,27, 0,9,151, - 84,7,67, 0,8,123, 0,8,59, 0,9,215, - 82,7,19, 0,8,107, 0,8,43, 0,9,183, - 0,8,11, 0,8,139, 0,8,75, 0,9,247, - 80,7,5, 0,8,87, 0,8,23, 192,8,0, - 83,7,51, 0,8,119, 0,8,55, 0,9,207, - 81,7,15, 0,8,103, 0,8,39, 0,9,175, - 0,8,7, 0,8,135, 0,8,71, 0,9,239, - 80,7,9, 0,8,95, 0,8,31, 0,9,159, - 84,7,99, 0,8,127, 0,8,63, 0,9,223, - 82,7,27, 0,8,111, 0,8,47, 0,9,191, - 0,8,15, 0,8,143, 0,8,79, 0,9,255 -]; -var fixed_td = [ - 80,5,1, 87,5,257, 83,5,17, 91,5,4097, - 81,5,5, 89,5,1025, 85,5,65, 93,5,16385, - 80,5,3, 88,5,513, 84,5,33, 92,5,8193, - 82,5,9, 90,5,2049, 86,5,129, 192,5,24577, - 80,5,2, 87,5,385, 83,5,25, 91,5,6145, - 81,5,7, 89,5,1537, 85,5,97, 93,5,24577, - 80,5,4, 88,5,769, 84,5,49, 92,5,12289, - 82,5,13, 90,5,3073, 86,5,193, 192,5,24577 -]; - - // Tables for deflate from PKZIP's appnote.txt. - var cplens = [ // Copy lengths for literal codes 257..285 - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 - ]; - - // see note #13 above about 258 - var cplext = [ // Extra bits for literal codes 257..285 - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid - ]; - - var cpdist = [ // Copy offsets for distance codes 0..29 - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577 - ]; - - var cpdext = [ // Extra bits for distance codes - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, - 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, - 12, 12, 13, 13]; - -// -// ZStream.java -// - -function ZStream() { -} - - -ZStream.prototype.inflateInit = function(w, nowrap) { - if (!w) { - w = DEF_WBITS; - } - if (nowrap) { - nowrap = false; - } - this.istate = new Inflate(); - return this.istate.inflateInit(this, nowrap?-w:w); -} - -ZStream.prototype.inflate = function(f) { - if(this.istate==null) return Z_STREAM_ERROR; - return this.istate.inflate(this, f); -} - -ZStream.prototype.inflateEnd = function(){ - if(this.istate==null) return Z_STREAM_ERROR; - var ret=istate.inflateEnd(this); - this.istate = null; - return ret; -} -ZStream.prototype.inflateSync = function(){ - // if(istate == null) return Z_STREAM_ERROR; - return istate.inflateSync(this); -} -ZStream.prototype.inflateSetDictionary = function(dictionary, dictLength){ - // if(istate == null) return Z_STREAM_ERROR; - return istate.inflateSetDictionary(this, dictionary, dictLength); -} - -/* - - public int deflateInit(int level){ - return deflateInit(level, MAX_WBITS); - } - public int deflateInit(int level, boolean nowrap){ - return deflateInit(level, MAX_WBITS, nowrap); - } - public int deflateInit(int level, int bits){ - return deflateInit(level, bits, false); - } - public int deflateInit(int level, int bits, boolean nowrap){ - dstate=new Deflate(); - return dstate.deflateInit(this, level, nowrap?-bits:bits); - } - public int deflate(int flush){ - if(dstate==null){ - return Z_STREAM_ERROR; - } - return dstate.deflate(this, flush); - } - public int deflateEnd(){ - if(dstate==null) return Z_STREAM_ERROR; - int ret=dstate.deflateEnd(); - dstate=null; - return ret; - } - public int deflateParams(int level, int strategy){ - if(dstate==null) return Z_STREAM_ERROR; - return dstate.deflateParams(this, level, strategy); - } - public int deflateSetDictionary (byte[] dictionary, int dictLength){ - if(dstate == null) - return Z_STREAM_ERROR; - return dstate.deflateSetDictionary(this, dictionary, dictLength); - } - -*/ - -/* - // Flush as much pending output as possible. All deflate() output goes - // through this function so some applications may wish to modify it - // to avoid allocating a large strm->next_out buffer and copying into it. - // (See also read_buf()). - void flush_pending(){ - int len=dstate.pending; - - if(len>avail_out) len=avail_out; - if(len==0) return; - - if(dstate.pending_buf.length<=dstate.pending_out || - next_out.length<=next_out_index || - dstate.pending_buf.length<(dstate.pending_out+len) || - next_out.length<(next_out_index+len)){ - System.out.println(dstate.pending_buf.length+", "+dstate.pending_out+ - ", "+next_out.length+", "+next_out_index+", "+len); - System.out.println("avail_out="+avail_out); - } - - System.arraycopy(dstate.pending_buf, dstate.pending_out, - next_out, next_out_index, len); - - next_out_index+=len; - dstate.pending_out+=len; - total_out+=len; - avail_out-=len; - dstate.pending-=len; - if(dstate.pending==0){ - dstate.pending_out=0; - } - } - - // Read a new buffer from the current input stream, update the adler32 - // and total number of bytes read. All deflate() input goes through - // this function so some applications may wish to modify it to avoid - // allocating a large strm->next_in buffer and copying from it. - // (See also flush_pending()). - int read_buf(byte[] buf, int start, int size) { - int len=avail_in; - - if(len>size) len=size; - if(len==0) return 0; - - avail_in-=len; - - if(dstate.noheader==0) { - adler=_adler.adler32(adler, next_in, next_in_index, len); - } - System.arraycopy(next_in, next_in_index, buf, start, len); - next_in_index += len; - total_in += len; - return len; - } - - public void free(){ - next_in=null; - next_out=null; - msg=null; - _adler=null; - } -} -*/ - - -// -// Inflate.java -// - -function Inflate() { - this.was = [0]; -} - -Inflate.prototype.inflateReset = function(z) { - if(z == null || z.istate == null) return Z_STREAM_ERROR; - - z.total_in = z.total_out = 0; - z.msg = null; - z.istate.mode = z.istate.nowrap!=0 ? BLOCKS : METHOD; - z.istate.blocks.reset(z, null); - return Z_OK; -} - -Inflate.prototype.inflateEnd = function(z){ - if(this.blocks != null) - this.blocks.free(z); - this.blocks=null; - return Z_OK; -} - -Inflate.prototype.inflateInit = function(z, w){ - z.msg = null; - this.blocks = null; - - // handle undocumented nowrap option (no zlib header or check) - var nowrap = 0; - if(w < 0){ - w = - w; - nowrap = 1; - } - - // set window size - if(w<8 ||w>15){ - this.inflateEnd(z); - return Z_STREAM_ERROR; - } - this.wbits=w; - - z.istate.blocks=new InfBlocks(z, - z.istate.nowrap!=0 ? null : this, - 1<>4)+8>z.istate.wbits){ - z.istate.mode = BAD; - z.msg="invalid window size"; - z.istate.marker = 5; // can't try inflateSync - break; - } - z.istate.mode=FLAG; - case FLAG: - - if(z.avail_in==0)return r;r=f; - - z.avail_in--; z.total_in++; - b = (z.next_in[z.next_in_index++])&0xff; - - if((((z.istate.method << 8)+b) % 31)!=0){ - z.istate.mode = BAD; - z.msg = "incorrect header check"; - z.istate.marker = 5; // can't try inflateSync - break; - } - - if((b&PRESET_DICT)==0){ - z.istate.mode = BLOCKS; - break; - } - z.istate.mode = DICT4; - case DICT4: - - if(z.avail_in==0)return r;r=f; - - z.avail_in--; z.total_in++; - z.istate.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000; - z.istate.mode=DICT3; - case DICT3: - - if(z.avail_in==0)return r;r=f; - - z.avail_in--; z.total_in++; - z.istate.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000; - z.istate.mode=DICT2; - case DICT2: - - if(z.avail_in==0)return r;r=f; - - z.avail_in--; z.total_in++; - z.istate.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00; - z.istate.mode=DICT1; - case DICT1: - - if(z.avail_in==0)return r;r=f; - - z.avail_in--; z.total_in++; - z.istate.need += (z.next_in[z.next_in_index++]&0xff); - z.adler = z.istate.need; - z.istate.mode = DICT0; - return Z_NEED_DICT; - case DICT0: - z.istate.mode = BAD; - z.msg = "need dictionary"; - z.istate.marker = 0; // can try inflateSync - return Z_STREAM_ERROR; - case BLOCKS: - - r = z.istate.blocks.proc(z, r); - if(r == Z_DATA_ERROR){ - z.istate.mode = BAD; - z.istate.marker = 0; // can try inflateSync - break; - } - if(r == Z_OK){ - r = f; - } - if(r != Z_STREAM_END){ - return r; - } - r = f; - z.istate.blocks.reset(z, z.istate.was); - if(z.istate.nowrap!=0){ - z.istate.mode=DONE; - break; - } - z.istate.mode=CHECK4; - case CHECK4: - - if(z.avail_in==0)return r;r=f; - - z.avail_in--; z.total_in++; - z.istate.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000; - z.istate.mode=CHECK3; - case CHECK3: - - if(z.avail_in==0)return r;r=f; - - z.avail_in--; z.total_in++; - z.istate.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000; - z.istate.mode = CHECK2; - case CHECK2: - - if(z.avail_in==0)return r;r=f; - - z.avail_in--; z.total_in++; - z.istate.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00; - z.istate.mode = CHECK1; - case CHECK1: - - if(z.avail_in==0)return r;r=f; - - z.avail_in--; z.total_in++; - z.istate.need+=(z.next_in[z.next_in_index++]&0xff); - - if(((z.istate.was[0])) != ((z.istate.need))){ - z.istate.mode = BAD; - z.msg = "incorrect data check"; - z.istate.marker = 5; // can't try inflateSync - break; - } - - z.istate.mode = DONE; - case DONE: - return Z_STREAM_END; - case BAD: - return Z_DATA_ERROR; - default: - return Z_STREAM_ERROR; - } - } - } - - -Inflate.prototype.inflateSetDictionary = function(z, dictionary, dictLength) { - var index=0; - var length = dictLength; - if(z==null || z.istate == null|| z.istate.mode != DICT0) - return Z_STREAM_ERROR; - - if(z._adler.adler32(1, dictionary, 0, dictLength)!=z.adler){ - return Z_DATA_ERROR; - } - - z.adler = z._adler.adler32(0, null, 0, 0); - - if(length >= (1<>> 1){ - case 0: // stored - {b>>>=(3);k-=(3);} - t = k & 7; // go to byte boundary - - {b>>>=(t);k-=(t);} - this.mode = IB_LENS; // get length of stored block - break; - case 1: // fixed - { - var bl=new Int32Array(1); - var bd=new Int32Array(1); - var tl=[]; - var td=[]; - - inflate_trees_fixed(bl, bd, tl, td, z); - this.codes.init(bl[0], bd[0], tl[0], 0, td[0], 0, z); - } - - {b>>>=(3);k-=(3);} - - this.mode = IB_CODES; - break; - case 2: // dynamic - - {b>>>=(3);k-=(3);} - - this.mode = IB_TABLE; - break; - case 3: // illegal - - {b>>>=(3);k-=(3);} - this.mode = BAD; - z.msg = "invalid block type"; - r = Z_DATA_ERROR; - - this.bitb=b; this.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z,r); - } - break; - case IB_LENS: - while(k<(32)){ - if(n!=0){ - r=Z_OK; - } - else{ - this.bitb=b; this.bitk=k; - z.avail_in=n; - z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z,r); - }; - n--; - b|=(z.next_in[p++]&0xff)<>> 16) & 0xffff) != (b & 0xffff)){ - this.mode = BAD; - z.msg = "invalid stored block lengths"; - r = Z_DATA_ERROR; - - this.bitb=b; this.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z,r); - } - this.left = (b & 0xffff); - b = k = 0; // dump bits - this.mode = this.left!=0 ? IB_STORED : (this.last!=0 ? IB_DRY : IB_TYPE); - break; - case IB_STORED: - if (n == 0){ - this.bitb=b; this.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - write=q; - return this.inflate_flush(z,r); - } - - if(m==0){ - if(q==end&&read!=0){ - q=0; m=(qn) t = n; - if(t>m) t = m; - arrayCopy(z.next_in, p, window, q, t); - p += t; n -= t; - q += t; m -= t; - if ((this.left -= t) != 0) - break; - this.mode = (this.last != 0 ? IB_DRY : IB_TYPE); - break; - case IB_TABLE: - - while(k<(14)){ - if(n!=0){ - r=Z_OK; - } - else{ - this.bitb=b; this.bitk=k; - z.avail_in=n; - z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z,r); - }; - n--; - b|=(z.next_in[p++]&0xff)< 29 || ((t >> 5) & 0x1f) > 29) - { - this.mode = IB_BAD; - z.msg = "too many length or distance symbols"; - r = Z_DATA_ERROR; - - this.bitb=b; this.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z,r); - } - t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f); - if(this.blens==null || this.blens.length>>=(14);k-=(14);} - - this.index = 0; - this.mode = IB_BTREE; - case IB_BTREE: - while (this.index < 4 + (this.table >>> 10)){ - while(k<(3)){ - if(n!=0){ - r=Z_OK; - } - else{ - this.bitb=b; this.bitk=k; - z.avail_in=n; - z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z,r); - }; - n--; - b|=(z.next_in[p++]&0xff)<>>=(3);k-=(3);} - } - - while(this.index < 19){ - this.blens[INFBLOCKS_BORDER[this.index++]] = 0; - } - - this.bb[0] = 7; - t = this.inftree.inflate_trees_bits(this.blens, this.bb, this.tb, this.hufts, z); - if (t != Z_OK){ - r = t; - if (r == Z_DATA_ERROR){ - this.blens=null; - this.mode = IB_BAD; - } - - this.bitb=b; this.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - write=q; - return this.inflate_flush(z,r); - } - - this.index = 0; - this.mode = IB_DTREE; - case IB_DTREE: - while (true){ - t = this.table; - if(!(this.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))){ - break; - } - - var h; //int[] - var i, j, c; - - t = this.bb[0]; - - while(k<(t)){ - if(n!=0){ - r=Z_OK; - } - else{ - this.bitb=b; this.bitk=k; - z.avail_in=n; - z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z,r); - }; - n--; - b|=(z.next_in[p++]&0xff)<>>=(t);k-=(t); - this.blens[this.index++] = c; - } - else { // c == 16..18 - i = c == 18 ? 7 : c - 14; - j = c == 18 ? 11 : 3; - - while(k<(t+i)){ - if(n!=0){ - r=Z_OK; - } - else{ - this.bitb=b; this.bitk=k; - z.avail_in=n; - z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z,r); - }; - n--; - b|=(z.next_in[p++]&0xff)<>>=(t);k-=(t); - - j += (b & inflate_mask[i]); - - b>>>=(i);k-=(i); - - i = this.index; - t = this.table; - if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || - (c == 16 && i < 1)){ - this.blens=null; - this.mode = IB_BAD; - z.msg = "invalid bit length repeat"; - r = Z_DATA_ERROR; - - this.bitb=b; this.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z,r); - } - - c = c == 16 ? this.blens[i-1] : 0; - do{ - this.blens[i++] = c; - } - while (--j!=0); - this.index = i; - } - } - - this.tb[0]=-1; - { - var bl=new Int32Array(1); - var bd=new Int32Array(1); - var tl=new Int32Array(1); - var td=new Int32Array(1); - bl[0] = 9; // must be <= 9 for lookahead assumptions - bd[0] = 6; // must be <= 9 for lookahead assumptions - - t = this.table; - t = this.inftree.inflate_trees_dynamic(257 + (t & 0x1f), - 1 + ((t >> 5) & 0x1f), - this.blens, bl, bd, tl, td, this.hufts, z); - - if (t != Z_OK){ - if (t == Z_DATA_ERROR){ - this.blens=null; - this.mode = BAD; - } - r = t; - - this.bitb=b; this.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z,r); - } - this.codes.init(bl[0], bd[0], this.hufts, tl[0], this.hufts, td[0], z); - } - this.mode = IB_CODES; - case IB_CODES: - this.bitb=b; this.bitk=k; - z.avail_in=n; z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - - if ((r = this.codes.proc(this, z, r)) != Z_STREAM_END){ - return this.inflate_flush(z, r); - } - r = Z_OK; - this.codes.free(z); - - p=z.next_in_index; n=z.avail_in;b=this.bitb;k=this.bitk; - q=this.write;m = (q < this.read ? this.read-q-1 : this.end-q); - - if (this.last==0){ - this.mode = IB_TYPE; - break; - } - this.mode = IB_DRY; - case IB_DRY: - this.write=q; - r = this.inflate_flush(z, r); - q=this.write; m = (q < this.read ? this.read-q-1 : this.end-q); - if (this.read != this.write){ - this.bitb=b; this.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z, r); - } - this.mode = DONE; - case IB_DONE: - r = Z_STREAM_END; - - this.bitb=b; this.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z, r); - case IB_BAD: - r = Z_DATA_ERROR; - - this.bitb=b; this.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z, r); - - default: - r = Z_STREAM_ERROR; - - this.bitb=b; this.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - this.write=q; - return this.inflate_flush(z, r); - } - } - } - -InfBlocks.prototype.free = function(z){ - this.reset(z, null); - this.window=null; - this.hufts=null; -} - -InfBlocks.prototype.set_dictionary = function(d, start, n){ - arrayCopy(d, start, window, 0, n); - this.read = this.write = n; -} - - // Returns true if inflate is currently at the end of a block generated - // by Z_SYNC_FLUSH or Z_FULL_FLUSH. -InfBlocks.prototype.sync_point = function(){ - return this.mode == IB_LENS; -} - - // copy as much as possible from the sliding window to the output area -InfBlocks.prototype.inflate_flush = function(z, r){ - var n; - var p; - var q; - - // local copies of source and destination pointers - p = z.next_out_index; - q = this.read; - - // compute number of bytes to copy as far as end of window - n = ((q <= this.write ? this.write : this.end) - q); - if (n > z.avail_out) n = z.avail_out; - if (n!=0 && r == Z_BUF_ERROR) r = Z_OK; - - // update counters - z.avail_out -= n; - z.total_out += n; - - // update check information - if(this.checkfn != null) - z.adler=this.check=z._adler.adler32(this.check, this.window, q, n); - - // copy as far as end of window - arrayCopy(this.window, q, z.next_out, p, n); - p += n; - q += n; - - // see if more to copy at beginning of window - if (q == this.end){ - // wrap pointers - q = 0; - if (this.write == this.end) - this.write = 0; - - // compute bytes to copy - n = this.write - q; - if (n > z.avail_out) n = z.avail_out; - if (n!=0 && r == Z_BUF_ERROR) r = Z_OK; - - // update counters - z.avail_out -= n; - z.total_out += n; - - // update check information - if(this.checkfn != null) - z.adler=this.check=z._adler.adler32(this.check, this.window, q, n); - - // copy - arrayCopy(this.window, q, z.next_out, p, n); - p += n; - q += n; - } - - // update pointers - z.next_out_index = p; - this.read = q; - - // done - return r; - } - -// -// InfCodes.java -// - -var IC_START=0; // x: set up for LEN -var IC_LEN=1; // i: get length/literal/eob next -var IC_LENEXT=2; // i: getting length extra (have base) -var IC_DIST=3; // i: get distance next -var IC_DISTEXT=4;// i: getting distance extra -var IC_COPY=5; // o: copying bytes in window, waiting for space -var IC_LIT=6; // o: got literal, waiting for output space -var IC_WASH=7; // o: got eob, possibly still output waiting -var IC_END=8; // x: got eob and all data flushed -var IC_BADCODE=9;// x: got error - -function InfCodes() { -} - -InfCodes.prototype.init = function(bl, bd, tl, tl_index, td, td_index, z) { - this.mode=IC_START; - this.lbits=bl; - this.dbits=bd; - this.ltree=tl; - this.ltree_index=tl_index; - this.dtree = td; - this.dtree_index=td_index; - this.tree=null; -} - -InfCodes.prototype.proc = function(s, z, r){ - var j; // temporary storage - var t; // temporary pointer (int[]) - var tindex; // temporary pointer - var e; // extra bits or operation - var b=0; // bit buffer - var k=0; // bits in bit buffer - var p=0; // input data pointer - var n; // bytes available there - var q; // output window write pointer - var m; // bytes to end of window or read pointer - var f; // pointer to copy strings from - - // copy input/output information to locals (UPDATE macro restores) - p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk; - q=s.write;m=q= 258 && n >= 10){ - - s.bitb=b;s.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - s.write=q; - r = this.inflate_fast(this.lbits, this.dbits, - this.ltree, this.ltree_index, - this.dtree, this.dtree_index, - s, z); - - p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk; - q=s.write;m=q>>=(this.tree[tindex+1]); - k-=(this.tree[tindex+1]); - - e=this.tree[tindex]; - - if(e == 0){ // literal - this.lit = this.tree[tindex+2]; - this.mode = IC_LIT; - break; - } - if((e & 16)!=0 ){ // length - this.get = e & 15; - this.len = this.tree[tindex+2]; - this.mode = IC_LENEXT; - break; - } - if ((e & 64) == 0){ // next table - this.need = e; - this.tree_index = tindex/3 + this.tree[tindex+2]; - break; - } - if ((e & 32)!=0){ // end of block - this.mode = IC_WASH; - break; - } - this.mode = IC_BADCODE; // invalid code - z.msg = "invalid literal/length code"; - r = Z_DATA_ERROR; - - s.bitb=b;s.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - s.write=q; - return s.inflate_flush(z,r); - - case IC_LENEXT: // i: getting length extra (have base) - j = this.get; - - while(k<(j)){ - if(n!=0)r=Z_OK; - else{ - - s.bitb=b;s.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - s.write=q; - return s.inflate_flush(z,r); - } - n--; b|=(z.next_in[p++]&0xff)<>=j; - k-=j; - - this.need = this.dbits; - this.tree = this.dtree; - this.tree_index = this.dtree_index; - this.mode = IC_DIST; - case IC_DIST: // i: get distance next - j = this.need; - - while(k<(j)){ - if(n!=0)r=Z_OK; - else{ - - s.bitb=b;s.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - s.write=q; - return s.inflate_flush(z,r); - } - n--; b|=(z.next_in[p++]&0xff)<>=this.tree[tindex+1]; - k-=this.tree[tindex+1]; - - e = (this.tree[tindex]); - if((e & 16)!=0){ // distance - this.get = e & 15; - this.dist = this.tree[tindex+2]; - this.mode = IC_DISTEXT; - break; - } - if ((e & 64) == 0){ // next table - this.need = e; - this.tree_index = tindex/3 + this.tree[tindex+2]; - break; - } - this.mode = IC_BADCODE; // invalid code - z.msg = "invalid distance code"; - r = Z_DATA_ERROR; - - s.bitb=b;s.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - s.write=q; - return s.inflate_flush(z,r); - - case IC_DISTEXT: // i: getting distance extra - j = this.get; - - while(k<(j)){ - if(n!=0)r=Z_OK; - else{ - - s.bitb=b;s.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - s.write=q; - return s.inflate_flush(z,r); - } - n--; b|=(z.next_in[p++]&0xff)<>=j; - k-=j; - - this.mode = IC_COPY; - case IC_COPY: // o: copying bytes in window, waiting for space - f = q - this.dist; - while(f < 0){ // modulo window size-"while" instead - f += s.end; // of "if" handles invalid distances - } - while (this.len!=0){ - - if(m==0){ - if(q==s.end&&s.read!=0){q=0;m=q 7){ // return unused byte, if any - k -= 8; - n++; - p--; // can always return one - } - - s.write=q; r=s.inflate_flush(z,r); - q=s.write;m=q= 258 && n >= 10 - // get literal/length code - while(k<(20)){ // max bits for literal/length code - n--; - b|=(z.next_in[p++]&0xff)<>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]); - - s.window[q++] = tp[tp_index_t_3+2]; - m--; - continue; - } - do { - - b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]); - - if((e&16)!=0){ - e &= 15; - c = tp[tp_index_t_3+2] + (b & inflate_mask[e]); - - b>>=e; k-=e; - - // decode distance base of block to copy - while(k<(15)){ // max bits for distance code - n--; - b|=(z.next_in[p++]&0xff)<>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]); - - if((e&16)!=0){ - // get extra bits to add to distance base - e &= 15; - while(k<(e)){ // get extra bits (up to 13) - n--; - b|=(z.next_in[p++]&0xff)<>=(e); k-=(e); - - // do the copy - m -= c; - if (q >= d){ // offset before dest - // just copy - r=q-d; - if(q-r>0 && 2>(q-r)){ - s.window[q++]=s.window[r++]; // minimum count is three, - s.window[q++]=s.window[r++]; // so unroll loop a little - c-=2; - } - else{ - s.window[q++]=s.window[r++]; // minimum count is three, - s.window[q++]=s.window[r++]; // so unroll loop a little - c-=2; - } - } - else{ // else offset after destination - r=q-d; - do{ - r+=s.end; // force pointer in window - }while(r<0); // covers invalid distances - e=s.end-r; - if(c>e){ // if source crosses, - c-=e; // wrapped copy - if(q-r>0 && e>(q-r)){ - do{s.window[q++] = s.window[r++];} - while(--e!=0); - } - else{ - arrayCopy(s.window, r, s.window, q, e); - q+=e; r+=e; e=0; - } - r = 0; // copy rest from start of window - } - - } - - // copy all or what's left - do{s.window[q++] = s.window[r++];} - while(--c!=0); - break; - } - else if((e&64)==0){ - t+=tp[tp_index_t_3+2]; - t+=(b&inflate_mask[e]); - tp_index_t_3=(tp_index+t)*3; - e=tp[tp_index_t_3]; - } - else{ - z.msg = "invalid distance code"; - - c=z.avail_in-n;c=(k>>3)>3:c;n+=c;p-=c;k-=c<<3; - - s.bitb=b;s.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - s.write=q; - - return Z_DATA_ERROR; - } - } - while(true); - break; - } - - if((e&64)==0){ - t+=tp[tp_index_t_3+2]; - t+=(b&inflate_mask[e]); - tp_index_t_3=(tp_index+t)*3; - if((e=tp[tp_index_t_3])==0){ - - b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]); - - s.window[q++]=tp[tp_index_t_3+2]; - m--; - break; - } - } - else if((e&32)!=0){ - - c=z.avail_in-n;c=(k>>3)>3:c;n+=c;p-=c;k-=c<<3; - - s.bitb=b;s.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - s.write=q; - - return Z_STREAM_END; - } - else{ - z.msg="invalid literal/length code"; - - c=z.avail_in-n;c=(k>>3)>3:c;n+=c;p-=c;k-=c<<3; - - s.bitb=b;s.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - s.write=q; - - return Z_DATA_ERROR; - } - } - while(true); - } - while(m>=258 && n>= 10); - - // not enough input or output--restore pointers and return - c=z.avail_in-n;c=(k>>3)>3:c;n+=c;p-=c;k-=c<<3; - - s.bitb=b;s.bitk=k; - z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p; - s.write=q; - - return Z_OK; -} - -// -// InfTree.java -// - -function InfTree() { -} - -InfTree.prototype.huft_build = function(b, bindex, n, s, d, e, t, m, hp, hn, v) { - - // Given a list of code lengths and a maximum table size, make a set of - // tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR - // if the given code set is incomplete (the tables are still built in this - // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of - // lengths), or Z_MEM_ERROR if not enough memory. - - var a; // counter for codes of length k - var f; // i repeats in table every f entries - var g; // maximum code length - var h; // table level - var i; // counter, current code - var j; // counter - var k; // number of bits in current code - var l; // bits per table (returned in m) - var mask; // (1 << w) - 1, to avoid cc -O bug on HP - var p; // pointer into c[], b[], or v[] - var q; // points to current table - var w; // bits before this table == (l * h) - var xp; // pointer into x - var y; // number of dummy codes added - var z; // number of entries in current table - - // Generate counts for each bit length - - p = 0; i = n; - do { - this.c[b[bindex+p]]++; p++; i--; // assume all entries <= BMAX - }while(i!=0); - - if(this.c[0] == n){ // null input--all zero length codes - t[0] = -1; - m[0] = 0; - return Z_OK; - } - - // Find minimum and maximum length, bound *m by those - l = m[0]; - for (j = 1; j <= BMAX; j++) - if(this.c[j]!=0) break; - k = j; // minimum code length - if(l < j){ - l = j; - } - for (i = BMAX; i!=0; i--){ - if(this.c[i]!=0) break; - } - g = i; // maximum code length - if(l > i){ - l = i; - } - m[0] = l; - - // Adjust last length count to fill out codes, if needed - for (y = 1 << j; j < i; j++, y <<= 1){ - if ((y -= this.c[j]) < 0){ - return Z_DATA_ERROR; - } - } - if ((y -= this.c[i]) < 0){ - return Z_DATA_ERROR; - } - this.c[i] += y; - - // Generate starting offsets into the value table for each length - this.x[1] = j = 0; - p = 1; xp = 2; - while (--i!=0) { // note that i == g from above - this.x[xp] = (j += this.c[p]); - xp++; - p++; - } - - // Make a table of values in order of bit lengths - i = 0; p = 0; - do { - if ((j = b[bindex+p]) != 0){ - this.v[this.x[j]++] = i; - } - p++; - } - while (++i < n); - n = this.x[g]; // set n to length of v - - // Generate the Huffman codes and for each, make the table entries - this.x[0] = i = 0; // first Huffman code is zero - p = 0; // grab values in bit order - h = -1; // no tables yet--level -1 - w = -l; // bits decoded == (l * h) - this.u[0] = 0; // just to keep compilers happy - q = 0; // ditto - z = 0; // ditto - - // go through the bit lengths (k already is bits in shortest code) - for (; k <= g; k++){ - a = this.c[k]; - while (a--!=0){ - // here i is the Huffman code of length k bits for value *p - // make tables up to required level - while (k > w + l){ - h++; - w += l; // previous table always l bits - // compute minimum size table less than or equal to l bits - z = g - w; - z = (z > l) ? l : z; // table size upper limit - if((f=1<<(j=k-w))>a+1){ // try a k-w bit table - // too few codes for k-w bit table - f -= a + 1; // deduct codes from patterns left - xp = k; - if(j < z){ - while (++j < z){ // try smaller tables up to z bits - if((f <<= 1) <= this.c[++xp]) - break; // enough codes to use up j bits - f -= this.c[xp]; // else deduct codes from patterns - } - } - } - z = 1 << j; // table entries for j-bit table - - // allocate new table - if (this.hn[0] + z > MANY){ // (note: doesn't matter for fixed) - return Z_DATA_ERROR; // overflow of MANY - } - this.u[h] = q = /*hp+*/ this.hn[0]; // DEBUG - this.hn[0] += z; - - // connect to last table, if there is one - if(h!=0){ - this.x[h]=i; // save pattern for backing up - this.r[0]=j; // bits in this table - this.r[1]=l; // bits to dump before this table - j=i>>>(w - l); - this.r[2] = (q - this.u[h-1] - j); // offset to this table - arrayCopy(this.r, 0, hp, (this.u[h-1]+j)*3, 3); // connect to last table - } - else{ - t[0] = q; // first table is returned result - } - } - - // set up table entry in r - this.r[1] = (k - w); - if (p >= n){ - this.r[0] = 128 + 64; // out of values--invalid code - } - else if (v[p] < s){ - this.r[0] = (this.v[p] < 256 ? 0 : 32 + 64); // 256 is end-of-block - this.r[2] = this.v[p++]; // simple code is just the value - } - else{ - this.r[0]=(e[this.v[p]-s]+16+64); // non-simple--look up in lists - this.r[2]=d[this.v[p++] - s]; - } - - // fill code-like entries with r - f=1<<(k-w); - for (j=i>>>w;j>>= 1){ - i ^= j; - } - i ^= j; - - // backup over finished tables - mask = (1 << w) - 1; // needed on HP, cc -O bug - while ((i & mask) != this.x[h]){ - h--; // don't need to update q - w -= l; - mask = (1 << w) - 1; - } - } - } - // Return Z_BUF_ERROR if we were given an incomplete table - return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK; -} - -InfTree.prototype.inflate_trees_bits = function(c, bb, tb, hp, z) { - var result; - this.initWorkArea(19); - this.hn[0]=0; - result = this.huft_build(c, 0, 19, 19, null, null, tb, bb, hp, this.hn, this.v); - - if(result == Z_DATA_ERROR){ - z.msg = "oversubscribed dynamic bit lengths tree"; - } - else if(result == Z_BUF_ERROR || bb[0] == 0){ - z.msg = "incomplete dynamic bit lengths tree"; - result = Z_DATA_ERROR; - } - return result; -} - -InfTree.prototype.inflate_trees_dynamic = function(nl, nd, c, bl, bd, tl, td, hp, z) { - var result; - - // build literal/length tree - this.initWorkArea(288); - this.hn[0]=0; - result = this.huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, this.hn, this.v); - if (result != Z_OK || bl[0] == 0){ - if(result == Z_DATA_ERROR){ - z.msg = "oversubscribed literal/length tree"; - } - else if (result != Z_MEM_ERROR){ - z.msg = "incomplete literal/length tree"; - result = Z_DATA_ERROR; - } - return result; - } - - // build distance tree - this.initWorkArea(288); - result = this.huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, this.hn, this.v); - - if (result != Z_OK || (bd[0] == 0 && nl > 257)){ - if (result == Z_DATA_ERROR){ - z.msg = "oversubscribed distance tree"; - } - else if (result == Z_BUF_ERROR) { - z.msg = "incomplete distance tree"; - result = Z_DATA_ERROR; - } - else if (result != Z_MEM_ERROR){ - z.msg = "empty distance tree with lengths"; - result = Z_DATA_ERROR; - } - return result; - } - - return Z_OK; -} -/* - static int inflate_trees_fixed(int[] bl, //literal desired/actual bit depth - int[] bd, //distance desired/actual bit depth - int[][] tl,//literal/length tree result - int[][] td,//distance tree result - ZStream z //for memory allocation - ){ - -*/ - -function inflate_trees_fixed(bl, bd, tl, td, z) { - bl[0]=fixed_bl; - bd[0]=fixed_bd; - tl[0]=fixed_tl; - td[0]=fixed_td; - return Z_OK; -} - -InfTree.prototype.initWorkArea = function(vsize){ - if(this.hn==null){ - this.hn=new Int32Array(1); - this.v=new Int32Array(vsize); - this.c=new Int32Array(BMAX+1); - this.r=new Int32Array(3); - this.u=new Int32Array(BMAX); - this.x=new Int32Array(BMAX+1); - } - if(this.v.length 100) { - arrayCopy_fast(new Uint8Array(src.buffer, src.byteOffset + srcOffset, count), dest, destOffset); - } else { - arrayCopy_slow(src, srcOffset, dest, destOffset, count); - } - -} - -function arrayCopy_slow(src, srcOffset, dest, destOffset, count) { - - // dlog('_slow call: srcOffset=' + srcOffset + '; destOffset=' + destOffset + '; count=' + count); - - for (var i = 0; i < count; ++i) { - dest[destOffset + i] = src[srcOffset + i]; - } -} - -function arrayCopy_fast(src, dest, destOffset) { - dest.set(src, destOffset); -} - - - // largest prime smaller than 65536 -var ADLER_BASE=65521; - // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 -var ADLER_NMAX=5552; - -function adler32(adler, /* byte[] */ buf, index, len){ - if(buf == null){ return 1; } - - var s1=adler&0xffff; - var s2=(adler>>16)&0xffff; - var k; - - while(len > 0) { - k=len=16){ - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - s1+=buf[index++]&0xff; s2+=s1; - k-=16; - } - if(k!=0){ - do{ - s1+=buf[index++]&0xff; s2+=s1; - } - while(--k!=0); - } - s1%=ADLER_BASE; - s2%=ADLER_BASE; - } - return (s2<<16)|s1; -} - - - -function jszlib_inflate_buffer(buffer, start, length, afterUncOffset) { - if (!start) { - buffer = new Uint8Array(buffer); - } else { - buffer = new Uint8Array(buffer, start, length); - } - - var z = new ZStream(); - z.inflateInit(DEF_WBITS, true); - z.next_in = buffer; - z.next_in_index = 0; - z.avail_in = buffer.length; - - var oBlockList = []; - var totalSize = 0; - while (true) { - var obuf = new Uint8Array(32000); - z.next_out = obuf; - z.next_out_index = 0; - z.avail_out = obuf.length; - var status = z.inflate(Z_NO_FLUSH); - if (status == Z_BUF_ERROR) { - break; - } - if (status != Z_OK && status != Z_STREAM_END) { - throw z.msg; - } - if (z.avail_out != 0) { - var newob = new Uint8Array(obuf.length - z.avail_out); - arrayCopy(obuf, 0, newob, 0, (obuf.length - z.avail_out)); - obuf = newob; - } - oBlockList.push(obuf); - totalSize += obuf.length; - if (status == Z_STREAM_END) { - break; - } - } - - if (afterUncOffset) { - afterUncOffset[0] = (start || 0) + z.next_in_index; - } - - if (oBlockList.length == 1) { - return oBlockList[0].buffer; - } else { - var out = new Uint8Array(totalSize); - var cursor = 0; - for (var i = 0; i < oBlockList.length; ++i) { - var b = oBlockList[i]; - arrayCopy(b, 0, out, cursor, b.length); - cursor += b.length; - } - return out.buffer; - } -} -// Source: https://github.com/vadimg/js_bintrees -// MIT license - - -function TreeBase() { -} - -// removes all nodes from the tree -TreeBase.prototype.clear = function () { - this._root = null; - this.size = 0; -}; - -// returns node data if found, null otherwise -TreeBase.prototype.find = function (data) { - var res = this._root; - - while (res !== null) { - var c = this._comparator(data, res.data); - if (c === 0) { - return res.data; - } - else { - res = res.get_child(c > 0); - } - } - - return null; -}; - -// returns iterator to node if found, null otherwise -TreeBase.prototype.findIter = function (data) { - var res = this._root; - var iter = this.iterator(); - - while (res !== null) { - var c = this._comparator(data, res.data); - if (c === 0) { - iter._cursor = res; - return iter; - } - else { - iter._ancestors.push(res); - res = res.get_child(c > 0); - } - } - - return null; -}; - -// Returns an iterator to the tree node at or immediately after the item -TreeBase.prototype.lowerBound = function (item) { - var cur = this._root; - var iter = this.iterator(); - var cmp = this._comparator; - - while (cur !== null) { - var c = cmp(item, cur.data); - if (c === 0) { - iter._cursor = cur; - return iter; - } - iter._ancestors.push(cur); - cur = cur.get_child(c > 0); - } - - for (var i = iter._ancestors.length - 1; i >= 0; --i) { - cur = iter._ancestors[i]; - if (cmp(item, cur.data) < 0) { - iter._cursor = cur; - iter._ancestors.length = i; - return iter; - } - } - - iter._ancestors.length = 0; - return iter; -}; - -// Returns an iterator to the tree node immediately after the item -TreeBase.prototype.upperBound = function (item) { - var iter = this.lowerBound(item); - var cmp = this._comparator; - - while (iter.data() !== null && cmp(iter.data(), item) === 0) { - iter.next(); - } - - return iter; -}; - -// returns null if tree is empty -TreeBase.prototype.min = function () { - var res = this._root; - if (res === null) { - return null; - } - - while (res.left !== null) { - res = res.left; - } - - return res.data; -}; - -// returns null if tree is empty -TreeBase.prototype.max = function () { - var res = this._root; - if (res === null) { - return null; - } - - while (res.right !== null) { - res = res.right; - } - - return res.data; -}; - -// returns a null iterator -// call next() or prev() to point to an element -TreeBase.prototype.iterator = function () { - return new Iterator(this); -}; - -// calls cb on each node's data, in order -TreeBase.prototype.each = function (cb) { - var it = this.iterator(), data; - while ((data = it.next()) !== null) { - cb(data); - } -}; - -// calls cb on each node's data, in reverse order -TreeBase.prototype.reach = function (cb) { - var it = this.iterator(), data; - while ((data = it.prev()) !== null) { - cb(data); - } -}; - - -function Iterator(tree) { - this._tree = tree; - this._ancestors = []; - this._cursor = null; -} - -Iterator.prototype.data = function () { - return this._cursor !== null ? this._cursor.data : null; -}; - -// if null-iterator, returns first node -// otherwise, returns next node -Iterator.prototype.next = function () { - if (this._cursor === null) { - var root = this._tree._root; - if (root !== null) { - this._minNode(root); - } - } - else { - if (this._cursor.right === null) { - // no greater node in subtree, go up to parent - // if coming from a right child, continue up the stack - var save; - do { - save = this._cursor; - if (this._ancestors.length) { - this._cursor = this._ancestors.pop(); - } - else { - this._cursor = null; - break; - } - } while (this._cursor.right === save); - } - else { - // get the next node from the subtree - this._ancestors.push(this._cursor); - this._minNode(this._cursor.right); - } - } - return this._cursor !== null ? this._cursor.data : null; -}; - -// if null-iterator, returns last node -// otherwise, returns previous node -Iterator.prototype.prev = function () { - if (this._cursor === null) { - var root = this._tree._root; - if (root !== null) { - this._maxNode(root); - } - } - else { - if (this._cursor.left === null) { - var save; - do { - save = this._cursor; - if (this._ancestors.length) { - this._cursor = this._ancestors.pop(); - } - else { - this._cursor = null; - break; - } - } while (this._cursor.left === save); - } - else { - this._ancestors.push(this._cursor); - this._maxNode(this._cursor.left); - } - } - return this._cursor !== null ? this._cursor.data : null; -}; - -Iterator.prototype._minNode = function (start) { - while (start.left !== null) { - this._ancestors.push(start); - start = start.left; - } - this._cursor = start; -}; - -Iterator.prototype._maxNode = function (start) { - while (start.right !== null) { - this._ancestors.push(start); - start = start.right; - } - this._cursor = start; -}; - - -function Node(data) { - this.data = data; - this.left = null; - this.right = null; - this.red = true; -} - -Node.prototype.get_child = function (dir) { - return dir ? this.right : this.left; -}; - -Node.prototype.set_child = function (dir, val) { - if (dir) { - this.right = val; - } - else { - this.left = val; - } -}; - -function RBTree(comparator) { - this._root = null; - this._comparator = comparator; - this.size = 0; -} - -RBTree.prototype = new TreeBase(); - -// returns true if inserted, false if duplicate -RBTree.prototype.insert = function (data) { - var ret = false; - - if (this._root === null) { - // empty tree - this._root = new Node(data); - ret = true; - this.size++; - } - else { - var head = new Node(undefined); // fake tree root - - var dir = 0; - var last = 0; - - // setup - var gp = null; // grandparent - var ggp = head; // grand-grand-parent - var p = null; // parent - var node = this._root; - ggp.right = this._root; - - // search down - while (true) { - if (node === null) { - // insert new node at the bottom - node = new Node(data); - p.set_child(dir, node); - ret = true; - this.size++; - } - else if (is_red(node.left) && is_red(node.right)) { - // color flip - node.red = true; - node.left.red = false; - node.right.red = false; - } - - // fix red violation - if (is_red(node) && is_red(p)) { - var dir2 = ggp.right === gp; - - if (node === p.get_child(last)) { - ggp.set_child(dir2, single_rotate(gp, !last)); - } - else { - ggp.set_child(dir2, double_rotate(gp, !last)); - } - } - - var cmp = this._comparator(node.data, data); - - // stop if found - if (cmp === 0) { - break; - } - - last = dir; - dir = cmp < 0; - - // update helpers - if (gp !== null) { - ggp = gp; - } - gp = p; - p = node; - node = node.get_child(dir); - } - - // update root - this._root = head.right; - } - - // make root black - this._root.red = false; - - return ret; -}; - -// returns true if removed, false if not found -RBTree.prototype.remove = function (data) { - if (this._root === null) { - return false; - } - - var head = new Node(undefined); // fake tree root - var node = head; - node.right = this._root; - var p = null; // parent - var gp = null; // grand parent - var found = null; // found item - var dir = 1; - - while (node.get_child(dir) !== null) { - var last = dir; - - // update helpers - gp = p; - p = node; - node = node.get_child(dir); - - var cmp = this._comparator(data, node.data); - - dir = cmp > 0; - - // save found node - if (cmp === 0) { - found = node; - } - - // push the red node down - if (!is_red(node) && !is_red(node.get_child(dir))) { - if (is_red(node.get_child(!dir))) { - var sr = single_rotate(node, dir); - p.set_child(last, sr); - p = sr; - } - else if (!is_red(node.get_child(!dir))) { - var sibling = p.get_child(!last); - if (sibling !== null) { - if (!is_red(sibling.get_child(!last)) && !is_red(sibling.get_child(last))) { - // color flip - p.red = false; - sibling.red = true; - node.red = true; - } - else { - var dir2 = gp.right === p; - - if (is_red(sibling.get_child(last))) { - gp.set_child(dir2, double_rotate(p, last)); - } - else if (is_red(sibling.get_child(!last))) { - gp.set_child(dir2, single_rotate(p, last)); - } - - // ensure correct coloring - var gpc = gp.get_child(dir2); - gpc.red = true; - node.red = true; - gpc.left.red = false; - gpc.right.red = false; - } - } - } - } - } - - // replace and remove if found - if (found !== null) { - found.data = node.data; - p.set_child(p.right === node, node.get_child(node.left === null)); - this.size--; - } - - // update root and make it black - this._root = head.right; - if (this._root !== null) { - this._root.red = false; - } - - return found !== null; -}; - -function is_red(node) { - return node !== null && node.red; -} - -function single_rotate(root, dir) { - var save = root.get_child(!dir); - - root.set_child(!dir, save.get_child(dir)); - save.set_child(dir, root); - - root.red = true; - save.red = false; - - return save; -} - -function double_rotate(root, dir) { - root.set_child(!dir, single_rotate(root.get_child(!dir), !dir)); - return single_rotate(root, dir); -} - - -// Source: https://github.com/welch/tdigest -// MIT License -// -// TDigest: -// -// approximate distribution percentiles from a stream of reals -// - - -function TDigest(delta, K, CX) { - // allocate a TDigest structure. - // - // delta is the compression factor, the max fraction of mass that - // can be owned by one centroid (bigger, up to 1.0, means more - // compression). delta=false switches off TDigest behavior and treats - // the distribution as discrete, with no merging and exact values - // reported. - // - // K is a size threshold that triggers recompression as the TDigest - // grows during input. (Set it to 0 to disable automatic recompression) - // - // CX specifies how often to update cached cumulative totals used - // for quantile estimation during ingest (see cumulate()). Set to - // 0 to use exact quantiles for each new point. - // - this.discrete = (delta === false); - this.delta = delta || 0.01; - this.K = (K === undefined) ? 25 : K; - this.CX = (CX === undefined) ? 1.1 : CX; - this.centroids = new RBTree(compare_centroid_means); - this.nreset = 0; - this.reset(); -} - -TDigest.prototype.reset = function () { - // prepare to digest new points. - // - this.centroids.clear(); - this.n = 0; - this.nreset += 1; - this.last_cumulate = 0; -}; - -TDigest.prototype.size = function () { - return this.centroids.size; -}; - -TDigest.prototype.toArray = function (everything) { - // return {mean,n} of centroids as an array ordered by mean. - // - var result = []; - if (everything) { - this._cumulate(true); // be sure cumns are exact - this.centroids.each(function (c) { - result.push(c); - }); - } else { - this.centroids.each(function (c) { - result.push({mean: c.mean, n: c.n}); - }); - } - return result; -}; - -TDigest.prototype.summary = function () { - var approx = (this.discrete) ? "exact " : "approximating "; - var s = [approx + this.n + " samples using " + this.size() + " centroids", - "min = " + this.percentile(0), - "Q1 = " + this.percentile(0.25), - "Q2 = " + this.percentile(0.5), - "Q3 = " + this.percentile(0.75), - "max = " + this.percentile(1.0)]; - return s.join('\n'); -}; - -function compare_centroid_means(a, b) { - // order two centroids by mean. - // - return (a.mean > b.mean) ? 1 : (a.mean < b.mean) ? -1 : 0; -} - -function compare_centroid_mean_cumns(a, b) { - // order two centroids by mean_cumn. - // - return (a.mean_cumn - b.mean_cumn); -} - -TDigest.prototype.push = function (x, n) { - // incorporate value or array of values x, having count n into the - // TDigest. n defaults to 1. - // - n = n || 1; - x = Array.isArray(x) ? x : [x]; - for (var i = 0; i < x.length; i++) { - this._digest(x[i], n); - } -}; - -TDigest.prototype.push_centroid = function (c) { - // incorporate centroid or array of centroids c - // - c = Array.isArray(c) ? c : [c]; - for (var i = 0; i < c.length; i++) { - this._digest(c[i].mean, c[i].n); - } -}; - -TDigest.prototype._cumulate = function (exact) { - // update cumulative counts for each centroid - // - // exact: falsey means only cumulate after sufficient - // growth. During ingest, these counts are used as quantile - // estimates, and they work well even when somewhat out of - // date. (this is a departure from the publication, you may set CX - // to 0 to disable). - // - if (this.n === this.last_cumulate || - !exact && this.CX && this.CX > (this.n / this.last_cumulate)) { - return; - } - var cumn = 0; - this.centroids.each(function (c) { - c.mean_cumn = cumn + c.n / 2; // half of n at the mean - cumn = c.cumn = cumn + c.n; - }); - this.n = this.last_cumulate = cumn; -}; - -TDigest.prototype.find_nearest = function (x) { - // find the centroid closest to x. The assumption of - // unique means and a unique nearest centroid departs from the - // paper, see _digest() below - // - if (this.size() === 0) { - return null; - } - var iter = this.centroids.lowerBound({mean: x}); // x <= iter || iter==null - var c = (iter.data() === null) ? iter.prev() : iter.data(); - if (c.mean === x || this.discrete) { - return c; // c is either x or a neighbor (discrete: no distance func) - } - var prev = iter.prev(); - if (prev && Math.abs(prev.mean - x) < Math.abs(c.mean - x)) { - return prev; - } else { - return c; - } -}; - -TDigest.prototype._new_centroid = function (x, n, cumn) { - // create and insert a new centroid into the digest (don't update - // cumulatives). - // - var c = {mean: x, n: n, cumn: cumn}; - this.centroids.insert(c); - this.n += n; - return c; -}; - -TDigest.prototype._addweight = function (nearest, x, n) { - // add weight at location x to nearest centroid. adding x to - // nearest will not shift its relative position in the tree and - // require reinsertion. - // - if (x !== nearest.mean) { - nearest.mean += n * (x - nearest.mean) / (nearest.n + n); - } - nearest.cumn += n; - nearest.mean_cumn += n / 2; - nearest.n += n; - this.n += n; -}; - -TDigest.prototype._digest = function (x, n) { - // incorporate value x, having count n into the TDigest. - // - var min = this.centroids.min(); - var max = this.centroids.max(); - var nearest = this.find_nearest(x); - if (nearest && nearest.mean === x) { - // accumulate exact matches into the centroid without - // limit. this is a departure from the paper, made so - // centroids remain unique and code can be simple. - this._addweight(nearest, x, n); - } else if (nearest === min) { - this._new_centroid(x, n, 0); // new point around min boundary - } else if (nearest === max) { - this._new_centroid(x, n, this.n); // new point around max boundary - } else if (this.discrete) { - this._new_centroid(x, n, nearest.cumn); // never merge - } else { - // conider a merge based on nearest centroid's capacity. if - // there's not room for all of n, don't bother merging any of - // it into nearest, as we'll have to make a new centroid - // anyway for the remainder (departure from the paper). - var p = nearest.mean_cumn / this.n; - var max_n = Math.floor(4 * this.n * this.delta * p * (1 - p)); - if (max_n - nearest.n >= n) { - this._addweight(nearest, x, n); - } else { - this._new_centroid(x, n, nearest.cumn); - } - } - this._cumulate(false); - if (!this.discrete && this.K && this.size() > this.K / this.delta) { - // re-process the centroids and hope for some compression. - this.compress(); - } -}; - -TDigest.prototype.bound_mean = function (x) { - // find centroids lower and upper such that lower.mean < x < - // upper.mean or lower.mean === x === upper.mean. Don't call - // this for x out of bounds. - // - var iter = this.centroids.upperBound({mean: x}); // x < iter - var lower = iter.prev(); // lower <= x - var upper = (lower.mean === x) ? lower : iter.next(); - return [lower, upper]; -}; - -TDigest.prototype.p_rank = function (x_or_xlist) { - // return approximate percentile-ranks (0..1) for data value x. - // or list of x. calculated according to - // https://en.wikipedia.org/wiki/Percentile_rank - // - // (Note that in continuous mode, boundary sample values will - // report half their centroid weight inward from 0/1 as the - // percentile-rank. X values outside the observed range return - // 0/1) - // - // this triggers cumulate() if cumn's are out of date. - // - var xs = Array.isArray(x_or_xlist) ? x_or_xlist : [x_or_xlist]; - var ps = xs.map(this._p_rank, this); - return Array.isArray(x_or_xlist) ? ps : ps[0]; -}; - -TDigest.prototype._p_rank = function (x) { - if (this.size() === 0) { - return undefined; - } else if (x < this.centroids.min().mean) { - return 0.0; - } else if (x > this.centroids.max().mean) { - return 1.0; - } - // find centroids that bracket x and interpolate x's cumn from - // their cumn's. - this._cumulate(true); // be sure cumns are exact - var bound = this.bound_mean(x); - var lower = bound[0], upper = bound[1]; - if (this.discrete) { - return lower.cumn / this.n; - } else { - var cumn = lower.mean_cumn; - if (lower !== upper) { - cumn += (x - lower.mean) * (upper.mean_cumn - lower.mean_cumn) / (upper.mean - lower.mean); - } - return cumn / this.n; - } -}; - -TDigest.prototype.bound_mean_cumn = function (cumn) { - // find centroids lower and upper such that lower.mean_cumn < x < - // upper.mean_cumn or lower.mean_cumn === x === upper.mean_cumn. Don't call - // this for cumn out of bounds. - // - // XXX because mean and mean_cumn give rise to the same sort order - // (up to identical means), use the mean rbtree for our search. - this.centroids._comparator = compare_centroid_mean_cumns; - var iter = this.centroids.upperBound({mean_cumn: cumn}); // cumn < iter - this.centroids._comparator = compare_centroid_means; - var lower = iter.prev(); // lower <= cumn - var upper = (lower && lower.mean_cumn === cumn) ? lower : iter.next(); - return [lower, upper]; -}; - -TDigest.prototype.percentile = function (p_or_plist) { - // for percentage p (0..1), or for each p in a list of ps, return - // the smallest data value q at which at least p percent of the - // observations <= q. - // - // for discrete distributions, this selects q using the Nearest - // Rank Method - // (https://en.wikipedia.org/wiki/Percentile#The_Nearest_Rank_method) - // (in scipy, same as percentile(...., interpolation='higher') - // - // for continuous distributions, interpolates data values between - // count-weighted bracketing means. - // - // this triggers cumulate() if cumn's are out of date. - // - var ps = Array.isArray(p_or_plist) ? p_or_plist : [p_or_plist]; - var qs = ps.map(this._percentile, this); - return Array.isArray(p_or_plist) ? qs : qs[0]; -}; - -TDigest.prototype._percentile = function (p) { - if (this.size() === 0) { - return undefined; - } - this._cumulate(true); // be sure cumns are exact - var h = this.n * p; - var bound = this.bound_mean_cumn(h); - var lower = bound[0], upper = bound[1]; - - if (upper === lower || lower === null || upper === null) { - return (lower || upper).mean; - } else if (!this.discrete) { - return lower.mean + (h - lower.mean_cumn) * (upper.mean - lower.mean) / (upper.mean_cumn - lower.mean_cumn); - } else if (h <= lower.cumn) { - return lower.mean; - } else { - return upper.mean; - } -}; - -function pop_random(choices) { - // remove and return an item randomly chosen from the array of choices - // (mutates choices) - // - var idx = Math.floor(Math.random() * choices.length); - return choices.splice(idx, 1)[0]; -} - -TDigest.prototype.compress = function () { - // TDigests experience worst case compression (none) when input - // increases monotonically. Improve on any bad luck by - // reconsuming digest centroids as if they were weighted points - // while shuffling their order (and hope for the best). - // - if (this.compressing) { - return; - } - var points = this.toArray(); - this.reset(); - this.compressing = true; - while (points.length > 0) { - this.push_centroid(pop_random(points)); - } - this._cumulate(true); - this.compressing = false; -}; - -function Digest(config) { - // allocate a distribution digest structure. This is an extension - // of a TDigest structure that starts in exact histogram (discrete) - // mode, and automatically switches to TDigest mode for large - // samples that appear to be from a continuous distribution. - // - this.config = config || {}; - this.mode = this.config.mode || 'auto'; // disc, cont, auto - TDigest.call(this, this.mode === 'cont' ? config.delta : false); - this.digest_ratio = this.config.ratio || 0.9; - this.digest_thresh = this.config.thresh || 1000; - this.n_unique = 0; -} -Digest.prototype = Object.create(TDigest.prototype); -Digest.prototype.constructor = Digest; - -Digest.prototype.push = function (x_or_xlist) { - TDigest.prototype.push.call(this, x_or_xlist); - this.check_continuous(); -}; - -Digest.prototype._new_centroid = function (x, n, cumn) { - this.n_unique += 1; - TDigest.prototype._new_centroid.call(this, x, n, cumn); -}; - -Digest.prototype._addweight = function (nearest, x, n) { - if (nearest.n === 1) { - this.n_unique -= 1; - } - TDigest.prototype._addweight.call(this, nearest, x, n); -}; - -Digest.prototype.check_continuous = function () { - // while in 'auto' mode, if there are many unique elements, assume - // they are from a continuous distribution and switch to 'cont' - // mode (tdigest behavior). Return true on transition from - // disctete to continuous. - if (this.mode !== 'auto' || this.size() < this.digest_thresh) { - return false; - } - if (this.n_unique / this.size() > this.digest_ratio) { - this.mode = 'cont'; - this.discrete = false; - this.delta = this.config.delta || 0.01; - this.compress(); - return true; - } - return false; -}; - -window.gmodCRAM=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=112)}([function(t,e){var r=t.exports={version:"2.5.7"};"number"==typeof __e&&(__e=r)},function(t,e,r){"use strict";e.__esModule=!0,e.default=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e,r){"use strict";var n=s(r(15)),i=s(r(1)),o=s(r(16)),a=s(r(17));function s(t){return t&&t.__esModule?t:{default:t}}var u=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(e.__proto__||(0,n.default)(e)).apply(this,arguments))}return(0,a.default)(e,t),e}(Error),f=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(e.__proto__||(0,n.default)(e)).apply(this,arguments))}return(0,a.default)(e,t),e}(Error),c=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(e.__proto__||(0,n.default)(e)).apply(this,arguments))}return(0,a.default)(e,t),e}(u),h=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(e.__proto__||(0,n.default)(e)).apply(this,arguments))}return(0,a.default)(e,t),e}(c),l=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(e.__proto__||(0,n.default)(e)).apply(this,arguments))}return(0,a.default)(e,t),e}(u),d=function(t){function e(){return(0,i.default)(this,e),(0,o.default)(this,(e.__proto__||(0,n.default)(e)).apply(this,arguments))}return(0,a.default)(e,t),e}(u);t.exports={CramBufferOverrunError:h,CramMalformedError:c,CramUnimplementedError:f,CramSizeLimitError:l,CramArgumentError:d}},function(t,e,r){"use strict";e.__esModule=!0;var n,i=r(137),o=(n=i)&&n.__esModule?n:{default:n};e.default=function(){function t(t,e){for(var r=0;r - * @license MIT - */ -var n=r(114),i=r(115),o=r(72);function a(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function s(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function p(t,e){if(u.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return j(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return D(t).length;default:if(n)return j(t).length;e=(""+e).toLowerCase(),n=!0}}function g(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function v(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=u.from(e,n)),u.isBuffer(e))return 0===e.length?-1:m(t,e,r,n,i);if("number"==typeof e)return e&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):m(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,r,n,i){var o,a=1,s=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,s/=2,u/=2,r/=2}function f(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(i){var c=-1;for(o=r;os&&(r=s-u),o=r;o>=0;o--){for(var h=!0,l=0;li&&(n=i):n=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var a=0;a>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function S(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function k(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i239?4:f>223?3:f>191?2:1;if(i+h<=r)switch(h){case 1:f<128&&(c=f);break;case 2:128==(192&(o=t[i+1]))&&(u=(31&f)<<6|63&o)>127&&(c=u);break;case 3:o=t[i+1],a=t[i+2],128==(192&o)&&128==(192&a)&&(u=(15&f)<<12|(63&o)<<6|63&a)>2047&&(u<55296||u>57343)&&(c=u);break;case 4:o=t[i+1],a=t[i+2],s=t[i+3],128==(192&o)&&128==(192&a)&&128==(192&s)&&(u=(15&f)<<18|(63&o)<<12|(63&a)<<6|63&s)>65535&&u<1114112&&(c=u)}null===c?(c=65533,h=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),i+=h}return function(t){var e=t.length;if(e<=A)return String.fromCharCode.apply(String,t);var r="",n=0;for(;nthis.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return R(this,e,r);case"utf8":case"utf-8":return k(this,e,r);case"ascii":return C(this,e,r);case"latin1":case"binary":return T(this,e,r);case"base64":return S(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},u.prototype.equals=function(t){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===u.compare(this,t)},u.prototype.inspect=function(){var t="",r=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),""},u.prototype.compare=function(t,e,r,n,i){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(e>>>=0),s=Math.min(o,a),f=this.slice(n,i),c=t.slice(e,r),h=0;hi)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return y(this,t,e,r);case"utf8":case"utf-8":return _(this,t,e,r);case"ascii":return b(this,t,e,r);case"latin1":case"binary":return w(this,t,e,r);case"base64":return x(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return E(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var A=4096;function C(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;in)&&(r=n);for(var i="",o=e;or)throw new RangeError("Trying to access beyond buffer length")}function L(t,e,r,n,i,o){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||et.length)throw new RangeError("Index out of range")}function M(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i>>8*(n?i:1-i)}function O(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i>>8*(n?i:3-i)&255}function F(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function N(t,e,r,n,o){return o||F(t,0,r,4),i.write(t,e,r,n,23,4),r+4}function P(t,e,r,n,o){return o||F(t,0,r,8),i.write(t,e,r,n,52,8),r+8}u.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(i*=256);)n+=this[t+--e]*i;return n},u.prototype.readUInt8=function(t,e){return e||B(t,1,this.length),this[t]},u.prototype.readUInt16LE=function(t,e){return e||B(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUInt16BE=function(t,e){return e||B(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUInt32LE=function(t,e){return e||B(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u.prototype.readUInt32BE=function(t,e){return e||B(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||B(t,e,this.length);for(var n=this[t],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*e)),n},u.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||B(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*e)),o},u.prototype.readInt8=function(t,e){return e||B(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,e){e||B(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt16BE=function(t,e){e||B(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt32LE=function(t,e){return e||B(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u.prototype.readInt32BE=function(t,e){return e||B(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u.prototype.readFloatLE=function(t,e){return e||B(t,4,this.length),i.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return e||B(t,4,this.length),i.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return e||B(t,8,this.length),i.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return e||B(t,8,this.length),i.read(this,t,!1,52,8)},u.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||L(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[e]=255&t;++o=0&&(o*=256);)this[e+i]=t/o&255;return e+r},u.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,1,255,0),u.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},u.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):M(this,t,e,!0),e+2},u.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):M(this,t,e,!1),e+2},u.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},u.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},u.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);L(this,t,e,r,i-1,-i)}var o=0,a=1,s=0;for(this[e]=255&t;++o>0)-s&255;return e+r},u.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);L(this,t,e,r,i-1,-i)}var o=r-1,a=1,s=0;for(this[e+o]=255&t;--o>=0&&(a*=256);)t<0&&0===s&&0!==this[e+o+1]&&(s=1),this[e+o]=(t/a>>0)-s&255;return e+r},u.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,1,127,-128),u.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},u.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):M(this,t,e,!0),e+2},u.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):M(this,t,e,!1),e+2},u.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,2147483647,-2147483648),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},u.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},u.prototype.writeFloatLE=function(t,e,r){return N(this,t,e,!0,r)},u.prototype.writeFloatBE=function(t,e,r){return N(this,t,e,!1,r)},u.prototype.writeDoubleLE=function(t,e,r){return P(this,t,e,!0,r)},u.prototype.writeDoubleBE=function(t,e,r){return P(this,t,e,!1,r)},u.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--i)t[i+e]=this[i+r];else if(o<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function D(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(U,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function q(t,e,r,n){for(var i=0;i=e.length||i>=t.length);++i)e[i+r]=t[i];return i}}).call(this,r(9))},function(t,e,r){var n=r(13);t.exports=function(t){if(!n(t))throw TypeError(t+" is not an object!");return t}},function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){var n=r(8),i=r(75),o=r(53),a=Object.defineProperty;e.f=r(14)?Object.defineProperty:function(t,e,r){if(n(t),e=o(e,!0),n(r),i)try{return a(t,e,r)}catch(t){}if("get"in r||"set"in r)throw TypeError("Accessors not supported!");return"value"in r&&(t[e]=r.value),t}},function(t,e,r){t.exports=r(116)},function(t,e,r){"use strict";e.__esModule=!0;var n,i=r(38),o=(n=i)&&n.__esModule?n:{default:n};e.default=function(t){return function(){var e=t.apply(this,arguments);return new o.default(function(t,r){return function n(i,a){try{var s=e[i](a),u=s.value}catch(t){return void r(t)}if(!s.done)return o.default.resolve(u).then(function(t){n("next",t)},function(t){n("throw",t)});t(u)}("next")})}}},function(t,e){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,e,r){t.exports=!r(19)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,e,r){t.exports={default:r(163),__esModule:!0}},function(t,e,r){"use strict";e.__esModule=!0;var n,i=r(100),o=(n=i)&&n.__esModule?n:{default:n};e.default=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!==(void 0===e?"undefined":(0,o.default)(e))&&"function"!=typeof e?t:e}},function(t,e,r){"use strict";e.__esModule=!0;var n=a(r(176)),i=a(r(180)),o=a(r(100));function a(t){return t&&t.__esModule?t:{default:t}}e.default=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+(void 0===e?"undefined":(0,o.default)(e)));t.prototype=(0,i.default)(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(n.default?(0,n.default)(t,e):t.__proto__=e)}},function(t,e,r){var n=r(10),i=r(32);t.exports=r(14)?function(t,e,r){return n.f(t,e,i(1,r))}:function(t,e,r){return t[e]=r,t}},function(t,e){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,e){var r={}.hasOwnProperty;t.exports=function(t,e){return r.call(t,e)}},function(t,e,r){var n=r(78),i=r(39);t.exports=function(t){return n(i(t))}},function(t,e){var r,n,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function s(t){if(r===setTimeout)return setTimeout(t,0);if((r===o||!r)&&setTimeout)return r=setTimeout,setTimeout(t,0);try{return r(t,0)}catch(e){try{return r.call(null,t,0)}catch(e){return r.call(this,t,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:o}catch(t){r=o}try{n="function"==typeof clearTimeout?clearTimeout:a}catch(t){n=a}}();var u,f=[],c=!1,h=-1;function l(){c&&u&&(c=!1,u.length?f=u.concat(f):h=-1,f.length&&d())}function d(){if(!c){var t=s(l);c=!0;for(var e=f.length;e;){for(u=f,f=[];++h1)for(var r=1;r0&&void 0!==arguments[0]?arguments[0]:{},r=arguments[1];if((0,n.default)(this,t),this.parameters=e,this.dataType=r,!r)throw new TypeError("must provide a data type to codec constructor");if(!s[r])throw new TypeError("invalid data type "+r)}return(0,i.default)(t,[{key:"_getBits",value:function(t,e,r){var n=0;if(e.bytePosition+(7-e.bitPosition+r)/8>t.length)throw new a("read error during decoding. the file seems to be truncated.");for(var i=r;i;i-=1)n<<=1,n|=t[e.bytePosition]>>e.bitPosition&1,e.bitPosition-=1,e.bitPosition<0&&(e.bytePosition+=1),e.bitPosition&=7;return n}}]),t}();t.exports=u},function(t,e,r){var n=r(40);t.exports=function(t,e,r){if(n(t),void 0===e)return t;switch(r){case 1:return function(r){return t.call(e,r)};case 2:return function(r,n){return t.call(e,r,n)};case 3:return function(r,n,i){return t.call(e,r,n,i)}}return function(){return t.apply(e,arguments)}}},function(t,e){t.exports={}},function(t,e,r){var n=r(77),i=r(58);t.exports=Object.keys||function(t){return n(t,i)}},function(t,e,r){"use strict";e.__esModule=!0;var n=o(r(221)),i=o(r(224));function o(t){return t&&t.__esModule?t:{default:t}}e.default=function(){return function(t,e){if(Array.isArray(t))return t;if((0,n.default)(Object(t)))return function(t,e){var r=[],n=!0,o=!1,a=void 0;try{for(var s,u=(0,i.default)(t);!(n=(s=u.next()).done)&&(r.push(s.value),!e||r.length!==e);n=!0);}catch(t){o=!0,a=t}finally{try{!n&&u.return&&u.return()}finally{if(o)throw a}}return r}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}()},function(t,e,r){"use strict";var n=r(119)(!0);r(74)(String,"String",function(t){this._t=String(t),this._i=0},function(){var t,e=this._t,r=this._i;return r>=e.length?{value:void 0,done:!0}:(t=n(e,r),this._i+=t.length,{value:t,done:!1})})},function(t,e){t.exports=!0},function(t,e){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},function(t,e){var r={}.toString;t.exports=function(t){return r.call(t).slice(8,-1)}},function(t,e,r){var n=r(39);t.exports=function(t){return Object(n(t))}},function(t,e,r){(function(t){function r(t){return Object.prototype.toString.call(t)}e.isArray=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===r(t)},e.isBoolean=function(t){return"boolean"==typeof t},e.isNull=function(t){return null===t},e.isNullOrUndefined=function(t){return null==t},e.isNumber=function(t){return"number"==typeof t},e.isString=function(t){return"string"==typeof t},e.isSymbol=function(t){return"symbol"==typeof t},e.isUndefined=function(t){return void 0===t},e.isRegExp=function(t){return"[object RegExp]"===r(t)},e.isObject=function(t){return"object"==typeof t&&null!==t},e.isDate=function(t){return"[object Date]"===r(t)},e.isError=function(t){return"[object Error]"===r(t)||t instanceof Error},e.isFunction=function(t){return"function"==typeof t},e.isPrimitive=function(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t},e.isBuffer=t.isBuffer}).call(this,r(7).Buffer)},function(t,e){e.f={}.propertyIsEnumerable},function(t,e,r){"use strict";var n=r(198),i=r(2).CramBufferOverrunError;t.exports={itf8Size:function(t){return-128&t?-16384&t?-2097152&t?-268435456&t?5:4:3:2:1},parseItf8:function(t,e){var r=e,n=t[r],o=void 0;if(n<128?(o=n,r+=1):n<192?(o=16383&(n<<8|t[r+1]),r+=2):n<224?(o=2097151&(n<<16|t[r+1]<<8|t[r+2]),r+=3):n<240?(o=268435455&(n<<24|t[r+1]<<16|t[r+2]<<8|t[r+3]),r+=4):(o=(15&n)<<28|t[r+1]<<20|t[r+2]<<12|t[r+3]<<4|15&t[r+4],r+=5),r>t.length)throw new i("Attempted to read beyond end of buffer; this file seems truncated.");return[o,r-e]},parseItem:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,i=e.parse(t),o=i.offset,a=i.result;return a._endPosition=o+n,a._size=o-r,a},tinyMemoize:function(t,e){var r=t.prototype[e],n="_memo_"+e;t.prototype[e]=function(){return n in this||(this[n]=r.call(this)),this[n]}},sequenceMD5:function(t){return n(t.toUpperCase().replace(/[^\x21-\x7e]/g,""))}}},function(t,e,r){t.exports={default:r(118),__esModule:!0}},function(t,e){t.exports=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t}},function(t,e){t.exports=function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!");return t}},function(t,e){var r=0,n=Math.random();t.exports=function(t){return"Symbol(".concat(void 0===t?"":t,")_",(++r+n).toString(36))}},function(t,e,r){var n=r(10).f,i=r(20),o=r(6)("toStringTag");t.exports=function(t,e,r){t&&!i(t=r?t:t.prototype,o)&&n(t,o,{configurable:!0,value:e})}},function(t,e,r){r(124);for(var n=r(5),i=r(18),o=r(27),a=r(6)("toStringTag"),s="CSSRuleList,CSSStyleDeclaration,CSSValueList,ClientRectList,DOMRectList,DOMStringList,DOMTokenList,DataTransferItemList,FileList,HTMLAllCollection,HTMLCollection,HTMLFormElement,HTMLSelectElement,MediaList,MimeTypeArray,NamedNodeMap,NodeList,PaintRequestList,Plugin,PluginArray,SVGLengthList,SVGNumberList,SVGPathSegList,SVGPointList,SVGStringList,SVGTransformList,SourceBufferList,StyleSheetList,TextTrackCueList,TextTrackList,TouchList".split(","),u=0;u>n)+(t&(1<>i)+(t&(1<0?n:r)(t)}},function(t,e,r){var n=r(13),i=r(5).document,o=n(i)&&n(i.createElement);t.exports=function(t){return o?i.createElement(t):{}}},function(t,e,r){var n=r(13);t.exports=function(t,e){if(!n(t))return t;var r,i;if(e&&"function"==typeof(r=t.toString)&&!n(i=r.call(t)))return i;if("function"==typeof(r=t.valueOf)&&!n(i=r.call(t)))return i;if(!e&&"function"==typeof(r=t.toString)&&!n(i=r.call(t)))return i;throw TypeError("Can't convert object to primitive value")}},function(t,e,r){var n=r(8),i=r(121),o=r(58),a=r(56)("IE_PROTO"),s=function(){},u=function(){var t,e=r(52)("iframe"),n=o.length;for(e.style.display="none",r(79).appendChild(e),e.src="javascript:",(t=e.contentWindow.document).open(),t.write("