@variousjs/various 5.1.2 → 5.1.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.
@@ -23,6 +23,2164 @@ function _extends() {
23
23
  }
24
24
 
25
25
 
26
+ /***/ }),
27
+
28
+ /***/ "./node_modules/@variousjs/requirejs/require.js":
29
+ /*!******************************************************!*\
30
+ !*** ./node_modules/@variousjs/requirejs/require.js ***!
31
+ \******************************************************/
32
+ /***/ (function() {
33
+
34
+ /** vim: et:ts=4:sw=4:sts=4
35
+ * @license RequireJS 2.3.6 Copyright jQuery Foundation and other contributors.
36
+ * Released under MIT license, https://github.com/requirejs/requirejs/blob/master/LICENSE
37
+ */
38
+ //Not using strict: uneven strict support in browsers, #392, and causes
39
+ //problems with requirejs.exec()/transpiler plugins that may not be strict.
40
+ /*jslint regexp: true, nomen: true, sloppy: true */
41
+ /*global window, navigator, document, importScripts, setTimeout, opera */
42
+
43
+ var requirejs, require, define;
44
+ (function (global, setTimeout) {
45
+ var req, s, head, baseElement, dataMain, src,
46
+ interactiveScript, currentlyAddingScript, mainScript, subPath,
47
+ version = '2.3.6',
48
+ commentRegExp = /\/\*[\s\S]*?\*\/|([^:"'=]|^)\/\/.*$/mg,
49
+ cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
50
+ jsSuffixRegExp = /\.js$/,
51
+ currDirRegExp = /^\.\//,
52
+ op = Object.prototype,
53
+ ostring = op.toString,
54
+ hasOwn = op.hasOwnProperty,
55
+ isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document),
56
+ isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
57
+ //PS3 indicates loaded and complete, but need to wait for complete
58
+ //specifically. Sequence is 'loading', 'loaded', execution,
59
+ // then 'complete'. The UA check is unfortunate, but not sure how
60
+ //to feature test w/o causing perf issues.
61
+ readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ?
62
+ /^complete$/ : /^(complete|loaded)$/,
63
+ defContextName = '_',
64
+ //Oh the tragedy, detecting opera. See the usage of isOpera for reason.
65
+ isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]',
66
+ contexts = {},
67
+ cfg = {},
68
+ globalDefQueue = [],
69
+ useInteractive = false;
70
+
71
+ //Could match something like ')//comment', do not lose the prefix to comment.
72
+ function commentReplace(match, singlePrefix) {
73
+ return singlePrefix || '';
74
+ }
75
+
76
+ function isFunction(it) {
77
+ return ostring.call(it) === '[object Function]';
78
+ }
79
+
80
+ function isArray(it) {
81
+ return ostring.call(it) === '[object Array]';
82
+ }
83
+
84
+ /**
85
+ * Helper function for iterating over an array. If the func returns
86
+ * a true value, it will break out of the loop.
87
+ */
88
+ function each(ary, func) {
89
+ if (ary) {
90
+ var i;
91
+ for (i = 0; i < ary.length; i += 1) {
92
+ if (ary[i] && func(ary[i], i, ary)) {
93
+ break;
94
+ }
95
+ }
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Helper function for iterating over an array backwards. If the func
101
+ * returns a true value, it will break out of the loop.
102
+ */
103
+ function eachReverse(ary, func) {
104
+ if (ary) {
105
+ var i;
106
+ for (i = ary.length - 1; i > -1; i -= 1) {
107
+ if (ary[i] && func(ary[i], i, ary)) {
108
+ break;
109
+ }
110
+ }
111
+ }
112
+ }
113
+
114
+ function hasProp(obj, prop) {
115
+ return hasOwn.call(obj, prop);
116
+ }
117
+
118
+ function getOwn(obj, prop) {
119
+ return hasProp(obj, prop) && obj[prop];
120
+ }
121
+
122
+ /**
123
+ * Cycles over properties in an object and calls a function for each
124
+ * property value. If the function returns a truthy value, then the
125
+ * iteration is stopped.
126
+ */
127
+ function eachProp(obj, func) {
128
+ var prop;
129
+ for (prop in obj) {
130
+ if (hasProp(obj, prop)) {
131
+ if (func(obj[prop], prop)) {
132
+ break;
133
+ }
134
+ }
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Simple function to mix in properties from source into target,
140
+ * but only if target does not already have a property of the same name.
141
+ */
142
+ function mixin(target, source, force, deepStringMixin) {
143
+ if (source) {
144
+ eachProp(source, function (value, prop) {
145
+ if (force || !hasProp(target, prop)) {
146
+ if (deepStringMixin && typeof value === 'object' && value &&
147
+ !isArray(value) && !isFunction(value) &&
148
+ !(value instanceof RegExp)) {
149
+
150
+ if (!target[prop]) {
151
+ target[prop] = {};
152
+ }
153
+ mixin(target[prop], value, force, deepStringMixin);
154
+ } else {
155
+ target[prop] = value;
156
+ }
157
+ }
158
+ });
159
+ }
160
+ return target;
161
+ }
162
+
163
+ //Similar to Function.prototype.bind, but the 'this' object is specified
164
+ //first, since it is easier to read/figure out what 'this' will be.
165
+ function bind(obj, fn) {
166
+ return function () {
167
+ return fn.apply(obj, arguments);
168
+ };
169
+ }
170
+
171
+ function scripts() {
172
+ return document.getElementsByTagName('script');
173
+ }
174
+
175
+ function defaultOnError(err) {
176
+ throw err;
177
+ }
178
+
179
+ //Allow getting a global that is expressed in
180
+ //dot notation, like 'a.b.c'.
181
+ function getGlobal(value) {
182
+ if (!value) {
183
+ return value;
184
+ }
185
+ var g = global;
186
+ each(value.split('.'), function (part) {
187
+ g = g[part];
188
+ });
189
+ return g;
190
+ }
191
+
192
+ /**
193
+ * Constructs an error with a pointer to an URL with more information.
194
+ * @param {String} id the error ID that maps to an ID on a web page.
195
+ * @param {String} message human readable error.
196
+ * @param {Error} [err] the original error, if there is one.
197
+ *
198
+ * @returns {Error}
199
+ */
200
+ function makeError(id, msg, err, requireModules) {
201
+ var e = new Error(msg + '\nhttps://requirejs.org/docs/errors.html#' + id);
202
+ e.requireType = id;
203
+ e.requireModules = requireModules;
204
+ if (err) {
205
+ e.originalError = err;
206
+ }
207
+ return e;
208
+ }
209
+
210
+ if (typeof define !== 'undefined') {
211
+ //If a define is already in play via another AMD loader,
212
+ //do not overwrite.
213
+ return;
214
+ }
215
+
216
+ if (typeof requirejs !== 'undefined') {
217
+ if (isFunction(requirejs)) {
218
+ //Do not overwrite an existing requirejs instance.
219
+ return;
220
+ }
221
+ cfg = requirejs;
222
+ requirejs = undefined;
223
+ }
224
+
225
+ //Allow for a require config object
226
+ if (typeof require !== 'undefined' && !isFunction(require)) {
227
+ //assume it is a config object.
228
+ cfg = require;
229
+ require = undefined;
230
+ }
231
+
232
+ function newContext(contextName) {
233
+ var inCheckLoaded, Module, context, handlers,
234
+ checkLoadedTimeoutId,
235
+ config = {
236
+ //Defaults. Do not set a default for map
237
+ //config to speed up normalize(), which
238
+ //will run faster if there is no default.
239
+ waitSeconds: 7,
240
+ baseUrl: './',
241
+ paths: {},
242
+ bundles: {},
243
+ pkgs: {},
244
+ shim: {},
245
+ config: {}
246
+ },
247
+ registry = {},
248
+ //registry of just enabled modules, to speed
249
+ //cycle breaking code when lots of modules
250
+ //are registered, but not activated.
251
+ enabledRegistry = {},
252
+ undefEvents = {},
253
+ defQueue = [],
254
+ defined = {},
255
+ urlFetched = {},
256
+ bundlesMap = {},
257
+ requireCounter = 1,
258
+ unnormalizedCounter = 1;
259
+
260
+ /**
261
+ * Trims the . and .. from an array of path segments.
262
+ * It will keep a leading path segment if a .. will become
263
+ * the first path segment, to help with module name lookups,
264
+ * which act like paths, but can be remapped. But the end result,
265
+ * all paths that use this function should look normalized.
266
+ * NOTE: this method MODIFIES the input array.
267
+ * @param {Array} ary the array of path segments.
268
+ */
269
+ function trimDots(ary) {
270
+ var i, part;
271
+ for (i = 0; i < ary.length; i++) {
272
+ part = ary[i];
273
+ if (part === '.') {
274
+ ary.splice(i, 1);
275
+ i -= 1;
276
+ } else if (part === '..') {
277
+ // If at the start, or previous value is still ..,
278
+ // keep them so that when converted to a path it may
279
+ // still work when converted to a path, even though
280
+ // as an ID it is less than ideal. In larger point
281
+ // releases, may be better to just kick out an error.
282
+ if (i === 0 || (i === 1 && ary[2] === '..') || ary[i - 1] === '..') {
283
+ continue;
284
+ } else if (i > 0) {
285
+ ary.splice(i - 1, 2);
286
+ i -= 2;
287
+ }
288
+ }
289
+ }
290
+ }
291
+
292
+ /**
293
+ * Given a relative module name, like ./something, normalize it to
294
+ * a real name that can be mapped to a path.
295
+ * @param {String} name the relative name
296
+ * @param {String} baseName a real name that the name arg is relative
297
+ * to.
298
+ * @param {Boolean} applyMap apply the map config to the value. Should
299
+ * only be done if this normalization is for a dependency ID.
300
+ * @returns {String} normalized name
301
+ */
302
+ function normalize(name, baseName, applyMap) {
303
+ var pkgMain, mapValue, nameParts, i, j, nameSegment, lastIndex,
304
+ foundMap, foundI, foundStarMap, starI, normalizedBaseParts,
305
+ baseParts = (baseName && baseName.split('/')),
306
+ map = config.map,
307
+ starMap = map && map['*'];
308
+
309
+ //Adjust any relative paths.
310
+ if (name) {
311
+ name = name.split('/');
312
+ lastIndex = name.length - 1;
313
+
314
+ // If wanting node ID compatibility, strip .js from end
315
+ // of IDs. Have to do this here, and not in nameToUrl
316
+ // because node allows either .js or non .js to map
317
+ // to same file.
318
+ if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
319
+ name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
320
+ }
321
+
322
+ // Starts with a '.' so need the baseName
323
+ if (name[0].charAt(0) === '.' && baseParts) {
324
+ //Convert baseName to array, and lop off the last part,
325
+ //so that . matches that 'directory' and not name of the baseName's
326
+ //module. For instance, baseName of 'one/two/three', maps to
327
+ //'one/two/three.js', but we want the directory, 'one/two' for
328
+ //this normalization.
329
+ normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
330
+ name = normalizedBaseParts.concat(name);
331
+ }
332
+
333
+ trimDots(name);
334
+ name = name.join('/');
335
+ }
336
+
337
+ //Apply map config if available.
338
+ if (applyMap && map && (baseParts || starMap)) {
339
+ nameParts = name.split('/');
340
+
341
+ outerLoop: for (i = nameParts.length; i > 0; i -= 1) {
342
+ nameSegment = nameParts.slice(0, i).join('/');
343
+
344
+ if (baseParts) {
345
+ //Find the longest baseName segment match in the config.
346
+ //So, do joins on the biggest to smallest lengths of baseParts.
347
+ for (j = baseParts.length; j > 0; j -= 1) {
348
+ mapValue = getOwn(map, baseParts.slice(0, j).join('/'));
349
+
350
+ //baseName segment has config, find if it has one for
351
+ //this name.
352
+ if (mapValue) {
353
+ mapValue = getOwn(mapValue, nameSegment);
354
+ if (mapValue) {
355
+ //Match, update name to the new value.
356
+ foundMap = mapValue;
357
+ foundI = i;
358
+ break outerLoop;
359
+ }
360
+ }
361
+ }
362
+ }
363
+
364
+ //Check for a star map match, but just hold on to it,
365
+ //if there is a shorter segment match later in a matching
366
+ //config, then favor over this star map.
367
+ if (!foundStarMap && starMap && getOwn(starMap, nameSegment)) {
368
+ foundStarMap = getOwn(starMap, nameSegment);
369
+ starI = i;
370
+ }
371
+ }
372
+
373
+ if (!foundMap && foundStarMap) {
374
+ foundMap = foundStarMap;
375
+ foundI = starI;
376
+ }
377
+
378
+ if (foundMap) {
379
+ nameParts.splice(0, foundI, foundMap);
380
+ name = nameParts.join('/');
381
+ }
382
+ }
383
+
384
+ // If the name points to a package's name, use
385
+ // the package main instead.
386
+ pkgMain = getOwn(config.pkgs, name);
387
+
388
+ return pkgMain ? pkgMain : name;
389
+ }
390
+
391
+ function removeScript(name) {
392
+ if (isBrowser) {
393
+ each(scripts(), function (scriptNode) {
394
+ if (scriptNode.getAttribute('data-requiremodule') === name &&
395
+ scriptNode.getAttribute('data-requirecontext') === context.contextName) {
396
+ scriptNode.parentNode.removeChild(scriptNode);
397
+ return true;
398
+ }
399
+ });
400
+ }
401
+ }
402
+
403
+ function hasPathFallback(id) {
404
+ var pathConfig = getOwn(config.paths, id);
405
+ if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) {
406
+ //Pop off the first array value, since it failed, and
407
+ //retry
408
+ pathConfig.shift();
409
+ context.require.undef(id);
410
+
411
+ //Custom require that does not do map translation, since
412
+ //ID is "absolute", already mapped/resolved.
413
+ context.makeRequire(null, {
414
+ skipMap: true
415
+ })([id]);
416
+
417
+ return true;
418
+ }
419
+ }
420
+
421
+ //Turns a plugin!resource to [plugin, resource]
422
+ //with the plugin being undefined if the name
423
+ //did not have a plugin prefix.
424
+ function splitPrefix(name) {
425
+ var prefix,
426
+ index = name ? name.indexOf('!') : -1;
427
+ if (index > -1) {
428
+ prefix = name.substring(0, index);
429
+ name = name.substring(index + 1, name.length);
430
+ }
431
+ return [prefix, name];
432
+ }
433
+
434
+ /**
435
+ * Creates a module mapping that includes plugin prefix, module
436
+ * name, and path. If parentModuleMap is provided it will
437
+ * also normalize the name via require.normalize()
438
+ *
439
+ * @param {String} name the module name
440
+ * @param {String} [parentModuleMap] parent module map
441
+ * for the module name, used to resolve relative names.
442
+ * @param {Boolean} isNormalized: is the ID already normalized.
443
+ * This is true if this call is done for a define() module ID.
444
+ * @param {Boolean} applyMap: apply the map config to the ID.
445
+ * Should only be true if this map is for a dependency.
446
+ *
447
+ * @returns {Object}
448
+ */
449
+ function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) {
450
+ var url, pluginModule, suffix, nameParts,
451
+ prefix = null,
452
+ parentName = parentModuleMap ? parentModuleMap.name : null,
453
+ originalName = name,
454
+ isDefine = true,
455
+ normalizedName = '';
456
+
457
+ //If no name, then it means it is a require call, generate an
458
+ //internal name.
459
+ if (!name) {
460
+ isDefine = false;
461
+ name = '_@r' + (requireCounter += 1);
462
+ }
463
+
464
+ nameParts = splitPrefix(name);
465
+ prefix = nameParts[0];
466
+ name = nameParts[1];
467
+
468
+ if (prefix) {
469
+ prefix = normalize(prefix, parentName, applyMap);
470
+ pluginModule = getOwn(defined, prefix);
471
+ }
472
+
473
+ //Account for relative paths if there is a base name.
474
+ if (name) {
475
+ if (prefix) {
476
+ if (isNormalized) {
477
+ normalizedName = name;
478
+ } else if (pluginModule && pluginModule.normalize) {
479
+ //Plugin is loaded, use its normalize method.
480
+ normalizedName = pluginModule.normalize(name, function (name) {
481
+ return normalize(name, parentName, applyMap);
482
+ });
483
+ } else {
484
+ // If nested plugin references, then do not try to
485
+ // normalize, as it will not normalize correctly. This
486
+ // places a restriction on resourceIds, and the longer
487
+ // term solution is not to normalize until plugins are
488
+ // loaded and all normalizations to allow for async
489
+ // loading of a loader plugin. But for now, fixes the
490
+ // common uses. Details in #1131
491
+ normalizedName = name.indexOf('!') === -1 ?
492
+ normalize(name, parentName, applyMap) :
493
+ name;
494
+ }
495
+ } else {
496
+ //A regular module.
497
+ normalizedName = normalize(name, parentName, applyMap);
498
+
499
+ //Normalized name may be a plugin ID due to map config
500
+ //application in normalize. The map config values must
501
+ //already be normalized, so do not need to redo that part.
502
+ nameParts = splitPrefix(normalizedName);
503
+ prefix = nameParts[0];
504
+ normalizedName = nameParts[1];
505
+ isNormalized = true;
506
+
507
+ url = context.nameToUrl(normalizedName);
508
+ }
509
+ }
510
+
511
+ //If the id is a plugin id that cannot be determined if it needs
512
+ //normalization, stamp it with a unique ID so two matching relative
513
+ //ids that may conflict can be separate.
514
+ suffix = prefix && !pluginModule && !isNormalized ?
515
+ '_unnormalized' + (unnormalizedCounter += 1) :
516
+ '';
517
+
518
+ return {
519
+ prefix: prefix,
520
+ name: normalizedName,
521
+ parentMap: parentModuleMap,
522
+ unnormalized: !!suffix,
523
+ url: url,
524
+ originalName: originalName,
525
+ isDefine: isDefine,
526
+ id: (prefix ?
527
+ prefix + '!' + normalizedName :
528
+ normalizedName) + suffix
529
+ };
530
+ }
531
+
532
+ function getModule(depMap) {
533
+ var id = depMap.id,
534
+ mod = getOwn(registry, id);
535
+
536
+ if (!mod) {
537
+ mod = registry[id] = new context.Module(depMap);
538
+ }
539
+
540
+ return mod;
541
+ }
542
+
543
+ function on(depMap, name, fn) {
544
+ var id = depMap.id,
545
+ mod = getOwn(registry, id);
546
+
547
+ if (hasProp(defined, id) &&
548
+ (!mod || mod.defineEmitComplete)) {
549
+ if (name === 'defined') {
550
+ fn(defined[id]);
551
+ }
552
+ } else {
553
+ mod = getModule(depMap);
554
+ if (mod.error && name === 'error') {
555
+ fn(mod.error);
556
+ } else {
557
+ mod.on(name, fn);
558
+ }
559
+ }
560
+ }
561
+
562
+ function onError(err, errback) {
563
+ var ids = err.requireModules,
564
+ notified = false;
565
+
566
+ if (errback) {
567
+ errback(err);
568
+ } else {
569
+ each(ids, function (id) {
570
+ var mod = getOwn(registry, id);
571
+ if (mod) {
572
+ //Set error on module, so it skips timeout checks.
573
+ mod.error = err;
574
+ if (mod.events.error) {
575
+ notified = true;
576
+ mod.emit('error', err);
577
+ }
578
+ }
579
+ });
580
+
581
+ if (!notified) {
582
+ req.onError(err);
583
+ }
584
+ }
585
+ }
586
+
587
+ /**
588
+ * Internal method to transfer globalQueue items to this context's
589
+ * defQueue.
590
+ */
591
+ function takeGlobalQueue() {
592
+ //Push all the globalDefQueue items into the context's defQueue
593
+ if (globalDefQueue.length) {
594
+ each(globalDefQueue, function(queueItem) {
595
+ var id = queueItem[0];
596
+ if (typeof id === 'string') {
597
+ context.defQueueMap[id] = true;
598
+ }
599
+ defQueue.push(queueItem);
600
+ });
601
+ globalDefQueue = [];
602
+ }
603
+ }
604
+
605
+ handlers = {
606
+ 'require': function (mod) {
607
+ if (mod.require) {
608
+ return mod.require;
609
+ } else {
610
+ return (mod.require = context.makeRequire(mod.map));
611
+ }
612
+ },
613
+ 'exports': function (mod) {
614
+ mod.usingExports = true;
615
+ if (mod.map.isDefine) {
616
+ if (mod.exports) {
617
+ return (defined[mod.map.id] = mod.exports);
618
+ } else {
619
+ return (mod.exports = defined[mod.map.id] = {});
620
+ }
621
+ }
622
+ },
623
+ 'module': function (mod) {
624
+ if (mod.module) {
625
+ return mod.module;
626
+ } else {
627
+ return (mod.module = {
628
+ id: mod.map.id,
629
+ uri: mod.map.url,
630
+ config: function () {
631
+ return getOwn(config.config, mod.map.id) || {};
632
+ },
633
+ exports: mod.exports || (mod.exports = {})
634
+ });
635
+ }
636
+ }
637
+ };
638
+
639
+ function cleanRegistry(id) {
640
+ //Clean up machinery used for waiting modules.
641
+ delete registry[id];
642
+ delete enabledRegistry[id];
643
+ }
644
+
645
+ function breakCycle(mod, traced, processed) {
646
+ var id = mod.map.id;
647
+
648
+ if (mod.error) {
649
+ mod.emit('error', mod.error);
650
+ } else {
651
+ traced[id] = true;
652
+ each(mod.depMaps, function (depMap, i) {
653
+ var depId = depMap.id,
654
+ dep = getOwn(registry, depId);
655
+
656
+ //Only force things that have not completed
657
+ //being defined, so still in the registry,
658
+ //and only if it has not been matched up
659
+ //in the module already.
660
+ if (dep && !mod.depMatched[i] && !processed[depId]) {
661
+ if (getOwn(traced, depId)) {
662
+ mod.defineDep(i, defined[depId]);
663
+ mod.check(); //pass false?
664
+ } else {
665
+ breakCycle(dep, traced, processed);
666
+ }
667
+ }
668
+ });
669
+ processed[id] = true;
670
+ }
671
+ }
672
+
673
+ function checkLoaded() {
674
+ var err, usingPathFallback,
675
+ waitInterval = config.waitSeconds * 1000,
676
+ //It is possible to disable the wait interval by using waitSeconds of 0.
677
+ expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
678
+ noLoads = [],
679
+ reqCalls = [],
680
+ stillLoading = false,
681
+ needCycleCheck = true;
682
+
683
+ //Do not bother if this call was a result of a cycle break.
684
+ if (inCheckLoaded) {
685
+ return;
686
+ }
687
+
688
+ inCheckLoaded = true;
689
+
690
+ //Figure out the state of all the modules.
691
+ eachProp(enabledRegistry, function (mod) {
692
+ var map = mod.map,
693
+ modId = map.id;
694
+
695
+ //Skip things that are not enabled or in error state.
696
+ if (!mod.enabled) {
697
+ return;
698
+ }
699
+
700
+ if (!map.isDefine) {
701
+ reqCalls.push(mod);
702
+ }
703
+
704
+ if (!mod.error) {
705
+ //If the module should be executed, and it has not
706
+ //been inited and time is up, remember it.
707
+ if (!mod.inited && expired) {
708
+ if (hasPathFallback(modId)) {
709
+ usingPathFallback = true;
710
+ stillLoading = true;
711
+ } else {
712
+ noLoads.push(modId);
713
+ removeScript(modId);
714
+ }
715
+ } else if (!mod.inited && mod.fetched && map.isDefine) {
716
+ stillLoading = true;
717
+ if (!map.prefix) {
718
+ //No reason to keep looking for unfinished
719
+ //loading. If the only stillLoading is a
720
+ //plugin resource though, keep going,
721
+ //because it may be that a plugin resource
722
+ //is waiting on a non-plugin cycle.
723
+ return (needCycleCheck = false);
724
+ }
725
+ }
726
+ }
727
+ });
728
+
729
+ if (expired && noLoads.length) {
730
+ //If wait time expired, throw error of unloaded modules.
731
+ err = makeError('timeout', 'Load timeout for modules: ' + noLoads, null, noLoads);
732
+ err.contextName = context.contextName;
733
+ return onError(err);
734
+ }
735
+
736
+ //Not expired, check for a cycle.
737
+ if (needCycleCheck) {
738
+ each(reqCalls, function (mod) {
739
+ breakCycle(mod, {}, {});
740
+ });
741
+ }
742
+
743
+ //If still waiting on loads, and the waiting load is something
744
+ //other than a plugin resource, or there are still outstanding
745
+ //scripts, then just try back later.
746
+ if ((!expired || usingPathFallback) && stillLoading) {
747
+ //Something is still waiting to load. Wait for it, but only
748
+ //if a timeout is not already in effect.
749
+ if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
750
+ checkLoadedTimeoutId = setTimeout(function () {
751
+ checkLoadedTimeoutId = 0;
752
+ checkLoaded();
753
+ }, 50);
754
+ }
755
+ }
756
+
757
+ inCheckLoaded = false;
758
+ }
759
+
760
+ Module = function (map) {
761
+ this.events = getOwn(undefEvents, map.id) || {};
762
+ this.map = map;
763
+ this.shim = getOwn(config.shim, map.id);
764
+ this.depExports = [];
765
+ this.depMaps = [];
766
+ this.depMatched = [];
767
+ this.pluginMaps = {};
768
+ this.depCount = 0;
769
+
770
+ /* this.exports this.factory
771
+ this.depMaps = [],
772
+ this.enabled, this.fetched
773
+ */
774
+ };
775
+
776
+ Module.prototype = {
777
+ init: function (depMaps, factory, errback, options) {
778
+ options = options || {};
779
+
780
+ //Do not do more inits if already done. Can happen if there
781
+ //are multiple define calls for the same module. That is not
782
+ //a normal, common case, but it is also not unexpected.
783
+ if (this.inited) {
784
+ return;
785
+ }
786
+
787
+ this.factory = factory;
788
+
789
+ if (errback) {
790
+ //Register for errors on this module.
791
+ this.on('error', errback);
792
+ } else if (this.events.error) {
793
+ //If no errback already, but there are error listeners
794
+ //on this module, set up an errback to pass to the deps.
795
+ errback = bind(this, function (err) {
796
+ this.emit('error', err);
797
+ });
798
+ }
799
+
800
+ //Do a copy of the dependency array, so that
801
+ //source inputs are not modified. For example
802
+ //"shim" deps are passed in here directly, and
803
+ //doing a direct modification of the depMaps array
804
+ //would affect that config.
805
+ this.depMaps = depMaps && depMaps.slice(0);
806
+
807
+ this.errback = errback;
808
+
809
+ //Indicate this module has be initialized
810
+ this.inited = true;
811
+
812
+ this.ignore = options.ignore;
813
+
814
+ //Could have option to init this module in enabled mode,
815
+ //or could have been previously marked as enabled. However,
816
+ //the dependencies are not known until init is called. So
817
+ //if enabled previously, now trigger dependencies as enabled.
818
+ if (options.enabled || this.enabled) {
819
+ //Enable this module and dependencies.
820
+ //Will call this.check()
821
+ this.enable();
822
+ } else {
823
+ this.check();
824
+ }
825
+ },
826
+
827
+ defineDep: function (i, depExports) {
828
+ //Because of cycles, defined callback for a given
829
+ //export can be called more than once.
830
+ if (!this.depMatched[i]) {
831
+ this.depMatched[i] = true;
832
+ this.depCount -= 1;
833
+ this.depExports[i] = depExports;
834
+ }
835
+ },
836
+
837
+ fetch: function () {
838
+ if (this.fetched) {
839
+ return;
840
+ }
841
+ this.fetched = true;
842
+
843
+ context.startTime = (new Date()).getTime();
844
+
845
+ var map = this.map;
846
+
847
+ //If the manager is for a plugin managed resource,
848
+ //ask the plugin to load it now.
849
+ if (this.shim) {
850
+ context.makeRequire(this.map, {
851
+ enableBuildCallback: true
852
+ })(this.shim.deps || [], bind(this, function () {
853
+ return map.prefix ? this.callPlugin() : this.load();
854
+ }));
855
+ } else {
856
+ //Regular dependency.
857
+ return map.prefix ? this.callPlugin() : this.load();
858
+ }
859
+ },
860
+
861
+ load: function () {
862
+ var url = this.map.url;
863
+
864
+ //Regular dependency.
865
+ if (!urlFetched[url]) {
866
+ urlFetched[url] = true;
867
+ context.load(this.map.id, url);
868
+ }
869
+ },
870
+
871
+ /**
872
+ * Checks if the module is ready to define itself, and if so,
873
+ * define it.
874
+ */
875
+ check: function () {
876
+ if (!this.enabled || this.enabling) {
877
+ return;
878
+ }
879
+
880
+ var err, cjsModule,
881
+ id = this.map.id,
882
+ depExports = this.depExports,
883
+ exports = this.exports,
884
+ factory = this.factory;
885
+
886
+ if (!this.inited) {
887
+ // Only fetch if not already in the defQueue.
888
+ if (!hasProp(context.defQueueMap, id)) {
889
+ this.fetch();
890
+ }
891
+ } else if (this.error) {
892
+ this.emit('error', this.error);
893
+ } else if (!this.defining) {
894
+ //The factory could trigger another require call
895
+ //that would result in checking this module to
896
+ //define itself again. If already in the process
897
+ //of doing that, skip this work.
898
+ this.defining = true;
899
+
900
+ if (this.depCount < 1 && !this.defined) {
901
+ if (isFunction(factory)) {
902
+ //If there is an error listener, favor passing
903
+ //to that instead of throwing an error. However,
904
+ //only do it for define()'d modules. require
905
+ //errbacks should not be called for failures in
906
+ //their callbacks (#699). However if a global
907
+ //onError is set, use that.
908
+ if ((this.events.error && this.map.isDefine) ||
909
+ req.onError !== defaultOnError) {
910
+ try {
911
+ exports = context.execCb(id, factory, depExports, exports);
912
+ } catch (e) {
913
+ err = e;
914
+ }
915
+ } else {
916
+ exports = context.execCb(id, factory, depExports, exports);
917
+ }
918
+
919
+ // Favor return value over exports. If node/cjs in play,
920
+ // then will not have a return value anyway. Favor
921
+ // module.exports assignment over exports object.
922
+ if (this.map.isDefine && exports === undefined) {
923
+ cjsModule = this.module;
924
+ if (cjsModule) {
925
+ exports = cjsModule.exports;
926
+ } else if (this.usingExports) {
927
+ //exports already set the defined value.
928
+ exports = this.exports;
929
+ }
930
+ }
931
+
932
+ if (err) {
933
+ err.requireMap = this.map;
934
+ err.requireModules = this.map.isDefine ? [this.map.id] : null;
935
+ err.requireType = this.map.isDefine ? 'define' : 'require';
936
+ return onError((this.error = err));
937
+ }
938
+
939
+ } else {
940
+ //Just a literal value
941
+ exports = factory;
942
+ }
943
+
944
+ this.exports = exports;
945
+
946
+ if (this.map.isDefine && !this.ignore) {
947
+ defined[id] = exports;
948
+
949
+ if (req.onResourceLoad) {
950
+ var resLoadMaps = [];
951
+ each(this.depMaps, function (depMap) {
952
+ resLoadMaps.push(depMap.normalizedMap || depMap);
953
+ });
954
+ req.onResourceLoad(context, this.map, resLoadMaps);
955
+ }
956
+ }
957
+
958
+ //Clean up
959
+ cleanRegistry(id);
960
+
961
+ this.defined = true;
962
+ }
963
+
964
+ //Finished the define stage. Allow calling check again
965
+ //to allow define notifications below in the case of a
966
+ //cycle.
967
+ this.defining = false;
968
+
969
+ if (this.defined && !this.defineEmitted) {
970
+ this.defineEmitted = true;
971
+ this.emit('defined', this.exports);
972
+ this.defineEmitComplete = true;
973
+ }
974
+
975
+ }
976
+ },
977
+
978
+ callPlugin: function () {
979
+ var map = this.map,
980
+ id = map.id,
981
+ //Map already normalized the prefix.
982
+ pluginMap = makeModuleMap(map.prefix);
983
+
984
+ //Mark this as a dependency for this plugin, so it
985
+ //can be traced for cycles.
986
+ this.depMaps.push(pluginMap);
987
+
988
+ on(pluginMap, 'defined', bind(this, function (plugin) {
989
+ var load, normalizedMap, normalizedMod,
990
+ bundleId = getOwn(bundlesMap, this.map.id),
991
+ name = this.map.name,
992
+ parentName = this.map.parentMap ? this.map.parentMap.name : null,
993
+ localRequire = context.makeRequire(map.parentMap, {
994
+ enableBuildCallback: true
995
+ });
996
+
997
+ //If current map is not normalized, wait for that
998
+ //normalized name to load instead of continuing.
999
+ if (this.map.unnormalized) {
1000
+ //Normalize the ID if the plugin allows it.
1001
+ if (plugin.normalize) {
1002
+ name = plugin.normalize(name, function (name) {
1003
+ return normalize(name, parentName, true);
1004
+ }) || '';
1005
+ }
1006
+
1007
+ //prefix and name should already be normalized, no need
1008
+ //for applying map config again either.
1009
+ normalizedMap = makeModuleMap(map.prefix + '!' + name,
1010
+ this.map.parentMap,
1011
+ true);
1012
+ on(normalizedMap,
1013
+ 'defined', bind(this, function (value) {
1014
+ this.map.normalizedMap = normalizedMap;
1015
+ this.init([], function () { return value; }, null, {
1016
+ enabled: true,
1017
+ ignore: true
1018
+ });
1019
+ }));
1020
+
1021
+ normalizedMod = getOwn(registry, normalizedMap.id);
1022
+ if (normalizedMod) {
1023
+ //Mark this as a dependency for this plugin, so it
1024
+ //can be traced for cycles.
1025
+ this.depMaps.push(normalizedMap);
1026
+
1027
+ if (this.events.error) {
1028
+ normalizedMod.on('error', bind(this, function (err) {
1029
+ this.emit('error', err);
1030
+ }));
1031
+ }
1032
+ normalizedMod.enable();
1033
+ }
1034
+
1035
+ return;
1036
+ }
1037
+
1038
+ //If a paths config, then just load that file instead to
1039
+ //resolve the plugin, as it is built into that paths layer.
1040
+ if (bundleId) {
1041
+ this.map.url = context.nameToUrl(bundleId);
1042
+ this.load();
1043
+ return;
1044
+ }
1045
+
1046
+ load = bind(this, function (value) {
1047
+ this.init([], function () { return value; }, null, {
1048
+ enabled: true
1049
+ });
1050
+ });
1051
+
1052
+ load.error = bind(this, function (err) {
1053
+ this.inited = true;
1054
+ this.error = err;
1055
+ err.requireModules = [id];
1056
+
1057
+ //Remove temp unnormalized modules for this module,
1058
+ //since they will never be resolved otherwise now.
1059
+ eachProp(registry, function (mod) {
1060
+ if (mod.map.id.indexOf(id + '_unnormalized') === 0) {
1061
+ cleanRegistry(mod.map.id);
1062
+ }
1063
+ });
1064
+
1065
+ onError(err);
1066
+ });
1067
+
1068
+ //Allow plugins to load other code without having to know the
1069
+ //context or how to 'complete' the load.
1070
+ load.fromText = bind(this, function (text, textAlt) {
1071
+ /*jslint evil: true */
1072
+ var moduleName = map.name,
1073
+ moduleMap = makeModuleMap(moduleName),
1074
+ hasInteractive = useInteractive;
1075
+
1076
+ //As of 2.1.0, support just passing the text, to reinforce
1077
+ //fromText only being called once per resource. Still
1078
+ //support old style of passing moduleName but discard
1079
+ //that moduleName in favor of the internal ref.
1080
+ if (textAlt) {
1081
+ text = textAlt;
1082
+ }
1083
+
1084
+ //Turn off interactive script matching for IE for any define
1085
+ //calls in the text, then turn it back on at the end.
1086
+ if (hasInteractive) {
1087
+ useInteractive = false;
1088
+ }
1089
+
1090
+ //Prime the system by creating a module instance for
1091
+ //it.
1092
+ getModule(moduleMap);
1093
+
1094
+ //Transfer any config to this other module.
1095
+ if (hasProp(config.config, id)) {
1096
+ config.config[moduleName] = config.config[id];
1097
+ }
1098
+
1099
+ try {
1100
+ req.exec(text);
1101
+ } catch (e) {
1102
+ return onError(makeError('fromtexteval',
1103
+ 'fromText eval for ' + id +
1104
+ ' failed: ' + e,
1105
+ e,
1106
+ [id]));
1107
+ }
1108
+
1109
+ if (hasInteractive) {
1110
+ useInteractive = true;
1111
+ }
1112
+
1113
+ //Mark this as a dependency for the plugin
1114
+ //resource
1115
+ this.depMaps.push(moduleMap);
1116
+
1117
+ //Support anonymous modules.
1118
+ context.completeLoad(moduleName);
1119
+
1120
+ //Bind the value of that module to the value for this
1121
+ //resource ID.
1122
+ localRequire([moduleName], load);
1123
+ });
1124
+
1125
+ //Use parentName here since the plugin's name is not reliable,
1126
+ //could be some weird string with no path that actually wants to
1127
+ //reference the parentName's path.
1128
+ plugin.load(map.name, localRequire, load, config);
1129
+ }));
1130
+
1131
+ context.enable(pluginMap, this);
1132
+ this.pluginMaps[pluginMap.id] = pluginMap;
1133
+ },
1134
+
1135
+ enable: function () {
1136
+ enabledRegistry[this.map.id] = this;
1137
+ this.enabled = true;
1138
+
1139
+ //Set flag mentioning that the module is enabling,
1140
+ //so that immediate calls to the defined callbacks
1141
+ //for dependencies do not trigger inadvertent load
1142
+ //with the depCount still being zero.
1143
+ this.enabling = true;
1144
+
1145
+ //Enable each dependency
1146
+ each(this.depMaps, bind(this, function (depMap, i) {
1147
+ var id, mod, handler;
1148
+
1149
+ if (typeof depMap === 'string') {
1150
+ //Dependency needs to be converted to a depMap
1151
+ //and wired up to this module.
1152
+ depMap = makeModuleMap(depMap,
1153
+ (this.map.isDefine ? this.map : this.map.parentMap),
1154
+ false,
1155
+ !this.skipMap);
1156
+ this.depMaps[i] = depMap;
1157
+
1158
+ handler = getOwn(handlers, depMap.id);
1159
+
1160
+ if (handler) {
1161
+ this.depExports[i] = handler(this);
1162
+ return;
1163
+ }
1164
+
1165
+ this.depCount += 1;
1166
+
1167
+ on(depMap, 'defined', bind(this, function (depExports) {
1168
+ if (this.undefed) {
1169
+ return;
1170
+ }
1171
+ this.defineDep(i, depExports);
1172
+ this.check();
1173
+ }));
1174
+
1175
+ if (this.errback) {
1176
+ on(depMap, 'error', bind(this, this.errback));
1177
+ } else if (this.events.error) {
1178
+ // No direct errback on this module, but something
1179
+ // else is listening for errors, so be sure to
1180
+ // propagate the error correctly.
1181
+ on(depMap, 'error', bind(this, function(err) {
1182
+ this.emit('error', err);
1183
+ }));
1184
+ }
1185
+ }
1186
+
1187
+ id = depMap.id;
1188
+ mod = registry[id];
1189
+
1190
+ //Skip special modules like 'require', 'exports', 'module'
1191
+ //Also, don't call enable if it is already enabled,
1192
+ //important in circular dependency cases.
1193
+ if (!hasProp(handlers, id) && mod && !mod.enabled) {
1194
+ context.enable(depMap, this);
1195
+ }
1196
+ }));
1197
+
1198
+ //Enable each plugin that is used in
1199
+ //a dependency
1200
+ eachProp(this.pluginMaps, bind(this, function (pluginMap) {
1201
+ var mod = getOwn(registry, pluginMap.id);
1202
+ if (mod && !mod.enabled) {
1203
+ context.enable(pluginMap, this);
1204
+ }
1205
+ }));
1206
+
1207
+ this.enabling = false;
1208
+
1209
+ this.check();
1210
+ },
1211
+
1212
+ on: function (name, cb) {
1213
+ var cbs = this.events[name];
1214
+ if (!cbs) {
1215
+ cbs = this.events[name] = [];
1216
+ }
1217
+ cbs.push(cb);
1218
+ },
1219
+
1220
+ emit: function (name, evt) {
1221
+ each(this.events[name], function (cb) {
1222
+ cb(evt);
1223
+ });
1224
+ if (name === 'error') {
1225
+ //Now that the error handler was triggered, remove
1226
+ //the listeners, since this broken Module instance
1227
+ //can stay around for a while in the registry.
1228
+ delete this.events[name];
1229
+ }
1230
+ }
1231
+ };
1232
+
1233
+ function callGetModule(args) {
1234
+ //Skip modules already defined.
1235
+ if (!hasProp(defined, args[0])) {
1236
+ getModule(makeModuleMap(args[0], null, true)).init(args[1], args[2]);
1237
+ }
1238
+ }
1239
+
1240
+ function removeListener(node, func, name, ieName) {
1241
+ //Favor detachEvent because of IE9
1242
+ //issue, see attachEvent/addEventListener comment elsewhere
1243
+ //in this file.
1244
+ if (node.detachEvent && !isOpera) {
1245
+ //Probably IE. If not it will throw an error, which will be
1246
+ //useful to know.
1247
+ if (ieName) {
1248
+ node.detachEvent(ieName, func);
1249
+ }
1250
+ } else {
1251
+ node.removeEventListener(name, func, false);
1252
+ }
1253
+ }
1254
+
1255
+ /**
1256
+ * Given an event from a script node, get the requirejs info from it,
1257
+ * and then removes the event listeners on the node.
1258
+ * @param {Event} evt
1259
+ * @returns {Object}
1260
+ */
1261
+ function getScriptData(evt) {
1262
+ //Using currentTarget instead of target for Firefox 2.0's sake. Not
1263
+ //all old browsers will be supported, but this one was easy enough
1264
+ //to support and still makes sense.
1265
+ var node = evt.currentTarget || evt.srcElement;
1266
+
1267
+ //Remove the listeners once here.
1268
+ removeListener(node, context.onScriptLoad, 'load', 'onreadystatechange');
1269
+ removeListener(node, context.onScriptError, 'error');
1270
+
1271
+ return {
1272
+ node: node,
1273
+ id: node && node.getAttribute('data-requiremodule')
1274
+ };
1275
+ }
1276
+
1277
+ function intakeDefines() {
1278
+ var args;
1279
+
1280
+ //Any defined modules in the global queue, intake them now.
1281
+ takeGlobalQueue();
1282
+
1283
+ //Make sure any remaining defQueue items get properly processed.
1284
+ while (defQueue.length) {
1285
+ args = defQueue.shift();
1286
+ if (args[0] === null) {
1287
+ return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' +
1288
+ args[args.length - 1]));
1289
+ } else {
1290
+ //args are id, deps, factory. Should be normalized by the
1291
+ //define() function.
1292
+ callGetModule(args);
1293
+ }
1294
+ }
1295
+ context.defQueueMap = {};
1296
+ }
1297
+
1298
+ context = {
1299
+ config: config,
1300
+ contextName: contextName,
1301
+ registry: registry,
1302
+ defined: defined,
1303
+ urlFetched: urlFetched,
1304
+ defQueue: defQueue,
1305
+ defQueueMap: {},
1306
+ Module: Module,
1307
+ makeModuleMap: makeModuleMap,
1308
+ nextTick: req.nextTick,
1309
+ onError: onError,
1310
+
1311
+ /**
1312
+ * Set a configuration for the context.
1313
+ * @param {Object} cfg config object to integrate.
1314
+ */
1315
+ configure: function (cfg) {
1316
+ //Make sure the baseUrl ends in a slash.
1317
+ if (cfg.baseUrl) {
1318
+ if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== '/') {
1319
+ cfg.baseUrl += '/';
1320
+ }
1321
+ }
1322
+
1323
+ // Convert old style urlArgs string to a function.
1324
+ if (typeof cfg.urlArgs === 'string') {
1325
+ var urlArgs = cfg.urlArgs;
1326
+ cfg.urlArgs = function(id, url) {
1327
+ return (url.indexOf('?') === -1 ? '?' : '&') + urlArgs;
1328
+ };
1329
+ }
1330
+
1331
+ //Save off the paths since they require special processing,
1332
+ //they are additive.
1333
+ var shim = config.shim,
1334
+ objs = {
1335
+ paths: true,
1336
+ bundles: true,
1337
+ config: true,
1338
+ map: true
1339
+ };
1340
+
1341
+ eachProp(cfg, function (value, prop) {
1342
+ if (objs[prop]) {
1343
+ if (!config[prop]) {
1344
+ config[prop] = {};
1345
+ }
1346
+ mixin(config[prop], value, true, true);
1347
+ } else {
1348
+ config[prop] = value;
1349
+ }
1350
+ });
1351
+
1352
+ //Reverse map the bundles
1353
+ if (cfg.bundles) {
1354
+ eachProp(cfg.bundles, function (value, prop) {
1355
+ each(value, function (v) {
1356
+ if (v !== prop) {
1357
+ bundlesMap[v] = prop;
1358
+ }
1359
+ });
1360
+ });
1361
+ }
1362
+
1363
+ //Merge shim
1364
+ if (cfg.shim) {
1365
+ eachProp(cfg.shim, function (value, id) {
1366
+ //Normalize the structure
1367
+ if (isArray(value)) {
1368
+ value = {
1369
+ deps: value
1370
+ };
1371
+ }
1372
+ if ((value.exports || value.init) && !value.exportsFn) {
1373
+ value.exportsFn = context.makeShimExports(value);
1374
+ }
1375
+ shim[id] = value;
1376
+ });
1377
+ config.shim = shim;
1378
+ }
1379
+
1380
+ //Adjust packages if necessary.
1381
+ if (cfg.packages) {
1382
+ each(cfg.packages, function (pkgObj) {
1383
+ var location, name;
1384
+
1385
+ pkgObj = typeof pkgObj === 'string' ? {name: pkgObj} : pkgObj;
1386
+
1387
+ name = pkgObj.name;
1388
+ location = pkgObj.location;
1389
+ if (location) {
1390
+ config.paths[name] = pkgObj.location;
1391
+ }
1392
+
1393
+ //Save pointer to main module ID for pkg name.
1394
+ //Remove leading dot in main, so main paths are normalized,
1395
+ //and remove any trailing .js, since different package
1396
+ //envs have different conventions: some use a module name,
1397
+ //some use a file name.
1398
+ config.pkgs[name] = pkgObj.name + '/' + (pkgObj.main || 'main')
1399
+ .replace(currDirRegExp, '')
1400
+ .replace(jsSuffixRegExp, '');
1401
+ });
1402
+ }
1403
+
1404
+ //If there are any "waiting to execute" modules in the registry,
1405
+ //update the maps for them, since their info, like URLs to load,
1406
+ //may have changed.
1407
+ eachProp(registry, function (mod, id) {
1408
+ //If module already has init called, since it is too
1409
+ //late to modify them, and ignore unnormalized ones
1410
+ //since they are transient.
1411
+ if (!mod.inited && !mod.map.unnormalized) {
1412
+ mod.map = makeModuleMap(id, null, true);
1413
+ }
1414
+ });
1415
+
1416
+ //If a deps array or a config callback is specified, then call
1417
+ //require with those args. This is useful when require is defined as a
1418
+ //config object before require.js is loaded.
1419
+ if (cfg.deps || cfg.callback) {
1420
+ context.require(cfg.deps || [], cfg.callback);
1421
+ }
1422
+ },
1423
+
1424
+ makeShimExports: function (value) {
1425
+ function fn() {
1426
+ var ret;
1427
+ if (value.init) {
1428
+ ret = value.init.apply(global, arguments);
1429
+ }
1430
+ return ret || (value.exports && getGlobal(value.exports));
1431
+ }
1432
+ return fn;
1433
+ },
1434
+
1435
+ makeRequire: function (relMap, options) {
1436
+ options = options || {};
1437
+
1438
+ function localRequire(deps, callback, errback) {
1439
+ var id, map, requireMod;
1440
+
1441
+ if (options.enableBuildCallback && callback && isFunction(callback)) {
1442
+ callback.__requireJsBuild = true;
1443
+ }
1444
+
1445
+ if (typeof deps === 'string') {
1446
+ if (isFunction(callback)) {
1447
+ //Invalid call
1448
+ return onError(makeError('requireargs', 'Invalid require call'), errback);
1449
+ }
1450
+
1451
+ //If require|exports|module are requested, get the
1452
+ //value for them from the special handlers. Caveat:
1453
+ //this only works while module is being defined.
1454
+ if (relMap && hasProp(handlers, deps)) {
1455
+ return handlers[deps](registry[relMap.id]);
1456
+ }
1457
+
1458
+ //Synchronous access to one module. If require.get is
1459
+ //available (as in the Node adapter), prefer that.
1460
+ if (req.get) {
1461
+ return req.get(context, deps, relMap, localRequire);
1462
+ }
1463
+
1464
+ //Normalize module name, if it contains . or ..
1465
+ map = makeModuleMap(deps, relMap, false, true);
1466
+ id = map.id;
1467
+
1468
+ if (!hasProp(defined, id)) {
1469
+ return onError(makeError('notloaded', 'Module name "' +
1470
+ id +
1471
+ '" has not been loaded yet for context: ' +
1472
+ contextName +
1473
+ (relMap ? '' : '. Use require([])')));
1474
+ }
1475
+ return defined[id];
1476
+ }
1477
+
1478
+ //Grab defines waiting in the global queue.
1479
+ intakeDefines();
1480
+
1481
+ //Mark all the dependencies as needing to be loaded.
1482
+ context.nextTick(function () {
1483
+ //Some defines could have been added since the
1484
+ //require call, collect them.
1485
+ intakeDefines();
1486
+
1487
+ requireMod = getModule(makeModuleMap(null, relMap));
1488
+
1489
+ //Store if map config should be applied to this require
1490
+ //call for dependencies.
1491
+ requireMod.skipMap = options.skipMap;
1492
+
1493
+ requireMod.init(deps, callback, errback, {
1494
+ enabled: true
1495
+ });
1496
+
1497
+ checkLoaded();
1498
+ });
1499
+
1500
+ return localRequire;
1501
+ }
1502
+
1503
+ mixin(localRequire, {
1504
+ isBrowser: isBrowser,
1505
+
1506
+ /**
1507
+ * Converts a module name + .extension into an URL path.
1508
+ * *Requires* the use of a module name. It does not support using
1509
+ * plain URLs like nameToUrl.
1510
+ */
1511
+ toUrl: function (moduleNamePlusExt) {
1512
+ var ext,
1513
+ index = moduleNamePlusExt.lastIndexOf('.'),
1514
+ segment = moduleNamePlusExt.split('/')[0],
1515
+ isRelative = segment === '.' || segment === '..';
1516
+
1517
+ //Have a file extension alias, and it is not the
1518
+ //dots from a relative path.
1519
+ if (index !== -1 && (!isRelative || index > 1)) {
1520
+ ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length);
1521
+ moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
1522
+ }
1523
+
1524
+ return context.nameToUrl(normalize(moduleNamePlusExt,
1525
+ relMap && relMap.id, true), ext, true);
1526
+ },
1527
+
1528
+ defined: function (id) {
1529
+ return hasProp(defined, makeModuleMap(id, relMap, false, true).id);
1530
+ },
1531
+
1532
+ specified: function (id) {
1533
+ id = makeModuleMap(id, relMap, false, true).id;
1534
+ return hasProp(defined, id) || hasProp(registry, id);
1535
+ }
1536
+ });
1537
+
1538
+ //Only allow undef on top level require calls
1539
+ if (!relMap) {
1540
+ localRequire.undef = function (id) {
1541
+ //Bind any waiting define() calls to this context,
1542
+ //fix for #408
1543
+ takeGlobalQueue();
1544
+
1545
+ var map = makeModuleMap(id, relMap, true),
1546
+ mod = getOwn(registry, id);
1547
+
1548
+ mod.undefed = true;
1549
+ removeScript(id);
1550
+
1551
+ delete defined[id];
1552
+ delete urlFetched[map.url];
1553
+ delete undefEvents[id];
1554
+
1555
+ //Clean queued defines too. Go backwards
1556
+ //in array so that the splices do not
1557
+ //mess up the iteration.
1558
+ eachReverse(defQueue, function(args, i) {
1559
+ if (args[0] === id) {
1560
+ defQueue.splice(i, 1);
1561
+ }
1562
+ });
1563
+ delete context.defQueueMap[id];
1564
+
1565
+ if (mod) {
1566
+ //Hold on to listeners in case the
1567
+ //module will be attempted to be reloaded
1568
+ //using a different config.
1569
+ if (mod.events.defined) {
1570
+ undefEvents[id] = mod.events;
1571
+ }
1572
+
1573
+ cleanRegistry(id);
1574
+ }
1575
+ };
1576
+ }
1577
+
1578
+ return localRequire;
1579
+ },
1580
+
1581
+ /**
1582
+ * Called to enable a module if it is still in the registry
1583
+ * awaiting enablement. A second arg, parent, the parent module,
1584
+ * is passed in for context, when this method is overridden by
1585
+ * the optimizer. Not shown here to keep code compact.
1586
+ */
1587
+ enable: function (depMap) {
1588
+ var mod = getOwn(registry, depMap.id);
1589
+ if (mod) {
1590
+ getModule(depMap).enable();
1591
+ }
1592
+ },
1593
+
1594
+ /**
1595
+ * Internal method used by environment adapters to complete a load event.
1596
+ * A load event could be a script load or just a load pass from a synchronous
1597
+ * load call.
1598
+ * @param {String} moduleName the name of the module to potentially complete.
1599
+ */
1600
+ completeLoad: function (moduleName) {
1601
+ var found, args, mod,
1602
+ shim = getOwn(config.shim, moduleName) || {},
1603
+ shExports = shim.exports;
1604
+
1605
+ takeGlobalQueue();
1606
+
1607
+ while (defQueue.length) {
1608
+ args = defQueue.shift();
1609
+ if (args[0] === null) {
1610
+ args[0] = moduleName;
1611
+ //If already found an anonymous module and bound it
1612
+ //to this name, then this is some other anon module
1613
+ //waiting for its completeLoad to fire.
1614
+ if (found) {
1615
+ break;
1616
+ }
1617
+ found = true;
1618
+ } else if (args[0] === moduleName) {
1619
+ //Found matching define call for this script!
1620
+ found = true;
1621
+ }
1622
+
1623
+ callGetModule(args);
1624
+ }
1625
+ context.defQueueMap = {};
1626
+
1627
+ //Do this after the cycle of callGetModule in case the result
1628
+ //of those calls/init calls changes the registry.
1629
+ mod = getOwn(registry, moduleName);
1630
+
1631
+ if (!found && !hasProp(defined, moduleName) && mod && !mod.inited) {
1632
+ if (config.enforceDefine && (!shExports || !getGlobal(shExports))) {
1633
+ if (hasPathFallback(moduleName)) {
1634
+ return;
1635
+ } else {
1636
+ return onError(makeError('nodefine',
1637
+ 'No define call for ' + moduleName,
1638
+ null,
1639
+ [moduleName]));
1640
+ }
1641
+ } else {
1642
+ //A script that does not call define(), so just simulate
1643
+ //the call for it.
1644
+ callGetModule([moduleName, (shim.deps || []), shim.exportsFn]);
1645
+ }
1646
+ }
1647
+
1648
+ checkLoaded();
1649
+ },
1650
+
1651
+ /**
1652
+ * Converts a module name to a file path. Supports cases where
1653
+ * moduleName may actually be just an URL.
1654
+ * Note that it **does not** call normalize on the moduleName,
1655
+ * it is assumed to have already been normalized. This is an
1656
+ * internal API, not a public one. Use toUrl for the public API.
1657
+ */
1658
+ nameToUrl: function (moduleName, ext, skipExt) {
1659
+ var paths, syms, i, parentModule, url,
1660
+ parentPath, bundleId,
1661
+ pkgMain = getOwn(config.pkgs, moduleName);
1662
+
1663
+ if (pkgMain) {
1664
+ moduleName = pkgMain;
1665
+ }
1666
+
1667
+ bundleId = getOwn(bundlesMap, moduleName);
1668
+
1669
+ if (bundleId) {
1670
+ return context.nameToUrl(bundleId, ext, skipExt);
1671
+ }
1672
+
1673
+ //If a colon is in the URL, it indicates a protocol is used and it is just
1674
+ //an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?)
1675
+ //or ends with .js, then assume the user meant to use an url and not a module id.
1676
+ //The slash is important for protocol-less URLs as well as full paths.
1677
+ if (req.jsExtRegExp.test(moduleName)) {
1678
+ //Just a plain path, not module name lookup, so just return it.
1679
+ //Add extension if it is included. This is a bit wonky, only non-.js things pass
1680
+ //an extension, this method probably needs to be reworked.
1681
+ url = moduleName + (ext || '');
1682
+ } else {
1683
+ //A module that needs to be converted to a path.
1684
+ paths = config.paths;
1685
+
1686
+ syms = moduleName.split('/');
1687
+ //For each module name segment, see if there is a path
1688
+ //registered for it. Start with most specific name
1689
+ //and work up from it.
1690
+ for (i = syms.length; i > 0; i -= 1) {
1691
+ parentModule = syms.slice(0, i).join('/');
1692
+
1693
+ parentPath = getOwn(paths, parentModule);
1694
+ if (parentPath) {
1695
+ //If an array, it means there are a few choices,
1696
+ //Choose the one that is desired
1697
+ if (isArray(parentPath)) {
1698
+ parentPath = parentPath[0];
1699
+ }
1700
+ syms.splice(0, i, parentPath);
1701
+ break;
1702
+ }
1703
+ }
1704
+
1705
+ //Join the path parts together, then figure out if baseUrl is needed.
1706
+ url = syms.join('/');
1707
+ url += (ext || (/^data\:|^blob\:|\?/.test(url) || skipExt ? '' : '.js'));
1708
+ url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
1709
+ }
1710
+
1711
+ return config.urlArgs && !/^blob\:/.test(url) ?
1712
+ url + config.urlArgs(moduleName, url) : url;
1713
+ },
1714
+
1715
+ //Delegates to req.load. Broken out as a separate function to
1716
+ //allow overriding in the optimizer.
1717
+ load: function (id, url) {
1718
+ req.load(context, id, url);
1719
+ },
1720
+
1721
+ /**
1722
+ * Executes a module callback function. Broken out as a separate function
1723
+ * solely to allow the build system to sequence the files in the built
1724
+ * layer in the right sequence.
1725
+ *
1726
+ * @private
1727
+ */
1728
+ execCb: function (name, callback, args, exports) {
1729
+ return callback.apply(exports, args);
1730
+ },
1731
+
1732
+ /**
1733
+ * callback for script loads, used to check status of loading.
1734
+ *
1735
+ * @param {Event} evt the event from the browser for the script
1736
+ * that was loaded.
1737
+ */
1738
+ onScriptLoad: function (evt) {
1739
+ //Using currentTarget instead of target for Firefox 2.0's sake. Not
1740
+ //all old browsers will be supported, but this one was easy enough
1741
+ //to support and still makes sense.
1742
+ if (evt.type === 'load' ||
1743
+ (readyRegExp.test((evt.currentTarget || evt.srcElement).readyState))) {
1744
+ //Reset interactive script so a script node is not held onto for
1745
+ //to long.
1746
+ interactiveScript = null;
1747
+
1748
+ //Pull out the name of the module and the context.
1749
+ var data = getScriptData(evt);
1750
+ context.completeLoad(data.id);
1751
+ }
1752
+ },
1753
+
1754
+ /**
1755
+ * Callback for script errors.
1756
+ */
1757
+ onScriptError: function (evt) {
1758
+ var data = getScriptData(evt);
1759
+ if (!hasPathFallback(data.id)) {
1760
+ var parents = [];
1761
+ eachProp(registry, function(value, key) {
1762
+ if (key.indexOf('_@r') !== 0) {
1763
+ each(value.depMaps, function(depMap) {
1764
+ if (depMap.id === data.id) {
1765
+ parents.push(key);
1766
+ return true;
1767
+ }
1768
+ });
1769
+ }
1770
+ });
1771
+ return onError(makeError('scripterror', 'Script error for "' + data.id +
1772
+ (parents.length ?
1773
+ '", needed by: ' + parents.join(', ') :
1774
+ '"'), evt, [data.id]));
1775
+ }
1776
+ }
1777
+ };
1778
+
1779
+ context.require = context.makeRequire();
1780
+ return context;
1781
+ }
1782
+
1783
+ /**
1784
+ * Main entry point.
1785
+ *
1786
+ * If the only argument to require is a string, then the module that
1787
+ * is represented by that string is fetched for the appropriate context.
1788
+ *
1789
+ * If the first argument is an array, then it will be treated as an array
1790
+ * of dependency string names to fetch. An optional function callback can
1791
+ * be specified to execute when all of those dependencies are available.
1792
+ *
1793
+ * Make a local req variable to help Caja compliance (it assumes things
1794
+ * on a require that are not standardized), and to give a short
1795
+ * name for minification/local scope use.
1796
+ */
1797
+ req = requirejs = function (deps, callback, errback, optional) {
1798
+
1799
+ //Find the right context, use default
1800
+ var context, config,
1801
+ contextName = defContextName;
1802
+
1803
+ // Determine if have config object in the call.
1804
+ if (!isArray(deps) && typeof deps !== 'string') {
1805
+ // deps is a config object
1806
+ config = deps;
1807
+ if (isArray(callback)) {
1808
+ // Adjust args if there are dependencies
1809
+ deps = callback;
1810
+ callback = errback;
1811
+ errback = optional;
1812
+ } else {
1813
+ deps = [];
1814
+ }
1815
+ }
1816
+
1817
+ if (config && config.context) {
1818
+ contextName = config.context;
1819
+ }
1820
+
1821
+ context = getOwn(contexts, contextName);
1822
+ if (!context) {
1823
+ context = contexts[contextName] = req.s.newContext(contextName);
1824
+ }
1825
+
1826
+ if (config) {
1827
+ context.configure(config);
1828
+ }
1829
+
1830
+ return context.require(deps, callback, errback);
1831
+ };
1832
+
1833
+ /**
1834
+ * Support require.config() to make it easier to cooperate with other
1835
+ * AMD loaders on globally agreed names.
1836
+ */
1837
+ req.config = function (config) {
1838
+ return req(config);
1839
+ };
1840
+
1841
+ /**
1842
+ * Execute something after the current tick
1843
+ * of the event loop. Override for other envs
1844
+ * that have a better solution than setTimeout.
1845
+ * @param {Function} fn function to execute later.
1846
+ */
1847
+ req.nextTick = typeof setTimeout !== 'undefined' ? function (fn) {
1848
+ setTimeout(fn, 4);
1849
+ } : function (fn) { fn(); };
1850
+
1851
+ /**
1852
+ * Export require as a global, but only if it does not already exist.
1853
+ */
1854
+ if (!require) {
1855
+ require = req;
1856
+ }
1857
+
1858
+ req.version = version;
1859
+
1860
+ //Used to filter out dependencies that are already paths.
1861
+ req.jsExtRegExp = /^\/|:|\?|\.js$/;
1862
+ req.isBrowser = isBrowser;
1863
+ s = req.s = {
1864
+ contexts: contexts,
1865
+ newContext: newContext
1866
+ };
1867
+
1868
+ //Create default context.
1869
+ req({});
1870
+
1871
+ //Exports some context-sensitive methods on global require.
1872
+ each([
1873
+ 'toUrl',
1874
+ 'undef',
1875
+ 'defined',
1876
+ 'specified'
1877
+ ], function (prop) {
1878
+ //Reference from contexts instead of early binding to default context,
1879
+ //so that during builds, the latest instance of the default context
1880
+ //with its config gets used.
1881
+ req[prop] = function () {
1882
+ var ctx = contexts[defContextName];
1883
+ return ctx.require[prop].apply(ctx, arguments);
1884
+ };
1885
+ });
1886
+
1887
+ if (isBrowser) {
1888
+ head = s.head = document.getElementsByTagName('head')[0];
1889
+ //If BASE tag is in play, using appendChild is a problem for IE6.
1890
+ //When that browser dies, this can be removed. Details in this jQuery bug:
1891
+ //http://dev.jquery.com/ticket/2709
1892
+ baseElement = document.getElementsByTagName('base')[0];
1893
+ if (baseElement) {
1894
+ head = s.head = baseElement.parentNode;
1895
+ }
1896
+ }
1897
+
1898
+ /**
1899
+ * Any errors that require explicitly generates will be passed to this
1900
+ * function. Intercept/override it if you want custom error handling.
1901
+ * @param {Error} err the error object.
1902
+ */
1903
+ req.onError = defaultOnError;
1904
+
1905
+ /**
1906
+ * Creates the node for the load command. Only used in browser envs.
1907
+ */
1908
+ req.createNode = function (config, moduleName, url) {
1909
+ var node = config.xhtml ?
1910
+ document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
1911
+ document.createElement('script');
1912
+ node.type = config.scriptType || 'text/javascript';
1913
+ node.charset = 'utf-8';
1914
+ node.async = true;
1915
+ return node;
1916
+ };
1917
+
1918
+ /**
1919
+ * Does the request to load a module for the browser case.
1920
+ * Make this a separate function to allow other environments
1921
+ * to override it.
1922
+ *
1923
+ * @param {Object} context the require context to find state.
1924
+ * @param {String} moduleName the name of the module.
1925
+ * @param {Object} url the URL to the module.
1926
+ */
1927
+ req.load = function (context, moduleName, url) {
1928
+ var config = (context && context.config) || {},
1929
+ node;
1930
+ if (isBrowser) {
1931
+ //In the browser so use a script tag
1932
+ node = req.createNode(config, moduleName, url);
1933
+
1934
+ node.setAttribute('data-requirecontext', context.contextName);
1935
+ node.setAttribute('data-requiremodule', moduleName);
1936
+
1937
+ //Set up load listener. Test attachEvent first because IE9 has
1938
+ //a subtle issue in its addEventListener and script onload firings
1939
+ //that do not match the behavior of all other browsers with
1940
+ //addEventListener support, which fire the onload event for a
1941
+ //script right after the script execution. See:
1942
+ //https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
1943
+ //UNFORTUNATELY Opera implements attachEvent but does not follow the script
1944
+ //script execution mode.
1945
+ if (node.attachEvent &&
1946
+ //Check if node.attachEvent is artificially added by custom script or
1947
+ //natively supported by browser
1948
+ //read https://github.com/requirejs/requirejs/issues/187
1949
+ //if we can NOT find [native code] then it must NOT natively supported.
1950
+ //in IE8, node.attachEvent does not have toString()
1951
+ //Note the test for "[native code" with no closing brace, see:
1952
+ //https://github.com/requirejs/requirejs/issues/273
1953
+ !(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) &&
1954
+ !isOpera) {
1955
+ //Probably IE. IE (at least 6-8) do not fire
1956
+ //script onload right after executing the script, so
1957
+ //we cannot tie the anonymous define call to a name.
1958
+ //However, IE reports the script as being in 'interactive'
1959
+ //readyState at the time of the define call.
1960
+ useInteractive = true;
1961
+
1962
+ node.attachEvent('onreadystatechange', context.onScriptLoad);
1963
+ //It would be great to add an error handler here to catch
1964
+ //404s in IE9+. However, onreadystatechange will fire before
1965
+ //the error handler, so that does not help. If addEventListener
1966
+ //is used, then IE will fire error before load, but we cannot
1967
+ //use that pathway given the connect.microsoft.com issue
1968
+ //mentioned above about not doing the 'script execute,
1969
+ //then fire the script load event listener before execute
1970
+ //next script' that other browsers do.
1971
+ //Best hope: IE10 fixes the issues,
1972
+ //and then destroys all installs of IE 6-9.
1973
+ //node.attachEvent('onerror', context.onScriptError);
1974
+ } else {
1975
+ node.addEventListener('load', context.onScriptLoad, false);
1976
+ node.addEventListener('error', context.onScriptError, false);
1977
+ }
1978
+ node.src = url;
1979
+
1980
+ //Calling onNodeCreated after all properties on the node have been
1981
+ //set, but before it is placed in the DOM.
1982
+ if (config.onNodeCreated) {
1983
+ config.onNodeCreated(node, config, moduleName, url);
1984
+ }
1985
+
1986
+ //For some cache cases in IE 6-8, the script executes before the end
1987
+ //of the appendChild execution, so to tie an anonymous define
1988
+ //call to the module name (which is stored on the node), hold on
1989
+ //to a reference to this node, but clear after the DOM insertion.
1990
+ currentlyAddingScript = node;
1991
+ if (baseElement) {
1992
+ head.insertBefore(node, baseElement);
1993
+ } else {
1994
+ head.appendChild(node);
1995
+ }
1996
+ currentlyAddingScript = null;
1997
+
1998
+ return node;
1999
+ } else if (isWebWorker) {
2000
+ try {
2001
+ //In a web worker, use importScripts. This is not a very
2002
+ //efficient use of importScripts, importScripts will block until
2003
+ //its script is downloaded and evaluated. However, if web workers
2004
+ //are in play, the expectation is that a build has been done so
2005
+ //that only one script needs to be loaded anyway. This may need
2006
+ //to be reevaluated if other use cases become common.
2007
+
2008
+ // Post a task to the event loop to work around a bug in WebKit
2009
+ // where the worker gets garbage-collected after calling
2010
+ // importScripts(): https://webkit.org/b/153317
2011
+ setTimeout(function() {}, 0);
2012
+ importScripts(url);
2013
+
2014
+ //Account for anonymous modules
2015
+ context.completeLoad(moduleName);
2016
+ } catch (e) {
2017
+ context.onError(makeError('importscripts',
2018
+ 'importScripts failed for ' +
2019
+ moduleName + ' at ' + url,
2020
+ e,
2021
+ [moduleName]));
2022
+ }
2023
+ }
2024
+ };
2025
+
2026
+ function getInteractiveScript() {
2027
+ if (interactiveScript && interactiveScript.readyState === 'interactive') {
2028
+ return interactiveScript;
2029
+ }
2030
+
2031
+ eachReverse(scripts(), function (script) {
2032
+ if (script.readyState === 'interactive') {
2033
+ return (interactiveScript = script);
2034
+ }
2035
+ });
2036
+ return interactiveScript;
2037
+ }
2038
+
2039
+ //Look for a data-main script attribute, which could also adjust the baseUrl.
2040
+ if (isBrowser && !cfg.skipDataMain) {
2041
+ //Figure out baseUrl. Get it from the script tag with require.js in it.
2042
+ eachReverse(scripts(), function (script) {
2043
+ //Set the 'head' where we can append children by
2044
+ //using the script's parent.
2045
+ if (!head) {
2046
+ head = script.parentNode;
2047
+ }
2048
+
2049
+ //Look for a data-main attribute to set main script for the page
2050
+ //to load. If it is there, the path to data main becomes the
2051
+ //baseUrl, if it is not already set.
2052
+ dataMain = script.getAttribute('data-main');
2053
+ if (dataMain) {
2054
+ //Preserve dataMain in case it is a path (i.e. contains '?')
2055
+ mainScript = dataMain;
2056
+
2057
+ //Set final baseUrl if there is not already an explicit one,
2058
+ //but only do so if the data-main value is not a loader plugin
2059
+ //module ID.
2060
+ if (!cfg.baseUrl && mainScript.indexOf('!') === -1) {
2061
+ //Pull off the directory of data-main for use as the
2062
+ //baseUrl.
2063
+ src = mainScript.split('/');
2064
+ mainScript = src.pop();
2065
+ subPath = src.length ? src.join('/') + '/' : './';
2066
+
2067
+ cfg.baseUrl = subPath;
2068
+ }
2069
+
2070
+ //Strip off any trailing .js since mainScript is now
2071
+ //like a module name.
2072
+ mainScript = mainScript.replace(jsSuffixRegExp, '');
2073
+
2074
+ //If mainScript is still a path, fall back to dataMain
2075
+ if (req.jsExtRegExp.test(mainScript)) {
2076
+ mainScript = dataMain;
2077
+ }
2078
+
2079
+ //Put the data-main script in the files to load.
2080
+ cfg.deps = cfg.deps ? cfg.deps.concat(mainScript) : [mainScript];
2081
+
2082
+ return true;
2083
+ }
2084
+ });
2085
+ }
2086
+
2087
+ /**
2088
+ * The function that handles definitions of modules. Differs from
2089
+ * require() in that a string for the module should be the first argument,
2090
+ * and the function to execute after dependencies are loaded should
2091
+ * return a value to define the module corresponding to the first argument's
2092
+ * name.
2093
+ */
2094
+ define = function (name, deps, callback) {
2095
+ var node, context;
2096
+
2097
+ //Allow for anonymous modules
2098
+ if (typeof name !== 'string') {
2099
+ //Adjust args appropriately
2100
+ callback = deps;
2101
+ deps = name;
2102
+ name = null;
2103
+ }
2104
+
2105
+ //This module may not have dependencies
2106
+ if (!isArray(deps)) {
2107
+ callback = deps;
2108
+ deps = null;
2109
+ }
2110
+
2111
+ //If no name, and callback is a function, then figure out if it a
2112
+ //CommonJS thing with dependencies.
2113
+ if (!deps && isFunction(callback)) {
2114
+ deps = [];
2115
+ //Remove comments from the callback string,
2116
+ //look for require calls, and pull them into the dependencies,
2117
+ //but only if there are function args.
2118
+ if (callback.length) {
2119
+ callback
2120
+ .toString()
2121
+ .replace(commentRegExp, commentReplace)
2122
+ .replace(cjsRequireRegExp, function (match, dep) {
2123
+ deps.push(dep);
2124
+ });
2125
+
2126
+ //May be a CommonJS thing even without require calls, but still
2127
+ //could use exports, and module. Avoid doing exports and module
2128
+ //work though if it just needs require.
2129
+ //REQUIRES the function to expect the CommonJS variables in the
2130
+ //order listed below.
2131
+ deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps);
2132
+ }
2133
+ }
2134
+
2135
+ //If in IE 6-8 and hit an anonymous define() call, do the interactive
2136
+ //work.
2137
+ if (useInteractive) {
2138
+ node = currentlyAddingScript || getInteractiveScript();
2139
+ if (node) {
2140
+ if (!name) {
2141
+ name = node.getAttribute('data-requiremodule');
2142
+ }
2143
+ context = contexts[node.getAttribute('data-requirecontext')];
2144
+ }
2145
+ }
2146
+
2147
+ //Always save off evaluating the def call until the script onload handler.
2148
+ //This allows multiple modules to be in a file without prematurely
2149
+ //tracing dependencies, and allows for anonymous module support,
2150
+ //where the module name is not known until the script onload event
2151
+ //occurs. If no context, use the global queue, and get it processed
2152
+ //in the onscript load callback.
2153
+ if (context) {
2154
+ context.defQueue.push([name, deps, callback]);
2155
+ context.defQueueMap[name] = true;
2156
+ } else {
2157
+ globalDefQueue.push([name, deps, callback]);
2158
+ }
2159
+ };
2160
+
2161
+ define.amd = {
2162
+ jQuery: true
2163
+ };
2164
+
2165
+ /**
2166
+ * Executes the text. Normally just uses eval, but can be modified
2167
+ * to use a better, environment-specific call. Only used for transpiling
2168
+ * loader plugins, not for plain JS modules.
2169
+ * @param {String} text the text to execute/evaluate.
2170
+ */
2171
+ req.exec = function (text) {
2172
+ /*jslint evil: true */
2173
+ return eval(text);
2174
+ };
2175
+
2176
+ //Set up with config info.
2177
+ req(cfg);
2178
+
2179
+ global.requirejs = global.require = req;
2180
+ global.define = define;
2181
+ }(window, (typeof setTimeout === 'undefined' ? undefined : setTimeout)));
2182
+
2183
+
26
2184
  /***/ }),
