Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

i2ui

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i2ui - npm Package Compare versions

Comparing version 2.0.0-alfa.3 to 2.0.0-alfa.4

2

dist/i2-number/index.d.ts
import React from "react";
export declare type I2NumberVerticalAlign = "top" | "center" | "bottom";
export type I2NumberVerticalAlign = "top" | "center" | "bottom";
export interface I2NumberProps {

@@ -4,0 +4,0 @@ fromStyle?: React.CSSProperties;

@@ -0,0 +0,0 @@ export * from "./i2-number";

@@ -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,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};
import React,{useMemo,useCallback,useEffect}from"react";import{emphasizeStyle}from"emphasizer";var __assign=function(){return(__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;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 u(){}return u.toFloat=function(t){var e;return"string"==typeof t?t===(e=parseFloat(t)).toString()?e:void 0:t},u.splitNumber=function(t,e){var r=[];if(void 0!==t){var n=e.decimalDigits,i=e.groupSeparator,a=void 0===i?",":i,i=e.decimalSeparator,e=e.groupDigits,t=t.toFixed(n||0).split(".");if(0<t.length){for(var o=u.toGroups(t[0],e),s=0;s<o.length;s++)r.push({text:o[s],separator:!(0<s)||void 0===a?void 0:a});2===t.length&&(n=t[1])&&r.push({text:n,isFraction:!0,separator:i||"."})}}return r},u.toGroups=function(t,e){return 0===e?[t]:(e=Math.abs(e||3),t.match(new RegExp("(\\d+?)(?=(\\d{".concat(e,"})+(?!\\d)|$)"),"g"))||[])},u}(),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,n=t.decimalDigits,i=t.verticalAlign,a=t.className,o=t.style,s=t.groupSeparator,u=t.decimalSeparator,c=t.groupDigits,l=t.value,d=t.basicMaxValue,f=t.children,h=useMemo(function(){return{decimalDigits:n,decimalSeparator:u,groupSeparator:s,groupDigits:c}},[n,u,s,c]),p=useMemo(function(){return NumberUtil.splitNumber(NumberUtil.toFloat(f||l),h)},[f,l,h]),_=useMemo(function(){return NumberUtil.splitNumber(NumberUtil.toFloat(d),h)},[d,h]),g=useMemo(function(){return __assign({fontSize:"1em"},e)},[e]),m=useMemo(function(){return __assign({fontSize:"2em"},r)},[r]),t=useMemo(function(){var t=__assign({},defaultContentStyle);return"top"===i?t.alignItems="flex-start":"center"===i&&(t.alignItems="center"),t},[i]);return React.createElement("div",{className:a,style:__assign(__assign({},rootStyle),o)},React.createElement("div",{style:t},p.map(function(t,e){var r=t.text,t=t.separator,n=_.length;return React.createElement("div",{key:e,style:__assign(__assign({},emphasizeStyle(g,m,1,n,p.length-e)),numberPartStyle)},"".concat(t||"").concat(r))})))},TagUtil=function(){function t(){}return t.order=function(t,e,r){var n,i,a;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&&(n=[],i.forEach(function(t,e){e%2==0?n.push(t):n.unshift(t)}),i=n),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&&(a=[],i.forEach(function(t,e){e%2==0?a.push(t):a.unshift(t)}),i=a),i):t},t}(),TagCloud=function(t){var e=t.data,n=t.fromStyle,i=t.toStyle,r=t.order,a=void 0===r?"middle":r,r=t.className,o=t.style,s=t.render,t=t.dataValueKey,u=void 0===t?"value":t,c=useCallback(function(t){return NumberUtil.toFloat(t[u])||0},[u]),t=useMemo(function(){var t=e.map(function(t){return c(t)});return[Math.min.apply(Math,t),Math.max.apply(Math,t)]},[e,c]),l=t[0],d=t[1],t=useMemo(function(){return TagUtil.order(e,a,c)},[e,a,c]),f=useMemo(function(){return __assign({display:"flex",flexWrap:"wrap",justifyItems:"center",alignItems:"center",justifyContent:"center",alignContent:"center"},o)},[o]);return React.createElement("div",{className:r,style:f},t.map(function(t,e){var r=emphasizeStyle(n,i,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,n){return{left:t,top:e,width:r,height:n}},t.split=function(t,e,r){var n=t.width-t.left,i=t.height-t.top,a=n<=i,e=Math.floor(e/(e+r)*(a?i:n));return a?(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._baseRate=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,n,i){void 0===n&&(n="rate"),void 0===i&&(i=0),this._count=0,this._cols=t,this._rows=e,this._data=r,this._valueDataIndex=n,this._baseRate=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 e=this,t=this._data.map(function(t){return __assign(__assign({},t),{__rate:e.getRecordRate(t)+e._baseRate})}).filter(function(t){return 0<t.__rate}).sort(function(t,e){return e.__rate-t.__rate}),r={top:0,left:0,width:this._rows,height:this._cols},n=t.reduce(function(t,e){return t+e.__rate},0);this.rootNode=this.initNode(t,r,n,this._cols*this._rows),this._cards=[],this.initCard(this.rootNode,this._cards)},t.prototype.initNode=function(t,e,r,n){this._count++;var i=t.reduce(function(t,e){return t+e.__rate},0),a=[],o=void 0;if(1===t.length&&(o=t[0]),2===t.length){var s=t[0],u=t[1],c=GridRectUtil.split(e,s.__rate,u.__rate),l=c[0],c=c[1];a.push({rate:s.__rate,rootRate:r,rootSquare:n,rect:l,record:s,children:[]}),a.push({rate:u.__rate,rootRate:r,rootSquare:n,rect:c,record:u,children:[]})}else if(2<t.length){for(var d=0,f=0,h=0,p=t;h<p.length;h++)if(f++,d+=p[h].__rate,i*SPLIT_RATIO<=d)break;s=GridRectUtil.split(e,d,i-d),l=s[0],c=s[1];a.push(this.initNode(t.slice(0,f),l,r,n)),a.push(this.initNode(t.slice(f),c,r,n))}return{rate:i,rootRate:r,rootSquare:n,rect:e,record:o,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,n=void 0===r?100:r,r=t.cols,i=void 0===r?100:r,a=t.gap,r=t.dataValueKey,o=void 0===r?"value":r,s=t.render,u=t.data,c=t.baseRate,r=useMemo(function(){return{display:"grid",gridTemplateColumns:"repeat(".concat(i,", 1fr)"),gridTemplateRows:"repeat(".concat(n,", 1fr)"),gap:a}},[n,i,a]),t=useMemo(function(){var t=new TreemapManager;return t.init(n,i,u,o,c),t.cards},[n,i,u,o,c]);return useEffect(function(){console.info("TREEMAP",e,n,i,a,o,u.length,"baseRate",c)},[e,n,i,a,o,u,c]),React.createElement("div",{style:r,className:e},t.map(function(t,e){var r=t.rect,t=t.record,n=r.left,i=r.top,a=r.width,r=r.height,o={gridColumn:"".concat(n+1," / ").concat(a+1),gridRow:"".concat(i+1," / ").concat(r+1)};return s(o,t,e,{left:n,top:i,width:a,height:r,rootRate:0,rootSquare:0})}))};export{GridRectUtil,I2Number,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,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;
"use strict";var React=require("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]),_=React.useMemo(function(){return __assign({fontSize:"1em"},e)},[e]),m=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.createElement("div",{className:n,style:__assign(__assign({},rootStyle),o)},React.createElement("div",{style:t},p.map(function(t,e){var r=t.text,t=t.separator,a=g.length;return React.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.dataValueKey,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.createElement("div",{className:r,style:f},t.map(function(t,e){var r=emphasizer.emphasizeStyle(a,i,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,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._baseRate=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,i){void 0===a&&(a="rate"),void 0===i&&(i=0),this._count=0,this._cols=t,this._rows=e,this._data=r,this._valueDataIndex=a,this._baseRate=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 e=this,t=this._data.map(function(t){return __assign(__assign({},t),{__rate:e.getRecordRate(t)+e._baseRate})}).filter(function(t){return 0<t.__rate}).sort(function(t,e){return e.__rate-t.__rate}),r={top:0,left:0,width:this._rows,height:this._cols},a=t.reduce(function(t,e){return t+e.__rate},0);this.rootNode=this.initNode(t,r,a,this._cols*this._rows),this._cards=[],this.initCard(this.rootNode,this._cards)},t.prototype.initNode=function(t,e,r,a){this._count++;var i=t.reduce(function(t,e){return t+e.__rate},0),n=[],o=void 0;if(1===t.length&&(o=t[0]),2===t.length){var s=t[0],c=t[1],u=GridRectUtil.split(e,s.__rate,c.__rate),l=u[0],u=u[1];n.push({rate:s.__rate,rootRate:r,rootSquare:a,rect:l,record:s,children:[]}),n.push({rate:c.__rate,rootRate:r,rootSquare:a,rect:u,record:c,children:[]})}else if(2<t.length){for(var d=0,f=0,h=0,p=t;h<p.length;h++)if(f++,d+=p[h].__rate,i*SPLIT_RATIO<=d)break;s=GridRectUtil.split(e,d,i-d),l=s[0],u=s[1];n.push(this.initNode(t.slice(0,f),l,r,a)),n.push(this.initNode(t.slice(f),u,r,a))}return{rate:i,rootRate:r,rootSquare:a,rect:e,record:o,children:n}},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.dataValueKey,o=void 0===r?"value":r,s=t.render,c=t.data,u=t.baseRate,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,u),t.cards},[a,i,c,o,u]);return React.useEffect(function(){console.info("TREEMAP",e,a,i,n,o,c.length,"baseRate",u)},[e,a,i,n,o,c,u]),React.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.GridRectUtil=GridRectUtil,exports.I2Number=I2Number,exports.TagCloud=TagCloud,exports.Treemap=Treemap,exports.TreemapManager=TreemapManager;
import React from "react";
export declare type TagCloudOrder = "none" | "desc" | "middle" | "asc" | "edge";
export type TagCloudOrder = "none" | "desc" | "middle" | "asc" | "edge";
export interface TagCloudProps {

@@ -11,4 +11,4 @@ className?: string;

render?: (style: React.CSSProperties, record: any, index: number) => React.ReactElement;
valueDataIndex?: string;
dataValueKey?: string;
}
export declare const TagCloud: React.FC<TagCloudProps>;

@@ -8,4 +8,5 @@ import React from "react";

gap?: number;
valueDataIndex?: string;
dataValueKey?: string;
data: any[];
baseRate?: number;
render: (style: React.CSSProperties, record: any, index: number, rect: GridCellMeta) => React.ReactNode;

@@ -12,0 +13,0 @@ }

@@ -0,0 +0,0 @@ import { GridCardRect } from "./interface";

export * from "./grid-rect";
export * from "./interface";
export * from "./style";
export * from "./treemap-manager";

@@ -0,0 +0,0 @@ export interface GridCardInfo {

@@ -15,2 +15,3 @@ import { GridCardInfo, GridCardRect } from "./interface";

private _rows;
private _baseRate;
private _cards;

@@ -20,3 +21,3 @@ private _valueDataIndex;

get cards(): GridCardInfo[];
init(cols: number, rows: number, data: any[], valueDataIndex?: string): void;
init(cols: number, rows: number, data: any[], valueDataIndex?: string, baseRate?: number): void;
private getRecordRate;

@@ -23,0 +24,0 @@ refresh(): void;

export * from "./number-util";
export * from "./tag-util";

@@ -0,0 +0,0 @@ export interface SplitedNumberGroupProps {

@@ -0,0 +0,0 @@ import { TagCloudOrder } from "..";

{
"name": "i2ui",
"version": "2.0.0-alfa.3",
"version": "2.0.0-alfa.4",
"description": "i2ui - Intuitively Understantable User Interface",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"devDependencies": {
"@rollup/plugin-typescript": "^11.0.0",
"@types/jest": "^24.0.20",

@@ -32,5 +32,4 @@ "@types/react": "^17.0.37",

"react-dom": "^17.0.2",
"rollup": "^1.19.4",
"rollup": "^3.20.2",
"rollup-plugin-scss": "^1.0.2",
"rollup-plugin-typescript2": "^0.22.1",
"rollup-plugin-uglify": "^6.0.3",

@@ -52,4 +51,4 @@ "stylelint": "^14.11.0",

"scripts": {
"build": "rollup -c",
"build:dev": "cross-env BUILD=dev rollup -c",
"build": "rollup -c --bundleConfigAsCjs",
"build:dev": "cross-env BUILD=dev rollup -c --bundleConfigAsCjs",
"build-watch": "rollup -c -w",

@@ -56,0 +55,0 @@ "install-all": "npm i && cd example && npm i",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc