Skip to content

Commit 4a30d3d

Browse files
committed
deps: updated template
- should fix any potential non-externalized deps problems
1 parent 51246fd commit 4a30d3d

13 files changed

+83
-33
lines changed

package.json

+13-11
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"gen:exports": "indexit update --ignore {Units,utils,internal}.ts -o '${path}.js'"
4444
},
4545
"dependencies": {
46-
"@alanscodelog/utils": "4.0.0-beta.5"
46+
"@alanscodelog/utils": "4.0.0-beta.9"
4747
},
4848
"peerDependencies": {
4949
"colorjs.io": "^0.4.3",
@@ -59,22 +59,22 @@
5959
},
6060
"devDependencies": {
6161
"@alanscodelog/commitlint-config": "^2.0.0",
62-
"@alanscodelog/eslint-config": "^4.0.3",
62+
"@alanscodelog/eslint-config": "^4.0.4",
6363
"@alanscodelog/semantic-release-config": "^3.0.0",
64-
"@alanscodelog/tsconfigs": "^3.1.3",
65-
"@types/node": "^20.4.1",
66-
"@typescript-eslint/eslint-plugin": "^5.61.0",
67-
"@typescript-eslint/parser": "^5.61.0",
64+
"@alanscodelog/tsconfigs": "^3.2.0",
65+
"@types/node": "^20.4.2",
66+
"@typescript-eslint/eslint-plugin": "^6.1.0",
67+
"@typescript-eslint/parser": "^6.1.0",
6868
"@vitest/coverage-c8": "^0.33.0",
6969
"@vue/eslint-config-typescript": "^11.0.3",
7070
"colorjs.io": "^0.4.5",
71-
"commitlint": "^17.6.6",
71+
"commitlint": "^17.6.7",
7272
"concurrently": "^8.2.0",
7373
"cross-env": "^7.0.3",
74-
"eslint": "^8.44.0",
74+
"eslint": "^8.45.0",
7575
"eslint-import-resolver-typescript": "^3.5.5",
7676
"eslint-plugin-import": "^2.27.5",
77-
"eslint-plugin-jsdoc": "^46.4.3",
77+
"eslint-plugin-jsdoc": "^46.4.4",
7878
"eslint-plugin-simple-import-sort": "^10.0.0",
7979
"eslint-plugin-vue": "^9.15.1",
8080
"fast-glob": "^3.3.0",
@@ -85,12 +85,14 @@
8585
"madge": "^6.1.0",
8686
"onchange": "^7.1.0",
8787
"semantic-release": "^21.0.7",
88-
"tailwindcss": "^3.3.2",
88+
"tailwindcss": "^3.3.3",
8989
"ts-node": "^10.9.1",
9090
"tsc-alias": "^1.8.7",
9191
"typedoc": "^0.24.8",
9292
"typescript": "^5.1.6",
93-
"vite": "^4.4.2",
93+
"vite": "^4.4.4",
94+
"vite-plugin-dts": "^3.3.1",
95+
"vite-plugin-externalize-deps": "^0.7.0",
9496
"vite-tsconfig-paths": "^4.2.0",
9597
"vitest": "^0.33.0"
9698
},

