@visactor/vutils 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/angle.d.ts +12 -0
- package/cjs/angle.js +40 -0
- package/cjs/angle.js.map +1 -0
- package/cjs/color/Color.d.ts +181 -0
- package/cjs/color/Color.js +298 -0
- package/cjs/color/Color.js.map +1 -0
- package/cjs/color/hexToRgb.d.ts +1 -0
- package/cjs/color/hexToRgb.js +13 -0
- package/cjs/color/hexToRgb.js.map +1 -0
- package/cjs/color/hslToRgb.d.ts +5 -0
- package/cjs/color/hslToRgb.js +21 -0
- package/cjs/color/hslToRgb.js.map +1 -0
- package/cjs/color/index.d.ts +6 -0
- package/cjs/color/index.js +80 -0
- package/cjs/color/index.js.map +1 -0
- package/cjs/color/interpolate.d.ts +2 -0
- package/cjs/color/interpolate.js +18 -0
- package/cjs/color/interpolate.js.map +1 -0
- package/cjs/color/rgbToHex.d.ts +1 -0
- package/cjs/color/rgbToHex.js +10 -0
- package/cjs/color/rgbToHex.js.map +1 -0
- package/cjs/color/rgbToHsl.d.ts +5 -0
- package/cjs/color/rgbToHsl.js +19 -0
- package/cjs/color/rgbToHsl.js.map +1 -0
- package/cjs/common/array.d.ts +9 -0
- package/cjs/common/array.js +64 -0
- package/cjs/common/array.js.map +1 -0
- package/cjs/common/ascending.d.ts +1 -0
- package/cjs/common/ascending.js +9 -0
- package/cjs/common/ascending.js.map +1 -0
- package/cjs/common/bisect.d.ts +1 -0
- package/cjs/common/bisect.js +24 -0
- package/cjs/common/bisect.js.map +1 -0
- package/cjs/common/clamp.d.ts +2 -0
- package/cjs/common/clamp.js +12 -0
- package/cjs/common/clamp.js.map +1 -0
- package/cjs/common/clampRange.d.ts +2 -0
- package/cjs/common/clampRange.js +16 -0
- package/cjs/common/clampRange.js.map +1 -0
- package/cjs/common/clamper.d.ts +1 -0
- package/cjs/common/clamper.js +11 -0
- package/cjs/common/clamper.js.map +1 -0
- package/cjs/common/clone.d.ts +1 -0
- package/cjs/common/clone.js +42 -0
- package/cjs/common/clone.js.map +1 -0
- package/cjs/common/cloneDeep.d.ts +1 -0
- package/cjs/common/cloneDeep.js +31 -0
- package/cjs/common/cloneDeep.js.map +1 -0
- package/cjs/common/constant.d.ts +2 -0
- package/cjs/common/constant.js +17 -0
- package/cjs/common/constant.js.map +1 -0
- package/cjs/common/debounce.d.ts +7 -0
- package/cjs/common/debounce.js +76 -0
- package/cjs/common/debounce.js.map +1 -0
- package/cjs/common/deviation.d.ts +1 -0
- package/cjs/common/deviation.js +15 -0
- package/cjs/common/deviation.js.map +1 -0
- package/cjs/common/get.d.ts +3 -0
- package/cjs/common/get.js +20 -0
- package/cjs/common/get.js.map +1 -0
- package/cjs/common/getType.d.ts +2 -0
- package/cjs/common/getType.js +10 -0
- package/cjs/common/getType.js.map +1 -0
- package/cjs/common/has.d.ts +3 -0
- package/cjs/common/has.js +10 -0
- package/cjs/common/has.js.map +1 -0
- package/cjs/common/index.d.ts +56 -0
- package/cjs/common/index.js +485 -0
- package/cjs/common/index.js.map +1 -0
- package/cjs/common/interpolate.d.ts +4 -0
- package/cjs/common/interpolate.js +55 -0
- package/cjs/common/interpolate.js.map +1 -0
- package/cjs/common/isArray.d.ts +2 -0
- package/cjs/common/isArray.js +17 -0
- package/cjs/common/isArray.js.map +1 -0
- package/cjs/common/isArrayLike.d.ts +2 -0
- package/cjs/common/isArrayLike.js +11 -0
- package/cjs/common/isArrayLike.js.map +1 -0
- package/cjs/common/isBase64.d.ts +2 -0
- package/cjs/common/isBase64.js +10 -0
- package/cjs/common/isBase64.js.map +1 -0
- package/cjs/common/isBoolean.d.ts +2 -0
- package/cjs/common/isBoolean.js +17 -0
- package/cjs/common/isBoolean.js.map +1 -0
- package/cjs/common/isDate.d.ts +2 -0
- package/cjs/common/isDate.js +16 -0
- package/cjs/common/isDate.js.map +1 -0
- package/cjs/common/isEmpty.d.ts +2 -0
- package/cjs/common/isEmpty.js +26 -0
- package/cjs/common/isEmpty.js.map +1 -0
- package/cjs/common/isEqual.d.ts +1 -0
- package/cjs/common/isEqual.js +49 -0
- package/cjs/common/isEqual.js.map +1 -0
- package/cjs/common/isFunction.d.ts +2 -0
- package/cjs/common/isFunction.js +10 -0
- package/cjs/common/isFunction.js.map +1 -0
- package/cjs/common/isNil.d.ts +2 -0
- package/cjs/common/isNil.js +10 -0
- package/cjs/common/isNil.js.map +1 -0
- package/cjs/common/isNull.d.ts +2 -0
- package/cjs/common/isNull.js +10 -0
- package/cjs/common/isNull.js.map +1 -0
- package/cjs/common/isNumber.d.ts +2 -0
- package/cjs/common/isNumber.js +19 -0
- package/cjs/common/isNumber.js.map +1 -0
- package/cjs/common/isNumeric.d.ts +2 -0
- package/cjs/common/isNumeric.js +10 -0
- package/cjs/common/isNumeric.js.map +1 -0
- package/cjs/common/isObject.d.ts +2 -0
- package/cjs/common/isObject.js +13 -0
- package/cjs/common/isObject.js.map +1 -0
- package/cjs/common/isObjectLike.d.ts +2 -0
- package/cjs/common/isObjectLike.js +10 -0
- package/cjs/common/isObjectLike.js.map +1 -0
- package/cjs/common/isPlainObject.d.ts +2 -0
- package/cjs/common/isPlainObject.js +22 -0
- package/cjs/common/isPlainObject.js.map +1 -0
- package/cjs/common/isPrototype.d.ts +2 -0
- package/cjs/common/isPrototype.js +13 -0
- package/cjs/common/isPrototype.js.map +1 -0
- package/cjs/common/isRegExp.d.ts +2 -0
- package/cjs/common/isRegExp.js +16 -0
- package/cjs/common/isRegExp.js.map +1 -0
- package/cjs/common/isShallowEqual.d.ts +1 -0
- package/cjs/common/isShallowEqual.js +33 -0
- package/cjs/common/isShallowEqual.js.map +1 -0
- package/cjs/common/isString.d.ts +2 -0
- package/cjs/common/isString.js +19 -0
- package/cjs/common/isString.js.map +1 -0
- package/cjs/common/isType.d.ts +2 -0
- package/cjs/common/isType.js +10 -0
- package/cjs/common/isType.js.map +1 -0
- package/cjs/common/isUndefined.d.ts +2 -0
- package/cjs/common/isUndefined.js +10 -0
- package/cjs/common/isUndefined.js.map +1 -0
- package/cjs/common/isValid.d.ts +2 -0
- package/cjs/common/isValid.js +10 -0
- package/cjs/common/isValid.js.map +1 -0
- package/cjs/common/isValidNumber.d.ts +2 -0
- package/cjs/common/isValidNumber.js +17 -0
- package/cjs/common/isValidNumber.js.map +1 -0
- package/cjs/common/isValidUrl.d.ts +2 -0
- package/cjs/common/isValidUrl.js +10 -0
- package/cjs/common/isValidUrl.js.map +1 -0
- package/cjs/common/lowerFirst.d.ts +2 -0
- package/cjs/common/lowerFirst.js +12 -0
- package/cjs/common/lowerFirst.js.map +1 -0
- package/cjs/common/median.d.ts +1 -0
- package/cjs/common/median.js +13 -0
- package/cjs/common/median.js.map +1 -0
- package/cjs/common/merge.d.ts +1 -0
- package/cjs/common/merge.js +63 -0
- package/cjs/common/merge.js.map +1 -0
- package/cjs/common/mixin.d.ts +5 -0
- package/cjs/common/mixin.js +35 -0
- package/cjs/common/mixin.js.map +1 -0
- package/cjs/common/number.d.ts +3 -0
- package/cjs/common/number.js +23 -0
- package/cjs/common/number.js.map +1 -0
- package/cjs/common/pad.d.ts +2 -0
- package/cjs/common/pad.js +17 -0
- package/cjs/common/pad.js.map +1 -0
- package/cjs/common/pick.d.ts +1 -0
- package/cjs/common/pick.js +24 -0
- package/cjs/common/pick.js.map +1 -0
- package/cjs/common/pickWithout.d.ts +1 -0
- package/cjs/common/pickWithout.js +28 -0
- package/cjs/common/pickWithout.js.map +1 -0
- package/cjs/common/quantileSorted.d.ts +1 -0
- package/cjs/common/quantileSorted.js +19 -0
- package/cjs/common/quantileSorted.js.map +1 -0
- package/cjs/common/range.d.ts +1 -0
- package/cjs/common/range.js +24 -0
- package/cjs/common/range.js.map +1 -0
- package/cjs/common/throttle.d.ts +5 -0
- package/cjs/common/throttle.js +27 -0
- package/cjs/common/throttle.js.map +1 -0
- package/cjs/common/tickStep.d.ts +1 -0
- package/cjs/common/tickStep.js +18 -0
- package/cjs/common/tickStep.js.map +1 -0
- package/cjs/common/toDate.d.ts +2 -0
- package/cjs/common/toDate.js +28 -0
- package/cjs/common/toDate.js.map +1 -0
- package/cjs/common/toNumber.d.ts +1 -0
- package/cjs/common/toNumber.js +10 -0
- package/cjs/common/toNumber.js.map +1 -0
- package/cjs/common/toValidNumber.d.ts +1 -0
- package/cjs/common/toValidNumber.js +22 -0
- package/cjs/common/toValidNumber.js.map +1 -0
- package/cjs/common/truncate.d.ts +2 -0
- package/cjs/common/truncate.js +19 -0
- package/cjs/common/truncate.js.map +1 -0
- package/cjs/common/upperFirst.d.ts +2 -0
- package/cjs/common/upperFirst.js +12 -0
- package/cjs/common/upperFirst.js.map +1 -0
- package/cjs/common/uuid.d.ts +2 -0
- package/cjs/common/uuid.js +19 -0
- package/cjs/common/uuid.js.map +1 -0
- package/cjs/common/variance.d.ts +1 -0
- package/cjs/common/variance.js +17 -0
- package/cjs/common/variance.js.map +1 -0
- package/cjs/data-structure/bounds.d.ts +81 -0
- package/cjs/data-structure/bounds.js +139 -0
- package/cjs/data-structure/bounds.js.map +1 -0
- package/cjs/data-structure/hashTable.d.ts +35 -0
- package/cjs/data-structure/hashTable.js +115 -0
- package/cjs/data-structure/hashTable.js.map +1 -0
- package/cjs/data-structure/index.d.ts +4 -0
- package/cjs/data-structure/index.js +22 -0
- package/cjs/data-structure/index.js.map +1 -0
- package/cjs/data-structure/matrix.d.ts +80 -0
- package/cjs/data-structure/matrix.js +113 -0
- package/cjs/data-structure/matrix.js.map +1 -0
- package/cjs/data-structure/point.d.ts +62 -0
- package/cjs/data-structure/point.js +81 -0
- package/cjs/data-structure/point.js.map +1 -0
- package/cjs/dom.d.ts +13 -0
- package/cjs/dom.js +78 -0
- package/cjs/dom.js.map +1 -0
- package/cjs/geo/index.d.ts +2 -0
- package/cjs/geo/index.js +21 -0
- package/cjs/geo/index.js.map +1 -0
- package/cjs/geo/interface.d.ts +1 -0
- package/cjs/geo/interface.js +6 -0
- package/cjs/geo/interface.js.map +1 -0
- package/cjs/geo/invariant.d.ts +9 -0
- package/cjs/geo/invariant.js +45 -0
- package/cjs/geo/invariant.js.map +1 -0
- package/cjs/graphics/algorithm/aabb.d.ts +6 -0
- package/cjs/graphics/algorithm/aabb.js +58 -0
- package/cjs/graphics/algorithm/aabb.js.map +1 -0
- package/cjs/graphics/algorithm/index.d.ts +3 -0
- package/cjs/graphics/algorithm/index.js +22 -0
- package/cjs/graphics/algorithm/index.js.map +1 -0
- package/cjs/graphics/algorithm/interface.d.ts +20 -0
- package/cjs/graphics/algorithm/interface.js +6 -0
- package/cjs/graphics/algorithm/interface.js.map +1 -0
- package/cjs/graphics/algorithm/intersect.d.ts +25 -0
- package/cjs/graphics/algorithm/intersect.js +143 -0
- package/cjs/graphics/algorithm/intersect.js.map +1 -0
- package/cjs/graphics/algorithm/obb.d.ts +5 -0
- package/cjs/graphics/algorithm/obb.js +80 -0
- package/cjs/graphics/algorithm/obb.js.map +1 -0
- package/cjs/graphics/graph-util.d.ts +23 -0
- package/cjs/graphics/graph-util.js +47 -0
- package/cjs/graphics/graph-util.js.map +1 -0
- package/cjs/graphics/image.d.ts +2 -0
- package/cjs/graphics/image.js +18 -0
- package/cjs/graphics/image.js.map +1 -0
- package/cjs/graphics/index.d.ts +5 -0
- package/cjs/graphics/index.js +23 -0
- package/cjs/graphics/index.js.map +1 -0
- package/cjs/graphics/polygon.d.ts +5 -0
- package/cjs/graphics/polygon.js +54 -0
- package/cjs/graphics/polygon.js.map +1 -0
- package/cjs/graphics/text/index.d.ts +2 -0
- package/cjs/graphics/text/index.js +39 -0
- package/cjs/graphics/text/index.js.map +1 -0
- package/cjs/graphics/text/measure/index.d.ts +4 -0
- package/cjs/graphics/text/measure/index.js +22 -0
- package/cjs/graphics/text/measure/index.js.map +1 -0
- package/cjs/graphics/text/measure/interface.d.ts +31 -0
- package/cjs/graphics/text/measure/interface.js +6 -0
- package/cjs/graphics/text/measure/interface.js.map +1 -0
- package/cjs/graphics/text/measure/test.d.ts +14 -0
- package/cjs/graphics/text/measure/test.js +67 -0
- package/cjs/graphics/text/measure/test.js.map +1 -0
- package/cjs/graphics/text/measure/textMeasure.d.ts +38 -0
- package/cjs/graphics/text/measure/textMeasure.js +185 -0
- package/cjs/graphics/text/measure/textMeasure.js.map +1 -0
- package/cjs/graphics/text/measure/util.d.ts +2 -0
- package/cjs/graphics/text/measure/util.js +11 -0
- package/cjs/graphics/text/measure/util.js.map +1 -0
- package/cjs/graphics/text/stringWidth.d.ts +2 -0
- package/cjs/graphics/text/stringWidth.js +49 -0
- package/cjs/graphics/text/stringWidth.js.map +1 -0
- package/cjs/index.d.ts +15 -0
- package/cjs/index.js +47 -0
- package/cjs/index.js.map +1 -0
- package/cjs/logger.d.ts +12 -0
- package/cjs/logger.js +36 -0
- package/cjs/logger.js.map +1 -0
- package/cjs/lru.d.ts +25 -0
- package/cjs/lru.js +43 -0
- package/cjs/lru.js.map +1 -0
- package/cjs/math.d.ts +66 -0
- package/cjs/math.js +57 -0
- package/cjs/math.js.map +1 -0
- package/cjs/padding.d.ts +7 -0
- package/cjs/padding.js +41 -0
- package/cjs/padding.js.map +1 -0
- package/cjs/time/formatUtils.d.ts +17 -0
- package/cjs/time/formatUtils.js +95 -0
- package/cjs/time/formatUtils.js.map +1 -0
- package/cjs/time/index.d.ts +2 -0
- package/cjs/time/index.js +21 -0
- package/cjs/time/index.js.map +1 -0
- package/cjs/time/interval.d.ts +77 -0
- package/cjs/time/interval.js +324 -0
- package/cjs/time/interval.js.map +1 -0
- package/cjs/type.d.ts +5 -0
- package/cjs/type.js +6 -0
- package/cjs/type.js.map +1 -0
- package/dist/index.js +4903 -0
- package/dist/index.min.js +1 -0
- package/es/angle.d.ts +12 -0
- package/es/angle.js +31 -0
- package/es/angle.js.map +1 -0
- package/es/color/Color.d.ts +181 -0
- package/es/color/Color.js +283 -0
- package/es/color/Color.js.map +1 -0
- package/es/color/hexToRgb.d.ts +1 -0
- package/es/color/hexToRgb.js +7 -0
- package/es/color/hexToRgb.js.map +1 -0
- package/es/color/hslToRgb.d.ts +5 -0
- package/es/color/hslToRgb.js +15 -0
- package/es/color/hslToRgb.js.map +1 -0
- package/es/color/index.d.ts +6 -0
- package/es/color/index.js +12 -0
- package/es/color/index.js.map +1 -0
- package/es/color/interpolate.d.ts +2 -0
- package/es/color/interpolate.js +10 -0
- package/es/color/interpolate.js.map +1 -0
- package/es/color/rgbToHex.d.ts +1 -0
- package/es/color/rgbToHex.js +4 -0
- package/es/color/rgbToHex.js.map +1 -0
- package/es/color/rgbToHsl.d.ts +5 -0
- package/es/color/rgbToHsl.js +13 -0
- package/es/color/rgbToHsl.js.map +1 -0
- package/es/common/array.d.ts +9 -0
- package/es/common/array.js +50 -0
- package/es/common/array.js.map +1 -0
- package/es/common/ascending.d.ts +1 -0
- package/es/common/ascending.js +3 -0
- package/es/common/ascending.js.map +1 -0
- package/es/common/bisect.d.ts +1 -0
- package/es/common/bisect.js +12 -0
- package/es/common/bisect.js.map +1 -0
- package/es/common/clamp.d.ts +2 -0
- package/es/common/clamp.js +6 -0
- package/es/common/clamp.js.map +1 -0
- package/es/common/clampRange.d.ts +2 -0
- package/es/common/clampRange.js +10 -0
- package/es/common/clampRange.js.map +1 -0
- package/es/common/clamper.d.ts +1 -0
- package/es/common/clamper.js +5 -0
- package/es/common/clamper.js.map +1 -0
- package/es/common/clone.d.ts +1 -0
- package/es/common/clone.js +32 -0
- package/es/common/clone.js.map +1 -0
- package/es/common/cloneDeep.d.ts +1 -0
- package/es/common/cloneDeep.js +26 -0
- package/es/common/cloneDeep.js.map +1 -0
- package/es/common/constant.d.ts +2 -0
- package/es/common/constant.js +6 -0
- package/es/common/constant.js.map +1 -0
- package/es/common/debounce.d.ts +7 -0
- package/es/common/debounce.js +68 -0
- package/es/common/debounce.js.map +1 -0
- package/es/common/deviation.d.ts +1 -0
- package/es/common/deviation.js +7 -0
- package/es/common/deviation.js.map +1 -0
- package/es/common/get.d.ts +3 -0
- package/es/common/get.js +10 -0
- package/es/common/get.js.map +1 -0
- package/es/common/getType.d.ts +2 -0
- package/es/common/getType.js +4 -0
- package/es/common/getType.js.map +1 -0
- package/es/common/has.d.ts +3 -0
- package/es/common/has.js +4 -0
- package/es/common/has.js.map +1 -0
- package/es/common/index.d.ts +56 -0
- package/es/common/index.js +112 -0
- package/es/common/index.js.map +1 -0
- package/es/common/interpolate.d.ts +4 -0
- package/es/common/interpolate.js +45 -0
- package/es/common/interpolate.js.map +1 -0
- package/es/common/isArray.d.ts +2 -0
- package/es/common/isArray.js +6 -0
- package/es/common/isArray.js.map +1 -0
- package/es/common/isArrayLike.d.ts +2 -0
- package/es/common/isArrayLike.js +5 -0
- package/es/common/isArrayLike.js.map +1 -0
- package/es/common/isBase64.d.ts +2 -0
- package/es/common/isBase64.js +4 -0
- package/es/common/isBase64.js.map +1 -0
- package/es/common/isBoolean.d.ts +2 -0
- package/es/common/isBoolean.js +6 -0
- package/es/common/isBoolean.js.map +1 -0
- package/es/common/isDate.d.ts +2 -0
- package/es/common/isDate.js +6 -0
- package/es/common/isDate.js.map +1 -0
- package/es/common/isEmpty.d.ts +2 -0
- package/es/common/isEmpty.js +22 -0
- package/es/common/isEmpty.js.map +1 -0
- package/es/common/isEqual.d.ts +1 -0
- package/es/common/isEqual.js +39 -0
- package/es/common/isEqual.js.map +1 -0
- package/es/common/isFunction.d.ts +2 -0
- package/es/common/isFunction.js +4 -0
- package/es/common/isFunction.js.map +1 -0
- package/es/common/isNil.d.ts +2 -0
- package/es/common/isNil.js +4 -0
- package/es/common/isNil.js.map +1 -0
- package/es/common/isNull.d.ts +2 -0
- package/es/common/isNull.js +4 -0
- package/es/common/isNull.js.map +1 -0
- package/es/common/isNumber.d.ts +2 -0
- package/es/common/isNumber.js +9 -0
- package/es/common/isNumber.js.map +1 -0
- package/es/common/isNumeric.d.ts +2 -0
- package/es/common/isNumeric.js +4 -0
- package/es/common/isNumeric.js.map +1 -0
- package/es/common/isObject.d.ts +2 -0
- package/es/common/isObject.js +7 -0
- package/es/common/isObject.js.map +1 -0
- package/es/common/isObjectLike.d.ts +2 -0
- package/es/common/isObjectLike.js +4 -0
- package/es/common/isObjectLike.js.map +1 -0
- package/es/common/isPlainObject.d.ts +2 -0
- package/es/common/isPlainObject.js +14 -0
- package/es/common/isPlainObject.js.map +1 -0
- package/es/common/isPrototype.d.ts +2 -0
- package/es/common/isPrototype.js +7 -0
- package/es/common/isPrototype.js.map +1 -0
- package/es/common/isRegExp.d.ts +2 -0
- package/es/common/isRegExp.js +6 -0
- package/es/common/isRegExp.js.map +1 -0
- package/es/common/isShallowEqual.d.ts +1 -0
- package/es/common/isShallowEqual.js +21 -0
- package/es/common/isShallowEqual.js.map +1 -0
- package/es/common/isString.d.ts +2 -0
- package/es/common/isString.js +9 -0
- package/es/common/isString.js.map +1 -0
- package/es/common/isType.d.ts +2 -0
- package/es/common/isType.js +4 -0
- package/es/common/isType.js.map +1 -0
- package/es/common/isUndefined.d.ts +2 -0
- package/es/common/isUndefined.js +4 -0
- package/es/common/isUndefined.js.map +1 -0
- package/es/common/isValid.d.ts +2 -0
- package/es/common/isValid.js +4 -0
- package/es/common/isValid.js.map +1 -0
- package/es/common/isValidNumber.d.ts +2 -0
- package/es/common/isValidNumber.js +6 -0
- package/es/common/isValidNumber.js.map +1 -0
- package/es/common/isValidUrl.d.ts +2 -0
- package/es/common/isValidUrl.js +4 -0
- package/es/common/isValidUrl.js.map +1 -0
- package/es/common/lowerFirst.d.ts +2 -0
- package/es/common/lowerFirst.js +6 -0
- package/es/common/lowerFirst.js.map +1 -0
- package/es/common/median.d.ts +1 -0
- package/es/common/median.js +9 -0
- package/es/common/median.js.map +1 -0
- package/es/common/merge.d.ts +1 -0
- package/es/common/merge.js +54 -0
- package/es/common/merge.js.map +1 -0
- package/es/common/mixin.d.ts +5 -0
- package/es/common/mixin.js +28 -0
- package/es/common/mixin.js.map +1 -0
- package/es/common/number.d.ts +3 -0
- package/es/common/number.js +15 -0
- package/es/common/number.js.map +1 -0
- package/es/common/pad.d.ts +2 -0
- package/es/common/pad.js +11 -0
- package/es/common/pad.js.map +1 -0
- package/es/common/pick.d.ts +1 -0
- package/es/common/pick.js +12 -0
- package/es/common/pick.js.map +1 -0
- package/es/common/pickWithout.d.ts +1 -0
- package/es/common/pickWithout.js +16 -0
- package/es/common/pickWithout.js.map +1 -0
- package/es/common/quantileSorted.d.ts +1 -0
- package/es/common/quantileSorted.js +11 -0
- package/es/common/quantileSorted.js.map +1 -0
- package/es/common/range.d.ts +1 -0
- package/es/common/range.js +10 -0
- package/es/common/range.js.map +1 -0
- package/es/common/throttle.d.ts +5 -0
- package/es/common/throttle.js +17 -0
- package/es/common/throttle.js.map +1 -0
- package/es/common/tickStep.d.ts +1 -0
- package/es/common/tickStep.js +10 -0
- package/es/common/tickStep.js.map +1 -0
- package/es/common/toDate.d.ts +2 -0
- package/es/common/toDate.js +18 -0
- package/es/common/toDate.js.map +1 -0
- package/es/common/toNumber.d.ts +1 -0
- package/es/common/toNumber.js +4 -0
- package/es/common/toNumber.js.map +1 -0
- package/es/common/toValidNumber.d.ts +1 -0
- package/es/common/toValidNumber.js +8 -0
- package/es/common/toValidNumber.js.map +1 -0
- package/es/common/truncate.d.ts +2 -0
- package/es/common/truncate.js +9 -0
- package/es/common/truncate.js.map +1 -0
- package/es/common/upperFirst.d.ts +2 -0
- package/es/common/upperFirst.js +6 -0
- package/es/common/upperFirst.js.map +1 -0
- package/es/common/uuid.d.ts +2 -0
- package/es/common/uuid.js +13 -0
- package/es/common/uuid.js.map +1 -0
- package/es/common/variance.d.ts +1 -0
- package/es/common/variance.js +11 -0
- package/es/common/variance.js.map +1 -0
- package/es/data-structure/bounds.d.ts +81 -0
- package/es/data-structure/bounds.js +127 -0
- package/es/data-structure/bounds.js.map +1 -0
- package/es/data-structure/hashTable.d.ts +35 -0
- package/es/data-structure/hashTable.js +105 -0
- package/es/data-structure/hashTable.js.map +1 -0
- package/es/data-structure/index.d.ts +4 -0
- package/es/data-structure/index.js +8 -0
- package/es/data-structure/index.js.map +1 -0
- package/es/data-structure/matrix.d.ts +80 -0
- package/es/data-structure/matrix.js +106 -0
- package/es/data-structure/matrix.js.map +1 -0
- package/es/data-structure/point.d.ts +62 -0
- package/es/data-structure/point.js +65 -0
- package/es/data-structure/point.js.map +1 -0
- package/es/dom.d.ts +13 -0
- package/es/dom.js +59 -0
- package/es/dom.js.map +1 -0
- package/es/geo/index.d.ts +2 -0
- package/es/geo/index.js +4 -0
- package/es/geo/index.js.map +1 -0
- package/es/geo/interface.d.ts +1 -0
- package/es/geo/interface.js +2 -0
- package/es/geo/interface.js.map +1 -0
- package/es/geo/invariant.d.ts +9 -0
- package/es/geo/invariant.js +40 -0
- package/es/geo/invariant.js.map +1 -0
- package/es/graphics/algorithm/aabb.d.ts +6 -0
- package/es/graphics/algorithm/aabb.js +49 -0
- package/es/graphics/algorithm/aabb.js.map +1 -0
- package/es/graphics/algorithm/index.d.ts +3 -0
- package/es/graphics/algorithm/index.js +6 -0
- package/es/graphics/algorithm/index.js.map +1 -0
- package/es/graphics/algorithm/interface.d.ts +20 -0
- package/es/graphics/algorithm/interface.js +2 -0
- package/es/graphics/algorithm/interface.js.map +1 -0
- package/es/graphics/algorithm/intersect.d.ts +25 -0
- package/es/graphics/algorithm/intersect.js +135 -0
- package/es/graphics/algorithm/intersect.js.map +1 -0
- package/es/graphics/algorithm/obb.d.ts +5 -0
- package/es/graphics/algorithm/obb.js +68 -0
- package/es/graphics/algorithm/obb.js.map +1 -0
- package/es/graphics/graph-util.d.ts +23 -0
- package/es/graphics/graph-util.js +39 -0
- package/es/graphics/graph-util.js.map +1 -0
- package/es/graphics/image.d.ts +2 -0
- package/es/graphics/image.js +12 -0
- package/es/graphics/image.js.map +1 -0
- package/es/graphics/index.d.ts +5 -0
- package/es/graphics/index.js +10 -0
- package/es/graphics/index.js.map +1 -0
- package/es/graphics/polygon.d.ts +5 -0
- package/es/graphics/polygon.js +47 -0
- package/es/graphics/polygon.js.map +1 -0
- package/es/graphics/text/index.d.ts +2 -0
- package/es/graphics/text/index.js +4 -0
- package/es/graphics/text/index.js.map +1 -0
- package/es/graphics/text/measure/index.d.ts +4 -0
- package/es/graphics/text/measure/index.js +8 -0
- package/es/graphics/text/measure/index.js.map +1 -0
- package/es/graphics/text/measure/interface.d.ts +31 -0
- package/es/graphics/text/measure/interface.js +2 -0
- package/es/graphics/text/measure/interface.js.map +1 -0
- package/es/graphics/text/measure/test.d.ts +14 -0
- package/es/graphics/text/measure/test.js +65 -0
- package/es/graphics/text/measure/test.js.map +1 -0
- package/es/graphics/text/measure/textMeasure.d.ts +38 -0
- package/es/graphics/text/measure/textMeasure.js +182 -0
- package/es/graphics/text/measure/textMeasure.js.map +1 -0
- package/es/graphics/text/measure/util.d.ts +2 -0
- package/es/graphics/text/measure/util.js +5 -0
- package/es/graphics/text/measure/util.js.map +1 -0
- package/es/graphics/text/stringWidth.d.ts +2 -0
- package/es/graphics/text/stringWidth.js +43 -0
- package/es/graphics/text/stringWidth.js.map +1 -0
- package/es/index.d.ts +15 -0
- package/es/index.js +30 -0
- package/es/index.js.map +1 -0
- package/es/logger.d.ts +12 -0
- package/es/logger.js +38 -0
- package/es/logger.js.map +1 -0
- package/es/lru.d.ts +25 -0
- package/es/lru.js +36 -0
- package/es/lru.js.map +1 -0
- package/es/math.d.ts +66 -0
- package/es/math.js +76 -0
- package/es/math.js.map +1 -0
- package/es/padding.d.ts +7 -0
- package/es/padding.js +31 -0
- package/es/padding.js.map +1 -0
- package/es/time/formatUtils.d.ts +17 -0
- package/es/time/formatUtils.js +72 -0
- package/es/time/formatUtils.js.map +1 -0
- package/es/time/index.d.ts +2 -0
- package/es/time/index.js +4 -0
- package/es/time/index.js.map +1 -0
- package/es/time/interval.d.ts +77 -0
- package/es/time/interval.js +227 -0
- package/es/time/interval.js.map +1 -0
- package/es/type.d.ts +5 -0
- package/es/type.js +2 -0
- package/es/type.js.map +1 -0
- package/package.json +3 -2
package/dist/index.js
ADDED
|
@@ -0,0 +1,4903 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.VUtils = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function getDefaultExportFromCjs (x) {
|
|
8
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
var eventemitter3 = {exports: {}};
|
|
12
|
+
|
|
13
|
+
(function (module) {
|
|
14
|
+
|
|
15
|
+
var has = Object.prototype.hasOwnProperty,
|
|
16
|
+
prefix = '~';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Constructor to create a storage for our `EE` objects.
|
|
20
|
+
* An `Events` instance is a plain object whose properties are event names.
|
|
21
|
+
*
|
|
22
|
+
* @constructor
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
function Events() {}
|
|
26
|
+
|
|
27
|
+
//
|
|
28
|
+
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
29
|
+
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
30
|
+
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
31
|
+
// character to make sure that the built-in object properties are not
|
|
32
|
+
// overridden or used as an attack vector.
|
|
33
|
+
//
|
|
34
|
+
if (Object.create) {
|
|
35
|
+
Events.prototype = Object.create(null);
|
|
36
|
+
|
|
37
|
+
//
|
|
38
|
+
// This hack is needed because the `__proto__` property is still inherited in
|
|
39
|
+
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
40
|
+
//
|
|
41
|
+
if (!new Events().__proto__) prefix = false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Representation of a single event listener.
|
|
46
|
+
*
|
|
47
|
+
* @param {Function} fn The listener function.
|
|
48
|
+
* @param {*} context The context to invoke the listener with.
|
|
49
|
+
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
50
|
+
* @constructor
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
function EE(fn, context, once) {
|
|
54
|
+
this.fn = fn;
|
|
55
|
+
this.context = context;
|
|
56
|
+
this.once = once || false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Add a listener for a given event.
|
|
61
|
+
*
|
|
62
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
63
|
+
* @param {(String|Symbol)} event The event name.
|
|
64
|
+
* @param {Function} fn The listener function.
|
|
65
|
+
* @param {*} context The context to invoke the listener with.
|
|
66
|
+
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
67
|
+
* @returns {EventEmitter}
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
function addListener(emitter, event, fn, context, once) {
|
|
71
|
+
if (typeof fn !== 'function') {
|
|
72
|
+
throw new TypeError('The listener must be a function');
|
|
73
|
+
}
|
|
74
|
+
var listener = new EE(fn, context || emitter, once),
|
|
75
|
+
evt = prefix ? prefix + event : event;
|
|
76
|
+
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);else emitter._events[evt] = [emitter._events[evt], listener];
|
|
77
|
+
return emitter;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Clear event by name.
|
|
82
|
+
*
|
|
83
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
84
|
+
* @param {(String|Symbol)} evt The Event name.
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
function clearEvent(emitter, evt) {
|
|
88
|
+
if (--emitter._eventsCount === 0) emitter._events = new Events();else delete emitter._events[evt];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
93
|
+
* `EventEmitter` interface.
|
|
94
|
+
*
|
|
95
|
+
* @constructor
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
function EventEmitter() {
|
|
99
|
+
this._events = new Events();
|
|
100
|
+
this._eventsCount = 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Return an array listing the events for which the emitter has registered
|
|
105
|
+
* listeners.
|
|
106
|
+
*
|
|
107
|
+
* @returns {Array}
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
111
|
+
var names = [],
|
|
112
|
+
events,
|
|
113
|
+
name;
|
|
114
|
+
if (this._eventsCount === 0) return names;
|
|
115
|
+
for (name in events = this._events) {
|
|
116
|
+
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
117
|
+
}
|
|
118
|
+
if (Object.getOwnPropertySymbols) {
|
|
119
|
+
return names.concat(Object.getOwnPropertySymbols(events));
|
|
120
|
+
}
|
|
121
|
+
return names;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Return the listeners registered for a given event.
|
|
126
|
+
*
|
|
127
|
+
* @param {(String|Symbol)} event The event name.
|
|
128
|
+
* @returns {Array} The registered listeners.
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
EventEmitter.prototype.listeners = function listeners(event) {
|
|
132
|
+
var evt = prefix ? prefix + event : event,
|
|
133
|
+
handlers = this._events[evt];
|
|
134
|
+
if (!handlers) return [];
|
|
135
|
+
if (handlers.fn) return [handlers.fn];
|
|
136
|
+
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
137
|
+
ee[i] = handlers[i].fn;
|
|
138
|
+
}
|
|
139
|
+
return ee;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Return the number of listeners listening to a given event.
|
|
144
|
+
*
|
|
145
|
+
* @param {(String|Symbol)} event The event name.
|
|
146
|
+
* @returns {Number} The number of listeners.
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
150
|
+
var evt = prefix ? prefix + event : event,
|
|
151
|
+
listeners = this._events[evt];
|
|
152
|
+
if (!listeners) return 0;
|
|
153
|
+
if (listeners.fn) return 1;
|
|
154
|
+
return listeners.length;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Calls each of the listeners registered for a given event.
|
|
159
|
+
*
|
|
160
|
+
* @param {(String|Symbol)} event The event name.
|
|
161
|
+
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
164
|
+
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
165
|
+
var evt = prefix ? prefix + event : event;
|
|
166
|
+
if (!this._events[evt]) return false;
|
|
167
|
+
var listeners = this._events[evt],
|
|
168
|
+
len = arguments.length,
|
|
169
|
+
args,
|
|
170
|
+
i;
|
|
171
|
+
if (listeners.fn) {
|
|
172
|
+
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
173
|
+
switch (len) {
|
|
174
|
+
case 1:
|
|
175
|
+
return listeners.fn.call(listeners.context), true;
|
|
176
|
+
case 2:
|
|
177
|
+
return listeners.fn.call(listeners.context, a1), true;
|
|
178
|
+
case 3:
|
|
179
|
+
return listeners.fn.call(listeners.context, a1, a2), true;
|
|
180
|
+
case 4:
|
|
181
|
+
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
182
|
+
case 5:
|
|
183
|
+
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
184
|
+
case 6:
|
|
185
|
+
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
186
|
+
}
|
|
187
|
+
for (i = 1, args = new Array(len - 1); i < len; i++) {
|
|
188
|
+
args[i - 1] = arguments[i];
|
|
189
|
+
}
|
|
190
|
+
listeners.fn.apply(listeners.context, args);
|
|
191
|
+
} else {
|
|
192
|
+
var length = listeners.length,
|
|
193
|
+
j;
|
|
194
|
+
for (i = 0; i < length; i++) {
|
|
195
|
+
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
196
|
+
switch (len) {
|
|
197
|
+
case 1:
|
|
198
|
+
listeners[i].fn.call(listeners[i].context);
|
|
199
|
+
break;
|
|
200
|
+
case 2:
|
|
201
|
+
listeners[i].fn.call(listeners[i].context, a1);
|
|
202
|
+
break;
|
|
203
|
+
case 3:
|
|
204
|
+
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
205
|
+
break;
|
|
206
|
+
case 4:
|
|
207
|
+
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
208
|
+
break;
|
|
209
|
+
default:
|
|
210
|
+
if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
|
|
211
|
+
args[j - 1] = arguments[j];
|
|
212
|
+
}
|
|
213
|
+
listeners[i].fn.apply(listeners[i].context, args);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return true;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Add a listener for a given event.
|
|
222
|
+
*
|
|
223
|
+
* @param {(String|Symbol)} event The event name.
|
|
224
|
+
* @param {Function} fn The listener function.
|
|
225
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
226
|
+
* @returns {EventEmitter} `this`.
|
|
227
|
+
* @public
|
|
228
|
+
*/
|
|
229
|
+
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
230
|
+
return addListener(this, event, fn, context, false);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Add a one-time listener for a given event.
|
|
235
|
+
*
|
|
236
|
+
* @param {(String|Symbol)} event The event name.
|
|
237
|
+
* @param {Function} fn The listener function.
|
|
238
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
239
|
+
* @returns {EventEmitter} `this`.
|
|
240
|
+
* @public
|
|
241
|
+
*/
|
|
242
|
+
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
243
|
+
return addListener(this, event, fn, context, true);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Remove the listeners of a given event.
|
|
248
|
+
*
|
|
249
|
+
* @param {(String|Symbol)} event The event name.
|
|
250
|
+
* @param {Function} fn Only remove the listeners that match this function.
|
|
251
|
+
* @param {*} context Only remove the listeners that have this context.
|
|
252
|
+
* @param {Boolean} once Only remove one-time listeners.
|
|
253
|
+
* @returns {EventEmitter} `this`.
|
|
254
|
+
* @public
|
|
255
|
+
*/
|
|
256
|
+
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
257
|
+
var evt = prefix ? prefix + event : event;
|
|
258
|
+
if (!this._events[evt]) return this;
|
|
259
|
+
if (!fn) {
|
|
260
|
+
clearEvent(this, evt);
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
var listeners = this._events[evt];
|
|
264
|
+
if (listeners.fn) {
|
|
265
|
+
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
|
|
266
|
+
clearEvent(this, evt);
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
270
|
+
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
|
|
271
|
+
events.push(listeners[i]);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
//
|
|
276
|
+
// Reset the array, or remove it completely if we have no more listeners.
|
|
277
|
+
//
|
|
278
|
+
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;else clearEvent(this, evt);
|
|
279
|
+
}
|
|
280
|
+
return this;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Remove all listeners, or those of the specified event.
|
|
285
|
+
*
|
|
286
|
+
* @param {(String|Symbol)} [event] The event name.
|
|
287
|
+
* @returns {EventEmitter} `this`.
|
|
288
|
+
* @public
|
|
289
|
+
*/
|
|
290
|
+
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
291
|
+
var evt;
|
|
292
|
+
if (event) {
|
|
293
|
+
evt = prefix ? prefix + event : event;
|
|
294
|
+
if (this._events[evt]) clearEvent(this, evt);
|
|
295
|
+
} else {
|
|
296
|
+
this._events = new Events();
|
|
297
|
+
this._eventsCount = 0;
|
|
298
|
+
}
|
|
299
|
+
return this;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
//
|
|
303
|
+
// Alias methods names because people roll like that.
|
|
304
|
+
//
|
|
305
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
306
|
+
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
307
|
+
|
|
308
|
+
//
|
|
309
|
+
// Expose the prefix.
|
|
310
|
+
//
|
|
311
|
+
EventEmitter.prefixed = prefix;
|
|
312
|
+
|
|
313
|
+
//
|
|
314
|
+
// Allow `EventEmitter` to be imported as module namespace.
|
|
315
|
+
//
|
|
316
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
317
|
+
|
|
318
|
+
//
|
|
319
|
+
// Expose the module.
|
|
320
|
+
//
|
|
321
|
+
{
|
|
322
|
+
module.exports = EventEmitter;
|
|
323
|
+
}
|
|
324
|
+
})(eventemitter3);
|
|
325
|
+
var eventemitter3Exports = eventemitter3.exports;
|
|
326
|
+
var index$1 = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports);
|
|
327
|
+
|
|
328
|
+
const isType = (value, type) => Object.prototype.toString.call(value) === `[object ${type}]`;
|
|
329
|
+
|
|
330
|
+
const isBoolean = (value, fuzzy = false) => {
|
|
331
|
+
if (fuzzy) {
|
|
332
|
+
return typeof value === 'boolean';
|
|
333
|
+
}
|
|
334
|
+
return value === true || value === false || isType(value, 'Boolean');
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const isFunction = (value) => {
|
|
338
|
+
return typeof value === 'function';
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const isNil = (value) => {
|
|
342
|
+
return value === null || value === undefined;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const isNull = (value) => {
|
|
346
|
+
return value === null;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const isValid = (value) => {
|
|
350
|
+
return value !== null && value !== undefined;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const isObject = (value) => {
|
|
354
|
+
const type = typeof value;
|
|
355
|
+
return (value !== null && type === 'object') || type === 'function';
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
const isObjectLike = (value) => {
|
|
359
|
+
return typeof value === 'object' && value !== null;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const isPlainObject = function (value) {
|
|
363
|
+
if (!isObjectLike(value) || !isType(value, 'Object')) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
if (Object.getPrototypeOf(value) === null) {
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
let proto = value;
|
|
370
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
371
|
+
proto = Object.getPrototypeOf(proto);
|
|
372
|
+
}
|
|
373
|
+
return Object.getPrototypeOf(value) === proto;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
const isUndefined = (value) => {
|
|
377
|
+
return value === undefined;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const isString = (value, fuzzy = false) => {
|
|
381
|
+
const type = typeof value;
|
|
382
|
+
if (fuzzy) {
|
|
383
|
+
return type === 'string';
|
|
384
|
+
}
|
|
385
|
+
return type === 'string' || isType(value, 'String');
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
const isArray = (value) => {
|
|
389
|
+
return Array.isArray ? Array.isArray(value) : isType(value, 'Array');
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const isArrayLike = function (value) {
|
|
393
|
+
return value !== null && typeof value !== 'function' && Number.isFinite(value.length);
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
const isDate = (value) => {
|
|
397
|
+
return isType(value, 'Date');
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
const isNumber = (value, fuzzy = false) => {
|
|
401
|
+
const type = typeof value;
|
|
402
|
+
if (fuzzy) {
|
|
403
|
+
return type === 'number';
|
|
404
|
+
}
|
|
405
|
+
return type === 'number' || isType(value, 'Number');
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
const isNumeric = (value) => {
|
|
409
|
+
if (typeof value !== 'string') {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
return !isNaN(Number(value)) && !isNaN(parseFloat(value));
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
const isValidNumber = (value) => {
|
|
416
|
+
return isNumber(value) && Number.isFinite(value);
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
const isValidUrl = (value) => {
|
|
420
|
+
const exp = /^(http(s)?:\/\/)\w+[^\s]+(\.[^\s]+){1,}$/;
|
|
421
|
+
const urlPattern = new RegExp(exp);
|
|
422
|
+
return urlPattern.test(value);
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const isRegExp = (value) => {
|
|
426
|
+
return isType(value, 'RegExp');
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
const isBase64 = (value) => {
|
|
430
|
+
const exp = /^data:image\/(?:gif|png|jpeg|bmp|webp)(?:;charset=utf-8)?;base64,(?:[A-Za-z0-9]|[+/])+={0,2}/g;
|
|
431
|
+
const urlPattern = new RegExp(exp);
|
|
432
|
+
return urlPattern.test(value);
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
const getType = (value) => {
|
|
436
|
+
return {}.toString
|
|
437
|
+
.call(value)
|
|
438
|
+
.replace(/^\[object /, '')
|
|
439
|
+
.replace(/]$/, '');
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
const objectProto = Object.prototype;
|
|
443
|
+
const isPrototype = function (value) {
|
|
444
|
+
const Ctor = value && value.constructor;
|
|
445
|
+
const proto = (typeof Ctor === 'function' && Ctor.prototype) || objectProto;
|
|
446
|
+
return value === proto;
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
const hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
450
|
+
function isEmpty(value) {
|
|
451
|
+
if (isNil(value)) {
|
|
452
|
+
return true;
|
|
453
|
+
}
|
|
454
|
+
if (isArrayLike(value)) {
|
|
455
|
+
return !value.length;
|
|
456
|
+
}
|
|
457
|
+
const type = getType(value);
|
|
458
|
+
if (type === 'Map' || type === 'Set') {
|
|
459
|
+
return !value.size;
|
|
460
|
+
}
|
|
461
|
+
if (isPrototype(value)) {
|
|
462
|
+
return !Object.keys(value).length;
|
|
463
|
+
}
|
|
464
|
+
for (const key in value) {
|
|
465
|
+
if (hasOwnProperty$2.call(value, key)) {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const get = (obj, path, defaultValue) => {
|
|
473
|
+
const paths = isString(path) ? path.split('.') : path;
|
|
474
|
+
for (let p = 0; p < paths.length; p++) {
|
|
475
|
+
obj = obj ? obj[paths[p]] : undefined;
|
|
476
|
+
}
|
|
477
|
+
return obj === undefined ? defaultValue : obj;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
481
|
+
const has = (object, key) => {
|
|
482
|
+
return object != null && hasOwnProperty$1.call(object, key);
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
function getRegExpFlags(re) {
|
|
486
|
+
let flags = '';
|
|
487
|
+
re.global && (flags += 'g');
|
|
488
|
+
re.ignoreCase && (flags += 'i');
|
|
489
|
+
re.multiline && (flags += 'm');
|
|
490
|
+
return flags;
|
|
491
|
+
}
|
|
492
|
+
function clone(parent, circular = false, depth = 0, prototype = undefined) {
|
|
493
|
+
const allParents = [];
|
|
494
|
+
const allChildren = [];
|
|
495
|
+
if (typeof circular === 'undefined') {
|
|
496
|
+
circular = true;
|
|
497
|
+
}
|
|
498
|
+
if (typeof depth === 'undefined') {
|
|
499
|
+
depth = Infinity;
|
|
500
|
+
}
|
|
501
|
+
function _clone(parent, depth) {
|
|
502
|
+
if (parent === null) {
|
|
503
|
+
return null;
|
|
504
|
+
}
|
|
505
|
+
if (depth === 0) {
|
|
506
|
+
return parent;
|
|
507
|
+
}
|
|
508
|
+
let child;
|
|
509
|
+
if (typeof parent !== 'object') {
|
|
510
|
+
return parent;
|
|
511
|
+
}
|
|
512
|
+
if (isArray(parent)) {
|
|
513
|
+
child = [];
|
|
514
|
+
}
|
|
515
|
+
else if (isRegExp(parent)) {
|
|
516
|
+
child = new RegExp(parent.source, getRegExpFlags(parent));
|
|
517
|
+
if (parent.lastIndex) {
|
|
518
|
+
child.lastIndex = parent.lastIndex;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
else if (isDate(parent)) {
|
|
522
|
+
child = new Date(parent.getTime());
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
if (typeof prototype === 'undefined') {
|
|
526
|
+
child = Object.create(Object.getPrototypeOf(parent));
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
child = Object.create(prototype);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
if (circular) {
|
|
533
|
+
const index = allParents.indexOf(parent);
|
|
534
|
+
if (index !== -1) {
|
|
535
|
+
return allChildren[index];
|
|
536
|
+
}
|
|
537
|
+
allParents.push(parent);
|
|
538
|
+
allChildren.push(child);
|
|
539
|
+
}
|
|
540
|
+
for (const i in parent) {
|
|
541
|
+
child[i] = _clone(parent[i], depth - 1);
|
|
542
|
+
}
|
|
543
|
+
return child;
|
|
544
|
+
}
|
|
545
|
+
return _clone(parent, depth);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function cloneDeep(value) {
|
|
549
|
+
let result;
|
|
550
|
+
if (!isValid(value) || typeof value !== 'object') {
|
|
551
|
+
return value;
|
|
552
|
+
}
|
|
553
|
+
const isArr = isArray(value);
|
|
554
|
+
const length = value.length;
|
|
555
|
+
if (isArr) {
|
|
556
|
+
result = new Array(length);
|
|
557
|
+
}
|
|
558
|
+
else if (typeof value === 'object') {
|
|
559
|
+
result = {};
|
|
560
|
+
}
|
|
561
|
+
else if (isBoolean(value) || isNumber(value) || isString(value)) {
|
|
562
|
+
result = value;
|
|
563
|
+
}
|
|
564
|
+
else if (isDate(value)) {
|
|
565
|
+
result = new Date(+value);
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
result = undefined;
|
|
569
|
+
}
|
|
570
|
+
const props = isArr ? undefined : Object.keys(Object(value));
|
|
571
|
+
let index = -1;
|
|
572
|
+
if (result) {
|
|
573
|
+
while (++index < (props || value).length) {
|
|
574
|
+
const key = props ? props[index] : index;
|
|
575
|
+
const subValue = value[key];
|
|
576
|
+
result[key] = cloneDeep(subValue);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
return result;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function baseMerge(target, source, shallowArray = false) {
|
|
583
|
+
if (source) {
|
|
584
|
+
if (target === source) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
if (isValid(source) && typeof source === 'object') {
|
|
588
|
+
const iterable = Object(source);
|
|
589
|
+
const props = [];
|
|
590
|
+
for (const key in iterable) {
|
|
591
|
+
props.push(key);
|
|
592
|
+
}
|
|
593
|
+
let { length } = props;
|
|
594
|
+
let propIndex = -1;
|
|
595
|
+
while (length--) {
|
|
596
|
+
const key = props[++propIndex];
|
|
597
|
+
if (isValid(iterable[key]) && typeof iterable[key] === 'object') {
|
|
598
|
+
baseMergeDeep(target, source, key, shallowArray);
|
|
599
|
+
}
|
|
600
|
+
else {
|
|
601
|
+
assignMergeValue(target, key, iterable[key]);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
function baseMergeDeep(target, source, key, shallowArray = false) {
|
|
608
|
+
const objValue = target[key];
|
|
609
|
+
const srcValue = source[key];
|
|
610
|
+
let newValue = source[key];
|
|
611
|
+
let isCommon = true;
|
|
612
|
+
if (isArray(srcValue)) {
|
|
613
|
+
if (shallowArray) {
|
|
614
|
+
newValue = [];
|
|
615
|
+
}
|
|
616
|
+
else if (isArray(objValue)) {
|
|
617
|
+
newValue = objValue;
|
|
618
|
+
}
|
|
619
|
+
else if (isArrayLike(objValue)) {
|
|
620
|
+
newValue = new Array(objValue.length);
|
|
621
|
+
let index = -1;
|
|
622
|
+
const length = objValue.length;
|
|
623
|
+
while (++index < length) {
|
|
624
|
+
newValue[index] = objValue[index];
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
else if (isPlainObject(srcValue)) {
|
|
629
|
+
newValue = objValue;
|
|
630
|
+
if (typeof objValue === 'function' || typeof objValue !== 'object') {
|
|
631
|
+
newValue = {};
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
isCommon = false;
|
|
636
|
+
}
|
|
637
|
+
if (isCommon) {
|
|
638
|
+
baseMerge(newValue, srcValue, shallowArray);
|
|
639
|
+
}
|
|
640
|
+
assignMergeValue(target, key, newValue);
|
|
641
|
+
}
|
|
642
|
+
function assignMergeValue(target, key, value) {
|
|
643
|
+
if ((value !== undefined && !eq(target[key], value)) || (value === undefined && !(key in target))) {
|
|
644
|
+
target[key] = value;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function eq(value, other) {
|
|
648
|
+
return value === other || (Number.isNaN(value) && Number.isNaN(other));
|
|
649
|
+
}
|
|
650
|
+
function merge(target, ...sources) {
|
|
651
|
+
let sourceIndex = -1;
|
|
652
|
+
const length = sources.length;
|
|
653
|
+
while (++sourceIndex < length) {
|
|
654
|
+
const source = sources[sourceIndex];
|
|
655
|
+
baseMerge(target, source, true);
|
|
656
|
+
}
|
|
657
|
+
return target;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
661
|
+
function pick(obj, keys) {
|
|
662
|
+
if (!obj || !isPlainObject(obj)) {
|
|
663
|
+
return obj;
|
|
664
|
+
}
|
|
665
|
+
const result = {};
|
|
666
|
+
keys.forEach(k => {
|
|
667
|
+
if (hasOwnProperty.call(obj, k)) {
|
|
668
|
+
result[k] = obj[k];
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
return result;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
function pickWithout(obj, keys) {
|
|
675
|
+
if (!obj || !isPlainObject(obj)) {
|
|
676
|
+
return obj;
|
|
677
|
+
}
|
|
678
|
+
const result = {};
|
|
679
|
+
Object.keys(obj).forEach((k) => {
|
|
680
|
+
const v = obj[k];
|
|
681
|
+
let match = false;
|
|
682
|
+
keys.forEach(itKey => {
|
|
683
|
+
if (isString(itKey) && itKey === k) {
|
|
684
|
+
match = true;
|
|
685
|
+
}
|
|
686
|
+
else if (itKey instanceof RegExp && k.match(itKey)) {
|
|
687
|
+
match = true;
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
if (!match) {
|
|
691
|
+
result[k] = v;
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
return result;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
function objToString(obj) {
|
|
698
|
+
return Object.prototype.toString.call(obj);
|
|
699
|
+
}
|
|
700
|
+
function objectKeys(obj) {
|
|
701
|
+
return Object.keys(obj);
|
|
702
|
+
}
|
|
703
|
+
function isEqual(a, b) {
|
|
704
|
+
if (a === b) {
|
|
705
|
+
return true;
|
|
706
|
+
}
|
|
707
|
+
if (typeof a !== typeof b) {
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
if (a == null || b == null) {
|
|
711
|
+
return false;
|
|
712
|
+
}
|
|
713
|
+
if (Number.isNaN(a) && Number.isNaN(b)) {
|
|
714
|
+
return true;
|
|
715
|
+
}
|
|
716
|
+
if (objToString(a) !== objToString(b)) {
|
|
717
|
+
return false;
|
|
718
|
+
}
|
|
719
|
+
if (isFunction(a)) {
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
if (typeof a !== 'object') {
|
|
723
|
+
return false;
|
|
724
|
+
}
|
|
725
|
+
if (isArray(a)) {
|
|
726
|
+
if (a.length !== b.length) {
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
for (let i = a.length - 1; i >= 0; i--) {
|
|
730
|
+
if (!isEqual(a[i], b[i])) {
|
|
731
|
+
return false;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
if (!isPlainObject(a)) {
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
const ka = objectKeys(a);
|
|
740
|
+
const kb = objectKeys(b);
|
|
741
|
+
if (ka.length !== kb.length) {
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
ka.sort();
|
|
745
|
+
kb.sort();
|
|
746
|
+
for (let i = ka.length - 1; i >= 0; i--) {
|
|
747
|
+
if (ka[i] != kb[i]) {
|
|
748
|
+
return false;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
for (let i = ka.length - 1; i >= 0; i--) {
|
|
752
|
+
const key = ka[i];
|
|
753
|
+
if (!isEqual(a[key], b[key])) {
|
|
754
|
+
return false;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return true;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
function is(x, y) {
|
|
761
|
+
if (x === y) {
|
|
762
|
+
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
|
763
|
+
}
|
|
764
|
+
return x !== x && y !== y;
|
|
765
|
+
}
|
|
766
|
+
function length(obj) {
|
|
767
|
+
if (isArray(obj)) {
|
|
768
|
+
return obj.length;
|
|
769
|
+
}
|
|
770
|
+
if (isObject(obj)) {
|
|
771
|
+
return Object.keys(obj).length;
|
|
772
|
+
}
|
|
773
|
+
return 0;
|
|
774
|
+
}
|
|
775
|
+
function isShallowEqual(objA, objB) {
|
|
776
|
+
if (is(objA, objB)) {
|
|
777
|
+
return true;
|
|
778
|
+
}
|
|
779
|
+
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
780
|
+
return false;
|
|
781
|
+
}
|
|
782
|
+
if (isArray(objA) !== isArray(objB)) {
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
if (length(objA) !== length(objB)) {
|
|
786
|
+
return false;
|
|
787
|
+
}
|
|
788
|
+
let ret = true;
|
|
789
|
+
Object.keys(objA).forEach((k) => {
|
|
790
|
+
const v = objA[k];
|
|
791
|
+
if (!is(v, objB[k])) {
|
|
792
|
+
ret = false;
|
|
793
|
+
return ret;
|
|
794
|
+
}
|
|
795
|
+
return true;
|
|
796
|
+
});
|
|
797
|
+
return ret;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
function keys(obj) {
|
|
801
|
+
if (!obj) {
|
|
802
|
+
return [];
|
|
803
|
+
}
|
|
804
|
+
if (Object.keys) {
|
|
805
|
+
return Object.keys(obj);
|
|
806
|
+
}
|
|
807
|
+
const keyList = [];
|
|
808
|
+
for (const key in obj) {
|
|
809
|
+
if (obj.hasOwnProperty(key)) {
|
|
810
|
+
keyList.push(key);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
return keyList;
|
|
814
|
+
}
|
|
815
|
+
function defaults(target, source, overlay) {
|
|
816
|
+
const keysArr = keys(source);
|
|
817
|
+
for (let i = 0; i < keysArr.length; i++) {
|
|
818
|
+
const key = keysArr[i];
|
|
819
|
+
if (overlay ? source[key] != null : target[key] == null) {
|
|
820
|
+
target[key] = source[key];
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
return target;
|
|
824
|
+
}
|
|
825
|
+
function mixin(target, source, override = true) {
|
|
826
|
+
target = 'prototype' in target ? target.prototype : target;
|
|
827
|
+
source = 'prototype' in source ? source.prototype : source;
|
|
828
|
+
if (Object.getOwnPropertyNames) {
|
|
829
|
+
const keyList = Object.getOwnPropertyNames(source);
|
|
830
|
+
for (let i = 0; i < keyList.length; i++) {
|
|
831
|
+
const key = keyList[i];
|
|
832
|
+
if (key !== 'constructor') {
|
|
833
|
+
if (override ? source[key] != null : target[key] == null) {
|
|
834
|
+
target[key] = source[key];
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
else {
|
|
840
|
+
defaults(target, source, override);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
function array(arr) {
|
|
845
|
+
if (isValid(arr)) {
|
|
846
|
+
return isArray(arr) ? arr : [arr];
|
|
847
|
+
}
|
|
848
|
+
return [];
|
|
849
|
+
}
|
|
850
|
+
function last(val) {
|
|
851
|
+
if (isArrayLike(val)) {
|
|
852
|
+
const arr = val;
|
|
853
|
+
return arr[arr.length - 1];
|
|
854
|
+
}
|
|
855
|
+
return undefined;
|
|
856
|
+
}
|
|
857
|
+
const span = (arr) => {
|
|
858
|
+
if (arr.length <= 1) {
|
|
859
|
+
return 0;
|
|
860
|
+
}
|
|
861
|
+
return last(arr) - arr[0];
|
|
862
|
+
};
|
|
863
|
+
function maxInArray(arr) {
|
|
864
|
+
if (!arr || !isArray(arr)) {
|
|
865
|
+
return undefined;
|
|
866
|
+
}
|
|
867
|
+
return arr.reduce((prev, curr) => Math.max(prev, curr), -Infinity);
|
|
868
|
+
}
|
|
869
|
+
function minInArray(arr) {
|
|
870
|
+
if (!arr || !isArray(arr)) {
|
|
871
|
+
return undefined;
|
|
872
|
+
}
|
|
873
|
+
return arr.reduce((prev, curr) => Math.min(prev, curr), Infinity);
|
|
874
|
+
}
|
|
875
|
+
function arrayEqual(a, b) {
|
|
876
|
+
if (!isArray(a) || !isArray(b)) {
|
|
877
|
+
return false;
|
|
878
|
+
}
|
|
879
|
+
if (a.length !== b.length) {
|
|
880
|
+
return false;
|
|
881
|
+
}
|
|
882
|
+
for (let i = 0; i < a.length; i++) {
|
|
883
|
+
if (a[i] !== b[i]) {
|
|
884
|
+
return false;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
return true;
|
|
888
|
+
}
|
|
889
|
+
function uniqArray(arr) {
|
|
890
|
+
if (!arr || !isArray(arr)) {
|
|
891
|
+
return arr;
|
|
892
|
+
}
|
|
893
|
+
return Array.from(new Set(array(arr)));
|
|
894
|
+
}
|
|
895
|
+
function shuffleArray(arr, random = Math.random) {
|
|
896
|
+
let j;
|
|
897
|
+
let x;
|
|
898
|
+
let i = arr.length;
|
|
899
|
+
while (i) {
|
|
900
|
+
j = Math.floor(random() * i);
|
|
901
|
+
x = arr[--i];
|
|
902
|
+
arr[i] = arr[j];
|
|
903
|
+
arr[j] = x;
|
|
904
|
+
}
|
|
905
|
+
return arr;
|
|
906
|
+
}
|
|
907
|
+
function flattenArray(arr) {
|
|
908
|
+
if (!isArray(arr)) {
|
|
909
|
+
return [arr];
|
|
910
|
+
}
|
|
911
|
+
const result = [];
|
|
912
|
+
for (const value of arr) {
|
|
913
|
+
result.push(...flattenArray(value));
|
|
914
|
+
}
|
|
915
|
+
return result;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
function range(start, stop, step) {
|
|
919
|
+
if (!isValid(stop)) {
|
|
920
|
+
stop = start;
|
|
921
|
+
start = 0;
|
|
922
|
+
}
|
|
923
|
+
if (!isValid(step)) {
|
|
924
|
+
step = 1;
|
|
925
|
+
}
|
|
926
|
+
let i = -1;
|
|
927
|
+
const n = Math.max(0, Math.ceil((stop - start) / step)) | 0;
|
|
928
|
+
const range = new Array(n);
|
|
929
|
+
while (++i < n) {
|
|
930
|
+
range[i] = start + i * step;
|
|
931
|
+
}
|
|
932
|
+
return range;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
function ascending(a, b) {
|
|
936
|
+
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
function toNumber(a) {
|
|
940
|
+
return Number(a);
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function quantileSorted(values, percent, valueof = toNumber) {
|
|
944
|
+
const n = values.length;
|
|
945
|
+
if (!n) {
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
if (percent <= 0 || n < 2) {
|
|
949
|
+
return valueof(values[0], 0, values);
|
|
950
|
+
}
|
|
951
|
+
if (percent >= 1) {
|
|
952
|
+
return valueof(values[n - 1], n - 1, values);
|
|
953
|
+
}
|
|
954
|
+
const i = (n - 1) * percent;
|
|
955
|
+
const i0 = Math.floor(i);
|
|
956
|
+
const value0 = valueof(values[i0], i0, values);
|
|
957
|
+
const value1 = valueof(values[i0 + 1], i0 + 1, values);
|
|
958
|
+
return value0 + (value1 - value0) * (i - i0);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
function bisect(a, x, lo = 0, hi) {
|
|
962
|
+
if (isNil(hi)) {
|
|
963
|
+
hi = a.length;
|
|
964
|
+
}
|
|
965
|
+
while (lo < hi) {
|
|
966
|
+
const mid = (lo + hi) >>> 1;
|
|
967
|
+
if (ascending(a[mid], x) > 0) {
|
|
968
|
+
hi = mid;
|
|
969
|
+
}
|
|
970
|
+
else {
|
|
971
|
+
lo = mid + 1;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
return lo;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
function variance(values, valueof) {
|
|
978
|
+
let count = 0;
|
|
979
|
+
let delta;
|
|
980
|
+
let mean = 0;
|
|
981
|
+
let sum = 0;
|
|
982
|
+
if (valueof === undefined) {
|
|
983
|
+
for (let value of values) {
|
|
984
|
+
if (value != null && (value = +value) >= value) {
|
|
985
|
+
delta = value - mean;
|
|
986
|
+
mean += delta / ++count;
|
|
987
|
+
sum += delta * (value - mean);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
else {
|
|
992
|
+
let index = -1;
|
|
993
|
+
for (let value of values) {
|
|
994
|
+
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
|
|
995
|
+
delta = value - mean;
|
|
996
|
+
mean += delta / ++count;
|
|
997
|
+
sum += delta * (value - mean);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
if (count > 1) {
|
|
1002
|
+
return sum / (count - 1);
|
|
1003
|
+
}
|
|
1004
|
+
return 0;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
function deviation(values, valueof) {
|
|
1008
|
+
const v = variance(values, valueof);
|
|
1009
|
+
return v ? Math.sqrt(v) : v;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
const median = (values, isSorted) => {
|
|
1013
|
+
let sorted = values;
|
|
1014
|
+
if (isSorted !== true) {
|
|
1015
|
+
sorted = values.sort(ascending);
|
|
1016
|
+
}
|
|
1017
|
+
return quantileSorted(sorted, 0.5);
|
|
1018
|
+
};
|
|
1019
|
+
|
|
1020
|
+
const e10 = Math.sqrt(50);
|
|
1021
|
+
const e5 = Math.sqrt(10);
|
|
1022
|
+
const e2 = Math.sqrt(2);
|
|
1023
|
+
function tickStep(start, stop, count) {
|
|
1024
|
+
const step0 = Math.abs(stop - start) / Math.max(0, count);
|
|
1025
|
+
let step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10));
|
|
1026
|
+
const error = step0 / step1;
|
|
1027
|
+
if (error >= e10) {
|
|
1028
|
+
step1 *= 10;
|
|
1029
|
+
}
|
|
1030
|
+
else if (error >= e5) {
|
|
1031
|
+
step1 *= 5;
|
|
1032
|
+
}
|
|
1033
|
+
else if (error >= e2) {
|
|
1034
|
+
step1 *= 2;
|
|
1035
|
+
}
|
|
1036
|
+
return stop < start ? -step1 : step1;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
const DEFAULT_ABSOLUTE_TOLERATE = 1e-10;
|
|
1040
|
+
const DEFAULT_RELATIVE_TOLERATE = 1e-10;
|
|
1041
|
+
function isNumberClose(a, b, relTol = DEFAULT_RELATIVE_TOLERATE, absTol = DEFAULT_ABSOLUTE_TOLERATE) {
|
|
1042
|
+
const abs = absTol;
|
|
1043
|
+
const rel = relTol * Math.max(a, b);
|
|
1044
|
+
return Math.abs(a - b) <= Math.max(abs, rel);
|
|
1045
|
+
}
|
|
1046
|
+
function isGreater(a, b, relTol, absTol) {
|
|
1047
|
+
return a > b && !isNumberClose(a, b, relTol, absTol);
|
|
1048
|
+
}
|
|
1049
|
+
function isLess(a, b, relTol, absTol) {
|
|
1050
|
+
return a < b && !isNumberClose(a, b, relTol, absTol);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
const constant = (value) => {
|
|
1054
|
+
return isFunction(value)
|
|
1055
|
+
? value
|
|
1056
|
+
: () => {
|
|
1057
|
+
return value;
|
|
1058
|
+
};
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
const repeat = (str, repeatCount = 0) => {
|
|
1062
|
+
let s = '';
|
|
1063
|
+
let i = repeatCount - 1;
|
|
1064
|
+
while (i >= 0) {
|
|
1065
|
+
s = `${s}${str}`;
|
|
1066
|
+
i -= 1;
|
|
1067
|
+
}
|
|
1068
|
+
return s;
|
|
1069
|
+
};
|
|
1070
|
+
const pad = (str, length, padChar = ' ', align = 'right') => {
|
|
1071
|
+
const c = padChar;
|
|
1072
|
+
const s = str + '';
|
|
1073
|
+
const n = length - s.length;
|
|
1074
|
+
if (n <= 0) {
|
|
1075
|
+
return s;
|
|
1076
|
+
}
|
|
1077
|
+
if (align === 'left') {
|
|
1078
|
+
return repeat(c, n) + s;
|
|
1079
|
+
}
|
|
1080
|
+
return align === 'center' ? repeat(c, Math.floor(n / 2)) + s + repeat(c, Math.ceil(n / 2)) : s + repeat(c, n);
|
|
1081
|
+
};
|
|
1082
|
+
|
|
1083
|
+
const truncate = (str, length, align = 'right', ellipsis) => {
|
|
1084
|
+
const e = !isNil(ellipsis) ? ellipsis : '\u2026';
|
|
1085
|
+
const s = str + '';
|
|
1086
|
+
const n = s.length;
|
|
1087
|
+
const l = Math.max(0, length - e.length);
|
|
1088
|
+
if (n <= length) {
|
|
1089
|
+
return s;
|
|
1090
|
+
}
|
|
1091
|
+
if (align === 'left') {
|
|
1092
|
+
return e + s.slice(n - l);
|
|
1093
|
+
}
|
|
1094
|
+
return align === 'center' ? s.slice(0, Math.ceil(l / 2)) + e + s.slice(n - Math.floor(l / 2)) : s.slice(0, l) + e;
|
|
1095
|
+
};
|
|
1096
|
+
|
|
1097
|
+
const uuid = (len, radix) => {
|
|
1098
|
+
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
|
|
1099
|
+
const uuid = [];
|
|
1100
|
+
let i;
|
|
1101
|
+
radix = radix || chars.length;
|
|
1102
|
+
if (len) {
|
|
1103
|
+
for (i = 0; i < len; i++) {
|
|
1104
|
+
uuid[i] = chars[0 | (Math.random() * radix)];
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
else {
|
|
1108
|
+
let r;
|
|
1109
|
+
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
|
|
1110
|
+
uuid[14] = '4';
|
|
1111
|
+
for (i = 0; i < 36; i++) {
|
|
1112
|
+
if (!uuid[i]) {
|
|
1113
|
+
r = 0 | (Math.random() * 16);
|
|
1114
|
+
uuid[i] = chars[i === 19 ? (r & 0x3) | 0x8 : r];
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
return uuid.join('');
|
|
1119
|
+
};
|
|
1120
|
+
|
|
1121
|
+
const clamp = function (input, min, max) {
|
|
1122
|
+
if (input < min) {
|
|
1123
|
+
return min;
|
|
1124
|
+
}
|
|
1125
|
+
else if (input > max) {
|
|
1126
|
+
return max;
|
|
1127
|
+
}
|
|
1128
|
+
return input;
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
const clampRange = (range, min, max) => {
|
|
1132
|
+
let [lowValue, highValue] = range;
|
|
1133
|
+
if (highValue < lowValue) {
|
|
1134
|
+
lowValue = range[1];
|
|
1135
|
+
highValue = range[0];
|
|
1136
|
+
}
|
|
1137
|
+
const span = highValue - lowValue;
|
|
1138
|
+
if (span >= max - min) {
|
|
1139
|
+
return [min, max];
|
|
1140
|
+
}
|
|
1141
|
+
lowValue = Math.min(Math.max(lowValue, min), max - span);
|
|
1142
|
+
return [lowValue, lowValue + span];
|
|
1143
|
+
};
|
|
1144
|
+
|
|
1145
|
+
function clamper(a, b) {
|
|
1146
|
+
let t;
|
|
1147
|
+
if (a > b) {
|
|
1148
|
+
t = a;
|
|
1149
|
+
a = b;
|
|
1150
|
+
b = t;
|
|
1151
|
+
}
|
|
1152
|
+
return (x) => {
|
|
1153
|
+
return Math.max(a, Math.min(b, x));
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
let hasRaf = false;
|
|
1158
|
+
try {
|
|
1159
|
+
hasRaf = typeof requestAnimationFrame === 'function' && typeof cancelAnimationFrame === 'function';
|
|
1160
|
+
}
|
|
1161
|
+
catch (err) {
|
|
1162
|
+
hasRaf = false;
|
|
1163
|
+
}
|
|
1164
|
+
hasRaf = false;
|
|
1165
|
+
function debounce(func, wait, options) {
|
|
1166
|
+
let lastArgs;
|
|
1167
|
+
let lastThis;
|
|
1168
|
+
let maxWait;
|
|
1169
|
+
let result;
|
|
1170
|
+
let timerId;
|
|
1171
|
+
let lastCallTime;
|
|
1172
|
+
let lastInvokeTime = 0;
|
|
1173
|
+
let leading = false;
|
|
1174
|
+
let maxing = false;
|
|
1175
|
+
let trailing = true;
|
|
1176
|
+
const useRAF = !wait && wait !== 0 && hasRaf;
|
|
1177
|
+
if (typeof func !== 'function') {
|
|
1178
|
+
throw new TypeError('Expected a function');
|
|
1179
|
+
}
|
|
1180
|
+
wait = +wait || 0;
|
|
1181
|
+
if (isObject(options)) {
|
|
1182
|
+
leading = !!options.leading;
|
|
1183
|
+
maxing = 'maxWait' in options;
|
|
1184
|
+
if (maxing) {
|
|
1185
|
+
maxWait = Math.max(isValidNumber(options.maxWait) ? options.maxWait : 0, wait);
|
|
1186
|
+
}
|
|
1187
|
+
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
1188
|
+
}
|
|
1189
|
+
function invokeFunc(time) {
|
|
1190
|
+
const args = lastArgs;
|
|
1191
|
+
const thisArg = lastThis;
|
|
1192
|
+
lastArgs = lastThis = undefined;
|
|
1193
|
+
lastInvokeTime = time;
|
|
1194
|
+
result = func.apply(thisArg, args);
|
|
1195
|
+
return result;
|
|
1196
|
+
}
|
|
1197
|
+
function startTimer(pendingFunc, wait) {
|
|
1198
|
+
if (useRAF) {
|
|
1199
|
+
cancelAnimationFrame(timerId);
|
|
1200
|
+
return requestAnimationFrame(pendingFunc);
|
|
1201
|
+
}
|
|
1202
|
+
return setTimeout(pendingFunc, wait);
|
|
1203
|
+
}
|
|
1204
|
+
function cancelTimer(id) {
|
|
1205
|
+
if (useRAF) {
|
|
1206
|
+
return cancelAnimationFrame(id);
|
|
1207
|
+
}
|
|
1208
|
+
clearTimeout(id);
|
|
1209
|
+
}
|
|
1210
|
+
function leadingEdge(time) {
|
|
1211
|
+
lastInvokeTime = time;
|
|
1212
|
+
timerId = startTimer(timerExpired, wait);
|
|
1213
|
+
return leading ? invokeFunc(time) : result;
|
|
1214
|
+
}
|
|
1215
|
+
function remainingWait(time) {
|
|
1216
|
+
const timeSinceLastCall = time - lastCallTime;
|
|
1217
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
1218
|
+
const timeWaiting = wait - timeSinceLastCall;
|
|
1219
|
+
return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
1220
|
+
}
|
|
1221
|
+
function shouldInvoke(time) {
|
|
1222
|
+
const timeSinceLastCall = time - lastCallTime;
|
|
1223
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
1224
|
+
return (lastCallTime === undefined ||
|
|
1225
|
+
timeSinceLastCall >= wait ||
|
|
1226
|
+
timeSinceLastCall < 0 ||
|
|
1227
|
+
(maxing && timeSinceLastInvoke >= maxWait));
|
|
1228
|
+
}
|
|
1229
|
+
function timerExpired() {
|
|
1230
|
+
const time = Date.now();
|
|
1231
|
+
if (shouldInvoke(time)) {
|
|
1232
|
+
return trailingEdge(time);
|
|
1233
|
+
}
|
|
1234
|
+
timerId = startTimer(timerExpired, remainingWait(time));
|
|
1235
|
+
}
|
|
1236
|
+
function trailingEdge(time) {
|
|
1237
|
+
timerId = undefined;
|
|
1238
|
+
if (trailing && lastArgs) {
|
|
1239
|
+
return invokeFunc(time);
|
|
1240
|
+
}
|
|
1241
|
+
lastArgs = lastThis = undefined;
|
|
1242
|
+
return result;
|
|
1243
|
+
}
|
|
1244
|
+
function cancel() {
|
|
1245
|
+
if (timerId !== undefined) {
|
|
1246
|
+
cancelTimer(timerId);
|
|
1247
|
+
}
|
|
1248
|
+
lastInvokeTime = 0;
|
|
1249
|
+
lastArgs = lastCallTime = lastThis = timerId = undefined;
|
|
1250
|
+
}
|
|
1251
|
+
function flush() {
|
|
1252
|
+
return timerId === undefined ? result : trailingEdge(Date.now());
|
|
1253
|
+
}
|
|
1254
|
+
function pending() {
|
|
1255
|
+
return timerId !== undefined;
|
|
1256
|
+
}
|
|
1257
|
+
function debounced(...args) {
|
|
1258
|
+
const time = Date.now();
|
|
1259
|
+
const isInvoking = shouldInvoke(time);
|
|
1260
|
+
lastArgs = args;
|
|
1261
|
+
lastThis = this;
|
|
1262
|
+
lastCallTime = time;
|
|
1263
|
+
if (isInvoking) {
|
|
1264
|
+
if (timerId === undefined) {
|
|
1265
|
+
return leadingEdge(lastCallTime);
|
|
1266
|
+
}
|
|
1267
|
+
if (maxing) {
|
|
1268
|
+
timerId = startTimer(timerExpired, wait);
|
|
1269
|
+
return invokeFunc(lastCallTime);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
if (timerId === undefined) {
|
|
1273
|
+
timerId = startTimer(timerExpired, wait);
|
|
1274
|
+
}
|
|
1275
|
+
return result;
|
|
1276
|
+
}
|
|
1277
|
+
debounced.cancel = cancel;
|
|
1278
|
+
debounced.flush = flush;
|
|
1279
|
+
debounced.pending = pending;
|
|
1280
|
+
return debounced;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
function throttle(func, wait, options) {
|
|
1284
|
+
let leading = true;
|
|
1285
|
+
let trailing = true;
|
|
1286
|
+
if (typeof func !== 'function') {
|
|
1287
|
+
throw new TypeError('Expected a function');
|
|
1288
|
+
}
|
|
1289
|
+
if (isObject(options)) {
|
|
1290
|
+
leading = 'leading' in options ? !!options.leading : leading;
|
|
1291
|
+
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
1292
|
+
}
|
|
1293
|
+
return debounce(func, wait, {
|
|
1294
|
+
leading,
|
|
1295
|
+
trailing,
|
|
1296
|
+
maxWait: wait
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
function interpolateNumber(a, b) {
|
|
1301
|
+
return (t) => {
|
|
1302
|
+
return a * (1 - t) + b * t;
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
function interpolateNumberRound(a, b) {
|
|
1306
|
+
return function (t) {
|
|
1307
|
+
return Math.round(a * (1 - t) + b * t);
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
function interpolateDate(a, b) {
|
|
1311
|
+
const aVal = a.valueOf();
|
|
1312
|
+
const bVal = b.valueOf();
|
|
1313
|
+
const d = new Date();
|
|
1314
|
+
return (t) => {
|
|
1315
|
+
d.setTime(aVal * (1 - t) + bVal * t);
|
|
1316
|
+
return d;
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
const reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
|
|
1320
|
+
const reB = new RegExp(reA.source, 'g');
|
|
1321
|
+
function zero(b) {
|
|
1322
|
+
return function () {
|
|
1323
|
+
return b;
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
function one(b) {
|
|
1327
|
+
return function (t) {
|
|
1328
|
+
return b(t) + '';
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
function interpolateString(a, b) {
|
|
1332
|
+
let bi = (reA.lastIndex = reB.lastIndex = 0);
|
|
1333
|
+
let am;
|
|
1334
|
+
let bm;
|
|
1335
|
+
let bs;
|
|
1336
|
+
let i = -1;
|
|
1337
|
+
const s = [];
|
|
1338
|
+
const q = [];
|
|
1339
|
+
(a = a + ''), (b = b + '');
|
|
1340
|
+
while ((am = reA.exec(a)) && (bm = reB.exec(b))) {
|
|
1341
|
+
if ((bs = bm.index) > bi) {
|
|
1342
|
+
bs = b.slice(bi, bs);
|
|
1343
|
+
if (s[i]) {
|
|
1344
|
+
s[i] += bs;
|
|
1345
|
+
}
|
|
1346
|
+
else {
|
|
1347
|
+
s[++i] = bs;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
if ((am = am[0]) === (bm = bm[0])) {
|
|
1351
|
+
if (s[i]) {
|
|
1352
|
+
s[i] += bm;
|
|
1353
|
+
}
|
|
1354
|
+
else {
|
|
1355
|
+
s[++i] = bm;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
else {
|
|
1359
|
+
s[++i] = null;
|
|
1360
|
+
q.push({ i: i, x: interpolateNumber(am, bm) });
|
|
1361
|
+
}
|
|
1362
|
+
bi = reB.lastIndex;
|
|
1363
|
+
}
|
|
1364
|
+
if (bi < b.length) {
|
|
1365
|
+
bs = b.slice(bi);
|
|
1366
|
+
if (s[i]) {
|
|
1367
|
+
s[i] += bs;
|
|
1368
|
+
}
|
|
1369
|
+
else {
|
|
1370
|
+
s[++i] = bs;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
return s.length < 2
|
|
1374
|
+
? q[0]
|
|
1375
|
+
? one(q[0].x)
|
|
1376
|
+
: zero(b)
|
|
1377
|
+
: ((b = q.length),
|
|
1378
|
+
function (t) {
|
|
1379
|
+
for (let i = 0, o; i < b; ++i) {
|
|
1380
|
+
s[(o = q[i]).i] = o.x(t);
|
|
1381
|
+
}
|
|
1382
|
+
return s.join('');
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
const TIME_REG = /^(?:(\d{4})(?:[-\/](\d{1,2})(?:[-\/](\d{1,2})(?:[T ](\d{1,2})(?::(\d{1,2})(?::(\d{1,2})(?:[.,](\d+))?)?)?(Z|[\+\-]\d\d:?\d\d)?)?)?)?)?$/;
|
|
1387
|
+
function toDate(val) {
|
|
1388
|
+
if (val instanceof Date) {
|
|
1389
|
+
return val;
|
|
1390
|
+
}
|
|
1391
|
+
else if (isString(val)) {
|
|
1392
|
+
const match = TIME_REG.exec(val);
|
|
1393
|
+
if (!match) {
|
|
1394
|
+
return new Date(NaN);
|
|
1395
|
+
}
|
|
1396
|
+
if (!match[8]) {
|
|
1397
|
+
return new Date(+match[1], +(match[2] || 1) - 1, +match[3] || 1, +match[4] || 0, +(match[5] || 0), +match[6] || 0, match[7] ? +match[7].substring(0, 3) : 0);
|
|
1398
|
+
}
|
|
1399
|
+
let hour = +match[4] || 0;
|
|
1400
|
+
if (match[8].toUpperCase() !== 'Z') {
|
|
1401
|
+
hour -= +match[8].slice(0, 3);
|
|
1402
|
+
}
|
|
1403
|
+
return new Date(Date.UTC(+match[1], +(match[2] || 1) - 1, +match[3] || 1, hour, +(match[5] || 0), +match[6] || 0, match[7] ? +match[7].substring(0, 3) : 0));
|
|
1404
|
+
}
|
|
1405
|
+
else if (isNil(val)) {
|
|
1406
|
+
return new Date(NaN);
|
|
1407
|
+
}
|
|
1408
|
+
return new Date(Math.round(val));
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
function toValidNumber(v) {
|
|
1412
|
+
if (isValidNumber(v)) {
|
|
1413
|
+
return v;
|
|
1414
|
+
}
|
|
1415
|
+
const value = +v;
|
|
1416
|
+
return isValidNumber(value) ? value : 0;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
const lowerFirst = function (str) {
|
|
1420
|
+
return str.charAt(0).toLowerCase() + str.substring(1);
|
|
1421
|
+
};
|
|
1422
|
+
|
|
1423
|
+
const upperFirst = function (str) {
|
|
1424
|
+
return str.charAt(0).toUpperCase() + str.substring(1);
|
|
1425
|
+
};
|
|
1426
|
+
|
|
1427
|
+
class HashValue {
|
|
1428
|
+
index;
|
|
1429
|
+
key;
|
|
1430
|
+
value;
|
|
1431
|
+
}
|
|
1432
|
+
class HashTable {
|
|
1433
|
+
items;
|
|
1434
|
+
itemList;
|
|
1435
|
+
constructor() {
|
|
1436
|
+
this.items = {};
|
|
1437
|
+
this.itemList = [];
|
|
1438
|
+
}
|
|
1439
|
+
get type() {
|
|
1440
|
+
return 'xhHashTable';
|
|
1441
|
+
}
|
|
1442
|
+
set(key, value) {
|
|
1443
|
+
const vl = new HashValue();
|
|
1444
|
+
vl.key = key;
|
|
1445
|
+
vl.value = value;
|
|
1446
|
+
let index = this.itemList.length;
|
|
1447
|
+
if (this.has(key)) {
|
|
1448
|
+
index = this.items[key].index;
|
|
1449
|
+
}
|
|
1450
|
+
vl.index = index;
|
|
1451
|
+
this.itemList[index] = vl;
|
|
1452
|
+
this.items[key] = vl;
|
|
1453
|
+
return vl;
|
|
1454
|
+
}
|
|
1455
|
+
clear() {
|
|
1456
|
+
this.items = {};
|
|
1457
|
+
this.itemList = [];
|
|
1458
|
+
}
|
|
1459
|
+
del(key) {
|
|
1460
|
+
if (this.has(key)) {
|
|
1461
|
+
const index = this.items[key].index;
|
|
1462
|
+
if (index > -1) {
|
|
1463
|
+
this.itemList.splice(index, 1);
|
|
1464
|
+
}
|
|
1465
|
+
delete this.items[key];
|
|
1466
|
+
this.resetIndex();
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
delFrom(index) {
|
|
1470
|
+
for (let i = index + 1; i < this.count(); i++) {
|
|
1471
|
+
const key = this.itemList[i].key;
|
|
1472
|
+
delete this.items[key];
|
|
1473
|
+
}
|
|
1474
|
+
this.itemList.splice(index + 1, this.count() - index);
|
|
1475
|
+
this.resetIndex();
|
|
1476
|
+
}
|
|
1477
|
+
resetIndex() {
|
|
1478
|
+
this.foreachHashv((k, v) => {
|
|
1479
|
+
const index = this.itemList.indexOf(v);
|
|
1480
|
+
this.items[k].index = index;
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
has(key) {
|
|
1484
|
+
return key in this.items;
|
|
1485
|
+
}
|
|
1486
|
+
get(key) {
|
|
1487
|
+
if (this.has(key)) {
|
|
1488
|
+
return this.items[key].value;
|
|
1489
|
+
}
|
|
1490
|
+
return null;
|
|
1491
|
+
}
|
|
1492
|
+
count() {
|
|
1493
|
+
return this.itemList.length;
|
|
1494
|
+
}
|
|
1495
|
+
all() {
|
|
1496
|
+
return this.itemList.map(vl => {
|
|
1497
|
+
return vl.value;
|
|
1498
|
+
});
|
|
1499
|
+
}
|
|
1500
|
+
first() {
|
|
1501
|
+
return this.itemList[0].value;
|
|
1502
|
+
}
|
|
1503
|
+
last() {
|
|
1504
|
+
return this.itemList[this.itemList.length - 1].value;
|
|
1505
|
+
}
|
|
1506
|
+
getByIndex(index) {
|
|
1507
|
+
return this.itemList[index].value;
|
|
1508
|
+
}
|
|
1509
|
+
getKeyByIndex(index) {
|
|
1510
|
+
return this.itemList[index].key;
|
|
1511
|
+
}
|
|
1512
|
+
foreach(callback) {
|
|
1513
|
+
for (const key in this.items) {
|
|
1514
|
+
const returnVal = callback(key, this.items[key].value);
|
|
1515
|
+
if (returnVal === false) {
|
|
1516
|
+
return false;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
return true;
|
|
1520
|
+
}
|
|
1521
|
+
foreachHashv(callback) {
|
|
1522
|
+
for (const key in this.items) {
|
|
1523
|
+
const returnVal = callback(key, this.items[key]);
|
|
1524
|
+
if (returnVal === false) {
|
|
1525
|
+
return false;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
return true;
|
|
1529
|
+
}
|
|
1530
|
+
hasValue(value) {
|
|
1531
|
+
for (const key in this.items) {
|
|
1532
|
+
if (this.items[key].value === value) {
|
|
1533
|
+
return true;
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
return false;
|
|
1537
|
+
}
|
|
1538
|
+
indexOf(key) {
|
|
1539
|
+
if (this.has(key)) {
|
|
1540
|
+
return this.items[key].index;
|
|
1541
|
+
}
|
|
1542
|
+
return -1;
|
|
1543
|
+
}
|
|
1544
|
+
insertAt(index, value, key) {
|
|
1545
|
+
const hashV = new HashValue();
|
|
1546
|
+
hashV.index = index;
|
|
1547
|
+
hashV.key = key;
|
|
1548
|
+
hashV.value = value;
|
|
1549
|
+
this.itemList.splice(index, 0, hashV);
|
|
1550
|
+
this.items[key] = hashV;
|
|
1551
|
+
this.resetIndex();
|
|
1552
|
+
}
|
|
1553
|
+
sort(callback) {
|
|
1554
|
+
return this.itemList.sort((a, b) => {
|
|
1555
|
+
return callback(a.value, b.value);
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
toArray() {
|
|
1559
|
+
return this.itemList.slice(0, this.itemList.length).map(vl => {
|
|
1560
|
+
return vl.value;
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
push(lists) {
|
|
1564
|
+
lists.foreach((key, value) => {
|
|
1565
|
+
this.set(key, value);
|
|
1566
|
+
});
|
|
1567
|
+
}
|
|
1568
|
+
mapKey() {
|
|
1569
|
+
const returnArr = [];
|
|
1570
|
+
for (const key in this.items) {
|
|
1571
|
+
returnArr.push(key);
|
|
1572
|
+
}
|
|
1573
|
+
return returnArr;
|
|
1574
|
+
}
|
|
1575
|
+
toImmutableMap() {
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
const epsilon = 1e-12;
|
|
1580
|
+
const pi = Math.PI;
|
|
1581
|
+
const halfPi = pi / 2;
|
|
1582
|
+
const tau = 2 * pi;
|
|
1583
|
+
const NEWTON_ITERATIONS = 4;
|
|
1584
|
+
const NEWTON_MIN_SLOPE = 0.001;
|
|
1585
|
+
const SUBDIVISION_PRECISION = 0.0000001;
|
|
1586
|
+
const SUBDIVISION_MAX_ITERATIONS = 10;
|
|
1587
|
+
const pi2 = Math.PI * 2;
|
|
1588
|
+
const abs = Math.abs;
|
|
1589
|
+
const atan2 = Math.atan2;
|
|
1590
|
+
const cos = Math.cos;
|
|
1591
|
+
const max = Math.max;
|
|
1592
|
+
const min = Math.min;
|
|
1593
|
+
const sin = Math.sin;
|
|
1594
|
+
const sqrt = Math.sqrt;
|
|
1595
|
+
const pow = Math.pow;
|
|
1596
|
+
function acos(x) {
|
|
1597
|
+
return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);
|
|
1598
|
+
}
|
|
1599
|
+
function asin(x) {
|
|
1600
|
+
return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);
|
|
1601
|
+
}
|
|
1602
|
+
function pointAt(x1, y1, x2, y2, t) {
|
|
1603
|
+
let x;
|
|
1604
|
+
let y;
|
|
1605
|
+
if (typeof x1 === 'number' && typeof x2 === 'number') {
|
|
1606
|
+
x = (1 - t) * x1 + t * x2;
|
|
1607
|
+
}
|
|
1608
|
+
if (typeof y1 === 'number' && typeof y2 === 'number') {
|
|
1609
|
+
y = (1 - t) * y1 + t * y2;
|
|
1610
|
+
}
|
|
1611
|
+
return {
|
|
1612
|
+
x,
|
|
1613
|
+
y
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
function lengthFromPointToLine(point, point1, point2) {
|
|
1617
|
+
const dir1X = point2.x - point1.x;
|
|
1618
|
+
const dir1Y = point2.y - point1.y;
|
|
1619
|
+
const dir2X = point.x - point1.x;
|
|
1620
|
+
const dir2Y = point.y - point1.y;
|
|
1621
|
+
const s = Math.abs(dir1X * dir2Y - dir2X * dir1Y);
|
|
1622
|
+
const length = Math.sqrt(dir1X * dir1X + dir1Y * dir1Y);
|
|
1623
|
+
return s / length;
|
|
1624
|
+
}
|
|
1625
|
+
function crossProduct(dir1, dir2) {
|
|
1626
|
+
return dir1[0] * dir2[1] - dir1[1] * dir2[0];
|
|
1627
|
+
}
|
|
1628
|
+
function crossProductPoint(dir1, dir2) {
|
|
1629
|
+
return dir1.x * dir2.y - dir1.y * dir2.x;
|
|
1630
|
+
}
|
|
1631
|
+
function fuzzyEqualNumber(a, b) {
|
|
1632
|
+
return abs(a - b) < epsilon;
|
|
1633
|
+
}
|
|
1634
|
+
function fuzzyEqualVec(a, b) {
|
|
1635
|
+
return abs(a[0] - b[0]) + abs(a[1] - b[1]) < epsilon;
|
|
1636
|
+
}
|
|
1637
|
+
function fixPrecision(num, precision = 10) {
|
|
1638
|
+
return Math.round(num * precision) / precision;
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
class Point {
|
|
1642
|
+
x = 0;
|
|
1643
|
+
y = 0;
|
|
1644
|
+
x1;
|
|
1645
|
+
y1;
|
|
1646
|
+
defined;
|
|
1647
|
+
context;
|
|
1648
|
+
constructor(x = 0, y = 0, x1, y1) {
|
|
1649
|
+
this.x = x;
|
|
1650
|
+
this.y = y;
|
|
1651
|
+
this.x1 = x1;
|
|
1652
|
+
this.y1 = y1;
|
|
1653
|
+
}
|
|
1654
|
+
clone() {
|
|
1655
|
+
return new Point(this.x, this.y);
|
|
1656
|
+
}
|
|
1657
|
+
copyFrom(p) {
|
|
1658
|
+
this.x = p.x;
|
|
1659
|
+
this.y = p.y;
|
|
1660
|
+
this.x1 = p.x1;
|
|
1661
|
+
this.y1 = p.y1;
|
|
1662
|
+
this.defined = p.defined;
|
|
1663
|
+
this.context = p.context;
|
|
1664
|
+
return this;
|
|
1665
|
+
}
|
|
1666
|
+
set(x, y) {
|
|
1667
|
+
this.x = x;
|
|
1668
|
+
this.y = y;
|
|
1669
|
+
return this;
|
|
1670
|
+
}
|
|
1671
|
+
add(point) {
|
|
1672
|
+
if (isNumber(point)) {
|
|
1673
|
+
this.x += point;
|
|
1674
|
+
this.y += point;
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
this.x += point.x;
|
|
1678
|
+
this.y += point.y;
|
|
1679
|
+
return this;
|
|
1680
|
+
}
|
|
1681
|
+
sub(point) {
|
|
1682
|
+
if (isNumber(point)) {
|
|
1683
|
+
this.x -= point;
|
|
1684
|
+
this.y -= point;
|
|
1685
|
+
return;
|
|
1686
|
+
}
|
|
1687
|
+
this.x -= point.x;
|
|
1688
|
+
this.y -= point.y;
|
|
1689
|
+
return this;
|
|
1690
|
+
}
|
|
1691
|
+
multi(point) {
|
|
1692
|
+
throw new Error('暂不支持');
|
|
1693
|
+
}
|
|
1694
|
+
div(point) {
|
|
1695
|
+
throw new Error('暂不支持');
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
class PointService {
|
|
1699
|
+
static distancePP(p1, p2) {
|
|
1700
|
+
return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2));
|
|
1701
|
+
}
|
|
1702
|
+
static distanceNN(x, y, x1, y1) {
|
|
1703
|
+
return sqrt(pow(x - x1, 2) + pow(y - y1, 2));
|
|
1704
|
+
}
|
|
1705
|
+
static distancePN(point, x, y) {
|
|
1706
|
+
return sqrt(pow(x - point.x, 2) + pow(y - point.y, 2));
|
|
1707
|
+
}
|
|
1708
|
+
static pointAtPP(p1, p2, t) {
|
|
1709
|
+
return new Point((p2.x - p1.x) * t + p1.x, (p2.y - p1.y) * t + p1.y);
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
class PolarPoint {
|
|
1713
|
+
r = 0;
|
|
1714
|
+
theta = 0;
|
|
1715
|
+
r1;
|
|
1716
|
+
theta1;
|
|
1717
|
+
defined;
|
|
1718
|
+
context;
|
|
1719
|
+
constructor(r = 0, theta = 0, r1, theta1) {
|
|
1720
|
+
this.r = r;
|
|
1721
|
+
this.theta = theta;
|
|
1722
|
+
this.r1 = r1;
|
|
1723
|
+
this.theta1 = theta1;
|
|
1724
|
+
}
|
|
1725
|
+
clone() {
|
|
1726
|
+
return new PolarPoint(this.r, this.theta);
|
|
1727
|
+
}
|
|
1728
|
+
copyFrom(p) {
|
|
1729
|
+
this.r = p.r;
|
|
1730
|
+
this.theta = p.theta;
|
|
1731
|
+
this.r1 = p.r1;
|
|
1732
|
+
this.theta1 = p.theta1;
|
|
1733
|
+
this.defined = p.defined;
|
|
1734
|
+
this.context = p.context;
|
|
1735
|
+
return this;
|
|
1736
|
+
}
|
|
1737
|
+
set(r, theta) {
|
|
1738
|
+
this.r = r;
|
|
1739
|
+
this.theta = theta;
|
|
1740
|
+
return this;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
function transformBoundsWithMatrix(out, bounds, matrix) {
|
|
1745
|
+
const { x1, y1, x2, y2 } = bounds;
|
|
1746
|
+
if (matrix.onlyTranslate()) {
|
|
1747
|
+
if (out !== bounds) {
|
|
1748
|
+
out.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2);
|
|
1749
|
+
}
|
|
1750
|
+
out.translate(matrix.e, matrix.f);
|
|
1751
|
+
return bounds;
|
|
1752
|
+
}
|
|
1753
|
+
out.clear();
|
|
1754
|
+
out.add(matrix.a * x1 + matrix.c * y1 + matrix.e, matrix.b * x1 + matrix.d * y1 + matrix.f);
|
|
1755
|
+
out.add(matrix.a * x2 + matrix.c * y1 + matrix.e, matrix.b * x2 + matrix.d * y1 + matrix.f);
|
|
1756
|
+
out.add(matrix.a * x2 + matrix.c * y2 + matrix.e, matrix.b * x2 + matrix.d * y2 + matrix.f);
|
|
1757
|
+
out.add(matrix.a * x1 + matrix.c * y2 + matrix.e, matrix.b * x1 + matrix.d * y2 + matrix.f);
|
|
1758
|
+
return bounds;
|
|
1759
|
+
}
|
|
1760
|
+
function transformBounds(bounds, x, y, scaleX, scaleY, angle, rotateCenter) {
|
|
1761
|
+
if (abs(scaleX) <= epsilon || abs(scaleY) <= epsilon) {
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
scaleX !== 1 && bounds.scaleX(scaleX);
|
|
1765
|
+
scaleY !== 1 && bounds.scaleY(scaleY);
|
|
1766
|
+
if (isFinite(angle) && Math.abs(angle) > epsilon) {
|
|
1767
|
+
let rx = 0;
|
|
1768
|
+
let ry = 0;
|
|
1769
|
+
if (rotateCenter !== undefined) {
|
|
1770
|
+
rx = rotateCenter[0];
|
|
1771
|
+
ry = rotateCenter[1];
|
|
1772
|
+
}
|
|
1773
|
+
bounds.rotate(angle, rx, ry);
|
|
1774
|
+
}
|
|
1775
|
+
bounds.translate(x, y);
|
|
1776
|
+
}
|
|
1777
|
+
class Bounds {
|
|
1778
|
+
x1;
|
|
1779
|
+
y1;
|
|
1780
|
+
x2;
|
|
1781
|
+
y2;
|
|
1782
|
+
constructor(bounds) {
|
|
1783
|
+
if (bounds) {
|
|
1784
|
+
this.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2);
|
|
1785
|
+
}
|
|
1786
|
+
else {
|
|
1787
|
+
this.clear();
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
clone() {
|
|
1791
|
+
return new Bounds(this);
|
|
1792
|
+
}
|
|
1793
|
+
clear() {
|
|
1794
|
+
this.x1 = +Number.MAX_VALUE;
|
|
1795
|
+
this.y1 = +Number.MAX_VALUE;
|
|
1796
|
+
this.x2 = -Number.MAX_VALUE;
|
|
1797
|
+
this.y2 = -Number.MAX_VALUE;
|
|
1798
|
+
return this;
|
|
1799
|
+
}
|
|
1800
|
+
empty() {
|
|
1801
|
+
return (this.x1 === +Number.MAX_VALUE &&
|
|
1802
|
+
this.y1 === +Number.MAX_VALUE &&
|
|
1803
|
+
this.x2 === -Number.MAX_VALUE &&
|
|
1804
|
+
this.y2 === -Number.MAX_VALUE);
|
|
1805
|
+
}
|
|
1806
|
+
equals(b) {
|
|
1807
|
+
return this.x1 === b.x1 && this.y1 === b.y1 && this.x2 === b.x2 && this.y2 === b.y2;
|
|
1808
|
+
}
|
|
1809
|
+
setValue(x1 = 0, y1 = 0, x2 = 0, y2 = 0) {
|
|
1810
|
+
this.x1 = x1;
|
|
1811
|
+
this.y1 = y1;
|
|
1812
|
+
this.x2 = x2;
|
|
1813
|
+
this.y2 = y2;
|
|
1814
|
+
return this;
|
|
1815
|
+
}
|
|
1816
|
+
set(x1 = 0, y1 = 0, x2 = 0, y2 = 0) {
|
|
1817
|
+
if (x2 < x1) {
|
|
1818
|
+
this.x2 = x1;
|
|
1819
|
+
this.x1 = x2;
|
|
1820
|
+
}
|
|
1821
|
+
else {
|
|
1822
|
+
this.x1 = x1;
|
|
1823
|
+
this.x2 = x2;
|
|
1824
|
+
}
|
|
1825
|
+
if (y2 < y1) {
|
|
1826
|
+
this.y2 = y1;
|
|
1827
|
+
this.y1 = y2;
|
|
1828
|
+
}
|
|
1829
|
+
else {
|
|
1830
|
+
this.y1 = y1;
|
|
1831
|
+
this.y2 = y2;
|
|
1832
|
+
}
|
|
1833
|
+
return this;
|
|
1834
|
+
}
|
|
1835
|
+
add(x = 0, y = 0) {
|
|
1836
|
+
if (x < this.x1) {
|
|
1837
|
+
this.x1 = x;
|
|
1838
|
+
}
|
|
1839
|
+
if (y < this.y1) {
|
|
1840
|
+
this.y1 = y;
|
|
1841
|
+
}
|
|
1842
|
+
if (x > this.x2) {
|
|
1843
|
+
this.x2 = x;
|
|
1844
|
+
}
|
|
1845
|
+
if (y > this.y2) {
|
|
1846
|
+
this.y2 = y;
|
|
1847
|
+
}
|
|
1848
|
+
return this;
|
|
1849
|
+
}
|
|
1850
|
+
expand(d = 0) {
|
|
1851
|
+
if (isArray(d)) {
|
|
1852
|
+
this.y1 -= d[0];
|
|
1853
|
+
this.x2 += d[1];
|
|
1854
|
+
this.y2 += d[2];
|
|
1855
|
+
this.x1 -= d[3];
|
|
1856
|
+
}
|
|
1857
|
+
else {
|
|
1858
|
+
this.x1 -= d;
|
|
1859
|
+
this.y1 -= d;
|
|
1860
|
+
this.x2 += d;
|
|
1861
|
+
this.y2 += d;
|
|
1862
|
+
}
|
|
1863
|
+
return this;
|
|
1864
|
+
}
|
|
1865
|
+
round() {
|
|
1866
|
+
this.x1 = Math.floor(this.x1);
|
|
1867
|
+
this.y1 = Math.floor(this.y1);
|
|
1868
|
+
this.x2 = Math.ceil(this.x2);
|
|
1869
|
+
this.y2 = Math.ceil(this.y2);
|
|
1870
|
+
return this;
|
|
1871
|
+
}
|
|
1872
|
+
translate(dx = 0, dy = 0) {
|
|
1873
|
+
this.x1 += dx;
|
|
1874
|
+
this.x2 += dx;
|
|
1875
|
+
this.y1 += dy;
|
|
1876
|
+
this.y2 += dy;
|
|
1877
|
+
return this;
|
|
1878
|
+
}
|
|
1879
|
+
rotate(angle = 0, x = 0, y = 0) {
|
|
1880
|
+
const p = this.rotatedPoints(angle, x, y);
|
|
1881
|
+
return this.clear().add(p[0], p[1]).add(p[2], p[3]).add(p[4], p[5]).add(p[6], p[7]);
|
|
1882
|
+
}
|
|
1883
|
+
scale(sx = 0, sy = 0, x = 0, y = 0) {
|
|
1884
|
+
const p = this.scalePoints(sx, sy, x, y);
|
|
1885
|
+
return this.clear().add(p[0], p[1]).add(p[2], p[3]);
|
|
1886
|
+
}
|
|
1887
|
+
union(b) {
|
|
1888
|
+
if (b.x1 < this.x1) {
|
|
1889
|
+
this.x1 = b.x1;
|
|
1890
|
+
}
|
|
1891
|
+
if (b.y1 < this.y1) {
|
|
1892
|
+
this.y1 = b.y1;
|
|
1893
|
+
}
|
|
1894
|
+
if (b.x2 > this.x2) {
|
|
1895
|
+
this.x2 = b.x2;
|
|
1896
|
+
}
|
|
1897
|
+
if (b.y2 > this.y2) {
|
|
1898
|
+
this.y2 = b.y2;
|
|
1899
|
+
}
|
|
1900
|
+
return this;
|
|
1901
|
+
}
|
|
1902
|
+
intersect(b) {
|
|
1903
|
+
if (b.x1 > this.x1) {
|
|
1904
|
+
this.x1 = b.x1;
|
|
1905
|
+
}
|
|
1906
|
+
if (b.y1 > this.y1) {
|
|
1907
|
+
this.y1 = b.y1;
|
|
1908
|
+
}
|
|
1909
|
+
if (b.x2 < this.x2) {
|
|
1910
|
+
this.x2 = b.x2;
|
|
1911
|
+
}
|
|
1912
|
+
if (b.y2 < this.y2) {
|
|
1913
|
+
this.y2 = b.y2;
|
|
1914
|
+
}
|
|
1915
|
+
return this;
|
|
1916
|
+
}
|
|
1917
|
+
encloses(b) {
|
|
1918
|
+
return b && this.x1 <= b.x1 && this.x2 >= b.x2 && this.y1 <= b.y1 && this.y2 >= b.y2;
|
|
1919
|
+
}
|
|
1920
|
+
alignsWith(b) {
|
|
1921
|
+
return b && (this.x1 === b.x1 || this.x2 === b.x2 || this.y1 === b.y1 || this.y2 === b.y2);
|
|
1922
|
+
}
|
|
1923
|
+
intersects(b) {
|
|
1924
|
+
return b && !(this.x2 < b.x1 || this.x1 > b.x2 || this.y2 < b.y1 || this.y1 > b.y2);
|
|
1925
|
+
}
|
|
1926
|
+
contains(x = 0, y = 0) {
|
|
1927
|
+
return !(x < this.x1 || x > this.x2 || y < this.y1 || y > this.y2);
|
|
1928
|
+
}
|
|
1929
|
+
containsPoint(p) {
|
|
1930
|
+
return !(p.x < this.x1 || p.x > this.x2 || p.y < this.y1 || p.y > this.y2);
|
|
1931
|
+
}
|
|
1932
|
+
width() {
|
|
1933
|
+
if (this.empty()) {
|
|
1934
|
+
return 0;
|
|
1935
|
+
}
|
|
1936
|
+
return this.x2 - this.x1;
|
|
1937
|
+
}
|
|
1938
|
+
height() {
|
|
1939
|
+
if (this.empty()) {
|
|
1940
|
+
return 0;
|
|
1941
|
+
}
|
|
1942
|
+
return this.y2 - this.y1;
|
|
1943
|
+
}
|
|
1944
|
+
scaleX(s = 0) {
|
|
1945
|
+
this.x1 *= s;
|
|
1946
|
+
this.x2 *= s;
|
|
1947
|
+
return this;
|
|
1948
|
+
}
|
|
1949
|
+
scaleY(s = 0) {
|
|
1950
|
+
this.y1 *= s;
|
|
1951
|
+
this.y2 *= s;
|
|
1952
|
+
return this;
|
|
1953
|
+
}
|
|
1954
|
+
transformWithMatrix(matrix) {
|
|
1955
|
+
transformBoundsWithMatrix(this, this, matrix);
|
|
1956
|
+
return this;
|
|
1957
|
+
}
|
|
1958
|
+
copy(b) {
|
|
1959
|
+
this.x1 = b.x1;
|
|
1960
|
+
this.y1 = b.y1;
|
|
1961
|
+
this.x2 = b.x2;
|
|
1962
|
+
this.y2 = b.y2;
|
|
1963
|
+
return this;
|
|
1964
|
+
}
|
|
1965
|
+
rotatedPoints(angle, x, y) {
|
|
1966
|
+
const { x1, y1, x2, y2 } = this;
|
|
1967
|
+
const cos = Math.cos(angle);
|
|
1968
|
+
const sin = Math.sin(angle);
|
|
1969
|
+
const cx = x - x * cos + y * sin;
|
|
1970
|
+
const cy = y - x * sin - y * cos;
|
|
1971
|
+
return [
|
|
1972
|
+
cos * x1 - sin * y1 + cx,
|
|
1973
|
+
sin * x1 + cos * y1 + cy,
|
|
1974
|
+
cos * x1 - sin * y2 + cx,
|
|
1975
|
+
sin * x1 + cos * y2 + cy,
|
|
1976
|
+
cos * x2 - sin * y1 + cx,
|
|
1977
|
+
sin * x2 + cos * y1 + cy,
|
|
1978
|
+
cos * x2 - sin * y2 + cx,
|
|
1979
|
+
sin * x2 + cos * y2 + cy
|
|
1980
|
+
];
|
|
1981
|
+
}
|
|
1982
|
+
scalePoints(sx, sy, x, y) {
|
|
1983
|
+
const { x1, y1, x2, y2 } = this;
|
|
1984
|
+
return [sx * x1 + (1 - sx) * x, sy * y1 + (1 - sy) * y, sx * x2 + (1 - sx) * x, sy * y2 + (1 - sy) * y];
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
class AABBBounds extends Bounds {
|
|
1988
|
+
}
|
|
1989
|
+
class OBBBounds extends Bounds {
|
|
1990
|
+
angle;
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
function degreeToRadian(degree) {
|
|
1994
|
+
return degree * (Math.PI / 180);
|
|
1995
|
+
}
|
|
1996
|
+
function radianToDegree(radian) {
|
|
1997
|
+
return (radian * 180) / Math.PI;
|
|
1998
|
+
}
|
|
1999
|
+
const clampRadian = (angle = 0) => {
|
|
2000
|
+
if (angle < 0) {
|
|
2001
|
+
while (angle < -tau) {
|
|
2002
|
+
angle += tau;
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
else if (angle > 0) {
|
|
2006
|
+
while (angle > tau) {
|
|
2007
|
+
angle -= tau;
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
return angle;
|
|
2011
|
+
};
|
|
2012
|
+
const clampAngleByRadian = clampRadian;
|
|
2013
|
+
const clampDegree = (a = 0) => {
|
|
2014
|
+
if (a > 360 || a < -360) {
|
|
2015
|
+
return a % 360;
|
|
2016
|
+
}
|
|
2017
|
+
return a;
|
|
2018
|
+
};
|
|
2019
|
+
const clampAngleByDegree = clampDegree;
|
|
2020
|
+
function polarToCartesian(center, radius, angleInRadian) {
|
|
2021
|
+
return {
|
|
2022
|
+
x: center.x + radius * Math.cos(angleInRadian),
|
|
2023
|
+
y: center.y + radius * Math.sin(angleInRadian)
|
|
2024
|
+
};
|
|
2025
|
+
}
|
|
2026
|
+
function getAngleByPoint(center, point) {
|
|
2027
|
+
return Math.atan2(point.y - center.y, point.x - center.x);
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
class Matrix {
|
|
2031
|
+
a;
|
|
2032
|
+
b;
|
|
2033
|
+
c;
|
|
2034
|
+
d;
|
|
2035
|
+
e;
|
|
2036
|
+
f;
|
|
2037
|
+
constructor(a = 1, b = 0, c = 0, d = 1, e = 0, f = 0) {
|
|
2038
|
+
this.a = a;
|
|
2039
|
+
this.b = b;
|
|
2040
|
+
this.c = c;
|
|
2041
|
+
this.d = d;
|
|
2042
|
+
this.e = e;
|
|
2043
|
+
this.f = f;
|
|
2044
|
+
}
|
|
2045
|
+
equalToMatrix(m2) {
|
|
2046
|
+
return !(this.e !== m2.e ||
|
|
2047
|
+
this.f !== m2.f ||
|
|
2048
|
+
this.a !== m2.a ||
|
|
2049
|
+
this.d !== m2.d ||
|
|
2050
|
+
this.b !== m2.b ||
|
|
2051
|
+
this.c !== m2.c);
|
|
2052
|
+
}
|
|
2053
|
+
equalTo(a, b, c, d, e, f) {
|
|
2054
|
+
return !(this.e !== e || this.f !== f || this.a !== a || this.d !== d || this.b !== b || this.c !== c);
|
|
2055
|
+
}
|
|
2056
|
+
setValue(a, b, c, d, e, f) {
|
|
2057
|
+
this.a = a;
|
|
2058
|
+
this.b = b;
|
|
2059
|
+
this.c = c;
|
|
2060
|
+
this.d = d;
|
|
2061
|
+
this.e = e;
|
|
2062
|
+
this.f = f;
|
|
2063
|
+
return this;
|
|
2064
|
+
}
|
|
2065
|
+
reset() {
|
|
2066
|
+
this.a = 1;
|
|
2067
|
+
this.b = 0;
|
|
2068
|
+
this.c = 0;
|
|
2069
|
+
this.d = 1;
|
|
2070
|
+
this.e = 0;
|
|
2071
|
+
this.f = 0;
|
|
2072
|
+
return this;
|
|
2073
|
+
}
|
|
2074
|
+
getInverse() {
|
|
2075
|
+
const a = this.a;
|
|
2076
|
+
const b = this.b;
|
|
2077
|
+
const c = this.c;
|
|
2078
|
+
const d = this.d;
|
|
2079
|
+
const e = this.e;
|
|
2080
|
+
const f = this.f;
|
|
2081
|
+
const m = new Matrix();
|
|
2082
|
+
const dt = a * d - b * c;
|
|
2083
|
+
m.a = d / dt;
|
|
2084
|
+
m.b = -b / dt;
|
|
2085
|
+
m.c = -c / dt;
|
|
2086
|
+
m.d = a / dt;
|
|
2087
|
+
m.e = (c * f - d * e) / dt;
|
|
2088
|
+
m.f = -(a * f - b * e) / dt;
|
|
2089
|
+
return m;
|
|
2090
|
+
}
|
|
2091
|
+
rotate(rad) {
|
|
2092
|
+
const c = Math.cos(rad);
|
|
2093
|
+
const s = Math.sin(rad);
|
|
2094
|
+
const m11 = this.a * c + this.c * s;
|
|
2095
|
+
const m12 = this.b * c + this.d * s;
|
|
2096
|
+
const m21 = this.a * -s + this.c * c;
|
|
2097
|
+
const m22 = this.b * -s + this.d * c;
|
|
2098
|
+
this.a = m11;
|
|
2099
|
+
this.b = m12;
|
|
2100
|
+
this.c = m21;
|
|
2101
|
+
this.d = m22;
|
|
2102
|
+
return this;
|
|
2103
|
+
}
|
|
2104
|
+
rotateByCenter(rad, cx, cy) {
|
|
2105
|
+
const cos = Math.cos(rad);
|
|
2106
|
+
const sin = Math.sin(rad);
|
|
2107
|
+
const rotateM13 = (1 - cos) * cx + sin * cy;
|
|
2108
|
+
const rotateM23 = (1 - cos) * cy - sin * cx;
|
|
2109
|
+
const m11 = cos * this.a - sin * this.b;
|
|
2110
|
+
const m21 = sin * this.a + cos * this.b;
|
|
2111
|
+
const m12 = cos * this.c - sin * this.d;
|
|
2112
|
+
const m22 = sin * this.c + cos * this.d;
|
|
2113
|
+
const m13 = cos * this.e - sin * this.f + rotateM13;
|
|
2114
|
+
const m23 = sin * this.e + cos * this.f + rotateM23;
|
|
2115
|
+
this.a = m11;
|
|
2116
|
+
this.b = m21;
|
|
2117
|
+
this.c = m12;
|
|
2118
|
+
this.d = m22;
|
|
2119
|
+
this.e = m13;
|
|
2120
|
+
this.f = m23;
|
|
2121
|
+
return this;
|
|
2122
|
+
}
|
|
2123
|
+
scale(sx, sy) {
|
|
2124
|
+
this.a *= sx;
|
|
2125
|
+
this.b *= sx;
|
|
2126
|
+
this.c *= sy;
|
|
2127
|
+
this.d *= sy;
|
|
2128
|
+
return this;
|
|
2129
|
+
}
|
|
2130
|
+
setScale(sx, sy) {
|
|
2131
|
+
this.b = (this.b / this.a) * sx;
|
|
2132
|
+
this.c = (this.c / this.d) * sy;
|
|
2133
|
+
this.a = sx;
|
|
2134
|
+
this.d = sy;
|
|
2135
|
+
return this;
|
|
2136
|
+
}
|
|
2137
|
+
transform(a, b, c, d, e, f) {
|
|
2138
|
+
this.multiply(a, b, c, d, e, f);
|
|
2139
|
+
return this;
|
|
2140
|
+
}
|
|
2141
|
+
translate(x, y) {
|
|
2142
|
+
this.e += this.a * x + this.c * y;
|
|
2143
|
+
this.f += this.b * x + this.d * y;
|
|
2144
|
+
return this;
|
|
2145
|
+
}
|
|
2146
|
+
transpose() {
|
|
2147
|
+
const { a, b, c, d, e, f } = this;
|
|
2148
|
+
this.a = b;
|
|
2149
|
+
this.b = a;
|
|
2150
|
+
this.c = d;
|
|
2151
|
+
this.d = c;
|
|
2152
|
+
this.e = f;
|
|
2153
|
+
this.f = e;
|
|
2154
|
+
return this;
|
|
2155
|
+
}
|
|
2156
|
+
multiply(a2, b2, c2, d2, e2, f2) {
|
|
2157
|
+
const a1 = this.a;
|
|
2158
|
+
const b1 = this.b;
|
|
2159
|
+
const c1 = this.c;
|
|
2160
|
+
const d1 = this.d;
|
|
2161
|
+
const e1 = this.e;
|
|
2162
|
+
const f1 = this.f;
|
|
2163
|
+
const m11 = a1 * a2 + c1 * b2;
|
|
2164
|
+
const m12 = b1 * a2 + d1 * b2;
|
|
2165
|
+
const m21 = a1 * c2 + c1 * d2;
|
|
2166
|
+
const m22 = b1 * c2 + d1 * d2;
|
|
2167
|
+
const dx = a1 * e2 + c1 * f2 + e1;
|
|
2168
|
+
const dy = b1 * e2 + d1 * f2 + f1;
|
|
2169
|
+
this.a = m11;
|
|
2170
|
+
this.b = m12;
|
|
2171
|
+
this.c = m21;
|
|
2172
|
+
this.d = m22;
|
|
2173
|
+
this.e = dx;
|
|
2174
|
+
this.f = dy;
|
|
2175
|
+
return this;
|
|
2176
|
+
}
|
|
2177
|
+
interpolate(m2, t) {
|
|
2178
|
+
const m = new Matrix();
|
|
2179
|
+
m.a = this.a + (m2.a - this.a) * t;
|
|
2180
|
+
m.b = this.b + (m2.b - this.b) * t;
|
|
2181
|
+
m.c = this.c + (m2.c - this.c) * t;
|
|
2182
|
+
m.d = this.d + (m2.d - this.d) * t;
|
|
2183
|
+
m.e = this.e + (m2.e - this.e) * t;
|
|
2184
|
+
m.f = this.f + (m2.f - this.f) * t;
|
|
2185
|
+
return m;
|
|
2186
|
+
}
|
|
2187
|
+
transformPoint(source, target) {
|
|
2188
|
+
const { a, b, c, d, e, f } = this;
|
|
2189
|
+
const dt = a * d - b * c;
|
|
2190
|
+
const nextA = d / dt;
|
|
2191
|
+
const nextB = -b / dt;
|
|
2192
|
+
const nextC = -c / dt;
|
|
2193
|
+
const nextD = a / dt;
|
|
2194
|
+
const nextE = (c * f - d * e) / dt;
|
|
2195
|
+
const nextF = -(a * f - b * e) / dt;
|
|
2196
|
+
const { x, y } = source;
|
|
2197
|
+
target.x = x * nextA + y * nextC + nextE;
|
|
2198
|
+
target.y = x * nextB + y * nextD + nextF;
|
|
2199
|
+
}
|
|
2200
|
+
onlyTranslate(scale = 1) {
|
|
2201
|
+
return this.a === scale && this.b === 0 && this.c === 0 && this.d === scale;
|
|
2202
|
+
}
|
|
2203
|
+
clone() {
|
|
2204
|
+
return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
|
|
2205
|
+
}
|
|
2206
|
+
toTransformAttrs() {
|
|
2207
|
+
const a = this.a;
|
|
2208
|
+
const b = this.b;
|
|
2209
|
+
const c = this.c;
|
|
2210
|
+
const d = this.d;
|
|
2211
|
+
const e = this.e;
|
|
2212
|
+
const f = this.f;
|
|
2213
|
+
const delta = a * d - b * c;
|
|
2214
|
+
const result = {
|
|
2215
|
+
x: e,
|
|
2216
|
+
y: f,
|
|
2217
|
+
rotateDeg: 0,
|
|
2218
|
+
scaleX: 0,
|
|
2219
|
+
scaleY: 0,
|
|
2220
|
+
skewX: 0,
|
|
2221
|
+
skewY: 0
|
|
2222
|
+
};
|
|
2223
|
+
if (a !== 0 || b !== 0) {
|
|
2224
|
+
const r = Math.sqrt(a * a + b * b);
|
|
2225
|
+
result.rotateDeg = b > 0 ? Math.acos(a / r) : -Math.acos(a / r);
|
|
2226
|
+
result.scaleX = r;
|
|
2227
|
+
result.scaleY = delta / r;
|
|
2228
|
+
result.skewX = (a * c + b * d) / delta;
|
|
2229
|
+
result.skewY = 0;
|
|
2230
|
+
}
|
|
2231
|
+
else if (c !== 0 || d !== 0) {
|
|
2232
|
+
const s = Math.sqrt(c * c + d * d);
|
|
2233
|
+
result.rotateDeg = Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s));
|
|
2234
|
+
result.scaleX = delta / s;
|
|
2235
|
+
result.scaleY = s;
|
|
2236
|
+
result.skewX = 0;
|
|
2237
|
+
result.skewY = (a * c + b * d) / delta;
|
|
2238
|
+
}
|
|
2239
|
+
else ;
|
|
2240
|
+
result.rotateDeg = radianToDegree(result.rotateDeg);
|
|
2241
|
+
return result;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
function normalTransform(out, origin, x, y, scaleX, scaleY, angle, rotateCenter) {
|
|
2245
|
+
const oa = origin.a;
|
|
2246
|
+
const ob = origin.b;
|
|
2247
|
+
const oc = origin.c;
|
|
2248
|
+
const od = origin.d;
|
|
2249
|
+
const oe = origin.e;
|
|
2250
|
+
const of = origin.f;
|
|
2251
|
+
const cosTheta = cos(angle);
|
|
2252
|
+
const sinTheta = sin(angle);
|
|
2253
|
+
let rotateCenterX;
|
|
2254
|
+
let rotateCenterY;
|
|
2255
|
+
if (rotateCenter) {
|
|
2256
|
+
rotateCenterX = rotateCenter[0];
|
|
2257
|
+
rotateCenterY = rotateCenter[1];
|
|
2258
|
+
}
|
|
2259
|
+
else {
|
|
2260
|
+
rotateCenterX = x;
|
|
2261
|
+
rotateCenterY = y;
|
|
2262
|
+
}
|
|
2263
|
+
const offsetX = rotateCenterX - x;
|
|
2264
|
+
const offsetY = rotateCenterY - y;
|
|
2265
|
+
const a1 = oa * cosTheta + oc * sinTheta;
|
|
2266
|
+
const b1 = ob * cosTheta + od * sinTheta;
|
|
2267
|
+
const c1 = oc * cosTheta - oa * sinTheta;
|
|
2268
|
+
const d1 = od * cosTheta - ob * sinTheta;
|
|
2269
|
+
out.a = scaleX * a1;
|
|
2270
|
+
out.b = scaleX * b1;
|
|
2271
|
+
out.c = scaleY * c1;
|
|
2272
|
+
out.d = scaleY * d1;
|
|
2273
|
+
out.e = oe + oa * rotateCenterX + oc * rotateCenterY - a1 * offsetX - c1 * offsetY;
|
|
2274
|
+
out.f = of + ob * rotateCenterX + od * rotateCenterY - b1 * offsetX - d1 * offsetY;
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
class LRU {
|
|
2278
|
+
static CLEAN_THRESHOLD = 1e3;
|
|
2279
|
+
static L_TIME = 1000;
|
|
2280
|
+
static R_COUNT = 1;
|
|
2281
|
+
static R_TIMESTAMP_MAX_SIZE = 20;
|
|
2282
|
+
static clearCache(cache, params) {
|
|
2283
|
+
const { CLEAN_THRESHOLD = LRU.CLEAN_THRESHOLD, L_TIME = LRU.L_TIME, R_COUNT = LRU.R_COUNT } = params;
|
|
2284
|
+
if (cache.size < CLEAN_THRESHOLD) {
|
|
2285
|
+
return 0;
|
|
2286
|
+
}
|
|
2287
|
+
let clearNum = 0;
|
|
2288
|
+
const clear = (key) => {
|
|
2289
|
+
clearNum++;
|
|
2290
|
+
cache.delete(key);
|
|
2291
|
+
};
|
|
2292
|
+
const now = Date.now();
|
|
2293
|
+
cache.forEach((item, key) => {
|
|
2294
|
+
if (item.timestamp.length < R_COUNT) {
|
|
2295
|
+
return clear(key);
|
|
2296
|
+
}
|
|
2297
|
+
let useCount = 0;
|
|
2298
|
+
while (now - item.timestamp[item.timestamp.length - 1 - useCount] < L_TIME) {
|
|
2299
|
+
useCount++;
|
|
2300
|
+
if (useCount >= R_COUNT) {
|
|
2301
|
+
break;
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
if (useCount < R_COUNT) {
|
|
2305
|
+
return clear(key);
|
|
2306
|
+
}
|
|
2307
|
+
while (now - item.timestamp[0] > L_TIME) {
|
|
2308
|
+
item.timestamp.shift();
|
|
2309
|
+
}
|
|
2310
|
+
return;
|
|
2311
|
+
});
|
|
2312
|
+
return clearNum;
|
|
2313
|
+
}
|
|
2314
|
+
static addLimitedTimestamp(cacheItem, t, params) {
|
|
2315
|
+
const { R_TIMESTAMP_MAX_SIZE = LRU.R_TIMESTAMP_MAX_SIZE } = params;
|
|
2316
|
+
if (cacheItem.timestamp.length > R_TIMESTAMP_MAX_SIZE) {
|
|
2317
|
+
cacheItem.timestamp.shift();
|
|
2318
|
+
}
|
|
2319
|
+
cacheItem.timestamp.push(t);
|
|
2320
|
+
}
|
|
2321
|
+
static clearTimeStamp(cache, params) {
|
|
2322
|
+
const { L_TIME = LRU.L_TIME } = params;
|
|
2323
|
+
const now = Date.now();
|
|
2324
|
+
cache.forEach(item => {
|
|
2325
|
+
while (now - item.timestamp[0] > L_TIME) {
|
|
2326
|
+
item.timestamp.shift();
|
|
2327
|
+
}
|
|
2328
|
+
});
|
|
2329
|
+
}
|
|
2330
|
+
static clearItemTimestamp(cacheItem, params) {
|
|
2331
|
+
const { L_TIME = LRU.L_TIME } = params;
|
|
2332
|
+
const now = Date.now();
|
|
2333
|
+
while (now - cacheItem.timestamp[0] > L_TIME) {
|
|
2334
|
+
cacheItem.timestamp.shift();
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
function hslToRgb(h, s, l) {
|
|
2340
|
+
s /= 100;
|
|
2341
|
+
l /= 100;
|
|
2342
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
2343
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
2344
|
+
const m = l - c / 2;
|
|
2345
|
+
let r = 0;
|
|
2346
|
+
let g = 0;
|
|
2347
|
+
let b = 0;
|
|
2348
|
+
if (0 <= h && h < 60) {
|
|
2349
|
+
r = c;
|
|
2350
|
+
g = x;
|
|
2351
|
+
b = 0;
|
|
2352
|
+
}
|
|
2353
|
+
else if (60 <= h && h < 120) {
|
|
2354
|
+
r = x;
|
|
2355
|
+
g = c;
|
|
2356
|
+
b = 0;
|
|
2357
|
+
}
|
|
2358
|
+
else if (120 <= h && h < 180) {
|
|
2359
|
+
r = 0;
|
|
2360
|
+
g = c;
|
|
2361
|
+
b = x;
|
|
2362
|
+
}
|
|
2363
|
+
else if (180 <= h && h < 240) {
|
|
2364
|
+
r = 0;
|
|
2365
|
+
g = x;
|
|
2366
|
+
b = c;
|
|
2367
|
+
}
|
|
2368
|
+
else if (240 <= h && h < 300) {
|
|
2369
|
+
r = x;
|
|
2370
|
+
g = 0;
|
|
2371
|
+
b = c;
|
|
2372
|
+
}
|
|
2373
|
+
else if (300 <= h && h < 360) {
|
|
2374
|
+
r = c;
|
|
2375
|
+
g = 0;
|
|
2376
|
+
b = x;
|
|
2377
|
+
}
|
|
2378
|
+
r = Math.round((r + m) * 255);
|
|
2379
|
+
g = Math.round((g + m) * 255);
|
|
2380
|
+
b = Math.round((b + m) * 255);
|
|
2381
|
+
return { r, g, b };
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
function rgbToHsl(r, g, b) {
|
|
2385
|
+
r /= 255;
|
|
2386
|
+
g /= 255;
|
|
2387
|
+
b /= 255;
|
|
2388
|
+
const cMin = Math.min(r, g, b);
|
|
2389
|
+
const cMax = Math.max(r, g, b);
|
|
2390
|
+
const delta = cMax - cMin;
|
|
2391
|
+
let h = 0;
|
|
2392
|
+
let s = 0;
|
|
2393
|
+
let l = 0;
|
|
2394
|
+
if (delta === 0) {
|
|
2395
|
+
h = 0;
|
|
2396
|
+
}
|
|
2397
|
+
else if (cMax === r) {
|
|
2398
|
+
h = ((g - b) / delta) % 6;
|
|
2399
|
+
}
|
|
2400
|
+
else if (cMax === g) {
|
|
2401
|
+
h = (b - r) / delta + 2;
|
|
2402
|
+
}
|
|
2403
|
+
else {
|
|
2404
|
+
h = (r - g) / delta + 4;
|
|
2405
|
+
}
|
|
2406
|
+
h = Math.round(h * 60);
|
|
2407
|
+
if (h < 0) {
|
|
2408
|
+
h += 360;
|
|
2409
|
+
}
|
|
2410
|
+
l = (cMax + cMin) / 2;
|
|
2411
|
+
s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
|
|
2412
|
+
s = +(s * 100).toFixed(1);
|
|
2413
|
+
l = +(l * 100).toFixed(1);
|
|
2414
|
+
return {
|
|
2415
|
+
h,
|
|
2416
|
+
s,
|
|
2417
|
+
l
|
|
2418
|
+
};
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
const REG_HEX = /^#([0-9a-f]{3,8})$/;
|
|
2422
|
+
const DEFAULT_COLORS_OPACITY = {
|
|
2423
|
+
transparent: 0xffffff00
|
|
2424
|
+
};
|
|
2425
|
+
const DEFAULT_COLORS = {
|
|
2426
|
+
aliceblue: 0xf0f8ff,
|
|
2427
|
+
antiquewhite: 0xfaebd7,
|
|
2428
|
+
aqua: 0x00ffff,
|
|
2429
|
+
aquamarine: 0x7fffd4,
|
|
2430
|
+
azure: 0xf0ffff,
|
|
2431
|
+
beige: 0xf5f5dc,
|
|
2432
|
+
bisque: 0xffe4c4,
|
|
2433
|
+
black: 0x000000,
|
|
2434
|
+
blanchedalmond: 0xffebcd,
|
|
2435
|
+
blue: 0x0000ff,
|
|
2436
|
+
blueviolet: 0x8a2be2,
|
|
2437
|
+
brown: 0xa52a2a,
|
|
2438
|
+
burlywood: 0xdeb887,
|
|
2439
|
+
cadetblue: 0x5f9ea0,
|
|
2440
|
+
chartreuse: 0x7fff00,
|
|
2441
|
+
chocolate: 0xd2691e,
|
|
2442
|
+
coral: 0xff7f50,
|
|
2443
|
+
cornflowerblue: 0x6495ed,
|
|
2444
|
+
cornsilk: 0xfff8dc,
|
|
2445
|
+
crimson: 0xdc143c,
|
|
2446
|
+
cyan: 0x00ffff,
|
|
2447
|
+
darkblue: 0x00008b,
|
|
2448
|
+
darkcyan: 0x008b8b,
|
|
2449
|
+
darkgoldenrod: 0xb8860b,
|
|
2450
|
+
darkgray: 0xa9a9a9,
|
|
2451
|
+
darkgreen: 0x006400,
|
|
2452
|
+
darkgrey: 0xa9a9a9,
|
|
2453
|
+
darkkhaki: 0xbdb76b,
|
|
2454
|
+
darkmagenta: 0x8b008b,
|
|
2455
|
+
darkolivegreen: 0x556b2f,
|
|
2456
|
+
darkorange: 0xff8c00,
|
|
2457
|
+
darkorchid: 0x9932cc,
|
|
2458
|
+
darkred: 0x8b0000,
|
|
2459
|
+
darksalmon: 0xe9967a,
|
|
2460
|
+
darkseagreen: 0x8fbc8f,
|
|
2461
|
+
darkslateblue: 0x483d8b,
|
|
2462
|
+
darkslategray: 0x2f4f4f,
|
|
2463
|
+
darkslategrey: 0x2f4f4f,
|
|
2464
|
+
darkturquoise: 0x00ced1,
|
|
2465
|
+
darkviolet: 0x9400d3,
|
|
2466
|
+
deeppink: 0xff1493,
|
|
2467
|
+
deepskyblue: 0x00bfff,
|
|
2468
|
+
dimgray: 0x696969,
|
|
2469
|
+
dimgrey: 0x696969,
|
|
2470
|
+
dodgerblue: 0x1e90ff,
|
|
2471
|
+
firebrick: 0xb22222,
|
|
2472
|
+
floralwhite: 0xfffaf0,
|
|
2473
|
+
forestgreen: 0x228b22,
|
|
2474
|
+
fuchsia: 0xff00ff,
|
|
2475
|
+
gainsboro: 0xdcdcdc,
|
|
2476
|
+
ghostwhite: 0xf8f8ff,
|
|
2477
|
+
gold: 0xffd700,
|
|
2478
|
+
goldenrod: 0xdaa520,
|
|
2479
|
+
gray: 0x808080,
|
|
2480
|
+
green: 0x008000,
|
|
2481
|
+
greenyellow: 0xadff2f,
|
|
2482
|
+
grey: 0x808080,
|
|
2483
|
+
honeydew: 0xf0fff0,
|
|
2484
|
+
hotpink: 0xff69b4,
|
|
2485
|
+
indianred: 0xcd5c5c,
|
|
2486
|
+
indigo: 0x4b0082,
|
|
2487
|
+
ivory: 0xfffff0,
|
|
2488
|
+
khaki: 0xf0e68c,
|
|
2489
|
+
lavender: 0xe6e6fa,
|
|
2490
|
+
lavenderblush: 0xfff0f5,
|
|
2491
|
+
lawngreen: 0x7cfc00,
|
|
2492
|
+
lemonchiffon: 0xfffacd,
|
|
2493
|
+
lightblue: 0xadd8e6,
|
|
2494
|
+
lightcoral: 0xf08080,
|
|
2495
|
+
lightcyan: 0xe0ffff,
|
|
2496
|
+
lightgoldenrodyellow: 0xfafad2,
|
|
2497
|
+
lightgray: 0xd3d3d3,
|
|
2498
|
+
lightgreen: 0x90ee90,
|
|
2499
|
+
lightgrey: 0xd3d3d3,
|
|
2500
|
+
lightpink: 0xffb6c1,
|
|
2501
|
+
lightsalmon: 0xffa07a,
|
|
2502
|
+
lightseagreen: 0x20b2aa,
|
|
2503
|
+
lightskyblue: 0x87cefa,
|
|
2504
|
+
lightslategray: 0x778899,
|
|
2505
|
+
lightslategrey: 0x778899,
|
|
2506
|
+
lightsteelblue: 0xb0c4de,
|
|
2507
|
+
lightyellow: 0xffffe0,
|
|
2508
|
+
lime: 0x00ff00,
|
|
2509
|
+
limegreen: 0x32cd32,
|
|
2510
|
+
linen: 0xfaf0e6,
|
|
2511
|
+
magenta: 0xff00ff,
|
|
2512
|
+
maroon: 0x800000,
|
|
2513
|
+
mediumaquamarine: 0x66cdaa,
|
|
2514
|
+
mediumblue: 0x0000cd,
|
|
2515
|
+
mediumorchid: 0xba55d3,
|
|
2516
|
+
mediumpurple: 0x9370db,
|
|
2517
|
+
mediumseagreen: 0x3cb371,
|
|
2518
|
+
mediumslateblue: 0x7b68ee,
|
|
2519
|
+
mediumspringgreen: 0x00fa9a,
|
|
2520
|
+
mediumturquoise: 0x48d1cc,
|
|
2521
|
+
mediumvioletred: 0xc71585,
|
|
2522
|
+
midnightblue: 0x191970,
|
|
2523
|
+
mintcream: 0xf5fffa,
|
|
2524
|
+
mistyrose: 0xffe4e1,
|
|
2525
|
+
moccasin: 0xffe4b5,
|
|
2526
|
+
navajowhite: 0xffdead,
|
|
2527
|
+
navy: 0x000080,
|
|
2528
|
+
oldlace: 0xfdf5e6,
|
|
2529
|
+
olive: 0x808000,
|
|
2530
|
+
olivedrab: 0x6b8e23,
|
|
2531
|
+
orange: 0xffa500,
|
|
2532
|
+
orangered: 0xff4500,
|
|
2533
|
+
orchid: 0xda70d6,
|
|
2534
|
+
palegoldenrod: 0xeee8aa,
|
|
2535
|
+
palegreen: 0x98fb98,
|
|
2536
|
+
paleturquoise: 0xafeeee,
|
|
2537
|
+
palevioletred: 0xdb7093,
|
|
2538
|
+
papayawhip: 0xffefd5,
|
|
2539
|
+
peachpuff: 0xffdab9,
|
|
2540
|
+
peru: 0xcd853f,
|
|
2541
|
+
pink: 0xffc0cb,
|
|
2542
|
+
plum: 0xdda0dd,
|
|
2543
|
+
powderblue: 0xb0e0e6,
|
|
2544
|
+
purple: 0x800080,
|
|
2545
|
+
rebeccapurple: 0x663399,
|
|
2546
|
+
red: 0xff0000,
|
|
2547
|
+
rosybrown: 0xbc8f8f,
|
|
2548
|
+
royalblue: 0x4169e1,
|
|
2549
|
+
saddlebrown: 0x8b4513,
|
|
2550
|
+
salmon: 0xfa8072,
|
|
2551
|
+
sandybrown: 0xf4a460,
|
|
2552
|
+
seagreen: 0x2e8b57,
|
|
2553
|
+
seashell: 0xfff5ee,
|
|
2554
|
+
sienna: 0xa0522d,
|
|
2555
|
+
silver: 0xc0c0c0,
|
|
2556
|
+
skyblue: 0x87ceeb,
|
|
2557
|
+
slateblue: 0x6a5acd,
|
|
2558
|
+
slategray: 0x708090,
|
|
2559
|
+
slategrey: 0x708090,
|
|
2560
|
+
snow: 0xfffafa,
|
|
2561
|
+
springgreen: 0x00ff7f,
|
|
2562
|
+
steelblue: 0x4682b4,
|
|
2563
|
+
tan: 0xd2b48c,
|
|
2564
|
+
teal: 0x008080,
|
|
2565
|
+
thistle: 0xd8bfd8,
|
|
2566
|
+
tomato: 0xff6347,
|
|
2567
|
+
turquoise: 0x40e0d0,
|
|
2568
|
+
violet: 0xee82ee,
|
|
2569
|
+
wheat: 0xf5deb3,
|
|
2570
|
+
white: 0xffffff,
|
|
2571
|
+
whitesmoke: 0xf5f5f5,
|
|
2572
|
+
yellow: 0xffff00,
|
|
2573
|
+
yellowgreen: 0x9acd32
|
|
2574
|
+
};
|
|
2575
|
+
function hex(value) {
|
|
2576
|
+
value = Math.max(0, Math.min(255, Math.round(value) || 0));
|
|
2577
|
+
return (value < 16 ? '0' : '') + value.toString(16);
|
|
2578
|
+
}
|
|
2579
|
+
function rgb(value) {
|
|
2580
|
+
if (isNumber(value)) {
|
|
2581
|
+
return new RGB(value >> 16, (value >> 8) & 0xff, value & 0xff, 1);
|
|
2582
|
+
}
|
|
2583
|
+
else if (isArray(value)) {
|
|
2584
|
+
return new RGB(value[0], value[1], value[2]);
|
|
2585
|
+
}
|
|
2586
|
+
return new RGB(255, 255, 255);
|
|
2587
|
+
}
|
|
2588
|
+
function rgba(value) {
|
|
2589
|
+
if (isNumber(value)) {
|
|
2590
|
+
return new RGB(value >>> 24, (value >>> 16) & 0xff, (value >>> 8) & 0xff, value & 0xff);
|
|
2591
|
+
}
|
|
2592
|
+
else if (isArray(value)) {
|
|
2593
|
+
return new RGB(value[0], value[1], value[2], value[3]);
|
|
2594
|
+
}
|
|
2595
|
+
return new RGB(255, 255, 255, 1);
|
|
2596
|
+
}
|
|
2597
|
+
class Color {
|
|
2598
|
+
color;
|
|
2599
|
+
static Brighter(source, b = 1) {
|
|
2600
|
+
if (b === 1) {
|
|
2601
|
+
return source;
|
|
2602
|
+
}
|
|
2603
|
+
return new Color(source).brighter(b).toRGBA();
|
|
2604
|
+
}
|
|
2605
|
+
static SetOpacity(source, o = 1) {
|
|
2606
|
+
if (o === 1) {
|
|
2607
|
+
return source;
|
|
2608
|
+
}
|
|
2609
|
+
return new Color(source).setOpacity(o).toRGBA();
|
|
2610
|
+
}
|
|
2611
|
+
static getColorBrightness(source, model = 'hsl') {
|
|
2612
|
+
const color = source instanceof Color ? source : new Color(source);
|
|
2613
|
+
switch (model) {
|
|
2614
|
+
case 'hsv':
|
|
2615
|
+
return color.getHSVBrightness();
|
|
2616
|
+
case 'hsl':
|
|
2617
|
+
return color.getHSLBrightness();
|
|
2618
|
+
case 'lum':
|
|
2619
|
+
return color.getLuminance();
|
|
2620
|
+
case 'lum2':
|
|
2621
|
+
return color.getLuminance2();
|
|
2622
|
+
case 'lum3':
|
|
2623
|
+
return color.getLuminance3();
|
|
2624
|
+
default:
|
|
2625
|
+
return color.getHSVBrightness();
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
static parseColorString(value) {
|
|
2629
|
+
if (isValid(DEFAULT_COLORS_OPACITY[value])) {
|
|
2630
|
+
return rgba(DEFAULT_COLORS_OPACITY[value]);
|
|
2631
|
+
}
|
|
2632
|
+
if (isValid(DEFAULT_COLORS[value])) {
|
|
2633
|
+
return rgb(DEFAULT_COLORS[value]);
|
|
2634
|
+
}
|
|
2635
|
+
const formatValue = `${value}`.trim().toLowerCase();
|
|
2636
|
+
const isHex = REG_HEX.exec(formatValue);
|
|
2637
|
+
if (isHex) {
|
|
2638
|
+
const hex = parseInt(isHex[1], 16);
|
|
2639
|
+
const hexLength = isHex[1].length;
|
|
2640
|
+
if (hexLength === 3) {
|
|
2641
|
+
return new RGB(((hex >> 8) & 0xf) + (((hex >> 8) & 0xf) << 4), ((hex >> 4) & 0xf) + (((hex >> 4) & 0xf) << 4), (hex & 0xf) + ((hex & 0xf) << 4), 1);
|
|
2642
|
+
}
|
|
2643
|
+
if (hexLength === 6) {
|
|
2644
|
+
return rgb(hex);
|
|
2645
|
+
}
|
|
2646
|
+
else if (hexLength === 8) {
|
|
2647
|
+
return new RGB((hex >> 24) & 0xff, (hex >> 16) & 0xff, (hex >> 8) & 0xff, (hex & 0xff) / 0xff);
|
|
2648
|
+
}
|
|
2649
|
+
return;
|
|
2650
|
+
}
|
|
2651
|
+
if (/^(rgb|RGB|rgba|RGBA)/.test(formatValue)) {
|
|
2652
|
+
const aColor = formatValue.replace(/(?:\(|\)|rgba|RGBA|rgb|RGB)*/g, '').split(',');
|
|
2653
|
+
return new RGB(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10), parseFloat(aColor[3]));
|
|
2654
|
+
}
|
|
2655
|
+
if (/^(hsl|HSL|hsla|HSLA)/.test(formatValue)) {
|
|
2656
|
+
const aColor = formatValue.replace(/(?:\(|\)|hsla|HSLA|hsl|HSL)*/g, '').split(',');
|
|
2657
|
+
const rgb = hslToRgb(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10));
|
|
2658
|
+
return new RGB(rgb.r, rgb.g, rgb.b, parseFloat(aColor[3]));
|
|
2659
|
+
}
|
|
2660
|
+
return;
|
|
2661
|
+
}
|
|
2662
|
+
constructor(value) {
|
|
2663
|
+
const color = Color.parseColorString(value);
|
|
2664
|
+
if (color) {
|
|
2665
|
+
this.color = color;
|
|
2666
|
+
}
|
|
2667
|
+
else {
|
|
2668
|
+
console.warn(`Warn: 传入${value}无法解析为Color`);
|
|
2669
|
+
this.color = new RGB(255, 255, 255);
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
toRGBA() {
|
|
2673
|
+
return this.color.formatRgb();
|
|
2674
|
+
}
|
|
2675
|
+
toString() {
|
|
2676
|
+
return this.color.formatRgb();
|
|
2677
|
+
}
|
|
2678
|
+
toHex() {
|
|
2679
|
+
return this.color.formatHex();
|
|
2680
|
+
}
|
|
2681
|
+
toHsl() {
|
|
2682
|
+
return this.color.formatHsl();
|
|
2683
|
+
}
|
|
2684
|
+
setOpacity(o = 1) {
|
|
2685
|
+
this.color.opacity = o;
|
|
2686
|
+
return this;
|
|
2687
|
+
}
|
|
2688
|
+
brighter(k) {
|
|
2689
|
+
const { r, g, b } = this.color;
|
|
2690
|
+
this.color.r = Math.max(0, Math.min(255, Math.floor(r * k)));
|
|
2691
|
+
this.color.g = Math.max(0, Math.min(255, Math.floor(g * k)));
|
|
2692
|
+
this.color.b = Math.max(0, Math.min(255, Math.floor(b * k)));
|
|
2693
|
+
return this;
|
|
2694
|
+
}
|
|
2695
|
+
getHSVBrightness() {
|
|
2696
|
+
return Math.max(this.color.r, this.color.g, this.color.b) / 255;
|
|
2697
|
+
}
|
|
2698
|
+
getHSLBrightness() {
|
|
2699
|
+
return ((Math.max(this.color.r, this.color.g, this.color.b) / 255 +
|
|
2700
|
+
Math.min(this.color.r, this.color.g, this.color.b) / 255) *
|
|
2701
|
+
0.5);
|
|
2702
|
+
}
|
|
2703
|
+
setHsl(h, s, l) {
|
|
2704
|
+
const opacity = this.color.opacity;
|
|
2705
|
+
const hsl = rgbToHsl(this.color.r, this.color.g, this.color.b);
|
|
2706
|
+
const rgb = hslToRgb(isNil(h) ? hsl.h : clamp(h, 0, 360), isNil(s) ? hsl.s : s >= 0 && s <= 1 ? s * 100 : s, isNil(l) ? hsl.l : l <= 1 && l >= 0 ? l * 100 : l);
|
|
2707
|
+
this.color = new RGB(rgb.r, rgb.g, rgb.b, opacity);
|
|
2708
|
+
return this;
|
|
2709
|
+
}
|
|
2710
|
+
getLuminance() {
|
|
2711
|
+
return (0.2126 * this.color.r + 0.7152 * this.color.g + 0.0722 * this.color.b) / 255;
|
|
2712
|
+
}
|
|
2713
|
+
getLuminance2() {
|
|
2714
|
+
return (0.2627 * this.color.r + 0.678 * this.color.g + 0.0593 * this.color.b) / 255;
|
|
2715
|
+
}
|
|
2716
|
+
getLuminance3() {
|
|
2717
|
+
return (0.299 * this.color.r + 0.587 * this.color.g + 0.114 * this.color.b) / 255;
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
class RGB {
|
|
2721
|
+
r;
|
|
2722
|
+
g;
|
|
2723
|
+
b;
|
|
2724
|
+
opacity;
|
|
2725
|
+
constructor(r, g, b, opacity) {
|
|
2726
|
+
this.r = isNaN(+r) ? 255 : Math.max(0, Math.min(255, +r));
|
|
2727
|
+
this.g = isNaN(+g) ? 255 : Math.max(0, Math.min(255, +g));
|
|
2728
|
+
this.b = isNaN(+b) ? 255 : Math.max(0, Math.min(255, +b));
|
|
2729
|
+
if (isValid(opacity)) {
|
|
2730
|
+
this.opacity = isNaN(+opacity) ? 1 : Math.max(0, Math.min(1, +opacity));
|
|
2731
|
+
}
|
|
2732
|
+
else {
|
|
2733
|
+
this.opacity = 1;
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
formatHex() {
|
|
2737
|
+
return `#${hex(this.r) + hex(this.g) + hex(this.b) + (this.opacity === 1 ? '' : hex(this.opacity * 255))}`;
|
|
2738
|
+
}
|
|
2739
|
+
formatRgb() {
|
|
2740
|
+
const opacity = this.opacity;
|
|
2741
|
+
return `${opacity === 1 ? 'rgb(' : 'rgba('}${this.r},${this.g},${this.b}${opacity === 1 ? ')' : `,${opacity})`}`;
|
|
2742
|
+
}
|
|
2743
|
+
formatHsl() {
|
|
2744
|
+
const opacity = this.opacity;
|
|
2745
|
+
const { h, s, l } = rgbToHsl(this.r, this.g, this.b);
|
|
2746
|
+
return `${opacity === 1 ? 'hsl(' : 'hsla('}${h},${s}%,${l}%${opacity === 1 ? ')' : `,${opacity})`}`;
|
|
2747
|
+
}
|
|
2748
|
+
toString() {
|
|
2749
|
+
return this.formatHex();
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
|
|
2753
|
+
function hexToRgb(str) {
|
|
2754
|
+
let r = '';
|
|
2755
|
+
let g = '';
|
|
2756
|
+
let b = '';
|
|
2757
|
+
const strtIndex = str[0] === '#' ? 1 : 0;
|
|
2758
|
+
for (let i = strtIndex; i < str.length; i++) {
|
|
2759
|
+
if (str[i] === '#') {
|
|
2760
|
+
continue;
|
|
2761
|
+
}
|
|
2762
|
+
if (i < strtIndex + 2) {
|
|
2763
|
+
r += str[i];
|
|
2764
|
+
}
|
|
2765
|
+
else if (i < strtIndex + 4) {
|
|
2766
|
+
g += str[i];
|
|
2767
|
+
}
|
|
2768
|
+
else if (i < strtIndex + 6) {
|
|
2769
|
+
b += str[i];
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
const ri = parseInt(r, 16);
|
|
2773
|
+
const gi = parseInt(g, 16);
|
|
2774
|
+
const bi = parseInt(b, 16);
|
|
2775
|
+
return [ri, gi, bi];
|
|
2776
|
+
}
|
|
2777
|
+
|
|
2778
|
+
function rgbToHex(r, g, b) {
|
|
2779
|
+
return Number((1 << 24) + (r << 16) + (g << 8) + b)
|
|
2780
|
+
.toString(16)
|
|
2781
|
+
.slice(1);
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
function interpolateRgb(colorA, colorB) {
|
|
2785
|
+
const redA = colorA.r;
|
|
2786
|
+
const redB = colorB.r;
|
|
2787
|
+
const greenA = colorA.g;
|
|
2788
|
+
const greenB = colorB.g;
|
|
2789
|
+
const blueA = colorA.b;
|
|
2790
|
+
const blueB = colorB.b;
|
|
2791
|
+
const opacityA = colorA.opacity;
|
|
2792
|
+
const opacityB = colorB.opacity;
|
|
2793
|
+
return (t) => {
|
|
2794
|
+
const r = Math.round(redA * (1 - t) + redB * t);
|
|
2795
|
+
const g = Math.round(greenA * (1 - t) + greenB * t);
|
|
2796
|
+
const b = Math.round(blueA * (1 - t) + blueB * t);
|
|
2797
|
+
const opacity = opacityA * (1 - t) + opacityB * t;
|
|
2798
|
+
return new RGB(r, g, b, opacity);
|
|
2799
|
+
};
|
|
2800
|
+
}
|
|
2801
|
+
|
|
2802
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
2803
|
+
__proto__: null,
|
|
2804
|
+
Color: Color,
|
|
2805
|
+
DEFAULT_COLORS: DEFAULT_COLORS,
|
|
2806
|
+
RGB: RGB,
|
|
2807
|
+
hexToRgb: hexToRgb,
|
|
2808
|
+
hslToRgb: hslToRgb,
|
|
2809
|
+
interpolateRgb: interpolateRgb,
|
|
2810
|
+
rgbToHex: rgbToHex,
|
|
2811
|
+
rgbToHsl: rgbToHsl
|
|
2812
|
+
});
|
|
2813
|
+
|
|
2814
|
+
const parseUint8ToImageData = (buffer, width, height) => {
|
|
2815
|
+
const clampBuffer = new Uint8ClampedArray(buffer);
|
|
2816
|
+
const flipClampBuffer = new Uint8ClampedArray(buffer.length);
|
|
2817
|
+
for (let i = height - 1; i >= 0; i--) {
|
|
2818
|
+
for (let j = 0; j < width; j++) {
|
|
2819
|
+
const sourceIdx = i * width * 4 + j * 4;
|
|
2820
|
+
const targetIdx = (height - i) * width * 4 + j * 4;
|
|
2821
|
+
flipClampBuffer[targetIdx] = clampBuffer[sourceIdx];
|
|
2822
|
+
flipClampBuffer[targetIdx + 1] = clampBuffer[sourceIdx + 1];
|
|
2823
|
+
flipClampBuffer[targetIdx + 2] = clampBuffer[sourceIdx + 2];
|
|
2824
|
+
flipClampBuffer[targetIdx + 3] = clampBuffer[sourceIdx + 3];
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
return new ImageData(flipClampBuffer, width, height);
|
|
2828
|
+
};
|
|
2829
|
+
|
|
2830
|
+
function sub(out, v1, v2) {
|
|
2831
|
+
out[0] = v1[0] - v2[0];
|
|
2832
|
+
out[1] = v1[1] - v2[1];
|
|
2833
|
+
}
|
|
2834
|
+
let x11;
|
|
2835
|
+
let x12;
|
|
2836
|
+
let y11;
|
|
2837
|
+
let y12;
|
|
2838
|
+
let x21;
|
|
2839
|
+
let x22;
|
|
2840
|
+
let y21;
|
|
2841
|
+
let y22;
|
|
2842
|
+
function isIntersect(left1, right1, left2, right2) {
|
|
2843
|
+
let min1 = left1[0];
|
|
2844
|
+
let max1 = right1[0];
|
|
2845
|
+
let min2 = left2[0];
|
|
2846
|
+
let max2 = right2[0];
|
|
2847
|
+
let _temp;
|
|
2848
|
+
if (max1 < min1) {
|
|
2849
|
+
_temp = max1;
|
|
2850
|
+
(max1 = min1), (min1 = _temp);
|
|
2851
|
+
}
|
|
2852
|
+
if (max2 < min2) {
|
|
2853
|
+
_temp = max2;
|
|
2854
|
+
(max2 = min2), (min2 = _temp);
|
|
2855
|
+
}
|
|
2856
|
+
if (max1 < min2 || max2 < min1) {
|
|
2857
|
+
return false;
|
|
2858
|
+
}
|
|
2859
|
+
(min1 = left1[1]), (max1 = right1[1]), (min2 = left2[1]), (max2 = right2[1]);
|
|
2860
|
+
if (max1 < min1) {
|
|
2861
|
+
_temp = max1;
|
|
2862
|
+
(max1 = min1), (min1 = _temp);
|
|
2863
|
+
}
|
|
2864
|
+
if (max2 < min2) {
|
|
2865
|
+
_temp = max2;
|
|
2866
|
+
(max2 = min2), (min2 = _temp);
|
|
2867
|
+
}
|
|
2868
|
+
if (max1 < min2 || max2 < min1) {
|
|
2869
|
+
return false;
|
|
2870
|
+
}
|
|
2871
|
+
return true;
|
|
2872
|
+
}
|
|
2873
|
+
function getIntersectPoint(left1, right1, left2, right2) {
|
|
2874
|
+
if (!isIntersect(left1, right1, left2, right2)) {
|
|
2875
|
+
return false;
|
|
2876
|
+
}
|
|
2877
|
+
const dir1 = [0, 0];
|
|
2878
|
+
const dir2 = [0, 0];
|
|
2879
|
+
const tempVec = [0, 0];
|
|
2880
|
+
sub(dir1, right1, left1);
|
|
2881
|
+
sub(dir2, right2, left2);
|
|
2882
|
+
if (fuzzyEqualVec(dir1, dir2)) {
|
|
2883
|
+
return true;
|
|
2884
|
+
}
|
|
2885
|
+
sub(tempVec, left2, left1);
|
|
2886
|
+
const t = crossProduct(tempVec, dir2) / crossProduct(dir1, dir2);
|
|
2887
|
+
if (t >= 0 && t <= 1) {
|
|
2888
|
+
return [left1[0] + dir1[0] * t, left1[1] + dir1[1] * t];
|
|
2889
|
+
}
|
|
2890
|
+
return false;
|
|
2891
|
+
}
|
|
2892
|
+
function getRectIntersect(bbox1, bbox2, format) {
|
|
2893
|
+
if (bbox1 === null) {
|
|
2894
|
+
return bbox2;
|
|
2895
|
+
}
|
|
2896
|
+
if (bbox2 === null) {
|
|
2897
|
+
return bbox1;
|
|
2898
|
+
}
|
|
2899
|
+
(x11 = bbox1.x1),
|
|
2900
|
+
(x12 = bbox1.x2),
|
|
2901
|
+
(y11 = bbox1.y1),
|
|
2902
|
+
(y12 = bbox1.y2),
|
|
2903
|
+
(x21 = bbox2.x1),
|
|
2904
|
+
(x22 = bbox2.x2),
|
|
2905
|
+
(y21 = bbox2.y1),
|
|
2906
|
+
(y22 = bbox2.y2);
|
|
2907
|
+
if (format) {
|
|
2908
|
+
if (x11 > x12) {
|
|
2909
|
+
[x11, x12] = [x12, x11];
|
|
2910
|
+
}
|
|
2911
|
+
if (y11 > y12) {
|
|
2912
|
+
[y11, y12] = [y12, y11];
|
|
2913
|
+
}
|
|
2914
|
+
if (x21 > x22) {
|
|
2915
|
+
[x21, x22] = [x22, x21];
|
|
2916
|
+
}
|
|
2917
|
+
if (y21 > y22) {
|
|
2918
|
+
[y21, y22] = [y22, y21];
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2921
|
+
if (x11 >= x22 || x12 <= x21 || y11 >= y22 || y12 <= y21) {
|
|
2922
|
+
return { x1: 0, y1: 0, x2: 0, y2: 0 };
|
|
2923
|
+
}
|
|
2924
|
+
return { x1: Math.max(x11, x21), y1: Math.max(y11, y21), x2: Math.min(x12, x22), y2: Math.min(y12, y22) };
|
|
2925
|
+
}
|
|
2926
|
+
exports.InnerBBox = void 0;
|
|
2927
|
+
(function (InnerBBox) {
|
|
2928
|
+
InnerBBox[InnerBBox["NONE"] = 0] = "NONE";
|
|
2929
|
+
InnerBBox[InnerBBox["BBOX1"] = 1] = "BBOX1";
|
|
2930
|
+
InnerBBox[InnerBBox["BBOX2"] = 2] = "BBOX2";
|
|
2931
|
+
})(exports.InnerBBox || (exports.InnerBBox = {}));
|
|
2932
|
+
function rectInsideAnotherRect(bbox1, bbox2, format) {
|
|
2933
|
+
if (!bbox1 || !bbox2) {
|
|
2934
|
+
return exports.InnerBBox.NONE;
|
|
2935
|
+
}
|
|
2936
|
+
(x11 = bbox1.x1),
|
|
2937
|
+
(x12 = bbox1.x2),
|
|
2938
|
+
(y11 = bbox1.y1),
|
|
2939
|
+
(y12 = bbox1.y2),
|
|
2940
|
+
(x21 = bbox2.x1),
|
|
2941
|
+
(x22 = bbox2.x2),
|
|
2942
|
+
(y21 = bbox2.y1),
|
|
2943
|
+
(y22 = bbox2.y2);
|
|
2944
|
+
if (format) {
|
|
2945
|
+
if (x11 > x12) {
|
|
2946
|
+
[x11, x12] = [x12, x11];
|
|
2947
|
+
}
|
|
2948
|
+
if (y11 > y12) {
|
|
2949
|
+
[y11, y12] = [y12, y11];
|
|
2950
|
+
}
|
|
2951
|
+
if (x21 > x22) {
|
|
2952
|
+
[x21, x22] = [x22, x21];
|
|
2953
|
+
}
|
|
2954
|
+
if (y21 > y22) {
|
|
2955
|
+
[y21, y22] = [y22, y21];
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
if (x11 > x21 && x12 < x22 && y11 > y21 && y12 < y22) {
|
|
2959
|
+
return exports.InnerBBox.BBOX1;
|
|
2960
|
+
}
|
|
2961
|
+
if (x21 > x11 && x22 < x12 && y21 > y11 && y22 < y12) {
|
|
2962
|
+
return exports.InnerBBox.BBOX2;
|
|
2963
|
+
}
|
|
2964
|
+
return exports.InnerBBox.NONE;
|
|
2965
|
+
}
|
|
2966
|
+
function isRectIntersect(bbox1, bbox2, format) {
|
|
2967
|
+
if (bbox1 && bbox2) {
|
|
2968
|
+
if (!format) {
|
|
2969
|
+
if (bbox1.x1 > bbox2.x2 || bbox1.x2 < bbox2.x1 || bbox1.y1 > bbox2.y2 || bbox1.y2 < bbox2.y1) {
|
|
2970
|
+
return false;
|
|
2971
|
+
}
|
|
2972
|
+
return true;
|
|
2973
|
+
}
|
|
2974
|
+
(x11 = bbox1.x1),
|
|
2975
|
+
(x12 = bbox1.x2),
|
|
2976
|
+
(y11 = bbox1.y1),
|
|
2977
|
+
(y12 = bbox1.y2),
|
|
2978
|
+
(x21 = bbox2.x1),
|
|
2979
|
+
(x22 = bbox2.x2),
|
|
2980
|
+
(y21 = bbox2.y1),
|
|
2981
|
+
(y22 = bbox2.y2);
|
|
2982
|
+
if (x11 > x12) {
|
|
2983
|
+
[x11, x12] = [x12, x11];
|
|
2984
|
+
}
|
|
2985
|
+
if (y11 > y12) {
|
|
2986
|
+
[y11, y12] = [y12, y11];
|
|
2987
|
+
}
|
|
2988
|
+
if (x21 > x22) {
|
|
2989
|
+
[x21, x22] = [x22, x21];
|
|
2990
|
+
}
|
|
2991
|
+
if (y21 > y22) {
|
|
2992
|
+
[y21, y22] = [y22, y21];
|
|
2993
|
+
}
|
|
2994
|
+
if (x11 > x22 || x12 < x21 || y11 > y22 || y12 < y21) {
|
|
2995
|
+
return false;
|
|
2996
|
+
}
|
|
2997
|
+
return true;
|
|
2998
|
+
}
|
|
2999
|
+
return true;
|
|
3000
|
+
}
|
|
3001
|
+
function pointInRect(point, bbox, format) {
|
|
3002
|
+
if (!bbox) {
|
|
3003
|
+
return true;
|
|
3004
|
+
}
|
|
3005
|
+
if (!format) {
|
|
3006
|
+
return point.x >= bbox.x1 && point.x <= bbox.x2 && point.y >= bbox.y1 && point.y <= bbox.y2;
|
|
3007
|
+
}
|
|
3008
|
+
(x11 = bbox.x1), (x12 = bbox.x2), (y11 = bbox.y1), (y12 = bbox.y2);
|
|
3009
|
+
if (x11 > x12) {
|
|
3010
|
+
[x11, x12] = [x12, x11];
|
|
3011
|
+
}
|
|
3012
|
+
if (y11 > y12) {
|
|
3013
|
+
[y11, y12] = [y12, y11];
|
|
3014
|
+
}
|
|
3015
|
+
return point.x >= x11 && point.x <= x12 && point.y >= y11 && point.y <= y12;
|
|
3016
|
+
}
|
|
3017
|
+
function getProjectionRadius(checkAxis, axis) {
|
|
3018
|
+
return Math.abs(axis[0] * checkAxis[0] + axis[1] * checkAxis[1]);
|
|
3019
|
+
}
|
|
3020
|
+
function rotate({ x, y }, deg, origin = { x: 0, y: 0 }) {
|
|
3021
|
+
return {
|
|
3022
|
+
x: (x - origin.x) * Math.cos(deg) + (y - origin.y) * Math.sin(deg) + origin.x,
|
|
3023
|
+
y: (x - origin.x) * Math.sin(deg) + (origin.y - y) * Math.cos(deg) + origin.y
|
|
3024
|
+
};
|
|
3025
|
+
}
|
|
3026
|
+
function toDeg(angle) {
|
|
3027
|
+
return (angle / 180) * Math.PI;
|
|
3028
|
+
}
|
|
3029
|
+
function getCenterPoint(box) {
|
|
3030
|
+
return {
|
|
3031
|
+
x: (box.x1 + box.x2) / 2,
|
|
3032
|
+
y: (box.y1 + box.y2) / 2
|
|
3033
|
+
};
|
|
3034
|
+
}
|
|
3035
|
+
function toRect(box, isDeg) {
|
|
3036
|
+
const deg = isDeg ? box.angle : toDeg(box.angle);
|
|
3037
|
+
const cp = getCenterPoint(box);
|
|
3038
|
+
return [
|
|
3039
|
+
rotate({
|
|
3040
|
+
x: box.x1,
|
|
3041
|
+
y: box.y1
|
|
3042
|
+
}, deg, cp),
|
|
3043
|
+
rotate({
|
|
3044
|
+
x: box.x2,
|
|
3045
|
+
y: box.y1
|
|
3046
|
+
}, deg, cp),
|
|
3047
|
+
rotate({
|
|
3048
|
+
x: box.x2,
|
|
3049
|
+
y: box.y2
|
|
3050
|
+
}, deg, cp),
|
|
3051
|
+
rotate({
|
|
3052
|
+
x: box.x1,
|
|
3053
|
+
y: box.y2
|
|
3054
|
+
}, deg, cp)
|
|
3055
|
+
];
|
|
3056
|
+
}
|
|
3057
|
+
function isRotateAABBIntersect(box1, box2, isDeg = false, ctx) {
|
|
3058
|
+
const rect1 = toRect(box1, isDeg);
|
|
3059
|
+
const rect2 = toRect(box2, isDeg);
|
|
3060
|
+
const vector = (start, end) => {
|
|
3061
|
+
return [end.x - start.x, end.y - start.y];
|
|
3062
|
+
};
|
|
3063
|
+
if (ctx) {
|
|
3064
|
+
ctx.save();
|
|
3065
|
+
ctx.fillStyle = 'red';
|
|
3066
|
+
ctx.globalAlpha = 0.6;
|
|
3067
|
+
rect1.forEach((item, index) => {
|
|
3068
|
+
if (index === 0) {
|
|
3069
|
+
ctx.moveTo(item.x, item.y);
|
|
3070
|
+
}
|
|
3071
|
+
else {
|
|
3072
|
+
ctx.lineTo(item.x, item.y);
|
|
3073
|
+
}
|
|
3074
|
+
});
|
|
3075
|
+
ctx.fill();
|
|
3076
|
+
ctx.restore();
|
|
3077
|
+
ctx.save();
|
|
3078
|
+
ctx.fillStyle = 'green';
|
|
3079
|
+
ctx.globalAlpha = 0.6;
|
|
3080
|
+
rect2.forEach((item, index) => {
|
|
3081
|
+
if (index === 0) {
|
|
3082
|
+
ctx.moveTo(item.x, item.y);
|
|
3083
|
+
}
|
|
3084
|
+
else {
|
|
3085
|
+
ctx.lineTo(item.x, item.y);
|
|
3086
|
+
}
|
|
3087
|
+
});
|
|
3088
|
+
ctx.fill();
|
|
3089
|
+
ctx.restore();
|
|
3090
|
+
}
|
|
3091
|
+
const p1 = getCenterPoint(box1);
|
|
3092
|
+
const p2 = getCenterPoint(box2);
|
|
3093
|
+
ctx && ctx.fillRect(p1.x, p1.y, 2, 2);
|
|
3094
|
+
ctx && ctx.fillRect(p2.x, p2.y, 2, 2);
|
|
3095
|
+
const vp1p2 = vector(p1, p2);
|
|
3096
|
+
const AB = vector(rect1[0], rect1[1]);
|
|
3097
|
+
const BC = vector(rect1[1], rect1[2]);
|
|
3098
|
+
const A1B1 = vector(rect2[0], rect2[1]);
|
|
3099
|
+
const B1C1 = vector(rect2[1], rect2[2]);
|
|
3100
|
+
const deg11 = isDeg ? box1.angle : toDeg(box1.angle);
|
|
3101
|
+
let deg12 = isDeg ? box1.angle + halfPi : toDeg(90 - box1.angle);
|
|
3102
|
+
const deg21 = isDeg ? box2.angle : toDeg(box2.angle);
|
|
3103
|
+
let deg22 = isDeg ? box2.angle + halfPi : toDeg(90 - box2.angle);
|
|
3104
|
+
if (deg12 > pi2) {
|
|
3105
|
+
deg12 -= pi2;
|
|
3106
|
+
}
|
|
3107
|
+
if (deg22 > pi2) {
|
|
3108
|
+
deg22 -= pi2;
|
|
3109
|
+
}
|
|
3110
|
+
const isCover = (checkAxisRadius, deg, targetAxis1, targetAxis2) => {
|
|
3111
|
+
const checkAxis = [Math.cos(deg), Math.sin(deg)];
|
|
3112
|
+
const targetAxisRadius = (getProjectionRadius(checkAxis, targetAxis1) + getProjectionRadius(checkAxis, targetAxis2)) / 2;
|
|
3113
|
+
const centerPointRadius = getProjectionRadius(checkAxis, vp1p2);
|
|
3114
|
+
return checkAxisRadius + targetAxisRadius > centerPointRadius;
|
|
3115
|
+
};
|
|
3116
|
+
return (isCover((box1.x2 - box1.x1) / 2, deg11, A1B1, B1C1) &&
|
|
3117
|
+
isCover((box1.y2 - box1.y1) / 2, deg12, A1B1, B1C1) &&
|
|
3118
|
+
isCover((box2.x2 - box2.x1) / 2, deg21, AB, BC) &&
|
|
3119
|
+
isCover((box2.y2 - box2.y1) / 2, deg22, AB, BC));
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
let x1;
|
|
3123
|
+
let y1;
|
|
3124
|
+
let x2;
|
|
3125
|
+
let y2;
|
|
3126
|
+
function getAABBFromPoints(points) {
|
|
3127
|
+
(x1 = Infinity), (y1 = Infinity), (x2 = -Infinity), (y2 = -Infinity);
|
|
3128
|
+
points.forEach(point => {
|
|
3129
|
+
if (x1 > point.x) {
|
|
3130
|
+
x1 = point.x;
|
|
3131
|
+
}
|
|
3132
|
+
if (x2 < point.x) {
|
|
3133
|
+
x2 = point.x;
|
|
3134
|
+
}
|
|
3135
|
+
if (y1 > point.y) {
|
|
3136
|
+
y1 = point.y;
|
|
3137
|
+
}
|
|
3138
|
+
if (y2 < point.y) {
|
|
3139
|
+
y2 = point.y;
|
|
3140
|
+
}
|
|
3141
|
+
});
|
|
3142
|
+
return { x1, y1, x2, y2 };
|
|
3143
|
+
}
|
|
3144
|
+
function pointInAABB(point, aabb) {
|
|
3145
|
+
return pointInRect(point, aabb, false);
|
|
3146
|
+
}
|
|
3147
|
+
function unionAABB(bounds1, bounds2, buffer = 3, format = false) {
|
|
3148
|
+
let x11 = bounds1.x1;
|
|
3149
|
+
let x12 = bounds1.x2;
|
|
3150
|
+
let y11 = bounds1.y1;
|
|
3151
|
+
let y12 = bounds1.y2;
|
|
3152
|
+
let x21 = bounds2.x1;
|
|
3153
|
+
let x22 = bounds2.x2;
|
|
3154
|
+
let y21 = bounds2.y1;
|
|
3155
|
+
let y22 = bounds2.y2;
|
|
3156
|
+
if (format) {
|
|
3157
|
+
let temp;
|
|
3158
|
+
if (x11 > x12) {
|
|
3159
|
+
temp = x11;
|
|
3160
|
+
x11 = x12;
|
|
3161
|
+
x12 = temp;
|
|
3162
|
+
}
|
|
3163
|
+
if (y11 > y12) {
|
|
3164
|
+
temp = y11;
|
|
3165
|
+
y11 = y12;
|
|
3166
|
+
y12 = temp;
|
|
3167
|
+
}
|
|
3168
|
+
if (x21 > x22) {
|
|
3169
|
+
temp = x21;
|
|
3170
|
+
x21 = x22;
|
|
3171
|
+
x22 = temp;
|
|
3172
|
+
}
|
|
3173
|
+
if (y21 > y22) {
|
|
3174
|
+
temp = y21;
|
|
3175
|
+
y21 = y22;
|
|
3176
|
+
y22 = temp;
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
3179
|
+
if (x11 >= x22 || x12 <= x21 || y11 >= y22 || y12 <= y21) {
|
|
3180
|
+
return [bounds1, bounds2];
|
|
3181
|
+
}
|
|
3182
|
+
const area1 = (x12 - x11 + buffer * 2) * (y12 - y11 + buffer * 2);
|
|
3183
|
+
const area2 = (x22 - x21 + buffer * 2) * (y22 - y21 + buffer * 2);
|
|
3184
|
+
const x1 = Math.min(x11, x21);
|
|
3185
|
+
const y1 = Math.min(y11, y21);
|
|
3186
|
+
const x2 = Math.max(x12, x22);
|
|
3187
|
+
const y2 = Math.max(y12, y22);
|
|
3188
|
+
const unionArea = (x2 - x1) * (y2 - y1);
|
|
3189
|
+
if (area1 + area2 > unionArea) {
|
|
3190
|
+
return [{ x1, x2, y1, y2 }];
|
|
3191
|
+
}
|
|
3192
|
+
return [bounds1, bounds2];
|
|
3193
|
+
}
|
|
3194
|
+
function mergeAABB(boundsList) {
|
|
3195
|
+
const nextList = [];
|
|
3196
|
+
function _merge(baseBound, list) {
|
|
3197
|
+
const l = [];
|
|
3198
|
+
list.forEach(b => {
|
|
3199
|
+
let arr;
|
|
3200
|
+
if ((arr = unionAABB(baseBound, b)).length > 1) {
|
|
3201
|
+
l.push(b);
|
|
3202
|
+
return;
|
|
3203
|
+
}
|
|
3204
|
+
baseBound = arr[0];
|
|
3205
|
+
});
|
|
3206
|
+
nextList.push(baseBound);
|
|
3207
|
+
l.length && _merge(l[0], l.slice(1));
|
|
3208
|
+
}
|
|
3209
|
+
_merge(boundsList[0], boundsList.slice(1));
|
|
3210
|
+
return nextList;
|
|
3211
|
+
}
|
|
3212
|
+
|
|
3213
|
+
let dirX;
|
|
3214
|
+
let dirY;
|
|
3215
|
+
let normalX;
|
|
3216
|
+
let normalY;
|
|
3217
|
+
let len;
|
|
3218
|
+
let lineWidthDiv2;
|
|
3219
|
+
let width;
|
|
3220
|
+
let height;
|
|
3221
|
+
function getOBBFromLine(point1, point2, lineWidth) {
|
|
3222
|
+
dirX = point2.x - point1.x;
|
|
3223
|
+
dirY = point2.y - point1.y;
|
|
3224
|
+
(normalX = dirY), (normalY = -dirX);
|
|
3225
|
+
width = len = Math.sqrt(normalX * normalX + normalY * normalY);
|
|
3226
|
+
height = lineWidth;
|
|
3227
|
+
normalX /= len;
|
|
3228
|
+
normalY /= len;
|
|
3229
|
+
lineWidthDiv2 = lineWidth / 2;
|
|
3230
|
+
dirX = lineWidthDiv2 * normalX;
|
|
3231
|
+
dirY = lineWidthDiv2 * normalY;
|
|
3232
|
+
const point11 = { x: point1.x + dirX, y: point1.y + dirY };
|
|
3233
|
+
const point12 = { x: point1.x - dirX, y: point1.y - dirY };
|
|
3234
|
+
const point13 = { x: point2.x + dirX, y: point2.y + dirY };
|
|
3235
|
+
const point14 = { x: point2.x - dirX, y: point2.y - dirY };
|
|
3236
|
+
return {
|
|
3237
|
+
point1: point11,
|
|
3238
|
+
point2: point12,
|
|
3239
|
+
point3: point13,
|
|
3240
|
+
point4: point14,
|
|
3241
|
+
width,
|
|
3242
|
+
height,
|
|
3243
|
+
left: Math.min(point1.x, point2.x) - Math.abs(dirX),
|
|
3244
|
+
top: Math.min(point1.y, point2.y) - Math.abs(dirY)
|
|
3245
|
+
};
|
|
3246
|
+
}
|
|
3247
|
+
const point1 = { x: 0, y: 0 };
|
|
3248
|
+
const point2 = { x: 0, y: 0 };
|
|
3249
|
+
function pointInOBB(point, obb) {
|
|
3250
|
+
point1.x = (obb.point1.x + obb.point2.x) / 2;
|
|
3251
|
+
point1.y = (obb.point1.y + obb.point2.y) / 2;
|
|
3252
|
+
point2.x = (obb.point3.x + obb.point4.x) / 2;
|
|
3253
|
+
point2.y = (obb.point3.y + obb.point4.y) / 2;
|
|
3254
|
+
return pointInLine(point, point1, point2, obb.height);
|
|
3255
|
+
}
|
|
3256
|
+
function pointInLine(point, point1, point2, lineWidth) {
|
|
3257
|
+
return lengthFromPointToLine(point, point1, point2) <= lineWidth / 2 && pointBetweenLine(point, point1, point2);
|
|
3258
|
+
}
|
|
3259
|
+
const dir1 = { x: 0, y: 0 };
|
|
3260
|
+
const dir2 = { x: 0, y: 0 };
|
|
3261
|
+
const normal = { x: 0, y: 0 };
|
|
3262
|
+
function pointBetweenLine(point, point1, point2) {
|
|
3263
|
+
dir1.x = point1.x - point.x;
|
|
3264
|
+
dir1.y = point1.y - point.y;
|
|
3265
|
+
dir2.x = point2.x - point.x;
|
|
3266
|
+
dir2.y = point2.y - point.y;
|
|
3267
|
+
normal.x = point1.y - point2.y;
|
|
3268
|
+
normal.y = point2.x - point1.x;
|
|
3269
|
+
return crossProductPoint(dir1, normal) * crossProductPoint(dir2, normal) < 0;
|
|
3270
|
+
}
|
|
3271
|
+
|
|
3272
|
+
function getContextFont$1({ fontStyle, fontVariant, fontWeight, fontSize, fontFamily }) {
|
|
3273
|
+
return ('' +
|
|
3274
|
+
(fontStyle ? fontStyle + ' ' : '') +
|
|
3275
|
+
(fontVariant ? fontVariant + ' ' : '') +
|
|
3276
|
+
(fontWeight ? fontWeight + ' ' : '') +
|
|
3277
|
+
(fontSize || 12) +
|
|
3278
|
+
'px ' +
|
|
3279
|
+
(fontFamily ? fontFamily : 'sans-serif'));
|
|
3280
|
+
}
|
|
3281
|
+
class GraphicUtil {
|
|
3282
|
+
canvas;
|
|
3283
|
+
ctx;
|
|
3284
|
+
static instance;
|
|
3285
|
+
constructor(canvas) {
|
|
3286
|
+
this.canvas = canvas;
|
|
3287
|
+
if (canvas) {
|
|
3288
|
+
this.ctx = canvas.getContext('2d');
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
setCanvas(canvas) {
|
|
3292
|
+
this.canvas = canvas;
|
|
3293
|
+
if (canvas) {
|
|
3294
|
+
this.ctx = canvas.getContext('2d');
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
measureText(tc) {
|
|
3298
|
+
if (!this.canvas) {
|
|
3299
|
+
console.warn('[warn] no canvas, measureText might be not accurate');
|
|
3300
|
+
return this.estimate(tc);
|
|
3301
|
+
}
|
|
3302
|
+
return this.measureTextByCanvas(tc);
|
|
3303
|
+
}
|
|
3304
|
+
measureTextByCanvas(tc) {
|
|
3305
|
+
if (!this.ctx) {
|
|
3306
|
+
console.error('[error!!!]measureTextByCanvas can not be called without canvas');
|
|
3307
|
+
return { width: -1, height: tc.fontSize };
|
|
3308
|
+
}
|
|
3309
|
+
this.ctx.font = getContextFont$1(tc);
|
|
3310
|
+
return {
|
|
3311
|
+
width: this.ctx.measureText(tc.text).width,
|
|
3312
|
+
height: tc.fontSize
|
|
3313
|
+
};
|
|
3314
|
+
}
|
|
3315
|
+
estimate({ text, fontSize }) {
|
|
3316
|
+
let eCharLen = 0;
|
|
3317
|
+
let cCharLen = 0;
|
|
3318
|
+
for (let i = 0; i < text.length; i++) {
|
|
3319
|
+
text.charCodeAt(i) < 128 ? eCharLen++ : cCharLen++;
|
|
3320
|
+
}
|
|
3321
|
+
return {
|
|
3322
|
+
width: ~~(0.8 * eCharLen * fontSize + cCharLen * fontSize),
|
|
3323
|
+
height: fontSize
|
|
3324
|
+
};
|
|
3325
|
+
}
|
|
3326
|
+
static getDefaultUtils(canvas) {
|
|
3327
|
+
if (!GraphicUtil.instance) {
|
|
3328
|
+
GraphicUtil.instance = new GraphicUtil(canvas);
|
|
3329
|
+
}
|
|
3330
|
+
return GraphicUtil.instance;
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
|
|
3334
|
+
const EPSILON = 1e-8;
|
|
3335
|
+
function lineIntersectPolygon(a1x, a1y, a2x, a2y, points) {
|
|
3336
|
+
for (let i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
|
|
3337
|
+
const p = points[i];
|
|
3338
|
+
if (isIntersect([a1x, a1y], [a2x, a2y], [p.x, p.y], [p2.x, p2.y])) {
|
|
3339
|
+
return true;
|
|
3340
|
+
}
|
|
3341
|
+
p2 = p;
|
|
3342
|
+
}
|
|
3343
|
+
return false;
|
|
3344
|
+
}
|
|
3345
|
+
function polygonContainPoint(points, x, y) {
|
|
3346
|
+
let w = 0;
|
|
3347
|
+
let p = points[0];
|
|
3348
|
+
if (!p) {
|
|
3349
|
+
return false;
|
|
3350
|
+
}
|
|
3351
|
+
for (let i = 1; i < points.length; i++) {
|
|
3352
|
+
const p2 = points[i];
|
|
3353
|
+
w += isPointInLine(p.x, p.y, p2.x, p2.y, x, y);
|
|
3354
|
+
p = p2;
|
|
3355
|
+
}
|
|
3356
|
+
const p0 = points[0];
|
|
3357
|
+
if (!isAroundEqual(p.x, p0.x) || !isAroundEqual(p.y, p0.y)) {
|
|
3358
|
+
w += isPointInLine(p.x, p.y, p0.x, p0.y, x, y);
|
|
3359
|
+
}
|
|
3360
|
+
return w !== 0;
|
|
3361
|
+
}
|
|
3362
|
+
function isPointInLine(x0, y0, x1, y1, x, y) {
|
|
3363
|
+
if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
|
|
3364
|
+
return 0;
|
|
3365
|
+
}
|
|
3366
|
+
if (y1 === y0) {
|
|
3367
|
+
return 0;
|
|
3368
|
+
}
|
|
3369
|
+
const t = (y - y0) / (y1 - y0);
|
|
3370
|
+
let dir = y1 < y0 ? 1 : -1;
|
|
3371
|
+
if (t === 1 || t === 0) {
|
|
3372
|
+
dir = y1 < y0 ? 0.5 : -0.5;
|
|
3373
|
+
}
|
|
3374
|
+
const x_ = t * (x1 - x0) + x0;
|
|
3375
|
+
return x_ === x ? Infinity : x_ > x ? dir : 0;
|
|
3376
|
+
}
|
|
3377
|
+
function isAroundEqual(a, b) {
|
|
3378
|
+
return Math.abs(a - b) < EPSILON;
|
|
3379
|
+
}
|
|
3380
|
+
function polygonIntersectPolygon(pointsA, pointsB) {
|
|
3381
|
+
for (let i = 0; i < pointsB.length; i++) {
|
|
3382
|
+
if (polygonContainPoint(pointsA, pointsB[i].x, pointsB[i].y)) {
|
|
3383
|
+
return true;
|
|
3384
|
+
}
|
|
3385
|
+
if (i > 0 && lineIntersectPolygon(pointsB[i - 1].x, pointsB[i - 1].y, pointsB[i].x, pointsB[i].y, pointsA)) {
|
|
3386
|
+
return true;
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
return false;
|
|
3390
|
+
}
|
|
3391
|
+
|
|
3392
|
+
function stringWidth(string, ambiguousCharacterIsNarrow = true) {
|
|
3393
|
+
if (typeof string !== 'string' || string.length === 0) {
|
|
3394
|
+
return 0;
|
|
3395
|
+
}
|
|
3396
|
+
string = stripAnsi(string);
|
|
3397
|
+
if (string.length === 0) {
|
|
3398
|
+
return 0;
|
|
3399
|
+
}
|
|
3400
|
+
string = string.replace(emojiRegex(), ' ');
|
|
3401
|
+
const ambiguousCharacterWidth = ambiguousCharacterIsNarrow ? 1 : 2;
|
|
3402
|
+
let width = 0;
|
|
3403
|
+
for (const character of string) {
|
|
3404
|
+
const codePoint = character.codePointAt(0);
|
|
3405
|
+
if (codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f)) {
|
|
3406
|
+
continue;
|
|
3407
|
+
}
|
|
3408
|
+
if (codePoint >= 0x300 && codePoint <= 0x36f) {
|
|
3409
|
+
continue;
|
|
3410
|
+
}
|
|
3411
|
+
const code = eastAsianCharacterInfo(character);
|
|
3412
|
+
switch (code) {
|
|
3413
|
+
case 'F':
|
|
3414
|
+
case 'W':
|
|
3415
|
+
width += 2;
|
|
3416
|
+
break;
|
|
3417
|
+
case 'A':
|
|
3418
|
+
width += ambiguousCharacterWidth;
|
|
3419
|
+
break;
|
|
3420
|
+
default:
|
|
3421
|
+
width += 1;
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
return width;
|
|
3425
|
+
}
|
|
3426
|
+
const stripAnsi = (string) => {
|
|
3427
|
+
if (typeof string !== 'string') {
|
|
3428
|
+
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
3429
|
+
}
|
|
3430
|
+
return string.replace(ansiRegex(), '');
|
|
3431
|
+
};
|
|
3432
|
+
const ansiRegex = ({ onlyFirst = false } = {}) => {
|
|
3433
|
+
const pattern = [
|
|
3434
|
+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
3435
|
+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
|
|
3436
|
+
].join('|');
|
|
3437
|
+
return new RegExp(pattern, onlyFirst ? undefined : 'g');
|
|
3438
|
+
};
|
|
3439
|
+
const eastAsianCharacterInfo = (character) => {
|
|
3440
|
+
let x = character.charCodeAt(0);
|
|
3441
|
+
let y = character.length === 2 ? character.charCodeAt(1) : 0;
|
|
3442
|
+
let codePoint = x;
|
|
3443
|
+
if (0xd800 <= x && x <= 0xdbff && 0xdc00 <= y && y <= 0xdfff) {
|
|
3444
|
+
x &= 0x3ff;
|
|
3445
|
+
y &= 0x3ff;
|
|
3446
|
+
codePoint = (x << 10) | y;
|
|
3447
|
+
codePoint += 0x10000;
|
|
3448
|
+
}
|
|
3449
|
+
if (0x3000 === codePoint ||
|
|
3450
|
+
(0xff01 <= codePoint && codePoint <= 0xff60) ||
|
|
3451
|
+
(0xffe0 <= codePoint && codePoint <= 0xffe6)) {
|
|
3452
|
+
return 'F';
|
|
3453
|
+
}
|
|
3454
|
+
if (0x20a9 === codePoint ||
|
|
3455
|
+
(0xff61 <= codePoint && codePoint <= 0xffbe) ||
|
|
3456
|
+
(0xffc2 <= codePoint && codePoint <= 0xffc7) ||
|
|
3457
|
+
(0xffca <= codePoint && codePoint <= 0xffcf) ||
|
|
3458
|
+
(0xffd2 <= codePoint && codePoint <= 0xffd7) ||
|
|
3459
|
+
(0xffda <= codePoint && codePoint <= 0xffdc) ||
|
|
3460
|
+
(0xffe8 <= codePoint && codePoint <= 0xffee)) {
|
|
3461
|
+
return 'H';
|
|
3462
|
+
}
|
|
3463
|
+
if ((0x1100 <= codePoint && codePoint <= 0x115f) ||
|
|
3464
|
+
(0x11a3 <= codePoint && codePoint <= 0x11a7) ||
|
|
3465
|
+
(0x11fa <= codePoint && codePoint <= 0x11ff) ||
|
|
3466
|
+
(0x2329 <= codePoint && codePoint <= 0x232a) ||
|
|
3467
|
+
(0x2e80 <= codePoint && codePoint <= 0x2e99) ||
|
|
3468
|
+
(0x2e9b <= codePoint && codePoint <= 0x2ef3) ||
|
|
3469
|
+
(0x2f00 <= codePoint && codePoint <= 0x2fd5) ||
|
|
3470
|
+
(0x2ff0 <= codePoint && codePoint <= 0x2ffb) ||
|
|
3471
|
+
(0x3001 <= codePoint && codePoint <= 0x303e) ||
|
|
3472
|
+
(0x3041 <= codePoint && codePoint <= 0x3096) ||
|
|
3473
|
+
(0x3099 <= codePoint && codePoint <= 0x30ff) ||
|
|
3474
|
+
(0x3105 <= codePoint && codePoint <= 0x312d) ||
|
|
3475
|
+
(0x3131 <= codePoint && codePoint <= 0x318e) ||
|
|
3476
|
+
(0x3190 <= codePoint && codePoint <= 0x31ba) ||
|
|
3477
|
+
(0x31c0 <= codePoint && codePoint <= 0x31e3) ||
|
|
3478
|
+
(0x31f0 <= codePoint && codePoint <= 0x321e) ||
|
|
3479
|
+
(0x3220 <= codePoint && codePoint <= 0x3247) ||
|
|
3480
|
+
(0x3250 <= codePoint && codePoint <= 0x32fe) ||
|
|
3481
|
+
(0x3300 <= codePoint && codePoint <= 0x4dbf) ||
|
|
3482
|
+
(0x4e00 <= codePoint && codePoint <= 0xa48c) ||
|
|
3483
|
+
(0xa490 <= codePoint && codePoint <= 0xa4c6) ||
|
|
3484
|
+
(0xa960 <= codePoint && codePoint <= 0xa97c) ||
|
|
3485
|
+
(0xac00 <= codePoint && codePoint <= 0xd7a3) ||
|
|
3486
|
+
(0xd7b0 <= codePoint && codePoint <= 0xd7c6) ||
|
|
3487
|
+
(0xd7cb <= codePoint && codePoint <= 0xd7fb) ||
|
|
3488
|
+
(0xf900 <= codePoint && codePoint <= 0xfaff) ||
|
|
3489
|
+
(0xfe10 <= codePoint && codePoint <= 0xfe19) ||
|
|
3490
|
+
(0xfe30 <= codePoint && codePoint <= 0xfe52) ||
|
|
3491
|
+
(0xfe54 <= codePoint && codePoint <= 0xfe66) ||
|
|
3492
|
+
(0xfe68 <= codePoint && codePoint <= 0xfe6b) ||
|
|
3493
|
+
(0x1b000 <= codePoint && codePoint <= 0x1b001) ||
|
|
3494
|
+
(0x1f200 <= codePoint && codePoint <= 0x1f202) ||
|
|
3495
|
+
(0x1f210 <= codePoint && codePoint <= 0x1f23a) ||
|
|
3496
|
+
(0x1f240 <= codePoint && codePoint <= 0x1f248) ||
|
|
3497
|
+
(0x1f250 <= codePoint && codePoint <= 0x1f251) ||
|
|
3498
|
+
(0x20000 <= codePoint && codePoint <= 0x2f73f) ||
|
|
3499
|
+
(0x2b740 <= codePoint && codePoint <= 0x2fffd) ||
|
|
3500
|
+
(0x30000 <= codePoint && codePoint <= 0x3fffd)) {
|
|
3501
|
+
return 'W';
|
|
3502
|
+
}
|
|
3503
|
+
if ((0x0020 <= codePoint && codePoint <= 0x007e) ||
|
|
3504
|
+
(0x00a2 <= codePoint && codePoint <= 0x00a3) ||
|
|
3505
|
+
(0x00a5 <= codePoint && codePoint <= 0x00a6) ||
|
|
3506
|
+
0x00ac === codePoint ||
|
|
3507
|
+
0x00af === codePoint ||
|
|
3508
|
+
(0x27e6 <= codePoint && codePoint <= 0x27ed) ||
|
|
3509
|
+
(0x2985 <= codePoint && codePoint <= 0x2986)) {
|
|
3510
|
+
return 'Na';
|
|
3511
|
+
}
|
|
3512
|
+
if (0x00a1 === codePoint ||
|
|
3513
|
+
0x00a4 === codePoint ||
|
|
3514
|
+
(0x00a7 <= codePoint && codePoint <= 0x00a8) ||
|
|
3515
|
+
0x00aa === codePoint ||
|
|
3516
|
+
(0x00ad <= codePoint && codePoint <= 0x00ae) ||
|
|
3517
|
+
(0x00b0 <= codePoint && codePoint <= 0x00b4) ||
|
|
3518
|
+
(0x00b6 <= codePoint && codePoint <= 0x00ba) ||
|
|
3519
|
+
(0x00bc <= codePoint && codePoint <= 0x00bf) ||
|
|
3520
|
+
0x00c6 === codePoint ||
|
|
3521
|
+
0x00d0 === codePoint ||
|
|
3522
|
+
(0x00d7 <= codePoint && codePoint <= 0x00d8) ||
|
|
3523
|
+
(0x00de <= codePoint && codePoint <= 0x00e1) ||
|
|
3524
|
+
0x00e6 === codePoint ||
|
|
3525
|
+
(0x00e8 <= codePoint && codePoint <= 0x00ea) ||
|
|
3526
|
+
(0x00ec <= codePoint && codePoint <= 0x00ed) ||
|
|
3527
|
+
0x00f0 === codePoint ||
|
|
3528
|
+
(0x00f2 <= codePoint && codePoint <= 0x00f3) ||
|
|
3529
|
+
(0x00f7 <= codePoint && codePoint <= 0x00fa) ||
|
|
3530
|
+
0x00fc === codePoint ||
|
|
3531
|
+
0x00fe === codePoint ||
|
|
3532
|
+
0x0101 === codePoint ||
|
|
3533
|
+
0x0111 === codePoint ||
|
|
3534
|
+
0x0113 === codePoint ||
|
|
3535
|
+
0x011b === codePoint ||
|
|
3536
|
+
(0x0126 <= codePoint && codePoint <= 0x0127) ||
|
|
3537
|
+
0x012b === codePoint ||
|
|
3538
|
+
(0x0131 <= codePoint && codePoint <= 0x0133) ||
|
|
3539
|
+
0x0138 === codePoint ||
|
|
3540
|
+
(0x013f <= codePoint && codePoint <= 0x0142) ||
|
|
3541
|
+
0x0144 === codePoint ||
|
|
3542
|
+
(0x0148 <= codePoint && codePoint <= 0x014b) ||
|
|
3543
|
+
0x014d === codePoint ||
|
|
3544
|
+
(0x0152 <= codePoint && codePoint <= 0x0153) ||
|
|
3545
|
+
(0x0166 <= codePoint && codePoint <= 0x0167) ||
|
|
3546
|
+
0x016b === codePoint ||
|
|
3547
|
+
0x01ce === codePoint ||
|
|
3548
|
+
0x01d0 === codePoint ||
|
|
3549
|
+
0x01d2 === codePoint ||
|
|
3550
|
+
0x01d4 === codePoint ||
|
|
3551
|
+
0x01d6 === codePoint ||
|
|
3552
|
+
0x01d8 === codePoint ||
|
|
3553
|
+
0x01da === codePoint ||
|
|
3554
|
+
0x01dc === codePoint ||
|
|
3555
|
+
0x0251 === codePoint ||
|
|
3556
|
+
0x0261 === codePoint ||
|
|
3557
|
+
0x02c4 === codePoint ||
|
|
3558
|
+
0x02c7 === codePoint ||
|
|
3559
|
+
(0x02c9 <= codePoint && codePoint <= 0x02cb) ||
|
|
3560
|
+
0x02cd === codePoint ||
|
|
3561
|
+
0x02d0 === codePoint ||
|
|
3562
|
+
(0x02d8 <= codePoint && codePoint <= 0x02db) ||
|
|
3563
|
+
0x02dd === codePoint ||
|
|
3564
|
+
0x02df === codePoint ||
|
|
3565
|
+
(0x0300 <= codePoint && codePoint <= 0x036f) ||
|
|
3566
|
+
(0x0391 <= codePoint && codePoint <= 0x03a1) ||
|
|
3567
|
+
(0x03a3 <= codePoint && codePoint <= 0x03a9) ||
|
|
3568
|
+
(0x03b1 <= codePoint && codePoint <= 0x03c1) ||
|
|
3569
|
+
(0x03c3 <= codePoint && codePoint <= 0x03c9) ||
|
|
3570
|
+
0x0401 === codePoint ||
|
|
3571
|
+
(0x0410 <= codePoint && codePoint <= 0x044f) ||
|
|
3572
|
+
0x0451 === codePoint ||
|
|
3573
|
+
0x2010 === codePoint ||
|
|
3574
|
+
(0x2013 <= codePoint && codePoint <= 0x2016) ||
|
|
3575
|
+
(0x2018 <= codePoint && codePoint <= 0x2019) ||
|
|
3576
|
+
(0x201c <= codePoint && codePoint <= 0x201d) ||
|
|
3577
|
+
(0x2020 <= codePoint && codePoint <= 0x2022) ||
|
|
3578
|
+
(0x2024 <= codePoint && codePoint <= 0x2027) ||
|
|
3579
|
+
0x2030 === codePoint ||
|
|
3580
|
+
(0x2032 <= codePoint && codePoint <= 0x2033) ||
|
|
3581
|
+
0x2035 === codePoint ||
|
|
3582
|
+
0x203b === codePoint ||
|
|
3583
|
+
0x203e === codePoint ||
|
|
3584
|
+
0x2074 === codePoint ||
|
|
3585
|
+
0x207f === codePoint ||
|
|
3586
|
+
(0x2081 <= codePoint && codePoint <= 0x2084) ||
|
|
3587
|
+
0x20ac === codePoint ||
|
|
3588
|
+
0x2103 === codePoint ||
|
|
3589
|
+
0x2105 === codePoint ||
|
|
3590
|
+
0x2109 === codePoint ||
|
|
3591
|
+
0x2113 === codePoint ||
|
|
3592
|
+
0x2116 === codePoint ||
|
|
3593
|
+
(0x2121 <= codePoint && codePoint <= 0x2122) ||
|
|
3594
|
+
0x2126 === codePoint ||
|
|
3595
|
+
0x212b === codePoint ||
|
|
3596
|
+
(0x2153 <= codePoint && codePoint <= 0x2154) ||
|
|
3597
|
+
(0x215b <= codePoint && codePoint <= 0x215e) ||
|
|
3598
|
+
(0x2160 <= codePoint && codePoint <= 0x216b) ||
|
|
3599
|
+
(0x2170 <= codePoint && codePoint <= 0x2179) ||
|
|
3600
|
+
0x2189 === codePoint ||
|
|
3601
|
+
(0x2190 <= codePoint && codePoint <= 0x2199) ||
|
|
3602
|
+
(0x21b8 <= codePoint && codePoint <= 0x21b9) ||
|
|
3603
|
+
0x21d2 === codePoint ||
|
|
3604
|
+
0x21d4 === codePoint ||
|
|
3605
|
+
0x21e7 === codePoint ||
|
|
3606
|
+
0x2200 === codePoint ||
|
|
3607
|
+
(0x2202 <= codePoint && codePoint <= 0x2203) ||
|
|
3608
|
+
(0x2207 <= codePoint && codePoint <= 0x2208) ||
|
|
3609
|
+
0x220b === codePoint ||
|
|
3610
|
+
0x220f === codePoint ||
|
|
3611
|
+
0x2211 === codePoint ||
|
|
3612
|
+
0x2215 === codePoint ||
|
|
3613
|
+
0x221a === codePoint ||
|
|
3614
|
+
(0x221d <= codePoint && codePoint <= 0x2220) ||
|
|
3615
|
+
0x2223 === codePoint ||
|
|
3616
|
+
0x2225 === codePoint ||
|
|
3617
|
+
(0x2227 <= codePoint && codePoint <= 0x222c) ||
|
|
3618
|
+
0x222e === codePoint ||
|
|
3619
|
+
(0x2234 <= codePoint && codePoint <= 0x2237) ||
|
|
3620
|
+
(0x223c <= codePoint && codePoint <= 0x223d) ||
|
|
3621
|
+
0x2248 === codePoint ||
|
|
3622
|
+
0x224c === codePoint ||
|
|
3623
|
+
0x2252 === codePoint ||
|
|
3624
|
+
(0x2260 <= codePoint && codePoint <= 0x2261) ||
|
|
3625
|
+
(0x2264 <= codePoint && codePoint <= 0x2267) ||
|
|
3626
|
+
(0x226a <= codePoint && codePoint <= 0x226b) ||
|
|
3627
|
+
(0x226e <= codePoint && codePoint <= 0x226f) ||
|
|
3628
|
+
(0x2282 <= codePoint && codePoint <= 0x2283) ||
|
|
3629
|
+
(0x2286 <= codePoint && codePoint <= 0x2287) ||
|
|
3630
|
+
0x2295 === codePoint ||
|
|
3631
|
+
0x2299 === codePoint ||
|
|
3632
|
+
0x22a5 === codePoint ||
|
|
3633
|
+
0x22bf === codePoint ||
|
|
3634
|
+
0x2312 === codePoint ||
|
|
3635
|
+
(0x2460 <= codePoint && codePoint <= 0x24e9) ||
|
|
3636
|
+
(0x24eb <= codePoint && codePoint <= 0x254b) ||
|
|
3637
|
+
(0x2550 <= codePoint && codePoint <= 0x2573) ||
|
|
3638
|
+
(0x2580 <= codePoint && codePoint <= 0x258f) ||
|
|
3639
|
+
(0x2592 <= codePoint && codePoint <= 0x2595) ||
|
|
3640
|
+
(0x25a0 <= codePoint && codePoint <= 0x25a1) ||
|
|
3641
|
+
(0x25a3 <= codePoint && codePoint <= 0x25a9) ||
|
|
3642
|
+
(0x25b2 <= codePoint && codePoint <= 0x25b3) ||
|
|
3643
|
+
(0x25b6 <= codePoint && codePoint <= 0x25b7) ||
|
|
3644
|
+
(0x25bc <= codePoint && codePoint <= 0x25bd) ||
|
|
3645
|
+
(0x25c0 <= codePoint && codePoint <= 0x25c1) ||
|
|
3646
|
+
(0x25c6 <= codePoint && codePoint <= 0x25c8) ||
|
|
3647
|
+
0x25cb === codePoint ||
|
|
3648
|
+
(0x25ce <= codePoint && codePoint <= 0x25d1) ||
|
|
3649
|
+
(0x25e2 <= codePoint && codePoint <= 0x25e5) ||
|
|
3650
|
+
0x25ef === codePoint ||
|
|
3651
|
+
(0x2605 <= codePoint && codePoint <= 0x2606) ||
|
|
3652
|
+
0x2609 === codePoint ||
|
|
3653
|
+
(0x260e <= codePoint && codePoint <= 0x260f) ||
|
|
3654
|
+
(0x2614 <= codePoint && codePoint <= 0x2615) ||
|
|
3655
|
+
0x261c === codePoint ||
|
|
3656
|
+
0x261e === codePoint ||
|
|
3657
|
+
0x2640 === codePoint ||
|
|
3658
|
+
0x2642 === codePoint ||
|
|
3659
|
+
(0x2660 <= codePoint && codePoint <= 0x2661) ||
|
|
3660
|
+
(0x2663 <= codePoint && codePoint <= 0x2665) ||
|
|
3661
|
+
(0x2667 <= codePoint && codePoint <= 0x266a) ||
|
|
3662
|
+
(0x266c <= codePoint && codePoint <= 0x266d) ||
|
|
3663
|
+
0x266f === codePoint ||
|
|
3664
|
+
(0x269e <= codePoint && codePoint <= 0x269f) ||
|
|
3665
|
+
(0x26be <= codePoint && codePoint <= 0x26bf) ||
|
|
3666
|
+
(0x26c4 <= codePoint && codePoint <= 0x26cd) ||
|
|
3667
|
+
(0x26cf <= codePoint && codePoint <= 0x26e1) ||
|
|
3668
|
+
0x26e3 === codePoint ||
|
|
3669
|
+
(0x26e8 <= codePoint && codePoint <= 0x26ff) ||
|
|
3670
|
+
0x273d === codePoint ||
|
|
3671
|
+
0x2757 === codePoint ||
|
|
3672
|
+
(0x2776 <= codePoint && codePoint <= 0x277f) ||
|
|
3673
|
+
(0x2b55 <= codePoint && codePoint <= 0x2b59) ||
|
|
3674
|
+
(0x3248 <= codePoint && codePoint <= 0x324f) ||
|
|
3675
|
+
(0xe000 <= codePoint && codePoint <= 0xf8ff) ||
|
|
3676
|
+
(0xfe00 <= codePoint && codePoint <= 0xfe0f) ||
|
|
3677
|
+
0xfffd === codePoint ||
|
|
3678
|
+
(0x1f100 <= codePoint && codePoint <= 0x1f10a) ||
|
|
3679
|
+
(0x1f110 <= codePoint && codePoint <= 0x1f12d) ||
|
|
3680
|
+
(0x1f130 <= codePoint && codePoint <= 0x1f169) ||
|
|
3681
|
+
(0x1f170 <= codePoint && codePoint <= 0x1f19a) ||
|
|
3682
|
+
(0xe0100 <= codePoint && codePoint <= 0xe01ef) ||
|
|
3683
|
+
(0xf0000 <= codePoint && codePoint <= 0xffffd) ||
|
|
3684
|
+
(0x100000 <= codePoint && codePoint <= 0x10fffd)) {
|
|
3685
|
+
return 'A';
|
|
3686
|
+
}
|
|
3687
|
+
return 'N';
|
|
3688
|
+
};
|
|
3689
|
+
const emojiRegex = () => {
|
|
3690
|
+
return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26F9(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC3\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC08\uDC26](?:\u200D\u2B1B)?|[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC2\uDECE-\uDEDB\uDEE0-\uDEE8]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
|
|
3691
|
+
};
|
|
3692
|
+
|
|
3693
|
+
function getContextFont(text, defaultAttr = {}) {
|
|
3694
|
+
const { fontStyle = defaultAttr.fontStyle, fontVariant = defaultAttr.fontVariant, fontWeight = defaultAttr.fontWeight, fontSize = defaultAttr.fontSize, fontFamily = defaultAttr.fontFamily } = text;
|
|
3695
|
+
return ('' +
|
|
3696
|
+
(fontStyle ? fontStyle + ' ' : '') +
|
|
3697
|
+
(fontVariant ? fontVariant + ' ' : '') +
|
|
3698
|
+
(fontWeight ? fontWeight + ' ' : '') +
|
|
3699
|
+
fontSize +
|
|
3700
|
+
'px ' +
|
|
3701
|
+
(fontFamily ? fontFamily : 'sans-serif'));
|
|
3702
|
+
}
|
|
3703
|
+
|
|
3704
|
+
class TextMeasure {
|
|
3705
|
+
static ALPHABET_CHAR_SET = 'abcdefghijklmnopqrstuvwxyz';
|
|
3706
|
+
static NUMBERS_CHAR_SET = '0123456789';
|
|
3707
|
+
static FULL_SIZE_CHAR = '字';
|
|
3708
|
+
_numberCharSize = null;
|
|
3709
|
+
_fullCharSize = null;
|
|
3710
|
+
_letterCharSize = null;
|
|
3711
|
+
_specialCharSizeMap = {};
|
|
3712
|
+
_canvas = null;
|
|
3713
|
+
_context = null;
|
|
3714
|
+
_contextSaved = false;
|
|
3715
|
+
_notSupportCanvas = false;
|
|
3716
|
+
_notSupportVRender = false;
|
|
3717
|
+
_userSpec = {};
|
|
3718
|
+
textSpec;
|
|
3719
|
+
_option;
|
|
3720
|
+
_standardMethod;
|
|
3721
|
+
specialCharSet = '-/: .,@%\'"~';
|
|
3722
|
+
constructor(option, textSpec) {
|
|
3723
|
+
this._option = option;
|
|
3724
|
+
this._userSpec = textSpec ?? {};
|
|
3725
|
+
this.textSpec = this._initSpec();
|
|
3726
|
+
if (isValid(option.specialCharSet)) {
|
|
3727
|
+
this.specialCharSet = option.specialCharSet;
|
|
3728
|
+
}
|
|
3729
|
+
this._standardMethod = isValid(option.getTextBounds)
|
|
3730
|
+
? this.fullMeasure.bind(this)
|
|
3731
|
+
: this.measureWithNaiveCanvas.bind(this);
|
|
3732
|
+
}
|
|
3733
|
+
initContext() {
|
|
3734
|
+
if (this._notSupportCanvas) {
|
|
3735
|
+
return false;
|
|
3736
|
+
}
|
|
3737
|
+
if (isNil(this._canvas)) {
|
|
3738
|
+
if (isValid(this._option.getCanvasForMeasure)) {
|
|
3739
|
+
this._canvas = this._option.getCanvasForMeasure();
|
|
3740
|
+
}
|
|
3741
|
+
if (isNil(this._canvas) &&
|
|
3742
|
+
typeof window !== 'undefined' &&
|
|
3743
|
+
typeof window.document !== 'undefined' &&
|
|
3744
|
+
isValid(globalThis.document)) {
|
|
3745
|
+
this._canvas = globalThis.document.createElement('canvas');
|
|
3746
|
+
}
|
|
3747
|
+
}
|
|
3748
|
+
if (isNil(this._context) && isValid(this._canvas)) {
|
|
3749
|
+
const context = this._canvas.getContext('2d');
|
|
3750
|
+
if (isValid(context)) {
|
|
3751
|
+
context.save();
|
|
3752
|
+
context.font = getContextFont(this.textSpec);
|
|
3753
|
+
this._contextSaved = true;
|
|
3754
|
+
this._context = context;
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
if (isNil(this._context)) {
|
|
3758
|
+
this._notSupportCanvas = true;
|
|
3759
|
+
return false;
|
|
3760
|
+
}
|
|
3761
|
+
return true;
|
|
3762
|
+
}
|
|
3763
|
+
_initSpec() {
|
|
3764
|
+
const { defaultFontParams = {} } = this._option;
|
|
3765
|
+
const { fontStyle = defaultFontParams.fontStyle, fontVariant = defaultFontParams.fontVariant, fontWeight = defaultFontParams.fontWeight ?? 'normal', fontSize = defaultFontParams.fontSize ?? 12, fontFamily = defaultFontParams.fontFamily ?? 'sans-serif', align, textAlign = align ?? 'center', baseline, textBaseline = baseline ?? 'middle', ellipsis, limit, lineHeight = fontSize } = this._userSpec;
|
|
3766
|
+
return {
|
|
3767
|
+
fontStyle,
|
|
3768
|
+
fontVariant,
|
|
3769
|
+
fontFamily,
|
|
3770
|
+
fontSize,
|
|
3771
|
+
fontWeight,
|
|
3772
|
+
textAlign,
|
|
3773
|
+
textBaseline,
|
|
3774
|
+
ellipsis,
|
|
3775
|
+
limit,
|
|
3776
|
+
lineHeight
|
|
3777
|
+
};
|
|
3778
|
+
}
|
|
3779
|
+
measure(text, method) {
|
|
3780
|
+
switch (method) {
|
|
3781
|
+
case 'vrender':
|
|
3782
|
+
case 'canopus':
|
|
3783
|
+
return this.fullMeasure(text);
|
|
3784
|
+
case 'canvas':
|
|
3785
|
+
return this.measureWithNaiveCanvas(text);
|
|
3786
|
+
case 'simple':
|
|
3787
|
+
return this.quickMeasureWithoutCanvas(text);
|
|
3788
|
+
case 'quick':
|
|
3789
|
+
default:
|
|
3790
|
+
return this.quickMeasure(text);
|
|
3791
|
+
}
|
|
3792
|
+
}
|
|
3793
|
+
fullMeasure(text) {
|
|
3794
|
+
if (isNil(text)) {
|
|
3795
|
+
return { width: 0, height: 0 };
|
|
3796
|
+
}
|
|
3797
|
+
if (isNil(this._option.getTextBounds) || !this._notSupportVRender) {
|
|
3798
|
+
return this.measureWithNaiveCanvas(text);
|
|
3799
|
+
}
|
|
3800
|
+
const { fontFamily, fontSize, fontWeight, textAlign, textBaseline, ellipsis, limit, lineHeight } = this.textSpec;
|
|
3801
|
+
let size;
|
|
3802
|
+
try {
|
|
3803
|
+
const bounds = this._option.getTextBounds({
|
|
3804
|
+
text,
|
|
3805
|
+
fontFamily,
|
|
3806
|
+
fontSize,
|
|
3807
|
+
fontWeight,
|
|
3808
|
+
textAlign,
|
|
3809
|
+
textBaseline,
|
|
3810
|
+
ellipsis: !!ellipsis,
|
|
3811
|
+
maxLineWidth: limit || Infinity,
|
|
3812
|
+
lineHeight
|
|
3813
|
+
});
|
|
3814
|
+
size = { width: bounds.width(), height: bounds.height() };
|
|
3815
|
+
}
|
|
3816
|
+
catch (e) {
|
|
3817
|
+
this._notSupportVRender = true;
|
|
3818
|
+
size = this.measureWithNaiveCanvas(text);
|
|
3819
|
+
}
|
|
3820
|
+
return size;
|
|
3821
|
+
}
|
|
3822
|
+
measureWithNaiveCanvas(text) {
|
|
3823
|
+
return this._measureReduce(text, this._measureWithNaiveCanvas.bind(this));
|
|
3824
|
+
}
|
|
3825
|
+
_measureWithNaiveCanvas(text) {
|
|
3826
|
+
if (!this.initContext()) {
|
|
3827
|
+
return this._quickMeasureWithoutCanvas(text);
|
|
3828
|
+
}
|
|
3829
|
+
const metrics = this._context.measureText(text);
|
|
3830
|
+
const { fontSize, lineHeight } = this.textSpec;
|
|
3831
|
+
return { width: metrics.width, height: lineHeight ?? fontSize };
|
|
3832
|
+
}
|
|
3833
|
+
quickMeasure(text) {
|
|
3834
|
+
return this._measureReduce(text, this._quickMeasure.bind(this));
|
|
3835
|
+
}
|
|
3836
|
+
_quickMeasure(text) {
|
|
3837
|
+
const totalSize = {
|
|
3838
|
+
width: 0,
|
|
3839
|
+
height: 0
|
|
3840
|
+
};
|
|
3841
|
+
for (let i = 0; i < text.length; i++) {
|
|
3842
|
+
const char = text[i];
|
|
3843
|
+
let size = this._measureSpecialChar(char);
|
|
3844
|
+
if (isNil(size) && TextMeasure.NUMBERS_CHAR_SET.includes(char)) {
|
|
3845
|
+
size = this._measureNumberChar();
|
|
3846
|
+
}
|
|
3847
|
+
if (isNil(size) && ['F', 'W'].includes(eastAsianCharacterInfo(char))) {
|
|
3848
|
+
size = this._measureFullSizeChar();
|
|
3849
|
+
}
|
|
3850
|
+
if (isNil(size)) {
|
|
3851
|
+
size = this._measureLetterChar();
|
|
3852
|
+
}
|
|
3853
|
+
totalSize.width += size.width;
|
|
3854
|
+
totalSize.height = Math.max(totalSize.height, size.height);
|
|
3855
|
+
}
|
|
3856
|
+
return totalSize;
|
|
3857
|
+
}
|
|
3858
|
+
quickMeasureWithoutCanvas(text) {
|
|
3859
|
+
return this._measureReduce(text, this._quickMeasureWithoutCanvas.bind(this));
|
|
3860
|
+
}
|
|
3861
|
+
_quickMeasureWithoutCanvas(text) {
|
|
3862
|
+
const totalSize = {
|
|
3863
|
+
width: 0,
|
|
3864
|
+
height: 0
|
|
3865
|
+
};
|
|
3866
|
+
const { fontSize, lineHeight } = this.textSpec;
|
|
3867
|
+
for (let i = 0; i < text.length; i++) {
|
|
3868
|
+
const char = text[i];
|
|
3869
|
+
const size = ['F', 'W'].includes(eastAsianCharacterInfo(char)) ? 1 : 0.53;
|
|
3870
|
+
totalSize.width += size * fontSize;
|
|
3871
|
+
}
|
|
3872
|
+
totalSize.height = lineHeight ?? fontSize;
|
|
3873
|
+
return totalSize;
|
|
3874
|
+
}
|
|
3875
|
+
_measureReduce(text, processor) {
|
|
3876
|
+
const { fontSize, lineHeight } = this.textSpec;
|
|
3877
|
+
const defaultResult = { width: 0, height: 0 };
|
|
3878
|
+
if (isNil(text)) {
|
|
3879
|
+
return defaultResult;
|
|
3880
|
+
}
|
|
3881
|
+
else if (isArray(text)) {
|
|
3882
|
+
const textArr = text.filter(isValid).map(s => s.toString());
|
|
3883
|
+
if (textArr.length === 0) {
|
|
3884
|
+
return defaultResult;
|
|
3885
|
+
}
|
|
3886
|
+
else if (textArr.length === 1) {
|
|
3887
|
+
return processor(textArr[0]);
|
|
3888
|
+
}
|
|
3889
|
+
return {
|
|
3890
|
+
width: textArr.reduce((maxWidth, cur) => Math.max(maxWidth, processor(cur).width), 0),
|
|
3891
|
+
height: textArr.length * ((lineHeight ?? fontSize) + 1) + 1
|
|
3892
|
+
};
|
|
3893
|
+
}
|
|
3894
|
+
return processor(text.toString());
|
|
3895
|
+
}
|
|
3896
|
+
_measureNumberChar() {
|
|
3897
|
+
if (isNil(this._numberCharSize)) {
|
|
3898
|
+
const numberBounds = this._standardMethod(TextMeasure.NUMBERS_CHAR_SET);
|
|
3899
|
+
this._numberCharSize = {
|
|
3900
|
+
width: numberBounds.width / TextMeasure.NUMBERS_CHAR_SET.length,
|
|
3901
|
+
height: numberBounds.height
|
|
3902
|
+
};
|
|
3903
|
+
}
|
|
3904
|
+
return this._numberCharSize;
|
|
3905
|
+
}
|
|
3906
|
+
_measureFullSizeChar() {
|
|
3907
|
+
if (isNil(this._fullCharSize)) {
|
|
3908
|
+
this._fullCharSize = this._standardMethod(TextMeasure.FULL_SIZE_CHAR);
|
|
3909
|
+
}
|
|
3910
|
+
return this._fullCharSize;
|
|
3911
|
+
}
|
|
3912
|
+
_measureLetterChar() {
|
|
3913
|
+
if (isNil(this._letterCharSize)) {
|
|
3914
|
+
const alphabetBounds = this._standardMethod(TextMeasure.ALPHABET_CHAR_SET);
|
|
3915
|
+
this._letterCharSize = {
|
|
3916
|
+
width: alphabetBounds.width / TextMeasure.ALPHABET_CHAR_SET.length,
|
|
3917
|
+
height: alphabetBounds.height
|
|
3918
|
+
};
|
|
3919
|
+
}
|
|
3920
|
+
return this._letterCharSize;
|
|
3921
|
+
}
|
|
3922
|
+
_measureSpecialChar(char) {
|
|
3923
|
+
if (isValid(this._specialCharSizeMap[char])) {
|
|
3924
|
+
return this._specialCharSizeMap[char];
|
|
3925
|
+
}
|
|
3926
|
+
if (this.specialCharSet.includes(char)) {
|
|
3927
|
+
this._specialCharSizeMap[char] = this._standardMethod(char);
|
|
3928
|
+
return this._specialCharSizeMap[char];
|
|
3929
|
+
}
|
|
3930
|
+
return null;
|
|
3931
|
+
}
|
|
3932
|
+
release() {
|
|
3933
|
+
if (isValid(this._canvas)) {
|
|
3934
|
+
this._canvas = null;
|
|
3935
|
+
}
|
|
3936
|
+
if (isValid(this._context)) {
|
|
3937
|
+
if (this._contextSaved) {
|
|
3938
|
+
this._context.restore();
|
|
3939
|
+
this._contextSaved = false;
|
|
3940
|
+
}
|
|
3941
|
+
this._context = null;
|
|
3942
|
+
}
|
|
3943
|
+
}
|
|
3944
|
+
}
|
|
3945
|
+
|
|
3946
|
+
const getNumberChar = () => {
|
|
3947
|
+
return TestTextMeasure.NUMBERS_CHAR_SET[Math.floor(Math.random() * TestTextMeasure.NUMBERS_CHAR_SET.length)];
|
|
3948
|
+
};
|
|
3949
|
+
const getTestNumbers = (length) => Array(length).fill(0).map(getNumberChar).join('');
|
|
3950
|
+
const getLetterChar = () => {
|
|
3951
|
+
return TestTextMeasure.ALPHABET_CHAR_SET[Math.floor(Math.random() * TestTextMeasure.ALPHABET_CHAR_SET.length)];
|
|
3952
|
+
};
|
|
3953
|
+
const getTestWord = (length) => Array(length).fill(0).map(getLetterChar).join('');
|
|
3954
|
+
class TestTextMeasure extends TextMeasure {
|
|
3955
|
+
test(methods, getStrCallback, count) {
|
|
3956
|
+
const sub = (numbers) => numbers.reduce((sum, cur) => sum + cur, 0);
|
|
3957
|
+
const mean = (numbers) => sub(numbers) / numbers.length;
|
|
3958
|
+
const variance = (numbers) => {
|
|
3959
|
+
const m = mean(numbers);
|
|
3960
|
+
return mean(numbers.map(num => Math.pow(num - m, 2)));
|
|
3961
|
+
};
|
|
3962
|
+
const callback = getStrCallback ?? (() => `测试${getTestWord(8)} ${getTestNumbers(4)}/${getTestNumbers(2)}-${getTestNumbers(2)}`);
|
|
3963
|
+
const textArr = Array(count ?? 100000)
|
|
3964
|
+
.fill(0)
|
|
3965
|
+
.map(callback);
|
|
3966
|
+
const methodMap = {
|
|
3967
|
+
vrender: this.fullMeasure.bind(this),
|
|
3968
|
+
canvas: this.measureWithNaiveCanvas.bind(this),
|
|
3969
|
+
simple: this.quickMeasureWithoutCanvas.bind(this),
|
|
3970
|
+
quick: this.quickMeasure.bind(this),
|
|
3971
|
+
old: (text) => {
|
|
3972
|
+
if (isNil(text)) {
|
|
3973
|
+
return { width: 0, height: 0 };
|
|
3974
|
+
}
|
|
3975
|
+
const str = text.toString();
|
|
3976
|
+
const { fontSize } = this.textSpec;
|
|
3977
|
+
return {
|
|
3978
|
+
width: fontSize * 0.8 * str.length,
|
|
3979
|
+
height: fontSize
|
|
3980
|
+
};
|
|
3981
|
+
}
|
|
3982
|
+
};
|
|
3983
|
+
const methodList = methods ?? Object.keys(methodMap);
|
|
3984
|
+
const report = {};
|
|
3985
|
+
const timetmp = performance.now();
|
|
3986
|
+
const standardResult = textArr.map(this._standardMethod);
|
|
3987
|
+
const standardTime = performance.now() - timetmp;
|
|
3988
|
+
report.standard = {
|
|
3989
|
+
time: standardTime
|
|
3990
|
+
};
|
|
3991
|
+
methodList.forEach(method => {
|
|
3992
|
+
const testMethod = methodMap[method];
|
|
3993
|
+
if (testMethod) {
|
|
3994
|
+
const timetmp = performance.now();
|
|
3995
|
+
const testResult = textArr.map(testMethod);
|
|
3996
|
+
const testTime = performance.now() - timetmp;
|
|
3997
|
+
const errList = textArr.map((_, i) => ({
|
|
3998
|
+
width: testResult[i].width - standardResult[i].width,
|
|
3999
|
+
height: testResult[i].height - standardResult[i].height
|
|
4000
|
+
}));
|
|
4001
|
+
report[method] = {
|
|
4002
|
+
errMean: {
|
|
4003
|
+
width: mean(errList.map(e => e.width)),
|
|
4004
|
+
height: mean(errList.map(e => e.height))
|
|
4005
|
+
},
|
|
4006
|
+
errVar: {
|
|
4007
|
+
width: variance(errList.map(e => e.width)),
|
|
4008
|
+
height: variance(errList.map(e => e.height))
|
|
4009
|
+
},
|
|
4010
|
+
time: testTime
|
|
4011
|
+
};
|
|
4012
|
+
}
|
|
4013
|
+
});
|
|
4014
|
+
return {
|
|
4015
|
+
report,
|
|
4016
|
+
textArr
|
|
4017
|
+
};
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
|
|
4021
|
+
function log(method, level, input) {
|
|
4022
|
+
const hasConsole = typeof console !== 'undefined';
|
|
4023
|
+
if (hasConsole) {
|
|
4024
|
+
const args = [level].concat([].slice.call(input));
|
|
4025
|
+
console[method].apply(console, args);
|
|
4026
|
+
}
|
|
4027
|
+
}
|
|
4028
|
+
const None = 0;
|
|
4029
|
+
const Error$1 = 1;
|
|
4030
|
+
const Warn = 2;
|
|
4031
|
+
const Info = 3;
|
|
4032
|
+
const Debug = 4;
|
|
4033
|
+
function logger(logLevel, method) {
|
|
4034
|
+
let level = logLevel || None;
|
|
4035
|
+
return {
|
|
4036
|
+
level(levelValue) {
|
|
4037
|
+
if (arguments.length) {
|
|
4038
|
+
level = +levelValue;
|
|
4039
|
+
return this;
|
|
4040
|
+
}
|
|
4041
|
+
return level;
|
|
4042
|
+
},
|
|
4043
|
+
error(...args) {
|
|
4044
|
+
if (level >= Error$1) {
|
|
4045
|
+
log(method || 'error', 'ERROR', args);
|
|
4046
|
+
}
|
|
4047
|
+
return this;
|
|
4048
|
+
},
|
|
4049
|
+
warn(...args) {
|
|
4050
|
+
if (level >= Warn) {
|
|
4051
|
+
log(method || 'warn', 'WARN', args);
|
|
4052
|
+
}
|
|
4053
|
+
return this;
|
|
4054
|
+
},
|
|
4055
|
+
info(...args) {
|
|
4056
|
+
if (level >= Info) {
|
|
4057
|
+
log(method || 'log', 'INFO', args);
|
|
4058
|
+
}
|
|
4059
|
+
return this;
|
|
4060
|
+
},
|
|
4061
|
+
debug(...args) {
|
|
4062
|
+
if (level >= Debug) {
|
|
4063
|
+
log(method || 'log', 'DEBUG', args);
|
|
4064
|
+
}
|
|
4065
|
+
return this;
|
|
4066
|
+
}
|
|
4067
|
+
};
|
|
4068
|
+
}
|
|
4069
|
+
|
|
4070
|
+
var logger$1 = /*#__PURE__*/Object.freeze({
|
|
4071
|
+
__proto__: null,
|
|
4072
|
+
Debug: Debug,
|
|
4073
|
+
Error: Error$1,
|
|
4074
|
+
Info: Info,
|
|
4075
|
+
None: None,
|
|
4076
|
+
Warn: Warn,
|
|
4077
|
+
logger: logger
|
|
4078
|
+
});
|
|
4079
|
+
|
|
4080
|
+
function normalizePadding(padding) {
|
|
4081
|
+
if (isValidNumber(padding)) {
|
|
4082
|
+
return [padding, padding, padding, padding];
|
|
4083
|
+
}
|
|
4084
|
+
if (isArray(padding)) {
|
|
4085
|
+
const length = padding.length;
|
|
4086
|
+
if (length === 1) {
|
|
4087
|
+
const paddingValue = padding[0];
|
|
4088
|
+
return [paddingValue, paddingValue, paddingValue, paddingValue];
|
|
4089
|
+
}
|
|
4090
|
+
if (length === 2) {
|
|
4091
|
+
const [vertical, horizontal] = padding;
|
|
4092
|
+
return [vertical, horizontal, vertical, horizontal];
|
|
4093
|
+
}
|
|
4094
|
+
if (length === 3) {
|
|
4095
|
+
const [top, horizontal, bottom] = padding;
|
|
4096
|
+
return [top, horizontal, bottom, horizontal];
|
|
4097
|
+
}
|
|
4098
|
+
if (length === 4) {
|
|
4099
|
+
return padding;
|
|
4100
|
+
}
|
|
4101
|
+
}
|
|
4102
|
+
if (isObject(padding)) {
|
|
4103
|
+
const { top = 0, right = 0, bottom = 0, left = 0 } = padding;
|
|
4104
|
+
return [top, right, bottom, left];
|
|
4105
|
+
}
|
|
4106
|
+
return [0, 0, 0, 0];
|
|
4107
|
+
}
|
|
4108
|
+
|
|
4109
|
+
function fullYearGetterName(isUTC) {
|
|
4110
|
+
return isUTC ? 'getUTCFullYear' : 'getFullYear';
|
|
4111
|
+
}
|
|
4112
|
+
function monthGetterName(isUTC) {
|
|
4113
|
+
return isUTC ? 'getUTCMonth' : 'getMonth';
|
|
4114
|
+
}
|
|
4115
|
+
function dateGetterName(isUTC) {
|
|
4116
|
+
return isUTC ? 'getUTCDate' : 'getDate';
|
|
4117
|
+
}
|
|
4118
|
+
function hoursGetterName(isUTC) {
|
|
4119
|
+
return isUTC ? 'getUTCHours' : 'getHours';
|
|
4120
|
+
}
|
|
4121
|
+
function minutesGetterName(isUTC) {
|
|
4122
|
+
return isUTC ? 'getUTCMinutes' : 'getMinutes';
|
|
4123
|
+
}
|
|
4124
|
+
function secondsGetterName(isUTC) {
|
|
4125
|
+
return isUTC ? 'getUTCSeconds' : 'getSeconds';
|
|
4126
|
+
}
|
|
4127
|
+
function millisecondsGetterName(isUTC) {
|
|
4128
|
+
return isUTC ? 'getUTCMilliseconds' : 'getMilliseconds';
|
|
4129
|
+
}
|
|
4130
|
+
function fullYearSetterName(isUTC) {
|
|
4131
|
+
return isUTC ? 'setUTCFullYear' : 'setFullYear';
|
|
4132
|
+
}
|
|
4133
|
+
function monthSetterName(isUTC) {
|
|
4134
|
+
return isUTC ? 'setUTCMonth' : 'setMonth';
|
|
4135
|
+
}
|
|
4136
|
+
function dateSetterName(isUTC) {
|
|
4137
|
+
return isUTC ? 'setUTCDate' : 'setDate';
|
|
4138
|
+
}
|
|
4139
|
+
function hoursSetterName(isUTC) {
|
|
4140
|
+
return isUTC ? 'setUTCHours' : 'setHours';
|
|
4141
|
+
}
|
|
4142
|
+
function minutesSetterName(isUTC) {
|
|
4143
|
+
return isUTC ? 'setUTCMinutes' : 'setMinutes';
|
|
4144
|
+
}
|
|
4145
|
+
function secondsSetterName(isUTC) {
|
|
4146
|
+
return isUTC ? 'setUTCSeconds' : 'setSeconds';
|
|
4147
|
+
}
|
|
4148
|
+
function millisecondsSetterName(isUTC) {
|
|
4149
|
+
return isUTC ? 'setUTCMilliseconds' : 'setMilliseconds';
|
|
4150
|
+
}
|
|
4151
|
+
function getFormatFromValue(value, isUTC) {
|
|
4152
|
+
const date = toDate(value);
|
|
4153
|
+
const M = date[monthGetterName(isUTC)]() + 1;
|
|
4154
|
+
const d = date[dateGetterName(isUTC)]();
|
|
4155
|
+
const h = date[hoursGetterName(isUTC)]();
|
|
4156
|
+
const m = date[minutesGetterName(isUTC)]();
|
|
4157
|
+
const s = date[secondsGetterName(isUTC)]();
|
|
4158
|
+
const S = date[millisecondsGetterName(isUTC)]();
|
|
4159
|
+
const isSecond = S === 0;
|
|
4160
|
+
const isMinute = isSecond && s === 0;
|
|
4161
|
+
const isHour = isMinute && m === 0;
|
|
4162
|
+
const isDay = isHour && h === 0;
|
|
4163
|
+
const isMonth = isDay && d === 1;
|
|
4164
|
+
const isYear = isMonth && M === 1;
|
|
4165
|
+
if (isYear) {
|
|
4166
|
+
return 'YYYY';
|
|
4167
|
+
}
|
|
4168
|
+
else if (isMonth) {
|
|
4169
|
+
return 'YYYY-MM';
|
|
4170
|
+
}
|
|
4171
|
+
else if (isDay) {
|
|
4172
|
+
return 'YYYY-MM-DD';
|
|
4173
|
+
}
|
|
4174
|
+
else if (isHour) {
|
|
4175
|
+
return 'HH';
|
|
4176
|
+
}
|
|
4177
|
+
else if (isMinute) {
|
|
4178
|
+
return 'HH:mm';
|
|
4179
|
+
}
|
|
4180
|
+
else if (isSecond) {
|
|
4181
|
+
return 'HH:mm:ss';
|
|
4182
|
+
}
|
|
4183
|
+
return 'HH:mm:ss SSS';
|
|
4184
|
+
}
|
|
4185
|
+
function getTimeFormatter(template, isUTC) {
|
|
4186
|
+
return (time) => {
|
|
4187
|
+
const date = toDate(time);
|
|
4188
|
+
const y = date[fullYearGetterName(isUTC)]();
|
|
4189
|
+
const M = date[monthGetterName(isUTC)]() + 1;
|
|
4190
|
+
const q = Math.floor((M - 1) / 3) + 1;
|
|
4191
|
+
const d = date[dateGetterName(isUTC)]();
|
|
4192
|
+
const e = date[('get' + (isUTC ? 'UTC' : '') + 'Day')]();
|
|
4193
|
+
const H = date[hoursGetterName(isUTC)]();
|
|
4194
|
+
const h = ((H - 1) % 12) + 1;
|
|
4195
|
+
const m = date[minutesGetterName(isUTC)]();
|
|
4196
|
+
const s = date[secondsGetterName(isUTC)]();
|
|
4197
|
+
const S = date[millisecondsGetterName(isUTC)]();
|
|
4198
|
+
return ((template || '')
|
|
4199
|
+
.replace(/YYYY/g, pad(y + '', 4, '0', 'left'))
|
|
4200
|
+
.replace(/yyyy/g, y + '')
|
|
4201
|
+
.replace(/yy/g, (y % 100) + '')
|
|
4202
|
+
.replace(/Q/g, q + '')
|
|
4203
|
+
.replace(/MM/g, pad(M, 2, '0', 'left'))
|
|
4204
|
+
.replace(/M/g, M + '')
|
|
4205
|
+
.replace(/dd/g, pad(d, 2, '0', 'left'))
|
|
4206
|
+
.replace(/d/g, d + '')
|
|
4207
|
+
.replace(/e/g, e + '')
|
|
4208
|
+
.replace(/HH/g, pad(H, 2, '0', 'left'))
|
|
4209
|
+
.replace(/H/g, H + '')
|
|
4210
|
+
.replace(/hh/g, pad(h + '', 2, '0', 'left'))
|
|
4211
|
+
.replace(/h/g, h + '')
|
|
4212
|
+
.replace(/mm/g, pad(m, 2, '0', 'left'))
|
|
4213
|
+
.replace(/m/g, m + '')
|
|
4214
|
+
.replace(/ss/g, pad(s, 2, '0', 'left'))
|
|
4215
|
+
.replace(/s/g, s + '')
|
|
4216
|
+
.replace(/SSS/g, pad(S, 3, '0', 'left'))
|
|
4217
|
+
.replace(/S/g, S + ''));
|
|
4218
|
+
};
|
|
4219
|
+
}
|
|
4220
|
+
|
|
4221
|
+
const SECOND = 1000;
|
|
4222
|
+
const MINUTE = 60 * SECOND;
|
|
4223
|
+
const HOUR = 60 * MINUTE;
|
|
4224
|
+
const DAY = 24 * HOUR;
|
|
4225
|
+
const MONTH = DAY * 31;
|
|
4226
|
+
const YEAR = DAY * 365;
|
|
4227
|
+
const yearFloor = (date) => {
|
|
4228
|
+
date.setMonth(0, 1);
|
|
4229
|
+
date.setHours(0, 0, 0, 0);
|
|
4230
|
+
return date;
|
|
4231
|
+
};
|
|
4232
|
+
const yearOffset = (date, step) => {
|
|
4233
|
+
date.setFullYear(date.getFullYear() + step);
|
|
4234
|
+
return date;
|
|
4235
|
+
};
|
|
4236
|
+
const yearCount = (start, end) => {
|
|
4237
|
+
return end.getFullYear() - start.getFullYear();
|
|
4238
|
+
};
|
|
4239
|
+
const yearField = (date) => date.getFullYear();
|
|
4240
|
+
const utcYearFloor = (date) => {
|
|
4241
|
+
date.setUTCMonth(0, 1);
|
|
4242
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
4243
|
+
return date;
|
|
4244
|
+
};
|
|
4245
|
+
const utcYearOffset = (date, step) => {
|
|
4246
|
+
date.setUTCFullYear(date.getUTCFullYear() + step);
|
|
4247
|
+
return date;
|
|
4248
|
+
};
|
|
4249
|
+
const utcYearCount = (start, end) => {
|
|
4250
|
+
return end.getUTCFullYear() - start.getUTCFullYear();
|
|
4251
|
+
};
|
|
4252
|
+
const utcYearField = (date) => date.getUTCFullYear();
|
|
4253
|
+
const monthFloor = (date) => {
|
|
4254
|
+
date.setDate(1);
|
|
4255
|
+
date.setHours(0, 0, 0, 0);
|
|
4256
|
+
return date;
|
|
4257
|
+
};
|
|
4258
|
+
const monthOffset = (date, step) => {
|
|
4259
|
+
date.setMonth(date.getMonth() + step);
|
|
4260
|
+
return date;
|
|
4261
|
+
};
|
|
4262
|
+
const monthCount = (start, end) => {
|
|
4263
|
+
return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
|
|
4264
|
+
};
|
|
4265
|
+
const monthField = (date) => date.getMonth();
|
|
4266
|
+
const utcMonthFloor = (date) => {
|
|
4267
|
+
date.setUTCDate(1);
|
|
4268
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
4269
|
+
return date;
|
|
4270
|
+
};
|
|
4271
|
+
const utcMonthOffset = (date, step) => {
|
|
4272
|
+
date.setUTCMonth(date.getUTCMonth() + step);
|
|
4273
|
+
return date;
|
|
4274
|
+
};
|
|
4275
|
+
const utcMonthCount = (start, end) => {
|
|
4276
|
+
return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
|
|
4277
|
+
};
|
|
4278
|
+
const utcMonthField = (date) => date.getUTCMonth();
|
|
4279
|
+
const dayFloor = (date) => {
|
|
4280
|
+
date.setHours(0, 0, 0, 0);
|
|
4281
|
+
return date;
|
|
4282
|
+
};
|
|
4283
|
+
const dayOffset = (date, step) => {
|
|
4284
|
+
date.setDate(date.getDate() + step);
|
|
4285
|
+
return date;
|
|
4286
|
+
};
|
|
4287
|
+
const dayCount = (start, end) => {
|
|
4288
|
+
return (+end - +start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * MINUTE) / DAY;
|
|
4289
|
+
};
|
|
4290
|
+
const dayField = (date) => date.getDate() - 1;
|
|
4291
|
+
const utcDayFloor = (date) => {
|
|
4292
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
4293
|
+
return date;
|
|
4294
|
+
};
|
|
4295
|
+
const utcDayOffset = (date, step) => {
|
|
4296
|
+
date.setUTCDate(date.getUTCDate() + step);
|
|
4297
|
+
return date;
|
|
4298
|
+
};
|
|
4299
|
+
const utcDayCount = (start, end) => {
|
|
4300
|
+
return (+end - +start) / DAY;
|
|
4301
|
+
};
|
|
4302
|
+
const utcDayField = (date) => date.getUTCDate() - 1;
|
|
4303
|
+
const hourFloor = (date) => {
|
|
4304
|
+
date.setTime(+date - date.getMilliseconds() - date.getSeconds() * SECOND - date.getMinutes() * MINUTE);
|
|
4305
|
+
return date;
|
|
4306
|
+
};
|
|
4307
|
+
const hourOffset = (date, step) => {
|
|
4308
|
+
date.setHours(date.getHours() + step);
|
|
4309
|
+
return date;
|
|
4310
|
+
};
|
|
4311
|
+
const hourCount = (start, end) => {
|
|
4312
|
+
return (+end - +start) / HOUR;
|
|
4313
|
+
};
|
|
4314
|
+
const hourField = (date) => date.getHours();
|
|
4315
|
+
const utcHourFloor = (date) => {
|
|
4316
|
+
date.setTime(+date - date.getUTCMilliseconds() - date.getUTCSeconds() * SECOND - date.getUTCMinutes() * MINUTE);
|
|
4317
|
+
return date;
|
|
4318
|
+
};
|
|
4319
|
+
const utcHourOffset = (date, step) => {
|
|
4320
|
+
date.setUTCHours(date.getUTCHours() + step);
|
|
4321
|
+
return date;
|
|
4322
|
+
};
|
|
4323
|
+
const utcHourField = (date) => date.getUTCHours();
|
|
4324
|
+
const minuteFloor = (date) => {
|
|
4325
|
+
date.setTime(+date - date.getMilliseconds() - date.getSeconds() * SECOND);
|
|
4326
|
+
return date;
|
|
4327
|
+
};
|
|
4328
|
+
const minuteOffset = (date, step) => {
|
|
4329
|
+
date.setMinutes(date.getMinutes() + step);
|
|
4330
|
+
return date;
|
|
4331
|
+
};
|
|
4332
|
+
const minuteCount = (start, end) => {
|
|
4333
|
+
return (+end - +start) / MINUTE;
|
|
4334
|
+
};
|
|
4335
|
+
const minuteField = (date) => {
|
|
4336
|
+
return date.getMinutes();
|
|
4337
|
+
};
|
|
4338
|
+
const utcMinuteFloor = (date) => {
|
|
4339
|
+
date.setTime(+date - date.getUTCMilliseconds() - date.getUTCSeconds() * SECOND);
|
|
4340
|
+
return date;
|
|
4341
|
+
};
|
|
4342
|
+
const utcMinuteOffset = (date, step) => {
|
|
4343
|
+
date.setUTCMinutes(date.getUTCMinutes() + step);
|
|
4344
|
+
return date;
|
|
4345
|
+
};
|
|
4346
|
+
const utcMinuteField = (date) => {
|
|
4347
|
+
return date.getUTCMinutes();
|
|
4348
|
+
};
|
|
4349
|
+
const secondFloor = (date) => {
|
|
4350
|
+
date.setTime(+date - date.getMilliseconds());
|
|
4351
|
+
return date;
|
|
4352
|
+
};
|
|
4353
|
+
const secondOffset = (date, step) => {
|
|
4354
|
+
date.setSeconds(date.getSeconds() + step);
|
|
4355
|
+
return date;
|
|
4356
|
+
};
|
|
4357
|
+
const secondCount = (start, end) => {
|
|
4358
|
+
return (+end - +start) / SECOND;
|
|
4359
|
+
};
|
|
4360
|
+
const secondField = (date) => date.getSeconds();
|
|
4361
|
+
const utcSecondFloor = (date) => {
|
|
4362
|
+
date.setTime(+date - date.getUTCMilliseconds());
|
|
4363
|
+
return date;
|
|
4364
|
+
};
|
|
4365
|
+
const utcSecondOffset = (date, step) => {
|
|
4366
|
+
date.setUTCSeconds(date.getUTCSeconds() + step);
|
|
4367
|
+
return date;
|
|
4368
|
+
};
|
|
4369
|
+
const utcSecondField = (date) => date.getUTCSeconds();
|
|
4370
|
+
const millisecondsFloor = (date) => {
|
|
4371
|
+
return date;
|
|
4372
|
+
};
|
|
4373
|
+
const millisecondsOffset = (date, step) => {
|
|
4374
|
+
date.setTime(+date + step);
|
|
4375
|
+
return date;
|
|
4376
|
+
};
|
|
4377
|
+
const millisecondsCount = (start, end) => +end - +start;
|
|
4378
|
+
const generateCeil = (floor, offset) => {
|
|
4379
|
+
return (date) => {
|
|
4380
|
+
const n = new Date(+date - 1);
|
|
4381
|
+
offset(n, 1);
|
|
4382
|
+
floor(n);
|
|
4383
|
+
return n;
|
|
4384
|
+
};
|
|
4385
|
+
};
|
|
4386
|
+
const generateCount = (floor, count) => {
|
|
4387
|
+
return (start, end) => {
|
|
4388
|
+
const a = new Date();
|
|
4389
|
+
const b = new Date();
|
|
4390
|
+
a.setTime(+start);
|
|
4391
|
+
b.setTime(+end);
|
|
4392
|
+
floor(a);
|
|
4393
|
+
floor(b);
|
|
4394
|
+
return Math.floor(count(a, b));
|
|
4395
|
+
};
|
|
4396
|
+
};
|
|
4397
|
+
const generateStepInterval = (step, { floor, offset, field, count }) => {
|
|
4398
|
+
const s = Math.floor(step);
|
|
4399
|
+
if (!Number.isFinite(s) || s <= 0) {
|
|
4400
|
+
return null;
|
|
4401
|
+
}
|
|
4402
|
+
if (s <= 1) {
|
|
4403
|
+
return {
|
|
4404
|
+
floor,
|
|
4405
|
+
offset,
|
|
4406
|
+
ceil: generateCeil(floor, offset)
|
|
4407
|
+
};
|
|
4408
|
+
}
|
|
4409
|
+
const stepCount = generateCount(floor, count);
|
|
4410
|
+
const testFunc = field
|
|
4411
|
+
? (d) => {
|
|
4412
|
+
return field(d) % s === 0;
|
|
4413
|
+
}
|
|
4414
|
+
: (d) => {
|
|
4415
|
+
return stepCount(0, d) % s === 0;
|
|
4416
|
+
};
|
|
4417
|
+
const stepFloor = (date) => {
|
|
4418
|
+
if (!Number.isNaN(+date)) {
|
|
4419
|
+
floor(date);
|
|
4420
|
+
while (!testFunc(date)) {
|
|
4421
|
+
date.setTime(+date - 1);
|
|
4422
|
+
floor(date);
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4425
|
+
return date;
|
|
4426
|
+
};
|
|
4427
|
+
const stepOffset = (date, stepCount) => {
|
|
4428
|
+
if (!Number.isNaN(+date)) {
|
|
4429
|
+
if (s < 0) {
|
|
4430
|
+
while (++stepCount <= 0) {
|
|
4431
|
+
offset(date, -1);
|
|
4432
|
+
while (!testFunc(date)) {
|
|
4433
|
+
offset(date, -1);
|
|
4434
|
+
}
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
else {
|
|
4438
|
+
while (--stepCount >= 0) {
|
|
4439
|
+
offset(date, +1);
|
|
4440
|
+
while (!testFunc(date)) {
|
|
4441
|
+
offset(date, +1);
|
|
4442
|
+
}
|
|
4443
|
+
}
|
|
4444
|
+
}
|
|
4445
|
+
}
|
|
4446
|
+
return date;
|
|
4447
|
+
};
|
|
4448
|
+
return {
|
|
4449
|
+
floor: stepFloor,
|
|
4450
|
+
offset: stepOffset,
|
|
4451
|
+
ceil: generateCeil(stepFloor, stepOffset)
|
|
4452
|
+
};
|
|
4453
|
+
};
|
|
4454
|
+
const getIntervalOptions = (type, isUTC) => {
|
|
4455
|
+
if (type === 'year' && isUTC) {
|
|
4456
|
+
return { floor: utcYearFloor, offset: utcYearOffset, count: utcYearCount, field: utcYearField };
|
|
4457
|
+
}
|
|
4458
|
+
if (type === 'month' && isUTC) {
|
|
4459
|
+
return { floor: utcMonthFloor, offset: utcMonthOffset, count: utcMonthCount, field: utcMonthField };
|
|
4460
|
+
}
|
|
4461
|
+
if (type === 'day' && isUTC) {
|
|
4462
|
+
return { floor: utcDayFloor, offset: utcDayOffset, count: utcDayCount, field: utcDayField };
|
|
4463
|
+
}
|
|
4464
|
+
if (type === 'hour' && isUTC) {
|
|
4465
|
+
return { floor: utcHourFloor, offset: utcHourOffset, count: hourCount, field: utcHourField };
|
|
4466
|
+
}
|
|
4467
|
+
if (type === 'minute' && isUTC) {
|
|
4468
|
+
return { floor: utcMinuteFloor, offset: utcMinuteOffset, count: minuteCount, field: utcMinuteField };
|
|
4469
|
+
}
|
|
4470
|
+
if (type === 'second' && isUTC) {
|
|
4471
|
+
return { floor: utcSecondFloor, offset: utcSecondOffset, count: secondCount, field: utcSecondField };
|
|
4472
|
+
}
|
|
4473
|
+
if (type === 'year') {
|
|
4474
|
+
return { floor: yearFloor, offset: yearOffset, count: yearCount, field: yearField };
|
|
4475
|
+
}
|
|
4476
|
+
if (type === 'month') {
|
|
4477
|
+
return { floor: monthFloor, offset: monthOffset, count: monthCount, field: monthField };
|
|
4478
|
+
}
|
|
4479
|
+
if (type === 'day') {
|
|
4480
|
+
return { floor: dayFloor, offset: dayOffset, count: dayCount, field: dayField };
|
|
4481
|
+
}
|
|
4482
|
+
if (type === 'hour') {
|
|
4483
|
+
return { floor: hourFloor, offset: hourOffset, count: hourCount, field: hourField };
|
|
4484
|
+
}
|
|
4485
|
+
if (type === 'minute') {
|
|
4486
|
+
return { floor: minuteFloor, offset: minuteOffset, count: minuteCount, field: minuteField };
|
|
4487
|
+
}
|
|
4488
|
+
if (type === 'second') {
|
|
4489
|
+
return { floor: secondFloor, offset: secondOffset, count: secondCount, field: secondField };
|
|
4490
|
+
}
|
|
4491
|
+
return { floor: millisecondsFloor, offset: millisecondsOffset, count: millisecondsCount };
|
|
4492
|
+
};
|
|
4493
|
+
|
|
4494
|
+
function getContainerSize(el, defaultWidth = 0, defaultHeight = 0) {
|
|
4495
|
+
if (!el) {
|
|
4496
|
+
return { width: defaultWidth, height: defaultHeight };
|
|
4497
|
+
}
|
|
4498
|
+
let getComputedStyle;
|
|
4499
|
+
try {
|
|
4500
|
+
getComputedStyle = window?.getComputedStyle;
|
|
4501
|
+
}
|
|
4502
|
+
catch (e) {
|
|
4503
|
+
getComputedStyle = () => {
|
|
4504
|
+
return {};
|
|
4505
|
+
};
|
|
4506
|
+
}
|
|
4507
|
+
const style = getComputedStyle(el);
|
|
4508
|
+
const computedWidth = parseFloat(style.width) - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight) || el.clientWidth - 1;
|
|
4509
|
+
const computedHeight = parseFloat(style.height) - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom) || el.clientHeight - 1;
|
|
4510
|
+
return {
|
|
4511
|
+
width: computedWidth <= 0 ? defaultWidth : computedWidth,
|
|
4512
|
+
height: computedHeight <= 0 ? defaultHeight : computedHeight
|
|
4513
|
+
};
|
|
4514
|
+
}
|
|
4515
|
+
function getElementAbsolutePosition(element) {
|
|
4516
|
+
const { x, y } = element.getBoundingClientRect();
|
|
4517
|
+
return { x, y };
|
|
4518
|
+
}
|
|
4519
|
+
function getElementRelativePosition(element, base) {
|
|
4520
|
+
const posElement = getElementAbsolutePosition(element);
|
|
4521
|
+
const posBase = getElementAbsolutePosition(base);
|
|
4522
|
+
return { x: posElement.x - posBase.x, y: posElement.y - posBase.y };
|
|
4523
|
+
}
|
|
4524
|
+
const getScrollLeft = (element) => {
|
|
4525
|
+
if (element === globalThis?.document?.body) {
|
|
4526
|
+
return globalThis?.document?.documentElement?.scrollLeft || element.scrollLeft;
|
|
4527
|
+
}
|
|
4528
|
+
else if (element.tagName.toLowerCase() === 'html') {
|
|
4529
|
+
return 0;
|
|
4530
|
+
}
|
|
4531
|
+
return element.scrollLeft;
|
|
4532
|
+
};
|
|
4533
|
+
const getScrollTop = (element) => {
|
|
4534
|
+
if (element === globalThis?.document?.body) {
|
|
4535
|
+
return globalThis?.document?.documentElement?.scrollTop || element.scrollTop;
|
|
4536
|
+
}
|
|
4537
|
+
else if (element.tagName.toLowerCase() === 'html') {
|
|
4538
|
+
return 0;
|
|
4539
|
+
}
|
|
4540
|
+
return element.scrollTop;
|
|
4541
|
+
};
|
|
4542
|
+
const getScaleX = (element) => {
|
|
4543
|
+
return element.getBoundingClientRect().width / element.offsetWidth;
|
|
4544
|
+
};
|
|
4545
|
+
const getScaleY = (element) => {
|
|
4546
|
+
return element.getBoundingClientRect().height / element.offsetHeight;
|
|
4547
|
+
};
|
|
4548
|
+
const getScale = (element) => {
|
|
4549
|
+
if (element.offsetWidth > 0) {
|
|
4550
|
+
return getScaleX(element);
|
|
4551
|
+
}
|
|
4552
|
+
return getScaleY(element);
|
|
4553
|
+
};
|
|
4554
|
+
function hasParentElement(element, target) {
|
|
4555
|
+
let parent = element.parentNode;
|
|
4556
|
+
while (parent !== null) {
|
|
4557
|
+
if (parent === target) {
|
|
4558
|
+
return true;
|
|
4559
|
+
}
|
|
4560
|
+
parent = parent.parentNode;
|
|
4561
|
+
}
|
|
4562
|
+
return false;
|
|
4563
|
+
}
|
|
4564
|
+
|
|
4565
|
+
/**
|
|
4566
|
+
* @module helpers
|
|
4567
|
+
*/
|
|
4568
|
+
/**
|
|
4569
|
+
* Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
|
|
4570
|
+
*
|
|
4571
|
+
* @memberof helpers
|
|
4572
|
+
* @type {number}
|
|
4573
|
+
*/
|
|
4574
|
+
var earthRadius = 6371008.8;
|
|
4575
|
+
/**
|
|
4576
|
+
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
|
|
4577
|
+
*
|
|
4578
|
+
* @memberof helpers
|
|
4579
|
+
* @type {Object}
|
|
4580
|
+
*/
|
|
4581
|
+
var factors = {
|
|
4582
|
+
centimeters: earthRadius * 100,
|
|
4583
|
+
centimetres: earthRadius * 100,
|
|
4584
|
+
degrees: earthRadius / 111325,
|
|
4585
|
+
feet: earthRadius * 3.28084,
|
|
4586
|
+
inches: earthRadius * 39.37,
|
|
4587
|
+
kilometers: earthRadius / 1000,
|
|
4588
|
+
kilometres: earthRadius / 1000,
|
|
4589
|
+
meters: earthRadius,
|
|
4590
|
+
metres: earthRadius,
|
|
4591
|
+
miles: earthRadius / 1609.344,
|
|
4592
|
+
millimeters: earthRadius * 1000,
|
|
4593
|
+
millimetres: earthRadius * 1000,
|
|
4594
|
+
nauticalmiles: earthRadius / 1852,
|
|
4595
|
+
radians: 1,
|
|
4596
|
+
yards: earthRadius * 1.0936
|
|
4597
|
+
};
|
|
4598
|
+
/**
|
|
4599
|
+
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
|
|
4600
|
+
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
4601
|
+
*
|
|
4602
|
+
* @name lengthToRadians
|
|
4603
|
+
* @param {number} distance in real units
|
|
4604
|
+
* @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
|
|
4605
|
+
* meters, kilometres, kilometers.
|
|
4606
|
+
* @returns {number} radians
|
|
4607
|
+
*/
|
|
4608
|
+
function lengthToRadians(distance, units) {
|
|
4609
|
+
if (units === void 0) {
|
|
4610
|
+
units = "kilometers";
|
|
4611
|
+
}
|
|
4612
|
+
var factor = factors[units];
|
|
4613
|
+
if (!factor) {
|
|
4614
|
+
throw new Error(units + " units is invalid");
|
|
4615
|
+
}
|
|
4616
|
+
return distance / factor;
|
|
4617
|
+
}
|
|
4618
|
+
|
|
4619
|
+
function getGeom(geojson) {
|
|
4620
|
+
if (geojson.type === 'Feature') {
|
|
4621
|
+
return geojson.geometry;
|
|
4622
|
+
}
|
|
4623
|
+
return geojson;
|
|
4624
|
+
}
|
|
4625
|
+
function isPointInPolygon(point, polygon) {
|
|
4626
|
+
if (!point) {
|
|
4627
|
+
return false;
|
|
4628
|
+
}
|
|
4629
|
+
if (!polygon) {
|
|
4630
|
+
return false;
|
|
4631
|
+
}
|
|
4632
|
+
const geom = getGeom(polygon);
|
|
4633
|
+
const type = geom.type;
|
|
4634
|
+
const bbox = polygon.bbox;
|
|
4635
|
+
let polys = geom.coordinates;
|
|
4636
|
+
if (bbox && pointInRect(point, { x1: bbox[0], x2: bbox[1], y1: bbox[1], y2: bbox[3] }, true) === true) {
|
|
4637
|
+
return false;
|
|
4638
|
+
}
|
|
4639
|
+
if (type === 'Polygon') {
|
|
4640
|
+
polys = [polys];
|
|
4641
|
+
}
|
|
4642
|
+
let result = false;
|
|
4643
|
+
for (let i = 0; i < polys.length; ++i) {
|
|
4644
|
+
for (let j = 0; j < polys[i].length; ++j) {
|
|
4645
|
+
const polyResult = polygonContainPoint(polys[i][j].map((p) => ({ x: p[0], y: p[1] })), point.x, point.y);
|
|
4646
|
+
if (polyResult) {
|
|
4647
|
+
result = true;
|
|
4648
|
+
return result;
|
|
4649
|
+
}
|
|
4650
|
+
}
|
|
4651
|
+
}
|
|
4652
|
+
return result;
|
|
4653
|
+
}
|
|
4654
|
+
function destination(point, distance, bearing, options = {}) {
|
|
4655
|
+
const longitude1 = degreeToRadian(point[0]);
|
|
4656
|
+
const latitude1 = degreeToRadian(point[1]);
|
|
4657
|
+
const bearingRad = degreeToRadian(bearing);
|
|
4658
|
+
const radians = lengthToRadians(distance, options.units);
|
|
4659
|
+
const latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) + Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad));
|
|
4660
|
+
const longitude2 = longitude1 +
|
|
4661
|
+
Math.atan2(Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1), Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
|
|
4662
|
+
const lng = radianToDegree(longitude2);
|
|
4663
|
+
const lat = radianToDegree(latitude2);
|
|
4664
|
+
return { x: lng, y: lat };
|
|
4665
|
+
}
|
|
4666
|
+
|
|
4667
|
+
exports.AABBBounds = AABBBounds;
|
|
4668
|
+
exports.Bounds = Bounds;
|
|
4669
|
+
exports.ColorUtil = index;
|
|
4670
|
+
exports.DAY = DAY;
|
|
4671
|
+
exports.EventEmitter = index$1;
|
|
4672
|
+
exports.GraphicUtil = GraphicUtil;
|
|
4673
|
+
exports.HOUR = HOUR;
|
|
4674
|
+
exports.HashTable = HashTable;
|
|
4675
|
+
exports.HashValue = HashValue;
|
|
4676
|
+
exports.LRU = LRU;
|
|
4677
|
+
exports.Logger = logger$1;
|
|
4678
|
+
exports.MINUTE = MINUTE;
|
|
4679
|
+
exports.MONTH = MONTH;
|
|
4680
|
+
exports.Matrix = Matrix;
|
|
4681
|
+
exports.NEWTON_ITERATIONS = NEWTON_ITERATIONS;
|
|
4682
|
+
exports.NEWTON_MIN_SLOPE = NEWTON_MIN_SLOPE;
|
|
4683
|
+
exports.OBBBounds = OBBBounds;
|
|
4684
|
+
exports.Point = Point;
|
|
4685
|
+
exports.PointService = PointService;
|
|
4686
|
+
exports.PolarPoint = PolarPoint;
|
|
4687
|
+
exports.SECOND = SECOND;
|
|
4688
|
+
exports.SUBDIVISION_MAX_ITERATIONS = SUBDIVISION_MAX_ITERATIONS;
|
|
4689
|
+
exports.SUBDIVISION_PRECISION = SUBDIVISION_PRECISION;
|
|
4690
|
+
exports.TestTextMeasure = TestTextMeasure;
|
|
4691
|
+
exports.TextMeasure = TextMeasure;
|
|
4692
|
+
exports.YEAR = YEAR;
|
|
4693
|
+
exports.abs = abs;
|
|
4694
|
+
exports.acos = acos;
|
|
4695
|
+
exports.array = array;
|
|
4696
|
+
exports.arrayEqual = arrayEqual;
|
|
4697
|
+
exports.ascending = ascending;
|
|
4698
|
+
exports.asin = asin;
|
|
4699
|
+
exports.atan2 = atan2;
|
|
4700
|
+
exports.bisect = bisect;
|
|
4701
|
+
exports.clamp = clamp;
|
|
4702
|
+
exports.clampAngleByDegree = clampAngleByDegree;
|
|
4703
|
+
exports.clampAngleByRadian = clampAngleByRadian;
|
|
4704
|
+
exports.clampDegree = clampDegree;
|
|
4705
|
+
exports.clampRadian = clampRadian;
|
|
4706
|
+
exports.clampRange = clampRange;
|
|
4707
|
+
exports.clamper = clamper;
|
|
4708
|
+
exports.clone = clone;
|
|
4709
|
+
exports.cloneDeep = cloneDeep;
|
|
4710
|
+
exports.constant = constant;
|
|
4711
|
+
exports.cos = cos;
|
|
4712
|
+
exports.crossProduct = crossProduct;
|
|
4713
|
+
exports.crossProductPoint = crossProductPoint;
|
|
4714
|
+
exports.dateGetterName = dateGetterName;
|
|
4715
|
+
exports.dateSetterName = dateSetterName;
|
|
4716
|
+
exports.dayCount = dayCount;
|
|
4717
|
+
exports.dayField = dayField;
|
|
4718
|
+
exports.dayFloor = dayFloor;
|
|
4719
|
+
exports.dayOffset = dayOffset;
|
|
4720
|
+
exports.debounce = debounce;
|
|
4721
|
+
exports.defaults = defaults;
|
|
4722
|
+
exports.degreeToRadian = degreeToRadian;
|
|
4723
|
+
exports.destination = destination;
|
|
4724
|
+
exports.deviation = deviation;
|
|
4725
|
+
exports.eastAsianCharacterInfo = eastAsianCharacterInfo;
|
|
4726
|
+
exports.epsilon = epsilon;
|
|
4727
|
+
exports.fixPrecision = fixPrecision;
|
|
4728
|
+
exports.flattenArray = flattenArray;
|
|
4729
|
+
exports.fullYearGetterName = fullYearGetterName;
|
|
4730
|
+
exports.fullYearSetterName = fullYearSetterName;
|
|
4731
|
+
exports.fuzzyEqualNumber = fuzzyEqualNumber;
|
|
4732
|
+
exports.fuzzyEqualVec = fuzzyEqualVec;
|
|
4733
|
+
exports.generateCeil = generateCeil;
|
|
4734
|
+
exports.generateCount = generateCount;
|
|
4735
|
+
exports.generateStepInterval = generateStepInterval;
|
|
4736
|
+
exports.get = get;
|
|
4737
|
+
exports.getAABBFromPoints = getAABBFromPoints;
|
|
4738
|
+
exports.getAngleByPoint = getAngleByPoint;
|
|
4739
|
+
exports.getContainerSize = getContainerSize;
|
|
4740
|
+
exports.getContextFont = getContextFont;
|
|
4741
|
+
exports.getElementAbsolutePosition = getElementAbsolutePosition;
|
|
4742
|
+
exports.getElementRelativePosition = getElementRelativePosition;
|
|
4743
|
+
exports.getFormatFromValue = getFormatFromValue;
|
|
4744
|
+
exports.getIntersectPoint = getIntersectPoint;
|
|
4745
|
+
exports.getIntervalOptions = getIntervalOptions;
|
|
4746
|
+
exports.getOBBFromLine = getOBBFromLine;
|
|
4747
|
+
exports.getRectIntersect = getRectIntersect;
|
|
4748
|
+
exports.getScale = getScale;
|
|
4749
|
+
exports.getScaleX = getScaleX;
|
|
4750
|
+
exports.getScaleY = getScaleY;
|
|
4751
|
+
exports.getScrollLeft = getScrollLeft;
|
|
4752
|
+
exports.getScrollTop = getScrollTop;
|
|
4753
|
+
exports.getTestNumbers = getTestNumbers;
|
|
4754
|
+
exports.getTestWord = getTestWord;
|
|
4755
|
+
exports.getTimeFormatter = getTimeFormatter;
|
|
4756
|
+
exports.halfPi = halfPi;
|
|
4757
|
+
exports.has = has;
|
|
4758
|
+
exports.hasParentElement = hasParentElement;
|
|
4759
|
+
exports.hourCount = hourCount;
|
|
4760
|
+
exports.hourField = hourField;
|
|
4761
|
+
exports.hourFloor = hourFloor;
|
|
4762
|
+
exports.hourOffset = hourOffset;
|
|
4763
|
+
exports.hoursGetterName = hoursGetterName;
|
|
4764
|
+
exports.hoursSetterName = hoursSetterName;
|
|
4765
|
+
exports.interpolateDate = interpolateDate;
|
|
4766
|
+
exports.interpolateNumber = interpolateNumber;
|
|
4767
|
+
exports.interpolateNumberRound = interpolateNumberRound;
|
|
4768
|
+
exports.interpolateString = interpolateString;
|
|
4769
|
+
exports.isArray = isArray;
|
|
4770
|
+
exports.isArrayLike = isArrayLike;
|
|
4771
|
+
exports.isBase64 = isBase64;
|
|
4772
|
+
exports.isBoolean = isBoolean;
|
|
4773
|
+
exports.isDate = isDate;
|
|
4774
|
+
exports.isEmpty = isEmpty;
|
|
4775
|
+
exports.isEqual = isEqual;
|
|
4776
|
+
exports.isFunction = isFunction;
|
|
4777
|
+
exports.isGreater = isGreater;
|
|
4778
|
+
exports.isIntersect = isIntersect;
|
|
4779
|
+
exports.isLess = isLess;
|
|
4780
|
+
exports.isNil = isNil;
|
|
4781
|
+
exports.isNull = isNull;
|
|
4782
|
+
exports.isNumber = isNumber;
|
|
4783
|
+
exports.isNumberClose = isNumberClose;
|
|
4784
|
+
exports.isNumeric = isNumeric;
|
|
4785
|
+
exports.isObject = isObject;
|
|
4786
|
+
exports.isObjectLike = isObjectLike;
|
|
4787
|
+
exports.isPlainObject = isPlainObject;
|
|
4788
|
+
exports.isPointInLine = isPointInLine;
|
|
4789
|
+
exports.isPointInPolygon = isPointInPolygon;
|
|
4790
|
+
exports.isRectIntersect = isRectIntersect;
|
|
4791
|
+
exports.isRegExp = isRegExp;
|
|
4792
|
+
exports.isRotateAABBIntersect = isRotateAABBIntersect;
|
|
4793
|
+
exports.isShallowEqual = isShallowEqual;
|
|
4794
|
+
exports.isString = isString;
|
|
4795
|
+
exports.isType = isType;
|
|
4796
|
+
exports.isUndefined = isUndefined;
|
|
4797
|
+
exports.isValid = isValid;
|
|
4798
|
+
exports.isValidNumber = isValidNumber;
|
|
4799
|
+
exports.isValidUrl = isValidUrl;
|
|
4800
|
+
exports.keys = keys;
|
|
4801
|
+
exports.last = last;
|
|
4802
|
+
exports.lengthFromPointToLine = lengthFromPointToLine;
|
|
4803
|
+
exports.lineIntersectPolygon = lineIntersectPolygon;
|
|
4804
|
+
exports.lowerFirst = lowerFirst;
|
|
4805
|
+
exports.max = max;
|
|
4806
|
+
exports.maxInArray = maxInArray;
|
|
4807
|
+
exports.median = median;
|
|
4808
|
+
exports.merge = merge;
|
|
4809
|
+
exports.mergeAABB = mergeAABB;
|
|
4810
|
+
exports.millisecondsCount = millisecondsCount;
|
|
4811
|
+
exports.millisecondsFloor = millisecondsFloor;
|
|
4812
|
+
exports.millisecondsGetterName = millisecondsGetterName;
|
|
4813
|
+
exports.millisecondsOffset = millisecondsOffset;
|
|
4814
|
+
exports.millisecondsSetterName = millisecondsSetterName;
|
|
4815
|
+
exports.min = min;
|
|
4816
|
+
exports.minInArray = minInArray;
|
|
4817
|
+
exports.minuteCount = minuteCount;
|
|
4818
|
+
exports.minuteField = minuteField;
|
|
4819
|
+
exports.minuteFloor = minuteFloor;
|
|
4820
|
+
exports.minuteOffset = minuteOffset;
|
|
4821
|
+
exports.minutesGetterName = minutesGetterName;
|
|
4822
|
+
exports.minutesSetterName = minutesSetterName;
|
|
4823
|
+
exports.mixin = mixin;
|
|
4824
|
+
exports.monthCount = monthCount;
|
|
4825
|
+
exports.monthField = monthField;
|
|
4826
|
+
exports.monthFloor = monthFloor;
|
|
4827
|
+
exports.monthGetterName = monthGetterName;
|
|
4828
|
+
exports.monthOffset = monthOffset;
|
|
4829
|
+
exports.monthSetterName = monthSetterName;
|
|
4830
|
+
exports.normalTransform = normalTransform;
|
|
4831
|
+
exports.normalizePadding = normalizePadding;
|
|
4832
|
+
exports.pad = pad;
|
|
4833
|
+
exports.parseUint8ToImageData = parseUint8ToImageData;
|
|
4834
|
+
exports.pi = pi;
|
|
4835
|
+
exports.pi2 = pi2;
|
|
4836
|
+
exports.pick = pick;
|
|
4837
|
+
exports.pickWithout = pickWithout;
|
|
4838
|
+
exports.pointAt = pointAt;
|
|
4839
|
+
exports.pointBetweenLine = pointBetweenLine;
|
|
4840
|
+
exports.pointInAABB = pointInAABB;
|
|
4841
|
+
exports.pointInLine = pointInLine;
|
|
4842
|
+
exports.pointInOBB = pointInOBB;
|
|
4843
|
+
exports.pointInRect = pointInRect;
|
|
4844
|
+
exports.polarToCartesian = polarToCartesian;
|
|
4845
|
+
exports.polygonContainPoint = polygonContainPoint;
|
|
4846
|
+
exports.polygonIntersectPolygon = polygonIntersectPolygon;
|
|
4847
|
+
exports.pow = pow;
|
|
4848
|
+
exports.quantileSorted = quantileSorted;
|
|
4849
|
+
exports.radianToDegree = radianToDegree;
|
|
4850
|
+
exports.range = range;
|
|
4851
|
+
exports.rectInsideAnotherRect = rectInsideAnotherRect;
|
|
4852
|
+
exports.secondCount = secondCount;
|
|
4853
|
+
exports.secondField = secondField;
|
|
4854
|
+
exports.secondFloor = secondFloor;
|
|
4855
|
+
exports.secondOffset = secondOffset;
|
|
4856
|
+
exports.secondsGetterName = secondsGetterName;
|
|
4857
|
+
exports.secondsSetterName = secondsSetterName;
|
|
4858
|
+
exports.shuffleArray = shuffleArray;
|
|
4859
|
+
exports.sin = sin;
|
|
4860
|
+
exports.span = span;
|
|
4861
|
+
exports.sqrt = sqrt;
|
|
4862
|
+
exports.stringWidth = stringWidth;
|
|
4863
|
+
exports.tau = tau;
|
|
4864
|
+
exports.throttle = throttle;
|
|
4865
|
+
exports.tickStep = tickStep;
|
|
4866
|
+
exports.toDate = toDate;
|
|
4867
|
+
exports.toNumber = toNumber;
|
|
4868
|
+
exports.toValidNumber = toValidNumber;
|
|
4869
|
+
exports.transformBounds = transformBounds;
|
|
4870
|
+
exports.transformBoundsWithMatrix = transformBoundsWithMatrix;
|
|
4871
|
+
exports.truncate = truncate;
|
|
4872
|
+
exports.unionAABB = unionAABB;
|
|
4873
|
+
exports.uniqArray = uniqArray;
|
|
4874
|
+
exports.upperFirst = upperFirst;
|
|
4875
|
+
exports.utcDayCount = utcDayCount;
|
|
4876
|
+
exports.utcDayField = utcDayField;
|
|
4877
|
+
exports.utcDayFloor = utcDayFloor;
|
|
4878
|
+
exports.utcDayOffset = utcDayOffset;
|
|
4879
|
+
exports.utcHourField = utcHourField;
|
|
4880
|
+
exports.utcHourFloor = utcHourFloor;
|
|
4881
|
+
exports.utcHourOffset = utcHourOffset;
|
|
4882
|
+
exports.utcMinuteField = utcMinuteField;
|
|
4883
|
+
exports.utcMinuteFloor = utcMinuteFloor;
|
|
4884
|
+
exports.utcMinuteOffset = utcMinuteOffset;
|
|
4885
|
+
exports.utcMonthCount = utcMonthCount;
|
|
4886
|
+
exports.utcMonthField = utcMonthField;
|
|
4887
|
+
exports.utcMonthFloor = utcMonthFloor;
|
|
4888
|
+
exports.utcMonthOffset = utcMonthOffset;
|
|
4889
|
+
exports.utcSecondField = utcSecondField;
|
|
4890
|
+
exports.utcSecondFloor = utcSecondFloor;
|
|
4891
|
+
exports.utcSecondOffset = utcSecondOffset;
|
|
4892
|
+
exports.utcYearCount = utcYearCount;
|
|
4893
|
+
exports.utcYearField = utcYearField;
|
|
4894
|
+
exports.utcYearFloor = utcYearFloor;
|
|
4895
|
+
exports.utcYearOffset = utcYearOffset;
|
|
4896
|
+
exports.uuid = uuid;
|
|
4897
|
+
exports.variance = variance;
|
|
4898
|
+
exports.yearCount = yearCount;
|
|
4899
|
+
exports.yearField = yearField;
|
|
4900
|
+
exports.yearFloor = yearFloor;
|
|
4901
|
+
exports.yearOffset = yearOffset;
|
|
4902
|
+
|
|
4903
|
+
}));
|