@salesforce-ux/design-system-data
Version:
This package contains scripts to generate data and data assets for aspects of the Salesforce Lightning Design System (SLDS).
311 lines (274 loc) • 11.9 kB
JavaScript
var $fojLo$fs = require("fs");
var $fojLo$nconf = require("nconf");
var $fojLo$immutable = require("immutable");
var $fojLo$path = require("path");
var $fojLo$glob = require("glob");
var $fojLo$lodash = require("lodash");
var $fojLo$theolibutil = require("theo/lib/util");
var $parcel$global = globalThis;
var $parcel$modules = {};
var $parcel$inits = {};
var parcelRequire = $parcel$global["parcelRequire1c17"];
if (parcelRequire == null) {
parcelRequire = function(id) {
if (id in $parcel$modules) {
return $parcel$modules[id].exports;
}
if (id in $parcel$inits) {
var init = $parcel$inits[id];
delete $parcel$inits[id];
var module = {id: id, exports: {}};
$parcel$modules[id] = module;
init.call(module.exports, module, module.exports);
return module.exports;
}
var err = new Error("Cannot find module '" + id + "'");
err.code = 'MODULE_NOT_FOUND';
throw err;
};
parcelRequire.register = function register(id, init) {
$parcel$inits[id] = init;
};
$parcel$global["parcelRequire1c17"] = parcelRequire;
}
var parcelRegister = parcelRequire.register;
parcelRegister("i9tnC", function(module, exports) {
var $hAWqx = parcelRequire("hAWqx");
var $67Y3J = parcelRequire("67Y3J");
var $d36fdb7a8f11bdf9$require$writeFile = $67Y3J.writeFile;
const $d36fdb7a8f11bdf9$var$icons = $fojLo$immutable.fromJS($hAWqx || {});
const $d36fdb7a8f11bdf9$var$iconData = JSON.stringify($d36fdb7a8f11bdf9$var$icons);
$fojLo$nconf.argv();
const $d36fdb7a8f11bdf9$var$generateToFile = $fojLo$nconf.get("to-file");
const $d36fdb7a8f11bdf9$var$writeIconFile = (data)=>{
$d36fdb7a8f11bdf9$require$writeFile(data, "icons.json");
};
const $d36fdb7a8f11bdf9$var$generate = (data, toFile)=>{
if (!toFile) console.log(data);
return toFile ? $d36fdb7a8f11bdf9$var$writeIconFile(data) : data;
};
// Export the function writeFile as default
module.exports = $d36fdb7a8f11bdf9$var$generate($d36fdb7a8f11bdf9$var$iconData, $d36fdb7a8f11bdf9$var$generateToFile);
});
parcelRegister("hAWqx", function(module, exports) {
// @preval
// Copyright (c) 2015-present, Salesforce, Inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
var $ccf31ede08787015$var$$parcel$__dirname = $fojLo$path.resolve(__dirname, "../src/preval");
var $ccf31ede08787015$require$kebabCase = $fojLo$theolibutil.kebabCase;
var $18Px7 = parcelRequire("18Px7");
const $ccf31ede08787015$var$nodeModulesDir = $18Px7($ccf31ede08787015$var$$parcel$__dirname);
const $ccf31ede08787015$var$sldsModule = "@salesforce-ux/design-system";
const $ccf31ede08787015$var$categoryBase = $fojLo$immutable.fromJS({
/**
* Return true if an icon should be included in a category
*
* @param {object} icon
* @returns {boolean}
*/ filter (icon) {
return true;
},
/**
* Return the corresponding prop name from the design properties
*
* @param {object} icon
* @returns {string}
*/ getPropName (icon) {
return $fojLo$lodash.camelCase(icon.get("symbol"));
},
/**
* Return the className for a given icon
*
* @param {string} spriteName
* @param {string} symbolName
* @returns {string}
*/ getClassName (spriteName, symbolName) {
return `slds-icon-${symbolName}`;
},
/**
* Description displayed on the page
*/ description: "",
/**
* An optional object mapping of design tokens / values
*/ props: false
});
const $ccf31ede08787015$var$categories = $fojLo$immutable.Map({
utility: $ccf31ede08787015$var$categoryBase.merge($fojLo$immutable.fromJS({
getClassName (spriteName, symbolName) {
// Utility icons have no background, so we're not generating any class for it
return null;
},
description: "Utility icons are used throughout the interface and are SVG's for extensibility."
})),
doctype: $ccf31ede08787015$var$categoryBase.merge($fojLo$immutable.fromJS({
getClassName (spriteName, symbolName) {
// Doctype icons have no background, so we're not generating any class for it
return null;
},
description: "Doctype icons represent a type of file when a preview or image is unavailable"
})),
standard: $ccf31ede08787015$var$categoryBase.merge($fojLo$immutable.fromJS({
getClassName (spriteName, symbolName) {
return `slds-icon-${spriteName}-${symbolName}`;
},
description: "Standard icons represent entities and objects within Salesforce.",
props: require(`${$ccf31ede08787015$var$sldsModule}/design-tokens/dist/bg-standard.common.js`)
})),
custom: $ccf31ede08787015$var$categoryBase.merge($fojLo$immutable.fromJS({
getClassName (spriteName, symbolName) {
// The desired format is: `icon-custom-custom27`, following the icon names displayed on the page
// below each icon, and be consistent with the class names in other sets
return `slds-icon-${spriteName}-${symbolName.replace(/[^a-z0-9]/g, "")}`;
},
description: "Custom icons are available for the identity of user created objects.",
props: require(`${$ccf31ede08787015$var$sldsModule}/design-tokens/dist/bg-custom.common.js`)
})),
action: $ccf31ede08787015$var$categoryBase.merge($fojLo$immutable.fromJS({
filter (icon) {
return !/custom/.test(icon.get("symbol"));
},
getPropName (icon) {
// Currently, actions look like: "actionSomeAction"
return $fojLo$lodash.camelCase("action" + $fojLo$lodash.capitalize(icon.get("symbol")));
},
getClassName (spriteName, symbolName) {
return `slds-icon-${spriteName}-${symbolName}`;
},
description: "Actions can be seen throughout the interface and represent actions a user can take on any given screen.",
props: require(`${$ccf31ede08787015$var$sldsModule}/design-tokens/dist/bg-actions.common.js`)
}))
});
const $ccf31ede08787015$var$toIcon = (svg)=>{
const spriteName = $fojLo$path.basename($fojLo$path.dirname(svg));
const category = $ccf31ede08787015$var$categories.get(spriteName, $ccf31ede08787015$var$categoryBase);
const symbolName = $fojLo$path.basename(svg, ".svg");
const className = category.get("getClassName")(spriteName, $ccf31ede08787015$require$kebabCase(symbolName.toLowerCase()));
const iconSets = [
"action",
"custom",
"doctype",
"standard",
"utility"
];
const iconSynonyms = {
icon_synonyms: {}
};
iconSets.forEach((iconSet)=>{
let iconFile = `${$ccf31ede08787015$var$nodeModulesDir}/@salesforce-ux/design-system/metadata/icons/${iconSet}-icons-metadata.json`;
iconSynonyms.icon_synonyms[iconSet] = JSON.parse($fojLo$fs.readFileSync(iconFile, "utf-8"));
});
try {
var synonyms = iconSynonyms.icon_synonyms[spriteName][symbolName].synonyms;
synonyms.push(symbolName);
} catch {
var synonyms = [
symbolName
];
}
let icon = $fojLo$immutable.Map({
sprite: spriteName,
symbol: symbolName,
synonyms: synonyms,
visible: true,
className: className
});
// If a category has design props, add a class to symbols
// that don't have a corresponding value / generated className
if (category.has("props")) {
const name = category.get("getPropName")(icon);
if (!category.getIn([
"props",
name
])) icon = icon.update("className", (className)=>className + " slds-icon__svg--default");
}
return icon;
};
const $ccf31ede08787015$var$toIcons = (svgs)=>{
let sprites = $ccf31ede08787015$var$categories.keySeq().reduce((sprites, name)=>{
const category = $ccf31ede08787015$var$categories.get(name);
const category_ = $fojLo$immutable.fromJS({
name: name,
description: category.get("description"),
icons: []
});
return sprites.set(name, category_);
}, $fojLo$immutable.OrderedMap());
return svgs.reduce((sprites, svg)=>{
const icon = $ccf31ede08787015$var$toIcon(svg);
const spriteName = icon.get("sprite");
const category = $ccf31ede08787015$var$categories.get(spriteName, $ccf31ede08787015$var$categoryBase);
return category.get("filter")(icon) ? sprites.updateIn([
spriteName,
"icons"
], (icons)=>icons.push(icon)) : sprites;
}, sprites);
};
const $ccf31ede08787015$var$generate = ()=>{
const svgs = $fojLo$immutable.List($fojLo$glob.sync(`${$ccf31ede08787015$var$nodeModulesDir}/${$ccf31ede08787015$var$sldsModule}/assets/icons/**/*.svg`)).filter((p)=>!/-sprite/.test(p));
return $ccf31ede08787015$var$toIcons(svgs)// Natural sorting for only the custom section of icons
.updateIn([
"custom",
"icons"
], (icons)=>icons.sort((a, b)=>{
a = parseInt(a.get("symbol").replace(/^[^\d]*/, ""), 10);
b = parseInt(b.get("symbol").replace(/^[^\d]*/, ""), 10);
return a > b ? 1 : -1;
})).toList();
};
module.exports = $ccf31ede08787015$var$generate();
});
parcelRegister("18Px7", function(module, exports) {
module.exports = function findNodeModules(baseDir) {
let currentDir = baseDir;
while(currentDir !== $fojLo$path.resolve(currentDir, "..")){
// Stop when reaching the root
const candidatePath = $fojLo$path.join(currentDir, "node_modules");
if ($fojLo$fs.existsSync(candidatePath)) return candidatePath;
currentDir = $fojLo$path.resolve(currentDir, "..");
}
throw new Error("Unable to find node_modules directory.");
};
});
parcelRegister("67Y3J", function(module, exports) {
/**
* Gets the output path from command line arguments or defaults to current working directory
* @returns {string} The resolved output path
*/ const $4761fc068f0672f1$var$getOutputPath = ()=>{
$fojLo$nconf.argv();
return $fojLo$nconf.get("output") || process.cwd();
};
/**
* Writes data to a file in the specified output directory
* @param {string} data - The data to write
* @param {string} filename - The name of the file to create
* @param {string} outputPath - The output directory path (optional, defaults to current working directory)
*/ const $4761fc068f0672f1$var$writeFile = (data, filename, outputPath = null)=>{
const outputDir = $fojLo$path.resolve(outputPath || $4761fc068f0672f1$var$getOutputPath());
const outputFile = $fojLo$path.join(outputDir, filename);
// Ensure the output directory exists
if (!$fojLo$fs.existsSync(outputDir)) $fojLo$fs.mkdirSync(outputDir, {
recursive: true
});
$fojLo$fs.writeFile(outputFile, data, "utf8", (err)=>{
if (err) console.error(`Error writing ${filename}:`, err);
else console.log(`${filename} has been saved successfully to: ${outputFile}`);
});
};
/**
* Writes JSON data to a file in the specified output directory
* @param {Object} data - The data object to stringify and write
* @param {string} filename - The name of the file to create
* @param {string} outputPath - The output directory path (optional, defaults to current working directory)
* @param {number} indent - Number of spaces for indentation (optional, defaults to 2)
*/ const $4761fc068f0672f1$var$writeJsonFile = (data, filename, outputPath = null, indent = 2)=>{
const jsonData = JSON.stringify(data, null, indent);
$4761fc068f0672f1$var$writeFile(jsonData, filename, outputPath);
};
module.exports = {
getOutputPath: $4761fc068f0672f1$var$getOutputPath,
writeFile: $4761fc068f0672f1$var$writeFile,
writeJsonFile: $4761fc068f0672f1$var$writeJsonFile
};
});
parcelRequire("i9tnC");
//# sourceMappingURL=generateIcons.js.map