wiki-plugin-wmap 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +39 -0
- package/client/dialog/index.html +12 -0
- package/client/wmap.css +34 -0
- package/client/wmap.js +4630 -0
- package/factory.json +5 -0
- package/package.json +42 -0
- package/pages/about-wmap-plugin +98 -0
package/client/wmap.js
ADDED
|
@@ -0,0 +1,4630 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
|
|
28
|
+
// node_modules/.pnpm/canvas@3.2.0/node_modules/canvas/browser.js
|
|
29
|
+
var require_browser = __commonJS({
|
|
30
|
+
"node_modules/.pnpm/canvas@3.2.0/node_modules/canvas/browser.js"(exports) {
|
|
31
|
+
exports.createCanvas = function(width, height) {
|
|
32
|
+
return Object.assign(document.createElement("canvas"), { width, height });
|
|
33
|
+
};
|
|
34
|
+
exports.createImageData = function(array, width, height) {
|
|
35
|
+
switch (arguments.length) {
|
|
36
|
+
case 0:
|
|
37
|
+
return new ImageData();
|
|
38
|
+
case 1:
|
|
39
|
+
return new ImageData(array);
|
|
40
|
+
case 2:
|
|
41
|
+
return new ImageData(array, width);
|
|
42
|
+
default:
|
|
43
|
+
return new ImageData(array, width, height);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.loadImage = function(src, options) {
|
|
47
|
+
return new Promise(function(resolve, reject) {
|
|
48
|
+
const image = Object.assign(document.createElement("img"), options);
|
|
49
|
+
function cleanup() {
|
|
50
|
+
image.onload = null;
|
|
51
|
+
image.onerror = null;
|
|
52
|
+
}
|
|
53
|
+
image.onload = function() {
|
|
54
|
+
cleanup();
|
|
55
|
+
resolve(image);
|
|
56
|
+
};
|
|
57
|
+
image.onerror = function() {
|
|
58
|
+
cleanup();
|
|
59
|
+
reject(new Error('Failed to load the image "' + src + '"'));
|
|
60
|
+
};
|
|
61
|
+
image.src = src;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// node_modules/.pnpm/dompurify@3.3.1/node_modules/dompurify/dist/purify.cjs.js
|
|
68
|
+
var require_purify_cjs = __commonJS({
|
|
69
|
+
"node_modules/.pnpm/dompurify@3.3.1/node_modules/dompurify/dist/purify.cjs.js"(exports, module) {
|
|
70
|
+
"use strict";
|
|
71
|
+
var {
|
|
72
|
+
entries,
|
|
73
|
+
setPrototypeOf,
|
|
74
|
+
isFrozen,
|
|
75
|
+
getPrototypeOf,
|
|
76
|
+
getOwnPropertyDescriptor
|
|
77
|
+
} = Object;
|
|
78
|
+
var {
|
|
79
|
+
freeze,
|
|
80
|
+
seal,
|
|
81
|
+
create
|
|
82
|
+
} = Object;
|
|
83
|
+
var {
|
|
84
|
+
apply,
|
|
85
|
+
construct
|
|
86
|
+
} = typeof Reflect !== "undefined" && Reflect;
|
|
87
|
+
if (!freeze) {
|
|
88
|
+
freeze = function freeze2(x) {
|
|
89
|
+
return x;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (!seal) {
|
|
93
|
+
seal = function seal2(x) {
|
|
94
|
+
return x;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (!apply) {
|
|
98
|
+
apply = function apply2(func, thisArg) {
|
|
99
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
100
|
+
args[_key - 2] = arguments[_key];
|
|
101
|
+
}
|
|
102
|
+
return func.apply(thisArg, args);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (!construct) {
|
|
106
|
+
construct = function construct2(Func) {
|
|
107
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
108
|
+
args[_key2 - 1] = arguments[_key2];
|
|
109
|
+
}
|
|
110
|
+
return new Func(...args);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
var arrayForEach = unapply(Array.prototype.forEach);
|
|
114
|
+
var arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
|
|
115
|
+
var arrayPop = unapply(Array.prototype.pop);
|
|
116
|
+
var arrayPush = unapply(Array.prototype.push);
|
|
117
|
+
var arraySplice = unapply(Array.prototype.splice);
|
|
118
|
+
var stringToLowerCase = unapply(String.prototype.toLowerCase);
|
|
119
|
+
var stringToString = unapply(String.prototype.toString);
|
|
120
|
+
var stringMatch = unapply(String.prototype.match);
|
|
121
|
+
var stringReplace = unapply(String.prototype.replace);
|
|
122
|
+
var stringIndexOf = unapply(String.prototype.indexOf);
|
|
123
|
+
var stringTrim = unapply(String.prototype.trim);
|
|
124
|
+
var objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
|
125
|
+
var regExpTest = unapply(RegExp.prototype.test);
|
|
126
|
+
var typeErrorCreate = unconstruct(TypeError);
|
|
127
|
+
function unapply(func) {
|
|
128
|
+
return function(thisArg) {
|
|
129
|
+
if (thisArg instanceof RegExp) {
|
|
130
|
+
thisArg.lastIndex = 0;
|
|
131
|
+
}
|
|
132
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
133
|
+
args[_key3 - 1] = arguments[_key3];
|
|
134
|
+
}
|
|
135
|
+
return apply(func, thisArg, args);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function unconstruct(Func) {
|
|
139
|
+
return function() {
|
|
140
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
141
|
+
args[_key4] = arguments[_key4];
|
|
142
|
+
}
|
|
143
|
+
return construct(Func, args);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function addToSet(set, array) {
|
|
147
|
+
let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
|
|
148
|
+
if (setPrototypeOf) {
|
|
149
|
+
setPrototypeOf(set, null);
|
|
150
|
+
}
|
|
151
|
+
let l = array.length;
|
|
152
|
+
while (l--) {
|
|
153
|
+
let element = array[l];
|
|
154
|
+
if (typeof element === "string") {
|
|
155
|
+
const lcElement = transformCaseFunc(element);
|
|
156
|
+
if (lcElement !== element) {
|
|
157
|
+
if (!isFrozen(array)) {
|
|
158
|
+
array[l] = lcElement;
|
|
159
|
+
}
|
|
160
|
+
element = lcElement;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
set[element] = true;
|
|
164
|
+
}
|
|
165
|
+
return set;
|
|
166
|
+
}
|
|
167
|
+
function cleanArray(array) {
|
|
168
|
+
for (let index = 0; index < array.length; index++) {
|
|
169
|
+
const isPropertyExist = objectHasOwnProperty(array, index);
|
|
170
|
+
if (!isPropertyExist) {
|
|
171
|
+
array[index] = null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return array;
|
|
175
|
+
}
|
|
176
|
+
function clone2(object2) {
|
|
177
|
+
const newObject = create(null);
|
|
178
|
+
for (const [property, value] of entries(object2)) {
|
|
179
|
+
const isPropertyExist = objectHasOwnProperty(object2, property);
|
|
180
|
+
if (isPropertyExist) {
|
|
181
|
+
if (Array.isArray(value)) {
|
|
182
|
+
newObject[property] = cleanArray(value);
|
|
183
|
+
} else if (value && typeof value === "object" && value.constructor === Object) {
|
|
184
|
+
newObject[property] = clone2(value);
|
|
185
|
+
} else {
|
|
186
|
+
newObject[property] = value;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return newObject;
|
|
191
|
+
}
|
|
192
|
+
function lookupGetter(object2, prop) {
|
|
193
|
+
while (object2 !== null) {
|
|
194
|
+
const desc = getOwnPropertyDescriptor(object2, prop);
|
|
195
|
+
if (desc) {
|
|
196
|
+
if (desc.get) {
|
|
197
|
+
return unapply(desc.get);
|
|
198
|
+
}
|
|
199
|
+
if (typeof desc.value === "function") {
|
|
200
|
+
return unapply(desc.value);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
object2 = getPrototypeOf(object2);
|
|
204
|
+
}
|
|
205
|
+
function fallbackValue() {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
return fallbackValue;
|
|
209
|
+
}
|
|
210
|
+
var html$1 = freeze(["a", "abbr", "acronym", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "decorator", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "element", "em", "fieldset", "figcaption", "figure", "font", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "marquee", "menu", "menuitem", "meter", "nav", "nobr", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "search", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "tr", "track", "tt", "u", "ul", "var", "video", "wbr"]);
|
|
211
|
+
var svg$1 = freeze(["svg", "a", "altglyph", "altglyphdef", "altglyphitem", "animatecolor", "animatemotion", "animatetransform", "circle", "clippath", "defs", "desc", "ellipse", "enterkeyhint", "exportparts", "filter", "font", "g", "glyph", "glyphref", "hkern", "image", "inputmode", "line", "lineargradient", "marker", "mask", "metadata", "mpath", "part", "path", "pattern", "polygon", "polyline", "radialgradient", "rect", "stop", "style", "switch", "symbol", "text", "textpath", "title", "tref", "tspan", "view", "vkern"]);
|
|
212
|
+
var svgFilters = freeze(["feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence"]);
|
|
213
|
+
var svgDisallowed = freeze(["animate", "color-profile", "cursor", "discard", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignobject", "hatch", "hatchpath", "mesh", "meshgradient", "meshpatch", "meshrow", "missing-glyph", "script", "set", "solidcolor", "unknown", "use"]);
|
|
214
|
+
var mathMl$1 = freeze(["math", "menclose", "merror", "mfenced", "mfrac", "mglyph", "mi", "mlabeledtr", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msup", "msubsup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "mprescripts"]);
|
|
215
|
+
var mathMlDisallowed = freeze(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]);
|
|
216
|
+
var text = freeze(["#text"]);
|
|
217
|
+
var html = freeze(["accept", "action", "align", "alt", "autocapitalize", "autocomplete", "autopictureinpicture", "autoplay", "background", "bgcolor", "border", "capture", "cellpadding", "cellspacing", "checked", "cite", "class", "clear", "color", "cols", "colspan", "controls", "controlslist", "coords", "crossorigin", "datetime", "decoding", "default", "dir", "disabled", "disablepictureinpicture", "disableremoteplayback", "download", "draggable", "enctype", "enterkeyhint", "exportparts", "face", "for", "headers", "height", "hidden", "high", "href", "hreflang", "id", "inert", "inputmode", "integrity", "ismap", "kind", "label", "lang", "list", "loading", "loop", "low", "max", "maxlength", "media", "method", "min", "minlength", "multiple", "muted", "name", "nonce", "noshade", "novalidate", "nowrap", "open", "optimum", "part", "pattern", "placeholder", "playsinline", "popover", "popovertarget", "popovertargetaction", "poster", "preload", "pubdate", "radiogroup", "readonly", "rel", "required", "rev", "reversed", "role", "rows", "rowspan", "spellcheck", "scope", "selected", "shape", "size", "sizes", "slot", "span", "srclang", "start", "src", "srcset", "step", "style", "summary", "tabindex", "title", "translate", "type", "usemap", "valign", "value", "width", "wrap", "xmlns", "slot"]);
|
|
218
|
+
var svg = freeze(["accent-height", "accumulate", "additive", "alignment-baseline", "amplitude", "ascent", "attributename", "attributetype", "azimuth", "basefrequency", "baseline-shift", "begin", "bias", "by", "class", "clip", "clippathunits", "clip-path", "clip-rule", "color", "color-interpolation", "color-interpolation-filters", "color-profile", "color-rendering", "cx", "cy", "d", "dx", "dy", "diffuseconstant", "direction", "display", "divisor", "dur", "edgemode", "elevation", "end", "exponent", "fill", "fill-opacity", "fill-rule", "filter", "filterunits", "flood-color", "flood-opacity", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "fx", "fy", "g1", "g2", "glyph-name", "glyphref", "gradientunits", "gradienttransform", "height", "href", "id", "image-rendering", "in", "in2", "intercept", "k", "k1", "k2", "k3", "k4", "kerning", "keypoints", "keysplines", "keytimes", "lang", "lengthadjust", "letter-spacing", "kernelmatrix", "kernelunitlength", "lighting-color", "local", "marker-end", "marker-mid", "marker-start", "markerheight", "markerunits", "markerwidth", "maskcontentunits", "maskunits", "max", "mask", "mask-type", "media", "method", "mode", "min", "name", "numoctaves", "offset", "operator", "opacity", "order", "orient", "orientation", "origin", "overflow", "paint-order", "path", "pathlength", "patterncontentunits", "patterntransform", "patternunits", "points", "preservealpha", "preserveaspectratio", "primitiveunits", "r", "rx", "ry", "radius", "refx", "refy", "repeatcount", "repeatdur", "restart", "result", "rotate", "scale", "seed", "shape-rendering", "slope", "specularconstant", "specularexponent", "spreadmethod", "startoffset", "stddeviation", "stitchtiles", "stop-color", "stop-opacity", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke", "stroke-width", "style", "surfacescale", "systemlanguage", "tabindex", "tablevalues", "targetx", "targety", "transform", "transform-origin", "text-anchor", "text-decoration", "text-rendering", "textlength", "type", "u1", "u2", "unicode", "values", "viewbox", "visibility", "version", "vert-adv-y", "vert-origin-x", "vert-origin-y", "width", "word-spacing", "wrap", "writing-mode", "xchannelselector", "ychannelselector", "x", "x1", "x2", "xmlns", "y", "y1", "y2", "z", "zoomandpan"]);
|
|
219
|
+
var mathMl = freeze(["accent", "accentunder", "align", "bevelled", "close", "columnsalign", "columnlines", "columnspan", "denomalign", "depth", "dir", "display", "displaystyle", "encoding", "fence", "frame", "height", "href", "id", "largeop", "length", "linethickness", "lspace", "lquote", "mathbackground", "mathcolor", "mathsize", "mathvariant", "maxsize", "minsize", "movablelimits", "notation", "numalign", "open", "rowalign", "rowlines", "rowspacing", "rowspan", "rspace", "rquote", "scriptlevel", "scriptminsize", "scriptsizemultiplier", "selection", "separator", "separators", "stretchy", "subscriptshift", "supscriptshift", "symmetric", "voffset", "width", "xmlns"]);
|
|
220
|
+
var xml = freeze(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]);
|
|
221
|
+
var MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm);
|
|
222
|
+
var ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
|
|
223
|
+
var TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm);
|
|
224
|
+
var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
|
|
225
|
+
var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
|
|
226
|
+
var IS_ALLOWED_URI = seal(
|
|
227
|
+
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
|
|
228
|
+
// eslint-disable-line no-useless-escape
|
|
229
|
+
);
|
|
230
|
+
var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
|
|
231
|
+
var ATTR_WHITESPACE = seal(
|
|
232
|
+
/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g
|
|
233
|
+
// eslint-disable-line no-control-regex
|
|
234
|
+
);
|
|
235
|
+
var DOCTYPE_NAME = seal(/^html$/i);
|
|
236
|
+
var CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
237
|
+
var EXPRESSIONS = /* @__PURE__ */ Object.freeze({
|
|
238
|
+
__proto__: null,
|
|
239
|
+
ARIA_ATTR,
|
|
240
|
+
ATTR_WHITESPACE,
|
|
241
|
+
CUSTOM_ELEMENT,
|
|
242
|
+
DATA_ATTR,
|
|
243
|
+
DOCTYPE_NAME,
|
|
244
|
+
ERB_EXPR,
|
|
245
|
+
IS_ALLOWED_URI,
|
|
246
|
+
IS_SCRIPT_OR_DATA,
|
|
247
|
+
MUSTACHE_EXPR,
|
|
248
|
+
TMPLIT_EXPR
|
|
249
|
+
});
|
|
250
|
+
var NODE_TYPE = {
|
|
251
|
+
element: 1,
|
|
252
|
+
attribute: 2,
|
|
253
|
+
text: 3,
|
|
254
|
+
cdataSection: 4,
|
|
255
|
+
entityReference: 5,
|
|
256
|
+
// Deprecated
|
|
257
|
+
entityNode: 6,
|
|
258
|
+
// Deprecated
|
|
259
|
+
progressingInstruction: 7,
|
|
260
|
+
comment: 8,
|
|
261
|
+
document: 9,
|
|
262
|
+
documentType: 10,
|
|
263
|
+
documentFragment: 11,
|
|
264
|
+
notation: 12
|
|
265
|
+
// Deprecated
|
|
266
|
+
};
|
|
267
|
+
var getGlobal = function getGlobal2() {
|
|
268
|
+
return typeof window === "undefined" ? null : window;
|
|
269
|
+
};
|
|
270
|
+
var _createTrustedTypesPolicy = function _createTrustedTypesPolicy2(trustedTypes, purifyHostElement) {
|
|
271
|
+
if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
let suffix = null;
|
|
275
|
+
const ATTR_NAME = "data-tt-policy-suffix";
|
|
276
|
+
if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
|
|
277
|
+
suffix = purifyHostElement.getAttribute(ATTR_NAME);
|
|
278
|
+
}
|
|
279
|
+
const policyName = "dompurify" + (suffix ? "#" + suffix : "");
|
|
280
|
+
try {
|
|
281
|
+
return trustedTypes.createPolicy(policyName, {
|
|
282
|
+
createHTML(html2) {
|
|
283
|
+
return html2;
|
|
284
|
+
},
|
|
285
|
+
createScriptURL(scriptUrl) {
|
|
286
|
+
return scriptUrl;
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
} catch (_) {
|
|
290
|
+
console.warn("TrustedTypes policy " + policyName + " could not be created.");
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
var _createHooksMap = function _createHooksMap2() {
|
|
295
|
+
return {
|
|
296
|
+
afterSanitizeAttributes: [],
|
|
297
|
+
afterSanitizeElements: [],
|
|
298
|
+
afterSanitizeShadowDOM: [],
|
|
299
|
+
beforeSanitizeAttributes: [],
|
|
300
|
+
beforeSanitizeElements: [],
|
|
301
|
+
beforeSanitizeShadowDOM: [],
|
|
302
|
+
uponSanitizeAttribute: [],
|
|
303
|
+
uponSanitizeElement: [],
|
|
304
|
+
uponSanitizeShadowNode: []
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
function createDOMPurify() {
|
|
308
|
+
let window2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
|
|
309
|
+
const DOMPurify2 = (root) => createDOMPurify(root);
|
|
310
|
+
DOMPurify2.version = "3.3.1";
|
|
311
|
+
DOMPurify2.removed = [];
|
|
312
|
+
if (!window2 || !window2.document || window2.document.nodeType !== NODE_TYPE.document || !window2.Element) {
|
|
313
|
+
DOMPurify2.isSupported = false;
|
|
314
|
+
return DOMPurify2;
|
|
315
|
+
}
|
|
316
|
+
let {
|
|
317
|
+
document: document2
|
|
318
|
+
} = window2;
|
|
319
|
+
const originalDocument = document2;
|
|
320
|
+
const currentScript = originalDocument.currentScript;
|
|
321
|
+
const {
|
|
322
|
+
DocumentFragment,
|
|
323
|
+
HTMLTemplateElement,
|
|
324
|
+
Node,
|
|
325
|
+
Element,
|
|
326
|
+
NodeFilter,
|
|
327
|
+
NamedNodeMap = window2.NamedNodeMap || window2.MozNamedAttrMap,
|
|
328
|
+
HTMLFormElement,
|
|
329
|
+
DOMParser,
|
|
330
|
+
trustedTypes
|
|
331
|
+
} = window2;
|
|
332
|
+
const ElementPrototype = Element.prototype;
|
|
333
|
+
const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
|
|
334
|
+
const remove = lookupGetter(ElementPrototype, "remove");
|
|
335
|
+
const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
|
|
336
|
+
const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
|
|
337
|
+
const getParentNode = lookupGetter(ElementPrototype, "parentNode");
|
|
338
|
+
if (typeof HTMLTemplateElement === "function") {
|
|
339
|
+
const template = document2.createElement("template");
|
|
340
|
+
if (template.content && template.content.ownerDocument) {
|
|
341
|
+
document2 = template.content.ownerDocument;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
let trustedTypesPolicy;
|
|
345
|
+
let emptyHTML = "";
|
|
346
|
+
const {
|
|
347
|
+
implementation,
|
|
348
|
+
createNodeIterator,
|
|
349
|
+
createDocumentFragment,
|
|
350
|
+
getElementsByTagName
|
|
351
|
+
} = document2;
|
|
352
|
+
const {
|
|
353
|
+
importNode
|
|
354
|
+
} = originalDocument;
|
|
355
|
+
let hooks = _createHooksMap();
|
|
356
|
+
DOMPurify2.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
|
|
357
|
+
const {
|
|
358
|
+
MUSTACHE_EXPR: MUSTACHE_EXPR2,
|
|
359
|
+
ERB_EXPR: ERB_EXPR2,
|
|
360
|
+
TMPLIT_EXPR: TMPLIT_EXPR2,
|
|
361
|
+
DATA_ATTR: DATA_ATTR2,
|
|
362
|
+
ARIA_ATTR: ARIA_ATTR2,
|
|
363
|
+
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA2,
|
|
364
|
+
ATTR_WHITESPACE: ATTR_WHITESPACE2,
|
|
365
|
+
CUSTOM_ELEMENT: CUSTOM_ELEMENT2
|
|
366
|
+
} = EXPRESSIONS;
|
|
367
|
+
let {
|
|
368
|
+
IS_ALLOWED_URI: IS_ALLOWED_URI$1
|
|
369
|
+
} = EXPRESSIONS;
|
|
370
|
+
let ALLOWED_TAGS = null;
|
|
371
|
+
const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
|
|
372
|
+
let ALLOWED_ATTR = null;
|
|
373
|
+
const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
|
|
374
|
+
let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
375
|
+
tagNameCheck: {
|
|
376
|
+
writable: true,
|
|
377
|
+
configurable: false,
|
|
378
|
+
enumerable: true,
|
|
379
|
+
value: null
|
|
380
|
+
},
|
|
381
|
+
attributeNameCheck: {
|
|
382
|
+
writable: true,
|
|
383
|
+
configurable: false,
|
|
384
|
+
enumerable: true,
|
|
385
|
+
value: null
|
|
386
|
+
},
|
|
387
|
+
allowCustomizedBuiltInElements: {
|
|
388
|
+
writable: true,
|
|
389
|
+
configurable: false,
|
|
390
|
+
enumerable: true,
|
|
391
|
+
value: false
|
|
392
|
+
}
|
|
393
|
+
}));
|
|
394
|
+
let FORBID_TAGS = null;
|
|
395
|
+
let FORBID_ATTR = null;
|
|
396
|
+
const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
397
|
+
tagCheck: {
|
|
398
|
+
writable: true,
|
|
399
|
+
configurable: false,
|
|
400
|
+
enumerable: true,
|
|
401
|
+
value: null
|
|
402
|
+
},
|
|
403
|
+
attributeCheck: {
|
|
404
|
+
writable: true,
|
|
405
|
+
configurable: false,
|
|
406
|
+
enumerable: true,
|
|
407
|
+
value: null
|
|
408
|
+
}
|
|
409
|
+
}));
|
|
410
|
+
let ALLOW_ARIA_ATTR = true;
|
|
411
|
+
let ALLOW_DATA_ATTR = true;
|
|
412
|
+
let ALLOW_UNKNOWN_PROTOCOLS = false;
|
|
413
|
+
let ALLOW_SELF_CLOSE_IN_ATTR = true;
|
|
414
|
+
let SAFE_FOR_TEMPLATES = false;
|
|
415
|
+
let SAFE_FOR_XML = true;
|
|
416
|
+
let WHOLE_DOCUMENT = false;
|
|
417
|
+
let SET_CONFIG = false;
|
|
418
|
+
let FORCE_BODY = false;
|
|
419
|
+
let RETURN_DOM = false;
|
|
420
|
+
let RETURN_DOM_FRAGMENT = false;
|
|
421
|
+
let RETURN_TRUSTED_TYPE = false;
|
|
422
|
+
let SANITIZE_DOM = true;
|
|
423
|
+
let SANITIZE_NAMED_PROPS = false;
|
|
424
|
+
const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
|
|
425
|
+
let KEEP_CONTENT = true;
|
|
426
|
+
let IN_PLACE = false;
|
|
427
|
+
let USE_PROFILES = {};
|
|
428
|
+
let FORBID_CONTENTS = null;
|
|
429
|
+
const DEFAULT_FORBID_CONTENTS = addToSet({}, ["annotation-xml", "audio", "colgroup", "desc", "foreignobject", "head", "iframe", "math", "mi", "mn", "mo", "ms", "mtext", "noembed", "noframes", "noscript", "plaintext", "script", "style", "svg", "template", "thead", "title", "video", "xmp"]);
|
|
430
|
+
let DATA_URI_TAGS = null;
|
|
431
|
+
const DEFAULT_DATA_URI_TAGS = addToSet({}, ["audio", "video", "img", "source", "image", "track"]);
|
|
432
|
+
let URI_SAFE_ATTRIBUTES = null;
|
|
433
|
+
const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "role", "summary", "title", "value", "style", "xmlns"]);
|
|
434
|
+
const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
|
|
435
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
436
|
+
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
437
|
+
let NAMESPACE = HTML_NAMESPACE;
|
|
438
|
+
let IS_EMPTY_INPUT = false;
|
|
439
|
+
let ALLOWED_NAMESPACES = null;
|
|
440
|
+
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
|
441
|
+
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ["mi", "mo", "mn", "ms", "mtext"]);
|
|
442
|
+
let HTML_INTEGRATION_POINTS = addToSet({}, ["annotation-xml"]);
|
|
443
|
+
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ["title", "style", "font", "a", "script"]);
|
|
444
|
+
let PARSER_MEDIA_TYPE = null;
|
|
445
|
+
const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
|
|
446
|
+
const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
|
|
447
|
+
let transformCaseFunc = null;
|
|
448
|
+
let CONFIG = null;
|
|
449
|
+
const formElement = document2.createElement("form");
|
|
450
|
+
const isRegexOrFunction = function isRegexOrFunction2(testValue) {
|
|
451
|
+
return testValue instanceof RegExp || testValue instanceof Function;
|
|
452
|
+
};
|
|
453
|
+
const _parseConfig = function _parseConfig2() {
|
|
454
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
455
|
+
if (CONFIG && CONFIG === cfg) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (!cfg || typeof cfg !== "object") {
|
|
459
|
+
cfg = {};
|
|
460
|
+
}
|
|
461
|
+
cfg = clone2(cfg);
|
|
462
|
+
PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
|
|
463
|
+
SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
|
|
464
|
+
transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
|
|
465
|
+
ALLOWED_TAGS = objectHasOwnProperty(cfg, "ALLOWED_TAGS") ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
|
|
466
|
+
ALLOWED_ATTR = objectHasOwnProperty(cfg, "ALLOWED_ATTR") ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
|
|
467
|
+
ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, "ALLOWED_NAMESPACES") ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
|
|
468
|
+
URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, "ADD_URI_SAFE_ATTR") ? addToSet(clone2(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
|
|
469
|
+
DATA_URI_TAGS = objectHasOwnProperty(cfg, "ADD_DATA_URI_TAGS") ? addToSet(clone2(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
|
|
470
|
+
FORBID_CONTENTS = objectHasOwnProperty(cfg, "FORBID_CONTENTS") ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
|
|
471
|
+
FORBID_TAGS = objectHasOwnProperty(cfg, "FORBID_TAGS") ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone2({});
|
|
472
|
+
FORBID_ATTR = objectHasOwnProperty(cfg, "FORBID_ATTR") ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone2({});
|
|
473
|
+
USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES : false;
|
|
474
|
+
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
|
|
475
|
+
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
|
|
476
|
+
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
|
|
477
|
+
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
|
|
478
|
+
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
|
|
479
|
+
SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
|
|
480
|
+
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
|
|
481
|
+
RETURN_DOM = cfg.RETURN_DOM || false;
|
|
482
|
+
RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
|
|
483
|
+
RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
|
|
484
|
+
FORCE_BODY = cfg.FORCE_BODY || false;
|
|
485
|
+
SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
|
|
486
|
+
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
|
|
487
|
+
KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
|
|
488
|
+
IN_PLACE = cfg.IN_PLACE || false;
|
|
489
|
+
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
|
|
490
|
+
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
|
|
491
|
+
MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
|
|
492
|
+
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
|
|
493
|
+
CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
|
|
494
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
|
|
495
|
+
CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
|
|
496
|
+
}
|
|
497
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
|
|
498
|
+
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
|
|
499
|
+
}
|
|
500
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === "boolean") {
|
|
501
|
+
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
|
|
502
|
+
}
|
|
503
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
504
|
+
ALLOW_DATA_ATTR = false;
|
|
505
|
+
}
|
|
506
|
+
if (RETURN_DOM_FRAGMENT) {
|
|
507
|
+
RETURN_DOM = true;
|
|
508
|
+
}
|
|
509
|
+
if (USE_PROFILES) {
|
|
510
|
+
ALLOWED_TAGS = addToSet({}, text);
|
|
511
|
+
ALLOWED_ATTR = [];
|
|
512
|
+
if (USE_PROFILES.html === true) {
|
|
513
|
+
addToSet(ALLOWED_TAGS, html$1);
|
|
514
|
+
addToSet(ALLOWED_ATTR, html);
|
|
515
|
+
}
|
|
516
|
+
if (USE_PROFILES.svg === true) {
|
|
517
|
+
addToSet(ALLOWED_TAGS, svg$1);
|
|
518
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
519
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
520
|
+
}
|
|
521
|
+
if (USE_PROFILES.svgFilters === true) {
|
|
522
|
+
addToSet(ALLOWED_TAGS, svgFilters);
|
|
523
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
524
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
525
|
+
}
|
|
526
|
+
if (USE_PROFILES.mathMl === true) {
|
|
527
|
+
addToSet(ALLOWED_TAGS, mathMl$1);
|
|
528
|
+
addToSet(ALLOWED_ATTR, mathMl);
|
|
529
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
if (cfg.ADD_TAGS) {
|
|
533
|
+
if (typeof cfg.ADD_TAGS === "function") {
|
|
534
|
+
EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
|
|
535
|
+
} else {
|
|
536
|
+
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
|
537
|
+
ALLOWED_TAGS = clone2(ALLOWED_TAGS);
|
|
538
|
+
}
|
|
539
|
+
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (cfg.ADD_ATTR) {
|
|
543
|
+
if (typeof cfg.ADD_ATTR === "function") {
|
|
544
|
+
EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
|
|
545
|
+
} else {
|
|
546
|
+
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
|
547
|
+
ALLOWED_ATTR = clone2(ALLOWED_ATTR);
|
|
548
|
+
}
|
|
549
|
+
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (cfg.ADD_URI_SAFE_ATTR) {
|
|
553
|
+
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
|
554
|
+
}
|
|
555
|
+
if (cfg.FORBID_CONTENTS) {
|
|
556
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
557
|
+
FORBID_CONTENTS = clone2(FORBID_CONTENTS);
|
|
558
|
+
}
|
|
559
|
+
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
|
560
|
+
}
|
|
561
|
+
if (cfg.ADD_FORBID_CONTENTS) {
|
|
562
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
563
|
+
FORBID_CONTENTS = clone2(FORBID_CONTENTS);
|
|
564
|
+
}
|
|
565
|
+
addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
|
|
566
|
+
}
|
|
567
|
+
if (KEEP_CONTENT) {
|
|
568
|
+
ALLOWED_TAGS["#text"] = true;
|
|
569
|
+
}
|
|
570
|
+
if (WHOLE_DOCUMENT) {
|
|
571
|
+
addToSet(ALLOWED_TAGS, ["html", "head", "body"]);
|
|
572
|
+
}
|
|
573
|
+
if (ALLOWED_TAGS.table) {
|
|
574
|
+
addToSet(ALLOWED_TAGS, ["tbody"]);
|
|
575
|
+
delete FORBID_TAGS.tbody;
|
|
576
|
+
}
|
|
577
|
+
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
578
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") {
|
|
579
|
+
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
580
|
+
}
|
|
581
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") {
|
|
582
|
+
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
583
|
+
}
|
|
584
|
+
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
585
|
+
emptyHTML = trustedTypesPolicy.createHTML("");
|
|
586
|
+
} else {
|
|
587
|
+
if (trustedTypesPolicy === void 0) {
|
|
588
|
+
trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
589
|
+
}
|
|
590
|
+
if (trustedTypesPolicy !== null && typeof emptyHTML === "string") {
|
|
591
|
+
emptyHTML = trustedTypesPolicy.createHTML("");
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (freeze) {
|
|
595
|
+
freeze(cfg);
|
|
596
|
+
}
|
|
597
|
+
CONFIG = cfg;
|
|
598
|
+
};
|
|
599
|
+
const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
|
|
600
|
+
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
|
601
|
+
const _checkValidNamespace = function _checkValidNamespace2(element) {
|
|
602
|
+
let parent = getParentNode(element);
|
|
603
|
+
if (!parent || !parent.tagName) {
|
|
604
|
+
parent = {
|
|
605
|
+
namespaceURI: NAMESPACE,
|
|
606
|
+
tagName: "template"
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
const tagName = stringToLowerCase(element.tagName);
|
|
610
|
+
const parentTagName = stringToLowerCase(parent.tagName);
|
|
611
|
+
if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
if (element.namespaceURI === SVG_NAMESPACE) {
|
|
615
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
616
|
+
return tagName === "svg";
|
|
617
|
+
}
|
|
618
|
+
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
619
|
+
return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
620
|
+
}
|
|
621
|
+
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
622
|
+
}
|
|
623
|
+
if (element.namespaceURI === MATHML_NAMESPACE) {
|
|
624
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
625
|
+
return tagName === "math";
|
|
626
|
+
}
|
|
627
|
+
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
628
|
+
return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
|
|
629
|
+
}
|
|
630
|
+
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
631
|
+
}
|
|
632
|
+
if (element.namespaceURI === HTML_NAMESPACE) {
|
|
633
|
+
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
637
|
+
return false;
|
|
638
|
+
}
|
|
639
|
+
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
640
|
+
}
|
|
641
|
+
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
642
|
+
return true;
|
|
643
|
+
}
|
|
644
|
+
return false;
|
|
645
|
+
};
|
|
646
|
+
const _forceRemove = function _forceRemove2(node) {
|
|
647
|
+
arrayPush(DOMPurify2.removed, {
|
|
648
|
+
element: node
|
|
649
|
+
});
|
|
650
|
+
try {
|
|
651
|
+
getParentNode(node).removeChild(node);
|
|
652
|
+
} catch (_) {
|
|
653
|
+
remove(node);
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
const _removeAttribute = function _removeAttribute2(name, element) {
|
|
657
|
+
try {
|
|
658
|
+
arrayPush(DOMPurify2.removed, {
|
|
659
|
+
attribute: element.getAttributeNode(name),
|
|
660
|
+
from: element
|
|
661
|
+
});
|
|
662
|
+
} catch (_) {
|
|
663
|
+
arrayPush(DOMPurify2.removed, {
|
|
664
|
+
attribute: null,
|
|
665
|
+
from: element
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
element.removeAttribute(name);
|
|
669
|
+
if (name === "is") {
|
|
670
|
+
if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
|
|
671
|
+
try {
|
|
672
|
+
_forceRemove(element);
|
|
673
|
+
} catch (_) {
|
|
674
|
+
}
|
|
675
|
+
} else {
|
|
676
|
+
try {
|
|
677
|
+
element.setAttribute(name, "");
|
|
678
|
+
} catch (_) {
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
const _initDocument = function _initDocument2(dirty) {
|
|
684
|
+
let doc = null;
|
|
685
|
+
let leadingWhitespace = null;
|
|
686
|
+
if (FORCE_BODY) {
|
|
687
|
+
dirty = "<remove></remove>" + dirty;
|
|
688
|
+
} else {
|
|
689
|
+
const matches = stringMatch(dirty, /^[\r\n\t ]+/);
|
|
690
|
+
leadingWhitespace = matches && matches[0];
|
|
691
|
+
}
|
|
692
|
+
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) {
|
|
693
|
+
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + "</body></html>";
|
|
694
|
+
}
|
|
695
|
+
const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
|
696
|
+
if (NAMESPACE === HTML_NAMESPACE) {
|
|
697
|
+
try {
|
|
698
|
+
doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
|
|
699
|
+
} catch (_) {
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
if (!doc || !doc.documentElement) {
|
|
703
|
+
doc = implementation.createDocument(NAMESPACE, "template", null);
|
|
704
|
+
try {
|
|
705
|
+
doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
|
|
706
|
+
} catch (_) {
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
const body = doc.body || doc.documentElement;
|
|
710
|
+
if (dirty && leadingWhitespace) {
|
|
711
|
+
body.insertBefore(document2.createTextNode(leadingWhitespace), body.childNodes[0] || null);
|
|
712
|
+
}
|
|
713
|
+
if (NAMESPACE === HTML_NAMESPACE) {
|
|
714
|
+
return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
|
|
715
|
+
}
|
|
716
|
+
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
|
717
|
+
};
|
|
718
|
+
const _createNodeIterator = function _createNodeIterator2(root) {
|
|
719
|
+
return createNodeIterator.call(
|
|
720
|
+
root.ownerDocument || root,
|
|
721
|
+
root,
|
|
722
|
+
// eslint-disable-next-line no-bitwise
|
|
723
|
+
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION,
|
|
724
|
+
null
|
|
725
|
+
);
|
|
726
|
+
};
|
|
727
|
+
const _isClobbered = function _isClobbered2(element) {
|
|
728
|
+
return element instanceof HTMLFormElement && (typeof element.nodeName !== "string" || typeof element.textContent !== "string" || typeof element.removeChild !== "function" || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== "function" || typeof element.setAttribute !== "function" || typeof element.namespaceURI !== "string" || typeof element.insertBefore !== "function" || typeof element.hasChildNodes !== "function");
|
|
729
|
+
};
|
|
730
|
+
const _isNode = function _isNode2(value) {
|
|
731
|
+
return typeof Node === "function" && value instanceof Node;
|
|
732
|
+
};
|
|
733
|
+
function _executeHooks(hooks2, currentNode, data) {
|
|
734
|
+
arrayForEach(hooks2, (hook) => {
|
|
735
|
+
hook.call(DOMPurify2, currentNode, data, CONFIG);
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
const _sanitizeElements = function _sanitizeElements2(currentNode) {
|
|
739
|
+
let content = null;
|
|
740
|
+
_executeHooks(hooks.beforeSanitizeElements, currentNode, null);
|
|
741
|
+
if (_isClobbered(currentNode)) {
|
|
742
|
+
_forceRemove(currentNode);
|
|
743
|
+
return true;
|
|
744
|
+
}
|
|
745
|
+
const tagName = transformCaseFunc(currentNode.nodeName);
|
|
746
|
+
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
747
|
+
tagName,
|
|
748
|
+
allowedTags: ALLOWED_TAGS
|
|
749
|
+
});
|
|
750
|
+
if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
|
|
751
|
+
_forceRemove(currentNode);
|
|
752
|
+
return true;
|
|
753
|
+
}
|
|
754
|
+
if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
|
755
|
+
_forceRemove(currentNode);
|
|
756
|
+
return true;
|
|
757
|
+
}
|
|
758
|
+
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
|
|
759
|
+
_forceRemove(currentNode);
|
|
760
|
+
return true;
|
|
761
|
+
}
|
|
762
|
+
if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {
|
|
763
|
+
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
764
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
768
|
+
return false;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
772
|
+
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
|
773
|
+
const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
|
|
774
|
+
if (childNodes && parentNode) {
|
|
775
|
+
const childCount = childNodes.length;
|
|
776
|
+
for (let i = childCount - 1; i >= 0; --i) {
|
|
777
|
+
const childClone = cloneNode(childNodes[i], true);
|
|
778
|
+
childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
|
|
779
|
+
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
_forceRemove(currentNode);
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
|
|
787
|
+
_forceRemove(currentNode);
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
|
|
791
|
+
_forceRemove(currentNode);
|
|
792
|
+
return true;
|
|
793
|
+
}
|
|
794
|
+
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
795
|
+
content = currentNode.textContent;
|
|
796
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
797
|
+
content = stringReplace(content, expr, " ");
|
|
798
|
+
});
|
|
799
|
+
if (currentNode.textContent !== content) {
|
|
800
|
+
arrayPush(DOMPurify2.removed, {
|
|
801
|
+
element: currentNode.cloneNode()
|
|
802
|
+
});
|
|
803
|
+
currentNode.textContent = content;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
_executeHooks(hooks.afterSanitizeElements, currentNode, null);
|
|
807
|
+
return false;
|
|
808
|
+
};
|
|
809
|
+
const _isValidAttribute = function _isValidAttribute2(lcTag, lcName, value) {
|
|
810
|
+
if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document2 || value in formElement)) {
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR2, lcName)) ;
|
|
814
|
+
else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR2, lcName)) ;
|
|
815
|
+
else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ;
|
|
816
|
+
else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
|
|
817
|
+
if (
|
|
818
|
+
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
819
|
+
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
820
|
+
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
|
|
821
|
+
_isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) || // Alternative, second condition checks if it's an `is`-attribute, AND
|
|
822
|
+
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
823
|
+
lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))
|
|
824
|
+
) ;
|
|
825
|
+
else {
|
|
826
|
+
return false;
|
|
827
|
+
}
|
|
828
|
+
} else if (URI_SAFE_ATTRIBUTES[lcName]) ;
|
|
829
|
+
else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
|
830
|
+
else if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) ;
|
|
831
|
+
else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA2, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
|
832
|
+
else if (value) {
|
|
833
|
+
return false;
|
|
834
|
+
} else ;
|
|
835
|
+
return true;
|
|
836
|
+
};
|
|
837
|
+
const _isBasicCustomElement = function _isBasicCustomElement2(tagName) {
|
|
838
|
+
return tagName !== "annotation-xml" && stringMatch(tagName, CUSTOM_ELEMENT2);
|
|
839
|
+
};
|
|
840
|
+
const _sanitizeAttributes = function _sanitizeAttributes2(currentNode) {
|
|
841
|
+
_executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
|
|
842
|
+
const {
|
|
843
|
+
attributes
|
|
844
|
+
} = currentNode;
|
|
845
|
+
if (!attributes || _isClobbered(currentNode)) {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
const hookEvent = {
|
|
849
|
+
attrName: "",
|
|
850
|
+
attrValue: "",
|
|
851
|
+
keepAttr: true,
|
|
852
|
+
allowedAttributes: ALLOWED_ATTR,
|
|
853
|
+
forceKeepAttr: void 0
|
|
854
|
+
};
|
|
855
|
+
let l = attributes.length;
|
|
856
|
+
while (l--) {
|
|
857
|
+
const attr = attributes[l];
|
|
858
|
+
const {
|
|
859
|
+
name,
|
|
860
|
+
namespaceURI,
|
|
861
|
+
value: attrValue
|
|
862
|
+
} = attr;
|
|
863
|
+
const lcName = transformCaseFunc(name);
|
|
864
|
+
const initValue = attrValue;
|
|
865
|
+
let value = name === "value" ? initValue : stringTrim(initValue);
|
|
866
|
+
hookEvent.attrName = lcName;
|
|
867
|
+
hookEvent.attrValue = value;
|
|
868
|
+
hookEvent.keepAttr = true;
|
|
869
|
+
hookEvent.forceKeepAttr = void 0;
|
|
870
|
+
_executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
|
|
871
|
+
value = hookEvent.attrValue;
|
|
872
|
+
if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name")) {
|
|
873
|
+
_removeAttribute(name, currentNode);
|
|
874
|
+
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
875
|
+
}
|
|
876
|
+
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title|textarea)/i, value)) {
|
|
877
|
+
_removeAttribute(name, currentNode);
|
|
878
|
+
continue;
|
|
879
|
+
}
|
|
880
|
+
if (lcName === "attributename" && stringMatch(value, "href")) {
|
|
881
|
+
_removeAttribute(name, currentNode);
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
if (hookEvent.forceKeepAttr) {
|
|
885
|
+
continue;
|
|
886
|
+
}
|
|
887
|
+
if (!hookEvent.keepAttr) {
|
|
888
|
+
_removeAttribute(name, currentNode);
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
|
|
892
|
+
_removeAttribute(name, currentNode);
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
895
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
896
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
897
|
+
value = stringReplace(value, expr, " ");
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
901
|
+
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
902
|
+
_removeAttribute(name, currentNode);
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function") {
|
|
906
|
+
if (namespaceURI) ;
|
|
907
|
+
else {
|
|
908
|
+
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
909
|
+
case "TrustedHTML": {
|
|
910
|
+
value = trustedTypesPolicy.createHTML(value);
|
|
911
|
+
break;
|
|
912
|
+
}
|
|
913
|
+
case "TrustedScriptURL": {
|
|
914
|
+
value = trustedTypesPolicy.createScriptURL(value);
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
if (value !== initValue) {
|
|
921
|
+
try {
|
|
922
|
+
if (namespaceURI) {
|
|
923
|
+
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
924
|
+
} else {
|
|
925
|
+
currentNode.setAttribute(name, value);
|
|
926
|
+
}
|
|
927
|
+
if (_isClobbered(currentNode)) {
|
|
928
|
+
_forceRemove(currentNode);
|
|
929
|
+
} else {
|
|
930
|
+
arrayPop(DOMPurify2.removed);
|
|
931
|
+
}
|
|
932
|
+
} catch (_) {
|
|
933
|
+
_removeAttribute(name, currentNode);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
_executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
|
|
938
|
+
};
|
|
939
|
+
const _sanitizeShadowDOM = function _sanitizeShadowDOM2(fragment) {
|
|
940
|
+
let shadowNode = null;
|
|
941
|
+
const shadowIterator = _createNodeIterator(fragment);
|
|
942
|
+
_executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
|
|
943
|
+
while (shadowNode = shadowIterator.nextNode()) {
|
|
944
|
+
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
|
|
945
|
+
_sanitizeElements(shadowNode);
|
|
946
|
+
_sanitizeAttributes(shadowNode);
|
|
947
|
+
if (shadowNode.content instanceof DocumentFragment) {
|
|
948
|
+
_sanitizeShadowDOM2(shadowNode.content);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
_executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
|
|
952
|
+
};
|
|
953
|
+
DOMPurify2.sanitize = function(dirty) {
|
|
954
|
+
let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
955
|
+
let body = null;
|
|
956
|
+
let importedNode = null;
|
|
957
|
+
let currentNode = null;
|
|
958
|
+
let returnNode = null;
|
|
959
|
+
IS_EMPTY_INPUT = !dirty;
|
|
960
|
+
if (IS_EMPTY_INPUT) {
|
|
961
|
+
dirty = "<!-->";
|
|
962
|
+
}
|
|
963
|
+
if (typeof dirty !== "string" && !_isNode(dirty)) {
|
|
964
|
+
if (typeof dirty.toString === "function") {
|
|
965
|
+
dirty = dirty.toString();
|
|
966
|
+
if (typeof dirty !== "string") {
|
|
967
|
+
throw typeErrorCreate("dirty is not a string, aborting");
|
|
968
|
+
}
|
|
969
|
+
} else {
|
|
970
|
+
throw typeErrorCreate("toString is not a function");
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
if (!DOMPurify2.isSupported) {
|
|
974
|
+
return dirty;
|
|
975
|
+
}
|
|
976
|
+
if (!SET_CONFIG) {
|
|
977
|
+
_parseConfig(cfg);
|
|
978
|
+
}
|
|
979
|
+
DOMPurify2.removed = [];
|
|
980
|
+
if (typeof dirty === "string") {
|
|
981
|
+
IN_PLACE = false;
|
|
982
|
+
}
|
|
983
|
+
if (IN_PLACE) {
|
|
984
|
+
if (dirty.nodeName) {
|
|
985
|
+
const tagName = transformCaseFunc(dirty.nodeName);
|
|
986
|
+
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
987
|
+
throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
} else if (dirty instanceof Node) {
|
|
991
|
+
body = _initDocument("<!---->");
|
|
992
|
+
importedNode = body.ownerDocument.importNode(dirty, true);
|
|
993
|
+
if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") {
|
|
994
|
+
body = importedNode;
|
|
995
|
+
} else if (importedNode.nodeName === "HTML") {
|
|
996
|
+
body = importedNode;
|
|
997
|
+
} else {
|
|
998
|
+
body.appendChild(importedNode);
|
|
999
|
+
}
|
|
1000
|
+
} else {
|
|
1001
|
+
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
|
|
1002
|
+
dirty.indexOf("<") === -1) {
|
|
1003
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
|
1004
|
+
}
|
|
1005
|
+
body = _initDocument(dirty);
|
|
1006
|
+
if (!body) {
|
|
1007
|
+
return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
if (body && FORCE_BODY) {
|
|
1011
|
+
_forceRemove(body.firstChild);
|
|
1012
|
+
}
|
|
1013
|
+
const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
|
|
1014
|
+
while (currentNode = nodeIterator.nextNode()) {
|
|
1015
|
+
_sanitizeElements(currentNode);
|
|
1016
|
+
_sanitizeAttributes(currentNode);
|
|
1017
|
+
if (currentNode.content instanceof DocumentFragment) {
|
|
1018
|
+
_sanitizeShadowDOM(currentNode.content);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
if (IN_PLACE) {
|
|
1022
|
+
return dirty;
|
|
1023
|
+
}
|
|
1024
|
+
if (RETURN_DOM) {
|
|
1025
|
+
if (RETURN_DOM_FRAGMENT) {
|
|
1026
|
+
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
1027
|
+
while (body.firstChild) {
|
|
1028
|
+
returnNode.appendChild(body.firstChild);
|
|
1029
|
+
}
|
|
1030
|
+
} else {
|
|
1031
|
+
returnNode = body;
|
|
1032
|
+
}
|
|
1033
|
+
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
|
|
1034
|
+
returnNode = importNode.call(originalDocument, returnNode, true);
|
|
1035
|
+
}
|
|
1036
|
+
return returnNode;
|
|
1037
|
+
}
|
|
1038
|
+
let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
|
1039
|
+
if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
|
|
1040
|
+
serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
|
|
1041
|
+
}
|
|
1042
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
1043
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
1044
|
+
serializedHTML = stringReplace(serializedHTML, expr, " ");
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
|
|
1048
|
+
};
|
|
1049
|
+
DOMPurify2.setConfig = function() {
|
|
1050
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1051
|
+
_parseConfig(cfg);
|
|
1052
|
+
SET_CONFIG = true;
|
|
1053
|
+
};
|
|
1054
|
+
DOMPurify2.clearConfig = function() {
|
|
1055
|
+
CONFIG = null;
|
|
1056
|
+
SET_CONFIG = false;
|
|
1057
|
+
};
|
|
1058
|
+
DOMPurify2.isValidAttribute = function(tag, attr, value) {
|
|
1059
|
+
if (!CONFIG) {
|
|
1060
|
+
_parseConfig({});
|
|
1061
|
+
}
|
|
1062
|
+
const lcTag = transformCaseFunc(tag);
|
|
1063
|
+
const lcName = transformCaseFunc(attr);
|
|
1064
|
+
return _isValidAttribute(lcTag, lcName, value);
|
|
1065
|
+
};
|
|
1066
|
+
DOMPurify2.addHook = function(entryPoint, hookFunction) {
|
|
1067
|
+
if (typeof hookFunction !== "function") {
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
arrayPush(hooks[entryPoint], hookFunction);
|
|
1071
|
+
};
|
|
1072
|
+
DOMPurify2.removeHook = function(entryPoint, hookFunction) {
|
|
1073
|
+
if (hookFunction !== void 0) {
|
|
1074
|
+
const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
|
|
1075
|
+
return index === -1 ? void 0 : arraySplice(hooks[entryPoint], index, 1)[0];
|
|
1076
|
+
}
|
|
1077
|
+
return arrayPop(hooks[entryPoint]);
|
|
1078
|
+
};
|
|
1079
|
+
DOMPurify2.removeHooks = function(entryPoint) {
|
|
1080
|
+
hooks[entryPoint] = [];
|
|
1081
|
+
};
|
|
1082
|
+
DOMPurify2.removeAllHooks = function() {
|
|
1083
|
+
hooks = _createHooksMap();
|
|
1084
|
+
};
|
|
1085
|
+
return DOMPurify2;
|
|
1086
|
+
}
|
|
1087
|
+
var purify = createDOMPurify();
|
|
1088
|
+
module.exports = purify;
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
// node_modules/.pnpm/isomorphic-dompurify@2.34.0_canvas@3.2.0/node_modules/isomorphic-dompurify/browser.js
|
|
1093
|
+
var require_browser2 = __commonJS({
|
|
1094
|
+
"node_modules/.pnpm/isomorphic-dompurify@2.34.0_canvas@3.2.0/node_modules/isomorphic-dompurify/browser.js"(exports, module) {
|
|
1095
|
+
module.exports = self.DOMPurify || (self.DOMPurify = require_purify_cjs().default || require_purify_cjs());
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
|
|
1099
|
+
// node_modules/.pnpm/wmap-parser@1.0.1/node_modules/wmap-parser/src/index.js
|
|
1100
|
+
var kLineSplitter = /\r\n|\r|\n/;
|
|
1101
|
+
function parse(source) {
|
|
1102
|
+
const components = [];
|
|
1103
|
+
const dependencies = [];
|
|
1104
|
+
const notes = [];
|
|
1105
|
+
const stages = [];
|
|
1106
|
+
const groups = [];
|
|
1107
|
+
const inertias = [];
|
|
1108
|
+
const evolutions = [];
|
|
1109
|
+
const lines = source.split(kLineSplitter);
|
|
1110
|
+
for (const rawLine of lines) {
|
|
1111
|
+
const line = rawLine.trim();
|
|
1112
|
+
if (!line) continue;
|
|
1113
|
+
const entity = parseLine(line);
|
|
1114
|
+
if (!entity) continue;
|
|
1115
|
+
switch (entity.type) {
|
|
1116
|
+
case "component":
|
|
1117
|
+
components.push({
|
|
1118
|
+
label: entity.label,
|
|
1119
|
+
coordinates: entity.coordinates,
|
|
1120
|
+
shape: entity.shape
|
|
1121
|
+
});
|
|
1122
|
+
break;
|
|
1123
|
+
case "dependency":
|
|
1124
|
+
dependencies.push({
|
|
1125
|
+
from: entity.from,
|
|
1126
|
+
to: entity.to,
|
|
1127
|
+
isDirected: entity.isDirected
|
|
1128
|
+
});
|
|
1129
|
+
break;
|
|
1130
|
+
case "note":
|
|
1131
|
+
notes.push({
|
|
1132
|
+
coordinates: entity.coordinates,
|
|
1133
|
+
text: entity.text
|
|
1134
|
+
});
|
|
1135
|
+
break;
|
|
1136
|
+
case "stage":
|
|
1137
|
+
stages.push({
|
|
1138
|
+
stage: entity.stage,
|
|
1139
|
+
value: entity.value
|
|
1140
|
+
});
|
|
1141
|
+
break;
|
|
1142
|
+
case "group":
|
|
1143
|
+
groups.push({
|
|
1144
|
+
components: entity.components
|
|
1145
|
+
});
|
|
1146
|
+
break;
|
|
1147
|
+
case "inertia":
|
|
1148
|
+
inertias.push({
|
|
1149
|
+
component: entity.component
|
|
1150
|
+
});
|
|
1151
|
+
break;
|
|
1152
|
+
case "evolution":
|
|
1153
|
+
evolutions.push({
|
|
1154
|
+
component: entity.component,
|
|
1155
|
+
value: entity.value
|
|
1156
|
+
});
|
|
1157
|
+
break;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return {
|
|
1161
|
+
components,
|
|
1162
|
+
dependencies,
|
|
1163
|
+
notes,
|
|
1164
|
+
stages,
|
|
1165
|
+
groups,
|
|
1166
|
+
inertias,
|
|
1167
|
+
evolutions
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
function parseLine(line) {
|
|
1171
|
+
const length = line.length;
|
|
1172
|
+
let i = 0;
|
|
1173
|
+
while (i < length && isWhitespace(line[i])) i++;
|
|
1174
|
+
if (i >= length) return null;
|
|
1175
|
+
if (line[i] === "[") {
|
|
1176
|
+
return parseKeywordEntity(line, i, length);
|
|
1177
|
+
}
|
|
1178
|
+
return parseComponentOrDependency(line, length);
|
|
1179
|
+
}
|
|
1180
|
+
function parseKeywordEntity(line, start, length) {
|
|
1181
|
+
let i = start + 1;
|
|
1182
|
+
const keywordStart = i;
|
|
1183
|
+
while (i < length && line[i] !== "]") i++;
|
|
1184
|
+
if (i >= length) return null;
|
|
1185
|
+
const keyword = line.substring(keywordStart, i).trim().toLowerCase();
|
|
1186
|
+
i++;
|
|
1187
|
+
while (i < length && isWhitespace(line[i])) i++;
|
|
1188
|
+
if (keyword === "note") {
|
|
1189
|
+
if (i >= length || line[i] !== "(") return null;
|
|
1190
|
+
i++;
|
|
1191
|
+
while (i < length && isWhitespace(line[i])) i++;
|
|
1192
|
+
const xStart = i;
|
|
1193
|
+
while (i < length && isDigitOrDot(line[i])) i++;
|
|
1194
|
+
if (i === xStart) return null;
|
|
1195
|
+
const x = parseFloat(line.substring(xStart, i));
|
|
1196
|
+
while (i < length && isWhitespace(line[i])) i++;
|
|
1197
|
+
if (i >= length || line[i] !== ",") return null;
|
|
1198
|
+
i++;
|
|
1199
|
+
while (i < length && isWhitespace(line[i])) i++;
|
|
1200
|
+
const yStart = i;
|
|
1201
|
+
while (i < length && isDigitOrDot(line[i])) i++;
|
|
1202
|
+
if (i === yStart) return null;
|
|
1203
|
+
const y = parseFloat(line.substring(yStart, i));
|
|
1204
|
+
while (i < length && isWhitespace(line[i])) i++;
|
|
1205
|
+
if (i >= length || line[i] !== ")") return null;
|
|
1206
|
+
i++;
|
|
1207
|
+
while (i < length && isWhitespace(line[i])) i++;
|
|
1208
|
+
const text = line.substring(i).trim();
|
|
1209
|
+
return {
|
|
1210
|
+
type: "note",
|
|
1211
|
+
coordinates: [x, y],
|
|
1212
|
+
text
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
if (keyword === "group") {
|
|
1216
|
+
const components = line.substring(i).split(",").map((v) => v.trim()).filter((v) => v);
|
|
1217
|
+
return components.length > 0 ? { type: "group", components } : null;
|
|
1218
|
+
}
|
|
1219
|
+
if (keyword === "inertia") {
|
|
1220
|
+
const component = line.substring(i).trim();
|
|
1221
|
+
return component ? { type: "inertia", component } : null;
|
|
1222
|
+
}
|
|
1223
|
+
if (keyword === "evolution") {
|
|
1224
|
+
let indexOfSign = -1;
|
|
1225
|
+
let signCharacter = null;
|
|
1226
|
+
for (let j = i; j < length; j++) {
|
|
1227
|
+
if (line[j] === "+" || line[j] === "-") {
|
|
1228
|
+
if (j + 1 < length && (line[j + 1] === ">" || line[j + 1] === "-"))
|
|
1229
|
+
continue;
|
|
1230
|
+
indexOfSign = j;
|
|
1231
|
+
signCharacter = line[j];
|
|
1232
|
+
break;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
if (indexOfSign === -1 || indexOfSign === i) return null;
|
|
1236
|
+
const component = line.substring(i, indexOfSign).trim();
|
|
1237
|
+
if (!component) return null;
|
|
1238
|
+
let indexOfNumber = indexOfSign + 1;
|
|
1239
|
+
while (indexOfNumber < length && isWhitespace(line[indexOfNumber]))
|
|
1240
|
+
indexOfNumber++;
|
|
1241
|
+
const startOfNumber = indexOfNumber;
|
|
1242
|
+
while (indexOfNumber < length && isDigitOrDot(line[indexOfNumber]))
|
|
1243
|
+
indexOfNumber++;
|
|
1244
|
+
if (indexOfNumber === startOfNumber) return null;
|
|
1245
|
+
return {
|
|
1246
|
+
type: "evolution",
|
|
1247
|
+
component,
|
|
1248
|
+
value: (signCharacter === "+" ? 1 : -1) * parseFloat(line.substring(startOfNumber, indexOfNumber))
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
if (keyword === "i" || keyword === "ii" || keyword === "iii" || keyword === "iv") {
|
|
1252
|
+
const startOfNumber = i;
|
|
1253
|
+
while (i < length && isDigitOrDot(line[i])) i++;
|
|
1254
|
+
if (i > startOfNumber) {
|
|
1255
|
+
return {
|
|
1256
|
+
type: "stage",
|
|
1257
|
+
stage: keyword,
|
|
1258
|
+
value: parseFloat(line.substring(startOfNumber, i))
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
return null;
|
|
1263
|
+
}
|
|
1264
|
+
function parseComponentOrDependency(line, length) {
|
|
1265
|
+
const indexOfArrow = line.indexOf("->");
|
|
1266
|
+
const indexOfDash = line.indexOf("--");
|
|
1267
|
+
const indexOfParenthesis = line.indexOf("(");
|
|
1268
|
+
if (indexOfArrow !== -1 && (indexOfParenthesis === -1 || indexOfArrow < indexOfParenthesis)) {
|
|
1269
|
+
const from = line.substring(0, indexOfArrow).trim();
|
|
1270
|
+
const to = line.substring(indexOfArrow + 2).trim();
|
|
1271
|
+
if (from && to) {
|
|
1272
|
+
return {
|
|
1273
|
+
type: "dependency",
|
|
1274
|
+
from,
|
|
1275
|
+
to,
|
|
1276
|
+
isDirected: true
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
return null;
|
|
1280
|
+
}
|
|
1281
|
+
if (indexOfDash !== -1 && (indexOfParenthesis === -1 || indexOfDash < indexOfParenthesis)) {
|
|
1282
|
+
const from = line.substring(0, indexOfDash).trim();
|
|
1283
|
+
const to = line.substring(indexOfDash + 2).trim();
|
|
1284
|
+
if (from && to) {
|
|
1285
|
+
return {
|
|
1286
|
+
type: "dependency",
|
|
1287
|
+
from,
|
|
1288
|
+
to,
|
|
1289
|
+
isDirected: false
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
return null;
|
|
1293
|
+
}
|
|
1294
|
+
if (indexOfParenthesis > 0) {
|
|
1295
|
+
return parseComponent(line, indexOfParenthesis, length);
|
|
1296
|
+
}
|
|
1297
|
+
return null;
|
|
1298
|
+
}
|
|
1299
|
+
function parseComponent(line, indexOfParenthesis, length) {
|
|
1300
|
+
const label = line.substring(0, indexOfParenthesis).trim();
|
|
1301
|
+
if (!label) return null;
|
|
1302
|
+
let i = indexOfParenthesis + 1;
|
|
1303
|
+
while (i < length && isWhitespace(line[i])) i++;
|
|
1304
|
+
const xStart = i;
|
|
1305
|
+
while (i < length && isDigitOrDot(line[i])) i++;
|
|
1306
|
+
if (i === xStart) return null;
|
|
1307
|
+
const x = parseFloat(line.substring(xStart, i));
|
|
1308
|
+
while (i < length && isWhitespace(line[i])) i++;
|
|
1309
|
+
if (i >= length || line[i] !== ",") return null;
|
|
1310
|
+
i++;
|
|
1311
|
+
while (i < length && isWhitespace(line[i])) i++;
|
|
1312
|
+
const yStart = i;
|
|
1313
|
+
while (i < length && isDigitOrDot(line[i])) i++;
|
|
1314
|
+
if (i === yStart) return null;
|
|
1315
|
+
const y = parseFloat(line.substring(yStart, i));
|
|
1316
|
+
while (i < length && isWhitespace(line[i])) i++;
|
|
1317
|
+
if (i >= length || line[i] !== ")") return null;
|
|
1318
|
+
i++;
|
|
1319
|
+
let shape = "circle";
|
|
1320
|
+
while (i < length && isWhitespace(line[i])) i++;
|
|
1321
|
+
if (i < length && line[i] === "[") {
|
|
1322
|
+
i++;
|
|
1323
|
+
const shapeStart = i;
|
|
1324
|
+
while (i < length && line[i] !== "]") i++;
|
|
1325
|
+
if (i > shapeStart && i < length) {
|
|
1326
|
+
shape = line.substring(shapeStart, i).trim().toLowerCase();
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
return {
|
|
1330
|
+
type: "component",
|
|
1331
|
+
label,
|
|
1332
|
+
coordinates: [x, y],
|
|
1333
|
+
shape
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
function isWhitespace(character) {
|
|
1337
|
+
return character === " " || character === " ";
|
|
1338
|
+
}
|
|
1339
|
+
function isDigitOrDot(character) {
|
|
1340
|
+
return character >= "0" && character <= "9" || character === ".";
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// node_modules/.pnpm/wmap-renderer-canvas@1.0.1/node_modules/wmap-renderer-canvas/src/patterns.js
|
|
1344
|
+
var patterns = {
|
|
1345
|
+
stitch: [
|
|
1346
|
+
1,
|
|
1347
|
+
1,
|
|
1348
|
+
1,
|
|
1349
|
+
1,
|
|
1350
|
+
1,
|
|
1351
|
+
1,
|
|
1352
|
+
1,
|
|
1353
|
+
1,
|
|
1354
|
+
1,
|
|
1355
|
+
1,
|
|
1356
|
+
1,
|
|
1357
|
+
1,
|
|
1358
|
+
1,
|
|
1359
|
+
1,
|
|
1360
|
+
1,
|
|
1361
|
+
1,
|
|
1362
|
+
1,
|
|
1363
|
+
0,
|
|
1364
|
+
1,
|
|
1365
|
+
1,
|
|
1366
|
+
1,
|
|
1367
|
+
1,
|
|
1368
|
+
1,
|
|
1369
|
+
1,
|
|
1370
|
+
0,
|
|
1371
|
+
1,
|
|
1372
|
+
0,
|
|
1373
|
+
1,
|
|
1374
|
+
1,
|
|
1375
|
+
1,
|
|
1376
|
+
1,
|
|
1377
|
+
1,
|
|
1378
|
+
1,
|
|
1379
|
+
1,
|
|
1380
|
+
1,
|
|
1381
|
+
1,
|
|
1382
|
+
1,
|
|
1383
|
+
1,
|
|
1384
|
+
1,
|
|
1385
|
+
1,
|
|
1386
|
+
1,
|
|
1387
|
+
1,
|
|
1388
|
+
1,
|
|
1389
|
+
1,
|
|
1390
|
+
1,
|
|
1391
|
+
1,
|
|
1392
|
+
1,
|
|
1393
|
+
1,
|
|
1394
|
+
1,
|
|
1395
|
+
1,
|
|
1396
|
+
1,
|
|
1397
|
+
1,
|
|
1398
|
+
1,
|
|
1399
|
+
0,
|
|
1400
|
+
1,
|
|
1401
|
+
1,
|
|
1402
|
+
1,
|
|
1403
|
+
1,
|
|
1404
|
+
1,
|
|
1405
|
+
1,
|
|
1406
|
+
0,
|
|
1407
|
+
1,
|
|
1408
|
+
0,
|
|
1409
|
+
1
|
|
1410
|
+
],
|
|
1411
|
+
shingles: [
|
|
1412
|
+
1,
|
|
1413
|
+
1,
|
|
1414
|
+
1,
|
|
1415
|
+
1,
|
|
1416
|
+
0,
|
|
1417
|
+
1,
|
|
1418
|
+
1,
|
|
1419
|
+
1,
|
|
1420
|
+
1,
|
|
1421
|
+
1,
|
|
1422
|
+
1,
|
|
1423
|
+
1,
|
|
1424
|
+
0,
|
|
1425
|
+
1,
|
|
1426
|
+
1,
|
|
1427
|
+
1,
|
|
1428
|
+
1,
|
|
1429
|
+
1,
|
|
1430
|
+
1,
|
|
1431
|
+
0,
|
|
1432
|
+
1,
|
|
1433
|
+
0,
|
|
1434
|
+
1,
|
|
1435
|
+
1,
|
|
1436
|
+
0,
|
|
1437
|
+
0,
|
|
1438
|
+
0,
|
|
1439
|
+
1,
|
|
1440
|
+
1,
|
|
1441
|
+
1,
|
|
1442
|
+
0,
|
|
1443
|
+
0,
|
|
1444
|
+
0,
|
|
1445
|
+
1,
|
|
1446
|
+
1,
|
|
1447
|
+
1,
|
|
1448
|
+
1,
|
|
1449
|
+
1,
|
|
1450
|
+
1,
|
|
1451
|
+
1,
|
|
1452
|
+
0,
|
|
1453
|
+
1,
|
|
1454
|
+
1,
|
|
1455
|
+
1,
|
|
1456
|
+
1,
|
|
1457
|
+
1,
|
|
1458
|
+
1,
|
|
1459
|
+
1,
|
|
1460
|
+
1,
|
|
1461
|
+
0,
|
|
1462
|
+
1,
|
|
1463
|
+
1,
|
|
1464
|
+
1,
|
|
1465
|
+
1,
|
|
1466
|
+
1,
|
|
1467
|
+
0,
|
|
1468
|
+
1,
|
|
1469
|
+
1,
|
|
1470
|
+
0,
|
|
1471
|
+
0,
|
|
1472
|
+
0,
|
|
1473
|
+
0,
|
|
1474
|
+
0,
|
|
1475
|
+
1
|
|
1476
|
+
],
|
|
1477
|
+
shadowGrid: [
|
|
1478
|
+
1,
|
|
1479
|
+
1,
|
|
1480
|
+
1,
|
|
1481
|
+
1,
|
|
1482
|
+
0,
|
|
1483
|
+
1,
|
|
1484
|
+
0,
|
|
1485
|
+
0,
|
|
1486
|
+
0,
|
|
1487
|
+
0,
|
|
1488
|
+
0,
|
|
1489
|
+
0,
|
|
1490
|
+
0,
|
|
1491
|
+
1,
|
|
1492
|
+
0,
|
|
1493
|
+
0,
|
|
1494
|
+
1,
|
|
1495
|
+
1,
|
|
1496
|
+
1,
|
|
1497
|
+
1,
|
|
1498
|
+
1,
|
|
1499
|
+
1,
|
|
1500
|
+
1,
|
|
1501
|
+
1,
|
|
1502
|
+
0,
|
|
1503
|
+
0,
|
|
1504
|
+
0,
|
|
1505
|
+
0,
|
|
1506
|
+
0,
|
|
1507
|
+
1,
|
|
1508
|
+
0,
|
|
1509
|
+
0,
|
|
1510
|
+
0,
|
|
1511
|
+
0,
|
|
1512
|
+
0,
|
|
1513
|
+
0,
|
|
1514
|
+
0,
|
|
1515
|
+
1,
|
|
1516
|
+
0,
|
|
1517
|
+
0,
|
|
1518
|
+
1,
|
|
1519
|
+
1,
|
|
1520
|
+
1,
|
|
1521
|
+
1,
|
|
1522
|
+
0,
|
|
1523
|
+
1,
|
|
1524
|
+
0,
|
|
1525
|
+
0,
|
|
1526
|
+
1,
|
|
1527
|
+
1,
|
|
1528
|
+
1,
|
|
1529
|
+
1,
|
|
1530
|
+
0,
|
|
1531
|
+
1,
|
|
1532
|
+
0,
|
|
1533
|
+
0,
|
|
1534
|
+
1,
|
|
1535
|
+
1,
|
|
1536
|
+
1,
|
|
1537
|
+
1,
|
|
1538
|
+
0,
|
|
1539
|
+
1,
|
|
1540
|
+
0,
|
|
1541
|
+
0
|
|
1542
|
+
],
|
|
1543
|
+
wicker: [
|
|
1544
|
+
0,
|
|
1545
|
+
0,
|
|
1546
|
+
0,
|
|
1547
|
+
0,
|
|
1548
|
+
0,
|
|
1549
|
+
1,
|
|
1550
|
+
1,
|
|
1551
|
+
1,
|
|
1552
|
+
1,
|
|
1553
|
+
0,
|
|
1554
|
+
0,
|
|
1555
|
+
0,
|
|
1556
|
+
1,
|
|
1557
|
+
0,
|
|
1558
|
+
1,
|
|
1559
|
+
1,
|
|
1560
|
+
1,
|
|
1561
|
+
1,
|
|
1562
|
+
0,
|
|
1563
|
+
1,
|
|
1564
|
+
1,
|
|
1565
|
+
1,
|
|
1566
|
+
0,
|
|
1567
|
+
1,
|
|
1568
|
+
1,
|
|
1569
|
+
0,
|
|
1570
|
+
1,
|
|
1571
|
+
1,
|
|
1572
|
+
1,
|
|
1573
|
+
0,
|
|
1574
|
+
0,
|
|
1575
|
+
0,
|
|
1576
|
+
0,
|
|
1577
|
+
1,
|
|
1578
|
+
1,
|
|
1579
|
+
1,
|
|
1580
|
+
0,
|
|
1581
|
+
0,
|
|
1582
|
+
0,
|
|
1583
|
+
0,
|
|
1584
|
+
1,
|
|
1585
|
+
1,
|
|
1586
|
+
1,
|
|
1587
|
+
0,
|
|
1588
|
+
1,
|
|
1589
|
+
0,
|
|
1590
|
+
0,
|
|
1591
|
+
0,
|
|
1592
|
+
1,
|
|
1593
|
+
1,
|
|
1594
|
+
0,
|
|
1595
|
+
1,
|
|
1596
|
+
1,
|
|
1597
|
+
1,
|
|
1598
|
+
0,
|
|
1599
|
+
1,
|
|
1600
|
+
1,
|
|
1601
|
+
0,
|
|
1602
|
+
0,
|
|
1603
|
+
0,
|
|
1604
|
+
1,
|
|
1605
|
+
1,
|
|
1606
|
+
1,
|
|
1607
|
+
0
|
|
1608
|
+
]
|
|
1609
|
+
};
|
|
1610
|
+
async function createPattern(ctx, patternData, pixelSize, fgColor, bgColor) {
|
|
1611
|
+
const size = 8;
|
|
1612
|
+
let patternCanvas;
|
|
1613
|
+
const isNode = typeof window === "undefined";
|
|
1614
|
+
if (isNode) {
|
|
1615
|
+
const { createCanvas } = await Promise.resolve().then(() => __toESM(require_browser(), 1));
|
|
1616
|
+
patternCanvas = createCanvas(size * pixelSize, size * pixelSize);
|
|
1617
|
+
} else {
|
|
1618
|
+
patternCanvas = window.document.createElement("canvas");
|
|
1619
|
+
patternCanvas.width = size * pixelSize;
|
|
1620
|
+
patternCanvas.height = size * pixelSize;
|
|
1621
|
+
}
|
|
1622
|
+
const patternCtx = patternCanvas.getContext("2d");
|
|
1623
|
+
for (let y = 0; y < size; y++) {
|
|
1624
|
+
for (let x = 0; x < size; x++) {
|
|
1625
|
+
const value = patternData[y * size + x];
|
|
1626
|
+
patternCtx.fillStyle = value === 0 ? fgColor : bgColor;
|
|
1627
|
+
patternCtx.fillRect(
|
|
1628
|
+
x * pixelSize,
|
|
1629
|
+
y * pixelSize,
|
|
1630
|
+
pixelSize,
|
|
1631
|
+
pixelSize
|
|
1632
|
+
);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
return ctx.createPattern(patternCanvas, "repeat");
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
// node_modules/.pnpm/wmap-renderer-canvas@1.0.1/node_modules/wmap-renderer-canvas/src/utils.js
|
|
1639
|
+
var internals = {
|
|
1640
|
+
kDefaultStages: [25, 50, 75]
|
|
1641
|
+
};
|
|
1642
|
+
function percentToPixel(percentage, dimension) {
|
|
1643
|
+
return percentage * dimension / 100;
|
|
1644
|
+
}
|
|
1645
|
+
function getStageValues(stageOverrides) {
|
|
1646
|
+
const stages = [...internals.kDefaultStages];
|
|
1647
|
+
if (stageOverrides && stageOverrides.length > 0) {
|
|
1648
|
+
stageOverrides.forEach((override) => {
|
|
1649
|
+
const index = { i: 0, ii: 1, iii: 2 }[override.stage];
|
|
1650
|
+
if (index !== void 0) {
|
|
1651
|
+
stages[index] = override.value;
|
|
1652
|
+
}
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
return stages;
|
|
1656
|
+
}
|
|
1657
|
+
function createComponentMap(components, width, height) {
|
|
1658
|
+
return components.reduce((map, current) => {
|
|
1659
|
+
map[current.label.toLowerCase()] = [
|
|
1660
|
+
percentToPixel(current.coordinates[0], width),
|
|
1661
|
+
percentToPixel(current.coordinates[1], height)
|
|
1662
|
+
];
|
|
1663
|
+
return map;
|
|
1664
|
+
}, {});
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
// node_modules/.pnpm/wmap-renderer-canvas@1.0.1/node_modules/wmap-renderer-canvas/src/smart-label-positioning.js
|
|
1668
|
+
function calculateOptimalLabelPosition(component, mapData, config, ctx, allLines, noteRects, inertiaRects) {
|
|
1669
|
+
const { mapWidth, mapHeight, vertexWidth, vertexHeight } = config.theme.sizes;
|
|
1670
|
+
const { family: fontFamily, vertexLabel: fontSize } = config.theme.fonts;
|
|
1671
|
+
const vertexPixelPos = {
|
|
1672
|
+
x: percentToPixel(component.coordinates[0], mapWidth),
|
|
1673
|
+
y: percentToPixel(component.coordinates[1], mapHeight)
|
|
1674
|
+
};
|
|
1675
|
+
ctx.font = `${fontSize}px ${fontFamily}`;
|
|
1676
|
+
const actualLabelSize = calculateLabelSize(component.label, ctx, config);
|
|
1677
|
+
const candidatePositions = generateCandidatePositions(
|
|
1678
|
+
vertexPixelPos,
|
|
1679
|
+
{ width: vertexWidth, height: vertexHeight },
|
|
1680
|
+
actualLabelSize
|
|
1681
|
+
);
|
|
1682
|
+
const defaultPosition = candidatePositions[0];
|
|
1683
|
+
const defaultRect = {
|
|
1684
|
+
x: defaultPosition.x,
|
|
1685
|
+
y: defaultPosition.y,
|
|
1686
|
+
width: actualLabelSize.width,
|
|
1687
|
+
height: actualLabelSize.height
|
|
1688
|
+
};
|
|
1689
|
+
if (countCollisions(defaultRect, allLines) === 0 && countNoteCollisions(defaultRect, noteRects) === 0 && countNoteCollisions(defaultRect, inertiaRects) === 0) {
|
|
1690
|
+
return defaultPosition;
|
|
1691
|
+
}
|
|
1692
|
+
let bestPosition = defaultPosition;
|
|
1693
|
+
let bestScore = Infinity;
|
|
1694
|
+
for (let index = 0; index < candidatePositions.length; index++) {
|
|
1695
|
+
const position = candidatePositions[index];
|
|
1696
|
+
const labelRect = {
|
|
1697
|
+
x: position.x,
|
|
1698
|
+
y: position.y,
|
|
1699
|
+
width: actualLabelSize.width,
|
|
1700
|
+
height: actualLabelSize.height
|
|
1701
|
+
};
|
|
1702
|
+
const collisionCount = countCollisions(labelRect, allLines);
|
|
1703
|
+
const noteCollisionCount = countNoteCollisions(labelRect, noteRects);
|
|
1704
|
+
const inertiaCollisionCount = countNoteCollisions(
|
|
1705
|
+
labelRect,
|
|
1706
|
+
inertiaRects
|
|
1707
|
+
);
|
|
1708
|
+
const distance2 = Math.sqrt(
|
|
1709
|
+
Math.pow(position.x - (vertexPixelPos.x + vertexWidth / 2), 2) + Math.pow(position.y - (vertexPixelPos.y + vertexHeight / 2), 2)
|
|
1710
|
+
);
|
|
1711
|
+
const ownershipPenalty = calculateOwnershipPenalty(
|
|
1712
|
+
labelRect,
|
|
1713
|
+
component,
|
|
1714
|
+
mapData.components,
|
|
1715
|
+
config
|
|
1716
|
+
);
|
|
1717
|
+
const score = collisionCount * 100 + noteCollisionCount * 500 + inertiaCollisionCount * 300 + distance2 * 0.5 + index * 0.1 + ownershipPenalty;
|
|
1718
|
+
if (score < bestScore) {
|
|
1719
|
+
bestScore = score;
|
|
1720
|
+
bestPosition = position;
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
return bestPosition;
|
|
1724
|
+
}
|
|
1725
|
+
function calculateLabelSize(text, ctx, config) {
|
|
1726
|
+
const cleanText = text.replace(/\\n/g, "\n");
|
|
1727
|
+
const lines = cleanText.split("\n");
|
|
1728
|
+
const lineHeight = config.theme.lineHeights.vertexLabel;
|
|
1729
|
+
let maxWidth = 0;
|
|
1730
|
+
let totalHeight = 0;
|
|
1731
|
+
for (const line of lines) {
|
|
1732
|
+
const metrics = ctx.measureText(line);
|
|
1733
|
+
maxWidth = Math.max(maxWidth, metrics.width);
|
|
1734
|
+
totalHeight += lineHeight;
|
|
1735
|
+
}
|
|
1736
|
+
return {
|
|
1737
|
+
width: Math.ceil(maxWidth) + 4,
|
|
1738
|
+
height: Math.ceil(totalHeight) + 2
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
function generateCandidatePositions(vertexPixelPos, vertexSize, labelSize) {
|
|
1742
|
+
const padding = 5;
|
|
1743
|
+
return [
|
|
1744
|
+
// Right
|
|
1745
|
+
{
|
|
1746
|
+
x: vertexPixelPos.x + vertexSize.width + padding,
|
|
1747
|
+
y: vertexPixelPos.y + (vertexSize.height - labelSize.height) / 2
|
|
1748
|
+
},
|
|
1749
|
+
// Left
|
|
1750
|
+
{
|
|
1751
|
+
x: vertexPixelPos.x - labelSize.width - padding,
|
|
1752
|
+
y: vertexPixelPos.y + (vertexSize.height - labelSize.height) / 2
|
|
1753
|
+
},
|
|
1754
|
+
// Top
|
|
1755
|
+
{
|
|
1756
|
+
x: vertexPixelPos.x + (vertexSize.width - labelSize.width) / 2,
|
|
1757
|
+
y: vertexPixelPos.y - labelSize.height - padding
|
|
1758
|
+
},
|
|
1759
|
+
// Bottom
|
|
1760
|
+
{
|
|
1761
|
+
x: vertexPixelPos.x + (vertexSize.width - labelSize.width) / 2,
|
|
1762
|
+
y: vertexPixelPos.y + vertexSize.height + padding
|
|
1763
|
+
},
|
|
1764
|
+
// Top-right
|
|
1765
|
+
{
|
|
1766
|
+
x: vertexPixelPos.x + vertexSize.width + padding,
|
|
1767
|
+
y: vertexPixelPos.y - labelSize.height - padding
|
|
1768
|
+
},
|
|
1769
|
+
// Top-left
|
|
1770
|
+
{
|
|
1771
|
+
x: vertexPixelPos.x - labelSize.width - padding,
|
|
1772
|
+
y: vertexPixelPos.y - labelSize.height - padding
|
|
1773
|
+
},
|
|
1774
|
+
// Bottom-right
|
|
1775
|
+
{
|
|
1776
|
+
x: vertexPixelPos.x + vertexSize.width + padding,
|
|
1777
|
+
y: vertexPixelPos.y + vertexSize.height + padding
|
|
1778
|
+
},
|
|
1779
|
+
// Bottom-left
|
|
1780
|
+
{
|
|
1781
|
+
x: vertexPixelPos.x - labelSize.width - padding,
|
|
1782
|
+
y: vertexPixelPos.y + vertexSize.height + padding
|
|
1783
|
+
}
|
|
1784
|
+
];
|
|
1785
|
+
}
|
|
1786
|
+
function collectAllLines(mapData, config, componentMap) {
|
|
1787
|
+
const { mapWidth, mapHeight, vertexWidth, vertexHeight } = config.theme.sizes;
|
|
1788
|
+
const lines = [];
|
|
1789
|
+
if (mapData.dependencies) {
|
|
1790
|
+
mapData.dependencies.forEach((edge) => {
|
|
1791
|
+
const originCoords = componentMap[edge.origin];
|
|
1792
|
+
const destCoords = componentMap[edge.destination];
|
|
1793
|
+
if (!originCoords || !destCoords) return;
|
|
1794
|
+
const origin = {
|
|
1795
|
+
x: originCoords[0],
|
|
1796
|
+
mapWidth,
|
|
1797
|
+
y: originCoords[1],
|
|
1798
|
+
mapHeight
|
|
1799
|
+
};
|
|
1800
|
+
const destination = {
|
|
1801
|
+
x: destCoords[0],
|
|
1802
|
+
mapWidth,
|
|
1803
|
+
y: destCoords[1],
|
|
1804
|
+
mapHeight
|
|
1805
|
+
};
|
|
1806
|
+
const slope = (destination.y - origin.y) / (destination.x - origin.x);
|
|
1807
|
+
const angle = Math.atan(slope);
|
|
1808
|
+
const multiplier = slope < 0 ? -1 : 1;
|
|
1809
|
+
const offsetOrigin = {
|
|
1810
|
+
x: origin.x + multiplier * (vertexWidth / 2) * Math.cos(angle),
|
|
1811
|
+
y: origin.y + multiplier * (vertexHeight / 2) * Math.sin(angle)
|
|
1812
|
+
};
|
|
1813
|
+
const offsetDestination = {
|
|
1814
|
+
x: destination.x - multiplier * (vertexWidth / 2) * Math.cos(angle),
|
|
1815
|
+
y: destination.y - multiplier * (vertexHeight / 2) * Math.sin(angle)
|
|
1816
|
+
};
|
|
1817
|
+
const adjustedOrigin = {
|
|
1818
|
+
x: offsetOrigin.x + vertexWidth / 2,
|
|
1819
|
+
y: offsetOrigin.y + vertexHeight / 2
|
|
1820
|
+
};
|
|
1821
|
+
const adjustedDestination = {
|
|
1822
|
+
x: offsetDestination.x + vertexWidth / 2,
|
|
1823
|
+
y: offsetDestination.y + vertexHeight / 2
|
|
1824
|
+
};
|
|
1825
|
+
lines.push({ start: adjustedOrigin, end: adjustedDestination });
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
if (mapData.evolutions) {
|
|
1829
|
+
mapData.evolutions.forEach((evolution) => {
|
|
1830
|
+
const coords = componentMap[evolution.component];
|
|
1831
|
+
if (!coords) return;
|
|
1832
|
+
const originX = coords[0];
|
|
1833
|
+
const originY = coords[1];
|
|
1834
|
+
const destX = evolution.value;
|
|
1835
|
+
const origin = {
|
|
1836
|
+
x: originX,
|
|
1837
|
+
mapWidth,
|
|
1838
|
+
y: originY,
|
|
1839
|
+
mapHeight
|
|
1840
|
+
};
|
|
1841
|
+
const destination = {
|
|
1842
|
+
x: destX,
|
|
1843
|
+
mapWidth,
|
|
1844
|
+
y: originY,
|
|
1845
|
+
mapHeight
|
|
1846
|
+
};
|
|
1847
|
+
const multiplier = destX > originX ? 1 : -1;
|
|
1848
|
+
const offsetOrigin = {
|
|
1849
|
+
x: origin.x + multiplier * (vertexWidth / 2),
|
|
1850
|
+
y: origin.y
|
|
1851
|
+
};
|
|
1852
|
+
const offsetDestination = {
|
|
1853
|
+
x: destination.x - multiplier * (vertexWidth / 2),
|
|
1854
|
+
y: destination.y
|
|
1855
|
+
};
|
|
1856
|
+
const adjustedOrigin = {
|
|
1857
|
+
x: offsetOrigin.x + vertexWidth / 2,
|
|
1858
|
+
y: offsetOrigin.y + vertexHeight / 2
|
|
1859
|
+
};
|
|
1860
|
+
const adjustedDestination = {
|
|
1861
|
+
x: offsetDestination.x + vertexWidth / 2,
|
|
1862
|
+
y: offsetDestination.y + vertexHeight / 2
|
|
1863
|
+
};
|
|
1864
|
+
lines.push({ start: adjustedOrigin, end: adjustedDestination });
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
lines.push(
|
|
1868
|
+
{ start: { x: 0, y: 0 }, end: { x: 0, y: mapHeight } },
|
|
1869
|
+
{ start: { x: 0, y: mapHeight }, end: { x: mapWidth, y: mapHeight } }
|
|
1870
|
+
);
|
|
1871
|
+
return lines;
|
|
1872
|
+
}
|
|
1873
|
+
function collectNoteRects(mapData, config, ctx) {
|
|
1874
|
+
if (!mapData.notes) return [];
|
|
1875
|
+
const { mapWidth, mapHeight } = config.theme.sizes;
|
|
1876
|
+
return mapData.notes.map((note) => {
|
|
1877
|
+
const notePixelPos = {
|
|
1878
|
+
x: percentToPixel(note.coordinates[0], mapWidth),
|
|
1879
|
+
y: percentToPixel(note.coordinates[1], mapHeight)
|
|
1880
|
+
};
|
|
1881
|
+
const noteSize = calculateLabelSize(note.text, ctx, config);
|
|
1882
|
+
return {
|
|
1883
|
+
x: notePixelPos.x,
|
|
1884
|
+
y: notePixelPos.y,
|
|
1885
|
+
width: noteSize.width,
|
|
1886
|
+
height: noteSize.height
|
|
1887
|
+
};
|
|
1888
|
+
});
|
|
1889
|
+
}
|
|
1890
|
+
function collectInertiaRects(mapData, config, componentMap) {
|
|
1891
|
+
if (!mapData.inertias) return [];
|
|
1892
|
+
const { vertexWidth, vertexHeight } = config.theme.sizes;
|
|
1893
|
+
return mapData.inertias.map((inertia) => {
|
|
1894
|
+
if (!inertia.component) return null;
|
|
1895
|
+
const coordinates = componentMap[inertia.component.toLowerCase()];
|
|
1896
|
+
if (!coordinates) return null;
|
|
1897
|
+
const x = coordinates[0] + 3 * vertexWidth;
|
|
1898
|
+
const y = coordinates[1] - vertexHeight * 2 / 3;
|
|
1899
|
+
const rectWidth = vertexWidth / 2;
|
|
1900
|
+
const rectHeight = vertexHeight * 2;
|
|
1901
|
+
return {
|
|
1902
|
+
x,
|
|
1903
|
+
y,
|
|
1904
|
+
width: rectWidth,
|
|
1905
|
+
height: rectHeight
|
|
1906
|
+
};
|
|
1907
|
+
}).filter((rect) => rect !== null);
|
|
1908
|
+
}
|
|
1909
|
+
function countCollisions(labelRect, lines) {
|
|
1910
|
+
let collisions = 0;
|
|
1911
|
+
for (const line of lines) {
|
|
1912
|
+
if (lineIntersectsRect(line, labelRect)) {
|
|
1913
|
+
collisions++;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
return collisions;
|
|
1917
|
+
}
|
|
1918
|
+
function countNoteCollisions(labelRect, noteRects) {
|
|
1919
|
+
let collisions = 0;
|
|
1920
|
+
for (const noteRect of noteRects) {
|
|
1921
|
+
if (rectsIntersect(labelRect, noteRect)) {
|
|
1922
|
+
collisions++;
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
return collisions;
|
|
1926
|
+
}
|
|
1927
|
+
function rectsIntersect(rect1, rect2) {
|
|
1928
|
+
return !(rect1.x + rect1.width < rect2.x || rect2.x + rect2.width < rect1.x || rect1.y + rect1.height < rect2.y || rect2.y + rect2.height < rect1.y);
|
|
1929
|
+
}
|
|
1930
|
+
function lineIntersectsRect(line, rect) {
|
|
1931
|
+
const rectLines = [
|
|
1932
|
+
{
|
|
1933
|
+
start: { x: rect.x, y: rect.y },
|
|
1934
|
+
end: { x: rect.x + rect.width, y: rect.y }
|
|
1935
|
+
},
|
|
1936
|
+
{
|
|
1937
|
+
start: { x: rect.x + rect.width, y: rect.y },
|
|
1938
|
+
end: { x: rect.x + rect.width, y: rect.y + rect.height }
|
|
1939
|
+
},
|
|
1940
|
+
{
|
|
1941
|
+
start: { x: rect.x + rect.width, y: rect.y + rect.height },
|
|
1942
|
+
end: { x: rect.x, y: rect.y + rect.height }
|
|
1943
|
+
},
|
|
1944
|
+
{
|
|
1945
|
+
start: { x: rect.x, y: rect.y + rect.height },
|
|
1946
|
+
end: { x: rect.x, y: rect.y }
|
|
1947
|
+
}
|
|
1948
|
+
];
|
|
1949
|
+
for (const rectLine of rectLines) {
|
|
1950
|
+
if (linesIntersect(line, rectLine)) {
|
|
1951
|
+
return true;
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
return pointInRect(line.start, rect) || pointInRect(line.end, rect);
|
|
1955
|
+
}
|
|
1956
|
+
function pointInRect(point2, rect) {
|
|
1957
|
+
return point2.x >= rect.x && point2.x <= rect.x + rect.width && point2.y >= rect.y && point2.y <= rect.y + rect.height;
|
|
1958
|
+
}
|
|
1959
|
+
function linesIntersect(line1, line2) {
|
|
1960
|
+
const x1 = line1.start.x;
|
|
1961
|
+
const y1 = line1.start.y;
|
|
1962
|
+
const x2 = line1.end.x;
|
|
1963
|
+
const y2 = line1.end.y;
|
|
1964
|
+
const x3 = line2.start.x;
|
|
1965
|
+
const y3 = line2.start.y;
|
|
1966
|
+
const x4 = line2.end.x;
|
|
1967
|
+
const y4 = line2.end.y;
|
|
1968
|
+
const denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
|
|
1969
|
+
if (Math.abs(denom) < 1e-10) {
|
|
1970
|
+
return false;
|
|
1971
|
+
}
|
|
1972
|
+
const t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / denom;
|
|
1973
|
+
const u = -((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3)) / denom;
|
|
1974
|
+
return t >= 0 && t <= 1 && u >= 0 && u <= 1;
|
|
1975
|
+
}
|
|
1976
|
+
function calculateOwnershipPenalty(labelRect, ownComponent, allComponents, config) {
|
|
1977
|
+
if (allComponents.length === 0) return 0;
|
|
1978
|
+
const { mapWidth, mapHeight, vertexWidth, vertexHeight } = config.theme.sizes;
|
|
1979
|
+
const labelCenter = {
|
|
1980
|
+
x: labelRect.x + labelRect.width / 2,
|
|
1981
|
+
y: labelRect.y + labelRect.height / 2
|
|
1982
|
+
};
|
|
1983
|
+
const ownVertexPixelPos = {
|
|
1984
|
+
x: percentToPixel(ownComponent.coordinates[0], mapWidth),
|
|
1985
|
+
y: percentToPixel(ownComponent.coordinates[1], mapHeight)
|
|
1986
|
+
};
|
|
1987
|
+
const ownVertexCenter = {
|
|
1988
|
+
x: ownVertexPixelPos.x + vertexWidth / 2,
|
|
1989
|
+
y: ownVertexPixelPos.y + vertexHeight / 2
|
|
1990
|
+
};
|
|
1991
|
+
const distanceToOwnVertex = Math.sqrt(
|
|
1992
|
+
Math.pow(labelCenter.x - ownVertexCenter.x, 2) + Math.pow(labelCenter.y - ownVertexCenter.y, 2)
|
|
1993
|
+
);
|
|
1994
|
+
for (const otherComponent of allComponents) {
|
|
1995
|
+
if (otherComponent === ownComponent) continue;
|
|
1996
|
+
const otherVertexPixelPos = {
|
|
1997
|
+
x: percentToPixel(otherComponent.coordinates[0], mapWidth),
|
|
1998
|
+
y: percentToPixel(otherComponent.coordinates[1], mapHeight)
|
|
1999
|
+
};
|
|
2000
|
+
const otherVertexCenter = {
|
|
2001
|
+
x: otherVertexPixelPos.x + vertexWidth / 2,
|
|
2002
|
+
y: otherVertexPixelPos.y + vertexHeight / 2
|
|
2003
|
+
};
|
|
2004
|
+
const distanceToOtherVertex = Math.sqrt(
|
|
2005
|
+
Math.pow(labelCenter.x - otherVertexCenter.x, 2) + Math.pow(labelCenter.y - otherVertexCenter.y, 2)
|
|
2006
|
+
);
|
|
2007
|
+
if (distanceToOtherVertex < distanceToOwnVertex) {
|
|
2008
|
+
return 50;
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
return 0;
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
// node_modules/.pnpm/@turf+helpers@7.3.1/node_modules/@turf/helpers/dist/esm/index.js
|
|
2015
|
+
var earthRadius = 63710088e-1;
|
|
2016
|
+
var factors = {
|
|
2017
|
+
centimeters: earthRadius * 100,
|
|
2018
|
+
centimetres: earthRadius * 100,
|
|
2019
|
+
degrees: 360 / (2 * Math.PI),
|
|
2020
|
+
feet: earthRadius * 3.28084,
|
|
2021
|
+
inches: earthRadius * 39.37,
|
|
2022
|
+
kilometers: earthRadius / 1e3,
|
|
2023
|
+
kilometres: earthRadius / 1e3,
|
|
2024
|
+
meters: earthRadius,
|
|
2025
|
+
metres: earthRadius,
|
|
2026
|
+
miles: earthRadius / 1609.344,
|
|
2027
|
+
millimeters: earthRadius * 1e3,
|
|
2028
|
+
millimetres: earthRadius * 1e3,
|
|
2029
|
+
nauticalmiles: earthRadius / 1852,
|
|
2030
|
+
radians: 1,
|
|
2031
|
+
yards: earthRadius * 1.0936
|
|
2032
|
+
};
|
|
2033
|
+
function feature(geom, properties, options = {}) {
|
|
2034
|
+
const feat = { type: "Feature" };
|
|
2035
|
+
if (options.id === 0 || options.id) {
|
|
2036
|
+
feat.id = options.id;
|
|
2037
|
+
}
|
|
2038
|
+
if (options.bbox) {
|
|
2039
|
+
feat.bbox = options.bbox;
|
|
2040
|
+
}
|
|
2041
|
+
feat.properties = properties || {};
|
|
2042
|
+
feat.geometry = geom;
|
|
2043
|
+
return feat;
|
|
2044
|
+
}
|
|
2045
|
+
function point(coordinates, properties, options = {}) {
|
|
2046
|
+
if (!coordinates) {
|
|
2047
|
+
throw new Error("coordinates is required");
|
|
2048
|
+
}
|
|
2049
|
+
if (!Array.isArray(coordinates)) {
|
|
2050
|
+
throw new Error("coordinates must be an Array");
|
|
2051
|
+
}
|
|
2052
|
+
if (coordinates.length < 2) {
|
|
2053
|
+
throw new Error("coordinates must be at least 2 numbers long");
|
|
2054
|
+
}
|
|
2055
|
+
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) {
|
|
2056
|
+
throw new Error("coordinates must contain numbers");
|
|
2057
|
+
}
|
|
2058
|
+
const geom = {
|
|
2059
|
+
type: "Point",
|
|
2060
|
+
coordinates
|
|
2061
|
+
};
|
|
2062
|
+
return feature(geom, properties, options);
|
|
2063
|
+
}
|
|
2064
|
+
function polygon(coordinates, properties, options = {}) {
|
|
2065
|
+
for (const ring of coordinates) {
|
|
2066
|
+
if (ring.length < 4) {
|
|
2067
|
+
throw new Error(
|
|
2068
|
+
"Each LinearRing of a Polygon must have 4 or more Positions."
|
|
2069
|
+
);
|
|
2070
|
+
}
|
|
2071
|
+
if (ring[ring.length - 1].length !== ring[0].length) {
|
|
2072
|
+
throw new Error("First and last Position are not equivalent.");
|
|
2073
|
+
}
|
|
2074
|
+
for (let j = 0; j < ring[ring.length - 1].length; j++) {
|
|
2075
|
+
if (ring[ring.length - 1][j] !== ring[0][j]) {
|
|
2076
|
+
throw new Error("First and last Position are not equivalent.");
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
const geom = {
|
|
2081
|
+
type: "Polygon",
|
|
2082
|
+
coordinates
|
|
2083
|
+
};
|
|
2084
|
+
return feature(geom, properties, options);
|
|
2085
|
+
}
|
|
2086
|
+
function lineString(coordinates, properties, options = {}) {
|
|
2087
|
+
if (coordinates.length < 2) {
|
|
2088
|
+
throw new Error("coordinates must be an array of two or more positions");
|
|
2089
|
+
}
|
|
2090
|
+
const geom = {
|
|
2091
|
+
type: "LineString",
|
|
2092
|
+
coordinates
|
|
2093
|
+
};
|
|
2094
|
+
return feature(geom, properties, options);
|
|
2095
|
+
}
|
|
2096
|
+
function featureCollection(features, options = {}) {
|
|
2097
|
+
const fc = { type: "FeatureCollection" };
|
|
2098
|
+
if (options.id) {
|
|
2099
|
+
fc.id = options.id;
|
|
2100
|
+
}
|
|
2101
|
+
if (options.bbox) {
|
|
2102
|
+
fc.bbox = options.bbox;
|
|
2103
|
+
}
|
|
2104
|
+
fc.features = features;
|
|
2105
|
+
return fc;
|
|
2106
|
+
}
|
|
2107
|
+
function multiLineString(coordinates, properties, options = {}) {
|
|
2108
|
+
const geom = {
|
|
2109
|
+
type: "MultiLineString",
|
|
2110
|
+
coordinates
|
|
2111
|
+
};
|
|
2112
|
+
return feature(geom, properties, options);
|
|
2113
|
+
}
|
|
2114
|
+
function geometryCollection(geometries, properties, options = {}) {
|
|
2115
|
+
const geom = {
|
|
2116
|
+
type: "GeometryCollection",
|
|
2117
|
+
geometries
|
|
2118
|
+
};
|
|
2119
|
+
return feature(geom, properties, options);
|
|
2120
|
+
}
|
|
2121
|
+
function radiansToLength(radians, units = "kilometers") {
|
|
2122
|
+
const factor = factors[units];
|
|
2123
|
+
if (!factor) {
|
|
2124
|
+
throw new Error(units + " units is invalid");
|
|
2125
|
+
}
|
|
2126
|
+
return radians * factor;
|
|
2127
|
+
}
|
|
2128
|
+
function degreesToRadians(degrees) {
|
|
2129
|
+
const normalisedDegrees = degrees % 360;
|
|
2130
|
+
return normalisedDegrees * Math.PI / 180;
|
|
2131
|
+
}
|
|
2132
|
+
function isNumber(num) {
|
|
2133
|
+
return !isNaN(num) && num !== null && !Array.isArray(num);
|
|
2134
|
+
}
|
|
2135
|
+
function isObject(input) {
|
|
2136
|
+
return input !== null && typeof input === "object" && !Array.isArray(input);
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
// node_modules/.pnpm/@turf+invariant@7.3.1/node_modules/@turf/invariant/dist/esm/index.js
|
|
2140
|
+
function getCoord(coord) {
|
|
2141
|
+
if (!coord) {
|
|
2142
|
+
throw new Error("coord is required");
|
|
2143
|
+
}
|
|
2144
|
+
if (!Array.isArray(coord)) {
|
|
2145
|
+
if (coord.type === "Feature" && coord.geometry !== null && coord.geometry.type === "Point") {
|
|
2146
|
+
return [...coord.geometry.coordinates];
|
|
2147
|
+
}
|
|
2148
|
+
if (coord.type === "Point") {
|
|
2149
|
+
return [...coord.coordinates];
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
if (Array.isArray(coord) && coord.length >= 2 && !Array.isArray(coord[0]) && !Array.isArray(coord[1])) {
|
|
2153
|
+
return [...coord];
|
|
2154
|
+
}
|
|
2155
|
+
throw new Error("coord must be GeoJSON Point or an Array of numbers");
|
|
2156
|
+
}
|
|
2157
|
+
function getType(geojson, _name) {
|
|
2158
|
+
if (geojson.type === "FeatureCollection") {
|
|
2159
|
+
return "FeatureCollection";
|
|
2160
|
+
}
|
|
2161
|
+
if (geojson.type === "GeometryCollection") {
|
|
2162
|
+
return "GeometryCollection";
|
|
2163
|
+
}
|
|
2164
|
+
if (geojson.type === "Feature" && geojson.geometry !== null) {
|
|
2165
|
+
return geojson.geometry.type;
|
|
2166
|
+
}
|
|
2167
|
+
return geojson.type;
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
// node_modules/.pnpm/@turf+distance@7.3.1/node_modules/@turf/distance/dist/esm/index.js
|
|
2171
|
+
function distance(from, to, options = {}) {
|
|
2172
|
+
var coordinates1 = getCoord(from);
|
|
2173
|
+
var coordinates2 = getCoord(to);
|
|
2174
|
+
var dLat = degreesToRadians(coordinates2[1] - coordinates1[1]);
|
|
2175
|
+
var dLon = degreesToRadians(coordinates2[0] - coordinates1[0]);
|
|
2176
|
+
var lat1 = degreesToRadians(coordinates1[1]);
|
|
2177
|
+
var lat2 = degreesToRadians(coordinates2[1]);
|
|
2178
|
+
var a = Math.pow(Math.sin(dLat / 2), 2) + Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);
|
|
2179
|
+
return radiansToLength(
|
|
2180
|
+
2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)),
|
|
2181
|
+
options.units
|
|
2182
|
+
);
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
// node_modules/.pnpm/@turf+meta@7.3.1/node_modules/@turf/meta/dist/esm/index.js
|
|
2186
|
+
function featureEach(geojson, callback) {
|
|
2187
|
+
if (geojson.type === "Feature") {
|
|
2188
|
+
callback(geojson, 0);
|
|
2189
|
+
} else if (geojson.type === "FeatureCollection") {
|
|
2190
|
+
for (var i = 0; i < geojson.features.length; i++) {
|
|
2191
|
+
if (callback(geojson.features[i], i) === false) break;
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
function geomEach(geojson, callback) {
|
|
2196
|
+
var i, j, g, geometry, stopG, geometryMaybeCollection, isGeometryCollection, featureProperties, featureBBox, featureId, featureIndex = 0, isFeatureCollection = geojson.type === "FeatureCollection", isFeature = geojson.type === "Feature", stop = isFeatureCollection ? geojson.features.length : 1;
|
|
2197
|
+
for (i = 0; i < stop; i++) {
|
|
2198
|
+
geometryMaybeCollection = isFeatureCollection ? geojson.features[i].geometry : isFeature ? geojson.geometry : geojson;
|
|
2199
|
+
featureProperties = isFeatureCollection ? geojson.features[i].properties : isFeature ? geojson.properties : {};
|
|
2200
|
+
featureBBox = isFeatureCollection ? geojson.features[i].bbox : isFeature ? geojson.bbox : void 0;
|
|
2201
|
+
featureId = isFeatureCollection ? geojson.features[i].id : isFeature ? geojson.id : void 0;
|
|
2202
|
+
isGeometryCollection = geometryMaybeCollection ? geometryMaybeCollection.type === "GeometryCollection" : false;
|
|
2203
|
+
stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;
|
|
2204
|
+
for (g = 0; g < stopG; g++) {
|
|
2205
|
+
geometry = isGeometryCollection ? geometryMaybeCollection.geometries[g] : geometryMaybeCollection;
|
|
2206
|
+
if (geometry === null) {
|
|
2207
|
+
if (callback(
|
|
2208
|
+
null,
|
|
2209
|
+
featureIndex,
|
|
2210
|
+
featureProperties,
|
|
2211
|
+
featureBBox,
|
|
2212
|
+
featureId
|
|
2213
|
+
) === false)
|
|
2214
|
+
return false;
|
|
2215
|
+
continue;
|
|
2216
|
+
}
|
|
2217
|
+
switch (geometry.type) {
|
|
2218
|
+
case "Point":
|
|
2219
|
+
case "LineString":
|
|
2220
|
+
case "MultiPoint":
|
|
2221
|
+
case "Polygon":
|
|
2222
|
+
case "MultiLineString":
|
|
2223
|
+
case "MultiPolygon": {
|
|
2224
|
+
if (callback(
|
|
2225
|
+
geometry,
|
|
2226
|
+
featureIndex,
|
|
2227
|
+
featureProperties,
|
|
2228
|
+
featureBBox,
|
|
2229
|
+
featureId
|
|
2230
|
+
) === false)
|
|
2231
|
+
return false;
|
|
2232
|
+
break;
|
|
2233
|
+
}
|
|
2234
|
+
case "GeometryCollection": {
|
|
2235
|
+
for (j = 0; j < geometry.geometries.length; j++) {
|
|
2236
|
+
if (callback(
|
|
2237
|
+
geometry.geometries[j],
|
|
2238
|
+
featureIndex,
|
|
2239
|
+
featureProperties,
|
|
2240
|
+
featureBBox,
|
|
2241
|
+
featureId
|
|
2242
|
+
) === false)
|
|
2243
|
+
return false;
|
|
2244
|
+
}
|
|
2245
|
+
break;
|
|
2246
|
+
}
|
|
2247
|
+
default:
|
|
2248
|
+
throw new Error("Unknown Geometry Type");
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
featureIndex++;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
function flattenEach(geojson, callback) {
|
|
2255
|
+
geomEach(geojson, function(geometry, featureIndex, properties, bbox, id) {
|
|
2256
|
+
var type = geometry === null ? null : geometry.type;
|
|
2257
|
+
switch (type) {
|
|
2258
|
+
case null:
|
|
2259
|
+
case "Point":
|
|
2260
|
+
case "LineString":
|
|
2261
|
+
case "Polygon":
|
|
2262
|
+
if (callback(
|
|
2263
|
+
feature(geometry, properties, { bbox, id }),
|
|
2264
|
+
featureIndex,
|
|
2265
|
+
0
|
|
2266
|
+
) === false)
|
|
2267
|
+
return false;
|
|
2268
|
+
return;
|
|
2269
|
+
}
|
|
2270
|
+
var geomType;
|
|
2271
|
+
switch (type) {
|
|
2272
|
+
case "MultiPoint":
|
|
2273
|
+
geomType = "Point";
|
|
2274
|
+
break;
|
|
2275
|
+
case "MultiLineString":
|
|
2276
|
+
geomType = "LineString";
|
|
2277
|
+
break;
|
|
2278
|
+
case "MultiPolygon":
|
|
2279
|
+
geomType = "Polygon";
|
|
2280
|
+
break;
|
|
2281
|
+
}
|
|
2282
|
+
for (var multiFeatureIndex = 0; multiFeatureIndex < geometry.coordinates.length; multiFeatureIndex++) {
|
|
2283
|
+
var coordinate = geometry.coordinates[multiFeatureIndex];
|
|
2284
|
+
var geom = {
|
|
2285
|
+
type: geomType,
|
|
2286
|
+
coordinates: coordinate
|
|
2287
|
+
};
|
|
2288
|
+
if (callback(feature(geom, properties), featureIndex, multiFeatureIndex) === false)
|
|
2289
|
+
return false;
|
|
2290
|
+
}
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2293
|
+
function lineEach(geojson, callback) {
|
|
2294
|
+
if (!geojson) throw new Error("geojson is required");
|
|
2295
|
+
flattenEach(geojson, function(feature2, featureIndex, multiFeatureIndex) {
|
|
2296
|
+
if (feature2.geometry === null) return;
|
|
2297
|
+
var type = feature2.geometry.type;
|
|
2298
|
+
var coords = feature2.geometry.coordinates;
|
|
2299
|
+
switch (type) {
|
|
2300
|
+
case "LineString":
|
|
2301
|
+
if (callback(feature2, featureIndex, multiFeatureIndex, 0, 0) === false)
|
|
2302
|
+
return false;
|
|
2303
|
+
break;
|
|
2304
|
+
case "Polygon":
|
|
2305
|
+
for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) {
|
|
2306
|
+
if (callback(
|
|
2307
|
+
lineString(coords[geometryIndex], feature2.properties),
|
|
2308
|
+
featureIndex,
|
|
2309
|
+
multiFeatureIndex,
|
|
2310
|
+
geometryIndex
|
|
2311
|
+
) === false)
|
|
2312
|
+
return false;
|
|
2313
|
+
}
|
|
2314
|
+
break;
|
|
2315
|
+
}
|
|
2316
|
+
});
|
|
2317
|
+
}
|
|
2318
|
+
function lineReduce(geojson, callback, initialValue) {
|
|
2319
|
+
var previousValue = initialValue;
|
|
2320
|
+
lineEach(
|
|
2321
|
+
geojson,
|
|
2322
|
+
function(currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
|
|
2323
|
+
if (featureIndex === 0 && initialValue === void 0)
|
|
2324
|
+
previousValue = currentLine;
|
|
2325
|
+
else
|
|
2326
|
+
previousValue = callback(
|
|
2327
|
+
previousValue,
|
|
2328
|
+
currentLine,
|
|
2329
|
+
featureIndex,
|
|
2330
|
+
multiFeatureIndex,
|
|
2331
|
+
geometryIndex
|
|
2332
|
+
);
|
|
2333
|
+
}
|
|
2334
|
+
);
|
|
2335
|
+
return previousValue;
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
// node_modules/.pnpm/@turf+tin@7.3.1/node_modules/@turf/tin/dist/esm/index.js
|
|
2339
|
+
function tin(points, z) {
|
|
2340
|
+
let isPointZ = false;
|
|
2341
|
+
return featureCollection(
|
|
2342
|
+
triangulate(
|
|
2343
|
+
points.features.map((p) => {
|
|
2344
|
+
const point2 = {
|
|
2345
|
+
x: p.geometry.coordinates[0],
|
|
2346
|
+
y: p.geometry.coordinates[1]
|
|
2347
|
+
};
|
|
2348
|
+
if (z) {
|
|
2349
|
+
point2.z = p.properties[z];
|
|
2350
|
+
} else if (p.geometry.coordinates.length === 3) {
|
|
2351
|
+
isPointZ = true;
|
|
2352
|
+
point2.z = p.geometry.coordinates[2];
|
|
2353
|
+
}
|
|
2354
|
+
return point2;
|
|
2355
|
+
})
|
|
2356
|
+
).map((triangle) => {
|
|
2357
|
+
const a = [triangle.a.x, triangle.a.y];
|
|
2358
|
+
const b = [triangle.b.x, triangle.b.y];
|
|
2359
|
+
const c = [triangle.c.x, triangle.c.y];
|
|
2360
|
+
let properties = {};
|
|
2361
|
+
if (isPointZ) {
|
|
2362
|
+
a.push(triangle.a.z);
|
|
2363
|
+
b.push(triangle.b.z);
|
|
2364
|
+
c.push(triangle.c.z);
|
|
2365
|
+
} else {
|
|
2366
|
+
properties = {
|
|
2367
|
+
a: triangle.a.z,
|
|
2368
|
+
b: triangle.b.z,
|
|
2369
|
+
c: triangle.c.z
|
|
2370
|
+
};
|
|
2371
|
+
}
|
|
2372
|
+
return polygon([[a, b, c, a]], properties);
|
|
2373
|
+
})
|
|
2374
|
+
);
|
|
2375
|
+
}
|
|
2376
|
+
var Triangle = class {
|
|
2377
|
+
constructor(a, b, c) {
|
|
2378
|
+
this.a = a;
|
|
2379
|
+
this.b = b;
|
|
2380
|
+
this.c = c;
|
|
2381
|
+
const A = b.x - a.x;
|
|
2382
|
+
const B = b.y - a.y;
|
|
2383
|
+
const C = c.x - a.x;
|
|
2384
|
+
const D = c.y - a.y;
|
|
2385
|
+
const E = A * (a.x + b.x) + B * (a.y + b.y);
|
|
2386
|
+
const F = C * (a.x + c.x) + D * (a.y + c.y);
|
|
2387
|
+
const G = 2 * (A * (c.y - b.y) - B * (c.x - b.x));
|
|
2388
|
+
let dx;
|
|
2389
|
+
let dy;
|
|
2390
|
+
this.x = (D * E - B * F) / G;
|
|
2391
|
+
this.y = (A * F - C * E) / G;
|
|
2392
|
+
dx = this.x - a.x;
|
|
2393
|
+
dy = this.y - a.y;
|
|
2394
|
+
this.r = dx * dx + dy * dy;
|
|
2395
|
+
}
|
|
2396
|
+
};
|
|
2397
|
+
function byX(a, b) {
|
|
2398
|
+
return b.x - a.x;
|
|
2399
|
+
}
|
|
2400
|
+
function dedup(edges) {
|
|
2401
|
+
let j = edges.length;
|
|
2402
|
+
let a;
|
|
2403
|
+
let b;
|
|
2404
|
+
let i;
|
|
2405
|
+
let m;
|
|
2406
|
+
let n;
|
|
2407
|
+
outer: while (j) {
|
|
2408
|
+
b = edges[--j];
|
|
2409
|
+
a = edges[--j];
|
|
2410
|
+
i = j;
|
|
2411
|
+
while (i) {
|
|
2412
|
+
n = edges[--i];
|
|
2413
|
+
m = edges[--i];
|
|
2414
|
+
if (a === m && b === n || a === n && b === m) {
|
|
2415
|
+
edges.splice(j, 2);
|
|
2416
|
+
edges.splice(i, 2);
|
|
2417
|
+
j -= 2;
|
|
2418
|
+
continue outer;
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
function triangulate(vertices) {
|
|
2424
|
+
if (vertices.length < 3) {
|
|
2425
|
+
return [];
|
|
2426
|
+
}
|
|
2427
|
+
vertices.sort(byX);
|
|
2428
|
+
let i = vertices.length - 1;
|
|
2429
|
+
const xmin = vertices[i].x;
|
|
2430
|
+
const xmax = vertices[0].x;
|
|
2431
|
+
let ymin = vertices[i].y;
|
|
2432
|
+
let ymax = ymin;
|
|
2433
|
+
const epsilon = 1e-12;
|
|
2434
|
+
let a;
|
|
2435
|
+
let b;
|
|
2436
|
+
let c;
|
|
2437
|
+
let A;
|
|
2438
|
+
let B;
|
|
2439
|
+
let G;
|
|
2440
|
+
while (i--) {
|
|
2441
|
+
if (vertices[i].y < ymin) {
|
|
2442
|
+
ymin = vertices[i].y;
|
|
2443
|
+
}
|
|
2444
|
+
if (vertices[i].y > ymax) {
|
|
2445
|
+
ymax = vertices[i].y;
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
let dx = xmax - xmin;
|
|
2449
|
+
let dy = ymax - ymin;
|
|
2450
|
+
const dmax = dx > dy ? dx : dy;
|
|
2451
|
+
const xmid = (xmax + xmin) * 0.5;
|
|
2452
|
+
const ymid = (ymax + ymin) * 0.5;
|
|
2453
|
+
const open = [
|
|
2454
|
+
new Triangle(
|
|
2455
|
+
{
|
|
2456
|
+
__sentinel: true,
|
|
2457
|
+
x: xmid - 20 * dmax,
|
|
2458
|
+
y: ymid - dmax
|
|
2459
|
+
},
|
|
2460
|
+
{
|
|
2461
|
+
__sentinel: true,
|
|
2462
|
+
x: xmid,
|
|
2463
|
+
y: ymid + 20 * dmax
|
|
2464
|
+
},
|
|
2465
|
+
{
|
|
2466
|
+
__sentinel: true,
|
|
2467
|
+
x: xmid + 20 * dmax,
|
|
2468
|
+
y: ymid - dmax
|
|
2469
|
+
}
|
|
2470
|
+
)
|
|
2471
|
+
];
|
|
2472
|
+
const closed = [];
|
|
2473
|
+
const edges = [];
|
|
2474
|
+
let j;
|
|
2475
|
+
i = vertices.length;
|
|
2476
|
+
while (i--) {
|
|
2477
|
+
edges.length = 0;
|
|
2478
|
+
j = open.length;
|
|
2479
|
+
while (j--) {
|
|
2480
|
+
dx = vertices[i].x - open[j].x;
|
|
2481
|
+
if (dx > 0 && dx * dx > open[j].r) {
|
|
2482
|
+
closed.push(open[j]);
|
|
2483
|
+
open.splice(j, 1);
|
|
2484
|
+
continue;
|
|
2485
|
+
}
|
|
2486
|
+
dy = vertices[i].y - open[j].y;
|
|
2487
|
+
if (dx * dx + dy * dy > open[j].r) {
|
|
2488
|
+
continue;
|
|
2489
|
+
}
|
|
2490
|
+
edges.push(
|
|
2491
|
+
open[j].a,
|
|
2492
|
+
open[j].b,
|
|
2493
|
+
open[j].b,
|
|
2494
|
+
open[j].c,
|
|
2495
|
+
open[j].c,
|
|
2496
|
+
open[j].a
|
|
2497
|
+
);
|
|
2498
|
+
open.splice(j, 1);
|
|
2499
|
+
}
|
|
2500
|
+
dedup(edges);
|
|
2501
|
+
j = edges.length;
|
|
2502
|
+
while (j) {
|
|
2503
|
+
b = edges[--j];
|
|
2504
|
+
a = edges[--j];
|
|
2505
|
+
c = vertices[i];
|
|
2506
|
+
A = b.x - a.x;
|
|
2507
|
+
B = b.y - a.y;
|
|
2508
|
+
G = 2 * (A * (c.y - b.y) - B * (c.x - b.x));
|
|
2509
|
+
if (Math.abs(G) > epsilon) {
|
|
2510
|
+
open.push(new Triangle(a, b, c));
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
Array.prototype.push.apply(closed, open);
|
|
2515
|
+
i = closed.length;
|
|
2516
|
+
while (i--) {
|
|
2517
|
+
if (closed[i].a.__sentinel || closed[i].b.__sentinel || closed[i].c.__sentinel) {
|
|
2518
|
+
closed.splice(i, 1);
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
return closed;
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
// node_modules/.pnpm/@turf+clone@7.3.1/node_modules/@turf/clone/dist/esm/index.js
|
|
2525
|
+
function clone(geojson) {
|
|
2526
|
+
if (!geojson) {
|
|
2527
|
+
throw new Error("geojson is required");
|
|
2528
|
+
}
|
|
2529
|
+
switch (geojson.type) {
|
|
2530
|
+
case "Feature":
|
|
2531
|
+
return cloneFeature(geojson);
|
|
2532
|
+
case "FeatureCollection":
|
|
2533
|
+
return cloneFeatureCollection(geojson);
|
|
2534
|
+
case "Point":
|
|
2535
|
+
case "LineString":
|
|
2536
|
+
case "Polygon":
|
|
2537
|
+
case "MultiPoint":
|
|
2538
|
+
case "MultiLineString":
|
|
2539
|
+
case "MultiPolygon":
|
|
2540
|
+
case "GeometryCollection":
|
|
2541
|
+
return cloneGeometry(geojson);
|
|
2542
|
+
default:
|
|
2543
|
+
throw new Error("unknown GeoJSON type");
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
function cloneFeature(geojson) {
|
|
2547
|
+
const cloned = { type: "Feature" };
|
|
2548
|
+
Object.keys(geojson).forEach((key) => {
|
|
2549
|
+
switch (key) {
|
|
2550
|
+
case "type":
|
|
2551
|
+
case "properties":
|
|
2552
|
+
case "geometry":
|
|
2553
|
+
return;
|
|
2554
|
+
default:
|
|
2555
|
+
cloned[key] = geojson[key];
|
|
2556
|
+
}
|
|
2557
|
+
});
|
|
2558
|
+
cloned.properties = cloneProperties(geojson.properties);
|
|
2559
|
+
if (geojson.geometry == null) {
|
|
2560
|
+
cloned.geometry = null;
|
|
2561
|
+
} else {
|
|
2562
|
+
cloned.geometry = cloneGeometry(geojson.geometry);
|
|
2563
|
+
}
|
|
2564
|
+
return cloned;
|
|
2565
|
+
}
|
|
2566
|
+
function cloneProperties(properties) {
|
|
2567
|
+
const cloned = {};
|
|
2568
|
+
if (!properties) {
|
|
2569
|
+
return cloned;
|
|
2570
|
+
}
|
|
2571
|
+
Object.keys(properties).forEach((key) => {
|
|
2572
|
+
const value = properties[key];
|
|
2573
|
+
if (typeof value === "object") {
|
|
2574
|
+
if (value === null) {
|
|
2575
|
+
cloned[key] = null;
|
|
2576
|
+
} else if (Array.isArray(value)) {
|
|
2577
|
+
cloned[key] = value.map((item) => {
|
|
2578
|
+
return item;
|
|
2579
|
+
});
|
|
2580
|
+
} else {
|
|
2581
|
+
cloned[key] = cloneProperties(value);
|
|
2582
|
+
}
|
|
2583
|
+
} else {
|
|
2584
|
+
cloned[key] = value;
|
|
2585
|
+
}
|
|
2586
|
+
});
|
|
2587
|
+
return cloned;
|
|
2588
|
+
}
|
|
2589
|
+
function cloneFeatureCollection(geojson) {
|
|
2590
|
+
const cloned = { type: "FeatureCollection" };
|
|
2591
|
+
Object.keys(geojson).forEach((key) => {
|
|
2592
|
+
switch (key) {
|
|
2593
|
+
case "type":
|
|
2594
|
+
case "features":
|
|
2595
|
+
return;
|
|
2596
|
+
default:
|
|
2597
|
+
cloned[key] = geojson[key];
|
|
2598
|
+
}
|
|
2599
|
+
});
|
|
2600
|
+
cloned.features = geojson.features.map((feature2) => {
|
|
2601
|
+
return cloneFeature(feature2);
|
|
2602
|
+
});
|
|
2603
|
+
return cloned;
|
|
2604
|
+
}
|
|
2605
|
+
function cloneGeometry(geometry) {
|
|
2606
|
+
const geom = { type: geometry.type };
|
|
2607
|
+
if (geometry.bbox) {
|
|
2608
|
+
geom.bbox = geometry.bbox;
|
|
2609
|
+
}
|
|
2610
|
+
if (geometry.type === "GeometryCollection") {
|
|
2611
|
+
geom.geometries = geometry.geometries.map((g) => {
|
|
2612
|
+
return cloneGeometry(g);
|
|
2613
|
+
});
|
|
2614
|
+
return geom;
|
|
2615
|
+
}
|
|
2616
|
+
geom.coordinates = deepSlice(geometry.coordinates);
|
|
2617
|
+
return geom;
|
|
2618
|
+
}
|
|
2619
|
+
function deepSlice(coords) {
|
|
2620
|
+
const cloned = coords;
|
|
2621
|
+
if (typeof cloned[0] !== "object") {
|
|
2622
|
+
return cloned.slice();
|
|
2623
|
+
}
|
|
2624
|
+
return cloned.map((coord) => {
|
|
2625
|
+
return deepSlice(coord);
|
|
2626
|
+
});
|
|
2627
|
+
}
|
|
2628
|
+
|
|
2629
|
+
// node_modules/.pnpm/topojson-client@3.1.0/node_modules/topojson-client/src/identity.js
|
|
2630
|
+
function identity_default(x) {
|
|
2631
|
+
return x;
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
// node_modules/.pnpm/topojson-client@3.1.0/node_modules/topojson-client/src/transform.js
|
|
2635
|
+
function transform_default(transform) {
|
|
2636
|
+
if (transform == null) return identity_default;
|
|
2637
|
+
var x0, y0, kx = transform.scale[0], ky = transform.scale[1], dx = transform.translate[0], dy = transform.translate[1];
|
|
2638
|
+
return function(input, i) {
|
|
2639
|
+
if (!i) x0 = y0 = 0;
|
|
2640
|
+
var j = 2, n = input.length, output = new Array(n);
|
|
2641
|
+
output[0] = (x0 += input[0]) * kx + dx;
|
|
2642
|
+
output[1] = (y0 += input[1]) * ky + dy;
|
|
2643
|
+
while (j < n) output[j] = input[j], ++j;
|
|
2644
|
+
return output;
|
|
2645
|
+
};
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
// node_modules/.pnpm/topojson-client@3.1.0/node_modules/topojson-client/src/reverse.js
|
|
2649
|
+
function reverse_default(array, n) {
|
|
2650
|
+
var t, j = array.length, i = j - n;
|
|
2651
|
+
while (i < --j) t = array[i], array[i++] = array[j], array[j] = t;
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2654
|
+
// node_modules/.pnpm/topojson-client@3.1.0/node_modules/topojson-client/src/feature.js
|
|
2655
|
+
function object(topology, o) {
|
|
2656
|
+
var transformPoint = transform_default(topology.transform), arcs = topology.arcs;
|
|
2657
|
+
function arc(i, points) {
|
|
2658
|
+
if (points.length) points.pop();
|
|
2659
|
+
for (var a = arcs[i < 0 ? ~i : i], k = 0, n = a.length; k < n; ++k) {
|
|
2660
|
+
points.push(transformPoint(a[k], k));
|
|
2661
|
+
}
|
|
2662
|
+
if (i < 0) reverse_default(points, n);
|
|
2663
|
+
}
|
|
2664
|
+
function point2(p) {
|
|
2665
|
+
return transformPoint(p);
|
|
2666
|
+
}
|
|
2667
|
+
function line(arcs2) {
|
|
2668
|
+
var points = [];
|
|
2669
|
+
for (var i = 0, n = arcs2.length; i < n; ++i) arc(arcs2[i], points);
|
|
2670
|
+
if (points.length < 2) points.push(points[0]);
|
|
2671
|
+
return points;
|
|
2672
|
+
}
|
|
2673
|
+
function ring(arcs2) {
|
|
2674
|
+
var points = line(arcs2);
|
|
2675
|
+
while (points.length < 4) points.push(points[0]);
|
|
2676
|
+
return points;
|
|
2677
|
+
}
|
|
2678
|
+
function polygon2(arcs2) {
|
|
2679
|
+
return arcs2.map(ring);
|
|
2680
|
+
}
|
|
2681
|
+
function geometry(o2) {
|
|
2682
|
+
var type = o2.type, coordinates;
|
|
2683
|
+
switch (type) {
|
|
2684
|
+
case "GeometryCollection":
|
|
2685
|
+
return { type, geometries: o2.geometries.map(geometry) };
|
|
2686
|
+
case "Point":
|
|
2687
|
+
coordinates = point2(o2.coordinates);
|
|
2688
|
+
break;
|
|
2689
|
+
case "MultiPoint":
|
|
2690
|
+
coordinates = o2.coordinates.map(point2);
|
|
2691
|
+
break;
|
|
2692
|
+
case "LineString":
|
|
2693
|
+
coordinates = line(o2.arcs);
|
|
2694
|
+
break;
|
|
2695
|
+
case "MultiLineString":
|
|
2696
|
+
coordinates = o2.arcs.map(line);
|
|
2697
|
+
break;
|
|
2698
|
+
case "Polygon":
|
|
2699
|
+
coordinates = polygon2(o2.arcs);
|
|
2700
|
+
break;
|
|
2701
|
+
case "MultiPolygon":
|
|
2702
|
+
coordinates = o2.arcs.map(polygon2);
|
|
2703
|
+
break;
|
|
2704
|
+
default:
|
|
2705
|
+
return null;
|
|
2706
|
+
}
|
|
2707
|
+
return { type, coordinates };
|
|
2708
|
+
}
|
|
2709
|
+
return geometry(o);
|
|
2710
|
+
}
|
|
2711
|
+
|
|
2712
|
+
// node_modules/.pnpm/topojson-client@3.1.0/node_modules/topojson-client/src/stitch.js
|
|
2713
|
+
function stitch_default(topology, arcs) {
|
|
2714
|
+
var stitchedArcs = {}, fragmentByStart = {}, fragmentByEnd = {}, fragments = [], emptyIndex = -1;
|
|
2715
|
+
arcs.forEach(function(i, j) {
|
|
2716
|
+
var arc = topology.arcs[i < 0 ? ~i : i], t;
|
|
2717
|
+
if (arc.length < 3 && !arc[1][0] && !arc[1][1]) {
|
|
2718
|
+
t = arcs[++emptyIndex], arcs[emptyIndex] = i, arcs[j] = t;
|
|
2719
|
+
}
|
|
2720
|
+
});
|
|
2721
|
+
arcs.forEach(function(i) {
|
|
2722
|
+
var e = ends(i), start = e[0], end = e[1], f, g;
|
|
2723
|
+
if (f = fragmentByEnd[start]) {
|
|
2724
|
+
delete fragmentByEnd[f.end];
|
|
2725
|
+
f.push(i);
|
|
2726
|
+
f.end = end;
|
|
2727
|
+
if (g = fragmentByStart[end]) {
|
|
2728
|
+
delete fragmentByStart[g.start];
|
|
2729
|
+
var fg = g === f ? f : f.concat(g);
|
|
2730
|
+
fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.end] = fg;
|
|
2731
|
+
} else {
|
|
2732
|
+
fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
|
|
2733
|
+
}
|
|
2734
|
+
} else if (f = fragmentByStart[end]) {
|
|
2735
|
+
delete fragmentByStart[f.start];
|
|
2736
|
+
f.unshift(i);
|
|
2737
|
+
f.start = start;
|
|
2738
|
+
if (g = fragmentByEnd[start]) {
|
|
2739
|
+
delete fragmentByEnd[g.end];
|
|
2740
|
+
var gf = g === f ? f : g.concat(f);
|
|
2741
|
+
fragmentByStart[gf.start = g.start] = fragmentByEnd[gf.end = f.end] = gf;
|
|
2742
|
+
} else {
|
|
2743
|
+
fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
|
|
2744
|
+
}
|
|
2745
|
+
} else {
|
|
2746
|
+
f = [i];
|
|
2747
|
+
fragmentByStart[f.start = start] = fragmentByEnd[f.end = end] = f;
|
|
2748
|
+
}
|
|
2749
|
+
});
|
|
2750
|
+
function ends(i) {
|
|
2751
|
+
var arc = topology.arcs[i < 0 ? ~i : i], p0 = arc[0], p1;
|
|
2752
|
+
if (topology.transform) p1 = [0, 0], arc.forEach(function(dp) {
|
|
2753
|
+
p1[0] += dp[0], p1[1] += dp[1];
|
|
2754
|
+
});
|
|
2755
|
+
else p1 = arc[arc.length - 1];
|
|
2756
|
+
return i < 0 ? [p1, p0] : [p0, p1];
|
|
2757
|
+
}
|
|
2758
|
+
function flush(fragmentByEnd2, fragmentByStart2) {
|
|
2759
|
+
for (var k in fragmentByEnd2) {
|
|
2760
|
+
var f = fragmentByEnd2[k];
|
|
2761
|
+
delete fragmentByStart2[f.start];
|
|
2762
|
+
delete f.start;
|
|
2763
|
+
delete f.end;
|
|
2764
|
+
f.forEach(function(i) {
|
|
2765
|
+
stitchedArcs[i < 0 ? ~i : i] = 1;
|
|
2766
|
+
});
|
|
2767
|
+
fragments.push(f);
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
flush(fragmentByEnd, fragmentByStart);
|
|
2771
|
+
flush(fragmentByStart, fragmentByEnd);
|
|
2772
|
+
arcs.forEach(function(i) {
|
|
2773
|
+
if (!stitchedArcs[i < 0 ? ~i : i]) fragments.push([i]);
|
|
2774
|
+
});
|
|
2775
|
+
return fragments;
|
|
2776
|
+
}
|
|
2777
|
+
|
|
2778
|
+
// node_modules/.pnpm/topojson-client@3.1.0/node_modules/topojson-client/src/merge.js
|
|
2779
|
+
function planarRingArea(ring) {
|
|
2780
|
+
var i = -1, n = ring.length, a, b = ring[n - 1], area = 0;
|
|
2781
|
+
while (++i < n) a = b, b = ring[i], area += a[0] * b[1] - a[1] * b[0];
|
|
2782
|
+
return Math.abs(area);
|
|
2783
|
+
}
|
|
2784
|
+
function merge_default(topology) {
|
|
2785
|
+
return object(topology, mergeArcs.apply(this, arguments));
|
|
2786
|
+
}
|
|
2787
|
+
function mergeArcs(topology, objects) {
|
|
2788
|
+
var polygonsByArc = {}, polygons = [], groups = [];
|
|
2789
|
+
objects.forEach(geometry);
|
|
2790
|
+
function geometry(o) {
|
|
2791
|
+
switch (o.type) {
|
|
2792
|
+
case "GeometryCollection":
|
|
2793
|
+
o.geometries.forEach(geometry);
|
|
2794
|
+
break;
|
|
2795
|
+
case "Polygon":
|
|
2796
|
+
extract(o.arcs);
|
|
2797
|
+
break;
|
|
2798
|
+
case "MultiPolygon":
|
|
2799
|
+
o.arcs.forEach(extract);
|
|
2800
|
+
break;
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
function extract(polygon2) {
|
|
2804
|
+
polygon2.forEach(function(ring) {
|
|
2805
|
+
ring.forEach(function(arc) {
|
|
2806
|
+
(polygonsByArc[arc = arc < 0 ? ~arc : arc] || (polygonsByArc[arc] = [])).push(polygon2);
|
|
2807
|
+
});
|
|
2808
|
+
});
|
|
2809
|
+
polygons.push(polygon2);
|
|
2810
|
+
}
|
|
2811
|
+
function area(ring) {
|
|
2812
|
+
return planarRingArea(object(topology, { type: "Polygon", arcs: [ring] }).coordinates[0]);
|
|
2813
|
+
}
|
|
2814
|
+
polygons.forEach(function(polygon2) {
|
|
2815
|
+
if (!polygon2._) {
|
|
2816
|
+
var group = [], neighbors = [polygon2];
|
|
2817
|
+
polygon2._ = 1;
|
|
2818
|
+
groups.push(group);
|
|
2819
|
+
while (polygon2 = neighbors.pop()) {
|
|
2820
|
+
group.push(polygon2);
|
|
2821
|
+
polygon2.forEach(function(ring) {
|
|
2822
|
+
ring.forEach(function(arc) {
|
|
2823
|
+
polygonsByArc[arc < 0 ? ~arc : arc].forEach(function(polygon3) {
|
|
2824
|
+
if (!polygon3._) {
|
|
2825
|
+
polygon3._ = 1;
|
|
2826
|
+
neighbors.push(polygon3);
|
|
2827
|
+
}
|
|
2828
|
+
});
|
|
2829
|
+
});
|
|
2830
|
+
});
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
});
|
|
2834
|
+
polygons.forEach(function(polygon2) {
|
|
2835
|
+
delete polygon2._;
|
|
2836
|
+
});
|
|
2837
|
+
return {
|
|
2838
|
+
type: "MultiPolygon",
|
|
2839
|
+
arcs: groups.map(function(polygons2) {
|
|
2840
|
+
var arcs = [], n;
|
|
2841
|
+
polygons2.forEach(function(polygon2) {
|
|
2842
|
+
polygon2.forEach(function(ring) {
|
|
2843
|
+
ring.forEach(function(arc) {
|
|
2844
|
+
if (polygonsByArc[arc < 0 ? ~arc : arc].length < 2) {
|
|
2845
|
+
arcs.push(arc);
|
|
2846
|
+
}
|
|
2847
|
+
});
|
|
2848
|
+
});
|
|
2849
|
+
});
|
|
2850
|
+
arcs = stitch_default(topology, arcs);
|
|
2851
|
+
if ((n = arcs.length) > 1) {
|
|
2852
|
+
for (var i = 1, k = area(arcs[0]), ki, t; i < n; ++i) {
|
|
2853
|
+
if ((ki = area(arcs[i])) > k) {
|
|
2854
|
+
t = arcs[0], arcs[0] = arcs[i], arcs[i] = t, k = ki;
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
return arcs;
|
|
2859
|
+
}).filter(function(arcs) {
|
|
2860
|
+
return arcs.length > 0;
|
|
2861
|
+
})
|
|
2862
|
+
};
|
|
2863
|
+
}
|
|
2864
|
+
|
|
2865
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/object.js
|
|
2866
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2867
|
+
|
|
2868
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/bounds.js
|
|
2869
|
+
function bounds_default(objects) {
|
|
2870
|
+
var x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
|
|
2871
|
+
function boundGeometry(geometry) {
|
|
2872
|
+
if (geometry != null && hasOwnProperty.call(boundGeometryType, geometry.type)) boundGeometryType[geometry.type](geometry);
|
|
2873
|
+
}
|
|
2874
|
+
var boundGeometryType = {
|
|
2875
|
+
GeometryCollection: function(o) {
|
|
2876
|
+
o.geometries.forEach(boundGeometry);
|
|
2877
|
+
},
|
|
2878
|
+
Point: function(o) {
|
|
2879
|
+
boundPoint(o.coordinates);
|
|
2880
|
+
},
|
|
2881
|
+
MultiPoint: function(o) {
|
|
2882
|
+
o.coordinates.forEach(boundPoint);
|
|
2883
|
+
},
|
|
2884
|
+
LineString: function(o) {
|
|
2885
|
+
boundLine(o.arcs);
|
|
2886
|
+
},
|
|
2887
|
+
MultiLineString: function(o) {
|
|
2888
|
+
o.arcs.forEach(boundLine);
|
|
2889
|
+
},
|
|
2890
|
+
Polygon: function(o) {
|
|
2891
|
+
o.arcs.forEach(boundLine);
|
|
2892
|
+
},
|
|
2893
|
+
MultiPolygon: function(o) {
|
|
2894
|
+
o.arcs.forEach(boundMultiLine);
|
|
2895
|
+
}
|
|
2896
|
+
};
|
|
2897
|
+
function boundPoint(coordinates) {
|
|
2898
|
+
var x = coordinates[0], y = coordinates[1];
|
|
2899
|
+
if (x < x0) x0 = x;
|
|
2900
|
+
if (x > x1) x1 = x;
|
|
2901
|
+
if (y < y0) y0 = y;
|
|
2902
|
+
if (y > y1) y1 = y;
|
|
2903
|
+
}
|
|
2904
|
+
function boundLine(coordinates) {
|
|
2905
|
+
coordinates.forEach(boundPoint);
|
|
2906
|
+
}
|
|
2907
|
+
function boundMultiLine(coordinates) {
|
|
2908
|
+
coordinates.forEach(boundLine);
|
|
2909
|
+
}
|
|
2910
|
+
for (var key in objects) {
|
|
2911
|
+
boundGeometry(objects[key]);
|
|
2912
|
+
}
|
|
2913
|
+
return x1 >= x0 && y1 >= y0 ? [x0, y0, x1, y1] : void 0;
|
|
2914
|
+
}
|
|
2915
|
+
|
|
2916
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/hash/hashset.js
|
|
2917
|
+
function hashset_default(size, hash, equal, type, empty) {
|
|
2918
|
+
if (arguments.length === 3) {
|
|
2919
|
+
type = Array;
|
|
2920
|
+
empty = null;
|
|
2921
|
+
}
|
|
2922
|
+
var store = new type(size = 1 << Math.max(4, Math.ceil(Math.log(size) / Math.LN2))), mask = size - 1;
|
|
2923
|
+
for (var i = 0; i < size; ++i) {
|
|
2924
|
+
store[i] = empty;
|
|
2925
|
+
}
|
|
2926
|
+
function add(value) {
|
|
2927
|
+
var index = hash(value) & mask, match = store[index], collisions = 0;
|
|
2928
|
+
while (match != empty) {
|
|
2929
|
+
if (equal(match, value)) return true;
|
|
2930
|
+
if (++collisions >= size) throw new Error("full hashset");
|
|
2931
|
+
match = store[index = index + 1 & mask];
|
|
2932
|
+
}
|
|
2933
|
+
store[index] = value;
|
|
2934
|
+
return true;
|
|
2935
|
+
}
|
|
2936
|
+
function has(value) {
|
|
2937
|
+
var index = hash(value) & mask, match = store[index], collisions = 0;
|
|
2938
|
+
while (match != empty) {
|
|
2939
|
+
if (equal(match, value)) return true;
|
|
2940
|
+
if (++collisions >= size) break;
|
|
2941
|
+
match = store[index = index + 1 & mask];
|
|
2942
|
+
}
|
|
2943
|
+
return false;
|
|
2944
|
+
}
|
|
2945
|
+
function values() {
|
|
2946
|
+
var values2 = [];
|
|
2947
|
+
for (var i2 = 0, n = store.length; i2 < n; ++i2) {
|
|
2948
|
+
var match = store[i2];
|
|
2949
|
+
if (match != empty) values2.push(match);
|
|
2950
|
+
}
|
|
2951
|
+
return values2;
|
|
2952
|
+
}
|
|
2953
|
+
return {
|
|
2954
|
+
add,
|
|
2955
|
+
has,
|
|
2956
|
+
values
|
|
2957
|
+
};
|
|
2958
|
+
}
|
|
2959
|
+
|
|
2960
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/hash/hashmap.js
|
|
2961
|
+
function hashmap_default(size, hash, equal, keyType, keyEmpty, valueType) {
|
|
2962
|
+
if (arguments.length === 3) {
|
|
2963
|
+
keyType = valueType = Array;
|
|
2964
|
+
keyEmpty = null;
|
|
2965
|
+
}
|
|
2966
|
+
var keystore = new keyType(size = 1 << Math.max(4, Math.ceil(Math.log(size) / Math.LN2))), valstore = new valueType(size), mask = size - 1;
|
|
2967
|
+
for (var i = 0; i < size; ++i) {
|
|
2968
|
+
keystore[i] = keyEmpty;
|
|
2969
|
+
}
|
|
2970
|
+
function set(key, value) {
|
|
2971
|
+
var index = hash(key) & mask, matchKey = keystore[index], collisions = 0;
|
|
2972
|
+
while (matchKey != keyEmpty) {
|
|
2973
|
+
if (equal(matchKey, key)) return valstore[index] = value;
|
|
2974
|
+
if (++collisions >= size) throw new Error("full hashmap");
|
|
2975
|
+
matchKey = keystore[index = index + 1 & mask];
|
|
2976
|
+
}
|
|
2977
|
+
keystore[index] = key;
|
|
2978
|
+
valstore[index] = value;
|
|
2979
|
+
return value;
|
|
2980
|
+
}
|
|
2981
|
+
function maybeSet(key, value) {
|
|
2982
|
+
var index = hash(key) & mask, matchKey = keystore[index], collisions = 0;
|
|
2983
|
+
while (matchKey != keyEmpty) {
|
|
2984
|
+
if (equal(matchKey, key)) return valstore[index];
|
|
2985
|
+
if (++collisions >= size) throw new Error("full hashmap");
|
|
2986
|
+
matchKey = keystore[index = index + 1 & mask];
|
|
2987
|
+
}
|
|
2988
|
+
keystore[index] = key;
|
|
2989
|
+
valstore[index] = value;
|
|
2990
|
+
return value;
|
|
2991
|
+
}
|
|
2992
|
+
function get(key, missingValue) {
|
|
2993
|
+
var index = hash(key) & mask, matchKey = keystore[index], collisions = 0;
|
|
2994
|
+
while (matchKey != keyEmpty) {
|
|
2995
|
+
if (equal(matchKey, key)) return valstore[index];
|
|
2996
|
+
if (++collisions >= size) break;
|
|
2997
|
+
matchKey = keystore[index = index + 1 & mask];
|
|
2998
|
+
}
|
|
2999
|
+
return missingValue;
|
|
3000
|
+
}
|
|
3001
|
+
function keys() {
|
|
3002
|
+
var keys2 = [];
|
|
3003
|
+
for (var i2 = 0, n = keystore.length; i2 < n; ++i2) {
|
|
3004
|
+
var matchKey = keystore[i2];
|
|
3005
|
+
if (matchKey != keyEmpty) keys2.push(matchKey);
|
|
3006
|
+
}
|
|
3007
|
+
return keys2;
|
|
3008
|
+
}
|
|
3009
|
+
return {
|
|
3010
|
+
set,
|
|
3011
|
+
maybeSet,
|
|
3012
|
+
// set if unset
|
|
3013
|
+
get,
|
|
3014
|
+
keys
|
|
3015
|
+
};
|
|
3016
|
+
}
|
|
3017
|
+
|
|
3018
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/hash/point-equal.js
|
|
3019
|
+
function point_equal_default(pointA, pointB) {
|
|
3020
|
+
return pointA[0] === pointB[0] && pointA[1] === pointB[1];
|
|
3021
|
+
}
|
|
3022
|
+
|
|
3023
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/hash/point-hash.js
|
|
3024
|
+
var buffer = new ArrayBuffer(16);
|
|
3025
|
+
var floats = new Float64Array(buffer);
|
|
3026
|
+
var uints = new Uint32Array(buffer);
|
|
3027
|
+
function point_hash_default(point2) {
|
|
3028
|
+
floats[0] = point2[0];
|
|
3029
|
+
floats[1] = point2[1];
|
|
3030
|
+
var hash = uints[0] ^ uints[1];
|
|
3031
|
+
hash = hash << 5 ^ hash >> 7 ^ uints[2] ^ uints[3];
|
|
3032
|
+
return hash & 2147483647;
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/join.js
|
|
3036
|
+
function join_default(topology) {
|
|
3037
|
+
var coordinates = topology.coordinates, lines = topology.lines, rings = topology.rings, indexes = index(), visitedByIndex = new Int32Array(coordinates.length), leftByIndex = new Int32Array(coordinates.length), rightByIndex = new Int32Array(coordinates.length), junctionByIndex = new Int8Array(coordinates.length), junctionCount = 0, i, n, previousIndex, currentIndex, nextIndex;
|
|
3038
|
+
for (i = 0, n = coordinates.length; i < n; ++i) {
|
|
3039
|
+
visitedByIndex[i] = leftByIndex[i] = rightByIndex[i] = -1;
|
|
3040
|
+
}
|
|
3041
|
+
for (i = 0, n = lines.length; i < n; ++i) {
|
|
3042
|
+
var line = lines[i], lineStart = line[0], lineEnd = line[1];
|
|
3043
|
+
currentIndex = indexes[lineStart];
|
|
3044
|
+
nextIndex = indexes[++lineStart];
|
|
3045
|
+
++junctionCount, junctionByIndex[currentIndex] = 1;
|
|
3046
|
+
while (++lineStart <= lineEnd) {
|
|
3047
|
+
sequence(i, previousIndex = currentIndex, currentIndex = nextIndex, nextIndex = indexes[lineStart]);
|
|
3048
|
+
}
|
|
3049
|
+
++junctionCount, junctionByIndex[nextIndex] = 1;
|
|
3050
|
+
}
|
|
3051
|
+
for (i = 0, n = coordinates.length; i < n; ++i) {
|
|
3052
|
+
visitedByIndex[i] = -1;
|
|
3053
|
+
}
|
|
3054
|
+
for (i = 0, n = rings.length; i < n; ++i) {
|
|
3055
|
+
var ring = rings[i], ringStart = ring[0] + 1, ringEnd = ring[1];
|
|
3056
|
+
previousIndex = indexes[ringEnd - 1];
|
|
3057
|
+
currentIndex = indexes[ringStart - 1];
|
|
3058
|
+
nextIndex = indexes[ringStart];
|
|
3059
|
+
sequence(i, previousIndex, currentIndex, nextIndex);
|
|
3060
|
+
while (++ringStart <= ringEnd) {
|
|
3061
|
+
sequence(i, previousIndex = currentIndex, currentIndex = nextIndex, nextIndex = indexes[ringStart]);
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
function sequence(i2, previousIndex2, currentIndex2, nextIndex2) {
|
|
3065
|
+
if (visitedByIndex[currentIndex2] === i2) return;
|
|
3066
|
+
visitedByIndex[currentIndex2] = i2;
|
|
3067
|
+
var leftIndex = leftByIndex[currentIndex2];
|
|
3068
|
+
if (leftIndex >= 0) {
|
|
3069
|
+
var rightIndex = rightByIndex[currentIndex2];
|
|
3070
|
+
if ((leftIndex !== previousIndex2 || rightIndex !== nextIndex2) && (leftIndex !== nextIndex2 || rightIndex !== previousIndex2)) {
|
|
3071
|
+
++junctionCount, junctionByIndex[currentIndex2] = 1;
|
|
3072
|
+
}
|
|
3073
|
+
} else {
|
|
3074
|
+
leftByIndex[currentIndex2] = previousIndex2;
|
|
3075
|
+
rightByIndex[currentIndex2] = nextIndex2;
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
function index() {
|
|
3079
|
+
var indexByPoint = hashmap_default(coordinates.length * 1.4, hashIndex, equalIndex, Int32Array, -1, Int32Array), indexes2 = new Int32Array(coordinates.length);
|
|
3080
|
+
for (var i2 = 0, n2 = coordinates.length; i2 < n2; ++i2) {
|
|
3081
|
+
indexes2[i2] = indexByPoint.maybeSet(i2, i2);
|
|
3082
|
+
}
|
|
3083
|
+
return indexes2;
|
|
3084
|
+
}
|
|
3085
|
+
function hashIndex(i2) {
|
|
3086
|
+
return point_hash_default(coordinates[i2]);
|
|
3087
|
+
}
|
|
3088
|
+
function equalIndex(i2, j2) {
|
|
3089
|
+
return point_equal_default(coordinates[i2], coordinates[j2]);
|
|
3090
|
+
}
|
|
3091
|
+
visitedByIndex = leftByIndex = rightByIndex = null;
|
|
3092
|
+
var junctionByPoint = hashset_default(junctionCount * 1.4, point_hash_default, point_equal_default), j;
|
|
3093
|
+
for (i = 0, n = coordinates.length; i < n; ++i) {
|
|
3094
|
+
if (junctionByIndex[j = indexes[i]]) {
|
|
3095
|
+
junctionByPoint.add(coordinates[j]);
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
return junctionByPoint;
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3101
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/cut.js
|
|
3102
|
+
function cut_default(topology) {
|
|
3103
|
+
var junctions = join_default(topology), coordinates = topology.coordinates, lines = topology.lines, rings = topology.rings, next, i, n;
|
|
3104
|
+
for (i = 0, n = lines.length; i < n; ++i) {
|
|
3105
|
+
var line = lines[i], lineMid = line[0], lineEnd = line[1];
|
|
3106
|
+
while (++lineMid < lineEnd) {
|
|
3107
|
+
if (junctions.has(coordinates[lineMid])) {
|
|
3108
|
+
next = { 0: lineMid, 1: line[1] };
|
|
3109
|
+
line[1] = lineMid;
|
|
3110
|
+
line = line.next = next;
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
for (i = 0, n = rings.length; i < n; ++i) {
|
|
3115
|
+
var ring = rings[i], ringStart = ring[0], ringMid = ringStart, ringEnd = ring[1], ringFixed = junctions.has(coordinates[ringStart]);
|
|
3116
|
+
while (++ringMid < ringEnd) {
|
|
3117
|
+
if (junctions.has(coordinates[ringMid])) {
|
|
3118
|
+
if (ringFixed) {
|
|
3119
|
+
next = { 0: ringMid, 1: ring[1] };
|
|
3120
|
+
ring[1] = ringMid;
|
|
3121
|
+
ring = ring.next = next;
|
|
3122
|
+
} else {
|
|
3123
|
+
rotateArray(coordinates, ringStart, ringEnd, ringEnd - ringMid);
|
|
3124
|
+
coordinates[ringEnd] = coordinates[ringStart];
|
|
3125
|
+
ringFixed = true;
|
|
3126
|
+
ringMid = ringStart;
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
return topology;
|
|
3132
|
+
}
|
|
3133
|
+
function rotateArray(array, start, end, offset) {
|
|
3134
|
+
reverse(array, start, end);
|
|
3135
|
+
reverse(array, start, start + offset);
|
|
3136
|
+
reverse(array, start + offset, end);
|
|
3137
|
+
}
|
|
3138
|
+
function reverse(array, start, end) {
|
|
3139
|
+
for (var mid = start + (end-- - start >> 1), t; start < mid; ++start, --end) {
|
|
3140
|
+
t = array[start], array[start] = array[end], array[end] = t;
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
|
|
3144
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/dedup.js
|
|
3145
|
+
function dedup_default(topology) {
|
|
3146
|
+
var coordinates = topology.coordinates, lines = topology.lines, line, rings = topology.rings, ring, arcCount = lines.length + rings.length, i, n;
|
|
3147
|
+
delete topology.lines;
|
|
3148
|
+
delete topology.rings;
|
|
3149
|
+
for (i = 0, n = lines.length; i < n; ++i) {
|
|
3150
|
+
line = lines[i];
|
|
3151
|
+
while (line = line.next) ++arcCount;
|
|
3152
|
+
}
|
|
3153
|
+
for (i = 0, n = rings.length; i < n; ++i) {
|
|
3154
|
+
ring = rings[i];
|
|
3155
|
+
while (ring = ring.next) ++arcCount;
|
|
3156
|
+
}
|
|
3157
|
+
var arcsByEnd = hashmap_default(arcCount * 2 * 1.4, point_hash_default, point_equal_default), arcs = topology.arcs = [];
|
|
3158
|
+
for (i = 0, n = lines.length; i < n; ++i) {
|
|
3159
|
+
line = lines[i];
|
|
3160
|
+
do {
|
|
3161
|
+
dedupLine(line);
|
|
3162
|
+
} while (line = line.next);
|
|
3163
|
+
}
|
|
3164
|
+
for (i = 0, n = rings.length; i < n; ++i) {
|
|
3165
|
+
ring = rings[i];
|
|
3166
|
+
if (ring.next) {
|
|
3167
|
+
do {
|
|
3168
|
+
dedupLine(ring);
|
|
3169
|
+
} while (ring = ring.next);
|
|
3170
|
+
} else {
|
|
3171
|
+
dedupRing(ring);
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
function dedupLine(arc) {
|
|
3175
|
+
var startPoint, endPoint, startArcs, startArc, endArcs, endArc, i2, n2;
|
|
3176
|
+
if (startArcs = arcsByEnd.get(startPoint = coordinates[arc[0]])) {
|
|
3177
|
+
for (i2 = 0, n2 = startArcs.length; i2 < n2; ++i2) {
|
|
3178
|
+
startArc = startArcs[i2];
|
|
3179
|
+
if (equalLine(startArc, arc)) {
|
|
3180
|
+
arc[0] = startArc[0];
|
|
3181
|
+
arc[1] = startArc[1];
|
|
3182
|
+
return;
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
}
|
|
3186
|
+
if (endArcs = arcsByEnd.get(endPoint = coordinates[arc[1]])) {
|
|
3187
|
+
for (i2 = 0, n2 = endArcs.length; i2 < n2; ++i2) {
|
|
3188
|
+
endArc = endArcs[i2];
|
|
3189
|
+
if (reverseEqualLine(endArc, arc)) {
|
|
3190
|
+
arc[1] = endArc[0];
|
|
3191
|
+
arc[0] = endArc[1];
|
|
3192
|
+
return;
|
|
3193
|
+
}
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
if (startArcs) startArcs.push(arc);
|
|
3197
|
+
else arcsByEnd.set(startPoint, [arc]);
|
|
3198
|
+
if (endArcs) endArcs.push(arc);
|
|
3199
|
+
else arcsByEnd.set(endPoint, [arc]);
|
|
3200
|
+
arcs.push(arc);
|
|
3201
|
+
}
|
|
3202
|
+
function dedupRing(arc) {
|
|
3203
|
+
var endPoint, endArcs, endArc, i2, n2;
|
|
3204
|
+
if (endArcs = arcsByEnd.get(endPoint = coordinates[arc[0]])) {
|
|
3205
|
+
for (i2 = 0, n2 = endArcs.length; i2 < n2; ++i2) {
|
|
3206
|
+
endArc = endArcs[i2];
|
|
3207
|
+
if (equalRing(endArc, arc)) {
|
|
3208
|
+
arc[0] = endArc[0];
|
|
3209
|
+
arc[1] = endArc[1];
|
|
3210
|
+
return;
|
|
3211
|
+
}
|
|
3212
|
+
if (reverseEqualRing(endArc, arc)) {
|
|
3213
|
+
arc[0] = endArc[1];
|
|
3214
|
+
arc[1] = endArc[0];
|
|
3215
|
+
return;
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
}
|
|
3219
|
+
if (endArcs = arcsByEnd.get(endPoint = coordinates[arc[0] + findMinimumOffset(arc)])) {
|
|
3220
|
+
for (i2 = 0, n2 = endArcs.length; i2 < n2; ++i2) {
|
|
3221
|
+
endArc = endArcs[i2];
|
|
3222
|
+
if (equalRing(endArc, arc)) {
|
|
3223
|
+
arc[0] = endArc[0];
|
|
3224
|
+
arc[1] = endArc[1];
|
|
3225
|
+
return;
|
|
3226
|
+
}
|
|
3227
|
+
if (reverseEqualRing(endArc, arc)) {
|
|
3228
|
+
arc[0] = endArc[1];
|
|
3229
|
+
arc[1] = endArc[0];
|
|
3230
|
+
return;
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
if (endArcs) endArcs.push(arc);
|
|
3235
|
+
else arcsByEnd.set(endPoint, [arc]);
|
|
3236
|
+
arcs.push(arc);
|
|
3237
|
+
}
|
|
3238
|
+
function equalLine(arcA, arcB) {
|
|
3239
|
+
var ia = arcA[0], ib = arcB[0], ja = arcA[1], jb = arcB[1];
|
|
3240
|
+
if (ia - ja !== ib - jb) return false;
|
|
3241
|
+
for (; ia <= ja; ++ia, ++ib) if (!point_equal_default(coordinates[ia], coordinates[ib])) return false;
|
|
3242
|
+
return true;
|
|
3243
|
+
}
|
|
3244
|
+
function reverseEqualLine(arcA, arcB) {
|
|
3245
|
+
var ia = arcA[0], ib = arcB[0], ja = arcA[1], jb = arcB[1];
|
|
3246
|
+
if (ia - ja !== ib - jb) return false;
|
|
3247
|
+
for (; ia <= ja; ++ia, --jb) if (!point_equal_default(coordinates[ia], coordinates[jb])) return false;
|
|
3248
|
+
return true;
|
|
3249
|
+
}
|
|
3250
|
+
function equalRing(arcA, arcB) {
|
|
3251
|
+
var ia = arcA[0], ib = arcB[0], ja = arcA[1], jb = arcB[1], n2 = ja - ia;
|
|
3252
|
+
if (n2 !== jb - ib) return false;
|
|
3253
|
+
var ka = findMinimumOffset(arcA), kb = findMinimumOffset(arcB);
|
|
3254
|
+
for (var i2 = 0; i2 < n2; ++i2) {
|
|
3255
|
+
if (!point_equal_default(coordinates[ia + (i2 + ka) % n2], coordinates[ib + (i2 + kb) % n2])) return false;
|
|
3256
|
+
}
|
|
3257
|
+
return true;
|
|
3258
|
+
}
|
|
3259
|
+
function reverseEqualRing(arcA, arcB) {
|
|
3260
|
+
var ia = arcA[0], ib = arcB[0], ja = arcA[1], jb = arcB[1], n2 = ja - ia;
|
|
3261
|
+
if (n2 !== jb - ib) return false;
|
|
3262
|
+
var ka = findMinimumOffset(arcA), kb = n2 - findMinimumOffset(arcB);
|
|
3263
|
+
for (var i2 = 0; i2 < n2; ++i2) {
|
|
3264
|
+
if (!point_equal_default(coordinates[ia + (i2 + ka) % n2], coordinates[jb - (i2 + kb) % n2])) return false;
|
|
3265
|
+
}
|
|
3266
|
+
return true;
|
|
3267
|
+
}
|
|
3268
|
+
function findMinimumOffset(arc) {
|
|
3269
|
+
var start = arc[0], end = arc[1], mid = start, minimum = mid, minimumPoint = coordinates[mid];
|
|
3270
|
+
while (++mid < end) {
|
|
3271
|
+
var point2 = coordinates[mid];
|
|
3272
|
+
if (point2[0] < minimumPoint[0] || point2[0] === minimumPoint[0] && point2[1] < minimumPoint[1]) {
|
|
3273
|
+
minimum = mid;
|
|
3274
|
+
minimumPoint = point2;
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
return minimum - start;
|
|
3278
|
+
}
|
|
3279
|
+
return topology;
|
|
3280
|
+
}
|
|
3281
|
+
|
|
3282
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/delta.js
|
|
3283
|
+
function delta_default(arcs) {
|
|
3284
|
+
var i = -1, n = arcs.length;
|
|
3285
|
+
while (++i < n) {
|
|
3286
|
+
var arc = arcs[i], j = 0, k = 1, m = arc.length, point2 = arc[0], x0 = point2[0], y0 = point2[1], x1, y1;
|
|
3287
|
+
while (++j < m) {
|
|
3288
|
+
point2 = arc[j], x1 = point2[0], y1 = point2[1];
|
|
3289
|
+
if (x1 !== x0 || y1 !== y0) arc[k++] = [x1 - x0, y1 - y0], x0 = x1, y0 = y1;
|
|
3290
|
+
}
|
|
3291
|
+
if (k === 1) arc[k++] = [0, 0];
|
|
3292
|
+
arc.length = k;
|
|
3293
|
+
}
|
|
3294
|
+
return arcs;
|
|
3295
|
+
}
|
|
3296
|
+
|
|
3297
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/extract.js
|
|
3298
|
+
function extract_default(objects) {
|
|
3299
|
+
var index = -1, lines = [], rings = [], coordinates = [];
|
|
3300
|
+
function extractGeometry(geometry) {
|
|
3301
|
+
if (geometry && hasOwnProperty.call(extractGeometryType, geometry.type)) extractGeometryType[geometry.type](geometry);
|
|
3302
|
+
}
|
|
3303
|
+
var extractGeometryType = {
|
|
3304
|
+
GeometryCollection: function(o) {
|
|
3305
|
+
o.geometries.forEach(extractGeometry);
|
|
3306
|
+
},
|
|
3307
|
+
LineString: function(o) {
|
|
3308
|
+
o.arcs = extractLine(o.arcs);
|
|
3309
|
+
},
|
|
3310
|
+
MultiLineString: function(o) {
|
|
3311
|
+
o.arcs = o.arcs.map(extractLine);
|
|
3312
|
+
},
|
|
3313
|
+
Polygon: function(o) {
|
|
3314
|
+
o.arcs = o.arcs.map(extractRing);
|
|
3315
|
+
},
|
|
3316
|
+
MultiPolygon: function(o) {
|
|
3317
|
+
o.arcs = o.arcs.map(extractMultiRing);
|
|
3318
|
+
}
|
|
3319
|
+
};
|
|
3320
|
+
function extractLine(line) {
|
|
3321
|
+
for (var i = 0, n = line.length; i < n; ++i) coordinates[++index] = line[i];
|
|
3322
|
+
var arc = { 0: index - n + 1, 1: index };
|
|
3323
|
+
lines.push(arc);
|
|
3324
|
+
return arc;
|
|
3325
|
+
}
|
|
3326
|
+
function extractRing(ring) {
|
|
3327
|
+
for (var i = 0, n = ring.length; i < n; ++i) coordinates[++index] = ring[i];
|
|
3328
|
+
var arc = { 0: index - n + 1, 1: index };
|
|
3329
|
+
rings.push(arc);
|
|
3330
|
+
return arc;
|
|
3331
|
+
}
|
|
3332
|
+
function extractMultiRing(rings2) {
|
|
3333
|
+
return rings2.map(extractRing);
|
|
3334
|
+
}
|
|
3335
|
+
for (var key in objects) {
|
|
3336
|
+
extractGeometry(objects[key]);
|
|
3337
|
+
}
|
|
3338
|
+
return {
|
|
3339
|
+
type: "Topology",
|
|
3340
|
+
coordinates,
|
|
3341
|
+
lines,
|
|
3342
|
+
rings,
|
|
3343
|
+
objects
|
|
3344
|
+
};
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3347
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/geometry.js
|
|
3348
|
+
function geometry_default(inputs) {
|
|
3349
|
+
var outputs = {}, key;
|
|
3350
|
+
for (key in inputs) outputs[key] = geomifyObject(inputs[key]);
|
|
3351
|
+
return outputs;
|
|
3352
|
+
}
|
|
3353
|
+
function geomifyObject(input) {
|
|
3354
|
+
return input == null ? { type: null } : (input.type === "FeatureCollection" ? geomifyFeatureCollection : input.type === "Feature" ? geomifyFeature : geomifyGeometry)(input);
|
|
3355
|
+
}
|
|
3356
|
+
function geomifyFeatureCollection(input) {
|
|
3357
|
+
var output = { type: "GeometryCollection", geometries: input.features.map(geomifyFeature) };
|
|
3358
|
+
if (input.bbox != null) output.bbox = input.bbox;
|
|
3359
|
+
return output;
|
|
3360
|
+
}
|
|
3361
|
+
function geomifyFeature(input) {
|
|
3362
|
+
var output = geomifyGeometry(input.geometry), key;
|
|
3363
|
+
if (input.id != null) output.id = input.id;
|
|
3364
|
+
if (input.bbox != null) output.bbox = input.bbox;
|
|
3365
|
+
for (key in input.properties) {
|
|
3366
|
+
output.properties = input.properties;
|
|
3367
|
+
break;
|
|
3368
|
+
}
|
|
3369
|
+
return output;
|
|
3370
|
+
}
|
|
3371
|
+
function geomifyGeometry(input) {
|
|
3372
|
+
if (input == null) return { type: null };
|
|
3373
|
+
var output = input.type === "GeometryCollection" ? { type: "GeometryCollection", geometries: input.geometries.map(geomifyGeometry) } : input.type === "Point" || input.type === "MultiPoint" ? { type: input.type, coordinates: input.coordinates } : { type: input.type, arcs: input.coordinates };
|
|
3374
|
+
if (input.bbox != null) output.bbox = input.bbox;
|
|
3375
|
+
return output;
|
|
3376
|
+
}
|
|
3377
|
+
|
|
3378
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/prequantize.js
|
|
3379
|
+
function prequantize_default(objects, bbox, n) {
|
|
3380
|
+
var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3], kx = x1 - x0 ? (n - 1) / (x1 - x0) : 1, ky = y1 - y0 ? (n - 1) / (y1 - y0) : 1;
|
|
3381
|
+
function quantizePoint(input) {
|
|
3382
|
+
return [Math.round((input[0] - x0) * kx), Math.round((input[1] - y0) * ky)];
|
|
3383
|
+
}
|
|
3384
|
+
function quantizePoints(input, m) {
|
|
3385
|
+
var i = -1, j = 0, n2 = input.length, output = new Array(n2), pi, px, py, x, y;
|
|
3386
|
+
while (++i < n2) {
|
|
3387
|
+
pi = input[i];
|
|
3388
|
+
x = Math.round((pi[0] - x0) * kx);
|
|
3389
|
+
y = Math.round((pi[1] - y0) * ky);
|
|
3390
|
+
if (x !== px || y !== py) output[j++] = [px = x, py = y];
|
|
3391
|
+
}
|
|
3392
|
+
output.length = j;
|
|
3393
|
+
while (j < m) j = output.push([output[0][0], output[0][1]]);
|
|
3394
|
+
return output;
|
|
3395
|
+
}
|
|
3396
|
+
function quantizeLine(input) {
|
|
3397
|
+
return quantizePoints(input, 2);
|
|
3398
|
+
}
|
|
3399
|
+
function quantizeRing(input) {
|
|
3400
|
+
return quantizePoints(input, 4);
|
|
3401
|
+
}
|
|
3402
|
+
function quantizePolygon(input) {
|
|
3403
|
+
return input.map(quantizeRing);
|
|
3404
|
+
}
|
|
3405
|
+
function quantizeGeometry(o) {
|
|
3406
|
+
if (o != null && hasOwnProperty.call(quantizeGeometryType, o.type)) quantizeGeometryType[o.type](o);
|
|
3407
|
+
}
|
|
3408
|
+
var quantizeGeometryType = {
|
|
3409
|
+
GeometryCollection: function(o) {
|
|
3410
|
+
o.geometries.forEach(quantizeGeometry);
|
|
3411
|
+
},
|
|
3412
|
+
Point: function(o) {
|
|
3413
|
+
o.coordinates = quantizePoint(o.coordinates);
|
|
3414
|
+
},
|
|
3415
|
+
MultiPoint: function(o) {
|
|
3416
|
+
o.coordinates = o.coordinates.map(quantizePoint);
|
|
3417
|
+
},
|
|
3418
|
+
LineString: function(o) {
|
|
3419
|
+
o.arcs = quantizeLine(o.arcs);
|
|
3420
|
+
},
|
|
3421
|
+
MultiLineString: function(o) {
|
|
3422
|
+
o.arcs = o.arcs.map(quantizeLine);
|
|
3423
|
+
},
|
|
3424
|
+
Polygon: function(o) {
|
|
3425
|
+
o.arcs = quantizePolygon(o.arcs);
|
|
3426
|
+
},
|
|
3427
|
+
MultiPolygon: function(o) {
|
|
3428
|
+
o.arcs = o.arcs.map(quantizePolygon);
|
|
3429
|
+
}
|
|
3430
|
+
};
|
|
3431
|
+
for (var key in objects) {
|
|
3432
|
+
quantizeGeometry(objects[key]);
|
|
3433
|
+
}
|
|
3434
|
+
return {
|
|
3435
|
+
scale: [1 / kx, 1 / ky],
|
|
3436
|
+
translate: [x0, y0]
|
|
3437
|
+
};
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
// node_modules/.pnpm/topojson-server@3.0.1/node_modules/topojson-server/src/topology.js
|
|
3441
|
+
function topology_default(objects, quantization) {
|
|
3442
|
+
var bbox = bounds_default(objects = geometry_default(objects)), transform = quantization > 0 && bbox && prequantize_default(objects, bbox, quantization), topology = dedup_default(cut_default(extract_default(objects))), coordinates = topology.coordinates, indexByArc = hashmap_default(topology.arcs.length * 1.4, hashArc, equalArc);
|
|
3443
|
+
objects = topology.objects;
|
|
3444
|
+
topology.bbox = bbox;
|
|
3445
|
+
topology.arcs = topology.arcs.map(function(arc, i) {
|
|
3446
|
+
indexByArc.set(arc, i);
|
|
3447
|
+
return coordinates.slice(arc[0], arc[1] + 1);
|
|
3448
|
+
});
|
|
3449
|
+
delete topology.coordinates;
|
|
3450
|
+
coordinates = null;
|
|
3451
|
+
function indexGeometry(geometry) {
|
|
3452
|
+
if (geometry && hasOwnProperty.call(indexGeometryType, geometry.type)) indexGeometryType[geometry.type](geometry);
|
|
3453
|
+
}
|
|
3454
|
+
var indexGeometryType = {
|
|
3455
|
+
GeometryCollection: function(o) {
|
|
3456
|
+
o.geometries.forEach(indexGeometry);
|
|
3457
|
+
},
|
|
3458
|
+
LineString: function(o) {
|
|
3459
|
+
o.arcs = indexArcs(o.arcs);
|
|
3460
|
+
},
|
|
3461
|
+
MultiLineString: function(o) {
|
|
3462
|
+
o.arcs = o.arcs.map(indexArcs);
|
|
3463
|
+
},
|
|
3464
|
+
Polygon: function(o) {
|
|
3465
|
+
o.arcs = o.arcs.map(indexArcs);
|
|
3466
|
+
},
|
|
3467
|
+
MultiPolygon: function(o) {
|
|
3468
|
+
o.arcs = o.arcs.map(indexMultiArcs);
|
|
3469
|
+
}
|
|
3470
|
+
};
|
|
3471
|
+
function indexArcs(arc) {
|
|
3472
|
+
var indexes = [];
|
|
3473
|
+
do {
|
|
3474
|
+
var index = indexByArc.get(arc);
|
|
3475
|
+
indexes.push(arc[0] < arc[1] ? index : ~index);
|
|
3476
|
+
} while (arc = arc.next);
|
|
3477
|
+
return indexes;
|
|
3478
|
+
}
|
|
3479
|
+
function indexMultiArcs(arcs) {
|
|
3480
|
+
return arcs.map(indexArcs);
|
|
3481
|
+
}
|
|
3482
|
+
for (var key in objects) {
|
|
3483
|
+
indexGeometry(objects[key]);
|
|
3484
|
+
}
|
|
3485
|
+
if (transform) {
|
|
3486
|
+
topology.transform = transform;
|
|
3487
|
+
topology.arcs = delta_default(topology.arcs);
|
|
3488
|
+
}
|
|
3489
|
+
return topology;
|
|
3490
|
+
}
|
|
3491
|
+
function hashArc(arc) {
|
|
3492
|
+
var i = arc[0], j = arc[1], t;
|
|
3493
|
+
if (j < i) t = i, i = j, j = t;
|
|
3494
|
+
return i + 31 * j;
|
|
3495
|
+
}
|
|
3496
|
+
function equalArc(arcA, arcB) {
|
|
3497
|
+
var ia = arcA[0], ja = arcA[1], ib = arcB[0], jb = arcB[1], t;
|
|
3498
|
+
if (ja < ia) t = ia, ia = ja, ja = t;
|
|
3499
|
+
if (jb < ib) t = ib, ib = jb, jb = t;
|
|
3500
|
+
return ia === ib && ja === jb;
|
|
3501
|
+
}
|
|
3502
|
+
|
|
3503
|
+
// node_modules/.pnpm/@turf+concave@7.3.1/node_modules/@turf/concave/dist/esm/index.js
|
|
3504
|
+
function lineDissolve(geojson, options = {}) {
|
|
3505
|
+
options = options || {};
|
|
3506
|
+
if (!isObject(options)) {
|
|
3507
|
+
throw new Error("options is invalid");
|
|
3508
|
+
}
|
|
3509
|
+
const mutate = options.mutate;
|
|
3510
|
+
if (getType(geojson) !== "FeatureCollection") {
|
|
3511
|
+
throw new Error("geojson must be a FeatureCollection");
|
|
3512
|
+
}
|
|
3513
|
+
if (!geojson.features.length) {
|
|
3514
|
+
throw new Error("geojson is empty");
|
|
3515
|
+
}
|
|
3516
|
+
if (mutate === false || mutate === void 0) {
|
|
3517
|
+
geojson = clone(geojson);
|
|
3518
|
+
}
|
|
3519
|
+
const result = [];
|
|
3520
|
+
const lastLine = lineReduce(
|
|
3521
|
+
geojson,
|
|
3522
|
+
(previousLine, currentLine) => {
|
|
3523
|
+
const merged = mergeLineStrings(previousLine, currentLine);
|
|
3524
|
+
if (merged) {
|
|
3525
|
+
return merged;
|
|
3526
|
+
} else {
|
|
3527
|
+
result.push(previousLine);
|
|
3528
|
+
return currentLine;
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
);
|
|
3532
|
+
if (lastLine) {
|
|
3533
|
+
result.push(lastLine);
|
|
3534
|
+
}
|
|
3535
|
+
if (!result.length) {
|
|
3536
|
+
return null;
|
|
3537
|
+
} else if (result.length === 1) {
|
|
3538
|
+
return result[0];
|
|
3539
|
+
} else {
|
|
3540
|
+
return multiLineString(
|
|
3541
|
+
result.map((line) => {
|
|
3542
|
+
return line.coordinates;
|
|
3543
|
+
})
|
|
3544
|
+
);
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
function coordId(coord) {
|
|
3548
|
+
return coord[0].toString() + "," + coord[1].toString();
|
|
3549
|
+
}
|
|
3550
|
+
function mergeLineStrings(a, b) {
|
|
3551
|
+
const coords1 = a.geometry.coordinates;
|
|
3552
|
+
const coords2 = b.geometry.coordinates;
|
|
3553
|
+
const s1 = coordId(coords1[0]);
|
|
3554
|
+
const e1 = coordId(coords1[coords1.length - 1]);
|
|
3555
|
+
const s2 = coordId(coords2[0]);
|
|
3556
|
+
const e2 = coordId(coords2[coords2.length - 1]);
|
|
3557
|
+
let coords;
|
|
3558
|
+
if (s1 === e2) {
|
|
3559
|
+
coords = coords2.concat(coords1.slice(1));
|
|
3560
|
+
} else if (s2 === e1) {
|
|
3561
|
+
coords = coords1.concat(coords2.slice(1));
|
|
3562
|
+
} else if (s1 === s2) {
|
|
3563
|
+
coords = coords1.slice(1).reverse().concat(coords2);
|
|
3564
|
+
} else if (e1 === e2) {
|
|
3565
|
+
coords = coords1.concat(coords2.reverse().slice(1));
|
|
3566
|
+
} else {
|
|
3567
|
+
return null;
|
|
3568
|
+
}
|
|
3569
|
+
return lineString(coords);
|
|
3570
|
+
}
|
|
3571
|
+
function polygonDissolve(geojson, options = {}) {
|
|
3572
|
+
if (getType(geojson) !== "FeatureCollection") {
|
|
3573
|
+
throw new Error("geojson must be a FeatureCollection");
|
|
3574
|
+
}
|
|
3575
|
+
if (!geojson.features.length) {
|
|
3576
|
+
throw new Error("geojson is empty");
|
|
3577
|
+
}
|
|
3578
|
+
if (options.mutate === false || options.mutate === void 0) {
|
|
3579
|
+
geojson = clone(geojson);
|
|
3580
|
+
}
|
|
3581
|
+
const geoms = [];
|
|
3582
|
+
flattenEach(geojson, (feature2) => {
|
|
3583
|
+
geoms.push(feature2.geometry);
|
|
3584
|
+
});
|
|
3585
|
+
const topo = topology_default({ geoms: geometryCollection(geoms).geometry });
|
|
3586
|
+
const merged = merge_default(topo, topo.objects.geoms.geometries);
|
|
3587
|
+
return merged;
|
|
3588
|
+
}
|
|
3589
|
+
function dissolve(geojson, options = {}) {
|
|
3590
|
+
options = options || {};
|
|
3591
|
+
if (!isObject(options)) {
|
|
3592
|
+
throw new Error("options is invalid");
|
|
3593
|
+
}
|
|
3594
|
+
const mutate = options.mutate;
|
|
3595
|
+
if (getType(geojson) !== "FeatureCollection") {
|
|
3596
|
+
throw new Error("geojson must be a FeatureCollection");
|
|
3597
|
+
}
|
|
3598
|
+
if (!geojson.features.length) {
|
|
3599
|
+
throw new Error("geojson is empty");
|
|
3600
|
+
}
|
|
3601
|
+
if (mutate === false || mutate === void 0) {
|
|
3602
|
+
geojson = clone(geojson);
|
|
3603
|
+
}
|
|
3604
|
+
const type = getHomogenousType(geojson);
|
|
3605
|
+
if (!type) {
|
|
3606
|
+
throw new Error("geojson must be homogenous");
|
|
3607
|
+
}
|
|
3608
|
+
const data = geojson;
|
|
3609
|
+
switch (type) {
|
|
3610
|
+
case "LineString":
|
|
3611
|
+
return lineDissolve(data, options);
|
|
3612
|
+
case "Polygon":
|
|
3613
|
+
return polygonDissolve(data, options);
|
|
3614
|
+
default:
|
|
3615
|
+
throw new Error(type + " is not supported");
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3618
|
+
function getHomogenousType(geojson) {
|
|
3619
|
+
const types = {};
|
|
3620
|
+
flattenEach(geojson, (feature2) => {
|
|
3621
|
+
types[feature2.geometry.type] = true;
|
|
3622
|
+
});
|
|
3623
|
+
const keys = Object.keys(types);
|
|
3624
|
+
if (keys.length === 1) {
|
|
3625
|
+
return keys[0];
|
|
3626
|
+
}
|
|
3627
|
+
return null;
|
|
3628
|
+
}
|
|
3629
|
+
function concave(points, options = {}) {
|
|
3630
|
+
const maxEdge = options.maxEdge || Infinity;
|
|
3631
|
+
const cleaned = removeDuplicates(points);
|
|
3632
|
+
const tinPolys = tin(cleaned);
|
|
3633
|
+
tinPolys.features = tinPolys.features.filter((triangle) => {
|
|
3634
|
+
const pt1 = triangle.geometry.coordinates[0][0];
|
|
3635
|
+
const pt2 = triangle.geometry.coordinates[0][1];
|
|
3636
|
+
const pt3 = triangle.geometry.coordinates[0][2];
|
|
3637
|
+
const dist1 = distance(pt1, pt2, options);
|
|
3638
|
+
const dist2 = distance(pt2, pt3, options);
|
|
3639
|
+
const dist3 = distance(pt1, pt3, options);
|
|
3640
|
+
return dist1 <= maxEdge && dist2 <= maxEdge && dist3 <= maxEdge;
|
|
3641
|
+
});
|
|
3642
|
+
if (tinPolys.features.length < 1) {
|
|
3643
|
+
return null;
|
|
3644
|
+
}
|
|
3645
|
+
const dissolved = dissolve(tinPolys);
|
|
3646
|
+
if (dissolved.coordinates.length === 1) {
|
|
3647
|
+
dissolved.coordinates = dissolved.coordinates[0];
|
|
3648
|
+
dissolved.type = "Polygon";
|
|
3649
|
+
}
|
|
3650
|
+
return feature(dissolved);
|
|
3651
|
+
}
|
|
3652
|
+
function removeDuplicates(points) {
|
|
3653
|
+
const cleaned = [];
|
|
3654
|
+
const existing = {};
|
|
3655
|
+
featureEach(points, (pt) => {
|
|
3656
|
+
if (!pt.geometry) {
|
|
3657
|
+
return;
|
|
3658
|
+
}
|
|
3659
|
+
const key = pt.geometry.coordinates.join("-");
|
|
3660
|
+
if (!Object.prototype.hasOwnProperty.call(existing, key)) {
|
|
3661
|
+
cleaned.push(pt);
|
|
3662
|
+
existing[key] = true;
|
|
3663
|
+
}
|
|
3664
|
+
});
|
|
3665
|
+
return featureCollection(cleaned);
|
|
3666
|
+
}
|
|
3667
|
+
var index_default = concave;
|
|
3668
|
+
|
|
3669
|
+
// node_modules/.pnpm/wmap-renderer-canvas@1.0.1/node_modules/wmap-renderer-canvas/src/renderer.js
|
|
3670
|
+
var patternCache = /* @__PURE__ */ new WeakMap();
|
|
3671
|
+
var offscreenCanvasCache = null;
|
|
3672
|
+
var offscreenCanvasContext = null;
|
|
3673
|
+
var internals2 = {
|
|
3674
|
+
// Padding around the axes
|
|
3675
|
+
kAxisLabelPadding: 5,
|
|
3676
|
+
// The default axis labels
|
|
3677
|
+
kAxisLabels: {
|
|
3678
|
+
xAxis: {
|
|
3679
|
+
leading: "Uncharted",
|
|
3680
|
+
trailing: "Industrialised"
|
|
3681
|
+
},
|
|
3682
|
+
yAxis: {
|
|
3683
|
+
top: "Visible",
|
|
3684
|
+
bottom: "Invisible"
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3687
|
+
};
|
|
3688
|
+
async function drawBackground(ctx, stages, config) {
|
|
3689
|
+
const { mapWidth, mapHeight } = config.theme.sizes;
|
|
3690
|
+
const { stageForeground, stageBackground } = config.theme.colors;
|
|
3691
|
+
const width = mapWidth;
|
|
3692
|
+
const height = mapHeight;
|
|
3693
|
+
let cachedPatterns = patternCache.get(ctx);
|
|
3694
|
+
if (!cachedPatterns || cachedPatterns.fg !== stageForeground || cachedPatterns.bg !== stageBackground) {
|
|
3695
|
+
cachedPatterns = {
|
|
3696
|
+
fg: stageForeground,
|
|
3697
|
+
bg: stageBackground,
|
|
3698
|
+
stitch: await createPattern(
|
|
3699
|
+
ctx,
|
|
3700
|
+
patterns.stitch,
|
|
3701
|
+
1,
|
|
3702
|
+
stageForeground,
|
|
3703
|
+
stageBackground
|
|
3704
|
+
),
|
|
3705
|
+
shingles: await createPattern(
|
|
3706
|
+
ctx,
|
|
3707
|
+
patterns.shingles,
|
|
3708
|
+
1,
|
|
3709
|
+
stageForeground,
|
|
3710
|
+
stageBackground
|
|
3711
|
+
),
|
|
3712
|
+
shadowGrid: await createPattern(
|
|
3713
|
+
ctx,
|
|
3714
|
+
patterns.shadowGrid,
|
|
3715
|
+
1,
|
|
3716
|
+
stageForeground,
|
|
3717
|
+
stageBackground
|
|
3718
|
+
),
|
|
3719
|
+
wicker: await createPattern(
|
|
3720
|
+
ctx,
|
|
3721
|
+
patterns.wicker,
|
|
3722
|
+
1,
|
|
3723
|
+
stageForeground,
|
|
3724
|
+
stageBackground
|
|
3725
|
+
)
|
|
3726
|
+
};
|
|
3727
|
+
patternCache.set(ctx, cachedPatterns);
|
|
3728
|
+
}
|
|
3729
|
+
const w = (dim) => percentToPixel(dim, width);
|
|
3730
|
+
ctx.fillStyle = cachedPatterns.stitch;
|
|
3731
|
+
ctx.fillRect(0, 0, w(stages[0]), height);
|
|
3732
|
+
ctx.fillStyle = cachedPatterns.shingles;
|
|
3733
|
+
ctx.fillRect(w(stages[0]), 0, w(stages[1]) - w(stages[0]), height);
|
|
3734
|
+
ctx.fillStyle = cachedPatterns.shadowGrid;
|
|
3735
|
+
ctx.fillRect(w(stages[1]), 0, w(stages[2]) - w(stages[1]), height);
|
|
3736
|
+
ctx.fillStyle = cachedPatterns.wicker;
|
|
3737
|
+
ctx.fillRect(w(stages[2]), 0, width - w(stages[2]), height);
|
|
3738
|
+
}
|
|
3739
|
+
function drawAxes(ctx, stages, stageType, config) {
|
|
3740
|
+
const { mapWidth, mapHeight, lineWidth } = config.theme.sizes;
|
|
3741
|
+
const { axis, label } = config.theme.colors;
|
|
3742
|
+
const { family: fontFamily, axisLabel } = config.theme.fonts;
|
|
3743
|
+
const width = mapWidth;
|
|
3744
|
+
const height = mapHeight;
|
|
3745
|
+
const xLabels = internals2.kAxisLabels.xAxis;
|
|
3746
|
+
const yLabels = internals2.kAxisLabels.yAxis;
|
|
3747
|
+
const w = (dim) => percentToPixel(dim, width);
|
|
3748
|
+
ctx.strokeStyle = axis;
|
|
3749
|
+
ctx.lineWidth = lineWidth * 2;
|
|
3750
|
+
ctx.beginPath();
|
|
3751
|
+
ctx.moveTo(0, 0);
|
|
3752
|
+
ctx.lineTo(0, height);
|
|
3753
|
+
ctx.lineTo(width, height);
|
|
3754
|
+
ctx.stroke();
|
|
3755
|
+
ctx.fillStyle = label;
|
|
3756
|
+
ctx.font = `${axisLabel}px ${fontFamily}`;
|
|
3757
|
+
ctx.textBaseline = "top";
|
|
3758
|
+
ctx.save();
|
|
3759
|
+
ctx.translate(-20, 45);
|
|
3760
|
+
ctx.rotate(-Math.PI / 2);
|
|
3761
|
+
ctx.fillText(yLabels.top, 0, 0);
|
|
3762
|
+
ctx.restore();
|
|
3763
|
+
ctx.save();
|
|
3764
|
+
ctx.translate(-20, height);
|
|
3765
|
+
ctx.rotate(-Math.PI / 2);
|
|
3766
|
+
ctx.fillText(yLabels.bottom, 0, 0);
|
|
3767
|
+
ctx.restore();
|
|
3768
|
+
const stageHeight = config.theme.sizes.stageHeight;
|
|
3769
|
+
ctx.textAlign = "left";
|
|
3770
|
+
ctx.fillText(xLabels.leading, 0, -stageHeight / 4);
|
|
3771
|
+
ctx.textAlign = "right";
|
|
3772
|
+
ctx.fillText(xLabels.trailing, width, -stageHeight / 4);
|
|
3773
|
+
ctx.textAlign = "left";
|
|
3774
|
+
ctx.fillText(stageType.stages[0], 0, height + internals2.kAxisLabelPadding);
|
|
3775
|
+
ctx.fillText(
|
|
3776
|
+
stageType.stages[1],
|
|
3777
|
+
w(stages[0]),
|
|
3778
|
+
height + internals2.kAxisLabelPadding
|
|
3779
|
+
);
|
|
3780
|
+
ctx.fillText(
|
|
3781
|
+
stageType.stages[2],
|
|
3782
|
+
w(stages[1]),
|
|
3783
|
+
height + internals2.kAxisLabelPadding
|
|
3784
|
+
);
|
|
3785
|
+
ctx.fillText(
|
|
3786
|
+
stageType.stages[3],
|
|
3787
|
+
w(stages[2]),
|
|
3788
|
+
height + internals2.kAxisLabelPadding
|
|
3789
|
+
);
|
|
3790
|
+
}
|
|
3791
|
+
function drawStages(ctx, stages, config) {
|
|
3792
|
+
const { mapWidth, mapHeight, lineWidth } = config.theme.sizes;
|
|
3793
|
+
const { axis } = config.theme.colors;
|
|
3794
|
+
const width = mapWidth;
|
|
3795
|
+
const height = mapHeight;
|
|
3796
|
+
const w = (dim) => percentToPixel(dim, width);
|
|
3797
|
+
ctx.strokeStyle = axis;
|
|
3798
|
+
ctx.lineWidth = lineWidth * 2;
|
|
3799
|
+
ctx.setLineDash([10, 18]);
|
|
3800
|
+
ctx.globalAlpha = 1;
|
|
3801
|
+
ctx.beginPath();
|
|
3802
|
+
ctx.moveTo(w(stages[0]), 0);
|
|
3803
|
+
ctx.lineTo(w(stages[0]), height);
|
|
3804
|
+
ctx.moveTo(w(stages[1]), 0);
|
|
3805
|
+
ctx.lineTo(w(stages[1]), height);
|
|
3806
|
+
ctx.moveTo(w(stages[2]), 0);
|
|
3807
|
+
ctx.lineTo(w(stages[2]), height);
|
|
3808
|
+
ctx.stroke();
|
|
3809
|
+
ctx.setLineDash([]);
|
|
3810
|
+
}
|
|
3811
|
+
function drawVertexShape(ctx, x, y, shape, config) {
|
|
3812
|
+
const { vertexWidth, vertexHeight } = config.theme.sizes;
|
|
3813
|
+
const { vertex } = config.theme.colors;
|
|
3814
|
+
const width = vertexWidth;
|
|
3815
|
+
const height = vertexHeight;
|
|
3816
|
+
ctx.fillStyle = vertex;
|
|
3817
|
+
switch (shape) {
|
|
3818
|
+
case "circle":
|
|
3819
|
+
ctx.beginPath();
|
|
3820
|
+
ctx.ellipse(
|
|
3821
|
+
x + width / 2,
|
|
3822
|
+
y + height / 2,
|
|
3823
|
+
width / 2,
|
|
3824
|
+
height / 2,
|
|
3825
|
+
0,
|
|
3826
|
+
0,
|
|
3827
|
+
Math.PI * 2
|
|
3828
|
+
);
|
|
3829
|
+
ctx.fill();
|
|
3830
|
+
break;
|
|
3831
|
+
case "square":
|
|
3832
|
+
ctx.fillRect(x, y, width, height);
|
|
3833
|
+
break;
|
|
3834
|
+
case "triangle":
|
|
3835
|
+
ctx.beginPath();
|
|
3836
|
+
ctx.moveTo(x, y + height);
|
|
3837
|
+
ctx.lineTo(x + width, y + height);
|
|
3838
|
+
ctx.lineTo(x + width / 2, y);
|
|
3839
|
+
ctx.closePath();
|
|
3840
|
+
ctx.fill();
|
|
3841
|
+
break;
|
|
3842
|
+
case "x":
|
|
3843
|
+
ctx.strokeStyle = vertex;
|
|
3844
|
+
ctx.lineWidth = 2;
|
|
3845
|
+
ctx.beginPath();
|
|
3846
|
+
ctx.moveTo(x, y);
|
|
3847
|
+
ctx.lineTo(x + width, y + height);
|
|
3848
|
+
ctx.moveTo(x + width, y);
|
|
3849
|
+
ctx.lineTo(x, y + height);
|
|
3850
|
+
ctx.stroke();
|
|
3851
|
+
break;
|
|
3852
|
+
default:
|
|
3853
|
+
ctx.beginPath();
|
|
3854
|
+
ctx.ellipse(
|
|
3855
|
+
x + width / 2,
|
|
3856
|
+
y + height / 2,
|
|
3857
|
+
width / 2,
|
|
3858
|
+
height / 2,
|
|
3859
|
+
0,
|
|
3860
|
+
0,
|
|
3861
|
+
Math.PI * 2
|
|
3862
|
+
);
|
|
3863
|
+
ctx.fill();
|
|
3864
|
+
}
|
|
3865
|
+
}
|
|
3866
|
+
function drawVertices(ctx, components, map, componentMap, configuration) {
|
|
3867
|
+
const {
|
|
3868
|
+
options: { smartLabelPositioning },
|
|
3869
|
+
theme: {
|
|
3870
|
+
sizes: { mapWidth, mapHeight, vertexWidth },
|
|
3871
|
+
colors: { label },
|
|
3872
|
+
fonts: { family: fontFamily, vertexLabel: fontSize }
|
|
3873
|
+
}
|
|
3874
|
+
} = configuration;
|
|
3875
|
+
const width = mapWidth;
|
|
3876
|
+
const height = mapHeight;
|
|
3877
|
+
const w = (dim) => percentToPixel(dim, width);
|
|
3878
|
+
const h = (dim) => percentToPixel(dim, height);
|
|
3879
|
+
ctx.font = `${fontSize}px ${fontFamily}`;
|
|
3880
|
+
ctx.fillStyle = label;
|
|
3881
|
+
ctx.textBaseline = "middle";
|
|
3882
|
+
ctx.textAlign = "left";
|
|
3883
|
+
let allLines, noteRects, inertiaRects;
|
|
3884
|
+
if (smartLabelPositioning) {
|
|
3885
|
+
allLines = collectAllLines(map, configuration, componentMap);
|
|
3886
|
+
noteRects = collectNoteRects(map, configuration, ctx);
|
|
3887
|
+
inertiaRects = collectInertiaRects(map, configuration, componentMap);
|
|
3888
|
+
}
|
|
3889
|
+
for (const component of components) {
|
|
3890
|
+
const [xPercent, yPercent] = component.coordinates;
|
|
3891
|
+
const x = w(xPercent);
|
|
3892
|
+
const y = h(yPercent);
|
|
3893
|
+
drawVertexShape(ctx, x, y, component.shape, configuration);
|
|
3894
|
+
let labelX, labelY;
|
|
3895
|
+
if (smartLabelPositioning) {
|
|
3896
|
+
const position = calculateOptimalLabelPosition(
|
|
3897
|
+
component,
|
|
3898
|
+
map,
|
|
3899
|
+
configuration,
|
|
3900
|
+
ctx,
|
|
3901
|
+
allLines,
|
|
3902
|
+
noteRects,
|
|
3903
|
+
inertiaRects
|
|
3904
|
+
);
|
|
3905
|
+
labelX = position.x;
|
|
3906
|
+
labelY = position.y;
|
|
3907
|
+
ctx.textBaseline = "top";
|
|
3908
|
+
} else {
|
|
3909
|
+
labelX = x + vertexWidth + internals2.kAxisLabelPadding;
|
|
3910
|
+
labelY = y + 7;
|
|
3911
|
+
ctx.textBaseline = "middle";
|
|
3912
|
+
}
|
|
3913
|
+
ctx.fillText(component.label, labelX, labelY);
|
|
3914
|
+
}
|
|
3915
|
+
}
|
|
3916
|
+
function drawDependencies(ctx, dependencies, componentMap, configuration) {
|
|
3917
|
+
const {
|
|
3918
|
+
theme: {
|
|
3919
|
+
sizes: { vertexWidth, vertexHeight, lineWidth, arrowheadSize },
|
|
3920
|
+
colors: { vertex }
|
|
3921
|
+
}
|
|
3922
|
+
} = configuration;
|
|
3923
|
+
ctx.strokeStyle = vertex;
|
|
3924
|
+
ctx.lineWidth = lineWidth;
|
|
3925
|
+
const halfWidth = vertexWidth / 2;
|
|
3926
|
+
const halfHeight = vertexHeight / 2;
|
|
3927
|
+
const arrowAngle = Math.PI / 4;
|
|
3928
|
+
for (const dependency of dependencies) {
|
|
3929
|
+
const fromCoordinates = componentMap[dependency.from.toLowerCase()];
|
|
3930
|
+
const toCoordinates = componentMap[dependency.to.toLowerCase()];
|
|
3931
|
+
if (!fromCoordinates || !toCoordinates) continue;
|
|
3932
|
+
const originX = fromCoordinates[0] + halfWidth;
|
|
3933
|
+
const originY = fromCoordinates[1] + halfHeight;
|
|
3934
|
+
const destX = toCoordinates[0] + halfWidth;
|
|
3935
|
+
const destY = toCoordinates[1] + halfHeight;
|
|
3936
|
+
const angle = Math.atan2(destY - originY, destX - originX);
|
|
3937
|
+
const cosine = Math.cos(angle);
|
|
3938
|
+
const sine = Math.sin(angle);
|
|
3939
|
+
const offsetOriginX = originX + halfWidth * cosine;
|
|
3940
|
+
const offsetOriginY = originY + halfHeight * sine;
|
|
3941
|
+
const offsetDestX = destX - halfWidth * cosine;
|
|
3942
|
+
const offsetDestY = destY - halfHeight * sine;
|
|
3943
|
+
ctx.beginPath();
|
|
3944
|
+
ctx.moveTo(offsetOriginX, offsetOriginY);
|
|
3945
|
+
ctx.lineTo(offsetDestX, offsetDestY);
|
|
3946
|
+
ctx.stroke();
|
|
3947
|
+
if (dependency.isDirected) {
|
|
3948
|
+
const upperAngle = angle - arrowAngle;
|
|
3949
|
+
const lowerAngle = angle + arrowAngle;
|
|
3950
|
+
ctx.beginPath();
|
|
3951
|
+
ctx.moveTo(
|
|
3952
|
+
offsetDestX - arrowheadSize * Math.cos(upperAngle),
|
|
3953
|
+
offsetDestY - arrowheadSize * Math.sin(upperAngle)
|
|
3954
|
+
);
|
|
3955
|
+
ctx.lineTo(offsetDestX, offsetDestY);
|
|
3956
|
+
ctx.lineTo(
|
|
3957
|
+
offsetDestX - arrowheadSize * Math.cos(lowerAngle),
|
|
3958
|
+
offsetDestY - arrowheadSize * Math.sin(lowerAngle)
|
|
3959
|
+
);
|
|
3960
|
+
ctx.stroke();
|
|
3961
|
+
}
|
|
3962
|
+
}
|
|
3963
|
+
}
|
|
3964
|
+
function drawNotes(ctx, notes, configuration) {
|
|
3965
|
+
const {
|
|
3966
|
+
theme: {
|
|
3967
|
+
sizes: { mapWidth, mapHeight, lineWidth },
|
|
3968
|
+
colors: { background, vertex, label },
|
|
3969
|
+
fonts: { family: fontFamily, note: fontSize },
|
|
3970
|
+
lineHeights: { note: lineHeight }
|
|
3971
|
+
}
|
|
3972
|
+
} = configuration;
|
|
3973
|
+
const w = (dim) => percentToPixel(dim, mapWidth);
|
|
3974
|
+
const h = (dim) => percentToPixel(dim, mapHeight);
|
|
3975
|
+
const maxWidth = 400;
|
|
3976
|
+
const padding = internals2.kAxisLabelPadding;
|
|
3977
|
+
ctx.font = `${fontSize}px ${fontFamily}`;
|
|
3978
|
+
ctx.textBaseline = "top";
|
|
3979
|
+
ctx.textAlign = "left";
|
|
3980
|
+
ctx.lineWidth = lineWidth;
|
|
3981
|
+
ctx.fillStyle = background;
|
|
3982
|
+
const noteData = [];
|
|
3983
|
+
for (const note of notes) {
|
|
3984
|
+
const x = w(note.coordinates[0]);
|
|
3985
|
+
const y = h(note.coordinates[1]);
|
|
3986
|
+
const lines = note.text.replace(/\\n/g, "\n").split("\n");
|
|
3987
|
+
let widestLine = 0;
|
|
3988
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3989
|
+
const lineWidth2 = ctx.measureText(lines[i]).width;
|
|
3990
|
+
if (lineWidth2 > widestLine) widestLine = lineWidth2;
|
|
3991
|
+
}
|
|
3992
|
+
const boxWidth = Math.min(maxWidth, widestLine + padding * 2);
|
|
3993
|
+
const boxHeight = lines.length * lineHeight + padding * 2;
|
|
3994
|
+
ctx.fillRect(x, y, boxWidth, boxHeight);
|
|
3995
|
+
noteData.push({ x, y, boxWidth, boxHeight, lines });
|
|
3996
|
+
}
|
|
3997
|
+
ctx.strokeStyle = vertex;
|
|
3998
|
+
for (const { x, y, boxWidth, boxHeight } of noteData) {
|
|
3999
|
+
ctx.strokeRect(x, y, boxWidth, boxHeight);
|
|
4000
|
+
}
|
|
4001
|
+
ctx.fillStyle = label;
|
|
4002
|
+
for (const { x, y, lines } of noteData) {
|
|
4003
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4004
|
+
ctx.fillText(lines[i], x + padding, y + padding + i * lineHeight);
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
}
|
|
4008
|
+
function drawInertias(ctx, inertias, componentMap, configuration) {
|
|
4009
|
+
const {
|
|
4010
|
+
theme: {
|
|
4011
|
+
sizes: { vertexWidth, vertexHeight },
|
|
4012
|
+
colors: { inertia }
|
|
4013
|
+
}
|
|
4014
|
+
} = configuration;
|
|
4015
|
+
const cornerRadius = 2;
|
|
4016
|
+
ctx.fillStyle = inertia;
|
|
4017
|
+
for (const inertia2 of inertias) {
|
|
4018
|
+
if (!inertia2.component) return;
|
|
4019
|
+
const coordinates = componentMap[inertia2.component.toLowerCase()];
|
|
4020
|
+
if (!coordinates) return;
|
|
4021
|
+
const x = coordinates[0] + 3 * vertexWidth;
|
|
4022
|
+
const y = coordinates[1] - vertexHeight * 2 / 3;
|
|
4023
|
+
const rectWidth = vertexWidth / 2;
|
|
4024
|
+
const rectHeight = vertexHeight * 2;
|
|
4025
|
+
ctx.beginPath();
|
|
4026
|
+
ctx.roundRect(x, y, rectWidth, rectHeight, cornerRadius);
|
|
4027
|
+
ctx.fill();
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
function drawEvolutions(ctx, evolutions, componentMap, configuration) {
|
|
4031
|
+
const {
|
|
4032
|
+
theme: {
|
|
4033
|
+
sizes: {
|
|
4034
|
+
mapWidth,
|
|
4035
|
+
vertexWidth,
|
|
4036
|
+
vertexHeight,
|
|
4037
|
+
lineWidth,
|
|
4038
|
+
arrowheadSize
|
|
4039
|
+
},
|
|
4040
|
+
colors: { evolution }
|
|
4041
|
+
}
|
|
4042
|
+
} = configuration;
|
|
4043
|
+
ctx.strokeStyle = evolution;
|
|
4044
|
+
ctx.lineWidth = lineWidth * 2;
|
|
4045
|
+
ctx.setLineDash([10]);
|
|
4046
|
+
ctx.globalAlpha = 1;
|
|
4047
|
+
evolutions.forEach((evolutionItem) => {
|
|
4048
|
+
const coords = componentMap[evolutionItem.component.toLowerCase()];
|
|
4049
|
+
if (!coords) return;
|
|
4050
|
+
const originX = coords[0];
|
|
4051
|
+
const originY = coords[1];
|
|
4052
|
+
const destX = Math.max(
|
|
4053
|
+
0,
|
|
4054
|
+
Math.min(
|
|
4055
|
+
mapWidth,
|
|
4056
|
+
originX + percentToPixel(evolutionItem.value, mapWidth)
|
|
4057
|
+
)
|
|
4058
|
+
);
|
|
4059
|
+
const destY = originY;
|
|
4060
|
+
const multiplier = destX > originX ? 1 : -1;
|
|
4061
|
+
const upperAngle = -Math.PI / 4;
|
|
4062
|
+
const lowerAngle = Math.PI / 4;
|
|
4063
|
+
const offsetOriginX = originX + multiplier * (vertexWidth / 2) + vertexWidth / 2;
|
|
4064
|
+
const offsetOriginY = originY + vertexHeight / 2;
|
|
4065
|
+
const offsetDestX = destX - multiplier * (vertexWidth / 2) + vertexWidth / 2;
|
|
4066
|
+
const offsetDestY = destY + vertexHeight / 2;
|
|
4067
|
+
ctx.beginPath();
|
|
4068
|
+
ctx.moveTo(offsetOriginX, offsetOriginY);
|
|
4069
|
+
ctx.lineTo(offsetDestX, offsetDestY);
|
|
4070
|
+
ctx.stroke();
|
|
4071
|
+
ctx.beginPath();
|
|
4072
|
+
ctx.moveTo(offsetDestX, offsetDestY);
|
|
4073
|
+
ctx.lineTo(
|
|
4074
|
+
offsetDestX - multiplier * arrowheadSize * Math.cos(upperAngle),
|
|
4075
|
+
offsetDestY - multiplier * arrowheadSize * Math.sin(upperAngle)
|
|
4076
|
+
);
|
|
4077
|
+
ctx.stroke();
|
|
4078
|
+
ctx.beginPath();
|
|
4079
|
+
ctx.moveTo(offsetDestX, offsetDestY);
|
|
4080
|
+
ctx.lineTo(
|
|
4081
|
+
offsetDestX - multiplier * arrowheadSize * Math.cos(lowerAngle),
|
|
4082
|
+
offsetDestY - multiplier * arrowheadSize * Math.sin(lowerAngle)
|
|
4083
|
+
);
|
|
4084
|
+
ctx.stroke();
|
|
4085
|
+
});
|
|
4086
|
+
ctx.setLineDash([]);
|
|
4087
|
+
ctx.globalAlpha = 1;
|
|
4088
|
+
}
|
|
4089
|
+
async function drawGroups(ctx, groups, componentMap, configuration) {
|
|
4090
|
+
const {
|
|
4091
|
+
theme: {
|
|
4092
|
+
colors: { groups: groupColors },
|
|
4093
|
+
sizes: { mapWidth, mapHeight, vertexWidth, vertexHeight },
|
|
4094
|
+
opacity: { groups: groupOpacity }
|
|
4095
|
+
}
|
|
4096
|
+
} = configuration;
|
|
4097
|
+
const width = mapWidth;
|
|
4098
|
+
const height = mapHeight;
|
|
4099
|
+
const isNode = typeof window === "undefined";
|
|
4100
|
+
if (!offscreenCanvasCache || offscreenCanvasCache.width !== width + vertexWidth || offscreenCanvasCache.height !== height + vertexHeight) {
|
|
4101
|
+
if (isNode) {
|
|
4102
|
+
const { createCanvas } = await Promise.resolve().then(() => __toESM(require_browser(), 1));
|
|
4103
|
+
offscreenCanvasCache = createCanvas(
|
|
4104
|
+
width + vertexWidth,
|
|
4105
|
+
height + vertexHeight
|
|
4106
|
+
);
|
|
4107
|
+
} else {
|
|
4108
|
+
offscreenCanvasCache = document.createElement("canvas");
|
|
4109
|
+
offscreenCanvasCache.width = width + vertexWidth;
|
|
4110
|
+
offscreenCanvasCache.height = height + vertexHeight;
|
|
4111
|
+
}
|
|
4112
|
+
offscreenCanvasContext = offscreenCanvasCache.getContext("2d");
|
|
4113
|
+
}
|
|
4114
|
+
groups.forEach((group, groupIndex) => {
|
|
4115
|
+
const componentCoords = group.components.map((label) => componentMap[label.toLowerCase()]).filter(Boolean);
|
|
4116
|
+
if (componentCoords.length === 0) return;
|
|
4117
|
+
const color = groupColors[groupIndex % groupColors.length];
|
|
4118
|
+
let coords;
|
|
4119
|
+
if (componentCoords.length === 1) {
|
|
4120
|
+
const [x, y] = componentCoords[0];
|
|
4121
|
+
const radius = 3;
|
|
4122
|
+
const segments = 16;
|
|
4123
|
+
coords = [];
|
|
4124
|
+
for (let i = 0; i <= segments; i++) {
|
|
4125
|
+
const angle = i / segments * 2 * Math.PI;
|
|
4126
|
+
coords.push([
|
|
4127
|
+
x + radius * Math.cos(angle),
|
|
4128
|
+
y + radius * Math.sin(angle)
|
|
4129
|
+
]);
|
|
4130
|
+
}
|
|
4131
|
+
} else if (componentCoords.length === 2) {
|
|
4132
|
+
coords = [componentCoords[0], componentCoords[1]];
|
|
4133
|
+
} else {
|
|
4134
|
+
const points = componentCoords.map(([x, y]) => point([x, y]));
|
|
4135
|
+
const fc = featureCollection(points);
|
|
4136
|
+
const hull = index_default(fc);
|
|
4137
|
+
if (!hull) return;
|
|
4138
|
+
coords = hull.geometry.coordinates[0];
|
|
4139
|
+
}
|
|
4140
|
+
offscreenCanvasContext.clearRect(
|
|
4141
|
+
0,
|
|
4142
|
+
0,
|
|
4143
|
+
offscreenCanvasCache.width,
|
|
4144
|
+
offscreenCanvasCache.height
|
|
4145
|
+
);
|
|
4146
|
+
offscreenCanvasContext.setTransform(1, 0, 0, 1, 0, 0);
|
|
4147
|
+
offscreenCanvasContext.translate(vertexWidth / 2, vertexHeight / 2);
|
|
4148
|
+
offscreenCanvasContext.beginPath();
|
|
4149
|
+
coords.forEach(([x, y], i) => {
|
|
4150
|
+
const px = x;
|
|
4151
|
+
const py = y;
|
|
4152
|
+
if (i === 0) {
|
|
4153
|
+
offscreenCanvasContext.moveTo(px, py);
|
|
4154
|
+
} else {
|
|
4155
|
+
offscreenCanvasContext.lineTo(px, py);
|
|
4156
|
+
}
|
|
4157
|
+
});
|
|
4158
|
+
const isLine = componentCoords.length === 2;
|
|
4159
|
+
if (!isLine) {
|
|
4160
|
+
offscreenCanvasContext.closePath();
|
|
4161
|
+
offscreenCanvasContext.fillStyle = color;
|
|
4162
|
+
offscreenCanvasContext.fill();
|
|
4163
|
+
}
|
|
4164
|
+
offscreenCanvasContext.strokeStyle = color;
|
|
4165
|
+
offscreenCanvasContext.lineWidth = 1.75 * vertexWidth;
|
|
4166
|
+
offscreenCanvasContext.lineCap = "round";
|
|
4167
|
+
offscreenCanvasContext.lineJoin = "round";
|
|
4168
|
+
offscreenCanvasContext.stroke();
|
|
4169
|
+
ctx.save();
|
|
4170
|
+
ctx.globalAlpha = groupOpacity;
|
|
4171
|
+
ctx.drawImage(offscreenCanvasCache, 0, 0);
|
|
4172
|
+
ctx.restore();
|
|
4173
|
+
});
|
|
4174
|
+
}
|
|
4175
|
+
async function render(map, ctx, stageType, configuration) {
|
|
4176
|
+
const {
|
|
4177
|
+
options: { showBackground },
|
|
4178
|
+
theme: {
|
|
4179
|
+
colors: { background },
|
|
4180
|
+
sizes: { mapWidth, mapHeight, padding }
|
|
4181
|
+
}
|
|
4182
|
+
} = configuration;
|
|
4183
|
+
const stages = getStageValues(map.stages);
|
|
4184
|
+
const componentMap = createComponentMap(
|
|
4185
|
+
map.components,
|
|
4186
|
+
mapWidth,
|
|
4187
|
+
mapHeight
|
|
4188
|
+
);
|
|
4189
|
+
ctx.fillStyle = background;
|
|
4190
|
+
const totalWidth = mapWidth + padding * 2;
|
|
4191
|
+
const totalHeight = mapHeight + padding * 2;
|
|
4192
|
+
ctx.fillRect(0, 0, totalWidth, totalHeight);
|
|
4193
|
+
ctx.save();
|
|
4194
|
+
ctx.translate(padding, padding);
|
|
4195
|
+
ctx.fillStyle = background;
|
|
4196
|
+
ctx.fillRect(0, 0, mapWidth, mapHeight);
|
|
4197
|
+
if (showBackground) {
|
|
4198
|
+
await drawBackground(ctx, stages, configuration);
|
|
4199
|
+
}
|
|
4200
|
+
drawAxes(ctx, stages, stageType, configuration);
|
|
4201
|
+
drawStages(ctx, stages, configuration);
|
|
4202
|
+
drawDependencies(ctx, map.dependencies, componentMap, configuration);
|
|
4203
|
+
await drawGroups(ctx, map.groups, componentMap, configuration);
|
|
4204
|
+
drawVertices(ctx, map.components, map, componentMap, configuration);
|
|
4205
|
+
drawInertias(ctx, map.inertias, componentMap, configuration);
|
|
4206
|
+
drawEvolutions(ctx, map.evolutions, componentMap, configuration);
|
|
4207
|
+
drawNotes(ctx, map.notes, configuration);
|
|
4208
|
+
ctx.restore();
|
|
4209
|
+
}
|
|
4210
|
+
|
|
4211
|
+
// node_modules/.pnpm/wmap-renderer-canvas@1.0.1/node_modules/wmap-renderer-canvas/src/configuration.js
|
|
4212
|
+
var internals3 = {
|
|
4213
|
+
kDefaults: {
|
|
4214
|
+
options: {
|
|
4215
|
+
showBackground: true,
|
|
4216
|
+
smartLabelPositioning: true
|
|
4217
|
+
},
|
|
4218
|
+
theme: {
|
|
4219
|
+
colors: {
|
|
4220
|
+
background: "#FFFFFF",
|
|
4221
|
+
axis: "#0F261F",
|
|
4222
|
+
vertex: "#0F261F",
|
|
4223
|
+
label: "#0F261F",
|
|
4224
|
+
stageForeground: "#DAE6E3",
|
|
4225
|
+
stageBackground: "#FFFFFF",
|
|
4226
|
+
inertia: "#FA2B00",
|
|
4227
|
+
evolution: "#4F8FE6",
|
|
4228
|
+
groups: [
|
|
4229
|
+
"#4F8FE6",
|
|
4230
|
+
// Olympic Blue
|
|
4231
|
+
"#FA2B00",
|
|
4232
|
+
// Jasper Red
|
|
4233
|
+
"#23C17C",
|
|
4234
|
+
// Light Porcelain Green
|
|
4235
|
+
"#FAED8F",
|
|
4236
|
+
// Naples Yellow
|
|
4237
|
+
"#FFB3F0"
|
|
4238
|
+
// Hermosa Pink
|
|
4239
|
+
]
|
|
4240
|
+
},
|
|
4241
|
+
sizes: {
|
|
4242
|
+
mapWidth: 1300,
|
|
4243
|
+
mapHeight: 1e3,
|
|
4244
|
+
padding: 42,
|
|
4245
|
+
lineWidth: 0.5,
|
|
4246
|
+
vertexWidth: 25,
|
|
4247
|
+
vertexHeight: 25,
|
|
4248
|
+
arrowheadSize: 10,
|
|
4249
|
+
stageHeight: 100
|
|
4250
|
+
},
|
|
4251
|
+
fonts: {
|
|
4252
|
+
family: '"Helvetica Neue", Helvetica, Arial, sans-serif',
|
|
4253
|
+
axisLabel: 14,
|
|
4254
|
+
vertexLabel: 12,
|
|
4255
|
+
note: 12
|
|
4256
|
+
},
|
|
4257
|
+
lineHeights: {
|
|
4258
|
+
vertexLabel: 18,
|
|
4259
|
+
note: 18
|
|
4260
|
+
},
|
|
4261
|
+
opacity: {
|
|
4262
|
+
groups: 0.1
|
|
4263
|
+
}
|
|
4264
|
+
}
|
|
4265
|
+
}
|
|
4266
|
+
};
|
|
4267
|
+
function extendConfiguration(overrides = {}) {
|
|
4268
|
+
const configuration = {
|
|
4269
|
+
options: Object.assign(
|
|
4270
|
+
{},
|
|
4271
|
+
internals3.kDefaults.options,
|
|
4272
|
+
overrides.options
|
|
4273
|
+
),
|
|
4274
|
+
theme: {
|
|
4275
|
+
colors: Object.assign(
|
|
4276
|
+
{},
|
|
4277
|
+
internals3.kDefaults.theme.colors,
|
|
4278
|
+
overrides.theme?.colors
|
|
4279
|
+
),
|
|
4280
|
+
sizes: Object.assign(
|
|
4281
|
+
{},
|
|
4282
|
+
internals3.kDefaults.theme.sizes,
|
|
4283
|
+
overrides.theme?.sizes
|
|
4284
|
+
),
|
|
4285
|
+
fonts: Object.assign(
|
|
4286
|
+
{},
|
|
4287
|
+
internals3.kDefaults.theme.fonts,
|
|
4288
|
+
overrides.theme?.fonts
|
|
4289
|
+
),
|
|
4290
|
+
lineHeights: Object.assign(
|
|
4291
|
+
{},
|
|
4292
|
+
internals3.kDefaults.theme.lineHeights,
|
|
4293
|
+
overrides.theme?.lineHeights
|
|
4294
|
+
),
|
|
4295
|
+
opacity: Object.assign(
|
|
4296
|
+
{},
|
|
4297
|
+
internals3.kDefaults.theme.opacity,
|
|
4298
|
+
overrides.theme?.opacity
|
|
4299
|
+
)
|
|
4300
|
+
}
|
|
4301
|
+
};
|
|
4302
|
+
return configuration;
|
|
4303
|
+
}
|
|
4304
|
+
|
|
4305
|
+
// node_modules/.pnpm/wmap-renderer-canvas@1.0.1/node_modules/wmap-renderer-canvas/src/stage_type.js
|
|
4306
|
+
var StageType = {
|
|
4307
|
+
BEHAVIOR: {
|
|
4308
|
+
name: "Behavior",
|
|
4309
|
+
stages: [
|
|
4310
|
+
"Uncertain when to use",
|
|
4311
|
+
"Learning when to use",
|
|
4312
|
+
"Learning through use",
|
|
4313
|
+
"Known / common usage"
|
|
4314
|
+
]
|
|
4315
|
+
},
|
|
4316
|
+
CERTAINTY: {
|
|
4317
|
+
name: "Certainty",
|
|
4318
|
+
stages: [
|
|
4319
|
+
"Poorly Understood / exploring the unknown",
|
|
4320
|
+
"Rapid Increase In Learning / discovery becomes refining",
|
|
4321
|
+
"Rapid increase in use / increasing fit for purpose",
|
|
4322
|
+
"Commonly understood (in terms of use)"
|
|
4323
|
+
]
|
|
4324
|
+
},
|
|
4325
|
+
COMPARISON: {
|
|
4326
|
+
name: "Comparison",
|
|
4327
|
+
stages: [
|
|
4328
|
+
"Constantly changing / a differential / unstable",
|
|
4329
|
+
"Learning from others / testing the water / some evidential support",
|
|
4330
|
+
"Competing models / feature difference / evidential support",
|
|
4331
|
+
"Essential / any advantage is operational / accepted norm"
|
|
4332
|
+
]
|
|
4333
|
+
},
|
|
4334
|
+
CYNEFIN: {
|
|
4335
|
+
name: "Cynefin",
|
|
4336
|
+
stages: ["Chaotic", "Complex", "Complicated", "Clear"]
|
|
4337
|
+
},
|
|
4338
|
+
DATA: {
|
|
4339
|
+
name: "Data",
|
|
4340
|
+
stages: ["Unmodelled", "Divergent", "Convergent", "Modelled"]
|
|
4341
|
+
},
|
|
4342
|
+
DECISION_DRIVERS: {
|
|
4343
|
+
name: "Decision Drivers",
|
|
4344
|
+
stages: [
|
|
4345
|
+
"Heritage / culture",
|
|
4346
|
+
"Analyses & synthesis",
|
|
4347
|
+
"Analyses & synthesis",
|
|
4348
|
+
"Previous Experience"
|
|
4349
|
+
]
|
|
4350
|
+
},
|
|
4351
|
+
EFFICIENCY: {
|
|
4352
|
+
name: "Efficiency",
|
|
4353
|
+
stages: [
|
|
4354
|
+
"Reducing the cost of change (experimentation)",
|
|
4355
|
+
"Reducing cost of waste (Learning)",
|
|
4356
|
+
"Reducing cost of waste (Learning)",
|
|
4357
|
+
"Reducing cost of deviation (Volume)"
|
|
4358
|
+
]
|
|
4359
|
+
},
|
|
4360
|
+
FAILURE: {
|
|
4361
|
+
name: "Failure",
|
|
4362
|
+
stages: [
|
|
4363
|
+
"High / tolerated / assumed to be wrong",
|
|
4364
|
+
"Moderate / unsurprising if wrong but disappointed",
|
|
4365
|
+
"Not tolerated / focus on constant improvement / assumed to be in the right direction / resistance to changing the model",
|
|
4366
|
+
"Surprised by failure / focus on operational efficiency"
|
|
4367
|
+
]
|
|
4368
|
+
},
|
|
4369
|
+
FOCUS_OF_VALUE: {
|
|
4370
|
+
name: "Focus Of Value",
|
|
4371
|
+
stages: [
|
|
4372
|
+
"High future worth but immediate investment",
|
|
4373
|
+
"Seeking ways to profit and a ROI / seeking confirmation of value",
|
|
4374
|
+
"High profitability per unit / a valuable model / a feeling of understanding / focus on exploitation",
|
|
4375
|
+
"High volume / reducing margin / important but invisible / an essential component of something more complex"
|
|
4376
|
+
]
|
|
4377
|
+
},
|
|
4378
|
+
ACTIVITIES: {
|
|
4379
|
+
name: "Activities",
|
|
4380
|
+
stages: [
|
|
4381
|
+
"Genesis",
|
|
4382
|
+
"Custom",
|
|
4383
|
+
"Product (+rental)",
|
|
4384
|
+
"Commodity (+utility)"
|
|
4385
|
+
]
|
|
4386
|
+
},
|
|
4387
|
+
KNOWLEDGE_MANAGEMENT: {
|
|
4388
|
+
name: "Knowledge Management",
|
|
4389
|
+
stages: [
|
|
4390
|
+
"Uncertain",
|
|
4391
|
+
"Learning on use / focused on testing prediction",
|
|
4392
|
+
"Learning on operation / using prediction / verification",
|
|
4393
|
+
"Known / accepted"
|
|
4394
|
+
]
|
|
4395
|
+
},
|
|
4396
|
+
KNOWLEDGE: {
|
|
4397
|
+
name: "Knowledge",
|
|
4398
|
+
stages: ["Concept", "Hypothesis", "Theory", "Accepted"]
|
|
4399
|
+
},
|
|
4400
|
+
MARKET_ACTION: {
|
|
4401
|
+
name: "Market Action",
|
|
4402
|
+
stages: [
|
|
4403
|
+
"Gambling / driven by gut",
|
|
4404
|
+
'Exploring a "found" value',
|
|
4405
|
+
"Market analysis / listening to customers",
|
|
4406
|
+
"Metric driven / build what is needed"
|
|
4407
|
+
]
|
|
4408
|
+
},
|
|
4409
|
+
MARKET_PERCEPTION: {
|
|
4410
|
+
name: "Market Perception",
|
|
4411
|
+
stages: [
|
|
4412
|
+
'Chaotic (non-linear) / domain of the "crazy"',
|
|
4413
|
+
'Domain of "experts"',
|
|
4414
|
+
'Increasing expectation of use / domain of "professionals"',
|
|
4415
|
+
"Ordered (appearance of being linear) / trivial / formula to be applied"
|
|
4416
|
+
]
|
|
4417
|
+
},
|
|
4418
|
+
MARKET: {
|
|
4419
|
+
name: "Market",
|
|
4420
|
+
stages: [
|
|
4421
|
+
"Undefined Market",
|
|
4422
|
+
"Forming Market / an array of competing forms and models of understanding",
|
|
4423
|
+
"Growing Market / consolidation to a few competing but more accepted forms",
|
|
4424
|
+
"Mature Market / stabilised to an accepted form"
|
|
4425
|
+
]
|
|
4426
|
+
},
|
|
4427
|
+
PERCEPTION_IN_INDUSTRY: {
|
|
4428
|
+
name: "Perception In Industry",
|
|
4429
|
+
stages: [
|
|
4430
|
+
"Future source of competitive advantage / unpredictable / unknown",
|
|
4431
|
+
"Seen as a scompetitive advantage / a differential / ROI / case examples",
|
|
4432
|
+
"Advantage through implementation / features / this model is better than that",
|
|
4433
|
+
"Cost of doing business / accepted / specific defined models"
|
|
4434
|
+
]
|
|
4435
|
+
},
|
|
4436
|
+
EVOLUTION_STAGE: {
|
|
4437
|
+
name: "Evolution Stage",
|
|
4438
|
+
stages: ["Stage I", "Stage II", "Stage III", "Stage IV"]
|
|
4439
|
+
},
|
|
4440
|
+
PRACTICE: {
|
|
4441
|
+
name: "Practice",
|
|
4442
|
+
stages: ["Novel", "Emerging", "Good", "Best"]
|
|
4443
|
+
},
|
|
4444
|
+
PUBLICATION_TYPES: {
|
|
4445
|
+
name: "Publication Types",
|
|
4446
|
+
stages: [
|
|
4447
|
+
"Describe the wonder of the thing / the discovery of some marvel / a new land / an unknown frontier",
|
|
4448
|
+
"Focused on build / construct / awareness and learning / many models of explanation / no accepted forms / a wild west",
|
|
4449
|
+
"Maintenance / operations / installation / comparison between competing forms / feature analysis",
|
|
4450
|
+
"Focused on use / increasingly an accepted, almost invisible component"
|
|
4451
|
+
]
|
|
4452
|
+
},
|
|
4453
|
+
UBIQUITY: {
|
|
4454
|
+
name: "Ubiquity",
|
|
4455
|
+
stages: [
|
|
4456
|
+
"Rare",
|
|
4457
|
+
"Slowly Increasing",
|
|
4458
|
+
"Rapidly Increasing",
|
|
4459
|
+
"Widespread in the applicable market / ecosystem"
|
|
4460
|
+
]
|
|
4461
|
+
},
|
|
4462
|
+
UNDERSTANDING: {
|
|
4463
|
+
name: "Understanding",
|
|
4464
|
+
stages: [
|
|
4465
|
+
"Poorly Understood / unpredictable",
|
|
4466
|
+
"Increasing understanding / development of measures",
|
|
4467
|
+
"Increasing education / constant refinement of needs / measures",
|
|
4468
|
+
"Believed to be well defined / stable / measurable"
|
|
4469
|
+
]
|
|
4470
|
+
},
|
|
4471
|
+
USER_PERCEPTION: {
|
|
4472
|
+
name: "User Perception",
|
|
4473
|
+
stages: [
|
|
4474
|
+
"Different / confusing / exciting / surprising / dangerous",
|
|
4475
|
+
"Leading edge / emerging / unceirtanty over results",
|
|
4476
|
+
"Increasingly common / disappointed if not used or available / feeling left behind",
|
|
4477
|
+
"Standard / expected / feeling of shock if not used"
|
|
4478
|
+
]
|
|
4479
|
+
}
|
|
4480
|
+
};
|
|
4481
|
+
|
|
4482
|
+
// node_modules/.pnpm/wmap-renderer-canvas@1.0.1/node_modules/wmap-renderer-canvas/src/index.js
|
|
4483
|
+
async function renderToCanvas(map, canvas, stageType = StageType.ACTIVITIES, overrides = {}) {
|
|
4484
|
+
if (!map) {
|
|
4485
|
+
throw new Error("Map object is required");
|
|
4486
|
+
}
|
|
4487
|
+
if (!canvas) {
|
|
4488
|
+
throw new Error("Canvas is required");
|
|
4489
|
+
}
|
|
4490
|
+
const configuration = extendConfiguration(overrides);
|
|
4491
|
+
const { mapWidth, mapHeight, padding } = configuration.theme.sizes;
|
|
4492
|
+
const totalWidth = mapWidth + padding * 2;
|
|
4493
|
+
const totalHeight = mapHeight + padding * 2;
|
|
4494
|
+
if (canvas.width !== totalWidth || canvas.height !== totalHeight) {
|
|
4495
|
+
canvas.width = totalWidth;
|
|
4496
|
+
canvas.height = totalHeight;
|
|
4497
|
+
}
|
|
4498
|
+
const context = canvas.getContext("2d");
|
|
4499
|
+
await render(map, context, stageType, configuration);
|
|
4500
|
+
}
|
|
4501
|
+
|
|
4502
|
+
// src/wmap.js
|
|
4503
|
+
var import_isomorphic_dompurify = __toESM(require_browser2(), 1);
|
|
4504
|
+
var internals4 = {
|
|
4505
|
+
kStyleSheet: "/plugins/wmap/wmap.css",
|
|
4506
|
+
kCanvasWidth: 1384,
|
|
4507
|
+
kCanvasHeight: 1884,
|
|
4508
|
+
// Returns HTML that shows a message in the wiki.
|
|
4509
|
+
message(text) {
|
|
4510
|
+
return `
|
|
4511
|
+
<div class="viewer" data-item="viewer" style="width:98%">
|
|
4512
|
+
<div style="width:80%; padding:8px; color:gray; background-color:#eee; margin:0 auto; text-align:center">
|
|
4513
|
+
<i>${text}</i>
|
|
4514
|
+
</div>
|
|
4515
|
+
</div>`;
|
|
4516
|
+
},
|
|
4517
|
+
// Creates a wmap PNG from text.
|
|
4518
|
+
async renderImage(source) {
|
|
4519
|
+
const parsedText = parse(source);
|
|
4520
|
+
const canvas = document.createElement("canvas");
|
|
4521
|
+
canvas.width = internals4.kCanvasWidth;
|
|
4522
|
+
canvas.height = internals4.kCanvasHeight;
|
|
4523
|
+
await renderToCanvas(parsedText, canvas);
|
|
4524
|
+
return canvas.toDataURL();
|
|
4525
|
+
},
|
|
4526
|
+
// Starts a download of the image.
|
|
4527
|
+
download(filename, text) {
|
|
4528
|
+
var element = document.createElement("a");
|
|
4529
|
+
element.setAttribute("href", text);
|
|
4530
|
+
element.setAttribute("download", filename);
|
|
4531
|
+
element.style.display = "none";
|
|
4532
|
+
document.body.appendChild(element);
|
|
4533
|
+
element.click();
|
|
4534
|
+
document.body.removeChild(element);
|
|
4535
|
+
},
|
|
4536
|
+
// Replaces the image in a window. Intended for use in a dialog.
|
|
4537
|
+
replaceImage(window2, imageData) {
|
|
4538
|
+
const $container = window2.document.querySelector("main");
|
|
4539
|
+
$container.querySelectorAll("img").forEach((img) => img.remove());
|
|
4540
|
+
const image = document.createElement("img");
|
|
4541
|
+
image.src = imageData;
|
|
4542
|
+
image.alt = "Wardley map rendered from source.";
|
|
4543
|
+
$container.appendChild(image);
|
|
4544
|
+
}
|
|
4545
|
+
};
|
|
4546
|
+
var emit = function emit2($item) {
|
|
4547
|
+
const hasStyleSheet = [...document.styleSheets].some(
|
|
4548
|
+
(styleSheet) => styleSheet.href.endsWith(internals4.kStyleSheet)
|
|
4549
|
+
);
|
|
4550
|
+
if (!hasStyleSheet) {
|
|
4551
|
+
console.log("Adding wmap stylesheet.");
|
|
4552
|
+
const link = document.createElement("link");
|
|
4553
|
+
link.rel = "stylesheet";
|
|
4554
|
+
link.href = internals4.kStyleSheet;
|
|
4555
|
+
link.type = "text/css";
|
|
4556
|
+
document.getElementsByTagName("head")[0].appendChild(link);
|
|
4557
|
+
}
|
|
4558
|
+
return $item.append(internals4.message("Loading Wardley Map"));
|
|
4559
|
+
};
|
|
4560
|
+
var bind = async function bind2($item, item) {
|
|
4561
|
+
$item.on("dblclick", () => {
|
|
4562
|
+
return wiki.textEditor($item, item);
|
|
4563
|
+
});
|
|
4564
|
+
$item.on("click", "a", (event) => {
|
|
4565
|
+
const { currentTarget } = event;
|
|
4566
|
+
const action = currentTarget.dataset?.action;
|
|
4567
|
+
if (!action) {
|
|
4568
|
+
return;
|
|
4569
|
+
}
|
|
4570
|
+
event.stopPropagation();
|
|
4571
|
+
event.preventDefault();
|
|
4572
|
+
switch (action) {
|
|
4573
|
+
case "download":
|
|
4574
|
+
{
|
|
4575
|
+
const slug = $item.parents(".page").attr("id");
|
|
4576
|
+
internals4.download(`${slug}.png`, item.png);
|
|
4577
|
+
}
|
|
4578
|
+
break;
|
|
4579
|
+
case "zoom":
|
|
4580
|
+
{
|
|
4581
|
+
const shouldOpenStandalone = !!event.shiftKey;
|
|
4582
|
+
const target = shouldOpenStandalone ? "_blank" : "wmap";
|
|
4583
|
+
const dialog = window.open(
|
|
4584
|
+
"/plugins/wmap/dialog/#",
|
|
4585
|
+
target,
|
|
4586
|
+
"popup,height=600,width=800"
|
|
4587
|
+
);
|
|
4588
|
+
if (dialog.location.pathname !== "/plugins/wmap/dialog/") {
|
|
4589
|
+
dialog.addEventListener("load", () => {
|
|
4590
|
+
internals4.replaceImage(dialog, item.png);
|
|
4591
|
+
});
|
|
4592
|
+
} else {
|
|
4593
|
+
internals4.replaceImage(dialog, item.png);
|
|
4594
|
+
}
|
|
4595
|
+
}
|
|
4596
|
+
break;
|
|
4597
|
+
}
|
|
4598
|
+
});
|
|
4599
|
+
try {
|
|
4600
|
+
let imageData = await internals4.renderImage(item.text);
|
|
4601
|
+
item.png = imageData;
|
|
4602
|
+
$item.find(".viewer").html(`
|
|
4603
|
+
<article class="wardley-map"><img src="${imageData}"</article>
|
|
4604
|
+
<nav class="actions">
|
|
4605
|
+
<menu>
|
|
4606
|
+
<li><a href="#" data-action="download" title="Download"><img width="18" height="18" alt="download" src='data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" viewBox="0 0 24 24" fill="grey"><g><rect fill="none" height="24" width="24"/></g><g><path d="M5,20h14v-2H5V20z M19,9h-4V3H9v6H5l7,7L19,9z"/></g></svg>'></a></li>
|
|
4607
|
+
<li><a href="#" data-action="zoom" title="Zoom"><img width="18" height="18" alt="toggle zoom" src='data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" viewBox="0 0 24 24"><g><rect fill="none" height="24" width="24"/></g><g><g><g><path fill="grey" d="M15,3l2.3,2.3l-2.89,2.87l1.42,1.42L18.7,6.7L21,9V3H15z M3,9l2.3-2.3l2.87,2.89l1.42-1.42L6.7,5.3L9,3H3V9z M9,21 l-2.3-2.3l2.89-2.87l-1.42-1.42L5.3,17.3L3,15v6H9z M21,15l-2.3,2.3l-2.87-2.89l-1.42,1.42l2.89,2.87L15,21h6V15z"/></g></g></g></svg>'></a></li>
|
|
4608
|
+
</menu>
|
|
4609
|
+
</nav>
|
|
4610
|
+
`);
|
|
4611
|
+
} catch (err) {
|
|
4612
|
+
console.log("Failed to parse wardley map: ", err);
|
|
4613
|
+
$item.html(internals4.message(err.message));
|
|
4614
|
+
}
|
|
4615
|
+
};
|
|
4616
|
+
if (typeof window !== "undefined" && window !== null) {
|
|
4617
|
+
if (!window.plugins.wmap) {
|
|
4618
|
+
window.plugins.wmap = { emit, bind };
|
|
4619
|
+
}
|
|
4620
|
+
}
|
|
4621
|
+
var expand = function(text) {
|
|
4622
|
+
return import_isomorphic_dompurify.default.sanitize(text);
|
|
4623
|
+
};
|
|
4624
|
+
var wmap = typeof window === "undefined" ? { expand } : void 0;
|
|
4625
|
+
})();
|
|
4626
|
+
/*! Bundled license information:
|
|
4627
|
+
|
|
4628
|
+
dompurify/dist/purify.cjs.js:
|
|
4629
|
+
(*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE *)
|
|
4630
|
+
*/
|