@typespec/html-program-viewer 0.76.0-dev.1 → 0.76.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.
@@ -0,0 +1,6 @@
1
+ const manifest = {
2
+ "version": "1.6.0",
3
+ "commit": "d8ea328e72d19b863da1fd4d499ec2ff6e5b737c"
4
+ };
5
+
6
+ export { manifest as default };
@@ -29119,6 +29119,192 @@ function useStateSet(key) {
29119
29119
  return [getter, setter];
29120
29120
  }
29121
29121
 
29122
+ class InvalidNumericError extends Error {
29123
+ code = "InvalidNumeric";
29124
+ }
29125
+ /** @internal */
29126
+ const InternalDataSym = Symbol.for("NumericInternalData");
29127
+ /**
29128
+ * Check if the given arg is a Numeric
29129
+ */
29130
+ function isNumeric(arg) {
29131
+ return typeof arg === "object" && arg !== null && InternalDataSym in arg;
29132
+ }
29133
+ /**
29134
+ * Represent any possible numeric value
29135
+ */
29136
+ function Numeric(stringValue) {
29137
+ if (new.target) {
29138
+ throw new Error("Numeric is not a constructor");
29139
+ }
29140
+ const data = parse(stringValue);
29141
+ const isInteger = data.d === 0;
29142
+ const obj = {
29143
+ [InternalDataSym]: data,
29144
+ isInteger,
29145
+ };
29146
+ // We are explicitly not using a class here due to version mismatch between the compiler and the runtime that could happen and break instanceof checks.
29147
+ const numeric = setTypedProptotype(obj, NumericPrototype);
29148
+ return Object.freeze(numeric);
29149
+ }
29150
+ function setTypedProptotype(obj, prototype) {
29151
+ Object.setPrototypeOf(obj, prototype);
29152
+ return obj;
29153
+ }
29154
+ function parse(original) {
29155
+ let stringValue = original;
29156
+ let start = 0;
29157
+ let sign = 1;
29158
+ let n;
29159
+ let exp;
29160
+ let decimal = undefined;
29161
+ if (stringValue[0] === "-") {
29162
+ start = 1;
29163
+ sign = -1;
29164
+ }
29165
+ const second = stringValue[start + 1]?.toLowerCase();
29166
+ if (stringValue[start] === "0" && (second === "b" || second === "x" || second === "o")) {
29167
+ try {
29168
+ n = BigInt(stringValue.slice(start));
29169
+ exp = n.toString().length;
29170
+ decimal = 0;
29171
+ }
29172
+ catch {
29173
+ throw new InvalidNumericError(`Invalid numeric value: ${original}`);
29174
+ }
29175
+ }
29176
+ else {
29177
+ // Skip leading 0.
29178
+ while (stringValue[start] === "0") {
29179
+ start++;
29180
+ }
29181
+ const decimalPointIndex = stringValue.indexOf(".");
29182
+ const adjustedPointIndex = decimalPointIndex - start;
29183
+ // Decimal point?
29184
+ if (decimalPointIndex !== -1) {
29185
+ exp = adjustedPointIndex;
29186
+ stringValue = stringValue.replace(".", "");
29187
+ }
29188
+ let i;
29189
+ if ((i = stringValue.search(/e/i)) > 0) {
29190
+ // Determine exponent.
29191
+ if (exp === undefined) {
29192
+ exp = i - start;
29193
+ }
29194
+ exp += Number(stringValue.slice(i + 1));
29195
+ stringValue = stringValue.slice(start, i);
29196
+ decimal = Math.max(stringValue.length - exp, 0);
29197
+ }
29198
+ else if (exp === undefined) {
29199
+ // Integer.
29200
+ exp = stringValue.length - start;
29201
+ stringValue = stringValue.slice(start);
29202
+ }
29203
+ else {
29204
+ stringValue = stringValue.slice(start);
29205
+ }
29206
+ let end = stringValue.length;
29207
+ while (stringValue[end - 1] === "0" && end > adjustedPointIndex) {
29208
+ end--;
29209
+ }
29210
+ // Only if there is 0 before the decimal point, keeps checking how many 0 there is after it and update the exponent accordingly.
29211
+ if (start === adjustedPointIndex + 1) {
29212
+ let cur = adjustedPointIndex;
29213
+ while (stringValue[cur] === "0" && cur < end) {
29214
+ cur++;
29215
+ exp--;
29216
+ }
29217
+ }
29218
+ try {
29219
+ stringValue = stringValue.slice(0, end);
29220
+ stringValue = stringValue + "0".repeat(Math.max(exp - stringValue.length, 0)); // add remaining zeros for cases like 3e30
29221
+ n = BigInt(stringValue);
29222
+ if (n === 0n) {
29223
+ decimal = 0;
29224
+ }
29225
+ else if (decimal === undefined) {
29226
+ decimal = Math.max(stringValue.length - Math.max(exp, 0), 0);
29227
+ }
29228
+ }
29229
+ catch {
29230
+ throw new InvalidNumericError(`Invalid numeric value: ${original}`);
29231
+ }
29232
+ }
29233
+ return { n, e: exp, s: sign, d: decimal };
29234
+ }
29235
+ function stringify(value) {
29236
+ if (value.n === 0n)
29237
+ return "0";
29238
+ const n = value.n.toString();
29239
+ const sign = value.s === -1 ? "-" : "";
29240
+ const int = value.e <= 0 ? "0" : n.slice(0, value.e);
29241
+ const decimal = value.e < n.length ? "." + n.slice(-value.d).padStart(value.d, "0") : "";
29242
+ return sign + int + decimal;
29243
+ }
29244
+ const equals = (a, b) => a.n === b.n && a.e === b.e;
29245
+ const compare = (a, b) => {
29246
+ if (a.s < b.s) {
29247
+ return -1;
29248
+ }
29249
+ else if (a.s > b.s) {
29250
+ return 1;
29251
+ }
29252
+ const neg = a.s;
29253
+ if (a.e < b.e) {
29254
+ return (-1 * neg);
29255
+ }
29256
+ else if (a.e > b.e) {
29257
+ return (1 * neg);
29258
+ }
29259
+ let aN = a.n;
29260
+ let bN = b.n;
29261
+ if (a.d < b.d) {
29262
+ aN *= 10n ** BigInt(b.d - a.d);
29263
+ }
29264
+ else {
29265
+ bN *= 10n ** BigInt(a.d - b.d);
29266
+ }
29267
+ if (aN < bN)
29268
+ return (-1 * neg);
29269
+ if (aN > bN)
29270
+ return (1 * neg);
29271
+ return 0;
29272
+ };
29273
+ const NumericPrototype = {
29274
+ toString: function () {
29275
+ return stringify(this[InternalDataSym]);
29276
+ },
29277
+ asNumber: function () {
29278
+ const num = Number(stringify(this[InternalDataSym]));
29279
+ return equals(this[InternalDataSym], Numeric(num.toString())[InternalDataSym]) ? num : null;
29280
+ },
29281
+ asBigInt: function () {
29282
+ if (!this.isInteger) {
29283
+ return null;
29284
+ }
29285
+ const { s, n } = this[InternalDataSym];
29286
+ return BigInt(s) * n;
29287
+ },
29288
+ equals: function (other) {
29289
+ return equals(this[InternalDataSym], other[InternalDataSym]);
29290
+ },
29291
+ lt: function (other) {
29292
+ return compare(this[InternalDataSym], other[InternalDataSym]) === -1;
29293
+ },
29294
+ lte: function (other) {
29295
+ return compare(this[InternalDataSym], other[InternalDataSym]) <= 0;
29296
+ },
29297
+ gt: function (other) {
29298
+ return compare(this[InternalDataSym], other[InternalDataSym]) === 1;
29299
+ },
29300
+ gte: function (other) {
29301
+ return compare(this[InternalDataSym], other[InternalDataSym]) >= 0;
29302
+ },
29303
+ };
29304
+ NumericPrototype.toString = function () {
29305
+ return stringify(this[InternalDataSym]);
29306
+ };
29307
+
29122
29308
  // Contains all intrinsic data setter or getter
