@cesium/engine 3.0.2 → 4.0.0

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