Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(typechecking): typecheck /lib #1138

Merged
merged 18 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
eff4bce
chore(typechecking): add typechecking on fake-string.js
pdesoyres-cc Jul 29, 2024
9743d18
chore(typechecking): add typechecking on animate.js
pdesoyres-cc Jul 29, 2024
c640195
chore(typechecking): add typechecking on buffer.js
pdesoyres-cc Jul 29, 2024
422c331
chore(typechecking): fix typechecking on clipboard.js
pdesoyres-cc Jul 29, 2024
e69e248
chore(typechecking): fix typechecking on color.js
pdesoyres-cc Jul 29, 2024
c14884e
chore(typechecking): fix typechecking on date utils
pdesoyres-cc Jul 29, 2024
cc7b97d
chore(typechecking): fix typechecking on ansi utils
pdesoyres-cc Jul 29, 2024
425255f
chore(typechecking): fix typechecking on dom.js
pdesoyres-cc Jul 29, 2024
0baf1a2
chore(typechecking): add ts-nocheck directive to immer.js
pdesoyres-cc Jul 29, 2024
42d4c4b
chore(typechecking): fix typechecking on memory-cache.js
pdesoyres-cc Jul 29, 2024
735a684
chore(typechecking): fix typechecking on notifications.js
pdesoyres-cc Jul 29, 2024
4386686
chore(typechecking): fix typechecking on shadow-dom-utils.js
pdesoyres-cc Jul 29, 2024
37cc3a9
chore(typechecking): fix typechecking on remote-assets.js
pdesoyres-cc Jul 29, 2024
bc5f184
chore(typechecking): fix typechecking on xml-parser.js
pdesoyres-cc Jul 31, 2024
7fe229f
chore(typechecking): fix typechecking on api-helpers.js
pdesoyres-cc Jul 31, 2024
bb87473
chore(typechecking): fix typechecking on smart
pdesoyres-cc Jul 31, 2024
06a1012
chore(typechecking): include almost all src/lib/* to ci typecheck
pdesoyres-cc Sep 9, 2024
6917821
chore(typecheck:stats): take into account the excluded patterns
pdesoyres-cc Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/components/cc-tile-instances/cc-tile-instances.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,25 @@ export class CcTileInstances extends LitElement {
if (this._lastRunningCount !== runningInstancesCount) {
this.updateComplete.then(() => {
// This is not supported in Safari yet, but it's purely decorative so let's keep it like that
animate(this.shadowRoot, '.instances[data-type=running] .count-bubble', ...QUICK_SHRINK);
animate(
this.shadowRoot,
'.instances[data-type=running] .count-bubble',
QUICK_SHRINK.keyframes,
QUICK_SHRINK.options,
);
this._lastRunningCount = runningInstancesCount;
});
}

if (this._lastDeployingCount !== deployingInstancesCount) {
this.updateComplete.then(() => {
// This is not supported in Safari yet, but it's purely decorative so let's keep it like that
animate(this.shadowRoot, '.instances[data-type=deploying] .count-bubble', ...QUICK_SHRINK);
animate(
this.shadowRoot,
'.instances[data-type=deploying] .count-bubble',
QUICK_SHRINK.keyframes,
QUICK_SHRINK.options,
);
this._lastDeployingCount = deployingInstancesCount;
});
}
Expand Down
14 changes: 13 additions & 1 deletion src/components/common.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ interface InvoiceAmount {
export interface Invoice {
downloadUrl: string;
emissionDate: string;
invoiceHtml: string;
invoiceHtml?: string;
number: string;
paymentUrl: string;
status: InvoiceStatusType;
Expand Down Expand Up @@ -214,3 +214,15 @@ interface EnvVarEditorStateLoaded {
/* endregion */

export type NotificationIntent = 'info' | 'success' | 'warning' | 'danger';

export interface Notification {
message: string | Node;
title?: string;
intent: NotificationIntent;
options?: NotificationOptions;
}

export interface NotificationOptions {
timeout?: number;
closeable?: boolean;
}
15 changes: 11 additions & 4 deletions src/lib/animate.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
/**
*
* @param {ShadowRoot} shadowRoot
* @param {string} selector
* @param {Array<Keyframe> | PropertyIndexedKeyframes} keyframes
* @param {number | KeyframeAnimationOptions} options
*/
export function animate(shadowRoot, selector, keyframes, options) {
Array.from(shadowRoot.querySelectorAll(selector)).forEach((element) => element.animate(keyframes, options));
}