29123
29309
  // Anything that the TypeSpec check might should be here.
29124
29310
  const stateKeys = {
@@ -29135,27 +29321,74 @@ const stateKeys = {
29135
29321
  errorsDocs: createStateSymbol("errorDocs"),
29136
29322
  discriminator: createStateSymbol("discriminator"),
29137
29323
  };
29324
+ // #region @minValue
29325
+ const [
29326
+ /** Get the min value for numeric or scalar types like date times */
29327
+ getMinValueRaw, setMinValue,] = useStateMap(stateKeys.minValues);
29328
+ /** Get the minimum value for a numeric type. If the value cannot be represented as a JS number(Overflow) undefined will be returned */
29138
29329
  function getMinValueAsNumeric(program, target) {
29139
- return program.stateMap(stateKeys.minValues).get(target);
29330
+ const value = getMinValueRaw(program, target);
29331
+ return isNumeric(value) ? value : undefined;
29140
29332
  }
29333
+ /**
29334
+ * Get the minimum value for a numeric type.
29335
+ * If the value cannot be represented as a JS number(Overflow) undefined will be returned
29336
+ * See {@link getMinValueAsNumeric} to get the precise value
29337
+ */
29141
29338
  function getMinValue(program, target) {
29142
29339
  return getMinValueAsNumeric(program, target)?.asNumber() ?? undefined;
29143
29340
  }
29341
+ // #endregion @minValue
29342
+ // #region @maxValue
29343
+ const [
29344
+ /** Get the max value for numeric or scalar types like date times */
29345
+ getMaxValueRaw, setMaxValue,] = useStateMap(stateKeys.maxValues);
29346
+ /** Get the maximum value for a numeric type. If the value cannot be represented as a JS number(Overflow) undefined will be returned */
29144
29347
  function getMaxValueAsNumeric(program, target) {
29145
- return program.stateMap(stateKeys.maxValues).get(target);
29348
+ const value = getMaxValueRaw(program, target);
29349
+ return isNumeric(value) ? value : undefined;
29146
29350
  }
29351
+ /**
29352
+ * Get the maximum value for a numeric type.
29353
+ * If the value cannot be represented as a JS number(Overflow) undefined will be returned
29354
+ * See {@link getMaxValueAsNumeric} to get the precise value
29355
+ */
29147
29356
  function getMaxValue(program, target) {
29148
29357
  return getMaxValueAsNumeric(program, target)?.asNumber() ?? undefined;
29149
29358
  }
29359
+ // #endregion @maxValue
29360
+ // #region @minValueExclusive
29361
+ const [
29362
+ /** Get the min value exclusive for numeric or scalar types like date times */
29363
+ getMinValueExclusiveRaw, setMinValueExclusive,] = useStateMap(stateKeys.minValueExclusive);
29364
+ /** Get the minimum value exclusive for a numeric type. If the value cannot be represented as a JS number(Overflow) undefined will be returned */
29150
29365
  function getMinValueExclusiveAsNumeric(program, target) {
29151
- return program.stateMap(stateKeys.minValueExclusive).get(target);
29366
+ const value = getMinValueExclusiveRaw(program, target);
29367
+ return isNumeric(value) ? value : undefined;
29152
29368
  }
29369
+ /**
29370
+ * Get the minimum value exclusive for a numeric type.
29371
+ * If the value cannot be represented as a JS number(Overflow) undefined will be returned
29372
+ * See {@link getMinValueExclusiveAsNumeric} to get the precise value
29373
+ */
29153
29374
  function getMinValueExclusive(program, target) {
29154
29375
  return getMinValueExclusiveAsNumeric(program, target)?.asNumber() ?? undefined;
29155
29376
  }
29377
+ // #endregion @minValueExclusive
29378
+ // #region @maxValueExclusive
29379
+ const [
29380
+ /** Get the max value exclusive for numeric or scalar types like date times */
29381
+ getMaxValueExclusiveRaw, setMaxValueExclusive,] = useStateMap(stateKeys.maxValueExclusive);
29382
+ /** Get the maximum value exclusive for a numeric type. If the value cannot be represented as a JS number(Overflow) undefined will be returned */
29156
29383
  function getMaxValueExclusiveAsNumeric(program, target) {
29157
- return program.stateMap(stateKeys.maxValueExclusive).get(target);
29384
+ const value = getMaxValueExclusiveRaw(program, target);
29385
+ return isNumeric(value) ? value : undefined;
29158
29386
  }
29387
+ /**
29388
+ * Get the maximum value exclusive for a numeric type.
29389
+ * If the value cannot be represented as a JS number(Overflow) undefined will be returned
29390
+ * See {@link getMaxValueExclusiveAsNumeric} to get the precise value
29391
+ */
29159
29392
  function getMaxValueExclusive(program, target) {
29160
29393
  return getMaxValueExclusiveAsNumeric(program, target)?.asNumber() ?? undefined;
29161
29394
  }
@@ -32304,186 +32537,6 @@ defineKit({
32304
32537
  },
32305
32538
  });
