UNPKG

zwapp

Version:

前端框架-学习

8 lines (7 loc) 3.06 kB
/*! * tools v0.2.2 * (c) 2022-2025 zhenwei * Released under the MIT License. */ var r=Symbol.for("Fragment"),t=Symbol.for("TEXT_ELEMENT");var e=function(e,n){for(var o=arguments.length,i=new Array(o>2?o-2:0),l=2;l<o;l++)i[l-2]=arguments[l];return e===r?{type:r,props:{},children:i.flat().filter(Boolean)}:{type:e,props:n||{},children:i.flat().map((function(r){return null==r||!1===r?null:"string"==typeof r||"number"==typeof r?{type:t,props:{nodeValue:String(r)},children:[]}:r})).filter(Boolean)}},n=function(t){return{type:r,props:t,children:t.children||[]}};n.isFragment=function(t){return t===r};function o(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=Array(t);e<t;e++)n[e]=r[e];return n}function i(r,t){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){var e=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=e){var n,o,i,l,a=[],u=!0,c=!1;try{if(i=(e=e.call(r)).next,0===t){if(Object(e)!==e)return;u=!1}else for(;!(u=(n=i.call(e)).done)&&(a.push(n.value),a.length!==t);u=!0);}catch(r){c=!0,o=r}finally{try{if(!u&&null!=e.return&&(l=e.return(),Object(l)!==l))return}finally{if(c)throw o}}return a}}(r,t)||function(r,t){if(r){if("string"==typeof r)return o(r,t);var e={}.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?o(r,t):void 0}}(r,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(r){return l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},l(r)}var a=function(r){return Boolean(r&&"object"===l(r))};function u(e){if(!a(e))return document.createTextNode(e?"".concat(e):"");var n;if(e.type===t)return document.createTextNode(null===(n=e.props)||void 0===n?void 0:n.nodeValue);if(e.type===r)return document.createDocumentFragment();if("function"==typeof e.type)return u(e.type(e.props));var o=document.createElement(e.type);return Object.entries(e.props||{}).forEach((function(r){var t=i(r,2),e=t[0],n=t[1];"className"===e?o.setAttribute("class",n):e.startsWith("on")&&e.toLowerCase()in window?o.addEventListener(e.toLowerCase().slice(2),n):"style"===e&&"object"===l(n)?Object.assign(o.style,n):"children"!==e&&"object"!==l(n)&&o.setAttribute(e,n)})),o}function c(t,e){if(t)if("object"===l(t)){var n=u(t);if(a(t)&&Array.isArray(null==t?void 0:t.children)&&(null==t?void 0:t.children.length)>0){var o=u({type:r,children:t.children});t.children.forEach((function(t){Array.isArray(t)?c({type:r,children:t,props:{}},o):c(t,o)})),n.appendChild(o)}e.appendChild(n)}else{var i=u(t);e.appendChild(i)}}var f={version:"0.2.2",h:e,Fragment:n,render:c};export{r as FRAGMENT_NODE,n as Fragment,f as default,e as h,c as render}; //# sourceMappingURL=index.js.map