@chayns-components/typewriter 5.0.0-beta.97 → 5.0.0-beta.970

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.
Files changed (47) hide show
  1. package/README.md +4 -15
  2. package/lib/cjs/components/typewriter/AnimatedTypewriterText.js +59 -0
  3. package/lib/cjs/components/typewriter/AnimatedTypewriterText.js.map +1 -0
  4. package/lib/cjs/components/typewriter/Typewriter.js +273 -0
  5. package/lib/cjs/components/typewriter/Typewriter.js.map +1 -0
  6. package/lib/cjs/components/typewriter/Typewriter.styles.js +96 -0
  7. package/lib/cjs/components/typewriter/Typewriter.styles.js.map +1 -0
  8. package/lib/{components → cjs/components}/typewriter/utils.js +43 -3
  9. package/lib/cjs/components/typewriter/utils.js.map +1 -0
  10. package/lib/cjs/index.js +34 -0
  11. package/lib/cjs/index.js.map +1 -0
  12. package/lib/cjs/types/cursor.js +12 -0
  13. package/lib/cjs/types/cursor.js.map +1 -0
  14. package/lib/cjs/types/speed.js +25 -0
  15. package/lib/cjs/types/speed.js.map +1 -0
  16. package/lib/esm/components/typewriter/AnimatedTypewriterText.js +51 -0
  17. package/lib/esm/components/typewriter/AnimatedTypewriterText.js.map +1 -0
  18. package/lib/esm/components/typewriter/Typewriter.js +265 -0
  19. package/lib/esm/components/typewriter/Typewriter.js.map +1 -0
  20. package/lib/esm/components/typewriter/Typewriter.styles.js +101 -0
  21. package/lib/esm/components/typewriter/Typewriter.styles.js.map +1 -0
  22. package/lib/esm/components/typewriter/utils.js +108 -0
  23. package/lib/esm/components/typewriter/utils.js.map +1 -0
  24. package/lib/esm/index.js +4 -0
  25. package/lib/esm/index.js.map +1 -0
  26. package/lib/esm/types/cursor.js +6 -0
  27. package/lib/esm/types/cursor.js.map +1 -0
  28. package/lib/esm/types/speed.js +21 -0
  29. package/lib/esm/types/speed.js.map +1 -0
  30. package/lib/types/components/typewriter/AnimatedTypewriterText.d.ts +8 -0
  31. package/lib/types/components/typewriter/Typewriter.d.ts +111 -0
  32. package/lib/types/components/typewriter/Typewriter.styles.d.ts +19 -0
  33. package/lib/{components → types/components}/typewriter/utils.d.ts +11 -0
  34. package/lib/types/index.d.ts +3 -0
  35. package/lib/types/types/cursor.d.ts +4 -0
  36. package/lib/types/types/speed.d.ts +15 -0
  37. package/package.json +46 -28
  38. package/lib/components/typewriter/Typewriter.d.ts +0 -27
  39. package/lib/components/typewriter/Typewriter.js +0 -128
  40. package/lib/components/typewriter/Typewriter.js.map +0 -1
  41. package/lib/components/typewriter/Typewriter.styles.d.ts +0 -7
  42. package/lib/components/typewriter/Typewriter.styles.js +0 -62
  43. package/lib/components/typewriter/Typewriter.styles.js.map +0 -1
  44. package/lib/components/typewriter/utils.js.map +0 -1
  45. package/lib/index.d.ts +0 -1
  46. package/lib/index.js +0 -21
  47. package/lib/index.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":["getSubTextFromHTML","html","length","div","document","createElement","innerHTML","text","currLength","traverse","element","nodeName","nodeType","textContent","nodeText","substring","toLowerCase","attributes","attribute","name","value","i","childNodes","childNode","exports","getCharactersCount","count","node","trim","Array","from","forEach","shuffleArray","array","result","j","Math","floor","random","calculateAutoSpeed","fullTextLength","currentPosition","baseSpeedFactor","MIN_SPEED","MAX_SPEED","remainingLength","speed","min","steps"],"sources":["../../../../src/components/typewriter/utils.ts"],"sourcesContent":["/**\n * This function extracts a part of the text from an HTML text. The HTML elements themselves are\n * returned in the result. In addition, the function ensures that the closing tag of the Bold HTML\n * element is also returned for text that is cut off in the middle of a Bold element, for example.\n *\n * @param html - The text from which a part should be taken\n * @param length - The length of the text to be extracted\n *\n * @return string - The text part with the specified length - additionally the HTML elements are added\n */\nexport const getSubTextFromHTML = (html: string, length: number): string => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let text = '';\n let currLength = 0;\n\n const traverse = (element: Element): boolean => {\n if (element.nodeName === 'TWIGNORE') {\n text += element.innerHTML;\n } else if (element.nodeType === 3 && typeof element.textContent === 'string') {\n const nodeText = element.textContent;\n\n if (currLength + nodeText.length <= length) {\n text += nodeText;\n currLength += nodeText.length;\n } else {\n text += nodeText.substring(0, length - currLength);\n\n return false;\n }\n } else if (element.nodeType === 1) {\n const nodeName = element.nodeName.toLowerCase();\n\n let attributes = '';\n\n // @ts-expect-error: Type is correct here\n // eslint-disable-next-line no-restricted-syntax\n for (const attribute of element.attributes) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions\n attributes += ` ${attribute.name}=\"${attribute.value}\"`;\n }\n\n text += `<${nodeName}${attributes}>`;\n\n for (let i = 0; i < element.childNodes.length; i++) {\n const childNode = element.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return false;\n }\n }\n\n text += `</${nodeName}>`;\n }\n\n return true;\n };\n\n for (let i = 0; i < div.childNodes.length; i++) {\n const childNode = div.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return text;\n }\n }\n\n return text;\n};\n\nexport const getCharactersCount = (html: string): number => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let count = 0;\n\n const traverse = (node: Node): void => {\n if (node.nodeName === 'TWIGNORE') {\n count += 1;\n } else if (node.nodeType === 3 && typeof node.textContent === 'string') {\n count += node.textContent.trim().length;\n } else if (node.nodeType === 1) {\n if (node.nodeName === 'CODE' && node.textContent !== null) {\n count += node.textContent.length;\n\n return;\n }\n\n Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\n};\n\nexport const shuffleArray = <T>(array: T[]): T[] => {\n const result = Array.from(array);\n\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n\n [result[i], result[j]] = [result[j]!, result[i]!];\n }\n\n return result;\n};\n\ninterface CalculateAutoSpeedProps {\n fullTextLength: number;\n currentPosition: number;\n baseSpeedFactor: number;\n}\n\nexport const calculateAutoSpeed = ({\n fullTextLength,\n currentPosition,\n baseSpeedFactor,\n}: CalculateAutoSpeedProps): { speed: number; steps: number } => {\n const MIN_SPEED = 1;\n const MAX_SPEED = 10;\n\n const remainingLength = fullTextLength - currentPosition;\n\n // Calculate the speed with the remaining text length and the baseSpeedFactor\n const speed = Math.min(baseSpeedFactor / remainingLength, MAX_SPEED);\n\n if (speed < MIN_SPEED) {\n return { speed: 1, steps: 2 };\n }\n\n return { speed, steps: 1 };\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAGA,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;EAElB,MAAMC,QAAQ,GAAIC,OAAgB,IAAc;IAC5C,IAAIA,OAAO,CAACC,QAAQ,KAAK,UAAU,EAAE;MACjCJ,IAAI,IAAIG,OAAO,CAACJ,SAAS;IAC7B,CAAC,MAAM,IAAII,OAAO,CAACE,QAAQ,KAAK,CAAC,IAAI,OAAOF,OAAO,CAACG,WAAW,KAAK,QAAQ,EAAE;MAC1E,MAAMC,QAAQ,GAAGJ,OAAO,CAACG,WAAW;MAEpC,IAAIL,UAAU,GAAGM,QAAQ,CAACZ,MAAM,IAAIA,MAAM,EAAE;QACxCK,IAAI,IAAIO,QAAQ;QAChBN,UAAU,IAAIM,QAAQ,CAACZ,MAAM;MACjC,CAAC,MAAM;QACHK,IAAI,IAAIO,QAAQ,CAACC,SAAS,CAAC,CAAC,EAAEb,MAAM,GAAGM,UAAU,CAAC;QAElD,OAAO,KAAK;MAChB;IACJ,CAAC,MAAM,IAAIE,OAAO,CAACE,QAAQ,KAAK,CAAC,EAAE;MAC/B,MAAMD,QAAQ,GAAGD,OAAO,CAACC,QAAQ,CAACK,WAAW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AAA,CAAAQ,YAAA,GAAAA,YAAA;AAQK,MAAMO,kBAAkB,GAAGA,CAAC;EAC/BC,cAAc;EACdC,eAAe;EACfC;AACqB,CAAC,KAAuC;EAC7D,MAAMC,SAAS,GAAG,CAAC;EACnB,MAAMC,SAAS,GAAG,EAAE;EAEpB,MAAMC,eAAe,GAAGL,cAAc,GAAGC,eAAe;;EAExD;EACA,MAAMK,KAAK,GAAGV,IAAI,CAACW,GAAG,CAACL,eAAe,GAAGG,eAAe,EAAED,SAAS,CAAC;EAEpE,IAAIE,KAAK,GAAGH,SAAS,EAAE;IACnB,OAAO;MAAEG,KAAK,EAAE,CAAC;MAAEE,KAAK,EAAE;IAAE,CAAC;EACjC;EAEA,OAAO;IAAEF,KAAK;IAAEE,KAAK,EAAE;EAAE,CAAC;AAC9B,CAAC;AAACxB,OAAA,CAAAe,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "CursorType", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _cursor.CursorType;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "Typewriter", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _Typewriter.default;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "TypewriterDelay", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _speed.TypewriterDelay;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "TypewriterSpeed", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _speed.TypewriterSpeed;
28
+ }
29
+ });
30
+ var _Typewriter = _interopRequireDefault(require("./components/typewriter/Typewriter"));
31
+ var _cursor = require("./types/cursor");
32
+ var _speed = require("./types/speed");
33
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_Typewriter","_interopRequireDefault","require","_cursor","_speed","e","__esModule","default"],"sources":["../../src/index.ts"],"sourcesContent":["export { default as Typewriter } from './components/typewriter/Typewriter';\nexport { CursorType } from './types/cursor';\nexport { TypewriterDelay, TypewriterSpeed } from './types/speed';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAAiE,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CursorType = void 0;
7
+ let CursorType = exports.CursorType = /*#__PURE__*/function (CursorType) {
8
+ CursorType["Default"] = "default";
9
+ CursorType["Thin"] = "thin";
10
+ return CursorType;
11
+ }({});
12
+ //# sourceMappingURL=cursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.js","names":["CursorType","exports"],"sources":["../../../src/types/cursor.ts"],"sourcesContent":["export enum CursorType {\n Default = 'default',\n Thin = 'thin',\n}\n"],"mappings":";;;;;;IAAYA,UAAU,GAAAC,OAAA,CAAAD,UAAA,0BAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA","ignoreList":[]}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TypewriterSpeed = exports.TypewriterDelay = void 0;
7
+ // noinspection JSUnusedGlobalSymbols
8
+ let TypewriterDelay = exports.TypewriterDelay = /*#__PURE__*/function (TypewriterDelay) {
9
+ TypewriterDelay[TypewriterDelay["ExtraSlow"] = 4000] = "ExtraSlow";
10
+ TypewriterDelay[TypewriterDelay["Slow"] = 2000] = "Slow";
11
+ TypewriterDelay[TypewriterDelay["Medium"] = 1000] = "Medium";
12
+ TypewriterDelay[TypewriterDelay["Fast"] = 500] = "Fast";
13
+ TypewriterDelay[TypewriterDelay["ExtraFast"] = 250] = "ExtraFast";
14
+ TypewriterDelay[TypewriterDelay["None"] = 0] = "None";
15
+ return TypewriterDelay;
16
+ }({}); // noinspection JSUnusedGlobalSymbols
17
+ let TypewriterSpeed = exports.TypewriterSpeed = /*#__PURE__*/function (TypewriterSpeed) {
18
+ TypewriterSpeed[TypewriterSpeed["ExtraSlow"] = 40] = "ExtraSlow";
19
+ TypewriterSpeed[TypewriterSpeed["Slow"] = 20] = "Slow";
20
+ TypewriterSpeed[TypewriterSpeed["Medium"] = 10] = "Medium";
21
+ TypewriterSpeed[TypewriterSpeed["Fast"] = 5] = "Fast";
22
+ TypewriterSpeed[TypewriterSpeed["ExtraFast"] = 2.5] = "ExtraFast";
23
+ return TypewriterSpeed;
24
+ }({});
25
+ //# sourceMappingURL=speed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speed.js","names":["TypewriterDelay","exports","TypewriterSpeed"],"sources":["../../../src/types/speed.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterDelay {\n ExtraSlow = 4000,\n Slow = 2000,\n Medium = 1000,\n Fast = 500,\n ExtraFast = 250,\n None = 0,\n}\n\n// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterSpeed {\n ExtraSlow = 40,\n Slow = 20,\n Medium = 10,\n Fast = 5,\n ExtraFast = 2.5,\n}\n"],"mappings":";;;;;;AAAA;AAAA,IACYA,eAAe,GAAAC,OAAA,CAAAD,eAAA,0BAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA,OAS3B;AAAA,IACYE,eAAe,GAAAD,OAAA,CAAAC,eAAA,0BAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA","ignoreList":[]}
@@ -0,0 +1,51 @@
1
+ import React, { useCallback, useMemo } from 'react';
2
+ import { StyledTypewriterText } from "./Typewriter.styles";
3
+ const AnimatedTypewriterText = _ref => {
4
+ let {
5
+ shouldHideCursor,
6
+ shownText,
7
+ textStyle
8
+ } = _ref;
9
+ const updateTypewriterCursor = useCallback(ref => {
10
+ if (ref && !shouldHideCursor) {
11
+ // Finds the last text node with content.
12
+ const traverseNodes = node => {
13
+ if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim()) {
14
+ return node.parentElement;
15
+ }
16
+ const childNodes = Array.from(node.childNodes);
17
+ for (let i = childNodes.length - 1; i >= 0; i--) {
18
+ const result = traverseNodes(childNodes[i]);
19
+ if (result) {
20
+ return result;
21
+ }
22
+ }
23
+ return null;
24
+ };
25
+ const lastParentWithContent = traverseNodes(ref);
26
+
27
+ // Removes lastWithContent class from all elements
28
+ ref.classList.remove('typewriter-lastWithContent');
29
+ ref.querySelectorAll('.lastWithContent').forEach(element => {
30
+ element.classList.remove('typewriter-lastWithContent');
31
+ });
32
+
33
+ // Adds lastWithContent class to the last element with content
34
+ if (lastParentWithContent) {
35
+ lastParentWithContent.classList.add('typewriter-lastWithContent');
36
+ } else {
37
+ ref.classList.add('typewriter-lastWithContent');
38
+ }
39
+ }
40
+ }, [shouldHideCursor]);
41
+ return useMemo(() => /*#__PURE__*/React.createElement(StyledTypewriterText, {
42
+ ref: ref => updateTypewriterCursor(ref),
43
+ dangerouslySetInnerHTML: {
44
+ __html: shownText
45
+ },
46
+ style: textStyle,
47
+ $isAnimatingText: true
48
+ }), [updateTypewriterCursor, shownText, textStyle]);
49
+ };
50
+ export default AnimatedTypewriterText;
51
+ //# sourceMappingURL=AnimatedTypewriterText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimatedTypewriterText.js","names":["React","useCallback","useMemo","StyledTypewriterText","AnimatedTypewriterText","_ref","shouldHideCursor","shownText","textStyle","updateTypewriterCursor","ref","traverseNodes","node","nodeType","Node","TEXT_NODE","textContent","trim","parentElement","childNodes","Array","from","i","length","result","lastParentWithContent","classList","remove","querySelectorAll","forEach","element","add","createElement","dangerouslySetInnerHTML","__html","style","$isAnimatingText"],"sources":["../../../../src/components/typewriter/AnimatedTypewriterText.tsx"],"sourcesContent":["import React, {FC, useCallback, useEffect, useMemo, useRef} from 'react';\nimport {StyledTypewriterText} from \"./Typewriter.styles\";\n\ntype AnimatedTypewriterTextProps = {\n shouldHideCursor: boolean;\n shownText: string;\n textStyle?: React.CSSProperties;\n};\n\nconst AnimatedTypewriterText: FC<AnimatedTypewriterTextProps> = ({\n shouldHideCursor,\n shownText,\n textStyle\n}) => {\n const updateTypewriterCursor = useCallback((ref: HTMLSpanElement | null) => {\n if (ref && !shouldHideCursor) {\n // Finds the last text node with content.\n const traverseNodes = (node: Node): HTMLElement | null => {\n if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim()) {\n return node.parentElement;\n }\n\n const childNodes = Array.from(node.childNodes);\n for (let i = childNodes.length - 1; i >= 0; i--) {\n const result = traverseNodes(childNodes[i] as Node);\n if (result) {\n return result;\n }\n }\n\n return null;\n }\n\n const lastParentWithContent = traverseNodes(ref);\n\n // Removes lastWithContent class from all elements\n ref.classList.remove('typewriter-lastWithContent');\n ref.querySelectorAll('.lastWithContent').forEach(element => {\n element.classList.remove('typewriter-lastWithContent');\n });\n\n // Adds lastWithContent class to the last element with content\n if (lastParentWithContent) {\n lastParentWithContent.classList.add('typewriter-lastWithContent');\n } else {\n ref.classList.add('typewriter-lastWithContent');\n }\n }\n }, [shouldHideCursor]);\n\n return useMemo(() => (\n <StyledTypewriterText\n ref={(ref) => updateTypewriterCursor(ref)}\n dangerouslySetInnerHTML={{ __html: shownText }}\n style={textStyle}\n $isAnimatingText\n />\n ), [updateTypewriterCursor, shownText, textStyle]);\n};\n\nexport default AnimatedTypewriterText;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAOC,WAAW,EAAaC,OAAO,QAAe,OAAO;AACxE,SAAQC,oBAAoB,QAAO,qBAAqB;AAQxD,MAAMC,sBAAuD,GAAGC,IAAA,IAI1D;EAAA,IAJ2D;IAC7DC,gBAAgB;IAChBC,SAAS;IACTC;EACJ,CAAC,GAAAH,IAAA;EACG,MAAMI,sBAAsB,GAAGR,WAAW,CAAES,GAA2B,IAAK;IACxE,IAAIA,GAAG,IAAI,CAACJ,gBAAgB,EAAE;MAC1B;MACA,MAAMK,aAAa,GAAIC,IAAU,IAAyB;QACtD,IAAIA,IAAI,CAACC,QAAQ,KAAKC,IAAI,CAACC,SAAS,IAAIH,IAAI,CAACI,WAAW,EAAEC,IAAI,CAAC,CAAC,EAAE;UAC9D,OAAOL,IAAI,CAACM,aAAa;QAC7B;QAEA,MAAMC,UAAU,GAAGC,KAAK,CAACC,IAAI,CAACT,IAAI,CAACO,UAAU,CAAC;QAC9C,KAAK,IAAIG,CAAC,GAAGH,UAAU,CAACI,MAAM,GAAG,CAAC,EAAED,CAAC,IAAI,CAAC,EAAEA,CAAC,EAAE,EAAE;UAC7C,MAAME,MAAM,GAAGb,aAAa,CAACQ,UAAU,CAACG,CAAC,CAAS,CAAC;UACnD,IAAIE,MAAM,EAAE;YACR,OAAOA,MAAM;UACjB;QACJ;QAEA,OAAO,IAAI;MACf,CAAC;MAED,MAAMC,qBAAqB,GAAGd,aAAa,CAACD,GAAG,CAAC;;MAEhD;MACAA,GAAG,CAACgB,SAAS,CAACC,MAAM,CAAC,4BAA4B,CAAC;MAClDjB,GAAG,CAACkB,gBAAgB,CAAC,kBAAkB,CAAC,CAACC,OAAO,CAACC,OAAO,IAAI;QACxDA,OAAO,CAACJ,SAAS,CAACC,MAAM,CAAC,4BAA4B,CAAC;MAC1D,CAAC,CAAC;;MAEF;MACA,IAAIF,qBAAqB,EAAE;QACvBA,qBAAqB,CAACC,SAAS,CAACK,GAAG,CAAC,4BAA4B,CAAC;MACrE,CAAC,MAAM;QACHrB,GAAG,CAACgB,SAAS,CAACK,GAAG,CAAC,4BAA4B,CAAC;MACnD;IACJ;EACJ,CAAC,EAAE,CAACzB,gBAAgB,CAAC,CAAC;EAEtB,OAAOJ,OAAO,CAAC,mBACXF,KAAA,CAAAgC,aAAA,CAAC7B,oBAAoB;IACjBO,GAAG,EAAGA,GAAG,IAAKD,sBAAsB,CAACC,GAAG,CAAE;IAC1CuB,uBAAuB,EAAE;MAAEC,MAAM,EAAE3B;IAAU,CAAE;IAC/C4B,KAAK,EAAE3B,SAAU;IACjB4B,gBAAgB;EAAA,CACnB,CACJ,EAAE,CAAC3B,sBAAsB,EAAEF,SAAS,EAAEC,SAAS,CAAC,CAAC;AACtD,CAAC;AAED,eAAeJ,sBAAsB","ignoreList":[]}
@@ -0,0 +1,265 @@
1
+ import { ColorSchemeProvider } from '@chayns-components/core';
2
+ import { ChaynsProvider, useFunctions, useValues } from 'chayns-api';
3
+ import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
4
+ import { createPortal } from 'react-dom';
5
+ import { renderToString } from 'react-dom/server';
6
+ import { CursorType } from '../../types/cursor';
7
+ import { TypewriterDelay, TypewriterSpeed } from '../../types/speed';
8
+ import AnimatedTypewriterText from './AnimatedTypewriterText';
9
+ import { StyledTypewriter, StyledTypewriterPseudoText, StyledTypewriterText } from './Typewriter.styles';
10
+ import { calculateAutoSpeed, getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';
11
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
12
+ const Typewriter = _ref => {
13
+ let {
14
+ children,
15
+ cursorType = CursorType.Default,
16
+ nextTextDelay = TypewriterDelay.Medium,
17
+ onFinish,
18
+ onResetAnimationEnd,
19
+ animationSteps = 1,
20
+ onResetAnimationStart,
21
+ onTypingAnimationEnd,
22
+ onTypingAnimationStart,
23
+ pseudoChildren,
24
+ resetDelay = TypewriterDelay.Medium,
25
+ shouldForceCursorAnimation = false,
26
+ shouldHideCursor = false,
27
+ shouldSortChildrenRandomly = false,
28
+ shouldUseAnimationHeight = false,
29
+ shouldUseResetAnimation = false,
30
+ shouldWaitForContent,
31
+ speed = TypewriterSpeed.Medium,
32
+ resetSpeed = speed,
33
+ startDelay = TypewriterDelay.None,
34
+ textStyle,
35
+ shouldCalcAutoSpeed = false,
36
+ autoSpeedBaseFactor = 2000
37
+ } = _ref;
38
+ const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);
39
+ const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);
40
+ const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);
41
+ const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);
42
+ const [shouldStopAnimation, setShouldStopAnimation] = useState(false);
43
+ const [autoSpeed, setAutoSpeed] = useState();
44
+ const [autoSteps, setAutoSteps] = useState(animationSteps);
45
+ const functions = useFunctions();
46
+ const values = useValues();
47
+ useIsomorphicLayoutEffect(() => {
48
+ if (children) {
49
+ setHasRenderedChildrenOnce(false);
50
+ }
51
+ }, [children]);
52
+ useEffect(() => {
53
+ if (!hasRenderedChildrenOnce) {
54
+ setHasRenderedChildrenOnce(true);
55
+ }
56
+ }, [hasRenderedChildrenOnce]);
57
+ useEffect(() => {
58
+ if (animationSteps > 0 && !shouldCalcAutoSpeed) {
59
+ setAutoSteps(animationSteps);
60
+ }
61
+ }, [animationSteps, shouldCalcAutoSpeed]);
62
+ const sortedChildren = useMemo(() => Array.isArray(children) && shouldSortChildrenRandomly ? shuffleArray(children) : children, [children, shouldSortChildrenRandomly]);
63
+ const areMultipleChildrenGiven = Array.isArray(sortedChildren);
64
+ const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;
65
+ const textContent = useMemo(() => {
66
+ if (areMultipleChildrenGiven) {
67
+ const currentChildren = sortedChildren[currentChildrenIndex];
68
+ if (currentChildren) {
69
+ return /*#__PURE__*/React.isValidElement(currentChildren) ? renderToString(/*#__PURE__*/React.createElement(ChaynsProvider, {
70
+ data: values,
71
+ functions: functions,
72
+ isModule: true
73
+ }, /*#__PURE__*/React.createElement(ColorSchemeProvider, {
74
+ color: "#005EB8",
75
+ colorMode: 0,
76
+ style: {
77
+ display: 'inline'
78
+ }
79
+ }, currentChildren))) : currentChildren;
80
+ }
81
+ return '';
82
+ }
83
+ return /*#__PURE__*/React.isValidElement(sortedChildren) ? renderToString(/*#__PURE__*/React.createElement(ChaynsProvider, {
84
+ data: values,
85
+ functions: functions,
86
+ isModule: true
87
+ }, /*#__PURE__*/React.createElement(ColorSchemeProvider, {
88
+ color: "#005EB8",
89
+ colorMode: 0,
90
+ style: {
91
+ display: 'inline'
92
+ }
93
+ }, sortedChildren))) : sortedChildren;
94
+ }, [areMultipleChildrenGiven, currentChildrenIndex, functions, sortedChildren, values]);
95
+ const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);
96
+ const [shownCharCount, setShownCharCount] = useState(charactersCount > 0 ? 0 : textContent.length);
97
+ const currentPosition = useRef(0);
98
+ useEffect(() => {
99
+ if (!shouldCalcAutoSpeed) {
100
+ setAutoSpeed(undefined);
101
+ setAutoSteps(animationSteps);
102
+ return;
103
+ }
104
+ const {
105
+ speed: calculatedAutoSpeed,
106
+ steps
107
+ } = calculateAutoSpeed({
108
+ fullTextLength: charactersCount,
109
+ currentPosition: currentPosition.current,
110
+ baseSpeedFactor: autoSpeedBaseFactor
111
+ });
112
+ setAutoSpeed(calculatedAutoSpeed);
113
+ setAutoSteps(steps);
114
+ }, [animationSteps, autoSpeedBaseFactor, charactersCount, shouldCalcAutoSpeed]);
115
+ const isAnimatingText = shownCharCount < textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
116
+ const handleClick = useCallback(event => {
117
+ event.stopPropagation();
118
+ event.preventDefault();
119
+ setShouldStopAnimation(true);
120
+ }, []);
121
+ const handleSetNextChildrenIndex = useCallback(() => setCurrentChildrenIndex(() => {
122
+ let newIndex = currentChildrenIndex + 1;
123
+ if (newIndex > childrenCount - 1) {
124
+ newIndex = 0;
125
+ }
126
+ return newIndex;
127
+ }), [childrenCount, currentChildrenIndex]);
128
+ useEffect(() => {
129
+ let interval;
130
+ if (shouldStopAnimation || charactersCount === 0) {
131
+ setShownCharCount(textContent.length);
132
+ currentPosition.current = textContent.length;
133
+ } else if (isResetAnimationActive) {
134
+ if (typeof onResetAnimationStart === 'function') {
135
+ onResetAnimationStart();
136
+ }
137
+ interval = window.setInterval(() => {
138
+ setShownCharCount(prevState => {
139
+ const nextState = prevState - autoSteps;
140
+ currentPosition.current = nextState;
141
+ if (nextState === 0) {
142
+ window.clearInterval(interval);
143
+ if (typeof onResetAnimationEnd === 'function') {
144
+ onResetAnimationEnd();
145
+ }
146
+ if (areMultipleChildrenGiven) {
147
+ setTimeout(() => {
148
+ setIsResetAnimationActive(false);
149
+ handleSetNextChildrenIndex();
150
+ }, nextTextDelay);
151
+ }
152
+ }
153
+ return nextState;
154
+ });
155
+ }, resetSpeed);
156
+ } else {
157
+ const startTypingAnimation = () => {
158
+ if (cursorType === CursorType.Thin) {
159
+ setShouldPreventBlinkingCursor(true);
160
+ }
161
+ if (typeof onTypingAnimationStart === 'function') {
162
+ onTypingAnimationStart();
163
+ }
164
+ const runTypingInterval = () => {
165
+ setShownCharCount(prevState => {
166
+ let nextState = Math.min(prevState + autoSteps, charactersCount);
167
+ if (nextState >= charactersCount && !shouldWaitForContent) {
168
+ window.clearInterval(interval);
169
+ if (cursorType === CursorType.Thin) {
170
+ setShouldPreventBlinkingCursor(false);
171
+ }
172
+ if (typeof onTypingAnimationEnd === 'function') {
173
+ onTypingAnimationEnd();
174
+ }
175
+
176
+ /**
177
+ * At this point, the next value for "shownCharCount" is deliberately set to
178
+ * the length of the textContent in order to correctly display HTML elements
179
+ * after the last letter.
180
+ */
181
+ nextState = textContent.length;
182
+ if (areMultipleChildrenGiven) {
183
+ setTimeout(() => {
184
+ if (shouldUseResetAnimation) {
185
+ setIsResetAnimationActive(true);
186
+ } else {
187
+ setShownCharCount(0);
188
+ setTimeout(handleSetNextChildrenIndex, nextTextDelay);
189
+ }
190
+ }, resetDelay);
191
+ }
192
+ }
193
+ currentPosition.current = nextState;
194
+ return nextState;
195
+ });
196
+ };
197
+ interval = window.setInterval(runTypingInterval, autoSpeed ?? speed);
198
+ };
199
+ if (startDelay) {
200
+ setTimeout(startTypingAnimation, startDelay);
201
+ } else {
202
+ startTypingAnimation();
203
+ }
204
+ }
205
+ return () => {
206
+ window.clearInterval(interval);
207
+ };
208
+ }, [resetSpeed, speed, resetDelay, childrenCount, charactersCount, textContent.length, shouldStopAnimation, shouldWaitForContent, isResetAnimationActive, shouldUseResetAnimation, areMultipleChildrenGiven, handleSetNextChildrenIndex, nextTextDelay, startDelay, onResetAnimationStart, onResetAnimationEnd, onTypingAnimationStart, onTypingAnimationEnd, cursorType, autoSpeed, autoSteps]);
209
+ useEffect(() => {
210
+ if (!isAnimatingText && typeof onFinish === 'function') {
211
+ onFinish();
212
+ }
213
+ }, [isAnimatingText, onFinish]);
214
+ const shownText = useMemo(() => getSubTextFromHTML(textContent, shownCharCount), [shownCharCount, textContent]);
215
+ const pseudoTextHTML = useMemo(() => {
216
+ if (pseudoChildren) {
217
+ const pseudoText = /*#__PURE__*/React.isValidElement(pseudoChildren) ? renderToString(/*#__PURE__*/React.createElement(ChaynsProvider, {
218
+ data: values,
219
+ functions: functions,
220
+ isModule: true
221
+ }, /*#__PURE__*/React.createElement(ColorSchemeProvider, {
222
+ color: "#005EB8",
223
+ colorMode: 0,
224
+ style: {
225
+ display: 'inline'
226
+ }
227
+ }, pseudoChildren))) : pseudoChildren;
228
+ if (shouldUseAnimationHeight) {
229
+ return getSubTextFromHTML(pseudoText, shownCharCount);
230
+ }
231
+ return pseudoText;
232
+ }
233
+ if (shouldUseAnimationHeight && textContent) {
234
+ return getSubTextFromHTML(textContent, shownCharCount);
235
+ }
236
+ return textContent || '&#8203;';
237
+ }, [functions, pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent, values]);
238
+ return useMemo(() => /*#__PURE__*/React.createElement(StyledTypewriter, {
239
+ $cursorType: cursorType,
240
+ onClick: isAnimatingText ? handleClick : undefined,
241
+ $isAnimatingText: isAnimatingText,
242
+ $shouldHideCursor: shouldHideCursor,
243
+ $shouldPreventBlinkAnimation: shouldPreventBlinkingCursor
244
+ }, isAnimatingText ? /*#__PURE__*/React.createElement(AnimatedTypewriterText, {
245
+ shouldHideCursor: shouldHideCursor,
246
+ shownText: shownText,
247
+ textStyle: textStyle
248
+ }) : /*#__PURE__*/React.createElement(StyledTypewriterText, {
249
+ style: textStyle
250
+ }, sortedChildren), isAnimatingText && /*#__PURE__*/React.createElement(StyledTypewriterPseudoText, {
251
+ $isAnimatingText: isAnimatingText,
252
+ $shouldHideCursor: shouldHideCursor,
253
+ dangerouslySetInnerHTML: {
254
+ __html: pseudoTextHTML
255
+ }
256
+ }), !hasRenderedChildrenOnce && /*#__PURE__*/createPortal(/*#__PURE__*/React.createElement("div", {
257
+ style: {
258
+ position: 'absolute',
259
+ visibility: 'hidden'
260
+ }
261
+ }, children), document.body)), [children, cursorType, handleClick, hasRenderedChildrenOnce, isAnimatingText, pseudoTextHTML, shouldHideCursor, shouldPreventBlinkingCursor, shownText, sortedChildren, textStyle]);
262
+ };
263
+ Typewriter.displayName = 'Typewriter';
264
+ export default Typewriter;
265
+ //# sourceMappingURL=Typewriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Typewriter.js","names":["ColorSchemeProvider","ChaynsProvider","useFunctions","useValues","React","useCallback","useEffect","useLayoutEffect","useMemo","useRef","useState","createPortal","renderToString","CursorType","TypewriterDelay","TypewriterSpeed","AnimatedTypewriterText","StyledTypewriter","StyledTypewriterPseudoText","StyledTypewriterText","calculateAutoSpeed","getCharactersCount","getSubTextFromHTML","shuffleArray","useIsomorphicLayoutEffect","window","Typewriter","_ref","children","cursorType","Default","nextTextDelay","Medium","onFinish","onResetAnimationEnd","animationSteps","onResetAnimationStart","onTypingAnimationEnd","onTypingAnimationStart","pseudoChildren","resetDelay","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","resetSpeed","startDelay","None","textStyle","shouldCalcAutoSpeed","autoSpeedBaseFactor","currentChildrenIndex","setCurrentChildrenIndex","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","shouldPreventBlinkingCursor","setShouldPreventBlinkingCursor","isResetAnimationActive","setIsResetAnimationActive","shouldStopAnimation","setShouldStopAnimation","autoSpeed","setAutoSpeed","autoSteps","setAutoSteps","functions","values","sortedChildren","Array","isArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","isValidElement","createElement","data","isModule","color","colorMode","style","display","charactersCount","shownCharCount","setShownCharCount","currentPosition","undefined","calculatedAutoSpeed","steps","fullTextLength","current","baseSpeedFactor","isAnimatingText","handleClick","event","stopPropagation","preventDefault","handleSetNextChildrenIndex","newIndex","interval","setInterval","prevState","nextState","clearInterval","setTimeout","startTypingAnimation","Thin","runTypingInterval","Math","min","shownText","pseudoTextHTML","pseudoText","$cursorType","onClick","$isAnimatingText","$shouldHideCursor","$shouldPreventBlinkAnimation","dangerouslySetInnerHTML","__html","position","visibility","document","body","displayName"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider } from '@chayns-components/core';\nimport { ChaynsProvider, useFunctions, useValues } from 'chayns-api';\nimport React, {\n FC,\n ReactElement,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { renderToString } from 'react-dom/server';\nimport { CursorType } from '../../types/cursor';\nimport { TypewriterDelay, TypewriterSpeed } from '../../types/speed';\nimport AnimatedTypewriterText from './AnimatedTypewriterText';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { calculateAutoSpeed, getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport type TypewriterProps = {\n /**\n * The amount of characters that will be animated per animation cycle.\n */\n animationSteps?: number;\n /**\n * The base speed factor to calculate the animation speed.\n */\n autoSpeedBaseFactor?: number;\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\n /**\n * The type of the cursor. Use the CursorType enum for this prop.\n */\n cursorType?: CursorType;\n /**\n * The delay in milliseconds before the next text is shown.\n * This prop is only used if multiple texts are given.\n */\n nextTextDelay?: TypewriterDelay;\n /**\n * Function that is executed when the typewriter animation has finished. This function will not\n * be executed if multiple texts are used.\n */\n onFinish?: VoidFunction;\n /**\n * Function that is executed when the reset animation has finished. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the reset animation has started. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationStart?: VoidFunction;\n /**\n * Function that is executed when the typing animation has finished. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the typing animation has started. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationStart?: VoidFunction;\n /**\n * Pseudo-element to be rendered invisible during animation to define the size of the element\n * for the typewriter effect. By default, the \"children\" is used for this purpose.\n */\n pseudoChildren?: ReactElement | string;\n /**\n * Waiting time in milliseconds before the typewriter resets the text.\n * This prop is only used if multiple texts are given.\n */\n resetDelay?: TypewriterDelay;\n /**\n * The reset speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n resetSpeed?: TypewriterSpeed | number;\n /**\n * Specifies whether the cursor should be forced to animate even if no text is currently animated.\n */\n shouldForceCursorAnimation?: boolean;\n /**\n * Specifies whether the cursor should be hidden\n */\n shouldHideCursor?: boolean;\n /**\n * Specifies whether the children should be sorted randomly if there are multiple texts.\n * This makes the typewriter start with a different text each time and also changes them\n * in a random order.\n */\n shouldSortChildrenRandomly?: boolean;\n /**\n * Specifies whether the animation should use its full height or the height of the current\n * chunk.\n */\n shouldUseAnimationHeight?: boolean;\n /**\n * Whether the animation speed should be calculated with the chunk interval.\n */\n shouldCalcAutoSpeed?: boolean;\n /**\n * Specifies whether the reset of the text should be animated with a backspace animation for\n * multiple texts.\n */\n shouldUseResetAnimation?: boolean;\n /**\n * Whether the typewriter should wait for new content\n */\n shouldWaitForContent?: boolean;\n /**\n * The speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n speed?: TypewriterSpeed | number;\n /**\n * The delay in milliseconds before the typewriter starts typing.\n */\n startDelay?: TypewriterDelay;\n /**\n * The style of the typewriter text element\n */\n textStyle?: React.CSSProperties;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n cursorType = CursorType.Default,\n nextTextDelay = TypewriterDelay.Medium,\n onFinish,\n onResetAnimationEnd,\n animationSteps = 1,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n pseudoChildren,\n resetDelay = TypewriterDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = false,\n shouldSortChildrenRandomly = false,\n shouldUseAnimationHeight = false,\n shouldUseResetAnimation = false,\n shouldWaitForContent,\n speed = TypewriterSpeed.Medium,\n resetSpeed = speed,\n startDelay = TypewriterDelay.None,\n textStyle,\n shouldCalcAutoSpeed = false,\n autoSpeedBaseFactor = 2000,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);\n const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [autoSpeed, setAutoSpeed] = useState<number>();\n const [autoSteps, setAutoSteps] = useState(animationSteps);\n\n const functions = useFunctions();\n const values = useValues();\n\n useIsomorphicLayoutEffect(() => {\n if (children) {\n setHasRenderedChildrenOnce(false);\n }\n }, [children]);\n\n useEffect(() => {\n if (!hasRenderedChildrenOnce) {\n setHasRenderedChildrenOnce(true);\n }\n }, [hasRenderedChildrenOnce]);\n\n useEffect(() => {\n if (animationSteps > 0 && !shouldCalcAutoSpeed) {\n setAutoSteps(animationSteps);\n }\n }, [animationSteps, shouldCalcAutoSpeed]);\n\n const sortedChildren = useMemo(\n () =>\n Array.isArray(children) && shouldSortChildrenRandomly\n ? shuffleArray<ReactElement | string>(children)\n : children,\n [children, shouldSortChildrenRandomly],\n );\n\n const areMultipleChildrenGiven = Array.isArray(sortedChildren);\n const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;\n\n const textContent = useMemo(() => {\n if (areMultipleChildrenGiven) {\n const currentChildren = sortedChildren[currentChildrenIndex];\n\n if (currentChildren) {\n return React.isValidElement(currentChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {currentChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (currentChildren as string);\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {sortedChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (sortedChildren as string);\n }, [areMultipleChildrenGiven, currentChildrenIndex, functions, sortedChildren, values]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n\n const currentPosition = useRef(0);\n\n useEffect(() => {\n if (!shouldCalcAutoSpeed) {\n setAutoSpeed(undefined);\n setAutoSteps(animationSteps);\n\n return;\n }\n\n const { speed: calculatedAutoSpeed, steps } = calculateAutoSpeed({\n fullTextLength: charactersCount,\n currentPosition: currentPosition.current,\n baseSpeedFactor: autoSpeedBaseFactor,\n });\n\n setAutoSpeed(calculatedAutoSpeed);\n setAutoSteps(steps);\n }, [animationSteps, autoSpeedBaseFactor, charactersCount, shouldCalcAutoSpeed]);\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\n\n const handleClick = useCallback((event: React.MouseEvent) => {\n event.stopPropagation();\n event.preventDefault();\n\n setShouldStopAnimation(true);\n }, []);\n\n const handleSetNextChildrenIndex = useCallback(\n () =>\n setCurrentChildrenIndex(() => {\n let newIndex = currentChildrenIndex + 1;\n\n if (newIndex > childrenCount - 1) {\n newIndex = 0;\n }\n\n return newIndex;\n }),\n [childrenCount, currentChildrenIndex],\n );\n\n useEffect(() => {\n let interval: number | undefined;\n\n if (shouldStopAnimation || charactersCount === 0) {\n setShownCharCount(textContent.length);\n currentPosition.current = textContent.length;\n } else if (isResetAnimationActive) {\n if (typeof onResetAnimationStart === 'function') {\n onResetAnimationStart();\n }\n\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - autoSteps;\n currentPosition.current = nextState;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (typeof onResetAnimationEnd === 'function') {\n onResetAnimationEnd();\n }\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, nextTextDelay);\n }\n }\n\n return nextState;\n });\n }, resetSpeed);\n } else {\n const startTypingAnimation = () => {\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(true);\n }\n\n if (typeof onTypingAnimationStart === 'function') {\n onTypingAnimationStart();\n }\n\n const runTypingInterval = () => {\n setShownCharCount((prevState) => {\n let nextState = Math.min(prevState + autoSteps, charactersCount);\n\n if (nextState >= charactersCount && !shouldWaitForContent) {\n window.clearInterval(interval);\n\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(false);\n }\n\n if (typeof onTypingAnimationEnd === 'function') {\n onTypingAnimationEnd();\n }\n\n /**\n * At this point, the next value for \"shownCharCount\" is deliberately set to\n * the length of the textContent in order to correctly display HTML elements\n * after the last letter.\n */\n nextState = textContent.length;\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(true);\n } else {\n setShownCharCount(0);\n setTimeout(handleSetNextChildrenIndex, nextTextDelay);\n }\n }, resetDelay);\n }\n }\n\n currentPosition.current = nextState;\n\n return nextState;\n });\n };\n\n interval = window.setInterval(runTypingInterval, autoSpeed ?? speed);\n };\n\n if (startDelay) {\n setTimeout(startTypingAnimation, startDelay);\n } else {\n startTypingAnimation();\n }\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n resetSpeed,\n speed,\n resetDelay,\n childrenCount,\n charactersCount,\n textContent.length,\n shouldStopAnimation,\n shouldWaitForContent,\n isResetAnimationActive,\n shouldUseResetAnimation,\n areMultipleChildrenGiven,\n handleSetNextChildrenIndex,\n nextTextDelay,\n startDelay,\n onResetAnimationStart,\n onResetAnimationEnd,\n onTypingAnimationStart,\n onTypingAnimationEnd,\n cursorType,\n autoSpeed,\n autoSteps,\n ]);\n\n useEffect(() => {\n if (!isAnimatingText && typeof onFinish === 'function') {\n onFinish();\n }\n }, [isAnimatingText, onFinish]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(textContent, shownCharCount),\n [shownCharCount, textContent],\n );\n\n const pseudoTextHTML = useMemo(() => {\n if (pseudoChildren) {\n const pseudoText = React.isValidElement(pseudoChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {pseudoChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (pseudoChildren as string);\n\n if (shouldUseAnimationHeight) {\n return getSubTextFromHTML(pseudoText, shownCharCount);\n }\n\n return pseudoText;\n }\n\n if (shouldUseAnimationHeight && textContent) {\n return getSubTextFromHTML(textContent, shownCharCount);\n }\n\n return textContent || '&#8203;';\n }, [functions, pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent, values]);\n\n return useMemo(\n () => (\n <StyledTypewriter\n $cursorType={cursorType}\n onClick={isAnimatingText ? handleClick : undefined}\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\n $shouldPreventBlinkAnimation={shouldPreventBlinkingCursor}\n >\n {isAnimatingText ? (\n <AnimatedTypewriterText\n shouldHideCursor={shouldHideCursor}\n shownText={shownText}\n textStyle={textStyle}\n />\n ) : (\n <StyledTypewriterText style={textStyle}>{sortedChildren}</StyledTypewriterText>\n )}\n {isAnimatingText && (\n <StyledTypewriterPseudoText\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\n dangerouslySetInnerHTML={{ __html: pseudoTextHTML }}\n />\n )}\n {/*\n The following is needed because some components like the CodeHighlighter will not render correct\n if the element is not rendered on client before...\n */}\n {!hasRenderedChildrenOnce &&\n createPortal(\n <div style={{ position: 'absolute', visibility: 'hidden' }}>\n {children}\n </div>,\n document.body,\n )}\n </StyledTypewriter>\n ),\n [\n children,\n cursorType,\n handleClick,\n hasRenderedChildrenOnce,\n isAnimatingText,\n pseudoTextHTML,\n shouldHideCursor,\n shouldPreventBlinkingCursor,\n shownText,\n sortedChildren,\n textStyle,\n ],\n );\n};\n\nTypewriter.displayName = 'Typewriter';\n\nexport default Typewriter;\n"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,cAAc,EAAEC,YAAY,EAAEC,SAAS,QAA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QACA,CAAC,EACNkG,QAAQ,CAACC,IACb,CACU,CACrB,EACD,CACInG,QAAQ,EACRC,UAAU,EACVoE,WAAW,EACXzC,uBAAuB,EACvBwC,eAAe,EACfmB,cAAc,EACdzE,gBAAgB,EAChBgB,2BAA2B,EAC3BwD,SAAS,EACT5C,cAAc,EACdnB,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDzB,UAAU,CAACsG,WAAW,GAAG,YAAY;AAErC,eAAetG,UAAU","ignoreList":[]}
@@ -0,0 +1,101 @@
1
+ import styled, { css, keyframes } from 'styled-components';
2
+ import { CursorType } from '../../types/cursor';
3
+ const typewriterCursorElement = _ref => {
4
+ let {
5
+ $cursorType,
6
+ $isAnimatingText,
7
+ $shouldHideCursor,
8
+ $shouldPreventBlinkAnimation
9
+ } = _ref;
10
+ if (!$isAnimatingText || $shouldHideCursor) {
11
+ return '';
12
+ }
13
+ if ($cursorType === CursorType.Thin) {
14
+ return css`
15
+ .typewriter-lastWithContent {
16
+ &:after {
17
+ animation: ${$shouldPreventBlinkAnimation ? 'none' : blinkAnimation} 1s steps(2, start) infinite;
18
+ color: inherit;
19
+ content: '|';
20
+ font-size: 25px;
21
+ position: relative;
22
+ line-height: 0;
23
+ vertical-align: baseline;
24
+ }
25
+ `;
26
+ }
27
+ return css`
28
+ .typewriter-lastWithContent {
29
+ &:after {
30
+ animation: ${blinkAnimation} 1s steps(2, start) infinite;
31
+ color: ${_ref2 => {
32
+ let {
33
+ theme
34
+ } = _ref2;
35
+ return theme.text;
36
+ }};
37
+ content: '▋';
38
+ margin-left: 0.25rem;
39
+ opacity: 0.85;
40
+ position: relative;
41
+ vertical-align: baseline;
42
+ }
43
+ }
44
+ `;
45
+ };
46
+ export const StyledTypewriter = styled.div`
47
+ align-items: inherit;
48
+ display: flex;
49
+ position: relative;
50
+ width: 100%;
51
+ ${typewriterCursorElement}
52
+ `;
53
+ const blinkAnimation = keyframes`
54
+ 100% {
55
+ visibility: hidden;
56
+ }
57
+ `;
58
+ export const StyledTypewriterPseudoText = styled.span`
59
+ opacity: 0;
60
+ pointer-events: none;
61
+ user-select: none;
62
+ width: fit-content;
63
+
64
+ ${_ref3 => {
65
+ let {
66
+ $isAnimatingText,
67
+ $shouldHideCursor
68
+ } = _ref3;
69
+ return $isAnimatingText && !$shouldHideCursor && css`
70
+ &:after {
71
+ animation: ${blinkAnimation} 1s steps(2, start) infinite;
72
+ color: inherit;
73
+ content: '|';
74
+ font-size: 25px;
75
+ position: relative;
76
+ line-height: 0;
77
+ vertical-align: baseline;
78
+ }
79
+ `;
80
+ }}
81
+ `;
82
+ export const StyledTypewriterText = styled.span`
83
+ color: inherit;
84
+ position: ${_ref4 => {
85
+ let {
86
+ $isAnimatingText
87
+ } = _ref4;
88
+ return $isAnimatingText ? 'absolute' : 'relative';
89
+ }};
90
+ width: fit-content;
91
+
92
+ ${_ref5 => {
93
+ let {
94
+ $isAnimatingText
95
+ } = _ref5;
96
+ return $isAnimatingText && css`
97
+ pointer-events: none;
98
+ `;
99
+ }}
100
+ `;
101
+ //# sourceMappingURL=Typewriter.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Typewriter.styles.js","names":["styled","css","keyframes","CursorType","typewriterCursorElement","_ref","$cursorType","$isAnimatingText","$shouldHideCursor","$shouldPreventBlinkAnimation","Thin","blinkAnimation","_ref2","theme","text","StyledTypewriter","div","StyledTypewriterPseudoText","span","_ref3","StyledTypewriterText","_ref4","_ref5"],"sources":["../../../../src/components/typewriter/Typewriter.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled, { css, keyframes } from 'styled-components';\nimport { CursorType } from '../../types/cursor';\nimport type { TypewriterProps } from './Typewriter';\n\ntype StyledTypewriterProps = WithTheme<{\n $cursorType: TypewriterProps['cursorType'];\n $isAnimatingText: boolean;\n $shouldHideCursor: TypewriterProps['shouldHideCursor'];\n $shouldPreventBlinkAnimation: boolean;\n}>;\n\nconst typewriterCursorElement = ({\n $cursorType,\n $isAnimatingText,\n $shouldHideCursor,\n $shouldPreventBlinkAnimation,\n}: StyledTypewriterProps) => {\n if (!$isAnimatingText || $shouldHideCursor) {\n return '';\n }\n\n if ($cursorType === CursorType.Thin) {\n return css`\n .typewriter-lastWithContent {\n &:after {\n animation: ${$shouldPreventBlinkAnimation ? 'none' : blinkAnimation} 1s steps(2, start) infinite;\n color: inherit;\n content: '|';\n font-size: 25px;\n position: relative;\n line-height: 0;\n vertical-align: baseline;\n }\n `;\n }\n\n return css`\n .typewriter-lastWithContent {\n &:after {\n animation: ${blinkAnimation} 1s steps(2, start) infinite;\n color: ${({ theme }: StyledTypewriterTextProps) => theme.text};\n content: '▋';\n margin-left: 0.25rem;\n opacity: 0.85;\n position: relative;\n vertical-align: baseline;\n }\n }\n `;\n};\n\nexport const StyledTypewriter = styled.div<StyledTypewriterProps>`\n align-items: inherit;\n display: flex;\n position: relative;\n width: 100%;\n ${typewriterCursorElement}\n`;\n\nconst blinkAnimation = keyframes`\n 100% {\n visibility: hidden;\n }\n`;\n\ntype StyledTypewriterPseudoTextProps = WithTheme<{\n $isAnimatingText?: boolean;\n $shouldHideCursor: TypewriterProps['shouldHideCursor'];\n}>;\n\nexport const StyledTypewriterPseudoText = styled.span<StyledTypewriterPseudoTextProps>`\n opacity: 0;\n pointer-events: none;\n user-select: none;\n width: fit-content;\n\n ${({ $isAnimatingText, $shouldHideCursor }) =>\n $isAnimatingText &&\n !$shouldHideCursor &&\n css`\n &:after {\n animation: ${blinkAnimation} 1s steps(2, start) infinite;\n color: inherit;\n content: '|';\n font-size: 25px;\n position: relative;\n line-height: 0;\n vertical-align: baseline;\n }\n `}\n`;\n\ntype StyledTypewriterTextProps = WithTheme<{\n $isAnimatingText?: boolean;\n}>;\n\nexport const StyledTypewriterText = styled.span<StyledTypewriterTextProps>`\n color: inherit;\n position: ${({ $isAnimatingText }) => ($isAnimatingText ? 'absolute' : 'relative')};\n width: fit-content;\n\n ${({ $isAnimatingText }) =>\n $isAnimatingText &&\n css`\n p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