@tachui/primitives 0.8.0-alpha → 0.8.5-alpha

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachui/primitives",
3
- "version": "0.8.0-alpha",
3
+ "version": "0.8.5-alpha",
4
4
  "description": "Basic UI components for tachUI framework",
5
5
  "homepage": "https://tachui.dev/",
6
6
  "type": "module",
@@ -33,13 +33,13 @@
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@tachui/core": "0.8.0-alpha",
37
- "@tachui/modifiers": "0.8.0-alpha"
36
+ "@tachui/core": "0.8.5-alpha",
37
+ "@tachui/modifiers": "0.8.5-alpha"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^20.0.0",
41
41
  "@types/jsdom": "^21.1.6",
42
- "@vitest/coverage-v8": "^1.0.0",
42
+ "@vitest/coverage-v8": "^3.2.4",
43
43
  "jsdom": "^23.2.0",
44
44
  "typescript": "^5.2.0",
45
45
  "vite": "^7.1.1",
@@ -69,6 +69,8 @@
69
69
  },
70
70
  "scripts": {
71
71
  "build": "rm -rf dist && vite build && tsc --project tsconfig.build.json",
72
+ "build:dev": "rm -rf dist && vite build --mode development && tsc --project tsconfig.build.json",
73
+ "build:prod": "rm -rf dist && vite build --mode production && tsc --project tsconfig.build.json",
72
74
  "dev": "vite build --watch",
73
75
  "valid": "clear && vitest run && pnpm type-check && pnpm lint && pnpm build",
74
76
  "test": "vitest run",
@@ -1,474 +0,0 @@
1
- import { createModifiableComponent as C, createModifierBuilder as S, ComponentWithCSSClasses as $, processElementOverride as D, useLifecycle as F, registerComponentWithLifecycleHooks as _, h as A, isSignal as y, createEffect as M } from "@tachui/core";
2
- var R = Object.defineProperty, L = (e, t, n) => t in e ? R(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, v = (e, t, n) => L(e, typeof t != "symbol" ? t + "" : t, n);
3
- function P(e) {
4
- return e && typeof e.concat == "function" && typeof e.toSegment == "function" && typeof e.isConcatenatable == "function";
5
- }
6
- function x(e) {
7
- const t = C(e), n = S(t), s = {
8
- ...t,
9
- modifier: n,
10
- modifierBuilder: n
11
- };
12
- return P(e) && (s.concat = function(a) {
13
- return e.concat(a);
14
- }, s.toSegment = function() {
15
- return e.toSegment();
16
- }, s.isConcatenatable = function() {
17
- return e.isConcatenatable();
18
- }), s;
19
- }
20
- class T extends $ {
21
- constructor(t, n, s = [], a = {}) {
22
- super(), this.props = t, this.layoutType = n, this.children = s, this.layoutProps = a, v(this, "type", "component"), v(this, "id"), v(this, "mounted", !1), v(this, "cleanup", []), v(this, "effectiveTag"), this.id = `layout-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
23
- const r = this.layoutType === "hstack" ? "HStack" : this.layoutType === "vstack" ? "VStack" : "ZStack", m = D(
24
- r,
25
- "div",
26
- this.props.element
27
- );
28
- this.effectiveTag = m.tag, process.env.NODE_ENV === "test" && this.effectiveTag !== "div" && (this.effectiveTag === "nav" ? this.props.role = "navigation" : this.effectiveTag === "header" ? this.props.role = "banner" : this.effectiveTag === "footer" ? this.props.role = "contentinfo" : this.effectiveTag === "main" ? this.props.role = "main" : this.effectiveTag === "aside" && (this.props.role = "complementary")), F(this, {
29
- onDOMReady: (l, i) => {
30
- this.children.forEach((o, u) => {
31
- const f = o._enhancedLifecycle;
32
- if (f && f.onDOMReady && !o.domReady)
33
- try {
34
- if (i) {
35
- const h = this.findChildDOMElements(
36
- o,
37
- i,
38
- u
39
- );
40
- if (h.length > 0) {
41
- o.domElements = /* @__PURE__ */ new Map(), h.forEach((g, w) => {
42
- const E = g.id || `element-${w}`;
43
- o.domElements.set(E, g), o.primaryElement || (o.primaryElement = g);
44
- }), o.domReady = !0;
45
- const d = f.onDOMReady(
46
- o.domElements,
47
- o.primaryElement
48
- );
49
- if (typeof d == "function" && (o.cleanup = o.cleanup || [], o.cleanup.push(d)), f.onMount) {
50
- const g = f.onMount();
51
- typeof g == "function" && (o.cleanup = o.cleanup || [], o.cleanup.push(g));
52
- }
53
- }
54
- }
55
- } catch (h) {
56
- console.error(
57
- `Error processing lifecycle hooks for child ${o.id}:`,
58
- h
59
- );
60
- }
61
- });
62
- }
63
- }), _(this);
64
- }
65
- /**
66
- * Find DOM elements for a specific child component within the layout container
67
- */
68
- findChildDOMElements(t, n, s) {
69
- if (t.id.startsWith("image-")) {
70
- const r = n.querySelectorAll("img.tachui-image");
71
- return r[s] ? [r[s]] : Array.from(r);
72
- }
73
- if (t.id.startsWith("button-")) {
74
- const r = n.querySelectorAll("button.tachui-button");
75
- return r[s] ? [r[s]] : Array.from(r);
76
- }
77
- if (t.id.startsWith("text-")) {
78
- const r = n.querySelectorAll(
79
- "span.tachui-text, .tachui-text"
80
- );
81
- return r[s] ? [r[s]] : Array.from(r);
82
- }
83
- const a = Array.from(n.children);
84
- return a[s] ? [a[s]] : a;
85
- }
86
- render() {
87
- const { spacing: t = 0, debugLabel: n } = this.layoutProps, s = this.layoutProps.alignment !== void 0 ? this.layoutProps.alignment : "center", a = [`tachui-${this.layoutType}`], r = this.createClassString(this.props, a);
88
- switch (this.layoutType) {
89
- case "vstack": {
90
- const l = this.children.map((u) => {
91
- const f = u.render();
92
- return Array.isArray(f) ? f : [f];
93
- }).flat(), i = {};
94
- return this.effectiveTag === "nav" ? i.role = "navigation" : this.effectiveTag === "header" ? i.role = "banner" : this.effectiveTag === "footer" ? i.role = "contentinfo" : this.effectiveTag === "main" ? i.role = "main" : this.effectiveTag === "aside" && (i.role = "complementary"), [{
95
- type: "element",
96
- tag: this.effectiveTag,
97
- props: {
98
- className: r,
99
- style: {
100
- display: "flex",
101
- flexDirection: "column",
102
- gap: t ? `${t}px` : "0",
103
- alignItems: s === "leading" ? "flex-start" : s === "trailing" ? "flex-end" : "center"
104
- },
105
- "data-tachui-component": "VStack",
106
- ...n && { "data-tachui-label": n },
107
- ...i
108
- },
109
- children: l
110
- }];
111
- }
112
- case "hstack": {
113
- const l = this.children.map((u) => {
114
- const f = u.render();
115
- return Array.isArray(f) ? f : [f];
116
- }).flat(), i = {};
117
- return this.effectiveTag === "nav" ? i.role = "navigation" : this.effectiveTag === "header" ? i.role = "banner" : this.effectiveTag === "footer" ? i.role = "contentinfo" : this.effectiveTag === "main" ? i.role = "main" : this.effectiveTag === "aside" && (i.role = "complementary"), [{
118
- type: "element",
119
- tag: this.effectiveTag,
120
- props: {
121
- className: r,
122
- style: {
123
- display: "flex",
124
- flexDirection: "row",
125
- gap: t ? `${t}px` : "0",
126
- alignItems: s === "top" ? "flex-start" : s === "bottom" ? "flex-end" : "center"
127
- },
128
- "data-tachui-component": "HStack",
129
- ...n && { "data-tachui-label": n },
130
- ...i
131
- },
132
- children: l
133
- }];
134
- }
135
- case "zstack": {
136
- const l = this.children.map((h) => {
137
- const d = h.render();
138
- return Array.isArray(d) ? d : [d];
139
- }).flat(), o = ((h) => {
140
- switch (h) {
141
- case "topLeading":
142
- return { justifyContent: "flex-start", alignItems: "flex-start" };
143
- case "top":
144
- return { justifyContent: "flex-start", alignItems: "center" };
145
- case "topTrailing":
146
- return { justifyContent: "flex-start", alignItems: "flex-end" };
147
- case "leading":
148
- return { justifyContent: "center", alignItems: "flex-start" };
149
- case "center":
150
- return { justifyContent: "center", alignItems: "center" };
151
- case "trailing":
152
- return { justifyContent: "center", alignItems: "flex-end" };
153
- case "bottomLeading":
154
- return { justifyContent: "flex-end", alignItems: "flex-start" };
155
- case "bottom":
156
- return { justifyContent: "flex-end", alignItems: "center" };
157
- case "bottomTrailing":
158
- return { justifyContent: "flex-end", alignItems: "flex-end" };
159
- default:
160
- return { justifyContent: "center", alignItems: "center" };
161
- }
162
- })(s), u = {};
163
- return this.effectiveTag === "nav" ? u.role = "navigation" : this.effectiveTag === "header" ? u.role = "banner" : this.effectiveTag === "footer" ? u.role = "contentinfo" : this.effectiveTag === "main" ? u.role = "main" : this.effectiveTag === "aside" && (u.role = "complementary"), [{
164
- type: "element",
165
- tag: this.effectiveTag,
166
- props: {
167
- className: r,
168
- style: {
169
- display: "flex",
170
- position: "relative",
171
- ...o
172
- },
173
- "data-tachui-component": "ZStack",
174
- ...u
175
- },
176
- children: l.map((h, d) => ({
177
- ...h,
178
- props: {
179
- ...h.props,
180
- style: {
181
- ...h.props?.style,
182
- position: d === 0 ? "relative" : "absolute",
183
- zIndex: l.length - d
184
- }
185
- }
186
- }))
187
- }];
188
- }
189
- default:
190
- return [];
191
- }
192
- }
193
- /**
194
- * Cleanup resources
195
- */
196
- dispose() {
197
- this.cleanup.forEach((t) => {
198
- try {
199
- t();
200
- } catch (n) {
201
- console.error("Layout component cleanup error:", n);
202
- }
203
- }), this.cleanup = [], this.children.forEach((t) => {
204
- t.dispose && t.dispose();
205
- });
206
- }
207
- }
208
- function Z(e = {}) {
209
- const { children: t = [], spacing: n = 0, debugLabel: s } = e, a = e.alignment !== void 0 ? e.alignment : "center", r = new T(e, "vstack", t, {
210
- spacing: n,
211
- alignment: a,
212
- debugLabel: s
213
- });
214
- return x(r);
215
- }
216
- function q(e = {}) {
217
- const { children: t = [], spacing: n = 0, debugLabel: s } = e, a = e.alignment !== void 0 ? e.alignment : "center", r = new T(e, "hstack", t, {
218
- spacing: n,
219
- alignment: a,
220
- debugLabel: s
221
- });
222
- return x(r);
223
- }
224
- function G(e = {}) {
225
- const { children: t = [], alignment: n = "center" } = e, s = new T(e, "zstack", t, {
226
- alignment: n
227
- });
228
- return x(s);
229
- }
230
- var V = Object.defineProperty, z = (e, t, n) => t in e ? V(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, k = (e, t, n) => z(e, typeof t != "symbol" ? t + "" : t, n);
231
- function B(e) {
232
- const t = C(e), n = S(t);
233
- return {
234
- ...t,
235
- modifier: n,
236
- modifierBuilder: n
237
- };
238
- }
239
- class N extends $ {
240
- constructor(t) {
241
- super(), k(this, "type", "component"), k(this, "id"), k(this, "props"), this.props = t, this.id = `spacer-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
242
- }
243
- render() {
244
- const t = this.props.minLength ?? 0, n = ["tachui-spacer"], s = this.createClassString(this.props, n);
245
- return A("div", {
246
- className: s,
247
- style: {
248
- // Core flex properties for expansion
249
- flexGrow: "1",
250
- flexShrink: "1",
251
- flexBasis: "0",
252
- // Minimum size constraints
253
- minWidth: `${t}px`,
254
- minHeight: `${t}px`,
255
- // Ensure proper behavior in both directions
256
- alignSelf: "stretch"
257
- // Visual debugging (remove in production)
258
- // backgroundColor: 'rgba(255, 0, 0, 0.1)', // Uncomment to visualize spacers
259
- }
260
- });
261
- }
262
- }
263
- function U(e) {
264
- let t;
265
- return typeof e == "number" ? t = { minLength: e } : t = e || {}, B(new N(t));
266
- }
267
- var j = Object.defineProperty, W = (e, t, n) => t in e ? j(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, b = (e, t, n) => W(e, typeof t != "symbol" ? t + "" : t, n);
268
- const c = {
269
- colors: {
270
- default: "#E5E5E5",
271
- light: "#F0F0F0",
272
- medium: "#D1D1D1",
273
- heavy: "#A0A0A0",
274
- primary: "#007AFF",
275
- secondary: "#5AC8FA",
276
- subtle: "#F2F2F7",
277
- prominent: "#1C1C1E"
278
- },
279
- thickness: {
280
- thin: 1,
281
- medium: 2,
282
- thick: 3
283
- },
284
- spacing: {
285
- small: 8,
286
- medium: 16,
287
- large: 24
288
- }
289
- };
290
- function O(e) {
291
- const t = C(e), n = S(t);
292
- return {
293
- ...t,
294
- modifier: n,
295
- modifierBuilder: n
296
- };
297
- }
298
- class H {
299
- constructor(t) {
300
- b(this, "type", "component"), b(this, "id"), b(this, "props"), b(this, "cleanup", []), b(this, "theme", c), this.props = t, this.id = `divider-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
301
- }
302
- resolveValue(t) {
303
- return y(t) ? t() : t;
304
- }
305
- getBaseStyles() {
306
- const t = this.props.orientation === "vertical", n = this.resolveValue(
307
- this.props.thickness ?? this.theme.thickness.thin
308
- ), s = this.resolveValue(
309
- this.props.color ?? this.theme.colors.default
310
- ), a = this.props.style ?? "solid", r = this.resolveValue(this.props.opacity ?? 1), m = this.resolveValue(
311
- this.props.margin ?? this.theme.spacing.medium
312
- ), l = this.resolveValue(this.props.length ?? "100%"), i = {
313
- backgroundColor: s,
314
- opacity: r.toString(),
315
- borderStyle: a,
316
- borderColor: s,
317
- flexShrink: "0"
318
- // Prevent shrinking
319
- };
320
- return t ? (i.width = `${n}px`, i.height = typeof l == "number" ? `${l}px` : l, i.marginLeft = `${m}px`, i.marginRight = `${m}px`, i.borderLeftWidth = `${n}px`, i.backgroundColor = "transparent") : (i.height = `${n}px`, i.width = typeof l == "number" ? `${l}px` : l, i.marginTop = `${m}px`, i.marginBottom = `${m}px`, i.borderTopWidth = `${n}px`, i.backgroundColor = "transparent"), i;
321
- }
322
- render() {
323
- const t = this.props.orientation === "vertical", n = y(this.props.color) || y(this.props.thickness) || y(this.props.length) || y(this.props.margin) || y(this.props.opacity), s = A("div", {
324
- className: `tachui-divider tachui-divider-${t ? "vertical" : "horizontal"}`,
325
- style: this.getBaseStyles(),
326
- role: "separator",
327
- "aria-orientation": t ? "vertical" : "horizontal"
328
- });
329
- if (n) {
330
- const a = M(() => {
331
- const r = this.getBaseStyles();
332
- s.element && Object.assign(s.element.style, r);
333
- });
334
- this.cleanup.push(() => a.dispose()), s.dispose = () => {
335
- this.cleanup.forEach((r) => r());
336
- };
337
- }
338
- return s;
339
- }
340
- /**
341
- * Cleanup resources
342
- */
343
- dispose() {
344
- this.cleanup.forEach((t) => {
345
- try {
346
- t();
347
- } catch (n) {
348
- console.error("Divider component cleanup error:", n);
349
- }
350
- }), this.cleanup = [];
351
- }
352
- }
353
- function p(e = {}) {
354
- return O(new H(e));
355
- }
356
- const J = {
357
- /**
358
- * Create a horizontal divider
359
- */
360
- horizontal(e = {}) {
361
- return p({ ...e, orientation: "horizontal" });
362
- },
363
- /**
364
- * Create a vertical divider
365
- */
366
- vertical(e, t) {
367
- return p(typeof e == "object" ? { ...e, orientation: "vertical" } : {
368
- orientation: "vertical",
369
- length: e,
370
- thickness: t
371
- });
372
- },
373
- /**
374
- * Create a thin divider
375
- */
376
- thin(e) {
377
- return p({ thickness: c.thickness.thin, color: e });
378
- },
379
- /**
380
- * Create a medium divider
381
- */
382
- medium(e) {
383
- return p({ thickness: c.thickness.medium, color: e });
384
- },
385
- /**
386
- * Create a thick divider
387
- */
388
- thick(e) {
389
- return p({ thickness: c.thickness.thick, color: e });
390
- },
391
- /**
392
- * Create a dashed divider
393
- */
394
- dashed(e, t) {
395
- return p({ style: "dashed", color: e, thickness: t });
396
- },
397
- /**
398
- * Create a dotted divider
399
- */
400
- dotted(e, t) {
401
- return p({ style: "dotted", color: e, thickness: t });
402
- },
403
- /**
404
- * Create a subtle divider
405
- */
406
- subtle(e) {
407
- return p({
408
- color: e || c.colors.light,
409
- opacity: 0.6
410
- });
411
- },
412
- /**
413
- * Create a prominent divider
414
- */
415
- prominent(e) {
416
- return p({
417
- color: e || c.colors.heavy,
418
- thickness: c.thickness.medium
419
- });
420
- }
421
- }, K = {
422
- theme: c,
423
- colors: {
424
- primary: "#007AFF",
425
- success: "#34C759",
426
- warning: "#FF9500",
427
- danger: "#FF3B30"
428
- },
429
- thin: (e) => ({
430
- thickness: c.thickness.thin,
431
- color: e
432
- }),
433
- medium: (e) => ({
434
- thickness: c.thickness.medium,
435
- color: e
436
- }),
437
- thick: (e) => ({
438
- thickness: c.thickness.thick,
439
- color: e
440
- }),
441
- createTheme: (e) => ({
442
- colors: {
443
- ...c.colors,
444
- ...e.colors
445
- },
446
- thickness: {
447
- ...c.thickness,
448
- ...e.thickness
449
- },
450
- spacing: {
451
- ...c.spacing,
452
- ...e.spacing
453
- }
454
- }),
455
- // Color presets
456
- primary: (e) => p({ color: e || c.colors.primary }),
457
- secondary: (e) => p({ color: e || c.colors.secondary }),
458
- subtle: (e) => p({ color: e || c.colors.subtle }),
459
- prominent: (e) => p({ color: e || c.colors.prominent })
460
- };
461
- export {
462
- p as D,
463
- q as H,
464
- T as L,
465
- U as S,
466
- Z as V,
467
- G as Z,
468
- N as a,
469
- H as b,
470
- J as c,
471
- K as d,
472
- c as e,
473
- x as w
474
- };