@sparted/shared-library 1.1.0-rc7 → 1.1.1
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/business/types/content.d.ts +1 -17
- package/business/types/content.js.map +1 -1
- package/color/get-contrast-color.d.ts +1 -0
- package/color/get-contrast-color.js +21 -0
- package/color/get-contrast-color.js.map +1 -0
- package/color/index.d.ts +1 -0
- package/color/index.js +10 -0
- package/color/index.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -73,23 +73,7 @@ export type SwipingCards = {
|
|
|
73
73
|
};
|
|
74
74
|
export type Game = ErrorText | MultipleChoiceQuestion | NoInteraction | OpenQuestion | OrderingCards | PictureSpot | SwipingCards;
|
|
75
75
|
export type GameType = 'error-text' | 'mcq' | 'open-question' | 'no-interaction' | 'picture-spot' | 'swiping-cards' | 'ordering-cards';
|
|
76
|
-
export declare const GAME_TYPE:
|
|
77
|
-
readonly MCQ: "mcq";
|
|
78
|
-
readonly ERROR_TEXT: "error-text";
|
|
79
|
-
readonly OPEN_QUESTION: "open-question";
|
|
80
|
-
readonly NO_INTERACTION: "no-interaction";
|
|
81
|
-
readonly PICTURE_SPOT: "picture-spot";
|
|
82
|
-
readonly ORDERING_CARDS: "ordering-cards";
|
|
83
|
-
readonly SWIPING_CARDS: "swiping-cards";
|
|
84
|
-
};
|
|
85
|
-
export type BaseContent = {
|
|
86
|
-
id: number;
|
|
87
|
-
identifier: string;
|
|
88
|
-
name: MultilingualLabel;
|
|
89
|
-
thematic: Thematic;
|
|
90
|
-
coverImage?: Image;
|
|
91
|
-
status: string;
|
|
92
|
-
};
|
|
76
|
+
export declare const GAME_TYPE: Record<string, GameType>;
|
|
93
77
|
export type ContentStatuses = Partial<{
|
|
94
78
|
[languageCode in LanguageCode]: 'draft' | 'validated' | 'waiting-translation' | 'waiting-validation';
|
|
95
79
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","sources":["../../../src/business/types/content.ts"],"sourcesContent":["import { LanguageCode, MultilingualLabel } from './multilingual';\nimport { Image, Media } from './media';\nimport { Thematic } from './thematic';\n\nexport type ErrorText = {\n type: 'error-text';\n gameMedia?: Media;\n explanationMedia?: Media;\n explanation?: MultilingualLabel;\n wrongText?: MultilingualLabel;\n correctText?: MultilingualLabel;\n};\n\nexport type MultipleChoiceQuestion = {\n type: 'mcq';\n gameMedia?: Media;\n question?: MultilingualLabel;\n explanation?: MultilingualLabel;\n explanationMedia?: Media;\n multiselect?: boolean;\n choices?: {\n correct: boolean;\n text: MultilingualLabel;\n }[];\n};\n\nexport type NoInteraction = {\n type: 'no-interaction';\n firstMedia?: Media;\n secondMedia?: Media;\n title?: MultilingualLabel;\n text?: MultilingualLabel;\n};\n\nexport type OpenQuestion = {\n type: 'open-question';\n gameMedia?: Media;\n question?: MultilingualLabel;\n answer?: MultilingualLabel;\n explanation?: MultilingualLabel;\n explanationMedia?: Media;\n levenshteinDistance?: number;\n};\n\nexport type OrderingCards = {\n type: 'ordering-cards';\n explanation?: MultilingualLabel;\n question?: MultilingualLabel;\n topLabel?: MultilingualLabel;\n bottomLabel?: MultilingualLabel;\n cards: MultilingualLabel[];\n};\n\nexport type PictureSpot = {\n type: 'picture-spot';\n image?: Image;\n explanation?: MultilingualLabel;\n items?: {\n x: number;\n y: number;\n r: number;\n question: MultilingualLabel;\n description: MultilingualLabel;\n }[];\n};\n\nexport type SwipingCards = {\n type: 'swiping-cards';\n explanation?: MultilingualLabel;\n question?: MultilingualLabel;\n zones?: {\n position: 'left' | 'right' | 'top' | 'bottom';\n text: MultilingualLabel;\n }[];\n cards?: {\n image?: Image;\n text?: MultilingualLabel;\n answer: 'left' | 'right' | 'top' | 'bottom';\n }[];\n};\n\nexport type Game =\n | ErrorText\n | MultipleChoiceQuestion\n | NoInteraction\n | OpenQuestion\n | OrderingCards\n | PictureSpot\n | SwipingCards;\n\nexport type GameType =\n | 'error-text'\n | 'mcq'\n | 'open-question'\n | 'no-interaction'\n | 'picture-spot'\n | 'swiping-cards'\n | 'ordering-cards';\n\nexport const GAME_TYPE = {\n MCQ: 'mcq',\n ERROR_TEXT: 'error-text',\n OPEN_QUESTION: 'open-question',\n NO_INTERACTION: 'no-interaction',\n PICTURE_SPOT: 'picture-spot',\n ORDERING_CARDS: 'ordering-cards',\n SWIPING_CARDS: 'swiping-cards',\n}
|
|
1
|
+
{"version":3,"file":"content.js","sources":["../../../src/business/types/content.ts"],"sourcesContent":["import { LanguageCode, MultilingualLabel } from './multilingual';\nimport { Image, Media } from './media';\nimport { Thematic } from './thematic';\n\nexport type ErrorText = {\n type: 'error-text';\n gameMedia?: Media;\n explanationMedia?: Media;\n explanation?: MultilingualLabel;\n wrongText?: MultilingualLabel;\n correctText?: MultilingualLabel;\n};\n\nexport type MultipleChoiceQuestion = {\n type: 'mcq';\n gameMedia?: Media;\n question?: MultilingualLabel;\n explanation?: MultilingualLabel;\n explanationMedia?: Media;\n multiselect?: boolean;\n choices?: {\n correct: boolean;\n text: MultilingualLabel;\n }[];\n};\n\nexport type NoInteraction = {\n type: 'no-interaction';\n firstMedia?: Media;\n secondMedia?: Media;\n title?: MultilingualLabel;\n text?: MultilingualLabel;\n};\n\nexport type OpenQuestion = {\n type: 'open-question';\n gameMedia?: Media;\n question?: MultilingualLabel;\n answer?: MultilingualLabel;\n explanation?: MultilingualLabel;\n explanationMedia?: Media;\n levenshteinDistance?: number;\n};\n\nexport type OrderingCards = {\n type: 'ordering-cards';\n explanation?: MultilingualLabel;\n question?: MultilingualLabel;\n topLabel?: MultilingualLabel;\n bottomLabel?: MultilingualLabel;\n cards: MultilingualLabel[];\n};\n\nexport type PictureSpot = {\n type: 'picture-spot';\n image?: Image;\n explanation?: MultilingualLabel;\n items?: {\n x: number;\n y: number;\n r: number;\n question: MultilingualLabel;\n description: MultilingualLabel;\n }[];\n};\n\nexport type SwipingCards = {\n type: 'swiping-cards';\n explanation?: MultilingualLabel;\n question?: MultilingualLabel;\n zones?: {\n position: 'left' | 'right' | 'top' | 'bottom';\n text: MultilingualLabel;\n }[];\n cards?: {\n image?: Image;\n text?: MultilingualLabel;\n answer: 'left' | 'right' | 'top' | 'bottom';\n }[];\n};\n\nexport type Game =\n | ErrorText\n | MultipleChoiceQuestion\n | NoInteraction\n | OpenQuestion\n | OrderingCards\n | PictureSpot\n | SwipingCards;\n\nexport type GameType =\n | 'error-text'\n | 'mcq'\n | 'open-question'\n | 'no-interaction'\n | 'picture-spot'\n | 'swiping-cards'\n | 'ordering-cards';\n\nexport const GAME_TYPE: Record<string, GameType> = {\n MCQ: 'mcq',\n ERROR_TEXT: 'error-text',\n OPEN_QUESTION: 'open-question',\n NO_INTERACTION: 'no-interaction',\n PICTURE_SPOT: 'picture-spot',\n ORDERING_CARDS: 'ordering-cards',\n SWIPING_CARDS: 'swiping-cards',\n};\n\nexport type ContentStatuses = Partial<{\n [languageCode in LanguageCode]: 'draft' | 'validated' | 'waiting-translation' | 'waiting-validation';\n}>;\n\nexport type Content = {\n archived: boolean;\n id: number;\n metadata: {\n coverImage: Image;\n identifier?: string;\n name: MultilingualLabel;\n thematic: Thematic;\n explanation?: string;\n knowMore?: string;\n };\n statuses: ContentStatuses;\n game?: Game;\n};\n"],"names":[],"mappings":";;;;AAmGa,MAAA,SAAS,GAA6B;AACjD,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,UAAU,EAAE,YAAY;AACxB,IAAA,aAAa,EAAE,eAAe;AAC9B,IAAA,cAAc,EAAE,gBAAgB;AAChC,IAAA,YAAY,EAAE,cAAc;AAC5B,IAAA,cAAc,EAAE,gBAAgB;AAChC,IAAA,aAAa,EAAE,eAAe;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getContrastColor: (bgColor: string, lightColor?: string, darkColor?: string) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const DEFAULT_LIGHT_COLOR = '#FFFFFF';
|
|
6
|
+
const DEFAULT_DARK_COLOR = '#000000';
|
|
7
|
+
// Based on https://stackoverflow.com/questions/11867545/change-text-color-based-on-brightness-of-the-covered-background-area
|
|
8
|
+
const getContrastColor = (bgColor, lightColor = DEFAULT_LIGHT_COLOR, darkColor = DEFAULT_DARK_COLOR) => {
|
|
9
|
+
const color = bgColor.charAt(0) === '#' ? bgColor.substring(1, 7) : bgColor;
|
|
10
|
+
if (color.length !== 6) {
|
|
11
|
+
throw new Error(`Invalid HEX color "${bgColor}" in sparted mail manager.`);
|
|
12
|
+
}
|
|
13
|
+
const r = parseInt(color.substring(0, 2), 16); // hexToR
|
|
14
|
+
const g = parseInt(color.substring(2, 4), 16); // hexToG
|
|
15
|
+
const b = parseInt(color.substring(4, 6), 16); // hexToB
|
|
16
|
+
// Values from https://www.w3.org/TR/AERT/#color-contrast
|
|
17
|
+
return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? darkColor : lightColor;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.getContrastColor = getContrastColor;
|
|
21
|
+
//# sourceMappingURL=get-contrast-color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-contrast-color.js","sources":["../../src/color/get-contrast-color.ts"],"sourcesContent":["const DEFAULT_LIGHT_COLOR = '#FFFFFF';\nconst DEFAULT_DARK_COLOR = '#000000';\n\n// Based on https://stackoverflow.com/questions/11867545/change-text-color-based-on-brightness-of-the-covered-background-area\nexport const getContrastColor = (bgColor: string, lightColor: string = DEFAULT_LIGHT_COLOR, darkColor: string = DEFAULT_DARK_COLOR): string => {\n const color = bgColor.charAt(0) === '#' ? bgColor.substring(1, 7) : bgColor;\n\n if (color.length !== 6) {\n throw new Error(`Invalid HEX color \"${bgColor}\" in sparted mail manager.`);\n }\n\n const r = parseInt(color.substring(0, 2), 16); // hexToR\n const g = parseInt(color.substring(2, 4), 16); // hexToG\n const b = parseInt(color.substring(4, 6), 16); // hexToB\n\n // Values from https://www.w3.org/TR/AERT/#color-contrast\n return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? darkColor : lightColor;\n};\n"],"names":[],"mappings":";;;;AAAA,MAAM,mBAAmB,GAAG,SAAS,CAAC;AACtC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAErC;AACO,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,UAAA,GAAqB,mBAAmB,EAAE,SAAoB,GAAA,kBAAkB,KAAY;IAC5I,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC;AAE5E,IAAA,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;AACtB,QAAA,MAAM,IAAI,KAAK,CAAC,sBAAsB,OAAO,CAAA,0BAAA,CAA4B,CAAC,CAAC;AAC5E,KAAA;AAED,IAAA,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9C,IAAA,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9C,IAAA,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;;IAG9C,OAAO,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,GAAG,GAAG,SAAS,GAAG,UAAU,CAAC;AAC1E;;;;"}
|
package/color/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './get-contrast-color';
|
package/color/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -37,6 +37,7 @@ var executeWithDelay = require('./promise/execute-with-delay.js');
|
|
|
37
37
|
var delay = require('./promise/delay.js');
|
|
38
38
|
var replaceInTemplate = require('./string/replace-in-template.js');
|
|
39
39
|
var isStringLengthWithinRange = require('./string/is-string-length-within-range.js');
|
|
40
|
+
var getContrastColor = require('./color/get-contrast-color.js');
|
|
40
41
|
|
|
41
42
|
|
|
42
43
|
|
|
@@ -82,4 +83,5 @@ exports.executeWithDelay = executeWithDelay.executeWithDelay;
|
|
|
82
83
|
exports.delay = delay.delay;
|
|
83
84
|
exports.replaceInTemplate = replaceInTemplate.replaceInTemplate;
|
|
84
85
|
exports.isStringLengthWithinRange = isStringLengthWithinRange.isStringLengthWithinRange;
|
|
86
|
+
exports.getContrastColor = getContrastColor.getContrastColor;
|
|
85
87
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|