✨ MAJOR FEATURES: • Auto-zoom intelligence với smart bounds fitting • Enhanced 3D GPS markers với pulsing effects • Professional route display với 6-layer rendering • Status-based parking icons với availability indicators • Production-ready build optimizations 🗺️ AUTO-ZOOM FEATURES: • Smart bounds fitting cho GPS + selected parking • Adaptive padding (50px) cho visual balance • Max zoom control (level 16) để tránh quá gần • Dynamic centering khi không có selection 🎨 ENHANCED VISUALS: • 3D GPS marker với multi-layer pulse effects • Advanced parking icons với status colors • Selection highlighting với animation • Dimming system cho non-selected items 🛣️ ROUTE SYSTEM: • OpenRouteService API integration • Multi-layer route rendering (glow, shadow, main, animated) • Real-time distance & duration calculation • Visual route info trong popup 📱 PRODUCTION READY: • SSR safe với dynamic imports • Build errors resolved • Global deployment via Vercel • Optimized performance 🌍 DEPLOYMENT: • Vercel: https://whatever-ctk2auuxr-phong12hexdockworks-projects.vercel.app • Bundle size: 22.8 kB optimized • Global CDN distribution • HTTPS enabled 💾 VERSION CONTROL: • MapView-v2.0.tsx backup created • MAPVIEW_VERSIONS.md documentation • Full version history tracking
116 lines
2.7 KiB
TypeScript
116 lines
2.7 KiB
TypeScript
import type { SourceMapSegment, ReverseSegment } from './sourcemap-segment';
|
|
import { COLUMN } from './sourcemap-segment';
|
|
|
|
export type MemoState = {
|
|
lastKey: number;
|
|
lastNeedle: number;
|
|
lastIndex: number;
|
|
};
|
|
|
|
export let found = false;
|
|
|
|
/**
|
|
* A binary search implementation that returns the index if a match is found.
|
|
* If no match is found, then the left-index (the index associated with the item that comes just
|
|
* before the desired index) is returned. To maintain proper sort order, a splice would happen at
|
|
* the next index:
|
|
*
|
|
* ```js
|
|
* const array = [1, 3];
|
|
* const needle = 2;
|
|
* const index = binarySearch(array, needle, (item, needle) => item - needle);
|
|
*
|
|
* assert.equal(index, 0);
|
|
* array.splice(index + 1, 0, needle);
|
|
* assert.deepEqual(array, [1, 2, 3]);
|
|
* ```
|
|
*/
|
|
export function binarySearch(
|
|
haystack: SourceMapSegment[] | ReverseSegment[],
|
|
needle: number,
|
|
low: number,
|
|
high: number,
|
|
): number {
|
|
while (low <= high) {
|
|
const mid = low + ((high - low) >> 1);
|
|
const cmp = haystack[mid][COLUMN] - needle;
|
|
|
|
if (cmp === 0) {
|
|
found = true;
|
|
return mid;
|
|
}
|
|
|
|
if (cmp < 0) {
|
|
low = mid + 1;
|
|
} else {
|
|
high = mid - 1;
|
|
}
|
|
}
|
|
|
|
found = false;
|
|
return low - 1;
|
|
}
|
|
|
|
export function upperBound(
|
|
haystack: SourceMapSegment[] | ReverseSegment[],
|
|
needle: number,
|
|
index: number,
|
|
): number {
|
|
for (let i = index + 1; i < haystack.length; index = i++) {
|
|
if (haystack[i][COLUMN] !== needle) break;
|
|
}
|
|
return index;
|
|
}
|
|
|
|
export function lowerBound(
|
|
haystack: SourceMapSegment[] | ReverseSegment[],
|
|
needle: number,
|
|
index: number,
|
|
): number {
|
|
for (let i = index - 1; i >= 0; index = i--) {
|
|
if (haystack[i][COLUMN] !== needle) break;
|
|
}
|
|
return index;
|
|
}
|
|
|
|
export function memoizedState(): MemoState {
|
|
return {
|
|
lastKey: -1,
|
|
lastNeedle: -1,
|
|
lastIndex: -1,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* This overly complicated beast is just to record the last tested line/column and the resulting
|
|
* index, allowing us to skip a few tests if mappings are monotonically increasing.
|
|
*/
|
|
export function memoizedBinarySearch(
|
|
haystack: SourceMapSegment[] | ReverseSegment[],
|
|
needle: number,
|
|
state: MemoState,
|
|
key: number,
|
|
): number {
|
|
const { lastKey, lastNeedle, lastIndex } = state;
|
|
|
|
let low = 0;
|
|
let high = haystack.length - 1;
|
|
if (key === lastKey) {
|
|
if (needle === lastNeedle) {
|
|
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
|
return lastIndex;
|
|
}
|
|
|
|
if (needle >= lastNeedle) {
|
|
// lastIndex may be -1 if the previous needle was not found.
|
|
low = lastIndex === -1 ? 0 : lastIndex;
|
|
} else {
|
|
high = lastIndex;
|
|
}
|
|
}
|
|
state.lastKey = key;
|
|
state.lastNeedle = needle;
|
|
|
|
return (state.lastIndex = binarySearch(haystack, needle, low, high));
|
|
}
|