@lightningjs/blits 1.7.0 → 1.7.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.7.1
4
+
5
+ _14 oct 2024_
6
+
7
+ - Fixed support for `.otf` and `.woff` fonts files in combination with MSDF generator
8
+
9
+
3
10
  ## v1.7.0
4
11
 
5
12
  _14 oct 2024_
@@ -125,9 +125,9 @@ Blits comes with a default keycode mapping. This mapping is a sensible default t
125
125
 
126
126
  But it's possible that the keycodes and mapping of your target device are slightly or even completely different.
127
127
 
128
- In Blits, you can easily configure the key mapping to match your needs. In the `src/index.js` file where we instantiate the App via the `Blits.Launch` function, we can add an extra key, called `keys`, to the _settings object_.
128
+ In Blits, you can easily configure the key mapping to match your needs. In the `src/index.js` file where we instantiate the App via the `Blits.Launch` function, we can add an extra key, called `keymap`, to the _settings object_.
129
129
 
130
- The `keys` item should be an object literal, where you map a `key` or `keyCode` (from the `KeyboardEvent`) to an event name that you can use in your Components.
130
+ The `keymap` should contain an object literal, where you map a `key` or `keyCode` (from the `KeyboardEvent`) to an event name that you can use in your Components.
131
131
 
132
132
  > You can use a site like [keyjs.dev](https://keyjs.dev/) to find the appropriate key and keyCode for your device
133
133
 
@@ -137,7 +137,7 @@ Blits.Launch(App, 'app', {
137
137
  w: 1920,
138
138
  h: 1080,
139
139
  //...
140
- keys: {
140
+ keymap: {
141
141
  // switch left and right using the key
142
142
  ArrowLeft: 'right',
143
143
  ArrowRight: 'left',
@@ -152,7 +152,7 @@ Blits.Launch(App, 'app', {
152
152
  })
153
153
  ```
154
154
 
155
- The custom keys object will be merged with the default key mapping, that looks like this:
155
+ The custom keymap object will be merged with the default key mapping, that looks like this:
156
156
 
157
157
  ```js
158
158
  const defaultKeyMap = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightningjs/blits",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Blits: The Lightning 3 App Development Framework",
5
5
  "bin": "bin/index.js",
6
6
  "exports": {
@@ -49,9 +49,19 @@ export default function () {
49
49
  if (!fs.existsSync(path.resolve(fontDir, file))) {
50
50
  const fontName = match[1]
51
51
  const ext = match[2]
52
- const fontFile = path.join(fontDir, `${fontName}.ttf`)
53
52
 
54
- if (fs.existsSync(fontFile)) {
53
+ // Attempt to find the font file with supported extensions
54
+ const supportedExtensions = ['ttf', 'otf', 'woff']
55
+ let fontFile = null
56
+ for (const fontExt of supportedExtensions) {
57
+ const potentialPath = path.join(fontDir, `${fontName}.${fontExt}`)
58
+ if (fs.existsSync(potentialPath)) {
59
+ fontFile = potentialPath
60
+ break
61
+ }
62
+ }
63
+
64
+ if (fontFile) {
55
65
  const generatedFontFile = path.join(
56
66
  msdfOutputDir,
57
67
  fontPath,
@@ -83,7 +93,7 @@ export default function () {
83
93
  next() // Handle case where generation might have failed
84
94
  }
85
95
  } else {
86
- next() // ttf file does not exist
96
+ next() // No supported font file found
87
97
  }
88
98
  } else {
89
99
  next() // file exists
@@ -95,18 +105,18 @@ export default function () {
95
105
  },
96
106
  // after build ends, the first hook is renderStart where we can modify the output
97
107
  async renderStart() {
98
- const ttfFiles = findAllTtfFiles(publicDir)
108
+ const fontFiles = findAllFontFiles(publicDir)
99
109
 
100
- for (const ttfFile of ttfFiles) {
101
- const relativePath = path.relative(publicDir, path.dirname(ttfFile))
102
- const baseName = path.basename(ttfFile).replace(/\.ttf$/i, '')
110
+ for (const fontFile of fontFiles) {
111
+ const relativePath = path.relative(publicDir, path.dirname(fontFile))
112
+ const baseName = path.basename(fontFile).replace(/\.(ttf|otf|woff)$/i, '')
103
113
  const msdfJsonPath = path.join(msdfOutputDir, relativePath, `${baseName}.msdf.json`)
104
114
  const msdfPngPath = path.join(msdfOutputDir, relativePath, `${baseName}.msdf.png`)
105
115
 
106
116
  // Check if MSDF files are generated, if not, generate them
107
117
  if (!fs.existsSync(msdfJsonPath) || !fs.existsSync(msdfPngPath)) {
108
- console.log(`Generating missing MSDF files for ${ttfFile}`)
109
- await generateSDF(ttfFile, path.join(msdfOutputDir, relativePath))
118
+ console.log(`Generating missing MSDF files for ${fontFile}`)
119
+ await generateSDF(fontFile, path.join(msdfOutputDir, relativePath))
110
120
  }
111
121
  }
112
122
 
@@ -129,17 +139,17 @@ const generateSDF = async (inputFilePath, outputDirPath) => {
129
139
  else console.error('Failed to generate MSDF file')
130
140
  }
131
141
 
132
- // finds all TTF files in a directory
133
- const findAllTtfFiles = (dir, filesList = []) => {
142
+ // Finds all font files (.ttf, .otf, .woff) in a directory
143
+ const findAllFontFiles = (dir, filesList = []) => {
134
144
  const files = fs.readdirSync(dir, { withFileTypes: true })
135
145
 
136
146
  files.forEach((file) => {
137
147
  if (file.isDirectory()) {
138
148
  const dirPath = path.join(dir, file.name)
139
- findAllTtfFiles(dirPath, filesList)
149
+ findAllFontFiles(dirPath, filesList)
140
150
  } else {
141
- // Check for all case variations of TTF extension
142
- if (file.name.match(/\.ttf$/i)) {
151
+ // Check for supported font extensions
152
+ if (file.name.match(/\.(ttf|otf|woff)$/i)) {
143
153
  filesList.push(path.join(dir, file.name))
144
154
  }
145
155
  }