text-slicer 1.3.0 → 1.3.1-dev.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/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var d=(a,t,e)=>t in a?l(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var i=(a,t,e)=>d(a,typeof t!="symbol"?t+"":t,e);class o{constructor(t={}){i(this,"textElement");i(this,"originalText");i(this,"splitMode");i(this,"cssVariables");i(this,"dataAttributes");i(this,"charIndexCounter");var e;if(this.textElement=t.container instanceof HTMLElement?t.container:document.querySelector(t.container||".text-slicer"),!this.textElement)return this.originalText="",this.splitMode="both",this.cssVariables=!1,this.dataAttributes=!1,void(this.charIndexCounter=0);this.originalText=((e=this.textElement.textContent)==null?void 0:e.trim())||"",this.splitMode=t.splitMode||"both",this.cssVariables=t.cssVariables||!1,this.dataAttributes=t.dataAttributes||!1,this.charIndexCounter=0}split(){if(!this.textElement)return;this.clear(),this.charIndexCounter=0;const t=document.createDocumentFragment(),e=this.originalText.split(" "),s=this.originalText.length;this.splitMode==="words"||this.splitMode==="both"?this.splitWords(t,e):this.splitMode==="chars"&&this.splitChars(t),this.textElement.appendChild(t),this.cssVariables&&(this.textElement.style.setProperty("--word-total",e.length.toString()),this.textElement.style.setProperty("--char-total",s.toString()))}splitWords(t,e){e.forEach((s,n)=>{if(this.splitMode==="both"){const r=this.createWordSpan(n,s);s.split("").forEach(h=>{const c=this.createCharSpan(h);r.append(c)}),t.append(r)}else{const r=this.createWordSpan(n);r.append(document.createTextNode(s)),t.append(r)}n<e.length-1&&t.append(o.createSpaceSpan())})}splitChars(t){this.originalText.split("").forEach(e=>{const s=this.createCharSpan(e);t.append(s)})}createWordSpan(t,e=""){const s=document.createElement("span");return s.classList.add("word"),this.dataAttributes&&s.setAttribute("data-word",e),this.cssVariables&&s.style.setProperty("--word-index",t.toString()),s}createCharSpan(t){const e=document.createElement("span");return e.textContent=t,this.dataAttributes&&e.setAttribute("data-char",t),t===" "?e.classList.add("whitespace"):(e.classList.add("char"),this.cssVariables&&e.style.setProperty("--char-index",this.charIndexCounter.toString()),this.charIndexCounter+=1),e}static createSpaceSpan(){const t=document.createElement("span");return t.classList.add("whitespace"),t.textContent=" ",t}clear(){this.textElement&&(this.textElement.innerHTML="")}init(){this.split()}}module.exports=o;
1
+ "use strict";var l=Object.defineProperty;var d=(r,t,e)=>t in r?l(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var a=(r,t,e)=>d(r,typeof t!="symbol"?t+"":t,e);class h{constructor(t={}){a(this,"textElement");a(this,"originalText");a(this,"splitMode");a(this,"cssVariables");a(this,"dataAttributes");a(this,"charIndexCounter");var o;const{container:e=".text-slicer",splitMode:s="both",cssVariables:n=!1,dataAttributes:i=!1}=t;if(this.textElement=typeof e=="string"?document.querySelector(e):e??null,!this.textElement)return this.originalText="",this.splitMode="both",this.cssVariables=!1,this.dataAttributes=!1,void(this.charIndexCounter=0);this.originalText=((o=this.textElement.textContent)==null?void 0:o.trim())||"",this.splitMode=s,this.cssVariables=n,this.dataAttributes=i,this.charIndexCounter=0}split(){if(!this.textElement)return;this.clear(),this.charIndexCounter=0;const t=document.createDocumentFragment(),e=this.originalText.split(" "),s=this.originalText.length;this.splitMode==="words"||this.splitMode==="both"?this.splitWords(t,e):this.splitMode==="chars"&&this.splitChars(t),this.textElement.appendChild(t),this.cssVariables&&(this.textElement.style.setProperty("--word-total",e.length.toString()),this.textElement.style.setProperty("--char-total",s.toString()))}splitWords(t,e){e.forEach((s,n)=>{if(this.splitMode==="both"){const i=this.createWordSpan(n,s);s.split("").forEach(o=>{const c=this.createCharSpan(o);i.append(c)}),t.append(i)}else{const i=this.createWordSpan(n);i.append(document.createTextNode(s)),t.append(i)}n<e.length-1&&t.append(h.createSpaceSpan())})}splitChars(t){this.originalText.split("").forEach(e=>{const s=this.createCharSpan(e);t.append(s)})}createWordSpan(t,e=""){const s=document.createElement("span");return s.classList.add("word"),this.dataAttributes&&s.setAttribute("data-word",e),this.cssVariables&&s.style.setProperty("--word-index",t.toString()),s}createCharSpan(t){const e=document.createElement("span");return e.textContent=t,this.dataAttributes&&e.setAttribute("data-char",t),t===" "?e.classList.add("whitespace"):(e.classList.add("char"),this.cssVariables&&e.style.setProperty("--char-index",this.charIndexCounter.toString()),this.charIndexCounter+=1),e}static createSpaceSpan(){const t=document.createElement("span");return t.classList.add("whitespace"),t.textContent=" ",t}clear(){this.textElement&&(this.textElement.innerHTML="")}init(){this.split()}}module.exports=h;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ export type SplitMode = 'words' | 'chars' | 'both';
2
+ export interface TextSlicerOptions {
3
+ container?: HTMLElement | string;
4
+ splitMode?: SplitMode;
5
+ cssVariables?: boolean;
6
+ dataAttributes?: boolean;
7
+ }
1
8
  declare class TextSlicer {
2
9
  private readonly textElement;
3
10
  private originalText;
@@ -5,12 +12,7 @@ declare class TextSlicer {
5
12
  private readonly cssVariables;
6
13
  private readonly dataAttributes;
7
14
  private charIndexCounter;
8
- constructor(options?: {
9
- container?: HTMLElement | string;
10
- splitMode?: 'words' | 'chars' | 'both';
11
- cssVariables?: boolean;
12
- dataAttributes?: boolean;
13
- });
15
+ constructor(options?: TextSlicerOptions);
14
16
  split(): void;
15
17
  private splitWords;
16
18
  private splitChars;
package/dist/index.es.js CHANGED
@@ -1,17 +1,18 @@
1
1
  var l = Object.defineProperty;
2
- var d = (a, t, e) => t in a ? l(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
- var i = (a, t, e) => d(a, typeof t != "symbol" ? t + "" : t, e);
4
- class o {
2
+ var d = (r, t, e) => t in r ? l(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var a = (r, t, e) => d(r, typeof t != "symbol" ? t + "" : t, e);
4
+ class h {
5
5
  constructor(t = {}) {
6
- i(this, "textElement");
7
- i(this, "originalText");
8
- i(this, "splitMode");
9
- i(this, "cssVariables");
10
- i(this, "dataAttributes");
11
- i(this, "charIndexCounter");
12
- var e;
13
- if (this.textElement = t.container instanceof HTMLElement ? t.container : document.querySelector(t.container || ".text-slicer"), !this.textElement) return this.originalText = "", this.splitMode = "both", this.cssVariables = !1, this.dataAttributes = !1, void (this.charIndexCounter = 0);
14
- this.originalText = ((e = this.textElement.textContent) == null ? void 0 : e.trim()) || "", this.splitMode = t.splitMode || "both", this.cssVariables = t.cssVariables || !1, this.dataAttributes = t.dataAttributes || !1, this.charIndexCounter = 0;
6
+ a(this, "textElement");
7
+ a(this, "originalText");
8
+ a(this, "splitMode");
9
+ a(this, "cssVariables");
10
+ a(this, "dataAttributes");
11
+ a(this, "charIndexCounter");
12
+ var o;
13
+ const { container: e = ".text-slicer", splitMode: s = "both", cssVariables: n = !1, dataAttributes: i = !1 } = t;
14
+ if (this.textElement = typeof e == "string" ? document.querySelector(e) : e ?? null, !this.textElement) return this.originalText = "", this.splitMode = "both", this.cssVariables = !1, this.dataAttributes = !1, void (this.charIndexCounter = 0);
15
+ this.originalText = ((o = this.textElement.textContent) == null ? void 0 : o.trim()) || "", this.splitMode = s, this.cssVariables = n, this.dataAttributes = i, this.charIndexCounter = 0;
15
16
  }
16
17
  split() {
17
18
  if (!this.textElement) return;
@@ -22,16 +23,16 @@ class o {
22
23
  splitWords(t, e) {
23
24
  e.forEach((s, n) => {
24
25
  if (this.splitMode === "both") {
25
- const r = this.createWordSpan(n, s);
26
- s.split("").forEach((h) => {
27
- const c = this.createCharSpan(h);
28
- r.append(c);
29
- }), t.append(r);
26
+ const i = this.createWordSpan(n, s);
27
+ s.split("").forEach((o) => {
28
+ const c = this.createCharSpan(o);
29
+ i.append(c);
30
+ }), t.append(i);
30
31
  } else {
31
- const r = this.createWordSpan(n);
32
- r.append(document.createTextNode(s)), t.append(r);
32
+ const i = this.createWordSpan(n);
33
+ i.append(document.createTextNode(s)), t.append(i);
33
34
  }
34
- n < e.length - 1 && t.append(o.createSpaceSpan());
35
+ n < e.length - 1 && t.append(h.createSpaceSpan());
35
36
  });
36
37
  }
37
38
  splitChars(t) {
@@ -60,5 +61,5 @@ class o {
60
61
  }
61
62
  }
62
63
  export {
63
- o as default
64
+ h as default
64
65
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(s,n){typeof exports=="object"&&typeof module<"u"?module.exports=n():typeof define=="function"&&define.amd?define(n):(s=typeof globalThis<"u"?globalThis:s||self).TextSlicer=n()})(this,function(){"use strict";var l=Object.defineProperty;var d=(s,n,t)=>n in s?l(s,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[n]=t;var a=(s,n,t)=>d(s,typeof n!="symbol"?n+"":n,t);class s{constructor(t={}){a(this,"textElement");a(this,"originalText");a(this,"splitMode");a(this,"cssVariables");a(this,"dataAttributes");a(this,"charIndexCounter");var e;if(this.textElement=t.container instanceof HTMLElement?t.container:document.querySelector(t.container||".text-slicer"),!this.textElement)return this.originalText="",this.splitMode="both",this.cssVariables=!1,this.dataAttributes=!1,void(this.charIndexCounter=0);this.originalText=((e=this.textElement.textContent)==null?void 0:e.trim())||"",this.splitMode=t.splitMode||"both",this.cssVariables=t.cssVariables||!1,this.dataAttributes=t.dataAttributes||!1,this.charIndexCounter=0}split(){if(!this.textElement)return;this.clear(),this.charIndexCounter=0;const t=document.createDocumentFragment(),e=this.originalText.split(" "),i=this.originalText.length;this.splitMode==="words"||this.splitMode==="both"?this.splitWords(t,e):this.splitMode==="chars"&&this.splitChars(t),this.textElement.appendChild(t),this.cssVariables&&(this.textElement.style.setProperty("--word-total",e.length.toString()),this.textElement.style.setProperty("--char-total",i.toString()))}splitWords(t,e){e.forEach((i,o)=>{if(this.splitMode==="both"){const r=this.createWordSpan(o,i);i.split("").forEach(c=>{const h=this.createCharSpan(c);r.append(h)}),t.append(r)}else{const r=this.createWordSpan(o);r.append(document.createTextNode(i)),t.append(r)}o<e.length-1&&t.append(s.createSpaceSpan())})}splitChars(t){this.originalText.split("").forEach(e=>{const i=this.createCharSpan(e);t.append(i)})}createWordSpan(t,e=""){const i=document.createElement("span");return i.classList.add("word"),this.dataAttributes&&i.setAttribute("data-word",e),this.cssVariables&&i.style.setProperty("--word-index",t.toString()),i}createCharSpan(t){const e=document.createElement("span");return e.textContent=t,this.dataAttributes&&e.setAttribute("data-char",t),t===" "?e.classList.add("whitespace"):(e.classList.add("char"),this.cssVariables&&e.style.setProperty("--char-index",this.charIndexCounter.toString()),this.charIndexCounter+=1),e}static createSpaceSpan(){const t=document.createElement("span");return t.classList.add("whitespace"),t.textContent=" ",t}clear(){this.textElement&&(this.textElement.innerHTML="")}init(){this.split()}}return s});
1
+ (function(i,r){typeof exports=="object"&&typeof module<"u"?module.exports=r():typeof define=="function"&&define.amd?define(r):(i=typeof globalThis<"u"?globalThis:i||self).TextSlicer=r()})(this,function(){"use strict";var l=Object.defineProperty;var d=(i,r,t)=>r in i?l(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var n=(i,r,t)=>d(i,typeof r!="symbol"?r+"":r,t);class i{constructor(t={}){n(this,"textElement");n(this,"originalText");n(this,"splitMode");n(this,"cssVariables");n(this,"dataAttributes");n(this,"charIndexCounter");var h;const{container:e=".text-slicer",splitMode:s="both",cssVariables:o=!1,dataAttributes:a=!1}=t;if(this.textElement=typeof e=="string"?document.querySelector(e):e??null,!this.textElement)return this.originalText="",this.splitMode="both",this.cssVariables=!1,this.dataAttributes=!1,void(this.charIndexCounter=0);this.originalText=((h=this.textElement.textContent)==null?void 0:h.trim())||"",this.splitMode=s,this.cssVariables=o,this.dataAttributes=a,this.charIndexCounter=0}split(){if(!this.textElement)return;this.clear(),this.charIndexCounter=0;const t=document.createDocumentFragment(),e=this.originalText.split(" "),s=this.originalText.length;this.splitMode==="words"||this.splitMode==="both"?this.splitWords(t,e):this.splitMode==="chars"&&this.splitChars(t),this.textElement.appendChild(t),this.cssVariables&&(this.textElement.style.setProperty("--word-total",e.length.toString()),this.textElement.style.setProperty("--char-total",s.toString()))}splitWords(t,e){e.forEach((s,o)=>{if(this.splitMode==="both"){const a=this.createWordSpan(o,s);s.split("").forEach(h=>{const c=this.createCharSpan(h);a.append(c)}),t.append(a)}else{const a=this.createWordSpan(o);a.append(document.createTextNode(s)),t.append(a)}o<e.length-1&&t.append(i.createSpaceSpan())})}splitChars(t){this.originalText.split("").forEach(e=>{const s=this.createCharSpan(e);t.append(s)})}createWordSpan(t,e=""){const s=document.createElement("span");return s.classList.add("word"),this.dataAttributes&&s.setAttribute("data-word",e),this.cssVariables&&s.style.setProperty("--word-index",t.toString()),s}createCharSpan(t){const e=document.createElement("span");return e.textContent=t,this.dataAttributes&&e.setAttribute("data-char",t),t===" "?e.classList.add("whitespace"):(e.classList.add("char"),this.cssVariables&&e.style.setProperty("--char-index",this.charIndexCounter.toString()),this.charIndexCounter+=1),e}static createSpaceSpan(){const t=document.createElement("span");return t.classList.add("whitespace"),t.textContent=" ",t}clear(){this.textElement&&(this.textElement.innerHTML="")}init(){this.split()}}return i});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "text-slicer",
3
- "version": "1.3.0",
3
+ "version": "1.3.1-dev.1",
4
4
  "description": "TextSlicer is designed to split text within an HTML element into separate words and/or characters, wrapping each word and/or character in separate span elements.",
5
5
  "author": "ux-ui.pro",
6
6
  "license": "MIT",
@@ -16,9 +16,9 @@
16
16
  "scripts": {
17
17
  "clean": "rimraf dist",
18
18
  "build": "vite build",
19
- "lint:js": "eslint **/*.{ts,js}",
20
- "lint:fix:js": "eslint **/*.{ts,js} --fix",
21
- "format:js": "prettier --write **/*.{ts,js}",
19
+ "lint:js": "eslint src/**/*.{ts,js}",
20
+ "lint:fix:js": "eslint src/**/*.{ts,js} --fix",
21
+ "format:js": "prettier --write src/**/*.{ts,js}",
22
22
  "lint:fix": "yarn lint:fix:js && yarn format:js"
23
23
  },
24
24
  "source": "src/index.ts",
@@ -27,28 +27,32 @@
27
27
  "browser": "./dist/index.umd.js",
28
28
  "types": "dist/index.d.ts",
29
29
  "exports": {
30
- "import": "./dist/index.es.js",
31
- "require": "./dist/index.cjs.js"
30
+ ".": {
31
+ "require": "./dist/index.cjs.js",
32
+ "import": "./dist/index.es.js",
33
+ "default": "./dist/index.umd.js"
34
+ },
35
+ "./dist/*": "./dist/*"
32
36
  },
33
37
  "files": [
34
38
  "dist/"
35
39
  ],
36
40
  "devDependencies": {
37
- "@eslint/js": "9.21.0",
41
+ "@eslint/js": "9.22.0",
38
42
  "@rollup/plugin-terser": "0.4.4",
39
- "@types/node": "22.13.8",
40
- "@typescript-eslint/eslint-plugin": "8.25.0",
41
- "@typescript-eslint/parser": "8.25.0",
42
- "eslint": "9.18.0",
43
- "eslint-config-prettier": "10.0.2",
43
+ "@types/node": "22.13.10",
44
+ "@typescript-eslint/eslint-plugin": "8.26.0",
45
+ "@typescript-eslint/parser": "8.26.0",
46
+ "eslint": "9.22.0",
47
+ "eslint-config-prettier": "10.1.1",
44
48
  "eslint-import-resolver-typescript": "3.8.3",
45
49
  "eslint-plugin-import": "2.31.0",
46
50
  "globals": "16.0.0",
47
- "prettier": "3.5.2",
51
+ "prettier": "3.5.3",
48
52
  "rimraf": "6.0.1",
49
53
  "typescript": "5.8.2",
50
- "vite": "6.2.0",
51
- "vite-plugin-dts": "4.5.1"
54
+ "vite": "6.2.1",
55
+ "vite-plugin-dts": "4.5.3"
52
56
  },
53
57
  "keywords": [
54
58
  "text",
@@ -60,11 +64,8 @@
60
64
  "effects",
61
65
  "fragment",
62
66
  "words",
63
- "characters",
64
67
  "HTML",
65
- "processing",
66
68
  "CSS",
67
- "variables",
68
69
  "web",
69
70
  "development",
70
71
  "frontend",
@@ -73,8 +74,6 @@
73
74
  "custom",
74
75
  "effects",
75
76
  "textslicer",
76
- "js",
77
- "webdev",
78
- "textprocessing"
77
+ "js"
79
78
  ]
80
79
  }