Upload folder using huggingface_hub (part 22)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/mapbox-gl/src/util/performance.js +112 -0
- node_modules/mapbox-gl/src/util/primitives.js +145 -0
- node_modules/mapbox-gl/src/util/resolve_tokens.js +16 -0
- node_modules/mapbox-gl/src/util/script_detection.js +328 -0
- node_modules/mapbox-gl/src/util/sku_token.js +42 -0
- node_modules/mapbox-gl/src/util/smart_wrap.js +55 -0
- node_modules/mapbox-gl/src/util/struct_array.js +243 -0
- node_modules/mapbox-gl/src/util/struct_array.js.ejs +112 -0
- node_modules/mapbox-gl/src/util/struct_array_layout.js.ejs +98 -0
- node_modules/mapbox-gl/src/util/task_queue.js +68 -0
- node_modules/mapbox-gl/src/util/throttle.js +27 -0
- node_modules/mapbox-gl/src/util/throttled_invoker.js +46 -0
- node_modules/mapbox-gl/src/util/tile_request_cache.js +172 -0
- node_modules/mapbox-gl/src/util/util.js +524 -0
- node_modules/mapbox-gl/src/util/vectortile_to_geojson.js +50 -0
- node_modules/mapbox-gl/src/util/verticalize_punctuation.js +114 -0
- node_modules/mapbox-gl/src/util/web_worker.js +91 -0
- node_modules/mapbox-gl/src/util/web_worker_transfer.js +266 -0
- node_modules/mapbox-gl/src/util/webp_supported.js +69 -0
- node_modules/mapbox-gl/src/util/window.js +102 -0
- node_modules/mapbox-gl/src/util/worker_pool.js +57 -0
- node_modules/math-intrinsics/.eslintrc +16 -0
- node_modules/math-intrinsics/.github/FUNDING.yml +12 -0
- node_modules/math-intrinsics/CHANGELOG.md +24 -0
- node_modules/math-intrinsics/LICENSE +21 -0
- node_modules/math-intrinsics/README.md +50 -0
- node_modules/math-intrinsics/abs.d.ts +1 -0
- node_modules/math-intrinsics/abs.js +4 -0
- node_modules/math-intrinsics/constants/maxArrayLength.d.ts +3 -0
- node_modules/math-intrinsics/constants/maxArrayLength.js +4 -0
- node_modules/math-intrinsics/constants/maxSafeInteger.d.ts +3 -0
- node_modules/math-intrinsics/constants/maxSafeInteger.js +5 -0
- node_modules/math-intrinsics/constants/maxValue.d.ts +3 -0
- node_modules/math-intrinsics/constants/maxValue.js +5 -0
- node_modules/math-intrinsics/floor.d.ts +1 -0
- node_modules/math-intrinsics/floor.js +4 -0
- node_modules/math-intrinsics/isFinite.d.ts +3 -0
- node_modules/math-intrinsics/isFinite.js +12 -0
- node_modules/math-intrinsics/isInteger.d.ts +3 -0
- node_modules/math-intrinsics/isInteger.js +16 -0
- node_modules/math-intrinsics/isNaN.d.ts +1 -0
- node_modules/math-intrinsics/isNaN.js +6 -0
- node_modules/math-intrinsics/isNegativeZero.d.ts +3 -0
- node_modules/math-intrinsics/isNegativeZero.js +6 -0
- node_modules/math-intrinsics/max.d.ts +1 -0
- node_modules/math-intrinsics/max.js +4 -0
- node_modules/math-intrinsics/min.d.ts +1 -0
- node_modules/math-intrinsics/min.js +4 -0
- node_modules/math-intrinsics/mod.d.ts +3 -0
- node_modules/math-intrinsics/mod.js +9 -0
node_modules/mapbox-gl/src/util/performance.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
import window from '../util/window';
|
| 4 |
+
import type {RequestParameters} from '../util/ajax';
|
| 5 |
+
|
| 6 |
+
const performance = window.performance;
|
| 7 |
+
|
| 8 |
+
export type PerformanceMetrics = {
|
| 9 |
+
loadTime: number,
|
| 10 |
+
fullLoadTime: number,
|
| 11 |
+
fps: number,
|
| 12 |
+
percentDroppedFrames: number
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export const PerformanceMarkers = {
|
| 16 |
+
create: 'create',
|
| 17 |
+
load: 'load',
|
| 18 |
+
fullLoad: 'fullLoad'
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
let lastFrameTime = null;
|
| 22 |
+
let frameTimes = [];
|
| 23 |
+
|
| 24 |
+
const minFramerateTarget = 30;
|
| 25 |
+
const frameTimeTarget = 1000 / minFramerateTarget;
|
| 26 |
+
|
| 27 |
+
export const PerformanceUtils = {
|
| 28 |
+
mark(marker: $Keys<typeof PerformanceMarkers>) {
|
| 29 |
+
performance.mark(marker);
|
| 30 |
+
},
|
| 31 |
+
frame(timestamp: number) {
|
| 32 |
+
const currTimestamp = timestamp;
|
| 33 |
+
if (lastFrameTime != null) {
|
| 34 |
+
const frameTime = currTimestamp - lastFrameTime;
|
| 35 |
+
frameTimes.push(frameTime);
|
| 36 |
+
}
|
| 37 |
+
lastFrameTime = currTimestamp;
|
| 38 |
+
},
|
| 39 |
+
clearMetrics() {
|
| 40 |
+
lastFrameTime = null;
|
| 41 |
+
frameTimes = [];
|
| 42 |
+
performance.clearMeasures('loadTime');
|
| 43 |
+
performance.clearMeasures('fullLoadTime');
|
| 44 |
+
|
| 45 |
+
for (const marker in PerformanceMarkers) {
|
| 46 |
+
performance.clearMarks(PerformanceMarkers[marker]);
|
| 47 |
+
}
|
| 48 |
+
},
|
| 49 |
+
getPerformanceMetrics(): PerformanceMetrics {
|
| 50 |
+
const loadTime = performance.measure('loadTime', PerformanceMarkers.create, PerformanceMarkers.load).duration;
|
| 51 |
+
const fullLoadTime = performance.measure('fullLoadTime', PerformanceMarkers.create, PerformanceMarkers.fullLoad).duration;
|
| 52 |
+
const totalFrames = frameTimes.length;
|
| 53 |
+
|
| 54 |
+
const avgFrameTime = frameTimes.reduce((prev, curr) => prev + curr, 0) / totalFrames / 1000;
|
| 55 |
+
const fps = 1 / avgFrameTime;
|
| 56 |
+
|
| 57 |
+
// count frames that missed our framerate target
|
| 58 |
+
const droppedFrames = frameTimes
|
| 59 |
+
.filter((frameTime) => frameTime > frameTimeTarget)
|
| 60 |
+
.reduce((acc, curr) => {
|
| 61 |
+
return acc + (curr - frameTimeTarget) / frameTimeTarget;
|
| 62 |
+
}, 0);
|
| 63 |
+
const percentDroppedFrames = (droppedFrames / (totalFrames + droppedFrames)) * 100;
|
| 64 |
+
|
| 65 |
+
return {
|
| 66 |
+
loadTime,
|
| 67 |
+
fullLoadTime,
|
| 68 |
+
fps,
|
| 69 |
+
percentDroppedFrames
|
| 70 |
+
};
|
| 71 |
+
}
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* Safe wrapper for the performance resource timing API in web workers with graceful degradation
|
| 76 |
+
*
|
| 77 |
+
* @param {RequestParameters} request
|
| 78 |
+
* @private
|
| 79 |
+
*/
|
| 80 |
+
export class RequestPerformance {
|
| 81 |
+
_marks: {start: string, end: string, measure: string};
|
| 82 |
+
|
| 83 |
+
constructor (request: RequestParameters) {
|
| 84 |
+
this._marks = {
|
| 85 |
+
start: [request.url, 'start'].join('#'),
|
| 86 |
+
end: [request.url, 'end'].join('#'),
|
| 87 |
+
measure: request.url.toString()
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
performance.mark(this._marks.start);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
finish() {
|
| 94 |
+
performance.mark(this._marks.end);
|
| 95 |
+
let resourceTimingData = performance.getEntriesByName(this._marks.measure);
|
| 96 |
+
|
| 97 |
+
// fallback if web worker implementation of perf.getEntriesByName returns empty
|
| 98 |
+
if (resourceTimingData.length === 0) {
|
| 99 |
+
performance.measure(this._marks.measure, this._marks.start, this._marks.end);
|
| 100 |
+
resourceTimingData = performance.getEntriesByName(this._marks.measure);
|
| 101 |
+
|
| 102 |
+
// cleanup
|
| 103 |
+
performance.clearMarks(this._marks.start);
|
| 104 |
+
performance.clearMarks(this._marks.end);
|
| 105 |
+
performance.clearMeasures(this._marks.measure);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return resourceTimingData;
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
export default performance;
|
node_modules/mapbox-gl/src/util/primitives.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
import {vec3, vec4} from 'gl-matrix';
|
| 4 |
+
import assert from 'assert';
|
| 5 |
+
|
| 6 |
+
class Frustum {
|
| 7 |
+
points: Array<Array<number>>;
|
| 8 |
+
planes: Array<Array<number>>;
|
| 9 |
+
|
| 10 |
+
constructor(points_: Array<Array<number>>, planes_: Array<Array<number>>) {
|
| 11 |
+
this.points = points_;
|
| 12 |
+
this.planes = planes_;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
static fromInvProjectionMatrix(invProj: Float64Array, worldSize: number, zoom: number): Frustum {
|
| 16 |
+
const clipSpaceCorners = [
|
| 17 |
+
[-1, 1, -1, 1],
|
| 18 |
+
[ 1, 1, -1, 1],
|
| 19 |
+
[ 1, -1, -1, 1],
|
| 20 |
+
[-1, -1, -1, 1],
|
| 21 |
+
[-1, 1, 1, 1],
|
| 22 |
+
[ 1, 1, 1, 1],
|
| 23 |
+
[ 1, -1, 1, 1],
|
| 24 |
+
[-1, -1, 1, 1]
|
| 25 |
+
];
|
| 26 |
+
|
| 27 |
+
const scale = Math.pow(2, zoom);
|
| 28 |
+
|
| 29 |
+
// Transform frustum corner points from clip space to tile space
|
| 30 |
+
const frustumCoords = clipSpaceCorners
|
| 31 |
+
.map(v => vec4.transformMat4([], v, invProj))
|
| 32 |
+
.map(v => vec4.scale([], v, 1.0 / v[3] / worldSize * scale));
|
| 33 |
+
|
| 34 |
+
const frustumPlanePointIndices = [
|
| 35 |
+
[0, 1, 2], // near
|
| 36 |
+
[6, 5, 4], // far
|
| 37 |
+
[0, 3, 7], // left
|
| 38 |
+
[2, 1, 5], // right
|
| 39 |
+
[3, 2, 6], // bottom
|
| 40 |
+
[0, 4, 5] // top
|
| 41 |
+
];
|
| 42 |
+
|
| 43 |
+
const frustumPlanes = frustumPlanePointIndices.map((p: Array<number>) => {
|
| 44 |
+
const a = vec3.sub([], frustumCoords[p[0]], frustumCoords[p[1]]);
|
| 45 |
+
const b = vec3.sub([], frustumCoords[p[2]], frustumCoords[p[1]]);
|
| 46 |
+
const n = vec3.normalize([], vec3.cross([], a, b));
|
| 47 |
+
const d = -vec3.dot(n, frustumCoords[p[1]]);
|
| 48 |
+
return n.concat(d);
|
| 49 |
+
});
|
| 50 |
+
|
| 51 |
+
return new Frustum(frustumCoords, frustumPlanes);
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
class Aabb {
|
| 56 |
+
min: vec3;
|
| 57 |
+
max: vec3;
|
| 58 |
+
center: vec3;
|
| 59 |
+
|
| 60 |
+
constructor(min_: vec3, max_: vec3) {
|
| 61 |
+
this.min = min_;
|
| 62 |
+
this.max = max_;
|
| 63 |
+
this.center = vec3.scale([], vec3.add([], this.min, this.max), 0.5);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
quadrant(index: number): Aabb {
|
| 67 |
+
const split = [(index % 2) === 0, index < 2];
|
| 68 |
+
const qMin = vec3.clone(this.min);
|
| 69 |
+
const qMax = vec3.clone(this.max);
|
| 70 |
+
for (let axis = 0; axis < split.length; axis++) {
|
| 71 |
+
qMin[axis] = split[axis] ? this.min[axis] : this.center[axis];
|
| 72 |
+
qMax[axis] = split[axis] ? this.center[axis] : this.max[axis];
|
| 73 |
+
}
|
| 74 |
+
// Elevation is always constant, hence quadrant.max.z = this.max.z
|
| 75 |
+
qMax[2] = this.max[2];
|
| 76 |
+
return new Aabb(qMin, qMax);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
distanceX(point: Array<number>): number {
|
| 80 |
+
const pointOnAabb = Math.max(Math.min(this.max[0], point[0]), this.min[0]);
|
| 81 |
+
return pointOnAabb - point[0];
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
distanceY(point: Array<number>): number {
|
| 85 |
+
const pointOnAabb = Math.max(Math.min(this.max[1], point[1]), this.min[1]);
|
| 86 |
+
return pointOnAabb - point[1];
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
// Performs a frustum-aabb intersection test. Returns 0 if there's no intersection,
|
| 90 |
+
// 1 if shapes are intersecting and 2 if the aabb if fully inside the frustum.
|
| 91 |
+
intersects(frustum: Frustum): number {
|
| 92 |
+
// Execute separating axis test between two convex objects to find intersections
|
| 93 |
+
// Each frustum plane together with 3 major axes define the separating axes
|
| 94 |
+
// Note: test only 4 points as both min and max points have equal elevation
|
| 95 |
+
assert(this.min[2] === 0 && this.max[2] === 0);
|
| 96 |
+
|
| 97 |
+
const aabbPoints = [
|
| 98 |
+
[this.min[0], this.min[1], 0.0, 1],
|
| 99 |
+
[this.max[0], this.min[1], 0.0, 1],
|
| 100 |
+
[this.max[0], this.max[1], 0.0, 1],
|
| 101 |
+
[this.min[0], this.max[1], 0.0, 1]
|
| 102 |
+
];
|
| 103 |
+
|
| 104 |
+
let fullyInside = true;
|
| 105 |
+
|
| 106 |
+
for (let p = 0; p < frustum.planes.length; p++) {
|
| 107 |
+
const plane = frustum.planes[p];
|
| 108 |
+
let pointsInside = 0;
|
| 109 |
+
|
| 110 |
+
for (let i = 0; i < aabbPoints.length; i++) {
|
| 111 |
+
pointsInside += vec4.dot(plane, aabbPoints[i]) >= 0;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
if (pointsInside === 0)
|
| 115 |
+
return 0;
|
| 116 |
+
|
| 117 |
+
if (pointsInside !== aabbPoints.length)
|
| 118 |
+
fullyInside = false;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
if (fullyInside)
|
| 122 |
+
return 2;
|
| 123 |
+
|
| 124 |
+
for (let axis = 0; axis < 3; axis++) {
|
| 125 |
+
let projMin = Number.MAX_VALUE;
|
| 126 |
+
let projMax = -Number.MAX_VALUE;
|
| 127 |
+
|
| 128 |
+
for (let p = 0; p < frustum.points.length; p++) {
|
| 129 |
+
const projectedPoint = frustum.points[p][axis] - this.min[axis];
|
| 130 |
+
|
| 131 |
+
projMin = Math.min(projMin, projectedPoint);
|
| 132 |
+
projMax = Math.max(projMax, projectedPoint);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
if (projMax < 0 || projMin > this.max[axis] - this.min[axis])
|
| 136 |
+
return 0;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
return 1;
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
export {
|
| 143 |
+
Aabb,
|
| 144 |
+
Frustum
|
| 145 |
+
};
|
node_modules/mapbox-gl/src/util/resolve_tokens.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
export default resolveTokens;
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* Replace tokens in a string template with values in an object
|
| 6 |
+
*
|
| 7 |
+
* @param properties a key/value relationship between tokens and replacements
|
| 8 |
+
* @param text the template string
|
| 9 |
+
* @returns the template with tokens replaced
|
| 10 |
+
* @private
|
| 11 |
+
*/
|
| 12 |
+
function resolveTokens(properties: {+[string]: mixed}, text: string): string {
|
| 13 |
+
return text.replace(/{([^{}]+)}/g, (match, key: string) => {
|
| 14 |
+
return key in properties ? String(properties[key]) : '';
|
| 15 |
+
});
|
| 16 |
+
}
|
node_modules/mapbox-gl/src/util/script_detection.js
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
/* eslint-disable new-cap */
|
| 4 |
+
|
| 5 |
+
import isChar from './is_char_in_unicode_block';
|
| 6 |
+
|
| 7 |
+
export function allowsIdeographicBreaking(chars: string) {
|
| 8 |
+
for (const char of chars) {
|
| 9 |
+
if (!charAllowsIdeographicBreaking(char.charCodeAt(0))) return false;
|
| 10 |
+
}
|
| 11 |
+
return true;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
export function allowsVerticalWritingMode(chars: string) {
|
| 15 |
+
for (const char of chars) {
|
| 16 |
+
if (charHasUprightVerticalOrientation(char.charCodeAt(0))) return true;
|
| 17 |
+
}
|
| 18 |
+
return false;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
export function allowsLetterSpacing(chars: string) {
|
| 22 |
+
for (const char of chars) {
|
| 23 |
+
if (!charAllowsLetterSpacing(char.charCodeAt(0))) return false;
|
| 24 |
+
}
|
| 25 |
+
return true;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
export function charAllowsLetterSpacing(char: number) {
|
| 29 |
+
if (isChar['Arabic'](char)) return false;
|
| 30 |
+
if (isChar['Arabic Supplement'](char)) return false;
|
| 31 |
+
if (isChar['Arabic Extended-A'](char)) return false;
|
| 32 |
+
if (isChar['Arabic Presentation Forms-A'](char)) return false;
|
| 33 |
+
if (isChar['Arabic Presentation Forms-B'](char)) return false;
|
| 34 |
+
|
| 35 |
+
return true;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
export function charAllowsIdeographicBreaking(char: number) {
|
| 39 |
+
// Return early for characters outside all ideographic ranges.
|
| 40 |
+
if (char < 0x2E80) return false;
|
| 41 |
+
|
| 42 |
+
if (isChar['Bopomofo Extended'](char)) return true;
|
| 43 |
+
if (isChar['Bopomofo'](char)) return true;
|
| 44 |
+
if (isChar['CJK Compatibility Forms'](char)) return true;
|
| 45 |
+
if (isChar['CJK Compatibility Ideographs'](char)) return true;
|
| 46 |
+
if (isChar['CJK Compatibility'](char)) return true;
|
| 47 |
+
if (isChar['CJK Radicals Supplement'](char)) return true;
|
| 48 |
+
if (isChar['CJK Strokes'](char)) return true;
|
| 49 |
+
if (isChar['CJK Symbols and Punctuation'](char)) return true;
|
| 50 |
+
if (isChar['CJK Unified Ideographs Extension A'](char)) return true;
|
| 51 |
+
if (isChar['CJK Unified Ideographs'](char)) return true;
|
| 52 |
+
if (isChar['Enclosed CJK Letters and Months'](char)) return true;
|
| 53 |
+
if (isChar['Halfwidth and Fullwidth Forms'](char)) return true;
|
| 54 |
+
if (isChar['Hiragana'](char)) return true;
|
| 55 |
+
if (isChar['Ideographic Description Characters'](char)) return true;
|
| 56 |
+
if (isChar['Kangxi Radicals'](char)) return true;
|
| 57 |
+
if (isChar['Katakana Phonetic Extensions'](char)) return true;
|
| 58 |
+
if (isChar['Katakana'](char)) return true;
|
| 59 |
+
if (isChar['Vertical Forms'](char)) return true;
|
| 60 |
+
if (isChar['Yi Radicals'](char)) return true;
|
| 61 |
+
if (isChar['Yi Syllables'](char)) return true;
|
| 62 |
+
|
| 63 |
+
return false;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
// The following logic comes from
|
| 67 |
+
// <http://www.unicode.org/Public/12.0.0/ucd/VerticalOrientation.txt>.
|
| 68 |
+
// Keep it synchronized with
|
| 69 |
+
// <http://www.unicode.org/Public/UCD/latest/ucd/VerticalOrientation.txt>.
|
| 70 |
+
// The data file denotes with “U” or “Tu” any codepoint that may be drawn
|
| 71 |
+
// upright in vertical text but does not distinguish between upright and
|
| 72 |
+
// “neutral” characters.
|
| 73 |
+
|
| 74 |
+
// Blocks in the Unicode supplementary planes are excluded from this module due
|
| 75 |
+
// to <https://github.com/mapbox/mapbox-gl/issues/29>.
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* Returns true if the given Unicode codepoint identifies a character with
|
| 79 |
+
* upright orientation.
|
| 80 |
+
*
|
| 81 |
+
* A character has upright orientation if it is drawn upright (unrotated)
|
| 82 |
+
* whether the line is oriented horizontally or vertically, even if both
|
| 83 |
+
* adjacent characters can be rotated. For example, a Chinese character is
|
| 84 |
+
* always drawn upright. An uprightly oriented character causes an adjacent
|
| 85 |
+
* “neutral” character to be drawn upright as well.
|
| 86 |
+
* @private
|
| 87 |
+
*/
|
| 88 |
+
export function charHasUprightVerticalOrientation(char: number) {
|
| 89 |
+
if (char === 0x02EA /* modifier letter yin departing tone mark */ ||
|
| 90 |
+
char === 0x02EB /* modifier letter yang departing tone mark */) {
|
| 91 |
+
return true;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
// Return early for characters outside all ranges whose characters remain
|
| 95 |
+
// upright in vertical writing mode.
|
| 96 |
+
if (char < 0x1100) return false;
|
| 97 |
+
|
| 98 |
+
if (isChar['Bopomofo Extended'](char)) return true;
|
| 99 |
+
if (isChar['Bopomofo'](char)) return true;
|
| 100 |
+
if (isChar['CJK Compatibility Forms'](char)) {
|
| 101 |
+
if (!((char >= 0xFE49 /* dashed overline */ && char <= 0xFE4F) /* wavy low line */)) {
|
| 102 |
+
return true;
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
if (isChar['CJK Compatibility Ideographs'](char)) return true;
|
| 106 |
+
if (isChar['CJK Compatibility'](char)) return true;
|
| 107 |
+
if (isChar['CJK Radicals Supplement'](char)) return true;
|
| 108 |
+
if (isChar['CJK Strokes'](char)) return true;
|
| 109 |
+
if (isChar['CJK Symbols and Punctuation'](char)) {
|
| 110 |
+
if (!((char >= 0x3008 /* left angle bracket */ && char <= 0x3011) /* right black lenticular bracket */) &&
|
| 111 |
+
!((char >= 0x3014 /* left tortoise shell bracket */ && char <= 0x301F) /* low double prime quotation mark */) &&
|
| 112 |
+
char !== 0x3030 /* wavy dash */) {
|
| 113 |
+
return true;
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
if (isChar['CJK Unified Ideographs Extension A'](char)) return true;
|
| 117 |
+
if (isChar['CJK Unified Ideographs'](char)) return true;
|
| 118 |
+
if (isChar['Enclosed CJK Letters and Months'](char)) return true;
|
| 119 |
+
if (isChar['Hangul Compatibility Jamo'](char)) return true;
|
| 120 |
+
if (isChar['Hangul Jamo Extended-A'](char)) return true;
|
| 121 |
+
if (isChar['Hangul Jamo Extended-B'](char)) return true;
|
| 122 |
+
if (isChar['Hangul Jamo'](char)) return true;
|
| 123 |
+
if (isChar['Hangul Syllables'](char)) return true;
|
| 124 |
+
if (isChar['Hiragana'](char)) return true;
|
| 125 |
+
if (isChar['Ideographic Description Characters'](char)) return true;
|
| 126 |
+
if (isChar['Kanbun'](char)) return true;
|
| 127 |
+
if (isChar['Kangxi Radicals'](char)) return true;
|
| 128 |
+
if (isChar['Katakana Phonetic Extensions'](char)) return true;
|
| 129 |
+
if (isChar['Katakana'](char)) {
|
| 130 |
+
if (char !== 0x30FC /* katakana-hiragana prolonged sound mark */) {
|
| 131 |
+
return true;
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
if (isChar['Halfwidth and Fullwidth Forms'](char)) {
|
| 135 |
+
if (char !== 0xFF08 /* fullwidth left parenthesis */ &&
|
| 136 |
+
char !== 0xFF09 /* fullwidth right parenthesis */ &&
|
| 137 |
+
char !== 0xFF0D /* fullwidth hyphen-minus */ &&
|
| 138 |
+
!((char >= 0xFF1A /* fullwidth colon */ && char <= 0xFF1E) /* fullwidth greater-than sign */) &&
|
| 139 |
+
char !== 0xFF3B /* fullwidth left square bracket */ &&
|
| 140 |
+
char !== 0xFF3D /* fullwidth right square bracket */ &&
|
| 141 |
+
char !== 0xFF3F /* fullwidth low line */ &&
|
| 142 |
+
!(char >= 0xFF5B /* fullwidth left curly bracket */ && char <= 0xFFDF) &&
|
| 143 |
+
char !== 0xFFE3 /* fullwidth macron */ &&
|
| 144 |
+
!(char >= 0xFFE8 /* halfwidth forms light vertical */ && char <= 0xFFEF)) {
|
| 145 |
+
return true;
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
if (isChar['Small Form Variants'](char)) {
|
| 149 |
+
if (!((char >= 0xFE58 /* small em dash */ && char <= 0xFE5E) /* small right tortoise shell bracket */) &&
|
| 150 |
+
!((char >= 0xFE63 /* small hyphen-minus */ && char <= 0xFE66) /* small equals sign */)) {
|
| 151 |
+
return true;
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
if (isChar['Unified Canadian Aboriginal Syllabics'](char)) return true;
|
| 155 |
+
if (isChar['Unified Canadian Aboriginal Syllabics Extended'](char)) return true;
|
| 156 |
+
if (isChar['Vertical Forms'](char)) return true;
|
| 157 |
+
if (isChar['Yijing Hexagram Symbols'](char)) return true;
|
| 158 |
+
if (isChar['Yi Syllables'](char)) return true;
|
| 159 |
+
if (isChar['Yi Radicals'](char)) return true;
|
| 160 |
+
|
| 161 |
+
return false;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/**
|
| 165 |
+
* Returns true if the given Unicode codepoint identifies a character with
|
| 166 |
+
* neutral orientation.
|
| 167 |
+
*
|
| 168 |
+
* A character has neutral orientation if it may be drawn rotated or unrotated
|
| 169 |
+
* when the line is oriented vertically, depending on the orientation of the
|
| 170 |
+
* adjacent characters. For example, along a verticlly oriented line, the vulgar
|
| 171 |
+
* fraction ½ is drawn upright among Chinese characters but rotated among Latin
|
| 172 |
+
* letters. A neutrally oriented character does not influence whether an
|
| 173 |
+
* adjacent character is drawn upright or rotated.
|
| 174 |
+
* @private
|
| 175 |
+
*/
|
| 176 |
+
export function charHasNeutralVerticalOrientation(char: number) {
|
| 177 |
+
if (isChar['Latin-1 Supplement'](char)) {
|
| 178 |
+
if (char === 0x00A7 /* section sign */ ||
|
| 179 |
+
char === 0x00A9 /* copyright sign */ ||
|
| 180 |
+
char === 0x00AE /* registered sign */ ||
|
| 181 |
+
char === 0x00B1 /* plus-minus sign */ ||
|
| 182 |
+
char === 0x00BC /* vulgar fraction one quarter */ ||
|
| 183 |
+
char === 0x00BD /* vulgar fraction one half */ ||
|
| 184 |
+
char === 0x00BE /* vulgar fraction three quarters */ ||
|
| 185 |
+
char === 0x00D7 /* multiplication sign */ ||
|
| 186 |
+
char === 0x00F7 /* division sign */) {
|
| 187 |
+
return true;
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
if (isChar['General Punctuation'](char)) {
|
| 191 |
+
if (char === 0x2016 /* double vertical line */ ||
|
| 192 |
+
char === 0x2020 /* dagger */ ||
|
| 193 |
+
char === 0x2021 /* double dagger */ ||
|
| 194 |
+
char === 0x2030 /* per mille sign */ ||
|
| 195 |
+
char === 0x2031 /* per ten thousand sign */ ||
|
| 196 |
+
char === 0x203B /* reference mark */ ||
|
| 197 |
+
char === 0x203C /* double exclamation mark */ ||
|
| 198 |
+
char === 0x2042 /* asterism */ ||
|
| 199 |
+
char === 0x2047 /* double question mark */ ||
|
| 200 |
+
char === 0x2048 /* question exclamation mark */ ||
|
| 201 |
+
char === 0x2049 /* exclamation question mark */ ||
|
| 202 |
+
char === 0x2051 /* two asterisks aligned vertically */) {
|
| 203 |
+
return true;
|
| 204 |
+
}
|
| 205 |
+
}
|
| 206 |
+
if (isChar['Letterlike Symbols'](char)) return true;
|
| 207 |
+
if (isChar['Number Forms'](char)) return true;
|
| 208 |
+
if (isChar['Miscellaneous Technical'](char)) {
|
| 209 |
+
if ((char >= 0x2300 /* diameter sign */ && char <= 0x2307 /* wavy line */) ||
|
| 210 |
+
(char >= 0x230C /* bottom right crop */ && char <= 0x231F /* bottom right corner */) ||
|
| 211 |
+
(char >= 0x2324 /* up arrowhead between two horizontal bars */ && char <= 0x2328 /* keyboard */) ||
|
| 212 |
+
char === 0x232B /* erase to the left */ ||
|
| 213 |
+
(char >= 0x237D /* shouldered open box */ && char <= 0x239A /* clear screen symbol */) ||
|
| 214 |
+
(char >= 0x23BE /* dentistry symbol light vertical and top right */ && char <= 0x23CD /* square foot */) ||
|
| 215 |
+
char === 0x23CF /* eject symbol */ ||
|
| 216 |
+
(char >= 0x23D1 /* metrical breve */ && char <= 0x23DB /* fuse */) ||
|
| 217 |
+
(char >= 0x23E2 /* white trapezium */ && char <= 0x23FF)) {
|
| 218 |
+
return true;
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
if (isChar['Control Pictures'](char) && char !== 0x2423 /* open box */) return true;
|
| 222 |
+
if (isChar['Optical Character Recognition'](char)) return true;
|
| 223 |
+
if (isChar['Enclosed Alphanumerics'](char)) return true;
|
| 224 |
+
if (isChar['Geometric Shapes'](char)) return true;
|
| 225 |
+
if (isChar['Miscellaneous Symbols'](char)) {
|
| 226 |
+
if (!((char >= 0x261A /* black left pointing index */ && char <= 0x261F) /* white down pointing index */)) {
|
| 227 |
+
return true;
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
if (isChar['Miscellaneous Symbols and Arrows'](char)) {
|
| 231 |
+
if ((char >= 0x2B12 /* square with top half black */ && char <= 0x2B2F /* white vertical ellipse */) ||
|
| 232 |
+
(char >= 0x2B50 /* white medium star */ && char <= 0x2B59 /* heavy circled saltire */) ||
|
| 233 |
+
(char >= 0x2BB8 /* upwards white arrow from bar with horizontal bar */ && char <= 0x2BEB)) {
|
| 234 |
+
return true;
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
if (isChar['CJK Symbols and Punctuation'](char)) return true;
|
| 238 |
+
if (isChar['Katakana'](char)) return true;
|
| 239 |
+
if (isChar['Private Use Area'](char)) return true;
|
| 240 |
+
if (isChar['CJK Compatibility Forms'](char)) return true;
|
| 241 |
+
if (isChar['Small Form Variants'](char)) return true;
|
| 242 |
+
if (isChar['Halfwidth and Fullwidth Forms'](char)) return true;
|
| 243 |
+
|
| 244 |
+
if (char === 0x221E /* infinity */ ||
|
| 245 |
+
char === 0x2234 /* therefore */ ||
|
| 246 |
+
char === 0x2235 /* because */ ||
|
| 247 |
+
(char >= 0x2700 /* black safety scissors */ && char <= 0x2767 /* rotated floral heart bullet */) ||
|
| 248 |
+
(char >= 0x2776 /* dingbat negative circled digit one */ && char <= 0x2793 /* dingbat negative circled sans-serif number ten */) ||
|
| 249 |
+
char === 0xFFFC /* object replacement character */ ||
|
| 250 |
+
char === 0xFFFD /* replacement character */) {
|
| 251 |
+
return true;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
return false;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
/**
|
| 258 |
+
* Returns true if the given Unicode codepoint identifies a character with
|
| 259 |
+
* rotated orientation.
|
| 260 |
+
*
|
| 261 |
+
* A character has rotated orientation if it is drawn rotated when the line is
|
| 262 |
+
* oriented vertically, even if both adjacent characters are upright. For
|
| 263 |
+
* example, a Latin letter is drawn rotated along a vertical line. A rotated
|
| 264 |
+
* character causes an adjacent “neutral” character to be drawn rotated as well.
|
| 265 |
+
* @private
|
| 266 |
+
*/
|
| 267 |
+
export function charHasRotatedVerticalOrientation(char: number) {
|
| 268 |
+
return !(charHasUprightVerticalOrientation(char) ||
|
| 269 |
+
charHasNeutralVerticalOrientation(char));
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
export function charInComplexShapingScript(char: number) {
|
| 273 |
+
return isChar['Arabic'](char) ||
|
| 274 |
+
isChar['Arabic Supplement'](char) ||
|
| 275 |
+
isChar['Arabic Extended-A'](char) ||
|
| 276 |
+
isChar['Arabic Presentation Forms-A'](char) ||
|
| 277 |
+
isChar['Arabic Presentation Forms-B'](char);
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
export function charInRTLScript(char: number) {
|
| 281 |
+
// Main blocks for Hebrew, Arabic, Thaana and other RTL scripts
|
| 282 |
+
return (char >= 0x0590 && char <= 0x08FF) ||
|
| 283 |
+
isChar['Arabic Presentation Forms-A'](char) ||
|
| 284 |
+
isChar['Arabic Presentation Forms-B'](char);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
export function charInSupportedScript(char: number, canRenderRTL: boolean) {
|
| 288 |
+
// This is a rough heuristic: whether we "can render" a script
|
| 289 |
+
// actually depends on the properties of the font being used
|
| 290 |
+
// and whether differences from the ideal rendering are considered
|
| 291 |
+
// semantically significant.
|
| 292 |
+
|
| 293 |
+
// Even in Latin script, we "can't render" combinations such as the fi
|
| 294 |
+
// ligature, but we don't consider that semantically significant.
|
| 295 |
+
if (!canRenderRTL && charInRTLScript(char)) {
|
| 296 |
+
return false;
|
| 297 |
+
}
|
| 298 |
+
if ((char >= 0x0900 && char <= 0x0DFF) ||
|
| 299 |
+
// Main blocks for Indic scripts and Sinhala
|
| 300 |
+
(char >= 0x0F00 && char <= 0x109F) ||
|
| 301 |
+
// Main blocks for Tibetan and Myanmar
|
| 302 |
+
isChar['Khmer'](char)) {
|
| 303 |
+
// These blocks cover common scripts that require
|
| 304 |
+
// complex text shaping, based on unicode script metadata:
|
| 305 |
+
// http://www.unicode.org/repos/cldr/trunk/common/properties/scriptMetadata.txt
|
| 306 |
+
// where "Web Rank <= 32" "Shaping Required = YES"
|
| 307 |
+
return false;
|
| 308 |
+
}
|
| 309 |
+
return true;
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
export function stringContainsRTLText(chars: string): boolean {
|
| 313 |
+
for (const char of chars) {
|
| 314 |
+
if (charInRTLScript(char.charCodeAt(0))) {
|
| 315 |
+
return true;
|
| 316 |
+
}
|
| 317 |
+
}
|
| 318 |
+
return false;
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
export function isStringInSupportedScript(chars: string, canRenderRTL: boolean) {
|
| 322 |
+
for (const char of chars) {
|
| 323 |
+
if (!charInSupportedScript(char.charCodeAt(0), canRenderRTL)) {
|
| 324 |
+
return false;
|
| 325 |
+
}
|
| 326 |
+
}
|
| 327 |
+
return true;
|
| 328 |
+
}
|
node_modules/mapbox-gl/src/util/sku_token.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
/***** START WARNING - IF YOU USE THIS CODE WITH MAPBOX MAPPING APIS, REMOVAL OR
|
| 4 |
+
* MODIFICATION OF THE FOLLOWING CODE VIOLATES THE MAPBOX TERMS OF SERVICE ******
|
| 5 |
+
* The following code is used to access Mapbox's Mapping APIs. Removal or modification
|
| 6 |
+
* of this code when used with Mapbox's Mapping APIs can result in higher fees and/or
|
| 7 |
+
* termination of your account with Mapbox.
|
| 8 |
+
*
|
| 9 |
+
* Under the Mapbox Terms of Service, you may not use this code to access Mapbox
|
| 10 |
+
* Mapping APIs other than through Mapbox SDKs.
|
| 11 |
+
*
|
| 12 |
+
* The Mapping APIs documentation is available at https://docs.mapbox.com/api/maps/#maps
|
| 13 |
+
* and the Mapbox Terms of Service are available at https://www.mapbox.com/tos/
|
| 14 |
+
******************************************************************************/
|
| 15 |
+
|
| 16 |
+
type SkuTokenObject = {|
|
| 17 |
+
token: string,
|
| 18 |
+
tokenExpiresAt: number
|
| 19 |
+
|};
|
| 20 |
+
|
| 21 |
+
const SKU_ID = '01';
|
| 22 |
+
|
| 23 |
+
function createSkuToken(): SkuTokenObject {
|
| 24 |
+
// SKU_ID and TOKEN_VERSION are specified by an internal schema and should not change
|
| 25 |
+
const TOKEN_VERSION = '1';
|
| 26 |
+
const base62chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
| 27 |
+
// sessionRandomizer is a randomized 10-digit base-62 number
|
| 28 |
+
let sessionRandomizer = '';
|
| 29 |
+
for (let i = 0; i < 10; i++) {
|
| 30 |
+
sessionRandomizer += base62chars[Math.floor(Math.random() * 62)];
|
| 31 |
+
}
|
| 32 |
+
const expiration = 12 * 60 * 60 * 1000; // 12 hours
|
| 33 |
+
const token = [TOKEN_VERSION, SKU_ID, sessionRandomizer].join('');
|
| 34 |
+
const tokenExpiresAt = Date.now() + expiration;
|
| 35 |
+
|
| 36 |
+
return {token, tokenExpiresAt};
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
export {createSkuToken, SKU_ID};
|
| 40 |
+
|
| 41 |
+
/***** END WARNING - REMOVAL OR MODIFICATION OF THE
|
| 42 |
+
PRECEDING CODE VIOLATES THE MAPBOX TERMS OF SERVICE ******/
|
node_modules/mapbox-gl/src/util/smart_wrap.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
import LngLat from '../geo/lng_lat';
|
| 4 |
+
|
| 5 |
+
import type Point from '@mapbox/point-geometry';
|
| 6 |
+
import type Transform from '../geo/transform';
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* Given a LngLat, prior projected position, and a transform, return a new LngLat shifted
|
| 10 |
+
* n × 360° east or west for some n ≥ 0 such that:
|
| 11 |
+
*
|
| 12 |
+
* * the projected location of the result is on screen, if possible, and secondarily:
|
| 13 |
+
* * the difference between the projected location of the result and the prior position
|
| 14 |
+
* is minimized.
|
| 15 |
+
*
|
| 16 |
+
* The object is to preserve perceived object constancy for Popups and Markers as much as
|
| 17 |
+
* possible; they should avoid shifting large distances across the screen, even when the
|
| 18 |
+
* map center changes by ±360° due to automatic wrapping, and when about to go off screen,
|
| 19 |
+
* should wrap just enough to avoid doing so.
|
| 20 |
+
*
|
| 21 |
+
* @private
|
| 22 |
+
*/
|
| 23 |
+
export default function(lngLat: LngLat, priorPos: ?Point, transform: Transform): LngLat {
|
| 24 |
+
lngLat = new LngLat(lngLat.lng, lngLat.lat);
|
| 25 |
+
|
| 26 |
+
// First, try shifting one world in either direction, and see if either is closer to the
|
| 27 |
+
// prior position. This preserves object constancy when the map center is auto-wrapped
|
| 28 |
+
// during animations.
|
| 29 |
+
if (priorPos) {
|
| 30 |
+
const left = new LngLat(lngLat.lng - 360, lngLat.lat);
|
| 31 |
+
const right = new LngLat(lngLat.lng + 360, lngLat.lat);
|
| 32 |
+
const delta = transform.locationPoint(lngLat).distSqr(priorPos);
|
| 33 |
+
if (transform.locationPoint(left).distSqr(priorPos) < delta) {
|
| 34 |
+
lngLat = left;
|
| 35 |
+
} else if (transform.locationPoint(right).distSqr(priorPos) < delta) {
|
| 36 |
+
lngLat = right;
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
// Second, wrap toward the center until the new position is on screen, or we can't get
|
| 41 |
+
// any closer.
|
| 42 |
+
while (Math.abs(lngLat.lng - transform.center.lng) > 180) {
|
| 43 |
+
const pos = transform.locationPoint(lngLat);
|
| 44 |
+
if (pos.x >= 0 && pos.y >= 0 && pos.x <= transform.width && pos.y <= transform.height) {
|
| 45 |
+
break;
|
| 46 |
+
}
|
| 47 |
+
if (lngLat.lng > transform.center.lng) {
|
| 48 |
+
lngLat.lng -= 360;
|
| 49 |
+
} else {
|
| 50 |
+
lngLat.lng += 360;
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
return lngLat;
|
| 55 |
+
}
|
node_modules/mapbox-gl/src/util/struct_array.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
// Note: all "sizes" are measured in bytes
|
| 4 |
+
|
| 5 |
+
import assert from 'assert';
|
| 6 |
+
|
| 7 |
+
import type {Transferable} from '../types/transferable';
|
| 8 |
+
|
| 9 |
+
const viewTypes = {
|
| 10 |
+
'Int8': Int8Array,
|
| 11 |
+
'Uint8': Uint8Array,
|
| 12 |
+
'Int16': Int16Array,
|
| 13 |
+
'Uint16': Uint16Array,
|
| 14 |
+
'Int32': Int32Array,
|
| 15 |
+
'Uint32': Uint32Array,
|
| 16 |
+
'Float32': Float32Array
|
| 17 |
+
};
|
| 18 |
+
|
| 19 |
+
export type ViewType = $Keys<typeof viewTypes>;
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* @private
|
| 23 |
+
*/
|
| 24 |
+
class Struct {
|
| 25 |
+
_pos1: number;
|
| 26 |
+
_pos2: number;
|
| 27 |
+
_pos4: number;
|
| 28 |
+
_pos8: number;
|
| 29 |
+
+_structArray: StructArray;
|
| 30 |
+
|
| 31 |
+
// The following properties are defined on the prototype of sub classes.
|
| 32 |
+
size: number;
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* @param {StructArray} structArray The StructArray the struct is stored in
|
| 36 |
+
* @param {number} index The index of the struct in the StructArray.
|
| 37 |
+
* @private
|
| 38 |
+
*/
|
| 39 |
+
constructor(structArray: StructArray, index: number) {
|
| 40 |
+
(this: any)._structArray = structArray;
|
| 41 |
+
this._pos1 = index * this.size;
|
| 42 |
+
this._pos2 = this._pos1 / 2;
|
| 43 |
+
this._pos4 = this._pos1 / 4;
|
| 44 |
+
this._pos8 = this._pos1 / 8;
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
const DEFAULT_CAPACITY = 128;
|
| 49 |
+
const RESIZE_MULTIPLIER = 5;
|
| 50 |
+
|
| 51 |
+
export type StructArrayMember = {
|
| 52 |
+
name: string,
|
| 53 |
+
type: ViewType,
|
| 54 |
+
components: number,
|
| 55 |
+
offset: number
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
export type StructArrayLayout = {
|
| 59 |
+
members: Array<StructArrayMember>,
|
| 60 |
+
size: number,
|
| 61 |
+
alignment: ?number
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
export type SerializedStructArray = {
|
| 65 |
+
length: number,
|
| 66 |
+
arrayBuffer: ArrayBuffer
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* `StructArray` provides an abstraction over `ArrayBuffer` and `TypedArray`
|
| 71 |
+
* making it behave like an array of typed structs.
|
| 72 |
+
*
|
| 73 |
+
* Conceptually, a StructArray is comprised of elements, i.e., instances of its
|
| 74 |
+
* associated struct type. Each particular struct type, together with an
|
| 75 |
+
* alignment size, determines the memory layout of a StructArray whose elements
|
| 76 |
+
* are of that type. Thus, for each such layout that we need, we have
|
| 77 |
+
* a corrseponding StructArrayLayout class, inheriting from StructArray and
|
| 78 |
+
* implementing `emplaceBack()` and `_refreshViews()`.
|
| 79 |
+
*
|
| 80 |
+
* In some cases, where we need to access particular elements of a StructArray,
|
| 81 |
+
* we implement a more specific subclass that inherits from one of the
|
| 82 |
+
* StructArrayLayouts and adds a `get(i): T` accessor that returns a structured
|
| 83 |
+
* object whose properties are proxies into the underlying memory space for the
|
| 84 |
+
* i-th element. This affords the convience of working with (seemingly) plain
|
| 85 |
+
* Javascript objects without the overhead of serializing/deserializing them
|
| 86 |
+
* into ArrayBuffers for efficient web worker transfer.
|
| 87 |
+
*
|
| 88 |
+
* @private
|
| 89 |
+
*/
|
| 90 |
+
class StructArray {
|
| 91 |
+
capacity: number;
|
| 92 |
+
length: number;
|
| 93 |
+
isTransferred: boolean;
|
| 94 |
+
arrayBuffer: ArrayBuffer;
|
| 95 |
+
uint8: Uint8Array;
|
| 96 |
+
|
| 97 |
+
// The following properties are defined on the prototype.
|
| 98 |
+
members: Array<StructArrayMember>;
|
| 99 |
+
bytesPerElement: number;
|
| 100 |
+
+emplaceBack: Function;
|
| 101 |
+
+emplace: Function;
|
| 102 |
+
|
| 103 |
+
constructor() {
|
| 104 |
+
this.isTransferred = false;
|
| 105 |
+
this.capacity = -1;
|
| 106 |
+
this.resize(0);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* Serialize a StructArray instance. Serializes both the raw data and the
|
| 111 |
+
* metadata needed to reconstruct the StructArray base class during
|
| 112 |
+
* deserialization.
|
| 113 |
+
* @private
|
| 114 |
+
*/
|
| 115 |
+
static serialize(array: StructArray, transferables?: Array<Transferable>): SerializedStructArray {
|
| 116 |
+
assert(!array.isTransferred);
|
| 117 |
+
|
| 118 |
+
array._trim();
|
| 119 |
+
|
| 120 |
+
if (transferables) {
|
| 121 |
+
array.isTransferred = true;
|
| 122 |
+
transferables.push(array.arrayBuffer);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return {
|
| 126 |
+
length: array.length,
|
| 127 |
+
arrayBuffer: array.arrayBuffer,
|
| 128 |
+
};
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
static deserialize(input: SerializedStructArray) {
|
| 132 |
+
const structArray = Object.create(this.prototype);
|
| 133 |
+
structArray.arrayBuffer = input.arrayBuffer;
|
| 134 |
+
structArray.length = input.length;
|
| 135 |
+
structArray.capacity = input.arrayBuffer.byteLength / structArray.bytesPerElement;
|
| 136 |
+
structArray._refreshViews();
|
| 137 |
+
return structArray;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* Resize the array to discard unused capacity.
|
| 142 |
+
*/
|
| 143 |
+
_trim() {
|
| 144 |
+
if (this.length !== this.capacity) {
|
| 145 |
+
this.capacity = this.length;
|
| 146 |
+
this.arrayBuffer = this.arrayBuffer.slice(0, this.length * this.bytesPerElement);
|
| 147 |
+
this._refreshViews();
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
/**
|
| 152 |
+
* Resets the the length of the array to 0 without de-allocating capcacity.
|
| 153 |
+
*/
|
| 154 |
+
clear() {
|
| 155 |
+
this.length = 0;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* Resize the array.
|
| 160 |
+
* If `n` is greater than the current length then additional elements with undefined values are added.
|
| 161 |
+
* If `n` is less than the current length then the array will be reduced to the first `n` elements.
|
| 162 |
+
* @param {number} n The new size of the array.
|
| 163 |
+
*/
|
| 164 |
+
resize(n: number) {
|
| 165 |
+
assert(!this.isTransferred);
|
| 166 |
+
this.reserve(n);
|
| 167 |
+
this.length = n;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
/**
|
| 171 |
+
* Indicate a planned increase in size, so that any necessary allocation may
|
| 172 |
+
* be done once, ahead of time.
|
| 173 |
+
* @param {number} n The expected size of the array.
|
| 174 |
+
*/
|
| 175 |
+
reserve(n: number) {
|
| 176 |
+
if (n > this.capacity) {
|
| 177 |
+
this.capacity = Math.max(n, Math.floor(this.capacity * RESIZE_MULTIPLIER), DEFAULT_CAPACITY);
|
| 178 |
+
this.arrayBuffer = new ArrayBuffer(this.capacity * this.bytesPerElement);
|
| 179 |
+
|
| 180 |
+
const oldUint8Array = this.uint8;
|
| 181 |
+
this._refreshViews();
|
| 182 |
+
if (oldUint8Array) this.uint8.set(oldUint8Array);
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
/**
|
| 187 |
+
* Create TypedArray views for the current ArrayBuffer.
|
| 188 |
+
*/
|
| 189 |
+
_refreshViews() {
|
| 190 |
+
throw new Error('_refreshViews() must be implemented by each concrete StructArray layout');
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/**
|
| 195 |
+
* Given a list of member fields, create a full StructArrayLayout, in
|
| 196 |
+
* particular calculating the correct byte offset for each field. This data
|
| 197 |
+
* is used at build time to generate StructArrayLayout_*#emplaceBack() and
|
| 198 |
+
* other accessors, and at runtime for binding vertex buffer attributes.
|
| 199 |
+
*
|
| 200 |
+
* @private
|
| 201 |
+
*/
|
| 202 |
+
function createLayout(
|
| 203 |
+
members: Array<{ name: string, type: ViewType, +components?: number, }>,
|
| 204 |
+
alignment: number = 1
|
| 205 |
+
): StructArrayLayout {
|
| 206 |
+
|
| 207 |
+
let offset = 0;
|
| 208 |
+
let maxSize = 0;
|
| 209 |
+
const layoutMembers = members.map((member) => {
|
| 210 |
+
assert(member.name.length);
|
| 211 |
+
const typeSize = sizeOf(member.type);
|
| 212 |
+
const memberOffset = offset = align(offset, Math.max(alignment, typeSize));
|
| 213 |
+
const components = member.components || 1;
|
| 214 |
+
|
| 215 |
+
maxSize = Math.max(maxSize, typeSize);
|
| 216 |
+
offset += typeSize * components;
|
| 217 |
+
|
| 218 |
+
return {
|
| 219 |
+
name: member.name,
|
| 220 |
+
type: member.type,
|
| 221 |
+
components,
|
| 222 |
+
offset: memberOffset,
|
| 223 |
+
};
|
| 224 |
+
});
|
| 225 |
+
|
| 226 |
+
const size = align(offset, Math.max(maxSize, alignment));
|
| 227 |
+
|
| 228 |
+
return {
|
| 229 |
+
members: layoutMembers,
|
| 230 |
+
size,
|
| 231 |
+
alignment
|
| 232 |
+
};
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
function sizeOf(type: ViewType): number {
|
| 236 |
+
return viewTypes[type].BYTES_PER_ELEMENT;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
function align(offset: number, size: number): number {
|
| 240 |
+
return Math.ceil(offset / size) * size;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
export {StructArray, Struct, viewTypes, createLayout};
|
node_modules/mapbox-gl/src/util/struct_array.js.ejs
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<%
|
| 2 |
+
const {
|
| 3 |
+
arrayClass,
|
| 4 |
+
members,
|
| 5 |
+
size,
|
| 6 |
+
usedTypes,
|
| 7 |
+
hasAnchorPoint,
|
| 8 |
+
layoutClass,
|
| 9 |
+
includeStructAccessors
|
| 10 |
+
} = locals
|
| 11 |
+
|
| 12 |
+
const StructTypeClass = arrayClass.replace('Array', 'Struct');
|
| 13 |
+
const StructArrayClass = arrayClass;
|
| 14 |
+
const StructArrayLayoutClass = layoutClass;
|
| 15 |
+
-%>
|
| 16 |
+
<%
|
| 17 |
+
// collect components
|
| 18 |
+
const components = [];
|
| 19 |
+
for (const member of members) {
|
| 20 |
+
for (let c = 0; c < member.components; c++) {
|
| 21 |
+
let name = member.name;
|
| 22 |
+
if (member.components > 1) {
|
| 23 |
+
name += c;
|
| 24 |
+
}
|
| 25 |
+
components.push({name, member, component: c});
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// exceptions for which we generate accessors on the array rather than a separate struct for performance
|
| 30 |
+
const useComponentGetters = StructArrayClass === 'GlyphOffsetArray' || StructArrayClass === 'SymbolLineVertexArray';
|
| 31 |
+
|
| 32 |
+
if (includeStructAccessors && !useComponentGetters) {
|
| 33 |
+
-%>
|
| 34 |
+
class <%=StructTypeClass%> extends Struct {
|
| 35 |
+
_structArray: <%=StructArrayClass%>;
|
| 36 |
+
<%
|
| 37 |
+
// property declarations
|
| 38 |
+
for (const {name} of components) {-%>
|
| 39 |
+
<%=name%>: number;
|
| 40 |
+
<% }
|
| 41 |
+
if (hasAnchorPoint) { -%>
|
| 42 |
+
anchorPoint: Point;
|
| 43 |
+
<% } -%>
|
| 44 |
+
<%
|
| 45 |
+
for (const {name, member, component} of components) {
|
| 46 |
+
const elementOffset = `this._pos${member.size.toFixed(0)}`;
|
| 47 |
+
const componentOffset = (member.offset / member.size + component).toFixed(0);
|
| 48 |
+
const index = `${elementOffset} + ${componentOffset}`;
|
| 49 |
+
const componentAccess = `this._structArray.${member.view}[${index}]`;
|
| 50 |
+
-%>
|
| 51 |
+
get <%=name%>() { return <%=componentAccess%>; }
|
| 52 |
+
<%
|
| 53 |
+
// generate setters for properties that are updated during runtime symbol placement; others are read-only
|
| 54 |
+
if (name === 'crossTileID' || name === 'placedOrientation' || name === 'hidden') {
|
| 55 |
+
-%>
|
| 56 |
+
set <%=name%>(x: number) { <%=componentAccess%> = x; }
|
| 57 |
+
<%
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
// Special case used for the CollisionBoxArray type
|
| 61 |
+
if (hasAnchorPoint) {
|
| 62 |
+
-%>
|
| 63 |
+
get anchorPoint() { return new Point(this.anchorPointX, this.anchorPointY); }
|
| 64 |
+
<%
|
| 65 |
+
}
|
| 66 |
+
-%>
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
<%=StructTypeClass%>.prototype.size = <%=size%>;
|
| 70 |
+
|
| 71 |
+
export type <%=StructTypeClass.replace('Struct', '')%> = <%=StructTypeClass%>;
|
| 72 |
+
|
| 73 |
+
<%
|
| 74 |
+
} // end 'if (includeStructAccessors)'
|
| 75 |
+
-%>
|
| 76 |
+
/**
|
| 77 |
+
* @private
|
| 78 |
+
*/
|
| 79 |
+
export class <%=StructArrayClass%> extends <%=StructArrayLayoutClass%> {
|
| 80 |
+
<%
|
| 81 |
+
if (useComponentGetters) {
|
| 82 |
+
for (const member of members) {
|
| 83 |
+
for (let c = 0; c < member.components; c++) {
|
| 84 |
+
if (!includeStructAccessors) continue;
|
| 85 |
+
let name = `get${member.name}`;
|
| 86 |
+
if (member.components > 1) {
|
| 87 |
+
name += c;
|
| 88 |
+
}
|
| 89 |
+
const componentOffset = (member.offset / member.size + c).toFixed(0);
|
| 90 |
+
const componentStride = size / member.size;
|
| 91 |
+
-%>
|
| 92 |
+
<%=name%>(index: number) { return this.<%=member.view%>[index * <%=componentStride%> + <%=componentOffset%>]; }
|
| 93 |
+
<%
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
} else if (includeStructAccessors) { // get(i)
|
| 97 |
+
-%>
|
| 98 |
+
/**
|
| 99 |
+
* Return the <%=StructTypeClass%> at the given location in the array.
|
| 100 |
+
* @param {number} index The index of the element.
|
| 101 |
+
* @private
|
| 102 |
+
*/
|
| 103 |
+
get(index: number): <%=StructTypeClass%> {
|
| 104 |
+
assert(!this.isTransferred);
|
| 105 |
+
return new <%=StructTypeClass%>(this, index);
|
| 106 |
+
}
|
| 107 |
+
<%
|
| 108 |
+
}
|
| 109 |
+
-%>
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
register('<%=StructArrayClass%>', <%=StructArrayClass%>);
|
node_modules/mapbox-gl/src/util/struct_array_layout.js.ejs
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<%
|
| 2 |
+
const {
|
| 3 |
+
className,
|
| 4 |
+
members,
|
| 5 |
+
size,
|
| 6 |
+
usedTypes
|
| 7 |
+
} = locals
|
| 8 |
+
|
| 9 |
+
const StructArrayLayoutClass = className;
|
| 10 |
+
-%>
|
| 11 |
+
/**
|
| 12 |
+
* Implementation of the StructArray layout:
|
| 13 |
+
<%
|
| 14 |
+
for (const member of members) {
|
| 15 |
+
-%>
|
| 16 |
+
* [<%=member.offset%>]: <%=member.type%>[<%=member.components%>]
|
| 17 |
+
<%
|
| 18 |
+
}
|
| 19 |
+
-%>
|
| 20 |
+
*
|
| 21 |
+
* @private
|
| 22 |
+
*/
|
| 23 |
+
class <%=StructArrayLayoutClass%> extends StructArray {
|
| 24 |
+
<%
|
| 25 |
+
for (const type of usedTypes) {
|
| 26 |
+
-%>
|
| 27 |
+
<%=type.toLowerCase()%>: <%=type%>Array;
|
| 28 |
+
<%
|
| 29 |
+
}
|
| 30 |
+
-%>
|
| 31 |
+
|
| 32 |
+
_refreshViews() {
|
| 33 |
+
<%
|
| 34 |
+
for (const type of usedTypes) {
|
| 35 |
+
-%>
|
| 36 |
+
this.<%=type.toLowerCase()%> = new <%=type%>Array(this.arrayBuffer);
|
| 37 |
+
<%
|
| 38 |
+
}
|
| 39 |
+
-%>
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
<%
|
| 43 |
+
// prep for emplaceBack: collect type sizes and count the number of arguments
|
| 44 |
+
// we'll need
|
| 45 |
+
const bytesPerElement = size;
|
| 46 |
+
const usedTypeSizes = [];
|
| 47 |
+
const argNames = [];
|
| 48 |
+
const argNamesTyped = [];
|
| 49 |
+
for (const member of members) {
|
| 50 |
+
if (usedTypeSizes.indexOf(member.size) < 0) {
|
| 51 |
+
usedTypeSizes.push(member.size);
|
| 52 |
+
}
|
| 53 |
+
for (let c = 0; c < member.components; c++) {
|
| 54 |
+
// arguments v0, v1, v2, ... are, in order, the components of
|
| 55 |
+
// member 0, then the components of member 1, etc.
|
| 56 |
+
const name = `v${argNames.length}`;
|
| 57 |
+
argNames.push(name);
|
| 58 |
+
argNamesTyped.push(`${name}: number`);
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
-%>
|
| 62 |
+
emplaceBack(<%=argNamesTyped.join(', ')%>) {
|
| 63 |
+
const i = this.length;
|
| 64 |
+
this.resize(i + 1);
|
| 65 |
+
return this.emplace(i, <%=argNames.join(', ')%>);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
emplace(i: number, <%=argNamesTyped.join(', ')%>) {
|
| 69 |
+
<%
|
| 70 |
+
{
|
| 71 |
+
for (const size of usedTypeSizes) {
|
| 72 |
+
-%>
|
| 73 |
+
const o<%=size.toFixed(0)%> = i * <%=(bytesPerElement / size).toFixed(0)%>;
|
| 74 |
+
<%
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
let argIndex = 0;
|
| 78 |
+
for (const member of members) {
|
| 79 |
+
for (let c = 0; c < member.components; c++) {
|
| 80 |
+
// The index for `member` component `c` into the appropriate type array is:
|
| 81 |
+
// this.{TYPE}[o{SIZE} + MEMBER_OFFSET + {c}] = v{X}
|
| 82 |
+
// where MEMBER_OFFSET = ROUND(member.offset / size) is the per-element
|
| 83 |
+
// offset of this member into the array
|
| 84 |
+
const index = `o${member.size.toFixed(0)} + ${(member.offset / member.size + c).toFixed(0)}`;
|
| 85 |
+
-%>
|
| 86 |
+
this.<%=member.view%>[<%=index%>] = v<%=argIndex++%>;
|
| 87 |
+
<%
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
-%>
|
| 92 |
+
return i;
|
| 93 |
+
}
|
| 94 |
+
-%>
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
<%=StructArrayLayoutClass%>.prototype.bytesPerElement = <%= size %>;
|
| 98 |
+
register('<%=StructArrayLayoutClass%>', <%=StructArrayLayoutClass%>);
|
node_modules/mapbox-gl/src/util/task_queue.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow strict
|
| 2 |
+
import assert from 'assert';
|
| 3 |
+
|
| 4 |
+
export type TaskID = number; // can't mark opaque due to https://github.com/flowtype/flow-remove-types/pull/61
|
| 5 |
+
type Task = {
|
| 6 |
+
callback: (timeStamp: number) => void;
|
| 7 |
+
id: TaskID;
|
| 8 |
+
cancelled: boolean;
|
| 9 |
+
};
|
| 10 |
+
|
| 11 |
+
class TaskQueue {
|
| 12 |
+
_queue: Array<Task>;
|
| 13 |
+
_id: TaskID;
|
| 14 |
+
_cleared: boolean;
|
| 15 |
+
_currentlyRunning: Array<Task> | false;
|
| 16 |
+
|
| 17 |
+
constructor() {
|
| 18 |
+
this._queue = [];
|
| 19 |
+
this._id = 0;
|
| 20 |
+
this._cleared = false;
|
| 21 |
+
this._currentlyRunning = false;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
add(callback: (timeStamp: number) => void): TaskID {
|
| 25 |
+
const id = ++this._id;
|
| 26 |
+
const queue = this._queue;
|
| 27 |
+
queue.push({callback, id, cancelled: false});
|
| 28 |
+
return id;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
remove(id: TaskID) {
|
| 32 |
+
const running = this._currentlyRunning;
|
| 33 |
+
const queue = running ? this._queue.concat(running) : this._queue;
|
| 34 |
+
for (const task of queue) {
|
| 35 |
+
if (task.id === id) {
|
| 36 |
+
task.cancelled = true;
|
| 37 |
+
return;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
run(timeStamp: number = 0) {
|
| 43 |
+
assert(!this._currentlyRunning);
|
| 44 |
+
const queue = this._currentlyRunning = this._queue;
|
| 45 |
+
|
| 46 |
+
// Tasks queued by callbacks in the current queue should be executed
|
| 47 |
+
// on the next run, not the current run.
|
| 48 |
+
this._queue = [];
|
| 49 |
+
|
| 50 |
+
for (const task of queue) {
|
| 51 |
+
if (task.cancelled) continue;
|
| 52 |
+
task.callback(timeStamp);
|
| 53 |
+
if (this._cleared) break;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
this._cleared = false;
|
| 57 |
+
this._currentlyRunning = false;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
clear() {
|
| 61 |
+
if (this._currentlyRunning) {
|
| 62 |
+
this._cleared = true;
|
| 63 |
+
}
|
| 64 |
+
this._queue = [];
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
export default TaskQueue;
|
node_modules/mapbox-gl/src/util/throttle.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow strict
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Throttle the given function to run at most every `period` milliseconds.
|
| 5 |
+
* @private
|
| 6 |
+
*/
|
| 7 |
+
export default function throttle(fn: () => void, time: number): () => ?TimeoutID {
|
| 8 |
+
let pending = false;
|
| 9 |
+
let timerId: ?TimeoutID = null;
|
| 10 |
+
|
| 11 |
+
const later = () => {
|
| 12 |
+
timerId = null;
|
| 13 |
+
if (pending) {
|
| 14 |
+
fn();
|
| 15 |
+
timerId = setTimeout(later, time);
|
| 16 |
+
pending = false;
|
| 17 |
+
}
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
return () => {
|
| 21 |
+
pending = true;
|
| 22 |
+
if (!timerId) {
|
| 23 |
+
later();
|
| 24 |
+
}
|
| 25 |
+
return timerId;
|
| 26 |
+
};
|
| 27 |
+
}
|
node_modules/mapbox-gl/src/util/throttled_invoker.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Invokes the wrapped function in a non-blocking way when trigger() is called. Invocation requests
|
| 5 |
+
* are ignored until the function was actually invoked.
|
| 6 |
+
*
|
| 7 |
+
* @private
|
| 8 |
+
*/
|
| 9 |
+
class ThrottledInvoker {
|
| 10 |
+
_channel: MessageChannel;
|
| 11 |
+
_triggered: boolean;
|
| 12 |
+
_callback: Function
|
| 13 |
+
|
| 14 |
+
constructor(callback: Function) {
|
| 15 |
+
this._callback = callback;
|
| 16 |
+
this._triggered = false;
|
| 17 |
+
if (typeof MessageChannel !== 'undefined') {
|
| 18 |
+
this._channel = new MessageChannel();
|
| 19 |
+
this._channel.port2.onmessage = () => {
|
| 20 |
+
this._triggered = false;
|
| 21 |
+
this._callback();
|
| 22 |
+
};
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
trigger() {
|
| 27 |
+
if (!this._triggered) {
|
| 28 |
+
this._triggered = true;
|
| 29 |
+
if (this._channel) {
|
| 30 |
+
this._channel.port1.postMessage(true);
|
| 31 |
+
} else {
|
| 32 |
+
setTimeout(() => {
|
| 33 |
+
this._triggered = false;
|
| 34 |
+
this._callback();
|
| 35 |
+
}, 0);
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
remove() {
|
| 41 |
+
delete this._channel;
|
| 42 |
+
this._callback = () => {};
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
export default ThrottledInvoker;
|
node_modules/mapbox-gl/src/util/tile_request_cache.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
import {warnOnce, parseCacheControl} from './util';
|
| 4 |
+
import window from './window';
|
| 5 |
+
|
| 6 |
+
import type Dispatcher from './dispatcher';
|
| 7 |
+
|
| 8 |
+
const CACHE_NAME = 'mapbox-tiles';
|
| 9 |
+
let cacheLimit = 500; // 50MB / (100KB/tile) ~= 500 tiles
|
| 10 |
+
let cacheCheckThreshold = 50;
|
| 11 |
+
|
| 12 |
+
const MIN_TIME_UNTIL_EXPIRY = 1000 * 60 * 7; // 7 minutes. Skip caching tiles with a short enough max age.
|
| 13 |
+
|
| 14 |
+
export type ResponseOptions = {
|
| 15 |
+
status: number,
|
| 16 |
+
statusText: string,
|
| 17 |
+
headers: window.Headers
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
// We're using a global shared cache object. Normally, requesting ad-hoc Cache objects is fine, but
|
| 21 |
+
// Safari has a memory leak in which it fails to release memory when requesting keys() from a Cache
|
| 22 |
+
// object. See https://bugs.webkit.org/show_bug.cgi?id=203991 for more information.
|
| 23 |
+
let sharedCache: ?Promise<Cache>;
|
| 24 |
+
|
| 25 |
+
function cacheOpen() {
|
| 26 |
+
if (window.caches && !sharedCache) {
|
| 27 |
+
sharedCache = window.caches.open(CACHE_NAME);
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
// We're never closing the cache, but our unit tests rely on changing out the global window.caches
|
| 32 |
+
// object, so we have a function specifically for unit tests that allows resetting the shared cache.
|
| 33 |
+
export function cacheClose() {
|
| 34 |
+
sharedCache = undefined;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
let responseConstructorSupportsReadableStream;
|
| 38 |
+
function prepareBody(response: Response, callback) {
|
| 39 |
+
if (responseConstructorSupportsReadableStream === undefined) {
|
| 40 |
+
try {
|
| 41 |
+
new Response(new ReadableStream()); // eslint-disable-line no-undef
|
| 42 |
+
responseConstructorSupportsReadableStream = true;
|
| 43 |
+
} catch (e) {
|
| 44 |
+
// Edge
|
| 45 |
+
responseConstructorSupportsReadableStream = false;
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
if (responseConstructorSupportsReadableStream) {
|
| 50 |
+
callback(response.body);
|
| 51 |
+
} else {
|
| 52 |
+
response.blob().then(callback);
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
export function cachePut(request: Request, response: Response, requestTime: number) {
|
| 57 |
+
cacheOpen();
|
| 58 |
+
if (!sharedCache) return;
|
| 59 |
+
|
| 60 |
+
const options: ResponseOptions = {
|
| 61 |
+
status: response.status,
|
| 62 |
+
statusText: response.statusText,
|
| 63 |
+
headers: new window.Headers()
|
| 64 |
+
};
|
| 65 |
+
response.headers.forEach((v, k) => options.headers.set(k, v));
|
| 66 |
+
|
| 67 |
+
const cacheControl = parseCacheControl(response.headers.get('Cache-Control') || '');
|
| 68 |
+
if (cacheControl['no-store']) {
|
| 69 |
+
return;
|
| 70 |
+
}
|
| 71 |
+
if (cacheControl['max-age']) {
|
| 72 |
+
options.headers.set('Expires', new Date(requestTime + cacheControl['max-age'] * 1000).toUTCString());
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
const timeUntilExpiry = new Date(options.headers.get('Expires')).getTime() - requestTime;
|
| 76 |
+
if (timeUntilExpiry < MIN_TIME_UNTIL_EXPIRY) return;
|
| 77 |
+
|
| 78 |
+
prepareBody(response, body => {
|
| 79 |
+
const clonedResponse = new window.Response(body, options);
|
| 80 |
+
|
| 81 |
+
cacheOpen();
|
| 82 |
+
if (!sharedCache) return;
|
| 83 |
+
sharedCache
|
| 84 |
+
.then(cache => cache.put(stripQueryParameters(request.url), clonedResponse))
|
| 85 |
+
.catch(e => warnOnce(e.message));
|
| 86 |
+
});
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
function stripQueryParameters(url: string) {
|
| 90 |
+
const start = url.indexOf('?');
|
| 91 |
+
return start < 0 ? url : url.slice(0, start);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
export function cacheGet(request: Request, callback: (error: ?any, response: ?Response, fresh: ?boolean) => void) {
|
| 95 |
+
cacheOpen();
|
| 96 |
+
if (!sharedCache) return callback(null);
|
| 97 |
+
|
| 98 |
+
const strippedURL = stripQueryParameters(request.url);
|
| 99 |
+
|
| 100 |
+
sharedCache
|
| 101 |
+
.then(cache => {
|
| 102 |
+
// manually strip URL instead of `ignoreSearch: true` because of a known
|
| 103 |
+
// performance issue in Chrome https://github.com/mapbox/mapbox-gl-js/issues/8431
|
| 104 |
+
cache.match(strippedURL)
|
| 105 |
+
.then(response => {
|
| 106 |
+
const fresh = isFresh(response);
|
| 107 |
+
|
| 108 |
+
// Reinsert into cache so that order of keys in the cache is the order of access.
|
| 109 |
+
// This line makes the cache a LRU instead of a FIFO cache.
|
| 110 |
+
cache.delete(strippedURL);
|
| 111 |
+
if (fresh) {
|
| 112 |
+
cache.put(strippedURL, response.clone());
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
callback(null, response, fresh);
|
| 116 |
+
})
|
| 117 |
+
.catch(callback);
|
| 118 |
+
})
|
| 119 |
+
.catch(callback);
|
| 120 |
+
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
function isFresh(response) {
|
| 124 |
+
if (!response) return false;
|
| 125 |
+
const expires = new Date(response.headers.get('Expires') || 0);
|
| 126 |
+
const cacheControl = parseCacheControl(response.headers.get('Cache-Control') || '');
|
| 127 |
+
return expires > Date.now() && !cacheControl['no-cache'];
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
// `Infinity` triggers a cache check after the first tile is loaded
|
| 131 |
+
// so that a check is run at least once on each page load.
|
| 132 |
+
let globalEntryCounter = Infinity;
|
| 133 |
+
|
| 134 |
+
// The cache check gets run on a worker. The reason for this is that
|
| 135 |
+
// profiling sometimes shows this as taking up significant time on the
|
| 136 |
+
// thread it gets called from. And sometimes it doesn't. It *may* be
|
| 137 |
+
// fine to run this on the main thread but out of caution this is being
|
| 138 |
+
// dispatched on a worker. This can be investigated further in the future.
|
| 139 |
+
export function cacheEntryPossiblyAdded(dispatcher: Dispatcher) {
|
| 140 |
+
globalEntryCounter++;
|
| 141 |
+
if (globalEntryCounter > cacheCheckThreshold) {
|
| 142 |
+
dispatcher.getActor().send('enforceCacheSizeLimit', cacheLimit);
|
| 143 |
+
globalEntryCounter = 0;
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
// runs on worker, see above comment
|
| 148 |
+
export function enforceCacheSizeLimit(limit: number) {
|
| 149 |
+
cacheOpen();
|
| 150 |
+
if (!sharedCache) return;
|
| 151 |
+
|
| 152 |
+
sharedCache
|
| 153 |
+
.then(cache => {
|
| 154 |
+
cache.keys().then(keys => {
|
| 155 |
+
for (let i = 0; i < keys.length - limit; i++) {
|
| 156 |
+
cache.delete(keys[i]);
|
| 157 |
+
}
|
| 158 |
+
});
|
| 159 |
+
});
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
export function clearTileCache(callback?: (err: ?Error) => void) {
|
| 163 |
+
const promise = window.caches.delete(CACHE_NAME);
|
| 164 |
+
if (callback) {
|
| 165 |
+
promise.catch(callback).then(() => callback());
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
export function setCacheLimits(limit: number, checkThreshold: number) {
|
| 170 |
+
cacheLimit = limit;
|
| 171 |
+
cacheCheckThreshold = checkThreshold;
|
| 172 |
+
}
|
node_modules/mapbox-gl/src/util/util.js
ADDED
|
@@ -0,0 +1,524 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
import UnitBezier from '@mapbox/unitbezier';
|
| 4 |
+
|
| 5 |
+
import Point from '@mapbox/point-geometry';
|
| 6 |
+
import window from './window';
|
| 7 |
+
|
| 8 |
+
import type {Callback} from '../types/callback';
|
| 9 |
+
|
| 10 |
+
// Number.MAX_SAFE_INTEGER not available in IE
|
| 11 |
+
export const MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* @module util
|
| 15 |
+
* @private
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Given a value `t` that varies between 0 and 1, return
|
| 20 |
+
* an interpolation function that eases between 0 and 1 in a pleasing
|
| 21 |
+
* cubic in-out fashion.
|
| 22 |
+
*
|
| 23 |
+
* @private
|
| 24 |
+
*/
|
| 25 |
+
export function easeCubicInOut(t: number): number {
|
| 26 |
+
if (t <= 0) return 0;
|
| 27 |
+
if (t >= 1) return 1;
|
| 28 |
+
const t2 = t * t,
|
| 29 |
+
t3 = t2 * t;
|
| 30 |
+
return 4 * (t < 0.5 ? t3 : 3 * (t - t2) + t3 - 0.75);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* Given given (x, y), (x1, y1) control points for a bezier curve,
|
| 35 |
+
* return a function that interpolates along that curve.
|
| 36 |
+
*
|
| 37 |
+
* @param p1x control point 1 x coordinate
|
| 38 |
+
* @param p1y control point 1 y coordinate
|
| 39 |
+
* @param p2x control point 2 x coordinate
|
| 40 |
+
* @param p2y control point 2 y coordinate
|
| 41 |
+
* @private
|
| 42 |
+
*/
|
| 43 |
+
export function bezier(p1x: number, p1y: number, p2x: number, p2y: number): (t: number) => number {
|
| 44 |
+
const bezier = new UnitBezier(p1x, p1y, p2x, p2y);
|
| 45 |
+
return function(t: number) {
|
| 46 |
+
return bezier.solve(t);
|
| 47 |
+
};
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* A default bezier-curve powered easing function with
|
| 52 |
+
* control points (0.25, 0.1) and (0.25, 1)
|
| 53 |
+
*
|
| 54 |
+
* @private
|
| 55 |
+
*/
|
| 56 |
+
export const ease = bezier(0.25, 0.1, 0.25, 1);
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* constrain n to the given range via min + max
|
| 60 |
+
*
|
| 61 |
+
* @param n value
|
| 62 |
+
* @param min the minimum value to be returned
|
| 63 |
+
* @param max the maximum value to be returned
|
| 64 |
+
* @returns the clamped value
|
| 65 |
+
* @private
|
| 66 |
+
*/
|
| 67 |
+
export function clamp(n: number, min: number, max: number): number {
|
| 68 |
+
return Math.min(max, Math.max(min, n));
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* constrain n to the given range, excluding the minimum, via modular arithmetic
|
| 73 |
+
*
|
| 74 |
+
* @param n value
|
| 75 |
+
* @param min the minimum value to be returned, exclusive
|
| 76 |
+
* @param max the maximum value to be returned, inclusive
|
| 77 |
+
* @returns constrained number
|
| 78 |
+
* @private
|
| 79 |
+
*/
|
| 80 |
+
export function wrap(n: number, min: number, max: number): number {
|
| 81 |
+
const d = max - min;
|
| 82 |
+
const w = ((n - min) % d + d) % d + min;
|
| 83 |
+
return (w === min) ? max : w;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/*
|
| 87 |
+
* Call an asynchronous function on an array of arguments,
|
| 88 |
+
* calling `callback` with the completed results of all calls.
|
| 89 |
+
*
|
| 90 |
+
* @param array input to each call of the async function.
|
| 91 |
+
* @param fn an async function with signature (data, callback)
|
| 92 |
+
* @param callback a callback run after all async work is done.
|
| 93 |
+
* called with an array, containing the results of each async call.
|
| 94 |
+
* @private
|
| 95 |
+
*/
|
| 96 |
+
export function asyncAll<Item, Result>(
|
| 97 |
+
array: Array<Item>,
|
| 98 |
+
fn: (item: Item, fnCallback: Callback<Result>) => void,
|
| 99 |
+
callback: Callback<Array<Result>>
|
| 100 |
+
) {
|
| 101 |
+
if (!array.length) { return callback(null, []); }
|
| 102 |
+
let remaining = array.length;
|
| 103 |
+
const results = new Array(array.length);
|
| 104 |
+
let error = null;
|
| 105 |
+
array.forEach((item, i) => {
|
| 106 |
+
fn(item, (err, result) => {
|
| 107 |
+
if (err) error = err;
|
| 108 |
+
results[i] = ((result: any): Result); // https://github.com/facebook/flow/issues/2123
|
| 109 |
+
if (--remaining === 0) callback(error, results);
|
| 110 |
+
});
|
| 111 |
+
});
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/*
|
| 115 |
+
* Polyfill for Object.values. Not fully spec compliant, but we don't
|
| 116 |
+
* need it to be.
|
| 117 |
+
*
|
| 118 |
+
* @private
|
| 119 |
+
*/
|
| 120 |
+
export function values<T>(obj: {[key: string]: T}): Array<T> {
|
| 121 |
+
const result = [];
|
| 122 |
+
for (const k in obj) {
|
| 123 |
+
result.push(obj[k]);
|
| 124 |
+
}
|
| 125 |
+
return result;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
/*
|
| 129 |
+
* Compute the difference between the keys in one object and the keys
|
| 130 |
+
* in another object.
|
| 131 |
+
*
|
| 132 |
+
* @returns keys difference
|
| 133 |
+
* @private
|
| 134 |
+
*/
|
| 135 |
+
export function keysDifference<S, T>(obj: {[key: string]: S}, other: {[key: string]: T}): Array<string> {
|
| 136 |
+
const difference = [];
|
| 137 |
+
for (const i in obj) {
|
| 138 |
+
if (!(i in other)) {
|
| 139 |
+
difference.push(i);
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
return difference;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/**
|
| 146 |
+
* Given a destination object and optionally many source objects,
|
| 147 |
+
* copy all properties from the source objects into the destination.
|
| 148 |
+
* The last source object given overrides properties from previous
|
| 149 |
+
* source objects.
|
| 150 |
+
*
|
| 151 |
+
* @param dest destination object
|
| 152 |
+
* @param sources sources from which properties are pulled
|
| 153 |
+
* @private
|
| 154 |
+
*/
|
| 155 |
+
export function extend(dest: Object, ...sources: Array<?Object>): Object {
|
| 156 |
+
for (const src of sources) {
|
| 157 |
+
for (const k in src) {
|
| 158 |
+
dest[k] = src[k];
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
return dest;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/**
|
| 165 |
+
* Given an object and a number of properties as strings, return version
|
| 166 |
+
* of that object with only those properties.
|
| 167 |
+
*
|
| 168 |
+
* @param src the object
|
| 169 |
+
* @param properties an array of property names chosen
|
| 170 |
+
* to appear on the resulting object.
|
| 171 |
+
* @returns object with limited properties.
|
| 172 |
+
* @example
|
| 173 |
+
* var foo = { name: 'Charlie', age: 10 };
|
| 174 |
+
* var justName = pick(foo, ['name']);
|
| 175 |
+
* // justName = { name: 'Charlie' }
|
| 176 |
+
* @private
|
| 177 |
+
*/
|
| 178 |
+
export function pick(src: Object, properties: Array<string>): Object {
|
| 179 |
+
const result = {};
|
| 180 |
+
for (let i = 0; i < properties.length; i++) {
|
| 181 |
+
const k = properties[i];
|
| 182 |
+
if (k in src) {
|
| 183 |
+
result[k] = src[k];
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
return result;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
let id = 1;
|
| 190 |
+
|
| 191 |
+
/**
|
| 192 |
+
* Return a unique numeric id, starting at 1 and incrementing with
|
| 193 |
+
* each call.
|
| 194 |
+
*
|
| 195 |
+
* @returns unique numeric id.
|
| 196 |
+
* @private
|
| 197 |
+
*/
|
| 198 |
+
export function uniqueId(): number {
|
| 199 |
+
return id++;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
/**
|
| 203 |
+
* Return a random UUID (v4). Taken from: https://gist.github.com/jed/982883
|
| 204 |
+
* @private
|
| 205 |
+
*/
|
| 206 |
+
export function uuid(): string {
|
| 207 |
+
function b(a) {
|
| 208 |
+
return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) :
|
| 209 |
+
//$FlowFixMe: Flow doesn't like the implied array literal conversion here
|
| 210 |
+
([1e7] + -[1e3] + -4e3 + -8e3 + -1e11).replace(/[018]/g, b);
|
| 211 |
+
}
|
| 212 |
+
return b();
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
/**
|
| 216 |
+
* Return whether a given value is a power of two
|
| 217 |
+
* @private
|
| 218 |
+
*/
|
| 219 |
+
export function isPowerOfTwo(value: number): boolean {
|
| 220 |
+
return (Math.log(value) / Math.LN2) % 1 === 0;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
/**
|
| 224 |
+
* Return the next power of two, or the input value if already a power of two
|
| 225 |
+
* @private
|
| 226 |
+
*/
|
| 227 |
+
export function nextPowerOfTwo(value: number): number {
|
| 228 |
+
if (value <= 1) return 1;
|
| 229 |
+
return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
/**
|
| 233 |
+
* Validate a string to match UUID(v4) of the
|
| 234 |
+
* form: xxxxxxxx-xxxx-4xxx-[89ab]xxx-xxxxxxxxxxxx
|
| 235 |
+
* @param str string to validate.
|
| 236 |
+
* @private
|
| 237 |
+
*/
|
| 238 |
+
export function validateUuid(str: ?string): boolean {
|
| 239 |
+
return str ? /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str) : false;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
/**
|
| 243 |
+
* Given an array of member function names as strings, replace all of them
|
| 244 |
+
* with bound versions that will always refer to `context` as `this`. This
|
| 245 |
+
* is useful for classes where otherwise event bindings would reassign
|
| 246 |
+
* `this` to the evented object or some other value: this lets you ensure
|
| 247 |
+
* the `this` value always.
|
| 248 |
+
*
|
| 249 |
+
* @param fns list of member function names
|
| 250 |
+
* @param context the context value
|
| 251 |
+
* @example
|
| 252 |
+
* function MyClass() {
|
| 253 |
+
* bindAll(['ontimer'], this);
|
| 254 |
+
* this.name = 'Tom';
|
| 255 |
+
* }
|
| 256 |
+
* MyClass.prototype.ontimer = function() {
|
| 257 |
+
* alert(this.name);
|
| 258 |
+
* };
|
| 259 |
+
* var myClass = new MyClass();
|
| 260 |
+
* setTimeout(myClass.ontimer, 100);
|
| 261 |
+
* @private
|
| 262 |
+
*/
|
| 263 |
+
export function bindAll(fns: Array<string>, context: Object): void {
|
| 264 |
+
fns.forEach((fn) => {
|
| 265 |
+
if (!context[fn]) { return; }
|
| 266 |
+
context[fn] = context[fn].bind(context);
|
| 267 |
+
});
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
/**
|
| 271 |
+
* Determine if a string ends with a particular substring
|
| 272 |
+
*
|
| 273 |
+
* @private
|
| 274 |
+
*/
|
| 275 |
+
export function endsWith(string: string, suffix: string): boolean {
|
| 276 |
+
return string.indexOf(suffix, string.length - suffix.length) !== -1;
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
/**
|
| 280 |
+
* Create an object by mapping all the values of an existing object while
|
| 281 |
+
* preserving their keys.
|
| 282 |
+
*
|
| 283 |
+
* @private
|
| 284 |
+
*/
|
| 285 |
+
export function mapObject(input: Object, iterator: Function, context?: Object): Object {
|
| 286 |
+
const output = {};
|
| 287 |
+
for (const key in input) {
|
| 288 |
+
output[key] = iterator.call(context || this, input[key], key, input);
|
| 289 |
+
}
|
| 290 |
+
return output;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
/**
|
| 294 |
+
* Create an object by filtering out values of an existing object.
|
| 295 |
+
*
|
| 296 |
+
* @private
|
| 297 |
+
*/
|
| 298 |
+
export function filterObject(input: Object, iterator: Function, context?: Object): Object {
|
| 299 |
+
const output = {};
|
| 300 |
+
for (const key in input) {
|
| 301 |
+
if (iterator.call(context || this, input[key], key, input)) {
|
| 302 |
+
output[key] = input[key];
|
| 303 |
+
}
|
| 304 |
+
}
|
| 305 |
+
return output;
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
import deepEqual from '../style-spec/util/deep_equal';
|
| 309 |
+
export {deepEqual};
|
| 310 |
+
|
| 311 |
+
/**
|
| 312 |
+
* Deeply clones two objects.
|
| 313 |
+
*
|
| 314 |
+
* @private
|
| 315 |
+
*/
|
| 316 |
+
export function clone<T>(input: T): T {
|
| 317 |
+
if (Array.isArray(input)) {
|
| 318 |
+
return input.map(clone);
|
| 319 |
+
} else if (typeof input === 'object' && input) {
|
| 320 |
+
return ((mapObject(input, clone): any): T);
|
| 321 |
+
} else {
|
| 322 |
+
return input;
|
| 323 |
+
}
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
/**
|
| 327 |
+
* Check if two arrays have at least one common element.
|
| 328 |
+
*
|
| 329 |
+
* @private
|
| 330 |
+
*/
|
| 331 |
+
export function arraysIntersect<T>(a: Array<T>, b: Array<T>): boolean {
|
| 332 |
+
for (let l = 0; l < a.length; l++) {
|
| 333 |
+
if (b.indexOf(a[l]) >= 0) return true;
|
| 334 |
+
}
|
| 335 |
+
return false;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
/**
|
| 339 |
+
* Print a warning message to the console and ensure duplicate warning messages
|
| 340 |
+
* are not printed.
|
| 341 |
+
*
|
| 342 |
+
* @private
|
| 343 |
+
*/
|
| 344 |
+
const warnOnceHistory: {[key: string]: boolean} = {};
|
| 345 |
+
|
| 346 |
+
export function warnOnce(message: string): void {
|
| 347 |
+
if (!warnOnceHistory[message]) {
|
| 348 |
+
// console isn't defined in some WebWorkers, see #2558
|
| 349 |
+
if (typeof console !== "undefined") console.warn(message);
|
| 350 |
+
warnOnceHistory[message] = true;
|
| 351 |
+
}
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
/**
|
| 355 |
+
* Indicates if the provided Points are in a counter clockwise (true) or clockwise (false) order
|
| 356 |
+
*
|
| 357 |
+
* @private
|
| 358 |
+
* @returns true for a counter clockwise set of points
|
| 359 |
+
*/
|
| 360 |
+
// http://bryceboe.com/2006/10/23/line-segment-intersection-algorithm/
|
| 361 |
+
export function isCounterClockwise(a: Point, b: Point, c: Point): boolean {
|
| 362 |
+
return (c.y - a.y) * (b.x - a.x) > (b.y - a.y) * (c.x - a.x);
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
/**
|
| 366 |
+
* Returns the signed area for the polygon ring. Postive areas are exterior rings and
|
| 367 |
+
* have a clockwise winding. Negative areas are interior rings and have a counter clockwise
|
| 368 |
+
* ordering.
|
| 369 |
+
*
|
| 370 |
+
* @private
|
| 371 |
+
* @param ring Exterior or interior ring
|
| 372 |
+
*/
|
| 373 |
+
export function calculateSignedArea(ring: Array<Point>): number {
|
| 374 |
+
let sum = 0;
|
| 375 |
+
for (let i = 0, len = ring.length, j = len - 1, p1, p2; i < len; j = i++) {
|
| 376 |
+
p1 = ring[i];
|
| 377 |
+
p2 = ring[j];
|
| 378 |
+
sum += (p2.x - p1.x) * (p1.y + p2.y);
|
| 379 |
+
}
|
| 380 |
+
return sum;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
/**
|
| 384 |
+
* Detects closed polygons, first + last point are equal
|
| 385 |
+
*
|
| 386 |
+
* @private
|
| 387 |
+
* @param points array of points
|
| 388 |
+
* @return true if the points are a closed polygon
|
| 389 |
+
*/
|
| 390 |
+
export function isClosedPolygon(points: Array<Point>): boolean {
|
| 391 |
+
// If it is 2 points that are the same then it is a point
|
| 392 |
+
// If it is 3 points with start and end the same then it is a line
|
| 393 |
+
if (points.length < 4)
|
| 394 |
+
return false;
|
| 395 |
+
|
| 396 |
+
const p1 = points[0];
|
| 397 |
+
const p2 = points[points.length - 1];
|
| 398 |
+
|
| 399 |
+
if (Math.abs(p1.x - p2.x) > 0 ||
|
| 400 |
+
Math.abs(p1.y - p2.y) > 0) {
|
| 401 |
+
return false;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
// polygon simplification can produce polygons with zero area and more than 3 points
|
| 405 |
+
return Math.abs(calculateSignedArea(points)) > 0.01;
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
/**
|
| 409 |
+
* Converts spherical coordinates to cartesian coordinates.
|
| 410 |
+
*
|
| 411 |
+
* @private
|
| 412 |
+
* @param spherical Spherical coordinates, in [radial, azimuthal, polar]
|
| 413 |
+
* @return cartesian coordinates in [x, y, z]
|
| 414 |
+
*/
|
| 415 |
+
|
| 416 |
+
export function sphericalToCartesian([r, azimuthal, polar]: [number, number, number]): {x: number, y: number, z: number} {
|
| 417 |
+
// We abstract "north"/"up" (compass-wise) to be 0° when really this is 90° (π/2):
|
| 418 |
+
// correct for that here
|
| 419 |
+
azimuthal += 90;
|
| 420 |
+
|
| 421 |
+
// Convert azimuthal and polar angles to radians
|
| 422 |
+
azimuthal *= Math.PI / 180;
|
| 423 |
+
polar *= Math.PI / 180;
|
| 424 |
+
|
| 425 |
+
return {
|
| 426 |
+
x: r * Math.cos(azimuthal) * Math.sin(polar),
|
| 427 |
+
y: r * Math.sin(azimuthal) * Math.sin(polar),
|
| 428 |
+
z: r * Math.cos(polar)
|
| 429 |
+
};
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
/* global self, WorkerGlobalScope */
|
| 433 |
+
/**
|
| 434 |
+
* Retuns true if the when run in the web-worker context.
|
| 435 |
+
*
|
| 436 |
+
* @private
|
| 437 |
+
* @returns {boolean}
|
| 438 |
+
*/
|
| 439 |
+
export function isWorker(): boolean {
|
| 440 |
+
return typeof WorkerGlobalScope !== 'undefined' && typeof self !== 'undefined' &&
|
| 441 |
+
self instanceof WorkerGlobalScope;
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
/**
|
| 445 |
+
* Parses data from 'Cache-Control' headers.
|
| 446 |
+
*
|
| 447 |
+
* @private
|
| 448 |
+
* @param cacheControl Value of 'Cache-Control' header
|
| 449 |
+
* @return object containing parsed header info.
|
| 450 |
+
*/
|
| 451 |
+
|
| 452 |
+
export function parseCacheControl(cacheControl: string): Object {
|
| 453 |
+
// Taken from [Wreck](https://github.com/hapijs/wreck)
|
| 454 |
+
const re = /(?:^|(?:\s*\,\s*))([^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)(?:\=(?:([^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)|(?:\"((?:[^"\\]|\\.)*)\")))?/g;
|
| 455 |
+
|
| 456 |
+
const header = {};
|
| 457 |
+
cacheControl.replace(re, ($0, $1, $2, $3) => {
|
| 458 |
+
const value = $2 || $3;
|
| 459 |
+
header[$1] = value ? value.toLowerCase() : true;
|
| 460 |
+
return '';
|
| 461 |
+
});
|
| 462 |
+
|
| 463 |
+
if (header['max-age']) {
|
| 464 |
+
const maxAge = parseInt(header['max-age'], 10);
|
| 465 |
+
if (isNaN(maxAge)) delete header['max-age'];
|
| 466 |
+
else header['max-age'] = maxAge;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
return header;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
let _isSafari = null;
|
| 473 |
+
|
| 474 |
+
/**
|
| 475 |
+
* Returns true when run in WebKit derived browsers.
|
| 476 |
+
* This is used as a workaround for a memory leak in Safari caused by using Transferable objects to
|
| 477 |
+
* transfer data between WebWorkers and the main thread.
|
| 478 |
+
* https://github.com/mapbox/mapbox-gl-js/issues/8771
|
| 479 |
+
*
|
| 480 |
+
* This should be removed once the underlying Safari issue is fixed.
|
| 481 |
+
*
|
| 482 |
+
* @private
|
| 483 |
+
* @param scope {WindowOrWorkerGlobalScope} Since this function is used both on the main thread and WebWorker context,
|
| 484 |
+
* let the calling scope pass in the global scope object.
|
| 485 |
+
* @returns {boolean}
|
| 486 |
+
*/
|
| 487 |
+
export function isSafari(scope: any): boolean {
|
| 488 |
+
if (_isSafari == null) {
|
| 489 |
+
const userAgent = scope.navigator ? scope.navigator.userAgent : null;
|
| 490 |
+
_isSafari = !!scope.safari ||
|
| 491 |
+
!!(userAgent && (/\b(iPad|iPhone|iPod)\b/.test(userAgent) || (!!userAgent.match('Safari') && !userAgent.match('Chrome'))));
|
| 492 |
+
}
|
| 493 |
+
return _isSafari;
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
export function storageAvailable(type: string): boolean {
|
| 497 |
+
try {
|
| 498 |
+
const storage = window[type];
|
| 499 |
+
storage.setItem('_mapbox_test_', 1);
|
| 500 |
+
storage.removeItem('_mapbox_test_');
|
| 501 |
+
return true;
|
| 502 |
+
} catch (e) {
|
| 503 |
+
return false;
|
| 504 |
+
}
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
// The following methods are from https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
|
| 508 |
+
//Unicode compliant base64 encoder for strings
|
| 509 |
+
export function b64EncodeUnicode(str: string) {
|
| 510 |
+
return window.btoa(
|
| 511 |
+
encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
|
| 512 |
+
(match, p1) => {
|
| 513 |
+
return String.fromCharCode(Number('0x' + p1)); //eslint-disable-line
|
| 514 |
+
}
|
| 515 |
+
)
|
| 516 |
+
);
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
// Unicode compliant decoder for base64-encoded strings
|
| 520 |
+
export function b64DecodeUnicode(str: string) {
|
| 521 |
+
return decodeURIComponent(window.atob(str).split('').map((c) => {
|
| 522 |
+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); //eslint-disable-line
|
| 523 |
+
}).join(''));
|
| 524 |
+
}
|
node_modules/mapbox-gl/src/util/vectortile_to_geojson.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
import type {GeoJSONGeometry} from '@mapbox/geojson-types';
|
| 3 |
+
|
| 4 |
+
class Feature {
|
| 5 |
+
type: 'Feature';
|
| 6 |
+
_geometry: ?GeoJSONGeometry;
|
| 7 |
+
properties: {};
|
| 8 |
+
id: number | string | void;
|
| 9 |
+
|
| 10 |
+
_vectorTileFeature: VectorTileFeature;
|
| 11 |
+
|
| 12 |
+
constructor(vectorTileFeature: VectorTileFeature, z: number, x: number, y: number, id: string | number | void) {
|
| 13 |
+
this.type = 'Feature';
|
| 14 |
+
|
| 15 |
+
this._vectorTileFeature = vectorTileFeature;
|
| 16 |
+
(vectorTileFeature: any)._z = z;
|
| 17 |
+
(vectorTileFeature: any)._x = x;
|
| 18 |
+
(vectorTileFeature: any)._y = y;
|
| 19 |
+
|
| 20 |
+
this.properties = vectorTileFeature.properties;
|
| 21 |
+
this.id = id;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
get geometry(): ?GeoJSONGeometry {
|
| 25 |
+
if (this._geometry === undefined) {
|
| 26 |
+
this._geometry = this._vectorTileFeature.toGeoJSON(
|
| 27 |
+
(this._vectorTileFeature: any)._x,
|
| 28 |
+
(this._vectorTileFeature: any)._y,
|
| 29 |
+
(this._vectorTileFeature: any)._z).geometry;
|
| 30 |
+
}
|
| 31 |
+
return this._geometry;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
set geometry(g: ?GeoJSONGeometry) {
|
| 35 |
+
this._geometry = g;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
toJSON() {
|
| 39 |
+
const json = {
|
| 40 |
+
geometry: this.geometry
|
| 41 |
+
};
|
| 42 |
+
for (const i in this) {
|
| 43 |
+
if (i === '_geometry' || i === '_vectorTileFeature') continue;
|
| 44 |
+
json[i] = (this: any)[i];
|
| 45 |
+
}
|
| 46 |
+
return json;
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
export default Feature;
|
node_modules/mapbox-gl/src/util/verticalize_punctuation.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
import {
|
| 4 |
+
charHasRotatedVerticalOrientation,
|
| 5 |
+
} from './script_detection';
|
| 6 |
+
|
| 7 |
+
export const verticalizedCharacterMap = {
|
| 8 |
+
'!': '︕',
|
| 9 |
+
'#': '#',
|
| 10 |
+
'$': '$',
|
| 11 |
+
'%': '%',
|
| 12 |
+
'&': '&',
|
| 13 |
+
'(': '︵',
|
| 14 |
+
')': '︶',
|
| 15 |
+
'*': '*',
|
| 16 |
+
'+': '+',
|
| 17 |
+
',': '︐',
|
| 18 |
+
'-': '︲',
|
| 19 |
+
'.': '・',
|
| 20 |
+
'/': '/',
|
| 21 |
+
':': '︓',
|
| 22 |
+
';': '︔',
|
| 23 |
+
'<': '︿',
|
| 24 |
+
'=': '=',
|
| 25 |
+
'>': '﹀',
|
| 26 |
+
'?': '︖',
|
| 27 |
+
'@': '@',
|
| 28 |
+
'[': '﹇',
|
| 29 |
+
'\\': '\',
|
| 30 |
+
']': '﹈',
|
| 31 |
+
'^': '^',
|
| 32 |
+
'_': '︳',
|
| 33 |
+
'`': '`',
|
| 34 |
+
'{': '︷',
|
| 35 |
+
'|': '―',
|
| 36 |
+
'}': '︸',
|
| 37 |
+
'~': '~',
|
| 38 |
+
'¢': '¢',
|
| 39 |
+
'£': '£',
|
| 40 |
+
'¥': '¥',
|
| 41 |
+
'¦': '¦',
|
| 42 |
+
'¬': '¬',
|
| 43 |
+
'¯': ' ̄',
|
| 44 |
+
'–': '︲',
|
| 45 |
+
'—': '︱',
|
| 46 |
+
'‘': '﹃',
|
| 47 |
+
'’': '﹄',
|
| 48 |
+
'“': '﹁',
|
| 49 |
+
'”': '﹂',
|
| 50 |
+
'…': '︙',
|
| 51 |
+
'‧': '・',
|
| 52 |
+
'₩': '₩',
|
| 53 |
+
'、': '︑',
|
| 54 |
+
'。': '︒',
|
| 55 |
+
'〈': '︿',
|
| 56 |
+
'〉': '﹀',
|
| 57 |
+
'《': '︽',
|
| 58 |
+
'》': '︾',
|
| 59 |
+
'「': '﹁',
|
| 60 |
+
'」': '﹂',
|
| 61 |
+
'『': '﹃',
|
| 62 |
+
'』': '﹄',
|
| 63 |
+
'【': '︻',
|
| 64 |
+
'】': '︼',
|
| 65 |
+
'〔': '︹',
|
| 66 |
+
'〕': '︺',
|
| 67 |
+
'〖': '︗',
|
| 68 |
+
'〗': '︘',
|
| 69 |
+
'!': '︕',
|
| 70 |
+
'(': '︵',
|
| 71 |
+
')': '︶',
|
| 72 |
+
',': '︐',
|
| 73 |
+
'-': '︲',
|
| 74 |
+
'.': '・',
|
| 75 |
+
':': '︓',
|
| 76 |
+
';': '︔',
|
| 77 |
+
'<': '︿',
|
| 78 |
+
'>': '﹀',
|
| 79 |
+
'?': '︖',
|
| 80 |
+
'[': '﹇',
|
| 81 |
+
']': '﹈',
|
| 82 |
+
'_': '︳',
|
| 83 |
+
'{': '︷',
|
| 84 |
+
'|': '―',
|
| 85 |
+
'}': '︸',
|
| 86 |
+
'⦅': '︵',
|
| 87 |
+
'⦆': '︶',
|
| 88 |
+
'。': '︒',
|
| 89 |
+
'「': '﹁',
|
| 90 |
+
'」': '﹂'
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
export default function verticalizePunctuation(input: string) {
|
| 94 |
+
let output = '';
|
| 95 |
+
|
| 96 |
+
for (let i = 0; i < input.length; i++) {
|
| 97 |
+
const nextCharCode = input.charCodeAt(i + 1) || null;
|
| 98 |
+
const prevCharCode = input.charCodeAt(i - 1) || null;
|
| 99 |
+
|
| 100 |
+
const canReplacePunctuation = (
|
| 101 |
+
(!nextCharCode || !charHasRotatedVerticalOrientation(nextCharCode) || verticalizedCharacterMap[input[i + 1]]) &&
|
| 102 |
+
(!prevCharCode || !charHasRotatedVerticalOrientation(prevCharCode) || verticalizedCharacterMap[input[i - 1]])
|
| 103 |
+
);
|
| 104 |
+
|
| 105 |
+
if (canReplacePunctuation && verticalizedCharacterMap[input[i]]) {
|
| 106 |
+
output += verticalizedCharacterMap[input[i]];
|
| 107 |
+
} else {
|
| 108 |
+
output += input[i];
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
return output;
|
| 113 |
+
}
|
| 114 |
+
|
node_modules/mapbox-gl/src/util/web_worker.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
// This file is intended for use in the GL-JS test suite
|
| 4 |
+
// It implements a MessageBus main thread interface for use in Node environments
|
| 5 |
+
// In a browser environment, this file is replaced with ./src/util/browser/web_worker.js
|
| 6 |
+
// when Rollup builds the main bundle.
|
| 7 |
+
// See package.json#browser
|
| 8 |
+
|
| 9 |
+
import Worker from '../source/worker';
|
| 10 |
+
|
| 11 |
+
import type {WorkerSource} from '../source/worker_source';
|
| 12 |
+
|
| 13 |
+
type MessageListener = ({data: Object}) => mixed;
|
| 14 |
+
|
| 15 |
+
// The main thread interface. Provided by Worker in a browser environment,
|
| 16 |
+
// and MessageBus below in a node environment.
|
| 17 |
+
export interface WorkerInterface {
|
| 18 |
+
addEventListener(type: 'message', listener: MessageListener): void;
|
| 19 |
+
removeEventListener(type: 'message', listener: MessageListener): void;
|
| 20 |
+
postMessage(message: any): void;
|
| 21 |
+
terminate(): void;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
export interface WorkerGlobalScopeInterface {
|
| 25 |
+
importScripts(...urls: Array<string>): void;
|
| 26 |
+
|
| 27 |
+
registerWorkerSource: (string, Class<WorkerSource>) => void,
|
| 28 |
+
registerRTLTextPlugin: (_: any) => void
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
class MessageBus implements WorkerInterface, WorkerGlobalScopeInterface {
|
| 32 |
+
addListeners: Array<MessageListener>;
|
| 33 |
+
postListeners: Array<MessageListener>;
|
| 34 |
+
target: MessageBus;
|
| 35 |
+
registerWorkerSource: *;
|
| 36 |
+
registerRTLTextPlugin: *;
|
| 37 |
+
|
| 38 |
+
constructor(addListeners: Array<MessageListener>, postListeners: Array<MessageListener>) {
|
| 39 |
+
this.addListeners = addListeners;
|
| 40 |
+
this.postListeners = postListeners;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
addEventListener(event: 'message', callback: MessageListener) {
|
| 44 |
+
if (event === 'message') {
|
| 45 |
+
this.addListeners.push(callback);
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
removeEventListener(event: 'message', callback: MessageListener) {
|
| 50 |
+
const i = this.addListeners.indexOf(callback);
|
| 51 |
+
if (i >= 0) {
|
| 52 |
+
this.addListeners.splice(i, 1);
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
postMessage(data: Object) {
|
| 57 |
+
setImmediate(() => {
|
| 58 |
+
try {
|
| 59 |
+
for (const listener of this.postListeners) {
|
| 60 |
+
listener({data, target: this.target});
|
| 61 |
+
}
|
| 62 |
+
} catch (e) {
|
| 63 |
+
console.error(e);
|
| 64 |
+
}
|
| 65 |
+
});
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
terminate() {
|
| 69 |
+
this.addListeners.splice(0, this.addListeners.length);
|
| 70 |
+
this.postListeners.splice(0, this.postListeners.length);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
importScripts() {}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
export default function WebWorker(): WorkerInterface {
|
| 77 |
+
const parentListeners = [],
|
| 78 |
+
workerListeners = [],
|
| 79 |
+
parentBus = new MessageBus(workerListeners, parentListeners),
|
| 80 |
+
workerBus = new MessageBus(parentListeners, workerListeners);
|
| 81 |
+
|
| 82 |
+
parentBus.target = workerBus;
|
| 83 |
+
workerBus.target = parentBus;
|
| 84 |
+
|
| 85 |
+
new WebWorker.Worker(workerBus);
|
| 86 |
+
|
| 87 |
+
return parentBus;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
// expose to allow stubbing in unit tests
|
| 91 |
+
WebWorker.Worker = Worker;
|
node_modules/mapbox-gl/src/util/web_worker_transfer.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
import assert from 'assert';
|
| 4 |
+
|
| 5 |
+
import Grid from 'grid-index';
|
| 6 |
+
import Color from '../style-spec/util/color';
|
| 7 |
+
import {StylePropertyFunction, StyleExpression, ZoomDependentExpression, ZoomConstantExpression} from '../style-spec/expression';
|
| 8 |
+
import CompoundExpression from '../style-spec/expression/compound_expression';
|
| 9 |
+
import expressions from '../style-spec/expression/definitions';
|
| 10 |
+
import ResolvedImage from '../style-spec/expression/types/resolved_image';
|
| 11 |
+
import window from './window';
|
| 12 |
+
const {ImageData, ImageBitmap} = window;
|
| 13 |
+
|
| 14 |
+
import type {Transferable} from '../types/transferable';
|
| 15 |
+
|
| 16 |
+
type SerializedObject = {[_: string]: Serialized }; // eslint-disable-line
|
| 17 |
+
export type Serialized =
|
| 18 |
+
| null
|
| 19 |
+
| void
|
| 20 |
+
| boolean
|
| 21 |
+
| number
|
| 22 |
+
| string
|
| 23 |
+
| Boolean
|
| 24 |
+
| Number
|
| 25 |
+
| String
|
| 26 |
+
| Date
|
| 27 |
+
| RegExp
|
| 28 |
+
| ArrayBuffer
|
| 29 |
+
| $ArrayBufferView
|
| 30 |
+
| ImageData
|
| 31 |
+
| Array<Serialized>
|
| 32 |
+
| SerializedObject;
|
| 33 |
+
|
| 34 |
+
type Registry = {
|
| 35 |
+
[_: string]: {
|
| 36 |
+
klass: Class<any>,
|
| 37 |
+
omit: $ReadOnlyArray<string>,
|
| 38 |
+
shallow: $ReadOnlyArray<string>
|
| 39 |
+
}
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
type RegisterOptions<T> = {
|
| 43 |
+
omit?: $ReadOnlyArray<$Keys<T>>,
|
| 44 |
+
shallow?: $ReadOnlyArray<$Keys<T>>
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
const registry: Registry = {};
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Register the given class as serializable.
|
| 51 |
+
*
|
| 52 |
+
* @param options
|
| 53 |
+
* @param options.omit List of properties to omit from serialization (e.g., cached/computed properties)
|
| 54 |
+
* @param options.shallow List of properties that should be serialized by a simple shallow copy, rather than by a recursive call to serialize().
|
| 55 |
+
*
|
| 56 |
+
* @private
|
| 57 |
+
*/
|
| 58 |
+
export function register<T: any>(name: string, klass: Class<T>, options: RegisterOptions<T> = {}) {
|
| 59 |
+
assert(!registry[name], `${name} is already registered.`);
|
| 60 |
+
(Object.defineProperty: any)(klass, '_classRegistryKey', {
|
| 61 |
+
value: name,
|
| 62 |
+
writeable: false
|
| 63 |
+
});
|
| 64 |
+
registry[name] = {
|
| 65 |
+
klass,
|
| 66 |
+
omit: options.omit || [],
|
| 67 |
+
shallow: options.shallow || []
|
| 68 |
+
};
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
register('Object', Object);
|
| 72 |
+
|
| 73 |
+
type SerializedGrid = { buffer: ArrayBuffer };
|
| 74 |
+
|
| 75 |
+
Grid.serialize = function serialize(grid: Grid, transferables?: Array<Transferable>): SerializedGrid {
|
| 76 |
+
const buffer = grid.toArrayBuffer();
|
| 77 |
+
if (transferables) {
|
| 78 |
+
transferables.push(buffer);
|
| 79 |
+
}
|
| 80 |
+
return {buffer};
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
Grid.deserialize = function deserialize(serialized: SerializedGrid): Grid {
|
| 84 |
+
return new Grid(serialized.buffer);
|
| 85 |
+
};
|
| 86 |
+
register('Grid', Grid);
|
| 87 |
+
|
| 88 |
+
register('Color', Color);
|
| 89 |
+
register('Error', Error);
|
| 90 |
+
register('ResolvedImage', ResolvedImage);
|
| 91 |
+
|
| 92 |
+
register('StylePropertyFunction', StylePropertyFunction);
|
| 93 |
+
register('StyleExpression', StyleExpression, {omit: ['_evaluator']});
|
| 94 |
+
|
| 95 |
+
register('ZoomDependentExpression', ZoomDependentExpression);
|
| 96 |
+
register('ZoomConstantExpression', ZoomConstantExpression);
|
| 97 |
+
register('CompoundExpression', CompoundExpression, {omit: ['_evaluate']});
|
| 98 |
+
for (const name in expressions) {
|
| 99 |
+
if ((expressions[name]: any)._classRegistryKey) continue;
|
| 100 |
+
register(`Expression_${name}`, expressions[name]);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
function isArrayBuffer(val: any): boolean {
|
| 104 |
+
return val && typeof ArrayBuffer !== 'undefined' &&
|
| 105 |
+
(val instanceof ArrayBuffer || (val.constructor && val.constructor.name === 'ArrayBuffer'));
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
function isImageBitmap(val: any): boolean {
|
| 109 |
+
return ImageBitmap &&
|
| 110 |
+
val instanceof ImageBitmap;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Serialize the given object for transfer to or from a web worker.
|
| 115 |
+
*
|
| 116 |
+
* For non-builtin types, recursively serialize each property (possibly
|
| 117 |
+
* omitting certain properties - see register()), and package the result along
|
| 118 |
+
* with the constructor's `name` so that the appropriate constructor can be
|
| 119 |
+
* looked up in `deserialize()`.
|
| 120 |
+
*
|
| 121 |
+
* If a `transferables` array is provided, add any transferable objects (i.e.,
|
| 122 |
+
* any ArrayBuffers or ArrayBuffer views) to the list. (If a copy is needed,
|
| 123 |
+
* this should happen in the client code, before using serialize().)
|
| 124 |
+
*
|
| 125 |
+
* @private
|
| 126 |
+
*/
|
| 127 |
+
export function serialize(input: mixed, transferables: ?Array<Transferable>): Serialized {
|
| 128 |
+
if (input === null ||
|
| 129 |
+
input === undefined ||
|
| 130 |
+
typeof input === 'boolean' ||
|
| 131 |
+
typeof input === 'number' ||
|
| 132 |
+
typeof input === 'string' ||
|
| 133 |
+
input instanceof Boolean ||
|
| 134 |
+
input instanceof Number ||
|
| 135 |
+
input instanceof String ||
|
| 136 |
+
input instanceof Date ||
|
| 137 |
+
input instanceof RegExp) {
|
| 138 |
+
return input;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
if (isArrayBuffer(input) || isImageBitmap(input)) {
|
| 142 |
+
if (transferables) {
|
| 143 |
+
transferables.push(((input: any): ArrayBuffer));
|
| 144 |
+
}
|
| 145 |
+
return input;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
if (ArrayBuffer.isView(input)) {
|
| 149 |
+
const view: $ArrayBufferView = (input: any);
|
| 150 |
+
if (transferables) {
|
| 151 |
+
transferables.push(view.buffer);
|
| 152 |
+
}
|
| 153 |
+
return view;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
if (input instanceof ImageData) {
|
| 157 |
+
if (transferables) {
|
| 158 |
+
transferables.push(input.data.buffer);
|
| 159 |
+
}
|
| 160 |
+
return input;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
if (Array.isArray(input)) {
|
| 164 |
+
const serialized: Array<Serialized> = [];
|
| 165 |
+
for (const item of input) {
|
| 166 |
+
serialized.push(serialize(item, transferables));
|
| 167 |
+
}
|
| 168 |
+
return serialized;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
if (typeof input === 'object') {
|
| 172 |
+
const klass = (input.constructor: any);
|
| 173 |
+
const name = klass._classRegistryKey;
|
| 174 |
+
if (!name) {
|
| 175 |
+
throw new Error(`can't serialize object of unregistered class`);
|
| 176 |
+
}
|
| 177 |
+
assert(registry[name]);
|
| 178 |
+
|
| 179 |
+
const properties: SerializedObject = klass.serialize ?
|
| 180 |
+
// (Temporary workaround) allow a class to provide static
|
| 181 |
+
// `serialize()` and `deserialize()` methods to bypass the generic
|
| 182 |
+
// approach.
|
| 183 |
+
// This temporary workaround lets us use the generic serialization
|
| 184 |
+
// approach for objects whose members include instances of dynamic
|
| 185 |
+
// StructArray types. Once we refactor StructArray to be static,
|
| 186 |
+
// we can remove this complexity.
|
| 187 |
+
(klass.serialize(input, transferables): SerializedObject) : {};
|
| 188 |
+
|
| 189 |
+
if (!klass.serialize) {
|
| 190 |
+
for (const key in input) {
|
| 191 |
+
// any cast due to https://github.com/facebook/flow/issues/5393
|
| 192 |
+
if (!(input: any).hasOwnProperty(key)) continue;
|
| 193 |
+
if (registry[name].omit.indexOf(key) >= 0) continue;
|
| 194 |
+
const property = (input: any)[key];
|
| 195 |
+
properties[key] = registry[name].shallow.indexOf(key) >= 0 ?
|
| 196 |
+
property :
|
| 197 |
+
serialize(property, transferables);
|
| 198 |
+
}
|
| 199 |
+
if (input instanceof Error) {
|
| 200 |
+
properties.message = input.message;
|
| 201 |
+
}
|
| 202 |
+
} else {
|
| 203 |
+
// make sure statically serialized object survives transfer of $name property
|
| 204 |
+
assert(!transferables || properties !== transferables[transferables.length - 1]);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
if (properties.$name) {
|
| 208 |
+
throw new Error('$name property is reserved for worker serialization logic.');
|
| 209 |
+
}
|
| 210 |
+
if (name !== 'Object') {
|
| 211 |
+
properties.$name = name;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
return properties;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
throw new Error(`can't serialize object of type ${typeof input}`);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
export function deserialize(input: Serialized): mixed {
|
| 221 |
+
if (input === null ||
|
| 222 |
+
input === undefined ||
|
| 223 |
+
typeof input === 'boolean' ||
|
| 224 |
+
typeof input === 'number' ||
|
| 225 |
+
typeof input === 'string' ||
|
| 226 |
+
input instanceof Boolean ||
|
| 227 |
+
input instanceof Number ||
|
| 228 |
+
input instanceof String ||
|
| 229 |
+
input instanceof Date ||
|
| 230 |
+
input instanceof RegExp ||
|
| 231 |
+
isArrayBuffer(input) ||
|
| 232 |
+
isImageBitmap(input) ||
|
| 233 |
+
ArrayBuffer.isView(input) ||
|
| 234 |
+
input instanceof ImageData) {
|
| 235 |
+
return input;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
if (Array.isArray(input)) {
|
| 239 |
+
return input.map(deserialize);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
if (typeof input === 'object') {
|
| 243 |
+
const name = (input: any).$name || 'Object';
|
| 244 |
+
|
| 245 |
+
const {klass} = registry[name];
|
| 246 |
+
if (!klass) {
|
| 247 |
+
throw new Error(`can't deserialize unregistered class ${name}`);
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
if (klass.deserialize) {
|
| 251 |
+
return (klass.deserialize: typeof deserialize)(input);
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
const result = Object.create(klass.prototype);
|
| 255 |
+
|
| 256 |
+
for (const key of Object.keys(input)) {
|
| 257 |
+
if (key === '$name') continue;
|
| 258 |
+
const value = (input: SerializedObject)[key];
|
| 259 |
+
result[key] = registry[name].shallow.indexOf(key) >= 0 ? value : deserialize(value);
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
return result;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
throw new Error(`can't deserialize object of type ${typeof input}`);
|
| 266 |
+
}
|
node_modules/mapbox-gl/src/util/webp_supported.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow strict
|
| 2 |
+
|
| 3 |
+
import window from './window';
|
| 4 |
+
|
| 5 |
+
const exported = {
|
| 6 |
+
supported: false,
|
| 7 |
+
testSupport
|
| 8 |
+
};
|
| 9 |
+
|
| 10 |
+
export default exported;
|
| 11 |
+
|
| 12 |
+
let glForTesting;
|
| 13 |
+
let webpCheckComplete = false;
|
| 14 |
+
let webpImgTest;
|
| 15 |
+
let webpImgTestOnloadComplete = false;
|
| 16 |
+
|
| 17 |
+
if (window.document) {
|
| 18 |
+
webpImgTest = window.document.createElement('img');
|
| 19 |
+
webpImgTest.onload = function() {
|
| 20 |
+
if (glForTesting) testWebpTextureUpload(glForTesting);
|
| 21 |
+
glForTesting = null;
|
| 22 |
+
webpImgTestOnloadComplete = true;
|
| 23 |
+
};
|
| 24 |
+
webpImgTest.onerror = function() {
|
| 25 |
+
webpCheckComplete = true;
|
| 26 |
+
glForTesting = null;
|
| 27 |
+
};
|
| 28 |
+
webpImgTest.src = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAQAAAAfQ//73v/+BiOh/AAA=';
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function testSupport(gl: WebGLRenderingContext) {
|
| 32 |
+
if (webpCheckComplete || !webpImgTest) return;
|
| 33 |
+
|
| 34 |
+
// HTMLImageElement.complete is set when an image is done loading it's source
|
| 35 |
+
// regardless of whether the load was successful or not.
|
| 36 |
+
// It's possible for an error to set HTMLImageElement.complete to true which would trigger
|
| 37 |
+
// testWebpTextureUpload and mistakenly set exported.supported to true in browsers which don't support webp
|
| 38 |
+
// To avoid this, we set a flag in the image's onload handler and only call testWebpTextureUpload
|
| 39 |
+
// after a successful image load event.
|
| 40 |
+
if (webpImgTestOnloadComplete) {
|
| 41 |
+
testWebpTextureUpload(gl);
|
| 42 |
+
} else {
|
| 43 |
+
glForTesting = gl;
|
| 44 |
+
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
function testWebpTextureUpload(gl: WebGLRenderingContext) {
|
| 49 |
+
// Edge 18 supports WebP but not uploading a WebP image to a gl texture
|
| 50 |
+
// Test support for this before allowing WebP images.
|
| 51 |
+
// https://github.com/mapbox/mapbox-gl-js/issues/7671
|
| 52 |
+
const texture = gl.createTexture();
|
| 53 |
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
| 54 |
+
|
| 55 |
+
try {
|
| 56 |
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, webpImgTest);
|
| 57 |
+
|
| 58 |
+
// The error does not get triggered in Edge if the context is lost
|
| 59 |
+
if (gl.isContextLost()) return;
|
| 60 |
+
|
| 61 |
+
exported.supported = true;
|
| 62 |
+
} catch (e) {
|
| 63 |
+
// Catch "Unspecified Error." in Edge 18.
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
gl.deleteTexture(texture);
|
| 67 |
+
|
| 68 |
+
webpCheckComplete = true;
|
| 69 |
+
}
|
node_modules/mapbox-gl/src/util/window.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow strict
|
| 2 |
+
|
| 3 |
+
// This file is intended for use in the GL-JS test suite
|
| 4 |
+
// It implements a JSDOM window object for use in Node environments
|
| 5 |
+
// In a browser environment, this file is replaced with ./src/util/browser/window.js
|
| 6 |
+
// when Rollup builds the main bundle
|
| 7 |
+
// See package.json#browser
|
| 8 |
+
|
| 9 |
+
import jsdom from 'jsdom';
|
| 10 |
+
|
| 11 |
+
import gl from 'gl';
|
| 12 |
+
import sinon from 'sinon';
|
| 13 |
+
|
| 14 |
+
import type {Window} from '../types/window';
|
| 15 |
+
|
| 16 |
+
const {window: _window} = new jsdom.JSDOM('', {
|
| 17 |
+
virtualConsole: new jsdom.VirtualConsole().sendTo(console)
|
| 18 |
+
});
|
| 19 |
+
|
| 20 |
+
restore();
|
| 21 |
+
|
| 22 |
+
export default _window;
|
| 23 |
+
|
| 24 |
+
function restore(): Window {
|
| 25 |
+
// Remove previous window from exported object
|
| 26 |
+
const previousWindow = _window;
|
| 27 |
+
if (previousWindow.close) previousWindow.close();
|
| 28 |
+
for (const key in previousWindow) {
|
| 29 |
+
if (previousWindow.hasOwnProperty(key)) {
|
| 30 |
+
delete previousWindow[key];
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
// Create new window and inject into exported object
|
| 35 |
+
const {window} = new jsdom.JSDOM('', {
|
| 36 |
+
// Send jsdom console output to the node console object.
|
| 37 |
+
virtualConsole: new jsdom.VirtualConsole().sendTo(console)
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
// Delete local and session storage from JSDOM and stub them out with a warning log
|
| 41 |
+
// Accessing these properties during extend() produces an error in Node environments
|
| 42 |
+
// See https://github.com/mapbox/mapbox-gl-js/pull/7455 for discussion
|
| 43 |
+
delete window.localStorage;
|
| 44 |
+
delete window.sessionStorage;
|
| 45 |
+
window.localStorage = window.sessionStorage = () => console.log('Local and session storage not available in Node. Use a stub implementation if needed for testing.');
|
| 46 |
+
|
| 47 |
+
window.devicePixelRatio = 1;
|
| 48 |
+
|
| 49 |
+
window.requestAnimationFrame = function(callback) {
|
| 50 |
+
return setImmediate(callback, 0);
|
| 51 |
+
};
|
| 52 |
+
window.cancelAnimationFrame = clearImmediate;
|
| 53 |
+
|
| 54 |
+
// Add webgl context with the supplied GL
|
| 55 |
+
const originalGetContext = window.HTMLCanvasElement.prototype.getContext;
|
| 56 |
+
window.HTMLCanvasElement.prototype.getContext = function (type, attributes) {
|
| 57 |
+
if (type === 'webgl') {
|
| 58 |
+
if (!this._webGLContext) {
|
| 59 |
+
this._webGLContext = gl(this.width, this.height, attributes);
|
| 60 |
+
}
|
| 61 |
+
return this._webGLContext;
|
| 62 |
+
}
|
| 63 |
+
// Fallback to existing HTMLCanvasElement getContext behaviour
|
| 64 |
+
return originalGetContext.call(this, type, attributes);
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
window.useFakeHTMLCanvasGetContext = function() {
|
| 68 |
+
this.HTMLCanvasElement.prototype.getContext = function() { return '2d'; };
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
window.useFakeXMLHttpRequest = function() {
|
| 72 |
+
sinon.xhr.supportsCORS = true;
|
| 73 |
+
this.server = sinon.fakeServer.create();
|
| 74 |
+
this.XMLHttpRequest = this.server.xhr;
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
window.URL.revokeObjectURL = function () {};
|
| 78 |
+
|
| 79 |
+
window.fakeWorkerPresence = function() {
|
| 80 |
+
global.WorkerGlobalScope = function() {};
|
| 81 |
+
global.self = new global.WorkerGlobalScope();
|
| 82 |
+
};
|
| 83 |
+
window.clearFakeWorkerPresence = function() {
|
| 84 |
+
global.WorkerGlobalScope = undefined;
|
| 85 |
+
global.self = undefined;
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
window.restore = restore;
|
| 89 |
+
|
| 90 |
+
window.performance.getEntriesByName = function() {};
|
| 91 |
+
window.performance.mark = function() {};
|
| 92 |
+
window.performance.measure = function() {};
|
| 93 |
+
window.performance.clearMarks = function() {};
|
| 94 |
+
window.performance.clearMeasures = function() {};
|
| 95 |
+
|
| 96 |
+
window.ImageData = window.ImageData || function() { return false; };
|
| 97 |
+
window.ImageBitmap = window.ImageBitmap || function() { return false; };
|
| 98 |
+
window.WebGLFramebuffer = window.WebGLFramebuffer || Object;
|
| 99 |
+
Object.assign(_window, window); // eslint-disable-line no-restricted-properties
|
| 100 |
+
|
| 101 |
+
return window;
|
| 102 |
+
}
|
node_modules/mapbox-gl/src/util/worker_pool.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @flow
|
| 2 |
+
|
| 3 |
+
import WebWorker from './web_worker';
|
| 4 |
+
import type {WorkerInterface} from './web_worker';
|
| 5 |
+
import browser from './browser';
|
| 6 |
+
|
| 7 |
+
export const PRELOAD_POOL_ID = 'mapboxgl_preloaded_worker_pool';
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* Constructs a worker pool.
|
| 11 |
+
* @private
|
| 12 |
+
*/
|
| 13 |
+
export default class WorkerPool {
|
| 14 |
+
static workerCount: number;
|
| 15 |
+
|
| 16 |
+
active: {[_: number | string]: boolean};
|
| 17 |
+
workers: Array<WorkerInterface>;
|
| 18 |
+
|
| 19 |
+
constructor() {
|
| 20 |
+
this.active = {};
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
acquire(mapId: number | string): Array<WorkerInterface> {
|
| 24 |
+
if (!this.workers) {
|
| 25 |
+
// Lazily look up the value of mapboxgl.workerCount so that
|
| 26 |
+
// client code has had a chance to set it.
|
| 27 |
+
this.workers = [];
|
| 28 |
+
while (this.workers.length < WorkerPool.workerCount) {
|
| 29 |
+
this.workers.push(new WebWorker());
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
this.active[mapId] = true;
|
| 34 |
+
return this.workers.slice();
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
release(mapId: number | string) {
|
| 38 |
+
delete this.active[mapId];
|
| 39 |
+
if (this.numActive() === 0) {
|
| 40 |
+
this.workers.forEach((w) => {
|
| 41 |
+
w.terminate();
|
| 42 |
+
});
|
| 43 |
+
this.workers = (null: any);
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
isPreloaded(): boolean {
|
| 48 |
+
return !!this.active[PRELOAD_POOL_ID];
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
numActive(): number {
|
| 52 |
+
return Object.keys(this.active).length;
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
const availableLogicalProcessors = Math.floor(browser.hardwareConcurrency / 2);
|
| 57 |
+
WorkerPool.workerCount = Math.max(Math.min(availableLogicalProcessors, 6), 1);
|
node_modules/math-intrinsics/.eslintrc
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"root": true,
|
| 3 |
+
|
| 4 |
+
"extends": "@ljharb",
|
| 5 |
+
|
| 6 |
+
"rules": {
|
| 7 |
+
"eqeqeq": ["error", "allow-null"],
|
| 8 |
+
"id-length": "off",
|
| 9 |
+
"new-cap": ["error", {
|
| 10 |
+
"capIsNewExceptions": [
|
| 11 |
+
"RequireObjectCoercible",
|
| 12 |
+
"ToObject",
|
| 13 |
+
],
|
| 14 |
+
}],
|
| 15 |
+
},
|
| 16 |
+
}
|
node_modules/math-intrinsics/.github/FUNDING.yml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# These are supported funding model platforms
|
| 2 |
+
|
| 3 |
+
github: [ljharb]
|
| 4 |
+
patreon: # Replace with a single Patreon username
|
| 5 |
+
open_collective: # Replace with a single Open Collective username
|
| 6 |
+
ko_fi: # Replace with a single Ko-fi username
|
| 7 |
+
tidelift: npm/math-intrinsics
|
| 8 |
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
| 9 |
+
liberapay: # Replace with a single Liberapay username
|
| 10 |
+
issuehunt: # Replace with a single IssueHunt username
|
| 11 |
+
otechie: # Replace with a single Otechie username
|
| 12 |
+
custom: # Replace with a single custom sponsorship URL
|
node_modules/math-intrinsics/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Changelog
|
| 2 |
+
|
| 3 |
+
All notable changes to this project will be documented in this file.
|
| 4 |
+
|
| 5 |
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
| 6 |
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
| 7 |
+
|
| 8 |
+
## [v1.1.0](https://github.com/es-shims/math-intrinsics/compare/v1.0.0...v1.1.0) - 2024-12-18
|
| 9 |
+
|
| 10 |
+
### Commits
|
| 11 |
+
|
| 12 |
+
- [New] add `round` [`7cfb044`](https://github.com/es-shims/math-intrinsics/commit/7cfb04460c0fbdf1ca101eecbac3f59d11994130)
|
| 13 |
+
- [Tests] add attw [`e96be8f`](https://github.com/es-shims/math-intrinsics/commit/e96be8fbf58449eafe976446a0470e6ea561ad8d)
|
| 14 |
+
- [Dev Deps] update `@types/tape` [`30d0023`](https://github.com/es-shims/math-intrinsics/commit/30d00234ce8a3fa0094a61cd55d6686eb91e36ec)
|
| 15 |
+
|
| 16 |
+
## v1.0.0 - 2024-12-11
|
| 17 |
+
|
| 18 |
+
### Commits
|
| 19 |
+
|
| 20 |
+
- Initial implementation, tests, readme, types [`b898caa`](https://github.com/es-shims/math-intrinsics/commit/b898caae94e9994a94a42b8740f7bbcfd0a868fe)
|
| 21 |
+
- Initial commit [`02745b0`](https://github.com/es-shims/math-intrinsics/commit/02745b03a62255af8a332771987b55d127538d9c)
|
| 22 |
+
- [New] add `constants/maxArrayLength`, `mod` [`b978178`](https://github.com/es-shims/math-intrinsics/commit/b978178a57685bd23ed1c7efe2137f3784f5fcc5)
|
| 23 |
+
- npm init [`a39fc57`](https://github.com/es-shims/math-intrinsics/commit/a39fc57e5639a645d0bd52a0dc56202480223be2)
|
| 24 |
+
- Only apps should have lockfiles [`9451580`](https://github.com/es-shims/math-intrinsics/commit/94515800fb34db4f3cc7e99290042d45609ac7bd)
|
node_modules/math-intrinsics/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2024 ECMAScript Shims
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
node_modules/math-intrinsics/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# math-intrinsics <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
| 2 |
+
|
| 3 |
+
[![github actions][actions-image]][actions-url]
|
| 4 |
+
[![coverage][codecov-image]][codecov-url]
|
| 5 |
+
[![License][license-image]][license-url]
|
| 6 |
+
[![Downloads][downloads-image]][downloads-url]
|
| 7 |
+
|
| 8 |
+
[![npm badge][npm-badge-png]][package-url]
|
| 9 |
+
|
| 10 |
+
ES Math-related intrinsics and helpers, robustly cached.
|
| 11 |
+
|
| 12 |
+
- `abs`
|
| 13 |
+
- `floor`
|
| 14 |
+
- `isFinite`
|
| 15 |
+
- `isInteger`
|
| 16 |
+
- `isNaN`
|
| 17 |
+
- `isNegativeZero`
|
| 18 |
+
- `max`
|
| 19 |
+
- `min`
|
| 20 |
+
- `mod`
|
| 21 |
+
- `pow`
|
| 22 |
+
- `round`
|
| 23 |
+
- `sign`
|
| 24 |
+
- `constants/maxArrayLength`
|
| 25 |
+
- `constants/maxSafeInteger`
|
| 26 |
+
- `constants/maxValue`
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
## Tests
|
| 30 |
+
Simply clone the repo, `npm install`, and run `npm test`
|
| 31 |
+
|
| 32 |
+
## Security
|
| 33 |
+
|
| 34 |
+
Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
|
| 35 |
+
|
| 36 |
+
[package-url]: https://npmjs.org/package/math-intrinsics
|
| 37 |
+
[npm-version-svg]: https://versionbadg.es/es-shims/math-intrinsics.svg
|
| 38 |
+
[deps-svg]: https://david-dm.org/es-shims/math-intrinsics.svg
|
| 39 |
+
[deps-url]: https://david-dm.org/es-shims/math-intrinsics
|
| 40 |
+
[dev-deps-svg]: https://david-dm.org/es-shims/math-intrinsics/dev-status.svg
|
| 41 |
+
[dev-deps-url]: https://david-dm.org/es-shims/math-intrinsics#info=devDependencies
|
| 42 |
+
[npm-badge-png]: https://nodei.co/npm/math-intrinsics.png?downloads=true&stars=true
|
| 43 |
+
[license-image]: https://img.shields.io/npm/l/math-intrinsics.svg
|
| 44 |
+
[license-url]: LICENSE
|
| 45 |
+
[downloads-image]: https://img.shields.io/npm/dm/es-object.svg
|
| 46 |
+
[downloads-url]: https://npm-stat.com/charts.html?package=math-intrinsics
|
| 47 |
+
[codecov-image]: https://codecov.io/gh/es-shims/math-intrinsics/branch/main/graphs/badge.svg
|
| 48 |
+
[codecov-url]: https://app.codecov.io/gh/es-shims/math-intrinsics/
|
| 49 |
+
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/math-intrinsics
|
| 50 |
+
[actions-url]: https://github.com/es-shims/math-intrinsics/actions
|
node_modules/math-intrinsics/abs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export = Math.abs;
|
node_modules/math-intrinsics/abs.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
/** @type {import('./abs')} */
|
| 4 |
+
module.exports = Math.abs;
|
node_modules/math-intrinsics/constants/maxArrayLength.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare const MAX_ARRAY_LENGTH: 4294967295;
|
| 2 |
+
|
| 3 |
+
export = MAX_ARRAY_LENGTH;
|
node_modules/math-intrinsics/constants/maxArrayLength.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
/** @type {import('./maxArrayLength')} */
|
| 4 |
+
module.exports = 4294967295; // Math.pow(2, 32) - 1;
|
node_modules/math-intrinsics/constants/maxSafeInteger.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare const MAX_SAFE_INTEGER: 9007199254740991;
|
| 2 |
+
|
| 3 |
+
export = MAX_SAFE_INTEGER;
|
node_modules/math-intrinsics/constants/maxSafeInteger.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
/** @type {import('./maxSafeInteger')} */
|
| 4 |
+
// eslint-disable-next-line no-extra-parens
|
| 5 |
+
module.exports = /** @type {import('./maxSafeInteger')} */ (Number.MAX_SAFE_INTEGER) || 9007199254740991; // Math.pow(2, 53) - 1;
|
node_modules/math-intrinsics/constants/maxValue.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare const MAX_VALUE: 1.7976931348623157e+308;
|
| 2 |
+
|
| 3 |
+
export = MAX_VALUE;
|
node_modules/math-intrinsics/constants/maxValue.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
/** @type {import('./maxValue')} */
|
| 4 |
+
// eslint-disable-next-line no-extra-parens
|
| 5 |
+
module.exports = /** @type {import('./maxValue')} */ (Number.MAX_VALUE) || 1.7976931348623157e+308;
|
node_modules/math-intrinsics/floor.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export = Math.floor;
|
node_modules/math-intrinsics/floor.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
/** @type {import('./floor')} */
|
| 4 |
+
module.exports = Math.floor;
|
node_modules/math-intrinsics/isFinite.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare function isFinite(x: unknown): x is number | bigint;
|
| 2 |
+
|
| 3 |
+
export = isFinite;
|
node_modules/math-intrinsics/isFinite.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
var $isNaN = require('./isNaN');
|
| 4 |
+
|
| 5 |
+
/** @type {import('./isFinite')} */
|
| 6 |
+
module.exports = function isFinite(x) {
|
| 7 |
+
return (typeof x === 'number' || typeof x === 'bigint')
|
| 8 |
+
&& !$isNaN(x)
|
| 9 |
+
&& x !== Infinity
|
| 10 |
+
&& x !== -Infinity;
|
| 11 |
+
};
|
| 12 |
+
|
node_modules/math-intrinsics/isInteger.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare function isInteger(argument: unknown): argument is number;
|
| 2 |
+
|
| 3 |
+
export = isInteger;
|
node_modules/math-intrinsics/isInteger.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
var $abs = require('./abs');
|
| 4 |
+
var $floor = require('./floor');
|
| 5 |
+
|
| 6 |
+
var $isNaN = require('./isNaN');
|
| 7 |
+
var $isFinite = require('./isFinite');
|
| 8 |
+
|
| 9 |
+
/** @type {import('./isInteger')} */
|
| 10 |
+
module.exports = function isInteger(argument) {
|
| 11 |
+
if (typeof argument !== 'number' || $isNaN(argument) || !$isFinite(argument)) {
|
| 12 |
+
return false;
|
| 13 |
+
}
|
| 14 |
+
var absValue = $abs(argument);
|
| 15 |
+
return $floor(absValue) === absValue;
|
| 16 |
+
};
|
node_modules/math-intrinsics/isNaN.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export = Number.isNaN;
|
node_modules/math-intrinsics/isNaN.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
/** @type {import('./isNaN')} */
|
| 4 |
+
module.exports = Number.isNaN || function isNaN(a) {
|
| 5 |
+
return a !== a;
|
| 6 |
+
};
|
node_modules/math-intrinsics/isNegativeZero.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare function isNegativeZero(x: unknown): boolean;
|
| 2 |
+
|
| 3 |
+
export = isNegativeZero;
|
node_modules/math-intrinsics/isNegativeZero.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
/** @type {import('./isNegativeZero')} */
|
| 4 |
+
module.exports = function isNegativeZero(x) {
|
| 5 |
+
return x === 0 && 1 / x === 1 / -0;
|
| 6 |
+
};
|
node_modules/math-intrinsics/max.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export = Math.max;
|
node_modules/math-intrinsics/max.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
/** @type {import('./max')} */
|
| 4 |
+
module.exports = Math.max;
|
node_modules/math-intrinsics/min.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export = Math.min;
|
node_modules/math-intrinsics/min.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
/** @type {import('./min')} */
|
| 4 |
+
module.exports = Math.min;
|
node_modules/math-intrinsics/mod.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare function mod(number: number, modulo: number): number;
|
| 2 |
+
|
| 3 |
+
export = mod;
|
node_modules/math-intrinsics/mod.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
var $floor = require('./floor');
|
| 4 |
+
|
| 5 |
+
/** @type {import('./mod')} */
|
| 6 |
+
module.exports = function mod(number, modulo) {
|
| 7 |
+
var remain = number % modulo;
|
| 8 |
+
return $floor(remain >= 0 ? remain : remain + modulo);
|
| 9 |
+
};
|