@gmod/trix 0.2.1 → 2.0.1

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.
@@ -1,1472 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
6
- try {
7
- var info = gen[key](arg);
8
- var value = info.value;
9
- } catch (error) {
10
- reject(error);
11
- return;
12
- }
13
-
14
- if (info.done) {
15
- resolve(value);
16
- } else {
17
- Promise.resolve(value).then(_next, _throw);
18
- }
19
- }
20
-
21
- function _asyncToGenerator(fn) {
22
- return function () {
23
- var self = this,
24
- args = arguments;
25
- return new Promise(function (resolve, reject) {
26
- var gen = fn.apply(self, args);
27
-
28
- function _next(value) {
29
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
- }
31
-
32
- function _throw(err) {
33
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
34
- }
35
-
36
- _next(undefined);
37
- });
38
- };
39
- }
40
-
41
- function _unsupportedIterableToArray(o, minLen) {
42
- if (!o) return;
43
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
44
- var n = Object.prototype.toString.call(o).slice(8, -1);
45
- if (n === "Object" && o.constructor) n = o.constructor.name;
46
- if (n === "Map" || n === "Set") return Array.from(o);
47
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
48
- }
49
-
50
- function _arrayLikeToArray(arr, len) {
51
- if (len == null || len > arr.length) len = arr.length;
52
-
53
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
54
-
55
- return arr2;
56
- }
57
-
58
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
59
- var it;
60
-
61
- if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
62
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
63
- if (it) o = it;
64
- var i = 0;
65
- return function () {
66
- if (i >= o.length) return {
67
- done: true
68
- };
69
- return {
70
- done: false,
71
- value: o[i++]
72
- };
73
- };
74
- }
75
-
76
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
77
- }
78
-
79
- it = o[Symbol.iterator]();
80
- return it.next.bind(it);
81
- }
82
-
83
- function createCommonjsModule(fn, module) {
84
- return module = { exports: {} }, fn(module, module.exports), module.exports;
85
- }
86
-
87
- var runtime_1 = createCommonjsModule(function (module) {
88
- /**
89
- * Copyright (c) 2014-present, Facebook, Inc.
90
- *
91
- * This source code is licensed under the MIT license found in the
92
- * LICENSE file in the root directory of this source tree.
93
- */
94
-
95
- var runtime = (function (exports) {
96
-
97
- var Op = Object.prototype;
98
- var hasOwn = Op.hasOwnProperty;
99
- var undefined$1; // More compressible than void 0.
100
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
101
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
102
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
103
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
104
-
105
- function define(obj, key, value) {
106
- Object.defineProperty(obj, key, {
107
- value: value,
108
- enumerable: true,
109
- configurable: true,
110
- writable: true
111
- });
112
- return obj[key];
113
- }
114
- try {
115
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
116
- define({}, "");
117
- } catch (err) {
118
- define = function(obj, key, value) {
119
- return obj[key] = value;
120
- };
121
- }
122
-
123
- function wrap(innerFn, outerFn, self, tryLocsList) {
124
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
125
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
126
- var generator = Object.create(protoGenerator.prototype);
127
- var context = new Context(tryLocsList || []);
128
-
129
- // The ._invoke method unifies the implementations of the .next,
130
- // .throw, and .return methods.
131
- generator._invoke = makeInvokeMethod(innerFn, self, context);
132
-
133
- return generator;
134
- }
135
- exports.wrap = wrap;
136
-
137
- // Try/catch helper to minimize deoptimizations. Returns a completion
138
- // record like context.tryEntries[i].completion. This interface could
139
- // have been (and was previously) designed to take a closure to be
140
- // invoked without arguments, but in all the cases we care about we
141
- // already have an existing method we want to call, so there's no need
142
- // to create a new function object. We can even get away with assuming
143
- // the method takes exactly one argument, since that happens to be true
144
- // in every case, so we don't have to touch the arguments object. The
145
- // only additional allocation required is the completion record, which
146
- // has a stable shape and so hopefully should be cheap to allocate.
147
- function tryCatch(fn, obj, arg) {
148
- try {
149
- return { type: "normal", arg: fn.call(obj, arg) };
150
- } catch (err) {
151
- return { type: "throw", arg: err };
152
- }
153
- }
154
-
155
- var GenStateSuspendedStart = "suspendedStart";
156
- var GenStateSuspendedYield = "suspendedYield";
157
- var GenStateExecuting = "executing";
158
- var GenStateCompleted = "completed";
159
-
160
- // Returning this object from the innerFn has the same effect as
161
- // breaking out of the dispatch switch statement.
162
- var ContinueSentinel = {};
163
-
164
- // Dummy constructor functions that we use as the .constructor and
165
- // .constructor.prototype properties for functions that return Generator
166
- // objects. For full spec compliance, you may wish to configure your
167
- // minifier not to mangle the names of these two functions.
168
- function Generator() {}
169
- function GeneratorFunction() {}
170
- function GeneratorFunctionPrototype() {}
171
-
172
- // This is a polyfill for %IteratorPrototype% for environments that
173
- // don't natively support it.
174
- var IteratorPrototype = {};
175
- IteratorPrototype[iteratorSymbol] = function () {
176
- return this;
177
- };
178
-
179
- var getProto = Object.getPrototypeOf;
180
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
181
- if (NativeIteratorPrototype &&
182
- NativeIteratorPrototype !== Op &&
183
- hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
184
- // This environment has a native %IteratorPrototype%; use it instead
185
- // of the polyfill.
186
- IteratorPrototype = NativeIteratorPrototype;
187
- }
188
-
189
- var Gp = GeneratorFunctionPrototype.prototype =
190
- Generator.prototype = Object.create(IteratorPrototype);
191
- GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
192
- GeneratorFunctionPrototype.constructor = GeneratorFunction;
193
- GeneratorFunction.displayName = define(
194
- GeneratorFunctionPrototype,
195
- toStringTagSymbol,
196
- "GeneratorFunction"
197
- );
198
-
199
- // Helper for defining the .next, .throw, and .return methods of the
200
- // Iterator interface in terms of a single ._invoke method.
201
- function defineIteratorMethods(prototype) {
202
- ["next", "throw", "return"].forEach(function(method) {
203
- define(prototype, method, function(arg) {
204
- return this._invoke(method, arg);
205
- });
206
- });
207
- }
208
-
209
- exports.isGeneratorFunction = function(genFun) {
210
- var ctor = typeof genFun === "function" && genFun.constructor;
211
- return ctor
212
- ? ctor === GeneratorFunction ||
213
- // For the native GeneratorFunction constructor, the best we can
214
- // do is to check its .name property.
215
- (ctor.displayName || ctor.name) === "GeneratorFunction"
216
- : false;
217
- };
218
-
219
- exports.mark = function(genFun) {
220
- if (Object.setPrototypeOf) {
221
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
222
- } else {
223
- genFun.__proto__ = GeneratorFunctionPrototype;
224
- define(genFun, toStringTagSymbol, "GeneratorFunction");
225
- }
226
- genFun.prototype = Object.create(Gp);
227
- return genFun;
228
- };
229
-
230
- // Within the body of any async function, `await x` is transformed to
231
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
232
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
233
- // meant to be awaited.
234
- exports.awrap = function(arg) {
235
- return { __await: arg };
236
- };
237
-
238
- function AsyncIterator(generator, PromiseImpl) {
239
- function invoke(method, arg, resolve, reject) {
240
- var record = tryCatch(generator[method], generator, arg);
241
- if (record.type === "throw") {
242
- reject(record.arg);
243
- } else {
244
- var result = record.arg;
245
- var value = result.value;
246
- if (value &&
247
- typeof value === "object" &&
248
- hasOwn.call(value, "__await")) {
249
- return PromiseImpl.resolve(value.__await).then(function(value) {
250
- invoke("next", value, resolve, reject);
251
- }, function(err) {
252
- invoke("throw", err, resolve, reject);
253
- });
254
- }
255
-
256
- return PromiseImpl.resolve(value).then(function(unwrapped) {
257
- // When a yielded Promise is resolved, its final value becomes
258
- // the .value of the Promise<{value,done}> result for the
259
- // current iteration.
260
- result.value = unwrapped;
261
- resolve(result);
262
- }, function(error) {
263
- // If a rejected Promise was yielded, throw the rejection back
264
- // into the async generator function so it can be handled there.
265
- return invoke("throw", error, resolve, reject);
266
- });
267
- }
268
- }
269
-
270
- var previousPromise;
271
-
272
- function enqueue(method, arg) {
273
- function callInvokeWithMethodAndArg() {
274
- return new PromiseImpl(function(resolve, reject) {
275
- invoke(method, arg, resolve, reject);
276
- });
277
- }
278
-
279
- return previousPromise =
280
- // If enqueue has been called before, then we want to wait until
281
- // all previous Promises have been resolved before calling invoke,
282
- // so that results are always delivered in the correct order. If
283
- // enqueue has not been called before, then it is important to
284
- // call invoke immediately, without waiting on a callback to fire,
285
- // so that the async generator function has the opportunity to do
286
- // any necessary setup in a predictable way. This predictability
287
- // is why the Promise constructor synchronously invokes its
288
- // executor callback, and why async functions synchronously
289
- // execute code before the first await. Since we implement simple
290
- // async functions in terms of async generators, it is especially
291
- // important to get this right, even though it requires care.
292
- previousPromise ? previousPromise.then(
293
- callInvokeWithMethodAndArg,
294
- // Avoid propagating failures to Promises returned by later
295
- // invocations of the iterator.
296
- callInvokeWithMethodAndArg
297
- ) : callInvokeWithMethodAndArg();
298
- }
299
-
300
- // Define the unified helper method that is used to implement .next,
301
- // .throw, and .return (see defineIteratorMethods).
302
- this._invoke = enqueue;
303
- }
304
-
305
- defineIteratorMethods(AsyncIterator.prototype);
306
- AsyncIterator.prototype[asyncIteratorSymbol] = function () {
307
- return this;
308
- };
309
- exports.AsyncIterator = AsyncIterator;
310
-
311
- // Note that simple async functions are implemented on top of
312
- // AsyncIterator objects; they just return a Promise for the value of
313
- // the final result produced by the iterator.
314
- exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
315
- if (PromiseImpl === void 0) PromiseImpl = Promise;
316
-
317
- var iter = new AsyncIterator(
318
- wrap(innerFn, outerFn, self, tryLocsList),
319
- PromiseImpl
320
- );
321
-
322
- return exports.isGeneratorFunction(outerFn)
323
- ? iter // If outerFn is a generator, return the full iterator.
324
- : iter.next().then(function(result) {
325
- return result.done ? result.value : iter.next();
326
- });
327
- };
328
-
329
- function makeInvokeMethod(innerFn, self, context) {
330
- var state = GenStateSuspendedStart;
331
-
332
- return function invoke(method, arg) {
333
- if (state === GenStateExecuting) {
334
- throw new Error("Generator is already running");
335
- }
336
-
337
- if (state === GenStateCompleted) {
338
- if (method === "throw") {
339
- throw arg;
340
- }
341
-
342
- // Be forgiving, per 25.3.3.3.3 of the spec:
343
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
344
- return doneResult();
345
- }
346
-
347
- context.method = method;
348
- context.arg = arg;
349
-
350
- while (true) {
351
- var delegate = context.delegate;
352
- if (delegate) {
353
- var delegateResult = maybeInvokeDelegate(delegate, context);
354
- if (delegateResult) {
355
- if (delegateResult === ContinueSentinel) continue;
356
- return delegateResult;
357
- }
358
- }
359
-
360
- if (context.method === "next") {
361
- // Setting context._sent for legacy support of Babel's
362
- // function.sent implementation.
363
- context.sent = context._sent = context.arg;
364
-
365
- } else if (context.method === "throw") {
366
- if (state === GenStateSuspendedStart) {
367
- state = GenStateCompleted;
368
- throw context.arg;
369
- }
370
-
371
- context.dispatchException(context.arg);
372
-
373
- } else if (context.method === "return") {
374
- context.abrupt("return", context.arg);
375
- }
376
-
377
- state = GenStateExecuting;
378
-
379
- var record = tryCatch(innerFn, self, context);
380
- if (record.type === "normal") {
381
- // If an exception is thrown from innerFn, we leave state ===
382
- // GenStateExecuting and loop back for another invocation.
383
- state = context.done
384
- ? GenStateCompleted
385
- : GenStateSuspendedYield;
386
-
387
- if (record.arg === ContinueSentinel) {
388
- continue;
389
- }
390
-
391
- return {
392
- value: record.arg,
393
- done: context.done
394
- };
395
-
396
- } else if (record.type === "throw") {
397
- state = GenStateCompleted;
398
- // Dispatch the exception by looping back around to the
399
- // context.dispatchException(context.arg) call above.
400
- context.method = "throw";
401
- context.arg = record.arg;
402
- }
403
- }
404
- };
405
- }
406
-
407
- // Call delegate.iterator[context.method](context.arg) and handle the
408
- // result, either by returning a { value, done } result from the
409
- // delegate iterator, or by modifying context.method and context.arg,
410
- // setting context.delegate to null, and returning the ContinueSentinel.
411
- function maybeInvokeDelegate(delegate, context) {
412
- var method = delegate.iterator[context.method];
413
- if (method === undefined$1) {
414
- // A .throw or .return when the delegate iterator has no .throw
415
- // method always terminates the yield* loop.
416
- context.delegate = null;
417
-
418
- if (context.method === "throw") {
419
- // Note: ["return"] must be used for ES3 parsing compatibility.
420
- if (delegate.iterator["return"]) {
421
- // If the delegate iterator has a return method, give it a
422
- // chance to clean up.
423
- context.method = "return";
424
- context.arg = undefined$1;
425
- maybeInvokeDelegate(delegate, context);
426
-
427
- if (context.method === "throw") {
428
- // If maybeInvokeDelegate(context) changed context.method from
429
- // "return" to "throw", let that override the TypeError below.
430
- return ContinueSentinel;
431
- }
432
- }
433
-
434
- context.method = "throw";
435
- context.arg = new TypeError(
436
- "The iterator does not provide a 'throw' method");
437
- }
438
-
439
- return ContinueSentinel;
440
- }
441
-
442
- var record = tryCatch(method, delegate.iterator, context.arg);
443
-
444
- if (record.type === "throw") {
445
- context.method = "throw";
446
- context.arg = record.arg;
447
- context.delegate = null;
448
- return ContinueSentinel;
449
- }
450
-
451
- var info = record.arg;
452
-
453
- if (! info) {
454
- context.method = "throw";
455
- context.arg = new TypeError("iterator result is not an object");
456
- context.delegate = null;
457
- return ContinueSentinel;
458
- }
459
-
460
- if (info.done) {
461
- // Assign the result of the finished delegate to the temporary
462
- // variable specified by delegate.resultName (see delegateYield).
463
- context[delegate.resultName] = info.value;
464
-
465
- // Resume execution at the desired location (see delegateYield).
466
- context.next = delegate.nextLoc;
467
-
468
- // If context.method was "throw" but the delegate handled the
469
- // exception, let the outer generator proceed normally. If
470
- // context.method was "next", forget context.arg since it has been
471
- // "consumed" by the delegate iterator. If context.method was
472
- // "return", allow the original .return call to continue in the
473
- // outer generator.
474
- if (context.method !== "return") {
475
- context.method = "next";
476
- context.arg = undefined$1;
477
- }
478
-
479
- } else {
480
- // Re-yield the result returned by the delegate method.
481
- return info;
482
- }
483
-
484
- // The delegate iterator is finished, so forget it and continue with
485
- // the outer generator.
486
- context.delegate = null;
487
- return ContinueSentinel;
488
- }
489
-
490
- // Define Generator.prototype.{next,throw,return} in terms of the
491
- // unified ._invoke helper method.
492
- defineIteratorMethods(Gp);
493
-
494
- define(Gp, toStringTagSymbol, "Generator");
495
-
496
- // A Generator should always return itself as the iterator object when the
497
- // @@iterator function is called on it. Some browsers' implementations of the
498
- // iterator prototype chain incorrectly implement this, causing the Generator
499
- // object to not be returned from this call. This ensures that doesn't happen.
500
- // See https://github.com/facebook/regenerator/issues/274 for more details.
501
- Gp[iteratorSymbol] = function() {
502
- return this;
503
- };
504
-
505
- Gp.toString = function() {
506
- return "[object Generator]";
507
- };
508
-
509
- function pushTryEntry(locs) {
510
- var entry = { tryLoc: locs[0] };
511
-
512
- if (1 in locs) {
513
- entry.catchLoc = locs[1];
514
- }
515
-
516
- if (2 in locs) {
517
- entry.finallyLoc = locs[2];
518
- entry.afterLoc = locs[3];
519
- }
520
-
521
- this.tryEntries.push(entry);
522
- }
523
-
524
- function resetTryEntry(entry) {
525
- var record = entry.completion || {};
526
- record.type = "normal";
527
- delete record.arg;
528
- entry.completion = record;
529
- }
530
-
531
- function Context(tryLocsList) {
532
- // The root entry object (effectively a try statement without a catch
533
- // or a finally block) gives us a place to store values thrown from
534
- // locations where there is no enclosing try statement.
535
- this.tryEntries = [{ tryLoc: "root" }];
536
- tryLocsList.forEach(pushTryEntry, this);
537
- this.reset(true);
538
- }
539
-
540
- exports.keys = function(object) {
541
- var keys = [];
542
- for (var key in object) {
543
- keys.push(key);
544
- }
545
- keys.reverse();
546
-
547
- // Rather than returning an object with a next method, we keep
548
- // things simple and return the next function itself.
549
- return function next() {
550
- while (keys.length) {
551
- var key = keys.pop();
552
- if (key in object) {
553
- next.value = key;
554
- next.done = false;
555
- return next;
556
- }
557
- }
558
-
559
- // To avoid creating an additional object, we just hang the .value
560
- // and .done properties off the next function object itself. This
561
- // also ensures that the minifier will not anonymize the function.
562
- next.done = true;
563
- return next;
564
- };
565
- };
566
-
567
- function values(iterable) {
568
- if (iterable) {
569
- var iteratorMethod = iterable[iteratorSymbol];
570
- if (iteratorMethod) {
571
- return iteratorMethod.call(iterable);
572
- }
573
-
574
- if (typeof iterable.next === "function") {
575
- return iterable;
576
- }
577
-
578
- if (!isNaN(iterable.length)) {
579
- var i = -1, next = function next() {
580
- while (++i < iterable.length) {
581
- if (hasOwn.call(iterable, i)) {
582
- next.value = iterable[i];
583
- next.done = false;
584
- return next;
585
- }
586
- }
587
-
588
- next.value = undefined$1;
589
- next.done = true;
590
-
591
- return next;
592
- };
593
-
594
- return next.next = next;
595
- }
596
- }
597
-
598
- // Return an iterator with no values.
599
- return { next: doneResult };
600
- }
601
- exports.values = values;
602
-
603
- function doneResult() {
604
- return { value: undefined$1, done: true };
605
- }
606
-
607
- Context.prototype = {
608
- constructor: Context,
609
-
610
- reset: function(skipTempReset) {
611
- this.prev = 0;
612
- this.next = 0;
613
- // Resetting context._sent for legacy support of Babel's
614
- // function.sent implementation.
615
- this.sent = this._sent = undefined$1;
616
- this.done = false;
617
- this.delegate = null;
618
-
619
- this.method = "next";
620
- this.arg = undefined$1;
621
-
622
- this.tryEntries.forEach(resetTryEntry);
623
-
624
- if (!skipTempReset) {
625
- for (var name in this) {
626
- // Not sure about the optimal order of these conditions:
627
- if (name.charAt(0) === "t" &&
628
- hasOwn.call(this, name) &&
629
- !isNaN(+name.slice(1))) {
630
- this[name] = undefined$1;
631
- }
632
- }
633
- }
634
- },
635
-
636
- stop: function() {
637
- this.done = true;
638
-
639
- var rootEntry = this.tryEntries[0];
640
- var rootRecord = rootEntry.completion;
641
- if (rootRecord.type === "throw") {
642
- throw rootRecord.arg;
643
- }
644
-
645
- return this.rval;
646
- },
647
-
648
- dispatchException: function(exception) {
649
- if (this.done) {
650
- throw exception;
651
- }
652
-
653
- var context = this;
654
- function handle(loc, caught) {
655
- record.type = "throw";
656
- record.arg = exception;
657
- context.next = loc;
658
-
659
- if (caught) {
660
- // If the dispatched exception was caught by a catch block,
661
- // then let that catch block handle the exception normally.
662
- context.method = "next";
663
- context.arg = undefined$1;
664
- }
665
-
666
- return !! caught;
667
- }
668
-
669
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
670
- var entry = this.tryEntries[i];
671
- var record = entry.completion;
672
-
673
- if (entry.tryLoc === "root") {
674
- // Exception thrown outside of any try block that could handle
675
- // it, so set the completion value of the entire function to
676
- // throw the exception.
677
- return handle("end");
678
- }
679
-
680
- if (entry.tryLoc <= this.prev) {
681
- var hasCatch = hasOwn.call(entry, "catchLoc");
682
- var hasFinally = hasOwn.call(entry, "finallyLoc");
683
-
684
- if (hasCatch && hasFinally) {
685
- if (this.prev < entry.catchLoc) {
686
- return handle(entry.catchLoc, true);
687
- } else if (this.prev < entry.finallyLoc) {
688
- return handle(entry.finallyLoc);
689
- }
690
-
691
- } else if (hasCatch) {
692
- if (this.prev < entry.catchLoc) {
693
- return handle(entry.catchLoc, true);
694
- }
695
-
696
- } else if (hasFinally) {
697
- if (this.prev < entry.finallyLoc) {
698
- return handle(entry.finallyLoc);
699
- }
700
-
701
- } else {
702
- throw new Error("try statement without catch or finally");
703
- }
704
- }
705
- }
706
- },
707
-
708
- abrupt: function(type, arg) {
709
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
710
- var entry = this.tryEntries[i];
711
- if (entry.tryLoc <= this.prev &&
712
- hasOwn.call(entry, "finallyLoc") &&
713
- this.prev < entry.finallyLoc) {
714
- var finallyEntry = entry;
715
- break;
716
- }
717
- }
718
-
719
- if (finallyEntry &&
720
- (type === "break" ||
721
- type === "continue") &&
722
- finallyEntry.tryLoc <= arg &&
723
- arg <= finallyEntry.finallyLoc) {
724
- // Ignore the finally entry if control is not jumping to a
725
- // location outside the try/catch block.
726
- finallyEntry = null;
727
- }
728
-
729
- var record = finallyEntry ? finallyEntry.completion : {};
730
- record.type = type;
731
- record.arg = arg;
732
-
733
- if (finallyEntry) {
734
- this.method = "next";
735
- this.next = finallyEntry.finallyLoc;
736
- return ContinueSentinel;
737
- }
738
-
739
- return this.complete(record);
740
- },
741
-
742
- complete: function(record, afterLoc) {
743
- if (record.type === "throw") {
744
- throw record.arg;
745
- }
746
-
747
- if (record.type === "break" ||
748
- record.type === "continue") {
749
- this.next = record.arg;
750
- } else if (record.type === "return") {
751
- this.rval = this.arg = record.arg;
752
- this.method = "return";
753
- this.next = "end";
754
- } else if (record.type === "normal" && afterLoc) {
755
- this.next = afterLoc;
756
- }
757
-
758
- return ContinueSentinel;
759
- },
760
-
761
- finish: function(finallyLoc) {
762
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
763
- var entry = this.tryEntries[i];
764
- if (entry.finallyLoc === finallyLoc) {
765
- this.complete(entry.completion, entry.afterLoc);
766
- resetTryEntry(entry);
767
- return ContinueSentinel;
768
- }
769
- }
770
- },
771
-
772
- "catch": function(tryLoc) {
773
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
774
- var entry = this.tryEntries[i];
775
- if (entry.tryLoc === tryLoc) {
776
- var record = entry.completion;
777
- if (record.type === "throw") {
778
- var thrown = record.arg;
779
- resetTryEntry(entry);
780
- }
781
- return thrown;
782
- }
783
- }
784
-
785
- // The context.catch method must only be called with a location
786
- // argument that corresponds to a known catch block.
787
- throw new Error("illegal catch attempt");
788
- },
789
-
790
- delegateYield: function(iterable, resultName, nextLoc) {
791
- this.delegate = {
792
- iterator: values(iterable),
793
- resultName: resultName,
794
- nextLoc: nextLoc
795
- };
796
-
797
- if (this.method === "next") {
798
- // Deliberately forget the last sent value so that we don't
799
- // accidentally pass it on to the delegate.
800
- this.arg = undefined$1;
801
- }
802
-
803
- return ContinueSentinel;
804
- }
805
- };
806
-
807
- // Regardless of whether this script is executing as a CommonJS module
808
- // or not, return the runtime object so that we can declare the variable
809
- // regeneratorRuntime in the outer scope, which allows this module to be
810
- // injected easily by `bin/regenerator --include-runtime script.js`.
811
- return exports;
812
-
813
- }(
814
- // If this script is executing as a CommonJS module, use module.exports
815
- // as the regeneratorRuntime namespace. Otherwise create a new empty
816
- // object. Either way, the resulting object will be used to initialize
817
- // the regeneratorRuntime variable at the top of this file.
818
- module.exports
819
- ));
820
-
821
- try {
822
- regeneratorRuntime = runtime;
823
- } catch (accidentalStrictMode) {
824
- // This module should not be running in strict mode, so the above
825
- // assignment should always work unless something is misconfigured. Just
826
- // in case runtime.js accidentally runs in strict mode, we can escape
827
- // strict mode using a global Function call. This could conceivably fail
828
- // if a Content Security Policy forbids using Function, but in that case
829
- // the proper solution is to fix the accidental strict mode problem. If
830
- // you've misconfigured your bundler to force strict mode and applied a
831
- // CSP to forbid Function, and you're not willing to fix either of those
832
- // problems, please detail your unique predicament in a GitHub issue.
833
- Function("r", "regeneratorRuntime = r")(runtime);
834
- }
835
- });
836
-
837
- var trixPrefixSize = 5; // Define this object with .ixx and .ix files.
838
- // Then use the trixSearch() function to search for a word.
839
-
840
- var Trix = /*#__PURE__*/function () {
841
- /**
842
- * @param ixxFile [anyFile] the second-level trix index file produced by ixIxx.
843
- * @param ixFile [anyFile] the first-level trix index file produced by ixIxx.
844
- * @param maxResults [number] the maximum number of results to return. Default is set to 20.
845
- */
846
- function Trix(ixxFile, ixFile, maxResults) {
847
- if (maxResults === void 0) {
848
- maxResults = 20;
849
- }
850
-
851
- this.index = this._parseIxx(ixxFile);
852
- this.ixFile = ixFile;
853
- this.maxResults = maxResults;
854
- }
855
- /**
856
- * Search trix for the given searchWord(s). Return up to {this.maxResults} results.
857
- * This method matches each index prefix against each searchWord. It does not do fuzzy matching.
858
- *
859
- * @param searchString [string] term(s) separated by spaces to search for id(s).
860
- * @returns results [Array<string>] where each string is a corresponding itemId.
861
- */
862
-
863
-
864
- var _proto = Trix.prototype;
865
-
866
- _proto.search =
867
- /*#__PURE__*/
868
- function () {
869
- var _search = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(searchString) {
870
- var resultArr, firstWord, initialSet, searchWords, w, searchWord, bufData, buf, bufPos, resultSet, linePtr, numValues, startsWith, done, i, tempBufData, cur, line, arr, _iterator, _step, hit;
871
-
872
- return runtime_1.wrap(function _callee$(_context) {
873
- while (1) {
874
- switch (_context.prev = _context.next) {
875
- case 0:
876
- // If there is one search word, store results in resultArr.
877
- resultArr = []; // If there are multiple words, store results in initialSet.
878
- // firstWord indicates we are iterating the first time.
879
-
880
- firstWord = true;
881
- initialSet = new Set();
882
- searchWords = searchString.split(' '); // Loop for each word in searchWords.
883
- // If there are more than one searchWords, use resultSet and only take the matching terms
884
- // that are also in initialSet.
885
- // Otherwise, just iterate once and add words to resultArr.
886
-
887
- w = 0;
888
-
889
- case 5:
890
- if (!(w < searchWords.length)) {
891
- _context.next = 89;
892
- break;
893
- }
894
-
895
- searchWord = searchWords[w];
896
- searchWord = searchWord.toLowerCase(); // 1. Seek ahead to byte `this.index` of `ixFile`. Load this section of .ix data into the buffer.
897
-
898
- _context.next = 10;
899
- return this._getBuffer(searchWord);
900
-
901
- case 10:
902
- bufData = _context.sent;
903
- buf = bufData.buf;
904
- bufPos = bufData.bufEndPos;
905
- resultSet = new Set();
906
- linePtr = 0;
907
- numValues = 0; // 2. Iterate through the entire buffer
908
-
909
- case 16:
910
- if (!(linePtr < buf.byteLength)) {
911
- _context.next = 82;
912
- break;
913
- }
914
-
915
- startsWith = true;
916
- done = false;
917
- i = linePtr; // 3. Check if the first word in the current line has the same prefix as searchWord.
918
- // Iterate through each char of the line in the buffer.
919
- // break out of loop when we hit a \n (unicode char 10) or the searchWord does not match the line.
920
-
921
- case 20:
922
- if (!(buf[i] != 10)) {
923
- _context.next = 54;
924
- break;
925
- }
926
-
927
- if (!(i >= buf.byteLength)) {
928
- _context.next = 34;
929
- break;
930
- }
931
-
932
- _context.next = 24;
933
- return this._getNextChunk(bufPos);
934
-
935
- case 24:
936
- tempBufData = _context.sent;
937
-
938
- if (!tempBufData) {
939
- _context.next = 32;
940
- break;
941
- }
942
-
943
- buf = tempBufData.buf;
944
- bufPos = tempBufData.bufEndPos;
945
- i = 0;
946
- linePtr = 0;
947
- _context.next = 34;
948
- break;
949
-
950
- case 32:
951
- // If tempBufData is null, we reached the end of the file, so we are done.
952
- done = true;
953
- return _context.abrupt("break", 54);
954
-
955
- case 34:
956
- if (!startsWith) {
957
- _context.next = 51;
958
- break;
959
- }
960
-
961
- cur = String.fromCharCode(buf[i]);
962
-
963
- if (!(i < linePtr + searchWord.length && searchWord[i - linePtr] > cur)) {
964
- _context.next = 40;
965
- break;
966
- }
967
-
968
- // searchWord[i] > cur, so keep looping.
969
- startsWith = false;
970
- _context.next = 51;
971
- break;
972
-
973
- case 40:
974
- if (!(i < linePtr + searchWord.length && searchWord[i - linePtr] < cur)) {
975
- _context.next = 46;
976
- break;
977
- }
978
-
979
- // searchWord[i] < cur, so we lexicographically will not find any more results.
980
- startsWith = false;
981
- done = true;
982
- return _context.abrupt("break", 54);
983
-
984
- case 46:
985
- if (!(buf[i] === 44)) {
986
- _context.next = 51;
987
- break;
988
- }
989
-
990
- // We found a ',' so increment numValues by one.
991
- numValues++; // If we're searching for one word and we have enough results, break out at the next space.
992
-
993
- if (!(numValues >= this.maxResults && searchWords.length === 1)) {
994
- _context.next = 51;
995
- break;
996
- }
997
-
998
- while (buf[i] != 32) {
999
- i++;
1000
- }
1001
-
1002
- return _context.abrupt("break", 54);
1003
-
1004
- case 51:
1005
- i++;
1006
- _context.next = 20;
1007
- break;
1008
-
1009
- case 54:
1010
- if (!done) {
1011
- _context.next = 56;
1012
- break;
1013
- }
1014
-
1015
- return _context.abrupt("break", 82);
1016
-
1017
- case 56:
1018
- if (!startsWith) {
1019
- _context.next = 79;
1020
- break;
1021
- }
1022
-
1023
- // Parse the line and add results to arr.
1024
- line = buf.slice(linePtr, i).toString();
1025
- arr = this._parseHitString(line);
1026
-
1027
- if (!(searchWords.length === 1)) {
1028
- _context.next = 65;
1029
- break;
1030
- }
1031
-
1032
- // Only a single search word so add results to array.
1033
- resultArr = resultArr.concat(arr); // Once we have enough results, stop searching.
1034
-
1035
- if (!(resultArr.length >= this.maxResults)) {
1036
- _context.next = 63;
1037
- break;
1038
- }
1039
-
1040
- return _context.abrupt("break", 82);
1041
-
1042
- case 63:
1043
- _context.next = 79;
1044
- break;
1045
-
1046
- case 65:
1047
- _iterator = _createForOfIteratorHelperLoose(arr);
1048
-
1049
- case 66:
1050
- if ((_step = _iterator()).done) {
1051
- _context.next = 79;
1052
- break;
1053
- }
1054
-
1055
- hit = _step.value;
1056
- hit = hit.toLowerCase();
1057
-
1058
- if (!firstWord) {
1059
- _context.next = 73;
1060
- break;
1061
- }
1062
-
1063
- resultSet.add(hit);
1064
- _context.next = 77;
1065
- break;
1066
-
1067
- case 73:
1068
- if (!initialSet.has(hit)) {
1069
- _context.next = 77;
1070
- break;
1071
- }
1072
-
1073
- resultSet.add(hit); // If it is on the last iteration of words, break after we reach maxResults
1074
-
1075
- if (!(w === searchWords.length - 1 && resultSet.size >= this.maxResults)) {
1076
- _context.next = 77;
1077
- break;
1078
- }
1079
-
1080
- return _context.abrupt("break", 79);
1081
-
1082
- case 77:
1083
- _context.next = 66;
1084
- break;
1085
-
1086
- case 79:
1087
- linePtr = i + 1;
1088
- _context.next = 16;
1089
- break;
1090
-
1091
- case 82:
1092
- initialSet = resultSet;
1093
- firstWord = false; // If there aren't any results, stop looping, because an intersection with an empty set is an empty set.
1094
-
1095
- if (!(resultArr.length === 0 && initialSet.size === 0)) {
1096
- _context.next = 86;
1097
- break;
1098
- }
1099
-
1100
- return _context.abrupt("return", []);
1101
-
1102
- case 86:
1103
- w++;
1104
- _context.next = 5;
1105
- break;
1106
-
1107
- case 89:
1108
- if (!(searchWords.length === 1)) {
1109
- _context.next = 91;
1110
- break;
1111
- }
1112
-
1113
- return _context.abrupt("return", resultArr);
1114
-
1115
- case 91:
1116
- // Else we need to return our set converted to an array
1117
- resultArr = Array.from(initialSet);
1118
-
1119
- if (!(resultArr.length > this.maxResults)) {
1120
- _context.next = 94;
1121
- break;
1122
- }
1123
-
1124
- return _context.abrupt("return", resultArr.slice(0, this.maxResults));
1125
-
1126
- case 94:
1127
- return _context.abrupt("return", resultArr);
1128
-
1129
- case 95:
1130
- case "end":
1131
- return _context.stop();
1132
- }
1133
- }
1134
- }, _callee, this);
1135
- }));
1136
-
1137
- function search(_x) {
1138
- return _search.apply(this, arguments);
1139
- }
1140
-
1141
- return search;
1142
- }() // Private Methods:
1143
-
1144
- /**
1145
- * Seek ahead to the correct position in the .ix file,
1146
- * then load that chunk of .ix into a buffer.
1147
- *
1148
- * @param searchWord [string]
1149
- * @returns a Buffer holding the sections we want to search.
1150
- */
1151
- ;
1152
-
1153
- _proto._getBuffer =
1154
- /*#__PURE__*/
1155
- function () {
1156
- var _getBuffer2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(searchWord) {
1157
- var seekPosStart, seekPosEnd, indexes, _iterator2, _step2, _step2$value, key, value, trimmedKey;
1158
-
1159
- return runtime_1.wrap(function _callee2$(_context2) {
1160
- while (1) {
1161
- switch (_context2.prev = _context2.next) {
1162
- case 0:
1163
- // Get position to seek to in .ix file from indexes.
1164
- seekPosStart = 0;
1165
- seekPosEnd = -1;
1166
- _context2.next = 4;
1167
- return this.index;
1168
-
1169
- case 4:
1170
- indexes = _context2.sent;
1171
- _iterator2 = _createForOfIteratorHelperLoose(indexes);
1172
-
1173
- case 6:
1174
- if ((_step2 = _iterator2()).done) {
1175
- _context2.next = 18;
1176
- break;
1177
- }
1178
-
1179
- _step2$value = _step2.value, key = _step2$value[0], value = _step2$value[1];
1180
- trimmedKey = key.slice(0, searchWord.length);
1181
-
1182
- if (!(seekPosEnd === -1)) {
1183
- _context2.next = 16;
1184
- break;
1185
- }
1186
-
1187
- if (!(trimmedKey >= searchWord)) {
1188
- _context2.next = 15;
1189
- break;
1190
- }
1191
-
1192
- // We reached the end pos in the file.
1193
- seekPosEnd = value - 1;
1194
- return _context2.abrupt("break", 18);
1195
-
1196
- case 15:
1197
- seekPosStart = value;
1198
-
1199
- case 16:
1200
- _context2.next = 6;
1201
- break;
1202
-
1203
- case 18:
1204
- return _context2.abrupt("return", this._createBuffer(seekPosStart, seekPosEnd));
1205
-
1206
- case 19:
1207
- case "end":
1208
- return _context2.stop();
1209
- }
1210
- }
1211
- }, _callee2, this);
1212
- }));
1213
-
1214
- function _getBuffer(_x2) {
1215
- return _getBuffer2.apply(this, arguments);
1216
- }
1217
-
1218
- return _getBuffer;
1219
- }()
1220
- /**
1221
- * Given the end position of the last buffer,
1222
- * load the next chunk of .ix data into a buffer and return it.
1223
- *
1224
- * @param seekPosStart [number] where to start loading data into the new buffer.
1225
- * @returns a Buffer holding the chunk we want to search.
1226
- */
1227
- ;
1228
-
1229
- _proto._getNextChunk =
1230
- /*#__PURE__*/
1231
- function () {
1232
- var _getNextChunk2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(seekPosStart) {
1233
- var seekPosEnd, indexes, _iterator3, _step3, _step3$value, value;
1234
-
1235
- return runtime_1.wrap(function _callee3$(_context3) {
1236
- while (1) {
1237
- switch (_context3.prev = _context3.next) {
1238
- case 0:
1239
- if (!(seekPosStart == -1)) {
1240
- _context3.next = 2;
1241
- break;
1242
- }
1243
-
1244
- return _context3.abrupt("return", null);
1245
-
1246
- case 2:
1247
- seekPosEnd = -1; // Get the next position of the end of buffer.
1248
-
1249
- _context3.next = 5;
1250
- return this.index;
1251
-
1252
- case 5:
1253
- indexes = _context3.sent;
1254
- _iterator3 = _createForOfIteratorHelperLoose(indexes);
1255
-
1256
- case 7:
1257
- if ((_step3 = _iterator3()).done) {
1258
- _context3.next = 15;
1259
- break;
1260
- }
1261
-
1262
- _step3$value = _step3.value, value = _step3$value[1];
1263
-
1264
- if (!(value <= seekPosStart + 1)) {
1265
- _context3.next = 11;
1266
- break;
1267
- }
1268
-
1269
- return _context3.abrupt("continue", 13);
1270
-
1271
- case 11:
1272
- seekPosEnd = value;
1273
- return _context3.abrupt("break", 15);
1274
-
1275
- case 13:
1276
- _context3.next = 7;
1277
- break;
1278
-
1279
- case 15:
1280
- seekPosStart--; // Return the buffer and its end position in the file.
1281
-
1282
- return _context3.abrupt("return", this._createBuffer(seekPosStart, seekPosEnd));
1283
-
1284
- case 17:
1285
- case "end":
1286
- return _context3.stop();
1287
- }
1288
- }
1289
- }, _callee3, this);
1290
- }));
1291
-
1292
- function _getNextChunk(_x3) {
1293
- return _getNextChunk2.apply(this, arguments);
1294
- }
1295
-
1296
- return _getNextChunk;
1297
- }()
1298
- /**
1299
- * Create and return a buffer given the start and end position
1300
- * of what to load from the .ix file.
1301
- *
1302
- * @param seekPosStart [number] byte the buffer should start reading from file.
1303
- * @param seekPosEnd [number] byte the buffer should stop reading from file.
1304
- * @returns a Buffer holding the chunk of data.
1305
- */
1306
- ;
1307
-
1308
- _proto._createBuffer =
1309
- /*#__PURE__*/
1310
- function () {
1311
- var _createBuffer2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(seekPosStart, seekPosEnd) {
1312
- var bufLength, stat, buf;
1313
- return runtime_1.wrap(function _callee4$(_context4) {
1314
- while (1) {
1315
- switch (_context4.prev = _context4.next) {
1316
- case 0:
1317
- if (!(seekPosEnd < 0)) {
1318
- _context4.next = 7;
1319
- break;
1320
- }
1321
-
1322
- _context4.next = 3;
1323
- return this.ixFile.stat();
1324
-
1325
- case 3:
1326
- stat = _context4.sent;
1327
- bufLength = stat.size - seekPosStart;
1328
- _context4.next = 8;
1329
- break;
1330
-
1331
- case 7:
1332
- bufLength = seekPosEnd - seekPosStart;
1333
-
1334
- case 8:
1335
- buf = Buffer.alloc(bufLength);
1336
- _context4.next = 11;
1337
- return this.ixFile.read(buf, 0, bufLength, seekPosStart);
1338
-
1339
- case 11:
1340
- return _context4.abrupt("return", {
1341
- buf: buf,
1342
- bufEndPos: seekPosEnd
1343
- });
1344
-
1345
- case 12:
1346
- case "end":
1347
- return _context4.stop();
1348
- }
1349
- }
1350
- }, _callee4, this);
1351
- }));
1352
-
1353
- function _createBuffer(_x4, _x5) {
1354
- return _createBuffer2.apply(this, arguments);
1355
- }
1356
-
1357
- return _createBuffer;
1358
- }()
1359
- /**
1360
- * Takes in a hit string and returns an array of result terms.
1361
- *
1362
- * @param line [string] The line of .ix that is a hit.
1363
- * @returns results [Array<hit>]. Each hit contains the itemId [string], and wordPos [number].
1364
- */
1365
- ;
1366
-
1367
- _proto._parseHitString = function _parseHitString(line) {
1368
- var arr = [];
1369
- var parts = line.split(' ').slice(1); // skip term
1370
- // Each result is of format: "{itemId},{wordPos}"
1371
- // Parse the entire line of these and return
1372
-
1373
- for (var _iterator4 = _createForOfIteratorHelperLoose(parts), _step4; !(_step4 = _iterator4()).done;) {
1374
- var part = _step4.value;
1375
- var pair = part.split(',');
1376
-
1377
- if (pair.length === 2) {
1378
- var itemId = pair[0];
1379
- var wordPos = Number.parseInt(pair[1]);
1380
- if (typeof wordPos !== 'number' || isNaN(wordPos)) throw new Error("Error in ix index format at term " + itemId + " for word " + parts[0]);
1381
- arr.push(itemId);
1382
- } else if (pair.length > 1) {
1383
- throw new Error("Error in ix index format at word " + parts[0]);
1384
- }
1385
- }
1386
-
1387
- return arr;
1388
- }
1389
- /**
1390
- * Parses ixx file and constructs a map of {word: ixFileLocation}
1391
- *
1392
- * @param ixxFile [anyFile] second level index that is produced by ixIxx.
1393
- * @returns a ParsedIxx map.
1394
- */
1395
- ;
1396
-
1397
- _proto._parseIxx =
1398
- /*#__PURE__*/
1399
- function () {
1400
- var _parseIxx2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(ixxFile) {
1401
- var ixx, buf, lines, _iterator5, _step5, line, prefix, posStr, pos;
1402
-
1403
- return runtime_1.wrap(function _callee5$(_context5) {
1404
- while (1) {
1405
- switch (_context5.prev = _context5.next) {
1406
- case 0:
1407
- ixx = new Map(); // Load the ixxFile into ixxData object
1408
-
1409
- _context5.next = 3;
1410
- return ixxFile.readFile();
1411
-
1412
- case 3:
1413
- buf = _context5.sent;
1414
- lines = buf.toString('utf8').split('\n');
1415
- _iterator5 = _createForOfIteratorHelperLoose(lines);
1416
-
1417
- case 6:
1418
- if ((_step5 = _iterator5()).done) {
1419
- _context5.next = 17;
1420
- break;
1421
- }
1422
-
1423
- line = _step5.value;
1424
-
1425
- if (!(line.length > 0)) {
1426
- _context5.next = 15;
1427
- break;
1428
- }
1429
-
1430
- // Parse the ixx line
1431
- // Format: 5 characters prefix, 10 characters hex
1432
- prefix = line.substr(0, trixPrefixSize);
1433
- posStr = line.substr(trixPrefixSize);
1434
- pos = Number.parseInt(posStr, 16);
1435
-
1436
- if (!(typeof pos !== 'number' || isNaN(pos))) {
1437
- _context5.next = 14;
1438
- break;
1439
- }
1440
-
1441
- throw new Error("Error in ixx index format at word " + prefix);
1442
-
1443
- case 14:
1444
- ixx.set(prefix, pos);
1445
-
1446
- case 15:
1447
- _context5.next = 6;
1448
- break;
1449
-
1450
- case 17:
1451
- return _context5.abrupt("return", ixx);
1452
-
1453
- case 18:
1454
- case "end":
1455
- return _context5.stop();
1456
- }
1457
- }
1458
- }, _callee5);
1459
- }));
1460
-
1461
- function _parseIxx(_x6) {
1462
- return _parseIxx2.apply(this, arguments);
1463
- }
1464
-
1465
- return _parseIxx;
1466
- }();
1467
-
1468
- return Trix;
1469
- }();
1470
-
1471
- exports.default = Trix;
1472
- //# sourceMappingURL=trix.cjs.development.js.map