export const QUICK_SHRINK = [
[{ transform: 'scale(1)' }, { transform: 'scale(0.9)' }, { transform: 'scale(1)' }],
{
export const QUICK_SHRINK = {
keyframes: [{ transform: 'scale(1)' }, { transform: 'scale(0.9)' }, { transform: 'scale(1)' }],
options: {
duration: 200,
easing: 'ease-in-out',
},
];
};
18 changes: 15 additions & 3 deletions src/lib/ansi/ansi-palette-analyser.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { getContrastRatio, hexToRgb, isDark } from '../color.js';

const colors = ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan'];
/**
* @typedef {import('./ansi.types.js').AnsiPalette} AnsiPalette
* @typedef {keyof AnsiPalette} ColorsType
*/

/** @type {Array<ColorsType>} */
const COLORS = ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan'];

/**
*
* @param {AnsiPalette} palette
*/
export function analyzePalette(palette) {
const background = hexToRgb(palette.background);
/** @type {Array<ColorsType>} */
const colorsToTest = getColorsToTest(isDark(background));

const colorsCount = colorsToTest.length;
let ratioSum = 0;
let compliantCount = 0;

/** @type {Partial<Record<ColorsType, { ratio: number, compliant: boolean }>>} */
const contrasts = {};

colorsToTest.forEach((colorName) => {
Expand All @@ -34,8 +41,13 @@ export function analyzePalette(palette) {
};
}

/**
* @param {boolean} isDarkPalette
* @return {Array<ColorsType>}
*/
function getColorsToTest(isDarkPalette) {
const result = [...colors, isDarkPalette ? 'white' : 'black'];
const result = [...COLORS, isDarkPalette ? 'white' : 'black'];

// @ts-ignore
pdesoyres-cc marked this conversation as resolved.
Show resolved Hide resolved
return [...result, ...result.map((c) => `bright-${c}`)];
}
32 changes: 28 additions & 4 deletions src/lib/ansi/ansi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import ansiRegEx from 'ansi-regex';
import { css, html, unsafeCSS } from 'lit';
import { MemoryCache } from '../memory-cache.js';

/**
* @typedef {import('./ansi.types.js').AnsiPart} AnsiPart
*/

/** @type {AnsiParser} - Lazy loaded parser */
let ansiParser;

Expand Down Expand Up @@ -134,7 +138,7 @@ ANSI_COLORS.forEach((style) => {

/**
* Remove all ANSI escape codes from the given text.
* @param text
* @param {string} text
* @return {string}
*/
export function stripAnsi(text) {
Expand All @@ -145,14 +149,16 @@ export function stripAnsi(text) {
* Converts the given text into Lit template according to the ANSI escape codes found in text.
*
* When using this, don't forget to include the `ansiPaletteStyle` CSS rules to a parent element. (see ./ansi-palette-style)
*
* @param {string} text
*/
export function ansiToLit(text) {
if (ansiParser == null) {
ansiParser = new AnsiParser();
}

const tokens = ansiParser.parse(text);
return tokens.map((token, i) => {
return tokens.map((token) => {
if (token.styles.length === 0) {
return token.text;
}
Expand Down Expand Up @@ -232,6 +238,11 @@ class AnsiParser {
/** @type {Map<string, Set<string>>} */
const commonEscapes = new Map();

/**
* @param {string} name
* @param {string} code
* @param {Array<string>} escapes
*/
const handleCode = (name, code, escapes) => {
const ansiCode = toAnsi(code);
this.codeToStyle.set(ansiCode, name);
Expand Down Expand Up @@ -261,15 +272,15 @@ class AnsiParser {
}

/**
* @param str
* @param {string} str
* @return {Array<AnsiPart>}
*/
parse(str) {
return this.cache.get(str);
}

/**
* @param str
* @param {string} str
* @return {Array<AnsiPart>}
*/
_doParse(str) {
Expand Down Expand Up @@ -329,17 +340,30 @@ function addToIndexMap(map, key, value) {
map.get(key).add(value);
}

/**
* @param {Array<T>} arr
* @param {T} val
* @template T
*/
function removeElm(arr, val) {
const i = arr.indexOf(val);
if (i >= 0) {
arr.splice(i, 1);
}
}

/**
* @param {string|number} code
* @return {string}
*/
function toAnsi(code) {
return `\u001b[${code}m`;
}

/**
* @param {string} ansiCode
* @return {string}
*/
function fromAnsi(ansiCode) {
return ansiCode.slice(2, ansiCode.length - 1);
}
Loading
Loading