From ee70e0014e069cad3f4e177ee0cb819fdf4794ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20K=C3=BChner?= Date: Wed, 23 Aug 2023 23:24:57 +0200 Subject: [PATCH] fix: add .js to imports so they work within browsers (#240) --- package.json | 5 ++++- src/conversion.ts | 4 ++-- src/format-input.ts | 14 ++++++++++---- src/from-ratio.ts | 6 +++--- src/index.ts | 8 ++++---- src/public_api.ts | 20 ++++++++++---------- src/random.ts | 4 ++-- src/readability.ts | 2 +- src/to-ms-filter.ts | 4 ++-- src/umd_api.ts | 14 +++++++------- 10 files changed, 45 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index e39dd41..83ec862 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,10 @@ }, "jest": { "testEnvironment": "node", - "coverageProvider": "v8" + "coverageProvider": "v8", + "moduleNameMapper": { + "(.+)\\.js": "$1" + } }, "babel": { "presets": [ diff --git a/src/conversion.ts b/src/conversion.ts index 606417e..1a03391 100644 --- a/src/conversion.ts +++ b/src/conversion.ts @@ -1,5 +1,5 @@ -import { HSL, HSV, Numberify, RGB } from './interfaces'; -import { bound01, pad2 } from './util'; +import { HSL, HSV, Numberify, RGB } from './interfaces.js'; +import { bound01, pad2 } from './util.js'; // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from: // diff --git a/src/format-input.ts b/src/format-input.ts index 86d78d5..1be137a 100644 --- a/src/format-input.ts +++ b/src/format-input.ts @@ -1,8 +1,14 @@ /* eslint-disable @typescript-eslint/no-redundant-type-constituents */ -import { convertHexToDecimal, hslToRgb, hsvToRgb, parseIntFromHex, rgbToRgb } from './conversion'; -import { names } from './css-color-names'; -import { HSL, HSLA, HSV, HSVA, RGB, RGBA } from './interfaces'; -import { boundAlpha, convertToPercentage } from './util'; +import { + convertHexToDecimal, + hslToRgb, + hsvToRgb, + parseIntFromHex, + rgbToRgb, +} from './conversion.js'; +import { names } from './css-color-names.js'; +import { HSL, HSLA, HSV, HSVA, RGB, RGBA } from './interfaces.js'; +import { boundAlpha, convertToPercentage } from './util.js'; /** * Given a string or object, convert that input to RGB diff --git a/src/from-ratio.ts b/src/from-ratio.ts index 7b435b9..79d7078 100644 --- a/src/from-ratio.ts +++ b/src/from-ratio.ts @@ -1,6 +1,6 @@ -import { TinyColor } from './index'; -import { RGBA } from './interfaces'; -import { convertToPercentage } from './util'; +import { TinyColor } from './index.js'; +import { RGBA } from './interfaces.js'; +import { convertToPercentage } from './util.js'; export interface RatioInput { r: number | string; diff --git a/src/index.ts b/src/index.ts index 0cab201..a64bf3a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ -import { numberInputToObject, rgbaToHex, rgbToHex, rgbToHsl, rgbToHsv } from './conversion'; -import { names } from './css-color-names'; +import { numberInputToObject, rgbaToHex, rgbToHex, rgbToHsl, rgbToHsv } from './conversion.js'; +import { names } from './css-color-names.js'; import { inputToRGB } from './format-input'; -import { HSL, HSLA, HSV, HSVA, Numberify, RGB, RGBA } from './interfaces'; -import { bound01, boundAlpha, clamp01 } from './util'; +import { HSL, HSLA, HSV, HSVA, Numberify, RGB, RGBA } from './interfaces.js'; +import { bound01, boundAlpha, clamp01 } from './util.js'; export interface TinyColorOptions { format: string; diff --git a/src/public_api.ts b/src/public_api.ts index 5756271..2745b01 100644 --- a/src/public_api.ts +++ b/src/public_api.ts @@ -1,13 +1,13 @@ -import { tinycolor } from './index'; -export * from './index'; -export * from './css-color-names'; -export * from './readability'; -export * from './to-ms-filter'; -export * from './from-ratio'; -export * from './format-input'; -export * from './random'; -export * from './interfaces'; -export * from './conversion'; +import { tinycolor } from './index.js'; +export * from './index.js'; +export * from './css-color-names.js'; +export * from './readability.js'; +export * from './to-ms-filter.js'; +export * from './from-ratio.js'; +export * from './format-input.js'; +export * from './random.js'; +export * from './interfaces.js'; +export * from './conversion.js'; // kept for backwards compatability with v1 export default tinycolor; diff --git a/src/random.ts b/src/random.ts index 4906faa..4817001 100644 --- a/src/random.ts +++ b/src/random.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/no-redundant-type-constituents */ // randomColor by David Merfield under the CC0 license // https://github.com/davidmerfield/randomColor/ -import { TinyColor } from './index'; -import { HSVA } from './interfaces'; +import { TinyColor } from './index.js'; +import { HSVA } from './interfaces.js'; export interface RandomOptions { seed?: number; diff --git a/src/readability.ts b/src/readability.ts index 855163a..9482fe4 100644 --- a/src/readability.ts +++ b/src/readability.ts @@ -1,4 +1,4 @@ -import { ColorInput, TinyColor } from './index'; +import { ColorInput, TinyColor } from './index.js'; // Readability Functions // --------------------- diff --git a/src/to-ms-filter.ts b/src/to-ms-filter.ts index f99a21d..15c5344 100644 --- a/src/to-ms-filter.ts +++ b/src/to-ms-filter.ts @@ -1,5 +1,5 @@ -import { rgbaToArgbHex } from './conversion'; -import { ColorInput, TinyColor } from './index'; +import { rgbaToArgbHex } from './conversion.js'; +import { ColorInput, TinyColor } from './index.js'; /** * Returns the color represented as a Microsoft filter for use in old versions of IE. */ diff --git a/src/umd_api.ts b/src/umd_api.ts index 24f0ce7..7129b0e 100644 --- a/src/umd_api.ts +++ b/src/umd_api.ts @@ -1,10 +1,10 @@ -import { names } from './css-color-names'; -import { inputToRGB, isValidCSSUnit, stringInputToObject } from './format-input'; -import { fromRatio, legacyRandom } from './from-ratio'; -import { TinyColor, tinycolor } from './index'; -import { random } from './random'; -import { mostReadable, readability } from './readability'; -import { toMsFilter } from './to-ms-filter'; +import { names } from './css-color-names.js'; +import { inputToRGB, isValidCSSUnit, stringInputToObject } from './format-input.js'; +import { fromRatio, legacyRandom } from './from-ratio.js'; +import { TinyColor, tinycolor } from './index.js'; +import { random } from './random.js'; +import { mostReadable, readability } from './readability.js'; +import { toMsFilter } from './to-ms-filter.js'; export interface TinyColorUMD { (): TinyColor;