{"name":"@antv/util","version":"1.2.1","description":"A common util collection for antv projects","main":"build/util.js","scripts":{"build":"webpack","build-lib":"babel src --out-dir lib","ci":"npm run lint && npm run test","compress":"uglifyjs --compress --mangle --output dist/util-$npm_package_version.min.js -- build/util.js","coverage":"npm run coverage-generator && npm run coverage-viewer","coverage-viewer":"torch-coverage","coverage-generator":"torch --coverage --compile --renderer --source-pattern src/*.js,src/**/*.js --recursive test/unit","dev":"webpack --config webpack-dev.config.js","dist":"rm -rf dist && mkdir dist && npm run build && npm run compress","prepublishOnly":"npm run build-lib && npm run dist","lint":"eslint ./","lint-fix":"eslint --fix ./","test":"torch --compile --renderer --recursive ./test/unit","test-live":"torch --compile --renderer --interactive --recursive ./test/"},"repository":{"type":"git","url":"git+https://github.com/antvis/util.git"},"keywords":["util","antv","g"],"author":{"name":"https://github.com/orgs/antvis/people"},"license":"ISC","bugs":{"url":"https://github.com/antvis/util/issues"},"devDependencies":{"babel-cli":"~6.26.0","babel-eslint":"~7.2.3","babel-loader":"~7.1.1","babel-plugin-transform-remove-strict-mode":"~0.0.2","babel-preset-env":"~1.6.1","chai":"~4.0.1","electron":"~2.0.2","eslint":"~3.19.0","eslint-config-airbnb":"~15.0.1","eslint-config-egg":"~4.2.0","istanbul":"~0.4.5","pre-commit":"~1.2.2","shelljs":"~0.7.8","spm-sinon":"~1.6.0","string-replace-loader":"~1.3.0","torchjs":"~2.0.4","uglify-js":"~3.0.15","webpack":"~3.4.1"},"pre-commit":{"run":["lint","test"],"silent":false},"homepage":"https://github.com/antvis/util#readme","dependencies":{"@antv/gl-matrix":"^2.7.1"},"gitHead":"3778ea09a8834086365c9e23c7dca919dab2a78f","_id":"@antv/util@1.2.1","_npmVersion":"5.6.0","_nodeVersion":"8.11.4","_npmUser":{"name":"leungwensen","email":"leungwensen@gmail.com"},"dist":{"integrity":"sha512-YxiQoLDtiMkr+rMzyZPKzlWsqohXYprr60ORXcHZBpV7DlcZwQLWR+Ros6yQVxM4q55YrWCGoWd3F7zp78a+YQ==","shasum":"8d13ce994ea04f14d599e7e12b3cef2f80681496","tarball":"http://registry-npm.ywwl.com/@antv/util/download/@antv/util-1.2.1.tgz","fileCount":255,"unpackedSize":284870,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbmcmjCRA9TVsSAnZWagAAM1oQAI176FjfYDyL0VATcbBV\nWUhP7XjRtunVuovBXkFP28EpFuEs0thLgQFfm+/3esbOQNJZCWpDVKS7itIf\n5y41XfV9LmY+CHaAYgf6E6z5jgsayTDZMILMPNli1gUWVtw/rp1126NRAz5X\nFUP4Th8+fVm3MSe9UYXKFqk/NOeS5e5nD2T2f+2jgt6+D/Wg7TV/XvZx4tYU\n+JX/CP/F5PfxMEyoPaBSMTFMmcSHaGV7wmi/oMpnqqryHwKmRHrst9jYXfE5\nXzs0yXg6LcwRtDKhNXd1nbbL73nvH81CtadG/C50aW0VG/dNxj6bLNwVU+sH\ngTDNOLLxV5/W/F9Bw/LqaxlQFKQPYBuSn3xIfjn1aUP9v4v5Cpad6N4N2HYw\n1Ya+nBgXABaQ6CWu1dI8Cvqsur9rvfTb18mClvgxgO4KaUBw361DJDEP9CAU\nj8DYK3fQ91FTWtlwUDH/Ek1aM9aYdahNqFb9B8eM/VWQsgmUKQ1olbns3sPG\nYh7FG8zDp5r3adZChlZHvxY7CTV9LQ7kzrnFlQ85bjABiENXymIyVMZuH7dw\nlT9i5PdU6sbY0RQn9L2e/eZh9KSRTBffYhCSdPJCDf0ScxferiDhnYGFpPIm\nBT+Umg+PJ0Ll+JclBKTSJUB93xaV6E1j0FNcruC3lSyUohtLQwBGVl587UqV\nJzlb\r\n=CZwC\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQClYFgIeLueVWXcFB9rHWVfAEZLKO+0boX+xjcQV6KfywIhAPmo3klPTxIOA7+Z29OkWED4QCFu2SW1AVPhcq5ZSLgz"}],"size":82132,"noattachment":false,"key":"/@antv/util/-/@antv/util-1.2.1.tgz"},"maintainers":[{"email":"418466938@qq.com","name":"dori"},{"email":"dxq613@gmail.com","name":"dxq613"},{"email":"yilin.qyl@antfin.com","name":"elaine.q.10"},{"email":"leungwensen@gmail.com","name":"leungwensen"},{"email":"360965398@qq.com","name":"sakuya223"},{"email":"sima.zhang1990@gmail.com","name":"simaq"},{"email":"yanyanwang93@gmail.com","name":"yanyan-wang"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/util_1.2.1_1536805282266_0.54244615501913"},"_hasShrinkwrap":false,"readme":"# util\n\n> AntV 底层依赖的工具库，不建议在自己业务中使用。\n\n[![Build Status](https://github.com/antvis/util/workflows/build/badge.svg)](https://github.com/antvis/util/actions)\n[![npm Version](https://img.shields.io/npm/v/@antv/util.svg)](https://www.npmjs.com/package/@antv/util)\n[![npm Download](https://img.shields.io/npm/dm/@antv/util.svg)](https://www.npmjs.com/package/@antv/util)\n[![npm License](https://img.shields.io/npm/l/@antv/util.svg)](https://www.npmjs.com/package/@antv/util)\n\n## Usage\n\n```ts\nimport { gradient } from '@antv/util';\n```\n\n## 原则\n\n- util 只有一个 npm 包，按照目录来组织不同类型的方法，避免 monorepo 互相依赖\n- 内容和 AntV 强相关，避免做和 lodash 等相同的工具库\n- 不使用的方法，及时删除，并保持新增方法可以按需引入\n- 旧版本的不维护，如果 AntV 技术栈的旧版本需要迭代，请升级到 v3\n\n## API\n\n提供以下 Path 工具方法，包含转换、几何计算等。\n\n### path2String\n\n将 PathArray 转换成字符串形式，不会对原始定义中的命令进行修改：\n\n```js\nconst str: PathArray = [\n  ['M', 10, 10],\n  ['L', 100, 100],\n  ['l', 10, 10],\n  ['h', 20],\n  ['v', 20],\n];\nexpect(path2String(str)).toEqual('M10 10L100 100l10 10h20v20');\n```\n\n### path2Array\n\n将 PathArray 转换成数组，不会对原始定义中的命令进行修改：\n\n```js\nconst str = 'M10 10L100 100l10 10h20v20';\nexpect(path2Array(str)).toEqual([\n  ['M', 10, 10],\n  ['L', 100, 100],\n  ['l', 10, 10],\n  ['h', 20],\n  ['v', 20],\n]);\n```\n\n### path2Absolute\n\n将定义中的相对命令转换成绝对命令，例如：\n\n- l -> L\n- h -> H\n- v -> V\n\n完整方法签名如下：\n\n```js\npath2Absolute(pathInput: string | PathArray): AbsoluteArray;\n```\n\n```js\nconst str: PathArray = [\n  ['M', 10, 10],\n  ['L', 100, 100],\n  ['l', 10, 10],\n  ['h', 20],\n  ['v', 20],\n];\nconst arr = path2Absolute(str);\nexpect(arr).toEqual([\n  ['M', 10, 10],\n  ['L', 100, 100],\n  ['L', 110, 110],\n  ['H', 130],\n  ['V', 130],\n]);\n```\n\n### path2Curve\n\n将部分命令转曲，例如 L / A 转成 C 命令，借助 cubic bezier 易于分割的特性用于实现形变动画。\n该方法内部会调用 [path2Absolute](#path2Absolute)，因此最终返回的 PathArray 中仅包含 M 和 C 命令。\n\n完整方法签名如下：\n\n```js\npath2Curve(pathInput: string | PathArray): CurveArray;\n```\n\n```js\nexpect(\n  path2Curve([\n    ['M', 0, 0],\n    ['L', 100, 100],\n  ]),\n).toEqual([\n  ['M', 0, 0],\n  ['C', 44.194173824159215, 44.194173824159215, 68.75, 68.75, 100, 100],\n]);\n```\n\n### clonePath\n\n复制路径：\n\n```js\nconst cloned = clonePath(pathInput);\n```\n\n### reverseCurve\n\n```js\nconst pathArray: CurveArray = [\n  ['M', 170, 90],\n  ['C', 150, 90, 155, 10, 130, 10],\n  ['C', 105, 10, 110, 90, 90, 90],\n  ['C', 70, 90, 75, 10, 50, 10],\n  ['C', 25, 10, 30, 90, 10, 90],\n];\n\nconst reversed = reverseCurve(pathArray);\n```\n\n### getPathBBox\n\n获取几何定义下的包围盒，形如：\n\n```js\nexport interface PathBBox {\n  width: number;\n  height: number;\n  x: number;\n  y: number;\n  x2: number;\n  y2: number;\n  cx: number;\n  cy: number;\n  cz: number;\n}\n```\n\n```js\nconst bbox = getPathBBox([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']]);\n\nexpect(bbox).toEqual({ cx: 50, cy: 50, cz: 150, height: 100, width: 100, x: 0, x2: 100, y: 0, y2: 100 });\n```\n\n### getTotalLength\n\n获取路径总长度。\n\n```js\nconst length = getTotalLength([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']]);\n\nexpect(length).toEqual(400);\n```\n\n### getPointAtLength\n\n获取路径上从起点出发，到指定距离的点。\n\n```js\nconst point = getPointAtLength([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']], 0);\nexpect(point).toEqual({ x: 0, y: 0 });\n```\n\n### getPathArea\n\n计算路径包围的面积。内部实现中首先通过 [path2Curve](#path2Curve) 转曲，再计算 cubic curve 面积，[详见](https://stackoverflow.com/a/15845996)。\n\n方法签名如下：\n\n```js\nfunction getPathArea(path: PathArray): number;\n```\n\n### isPointInStroke\n\n判断一个点是否在路径上，仅通过几何定义计算，不考虑其他样式属性例如线宽、lineJoin、miter 等。\n\n方法签名如下：\n\n```js\nisPointInStroke(pathInput: string | PathArray, point: Point): boolean;\n```\n\n```js\nconst result = isPointInStroke(segments, { x: 10, y: 10 });\n```\n\n### distanceSquareRoot\n\n计算两点之间的距离。\n\n方法签名如下：\n\n```js\ndistanceSquareRoot(a: [number, number], b: [number, number]): number;\n```\n\n### equalizeSegments\n\n将两条路径处理成段数相同，用于形变动画前的分割操作。\n\n```js\nconst [formattedPath1, formattedPath2] = equalizeSegments(path1, path2);\n```\n\n### isPointInPolygon\n\n判断一个点是否在多边形内。多边形形如：\n\n```js\nconst polygon = [\n  [0, 0],\n  [0, 100],\n  [30, 100],\n  [30, 0],\n];\n\n// [0, 0] 在多边形的边上\nisPointInPolygon(polygon, 0, 0); // true\n```\n\n### isPolygonsIntersect\n\n判断两个多边形是否相交：\n\n```js\nisPolygonsIntersect(polygon1, polygon2);\n```\n\n## License\n\nMIT@[AntV](https://github.com/antvis).\n","publish_time":1536805282454,"_cnpm_publish_time":1536805282454,"dist-tags":{"beta":"1.0.6-beta.2","latest":"3.3.11"}}