Socket
Socket
Sign inDemoInstall

i2ui

Package Overview
Dependencies
7
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-alfa.1 to 2.0.0-alfa.2

dist/src/treemap/utils/index.d.ts

2

dist/index.esm.js

@@ -1,1 +0,1 @@

import React,{useMemo,useCallback}from"react";import{emphasizeStyle}from"emphasizer";var __assign=function(){return(__assign=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++)for(var n in e=arguments[r])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)},NumberUtil=function(){function c(){}return c.toFloat=function(t){var e;return"string"==typeof t?t===(e=parseFloat(t)).toString()?e:void 0:t},c.splitNumber=function(t,e){var r=[];if(void 0!==t){var i=e.decimalDigits,n=e.groupSeparator,o=void 0===n?",":n,n=e.decimalSeparator,e=e.groupDigits,t=t.toFixed(i||0).split(".");if(0<t.length){for(var a=c.toGroups(t[0],e),s=0;s<a.length;s++)r.push({text:a[s],separator:!(0<s)||void 0===o?void 0:o});2!==t.length||(i=t[1])&&r.push({text:i,isFraction:!0,separator:n||"."})}}return r},c.toGroups=function(t,e){return 0===e?[t]:(e=Math.abs(e||3),t.match(new RegExp("(\\d+?)(?=(\\d{".concat(e,"})+(?!\\d)|$)"),"g"))||[])},c}(),rootStyle={display:"inline-block"},defaultContentStyle={display:"flex",flexDirection:"row",alignItems:"flex-end"},numberPartStyle={lineHeight:"1em"},I2Number=function(t){var e=t.fromStyle,r=t.toStyle,i=t.decimalDigits,n=t.verticalAlign,o=t.className,a=t.style,s=t.groupSeparator,c=t.decimalSeparator,u=t.groupDigits,l=t.value,d=t.basicMaxValue,h=t.children,f=useMemo(function(){return{decimalDigits:i,decimalSeparator:c,groupSeparator:s,groupDigits:u}},[i,c,s,u]),p=useMemo(function(){return NumberUtil.splitNumber(NumberUtil.toFloat(h||l),f)},[h,l,f]),g=useMemo(function(){return NumberUtil.splitNumber(NumberUtil.toFloat(d),f)},[d,f]),m=useMemo(function(){return __assign({fontSize:"1em"},e)},[e]),_=useMemo(function(){return __assign({fontSize:"2em"},r)},[r]),t=useMemo(function(){var t=__assign({},defaultContentStyle);return"top"===n?t.alignItems="flex-start":"center"===n&&(t.alignItems="center"),t},[n]);return React.createElement("div",{className:o,style:__assign(__assign({},rootStyle),a)},React.createElement("div",{style:t},p.map(function(t,e){var r=t.text,t=t.separator,i=g.length;return React.createElement("div",{key:e,style:__assign(__assign({},emphasizeStyle(m,_,1,i,p.length-e)),numberPartStyle)},"".concat(t||"").concat(r))})))},TagUtil=function(){function t(){}return t.order=function(t,e,r){var i,n,o;return"desc"===e||"middle"===e?(n=t.sort(function(t,e){return r(t)>r(e)?-1:r(t)<r(e)?1:0}),"middle"===e&&(i=[],n.forEach(function(t,e){e%2==0?i.push(t):i.unshift(t)}),n=i),n):"asc"===e||"edge"===e?(n=t.sort(function(t,e){return r(t)<r(e)?-1:r(t)>r(e)?1:0}),"edge"===e&&(o=[],n.forEach(function(t,e){e%2==0?o.push(t):o.unshift(t)}),n=o),n):t},t}(),TagCloud=function(t){var e=t.data,i=t.fromStyle,n=t.toStyle,r=t.order,o=void 0===r?"middle":r,r=t.className,a=t.style,s=t.render,t=t.valueDataIndex,c=void 0===t?"value":t,u=useCallback(function(t){return NumberUtil.toFloat(t[c])||0},[c]),t=useMemo(function(){var t=e.map(function(t){return u(t)});return[Math.min.apply(Math,t),Math.max.apply(Math,t)]},[e,u]),l=t[0],d=t[1],t=useMemo(function(){return TagUtil.order(e,o,u)},[e,o,u]),h=useMemo(function(){return __assign({display:"flex",flexWrap:"wrap",justifyItems:"center",alignItems:"center",justifyContent:"center",alignContent:"center"},a)},[a]);return React.createElement("div",{className:r,style:h},t.map(function(t,e){var r=emphasizeStyle(i,n,l,d,t.rate);return React.createElement(React.Fragment,{key:e},s?s(r,t,e):React.createElement("div",{style:r},t.text))}))},GridRectUtil=function(){function t(){}return t.rect=function(t,e,r,i){return{left:t,top:e,width:r,height:i}},t.split=function(t,e,r){var i=t.width-t.left,n=t.height-t.top,o=i<=n,e=Math.floor(e/(e+r)*(o?n:i));return o?(r=t.top+e,[__assign(__assign({},t),{height:r}),__assign(__assign({},t),{top:r})]):(n=t.left+e,[__assign(__assign({},t),{width:n}),__assign(__assign({},t),{left:n})])},t.square=function(t){return(t.width-t.left)*(t.height-t.top)},t}(),SPLIT_RATIO=.5,TreemapManager=function(){function t(){this._count=0,this._data=[],this._cols=0,this._rows=0,this._cards=[],this._valueDataIndex="",this.rootNode={rate:0,rootRate:0,rootSquare:0,rect:{top:0,left:0,width:100,height:100},record:void 0,children:[]}}return Object.defineProperty(t.prototype,"cards",{get:function(){return this._cards},enumerable:!1,configurable:!0}),t.prototype.init=function(t,e,r,i){void 0===i&&(i="rate"),this._count=0,this._cols=t,this._rows=e,this._data=r,this._valueDataIndex=i,this.refresh()},t.prototype.getRecordRate=function(t){t=t[this._valueDataIndex];if("number"==typeof t)return t;if("string"==typeof t){var e=parseFloat(t);if(e.toString()===t.toString())return e}return 0},t.prototype.refresh=function(){var r=this,t=this._data.map(function(t){return __assign({},t)}).sort(function(t,e){return r.getRecordRate(e)-r.getRecordRate(t)}),e={top:0,left:0,width:this._rows,height:this._cols},i=t.reduce(function(t,e){return t+r.getRecordRate(e)},0);this.rootNode=this.initNode(t,e,i,this._cols*this._rows),this._cards=[],this.initCard(this.rootNode,this._cards)},t.prototype.initNode=function(t,e,r,i){var n=this,o=(this._count++,t.reduce(function(t,e){return t+n.getRecordRate(e)},0)),a=[],s=void 0;if(1===t.length&&(s=t[0]),2===t.length){var c=t[0],u=t[1],l=GridRectUtil.split(e,this.getRecordRate(c),this.getRecordRate(u)),d=l[0],l=l[1];a.push({rate:this.getRecordRate(c),rootRate:r,rootSquare:i,rect:d,record:c,children:[]}),a.push({rate:this.getRecordRate(u),rootRate:r,rootSquare:i,rect:l,record:u,children:[]})}else if(2<t.length){for(var h=0,f=0,p=0,g=t;p<g.length;p++){var m=g[p];if(f++,h+=this.getRecordRate(m),o*SPLIT_RATIO<=h)break}c=GridRectUtil.split(e,h,o-h),d=c[0],l=c[1];a.push(this.initNode(t.slice(0,f),d,r,i)),a.push(this.initNode(t.slice(f),l,r,i))}return{rate:o,rootRate:r,rootSquare:i,rect:e,record:s,children:a}},t.prototype.initCard=function(t,e){var r=this;t.record&&e.push({record:t.record,rect:t.rect}),t.children.forEach(function(t){r.initCard(t,e)})},t}(),Treemap=function(t){var e=t.className,r=t.rows,i=void 0===r?100:r,r=t.cols,n=void 0===r?100:r,o=t.gap,r=t.valueDataIndex,a=void 0===r?"value":r,s=t.render,c=t.data,r=useMemo(function(){return{display:"grid",gridTemplateColumns:"repeat(".concat(n,", 1fr)"),gridTemplateRows:"repeat(".concat(i,", 1fr)"),gap:o}},[i,n,o]),t=useMemo(function(){var t=new TreemapManager;return t.init(i,n,c,a),t.cards},[i,n,c,a]);return React.createElement("div",{style:r,className:e},t.map(function(t,e){var r=t.rect,t=t.record,i=r.left,n=r.top,o=r.width,r=r.height,a={gridColumn:"".concat(i+1," / ").concat(o+1),gridRow:"".concat(n+1," / ").concat(r+1)};return s(a,t,e,{left:i,top:n,width:o,height:r,rootRate:0,rootSquare:0})}))};export{I2Number,TagCloud,Treemap};
import React,{useMemo,useCallback}from"react";import{emphasizeStyle}from"emphasizer";var __assign=function(){return(__assign=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++)for(var n in e=arguments[r])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)},NumberUtil=function(){function c(){}return c.toFloat=function(t){var e;return"string"==typeof t?t===(e=parseFloat(t)).toString()?e:void 0:t},c.splitNumber=function(t,e){var r=[];if(void 0!==t){var i=e.decimalDigits,n=e.groupSeparator,o=void 0===n?",":n,n=e.decimalSeparator,e=e.groupDigits,t=t.toFixed(i||0).split(".");if(0<t.length){for(var a=c.toGroups(t[0],e),s=0;s<a.length;s++)r.push({text:a[s],separator:!(0<s)||void 0===o?void 0:o});2!==t.length||(i=t[1])&&r.push({text:i,isFraction:!0,separator:n||"."})}}return r},c.toGroups=function(t,e){return 0===e?[t]:(e=Math.abs(e||3),t.match(new RegExp("(\\d+?)(?=(\\d{".concat(e,"})+(?!\\d)|$)"),"g"))||[])},c}(),rootStyle={display:"inline-block"},defaultContentStyle={display:"flex",flexDirection:"row",alignItems:"flex-end"},numberPartStyle={lineHeight:"1em"},I2Number=function(t){var e=t.fromStyle,r=t.toStyle,i=t.decimalDigits,n=t.verticalAlign,o=t.className,a=t.style,s=t.groupSeparator,c=t.decimalSeparator,u=t.groupDigits,l=t.value,d=t.basicMaxValue,f=t.children,h=useMemo(function(){return{decimalDigits:i,decimalSeparator:c,groupSeparator:s,groupDigits:u}},[i,c,s,u]),p=useMemo(function(){return NumberUtil.splitNumber(NumberUtil.toFloat(f||l),h)},[f,l,h]),g=useMemo(function(){return NumberUtil.splitNumber(NumberUtil.toFloat(d),h)},[d,h]),m=useMemo(function(){return __assign({fontSize:"1em"},e)},[e]),_=useMemo(function(){return __assign({fontSize:"2em"},r)},[r]),t=useMemo(function(){var t=__assign({},defaultContentStyle);return"top"===n?t.alignItems="flex-start":"center"===n&&(t.alignItems="center"),t},[n]);return React.createElement("div",{className:o,style:__assign(__assign({},rootStyle),a)},React.createElement("div",{style:t},p.map(function(t,e){var r=t.text,t=t.separator,i=g.length;return React.createElement("div",{key:e,style:__assign(__assign({},emphasizeStyle(m,_,1,i,p.length-e)),numberPartStyle)},"".concat(t||"").concat(r))})))},TagUtil=function(){function t(){}return t.order=function(t,e,r){var i,n,o;return"desc"===e||"middle"===e?(n=t.sort(function(t,e){return r(t)>r(e)?-1:r(t)<r(e)?1:0}),"middle"===e&&(i=[],n.forEach(function(t,e){e%2==0?i.push(t):i.unshift(t)}),n=i),n):"asc"===e||"edge"===e?(n=t.sort(function(t,e){return r(t)<r(e)?-1:r(t)>r(e)?1:0}),"edge"===e&&(o=[],n.forEach(function(t,e){e%2==0?o.push(t):o.unshift(t)}),n=o),n):t},t}(),TagCloud=function(t){var e=t.data,i=t.fromStyle,n=t.toStyle,r=t.order,o=void 0===r?"middle":r,r=t.className,a=t.style,s=t.render,t=t.valueDataIndex,c=void 0===t?"value":t,u=useCallback(function(t){return NumberUtil.toFloat(t[c])||0},[c]),t=useMemo(function(){var t=e.map(function(t){return u(t)});return[Math.min.apply(Math,t),Math.max.apply(Math,t)]},[e,u]),l=t[0],d=t[1],t=useMemo(function(){return TagUtil.order(e,o,u)},[e,o,u]),f=useMemo(function(){return __assign({display:"flex",flexWrap:"wrap",justifyItems:"center",alignItems:"center",justifyContent:"center",alignContent:"center"},a)},[a]);return React.createElement("div",{className:r,style:f},t.map(function(t,e){var r=emphasizeStyle(i,n,l,d,t.rate);return React.createElement(React.Fragment,{key:e},s?s(r,t,e):React.createElement("div",{style:r},t.text))}))},GridRectUtil=function(){function t(){}return t.rect=function(t,e,r,i){return{left:t,top:e,width:r,height:i}},t.split=function(t,e,r){var i=t.width-t.left,n=t.height-t.top,o=i<=n,e=Math.floor(e/(e+r)*(o?n:i));return o?(r=t.top+e,[__assign(__assign({},t),{height:r}),__assign(__assign({},t),{top:r})]):(n=t.left+e,[__assign(__assign({},t),{width:n}),__assign(__assign({},t),{left:n})])},t.square=function(t){return(t.width-t.left)*(t.height-t.top)},t}(),SPLIT_RATIO=.5,TreemapManager=function(){function t(){this._count=0,this._data=[],this._cols=0,this._rows=0,this._cards=[],this._valueDataIndex="",this.rootNode={rate:0,rootRate:0,rootSquare:0,rect:{top:0,left:0,width:100,height:100},record:void 0,children:[]}}return Object.defineProperty(t.prototype,"cards",{get:function(){return this._cards},enumerable:!1,configurable:!0}),t.prototype.init=function(t,e,r,i){void 0===i&&(i="rate"),this._count=0,this._cols=t,this._rows=e,this._data=r,this._valueDataIndex=i,this.refresh()},t.prototype.getRecordRate=function(t){t=t[this._valueDataIndex];if("number"==typeof t)return t;if("string"==typeof t){var e=parseFloat(t);if(e.toString()===t.toString())return e}return 0},t.prototype.refresh=function(){var r=this,t=this._data.map(function(t){return __assign({},t)}).sort(function(t,e){return r.getRecordRate(e)-r.getRecordRate(t)}),e={top:0,left:0,width:this._rows,height:this._cols},i=t.reduce(function(t,e){return t+r.getRecordRate(e)},0);this.rootNode=this.initNode(t,e,i,this._cols*this._rows),this._cards=[],this.initCard(this.rootNode,this._cards)},t.prototype.initNode=function(t,e,r,i){var n=this,o=(this._count++,t.reduce(function(t,e){return t+n.getRecordRate(e)},0)),a=[],s=void 0;if(1===t.length&&(s=t[0]),2===t.length){var c=t[0],u=t[1],l=GridRectUtil.split(e,this.getRecordRate(c),this.getRecordRate(u)),d=l[0],l=l[1];a.push({rate:this.getRecordRate(c),rootRate:r,rootSquare:i,rect:d,record:c,children:[]}),a.push({rate:this.getRecordRate(u),rootRate:r,rootSquare:i,rect:l,record:u,children:[]})}else if(2<t.length){for(var f=0,h=0,p=0,g=t;p<g.length;p++){var m=g[p];if(h++,f+=this.getRecordRate(m),o*SPLIT_RATIO<=f)break}c=GridRectUtil.split(e,f,o-f),d=c[0],l=c[1];a.push(this.initNode(t.slice(0,h),d,r,i)),a.push(this.initNode(t.slice(h),l,r,i))}return{rate:o,rootRate:r,rootSquare:i,rect:e,record:s,children:a}},t.prototype.initCard=function(t,e){var r=this;t.record&&e.push({record:t.record,rect:t.rect}),t.children.forEach(function(t){r.initCard(t,e)})},t}(),Treemap=function(t){var e=t.className,r=t.rows,i=void 0===r?100:r,r=t.cols,n=void 0===r?100:r,o=t.gap,r=t.valueDataIndex,a=void 0===r?"value":r,s=t.render,c=t.data,r=useMemo(function(){return{display:"grid",gridTemplateColumns:"repeat(".concat(n,", 1fr)"),gridTemplateRows:"repeat(".concat(i,", 1fr)"),gap:o}},[i,n,o]),t=useMemo(function(){var t=new TreemapManager;return t.init(i,n,c,a),t.cards},[i,n,c,a]);return React.createElement("div",{style:r,className:e},t.map(function(t,e){var r=t.rect,t=t.record,i=r.left,n=r.top,o=r.width,r=r.height,a={gridColumn:"".concat(i+1," / ").concat(o+1),gridRow:"".concat(n+1," / ").concat(r+1)};return s(a,t,e,{left:i,top:n,width:o,height:r,rootRate:0,rootSquare:0})}))},StyleUtil={parse:function(t){t=__assign({},t);return t.fontSize&&(t.fontSize=NumberUtil.toFloat(t.fontSize)),t.opacity&&(t.opacity=NumberUtil.toFloat(t.opacity)),t}};export{GridRectUtil,I2Number,StyleUtil,TagCloud,Treemap,TreemapManager};