27
2185
 
28
2186
  /***/ "./node_modules/nycticorax/dist/index.js":
@@ -50,6 +2208,7 @@ __webpack_require__.r(__webpack_exports__);
50
2208
  /* harmony export */ DEPENDENCIES_KEY: function() { return /* binding */ DEPENDENCIES_KEY; },
51
2209
  /* harmony export */ MESSAGE_KEY: function() { return /* binding */ MESSAGE_KEY; },
52
2210
  /* harmony export */ MOUNTED_COMPONENTS_KEY: function() { return /* binding */ MOUNTED_COMPONENTS_KEY; },
2211
+ /* harmony export */ STANDALONE_CONFIG_READY: function() { return /* binding */ STANDALONE_CONFIG_READY; },
53
2212
  /* harmony export */ VUE_FUNCTION_OPTIONS: function() { return /* binding */ VUE_FUNCTION_OPTIONS; },
54
2213
  /* harmony export */ VUE_VERSION: function() { return /* binding */ VUE_VERSION; }
55
2214
  /* harmony export */ });
@@ -57,6 +2216,7 @@ const MOUNTED_COMPONENTS_KEY = Symbol('MOUNTED_COMPONENTS');
57
2216
  const MESSAGE_KEY = Symbol('MESSAGE');
58
2217
  const CONFIG_KEY = Symbol('CONFIG');
