@c15t/dev-tools 2.0.0-rc.6 → 2.0.0-rc.8

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
@@ -1970,6 +1970,7 @@ var __webpack_exports__ = {};
1970
1970
  createDevToolsPanel: ()=>createDevToolsPanel,
1971
1971
  createDevTools: ()=>createDevTools
1972
1972
  });
1973
+ const external_c15t_namespaceObject = require("c15t");
1973
1974
  const DEVTOOLS_STORAGE_KEY = 'c15t-devtools-position';
1974
1975
  const DRAG_THRESHOLD = 30;
1975
1976
  const VELOCITY_THRESHOLD = 0.15;
@@ -2347,7 +2348,7 @@ var __webpack_exports__ = {};
2347
2348
  }
2348
2349
  return null;
2349
2350
  }
2350
- const version = '2.0.0-rc.6';
2351
+ const version = '2.0.0-rc.8';
2351
2352
  const DEVTOOLS_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 446 445" aria-label="c15t">
2352
2353
  <path fill="currentColor" d="M223.178.313c39.064 0 70.732 31.668 70.732 70.732-.001 39.064-31.668 70.731-70.732 70.731-12.181 0-23.642-3.079-33.649-8.502l-55.689 55.689a70.267 70.267 0 0 1 5.574 13.441h167.531c8.695-29.217 35.762-50.523 67.804-50.523 39.064 0 70.731 31.668 70.731 70.732s-31.668 70.732-70.731 70.732c-32.042 0-59.108-21.306-67.803-50.523H139.413a70.417 70.417 0 0 1-7.888 17.396l54.046 54.046c10.893-6.851 23.786-10.815 37.605-10.815 39.064 0 70.732 31.669 70.732 70.733 0 39.064-31.668 70.731-70.732 70.731s-70.732-31.667-70.732-70.731c0-10.518 2.296-20.499 6.414-29.471l-57.78-57.78c-8.972 4.117-18.952 6.414-29.47 6.414-39.063 0-70.731-31.668-70.732-70.732 0-39.064 31.669-70.732 70.733-70.732 12.18 0 23.642 3.079 33.649 8.502l55.688-55.688c-5.423-10.007-8.502-21.469-8.502-33.65 0-39.064 31.668-70.733 70.732-70.733Zm0 343.555c-16.742 0-30.314 13.572-30.314 30.314 0 16.741 13.572 30.313 30.314 30.313s30.314-13.572 30.314-30.313c0-16.742-13.572-30.314-30.314-30.314ZM71.611 192.299c-16.742 0-30.315 13.572-30.315 30.314s13.573 30.314 30.315 30.314c16.741 0 30.313-13.572 30.313-30.314 0-16.741-13.572-30.314-30.313-30.314Zm303.138 0c-16.729 0-30.294 13.551-30.315 30.275l.001.039-.001.038c.021 16.725 13.586 30.276 30.315 30.276 16.741 0 30.313-13.572 30.313-30.314 0-16.741-13.572-30.314-30.313-30.314ZM223.178 40.73c-16.742 0-30.314 13.573-30.314 30.315s13.573 30.313 30.314 30.313c16.742 0 30.313-13.572 30.314-30.313 0-16.742-13.572-30.314-30.314-30.315Z"/>
