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