mtrl-addons 0.1.0 → 0.1.2

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.
Files changed (92) hide show
  1. package/.cursorrules +117 -0
  2. package/AI.md +241 -0
  3. package/build.js +148 -0
  4. package/bun.lock +792 -0
  5. package/index.ts +7 -0
  6. package/package.json +10 -17
  7. package/scripts/analyze-orphaned-functions.ts +387 -0
  8. package/src/components/index.ts +45 -0
  9. package/src/components/list/api.ts +314 -0
  10. package/src/components/list/config.ts +352 -0
  11. package/src/components/list/constants.ts +56 -0
  12. package/src/components/list/features/api.ts +428 -0
  13. package/src/components/list/features/index.ts +31 -0
  14. package/src/components/list/features/list-manager.ts +502 -0
  15. package/src/components/list/features.ts +112 -0
  16. package/src/components/list/index.ts +39 -0
  17. package/src/components/list/list.ts +234 -0
  18. package/src/components/list/types.ts +513 -0
  19. package/src/core/collection/base-collection.ts +100 -0
  20. package/src/core/collection/collection-composer.ts +178 -0
  21. package/src/core/collection/collection.ts +745 -0
  22. package/src/core/collection/constants.ts +172 -0
  23. package/src/core/collection/events.ts +428 -0
  24. package/src/core/collection/features/api/loading.ts +279 -0
  25. package/src/core/collection/features/operations/data-operations.ts +147 -0
  26. package/src/core/collection/index.ts +104 -0
  27. package/src/core/collection/state.ts +497 -0
  28. package/src/core/collection/types.ts +404 -0
  29. package/src/core/compose/features/collection.ts +119 -0
  30. package/src/core/compose/features/index.ts +39 -0
  31. package/src/core/compose/features/performance.ts +161 -0
  32. package/src/core/compose/features/selection.ts +213 -0
  33. package/src/core/compose/features/styling.ts +108 -0
  34. package/src/core/compose/index.ts +31 -0
  35. package/src/core/index.ts +167 -0
  36. package/src/core/layout/config.ts +102 -0
  37. package/src/core/layout/index.ts +168 -0
  38. package/src/core/layout/jsx.ts +174 -0
  39. package/src/core/layout/schema.ts +963 -0
  40. package/src/core/layout/types.ts +92 -0
  41. package/src/core/list-manager/api.ts +599 -0
  42. package/src/core/list-manager/config.ts +593 -0
  43. package/src/core/list-manager/constants.ts +268 -0
  44. package/src/core/list-manager/features/api.ts +58 -0
  45. package/src/core/list-manager/features/collection/collection.ts +705 -0
  46. package/src/core/list-manager/features/collection/index.ts +17 -0
  47. package/src/core/list-manager/features/viewport/constants.ts +42 -0
  48. package/src/core/list-manager/features/viewport/index.ts +16 -0
  49. package/src/core/list-manager/features/viewport/item-size.ts +274 -0
  50. package/src/core/list-manager/features/viewport/loading.ts +263 -0
  51. package/src/core/list-manager/features/viewport/placeholders.ts +281 -0
  52. package/src/core/list-manager/features/viewport/rendering.ts +575 -0
  53. package/src/core/list-manager/features/viewport/scrollbar.ts +495 -0
  54. package/src/core/list-manager/features/viewport/scrolling.ts +795 -0
  55. package/src/core/list-manager/features/viewport/template.ts +220 -0
  56. package/src/core/list-manager/features/viewport/viewport.ts +654 -0
  57. package/src/core/list-manager/features/viewport/virtual.ts +309 -0
  58. package/src/core/list-manager/index.ts +279 -0
  59. package/src/core/list-manager/list-manager.ts +206 -0
  60. package/src/core/list-manager/types.ts +439 -0
  61. package/src/core/list-manager/utils/calculations.ts +290 -0
  62. package/src/core/list-manager/utils/range-calculator.ts +349 -0
  63. package/src/core/list-manager/utils/speed-tracker.ts +273 -0
  64. package/src/index.ts +17 -0
  65. package/src/styles/components/_list.scss +244 -0
  66. package/src/styles/index.scss +12 -0
  67. package/src/types/mtrl.d.ts +6 -0
  68. package/test/benchmarks/layout/advanced.test.ts +656 -0
  69. package/test/benchmarks/layout/comparison.test.ts +519 -0
  70. package/test/benchmarks/layout/performance-comparison.test.ts +274 -0
  71. package/test/benchmarks/layout/real-components.test.ts +733 -0
  72. package/test/benchmarks/layout/simple.test.ts +321 -0
  73. package/test/benchmarks/layout/stress.test.ts +990 -0
  74. package/test/collection/basic.test.ts +304 -0
  75. package/test/components/list.test.ts +256 -0
  76. package/test/core/collection/collection.test.ts +394 -0
  77. package/test/core/collection/failed-ranges.test.ts +270 -0
  78. package/test/core/compose/features.test.ts +183 -0
  79. package/test/core/layout/layout.test.ts +201 -0
  80. package/test/core/list-manager/features/collection.test.ts +704 -0
  81. package/test/core/list-manager/features/viewport.test.ts +698 -0
  82. package/test/core/list-manager/list-manager.test.ts +593 -0
  83. package/test/core/list-manager/utils/calculations.test.ts +433 -0
  84. package/test/core/list-manager/utils/range-calculator.test.ts +569 -0
  85. package/test/core/list-manager/utils/speed-tracker.test.ts +530 -0
  86. package/test/utils/dom-helpers.ts +275 -0
  87. package/test/utils/performance-helpers.ts +392 -0
  88. package/tsconfig.build.json +23 -0
  89. package/tsconfig.json +20 -0
  90. package/dist/index.d.ts +0 -5
  91. package/dist/index.js +0 -38
  92. package/dist/index.mjs +0 -8
