@dra2020/baseclient 1.0.0 → 1.0.4

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/README.md CHANGED
@@ -22,4 +22,5 @@ These libraries are used across both client and server:
22
22
  - [LogAbstract](./docs/logabstract.md): An abstract logging interface. Different implementations are used on client and server.
23
23
  - [LogClient](./docs/logclient.md): A client implementation of the logging abstract interface.
24
24
  - [OT](./docs/ot-js.md): An Operational Transformation implementation, used as the basis for all content editing.
25
- - [OTE](.docs/ot-editutil.md): A set of utility functions for creating OT edits.
25
+ - [OTE](./docs/ot-editutil.md): A set of utility functions for creating OT edits.
26
+ - [FilterExpr](./docs/filterexpr.md): A class for parsing and executing a filter expression against an array of objects.
package/dist/all/all.d.ts CHANGED
@@ -16,3 +16,5 @@ import * as OTE from '../ot-editutil/all';
16
16
  export { OTE };
17
17
  import { FilterExpr } from '../filterexpr/all';
18
18
  export { FilterExpr };
19
+ import * as G from '../geo/all';
20
+ export { G };
@@ -39,7 +39,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
39
39
  return result;
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", ({ value: true }));
42
- exports.FilterExpr = exports.OTE = exports.OT = exports.LogClient = exports.LogAbstract = exports.Poly = exports.FSM = exports.Context = exports.Util = void 0;
42
+ exports.G = exports.FilterExpr = exports.OTE = exports.OT = exports.LogClient = exports.LogAbstract = exports.Poly = exports.FSM = exports.Context = exports.Util = void 0;
43
43
  // Client and Server
44
44
  const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
45
45
  exports.Util = Util;
@@ -59,6 +59,8 @@ const OTE = __importStar(__webpack_require__(/*! ../ot-editutil/all */ "./lib/ot
59
59
  exports.OTE = OTE;
60
60
  const all_1 = __webpack_require__(/*! ../filterexpr/all */ "./lib/filterexpr/all.ts");
61
61
  Object.defineProperty(exports, "FilterExpr", ({ enumerable: true, get: function () { return all_1.FilterExpr; } }));
62
+ const G = __importStar(__webpack_require__(/*! ../geo/all */ "./lib/geo/all.ts"));
63
+ exports.G = G;
62
64
 
63
65
 
64
66
  /***/ }),
