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AQ,OAAS,GAAI,GAOhH,YANuB,IAAnB,EAAQ,SACV,EAAQ,QAAS,GAEf,EAAQ,SACT,EAAK,QAAU,EAAW,QAAQ,aAAa,SAAS,GAEpD,C","file":"/npm/paperjs-offset-core@1.0.10/dist/index.umd.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/paperjs-offset-core@1.0.10/dist/index.umd.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import type paper from 'paper/dist/paper-core';\n\nexport type StrokeJoinType = 'miter' | 'bevel' | 'round';\nexport type StrokeCapType = 'round' | 'butt';\nexport type PathType = paper.Path | paper.CompoundPath;\n\ntype HandleType = 'handleIn' | 'handleOut';\n\n/**\n * Offset the start/terminal segment of a bezier curve\n * @param segment segment to offset\n * @param curve curve to offset\n * @param handleNormal the normal of the the line formed of two handles\n * @param offset offset value\n */\nfunction offsetSegment(segment: paper.Segment, curve: paper.Curve, handleNormal: paper.Point, offset: number, paperScope: paper.PaperScope) {\n  const isFirst = segment.curve === curve;\n  // get offset vector\n  const offsetVector = (curve.getNormalAtTime(isFirst ? 0 : 1)).multiply(offset);\n  // get offset point\n  const point = segment.point.add(offsetVector);\n  const newSegment = new paperScope.Segment(point);\n  // handleOut for start segment & handleIn for terminal segment\n  const handle = (isFirst ? 'handleOut' : 'handleIn') as HandleType;\n  newSegment[handle] = segment[handle]!.add(handleNormal.subtract(offsetVector).divide(2));\n  return newSegment;\n}\n\n/**\n * Adaptive offset a curve by repeatly apply the approximation proposed by Tiller and Hanson.\n * @param curve curve to offset\n * @param offset offset value\n */\nfunction adaptiveOffsetCurve(curve: paper.Curve, offset: number, paperScope: paper.PaperScope): paper.Segment[] {\n  const hNormal = (new paperScope.Curve(curve.segment1.handleOut!.add(curve.segment1.point), new paperScope.Point(0, 0),\n    new paperScope.Point(0, 0), curve.segment2.handleIn!.add(curve.segment2.point))).getNormalAtTime(0.5).multiply(offset);\n  const segment1 = offsetSegment(curve.segment1, curve, hNormal, offset, paperScope);\n  const segment2 = offsetSegment(curve.segment2, curve, hNormal, offset, paperScope);\n  // divide && re-offset\n  const offsetCurve = new paperScope.Curve(segment1, segment2);\n  // if the offset curve is not self intersected, divide it\n  if (offsetCurve.getIntersections(offsetCurve).length === 0) {\n    const threshold = Math.min(Math.abs(offset) / 10, 1);\n    const midOffset = offsetCurve.getPointAtTime(0.5).getDistance(curve.getPointAtTime(0.5));\n    if (Math.abs(midOffset - Math.abs(offset)) > threshold) {\n      const subCurve = curve.divideAtTime(0.5);\n      if (subCurve != null) {\n        return [...adaptiveOffsetCurve(curve, offset, paperScope), ...adaptiveOffsetCurve(subCurve, offset, paperScope)];\n      }\n    }\n  }\n  return [segment1, segment2];\n}\n\n/**\n * Create a round join segment between two adjacent segments.\n */\nfunction makeRoundJoin(segment1: paper.Segment, segment2: paper.Segment, originPoint: paper.Point, radius: number, paperScope: paper.PaperScope) {\n  const through = segment1.point.subtract(originPoint).add(segment2.point.subtract(originPoint))\n    .normalize(Math.abs(radius)).add(originPoint);\n  const arc = new paperScope.Path.Arc({ from: segment1.point, to: segment2.point, through, insert: false });\n  segment1.handleOut = arc.firstSegment.handleOut;\n  segment2.handleIn = arc.lastSegment.handleIn;\n  return arc.segments.length === 3 ? arc.segments[1] : null;\n}\n\nfunction det(p1: paper.Point, p2: paper.Point) {\n  return p1.x * p2.y - p1.y * p2.x;\n}\n\n/**\n * Get the intersection point of point based lines\n */\nfunction getPointLineIntersections(p1: paper.Point, p2: paper.Point, p3: paper.Point, p4: paper.Point, paperScope: paper.PaperScope) {\n  const l1 = p1.subtract(p2);\n  const l2 = p3.subtract(p4);\n  const dl1 = det(p1, p2);\n  const dl2 = det(p3, p4);\n  return new paperScope.Point(dl1 * l2.x - l1.x * dl2, dl1 * l2.y - l1.y * dl2).divide(det(l1, l2));\n}\n\n/**\n * Connect two adjacent bezier curve, each curve is represented by two segments,\n * create different types of joins or simply removal redundant segment.\n */\nfunction connectAdjacentBezier(segments1: paper.Segment[], segments2: paper.Segment[], origin: paper.Segment,\njoinType: StrokeJoinType, offset: number, limit: number, paperScope: paper.PaperScope) {\n  const curve1 = new paperScope.Curve(segments1[0], segments1[1]);\n  const curve2 = new paperScope.Curve(segments2[0], segments2[1]);\n  const intersection = curve1.getIntersections(curve2);\n  const distance = segments1[1].point.getDistance(segments2[0].point);\n  if (origin.isSmooth()) {\n    segments2[0].handleOut = segments2[0].handleOut!.project(origin.handleOut!);\n    segments2[0].handleIn = segments1[1].handleIn!.project(origin.handleIn!);\n    segments2[0].point = segments1[1].point.add(segments2[0].point).divide(2);\n    segments1.pop();\n  } else {\n    if (intersection.length === 0) {\n      if (distance > Math.abs(offset) * 0.1) {\n        // connect\n        switch (joinType) {\n          case 'miter':\n            const join = getPointLineIntersections(curve1.point2, curve1.point2.add(curve1.getTangentAtTime(1)),\n              curve2.point1, curve2.point1.add(curve2.getTangentAtTime(0)), paperScope);\n            // prevent sharp angle\n            const joinOffset = Math.max(join.getDistance(curve1.point2), join.getDistance(curve2.point1));\n            if (joinOffset < Math.abs(offset) * limit) {\n              segments1.push(new paperScope.Segment(join));\n            }\n            break;\n          case 'round':\n            const mid = makeRoundJoin(segments1[1], segments2[0], origin.point, offset, paperScope);\n            if (mid) {\n              segments1.push(mid);\n            }\n            break;\n          default: break;\n        }\n      } else {\n        segments2[0].handleIn = segments1[1].handleIn;\n        segments1.pop();\n      }\n    } else {\n      const second1 = curve1.divideAt(intersection[0]);\n      if (second1) {\n        const join = second1.segment1;\n        const second2 = curve2.divideAt(curve2.getIntersections(curve1)[0]);\n        join.handleOut = second2 ? second2.segment1.handleOut : segments2[0].handleOut;\n        segments1.pop();\n        segments2[0] = join;\n      } else {\n        segments2[0].handleIn = segments1[1].handleIn;\n        segments1.pop();\n      }\n    }\n  }\n}\n\n/**\n * Connect all the segments together.\n */\nfunction connectBeziers(rawSegments: paper.Segment[][], join: StrokeJoinType, source: paper.Path, offset: number,\n  limit: number, paperScope: paper.PaperScope) {\n  const originSegments = source.segments;\n  const first = rawSegments[0].slice();\n  for (let i = 0; i < rawSegments.length - 1; ++i) {\n    connectAdjacentBezier(rawSegments[i], rawSegments[i + 1], originSegments[i + 1], join, offset, limit, paperScope);\n  }\n  if (source.closed) {\n    connectAdjacentBezier(rawSegments[rawSegments.length - 1], first, originSegments[0], join, offset, limit, paperScope);\n    rawSegments[0][0] = first[0];\n  }\n  return rawSegments;\n}\n\nfunction reduceSingleChildCompoundPath(path: PathType) {\n  if (path.children.length === 1) {\n    path = path.children[0] as paper.Path;\n    path.remove(); // remove from parent, this is critical, or the style attributes will be ignored\n  }\n  return path;\n}\n\n/** Normalize a path, always clockwise, non-self-intersection, ignore really small components, and no one-component compound path. */\nfunction normalize(path: PathType, areaThreshold = 0.01, paperScope: paper.PaperScope) {\n  if (path.closed) {\n    const ignoreArea = Math.abs(path.area * areaThreshold);\n    if (!path.clockwise) {\n      path.reverse();\n    }\n    path = path.unite(path, { insert: false }) as PathType;\n    if (path instanceof paperScope.CompoundPath) {\n      path.children.filter((c) => Math.abs((c as PathType).area) < ignoreArea).forEach((c) => c.remove());\n      if (path.children.length === 1) {\n        return reduceSingleChildCompoundPath(path);\n      }\n    }\n  }\n  return path;\n}\n\nfunction isSameDirection(partialPath: paper.Path, fullPath: PathType) {\n  const offset1 = partialPath.segments[0].location.offset;\n  const offset2 = partialPath.segments[Math.max(1, Math.floor(partialPath.segments.length / 2))].location.offset;\n  const sampleOffset = (offset1 + offset2) / 3;\n  const originOffset1 = fullPath.getNearestLocation(partialPath.getPointAt(sampleOffset)).offset;\n  const originOffset2 = fullPath.getNearestLocation(partialPath.getPointAt(2 * sampleOffset)).offset;\n  return originOffset1 < originOffset2;\n}\n\n/** Remove self intersection when offset is negative by point direction dectection. */\nfunction removeIntersection(path: PathType, paperScope: paper.PaperScope) {\n  if (path.closed) {\n    const newPath = path.unite(path, { insert: false }) as PathType;\n    if (newPath instanceof paperScope.CompoundPath) {\n      (newPath.children as paper.Path[]).filter((c) => {\n        if (c.segments.length > 1) {\n          return !isSameDirection(c, path);\n        } else {\n          return true;\n        }\n      }).forEach((c) => c.remove());\n      return reduceSingleChildCompoundPath(newPath);\n    }\n  }\n  return path;\n}\n\nfunction getSegments(path: PathType, paperScope: paper.PaperScope) {\n  if (path instanceof paperScope.CompoundPath) {\n    return path.children.map((c) => (c as paper.Path).segments).flat();\n  } else {\n    return (path as paper.Path).segments;\n  }\n}\n\n/**\n * Remove impossible segments in negative offset condition.\n */\nfunction removeOutsiders(newPath: PathType, path: PathType, paperScope: paper.PaperScope) {\n  const segments = getSegments(newPath, paperScope).slice();\n  segments.forEach((segment) => {\n    if (!path.contains(segment.point)) {\n      segment.remove();\n    }\n  });\n}\n\nfunction preparePath(path: paper.Path, offset: number): [paper.Path, number] {\n  const source = path.clone({ insert: false }) as paper.Path;\n  source.reduce({});\n  if (!path.clockwise) {\n    source.reverse();\n    offset = -offset;\n  }\n  return [source, offset];\n}\n\nfunction offsetSimpleShape(path: paper.Path, offset: number, join: StrokeJoinType, limit: number, paperScope: paper.PaperScope): PathType {\n  let source: paper.Path;\n  [source, offset] = preparePath(path, offset);\n  const curves = source.curves.slice();\n  const offsetCurves = curves.map((curve) => adaptiveOffsetCurve(curve, offset, paperScope)).flat();\n  const raws: paper.Segment[][] = [];\n  for (let i = 0; i < offsetCurves.length; i += 2) {\n    raws.push(offsetCurves.slice(i, i + 2));\n  }\n  const segments = connectBeziers(raws, join, source, offset, limit, paperScope).flat();\n  const newPath = removeIntersection(new paperScope.Path({ segments, insert: false, closed: path.closed }), paperScope);\n  newPath.reduce({});\n  if (source.closed && ((source.clockwise && offset < 0) || (!source.clockwise && offset > 0))) {\n    removeOutsiders(newPath, path, paperScope);\n  }\n  // recovery path\n  if (source.clockwise !== path.clockwise) {\n    newPath.reverse();\n  }\n  return normalize(newPath, 0.01, paperScope);\n}\n\nfunction makeRoundCap(from: paper.Segment, to: paper.Segment, offset: number, paperScope: paper.PaperScope) {\n  const origin = from.point.add(to.point).divide(2);\n  const normal = to.point.subtract(from.point).rotate(-90, new paperScope.Point(0, 0)).normalize(offset);\n  const through = origin.add(normal);\n  const arc = new paperScope.Path.Arc({ from: from.point, to: to.point, through, insert: false });\n  return arc.segments;\n}\n\nfunction connectSide(outer: PathType, inner: paper.Path, offset: number, cap: StrokeCapType, paperScope: paper.PaperScope): paper.Path {\n  if (outer instanceof paperScope.CompoundPath) {\n    let cs = outer.children.map((c) => ({ c, a: Math.abs((c as paper.Path).area) }));\n    cs = cs.sort((c1, c2) => c2.a - c1.a);\n    outer = cs[0].c as paper.Path;\n  }\n  const oSegments = (outer as paper.Path).segments.slice();\n  const iSegments = inner.segments.slice();\n  switch (cap) {\n    case 'round':\n      const heads = makeRoundCap(iSegments[iSegments.length - 1], oSegments[0], offset, paperScope);\n      const tails = makeRoundCap(oSegments[oSegments.length - 1], iSegments[0], offset, paperScope);\n      const result = new paperScope.Path({ segments: [...heads, ...oSegments, ...tails, ...iSegments], closed: true, insert: false });\n      result.reduce({});\n      return result;\n    default: return new paperScope.Path({ segments: [...oSegments, ...iSegments], closed: true, insert: false });\n  }\n}\n\nfunction offsetSimpleStroke(path: paper.Path, offset: number, join: StrokeJoinType, cap: StrokeCapType, limit: number, paperScope: paper.PaperScope): PathType {\n  offset = path.clockwise ? offset : -offset;\n  const positiveOffset = offsetSimpleShape(path, offset, join, limit, paperScope);\n  const negativeOffset = offsetSimpleShape(path, -offset, join, limit, paperScope);\n  if (path.closed) {\n    return positiveOffset.subtract(negativeOffset, { insert: false }) as PathType;\n  } else {\n    let inner = negativeOffset;\n    let holes = new Array<paper.Path>();\n    if (negativeOffset instanceof paperScope.CompoundPath) {\n      holes = negativeOffset.children.filter((c) => (c as paper.Path).closed) as paper.Path[];\n      holes.forEach((h) => h.remove());\n      inner = negativeOffset.children[0] as paper.Path;\n    }\n    inner.reverse();\n    let final = connectSide(positiveOffset, inner as paper.Path, offset, cap, paperScope) as PathType;\n    if (holes.length > 0) {\n      for (const hole of holes) {\n        final = final.subtract(hole, { insert: false }) as PathType;\n      }\n    }\n    return final;\n  }\n}\n\nfunction getNonSelfItersectionPath(path: PathType) {\n  if (path.closed) {\n    return path.unite(path, { insert: false }) as PathType;\n  }\n  return path;\n}\n\nexport function offsetPath(path: PathType, offset: number, join: StrokeJoinType, limit: number, paperScope: paper.PaperScope): PathType {\n  const nonSIPath = getNonSelfItersectionPath(path);\n  let result = nonSIPath;\n  if (nonSIPath instanceof paperScope.Path) {\n    result = offsetSimpleShape(nonSIPath, offset, join, limit, paperScope);\n  } else {\n    const offsetParts = (nonSIPath.children as paper.Path[]).map((c) => {\n      if (c.segments.length > 1) {\n        if (!isSameDirection(c, path)) {\n          c.reverse();\n        }\n        let offseted = offsetSimpleShape(c, offset, join, limit, paperScope);\n        offseted = normalize(offseted, 0.01, paperScope);\n        if (offseted.clockwise !== c.clockwise) {\n          offseted.reverse();\n        }\n        if (offseted instanceof paperScope.CompoundPath) {\n          offseted.applyMatrix = true;\n          return offseted.children;\n        } else {\n          return offseted;\n        }\n      } else {\n        return null;\n      }\n    });\n    const children = offsetParts.flat().filter((c) => !!c) as paper.Item[];\n    result = new paperScope.CompoundPath({ children, insert: false });\n  }\n  result.copyAttributes(nonSIPath, false);\n  result.remove();\n  return result;\n}\n\nexport function offsetStroke(path: PathType, offset: number, join: StrokeJoinType, cap: StrokeCapType, limit: number, paperScope: paper.PaperScope): PathType {\n  const nonSIPath = getNonSelfItersectionPath(path);\n  let result = nonSIPath;\n  if (nonSIPath instanceof paperScope.Path) {\n    result = offsetSimpleStroke(nonSIPath, offset, join, cap, limit, paperScope);\n  } else {\n    const children = (nonSIPath.children as paper.Path[]).flatMap((c) => {\n      return offsetSimpleStroke(c, offset, join, cap, limit, paperScope);\n    });\n    result = children.reduce((c1, c2) => c1.unite(c2, { insert: false }) as PathType);\n  }\n  result.strokeWidth = 0;\n  result.fillColor = nonSIPath.strokeColor;\n  result.shadowBlur = nonSIPath.shadowBlur;\n  result.shadowColor = nonSIPath.shadowColor;\n  result.shadowOffset = nonSIPath.shadowOffset;\n  return result;\n}\n","import type paper from 'paper/dist/paper-core';\nimport { StrokeJoinType, PathType, StrokeCapType, offsetPath, offsetStroke } from './offset_core';\n\nexport interface OffsetOptions {\n  join?: StrokeJoinType;\n  cap?: StrokeCapType;\n  limit?: number;\n  insert?: boolean;\n  scope: paper.PaperScope;\n}\n\nexport class PaperOffset {\n  public static offset(path: PathType, offset: number, options?: OffsetOptions): PathType {\n    if (!options || !options.scope) {\n      throw new Error('Options need to be defined with a scope property referencing a Paperscope.');\n    }\n\n    const paperScope = options.scope;\n    const newPath = offsetPath(path, offset, options.join || 'miter', options.limit || 10, paperScope);\n    if (options.insert === undefined) {\n      options.insert = true;\n    }\n    if (options.insert) {\n      (path.parent || paperScope.project.activeLayer).addChild(newPath);\n    }\n    return newPath;\n  }\n\n  public static offsetStroke(path: PathType, offset: number, options?: OffsetOptions): PathType {\n    if (!options || !options.scope) {\n      throw new Error('Options need to be defined with a scope property referencing a Paperscope.');\n    }\n\n    const paperScope = options.scope;\n    const newPath = offsetStroke(path, offset, options.join || 'miter', options.cap || 'butt', options.limit || 10, paperScope);\n    if (options.insert === undefined) {\n      options.insert = true;\n    }\n    if (options.insert) {\n      (path.parent || paperScope.project.activeLayer).addChild(newPath);\n    }\n    return newPath;\n  }\n}\n"]}