@@ -0,0 +1,168 @@
1
+ /**
2
+ * @module core/layout
3
+ * @description Unified layout system for mtrl-addons
4
+ * Provides array, object, and JSX-based layout creation with integrated optimizations
5
+ */
6
+
7
+ // Import for use in convenience functions
8
+ import { createLayout, clearClassCache, clearFragmentPool } from "./schema";
9
+
10
+ // Core schema processor and utilities
11
+ export {
12
+ createLayout,
13
+ processClassNames,
14
+ isComponent,
15
+ flattenLayout,
16
+ applyLayoutClasses,
17
+ applyLayoutItemClasses,
18
+ createLayoutResult,
19
+ clearClassCache,
20
+ clearFragmentPool,
21
+ } from "./schema";
22
+
23
+ // Essential types
24
+ export type {
25
+ LayoutConfig,
26
+ LayoutItemConfig,
27
+ LayoutOptions,
28
+ LayoutResult,
29
+ ComponentLike,
30
+ ElementOptions,
31
+ ElementDefinition,
32
+ Schema,
33
+ } from "./types";
34
+
35
+ // Configuration utilities
36
+ export {
37
+ cleanupLayoutClasses,
38
+ getLayoutType,
39
+ getLayoutPrefix,
40
+ setLayoutClasses,
41
+ } from "./config";
42
+
43
+ // JSX support
44
+ export {
45
+ h,
46
+ Fragment,
47
+ createJsxLayout,
48
+ component,
49
+ renderElements,
50
+ jsx,
51
+ } from "./jsx";
52
+
53
+ // Default export for convenient usage
54
+ export { createLayout as default } from "./schema";
55
+
56
+ /**
57
+ * Convenience function to create a layout with common patterns
58
+ * Provides a simpler API for common use cases
59
+ */
60
+ export function layout(
61
+ type: "stack" | "row" | "grid" | "flex" = "stack",
62
+ options: Record<string, any> = {}
63
+ ): any {
64
+ return createLayout([
65
+ "div",
66
+ {
67
+ layout: { type },
68
+ ...options,
69
+ },
70
+ ]);
71
+ }
72
+
73
+ /**
74
+ * Creates a responsive grid layout
75
+ * Automatically handles responsive breakpoints
76
+ */
77
+ export function grid(
78
+ columns: number | "auto-fit" | "auto-fill" = "auto-fit",
79
+ options: Record<string, any> = {}
80
+ ): any {
81
+ return createLayout([
82
+ "div",
83
+ {
84
+ layout: {
85
+ type: "grid",
86
+ columns,
87
+ gap: options.gap || "1rem",
88
+ ...options.layout,
89
+ },
90
+ ...options,
91
+ },
92
+ ]);
93
+ }
94
+
95
+ /**
96
+ * Creates a flexible row layout
97
+ * Automatically handles mobile stacking
98
+ */
99
+ export function row(options: Record<string, any> = {}): any {
100
+ return createLayout([
101
+ "div",
102
+ {
103
+ layout: {
104
+ type: "row",
105
+ gap: options.gap || "1rem",
106
+ mobileStack: options.mobileStack !== false,
107
+ ...options.layout,
108
+ },
109
+ ...options,
110
+ },
111
+ ]);
112
+ }
113
+
114
+ /**
115
+ * Creates a vertical stack layout
116
+ * Default layout type with consistent spacing
117
+ */
118
+ export function stack(options: Record<string, any> = {}): any {
119
+ return createLayout([
120
+ "div",
121
+ {
122
+ layout: {
123
+ type: "stack",
124
+ gap: options.gap || "1rem",
125
+ ...options.layout,
126
+ },
127
+ ...options,
128
+ },
129
+ ]);
130
+ }
131
+
132
+ /**
133
+ * Creates a layout from a template function
134
+ * Useful for dynamic layouts
135
+ */
136
+ export function template(
137
+ fn: (props: Record<string, any>) => any,
138
+ props: Record<string, any> = {}
139
+ ): any {
140
+ const schema = fn(props);
141
+ return createLayout(schema);
142
+ }
143
+
144
+ /**
145
+ * Performance utilities for layout management
146
+ */
147
+ export const performance = {
148
+ clearCache: clearClassCache,
149
+ clearFragmentPool,
150
+
151
+ /**
152
+ * Clears all cached resources
153
+ */
154
+ clearAll(): void {
155
+ clearClassCache();
156
+ clearFragmentPool();
157
+ },
158
+
159
+ /**
160
+ * Gets current cache stats
161
+ */
162
+ getStats(): Record<string, any> {
163
+ return {
164
+ // Stats would be implemented in the actual cache system
165
+ message: "Performance stats available in browser console",
166
+ };
167
+ },
168
+ };
@@ -0,0 +1,174 @@
1
+ /**
2
+ * @module core/layout/jsx
3
+ * @description JSX-like syntax support for layout creation
4
+ * Provides a simple h() function for creating elements without React dependency
5
+ */
6
+
7
+ import type { LayoutResult } from "./types";
8
+ import { createLayout } from "./schema";
9
+
10
+ /**
11
+ * Fragment symbol for JSX fragments
12
+ */
13
+ export const Fragment = Symbol("Fragment");
14
+
15
+ /**
16
+ * JSX-like hyperscript function
17
+ * Creates elements in a React-like syntax without React dependency
18
+ *
19
+ * @param tag - HTML tag name, component function, or Fragment
20
+ * @param props - Element properties and attributes
21
+ * @param children - Child elements
22
+ * @returns DOM element or component
23
+ */
24
+ export function h(
25
+ tag: string | Function | typeof Fragment,
26
+ props?: Record<string, any> | null,
27
+ ...children: any[]
28
+ ): any {
29
+ // Handle Fragment
30
+ if (tag === Fragment) {
31
+ const fragment = document.createDocumentFragment();
32
+ children.forEach((child) => {
33
+ if (child != null) {
34
+ const element =
35
+ typeof child === "string" ? document.createTextNode(child) : child;
36
+ fragment.appendChild(element);
37
+ }
38
+ });
39
+ return fragment;
40
+ }
41
+
42
+ // Handle string tags (HTML elements)
43
+ if (typeof tag === "string") {
44
+ const element = document.createElement(tag);
45
+
46
+ // Apply props
47
+ if (props) {
48
+ for (const [key, value] of Object.entries(props)) {
49
+ if (key === "className" || key === "class") {
50
+ element.className = value;
51
+ } else if (key.startsWith("on") && typeof value === "function") {
52
+ // Event handler
53
+ const eventName = key.slice(2).toLowerCase();
54
+ element.addEventListener(eventName, value);
55
+ } else if (key === "style" && typeof value === "object") {
56
+ // Style object
57
+ Object.assign(element.style, value);
58
+ } else if (key === "dangerouslySetInnerHTML") {
59
+ // HTML content
60
+ element.innerHTML = value.__html || "";
61
+ } else if (value != null) {
62
+ // Regular attribute
63
+ element.setAttribute(key, value.toString());
64
+ }
65
+ }
66
+ }
67
+
68
+ // Append children
69
+ children.forEach((child) => {
70
+ if (child != null) {
71
+ if (typeof child === "string") {
72
+ element.appendChild(document.createTextNode(child));
73
+ } else if (child instanceof Node) {
74
+ element.appendChild(child);
75
+ } else {
76
+ element.appendChild(document.createTextNode(String(child)));
77
+ }
78
+ }
79
+ });
80
+
81
+ return element;
82
+ }
83
+
84
+ // Handle component functions
85
+ if (typeof tag === "function") {
86
+ const allProps = props || {};
87
+ if (children.length > 0) {
88
+ allProps.children = children;
89
+ }
90
+ return tag(allProps);
91
+ }
92
+
93
+ // Fallback to div
94
+ return h("div", props, ...children);
95
+ }
96
+
97
+ /**
98
+ * Creates a layout using JSX-like syntax
99
+ * Provides a bridge between JSX and the layout system
100
+ *
101
+ * @param jsxElement - JSX element created with h()
102
+ * @param parentElement - Parent element to attach to
103
+ * @returns Layout result
104
+ */
105
+ export function createJsxLayout(
106
+ jsxElement: any,
107
+ parentElement?: any
108
+ ): LayoutResult {
109
+ // Convert JSX element to layout schema
110
+ const schema = jsxElement;
111
+
112
+ // Create layout using the standard createLayout function
113
+ return createLayout(schema, parentElement);
114
+ }
115
+
116
+ /**
117
+ * Utility to create a simple component from a function
118
+ * Useful for creating reusable JSX components
119
+ *
120
+ * @param fn - Component function
121
+ * @returns Component that can be used in JSX
122
+ */
123
+ export function component(fn: (props: Record<string, any>) => any): Function {
124
+ return function (props: Record<string, any>): any {
125
+ return fn(props || {});
126
+ };
127
+ }
128
+
129
+ /**
130
+ * Utility to render multiple JSX elements
131
+ * Useful for creating lists or collections
132
+ *
133
+ * @param elements - Array of JSX elements
134
+ * @param parentElement - Parent element to attach to
135
+ * @returns Array of layout results
136
+ */
137
+ export function renderElements(
138
+ elements: any[],
139
+ parentElement?: any
140
+ ): LayoutResult[] {
141
+ return elements.map((element) => createJsxLayout(element, parentElement));
142
+ }
143
+
144
+ /**
145
+ * Common JSX element creators for convenience
146
+ */
147
+ export const jsx = {
148
+ div: (props?: Record<string, any>, ...children: any[]) =>
149
+ h("div", props, ...children),
150
+ span: (props?: Record<string, any>, ...children: any[]) =>
151
+ h("span", props, ...children),
152
+ p: (props?: Record<string, any>, ...children: any[]) =>
153
+ h("p", props, ...children),
154
+ button: (props?: Record<string, any>, ...children: any[]) =>
155
+ h("button", props, ...children),
156
+ input: (props?: Record<string, any>) => h("input", props),
157
+ img: (props?: Record<string, any>) => h("img", props),
158
+ a: (props?: Record<string, any>, ...children: any[]) =>
159
+ h("a", props, ...children),
160
+ ul: (props?: Record<string, any>, ...children: any[]) =>
161
+ h("ul", props, ...children),
162
+ li: (props?: Record<string, any>, ...children: any[]) =>
163
+ h("li", props, ...children),
164
+ section: (props?: Record<string, any>, ...children: any[]) =>
165
+ h("section", props, ...children),
166
+ header: (props?: Record<string, any>, ...children: any[]) =>
167
+ h("header", props, ...children),
168
+ footer: (props?: Record<string, any>, ...children: any[]) =>
169
+ h("footer", props, ...children),
170
+ main: (props?: Record<string, any>, ...children: any[]) =>
171
+ h("main", props, ...children),
172
+ article: (props?: Record<string, any>, ...children: any[]) =>
173
+ h("article", props, ...children),
174
+ };