mapshaper 0.6.14 → 0.6.15
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/mapshaper.js +224 -96
- package/package.json +9 -7
- package/www/mapshaper-gui.js +16 -5
- package/www/mapshaper.js +224 -96
- package/www/modules.js +904 -2
package/www/modules.js
CHANGED
|
@@ -5866,8 +5866,910 @@ function handleQs(url, query) {
|
|
|
5866
5866
|
}
|
|
5867
5867
|
exports["default"] = handleQs;
|
|
5868
5868
|
|
|
5869
|
-
},{"qs":27}],"@
|
|
5870
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).toGeoJSON={})}(this,(function(e){"use strict";function t(e){return e&&e.normalize&&e.normalize(),e&&e.textContent||""}function n(e,t){const n=e.getElementsByTagName(t);return n.length?n[0]:null}function o(e){const o={};if(e){const s=n(e,"line");if(s){const e=t(n(s,"color")),r=parseFloat(t(n(s,"opacity"))),i=parseFloat(t(n(s,"width")));e&&(o.stroke=e),isNaN(r)||(o["stroke-opacity"]=r),isNaN(i)||(o["stroke-width"]=96*i/25.4)}}return o}function s(e){let n=[];if(null!==e)for(let o=0;o<e.childNodes.length;o++){const r=e.childNodes[o];if(1!==r.nodeType)continue;const i=["heart","gpxtpx:hr","hr"].includes(r.nodeName)?"heart":r.nodeName;if("gpxtpx:TrackPointExtension"===i)n=n.concat(s(r));else{const e=t(r);n.push([i,isNaN(e)?e:parseFloat(e)])}}return n}function r(e,o){const s={};let r,i;for(i=0;i<o.length;i++)r=n(e,o[i]),r&&(s[o[i]]=t(r));return s}function i(e){const n=r(e,["name","cmt","desc","type","time","keywords"]),o=e.getElementsByTagNameNS("http://www.garmin.com/xmlschemas/GpxExtensions/v3","*");for(let s=0;s<o.length;s++){const r=o[s];r.parentNode.parentNode===e&&(n[r.tagName.replace(":","_")]=t(r))}const s=e.getElementsByTagName("link");s.length&&(n.links=[]);for(let e=0;e<s.length;e++)n.links.push(Object.assign({href:s[e].getAttribute("href")},r(s[e],["text","type"])));return n}function l(e){const o=[parseFloat(e.getAttribute("lon")),parseFloat(e.getAttribute("lat"))],r=n(e,"ele"),i=n(e,"time");if(r){const e=parseFloat(t(r));isNaN(e)||o.push(e)}return{coordinates:o,time:i?t(i):null,extendedValues:s(n(e,"extensions"))}}function a(e){const t=c(e,"rtept");if(t)return{type:"Feature",properties:Object.assign(i(e),o(n(e,"extensions")),{_gpxType:"rte"}),geometry:{type:"LineString",coordinates:t.line}}}function c(e,t){const n=e.getElementsByTagName(t);if(n.length<2)return;const o=[],s=[],r={};for(let e=0;e<n.length;e++){const t=l(n[e]);o.push(t.coordinates),t.time&&s.push(t.time);for(let o=0;o<t.extendedValues.length;o++){const[s,i]=t.extendedValues[o],l="heart"===s?s:s.replace("gpxtpx:","")+"s";r[l]||(r[l]=Array(n.length).fill(null)),r[l][e]=i}}return{line:o,times:s,extendedValues:r}}function g(e){const t=e.getElementsByTagName("trkseg"),s=[],r=[],l=[];for(let e=0;e<t.length;e++){const n=c(t[e],"trkpt");n&&(l.push(n),n.times&&n.times.length&&r.push(n.times))}if(0===l.length)return;const a=l.length>1,g=Object.assign(i(e),o(n(e,"extensions")),{_gpxType:"trk"},r.length?{coordinateProperties:{times:a?r:r[0]}}:{});for(let e=0;e<l.length;e++){const t=l[e];s.push(t.line);for(const[n,o]of Object.entries(t.extendedValues)){g.coordinateProperties||(g.coordinateProperties={});const t=g.coordinateProperties;a?(t[n]||(t[n]=l.map((e=>new Array(e.line.length).fill(null)))),t[n][e]=o):t[n]=o}}return{type:"Feature",properties:g,geometry:a?{type:"MultiLineString",coordinates:s}:{type:"LineString",coordinates:s[0]}}}function*u(e){const t=e.getElementsByTagName("trk"),n=e.getElementsByTagName("rte"),o=e.getElementsByTagName("wpt");for(let e=0;e<t.length;e++){const n=g(t[e]);n&&(yield n)}for(let e=0;e<n.length;e++){const t=a(n[e]);t&&(yield t)}for(let e=0;e<o.length;e++)yield(s=o[e],{type:"Feature",properties:Object.assign(i(s),r(s,["sym"])),geometry:{type:"Point",coordinates:l(s).coordinates}});var s}const p=[["heartRate","heartRates"],["Cadence","cadences"],["Speed","speeds"],["Watts","watts"]],m=[["TotalTimeSeconds","totalTimeSeconds"],["DistanceMeters","distanceMeters"],["MaximumSpeed","maxSpeed"],["AverageHeartRateBpm","avgHeartRate"],["MaximumHeartRateBpm","maxHeartRate"],["AvgSpeed","avgSpeed"],["AvgWatts","avgWatts"],["MaxWatts","maxWatts"]];function d(e,o){const s=[];for(const[r,i]of o){let o=n(e,r);if(!o){const t=e.getElementsByTagNameNS("http://www.garmin.com/xmlschemas/ActivityExtension/v2",r);t.length&&(o=t[0])}const l=parseFloat(t(o));isNaN(l)||s.push([i,l])}return s}function f(e){const o=t(n(e,"LongitudeDegrees")),s=t(n(e,"LatitudeDegrees"));if(!o.length||!s.length)return null;const r=[parseFloat(o),parseFloat(s)],i=n(e,"AltitudeMeters"),l=n(e,"HeartRateBpm"),a=n(e,"Time");let c;return i&&(c=parseFloat(t(i)),isNaN(c)||r.push(c)),{coordinates:r,time:a?t(a):null,heartRate:l?parseFloat(t(l)):null,extensions:d(e,p)}}function h(e,t){const n=e.getElementsByTagName(t),o=[],s=[],r=[];if(n.length<2)return null;const i={extendedProperties:{}};for(let e=0;e<n.length;e++){const t=f(n[e]);if(null!==t){o.push(t.coordinates),t.time&&s.push(t.time),t.heartRate&&r.push(t.heartRate);for(const[o,s]of t.extensions)i.extendedProperties[o]||(i.extendedProperties[o]=Array(n.length).fill(null)),i.extendedProperties[o][e]=s}}return Object.assign(i,{line:o,times:s,heartRates:r})}function y(e){const o=e.getElementsByTagName("Track"),s=[],r=[],i=[],l=[];let a;const c=function(e){const t={};for(const[n,o]of e)t[n]=o;return t}(d(e,m)),g=n(e,"Name");g&&(c.name=t(g));for(let e=0;e<o.length;e++)a=h(o[e],"Trackpoint"),a&&(s.push(a.line),a.times.length&&r.push(a.times),a.heartRates.length&&i.push(a.heartRates),l.push(a.extendedProperties));for(let e=0;e<l.length;e++){const t=l[e];for(const n in t)1===o.length?c[n]=a.extendedProperties[n]:(c[n]||(c[n]=s.map((e=>Array(e.length).fill(null)))),c[n][e]=t[n])}if(0!==s.length)return(r.length||i.length)&&(c.coordinateProperties=Object.assign(r.length?{times:1===s.length?r[0]:r}:{},i.length?{heart:1===s.length?i[0]:i}:{})),{type:"Feature",properties:c,geometry:{type:1===s.length?"LineString":"MultiLineString",coordinates:1===s.length?s[0]:s}}}function*N(e){const t=e.getElementsByTagName("Lap");for(let e=0;e<t.length;e++){const n=y(t[e]);n&&(yield n)}const n=e.getElementsByTagName("Courses");for(let e=0;e<n.length;e++){const t=y(n[e]);t&&(yield t)}}const x=/\s*/g,T=/^\s*|\s*$/g,b=/\s+/;function S(e){if(!e||!e.length)return 0;let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return t}function k(e){return e.replace(x,"").split(",").map(parseFloat)}function E(e){return e.replace(T,"").split(b).map(k)}function A(e){if(void 0!==e.xml)return e.xml;if(e.tagName){let t=e.tagName;for(let n=0;n<e.attributes.length;n++)t+=e.attributes[n].name+e.attributes[n].value;for(let n=0;n<e.childNodes.length;n++)t+=A(e.childNodes[n]);return t}return"#text"===e.nodeName?(e.nodeValue||e.value||"").trim():"#cdata-section"===e.nodeName?e.nodeValue:""}const B=["Polygon","LineString","Point","Track","gx:Track"];function P(e,o,s){let r=t(n(o,"color"))||"";const i="stroke"==s||"fill"===s?s:s+"-color";"#"===r.substr(0,1)&&(r=r.substr(1)),6===r.length||3===r.length?e[i]=r:8===r.length&&(e[s+"-opacity"]=parseInt(r.substr(0,2),16)/255,e[i]="#"+r.substr(6,2)+r.substr(4,2)+r.substr(2,2))}function F(e,o,s,r){const i=parseFloat(t(n(o,s)));isNaN(i)||(e[r]=i)}function v(e){let n=e.getElementsByTagName("coord");const o=[],s=[];0===n.length&&(n=e.getElementsByTagName("gx:coord"));for(let e=0;e<n.length;e++)o.push(t(n[e]).split(" ").map(parseFloat));const r=e.getElementsByTagName("when");for(let e=0;e<r.length;e++)s.push(t(r[e]));return{coords:o,times:s}}function L(e){let o,s,r,i,l;const a=[],c=[];if(n(e,"MultiGeometry"))return L(n(e,"MultiGeometry"));if(n(e,"MultiTrack"))return L(n(e,"MultiTrack"));if(n(e,"gx:MultiTrack"))return L(n(e,"gx:MultiTrack"));for(r=0;r<B.length;r++)if(s=e.getElementsByTagName(B[r]),s)for(i=0;i<s.length;i++)if(o=s[i],"Point"===B[r])a.push({type:"Point",coordinates:k(t(n(o,"coordinates")))});else if("LineString"===B[r])a.push({type:"LineString",coordinates:E(t(n(o,"coordinates")))});else if("Polygon"===B[r]){const e=o.getElementsByTagName("LinearRing"),s=[];for(l=0;l<e.length;l++)s.push(E(t(n(e[l],"coordinates"))));a.push({type:"Polygon",coordinates:s})}else if("Track"===B[r]||"gx:Track"===B[r]){const e=v(o);a.push({type:"LineString",coordinates:e.coords}),e.times.length&&c.push(e.times)}return{geoms:a,coordTimes:c}}function M(e,o,s,r){const i=L(e);let l;const a={},c=t(n(e,"name")),g=t(n(e,"address"));let u=t(n(e,"styleUrl"));const p=t(n(e,"description")),m=n(e,"TimeSpan"),d=n(e,"TimeStamp"),f=n(e,"ExtendedData");let h=n(e,"IconStyle"),y=n(e,"LabelStyle"),N=n(e,"LineStyle"),x=n(e,"PolyStyle");const T=n(e,"visibility");if(c&&(a.name=c),g&&(a.address=g),u){"#"!==u[0]&&(u="#"+u),a.styleUrl=u,o[u]&&(a.styleHash=o[u]),s[u]&&(a.styleMapHash=s[u],a.styleHash=o[s[u].normal]);const e=r[a.styleHash];e&&(h||(h=n(e,"IconStyle")),y||(y=n(e,"LabelStyle")),N||(N=n(e,"LineStyle")),x||(x=n(e,"PolyStyle")))}if(p&&(a.description=p),m){const e=t(n(m,"begin")),o=t(n(m,"end"));a.timespan={begin:e,end:o}}if(d&&(a.timestamp=t(n(d,"when"))),h){P(a,h,"icon"),F(a,h,"scale","icon-scale"),F(a,h,"heading","icon-heading");const e=n(h,"hotSpot");if(e){const t=parseFloat(e.getAttribute("x")),n=parseFloat(e.getAttribute("y"));isNaN(t)||isNaN(n)||(a["icon-offset"]=[t,n])}const o=n(h,"Icon");if(o){const e=t(n(o,"href"));e&&(a.icon=e)}}if(y&&(P(a,y,"label"),F(a,y,"scale","label-scale")),N&&(P(a,N,"stroke"),F(a,N,"width","stroke-width")),x){P(a,x,"fill");const e=t(n(x,"fill")),o=t(n(x,"outline"));e&&(a["fill-opacity"]="1"===e?a["fill-opacity"]||1:0),o&&(a["stroke-opacity"]="1"===o?a["stroke-opacity"]||1:0)}if(f){const e=f.getElementsByTagName("Data"),o=f.getElementsByTagName("SimpleData");for(l=0;l<e.length;l++)a[e[l].getAttribute("name")]=t(n(e[l],"value"));for(l=0;l<o.length;l++)a[o[l].getAttribute("name")]=t(o[l])}T&&(a.visibility=t(T)),i.coordTimes.length&&(a.coordinateProperties={times:1===i.coordTimes.length?i.coordTimes[0]:i.coordTimes});const b={type:"Feature",geometry:0===i.geoms.length?null:1===i.geoms.length?i.geoms[0]:{type:"GeometryCollection",geometries:i.geoms},properties:a};return e.getAttribute("id")&&(b.id=e.getAttribute("id")),b}function*w(e){const o={},s={},r={},i=e.getElementsByTagName("Placemark"),l=e.getElementsByTagName("Style"),a=e.getElementsByTagName("StyleMap");for(let e=0;e<l.length;e++){const t=l[e],n=S(A(t)).toString(16);let r=t.getAttribute("id");r||"CascadingStyle"!==t.parentNode.tagName.replace("gx:","")||(r=t.parentNode.getAttribute("kml:id")||t.parentNode.getAttribute("id")),o["#"+r]=n,s[n]=t}for(let e=0;e<a.length;e++){o["#"+a[e].getAttribute("id")]=S(A(a[e])).toString(16);const s=a[e].getElementsByTagName("Pair"),i={};for(let e=0;e<s.length;e++)i[t(n(s[e],"key"))]=t(n(s[e],"styleUrl"));r["#"+a[e].getAttribute("id")]=i}for(let e=0;e<i.length;e++){const t=M(i[e],o,r,s);t&&(yield t)}}e.gpx=function(e){return{type:"FeatureCollection",features:Array.from(u(e))}},e.gpxGen=u,e.kml=function(e){return{type:"FeatureCollection",features:Array.from(w(e))}},e.kmlGen=w,e.tcx=function(e){return{type:"FeatureCollection",features:Array.from(N(e))}},e.tcxGen=N,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
5869
|
+
},{"qs":27}],"@placemarkio/tokml":[function(require,module,exports){
|
|
5870
|
+
'use strict';
|
|
5871
|
+
|
|
5872
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5873
|
+
|
|
5874
|
+
/**
|
|
5875
|
+
* @typedef {import('unist').Node} Node
|
|
5876
|
+
* @typedef {import('unist').Parent} Parent
|
|
5877
|
+
* @typedef {import('unist').Literal} Literal
|
|
5878
|
+
* @typedef {Object.<string, unknown>} Props
|
|
5879
|
+
* @typedef {Array.<Node>|string} ChildrenOrValue
|
|
5880
|
+
*
|
|
5881
|
+
* @typedef {(<T extends string, P extends Record<string, unknown>, C extends Node[]>(type: T, props: P, children: C) => {type: T, children: C} & P)} BuildParentWithProps
|
|
5882
|
+
* @typedef {(<T extends string, P extends Record<string, unknown>>(type: T, props: P, value: string) => {type: T, value: string} & P)} BuildLiteralWithProps
|
|
5883
|
+
* @typedef {(<T extends string, P extends Record<string, unknown>>(type: T, props: P) => {type: T} & P)} BuildVoidWithProps
|
|
5884
|
+
* @typedef {(<T extends string, C extends Node[]>(type: T, children: C) => {type: T, children: C})} BuildParent
|
|
5885
|
+
* @typedef {(<T extends string>(type: T, value: string) => {type: T, value: string})} BuildLiteral
|
|
5886
|
+
* @typedef {(<T extends string>(type: T) => {type: T})} BuildVoid
|
|
5887
|
+
*/
|
|
5888
|
+
|
|
5889
|
+
var u = /**
|
|
5890
|
+
* @type {BuildVoid & BuildVoidWithProps & BuildLiteral & BuildLiteralWithProps & BuildParent & BuildParentWithProps}
|
|
5891
|
+
*/ (
|
|
5892
|
+
/**
|
|
5893
|
+
* @param {string} type Type of node
|
|
5894
|
+
* @param {Props|ChildrenOrValue} [props] Additional properties for node (or `children` or `value`)
|
|
5895
|
+
* @param {ChildrenOrValue} [value] `children` or `value` of node
|
|
5896
|
+
* @returns {Node}
|
|
5897
|
+
*/
|
|
5898
|
+
function (type, props, value) {
|
|
5899
|
+
/** @type {Node} */
|
|
5900
|
+
var node = {type: String(type)};
|
|
5901
|
+
|
|
5902
|
+
if (
|
|
5903
|
+
(value === undefined || value === null) &&
|
|
5904
|
+
(typeof props === 'string' || Array.isArray(props))
|
|
5905
|
+
) {
|
|
5906
|
+
value = props;
|
|
5907
|
+
} else {
|
|
5908
|
+
Object.assign(node, props);
|
|
5909
|
+
}
|
|
5910
|
+
|
|
5911
|
+
if (Array.isArray(value)) {
|
|
5912
|
+
node.children = value;
|
|
5913
|
+
} else if (value !== undefined && value !== null) {
|
|
5914
|
+
node.value = String(value);
|
|
5915
|
+
}
|
|
5916
|
+
|
|
5917
|
+
return node
|
|
5918
|
+
}
|
|
5919
|
+
);
|
|
5920
|
+
|
|
5921
|
+
/**
|
|
5922
|
+
* @typedef {import('xast').Root} Root
|
|
5923
|
+
* @typedef {import('xast').Element} Element
|
|
5924
|
+
* @typedef {Root['children'][number]} Child
|
|
5925
|
+
* @typedef {Child|Root} Node
|
|
5926
|
+
* @typedef {Root|Element} XResult
|
|
5927
|
+
* @typedef {string|number|boolean|null|undefined} XValue
|
|
5928
|
+
* @typedef {{[attribute: string]: XValue}} XAttributes Attributes to support JS primitive types
|
|
5929
|
+
*
|
|
5930
|
+
* @typedef {string|number|null|undefined} XPrimitiveChild
|
|
5931
|
+
* @typedef {Array.<Node|XPrimitiveChild>} XArrayChild
|
|
5932
|
+
* @typedef {Node|XPrimitiveChild|XArrayChild} XChild
|
|
5933
|
+
* @typedef {import('./jsx-classic').Element} x.JSX.Element
|
|
5934
|
+
* @typedef {import('./jsx-classic').IntrinsicAttributes} x.JSX.IntrinsicAttributes
|
|
5935
|
+
* @typedef {import('./jsx-classic').IntrinsicElements} x.JSX.IntrinsicElements
|
|
5936
|
+
* @typedef {import('./jsx-classic').ElementChildrenAttribute} x.JSX.ElementChildrenAttribute
|
|
5937
|
+
*/
|
|
5938
|
+
|
|
5939
|
+
/**
|
|
5940
|
+
* Create XML trees in xast.
|
|
5941
|
+
*
|
|
5942
|
+
* @param name Qualified name. Case sensitive and can contain a namespace prefix (such as `rdf:RDF`). Pass `null|undefined` to build a root.
|
|
5943
|
+
* @param attributes Map of attributes. Nullish (null or undefined) or NaN values are ignored, other values (strings, booleans) are cast to strings.
|
|
5944
|
+
* @param children (Lists of) child nodes. When strings are encountered, they are mapped to Text nodes.
|
|
5945
|
+
*/
|
|
5946
|
+
const x =
|
|
5947
|
+
/**
|
|
5948
|
+
* @type {{
|
|
5949
|
+
* (): Root
|
|
5950
|
+
* (name: null|undefined, ...children: XChild[]): Root
|
|
5951
|
+
* (name: string, attributes: XAttributes, ...children: XChild[]): Element
|
|
5952
|
+
* (name: string, ...children: XChild[]): Element
|
|
5953
|
+
* }}
|
|
5954
|
+
*/
|
|
5955
|
+
(
|
|
5956
|
+
/**
|
|
5957
|
+
* Hyperscript compatible DSL for creating virtual xast trees.
|
|
5958
|
+
*
|
|
5959
|
+
* @param {string|null} [name]
|
|
5960
|
+
* @param {XAttributes|XChild} [attributes]
|
|
5961
|
+
* @param {XChild[]} children
|
|
5962
|
+
* @returns {XResult}
|
|
5963
|
+
*/
|
|
5964
|
+
function (name, attributes, ...children) {
|
|
5965
|
+
var index = -1;
|
|
5966
|
+
/** @type {XResult} */
|
|
5967
|
+
var node;
|
|
5968
|
+
/** @type {string} */
|
|
5969
|
+
var key;
|
|
5970
|
+
|
|
5971
|
+
if (name === undefined || name === null) {
|
|
5972
|
+
node = {type: 'root', children: []};
|
|
5973
|
+
// @ts-ignore Root builder doesn’t accept attributes.
|
|
5974
|
+
children.unshift(attributes);
|
|
5975
|
+
} else if (typeof name === 'string') {
|
|
5976
|
+
node = {type: 'element', name, attributes: {}, children: []};
|
|
5977
|
+
|
|
5978
|
+
if (isAttributes(attributes)) {
|
|
5979
|
+
for (key in attributes) {
|
|
5980
|
+
// Ignore nullish and NaN values.
|
|
5981
|
+
if (
|
|
5982
|
+
attributes[key] !== undefined &&
|
|
5983
|
+
attributes[key] !== null &&
|
|
5984
|
+
(typeof attributes[key] !== 'number' ||
|
|
5985
|
+
!Number.isNaN(attributes[key]))
|
|
5986
|
+
) {
|
|
5987
|
+
// @ts-ignore Pretty sure we just set it.
|
|
5988
|
+
node.attributes[key] = String(attributes[key]);
|
|
5989
|
+
}
|
|
5990
|
+
}
|
|
5991
|
+
} else {
|
|
5992
|
+
children.unshift(attributes);
|
|
5993
|
+
}
|
|
5994
|
+
} else {
|
|
5995
|
+
throw new TypeError('Expected element name, got `' + name + '`')
|
|
5996
|
+
}
|
|
5997
|
+
|
|
5998
|
+
// Handle children.
|
|
5999
|
+
while (++index < children.length) {
|
|
6000
|
+
addChild(node.children, children[index]);
|
|
6001
|
+
}
|
|
6002
|
+
|
|
6003
|
+
return node
|
|
6004
|
+
}
|
|
6005
|
+
);
|
|
6006
|
+
|
|
6007
|
+
/**
|
|
6008
|
+
* @param {Array.<Child>} nodes
|
|
6009
|
+
* @param {XChild} value
|
|
6010
|
+
*/
|
|
6011
|
+
function addChild(nodes, value) {
|
|
6012
|
+
var index = -1;
|
|
6013
|
+
|
|
6014
|
+
if (value === undefined || value === null) ; else if (typeof value === 'string' || typeof value === 'number') {
|
|
6015
|
+
nodes.push({type: 'text', value: String(value)});
|
|
6016
|
+
} else if (Array.isArray(value)) {
|
|
6017
|
+
while (++index < value.length) {
|
|
6018
|
+
addChild(nodes, value[index]);
|
|
6019
|
+
}
|
|
6020
|
+
} else if (typeof value === 'object' && 'type' in value) {
|
|
6021
|
+
if (value.type === 'root') {
|
|
6022
|
+
addChild(nodes, value.children);
|
|
6023
|
+
} else {
|
|
6024
|
+
nodes.push(value);
|
|
6025
|
+
}
|
|
6026
|
+
} else {
|
|
6027
|
+
throw new TypeError('Expected node, nodes, string, got `' + value + '`')
|
|
6028
|
+
}
|
|
6029
|
+
}
|
|
6030
|
+
|
|
6031
|
+
/**
|
|
6032
|
+
* @param {XAttributes|XChild} value
|
|
6033
|
+
* @returns {value is XAttributes}
|
|
6034
|
+
*/
|
|
6035
|
+
function isAttributes(value) {
|
|
6036
|
+
if (
|
|
6037
|
+
value === null ||
|
|
6038
|
+
value === undefined ||
|
|
6039
|
+
typeof value !== 'object' ||
|
|
6040
|
+
Array.isArray(value)
|
|
6041
|
+
) {
|
|
6042
|
+
return false
|
|
6043
|
+
}
|
|
6044
|
+
|
|
6045
|
+
return true
|
|
6046
|
+
}
|
|
6047
|
+
|
|
6048
|
+
/**
|
|
6049
|
+
* @typedef {import('./index.js').Parent} Parent
|
|
6050
|
+
* @typedef {import('./index.js').Context} Context
|
|
6051
|
+
* @typedef {import('./index.js').Child} Child
|
|
6052
|
+
*/
|
|
6053
|
+
|
|
6054
|
+
/**
|
|
6055
|
+
* Serialize all children of `parent`.
|
|
6056
|
+
*
|
|
6057
|
+
* @param {Parent} parent
|
|
6058
|
+
* @param {Context} ctx
|
|
6059
|
+
* @returns {string}
|
|
6060
|
+
*
|
|
6061
|
+
*/
|
|
6062
|
+
function all(parent, ctx) {
|
|
6063
|
+
/** @type {Array.<Child>} */
|
|
6064
|
+
var children = (parent && parent.children) || [];
|
|
6065
|
+
var index = -1;
|
|
6066
|
+
/** @type {Array.<string>} */
|
|
6067
|
+
var results = [];
|
|
6068
|
+
|
|
6069
|
+
while (++index < children.length) {
|
|
6070
|
+
results[index] = one(children[index], ctx);
|
|
6071
|
+
}
|
|
6072
|
+
|
|
6073
|
+
return results.join('')
|
|
6074
|
+
}
|
|
6075
|
+
|
|
6076
|
+
/**
|
|
6077
|
+
* @typedef {Object} CoreOptions
|
|
6078
|
+
* @property {string[]} [subset=[]]
|
|
6079
|
+
* Whether to only escape the given subset of characters.
|
|
6080
|
+
* @property {boolean} [escapeOnly=false]
|
|
6081
|
+
* Whether to only escape possibly dangerous characters.
|
|
6082
|
+
* Those characters are `"`, `&`, `'`, `<`, `>`, and `` ` ``.
|
|
6083
|
+
*
|
|
6084
|
+
* @typedef {Object} FormatOptions
|
|
6085
|
+
* @property {(code: number, next: number, options: CoreWithFormatOptions) => string} format
|
|
6086
|
+
* Format strategy.
|
|
6087
|
+
*
|
|
6088
|
+
* @typedef {CoreOptions & FormatOptions & import('./util/format-smart.js').FormatSmartOptions} CoreWithFormatOptions
|
|
6089
|
+
*/
|
|
6090
|
+
|
|
6091
|
+
/**
|
|
6092
|
+
* Encode certain characters in `value`.
|
|
6093
|
+
*
|
|
6094
|
+
* @param {string} value
|
|
6095
|
+
* @param {CoreWithFormatOptions} options
|
|
6096
|
+
* @returns {string}
|
|
6097
|
+
*/
|
|
6098
|
+
function core(value, options) {
|
|
6099
|
+
value = value.replace(
|
|
6100
|
+
options.subset ? charactersToExpression(options.subset) : /["&'<>`]/g,
|
|
6101
|
+
basic
|
|
6102
|
+
);
|
|
6103
|
+
|
|
6104
|
+
if (options.subset || options.escapeOnly) {
|
|
6105
|
+
return value
|
|
6106
|
+
}
|
|
6107
|
+
|
|
6108
|
+
return (
|
|
6109
|
+
value
|
|
6110
|
+
// Surrogate pairs.
|
|
6111
|
+
.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, surrogate)
|
|
6112
|
+
// BMP control characters (C0 except for LF, CR, SP; DEL; and some more
|
|
6113
|
+
// non-ASCII ones).
|
|
6114
|
+
.replace(
|
|
6115
|
+
// eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
|
|
6116
|
+
/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,
|
|
6117
|
+
basic
|
|
6118
|
+
)
|
|
6119
|
+
)
|
|
6120
|
+
|
|
6121
|
+
/**
|
|
6122
|
+
* @param {string} pair
|
|
6123
|
+
* @param {number} index
|
|
6124
|
+
* @param {string} all
|
|
6125
|
+
*/
|
|
6126
|
+
function surrogate(pair, index, all) {
|
|
6127
|
+
return options.format(
|
|
6128
|
+
(pair.charCodeAt(0) - 0xd800) * 0x400 +
|
|
6129
|
+
pair.charCodeAt(1) -
|
|
6130
|
+
0xdc00 +
|
|
6131
|
+
0x10000,
|
|
6132
|
+
all.charCodeAt(index + 2),
|
|
6133
|
+
options
|
|
6134
|
+
)
|
|
6135
|
+
}
|
|
6136
|
+
|
|
6137
|
+
/**
|
|
6138
|
+
* @param {string} character
|
|
6139
|
+
* @param {number} index
|
|
6140
|
+
* @param {string} all
|
|
6141
|
+
*/
|
|
6142
|
+
function basic(character, index, all) {
|
|
6143
|
+
return options.format(
|
|
6144
|
+
character.charCodeAt(0),
|
|
6145
|
+
all.charCodeAt(index + 1),
|
|
6146
|
+
options
|
|
6147
|
+
)
|
|
6148
|
+
}
|
|
6149
|
+
}
|
|
6150
|
+
|
|
6151
|
+
/**
|
|
6152
|
+
* @param {string[]} subset
|
|
6153
|
+
* @returns {RegExp}
|
|
6154
|
+
*/
|
|
6155
|
+
function charactersToExpression(subset) {
|
|
6156
|
+
/** @type {string[]} */
|
|
6157
|
+
const groups = [];
|
|
6158
|
+
let index = -1;
|
|
6159
|
+
|
|
6160
|
+
while (++index < subset.length) {
|
|
6161
|
+
groups.push(subset[index].replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'));
|
|
6162
|
+
}
|
|
6163
|
+
|
|
6164
|
+
return new RegExp('(?:' + groups.join('|') + ')', 'g')
|
|
6165
|
+
}
|
|
6166
|
+
|
|
6167
|
+
/**
|
|
6168
|
+
* The smallest way to encode a character.
|
|
6169
|
+
*
|
|
6170
|
+
* @param {number} code
|
|
6171
|
+
* @returns {string}
|
|
6172
|
+
*/
|
|
6173
|
+
function formatBasic(code) {
|
|
6174
|
+
return '&#x' + code.toString(16).toUpperCase() + ';'
|
|
6175
|
+
}
|
|
6176
|
+
|
|
6177
|
+
/**
|
|
6178
|
+
* @typedef {import('./core.js').CoreOptions & import('./util/format-smart.js').FormatSmartOptions} Options
|
|
6179
|
+
* @typedef {import('./core.js').CoreOptions} LightOptions
|
|
6180
|
+
*/
|
|
6181
|
+
|
|
6182
|
+
/**
|
|
6183
|
+
* Encode special characters in `value` as hexadecimals.
|
|
6184
|
+
*
|
|
6185
|
+
* @param {string} value
|
|
6186
|
+
* Value to encode.
|
|
6187
|
+
* @param {LightOptions} [options]
|
|
6188
|
+
* Configuration.
|
|
6189
|
+
* @returns {string}
|
|
6190
|
+
* Encoded value.
|
|
6191
|
+
*/
|
|
6192
|
+
function stringifyEntitiesLight(value, options) {
|
|
6193
|
+
return core(value, Object.assign({format: formatBasic}, options))
|
|
6194
|
+
}
|
|
6195
|
+
|
|
6196
|
+
var noncharacter = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
|
|
6197
|
+
|
|
6198
|
+
/**
|
|
6199
|
+
* Escape a string.
|
|
6200
|
+
*
|
|
6201
|
+
* @param {string} value
|
|
6202
|
+
* @param {Array.<string>} subset
|
|
6203
|
+
* @param {RegExp} [unsafe]
|
|
6204
|
+
* @returns {string}
|
|
6205
|
+
*/
|
|
6206
|
+
function escape(value, subset, unsafe) {
|
|
6207
|
+
var result = clean(value);
|
|
6208
|
+
|
|
6209
|
+
return unsafe ? result.replace(unsafe, encode) : encode(result)
|
|
6210
|
+
|
|
6211
|
+
/**
|
|
6212
|
+
* @param {string} $0
|
|
6213
|
+
* @returns {string}
|
|
6214
|
+
*/
|
|
6215
|
+
function encode($0) {
|
|
6216
|
+
return stringifyEntitiesLight($0, {subset})
|
|
6217
|
+
}
|
|
6218
|
+
}
|
|
6219
|
+
|
|
6220
|
+
/**
|
|
6221
|
+
* @param {string} value
|
|
6222
|
+
* @returns {string}
|
|
6223
|
+
*/
|
|
6224
|
+
function clean(value) {
|
|
6225
|
+
return String(value || '').replace(noncharacter, '')
|
|
6226
|
+
}
|
|
6227
|
+
|
|
6228
|
+
var subset$3 = ['\t', '\n', ' ', '"', '&', "'", '/', '<', '=', '>'];
|
|
6229
|
+
|
|
6230
|
+
/**
|
|
6231
|
+
* Serialize a node name.
|
|
6232
|
+
*
|
|
6233
|
+
* @param {string} value
|
|
6234
|
+
* @returns {string}
|
|
6235
|
+
*/
|
|
6236
|
+
function name(value) {
|
|
6237
|
+
return escape(value, subset$3)
|
|
6238
|
+
}
|
|
6239
|
+
|
|
6240
|
+
/**
|
|
6241
|
+
* Count how often a character (or substring) is used in a string.
|
|
6242
|
+
*
|
|
6243
|
+
* @param {string} value
|
|
6244
|
+
* Value to search in.
|
|
6245
|
+
* @param {string} character
|
|
6246
|
+
* Character (or substring) to look for.
|
|
6247
|
+
* @return {number}
|
|
6248
|
+
* Number of times `character` occurred in `value`.
|
|
6249
|
+
*/
|
|
6250
|
+
function ccount(value, character) {
|
|
6251
|
+
const source = String(value);
|
|
6252
|
+
|
|
6253
|
+
if (typeof character !== 'string') {
|
|
6254
|
+
throw new TypeError('Expected character')
|
|
6255
|
+
}
|
|
6256
|
+
|
|
6257
|
+
let count = 0;
|
|
6258
|
+
let index = source.indexOf(character);
|
|
6259
|
+
|
|
6260
|
+
while (index !== -1) {
|
|
6261
|
+
count++;
|
|
6262
|
+
index = source.indexOf(character, index + character.length);
|
|
6263
|
+
}
|
|
6264
|
+
|
|
6265
|
+
return count
|
|
6266
|
+
}
|
|
6267
|
+
|
|
6268
|
+
/**
|
|
6269
|
+
* @typedef {import('./index.js').Context} Context
|
|
6270
|
+
*/
|
|
6271
|
+
|
|
6272
|
+
/**
|
|
6273
|
+
* Serialize an attribute value.
|
|
6274
|
+
*
|
|
6275
|
+
* @param {string} value
|
|
6276
|
+
* @param {Context} ctx
|
|
6277
|
+
* @returns {string}
|
|
6278
|
+
*/
|
|
6279
|
+
function value(value, ctx) {
|
|
6280
|
+
var primary = ctx.quote;
|
|
6281
|
+
var secondary = ctx.alternative;
|
|
6282
|
+
var result = String(value);
|
|
6283
|
+
var quote =
|
|
6284
|
+
secondary && ccount(result, primary) > ccount(result, secondary)
|
|
6285
|
+
? secondary
|
|
6286
|
+
: primary;
|
|
6287
|
+
|
|
6288
|
+
return quote + escape(result, ['<', '&', quote]) + quote
|
|
6289
|
+
}
|
|
6290
|
+
|
|
6291
|
+
/**
|
|
6292
|
+
* @typedef {import('./index.js').Handle} Handle
|
|
6293
|
+
* @typedef {import('./index.js').Element} Element
|
|
6294
|
+
* @typedef {import('./index.js').Attributes} Attributes
|
|
6295
|
+
*/
|
|
6296
|
+
|
|
6297
|
+
var own$1 = {}.hasOwnProperty;
|
|
6298
|
+
|
|
6299
|
+
/**
|
|
6300
|
+
* Serialize an element.
|
|
6301
|
+
*
|
|
6302
|
+
* @type {Handle}
|
|
6303
|
+
* @param {Element} node
|
|
6304
|
+
*/
|
|
6305
|
+
function element(node, ctx) {
|
|
6306
|
+
var nodeName = name(node.name);
|
|
6307
|
+
var content = all(node, ctx);
|
|
6308
|
+
/** @type {Attributes} */
|
|
6309
|
+
var attributes = node.attributes || {};
|
|
6310
|
+
var close = content ? false : ctx.close;
|
|
6311
|
+
/** @type {Array.<string>} */
|
|
6312
|
+
var attrs = [];
|
|
6313
|
+
/** @type {string} */
|
|
6314
|
+
var key;
|
|
6315
|
+
/** @type {Attributes[keyof Attributes]} */
|
|
6316
|
+
var result;
|
|
6317
|
+
|
|
6318
|
+
for (key in attributes) {
|
|
6319
|
+
if (own$1.call(attributes, key)) {
|
|
6320
|
+
result = attributes[key];
|
|
6321
|
+
|
|
6322
|
+
if (result !== null && result !== undefined) {
|
|
6323
|
+
attrs.push(name(key) + '=' + value(result, ctx));
|
|
6324
|
+
}
|
|
6325
|
+
}
|
|
6326
|
+
}
|
|
6327
|
+
|
|
6328
|
+
return (
|
|
6329
|
+
'<' +
|
|
6330
|
+
nodeName +
|
|
6331
|
+
(attrs.length === 0 ? '' : ' ' + attrs.join(' ')) +
|
|
6332
|
+
(close ? (ctx.tight ? '' : ' ') + '/' : '') +
|
|
6333
|
+
'>' +
|
|
6334
|
+
content +
|
|
6335
|
+
(close ? '' : '</' + nodeName + '>')
|
|
6336
|
+
)
|
|
6337
|
+
}
|
|
6338
|
+
|
|
6339
|
+
/**
|
|
6340
|
+
* @typedef {import('./index.js').Handle} Handle
|
|
6341
|
+
* @typedef {import('./index.js').Text} Text
|
|
6342
|
+
*/
|
|
6343
|
+
|
|
6344
|
+
var subset$2 = ['&', '<'];
|
|
6345
|
+
|
|
6346
|
+
/**
|
|
6347
|
+
* Serialize a text.
|
|
6348
|
+
*
|
|
6349
|
+
* @type {Handle}
|
|
6350
|
+
* @param {Text} node
|
|
6351
|
+
*/
|
|
6352
|
+
function text(node) {
|
|
6353
|
+
return escape(node.value, subset$2)
|
|
6354
|
+
}
|
|
6355
|
+
|
|
6356
|
+
/**
|
|
6357
|
+
* @typedef {import('./index.js').Handle} Handle
|
|
6358
|
+
* @typedef {import('./index.js').Comment} Comment
|
|
6359
|
+
*/
|
|
6360
|
+
|
|
6361
|
+
/**
|
|
6362
|
+
* Serialize a comment.
|
|
6363
|
+
*
|
|
6364
|
+
* @type {Handle}
|
|
6365
|
+
* @param {Comment} node
|
|
6366
|
+
*/
|
|
6367
|
+
function comment(node) {
|
|
6368
|
+
return '<!--' + escape(node.value, ['-']) + '-->'
|
|
6369
|
+
}
|
|
6370
|
+
|
|
6371
|
+
/**
|
|
6372
|
+
* @typedef {import('./index.js').Handle} Handle
|
|
6373
|
+
* @typedef {import('./index.js').Doctype} Doctype
|
|
6374
|
+
*/
|
|
6375
|
+
|
|
6376
|
+
/**
|
|
6377
|
+
* Serialize a doctype.
|
|
6378
|
+
*
|
|
6379
|
+
* @type {Handle}
|
|
6380
|
+
* @param {Doctype} node
|
|
6381
|
+
*/
|
|
6382
|
+
function doctype(node, ctx) {
|
|
6383
|
+
var nodeName = name(node.name);
|
|
6384
|
+
var pub = node.public;
|
|
6385
|
+
var sys = node.system;
|
|
6386
|
+
var result = '<!DOCTYPE';
|
|
6387
|
+
|
|
6388
|
+
if (nodeName !== '') {
|
|
6389
|
+
result += ' ' + nodeName;
|
|
6390
|
+
}
|
|
6391
|
+
|
|
6392
|
+
if (pub !== null && pub !== undefined && pub !== '') {
|
|
6393
|
+
result += ' PUBLIC ' + value(pub, ctx);
|
|
6394
|
+
} else if (sys !== null && sys !== undefined && sys !== '') {
|
|
6395
|
+
result += ' SYSTEM';
|
|
6396
|
+
}
|
|
6397
|
+
|
|
6398
|
+
if (sys !== null && sys !== undefined && sys !== '') {
|
|
6399
|
+
result += ' ' + value(sys, ctx);
|
|
6400
|
+
}
|
|
6401
|
+
|
|
6402
|
+
return result + '>'
|
|
6403
|
+
}
|
|
6404
|
+
|
|
6405
|
+
/**
|
|
6406
|
+
* @typedef {import('./index.js').Handle} Handle
|
|
6407
|
+
* @typedef {import('./index.js').Instruction} Instruction
|
|
6408
|
+
*/
|
|
6409
|
+
|
|
6410
|
+
var unsafe$1 = /\?>/g;
|
|
6411
|
+
var subset$1 = ['>'];
|
|
6412
|
+
|
|
6413
|
+
/**
|
|
6414
|
+
* Serialize an instruction.
|
|
6415
|
+
*
|
|
6416
|
+
* @type {Handle}
|
|
6417
|
+
* @param {Instruction} node
|
|
6418
|
+
*/
|
|
6419
|
+
function instruction(node) {
|
|
6420
|
+
var nodeName = name(node.name) || 'x';
|
|
6421
|
+
var result = escape(node.value, subset$1, unsafe$1);
|
|
6422
|
+
return '<?' + nodeName + (result ? ' ' + result : '') + '?>'
|
|
6423
|
+
}
|
|
6424
|
+
|
|
6425
|
+
/**
|
|
6426
|
+
* @typedef {import('./index.js').Handle} Handle
|
|
6427
|
+
* @typedef {import('./index.js').Cdata} Cdata
|
|
6428
|
+
*/
|
|
6429
|
+
|
|
6430
|
+
var unsafe = /]]>/g;
|
|
6431
|
+
var subset = ['>'];
|
|
6432
|
+
|
|
6433
|
+
/**
|
|
6434
|
+
* Serialize a CDATA section.
|
|
6435
|
+
*
|
|
6436
|
+
* @type {Handle}
|
|
6437
|
+
* @param {Cdata} node
|
|
6438
|
+
*/
|
|
6439
|
+
function cdata(node) {
|
|
6440
|
+
return '<![CDATA[' + escape(node.value, subset, unsafe) + ']]>'
|
|
6441
|
+
}
|
|
6442
|
+
|
|
6443
|
+
/**
|
|
6444
|
+
* @typedef {import('./index.js').Handle} Handle
|
|
6445
|
+
* @typedef {import('./index.js').Raw} Raw
|
|
6446
|
+
*/
|
|
6447
|
+
|
|
6448
|
+
/**
|
|
6449
|
+
* Serialize a (non-standard) raw.
|
|
6450
|
+
*
|
|
6451
|
+
* @type {Handle}
|
|
6452
|
+
* @param {Raw} node
|
|
6453
|
+
*/
|
|
6454
|
+
function raw(node, ctx) {
|
|
6455
|
+
// @ts-ignore Looks like a text.
|
|
6456
|
+
return ctx.dangerous ? node.value : text(node)
|
|
6457
|
+
}
|
|
6458
|
+
|
|
6459
|
+
/**
|
|
6460
|
+
* @typedef {import('./index.js').Handle} Handle
|
|
6461
|
+
*/
|
|
6462
|
+
|
|
6463
|
+
var own = {}.hasOwnProperty;
|
|
6464
|
+
|
|
6465
|
+
var handlers = {
|
|
6466
|
+
root: all,
|
|
6467
|
+
element,
|
|
6468
|
+
text,
|
|
6469
|
+
comment,
|
|
6470
|
+
doctype,
|
|
6471
|
+
instruction,
|
|
6472
|
+
cdata,
|
|
6473
|
+
raw
|
|
6474
|
+
};
|
|
6475
|
+
|
|
6476
|
+
/**
|
|
6477
|
+
* Serialize a node.
|
|
6478
|
+
*
|
|
6479
|
+
* @type {Handle}
|
|
6480
|
+
*/
|
|
6481
|
+
function one(node, ctx) {
|
|
6482
|
+
var type = node && node.type;
|
|
6483
|
+
|
|
6484
|
+
if (!type) {
|
|
6485
|
+
throw new Error('Expected node, not `' + node + '`')
|
|
6486
|
+
}
|
|
6487
|
+
|
|
6488
|
+
if (!own.call(handlers, type)) {
|
|
6489
|
+
throw new Error('Cannot compile unknown node `' + type + '`')
|
|
6490
|
+
}
|
|
6491
|
+
|
|
6492
|
+
// @ts-ignore Hush, it works.
|
|
6493
|
+
return handlers[type](node, ctx)
|
|
6494
|
+
}
|
|
6495
|
+
|
|
6496
|
+
/**
|
|
6497
|
+
* @typedef {import('xast').Root} Root
|
|
6498
|
+
* @typedef {import('xast').Element} Element
|
|
6499
|
+
* @typedef {import('xast').Cdata} Cdata
|
|
6500
|
+
* @typedef {import('xast').Comment} Comment
|
|
6501
|
+
* @typedef {import('xast').Doctype} Doctype
|
|
6502
|
+
* @typedef {import('xast').Instruction} Instruction
|
|
6503
|
+
* @typedef {import('xast').Text} Text
|
|
6504
|
+
* @typedef {import('xast').Literal & {type: 'raw'}} Raw
|
|
6505
|
+
* @typedef {Root|Element} Parent
|
|
6506
|
+
* @typedef {import('xast').Attributes} Attributes
|
|
6507
|
+
* @typedef {Root['children'][number]} Child
|
|
6508
|
+
* @typedef {Child|Root} Node
|
|
6509
|
+
*
|
|
6510
|
+
* @typedef {'"'|"'"} Quote
|
|
6511
|
+
*
|
|
6512
|
+
* @typedef Options
|
|
6513
|
+
* @property {Quote} [quote='"'] Preferred quote to use
|
|
6514
|
+
* @property {boolean} [quoteSmart=false] Use the other quote if that results in
|
|
6515
|
+
* less bytes
|
|
6516
|
+
* @property {boolean} [closeEmptyElements=false] Close elements without any
|
|
6517
|
+
* content with slash (/) on the opening tag instead of an end tag:
|
|
6518
|
+
* `<circle />` instead of `<circle></circle>`.
|
|
6519
|
+
* See `tightClose` to control whether a space is used before the slash.
|
|
6520
|
+
* @property {boolean} [tightClose=false] Do not use an extra space when closing
|
|
6521
|
+
* self-closing elements: `<circle/>` instead of `<circle />`.
|
|
6522
|
+
* @property {boolean} [allowDangerousXml=false] Allow `raw` nodes and insert
|
|
6523
|
+
* them as raw XML. When falsey, encodes `raw` nodes.
|
|
6524
|
+
* Only set this if you completely trust the content!
|
|
6525
|
+
*
|
|
6526
|
+
* @typedef Context
|
|
6527
|
+
* @property {Quote} quote
|
|
6528
|
+
* @property {Quote} alternative
|
|
6529
|
+
* @property {boolean} close
|
|
6530
|
+
* @property {boolean} tight
|
|
6531
|
+
* @property {boolean} dangerous
|
|
6532
|
+
*
|
|
6533
|
+
* @callback Handle
|
|
6534
|
+
* @param {Node} node
|
|
6535
|
+
* @param {Context} context
|
|
6536
|
+
* @returns {string}
|
|
6537
|
+
*/
|
|
6538
|
+
|
|
6539
|
+
/**
|
|
6540
|
+
* Serialize the given xast tree (or list of nodes).
|
|
6541
|
+
*
|
|
6542
|
+
* @param {Node|Array.<Node>} node
|
|
6543
|
+
* @param {Options} [options]
|
|
6544
|
+
* @returns {string}
|
|
6545
|
+
*/
|
|
6546
|
+
function toXml(node, options = {}) {
|
|
6547
|
+
var quote = options.quote || '"';
|
|
6548
|
+
/** @type {Quote} */
|
|
6549
|
+
var alternative = quote === '"' ? "'" : '"';
|
|
6550
|
+
var smart = options.quoteSmart;
|
|
6551
|
+
/** @type {Node} */
|
|
6552
|
+
// @ts-ignore Assume no `root` in `node`.
|
|
6553
|
+
var value = Array.isArray(node) ? {type: 'root', children: node} : node;
|
|
6554
|
+
|
|
6555
|
+
if (quote !== '"' && quote !== "'") {
|
|
6556
|
+
throw new Error('Invalid quote `' + quote + '`, expected `\'` or `"`')
|
|
6557
|
+
}
|
|
6558
|
+
|
|
6559
|
+
return one(value, {
|
|
6560
|
+
dangerous: options.allowDangerousXml,
|
|
6561
|
+
close: options.closeEmptyElements,
|
|
6562
|
+
tight: options.tightClose,
|
|
6563
|
+
quote,
|
|
6564
|
+
alternative: smart ? alternative : null
|
|
6565
|
+
})
|
|
6566
|
+
}
|
|
6567
|
+
|
|
6568
|
+
const BR = u('text', '\n');
|
|
6569
|
+
const TAB = u('text', ' ');
|
|
6570
|
+
/**
|
|
6571
|
+
* Convert nested folder structure to KML. This expects
|
|
6572
|
+
* input that follows the same patterns as [toGeoJSON](https://github.com/placemark/togeojson)'s
|
|
6573
|
+
* kmlWithFolders method: a tree of folders and features,
|
|
6574
|
+
* starting with a root element.
|
|
6575
|
+
*/
|
|
6576
|
+
function foldersToKML(root) {
|
|
6577
|
+
return toXml(u('root', [
|
|
6578
|
+
x('kml', { xmlns: 'http://www.opengis.net/kml/2.2' }, x('Document', root.children.flatMap((child) => convertChild(child)))),
|
|
6579
|
+
]));
|
|
6580
|
+
}
|
|
6581
|
+
/**
|
|
6582
|
+
* Convert a GeoJSON FeatureCollection to a string of
|
|
6583
|
+
* KML data.
|
|
6584
|
+
*/
|
|
6585
|
+
function toKML(featureCollection) {
|
|
6586
|
+
return toXml(u('root', [
|
|
6587
|
+
x('kml', { xmlns: 'http://www.opengis.net/kml/2.2' }, x('Document', featureCollection.features.flatMap((feature) => convertFeature(feature)))),
|
|
6588
|
+
]));
|
|
6589
|
+
}
|
|
6590
|
+
function convertChild(child) {
|
|
6591
|
+
switch (child.type) {
|
|
6592
|
+
case 'Feature':
|
|
6593
|
+
return convertFeature(child);
|
|
6594
|
+
case 'folder':
|
|
6595
|
+
return convertFolder(child);
|
|
6596
|
+
}
|
|
6597
|
+
}
|
|
6598
|
+
function convertFolder(folder) {
|
|
6599
|
+
const id = ['string', 'number'].includes(typeof folder.meta.id)
|
|
6600
|
+
? {
|
|
6601
|
+
id: String(folder.meta.id),
|
|
6602
|
+
}
|
|
6603
|
+
: {};
|
|
6604
|
+
return [
|
|
6605
|
+
BR,
|
|
6606
|
+
x('Folder', id, [
|
|
6607
|
+
BR,
|
|
6608
|
+
...folderMeta(folder.meta),
|
|
6609
|
+
BR,
|
|
6610
|
+
TAB,
|
|
6611
|
+
...folder.children.flatMap((child) => convertChild(child)),
|
|
6612
|
+
]),
|
|
6613
|
+
];
|
|
6614
|
+
}
|
|
6615
|
+
const META_PROPERTIES = [
|
|
6616
|
+
'address',
|
|
6617
|
+
'description',
|
|
6618
|
+
'name',
|
|
6619
|
+
'open',
|
|
6620
|
+
'visibility',
|
|
6621
|
+
'phoneNumber',
|
|
6622
|
+
];
|
|
6623
|
+
function folderMeta(meta) {
|
|
6624
|
+
return META_PROPERTIES.filter((p) => meta[p] !== undefined).map((p) => {
|
|
6625
|
+
return x(p, [u('text', String(meta[p]))]);
|
|
6626
|
+
});
|
|
6627
|
+
}
|
|
6628
|
+
function convertFeature(feature) {
|
|
6629
|
+
const { id } = feature;
|
|
6630
|
+
const idMember = ['string', 'number'].includes(typeof id)
|
|
6631
|
+
? {
|
|
6632
|
+
id: id,
|
|
6633
|
+
}
|
|
6634
|
+
: {};
|
|
6635
|
+
return [
|
|
6636
|
+
BR,
|
|
6637
|
+
x('Placemark', idMember, [
|
|
6638
|
+
BR,
|
|
6639
|
+
...propertiesToTags(feature.properties),
|
|
6640
|
+
BR,
|
|
6641
|
+
TAB,
|
|
6642
|
+
...(feature.geometry ? [convertGeometry(feature.geometry)] : []),
|
|
6643
|
+
]),
|
|
6644
|
+
];
|
|
6645
|
+
}
|
|
6646
|
+
function join(position) {
|
|
6647
|
+
return `${position[0]},${position[1]}`;
|
|
6648
|
+
}
|
|
6649
|
+
function coord1(coordinates) {
|
|
6650
|
+
return x('coordinates', [u('text', join(coordinates))]);
|
|
6651
|
+
}
|
|
6652
|
+
function coord2(coordinates) {
|
|
6653
|
+
return x('coordinates', [u('text', coordinates.map(join).join('\n'))]);
|
|
6654
|
+
}
|
|
6655
|
+
function toString(value) {
|
|
6656
|
+
switch (typeof value) {
|
|
6657
|
+
case 'string': {
|
|
6658
|
+
return value;
|
|
6659
|
+
}
|
|
6660
|
+
case 'boolean':
|
|
6661
|
+
case 'number': {
|
|
6662
|
+
return String(value);
|
|
6663
|
+
}
|
|
6664
|
+
case 'object': {
|
|
6665
|
+
try {
|
|
6666
|
+
return JSON.stringify(value);
|
|
6667
|
+
}
|
|
6668
|
+
catch (e) {
|
|
6669
|
+
return '';
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
}
|
|
6673
|
+
return '';
|
|
6674
|
+
}
|
|
6675
|
+
function maybeCData(value) {
|
|
6676
|
+
if (value &&
|
|
6677
|
+
typeof value === 'object' &&
|
|
6678
|
+
'@type' in value &&
|
|
6679
|
+
value['@type'] === 'html' &&
|
|
6680
|
+
'value' in value &&
|
|
6681
|
+
typeof value.value === 'string') {
|
|
6682
|
+
return u('cdata', value.value);
|
|
6683
|
+
}
|
|
6684
|
+
return toString(value);
|
|
6685
|
+
}
|
|
6686
|
+
function propertiesToTags(properties) {
|
|
6687
|
+
if (!properties)
|
|
6688
|
+
return [];
|
|
6689
|
+
const { name, description, visibility, ...otherProperties } = properties;
|
|
6690
|
+
return [
|
|
6691
|
+
name && x('name', [u('text', toString(name))]),
|
|
6692
|
+
description && x('description', [u('text', maybeCData(description))]),
|
|
6693
|
+
visibility !== undefined &&
|
|
6694
|
+
x('visibility', [u('text', visibility ? '1' : '0')]),
|
|
6695
|
+
x('ExtendedData', Object.entries(otherProperties).flatMap(([name, value]) => [
|
|
6696
|
+
BR,
|
|
6697
|
+
TAB,
|
|
6698
|
+
x('Data', { name: name }, [
|
|
6699
|
+
x('value', [
|
|
6700
|
+
u('text', typeof value === 'string' ? value : JSON.stringify(value)),
|
|
6701
|
+
]),
|
|
6702
|
+
]),
|
|
6703
|
+
])),
|
|
6704
|
+
].filter(Boolean);
|
|
6705
|
+
}
|
|
6706
|
+
const linearRing = (ring) => x('LinearRing', [coord2(ring)]);
|
|
6707
|
+
function convertMultiPoint(geometry) {
|
|
6708
|
+
return x('MultiGeometry', geometry.coordinates.flatMap((coordinates) => [
|
|
6709
|
+
BR,
|
|
6710
|
+
convertGeometry({
|
|
6711
|
+
type: 'Point',
|
|
6712
|
+
coordinates,
|
|
6713
|
+
}),
|
|
6714
|
+
]));
|
|
6715
|
+
}
|
|
6716
|
+
function convertMultiLineString(geometry) {
|
|
6717
|
+
return x('MultiGeometry', geometry.coordinates.flatMap((coordinates) => [
|
|
6718
|
+
BR,
|
|
6719
|
+
convertGeometry({
|
|
6720
|
+
type: 'LineString',
|
|
6721
|
+
coordinates,
|
|
6722
|
+
}),
|
|
6723
|
+
]));
|
|
6724
|
+
}
|
|
6725
|
+
function convertMultiPolygon(geometry) {
|
|
6726
|
+
return x('MultiGeometry', geometry.coordinates.flatMap((coordinates) => [
|
|
6727
|
+
BR,
|
|
6728
|
+
convertGeometry({
|
|
6729
|
+
type: 'Polygon',
|
|
6730
|
+
coordinates,
|
|
6731
|
+
}),
|
|
6732
|
+
]));
|
|
6733
|
+
}
|
|
6734
|
+
function convertPolygon(geometry) {
|
|
6735
|
+
const [outerBoundary, ...innerRings] = geometry.coordinates;
|
|
6736
|
+
return x('Polygon', [
|
|
6737
|
+
BR,
|
|
6738
|
+
x('outerBoundaryIs', [BR, TAB, linearRing(outerBoundary)]),
|
|
6739
|
+
...innerRings.flatMap((innerRing) => [
|
|
6740
|
+
BR,
|
|
6741
|
+
x('innerBoundaryIs', [BR, TAB, linearRing(innerRing)]),
|
|
6742
|
+
]),
|
|
6743
|
+
]);
|
|
6744
|
+
}
|
|
6745
|
+
function convertGeometry(geometry) {
|
|
6746
|
+
switch (geometry.type) {
|
|
6747
|
+
case 'Point':
|
|
6748
|
+
return x('Point', [coord1(geometry.coordinates)]);
|
|
6749
|
+
case 'MultiPoint':
|
|
6750
|
+
return convertMultiPoint(geometry);
|
|
6751
|
+
case 'LineString':
|
|
6752
|
+
return x('LineString', [coord2(geometry.coordinates)]);
|
|
6753
|
+
case 'MultiLineString':
|
|
6754
|
+
return convertMultiLineString(geometry);
|
|
6755
|
+
case 'Polygon':
|
|
6756
|
+
return convertPolygon(geometry);
|
|
6757
|
+
case 'MultiPolygon':
|
|
6758
|
+
return convertMultiPolygon(geometry);
|
|
6759
|
+
case 'GeometryCollection':
|
|
6760
|
+
return x('MultiGeometry', geometry.geometries.flatMap((geometry) => [
|
|
6761
|
+
BR,
|
|
6762
|
+
convertGeometry(geometry),
|
|
6763
|
+
]));
|
|
6764
|
+
}
|
|
6765
|
+
}
|
|
6766
|
+
|
|
6767
|
+
exports.foldersToKML = foldersToKML;
|
|
6768
|
+
exports.toKML = toKML;
|
|
6769
|
+
|
|
6770
|
+
|
|
6771
|
+
},{}],"@tmcw/togeojson":[function(require,module,exports){
|
|
6772
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).toGeoJSON={})}(this,(function(t){"use strict";function e(t,e){return Array.from(t.getElementsByTagName(e))}function n(t){return"#"===t[0]?t:`#${t}`}function o(t){return t?.normalize(),t&&t.textContent||""}function r(t,e,n){const o=t.getElementsByTagName(e),r=o.length?o[0]:null;return r&&n&&n(r),r}function i(t,e,n){const o={};if(!t)return o;const r=t.getElementsByTagName(e),i=r.length?r[0]:null;return i&&n?n(i,o):o}function s(t,e,n){const i=o(r(t,e));return i&&n&&n(i)||{}}function c(t,e,n){const i=parseFloat(o(r(t,e)));if(!isNaN(i))return i&&n&&n(i)||{}}function a(t,e,n){const i=parseFloat(o(r(t,e)));if(!isNaN(i))return i&&n&&n(i),i}function l(t,e){const n={};for(const o of e)s(t,o,(t=>{n[o]=t}));return n}function u(t){return 1===t?.nodeType}function f(t){return i(t,"line",(t=>Object.assign({},s(t,"color",(t=>({stroke:`#${t}`}))),c(t,"opacity",(t=>({"stroke-opacity":t}))),c(t,"width",(t=>({"stroke-width":96*t/25.4}))))))}function p(t){let e=[];if(null===t)return e;for(const n of Array.from(t.childNodes)){if(!u(n))continue;const t=g(n.nodeName);if("gpxtpx:TrackPointExtension"===t)e=e.concat(p(n));else{const r=o(n);e.push([t,d(r)])}}return e}function g(t){return["heart","gpxtpx:hr","hr"].includes(t)?"heart":t}function d(t){const e=parseFloat(t);return isNaN(e)?t:e}function h(t){const e=[parseFloat(t.getAttribute("lon")||""),parseFloat(t.getAttribute("lat")||"")];if(isNaN(e[0])||isNaN(e[1]))return null;a(t,"ele",(t=>{e.push(t)}));const n=r(t,"time");return{coordinates:e,time:n?o(n):null,extendedValues:p(r(t,"extensions"))}}function m(t){const n=l(t,["name","cmt","desc","type","time","keywords"]),r=Array.from(t.getElementsByTagNameNS("http://www.garmin.com/xmlschemas/GpxExtensions/v3","*"));for(const e of r)e.parentNode?.parentNode===t&&(n[e.tagName.replace(":","_")]=o(e));const i=e(t,"link");return i.length&&(n.links=i.map((t=>Object.assign({href:t.getAttribute("href")},l(t,["text","type"]))))),n}function y(t,n){const o=e(t,n),r=[],i=[],s={};for(let t=0;t<o.length;t++){const e=h(o[t]);if(e){r.push(e.coordinates),e.time&&i.push(e.time);for(const[n,r]of e.extendedValues){const e="heart"===n?n:n.replace("gpxtpx:","")+"s";s[e]||(s[e]=Array(o.length).fill(null)),s[e][t]=r}}}if(!(r.length<2))return{line:r,times:i,extendedValues:s}}function b(t){const e=y(t,"rtept");if(e)return{type:"Feature",properties:Object.assign({_gpxType:"rte"},m(t),f(r(t,"extensions"))),geometry:{type:"LineString",coordinates:e.line}}}function N(t){const n=e(t,"trkseg"),o=[],i=[],s=[];for(const t of n){const e=y(t,"trkpt");e&&(s.push(e),e.times&&e.times.length&&i.push(e.times))}if(0===s.length)return null;const c=s.length>1,a=Object.assign({_gpxType:"trk"},m(t),f(r(t,"extensions")),i.length?{coordinateProperties:{times:c?i:i[0]}}:{});for(const t of s){o.push(t.line),a.coordinateProperties||(a.coordinateProperties={});const e=a.coordinateProperties,n=Object.entries(t.extendedValues);for(let t=0;t<n.length;t++){const[o,r]=n[t];c?(e[o]||(e[o]=s.map((t=>new Array(t.line.length).fill(null)))),e[o][t]=r):e[o]=r}}return{type:"Feature",properties:a,geometry:c?{type:"MultiLineString",coordinates:o}:{type:"LineString",coordinates:o[0]}}}function x(t){const e=Object.assign(m(t),l(t,["sym"])),n=h(t);return n?{type:"Feature",properties:e,geometry:{type:"Point",coordinates:n.coordinates}}:null}function*k(t){for(const n of e(t,"trk")){const t=N(n);t&&(yield t)}for(const n of e(t,"rte")){const t=b(n);t&&(yield t)}for(const n of e(t,"wpt")){const t=x(n);t&&(yield t)}}const A=[["heartRate","heartRates"],["Cadence","cadences"],["Speed","speeds"],["Watts","watts"]],S=[["TotalTimeSeconds","totalTimeSeconds"],["DistanceMeters","distanceMeters"],["MaximumSpeed","maxSpeed"],["AverageHeartRateBpm","avgHeartRate"],["MaximumHeartRateBpm","maxHeartRate"],["AvgSpeed","avgSpeed"],["AvgWatts","avgWatts"],["MaxWatts","maxWatts"]];function v(t,e){const n=[];for(const[i,s]of e){let e=r(t,i);if(!e){const n=t.getElementsByTagNameNS("http://www.garmin.com/xmlschemas/ActivityExtension/v2",i);n.length&&(e=n[0])}const c=parseFloat(o(e));isNaN(c)||n.push([s,c])}return n}function T(t){const e=[a(t,"LongitudeDegrees"),a(t,"LatitudeDegrees")];if(void 0===e[0]||isNaN(e[0])||void 0===e[1]||isNaN(e[1]))return null;const n=r(t,"HeartRateBpm"),i=o(r(t,"Time"));return r(t,"AltitudeMeters",(t=>{const n=parseFloat(o(t));isNaN(n)||e.push(n)})),{coordinates:e,time:i||null,heartRate:n?parseFloat(o(n)):null,extensions:v(t,A)}}function F(t){const n=e(t,"Trackpoint"),o=[],r=[],i=[];if(n.length<2)return null;const s={},c={extendedProperties:s};for(let t=0;t<n.length;t++){const e=T(n[t]);if(null===e)continue;o.push(e.coordinates);const{time:c,heartRate:a,extensions:l}=e;c&&r.push(c),a&&i.push(a);for(const[e,o]of l)s[e]||(s[e]=Array(n.length).fill(null)),s[e][t]=o}return o.length<2?null:Object.assign(c,{line:o,times:r,heartRates:i})}function P(t){const n=e(t,"Track"),r=[],s=[],c=[],a=[];let l;const u=Object.assign(Object.fromEntries(v(t,S)),i(t,"Name",(t=>({name:o(t)}))));for(const t of n)l=F(t),l&&(r.push(l.line),l.times.length&&s.push(l.times),l.heartRates.length&&c.push(l.heartRates),a.push(l.extendedProperties));for(let t=0;t<a.length;t++){const e=a[t];for(const o in e)1===n.length?l&&(u[o]=l.extendedProperties[o]):(u[o]||(u[o]=r.map((t=>Array(t.length).fill(null)))),u[o][t]=e[o])}return 0===r.length?null:((s.length||c.length)&&(u.coordinateProperties=Object.assign(s.length?{times:1===r.length?s[0]:s}:{},c.length?{heart:1===r.length?c[0]:c}:{})),{type:"Feature",properties:u,geometry:1===r.length?{type:"LineString",coordinates:r[0]}:{type:"MultiLineString",coordinates:r}})}function*O(t){for(const n of e(t,"Lap")){const t=P(n);t&&(yield t)}for(const n of e(t,"Courses")){const t=P(n);t&&(yield t)}}function w(t,e){const n={},o="stroke"==e||"fill"===e?e:e+"-color";return"#"===t[0]&&(t=t.substring(1)),6===t.length||3===t.length?n[o]="#"+t:8===t.length&&(n[e+"-opacity"]=parseInt(t.substring(0,2),16)/255,n[o]="#"+t.substring(6,8)+t.substring(4,6)+t.substring(2,4)),n}function M(t,e,n){const o={};return a(t,e,(t=>{o[n]=t})),o}function j(t,e){return i(t,"color",(t=>w(o(t),e)))}function L(t){return i(t,"Icon",((t,e)=>(s(t,"href",(t=>{e.icon=t})),e)))}function R(t){return Object.assign({},function(t){return i(t,"PolyStyle",((t,e)=>Object.assign(e,i(t,"color",(t=>w(o(t),"fill"))),s(t,"fill",(t=>{if("0"===t)return{"fill-opacity":0}})),s(t,"outline",(t=>{if("0"===t)return{"stroke-opacity":0}})))))}(t),function(t){return i(t,"LineStyle",(t=>Object.assign(j(t,"stroke"),M(t,"width","stroke-width"))))}(t),function(t){return i(t,"LabelStyle",(t=>Object.assign(j(t,"label"),M(t,"scale","label-scale"))))}(t),function(t){return i(t,"IconStyle",(t=>Object.assign(j(t,"icon"),M(t,"scale","icon-scale"),M(t,"heading","icon-heading"),i(t,"hotSpot",(t=>{const e=parseFloat(t.getAttribute("x")||""),n=parseFloat(t.getAttribute("y")||""),o=t.getAttribute("xunits")||"",r=t.getAttribute("yunits")||"";return isNaN(e)||isNaN(n)?{}:{"icon-offset":[e,n],"icon-offset-units":[o,r]}})),L(t))))}(t))}const B=t=>Number(t),E={string:t=>t,int:B,uint:B,short:B,ushort:B,float:B,double:B,bool:t=>Boolean(t)};function G(t,n){return i(t,"ExtendedData",((t,i)=>{for(const n of e(t,"Data"))i[n.getAttribute("name")||""]=o(r(n,"value"));for(const r of e(t,"SimpleData")){const t=r.getAttribute("name")||"",e=n[t]||E.string;i[t]=e(o(r))}return i}))}function C(t){const e=r(t,"description");for(const t of Array.from(e?.childNodes||[]))if(4===t.nodeType)return{description:{"@type":"html",value:o(t)}};return{}}function D(t){return i(t,"TimeSpan",(t=>({timespan:{begin:o(r(t,"begin")),end:o(r(t,"end"))}})))}function W(t){return i(t,"TimeStamp",(t=>({timestamp:o(r(t,"when"))})))}function H(t,e){return s(t,"styleUrl",(t=>(t=n(t),e[t]?Object.assign({styleUrl:t},e[t]):{styleUrl:t})))}const _=/\s*/g,I=/^\s*|\s*$/g,U=/\s+/;function V(t){return t.replace(_,"").split(",").map(parseFloat).filter((t=>!isNaN(t))).slice(0,3)}function $(t){return t.replace(I,"").split(U).map(V).filter((t=>t.length>=2))}function q(t){let n=e(t,"coord");var r,i,s;0===n.length&&(r=t,i="coord",s="*",n=Array.from(r.getElementsByTagNameNS(s,i)));const c=n.map((t=>o(t).split(" ").map(parseFloat)));return 0===c.length?null:{geometry:c.length>2?{type:"LineString",coordinates:c}:{type:"Point",coordinates:c[0]},times:e(t,"when").map((t=>o(t)))}}function z(t){if(0===t.length)return t;const e=t[0],n=t[t.length-1];let o=!0;for(let t=0;t<Math.max(e.length,n.length);t++)if(e[t]!==n[t]){o=!1;break}return o?t:t.concat([t[0]])}function J(t){return o(r(t,"coordinates"))}function Q(t){let n=[],o=[];for(let r=0;r<t.childNodes.length;r++){const i=t.childNodes.item(r);if(u(i))switch(i.tagName){case"MultiGeometry":case"MultiTrack":case"gx:MultiTrack":{const t=Q(i);n=n.concat(t.geometries),o=o.concat(t.coordTimes);break}case"Point":{const t=V(J(i));t.length>=2&&n.push({type:"Point",coordinates:t});break}case"LineString":{const t=$(J(i));t.length>=2&&n.push({type:"LineString",coordinates:t});break}case"Polygon":{const t=[];for(const n of e(i,"LinearRing")){const e=z($(J(n)));e.length>=4&&t.push(e)}t.length&&n.push({type:"Polygon",coordinates:t});break}case"Track":case"gx:Track":{const t=q(i);if(!t)break;const{times:e,geometry:r}=t;n.push(r),e.length&&o.push(e);break}}}return{geometries:n,coordTimes:o}}function K(t){return 0===t.length?null:1===t.length?t[0]:{type:"GeometryCollection",geometries:t}}function X(t,e,n){const{coordTimes:o,geometries:r}=Q(t),i={type:"Feature",geometry:K(r),properties:Object.assign(l(t,["name","address","visibility","open","phoneNumber","description"]),C(t),H(t,e),R(t),G(t,n),D(t),W(t),o.length?{coordinateProperties:{times:1===o.length?o[0]:o}}:{})};void 0!==i.properties?.visibility&&(i.properties.visibility="0"!==i.properties.visibility);const s=t.getAttribute("id");return null!==s&&""!==s&&(i.id=s),i}function Y(t){if(r(t,"gx:LatLonQuad")){return{type:"Polygon",coordinates:[z($(J(t)))]}}return function(t){const e=r(t,"LatLonBox");if(e){const t=a(e,"north"),n=a(e,"west"),o=a(e,"east"),r=a(e,"south"),i=a(e,"rotation");if("number"==typeof t&&"number"==typeof r&&"number"==typeof n&&"number"==typeof o){const e=[n,r,o,t];let s=[[[n,t],[o,t],[o,r],[n,r],[n,t]]];return"number"==typeof i&&(s=function(t,e,n){const o=[(t[0]+t[2])/2,(t[1]+t[3])/2];return[e[0].map((t=>{const e=t[1]-o[1],r=t[0]-o[0],i=Math.sqrt(Math.pow(e,2)+Math.pow(r,2)),s=Math.atan2(e,r)-n*Z;return[o[0]+Math.cos(s)*i,o[1]+Math.sin(s)*i]}))]}(e,s,i)),{type:"Polygon",coordinates:s}}}return null}(t)}const Z=Math.PI/180;function tt(t,e,n){const o={type:"Feature",geometry:Y(t),properties:Object.assign({"@geometry-type":"groundoverlay"},l(t,["name","address","visibility","open","phoneNumber","description"]),C(t),H(t,e),R(t),L(t),G(t,n),D(t),W(t))};void 0!==o.properties?.visibility&&(o.properties.visibility="0"!==o.properties.visibility);const r=t.getAttribute("id");return null!==r&&""!==r&&(o.id=r),o}function et(t){let e=t.getAttribute("id");const o=t.parentNode;return!e&&u(o)&&"CascadingStyle"===o.localName&&(e=o.getAttribute("kml:id")||o.getAttribute("id")),n(e||"")}function nt(t){const o={};for(const n of e(t,"Style"))o[et(n)]=R(n);for(const r of e(t,"StyleMap")){const t=n(r.getAttribute("id")||"");s(r,"styleUrl",(e=>{e=n(e),o[e]&&(o[t]=o[e])}))}return o}function ot(t){const n={};for(const o of e(t,"SimpleField"))n[o.getAttribute("name")||""]=E[o.getAttribute("type")||""]||E.string;return n}const rt=["name","visibility","open","address","description","phoneNumber","visibility"];function*it(t){const n=nt(t),o=ot(t);for(const r of e(t,"Placemark")){const t=X(r,n,o);t&&(yield t)}for(const r of e(t,"GroundOverlay")){const t=tt(r,n,o);t&&(yield t)}}t.gpx=function(t){return{type:"FeatureCollection",features:Array.from(k(t))}},t.gpxGen=k,t.kml=function(t){return{type:"FeatureCollection",features:Array.from(it(t))}},t.kmlGen=it,t.kmlWithFolders=function(t){const e=nt(t),n=ot(t),r={type:"root",children:[]};return function t(r,i){if(u(r))switch(r.tagName){case"GroundOverlay":{const t=tt(r,e,n);t&&i.children.push(t);break}case"Placemark":{const t=X(r,e,n);t&&i.children.push(t);break}case"Folder":{const t=function(t){const e={};for(const n of Array.from(t.childNodes))u(n)&&rt.includes(n.tagName)&&(e[n.tagName]=o(n));return{type:"folder",meta:e,children:[]}}(r);i.children.push(t),i=t;break}}if(r.childNodes)for(let e=0;e<r.childNodes.length;e++)t(r.childNodes[e],i)}(t,r),r},t.tcx=function(t){return{type:"FeatureCollection",features:Array.from(O(t))}},t.tcxGen=O,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
5871
6773
|
|
|
5872
6774
|
|
|
5873
6775
|
},{}],"buffer":[function(require,module,exports){
|