figureone 0.15.10 → 1.0.0
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/figureone.min.js +1 -1
- package/index.js +79167 -0
- package/package.json +15 -1
- package/types/index.d.ts +132 -0
- package/types/js/figure/Animation/Animation.d.ts +36 -0
- package/types/js/figure/Animation/AnimationBuilder.d.ts +173 -0
- package/types/js/figure/Animation/AnimationManager.d.ts +392 -0
- package/types/js/figure/Animation/AnimationStep/CustomStep.d.ts +99 -0
- package/types/js/figure/Animation/AnimationStep/DelayStep.d.ts +24 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ColorAnimationStep.d.ts +203 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/OpacityAnimationStep.d.ts +220 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PositionAnimationStep.d.ts +124 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PulseAnimationStep.d.ts +137 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PulseTransformAnimationStep.d.ts +52 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/RotationAnimationStep.d.ts +119 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ScaleAnimationStep.d.ts +93 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ScenarioAnimationStep.d.ts +204 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/TransformAnimationStep.d.ts +163 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep.d.ts +56 -0
- package/types/js/figure/Animation/AnimationStep/ParallelAnimationStep.d.ts +70 -0
- package/types/js/figure/Animation/AnimationStep/SerialAnimationStep.d.ts +84 -0
- package/types/js/figure/Animation/AnimationStep/TriggerStep.d.ts +106 -0
- package/types/js/figure/Animation/AnimationStep.d.ts +110 -0
- package/types/js/figure/DrawContext2D.d.ts +9 -0
- package/types/js/figure/DrawingObjects/DrawingObject.d.ts +45 -0
- package/types/js/figure/DrawingObjects/GLObject/GLObject.d.ts +146 -0
- package/types/js/figure/DrawingObjects/HTMLObject/HTMLObject.d.ts +29 -0
- package/types/js/figure/DrawingObjects/TextObject/TextObject.d.ts +94 -0
- package/types/js/figure/DrawingObjects/TextObject/glyphMeasures.d.ts +7 -0
- package/types/js/figure/DrawingObjects/VertexObject/VertexGeneric.d.ts +21 -0
- package/types/js/figure/DrawingObjects/VertexObject/VertexObject.d.ts +0 -0
- package/types/js/figure/DrawingObjects/VertexObject/VertexText.d.ts +34 -0
- package/types/js/figure/Element.d.ts +1212 -0
- package/types/js/figure/Equation/Elements/BaseAnnotationFunction.d.ts +118 -0
- package/types/js/figure/Equation/Elements/BaseEquationFunction.d.ts +20 -0
- package/types/js/figure/Equation/Elements/Bounds.d.ts +49 -0
- package/types/js/figure/Equation/Elements/Color.d.ts +7 -0
- package/types/js/figure/Equation/Elements/Container.d.ts +5 -0
- package/types/js/figure/Equation/Elements/Element.d.ts +95 -0
- package/types/js/figure/Equation/Elements/Fraction.d.ts +5 -0
- package/types/js/figure/Equation/Elements/Lines.d.ts +5 -0
- package/types/js/figure/Equation/Elements/Matrix.d.ts +5 -0
- package/types/js/figure/Equation/Elements/Offset.d.ts +5 -0
- package/types/js/figure/Equation/Elements/Scale.d.ts +5 -0
- package/types/js/figure/Equation/Equation.d.ts +984 -0
- package/types/js/figure/Equation/EquationForm.d.ts +139 -0
- package/types/js/figure/Equation/EquationFunctions.d.ts +3367 -0
- package/types/js/figure/Equation/EquationSymbols.d.ts +1646 -0
- package/types/js/figure/Equation/HTMLEquation.d.ts +56 -0
- package/types/js/figure/Equation/Symbols/AngleBracket.d.ts +6 -0
- package/types/js/figure/Equation/Symbols/Arrow.d.ts +17 -0
- package/types/js/figure/Equation/Symbols/Bar.d.ts +6 -0
- package/types/js/figure/Equation/Symbols/Box.d.ts +11 -0
- package/types/js/figure/Equation/Symbols/Brace.d.ts +6 -0
- package/types/js/figure/Equation/Symbols/Bracket.d.ts +8 -0
- package/types/js/figure/Equation/Symbols/Division.d.ts +8 -0
- package/types/js/figure/Equation/Symbols/Integral.d.ts +7 -0
- package/types/js/figure/Equation/Symbols/Line.d.ts +5 -0
- package/types/js/figure/Equation/Symbols/Product.d.ts +6 -0
- package/types/js/figure/Equation/Symbols/Radical.d.ts +9 -0
- package/types/js/figure/Equation/Symbols/SquareBracket.d.ts +6 -0
- package/types/js/figure/Equation/Symbols/Strike.d.ts +8 -0
- package/types/js/figure/Equation/Symbols/Sum.d.ts +6 -0
- package/types/js/figure/Equation/Symbols/SymbolNew.d.ts +15 -0
- package/types/js/figure/Equation/Symbols/Vinculum.d.ts +6 -0
- package/types/js/figure/Figure.d.ts +711 -0
- package/types/js/figure/FigureCollections/Angle.d.ts +766 -0
- package/types/js/figure/FigureCollections/Axis.d.ts +517 -0
- package/types/js/figure/FigureCollections/Axis3.d.ts +118 -0
- package/types/js/figure/FigureCollections/Button.d.ts +195 -0
- package/types/js/figure/FigureCollections/EquationLabel.d.ts +77 -0
- package/types/js/figure/FigureCollections/FigureCollections.d.ts +122 -0
- package/types/js/figure/FigureCollections/Legend.d.ts +270 -0
- package/types/js/figure/FigureCollections/Line.d.ts +587 -0
- package/types/js/figure/FigureCollections/Plot.d.ts +558 -0
- package/types/js/figure/FigureCollections/PolyLine.d.ts +487 -0
- package/types/js/figure/FigureCollections/Rectangle.d.ts +235 -0
- package/types/js/figure/FigureCollections/SlideNavigator.d.ts +255 -0
- package/types/js/figure/FigureCollections/Slider.d.ts +155 -0
- package/types/js/figure/FigureCollections/Text.d.ts +307 -0
- package/types/js/figure/FigureCollections/Toggle.d.ts +185 -0
- package/types/js/figure/FigureCollections/Trace.d.ts +237 -0
- package/types/js/figure/FigurePrimitives/FigureElementPrimitive2DText.d.ts +119 -0
- package/types/js/figure/FigurePrimitives/FigureElementPrimitiveGLText.d.ts +94 -0
- package/types/js/figure/FigurePrimitives/FigureElementPrimitiveGesture.d.ts +536 -0
- package/types/js/figure/FigurePrimitives/FigureElementPrimitiveMorph.d.ts +175 -0
- package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes.d.ts +788 -0
- package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes2D.d.ts +1324 -0
- package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes3D.d.ts +1105 -0
- package/types/js/figure/FigurePrimitives/FigurePrimitives.d.ts +173 -0
- package/types/js/figure/FigurePrimitives/Generic.d.ts +5 -0
- package/types/js/figure/FigurePrimitives/Text.d.ts +17 -0
- package/types/js/figure/FontManager.d.ts +113 -0
- package/types/js/figure/Gesture.d.ts +39 -0
- package/types/js/figure/Recorder/Recorder.d.ts +291 -0
- package/types/js/figure/Recorder/parseState.d.ts +3 -0
- package/types/js/figure/Recorder/recorder.worker.d.ts +1 -0
- package/types/js/figure/Recorder/state.d.ts +7 -0
- package/types/js/figure/SlideNavigator.d.ts +606 -0
- package/types/js/figure/TimeKeeper.d.ts +174 -0
- package/types/js/figure/geometries/arc.d.ts +18 -0
- package/types/js/figure/geometries/arrow.d.ts +215 -0
- package/types/js/figure/geometries/buffer.d.ts +4 -0
- package/types/js/figure/geometries/copy/copy.d.ts +178 -0
- package/types/js/figure/geometries/ellipse.d.ts +17 -0
- package/types/js/figure/geometries/line.d.ts +13 -0
- package/types/js/figure/geometries/lines/corners.d.ts +7 -0
- package/types/js/figure/geometries/lines/dashes.d.ts +23 -0
- package/types/js/figure/geometries/lines/lines.d.ts +31 -0
- package/types/js/figure/geometries/polygon/polygon.d.ts +12 -0
- package/types/js/figure/geometries/rectangle.d.ts +19 -0
- package/types/js/figure/geometries/triangle.d.ts +27 -0
- package/types/js/figure/webgl/Atlas.d.ts +42 -0
- package/types/js/figure/webgl/shaders.d.ts +143 -0
- package/types/js/figure/webgl/target.d.ts +9 -0
- package/types/js/figure/webgl/webgl.d.ts +54 -0
- package/types/js/tools/FunctionMap.d.ts +69 -0
- package/types/js/tools/color.d.ts +11 -0
- package/types/js/tools/colorNames.d.ts +2 -0
- package/types/js/tools/d2/polygon.d.ts +60 -0
- package/types/js/tools/d2/triangles.d.ts +0 -0
- package/types/js/tools/d3/cone.d.ts +57 -0
- package/types/js/tools/d3/cube.d.ts +26 -0
- package/types/js/tools/d3/cylinder.d.ts +45 -0
- package/types/js/tools/d3/line3.d.ts +55 -0
- package/types/js/tools/d3/prism.d.ts +49 -0
- package/types/js/tools/d3/revolve.d.ts +87 -0
- package/types/js/tools/d3/sphere.d.ts +33 -0
- package/types/js/tools/d3/surface.d.ts +47 -0
- package/types/js/tools/g2.d.ts +242 -0
- package/types/js/tools/geometry/Bounds.d.ts +446 -0
- package/types/js/tools/geometry/Line.d.ts +314 -0
- package/types/js/tools/geometry/Path.d.ts +67 -0
- package/types/js/tools/geometry/Plane.d.ts +201 -0
- package/types/js/tools/geometry/Point.d.ts +359 -0
- package/types/js/tools/geometry/Rect.d.ts +115 -0
- package/types/js/tools/geometry/Transform.d.ts +623 -0
- package/types/js/tools/geometry/angle.d.ts +105 -0
- package/types/js/tools/geometry/common.d.ts +9 -0
- package/types/js/tools/geometry/coordinates.d.ts +30 -0
- package/types/js/tools/geometry/deceleration.d.ts +13 -0
- package/types/js/tools/geometry/polygon.d.ts +4 -0
- package/types/js/tools/geometry/quaternion.d.ts +15 -0
- package/types/js/tools/geometry/scene.d.ts +282 -0
- package/types/js/tools/geometry/tools.d.ts +8 -0
- package/types/js/tools/geometry/types.d.ts +2 -0
- package/types/js/tools/getCssColors.d.ts +1 -0
- package/types/js/tools/getCssVariables.d.ts +4 -0
- package/types/js/tools/getImageData.d.ts +1 -0
- package/types/js/tools/getScssColors.d.ts +2 -0
- package/types/js/tools/htmlGenerator.d.ts +85 -0
- package/types/js/tools/m2.d.ts +24 -0
- package/types/js/tools/m3.d.ts +71 -0
- package/types/js/tools/math.d.ts +112 -0
- package/types/js/tools/morph.d.ts +651 -0
- package/types/js/tools/styleSheets.d.ts +3 -0
- package/types/js/tools/tools.d.ts +281 -0
- package/types/js/tools/types.d.ts +305 -0
- package/figureone.worker.js +0 -1
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { FunctionMap } from './FunctionMap';
|
|
2
|
+
declare const Console: (...msg: any[]) => void;
|
|
3
|
+
declare const classify: (key: string, value: string) => string;
|
|
4
|
+
declare class ObjectKeyPointer {
|
|
5
|
+
object: Record<string, any>;
|
|
6
|
+
key: string;
|
|
7
|
+
constructor(object: Record<string, any>, key: string);
|
|
8
|
+
setValue(value: any): void;
|
|
9
|
+
execute(...args: any[]): any;
|
|
10
|
+
value(): any;
|
|
11
|
+
}
|
|
12
|
+
declare function extractFrom(objectToExtractFrom: Record<string, any>, keyValues: Record<string, any> | Array<any> | string, keyPrefix?: string, keySeparator?: string): any[] | ObjectKeyPointer | undefined;
|
|
13
|
+
declare function getFromObject(objectToGetFrom: Record<string, any>, keyPath: string, levelSeparator?: string): any;
|
|
14
|
+
declare function getElement(collection: Record<string, any>, keyValues: Record<string, any> | Array<any> | string): any[] | ObjectKeyPointer | undefined;
|
|
15
|
+
declare function addToObject(obj: Record<string, any>, keyPath: string, valueToAdd: any, levelSeparator?: string): void;
|
|
16
|
+
declare function duplicate(value: number | boolean | string | Record<string, any> | null | undefined, precision?: number | null): any;
|
|
17
|
+
declare function assignObjectFromTo(fromObject: Record<string, any>, toObject: Record<string, any>, exceptIn?: Array<string> | string, duplicateValues?: boolean, parentPath?: string): void;
|
|
18
|
+
declare function joinObjectsWithOptions(options: {
|
|
19
|
+
duplicate?: boolean;
|
|
20
|
+
except?: Array<string> | string;
|
|
21
|
+
}, ...objects: Array<Record<string, any>>): Record<string, any>;
|
|
22
|
+
declare function joinObjects<T>(...objects: any[]): T;
|
|
23
|
+
declare function duplicateFromTo(fromObject: Record<string, any>, toObject: Record<string, any>, exceptKeys?: Array<string>): void;
|
|
24
|
+
declare function generateUniqueId(seed?: string): string;
|
|
25
|
+
declare function generateUniqueColor(seed?: string): number[];
|
|
26
|
+
declare function isTouchDevice(): boolean;
|
|
27
|
+
declare function loadRemote(scriptId: string, url: string, callback?: null | ((id: string, url: string) => void)): void;
|
|
28
|
+
declare function loadRemoteCSS(id: string, url: string, callback?: null | ((id: string, url: string) => void)): void;
|
|
29
|
+
declare const cleanUIDs: (objectToClean: any) => void;
|
|
30
|
+
declare function deleteKeys(obj: Record<string, any>, keys: Array<string>): void;
|
|
31
|
+
declare function copyKeysFromTo(source: Record<string, any>, destination: Record<string, any>, keys: Array<string>): void;
|
|
32
|
+
declare function generateRandomString(): string;
|
|
33
|
+
declare class UniqueMap {
|
|
34
|
+
map: Record<string, any>;
|
|
35
|
+
inverseMap: Record<string, any>;
|
|
36
|
+
index: number;
|
|
37
|
+
letters: string;
|
|
38
|
+
undefinedCode: string;
|
|
39
|
+
constructor();
|
|
40
|
+
reset(): void;
|
|
41
|
+
add(pathStr: string): any;
|
|
42
|
+
getNextUniqueString(): string;
|
|
43
|
+
makeInverseMap(): void;
|
|
44
|
+
get(uniqueStr: string): any;
|
|
45
|
+
}
|
|
46
|
+
declare function compressObject(obj: any, map: UniqueMap, keys?: boolean, strValues?: boolean, precision?: number | null, uncompress?: boolean): any;
|
|
47
|
+
declare function uncompressObject(obj: any, map: UniqueMap, keys?: boolean, strValues?: boolean): any;
|
|
48
|
+
declare function minify(objectOrArray: any, precision?: number | null): {
|
|
49
|
+
minified: any;
|
|
50
|
+
map: UniqueMap;
|
|
51
|
+
};
|
|
52
|
+
declare function unminify(minObjectOrArray: {
|
|
53
|
+
map: any;
|
|
54
|
+
minified: any;
|
|
55
|
+
}): any;
|
|
56
|
+
declare function objectToPaths(obj: any, path?: string, pathObj?: Record<string, any>, precision?: number | null): Record<string, any>;
|
|
57
|
+
declare function getObjectDiff(obj1In: Record<string, any>, diffs: Array<Record<string, any>>, obj2: Record<string, any>, precision?: number | null, debug?: boolean): Record<string, any>;
|
|
58
|
+
declare function updateObjFromPath(remainingPath: Array<string>, obj: Record<string, any>, value: any, remove?: boolean): void;
|
|
59
|
+
declare function pathsToObj(paths: Record<string, any>): Record<string, any>;
|
|
60
|
+
declare function refAndDiffToObject(referenceIn: Record<string, any>, ...diffsIn: Array<{
|
|
61
|
+
added?: Record<string, any>;
|
|
62
|
+
diff?: Record<string, any>;
|
|
63
|
+
removed?: Record<string, any>;
|
|
64
|
+
}>): any;
|
|
65
|
+
declare function diffPathsToObj(diff: {
|
|
66
|
+
added?: Record<string, any>;
|
|
67
|
+
removed?: Record<string, any>;
|
|
68
|
+
diff?: Record<string, any>;
|
|
69
|
+
}): Record<string, any>;
|
|
70
|
+
declare function diffObjToPaths(diff: {
|
|
71
|
+
added?: Record<string, any>;
|
|
72
|
+
removed?: Record<string, any>;
|
|
73
|
+
diff?: Record<string, any>;
|
|
74
|
+
}): Record<string, any>;
|
|
75
|
+
declare class ObjectTracker {
|
|
76
|
+
baseReference: Record<string, any> | null;
|
|
77
|
+
references: {
|
|
78
|
+
[refName: string]: {
|
|
79
|
+
basedOn: string;
|
|
80
|
+
diff: Record<string, any>;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
precision: number;
|
|
84
|
+
worker: Worker | any;
|
|
85
|
+
diffs: Array<[number, string, Record<string, any>, number]>;
|
|
86
|
+
lastReferenceName: string;
|
|
87
|
+
constructor(precision?: number);
|
|
88
|
+
toObj(): {
|
|
89
|
+
baseReference: any;
|
|
90
|
+
diffs: (string | number | Record<string, any>)[][];
|
|
91
|
+
references: Record<string, any>;
|
|
92
|
+
precision: number;
|
|
93
|
+
lastReferenceName: string;
|
|
94
|
+
};
|
|
95
|
+
setFromObj(obj: any): void;
|
|
96
|
+
reset(): void;
|
|
97
|
+
setBaseReference(obj: Record<string, any>): void;
|
|
98
|
+
addReference(obj: Record<string, any>, refName: string, basedOn?: string): void;
|
|
99
|
+
getReferenceChain(name: string, chain: Array<Record<string, any>>): Array<Record<string, any>>;
|
|
100
|
+
getReference(refName: string): any;
|
|
101
|
+
getDiffToReference(obj: Record<string, any>, refName: string): Record<string, any>;
|
|
102
|
+
getObjFromDiffAndReference(diff: Record<string, any>, refName: string): any;
|
|
103
|
+
add(time: number, obj: Record<string, any>, refName?: string, timeCount?: number): void;
|
|
104
|
+
addWithWorker(time: number, obj: Record<string, any>, refName?: string, timeCount?: number): void;
|
|
105
|
+
startWorker(): void;
|
|
106
|
+
getFromIndex(index: number): any;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Subscriber
|
|
110
|
+
* @property {string | function(): void} callback callback to use when
|
|
111
|
+
* subscription is published
|
|
112
|
+
* @property {number} num number of notifications
|
|
113
|
+
* @interface
|
|
114
|
+
* @group Misc Figure Element
|
|
115
|
+
*/
|
|
116
|
+
type OBJ_Subscriber = {
|
|
117
|
+
callback: string | (() => void);
|
|
118
|
+
num: number;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Subscriber Map.
|
|
122
|
+
*
|
|
123
|
+
* @property {OBJ_Subscriber} [_id] each key in this object is a unique
|
|
124
|
+
* identifier associated with a subscriber callback.
|
|
125
|
+
* @interface
|
|
126
|
+
* @group Misc Figure Element
|
|
127
|
+
*/
|
|
128
|
+
type OBJ_Subscribers = {
|
|
129
|
+
[id: string]: OBJ_Subscriber;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* A single subscription
|
|
133
|
+
*
|
|
134
|
+
* @property {OBJ_Subscribers} subscribers
|
|
135
|
+
* @property {FunctionMap} fnMap
|
|
136
|
+
* @group Misc Figure Element
|
|
137
|
+
*/
|
|
138
|
+
declare class Notification {
|
|
139
|
+
fnMap: FunctionMap;
|
|
140
|
+
subscribers: OBJ_Subscribers;
|
|
141
|
+
order: Array<string>;
|
|
142
|
+
nextId: number;
|
|
143
|
+
/**
|
|
144
|
+
* @property {FunctionMap} fnMap Only needed for {@link Recorder}.
|
|
145
|
+
*/
|
|
146
|
+
constructor(fnMap?: FunctionMap);
|
|
147
|
+
cleanup(): void;
|
|
148
|
+
/**
|
|
149
|
+
* Add a subscriber to an event.
|
|
150
|
+
* @param {string} subscriptionName event name
|
|
151
|
+
* @param {string | function(): void} callback to be called when events
|
|
152
|
+
* are published. If `string`, then {@link FunctionMap} of the {@link Figure}
|
|
153
|
+
* or {@link FigureElement} to which the notification manager is a property
|
|
154
|
+
* of will be used.
|
|
155
|
+
* @param {number} numberOfSubscriptions how many publications the
|
|
156
|
+
* subscription will receive. `-1` is no limit (`-1`).
|
|
157
|
+
* @return {number} subscirber id
|
|
158
|
+
*/
|
|
159
|
+
add(callback: string | (() => void), numberOfPublications?: number): number;
|
|
160
|
+
/**
|
|
161
|
+
* Publish to all subscribers
|
|
162
|
+
*
|
|
163
|
+
* @param {any} functionArgument argument to pass to subscriber callback
|
|
164
|
+
*/
|
|
165
|
+
publish(functionArgument?: any, asArray?: boolean): void;
|
|
166
|
+
/**
|
|
167
|
+
* Remove subscriber - the subscirber id is returned by this object's `add`
|
|
168
|
+
* method
|
|
169
|
+
*/
|
|
170
|
+
remove(subscirberId: string | number): void;
|
|
171
|
+
_excludeStateKeys(): string[];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Subscription Map.
|
|
175
|
+
*
|
|
176
|
+
* @property {Notification} [_eventName] each key in this object is a
|
|
177
|
+
* unique notification name associated with an event.
|
|
178
|
+
* @interface
|
|
179
|
+
* @group Misc Figure Element
|
|
180
|
+
*/
|
|
181
|
+
type OBJ_Notifications = {
|
|
182
|
+
[notificationName: string]: Notification;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Notification manager.
|
|
186
|
+
*
|
|
187
|
+
* Publishes notifications of events to subscribers.
|
|
188
|
+
*
|
|
189
|
+
* {@link Figure}, {@link FigureElement}, {@link Recorder}, and
|
|
190
|
+
* {@link SlideNavigator} all use notification managers for event nofitications.
|
|
191
|
+
*
|
|
192
|
+
* Notification managers can also be added to custom objects, but will only
|
|
193
|
+
* publish to subscribers when it is told to publish.
|
|
194
|
+
*
|
|
195
|
+
* @property {OBJ_Notifications} notifications
|
|
196
|
+
* @property {FunctionMap} fnMap
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* // Subscribe to the `setTransform` notification of `ball1` to move `ball2`
|
|
200
|
+
*
|
|
201
|
+
* // Add ball1 and ball2 to the figure
|
|
202
|
+
* const [ball1, ball2] = figure.add([
|
|
203
|
+
* {
|
|
204
|
+
* name: 'ball1',
|
|
205
|
+
* make: 'primitives.polygon',
|
|
206
|
+
* sides: 100, radius: 0.5, color: [1, 0, 0, 1],
|
|
207
|
+
* },
|
|
208
|
+
* {
|
|
209
|
+
* name: 'ball2',
|
|
210
|
+
* make: 'primitives.polygon',
|
|
211
|
+
* sides: 100, radius: 0.3, color: [0, 0, 1, 1],
|
|
212
|
+
* },
|
|
213
|
+
* ]);
|
|
214
|
+
*
|
|
215
|
+
* // Subscribe to ball1's `setTransform` event notification, and use the set
|
|
216
|
+
* transform to move ball2 with ball1
|
|
217
|
+
* ball1.notifications.add('setTransform', (transform) => {
|
|
218
|
+
* ball2.setTransform(transform[0]);
|
|
219
|
+
* });
|
|
220
|
+
*
|
|
221
|
+
* // Animate ball1 to show ball2 moves with it
|
|
222
|
+
* ball1.animations.new()
|
|
223
|
+
* .position({ target: [1, 0], duration: 2 })
|
|
224
|
+
* .start();
|
|
225
|
+
* @group Misc Figure Element
|
|
226
|
+
*/
|
|
227
|
+
declare class NotificationManager {
|
|
228
|
+
fnMap: FunctionMap;
|
|
229
|
+
notifications: OBJ_Notifications;
|
|
230
|
+
/**
|
|
231
|
+
* @param {FunctionMap} fnMap default function map to use. Function maps
|
|
232
|
+
* need only be used with {@link Recorder}.
|
|
233
|
+
*/
|
|
234
|
+
constructor(fnMap?: FunctionMap);
|
|
235
|
+
cleanup(): void;
|
|
236
|
+
/**
|
|
237
|
+
* Subscribe to a notification.
|
|
238
|
+
* @param {string} name event notification name
|
|
239
|
+
* @param {string | function(): void} callback to be called when events
|
|
240
|
+
* occur. If `string`, then {@link FunctionMap} of the {@link Figure}
|
|
241
|
+
* or {@link FigureElement} to which the notification manager is a property
|
|
242
|
+
* of will be used.
|
|
243
|
+
* @param {number} num how many notifications the subscriber will receive.
|
|
244
|
+
* `num = 1` will mean only the first notification will be sent to the
|
|
245
|
+
* subscriber .`num = -1` means all notifications of the event will be sent
|
|
246
|
+
* to the subscriber (`-1`).
|
|
247
|
+
* @return {number} subscriber id
|
|
248
|
+
*/
|
|
249
|
+
add(name: string, callback: string | (() => void), num?: number): number;
|
|
250
|
+
/**
|
|
251
|
+
* Publish to all subscribers
|
|
252
|
+
*
|
|
253
|
+
* @param {string} subscriptionName
|
|
254
|
+
* @param {any} payload payload to pass to subscribers
|
|
255
|
+
* @param {boolean} asArray set to `true` if payload is an array that should
|
|
256
|
+
* be published as an array. Set to `false` if payload should be published as
|
|
257
|
+
* separated arguments.
|
|
258
|
+
*/
|
|
259
|
+
publish(eventName: string, payload?: any, asArray?: boolean): void;
|
|
260
|
+
/**
|
|
261
|
+
* Remove subscriber from subscription
|
|
262
|
+
* @param {string} subsciptionName
|
|
263
|
+
* @param {string | number} subscriberId
|
|
264
|
+
*/
|
|
265
|
+
remove(eventName: string, subscriberId: string | number): void;
|
|
266
|
+
_excludeStateKeys(): string[];
|
|
267
|
+
}
|
|
268
|
+
declare function download(filename: string, text: string): void;
|
|
269
|
+
declare function splitString(str: string, token?: string, escape?: string): [string[], number];
|
|
270
|
+
declare class PerformanceTimer {
|
|
271
|
+
stamps: Array<[number, string]>;
|
|
272
|
+
index: number;
|
|
273
|
+
constructor();
|
|
274
|
+
reset(): void;
|
|
275
|
+
stamp(label?: string): void;
|
|
276
|
+
deltas(): any[];
|
|
277
|
+
log(): void;
|
|
278
|
+
}
|
|
279
|
+
declare function hash32(s: string): number;
|
|
280
|
+
declare function findReferences(toFind: any, start: any, path?: string, alreadyParsed?: Array<any>, depth?: number): any;
|
|
281
|
+
export { diffPathsToObj, diffObjToPaths, Console, classify, extractFrom, ObjectKeyPointer, getElement, addToObject, duplicateFromTo, isTouchDevice, generateUniqueId, joinObjects, cleanUIDs, loadRemote, loadRemoteCSS, deleteKeys, copyKeysFromTo, generateRandomString, duplicate, assignObjectFromTo, joinObjectsWithOptions, objectToPaths, getObjectDiff, updateObjFromPath, pathsToObj, UniqueMap, compressObject, refAndDiffToObject, uncompressObject, unminify, minify, ObjectTracker, download, Notification, NotificationManager, getFromObject, splitString, PerformanceTimer, generateUniqueColor, hash32, findReferences, };
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atlas map type - defined locally to avoid dependency on unmigrated figure layer.
|
|
3
|
+
* Mirrors OBJ_AtlasMap from '../figure/webgl/Atlas'.
|
|
4
|
+
*/
|
|
5
|
+
type OBJ_AtlasMap = {
|
|
6
|
+
[char: string]: {
|
|
7
|
+
width: number;
|
|
8
|
+
ascent: number;
|
|
9
|
+
descent: number;
|
|
10
|
+
offsetX: number;
|
|
11
|
+
offsetY: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Defines whether a line is solid or dashed.
|
|
16
|
+
*
|
|
17
|
+
* `Array<number>`
|
|
18
|
+
*
|
|
19
|
+
* Leave empty for solid line.
|
|
20
|
+
*
|
|
21
|
+
* Use array of numbers for a dashed line where indexes 0, 2, 4... are line
|
|
22
|
+
* lengths and indexes 1, 3, 5... are gap lengths. If line is longer than
|
|
23
|
+
* cumulative length of line and gap lengths, then pattern will repeat.
|
|
24
|
+
*
|
|
25
|
+
* If array length is odd, then the first element will be the offset of the
|
|
26
|
+
* dash pattern - the length where the dash pattern starts. In this case index
|
|
27
|
+
* 0 is the offset, indexes 1, 3, 5... are the dash lengths and indexes 2, 4,
|
|
28
|
+
* 6... are the gap lengths.
|
|
29
|
+
*
|
|
30
|
+
* For example [0.1, 0.01, 0.02, 0.01] produces 0.1 length dash, then a 0.01
|
|
31
|
+
* length gap, then a 0.02 length dash, then a 0.01 length gap. This pattern
|
|
32
|
+
* will repeat for the length of the line.
|
|
33
|
+
* @group Misc Shapes
|
|
34
|
+
*/
|
|
35
|
+
export type TypeDash = Array<number>;
|
|
36
|
+
/**
|
|
37
|
+
* Defines a color
|
|
38
|
+
*
|
|
39
|
+
* `[number, number, number, number]`
|
|
40
|
+
*
|
|
41
|
+
* Color is defined as an RGBA array with values between 0 and 1. The alpha
|
|
42
|
+
* channel defines the transparency or opacity of the color where
|
|
43
|
+
* 1 is fully opaque and 0 is fully transparent.
|
|
44
|
+
* @group Misc Shapes
|
|
45
|
+
*/
|
|
46
|
+
export type TypeColor = Array<number>;
|
|
47
|
+
/**
|
|
48
|
+
* `'pixel' | 'gl' | 'figure' | 'local' | 'draw'`
|
|
49
|
+
* @group Misc Figure Element
|
|
50
|
+
*/
|
|
51
|
+
export type TypeCoordinateSpace = 'pixel' | 'gl' | 'figure' | 'local' | 'draw';
|
|
52
|
+
/**
|
|
53
|
+
Curved Corner Definition
|
|
54
|
+
* @interface
|
|
55
|
+
* @group Misc Shapes
|
|
56
|
+
*/
|
|
57
|
+
export type OBJ_CurvedCorner = {
|
|
58
|
+
radius?: number;
|
|
59
|
+
sides?: number;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Outline options.
|
|
63
|
+
*
|
|
64
|
+
* By default the glyphs will not be filled, with the outline the same color
|
|
65
|
+
* as the font.
|
|
66
|
+
*
|
|
67
|
+
* Glyphs can be filled with the `fill` property, but both fill and outline
|
|
68
|
+
* will be the same color unless the `color` property is used to override the
|
|
69
|
+
* outline's color.
|
|
70
|
+
*
|
|
71
|
+
* @property {number} [width] line width
|
|
72
|
+
* @property {boolean} [fill] include fill (`false`)
|
|
73
|
+
* @property {TypeColor} [color] outline color that overrides the font color -
|
|
74
|
+
* use if including a fill
|
|
75
|
+
* @interface
|
|
76
|
+
* @group Misc Text
|
|
77
|
+
*/
|
|
78
|
+
export type OBJ_Outline = {
|
|
79
|
+
width?: number;
|
|
80
|
+
fill?: boolean;
|
|
81
|
+
color?: TypeColor;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Underline options.
|
|
85
|
+
*
|
|
86
|
+
* An underline is defined as a horizontal line with some `width` with a bottom
|
|
87
|
+
* edge `descent` below the text baseline.
|
|
88
|
+
*
|
|
89
|
+
* If `descent` is negative, the line can be moved into a strike through
|
|
90
|
+
* position, or placed above the text.
|
|
91
|
+
*
|
|
92
|
+
* @property {number} [width]
|
|
93
|
+
* @property {number} [descent]
|
|
94
|
+
* @property {TypeColor} [color]
|
|
95
|
+
* @interface
|
|
96
|
+
* @group Misc Text
|
|
97
|
+
*/
|
|
98
|
+
export type OBJ_Underline = {
|
|
99
|
+
width?: number;
|
|
100
|
+
descent?: number;
|
|
101
|
+
color?: TypeColor;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Texture atlas font individual glyph ascent, descent and width modifiers.
|
|
105
|
+
*
|
|
106
|
+
* @property {w} [number] width
|
|
107
|
+
* @property {d} [number] descent
|
|
108
|
+
* @property {a} [number] ascent
|
|
109
|
+
* @interface
|
|
110
|
+
* @group Misc Text
|
|
111
|
+
*/
|
|
112
|
+
export type OBJ_GlyphModifiers = {
|
|
113
|
+
w?: number;
|
|
114
|
+
d?: number;
|
|
115
|
+
a?: number;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Font weight definition.
|
|
119
|
+
* `'normal' | 'bold' | 'lighter' | 'bolder' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'`
|
|
120
|
+
* @group Misc Text
|
|
121
|
+
*/
|
|
122
|
+
export type TypeFontWeight = 'normal' | 'bold' | 'lighter' | 'bolder' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
|
|
123
|
+
/**
|
|
124
|
+
* Font definition object.
|
|
125
|
+
*
|
|
126
|
+
* A font can be defined either from a subset of the properties used to define
|
|
127
|
+
* [fonts in css](https://developer.mozilla.org/en-US/docs/Web/CSS/font), or
|
|
128
|
+
* by using a texture altas of the various glyphs to be used.
|
|
129
|
+
*
|
|
130
|
+
* A font can be rendered into a [2D canvas](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D)
|
|
131
|
+
* or into the WebGL canvas using the texture atlas.
|
|
132
|
+
*
|
|
133
|
+
* A texture atlas can either be supplied as an image, or generated
|
|
134
|
+
* automatically by FigureOne based on css font definitions.
|
|
135
|
+
*
|
|
136
|
+
* Choosing how to render text depends on the application.
|
|
137
|
+
*
|
|
138
|
+
* If text size is to be animated through a large scale range, then rendering
|
|
139
|
+
* on the 2D canvas is advantageous as it can scale text to any size without a
|
|
140
|
+
* loss of sharpness. The main disadvantage of the 2D canvas is the fact that
|
|
141
|
+
* it's a different HTML canvas element to the WebGL canvas. Thus all text on
|
|
142
|
+
* the 2D canvas will always be above (default) or below the WebGl canvas
|
|
143
|
+
* independent of when it is drawn. This means text will always be above or
|
|
144
|
+
* below shapes. regenerated each time the size changes by some threshold.
|
|
145
|
+
*
|
|
146
|
+
* Conversely, drawing text on the WebGL canvas provides control on which
|
|
147
|
+
* shapes can hide text and vise versa. The disadvantage is that text is drawn
|
|
148
|
+
* from a texture atlas of bitmapped fonts. This means as text is progressively
|
|
149
|
+
* scaled up or down, the the text will look more pixelated or blurry. For many
|
|
150
|
+
* scalings (like common scalings in an equation), this will likely not be a
|
|
151
|
+
* problem. But for large changes in animated scale, it will be better to use
|
|
152
|
+
* the 2D canvas. Scaling also needs to be considered if the WebGL canvas is
|
|
153
|
+
* expected to be resized. On a desktop browser, a canvas element can be
|
|
154
|
+
* resized a lot, and so if using the WebGL atlas, it may need to be
|
|
155
|
+
*
|
|
156
|
+
* Note, the choice of where to render text can be made for each text element.
|
|
157
|
+
* Therefore it is possible to have some text rendered to the 2D canvas, and
|
|
158
|
+
* other text rendered to the WebGL canvas in the same figure.
|
|
159
|
+
*
|
|
160
|
+
* A texture atlas can either be supplied as an image, or generated
|
|
161
|
+
* automatically by FigureOne based on the css font definitions.
|
|
162
|
+
*
|
|
163
|
+
* CSS font definition:
|
|
164
|
+
* * `family` - the typeface family from which it comes (e.g. 'Helvetica',
|
|
165
|
+
* 'Times New Roman')
|
|
166
|
+
* * `style` - its slope (e.g. 'italic')
|
|
167
|
+
* * `weight` - its thickness (e.g. 'bold')
|
|
168
|
+
* * `size`
|
|
169
|
+
*
|
|
170
|
+
* Atlas font definition:
|
|
171
|
+
* * `src` - the image or url to the image - if not supplied then atlas will
|
|
172
|
+
* be generated automatically
|
|
173
|
+
* * `map` - description of location and size of each glyph in the atlas
|
|
174
|
+
* * `glyphs` - the available glyphs in the atlas. To reduce the size of the
|
|
175
|
+
* atlas, include only the glyphs that are being used, or use a preset
|
|
176
|
+
* alphabet (like 'latin', or 'math')
|
|
177
|
+
* * `atlasColor` - if `true` then the rendered glyph color will be the same
|
|
178
|
+
* as that in the texture. If `false`, then only the transparency channel of
|
|
179
|
+
* the texture will be used and color will be defined by the FigureElement
|
|
180
|
+
* drawing the text.
|
|
181
|
+
* * `atlasSize` - if defined, and if the glyphs are generated automatically
|
|
182
|
+
* then the glyphs will be created with a pixel size that is `atlasSize`
|
|
183
|
+
* portion of the canvas height. If undefined, then the glyphs will be
|
|
184
|
+
* created with a pixel size that is the ratio of the font size to the
|
|
185
|
+
* scene height portion of the canvas height.
|
|
186
|
+
*
|
|
187
|
+
* A font can also have a number of modifying properties:
|
|
188
|
+
* * `color` - fill or outline color of each glyph - not used if the texture
|
|
189
|
+
* atlas color is to be used
|
|
190
|
+
* * `underline`
|
|
191
|
+
* * `outline` - defines whether the font is filled, is an outline, or both
|
|
192
|
+
*
|
|
193
|
+
* Fonts that are generated automatically rely on the client's browser to
|
|
194
|
+
* measure the font's width. From this the ascent and descent of each glyph
|
|
195
|
+
* is then estimated. Each glyph's width, ascent and descent is used to layout
|
|
196
|
+
* the glyphs in regular text and equations, as well as determine the borders
|
|
197
|
+
* and touch borders of FigureElements that draw the text.
|
|
198
|
+
*
|
|
199
|
+
* However, this estimate for different font families is not always perfectly
|
|
200
|
+
* accurate. If the estimate is not sufficient, then it can be modified by using
|
|
201
|
+
* the following properties (where each property is a proportion of the width
|
|
202
|
+
* of a character 'a'):
|
|
203
|
+
* * `maxAscent`: Maximum ascent of glyphs like "A" or "$"
|
|
204
|
+
* * `midAscent`: ascent of mid level glyphs like "a" and "g"
|
|
205
|
+
* * `descent`: descent of glyphs that do not noticeably go below the
|
|
206
|
+
* baseline (but often do a little) like "a" and "b"
|
|
207
|
+
* * `midDescent`: descent of glyphs that go a little below the baseline like
|
|
208
|
+
* "," and ";"
|
|
209
|
+
* * `maxDescent`: maximum descent of glyphs like "g" and "|"
|
|
210
|
+
*
|
|
211
|
+
* Individual glyphs can also be modified (for atlas based fonts only) using
|
|
212
|
+
* the `modifiers` property.
|
|
213
|
+
*
|
|
214
|
+
*
|
|
215
|
+
* @property {string} [family] The font family (`'Times New Roman'`)
|
|
216
|
+
* @property {'normal' | 'italic' | 'oblique'} [style] (`'normal'`)
|
|
217
|
+
* @property {TypeFontWeight} [weight]
|
|
218
|
+
* font weight (`'normal'`)
|
|
219
|
+
* @property {number} [size] size of font in draw space (`0.2`)
|
|
220
|
+
* @property {boolean | OBJ_Underline} [underline] `true` to include
|
|
221
|
+
* an underline or use object to define its properties (`false`)
|
|
222
|
+
* @property {[number, number, number, number]} [color] Font color
|
|
223
|
+
* [red, green, blue, alpha] between 0 and 1 - (`[1, 0, 0, 1]`)
|
|
224
|
+
* @property {OBJ_Outline} [outline] options to draw the text in outline
|
|
225
|
+
* instead of or in addition to a fill (`false`)
|
|
226
|
+
* @property {number} [descent] (`0.8`)
|
|
227
|
+
* @property {number} [maxDescent] (`0.2`)
|
|
228
|
+
* @property {number} [midDescent] (`0.5`)
|
|
229
|
+
* @property {number} [maxAscent] (`0.95`)
|
|
230
|
+
* @property {number} [midAscent] (`1.4`)
|
|
231
|
+
* @property {OBJ_GlyphModifiers} [modifiers] individual glyph adjustments for
|
|
232
|
+
* texture atlas fonts
|
|
233
|
+
* @property {Image | string} [src] source image or url for atlas
|
|
234
|
+
* @property {OBJ_AtlasMap} [map] atlas definition needed if using a source
|
|
235
|
+
* image or url
|
|
236
|
+
* @property {string | 'greek' | 'math' | 'latin' | 'all' | 'common' | 'mathExt' | Array<string>} [glyphs]
|
|
237
|
+
* glyphs included in the font - an array can be used combining glyphs together
|
|
238
|
+
* @property {null |number} [atlasSize] font size of atlas as a proportion of
|
|
239
|
+
* the WebGL canvas height. If this is null, then the atlas font size is
|
|
240
|
+
* calculated from the font size, scene height and number of pixels in the
|
|
241
|
+
* canvas height. (`null`)
|
|
242
|
+
* @property {TypeColor} [loadColor] color of temporary texture while actual
|
|
243
|
+
* texture is loading
|
|
244
|
+
* @property {boolean} [atlasColor] `true` to use the color of the glyphs in
|
|
245
|
+
* the atlas. `false` will just use the opacity and color the glyphs from the
|
|
246
|
+
* FigureElement drawing them
|
|
247
|
+
* @property {'gl' | '2d' | 'html'} [render] render the associated text to
|
|
248
|
+
* either the WebGL canvas, the 2D canvas, or the HTML canvas.
|
|
249
|
+
|
|
250
|
+
* @interface
|
|
251
|
+
* @group Text
|
|
252
|
+
* @example
|
|
253
|
+
* // Full font definition
|
|
254
|
+
* const font = new FigureFont({
|
|
255
|
+
* family: 'Helvetica',
|
|
256
|
+
* style: 'italic',
|
|
257
|
+
* weight: 'bold',
|
|
258
|
+
* color: [1, 1, 0, 1],
|
|
259
|
+
* opacity: 1,
|
|
260
|
+
* });
|
|
261
|
+
* @example
|
|
262
|
+
* // Define style only, remaining properties are defaults
|
|
263
|
+
* const font = new FigureFont({
|
|
264
|
+
* style: 'italic',
|
|
265
|
+
* });
|
|
266
|
+
*/
|
|
267
|
+
export type OBJ_Font = {
|
|
268
|
+
family?: string;
|
|
269
|
+
weight?: TypeFontWeight;
|
|
270
|
+
style?: 'normal' | 'italic' | 'oblique';
|
|
271
|
+
size?: number;
|
|
272
|
+
underline?: boolean | OBJ_Underline;
|
|
273
|
+
color?: TypeColor | null;
|
|
274
|
+
outline?: boolean | OBJ_Outline;
|
|
275
|
+
descent?: number;
|
|
276
|
+
maxDescent?: number;
|
|
277
|
+
midDescent?: number;
|
|
278
|
+
maxAscent?: number;
|
|
279
|
+
midAscent?: number;
|
|
280
|
+
modifiers?: OBJ_GlyphModifiers;
|
|
281
|
+
src?: HTMLImageElement | string;
|
|
282
|
+
map?: OBJ_AtlasMap;
|
|
283
|
+
glyphs?: string | 'greek' | 'math' | 'latin' | 'all' | 'common' | 'mathExt';
|
|
284
|
+
loadColor?: TypeColor;
|
|
285
|
+
atlasColor?: boolean;
|
|
286
|
+
atlasSize?: number | null;
|
|
287
|
+
timeout?: number;
|
|
288
|
+
render?: 'gl' | '2d' | 'html';
|
|
289
|
+
};
|
|
290
|
+
export type OBJ_Font_Fixed = {
|
|
291
|
+
family: string;
|
|
292
|
+
style: 'normal' | 'italic';
|
|
293
|
+
size: number;
|
|
294
|
+
weight: 'normal' | 'bold' | 'lighter' | 'bolder' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
|
|
295
|
+
color: TypeColor | null;
|
|
296
|
+
underline: boolean | number | [number, number];
|
|
297
|
+
width: number;
|
|
298
|
+
descent: number;
|
|
299
|
+
maxDescent: number;
|
|
300
|
+
midDescent: number;
|
|
301
|
+
maxAscent: number;
|
|
302
|
+
midAscent: number;
|
|
303
|
+
};
|
|
304
|
+
declare const doNothing = 1;
|
|
305
|
+
export default doNothing;
|
package/figureone.worker.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(()=>{"use strict";var e=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5,r=Math.pow(10,n),t=Math.round(e*r)/r,i=function(e,n){return e===n?0!==e||1/e==1/n:e!=e&&n!=n};return i(t,-0)&&(t=0),t};function n(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==r)return;var t,i,a=[],f=!0,o=!1;try{for(r=r.call(e);!(f=(t=r.next()).done)&&(a.push(t.value),!n||a.length!==n);f=!0);}catch(e){o=!0,i=e}finally{try{f||null==r.return||r.return()}finally{if(o)throw i}}return a}(e,n)||t(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e){return function(e){if(Array.isArray(e))return i(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||t(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,n){if(e){if("string"==typeof e)return i(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,n):void 0}}function i(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}function f(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function o(e,n){for(var r=0;r<n.length;r++){var t=n[r];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}function c(e,n,r){return n&&o(e.prototype,n),r&&o(e,r),e}function s(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if("number"==typeof n&&null!=r)return e(n,r);if("number"==typeof n||"boolean"==typeof n||"string"==typeof n||null==n||NaN===n||"function"==typeof n)return n;if("function"==typeof n._dup)return n._dup();if(Array.isArray(n)){var t=[];return n.forEach((function(e){return t.push(s(e,r))})),t}var i={};return Object.keys(n).forEach((function(e){var t=s(n[e],r);i[e]=t})),i}function l(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;return"string"==typeof n||"boolean"==typeof n||"function"==typeof n?(t["".concat(r)]=n,t):"number"==typeof n?(t["".concat(r)]=null!=i?e(n,i):n,t):null===n?(t["".concat(r)]=null,t):void 0===n?t:Array.isArray(n)?(n.forEach((function(e,n){l(e,"".concat(r,"[").concat(n,"]"),t,i)})),t):(Object.keys(n).forEach((function(e){l(n[e],"".concat(r,".").concat(e),t,i)})),t)}function u(e,n,r){var t=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=e[0];if(0!==i.length){var f=i.match(/\[[^\]]*\]/g),o=i.replace(/\[.*/,"");if(1!==e.length||!t||f){if(f){var c=f.map((function(e){return parseInt(e.replace(/\[|\]/g,""),10)}));null!=n[o]&&Array.isArray(n[o])||(n[o]=[]);for(var s=n[o],l=0,d=0;d<c.length;d+=1){if(l=c[d],s.length<=l)for(var h=s.length;h<l-s.length+1;h+=1)s.push(void 0);d<c.length-1&&(Array.isArray(s[l])||(s[l]=[]),s=s[l])}return 1===e.length&&t?void(s[l]=void 0):1===e.length?void(s[l]=r):(null!=s[l]&&"object"===a(s[l])||(s[l]={}),void u(e.slice(1),s[l],r,t))}1!==e.length?(null==n[o]&&(n[o]={}),u(e.slice(1),n[o],r,t)):n[o]=r}else delete n[o]}}function d(e){var n={};return Object.keys(e).forEach((function(r){var t=r.split(".").filter((function(e){return e.length>0})),i=e[r];Array.isArray(i)?u(t,n,i.slice(-1)[0]):u(t,n,i)})),n}function h(e){for(var n=s(e),r=function(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];Object.keys(e).forEach((function(t){var i=t.split(".").filter((function(e){return e.length>0})),a=e[t];Array.isArray(a)?u(i,n,a.slice(-1)[0],r):u(i,n,a,r)}))},t=arguments.length,i=new Array(t>1?t-1:0),a=1;a<t;a++)i[a-1]=arguments[a];return i.forEach((function(e){var n=e.added,t=e.removed,i=e.diff;null!=t&&r(t,!0),null!=n&&r(n),null!=i&&r(i)})),n}function v(e){var n={};return e.diff&&Object.keys(e.diff).length>0&&(n.diff=d(e.diff)),e.added&&Object.keys(e.added).length>0&&(n.added=d(e.added)),e.removed&&Object.keys(e.removed).length>0&&(n.removed=d(e.removed)),n}function y(e){var n={};return e.diff&&Object.keys(e.diff).length>0&&(n.diff=l(e.diff)),e.added&&Object.keys(e.added).length>0&&(n.added=l(e.added)),e.removed&&Object.keys(e.removed).length>0&&(n.removed=l(e.removed)),n}var b=function(){function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8;f(this,e),this.precision=n,this.reset()}return c(e,[{key:"toObj",value:function(){var e=this,n={};Object.keys(this.references).forEach((function(r){n[r]={basedOn:e.references[r].basedOn,diff:v(e.references[r].diff)}}));var r=this.diffs.map((function(e){return[e[0],e[1],v(e[2]),e[3]]}));return{baseReference:s(this.baseReference),diffs:r,references:n,precision:this.precision,lastReferenceName:this.lastReferenceName}}},{key:"setFromObj",value:function(e){var n={};Object.keys(e.references).forEach((function(r){n[r]={basedOn:e.references[r].basedOn,diff:y(e.references[r].diff)}})),this.references=n,this.baseReference=s(e.baseReference),this.precision=e.precision,this.diffs=e.diffs.map((function(e){return[e[0],e[1],y(e[2]),e[3]]})),this.lastReferenceName=e.lastReferenceName}},{key:"reset",value:function(){this.baseReference=null,this.references={},this.diffs=[],this.lastReferenceName="__base"}},{key:"setBaseReference",value:function(e){this.baseReference=s(e),this.lastReferenceName="__base"}},{key:"addReference",value:function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"__base";null!=this.baseReference&&"__base"!==n||this.setBaseReference(e),"__base"!==n&&(this.references[n]={diff:this.getDiffToReference(e,r),basedOn:r},this.lastReferenceName=n)}},{key:"getReferenceChain",value:function(e,n){return"__base"===e||null==this.references[e]?n:this.getReferenceChain(this.references[e].basedOn,[this.references[e].diff].concat(r(n)))}},{key:"getReference",value:function(e){var n=this.getReferenceChain(e,[]);return h.apply(void 0,[this.baseReference].concat(r(n)))}},{key:"getDiffToReference",value:function(e,n){var t=this.getReferenceChain(n,[]),i=function(e,n,t){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,a=arguments.length>4&&void 0!==arguments[4]&&arguments[4],f=e;n.length>0&&(f=h.apply(void 0,[e].concat(r(n))));var o=l(f,"",{},i),c=l(t,"",{},i),s={},u={},d={};Object.keys(o).forEach((function(e){void 0!==c[e]?o[e]!==c[e]&&(u[e]=a?[o[e],c[e]]:c[e]):d[e]=o[e]})),Object.keys(c).forEach((function(e){void 0===o[e]&&(s[e]=c[e])}));var v={};return Object.keys(u).length>0&&(v.diff=u),Object.keys(s).length>0&&(v.added=s),Object.keys(d).length>0&&(v.removed=d),v}(this.baseReference,t,e,this.precision);return i}},{key:"getObjFromDiffAndReference",value:function(e,n){var t=this.getReferenceChain(n,[]),i=[].concat(r(t),[e]);return h.apply(void 0,[this.baseReference].concat(r(i)))}},{key:"add",value:function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.lastReferenceName,t=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;null==this.baseReference&&this.setBaseReference(n);var i=this.getDiffToReference(n,r);this.diffs.push([e,r,i,t])}},{key:"addWithWorker",value:function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.lastReferenceName,t=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;null==this.baseReference&&this.setBaseReference(n),this.startWorker(),null!=this.worker&&this.worker.postMessage([e,r,n,t])}},{key:"startWorker",value:function(){null==this.worker&&(this.worker=new Worker)}},{key:"getFromIndex",value:function(e){if(e>this.diffs.length||0===this.diffs.length)return null;var r=n(this.diffs[e],3),t=r[1],i=r[2];return this.getObjFromDiffAndReference(i,t)}}]),e}();var g=new b;addEventListener("message",(function(e){var n=e.data,r=n.message,t=n.payload;"reset"===r?((g=new b).baseReference=t.baseReference,g.references=t.references):"get"===r?postMessage({message:"cache",payload:{baseReferece:g.baseReference,references:g.references,diffs:g.diffs}}):"add"===r?g.add(t.now,t.state,t.reference,t.lastRecordTimeCount):"addReference"===r&&g.addReference(t.state,t.refName,t.basedOn)}))})();
|