src/Base.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
export class Base {
22
protected _dependants: Base[] = []
3+
34
addDep(dep: any): void {
45
this._dependants.push(dep)
56
}
7+
68
removeDep(dep: any): void {
79
const i = this._dependants.indexOf(dep)
810
if (i >= 0) {
911
this._dependants.slice(i, 1)
1012
}
1113
}
14+
1215
protected _notify(): void {
1316
for (const dep of this._dependants) {
1417
dep.notify(this)
1518
}
1619
}
20+
1721
protected notify(..._any: any[]): void {
1822
throw new Error("Extending class must implement.")
1923
}

src/ControlVar.ts

+5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export class ControlVar<
3131
TVal extends Record<string, any> ? TVal : Record<"_", MakePrimitive<TVal>>,
3232
> extends Base {
3333
unit: (value: TUnit) => string
34+
3435
value!: TUnit
36+
3537
css: string = ""
3638

3739
constructor(
@@ -43,14 +45,17 @@ export class ControlVar<
4345
this.unit = unit
4446
this.set(value as any)
4547
}
48+
4649
set(value: MakePrimitive<TVal> | TUnit): void {
4750
this.value = (["number", "string", "boolean"].includes(typeof value) ? { _: value } : value) as TUnit
4851
this.notify()
4952
}
53+
5054
protected notify(): void {
5155
this.recompute()
5256
this._notify()
5357
}
58+
5459
protected recompute(): void {
5560
this.css = this.unit(this.value)
5661
}

src/InterpolatedVars.ts

+11
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,17 @@ export class InterpolatedVars<
6262
TUnit extends Record<string, any> = Record<string, any>,
6363
> extends Base {
6464
name: string
65+
6566
unit: (value: TUnit) => string
67+
6668
values!: Value<TUnit>
69+
6770
ready: boolean = false
71+
6872
value: Record<string, any>[] = []
73+
6974
interpolated: Record<string, string> = {}
75+
7076
options: InterpolatedVarsOptions<ControlVar<any, TUnit>> = {
7177
roundTo: 3,
7278
exclude: [],
@@ -76,6 +82,7 @@ export class InterpolatedVars<
7682
separator: "-",
7783
steps: 10,
7884
}
85+
7986
constructor(
8087
name: string,
8188
unit: (value: TUnit) => string,
@@ -92,10 +99,12 @@ export class InterpolatedVars<
9299
this.ready = true
93100
this.notify()
94101
}
102+
95103
setOpts(value: Partial<InterpolatedVarsOptions<ControlVar<any, TUnit>>>): void {
96104
this.options = { ...this.options, ...value }
97105
if (this.ready) { this.notify() }
98106
}
107+
99108
set(value: Value<TUnit>): void {
100109
// :/ https://github.com/microsoft/TypeScript/issues/50652
101110
type Stop = StopEntry<TUnit>
@@ -121,10 +130,12 @@ export class InterpolatedVars<
121130

122131
if (this.ready) { this.notify() }
123132
}
133+
124134
protected notify(): void {
125135
this.recompute()
126136
this._notify()
127137
}
138+
128139
protected recompute(): void {
129140
const valRes: Record<string, any>[] = []
130141
const interpolatedRes: Record<string, string> = {}

src/Theme.ts

+20
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,40 @@ import { escapeKey } from "./utils.js"
1111
*/
1212
export class Theme<TValues extends Record<string, InterpolatedVars<any> | ControlVar<any, any>> = Record<string, InterpolatedVars<any> | ControlVar<any, any>>> extends Base {
1313
protected ready: boolean = false
14+
1415
els: HTMLElement[] = []
16+
1517
css: Record<string, string> = {}
18+
1619
value: TValues = {} as any
20+
1721
options: { escapeChar: string } = {
1822
/** For replacing invalid css variable key characters. */
1923
escapeChar: "-",
2024
}
25+
2126
protected _listeners: Record<string, (() => void) []> = { change: []}
27+
2228
constructor(value: TValues, opts: Partial<Theme<TValues>["options"]> = {}) {
2329
super()
2430
this.add(value)
2531
this.setOpts(opts)
2632
this.recompute(false)
2733
this.ready = true
2834
}
35+
2936
setOpts(value: Partial<Theme<TValues>["options"]> = {}): void {
3037
this.options = { ...this.options, ...value }
3138
if (!this.ready) return
3239
this.notify()
3340
}
41+
3442
add(value: Record<string, ControlVar<any, any> | InterpolatedVars<any> >): void {
3543
for (const key of keys(value)) {
3644
this._add(key, value[key])
3745
}
3846
}
47+
3948
protected _add(key: string, value: InterpolatedVars<any> | ControlVar<any, any>): void {
4049
if (this.value[key]) throw new Error(`Key ${key} already exists in theme. Use set to change the value.`)
4150
if (this.ready) { this.value[key]?.removeDep(this) }
@@ -46,6 +55,7 @@ export class Theme<TValues extends Record<string, InterpolatedVars<any> | Contro
4655

4756
if (this.ready) { this.notify() }
4857
}
58+
4959
remove(key: string): void {
5060
if (!this.value[key]) return
5161
if (this.ready) { this.value[key]?.removeDep(this) }
@@ -57,6 +67,7 @@ export class Theme<TValues extends Record<string, InterpolatedVars<any> | Contro
5767
// NOTE the use of _, we don't need to recompute other keys
5868
if (this.ready) { this.notify() }
5969
}
70+
6071
set(key: string, value: InterpolatedVars<any> | ControlVar<any, any>): void {
6172
if (this.ready) { this.value[key]?.removeDep(this) }
6273

@@ -66,6 +77,7 @@ export class Theme<TValues extends Record<string, InterpolatedVars<any> | Contro
6677

6778
if (this.ready) { this.notify({ recompute: false }) }
6879
}
80+
6981
protected notify({ recompute = true }: { recompute?: boolean } = {}): void {
7082
if (!this.ready) return
7183
if (recompute) this.recompute(false)
@@ -77,15 +89,18 @@ export class Theme<TValues extends Record<string, InterpolatedVars<any> | Contro
7789
this._lastPropertiesSet = Theme.setElVariables(el, this.css, this._lastPropertiesSet)
7890
}
7991
}
92+
8093
on(type: "change", cb: () => void): void {
8194
this._listeners[type].push(cb)
8295
}
96+
8397
off(type: "change", cb: () => void): void {
8498
const i = this._listeners[type].findIndex(cb)
8599
if (i > -1) {
86100
this._listeners[type].splice(i, 1)
87101
}
88102
}
103+
89104
protected _generateCss(
90105
res: Record<string, string>,
91106
key: string,
@@ -127,7 +142,9 @@ export class Theme<TValues extends Record<string, InterpolatedVars<any> | Contro
127142
}
128143
this.css = res
129144
}
145+
130146
protected _lastPropertiesSet: string[] = []
147+
131148
// todo move to utils?
132149
/**
133150
* Set css variables on an element.
@@ -147,6 +164,7 @@ export class Theme<TValues extends Record<string, InterpolatedVars<any> | Contro
147164
}
148165
return newLastPropertiesSet
149166
}
167+
150168
/**
151169
* Attach to an element and automatically set and update the theme's properties on it.
152170
*
@@ -156,6 +174,7 @@ export class Theme<TValues extends Record<string, InterpolatedVars<any> | Contro
156174
this.els.push(el)
157175
this._lastPropertiesSet = Theme.setElVariables(el, this.css, this._lastPropertiesSet)
158176
}
177+
159178
detach(el: HTMLElement = document.documentElement): void {
160179
const existing = this.els.indexOf(el)
161180
if (existing >= 0) {
@@ -168,6 +187,7 @@ export class Theme<TValues extends Record<string, InterpolatedVars<any> | Contro
168187
console.warn("Was not attached to element:", el)
169188
}
170189
}
190+
171191
/**
172192
* Write theme variables to get autocomplete while developing. Only works from node.
173193
*

tests/BaseTheme.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { keys, pretty, testName } from "@alanscodelog/utils"
1+
import { keys } from "@alanscodelog/utils"
2+
import { testName } from "@alanscodelog/utils/testing"
23
import { describe, expect, it } from "vitest"
34

45
import { baseTheme } from "../src/BaseTheme.js"

tests/ControlVar.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { testName } from "@alanscodelog/utils"
1+
import { testName } from "@alanscodelog/utils/testing"
22
import { describe, expect, it } from "vitest"
33

44
import { ControlVar } from "../src/ControlVar.js"

tests/InterpolatedVar.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expectType, testName } from "@alanscodelog/utils"
1+
import { expectType, testName } from "@alanscodelog/utils/testing"
22
import { describe, expect, it } from "vitest"
33

44
import { ControlVar } from "../src/ControlVar.js"

tests/README.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { testName } from "@alanscodelog/utils"
1+
import { testName } from "@alanscodelog/utils/testing"
22
import Color from "colorjs.io"
33
import { describe, it } from "vitest"
44

tests/Theme.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { testName } from "@alanscodelog/utils"
1+
import { testName } from "@alanscodelog/utils/testing"
22
import { describe, expect, it, vi } from "vitest"
33

44
import { ControlVar } from "../src/ControlVar.js"

tests/template.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { testName } from "@alanscodelog/utils"
1+
import { testName } from "@alanscodelog/utils/testing"
22
import { describe, expect, it } from "vitest"
33

44

tsconfig.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
"target": "ESNext",
99
"outDir": "dist",
1010
// "baseUrl": "src",
11-
"lib": [ "dom", "esnext" ],
12-
"noErrorTruncation":true,
13-
"importsNotUsedAsValues": "remove", // todo - workaround for https://github.com/microsoft/TypeScript/issues/53302 - must remove from main config package
11+
"lib": [
12+
"dom",
13+
"esnext"
14+
],
15+
"noErrorTruncation": true,
1416
"verbatimModuleSyntax": true,
15-
1617
"moduleResolution": "bundler"
1718
},
1819
"include": [

0 commit comments

Comments
 (0)