You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

434 lines
15 KiB

3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /**
  2. * @license almond 0.3.3 Copyright jQuery Foundation and other contributors.
  3. * Released under MIT license, http://github.com/requirejs/almond/LICENSE
  4. */
  5. //Going sloppy to avoid 'use strict' string cost, but strict practices should
  6. //be followed.
  7. /*global setTimeout: false */
  8. var requirejs, require, define;
  9. (function (undef) {
  10. var main, req, makeMap, handlers,
  11. defined = {},
  12. waiting = {},
  13. config = {},
  14. defining = {},
  15. hasOwn = Object.prototype.hasOwnProperty,
  16. aps = [].slice,
  17. jsSuffixRegExp = /\.js$/;
  18. function hasProp(obj, prop) {
  19. return hasOwn.call(obj, prop);
  20. }
  21. /**
  22. * Given a relative module name, like ./something, normalize it to
  23. * a real name that can be mapped to a path.
  24. * @param {String} name the relative name
  25. * @param {String} baseName a real name that the name arg is relative
  26. * to.
  27. * @returns {String} normalized name
  28. */
  29. function normalize(name, baseName) {
  30. var nameParts, nameSegment, mapValue, foundMap, lastIndex,
  31. foundI, foundStarMap, starI, i, j, part, normalizedBaseParts,
  32. baseParts = baseName && baseName.split("/"),
  33. map = config.map,
  34. starMap = (map && map['*']) || {};
  35. //Adjust any relative paths.
  36. if (name) {
  37. name = name.split('/');
  38. lastIndex = name.length - 1;
  39. // If wanting node ID compatibility, strip .js from end
  40. // of IDs. Have to do this here, and not in nameToUrl
  41. // because node allows either .js or non .js to map
  42. // to same file.
  43. if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
  44. name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
  45. }
  46. // Starts with a '.' so need the baseName
  47. if (name[0].charAt(0) === '.' && baseParts) {
  48. //Convert baseName to array, and lop off the last part,
  49. //so that . matches that 'directory' and not name of the baseName's
  50. //module. For instance, baseName of 'one/two/three', maps to
  51. //'one/two/three.js', but we want the directory, 'one/two' for
  52. //this normalization.
  53. normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
  54. name = normalizedBaseParts.concat(name);
  55. }
  56. //start trimDots
  57. for (i = 0; i < name.length; i++) {
  58. part = name[i];
  59. if (part === '.') {
  60. name.splice(i, 1);
  61. i -= 1;
  62. } else if (part === '..') {
  63. // If at the start, or previous value is still ..,
  64. // keep them so that when converted to a path it may
  65. // still work when converted to a path, even though
  66. // as an ID it is less than ideal. In larger point
  67. // releases, may be better to just kick out an error.
  68. if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') {
  69. continue;
  70. } else if (i > 0) {
  71. name.splice(i - 1, 2);
  72. i -= 2;
  73. }
  74. }
  75. }
  76. //end trimDots
  77. name = name.join('/');
  78. }
  79. //Apply map config if available.
  80. if ((baseParts || starMap) && map) {
  81. nameParts = name.split('/');
  82. for (i = nameParts.length; i > 0; i -= 1) {
  83. nameSegment = nameParts.slice(0, i).join("/");
  84. if (baseParts) {
  85. //Find the longest baseName segment match in the config.
  86. //So, do joins on the biggest to smallest lengths of baseParts.
  87. for (j = baseParts.length; j > 0; j -= 1) {
  88. mapValue = map[baseParts.slice(0, j).join('/')];
  89. //baseName segment has config, find if it has one for
  90. //this name.
  91. if (mapValue) {
  92. mapValue = mapValue[nameSegment];
  93. if (mapValue) {
  94. //Match, update name to the new value.
  95. foundMap = mapValue;
  96. foundI = i;
  97. break;
  98. }
  99. }
  100. }
  101. }
  102. if (foundMap) {
  103. break;
  104. }
  105. //Check for a star map match, but just hold on to it,
  106. //if there is a shorter segment match later in a matching
  107. //config, then favor over this star map.
  108. if (!foundStarMap && starMap && starMap[nameSegment]) {
  109. foundStarMap = starMap[nameSegment];
  110. starI = i;
  111. }
  112. }
  113. if (!foundMap && foundStarMap) {
  114. foundMap = foundStarMap;
  115. foundI = starI;
  116. }
  117. if (foundMap) {
  118. nameParts.splice(0, foundI, foundMap);
  119. name = nameParts.join('/');
  120. }
  121. }
  122. return name;
  123. }
  124. function makeRequire(relName, forceSync) {
  125. return function () {
  126. //A version of a require function that passes a moduleName
  127. //value for items that may need to
  128. //look up paths relative to the moduleName
  129. var args = aps.call(arguments, 0);
  130. //If first arg is not require('string'), and there is only
  131. //one arg, it is the array form without a callback. Insert
  132. //a null so that the following concat is correct.
  133. if (typeof args[0] !== 'string' && args.length === 1) {
  134. args.push(null);
  135. }
  136. return req.apply(undef, args.concat([relName, forceSync]));
  137. };
  138. }
  139. function makeNormalize(relName) {
  140. return function (name) {
  141. return normalize(name, relName);
  142. };
  143. }
  144. function makeLoad(depName) {
  145. return function (value) {
  146. defined[depName] = value;
  147. };
  148. }
  149. function callDep(name) {
  150. if (hasProp(waiting, name)) {
  151. var args = waiting[name];
  152. delete waiting[name];
  153. defining[name] = true;
  154. main.apply(undef, args);
  155. }
  156. if (!hasProp(defined, name) && !hasProp(defining, name)) {
  157. throw new Error('No ' + name);
  158. }
  159. return defined[name];
  160. }
  161. //Turns a plugin!resource to [plugin, resource]
  162. //with the plugin being undefined if the name
  163. //did not have a plugin prefix.
  164. function splitPrefix(name) {
  165. var prefix,
  166. index = name ? name.indexOf('!') : -1;
  167. if (index > -1) {
  168. prefix = name.substring(0, index);
  169. name = name.substring(index + 1, name.length);
  170. }
  171. return [prefix, name];
  172. }
  173. //Creates a parts array for a relName where first part is plugin ID,
  174. //second part is resource ID. Assumes relName has already been normalized.
  175. function makeRelParts(relName) {
  176. return relName ? splitPrefix(relName) : [];
  177. }
  178. /**
  179. * Makes a name map, normalizing the name, and using a plugin
  180. * for normalization if necessary. Grabs a ref to plugin
  181. * too, as an optimization.
  182. */
  183. makeMap = function (name, relParts) {
  184. var plugin,
  185. parts = splitPrefix(name),
  186. prefix = parts[0],
  187. relResourceName = relParts[1];
  188. name = parts[1];
  189. if (prefix) {
  190. prefix = normalize(prefix, relResourceName);
  191. plugin = callDep(prefix);
  192. }
  193. //Normalize according
  194. if (prefix) {
  195. if (plugin && plugin.normalize) {
  196. name = plugin.normalize(name, makeNormalize(relResourceName));
  197. } else {
  198. name = normalize(name, relResourceName);
  199. }
  200. } else {
  201. name = normalize(name, relResourceName);
  202. parts = splitPrefix(name);
  203. prefix = parts[0];
  204. name = parts[1];
  205. if (prefix) {
  206. plugin = callDep(prefix);
  207. }
  208. }
  209. //Using ridiculous property names for space reasons
  210. return {
  211. f: prefix ? prefix + '!' + name : name, //fullName
  212. n: name,
  213. pr: prefix,
  214. p: plugin
  215. };
  216. };
  217. function makeConfig(name) {
  218. return function () {
  219. return (config && config.config && config.config[name]) || {};
  220. };
  221. }
  222. handlers = {
  223. require: function (name) {
  224. return makeRequire(name);
  225. },
  226. exports: function (name) {
  227. var e = defined[name];
  228. if (typeof e !== 'undefined') {
  229. return e;
  230. } else {
  231. return (defined[name] = {});
  232. }
  233. },
  234. module: function (name) {
  235. return {
  236. id: name,
  237. uri: '',
  238. exports: defined[name],
  239. config: makeConfig(name)
  240. };
  241. }
  242. };
  243. main = function (name, deps, callback, relName) {
  244. var cjsModule, depName, ret, map, i, relParts,
  245. args = [],
  246. callbackType = typeof callback,
  247. usingExports;
  248. //Use name if no relName
  249. relName = relName || name;
  250. relParts = makeRelParts(relName);
  251. //Call the callback to define the module, if necessary.
  252. if (callbackType === 'undefined' || callbackType === 'function') {
  253. //Pull out the defined dependencies and pass the ordered
  254. //values to the callback.
  255. //Default to [require, exports, module] if no deps
  256. deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
  257. for (i = 0; i < deps.length; i += 1) {
  258. map = makeMap(deps[i], relParts);
  259. depName = map.f;
  260. //Fast path CommonJS standard dependencies.
  261. if (depName === "require") {
  262. args[i] = handlers.require(name);
  263. } else if (depName === "exports") {
  264. //CommonJS module spec 1.1
  265. args[i] = handlers.exports(name);
  266. usingExports = true;
  267. } else if (depName === "module") {
  268. //CommonJS module spec 1.1
  269. cjsModule = args[i] = handlers.module(name);
  270. } else if (hasProp(defined, depName) ||
  271. hasProp(waiting, depName) ||
  272. hasProp(defining, depName)) {
  273. args[i] = callDep(depName);
  274. } else if (map.p) {
  275. map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
  276. args[i] = defined[depName];
  277. } else {
  278. throw new Error(name + ' missing ' + depName);
  279. }
  280. }
  281. ret = callback ? callback.apply(defined[name], args) : undefined;
  282. if (name) {
  283. //If setting exports via "module" is in play,
  284. //favor that over return value and exports. After that,
  285. //favor a non-undefined return value over exports use.
  286. if (cjsModule && cjsModule.exports !== undef &&
  287. cjsModule.exports !== defined[name]) {
  288. defined[name] = cjsModule.exports;
  289. } else if (ret !== undef || !usingExports) {
  290. //Use the return value from the function.
  291. defined[name] = ret;
  292. }
  293. }
  294. } else if (name) {
  295. //May just be an object definition for the module. Only
  296. //worry about defining if have a module name.
  297. defined[name] = callback;
  298. }
  299. };
  300. requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
  301. if (typeof deps === "string") {
  302. if (handlers[deps]) {
  303. //callback in this case is really relName
  304. return handlers[deps](callback);
  305. }
  306. //Just return the module wanted. In this scenario, the
  307. //deps arg is the module name, and second arg (if passed)
  308. //is just the relName.
  309. //Normalize module name, if it contains . or ..
  310. return callDep(makeMap(deps, makeRelParts(callback)).f);
  311. } else if (!deps.splice) {
  312. //deps is a config object, not an array.
  313. config = deps;
  314. if (config.deps) {
  315. req(config.deps, config.callback);
  316. }
  317. if (!callback) {
  318. return;
  319. }
  320. if (callback.splice) {
  321. //callback is an array, which means it is a dependency list.
  322. //Adjust args if there are dependencies
  323. deps = callback;
  324. callback = relName;
  325. relName = null;
  326. } else {
  327. deps = undef;
  328. }
  329. }
  330. //Support require(['a'])
  331. callback = callback || function () {};
  332. //If relName is a function, it is an errback handler,
  333. //so remove it.
  334. if (typeof relName === 'function') {
  335. relName = forceSync;
  336. forceSync = alt;
  337. }
  338. //Simulate async callback;
  339. if (forceSync) {
  340. main(undef, deps, callback, relName);
  341. } else {
  342. //Using a non-zero value because of concern for what old browsers
  343. //do, and latest browsers "upgrade" to 4 if lower value is used:
  344. //http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout:
  345. //If want a value immediately, use require('id') instead -- something
  346. //that works in almond on the global level, but not guaranteed and
  347. //unlikely to work in other AMD implementations.
  348. setTimeout(function () {
  349. main(undef, deps, callback, relName);
  350. }, 4);
  351. }
  352. return req;
  353. };
  354. /**
  355. * Just drops the config on the floor, but returns req in case
  356. * the config return value is used.
  357. */
  358. req.config = function (cfg) {
  359. return req(cfg);
  360. };
  361. /**
  362. * Expose module registry for debugging and tooling
  363. */
  364. requirejs._defined = defined;
  365. define = function (name, deps, callback) {
  366. if (typeof name !== 'string') {
  367. throw new Error('See almond README: incorrect module build, no module name');
  368. }
  369. //This module may not have dependencies
  370. if (!deps.splice) {
  371. //deps is not an array, so probably means
  372. //an object literal or factory function for
  373. //the value. Adjust args.
  374. callback = deps;
  375. deps = [];
  376. }
  377. if (!hasProp(defined, name) && !hasProp(waiting, name)) {
  378. waiting[name] = [name, deps, callback];
  379. }
  380. };
  381. define.amd = {
  382. jQuery: true
  383. };
  384. }());