MediaWiki:GlaMapMention.js
Ir para navegação
Ir para pesquisar
Nota: Após salvar, você pode ter que limpar o "cache" do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Internet Explorer/Edge: PressioneCtrl enquanto clica Recarregar, ou Pressione Ctrl-F5
- Opera: Pressione Ctrl-F5.
// Generated by projetos/interactive-map/build.py (map-model.js, map-renderer.js, mention.js, mention.css): edit the sources there.
// A page with an InteractiveMap widget already has the engine; it is defined here only when missing.
if (!(globalThis.GlaMapModel && globalThis.GlaMapModel.createRenderer)) {
(function (root) {
'use strict';
function decode(base64) {
var text = typeof atob === 'function' ? atob(base64) : Buffer.from(base64, 'base64').toString('binary');
var bytes = new Uint8Array(text.length);
for (var i = 0; i < text.length; i++) bytes[i] = text.charCodeAt(i);
return bytes;
}
function pad(z) { return String(z).padStart(2, '0'); }
var MD5_TURNS = [7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21], MD5_K = [];
for (var n = 0; n < 64; n++) MD5_K[n] = Math.floor(Math.abs(Math.sin(n + 1)) * 4294967296) | 0;
function md5(text) {
var bytes = [], bits = text.length * 8, i;
for (i = 0; i < text.length; i++) bytes.push(text.charCodeAt(i) & 255);
bytes.push(128);
while (bytes.length % 64 !== 56) bytes.push(0);
for (i = 0; i < 8; i++) bytes.push(i < 4 ? bits >>> (i * 8) & 255 : 0);
var state = [0x67452301, 0xefcdab89 | 0, 0x98badcfe | 0, 0x10325476];
for (var at = 0; at < bytes.length; at += 64) {
var m = [], a = state[0], b = state[1], c = state[2], d = state[3];
for (i = 0; i < 16; i++) m[i] = bytes[at + i * 4] | bytes[at + i * 4 + 1] << 8 | bytes[at + i * 4 + 2] << 16 | bytes[at + i * 4 + 3] << 24;
for (i = 0; i < 64; i++) {
var round = i >> 4, f, g;
if (round === 0) { f = b & c | ~b & d; g = i; }
else if (round === 1) { f = d & b | ~d & c; g = (5 * i + 1) % 16; }
else if (round === 2) { f = b ^ c ^ d; g = (3 * i + 5) % 16; }
else { f = c ^ (b | ~d); g = 7 * i % 16; }
var sum = a + f + MD5_K[i] + m[g] | 0, turn = MD5_TURNS[round * 4 + i % 4];
a = d; d = c; c = b;
b = b + (sum << turn | sum >>> 32 - turn) | 0;
}
state[0] = state[0] + a | 0; state[1] = state[1] + b | 0; state[2] = state[2] + c | 0; state[3] = state[3] + d | 0;
}
return state.map(function (word) {
var out = '';
for (var j = 0; j < 4; j++) out += ('0' + (word >>> j * 8 & 255).toString(16)).slice(-2);
return out;
}).join('');
}
var PT_NOTES = {
'Requires bridge-building abilities or a Milky Dial': 'Requer habilidades de construir pontes ou um Milky Dial',
'Crossable with a Teleport skill, bridge-building abilities, or a Milky Dial': 'Atravessável com habilidade de Teleporte, habilidades de construir pontes ou um Milky Dial',
'Requires a Teleport skill, bridge ability, or Milky Dial': 'Requer habilidade de Teleporte, habilidade de construir pontes ou Milky Dial',
'Can be crossed with Dash/Teleport, bridge-building abilities, or a Milky Dial': 'Pode ser atravessado com Dash/Teleporte, habilidades de construir pontes ou um Milky Dial',
'Requires a bridge ability or Milky Dial': 'Requer habilidade de construir pontes ou Milky Dial',
'Breakable Wall: requires a powerful ability or Impact Dial': 'Parede quebrável: requer uma habilidade poderosa ou Impact Dial',
'Breakable with powerful abilities or an Impact Dial': 'Quebrável com habilidades poderosas ou um Impact Dial'
};
root.GlaMapModel = {
MIN_ZOOM: 0.12,
MAX_ZOOM: 0.81,
STAIRS_MIN_SCALE: 3,
markerLayout: function (scale, touch) {
var icon = Math.round(Math.max(16, Math.min(28, scale * .75)) * (touch ? 2 : 1));
return { icon: icon, hit: touch ? Math.max(44, icon) : icon };
},
rewardKey: function (mark) {
return [mark.x, mark.y, mark.z].join(',') + '\n' + (mark.lines || []).join('\n');
},
markerCategory: function (mark) {
if (mark.kind === 'stairs') return 'ladders';
var icon = Number(mark.icon);
return icon === 13 ? 'chests' : icon === 2 || icon === 8 ? 'obstacles' : 'points'; // 2 bridges, 8 breakable walls
},
objectRect: function (obj, centre, scale, native) {
var k = scale / native;
return { left: centre.x - scale / 2 + obj.left * k, top: centre.y - scale / 2 + obj.top * k, width: obj.w * k, height: obj.h * k };
},
LEGEND_ORDER: ['chests', 'points', 'obstacles', 'ladders'],
legendCategories: function (markers) {
var M = root.GlaMapModel, seen = {};
markers.forEach(function (mark) { seen[M.markerCategory(mark)] = true; });
var known = M.LEGEND_ORDER.filter(function (name) { return seen[name]; });
return known.concat(Object.keys(seen).filter(function (name) { return M.LEGEND_ORDER.indexOf(name) < 0; }).sort());
},
parseShare: function (hash) {
var text = String(hash || '').replace(/^#/, '').replace(/%23/gi, '#'); // some apps encode the second '#'
var old = /^([a-z0-9]+(?:-[a-z0-9]+)*)((?:_\d{1,5}-\d{1,5}-\d{1,2})+)$/.exec(text);
if (old) {
var first = /^_(\d+)-(\d+)-(\d+)/.exec(old[2]);
return { island: old[1], pins: [{ x: Number(first[1]), y: Number(first[2]), z: Number(first[3]) }] };
}
var found = /^([A-Za-z0-9]+(?:[_-][A-Za-z0-9]+)*)(?:#(?:(\d{1,5})_(\d{1,5})_(\d{1,2}))?)?$/.exec(text);
if (!found) return null;
return { island: found[1], pins: found[2] ? [{ x: Number(found[2]), y: Number(found[3]), z: Number(found[4]) }] : [] };
},
shareHash: function (island, pins) {
return island + (pins.length ? '#' + pins[0].x + '_' + pins[0].y + '_' + pins[0].z : '');
},
togglePin: function (pins, tile) {
var same = pins.some(function (p) { return p.x === tile.x && p.y === tile.y && p.z === tile.z; });
return same ? [] : [{ x: tile.x, y: tile.y, z: tile.z }];
},
markerIcon: function (mark) {
return mark.kind !== 'stairs' && Number(mark.icon) === 2 ? 8 : mark.icon;
},
ptTitle: function (text) {
var period = /\.$/.test(text) ? '.' : '', known = PT_NOTES[text.replace(/\.$/, '')];
if (known) return known + period;
return text.replace(/^Chest\b/, 'Baú').replace(/\bLv\./, 'Nv.');
},
filterMarkers: function (markers, filters) {
filters = filters || {};
return markers.filter(function (mark) {
var value = filters[root.GlaMapModel.markerCategory(mark)];
return value === true || String(value || '').trim().toLowerCase() === 'yes';
});
},
CHEST_ZOOM: 0.5,
chestButtons: function (markers) {
return markers.filter(function (mark) {
return root.GlaMapModel.markerCategory(mark) === 'chests';
}).map(function (mark, order) {
var found = /#\s*(\d+)/.exec((mark.lines && mark.lines[0]) || '');
return { mark: mark, number: found ? Number(found[1]) : null, order: order };
}).sort(function (a, b) {
var x = a.number === null ? Infinity : a.number, y = b.number === null ? Infinity : b.number;
return x === y ? a.order - b.order : x - y;
});
},
viewOnTile: function (data, shifts, tile, scale, width, height) {
var s = root.GlaMapModel.shift(shifts, tile.z);
return {
x: width / 2 - (tile.x - data.origin[0] + .5 + s[0]) * scale,
y: height / 2 - (tile.y - data.origin[1] + .5 + s[1]) * scale,
scale: scale
};
},
flightView: function (from, to, width, height, t) {
var eased = t < .5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
var scale = from.scale * Math.pow(to.scale / from.scale, eased);
var startX = (width / 2 - from.x) / from.scale, startY = (height / 2 - from.y) / from.scale;
var endX = (width / 2 - to.x) / to.scale, endY = (height / 2 - to.y) / to.scale;
return {
x: width / 2 - (startX + (endX - startX) * eased) * scale,
y: height / 2 - (startY + (endY - startY) * eased) * scale,
scale: scale
};
},
preloadRoom: function (cachePixels, wantedPixels) {
return Math.min(cachePixels - wantedPixels, cachePixels * .5);
},
evictionOrder: function (records, floorMark) {
function here(record) { return record.name.indexOf(floorMark) >= 0 ? 1 : 0; }
return records.slice().sort(function (a, b) { return here(a) - here(b) || a.used - b.used; });
},
coverScale: function (bounds, width, height) {
return Math.max(width / (bounds[2] - bounds[0]), height / (bounds[3] - bounds[1]));
},
constrainView: function (view, bounds, width, height, minScale) {
var scale = Math.max(view.scale, minScale);
return {
x: Math.min(0 - bounds[0] * scale, Math.max(width - bounds[2] * scale, view.x)),
y: Math.min(0 - bounds[1] * scale, Math.max(height - bounds[3] * scale, view.y)),
scale: scale
};
},
contentBounds: function (floors, shifts, fallback) {
var out = null, model = this;
floors.forEach(function (f) {
if (!f.bounds) return;
var s = model.shift(shifts, f.z), b = f.bounds;
if (!out) out = [b[0] + s[0], b[1] + s[1], b[2] + s[0], b[3] + s[1]];
else out = [Math.min(out[0], b[0] + s[0]), Math.min(out[1], b[1] + s[1]), Math.max(out[2], b[2] + s[0]), Math.max(out[3], b[3] + s[1])];
});
return out || fallback;
},
limitPan: function (view, bounds, width, height) {
function axis(position, low, high, screen) {
var size = (high - low) * view.scale, edge = position + low * view.scale;
var limited = Math.max(Math.min(screen / 2 - size, 0), Math.min(Math.max(screen / 2, screen - size), edge));
return position + limited - edge;
}
return { x: axis(view.x, bounds[0], bounds[2], width), y: axis(view.y, bounds[1], bounds[3], height), scale: view.scale };
},
chunkName: function (prefix, z, ppt, x, y) { return prefix + '_z' + pad(z) + '_L' + ppt + '_' + x + '_' + y + '.webp'; },
overviewName: function (prefix, z) { return prefix + '_z' + pad(z) + '_overview.webp'; },
md5: md5,
hashedPath: function (name) {
var key = name.charAt(0).toUpperCase() + name.slice(1), hash = md5(key);
return hash.charAt(0) + '/' + hash.slice(0, 2) + '/' + encodeURIComponent(key);
},
lowerFloors: function (floors, selected, enabled) {
return enabled ? floors.filter(function (z) { return z > selected; }).sort(function (a, b) { return b - a; }) : [];
},
zoomAt: function (view, scale, x, y) {
return { x: x - (x - view.x) * scale / view.scale, y: y - (y - view.y) * scale / view.scale, scale: scale };
},
fit: function (bounds, width, height) {
var scale = Math.min(width / (bounds[2] - bounds[0]), height / (bounds[3] - bounds[1])) * 0.92;
return { scale: scale, x: width / 2 - (bounds[0] + bounds[2]) / 2 * scale, y: height / 2 - (bounds[1] + bounds[3]) / 2 * scale };
},
pickLevel: function (levels, need) {
var sorted = levels.slice().sort(function (a, b) { return a - b; });
if (need <= 1) return 0;
for (var i = 0; i < sorted.length; i++) if (sorted[i] >= need) return sorted[i];
return sorted[sorted.length - 1];
},
chunkSet: function (base64, cols) {
var bytes = decode(base64);
return { has: function (x, y) { if (x < 0 || y < 0 || x >= cols) return false; var i = y * cols + x; return i >> 3 < bytes.length && (bytes[i >> 3] >> (i & 7) & 1) === 1; } };
},
shift: function (shifts, z) {
var a = (shifts && shifts[z]) || [0, 0];
return [a[0], a[1]];
},
floorStep: function (state, deltaY, deltaMode, now) {
if (now - (state.time || 0) > 300) state.acc = 0;
state.time = now;
var delta = deltaMode === 1 ? deltaY * 33 : deltaMode === 2 ? deltaY * 800 : deltaY;
state.acc = (state.acc || 0) + delta;
if (now < (state.lock || 0) || Math.abs(state.acc) < 60) return 0;
var step = state.acc < 0 ? -1 : 1;
state.acc = 0; state.lock = now + (Math.abs(delta) >= 60 ? 60 : 150);
return step;
},
gameShift: function (floors) {
var out = {};
floors.forEach(function (z) { out[z] = [z, z]; });
return out;
}
};
})(globalThis);
(function (root) {
'use strict';
var M = root.GlaMapModel;
var HOLD_MS = 200, WORKERS = 8, BACKGROUND_WORKERS = 2, SETTLE_MS = 120;
function decode(url, signal) {
if (root.createImageBitmap && new URL(url, root.location.href).origin === root.location.origin) {
return root.fetch(url, { credentials: 'same-origin', signal: signal }).then(function (response) {
if (!response.ok) throw new Error('HTTP ' + response.status);
return response.blob();
}).then(function (blob) { return root.createImageBitmap(blob); });
}
var image = new Image();
image.decoding = 'async';
image.src = url;
if (signal) signal.addEventListener('abort', function () { image.src = ''; }, { once: true });
return image.decode().then(function () {
return root.createImageBitmap ? root.createImageBitmap(image) : image;
});
}
function release(image) { if (image && image.close) image.close(); }
M.createRenderer = function (options) {
var data = options.map, canvas = options.canvas, tileUrls = options.tileUrls, onFrame = options.onFrame;
var shifts = options.shifts || {}, preloading = options.preload !== false, cachePixels = options.cachePixels || 120e6;
var ctx = canvas.getContext('2d', { alpha: false });
var under = document.createElement('canvas'), underCtx = under.getContext('2d');
var plane = document.createElement('canvas'), planeCtx = plane.getContext('2d');
var warm = document.createElement('canvas'), warmCtx = warm.getContext('2d');
warm.width = warm.height = 1;
var floors = data.floors.map(function (f) { return f.z; }).sort(function (a, b) { return a - b; });
var levels = data.levels.slice().sort(function (a, b) { return a - b; });
var native = levels[levels.length - 1], size = data.chunk, grid = {}, chunks = new Map();
levels.forEach(function (ppt) {
grid[ppt] = { cols: Math.ceil(data.width * ppt / size), rows: Math.ceil(data.height * ppt / size) };
});
data.floors.forEach(function (f) {
var sets = {};
levels.forEach(function (ppt) { sets[ppt] = M.chunkSet(f.chunks[ppt], grid[ppt].cols); });
chunks.set(f.z, sets);
});
var selected = data.defaultFloor, onScreen = null, holdUntil = 0, holdTimer = 0, missing = 0;
var width = 0, height = 0, ratio = 1, view = { x: 0, y: 0, scale: 1 };
var touched = false, settled = true, settleTimer = 0, scheduled = false, destroyed = false;
var lowerOn = true, lowerOpacity = 0.7;
var records = new Map(), queue = [], running = 0, serial = 0, wanted = new Set();
function get(name, prio) {
var fresh = !wanted.has(name), record = records.get(name);
wanted.add(name);
if (!record) {
record = { name: name, state: 'queued', used: 0, prio: prio };
records.set(name, record);
queue.push(record);
}
record.used = ++serial;
record.prio = fresh ? prio : Math.min(record.prio, prio);
return record.state === 'loaded' ? record.image : null;
}
function peek(name) {
var record = records.get(name);
if (!record || record.state !== 'loaded') return null;
wanted.add(name);
record.used = ++serial;
return record.image;
}
function decodeFirst(urls, attempt, signal) {
return decode(urls[attempt], signal).catch(function (error) {
if (signal && signal.aborted) throw error;
if (attempt + 1 < urls.length) return decodeFirst(urls, attempt + 1, signal);
throw error;
});
}
function load(record) {
record.controller = new AbortController();
decodeFirst(tileUrls(record.name), 0, record.controller.signal).then(function (image) {
if (destroyed || record.controller.signal.aborted) { release(image); finished(record); return; }
warmCtx.drawImage(image, 0, 0, 1, 1);
record.image = image;
record.state = 'loaded';
finished(record);
}, function () {
record.state = record.controller.signal.aborted ? 'cancelled' : 'failed';
finished(record);
});
}
function finished(record) {
running--;
if (destroyed) return;
if (record.prio < 2 || (!queue.length && !running)) invalidate(); else pump();
}
function pump() {
records.forEach(function (r, name) {
if (r.state === 'loading' && !wanted.has(name)) {
records.delete(name);
r.controller.abort();
}
});
queue = queue.filter(function (r) {
if (wanted.has(r.name)) return true;
records.delete(r.name);
return false;
});
queue.sort(function (a, b) { return a.prio - b.prio; });
var background = Array.from(records.values()).filter(function (r) { return r.state === 'loading' && r.prio >= 2; }).length;
while (running < WORKERS && queue.length) {
if (queue[0].prio >= 2 && background >= BACKGROUND_WORKERS) break;
var record = queue.shift();
record.state = 'loading';
if (record.prio >= 2) background++;
running++;
load(record);
}
var loaded = Array.from(records.values()).filter(function (r) { return r.state === 'loaded'; });
var excess = loaded.reduce(function (sum, r) { return sum + r.image.width * r.image.height; }, 0) - cachePixels;
if (excess <= 0) return;
M.evictionOrder(loaded, M.overviewName(data.prefix, selected).replace('overview.webp', '')).forEach(function (r) {
if (excess > 0 && !wanted.has(r.name)) {
excess -= r.image.width * r.image.height;
release(r.image);
r.image = null;
records.delete(r.name);
}
});
}
function run() { if (scheduled) draw(); }
function invalidate() {
if (scheduled || destroyed) return;
scheduled = true;
requestAnimationFrame(run);
setTimeout(run, 64); // tiles keep appearing where the browser throttles animation frames
}
function dx(t) { return Math.round(ratio * (view.x + t * view.scale)); }
function dy(t) { return Math.round(ratio * (view.y + t * view.scale)); }
function paint(context, image, sx, sy, sw, sh, tx, ty, tw, th, smooth) {
var x0 = dx(tx), y0 = dy(ty), x1 = dx(tx + tw), y1 = dy(ty + th);
if (x1 <= x0 || y1 <= y0) return;
context.imageSmoothingEnabled = smooth;
context.drawImage(image, sx, sy, sw, sh, x0, y0, x1 - x0, y1 - y0);
}
function eachChunk(z, level, shift, visit) {
var tiles = size / level, set = chunks.get(z)[level];
var firstX = Math.max(0, Math.floor((-view.x / view.scale - shift[0]) / tiles));
var lastX = Math.min(grid[level].cols - 1, Math.floor(((width - view.x) / view.scale - shift[0]) / tiles));
var firstY = Math.max(0, Math.floor((-view.y / view.scale - shift[1]) / tiles));
var lastY = Math.min(grid[level].rows - 1, Math.floor(((height - view.y) / view.scale - shift[1]) / tiles));
for (var y = firstY; y <= lastY; y++) for (var x = firstX; x <= lastX; x++) if (set.has(x, y)) visit(x, y);
}
function note(name) { if (records.get(name).state !== 'failed') missing++; }
var joined = null, joinedCtx = null, joinedPieces = new Set();
function drawJoined(context, z, level, shift, overview, prio) {
if (!joined) {
joined = document.createElement('canvas');
joined.width = data.width * level; joined.height = data.height * level;
joinedCtx = joined.getContext('2d');
}
eachChunk(z, level, shift, function (x, y) {
var piece = M.chunkName(data.prefix, z, level, x, y);
if (joinedPieces.has(piece)) return;
var image = get(piece, prio);
if (!image) { note(piece); return; }
joinedCtx.drawImage(image, x * size, y * size);
joinedPieces.add(piece);
});
if (overview) paint(context, overview, 0, 0, overview.width, overview.height, shift[0], shift[1], data.width, data.height, true);
paint(context, joined, 0, 0, joined.width, joined.height, shift[0], shift[1], data.width, data.height, true);
}
function drawFloor(context, z, level, prio, reuseFine) {
var shift = M.shift(shifts, z), name = M.overviewName(data.prefix, z), overview = get(name, prio);
if (!level) {
if (overview) paint(context, overview, 0, 0, overview.width, overview.height, shift[0], shift[1], data.width, data.height, true);
else note(name);
return;
}
if (data.bigImage) { drawJoined(context, z, level, shift, overview, prio); return; }
var tiles = size / level, sets = chunks.get(z), crisp = level === native && view.scale * ratio > level;
eachChunk(z, level, shift, function (x, y) {
var tx = x * tiles + shift[0], ty = y * tiles + shift[1], piece = M.chunkName(data.prefix, z, level, x, y), image = get(piece, prio);
if (image) { paint(context, image, 0, 0, size, size, tx, ty, tiles, tiles, !crisp); return; }
note(piece);
var fallback = false;
for (var k = 1; levels.indexOf(level >> k) >= 0; k++) {
var parent = sets[level >> k].has(x >> k, y >> k) && peek(M.chunkName(data.prefix, z, level >> k, x >> k, y >> k));
if (!parent) continue;
var part = size >> k;
paint(context, parent, (x - ((x >> k) << k)) * part, (y - ((y >> k) << k)) * part, part, part, tx, ty, tiles, tiles, true);
fallback = true; break;
}
if (!fallback && overview) {
var w = Math.min(tiles, data.width - x * tiles), h = Math.min(tiles, data.height - y * tiles);
if (w > 0 && h > 0) paint(context, overview, x * tiles, y * tiles, w, h, tx, ty, w, h, true);
}
if (reuseFine === false) return;
levels.forEach(function (higher) {
if (higher <= level) return;
var span = size / higher;
eachChunk(z, higher, shift, function (cx, cy) {
var left = Math.max(tx, cx * span + shift[0]), top = Math.max(ty, cy * span + shift[1]);
var right = Math.min(tx + tiles, (cx + 1) * span + shift[0]), bottom = Math.min(ty + tiles, (cy + 1) * span + shift[1]);
if (right <= left || bottom <= top) return;
var cached = peek(M.chunkName(data.prefix, z, higher, cx, cy));
if (!cached) return;
context.clearRect(dx(left), dy(top), dx(right) - dx(left), dy(bottom) - dy(top));
paint(context, cached, (left - cx * span - shift[0]) * higher, (top - cy * span - shift[1]) * higher,
(right - left) * higher, (bottom - top) * higher, left, top, right - left, bottom - top, true);
});
});
});
}
function preload(level, drawn) {
var room = M.preloadRoom(cachePixels, wanted.size * size * size);
var next = levels[levels.indexOf(level) + 1];
if (preloading && next) {
var detail = [];
eachChunk(selected, next, M.shift(shifts, selected), function (x, y) { detail.push(M.chunkName(data.prefix, selected, next, x, y)); });
if (room >= detail.length * size * size) {
detail.forEach(function (name) { get(name, 2); });
room -= detail.length * size * size;
}
}
floors.slice().sort(function (a, b) { return Math.abs(a - selected) - Math.abs(b - selected); }).forEach(function (z) {
var prio = 3 + Math.abs(z - selected), pieces = [];
get(M.overviewName(data.prefix, z), prio);
if (!preloading || !level || z === selected || drawn.indexOf(z) >= 0) return;
eachChunk(z, level, M.shift(shifts, z), function (x, y) { pieces.push(M.chunkName(data.prefix, z, level, x, y)); });
room -= pieces.length * size * size;
if (room >= 0) pieces.forEach(function (name) { get(name, prio); });
});
}
function draw() {
scheduled = false;
if (!width || !height || destroyed) return;
wanted = new Set();
missing = 0;
var overview = M.overviewName(data.prefix, selected), level = M.pickLevel(levels, view.scale * ratio);
get(overview, 0);
var lower = M.lowerFloors(floors, selected, lowerOn);
var lowerLevel = (!settled && !data.bigImage) ? 0 : level;
underCtx.setTransform(1, 0, 0, 1, 0, 0);
underCtx.clearRect(0, 0, under.width, under.height);
lower.forEach(function (z) { drawFloor(underCtx, z, lowerLevel, 1, settled); });
planeCtx.setTransform(1, 0, 0, 1, 0, 0);
planeCtx.clearRect(0, 0, plane.width, plane.height);
drawFloor(planeCtx, selected, level, 0);
if (settled && !missing) preload(level, lower);
var now = performance.now();
if (onScreen !== null && selected !== onScreen && missing > 0 && now < holdUntil) {
if (!holdTimer) holdTimer = setTimeout(function () { holdTimer = 0; invalidate(); }, Math.ceil(holdUntil - now) + 1);
pump();
return;
}
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.globalAlpha = 1;
ctx.fillStyle = '#1b2024';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.globalAlpha = lowerOpacity;
ctx.drawImage(under, 0, 0);
ctx.globalAlpha = 1;
ctx.drawImage(plane, 0, 0);
onScreen = selected;
holdUntil = 0;
var active = records.get(overview), names = Array.from(wanted);
onFrame({
floor: onScreen,
level: level,
detailPending: missing,
ready: !!(active && active.state === 'loaded'),
failed: names.some(function (n) { var r = records.get(n); return r.state === 'failed' && r.prio < 2; }),
pending: names.filter(function (n) { return ['queued', 'loading'].indexOf(records.get(n).state) >= 0; }).length
});
pump();
}
function select(z) {
if (!chunks.has(z)) return;
if (z !== selected && !holdUntil) holdUntil = performance.now() + HOLD_MS;
selected = z;
scheduled = true;
draw();
}
function step(dir) {
var i = floors.indexOf(selected) + dir;
if (i >= 0 && i < floors.length) select(floors[i]);
}
var minScale = data.minScale || native * M.MIN_ZOOM, maxScale = data.maxScale || native * M.MAX_ZOOM;
function lowestScale() { return data.bigImage && width && height ? Math.max(minScale, M.coverScale(data.focusBounds, width, height)) : minScale; }
function clamp(scale) { return Math.max(lowestScale(), Math.min(maxScale, scale)); }
var panBounds = M.contentBounds(data.floors, shifts, data.focusBounds);
function constrain(next) {
if (!width || !height) return next;
return data.bigImage ? M.constrainView(next, data.focusBounds, width, height, lowestScale()) : M.limitPan(next, panBounds, width, height);
}
function fit() {
if (!width || !height) return;
var s = M.shift(shifts, selected), b = data.focusBounds;
view = M.fit([b[0] + s[0], b[1] + s[1], b[2] + s[0], b[3] + s[1]], width, height);
var scale = clamp(view.scale);
if (view.scale !== scale) view = M.zoomAt(view, scale, width / 2, height / 2);
view = constrain(view);
touched = false;
invalidate();
}
function home() {
var z = chunks.has(data.defaultFloor) ? data.defaultFloor : floors[0];
if (z !== selected && !holdUntil) holdUntil = performance.now() + HOLD_MS;
selected = z;
fit();
}
function moved() {
touched = true;
settled = false;
clearTimeout(settleTimer);
settleTimer = setTimeout(function () { settled = true; invalidate(); }, SETTLE_MS);
invalidate();
}
function setView(next) { view = constrain(next); moved(); }
function zoom(scale, x, y) { setView(M.zoomAt(view, clamp(scale), x, y)); }
function pan(x, y) { setView({ x: view.x + x, y: view.y + y, scale: view.scale }); }
function resize(w, h, dpr) {
var oldWidth = width, oldHeight = height;
width = w; height = h; ratio = dpr;
canvas.width = under.width = plane.width = Math.round(w * dpr);
canvas.height = under.height = plane.height = Math.round(h * dpr);
if (oldWidth && touched) {
view = constrain({ x: view.x + (w - oldWidth) / 2, y: view.y + (h - oldHeight) / 2, scale: view.scale });
invalidate();
} else fit();
}
function floorOnScreen() { return onScreen === null ? selected : onScreen; }
return {
native: native,
get minScale() { return lowestScale(); },
maxScale: maxScale,
constrain: constrain,
get view() { return view; },
get width() { return width; },
get height() { return height; },
get floor() { return floorOnScreen(); },
select: select, step: step, fit: fit, home: home, zoom: zoom, pan: pan, setView: setView, resize: resize, clamp: clamp, invalidate: invalidate,
setLower: function (on, opacity) { lowerOn = on; lowerOpacity = opacity; invalidate(); },
retry: function () {
records.forEach(function (r, key) { if (r.state === 'failed') records.delete(key); });
invalidate();
},
tileAt: function (px, py) {
var s = M.shift(shifts, floorOnScreen());
var x = (px - view.x) / view.scale - s[0], y = (py - view.y) / view.scale - s[1];
return (x < 0 || y < 0 || x >= data.width || y >= data.height) ? null : { x: Math.floor(x + data.origin[0]), y: Math.floor(y + data.origin[1]) };
},
screenOf: function (x, y) {
var s = M.shift(shifts, floorOnScreen());
return { x: view.x + (x - data.origin[0] + .5 + s[0]) * view.scale, y: view.y + (y - data.origin[1] + .5 + s[1]) * view.scale };
},
destroy: function () {
destroyed = true;
if (joined) joined.width = joined.height = 0;
clearTimeout(settleTimer);
clearTimeout(holdTimer);
records.forEach(function (r) { release(r.image); r.image = null; });
records.forEach(function (r) { if (r.controller) r.controller.abort(); });
records.clear();
queue = [];
}
};
};
})(globalThis);
}
(function () {
'use strict';
if (globalThis.__glaMapMention) return;
globalThis.__glaMapMention = true;
var M = globalThis.GlaMapModel;
var CFG = {"tileBase":"/images/","configTitle":"MediaWiki:InteractiveMap-{id}.json","islands":[{"id":"east-blue","name":"East Blue","pt":"East Blue (Mar)","en":"East Blue (Sea)","region":"east_blue","link":"East_Blue","photo":"East_Blue_Chests_Background.png"},{"id":"grand-line","name":"Grand Line","pt":"Grand Line (Mar)","en":"Grand Line (Sea)","region":"grand_line","link":"Grand_Line","photo":"Grand_Line_Chests_Background.png"},{"id":"foosha-village","name":"Foosha Village","pt":"Foosha Village","en":"Foosha Village","region":"east_blue","link":"Foosha_Village","pose":"foosha"},{"id":"shells-town","name":"Shells Town","pt":"Shells Town","en":"Shells Town","region":"east_blue","link":"Shells_Town","pose":"shellstown"},{"id":"samui-island","name":"Samui Island","pt":"Samui Island","en":"Samui Island","region":"east_blue","link":"Samui_Island","pose":"samui"},{"id":"orange-town","name":"Orange Town","pt":"Orange Town","en":"Orange Town","region":"east_blue","link":"Orange_Town","pose":"orange"},{"id":"syrup-village","name":"Syrup Village","pt":"Syrup Village (Vila)","en":"Syrup Village (Village)","region":"east_blue","link":"Syrup_Village","pose":"syrup","group":"Syrup Village","area":["Vila","Village"]},{"id":"syrup-forest","name":"Syrup Forest","pt":"Syrup Village (Floresta)","en":"Syrup Village (Forest)","region":"east_blue","link":"Syrup_Forest","group":"Syrup Village","area":["Floresta","Forest"]},{"id":"island-of-rare-animals","name":"Island of Rare Animals","pt":"Island of Rare Animals","en":"Island of Rare Animals","region":"east_blue","link":"Island_of_Rare_Animals","pose":"rareanimals"},{"id":"baratie","name":"Baratie","pt":"Baratie","en":"Baratie","region":"east_blue","link":"Baratie","pose":"baratie"},{"id":"cocoyasi-village","name":"Cocoyasi Village","pt":"Cocoyasi Village","en":"Cocoyasi Village","region":"east_blue","link":"Cocoyasi_Village","pose":"cocoyasi","group":"Cocoyasi Village","area":["Cocoyasi","Cocoyasi"]},{"id":"conomi-island","name":"Conomi Island","pt":"Conomi Island (Cocoyasi)","en":"Conomi Island (Cocoyasi)","region":"east_blue","link":"Conomi_Island","group":"Cocoyasi Village","area":["Conomi Island","Conomi Island"]},{"id":"loguetown","name":"Loguetown","pt":"Loguetown","en":"Loguetown","region":"east_blue","link":"Loguetown","pose":"loguetown"},{"id":"kumo-island","name":"Kumo Island","pt":"Kumo Island","en":"Kumo Island","region":"east_blue","link":"Kumo_Island","pose":"kumo"},{"id":"gunkan-island","name":"Gunkan Island","pt":"Gunkan Island","en":"Gunkan Island","region":"grand_line","link":"Gunkan_Island","pose":"gunkan"},{"id":"lost-island","name":"Lost Island","pt":"Lost Island","en":"Lost Island","region":"grand_line","link":"Lost_Island","pose":"lost"},{"id":"whisky-peak","name":"Whisky Peak","pt":"Whisky Peak","en":"Whisky Peak","region":"grand_line","link":"Whisky_Peak","pose":"whisky"},{"id":"little-garden","name":"Little Garden","pt":"Little Garden","en":"Little Garden","region":"grand_line","link":"Little_Garden","pose":"little"},{"id":"jaya","name":"Jaya","pt":"Jaya (Cidade)","en":"Jaya (City)","region":"grand_line","link":"Jaya","pose":"jaya","group":"Jaya","area":["Cidade","City"]},{"id":"jaya-2","name":"Jaya (parte 2)","pt":"Jaya (Floresta)","en":"Jaya (Forest)","region":"grand_line","link":"Jaya_Forest","group":"Jaya","area":["Floresta","Forest"]},{"id":"g7-marine-base","name":"G-7 Marine Base","pt":"G-7 Marine Base","en":"G-7 Marine Base","region":"grand_line","link":"G-7_Marine_Base","pose":"marinebase"},{"id":"drum-island","name":"Drum Island","pt":"Drum Island","en":"Drum Island","region":"grand_line","link":"Drum_Island","pose":"drum"},{"id":"nanimonai-island","name":"Nanimonai Island","pt":"Nanimonai Island","en":"Nanimonai Island","region":"grand_line","link":"Nanimonai_Island","pose":"nanimonai"},{"id":"nige-hashiru","name":"Nige Hashiru","pt":"Nige Hashiru","en":"Nige Hashiru","region":"grand_line","link":"Nige_Hashiru","pose":"nige"},{"id":"alabasta-east","name":"Alabasta East (Alubarna)","pt":"Alabasta East (Alubarna)","en":"Alabasta East (Alubarna)","region":"grand_line","link":"Alabasta_East","pose":"nanohana"},{"id":"alabasta-west","name":"Alabasta West (Rainbase)","pt":"Alabasta West (Rainbase)","en":"Alabasta West (Rainbase)","region":"grand_line","link":"Alabasta_West","pose":"rainbase"},{"id":"skypiea","name":"Skypiea","pt":"Skypiea","en":"Skypiea","region":"grand_line","link":"Skypiea","pose":"skypiea"},{"id":"water-7","name":"Water 7","pt":"Water 7","en":"Water 7","region":"grand_line","link":"Water_7","pose":"water7"},{"id":"enies-lobby","name":"Enies Lobby","pt":"Enies Lobby","en":"Enies Lobby","region":"grand_line","link":"Enies_Lobby","pose":"enies"},{"id":"amazon-lily","name":"Amazon Lily","pt":"Amazon Lily","en":"Amazon Lily","region":"grand_line","link":"Amazon_Lily","pose":"amazonlily"},{"id":"kuraigana-island","name":"Kuraigana Island","pt":"Kuraigana Island","en":"Kuraigana Island","region":"grand_line","link":"Kuraigana_Island","pose":"kuraigana"},{"id":"sabaody-archipelago","name":"Sabaody Archipelago","pt":"Sabaody Archipelago","en":"Sabaody Archipelago","region":"grand_line","link":"Sabaody_Archipelago","pose":"sabaody"},{"id":"alliance-base","name":"Alliance Base","pt":"Base da Aliança","en":"Alliance Base","region":"alliance","link":"Alliance_Base"},{"id":"black-market","name":"Black Market","pt":"Black Market","en":"Black Market","region":"market","link":"Black_Market"}],"hashedTiles":true,"tileFallback":"/Special:Redirect/file/"};
var CSS = "/* {{MapMention}} modal. The link itself (icon) is styled by Widget:MapMention so it shows before this script loads. */\n/* The skin scrolls through <body> (overflow-y:scroll). Lock it there: overflow on <html> stops body's overflow from\n reaching the viewport, body turns into a 100vh clip box and the page content below it vanishes. */\nhtml.gla-mm-open{scrollbar-gutter:stable}\nhtml.gla-mm-open body{overflow:hidden!important}\n.gla-mm{position:fixed;inset:0;z-index:1000;display:grid;place-items:center;padding:24px;font:14px/1.4 \"Noto Sans\",\"Segoe UI\",sans-serif;color:#cfccc5}\n.gla-mm *{box-sizing:border-box}\n.gla-mm [hidden]{display:none!important}\n.gla-mm__backdrop{position:absolute;inset:0;background:#05070acc}\n.gla-mm__box{position:relative;display:flex;flex-direction:column;width:min(760px,100%);height:min(480px,100%);background:#1e2124;border:1px solid #3a3f45;border-radius:12px;box-shadow:0 18px 50px #000b;overflow:hidden}\n.gla-mm button{font:inherit;color:#cfccc5;background:transparent;border:1px solid #3a3f45;border-radius:7px;cursor:pointer}\n.gla-mm button:hover{background:#363d44;border-color:#59636e}\n.gla-mm button:focus-visible,.gla-mm a:focus-visible{outline:2px solid #86b0d8;outline-offset:2px}\n.gla-mm button:disabled{opacity:.35;cursor:default}\n.gla-mm__view{position:relative;flex:1;min-height:0;overflow:hidden;background:#1e2124;cursor:grab;touch-action:none;outline:0}\n.gla-mm__view--drag{cursor:grabbing}\n.gla-mm__canvas{display:block;width:100%;height:100%;filter:none!important}\n.gla-mm .gla-mm__object{position:absolute;z-index:0;max-width:none!important;margin:0;border:0;pointer-events:none}\n.gla-mm__cross{position:absolute;z-index:1;pointer-events:none;background:#000c;box-shadow:0 0 0 .5px #fff6}\n.gla-mm__cross--x{left:0;right:0;height:1px}\n.gla-mm__cross--y{top:0;bottom:0;width:1px}\n.gla-mm__pin{position:absolute;z-index:2;box-sizing:border-box;transform:translate(-50%,-50%);border:2px solid #ffd54a;border-radius:2px;background:#ffd54a33;box-shadow:0 0 0 1px #000a,0 0 8px #000a;pointer-events:none}\n.gla-mm__status{position:absolute;z-index:3;left:50%;top:50%;transform:translate(-50%,-50%);padding:8px 14px;background:#14181bf0;border:1px solid #3a3f45;border-radius:8px}\n.gla-mm__controls{position:absolute;z-index:3;left:12px;top:12px;display:grid;gap:9px;cursor:default}\n.gla-mm__stack{display:grid;overflow:hidden;border:2px solid #0003;border-radius:5px;background:#fff;box-shadow:0 1px 5px #0005;background-clip:padding-box}\n.gla-mm .gla-mm__stack button{display:grid;place-items:center;width:34px;height:34px;padding:0;border:0;border-radius:0;background:#fff;color:#222;font:bold 22px/1 Arial,sans-serif}\n.gla-mm .gla-mm__stack button:hover{background:#ececec;color:#000}\n.gla-mm .gla-mm__stack button+button{border-top:1px solid #ccc}\n.gla-mm .gla-mm__stack button:disabled{opacity:1;color:#aaa;background:#f4f4f4}\n.gla-mm__stack svg{display:block;pointer-events:none}\n.gla-mm .gla-mm__go{position:absolute;z-index:3;left:50%;bottom:14px;transform:translateX(-50%);padding:7px 14px;background:#14181bf2;border-color:#ffd54a;color:#ffe48a;font-size:13px;box-shadow:0 4px 14px #0008}\n.gla-mm .gla-mm__go:hover{background:#2e3237;border-color:#ffe7a3}\n/* One-shot arrival, same as the Map page: two rings leave the square, then it rests. */\n.gla-mm__pin--arrive{animation:gla-mm-pin-flash 1.15s ease-out 1}\n.gla-mm__pin--arrive::before,.gla-mm__pin--arrive::after{content:\"\";position:absolute;inset:-1px;border:2px solid #ffe7a3;border-radius:2px;pointer-events:none;opacity:0;animation:gla-mm-pin-ring 1.05s ease-out 1 forwards}\n.gla-mm__pin--arrive::after{animation-delay:.16s;border-color:#ffd54a}\n@keyframes gla-mm-pin-flash{0%{background:#fff6ccee;box-shadow:0 0 0 0 #ffd54acc}28%{background:#ffd54ad9;box-shadow:0 0 0 6px #ffd54a66}100%{background:#ffd54a33;box-shadow:0 0 0 1px #000a,0 0 8px #000a}}\n@keyframes gla-mm-pin-ring{0%{transform:scale(1);opacity:.95}100%{transform:scale(3.4);opacity:0}}\n@media(prefers-reduced-motion:reduce){.gla-mm__pin--arrive,.gla-mm__pin--arrive::before,.gla-mm__pin--arrive::after{animation:none}}\n@media(max-width:600px){.gla-mm{padding:8px}.gla-mm__box{height:min(560px,100%)}}\n.gla-mm,.gla-mm *{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}\n.gla-mm img,.gla-mm a,.gla-mm button{-webkit-user-drag:none}\n";
var copy = {
pt: { close: 'Fechar', open: 'Abrir no mapa completo', loading: 'Carregando mapa…', failed: 'Não foi possível carregar o mapa.', zoomIn: 'Ampliar', zoomOut: 'Reduzir', floorUp: 'Subir andar', floorDown: 'Descer andar', goMark: 'Ir até a marcação', dialog: 'Localização no mapa' },
en: { close: 'Close', open: 'Open in the full map', loading: 'Loading map…', failed: 'Could not load the map.', zoomIn: 'Zoom in', zoomOut: 'Zoom out', floorUp: 'Go up a floor', floorDown: 'Go down a floor', goMark: 'Go to mark', dialog: 'Location on the map' }
};
var lang = (document.documentElement.lang || 'pt').indexOf('en') === 0 ? 'en' : 'pt';
window.addEventListener('gla:langChanged', function (e) { var d = e.detail || {}; lang = (d.norm || d.lang || d.language || '') === 'en' ? 'en' : 'pt'; });
function entry(name) {
var key = String(name || '').trim().replace(/ /g, '_').toLowerCase();
return CFG.islands.find(function (item) { return item.id === key || String(item.link).toLowerCase() === key; });
}
function parseTile(text) {
var found = /^\s*(\d{1,5})[_,\s]+(\d{1,5})[_,\s]+(\d{1,2})\s*$/.exec(String(text || ''));
return found ? { x: Number(found[1]), y: Number(found[2]), z: Number(found[3]) } : null;
}
function el(tag, className, parent) { var node = document.createElement(tag); if (className) node.className = className; if (parent) parent.appendChild(node); return node; }
function script() { return (globalThis.mw && mw.config && mw.config.get('wgScript')) || '/index.php'; }
var payloads = {};
function load(island) {
if (!payloads[island.id]) {
var url = script() + '?title=' + encodeURIComponent(CFG.configTitle.split('{id}').join(island.id)) + '&action=raw&ctype=application/json&maxage=300&smaxage=300';
payloads[island.id] = fetch(url, { credentials: 'same-origin' })
.then(function (r) { if (!r.ok) throw new Error('HTTP ' + r.status); return r.json(); })
.catch(function (error) { delete payloads[island.id]; throw error; });
}
return payloads[island.id];
}
var current = null;
function close() {
if (!current) return;
var state = current; current = null;
state.destroy();
state.root.remove();
document.documentElement.classList.remove('gla-mm-open');
if (state.opener && state.opener.focus) state.opener.focus({ preventScroll: true });
}
function open(island, tile, label, opener) {
close();
var t = copy[lang];
var root = el('div', 'gla-mm', document.body);
root.setAttribute('role', 'dialog'); root.setAttribute('aria-modal', 'true');
root.setAttribute('aria-label', t.dialog + ': ' + (island[lang] || island.name) + (label ? ' · ' + label : ''));
['dragstart', 'selectstart', 'contextmenu'].forEach(function (type) { root.addEventListener(type, function (e) { e.preventDefault(); }); });
var backdrop = el('div', 'gla-mm__backdrop', root);
var box = el('div', 'gla-mm__box', root);
var view = el('div', 'gla-mm__view', box); view.tabIndex = -1;
var canvas = el('canvas', 'gla-mm__canvas', view);
var crossX = el('div', 'gla-mm__cross gla-mm__cross--x', view), crossY = el('div', 'gla-mm__cross gla-mm__cross--y', view);
var pin = el('div', 'gla-mm__pin', view);
var controls = el('div', 'gla-mm__controls', view);
function control(stack, text, label) {
var b = el('button', '', stack); b.type = 'button'; b.setAttribute('aria-label', label); b.title = label;
if (text) b.textContent = text;
return b;
}
var zoom = el('div', 'gla-mm__stack', controls), floorsStack = el('div', 'gla-mm__stack', controls);
var zoomIn = control(zoom, '+', t.zoomIn), zoomOut = control(zoom, '−', t.zoomOut);
function chevron(d) { return '<svg viewBox="0 0 20 20" width="18" height="18" aria-hidden="true" focusable="false"><path d="' + d + '" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square"/></svg>'; }
var floorUp = control(floorsStack, '', t.floorUp), floorDown = control(floorsStack, '', t.floorDown);
floorUp.innerHTML = chevron('m5 12 5-5 5 5'); floorDown.innerHTML = chevron('m5 8 5 5 5-5');
var go = el('button', 'gla-mm__go', view); go.type = 'button'; go.textContent = t.goMark; go.hidden = true;
var status = el('div', 'gla-mm__status', view); status.textContent = t.loading;
document.documentElement.classList.add('gla-mm-open');
var map = null, observer = null, dead = false, flight = 0;
var state = { root: root, opener: opener, destroy: function () {
dead = true;
if (flight) cancelAnimationFrame(flight);
if (observer) observer.disconnect();
if (map) map.destroy();
document.removeEventListener('keydown', onKey, true);
} };
current = state;
function onKey(e) { if (e.key === 'Escape') { e.preventDefault(); close(); } }
document.addEventListener('keydown', onKey, true);
backdrop.addEventListener('click', close);
view.focus({ preventScroll: true });
load(island).then(function (payload) {
if (dead) return;
var data = payload.map, shifts = data.floorShift || {};
function tileUrls(name) {
return CFG.hashedTiles ? [CFG.tileBase + M.hashedPath(name), CFG.tileFallback + encodeURIComponent(name)] : [CFG.tileBase.split('{id}').join(island.id) + encodeURIComponent(name)];
}
var start = 0, low = 0, floors = data.floors.map(function (f) { return f.z; }).sort(function (a, b) { return a - b; });
var pulse = true, readyAt = 0;
var objects = (data.objects || []).map(function (o) {
var img = document.createElement('img'); img.className = 'gla-mm__object'; img.alt = ''; img.src = o.src; img.hidden = true;
view.insertBefore(img, crossX);
return { data: o, el: img };
});
map = M.createRenderer({ map: data, canvas: canvas, shifts: shifts, tileUrls: tileUrls, preload: true, cachePixels: 80e6, onFrame: function (info) {
status.hidden = info.ready || info.failed;
if (info.failed) { status.hidden = false; status.textContent = t.failed; }
var p = map.screenOf(tile.x, tile.y), size = Math.max(8, map.view.scale), here = info.floor === tile.z;
crossX.style.top = p.y + 'px'; crossY.style.left = p.x + 'px';
pin.style.left = p.x + 'px'; pin.style.top = p.y + 'px'; pin.style.width = pin.style.height = size + 'px';
pin.hidden = crossX.hidden = crossY.hidden = !here;
objects.forEach(function (o) {
var on = o.data.z === info.floor;
if (on) {
var r = M.objectRect(o.data, map.screenOf(o.data.x, o.data.y), map.view.scale, map.native), s = o.el.style;
s.left = r.left + 'px'; s.top = r.top + 'px';
s.setProperty('width', r.width + 'px', 'important'); s.setProperty('height', r.height + 'px', 'important');
s.imageRendering = map.view.scale >= map.native ? 'pixelated' : 'auto';
}
if (o.el.hidden === on) o.el.hidden = !on;
});
var inView = here && p.x >= 0 && p.y >= 0 && p.x <= map.width && p.y <= map.height;
go.hidden = inView || !map.width || !!flight;
zoomIn.disabled = map.view.scale >= map.maxScale - 1e-9;
zoomOut.disabled = map.view.scale <= low + 1e-9;
floorUp.disabled = info.floor === floors[0];
floorDown.disabled = info.floor === floors[floors.length - 1];
if ((info.ready || info.failed) && !readyAt) readyAt = performance.now();
var sharp = info.ready && (!info.detailPending || performance.now() - readyAt > 700);
if (pulse && sharp && inView && !flight) {
pulse = false;
pin.classList.remove('gla-mm__pin--arrive'); void pin.offsetWidth; pin.classList.add('gla-mm__pin--arrive');
clearTimeout(pin._pulse); pin._pulse = setTimeout(function () { pin.classList.remove('gla-mm__pin--arrive'); }, 1300);
}
} });
function stopFlight() { if (flight) cancelAnimationFrame(flight); flight = 0; }
function flyHome() {
stopFlight();
map.select(tile.z);
var from = map.view, to = map.constrain(M.viewOnTile(data, shifts, tile, Math.max(map.view.scale, start), map.width, map.height));
if (window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches) { map.setView(to); pulse = true; return; }
var begin = performance.now();
function travel(now) {
var k = Math.min(1, Math.max(0, (now - begin) / 800));
map.setView(M.flightView(from, to, map.width, map.height, k));
flight = k < 1 ? requestAnimationFrame(travel) : 0;
if (!flight) { pulse = true; map.invalidate(); }
}
travel(begin);
}
go.addEventListener('click', flyHome);
floorUp.addEventListener('click', function () { stopFlight(); map.step(-1); });
floorDown.addEventListener('click', function () { stopFlight(); map.step(1); });
map.setLower(true, 0.35);
function centre(scale) { map.setView(M.viewOnTile(data, shifts, tile, scale, map.width, map.height)); }
function zoomTo(scale, x, y) {
scale = Math.max(low, Math.min(map.maxScale, scale));
map.setView(M.zoomAt(map.view, scale, x === undefined ? map.width / 2 : x, y === undefined ? map.height / 2 : y));
}
var first = true;
observer = new ResizeObserver(function () {
var r = view.getBoundingClientRect();
if (!r.width || !r.height) return;
map.resize(r.width, r.height, Math.min(window.devicePixelRatio || 1, 2));
if (first) {
first = false;
start = map.clamp(data.chestScale || map.native * M.CHEST_ZOOM);
low = Math.max(map.minScale, start * 0.6);
map.select(tile.z);
centre(start);
}
});
observer.observe(view);
zoomIn.addEventListener('click', function () { stopFlight(); zoomTo(map.view.scale * 1.4); });
zoomOut.addEventListener('click', function () { stopFlight(); zoomTo(map.view.scale / 1.4); });
var floorWheel = {};
view.addEventListener('wheel', function (e) {
e.preventDefault(); stopFlight();
if (e.ctrlKey) { var step = M.floorStep(floorWheel, e.deltaY, e.deltaMode, Date.now()); if (step) map.step(step); return; }
var r = view.getBoundingClientRect();
zoomTo(map.view.scale * Math.exp(-Math.max(-120, Math.min(120, e.deltaY)) * 0.004), e.clientX - r.left, e.clientY - r.top);
}, { passive: false });
var drag = null;
view.addEventListener('pointerdown', function (e) {
if (e.target.closest('button') || (e.pointerType === 'mouse' && e.button !== 0)) return;
stopFlight();
drag = { id: e.pointerId, x: e.clientX, y: e.clientY, view: { x: map.view.x, y: map.view.y, scale: map.view.scale } };
view.setPointerCapture(e.pointerId); view.classList.add('gla-mm__view--drag');
});
view.addEventListener('pointermove', function (e) {
if (!drag || drag.id !== e.pointerId) return;
map.setView({ x: drag.view.x + e.clientX - drag.x, y: drag.view.y + e.clientY - drag.y, scale: drag.view.scale });
});
['pointerup', 'pointercancel'].forEach(function (name) {
view.addEventListener(name, function (e) { if (drag && drag.id === e.pointerId) { drag = null; view.classList.remove('gla-mm__view--drag'); } });
});
}).catch(function () { if (!dead) { status.hidden = false; status.textContent = t.failed; } });
}
if (CSS) { var style = document.createElement('style'); style.textContent = CSS; document.head.appendChild(style); }
document.addEventListener('click', function (e) {
if (e.defaultPrevented || e.button !== 0 || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey) return;
var holder = e.target.closest && e.target.closest('.gla-mention');
var link = holder && e.target.closest('a');
if (!link || !holder.contains(link)) return;
var island = entry(holder.getAttribute('data-map')), tile = parseTile(holder.getAttribute('data-tile'));
if (!island || !tile) return;
e.preventDefault();
open(island, tile, link.textContent.trim(), link);
});
})();