@ramme-io/shared 3.4.0 → 3.6.0

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/dist/index.cjs CHANGED
@@ -50,6 +50,7 @@ __export(index_exports, {
50
50
  AppDialSchema: () => AppDialSchema,
51
51
  AppDocumentSchema: () => AppDocumentSchema,
52
52
  AppGroupSchema: () => AppGroupSchema,
53
+ AppIconSchema: () => AppIconSchema,
53
54
  AppImageSchema: () => AppImageSchema,
54
55
  AppLeafSchema: () => AppLeafSchema,
55
56
  AppOperandSchema: () => AppOperandSchema,
@@ -120,11 +121,16 @@ __export(index_exports, {
120
121
  EventSourceSchema: () => EventSourceSchema,
121
122
  FIRMWARE_UPDATE_ATTEMPTS: () => FIRMWARE_UPDATE_ATTEMPTS,
122
123
  FIRMWARE_UPDATE_PREFIX: () => FIRMWARE_UPDATE_PREFIX,
124
+ FULL_COLOUR_FRAME_MAX: () => FULL_COLOUR_FRAME_MAX,
125
+ FULL_RENDITION: () => FULL_RENDITION,
123
126
  FieldSchema: () => FieldSchema,
124
127
  FirmwareUpdateSchema: () => FirmwareUpdateSchema,
125
128
  FloraTelemetrySchema: () => FloraTelemetrySchema,
126
129
  GENESIS_LIBRARY_CONTEXT: () => GENESIS_LIBRARY_CONTEXT,
127
130
  GENESIS_VALID_COMPONENTS: () => GENESIS_VALID_COMPONENTS,
131
+ ICON_GRID: () => ICON_GRID,
132
+ ICON_SIZE_PX: () => ICON_SIZE_PX,
133
+ ICON_STROKE: () => ICON_STROKE,
128
134
  IMAGE_MAX_DRAWN: () => IMAGE_MAX_DRAWN,
129
135
  IMAGE_MAX_SCALE: () => IMAGE_MAX_SCALE,
130
136
  IMPACT_FLAG_THRESHOLD: () => IMPACT_FLAG_THRESHOLD,
@@ -144,6 +150,8 @@ __export(index_exports, {
144
150
  PageSectionSchema: () => PageSectionSchema,
145
151
  PaginatedEntityEventsSchema: () => PaginatedEntityEventsSchema,
146
152
  PairCodeSchema: () => PairCodeSchema,
153
+ PhotoCropSchema: () => PhotoCropSchema,
154
+ PhotoFullSchema: () => PhotoFullSchema,
147
155
  PhotoSummarySchema: () => PhotoSummarySchema,
148
156
  PhotoUploadSchema: () => PhotoUploadSchema,
149
157
  ProvisioningStateSchema: () => ProvisioningStateSchema,
@@ -184,6 +192,9 @@ __export(index_exports, {
184
192
  TriggerSchema: () => TriggerSchema,
185
193
  UserSchema: () => UserSchema,
186
194
  VitalSourceSchema: () => VitalSourceSchema,
195
+ WEATHER_CODES: () => WEATHER_CODES,
196
+ WEATHER_ICONS: () => WEATHER_ICONS,
197
+ WEATHER_ICON_NAMES: () => WEATHER_ICON_NAMES,
187
198
  WeatherAppConfigSchema: () => WeatherAppConfigSchema,
188
199
  WorkflowSchema: () => WorkflowSchema,
189
200
  architectureReferenceParameters: () => architectureReferenceParameters,
@@ -696,6 +707,8 @@ var AppTextSchema = import_zod6.z.object({
696
707
  size: AppTextSizeSchema.default("base"),
697
708
  align: AppAlignSchema.default("start"),
698
709
  /** Printed after the value, e.g. a degree symbol. Never itself bound. */
710
+ /** Drawn before the value, as `suffix` is after: "H " for "H 68°". */
711
+ prefix: import_zod6.z.string().max(8).optional(),
699
712
  suffix: import_zod6.z.string().max(8).optional(),
700
713
  ...leafBase
701
714
  });
@@ -753,6 +766,7 @@ var AssetHashSchema = import_zod6.z.string().regex(/^[0-9a-f]{64}$/, "a lowercas
753
766
  var IMAGE_MAX_DRAWN = { width: 304, height: 224 };
754
767
  var IMAGE_MAX_SCALE = 8;
755
768
  var RETRO_RENDITION = { width: 76, height: 56, scale: 4, colors: 16 };
769
+ var FULL_RENDITION = { width: 304, height: 224, quality: 0.82, maxBytes: 48e3 };
756
770
  var SPR_FORMAT = {
757
771
  /** "RSPR". */
758
772
  magic: [82, 83, 80, 82],
@@ -771,7 +785,24 @@ var AppImageSchema = import_zod6.z.object({
771
785
  width: import_zod6.z.number().int().min(1).max(IMAGE_MAX_DRAWN.width),
772
786
  height: import_zod6.z.number().int().min(1).max(IMAGE_MAX_DRAWN.height),
773
787
  scale: import_zod6.z.number().int().min(1).max(IMAGE_MAX_SCALE).default(1),
788
+ /**
789
+ * What kind of file `asset` names: `spr`, the palette file the retro look
790
+ * uses, or `jpeg`, the full-colour rendition (drawn at scale 1). Absent means
791
+ * `spr`, which is every image block written before full colour existed.
792
+ */
793
+ format: import_zod6.z.enum(["spr", "jpeg"]).default("spr"),
794
+ align: AppAlignSchema.default("start"),
795
+ /** Drawn only when this is false, or absent. */
796
+ hideWhen: AppConditionSchema.optional()
797
+ });
798
+ var ICON_SIZE_PX = { sm: 24, md: 48, lg: 72, xl: 96 };
799
+ var AppIconSchema = import_zod6.z.object({
800
+ type: import_zod6.z.literal("icon"),
801
+ value: AppBindingSchema,
802
+ size: import_zod6.z.enum(["sm", "md", "lg", "xl"]).default("md"),
774
803
  align: AppAlignSchema.default("start"),
804
+ color: AppColorSchema.default("foreground"),
805
+ rules: import_zod6.z.array(AppStyleRuleSchema).max(4).optional(),
775
806
  /** Drawn only when this is false, or absent. */
776
807
  hideWhen: AppConditionSchema.optional()
777
808
  });
@@ -782,13 +813,25 @@ var AppLeafSchema = import_zod6.z.discriminatedUnion("type", [
782
813
  AppBarSchema,
783
814
  AppStatusSchema,
784
815
  AppSpriteSchema,
785
- AppImageSchema
816
+ AppImageSchema,
817
+ AppIconSchema
786
818
  ]);
787
819
  var AppGroupSchema = import_zod6.z.object({
788
820
  type: import_zod6.z.literal("group"),
789
821
  direction: import_zod6.z.enum(["row", "stack"]),
790
822
  gap: import_zod6.z.number().int().min(0).max(64).default(4),
791
823
  align: AppAlignSchema.default("start"),
824
+ /**
825
+ * A row whose children take their own width, `gap` apart, placed together
826
+ * at the row's `align` — "68°" with its icon right beside it, "H 68° L 56°"
827
+ * as one line. Without it a row splits into equal cells, which put a short
828
+ * temperature and its icon half a screen apart. Text is as wide as the
829
+ * board draws it (six pixels in eight, per character); bars, dials,
830
+ * sparklines and status lights have no width of their own and share what is
831
+ * left. Ignored by a stack, and by firmware older than 2026-10-17, which
832
+ * falls back to equal cells.
833
+ */
834
+ pack: import_zod6.z.boolean().optional(),
792
835
  children: import_zod6.z.array(AppLeafSchema).min(1).max(8)
793
836
  });
794
837
  var AppBlockSchema = import_zod6.z.union([AppLeafSchema, AppGroupSchema]);
@@ -805,6 +848,13 @@ var AppDocumentSchema = import_zod6.z.object({
805
848
  author: import_zod6.z.string().max(32).optional(),
806
849
  screen: AppScreenSizeSchema.default("320x240"),
807
850
  background: AppColorSchema.default("background"),
851
+ /**
852
+ * Where the blocks sit on the screen as a whole: from the top, or in the
853
+ * middle with the space shared above and below. A document taller than the
854
+ * screen starts at the top either way, so centring never pushes the first
855
+ * block off the glass. Older firmware draws from the top.
856
+ */
857
+ valign: import_zod6.z.enum(["start", "center"]).optional(),
808
858
  /** Named so bindings can refer to them. */
809
859
  sources: import_zod6.z.record(AppSourceSchema).default({}),
810
860
  blocks: import_zod6.z.array(AppBlockSchema).min(1).max(12)
@@ -826,6 +876,14 @@ var AppDocumentSchema = import_zod6.z.object({
826
876
  const b = block;
827
877
  if (b?.type !== "image" || !b.width || !b.height) return;
828
878
  const scale = b.scale ?? 1;
879
+ if (b.format === "jpeg" && scale !== 1) {
880
+ ctx.addIssue({
881
+ code: import_zod6.z.ZodIssueCode.custom,
882
+ path: [...path, "scale"],
883
+ message: "A jpeg image is drawn at scale 1; make the file the size it should appear."
884
+ });
885
+ return;
886
+ }
829
887
  const w = b.width * scale;
830
888
  const h = b.height * scale;
831
889
  if (w <= IMAGE_MAX_DRAWN.width && h <= IMAGE_MAX_DRAWN.height) return;
@@ -854,10 +912,22 @@ var ORIGINAL_MAX_SIDE = 3072;
854
912
  var ORIGINAL_MAX_BYTES = 3e6;
855
913
  var PHOTOS_PER_ACCOUNT = 50;
856
914
  var PHOTO_UPLOADS_PER_HOUR = 30;
915
+ var PhotoCropSchema = import_zod7.z.object({
916
+ x: import_zod7.z.number().min(0).max(1),
917
+ y: import_zod7.z.number().min(0).max(1),
918
+ w: import_zod7.z.number().gt(0).max(1),
919
+ h: import_zod7.z.number().gt(0).max(1),
920
+ mirror: import_zod7.z.boolean().default(false)
921
+ });
857
922
  var PhotoUploadSchema = import_zod7.z.object({
858
923
  rendition: import_zod7.z.string().min(4),
859
- original: import_zod7.z.string().min(4)
924
+ original: import_zod7.z.string().min(4),
925
+ /** The full-colour rendition (FULL_RENDITION), base64 JPEG. Optional for older clients. */
926
+ full: import_zod7.z.string().min(4).optional(),
927
+ crop: PhotoCropSchema.optional()
860
928
  });
929
+ var PhotoFullSchema = import_zod7.z.object({ full: import_zod7.z.string().min(4) });
930
+ var FULL_COLOUR_FRAME_MAX = 4;
861
931
  var PhotoSummarySchema = import_zod7.z.object({
862
932
  hash: AssetHashSchema,
863
933
  /** The rendition's own pixels. */
@@ -867,7 +937,10 @@ var PhotoSummarySchema = import_zod7.z.object({
867
937
  originalWidth: import_zod7.z.number().int().positive(),
868
938
  originalHeight: import_zod7.z.number().int().positive(),
869
939
  originalBytes: import_zod7.z.number().int().positive(),
870
- uploadedAt: import_zod7.z.number().int()
940
+ uploadedAt: import_zod7.z.number().int(),
941
+ /** The full-colour rendition, when one has been made. Its own hash names it. */
942
+ full: import_zod7.z.object({ hash: AssetHashSchema, bytes: import_zod7.z.number().int().positive() }).optional(),
943
+ crop: PhotoCropSchema.optional()
871
944
  });
872
945
 
873
946
  // src/apps/delivery.ts
@@ -1141,6 +1214,73 @@ var DEVICE_TIMEZONES = [
1141
1214
  ];
1142
1215
  var DEVICE_TIMEZONE_FALLBACK = "UTC0";
1143
1216
 
1217
+ // src/apps/weather.ts
1218
+ var WEATHER_ICON_NAMES = ["sun", "partly", "cloud", "fog", "rain", "snow", "storm"];
1219
+ var WEATHER_CODES = [
1220
+ { upTo: 0, word: "Clear", icon: "sun" },
1221
+ { upTo: 1, word: "Mostly clear", icon: "sun" },
1222
+ { upTo: 2, word: "Partly cloudy", icon: "partly" },
1223
+ { upTo: 3, word: "Cloudy", icon: "cloud" },
1224
+ { upTo: 48, word: "Fog", icon: "fog" },
1225
+ { upTo: 57, word: "Drizzle", icon: "rain" },
1226
+ { upTo: 67, word: "Rain", icon: "rain" },
1227
+ { upTo: 77, word: "Snow", icon: "snow" },
1228
+ { upTo: 82, word: "Showers", icon: "rain" },
1229
+ { upTo: 86, word: "Snow showers", icon: "snow" },
1230
+ { upTo: 99, word: "Storm", icon: "storm" }
1231
+ ];
1232
+ var ICON_GRID = 48;
1233
+ var ICON_STROKE = 3;
1234
+ var WEATHER_ICONS = {
1235
+ sun: [
1236
+ [32, 24, 32, 26, 30, 29, 29, 30, 26, 32, 22, 32, 19, 30, 18, 29, 16, 26, 16, 22, 18, 19, 19, 18, 22, 16, 26, 16, 29, 18, 30, 19, 32, 22, 32, 24],
1237
+ [37, 24, 43, 24],
1238
+ [33, 33, 37, 37],
1239
+ [24, 37, 24, 43],
1240
+ [15, 33, 11, 37],
1241
+ [11, 24, 5, 24],
1242
+ [15, 15, 11, 11],
1243
+ [24, 11, 24, 5],
1244
+ [33, 15, 37, 11]
1245
+ ],
1246
+ partly: [
1247
+ [17, 23, 15, 23, 13, 22, 11, 20, 10, 18, 10, 14, 11, 12, 13, 10, 15, 9, 19, 9, 21, 10, 23, 12, 24, 14, 24, 16],
1248
+ [28, 16, 32, 16],
1249
+ [9, 24, 6, 27],
1250
+ [6, 16, 2, 16],
1251
+ [9, 8, 6, 5],
1252
+ [17, 5, 17, 1],
1253
+ [25, 8, 28, 5],
1254
+ [41, 33, 40, 35, 38, 37, 36, 38, 15, 38, 13, 37, 11, 33, 13, 29, 15, 27, 17, 27, 17, 24, 19, 20, 21, 18, 23, 17, 28, 17, 30, 18, 34, 22, 34, 24, 37, 25, 39, 26, 41, 28, 42, 30, 41, 33]
1255
+ ],
1256
+ cloud: [
1257
+ [42, 32, 40, 35, 38, 37, 35, 38, 12, 38, 10, 37, 9, 34, 8, 32, 9, 30, 10, 27, 14, 25, 14, 22, 15, 20, 21, 14, 27, 14, 33, 20, 34, 22, 37, 23, 39, 24, 41, 26, 42, 29, 42, 32]
1258
+ ],
1259
+ fog: [
1260
+ [8, 16, 40, 16],
1261
+ [12, 24, 36, 24],
1262
+ [8, 32, 40, 32]
1263
+ ],
1264
+ rain: [
1265
+ [41, 25, 37, 29, 35, 30, 13, 30, 10, 29, 9, 27, 9, 22, 10, 20, 14, 18, 15, 15, 15, 13, 19, 9, 21, 8, 26, 8, 29, 9, 31, 11, 33, 15, 36, 16, 38, 17, 40, 19, 41, 22, 41, 24],
1266
+ [15, 36, 12, 43],
1267
+ [24, 36, 21, 43],
1268
+ [33, 36, 30, 43]
1269
+ ],
1270
+ snow: [
1271
+ [41, 25, 37, 29, 35, 30, 13, 30, 10, 29, 9, 27, 9, 22, 10, 20, 14, 18, 15, 15, 15, 13, 19, 9, 21, 8, 26, 8, 29, 9, 31, 11, 33, 15, 36, 16, 38, 17, 40, 19, 41, 22, 41, 24],
1272
+ [14, 39, 14, 39],
1273
+ [24, 42, 24, 42],
1274
+ [34, 39, 34, 39],
1275
+ [19, 45, 19, 45],
1276
+ [29, 45, 29, 45]
1277
+ ],
1278
+ storm: [
1279
+ [41, 25, 37, 29, 35, 30, 13, 30, 10, 29, 9, 27, 9, 22, 10, 20, 14, 18, 15, 15, 15, 13, 19, 9, 21, 8, 26, 8, 29, 9, 31, 11, 33, 15, 36, 16, 38, 17, 40, 19, 41, 22, 41, 24],
1280
+ [26, 33, 20, 41, 27, 41, 22, 47]
1281
+ ]
1282
+ };
1283
+
1144
1284
  // src/ai/tools.ts
1145
1285
  var import_zod10 = require("zod");
1146
1286
  var telemetryGraphParameters = import_zod10.z.object({
@@ -1424,7 +1564,8 @@ THE SHAPE
1424
1564
 
1425
1565
  BLOCKS \u2014 up to 12, drawn top to bottom. Each is one of:
1426
1566
 
1427
- { "type": "text", "value": V, "size": S, "align": A, "color": C, "suffix": "\xB0" }
1567
+ { "type": "text", "value": V, "size": S, "align": A, "color": C, "prefix": "H ", "suffix": "\xB0" }
1568
+ { "type": "icon", "value": V, "size": "sm"|"md"|"lg"|"xl", "align": A, "color": C }
1428
1569
  { "type": "dial", "value": V, "min": 0, "max": 100, "label": "CPU", "color": C }
1429
1570
  { "type": "bar", "value": V, "min": 0, "max": 100, "color": C }
1430
1571
  { "type": "sparkline", "series": V, "color": C }
@@ -1433,7 +1574,18 @@ BLOCKS \u2014 up to 12, drawn top to bottom. Each is one of:
1433
1574
  0110
1434
1575
  1100
1435
1576
  0011", "align": A }
1436
- { "type": "group", "direction": "row"|"stack", "gap": 8, "align": A, "children": [ ...leaves... ] }
1577
+ { "type": "group", "direction": "row"|"stack", "gap": 8, "align": A, "pack": true, "children": [ ...leaves... ] }
1578
+
1579
+ A row splits the width into equal cells. Add "pack": true and each child takes
1580
+ only its own width, "gap" apart \u2014 a number with its icon right beside it, or
1581
+ "H 68\xB0 L 56\xB0" as one line. Put "valign": "center" at the top level of the
1582
+ document to centre the blocks on the screen rather than start at the top.
1583
+
1584
+ AN ICON is the sky drawn in outline: "sun", "partly", "cloud", "fog", "rain",
1585
+ "snow" or "storm". Bind its value to a weather source's "icon" field so it
1586
+ follows the weather \u2014 { "source": "forecast", "field": "icon" } \u2014 or write one
1587
+ of those names as a literal. Sizes are 24, 48, 72 and 96 pixels square. Prefer
1588
+ it to drawing a weather sprite: it costs nothing and the board draws it crisply.
1437
1589
 
1438
1590
  DRAWING A SPRITE \u2014 you may, and here is the only form that works.
1439
1591
 
@@ -1515,7 +1667,7 @@ SOURCES \u2014 declare what the app reads, then bind to it by name:
1515
1667
 
1516
1668
  "forecast": { "kind": "weather", "latitude": 39.95, "longitude": -75.17,
1517
1669
  "units": "imperial", "refreshSeconds": 600 }
1518
- fields: temperature, condition, high, low
1670
+ fields: temperature, condition, icon, high, low
1519
1671
  "now": { "kind": "clock", "timezone": "America/New_York", "twentyFourHour": false }
1520
1672
  fields: time, date, weekday, hour (hour is 0-23, for rules about time of day)
1521
1673
  "until": { "kind": "countdown", "target": "2026-12-25", "label": "Christmas" }
@@ -1936,6 +2088,7 @@ var EXCLUDED_SOURCES = {
1936
2088
  AppDialSchema,
1937
2089
  AppDocumentSchema,
1938
2090
  AppGroupSchema,
2091
+ AppIconSchema,
1939
2092
  AppImageSchema,
1940
2093
  AppLeafSchema,
1941
2094
  AppOperandSchema,
@@ -2006,11 +2159,16 @@ var EXCLUDED_SOURCES = {
2006
2159
  EventSourceSchema,
2007
2160
  FIRMWARE_UPDATE_ATTEMPTS,
2008
2161
  FIRMWARE_UPDATE_PREFIX,
2162
+ FULL_COLOUR_FRAME_MAX,
2163
+ FULL_RENDITION,
2009
2164
  FieldSchema,
2010
2165
  FirmwareUpdateSchema,
2011
2166
  FloraTelemetrySchema,
2012
2167
  GENESIS_LIBRARY_CONTEXT,
2013
2168
  GENESIS_VALID_COMPONENTS,
2169
+ ICON_GRID,
2170
+ ICON_SIZE_PX,
2171
+ ICON_STROKE,
2014
2172
  IMAGE_MAX_DRAWN,
2015
2173
  IMAGE_MAX_SCALE,
2016
2174
  IMPACT_FLAG_THRESHOLD,
@@ -2030,6 +2188,8 @@ var EXCLUDED_SOURCES = {
2030
2188
  PageSectionSchema,
2031
2189
  PaginatedEntityEventsSchema,
2032
2190
  PairCodeSchema,
2191
+ PhotoCropSchema,
2192
+ PhotoFullSchema,
2033
2193
  PhotoSummarySchema,
2034
2194
  PhotoUploadSchema,
2035
2195
  ProvisioningStateSchema,
@@ -2070,6 +2230,9 @@ var EXCLUDED_SOURCES = {
2070
2230
  TriggerSchema,
2071
2231
  UserSchema,
2072
2232
  VitalSourceSchema,
2233
+ WEATHER_CODES,
2234
+ WEATHER_ICONS,
2235
+ WEATHER_ICON_NAMES,
2073
2236
  WeatherAppConfigSchema,
2074
2237
  WorkflowSchema,
2075
2238
  architectureReferenceParameters,