diff options
-rw-r--r-- | src/client/documents/Documents.ts | 20 | ||||
-rw-r--r-- | src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx | 66 |
2 files changed, 34 insertions, 52 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 640fb251d..a67e6b4f6 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -5,22 +5,7 @@ import { reaction } from 'mobx'; import { basename } from 'path'; import { ClientUtils, OmitKeys } from '../../ClientUtils'; import { DateField } from '../../fields/DateField'; -import { - ActiveArrowEnd, - ActiveArrowStart, - ActiveDash, - ActiveFillColor, - ActiveInkBezierApprox, - ActiveInkColor, - ActiveEraserWidth, - ActiveInkWidth, - ActiveIsInkMask, - CreateLinkToActiveAudio, - Doc, - FieldType, - Opt, - updateCachedAcls, -} from '../../fields/Doc'; +import { ActiveArrowEnd, ActiveArrowStart, ActiveDash, ActiveFillColor, ActiveInkBezierApprox, ActiveInkColor, ActiveInkWidth, ActiveIsInkMask, CreateLinkToActiveAudio, Doc, FieldType, Opt, updateCachedAcls } from '../../fields/Doc'; import { Initializing } from '../../fields/DocSymbols'; import { HtmlField } from '../../fields/HtmlField'; import { InkField } from '../../fields/InkField'; @@ -852,7 +837,6 @@ export namespace Docs { points: PointData[], options: DocumentOptions = {}, strokeWidth = ActiveInkWidth(), - eraserWidth = ActiveEraserWidth(), color = ActiveInkColor(), strokeBezier = ActiveInkBezierApprox(), fillColor = ActiveFillColor(), @@ -963,7 +947,7 @@ export namespace Docs { return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { ...options, _type_collection: CollectionViewType.Carousel3D }); } - export function CardDeckDocument(documents: Array<Doc>, options: DocumentOptions, id?: string) { + export function CardDeckDocument(documents: Array<Doc>, options: DocumentOptions) { return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { ...options, _type_collection: CollectionViewType.Card }); } diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index be96b914c..b6e1fca77 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -894,7 +894,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection const inkList = strokeToTVals.get(inkView); if (inkList !== undefined) { const tValOffset = ActiveEraserWidth() / 1050; // to prevent tVals from being added when too close, but scaled by eraser width - const inList = inkList.some(val => Math.abs(val - (t + Math.floor(i / 4))) <= tValOffset); + const inList = inkList.some(ival => Math.abs(ival - (t + Math.floor(i / 4))) <= tValOffset); if (!inList) { inkList.push(t + Math.floor(i / 4)); } @@ -1007,7 +1007,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection let segment2: Segment = []; const { inkData } = (ink?.ComponentView as InkingStroke).inkScaledData(); let intersections: number[] = []; // list of the ink stroke's intersections - let segmentIndexes: number[] = []; // list of indexes of the curve's segment where each intersection occured + const segmentIndexes: number[] = []; // list of indexes of the curve's segment where each intersection occured // loops through each segment and adds intersections to the list for (let i = 0; i < inkData.length - 3; i += 4) { @@ -1034,7 +1034,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection if (intersections.length) { // this is the indexes of the closest intersection(s) - let closestTs = this.getClosestTs(intersections, excludeT, 0, intersections.length - 1); + const closestTs = this.getClosestTs(intersections, excludeT, 0, intersections.length - 1); // find the segments that need to be split let splitSegment1 = -1; // stays -1 if left end is deleted @@ -1095,23 +1095,22 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection } else if (hasSplit && !continueErasing) { segment2.push(inkSegment); } - } else { - // case where last end is erased - if (currCurveT === segmentIndexes[0] && isClosedCurve) { - if (isClosedCurve && currCurveT === segmentIndexes.lastElement()) { - segment1.push(inkSegment.split(intersections[0] - currCurveT, intersections.lastElement() - currCurveT)); - continueErasing = true; - } else { - segment1.push(inkSegment.split(intersections[0] - currCurveT, 1)); - } - hasSplit = true; - } else if (currCurveT === splitSegment1) { - segment1.push(inkSegment.split(0, intersections[closestTs[0]] - currCurveT)); - hasSplit = true; + } + // case where last end is erased + else if (currCurveT === segmentIndexes[0] && isClosedCurve) { + if (isClosedCurve && currCurveT === segmentIndexes.lastElement()) { + segment1.push(inkSegment.split(intersections[0] - currCurveT, intersections.lastElement() - currCurveT)); continueErasing = true; - } else if ((isClosedCurve && hasSplit && !continueErasing) || (!isClosedCurve && !hasSplit)) { - segment1.push(inkSegment); + } else { + segment1.push(inkSegment.split(intersections[0] - currCurveT, 1)); } + hasSplit = true; + } else if (currCurveT === splitSegment1) { + segment1.push(inkSegment.split(0, intersections[closestTs[0]] - currCurveT)); + hasSplit = true; + continueErasing = true; + } else if ((isClosedCurve && hasSplit && !continueErasing) || (!isClosedCurve && !hasSplit)) { + segment1.push(inkSegment); } } } @@ -1144,22 +1143,21 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection getClosestTs = (tVals: number[], excludeT: number, startIndex: number, endIndex: number): number[] => { if (tVals[startIndex] >= excludeT) { return [-1, startIndex]; - } else if (tVals[endIndex] < excludeT) { + } + if (tVals[endIndex] < excludeT) { return [endIndex, -1]; - } else { - const mid = Math.floor((startIndex + endIndex) / 2); - if (excludeT >= tVals[mid]) { - if (mid + 1 <= endIndex && tVals[mid + 1] > excludeT) { - return [mid, mid + 1]; - } else { - return this.getClosestTs(tVals, excludeT, mid + 1, endIndex); - } - } else if (mid - 1 >= startIndex && tVals[mid - 1] < excludeT) { - return [mid - 1, mid]; - } else { - return this.getClosestTs(tVals, excludeT, startIndex, mid - 1); + } + const mid = Math.floor((startIndex + endIndex) / 2); + if (excludeT >= tVals[mid]) { + if (mid + 1 <= endIndex && tVals[mid + 1] > excludeT) { + return [mid, mid + 1]; } + return this.getClosestTs(tVals, excludeT, mid + 1, endIndex); + } + if (mid - 1 >= startIndex && tVals[mid - 1] < excludeT) { + return [mid - 1, mid]; } + return this.getClosestTs(tVals, excludeT, startIndex, mid - 1); }; // for some reason bezier.js doesn't handle the case of intersecting a linear curve, so we wrap the intersection @@ -1212,10 +1210,10 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection if (apt.d !== undefined && apt.d < 1 && apt.t !== undefined && !tVals.includes(apt.t)) { tVals.push(apt.t); } - this.bintersects(curve, otherCurve).forEach((val: string | number, i: number) => { + this.bintersects(curve, otherCurve).forEach((val: string | number, ival: number) => { // Converting the Bezier.js Split type to a t-value number. const t = +val.toString().split('/')[0]; - if (i % 2 === 0 && !tVals.includes(t)) tVals.push(t); // bcz: Hack! don't know why but intersection points are doubled from bezier.js (but not identical). + if (ival % 2 === 0 && !tVals.includes(t)) tVals.push(t); // bcz: Hack! don't know why but intersection points are doubled from bezier.js (but not identical). }); if (bpt.d !== undefined && bpt.d < 1 && bpt.t !== undefined && !tVals.includes(bpt.t)) { tVals.push(bpt.t); @@ -1775,8 +1773,8 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection ({ code, first }) => { if (!code.includes('dashDiv')) { const script = CompileScript(code, { params: { docView: 'any' }, typecheck: false, editable: true }); - // eslint-disable-next-line no-eval if (script.compiled) script.run({ this: this.DocumentView?.() }); + // eslint-disable-next-line no-eval } else code && !first && eval?.(code); }, { fireImmediately: true } |