59
2218
  const DEPENDENCIES_KEY = Symbol('DEPENDENCIES');
2219
+ const STANDALONE_CONFIG_READY = Symbol('STANDALONE_CONFIG_READY');
60
2220
  const VUE_FUNCTION_OPTIONS = ['beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUpdate', 'updated', 'beforeUnmount', 'unmounted', 'errorCaptured', 'renderTracked', 'renderTriggered', 'activated', 'deactivated', 'setup', 'data', 'render'];
61
2221
  const VUE_VERSION = 3;
62
2222
  const BASE_DEPENDENCIES = ['react', 'react-dom', '@variousjs/various', 'app'];
@@ -604,7 +2764,15 @@ const resetDependencyConfig = (name, url) => {
604
2764
  const dependencies = (0,_store__WEBPACK_IMPORTED_MODULE_0__.getStore)(_config__WEBPACK_IMPORTED_MODULE_2__.DEPENDENCIES_KEY);
605
2765
 
606
2766
  // ignore multiple custom module url
607
- if (url && window.requirejs.defined(name)) {
2767
+ if (url && isModuleLoaded(name)) {
2768
+ return;
2769
+ }
2770
+ if (!dependencies[name] && url) {
2771
+ window.requirejs.config({
2772
+ paths: {
2773
+ [name]: `${url}#${name}`
2774
+ }
2775
+ });
608
2776
  return;
609
2777
  }
610
2778
  let path = getUrlHash(dependencies[name]);
@@ -1537,58 +3705,25 @@ function vueComponent(config) {
1537
3705
  "use strict";
1538
3706
  __webpack_require__.r(__webpack_exports__);
1539
3707
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1540
- /* harmony export */ defineModules: function() { return /* binding */ defineModules; },
1541
- /* harmony export */ loadRequireJS: function() { return /* binding */ loadRequireJS; }
3708
+ /* harmony export */ defineModules: function() { return /* binding */ defineModules; }
1542
3709
  /* harmony export */ });
1543
3710
  /* harmony import */ var _core_helper__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/helper */ "./src/core/helper.ts");
