@medely/fontawesome-svg-core 0.0.1 → 0.1.0

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/LICENSE.txt CHANGED
@@ -23,7 +23,7 @@ as SVG and JS file types.
23
23
  In the Font Awesome Free download, the SIL OFL license applies to all icons
24
24
  packaged as web and desktop font files.
25
25
 
26
- Copyright (c) 2023 Fonticons, Inc. (https://fontawesome.com)
26
+ Copyright (c) 2024 Fonticons, Inc. (https://fontawesome.com)
27
27
  with Reserved Font Name: "Font Awesome".
28
28
 
29
29
  This Font Software is licensed under the SIL Open Font License, Version 1.1.
@@ -123,7 +123,7 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
123
123
  In the Font Awesome Free download, the MIT license applies to all non-font and
124
124
  non-icon files.
125
125
 
126
- Copyright 2023 Fonticons, Inc.
126
+ Copyright 2024 Fonticons, Inc.
127
127
 
128
128
  Permission is hereby granted, free of charge, to any person obtaining a copy of
129
129
  this software and associated documentation files (the "Software"), to deal in the
package/README.md CHANGED
@@ -1,26 +1,26 @@
1
- # ../fontawesome-svg-core - SVG with JavaScript version
1
+ # @fortawesome/fontawesome-svg-core - SVG with JavaScript version
2
2
 
3
3
  > "I came here to chew bubblegum and install Font Awesome 6 - and I'm all out of bubblegum"
4
4
 
5
- [![npm](https://img.shields.io/npm/v/../fontawesome-svg-core.svg?style=flat-square)](https://www.npmjs.com/package/../fontawesome-svg-core)
5
+ [![npm](https://img.shields.io/npm/v/@fortawesome/fontawesome-svg-core.svg?style=flat-square)](https://www.npmjs.com/package/@fortawesome/fontawesome-svg-core)
6
6
 
7
7
  ## Installation
8
8
 
9
9
  ```
10
- $ npm i --save ../fontawesome-svg-core
10
+ $ npm i --save @fortawesome/fontawesome-svg-core
11
11
  ```
12
12
 
13
13
  Or
14
14
 
15
15
  ```
16
- $ yarn add ../fontawesome-svg-core
16
+ $ yarn add @fortawesome/fontawesome-svg-core
17
17
  ```
18
18
 
19
19
  ## Documentation
20
20
 
21
- Get started [here](https://fontawesome.com/how-to-use/on-the-web/setup/getting-started). Continue your journey [here](https://fontawesome.com/how-to-use/on-the-web/advanced).
21
+ Get started [here](https://docs.fontawesome.com/web/setup/get-started). Continue your journey [here](https://docs.fontawesome.com/web/setup/packages).
22
22
 
23
- Or go straight to the [API documentation](https://fontawesome.com/how-to-use/with-the-api).
23
+ Or go straight to the [API documentation](https://docs.fontawesome.com/apis/javascript/get-started).
24
24
 
25
25
  ## Issues and support
26
26
 
package/import.macro.d.ts CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  IconName,
4
4
  IconStyle,
5
5
  IconFamily
6
- } from '../fontawesome-common-types';
6
+ } from '@fortawesome/fontawesome-common-types';
7
7
 
8
8
  export type IconMacroParams = {
9
9
  name: IconName,
package/import.macro.js CHANGED
@@ -1,21 +1,23 @@
1
- const { createMacro, MacroError } = require('babel-plugin-macros');
2
- const { addNamed } = require('@babel/helper-module-imports');
1
+ const { createMacro, MacroError } = require('babel-plugin-macros')
2
+ const { addNamed } = require('@babel/helper-module-imports')
3
+ const { FAFamilyIds, FAFamilyClassicId, FAFamilyDuotoneId } = require('@fortawesome-internal-tools/fontawesome-icons/canonical')
4
+ const { FALegacyStyleIds } = require('@fortawesome-internal-tools/fontawesome-icons/legacy')
3
5
 
4
6
  module.exports = createMacro(importer, {
5
- configName: 'fontawesome-svg-core',
6
- });
7
+ configName: 'fontawesome-svg-core'
8
+ })
7
9
 
8
- const styles = ['solid', 'regular', 'light', 'thin', 'duotone', 'brands'];
10
+ const styles = FALegacyStyleIds
9
11
 
10
- const macroNames = [...styles, 'icon'];
12
+ const macroNames = [...styles, 'icon']
11
13
 
12
- const families = ['classic', 'duotone', 'sharp'];
14
+ const families = FAFamilyIds.map((family) => family.toLowerCase())
13
15
 
14
16
  function importer({ references, state, babel, source, config }) {
15
- const license = config !== undefined ? config.license : 'free';
17
+ const license = config !== undefined ? config.license : 'free'
16
18
 
17
19
  if (!['free', 'pro'].includes(license)) {
18
- throw new Error("config license must be either 'free' or 'pro'");
20
+ throw new Error("config license must be either 'free' or 'pro'")
19
21
  }
20
22
 
21
23
  Object.keys(references).forEach((key) => {
@@ -25,67 +27,58 @@ function importer({ references, state, babel, source, config }) {
25
27
  references: references[key],
26
28
  state,
27
29
  babel,
28
- source,
29
- });
30
- });
30
+ source
31
+ })
32
+ })
31
33
  }
32
34
 
33
35
  function replace({ macroName, license, references, state, babel, source }) {
34
36
  references.forEach((nodePath) => {
35
- const { iconName, style, family } = resolveReplacement({ nodePath, babel, state, macroName });
37
+ const { iconName, style, family } = resolveReplacement({ nodePath, babel, state, macroName })
36
38
 
37
- const name = `fa${capitalize(camelCase(iconName))}`;
38
- const importFrom = getImport({ family, style, license, name });
39
+ const name = `fa${capitalize(camelCase(iconName))}`
40
+ const importFrom = getImport({ family, style, license, name })
39
41
 
40
- const importName = addNamed(nodePath, name, importFrom);
42
+ const importName = addNamed(nodePath, name, importFrom)
41
43
 
42
- nodePath.parentPath.replaceWith(importName);
43
- });
44
+ nodePath.parentPath.replaceWith(importName)
45
+ })
44
46
  }
