98 lines
2.3 KiB
JavaScript
98 lines
2.3 KiB
JavaScript
import {
|
|
WORKER_OFFSCREEN_CANVAS
|
|
} from "./chunk-5XHD7RSF.js";
|
|
|
|
// node_modules/ol/dom.js
|
|
function createCanvasContext2D(width, height, canvasPool, settings) {
|
|
let canvas;
|
|
if (canvasPool && canvasPool.length) {
|
|
canvas = /** @type {HTMLCanvasElement} */
|
|
canvasPool.shift();
|
|
} else if (WORKER_OFFSCREEN_CANVAS) {
|
|
canvas = new OffscreenCanvas(width || 300, height || 300);
|
|
} else {
|
|
canvas = document.createElement("canvas");
|
|
}
|
|
if (width) {
|
|
canvas.width = width;
|
|
}
|
|
if (height) {
|
|
canvas.height = height;
|
|
}
|
|
return (
|
|
/** @type {CanvasRenderingContext2D} */
|
|
canvas.getContext("2d", settings)
|
|
);
|
|
}
|
|
var sharedCanvasContext;
|
|
function getSharedCanvasContext2D() {
|
|
if (!sharedCanvasContext) {
|
|
sharedCanvasContext = createCanvasContext2D(1, 1);
|
|
}
|
|
return sharedCanvasContext;
|
|
}
|
|
function releaseCanvas(context) {
|
|
const canvas = context.canvas;
|
|
canvas.width = 1;
|
|
canvas.height = 1;
|
|
context.clearRect(0, 0, 1, 1);
|
|
}
|
|
function outerWidth(element) {
|
|
let width = element.offsetWidth;
|
|
const style = getComputedStyle(element);
|
|
width += parseInt(style.marginLeft, 10) + parseInt(style.marginRight, 10);
|
|
return width;
|
|
}
|
|
function outerHeight(element) {
|
|
let height = element.offsetHeight;
|
|
const style = getComputedStyle(element);
|
|
height += parseInt(style.marginTop, 10) + parseInt(style.marginBottom, 10);
|
|
return height;
|
|
}
|
|
function replaceNode(newNode, oldNode) {
|
|
const parent = oldNode.parentNode;
|
|
if (parent) {
|
|
parent.replaceChild(newNode, oldNode);
|
|
}
|
|
}
|
|
function removeChildren(node) {
|
|
while (node.lastChild) {
|
|
node.lastChild.remove();
|
|
}
|
|
}
|
|
function replaceChildren(node, children) {
|
|
const oldChildren = node.childNodes;
|
|
for (let i = 0; true; ++i) {
|
|
const oldChild = oldChildren[i];
|
|
const newChild = children[i];
|
|
if (!oldChild && !newChild) {
|
|
break;
|
|
}
|
|
if (oldChild === newChild) {
|
|
continue;
|
|
}
|
|
if (!oldChild) {
|
|
node.appendChild(newChild);
|
|
continue;
|
|
}
|
|
if (!newChild) {
|
|
node.removeChild(oldChild);
|
|
--i;
|
|
continue;
|
|
}
|
|
node.insertBefore(newChild, oldChild);
|
|
}
|
|
}
|
|
|
|
export {
|
|
createCanvasContext2D,
|
|
getSharedCanvasContext2D,
|
|
releaseCanvas,
|
|
outerWidth,
|
|
outerHeight,
|
|
replaceNode,
|
|
removeChildren,
|
|
replaceChildren
|
|
};
|
|
//# sourceMappingURL=chunk-YWIWRQT2.js.map
|