umap-project 2.4.1__py3-none-any.whl → 2.5.0__py3-none-any.whl
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.
- umap/__init__.py +1 -1
- umap/locale/el/LC_MESSAGES/django.mo +0 -0
- umap/locale/el/LC_MESSAGES/django.po +145 -90
- umap/locale/en/LC_MESSAGES/django.po +13 -13
- umap/locale/eu/LC_MESSAGES/django.mo +0 -0
- umap/locale/eu/LC_MESSAGES/django.po +145 -89
- umap/locale/hu/LC_MESSAGES/django.mo +0 -0
- umap/locale/hu/LC_MESSAGES/django.po +100 -50
- umap/static/umap/base.css +5 -2
- umap/static/umap/content.css +2 -2
- umap/static/umap/css/contextmenu.css +11 -0
- umap/static/umap/css/dialog.css +25 -4
- umap/static/umap/css/importers.css +2 -0
- umap/static/umap/css/panel.css +6 -4
- umap/static/umap/css/slideshow.css +69 -0
- umap/static/umap/css/tableeditor.css +69 -0
- umap/static/umap/css/tooltip.css +3 -3
- umap/static/umap/img/16-white.svg +4 -0
- umap/static/umap/img/source/16-white.svg +5 -1
- umap/static/umap/js/components/alerts/alert.css +11 -11
- umap/static/umap/js/components/alerts/alert.js +1 -1
- umap/static/umap/js/modules/autocomplete.js +27 -5
- umap/static/umap/js/modules/browser.js +20 -14
- umap/static/umap/js/modules/caption.js +4 -4
- umap/static/umap/js/modules/dompurify.js +2 -3
- umap/static/umap/js/modules/facets.js +53 -17
- umap/static/umap/js/modules/formatter.js +153 -0
- umap/static/umap/js/modules/global.js +25 -16
- umap/static/umap/js/modules/help.js +26 -26
- umap/static/umap/js/modules/importer.js +10 -10
- umap/static/umap/js/modules/importers/communesfr.js +3 -1
- umap/static/umap/js/modules/importers/datasets.js +8 -6
- umap/static/umap/js/modules/importers/geodatamine.js +14 -14
- umap/static/umap/js/modules/importers/overpass.js +19 -15
- umap/static/umap/js/modules/orderable.js +2 -2
- umap/static/umap/js/modules/request.js +1 -1
- umap/static/umap/js/modules/rules.js +26 -11
- umap/static/umap/js/modules/schema.js +16 -12
- umap/static/umap/js/{umap.share.js → modules/share.js} +58 -103
- umap/static/umap/js/modules/slideshow.js +141 -0
- umap/static/umap/js/modules/sync/engine.js +3 -3
- umap/static/umap/js/modules/sync/updaters.js +10 -11
- umap/static/umap/js/modules/sync/websocket.js +1 -1
- umap/static/umap/js/modules/tableeditor.js +329 -0
- umap/static/umap/js/modules/ui/base.js +93 -0
- umap/static/umap/js/modules/ui/contextmenu.js +50 -0
- umap/static/umap/js/modules/ui/dialog.js +169 -31
- umap/static/umap/js/modules/ui/panel.js +7 -5
- umap/static/umap/js/modules/ui/tooltip.js +7 -77
- umap/static/umap/js/modules/urls.js +1 -2
- umap/static/umap/js/modules/utils.js +36 -16
- umap/static/umap/js/umap.controls.js +27 -29
- umap/static/umap/js/umap.core.js +19 -15
- umap/static/umap/js/umap.datalayer.permissions.js +15 -18
- umap/static/umap/js/umap.features.js +113 -131
- umap/static/umap/js/umap.forms.js +203 -228
- umap/static/umap/js/umap.icon.js +17 -22
- umap/static/umap/js/umap.js +117 -107
- umap/static/umap/js/umap.layer.js +374 -324
- umap/static/umap/js/umap.permissions.js +7 -10
- umap/static/umap/js/umap.popup.js +20 -20
- umap/static/umap/locale/am_ET.js +22 -5
- umap/static/umap/locale/am_ET.json +22 -5
- umap/static/umap/locale/ar.js +22 -5
- umap/static/umap/locale/ar.json +22 -5
- umap/static/umap/locale/ast.js +22 -5
- umap/static/umap/locale/ast.json +22 -5
- umap/static/umap/locale/bg.js +22 -5
- umap/static/umap/locale/bg.json +22 -5
- umap/static/umap/locale/br.js +22 -5
- umap/static/umap/locale/br.json +22 -5
- umap/static/umap/locale/ca.js +56 -39
- umap/static/umap/locale/ca.json +56 -39
- umap/static/umap/locale/cs_CZ.js +22 -5
- umap/static/umap/locale/cs_CZ.json +22 -5
- umap/static/umap/locale/da.js +22 -5
- umap/static/umap/locale/da.json +22 -5
- umap/static/umap/locale/de.js +22 -5
- umap/static/umap/locale/de.json +22 -5
- umap/static/umap/locale/el.js +27 -10
- umap/static/umap/locale/el.json +27 -10
- umap/static/umap/locale/en.js +22 -6
- umap/static/umap/locale/en.json +22 -6
- umap/static/umap/locale/en_US.json +22 -5
- umap/static/umap/locale/es.js +22 -6
- umap/static/umap/locale/es.json +22 -6
- umap/static/umap/locale/et.js +22 -5
- umap/static/umap/locale/et.json +22 -5
- umap/static/umap/locale/eu.js +167 -150
- umap/static/umap/locale/eu.json +167 -150
- umap/static/umap/locale/fa_IR.js +22 -5
- umap/static/umap/locale/fa_IR.json +22 -5
- umap/static/umap/locale/fi.js +22 -5
- umap/static/umap/locale/fi.json +22 -5
- umap/static/umap/locale/fr.js +22 -6
- umap/static/umap/locale/fr.json +22 -6
- umap/static/umap/locale/gl.js +22 -5
- umap/static/umap/locale/gl.json +22 -5
- umap/static/umap/locale/he.js +22 -5
- umap/static/umap/locale/he.json +22 -5
- umap/static/umap/locale/hr.js +22 -5
- umap/static/umap/locale/hr.json +22 -5
- umap/static/umap/locale/hu.js +89 -72
- umap/static/umap/locale/hu.json +89 -72
- umap/static/umap/locale/id.js +22 -5
- umap/static/umap/locale/id.json +22 -5
- umap/static/umap/locale/is.js +22 -5
- umap/static/umap/locale/is.json +22 -5
- umap/static/umap/locale/it.js +22 -5
- umap/static/umap/locale/it.json +22 -5
- umap/static/umap/locale/ja.js +22 -5
- umap/static/umap/locale/ja.json +22 -5
- umap/static/umap/locale/ko.js +22 -5
- umap/static/umap/locale/ko.json +22 -5
- umap/static/umap/locale/lt.js +22 -5
- umap/static/umap/locale/lt.json +22 -5
- umap/static/umap/locale/ms.js +22 -5
- umap/static/umap/locale/ms.json +22 -5
- umap/static/umap/locale/nl.js +22 -5
- umap/static/umap/locale/nl.json +22 -5
- umap/static/umap/locale/no.js +22 -5
- umap/static/umap/locale/no.json +22 -5
- umap/static/umap/locale/pl.js +22 -5
- umap/static/umap/locale/pl.json +22 -5
- umap/static/umap/locale/pl_PL.json +22 -5
- umap/static/umap/locale/pt.js +22 -6
- umap/static/umap/locale/pt.json +22 -6
- umap/static/umap/locale/pt_BR.js +22 -5
- umap/static/umap/locale/pt_BR.json +22 -5
- umap/static/umap/locale/pt_PT.js +22 -5
- umap/static/umap/locale/pt_PT.json +22 -5
- umap/static/umap/locale/ro.js +22 -5
- umap/static/umap/locale/ro.json +22 -5
- umap/static/umap/locale/ru.js +22 -5
- umap/static/umap/locale/ru.json +22 -5
- umap/static/umap/locale/sk_SK.js +22 -5
- umap/static/umap/locale/sk_SK.json +22 -5
- umap/static/umap/locale/sl.js +22 -5
- umap/static/umap/locale/sl.json +22 -5
- umap/static/umap/locale/sr.js +22 -5
- umap/static/umap/locale/sr.json +22 -5
- umap/static/umap/locale/sv.js +22 -5
- umap/static/umap/locale/sv.json +22 -5
- umap/static/umap/locale/th_TH.js +22 -5
- umap/static/umap/locale/th_TH.json +22 -5
- umap/static/umap/locale/tr.js +22 -5
- umap/static/umap/locale/tr.json +22 -5
- umap/static/umap/locale/uk_UA.js +22 -5
- umap/static/umap/locale/uk_UA.json +22 -5
- umap/static/umap/locale/vi.js +22 -5
- umap/static/umap/locale/vi.json +22 -5
- umap/static/umap/locale/vi_VN.json +22 -5
- umap/static/umap/locale/zh.js +22 -5
- umap/static/umap/locale/zh.json +22 -5
- umap/static/umap/locale/zh_CN.json +22 -5
- umap/static/umap/locale/zh_TW.Big5.json +22 -5
- umap/static/umap/locale/zh_TW.js +22 -5
- umap/static/umap/locale/zh_TW.json +22 -5
- umap/static/umap/map.css +9 -153
- umap/static/umap/vars.css +15 -0
- umap/static/umap/vendors/dompurify/purify.es.js +5 -59
- umap/static/umap/vendors/dompurify/purify.es.mjs.map +1 -1
- umap/static/umap/vendors/formbuilder/Leaflet.FormBuilder.js +410 -428
- umap/static/umap/vendors/geojson-to-gpx/index.js +155 -0
- umap/static/umap/vendors/osmtogeojson/osmtogeojson.js +1 -2
- umap/static/umap/vendors/togeojson/togeojson.es.js +1109 -0
- umap/static/umap/vendors/togeojson/{togeojson.umd.js.map → togeojson.es.mjs.map} +1 -1
- umap/static/umap/vendors/tokml/tokml.es.js +895 -0
- umap/static/umap/vendors/tokml/tokml.es.mjs.map +1 -0
- umap/storage.py +6 -2
- umap/templates/umap/components/alerts/alert.html +3 -3
- umap/templates/umap/css.html +3 -0
- umap/templates/umap/js.html +0 -6
- umap/tests/fixtures/categorized_highway.geojson +1 -0
- umap/tests/fixtures/test_import_osm_relation.json +130 -0
- umap/tests/integration/conftest.py +8 -1
- umap/tests/integration/test_browser.py +3 -2
- umap/tests/integration/test_categorized_layer.py +141 -0
- umap/tests/integration/test_conditional_rules.py +21 -0
- umap/tests/integration/test_datalayer.py +9 -4
- umap/tests/integration/test_edit_datalayer.py +1 -0
- umap/tests/integration/test_edit_polygon.py +1 -1
- umap/tests/integration/test_export_map.py +2 -3
- umap/tests/integration/test_import.py +22 -0
- umap/tests/integration/test_map_preview.py +36 -2
- umap/tests/integration/test_tableeditor.py +158 -4
- umap/tests/integration/test_websocket_sync.py +2 -2
- umap/tests/test_views.py +2 -2
- umap/views.py +3 -2
- {umap_project-2.4.1.dist-info → umap_project-2.5.0.dist-info}/METADATA +8 -8
- {umap_project-2.4.1.dist-info → umap_project-2.5.0.dist-info}/RECORD +194 -184
- umap/static/umap/js/umap.slideshow.js +0 -165
- umap/static/umap/js/umap.tableeditor.js +0 -118
- umap/static/umap/vendors/togeojson/togeojson.umd.js +0 -2
- umap/static/umap/vendors/togpx/togpx.js +0 -547
- umap/static/umap/vendors/tokml/tokml.js +0 -343
- {umap_project-2.4.1.dist-info → umap_project-2.5.0.dist-info}/WHEEL +0 -0
- {umap_project-2.4.1.dist-info → umap_project-2.5.0.dist-info}/entry_points.txt +0 -0
- {umap_project-2.4.1.dist-info → umap_project-2.5.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,547 +0,0 @@
|
|
|
1
|
-
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.togpx = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
2
|
-
var JXON = require("jxon");
|
|
3
|
-
JXON.config({attrPrefix: '@'});
|
|
4
|
-
|
|
5
|
-
function togpx( geojson, options ) {
|
|
6
|
-
options = (function (defaults, options) {
|
|
7
|
-
for (var k in defaults) {
|
|
8
|
-
if (options.hasOwnProperty(k))
|
|
9
|
-
defaults[k] = options[k];
|
|
10
|
-
}
|
|
11
|
-
return defaults;
|
|
12
|
-
})({
|
|
13
|
-
creator: "togpx",
|
|
14
|
-
metadata: undefined,
|
|
15
|
-
featureTitle: get_feature_title,
|
|
16
|
-
featureDescription: get_feature_description,
|
|
17
|
-
featureLink: undefined,
|
|
18
|
-
featureCoordTimes: get_feature_coord_times,
|
|
19
|
-
}, options || {});
|
|
20
|
-
|
|
21
|
-
// is featureCoordTimes is a string -> look for the specified property
|
|
22
|
-
if (typeof options.featureCoordTimes === 'string') {
|
|
23
|
-
var customTimesFieldKey = options.featureCoordTimes;
|
|
24
|
-
options.featureCoordTimes = function (feature) {
|
|
25
|
-
return feature.properties[customTimesFieldKey];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function get_feature_title(props) {
|
|
30
|
-
// a simple default heuristic to determine a title for a given feature
|
|
31
|
-
// uses a nested `tags` object or the feature's `properties` if present
|
|
32
|
-
// and then searchs for the following properties to construct a title:
|
|
33
|
-
// `name`, `ref`, `id`
|
|
34
|
-
if (!props) return "";
|
|
35
|
-
if (typeof props.tags === "object") {
|
|
36
|
-
var tags_title = get_feature_title(props.tags);
|
|
37
|
-
if (tags_title !== "")
|
|
38
|
-
return tags_title;
|
|
39
|
-
}
|
|
40
|
-
if (props.name)
|
|
41
|
-
return props.name;
|
|
42
|
-
if (props.ref)
|
|
43
|
-
return props.ref;
|
|
44
|
-
if (props.id)
|
|
45
|
-
return props.id;
|
|
46
|
-
return "";
|
|
47
|
-
}
|
|
48
|
-
function get_feature_description(props) {
|
|
49
|
-
// constructs a description for a given feature
|
|
50
|
-
// uses a nested `tags` object or the feature's `properties` if present
|
|
51
|
-
// and then concatenates all properties to construct a description.
|
|
52
|
-
if (!props) return "";
|
|
53
|
-
if (typeof props.tags === "object")
|
|
54
|
-
return get_feature_description(props.tags);
|
|
55
|
-
var res = "";
|
|
56
|
-
for (var k in props) {
|
|
57
|
-
if (typeof props[k] === "object")
|
|
58
|
-
continue;
|
|
59
|
-
res += k+"="+props[k]+"\n";
|
|
60
|
-
}
|
|
61
|
-
return res.substr(0,res.length-1);
|
|
62
|
-
}
|
|
63
|
-
function get_feature_coord_times(feature) {
|
|
64
|
-
if (!feature.properties) return null;
|
|
65
|
-
return feature.properties.times || feature.properties.coordTimes || null;
|
|
66
|
-
}
|
|
67
|
-
function add_feature_link(o, f) {
|
|
68
|
-
if (options.featureLink)
|
|
69
|
-
o.link = { "@href": options.featureLink(f.properties) }
|
|
70
|
-
}
|
|
71
|
-
// make gpx object
|
|
72
|
-
var gpx = {"gpx": {
|
|
73
|
-
"@xmlns":"http://www.topografix.com/GPX/1/1",
|
|
74
|
-
"@xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance",
|
|
75
|
-
"@xsi:schemaLocation":"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd",
|
|
76
|
-
"@version":"1.1",
|
|
77
|
-
"metadata": null,
|
|
78
|
-
"wpt": [],
|
|
79
|
-
"trk": [],
|
|
80
|
-
}};
|
|
81
|
-
if (options.creator)
|
|
82
|
-
gpx.gpx["@creator"] = options.creator;
|
|
83
|
-
if (options.metadata)
|
|
84
|
-
gpx.gpx["metadata"] = options.metadata;
|
|
85
|
-
else
|
|
86
|
-
delete options.metadata;
|
|
87
|
-
|
|
88
|
-
var features;
|
|
89
|
-
if (geojson.type === "FeatureCollection")
|
|
90
|
-
features = geojson.features;
|
|
91
|
-
else if (geojson.type === "Feature")
|
|
92
|
-
features = [geojson];
|
|
93
|
-
else
|
|
94
|
-
features = [{type:"Feature", properties: {}, geometry: geojson}];
|
|
95
|
-
features.forEach(function mapFeature(f) {
|
|
96
|
-
switch (f.geometry.type) {
|
|
97
|
-
// POIs
|
|
98
|
-
case "Point":
|
|
99
|
-
case "MultiPoint":
|
|
100
|
-
var coords = f.geometry.coordinates;
|
|
101
|
-
if (f.geometry.type == "Point") coords = [coords];
|
|
102
|
-
coords.forEach(function (coordinates) {
|
|
103
|
-
o = {
|
|
104
|
-
"@lat": coordinates[1],
|
|
105
|
-
"@lon": coordinates[0],
|
|
106
|
-
"name": options.featureTitle(f.properties),
|
|
107
|
-
"desc": options.featureDescription(f.properties)
|
|
108
|
-
};
|
|
109
|
-
if (coordinates[2] !== undefined) {
|
|
110
|
-
o.ele = coordinates[2];
|
|
111
|
-
}
|
|
112
|
-
add_feature_link(o,f);
|
|
113
|
-
gpx.gpx.wpt.push(o);
|
|
114
|
-
});
|
|
115
|
-
break;
|
|
116
|
-
// LineStrings
|
|
117
|
-
case "LineString":
|
|
118
|
-
case "MultiLineString":
|
|
119
|
-
var coords = f.geometry.coordinates;
|
|
120
|
-
var times = options.featureCoordTimes(f);
|
|
121
|
-
if (f.geometry.type == "LineString") coords = [coords];
|
|
122
|
-
o = {
|
|
123
|
-
"name": options.featureTitle(f.properties),
|
|
124
|
-
"desc": options.featureDescription(f.properties)
|
|
125
|
-
};
|
|
126
|
-
add_feature_link(o,f);
|
|
127
|
-
o.trkseg = [];
|
|
128
|
-
coords.forEach(function(coordinates) {
|
|
129
|
-
var seg = {trkpt: []};
|
|
130
|
-
coordinates.forEach(function(c, i) {
|
|
131
|
-
var o = {
|
|
132
|
-
"@lat": c[1],
|
|
133
|
-
"@lon":c[0]
|
|
134
|
-
};
|
|
135
|
-
if (c[2] !== undefined) {
|
|
136
|
-
o.ele = c[2];
|
|
137
|
-
}
|
|
138
|
-
if (times && times[i]) {
|
|
139
|
-
o.time = times[i];
|
|
140
|
-
}
|
|
141
|
-
seg.trkpt.push(o);
|
|
142
|
-
});
|
|
143
|
-
o.trkseg.push(seg);
|
|
144
|
-
});
|
|
145
|
-
gpx.gpx.trk.push(o);
|
|
146
|
-
break;
|
|
147
|
-
// Polygons / Multipolygons
|
|
148
|
-
case "Polygon":
|
|
149
|
-
case "MultiPolygon":
|
|
150
|
-
o = {
|
|
151
|
-
"name": options.featureTitle(f.properties),
|
|
152
|
-
"desc": options.featureDescription(f.properties)
|
|
153
|
-
};
|
|
154
|
-
add_feature_link(o,f);
|
|
155
|
-
o.trkseg = [];
|
|
156
|
-
var coords = f.geometry.coordinates;
|
|
157
|
-
var times = options.featureCoordTimes(f);
|
|
158
|
-
if (f.geometry.type == "Polygon") coords = [coords];
|
|
159
|
-
coords.forEach(function(poly) {
|
|
160
|
-
poly.forEach(function(ring) {
|
|
161
|
-
var seg = {trkpt: []};
|
|
162
|
-
var i = 0;
|
|
163
|
-
ring.forEach(function(c) {
|
|
164
|
-
var o = {
|
|
165
|
-
"@lat": c[1],
|
|
166
|
-
"@lon":c[0]
|
|
167
|
-
};
|
|
168
|
-
if (c[2] !== undefined) {
|
|
169
|
-
o.ele = c[2];
|
|
170
|
-
}
|
|
171
|
-
if (times && times[i]) {
|
|
172
|
-
o.time = times[i];
|
|
173
|
-
}
|
|
174
|
-
i++;
|
|
175
|
-
seg.trkpt.push(o);
|
|
176
|
-
});
|
|
177
|
-
o.trkseg.push(seg);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
gpx.gpx.trk.push(o);
|
|
181
|
-
break;
|
|
182
|
-
case "GeometryCollection":
|
|
183
|
-
f.geometry.geometries.forEach(function (geometry) {
|
|
184
|
-
var pseudo_feature = {
|
|
185
|
-
"properties": f.properties,
|
|
186
|
-
"geometry": geometry
|
|
187
|
-
};
|
|
188
|
-
mapFeature(pseudo_feature);
|
|
189
|
-
});
|
|
190
|
-
break;
|
|
191
|
-
default:
|
|
192
|
-
console.log("warning: unsupported geometry type: "+f.geometry.type);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
gpx_str = JXON.stringify(gpx);
|
|
196
|
-
return gpx_str;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
module.exports = togpx;
|
|
200
|
-
|
|
201
|
-
},{"jxon":2}],2:[function(require,module,exports){
|
|
202
|
-
/*
|
|
203
|
-
* JXON framework - Copyleft 2011 by Mozilla Developer Network
|
|
204
|
-
*
|
|
205
|
-
* Revision #1 - September 5, 2014
|
|
206
|
-
*
|
|
207
|
-
* https://developer.mozilla.org/en-US/docs/JXON
|
|
208
|
-
*
|
|
209
|
-
* This framework is released under the GNU Public License, version 3 or later.
|
|
210
|
-
* http://www.gnu.org/licenses/gpl-3.0-standalone.html
|
|
211
|
-
*
|
|
212
|
-
* small modifications performed by the iD project:
|
|
213
|
-
* https://github.com/openstreetmap/iD/commits/18aa33ba97b52cacf454e95c65d154000e052a1f/js/lib/jxon.js
|
|
214
|
-
*
|
|
215
|
-
* small modifications performed by user @bugreport0
|
|
216
|
-
* https://github.com/tyrasd/JXON/pull/2/commits
|
|
217
|
-
*
|
|
218
|
-
* some additions and modifications by user @igord
|
|
219
|
-
* https://github.com/tyrasd/JXON/pull/5/commits
|
|
220
|
-
*
|
|
221
|
-
* bugfixes and code cleanup by user @laubstein
|
|
222
|
-
* https://github.com/tyrasd/jxon/pull/32
|
|
223
|
-
*
|
|
224
|
-
* adapted for nodejs and npm by @tyrasd (Martin Raifer <tyr.asd@gmail.com>)
|
|
225
|
-
*/
|
|
226
|
-
|
|
227
|
-
(function(root, factory) {
|
|
228
|
-
if (typeof define === 'function' && define.amd) {
|
|
229
|
-
// AMD. Register as an anonymous module.
|
|
230
|
-
define([], factory(window));
|
|
231
|
-
} else if (typeof exports === 'object') {
|
|
232
|
-
if (typeof window === 'object' && window.DOMImplementation && window.XMLSerializer && window.DOMParser) {
|
|
233
|
-
// Browserify. hardcode usage of browser's own XMLDom implementation
|
|
234
|
-
// see https://github.com/tyrasd/jxon/issues/18
|
|
235
|
-
|
|
236
|
-
module.exports = factory(window);
|
|
237
|
-
} else {
|
|
238
|
-
// Node. Does not work with strict CommonJS, but
|
|
239
|
-
// only CommonJS-like environments that support module.exports,
|
|
240
|
-
// like Node.
|
|
241
|
-
|
|
242
|
-
module.exports = factory(require('xmldom'), true);
|
|
243
|
-
}
|
|
244
|
-
} else {
|
|
245
|
-
// Browser globals (root is window)
|
|
246
|
-
|
|
247
|
-
root.JXON = factory(window);
|
|
248
|
-
}
|
|
249
|
-
}(this, function(xmlDom, isNodeJs) {
|
|
250
|
-
var opts = {
|
|
251
|
-
valueKey: '_',
|
|
252
|
-
attrKey: '$',
|
|
253
|
-
attrPrefix: '$',
|
|
254
|
-
lowerCaseTags: false,
|
|
255
|
-
trueIsEmpty: false,
|
|
256
|
-
autoDate: false,
|
|
257
|
-
ignorePrefixedNodes: false,
|
|
258
|
-
parseValues: false
|
|
259
|
-
};
|
|
260
|
-
var aCache = [];
|
|
261
|
-
var rIsNull = /^\s*$/;
|
|
262
|
-
var rIsBool = /^(?:true|false)$/i;
|
|
263
|
-
var DOMParser;
|
|
264
|
-
|
|
265
|
-
return new (function() {
|
|
266
|
-
|
|
267
|
-
this.config = function(cfg) {
|
|
268
|
-
for (var k in cfg) {
|
|
269
|
-
|
|
270
|
-
opts[k] = cfg[k];
|
|
271
|
-
}
|
|
272
|
-
if (opts.parserErrorHandler) {
|
|
273
|
-
DOMParser = new xmlDom.DOMParser({
|
|
274
|
-
errorHandler: opts.parserErrorHandler,
|
|
275
|
-
locator: {}
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
function parseText(sValue) {
|
|
281
|
-
if (!opts.parseValues) {
|
|
282
|
-
return sValue;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (rIsNull.test(sValue)) {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (rIsBool.test(sValue)) {
|
|
290
|
-
return sValue.toLowerCase() === 'true';
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (isFinite(sValue)) {
|
|
294
|
-
return parseFloat(sValue);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
if (opts.autoDate && isFinite(Date.parse(sValue))) {
|
|
298
|
-
return new Date(sValue);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
return sValue;
|
|
302
|
-
}
|
|
303
|
-
function EmptyTree() {
|
|
304
|
-
}
|
|
305
|
-
EmptyTree.prototype.toString = function() {
|
|
306
|
-
return 'null';
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
EmptyTree.prototype.valueOf = function() {
|
|
310
|
-
return null;
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
function objectify(vValue) {
|
|
314
|
-
return vValue === null ? new EmptyTree() : vValue instanceof Object ? vValue : new vValue.constructor(vValue);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function createObjTree(oParentNode, nVerb, bFreeze, bNesteAttr) {
|
|
318
|
-
var CDATA = 4,
|
|
319
|
-
TEXT = 3,
|
|
320
|
-
ELEMENT = 1,
|
|
321
|
-
nLevelStart = aCache.length,
|
|
322
|
-
bChildren = oParentNode.hasChildNodes(),
|
|
323
|
-
bAttributes = oParentNode.nodeType === oParentNode.ELEMENT_NODE && oParentNode.hasAttributes(),
|
|
324
|
-
bHighVerb = Boolean(nVerb & 2),
|
|
325
|
-
nLength = 0,
|
|
326
|
-
sCollectedTxt = '',
|
|
327
|
-
vResult = bHighVerb ? {} : /* put here the default value for empty nodes: */ (opts.trueIsEmpty ? true : ''),
|
|
328
|
-
sProp,
|
|
329
|
-
vContent;
|
|
330
|
-
|
|
331
|
-
if (bChildren) {
|
|
332
|
-
for (var oNode, nItem = 0; nItem < oParentNode.childNodes.length; nItem++) {
|
|
333
|
-
|
|
334
|
-
oNode = oParentNode.childNodes.item(nItem);
|
|
335
|
-
if (oNode.nodeType === CDATA) {
|
|
336
|
-
sCollectedTxt += oNode.nodeValue;
|
|
337
|
-
} /* nodeType is "CDATASection" (4) */
|
|
338
|
-
else if (oNode.nodeType === TEXT) {
|
|
339
|
-
sCollectedTxt += oNode.nodeValue.trim();
|
|
340
|
-
} /* nodeType is "Text" (3) */
|
|
341
|
-
else if (oNode.nodeType === ELEMENT && !(opts.ignorePrefixedNodes && oNode.prefix)) {
|
|
342
|
-
aCache.push(oNode);
|
|
343
|
-
}
|
|
344
|
-
/* nodeType is "Element" (1) */
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
var nLevelEnd = aCache.length,
|
|
349
|
-
vBuiltVal = parseText(sCollectedTxt);
|
|
350
|
-
|
|
351
|
-
if (!bHighVerb && (bChildren || bAttributes)) {
|
|
352
|
-
vResult = nVerb === 0 ? objectify(vBuiltVal) : {};
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
for (var nElId = nLevelStart; nElId < nLevelEnd; nElId++) {
|
|
356
|
-
|
|
357
|
-
sProp = aCache[nElId].nodeName;
|
|
358
|
-
if (opts.lowerCaseTags) {
|
|
359
|
-
sProp = sProp.toLowerCase();
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
vContent = createObjTree(aCache[nElId], nVerb, bFreeze, bNesteAttr);
|
|
363
|
-
if (vResult.hasOwnProperty(sProp)) {
|
|
364
|
-
if (vResult[sProp].constructor !== Array) {
|
|
365
|
-
vResult[sProp] = [vResult[sProp]];
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
vResult[sProp].push(vContent);
|
|
369
|
-
} else {
|
|
370
|
-
vResult[sProp] = vContent;
|
|
371
|
-
|
|
372
|
-
nLength++;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
if (bAttributes) {
|
|
377
|
-
var nAttrLen = oParentNode.attributes.length,
|
|
378
|
-
sAPrefix = bNesteAttr ? '' : opts.attrPrefix,
|
|
379
|
-
oAttrParent = bNesteAttr ? {} : vResult;
|
|
380
|
-
|
|
381
|
-
for (var oAttrib, oAttribName, nAttrib = 0; nAttrib < nAttrLen; nLength++, nAttrib++) {
|
|
382
|
-
|
|
383
|
-
oAttrib = oParentNode.attributes.item(nAttrib);
|
|
384
|
-
|
|
385
|
-
oAttribName = oAttrib.name;
|
|
386
|
-
if (opts.lowerCaseTags) {
|
|
387
|
-
oAttribName = oAttribName.toLowerCase();
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
oAttrParent[sAPrefix + oAttribName] = parseText(oAttrib.value.trim());
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
if (bNesteAttr) {
|
|
394
|
-
if (bFreeze) {
|
|
395
|
-
Object.freeze(oAttrParent);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
vResult[opts.attrKey] = oAttrParent;
|
|
399
|
-
|
|
400
|
-
nLength -= nAttrLen - 1;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
if (nVerb === 3 || (nVerb === 2 || nVerb === 1 && nLength > 0) && sCollectedTxt) {
|
|
406
|
-
vResult[opts.valueKey] = vBuiltVal;
|
|
407
|
-
} else if (!bHighVerb && nLength === 0 && sCollectedTxt) {
|
|
408
|
-
vResult = vBuiltVal;
|
|
409
|
-
}
|
|
410
|
-
if (bFreeze && (bHighVerb || nLength > 0)) {
|
|
411
|
-
Object.freeze(vResult);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
aCache.length = nLevelStart;
|
|
415
|
-
|
|
416
|
-
return vResult;
|
|
417
|
-
}
|
|
418
|
-
function loadObjTree(oXMLDoc, oParentEl, oParentObj) {
|
|
419
|
-
var vValue,
|
|
420
|
-
oChild,
|
|
421
|
-
elementNS;
|
|
422
|
-
|
|
423
|
-
if (oParentObj.constructor === String || oParentObj.constructor === Number || oParentObj.constructor === Boolean) {
|
|
424
|
-
oParentEl.appendChild(oXMLDoc.createTextNode(oParentObj.toString())); /* verbosity level is 0 or 1 */
|
|
425
|
-
if (oParentObj === oParentObj.valueOf()) {
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
} else if (oParentObj.constructor === Date) {
|
|
430
|
-
oParentEl.appendChild(oXMLDoc.createTextNode(oParentObj.toISOString()));
|
|
431
|
-
}
|
|
432
|
-
for (var sName in oParentObj) {
|
|
433
|
-
|
|
434
|
-
vValue = oParentObj[sName];
|
|
435
|
-
if ( vValue === undefined ) {
|
|
436
|
-
continue;
|
|
437
|
-
}
|
|
438
|
-
if ( vValue === null ) {
|
|
439
|
-
vValue = {};
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
if (isFinite(sName) || vValue instanceof Function) {
|
|
443
|
-
continue;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
/* verbosity level is 0 */
|
|
447
|
-
if (sName === opts.valueKey) {
|
|
448
|
-
if (vValue !== null && vValue !== true) {
|
|
449
|
-
oParentEl.appendChild(oXMLDoc.createTextNode(vValue.constructor === Date ? vValue.toISOString() : String(vValue)));
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
} else if (sName === opts.attrKey) { /* verbosity level is 3 */
|
|
453
|
-
for (var sAttrib in vValue) {
|
|
454
|
-
oParentEl.setAttribute(sAttrib, vValue[sAttrib]);
|
|
455
|
-
}
|
|
456
|
-
} else if (sName === opts.attrPrefix + 'xmlns') {
|
|
457
|
-
if (isNodeJs) {
|
|
458
|
-
oParentEl.setAttribute(sName.slice(1), vValue);
|
|
459
|
-
}
|
|
460
|
-
// do nothing: special handling of xml namespaces is done via createElementNS()
|
|
461
|
-
} else if (sName.charAt(0) === opts.attrPrefix) {
|
|
462
|
-
oParentEl.setAttribute(sName.slice(1), vValue);
|
|
463
|
-
} else if (vValue.constructor === Array) {
|
|
464
|
-
for (var nItem in vValue) {
|
|
465
|
-
if (!vValue.hasOwnProperty(nItem)) continue;
|
|
466
|
-
elementNS = (vValue[nItem] && vValue[nItem][opts.attrPrefix + 'xmlns']) || oParentEl.namespaceURI;
|
|
467
|
-
if (elementNS) {
|
|
468
|
-
oChild = oXMLDoc.createElementNS(elementNS, sName);
|
|
469
|
-
} else {
|
|
470
|
-
oChild = oXMLDoc.createElement(sName);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
loadObjTree(oXMLDoc, oChild, vValue[nItem] || {});
|
|
474
|
-
oParentEl.appendChild(oChild);
|
|
475
|
-
}
|
|
476
|
-
} else {
|
|
477
|
-
elementNS = (vValue || {})[opts.attrPrefix + 'xmlns'] || oParentEl.namespaceURI;
|
|
478
|
-
if (elementNS) {
|
|
479
|
-
oChild = oXMLDoc.createElementNS(elementNS, sName);
|
|
480
|
-
} else {
|
|
481
|
-
oChild = oXMLDoc.createElement(sName);
|
|
482
|
-
}
|
|
483
|
-
if (vValue instanceof Object) {
|
|
484
|
-
loadObjTree(oXMLDoc, oChild, vValue);
|
|
485
|
-
} else if (vValue !== null && (vValue !== true || !opts.trueIsEmpty)) {
|
|
486
|
-
oChild.appendChild(oXMLDoc.createTextNode(vValue.toString()));
|
|
487
|
-
}
|
|
488
|
-
oParentEl.appendChild(oChild);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
this.xmlToJs = this.build = function(oXMLParent, nVerbosity /* optional */ , bFreeze /* optional */ , bNesteAttributes /* optional */ ) {
|
|
493
|
-
var _nVerb = arguments.length > 1 && typeof nVerbosity === 'number' ? nVerbosity & 3 : /* put here the default verbosity level: */ 1;
|
|
494
|
-
return createObjTree(oXMLParent, _nVerb, bFreeze || false, arguments.length > 3 ? bNesteAttributes : _nVerb === 3);
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
this.jsToXml = this.unbuild = function(oObjTree, sNamespaceURI /* optional */ , sQualifiedName /* optional */ , oDocumentType /* optional */ ) {
|
|
498
|
-
var documentImplementation = xmlDom.document && xmlDom.document.implementation || new xmlDom.DOMImplementation();
|
|
499
|
-
var oNewDoc = documentImplementation.createDocument(sNamespaceURI || null, sQualifiedName || '', oDocumentType || null);
|
|
500
|
-
loadObjTree(oNewDoc, oNewDoc.documentElement || oNewDoc, oObjTree);
|
|
501
|
-
return oNewDoc;
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
this.stringToXml = function(xmlStr) {
|
|
505
|
-
if (!DOMParser) {
|
|
506
|
-
DOMParser = new xmlDom.DOMParser();
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
return DOMParser.parseFromString(xmlStr, 'application/xml');
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
this.xmlToString = function(xmlObj) {
|
|
513
|
-
if (typeof xmlObj.xml !== 'undefined') {
|
|
514
|
-
return xmlObj.xml;
|
|
515
|
-
} else {
|
|
516
|
-
return (new xmlDom.XMLSerializer()).serializeToString(xmlObj);
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
this.stringToJs = function(str) {
|
|
521
|
-
var xmlObj = this.stringToXml(str);
|
|
522
|
-
return this.xmlToJs(xmlObj);
|
|
523
|
-
};
|
|
524
|
-
|
|
525
|
-
this.jsToString = this.stringify = function(oObjTree, sNamespaceURI /* optional */ , sQualifiedName /* optional */ , oDocumentType /* optional */ ) {
|
|
526
|
-
return this.xmlToString(
|
|
527
|
-
this.jsToXml(oObjTree, sNamespaceURI, sQualifiedName, oDocumentType)
|
|
528
|
-
);
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
this.each = function(arr, func, thisArg) {
|
|
532
|
-
if (arr instanceof Array) {
|
|
533
|
-
arr.forEach(func, thisArg);
|
|
534
|
-
} else {
|
|
535
|
-
[arr].forEach(func, thisArg);
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
})();
|
|
539
|
-
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
));
|
|
543
|
-
|
|
544
|
-
},{"xmldom":3}],3:[function(require,module,exports){
|
|
545
|
-
|
|
546
|
-
},{}]},{},[1])(1)
|
|
547
|
-
});
|