45
47
 
46
48
  function getImport({ family, style, license, name }) {
47
49
  if (family) {
48
- return `../${family.toLowerCase()}-${style}-svg-icons/${name}`;
50
+ return `@fortawesome/${family.toLowerCase()}-${style}-svg-icons/${name}`
49
51
  } else if (style === 'brands') {
50
- return `../free-brands-svg-icons/${name}`;
52
+ return `@fortawesome/free-brands-svg-icons/${name}`
51
53
  } else {
52
- return `../${license}-${style}-svg-icons/${name}`;
54
+ return `@fortawesome/${license}-${style}-svg-icons/${name}`
53
55
  }
54
56
  }
55
57
 
56
58
  function resolveReplacement({ nodePath, babel, state, macroName }) {
57
59
  if ('icon' === macroName) {
58
- return resolveReplacementIcon({ nodePath, babel, state, macroName });
60
+ return resolveReplacementIcon({ nodePath, babel, state, macroName })
59
61
  } else {
60
- return resolveReplacementLegacyStyle({ nodePath, babel, state, macroName });
62
+ return resolveReplacementLegacyStyle({ nodePath, babel, state, macroName })
61
63
  }
62
64
  }
63
65
 
64
66
  // The macros corresonding to legacy style names: solid(), regular(), light(), thin(), duotone(), brands().
