@procaaso/alphinity-ui-components 1.12.0 → 1.13.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/dist/index.cjs CHANGED
@@ -88,7 +88,9 @@ __export(index_exports, {
88
88
  generateRoutePoints: () => generateRoutePoints,
89
89
  getAppearanceDefaults: () => getAppearanceDefaults,
90
90
  getAppearanceSchema: () => getAppearanceSchema,
91
+ getAvailableBadgeGlyphs: () => getAvailableBadgeGlyphs,
91
92
  getAvailableSymbols: () => getAvailableSymbols,
93
+ getBadgeGlyph: () => getBadgeGlyph,
92
94
  getPortWorldPosition: () => getPortWorldPosition,
93
95
  getSymbolDefinition: () => getSymbolDefinition,
94
96
  importDiagram: () => importDiagram,
@@ -97,6 +99,8 @@ __export(index_exports, {
97
99
  normalizeDeviceStatus: () => normalizeDeviceStatus,
98
100
  overlayStyles: () => overlayStyles,
99
101
  readAppearanceValue: () => readAppearanceValue,
102
+ registerBadgeGlyph: () => registerBadgeGlyph,
103
+ registerBadgeGlyphs: () => registerBadgeGlyphs,
100
104
  registerSymbol: () => registerSymbol,
101
105
  registerSymbols: () => registerSymbols,
102
106
  resolvePresetColor: () => resolvePresetColor,
@@ -5150,6 +5154,32 @@ function writeAppearanceValue(node, field, value) {
5150
5154
  return { metadata: { ...node.metadata, [field.key]: value } };
5151
5155
  }
5152
5156
 
5157
+ // src/diagram/badges/nodeBadgeGlyphs.ts
5158
+ var PROHIBIT_GLYPH = {
5159
+ id: "prohibit",
5160
+ svgContent: '<circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2.4"/><line x1="5.6" y1="18.4" x2="18.4" y2="5.6" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"/>'
5161
+ };
5162
+ var builtInBadgeGlyphs = {
5163
+ [PROHIBIT_GLYPH.id]: PROHIBIT_GLYPH
5164
+ };
5165
+ var customBadgeGlyphs = {};
5166
+ function registerBadgeGlyph(glyph) {
5167
+ customBadgeGlyphs[glyph.id] = glyph;
5168
+ }
5169
+ function registerBadgeGlyphs(glyphs) {
5170
+ if (Array.isArray(glyphs)) {
5171
+ glyphs.forEach((glyph) => registerBadgeGlyph(glyph));
5172
+ } else {
5173
+ Object.values(glyphs).forEach((glyph) => registerBadgeGlyph(glyph));
5174
+ }
5175
+ }
5176
+ function getBadgeGlyph(glyphId) {
5177
+ return customBadgeGlyphs[glyphId] ?? builtInBadgeGlyphs[glyphId];
5178
+ }
5179
+ function getAvailableBadgeGlyphs() {
5180
+ return [...Object.keys(customBadgeGlyphs), ...Object.keys(builtInBadgeGlyphs)];
5181
+ }
5182
+
5153
5183
  // src/components/PIDCanvas/NodeRenderer.tsx
5154
5184
  var import_jsx_runtime17 = require("react/jsx-runtime");
5155
5185
  var HATCH_TILE_SIZE = 7;
@@ -5159,6 +5189,75 @@ var HATCH_STRIPE_OPACITY = 85 / 255;
5159
5189
  function isUnknownNode(node) {
5160
5190
  return node.positionUnknown === true || normalizeDeviceStatus(node.status) === "unknown";
5161
5191
  }
5192
+ var DEFAULT_BADGE_CORNER = "top-right";
5193
+ var DEFAULT_BADGE_SIZE = 14;
5194
+ var DEFAULT_BADGE_COLOR = "#111827";
5195
+ var DEFAULT_BADGE_BACKGROUND = "#d1d5db";
5196
+ var BADGE_GLYPH_BOX = 24;
5197
+ var BADGE_BLINK_KEYFRAME_ID = "pid-node-badge-blink-keyframes";
5198
+ var BADGE_BLINK_KEYFRAME_NAME = "pid-node-badge-blink";
5199
+ function ensureBadgeBlinkKeyframes() {
5200
+ if (typeof document === "undefined") return;
5201
+ if (document.getElementById(BADGE_BLINK_KEYFRAME_ID)) return;
5202
+ const style = document.createElement("style");
5203
+ style.id = BADGE_BLINK_KEYFRAME_ID;
5204
+ style.textContent = `@keyframes ${BADGE_BLINK_KEYFRAME_NAME}{0%{opacity:1}50%{opacity:.15}100%{opacity:1}}`;
5205
+ document.head.appendChild(style);
5206
+ }
5207
+ function badgeCenter(corner, vb, size) {
5208
+ const margin = size / 4;
5209
+ switch (corner) {
5210
+ case "top-left":
5211
+ return { x: -margin, y: -margin };
5212
+ case "bottom-left":
5213
+ return { x: -margin, y: vb.height + margin };
5214
+ case "bottom-right":
5215
+ return { x: vb.width + margin, y: vb.height + margin };
5216
+ case "top-right":
5217
+ default:
5218
+ return { x: vb.width + margin, y: -margin };
5219
+ }
5220
+ }
5221
+ function renderNodeBadge(badge, vb, rotation) {
5222
+ const glyphDef = getBadgeGlyph(badge.glyph);
5223
+ const size = badge.size ?? DEFAULT_BADGE_SIZE;
5224
+ const color = badge.color ?? DEFAULT_BADGE_COLOR;
5225
+ const backgroundColor = badge.backgroundColor ?? DEFAULT_BADGE_BACKGROUND;
5226
+ const corner = badge.corner ?? DEFAULT_BADGE_CORNER;
5227
+ const { x: cx, y: cy } = badgeCenter(corner, vb, size);
5228
+ const radius = size / 2;
5229
+ const glyphScale = size / BADGE_GLYPH_BOX;
5230
+ let blinkStyle;
5231
+ if (badge.blink) {
5232
+ ensureBadgeBlinkKeyframes();
5233
+ blinkStyle = {
5234
+ animation: `${BADGE_BLINK_KEYFRAME_NAME} ${badge.blinkPeriodMs}ms ease-in-out infinite`
5235
+ };
5236
+ }
5237
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
5238
+ "g",
5239
+ {
5240
+ "data-node-badge": badge.glyph,
5241
+ "data-badge-corner": corner,
5242
+ "data-badge-blink": badge.blink ? "true" : "false",
5243
+ "aria-label": badge.label,
5244
+ role: badge.label ? "img" : void 0,
5245
+ transform: rotation ? `translate(${cx}, ${cy}) rotate(${-rotation})` : `translate(${cx}, ${cy})`,
5246
+ style: blinkStyle,
5247
+ children: [
5248
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("circle", { r: radius, fill: backgroundColor }),
5249
+ glyphDef && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
5250
+ "g",
5251
+ {
5252
+ color,
5253
+ transform: `scale(${glyphScale}) translate(${-BADGE_GLYPH_BOX / 2}, ${-BADGE_GLYPH_BOX / 2})`,
5254
+ dangerouslySetInnerHTML: { __html: glyphDef.svgContent }
5255
+ }
5256
+ )
5257
+ ]
5258
+ }
5259
+ );
5260
+ }
5162
5261
  function NodeRendererImpl({
5163
5262
  nodes: nodes2,
5164
5263
  selectedNodeIds,
@@ -5365,7 +5464,8 @@ function NodeRendererImpl({
5365
5464
  transform: node.transform.rotation ? `rotate(${-node.transform.rotation}, ${labelX}, ${labelY})` : void 0,
5366
5465
  children: node.label || node.id
5367
5466
  }
5368
- )
5467
+ ),
5468
+ node.badge && renderNodeBadge(node.badge, vb, node.transform.rotation)
5369
5469
  ]
5370
5470
  },
5371
5471
  node.id
@@ -10461,7 +10561,9 @@ function useSimulation(telemetry, updateTelemetryBatch, options = {}) {
10461
10561
  generateRoutePoints,
10462
10562
  getAppearanceDefaults,
10463
10563
  getAppearanceSchema,
10564
+ getAvailableBadgeGlyphs,
10464
10565
  getAvailableSymbols,
10566
+ getBadgeGlyph,
10465
10567
  getPortWorldPosition,
10466
10568
  getSymbolDefinition,
10467
10569
  importDiagram,
@@ -10470,6 +10572,8 @@ function useSimulation(telemetry, updateTelemetryBatch, options = {}) {
10470
10572
  normalizeDeviceStatus,
10471
10573
  overlayStyles,
10472
10574
  readAppearanceValue,
10575
+ registerBadgeGlyph,
10576
+ registerBadgeGlyphs,
10473
10577
  registerSymbol,
10474
10578
  registerSymbols,
10475
10579
  resolvePresetColor,