2353
2354
  </svg>`;
@@ -4069,7 +4070,8 @@ var __webpack_exports__ = {};
4069
4070
  'error',
4070
4071
  'consent',
4071
4072
  'network',
4072
- 'iab'
4073
+ 'iab',
4074
+ "script"
4073
4075
  ];
4074
4076
  function createFilterButton(filter, active, onClick) {
4075
4077
  return createButton({
@@ -4084,6 +4086,7 @@ var __webpack_exports__ = {};
4084
4086
  if ('error' === filter) return 'error' === event.type;
4085
4087
  if ('consent' === filter) return 'consent_set' === event.type || 'consent_save' === event.type || 'consent_reset' === event.type;
4086
4088
  if ('network' === filter) return 'network' === event.type;
4089
+ if ("script" === filter) return "script" === event.type;
4087
4090
  return 'iab' === event.type;
4088
4091
  }
4089
4092
  function matchesSearch(event, query) {
@@ -4207,6 +4210,8 @@ var __webpack_exports__ = {};
4207
4210
  return '◉';
4208
4211
  case 'iab':
4209
4212
  return '◆';
4213
+ case "script":
4214
+ return '⌘';
4210
4215
  default:
4211
4216
  return '○';
4212
4217
  }
@@ -4224,6 +4229,8 @@ var __webpack_exports__ = {};
4224
4229
  return 'var(--c15t-devtools-badge-warning, #f59e0b)';
4225
4230
  case 'iab':
4226
4231
  return 'var(--c15t-devtools-badge-info, #3b82f6)';
4232
+ case "script":
4233
+ return 'var(--c15t-devtools-badge-info, #14b8a6)';
4227
4234
  default:
4228
4235
  return 'var(--c15t-text-muted)';
4229
4236
  }
@@ -5524,6 +5531,20 @@ var __webpack_exports__ = {};
5524
5531
  <polyline points="8 6 2 12 8 18"></polyline>
5525
5532
  </svg>`;
5526
5533
  const scriptsSearchByContainer = new WeakMap();
5534
+ const expandedScriptsByContainer = new WeakMap();
5535
+ const CHEVRON_DOWN_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
5536
+ <polyline points="6 9 12 15 18 9"></polyline>
5537
+ </svg>`;
5538
+ const CHEVRON_RIGHT_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
5539
+ <polyline points="9 18 15 12 9 6"></polyline>
5540
+ </svg>`;
5541
+ function getExpandedScripts(container) {
5542
+ const existing = expandedScriptsByContainer.get(container);
5543
+ if (existing) return existing;
5544
+ const expanded = new Set();
5545
+ expandedScriptsByContainer.set(container, expanded);
5546
+ return expanded;
5547
+ }
5527
5548
  function renderScriptsPanel(container, options) {
5528
5549
  const { getState, getEvents } = options;
5529
5550
  clearElement(container);
@@ -5585,6 +5606,10 @@ var __webpack_exports__ = {};
5585
5606
  for (const script of filteredScripts){
5586
5607
  const scriptId = script.id;
5587
5608
  const isLoaded = true === loadedScripts[scriptId];
5609
+ const scriptEvents = getScriptActivityEvents(events, scriptId);
5610
+ const latestActivity = scriptEvents[scriptEvents.length - 1];
5611
+ const expandedScripts = getExpandedScripts(container);
5612
+ const isExpanded = expandedScripts.has(scriptId);
5588
5613
  const category = script.category;
5589
5614
  const categoryDisplay = 'string' == typeof category ? category : JSON.stringify(category);
5590
5615
  let status = 'pending';
@@ -5606,7 +5631,7 @@ var __webpack_exports__ = {};
5606
5631
  text: status.charAt(0).toUpperCase() + status.slice(1),
5607
5632
  variant: statusVariant
5608
5633
  });
5609
- const row = renderer_div({
5634
+ const header = renderer_div({
5610
5635
  style: {
5611
5636
  display: 'flex',
5612
5637
  alignItems: 'center',
@@ -5645,19 +5670,57 @@ var __webpack_exports__ = {};
5645
5670
  whiteSpace: 'nowrap'
5646
5671
  },
5647
5672
  text: `Category: ${categoryDisplay}`
5648
- })
5673
+ }),
5674
+ ...latestActivity && scriptEvents.length > 0 ? [
5675
+ renderer_div({
5676
+ style: {
5677
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5678
+ color: 'var(--c15t-text-muted)',
5679
+ overflow: 'hidden',
5680
+ textOverflow: 'ellipsis',
5681
+ whiteSpace: 'nowrap'
5682
+ },
5683
+ text: `Activity: ${latestActivity.message} (${scriptEvents.length} event${1 === scriptEvents.length ? '' : 's'})`
5684
+ })
5685
+ ] : []
5649
5686
  ]
5650
5687
  }),
5651
5688
  renderer_div({
5652
5689
  style: {
5653
- flexShrink: '0'
5690
+ flexShrink: '0',
5691
+ display: 'flex',
5692
+ alignItems: 'center',
5693
+ gap: '8px'
5654
5694
  },
5655
5695
  children: [
5656
- badge
5696
+ badge,
5697
+ ...scriptEvents.length > 0 ? [
5698
+ createAccordionToggle({
5699
+ scriptId,
5700
+ isExpanded,
5701
+ onToggle: ()=>{
5702
+ if (isExpanded) expandedScripts.delete(scriptId);
5703
+ else expandedScripts.add(scriptId);
5704
+ renderScriptsPanel(container, options);
5705
+ }
5706
+ })
5707
+ ] : []
5657
5708
  ]
5658
5709
  })
5659
5710
  ]
5660
5711
  });
5712
+ const details = isExpanded && scriptEvents.length > 0 ? createScriptActivityDetails(scriptEvents) : null;
5713
+ const row = renderer_div({
5714
+ style: {
5715
+ display: 'flex',
5716
+ flexDirection: 'column',
5717
+ borderBottom: '1px solid var(--c15t-border)'
5718
+ },
5719
+ children: [
5720
+ header,
5721
+ details
5722
+ ]
5723
+ });
5661
5724
  scriptsList.appendChild(row);
5662
5725
  }
5663
5726
  const lastRow = scriptsList.lastElementChild;
@@ -5794,13 +5857,172 @@ var __webpack_exports__ = {};
5794
5857
  return 'string' == typeof url ? url : event.message;
5795
5858
  }
5796
5859
  function formatEventTime(timestamp) {
5797
- return new Date(timestamp).toLocaleTimeString('en-US', {
5798
- hour12: false,
5799
- hour: '2-digit',
5800
- minute: '2-digit',
5801
- second: '2-digit'
5860
+ const date = new Date(timestamp);
5861
+ const hours = String(date.getHours()).padStart(2, '0');
5862
+ const minutes = String(date.getMinutes()).padStart(2, '0');
5863
+ const seconds = String(date.getSeconds()).padStart(2, '0');
5864
+ const milliseconds = String(date.getMilliseconds()).padStart(3, '0');
5865
+ return `${hours}:${minutes}:${seconds}.${milliseconds}`;
5866
+ }
5867
+ function getScriptActivityEvents(events, scriptId) {
5868
+ return events.filter((event)=>{
5869
+ if ("script" !== event.type) return false;
5870
+ const data = event.data;
5871
+ if (data?.scriptId !== scriptId) return false;
5872
+ return data?.scope === 'lifecycle' || data?.scope === 'phase';
5873
+ }).sort((left, right)=>left.timestamp - right.timestamp);
5874
+ }
5875
+ function createAccordionToggle(options) {
5876
+ const { scriptId, isExpanded, onToggle } = options;
5877
+ const toggle = renderer_button({
5878
+ ariaLabel: `${isExpanded ? 'Collapse' : 'Expand'} ${scriptId} activity`,
5879
+ ariaExpanded: isExpanded ? 'true' : 'false',
5880
+ style: {
5881
+ display: 'inline-flex',
5882
+ alignItems: 'center',
5883
+ justifyContent: 'center',
5884
+ width: '24px',
5885
+ height: '24px',
5886
+ padding: '0',
5887
+ border: '1px solid var(--c15t-border)',
5888
+ borderRadius: '6px',
5889
+ background: 'transparent',
5890
+ color: 'var(--c15t-text-muted)',
5891
+ cursor: 'pointer',
5892
+ flexShrink: '0'
5893
+ },
5894
+ onClick: onToggle
5895
+ });
5896
+ toggle.innerHTML = isExpanded ? CHEVRON_DOWN_ICON : CHEVRON_RIGHT_ICON;
5897
+ return toggle;
5898
+ }
5899
+ function createScriptActivityDetails(events) {
5900
+ const groupedEvents = groupScriptActivityEvents(events.slice(-8));
5901
+ return renderer_div({
5902
+ style: {
5903
+ display: 'flex',
5904
+ flexDirection: 'column',
5905
+ gap: '6px',
5906
+ padding: '0 0 10px 0',
5907
+ marginLeft: '0'
5908
+ },
5909
+ children: groupedEvents.map(([groupName, groupEvents])=>createScriptActivityGroup(groupName, groupEvents))
5802
5910
  });
5803
5911
  }
5912
+ function createScriptActivityGroup(groupName, events) {
5913
+ return renderer_div({
5914
+ style: {
5915
+ display: 'flex',
5916
+ flexDirection: 'column',
5917
+ gap: '4px'
5918
+ },
5919
+ children: [
5920
+ renderer_span({
5921
+ style: {
5922
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5923
+ fontWeight: '600',
5924
+ color: 'var(--c15t-text)',
5925
+ textTransform: 'none'
5926
+ },
5927
+ text: groupName
5928
+ }),
5929
+ ...events.map((event)=>createScriptActivityRow(event))
5930
+ ]
5931
+ });
5932
+ }
5933
+ function createScriptActivityRow(event) {
5934
+ const data = event.data ?? {};
5935
+ const scope = 'string' == typeof data.scope ? data.scope : void 0;
5936
+ const phase = 'string' == typeof data.phase ? data.phase : void 0;
5937
+ const stepType = 'string' == typeof data.stepType ? data.stepType : void 0;
5938
+ const metadata = [
5939
+ scope,
5940
+ phase,
5941
+ stepType
5942
+ ].filter(Boolean).join(' / ');
5943
+ return renderer_div({
5944
+ style: {
5945
+ display: 'flex',
5946
+ flexDirection: 'column',
5947
+ gap: '2px',
5948
+ padding: '6px 10px',
5949
+ marginLeft: '0',
5950
+ borderLeft: '2px solid var(--c15t-border)',
5951
+ backgroundColor: 'var(--c15t-devtools-surface-secondary, rgba(127,127,127,0.06))',
5952
+ borderRadius: '0 8px 8px 0'
5953
+ },
5954
+ children: [
5955
+ renderer_div({
5956
+ style: {
5957
+ display: 'flex',
5958
+ alignItems: 'center',
5959
+ justifyContent: 'space-between',
5960
+ gap: '8px'
5961
+ },
5962
+ children: [
5963
+ renderer_span({
5964
+ style: {
5965
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5966
+ fontWeight: '600',
5967
+ color: 'var(--c15t-text)'
5968
+ },
5969
+ text: event.message
5970
+ }),
5971
+ renderer_span({
5972
+ style: {
5973
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5974
+ color: 'var(--c15t-text-muted)',
5975
+ flexShrink: '0'
5976
+ },
5977
+ text: formatEventTime(event.timestamp)
5978
+ })
5979
+ ]
5980
+ }),
5981
+ ...metadata ? [
5982
+ renderer_span({
5983
+ style: {
5984
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5985
+ color: 'var(--c15t-text-muted)'
5986
+ },
5987
+ text: metadata
5988
+ })
5989
+ ] : []
5990
+ ]
5991
+ });
5992
+ }
5993
+ function groupScriptActivityEvents(events) {
5994
+ const groups = new Map();
5995
+ for (const event of events){
5996
+ const groupName = getScriptActivityGroupName(event);
5997
+ const existing = groups.get(groupName);
5998
+ if (existing) existing.push(event);
5999
+ else groups.set(groupName, [
6000
+ event
6001
+ ]);
6002
+ }
6003
+ const orderedGroupNames = [
6004
+ 'onBeforeLoad',
6005
+ 'onLoad',
6006
+ 'onConsentChange',
6007
+ 'other'
6008
+ ];
6009
+ return orderedGroupNames.map((groupName)=>{
6010
+ const groupEvents = groups.get(groupName);
6011
+ return groupEvents ? [
6012
+ groupName,
6013
+ groupEvents
6014
+ ] : null;
6015
+ }).filter((group)=>null !== group);
6016
+ }
6017
+ function getScriptActivityGroupName(event) {
6018
+ const data = event.data ?? {};
6019
+ if ('string' == typeof data.callback) return data.callback;
6020
+ const phase = 'string' == typeof data.phase ? data.phase : '';
6021
+ if ('bootstrap' === phase || 'consent-default' === phase || 'setup' === phase || 'onBeforeLoadGranted' === phase || 'onBeforeLoadDenied' === phase) return 'onBeforeLoad';
6022
+ if ('afterLoad' === phase || 'onLoadGranted' === phase || 'onLoadDenied' === phase) return 'onLoad';
6023
+ if ('consent-update' === phase || 'onConsentChange' === phase || 'onConsentGranted' === phase || 'onConsentDenied' === phase) return 'onConsentChange';
6024
+ return 'other';
6025
+ }
5804
6026
  function scripts_truncateText(text, maxLength) {
5805
6027
  if (text.length <= maxLength) return text;
5806
6028
  return `${text.slice(0, maxLength - 3)}...`;
@@ -6378,6 +6600,7 @@ var __webpack_exports__ = {};
6378
6600
  const state = entry.store.getState();
6379
6601
  state.setCallback('onBannerFetched', entry.originalCallbacks.onBannerFetched);
6380
6602
  state.setCallback('onConsentSet', entry.originalCallbacks.onConsentSet);
6603
+ state.setCallback('onConsentChanged', entry.originalCallbacks.onConsentChanged);
6381
6604
  state.setCallback('onError', entry.originalCallbacks.onError);
6382
6605
  state.setCallback('onBeforeConsentRevocationReload', entry.originalCallbacks.onBeforeConsentRevocationReload);
6383
6606
  const blocker = state.networkBlocker;
@@ -6415,6 +6638,14 @@ var __webpack_exports__ = {};
6415
6638
  });
6416
6639
  if ('function' == typeof entry.originalCallbacks.onConsentSet) entry.originalCallbacks.onConsentSet(payload);
6417
6640
  });