65
67
  function resolveReplacementLegacyStyle({ nodePath, babel, state, macroName }) {
66
- const { types: t } = babel;
67
- const { parentPath } = nodePath;
68
+ const { types: t } = babel
69
+ const { parentPath } = nodePath
68
70
 
69
71
  if (!styles.includes(macroName)) {
70
- throw parentPath.buildCodeFrameError(
71
- `${macroName} is not a valid macro name. Use one of ${macroNames.join(', ')}`,
72
- MacroError,
73
- );
72
+ throw parentPath.buildCodeFrameError(`${macroName} is not a valid macro name. Use one of ${macroNames.join(', ')}`, MacroError)
74
73
  }
75
74
 
76
75
  if (parentPath.node.arguments) {
77
76
  if (parentPath.node.arguments.length < 1) {
78
- throw parentPath.buildCodeFrameError(
79
- `Received an invalid number of arguments for ${macroName} macro: must be exactly 1`,
80
- MacroError,
81
- );
77
+ throw parentPath.buildCodeFrameError(`Received an invalid number of arguments for ${macroName} macro: must be exactly 1`, MacroError)
82
78
  }
83
79
 
84
80
  if (parentPath.node.arguments.length > 1) {
85
- throw parentPath.buildCodeFrameError(
86
- `Received an invalid number of arguments for ${macroName} macro: must be exactly 1`,
87
- MacroError,
88
- );
81
+ throw parentPath.buildCodeFrameError(`Received an invalid number of arguments for ${macroName} macro: must be exactly 1`, MacroError)
89
82
  }
90
83
 
91
84
  if (
@@ -93,209 +86,135 @@ function resolveReplacementLegacyStyle({ nodePath, babel, state, macroName }) {
93
86
  t.isStringLiteral(parentPath.node.arguments[0]) &&
94
87
  nodePath.parentPath.node.arguments[0].value.startsWith('fa-')
95
88
  ) {
96
- throw parentPath.buildCodeFrameError(
97
- `Don't begin the icon name with fa-, just use ${nodePath.parentPath.node.arguments[0].value.slice(
98
- 3,
99
- )}`,
100
- MacroError,
101
- );
89
+ throw parentPath.buildCodeFrameError(`Don't begin the icon name with fa-, just use ${nodePath.parentPath.node.arguments[0].value.slice(3)}`, MacroError)
102
90
  }
103
91
 
104
- if (
105
- (parentPath.node.arguments.length === 1 || parentPath.node.arguments.length === 2) &&
106
- !t.isStringLiteral(parentPath.node.arguments[0])
107
- ) {
108
- throw parentPath.buildCodeFrameError(
109
- 'Only string literals are supported when referencing icons (use a string here instead)',
110
- MacroError,
111
- );
92
+ if ((parentPath.node.arguments.length === 1 || parentPath.node.arguments.length === 2) && !t.isStringLiteral(parentPath.node.arguments[0])) {
93
+ throw parentPath.buildCodeFrameError('Only string literals are supported when referencing icons (use a string here instead)', MacroError)
112
94
  }
113
95
  } else {
114
- throw parentPath.buildCodeFrameError(
115
- 'Pass the icon name you would like to import as an argument.',
116
- MacroError,
117
- );
96
+ throw parentPath.buildCodeFrameError('Pass the icon name you would like to import as an argument.', MacroError)
118
97
  }
119
98
 
120
99
  return {
121
100
  iconName: nodePath.parentPath.node.arguments[0].value,
122
101
  style: macroName,
123
- family: undefined,
124
- };
102
+ family: undefined
103
+ }
125
104
  }
126
105
 
127
106
  // The icon() macro.
128
107
  function resolveReplacementIcon({ nodePath, babel, state, macroName }) {
129
- const { types: t } = babel;
130
- const { parentPath } = nodePath;
108
+ const { types: t } = babel
109
+ const { parentPath } = nodePath
131
110
 
132
111
  if ('icon' !== macroName) {
133
- throw parentPath.buildCodeFrameError(
134
- `${macroName} is not a valid macro name. Use one of ${macroNames.join(', ')}`,
135
- MacroError,
136
- );
112
+ throw parentPath.buildCodeFrameError(`${macroName} is not a valid macro name. Use one of ${macroNames.join(', ')}`, MacroError)
137
113
  }
138
114
 
139
115
  if (parentPath.node.arguments.length !== 1) {
140
- throw parentPath.buildCodeFrameError(
141
- `Received an invalid number of arguments for ${macroName} macro: must be exactly 1`,
142
- MacroError,
143
- );
116
+ throw parentPath.buildCodeFrameError(`Received an invalid number of arguments for ${macroName} macro: must be exactly 1`, MacroError)
144
117
  }
145
118
 
146
119
  if (!t.isObjectExpression(parentPath.node.arguments[0])) {
147
120
  throw parentPath.buildCodeFrameError(
148
121
  "Only object expressions are supported when referencing icons with this macro, like this: { name: 'star' }",
149
- MacroError,
150
- );
122
+ MacroError
123
+ )
151
124
  }
152
125
 
153
- const properties = parentPath.node.arguments[0].properties || [];
126
+ const properties = parentPath.node.arguments[0].properties || []
154
127
 
155
- const namePropIndex = properties.findIndex((prop) => 'name' === prop.key.name);
128
+ const namePropIndex = properties.findIndex((prop) => 'name' === prop.key.name)
156
129
 
157
- const name =
158
- namePropIndex >= 0
159
- ? getStringLiteralPropertyValue(
160
- t,
161
- parentPath,
162
- parentPath.node.arguments[0].properties[namePropIndex],
163
- )
164
- : undefined;
130
+ const name = namePropIndex >= 0 ? getStringLiteralPropertyValue(t, parentPath, parentPath.node.arguments[0].properties[namePropIndex]) : undefined
165
131
 
166
132
  if (!name) {
167
- throw parentPath.buildCodeFrameError(
168
- 'The object argument to the icon() macro must have a name property',
169
- MacroError,
170
- );
133
+ throw parentPath.buildCodeFrameError('The object argument to the icon() macro must have a name property', MacroError)
171
134
  }
172
135
 
173
- const stylePropIndex = properties.findIndex((prop) => 'style' === prop.key.name);
136
+ const stylePropIndex = properties.findIndex((prop) => 'style' === prop.key.name)
174
137
 
175
- let style =
176
- stylePropIndex >= 0
177
- ? getStringLiteralPropertyValue(
178
- t,
179
- parentPath,
180
- parentPath.node.arguments[0].properties[stylePropIndex],
181
- )
182
- : undefined;
138
+ let style = stylePropIndex >= 0 ? getStringLiteralPropertyValue(t, parentPath, parentPath.node.arguments[0].properties[stylePropIndex]) : undefined
183
139
 
184
140
  if (style && !styles.includes(style)) {
185
- throw parentPath.buildCodeFrameError(
186
- `Invalid style name: ${style}. It must be one of the following: ${styles.join(', ')}`,
187
- MacroError,
188
- );
141
+ throw parentPath.buildCodeFrameError(`Invalid style name: ${style}. It must be one of the following: ${styles.join(', ')}`, MacroError)
189
142
  }
190
143
 
191
- const familyPropIndex = properties.findIndex((prop) => 'family' === prop.key.name);
144
+ const familyPropIndex = properties.findIndex((prop) => 'family' === prop.key.name)
192
145
 
193
- let family =
194
- familyPropIndex >= 0
195
- ? getStringLiteralPropertyValue(
196
- t,
197
- parentPath,
198
- parentPath.node.arguments[0].properties[familyPropIndex],
199
- )
200
- : undefined;
146
+ let family = familyPropIndex >= 0 ? getStringLiteralPropertyValue(t, parentPath, parentPath.node.arguments[0].properties[familyPropIndex]) : undefined
201
147
 
202
148
  if (family && !families.includes(family)) {
203
- throw parentPath.buildCodeFrameError(
204
- `Invalid family name: ${family}. It must be one of the following: ${families.join(', ')}`,
205
- MacroError,
206
- );
149
+ throw parentPath.buildCodeFrameError(`Invalid family name: ${family}. It must be one of the following: ${families.join(', ')}`, MacroError)
207
150
  }
208
151
 
209
- if ('duotone' === style && family && 'classic' !== family) {
210
- throw parentPath.buildCodeFrameError(
211
- `duotone cannot be used as a style name with any family other than classic`,
212
- MacroError,
213
- );
152
+ if (FAFamilyDuotoneId === style && family && FAFamilyClassicId !== family) {
153
+ throw parentPath.buildCodeFrameError(`duotone cannot be used as a style name with any family other than classic`, MacroError)
214
154
  }
215
155
 
216
- if ('brands' === style && family && 'classic' !== family) {
217
- throw parentPath.buildCodeFrameError(
218
- `brands cannot be used as a style name with any family other than classic`,
219
- MacroError,
220
- );
156
+ if ('brands' === style && family && FAFamilyClassicId !== family) {
157
+ throw parentPath.buildCodeFrameError(`brands cannot be used as a style name with any family other than classic`, MacroError)
221
158
  }
222
159
 
223
160
  if (family && !style) {
224
- throw parentPath.buildCodeFrameError(
225
- `When a family is specified, a style must also be specified`,
226
- MacroError,
227
- );
161
+ throw parentPath.buildCodeFrameError(`When a family is specified, a style must also be specified`, MacroError)
228
162
  }
229
163
 
230
- if ('duotone' === style || 'duotone' === family) {
231
- family = undefined;
232
- style = 'duotone';
164
+ if (FAFamilyDuotoneId === style || FAFamilyDuotoneId === family) {
165
+ family = undefined
166
+ style = FAFamilyDuotoneId
233
167
  }
234
168
 
235
169
  if ('brands' === style) {
236
- family = undefined;
170
+ family = undefined
237
171
  }
238
172
 
239
173
  // defaults
240
174
  if (!style) {
241
- style = 'solid';
175
+ style = 'solid'
242
176
  }
243
177
 
244
- if ('classic' === family) {
245
- family = undefined;
178
+ if (FAFamilyClassicId === family) {
179
+ family = undefined
246
180
  }
247
181
 
248
182
  return {
249
183
  iconName: name,
250
184
  family,
251
- style,
252
- };
185
+ style
186
+ }
253
187
  }
254
188
 
255
189
  function getStringLiteralPropertyValue(t, parentPath, property) {
256
190
  if (!('object' === typeof t && 'function' === typeof t.isStringLiteral)) {
257
- throw Error(
258
- 'ERROR: invalid babel-types arg. This is probably a programming error in import.macro',
259
- );
191
+ throw Error('ERROR: invalid babel-types arg. This is probably a programming error in import.macro')
260
192
  }
261
193
 
262
- if (
263
- !(
264
- 'object' === typeof property &&
265
- 'object' === typeof property.value &&
266
- 'object' === typeof property.key
267
- )
268
- ) {
269
- throw Error(
270
- 'ERROR: invalid babel property arg. This is probably a programming error in import.macro',
271
- );
194
+ if (!('object' === typeof property && 'object' === typeof property.value && 'object' == typeof property.key)) {
195
+ throw Error('ERROR: invalid babel property arg. This is probably a programming error in import.macro')
272
196
  }
273
197
 
274
198
  if (!('object' === typeof parentPath && 'function' === typeof parentPath.buildCodeFrameError)) {
275
- throw Error(
276
- 'ERROR: invalid babel parentPath arg. This is probably a programming error in import.macro',
277
- );
199
+ throw Error('ERROR: invalid babel parentPath arg. This is probably a programming error in import.macro')
278
200
  }
279
201
 
280
202
  if (!t.isStringLiteral(property.value)) {
281
- throw parentPath.buildCodeFrameError(
282
- `Only string literals are supported for the ${property.key.name} property (use a string here instead)`,
283
- MacroError,
284
- );
203
+ throw parentPath.buildCodeFrameError(`Only string literals are supported for the ${property.key.name} property (use a string here instead)`, MacroError)
285
204
  }
286
205
 
287
- return property.value.value;
206
+ return property.value.value
288
207
  }
289
208
 
290
209
  function capitalize(str) {
291
- return str[0].toUpperCase() + str.slice(1);
210
+ return str[0].toUpperCase() + str.slice(1)
292
211
  }
293
212
 
294
213
  function camelCase(str) {
295
214
  return str
296
215
  .split('-')
297
216
  .map((s, index) => {
298
- return (index === 0 ? s[0].toLowerCase() : s[0].toUpperCase()) + s.slice(1).toLowerCase();
217
+ return (index === 0 ? s[0].toLowerCase() : s[0].toUpperCase()) + s.slice(1).toLowerCase()
299
218
  })
300
- .join('');
219
+ .join('')
301
220
  }
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import {IconDefinition, IconLookup, IconName, IconFamily, IconPrefix, CssStyleClass, IconStyle, IconPathData, IconPack} from '../fontawesome-common-types';
2
- export {IconDefinition, IconLookup, IconName, IconFamily, IconPrefix, CssStyleClass, IconStyle, IconPathData, IconPack} from '../fontawesome-common-types';
1
+ import {IconDefinition, IconLookup, IconName, IconFamily, IconPrefix, CssStyleClass, IconStyle, IconPathData, IconPack} from '@fortawesome/fontawesome-common-types';
2
+ export {IconDefinition, IconLookup, IconName, IconFamily, IconPrefix, CssStyleClass, IconStyle, IconPathData, IconPack} from '@fortawesome/fontawesome-common-types';
3
3
  export const dom: DOM;
4
4
  export const library: Library;
5
5
  export const parse: { transform(transformString: string): Transform, icon(parseIconString: string): IconLookup };
@@ -52,6 +52,7 @@ export interface Config {
52
52
  observeMutations: boolean;
53
53
  keepOriginalSource: boolean;
54
54
  measurePerformance: boolean;
55
+ mutateApproach: "async" | "sync";
55
56
  showMissingIcons: boolean;
56
57
  }
57
58
  export interface AbstractElement {
@@ -120,6 +121,6 @@ export interface DOM {
120
121
  }
121
122
  type IconDefinitionOrPack = IconDefinition | IconPack;
122
123
  export interface Library {
123
- add(...definitions: IconDefinitionOrPack[]): void;
124
+ add(...definitions: Array<IconDefinitionOrPack | IconDefinitionOrPack[]>): void;
124
125
  reset(): void;
125
126
  }