@@ -1,1 +0,1 @@

"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React),emphasizer=require("emphasizer"),__assign=function(){return(__assign=Object.assign||function(t){for(var e,r=1,a=arguments.length;r<a;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},NumberUtil=function(){function c(){}return c.toFloat=function(t){var e;return"string"==typeof t?t===(e=parseFloat(t)).toString()?e:void 0:t},c.splitNumber=function(t,e){var r=[];if(void 0!==t){var a=e.decimalDigits,i=e.groupSeparator,n=void 0===i?",":i,i=e.decimalSeparator,e=e.groupDigits,t=t.toFixed(a||0).split(".");if(0<t.length){for(var o=c.toGroups(t[0],e),s=0;s<o.length;s++)r.push({text:o[s],separator:!(0<s)||void 0===n?void 0:n});2!==t.length||(a=t[1])&&r.push({text:a,isFraction:!0,separator:i||"."})}}return r},c.toGroups=function(t,e){return 0===e?[t]:(e=Math.abs(e||3),t.match(new RegExp("(\\d+?)(?=(\\d{".concat(e,"})+(?!\\d)|$)"),"g"))||[])},c}(),rootStyle={display:"inline-block"},defaultContentStyle={display:"flex",flexDirection:"row",alignItems:"flex-end"},numberPartStyle={lineHeight:"1em"},I2Number=function(t){var e=t.fromStyle,r=t.toStyle,a=t.decimalDigits,i=t.verticalAlign,n=t.className,o=t.style,s=t.groupSeparator,c=t.decimalSeparator,u=t.groupDigits,l=t.value,d=t.basicMaxValue,f=t.children,h=React.useMemo(function(){return{decimalDigits:a,decimalSeparator:c,groupSeparator:s,groupDigits:u}},[a,c,s,u]),p=React.useMemo(function(){return NumberUtil.splitNumber(NumberUtil.toFloat(f||l),h)},[f,l,h]),g=React.useMemo(function(){return NumberUtil.splitNumber(NumberUtil.toFloat(d),h)},[d,h]),m=React.useMemo(function(){return __assign({fontSize:"1em"},e)},[e]),_=React.useMemo(function(){return __assign({fontSize:"2em"},r)},[r]),t=React.useMemo(function(){var t=__assign({},defaultContentStyle);return"top"===i?t.alignItems="flex-start":"center"===i&&(t.alignItems="center"),t},[i]);return React__default.createElement("div",{className:n,style:__assign(__assign({},rootStyle),o)},React__default.createElement("div",{style:t},p.map(function(t,e){var r=t.text,t=t.separator,a=g.length;return React__default.createElement("div",{key:e,style:__assign(__assign({},emphasizer.emphasizeStyle(m,_,1,a,p.length-e)),numberPartStyle)},"".concat(t||"").concat(r))})))},TagUtil=function(){function t(){}return t.order=function(t,e,r){var a,i,n;return"desc"===e||"middle"===e?(i=t.sort(function(t,e){return r(t)>r(e)?-1:r(t)<r(e)?1:0}),"middle"===e&&(a=[],i.forEach(function(t,e){e%2==0?a.push(t):a.unshift(t)}),i=a),i):"asc"===e||"edge"===e?(i=t.sort(function(t,e){return r(t)<r(e)?-1:r(t)>r(e)?1:0}),"edge"===e&&(n=[],i.forEach(function(t,e){e%2==0?n.push(t):n.unshift(t)}),i=n),i):t},t}(),TagCloud=function(t){var e=t.data,a=t.fromStyle,i=t.toStyle,r=t.order,n=void 0===r?"middle":r,r=t.className,o=t.style,s=t.render,t=t.valueDataIndex,c=void 0===t?"value":t,u=React.useCallback(function(t){return NumberUtil.toFloat(t[c])||0},[c]),t=React.useMemo(function(){var t=e.map(function(t){return u(t)});return[Math.min.apply(Math,t),Math.max.apply(Math,t)]},[e,u]),l=t[0],d=t[1],t=React.useMemo(function(){return TagUtil.order(e,n,u)},[e,n,u]),f=React.useMemo(function(){return __assign({display:"flex",flexWrap:"wrap",justifyItems:"center",alignItems:"center",justifyContent:"center",alignContent:"center"},o)},[o]);return React__default.createElement("div",{className:r,style:f},t.map(function(t,e){var r=emphasizer.emphasizeStyle(a,i,l,d,t.rate);return React__default.createElement(React__default.Fragment,{key:e},s?s(r,t,e):React__default.createElement("div",{style:r},t.text))}))},GridRectUtil=function(){function t(){}return t.rect=function(t,e,r,a){return{left:t,top:e,width:r,height:a}},t.split=function(t,e,r){var a=t.width-t.left,i=t.height-t.top,n=a<=i,e=Math.floor(e/(e+r)*(n?i:a));return n?(r=t.top+e,[__assign(__assign({},t),{height:r}),__assign(__assign({},t),{top:r})]):(i=t.left+e,[__assign(__assign({},t),{width:i}),__assign(__assign({},t),{left:i})])},t.square=function(t){return(t.width-t.left)*(t.height-t.top)},t}(),SPLIT_RATIO=.5,TreemapManager=function(){function t(){this._count=0,this._data=[],this._cols=0,this._rows=0,this._cards=[],this._valueDataIndex="",this.rootNode={rate:0,rootRate:0,rootSquare:0,rect:{top:0,left:0,width:100,height:100},record:void 0,children:[]}}return Object.defineProperty(t.prototype,"cards",{get:function(){return this._cards},enumerable:!1,configurable:!0}),t.prototype.init=function(t,e,r,a){void 0===a&&(a="rate"),this._count=0,this._cols=t,this._rows=e,this._data=r,this._valueDataIndex=a,this.refresh()},t.prototype.getRecordRate=function(t){t=t[this._valueDataIndex];if("number"==typeof t)return t;if("string"==typeof t){var e=parseFloat(t);if(e.toString()===t.toString())return e}return 0},t.prototype.refresh=function(){var r=this,t=this._data.map(function(t){return __assign({},t)}).sort(function(t,e){return r.getRecordRate(e)-r.getRecordRate(t)}),e={top:0,left:0,width:this._rows,height:this._cols},a=t.reduce(function(t,e){return t+r.getRecordRate(e)},0);this.rootNode=this.initNode(t,e,a,this._cols*this._rows),this._cards=[],this.initCard(this.rootNode,this._cards)},t.prototype.initNode=function(t,e,r,a){var i=this,n=(this._count++,t.reduce(function(t,e){return t+i.getRecordRate(e)},0)),o=[],s=void 0;if(1===t.length&&(s=t[0]),2===t.length){var c=t[0],u=t[1],l=GridRectUtil.split(e,this.getRecordRate(c),this.getRecordRate(u)),d=l[0],l=l[1];o.push({rate:this.getRecordRate(c),rootRate:r,rootSquare:a,rect:d,record:c,children:[]}),o.push({rate:this.getRecordRate(u),rootRate:r,rootSquare:a,rect:l,record:u,children:[]})}else if(2<t.length){for(var f=0,h=0,p=0,g=t;p<g.length;p++){var m=g[p];if(h++,f+=this.getRecordRate(m),n*SPLIT_RATIO<=f)break}c=GridRectUtil.split(e,f,n-f),d=c[0],l=c[1];o.push(this.initNode(t.slice(0,h),d,r,a)),o.push(this.initNode(t.slice(h),l,r,a))}return{rate:n,rootRate:r,rootSquare:a,rect:e,record:s,children:o}},t.prototype.initCard=function(t,e){var r=this;t.record&&e.push({record:t.record,rect:t.rect}),t.children.forEach(function(t){r.initCard(t,e)})},t}(),Treemap=function(t){var e=t.className,r=t.rows,a=void 0===r?100:r,r=t.cols,i=void 0===r?100:r,n=t.gap,r=t.valueDataIndex,o=void 0===r?"value":r,s=t.render,c=t.data,r=React.useMemo(function(){return{display:"grid",gridTemplateColumns:"repeat(".concat(i,", 1fr)"),gridTemplateRows:"repeat(".concat(a,", 1fr)"),gap:n}},[a,i,n]),t=React.useMemo(function(){var t=new TreemapManager;return t.init(a,i,c,o),t.cards},[a,i,c,o]);return React__default.createElement("div",{style:r,className:e},t.map(function(t,e){var r=t.rect,t=t.record,a=r.left,i=r.top,n=r.width,r=r.height,o={gridColumn:"".concat(a+1," / ").concat(n+1),gridRow:"".concat(i+1," / ").concat(r+1)};return s(o,t,e,{left:a,top:i,width:n,height:r,rootRate:0,rootSquare:0})}))};exports.I2Number=I2Number,exports.TagCloud=TagCloud,exports.Treemap=Treemap;
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React),emphasizer=require("emphasizer"),__assign=function(){return(__assign=Object.assign||function(t){for(var e,r=1,a=arguments.length;r<a;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},NumberUtil=function(){function c(){}return c.toFloat=function(t){var e;return"string"==typeof t?t===(e=parseFloat(t)).toString()?e:void 0:t},c.splitNumber=function(t,e){var r=[];if(void 0!==t){var a=e.decimalDigits,i=e.groupSeparator,n=void 0===i?",":i,i=e.decimalSeparator,e=e.groupDigits,t=t.toFixed(a||0).split(".");if(0<t.length){for(var o=c.toGroups(t[0],e),s=0;s<o.length;s++)r.push({text:o[s],separator:!(0<s)||void 0===n?void 0:n});2!==t.length||(a=t[1])&&r.push({text:a,isFraction:!0,separator:i||"."})}}return r},c.toGroups=function(t,e){return 0===e?[t]:(e=Math.abs(e||3),t.match(new RegExp("(\\d+?)(?=(\\d{".concat(e,"})+(?!\\d)|$)"),"g"))||[])},c}(),rootStyle={display:"inline-block"},defaultContentStyle={display:"flex",flexDirection:"row",alignItems:"flex-end"},numberPartStyle={lineHeight:"1em"},I2Number=function(t){var e=t.fromStyle,r=t.toStyle,a=t.decimalDigits,i=t.verticalAlign,n=t.className,o=t.style,s=t.groupSeparator,c=t.decimalSeparator,u=t.groupDigits,l=t.value,d=t.basicMaxValue,f=t.children,p=React.useMemo(function(){return{decimalDigits:a,decimalSeparator:c,groupSeparator:s,groupDigits:u}},[a,c,s,u]),h=React.useMemo(function(){return NumberUtil.splitNumber(NumberUtil.toFloat(f||l),p)},[f,l,p]),g=React.useMemo(function(){return NumberUtil.splitNumber(NumberUtil.toFloat(d),p)},[d,p]),m=React.useMemo(function(){return __assign({fontSize:"1em"},e)},[e]),_=React.useMemo(function(){return __assign({fontSize:"2em"},r)},[r]),t=React.useMemo(function(){var t=__assign({},defaultContentStyle);return"top"===i?t.alignItems="flex-start":"center"===i&&(t.alignItems="center"),t},[i]);return React__default.createElement("div",{className:n,style:__assign(__assign({},rootStyle),o)},React__default.createElement("div",{style:t},h.map(function(t,e){var r=t.text,t=t.separator,a=g.length;return React__default.createElement("div",{key:e,style:__assign(__assign({},emphasizer.emphasizeStyle(m,_,1,a,h.length-e)),numberPartStyle)},"".concat(t||"").concat(r))})))},TagUtil=function(){function t(){}return t.order=function(t,e,r){var a,i,n;return"desc"===e||"middle"===e?(i=t.sort(function(t,e){return r(t)>r(e)?-1:r(t)<r(e)?1:0}),"middle"===e&&(a=[],i.forEach(function(t,e){e%2==0?a.push(t):a.unshift(t)}),i=a),i):"asc"===e||"edge"===e?(i=t.sort(function(t,e){return r(t)<r(e)?-1:r(t)>r(e)?1:0}),"edge"===e&&(n=[],i.forEach(function(t,e){e%2==0?n.push(t):n.unshift(t)}),i=n),i):t},t}(),TagCloud=function(t){var e=t.data,a=t.fromStyle,i=t.toStyle,r=t.order,n=void 0===r?"middle":r,r=t.className,o=t.style,s=t.render,t=t.valueDataIndex,c=void 0===t?"value":t,u=React.useCallback(function(t){return NumberUtil.toFloat(t[c])||0},[c]),t=React.useMemo(function(){var t=e.map(function(t){return u(t)});return[Math.min.apply(Math,t),Math.max.apply(Math,t)]},[e,u]),l=t[0],d=t[1],t=React.useMemo(function(){return TagUtil.order(e,n,u)},[e,n,u]),f=React.useMemo(function(){return __assign({display:"flex",flexWrap:"wrap",justifyItems:"center",alignItems:"center",justifyContent:"center",alignContent:"center"},o)},[o]);return React__default.createElement("div",{className:r,style:f},t.map(function(t,e){var r=emphasizer.emphasizeStyle(a,i,l,d,t.rate);return React__default.createElement(React__default.Fragment,{key:e},s?s(r,t,e):React__default.createElement("div",{style:r},t.text))}))},GridRectUtil=function(){function t(){}return t.rect=function(t,e,r,a){return{left:t,top:e,width:r,height:a}},t.split=function(t,e,r){var a=t.width-t.left,i=t.height-t.top,n=a<=i,e=Math.floor(e/(e+r)*(n?i:a));return n?(r=t.top+e,[__assign(__assign({},t),{height:r}),__assign(__assign({},t),{top:r})]):(i=t.left+e,[__assign(__assign({},t),{width:i}),__assign(__assign({},t),{left:i})])},t.square=function(t){return(t.width-t.left)*(t.height-t.top)},t}(),SPLIT_RATIO=.5,TreemapManager=function(){function t(){this._count=0,this._data=[],this._cols=0,this._rows=0,this._cards=[],this._valueDataIndex="",this.rootNode={rate:0,rootRate:0,rootSquare:0,rect:{top:0,left:0,width:100,height:100},record:void 0,children:[]}}return Object.defineProperty(t.prototype,"cards",{get:function(){return this._cards},enumerable:!1,configurable:!0}),t.prototype.init=function(t,e,r,a){void 0===a&&(a="rate"),this._count=0,this._cols=t,this._rows=e,this._data=r,this._valueDataIndex=a,this.refresh()},t.prototype.getRecordRate=function(t){t=t[this._valueDataIndex];if("number"==typeof t)return t;if("string"==typeof t){var e=parseFloat(t);if(e.toString()===t.toString())return e}return 0},t.prototype.refresh=function(){var r=this,t=this._data.map(function(t){return __assign({},t)}).sort(function(t,e){return r.getRecordRate(e)-r.getRecordRate(t)}),e={top:0,left:0,width:this._rows,height:this._cols},a=t.reduce(function(t,e){return t+r.getRecordRate(e)},0);this.rootNode=this.initNode(t,e,a,this._cols*this._rows),this._cards=[],this.initCard(this.rootNode,this._cards)},t.prototype.initNode=function(t,e,r,a){var i=this,n=(this._count++,t.reduce(function(t,e){return t+i.getRecordRate(e)},0)),o=[],s=void 0;if(1===t.length&&(s=t[0]),2===t.length){var c=t[0],u=t[1],l=GridRectUtil.split(e,this.getRecordRate(c),this.getRecordRate(u)),d=l[0],l=l[1];o.push({rate:this.getRecordRate(c),rootRate:r,rootSquare:a,rect:d,record:c,children:[]}),o.push({rate:this.getRecordRate(u),rootRate:r,rootSquare:a,rect:l,record:u,children:[]})}else if(2<t.length){for(var f=0,p=0,h=0,g=t;h<g.length;h++){var m=g[h];if(p++,f+=this.getRecordRate(m),n*SPLIT_RATIO<=f)break}c=GridRectUtil.split(e,f,n-f),d=c[0],l=c[1];o.push(this.initNode(t.slice(0,p),d,r,a)),o.push(this.initNode(t.slice(p),l,r,a))}return{rate:n,rootRate:r,rootSquare:a,rect:e,record:s,children:o}},t.prototype.initCard=function(t,e){var r=this;t.record&&e.push({record:t.record,rect:t.rect}),t.children.forEach(function(t){r.initCard(t,e)})},t}(),Treemap=function(t){var e=t.className,r=t.rows,a=void 0===r?100:r,r=t.cols,i=void 0===r?100:r,n=t.gap,r=t.valueDataIndex,o=void 0===r?"value":r,s=t.render,c=t.data,r=React.useMemo(function(){return{display:"grid",gridTemplateColumns:"repeat(".concat(i,", 1fr)"),gridTemplateRows:"repeat(".concat(a,", 1fr)"),gap:n}},[a,i,n]),t=React.useMemo(function(){var t=new TreemapManager;return t.init(a,i,c,o),t.cards},[a,i,c,o]);return React__default.createElement("div",{style:r,className:e},t.map(function(t,e){var r=t.rect,t=t.record,a=r.left,i=r.top,n=r.width,r=r.height,o={gridColumn:"".concat(a+1," / ").concat(n+1),gridRow:"".concat(i+1," / ").concat(r+1)};return s(o,t,e,{left:a,top:i,width:n,height:r,rootRate:0,rootSquare:0})}))},StyleUtil={parse:function(t){t=__assign({},t);return t.fontSize&&(t.fontSize=NumberUtil.toFloat(t.fontSize)),t.opacity&&(t.opacity=NumberUtil.toFloat(t.opacity)),t}};exports.GridRectUtil=GridRectUtil,exports.I2Number=I2Number,exports.StyleUtil=StyleUtil,exports.TagCloud=TagCloud,exports.Treemap=Treemap,exports.TreemapManager=TreemapManager;
export * from "./i2-number";
export * from "./tag-cloud";
export * from "./treemap";
export * from "./treemap/utils";
{
"name": "i2ui",
"version": "2.0.0-alfa.1",
"version": "2.0.0-alfa.2",
"description": "i2ui - Intuitively Understantable User Interface",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc