squarified 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  `squarified` is a minimal and powerful treemap component.
4
4
 
5
- https://github.com/user-attachments/assets/caf30d9d-0a5a-446a-b767-7927bf4387c9
6
-
7
5
  ## Install
8
6
 
9
7
  ```shell
@@ -18,6 +16,10 @@ nonzzz.github.io/squarified/
18
16
 
19
17
  Kanno
20
18
 
19
+ ### Credits
20
+
21
+ Algorithm is ported from [esbuild Bundle Size Analyzer](https://esbuild.github.io/analyze/) by [Evan Wallace](https://github.com/evanw). Refactor algorithm to adjusted the layout.
22
+
21
23
  ### LICENSE
22
24
 
23
25
  [MIT](./LICENSE)
@@ -1,3 +1,10 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ type Any = any
3
+
4
+ type AnyObject = Record<keyof Any, Any>
5
+
6
+ type NonNull = NonNullable<unknown>
7
+
1
8
  interface MatrixLoc {
2
9
  a: number;
3
10
  b: number;
@@ -507,6 +514,7 @@ declare function createTreemap<const P extends readonly Plugin[]>(options?: Crea
507
514
  } & {
508
515
  off: () => (evt: string, handler?: ((this: unknown, ...args: any[]) => any) | undefined) => void;
509
516
  } & Record<string, never>) & BasicTreemapInstance & ExposedEventMethods & PluginMixins<P>;
517
+ type TreemapInstance<P extends readonly Plugin[]> = BasicTreemapInstance & ExposedEventMethods & PluginMixins<P>;
510
518
 
511
- export { isScrollWheelOrRightButtonOnMouseupAndDown as $, noop as A, createRoundBlock as F, createTitleText as H, raf as I, createCanvasElement as J, applyCanvasTransform as K, mixin as Q, mixinWithParams as U, prettyStrJoin as V, isMacOS as W, typedForIn as X, stackMatrixTransform as Y, stackMatrixTransformWithGraphAndLayer as Z, smoothFrame as _, DefaultMap as a0, DOMEvent as b, createTreemap as d, c2m as e, findRelativeNode as f, findRelativeNodeById as g, flatten as h, getNodeDepth as i, definePlugin as l, isClickEvent as p, isContextMenuEvent as q, isMouseEvent as r, sortChildrenByKey as s, isWheelEvent as t, visit as v, hashCode as y, perferNumeric as z };
512
- export type { BasicTreemapInstance as B, ColorMappings as C, DOMEventType as D, ExposedEventCallback as E, GraphicLayout as G, LayoutModule as L, Module as M, NativeModule as N, InheritedCollections as O, PluginContext as P, InheritedCollectionsWithParamter as R, Series as S, TreemapOptions as T, DOMEventMetadata as a, CreateTreemapOptions as c, Plugin as j, PluginHooks as k, ExposedEventDefinition as m, ExposedEventMethods as n, PrimitiveEventMetadata as o, GraphicFont as u, GraphicConfig as w, TreemapInstanceAPI as x };
519
+ export { smoothFrame as $, perferNumeric as A, noop as F, createRoundBlock as H, createTitleText as I, raf as J, createCanvasElement as K, applyCanvasTransform as O, mixin as R, mixinWithParams as V, prettyStrJoin as W, isMacOS as X, typedForIn as Y, stackMatrixTransform as Z, stackMatrixTransformWithGraphAndLayer as _, isScrollWheelOrRightButtonOnMouseupAndDown as a0, DefaultMap as a1, DOMEvent as b, createTreemap as d, c2m as f, findRelativeNode as g, findRelativeNodeById as h, flatten as i, getNodeDepth as j, definePlugin as m, isClickEvent as q, isContextMenuEvent as r, sortChildrenByKey as s, isMouseEvent as t, isWheelEvent as u, visit as v, hashCode as z };
520
+ export type { BasicTreemapInstance as B, ColorMappings as C, DOMEventType as D, ExposedEventCallback as E, GraphicLayout as G, LayoutModule as L, Module as M, NativeModule as N, PluginContext as P, InheritedCollections as Q, Series as S, TreemapOptions as T, InheritedCollectionsWithParamter as U, DOMEventMetadata as a, CreateTreemapOptions as c, TreemapInstance as e, Plugin as k, PluginHooks as l, ExposedEventDefinition as n, ExposedEventMethods as o, PrimitiveEventMetadata as p, GraphicFont as w, GraphicConfig as x, TreemapInstanceAPI as y };
package/dist/index.d.mts CHANGED
@@ -1 +1 @@
1
- export { B as BasicTreemapInstance, c as CreateTreemapOptions, D as DOMEventType, a0 as DefaultMap, E as ExposedEventCallback, m as ExposedEventDefinition, n as ExposedEventMethods, w as GraphicConfig, u as GraphicFont, G as GraphicLayout, O as InheritedCollections, R as InheritedCollectionsWithParamter, L as LayoutModule, M as Module, N as NativeModule, j as Plugin, P as PluginContext, k as PluginHooks, o as PrimitiveEventMetadata, S as Series, x as TreemapInstanceAPI, T as TreemapOptions, K as applyCanvasTransform, e as c2m, J as createCanvasElement, F as createRoundBlock, H as createTitleText, d as createTreemap, l as definePlugin, f as findRelativeNode, g as findRelativeNodeById, h as flattenModule, i as getNodeDepth, y as hashCode, p as isClickEvent, q as isContextMenuEvent, W as isMacOS, r as isMouseEvent, $ as isScrollWheelOrRightButtonOnMouseupAndDown, t as isWheelEvent, Q as mixin, U as mixinWithParams, A as noop, z as perferNumeric, V as prettyStrJoin, I as raf, _ as smoothFrame, s as sortChildrenByKey, Y as stackMatrixTransform, Z as stackMatrixTransformWithGraphAndLayer, X as typedForIn, v as visit } from './index-DcZTC3Az.js';
1
+ export { B as BasicTreemapInstance, c as CreateTreemapOptions, D as DOMEventType, a1 as DefaultMap, E as ExposedEventCallback, n as ExposedEventDefinition, o as ExposedEventMethods, x as GraphicConfig, w as GraphicFont, G as GraphicLayout, Q as InheritedCollections, U as InheritedCollectionsWithParamter, L as LayoutModule, M as Module, N as NativeModule, k as Plugin, P as PluginContext, l as PluginHooks, p as PrimitiveEventMetadata, S as Series, e as TreemapInstance, y as TreemapInstanceAPI, T as TreemapOptions, O as applyCanvasTransform, f as c2m, K as createCanvasElement, H as createRoundBlock, I as createTitleText, d as createTreemap, m as definePlugin, g as findRelativeNode, h as findRelativeNodeById, i as flattenModule, j as getNodeDepth, z as hashCode, q as isClickEvent, r as isContextMenuEvent, X as isMacOS, t as isMouseEvent, a0 as isScrollWheelOrRightButtonOnMouseupAndDown, u as isWheelEvent, R as mixin, V as mixinWithParams, F as noop, A as perferNumeric, W as prettyStrJoin, J as raf, $ as smoothFrame, s as sortChildrenByKey, Z as stackMatrixTransform, _ as stackMatrixTransformWithGraphAndLayer, Y as typedForIn, v as visit } from './index-BoUEaWVv.js';
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { B as BasicTreemapInstance, c as CreateTreemapOptions, D as DOMEventType, a0 as DefaultMap, E as ExposedEventCallback, m as ExposedEventDefinition, n as ExposedEventMethods, w as GraphicConfig, u as GraphicFont, G as GraphicLayout, O as InheritedCollections, R as InheritedCollectionsWithParamter, L as LayoutModule, M as Module, N as NativeModule, j as Plugin, P as PluginContext, k as PluginHooks, o as PrimitiveEventMetadata, S as Series, x as TreemapInstanceAPI, T as TreemapOptions, K as applyCanvasTransform, e as c2m, J as createCanvasElement, F as createRoundBlock, H as createTitleText, d as createTreemap, l as definePlugin, f as findRelativeNode, g as findRelativeNodeById, h as flattenModule, i as getNodeDepth, y as hashCode, p as isClickEvent, q as isContextMenuEvent, W as isMacOS, r as isMouseEvent, $ as isScrollWheelOrRightButtonOnMouseupAndDown, t as isWheelEvent, Q as mixin, U as mixinWithParams, A as noop, z as perferNumeric, V as prettyStrJoin, I as raf, _ as smoothFrame, s as sortChildrenByKey, Y as stackMatrixTransform, Z as stackMatrixTransformWithGraphAndLayer, X as typedForIn, v as visit } from './index-DcZTC3Az.js';
1
+ export { B as BasicTreemapInstance, c as CreateTreemapOptions, D as DOMEventType, a1 as DefaultMap, E as ExposedEventCallback, n as ExposedEventDefinition, o as ExposedEventMethods, x as GraphicConfig, w as GraphicFont, G as GraphicLayout, Q as InheritedCollections, U as InheritedCollectionsWithParamter, L as LayoutModule, M as Module, N as NativeModule, k as Plugin, P as PluginContext, l as PluginHooks, p as PrimitiveEventMetadata, S as Series, e as TreemapInstance, y as TreemapInstanceAPI, T as TreemapOptions, O as applyCanvasTransform, f as c2m, K as createCanvasElement, H as createRoundBlock, I as createTitleText, d as createTreemap, m as definePlugin, g as findRelativeNode, h as findRelativeNodeById, i as flattenModule, j as getNodeDepth, z as hashCode, q as isClickEvent, r as isContextMenuEvent, X as isMacOS, t as isMouseEvent, a0 as isScrollWheelOrRightButtonOnMouseupAndDown, u as isWheelEvent, R as mixin, V as mixinWithParams, F as noop, A as perferNumeric, W as prettyStrJoin, J as raf, $ as smoothFrame, s as sortChildrenByKey, Z as stackMatrixTransform, _ as stackMatrixTransformWithGraphAndLayer, Y as typedForIn, v as visit } from './index-BoUEaWVv.js';
package/dist/plugin.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { P as PluginContext, D as DOMEventType, a as DOMEventMetadata, L as LayoutModule, b as DOMEvent, C as ColorMappings, B as BasicTreemapInstance } from './index-DcZTC3Az.js';
1
+ import { P as PluginContext, D as DOMEventType, a as DOMEventMetadata, L as LayoutModule, b as DOMEvent, C as ColorMappings, B as BasicTreemapInstance } from './index-BoUEaWVv.js';
2
2
 
3
3
  declare const presetHighlightPlugin: {
4
4
  name: "treemap:preset-highlight";
@@ -25,6 +25,21 @@ declare const presetDragElementPlugin: {
25
25
  onResize(this: PluginContext, { matrix, stateManager: state }: DOMEvent): void;
26
26
  };
27
27
 
28
+ interface MenuRenderConfig {
29
+ html: string;
30
+ action: string;
31
+ }
32
+ interface MenuPluginOptions {
33
+ style?: Partial<CSSStyleDeclaration>;
34
+ render?: (menu: HTMLDivElement) => MenuRenderConfig[];
35
+ onClick?: (action: string, module: LayoutModule | null) => void;
36
+ }
37
+ declare function presetMenuPlugin(options?: MenuPluginOptions): {
38
+ name: "treemap:preset-menu";
39
+ onDOMEventTriggered<N extends DOMEventType>(this: PluginContext, _: N, event: DOMEventMetadata<N>, __: LayoutModule | null, DOMEvent: DOMEvent): void;
40
+ onDispose(this: PluginContext): void;
41
+ };
42
+
28
43
  declare const presetColorPlugin: {
29
44
  name: "treemap:preset-color";
30
45
  onModuleInit(this: PluginContext, modules: LayoutModule[]): {
@@ -75,4 +90,4 @@ declare const presetZoomablePlugin: {
75
90
  meta: ZoomableMetadata;
76
91
  };
77
92
 
78
- export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetScalePlugin, presetZoomablePlugin };
93
+ export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetMenuPlugin, presetScalePlugin, presetZoomablePlugin };
package/dist/plugin.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { P as PluginContext, D as DOMEventType, a as DOMEventMetadata, L as LayoutModule, b as DOMEvent, C as ColorMappings, B as BasicTreemapInstance } from './index-DcZTC3Az.js';
1
+ import { P as PluginContext, D as DOMEventType, a as DOMEventMetadata, L as LayoutModule, b as DOMEvent, C as ColorMappings, B as BasicTreemapInstance } from './index-BoUEaWVv.js';
2
2
 
3
3
  declare const presetHighlightPlugin: {
4
4
  name: "treemap:preset-highlight";
@@ -25,6 +25,21 @@ declare const presetDragElementPlugin: {
25
25
  onResize(this: PluginContext, { matrix, stateManager: state }: DOMEvent): void;
26
26
  };
27
27
 
28
+ interface MenuRenderConfig {
29
+ html: string;
30
+ action: string;
31
+ }
32
+ interface MenuPluginOptions {
33
+ style?: Partial<CSSStyleDeclaration>;
34
+ render?: (menu: HTMLDivElement) => MenuRenderConfig[];
35
+ onClick?: (action: string, module: LayoutModule | null) => void;
36
+ }
37
+ declare function presetMenuPlugin(options?: MenuPluginOptions): {
38
+ name: "treemap:preset-menu";
39
+ onDOMEventTriggered<N extends DOMEventType>(this: PluginContext, _: N, event: DOMEventMetadata<N>, __: LayoutModule | null, DOMEvent: DOMEvent): void;
40
+ onDispose(this: PluginContext): void;
41
+ };
42
+
28
43
  declare const presetColorPlugin: {
29
44
  name: "treemap:preset-color";
30
45
  onModuleInit(this: PluginContext, modules: LayoutModule[]): {
@@ -75,4 +90,4 @@ declare const presetZoomablePlugin: {
75
90
  meta: ZoomableMetadata;
76
91
  };
77
92
 
78
- export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetScalePlugin, presetZoomablePlugin };
93
+ export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetMenuPlugin, presetScalePlugin, presetZoomablePlugin };
package/dist/plugin.js CHANGED
@@ -241,6 +241,72 @@ function getDragOptions() {
241
241
  return meta;
242
242
  }
243
243
 
244
+ function presetMenuPlugin(options) {
245
+ let menu = null;
246
+ let domEvent$1 = null;
247
+ const handleMenuClick = (e)=>{
248
+ if (!domEvent$1) {
249
+ return;
250
+ }
251
+ if (!menu) {
252
+ return;
253
+ }
254
+ const target = e.target;
255
+ if (target.parentNode) {
256
+ const parent = target.parentNode;
257
+ const action = parent.getAttribute('data-action');
258
+ if (!action) {
259
+ return;
260
+ }
261
+ if (options?.onClick) {
262
+ options.onClick(action, domEvent$1.findRelativeNode({
263
+ native: e,
264
+ kind: undefined
265
+ }));
266
+ }
267
+ }
268
+ menu.style.display = 'none';
269
+ };
270
+ return domEvent.definePlugin({
271
+ name: 'treemap:preset-menu',
272
+ onDOMEventTriggered (_, event, __, DOMEvent) {
273
+ if (domEvent.isContextMenuEvent(event)) {
274
+ event.native.stopPropagation();
275
+ event.native.preventDefault();
276
+ if (!menu) {
277
+ menu = document.createElement('div');
278
+ domEvent$1 = DOMEvent;
279
+ Object.assign(menu.style, {
280
+ backgroundColor: '#fff',
281
+ ...options?.style,
282
+ position: 'absolute',
283
+ zIndex: '9999'
284
+ });
285
+ menu.addEventListener('click', handleMenuClick);
286
+ if (menu && options?.render) {
287
+ const result = options.render(menu);
288
+ menu.innerHTML = result.map((item)=>{
289
+ return `<div data-action='${item.action}'>${item.html}</div>`;
290
+ }).join('');
291
+ }
292
+ document.body.append(menu);
293
+ }
294
+ menu.style.left = event.native.clientX + 'px';
295
+ menu.style.top = event.native.clientY + 'px';
296
+ menu.style.display = 'initial';
297
+ }
298
+ },
299
+ onDispose () {
300
+ if (!menu) {
301
+ return;
302
+ }
303
+ menu.removeEventListener('click', handleMenuClick);
304
+ menu = null;
305
+ domEvent$1 = null;
306
+ }
307
+ });
308
+ }
309
+
244
310
  const presetColorPlugin = domEvent.definePlugin({
245
311
  name: 'treemap:preset-color',
246
312
  onModuleInit (modules) {
@@ -334,7 +400,8 @@ function onWheel(pluginContext, event, { stateManager: state, component, matrix
334
400
  return;
335
401
  }
336
402
  const { scale, minScale, maxScale, scaleFactor } = meta.scaleOptions;
337
- const delta = event.native.deltaY < 0 ? scaleFactor : -scaleFactor;
403
+ const dynamicScaleFactor = Math.max(scaleFactor, scale * 0.1);
404
+ const delta = event.native.deltaY < 0 ? dynamicScaleFactor : -dynamicScaleFactor;
338
405
  const newScale = Math.max(minScale, Math.min(maxScale, scale + delta));
339
406
  if (newScale === scale) {
340
407
  return;
@@ -474,5 +541,6 @@ const presetZoomablePlugin = domEvent.definePlugin({
474
541
  exports.presetColorPlugin = presetColorPlugin;
475
542
  exports.presetDragElementPlugin = presetDragElementPlugin;
476
543
  exports.presetHighlightPlugin = presetHighlightPlugin;
544
+ exports.presetMenuPlugin = presetMenuPlugin;
477
545
  exports.presetScalePlugin = presetScalePlugin;
478
546
  exports.presetZoomablePlugin = presetZoomablePlugin;
package/dist/plugin.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { h as definePlugin, H as smoothFrame, r as createRoundBlock, F as stackMatrixTransform, S as Schedule, K as DEFAULT_MATRIX_LOC, I as isScrollWheelOrRightButtonOnMouseupAndDown, G as stackMatrixTransformWithGraphAndLayer, p as hashCode, P as PI_2, o as isWheelEvent, y as mixinWithParams } from './dom-event-BLJt9knO.mjs';
1
+ import { h as definePlugin, H as smoothFrame, r as createRoundBlock, F as stackMatrixTransform, S as Schedule, K as DEFAULT_MATRIX_LOC, I as isScrollWheelOrRightButtonOnMouseupAndDown, G as stackMatrixTransformWithGraphAndLayer, j as isContextMenuEvent, p as hashCode, P as PI_2, o as isWheelEvent, y as mixinWithParams } from './dom-event-BLJt9knO.mjs';
2
2
 
3
3
  // Currently, etoile is an internal module, so we won't need too much easing functions.
4
4
  // And the animation logic is implemented by user code.
@@ -239,6 +239,72 @@ function getDragOptions() {
239
239
  return meta;
240
240
  }
241
241
 
242
+ function presetMenuPlugin(options) {
243
+ let menu = null;
244
+ let domEvent = null;
245
+ const handleMenuClick = (e)=>{
246
+ if (!domEvent) {
247
+ return;
248
+ }
249
+ if (!menu) {
250
+ return;
251
+ }
252
+ const target = e.target;
253
+ if (target.parentNode) {
254
+ const parent = target.parentNode;
255
+ const action = parent.getAttribute('data-action');
256
+ if (!action) {
257
+ return;
258
+ }
259
+ if (options?.onClick) {
260
+ options.onClick(action, domEvent.findRelativeNode({
261
+ native: e,
262
+ kind: undefined
263
+ }));
264
+ }
265
+ }
266
+ menu.style.display = 'none';
267
+ };
268
+ return definePlugin({
269
+ name: 'treemap:preset-menu',
270
+ onDOMEventTriggered (_, event, __, DOMEvent) {
271
+ if (isContextMenuEvent(event)) {
272
+ event.native.stopPropagation();
273
+ event.native.preventDefault();
274
+ if (!menu) {
275
+ menu = document.createElement('div');
276
+ domEvent = DOMEvent;
277
+ Object.assign(menu.style, {
278
+ backgroundColor: '#fff',
279
+ ...options?.style,
280
+ position: 'absolute',
281
+ zIndex: '9999'
282
+ });
283
+ menu.addEventListener('click', handleMenuClick);
284
+ if (menu && options?.render) {
285
+ const result = options.render(menu);
286
+ menu.innerHTML = result.map((item)=>{
287
+ return `<div data-action='${item.action}'>${item.html}</div>`;
288
+ }).join('');
289
+ }
290
+ document.body.append(menu);
291
+ }
292
+ menu.style.left = event.native.clientX + 'px';
293
+ menu.style.top = event.native.clientY + 'px';
294
+ menu.style.display = 'initial';
295
+ }
296
+ },
297
+ onDispose () {
298
+ if (!menu) {
299
+ return;
300
+ }
301
+ menu.removeEventListener('click', handleMenuClick);
302
+ menu = null;
303
+ domEvent = null;
304
+ }
305
+ });
306
+ }
307
+
242
308
  const presetColorPlugin = definePlugin({
243
309
  name: 'treemap:preset-color',
244
310
  onModuleInit (modules) {
@@ -332,7 +398,8 @@ function onWheel(pluginContext, event, { stateManager: state, component, matrix
332
398
  return;
333
399
  }
334
400
  const { scale, minScale, maxScale, scaleFactor } = meta.scaleOptions;
335
- const delta = event.native.deltaY < 0 ? scaleFactor : -scaleFactor;
401
+ const dynamicScaleFactor = Math.max(scaleFactor, scale * 0.1);
402
+ const delta = event.native.deltaY < 0 ? dynamicScaleFactor : -dynamicScaleFactor;
336
403
  const newScale = Math.max(minScale, Math.min(maxScale, scale + delta));
337
404
  if (newScale === scale) {
338
405
  return;
@@ -469,4 +536,4 @@ const presetZoomablePlugin = definePlugin({
469
536
  }
470
537
  });
471
538
 
472
- export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetScalePlugin, presetZoomablePlugin };
539
+ export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetMenuPlugin, presetScalePlugin, presetZoomablePlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squarified",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "squarified tree map",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -34,7 +34,6 @@
34
34
  "author": "Kanno",
35
35
  "license": "MIT",
36
36
  "devDependencies": {
37
- "@microsoft/api-extractor": "^7.52.3",
38
37
  "@swc/core": "^1.11.29",
39
38
  "@types/markdown-it": "^14.1.2",
40
39
  "@types/node": "^22.7.4",
@@ -57,7 +56,7 @@
57
56
  "tinyglobby": "^0.2.13",
58
57
  "tsx": "^4.19.2",
59
58
  "typescript": "^5.7.3",
60
- "vite-bundle-analyzer": "^0.21.0"
59
+ "vite-bundle-analyzer": "^0.22.0"
61
60
  },
62
61
  "pnpm": {
63
62
  "overrides": {