1544
3711
 
1545
- let requirejsPromise;
1546
- function loadRequireJS(dep) {
1547
- if (requirejsPromise) {
1548
- return requirejsPromise;
1549
- }
1550
- const promise = new Promise((resolve, reject) => {
1551
- if (!dep) {
1552
- reject(new _core_helper__WEBPACK_IMPORTED_MODULE_0__.VariousError({
1553
- name: 'standalone',
1554
- type: 'NOT_DEFINED',
1555
- originalError: new Error('requirejs not defined')
1556
- }));
3712
+ const defineAsync = (name, dep) => new Promise(resolve => {
3713
+ window.define(name, [], () => dep);
3714
+ const check = () => {
3715
+ if (window.requirejs.specified(name)) {
3716
+ resolve();
1557
3717
  return;
1558
3718
  }
1559
- if (typeof dep === 'string') {
1560
- const script = document.createElement('script');
1561
- script.src = dep;
1562
- script.onload = e => resolve(e);
1563
- script.onerror = e => reject(e);
1564
- document.head.appendChild(script);
1565
- return;
1566
- }
1567
-
1568
- // @ts-ignore
1569
- window.requirejs = dep;
1570
- resolve(new Event('requirejs defined'));
1571
- });
1572
- requirejsPromise = promise;
1573
- return requirejsPromise;
1574
- }
1575
- const defineAsync = (name, factory) => {
1576
- window.define(name, [], factory);
1577
- return new Promise(resolve => {
1578
- const check = () => {
1579
- if (window.requirejs.specified(name)) {
1580
- resolve();
1581
- return;
1582
- }
1583
- setTimeout(check, 100);
1584
- };
1585
- check();
1586
- });
1587
- };
3719
+ setTimeout(check, 100);
3720
+ };
3721
+ check();
3722
+ });
1588
3723
  function defineModules(deps) {
1589
3724
  const defines = [];
1590
3725
  Object.entries(deps).forEach(([key, value]) => {
1591
- if ((0,_core_helper__WEBPACK_IMPORTED_MODULE_0__.isModuleSpecified)(key)) {
3726
+ if ((0,_core_helper__WEBPACK_IMPORTED_MODULE_0__.isModuleSpecified)(key) || value === undefined) {
1592
3727
  return;
1593
3728
  }
1594
3729
  if (typeof value === 'string') {
@@ -1604,7 +3739,7 @@ function defineModules(deps) {
1604
3739
  value
1605
3740
  });
1606
3741
  });
1607
- return Promise.all(defines.map(item => defineAsync(item.key, () => item.value)));
3742
+ return Promise.all(defines.map(item => defineAsync(item.key, item.value)));
1608
3743
  }
1609
3744
 
1610
3745
  /***/ }),
@@ -1701,12 +3836,13 @@ __webpack_require__.r(__webpack_exports__);
1701
3836
  /* harmony export */ createConfig: function() { return /* binding */ createConfig; }
1702
3837
  /* harmony export */ });
1703
3838
  /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/extends */ "./node_modules/@babel/runtime/helpers/esm/extends.js");
1704
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react */ "react");
1705
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
1706
- /* harmony import */ var _core_create_component__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../core/create-component */ "./src/core/create-component.tsx");
1707
- /* harmony import */ var _core_error_boundary__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../core/error-boundary */ "./src/core/error-boundary.tsx");
1708
- /* harmony import */ var _core_connector__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../core/connector */ "./src/core/connector.ts");
1709
- /* harmony import */ var _core_helper__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../core/helper */ "./src/core/helper.ts");
3839
+ /* harmony import */ var _variousjs_requirejs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @variousjs/requirejs */ "./node_modules/@variousjs/requirejs/require.js");
3840
+ /* harmony import */ var _variousjs_requirejs__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_variousjs_requirejs__WEBPACK_IMPORTED_MODULE_1__);
3841
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react */ "react");
3842
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_2__);
3843
+ /* harmony import */ var _core_create_component__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../core/create-component */ "./src/core/create-component.tsx");
3844
+ /* harmony import */ var _core_error_boundary__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../core/error-boundary */ "./src/core/error-boundary.tsx");
3845
+ /* harmony import */ var _core_connector__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../core/connector */ "./src/core/connector.ts");
1710
3846
  /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./helper */ "./src/standalone/helper.ts");
1711
3847
  /* harmony import */ var _core_store__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../core/store */ "./src/core/store.ts");
1712
3848
  /* harmony import */ var _core_config__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../core/config */ "./src/core/config.ts");
@@ -1723,8 +3859,10 @@ __webpack_require__.r(__webpack_exports__);
1723
3859
  [_core_config__WEBPACK_IMPORTED_MODULE_8__.MOUNTED_COMPONENTS_KEY]: [],
1724
3860
  [_core_config__WEBPACK_IMPORTED_MODULE_8__.MESSAGE_KEY]: null,
1725
3861
  [_core_config__WEBPACK_IMPORTED_MODULE_8__.CONFIG_KEY]: {},
1726
- [_core_config__WEBPACK_IMPORTED_MODULE_8__.DEPENDENCIES_KEY]: {}
3862
+ [_core_config__WEBPACK_IMPORTED_MODULE_8__.DEPENDENCIES_KEY]: {},
3863
+ [_core_config__WEBPACK_IMPORTED_MODULE_8__.STANDALONE_CONFIG_READY]: undefined
1727
3864
  });
3865
+ window.define('react', [], () => (react__WEBPACK_IMPORTED_MODULE_2___default()));
1728
3866
  const Standalone = props => {
1729
3867
  const {
1730
3868
  dependencies,
@@ -1736,37 +3874,23 @@ const Standalone = props => {
1736
3874
  $ref,
1737
3875
  storeKeys
1738
3876
  } = props;
1739
- const [componentReady, setComponentReady] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(false);
1740
- const componentNode = (0,react__WEBPACK_IMPORTED_MODULE_1__.useRef)();
1741
- const errorRef = (0,react__WEBPACK_IMPORTED_MODULE_1__.useRef)();
1742
- const [isError, setIsError] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(false);
1743
- (0,react__WEBPACK_IMPORTED_MODULE_1__.useEffect)(() => {
1744
- (0,_helper__WEBPACK_IMPORTED_MODULE_6__.loadRequireJS)(dependencies?.requirejs).then(() => {
1745
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1746
- const {
1747
- requirejs,
1748
- ...rest
1749
- } = dependencies || {};
1750
- return (0,_helper__WEBPACK_IMPORTED_MODULE_6__.defineModules)(rest);
1751
- }).then(() => {
1752
- componentNode.current = (0,_core_create_component__WEBPACK_IMPORTED_MODULE_2__["default"])({
3877
+ const store = (0,_core_store__WEBPACK_IMPORTED_MODULE_7__.useStore)(_core_config__WEBPACK_IMPORTED_MODULE_8__.STANDALONE_CONFIG_READY);
3878
+ const [componentReady, setComponentReady] = (0,react__WEBPACK_IMPORTED_MODULE_2__.useState)(false);
3879
+ const componentNode = (0,react__WEBPACK_IMPORTED_MODULE_2__.useRef)();
3880
+ (0,react__WEBPACK_IMPORTED_MODULE_2__.useEffect)(() => {
3881
+ (0,_helper__WEBPACK_IMPORTED_MODULE_6__.defineModules)(dependencies || {}).then(() => {
3882
+ componentNode.current = (0,_core_create_component__WEBPACK_IMPORTED_MODULE_3__["default"])({
1753
3883
  name,
1754
3884
  module,
1755
3885
  url,
1756
3886
  type
1757
3887
  }, storeKeys);
1758
3888
  setComponentReady(true);
1759
- }).catch(e => {
1760
- errorRef.current = e;
1761
- setIsError(true);
1762
3889
  });
1763
3890
  }, [name, url, module, dependencies, type, storeKeys]);
1764
- if (isError) {
1765
- throw errorRef.current;
1766
- }
1767
- if (!componentReady) {
1768
- const FallBack = _core_connector__WEBPACK_IMPORTED_MODULE_4__["default"].getFallbackComponent();
1769
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement(FallBack, {
3891
+ if (!componentReady || store[_core_config__WEBPACK_IMPORTED_MODULE_8__.STANDALONE_CONFIG_READY] === false) {
3892
+ const FallBack = _core_connector__WEBPACK_IMPORTED_MODULE_5__["default"].getFallbackComponent();
3893
+ return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_2___default().createElement(FallBack, {
1770
3894
  $self: {
1771
3895
  name,
1772
3896
  module,
@@ -1776,17 +3900,17 @@ const Standalone = props => {
1776
3900
  });
1777
3901
  }
1778
3902
  const C = componentNode.current;
1779
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement(C, (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__["default"])({}, $componentProps, {
3903
+ return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_2___default().createElement(C, (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__["default"])({}, $componentProps, {
1780
3904
  ref: $ref
1781
3905
  }));
1782
3906
  };
1783
3907
  Standalone.displayName = 'various-standalone';
1784
3908
  const createComponent = args => {
1785
- const component = props => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement(_core_error_boundary__WEBPACK_IMPORTED_MODULE_3__["default"], {
3909
+ const component = props => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_2___default().createElement(_core_error_boundary__WEBPACK_IMPORTED_MODULE_4__["default"], {
1786
3910
  name: "standalone",
1787
3911
  url: args.url,
1788
3912
  module: args.module
1789
- }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement(Standalone, (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__["default"])({
3913
+ }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_2___default().createElement(Standalone, (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__["default"])({
1790
3914
  $componentProps: props
1791
3915
  }, args)));
1792
3916
  const dispatch = next => {
@@ -1804,27 +3928,22 @@ const createConfig = config => {
1804
3928
  fallback,
1805
3929
  store
1806
3930
  } = config;
1807
- const {
1808
- requirejs,
1809
- ...rest
1810
- } = baseDependencies;
3931
+ (0,_core_store__WEBPACK_IMPORTED_MODULE_7__.emit)({
3932
+ [_core_config__WEBPACK_IMPORTED_MODULE_8__.STANDALONE_CONFIG_READY]: false
3933
+ }, true);
1811
3934
  if (errorFallback) {
1812
- _core_connector__WEBPACK_IMPORTED_MODULE_4__["default"].setErrorFallbackComponent(errorFallback);
3935
+ _core_connector__WEBPACK_IMPORTED_MODULE_5__["default"].setErrorFallbackComponent(errorFallback);
1813
3936
  }
1814
3937
  if (fallback) {
1815
- _core_connector__WEBPACK_IMPORTED_MODULE_4__["default"].setFallbackComponent(fallback);
3938
+ _core_connector__WEBPACK_IMPORTED_MODULE_5__["default"].setFallbackComponent(fallback);
1816
3939
  }
1817
3940
  if (store) {
1818
3941
  (0,_core_store__WEBPACK_IMPORTED_MODULE_7__.emit)(store);
1819
3942
  }
1820
- (0,_helper__WEBPACK_IMPORTED_MODULE_6__.loadRequireJS)(requirejs).then(() => {
1821
- (0,_helper__WEBPACK_IMPORTED_MODULE_6__.defineModules)(rest);
1822
- }).catch(e => {
1823
- (0,_core_helper__WEBPACK_IMPORTED_MODULE_5__.onError)(new _core_helper__WEBPACK_IMPORTED_MODULE_5__.VariousError({
1824
- name: 'standalone',
1825
- type: 'CONFIG_ERROR',
1826
- originalError: e
1827
- }));
3943
+ (0,_helper__WEBPACK_IMPORTED_MODULE_6__.defineModules)(baseDependencies).then(() => {
3944
+ (0,_core_store__WEBPACK_IMPORTED_MODULE_7__.emit)({
3945
+ [_core_config__WEBPACK_IMPORTED_MODULE_8__.STANDALONE_CONFIG_READY]: true
3946
+ });
1828
3947
  });
1829
3948
  };
1830
3949
  }();