@@ -1156,6 +1158,484 @@ class FsmArray extends Fsm {
1156
1158
  exports.FsmArray = FsmArray;
1157
1159
 
1158
1160
 
1161
+ /***/ }),
1162
+
1163
+ /***/ "./lib/geo/all.ts":
1164
+ /*!************************!*\
1165
+ !*** ./lib/geo/all.ts ***!
1166
+ \************************/
1167
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
1168
+
1169
+
1170
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1171
+ if (k2 === undefined) k2 = k;
1172
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1173
+ }) : (function(o, m, k, k2) {
1174
+ if (k2 === undefined) k2 = k;
1175
+ o[k2] = m[k];
1176
+ }));
1177
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
1178
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1179
+ };
1180
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
1181
+ __exportStar(__webpack_require__(/*! ./geo */ "./lib/geo/geo.ts"), exports);
1182
+ __exportStar(__webpack_require__(/*! ./vfeature */ "./lib/geo/vfeature.ts"), exports);
1183
+
1184
+
1185
+ /***/ }),
1186
+
1187
+ /***/ "./lib/geo/geo.ts":
1188
+ /*!************************!*\
1189
+ !*** ./lib/geo/geo.ts ***!
1190
+ \************************/
1191
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
1192
+
1193
+
1194
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1195
+ if (k2 === undefined) k2 = k;
1196
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1197
+ }) : (function(o, m, k, k2) {
1198
+ if (k2 === undefined) k2 = k;
1199
+ o[k2] = m[k];
1200
+ }));
1201
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1202
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
1203
+ }) : function(o, v) {
1204
+ o["default"] = v;
1205
+ });
1206
+ var __importStar = (this && this.__importStar) || function (mod) {
1207
+ if (mod && mod.__esModule) return mod;
1208
+ var result = {};
1209
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1210
+ __setModuleDefault(result, mod);
1211
+ return result;
1212
+ };
1213
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
1214
+ exports.geoIntersect = exports.geoIntersectOptions = exports.GeoMultiCollection = exports.geoMapEqual = exports.geoEqual = exports.geoTopoToCollection = exports.geoCollectionToTopo = exports.geoMapToCollection = exports.geoCollectionToMap = void 0;
1215
+ const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
1216
+ const Poly = __importStar(__webpack_require__(/*! ../poly/all */ "./lib/poly/all.ts"));
1217
+ function geoCollectionToMap(col) {
1218
+ if (col == null)
1219
+ return null;
1220
+ let map = {};
1221
+ col.features.forEach((f) => { map[String(f.properties.id)] = f; });
1222
+ return map;
1223
+ }
1224
+ exports.geoCollectionToMap = geoCollectionToMap;
1225
+ function geoMapToCollection(map) {
1226
+ if (map == null || Util.countKeys(map) == 0)
1227
+ return null;
1228
+ let col = { type: 'FeatureCollection', features: [] };
1229
+ Object.keys(map).forEach((geoid) => { col.features.push(map[geoid]); });
1230
+ return col;
1231
+ }
1232
+ exports.geoMapToCollection = geoMapToCollection;
1233
+ function geoCollectionToTopo(col) {
1234
+ let topo = Poly.topoFromCollection(col);
1235
+ Poly.topoPack(topo);
1236
+ return topo;
1237
+ }
1238
+ exports.geoCollectionToTopo = geoCollectionToTopo;
1239
+ function geoTopoToCollection(topo) {
1240
+ let col = Poly.topoToCollection(topo);
1241
+ Poly.featurePack(col);
1242
+ return col;
1243
+ }
1244
+ exports.geoTopoToCollection = geoTopoToCollection;
1245
+ function geoEqual(m1, m2) {
1246
+ let n1 = m1 ? m1.length : 0;
1247
+ let n2 = m2 ? m2.length : 0;
1248
+ if (n1 != n2)
1249
+ return false;
1250
+ if (n1 == 0)
1251
+ return true;
1252
+ let n = 0;
1253
+ let eq = true;
1254
+ m1.forEach(f => { if (eq && !m2.find(f.properties.id))
1255
+ eq = false; });
1256
+ return eq;
1257
+ }
1258
+ exports.geoEqual = geoEqual;
1259
+ function geoMapEqual(m1, m2) {
1260
+ if (m1 == null)
1261
+ return Util.isEmpty(m2);
1262
+ if (m2 == null)
1263
+ return Util.isEmpty(m1);
1264
+ let p;
1265
+ for (p in m1)
1266
+ if (m1.hasOwnProperty(p))
1267
+ if (m1[p] !== m2[p])
1268
+ return false;
1269
+ for (p in m2)
1270
+ if (m2.hasOwnProperty(p))
1271
+ if (m1[p] === undefined)
1272
+ return false;
1273
+ return true;
1274
+ }
1275
+ exports.geoMapEqual = geoMapEqual;
1276
+ class GeoMultiCollection {
1277
+ constructor(tag, topo, col, map) {
1278
+ this.stamp = Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER / 2);
1279
+ this.empty();
1280
+ if (tag)
1281
+ this.add(tag, topo, col, map);
1282
+ }
1283
+ empty() {
1284
+ this.entries = {};
1285
+ this.hidden = {};
1286
+ this._onChange();
1287
+ }
1288
+ get nEntries() { return Util.countKeys(this.entries); }
1289
+ nthEntry(n) {
1290
+ return Util.nthProperty(this.entries, n);
1291
+ }
1292
+ add(tag, topo, col, map) {
1293
+ let entry = this.entries[tag];
1294
+ if (entry === undefined)
1295
+ entry = { tag: tag }, this.entries[tag] = entry;
1296
+ if ((topo && entry.topo !== topo) || (col && entry.col !== col) || (map && entry.map !== map)) {
1297
+ entry.topo = topo;
1298
+ entry.col = col;
1299
+ entry.map = map;
1300
+ this._onChange();
1301
+ }
1302
+ else if (topo == null && col == null && map == null)
1303
+ this.remove(tag);
1304
+ }
1305
+ addMulti(multi) {
1306
+ multi.forEachEntry(e => {
1307
+ this.add(e.tag, e.topo, e.col, e.map);
1308
+ });
1309
+ for (let p in multi.hidden)
1310
+ if (multi.hidden.hasOwnProperty(p)) {
1311
+ this.hidden[p] = true;
1312
+ this._onChange();
1313
+ }
1314
+ }
1315
+ remove(tag) {
1316
+ let entry = this.entries[tag];
1317
+ if (entry) {
1318
+ if (entry.topo || entry.col || entry.map)
1319
+ this._onChange();
1320
+ delete this.entries[tag];
1321
+ }
1322
+ }
1323
+ _onChange() {
1324
+ this.all = { tag: 'all' };
1325
+ this.stamp++;
1326
+ }
1327
+ _col(e) {
1328
+ if (e == null)
1329
+ return null;
1330
+ if (!e.col) {
1331
+ if (e.map)
1332
+ e.col = geoMapToCollection(e.map);
1333
+ else if (e.topo)
1334
+ e.col = geoTopoToCollection(e.topo);
1335
+ }
1336
+ return e.col;
1337
+ }
1338
+ _map(e) {
1339
+ if (e == null)
1340
+ return null;
1341
+ if (!e.map) {
1342
+ if (e.col)
1343
+ e.map = geoCollectionToMap(e.col);
1344
+ else if (e.topo) {
1345
+ e.col = geoTopoToCollection(e.topo);
1346
+ e.map = geoCollectionToMap(e.col);
1347
+ }
1348
+ }
1349
+ return e.map;
1350
+ }
1351
+ _topo(e) {
1352
+ if (e == null)
1353
+ return null;
1354
+ if (!e.topo) {
1355
+ if (e.col)
1356
+ e.topo = geoCollectionToTopo(e.col);
1357
+ else if (e.map) {
1358
+ e.col = geoMapToCollection(e.map);
1359
+ e.topo = geoCollectionToTopo(e.col);
1360
+ }
1361
+ }
1362
+ return e.topo;
1363
+ }
1364
+ colOf(tag) { return this._col(this.entries[tag]); }
1365
+ mapOf(tag) { return this._map(this.entries[tag]); }
1366
+ topoOf(tag) { return this._topo(this.entries[tag]); }
1367
+ forEachEntry(cb) {
1368
+ Object.values(this.entries).forEach(cb);
1369
+ }
1370
+ allCol() {
1371
+ if (this.nEntries == 0)
1372
+ return null;
1373
+ if (!this.all.col) {
1374
+ // optimise case where one entry
1375
+ let n = this.nEntries;
1376
+ if (n == 1)
1377
+ this.all.col = this._col(this.nthEntry(0));
1378
+ else {
1379
+ this.all.col = { type: 'FeatureCollection', features: [] };
1380
+ this.forEach(f => { this.all.col.features.push(f); });
1381
+ }
1382
+ }
1383
+ return this.all.col;
1384
+ }
1385
+ allMap() {
1386
+ if (this.nEntries == 0)
1387
+ return null;
1388
+ if (!this.all.map) {
1389
+ // optimise case where one entry
1390
+ let n = this.nEntries;
1391
+ if (n == 1)
1392
+ this.all.map = this._map(this.nthEntry(0));
1393
+ else
1394
+ this.all.map = geoCollectionToMap(this.allCol());
1395
+ }
1396
+ return this.all.map;
1397
+ }
1398
+ allTopo() {
1399
+ if (this.nEntries == 0)
1400
+ return null;
1401
+ if (!this.all.topo) {
1402
+ // optimise case where one entry
1403
+ let n = this.nEntries;
1404
+ if (n == 1)
1405
+ this.all.topo = this._topo(this.nthEntry(0));
1406
+ else
1407
+ this.all.topo = geoCollectionToTopo(this.allCol());
1408
+ }
1409
+ return this.all.topo;
1410
+ }
1411
+ hide(id) {
1412
+ if (id) {
1413
+ if (typeof id === 'string')
1414
+ this.hidden[id] = true;
1415
+ else if (Array.isArray(id))
1416
+ id.forEach((i) => { this.hidden[i] = true; });
1417
+ else if (typeof id === 'object')
1418
+ for (let p in id)
1419
+ if (id.hasOwnProperty(p))
1420
+ this.hidden[p] = true;
1421
+ this._onChange();
1422
+ }
1423
+ }
1424
+ show(id) {
1425
+ if (id) {
1426
+ if (typeof id === 'string')
1427
+ delete this.hidden[id];
1428
+ else if (Array.isArray(id))
1429
+ id.forEach((i) => { delete this.hidden[i]; });
1430
+ else if (typeof id === 'object')
1431
+ for (let p in id)
1432
+ if (id.hasOwnProperty(p))
1433
+ delete this.hidden[p];
1434
+ this._onChange();
1435
+ }
1436
+ }
1437
+ showAll() {
1438
+ if (!Util.isEmpty(this.hidden)) {
1439
+ this.hidden = {};
1440
+ this._onChange();
1441
+ }
1442
+ }
1443
+ get length() {
1444
+ let n = 0;
1445
+ this.forEachEntry(e => {
1446
+ if (e.col)
1447
+ n += e.col.features.length;
1448
+ else if (e.map)
1449
+ n += Util.countKeys(e.map);
1450
+ else if (e.topo)
1451
+ n += Util.countKeys(e.topo.objects);
1452
+ });
1453
+ return n;
1454
+ }
1455
+ // Use forEach in preference to iteration using this function
1456
+ nthFeature(n) {
1457
+ let found;
1458
+ if (n >= 0)
1459
+ this.forEachEntry(e => {
1460
+ if (found)
1461
+ return;
1462
+ let col = this._col(e);
1463
+ if (col)
1464
+ if (n > col.features.length)
1465
+ n -= col.features.length;
1466
+ else
1467
+ found = col.features[n];
1468
+ });
1469
+ return found;
1470
+ }
1471
+ nthFilteredFeature(n, cb) {
1472
+ let found;
1473
+ this.forEachEntry(e => {
1474
+ if (found)
1475
+ return;
1476
+ let col = this._col(e);
1477
+ if (col)
1478
+ for (let i = 0; !found && i < col.features.length; i++) {
1479
+ let f = col.features[i];
1480
+ if (this.hidden[f.properties.id] === undefined && cb(f)) {
1481
+ if (n === 0) {
1482
+ found = f;
1483
+ break;
1484
+ }
1485
+ n--;
1486
+ }
1487
+ }
1488
+ });
1489
+ return found;
1490
+ }
1491
+ forEach(cb) {
1492
+ this.forEachEntry(e => {
1493
+ let col = this._col(e);
1494
+ if (e.col)
1495
+ e.col.features.forEach(f => { if (this.hidden[f.properties.id] === undefined)
1496
+ cb(f); });
1497
+ });
1498
+ }
1499
+ map(cb) {
1500
+ let features = [];
1501
+ this.forEach((f) => { features.push(cb(f)); });
1502
+ return features;
1503
+ }
1504
+ isHidden(id) {
1505
+ return this.hidden[id] !== undefined;
1506
+ }
1507
+ find(id) {
1508
+ if (this.hidden[id] !== undefined)
1509
+ return undefined;
1510
+ let entries = Object.values(this.entries);
1511
+ for (let i = 0; i < entries.length; i++) {
1512
+ let map = this._map(entries[i]);
1513
+ if (map[id])
1514
+ return map[id];
1515
+ }
1516
+ return undefined;
1517
+ }
1518
+ filter(test) {
1519
+ let m = new GeoMultiCollection();
1520
+ this.forEachEntry(e => {
1521
+ let col = this._col(e);
1522
+ let features = col ? col.features.filter(test) : null;
1523
+ if (features && features.length)
1524
+ m.add(e.tag, null, { type: 'FeatureCollection', features: features }, null);
1525
+ });
1526
+ return m;
1527
+ }
1528
+ }
1529
+ exports.GeoMultiCollection = GeoMultiCollection;
1530
+ var geoIntersectOptions;
1531
+ (function (geoIntersectOptions) {
1532
+ geoIntersectOptions[geoIntersectOptions["Intersects"] = 0] = "Intersects";
1533
+ geoIntersectOptions[geoIntersectOptions["Bounds"] = 1] = "Bounds";
1534
+ geoIntersectOptions[geoIntersectOptions["BoundsCenter"] = 2] = "BoundsCenter";
1535
+ })(geoIntersectOptions = exports.geoIntersectOptions || (exports.geoIntersectOptions = {}));
1536
+ ;
1537
+ function geoBoxIntersect(x1, x2, opt) {
1538
+ if (x1.left === undefined || x2.left === undefined)
1539
+ return false;
1540
+ let l1 = x1.left;
1541
+ let l2 = x2.left;
1542
+ let r1 = x1.right;
1543
+ let r2 = x2.right;
1544
+ let b1 = x1.top; // flip
1545
+ let b2 = x2.top; // flip
1546
+ let t1 = x1.bottom; // flip
1547
+ let t2 = x2.bottom; // flip
1548
+ let cx2 = l2 + (r2 - l2) / 2;
1549
+ let cy2 = t2 + (b2 - t2) / 2;
1550
+ // Note I flipped top and bottom above when extracting,
1551
+ // in order to make below logic work for normal y axis alignment (0 at top).
1552
+ switch (opt) {
1553
+ case geoIntersectOptions.Intersects:
1554
+ return !(l2 > r1 || r2 < l1 || t2 > b1 || b2 < t1);
1555
+ case geoIntersectOptions.Bounds:
1556
+ return l1 <= l2 && t1 <= t2 && r1 >= r2 && b1 >= b2;
1557
+ case geoIntersectOptions.BoundsCenter:
1558
+ return l1 <= cx2 && t1 <= cy2 && r1 >= cx2 && b1 >= cy2;
1559
+ }
1560
+ }
1561
+ function geoIntersect(multi, bbox, opt) {
1562
+ let m = {};
1563
+ let bboxPoly = Poly.boundboxPoly(bbox);
1564
+ multi.forEach((f) => {
1565
+ let box = Poly.boundbox(f);
1566
+ if (geoBoxIntersect(bbox, box, opt)) {
1567
+ if (opt !== geoIntersectOptions.Intersects || Poly.polyIntersects(bboxPoly, f))
1568
+ m[f.properties.id] = f;
1569
+ }
1570
+ });
1571
+ let result = new GeoMultiCollection();
1572
+ result.add('result', null, null, m);
1573
+ return result;
1574
+ }
1575
+ exports.geoIntersect = geoIntersect;
1576
+
1577
+
1578
+ /***/ }),
1579
+
1580
+ /***/ "./lib/geo/vfeature.ts":
1581
+ /*!*****************************!*\
1582
+ !*** ./lib/geo/vfeature.ts ***!
1583
+ \*****************************/
1584
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
1585
+
1586
+
1587
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1588
+ if (k2 === undefined) k2 = k;
1589
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1590
+ }) : (function(o, m, k, k2) {
1591
+ if (k2 === undefined) k2 = k;
1592
+ o[k2] = m[k];
1593
+ }));
1594
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1595
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
1596
+ }) : function(o, v) {
1597
+ o["default"] = v;
1598
+ });
1599
+ var __importStar = (this && this.__importStar) || function (mod) {
1600
+ if (mod && mod.__esModule) return mod;
1601
+ var result = {};
1602
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1603
+ __setModuleDefault(result, mod);
1604
+ return result;
1605
+ };
1606
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
1607
+ exports.computeVFeature = void 0;
1608
+ const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
1609
+ const Poly = __importStar(__webpack_require__(/*! ../poly/all */ "./lib/poly/all.ts"));
1610
+ // Given the topology for a precinct, the bintrie mapping and the list of blocks, construct the
1611
+ // feature data for the virtual feature.
1612
+ //
1613
+ function computeVFeature(topoPrecinct, bintrie, blocks) {
1614
+ let contiguity = new Util.IndexedArray();
1615
+ let block_contiguity = new Util.IndexedArray();
1616
+ let f = Poly.topoMerge(topoPrecinct, blocks);
1617
+ f.properties.datasets = {};
1618
+ blocks.forEach(blockid => {
1619
+ let b = topoPrecinct.objects[blockid];
1620
+ if (b.properties.datasets)
1621
+ Util.deepAccum(f.properties.datasets, b.properties.datasets);
1622
+ if (b.properties.contiguity) {
1623
+ b.properties.contiguity.forEach((id) => {
1624
+ contiguity.set(id === 'OUT_OF_STATE' ? id : bintrie.get(id));
1625
+ });
1626
+ b.properties.contiguity.forEach((id) => {
1627
+ block_contiguity.set(id);
1628
+ });
1629
+ }
1630
+ });
1631
+ f.properties.contiguity = contiguity.asArray();
1632
+ f.properties.block_contiguity = block_contiguity.asArray();
1633
+ f.properties.blocks = blocks;
1634
+ return f;
1635
+ }
1636
+ exports.computeVFeature = computeVFeature;
1637
+
1638
+
1159
1639
  /***/ }),