6641
+ store.getState().setCallback('onConsentChanged', (payload)=>{
6642
+ emitEvent(entry, {
6643
+ type: 'consent_save',
6644
+ message: 'Consent preferences changed',
6645
+ data: payload
6646
+ });
6647
+ if ('function' == typeof entry.originalCallbacks.onConsentChanged) entry.originalCallbacks.onConsentChanged(payload);
6648
+ });
6418
6649
  store.getState().setCallback('onError', (payload)=>{
6419
6650
  const errorMessage = payload.error;
6420
6651
  emitEvent(entry, {
@@ -6555,6 +6786,25 @@ var __webpack_exports__ = {};
6555
6786
  loadedScripts: state.loadedScripts
6556
6787
  };
6557
6788
  }
6789
+ function scriptDebugEventToLogEntry(event) {
6790
+ return {
6791
+ type: "script",
6792
+ message: event.message,
6793
+ data: {
6794
+ ...event.data ?? {},
6795
+ source: event.source,
6796
+ scope: event.scope,
6797
+ action: event.action,
6798
+ scriptId: event.scriptId,
6799
+ elementId: event.elementId,
6800
+ hasConsent: event.hasConsent,
6801
+ callback: event.callback,
6802
+ phase: event.phase,
6803
+ stepType: event.stepType,
6804
+ stepIndex: event.stepIndex
6805
+ }
6806
+ };
6807
+ }
6558
6808
  function createDevTools(options = {}) {
6559
6809
  const { namespace = 'c15tStore', position = 'bottom-right', defaultOpen = false } = options;
6560
6810
  const stateManager = createStateManager({
@@ -6562,6 +6812,7 @@ var __webpack_exports__ = {};
6562
6812
  isOpen: defaultOpen
6563
6813
  });
6564
6814
  let detachInstrumentation = null;
6815
+ let detachScriptDebug = null;
6565
6816
  const storeConnector = createStoreConnector({
6566
6817
  namespace,
6567
6818
  onConnect: (_state, store)=>{
@@ -6573,6 +6824,10 @@ var __webpack_exports__ = {};
6573
6824
  stateManager.addEvent(event);
6574
6825
  }
6575
6826
  });
6827
+ detachScriptDebug?.();
6828
+ detachScriptDebug = (0, external_c15t_namespaceObject.subscribeToScriptDebugEvents)((event)=>{
6829
+ stateManager.addEvent(scriptDebugEventToLogEntry(event));
6830
+ });
6576
6831
  stateManager.setConnected(true);
6577
6832
  stateManager.addEvent({
6578
6833
  type: 'info',
@@ -6609,6 +6864,8 @@ var __webpack_exports__ = {};
6609
6864
  stateManager.setConnected(false);
6610
6865
  detachInstrumentation?.();
6611
6866
  detachInstrumentation = null;
6867
+ detachScriptDebug?.();
6868
+ detachScriptDebug = null;
6612
6869
  stateManager.addEvent({
6613
6870
  type: 'error',
6614
6871
  message: 'Disconnected from c15tStore'
@@ -6698,6 +6955,8 @@ var __webpack_exports__ = {};
6698
6955
  destroy: ()=>{
6699
6956
  detachInstrumentation?.();
6700
6957
  detachInstrumentation = null;
6958
+ detachScriptDebug?.();
6959
+ detachScriptDebug = null;
6701
6960
  panelHeightAnimator.destroy();
6702
6961
  tabsInstance?.destroy();
6703
6962
  panelInstance.destroy();
@@ -6712,6 +6971,7 @@ var __webpack_exports__ = {};
6712
6971
  function createDevToolsPanel(options) {
6713
6972
  const { namespace = 'c15tStore' } = options;
6714
6973
  let detachInstrumentation = null;
6974
+ let detachScriptDebug = null;
6715
6975
  const stateManager = createStateManager({
6716
6976
  isOpen: true
6717
6977
  });
@@ -6724,6 +6984,10 @@ var __webpack_exports__ = {};
6724
6984
  store,
6725
6985
  onEvent: (event)=>stateManager.addEvent(event)
6726
6986
  });
6987
+ detachScriptDebug?.();
6988
+ detachScriptDebug = (0, external_c15t_namespaceObject.subscribeToScriptDebugEvents)((event)=>{
6989
+ stateManager.addEvent(scriptDebugEventToLogEntry(event));
6990
+ });
6727
6991
  stateManager.setConnected(true);
6728
6992
  const persistedOverrides = loadPersistedOverrides();
6729
6993
  if (persistedOverrides) {
@@ -6740,6 +7004,8 @@ var __webpack_exports__ = {};
6740
7004
  stateManager.setConnected(false);
6741
7005
  detachInstrumentation?.();
6742
7006
  detachInstrumentation = null;
7007
+ detachScriptDebug?.();
7008
+ detachScriptDebug = null;
6743
7009
  }
6744
7010
  });
6745
7011
  const panelRenderer = createPanelRenderer({
@@ -6832,6 +7098,8 @@ var __webpack_exports__ = {};
6832
7098
  destroy: ()=>{
6833
7099
  detachInstrumentation?.();
6834
7100
  detachInstrumentation = null;
7101
+ detachScriptDebug?.();
7102
+ detachScriptDebug = null;
6835
7103
  unsubscribe();
6836
7104
  tabsInstance?.destroy();
6837
7105
  storeConnector.destroy();