@sparted/shared-library 1.1.0 → 1.1.2

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.
@@ -91,3 +91,10 @@ export type Content = {
91
91
  statuses: ContentStatuses;
92
92
  game?: Game;
93
93
  };
94
+ export declare const isGameMultipleChoiceQuestion: (game: Game) => game is MultipleChoiceQuestion;
95
+ export declare const isGameErrorText: (game: Game) => game is ErrorText;
96
+ export declare const isGameOpenQuestion: (game: Game) => game is OpenQuestion;
97
+ export declare const isGameNoInteraction: (game: Game) => game is NoInteraction;
98
+ export declare const isGamePictureSpot: (game: Game) => game is PictureSpot;
99
+ export declare const isGameOrderingCards: (game: Game) => game is OrderingCards;
100
+ export declare const isGameSwipingCards: (game: Game) => game is SwipingCards;
@@ -10,7 +10,21 @@ const GAME_TYPE = {
10
10
  PICTURE_SPOT: 'picture-spot',
11
11
  ORDERING_CARDS: 'ordering-cards',
12
12
  SWIPING_CARDS: 'swiping-cards',
13
- };
13
+ };
14
+ const isGameMultipleChoiceQuestion = (game) => game.type === GAME_TYPE.MCQ;
15
+ const isGameErrorText = (game) => game.type === GAME_TYPE.ERROR_TEXT;
16
+ const isGameOpenQuestion = (game) => game.type === GAME_TYPE.OPEN_QUESTION;
17
+ const isGameNoInteraction = (game) => game.type === GAME_TYPE.NO_INTERACTION;
18
+ const isGamePictureSpot = (game) => game.type === GAME_TYPE.PICTURE_SPOT;
19
+ const isGameOrderingCards = (game) => game.type === GAME_TYPE.ORDERING_CARDS;
20
+ const isGameSwipingCards = (game) => game.type === GAME_TYPE.SWIPING_CARDS;
14
21
 
15
22
  exports.GAME_TYPE = GAME_TYPE;
23
+ exports.isGameErrorText = isGameErrorText;
24
+ exports.isGameMultipleChoiceQuestion = isGameMultipleChoiceQuestion;
25
+ exports.isGameNoInteraction = isGameNoInteraction;
26
+ exports.isGameOpenQuestion = isGameOpenQuestion;
27
+ exports.isGameOrderingCards = isGameOrderingCards;
28
+ exports.isGamePictureSpot = isGamePictureSpot;
29
+ exports.isGameSwipingCards = isGameSwipingCards;
16
30
  //# sourceMappingURL=content.js.map
@@ -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: 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;;;;;"}
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\nexport const isGameMultipleChoiceQuestion = (game: Game): game is MultipleChoiceQuestion => game.type === GAME_TYPE.MCQ;\nexport const isGameErrorText = (game: Game): game is ErrorText => game.type === GAME_TYPE.ERROR_TEXT;\nexport const isGameOpenQuestion = (game: Game): game is OpenQuestion => game.type === GAME_TYPE.OPEN_QUESTION;\nexport const isGameNoInteraction = (game: Game): game is NoInteraction => game.type === GAME_TYPE.NO_INTERACTION;\nexport const isGamePictureSpot = (game: Game): game is PictureSpot => game.type === GAME_TYPE.PICTURE_SPOT;\nexport const isGameOrderingCards = (game: Game): game is OrderingCards => game.type === GAME_TYPE.ORDERING_CARDS;\nexport const isGameSwipingCards = (game: Game): game is SwipingCards => game.type === GAME_TYPE.SWIPING_CARDS;\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;EAC9B;AAqBW,MAAA,4BAA4B,GAAG,CAAC,IAAU,KAAqC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI;AAC3G,MAAA,eAAe,GAAG,CAAC,IAAU,KAAwB,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,WAAW;AACxF,MAAA,kBAAkB,GAAG,CAAC,IAAU,KAA2B,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,cAAc;AACjG,MAAA,mBAAmB,GAAG,CAAC,IAAU,KAA4B,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,eAAe;AACpG,MAAA,iBAAiB,GAAG,CAAC,IAAU,KAA0B,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,aAAa;AAC9F,MAAA,mBAAmB,GAAG,CAAC,IAAU,KAA4B,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,eAAe;AACpG,MAAA,kBAAkB,GAAG,CAAC,IAAU,KAA2B,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;;;;;;;;;;;"}
@@ -8,5 +8,12 @@ var multilingual = require('./multilingual.js');
8
8
 
9
9
 
10
10
  exports.GAME_TYPE = content.GAME_TYPE;
11
+ exports.isGameErrorText = content.isGameErrorText;
12
+ exports.isGameMultipleChoiceQuestion = content.isGameMultipleChoiceQuestion;
13
+ exports.isGameNoInteraction = content.isGameNoInteraction;
14
+ exports.isGameOpenQuestion = content.isGameOpenQuestion;
15
+ exports.isGameOrderingCards = content.isGameOrderingCards;
16
+ exports.isGamePictureSpot = content.isGamePictureSpot;
17
+ exports.isGameSwipingCards = content.isGameSwipingCards;
11
18
  exports.Languages = multilingual.Languages;
12
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -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;;;;"}
@@ -0,0 +1 @@
1
+ export * from './get-contrast-color';
package/color/index.js ADDED
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var getContrastColor = require('./get-contrast-color.js');
6
+
7
+
8
+
9
+ exports.getContrastColor = getContrastColor.getContrastColor;
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
package/index.d.ts CHANGED
@@ -12,3 +12,4 @@ export * from './predicates';
12
12
  export * from './promise';
13
13
  export * from './string';
14
14
  export * from './types';
15
+ export * from './color';
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparted/shared-library",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "repository": "git@github.com:Sparted/shared-library.git",
5
5
  "author": {
6
6
  "name": "Sparted",