1160
1640
 
1161
1641
  /***/ "./lib/logabstract/all.ts":
@@ -7744,7 +8224,7 @@ class FsmIncrementalUnion extends FSM.Fsm {
7744
8224
  let values = Object.values(map);
7745
8225
  this.work = { nUnion: values.length, nDifference: 0, ms: 0 };
7746
8226
  let elapsed = new Util.Elapsed();
7747
- this.result = topoMergeFeatures(this.key.topo, values);
8227
+ this.result = topoMergeFeatures(this.key.multi.allTopo(), values);
7748
8228
  this.work.ms = elapsed.ms();
7749
8229
  this.map = map;
7750
8230
  }
@@ -7870,7 +8350,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
7870
8350
  return result;
7871
8351
  };
7872
8352
  Object.defineProperty(exports, "__esModule", ({ value: true }));
7873
- exports.FsmUnion = exports.polyIntersects = void 0;
8353
+ exports.FsmUnion = exports.polyDifference = exports.polyIntersects = void 0;
7874
8354
  const PC = __importStar(__webpack_require__(/*! polygon-clipping */ "polygon-clipping"));
7875
8355
  const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
7876
8356
  const FSM = __importStar(__webpack_require__(/*! ../fsm/all */ "./lib/fsm/all.ts"));
@@ -7929,6 +8409,20 @@ function polyIntersects(p1, p2) {
7929
8409
  return bIntersects;
7930
8410
  }
7931
8411
  exports.polyIntersects = polyIntersects;
8412
+ function polyDifference(main, parts) {
8413
+ main = PP.polyUnpack(coords(main));
8414
+ // need to explode multipolygon so that "exploded" is a valid multipolygon input to underlying difference routine
8415
+ let exploded = [];
8416
+ parts.forEach((p) => {
8417
+ p = PP.polyUnpack(coords(p));
8418
+ if (Util.depthof(p) == 5)
8419
+ p.forEach((poly) => { exploded.push(poly); });
8420
+ else
8421
+ exploded.push(p);
8422
+ });
8423
+ return PR.polyRound(_difference(main, exploded));
8424
+ }
8425
+ exports.polyDifference = polyDifference;
7932
8426
  class FsmDifference extends FSM.Fsm {
7933
8427
  constructor(env, accum, polys) {
7934
8428
  super(env);