@stacksjs/stx 0.2.623 → 0.2.625

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.
@@ -3,6 +3,7 @@ export const FALLBACK_SYMBOL = "circle", LUCIDE_TO_SF = {
3
3
  "alarm-clock": "alarm",
4
4
  "alert-circle": "exclamationmark.circle",
5
5
  "alert-triangle": "exclamationmark.triangle",
6
+ apple: "leaf",
6
7
  archive: "archivebox",
7
8
  armchair: "sofa",
8
9
  "arrow-down": "arrow.down",
@@ -22,7 +23,9 @@ export const FALLBACK_SYMBOL = "circle", LUCIDE_TO_SF = {
22
23
  "bar-chart-3": "chart.bar",
23
24
  battery: "battery.100",
24
25
  "battery-charging": "battery.100.bolt",
26
+ bean: "leaf",
25
27
  bed: "bed.double",
28
+ beef: "fork.knife",
26
29
  bell: "bell",
27
30
  "bell-off": "bell.slash",
28
31
  "bell-ring": "bell.and.waves.left.and.right",
@@ -37,6 +40,7 @@ export const FALLBACK_SYMBOL = "circle", LUCIDE_TO_SF = {
37
40
  building: "building",
38
41
  "building-2": "building.2",
39
42
  cable: "cable.connector",
43
+ "cake-slice": "birthday.cake",
40
44
  calendar: "calendar",
41
45
  "calendar-check": "calendar.badge.checkmark",
42
46
  "calendar-clock": "calendar.badge.clock",
@@ -50,6 +54,7 @@ export const FALLBACK_SYMBOL = "circle", LUCIDE_TO_SF = {
50
54
  "calendar-x": "calendar.badge.exclamationmark",
51
55
  "calendar-x-2": "calendar.badge.exclamationmark",
52
56
  camera: "camera",
57
+ carrot: "carrot",
53
58
  "chart-bar": "chart.bar",
54
59
  "chart-column": "chart.bar",
55
60
  "chart-line": "chart.xyaxis.line",
@@ -83,33 +88,41 @@ export const FALLBACK_SYMBOL = "circle", LUCIDE_TO_SF = {
83
88
  "clock-3": "clock",
84
89
  "clock-4": "clock",
85
90
  "clock-8": "clock",
91
+ "clock-alert": "clock.badge.exclamationmark",
86
92
  cloud: "cloud",
87
93
  "cloud-off": "icloud.slash",
88
94
  coffee: "cup.and.saucer",
95
+ cookie: "birthday.cake",
89
96
  copy: "doc.on.doc",
90
97
  "credit-card": "creditcard",
98
+ "cup-soda": "takeoutbag.and.cup.and.straw",
91
99
  cylinder: "cylinder",
92
100
  disc: "opticaldisc",
93
101
  download: "arrow.down.circle",
94
102
  droplet: "drop",
95
103
  droplets: "drop",
104
+ drumstick: "fork.knife",
96
105
  dumbbell: "dumbbell",
97
106
  edit: "pencil",
107
+ egg: "frying.pan",
98
108
  "external-link": "arrow.up.right.square",
99
109
  eye: "eye",
100
110
  "eye-off": "eye.slash",
101
111
  file: "doc",
102
112
  "file-text": "doc.text",
103
113
  filter: "line.3.horizontal.decrease",
114
+ fish: "fish",
104
115
  flag: "flag",
105
116
  flame: "flame",
106
117
  "flower-2": "camera.macro",
107
118
  footprints: "figure.run",
108
119
  gauge: "gauge",
109
120
  gift: "gift",
121
+ "glass-water": "waterbottle",
110
122
  globe: "globe",
111
123
  "graduation-cap": "graduationcap",
112
124
  "grip-vertical": "line.3.horizontal",
125
+ hamburger: "takeoutbag.and.cup.and.straw",
113
126
  "hand-fist": "hand.raised",
114
127
  heart: "heart",
115
128
  "heart-off": "heart.slash",
@@ -146,7 +159,9 @@ export const FALLBACK_SYMBOL = "circle", LUCIDE_TO_SF = {
146
159
  "message-circle": "bubble.left",
147
160
  "message-square": "text.bubble",
148
161
  "message-square-quote": "quote.bubble",
162
+ "messages-square": "bubble.left.and.bubble.right",
149
163
  mic: "mic",
164
+ milk: "waterbottle",
150
165
  minus: "minus",
151
166
  moon: "moon",
152
167
  "more-horizontal": "ellipsis",
@@ -154,6 +169,7 @@ export const FALLBACK_SYMBOL = "circle", LUCIDE_TO_SF = {
154
169
  mountain: "mountain.2",
155
170
  music: "music.note",
156
171
  "music-2": "music.note",
172
+ nut: "leaf",
157
173
  package: "shippingbox",
158
174
  pause: "pause",
159
175
  "pause-circle": "pause.circle",
@@ -171,6 +187,7 @@ export const FALLBACK_SYMBOL = "circle", LUCIDE_TO_SF = {
171
187
  route: "point.topleft.down.to.point.bottomright.curvepath",
172
188
  ruler: "ruler",
173
189
  sailboat: "sailboat",
190
+ salad: "leaf",
174
191
  satellite: "antenna.radiowaves.left.and.right",
175
192
  save: "square.and.arrow.down",
176
193
  scale: "scalemass",
@@ -192,6 +209,7 @@ export const FALLBACK_SYMBOL = "circle", LUCIDE_TO_SF = {
192
209
  "sliders-horizontal": "slider.horizontal.3",
193
210
  smartphone: "iphone",
194
211
  snowflake: "snowflake",
212
+ soup: "mug",
195
213
  sparkles: "sparkles",
196
214
  sprout: "leaf",
197
215
  square: "square",
@@ -227,15 +245,18 @@ export const FALLBACK_SYMBOL = "circle", LUCIDE_TO_SF = {
227
245
  "user-x": "person.crop.circle.badge.xmark",
228
246
  users: "person.2",
229
247
  "users-round": "person.2",
248
+ utensils: "fork.knife",
230
249
  video: "video",
231
250
  "volume-2": "speaker.wave.2",
232
251
  warehouse: "building.2",
233
252
  watch: "applewatch",
234
253
  waves: "figure.pool.swim",
235
254
  weight: "scalemass",
255
+ wheat: "laurel.leading",
236
256
  wifi: "wifi",
237
257
  "wifi-off": "wifi.slash",
238
258
  wind: "wind",
259
+ wine: "wineglass",
239
260
  x: "xmark",
240
261
  "x-circle": "xmark.circle",
241
262
  zap: "bolt"
@@ -243,7 +243,8 @@ export type STXComponentType = | 'Sidebar'
243
243
  | 'Ellipse'
244
244
  | 'Polyline'
245
245
  | 'Polygon'
246
- | 'SvgText';
246
+ | 'SvgText'
247
+ | 'Animate';
247
248
  // ============================================================================
248
249
  // Event Types
249
250
  // ============================================================================
@@ -8,6 +8,23 @@ export declare function pathGeometry(d: string): number[];
8
8
  * type that has none (`Svg`, `G`, `SvgText`).
9
9
  */
10
10
  export declare function svgGeometry(type: string, props: Record<string, unknown>): number[] | null;
11
+ /**
12
+ * An `<animate attributeName="d">` (SMIL) as the renderers play it: each of
13
+ * its `values` as an outline (`frames`), when in the repetition each is
14
+ * reached (`frameTimes`, from `keyTimes` or spread evenly), and how long one
15
+ * repetition takes (`duration`, in seconds). A renderer draws the shape's
16
+ * outline between the two frames either side of now, as SMIL's linear
17
+ * `calcMode` does, and its own outline when motion is reduced.
18
+ *
19
+ * Only path data animates natively for now: other attributes, too few
20
+ * frames or an unreadable duration give null, and the shape stays still.
21
+ */
22
+ export declare function svgAnimation(props: Record<string, unknown>): { frames: number[][], frameTimes: number[], duration: number } | null;
23
+ /**
24
+ * Sets (or clears) an `Animate` node's `frames`, `frameTimes` and `duration`
25
+ * from its attributes, and returns them as a patch for the renderers.
26
+ */
27
+ export declare function applySvgAnimation(props: Record<string, unknown>): Record<string, unknown>;
11
28
  /** Whether changing `attribute` on a `type` node changes its outline. */
12
29
  export declare function affectsGeometry(type: string, attribute: string): boolean;
13
30
  /**
@@ -60,7 +77,8 @@ export declare function parseSvgMarkup(markup: string): STXNode[];
60
77
  * polyline: 'Polyline',
61
78
  * polygon: 'Polygon',
62
79
  * text: 'SvgText',
63
- * tspan: 'SvgText'
80
+ * tspan: 'SvgText',
81
+ * animate: 'Animate'
64
82
  * }
65
83
  * ```
66
84
  */
@@ -80,7 +98,7 @@ export declare const SVG_DROPPED: Set<any>;
80
98
  * lowercases `viewBox`, and a template writes `stroke-width`; both arrive as
81
99
  * the one spelling.
82
100
  */
83
- export declare const SVG_PROP_NAMES: readonly ['viewBox', 'preserveAspectRatio', 'strokeWidth', 'strokeDasharray', 'strokeDashoffset', 'strokeLinecap', 'strokeLinejoin', 'strokeMiterlimit', 'strokeOpacity', 'fillOpacity', 'fillRule', 'vectorEffect', 'textAnchor', 'dominantBaseline', 'fontSize', 'fontWeight'];
101
+ export declare const SVG_PROP_NAMES: readonly ['viewBox', 'preserveAspectRatio', 'strokeWidth', 'strokeDasharray', 'strokeDashoffset', 'strokeLinecap', 'strokeLinejoin', 'strokeMiterlimit', 'strokeOpacity', 'fillOpacity', 'fillRule', 'vectorEffect', 'textAnchor', 'dominantBaseline', 'fontSize', 'fontWeight', 'attributeName', 'keyTimes', 'repeatCount'];
84
102
  /**
85
103
  * The attributes `geometry` is read from, per shape.
86
104
  * @defaultValue
@@ -102,3 +120,5 @@ export declare const LINE: 1;
102
120
  export declare const CUBIC: 2;
103
121
  export declare const QUAD: 3;
104
122
  export declare const CLOSE: 4;
123
+ /** The attributes an `Animate` node's keyframes are read from. */
124
+ export declare const SVG_ANIMATION_ATTRIBUTES: readonly string[];
@@ -9,7 +9,8 @@ export const SVG_TYPES = {
9
9
  polyline: "Polyline",
10
10
  polygon: "Polygon",
11
11
  text: "SvgText",
12
- tspan: "SvgText"
12
+ tspan: "SvgText",
13
+ animate: "Animate"
13
14
  }, SVG_NODE_TYPES = new Set(Object.values(SVG_TYPES)), SVG_SHAPE_TYPES = new Set(["Path", "Line", "Rect", "Circle", "Ellipse", "Polyline", "Polygon"]), SVG_DROPPED = new Set([
14
15
  "defs",
15
16
  "title",
@@ -43,7 +44,10 @@ export const SVG_TYPES = {
43
44
  "textAnchor",
44
45
  "dominantBaseline",
45
46
  "fontSize",
46
- "fontWeight"
47
+ "fontWeight",
48
+ "attributeName",
49
+ "keyTimes",
50
+ "repeatCount"
47
51
  ], SVG_GEOMETRY_ATTRIBUTES = {
48
52
  Path: ["d"],
49
53
  Line: ["x1", "y1", "x2", "y2"],
@@ -409,6 +413,35 @@ export function svgGeometry(type, props) {
409
413
  return null;
410
414
  }
411
415
  }
416
+ export const SVG_ANIMATION_ATTRIBUTES = ["attributeName", "values", "keyTimes", "dur"];
417
+ function seconds(value) {
418
+ const match = /^\s*(\d+(?:\.\d+)?|\.\d+)\s*(ms|s)?\s*$/.exec(String(value ?? ""));
419
+ if (!match)
420
+ return null;
421
+ const amount = Number(match[1]) / (match[2] === "ms" ? 1000 : 1);
422
+ return amount > 0 ? amount : null;
423
+ }
424
+ export function svgAnimation(props) {
425
+ if (props.attributeName !== "d")
426
+ return null;
427
+ const duration = seconds(props.dur), values = String(props.values ?? "").split(";").map((value) => value.trim()).filter(Boolean);
428
+ if (duration === null || values.length < 2)
429
+ return null;
430
+ const frames = values.map(pathGeometry);
431
+ if (frames.some((frame) => !frame.length))
432
+ return null;
433
+ const given = String(props.keyTimes ?? "").split(";").map((value) => value.trim()).filter(Boolean).map(Number), frameTimes = given.length === frames.length && given[0] === 0 && given[given.length - 1] === 1 && given.every((time, index) => Number.isFinite(time) && (index === 0 || time >= given[index - 1])) ? given.map(round) : frames.map((_, index) => round(index / (frames.length - 1)));
434
+ return { frames, frameTimes, duration };
435
+ }
436
+ export function applySvgAnimation(props) {
437
+ const animation = svgAnimation(props), patch = { frames: animation?.frames ?? null, frameTimes: animation?.frameTimes ?? null, duration: animation?.duration ?? null };
438
+ for (const [key, value] of Object.entries(patch))
439
+ if (value === null)
440
+ delete props[key];
441
+ else
442
+ props[key] = value;
443
+ return patch;
444
+ }
412
445
  export function affectsGeometry(type, attribute) {
413
446
  return SVG_GEOMETRY_ATTRIBUTES[type]?.includes(attribute) ?? !1;
414
447
  }
@@ -550,6 +583,8 @@ export function parseSvgMarkup(markup) {
550
583
  const geometry = svgGeometry(type, node.props);
551
584
  if (geometry)
552
585
  node.props.geometry = geometry;
586
+ if (type === "Animate")
587
+ applySvgAnimation(node.props);
553
588
  append(node);
554
589
  if (!selfClosing)
555
590
  stack.push({ tag: name, node, dropped: !1 });
@@ -1,5 +1,9 @@
1
1
  import { LUCIDE_TO_SF } from "../compiler/icons.js";
2
- const SYMBOL_TO_ICON = Object.fromEntries(Object.entries(LUCIDE_TO_SF).map(([name, symbol]) => [symbol, name])), SVG_NS = "http://www.w3.org/2000/svg", SVG = { Svg: "svg", G: "g", Path: "path", Line: "line", Rect: "rect", Circle: "circle", Ellipse: "ellipse", Polyline: "polyline", Polygon: "polygon", SvgText: "text" }, TAGS = { View: "div", SafeAreaView: "div", ScrollView: "div", KeyboardAvoidingView: "div", Text: "span", TextInput: "input", Button: "button", Link: "a", TouchableOpacity: "button", TouchableHighlight: "button", Pressable: "button", Icon: "span", Image: "img", ImageBackground: "div", Video: "video", FlatList: "div", SectionList: "div", Switch: "input", Checkbox: "input", Slider: "input", Picker: "select", DatePicker: "input", Modal: "dialog", ActivityIndicator: "progress", StatusBar: "div", RefreshControl: "progress", Sidebar: "aside", SplitView: "div" }, CONTAINERS = new Set(["View", "SafeAreaView", "ScrollView", "KeyboardAvoidingView", "FlatList", "SectionList", "Sidebar", "SplitView", "ImageBackground"]), UNITLESS = new Set(["opacity", "flex", "flexGrow", "flexShrink", "fontWeight", "zIndex", "aspectRatio", "order"]), SVG_PROPS = { viewBox: "viewBox", fillRule: "fill-rule", clipRule: "clip-rule", strokeWidth: "stroke-width", strokeLinecap: "stroke-linecap", strokeLinejoin: "stroke-linejoin", strokeDasharray: "stroke-dasharray", strokeDashoffset: "stroke-dashoffset", fillOpacity: "fill-opacity", strokeOpacity: "stroke-opacity", textAnchor: "text-anchor" };
2
+ const SYMBOL_TO_ICON = {};
3
+ for (const [name, symbol] of Object.entries(LUCIDE_TO_SF))
4
+ if (!(symbol in SYMBOL_TO_ICON) || name === symbol)
5
+ SYMBOL_TO_ICON[symbol] = name;
6
+ const SVG_NS = "http://www.w3.org/2000/svg", SVG = { Svg: "svg", G: "g", Path: "path", Line: "line", Rect: "rect", Circle: "circle", Ellipse: "ellipse", Polyline: "polyline", Polygon: "polygon", SvgText: "text", Animate: "animate" }, TAGS = { View: "div", SafeAreaView: "div", ScrollView: "div", KeyboardAvoidingView: "div", Text: "span", TextInput: "input", Button: "button", Link: "a", TouchableOpacity: "button", TouchableHighlight: "button", Pressable: "button", Icon: "span", Image: "img", ImageBackground: "div", Video: "video", FlatList: "div", SectionList: "div", Switch: "input", Checkbox: "input", Slider: "input", Picker: "select", DatePicker: "input", Modal: "dialog", ActivityIndicator: "progress", StatusBar: "div", RefreshControl: "progress", Sidebar: "aside", SplitView: "div" }, CONTAINERS = new Set(["View", "SafeAreaView", "ScrollView", "KeyboardAvoidingView", "FlatList", "SectionList", "Sidebar", "SplitView", "ImageBackground"]), UNITLESS = new Set(["opacity", "flex", "flexGrow", "flexShrink", "fontWeight", "zIndex", "aspectRatio", "order"]), SVG_PROPS = { viewBox: "viewBox", fillRule: "fill-rule", clipRule: "clip-rule", strokeWidth: "stroke-width", strokeLinecap: "stroke-linecap", strokeLinejoin: "stroke-linejoin", strokeDasharray: "stroke-dasharray", strokeDashoffset: "stroke-dashoffset", fillOpacity: "fill-opacity", strokeOpacity: "stroke-opacity", textAnchor: "text-anchor" };
3
7
 
4
8
  export class BrowserScreenRenderer {
5
9
  container;
@@ -515,7 +519,7 @@ export class BrowserScreenRenderer {
515
519
  }
516
520
  if (SVG[type])
517
521
  for (const [key, value] of Object.entries(props)) {
518
- if (["geometry", "testID", "accessibilityLabel"].includes(key))
522
+ if (["geometry", "frames", "frameTimes", "duration", "testID", "accessibilityLabel"].includes(key))
519
523
  continue;
520
524
  const name = SVG_PROPS[key] ?? key;
521
525
  if (value == null)
@@ -3,7 +3,7 @@ import { compileClassStyles } from "../compiler/headwind-to-style.js";
3
3
  import { resolveIconName } from "../compiler/icons.js";
4
4
  import { applyNativeLayoutDefaults, parseNativeStyleLayers } from "../compiler/inline-style.js";
5
5
  import { createStyleVariables } from "../compiler/style-variables.js";
6
- import { affectsGeometry, parseSvgMarkup, parseViewBox, SVG_NODE_TYPES, svgGeometry } from "../compiler/svg.js";
6
+ import { affectsGeometry, applySvgAnimation, parseSvgMarkup, parseViewBox, SVG_ANIMATION_ATTRIBUTES, SVG_NODE_TYPES, svgGeometry } from "../compiler/svg.js";
7
7
  import { NATIVE_EVENT_NAMES } from "../event-names.js";
8
8
  import { nativePropName } from "../prop-names.js";
9
9
  import { cloneNativeBindingNode } from "./binding-tree.js";
@@ -645,6 +645,8 @@ export function createNativeHost(options) {
645
645
  patch[prop] = record.props[prop] = parseViewBox(value);
646
646
  if (affectsGeometry(record.type, prop))
647
647
  patch.geometry = record.props.geometry = svgGeometry(record.type, record.props);
648
+ if (record.type === "Animate" && SVG_ANIMATION_ATTRIBUTES.includes(prop))
649
+ Object.assign(patch, applySvgAnimation(record.props));
648
650
  }
649
651
  if (record.materialized)
650
652
  emit({ op: "updateNode", id: node.__stxId, patch: { props: patch } });
@@ -669,6 +671,8 @@ export function createNativeHost(options) {
669
671
  Object.assign(patch, accessibilityChanges(record.props, accessibilityBefore, prop));
670
672
  if (affectsGeometry(record.type, prop))
671
673
  patch.geometry = record.props.geometry = svgGeometry(record.type, record.props);
674
+ if (record.type === "Animate" && SVG_ANIMATION_ATTRIBUTES.includes(prop))
675
+ Object.assign(patch, applySvgAnimation(record.props));
672
676
  if (record.materialized)
673
677
  emit({ op: "updateNode", id: node.__stxId, patch: { props: patch } });
674
678
  },
@@ -1,5 +1,5 @@
1
1
  export function validateTestMutations(source, operations) {
2
- const containers = new Set(["View", "SafeAreaView", "ScrollView", "KeyboardAvoidingView", "Modal", "Pressable", "TouchableOpacity", "TouchableHighlight", "ImageBackground", "FlatList", "SectionList", "Fragment", "Svg", "G", "Map"].map((type) => type.toLowerCase())), nodes = new Map([...source].map(([id, node]) => [id, {
2
+ const containers = new Set(["View", "SafeAreaView", "ScrollView", "KeyboardAvoidingView", "Modal", "Pressable", "TouchableOpacity", "TouchableHighlight", "ImageBackground", "FlatList", "SectionList", "Fragment", "Svg", "G", "Map", "Path", "Line", "Rect", "Circle", "Ellipse", "Polyline", "Polygon"].map((type) => type.toLowerCase())), nodes = new Map([...source].map(([id, node]) => [id, {
3
3
  type: node.type,
4
4
  parent: null,
5
5
  children: node.children.filter((child) => typeof child !== "string").map((child) => child.id)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.623",
4
+ "version": "0.2.625",
5
5
  "description": "A performant UI Framework. Powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -128,12 +128,12 @@
128
128
  "dependencies": {
129
129
  "@stacksjs/ts-css": "^0.3.11",
130
130
  "@stacksjs/clapp": "^0.2.16",
131
- "@stacksjs/desktop": "0.2.623",
132
- "@stacksjs/sanitizer": "0.2.623",
131
+ "@stacksjs/desktop": "0.2.625",
132
+ "@stacksjs/sanitizer": "0.2.625",
133
133
  "@stacksjs/ts-i18n": "^0.1.11",
134
- "bun-plugin-stx": "0.2.623",
134
+ "bun-plugin-stx": "0.2.625",
135
135
  "bunfig": "^0.15.21",
136
- "stx-router": "0.2.623",
136
+ "stx-router": "0.2.625",
137
137
  "ts-broadcasting": "^0.0.11",
138
138
  "ts-images": "^0.2.22",
139
139
  "ts-syntax-highlighter": "^0.2.1"