juxscript 1.1.314 → 1.1.315

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.
@@ -1,7 +1,11 @@
1
1
  type GridDensity = 'dense' | 'normal' | 'inflated';
2
+ interface GridColumn {
3
+ name: string;
4
+ width?: string;
5
+ }
2
6
  interface GridOptions {
3
7
  rows?: number;
4
- cols?: number;
8
+ cols?: number | GridColumn[];
5
9
  density?: GridDensity;
6
10
  class?: string;
7
11
  style?: string;
@@ -12,6 +16,7 @@ declare class Grid {
12
16
  id: string;
13
17
  opts: GridOptions;
14
18
  private _element;
19
+ private _columns;
15
20
  constructor(id: string, options?: GridOptions);
16
21
  getValue(): string;
17
22
  getContent(): string;
@@ -20,25 +25,34 @@ declare class Grid {
20
25
  setStyle(val: string): this;
21
26
  setInnerHTML(val: string): this;
22
27
  getElement(): HTMLElement;
28
+ /** Get a named column cell element */
29
+ getColumn(name: string): HTMLElement | null;
30
+ getColumns(): GridColumn[];
23
31
  }
24
32
  /**
25
33
  * Create a CSS grid layout container.
26
34
  *
27
35
  * @example
28
- * // 3-column grid, normal spacing
36
+ * // Simple: 3 equal columns
29
37
  * jux.grid('cards', { cols: 3 });
30
38
  *
31
- * // 2x4 tight grid
32
- * jux.grid('dashboard', { cols: 4, rows: 2, density: 'dense' });
33
- *
34
- * // Spacious 2-col grid inside a target
35
- * jux.grid('content', { cols: 2, density: 'inflated', target: 'main' });
39
+ * // Named columns with custom widths
40
+ * jux.grid('layout', {
41
+ * cols: [
42
+ * { name: 'sidebar', width: '260px' },
43
+ * { name: 'content', width: '3fr' },
44
+ * { name: 'aside', width: '1fr' },
45
+ * ]
46
+ * });
47
+ * // Then target into them:
48
+ * jux.nav('main-nav', { target: 'sidebar' });
49
+ * jux.h1('title', { content: 'Hello', target: 'content' });
36
50
  *
37
- * // Add children into it
38
- * jux.div('cell-1', { content: 'A', target: 'cards' });
39
- * jux.div('cell-2', { content: 'B', target: 'cards' });
51
+ * // Density options
52
+ * jux.grid('tight', { cols: 4, density: 'dense' });
53
+ * jux.grid('spacious', { cols: 2, density: 'inflated' });
40
54
  */
41
55
  export declare function grid(id: string, options?: GridOptions): Grid;
42
- export { Grid, GridOptions, GridDensity };
56
+ export { Grid, GridOptions, GridColumn, GridDensity };
43
57
  export default grid;
44
58
  //# sourceMappingURL=grid.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../lib/components/grid.ts"],"names":[],"mappings":"AAGA,KAAK,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEnD,UAAU,WAAW;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAQD,cAAM,IAAI;IACN,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,CAAC,QAAQ,CAAc;gBAElB,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB;IA0CjD,QAAQ,IAAI,MAAM;IAClB,UAAU,IAAI,MAAM;IAEpB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAK7B,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAK3B,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAK3B,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAK/B,UAAU,IAAI,WAAW;CAC5B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,IAAI,CAIhE;AAED,OAA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BAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,IAAI,CAIhE;AAED,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;AACtD,eAAe,IAAI,CAAC"}
@@ -7,6 +7,7 @@ const DENSITY_MAP = {
7
7
  };
8
8
  class Grid {
9
9
  constructor(id, options = {}) {
10
+ this._columns = [];
10
11
  this.id = id || generateId();
11
12
  this.opts = {
12
13
  cols: 2,
@@ -17,10 +18,24 @@ class Grid {
17
18
  this._element.id = this.id;
18
19
  if (this.opts.class)
19
20
  this._element.className = this.opts.class;
21
+ // Resolve columns
22
+ const cols = this.opts.cols;
23
+ let templateCols;
24
+ if (Array.isArray(cols)) {
25
+ this._columns = cols.map(c => ({
26
+ name: c.name,
27
+ width: c.width || '1fr'
28
+ }));
29
+ templateCols = this._columns.map(c => c.width).join(' ');
30
+ }
31
+ else {
32
+ const count = cols || 2;
33
+ templateCols = `repeat(${count}, 1fr)`;
34
+ }
20
35
  const d = DENSITY_MAP[this.opts.density] || DENSITY_MAP.normal;
21
36
  const parts = [
22
37
  'display:grid',
23
- `grid-template-columns:repeat(${this.opts.cols}, 1fr)`,
38
+ `grid-template-columns:${templateCols}`,
24
39
  `gap:${d.gap}`,
25
40
  `padding:${d.padding}`,
26
41
  ];
@@ -36,11 +51,21 @@ class Grid {
36
51
  continue;
37
52
  this._element.setAttribute(`data-${key}`, String(value));
38
53
  }
54
+ // Mount
39
55
  const resolvedTarget = this.opts.target;
40
56
  const parent = resolvedTarget
41
57
  ? document.getElementById(resolvedTarget) || document.querySelector(resolvedTarget)
42
58
  : document.getElementById('app');
43
59
  parent?.appendChild(this._element);
60
+ // Create named column cells if using array cols
61
+ if (this._columns.length > 0) {
62
+ for (const col of this._columns) {
63
+ const cell = document.createElement('div');
64
+ cell.id = col.name;
65
+ cell.setAttribute('data-grid-col', col.name);
66
+ this._element.appendChild(cell);
67
+ }
68
+ }
44
69
  }
45
70
  // ═══════════════════════════════════════════════════════════
46
71
  // PAGESTATE INTEGRATION
@@ -64,23 +89,34 @@ class Grid {
64
89
  return this;
65
90
  }
66
91
  getElement() { return this._element; }
92
+ /** Get a named column cell element */
93
+ getColumn(name) {
94
+ return this._element.querySelector(`[data-grid-col="${name}"]`);
95
+ }
96
+ getColumns() { return [...this._columns]; }
67
97
  }
68
98
  /**
69
99
  * Create a CSS grid layout container.
70
100
  *
71
101
  * @example
72
- * // 3-column grid, normal spacing
102
+ * // Simple: 3 equal columns
73
103
  * jux.grid('cards', { cols: 3 });
74
104
  *
75
- * // 2x4 tight grid
76
- * jux.grid('dashboard', { cols: 4, rows: 2, density: 'dense' });
77
- *
78
- * // Spacious 2-col grid inside a target
79
- * jux.grid('content', { cols: 2, density: 'inflated', target: 'main' });
105
+ * // Named columns with custom widths
106
+ * jux.grid('layout', {
107
+ * cols: [
108
+ * { name: 'sidebar', width: '260px' },
109
+ * { name: 'content', width: '3fr' },
110
+ * { name: 'aside', width: '1fr' },
111
+ * ]
112
+ * });
113
+ * // Then target into them:
114
+ * jux.nav('main-nav', { target: 'sidebar' });
115
+ * jux.h1('title', { content: 'Hello', target: 'content' });
80
116
  *
81
- * // Add children into it
82
- * jux.div('cell-1', { content: 'A', target: 'cards' });
83
- * jux.div('cell-2', { content: 'B', target: 'cards' });
117
+ * // Density options
118
+ * jux.grid('tight', { cols: 4, density: 'dense' });
119
+ * jux.grid('spacious', { cols: 2, density: 'inflated' });
84
120
  */
85
121
  export function grid(id, options = {}) {
86
122
  const g = new Grid(id, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "juxscript",
3
- "version": "1.1.314",
3
+ "version": "1.1.315",
4
4
  "type": "module",
5
5
  "description": "A JavaScript UX authorship platform",
6
6
  "main": "./dist/lib/index.js",