32306
32539
 
32307
- class InvalidNumericError extends Error {
32308
- code = "InvalidNumeric";
32309
- }
32310
- /** @internal */
32311
- const InternalDataSym = Symbol.for("NumericInternalData");
32312
- /**
32313
- * Represent any possible numeric value
32314
- */
32315
- function Numeric(stringValue) {
32316
- if (new.target) {
32317
- throw new Error("Numeric is not a constructor");
32318
- }
32319
- const data = parse(stringValue);
32320
- const isInteger = data.d === 0;
32321
- const obj = {
32322
- [InternalDataSym]: data,
32323
- isInteger,
32324
- };
32325
- // We are explicitly not using a class here due to version mismatch between the compiler and the runtime that could happen and break instanceof checks.
32326
- const numeric = setTypedProptotype(obj, NumericPrototype);
32327
- return Object.freeze(numeric);
32328
- }
32329
- function setTypedProptotype(obj, prototype) {
32330
- Object.setPrototypeOf(obj, prototype);
32331
- return obj;
32332
- }
32333
- function parse(original) {
32334
- let stringValue = original;
32335
- let start = 0;
32336
- let sign = 1;
32337
- let n;
32338
- let exp;
32339
- let decimal = undefined;
32340
- if (stringValue[0] === "-") {
32341
- start = 1;
32342
- sign = -1;
32343
- }
32344
- const second = stringValue[start + 1]?.toLowerCase();
32345
- if (stringValue[start] === "0" && (second === "b" || second === "x" || second === "o")) {
32346
- try {
32347
- n = BigInt(stringValue.slice(start));
32348
- exp = n.toString().length;
32349
- decimal = 0;
32350
- }
32351
- catch {
32352
- throw new InvalidNumericError(`Invalid numeric value: ${original}`);
32353
- }
32354
- }
32355
- else {
32356
- // Skip leading 0.
32357
- while (stringValue[start] === "0") {
32358
- start++;
32359
- }
32360
- const decimalPointIndex = stringValue.indexOf(".");
32361
- const adjustedPointIndex = decimalPointIndex - start;
32362
- // Decimal point?
32363
- if (decimalPointIndex !== -1) {
32364
- exp = adjustedPointIndex;
32365
- stringValue = stringValue.replace(".", "");
32366
- }
32367
- let i;
32368
- if ((i = stringValue.search(/e/i)) > 0) {
32369
- // Determine exponent.
32370
- if (exp === undefined) {
32371
- exp = i - start;
32372
- }
32373
- exp += Number(stringValue.slice(i + 1));
32374
- stringValue = stringValue.slice(start, i);
32375
- decimal = Math.max(stringValue.length - exp, 0);
32376
- }
32377
- else if (exp === undefined) {
32378
- // Integer.
32379
- exp = stringValue.length - start;
32380
- stringValue = stringValue.slice(start);
32381
- }
32382
- else {
32383
- stringValue = stringValue.slice(start);
32384
- }
32385
- let end = stringValue.length;
32386
- while (stringValue[end - 1] === "0" && end > adjustedPointIndex) {
32387
- end--;
32388
- }
32389
- // Only if there is 0 before the decimal point, keeps checking how many 0 there is after it and update the exponent accordingly.
32390
- if (start === adjustedPointIndex + 1) {
32391
- let cur = adjustedPointIndex;
32392
- while (stringValue[cur] === "0" && cur < end) {
32393
- cur++;
32394
- exp--;
32395
- }
32396
- }
32397
- try {
32398
- stringValue = stringValue.slice(0, end);
32399
- stringValue = stringValue + "0".repeat(Math.max(exp - stringValue.length, 0)); // add remaining zeros for cases like 3e30
32400
- n = BigInt(stringValue);
32401
- if (n === 0n) {
32402
- decimal = 0;
32403
- }
32404
- else if (decimal === undefined) {
32405
- decimal = Math.max(stringValue.length - Math.max(exp, 0), 0);
32406
- }
32407
- }
32408
- catch {
32409
- throw new InvalidNumericError(`Invalid numeric value: ${original}`);
32410
- }
32411
- }
32412
- return { n, e: exp, s: sign, d: decimal };
32413
- }
32414
- function stringify(value) {
32415
- if (value.n === 0n)
32416
- return "0";
32417
- const n = value.n.toString();
32418
- const sign = value.s === -1 ? "-" : "";
32419
- const int = value.e <= 0 ? "0" : n.slice(0, value.e);
32420
- const decimal = value.e < n.length ? "." + n.slice(-value.d).padStart(value.d, "0") : "";
32421
- return sign + int + decimal;
32422
- }
32423
- const equals = (a, b) => a.n === b.n && a.e === b.e;
32424
- const compare = (a, b) => {
32425
- if (a.s < b.s) {
32426
- return -1;
32427
- }
32428
- else if (a.s > b.s) {
32429
- return 1;
32430
- }
32431
- const neg = a.s;
32432
- if (a.e < b.e) {
32433
- return (-1 * neg);
32434
- }
32435
- else if (a.e > b.e) {
32436
- return (1 * neg);
32437
- }
32438
- let aN = a.n;
32439
- let bN = b.n;
32440
- if (a.d < b.d) {
32441
- aN *= 10n ** BigInt(b.d - a.d);
32442
- }
32443
- else {
32444
- bN *= 10n ** BigInt(a.d - b.d);
32445
- }
32446
- if (aN < bN)
32447
- return (-1 * neg);
32448
- if (aN > bN)
32449
- return (1 * neg);
32450
- return 0;
32451
- };
32452
- const NumericPrototype = {
32453
- toString: function () {
32454
- return stringify(this[InternalDataSym]);
32455
- },
32456
- asNumber: function () {
32457
- const num = Number(stringify(this[InternalDataSym]));
32458
- return equals(this[InternalDataSym], Numeric(num.toString())[InternalDataSym]) ? num : null;
32459
- },
32460
- asBigInt: function () {
32461
- if (!this.isInteger) {
32462
- return null;
32463
- }
32464
- const { s, n } = this[InternalDataSym];
32465
- return BigInt(s) * n;
32466
- },
32467
- equals: function (other) {
32468
- return equals(this[InternalDataSym], other[InternalDataSym]);
32469
- },
32470
- lt: function (other) {
32471
- return compare(this[InternalDataSym], other[InternalDataSym]) === -1;
32472
- },
32473
- lte: function (other) {
32474
- return compare(this[InternalDataSym], other[InternalDataSym]) <= 0;
32475
- },
32476
- gt: function (other) {
32477
- return compare(this[InternalDataSym], other[InternalDataSym]) === 1;
32478
- },
32479
- gte: function (other) {
32480
- return compare(this[InternalDataSym], other[InternalDataSym]) >= 0;
32481
- },
32482
- };
32483
- NumericPrototype.toString = function () {
32484
- return stringify(this[InternalDataSym]);
32485
- };
32486
-
32487
32540
  defineKit({
32488
32541
  value: {
32489
32542
  is(value) {
@@ -32555,6 +32608,9 @@ defineKit({
32555
32608
  isAssignableTo: createDiagnosable(function (source, target, diagnosticTarget) {
32556
32609
  return this.program.checker.isTypeAssignableTo(source, target, diagnosticTarget ?? source);
32557
32610
  }),
32611
+ isOfType: createDiagnosable(function (source, target, diagnosticTarget) {
32612
+ return this.program.checker.isValueOfType(source, target, diagnosticTarget ?? source);
32613
+ }),
32558
32614
  resolve: createDiagnosable(function (reference, kind) {
32559
32615
  const [value, diagnostics] = this.program.resolveTypeOrValueReference(reference);
32560
32616
  if (value && !isValue(value)) {
@@ -34384,7 +34440,7 @@ let manifest;
34384
34440
  try {
34385
34441
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
34386
34442
  // @ts-ignore
34387
- manifest = (await import('../manifest-TRRff3AQ.js')).default;
34443
+ manifest = (await import('../manifest-CzALiBr1.js')).default;
34388
34444
  }
34389
34445
  catch {
34390
34446
  const name = "../dist/manifest.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/html-program-viewer",
3
- "version": "0.76.0-dev.1",
3
+ "version": "0.76.0",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec library for emitting an html view of the program.",
6
6
  "homepage": "https://typespec.io",
@@ -36,7 +36,7 @@
36
36
  "!dist/test/**"
37
37
  ],
38
38
  "peerDependencies": {
39
- "@typespec/compiler": "^1.5.0"
39
+ "@typespec/compiler": "^1.6.0"
40
40
  },
41
41
  "dependencies": {
42
42
  "@fluentui/react-components": "~9.72.3",
@@ -54,7 +54,6 @@
54
54
  "@types/node": "~24.9.1",
55
55
  "@types/react": "~19.2.2",
56
56
  "@types/react-dom": "~19.2.2",
57
- "@typespec/compiler": "^1.5.0",
58
57
  "@vitejs/plugin-react": "~5.1.0",
59
58
  "@vitest/coverage-v8": "^4.0.4",
60
59
  "@vitest/ui": "^4.0.4",
@@ -66,6 +65,7 @@
66
65
  "vite-plugin-dts": "4.5.4",
67
66
  "vite-plugin-node-polyfills": "^0.24.0",
68
67
  "vitest": "^4.0.4",
68
+ "@typespec/compiler": "^1.6.0",
69
69
  "@typespec/react-components": "^0.57.0"
70
70
  },
71
71
  "scripts": {
@@ -1,6 +0,0 @@
1
- const manifest = {
2
- "version": "1.5.0",
3
- "commit": "26936583098495a9c2bc2fe09f8c47865c9b4d2d"
4
- };
5
-
6
- export { manifest as default };