UNPKG

can-fragment

Version:

Create a fragment from lots of stuff

266 lines (258 loc) 8.52 kB
/*[process-shim]*/ (function(global, env) { // jshint ignore:line if (typeof process === "undefined") { global.process = { argv: [], cwd: function() { return ""; }, browser: true, env: { NODE_ENV: env || "development" }, version: "", platform: global.navigator && global.navigator.userAgent && /Windows/.test(global.navigator.userAgent) ? "win" : "" }; } })( typeof self == "object" && self.Object == Object ? self : typeof process === "object" && Object.prototype.toString.call(process) === "[object process]" ? global : window, "development" ); /*[global-shim-start]*/ (function(exports, global, doEval) { // jshint ignore:line var origDefine = global.define; var get = function(name) { var parts = name.split("."), cur = global, i; for (i = 0; i < parts.length; i++) { if (!cur) { break; } cur = cur[parts[i]]; } return cur; }; var set = function(name, val) { var parts = name.split("."), cur = global, i, part, next; for (i = 0; i < parts.length - 1; i++) { part = parts[i]; next = cur[part]; if (!next) { next = cur[part] = {}; } cur = next; } part = parts[parts.length - 1]; cur[part] = val; }; var useDefault = function(mod) { if (!mod || !mod.__esModule) return false; var esProps = { __esModule: true, default: true }; for (var p in mod) { if (!esProps[p]) return false; } return true; }; var hasCjsDependencies = function(deps) { return ( deps[0] === "require" && deps[1] === "exports" && deps[2] === "module" ); }; var modules = (global.define && global.define.modules) || (global._define && global._define.modules) || {}; var ourDefine = (global.define = function(moduleName, deps, callback) { var module; if (typeof deps === "function") { callback = deps; deps = []; } var args = [], i; for (i = 0; i < deps.length; i++) { args.push( exports[deps[i]] ? get(exports[deps[i]]) : modules[deps[i]] || get(deps[i]) ); } // CJS has no dependencies but 3 callback arguments if (hasCjsDependencies(deps) || (!deps.length && callback.length)) { module = { exports: {} }; args[0] = function(name) { return exports[name] ? get(exports[name]) : modules[name]; }; args[1] = module.exports; args[2] = module; } // Babel uses the exports and module object. else if (!args[0] && deps[0] === "exports") { module = { exports: {} }; args[0] = module.exports; if (deps[1] === "module") { args[1] = module; } } else if (!args[0] && deps[0] === "module") { args[0] = { id: moduleName }; } global.define = origDefine; var result = callback ? callback.apply(null, args) : undefined; global.define = ourDefine; // Favor CJS module.exports over the return value result = module && module.exports ? module.exports : result; modules[moduleName] = result; // Set global exports var globalExport = exports[moduleName]; if (globalExport && !get(globalExport)) { if (useDefault(result)) { result = result["default"]; } set(globalExport, result); } }); global.define.orig = origDefine; global.define.modules = modules; global.define.amd = true; ourDefine("@loader", [], function() { // shim for @@global-helpers var noop = function() {}; return { get: function() { return { prepareGlobal: noop, retrieveGlobal: noop }; }, global: global, __exec: function(__load) { doEval(__load.source, global); } }; }); })( {}, typeof self == "object" && self.Object == Object ? self : typeof process === "object" && Object.prototype.toString.call(process) === "[object process]" ? global : window, function(__$source__, __$global__) { // jshint ignore:line eval("(function() { " + __$source__ + " \n }).call(__$global__);"); } ); /*can-fragment@1.3.0#can-fragment*/ define('can-fragment', [ 'require', 'exports', 'module', 'can-globals/document/document', 'can-namespace', 'can-reflect', 'can-child-nodes', 'can-symbol' ], function (require, exports, module) { (function (global, require, exports, module) { 'use strict'; var getDocument = require('can-globals/document/document'); var namespace = require('can-namespace'); var canReflect = require('can-reflect'); var childNodes = require('can-child-nodes'); var canSymbol = require('can-symbol'); var fragmentRE = /^\s*<(\w+)[^>]*>/, toString = {}.toString, toDOMSymbol = canSymbol.for('can.toDOM'); function makeFragment(html, name, doc) { if (name === undefined) { name = fragmentRE.test(html) && RegExp.$1; } if (html && toString.call(html.replace) === '[object Function]') { html = html.replace(/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, '<$1></$2>'); } var container = doc.createElement('div'), temp = doc.createElement('div'); if (name === 'tbody' || name === 'tfoot' || name === 'thead' || name === 'colgroup') { temp.innerHTML = '<table>' + html + '</table>'; container = temp.firstChild.nodeType === 3 ? temp.lastChild : temp.firstChild; } else if (name === 'col') { temp.innerHTML = '<table><colgroup>' + html + '</colgroup></table>'; container = temp.firstChild.nodeType === 3 ? temp.lastChild : temp.firstChild.firstChild; } else if (name === 'tr') { temp.innerHTML = '<table><tbody>' + html + '</tbody></table>'; container = temp.firstChild.nodeType === 3 ? temp.lastChild : temp.firstChild.firstChild; } else if (name === 'td' || name === 'th') { temp.innerHTML = '<table><tbody><tr>' + html + '</tr></tbody></table>'; container = temp.firstChild.nodeType === 3 ? temp.lastChild : temp.firstChild.firstChild.firstChild; } else if (name === 'option') { temp.innerHTML = '<select>' + html + '</select>'; container = temp.firstChild.nodeType === 3 ? temp.lastChild : temp.firstChild; } else { container.innerHTML = '' + html; } return [].slice.call(childNodes(container)); } function fragment(html, doc) { if (html && html.nodeType === 11) { return html; } if (!doc) { doc = getDocument(); } else if (doc.length) { doc = doc[0]; } var parts = makeFragment(html, undefined, doc), frag = (doc || document).createDocumentFragment(); for (var i = 0, length = parts.length; i < length; i++) { frag.appendChild(parts[i]); } return frag; } var makeFrag = function (item, doc) { var document = doc || getDocument(); var frag; if (!item || typeof item === 'string') { frag = fragment(item == null ? '' : '' + item, document); } else if (typeof item[toDOMSymbol] === 'function') { return makeFrag(item[toDOMSymbol]()); } else if (item.nodeType === 11) { return item; } else if (typeof item.nodeType === 'number') { frag = document.createDocumentFragment(); frag.appendChild(item); return frag; } else if (canReflect.isListLike(item)) { frag = document.createDocumentFragment(); canReflect.eachIndex(item, function (item) { frag.appendChild(makeFrag(item)); }); } else { frag = fragment('' + item, document); } if (!childNodes(frag).length) { frag.appendChild(document.createTextNode('')); } return frag; }; module.exports = namespace.fragment = namespace.frag = makeFrag; }(function () { return this; }(), require, exports, module)); }); /*[global-shim-end]*/ (function(global) { // jshint ignore:line global._define = global.define; global.define = global.define.orig; } )(typeof self == "object" && self.Object == Object ? self : (typeof process === "object" && Object.prototype.toString.call(process) === "[object process]") ? global : window);